From f7732c65f020e54a8bd86b84ca110142e5998ff3 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Fri, 18 Jun 2021 13:16:45 -0500 Subject: [PATCH] Revert "Delay initialization of OptBisect" This reverts commit ec91df8d8195b8b759a89734dba227da1eaa729f. It was committed by accident. --- include/llvm/IR/OptBisect.h | 23 +++++++++-------------- lib/IR/OptBisect.cpp | 16 +++++++++------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/include/llvm/IR/OptBisect.h b/include/llvm/IR/OptBisect.h index ada28a05f5d..6c2a1b01d89 100644 --- a/include/llvm/IR/OptBisect.h +++ b/include/llvm/IR/OptBisect.h @@ -16,7 +16,6 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/ManagedStatic.h" -#include namespace llvm { @@ -44,12 +43,14 @@ public: /// optimization-related problems. class OptBisect : public OptPassGate { public: - /// Default constructor. Initializes the state to "disabled". The bisection - /// will be enabled by the cl::opt call-back when the command line option - /// is processed. + /// Default constructor, initializes the OptBisect state based on the + /// -opt-bisect-limit command line argument. + /// + /// By default, bisection is disabled. + /// /// Clients should not instantiate this class directly. All access should go /// through LLVMContext. - OptBisect() = default; + OptBisect(); virtual ~OptBisect() = default; @@ -59,11 +60,7 @@ public: bool shouldRunPass(const Pass *P, StringRef IRDescription) override; /// isEnabled() should return true before calling shouldRunPass(). - bool isEnabled() const override { return BisectLimit != Disabled; } - - /// Set the new optimization limit. Passing OptBisect::Disabled disables - /// the limiting. - void setLimit(int Limit) { BisectLimit = Limit; } + bool isEnabled() const override { return BisectEnabled; } /// Checks the bisect limit to determine if the specified pass should run. /// @@ -78,11 +75,9 @@ public: /// instance, function passes should call FunctionPass::skipFunction(). bool checkPass(const StringRef PassName, const StringRef TargetDesc); - static const int Disabled = std::numeric_limits::max(); - private: - int BisectLimit = Disabled; - int LastBisectNum = 0; + bool BisectEnabled = false; + unsigned LastBisectNum = 0; }; /// Singleton instance of the OptBisect class, so multiple pass managers don't diff --git a/lib/IR/OptBisect.cpp b/lib/IR/OptBisect.cpp index 923be3efd85..2cf2298e000 100644 --- a/lib/IR/OptBisect.cpp +++ b/lib/IR/OptBisect.cpp @@ -22,12 +22,14 @@ using namespace llvm; static cl::opt OptBisectLimit("opt-bisect-limit", cl::Hidden, - cl::init(OptBisect::Disabled), cl::Optional, - cl::cb([](int Limit) { - llvm::OptBisector->setLimit(Limit); - }), + cl::init(std::numeric_limits::max()), + cl::Optional, cl::desc("Maximum optimization to perform")); +OptBisect::OptBisect() : OptPassGate() { + BisectEnabled = OptBisectLimit != std::numeric_limits::max(); +} + static void printPassMessage(const StringRef &Name, int PassNum, StringRef TargetDesc, bool Running) { StringRef Status = Running ? "" : "NOT "; @@ -36,17 +38,17 @@ static void printPassMessage(const StringRef &Name, int PassNum, } bool OptBisect::shouldRunPass(const Pass *P, StringRef IRDescription) { - assert(isEnabled()); + assert(BisectEnabled); return checkPass(P->getPassName(), IRDescription); } bool OptBisect::checkPass(const StringRef PassName, const StringRef TargetDesc) { - assert(isEnabled()); + assert(BisectEnabled); int CurBisectNum = ++LastBisectNum; - bool ShouldRun = (BisectLimit == -1 || CurBisectNum <= BisectLimit); + bool ShouldRun = (OptBisectLimit == -1 || CurBisectNum <= OptBisectLimit); printPassMessage(PassName, CurBisectNum, TargetDesc, ShouldRun); return ShouldRun; }