@@ -839,10 +839,6 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
839839 MPM.addPass (PGOInstrumentationGen (IsCS));
840840
841841 addPostPGOLoopRotation (MPM, Level);
842- if (PGOCtxProfLoweringPass::isContextualIRPGOEnabled ()) {
843- MPM.addPass (PGOCtxProfLoweringPass ());
844- return ;
845- }
846842 // Add the profile lowering pass.
847843 InstrProfOptions Options;
848844 if (!ProfileFile.empty ())
@@ -1157,8 +1153,17 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
11571153 const bool IsPGOInstrUse =
11581154 IsPGOPreLink && PGOOpt->Action == PGOOptions::IRUse;
11591155 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)
11621167 addPreInlinerPasses (MPM, Level, Phase);
11631168
11641169 // Add all the requested passes for instrumentation PGO, if requested.
@@ -1168,9 +1173,13 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
11681173 /* IsCS=*/ false , PGOOpt->AtomicCounterUpdate ,
11691174 PGOOpt->ProfileFile , PGOOpt->ProfileRemappingFile ,
11701175 PGOOpt->FS );
1176+ } else if (IsCtxProfGen) {
1177+ MPM.addPass (PGOInstrumentationGen (false ));
1178+ addPostPGOLoopRotation (MPM, Level);
1179+ MPM.addPass (PGOCtxProfLoweringPass ());
11711180 }
11721181
1173- if (IsPGOInstrGen || IsPGOInstrUse)
1182+ if (IsPGOInstrGen || IsPGOInstrUse || IsCtxProfGen )
11741183 MPM.addPass (PGOIndirectCallPromotion (false , false ));
11751184
11761185 if (IsPGOPreLink && PGOOpt->CSAction == PGOOptions::CSIRInstr)
0 commit comments