Exemple #1
0
    def test_inline_asm(self):
        """The InlineAsm class from llvmlite.ir has no 'name' attr the refcount
        pruning pass should be tolerant to this"""
        llvm.initialize()
        llvm.initialize_native_target()
        llvm.initialize_native_asmprinter()
        llvm.initialize_native_asmparser()

        @intrinsic
        def bar(tyctx, x, y):
            def codegen(cgctx, builder, sig, args):
                (arg_0, arg_1) = args
                fty = ir.FunctionType(ir.IntType(64), [ir.IntType(64),
                                                       ir.IntType(64)])
                mul = builder.asm(fty, "mov $2, $0; imul $1, $0", "=r,r,r",
                                  (arg_0, arg_1), name="asm_mul",
                                  side_effect=False)
                return impl_ret_untracked(cgctx, builder, sig.return_type, mul)
            return signature(x, x, x), codegen

        @njit(['int64(int64)'])
        def foo(x):
            x += 1
            z = bar(x, 2)
            return z

        self.assertEqual(foo(10), 22) # expect (10 + 1) * 2 = 22
Exemple #2
0
def compile_fnclex(context):
    """
    Compile a function that calls fnclex to workround
    https://support.microsoft.com/en-us/kb/982107
    """
    codegen = context.codegen()
    library = codegen.create_library("kb982107")
    ir_mod = """
define void @fnclex() {
  call void asm sideeffect "fnclex", ""()
  ret void
}
    """
    ll.initialize_native_asmparser()
    library.add_llvm_module(ll.parse_assembly(ir_mod))
    library.finalize()
    return library
Exemple #3
0
 def test_inlineasm(self):
     llvm.initialize_native_asmparser()
     m = self.module(asm=asm_inlineasm)
     tm = self.target_machine()
     asm = tm.emit_assembly(m)
     self.assertIn('nop', asm)
Exemple #4
0
 def test_inlineasm(self):
     llvm.initialize_native_asmparser()
     m = self.module(asm=asm_inlineasm)
     tm = self.target_machine()
     asm = tm.emit_assembly(m)
     self.assertIn('nop', asm)
Exemple #5
0
def setup_llvm():
    llvm.initialize()
    llvm.initialize_native_target()
    llvm.initialize_native_asmprinter()
    llvm.initialize_native_asmparser()