[llvm] r268444 - PM: Check that loop passes preserve a basic set of analyses

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Tue May 3 14:35:08 PDT 2016


Author: bogner
Date: Tue May  3 16:35:08 2016
New Revision: 268444

URL: http://llvm.org/viewvc/llvm-project?rev=268444&view=rev
Log:
PM: Check that loop passes preserve a basic set of analyses

A loop pass that didn't preserve this entire set of passes wouldn't
play well with other loop passes, since these are generally a basic
requirement to do any interesting transformations to a loop.

Adds a helper to get the set of analyses a loop pass should preserve,
and checks that any loop pass we run satisfies the requirement.

Modified:
    llvm/trunk/include/llvm/Analysis/LoopPassManager.h
    llvm/trunk/include/llvm/IR/PassManager.h
    llvm/trunk/lib/Analysis/LoopPassManager.cpp
    llvm/trunk/unittests/Analysis/LoopPassManagerTest.cpp

Modified: llvm/trunk/include/llvm/Analysis/LoopPassManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopPassManager.h?rev=268444&r1=268443&r2=268444&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopPassManager.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopPassManager.h Tue May  3 16:35:08 2016
@@ -48,6 +48,9 @@ extern template class OuterAnalysisManag
 typedef OuterAnalysisManagerProxy<FunctionAnalysisManager, Loop>
     FunctionAnalysisManagerLoopProxy;
 
+/// Returns the minimum set of Analyses that all loop passes must preserve.
+PreservedAnalyses getLoopPassPreservedAnalyses();
+
 /// \brief Adaptor that maps from a function to its loops.
 ///
 /// Designed to allow composition of a LoopPass(Manager) and a
@@ -101,6 +104,8 @@ public:
     // post-order.
     for (auto *L : reverse(Loops)) {
       PreservedAnalyses PassPA = Pass.run(*L, LAM);
+      assert(PassPA.preserved(getLoopPassPreservedAnalyses()) &&
+             "Loop passes must preserve all relevant analyses");
 
       // We know that the loop pass couldn't have invalidated any other loop's
       // analyses (that's the contract of a loop pass), so directly handle the

Modified: llvm/trunk/include/llvm/IR/PassManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PassManager.h?rev=268444&r1=268443&r2=268444&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PassManager.h (original)
+++ llvm/trunk/include/llvm/IR/PassManager.h Tue May  3 16:35:08 2016
@@ -144,6 +144,16 @@ public:
            PreservedPassIDs.count(PassID);
   }
 
+  /// \brief Query whether all of the analyses in the set are preserved.
+  bool preserved(PreservedAnalyses Arg) {
+    if (Arg.areAllPreserved())
+      return areAllPreserved();
+    for (void *P : Arg.PreservedPassIDs)
+      if (!preserved(P))
+        return false;
+    return true;
+  }
+
   /// \brief Test whether all passes are preserved.
   ///
   /// This is used primarily to optimize for the case of no changes which will

Modified: llvm/trunk/lib/Analysis/LoopPassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopPassManager.cpp?rev=268444&r1=268443&r2=268444&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopPassManager.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopPassManager.cpp Tue May  3 16:35:08 2016
@@ -8,6 +8,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Analysis/LoopPassManager.h"
+#include "llvm/Analysis/BasicAliasAnalysis.h"
+#include "llvm/Analysis/GlobalsModRef.h"
+#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Analysis/ScalarEvolution.h"
+#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
+#include "llvm/IR/Dominators.h"
 
 using namespace llvm;
 
@@ -18,3 +24,16 @@ template class AnalysisManager<Loop>;
 template class InnerAnalysisManagerProxy<LoopAnalysisManager, Function>;
 template class OuterAnalysisManagerProxy<FunctionAnalysisManager, Loop>;
 }
+
+PreservedAnalyses llvm::getLoopPassPreservedAnalyses() {
+  PreservedAnalyses PA;
+  PA.preserve<DominatorTreeAnalysis>();
+  PA.preserve<LoopAnalysis>();
+  PA.preserve<ScalarEvolutionAnalysis>();
+  // TODO: What we really want to do here is preserve an AA category, but that
+  // concept doesn't exist yet.
+  PA.preserve<BasicAA>();
+  PA.preserve<GlobalsAA>();
+  PA.preserve<SCEVAA>();
+  return PA;
+}

Modified: llvm/trunk/unittests/Analysis/LoopPassManagerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/LoopPassManagerTest.cpp?rev=268444&r1=268443&r2=268444&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/LoopPassManagerTest.cpp (original)
+++ llvm/trunk/unittests/Analysis/LoopPassManagerTest.cpp Tue May  3 16:35:08 2016
@@ -92,7 +92,7 @@ public:
   TestLoopInvalidatingPass(StringRef LoopName) : Name(LoopName) {}
 
   PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &AM) {
-    return L.getName() == Name ? PreservedAnalyses::none()
+    return L.getName() == Name ? getLoopPassPreservedAnalyses()
                                : PreservedAnalyses::all();
   }
 




More information about the llvm-commits mailing list