void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry,
LocationSize Size, const AAMDNodes &AAInfo,
- bool KnownMustAlias) {
+ bool KnownMustAlias, bool SkipSizeUpdate) {
assert(!Entry.hasAliasSet() && "Entry already in set!");
// Check to see if we have to downgrade to _may_ alias.
- if (isMustAlias() && !KnownMustAlias)
+ if (isMustAlias())
if (PointerRec *P = getSomePointer()) {
- AliasAnalysis &AA = AST.getAliasAnalysis();
- AliasResult Result =
- AA.alias(MemoryLocation(P->getValue(), P->getSize(), P->getAAInfo()),
- MemoryLocation(Entry.getValue(), Size, AAInfo));
- if (Result != MustAlias) {
- Alias = SetMayAlias;
- AST.TotalMayAliasSetSize += size();
- } else {
- // First entry of must alias must have maximum size!
+ if (!KnownMustAlias) {
+ AliasAnalysis &AA = AST.getAliasAnalysis();
+ AliasResult Result = AA.alias(
+ MemoryLocation(P->getValue(), P->getSize(), P->getAAInfo()),
+ MemoryLocation(Entry.getValue(), Size, AAInfo));
+ if (Result != MustAlias) {
+ Alias = SetMayAlias;
+ AST.TotalMayAliasSetSize += size();
+ }
+ assert(Result != NoAlias && "Cannot be part of must set!");
+ } else if (!SkipSizeUpdate)
P->updateSizeAndAAInfo(Size, AAInfo);
- }
- assert(Result != NoAlias && "Cannot be part of must set!");
}
Entry.setAliasSet(this);
AliasSets.clear();
}
-
/// mergeAliasSetsForPointer - Given a pointer, merge all alias sets that may
/// alias the pointer. Return the unified set, or nullptr if no set that aliases
-/// the pointer was found.
+/// the pointer was found. MustAliasAll is updated to true/false if the pointer
+/// is found to MustAlias all the sets it merged.
AliasSet *AliasSetTracker::mergeAliasSetsForPointer(const Value *Ptr,
LocationSize Size,
- const AAMDNodes &AAInfo) {
+ const AAMDNodes &AAInfo,
+ bool &MustAliasAll) {
AliasSet *FoundSet = nullptr;
+ AliasResult AllAR = MustAlias;
for (iterator I = begin(), E = end(); I != E;) {
iterator Cur = I++;
- if (Cur->Forward || !Cur->aliasesPointer(Ptr, Size, AAInfo, AA)) continue;
+ if (Cur->Forward)
+ continue;
+
+ AliasResult AR = Cur->aliasesPointer(Ptr, Size, AAInfo, AA);
+ if (AR == NoAlias)
+ continue;
+
+ AllAR =
+ AliasResult(AllAR & AR); // Possible downgrade to May/Partial, even No
if (!FoundSet) {
// If this is the first alias set ptr can go into, remember it.
}
}
+ MustAliasAll = (AllAR == MustAlias);
return FoundSet;
}
return *AliasAnyAS;
}
+ bool MustAliasAll = false;
// Check to see if the pointer is already known.
if (Entry.hasAliasSet()) {
// If the size changed, we may need to merge several alias sets.
// is NoAlias, mergeAliasSetsForPointer(undef, ...) will not find the
// the right set for undef, even if it exists.
if (Entry.updateSizeAndAAInfo(Size, AAInfo))
- mergeAliasSetsForPointer(Pointer, Size, AAInfo);
+ mergeAliasSetsForPointer(Pointer, Size, AAInfo, MustAliasAll);
// Return the set!
return *Entry.getAliasSet(*this)->getForwardedTarget(*this);
}
- if (AliasSet *AS = mergeAliasSetsForPointer(Pointer, Size, AAInfo)) {
+ if (AliasSet *AS =
+ mergeAliasSetsForPointer(Pointer, Size, AAInfo, MustAliasAll)) {
// Add it to the alias set it aliases.
- AS->addPointer(*this, Entry, Size, AAInfo);
+ AS->addPointer(*this, Entry, Size, AAInfo, MustAliasAll);
return *AS;
}
// Otherwise create a new alias set to hold the loaded pointer.
AliasSets.push_back(new AliasSet());
- AliasSets.back().addPointer(*this, Entry, Size, AAInfo);
+ AliasSets.back().addPointer(*this, Entry, Size, AAInfo, true);
return AliasSets.back();
}
I = PointerMap.find_as(From);
// Add it to the alias set it aliases...
AliasSet *AS = I->second->getAliasSet(*this);
- AS->addPointer(*this, Entry, I->second->getSize(),
- I->second->getAAInfo(),
- true);
+ AS->addPointer(*this, Entry, I->second->getSize(), I->second->getAAInfo(),
+ true, true);
}
AliasSet &AliasSetTracker::mergeAllAliasSets() {