tvm
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
tvm::script::ir_builder::IRBuilderObj Class Reference

A language variant agnostic IRBuilder that constructs any IR of TVM. An idiomatic use of this class is to put this inside the RAII with-scope, call language variant specific methods accordingly. Upon exiting the scope. More...

#include <base.h>

Inheritance diagram for tvm::script::ir_builder::IRBuilderObj:
Collaboration diagram for tvm::script::ir_builder::IRBuilderObj:

Public Member Functions

 TVM_FFI_DECLARE_OBJECT_INFO_FINAL ("script.ir_builder.IRBuilder", IRBuilderObj, ffi::Object)
 
template<typename TFrame >
ffi::Optional< TFrame > FindFrame () const
 Find a frame of the given type in the stack this->frames from top to bottom.
 
template<typename TFrame >
ffi::Optional< TFrame > GetLastFrame () const
 Get the top frame if its type is TFrame.
 
template<typename TObjectRef >
TObjectRef Get () const
 Get the IR being constructed.
 
void PushLoc (Location loc)
 Push a frontend source location for IR constructed in the nested scope.
 
void PopLoc ()
 Pop the innermost frontend source location.
 
Location GetCurrentLoc (Location location=UnknownLoc()) const
 Return the normalized active source loc, including expansion history.
 
ffi::ObjectRef SetCurrentLoc (ffi::ObjectRef obj) const
 Compose active source context onto a supported node or construction frame.
 
ffi::ObjectRef SetLoc (ffi::ObjectRef obj, Location loc) const
 Attach an explicit location composed with the active source-call context.
 

Static Public Member Functions

static void RegisterReflection ()
 

Public Attributes

ffi::Array< IRBuilderFrame > frames
 A stack of context frames in the IRBuilder.
 
ffi::Optional< ffi::ObjectRef > result
 The outcome of IR construction.
 
std::vector< Location > locs
 Active frontend source locations, from outermost to innermost.
 

Static Public Attributes

static constexpr const bool _type_mutable = true
 

Detailed Description

A language variant agnostic IRBuilder that constructs any IR of TVM. An idiomatic use of this class is to put this inside the RAII with-scope, call language variant specific methods accordingly. Upon exiting the scope.

IRModule ConstructModule() {
using namespace tvm::script::ir_builder;
IRBuilder builder;
{
With<IRBuilder> scope(builder);
// Add function declarations and definitions with the chosen language variant builder.
}
return builder->Get<IRModule>();
}
Managed reference class to IRModuleNode.
Definition module.h:255
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
Managed reference to an IRBuilderObj.
Definition base.h:194
TVM_TIRX_DLL IRModuleFrame IRModule()
The IRModule declaration statement.
Definition module.h:248
Definition frame.h:33

Member Function Documentation

◆ FindFrame()

template<typename TFrame >
ffi::Optional< TFrame > tvm::script::ir_builder::IRBuilderObj::FindFrame ( ) const
inline

Find a frame of the given type in the stack this->frames from top to bottom.

Template Parameters
TThe type of the frame to find.
Returns
The frame if found, otherwise std::nullopt.

◆ Get()

template<typename TObjectRef >
TObjectRef tvm::script::ir_builder::IRBuilderObj::Get ( ) const
inline

Get the IR being constructed.

Template Parameters
TObjectRefThe type of the IR being constructed.
Returns
The resulting IR. Throw an exception if the IR is not constructed yet.

◆ GetCurrentLoc()

Location tvm::script::ir_builder::IRBuilderObj::GetCurrentLoc ( Location  location = UnknownLoc()) const

Return the normalized active source loc, including expansion history.

◆ GetLastFrame()

template<typename TFrame >
ffi::Optional< TFrame > tvm::script::ir_builder::IRBuilderObj::GetLastFrame ( ) const
inline

Get the top frame if its type is TFrame.

Template Parameters
TFrameThe assumed type of the last frame on stack.
Returns
The frame if the stack is non-empty and the top of the stack is of type TFrame. Otherwise std::nullopt.

◆ PopLoc()

void tvm::script::ir_builder::IRBuilderObj::PopLoc ( )

Pop the innermost frontend source location.

◆ PushLoc()

void tvm::script::ir_builder::IRBuilderObj::PushLoc ( Location  loc)

Push a frontend source location for IR constructed in the nested scope.

◆ RegisterReflection()

static void tvm::script::ir_builder::IRBuilderObj::RegisterReflection ( )
inlinestatic

◆ SetCurrentLoc()

ffi::ObjectRef tvm::script::ir_builder::IRBuilderObj::SetCurrentLoc ( ffi::ObjectRef  obj) const

Compose active source context onto a supported node or construction frame.

◆ SetLoc()

ffi::ObjectRef tvm::script::ir_builder::IRBuilderObj::SetLoc ( ffi::ObjectRef  obj,
Location  loc 
) const

Attach an explicit location composed with the active source-call context.

◆ TVM_FFI_DECLARE_OBJECT_INFO_FINAL()

tvm::script::ir_builder::IRBuilderObj::TVM_FFI_DECLARE_OBJECT_INFO_FINAL ( "script.ir_builder.IRBuilder"  ,
IRBuilderObj  ,
ffi::Object   
)

Member Data Documentation

◆ _type_mutable

constexpr const bool tvm::script::ir_builder::IRBuilderObj::_type_mutable = true
staticconstexpr

◆ frames

ffi::Array<IRBuilderFrame> tvm::script::ir_builder::IRBuilderObj::frames

A stack of context frames in the IRBuilder.

◆ locs

std::vector<Location> tvm::script::ir_builder::IRBuilderObj::locs

Active frontend source locations, from outermost to innermost.

◆ result

ffi::Optional<ffi::ObjectRef> tvm::script::ir_builder::IRBuilderObj::result

The outcome of IR construction.


The documentation for this class was generated from the following file: