[llvm] r353335 - [AliasSetTracker] Pass MustAlias to addPointer more often.
Alina Sbirlea via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 6 11:55:12 PST 2019
Author: asbirlea
Date: Wed Feb 6 11:55:12 2019
New Revision: 353335
URL: http://llvm.org/viewvc/llvm-project?rev=353335&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/Analysis/AliasSetTracker.h
llvm/trunk/lib/Analysis/AliasSetTracker.cpp
Modified: llvm/trunk/include/llvm/Analysis/AliasSetTracker.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/AliasSetTracker.h?rev=353335&r1=353334&r2=353335&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/AliasSetTracker.h (original)
+++ llvm/trunk/include/llvm/Analysis/AliasSetTracker.h Wed Feb 6 11:55:12 2019
@@ -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.
Modified: llvm/trunk/lib/Analysis/AliasSetTracker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AliasSetTracker.cpp?rev=353335&r1=353334&r2=353335&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/AliasSetTracker.cpp (original)
+++ llvm/trunk/lib/Analysis/AliasSetTracker.cpp Wed Feb 6 11:55:12 2019
@@ -126,24 +126,24 @@ void AliasSet::removeFromTracker(AliasSe
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::mergeAliasSet
}
}
+ MustAliasAll = (AllAR == MustAlias);
return FoundSet;
}
@@ -354,6 +365,7 @@ AliasSet &AliasSetTracker::getAliasSetFo
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::getAliasSetFo
// 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 *F
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() {
More information about the llvm-commits
mailing list