LLVM 23.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.
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 /// Reset the pass gate to its initial configuration, before any command line
41 /// options were parsed.
42 virtual void reset() {}
43};
44
45/// This class implements a mechanism to disable passes and individual
46/// optimizations at compile time based on two command line options
47/// (-opt-bisect and -opt-disable) in order to perform a bisecting
48/// search for optimization-related problems, and/or disable individual
49/// passes or combinations thereof.
51public:
52 /// Default constructor. Initializes the state to "disabled". The bisection
53 /// will be enabled by the cl::opt call-back when the command line option
54 /// is processed.
55 /// Clients should not instantiate this class directly. All access should go
56 /// through LLVMContext.
57 OptBisect() = default;
58
59 ~OptBisect() override = default;
60
61 /// Checks the bisect intervals to determine if the specified pass should run.
62 ///
63 /// The method prints the name of the pass, its assigned bisect number, and
64 /// whether or not the pass will be executed. It returns true if the pass
65 /// should run, i.e. if no intervals are specified or the current pass number
66 /// falls within one of the specified intervals.
67 ///
68 /// Most passes should not call this routine directly. Instead, it is called
69 /// through helper routines provided by the base classes of the pass. For
70 /// instance, function passes should call FunctionPass::skipFunction().
72 StringRef IRDescription) const override;
73
74 /// isEnabled() should return true before calling shouldRunPass().
75 bool isEnabled() const override {
76 return !BisectIntervals.empty() || !DisabledPasses.empty();
77 }
78
79 void reset() override {
81 DisabledPasses.clear();
82 }
83
84 /// Set intervals directly from an IntervalList.
86 BisectIntervals = std::move(Intervals);
87 }
88
89 /// Clear all intervals, effectively disabling bisection.
91 BisectIntervals.clear();
92 LastBisectNum = 0;
93 }
94
95 /// Parses the command line argument to extract the names of the passes
96 /// to be disabled. Multiple pass names can be provided with comma separation.
97 void setDisabled(StringRef Pass) { DisabledPasses.insert(Pass); }
98
99private:
100 mutable int LastBisectNum = 0;
102
103 StringSet<> DisabledPasses = {};
104};
105
106/// Singleton instance of the OptPassGate class, so multiple pass managers don't
107/// need to coordinate their uses of OptBisect and OptDisable.
109
110} // end namespace llvm
111
112#endif // LLVM_IR_OPTBISECT_H
#define LLVM_ABI
Definition Compiler.h:213
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:97
~OptBisect() override=default
void clearIntervals()
Clear all intervals, effectively disabling bisection.
Definition OptBisect.h:90
bool shouldRunPass(StringRef PassName, StringRef IRDescription) const override
Checks the bisect intervals to determine if the specified pass should run.
Definition OptBisect.cpp:96
void setIntervals(IntegerInclusiveIntervalUtils::IntervalList Intervals)
Set intervals directly from an IntervalList.
Definition OptBisect.h:85
bool isEnabled() const override
isEnabled() should return true before calling shouldRunPass().
Definition OptBisect.h:75
void reset() override
Reset the pass gate to its initial configuration, before any command line options were parsed.
Definition OptBisect.h:79
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:38
virtual void reset()
Reset the pass gate to its initial configuration, before any command line options were parsed.
Definition OptBisect.h:42
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
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...