25#include <tvm/ffi/reflection/registry.h>
29#include <initializer_list>
49 namespace refl = tvm::ffi::reflection;
50 refl::ObjectDef<StmtObj>().def_ro(
"loc", &
StmtObj::loc, refl::AttachFieldFlag::SEqHashIgnore());
61class Stmt :
public ffi::ObjectRef {
63 explicit Stmt(ffi::ObjectPtr<StmtObj> node) : ffi::ObjectRef(std::move(node)) {
64 TVM_FFI_CHECK(defined(), ValueError) <<
"Stmt expects a defined node";
80 size_t size()
const {
return seq.size(); }
102 :
SeqStmt(ffi::Array<
Stmt>(seq), std::move(loc)) {}
105 size_t size()
const {
return operator->()->size(); }
110 explicit SeqStmt(ffi::ObjectPtr<SeqStmtObj> node) :
Stmt(std::move(node)) {}
121struct TypeTraits<
SeqStmt> :
public ObjectRefWithFallbackTraitsBase<SeqStmt, Stmt, Array<Stmt>> {
146 namespace refl = tvm::ffi::reflection;
147 refl::ObjectDef<BindObj>()
148 .def_ro(
"var", &
BindObj::var, refl::AttachFieldFlag::SEqHashDefSimple())
162 explicit Bind(ffi::ObjectPtr<BindObj> node) :
Stmt(std::move(node)) {}
208 namespace refl = tvm::ffi::reflection;
209 refl::ObjectDef<RegionStmtObj>()
214 refl::AttachFieldFlag::SEqHashDefSimple())
217 refl::AttachFieldFlag::SEqHashDefSimple());
229 explicit RegionStmt(ffi::ObjectPtr<RegionStmtObj> node) :
Stmt(std::move(node)) {}
245inline constexpr ffi::reflection::AttrKey<
246 ffi::reflection::NativeFunctionView<ffi::Array<Var>(
const CallObj* call)>>
249inline constexpr ffi::reflection::AttrKey<
250 ffi::reflection::NativeFunctionView<void(
const RegionStmtObj*)>>
282 namespace refl = tvm::ffi::reflection;
283 refl::ObjectDef<AssertStmtObj>()
300 explicit AssertStmt(ffi::ObjectPtr<AssertStmtObj> node) :
Stmt(std::move(node)) {}
329 namespace refl = tvm::ffi::reflection;
330 refl::ObjectDef<TensorStoreObj>()
355inline constexpr ffi::reflection::AttrKey<ffi::reflection::NativeFunctionView<void(
356 const Expr&,
const ffi::Array<PrimExpr>&,
const PrimExpr&)>>
376 namespace refl = tvm::ffi::reflection;
392 explicit Evaluate(ffi::ObjectPtr<EvaluateObj> node) :
Stmt(std::move(node)) {}
416 namespace refl = tvm::ffi::reflection;
417 refl::ObjectDef<IfObj>()
434 explicit If(ffi::ObjectPtr<IfObj> node) :
Stmt(std::move(node)) {}
504 namespace refl = tvm::ffi::reflection;
505 refl::ObjectDef<ForObj>()
506 .def_ro(
"var", &
ForObj::var, refl::AttachFieldFlag::SEqHashDefSimple())
514 refl::DefaultValue(ffi::Map<ffi::String, ffi::Any>()));
530 SeqStmt body, ffi::Map<ffi::String, ffi::Any> annotations = {},
533 explicit For(ffi::ObjectPtr<ForObj> node) :
Stmt(std::move(node)) {}
562 namespace refl = tvm::ffi::reflection;
563 refl::ObjectDef<WhileObj>()
578 explicit While(ffi::ObjectPtr<WhileObj> node) :
Stmt(std::move(node)) {}
597 namespace refl = tvm::ffi::reflection;
612 explicit Return(ffi::ObjectPtr<ReturnObj> node) :
Stmt(std::move(node)) {}
624 namespace refl = tvm::ffi::reflection;
625 refl::ObjectDef<BreakObj>();
639 explicit Break(ffi::ObjectPtr<BreakObj> node) :
Stmt(std::move(node)) {}
651 namespace refl = tvm::ffi::reflection;
652 refl::ObjectDef<ContinueObj>();
666 explicit Continue(ffi::ObjectPtr<ContinueObj> node) :
Stmt(std::move(node)) {}
687 TVM_FFI_THROW(InternalError) <<
"Unknown ForKind" << t;
688 TVM_FFI_UNREACHABLE();
Canonical primitive operators and their registration.
#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
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