LLVM 20.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
28static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden,
30 cl::cb<void, int>([](int Limit) {
31 getOptBisector().setLimit(Limit);
32 }),
33 cl::desc("Maximum optimization to perform"));
34
36 "opt-bisect-verbose",
37 cl::desc("Show verbose output when opt-bisect-limit is set"), cl::Hidden,
38 cl::init(true), cl::Optional);
39
40static void printPassMessage(const StringRef &Name, int PassNum,
41 StringRef TargetDesc, bool Running) {
42 StringRef Status = Running ? "" : "NOT ";
43 errs() << "BISECT: " << Status << "running pass "
44 << "(" << PassNum << ") " << Name << " on " << TargetDesc << "\n";
45}
46
48 StringRef IRDescription) {
50
51 int CurBisectNum = ++LastBisectNum;
52 bool ShouldRun = (BisectLimit == -1 || CurBisectNum <= BisectLimit);
54 printPassMessage(PassName, CurBisectNum, IRDescription, ShouldRun);
55 return ShouldRun;
56}
57
58const int OptBisect::Disabled;
59
std::string Name
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 void printPassMessage(const StringRef &Name, int PassNum, StringRef TargetDesc, bool Running)
Definition: OptBisect.cpp:40
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"))
This file declares the interface for bisecting optimizations.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const char PassName[]
This class implements a mechanism to disable passes and individual optimizations at compile time base...
Definition: OptBisect.h:43
bool shouldRunPass(const StringRef PassName, StringRef IRDescription) override
Checks the bisect limit to determine if the specified pass should run.
Definition: OptBisect.cpp:47
static const int Disabled
Definition: OptBisect.h:77
void setLimit(int Limit)
Set the new optimization limit and reset the counter.
Definition: OptBisect.h:72
bool isEnabled() const override
isEnabled() should return true before calling shouldRunPass().
Definition: OptBisect.h:68
Extensions to this class implement mechanisms to disable passes and individual optimizations at compi...
Definition: OptBisect.h:24
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OptPassGate & getGlobalPassGate()
Singleton instance of the OptBisect class, so multiple pass managers don't need to coordinate their u...
Definition: OptBisect.cpp:60
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.