LLVM 22.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 "llvm/ADT/StringSet.h"
20#include <limits>
21
22namespace llvm {
23
24/// Extensions to this class implement mechanisms to disable passes and
25/// individual optimizations at compile time.
27public:
28 virtual ~OptPassGate() = default;
29
30 /// IRDescription is a textual description of the IR unit the pass is running
31 /// over.
33 StringRef IRDescription) const {
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.
46public:
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 /// The method prints the name of the pass, its assigned bisect number, and
59 /// whether or not the pass will be executed. It returns true if the pass
60 /// should run, i.e. if the bisect limit is set to -1 or has not yet been
61 /// exceeded.
62 ///
63 /// Most passes should not call this routine directly. Instead, it is called
64 /// through helper routines provided by the base classes of the pass. For
65 /// instance, function passes should call FunctionPass::skipFunction().
66 bool shouldRunPass(StringRef PassName,
67 StringRef IRDescription) const override;
68
69 /// isEnabled() should return true before calling shouldRunPass().
70 bool isEnabled() const override { return BisectLimit != Disabled; }
71
72 /// Set the new optimization limit and reset the counter. Passing
73 /// OptBisect::Disabled disables the limiting.
74 void setLimit(int Limit) {
75 BisectLimit = Limit;
76 LastBisectNum = 0;
77 }
78
79 static constexpr int Disabled = std::numeric_limits<int>::max();
80
81private:
82 int BisectLimit = Disabled;
83 mutable int LastBisectNum = 0;
84};
85
86/// This class implements a mechanism to disable passes and individual
87/// optimizations at compile time based on a command line option
88/// (-opt-disable) in order to study how single transformations, or
89/// combinations thereof, affect the IR.
91public:
92 /// Checks the pass name to determine if the specified pass should run.
93 ///
94 /// It returns true if the pass should run, i.e. if its name is was
95 /// not provided via command line.
96 /// If -opt-disable-enable-verbosity is given, the method prints the
97 /// name of the pass, and whether or not the pass will be executed.
98 ///
99 /// Most passes should not call this routine directly. Instead, it is called
100 /// through helper routines provided by the base classes of the pass. For
101 /// instance, function passes should call FunctionPass::skipFunction().
102 bool shouldRunPass(StringRef PassName,
103 StringRef IRDescription) const override;
104
105 /// Parses the command line argument to extract the names of the passes
106 /// to be disabled. Multiple pass names can be provided with comma separation.
107 void setDisabled(StringRef Pass);
108
109 /// isEnabled() should return true before calling shouldRunPass().
110 bool isEnabled() const override { return !DisabledPasses.empty(); }
111
112private:
113 StringSet<> DisabledPasses = {};
114};
115
116/// Singleton instance of the OptPassGate class, so multiple pass managers don't
117/// need to coordinate their uses of OptBisect and OptDisable.
118LLVM_ABI OptPassGate &getGlobalPassGate();
119
120} // end namespace llvm
121
122#endif // LLVM_IR_OPTBISECT_H
#define LLVM_ABI
Definition: Compiler.h:213
StringSet - A set-like wrapper for the StringMap.
static const char PassName[]
This class implements a mechanism to disable passes and individual optimizations at compile time base...
Definition: OptBisect.h:45
void setLimit(int Limit)
Set the new optimization limit and reset the counter.
Definition: OptBisect.h:74
bool isEnabled() const override
isEnabled() should return true before calling shouldRunPass().
Definition: OptBisect.h:70
virtual ~OptBisect()=default
OptBisect()=default
Default constructor.
This class implements a mechanism to disable passes and individual optimizations at compile time base...
Definition: OptBisect.h:90
bool isEnabled() const override
isEnabled() should return true before calling shouldRunPass().
Definition: OptBisect.h:110
Extensions to this class implement mechanisms to disable passes and individual optimizations at compi...
Definition: OptBisect.h:26
virtual bool isEnabled() const
isEnabled() should return true before calling shouldRunPass().
Definition: OptBisect.h:38
virtual bool shouldRunPass(StringRef PassName, StringRef IRDescription) const
IRDescription is a textual description of the IR unit the pass is running over.
Definition: OptBisect.h:32
virtual ~OptPassGate()=default
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:99
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:25
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI OptPassGate & getGlobalPassGate()
Singleton instance of the OptPassGate class, so multiple pass managers don't need to coordinate their...
Definition: OptBisect.cpp:94