[llvm] r345918 - LLVMTargetMachine/TargetPassConfig: Simplify handling of start/stop options; NFC
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 1 18:31:51 PDT 2018
Author: matze
Date: Thu Nov 1 18:31:50 2018
New Revision: 345918
URL: http://llvm.org/viewvc/llvm-project?rev=345918&view=rev
Log:
LLVMTargetMachine/TargetPassConfig: Simplify handling of start/stop options; NFC
- Make some TargetPassConfig methods that just check whether options have
been set static.
- Shuffle code in LLVMTargetMachine around so addPassesToGenerateCode
only deals with TargetPassConfig now (but not with MCContext or the
creation of MachineModuleInfo)
Modified:
llvm/trunk/include/llvm/CodeGen/TargetPassConfig.h
llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
llvm/trunk/lib/CodeGen/TargetPassConfig.cpp
Modified: llvm/trunk/include/llvm/CodeGen/TargetPassConfig.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/TargetPassConfig.h?rev=345918&r1=345917&r2=345918&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/TargetPassConfig.h (original)
+++ llvm/trunk/include/llvm/CodeGen/TargetPassConfig.h Thu Nov 1 18:31:50 2018
@@ -145,13 +145,13 @@ public:
CodeGenOpt::Level getOptLevel() const;
- /// Describe the status of the codegen
- /// pipeline set by this target pass config.
- /// Having a limited codegen pipeline means that options
- /// have been used to restrict what codegen is doing.
- /// In particular, that means that codegen won't emit
- /// assembly code.
- bool hasLimitedCodeGenPipeline() const;
+ /// Returns true if one of the `-start-after`, `-start-before`, `-stop-after`
+ /// or `-stop-before` options is set.
+ static bool hasLimitedCodeGenPipeline();
+
+ /// Returns true if none of the `-stop-before` and `-stop-after` options is
+ /// set.
+ static bool willCompleteCodeGenPipeline();
/// If hasLimitedCodeGenPipeline is true, this method
/// returns a string with the name of the options, separated
@@ -159,13 +159,6 @@ public:
std::string
getLimitedCodeGenPipelineReason(const char *Separator = "/") const;
- /// Check if the codegen pipeline is limited in such a way that it
- /// won't be complete. When the codegen pipeline is not complete,
- /// this means it may not be possible to generate assembly from it.
- bool willCompleteCodeGenPipeline() const {
- return !hasLimitedCodeGenPipeline() || (!StopAfter && !StopBefore);
- }
-
void setDisableVerify(bool Disable) { setOpt(DisableVerify, Disable); }
bool getEnableTailMerge() const { return EnableTailMerge; }
Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=345918&r1=345917&r2=345918&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Thu Nov 1 18:31:50 2018
@@ -95,29 +95,22 @@ LLVMTargetMachine::getTargetTransformInf
}
/// addPassesToX helper drives creation and initialization of TargetPassConfig.
-static MCContext *
-addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM,
- bool DisableVerify, bool &WillCompleteCodeGenPipeline,
- raw_pwrite_stream &Out, MachineModuleInfo *MMI) {
+static TargetPassConfig *
+addPassesToGenerateCode(LLVMTargetMachine &TM, PassManagerBase &PM,
+ bool DisableVerify, MachineModuleInfo &MMI) {
// Targets may override createPassConfig to provide a target-specific
// subclass.
- TargetPassConfig *PassConfig = TM->createPassConfig(PM);
+ TargetPassConfig *PassConfig = TM.createPassConfig(PM);
// Set PassConfig options provided by TargetMachine.
PassConfig->setDisableVerify(DisableVerify);
- WillCompleteCodeGenPipeline = PassConfig->willCompleteCodeGenPipeline();
PM.add(PassConfig);
- if (!MMI)
- MMI = new MachineModuleInfo(TM);
- PM.add(MMI);
+ PM.add(&MMI);
if (PassConfig->addISelPasses())
return nullptr;
PassConfig->addMachinePasses();
PassConfig->setInitialized();
- if (!WillCompleteCodeGenPipeline)
- PM.add(createPrintMIRPass(Out));
-
- return &MMI->getContext();
+ return PassConfig;
}
bool LLVMTargetMachine::addAsmPrinter(PassManagerBase &PM,
@@ -201,14 +194,16 @@ bool LLVMTargetMachine::addPassesToEmitF
bool DisableVerify,
MachineModuleInfo *MMI) {
// Add common CodeGen passes.
- bool WillCompleteCodeGenPipeline = true;
- MCContext *Context = addPassesToGenerateCode(
- this, PM, DisableVerify, WillCompleteCodeGenPipeline, Out, MMI);
- if (!Context)
+ if (!MMI)
+ MMI = new MachineModuleInfo(this);
+ TargetPassConfig *PassConfig =
+ addPassesToGenerateCode(*this, PM, DisableVerify, *MMI);
+ if (!PassConfig)
return true;
- if (WillCompleteCodeGenPipeline &&
- addAsmPrinter(PM, Out, DwoOut, FileType, *Context))
+ if (!TargetPassConfig::willCompleteCodeGenPipeline()) {
+ PM.add(createPrintMIRPass(Out));
+ } else if (addAsmPrinter(PM, Out, DwoOut, FileType, MMI->getContext()))
return true;
PM.add(createFreeMachineFunctionPass());
@@ -224,14 +219,15 @@ bool LLVMTargetMachine::addPassesToEmitM
raw_pwrite_stream &Out,
bool DisableVerify) {
// Add common CodeGen passes.
- bool WillCompleteCodeGenPipeline = true;
- Ctx = addPassesToGenerateCode(this, PM, DisableVerify,
- WillCompleteCodeGenPipeline, Out,
- /*MachineModuleInfo*/ nullptr);
- if (!Ctx)
+ MachineModuleInfo *MMI = new MachineModuleInfo(this);
+ TargetPassConfig *PassConfig =
+ addPassesToGenerateCode(*this, PM, DisableVerify, *MMI);
+ if (!PassConfig)
return true;
- assert(WillCompleteCodeGenPipeline && "CodeGen pipeline has been altered");
+ assert(TargetPassConfig::willCompleteCodeGenPipeline() &&
+ "Cannot emit MC with limited codegen pipeline");
+ Ctx = &MMI->getContext();
if (Options.MCOptions.MCSaveTempLabels)
Ctx->setAllowTemporaryLabels(false);
Modified: llvm/trunk/lib/CodeGen/TargetPassConfig.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetPassConfig.cpp?rev=345918&r1=345917&r2=345918&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetPassConfig.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetPassConfig.cpp Thu Nov 1 18:31:50 2018
@@ -419,8 +419,13 @@ TargetPassConfig::TargetPassConfig()
"triple set?");
}
-bool TargetPassConfig::hasLimitedCodeGenPipeline() const {
- return StartBefore || StartAfter || StopBefore || StopAfter;
+bool TargetPassConfig::willCompleteCodeGenPipeline() {
+ return StopBeforeOpt.empty() && StopAfterOpt.empty();
+}
+
+bool TargetPassConfig::hasLimitedCodeGenPipeline() {
+ return !StartBeforeOpt.empty() || !StartAfterOpt.empty() ||
+ !willCompleteCodeGenPipeline();
}
std::string
More information about the llvm-commits
mailing list