def test_transform(): #XXX This uses Module transforms, think about Function transforms too. llvmjit.restart() llvmjit.parse(lldeadcode) deadcode = llvmjit.getNamedFunction('deadcode') assert llvmjit.execute(deadcode, 10) == 10 * 2 assert llvmjit.transform(3) #optlevel = [0123] assert llvmjit.execute(deadcode, 20) == 20 * 2
def test_getNamedFunction(): for i in range(3): llvmjit.restart() assert not llvmjit.getNamedFunction('square') assert not llvmjit.getNamedFunction('square') assert llvmjit.parse(llsquare) assert llvmjit.getNamedFunction('square') assert llvmjit.getNamedFunction('square')
def test_execute_translation(): #put this one last because it takes the most time skip_unsupported_platform() llvmjit.restart() def f(x): return execute(llsquare, 'square', x + 5) fn = compile(f, [int]) res = fn(1) assert res == 36
def test_transform( ): #XXX This uses Module transforms, think about Function transforms too. llvmjit.restart() llvmjit.parse(lldeadcode) deadcode = llvmjit.getNamedFunction('deadcode') assert llvmjit.execute(deadcode, 10) == 10 * 2 assert llvmjit.transform(3) #optlevel = [0123] assert llvmjit.execute(deadcode, 20) == 20 * 2
def test_getNamedFunction(): for i in range(3): llvmjit.restart() assert not llvmjit.getNamedFunction('square') assert not llvmjit.getNamedFunction('square') assert llvmjit.parse(llsquare) assert llvmjit.getNamedFunction('square') assert llvmjit.getNamedFunction('square')
def test_execute_multiple(): llvmjit.restart() llvmjit.parse(llsquare) llvmjit.parse(llmul2) square = llvmjit.getNamedFunction('square') mul2 = llvmjit.getNamedFunction('mul2') for i in range(5): assert llvmjit.execute(square, i) == i * i assert llvmjit.execute(mul2, i) == i * 2
def test_execute_multiple(): llvmjit.restart() llvmjit.parse(llsquare) llvmjit.parse(llmul2) square = llvmjit.getNamedFunction('square') mul2 = llvmjit.getNamedFunction('mul2') for i in range(5): assert llvmjit.execute(square, i) == i * i assert llvmjit.execute(mul2 , i) == i * 2
def test_execute_translation( ): #put this one last because it takes the most time skip_unsupported_platform() llvmjit.restart() def f(x): return execute(llsquare, 'square', x + 5) fn = compile(f, [int]) res = fn(1) assert res == 36
def test_call_global_function(): #used by PyPy JIT for adding case(s) to a flexswitch llvmjit.restart() gp_function = llvmjit.get_pointer_to_global_function() llvmjit.parse(llcall_global_function) p = llvmjit.getNamedFunction('my_global_function...') assert not p p = llvmjit.getNamedFunction('my_global_function') assert p llvmjit.addGlobalMapping(p, gp_function) #prior to execute()! call_global_function = llvmjit.getNamedFunction('call_global_function') assert llvmjit.execute(call_global_function, 5) == 3 + 5 + 7
def test_call_global_function( ): #used by PyPy JIT for adding case(s) to a flexswitch llvmjit.restart() gp_function = llvmjit.get_pointer_to_global_function() llvmjit.parse(llcall_global_function) p = llvmjit.getNamedFunction('my_global_function...') assert not p p = llvmjit.getNamedFunction('my_global_function') assert p llvmjit.addGlobalMapping(p, gp_function) #prior to execute()! call_global_function = llvmjit.getNamedFunction('call_global_function') assert llvmjit.execute(call_global_function, 5) == 3 + 5 + 7
def test_modify_global_data(): llvmjit.restart() llvmjit.set_global_data(10) assert llvmjit.get_global_data() == 10 gp_data = llvmjit.get_pointer_to_global_data() llvmjit.parse(llglobalmul4) p = llvmjit.getNamedGlobal('my_global_data...') assert not p p = llvmjit.getNamedGlobal('my_global_data') assert p llvmjit.addGlobalMapping(p, gp_data) #note: should be prior to execute() globalmul4 = llvmjit.getNamedFunction('globalmul4') assert llvmjit.execute(globalmul4, 5) == 10 * 4 + 5 assert llvmjit.get_global_data() == 10 * 4 + 5
def test_modify_global_data(): llvmjit.restart() llvmjit.set_global_data(10) assert llvmjit.get_global_data() == 10 gp_data = llvmjit.get_pointer_to_global_data() llvmjit.parse(llglobalmul4) p = llvmjit.getNamedGlobal('my_global_data...') assert not p p = llvmjit.getNamedGlobal('my_global_data') assert p llvmjit.addGlobalMapping(p, gp_data) #note: should be prior to execute() globalmul4 = llvmjit.getNamedFunction('globalmul4') assert llvmjit.execute(globalmul4, 5) == 10 * 4 + 5 assert llvmjit.get_global_data() == 10 * 4 + 5
def test_recompile(): py.test.skip("recompile new function implementation test is work in progress") def funcA(n): return n + n def funcB(n): return n * n llvmjit.restart() llvmjit.parse(llfuncA) _llfuncA = llvmjit.getNamedFunction('func') print '_llfuncA', _llfuncA for i in range(5): assert llvmjit.execute(_llfuncA, i) == funcA(i) llvmjit.freeMachineCodeForFunction(_llfuncA) llvmjit.parse(llfuncB) _llfuncB = llvmjit.getNamedFunction('func') print '_llfuncB', _llfuncB llvmjit.recompile(_llfuncB) #note: because %func has changed because of the 2nd parse for i in range(5): assert llvmjit.execute(_llfuncB, i) == funcB(i)
def test_execute_across_module(): def my_across1(n): return n * 3 def my_across1to2(n): return my_across2(n + 5) def my_across2(n): return n * 7 def my_across2to1(n): return my_across1(n + 9) llvmjit.restart() llvmjit.parse(llacross1) llvmjit.parse(llacross2) across1to2 = llvmjit.getNamedFunction('across1to2') across2to1 = llvmjit.getNamedFunction('across2to1') for i in range(5): assert llvmjit.execute(across1to2, i) == my_across1to2(i) assert llvmjit.execute(across2to1, i) == my_across2to1(i)
def test_execute_across_module(): def my_across1(n): return n * 3 def my_across1to2(n): return my_across2(n + 5) def my_across2(n): return n * 7 def my_across2to1(n): return my_across1(n + 9) llvmjit.restart() llvmjit.parse(llacross1) llvmjit.parse(llacross2) across1to2 = llvmjit.getNamedFunction('across1to2') across2to1 = llvmjit.getNamedFunction('across2to1') for i in range(5): assert llvmjit.execute(across1to2, i) == my_across1to2(i) assert llvmjit.execute(across2to1, i) == my_across2to1(i)
def test_recompile(): py.test.skip( "recompile new function implementation test is work in progress") def funcA(n): return n + n def funcB(n): return n * n llvmjit.restart() llvmjit.parse(llfuncA) _llfuncA = llvmjit.getNamedFunction('func') print '_llfuncA', _llfuncA for i in range(5): assert llvmjit.execute(_llfuncA, i) == funcA(i) llvmjit.freeMachineCodeForFunction(_llfuncA) llvmjit.parse(llfuncB) _llfuncB = llvmjit.getNamedFunction('func') print '_llfuncB', _llfuncB llvmjit.recompile( _llfuncB) #note: because %func has changed because of the 2nd parse for i in range(5): assert llvmjit.execute(_llfuncB, i) == funcB(i)
def test_parse(): llvmjit.restart() assert llvmjit.parse(llsquare)
def test_execute(): llvmjit.restart() assert execute(llsquare, 'square', 4) == 4 * 4
def test_execute_nothing(): llvmjit.restart() assert llvmjit.execute(None, 4) == -1 #-1 == no function supplied
def test_execute(): llvmjit.restart() assert execute(llsquare, 'square', 4) == 4 * 4
def test_parse(): llvmjit.restart() assert llvmjit.parse(llsquare)
def test_execute_nothing(): llvmjit.restart() assert llvmjit.execute(None, 4) == -1 #-1 == no function supplied