forked from OSchip/llvm-project
[AA] Add helper to update result (NFC)
This pattern was repeated a few times, and for some reason always using insert or try_emplace, even though we know in advance that we're looking for an existing entry and not trying to create a new one.
This commit is contained in:
parent
b86595c93f
commit
f9172d3c7b
|
@ -349,6 +349,12 @@ public:
|
|||
IsCapturedCacheT IsCapturedCache;
|
||||
|
||||
AAQueryInfo() : AliasCache(), IsCapturedCache() {}
|
||||
|
||||
AliasResult updateResult(const LocPair &Locs, AliasResult Result) {
|
||||
auto It = AliasCache.find(Locs);
|
||||
assert(It != AliasCache.end() && "Entry must have existed");
|
||||
return It->second = Result;
|
||||
}
|
||||
};
|
||||
|
||||
class BatchAAResults;
|
||||
|
|
|
@ -1577,12 +1577,8 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize,
|
|||
}
|
||||
|
||||
// Reset if speculation failed.
|
||||
if (Alias != NoAlias) {
|
||||
auto Pair =
|
||||
AAQI.AliasCache.insert(std::make_pair(Locs, OrigAliasResult));
|
||||
assert(!Pair.second && "Entry must have existed");
|
||||
Pair.first->second = OrigAliasResult;
|
||||
}
|
||||
if (Alias != NoAlias)
|
||||
AAQI.updateResult(Locs, OrigAliasResult);
|
||||
return Alias;
|
||||
}
|
||||
|
||||
|
@ -1801,12 +1797,8 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
|
|||
if (const GEPOperator *GV1 = dyn_cast<GEPOperator>(V1)) {
|
||||
AliasResult Result =
|
||||
aliasGEP(GV1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O1, O2, AAQI);
|
||||
if (Result != MayAlias) {
|
||||
auto ItInsPair = AAQI.AliasCache.insert(std::make_pair(Locs, Result));
|
||||
assert(!ItInsPair.second && "Entry must have existed");
|
||||
ItInsPair.first->second = Result;
|
||||
return Result;
|
||||
}
|
||||
if (Result != MayAlias)
|
||||
return AAQI.updateResult(Locs, Result);
|
||||
}
|
||||
|
||||
if (isa<PHINode>(V2) && !isa<PHINode>(V1)) {
|
||||
|
@ -1818,11 +1810,8 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
|
|||
if (const PHINode *PN = dyn_cast<PHINode>(V1)) {
|
||||
AliasResult Result =
|
||||
aliasPHI(PN, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O2, AAQI);
|
||||
if (Result != MayAlias) {
|
||||
Pair = AAQI.AliasCache.try_emplace(Locs, Result);
|
||||
assert(!Pair.second && "Entry must have existed");
|
||||
return Pair.first->second = Result;
|
||||
}
|
||||
if (Result != MayAlias)
|
||||
return AAQI.updateResult(Locs, Result);
|
||||
}
|
||||
|
||||
if (isa<SelectInst>(V2) && !isa<SelectInst>(V1)) {
|
||||
|
@ -1834,11 +1823,8 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
|
|||
if (const SelectInst *S1 = dyn_cast<SelectInst>(V1)) {
|
||||
AliasResult Result =
|
||||
aliasSelect(S1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O2, AAQI);
|
||||
if (Result != MayAlias) {
|
||||
Pair = AAQI.AliasCache.try_emplace(Locs, Result);
|
||||
assert(!Pair.second && "Entry must have existed");
|
||||
return Pair.first->second = Result;
|
||||
}
|
||||
if (Result != MayAlias)
|
||||
return AAQI.updateResult(Locs, Result);
|
||||
}
|
||||
|
||||
// If both pointers are pointing into the same object and one of them
|
||||
|
@ -1846,19 +1832,14 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
|
|||
if (O1 == O2)
|
||||
if (V1Size.isPrecise() && V2Size.isPrecise() &&
|
||||
(isObjectSize(O1, V1Size.getValue(), DL, TLI, NullIsValidLocation) ||
|
||||
isObjectSize(O2, V2Size.getValue(), DL, TLI, NullIsValidLocation))) {
|
||||
Pair = AAQI.AliasCache.try_emplace(Locs, PartialAlias);
|
||||
assert(!Pair.second && "Entry must have existed");
|
||||
return Pair.first->second = PartialAlias;
|
||||
}
|
||||
isObjectSize(O2, V2Size.getValue(), DL, TLI, NullIsValidLocation)))
|
||||
return AAQI.updateResult(Locs, PartialAlias);
|
||||
|
||||
// Recurse back into the best AA results we have, potentially with refined
|
||||
// memory locations. We have already ensured that BasicAA has a MayAlias
|
||||
// cache result for these, so any recursion back into BasicAA won't loop.
|
||||
AliasResult Result = getBestAAResults().alias(Locs.first, Locs.second, AAQI);
|
||||
Pair = AAQI.AliasCache.try_emplace(Locs, Result);
|
||||
assert(!Pair.second && "Entry must have existed");
|
||||
return Pair.first->second = Result;
|
||||
return AAQI.updateResult(Locs, Result);
|
||||
}
|
||||
|
||||
/// Check whether two Values can be considered equivalent.
|
||||
|
|
Loading…
Reference in New Issue