@@ -839,10 +839,6 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
839
839
MPM.addPass (PGOInstrumentationGen (IsCS));
840
840
841
841
addPostPGOLoopRotation (MPM, Level);
842
- if (PGOCtxProfLoweringPass::isContextualIRPGOEnabled ()) {
843
- MPM.addPass (PGOCtxProfLoweringPass ());
844
- return ;
845
- }
846
842
// Add the profile lowering pass.
847
843
InstrProfOptions Options;
848
844
if (!ProfileFile.empty ())
@@ -1157,8 +1153,17 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
1157
1153
const bool IsPGOInstrUse =
1158
1154
IsPGOPreLink && PGOOpt->Action == PGOOptions::IRUse;
1159
1155
const bool IsMemprofUse = IsPGOPreLink && !PGOOpt->MemoryProfile .empty ();
1160
-
1161
- if (IsPGOInstrGen || IsPGOInstrUse || IsMemprofUse)
1156
+ // We don't want to mix pgo ctx gen and pgo gen; we also don't currently
1157
+ // enable ctx profiling from the frontend.
1158
+ assert (
1159
+ !(IsPGOInstrGen && PGOCtxProfLoweringPass::isContextualIRPGOEnabled ()) &&
1160
+ " Enabling both instrumented FDO and contextual instrumentation is not "
1161
+ " supported." );
1162
+ // Enable contextual profiling instrumentation.
1163
+ const bool IsCtxProfGen = !IsPGOInstrGen && IsPreLink &&
1164
+ PGOCtxProfLoweringPass::isContextualIRPGOEnabled ();
1165
+
1166
+ if (IsPGOInstrGen || IsPGOInstrUse || IsMemprofUse || IsCtxProfGen)
1162
1167
addPreInlinerPasses (MPM, Level, Phase);
1163
1168
1164
1169
// Add all the requested passes for instrumentation PGO, if requested.
@@ -1168,9 +1173,13 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
1168
1173
/* IsCS=*/ false , PGOOpt->AtomicCounterUpdate ,
1169
1174
PGOOpt->ProfileFile , PGOOpt->ProfileRemappingFile ,
1170
1175
PGOOpt->FS );
1176
+ } else if (IsCtxProfGen) {
1177
+ MPM.addPass (PGOInstrumentationGen (false ));
1178
+ addPostPGOLoopRotation (MPM, Level);
1179
+ MPM.addPass (PGOCtxProfLoweringPass ());
1171
1180
}
1172
1181
1173
- if (IsPGOInstrGen || IsPGOInstrUse)
1182
+ if (IsPGOInstrGen || IsPGOInstrUse || IsCtxProfGen )
1174
1183
MPM.addPass (PGOIndirectCallPromotion (false , false ));
1175
1184
1176
1185
if (IsPGOPreLink && PGOOpt->CSAction == PGOOptions::CSIRInstr)
0 commit comments