[PATCH] Factor common code in JIT

Yaron Keren yaron.keren at gmail.com
Sat May 17 01:46:11 PDT 2014


FunctionPassManager initialization code repeats three times, identical.

http://reviews.llvm.org/D3818

Files:
  lib/ExecutionEngine/JIT/JIT.cpp
  lib/ExecutionEngine/JIT/JIT.h

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;
 }
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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3818.9508.patch
Type: text/x-patch
Size: 3041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140517/1420985f/attachment.bin>


More information about the llvm-commits mailing list