Skip to content

Commit 2f0af50

Browse files
committed
Always use cgutils for add_global_variable
1 parent 9e6c9e6 commit 2f0af50

5 files changed

Lines changed: 20 additions & 15 deletions

File tree

‎numba/core/base.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def get_c_value(self, builder, typ, name, dllimport=False):
766766
try:
767767
gv = module.get_global_variable_named(name)
768768
except LLVMException:
769-
gv = module.add_global_variable(typ, name)
769+
gv = cgutils.add_global_variable(module, typ, name)
770770
if dllimport and self.aot_mode and sys.platform == 'win32':
771771
gv.storage_class = "dllimport"
772772
return gv
@@ -1087,7 +1087,7 @@ def add_dynamic_addr(self, builder, intaddr, info):
10871087
addr = self.get_constant(types.uintp, intaddr).inttoptr(llvoidptr)
10881088
# Use a unique name by embedding the address value
10891089
symname = 'numba.dynamic.globals.{:x}'.format(intaddr)
1090-
gv = mod.add_global_variable(llvoidptr, name=symname)
1090+
gv = cgutils.add_global_variable(mod, llvoidptr, symname)
10911091
# Use linkonce linkage to allow merging with other GV of the same name.
10921092
# And, avoid optimization from assuming its value.
10931093
gv.linkage = 'linkonce'

‎numba/cuda/nvvmutils.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ def insert_addrspace_conv(lmod, elemtype, addrspace):
176176
def declare_string(builder, value):
177177
lmod = builder.basic_block.function.module
178178
cval = cgutils.make_bytearray(value.encode("utf-8") + b"\x00")
179-
gl = lmod.add_global_variable(cval.type, name="_str",
180-
addrspace=nvvm.ADDRSPACE_CONSTANT)
179+
gl = cgutils.add_global_variable(lmod, cval.type, name="_str",
180+
addrspace=nvvm.ADDRSPACE_CONSTANT)
181181
gl.linkage = 'internal'
182182
gl.global_constant = True
183183
gl.initializer = cval

‎numba/pycc/compiler.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,9 @@ def _emit_method_array(self, llvm_module):
244244
sentinel = lc.Constant.struct([NULL, NULL, ZERO, NULL])
245245
method_defs.append(sentinel)
246246
method_array_init = lc.Constant.array(self.method_def_ty, method_defs)
247-
method_array = llvm_module.add_global_variable(method_array_init.type,
248-
'.module_methods')
247+
method_array = cgutils.add_global_variable(llvm_module,
248+
method_array_init.type,
249+
'.module_methods')
249250
method_array.initializer = method_array_init
250251
method_array.linkage = lc.LINKAGE_INTERNAL
251252
method_array_ptr = lc.Constant.gep(method_array, [ZERO, ZERO])
@@ -405,8 +406,9 @@ def _emit_python_wrapper(self, llvm_module):
405406
lc.Constant.null(lt._pyobject_head_p), # m_copy
406407
)
407408
)
408-
mod_def_base = llvm_module.add_global_variable(mod_def_base_init.type,
409-
'.module_def_base')
409+
mod_def_base = cgutils.add_global_variable(llvm_module,
410+
mod_def_base_init.type,
411+
'.module_def_base')
410412
mod_def_base.initializer = mod_def_base_init
411413
mod_def_base.linkage = lc.LINKAGE_INTERNAL
412414

@@ -426,8 +428,8 @@ def _emit_python_wrapper(self, llvm_module):
426428
)
427429

428430
# Define a constant string for the module name.
429-
mod_def = llvm_module.add_global_variable(mod_def_init.type,
430-
'.module_def')
431+
mod_def = cgutils.add_global_variable(llvm_module, mod_def_init.type,
432+
'.module_def')
431433
mod_def.initializer = mod_def_init
432434
mod_def.linkage = lc.LINKAGE_INTERNAL
433435

‎numba/roc/hsaimpl.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ def _generic_array(context, builder, shape, dtype, symbol_name, addrspace):
264264
lmod = builder.module
265265

266266
# Create global variable in the requested address-space
267-
gvmem = lmod.add_global_variable(laryty, symbol_name, addrspace)
267+
gvmem = cgutils.add_global_variable(lmod, laryty, symbol_name,
268+
addrspace)
268269

269270
if elemcount <= 0:
270271
raise ValueError("array length <= 0")

‎numba/roc/target.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def set_hsa_kernel(fn):
212212
fn.calling_convention = CC_SPIR_KERNEL
213213

214214
# Mark kernels
215-
ocl_kernels = mod.get_or_insert_named_metadata("opencl.kernels")
215+
ocl_kernels = cgutils.get_or_insert_named_metadata(mod, "opencl.kernels")
216216
ocl_kernels.add(lc.MetaData.get(mod, [fn,
217217
gen_arg_addrspace_md(fn),
218218
gen_arg_access_qual_md(fn),
@@ -224,11 +224,13 @@ def set_hsa_kernel(fn):
224224
make_constant = lambda x: lc.Constant.int(lc.Type.int(), x)
225225
spir_version_constant = [make_constant(x) for x in SPIR_VERSION]
226226

227-
spir_version = mod.get_or_insert_named_metadata("opencl.spir.version")
227+
spir_version = cgutils.get_or_insert_named_metadata(mod,
228+
"opencl.spir.version")
228229
if not spir_version.operands:
229230
spir_version.add(lc.MetaData.get(mod, spir_version_constant))
230231

231-
ocl_version = mod.get_or_insert_named_metadata("opencl.ocl.version")
232+
ocl_version = cgutils.get_or_insert_named_metadata(mod,
233+
"opencl.ocl.version")
232234
if not ocl_version.operands:
233235
ocl_version.add(lc.MetaData.get(mod, spir_version_constant))
234236

@@ -240,7 +242,7 @@ def set_hsa_kernel(fn):
240242
# "opencl.compiler.options"]cat
241243
#
242244
# for name in others:
243-
# nmd = mod.get_or_insert_named_metadata(name)
245+
# nmd = cgutils.get_or_insert_named_metadata(mod, name)
244246
# if not nmd.operands:
245247
# nmd.add(empty_md)
246248

0 commit comments

Comments
 (0)