Index: include/llvm/IR/LLVMContext.h =================================================================== --- include/llvm/IR/LLVMContext.h +++ include/llvm/IR/LLVMContext.h @@ -318,6 +318,11 @@ /// \brief Access the object which manages optimization bisection for failure /// analysis. OptBisect &getOptBisect(); + + /// \brief Set the object which manages optimization bisection for failure + /// analysis. + void setOptBisect(OptBisect&); + private: // Module needs access to the add/removeModule methods. friend class Module; Index: include/llvm/IR/OptBisect.h =================================================================== --- include/llvm/IR/OptBisect.h +++ include/llvm/IR/OptBisect.h @@ -36,6 +36,8 @@ /// through LLVMContext. OptBisect(); + virtual ~OptBisect() = default; + /// Checks the bisect limit to determine if the specified pass should run. /// /// This function will immediate return true if bisection is disabled. If the @@ -51,8 +53,8 @@ template bool shouldRunPass(const Pass *P, const UnitT &U); -private: - bool checkPass(const StringRef PassName, const StringRef TargetDesc); +protected: + virtual bool checkPass(const StringRef PassName, const StringRef TargetDesc); bool BisectEnabled = false; unsigned LastBisectNum = 0; Index: lib/IR/LLVMContext.cpp =================================================================== --- lib/IR/LLVMContext.cpp +++ lib/IR/LLVMContext.cpp @@ -336,6 +336,10 @@ return pImpl->getOptBisect(); } +void LLVMContext::setOptBisect(OptBisect& OB) { + pImpl->setOptBisect(OB); +} + const DiagnosticHandler *LLVMContext::getDiagHandlerPtr() const { return pImpl->DiagHandler.get(); } Index: lib/IR/LLVMContextImpl.h =================================================================== --- lib/IR/LLVMContextImpl.h +++ lib/IR/LLVMContextImpl.h @@ -1355,9 +1355,15 @@ /// Destroy the ConstantArrays if they are not used. void dropTriviallyDeadConstantArrays(); + OptBisect *OptBisector = nullptr; + /// \brief Access the object which manages optimization bisection for failure /// analysis. OptBisect &getOptBisect(); + + /// \brief Set the object which manages optimization bisection for failure + /// analysis. + void setOptBisect(OptBisect&); }; } // end namespace llvm Index: lib/IR/LLVMContextImpl.cpp =================================================================== --- lib/IR/LLVMContextImpl.cpp +++ lib/IR/LLVMContextImpl.cpp @@ -234,5 +234,11 @@ static ManagedStatic OptBisector; OptBisect &LLVMContextImpl::getOptBisect() { + if (!OptBisector) + OptBisector = &(*::OptBisector); return *OptBisector; } + +void LLVMContextImpl::setOptBisect(OptBisect& OB) { + OptBisector = &OB; +}