[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / IR / OptBisect.cpp
blob55c0dbad5aabe5169a9d2f544113ea272cf38b87
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/Pass.h"
17 #include "llvm/Support/CommandLine.h"
18 #include "llvm/Support/raw_ostream.h"
19 #include <cassert>
20 #include <limits>
22 using namespace llvm;
24 static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden,
25 cl::init(OptBisect::Disabled), cl::Optional,
26 cl::cb<void, int>([](int Limit) {
27 llvm::OptBisector->setLimit(Limit);
28 }),
29 cl::desc("Maximum optimization to perform"));
31 static void printPassMessage(const StringRef &Name, int PassNum,
32 StringRef TargetDesc, bool Running) {
33 StringRef Status = Running ? "" : "NOT ";
34 errs() << "BISECT: " << Status << "running pass "
35 << "(" << PassNum << ") " << Name << " on " << TargetDesc << "\n";
38 bool OptBisect::shouldRunPass(const Pass *P, StringRef IRDescription) {
39 assert(isEnabled());
41 return checkPass(P->getPassName(), IRDescription);
44 bool OptBisect::checkPass(const StringRef PassName,
45 const StringRef TargetDesc) {
46 assert(isEnabled());
48 int CurBisectNum = ++LastBisectNum;
49 bool ShouldRun = (BisectLimit == -1 || CurBisectNum <= BisectLimit);
50 printPassMessage(PassName, CurBisectNum, TargetDesc, ShouldRun);
51 return ShouldRun;
54 const int OptBisect::Disabled;
56 ManagedStatic<OptBisect> llvm::OptBisector;