llvm.org GIT mirror llvm / 0d5bf69
[PGO] Context sensitive PGO (part 3) Part 3 of CSPGO changes (mostly related to PassMananger). Differential Revision: https://reviews.llvm.org/D54175 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355330 91177308-0d34-0410-b5e6-96231b3b80d8 Rong Xu 5 months ago
8 changed file(s) with 204 addition(s) and 67 deletion(s). Raw diff Collapse all Expand all
3030
3131 /// A struct capturing PGO tunables.
3232 struct PGOOptions {
33 PGOOptions(std::string ProfileGenFile = "", std::string ProfileUseFile = "",
34 std::string SampleProfileFile = "",
35 std::string ProfileRemappingFile = "",
36 bool RunProfileGen = false, bool SamplePGOSupport = false)
37 : ProfileGenFile(ProfileGenFile), ProfileUseFile(ProfileUseFile),
38 SampleProfileFile(SampleProfileFile),
39 ProfileRemappingFile(ProfileRemappingFile),
40 RunProfileGen(RunProfileGen),
41 SamplePGOSupport(SamplePGOSupport || !SampleProfileFile.empty()) {
42 assert((RunProfileGen ||
43 !SampleProfileFile.empty() ||
44 !ProfileUseFile.empty() ||
45 SamplePGOSupport) && "Illegal PGOOptions.");
46 }
47 std::string ProfileGenFile;
48 std::string ProfileUseFile;
49 std::string SampleProfileFile;
33 enum PGOAction { NoAction, IRInstr, IRUse, SampleUse };
34 enum CSPGOAction { NoCSAction, CSIRInstr, CSIRUse };
35 PGOOptions(std::string ProfileFile = "", std::string CSProfileGenFile = "",
36 std::string ProfileRemappingFile = "", PGOAction Action = NoAction,
37 CSPGOAction CSAction = NoCSAction, bool SamplePGOSupport = false)
38 : ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
39 ProfileRemappingFile(ProfileRemappingFile), Action(Action),
40 CSAction(CSAction),
41 SamplePGOSupport(SamplePGOSupport || Action == SampleUse) {
42 // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
43 // callback with IRUse action without ProfileFile.
44
45 // If there is a CSAction, PGOAction cannot be IRInstr or SampleUse.
46 assert(this->CSAction == NoCSAction ||
47 (this->Action != IRInstr && this->Action != SampleUse));
48
49 // For CSIRInstr, CSProfileGenFile also needs to be nonempty.
50 assert(this->CSAction != CSIRInstr || !this->CSProfileGenFile.empty());
51
52 // If CSAction is CSIRUse, PGOAction needs to be IRUse as they share
53 // a profile.
54 assert(this->CSAction != CSIRUse || this->Action == IRUse);
55
56 // If neither CSAction nor CSAction, SamplePGOSupport needs to be true.
57 assert(this->Action != NoAction || this->CSAction != NoCSAction ||
58 this->SamplePGOSupport);
59 }
60 std::string ProfileFile;
61 std::string CSProfileGenFile;
5062 std::string ProfileRemappingFile;
51 bool RunProfileGen;
63 PGOAction Action;
64 CSPGOAction CSAction;
5265 bool SamplePGOSupport;
5366 };
5467
606619 bool VerifyEachPass, bool DebugLogging);
607620
608621 void addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
609 OptimizationLevel Level, bool RunProfileGen,
610 std::string ProfileGenFile,
611 std::string ProfileUseFile,
622 OptimizationLevel Level, bool RunProfileGen, bool IsCS,
623 std::string ProfileFile,
612624 std::string ProfileRemappingFile);
613625
614626 void invokePeepholeEPCallbacks(FunctionPassManager &, OptimizationLevel);
158158
159159 /// Enable profile instrumentation pass.
160160 bool EnablePGOInstrGen;
161 /// Enable profile context sensitive instrumentation pass.
162 bool EnablePGOCSInstrGen;
163 /// Enable profile context sensitive profile use pass.
164 bool EnablePGOCSInstrUse;
161165 /// Profile data file name that the instrumentation will be written to.
162166 std::string PGOInstrGen;
163167 /// Path of the profile data file.
184188 void addInitialAliasAnalysisPasses(legacy::PassManagerBase &PM) const;
185189 void addLTOOptimizationPasses(legacy::PassManagerBase &PM);
186190 void addLateLTOOptimizationPasses(legacy::PassManagerBase &PM);
187 void addPGOInstrPasses(legacy::PassManagerBase &MPM);
191 void addPGOInstrPasses(legacy::PassManagerBase &MPM, bool IsCS);
188192 void addFunctionSimplificationPasses(legacy::PassManagerBase &MPM);
189193 void addInstructionCombiningPass(legacy::PassManagerBase &MPM) const;
190194
153153 const ModuleSummaryIndex *ImportSummary) {
154154 Optional PGOOpt;
155155 if (!Conf.SampleProfile.empty())
156 PGOOpt = PGOOptions("", "", Conf.SampleProfile, Conf.ProfileRemapping,
157 false, true);
156 PGOOpt = PGOOptions(Conf.SampleProfile, "", Conf.ProfileRemapping,
157 PGOOptions::SampleUse, PGOOptions::NoCSAction, true);
158 else if (Conf.RunCSIRInstr) {
159 PGOOpt = PGOOptions("", Conf.CSIRProfile, Conf.ProfileRemapping,
160 PGOOptions::IRUse, PGOOptions::CSIRInstr);
161 } else if (!Conf.CSIRProfile.empty()) {
162 PGOOpt = PGOOptions(Conf.CSIRProfile, "", Conf.ProfileRemapping,
163 PGOOptions::IRUse, PGOOptions::CSIRUse);
164 }
158165
159166 PassBuilder PB(TM, PGOOpt);
160167 AAManager AA;
272279 PMB.SLPVectorize = true;
273280 PMB.OptLevel = Conf.OptLevel;
274281 PMB.PGOSampleUse = Conf.SampleProfile;
282 PMB.EnablePGOCSInstrGen = Conf.RunCSIRInstr;
283 if (!Conf.RunCSIRInstr && !Conf.CSIRProfile.empty()) {
284 PMB.EnablePGOCSInstrUse = true;
285 PMB.PGOInstrUse = Conf.CSIRProfile;
286 }
275287 if (IsThinLTO)
276288 PMB.populateThinLTOPassManager(passes);
277289 else
405405
406406 // For PGO use pipeline, try to optimize memory intrinsics such as memcpy
407407 // using the size value profile. Don't perform this when optimizing for size.
408 if (PGOOpt && !PGOOpt->ProfileUseFile.empty() &&
408 if (PGOOpt && PGOOpt->Action == PGOOptions::IRUse &&
409409 !isOptimizingForSize(Level))
410410 FPM.addPass(PGOMemOPSizeOpt());
411411
448448 // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
449449 // because it changes IR to makes profile annotation in back compile
450450 // inaccurate.
451 if (Phase != ThinLTOPhase::PreLink ||
452 !PGOOpt || PGOOpt->SampleProfileFile.empty())
451 if (Phase != ThinLTOPhase::PreLink || !PGOOpt ||
452 PGOOpt->Action != PGOOptions::SampleUse)
453453 LPM2.addPass(LoopFullUnrollPass(Level));
454454
455455 for (auto &C : LoopOptimizerEndEPCallbacks)
509509 invokePeepholeEPCallbacks(FPM, Level);
510510
511511 if (EnableCHR && Level == O3 && PGOOpt &&
512 (!PGOOpt->ProfileUseFile.empty() || !PGOOpt->SampleProfileFile.empty()))
512 (PGOOpt->Action == PGOOptions::IRUse ||
513 PGOOpt->Action == PGOOptions::SampleUse))
513514 FPM.addPass(ControlHeightReductionPass());
514515
515516 return FPM;
517518
518519 void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
519520 PassBuilder::OptimizationLevel Level,
520 bool RunProfileGen,
521 std::string ProfileGenFile,
522 std::string ProfileUseFile,
521 bool RunProfileGen, bool IsCS,
522 std::string ProfileFile,
523523 std::string ProfileRemappingFile) {
524524 // Generally running simplification passes and the inliner with an high
525525 // threshold results in smaller executables, but there may be cases where
526526 // the size grows, so let's be conservative here and skip this simplification
527 // at -Os/Oz.
528 if (!isOptimizingForSize(Level)) {
527 // at -Os/Oz. We will not do this inline for context sensistive PGO (when
528 // IsCS is true).
529 if (!isOptimizingForSize(Level) && !IsCS) {
529530 InlineParams IP;
530531
531532 // In the old pass manager, this is a cl::opt. Should still this be one?
558559 MPM.addPass(GlobalDCEPass());
559560
560561 if (RunProfileGen) {
561 MPM.addPass(PGOInstrumentationGen());
562 MPM.addPass(PGOInstrumentationGen(IsCS));
562563
563564 FunctionPassManager FPM;
564565 FPM.addPass(
567568
568569 // Add the profile lowering pass.
569570 InstrProfOptions Options;
570 if (!ProfileGenFile.empty())
571 Options.InstrProfileOutput = ProfileGenFile;
571 if (!ProfileFile.empty())
572 Options.InstrProfileOutput = ProfileFile;
572573 Options.DoCounterPromotion = true;
573 Options.UseBFIInPromotion = false;
574 MPM.addPass(InstrProfiling(Options, false));
575 }
576
577 if (!ProfileUseFile.empty())
578 MPM.addPass(PGOInstrumentationUse(ProfileUseFile, ProfileRemappingFile));
574 Options.UseBFIInPromotion = IsCS;
575 MPM.addPass(InstrProfiling(Options, IsCS));
576 } else if (!ProfileFile.empty())
577 MPM.addPass(PGOInstrumentationUse(ProfileFile, ProfileRemappingFile, IsCS));
579578 }
580579
581580 static InlineParams
592591 bool DebugLogging) {
593592 ModulePassManager MPM(DebugLogging);
594593
595 bool HasSampleProfile = PGOOpt && !PGOOpt->SampleProfileFile.empty();
594 bool HasSampleProfile = PGOOpt && (PGOOpt->Action == PGOOptions::SampleUse);
596595
597596 // In ThinLTO mode, when flattened profile is used, all the available
598597 // profile information will be annotated in PreLink phase so there is
645644 if (LoadSampleProfile) {
646645 // Annotate sample profile right after early FPM to ensure freshness of
647646 // the debug info.
648 MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile,
647 MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
649648 PGOOpt->ProfileRemappingFile,
650649 Phase == ThinLTOPhase::PreLink));
651650 // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard
694693
695694 // Add all the requested passes for instrumentation PGO, if requested.
696695 if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
697 (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())) {
698 addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
699 PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile,
696 (PGOOpt->Action == PGOOptions::IRInstr ||
697 PGOOpt->Action == PGOOptions::IRUse)) {
698 addPGOInstrPasses(MPM, DebugLogging, Level,
699 /* RunProfileGen */ PGOOpt->Action == PGOOptions::IRInstr,
700 /* IsCS */ false, PGOOpt->ProfileFile,
700701 PGOOpt->ProfileRemappingFile);
701702 MPM.addPass(PGOIndirectCallPromotion(false, false));
702703 }
704 if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
705 PGOOpt->CSAction == PGOOptions::CSIRInstr)
706 MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->CSProfileGenFile));
703707
704708 // Synthesize function entry counts for non-PGO compilation.
705709 if (EnableSyntheticCounts && !PGOOpt)
730734 // For PreLinkThinLTO pass, we disable hot-caller heuristic for sample PGO
731735 // because it makes profile annotation in the backend inaccurate.
732736 InlineParams IP = getInlineParamsFromOptLevel(Level);
733 if (Phase == ThinLTOPhase::PreLink &&
734 PGOOpt && !PGOOpt->SampleProfileFile.empty())
737 if (Phase == ThinLTOPhase::PreLink && PGOOpt &&
738 PGOOpt->Action == PGOOptions::SampleUse)
735739 IP.HotCallSiteThreshold = 0;
736740 MainCGPipeline.addPass(InlinerPass(IP));
737741
793797 // attributes where applicable.
794798 // FIXME: Is this really an optimization rather than a canonicalization?
795799 MPM.addPass(ReversePostOrderFunctionAttrsPass());
800
801 // Do a post inline PGO instrumentation and use pass. This is a context
802 // sensitive PGO pass. We don't want to do this in LTOPreLink phrase as
803 // cross-module inline has not been done yet. The context sensitive
804 // instrumentation is after all the inlines are done.
805 if (!LTOPreLink && PGOOpt) {
806 if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
807 addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ true,
808 /* IsCS */ true, PGOOpt->CSProfileGenFile,
809 PGOOpt->ProfileRemappingFile);
810 else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
811 addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ false,
812 /* IsCS */ true, PGOOpt->ProfileFile,
813 PGOOpt->ProfileRemappingFile);
814 }
796815
797816 // Re-require GloblasAA here prior to function passes. This is particularly
798817 // useful as the above will have inlined, DCE'ed, and function-attr
10301049 assert(Level != O0 && "Must request optimizations for the default pipeline!");
10311050 // FIXME: We should use a customized pre-link pipeline!
10321051 return buildPerModuleDefaultPipeline(Level, DebugLogging,
1033 /*LTOPreLink=*/true);
1052 /* LTOPreLink */true);
10341053 }
10351054
10361055 ModulePassManager
10391058 assert(Level != O0 && "Must request optimizations for the default pipeline!");
10401059 ModulePassManager MPM(DebugLogging);
10411060
1042 if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) {
1061 if (PGOOpt && PGOOpt->Action == PGOOptions::SampleUse) {
10431062 // Load sample profile before running the LTO optimization pipeline.
1044 MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile,
1063 MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
10451064 PGOOpt->ProfileRemappingFile,
10461065 false /* ThinLTOPhase::PreLink */));
10471066 }
10671086 // This two-step promotion is to save the compile time. For LTO, it should
10681087 // produce the same result as if we only do promotion here.
10691088 MPM.addPass(PGOIndirectCallPromotion(
1070 true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
1089 true /* InLTO */, PGOOpt && PGOOpt->Action == PGOOptions::SampleUse));
10711090 // Propagate constants at call sites into the functions they call. This
10721091 // opens opportunities for globalopt (and inlining) by substituting function
10731092 // pointers passed as arguments to direct uses of functions.
11481167 invokePeepholeEPCallbacks(FPM, Level);
11491168
11501169 FPM.addPass(JumpThreadingPass());
1170
1171 // Do a post inline PGO instrumentation and use pass. This is a context
1172 // sensitive PGO pass.
1173 if (PGOOpt) {
1174 if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
1175 addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ true,
1176 /* IsCS */ true, PGOOpt->CSProfileGenFile,
1177 PGOOpt->ProfileRemappingFile);
1178 else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
1179 addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ false,
1180 /* IsCS */ true, PGOOpt->ProfileFile,
1181 PGOOpt->ProfileRemappingFile);
1182 }
11511183
11521184 // Break up allocas
11531185 FPM.addPass(SROA());
173173 MergeFunctions = false;
174174 PrepareForLTO = false;
175175 EnablePGOInstrGen = false;
176 EnablePGOCSInstrGen = false;
177 EnablePGOCSInstrUse = false;
176178 PGOInstrGen = "";
177179 PGOInstrUse = "";
178180 PGOSampleUse = "";
270272 }
271273
272274 // Do PGO instrumentation generation or use pass as the option specified.
273 void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM) {
274 if (!EnablePGOInstrGen && PGOInstrUse.empty() && PGOSampleUse.empty())
275 void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM,
276 bool IsCS = false) {
277 if (IsCS) {
278 if (!EnablePGOCSInstrGen && !EnablePGOCSInstrUse)
279 return;
280 } else if (!EnablePGOInstrGen && PGOInstrUse.empty() && PGOSampleUse.empty())
275281 return;
282
276283 // Perform the preinline and cleanup passes for O1 and above.
277284 // And avoid doing them if optimizing for size.
285 // We will not do this inline for context sensitive PGO (when IsCS is true).
278286 if (OptLevel > 0 && SizeLevel == 0 && !DisablePreInliner &&
279 PGOSampleUse.empty()) {
287 PGOSampleUse.empty() && !IsCS) {
280288 // Create preinline pass. We construct an InlineParams object and specify
281289 // the threshold here to avoid the command line options of the regular
282290 // inliner to influence pre-inlining. The only fields of InlineParams we
294302 MPM.add(createInstructionCombiningPass()); // Combine silly seq's
295303 addExtensionsToPM(EP_Peephole, MPM);
296304 }
297 if (EnablePGOInstrGen) {
298 MPM.add(createPGOInstrumentationGenLegacyPass());
305 if ((EnablePGOInstrGen && !IsCS) || (EnablePGOCSInstrGen && IsCS)) {
306 MPM.add(createPGOInstrumentationGenLegacyPass(IsCS));
299307 // Add the profile lowering pass.
300308 InstrProfOptions Options;
301309 if (!PGOInstrGen.empty())
302310 Options.InstrProfileOutput = PGOInstrGen;
303311 Options.DoCounterPromotion = true;
312 Options.UseBFIInPromotion = IsCS;
304313 MPM.add(createLoopRotatePass());
305 MPM.add(createInstrProfilingLegacyPass(Options));
314 MPM.add(createInstrProfilingLegacyPass(Options, IsCS));
306315 }
307316 if (!PGOInstrUse.empty())
308 MPM.add(createPGOInstrumentationUseLegacyPass(PGOInstrUse));
317 MPM.add(createPGOInstrumentationUseLegacyPass(PGOInstrUse, IsCS));
309318 // Indirect call promotion that promotes intra-module targets only.
310319 // For ThinLTO this is done earlier due to interactions with globalopt
311320 // for imported functions. We don't run this at -O0.
312 if (OptLevel > 0)
321 if (OptLevel > 0 && !IsCS)
313322 MPM.add(
314323 createPGOIndirectCallPromotionLegacyPass(false, !PGOSampleUse.empty()));
315324 }
417426 addExtensionsToPM(EP_Peephole, MPM);
418427
419428 if (EnableCHR && OptLevel >= 3 &&
420 (!PGOInstrUse.empty() || !PGOSampleUse.empty()))
429 (!PGOInstrUse.empty() || !PGOSampleUse.empty() || EnablePGOCSInstrGen))
421430 MPM.add(createControlHeightReductionLegacyPass());
422431 }
423432
531540 // not run it a second time
532541 if (DefaultOrPreLinkPipeline && !PrepareForThinLTOUsingPGOSampleProfile)
533542 addPGOInstrPasses(MPM);
543
544 // Create profile COMDAT variables. Lld linker wants to see all variables
545 // before the LTO/ThinLTO link since it needs to resolve symbols/comdats.
546 if (!PerformThinLTO && EnablePGOCSInstrGen)
547 MPM.add(createPGOInstrumentationGenCreateVarLegacyPass(PGOInstrGen));
534548
535549 // We add a module alias analysis pass here. In part due to bugs in the
536550 // analysis infrastructure this "works" in that the analysis stays alive
572586 // globals referenced by available external functions dead
573587 // and saves running remaining passes on the eliminated functions.
574588 MPM.add(createEliminateAvailableExternallyPass());
589
590 // CSFDO instrumentation and use pass. Don't invoke this for Prepare pass
591 // for LTO and ThinLTO -- The actual pass will be called after all inlines
592 // are performed.
593 // Need to do this after COMDAT variables have been eliminated,
594 // (i.e. after EliminateAvailableExternallyPass).
595 if (!(PrepareForLTO || PrepareForThinLTO))
596 addPGOInstrPasses(MPM, /* IsCS */ true);
575597
576598 if (EnableOrderFileInstrumentation)
577599 MPM.add(createInstrOrderFilePass());
853875
854876 PM.add(createPruneEHPass()); // Remove dead EH info.
855877
878 // CSFDO instrumentation and use pass.
879 addPGOInstrPasses(PM, /* IsCS */ true);
880
856881 // Optimize globals again if we ran the inliner.
857882 if (RunInliner)
858883 PM.add(createGlobalOptimizerPass());
101101
102102 extern cl::opt PGOKindFlag;
103103 extern cl::opt ProfileFile;
104 extern cl::opt CSPGOKindFlag;
105 extern cl::opt CSProfileGenFile;
106
104107 static cl::opt
105108 ProfileRemappingFile("profile-remapping-file",
106109 cl::desc("Path to the profile remapping file."),
218221 Optional P;
219222 switch (PGOKindFlag) {
220223 case InstrGen:
221 P = PGOOptions(ProfileFile, "", "", "", true);
224 P = PGOOptions(ProfileFile, "", "", PGOOptions::IRInstr);
222225 break;
223226 case InstrUse:
224 P = PGOOptions("", ProfileFile, "", ProfileRemappingFile, false);
227 P = PGOOptions(ProfileFile, "", ProfileRemappingFile, PGOOptions::IRUse);
225228 break;
226229 case SampleUse:
227 P = PGOOptions("", "", ProfileFile, ProfileRemappingFile, false);
230 P = PGOOptions(ProfileFile, "", ProfileRemappingFile,
231 PGOOptions::SampleUse);
228232 break;
229233 case NoPGO:
230234 if (DebugInfoForProfiling)
231 P = PGOOptions("", "", "", "", false, true);
235 P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
236 true);
232237 else
233238 P = None;
234 }
239 }
240 if (CSPGOKindFlag != NoCSPGO) {
241 if (P && (P->Action == PGOOptions::IRInstr ||
242 P->Action == PGOOptions::SampleUse))
243 errs() << "CSPGOKind cannot be used with IRInstr or SampleUse";
244 if (CSPGOKindFlag == CSInstrGen) {
245 if (CSProfileGenFile.empty())
246 errs() << "CSInstrGen needs to specify CSProfileGenFile";
247 if (P) {
248 P->CSAction = PGOOptions::CSIRInstr;
249 P->CSProfileGenFile = CSProfileGenFile;
250 } else
251 P = PGOOptions("", CSProfileGenFile, ProfileRemappingFile,
252 PGOOptions::NoAction, PGOOptions::CSIRInstr);
253 } else /* CSPGOKindFlag == CSInstrUse */ {
254 if (!P)
255 errs() << "CSInstrUse needs to be together with InstrUse";
256 P->CSAction = PGOOptions::CSIRUse;
257 }
258 }
235259 PassInstrumentationCallbacks PIC;
236260 StandardInstrumentations SI;
237261 SI.registerCallbacks(PIC);
4444 InstrUse,
4545 SampleUse
4646 };
47 enum CSPGOKind { NoCSPGO, CSInstrGen, CSInstrUse };
4748 }
4849
4950 /// Driver function to run the new pass manager over a module.
286286 cl::opt ProfileFile("profile-file",
287287 cl::desc("Path to the profile."), cl::Hidden);
288288
289 cl::opt CSPGOKindFlag(
290 "cspgo-kind", cl::init(NoCSPGO), cl::Hidden,
291 cl::desc("The kind of context sensitive profile guided optimization"),
292 cl::values(
293 clEnumValN(NoCSPGO, "nocspgo", "Do not use CSPGO."),
294 clEnumValN(
295 CSInstrGen, "cspgo-instr-gen-pipeline",
296 "Instrument (context sensitive) the IR to generate profile."),
297 clEnumValN(
298 CSInstrUse, "cspgo-instr-use-pipeline",
299 "Use instrumented (context sensitive) profile to guide PGO.")));
300 cl::opt CSProfileGenFile(
301 "cs-profilegen-file",
302 cl::desc("Path to the instrumented context sensitive profile."),
303 cl::Hidden);
304
289305 class OptCustomPassManager : public legacy::PassManager {
290306 DebugifyStatsMap DIStatsMap;
291307
390406 break;
391407 case SampleUse:
392408 Builder.PGOSampleUse = ProfileFile;
409 break;
410 default:
411 break;
412 }
413
414 switch (CSPGOKindFlag) {
415 case CSInstrGen:
416 Builder.EnablePGOCSInstrGen = true;
417 break;
418 case InstrUse:
419 Builder.EnablePGOCSInstrUse = true;
393420 break;
394421 default:
395422 break;