llvm.org GIT mirror llvm / ddcc2ba
[AliasAnalysis/NewPassManager] Invalidate AAManager less often. Summary: This is a redo of D60914. The objective is to not invalidate AAManager, which is stateless, unless there is an explicit invalidate in one of the AAResults. To achieve this, this patch adds an API to PAC, to check precisely this: is this analysis not invalidated explicitly == is this analysis not abandoned == is this analysis stateless, so preserved without explicitly being marked as preserved by everyone Reviewers: chandlerc Subscribers: mehdi_amini, jlebar, george.burgess.iv, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61284 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359622 91177308-0d34-0410-b5e6-96231b3b80d8 Alina Sbirlea 3 months ago
6 changed file(s) with 24 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
10951095 /// This manager effectively wraps the AnalysisManager for registering alias
10961096 /// analyses. When you register your alias analysis with this manager, it will
10971097 /// ensure the analysis itself is registered with its AnalysisManager.
1098 ///
1099 /// The result of this analysis is only invalidated if one of the particular
1100 /// aggregated AA results end up being invalidated. This removes the need to
1101 /// explicitly preserve the results of `AAManager`. Note that analyses should no
1102 /// longer be registered once the `AAManager` is run.
10981103 class AAManager : public AnalysisInfoMixin {
10991104 public:
11001105 using Result = AAResults;
283283 bool preserved() {
284284 return !IsAbandoned && (PA.PreservedIDs.count(&AllAnalysesKey) ||
285285 PA.PreservedIDs.count(ID));
286 }
287
288 /// Return true if the checker's analysis was not abandoned, i.e. it was not
289 /// explicitly invalidated. Even if the analysis is not explicitly
290 /// preserved, if the analysis is known stateless, then it is preserved.
291 bool preservedWhenStateless() {
292 return !IsAbandoned;
286293 }
287294
288295 /// Returns true if the checker's analysis was not abandoned and either
7878
7979 bool AAResults::invalidate(Function &F, const PreservedAnalyses &PA,
8080 FunctionAnalysisManager::Invalidator &Inv) {
81 // Check if the AA manager itself has been invalidated.
81 // AAResults preserves the AAManager by default, due to the stateless nature
82 // of AliasAnalysis. There is no need to check whether it has been preserved
83 // explicitly. Check if any module dependency was invalidated and caused the
84 // AAManager to be invalidated. Invalidate ourselves in that case.
8285 auto PAC = PA.getChecker();
83 if (!PAC.preserved() && !PAC.preservedSet>())
84 return true; // The manager needs to be blown away, clear everything.
85
86 // Check all of the dependencies registered.
86 if (!PAC.preservedWhenStateless())
87 return true;
88
89 // Check if any of the function dependencies were invalidated, and invalidate
90 // ourselves in that case.
8791 for (AnalysisKey *ID : AADeps)
8892 if (Inv.invalidate(ID, F, PA))
8993 return true;
0 ; Test that memdep gets invalidated when the analyses it depends on are
11 ; invalidated.
22 ;
3 ; Check AA specifically.
3 ; Check AA. AA is stateless, there's nothing to invalidate.
44 ; RUN: opt -disable-output -debug-pass-manager -aa-pipeline='basic-aa' %s 2>&1 \
55 ; RUN: -passes='require,invalidate,gvn' \
66 ; RUN: | FileCheck %s --check-prefix=CHECK-AA-INVALIDATE
77 ; CHECK-AA-INVALIDATE: Running pass: RequireAnalysisPass
88 ; CHECK-AA-INVALIDATE: Running analysis: MemoryDependenceAnalysis
99 ; CHECK-AA-INVALIDATE: Running pass: InvalidateAnalysisPass
10 ; CHECK-AA-INVALIDATE: Invalidating analysis: AAManager
11 ; CHECK-AA-INVALIDATE: Invalidating analysis: MemoryDependenceAnalysis
10 ; CHECK-NOT-AA-INVALIDATE: Invalidating analysis: MemoryDependenceAnalysis
1211 ; CHECK-AA-INVALIDATE: Running pass: GVN
13 ; CHECK-AA-INVALIDATE: Running analysis: MemoryDependenceAnalysis
12 ; CHECK-NOT-AA-INVALIDATE: Running analysis: MemoryDependenceAnalysis
1413 ;
1514 ; Check domtree specifically.
1615 ; RUN: opt -disable-output -debug-pass-manager %s 2>&1 \
354354 ; CHECK-AA-MODULE-INVALIDATE: Running analysis: AAManager
355355 ; CHECK-AA-MODULE-INVALIDATE: Finished llvm::Function pass manager run
356356 ; CHECK-AA-MODULE-INVALIDATE: Running pass: InvalidateAnalysisPass
357 ; CHECK-AA-MODULE-INVALIDATE: Invalidating analysis: AAManager
358357 ; CHECK-AA-MODULE-INVALIDATE: Invalidating analysis: GlobalsAA
359358 ; CHECK-AA-MODULE-INVALIDATE: Running pass: RequireAnalysisPass
360359 ; CHECK-AA-MODULE-INVALIDATE: Running analysis: GlobalsAA
361360 ; CHECK-AA-MODULE-INVALIDATE: Starting llvm::Function pass manager run
362361 ; CHECK-AA-MODULE-INVALIDATE: Running pass: AAEvaluator
363 ; CHECK-AA-MODULE-INVALIDATE: Running analysis: AAManager
364362 ; CHECK-AA-MODULE-INVALIDATE: Finished llvm::Function pass manager run
365363 ; CHECK-AA-MODULE-INVALIDATE: Finished llvm::Module pass manager run
366364
571571 // invalidation and running.
572572 EXPECT_CALL(MFPHandle, run(HasName("f"), _))
573573 .WillOnce(Return(getLoopPassPreservedAnalyses()));
574 EXPECT_CALL(MLAHandle, invalidate(_, _, _)).Times(3);
575574 EXPECT_CALL(MLAHandle, run(HasName("loop.0.0"), _, _));
576575 EXPECT_CALL(MLAHandle, run(HasName("loop.0.1"), _, _));
577576 EXPECT_CALL(MLAHandle, run(HasName("loop.0"), _, _));