25#include <tvm/ffi/reflection/registry.h>
29#include <initializer_list>
49 namespace refl = tvm::ffi::reflection;
51 refl::AttachFieldFlag::SEqHashIgnore());
62class Stmt :
public ffi::ObjectRef {
64 explicit Stmt(ffi::ObjectPtr<StmtNode> node) : ffi::ObjectRef(std::move(node)) {
65 TVM_FFI_CHECK(defined(), ValueError) <<
"Stmt expects a defined node";
81 size_t size()
const {
return seq.size(); }
103 :
SeqStmt(ffi::Array<
Stmt>(seq), std::move(loc)) {}
106 size_t size()
const {
return operator->()->size(); }
111 explicit SeqStmt(ffi::ObjectPtr<SeqStmtNode> node) :
Stmt(std::move(node)) {}
122struct TypeTraits<
SeqStmt> :
public ObjectRefWithFallbackTraitsBase<SeqStmt, Stmt, Array<Stmt>> {
147 namespace refl = tvm::ffi::reflection;
148 refl::ObjectDef<BindNode>()
149 .def_ro(
"var", &
BindNode::var, refl::AttachFieldFlag::SEqHashDefSimple())
163 explicit Bind(ffi::ObjectPtr<BindNode> node) :
Stmt(std::move(node)) {}
209 namespace refl = tvm::ffi::reflection;
210 refl::ObjectDef<RegionStmtNode>()
215 refl::AttachFieldFlag::SEqHashDefSimple())
218 refl::AttachFieldFlag::SEqHashDefSimple());
230 explicit RegionStmt(ffi::ObjectPtr<RegionStmtNode> node) :
Stmt(std::move(node)) {}
246 ffi::reflection::NativeFunctionView<ffi::Array<Var>(
const CallNode* call)>;
275 namespace refl = tvm::ffi::reflection;
276 refl::ObjectDef<AssertStmtNode>()
293 explicit AssertStmt(ffi::ObjectPtr<AssertStmtNode> node) :
Stmt(std::move(node)) {}
322 namespace refl = tvm::ffi::reflection;
323 refl::ObjectDef<TensorStoreNode>()
362 namespace refl = tvm::ffi::reflection;
378 explicit Evaluate(ffi::ObjectPtr<EvaluateNode> node) :
Stmt(std::move(node)) {}
402 namespace refl = tvm::ffi::reflection;
403 refl::ObjectDef<IfNode>()
420 explicit If(ffi::ObjectPtr<IfNode> node) :
Stmt(std::move(node)) {}
490 namespace refl = tvm::ffi::reflection;
491 refl::ObjectDef<ForNode>()
492 .def_ro(
"loop_var", &
ForNode::loop_var, refl::AttachFieldFlag::SEqHashDefSimple())
514 ffi::Map<ffi::String, ffi::Any> annotations = {},
517 explicit For(ffi::ObjectPtr<ForNode> node) :
Stmt(std::move(node)) {}
546 namespace refl = tvm::ffi::reflection;
547 refl::ObjectDef<WhileNode>()
562 explicit While(ffi::ObjectPtr<WhileNode> node) :
Stmt(std::move(node)) {}
581 namespace refl = tvm::ffi::reflection;
596 explicit Return(ffi::ObjectPtr<ReturnNode> node) :
Stmt(std::move(node)) {}
608 namespace refl = tvm::ffi::reflection;
609 refl::ObjectDef<BreakNode>();
623 explicit Break(ffi::ObjectPtr<BreakNode> node) :
Stmt(std::move(node)) {}
635 namespace refl = tvm::ffi::reflection;
636 refl::ObjectDef<ContinueNode>();
650 explicit Continue(ffi::ObjectPtr<ContinueNode> node) :
Stmt(std::move(node)) {}
671 TVM_FFI_THROW(InternalError) <<
"Unknown ForKind" << t;
672 TVM_FFI_UNREACHABLE();
Assert condition, if an error occurs, return the error message.
Definition stmt.h:260
static void RegisterReflection()
Definition stmt.h:274
ffi::Array< StringImm > message_parts
Error message fragments, concatenated at runtime when assertion fails.
Definition stmt.h:272
PrimExpr condition
Condition to be checked.
Definition stmt.h:268
AssertStmtNode(PrimExpr condition, StringImm error_kind)
Definition stmt.h:264
StringImm error_kind
The error kind, e.g. "RuntimeError", "TypeError", "ValueError".
Definition stmt.h:270
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.AssertStmt", AssertStmtNode, StmtNode)
AssertStmtNode(ffi::UnsafeInit tag)
Definition stmt.h:262
Managed reference to AssertStmtNode.
Definition stmt.h:288
TVM_DEFINE_OBJECT_REF_COW_METHOD(AssertStmtNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(AssertStmt, Stmt, AssertStmtNode)
AssertStmt(ffi::ObjectPtr< AssertStmtNode > node)
Definition stmt.h:293
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:135
Var var
The variable being bound.
Definition stmt.h:142
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Bind", BindNode, StmtNode)
BindNode(Var var, Expr value)
Definition stmt.h:139
Expr value
The value to bind to the variable.
Definition stmt.h:144
static void RegisterReflection()
Definition stmt.h:146
BindNode(ffi::UnsafeInit tag)
Definition stmt.h:137
Managed reference to BindNode.
Definition stmt.h:159
Bind(ffi::ObjectPtr< BindNode > node)
Definition stmt.h:163
TVM_DEFINE_OBJECT_REF_COW_METHOD(BindNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Bind, Stmt, BindNode)
TVM_TIRX_DLL Bind(Var var, Expr value, Location loc=UnknownLoc())
A Break in control flow.
Definition stmt.h:605
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Break", BreakNode, StmtNode)
static void RegisterReflection()
Definition stmt.h:607
Managed reference to BreakNode.
Definition stmt.h:619
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Break, Stmt, BreakNode)
Break(ffi::ObjectPtr< BreakNode > node)
Definition stmt.h:623
TVM_TIRX_DLL Break(Location loc)
TVM_DEFINE_OBJECT_REF_COW_METHOD(BreakNode)
Call corresponds to callable invocation.
Definition expr.h:935
A Continue in control flow.
Definition stmt.h:632
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Continue", ContinueNode, StmtNode)
static void RegisterReflection()
Definition stmt.h:634
Managed reference to ContinueNode.
Definition stmt.h:646
TVM_DEFINE_OBJECT_REF_COW_METHOD(ContinueNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Continue, Stmt, ContinueNode)
Continue(ffi::ObjectPtr< ContinueNode > node)
Definition stmt.h:650
TVM_TIRX_DLL Continue(Location loc)
Managed reference to DictAttrsNode.
Definition attrs.h:108
Evaluates an expression. This is mostly used for putting a Call node into Stmt.
Definition stmt.h:352
EvaluateNode(ffi::UnsafeInit tag)
Definition stmt.h:354
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Evaluate", EvaluateNode, StmtNode)
static void RegisterReflection()
Definition stmt.h:361
Expr value
The expression to be evaluated.
Definition stmt.h:359
EvaluateNode(Expr value)
Definition stmt.h:356
Managed reference to EvaluateNode.
Definition stmt.h:372
Evaluate(int value, Location loc=UnknownLoc())
Definition stmt.h:376
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Evaluate, Stmt, EvaluateNode)
TVM_TIRX_DLL Evaluate(Expr value, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(EvaluateNode)
Evaluate(ffi::ObjectPtr< EvaluateNode > node)
Definition stmt.h:378
Managed reference to ExprNode.
Definition base_expr.h:359
A for loop, with possible type annotations.
Definition stmt.h:457
ForNode(PrimVar loop_var, PrimExpr min, PrimExpr extent, SeqStmt body)
Definition stmt.h:461
SeqStmt body
The body of the for loop.
Definition stmt.h:476
ForNode(ffi::UnsafeInit tag)
Definition stmt.h:459
PrimExpr min
The minimum value of iteration.
Definition stmt.h:470
ForKind kind
The kind of the for loop.
Definition stmt.h:474
static void RegisterReflection()
Definition stmt.h:489
PrimExpr extent
The extent of the iteration.
Definition stmt.h:472
ffi::Optional< PrimExpr > step
The loop step. It is one if not specified.
Definition stmt.h:487
ffi::Map< ffi::String, ffi::Any > annotations
Additional annotations about the loop.
Definition stmt.h:483
bool HasTrivialStep() const
Check it is a loop without nontrivial loop step.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.For", ForNode, StmtNode)
PrimVar loop_var
The loop variable.
Definition stmt.h:468
Managed reference to ForNode.
Definition stmt.h:511
TVM_DEFINE_OBJECT_REF_COW_METHOD(ForNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(For, Stmt, ForNode)
For(ffi::ObjectPtr< ForNode > node)
Definition stmt.h:517
TVM_TIRX_DLL For(PrimVar loop_var, PrimExpr min, PrimExpr extent, ForKind kind, SeqStmt body, ffi::Map< ffi::String, ffi::Any > annotations={}, ffi::Optional< PrimExpr > step=std::nullopt, Location loc=UnknownLoc())
If statement.
Definition stmt.h:387
IfNode(PrimExpr condition, SeqStmt then_case)
Definition stmt.h:391
ffi::Optional< SeqStmt > else_case
The branch to be executed when condition is false, can be null.
Definition stmt.h:399
PrimExpr condition
The condition.
Definition stmt.h:395
IfNode(ffi::UnsafeInit tag)
Definition stmt.h:389
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.If", IfNode, StmtNode)
static void RegisterReflection()
Definition stmt.h:401
SeqStmt then_case
The branch to be executed when condition is true.
Definition stmt.h:397
Managed reference to IfNode.
Definition stmt.h:415
If(ffi::ObjectPtr< IfNode > node)
Definition stmt.h:420
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(If, Stmt, IfNode)
TVM_TIRX_DLL If(PrimExpr condition, SeqStmt then_case, ffi::Optional< SeqStmt > else_case=std::nullopt, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(IfNode)
Non-nullable source-location metadata.
Definition location.h:91
Reference-counted handle to a canonical named operator.
Definition op.h:147
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:447
Checked scalar view over a VarNode.
Definition expr.h:742
A single-body statement whose semantics are defined by an operator. Operands are evaluated in the enc...
Definition stmt.h:189
static void RegisterReflection()
Definition stmt.h:208
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.RegionStmt", RegionStmtNode, StmtNode)
DictAttrs attrs
Attributes evaluated in the enclosing scope.
Definition stmt.h:198
RegionStmtNode(ffi::UnsafeInit tag)
Definition stmt.h:204
Op op
Operator defining the region's semantics.
Definition stmt.h:192
ffi::Array< Expr > args
Operands evaluated in the enclosing scope.
Definition stmt.h:194
RegionStmtNode(Op op, SeqStmt body)
Definition stmt.h:206
ffi::Array< Var > result_vars
Variables defined after the region in the enclosing sequence.
Definition stmt.h:202
SeqStmt body
Body evaluated with the body parameters in scope.
Definition stmt.h:200
ffi::Array< Var > body_params
Variables defined at body entry, visible only within the body.
Definition stmt.h:196
Managed reference to RegionStmtNode.
Definition stmt.h:224
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(RegionStmt, Stmt, RegionStmtNode)
RegionStmt(ffi::ObjectPtr< RegionStmtNode > node)
Definition stmt.h:230
TVM_DEFINE_OBJECT_REF_COW_METHOD(RegionStmtNode)
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:571
Expr value
The value to return.
Definition stmt.h:578
ReturnNode(Expr value)
Definition stmt.h:575
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Return", ReturnNode, StmtNode)
ReturnNode(ffi::UnsafeInit tag)
Definition stmt.h:573
static void RegisterReflection()
Definition stmt.h:580
Managed reference to ReturnNode.
Definition stmt.h:592
Return(ffi::ObjectPtr< ReturnNode > node)
Definition stmt.h:596
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Return, Stmt, ReturnNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(ReturnNode)
TVM_TIRX_DLL Return(Expr value, Location loc=UnknownLoc())
The container of seq statement. Represent a sequence of statements.
Definition stmt.h:75
static TVM_TIRX_DLL void RegisterReflection()
ffi::Array< Stmt > seq
internal sequence content.
Definition stmt.h:78
Stmt operator[](size_t index) const
Get the index-th element in the sequence.
Definition stmt.h:85
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.SeqStmt", SeqStmtNode, StmtNode)
size_t size() const
Definition stmt.h:81
Sequence statement.
Definition stmt.h:92
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SeqStmt, Stmt, SeqStmtNode)
SeqStmt(std::initializer_list< Stmt > seq, Location loc=UnknownLoc())
Definition stmt.h:102
TVM_DEFINE_OBJECT_REF_COW_METHOD(SeqStmtNode)
SeqStmt(ffi::ObjectPtr< SeqStmtNode > node)
Definition stmt.h:111
size_t size() const
Definition stmt.h:106
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:110
TVM_TIRX_DLL SeqStmt(ffi::Array< Stmt > seq, Location loc=UnknownLoc())
Construct SeqStmt.
Base node of all statements.
Definition stmt.h:37
static constexpr const uint32_t _type_child_slots
Definition stmt.h:57
Location loc
Location that points to the original source code. Reserved debug information.
Definition stmt.h:43
static void RegisterReflection()
Definition stmt.h:48
static constexpr bool _type_s_eq_hash_subclass_kind_fixed
Definition stmt.h:55
StmtNode(Location loc)
Definition stmt.h:46
TVM_FFI_DECLARE_OBJECT_INFO("ir.Stmt", StmtNode, ffi::Object)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition stmt.h:54
Container of all statements.
Definition stmt.h:62
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Stmt, ffi::ObjectRef, StmtNode)
Stmt(ffi::ObjectPtr< StmtNode > node)
Definition stmt.h:64
Managed reference to a string literal.
Definition expr.h:99
Store a primitive value to an indexed destination expression.
Definition stmt.h:308
Expr dest
The indexed destination expression.
Definition stmt.h:315
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TensorStore", TensorStoreNode, StmtNode)
TensorStoreNode(ffi::UnsafeInit tag)
Definition stmt.h:310
static void RegisterReflection()
Definition stmt.h:321
TensorStoreNode(Expr dest, PrimExpr value)
Definition stmt.h:312
PrimExpr value
The value to be stored.
Definition stmt.h:319
ffi::Array< PrimExpr > indices
The indices location to be stored.
Definition stmt.h:317
Managed reference to TensorStoreNode.
Definition stmt.h:335
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TensorStore, Stmt, TensorStoreNode)
TVM_TIRX_DLL TensorStore(Expr dest, ffi::Array< PrimExpr > indices, PrimExpr value, Location loc=UnknownLoc())
TensorStore(ffi::ObjectPtr< TensorStoreNode > node)
Definition stmt.h:340
TVM_DEFINE_OBJECT_REF_COW_METHOD(TensorStoreNode)
Reference to the shared immutable unknown location.
Definition location.h:105
Managed reference to VarNode.
Definition expr.h:714
A While loop.
Definition stmt.h:533
SeqStmt body
The body of the while loop.
Definition stmt.h:543
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.While", WhileNode, StmtNode)
static void RegisterReflection()
Definition stmt.h:545
WhileNode(ffi::UnsafeInit tag)
Definition stmt.h:535
WhileNode(PrimExpr condition, SeqStmt body)
Definition stmt.h:537
PrimExpr condition
The termination condition.
Definition stmt.h:541
Managed reference to WhileNode.
Definition stmt.h:558
While(ffi::ObjectPtr< WhileNode > node)
Definition stmt.h:562
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(While, Stmt, WhileNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(WhileNode)
TVM_TIRX_DLL While(PrimExpr condition, SeqStmt body, Location loc=UnknownLoc())
Canonical primitive operators and their registration.
constexpr bool use_default_type_traits_v< SeqStmt >
Definition stmt.h:119
constexpr const char * kRegionGetBodyParams
Definition stmt.h:676
constexpr const char * kRegionValidate
Definition stmt.h:677
constexpr const char * kEvaluateValidate
Definition stmt.h:681
constexpr const char * kTensorStoreValidate
Definition stmt.h:682
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
TVM_TIRX_DLL bool IsRegionOp(const Op &op)
Check FRegionGetBodyParams registration without invoking it or creating variables.
TVM_TIRX_DLL PrimExpr min(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
take minimum of two values
TVM_TIRX_DLL ffi::Array< Var > GetRegionBodyParams(Op op, ffi::Array< Expr > args, DictAttrs attrs)
Validate region operands and construct fresh typed body parameters.
@ kDefault
Default calling convention.
const char * ForKind2String(ForKind t)
Definition stmt.h:660
ForKind
The kind of the loop.
Definition stmt.h:433
@ 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.
ffi::reflection::NativeFunctionView< void(const RegionStmtNode *)> FRegionValidate
Optional dialect validation of a complete region statement.
Definition stmt.h:249
ffi::reflection::NativeFunctionView< ffi::Array< Var >(const CallNode *call)> FRegionGetBodyParams
Construct fresh typed variables for a region's lexical body parameters.
Definition stmt.h:246
TVM_TIRX_DLL PrimExpr operator<<(PrimExpr a, PrimExpr b)
left shift operator
#define TVM_TIRX_DLL
Definition base.h:83
static SeqStmt ConvertFallbackValue(Stmt stmt)
Definition stmt.h:123
static SeqStmt ConvertFallbackValue(Array< Stmt > seq)
Definition stmt.h:124