[llvm] 954bd9c - [NewPM] Only verify loop for nonskipped user loop pass

Yuanfang Chen via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 7 11:00:57 PDT 2020


Author: Yuanfang Chen
Date: 2020-08-07T11:00:31-07:00
New Revision: 954bd9c861218357977f88b9678c7b1df515e14a

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

LOG: [NewPM] Only verify loop for nonskipped user loop pass

No verification for pass mangers since it is not needed.
No verification for skipped loop pass since the asserted condition is not used.

Add a BeforeNonSkippedPass callback for this. The callback needs more
inputs than its parameters to work so the callback is added on-the-fly.

Reviewed By: aeubanks, asbirlea

Differential Revision: https://reviews.llvm.org/D84977

Added: 
    

Modified: 
    llvm/include/llvm/IR/PassInstrumentation.h
    llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
    llvm/lib/Transforms/Scalar/LoopPassManager.cpp
    llvm/test/Feature/optnone-opt.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/PassInstrumentation.h b/llvm/include/llvm/IR/PassInstrumentation.h
index 8bee51e8d516..137053854fcb 100644
--- a/llvm/include/llvm/IR/PassInstrumentation.h
+++ b/llvm/include/llvm/IR/PassInstrumentation.h
@@ -243,6 +243,16 @@ class PassInstrumentation {
                   ExtraArgsT...) {
     return false;
   }
+
+  template <typename CallableT>
+  void pushBeforeNonSkippedPassCallback(CallableT C) {
+    if (Callbacks)
+      Callbacks->BeforeNonSkippedPassCallbacks.emplace_back(std::move(C));
+  }
+  void popBeforeNonSkippedPassCallback() {
+    if (Callbacks)
+      Callbacks->BeforeNonSkippedPassCallbacks.pop_back();
+  }
 };
 
 bool isSpecialPass(StringRef PassID, const std::vector<StringRef> &Specials);

diff  --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
index aff80ef1dcfa..edc27b7f8a1b 100644
--- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
+++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
@@ -50,6 +50,7 @@
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/IR/Dominators.h"
+#include "llvm/IR/PassInstrumentation.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Transforms/Utils/LCSSA.h"
 #include "llvm/Transforms/Utils/LoopSimplify.h"
@@ -296,6 +297,21 @@ class FunctionToLoopPassAdaptor
     // declaration.
     appendLoopsToWorklist(LI, Worklist);
 
+#ifndef NDEBUG
+    PI.pushBeforeNonSkippedPassCallback([&LAR, &LI](StringRef PassID, Any IR) {
+      if (isSpecialPass(PassID, {"PassManager"}))
+        return;
+      assert(any_isa<const Loop *>(IR));
+      const Loop *L = any_cast<const Loop *>(IR);
+      assert(L && "Loop should be valid for printing");
+
+      // Verify the loop structure and LCSSA form before visiting the loop.
+      L->verifyLoop();
+      assert(L->isRecursivelyLCSSAForm(LAR.DT, LI) &&
+             "Loops must remain in LCSSA form!");
+    });
+#endif
+
     do {
       Loop *L = Worklist.pop_back_val();
 
@@ -306,11 +322,6 @@ class FunctionToLoopPassAdaptor
 #ifndef NDEBUG
       // Save a parent loop pointer for asserts.
       Updater.ParentL = L->getParentLoop();
-
-      // Verify the loop structure and LCSSA form before visiting the loop.
-      L->verifyLoop();
-      assert(L->isRecursivelyLCSSAForm(LAR.DT, LI) &&
-             "Loops must remain in LCSSA form!");
 #endif
       // Check the PassInstrumentation's BeforePass callbacks before running the
       // pass, skip its execution completely if asked to (callback returns
@@ -345,6 +356,10 @@ class FunctionToLoopPassAdaptor
       PA.intersect(std::move(PassPA));
     } while (!Worklist.empty());
 
+#ifndef NDEBUG
+    PI.popBeforeNonSkippedPassCallback();
+#endif
+
     // By definition we preserve the proxy. We also preserve all analyses on
     // Loops. This precludes *any* invalidation of loop analyses by the proxy,
     // but that's OK because we've taken care to invalidate analyses in the

diff  --git a/llvm/lib/Transforms/Scalar/LoopPassManager.cpp b/llvm/lib/Transforms/Scalar/LoopPassManager.cpp
index 91de5715a6ae..2b0ac78f52d2 100644
--- a/llvm/lib/Transforms/Scalar/LoopPassManager.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopPassManager.cpp
@@ -57,13 +57,6 @@ PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
       break;
     }
 
-#ifndef NDEBUG
-    // Verify the loop structure and LCSSA form before visiting the loop.
-    L.verifyLoop();
-    assert(L.isRecursivelyLCSSAForm(AR.DT, AR.LI) &&
-           "Loops must remain in LCSSA form!");
-#endif
-
     // Update the analysis manager as each pass runs and potentially
     // invalidates analyses.
     AM.invalidate(L, PassPA);

diff  --git a/llvm/test/Feature/optnone-opt.ll b/llvm/test/Feature/optnone-opt.ll
index 3af0ce8d0fd0..b9129a0c3745 100644
--- a/llvm/test/Feature/optnone-opt.ll
+++ b/llvm/test/Feature/optnone-opt.ll
@@ -34,7 +34,7 @@ while.body:                                       ; preds = %while.cond
   br label %while.cond
 
 while.end:                                        ; preds = %while.cond
-  ret i32 0
+  ret i32 %dec
 }
 
 attributes #0 = { optnone noinline }


        


More information about the llvm-commits mailing list