2017-09-01 00:06:09 +02:00
|
|
|
//===- llvm/IR/OptBisect/Bisect.cpp - LLVM Bisect support -----------------===//
|
2016-04-23 00:06:11 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-04-23 00:06:11 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2017-09-01 00:06:09 +02:00
|
|
|
//
|
2016-04-23 00:06:11 +02:00
|
|
|
/// \file
|
|
|
|
/// This file implements support for a bisecting optimizations based on a
|
|
|
|
/// command line option.
|
2017-09-01 00:06:09 +02:00
|
|
|
//
|
2016-04-23 00:06:11 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm/IR/OptBisect.h"
|
2016-04-23 00:06:11 +02:00
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-09-01 00:06:09 +02:00
|
|
|
#include <cassert>
|
|
|
|
#include <limits>
|
2016-04-23 00:06:11 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden,
|
2021-06-18 20:16:45 +02:00
|
|
|
cl::init(std::numeric_limits<int>::max()),
|
|
|
|
cl::Optional,
|
2016-04-23 00:06:11 +02:00
|
|
|
cl::desc("Maximum optimization to perform"));
|
|
|
|
|
2021-06-18 20:16:45 +02:00
|
|
|
OptBisect::OptBisect() : OptPassGate() {
|
|
|
|
BisectEnabled = OptBisectLimit != std::numeric_limits<int>::max();
|
|
|
|
}
|
|
|
|
|
2016-04-23 00:06:11 +02:00
|
|
|
static void printPassMessage(const StringRef &Name, int PassNum,
|
|
|
|
StringRef TargetDesc, bool Running) {
|
|
|
|
StringRef Status = Running ? "" : "NOT ";
|
|
|
|
errs() << "BISECT: " << Status << "running pass "
|
|
|
|
<< "(" << PassNum << ") " << Name << " on " << TargetDesc << "\n";
|
|
|
|
}
|
|
|
|
|
2019-02-28 05:00:55 +01:00
|
|
|
bool OptBisect::shouldRunPass(const Pass *P, StringRef IRDescription) {
|
2021-06-18 20:16:45 +02:00
|
|
|
assert(BisectEnabled);
|
2018-03-27 18:57:20 +02:00
|
|
|
|
2019-02-28 05:00:55 +01:00
|
|
|
return checkPass(P->getPassName(), IRDescription);
|
2016-04-23 00:06:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OptBisect::checkPass(const StringRef PassName,
|
|
|
|
const StringRef TargetDesc) {
|
2021-06-18 20:16:45 +02:00
|
|
|
assert(BisectEnabled);
|
2016-04-23 00:06:11 +02:00
|
|
|
|
|
|
|
int CurBisectNum = ++LastBisectNum;
|
2021-06-18 20:16:45 +02:00
|
|
|
bool ShouldRun = (OptBisectLimit == -1 || CurBisectNum <= OptBisectLimit);
|
2016-04-23 00:06:11 +02:00
|
|
|
printPassMessage(PassName, CurBisectNum, TargetDesc, ShouldRun);
|
|
|
|
return ShouldRun;
|
|
|
|
}
|
2020-12-20 22:47:46 +01:00
|
|
|
|
|
|
|
ManagedStatic<OptBisect> llvm::OptBisector;
|