19#ifndef TVM_RELAX_SCRIPT_IR_BUILDER_FRAME_H_
20#define TVM_RELAX_SCRIPT_IR_BUILDER_FRAME_H_
22#include <tvm/ffi/reflection/registry.h>
40 namespace refl = tvm::ffi::reflection;
41 refl::ObjectDef<RelaxFrameObj>();
50 TVM_FFI_ICHECK(data !=
nullptr);
51 data_ = std::move(data);
67 ffi::Optional<tvm::relax::Expr>
output;
70 namespace refl = tvm::ffi::reflection;
71 refl::ObjectDef<SeqExprFrameObj>()
86 TVM_FFI_ICHECK(data !=
nullptr);
101 ffi::Optional<ffi::String>
name;
131 namespace refl = tvm::ffi::reflection;
132 refl::ObjectDef<FunctionFrameObj>()
155 TVM_FFI_ICHECK(data !=
nullptr);
182 namespace refl = tvm::ffi::reflection;
183 refl::ObjectDef<BindingBlockFrameObj>()
184 .def_ro(
"is_dataflow", &BindingBlockFrameObj::is_dataflow)
185 .def_ro(
"emitted_vars", &BindingBlockFrameObj::emitted_vars)
186 .def_ro(
"output_vars", &BindingBlockFrameObj::output_vars);
194 void ExitWithScope() final;
200 TVM_FFI_ICHECK(data !=
nullptr);
214 explicit IfFrameObj(ffi::UnsafeInit) : condition(ffi::UnsafeInit{}) {}
223 ffi::Optional<tvm::Var>
var;
228 namespace refl = tvm::ffi::reflection;
229 refl::ObjectDef<IfFrameObj>()
230 .def_ro(
"condition", &IfFrameObj::condition)
231 .def_ro(
"then_expr", &IfFrameObj::then_expr)
232 .def_ro(
"else_expr", &IfFrameObj::else_expr)
233 .def_ro(
"var", &IfFrameObj::var)
234 .def_ro(
"var_name", &IfFrameObj::var_name);
248 void ExitWithScope() final;
259 TVM_FFI_ICHECK(data !=
nullptr);
272 namespace refl = tvm::ffi::reflection;
273 refl::ObjectDef<ThenFrameObj>();
288 void ExitWithScope() final;
299 TVM_FFI_ICHECK(data !=
nullptr);
312 namespace refl = tvm::ffi::reflection;
313 refl::ObjectDef<ElseFrameObj>();
328 void ExitWithScope() final;
339 TVM_FFI_ICHECK(data !=
nullptr);
Base IRBuilder and frame definitions.
Shared IRBuilder frames for IRModules and statements.
Shared IRBuilder APIs for IRModule construction.
The utility for constructing Relax binding blocks.
Managed reference to ExprObj.
Definition expr.h:101
Definition block_builder.h:262
A stack frame of the IRBuilder used to keep track of the current scope. Furthermore,...
Definition base.h:48
Managed reference to an IRBuilderFrameObj.
Definition base.h:90
The ir_builder frame for relax binding blocks.
Definition frame.h:161
ffi::Map< tvm::Var, Location > binding_locs
Statement ranges for explicitly emitted bindings.
Definition frame.h:179
ffi::Array< tvm::Var > output_vars
The output vars of the dataflow block.
Definition frame.h:177
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.relax.BindingBlockFrame", BindingBlockFrameObj, RelaxFrameObj)
void EnterWithScope() final
The method called when entering RAII scope.
ffi::Array< tvm::Var > emitted_vars
The variables emitted in this block.
Definition frame.h:166
static void RegisterReflection()
Definition frame.h:181
bool block_ended
A boolean indicating if the dataflow block is ended of construction. If it is true,...
Definition frame.h:172
bool is_dataflow
The flag that indicates whether the block is a dataflow block.
Definition frame.h:164
BindingBlockFrame(ffi::ObjectPtr< BindingBlockFrameObj > data)
Definition frame.h:199
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(BindingBlockFrame, RelaxFrame, BindingBlockFrameObj)
A frame that represents else.
Definition frame.h:309
static void RegisterReflection()
Definition frame.h:311
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.relax.ElseFrame", ElseFrameObj, SeqExprFrameObj)
void EnterWithScope() final
The method called when entering RAII scope.
Managed reference to ElseFrameObj.
Definition frame.h:336
ElseFrame(ffi::ObjectPtr< ElseFrameObj > data)
Definition frame.h:338
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ElseFrame, SeqExprFrame, ElseFrameObj)
The ir_builder frame for the relax function.
Definition frame.h:92
void EnterWithScope() final
The method called when entering RAII scope.
ffi::Optional< bool > is_pure
Whether the function is annotated as pure.
Definition frame.h:115
ffi::Optional< bool > is_private
Whether the function is annotated as private.
Definition frame.h:117
static void RegisterReflection()
Definition frame.h:130
ffi::Optional< tvm::GlobalVar > global_var
Definition frame.h:128
FunctionFrameObj(ffi::UnsafeInit)
Definition frame.h:95
tvm::relax::BlockBuilder block_builder
The block builder to create Relax function.
Definition frame.h:121
void ExitWithScope() final
The method called when exiting RAII scope.
ffi::Map< ffi::String, Any > attrs
The function attributes.
Definition frame.h:119
ffi::Optional< ffi::String > name
The function name.
Definition frame.h:101
FunctionFrameObj(tvm::relax::BlockBuilder builder)
Definition frame.h:94
ffi::Optional< tvm::Type > ret_ty
The function return type.
Definition frame.h:113
ffi::Optional< tvm::Var > local_var
Definition frame.h:125
ffi::Optional< tvm::relax::Function > function
Finalized function and its stable module reference.
Definition frame.h:127
bool local
Definition frame.h:124
ffi::Array< tvm::Var > params
The function params.
Definition frame.h:103
bool declaration
Whether this frame constructs only a function signature.
Definition frame.h:123
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.relax.FunctionFrame", FunctionFrameObj, SeqExprFrameObj)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(FunctionFrame, SeqExprFrame, FunctionFrameObj)
FunctionFrame(ffi::ObjectPtr< FunctionFrameObj > data)
Definition frame.h:154
A frame that represents if statement.
Definition frame.h:211
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.relax.IfFrame", IfFrameObj, RelaxFrameObj)
ffi::Optional< tvm::relax::Expr > else_expr
The Bindings in the false branch.
Definition frame.h:221
IfFrameObj(ffi::UnsafeInit)
Definition frame.h:214
IfFrameObj(tvm::relax::Expr condition)
Definition frame.h:213
ffi::String var_name
The binding var name.
Definition frame.h:225
void EnterWithScope() final
The method called when entering RAII scope.
ffi::Optional< tvm::Var > var
The Binding var.
Definition frame.h:223
tvm::relax::Expr condition
The condition of the if statement.
Definition frame.h:217
static void RegisterReflection()
Definition frame.h:227
ffi::Optional< tvm::relax::Expr > then_expr
The Bindings in the true branch.
Definition frame.h:219
Managed reference to IfFrameObj.
Definition frame.h:256
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IfFrame, RelaxFrame, IfFrameObj)
IfFrame(ffi::ObjectPtr< IfFrameObj > data)
Definition frame.h:258
The base ir_builder frame for the relax dialect.
Definition frame.h:37
static void RegisterReflection()
Definition frame.h:39
TVM_FFI_DECLARE_OBJECT_INFO("script.ir_builder.relax.RelaxFrame", RelaxFrameObj, IRBuilderFrameObj)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(RelaxFrame, IRBuilderFrame, RelaxFrameObj)
RelaxFrame(ffi::ObjectPtr< RelaxFrameObj > data)
Definition frame.h:49
The base ir_builder frame for frames with SeqExpr i.e. Functions, IfExpr branches.
Definition frame.h:62
static void RegisterReflection()
Definition frame.h:69
ffi::Array< tvm::relax::BindingBlock > binding_blocks
The binding blocks inside the frame.
Definition frame.h:65
TVM_FFI_DECLARE_OBJECT_INFO("script.ir_builder.relax.SeqExprFrame", SeqExprFrameObj, RelaxFrameObj)
void ExitWithScope() override
The method called when exiting RAII scope.
void EnterWithScope() override
The method called when entering RAII scope.
ffi::Optional< tvm::relax::Expr > output
The frame output expr. std::nullopt when undefined.
Definition frame.h:67
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SeqExprFrame, RelaxFrame, SeqExprFrameObj)
SeqExprFrame(ffi::ObjectPtr< SeqExprFrameObj > data)
Definition frame.h:85
A frame that represents then.
Definition frame.h:269
static void RegisterReflection()
Definition frame.h:271
void EnterWithScope() final
The method called when entering RAII scope.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.relax.ThenFrame", ThenFrameObj, SeqExprFrameObj)
Managed reference to ThenFrameObj.
Definition frame.h:296
ThenFrame(ffi::ObjectPtr< ThenFrameObj > data)
Definition frame.h:298
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ThenFrame, SeqExprFrame, ThenFrameObj)
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41