[llvm] a2ae145 - Making Instrumentation aware of LoopNest Pass

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon May 24 20:26:22 PDT 2021


Author: Arthur Eubanks
Date: 2021-05-24T20:25:52-07:00
New Revision: a2ae14514a26bda6d8dae11e56f3186931b8d8c7

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

LOG: Making Instrumentation aware of LoopNest Pass

Intrumentation callbacks are not made aware of LoopNest passes. From the loop pass manager, we can pass the outermost loop of the LoopNest to instrumentation in case of LoopNest passes.

The current patch made the change in two places in StandardInstrumentation.cpp. I will submit a proper patch where the OuterMostLoop is passed from the LoopPassManager to the call backs. That way we will avoid making changes at multiple places in StandardInstrumentation.cpp.

A testcase also will be submitted.

Reviewed By: aeubanks

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

Added: 
    llvm/test/Other/loopnest-callback.ll

Modified: 
    llvm/include/llvm/Transforms/Scalar/LoopPassManager.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
index b7388dbb4569f..c3833f3635339 100644
--- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
+++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
@@ -183,6 +183,12 @@ class PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
   PreservedAnalyses runWithoutLoopNestPasses(Loop &L, LoopAnalysisManager &AM,
                                              LoopStandardAnalysisResults &AR,
                                              LPMUpdater &U);
+
+private:
+  static const Loop &getLoopFromIR(Loop &L) { return L; }
+  static const Loop &getLoopFromIR(LoopNest &LN) {
+    return LN.getOutermostLoop();
+  }
 };
 
 /// The Loop pass manager.
@@ -358,9 +364,12 @@ template <typename IRUnitT, typename PassT>
 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 +382,7 @@ Optional<PreservedAnalyses> LoopPassManager::runSinglePass(
   if (U.skipCurrentLoop())
     PI.runAfterPassInvalidated<IRUnitT>(*Pass, PA);
   else
-    PI.runAfterPass<IRUnitT>(*Pass, IR, PA);
+    PI.runAfterPass<Loop>(*Pass, L, PA);
   return PA;
 }
 

diff  --git a/llvm/test/Other/loopnest-callback.ll b/llvm/test/Other/loopnest-callback.ll
new file mode 100644
index 0000000000000..645e0ee30a70b
--- /dev/null
+++ b/llvm/test/Other/loopnest-callback.ll
@@ -0,0 +1,9 @@
+;RUN: opt -disable-output -passes=loop-interchange -print-after-all < %s 2>&1 | FileCheck %s
+
+; CHECK: IR Dump After LoopInterchangePass
+define void @foo() {
+entry:
+  br label %for.cond
+for.cond:
+  br label %for.cond
+}


        


More information about the llvm-commits mailing list