Skip to content

Commit 4ea6ffb

Browse files
committed
[LegacyPM] Remove pipeline extension mechanism
Part of gradually removing the legacy PM optimization pipeline. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D136622
1 parent f7985dd commit 4ea6ffb

File tree

4 files changed

+0
-212
lines changed

4 files changed

+0
-212
lines changed

llvm/docs/WritingAnLLVMPass.rst

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,6 @@ without modifying it then the third argument is set to ``true``; if a pass is
185185
an analysis pass, for example dominator tree pass, then ``true`` is supplied as
186186
the fourth argument.
187187

188-
If we want to register the pass as a step of an existing pipeline, some extension
189-
points are provided, e.g. ``PassManagerBuilder::EP_EarlyAsPossible`` to apply our
190-
pass before any optimization, or ``PassManagerBuilder::EP_FullLinkTimeOptimizationLast``
191-
to apply it after Link Time Optimizations.
192-
193-
.. code-block:: c++
194-
195-
static llvm::RegisterStandardPasses Y(
196-
llvm::PassManagerBuilder::EP_EarlyAsPossible,
197-
[](const llvm::PassManagerBuilder &Builder,
198-
llvm::legacy::PassManagerBase &PM) { PM.add(new Hello()); });
199-
200188
As a whole, the ``.cpp`` file looks like:
201189

202190
.. code-block:: c++
@@ -228,11 +216,6 @@ As a whole, the ``.cpp`` file looks like:
228216
false /* Only looks at CFG */,
229217
false /* Analysis Pass */);
230218
231-
static RegisterStandardPasses Y(
232-
PassManagerBuilder::EP_EarlyAsPossible,
233-
[](const PassManagerBuilder &Builder,
234-
legacy::PassManagerBase &PM) { PM.add(new Hello()); });
235-
236219
Now that it's all together, compile the file with a simple "``gmake``" command
237220
from the top level of your build directory and you should get a new file
238221
"``lib/LLVMHello.so``". Note that everything in this file is

llvm/examples/Bye/Bye.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ static RegisterPass<LegacyBye> X("goodbye", "Good Bye World Pass",
4444
false /* Only looks at CFG */,
4545
false /* Analysis Pass */);
4646

47-
/* Legacy PM Registration */
48-
static llvm::RegisterStandardPasses RegisterBye(
49-
llvm::PassManagerBuilder::EP_VectorizerStart,
50-
[](const llvm::PassManagerBuilder &Builder,
51-
llvm::legacy::PassManagerBase &PM) { PM.add(new LegacyBye()); });
52-
53-
static llvm::RegisterStandardPasses RegisterByeLTO(
54-
llvm::PassManagerBuilder::EP_ModuleOptimizerEarly,
55-
[](const llvm::PassManagerBuilder &Builder,
56-
llvm::legacy::PassManagerBase &PM) { PM.add(new LegacyBye()); });
57-
5847
/* New PM Registration */
5948
llvm::PassPluginLibraryInfo getByePluginInfo() {
6049
return {LLVM_PLUGIN_API_VERSION, "Bye", LLVM_VERSION_STRING,

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

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -63,68 +63,6 @@ class PassManagerBuilder {
6363
ExtensionFn;
6464
typedef int GlobalExtensionID;
6565

66-
enum ExtensionPointTy {
67-
/// EP_EarlyAsPossible - This extension point allows adding passes before
68-
/// any other transformations, allowing them to see the code as it is coming
69-
/// out of the frontend.
70-
EP_EarlyAsPossible,
71-
72-
/// EP_ModuleOptimizerEarly - This extension point allows adding passes
73-
/// just before the main module-level optimization passes.
74-
EP_ModuleOptimizerEarly,
75-
76-
/// EP_LoopOptimizerEnd - This extension point allows adding loop passes to
77-
/// the end of the loop optimizer.
78-
EP_LoopOptimizerEnd,
79-
80-
/// EP_ScalarOptimizerLate - This extension point allows adding optimization
81-
/// passes after most of the main optimizations, but before the last
82-
/// cleanup-ish optimizations.
83-
EP_ScalarOptimizerLate,
84-
85-
/// EP_OptimizerLast -- This extension point allows adding passes that
86-
/// run after everything else.
87-
EP_OptimizerLast,
88-
89-
/// EP_VectorizerStart - This extension point allows adding optimization
90-
/// passes before the vectorizer and other highly target specific
91-
/// optimization passes are executed.
92-
EP_VectorizerStart,
93-
94-
/// EP_EnabledOnOptLevel0 - This extension point allows adding passes that
95-
/// should not be disabled by O0 optimization level. The passes will be
96-
/// inserted after the inlining pass.
97-
EP_EnabledOnOptLevel0,
98-
99-
/// EP_Peephole - This extension point allows adding passes that perform
100-
/// peephole optimizations similar to the instruction combiner. These passes
101-
/// will be inserted after each instance of the instruction combiner pass.
102-
EP_Peephole,
103-
104-
/// EP_LateLoopOptimizations - This extension point allows adding late loop
105-
/// canonicalization and simplification passes. This is the last point in
106-
/// the loop optimization pipeline before loop deletion. Each pass added
107-
/// here must be an instance of LoopPass.
108-
/// This is the place to add passes that can remove loops, such as target-
109-
/// specific loop idiom recognition.
110-
EP_LateLoopOptimizations,
111-
112-
/// EP_CGSCCOptimizerLate - This extension point allows adding CallGraphSCC
113-
/// passes at the end of the main CallGraphSCC passes and before any
114-
/// function simplification passes run by CGPassManager.
115-
EP_CGSCCOptimizerLate,
116-
117-
/// EP_FullLinkTimeOptimizationEarly - This extensions point allow adding
118-
/// passes that
119-
/// run at Link Time, before Full Link Time Optimization.
120-
EP_FullLinkTimeOptimizationEarly,
121-
122-
/// EP_FullLinkTimeOptimizationLast - This extensions point allow adding
123-
/// passes that
124-
/// run at Link Time, after Full Link Time Optimization.
125-
EP_FullLinkTimeOptimizationLast,
126-
};
127-
12866
/// The Optimization Level - Specify the basic optimization level.
12967
/// 0 = -O0, 1 = -O1, 2 = -O2, 3 = -O3
13068
unsigned OptLevel;
@@ -168,32 +106,11 @@ class PassManagerBuilder {
168106
unsigned LicmMssaOptCap;
169107
unsigned LicmMssaNoAccForPromotionCap;
170108

171-
private:
172-
/// ExtensionList - This is list of all of the extensions that are registered.
173-
std::vector<std::pair<ExtensionPointTy, ExtensionFn>> Extensions;
174-
175109
public:
176110
PassManagerBuilder();
177111
~PassManagerBuilder();
178-
/// Adds an extension that will be used by all PassManagerBuilder instances.
179-
/// This is intended to be used by plugins, to register a set of
180-
/// optimisations to run automatically.
181-
///
182-
/// \returns A global extension identifier that can be used to remove the
183-
/// extension.
184-
static GlobalExtensionID addGlobalExtension(ExtensionPointTy Ty,
185-
ExtensionFn Fn);
186-
/// Removes an extension that was previously added using addGlobalExtension.
187-
/// This is also intended to be used by plugins, to remove any extension that
188-
/// was previously registered before being unloaded.
189-
///
190-
/// \param ExtensionID Identifier of the extension to be removed.
191-
static void removeGlobalExtension(GlobalExtensionID ExtensionID);
192-
void addExtension(ExtensionPointTy Ty, ExtensionFn Fn);
193112

194113
private:
195-
void addExtensionsToPM(ExtensionPointTy ETy,
196-
legacy::PassManagerBase &PM) const;
197114
void addInitialAliasAnalysisPasses(legacy::PassManagerBase &PM) const;
198115
void addFunctionSimplificationPasses(legacy::PassManagerBase &MPM);
199116
void addVectorPasses(legacy::PassManagerBase &PM, bool IsFullLTO);
@@ -208,27 +125,6 @@ class PassManagerBuilder {
208125
void populateModulePassManager(legacy::PassManagerBase &MPM);
209126
};
210127

211-
/// Registers a function for adding a standard set of passes. This should be
212-
/// used by optimizer plugins to allow all front ends to transparently use
213-
/// them. Create a static instance of this class in your plugin, providing a
214-
/// private function that the PassManagerBuilder can use to add your passes.
215-
class RegisterStandardPasses {
216-
PassManagerBuilder::GlobalExtensionID ExtensionID;
217-
218-
public:
219-
RegisterStandardPasses(PassManagerBuilder::ExtensionPointTy Ty,
220-
PassManagerBuilder::ExtensionFn Fn) {
221-
ExtensionID = PassManagerBuilder::addGlobalExtension(Ty, std::move(Fn));
222-
}
223-
224-
~RegisterStandardPasses() {
225-
// If the collection holding the global extensions is destroyed after the
226-
// plugin is unloaded, the extension has to be removed here. Indeed, the
227-
// destructor of the ExtensionFn may reference code in the plugin.
228-
PassManagerBuilder::removeGlobalExtension(ExtensionID);
229-
}
230-
};
231-
232128
inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
233129
return reinterpret_cast<PassManagerBuilder*>(P);
234130
}

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -193,64 +193,6 @@ PassManagerBuilder::~PassManagerBuilder() {
193193
delete Inliner;
194194
}
195195

196-
/// Set of global extensions, automatically added as part of the standard set.
197-
static ManagedStatic<
198-
SmallVector<std::tuple<PassManagerBuilder::ExtensionPointTy,
199-
PassManagerBuilder::ExtensionFn,
200-
PassManagerBuilder::GlobalExtensionID>,
201-
8>>
202-
GlobalExtensions;
203-
static PassManagerBuilder::GlobalExtensionID GlobalExtensionsCounter;
204-
205-
/// Check if GlobalExtensions is constructed and not empty.
206-
/// Since GlobalExtensions is a managed static, calling 'empty()' will trigger
207-
/// the construction of the object.
208-
static bool GlobalExtensionsNotEmpty() {
209-
return GlobalExtensions.isConstructed() && !GlobalExtensions->empty();
210-
}
211-
212-
PassManagerBuilder::GlobalExtensionID
213-
PassManagerBuilder::addGlobalExtension(PassManagerBuilder::ExtensionPointTy Ty,
214-
PassManagerBuilder::ExtensionFn Fn) {
215-
auto ExtensionID = GlobalExtensionsCounter++;
216-
GlobalExtensions->push_back(std::make_tuple(Ty, std::move(Fn), ExtensionID));
217-
return ExtensionID;
218-
}
219-
220-
void PassManagerBuilder::removeGlobalExtension(
221-
PassManagerBuilder::GlobalExtensionID ExtensionID) {
222-
// RegisterStandardPasses may try to call this function after GlobalExtensions
223-
// has already been destroyed; doing so should not generate an error.
224-
if (!GlobalExtensions.isConstructed())
225-
return;
226-
227-
auto GlobalExtension =
228-
llvm::find_if(*GlobalExtensions, [ExtensionID](const auto &elem) {
229-
return std::get<2>(elem) == ExtensionID;
230-
});
231-
assert(GlobalExtension != GlobalExtensions->end() &&
232-
"The extension ID to be removed should always be valid.");
233-
234-
GlobalExtensions->erase(GlobalExtension);
235-
}
236-
237-
void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
238-
Extensions.push_back(std::make_pair(Ty, std::move(Fn)));
239-
}
240-
241-
void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
242-
legacy::PassManagerBase &PM) const {
243-
if (GlobalExtensionsNotEmpty()) {
244-
for (auto &Ext : *GlobalExtensions) {
245-
if (std::get<0>(Ext) == ETy)
246-
std::get<1>(Ext)(*this, PM);
247-
}
248-
}
249-
for (const auto &[PT, Fn] : Extensions)
250-
if (PT == ETy)
251-
Fn(*this, PM);
252-
}
253-
254196
void PassManagerBuilder::addInitialAliasAnalysisPasses(
255197
legacy::PassManagerBase &PM) const {
256198
switch (UseCFLAA) {
@@ -277,8 +219,6 @@ void PassManagerBuilder::addInitialAliasAnalysisPasses(
277219

278220
void PassManagerBuilder::populateFunctionPassManager(
279221
legacy::FunctionPassManager &FPM) {
280-
addExtensionsToPM(EP_EarlyAsPossible, FPM);
281-
282222
// Add LibraryInfo if we have some.
283223
if (LibraryInfo)
284224
FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
@@ -341,7 +281,6 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
341281
MPM.add(createInstructionCombiningPass());
342282
if (SizeLevel == 0 && !DisableLibCallsShrinkWrap)
343283
MPM.add(createLibCallsShrinkWrapPass());
344-
addExtensionsToPM(EP_Peephole, MPM);
345284

346285
// TODO: Investigate the cost/benefit of tail call elimination on debugging.
347286
if (OptLevel > 1)
@@ -391,7 +330,6 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
391330
}
392331
MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
393332
MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
394-
addExtensionsToPM(EP_LateLoopOptimizations, MPM);
395333
MPM.add(createLoopDeletionPass()); // Delete dead loops
396334

397335
if (EnableLoopInterchange)
@@ -400,7 +338,6 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
400338
// Unroll small loops and perform peeling.
401339
MPM.add(createSimpleLoopUnrollPass(OptLevel, DisableUnrollLoops,
402340
ForgetAllSCEVInLoopUnroll));
403-
addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
404341
// This ends the loop pass pipelines.
405342

406343
// Break up allocas that may now be splittable after loop unrolling.
@@ -424,7 +361,6 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
424361
// Run instcombine after redundancy elimination to exploit opportunities
425362
// opened up by them.
426363
MPM.add(createInstructionCombiningPass());
427-
addExtensionsToPM(EP_Peephole, MPM);
428364
if (OptLevel > 1) {
429365
if (EnableDFAJumpThreading && SizeLevel == 0)
430366
MPM.add(createDFAJumpThreadingPass());
@@ -442,8 +378,6 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
442378
/*AllowSpeculation=*/true));
443379
}
444380

445-
addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
446-
447381
if (RerollLoops)
448382
MPM.add(createLoopRerollPass());
449383

@@ -452,7 +386,6 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
452386
SimplifyCFGOptions().hoistCommonInsts(true).sinkCommonInsts(true)));
453387
// Clean up after everything.
454388
MPM.add(createInstructionCombiningPass());
455-
addExtensionsToPM(EP_Peephole, MPM);
456389
}
457390

458391
/// FIXME: Should LTO cause any differences to this set of passes?
@@ -536,7 +469,6 @@ void PassManagerBuilder::addVectorPasses(legacy::PassManagerBase &PM,
536469
PM.add(createVectorCombinePass());
537470

538471
if (!IsFullLTO) {
539-
addExtensionsToPM(EP_Peephole, PM);
540472
PM.add(createInstructionCombiningPass());
541473

542474
if (EnableUnrollAndJam && !DisableUnrollLoops) {
@@ -595,10 +527,6 @@ void PassManagerBuilder::populateModulePassManager(
595527
// builds. The function merging pass is
596528
if (MergeFunctions)
597529
MPM.add(createMergeFunctionsPass());
598-
else if (GlobalExtensionsNotEmpty() || !Extensions.empty())
599-
MPM.add(createBarrierNoopPass());
600-
601-
addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
602530

603531
MPM.add(createAnnotationRemarksLegacyPass());
604532
return;
@@ -617,8 +545,6 @@ void PassManagerBuilder::populateModulePassManager(
617545
if (AttributorRun & AttributorRunOption::MODULE)
618546
MPM.add(createAttributorLegacyPass());
619547

620-
addExtensionsToPM(EP_ModuleOptimizerEarly, MPM);
621-
622548
if (OptLevel > 2)
623549
MPM.add(createCallSiteSplittingPass());
624550

@@ -636,7 +562,6 @@ void PassManagerBuilder::populateModulePassManager(
636562
MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
637563

638564
MPM.add(createInstructionCombiningPass()); // Clean up after IPCP & DAE
639-
addExtensionsToPM(EP_Peephole, MPM);
640565
MPM.add(
641566
createCFGSimplificationPass(SimplifyCFGOptions().convertSwitchRangeToICmp(
642567
true))); // Clean up after IPCP & DAE
@@ -665,7 +590,6 @@ void PassManagerBuilder::populateModulePassManager(
665590

666591
MPM.add(createPostOrderFunctionAttrsLegacyPass());
667592

668-
addExtensionsToPM(EP_CGSCCOptimizerLate, MPM);
669593
addFunctionSimplificationPasses(MPM);
670594

671595
// FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
@@ -740,8 +664,6 @@ void PassManagerBuilder::populateModulePassManager(
740664
MPM.add(createEarlyCSEPass(false));
741665
}
742666

743-
addExtensionsToPM(EP_VectorizerStart, MPM);
744-
745667
// Re-rotate loops in all our loop nests. These may have fallout out of
746668
// rotated form due to GVN or other transformations, and the vectorizer relies
747669
// on the rotated form. Disable header duplication at -Oz.
@@ -794,8 +716,6 @@ void PassManagerBuilder::populateModulePassManager(
794716
MPM.add(createCFGSimplificationPass(
795717
SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
796718

797-
addExtensionsToPM(EP_OptimizerLast, MPM);
798-
799719
MPM.add(createAnnotationRemarksLegacyPass());
800720
}
801721

0 commit comments

Comments
 (0)