llvm.org GIT mirror llvm / 558f76f
[NFC] OptPassGate extracted from OptBisect Summary: This is an NFC refactoring of the OptBisect class to split it into an optional pass gate interface used by LLVMContext and the Optional Pass Bisector (OptBisect) used for debugging of optional passes. This refactoring is needed for D44464, which introduces setOptPassGate() method to allow implementations other than OptBisect. Patch by Yevgeny Rouban. Reviewers: andrew.w.kaylor, fedor.sergeev, vsk, dberlin, Eugene.Zelenko, reames, skatkov Reviewed By: fedor.sergeev Differential Revision: https://reviews.llvm.org/D44821 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328637 91177308-0d34-0410-b5e6-96231b3b80d8 Fedor Sergeev 2 years ago
10 changed file(s) with 73 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
3030 class Instruction;
3131 class LLVMContextImpl;
3232 class Module;
33 class OptBisect;
33 class OptPassGate;
3434 template class SmallVectorImpl;
3535 class SMDiagnostic;
3636 class StringRef;
316316
317317 /// \brief Access the object which manages optimization bisection for failure
318318 /// analysis.
319 OptBisect &getOptBisect();
319 OptPassGate &getOptPassGate();
320
320321 private:
321322 // Module needs access to the add/removeModule methods.
322323 friend class Module;
1919 namespace llvm {
2020
2121 class Pass;
22 class Module;
23 class Function;
24 class BasicBlock;
25 class Region;
26 class Loop;
27 class CallGraphSCC;
28
29 /// Extensions to this class implement mechanisms to disable passes and
30 /// individual optimizations at compile time.
31 class OptPassGate {
32 public:
33 virtual ~OptPassGate() = default;
34
35 virtual bool shouldRunPass(const Pass *P, const Module &U) { return true; }
36 virtual bool shouldRunPass(const Pass *P, const Function &U) {return true; }
37 virtual bool shouldRunPass(const Pass *P, const BasicBlock &U) { return true; }
38 virtual bool shouldRunPass(const Pass *P, const Region &U) { return true; }
39 virtual bool shouldRunPass(const Pass *P, const Loop &U) { return true; }
40 virtual bool shouldRunPass(const Pass *P, const CallGraphSCC &U) { return true; }
41 };
2242
2343 /// This class implements a mechanism to disable passes and individual
2444 /// optimizations at compile time based on a command line option
2545 /// (-opt-bisect-limit) in order to perform a bisecting search for
2646 /// optimization-related problems.
27 class OptBisect {
47 class OptBisect : public OptPassGate {
2848 public:
2949 /// \brief Default constructor, initializes the OptBisect state based on the
3050 /// -opt-bisect-limit command line argument.
3555 /// through LLVMContext.
3656 OptBisect();
3757
58 virtual ~OptBisect() = default;
59
3860 /// Checks the bisect limit to determine if the specified pass should run.
3961 ///
40 /// This function will immediate return true if bisection is disabled. If the
41 /// bisect limit is set to -1, the function will print a message describing
62 /// These functions immediately return true if bisection is disabled. If the
63 /// bisect limit is set to -1, the functions print a message describing
4264 /// the pass and the bisect number assigned to it and return true. Otherwise,
43 /// the function will print a message with the bisect number assigned to the
65 /// the functions print a message with the bisect number assigned to the
4466 /// pass and indicating whether or not the pass will be run and return true if
45 /// the bisect limit has not yet been exceded or false if it has.
67 /// the bisect limit has not yet been exceeded or false if it has.
4668 ///
47 /// Most passes should not call this routine directly. Instead, it is called
48 /// through a helper routine provided by the pass base class. For instance,
49 /// function passes should call FunctionPass::skipFunction().
50 template
51 bool shouldRunPass(const Pass *P, const UnitT &U);
69 /// Most passes should not call these routines directly. Instead, they are
70 /// called through helper routines provided by the pass base classes. For
71 /// instance, function passes should call FunctionPass::skipFunction().
72 bool shouldRunPass(const Pass *P, const Module &U) override;
73 bool shouldRunPass(const Pass *P, const Function &U) override;
74 bool shouldRunPass(const Pass *P, const BasicBlock &U) override;
75 bool shouldRunPass(const Pass *P, const Region &U) override;
76 bool shouldRunPass(const Pass *P, const Loop &U) override;
77 bool shouldRunPass(const Pass *P, const CallGraphSCC &U) override;
5278
5379 private:
5480 bool checkPass(const StringRef PassName, const StringRef TargetDesc);
647647 bool CallGraphSCCPass::skipSCC(CallGraphSCC &SCC) const {
648648 return !SCC.getCallGraph().getModule()
649649 .getContext()
650 .getOptBisect()
650 .getOptPassGate()
651651 .shouldRunPass(this, SCC);
652652 }
653653
356356 return false;
357357 // Check the opt bisect limit.
358358 LLVMContext &Context = F->getContext();
359 if (!Context.getOptBisect().shouldRunPass(this, *L))
359 if (!Context.getOptPassGate().shouldRunPass(this, *L))
360360 return true;
361361 // Check for the OptimizeNone attribute.
362362 if (F->hasFnAttribute(Attribute::OptimizeNone)) {
282282
283283 bool RegionPass::skipRegion(Region &R) const {
284284 Function &F = *R.getEntry()->getParent();
285 if (!F.getContext().getOptBisect().shouldRunPass(this, R))
285 if (!F.getContext().getOptPassGate().shouldRunPass(this, R))
286286 return true;
287287
288288 if (F.hasFnAttribute(Attribute::OptimizeNone)) {
331331 pImpl->DiscardValueNames = Discard;
332332 }
333333
334 OptBisect &LLVMContext::getOptBisect() {
335 return pImpl->getOptBisect();
334 OptPassGate &LLVMContext::getOptPassGate() {
335 return pImpl->getOptPassGate();
336336 }
337337
338338 const DiagnosticHandler *LLVMContext::getDiagHandlerPtr() const {
221221
222222 /// Singleton instance of the OptBisect class.
223223 ///
224 /// This singleton is accessed via the LLVMContext::getOptBisect() function. It
225 /// provides a mechanism to disable passes and individual optimizations at
224 /// This singleton is accessed via the LLVMContext::getOptPassGate() function.
225 /// It provides a mechanism to disable passes and individual optimizations at
226226 /// compile time based on a command line option (-opt-bisect-limit) in order to
227227 /// perform a bisecting search for optimization-related problems.
228228 ///
232232 /// enabled in order to enable a consistent bisect count.
233233 static ManagedStatic OptBisector;
234234
235 OptBisect &LLVMContextImpl::getOptBisect() {
235 OptPassGate &LLVMContextImpl::getOptPassGate() {
236236 return *OptBisector;
237237 }
13561356
13571357 /// \brief Access the object which manages optimization bisection for failure
13581358 /// analysis.
1359 OptBisect &getOptBisect();
1359 OptPassGate &getOptPassGate();
13601360 };
13611361
13621362 } // end namespace llvm
3535 cl::Optional,
3636 cl::desc("Maximum optimization to perform"));
3737
38 OptBisect::OptBisect() {
38 OptBisect::OptBisect() : OptPassGate() {
3939 BisectEnabled = OptBisectLimit != std::numeric_limits::max();
4040 }
4141
9191 return Desc;
9292 }
9393
94 // Force instantiations.
95 template bool OptBisect::shouldRunPass(const Pass *, const Module &);
96 template bool OptBisect::shouldRunPass(const Pass *, const Function &);
97 template bool OptBisect::shouldRunPass(const Pass *, const BasicBlock &);
98 template bool OptBisect::shouldRunPass(const Pass *, const Loop &);
99 template bool OptBisect::shouldRunPass(const Pass *, const CallGraphSCC &);
100 template bool OptBisect::shouldRunPass(const Pass *, const Region &);
94 bool OptBisect::shouldRunPass(const Pass *P, const Module &U) {
95 return !BisectEnabled || checkPass(P->getPassName(), getDescription(U));
96 }
10197
102 template
103 bool OptBisect::shouldRunPass(const Pass *P, const UnitT &U) {
104 if (!BisectEnabled)
105 return true;
106 return checkPass(P->getPassName(), getDescription(U));
98 bool OptBisect::shouldRunPass(const Pass *P, const Function &U) {
99 return !BisectEnabled || checkPass(P->getPassName(), getDescription(U));
100 }
101
102 bool OptBisect::shouldRunPass(const Pass *P, const BasicBlock &U) {
103 return !BisectEnabled || checkPass(P->getPassName(), getDescription(U));
104 }
105
106 bool OptBisect::shouldRunPass(const Pass *P, const Region &U) {
107 return !BisectEnabled || checkPass(P->getPassName(), getDescription(U));
108 }
109
110 bool OptBisect::shouldRunPass(const Pass *P, const Loop &U) {
111 return !BisectEnabled || checkPass(P->getPassName(), getDescription(U));
112 }
113
114 bool OptBisect::shouldRunPass(const Pass *P, const CallGraphSCC &U) {
115 return !BisectEnabled || checkPass(P->getPassName(), getDescription(U));
107116 }
108117
109118 bool OptBisect::checkPass(const StringRef PassName,
5555 }
5656
5757 bool ModulePass::skipModule(Module &M) const {
58 return !M.getContext().getOptBisect().shouldRunPass(this, M);
58 return !M.getContext().getOptPassGate().shouldRunPass(this, M);
5959 }
6060
6161 bool Pass::mustPreserveAnalysisID(char &AID) const {
154154 }
155155
156156 bool FunctionPass::skipFunction(const Function &F) const {
157 if (!F.getContext().getOptBisect().shouldRunPass(this, F))
157 if (!F.getContext().getOptPassGate().shouldRunPass(this, F))
158158 return true;
159159
160160 if (F.hasFnAttribute(Attribute::OptimizeNone)) {
188188 const Function *F = BB.getParent();
189189 if (!F)
190190 return false;
191 if (!F->getContext().getOptBisect().shouldRunPass(this, BB))
191 if (!F->getContext().getOptPassGate().shouldRunPass(this, BB))
192192 return true;
193193 if (F->hasFnAttribute(Attribute::OptimizeNone)) {
194194 // Report this only once per function.