[AliasAnalysis] Second prototype to cache BasicAA / anyAA state.
Summary:
Adding contained caching to AliasAnalysis. BasicAA is currently the only one using it.
AA changes:
- This patch is pulling the caches from BasicAAResults to AAResults, meaning the getModRefInfo call benefits from the IsCapturedCache as well when in "batch mode".
- All AAResultBase implementations add the QueryInfo member to all APIs. AAResults APIs maintain wrapper APIs such that all alias()/getModRefInfo call sites are unchanged.
- AA now provides a BatchAAResults type as a wrapper to AAResults. It keeps the AAResults instance and a QueryInfo instantiated to batch mode. It delegates all work to the AAResults instance with the batched QueryInfo. More API wrappers may be needed in BatchAAResults; only the minimum needed is currently added.
MemorySSA changes:
- All walkers are now templated on the AA used (AliasAnalysis=AAResults or BatchAAResults).
- At build time, we optimize uses; now we create a local walker (lives only as long as OptimizeUses does) using BatchAAResults.
- All Walkers have an internal AA and only use that now, never the AA in MemorySSA. The Walkers receive the AA they will use when built.
- The walker we use for queries after the build is instantiated on AliasAnalysis and is built after building MemorySSA and setting AA.
- All static methods doing walking are now templated on AliasAnalysisType if they are used both during build and after. If used only during build, the method now only takes a BatchAAResults. If used only after build, the method now takes an AliasAnalysis.
Subscribers: sanjoy, arsenm, jvesely, nhaehnle, jlebar, george.burgess.iv, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59315
llvm-svn: 356783
diff --git a/llvm/unittests/Analysis/BasicAliasAnalysisTest.cpp b/llvm/unittests/Analysis/BasicAliasAnalysisTest.cpp
index 068774c..f69d2d1 100644
--- a/llvm/unittests/Analysis/BasicAliasAnalysisTest.cpp
+++ b/llvm/unittests/Analysis/BasicAliasAnalysisTest.cpp
@@ -44,17 +44,19 @@
DominatorTree DT;
AssumptionCache AC;
BasicAAResult BAA;
+ AAQueryInfo AAQI;
TestAnalyses(BasicAATest &Test)
- : DT(*Test.F), AC(*Test.F), BAA(Test.DL, *Test.F, Test.TLI, AC, &DT) {}
+ : DT(*Test.F), AC(*Test.F), BAA(Test.DL, *Test.F, Test.TLI, AC, &DT),
+ AAQI() {}
};
llvm::Optional<TestAnalyses> Analyses;
- BasicAAResult &setupAnalyses() {
+ TestAnalyses &setupAnalyses() {
assert(F);
Analyses.emplace(*this);
- return Analyses->BAA;
+ return Analyses.getValue();
}
public:
@@ -83,15 +85,17 @@
GlobalPtr->setLinkage(GlobalValue::LinkageTypes::InternalLinkage);
GlobalPtr->setInitializer(B.getInt8(0));
- BasicAAResult &BasicAA = setupAnalyses();
+ auto &AllAnalyses = setupAnalyses();
+ BasicAAResult &BasicAA = AllAnalyses.BAA;
+ AAQueryInfo &AAQI = AllAnalyses.AAQI;
ASSERT_EQ(
BasicAA.alias(MemoryLocation(IncomingI32Ptr, LocationSize::precise(4)),
- MemoryLocation(GlobalPtr, LocationSize::precise(1))),
+ MemoryLocation(GlobalPtr, LocationSize::precise(1)), AAQI),
AliasResult::NoAlias);
ASSERT_EQ(
BasicAA.alias(MemoryLocation(IncomingI32Ptr, LocationSize::upperBound(4)),
- MemoryLocation(GlobalPtr, LocationSize::precise(1))),
+ MemoryLocation(GlobalPtr, LocationSize::precise(1)), AAQI),
AliasResult::MayAlias);
}
@@ -110,14 +114,18 @@
auto *I8AtUncertainOffset =
cast<GetElementPtrInst>(B.CreateGEP(B.getInt8Ty(), I8, ArbitraryI32));
- BasicAAResult &BasicAA = setupAnalyses();
+ auto &AllAnalyses = setupAnalyses();
+ BasicAAResult &BasicAA = AllAnalyses.BAA;
+ AAQueryInfo &AAQI = AllAnalyses.AAQI;
ASSERT_EQ(BasicAA.alias(
MemoryLocation(I8, LocationSize::precise(2)),
- MemoryLocation(I8AtUncertainOffset, LocationSize::precise(1))),
+ MemoryLocation(I8AtUncertainOffset, LocationSize::precise(1)),
+ AAQI),
AliasResult::PartialAlias);
ASSERT_EQ(BasicAA.alias(
MemoryLocation(I8, LocationSize::upperBound(2)),
- MemoryLocation(I8AtUncertainOffset, LocationSize::precise(1))),
+ MemoryLocation(I8AtUncertainOffset, LocationSize::precise(1)),
+ AAQI),
AliasResult::MayAlias);
}