Skip to content

Commit

Permalink
[PassBuilder] Replace bool LTOPreLink with `ThinOrFullLTOPhase Phas…
Browse files Browse the repository at this point in the history
…e` (#114564)

This will allow more fine-grained control in the future.
  • Loading branch information
shiltian authored Nov 1, 2024
1 parent 339c788 commit 5445edb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
10 changes: 6 additions & 4 deletions llvm/include/llvm/Passes/PassBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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.
Expand Down
24 changes: 11 additions & 13 deletions llvm/lib/Passes/PassBuilderPipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -1635,7 +1632,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
// Emit annotation remarks.
addAnnotationRemarksPass(MPM);

if (LTOPreLink)
if (isLTOPreLink(Phase))
addRequiredLTOPreLinkPasses(MPM);
return MPM;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -2220,7 +2218,7 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,

invokeOptimizerLastEPCallbacks(MPM, Level);

if (LTOPreLink)
if (isLTOPreLink(Phase))
addRequiredLTOPreLinkPasses(MPM);

MPM.addPass(createModuleToFunctionPassAdaptor(AnnotationRemarksPass()));
Expand Down

0 comments on commit 5445edb

Please sign in to comment.