diff options
author | Dehao Chen <dehao@google.com> | 2017-08-07 20:23:20 +0000 |
---|---|---|
committer | Dehao Chen <dehao@google.com> | 2017-08-07 20:23:20 +0000 |
commit | 6858db5aed8707b5ef1b520d4aa7a5f5c1c37fcd (patch) | |
tree | 4bcd6d4ae15b727bd884072b721d33c535af6da4 /lib/Passes | |
parent | b6ff06ef35af98e150763d170b6687ae79df4092 (diff) |
Move the SampleProfileLoader right after EarlyFPM.
Summary: SampleProfileLoader pass do need to happen after some early cleanup passes so that inlining can happen correctly inside the SampleProfileLoader pass.
Reviewers: chandlerc, davidxl, tejohnson
Reviewed By: chandlerc, tejohnson
Subscribers: sanjoy, mehdi_amini, eraman, llvm-commits
Differential Revision: https://reviews.llvm.org/D36333
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310296 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Passes')
-rw-r--r-- | lib/Passes/PassBuilder.cpp | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/lib/Passes/PassBuilder.cpp b/lib/Passes/PassBuilder.cpp index 0b449bd5d45..e5f6cb01d21 100644 --- a/lib/Passes/PassBuilder.cpp +++ b/lib/Passes/PassBuilder.cpp @@ -540,8 +540,32 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, EarlyFPM.addPass(SROA()); EarlyFPM.addPass(EarlyCSEPass()); EarlyFPM.addPass(LowerExpectIntrinsicPass()); + // In SamplePGO ThinLTO backend, we need instcombine before profile annotation + // to convert bitcast to direct calls so that they can be inlined during the + // profile annotation prepration step. + // More details about SamplePGO design can be found in: + // https://research.google.com/pubs/pub45290.html + // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured. + if (PGOOpt && !PGOOpt->SampleProfileFile.empty() && + Phase == ThinLTOPhase::PostLink) + EarlyFPM.addPass(InstCombinePass()); MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM))); + if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) { + // Annotate sample profile right after early FPM to ensure freshness of + // the debug info. + MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile)); + // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard + // for the profile annotation to be accurate in the ThinLTO backend. + if (Phase != ThinLTOPhase::PreLink) + // We perform early indirect call promotion here, before globalopt. + // This is important for the ThinLTO backend phase because otherwise + // imported available_externally functions look unreferenced and are + // removed. + MPM.addPass(PGOIndirectCallPromotion(Phase == ThinLTOPhase::PostLink, + true)); + } + // Interprocedural constant propagation now that basic cleanup has occured // and prior to optimizing globals. // FIXME: This position in the pipeline hasn't been carefully considered in @@ -768,13 +792,8 @@ 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, @@ -796,14 +815,8 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(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 first time to annotate - // profile for functions in the current module to give ThinLink info - // about module grouping. - if (PGOOpt && PGOOpt->SamplePGOSupport) { + 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,16 +852,14 @@ 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())); + // FIXME: move this into buildModuleSimplificationPipeline to merge the logic + // with SamplePGO. + if (PGOOpt && !PGOOpt->ProfileUseFile.empty()) + MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */, + false /* SamplePGO */)); // Add the core simplification pipeline. MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink, |