diff options
author | Mircea Trofin <mtrofin@google.com> | 2024-05-16 12:17:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-16 12:17:22 -0700 |
commit | 174cdeced0fe0da07a03d0d118bd70b93badfbb1 (patch) | |
tree | f863b2747245efcd400d4523678db79fee8c09e4 /llvm/lib/Passes | |
parent | 476f7f65f9f17fab7e78f395b83dcb7b0bbd5215 (diff) | |
download | llvm-174cdeced0fe0da07a03d0d118bd70b93badfbb1.zip llvm-174cdeced0fe0da07a03d0d118bd70b93badfbb1.tar.gz llvm-174cdeced0fe0da07a03d0d118bd70b93badfbb1.tar.bz2 |
[nfc] Clarify when the various PGO instrumentation passes run (#92330)
The code seems easier to read if it's centered on what the user wants rather than combinations of whatever internal variables.
Diffstat (limited to 'llvm/lib/Passes')
-rw-r--r-- | llvm/lib/Passes/PassBuilderPipelines.cpp | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index 72f2739..682bdef 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -803,6 +803,20 @@ void PassBuilder::addPreInlinerPasses(ModulePassManager &MPM, MPM.addPass(GlobalDCEPass()); } +void PassBuilder::addPostPGOLoopRotation(ModulePassManager &MPM, + OptimizationLevel Level) { + if (EnablePostPGOLoopRotation) { + // Disable header duplication in loop rotation at -Oz. + MPM.addPass(createModuleToFunctionPassAdaptor( + createFunctionToLoopPassAdaptor( + LoopRotatePass(EnableLoopHeaderDuplication || + Level != OptimizationLevel::Oz), + /*UseMemorySSA=*/false, + /*UseBlockFrequencyInfo=*/false), + PTO.EagerlyInvalidateAnalyses)); + } +} + void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, OptimizationLevel Level, bool RunProfileGen, bool IsCS, bool AtomicCounterUpdate, @@ -824,17 +838,7 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, // Perform PGO instrumentation. MPM.addPass(PGOInstrumentationGen(IsCS)); - if (EnablePostPGOLoopRotation) { - // Disable header duplication in loop rotation at -Oz. - MPM.addPass(createModuleToFunctionPassAdaptor( - createFunctionToLoopPassAdaptor( - LoopRotatePass(EnableLoopHeaderDuplication || - Level != OptimizationLevel::Oz), - /*UseMemorySSA=*/false, - /*UseBlockFrequencyInfo=*/false), - PTO.EagerlyInvalidateAnalyses)); - } - + addPostPGOLoopRotation(MPM, Level); if (PGOCtxProfLoweringPass::isContextualIRPGOEnabled()) { MPM.addPass(PGOCtxProfLoweringPass()); return; @@ -1145,29 +1149,34 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM), PTO.EagerlyInvalidateAnalyses)); - // Invoke the pre-inliner passes for instrumentation PGO or MemProf. - if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink && - (PGOOpt->Action == PGOOptions::IRInstr || - PGOOpt->Action == PGOOptions::IRUse || !PGOOpt->MemoryProfile.empty())) + // We already asserted this happens in non-FullLTOPostLink earlier. + const bool IsPreLink = Phase != ThinOrFullLTOPhase::ThinLTOPostLink; + const bool IsPGOPreLink = PGOOpt && IsPreLink; + const bool IsPGOInstrGen = + IsPGOPreLink && PGOOpt->Action == PGOOptions::IRInstr; + const bool IsPGOInstrUse = + IsPGOPreLink && PGOOpt->Action == PGOOptions::IRUse; + const bool IsMemprofUse = IsPGOPreLink && !PGOOpt->MemoryProfile.empty(); + + if (IsPGOInstrGen || IsPGOInstrUse || IsMemprofUse) addPreInlinerPasses(MPM, Level, Phase); // Add all the requested passes for instrumentation PGO, if requested. - if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink && - (PGOOpt->Action == PGOOptions::IRInstr || - PGOOpt->Action == PGOOptions::IRUse)) { + if (IsPGOInstrGen || IsPGOInstrUse) { addPGOInstrPasses(MPM, Level, - /*RunProfileGen=*/PGOOpt->Action == PGOOptions::IRInstr, + /*RunProfileGen=*/IsPGOInstrGen, /*IsCS=*/false, PGOOpt->AtomicCounterUpdate, PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile, PGOOpt->FS); - MPM.addPass(PGOIndirectCallPromotion(false, false)); } - if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink && - PGOOpt->CSAction == PGOOptions::CSIRInstr) + + if (IsPGOInstrGen || IsPGOInstrUse) + MPM.addPass(PGOIndirectCallPromotion(false, false)); + + if (IsPGOPreLink && PGOOpt->CSAction == PGOOptions::CSIRInstr) MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->CSProfileGenFile)); - if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink && - !PGOOpt->MemoryProfile.empty()) + if (IsMemprofUse) MPM.addPass(MemProfUsePass(PGOOpt->MemoryProfile, PGOOpt->FS)); // Synthesize function entry counts for non-PGO compilation. |