Skip to content

[PassBuilder] Replace bool LTOPreLink with ThinOrFullLTOPhase Phase #114564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading