LLVM 19.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
35static void printPassMessage(const StringRef &Name, int PassNum,
36 StringRef TargetDesc, bool Running) {
37 StringRef Status = Running ? "" : "NOT ";
38 errs() << "BISECT: " << Status << "running pass "
39 << "(" << PassNum << ") " << Name << " on " << TargetDesc << "\n";
40}
41
43 StringRef IRDescription) {
45
46 int CurBisectNum = ++LastBisectNum;
47 bool ShouldRun = (BisectLimit == -1 || CurBisectNum <= BisectLimit);
48 printPassMessage(PassName, CurBisectNum, IRDescription, ShouldRun);
49 return ShouldRun;
50}
51
52const int OptBisect::Disabled;
53
std::string Name
static void printPassMessage(const StringRef &Name, int PassNum, StringRef TargetDesc, bool Running)
Definition: OptBisect.cpp:35
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:42
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:50
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:450
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:54
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.