mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-04 18:06:49 +00:00
57bd1ea8eb
Summary: Ths "cases" support was not quite finished, is unused, and is really just debug counters. (well, almost, debug counters are slightly more powerful, in that they can skip things at the start, too). Note, opt-bisect itself could also be implemented as a wrapper around debug counters, but not sure it's worth it ATM. I'll shove it on a todo list if we think it is. Reviewers: MatzeB, chandlerc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D30856 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297542 91177308-0d34-0410-b5e6-96231b3b80d8
103 lines
3.3 KiB
C++
103 lines
3.3 KiB
C++
//===------- llvm/IR/OptBisect/Bisect.cpp - LLVM Bisect support --------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// This file implements support for a bisecting optimizations based on a
|
|
/// command line option.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Analysis/CallGraphSCCPass.h"
|
|
#include "llvm/Analysis/LazyCallGraph.h"
|
|
#include "llvm/Analysis/LoopInfo.h"
|
|
#include "llvm/IR/Module.h"
|
|
#include "llvm/IR/OptBisect.h"
|
|
#include "llvm/Pass.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden,
|
|
cl::init(INT_MAX), cl::Optional,
|
|
cl::desc("Maximum optimization to perform"));
|
|
|
|
OptBisect::OptBisect() {
|
|
BisectEnabled = OptBisectLimit != INT_MAX;
|
|
}
|
|
|
|
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";
|
|
}
|
|
|
|
static std::string getDescription(const Module &M) {
|
|
return "module (" + M.getName().str() + ")";
|
|
}
|
|
|
|
static std::string getDescription(const Function &F) {
|
|
return "function (" + F.getName().str() + ")";
|
|
}
|
|
|
|
static std::string getDescription(const BasicBlock &BB) {
|
|
return "basic block (" + BB.getName().str() + ") in function (" +
|
|
BB.getParent()->getName().str() + ")";
|
|
}
|
|
|
|
static std::string getDescription(const Loop &L) {
|
|
// FIXME: I'd like to be able to provide a better description here, but
|
|
// calling L->getHeader() would introduce a new dependency on the
|
|
// LLVMCore library.
|
|
return "loop";
|
|
}
|
|
|
|
static std::string getDescription(const CallGraphSCC &SCC) {
|
|
std::string Desc = "SCC (";
|
|
bool First = true;
|
|
for (CallGraphNode *CGN : SCC) {
|
|
if (First)
|
|
First = false;
|
|
else
|
|
Desc += ", ";
|
|
Function *F = CGN->getFunction();
|
|
if (F)
|
|
Desc += F->getName();
|
|
else
|
|
Desc += "<<null function>>";
|
|
}
|
|
Desc += ")";
|
|
return Desc;
|
|
}
|
|
|
|
// Force instantiations.
|
|
template bool OptBisect::shouldRunPass(const Pass *, const Module &);
|
|
template bool OptBisect::shouldRunPass(const Pass *, const Function &);
|
|
template bool OptBisect::shouldRunPass(const Pass *, const BasicBlock &);
|
|
template bool OptBisect::shouldRunPass(const Pass *, const Loop &);
|
|
template bool OptBisect::shouldRunPass(const Pass *, const CallGraphSCC &);
|
|
|
|
template <class UnitT>
|
|
bool OptBisect::shouldRunPass(const Pass *P, const UnitT &U) {
|
|
if (!BisectEnabled)
|
|
return true;
|
|
return checkPass(P->getPassName(), getDescription(U));
|
|
}
|
|
|
|
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;
|
|
}
|