LLVM  17.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 
21 using namespace llvm;
22 
24  static OptBisect OptBisector;
25  return OptBisector;
26 }
27 
28 static 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 
35 static 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) {
44  assert(isEnabled());
45 
46  int CurBisectNum = ++LastBisectNum;
47  bool ShouldRun = (BisectLimit == -1 || CurBisectNum <= BisectLimit);
48  printPassMessage(PassName, CurBisectNum, IRDescription, ShouldRun);
49  return ShouldRun;
50 }
51 
52 const int OptBisect::Disabled;
53 
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Pass.h
llvm::cl::cb
Definition: CommandLine.h:489
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:138
OptBisect.h
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:891
getOptBisector
static OptBisect & getOptBisector()
Definition: OptBisect.cpp:23
CommandLine.h
llvm::OptBisect::Disabled
static const int Disabled
Definition: OptBisect.h:85
llvm::OptBisect
This class implements a mechanism to disable passes and individual optimizations at compile time base...
Definition: OptBisect.h:45
llvm::OptPassGate
Extensions to this class implement mechanisms to disable passes and individual optimizations at compi...
Definition: OptBisect.h:26
llvm::getGlobalPassGate
OptPassGate & getGlobalPassGate()
Singleton instance of the OptBisect class, so multiple pass managers don't need to coordinate their u...
Definition: OptBisect.cpp:54
llvm::cl::opt
Definition: CommandLine.h:1410
OptBisectLimit
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"))
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:445
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Status
Definition: SIModeRegister.cpp:29
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
printPassMessage
static void printPassMessage(const StringRef &Name, int PassNum, StringRef TargetDesc, bool Running)
Definition: OptBisect.cpp:35
llvm::cl::Optional
@ Optional
Definition: CommandLine.h:114
llvm::OptBisect::isEnabled
bool isEnabled() const override
isEnabled() should return true before calling shouldRunPass().
Definition: OptBisect.h:63
llvm::cl::desc
Definition: CommandLine.h:411
raw_ostream.h
llvm::OptBisect::setLimit
void setLimit(int Limit)
Set the new optimization limit and reset the counter.
Definition: OptBisect.h:67
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:671
llvm::OptBisect::shouldRunPass
bool shouldRunPass(const StringRef PassName, StringRef IRDescription) override
Checks the bisect limit to determine if the specified pass should run.
Definition: OptBisect.cpp:42