[llvm] 174cdec - [nfc] Clarify when the various PGO instrumentation passes run (#92330)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 16 12:17:26 PDT 2024
Author: Mircea Trofin
Date: 2024-05-16T12:17:22-07:00
New Revision: 174cdeced0fe0da07a03d0d118bd70b93badfbb1
URL: https://github.com/llvm/llvm-project/commit/174cdeced0fe0da07a03d0d118bd70b93badfbb1
DIFF: https://github.com/llvm/llvm-project/commit/174cdeced0fe0da07a03d0d118bd70b93badfbb1.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/Passes/PassBuilder.h
llvm/lib/Passes/PassBuilderPipelines.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 9b4da1c466f57..8de0f024a4b11 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -723,6 +723,7 @@ class PassBuilder {
bool AtomicCounterUpdate, std::string ProfileFile,
std::string ProfileRemappingFile,
IntrusiveRefCntPtr<vfs::FileSystem> FS);
+ void addPostPGOLoopRotation(ModulePassManager &MPM, OptimizationLevel Level);
// Extension Point callbacks
SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 72f273972f2f7..682bdefbd5243 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.
More information about the llvm-commits
mailing list