LLVM  9.0.0svn
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/ADT/StringRef.h"
17 #include "llvm/Pass.h"
20 #include <cassert>
21 #include <limits>
22 #include <string>
23 
24 using namespace llvm;
25 
26 static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden,
29  cl::desc("Maximum optimization to perform"));
30 
32  BisectEnabled = OptBisectLimit != std::numeric_limits<int>::max();
33 }
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 
42 bool OptBisect::shouldRunPass(const Pass *P, StringRef IRDescription) {
43  assert(BisectEnabled);
44 
45  return checkPass(P->getPassName(), IRDescription);
46 }
47 
48 bool OptBisect::checkPass(const StringRef PassName,
49  const StringRef TargetDesc) {
50  assert(BisectEnabled);
51 
52  int CurBisectNum = ++LastBisectNum;
53  bool ShouldRun = (OptBisectLimit == -1 || CurBisectNum <= OptBisectLimit);
54  printPassMessage(PassName, CurBisectNum, TargetDesc, ShouldRun);
55  return ShouldRun;
56 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:80
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Extensions to this class implement mechanisms to disable passes and individual optimizations at compi...
Definition: OptBisect.h:25
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:79
static void printPassMessage(const StringRef &Name, int PassNum, StringRef TargetDesc, bool Running)
Definition: OptBisect.cpp:35
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:432
OptBisect()
Default constructor, initializes the OptBisect state based on the -opt-bisect-limit command line argu...
Definition: OptBisect.cpp:31
static cl::opt< int > OptBisectLimit("opt-bisect-limit", cl::Hidden, cl::init(std::numeric_limits< int >::max()), cl::Optional, cl::desc("Maximum optimization to perform"))
This file declares the interface for bisecting optimizations.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool shouldRunPass(const Pass *P, StringRef IRDescription) override
Checks the bisect limit to determine if the specified pass should run.
Definition: OptBisect.cpp:42
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48