llvm.org GIT mirror llvm / b09bd97
[PM] Teach BasicAA how to invalidate its result object. This requires custom handling because BasicAA caches handles to other analyses and so it needs to trigger indirect invalidation. This fixes one of the common crashes when using the new PM in real pipelines. I've also tweaked a regression test to check that we are at least handling the most immediate case. I'm going to work at re-structuring this test some to both scale better (rather than all being in one file) and check more invalidation paths in a follow-up commit, but I wanted to get the basic bug fix in place. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290603 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 2 years ago
3 changed file(s) with 28 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
3232
3333 /// This is the AA result object for the basic, local, and stateless alias
3434 /// analysis. It implements the AA query interface in an entirely stateless
35 /// manner. As one consequence, it is never invalidated. While it does retain
36 /// some storage, that is used as an optimization and not to preserve
37 /// information from query to query.
35 /// manner. As one consequence, it is never invalidated due to IR changes.
36 /// While it does retain some storage, that is used as an optimization and not
37 /// to preserve information from query to query. However it does retain handles
38 /// to various other analyses and must be recomputed when those analyses are.
3839 class BasicAAResult : public AAResultBase {
3940 friend AAResultBase;
4041
5657 BasicAAResult(BasicAAResult &&Arg)
5758 : AAResultBase(std::move(Arg)), DL(Arg.DL), TLI(Arg.TLI), AC(Arg.AC),
5859 DT(Arg.DT), LI(Arg.LI) {}
60
61 /// Handle invalidation events in the new pass manager.
62 bool invalidate(Function &F, const PreservedAnalyses &PA,
63 FunctionAnalysisManager::Invalidator &Inv);
5964
6065 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
6166
6161 // GetUnderlyingObject(), both functions need to use the same search
6262 // depth otherwise the algorithm in aliasGEP will assert.
6363 static const unsigned MaxLookupSearchDepth = 6;
64
65 bool BasicAAResult::invalidate(Function &F, const PreservedAnalyses &PA,
66 FunctionAnalysisManager::Invalidator &Inv) {
67 if (PA.areAllPreserved())
68 return false; // Nothing to do, everything is still valid.
69
70 // We don't care if this analysis itself is preserved, it has no state. But
71 // we need to check that the analyses it depends on have been. Note that we
72 // may be created without handles to some analyses and in that case don't
73 // depend on them.
74 if (Inv.invalidate(F, PA) ||
75 (DT && Inv.invalidate(F, PA)) ||
76 (LI && Inv.invalidate(F, PA)))
77 return true;
78
79 // Otherwise this analysis result remains valid.
80 return false;
81 }
6482
6583 //===----------------------------------------------------------------------===//
6684 // Useful predicates
324324 ; CHECK-AA-DEFAULT: Finished llvm::Module pass manager run
325325
326326 ; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
327 ; RUN: -passes='require,invalidate<basic-aa>,aa-eval' -aa-pipeline='basic-aa' \
327 ; RUN: -passes='require,invalidate<domtree>,aa-eval' -aa-pipeline='basic-aa' \
328328 ; RUN: | FileCheck %s --check-prefix=CHECK-AA-FUNCTION-INVALIDATE
329329 ; CHECK-AA-FUNCTION-INVALIDATE: Starting llvm::Function pass manager run
330330 ; CHECK-AA-FUNCTION-INVALIDATE: Running pass: RequireAnalysisPass
331331 ; CHECK-AA-FUNCTION-INVALIDATE: Running analysis: AAManager
332332 ; CHECK-AA-FUNCTION-INVALIDATE: Running analysis: BasicAA
333333 ; CHECK-AA-FUNCTION-INVALIDATE: Running pass: InvalidateAnalysisPass
334 ; CHECK-AA-FUNCTION-INVALIDATE: Invalidating analysis: DominatorTreeAnalysis
334335 ; CHECK-AA-FUNCTION-INVALIDATE: Invalidating analysis: BasicAA
335336 ; CHECK-AA-FUNCTION-INVALIDATE: Invalidating analysis: AAManager
336337 ; CHECK-AA-FUNCTION-INVALIDATE: Running pass: AAEvaluator