LLVM  14.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"
19 #include <limits>
20 
21 namespace llvm {
22 
23 class Pass;
24 
25 /// Extensions to this class implement mechanisms to disable passes and
26 /// individual optimizations at compile time.
27 class OptPassGate {
28 public:
29  virtual ~OptPassGate() = default;
30 
31  /// IRDescription is a textual description of the IR unit the pass is running
32  /// over.
33  virtual bool shouldRunPass(const Pass *P, 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 Pass *P, StringRef IRDescription) override;
60 
61  /// isEnabled() should return true before calling shouldRunPass().
62  bool isEnabled() const override { return BisectLimit != Disabled; }
63 
64  /// Set the new optimization limit and reset the counter. Passing
65  /// OptBisect::Disabled disables the limiting.
66  void setLimit(int Limit) {
67  BisectLimit = Limit;
68  LastBisectNum = 0;
69  }
70 
71  /// Checks the bisect limit to determine if the specified pass should run.
72  ///
73  /// If the bisect limit is set to -1, the function prints a message describing
74  /// the pass and the bisect number assigned to it and return true. Otherwise,
75  /// the function prints a message with the bisect number assigned to the
76  /// pass and indicating whether or not the pass will be run and return true if
77  /// the bisect limit has not yet been exceeded or false if it has.
78  ///
79  /// Most passes should not call this routine directly. Instead, they are
80  /// called through helper routines provided by the pass base classes. For
81  /// instance, function passes should call FunctionPass::skipFunction().
82  bool checkPass(const StringRef PassName, const StringRef TargetDesc);
83 
85 
86 private:
87  int BisectLimit = Disabled;
88  int LastBisectNum = 0;
89 };
90 
91 /// Singleton instance of the OptBisect class, so multiple pass managers don't
92 /// need to coordinate their uses of OptBisect.
94 } // end namespace llvm
95 
96 #endif // LLVM_IR_OPTBISECT_H
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
Pass
print lazy value Lazy Value Info Printer Pass
Definition: LazyValueInfo.cpp:1965
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
ManagedStatic.h
llvm::OptPassGate::isEnabled
virtual bool isEnabled() const
isEnabled() should return true before calling shouldRunPass().
Definition: OptBisect.h:38
llvm::OptBisect::OptBisect
OptBisect()=default
Default constructor.
llvm::OptBisect::Disabled
static const int Disabled
Definition: OptBisect.h:84
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:27
llvm::ManagedStatic
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
llvm::OptBisect::shouldRunPass
bool shouldRunPass(const Pass *P, StringRef IRDescription) override
Checks the bisect limit to determine if the specified pass should run.
Definition: OptBisect.cpp:38
llvm::OptBisect::checkPass
bool checkPass(const StringRef PassName, const StringRef TargetDesc)
Checks the bisect limit to determine if the specified pass should run.
Definition: OptBisect.cpp:44
llvm::OptPassGate::~OptPassGate
virtual ~OptPassGate()=default
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::OptBisector
ManagedStatic< OptBisect > OptBisector
Singleton instance of the OptBisect class, so multiple pass managers don't need to coordinate their u...
Definition: OptBisect.cpp:56
llvm::OptBisect::~OptBisect
virtual ~OptBisect()=default
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::OptBisect::isEnabled
bool isEnabled() const override
isEnabled() should return true before calling shouldRunPass().
Definition: OptBisect.h:62
llvm::OptPassGate::shouldRunPass
virtual bool shouldRunPass(const Pass *P, StringRef IRDescription)
IRDescription is a textual description of the IR unit the pass is running over.
Definition: OptBisect.h:33
llvm::OptBisect::setLimit
void setLimit(int Limit)
Set the new optimization limit and reset the counter.
Definition: OptBisect.h:66
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:669