[llvm-objdump] - Import the test/Object/X86/no-start-symbol.test test case and rewrit...
[llvm-complete.git] / lib / IR / OptBisect.cpp
blob3104b90f30701b530d7ffa9842893977a8c06761
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.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/IR/OptBisect.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Pass.h"
18 #include "llvm/Support/CommandLine.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include <cassert>
21 #include <limits>
22 #include <string>
24 using namespace llvm;
26 static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden,
27 cl::init(std::numeric_limits<int>::max()),
28 cl::Optional,
29 cl::desc("Maximum optimization to perform"));
31 OptBisect::OptBisect() : OptPassGate() {
32 BisectEnabled = OptBisectLimit != std::numeric_limits<int>::max();
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";
42 bool OptBisect::shouldRunPass(const Pass *P, StringRef IRDescription) {
43 assert(BisectEnabled);
45 return checkPass(P->getPassName(), IRDescription);
48 bool OptBisect::checkPass(const StringRef PassName,
49 const StringRef TargetDesc) {
50 assert(BisectEnabled);
52 int CurBisectNum = ++LastBisectNum;
53 bool ShouldRun = (OptBisectLimit == -1 || CurBisectNum <= OptBisectLimit);
54 printPassMessage(PassName, CurBisectNum, TargetDesc, ShouldRun);
55 return ShouldRun;