Skip to content

Commit

Permalink
Hack to preserve modules following compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarkall committed Mar 15, 2023
1 parent 1116373 commit 0c6b605
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ffi/orcjit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ inline OwningBinary<ObjectFile> *unwrap(LLVMObjectFileRef OF) {

extern "C" {

std::vector<ThreadSafeModule> GlobalTSMs;

API_EXPORT(LLVMOrcLLJITRef)
LLVMPY_CreateLLJITCompiler(LLVMTargetMachineRef tm, const char **OutError) {
LLVMOrcLLJITRef jit;
Expand Down Expand Up @@ -62,6 +64,11 @@ LLVMPY_CreateLLJITCompiler(LLVMTargetMachineRef tm, const char **OutError) {

auto error = LLVMOrcCreateLLJIT(&jit, builder);

unwrap(jit)->getIRCompileLayer().setNotifyCompiled([](MaterializationResponsibility &R, ThreadSafeModule TSM) {
// Move TSM to take ownership and preserve the module.
GlobalTSMs.push_back(std::move(TSM));
});

if (error) {
char *message = LLVMGetErrorMessage(error);
*OutError = LLVMPY_CreateString(message);
Expand Down

0 comments on commit 0c6b605

Please sign in to comment.