1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00

[AliasSetTracker] Pass MustAlias to addPointer more often.

Summary:
Pass the alias info to addPointer when available. Will save an alias()
call for must sets when adding a known Must or May alias.
[Part of a series of cleanup patches]

Reviewers: reames, mkazantsev

Subscribers: sanjoy, jlebar, llvm-commits

Differential Revision: https://reviews.llvm.org/D56613

llvm-svn: 353335
This commit is contained in:
Alina Sbirlea 2019-02-06 19:55:12 +00:00
parent b885cd68c3
commit cbb1b7b00a
2 changed files with 40 additions and 26 deletions

View File

@ -293,7 +293,8 @@ private:
void removeFromTracker(AliasSetTracker &AST);
void addPointer(AliasSetTracker &AST, PointerRec &Entry, LocationSize Size,
const AAMDNodes &AAInfo, bool KnownMustAlias = false);
const AAMDNodes &AAInfo, bool KnownMustAlias = false,
bool SkipSizeUpdate = false);
void addUnknownInst(Instruction *I, AliasAnalysis &AA);
void removeUnknownInst(AliasSetTracker &AST, Instruction *I) {
@ -438,7 +439,8 @@ private:
AliasSet &addPointer(MemoryLocation Loc, AliasSet::AccessLattice E);
AliasSet *mergeAliasSetsForPointer(const Value *Ptr, LocationSize Size,
const AAMDNodes &AAInfo);
const AAMDNodes &AAInfo,
bool &MustAliasAll);
/// Merge all alias sets into a single set that is considered to alias any
/// pointer.

View File

@ -126,24 +126,24 @@ void AliasSet::removeFromTracker(AliasSetTracker &AST) {
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);
@ -289,17 +289,27 @@ void AliasSetTracker::clear() {
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.
@ -310,6 +320,7 @@ AliasSet *AliasSetTracker::mergeAliasSetsForPointer(const Value *Ptr,
}
}
MustAliasAll = (AllAR == MustAlias);
return FoundSet;
}
@ -354,6 +365,7 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
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.
@ -362,20 +374,21 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
// 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();
}
@ -567,9 +580,8 @@ void AliasSetTracker::copyValue(Value *From, Value *To) {
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() {