[llvm] [PassBuilder] Replace `bool LTOPreLink` with `ThinOrFullLTOPhase Phase` (PR #114564)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 1 10:12:41 PDT 2024
https://github.com/shiltian updated https://github.com/llvm/llvm-project/pull/114564
>From 8f36cd96bcfbefa8259989e6439ad40545384dad Mon Sep 17 00:00:00 2001
From: Shilei Tian <i at tianshilei.me>
Date: Fri, 1 Nov 2024 12:22:06 -0400
Subject: [PATCH] [PassBuilder] Replace `bool LTOPreLink` with
`ThinOrFullLTOPhase Phase`
This will allow more fine-grained control in the future.
---
llvm/include/llvm/Passes/PassBuilder.h | 10 ++++++----
llvm/lib/Passes/PassBuilderPipelines.cpp | 24 +++++++++++-------------
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index e6ced0cccb9b3c..0ebfdbb7865fdd 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -245,8 +245,9 @@ class PassBuilder {
/// optimization and code generation without any link-time optimization. It
/// typically correspond to frontend "-O[123]" options for optimization
/// levels \c O1, \c O2 and \c O3 resp.
- ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level,
- bool LTOPreLink = false);
+ ModulePassManager buildPerModuleDefaultPipeline(
+ OptimizationLevel Level,
+ ThinOrFullLTOPhase Phase = ThinOrFullLTOPhase::None);
/// Build a fat object default optimization pipeline.
///
@@ -296,8 +297,9 @@ class PassBuilder {
/// Build an O0 pipeline with the minimal semantically required passes.
///
/// This should only be used for non-LTO and LTO pre-link pipelines.
- ModulePassManager buildO0DefaultPipeline(OptimizationLevel Level,
- bool LTOPreLink = false);
+ ModulePassManager
+ buildO0DefaultPipeline(OptimizationLevel Level,
+ ThinOrFullLTOPhase Phase = ThinOrFullLTOPhase::None);
/// Build the default `AAManager` with the default alias analysis pipeline
/// registered.
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 3f28dd39911f79..466fbcd7bb7703 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1601,9 +1601,9 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
ModulePassManager
PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
- bool LTOPreLink) {
+ ThinOrFullLTOPhase Phase) {
if (Level == OptimizationLevel::O0)
- return buildO0DefaultPipeline(Level, LTOPreLink);
+ return buildO0DefaultPipeline(Level, Phase);
ModulePassManager MPM;
@@ -1619,14 +1619,11 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
// Apply module pipeline start EP callback.
invokePipelineStartEPCallbacks(MPM, Level);
- const ThinOrFullLTOPhase LTOPhase = LTOPreLink
- ? ThinOrFullLTOPhase::FullLTOPreLink
- : ThinOrFullLTOPhase::None;
// Add the core simplification pipeline.
- MPM.addPass(buildModuleSimplificationPipeline(Level, LTOPhase));
+ MPM.addPass(buildModuleSimplificationPipeline(Level, Phase));
// Now add the optimization pipeline.
- MPM.addPass(buildModuleOptimizationPipeline(Level, LTOPhase));
+ MPM.addPass(buildModuleOptimizationPipeline(Level, Phase));
if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
PGOOpt->Action == PGOOptions::SampleUse)
@@ -1635,7 +1632,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
// Emit annotation remarks.
addAnnotationRemarksPass(MPM);
- if (LTOPreLink)
+ if (isLTOPreLink(Phase))
addRequiredLTOPreLinkPasses(MPM);
return MPM;
}
@@ -1673,7 +1670,7 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
ModulePassManager
PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
if (Level == OptimizationLevel::O0)
- return buildO0DefaultPipeline(Level, /*LTOPreLink*/true);
+ return buildO0DefaultPipeline(Level, ThinOrFullLTOPhase::ThinLTOPreLink);
ModulePassManager MPM;
@@ -1794,7 +1791,7 @@ ModulePassManager
PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
// FIXME: We should use a customized pre-link pipeline!
return buildPerModuleDefaultPipeline(Level,
- /* LTOPreLink */ true);
+ ThinOrFullLTOPhase::FullLTOPreLink);
}
ModulePassManager
@@ -2124,8 +2121,9 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
return MPM;
}
-ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
- bool LTOPreLink) {
+ModulePassManager
+PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
+ ThinOrFullLTOPhase Phase) {
assert(Level == OptimizationLevel::O0 &&
"buildO0DefaultPipeline should only be used with O0");
@@ -2220,7 +2218,7 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
invokeOptimizerLastEPCallbacks(MPM, Level);
- if (LTOPreLink)
+ if (isLTOPreLink(Phase))
addRequiredLTOPreLinkPasses(MPM);
MPM.addPass(createModuleToFunctionPassAdaptor(AnnotationRemarksPass()));
More information about the llvm-commits
mailing list