From c162bc2aedbe7412a56063cd2284d1c7b1858f05 Mon Sep 17 00:00:00 2001 From: Daniel Sanders Date: Wed, 8 Apr 2020 13:43:46 -0700 Subject: [PATCH] Make TargetPassConfig and llc add pre/post passes the same way. NFC Summary: At the moment, any changes we make to the passes that can be injected before/after others (e.g. -verify-machineinstrs and -print-after-all) have to be duplicated in both TargetPassConfig (for normal execution, -start-before/ -stop-before/etc) and llc (for -run-pass). Unify this pass injection into addMachinePrePass/addMachinePostPass that both TargetPassConfig and llc can use. Reviewers: vsk, aprantl, bogner Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77887 --- llvm/include/llvm/CodeGen/TargetPassConfig.h | 9 +++++++++ llvm/lib/CodeGen/TargetPassConfig.cpp | 21 +++++++++++++++------ llvm/tools/llc/llc.cpp | 3 ++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/CodeGen/TargetPassConfig.h b/llvm/include/llvm/CodeGen/TargetPassConfig.h index d48fc66..f84e85c5 100644 --- a/llvm/include/llvm/CodeGen/TargetPassConfig.h +++ b/llvm/include/llvm/CodeGen/TargetPassConfig.h @@ -306,6 +306,15 @@ public: /// verification is enabled. void addVerifyPass(const std::string &Banner); + /// Add standard passes before a pass that's about to be added. For example, + /// the DebugifyMachineModulePass if it is enabled. + void addMachinePrePasses(); + + /// Add standard passes after a pass that has just been added. For example, + /// the MachineVerifier if it is enabled. + void addMachinePostPasses(const std::string &Banner, bool AllowPrint = true, + bool AllowVerify = true); + /// Check whether or not GlobalISel should abort on error. /// When this is disabled, GlobalISel will fall back on SDISel instead of /// erroring out. diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp index 44c326e..448a087 100644 --- a/llvm/lib/CodeGen/TargetPassConfig.cpp +++ b/llvm/lib/CodeGen/TargetPassConfig.cpp @@ -530,17 +530,16 @@ void TargetPassConfig::addPass(Pass *P, bool verifyAfter, bool printAfter) { if (StopBefore == PassID && StopBeforeCount++ == StopBeforeInstanceNum) Stopped = true; if (Started && !Stopped) { + if (AddingMachinePasses) + addMachinePrePasses(); std::string Banner; // Construct banner message before PM->add() as that may delete the pass. if (AddingMachinePasses && (printAfter || verifyAfter)) Banner = std::string("After ") + std::string(P->getPassName()); PM->add(P); - if (AddingMachinePasses) { - if (printAfter) - addPrintPass(Banner); - if (verifyAfter) - addVerifyPass(Banner); - } + if (AddingMachinePasses) + addMachinePostPasses(Banner, /*AllowPrint*/ printAfter, + /*AllowVerify*/ verifyAfter); // Add the passes after the pass P if there is any. for (auto IP : Impl->InsertedPasses) { @@ -606,6 +605,16 @@ void TargetPassConfig::addVerifyPass(const std::string &Banner) { PM->add(createMachineVerifierPass(Banner)); } +void TargetPassConfig::addMachinePrePasses() {} + +void TargetPassConfig::addMachinePostPasses(const std::string &Banner, + bool AllowPrint, bool AllowVerify) { + if (AllowPrint) + addPrintPass(Banner); + if (AllowVerify) + addVerifyPass(Banner); +} + /// Add common target configurable passes that perform LLVM IR to IR transforms /// following machine independent optimization. void TargetPassConfig::addIRPasses() { diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index cd02971..d9da107 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -387,8 +387,9 @@ static bool addPass(PassManagerBase &PM, const char *argv0, return true; } std::string Banner = std::string("After ") + std::string(P->getPassName()); + TPC.addMachinePrePasses(); PM.add(P); - TPC.printAndVerify(Banner); + TPC.addMachinePostPasses(Banner); return false; } -- 2.7.4