[PATCH] D132581: [LoopPassManager] Implement and use LoopNestAnalysis::run() instead of manually creating LoopNests

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 2 10:59:53 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG57fd86655161: [LoopPassManager] Implement and use LoopNestAnalysis::run() instead of manually… (authored by aeubanks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132581

Files:
  llvm/lib/Analysis/LoopNestAnalysis.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Scalar/LoopPassManager.cpp
  llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp


Index: llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
===================================================================
--- llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
+++ llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
@@ -301,6 +301,8 @@
     // Register our mock analysis.
     LAM.registerPass([&] { return MLAHandle.getAnalysis(); });
 
+    LAM.registerPass([&] { return LoopNestAnalysis(); });
+
     // We need DominatorTreeAnalysis for LoopAnalysis.
     FAM.registerPass([&] { return DominatorTreeAnalysis(); });
     FAM.registerPass([&] { return LoopAnalysis(); });
Index: llvm/lib/Transforms/Scalar/LoopPassManager.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopPassManager.cpp
+++ llvm/lib/Transforms/Scalar/LoopPassManager.cpp
@@ -78,13 +78,6 @@
 
   unsigned LoopPassIndex = 0, LoopNestPassIndex = 0;
 
-  // `LoopNestPtr` points to the `LoopNest` object for the current top-level
-  // loop and `IsLoopNestPtrValid` indicates whether the pointer is still valid.
-  // The `LoopNest` object will have to be re-constructed if the pointer is
-  // invalid when encountering a loop-nest pass.
-  std::unique_ptr<LoopNest> LoopNestPtr;
-  bool IsLoopNestPtrValid = false;
-
   for (size_t I = 0, E = IsLoopNestPass.size(); I != E; ++I) {
     Optional<PreservedAnalyses> PassPA;
     if (!IsLoopNestPass[I]) {
@@ -95,13 +88,8 @@
       // The `I`-th pass is a loop-nest pass.
       auto &Pass = LoopNestPasses[LoopNestPassIndex++];
 
-      // If the loop-nest object calculated before is no longer valid,
-      // re-calculate it here before running the loop-nest pass.
-      if (!IsLoopNestPtrValid) {
-        LoopNestPtr = LoopNest::getLoopNest(L, AR.SE);
-        IsLoopNestPtrValid = true;
-      }
-      PassPA = runSinglePass(*LoopNestPtr, Pass, AM, AR, U, PI);
+      LoopNest &LN = AM.getResult<LoopNestAnalysis>(L, AR);
+      PassPA = runSinglePass(LN, Pass, AM, AR, U, PI);
     }
 
     // `PassPA` is `None` means that the before-pass callbacks in
@@ -124,9 +112,6 @@
     // aggregate preserved set for this pass manager.
     PA.intersect(std::move(*PassPA));
 
-    // Check if the current pass preserved the loop-nest object or not.
-    IsLoopNestPtrValid &= PassPA->getChecker<LoopNestAnalysis>().preserved();
-
     // After running the loop pass, the parent loop might change and we need to
     // notify the updater, otherwise U.ParentL might gets outdated and triggers
     // assertion failures in addSiblingLoops and addChildLoops.
Index: llvm/lib/Passes/PassRegistry.def
===================================================================
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -499,6 +499,7 @@
 LOOP_ANALYSIS("ddg", DDGAnalysis())
 LOOP_ANALYSIS("iv-users", IVUsersAnalysis())
 LOOP_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
+LOOP_ANALYSIS("loop-nest", LoopNestAnalysis())
 #undef LOOP_ANALYSIS
 
 #ifndef LOOP_PASS
Index: llvm/lib/Analysis/LoopNestAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/LoopNestAnalysis.cpp
+++ llvm/lib/Analysis/LoopNestAnalysis.cpp
@@ -450,6 +450,12 @@
   return OS;
 }
 
+LoopNestAnalysis::Result
+LoopNestAnalysis::run(Loop &L, LoopAnalysisManager &AM,
+                      LoopStandardAnalysisResults &AR) {
+  return LoopNest(L, AR.SE);
+}
+
 //===----------------------------------------------------------------------===//
 // LoopNestPrinterPass implementation
 //


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132581.457642.patch
Type: text/x-patch
Size: 3560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220902/10a7b919/attachment.bin>


More information about the llvm-commits mailing list