Index: lib/ExecutionEngine/JIT/JIT.h =================================================================== --- lib/ExecutionEngine/JIT/JIT.h +++ lib/ExecutionEngine/JIT/JIT.h @@ -80,6 +80,9 @@ JIT(Module *M, TargetMachine &tm, TargetJITInfo &tji, JITMemoryManager *JMM, bool AllocateGVsWithCode); + + /// initPM - initialize the PassManager. + void initPM(Module *M, const MutexGuard &locked); public: ~JIT(); Index: lib/ExecutionEngine/JIT/JIT.cpp =================================================================== --- lib/ExecutionEngine/JIT/JIT.cpp +++ lib/ExecutionEngine/JIT/JIT.cpp @@ -134,6 +134,21 @@ } } +void JIT::initPM(Module *M, const MutexGuard &locked) { + FunctionPassManager &PM = jitstate->getPM(locked); + M->setDataLayout(TM.getDataLayout()); + PM.add(new DataLayoutPass(M)); + + // Turn the machine code intermediate representation into bytes in memory that + // may be executed. + if (TM.addPassesToEmitMachineCode(PM, *JCE, !getVerifyModules())) { + report_fatal_error("Target does not support machine code emission!"); + } + + // Initialize passes. + PM.doInitialization(); +} + JIT::JIT(Module *M, TargetMachine &tm, TargetJITInfo &tji, JITMemoryManager *jmm, bool GVsWithCode) : ExecutionEngine(M), TM(tm), TJI(tji), @@ -151,18 +166,7 @@ // Add target data MutexGuard locked(lock); - FunctionPassManager &PM = jitstate->getPM(locked); - M->setDataLayout(TM.getDataLayout()); - PM.add(new DataLayoutPass(M)); - - // Turn the machine code intermediate representation into bytes in memory that - // may be executed. - if (TM.addPassesToEmitMachineCode(PM, *JCE, !getVerifyModules())) { - report_fatal_error("Target does not support machine code emission!"); - } - - // Initialize passes. - PM.doInitialization(); + initPM(M, lock); } JIT::~JIT() { @@ -184,18 +188,7 @@ jitstate = new JITState(M); - FunctionPassManager &PM = jitstate->getPM(locked); - M->setDataLayout(TM.getDataLayout()); - PM.add(new DataLayoutPass(M)); - - // Turn the machine code intermediate representation into bytes in memory - // that may be executed. - if (TM.addPassesToEmitMachineCode(PM, *JCE, !getVerifyModules())) { - report_fatal_error("Target does not support machine code emission!"); - } - - // Initialize passes. - PM.doInitialization(); + initPM(M, lock); } ExecutionEngine::addModule(M); @@ -216,18 +209,7 @@ if (!jitstate && !Modules.empty()) { jitstate = new JITState(Modules[0]); - FunctionPassManager &PM = jitstate->getPM(locked); - M->setDataLayout(TM.getDataLayout()); - PM.add(new DataLayoutPass(M)); - - // Turn the machine code intermediate representation into bytes in memory - // that may be executed. - if (TM.addPassesToEmitMachineCode(PM, *JCE, !getVerifyModules())) { - report_fatal_error("Target does not support machine code emission!"); - } - - // Initialize passes. - PM.doInitialization(); + initPM(M, lock); } return result; }