[PM] Don't run the machinery of invalidating all the analysis passes
authorChandler Carruth <chandlerc@gmail.com>
Mon, 5 Jan 2015 12:32:11 +0000 (12:32 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 5 Jan 2015 12:32:11 +0000 (12:32 +0000)
when all are being preserved.

We want to short-circuit this for a couple of reasons. One, I don't
really want passes to grow a dependency on actually receiving their
invalidate call when they've been preserved. I'm thinking about removing
this entirely. But more importantly, preserving everything is likely to
be the common case in a lot of scenarios, and it would be really good to
bypass all of the invalidation and preservation machinery there.
Avoiding calling N opaque functions to try to invalidate things that are
by definition still valid seems important. =]

This wasn't really inpsired by much other than seeing the spam in the
logging for analyses, but it seems better ot get it checked in rather
than forgetting about it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225163 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/PassManager.h
lib/Analysis/CGSCCPassManager.cpp
lib/IR/PassManager.cpp
test/Other/new-pass-manager.ll

index b2bf73ffe8b4b5d5af93bd41ad31fefe3a82cf60..59855b5fc91c845f1788aa40bb6694fe4a56c2d7 100644 (file)
@@ -141,15 +141,19 @@ public:
            PreservedPassIDs.count(PassID);
   }
 
+  /// \brief Test whether all passes are preserved.
+  ///
+  /// This is used primarily to optimize for the case of no changes which will
+  /// common in many scenarios.
+  bool areAllPreserved() const {
+    return PreservedPassIDs.count((void *)AllPassesID);
+  }
+
 private:
   // Note that this must not be -1 or -2 as those are already used by the
   // SmallPtrSet.
   static const uintptr_t AllPassesID = (intptr_t)(-3);
 
-  bool areAllPreserved() const {
-    return PreservedPassIDs.count((void *)AllPassesID);
-  }
-
   SmallPtrSet<void *, 2> PreservedPassIDs;
 };
 
index 4d569a972fe999ab5e3dc786f033297590c6fd26..ad7eea8efca521e756b4116eb29c3235cd1d7c57 100644 (file)
@@ -92,6 +92,10 @@ void CGSCCAnalysisManager::invalidateImpl(void *PassID, LazyCallGraph::SCC &C) {
 
 void CGSCCAnalysisManager::invalidateImpl(LazyCallGraph::SCC &C,
                                           const PreservedAnalyses &PA) {
+  // Short circuit for a common case of all analyses being preserved.
+  if (PA.areAllPreserved())
+    return;
+
   if (DebugPM)
     dbgs() << "Invalidating all non-preserved analyses for SCC: " << C.getName()
            << "\n";
index c7638bb7fce3f7da5944debf6d655ea1c7331a11..1eab4ae19bf37619cfc90f52644ea65cca3e946a 100644 (file)
@@ -78,6 +78,10 @@ void ModuleAnalysisManager::invalidateImpl(void *PassID, Module &M) {
 
 void ModuleAnalysisManager::invalidateImpl(Module &M,
                                            const PreservedAnalyses &PA) {
+  // Short circuit for a common case of all analyses being preserved.
+  if (PA.areAllPreserved())
+    return;
+
   if (DebugPM)
     dbgs() << "Invalidating all non-preserved analyses for module: "
            << M.getModuleIdentifier() << "\n";
@@ -176,6 +180,10 @@ void FunctionAnalysisManager::invalidateImpl(void *PassID, Function &F) {
 
 void FunctionAnalysisManager::invalidateImpl(Function &F,
                                              const PreservedAnalyses &PA) {
+  // Short circuit for a common case of all analyses being preserved.
+  if (PA.areAllPreserved())
+    return;
+
   if (DebugPM)
     dbgs() << "Invalidating all non-preserved analyses for function: "
            << F.getName() << "\n";
index f9fc444dbf10f76376975c373013f560c0e96bd7..bb338d42253afdef6dac5694458fddb3cb0cd31e 100644 (file)
 ; CHECK-LCG-ANALYSIS: Running module analysis: Lazy CallGraph Analysis
 ; CHECK-LCG-ANALYSIS: Starting CGSCC pass manager run.
 
+; Make sure no-op passes that preserve all analyses don't even try to do any
+; analysis invalidation.
+; RUN: opt -disable-output -debug-pass-manager -debug-cgscc-pass-manager -passes='cgscc(function(no-op-function))' %s 2>&1 \
+; RUN:     | FileCheck %s --check-prefix=CHECK-NO-OP-INVALIDATION
+; CHECK-NO-OP-INVALIDATION: Starting module pass manager
+; CHECK-NO-OP-INVALIDATION-NOT: Invalidating all non-preserved analyses
+
 define void @foo() {
   ret void
 }