LLVM 24.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"
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. FuncName is the name of the function or the empty string if a module
32 /// level pass is being run.
33 virtual bool shouldRunPass(StringRef PassName, StringRef IRDescription,
34 StringRef FuncName) const {
35 return true;
36 }
37
38 /// isEnabled() should return true before calling shouldRunPass().
39 virtual bool isEnabled() const { return false; }
40
41 /// Reset the pass gate to its initial configuration, before any command line
42 /// options were parsed.
43 virtual void reset() {}
44};
45
46/// This class implements a mechanism to disable passes and individual
47/// optimizations at compile time based on two command line options
48/// (-opt-bisect and -opt-disable) in order to perform a bisecting
49/// search for optimization-related problems, and/or disable individual
50/// passes or combinations thereof.
52public:
53 /// Default constructor. Initializes the state to "disabled". The bisection
54 /// will be enabled by the cl::opt call-back when the command line option
55 /// is processed.
56 /// Clients should not instantiate this class directly. All access should go
57 /// through LLVMContext.
58 OptBisect() = default;
59
60 ~OptBisect() override = default;
61
62 /// Checks the bisect intervals to determine if the specified pass should run.
63 ///
64 /// The method prints the name of the pass, its assigned bisect number, and
65 /// whether or not the pass will be executed. It returns true if the pass
66 /// should run, i.e. if no intervals are specified or the current pass number
67 /// falls within one of the specified intervals.
68 ///
69 /// Most passes should not call this routine directly. Instead, it is called
70 /// through helper routines provided by the base classes of the pass. For
71 /// instance, function passes should call FunctionPass::skipFunction().
72 bool shouldRunPass(StringRef PassName, StringRef IRDescription,
73 StringRef FuncName) const override;
74
75 /// isEnabled() should return true before calling shouldRunPass().
76 bool isEnabled() const override {
77 return !BisectIntervals.empty() || !DisabledPasses.empty();
78 }
79
80 void reset() override {
82 DisabledPasses.clear();
84 }
85
86 /// Set intervals directly from an IntervalList.
88 BisectIntervals = std::move(Intervals);
89 }
90
91 /// Clear all intervals, effectively disabling bisection.
93 BisectIntervals.clear();
94 LastBisectNum = 0;
95 }
96
97 /// Parses the command line argument to extract the names of the passes
98 /// to be disabled. Multiple pass names can be provided with comma separation.
99 void setDisabled(StringRef Pass) { DisabledPasses.insert(Pass); }
100
101 /// Add a function name to the set of functions enabled for opt bisect.
102 void setEnabledFunc(StringRef FuncName) {
103 OptBisectFuncNames.insert(FuncName);
104 }
105
106 /// Clear the set of functions enabled for opt bisect, this reenables all
107 /// functions.
108 void clearEnabledFuncs() { OptBisectFuncNames.clear(); }
109
110private:
111 mutable int LastBisectNum = 0;
113
114 StringSet<> DisabledPasses = {};
115
116 StringSet<> OptBisectFuncNames = {};
117};
118
119/// Singleton instance of the OptPassGate class, so multiple pass managers don't
120/// need to coordinate their uses of OptBisect and OptDisable.
122
123} // end namespace llvm
124
125#endif // LLVM_IR_OPTBISECT_H
#define LLVM_ABI
Definition Compiler.h:211
StringSet - A set-like wrapper for the StringMap.
static const char PassName[]
void setDisabled(StringRef Pass)
Parses the command line argument to extract the names of the passes to be disabled.
Definition OptBisect.h:99
void setEnabledFunc(StringRef FuncName)
Add a function name to the set of functions enabled for opt bisect.
Definition OptBisect.h:102
void clearEnabledFuncs()
Clear the set of functions enabled for opt bisect, this reenables all functions.
Definition OptBisect.h:108
~OptBisect() override=default
bool shouldRunPass(StringRef PassName, StringRef IRDescription, StringRef FuncName) const override
Checks the bisect intervals to determine if the specified pass should run.
void clearIntervals()
Clear all intervals, effectively disabling bisection.
Definition OptBisect.h:92
void setIntervals(IntegerInclusiveIntervalUtils::IntervalList Intervals)
Set intervals directly from an IntervalList.
Definition OptBisect.h:87
bool isEnabled() const override
isEnabled() should return true before calling shouldRunPass().
Definition OptBisect.h:76
void reset() override
Reset the pass gate to its initial configuration, before any command line options were parsed.
Definition OptBisect.h:80
OptBisect()=default
Default constructor.
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:39
virtual void reset()
Reset the pass gate to its initial configuration, before any command line options were parsed.
Definition OptBisect.h:43
virtual bool shouldRunPass(StringRef PassName, StringRef IRDescription, StringRef FuncName) const
IRDescription is a textual description of the IR unit the pass is running over.
Definition OptBisect.h:33
virtual ~OptPassGate()=default
Pass interface - Implemented by all 'passes'.
Definition Pass.h:97
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition StringSet.h:25
SmallVector< IntegerInclusiveInterval, 8 > IntervalList
A list of integer intervals.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI OptPassGate & getGlobalPassGate()
Singleton instance of the OptPassGate class, so multiple pass managers don't need to coordinate their...