llc: Add -start-before/-stop-before options

Differential Revision: https://reviews.llvm.org/D23089

llvm-svn: 282302
This commit is contained in:
Matthias Braun 2016-09-23 21:46:02 +00:00
parent 2d3a26ffb9
commit 729c989083
7 changed files with 99 additions and 46 deletions

View File

@ -94,8 +94,10 @@ public:
private:
PassManagerBase *PM;
AnalysisID StartBefore, StartAfter;
AnalysisID StopAfter;
AnalysisID StartBefore = nullptr;
AnalysisID StartAfter = nullptr;
AnalysisID StopBefore = nullptr;
AnalysisID StopAfter = nullptr;
bool Started;
bool Stopped;
bool AddingMachinePasses;
@ -143,11 +145,14 @@ public:
/// This function expects that at least one of the StartAfter or the
/// StartBefore pass IDs is null.
void setStartStopPasses(AnalysisID StartBefore, AnalysisID StartAfter,
AnalysisID StopAfter) {
if (StartAfter)
assert(!StartBefore && "Start after and start before passes are given");
AnalysisID StopBefore, AnalysisID StopAfter) {
assert(!(StartBefore && StartAfter) &&
"Start after and start before passes are given");
assert(!(StopBefore && StopAfter) &&
"Stop after and stop before passed are given");
this->StartBefore = StartBefore;
this->StartAfter = StartAfter;
this->StopBefore = StopBefore;
this->StopAfter = StopAfter;
Started = (StartAfter == nullptr) && (StartBefore == nullptr);
}

View File

@ -241,7 +241,8 @@ public:
virtual bool addPassesToEmitFile(
PassManagerBase &, raw_pwrite_stream &, CodeGenFileType,
bool /*DisableVerify*/ = true, AnalysisID /*StartBefore*/ = nullptr,
AnalysisID /*StartAfter*/ = nullptr, AnalysisID /*StopAfter*/ = nullptr,
AnalysisID /*StartAfter*/ = nullptr, AnalysisID /*StopBefore*/ = nullptr,
AnalysisID /*StopAfter*/ = nullptr,
MachineFunctionInitializer * /*MFInitializer*/ = nullptr) {
return true;
}
@ -302,7 +303,8 @@ public:
bool addPassesToEmitFile(
PassManagerBase &PM, raw_pwrite_stream &Out, CodeGenFileType FileType,
bool DisableVerify = true, AnalysisID StartBefore = nullptr,
AnalysisID StartAfter = nullptr, AnalysisID StopAfter = nullptr,
AnalysisID StartAfter = nullptr, AnalysisID StopBefore = nullptr,
AnalysisID StopAfter = nullptr,
MachineFunctionInitializer *MFInitializer = nullptr) override;
/// Add passes to the specified pass manager to get machine code emitted with

View File

@ -105,7 +105,8 @@ TargetIRAnalysis LLVMTargetMachine::getTargetIRAnalysis() {
static MCContext *
addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
bool DisableVerify, AnalysisID StartBefore,
AnalysisID StartAfter, AnalysisID StopAfter,
AnalysisID StartAfter, AnalysisID StopBefore,
AnalysisID StopAfter,
MachineFunctionInitializer *MFInitializer = nullptr) {
// When in emulated TLS mode, add the LowerEmuTLS pass.
@ -120,7 +121,8 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
// Targets may override createPassConfig to provide a target-specific
// subclass.
TargetPassConfig *PassConfig = TM->createPassConfig(PM);
PassConfig->setStartStopPasses(StartBefore, StartAfter, StopAfter);
PassConfig->setStartStopPasses(StartBefore, StartAfter, StopBefore,
StopAfter);
// Set PassConfig options provided by TargetMachine.
PassConfig->setDisableVerify(DisableVerify);
@ -191,15 +193,16 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
bool LLVMTargetMachine::addPassesToEmitFile(
PassManagerBase &PM, raw_pwrite_stream &Out, CodeGenFileType FileType,
bool DisableVerify, AnalysisID StartBefore, AnalysisID StartAfter,
AnalysisID StopAfter, MachineFunctionInitializer *MFInitializer) {
AnalysisID StopBefore, AnalysisID StopAfter,
MachineFunctionInitializer *MFInitializer) {
// Add common CodeGen passes.
MCContext *Context =
addPassesToGenerateCode(this, PM, DisableVerify, StartBefore, StartAfter,
StopAfter, MFInitializer);
StopBefore, StopAfter, MFInitializer);
if (!Context)
return true;
if (StopAfter) {
if (StopBefore || StopAfter) {
PM.add(createPrintMIRPass(Out));
return false;
}
@ -284,7 +287,7 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
bool DisableVerify) {
// Add common CodeGen passes.
Ctx = addPassesToGenerateCode(this, PM, DisableVerify, nullptr, nullptr,
nullptr);
nullptr, nullptr);
if (!Ctx)
return true;

View File

@ -260,8 +260,7 @@ TargetPassConfig::~TargetPassConfig() {
// Out of line constructor provides default values for pass options and
// registers all common codegen passes.
TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm)
: ImmutablePass(ID), PM(&pm), StartBefore(nullptr), StartAfter(nullptr),
StopAfter(nullptr), Started(true), Stopped(false),
: ImmutablePass(ID), PM(&pm), Started(true), Stopped(false),
AddingMachinePasses(false), TM(tm), Impl(nullptr), Initialized(false),
DisableVerify(false), EnableTailMerge(true) {
@ -355,6 +354,8 @@ void TargetPassConfig::addPass(Pass *P, bool verifyAfter, bool printAfter) {
if (StartBefore == PassID)
Started = true;
if (StopBefore == PassID)
Stopped = true;
if (Started && !Stopped) {
std::string Banner;
// Construct banner message before PM->add() as that may delete the pass.

View File

@ -0,0 +1,35 @@
; RUN: llc < %s -debug-pass=Structure -stop-after=loop-reduce -o /dev/null 2>&1 | FileCheck %s -check-prefix=STOP-AFTER
; STOP-AFTER: -loop-reduce
; STOP-AFTER: Dominator Tree Construction
; STOP-AFTER: Loop Strength Reduction
; STOP-AFTER-NEXT: MIR Printing Pass
; RUN: llc < %s -debug-pass=Structure -stop-before=loop-reduce -o /dev/null 2>&1 | FileCheck %s -check-prefix=STOP-BEFORE
; STOP-BEFORE-NOT: -loop-reduce
; STOP-BEFORE: Dominator Tree Construction
; STOP-BEFORE-NOT: Loop Strength Reduction
; RUN: llc < %s -debug-pass=Structure -start-after=loop-reduce -o /dev/null 2>&1 | FileCheck %s -check-prefix=START-AFTER
; START-AFTER: -machine-branch-prob -pre-isel-intrinsic-lowering
; START-AFTER: FunctionPass Manager
; START-AFTER-NEXT: Lower Garbage Collection Instructions
; RUN: llc < %s -debug-pass=Structure -start-before=loop-reduce -o /dev/null 2>&1 | FileCheck %s -check-prefix=START-BEFORE
; START-BEFORE: -machine-branch-prob -pre-isel-intrinsic-lowering
; START-BEFORE: FunctionPass Manager
; START-BEFORE: Loop Strength Reduction
; START-BEFORE-NEXT: Lower Garbage Collection Instructions
; RUN: not llc < %s -start-before=nonexistent -o /dev/null 2>&1 | FileCheck %s -check-prefix=NONEXISTENT-START-BEFORE
; RUN: not llc < %s -stop-before=nonexistent -o /dev/null 2>&1 | FileCheck %s -check-prefix=NONEXISTENT-STOP-BEFORE
; RUN: not llc < %s -start-after=nonexistent -o /dev/null 2>&1 | FileCheck %s -check-prefix=NONEXISTENT-START-AFTER
; RUN: not llc < %s -stop-after=nonexistent -o /dev/null 2>&1 | FileCheck %s -check-prefix=NONEXISTENT-STOP-AFTER
; NONEXISTENT-START-BEFORE: start-before pass is not registered.
; NONEXISTENT-STOP-BEFORE: stop-before pass is not registered.
; NONEXISTENT-START-AFTER: start-after pass is not registered.
; NONEXISTENT-STOP-AFTER: stop-after pass is not registered.
; RUN: not llc < %s -start-before=loop-reduce -start-after=loop-reduce -o /dev/null 2>&1 | FileCheck %s -check-prefix=DOUBLE-START
; RUN: not llc < %s -stop-before=loop-reduce -stop-after=loop-reduce -o /dev/null 2>&1 | FileCheck %s -check-prefix=DOUBLE-STOP
; DOUBLE-START: -start-before and -start-after specified!
; DOUBLE-STOP: -stop-before and -stop-after specified!

View File

@ -1,10 +0,0 @@
; RUN: llc < %s -debug-pass=Structure -stop-after=loop-reduce -o /dev/null 2>&1 | FileCheck %s -check-prefix=STOP
; RUN: llc < %s -debug-pass=Structure -start-after=loop-reduce -o /dev/null 2>&1 | FileCheck %s -check-prefix=START
; STOP: -loop-reduce
; STOP: Loop Strength Reduction
; STOP-NEXT: MIR Printing Pass
; START: -machine-branch-prob -pre-isel-intrinsic-lowering
; START: FunctionPass Manager
; START-NEXT: Lower Garbage Collection Instructions

View File

@ -118,10 +118,18 @@ static cl::opt<bool> DiscardValueNames(
cl::desc("Discard names from Value (other than GlobalValue)."),
cl::init(false), cl::Hidden);
static cl::opt<std::string> StopBefore("stop-before",
cl::desc("Stop compilation before a specific pass"),
cl::value_desc("pass-name"), cl::init(""));
static cl::opt<std::string> StopAfter("stop-after",
cl::desc("Stop compilation after a specific pass"),
cl::value_desc("pass-name"), cl::init(""));
static cl::opt<std::string> StartBefore("start-before",
cl::desc("Resume compilation before a specific pass"),
cl::value_desc("pass-name"), cl::init(""));
static cl::opt<std::string> StartAfter("start-after",
cl::desc("Resume compilation after a specific pass"),
cl::value_desc("pass-name"), cl::init(""));
@ -304,6 +312,20 @@ static bool addPass(PassManagerBase &PM, const char *argv0,
return false;
}
static AnalysisID getPassID(const char *argv0, const char *OptionName,
StringRef PassName) {
if (PassName.empty())
return nullptr;
const PassRegistry &PR = *PassRegistry::getPassRegistry();
const PassInfo *PI = PR.getPassInfo(PassName);
if (!PI) {
errs() << argv0 << ": " << OptionName << " pass is not registered.\n";
exit(1);
}
return PI->getTypeInfo();
}
static int compileModule(char **argv, LLVMContext &Context) {
// Load the module to be compiled...
SMDiagnostic Err;
@ -434,12 +456,9 @@ static int compileModule(char **argv, LLVMContext &Context) {
OS = BOS.get();
}
AnalysisID StartBeforeID = nullptr;
AnalysisID StartAfterID = nullptr;
AnalysisID StopAfterID = nullptr;
const PassRegistry *PR = PassRegistry::getPassRegistry();
if (!RunPassNames->empty()) {
if (!StartAfter.empty() || !StopAfter.empty()) {
if (!StartAfter.empty() || !StopAfter.empty() || !StartBefore.empty() ||
!StopBefore.empty()) {
errs() << argv[0] << ": start-after and/or stop-after passes are "
"redundant when run-pass is specified.\n";
return 1;
@ -462,27 +481,25 @@ static int compileModule(char **argv, LLVMContext &Context) {
}
PM.add(createPrintMIRPass(*OS));
} else {
if (!StartAfter.empty()) {
const PassInfo *PI = PR->getPassInfo(StartAfter);
if (!PI) {
errs() << argv[0] << ": start-after pass is not registered.\n";
return 1;
}
StartAfterID = PI->getTypeInfo();
const char *argv0 = argv[0];
AnalysisID StartBeforeID = getPassID(argv0, "start-before", StartBefore);
AnalysisID StartAfterID = getPassID(argv0, "start-after", StartAfter);
AnalysisID StopAfterID = getPassID(argv0, "stop-after", StopAfter);
AnalysisID StopBeforeID = getPassID(argv0, "stop-before", StopBefore);
if (StartBeforeID && StartAfterID) {
errs() << argv[0] << ": -start-before and -start-after specified!\n";
return 1;
}
if (!StopAfter.empty()) {
const PassInfo *PI = PR->getPassInfo(StopAfter);
if (!PI) {
errs() << argv[0] << ": stop-after pass is not registered.\n";
return 1;
}
StopAfterID = PI->getTypeInfo();
if (StopBeforeID && StopAfterID) {
errs() << argv[0] << ": -stop-before and -stop-after specified!\n";
return 1;
}
// Ask the target to add backend passes as necessary.
if (Target->addPassesToEmitFile(PM, *OS, FileType, NoVerify,
StartBeforeID, StartAfterID, StopAfterID,
MIR.get())) {
StartBeforeID, StartAfterID, StopBeforeID,
StopAfterID, MIR.get())) {
errs() << argv[0] << ": target does not support generation of this"
<< " file type!\n";
return 1;