assert(!gallivm->engine);
lp_free_generated_code(gallivm->code);
gallivm->code = NULL;
+#if HAVE_LLVM < 0x0306
+ LLVMDisposeMCJITMemoryManager(gallivm->memorymgr);
+ gallivm->memorymgr = NULL;
+#endif
}
ret = lp_build_create_jit_compiler_for_module(&gallivm->engine,
&gallivm->code,
gallivm->module,
+ gallivm->memorymgr,
(unsigned) optlevel,
USE_MCJIT,
&error);
if (!gallivm->builder)
goto fail;
+#if HAVE_LLVM < 0x0306
+ gallivm->memorymgr = lp_get_default_memory_manager();
+ if (!gallivm->memorymgr)
+ goto fail;
+#else
+ gallivm->memorymgr = 0;
+#endif
+
/* FIXME: MC-JIT only allows compiling one module at a time, and it must be
* complete when MC-JIT is created. So defer the MC-JIT engine creation for
* now.
*/
class ShaderMemoryManager : public DelegatingJITMemoryManager {
- static llvm::JITMemoryManager *TheMM;
- static unsigned NumUsers;
+ llvm::JITMemoryManager *TheMM;
struct GeneratedCode {
typedef std::vector<void *> Vec;
Vec FunctionBody, ExceptionTable;
+ llvm::JITMemoryManager *TheMM;
- GeneratedCode() {
- ++NumUsers;
+ GeneratedCode(llvm::JITMemoryManager *MM) {
+ TheMM = MM;
}
~GeneratedCode() {
for ( i = ExceptionTable.begin(); i != ExceptionTable.end(); ++i )
TheMM->deallocateExceptionTable(*i);
#endif
- --NumUsers;
- if (NumUsers == 0) {
- delete TheMM;
- TheMM = 0;
- }
}
};
GeneratedCode *code;
llvm::JITMemoryManager *mgr() const {
- if (!TheMM) {
- TheMM = CreateDefaultMemManager();
- }
return TheMM;
}
public:
- ShaderMemoryManager() {
- code = new GeneratedCode;
+ ShaderMemoryManager(llvm::JITMemoryManager* MM) {
+ TheMM = MM;
+ code = new GeneratedCode(MM);
}
virtual ~ShaderMemoryManager() {
}
};
-llvm::JITMemoryManager *ShaderMemoryManager::TheMM = 0;
-unsigned ShaderMemoryManager::NumUsers = 0;
-
#endif
/**
lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
lp_generated_code **OutCode,
LLVMModuleRef M,
+ LLVMMCJITMemoryManagerRef CMM,
unsigned OptLevel,
int useMCJIT,
char **OutError)
builder.setMCPU(MCPU);
#endif
- ShaderMemoryManager *MM = new ShaderMemoryManager();
+ llvm::JITMemoryManager* JMM = reinterpret_cast<llvm::JITMemoryManager*>(CMM);
+ ShaderMemoryManager *MM = new ShaderMemoryManager(JMM);
*OutCode = MM->getGeneratedCode();
builder.setJITMemoryManager(MM);
ShaderMemoryManager::freeGeneratedCode(code);
#endif
}
+
+extern "C"
+LLVMMCJITMemoryManagerRef
+lp_get_default_memory_manager()
+{
+#if HAVE_LLVM < 0x0306
+ llvm::JITMemoryManager *mm;
+ mm = llvm::JITMemoryManager::CreateDefaultMemManager();
+ return reinterpret_cast<LLVMMCJITMemoryManagerRef>(mm);
+#else
+ return 0;
+#endif
+}
lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
struct lp_generated_code **OutCode,
LLVMModuleRef M,
+ LLVMMCJITMemoryManagerRef MM,
unsigned OptLevel,
int useMCJIT,
char **OutError);
extern void
lp_free_generated_code(struct lp_generated_code *code);
+extern LLVMMCJITMemoryManagerRef
+lp_get_default_memory_manager();
#ifdef __cplusplus
}