Class IRBuilderObj#

Inheritance Relationships#

Base Type#

  • public ffi::Object

Class Documentation#

class IRBuilderObj : public ffi::Object#

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);
    With<ir::IRModuleFrame> module(ir::IRModule());
// Add function declarations and definitions with the chosen language variant builder.
  }
return builder->Get<IRModule>();
}

Public Functions

template<typename TFrame>
inline ffi::Optional<TFrame> FindFrame() const#

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

Template Parameters:

T – The type of the frame to find.

Returns:

The frame if found, otherwise std::nullopt.

template<typename TFrame>
inline ffi::Optional<TFrame> GetLastFrame() const#

Get the top frame if its type is TFrame.

Template Parameters:

TFrame – The 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.

template<typename TObjectRef>
inline TObjectRef Get() const#

Get the IR being constructed.

Template Parameters:

TObjectRef – The type of the IR being constructed.

Returns:

The resulting IR. Throw an exception if the IR is not constructed yet.

inline int64_t PushLoc(Location loc)#

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

Returns:

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

inline void UpdateLoc(int64_t index, Location loc)#

Update a source location without changing its nested scopes.

Parameters:
  • index – The index returned by PushLoc for a scope that has not been popped.

  • loc – The replacement location for that scope.

inline void PopLoc()#

Pop the innermost frontend source location.

Location ResolveLoc(Location location = UnknownLoc()) const#

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

ffi::ObjectRef AttachLoc(ffi::ObjectRef obj, Location loc = UnknownLoc()) const#

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

Public Members

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.

Public Static Functions

static inline void RegisterReflection()#
static inline int32_t _GetOrAllocRuntimeTypeIndex()#
static inline int32_t RuntimeTypeIndex() noexcept#