[pypy-svn] r65025 - pypy/branch/pyjitpl5/pypy/jit/backend/llvm
arigo at codespeak.net
arigo at codespeak.net
Mon May 4 17:40:39 CEST 2009
Author: arigo
Date: Mon May 4 17:40:38 2009
New Revision: 65025
Modified:
pypy/branch/pyjitpl5/pypy/jit/backend/llvm/demo2.cpp
pypy/branch/pyjitpl5/pypy/jit/backend/llvm/demo2.h
pypy/branch/pyjitpl5/pypy/jit/backend/llvm/llvm_rffi.py
pypy/branch/pyjitpl5/pypy/jit/backend/llvm/runner.py
Log:
Move this logic to C++, where it's a bit more readable.
It will allow more easily to play with it, too (like
adding optimization passes).
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llvm/demo2.cpp
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llvm/demo2.cpp (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llvm/demo2.cpp Mon May 4 17:40:38 2009
@@ -1,4 +1,5 @@
/* LLVM includes */
+#include <cstdio>
#include "llvm-c/ExecutionEngine.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
@@ -9,8 +10,22 @@
/* Missing pieces of the C interface...
*/
+LLVMExecutionEngineRef _LLVM_EE_Create(LLVMModuleRef M)
+{
+ LLVMModuleProviderRef mp = LLVMCreateModuleProviderForExistingModule(M);
+ LLVMExecutionEngineRef ee;
+ char* errormsg;
+ int error = LLVMCreateJITCompiler(&ee, mp, 1 /*Fast*/, &errormsg);
+ if (error)
+ {
+ fprintf(stderr, "Error creating the JIT compiler:\n%s", errormsg);
+ abort();
+ }
+ return ee;
+}
+
void *_LLVM_EE_getPointerToFunction(LLVMExecutionEngineRef EE,
- LLVMValueRef F)
+ LLVMValueRef F)
{
return unwrap(EE)->getPointerToFunction(unwrap<Function>(F));
}
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llvm/demo2.h
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llvm/demo2.h (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llvm/demo2.h Mon May 4 17:40:38 2009
@@ -1,8 +1,10 @@
+
#ifdef __cplusplus
extern "C" {
#endif
-
-void* _LLVM_EE_getPointerToFunction(LLVMExecutionEngineRef EE,
+
+LLVMExecutionEngineRef _LLVM_EE_Create(LLVMModuleRef M);
+void *_LLVM_EE_getPointerToFunction(LLVMExecutionEngineRef EE,
LLVMValueRef F);
#ifdef __cplusplus
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llvm/llvm_rffi.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llvm/llvm_rffi.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llvm/llvm_rffi.py Mon May 4 17:40:38 2009
@@ -279,6 +279,8 @@
rffi.CArrayPtr(LLVMGenericValueRef)], # args
LLVMGenericValueRef) # return value
+LLVM_EE_Create = llexternal('_LLVM_EE_Create', [LLVMModuleRef],
+ LLVMExecutionEngineRef)
LLVM_EE_getPointerToFunction = llexternal('_LLVM_EE_getPointerToFunction',
[LLVMExecutionEngineRef,
LLVMValueRef], # function
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llvm/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llvm/runner.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llvm/runner.py Mon May 4 17:40:38 2009
@@ -9,10 +9,6 @@
from pypy.jit.metainterp.resoperation import rop
-class LLVMException(Exception):
- pass
-
-
class LLVMCPU(model.AbstractCPU):
RAW_VALUE = rffi.CFixedArray(rffi.ULONGLONG, 1)
SIGNED_VALUE = rffi.CFixedArray(lltype.Signed, 1)
@@ -46,22 +42,7 @@
1, False)
lltype.free(arglist, flavor='raw')
#
- mp = llvm_rffi.LLVMCreateModuleProviderForExistingModule(self.module)
- ee_out = lltype.malloc(rffi.CArray(llvm_rffi.LLVMExecutionEngineRef),
- 1, flavor='raw')
- error_out = lltype.malloc(rffi.CArray(rffi.CCHARP), 1, flavor='raw')
- error_out[0] = lltype.nullptr(rffi.CCHARP.TO)
- try:
- error = llvm_rffi.LLVMCreateJITCompiler(ee_out, mp, True,
- error_out)
- if rffi.cast(lltype.Signed, error) != 0:
- raise LLVMException(rffi.charp2str(error_out[0]))
- self.ee = ee_out[0]
- finally:
- if error_out[0]:
- llvm_rffi.LLVMDisposeMessage(error_out[0])
- lltype.free(error_out, flavor='raw')
- lltype.free(ee_out, flavor='raw')
+ self.ee = llvm_rffi.LLVM_EE_Create(self.module)
if not we_are_translated():
set_teardown_function(self._teardown)
More information about the Pypy-commit
mailing list