summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/LLVMTargetMachine.cpp
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2017-07-31 18:24:07 +0000
committerQuentin Colombet <qcolombet@apple.com>2017-07-31 18:24:07 +0000
commit15f6ffbf7c26bb468d6a5f525560538c0f1a103e (patch)
tree96cbb79ccfc4f637c3a485b7e137b038aff9e516 /llvm/lib/CodeGen/LLVMTargetMachine.cpp
parente2a247ccb0e08de8fcd5999e453bac5feb66b2a7 (diff)
downloadbcm5719-llvm-15f6ffbf7c26bb468d6a5f525560538c0f1a103e.tar.gz
bcm5719-llvm-15f6ffbf7c26bb468d6a5f525560538c0f1a103e.zip
[TargetPassConfig] Feature generic options to setup start/stop-after/before
This patch refactors the code used in llc such that all the users of the addPassesToEmitFile API have access to a homogeneous way of handling start/stop-after/before options right out of the box. In particular, just invoking addPassesToEmitFile will set the proper pipeline without additional effort (modulo parsing a .mir file if the start-before/after options are used. NFC. Differential Revision: https://reviews.llvm.org/D30913 llvm-svn: 309599
Diffstat (limited to 'llvm/lib/CodeGen/LLVMTargetMachine.cpp')
-rw-r--r--llvm/lib/CodeGen/LLVMTargetMachine.cpp43
1 files changed, 22 insertions, 21 deletions
diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index f2defb4fd62..ad105429bfe 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -92,24 +92,25 @@ TargetIRAnalysis LLVMTargetMachine::getTargetIRAnalysis() {
/// addPassesToX helper drives creation and initialization of TargetPassConfig.
static MCContext *
addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
- bool DisableVerify, AnalysisID StartBefore,
- AnalysisID StartAfter, AnalysisID StopBefore,
- AnalysisID StopAfter) {
+ bool DisableVerify, bool &WillCompleteCodeGenPipeline,
+ raw_pwrite_stream &Out, MachineModuleInfo *MMI) {
// Targets may override createPassConfig to provide a target-specific
// subclass.
TargetPassConfig *PassConfig = TM->createPassConfig(PM);
- PassConfig->setStartStopPasses(StartBefore, StartAfter, StopBefore,
- StopAfter);
// Set PassConfig options provided by TargetMachine.
PassConfig->setDisableVerify(DisableVerify);
+ WillCompleteCodeGenPipeline = PassConfig->willCompleteCodeGenPipeline();
PM.add(PassConfig);
- MachineModuleInfo *MMI = new MachineModuleInfo(TM);
+ if (!MMI)
+ MMI = new MachineModuleInfo(TM);
PM.add(MMI);
if (PassConfig->addISelPasses())
return nullptr;
PassConfig->addMachinePasses();
PassConfig->setInitialized();
+ if (!WillCompleteCodeGenPipeline)
+ PM.add(createPrintMIRPass(Out));
return &MMI->getContext();
}
@@ -185,23 +186,20 @@ bool LLVMTargetMachine::addAsmPrinter(PassManagerBase &PM,
return false;
}
-bool LLVMTargetMachine::addPassesToEmitFile(
- PassManagerBase &PM, raw_pwrite_stream &Out, CodeGenFileType FileType,
- bool DisableVerify, AnalysisID StartBefore, AnalysisID StartAfter,
- AnalysisID StopBefore, AnalysisID StopAfter) {
+bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
+ raw_pwrite_stream &Out,
+ CodeGenFileType FileType,
+ bool DisableVerify,
+ MachineModuleInfo *MMI) {
// Add common CodeGen passes.
- MCContext *Context =
- addPassesToGenerateCode(this, PM, DisableVerify, StartBefore, StartAfter,
- StopBefore, StopAfter);
+ bool WillCompleteCodeGenPipeline = true;
+ MCContext *Context = addPassesToGenerateCode(
+ this, PM, DisableVerify, WillCompleteCodeGenPipeline, Out, MMI);
if (!Context)
return true;
- if (StopBefore || StopAfter) {
- PM.add(createPrintMIRPass(Out));
- } else {
- if (addAsmPrinter(PM, Out, FileType, *Context))
- return true;
- }
+ if (WillCompleteCodeGenPipeline && addAsmPrinter(PM, Out, FileType, *Context))
+ return true;
PM.add(createFreeMachineFunctionPass());
return false;
@@ -216,10 +214,13 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
raw_pwrite_stream &Out,
bool DisableVerify) {
// Add common CodeGen passes.
- Ctx = addPassesToGenerateCode(this, PM, DisableVerify, nullptr, nullptr,
- nullptr, nullptr);
+ bool WillCompleteCodeGenPipeline = true;
+ Ctx = addPassesToGenerateCode(this, PM, DisableVerify,
+ WillCompleteCodeGenPipeline, Out,
+ /*MachineModuleInfo*/ nullptr);
if (!Ctx)
return true;
+ assert(WillCompleteCodeGenPipeline && "CodeGen pipeline has been altered");
if (Options.MCOptions.MCSaveTempLabels)
Ctx->setAllowTemporaryLabels(false);
OpenPOWER on IntegriCloud