diff options
author | Dehao Chen <dehao@google.com> | 2017-07-29 04:10:24 +0000 |
---|---|---|
committer | Dehao Chen <dehao@google.com> | 2017-07-29 04:10:24 +0000 |
commit | ce0842ce9cd73f71697c4383a75a9b1aa607271e (patch) | |
tree | 9596acd7950d5196fb5393a42e2825b257e31ac2 /llvm/lib/Passes | |
parent | 503fd446adcfacda0636f1eca473d997ca0b660a (diff) | |
download | bcm5719-llvm-ce0842ce9cd73f71697c4383a75a9b1aa607271e.tar.gz bcm5719-llvm-ce0842ce9cd73f71697c4383a75a9b1aa607271e.zip |
Refine the PGOOpt and SamplePGOSupport handling.
Summary:
Now that SamplePGOSupport is part of PGOOpt, there are several places that need tweaking:
1. AddDiscriminator pass should *not* be invoked at ThinLTOBackend (as it's already invoked in the PreLink phase)
2. addPGOInstrPasses should only be invoked when either ProfileGenFile or ProfileUseFile is non-empty.
3. SampleProfileLoaderPass should only be invoked when SampleProfileFile is non-empty.
4. PGOIndirectCallPromotion should only be invoked in ProfileUse phase, or in ThinLTOBackend of SamplePGO.
Reviewers: chandlerc, tejohnson, davidxl
Reviewed By: chandlerc
Subscribers: sanjoy, mehdi_amini, eraman, llvm-commits
Differential Revision: https://reviews.llvm.org/D36040
llvm-svn: 309478
Diffstat (limited to 'llvm/lib/Passes')
-rw-r--r-- | llvm/lib/Passes/PassBuilder.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index aeddfeaca75..c9e4839c931 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -535,8 +535,6 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, // Create an early function pass manager to cleanup the output of the // frontend. FunctionPassManager EarlyFPM(DebugLogging); - if (PGOOpt && PGOOpt->SamplePGOSupport) - EarlyFPM.addPass(AddDiscriminatorsPass()); EarlyFPM.addPass(SimplifyCFGPass()); EarlyFPM.addPass(SROA()); EarlyFPM.addPass(EarlyCSEPass()); @@ -574,18 +572,19 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, // Add all the requested passes for PGO, if requested. if (PGOOpt) { - assert(PGOOpt->RunProfileGen || !PGOOpt->SampleProfileFile.empty() || - !PGOOpt->ProfileUseFile.empty() || PGOOpt->SamplePGOSupport); - if (PGOOpt->SampleProfileFile.empty()) + if (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty()) + // Instrumentation based PGO (gen and use) addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen, PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile); - else + 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 PrepareForThinLTO phase during sample PGO because // it changes IR to makes profile annotation in back compile inaccurate. - if (!PrepareForThinLTO || PGOOpt->SampleProfileFile.empty()) + if ((!PrepareForThinLTO && !PGOOpt->SampleProfileFile.empty()) + || !PGOOpt->ProfileUseFile.empty()) MPM.addPass(PGOIndirectCallPromotion( false, PGOOpt && !PGOOpt->SampleProfileFile.empty())); } @@ -779,6 +778,9 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level, // Force any function attributes we want the rest of the pipeline to observe. MPM.addPass(ForceFunctionAttrsPass()); + if (PGOOpt && PGOOpt->SamplePGOSupport) + MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass())); + // Add the core simplification pipeline. MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging, /*PrepareForThinLTO=*/false)); @@ -799,6 +801,9 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level, // Force any function attributes we want the rest of the pipeline to observe. MPM.addPass(ForceFunctionAttrsPass()); + if (PGOOpt && PGOOpt->SamplePGOSupport) + MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass())); + // 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 // can. |