def test_normalize_ir_text_unicode(self): # unicode input out = cgutils.normalize_ir_text(unicode_name2) # str returned self.assertIsInstance(out, str) # try encoding to latin out.encode('latin1')
def test_normalize_ir_text(self): # non-unicode input out = cgutils.normalize_ir_text("abc") # str returned self.assertIsInstance(out, str) # try encoding to latin out.encode("latin1")
def __init__(self, codegen, name): self._codegen = codegen self._name = name self._linking_libraries = [] # maintain insertion order self._final_module = ll.parse_assembly( str(self._codegen._create_empty_module(self._name))) self._final_module.name = cgutils.normalize_ir_text(self._name) self._shared_module = None # Track names of the dynamic globals self._dynamic_globals = []
def add_ir_module(self, ir_module): """ Add a LLVM IR module's contents to this library. """ self._raise_if_finalized() assert isinstance(ir_module, llvmir.Module) ir = cgutils.normalize_ir_text(str(ir_module)) ll_module = ll.parse_assembly(ir) ll_module.name = ir_module.name ll_module.verify() self.add_llvm_module(ll_module)
def remove_redundant_nrt_refct(ll_module): """ Remove redundant reference count operations from the `llvmlite.binding.ModuleRef`. This parses the ll_module as a string and line by line to remove the unnecessary nrt refct pairs within each block. Decref calls are moved after the last incref call in the block to avoid temporarily decref'ing to zero (which can happen due to hidden decref from alias). Note: non-threadsafe due to usage of global LLVMcontext """ # Early escape if NRT_incref is not used try: ll_module.get_function('NRT_incref') except NameError: return ll_module # the optimisation pass loses the name of module as it operates on # strings, so back it up and reset it on completion name = ll_module.name newll = _remove_redundant_nrt_refct(str(ll_module)) new_mod = ll.parse_assembly(newll) new_mod.name = cgutils.normalize_ir_text(name) return new_mod
def _create_empty_module(self, name): ir_module = lc.Module(cgutils.normalize_ir_text(name)) ir_module.triple = ll.get_process_triple() if self._data_layout: ir_module.data_layout = self._data_layout return ir_module