[PATCH] D102463: Making Instrumentation aware of LoopNest Pass

Raghesh Aloor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 20 08:00:10 PDT 2021


raghesh updated this revision to Diff 346739.
raghesh added a comment.

Made the suggested change. Added a simple testcase which uses -print-after for LoopInterchange pass (a LoopNest pass). This would crash without this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102463

Files:
  llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
  llvm/test/Other/loopnest-callback.ll


Index: llvm/test/Other/loopnest-callback.ll
===================================================================
--- /dev/null
+++ llvm/test/Other/loopnest-callback.ll
@@ -0,0 +1,11 @@
+;RUN: opt -disable-output -loop-interchange \
+;RUN:      -print-after=loop-interchange < %s 2>&1 |\
+;RUN:      FileCheck --check-prefix=CHECK %s
+
+; CHECK: IR Dump After LoopInterchangePass
+define void @foo() {
+entry:
+  br label %for.cond
+for.cond:
+  br label %for.cond
+}
Index: llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
===================================================================
--- llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
+++ llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
@@ -183,6 +183,10 @@
   PreservedAnalyses runWithoutLoopNestPasses(Loop &L, LoopAnalysisManager &AM,
                                              LoopStandardAnalysisResults &AR,
                                              LPMUpdater &U);
+
+private:
+  const Loop &getLoopFromIR(Loop &L) { return L; }
+  const Loop &getLoopFromIR(LoopNest &LN) { return LN.getOutermostLoop(); }
 };
 
 /// The Loop pass manager.
@@ -358,9 +362,12 @@
 Optional<PreservedAnalyses> LoopPassManager::runSinglePass(
     IRUnitT &IR, PassT &Pass, LoopAnalysisManager &AM,
     LoopStandardAnalysisResults &AR, LPMUpdater &U, PassInstrumentation &PI) {
+  // Get the loop in case of Loop pass and outermost loop in case of LoopNest
+  // pass which is to be passed to BeforePass and AfterPass call backs.
+  const Loop &L = getLoopFromIR(IR);
   // Check the PassInstrumentation's BeforePass callbacks before running the
   // pass, skip its execution completely if asked to (callback returns false).
-  if (!PI.runBeforePass<IRUnitT>(*Pass, IR))
+  if (!PI.runBeforePass<Loop>(*Pass, L))
     return None;
 
   PreservedAnalyses PA;
@@ -373,7 +380,7 @@
   if (U.skipCurrentLoop())
     PI.runAfterPassInvalidated<IRUnitT>(*Pass, PA);
   else
-    PI.runAfterPass<IRUnitT>(*Pass, IR, PA);
+    PI.runAfterPass<Loop>(*Pass, L, PA);
   return PA;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102463.346739.patch
Type: text/x-patch
Size: 2043 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210520/afb533ba/attachment.bin>


More information about the llvm-commits mailing list