@@ -803,6 +803,20 @@ void PassBuilder::addPreInlinerPasses(ModulePassManager &MPM,
803
803
MPM.addPass (GlobalDCEPass ());
804
804
}
805
805
806
+ void PassBuilder::addPostPGOLoopRotation (ModulePassManager &MPM,
807
+ OptimizationLevel Level) {
808
+ if (EnablePostPGOLoopRotation) {
809
+ // Disable header duplication in loop rotation at -Oz.
810
+ MPM.addPass (createModuleToFunctionPassAdaptor (
811
+ createFunctionToLoopPassAdaptor (
812
+ LoopRotatePass (EnableLoopHeaderDuplication ||
813
+ Level != OptimizationLevel::Oz),
814
+ /* UseMemorySSA=*/ false ,
815
+ /* UseBlockFrequencyInfo=*/ false ),
816
+ PTO.EagerlyInvalidateAnalyses ));
817
+ }
818
+ }
819
+
806
820
void PassBuilder::addPGOInstrPasses (ModulePassManager &MPM,
807
821
OptimizationLevel Level, bool RunProfileGen,
808
822
bool IsCS, bool AtomicCounterUpdate,
@@ -824,17 +838,7 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
824
838
// Perform PGO instrumentation.
825
839
MPM.addPass (PGOInstrumentationGen (IsCS));
826
840
827
- if (EnablePostPGOLoopRotation) {
828
- // Disable header duplication in loop rotation at -Oz.
829
- MPM.addPass (createModuleToFunctionPassAdaptor (
830
- createFunctionToLoopPassAdaptor (
831
- LoopRotatePass (EnableLoopHeaderDuplication ||
832
- Level != OptimizationLevel::Oz),
833
- /* UseMemorySSA=*/ false ,
834
- /* UseBlockFrequencyInfo=*/ false ),
835
- PTO.EagerlyInvalidateAnalyses ));
836
- }
837
-
841
+ addPostPGOLoopRotation (MPM, Level);
838
842
if (PGOCtxProfLoweringPass::isContextualIRPGOEnabled ()) {
839
843
MPM.addPass (PGOCtxProfLoweringPass ());
840
844
return ;
@@ -1145,29 +1149,34 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
1145
1149
MPM.addPass (createModuleToFunctionPassAdaptor (std::move (GlobalCleanupPM),
1146
1150
PTO.EagerlyInvalidateAnalyses ));
1147
1151
1148
- // Invoke the pre-inliner passes for instrumentation PGO or MemProf.
1149
- if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink &&
1150
- (PGOOpt->Action == PGOOptions::IRInstr ||
1151
- PGOOpt->Action == PGOOptions::IRUse || !PGOOpt->MemoryProfile .empty ()))
1152
+ // We already asserted this happens in non-FullLTOPostLink earlier.
1153
+ const bool IsPreLink = Phase != ThinOrFullLTOPhase::ThinLTOPostLink;
1154
+ const bool IsPGOPreLink = PGOOpt && IsPreLink;
1155
+ const bool IsPGOInstrGen =
1156
+ IsPGOPreLink && PGOOpt->Action == PGOOptions::IRInstr;
1157
+ const bool IsPGOInstrUse =
1158
+ IsPGOPreLink && PGOOpt->Action == PGOOptions::IRUse;
1159
+ const bool IsMemprofUse = IsPGOPreLink && !PGOOpt->MemoryProfile .empty ();
1160
+
1161
+ if (IsPGOInstrGen || IsPGOInstrUse || IsMemprofUse)
1152
1162
addPreInlinerPasses (MPM, Level, Phase);
1153
1163
1154
1164
// Add all the requested passes for instrumentation PGO, if requested.
1155
- if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink &&
1156
- (PGOOpt->Action == PGOOptions::IRInstr ||
1157
- PGOOpt->Action == PGOOptions::IRUse)) {
1165
+ if (IsPGOInstrGen || IsPGOInstrUse) {
1158
1166
addPGOInstrPasses (MPM, Level,
1159
- /* RunProfileGen=*/ PGOOpt-> Action == PGOOptions::IRInstr ,
1167
+ /* RunProfileGen=*/ IsPGOInstrGen ,
1160
1168
/* IsCS=*/ false , PGOOpt->AtomicCounterUpdate ,
1161
1169
PGOOpt->ProfileFile , PGOOpt->ProfileRemappingFile ,
1162
1170
PGOOpt->FS );
1163
- MPM.addPass (PGOIndirectCallPromotion (false , false ));
1164
1171
}
1165
- if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink &&
1166
- PGOOpt->CSAction == PGOOptions::CSIRInstr)
1172
+
1173
+ if (IsPGOInstrGen || IsPGOInstrUse)
1174
+ MPM.addPass (PGOIndirectCallPromotion (false , false ));
1175
+
1176
+ if (IsPGOPreLink && PGOOpt->CSAction == PGOOptions::CSIRInstr)
1167
1177
MPM.addPass (PGOInstrumentationGenCreateVar (PGOOpt->CSProfileGenFile ));
1168
1178
1169
- if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink &&
1170
- !PGOOpt->MemoryProfile .empty ())
1179
+ if (IsMemprofUse)
1171
1180
MPM.addPass (MemProfUsePass (PGOOpt->MemoryProfile , PGOOpt->FS ));
1172
1181
1173
1182
// Synthesize function entry counts for non-PGO compilation.
0 commit comments