From: Nikita Popov Date: Fri, 12 Feb 2021 14:41:22 +0000 (+0100) Subject: [AA] Move Depth member from AAResults to AAQI (NFC) X-Git-Tag: llvmorg-14-init~15213 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=191e469edee619f578076d775ce1ca19c9ecc103;p=platform%2Fupstream%2Fllvm.git [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. --- diff --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h index 9f74612..59963bc 100644 --- a/llvm/include/llvm/Analysis/AliasAnalysis.h +++ b/llvm/include/llvm/Analysis/AliasAnalysis.h @@ -360,6 +360,9 @@ public: using IsCapturedCacheT = SmallDenseMap; 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 @@ public: SmallVector 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 @@ private: std::vector 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 fae7a84..ebf7070 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 97d0cb6..a3add55 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(