[PATCH] D84977: [NewPM] Only verify loop for nonskipped user loop pass

Yuanfang Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 31 09:22:39 PDT 2020


ychen updated this revision to Diff 282246.
ychen added a comment.

- Use non-skipped-pass callback. For wrapped loop pass manager, it is called before each non-skipped loop pass instead of once before the loop pass manager begin to run.
- The introduced push/pop thing could be used elsewhere like MachineVerifier. I think it should work well enough for the use cases we have now and no need to change the callback API everywhere. Thoughts?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84977/new/

https://reviews.llvm.org/D84977

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


Index: llvm/test/Feature/optnone-opt.ll
===================================================================
--- llvm/test/Feature/optnone-opt.ll
+++ llvm/test/Feature/optnone-opt.ll
@@ -34,7 +34,7 @@
   br label %while.cond
 
 while.end:                                        ; preds = %while.cond
-  ret i32 0
+  ret i32 %dec
 }
 
 attributes #0 = { optnone noinline }
Index: llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
===================================================================
--- llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
+++ 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 @@
     // 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 @@
 #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 @@
       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
Index: llvm/include/llvm/IR/PassInstrumentation.h
===================================================================
--- llvm/include/llvm/IR/PassInstrumentation.h
+++ llvm/include/llvm/IR/PassInstrumentation.h
@@ -232,6 +232,14 @@
                   ExtraArgsT...) {
     return false;
   }
+
+  template <typename CallableT>
+  void pushBeforeNonSkippedPassCallback(CallableT C) {
+    Callbacks->BeforeNonSkippedPassCallbacks.emplace_back(std::move(C));
+  }
+  void popBeforeNonSkippedPassCallback() {
+    Callbacks->BeforeNonSkippedPassCallbacks.pop_back();
+  }
 };
 
 bool isSpecialPass(StringRef PassID, const std::vector<StringRef> &Specials);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84977.282246.patch
Type: text/x-patch
Size: 3174 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200731/d7255134/attachment.bin>


More information about the llvm-commits mailing list