LLVM 22.0.0git
OptBisect.cpp
Go to the documentation of this file.
1//===- llvm/IR/OptBisect/Bisect.cpp - LLVM Bisect support -----------------===//
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 implements support for a bisecting optimizations based on a
11/// command line option.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/IR/OptBisect.h"
16#include "llvm/Pass.h"
19#include <cassert>
20
21using namespace llvm;
22
24 static OptBisect OptBisector;
25 return OptBisector;
26}
27
29 static OptDisable OptDisabler;
30 return OptDisabler;
31}
32
33static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden,
35 cl::cb<void, int>([](int Limit) {
36 getOptBisector().setLimit(Limit);
37 }),
38 cl::desc("Maximum optimization to perform"));
39
41 "opt-bisect-verbose",
42 cl::desc("Show verbose output when opt-bisect-limit is set"), cl::Hidden,
43 cl::init(true), cl::Optional);
44
47 cl::cb<void, std::string>([](const std::string &Pass) {
49 }),
50 cl::desc("Optimization pass(es) to disable (comma-separated list)"));
51
52static cl::opt<bool>
53 OptDisableVerbose("opt-disable-enable-verbosity",
54 cl::desc("Show verbose output when opt-disable is set"),
56
57static void printPassMessage(StringRef Name, int PassNum, StringRef TargetDesc,
58 bool Running) {
59 StringRef Status = Running ? "" : "NOT ";
60 errs() << "BISECT: " << Status << "running pass (" << PassNum << ") " << Name
61 << " on " << TargetDesc << '\n';
62}
63
65 StringRef IRDescription) const {
67
68 int CurBisectNum = ++LastBisectNum;
69 bool ShouldRun = (BisectLimit == -1 || CurBisectNum <= BisectLimit);
71 printPassMessage(PassName, CurBisectNum, IRDescription, ShouldRun);
72 return ShouldRun;
73}
74
75static void printDisablePassMessage(const StringRef &Name, StringRef TargetDesc,
76 bool Running) {
77 StringRef Status = Running ? "" : "NOT ";
78 dbgs() << "OptDisable: " << Status << "running pass " << Name << " on "
79 << TargetDesc << "\n";
80}
81
83
85 StringRef IRDescription) const {
87
88 const bool ShouldRun = !DisabledPasses.contains(PassName);
90 printDisablePassMessage(PassName, IRDescription, ShouldRun);
91 return ShouldRun;
92}
93
95 if (getOptDisabler().isEnabled())
96 return getOptDisabler();
97 return getOptBisector();
98}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
std::string Name
static void printPassMessage(StringRef Name, int PassNum, StringRef TargetDesc, bool Running)
Definition: OptBisect.cpp:57
static cl::opt< bool > OptBisectVerbose("opt-bisect-verbose", cl::desc("Show verbose output when opt-bisect-limit is set"), cl::Hidden, cl::init(true), cl::Optional)
static cl::opt< bool > OptDisableVerbose("opt-disable-enable-verbosity", cl::desc("Show verbose output when opt-disable is set"), cl::Hidden, cl::init(false), cl::Optional)
static void printDisablePassMessage(const StringRef &Name, StringRef TargetDesc, bool Running)
Definition: OptBisect.cpp:75
static OptBisect & getOptBisector()
Definition: OptBisect.cpp:23
static cl::opt< int > OptBisectLimit("opt-bisect-limit", cl::Hidden, cl::init(OptBisect::Disabled), cl::Optional, cl::cb< void, int >([](int Limit) { getOptBisector().setLimit(Limit);}), cl::desc("Maximum optimization to perform"))
static OptDisable & getOptDisabler()
Definition: OptBisect.cpp:28
static cl::list< std::string > OptDisablePasses("opt-disable", cl::Hidden, cl::CommaSeparated, cl::Optional, cl::cb< void, std::string >([](const std::string &Pass) { getOptDisabler().setDisabled(Pass);}), cl::desc("Optimization pass(es) to disable (comma-separated list)"))
This file declares the interface for bisecting optimizations.
static const char PassName[]
This class implements a mechanism to disable passes and individual optimizations at compile time base...
Definition: OptBisect.h:45
static constexpr int Disabled
Definition: OptBisect.h:79
void setLimit(int Limit)
Set the new optimization limit and reset the counter.
Definition: OptBisect.h:74
bool shouldRunPass(StringRef PassName, StringRef IRDescription) const override
Checks the bisect limit to determine if the specified pass should run.
Definition: OptBisect.cpp:64
bool isEnabled() const override
isEnabled() should return true before calling shouldRunPass().
Definition: OptBisect.h:70
This class implements a mechanism to disable passes and individual optimizations at compile time base...
Definition: OptBisect.h:90
bool shouldRunPass(StringRef PassName, StringRef IRDescription) const override
Checks the pass name to determine if the specified pass should run.
Definition: OptBisect.cpp:84
bool isEnabled() const override
isEnabled() should return true before calling shouldRunPass().
Definition: OptBisect.h:110
void setDisabled(StringRef Pass)
Parses the command line argument to extract the names of the passes to be disabled.
Definition: OptBisect.cpp:82
Extensions to this class implement mechanisms to disable passes and individual optimizations at compi...
Definition: OptBisect.h:26
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:99
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
bool contains(StringRef key) const
Check if the set contains the given key.
Definition: StringSet.h:60
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition: StringSet.h:39
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:444
@ CommaSeparated
Definition: CommandLine.h:164
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
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:207
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.