[llvm] r225163 - [PM] Don't run the machinery of invalidating all the analysis passes
Chandler Carruth
chandlerc at gmail.com
Mon Jan 5 04:32:11 PST 2015
Author: chandlerc
Date: Mon Jan 5 06:32:11 2015
New Revision: 225163
URL: http://llvm.org/viewvc/llvm-project?rev=225163&view=rev
Log:
[PM] Don't run the machinery of invalidating all the analysis passes
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.
Modified:
llvm/trunk/include/llvm/IR/PassManager.h
llvm/trunk/lib/Analysis/CGSCCPassManager.cpp
llvm/trunk/lib/IR/PassManager.cpp
llvm/trunk/test/Other/new-pass-manager.ll
Modified: llvm/trunk/include/llvm/IR/PassManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PassManager.h?rev=225163&r1=225162&r2=225163&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PassManager.h (original)
+++ llvm/trunk/include/llvm/IR/PassManager.h Mon Jan 5 06:32:11 2015
@@ -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;
};
Modified: llvm/trunk/lib/Analysis/CGSCCPassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CGSCCPassManager.cpp?rev=225163&r1=225162&r2=225163&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CGSCCPassManager.cpp (original)
+++ llvm/trunk/lib/Analysis/CGSCCPassManager.cpp Mon Jan 5 06:32:11 2015
@@ -92,6 +92,10 @@ void CGSCCAnalysisManager::invalidateImp
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";
Modified: llvm/trunk/lib/IR/PassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/PassManager.cpp?rev=225163&r1=225162&r2=225163&view=diff
==============================================================================
--- llvm/trunk/lib/IR/PassManager.cpp (original)
+++ llvm/trunk/lib/IR/PassManager.cpp Mon Jan 5 06:32:11 2015
@@ -78,6 +78,10 @@ void ModuleAnalysisManager::invalidateIm
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::invalidate
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";
Modified: llvm/trunk/test/Other/new-pass-manager.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/new-pass-manager.ll?rev=225163&r1=225162&r2=225163&view=diff
==============================================================================
--- llvm/trunk/test/Other/new-pass-manager.ll (original)
+++ llvm/trunk/test/Other/new-pass-manager.ll Mon Jan 5 06:32:11 2015
@@ -94,6 +94,13 @@
; 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
}
More information about the llvm-commits
mailing list