[pypy-svn] r35061 - in pypy/dist/pypy/jit/codegen/llvm: . lib test
ericvrp at codespeak.net
ericvrp at codespeak.net
Mon Nov 27 22:21:49 CET 2006
Author: ericvrp
Date: Mon Nov 27 22:21:42 2006
New Revision: 35061
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:
Attempt to use global data from JITed code in the llvm codegenereator.
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 Mon Nov 27 22:21:42 2006
@@ -3,6 +3,8 @@
#include "libllvmjit.h"
#include "llvm/Module.h"
+#include "llvm/Type.h"
+#include "llvm/GlobalVariable.h"
#include "llvm/Assembly/Parser.h"
#include "llvm/Bytecode/Writer.h"
#include "llvm/Analysis/Verifier.h"
@@ -38,6 +40,9 @@
static cl::list<const PassInfo*, bool, PassNameParser>
PassList(cl::desc("Optimizations available:"));
+//some global data for the tests to play with
+char g_char[2] = {10,0};
+
//
//code...
@@ -100,3 +105,24 @@
return gv.IntVal;
}
+
+char* get_pointer_to_global_char() {
+ printf("get_pointer_to_global_char g_char=%08x\n", g_char);
+ return g_char;
+}
+
+
+void add_global_mapping(const char* name, void* address) {
+ //GlobalValue(const Type *Ty, ValueTy vty, Use *Ops, unsigned NumOps, LinkageTypes linkage, const std::string &name = "");
+
+ /// GlobalVariable ctor - If a parent module is specified, the global is
+ // /// automatically inserted into the end of the specified modules global list.
+ // GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage,
+ // Constant *Initializer = 0, const std::string &Name = "",
+ // Module *Parent = 0);
+
+ GlobalVariable var(Type::UByteTy, false, GlobalVariable::ExternalLinkage, 0, name, gp_module);
+ printf("add_global_mapping address=%08x\n", address);
+ gp_execution_engine->addGlobalMapping(&var, 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 Mon Nov 27 22:21:42 2006
@@ -9,6 +9,8 @@
int compile(const char* llsource);
void* find_function(const char* funcname);
int execute(const void* function, int param);
+char* get_pointer_to_global_char();
+void add_global_mapping(const char* name, void* address);
#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 Mon Nov 27 22:21:42 2006
@@ -61,3 +61,11 @@
execute.restype = c_int
execute.argtypes = [c_void_p, c_int]
+get_pointer_to_global_char= llvmjit.get_pointer_to_global_char
+get_pointer_to_global_char.restype = c_char_p
+get_pointer_to_global_char.argtypes = []
+
+add_global_mapping = llvmjit.add_global_mapping
+#add_global_mapping.restype = c_void
+add_global_mapping.argtypes = [c_char_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 Mon Nov 27 22:21:42 2006
@@ -14,13 +14,11 @@
curdir = dirname(__file__)
llsquare = '''int %square(int %n) {
-block0:
%n2 = mul int %n, %n
ret int %n2
}'''
llmul2 = '''int %mul2(int %n) {
-block0:
%n2 = mul int %n, 2
ret int %n2
}'''
@@ -43,13 +41,11 @@
implementation
int %across1(int %n) {
-block0:
%n2 = mul int %n, 3
ret int %n2
}
int %across1to2(int %n) {
-block0:
%n2 = add int %n, 5
%n3 = call int %across2(int %n2)
ret int %n3
@@ -60,18 +56,30 @@
implementation
int %across2(int %n) {
-block0:
%n2 = mul int %n, 7
ret int %n2
}
int %across2to1(int %n) {
-block0:
%n2 = add int %n, 9
%n3 = call int %across1(int %n2)
ret int %n3
}'''
+llglobalmul4 = '''%my_global_ubyte = external global ubyte
+
+implementation
+
+int %globalmul4(int %a) {
+ %aa = cast int %a to ubyte
+ %v0 = load ubyte* %my_global_ubyte
+ %v1 = mul ubyte %v0, 4
+ %v2 = add ubyte %v1, %aa
+ store ubyte %v2, ubyte* %my_global_ubyte
+ %v3 = cast ubyte %v2 to int
+ ret int %v3
+}'''
+
#helpers
def execute(llsource, function_name, param):
assert llvmjit.compile(llsource)
@@ -154,7 +162,15 @@
assert llvmjit.execute(deadcode, 30) == 30 * 2
def DONTtest_modify_global_data():
- pass
+ llvmjit.restart()
+ gp_char = llvmjit.get_pointer_to_global_char()
+ assert len(gp_char) == 1
+ assert ord(gp_char[0]) == 10
+ llvmjit.add_global_mapping('my_global_ubyte', gp_char) #note: should be prior to compile()
+ llvmjit.compile(llglobalmul4) #XXX assert error, incorrect types???
+ globalmul4 = llvmjit.find_function('globalmul4')
+ assert llvmjit.execute(globalmul4, 5) == 10 * 4 + 5
+ assert ord(gp_char[0]) == 10 * 4 + 5
def DONTtest_call_back_to_parent(): #call JIT-compiler again for it to add case(s) to flexswitch
pass
More information about the Pypy-commit
mailing list