[llvm] 7e3aa8f - Revert "[LoopPassManager] Implement and use LoopNestAnalysis::run() instead of manually creating LoopNests"

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 5 15:43:18 PDT 2022


Author: Arthur Eubanks
Date: 2022-09-05T15:42:48-07:00
New Revision: 7e3aa8f01a31bcf9a9cafc79594b3b8b950532f2

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

LOG: Revert "[LoopPassManager] Implement and use LoopNestAnalysis::run() instead of manually creating LoopNests"

This reverts commit 57fd8665516161c3d2dbe3f0ad8461552967692a.

Causes crashes, see comments in D132581.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/LoopNestAnalysis.cpp b/llvm/lib/Analysis/LoopNestAnalysis.cpp
index 17c3bc7fb75a8..bff796f339ab8 100644
--- a/llvm/lib/Analysis/LoopNestAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopNestAnalysis.cpp
@@ -450,12 +450,6 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const LoopNest &LN) {
   return OS;
 }
 
-LoopNestAnalysis::Result
-LoopNestAnalysis::run(Loop &L, LoopAnalysisManager &AM,
-                      LoopStandardAnalysisResults &AR) {
-  return LoopNest(L, AR.SE);
-}
-
 //===----------------------------------------------------------------------===//
 // LoopNestPrinterPass implementation
 //

diff  --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index a4bbe9d62db84..a6aa06c1be5c8 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -499,7 +499,6 @@ LOOP_ANALYSIS("access-info", LoopAccessAnalysis())
 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

diff  --git a/llvm/lib/Transforms/Scalar/LoopPassManager.cpp b/llvm/lib/Transforms/Scalar/LoopPassManager.cpp
index 82a44d5436ddf..d20d275ea60c4 100644
--- a/llvm/lib/Transforms/Scalar/LoopPassManager.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopPassManager.cpp
@@ -78,6 +78,13 @@ LoopPassManager::runWithLoopNestPasses(Loop &L, LoopAnalysisManager &AM,
 
   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]) {
@@ -88,8 +95,13 @@ LoopPassManager::runWithLoopNestPasses(Loop &L, LoopAnalysisManager &AM,
       // The `I`-th pass is a loop-nest pass.
       auto &Pass = LoopNestPasses[LoopNestPassIndex++];
 
-      LoopNest &LN = AM.getResult<LoopNestAnalysis>(L, AR);
-      PassPA = runSinglePass(LN, Pass, AM, AR, U, PI);
+      // 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);
     }
 
     // `PassPA` is `None` means that the before-pass callbacks in
@@ -112,6 +124,9 @@ LoopPassManager::runWithLoopNestPasses(Loop &L, LoopAnalysisManager &AM,
     // 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.

diff  --git a/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp b/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
index 16bb10f41efa9..bdabc34decf85 100644
--- a/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
+++ b/llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp
@@ -301,8 +301,6 @@ class LoopPassManagerTest : public ::testing::Test {
     // 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(); });


        


More information about the llvm-commits mailing list