[llvm] r309500 - Refactor the build{Module|Function}SimplificationPipeline to expose optimization phase.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 29 21:55:39 PDT 2017
Author: dehao
Date: Sat Jul 29 21:55:39 2017
New Revision: 309500
URL: http://llvm.org/viewvc/llvm-project?rev=309500&view=rev
Log:
Refactor the build{Module|Function}SimplificationPipeline to expose optimization phase.
Summary: This is in preparation of https://reviews.llvm.org/D36052
Reviewers: chandlerc, davidxl, tejohnson
Reviewed By: chandlerc
Subscribers: sanjoy, llvm-commits
Differential Revision: https://reviews.llvm.org/D36053
Modified:
llvm/trunk/include/llvm/Passes/PassBuilder.h
llvm/trunk/lib/Passes/PassBuilder.cpp
Modified: llvm/trunk/include/llvm/Passes/PassBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Passes/PassBuilder.h?rev=309500&r1=309499&r2=309500&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Passes/PassBuilder.h (original)
+++ llvm/trunk/include/llvm/Passes/PassBuilder.h Sat Jul 29 21:55:39 2017
@@ -71,6 +71,18 @@ public:
std::vector<PipelineElement> InnerPipeline;
};
+ /// \brief ThinLTO phase.
+ ///
+ /// This enumerates the LLVM ThinLTO optimization phases.
+ enum class ThinLTOPhase {
+ /// No ThinLTO behavior needed.
+ None,
+ // ThinLTO prelink (summary) phase.
+ PreLink,
+ // ThinLTO postlink (backend compile) phase.
+ PostLink
+ };
+
/// \brief LLVM-provided high-level optimization levels.
///
/// This enumerates the LLVM-provided high-level optimization levels. Each
@@ -214,13 +226,11 @@ public:
/// require some transformations for semantic reasons, they should explicitly
/// build them.
///
- /// \p PrepareForThinLTO indicates whether this is invoked in
- /// PrepareForThinLTO phase. Special handling is needed for sample PGO to
- /// ensure profile accurate in the backend profile annotation phase.
+ /// \p Phase indicates the current ThinLTO phase.
FunctionPassManager
buildFunctionSimplificationPipeline(OptimizationLevel Level,
- bool DebugLogging = false,
- bool PrepareForThinLTO = false);
+ ThinLTOPhase Phase,
+ bool DebugLogging = false);
/// Construct the core LLVM module canonicalization and simplification
/// pipeline.
@@ -236,13 +246,11 @@ public:
/// require some transformations for semantic reasons, they should explicitly
/// build them.
///
- /// \p PrepareForThinLTO indicates whether this is invoked in
- /// PrepareForThinLTO phase. Special handling is needed for sample PGO to
- /// ensure profile accurate in the backend profile annotation phase.
+ /// \p Phase indicates the current ThinLTO phase.
ModulePassManager
buildModuleSimplificationPipeline(OptimizationLevel Level,
- bool DebugLogging = false,
- bool PrepareForThinLTO = false);
+ ThinLTOPhase Phase,
+ bool DebugLogging = false);
/// Construct the core LLVM module optimization pipeline.
///
Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=309500&r1=309499&r2=309500&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Sat Jul 29 21:55:39 2017
@@ -325,8 +325,8 @@ void PassBuilder::registerLoopAnalyses(L
FunctionPassManager
PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
- bool DebugLogging,
- bool PrepareForThinLTO) {
+ ThinLTOPhase Phase,
+ bool DebugLogging) {
assert(Level != O0 && "Must request optimizations!");
FunctionPassManager FPM(DebugLogging);
@@ -389,10 +389,11 @@ PassBuilder::buildFunctionSimplification
C(LPM2, Level);
LPM2.addPass(LoopDeletionPass());
- // Do not enable unrolling in PrepareForThinLTO phase during sample PGO
+ // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
// because it changes IR to makes profile annotation in back compile
// inaccurate.
- if (!PrepareForThinLTO || !PGOOpt || PGOOpt->SampleProfileFile.empty())
+ if (Phase != ThinLTOPhase::PreLink ||
+ !PGOOpt || PGOOpt->SampleProfileFile.empty())
LPM2.addPass(LoopUnrollPass::createFull(Level));
for (auto &C : LoopOptimizerEndEPCallbacks)
@@ -524,8 +525,8 @@ getInlineParamsFromOptLevel(PassBuilder:
ModulePassManager
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
- bool DebugLogging,
- bool PrepareForThinLTO) {
+ ThinLTOPhase Phase,
+ bool DebugLogging) {
ModulePassManager MPM(DebugLogging);
// Do basic inference of function attributes from known properties of system
@@ -581,9 +582,9 @@ PassBuilder::buildModuleSimplificationPi
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
+ // Do not enable it in PreLinkThinLTO phase during sample PGO because
// it changes IR to makes profile annotation in back compile inaccurate.
- if ((!PrepareForThinLTO && !PGOOpt->SampleProfileFile.empty())
+ if ((Phase != ThinLTOPhase::PreLink && !PGOOpt->SampleProfileFile.empty())
|| !PGOOpt->ProfileUseFile.empty())
MPM.addPass(PGOIndirectCallPromotion(
false, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
@@ -611,10 +612,11 @@ PassBuilder::buildModuleSimplificationPi
// Run the inliner first. The theory is that we are walking bottom-up and so
// the callees have already been fully optimized, and we want to inline them
// into the callers so that our optimizations can reflect that.
- // For PrepareForThinLTO pass, we disable hot-caller heuristic for sample PGO
+ // For PreLinkThinLTO pass, we disable hot-caller heuristic for sample PGO
// because it makes profile annotation in the backend inaccurate.
InlineParams IP = getInlineParamsFromOptLevel(Level);
- if (PrepareForThinLTO && PGOOpt && !PGOOpt->SampleProfileFile.empty())
+ if (Phase == ThinLTOPhase::PreLink &&
+ PGOOpt && !PGOOpt->SampleProfileFile.empty())
IP.HotCallSiteThreshold = 0;
MainCGPipeline.addPass(InlinerPass(IP));
@@ -629,8 +631,7 @@ PassBuilder::buildModuleSimplificationPi
// Lastly, add the core function simplification pipeline nested inside the
// CGSCC walk.
MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
- buildFunctionSimplificationPipeline(Level, DebugLogging,
- PrepareForThinLTO)));
+ buildFunctionSimplificationPipeline(Level, Phase, DebugLogging)));
for (auto &C : CGSCCOptimizerLateEPCallbacks)
C(MainCGPipeline, Level);
@@ -782,8 +783,8 @@ PassBuilder::buildPerModuleDefaultPipeli
MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
// Add the core simplification pipeline.
- MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging,
- /*PrepareForThinLTO=*/false));
+ MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None,
+ DebugLogging));
// Now add the optimization pipeline.
MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
@@ -807,8 +808,8 @@ PassBuilder::buildThinLTOPreLinkDefaultP
// 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.
- MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging,
- /*PrepareForThinLTO=*/true));
+ MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PreLink,
+ DebugLogging));
// Run partial inlining pass to partially inline functions that have
// large bodies.
@@ -846,8 +847,8 @@ PassBuilder::buildThinLTODefaultPipeline
!PGOOpt->ProfileUseFile.empty()));
// Add the core simplification pipeline.
- MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging,
- /*PrepareForThinLTO=*/false));
+ MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
+ DebugLogging));
// Now add the optimization pipeline.
MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
More information about the llvm-commits
mailing list