summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Passes
diff options
context:
space:
mode:
authorDehao Chen <dehao@google.com>2017-08-02 01:28:31 +0000
committerDehao Chen <dehao@google.com>2017-08-02 01:28:31 +0000
commit89d322601932f515b824ead1c809591db8005655 (patch)
treeedebd5d2981c2e79a693e26d5deb37adfb3546c8 /llvm/lib/Passes
parentf23ae4fbe9287a824f93176afaddab08f07924a9 (diff)
downloadbcm5719-llvm-89d322601932f515b824ead1c809591db8005655.tar.gz
bcm5719-llvm-89d322601932f515b824ead1c809591db8005655.zip
Update the new PM pipeline to make ICP aware if it is SamplePGO build.
Summary: In ThinLTO backend compile, OPTOptions are not set so that the ICP in ThinLTO backend does not know if it is a SamplePGO build, in which profile count needs to be annotated directly on call instructions. This patch cleaned up the PGOOptions handling logic and passes down PGOOptions to ThinLTO backend. Reviewers: chandlerc, tejohnson, davidxl Reviewed By: chandlerc Subscribers: sanjoy, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D36052 llvm-svn: 309780
Diffstat (limited to 'llvm/lib/Passes')
-rw-r--r--llvm/lib/Passes/PassBuilder.cpp46
1 files changed, 25 insertions, 21 deletions
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index de9e2a98deb..f2dd950f22e 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -571,23 +571,12 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
GlobalCleanupPM.addPass(SimplifyCFGPass());
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
- // Add all the requested passes for PGO, if requested.
- if (PGOOpt) {
- if (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())
- // Instrumentation based PGO (gen and use)
- addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
- PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
- else if (!PGOOpt->SampleProfileFile.empty())
- // SamplePGO use
- MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
-
- // Indirect call promotion that promotes intra-module targes only.
- // Do not enable it in PreLinkThinLTO phase during sample PGO because
- // it changes IR to makes profile annotation in back compile inaccurate.
- if ((Phase != ThinLTOPhase::PreLink && !PGOOpt->SampleProfileFile.empty())
- || !PGOOpt->ProfileUseFile.empty())
- MPM.addPass(PGOIndirectCallPromotion(
- false, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
+ // Add all the requested passes for instrumentation PGO, if requested.
+ if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
+ (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())) {
+ addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
+ PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
+ MPM.addPass(PGOIndirectCallPromotion(false, false));
}
// Require the GlobalsAA analysis for the module so we can query it within
@@ -779,8 +768,13 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
// Force any function attributes we want the rest of the pipeline to observe.
MPM.addPass(ForceFunctionAttrsPass());
- if (PGOOpt && PGOOpt->SamplePGOSupport)
+ if (PGOOpt && PGOOpt->SamplePGOSupport) {
MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
+ if (!PGOOpt->SampleProfileFile.empty()) {
+ MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
+ MPM.addPass(PGOIndirectCallPromotion(false, true));
+ }
+ }
// Add the core simplification pipeline.
MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None,
@@ -802,8 +796,14 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
// Force any function attributes we want the rest of the pipeline to observe.
MPM.addPass(ForceFunctionAttrsPass());
- if (PGOOpt && PGOOpt->SamplePGOSupport)
+ // Invoke the SamplePGO annotation pass for the first time to annotate
+ // profile for functions in the current module to give ThinLink info
+ // about module grouping.
+ if (PGOOpt && PGOOpt->SamplePGOSupport) {
MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
+ if (!PGOOpt->SampleProfileFile.empty())
+ MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
+ }
// If we are planning to perform ThinLTO later, we don't bloat the code with
// unrolling/vectorization/... now. Just simplify the module as much as we
@@ -839,12 +839,16 @@ PassBuilder::buildThinLTODefaultPipeline(OptimizationLevel Level,
// Force any function attributes we want the rest of the pipeline to observe.
MPM.addPass(ForceFunctionAttrsPass());
+ // Invoke the SamplePGO annotation pass for the second time to annotate on
+ // functions imported from other modules.
+ if (PGOOpt && !PGOOpt->SampleProfileFile.empty())
+ MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
+
// During the ThinLTO backend phase we perform early indirect call promotion
// here, before globalopt. Otherwise imported available_externally functions
// look unreferenced and are removed.
MPM.addPass(PGOIndirectCallPromotion(
- true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
- !PGOOpt->ProfileUseFile.empty()));
+ true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
// Add the core simplification pipeline.
MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
OpenPOWER on IntegriCloud