Skip to content

Commit 04e094a

Browse files
committed
[PGO] Remove legacy PM passes
Legacy PM for optimization pipeline was deprecated in 13.0.0 and Clang dropped legacy PM support in D123609. This change removes legacy PM passes for PGO so that downstream projects won't be able to use it. It seems appropriate to start removing such "add-on" features like instrumentations, before we remove more stuff after 15.x is branched. I have checked many LLVM users and only ldc[1] uses the legacy PGO pass. [1]: ldc-developers/ldc#3961 Reviewed By: davidxl Differential Revision: https://reviews.llvm.org/D123834
1 parent ed499dd commit 04e094a

File tree

10 files changed

+0
-410
lines changed

10 files changed

+0
-410
lines changed

llvm/include/llvm/InitializePasses.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,6 @@ void initializeOptimizationRemarkEmitterWrapperPassPass(PassRegistry&);
342342
void initializeOptimizePHIsPass(PassRegistry&);
343343
void initializePAEvalPass(PassRegistry&);
344344
void initializePEIPass(PassRegistry&);
345-
void initializePGOIndirectCallPromotionLegacyPassPass(PassRegistry&);
346-
void initializePGOInstrumentationGenLegacyPassPass(PassRegistry&);
347-
void initializePGOInstrumentationUseLegacyPassPass(PassRegistry&);
348-
void initializePGOInstrumentationGenCreateVarLegacyPassPass(PassRegistry&);
349-
void initializePGOMemOPSizeOptLegacyPassPass(PassRegistry&);
350345
void initializePHIEliminationPass(PassRegistry&);
351346
void initializePartialInlinerLegacyPassPass(PassRegistry&);
352347
void initializePartiallyInlineLibCallsLegacyPassPass(PassRegistry&);

llvm/include/llvm/LinkAllPasses.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,6 @@ namespace {
103103
(void) llvm::createDomOnlyViewerPass();
104104
(void) llvm::createDomViewerPass();
105105
(void) llvm::createGCOVProfilerPass();
106-
(void) llvm::createPGOInstrumentationGenLegacyPass();
107-
(void) llvm::createPGOInstrumentationUseLegacyPass();
108-
(void) llvm::createPGOInstrumentationGenCreateVarLegacyPass();
109-
(void) llvm::createPGOIndirectCallPromotionLegacyPass();
110-
(void) llvm::createPGOMemOPSizeOptLegacyPass();
111106
(void) llvm::createInstrProfilingLegacyPass();
112107
(void) llvm::createFunctionImportPass();
113108
(void) llvm::createFunctionInliningPass();

llvm/include/llvm/Transforms/IPO/PassManagerBuilder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ class PassManagerBuilder {
213213
void addInitialAliasAnalysisPasses(legacy::PassManagerBase &PM) const;
214214
void addLTOOptimizationPasses(legacy::PassManagerBase &PM);
215215
void addLateLTOOptimizationPasses(legacy::PassManagerBase &PM);
216-
void addPGOInstrPasses(legacy::PassManagerBase &MPM, bool IsCS);
217216
void addFunctionSimplificationPasses(legacy::PassManagerBase &MPM);
218217
void addVectorPasses(legacy::PassManagerBase &PM, bool IsFullLTO);
219218

llvm/include/llvm/Transforms/Instrumentation.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,6 @@ struct GCOVOptions {
7878
ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
7979
GCOVOptions::getDefault());
8080

81-
// PGO Instrumention. Parameter IsCS indicates if this is the context sensitive
82-
// instrumentation.
83-
ModulePass *createPGOInstrumentationGenLegacyPass(bool IsCS = false);
84-
ModulePass *
85-
createPGOInstrumentationUseLegacyPass(StringRef Filename = StringRef(""),
86-
bool IsCS = false);
87-
ModulePass *createPGOInstrumentationGenCreateVarLegacyPass(
88-
StringRef CSInstrName = StringRef(""));
89-
ModulePass *createPGOIndirectCallPromotionLegacyPass(bool InLTO = false,
90-
bool SamplePGO = false);
91-
FunctionPass *createPGOMemOPSizeOptLegacyPass();
92-
9381
ModulePass *createCGProfileLegacyPass();
9482

9583
// The pgo-specific indirect call promotion function declared below is used by

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -327,61 +327,6 @@ void PassManagerBuilder::populateFunctionPassManager(
327327
FPM.add(createEarlyCSEPass());
328328
}
329329

330-
// Do PGO instrumentation generation or use pass as the option specified.
331-
void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM,
332-
bool IsCS = false) {
333-
if (IsCS) {
334-
if (!EnablePGOCSInstrGen && !EnablePGOCSInstrUse)
335-
return;
336-
} else if (!EnablePGOInstrGen && PGOInstrUse.empty() && PGOSampleUse.empty())
337-
return;
338-
339-
// Perform the preinline and cleanup passes for O1 and above.
340-
// We will not do this inline for context sensitive PGO (when IsCS is true).
341-
if (OptLevel > 0 && !DisablePreInliner && PGOSampleUse.empty() && !IsCS) {
342-
// Create preinline pass. We construct an InlineParams object and specify
343-
// the threshold here to avoid the command line options of the regular
344-
// inliner to influence pre-inlining. The only fields of InlineParams we
345-
// care about are DefaultThreshold and HintThreshold.
346-
InlineParams IP;
347-
IP.DefaultThreshold = PreInlineThreshold;
348-
// FIXME: The hint threshold has the same value used by the regular inliner
349-
// when not optimzing for size. This should probably be lowered after
350-
// performance testing.
351-
// Use PreInlineThreshold for both -Os and -Oz. Not running preinliner makes
352-
// the instrumented binary unusably large. Even if PreInlineThreshold is not
353-
// correct thresold for -Oz, it is better than not running preinliner.
354-
IP.HintThreshold = SizeLevel > 0 ? PreInlineThreshold : 325;
355-
356-
MPM.add(createFunctionInliningPass(IP));
357-
MPM.add(createSROAPass());
358-
MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
359-
MPM.add(createCFGSimplificationPass(
360-
SimplifyCFGOptions().convertSwitchRangeToICmp(
361-
true))); // Merge & remove BBs
362-
MPM.add(createInstructionCombiningPass()); // Combine silly seq's
363-
addExtensionsToPM(EP_Peephole, MPM);
364-
}
365-
if ((EnablePGOInstrGen && !IsCS) || (EnablePGOCSInstrGen && IsCS)) {
366-
MPM.add(createPGOInstrumentationGenLegacyPass(IsCS));
367-
// Add the profile lowering pass.
368-
InstrProfOptions Options;
369-
if (!PGOInstrGen.empty())
370-
Options.InstrProfileOutput = PGOInstrGen;
371-
Options.DoCounterPromotion = true;
372-
Options.UseBFIInPromotion = IsCS;
373-
MPM.add(createLoopRotatePass());
374-
MPM.add(createInstrProfilingLegacyPass(Options, IsCS));
375-
}
376-
if (!PGOInstrUse.empty())
377-
MPM.add(createPGOInstrumentationUseLegacyPass(PGOInstrUse, IsCS));
378-
// Indirect call promotion that promotes intra-module targets only.
379-
// For ThinLTO this is done earlier due to interactions with globalopt
380-
// for imported functions. We don't run this at -O0.
381-
if (OptLevel > 0 && !IsCS)
382-
MPM.add(
383-
createPGOIndirectCallPromotionLegacyPass(false, !PGOSampleUse.empty()));
384-
}
385330
void PassManagerBuilder::addFunctionSimplificationPasses(
386331
legacy::PassManagerBase &MPM) {
387332
// Start of function pass.
@@ -423,10 +368,6 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
423368
MPM.add(createLibCallsShrinkWrapPass());
424369
addExtensionsToPM(EP_Peephole, MPM);
425370

426-
// Optimize memory intrinsic calls based on the profiled size information.
427-
if (SizeLevel == 0)
428-
MPM.add(createPGOMemOPSizeOptLegacyPass());
429-
430371
// TODO: Investigate the cost/benefit of tail call elimination on debugging.
431372
if (OptLevel > 1)
432373
MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
@@ -666,10 +607,6 @@ void PassManagerBuilder::addVectorPasses(legacy::PassManagerBase &PM,
666607

667608
void PassManagerBuilder::populateModulePassManager(
668609
legacy::PassManagerBase &MPM) {
669-
// Whether this is a default or *LTO pre-link pipeline. The FullLTO post-link
670-
// is handled separately, so just check this is not the ThinLTO post-link.
671-
bool DefaultOrPreLinkPipeline = !PerformThinLTO;
672-
673610
MPM.add(createAnnotation2MetadataLegacyPass());
674611

675612
if (!PGOSampleUse.empty()) {
@@ -687,7 +624,6 @@ void PassManagerBuilder::populateModulePassManager(
687624
// If all optimizations are disabled, just run the always-inline pass and,
688625
// if enabled, the function merging pass.
689626
if (OptLevel == 0) {
690-
addPGOInstrPasses(MPM);
691627
if (Inliner) {
692628
MPM.add(Inliner);
693629
Inliner = nullptr;
@@ -741,8 +677,6 @@ void PassManagerBuilder::populateModulePassManager(
741677
// earlier in the pass pipeline, here before globalopt. Otherwise imported
742678
// available_externally functions look unreferenced and are removed.
743679
if (PerformThinLTO) {
744-
MPM.add(createPGOIndirectCallPromotionLegacyPass(/*InLTO = */ true,
745-
!PGOSampleUse.empty()));
746680
MPM.add(createLowerTypeTestsPass(nullptr, nullptr, true));
747681
}
748682

@@ -785,19 +719,6 @@ void PassManagerBuilder::populateModulePassManager(
785719
createCFGSimplificationPass(SimplifyCFGOptions().convertSwitchRangeToICmp(
786720
true))); // Clean up after IPCP & DAE
787721

788-
// For SamplePGO in ThinLTO compile phase, we do not want to do indirect
789-
// call promotion as it will change the CFG too much to make the 2nd
790-
// profile annotation in backend more difficult.
791-
// PGO instrumentation is added during the compile phase for ThinLTO, do
792-
// not run it a second time
793-
if (DefaultOrPreLinkPipeline && !PrepareForThinLTOUsingPGOSampleProfile)
794-
addPGOInstrPasses(MPM);
795-
796-
// Create profile COMDAT variables. Lld linker wants to see all variables
797-
// before the LTO/ThinLTO link since it needs to resolve symbols/comdats.
798-
if (!PerformThinLTO && EnablePGOCSInstrGen)
799-
MPM.add(createPGOInstrumentationGenCreateVarLegacyPass(PGOInstrGen));
800-
801722
// We add a module alias analysis pass here. In part due to bugs in the
802723
// analysis infrastructure this "works" in that the analysis stays alive
803724
// for the entire SCC pass run below.
@@ -848,14 +769,6 @@ void PassManagerBuilder::populateModulePassManager(
848769
// and saves running remaining passes on the eliminated functions.
849770
MPM.add(createEliminateAvailableExternallyPass());
850771

851-
// CSFDO instrumentation and use pass. Don't invoke this for Prepare pass
852-
// for LTO and ThinLTO -- The actual pass will be called after all inlines
853-
// are performed.
854-
// Need to do this after COMDAT variables have been eliminated,
855-
// (i.e. after EliminateAvailableExternallyPass).
856-
if (!(PrepareForLTO || PrepareForThinLTO))
857-
addPGOInstrPasses(MPM, /* IsCS */ true);
858-
859772
if (EnableOrderFileInstrumentation)
860773
MPM.add(createInstrOrderFilePass());
861774

@@ -1022,13 +935,6 @@ void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
1022935
// Split call-site with more constrained arguments.
1023936
PM.add(createCallSiteSplittingPass());
1024937

1025-
// Indirect call promotion. This should promote all the targets that are
1026-
// left by the earlier promotion pass that promotes intra-module targets.
1027-
// This two-step promotion is to save the compile time. For LTO, it should
1028-
// produce the same result as if we only do promotion here.
1029-
PM.add(
1030-
createPGOIndirectCallPromotionLegacyPass(true, !PGOSampleUse.empty()));
1031-
1032938
// Propage constant function arguments by specializing the functions.
1033939
if (EnableFunctionSpecialization && OptLevel > 2)
1034940
PM.add(createFunctionSpecializationPass());
@@ -1094,9 +1000,6 @@ void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
10941000

10951001
PM.add(createPruneEHPass()); // Remove dead EH info.
10961002

1097-
// CSFDO instrumentation and use pass.
1098-
addPGOInstrPasses(PM, /* IsCS */ true);
1099-
11001003
// Infer attributes on declarations, call sites, arguments, etc. for an SCC.
11011004
if (AttributorRun & AttributorRunOption::CGSCC)
11021005
PM.add(createAttributorCGSCCLegacyPass());

llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -106,55 +106,6 @@ static cl::opt<bool>
106106

107107
namespace {
108108

109-
class PGOIndirectCallPromotionLegacyPass : public ModulePass {
110-
public:
111-
static char ID;
112-
113-
PGOIndirectCallPromotionLegacyPass(bool InLTO = false, bool SamplePGO = false)
114-
: ModulePass(ID), InLTO(InLTO), SamplePGO(SamplePGO) {
115-
initializePGOIndirectCallPromotionLegacyPassPass(
116-
*PassRegistry::getPassRegistry());
117-
}
118-
119-
void getAnalysisUsage(AnalysisUsage &AU) const override {
120-
AU.addRequired<ProfileSummaryInfoWrapperPass>();
121-
}
122-
123-
StringRef getPassName() const override { return "PGOIndirectCallPromotion"; }
124-
125-
private:
126-
bool runOnModule(Module &M) override;
127-
128-
// If this pass is called in LTO. We need to special handling the PGOFuncName
129-
// for the static variables due to LTO's internalization.
130-
bool InLTO;
131-
132-
// If this pass is called in SamplePGO. We need to add the prof metadata to
133-
// the promoted direct call.
134-
bool SamplePGO;
135-
};
136-
137-
} // end anonymous namespace
138-
139-
char PGOIndirectCallPromotionLegacyPass::ID = 0;
140-
141-
INITIALIZE_PASS_BEGIN(PGOIndirectCallPromotionLegacyPass, "pgo-icall-prom",
142-
"Use PGO instrumentation profile to promote indirect "
143-
"calls to direct calls.",
144-
false, false)
145-
INITIALIZE_PASS_DEPENDENCY(ProfileSummaryInfoWrapperPass)
146-
INITIALIZE_PASS_END(PGOIndirectCallPromotionLegacyPass, "pgo-icall-prom",
147-
"Use PGO instrumentation profile to promote indirect "
148-
"calls to direct calls.",
149-
false, false)
150-
151-
ModulePass *llvm::createPGOIndirectCallPromotionLegacyPass(bool InLTO,
152-
bool SamplePGO) {
153-
return new PGOIndirectCallPromotionLegacyPass(InLTO, SamplePGO);
154-
}
155-
156-
namespace {
157-
158109
// The class for main data structure to promote indirect calls to conditional
159110
// direct calls.
160111
class ICallPromotionFunc {
@@ -419,15 +370,6 @@ static bool promoteIndirectCalls(Module &M, ProfileSummaryInfo *PSI,
419370
return Changed;
420371
}
421372

422-
bool PGOIndirectCallPromotionLegacyPass::runOnModule(Module &M) {
423-
ProfileSummaryInfo *PSI =
424-
&getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
425-
426-
// Command-line option has the priority for InLTO.
427-
return promoteIndirectCalls(M, PSI, InLTO | ICPLTOMode,
428-
SamplePGO | ICPSamplePGOMode);
429-
}
430-
431373
PreservedAnalyses PGOIndirectCallPromotion::run(Module &M,
432374
ModuleAnalysisManager &AM) {
433375
ProfileSummaryInfo *PSI = &AM.getResult<ProfileSummaryAnalysis>(M);

llvm/lib/Transforms/Instrumentation/Instrumentation.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ void llvm::initializeInstrumentation(PassRegistry &Registry) {
9898
initializeBoundsCheckingLegacyPassPass(Registry);
9999
initializeControlHeightReductionLegacyPassPass(Registry);
100100
initializeGCOVProfilerLegacyPassPass(Registry);
101-
initializePGOInstrumentationGenLegacyPassPass(Registry);
102-
initializePGOInstrumentationUseLegacyPassPass(Registry);
103-
initializePGOIndirectCallPromotionLegacyPassPass(Registry);
104-
initializePGOMemOPSizeOptLegacyPassPass(Registry);
105101
initializeCGProfileLegacyPassPass(Registry);
106102
initializeInstrOrderFileLegacyPassPass(Registry);
107103
initializeInstrProfilingLegacyPassPass(Registry);

0 commit comments

Comments
 (0)