summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Passes/PassBuilder.h28
-rw-r--r--llvm/lib/Passes/PassBuilder.cpp37
2 files changed, 37 insertions, 28 deletions
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 0502913e7fb..b6998882625 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -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.
///
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index c9e4839c931..de9e2a98deb 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -325,8 +325,8 @@ void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
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::buildFunctionSimplificationPipeline(OptimizationLevel Level,
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::OptimizationLevel Level) {
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::buildModuleSimplificationPipeline(OptimizationLevel Level,
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::buildModuleSimplificationPipeline(OptimizationLevel Level,
// 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::buildModuleSimplificationPipeline(OptimizationLevel Level,
// 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::buildPerModuleDefaultPipeline(OptimizationLevel Level,
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::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
// 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(OptimizationLevel Level,
!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));
OpenPOWER on IntegriCloud