tvm
Loading...
Searching...
No Matches
Classes | Functions
tvm::script::ir_builder::ir Namespace Reference

Classes

class  AssertFrame
 Managed reference to AssertFrameObj. More...
 
class  AssertFrameObj
 A frame that represents the assert statement. Proceeds if the condition is true, otherwise aborts with the message. More...
 
class  ElseFrame
 Managed reference to ElseFrameObj. More...
 
class  ElseFrameObj
 A frame that represents else. More...
 
class  ForFrame
 Managed reference to ForFrameObj. More...
 
class  ForFrameObj
 A frame that represents the for loop. More...
 
class  IfFrame
 Managed reference to IfFrameObj. More...
 
class  IfFrameObj
 A frame that represents if statement. More...
 
class  IRModuleFrame
 Managed reference to IRModuleFrameObj. More...
 
class  IRModuleFrameObj
 A frame that represents the IRModule frame with functions and global variables. More...
 
class  RegionFrame
 Managed reference to RegionFrameObj. More...
 
class  RegionFrameObj
 A result-free region with lexical body parameters. More...
 
class  StmtFrame
 Managed reference to StmtFrameObj. More...
 
class  StmtFrameObj
 A shared frame containing a sequence of core IR statements. More...
 
class  ThenFrame
 Managed reference to ThenFrameObj. More...
 
class  ThenFrameObj
 A frame that represents then. More...
 
class  WhileFrame
 Managed reference to WhileFrameObj. More...
 
class  WhileFrameObj
 A frame that represents while loop. More...
 

Functions

TVM_TIRX_DLL IRModuleFrame FindModuleFrame ()
 Find the enclosing IRModule frame, allowing intervening frames.
 
TVM_TIRX_DLL void AddToParent (tvm::Stmt stmt, Location loc)
 Append a statement to the current statement frame or top-level builder result.
 
TVM_TIRX_DLL IRModuleFrame IRModule ()
 The IRModule declaration statement.
 
TVM_TIRX_DLL GlobalVar DeclFunction (const ffi::String &func_name, const BaseFunc &func_signature)
 Declare a Function without given the specific function implementation.
 
TVM_TIRX_DLL void DefFunction (const ffi::String &func_name, const BaseFunc &func)
 Define the function which is declared before.
 
TVM_TIRX_DLL ForFrame For (ForKind kind, PrimExpr start, PrimExpr stop, ffi::Optional< PrimExpr > step=std::nullopt, ffi::Optional< PrimType > dtype=std::nullopt, ffi::Optional< ffi::Map< ffi::String, Any > > annotations=std::nullopt)
 Construct a For statement of the given kind.
 
TVM_TIRX_DLL ForFrame Grid (ffi::Array< ffi::Variant< PrimExpr, ffi::Tuple< PrimExpr, PrimExpr > > > extents, ffi::Optional< PrimType > dtype=std::nullopt)
 The grid For statement.
 
TVM_TIRX_DLL AssertFrame Assert (PrimExpr condition, ffi::String error_kind, ffi::Array< ffi::String > message_parts)
 The assertion statement.
 
TVM_TIRX_DLL WhileFrame While (PrimExpr condition)
 Create a while loop.
 
TVM_TIRX_DLL tvm::Stmt Return (Expr value)
 Create a return statement.
 
TVM_TIRX_DLL tvm::Stmt Break ()
 Create a break statement.
 
TVM_TIRX_DLL tvm::Stmt Continue ()
 Create a continue statement.
 
TVM_TIRX_DLL IfFrame If (PrimExpr condition)
 Create an if statement.
 
TVM_TIRX_DLL ThenFrame Then ()
 Create a then.
 
TVM_TIRX_DLL ElseFrame Else ()
 Create an else.
 
TVM_TIRX_DLL RegionFrame Region (Op op, ffi::Array< Expr > args, ffi::Optional< ffi::Array< Var > > body_params=std::nullopt, DictAttrs attrs=DictAttrs())
 Construct a result-free region with lexical body parameters.
 
TVM_TIRX_DLL tvm::Stmt Evaluate (Expr value)
 Evaluate the input expression.
 

Function Documentation

◆ AddToParent()

TVM_TIRX_DLL void tvm::script::ir_builder::ir::AddToParent ( tvm::Stmt  stmt,
Location  loc 
)

Append a statement to the current statement frame or top-level builder result.

Parameters
stmtThe statement to append, flattening top-level sequences with copy-on-write.
locThe deferred source location, used only when the statement has UnknownLoc. Empty top-level sequences add no statements to an existing result. Existing statement locations and results retained by callers are preserved.
Exceptions
ffi::ErrorIf an existing result is not a statement or the current frame cannot contain statements.

◆ Assert()

TVM_TIRX_DLL AssertFrame tvm::script::ir_builder::ir::Assert ( PrimExpr  condition,
ffi::String  error_kind,
ffi::Array< ffi::String >  message_parts 
)

The assertion statement.

Parameters
conditionThe assertion condition.
error_kindThe error kind (e.g. "RuntimeError", "TypeError", "ValueError").
message_partsThe error message parts (stored as separate fragments in the IR).
Returns
The AssertFrame.

◆ Break()

TVM_TIRX_DLL tvm::Stmt tvm::script::ir_builder::ir::Break ( )

Create a break statement.

Returns
The same statement that was added to the parent frame.

◆ Continue()

TVM_TIRX_DLL tvm::Stmt tvm::script::ir_builder::ir::Continue ( )

Create a continue statement.

Returns
The same statement that was added to the parent frame.

◆ DeclFunction()

TVM_TIRX_DLL GlobalVar tvm::script::ir_builder::ir::DeclFunction ( const ffi::String &  func_name,
const BaseFunc &  func_signature 
)

Declare a Function without given the specific function implementation.

Note
It is usually used in cross-function call. And we can specify the function by DefFunction
Parameters
func_nameThe function unique name.
func_signatureA Function marked with attr::kDeclaration, specifying the signature (i.e. func params and func return type/shape).
Returns
The corresponding GlobalVar.

◆ DefFunction()

TVM_TIRX_DLL void tvm::script::ir_builder::ir::DefFunction ( const ffi::String &  func_name,
const BaseFunc &  func 
)

Define the function which is declared before.

Parameters
func_nameThe function unique name.
funcThe given function implementation

◆ Else()

TVM_TIRX_DLL ElseFrame tvm::script::ir_builder::ir::Else ( )

Create an else.

Returns
The result ElseFrame.

◆ Evaluate()

TVM_TIRX_DLL tvm::Stmt tvm::script::ir_builder::ir::Evaluate ( Expr  value)

Evaluate the input expression.

Parameters
valueThe input expression to evaluate.
Returns
The same statement that was added to the parent frame.

◆ FindModuleFrame()

TVM_TIRX_DLL IRModuleFrame tvm::script::ir_builder::ir::FindModuleFrame ( )

Find the enclosing IRModule frame, allowing intervening frames.

Returns
The enclosing frame, or raise ValueError when there is none.

◆ For()

TVM_TIRX_DLL ForFrame tvm::script::ir_builder::ir::For ( ForKind  kind,
PrimExpr  start,
PrimExpr  stop,
ffi::Optional< PrimExpr >  step = std::nullopt,
ffi::Optional< PrimType >  dtype = std::nullopt,
ffi::Optional< ffi::Map< ffi::String, Any > >  annotations = std::nullopt 
)

Construct a For statement of the given kind.

Parameters
kindThe kind of iteration.
startThe minimum value of iteration.
stopThe maximum value of iteration.
stepThe optional step value of iteration.
dtypeThe optional dtype of the loop var ("int32" or "uint32"). When omitted it is inferred from the bounds.
annotationsThe optional annotations of the For statement.
Returns
The ForFrame.

◆ Grid()

TVM_TIRX_DLL ForFrame tvm::script::ir_builder::ir::Grid ( ffi::Array< ffi::Variant< PrimExpr, ffi::Tuple< PrimExpr, PrimExpr > > >  extents,
ffi::Optional< PrimType >  dtype = std::nullopt 
)

The grid For statement.

Parameters
extentsThe extents of the iteration.
dtypeThe optional dtype of every loop var ("int32" or "uint32"). When omitted each loop var takes the dtype of its own extent.
Returns
The ForFrame.

◆ If()

TVM_TIRX_DLL IfFrame tvm::script::ir_builder::ir::If ( PrimExpr  condition)

Create an if statement.

Parameters
conditionThe condition of if statement.
Returns
The result IfFrame.

◆ IRModule()

TVM_TIRX_DLL IRModuleFrame tvm::script::ir_builder::ir::IRModule ( )

The IRModule declaration statement.

Returns
The IRModuleFrame.

◆ Region()

TVM_TIRX_DLL RegionFrame tvm::script::ir_builder::ir::Region ( Op  op,
ffi::Array< Expr >  args,
ffi::Optional< ffi::Array< Var > >  body_params = std::nullopt,
DictAttrs  attrs = DictAttrs() 
)

Construct a result-free region with lexical body parameters.

Parameters
opThe region operation.
argsOperands evaluated outside the region body.
body_paramsExisting body parameters, or omitted to generate them from the operation.
attrsAdditional operation attributes.

◆ Return()

TVM_TIRX_DLL tvm::Stmt tvm::script::ir_builder::ir::Return ( Expr  value)

Create a return statement.

Parameters
valueThe value to return.
Returns
The same statement that was added to the parent frame.

◆ Then()

TVM_TIRX_DLL ThenFrame tvm::script::ir_builder::ir::Then ( )

Create a then.

Returns
The result ThenFrame.

◆ While()

TVM_TIRX_DLL WhileFrame tvm::script::ir_builder::ir::While ( PrimExpr  condition)

Create a while loop.

Parameters
conditionThe termination condition of the loop.
Returns
The result WhileFrame.