1616# under the License.
1717"""Suppliers that are used to guarantee uniqueness of names and GlobalVars."""
1818import tvm
19- from tvm import Object
19+ from tvm import Object , IRModule
2020from . import _ffi_api
2121
2222
@@ -38,6 +38,12 @@ def fresh_name(self, name, add_prefix=True):
3838 def reserve_name (self , name , add_prefix = True ):
3939 return _ffi_api .NameSupply_ReserveName (self , name , add_prefix )
4040
41+ def contains_name (self , name , add_prefix = True ):
42+ return _ffi_api .NameSupply_ContainsName (self , name , add_prefix )
43+
44+ def clear (self ):
45+ return _ffi_api .NameSupply_Clear (self )
46+
4147
4248@tvm ._ffi .register_object ("GlobalVarSupply" )
4349class GlobalVarSupply (Object ):
@@ -48,15 +54,24 @@ class GlobalVarSupply(Object):
4854
4955 Parameters
5056 ----------
51- name_supply: The NameSupply to be used by this GlobalVarSupply.
57+ value: Union[List[IRModule], IRModule, NameSupply]
58+ The IRModules used to build this GlobalVarSupply or a NameSupply.
5259 """
5360
54- def __init__ (self , name_supply = None ):
55- name_supply = name_supply if name_supply is not None else NameSupply ("" )
56- self .__init_handle_by_constructor__ (_ffi_api .GlobalVarSupply , name_supply )
61+ def __init__ (self , value = None ):
62+ if value is None :
63+ name_supply = NameSupply ("" )
64+ self .__init_handle_by_constructor__ (_ffi_api .GlobalVarSupply_NameSupply , name_supply )
65+ elif isinstance (value , (list , tvm .container .Array )):
66+ self .__init_handle_by_constructor__ (_ffi_api .GlobalVarSupply_IRModules , value )
67+ elif isinstance (value , IRModule ):
68+ self .__init_handle_by_constructor__ (_ffi_api .GlobalVarSupply_IRModule , value )
5769
5870 def fresh_global (self , name , add_prefix = True ):
5971 return _ffi_api .GlobalVarSupply_FreshGlobal (self , name , add_prefix )
6072
6173 def unique_global_for (self , name , add_prefix = True ):
6274 return _ffi_api .GlobalVarSupply_UniqueGlobalFor (self , name , add_prefix )
75+
76+ def reserve_global (self , global_var , allow_conflict = False ):
77+ return _ffi_api .GlobalVarSupply_ReserveGlobalVar (self , global_var , allow_conflict )
0 commit comments