Add lazy compilation option.
Unify execution engine creation through engine-builder internally.
This commit is contained in:
parent
91a10e6a8e
commit
bdac4a809d
4 changed files with 55 additions and 38 deletions
|
|
@ -1279,37 +1279,38 @@ _wLLVMEngineBuilderCreateTM(PyObject *self, PyObject *args)
|
||||||
/* Execution Engine */
|
/* Execution Engine */
|
||||||
/*===----------------------------------------------------------------------===*/
|
/*===----------------------------------------------------------------------===*/
|
||||||
|
|
||||||
static PyObject *
|
// Use EngineBuilder
|
||||||
_wLLVMCreateExecutionEngine(PyObject *self, PyObject *args)
|
//static PyObject *
|
||||||
{
|
//_wLLVMCreateExecutionEngine(PyObject *self, PyObject *args)
|
||||||
LLVMPY_TRY
|
//{
|
||||||
PyObject *obj;
|
// LLVMPY_TRY
|
||||||
int force_interpreter;
|
// PyObject *obj;
|
||||||
char *outmsg = 0;
|
// int force_interpreter;
|
||||||
int error;
|
// char *outmsg = 0;
|
||||||
|
// int error;
|
||||||
if (!PyArg_ParseTuple(args, "Oi", &obj, &force_interpreter))
|
//
|
||||||
return NULL;
|
// if (!PyArg_ParseTuple(args, "Oi", &obj, &force_interpreter))
|
||||||
|
// return NULL;
|
||||||
const LLVMModuleRef mod = pycap_get<LLVMModuleRef>( obj ) ;
|
//
|
||||||
|
// const LLVMModuleRef mod = pycap_get<LLVMModuleRef>( obj ) ;
|
||||||
LLVMExecutionEngineRef ee;
|
//
|
||||||
if (force_interpreter)
|
// LLVMExecutionEngineRef ee;
|
||||||
error = LLVMCreateInterpreterForModule(&ee, mod, &outmsg);
|
// if (force_interpreter)
|
||||||
else
|
// error = LLVMCreateInterpreterForModule(&ee, mod, &outmsg);
|
||||||
error = LLVMCreateJITCompilerForModule(&ee, mod, 1 /*fast*/, &outmsg);
|
// else
|
||||||
|
// error = LLVMCreateJITCompilerForModule(&ee, mod, 1 /*fast*/, &outmsg);
|
||||||
PyObject *ret;
|
//
|
||||||
if (error) {
|
// PyObject *ret;
|
||||||
ret = PyUnicode_FromString(outmsg);
|
// if (error) {
|
||||||
LLVMDisposeMessage(outmsg);
|
// ret = PyUnicode_FromString(outmsg);
|
||||||
} else {
|
// LLVMDisposeMessage(outmsg);
|
||||||
ret = pycap_new<LLVMExecutionEngineRef>(ee);
|
// } else {
|
||||||
}
|
// ret = pycap_new<LLVMExecutionEngineRef>(ee);
|
||||||
|
// }
|
||||||
return ret;
|
//
|
||||||
LLVMPY_CATCH_ALL
|
// return ret;
|
||||||
}
|
// LLVMPY_CATCH_ALL
|
||||||
|
//}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_wLLVMGetPointerToFunction(PyObject *self, PyObject *args)
|
_wLLVMGetPointerToFunction(PyObject *self, PyObject *args)
|
||||||
|
|
@ -1405,6 +1406,8 @@ _wLLVMRemoveModule2(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
_wrap_obj2none(LLVMDisposeExecutionEngine, LLVMExecutionEngineRef)
|
_wrap_obj2none(LLVMDisposeExecutionEngine, LLVMExecutionEngineRef)
|
||||||
|
_wrap_objint2none(LLVMExecutionEngineDisableLazyCompilation,
|
||||||
|
LLVMExecutionEngineRef)
|
||||||
_wrap_objobjlist2obj(LLVMRunFunction2, LLVMExecutionEngineRef,
|
_wrap_objobjlist2obj(LLVMRunFunction2, LLVMExecutionEngineRef,
|
||||||
LLVMValueRef, LLVMGenericValueRef, LLVMGenericValueRef)
|
LLVMValueRef, LLVMGenericValueRef, LLVMGenericValueRef)
|
||||||
_wrap_obj2obj(LLVMGetExecutionEngineTargetData, LLVMExecutionEngineRef,
|
_wrap_obj2obj(LLVMGetExecutionEngineTargetData, LLVMExecutionEngineRef,
|
||||||
|
|
@ -2116,8 +2119,10 @@ static PyMethodDef core_methods[] = {
|
||||||
_method( LLVMEngineBuilderCreateTM )
|
_method( LLVMEngineBuilderCreateTM )
|
||||||
|
|
||||||
/* Execution Engine */
|
/* Execution Engine */
|
||||||
_method( LLVMCreateExecutionEngine )
|
// Use EngineBuilder instead
|
||||||
|
// _method( LLVMCreateExecutionEngine )
|
||||||
_method( LLVMDisposeExecutionEngine )
|
_method( LLVMDisposeExecutionEngine )
|
||||||
|
_method( LLVMExecutionEngineDisableLazyCompilation )
|
||||||
_method( LLVMRunFunction2 )
|
_method( LLVMRunFunction2 )
|
||||||
_method( LLVMGetPointerToFunction )
|
_method( LLVMGetPointerToFunction )
|
||||||
_method( LLVMGetPointerToGlobal )
|
_method( LLVMGetPointerToGlobal )
|
||||||
|
|
|
||||||
14
llvm/ee.py
14
llvm/ee.py
|
|
@ -205,12 +205,10 @@ class ExecutionEngine(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new(module, force_interpreter=False):
|
def new(module, force_interpreter=False):
|
||||||
core.check_is_module(module)
|
eb = EngineBuilder.new(module)
|
||||||
_util.check_is_unowned(module)
|
if force_interpreter:
|
||||||
ret = _core.LLVMCreateExecutionEngine(module.ptr, int(force_interpreter))
|
eb.force_interpreter()
|
||||||
if isinstance(ret, str):
|
return eb.create()
|
||||||
raise llvm.LLVMException(ret)
|
|
||||||
return ExecutionEngine(ret, module)
|
|
||||||
|
|
||||||
def __init__(self, ptr, module):
|
def __init__(self, ptr, module):
|
||||||
self.ptr = ptr
|
self.ptr = ptr
|
||||||
|
|
@ -219,6 +217,10 @@ class ExecutionEngine(object):
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
_core.LLVMDisposeExecutionEngine(self.ptr)
|
_core.LLVMDisposeExecutionEngine(self.ptr)
|
||||||
|
|
||||||
|
def disable_lazy_compilation(self, disabled=True):
|
||||||
|
_core.LLVMExecutionEngineDisableLazyCompilation(self.ptr,
|
||||||
|
int(bool(disabled)))
|
||||||
|
|
||||||
def run_function(self, fn, args):
|
def run_function(self, fn, args):
|
||||||
core.check_is_function(fn)
|
core.check_is_function(fn)
|
||||||
ptrs = _unpack_generic_values(args)
|
ptrs = _unpack_generic_values(args)
|
||||||
|
|
|
||||||
|
|
@ -1254,6 +1254,11 @@ unsigned LLVMLoadLibraryPermanently(const char* filename, char **errmsg)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LLVMExecutionEngineDisableLazyCompilation(LLVMExecutionEngineRef ee, int flag)
|
||||||
|
{
|
||||||
|
llvm::unwrap(ee)->DisableLazyCompilation(flag);
|
||||||
|
}
|
||||||
|
|
||||||
void *LLVMGetPointerToFunction(LLVMExecutionEngineRef ee, LLVMValueRef fn)
|
void *LLVMGetPointerToFunction(LLVMExecutionEngineRef ee, LLVMValueRef fn)
|
||||||
{
|
{
|
||||||
llvm::ExecutionEngine *eep = llvm::unwrap(ee);
|
llvm::ExecutionEngine *eep = llvm::unwrap(ee);
|
||||||
|
|
|
||||||
|
|
@ -590,6 +590,11 @@ unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef module, size_t *len);
|
||||||
* use, via LLVMDisposeMessage(). */
|
* use, via LLVMDisposeMessage(). */
|
||||||
unsigned LLVMLoadLibraryPermanently(const char* filename, char **errmsg);
|
unsigned LLVMLoadLibraryPermanently(const char* filename, char **errmsg);
|
||||||
|
|
||||||
|
/* Wraps llvm::ExecutionEngine::DisableLazyCompilation(bool)
|
||||||
|
*/
|
||||||
|
void LLVMExecutionEngineDisableLazyCompilation(LLVMExecutionEngineRef ee,
|
||||||
|
int flag);
|
||||||
|
|
||||||
/* Wraps llvm::ExecutionEngine::getPointerToFunction(). Returns a pointer
|
/* Wraps llvm::ExecutionEngine::getPointerToFunction(). Returns a pointer
|
||||||
* to the JITted function. */
|
* to the JITted function. */
|
||||||
void *LLVMGetPointerToFunction(LLVMExecutionEngineRef ee, LLVMValueRef fn);
|
void *LLVMGetPointerToFunction(LLVMExecutionEngineRef ee, LLVMValueRef fn);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue