[pypy-svn] r35204 - in pypy/dist/pypy/jit/codegen/llvm: . lib test

ericvrp at codespeak.net ericvrp at codespeak.net
Fri Dec 1 17:30:15 CET 2006


Author: ericvrp
Date: Fri Dec  1 17:30:13 2006
New Revision: 35204

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:
llvmjit test_call_global_function is working.
Some function renaming to stay closer to the llvm names.


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	Fri Dec  1 17:30:13 2006
@@ -86,11 +86,7 @@
 }
 
 
-void*   find_function(const char* name) {
-    return gp_execution_engine->FindFunctionNamed(name); //note: can be NULL
-}
-
-
+//Function methods
 int     freeMachineCodeForFunction(const void* function) {
     if (!function) {
         std::cerr << "No function supplied to libllvmjit.freeMachineCodeForFunction(...)\n" << std::flush;
@@ -127,6 +123,7 @@
 }
 
 
+//code for testcases
 int     get_global_data() {
     return g_data;
 }
@@ -137,14 +134,37 @@
 }
 
 
-int*    get_pointer_to_global_data() {
+int*   get_pointer_to_global_data() {
     return &g_data;
 }
 
 
-void    add_global_mapping(const char* name, void* address) {
-    //note: using getNamedGlobal implies that we can not have globals of different type
-    //      but with identical names! This is probably easy to do.
-    gp_execution_engine->addGlobalMapping(gp_module->getNamedGlobal(name), address);
+int     global_function(int a, int b, int c) {
+    return a + b + c;
+}
+
+
+void*   get_pointer_to_global_function() {
+    return (void*)global_function; //note: we don't care about the actual signature here
+}
+
+
+// Module methods
+void*   getNamedFunction(const char* name) {
+    return gp_module->getNamedFunction(name); //note: can be NULL
+}
+
+
+void*   getNamedGlobal(const char* name) {
+    return gp_module->getNamedGlobal(name); //note: can be NULL
+}
+
+
+void    addGlobalMapping(const void* p, void* address) {
+    if (!p) {
+        std::cerr << "No global variable or function supplied to addGlobalMapping\n" << std::flush;
+        return;
+    }
+    gp_execution_engine->addGlobalMapping((const GlobalValue*)p, address);
 }
 

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	Fri Dec  1 17:30:13 2006
@@ -7,14 +7,22 @@
 void    restart();
 int     transform(const char* passnames);
 int     parse(const char* llsource);
-void*   find_function(const char* funcname);
+
+//Function code
 int     freeMachineCodeForFunction(const void* function);
 int     recompile(const void* function);
 int     execute(const void* function, int param);
+
+//Module code
+void*   getNamedFunction(const char* name);
+void*   getNamedGlobal(const char* name);
+void    addGlobalMapping(const void* p, void* address); 
+
+//test code
 int     get_global_data();
 void    set_global_data(int n);
 int*    get_pointer_to_global_data();
-void    add_global_mapping(const char* name, void* address); 
+void*   get_pointer_to_global_function();
 
 #ifdef  __cplusplus    
 }

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	Fri Dec  1 17:30:13 2006
@@ -55,9 +55,13 @@
 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]
+getNamedFunction = llvmjit.getNamedFunction
+getNamedFunction.restype  = c_void_p
+getNamedFunction.argtypes = [c_char_p]
+
+getNamedGlobal = llvmjit.getNamedGlobal
+getNamedGlobal.restype  = c_void_p
+getNamedGlobal.argtypes = [c_char_p]
 
 freeMachineCodeForFunction = llvmjit.freeMachineCodeForFunction
 freeMachineCodeForFunction.restype  = c_int
@@ -71,17 +75,21 @@
 execute.restype  = c_int
 execute.argtypes = [c_void_p, c_int]
 
-get_global_data= llvmjit.get_global_data
+get_global_data = llvmjit.get_global_data
 get_global_data.restype = c_int
 get_global_data.argtypes = []
 
-set_global_data= llvmjit.set_global_data
+set_global_data = llvmjit.set_global_data
 set_global_data.argtypes = [c_int]
 
-get_pointer_to_global_data= llvmjit.get_pointer_to_global_data
+get_pointer_to_global_data = llvmjit.get_pointer_to_global_data
 get_pointer_to_global_data.restype = POINTER(c_int)
 get_pointer_to_global_data.argtypes = []
 
-add_global_mapping = llvmjit.add_global_mapping
-add_global_mapping.argtypes = [c_char_p, c_void_p]
+get_pointer_to_global_function = llvmjit.get_pointer_to_global_function
+get_pointer_to_global_function.restype = c_void_p
+get_pointer_to_global_function.argtypes = []
+
+addGlobalMapping = llvmjit.addGlobalMapping
+addGlobalMapping.argtypes = [c_void_p, c_void_p]
 

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	Fri Dec  1 17:30:13 2006
@@ -90,10 +90,20 @@
     ret int %v2
 }'''
 
+#
+llcall_global_function = '''declare int %my_global_function(int, int, int)
+
+implementation
+
+int %call_global_function(int %n) {
+    %v = call int %my_global_function(int 3, int %n, int 7) ;note: maybe tail call?
+    ret int %v
+}'''
+
 #helpers
 def execute(llsource, function_name, param):
     assert llvmjit.parse(llsource)
-    function = llvmjit.find_function(function_name)
+    function = llvmjit.getNamedFunction(function_name)
     assert function
     return llvmjit.execute(function, param)
 
@@ -101,18 +111,18 @@
 def test_restart():
     for i in range(3):
         llvmjit.restart()
-        assert not llvmjit.find_function('square')
+        assert not llvmjit.getNamedFunction('square')
         assert llvmjit.parse(llsquare)
-        assert llvmjit.find_function('square')
+        assert llvmjit.getNamedFunction('square')
 
-def test_find_function():
+def test_getNamedFunction():
     for i in range(3):
         llvmjit.restart()
-        assert not llvmjit.find_function('square')
-        assert not llvmjit.find_function('square')
+        assert not llvmjit.getNamedFunction('square')
+        assert not llvmjit.getNamedFunction('square')
         assert llvmjit.parse(llsquare)
-        assert llvmjit.find_function('square')
-        assert llvmjit.find_function('square')
+        assert llvmjit.getNamedFunction('square')
+        assert llvmjit.getNamedFunction('square')
 
 def test_parse():
     llvmjit.restart()
@@ -130,8 +140,8 @@
     llvmjit.restart()
     llvmjit.parse(llsquare)
     llvmjit.parse(llmul2)
-    square = llvmjit.find_function('square')
-    mul2   = llvmjit.find_function('mul2')
+    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
@@ -152,8 +162,8 @@
     llvmjit.restart()
     llvmjit.parse(llacross1)
     llvmjit.parse(llacross2)
-    across1to2 = llvmjit.find_function('across1to2')
-    across2to1 = llvmjit.find_function('across2to1')
+    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)
@@ -168,13 +178,13 @@
         return n * n
     llvmjit.restart()
     llvmjit.parse(llfuncA)
-    _llfuncA = llvmjit.find_function('func')
+    _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.find_function('func')
+    _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):
@@ -183,7 +193,7 @@
 def test_transform(): #XXX This uses Module transforms, think about Function transforms too.
     llvmjit.restart()
     llvmjit.parse(lldeadcode)
-    deadcode = llvmjit.find_function('deadcode')
+    deadcode = llvmjit.getNamedFunction('deadcode')
     assert llvmjit.execute(deadcode, 10) == 10 * 2
 
     #XXX enable this part of the test asap
@@ -199,16 +209,26 @@
     assert llvmjit.get_global_data() == 10
     gp_data = llvmjit.get_pointer_to_global_data()
     llvmjit.parse(llglobalmul4)
-    llvmjit.add_global_mapping('my_global_data', gp_data) #note: should be prior to execute()
-    globalmul4 = llvmjit.find_function('globalmul4')
+    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 DONTtest_call_back_to_parent(): #call JIT-compiler again for it to add case(s) to flexswitch
-    pass
-
-def DONTtest_delete_function():
-    pass
+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 DONTtest_functions_with_different_signatures():
     pass



More information about the Pypy-commit mailing list