Skip to content

Commit

Permalink
[PGO] Promote indirect calls to conditional direct calls with value-p…
Browse files Browse the repository at this point in the history
…rofile

This patch implements the transformation that promotes indirect calls to
conditional direct calls when the indirect-call value profile meta-data is
available.

Differential Revision: http://reviews.llvm.org/D17864

llvm-svn: 267815
  • Loading branch information
xur-llvm committed Apr 27, 2016
1 parent 8dd6628 commit 6e34c49
Show file tree
Hide file tree
Showing 13 changed files with 1,092 additions and 1 deletion.
1 change: 1 addition & 0 deletions llvm/include/llvm/InitializePasses.h
Expand Up @@ -124,6 +124,7 @@ void initializeAAResultsWrapperPassPass(PassRegistry &);
void initializeGCOVProfilerPass(PassRegistry&);
void initializePGOInstrumentationGenPass(PassRegistry&);
void initializePGOInstrumentationUsePass(PassRegistry&);
void initializePGOIndirectCallPromotionPass(PassRegistry&);
void initializeInstrProfilingLegacyPassPass(PassRegistry &);
void initializeAddressSanitizerPass(PassRegistry&);
void initializeAddressSanitizerModulePass(PassRegistry&);
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/LinkAllPasses.h
Expand Up @@ -91,6 +91,7 @@ namespace {
(void) llvm::createGCOVProfilerPass();
(void) llvm::createPGOInstrumentationGenPass();
(void) llvm::createPGOInstrumentationUsePass();
(void) llvm::createPGOIndirectCallPromotionPass();
(void) llvm::createInstrProfilingLegacyPass();
(void) llvm::createFunctionImportPass();
(void) llvm::createFunctionInliningPass();
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/Transforms/Instrumentation.h
Expand Up @@ -83,6 +83,7 @@ ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
ModulePass *createPGOInstrumentationGenPass();
ModulePass *
createPGOInstrumentationUsePass(StringRef Filename = StringRef(""));
ModulePass *createPGOIndirectCallPromotionPass(bool InLTO = false);

/// Options for the frontend instrumentation based profiling pass.
struct InstrProfOptions {
Expand Down
11 changes: 10 additions & 1 deletion llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
Expand Up @@ -371,10 +371,13 @@ void PassManagerBuilder::populateModulePassManager(
MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
}

if (!PerformThinLTO)
if (!PerformThinLTO) {
/// PGO instrumentation is added during the compile phase for ThinLTO, do
/// not run it a second time
addPGOInstrPasses(MPM);
// Indirect call promotion that promotes intra-module targets only.
MPM.add(createPGOIndirectCallPromotionPass());
}

if (EnableNonLTOGlobalsModRef)
// We add a module alias analysis pass here. In part due to bugs in the
Expand Down Expand Up @@ -585,6 +588,12 @@ void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
// Infer attributes about declarations if possible.
PM.add(createInferFunctionAttrsLegacyPass());

// Indirect call promotion. This should promote all the targets that are left
// by the earlier promotion pass that promotes intra-module targets.
// This two-step promotion is to save the compile time. For LTO, it should
// produce the same result as if we only do promotion here.
PM.add(createPGOIndirectCallPromotionPass(true));

// Propagate constants at call sites into the functions they call. This
// opens opportunities for globalopt (and inlining) by substituting function
// pointers passed as arguments to direct uses of functions.
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Instrumentation/CMakeLists.txt
Expand Up @@ -4,6 +4,7 @@ add_llvm_library(LLVMInstrumentation
DataFlowSanitizer.cpp
GCOVProfiling.cpp
MemorySanitizer.cpp
IndirectCallPromotion.cpp
Instrumentation.cpp
InstrProfiling.cpp
PGOInstrumentation.cpp
Expand Down

0 comments on commit 6e34c49

Please sign in to comment.