[pypy-svn] r35109 - in pypy/dist/pypy/jit/codegen/llvm: . lib test
ericvrp at codespeak.net
ericvrp at codespeak.net
Wed Nov 29 11:10:38 CET 2006
Author: ericvrp
Date: Wed Nov 29 11:10:34 2006
New Revision: 35109
Modified:
pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.cpp
pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.h
pypy/dist/pypy/jit/codegen/llvm/llvmjit.py
pypy/dist/pypy/jit/codegen/llvm/test/test_llvmjit.py
Log:
* renamed llvmjit.compile to llvmjit.parse
* added (currently skipped) test for recompiling functions (with different code of course
Modified: pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.cpp
==============================================================================
--- pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.cpp (original)
+++ pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.cpp Wed Nov 29 11:10:34 2006
@@ -76,7 +76,7 @@
}
-int compile(const char* llsource) {
+int parse(const char* llsource) {
Module* module = ParseAssemblyString(llsource, gp_module);
if (!module) {
std::cerr << "Can not parse:\n" << llsource << "\n" << std::flush;
@@ -92,6 +92,28 @@
}
+int freeMachineCodeForFunction(const void* function) {
+ if (!function) {
+ std::cerr << "No function supplied to libllvmjit.freeMachineCodeForFunction(...)\n" << std::flush;
+ return 0;
+ }
+
+ gp_execution_engine->freeMachineCodeForFunction((Function*)function);
+ return 1;
+}
+
+
+int recompile(const void* function) {
+ if (!function) {
+ std::cerr << "No function supplied to libllvmjit.recompile(...)\n" << std::flush;
+ return 0;
+ }
+
+ gp_execution_engine->recompileAndRelinkFunction((Function*)function);
+ return 1;
+}
+
+
int execute(const void* function, int param) { //XXX allow different function signatures
if (!function) {
std::cerr << "No function supplied to libllvmjit.execute(...)\n" << std::flush;
Modified: pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.h
==============================================================================
--- pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.h (original)
+++ pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.h Wed Nov 29 11:10:34 2006
@@ -6,8 +6,10 @@
void restart();
int transform(const char* passnames);
-int compile(const char* llsource);
+int parse(const char* llsource);
void* find_function(const char* funcname);
+int freeMachineCodeForFunction(const void* function);
+int recompile(const void* function);
int execute(const void* function, int param);
int get_global_data();
void set_global_data(int n);
Modified: pypy/dist/pypy/jit/codegen/llvm/llvmjit.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llvm/llvmjit.py (original)
+++ pypy/dist/pypy/jit/codegen/llvm/llvmjit.py Wed Nov 29 11:10:34 2006
@@ -51,14 +51,22 @@
transform.restype = c_int
transform.argtypes = [c_char_p]
-compile = llvmjit.compile
-compile.restype = c_int
-compile.argtypes = [c_char_p]
+parse = llvmjit.parse
+parse.restype = c_int
+parse.argtypes = [c_char_p]
find_function = llvmjit.find_function
find_function.restype = c_void_p
find_function.argtypes = [c_char_p]
+freeMachineCodeForFunction = llvmjit.freeMachineCodeForFunction
+freeMachineCodeForFunction.restype = c_int
+freeMachineCodeForFunction.argtypes = [c_void_p]
+
+recompile = llvmjit.recompile
+recompile.restype = c_int
+recompile.argtypes = [c_void_p]
+
execute = llvmjit.execute
execute.restype = c_int
execute.argtypes = [c_void_p, c_int]
Modified: pypy/dist/pypy/jit/codegen/llvm/test/test_llvmjit.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llvm/test/test_llvmjit.py (original)
+++ pypy/dist/pypy/jit/codegen/llvm/test/test_llvmjit.py Wed Nov 29 11:10:34 2006
@@ -10,9 +10,7 @@
except OSError:
py.test.skip("can not load libllvmjit library (see ../README.TXT)")
-#helper data
-curdir = dirname(__file__)
-
+#
llsquare = '''int %square(int %n) {
%n2 = mul int %n, %n
ret int %n2
@@ -23,6 +21,7 @@
ret int %n2
}'''
+#
lldeadcode = '''int %deadcode(int %n) {
Test:
%cond = seteq int %n, %n
@@ -36,6 +35,18 @@
ret int -1
}'''
+#
+llfuncA = '''int %func(int %n) {
+ %n2 = add int %n, %n
+ ret int %n2
+}'''
+
+llfuncB = '''int %func(int %n) {
+ %n2 = mul int %n, %n
+ ret int %n2
+}'''
+
+#
llacross1 = '''declare int %across2(int)
implementation
@@ -66,6 +77,7 @@
ret int %n3
}'''
+#
llglobalmul4 = '''%my_global_data = external global int
implementation
@@ -80,7 +92,7 @@
#helpers
def execute(llsource, function_name, param):
- assert llvmjit.compile(llsource)
+ assert llvmjit.parse(llsource)
function = llvmjit.find_function(function_name)
assert function
return llvmjit.execute(function, param)
@@ -90,7 +102,7 @@
for i in range(3):
llvmjit.restart()
assert not llvmjit.find_function('square')
- assert llvmjit.compile(llsquare)
+ assert llvmjit.parse(llsquare)
assert llvmjit.find_function('square')
def test_find_function():
@@ -98,13 +110,13 @@
llvmjit.restart()
assert not llvmjit.find_function('square')
assert not llvmjit.find_function('square')
- assert llvmjit.compile(llsquare)
+ assert llvmjit.parse(llsquare)
assert llvmjit.find_function('square')
assert llvmjit.find_function('square')
-def test_compile():
+def test_parse():
llvmjit.restart()
- assert llvmjit.compile(llsquare)
+ assert llvmjit.parse(llsquare)
def test_execute():
llvmjit.restart()
@@ -116,8 +128,8 @@
def test_execute_multiple():
llvmjit.restart()
- llvmjit.compile(llsquare)
- llvmjit.compile(llmul2)
+ llvmjit.parse(llsquare)
+ llvmjit.parse(llmul2)
square = llvmjit.find_function('square')
mul2 = llvmjit.find_function('mul2')
for i in range(5):
@@ -138,17 +150,39 @@
return my_across1(n + 9)
llvmjit.restart()
- llvmjit.compile(llacross1)
- llvmjit.compile(llacross2)
+ llvmjit.parse(llacross1)
+ llvmjit.parse(llacross2)
across1to2 = llvmjit.find_function('across1to2')
across2to1 = llvmjit.find_function('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.find_function('func')
+ print '_llfuncA', _llfuncA
+ for i in range(5):
+ assert llvmjit.execute(_llfuncA, i) == funcA(i)
+ llvmjit.freeMachineCodeForFunction(_llfuncA)
+ llvmjit.parse(llfuncB)
+ _llfuncB = llvmjit.find_function('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_transform(): #XXX This uses Module transforms, think about Function transforms too.
llvmjit.restart()
- llvmjit.compile(lldeadcode)
+ llvmjit.parse(lldeadcode)
deadcode = llvmjit.find_function('deadcode')
assert llvmjit.execute(deadcode, 10) == 10 * 2
@@ -164,7 +198,7 @@
llvmjit.set_global_data(10)
assert llvmjit.get_global_data() == 10
gp_data = llvmjit.get_pointer_to_global_data()
- llvmjit.compile(llglobalmul4)
+ llvmjit.parse(llglobalmul4)
llvmjit.add_global_mapping('my_global_data', gp_data) #note: should be prior to execute()
globalmul4 = llvmjit.find_function('globalmul4')
assert llvmjit.execute(globalmul4, 5) == 10 * 4 + 5
More information about the Pypy-commit
mailing list