23 #ifndef TVM_RELAX_EXEC_BUILDER_H_
24 #define TVM_RELAX_EXEC_BUILDER_H_
26 #include <tvm/ffi/function.h>
27 #include <tvm/ffi/reflection/registry.h>
35 #include <unordered_map>
65 Optional<Array<String>> param_names,
67 int64_t init_register_size = 0);
119 template <
typename T>
123 return ConvertConstant_(rv);
133 ObjectPtr<vm::VMExecutable>
Get();
142 refl::ObjectDef<ExecBuilderNode>();
145 static constexpr
const char*
_type_key =
"relax.ExecBuilder";
163 void CheckExecutable();
170 ObjectPtr<vm::VMExecutable> exec_;
172 std::unordered_map<ffi::Any, vm::Index, StructuralHash, StructuralEqual> const_dedup_map_;
The bytecode for the virtual machine.
A builder provides api to build VM executable with instructions.
Definition: exec_builder.h:48
void EndFunction(const std::string &func)
Annotate the end of a vm function.
TVM_DECLARE_FINAL_OBJECT_INFO(ExecBuilderNode, Object)
void EmitGoto(vm::Index pc_offset)
Emit a goto instruction.
void EmitCall(vm::Instruction::Arg func, std::vector< vm::Instruction::Arg > args, vm::RegName ret)
Emit a call instruction with func as argument.
static constexpr const char * _type_key
Definition: exec_builder.h:145
vm::VMExecutable * exec() const
Raw access to underlying executable build in progress.
static void RegisterReflection()
Definition: exec_builder.h:140
static ExecBuilder Create()
Create an ExecBuilder.
vm::Instruction::Arg GetFunction(const std::string &name)
Get function index by its name.
ObjectPtr< vm::VMExecutable > Get()
Finalize the build, run formalize and get the final result.
void EmitCall(const std::string &func, std::vector< vm::Instruction::Arg > args, vm::RegName ret)
Emit a call instruction for a packed function.
void EmitFunction(const std::string &func, int64_t num_inputs, Optional< Array< String >> param_names, vm::VMFuncInfo::FuncKind kind=vm::VMFuncInfo::FuncKind::kVMFunc, int64_t init_register_size=0)
To annotate the start of a vm function.
vm::Instruction::Arg ConvertConstant(T value)
Convert a constant value something that exec builder can understand.
Definition: exec_builder.h:120
void DeclareFunction(const std::string &func, vm::VMFuncInfo::FuncKind kind)
Declare a function, it is OK to have multiple declarations.
void EmitIf(vm::Instruction::Arg cond, vm::Index false_offset)
Emit an If instruction.
void EmitRet(vm::Instruction::Arg result)
Emit a ret instruction.
Definition: exec_builder.h:175
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(ExecBuilder, ObjectRef, ExecBuilderNode)
The virtual machine executable emitted by the VM compiler.
Definition: executable.h:88
Definition: repr_printer.h:91
ExecWord Index
An alias for the integer type used ubiquitously in the VM.
Definition: bytecode.h:48
ExecWord RegName
A register name.
Definition: bytecode.h:43
tvm::relax::Var Arg(const String &name, const tvm::relax::StructInfo &struct_info)
Add a parameter to the last function frame.
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
PrimExpr ret(PrimExpr value, Span span=Span())
Return the value.
A managed object in the TVM runtime.
Printer class to print repr string of each AST/IR nodes.
FuncKind
kind of the function.
Definition: executable.h:54