@@ -733,47 +733,52 @@ void PassBuilder::addRequiredLTOPreLinkPasses(ModulePassManager &MPM) {
733
733
MPM.addPass (NameAnonGlobalPass ());
734
734
}
735
735
736
- void PassBuilder::addPGOInstrPasses (ModulePassManager &MPM,
737
- OptimizationLevel Level, bool RunProfileGen,
738
- bool IsCS, bool AtomicCounterUpdate,
739
- std::string ProfileFile,
740
- std::string ProfileRemappingFile,
741
- ThinOrFullLTOPhase LTOPhase,
742
- IntrusiveRefCntPtr<vfs::FileSystem> FS) {
736
+ void PassBuilder::addPreInlinerPasses (ModulePassManager &MPM,
737
+ OptimizationLevel Level,
738
+ ThinOrFullLTOPhase LTOPhase) {
743
739
assert (Level != OptimizationLevel::O0 && " Not expecting O0 here!" );
744
- if (!IsCS && !DisablePreInliner) {
745
- InlineParams IP;
740
+ if (DisablePreInliner)
741
+ return ;
742
+ InlineParams IP;
746
743
747
- IP.DefaultThreshold = PreInlineThreshold;
744
+ IP.DefaultThreshold = PreInlineThreshold;
748
745
749
- // FIXME: The hint threshold has the same value used by the regular inliner
750
- // when not optimzing for size. This should probably be lowered after
751
- // performance testing.
752
- // FIXME: this comment is cargo culted from the old pass manager, revisit).
753
- IP.HintThreshold = Level.isOptimizingForSize () ? PreInlineThreshold : 325 ;
754
- ModuleInlinerWrapperPass MIWP (
755
- IP, /* MandatoryFirst */ true ,
756
- InlineContext{LTOPhase, InlinePass::EarlyInliner});
757
- CGSCCPassManager &CGPipeline = MIWP.getPM ();
746
+ // FIXME: The hint threshold has the same value used by the regular inliner
747
+ // when not optimzing for size. This should probably be lowered after
748
+ // performance testing.
749
+ // FIXME: this comment is cargo culted from the old pass manager, revisit).
750
+ IP.HintThreshold = Level.isOptimizingForSize () ? PreInlineThreshold : 325 ;
751
+ ModuleInlinerWrapperPass MIWP (
752
+ IP, /* MandatoryFirst */ true ,
753
+ InlineContext{LTOPhase, InlinePass::EarlyInliner});
754
+ CGSCCPassManager &CGPipeline = MIWP.getPM ();
758
755
759
- FunctionPassManager FPM;
760
- FPM.addPass (SROAPass (SROAOptions::ModifyCFG));
761
- FPM.addPass (EarlyCSEPass ()); // Catch trivial redundancies.
762
- FPM.addPass (SimplifyCFGPass (SimplifyCFGOptions ().convertSwitchRangeToICmp (
763
- true ))); // Merge & remove basic blocks.
764
- FPM.addPass (InstCombinePass ()); // Combine silly sequences.
765
- invokePeepholeEPCallbacks (FPM, Level);
756
+ FunctionPassManager FPM;
757
+ FPM.addPass (SROAPass (SROAOptions::ModifyCFG));
758
+ FPM.addPass (EarlyCSEPass ()); // Catch trivial redundancies.
759
+ FPM.addPass (SimplifyCFGPass (SimplifyCFGOptions ().convertSwitchRangeToICmp (
760
+ true ))); // Merge & remove basic blocks.
761
+ FPM.addPass (InstCombinePass ()); // Combine silly sequences.
762
+ invokePeepholeEPCallbacks (FPM, Level);
766
763
767
- CGPipeline.addPass (createCGSCCToFunctionPassAdaptor (
768
- std::move (FPM), PTO.EagerlyInvalidateAnalyses ));
764
+ CGPipeline.addPass (createCGSCCToFunctionPassAdaptor (
765
+ std::move (FPM), PTO.EagerlyInvalidateAnalyses ));
769
766
770
- MPM.addPass (std::move (MIWP));
767
+ MPM.addPass (std::move (MIWP));
771
768
772
- // Delete anything that is now dead to make sure that we don't instrument
773
- // dead code. Instrumentation can end up keeping dead code around and
774
- // dramatically increase code size.
775
- MPM.addPass (GlobalDCEPass ());
776
- }
769
+ // Delete anything that is now dead to make sure that we don't instrument
770
+ // dead code. Instrumentation can end up keeping dead code around and
771
+ // dramatically increase code size.
772
+ MPM.addPass (GlobalDCEPass ());
773
+ }
774
+
775
+ void PassBuilder::addPGOInstrPasses (ModulePassManager &MPM,
776
+ OptimizationLevel Level, bool RunProfileGen,
777
+ bool IsCS, bool AtomicCounterUpdate,
778
+ std::string ProfileFile,
779
+ std::string ProfileRemappingFile,
780
+ IntrusiveRefCntPtr<vfs::FileSystem> FS) {
781
+ assert (Level != OptimizationLevel::O0 && " Not expecting O0 here!" );
777
782
778
783
if (!RunProfileGen) {
779
784
assert (!ProfileFile.empty () && " Profile use expecting a profile file!" );
@@ -1104,14 +1109,20 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
1104
1109
MPM.addPass (createModuleToFunctionPassAdaptor (std::move (GlobalCleanupPM),
1105
1110
PTO.EagerlyInvalidateAnalyses ));
1106
1111
1112
+ // Invoke the pre-inliner passes for instrumentation PGO or MemProf.
1113
+ if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink &&
1114
+ (PGOOpt->Action == PGOOptions::IRInstr ||
1115
+ PGOOpt->Action == PGOOptions::IRUse || !PGOOpt->MemoryProfile .empty ()))
1116
+ addPreInlinerPasses (MPM, Level, Phase);
1117
+
1107
1118
// Add all the requested passes for instrumentation PGO, if requested.
1108
1119
if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink &&
1109
1120
(PGOOpt->Action == PGOOptions::IRInstr ||
1110
1121
PGOOpt->Action == PGOOptions::IRUse)) {
1111
1122
addPGOInstrPasses (MPM, Level,
1112
1123
/* RunProfileGen=*/ PGOOpt->Action == PGOOptions::IRInstr,
1113
1124
/* IsCS=*/ false , PGOOpt->AtomicCounterUpdate ,
1114
- PGOOpt->ProfileFile , PGOOpt->ProfileRemappingFile , Phase,
1125
+ PGOOpt->ProfileFile , PGOOpt->ProfileRemappingFile ,
1115
1126
PGOOpt->FS );
1116
1127
MPM.addPass (PGOIndirectCallPromotion (false , false ));
1117
1128
}
@@ -1332,12 +1343,12 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
1332
1343
addPGOInstrPasses (MPM, Level, /* RunProfileGen=*/ true ,
1333
1344
/* IsCS=*/ true , PGOOpt->AtomicCounterUpdate ,
1334
1345
PGOOpt->CSProfileGenFile , PGOOpt->ProfileRemappingFile ,
1335
- LTOPhase, PGOOpt->FS );
1346
+ PGOOpt->FS );
1336
1347
else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
1337
1348
addPGOInstrPasses (MPM, Level, /* RunProfileGen=*/ false ,
1338
1349
/* IsCS=*/ true , PGOOpt->AtomicCounterUpdate ,
1339
1350
PGOOpt->ProfileFile , PGOOpt->ProfileRemappingFile ,
1340
- LTOPhase, PGOOpt->FS );
1351
+ PGOOpt->FS );
1341
1352
}
1342
1353
1343
1354
// Re-compute GlobalsAA here prior to function passes. This is particularly
@@ -1831,12 +1842,12 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
1831
1842
addPGOInstrPasses (MPM, Level, /* RunProfileGen=*/ true ,
1832
1843
/* IsCS=*/ true , PGOOpt->AtomicCounterUpdate ,
1833
1844
PGOOpt->CSProfileGenFile , PGOOpt->ProfileRemappingFile ,
1834
- ThinOrFullLTOPhase::FullLTOPostLink, PGOOpt->FS );
1845
+ PGOOpt->FS );
1835
1846
else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
1836
1847
addPGOInstrPasses (MPM, Level, /* RunProfileGen=*/ false ,
1837
1848
/* IsCS=*/ true , PGOOpt->AtomicCounterUpdate ,
1838
1849
PGOOpt->ProfileFile , PGOOpt->ProfileRemappingFile ,
1839
- ThinOrFullLTOPhase::FullLTOPostLink, PGOOpt->FS );
1850
+ PGOOpt->FS );
1840
1851
}
1841
1852
1842
1853
// Break up allocas
0 commit comments