[llvm] r199926 - Add target analysis passes to the codegen pipeline for MCJIT.

Juergen Ributzka juergen at apple.com
Thu Jan 23 11:23:29 PST 2014


Author: ributzka
Date: Thu Jan 23 13:23:28 2014
New Revision: 199926

URL: http://llvm.org/viewvc/llvm-project?rev=199926&view=rev
Log:
Add target analysis passes to the codegen pipeline for MCJIT.

This patch adds the target analysis passes (usually TargetTransformInfo) to the
codgen pipeline. We also expose now the AddAnalysisPasses method through the C
API, because the optimizer passes would also benefit from better target-specific
cost models.

Reviewed by Andrew Kaylor

Modified:
    llvm/trunk/include/llvm-c/ExecutionEngine.h
    llvm/trunk/include/llvm-c/TargetMachine.h
    llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
    llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
    llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp
    llvm/trunk/lib/ExecutionEngine/JIT/JIT.h
    llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
    llvm/trunk/lib/Target/TargetMachineC.cpp
    llvm/trunk/tools/llc/llc.cpp

Modified: llvm/trunk/include/llvm-c/ExecutionEngine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/ExecutionEngine.h?rev=199926&r1=199925&r2=199926&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/ExecutionEngine.h (original)
+++ llvm/trunk/include/llvm-c/ExecutionEngine.h Thu Jan 23 13:23:28 2014
@@ -163,6 +163,8 @@ void *LLVMRecompileAndRelinkFunction(LLV
                                      LLVMValueRef Fn);
 
 LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
+LLVMTargetMachineRef
+LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
 
 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
                           void* Addr);

Modified: llvm/trunk/include/llvm-c/TargetMachine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/TargetMachine.h?rev=199926&r1=199925&r2=199926&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/TargetMachine.h (original)
+++ llvm/trunk/include/llvm-c/TargetMachine.h Thu Jan 23 13:23:28 2014
@@ -137,6 +137,9 @@ LLVMBool LLVMTargetMachineEmitToMemoryBu
   disposed with LLVMDisposeMessage. */
 char* LLVMGetDefaultTargetTriple(void);
 
+/** Adds the target-specific analysis passes to the pass manager. */
+void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);
+
 #ifdef __cplusplus
 }
 #endif

Modified: llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h?rev=199926&r1=199925&r2=199926&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h Thu Jan 23 13:23:28 2014
@@ -462,6 +462,9 @@ public:
     llvm_unreachable("No support for an object cache");
   }
 
+  /// Return the target machine (if available).
+  virtual TargetMachine *getTargetMachine() { return NULL; }
+
   /// DisableLazyCompilation - When lazy compilation is off (the default), the
   /// JIT will eagerly compile every function reachable from the argument to
   /// getPointerToFunction.  If lazy compilation is turned on, the JIT will only

Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=199926&r1=199925&r2=199926&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Thu Jan 23 13:23:28 2014
@@ -92,6 +92,9 @@ static MCContext *addPassesToGenerateCod
                                           bool DisableVerify,
                                           AnalysisID StartAfter,
                                           AnalysisID StopAfter) {
+  // Add internal analysis passes from the target machine.
+  TM->addAnalysisPasses(PM);
+
   // Targets may override createPassConfig to provide a target-specific sublass.
   TargetPassConfig *PassConfig = TM->createPassConfig(PM);
   PassConfig->setStartStopPasses(StartAfter, StopAfter);

Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp?rev=199926&r1=199925&r2=199926&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/ExecutionEngineBindings.cpp Thu Jan 23 13:23:28 2014
@@ -43,6 +43,11 @@ inline LLVMTargetLibraryInfoRef wrap(con
   return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
 }
 
+inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
+  return
+  reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine*>(P));
+}
+
 /*===-- Operations on generic values --------------------------------------===*/
 
 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
@@ -323,6 +328,11 @@ LLVMTargetDataRef LLVMGetExecutionEngine
   return wrap(unwrap(EE)->getDataLayout());
 }
 
+LLVMTargetMachineRef
+LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE) {
+  return wrap(unwrap(EE)->getTargetMachine());
+}
+
 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
                           void* Addr) {
   unwrap(EE)->addGlobalMapping(unwrap<GlobalValue>(Global), Addr);

Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.h?rev=199926&r1=199925&r2=199926&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JIT.h (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.h Thu Jan 23 13:23:28 2014
@@ -193,6 +193,9 @@ public:
 
   virtual void RegisterJITEventListener(JITEventListener *L);
   virtual void UnregisterJITEventListener(JITEventListener *L);
+
+  virtual TargetMachine *getTargetMachine() { return &TM; }
+
   /// These functions correspond to the methods on JITEventListener.  They
   /// iterate over the registered listeners and call the corresponding method on
   /// each.

Modified: llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h?rev=199926&r1=199925&r2=199926&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h (original)
+++ llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.h Thu Jan 23 13:23:28 2014
@@ -301,6 +301,8 @@ public:
   virtual uint64_t getGlobalValueAddress(const std::string &Name);
   virtual uint64_t getFunctionAddress(const std::string &Name);
 
+  virtual TargetMachine *getTargetMachine() { return TM; }
+
   /// @}
   /// @name (Private) Registration Interfaces
   /// @{

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=199926&r1=199925&r2=199926&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Thu Jan 23 13:23:28 2014
@@ -498,7 +498,6 @@ bool LTOCodeGenerator::generateObjectFil
   PassManager codeGenPasses;
 
   codeGenPasses.add(new DataLayout(*TargetMach->getDataLayout()));
-  TargetMach->addAnalysisPasses(codeGenPasses);
 
   formatted_raw_ostream Out(out);
 

Modified: llvm/trunk/lib/Target/TargetMachineC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachineC.cpp?rev=199926&r1=199925&r2=199926&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachineC.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachineC.cpp Thu Jan 23 13:23:28 2014
@@ -267,3 +267,7 @@ LLVMBool LLVMTargetMachineEmitToMemoryBu
 char *LLVMGetDefaultTargetTriple(void) {
   return strdup(sys::getDefaultTargetTriple().c_str());
 }
+
+void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM) {
+  unwrap(T)->addAnalysisPasses(*unwrap(PM));
+}

Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=199926&r1=199925&r2=199926&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Thu Jan 23 13:23:28 2014
@@ -319,9 +319,6 @@ static int compileModule(char **argv, LL
     TLI->disableAllFunctions();
   PM.add(TLI);
 
-  // Add intenal analysis passes from the target machine.
-  Target.addAnalysisPasses(PM);
-
   // Add the target data from the target machine, if it exists, or the module.
   if (const DataLayout *TD = Target.getDataLayout())
     PM.add(new DataLayout(*TD));





More information about the llvm-commits mailing list