Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 9ce88db

Browse files
committed
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199926 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a8aa6c3 commit 9ce88db

File tree

10 files changed

+30
-4
lines changed

10 files changed

+30
-4
lines changed

include/llvm-c/ExecutionEngine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
163163
LLVMValueRef Fn);
164164

165165
LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
166+
LLVMTargetMachineRef
167+
LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE);
166168

167169
void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
168170
void* Addr);

include/llvm-c/TargetMachine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleR
137137
disposed with LLVMDisposeMessage. */
138138
char* LLVMGetDefaultTargetTriple(void);
139139

140+
/** Adds the target-specific analysis passes to the pass manager. */
141+
void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);
142+
140143
#ifdef __cplusplus
141144
}
142145
#endif

include/llvm/ExecutionEngine/ExecutionEngine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ class ExecutionEngine {
462462
llvm_unreachable("No support for an object cache");
463463
}
464464

465+
/// Return the target machine (if available).
466+
virtual TargetMachine *getTargetMachine() { return NULL; }
467+
465468
/// DisableLazyCompilation - When lazy compilation is off (the default), the
466469
/// JIT will eagerly compile every function reachable from the argument to
467470
/// getPointerToFunction. If lazy compilation is turned on, the JIT will only

lib/CodeGen/LLVMTargetMachine.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ static MCContext *addPassesToGenerateCode(LLVMTargetMachine *TM,
9292
bool DisableVerify,
9393
AnalysisID StartAfter,
9494
AnalysisID StopAfter) {
95+
// Add internal analysis passes from the target machine.
96+
TM->addAnalysisPasses(PM);
97+
9598
// Targets may override createPassConfig to provide a target-specific sublass.
9699
TargetPassConfig *PassConfig = TM->createPassConfig(PM);
97100
PassConfig->setStartStopPasses(StartAfter, StopAfter);

lib/ExecutionEngine/ExecutionEngineBindings.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
4343
return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
4444
}
4545

46+
inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
47+
return
48+
reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine*>(P));
49+
}
50+
4651
/*===-- Operations on generic values --------------------------------------===*/
4752

4853
LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
@@ -323,6 +328,11 @@ LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE) {
323328
return wrap(unwrap(EE)->getDataLayout());
324329
}
325330

331+
LLVMTargetMachineRef
332+
LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE) {
333+
return wrap(unwrap(EE)->getTargetMachine());
334+
}
335+
326336
void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
327337
void* Addr) {
328338
unwrap(EE)->addGlobalMapping(unwrap<GlobalValue>(Global), Addr);

lib/ExecutionEngine/JIT/JIT.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ class JIT : public ExecutionEngine {
193193

194194
virtual void RegisterJITEventListener(JITEventListener *L);
195195
virtual void UnregisterJITEventListener(JITEventListener *L);
196+
197+
virtual TargetMachine *getTargetMachine() { return &TM; }
198+
196199
/// These functions correspond to the methods on JITEventListener. They
197200
/// iterate over the registered listeners and call the corresponding method on
198201
/// each.

lib/ExecutionEngine/MCJIT/MCJIT.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ class MCJIT : public ExecutionEngine {
301301
virtual uint64_t getGlobalValueAddress(const std::string &Name);
302302
virtual uint64_t getFunctionAddress(const std::string &Name);
303303

304+
virtual TargetMachine *getTargetMachine() { return TM; }
305+
304306
/// @}
305307
/// @name (Private) Registration Interfaces
306308
/// @{

lib/LTO/LTOCodeGenerator.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
498498
PassManager codeGenPasses;
499499

500500
codeGenPasses.add(new DataLayout(*TargetMach->getDataLayout()));
501-
TargetMach->addAnalysisPasses(codeGenPasses);
502501

503502
formatted_raw_ostream Out(out);
504503

lib/Target/TargetMachineC.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,7 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T,
267267
char *LLVMGetDefaultTargetTriple(void) {
268268
return strdup(sys::getDefaultTargetTriple().c_str());
269269
}
270+
271+
void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM) {
272+
unwrap(T)->addAnalysisPasses(*unwrap(PM));
273+
}

tools/llc/llc.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,6 @@ static int compileModule(char **argv, LLVMContext &Context) {
319319
TLI->disableAllFunctions();
320320
PM.add(TLI);
321321

322-
// Add intenal analysis passes from the target machine.
323-
Target.addAnalysisPasses(PM);
324-
325322
// Add the target data from the target machine, if it exists, or the module.
326323
if (const DataLayout *TD = Target.getDataLayout())
327324
PM.add(new DataLayout(*TD));

0 commit comments

Comments
 (0)