IRModule that holds functions and type definitions. IRModule is the basic unit for all IR transformations across the stack. Parameters ---------- functions: Optional[dict]. Map of global var to BaseFunc
| 29 | |
| 30 | @tvm_ffi.register_object("ir.IRModule") |
| 31 | class IRModule(Node, Scriptable): |
| 32 | """IRModule that holds functions and type definitions. |
| 33 | |
| 34 | IRModule is the basic unit for all IR transformations across the stack. |
| 35 | |
| 36 | Parameters |
| 37 | ---------- |
| 38 | functions: Optional[dict]. |
| 39 | Map of global var to BaseFunc |
| 40 | """ |
| 41 | |
| 42 | def __init__(self, functions=None, attrs=None, global_infos=None): |
| 43 | if functions is None: |
| 44 | functions = {} |
| 45 | elif isinstance(functions, dict): |
| 46 | mapped_funcs = {} |
| 47 | for k, v in functions.items(): |
| 48 | if isinstance(k, str): |
| 49 | k = _expr.GlobalVar(k) |
| 50 | if not isinstance(k, _expr.GlobalVar): |
| 51 | raise TypeError("Expect functions to be Dict[GlobalVar, Function]") |
| 52 | mapped_funcs[k] = v |
| 53 | functions = mapped_funcs |
| 54 | |
| 55 | attrs = None if not attrs else attrs |
| 56 | if attrs is not None: |
| 57 | attrs = tvm.ir.make_node("ir.DictAttrs", **attrs) |
| 58 | if global_infos is None: |
| 59 | global_infos = {} |
| 60 | self.__init_handle_by_constructor__( |
| 61 | _ffi_api.IRModule, |
| 62 | functions, |
| 63 | attrs, |
| 64 | global_infos, |
| 65 | ) |
| 66 | self.pyfuncs = {} |
| 67 | |
| 68 | def clone(self) -> "IRModule": |
| 69 | return _ffi_api.Module_Clone(self) |
| 70 | |
| 71 | def functions_items(self): |
| 72 | """Get items in self.functions.items() in alphabetical order. |
| 73 | |
| 74 | Returns |
| 75 | ------- |
| 76 | items: List[Tuple[GlobalVar, Function]] |
| 77 | The functions items. |
| 78 | """ |
| 79 | items = list(self.functions.items()) |
| 80 | items.sort(key=lambda item: str(item[0].name_hint)) |
| 81 | return items |
| 82 | |
| 83 | def __setitem__(self, var, val): |
| 84 | """Add a mapping to the module. |
| 85 | |
| 86 | Parameters |
| 87 | --------- |
| 88 | var: GlobalVar |
no outgoing calls
searching dependent graphs…