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.
 
int64_t PushLoc (Location loc)
 Push a frontend source location for IR constructed in the nested scope.
 
void UpdateLoc (int64_t index, Location loc)
 Update a source location without changing its nested scopes.
 
void PopLoc ()
 Pop the innermost frontend source location.
 
TVM_TIRX_DLL Location ResolveLoc (Location location=UnknownLoc()) const
 Normalize the full active source stack with an optional explicit location.
 
TVM_TIRX_DLL ffi::ObjectRef AttachLoc (ffi::ObjectRef obj, Location loc=UnknownLoc()) const
 Compose active and explicit source context onto the same supported node or frame.
 

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 IRModuleObj.
Definition module.h:292
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:58
Managed reference to an IRBuilderObj.
Definition base.h:217
TVM_TIRX_DLL IRModuleFrame IRModule()
The IRModule declaration statement.
Definition module.h:285
Definition frame.h:33

Member Function Documentation

◆ AttachLoc()

TVM_TIRX_DLL ffi::ObjectRef tvm::script::ir_builder::IRBuilderObj::AttachLoc ( ffi::ObjectRef  obj,
Location  loc = UnknownLoc() 
) const

Compose active and explicit source context onto the same supported node or frame.

◆ 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.

◆ 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 ( )
inline

Pop the innermost frontend source location.

◆ PushLoc()

int64_t tvm::script::ir_builder::IRBuilderObj::PushLoc ( Location  loc)
inline

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

Returns
The index of the pushed scope, valid until it is popped.

◆ RegisterReflection()

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

◆ ResolveLoc()

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

Normalize the full active source stack with an optional explicit location.

◆ TVM_FFI_DECLARE_OBJECT_INFO_FINAL()

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

◆ UpdateLoc()

void tvm::script::ir_builder::IRBuilderObj::UpdateLoc ( int64_t  index,
Location  loc 
)
inline

Update a source location without changing its nested scopes.

Parameters
indexThe index returned by PushLoc for a scope that has not been popped.
locThe replacement location for that scope.

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: