LLVM  16.0.0git
OptBisect.h
Go to the documentation of this file.
1 //===- llvm/IR/OptBisect.h - LLVM Bisect support ----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file declares the interface for bisecting optimizations.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IR_OPTBISECT_H
15 #define LLVM_IR_OPTBISECT_H
16 
17 #include "llvm/ADT/StringRef.h"
18 #include <limits>
19 
20 namespace llvm {
21 
22 class Pass;
23 
24 /// Extensions to this class implement mechanisms to disable passes and
25 /// individual optimizations at compile time.
26 class OptPassGate {
27 public:
28  virtual ~OptPassGate() = default;
29 
30  /// IRDescription is a textual description of the IR unit the pass is running
31  /// over.
32  virtual bool shouldRunPass(const StringRef PassName,
33  StringRef IRDescription) {
34  return true;
35  }
36 
37  /// isEnabled() should return true before calling shouldRunPass().
38  virtual bool isEnabled() const { return false; }
39 };
40 
41 /// This class implements a mechanism to disable passes and individual
42 /// optimizations at compile time based on a command line option
43 /// (-opt-bisect-limit) in order to perform a bisecting search for
44 /// optimization-related problems.
45 class OptBisect : public OptPassGate {
46 public:
47  /// Default constructor. Initializes the state to "disabled". The bisection
48  /// will be enabled by the cl::opt call-back when the command line option
49  /// is processed.
50  /// Clients should not instantiate this class directly. All access should go
51  /// through LLVMContext.
52  OptBisect() = default;
53 
54  virtual ~OptBisect() = default;
55 
56  /// Checks the bisect limit to determine if the specified pass should run.
57  ///
58  /// This forwards to checkPass().
59  bool shouldRunPass(const StringRef PassName,
60  StringRef IRDescription) override;
61 
62  /// isEnabled() should return true before calling shouldRunPass().
63  bool isEnabled() const override { return BisectLimit != Disabled; }
64 
65  /// Set the new optimization limit and reset the counter. Passing
66  /// OptBisect::Disabled disables the limiting.
67  void setLimit(int Limit) {
68  BisectLimit = Limit;
69  LastBisectNum = 0;
70  }
71 
72  /// Checks the bisect limit to determine if the specified pass should run.
73  ///
74  /// If the bisect limit is set to -1, the function prints a message describing
75  /// the pass and the bisect number assigned to it and return true. Otherwise,
76  /// the function prints a message with the bisect number assigned to the
77  /// pass and indicating whether or not the pass will be run and return true if
78  /// the bisect limit has not yet been exceeded or false if it has.
79  ///
80  /// Most passes should not call this routine directly. Instead, they are
81  /// called through helper routines provided by the pass base classes. For
82  /// instance, function passes should call FunctionPass::skipFunction().
83  bool checkPass(const StringRef PassName, const StringRef TargetDesc);
84 
86 
87 private:
88  int BisectLimit = Disabled;
89  int LastBisectNum = 0;
90 };
91 
92 /// Singleton instance of the OptBisect class, so multiple pass managers don't
93 /// need to coordinate their uses of OptBisect.
95 
96 } // end namespace llvm
97 
98 #endif // LLVM_IR_OPTBISECT_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Pass
print lazy value Lazy Value Info Printer Pass
Definition: LazyValueInfo.cpp:1999
StringRef.h
llvm::OptPassGate::isEnabled
virtual bool isEnabled() const
isEnabled() should return true before calling shouldRunPass().
Definition: OptBisect.h:38
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::OptBisect::OptBisect
OptBisect()=default
Default constructor.
llvm::OptBisect::Disabled
static const int Disabled
Definition: OptBisect.h:85
llvm::OptBisect
This class implements a mechanism to disable passes and individual optimizations at compile time base...
Definition: OptBisect.h:45
llvm::OptPassGate
Extensions to this class implement mechanisms to disable passes and individual optimizations at compi...
Definition: OptBisect.h:26
llvm::OptBisect::checkPass
bool checkPass(const StringRef PassName, const StringRef TargetDesc)
Checks the bisect limit to determine if the specified pass should run.
llvm::getGlobalPassGate
OptPassGate & getGlobalPassGate()
Singleton instance of the OptBisect class, so multiple pass managers don't need to coordinate their u...
Definition: OptBisect.cpp:54
llvm::OptPassGate::~OptPassGate
virtual ~OptPassGate()=default
llvm::OptPassGate::shouldRunPass
virtual bool shouldRunPass(const StringRef PassName, StringRef IRDescription)
IRDescription is a textual description of the IR unit the pass is running over.
Definition: OptBisect.h:32
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::OptBisect::~OptBisect
virtual ~OptBisect()=default
llvm::OptBisect::isEnabled
bool isEnabled() const override
isEnabled() should return true before calling shouldRunPass().
Definition: OptBisect.h:63
llvm::OptBisect::setLimit
void setLimit(int Limit)
Set the new optimization limit and reset the counter.
Definition: OptBisect.h:67
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:671
llvm::OptBisect::shouldRunPass
bool shouldRunPass(const StringRef PassName, StringRef IRDescription) override
Checks the bisect limit to determine if the specified pass should run.
Definition: OptBisect.cpp:42