Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Always use cgutils for add_global_variable
  • Loading branch information
gmarkall committed Mar 10, 2021
commit 2f0af50fb8ed71fc340582b2ef351621629388b8
4 changes: 2 additions & 2 deletions numba/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ def get_c_value(self, builder, typ, name, dllimport=False):
try:
gv = module.get_global_variable_named(name)
except LLVMException:
gv = module.add_global_variable(typ, name)
gv = cgutils.add_global_variable(module, typ, name)
if dllimport and self.aot_mode and sys.platform == 'win32':
gv.storage_class = "dllimport"
return gv
Expand Down Expand Up @@ -1087,7 +1087,7 @@ def add_dynamic_addr(self, builder, intaddr, info):
addr = self.get_constant(types.uintp, intaddr).inttoptr(llvoidptr)
# Use a unique name by embedding the address value
symname = 'numba.dynamic.globals.{:x}'.format(intaddr)
gv = mod.add_global_variable(llvoidptr, name=symname)
gv = cgutils.add_global_variable(mod, llvoidptr, symname)
# Use linkonce linkage to allow merging with other GV of the same name.
# And, avoid optimization from assuming its value.
gv.linkage = 'linkonce'
Expand Down
4 changes: 2 additions & 2 deletions numba/cuda/nvvmutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def insert_addrspace_conv(lmod, elemtype, addrspace):
def declare_string(builder, value):
lmod = builder.basic_block.function.module
cval = cgutils.make_bytearray(value.encode("utf-8") + b"\x00")
gl = lmod.add_global_variable(cval.type, name="_str",
addrspace=nvvm.ADDRSPACE_CONSTANT)
gl = cgutils.add_global_variable(lmod, cval.type, name="_str",
addrspace=nvvm.ADDRSPACE_CONSTANT)
gl.linkage = 'internal'
gl.global_constant = True
gl.initializer = cval
Expand Down
14 changes: 8 additions & 6 deletions numba/pycc/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ def _emit_method_array(self, llvm_module):
sentinel = lc.Constant.struct([NULL, NULL, ZERO, NULL])
method_defs.append(sentinel)
method_array_init = lc.Constant.array(self.method_def_ty, method_defs)
method_array = llvm_module.add_global_variable(method_array_init.type,
'.module_methods')
method_array = cgutils.add_global_variable(llvm_module,
method_array_init.type,
'.module_methods')
method_array.initializer = method_array_init
method_array.linkage = lc.LINKAGE_INTERNAL
method_array_ptr = lc.Constant.gep(method_array, [ZERO, ZERO])
Expand Down Expand Up @@ -405,8 +406,9 @@ def _emit_python_wrapper(self, llvm_module):
lc.Constant.null(lt._pyobject_head_p), # m_copy
)
)
mod_def_base = llvm_module.add_global_variable(mod_def_base_init.type,
'.module_def_base')
mod_def_base = cgutils.add_global_variable(llvm_module,
mod_def_base_init.type,
'.module_def_base')
mod_def_base.initializer = mod_def_base_init
mod_def_base.linkage = lc.LINKAGE_INTERNAL

Expand All @@ -426,8 +428,8 @@ def _emit_python_wrapper(self, llvm_module):
)

# Define a constant string for the module name.
mod_def = llvm_module.add_global_variable(mod_def_init.type,
'.module_def')
mod_def = cgutils.add_global_variable(llvm_module, mod_def_init.type,
'.module_def')
mod_def.initializer = mod_def_init
mod_def.linkage = lc.LINKAGE_INTERNAL

Expand Down
3 changes: 2 additions & 1 deletion numba/roc/hsaimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ def _generic_array(context, builder, shape, dtype, symbol_name, addrspace):
lmod = builder.module

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

if elemcount <= 0:
raise ValueError("array length <= 0")
Expand Down
10 changes: 6 additions & 4 deletions numba/roc/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def set_hsa_kernel(fn):
fn.calling_convention = CC_SPIR_KERNEL

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

spir_version = mod.get_or_insert_named_metadata("opencl.spir.version")
spir_version = cgutils.get_or_insert_named_metadata(mod,
"opencl.spir.version")
if not spir_version.operands:
spir_version.add(lc.MetaData.get(mod, spir_version_constant))

ocl_version = mod.get_or_insert_named_metadata("opencl.ocl.version")
ocl_version = cgutils.get_or_insert_named_metadata(mod,
"opencl.ocl.version")
if not ocl_version.operands:
ocl_version.add(lc.MetaData.get(mod, spir_version_constant))

Expand All @@ -240,7 +242,7 @@ def set_hsa_kernel(fn):
# "opencl.compiler.options"]cat
#
# for name in others:
# nmd = mod.get_or_insert_named_metadata(name)
# nmd = cgutils.get_or_insert_named_metadata(mod, name)
# if not nmd.operands:
# nmd.add(empty_md)

Expand Down