tvm
Loading...
Searching...
No Matches
stmt.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
22#ifndef TVM_IR_STMT_H_
23#define TVM_IR_STMT_H_
24
25#include <tvm/ffi/reflection/registry.h>
26#include <tvm/ir/op.h>
27#include <tvm/ir/prim/expr.h>
28
29#include <initializer_list>
30#include <optional>
31#include <string>
32#include <utility>
33
34namespace tvm {
35
37class StmtObj : public ffi::Object {
38 public:
43 mutable Location loc = UnknownLoc();
44
45 StmtObj() = default;
46 explicit StmtObj(Location loc) : loc(loc) {}
47
48 static void RegisterReflection() {
49 namespace refl = tvm::ffi::reflection;
50 refl::ObjectDef<StmtObj>().def_ro("loc", &StmtObj::loc, refl::AttachFieldFlag::SEqHashIgnore());
51 }
52
53 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
54 static constexpr bool _type_s_eq_hash_subclass_kind_fixed = true;
55
56 static constexpr const uint32_t _type_child_slots = 15;
57 TVM_FFI_DECLARE_OBJECT_INFO("ir.Stmt", StmtObj, ffi::Object);
58};
59
61class Stmt : public ffi::ObjectRef {
62 public:
63 explicit Stmt(ffi::ObjectPtr<StmtObj> node) : ffi::ObjectRef(std::move(node)) {
64 TVM_FFI_CHECK(defined(), ValueError) << "Stmt expects a defined node";
65 }
66
68};
69
74class SeqStmtObj : public StmtObj {
75 public:
77 ffi::Array<Stmt> seq;
78
80 size_t size() const { return seq.size(); }
84 Stmt operator[](size_t index) const { return seq[index]; }
85
88};
89
91class SeqStmt : public Stmt {
92 public:
98 TVM_TIRX_DLL explicit SeqStmt(ffi::Array<Stmt> seq, Location loc = UnknownLoc());
100 TVM_TIRX_DLL SeqStmt(Stmt stmt, ffi::Optional<Location> loc = std::nullopt);
101 SeqStmt(std::initializer_list<Stmt> seq, Location loc = UnknownLoc())
102 : SeqStmt(ffi::Array<Stmt>(seq), std::move(loc)) {}
103
105 size_t size() const { return operator->()->size(); }
109 Stmt operator[](size_t index) const { return (*(operator->()))[index]; }
110 explicit SeqStmt(ffi::ObjectPtr<SeqStmtObj> node) : Stmt(std::move(node)) {}
111
114};
115
116namespace ffi {
117template <>
118inline constexpr bool use_default_type_traits_v<SeqStmt> = false;
119
120template <>
121struct TypeTraits<SeqStmt> : public ObjectRefWithFallbackTraitsBase<SeqStmt, Stmt, Array<Stmt>> {
122 static SeqStmt ConvertFallbackValue(Stmt stmt) { return SeqStmt(std::move(stmt)); }
123 static SeqStmt ConvertFallbackValue(Array<Stmt> seq) { return SeqStmt(std::move(seq)); }
124};
125} // namespace ffi
126
134class BindObj : public StmtObj {
135 public:
136 explicit BindObj(ffi::UnsafeInit tag) : var(tag), value(tag) {}
137
138 BindObj(Var var, Expr value) : var(std::move(var)), value(std::move(value)) {}
139
144
145 static void RegisterReflection() {
146 namespace refl = tvm::ffi::reflection;
147 refl::ObjectDef<BindObj>()
148 .def_ro("var", &BindObj::var, refl::AttachFieldFlag::SEqHashDefSimple())
149 .def_ro("value", &BindObj::value);
150 }
152};
153
158class Bind : public Stmt {
159 public:
161
162 explicit Bind(ffi::ObjectPtr<BindObj> node) : Stmt(std::move(node)) {}
163
166};
167
171TVM_TIRX_DLL bool IsRegionOp(const Op& op);
172
181TVM_TIRX_DLL ffi::Array<Var> GetRegionBodyParams(Op op, ffi::Array<Expr> args, DictAttrs attrs);
182
188class RegionStmtObj : public StmtObj {
189 public:
193 ffi::Array<Expr> args;
195 ffi::Array<Var> body_params;
201 ffi::Array<Var> result_vars;
202
203 explicit RegionStmtObj(ffi::UnsafeInit tag) : op(tag), body(tag) {}
204
205 RegionStmtObj(Op op, SeqStmt body) : op(std::move(op)), body(std::move(body)) {}
206
207 static void RegisterReflection() {
208 namespace refl = tvm::ffi::reflection;
209 refl::ObjectDef<RegionStmtObj>()
210 .def_ro("op", &RegionStmtObj::op)
211 .def_ro("attrs", &RegionStmtObj::attrs)
212 .def_ro("args", &RegionStmtObj::args)
213 .def_ro("body_params", &RegionStmtObj::body_params,
214 refl::AttachFieldFlag::SEqHashDefSimple())
215 .def_ro("body", &RegionStmtObj::body)
216 .def_ro("result_vars", &RegionStmtObj::result_vars,
217 refl::AttachFieldFlag::SEqHashDefSimple());
218 }
220};
221
223class RegionStmt : public Stmt {
224 public:
225 TVM_TIRX_DLL RegionStmt(Op op, ffi::Array<Expr> args, ffi::Array<Var> body_params,
226 DictAttrs attrs, SeqStmt body, ffi::Array<Var> result_vars = {},
227 Location loc = UnknownLoc());
228
229 explicit RegionStmt(ffi::ObjectPtr<RegionStmtObj> node) : Stmt(std::move(node)) {}
230
233};
234
235namespace op_attr {
245inline constexpr ffi::reflection::AttrKey<
246 ffi::reflection::NativeFunctionView<ffi::Array<Var>(const CallObj* call)>>
247 kRegionGetBodyParams{"FRegionGetBodyParams"};
249inline constexpr ffi::reflection::AttrKey<
250 ffi::reflection::NativeFunctionView<void(const RegionStmtObj*)>>
251 kRegionValidate{"FRegionValidate"};
252} // namespace op_attr
253
254// Compatibility names; new callers can deduce the value type from the key.
256using FRegionValidate = decltype(op_attr::kRegionValidate)::ValueType;
257
267class AssertStmtObj : public StmtObj {
268 public:
269 explicit AssertStmtObj(ffi::UnsafeInit tag) : condition(tag), error_kind(tag) {}
270
273
279 ffi::Array<StringImm> message_parts;
280
281 static void RegisterReflection() {
282 namespace refl = tvm::ffi::reflection;
283 refl::ObjectDef<AssertStmtObj>()
284 .def_ro("condition", &AssertStmtObj::condition)
285 .def_ro("error_kind", &AssertStmtObj::error_kind)
286 .def_ro("message_parts", &AssertStmtObj::message_parts);
287 }
289};
290
295class AssertStmt : public Stmt {
296 public:
298 ffi::Array<StringImm> message_parts, Location loc = UnknownLoc());
299
300 explicit AssertStmt(ffi::ObjectPtr<AssertStmtObj> node) : Stmt(std::move(node)) {}
301
304};
305
315class TensorStoreObj : public StmtObj {
316 public:
317 explicit TensorStoreObj(ffi::UnsafeInit tag) : dest(tag), value(tag) {}
318
319 TensorStoreObj(Expr dest, PrimExpr value) : dest(std::move(dest)), value(std::move(value)) {}
320
324 ffi::Array<PrimExpr> indices;
327
328 static void RegisterReflection() {
329 namespace refl = tvm::ffi::reflection;
330 refl::ObjectDef<TensorStoreObj>()
331 .def_ro("dest", &TensorStoreObj::dest)
332 .def_ro("indices", &TensorStoreObj::indices)
333 .def_ro("value", &TensorStoreObj::value);
334 }
336};
337
342class TensorStore : public Stmt {
343 public:
344 TVM_TIRX_DLL explicit TensorStore(Expr dest, ffi::Array<PrimExpr> indices, PrimExpr value,
345 Location loc = UnknownLoc());
346
347 explicit TensorStore(ffi::ObjectPtr<TensorStoreObj> node) : Stmt(std::move(node)) {}
348
351};
352
353namespace type_attr {
355inline constexpr ffi::reflection::AttrKey<ffi::reflection::NativeFunctionView<void(
356 const Expr&, const ffi::Array<PrimExpr>&, const PrimExpr&)>>
357 kTensorStoreValidateByTy{"__tvm_tensor_store_validate__"};
358} // namespace type_attr
359
366class EvaluateObj : public StmtObj {
367 public:
368 explicit EvaluateObj(ffi::UnsafeInit tag) : value(tag) {}
369
370 explicit EvaluateObj(Expr value) : value(std::move(value)) {}
371
374
375 static void RegisterReflection() {
376 namespace refl = tvm::ffi::reflection;
377 refl::ObjectDef<EvaluateObj>().def_ro("value", &EvaluateObj::value);
378 }
380};
381
386class Evaluate : public Stmt {
387 public:
388 TVM_TIRX_DLL explicit Evaluate(Expr value, Location loc = UnknownLoc());
389
390 explicit Evaluate(int value, Location loc = UnknownLoc()) : Evaluate(PrimExpr(value), loc) {}
391
392 explicit Evaluate(ffi::ObjectPtr<EvaluateObj> node) : Stmt(std::move(node)) {}
393
396};
397
401class IfObj : public StmtObj {
402 public:
403 explicit IfObj(ffi::UnsafeInit tag) : condition(tag), then_case(tag) {}
404
407
413 ffi::Optional<SeqStmt> else_case;
414
415 static void RegisterReflection() {
416 namespace refl = tvm::ffi::reflection;
417 refl::ObjectDef<IfObj>()
418 .def_ro("condition", &IfObj::condition)
419 .def_ro("then_case", &IfObj::then_case)
420 .def_ro("else_case", &IfObj::else_case);
421 }
423};
424
429class If : public Stmt {
430 public:
431 TVM_TIRX_DLL If(PrimExpr condition, SeqStmt then_case,
432 ffi::Optional<SeqStmt> else_case = std::nullopt, Location loc = UnknownLoc());
433
434 explicit If(ffi::ObjectPtr<IfObj> node) : Stmt(std::move(node)) {}
435
438};
439
447enum class ForKind : int {
449 kDefault = 0,
451 kParallel = 1,
456 kVectorized = 2,
458 kUnrolled = 3,
459};
460
471class ForObj : public StmtObj {
472 public:
473 explicit ForObj(ffi::UnsafeInit tag) : var(tag), begin(tag), end(tag), step(tag), body(tag) {}
474
476 : var(std::move(var)),
477 begin(std::move(begin)),
478 end(std::move(end)),
479 step(std::move(step)),
480 kind(kind),
481 body(std::move(body)) {}
482
501 ffi::Map<ffi::String, ffi::Any> annotations;
502
503 static void RegisterReflection() {
504 namespace refl = tvm::ffi::reflection;
505 refl::ObjectDef<ForObj>()
506 .def_ro("var", &ForObj::var, refl::AttachFieldFlag::SEqHashDefSimple())
507 .def_ro("begin", &ForObj::begin)
508 .def_ro("end", &ForObj::end)
509 // Reflection stores one typed default. Wider unit steps remain distinct.
510 .def_ro("step", &ForObj::step, refl::DefaultValue(IntImm::Int32(1)))
511 .def_ro("kind", &ForObj::kind, refl::DefaultValue(ForKind::kDefault))
512 .def_ro("body", &ForObj::body)
513 .def_ro("annotations", &ForObj::annotations,
514 refl::DefaultValue(ffi::Map<ffi::String, ffi::Any>()));
515 }
516
519
521};
522
527class For : public Stmt {
528 public:
530 SeqStmt body, ffi::Map<ffi::String, ffi::Any> annotations = {},
531 Location loc = UnknownLoc());
532
533 explicit For(ffi::ObjectPtr<ForObj> node) : Stmt(std::move(node)) {}
534
537};
538
549class WhileObj : public StmtObj {
550 public:
551 explicit WhileObj(ffi::UnsafeInit tag) : condition(tag), body(tag) {}
552
554 : condition(std::move(condition)), body(std::move(body)) {}
555
560
561 static void RegisterReflection() {
562 namespace refl = tvm::ffi::reflection;
563 refl::ObjectDef<WhileObj>()
564 .def_ro("condition", &WhileObj::condition)
565 .def_ro("body", &WhileObj::body);
566 }
568};
569
574class While : public Stmt {
575 public:
577
578 explicit While(ffi::ObjectPtr<WhileObj> node) : Stmt(std::move(node)) {}
579
582};
583
587class ReturnObj : public StmtObj {
588 public:
589 explicit ReturnObj(ffi::UnsafeInit tag) : value(tag) {}
590
591 explicit ReturnObj(Expr value) : value(std::move(value)) {}
592
595
596 static void RegisterReflection() {
597 namespace refl = tvm::ffi::reflection;
598 refl::ObjectDef<ReturnObj>().def_ro("value", &ReturnObj::value);
599 }
600
602};
603
608class Return : public Stmt {
609 public:
610 TVM_TIRX_DLL explicit Return(Expr value, Location loc = UnknownLoc());
611
612 explicit Return(ffi::ObjectPtr<ReturnObj> node) : Stmt(std::move(node)) {}
613
616};
617
621class BreakObj : public StmtObj {
622 public:
623 static void RegisterReflection() {
624 namespace refl = tvm::ffi::reflection;
625 refl::ObjectDef<BreakObj>();
626 }
627
629};
630
635class Break : public Stmt {
636 public:
638
639 explicit Break(ffi::ObjectPtr<BreakObj> node) : Stmt(std::move(node)) {}
640
643};
644
648class ContinueObj : public StmtObj {
649 public:
650 static void RegisterReflection() {
651 namespace refl = tvm::ffi::reflection;
652 refl::ObjectDef<ContinueObj>();
653 }
654
656};
657
662class Continue : public Stmt {
663 public:
665
666 explicit Continue(ffi::ObjectPtr<ContinueObj> node) : Stmt(std::move(node)) {}
667
670};
671
672// overload printing of for type.
673TVM_TIRX_DLL std::ostream& operator<<(std::ostream& os, ForKind kind);
674
675// inline implementations
676inline const char* ForKind2String(ForKind t) {
677 switch (t) {
679 return "serial";
681 return "parallel";
683 return "vectorized";
685 return "unroll";
686 }
687 TVM_FFI_THROW(InternalError) << "Unknown ForKind" << t;
688 TVM_FFI_UNREACHABLE();
689}
690
691} // namespace tvm
692#endif // TVM_IR_STMT_H_
Canonical primitive operators and their registration.
TIR expressions.
#define TVM_TIRX_DLL
Definition base.h:55
Assert condition, if an error occurs, return the error message.
Definition stmt.h:267
PrimExpr condition
Condition to be checked.
Definition stmt.h:275
StringImm error_kind
The error kind, e.g. "RuntimeError", "TypeError", "ValueError".
Definition stmt.h:277
AssertStmtObj(ffi::UnsafeInit tag)
Definition stmt.h:269
ffi::Array< StringImm > message_parts
Error message fragments, concatenated at runtime when assertion fails.
Definition stmt.h:279
AssertStmtObj(PrimExpr condition, StringImm error_kind)
Definition stmt.h:271
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.AssertStmt", AssertStmtObj, StmtObj)
static void RegisterReflection()
Definition stmt.h:281
Managed reference to AssertStmtObj.
Definition stmt.h:295
AssertStmt(ffi::ObjectPtr< AssertStmtObj > node)
Definition stmt.h:300
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(AssertStmt, Stmt, AssertStmtObj)
TVM_DEFINE_OBJECT_REF_COW_METHOD(AssertStmtObj)
TVM_TIRX_DLL AssertStmt(PrimExpr condition, StringImm error_kind, ffi::Array< StringImm > message_parts, Location loc=UnknownLoc())
Bind a variable to a value in the enclosing scope.
Definition stmt.h:134
static void RegisterReflection()
Definition stmt.h:145
BindObj(ffi::UnsafeInit tag)
Definition stmt.h:136
Expr value
The value to bind to the variable.
Definition stmt.h:143
BindObj(Var var, Expr value)
Definition stmt.h:138
Var var
The variable being bound.
Definition stmt.h:141
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Bind", BindObj, StmtObj)
Managed reference to BindObj.
Definition stmt.h:158
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Bind, Stmt, BindObj)
Bind(ffi::ObjectPtr< BindObj > node)
Definition stmt.h:162
TVM_DEFINE_OBJECT_REF_COW_METHOD(BindObj)
TVM_TIRX_DLL Bind(Var var, Expr value, Location loc=UnknownLoc())
A Break in control flow.
Definition stmt.h:621
static void RegisterReflection()
Definition stmt.h:623
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Break", BreakObj, StmtObj)
Managed reference to BreakObj.
Definition stmt.h:635
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Break, Stmt, BreakObj)
TVM_DEFINE_OBJECT_REF_COW_METHOD(BreakObj)
TVM_TIRX_DLL Break(Location loc)
Break(ffi::ObjectPtr< BreakObj > node)
Definition stmt.h:639
Call corresponds to callable invocation.
Definition expr.h:788
A Continue in control flow.
Definition stmt.h:648
static void RegisterReflection()
Definition stmt.h:650
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Continue", ContinueObj, StmtObj)
Managed reference to ContinueObj.
Definition stmt.h:662
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Continue, Stmt, ContinueObj)
Continue(ffi::ObjectPtr< ContinueObj > node)
Definition stmt.h:666
TVM_DEFINE_OBJECT_REF_COW_METHOD(ContinueObj)
TVM_TIRX_DLL Continue(Location loc)
Managed reference to DictAttrsObj.
Definition attrs.h:108
Evaluates an expression. This is mostly used for putting a Call node into Stmt.
Definition stmt.h:366
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Evaluate", EvaluateObj, StmtObj)
EvaluateObj(ffi::UnsafeInit tag)
Definition stmt.h:368
Expr value
The expression to be evaluated.
Definition stmt.h:373
EvaluateObj(Expr value)
Definition stmt.h:370
static void RegisterReflection()
Definition stmt.h:375
Managed reference to EvaluateObj.
Definition stmt.h:386
Evaluate(int value, Location loc=UnknownLoc())
Definition stmt.h:390
TVM_DEFINE_OBJECT_REF_COW_METHOD(EvaluateObj)
TVM_TIRX_DLL Evaluate(Expr value, Location loc=UnknownLoc())
Evaluate(ffi::ObjectPtr< EvaluateObj > node)
Definition stmt.h:392
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Evaluate, Stmt, EvaluateObj)
Managed reference to ExprObj.
Definition expr.h:101
A for loop, with possible type annotations.
Definition stmt.h:471
static void RegisterReflection()
Definition stmt.h:503
ffi::Map< ffi::String, ffi::Any > annotations
Additional annotations about the loop.
Definition stmt.h:501
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.For", ForObj, StmtObj)
PrimExpr begin
The inclusive beginning of iteration.
Definition stmt.h:486
ForObj(PrimVar var, PrimExpr begin, PrimExpr end, PrimExpr step, ForKind kind, SeqStmt body)
Definition stmt.h:475
PrimExpr step
The required loop step, including an explicit typed one for unit stride.
Definition stmt.h:490
ForObj(ffi::UnsafeInit tag)
Definition stmt.h:473
PrimExpr end
The exclusive end of iteration.
Definition stmt.h:488
SeqStmt body
The body of the for loop.
Definition stmt.h:494
PrimVar var
The loop variable.
Definition stmt.h:484
ForKind kind
The kind of the for loop.
Definition stmt.h:492
TVM_TIRX_DLL bool HasTrivialStep() const
Check it is a loop without nontrivial loop step.
Managed reference to ForObj.
Definition stmt.h:527
TVM_TIRX_DLL For(PrimVar var, PrimExpr begin, PrimExpr end, PrimExpr step, ForKind kind, SeqStmt body, ffi::Map< ffi::String, ffi::Any > annotations={}, Location loc=UnknownLoc())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(For, Stmt, ForObj)
TVM_DEFINE_OBJECT_REF_COW_METHOD(ForObj)
For(ffi::ObjectPtr< ForObj > node)
Definition stmt.h:533
If statement.
Definition stmt.h:401
IfObj(PrimExpr condition, SeqStmt then_case)
Definition stmt.h:405
IfObj(ffi::UnsafeInit tag)
Definition stmt.h:403
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.If", IfObj, StmtObj)
PrimExpr condition
The condition.
Definition stmt.h:409
ffi::Optional< SeqStmt > else_case
The branch to be executed when condition is false, can be null.
Definition stmt.h:413
SeqStmt then_case
The branch to be executed when condition is true.
Definition stmt.h:411
static void RegisterReflection()
Definition stmt.h:415
Managed reference to IfObj.
Definition stmt.h:429
TVM_DEFINE_OBJECT_REF_COW_METHOD(IfObj)
If(ffi::ObjectPtr< IfObj > node)
Definition stmt.h:434
TVM_TIRX_DLL If(PrimExpr condition, SeqStmt then_case, ffi::Optional< SeqStmt > else_case=std::nullopt, Location loc=UnknownLoc())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(If, Stmt, IfObj)
static IntImm Int32(ffi::BigInt value, Location loc=UnknownLoc())
Construct a scalar int32 constant.
Definition expr.h:360
Non-nullable source-location metadata.
Definition location.h:91
Reference-counted handle to a canonical named operator.
Definition op.h:140
Typed reference/view over any Expr whose ExprObj::ty is PrimType.
Definition expr.h:187
Checked scalar view over a VarObj.
Definition expr.h:598
A single-body statement whose semantics are defined by an operator. Operands are evaluated in the enc...
Definition stmt.h:188
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.RegionStmt", RegionStmtObj, StmtObj)
ffi::Array< Var > result_vars
Variables defined after the region in the enclosing sequence.
Definition stmt.h:201
ffi::Array< Var > body_params
Variables defined at body entry, visible only within the body.
Definition stmt.h:195
DictAttrs attrs
Attributes evaluated in the enclosing scope.
Definition stmt.h:197
SeqStmt body
Body evaluated with the body parameters in scope.
Definition stmt.h:199
RegionStmtObj(Op op, SeqStmt body)
Definition stmt.h:205
ffi::Array< Expr > args
Operands evaluated in the enclosing scope.
Definition stmt.h:193
RegionStmtObj(ffi::UnsafeInit tag)
Definition stmt.h:203
Op op
Operator defining the region's semantics.
Definition stmt.h:191
static void RegisterReflection()
Definition stmt.h:207
Managed reference to RegionStmtObj.
Definition stmt.h:223
RegionStmt(ffi::ObjectPtr< RegionStmtObj > node)
Definition stmt.h:229
TVM_DEFINE_OBJECT_REF_COW_METHOD(RegionStmtObj)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(RegionStmt, Stmt, RegionStmtObj)
TVM_TIRX_DLL RegionStmt(Op op, ffi::Array< Expr > args, ffi::Array< Var > body_params, DictAttrs attrs, SeqStmt body, ffi::Array< Var > result_vars={}, Location loc=UnknownLoc())
A return from the current function.
Definition stmt.h:587
static void RegisterReflection()
Definition stmt.h:596
ReturnObj(ffi::UnsafeInit tag)
Definition stmt.h:589
ReturnObj(Expr value)
Definition stmt.h:591
Expr value
The value to return.
Definition stmt.h:594
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Return", ReturnObj, StmtObj)
Managed reference to ReturnObj.
Definition stmt.h:608
Return(ffi::ObjectPtr< ReturnObj > node)
Definition stmt.h:612
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Return, Stmt, ReturnObj)
TVM_DEFINE_OBJECT_REF_COW_METHOD(ReturnObj)
TVM_TIRX_DLL Return(Expr value, Location loc=UnknownLoc())
The container of seq statement. Represent a sequence of statements.
Definition stmt.h:74
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.SeqStmt", SeqStmtObj, StmtObj)
Stmt operator[](size_t index) const
Get the index-th element in the sequence.
Definition stmt.h:84
static TVM_TIRX_DLL void RegisterReflection()
ffi::Array< Stmt > seq
internal sequence content.
Definition stmt.h:77
size_t size() const
Definition stmt.h:80
Sequence statement.
Definition stmt.h:91
SeqStmt(std::initializer_list< Stmt > seq, Location loc=UnknownLoc())
Definition stmt.h:101
TVM_DEFINE_OBJECT_REF_COW_METHOD(SeqStmtObj)
size_t size() const
Definition stmt.h:105
SeqStmt(ffi::ObjectPtr< SeqStmtObj > node)
Definition stmt.h:110
TVM_TIRX_DLL SeqStmt(Stmt stmt, ffi::Optional< Location > loc=std::nullopt)
Wrap a statement, reusing an existing sequence when possible.
Stmt operator[](size_t index) const
Get the index-th element in the sequence.
Definition stmt.h:109
TVM_TIRX_DLL SeqStmt(ffi::Array< Stmt > seq, Location loc=UnknownLoc())
Construct SeqStmt.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SeqStmt, Stmt, SeqStmtObj)
Base node of all statements.
Definition stmt.h:37
Location loc
Location that points to the original source code. Reserved debug information.
Definition stmt.h:43
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition stmt.h:53
static constexpr bool _type_s_eq_hash_subclass_kind_fixed
Definition stmt.h:54
static void RegisterReflection()
Definition stmt.h:48
StmtObj()=default
TVM_FFI_DECLARE_OBJECT_INFO("ir.Stmt", StmtObj, ffi::Object)
static constexpr const uint32_t _type_child_slots
Definition stmt.h:56
StmtObj(Location loc)
Definition stmt.h:46
Container of all statements.
Definition stmt.h:61
Stmt(ffi::ObjectPtr< StmtObj > node)
Definition stmt.h:63
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Stmt, ffi::ObjectRef, StmtObj)
Managed reference to a string literal.
Definition expr.h:278
Store a primitive value to an indexed destination expression.
Definition stmt.h:315
TensorStoreObj(Expr dest, PrimExpr value)
Definition stmt.h:319
ffi::Array< PrimExpr > indices
The indices location to be stored.
Definition stmt.h:324
TensorStoreObj(ffi::UnsafeInit tag)
Definition stmt.h:317
PrimExpr value
The value to be stored.
Definition stmt.h:326
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TensorStore", TensorStoreObj, StmtObj)
static void RegisterReflection()
Definition stmt.h:328
Expr dest
The indexed destination expression.
Definition stmt.h:322
Managed reference to TensorStoreObj.
Definition stmt.h:342
TVM_TIRX_DLL TensorStore(Expr dest, ffi::Array< PrimExpr > indices, PrimExpr value, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(TensorStoreObj)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TensorStore, Stmt, TensorStoreObj)
TensorStore(ffi::ObjectPtr< TensorStoreObj > node)
Definition stmt.h:347
Reference to the shared immutable unknown location.
Definition location.h:105
Managed reference to VarObj.
Definition expr.h:571
A While loop.
Definition stmt.h:549
PrimExpr condition
The termination condition.
Definition stmt.h:557
static void RegisterReflection()
Definition stmt.h:561
WhileObj(PrimExpr condition, SeqStmt body)
Definition stmt.h:553
WhileObj(ffi::UnsafeInit tag)
Definition stmt.h:551
SeqStmt body
The body of the while loop.
Definition stmt.h:559
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.While", WhileObj, StmtObj)
Managed reference to WhileObj.
Definition stmt.h:574
While(ffi::ObjectPtr< WhileObj > node)
Definition stmt.h:578
TVM_DEFINE_OBJECT_REF_COW_METHOD(WhileObj)
TVM_TIRX_DLL While(PrimExpr condition, SeqStmt body, Location loc=UnknownLoc())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(While, Stmt, WhileObj)
constexpr bool use_default_type_traits_v< SeqStmt >
Definition stmt.h:118
constexpr ffi::reflection::AttrKey< ffi::reflection::NativeFunctionView< ffi::Array< Var >(const CallObj *call)> > kRegionGetBodyParams
Construct fresh typed variables for a region's lexical body parameters.
Definition stmt.h:247
constexpr ffi::reflection::AttrKey< ffi::reflection::NativeFunctionView< void(const RegionStmtObj *)> > kRegionValidate
Optional dialect validation of a complete region statement.
Definition stmt.h:251
constexpr ffi::reflection::AttrKey< ffi::reflection::NativeFunctionView< void(const Expr &, const ffi::Array< PrimExpr > &, const PrimExpr &)> > kTensorStoreValidateByTy
Validate a tensor store by its destination type before constructing the statement.
Definition stmt.h:357
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41
TVM_TIRX_DLL bool IsRegionOp(const Op &op)
Check FRegionGetBodyParams registration without invoking it or creating variables.
std::ostream & operator<<(std::ostream &os, CallEffectKind side_effect)
Definition expr.h:757
decltype(op_attr::kRegionGetBodyParams)::ValueType FRegionGetBodyParams
Definition stmt.h:255
TVM_TIRX_DLL ffi::Array< Var > GetRegionBodyParams(Op op, ffi::Array< Expr > args, DictAttrs attrs)
Validate region operands and construct fresh typed body parameters.
decltype(op_attr::kRegionValidate)::ValueType FRegionValidate
Definition stmt.h:256
@ kDefault
Default calling convention.
const char * ForKind2String(ForKind t)
Definition stmt.h:676
ForKind
The kind of the loop.
Definition stmt.h:447
@ kUnrolled
The loop body must be unrolled.
@ kDefault
Ordinary loop with sequential iteration semantics.
@ kParallel
Parallel execution.
@ kVectorized
Vector SIMD loop. The loop body will be vectorized.
static SeqStmt ConvertFallbackValue(Stmt stmt)
Definition stmt.h:122
static SeqStmt ConvertFallbackValue(Array< Stmt > seq)
Definition stmt.h:123