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