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"
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) 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 ~OptBisect() override = default;
55
56 /// Checks the bisect intervals 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 no intervals are specified or the current pass number
61 /// falls within one of the specified intervals.
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().
67 StringRef IRDescription) const override;
68
69 /// isEnabled() should return true before calling shouldRunPass().
70 bool isEnabled() const override { return !BisectIntervals.empty(); }
71
72 /// Set intervals directly from an IntervalList.
74 BisectIntervals = std::move(Intervals);
75 }
76
77 /// Clear all intervals, effectively disabling bisection.
79 BisectIntervals.clear();
80 LastBisectNum = 0;
81 }
82
83private:
84 mutable int LastBisectNum = 0;
86};
87
88/// This class implements a mechanism to disable passes and individual
89/// optimizations at compile time based on a command line option
90/// (-opt-disable) in order to study how single transformations, or
91/// combinations thereof, affect the IR.
93public:
94 /// Checks the pass name to determine if the specified pass should run.
95 ///
96 /// It returns true if the pass should run, i.e. if its name is was
97 /// not provided via command line.
98 /// If -opt-disable-enable-verbosity is given, the method prints the
99 /// name of the pass, and whether or not the pass will be executed.
100 ///
101 /// Most passes should not call this routine directly. Instead, it is called
102 /// through helper routines provided by the base classes of the pass. For
103 /// instance, function passes should call FunctionPass::skipFunction().
105 StringRef IRDescription) const override;
106
107 /// Parses the command line argument to extract the names of the passes
108 /// to be disabled. Multiple pass names can be provided with comma separation.
110
111 /// isEnabled() should return true before calling shouldRunPass().
112 bool isEnabled() const override { return !DisabledPasses.empty(); }
113
114private:
115 StringSet<> DisabledPasses = {};
116};
117
118/// Singleton instance of the OptPassGate class, so multiple pass managers don't
119/// need to coordinate their uses of OptBisect and OptDisable.
121
122} // end namespace llvm
123
124#endif // LLVM_IR_OPTBISECT_H
#define LLVM_ABI
Definition Compiler.h:213
StringSet - A set-like wrapper for the StringMap.
static const char PassName[]
~OptBisect() override=default
void clearIntervals()
Clear all intervals, effectively disabling bisection.
Definition OptBisect.h:78
bool shouldRunPass(StringRef PassName, StringRef IRDescription) const override
Checks the bisect intervals to determine if the specified pass should run.
void setIntervals(IntegerInclusiveIntervalUtils::IntervalList Intervals)
Set intervals directly from an IntervalList.
Definition OptBisect.h:73
bool isEnabled() const override
isEnabled() should return true before calling shouldRunPass().
Definition OptBisect.h:70
OptBisect()=default
Default constructor.
This class implements a mechanism to disable passes and individual optimizations at compile time base...
Definition OptBisect.h:92
bool shouldRunPass(StringRef PassName, StringRef IRDescription) const override
Checks the pass name to determine if the specified pass should run.
bool isEnabled() const override
isEnabled() should return true before calling shouldRunPass().
Definition OptBisect.h:112
void setDisabled(StringRef Pass)
Parses the command line argument to extract the names of the passes to be disabled.
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
SmallVector< IntegerInclusiveInterval, 8 > IntervalList
A list of integer intervals.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
LLVM_ABI OptPassGate & getGlobalPassGate()
Singleton instance of the OptPassGate class, so multiple pass managers don't need to coordinate their...