diff options
Diffstat (limited to 'llvm/lib/ExecutionEngine/JIT/JIT.cpp')
-rw-r--r-- | llvm/lib/ExecutionEngine/JIT/JIT.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/llvm/lib/ExecutionEngine/JIT/JIT.cpp b/llvm/lib/ExecutionEngine/JIT/JIT.cpp index ab0c1a680bd..063b35f478c 100644 --- a/llvm/lib/ExecutionEngine/JIT/JIT.cpp +++ b/llvm/lib/ExecutionEngine/JIT/JIT.cpp @@ -69,10 +69,9 @@ static struct RegisterJIT { extern "C" void LLVMLinkInJIT() { } -/// createJIT - This is the factory method for creating a JIT for the current -/// machine, it does not fall back to the interpreter. This takes ownership -/// of the module. -ExecutionEngine *JIT::createJIT(Module *M, +/// This is the factory method for creating a JIT for the current machine, it +/// does not fall back to the interpreter. +ExecutionEngine *JIT::createJIT(std::unique_ptr<Module> M, std::string *ErrorStr, JITMemoryManager *JMM, bool GVsWithCode, @@ -84,7 +83,7 @@ ExecutionEngine *JIT::createJIT(Module *M, // If the target supports JIT code generation, create the JIT. if (TargetJITInfo *TJ = TM->getSubtargetImpl()->getJITInfo()) { - return new JIT(M, *TM, *TJ, JMM, GVsWithCode); + return new JIT(std::move(M), *TM, *TJ, JMM, GVsWithCode); } else { if (ErrorStr) *ErrorStr = "target does not support JIT code generation"; @@ -135,14 +134,15 @@ extern "C" { } } -JIT::JIT(Module *M, TargetMachine &tm, TargetJITInfo &tji, +JIT::JIT(std::unique_ptr<Module> M, TargetMachine &tm, TargetJITInfo &tji, JITMemoryManager *jmm, bool GVsWithCode) - : ExecutionEngine(M), TM(tm), TJI(tji), + : ExecutionEngine(std::move(M)), TM(tm), TJI(tji), JMM(jmm ? jmm : JITMemoryManager::CreateDefaultMemManager()), AllocateGVsWithCode(GVsWithCode), isAlreadyCodeGenerating(false) { setDataLayout(TM.getSubtargetImpl()->getDataLayout()); - jitstate = new JITState(M); + Module *Mod = Modules.back().get(); + jitstate = new JITState(Mod); // Initialize JCE JCE = createEmitter(*this, JMM, TM); @@ -153,8 +153,8 @@ JIT::JIT(Module *M, TargetMachine &tm, TargetJITInfo &tji, // Add target data MutexGuard locked(lock); FunctionPassManager &PM = jitstate->getPM(); - M->setDataLayout(TM.getSubtargetImpl()->getDataLayout()); - PM.add(new DataLayoutPass(M)); + Mod->setDataLayout(TM.getSubtargetImpl()->getDataLayout()); + PM.add(new DataLayoutPass(Mod)); // Turn the machine code intermediate representation into bytes in memory that // may be executed. @@ -175,19 +175,19 @@ JIT::~JIT() { delete &TM; } -/// addModule - Add a new Module to the JIT. If we previously removed the last -/// Module, we need re-initialize jitstate with a valid Module. -void JIT::addModule(Module *M) { +/// Add a new Module to the JIT. If we previously removed the last Module, we +/// need re-initialize jitstate with a valid Module. +void JIT::addModule(std::unique_ptr<Module> M) { MutexGuard locked(lock); if (Modules.empty()) { assert(!jitstate && "jitstate should be NULL if Modules vector is empty!"); - jitstate = new JITState(M); + jitstate = new JITState(M.get()); FunctionPassManager &PM = jitstate->getPM(); M->setDataLayout(TM.getSubtargetImpl()->getDataLayout()); - PM.add(new DataLayoutPass(M)); + PM.add(new DataLayoutPass(M.get())); // Turn the machine code intermediate representation into bytes in memory // that may be executed. @@ -199,11 +199,11 @@ void JIT::addModule(Module *M) { PM.doInitialization(); } - ExecutionEngine::addModule(M); + ExecutionEngine::addModule(std::move(M)); } -/// removeModule - If we are removing the last Module, invalidate the jitstate -/// since the PassManager it contains references a released Module. +/// If we are removing the last Module, invalidate the jitstate since the +/// PassManager it contains references a released Module. bool JIT::removeModule(Module *M) { bool result = ExecutionEngine::removeModule(M); @@ -215,7 +215,7 @@ bool JIT::removeModule(Module *M) { } if (!jitstate && !Modules.empty()) { - jitstate = new JITState(Modules[0]); + jitstate = new JITState(Modules[0].get()); FunctionPassManager &PM = jitstate->getPM(); M->setDataLayout(TM.getSubtargetImpl()->getDataLayout()); |