MCPcopy Index your code
hub / github.com/apache/tvm / IRBuilder

Class IRBuilder

python/tvm/script/ir_builder/base.py:91–202  ·  view source on GitHub ↗

A dialect-agnostic IRBuilder that constructs any IR of TVM. Examples -------- An idiomatic use of this class is to put this inside the with-scope, call dialect-specific methods accordingly. Upon exiting the scope. .. code-block:: python from tvm.script.ir_builder impor

Source from the content-addressed store, hash-verified

89
90@_register_object("script.ir_builder.IRBuilder")
91class IRBuilder(_Object):
92 """A dialect-agnostic IRBuilder that constructs any IR of TVM.
93
94 Examples
95 --------
96 An idiomatic use of this class is to put this inside the with-scope,
97 call dialect-specific methods accordingly. Upon exiting the scope.
98
99 .. code-block:: python
100
101 from tvm.script.ir_builder import tirx as T
102 from tvm.script.ir_builder import IRBuilder
103
104 with IRBuilder() as builder:
105 with T.prim_func(...): # pushes a PrimFuncFrame (subclass of IRBuilderFrame)
106 # to `builder`'s stack of frames
107 buffer = T.match_buffer(...)
108
109 return builder.get() # returns the constructed IR, i.e. tirx.PrimFunc
110 """
111
112 def __init__(self) -> None:
113 """Construct an IRBuilder."""
114 self.__init_handle_by_constructor__(
115 _ffi_api.IRBuilder # type: ignore[attr-defined] # pylint: disable=no-member
116 )
117
118 def __enter__(self) -> "IRBuilder":
119 """Enter the with-scope for IRBuilder, which allows the IRBuilder to be discoverable
120 using `IRBuilder.current()`.
121
122 Examples
123 --------
124 .. code-block:: python
125
126 from tvm.script.ir_builder import IRBuilder
127
128 with IRBuilder() as builder:
129 assert IRBuilder.current() == builder
130
131 """
132 _ffi_api.IRBuilderEnter(self) # type: ignore[attr-defined] # pylint: disable=no-member
133 return self
134
135 def __exit__(self, ptype, value, trace) -> None: # pylint: disable=unused-argument
136 _ffi_api.IRBuilderExit(self) # type: ignore[attr-defined] # pylint: disable=no-member
137
138 @staticmethod
139 def current() -> "IRBuilder":
140 """Get the current IRBuilder put in the with-scope.
141
142 Returns
143 -------
144 builder : IRBuilder
145 The current IRBuilder.
146 """
147 return _ffi_api.IRBuilderCurrent() # type: ignore[attr-defined] # pylint: disable=no-member
148

Callers 15

pre_visit_local_functionFunction · 0.90
gen_irFunction · 0.90
get_relax_matmul_moduleFunction · 0.90
implFunction · 0.90
_calc_adjacent_diff_irFunction · 0.90
gen_irFunction · 0.90
gen_irFunction · 0.90
gen_irFunction · 0.90
irFunction · 0.90
gen_irFunction · 0.90

Calls

no outgoing calls

Tested by 15

get_parallel_matmulFunction · 0.72
get_relax_conv2d_moduleFunction · 0.72
get_modFunction · 0.72
test_function_simpleFunction · 0.72
test_emitsFunction · 0.72
test_dataflow_blockFunction · 0.72
get_relax_conv2d_moduleFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…