def __init__(self): # TODO: come up with a less naive way of handling the symtab and types self.classes = None self.symtab = {} self.typetab = {} self.is_break = False self.current_class = None self.loop_end_blocks = [] self.loop_cond_blocks = [] context = ir.Context() self.module = Module(name='opal-lang', context=context) self.blocks = [] self.scope = {} self._add_builtins() func_ty = ir.FunctionType(ir.VoidType(), []) func = Function(self.module, func_ty, 'main') self.current_function = func entry_block = self.add_block('entry') exit_block = self.add_block('exit') self.function_stack = [func] self.builder = Builder(entry_block) self.exit_blocks = [exit_block] self.block_stack = [entry_block]
def test_nvvm_from_llvm(self): m = Module("test_nvvm_from_llvm") fty = Type.function(Type.void(), [Type.int()]) kernel = m.add_function(fty, name='mycudakernel') bldr = Builder(kernel.append_basic_block('entry')) bldr.ret_void() set_cuda_kernel(kernel) fix_data_layout(m) ptx = llvm_to_ptx(str(m)).decode('utf8') self.assertTrue('mycudakernel' in ptx) if is64bit: self.assertTrue('.address_size 64' in ptx) else: self.assertTrue('.address_size 32' in ptx)
def test_inline_rsqrt(self): mod = Module(__name__) fnty = Type.function(Type.void(), [Type.pointer(Type.float())]) fn = mod.add_function(fnty, 'cu_rsqrt') bldr = Builder(fn.append_basic_block('entry')) rsqrt_approx_fnty = Type.function(Type.float(), [Type.float()]) inlineasm = InlineAsm.get(rsqrt_approx_fnty, 'rsqrt.approx.f32 $0, $1;', '=f,f', side_effect=True) val = bldr.load(fn.args[0]) res = bldr.call(inlineasm, [val]) bldr.store(res, fn.args[0]) bldr.ret_void() # generate ptx nvvm.fix_data_layout(mod) nvvm.set_cuda_kernel(fn) nvvmir = str(mod) ptx = nvvm.llvm_to_ptx(nvvmir) self.assertTrue('rsqrt.approx.f32' in str(ptx))