23#ifndef TVM_SCRIPT_IR_BUILDER_FRAME_H_
24#define TVM_SCRIPT_IR_BUILDER_FRAME_H_
26#include <tvm/ffi/reflection/registry.h>
55 ffi::Map<ffi::String, Any>
attrs;
60 namespace refl = tvm::ffi::reflection;
61 refl::ObjectDef<IRModuleFrameObj>()
82 TVM_FFI_ICHECK(data !=
nullptr);
100 ffi::reflection::ObjectDef<StmtFrameObj>().def_ro(
"stmts", &StmtFrameObj::stmts);
141 ffi::Array<tvm::Var> loop_vars, ffi::Array<Range> loop_extents,
148 ffi::Array<ffi::Optional<PrimExpr>>
steps;
153 namespace refl = tvm::ffi::reflection;
154 refl::ObjectDef<ForFrameObj>()
155 .def_ro(
"vars", &ForFrameObj::vars)
156 .def_ro(
"doms", &ForFrameObj::doms);
164 ffi::Optional<ffi::Variant<ffi::String, ffi::Array<ffi::String>>> names);
177 TVM_FFI_ICHECK(data !=
nullptr);
178 data_ = std::move(data);
191 explicit AssertFrameObj(ffi::UnsafeInit tag) : condition(tag), error_kind(tag) {}
194 : condition(std::move(condition)), error_kind(std::move(error_kind)) {}
204 namespace refl = tvm::ffi::reflection;
205 refl::ObjectDef<AssertFrameObj>()
206 .def_ro(
"condition", &AssertFrameObj::condition)
207 .def_ro(
"error_kind", &AssertFrameObj::error_kind)
208 .def_ro(
"message_parts", &AssertFrameObj::message_parts);
228 TVM_FFI_ICHECK(data !=
nullptr);
229 data_ = std::move(data);
253 namespace refl = tvm::ffi::reflection;
254 refl::ObjectDef<RegionFrameObj>()
255 .def_ro(
"op", &RegionFrameObj::op)
256 .def_ro(
"args", &RegionFrameObj::args)
257 .def_ro(
"body_params", &RegionFrameObj::body_params)
258 .def_ro(
"attrs", &RegionFrameObj::attrs);
270 TVM_FFI_ICHECK(data !=
nullptr);
271 data_ = std::move(data);
291 namespace refl = tvm::ffi::reflection;
292 refl::ObjectDef<WhileFrameObj>().def_ro(
"condition", &WhileFrameObj::condition);
312 TVM_FFI_ICHECK(data !=
nullptr);
313 data_ = std::move(data);
337 namespace refl = tvm::ffi::reflection;
338 refl::ObjectDef<IfFrameObj>()
339 .def_ro(
"condition", &IfFrameObj::condition)
340 .def_ro(
"then_stmts", &IfFrameObj::then_stmts)
341 .def_ro(
"else_stmts", &IfFrameObj::else_stmts);
361 TVM_FFI_ICHECK(data !=
nullptr);
374 namespace refl = tvm::ffi::reflection;
375 refl::ObjectDef<ThenFrameObj>();
400 TVM_FFI_ICHECK(data !=
nullptr);
413 namespace refl = tvm::ffi::reflection;
414 refl::ObjectDef<ElseFrameObj>();
439 TVM_FFI_ICHECK(data !=
nullptr);
Statements shared across IR dialects.
#define TVM_TIRX_DLL
Definition base.h:55
Base IRBuilder and frame definitions.
Managed reference to DictAttrsObj.
Definition attrs.h:108
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
Sequence statement.
Definition stmt.h:91
Container of all statements.
Definition stmt.h:61
Managed reference to a string literal.
Definition expr.h:278
A stack frame of the IRBuilder used to keep track of the current scope. Furthermore,...
Definition base.h:48
Location loc
Source context retained until this frame constructs its result.
Definition base.h:55
Managed reference to an IRBuilderFrameObj.
Definition base.h:90
A frame that represents the assert statement. Proceeds if the condition is true, otherwise aborts wit...
Definition frame.h:189
tvm::StringImm error_kind
The error kind, e.g. "RuntimeError", "TypeError", "ValueError".
Definition frame.h:199
static void RegisterReflection()
Definition frame.h:203
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.AssertFrame", AssertFrameObj, StmtFrameObj)
AssertFrameObj(PrimExpr condition, tvm::StringImm error_kind)
Definition frame.h:193
AssertFrameObj(ffi::UnsafeInit tag)
Definition frame.h:191
ffi::Array< tvm::StringImm > message_parts
Error message fragments, concatenated at runtime when assertion fails.
Definition frame.h:201
PrimExpr condition
The PrimExpr to test.
Definition frame.h:197
TVM_TIRX_DLL void ExitWithScope() final
The method called when exiting RAII scope.
Managed reference to AssertFrameObj.
Definition frame.h:225
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(AssertFrame, StmtFrame, AssertFrameObj)
AssertFrame(ffi::ObjectPtr< AssertFrameObj > data)
Definition frame.h:227
A frame that represents else.
Definition frame.h:410
TVM_TIRX_DLL void EnterWithScope() final
The method called when entering RAII scope.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.ElseFrame", ElseFrameObj, StmtFrameObj)
static void RegisterReflection()
Definition frame.h:412
Managed reference to ElseFrameObj.
Definition frame.h:436
ElseFrame(ffi::ObjectPtr< ElseFrameObj > data)
Definition frame.h:438
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ElseFrame, StmtFrame, ElseFrameObj)
A frame that represents the for loop.
Definition frame.h:131
static void RegisterReflection()
Definition frame.h:152
ffi::Array< Range > doms
The domains of iteration.
Definition frame.h:146
FMakeForLoop f_make_for_loop
The for loop generating function.
Definition frame.h:150
ffi::Array< ffi::Optional< PrimExpr > > steps
The optional steps of iteration.
Definition frame.h:148
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.ForFrame", ForFrameObj, StmtFrameObj)
ffi::TypedFunction< tvm::Stmt(ffi::Array< tvm::Var > loop_vars, ffi::Array< Range > loop_extents, ffi::Array< ffi::Optional< PrimExpr > > loop_steps, tvm::SeqStmt loop_body, Location loc)> FMakeForLoop
Functions that generate loop nests.
Definition frame.h:142
ffi::Array< tvm::Var > vars
The loop variable.
Definition frame.h:144
TVM_TIRX_DLL void SetNames(ffi::Optional< ffi::Variant< ffi::String, ffi::Array< ffi::String > > > names)
Apply source target names before entry, preserving variable identity.
TVM_TIRX_DLL void ExitWithScope() final
Construct the loop nest with this frame's stored source location.
Managed reference to ForFrameObj.
Definition frame.h:174
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ForFrame, StmtFrame, ForFrameObj)
ForFrame(ffi::ObjectPtr< ForFrameObj > data)
Definition frame.h:176
A frame that represents the IRModule frame with functions and global variables.
Definition frame.h:45
ffi::Map< GlobalVar, BaseFunc > functions
A map from GlobalVar to global functions and pending declarations.
Definition frame.h:53
static void RegisterReflection()
Definition frame.h:59
ffi::Map< ffi::String, GlobalVar > global_var_map
A map from string names to global variables that ensures global uniqueness.
Definition frame.h:48
TVM_TIRX_DLL void ExitWithScope() final
The method called when exiting RAII scope.
ffi::Map< ffi::String, ffi::Array< GlobalInfo > > global_infos
IRModule's global_infos.
Definition frame.h:57
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.IRModuleFrame", IRModuleFrameObj, IRBuilderFrameObj)
ffi::Map< ffi::String, Any > attrs
IRModule's attributes.
Definition frame.h:55
Managed reference to IRModuleFrameObj.
Definition frame.h:79
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IRModuleFrame, IRBuilderFrame, IRModuleFrameObj)
IRModuleFrame(ffi::ObjectPtr< IRModuleFrameObj > data)
Definition frame.h:81
A frame that represents if statement.
Definition frame.h:323
IfFrameObj(ffi::UnsafeInit tag)
Definition frame.h:325
PrimExpr condition
The condition of the if statement.
Definition frame.h:330
ffi::Optional< ffi::Array< tvm::Stmt > > then_stmts
The statements in the true branch.
Definition frame.h:332
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.IfFrame", IfFrameObj, StmtFrameObj)
ffi::Optional< ffi::Array< tvm::Stmt > > else_stmts
The stetements in the false branch.
Definition frame.h:334
TVM_TIRX_DLL void ExitWithScope() final
The method called when exiting RAII scope.
IfFrameObj(PrimExpr condition)
Definition frame.h:327
static void RegisterReflection()
Definition frame.h:336
Managed reference to IfFrameObj.
Definition frame.h:358
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IfFrame, StmtFrame, IfFrameObj)
IfFrame(ffi::ObjectPtr< IfFrameObj > data)
Definition frame.h:360
A result-free region with lexical body parameters.
Definition frame.h:238
RegionFrameObj(Op op)
Definition frame.h:241
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.RegionFrame", RegionFrameObj, StmtFrameObj)
ffi::Array< Expr > args
Operands evaluated in the enclosing scope.
Definition frame.h:246
RegionFrameObj(ffi::UnsafeInit tag)
Definition frame.h:240
static void RegisterReflection()
Definition frame.h:252
Op op
The operation represented by this region.
Definition frame.h:244
DictAttrs attrs
Additional operation attributes.
Definition frame.h:250
ffi::Array< Var > body_params
Variables defined at entry to the region body.
Definition frame.h:248
TVM_TIRX_DLL void ExitWithScope() final
Construct the region and add it to the enclosing builder frame.
Managed reference to RegionFrameObj.
Definition frame.h:267
RegionFrame(ffi::ObjectPtr< RegionFrameObj > data)
Definition frame.h:269
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(RegionFrame, StmtFrame, RegionFrameObj)
A shared frame containing a sequence of core IR statements.
Definition frame.h:94
ffi::Array< tvm::Stmt > stmts
The statements within this frame.
Definition frame.h:97
static void RegisterReflection()
Definition frame.h:99
TVM_FFI_DECLARE_OBJECT_INFO("script.ir_builder.StmtFrame", StmtFrameObj, IRBuilderFrameObj)
Managed reference to StmtFrameObj.
Definition frame.h:106
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(StmtFrame, IRBuilderFrame, StmtFrameObj)
StmtFrame(ffi::ObjectPtr< StmtFrameObj > data)
Definition frame.h:112
A frame that represents then.
Definition frame.h:371
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.ThenFrame", ThenFrameObj, StmtFrameObj)
static void RegisterReflection()
Definition frame.h:373
TVM_TIRX_DLL void EnterWithScope() final
The method called when entering RAII scope.
Managed reference to ThenFrameObj.
Definition frame.h:397
ThenFrame(ffi::ObjectPtr< ThenFrameObj > data)
Definition frame.h:399
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ThenFrame, StmtFrame, ThenFrameObj)
A frame that represents while loop.
Definition frame.h:281
WhileFrameObj(ffi::UnsafeInit tag)
Definition frame.h:283
WhileFrameObj(PrimExpr condition)
Definition frame.h:285
TVM_TIRX_DLL void ExitWithScope() final
The method called when exiting RAII scope.
static void RegisterReflection()
Definition frame.h:290
PrimExpr condition
The termination condition of while.
Definition frame.h:288
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.WhileFrame", WhileFrameObj, StmtFrameObj)
Managed reference to WhileFrameObj.
Definition frame.h:309
WhileFrame(ffi::ObjectPtr< WhileFrameObj > data)
Definition frame.h:311
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(WhileFrame, StmtFrame, WhileFrameObj)
IRModule that holds the functions and type definitions.
TVM_TIRX_DLL IRModuleFrame FindModuleFrame()
Find the enclosing IRModule frame, allowing intervening frames.
TVM_TIRX_DLL void AddToParent(tvm::Stmt stmt, Location loc)
Append a statement to the current statement frame or top-level builder result.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41