Skip to content

Commit

Permalink
[AliasSetTracker] Pass MustAlias to addPointer more often.
Browse files Browse the repository at this point in the history
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353335 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
alinas committed Feb 6, 2019
1 parent 85dc9a8 commit 6822ef3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
6 changes: 4 additions & 2 deletions include/llvm/Analysis/AliasSetTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ class AliasSet : public ilist_node<AliasSet> {
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) {
Expand Down Expand Up @@ -438,7 +439,8 @@ class AliasSetTracker {

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.
Expand Down
60 changes: 36 additions & 24 deletions lib/Analysis/AliasSetTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand All @@ -310,6 +320,7 @@ AliasSet *AliasSetTracker::mergeAliasSetsForPointer(const Value *Ptr,
}
}

MustAliasAll = (AllAR == MustAlias);
return FoundSet;
}

Expand Down Expand Up @@ -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.
Expand All @@ -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();
}

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 6822ef3

Please sign in to comment.