Add target analysis passes to the codegen pipeline for MCJIT.
authorJuergen Ributzka <juergen@apple.com>
Thu, 23 Jan 2014 19:23:28 +0000 (19:23 +0000)
committerJuergen Ributzka <juergen@apple.com>
Thu, 23 Jan 2014 19:23:28 +0000 (19:23 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199926 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 35643122003a873d47edbe595054680b0c5ecc42..7cdf0d78d5b6e07f0a41696ab7a34b11dae2a3c3 100644 (file)
@@ -163,6 +163,8 @@ void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
                                      LLVMValueRef Fn);
 
 LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
+LLVMTargetMachineRef
+LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
 
 void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
                           void* Addr);
index 46de054e78be2fbf983ef6454dd1cffecd36d516..d4993e7e6da1e0e5f9bd4892062202db2e981af8 100644 (file)
@@ -137,6 +137,9 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleR
   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
index 199cf8deb8bbcaff47a8ed6740b122721d0a30e5..e228f202e7874fe24590c3ab5c07fd18cf3397cb 100644 (file)
@@ -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
index 9a7697e5378abb4e2d61ec5646d5e3e14019397d..27a4022ff71d9e6ed7ca117875fe66fcf973e154 100644 (file)
@@ -92,6 +92,9 @@ static MCContext *addPassesToGenerateCode(LLVMTargetMachine *TM,
                                           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);
index 2d34eeabf2a97525b0f266e215145bebbeb2d9c0..af0a372db8486995a692c2edd7d3b72d7f1503f3 100644 (file)
@@ -43,6 +43,11 @@ inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
   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 LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE) {
   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);
index 2ae155bebf40ae97ac6ca97479a075387c394661..4f6416ff10bfeb444115d656d31a9ce5fa8a8321 100644 (file)
@@ -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.
index 44fd6bce47b9a0157394dda9ec69c45f6ac6c4ec..a458356fe4b4c135906b445eba6a7df5996b5fd7 100644 (file)
@@ -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
   /// @{
index cae0ea27597042239c53c042064c553971bb89e0..073947055ace16f0b5b96c9257f736f707611f26 100644 (file)
@@ -498,7 +498,6 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
   PassManager codeGenPasses;
 
   codeGenPasses.add(new DataLayout(*TargetMach->getDataLayout()));
-  TargetMach->addAnalysisPasses(codeGenPasses);
 
   formatted_raw_ostream Out(out);
 
index 9e1c8997518ec0740fa87f90a999e8764acdc812..f0644ea3cc232f0fd1dbeee3e879567cb1c0f5a8 100644 (file)
@@ -267,3 +267,7 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T,
 char *LLVMGetDefaultTargetTriple(void) {
   return strdup(sys::getDefaultTargetTriple().c_str());
 }
+
+void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM) {
+  unwrap(T)->addAnalysisPasses(*unwrap(PM));
+}
index 6373d20811df0846851a702e62dd7fc4c80625f4..225a490d536940fcb70506907a8671bdb31f8108 100644 (file)
@@ -319,9 +319,6 @@ static int compileModule(char **argv, LLVMContext &Context) {
     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));