mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
llc: Add -start-before/-stop-before options
Differential Revision: https://reviews.llvm.org/D23089 llvm-svn: 282302
This commit is contained in:
parent
cef2ce70e8
commit
948a4beee1
@ -94,8 +94,10 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
PassManagerBase *PM;
|
PassManagerBase *PM;
|
||||||
AnalysisID StartBefore, StartAfter;
|
AnalysisID StartBefore = nullptr;
|
||||||
AnalysisID StopAfter;
|
AnalysisID StartAfter = nullptr;
|
||||||
|
AnalysisID StopBefore = nullptr;
|
||||||
|
AnalysisID StopAfter = nullptr;
|
||||||
bool Started;
|
bool Started;
|
||||||
bool Stopped;
|
bool Stopped;
|
||||||
bool AddingMachinePasses;
|
bool AddingMachinePasses;
|
||||||
@ -143,11 +145,14 @@ public:
|
|||||||
/// This function expects that at least one of the StartAfter or the
|
/// This function expects that at least one of the StartAfter or the
|
||||||
/// StartBefore pass IDs is null.
|
/// StartBefore pass IDs is null.
|
||||||
void setStartStopPasses(AnalysisID StartBefore, AnalysisID StartAfter,
|
void setStartStopPasses(AnalysisID StartBefore, AnalysisID StartAfter,
|
||||||
AnalysisID StopAfter) {
|
AnalysisID StopBefore, AnalysisID StopAfter) {
|
||||||
if (StartAfter)
|
assert(!(StartBefore && StartAfter) &&
|
||||||
assert(!StartBefore && "Start after and start before passes are given");
|
"Start after and start before passes are given");
|
||||||
|
assert(!(StopBefore && StopAfter) &&
|
||||||
|
"Stop after and stop before passed are given");
|
||||||
this->StartBefore = StartBefore;
|
this->StartBefore = StartBefore;
|
||||||
this->StartAfter = StartAfter;
|
this->StartAfter = StartAfter;
|
||||||
|
this->StopBefore = StopBefore;
|
||||||
this->StopAfter = StopAfter;
|
this->StopAfter = StopAfter;
|
||||||
Started = (StartAfter == nullptr) && (StartBefore == nullptr);
|
Started = (StartAfter == nullptr) && (StartBefore == nullptr);
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,8 @@ public:
|
|||||||
virtual bool addPassesToEmitFile(
|
virtual bool addPassesToEmitFile(
|
||||||
PassManagerBase &, raw_pwrite_stream &, CodeGenFileType,
|
PassManagerBase &, raw_pwrite_stream &, CodeGenFileType,
|
||||||
bool /*DisableVerify*/ = true, AnalysisID /*StartBefore*/ = nullptr,
|
bool /*DisableVerify*/ = true, AnalysisID /*StartBefore*/ = nullptr,
|
||||||
AnalysisID /*StartAfter*/ = nullptr, AnalysisID /*StopAfter*/ = nullptr,
|
AnalysisID /*StartAfter*/ = nullptr, AnalysisID /*StopBefore*/ = nullptr,
|
||||||
|
AnalysisID /*StopAfter*/ = nullptr,
|
||||||
MachineFunctionInitializer * /*MFInitializer*/ = nullptr) {
|
MachineFunctionInitializer * /*MFInitializer*/ = nullptr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -302,7 +303,8 @@ public:
|
|||||||
bool addPassesToEmitFile(
|
bool addPassesToEmitFile(
|
||||||
PassManagerBase &PM, raw_pwrite_stream &Out, CodeGenFileType FileType,
|
PassManagerBase &PM, raw_pwrite_stream &Out, CodeGenFileType FileType,
|
||||||
bool DisableVerify = true, AnalysisID StartBefore = nullptr,
|
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;
|
MachineFunctionInitializer *MFInitializer = nullptr) override;
|
||||||
|
|
||||||
/// Add passes to the specified pass manager to get machine code emitted with
|
/// Add passes to the specified pass manager to get machine code emitted with
|
||||||
|
@ -105,7 +105,8 @@ TargetIRAnalysis LLVMTargetMachine::getTargetIRAnalysis() {
|
|||||||
static MCContext *
|
static MCContext *
|
||||||
addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
|
addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
|
||||||
bool DisableVerify, AnalysisID StartBefore,
|
bool DisableVerify, AnalysisID StartBefore,
|
||||||
AnalysisID StartAfter, AnalysisID StopAfter,
|
AnalysisID StartAfter, AnalysisID StopBefore,
|
||||||
|
AnalysisID StopAfter,
|
||||||
MachineFunctionInitializer *MFInitializer = nullptr) {
|
MachineFunctionInitializer *MFInitializer = nullptr) {
|
||||||
|
|
||||||
// When in emulated TLS mode, add the LowerEmuTLS pass.
|
// 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
|
// Targets may override createPassConfig to provide a target-specific
|
||||||
// subclass.
|
// subclass.
|
||||||
TargetPassConfig *PassConfig = TM->createPassConfig(PM);
|
TargetPassConfig *PassConfig = TM->createPassConfig(PM);
|
||||||
PassConfig->setStartStopPasses(StartBefore, StartAfter, StopAfter);
|
PassConfig->setStartStopPasses(StartBefore, StartAfter, StopBefore,
|
||||||
|
StopAfter);
|
||||||
|
|
||||||
// Set PassConfig options provided by TargetMachine.
|
// Set PassConfig options provided by TargetMachine.
|
||||||
PassConfig->setDisableVerify(DisableVerify);
|
PassConfig->setDisableVerify(DisableVerify);
|
||||||
@ -191,15 +193,16 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
|
|||||||
bool LLVMTargetMachine::addPassesToEmitFile(
|
bool LLVMTargetMachine::addPassesToEmitFile(
|
||||||
PassManagerBase &PM, raw_pwrite_stream &Out, CodeGenFileType FileType,
|
PassManagerBase &PM, raw_pwrite_stream &Out, CodeGenFileType FileType,
|
||||||
bool DisableVerify, AnalysisID StartBefore, AnalysisID StartAfter,
|
bool DisableVerify, AnalysisID StartBefore, AnalysisID StartAfter,
|
||||||
AnalysisID StopAfter, MachineFunctionInitializer *MFInitializer) {
|
AnalysisID StopBefore, AnalysisID StopAfter,
|
||||||
|
MachineFunctionInitializer *MFInitializer) {
|
||||||
// Add common CodeGen passes.
|
// Add common CodeGen passes.
|
||||||
MCContext *Context =
|
MCContext *Context =
|
||||||
addPassesToGenerateCode(this, PM, DisableVerify, StartBefore, StartAfter,
|
addPassesToGenerateCode(this, PM, DisableVerify, StartBefore, StartAfter,
|
||||||
StopAfter, MFInitializer);
|
StopBefore, StopAfter, MFInitializer);
|
||||||
if (!Context)
|
if (!Context)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (StopAfter) {
|
if (StopBefore || StopAfter) {
|
||||||
PM.add(createPrintMIRPass(Out));
|
PM.add(createPrintMIRPass(Out));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -284,7 +287,7 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
|
|||||||
bool DisableVerify) {
|
bool DisableVerify) {
|
||||||
// Add common CodeGen passes.
|
// Add common CodeGen passes.
|
||||||
Ctx = addPassesToGenerateCode(this, PM, DisableVerify, nullptr, nullptr,
|
Ctx = addPassesToGenerateCode(this, PM, DisableVerify, nullptr, nullptr,
|
||||||
nullptr);
|
nullptr, nullptr);
|
||||||
if (!Ctx)
|
if (!Ctx)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -260,8 +260,7 @@ TargetPassConfig::~TargetPassConfig() {
|
|||||||
// Out of line constructor provides default values for pass options and
|
// Out of line constructor provides default values for pass options and
|
||||||
// registers all common codegen passes.
|
// registers all common codegen passes.
|
||||||
TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm)
|
TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm)
|
||||||
: ImmutablePass(ID), PM(&pm), StartBefore(nullptr), StartAfter(nullptr),
|
: ImmutablePass(ID), PM(&pm), Started(true), Stopped(false),
|
||||||
StopAfter(nullptr), Started(true), Stopped(false),
|
|
||||||
AddingMachinePasses(false), TM(tm), Impl(nullptr), Initialized(false),
|
AddingMachinePasses(false), TM(tm), Impl(nullptr), Initialized(false),
|
||||||
DisableVerify(false), EnableTailMerge(true) {
|
DisableVerify(false), EnableTailMerge(true) {
|
||||||
|
|
||||||
@ -355,6 +354,8 @@ void TargetPassConfig::addPass(Pass *P, bool verifyAfter, bool printAfter) {
|
|||||||
|
|
||||||
if (StartBefore == PassID)
|
if (StartBefore == PassID)
|
||||||
Started = true;
|
Started = true;
|
||||||
|
if (StopBefore == PassID)
|
||||||
|
Stopped = true;
|
||||||
if (Started && !Stopped) {
|
if (Started && !Stopped) {
|
||||||
std::string Banner;
|
std::string Banner;
|
||||||
// Construct banner message before PM->add() as that may delete the pass.
|
// Construct banner message before PM->add() as that may delete the pass.
|
||||||
|
35
test/CodeGen/Generic/llc-start-stop.ll
Normal file
35
test/CodeGen/Generic/llc-start-stop.ll
Normal 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!
|
@ -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
|
|
@ -118,10 +118,18 @@ static cl::opt<bool> DiscardValueNames(
|
|||||||
cl::desc("Discard names from Value (other than GlobalValue)."),
|
cl::desc("Discard names from Value (other than GlobalValue)."),
|
||||||
cl::init(false), cl::Hidden);
|
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",
|
static cl::opt<std::string> StopAfter("stop-after",
|
||||||
cl::desc("Stop compilation after a specific pass"),
|
cl::desc("Stop compilation after a specific pass"),
|
||||||
cl::value_desc("pass-name"), cl::init(""));
|
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",
|
static cl::opt<std::string> StartAfter("start-after",
|
||||||
cl::desc("Resume compilation after a specific pass"),
|
cl::desc("Resume compilation after a specific pass"),
|
||||||
cl::value_desc("pass-name"), cl::init(""));
|
cl::value_desc("pass-name"), cl::init(""));
|
||||||
@ -304,6 +312,20 @@ static bool addPass(PassManagerBase &PM, const char *argv0,
|
|||||||
return false;
|
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) {
|
static int compileModule(char **argv, LLVMContext &Context) {
|
||||||
// Load the module to be compiled...
|
// Load the module to be compiled...
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
@ -434,12 +456,9 @@ static int compileModule(char **argv, LLVMContext &Context) {
|
|||||||
OS = BOS.get();
|
OS = BOS.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
AnalysisID StartBeforeID = nullptr;
|
|
||||||
AnalysisID StartAfterID = nullptr;
|
|
||||||
AnalysisID StopAfterID = nullptr;
|
|
||||||
const PassRegistry *PR = PassRegistry::getPassRegistry();
|
|
||||||
if (!RunPassNames->empty()) {
|
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 "
|
errs() << argv[0] << ": start-after and/or stop-after passes are "
|
||||||
"redundant when run-pass is specified.\n";
|
"redundant when run-pass is specified.\n";
|
||||||
return 1;
|
return 1;
|
||||||
@ -462,27 +481,25 @@ static int compileModule(char **argv, LLVMContext &Context) {
|
|||||||
}
|
}
|
||||||
PM.add(createPrintMIRPass(*OS));
|
PM.add(createPrintMIRPass(*OS));
|
||||||
} else {
|
} else {
|
||||||
if (!StartAfter.empty()) {
|
const char *argv0 = argv[0];
|
||||||
const PassInfo *PI = PR->getPassInfo(StartAfter);
|
AnalysisID StartBeforeID = getPassID(argv0, "start-before", StartBefore);
|
||||||
if (!PI) {
|
AnalysisID StartAfterID = getPassID(argv0, "start-after", StartAfter);
|
||||||
errs() << argv[0] << ": start-after pass is not registered.\n";
|
AnalysisID StopAfterID = getPassID(argv0, "stop-after", StopAfter);
|
||||||
return 1;
|
AnalysisID StopBeforeID = getPassID(argv0, "stop-before", StopBefore);
|
||||||
}
|
|
||||||
StartAfterID = PI->getTypeInfo();
|
if (StartBeforeID && StartAfterID) {
|
||||||
|
errs() << argv[0] << ": -start-before and -start-after specified!\n";
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
if (!StopAfter.empty()) {
|
if (StopBeforeID && StopAfterID) {
|
||||||
const PassInfo *PI = PR->getPassInfo(StopAfter);
|
errs() << argv[0] << ": -stop-before and -stop-after specified!\n";
|
||||||
if (!PI) {
|
return 1;
|
||||||
errs() << argv[0] << ": stop-after pass is not registered.\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
StopAfterID = PI->getTypeInfo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask the target to add backend passes as necessary.
|
// Ask the target to add backend passes as necessary.
|
||||||
if (Target->addPassesToEmitFile(PM, *OS, FileType, NoVerify,
|
if (Target->addPassesToEmitFile(PM, *OS, FileType, NoVerify,
|
||||||
StartBeforeID, StartAfterID, StopAfterID,
|
StartBeforeID, StartAfterID, StopBeforeID,
|
||||||
MIR.get())) {
|
StopAfterID, MIR.get())) {
|
||||||
errs() << argv[0] << ": target does not support generation of this"
|
errs() << argv[0] << ": target does not support generation of this"
|
||||||
<< " file type!\n";
|
<< " file type!\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user