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"
|
2017-09-01 00:06:09 +02:00
|
|
|
#include "llvm/ADT/StringRef.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>
|
|
|
|
#include <string>
|
2016-04-23 00:06:11 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden,
|
2017-09-01 00:06:09 +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"));
|
|
|
|
|
2018-03-27 18:57:20 +02:00
|
|
|
OptBisect::OptBisect() : OptPassGate() {
|
2017-09-01 00:06:09 +02:00
|
|
|
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) {
|
|
|
|
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) {
|
|
|
|
assert(BisectEnabled);
|
|
|
|
|
|
|
|
int CurBisectNum = ++LastBisectNum;
|
|
|
|
bool ShouldRun = (OptBisectLimit == -1 || CurBisectNum <= OptBisectLimit);
|
|
|
|
printPassMessage(PassName, CurBisectNum, TargetDesc, ShouldRun);
|
|
|
|
return ShouldRun;
|
|
|
|
}
|