AA metadata refactoring (introduce AAMDNodes)

In order to enable the preservation of noalias function parameter information
after inlining, and the representation of block-level __restrict__ pointer
information (etc.), additional kinds of aliasing metadata will be introduced.
This metadata needs to be carried around in AliasAnalysis::Location objects
(and MMOs at the SDAG level), and so we need to generalize the current scheme
(which is hard-coded to just one TBAA MDNode*).

This commit introduces only the necessary refactoring to allow for the
introduction of other aliasing metadata types, but does not actually introduce
any (that will come in a follow-up commit). What it does introduce is a new
AAMDNodes structure to hold all of the aliasing metadata nodes associated with
a particular memory-accessing instruction, and uses that structure instead of
the raw MDNode* in AliasAnalysis::Location, etc.

No functionality change intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213859 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Hal Finkel
2014-07-24 12:16:19 +00:00
parent a4abc43a56
commit 2c7c54c86c
50 changed files with 521 additions and 389 deletions

View File

@ -47,10 +47,10 @@ void AliasSet::mergeSetIn(AliasSet &AS, AliasSetTracker &AST) {
// If the pointers are not a must-alias pair, this set becomes a may alias.
if (AA.alias(AliasAnalysis::Location(L->getValue(),
L->getSize(),
L->getTBAAInfo()),
L->getAAInfo()),
AliasAnalysis::Location(R->getValue(),
R->getSize(),
R->getTBAAInfo()))
R->getAAInfo()))
!= AliasAnalysis::MustAlias)
AliasTy = MayAlias;
}
@ -92,7 +92,7 @@ void AliasSet::removeFromTracker(AliasSetTracker &AST) {
}
void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry,
uint64_t Size, const MDNode *TBAAInfo,
uint64_t Size, const AAMDNodes &AAInfo,
bool KnownMustAlias) {
assert(!Entry.hasAliasSet() && "Entry already in set!");
@ -102,17 +102,17 @@ void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry,
AliasAnalysis &AA = AST.getAliasAnalysis();
AliasAnalysis::AliasResult Result =
AA.alias(AliasAnalysis::Location(P->getValue(), P->getSize(),
P->getTBAAInfo()),
AliasAnalysis::Location(Entry.getValue(), Size, TBAAInfo));
P->getAAInfo()),
AliasAnalysis::Location(Entry.getValue(), Size, AAInfo));
if (Result != AliasAnalysis::MustAlias)
AliasTy = MayAlias;
else // First entry of must alias must have maximum size!
P->updateSizeAndTBAAInfo(Size, TBAAInfo);
P->updateSizeAndAAInfo(Size, AAInfo);
assert(Result != AliasAnalysis::NoAlias && "Cannot be part of must set!");
}
Entry.setAliasSet(this);
Entry.updateSizeAndTBAAInfo(Size, TBAAInfo);
Entry.updateSizeAndAAInfo(Size, AAInfo);
// Add it to the end of the list...
assert(*PtrListEnd == nullptr && "End of list is not null?");
@ -140,7 +140,7 @@ void AliasSet::addUnknownInst(Instruction *I, AliasAnalysis &AA) {
/// alias one of the members in the set.
///
bool AliasSet::aliasesPointer(const Value *Ptr, uint64_t Size,
const MDNode *TBAAInfo,
const AAMDNodes &AAInfo,
AliasAnalysis &AA) const {
if (AliasTy == MustAlias) {
assert(UnknownInsts.empty() && "Illegal must alias set!");
@ -151,23 +151,23 @@ bool AliasSet::aliasesPointer(const Value *Ptr, uint64_t Size,
assert(SomePtr && "Empty must-alias set??");
return AA.alias(AliasAnalysis::Location(SomePtr->getValue(),
SomePtr->getSize(),
SomePtr->getTBAAInfo()),
AliasAnalysis::Location(Ptr, Size, TBAAInfo));
SomePtr->getAAInfo()),
AliasAnalysis::Location(Ptr, Size, AAInfo));
}
// If this is a may-alias set, we have to check all of the pointers in the set
// to be sure it doesn't alias the set...
for (iterator I = begin(), E = end(); I != E; ++I)
if (AA.alias(AliasAnalysis::Location(Ptr, Size, TBAAInfo),
if (AA.alias(AliasAnalysis::Location(Ptr, Size, AAInfo),
AliasAnalysis::Location(I.getPointer(), I.getSize(),
I.getTBAAInfo())))
I.getAAInfo())))
return true;
// Check the unknown instructions...
if (!UnknownInsts.empty()) {
for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i)
if (AA.getModRefInfo(UnknownInsts[i],
AliasAnalysis::Location(Ptr, Size, TBAAInfo)) !=
AliasAnalysis::Location(Ptr, Size, AAInfo)) !=
AliasAnalysis::NoModRef)
return true;
}
@ -190,7 +190,7 @@ bool AliasSet::aliasesUnknownInst(Instruction *Inst, AliasAnalysis &AA) const {
for (iterator I = begin(), E = end(); I != E; ++I)
if (AA.getModRefInfo(Inst, AliasAnalysis::Location(I.getPointer(),
I.getSize(),
I.getTBAAInfo())) !=
I.getAAInfo())) !=
AliasAnalysis::NoModRef)
return true;
@ -216,10 +216,10 @@ void AliasSetTracker::clear() {
///
AliasSet *AliasSetTracker::findAliasSetForPointer(const Value *Ptr,
uint64_t Size,
const MDNode *TBAAInfo) {
const AAMDNodes &AAInfo) {
AliasSet *FoundSet = nullptr;
for (iterator I = begin(), E = end(); I != E; ++I) {
if (I->Forward || !I->aliasesPointer(Ptr, Size, TBAAInfo, AA)) continue;
if (I->Forward || !I->aliasesPointer(Ptr, Size, AAInfo, AA)) continue;
if (!FoundSet) { // If this is the first alias set ptr can go into.
FoundSet = I; // Remember it.
@ -235,9 +235,9 @@ AliasSet *AliasSetTracker::findAliasSetForPointer(const Value *Ptr,
/// this alias set, false otherwise. This does not modify the AST object or
/// alias sets.
bool AliasSetTracker::containsPointer(Value *Ptr, uint64_t Size,
const MDNode *TBAAInfo) const {
const AAMDNodes &AAInfo) const {
for (const_iterator I = begin(), E = end(); I != E; ++I)
if (!I->Forward && I->aliasesPointer(Ptr, Size, TBAAInfo, AA))
if (!I->Forward && I->aliasesPointer(Ptr, Size, AAInfo, AA))
return true;
return false;
}
@ -264,67 +264,75 @@ AliasSet *AliasSetTracker::findAliasSetForUnknownInst(Instruction *Inst) {
/// getAliasSetForPointer - Return the alias set that the specified pointer
/// lives in.
AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, uint64_t Size,
const MDNode *TBAAInfo,
const AAMDNodes &AAInfo,
bool *New) {
AliasSet::PointerRec &Entry = getEntryFor(Pointer);
// Check to see if the pointer is already known.
if (Entry.hasAliasSet()) {
Entry.updateSizeAndTBAAInfo(Size, TBAAInfo);
Entry.updateSizeAndAAInfo(Size, AAInfo);
// Return the set!
return *Entry.getAliasSet(*this)->getForwardedTarget(*this);
}
if (AliasSet *AS = findAliasSetForPointer(Pointer, Size, TBAAInfo)) {
if (AliasSet *AS = findAliasSetForPointer(Pointer, Size, AAInfo)) {
// Add it to the alias set it aliases.
AS->addPointer(*this, Entry, Size, TBAAInfo);
AS->addPointer(*this, Entry, Size, AAInfo);
return *AS;
}
if (New) *New = true;
// Otherwise create a new alias set to hold the loaded pointer.
AliasSets.push_back(new AliasSet());
AliasSets.back().addPointer(*this, Entry, Size, TBAAInfo);
AliasSets.back().addPointer(*this, Entry, Size, AAInfo);
return AliasSets.back();
}
bool AliasSetTracker::add(Value *Ptr, uint64_t Size, const MDNode *TBAAInfo) {
bool AliasSetTracker::add(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo) {
bool NewPtr;
addPointer(Ptr, Size, TBAAInfo, AliasSet::NoModRef, NewPtr);
addPointer(Ptr, Size, AAInfo, AliasSet::NoModRef, NewPtr);
return NewPtr;
}
bool AliasSetTracker::add(LoadInst *LI) {
if (LI->getOrdering() > Monotonic) return addUnknown(LI);
AAMDNodes AAInfo;
LI->getAAMetadata(AAInfo);
AliasSet::AccessType ATy = AliasSet::Refs;
bool NewPtr;
AliasSet &AS = addPointer(LI->getOperand(0),
AA.getTypeStoreSize(LI->getType()),
LI->getMetadata(LLVMContext::MD_tbaa),
ATy, NewPtr);
AAInfo, ATy, NewPtr);
if (LI->isVolatile()) AS.setVolatile();
return NewPtr;
}
bool AliasSetTracker::add(StoreInst *SI) {
if (SI->getOrdering() > Monotonic) return addUnknown(SI);
AAMDNodes AAInfo;
SI->getAAMetadata(AAInfo);
AliasSet::AccessType ATy = AliasSet::Mods;
bool NewPtr;
Value *Val = SI->getOperand(0);
AliasSet &AS = addPointer(SI->getOperand(1),
AA.getTypeStoreSize(Val->getType()),
SI->getMetadata(LLVMContext::MD_tbaa),
ATy, NewPtr);
AAInfo, ATy, NewPtr);
if (SI->isVolatile()) AS.setVolatile();
return NewPtr;
}
bool AliasSetTracker::add(VAArgInst *VAAI) {
AAMDNodes AAInfo;
VAAI->getAAMetadata(AAInfo);
bool NewPtr;
addPointer(VAAI->getOperand(0), AliasAnalysis::UnknownSize,
VAAI->getMetadata(LLVMContext::MD_tbaa),
AliasSet::ModRef, NewPtr);
AAInfo, AliasSet::ModRef, NewPtr);
return NewPtr;
}
@ -382,7 +390,7 @@ void AliasSetTracker::add(const AliasSetTracker &AST) {
bool X;
for (AliasSet::iterator ASI = AS.begin(), E = AS.end(); ASI != E; ++ASI) {
AliasSet &NewAS = addPointer(ASI.getPointer(), ASI.getSize(),
ASI.getTBAAInfo(),
ASI.getAAInfo(),
(AliasSet::AccessType)AS.AccessTy, X);
if (AS.isVolatile()) NewAS.setVolatile();
}
@ -419,8 +427,8 @@ void AliasSetTracker::remove(AliasSet &AS) {
}
bool
AliasSetTracker::remove(Value *Ptr, uint64_t Size, const MDNode *TBAAInfo) {
AliasSet *AS = findAliasSetForPointer(Ptr, Size, TBAAInfo);
AliasSetTracker::remove(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo) {
AliasSet *AS = findAliasSetForPointer(Ptr, Size, AAInfo);
if (!AS) return false;
remove(*AS);
return true;
@ -428,8 +436,11 @@ AliasSetTracker::remove(Value *Ptr, uint64_t Size, const MDNode *TBAAInfo) {
bool AliasSetTracker::remove(LoadInst *LI) {
uint64_t Size = AA.getTypeStoreSize(LI->getType());
const MDNode *TBAAInfo = LI->getMetadata(LLVMContext::MD_tbaa);
AliasSet *AS = findAliasSetForPointer(LI->getOperand(0), Size, TBAAInfo);
AAMDNodes AAInfo;
LI->getAAMetadata(AAInfo);
AliasSet *AS = findAliasSetForPointer(LI->getOperand(0), Size, AAInfo);
if (!AS) return false;
remove(*AS);
return true;
@ -437,17 +448,22 @@ bool AliasSetTracker::remove(LoadInst *LI) {
bool AliasSetTracker::remove(StoreInst *SI) {
uint64_t Size = AA.getTypeStoreSize(SI->getOperand(0)->getType());
const MDNode *TBAAInfo = SI->getMetadata(LLVMContext::MD_tbaa);
AliasSet *AS = findAliasSetForPointer(SI->getOperand(1), Size, TBAAInfo);
AAMDNodes AAInfo;
SI->getAAMetadata(AAInfo);
AliasSet *AS = findAliasSetForPointer(SI->getOperand(1), Size, AAInfo);
if (!AS) return false;
remove(*AS);
return true;
}
bool AliasSetTracker::remove(VAArgInst *VAAI) {
AAMDNodes AAInfo;
VAAI->getAAMetadata(AAInfo);
AliasSet *AS = findAliasSetForPointer(VAAI->getOperand(0),
AliasAnalysis::UnknownSize,
VAAI->getMetadata(LLVMContext::MD_tbaa));
AliasAnalysis::UnknownSize, AAInfo);
if (!AS) return false;
remove(*AS);
return true;
@ -536,7 +552,7 @@ void AliasSetTracker::copyValue(Value *From, Value *To) {
I = PointerMap.find_as(From);
AliasSet *AS = I->second->getAliasSet(*this);
AS->addPointer(*this, Entry, I->second->getSize(),
I->second->getTBAAInfo(),
I->second->getAAInfo(),
true);
}