[llvm] c162bc2 - Make TargetPassConfig and llc add pre/post passes the same way. NFC

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 13:47:05 PDT 2020


Author: Daniel Sanders
Date: 2020-04-10T13:46:53-07:00
New Revision: c162bc2aedbe7412a56063cd2284d1c7b1858f05

URL: https://github.com/llvm/llvm-project/commit/c162bc2aedbe7412a56063cd2284d1c7b1858f05
DIFF: https://github.com/llvm/llvm-project/commit/c162bc2aedbe7412a56063cd2284d1c7b1858f05.diff

LOG: 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

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/TargetPassConfig.h
    llvm/lib/CodeGen/TargetPassConfig.cpp
    llvm/tools/llc/llc.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/TargetPassConfig.h b/llvm/include/llvm/CodeGen/TargetPassConfig.h
index d48fc664c1c3..f84e85c5c8f9 100644
--- a/llvm/include/llvm/CodeGen/TargetPassConfig.h
+++ b/llvm/include/llvm/CodeGen/TargetPassConfig.h
@@ -306,6 +306,15 @@ class TargetPassConfig : public ImmutablePass {
   /// 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 44c326ecba8f..448a08728e3f 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 cd02971b2494..d9da1073f1b7 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;
 }


        


More information about the llvm-commits mailing list