[llvm] 191e469 - [AA] Move Depth member from AAResults to AAQI (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 12 12:42:49 PST 2021
Author: Nikita Popov
Date: 2021-02-12T21:42:36+01:00
New Revision: 191e469edee619f578076d775ce1ca19c9ecc103
URL: https://github.com/llvm/llvm-project/commit/191e469edee619f578076d775ce1ca19c9ecc103
DIFF: https://github.com/llvm/llvm-project/commit/191e469edee619f578076d775ce1ca19c9ecc103.diff
LOG: [AA] Move Depth member from AAResults to AAQI (NFC)
Rather than storing the query depth in AAResults, store it in AAQI.
This makes more sense, as it is a property of the query. This
sidesteps the issue of D94363, fixing slightly inaccurate AA
statistics. Additionally, I plan to use the Depth from BasicAA in
the future, where fetching it from AAResults would be unreliable.
This change is not quite as straightforward as it seems, because
we need to preserve the depth when creating a new AAQI for recursive
queries across phis. I'm adding a new method for this, as we may
need to preserve additional information here in the future.
Added:
Modified:
llvm/include/llvm/Analysis/AliasAnalysis.h
llvm/lib/Analysis/AliasAnalysis.cpp
llvm/lib/Analysis/BasicAliasAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h
index 9f7461243f35..59963bcde6f9 100644
--- a/llvm/include/llvm/Analysis/AliasAnalysis.h
+++ b/llvm/include/llvm/Analysis/AliasAnalysis.h
@@ -360,6 +360,9 @@ class AAQueryInfo {
using IsCapturedCacheT = SmallDenseMap<const Value *, bool, 8>;
IsCapturedCacheT IsCapturedCache;
+ /// Query depth used to distinguish recursive queries.
+ unsigned Depth = 0;
+
/// How many active NoAlias assumption uses there are.
int NumAssumptionUses = 0;
@@ -369,6 +372,15 @@ class AAQueryInfo {
SmallVector<AAQueryInfo::LocPair, 4> AssumptionBasedResults;
AAQueryInfo() : AliasCache(), IsCapturedCache() {}
+
+ /// Create a new AAQueryInfo based on this one, but with the cache cleared.
+ /// This is used for recursive queries across phis, where cache results may
+ /// not be valid.
+ AAQueryInfo withEmptyCache() {
+ AAQueryInfo NewAAQI;
+ NewAAQI.Depth = Depth;
+ return NewAAQI;
+ }
};
class BatchAAResults;
@@ -797,9 +809,6 @@ class AAResults {
std::vector<AnalysisKey *> AADeps;
- /// Query depth used to distinguish recursive queries.
- unsigned Depth = 0;
-
friend class BatchAAResults;
};
diff --git a/llvm/lib/Analysis/AliasAnalysis.cpp b/llvm/lib/Analysis/AliasAnalysis.cpp
index fae7a84332fd..ebf7070c5aa1 100644
--- a/llvm/lib/Analysis/AliasAnalysis.cpp
+++ b/llvm/lib/Analysis/AliasAnalysis.cpp
@@ -118,15 +118,15 @@ AliasResult AAResults::alias(const MemoryLocation &LocA,
const MemoryLocation &LocB, AAQueryInfo &AAQI) {
AliasResult Result = MayAlias;
- Depth++;
+ AAQI.Depth++;
for (const auto &AA : AAs) {
Result = AA->alias(LocA, LocB, AAQI);
if (Result != MayAlias)
break;
}
- Depth--;
+ AAQI.Depth--;
- if (Depth == 0) {
+ if (AAQI.Depth == 0) {
if (Result == NoAlias)
++NumNoAlias;
else if (Result == MustAlias)
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 97d0cb63ef99..a3add55a4f1c 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1456,7 +1456,7 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize,
// If we inserted a block into VisitedPhiBBs, alias analysis results that
// have been cached earlier may no longer be valid. Perform recursive queries
// with a new AAQueryInfo.
- AAQueryInfo NewAAQI;
+ AAQueryInfo NewAAQI = AAQI.withEmptyCache();
AAQueryInfo *UseAAQI = BlockInserted ? &NewAAQI : &AAQI;
AliasResult Alias = getBestAAResults().alias(
More information about the llvm-commits
mailing list