Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:08

0001 //===- llvm/IR/OptBisect.h - LLVM Bisect support ----------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// \file
0010 /// This file declares the interface for bisecting optimizations.
0011 ///
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_IR_OPTBISECT_H
0015 #define LLVM_IR_OPTBISECT_H
0016 
0017 #include "llvm/ADT/StringRef.h"
0018 #include <limits>
0019 
0020 namespace llvm {
0021 
0022 /// Extensions to this class implement mechanisms to disable passes and
0023 /// individual optimizations at compile time.
0024 class OptPassGate {
0025 public:
0026   virtual ~OptPassGate() = default;
0027 
0028   /// IRDescription is a textual description of the IR unit the pass is running
0029   /// over.
0030   virtual bool shouldRunPass(const StringRef PassName,
0031                              StringRef IRDescription) {
0032     return true;
0033   }
0034 
0035   /// isEnabled() should return true before calling shouldRunPass().
0036   virtual bool isEnabled() const { return false; }
0037 };
0038 
0039 /// This class implements a mechanism to disable passes and individual
0040 /// optimizations at compile time based on a command line option
0041 /// (-opt-bisect-limit) in order to perform a bisecting search for
0042 /// optimization-related problems.
0043 class OptBisect : public OptPassGate {
0044 public:
0045   /// Default constructor. Initializes the state to "disabled". The bisection
0046   /// will be enabled by the cl::opt call-back when the command line option
0047   /// is processed.
0048   /// Clients should not instantiate this class directly.  All access should go
0049   /// through LLVMContext.
0050   OptBisect() = default;
0051 
0052   virtual ~OptBisect() = default;
0053 
0054   /// Checks the bisect limit to determine if the specified pass should run.
0055   ///
0056   /// The method prints the name of the pass, its assigned bisect number, and
0057   /// whether or not the pass will be executed. It returns true if the pass
0058   /// should run, i.e. if the bisect limit is set to -1 or has not yet been
0059   /// exceeded.
0060   ///
0061   /// Most passes should not call this routine directly. Instead, it is called
0062   /// through helper routines provided by the base classes of the pass. For
0063   /// instance, function passes should call FunctionPass::skipFunction().
0064   bool shouldRunPass(const StringRef PassName,
0065                      StringRef IRDescription) override;
0066 
0067   /// isEnabled() should return true before calling shouldRunPass().
0068   bool isEnabled() const override { return BisectLimit != Disabled; }
0069 
0070   /// Set the new optimization limit and reset the counter. Passing
0071   /// OptBisect::Disabled disables the limiting.
0072   void setLimit(int Limit) {
0073     BisectLimit = Limit;
0074     LastBisectNum = 0;
0075   }
0076 
0077   static const int Disabled = std::numeric_limits<int>::max();
0078 
0079 private:
0080   int BisectLimit = Disabled;
0081   int LastBisectNum = 0;
0082 };
0083 
0084 /// Singleton instance of the OptBisect class, so multiple pass managers don't
0085 /// need to coordinate their uses of OptBisect.
0086 OptPassGate &getGlobalPassGate();
0087 
0088 } // end namespace llvm
0089 
0090 #endif // LLVM_IR_OPTBISECT_H