Change AliasAnalysis and its clients to use uint64_t instead of unsigned

for representing object sizes, for consistency with other parts of LLVM.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116831 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2010-10-19 18:00:02 +00:00
parent f7d5278fb3
commit 4cccb87b4d
5 changed files with 42 additions and 40 deletions

View File

@@ -283,7 +283,7 @@ void AliasAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
/// getTypeStoreSize - Return the TargetData store size for the given type, /// getTypeStoreSize - Return the TargetData store size for the given type,
/// if known, or a conservative value otherwise. /// if known, or a conservative value otherwise.
/// ///
unsigned AliasAnalysis::getTypeStoreSize(const Type *Ty) { uint64_t AliasAnalysis::getTypeStoreSize(const Type *Ty) {
return TD ? TD->getTypeStoreSize(Ty) : UnknownSize; return TD ? TD->getTypeStoreSize(Ty) : UnknownSize;
} }

View File

@@ -168,12 +168,12 @@ bool AAEval::runOnFunction(Function &F) {
// iterate over the worklist, and run the full (n^2)/2 disambiguations // iterate over the worklist, and run the full (n^2)/2 disambiguations
for (SetVector<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end(); for (SetVector<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end();
I1 != E; ++I1) { I1 != E; ++I1) {
unsigned I1Size = AliasAnalysis::UnknownSize; uint64_t I1Size = AliasAnalysis::UnknownSize;
const Type *I1ElTy = cast<PointerType>((*I1)->getType())->getElementType(); const Type *I1ElTy = cast<PointerType>((*I1)->getType())->getElementType();
if (I1ElTy->isSized()) I1Size = AA.getTypeStoreSize(I1ElTy); if (I1ElTy->isSized()) I1Size = AA.getTypeStoreSize(I1ElTy);
for (SetVector<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2) { for (SetVector<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2) {
unsigned I2Size = AliasAnalysis::UnknownSize; uint64_t I2Size = AliasAnalysis::UnknownSize;
const Type *I2ElTy =cast<PointerType>((*I2)->getType())->getElementType(); const Type *I2ElTy =cast<PointerType>((*I2)->getType())->getElementType();
if (I2ElTy->isSized()) I2Size = AA.getTypeStoreSize(I2ElTy); if (I2ElTy->isSized()) I2Size = AA.getTypeStoreSize(I2ElTy);
@@ -200,7 +200,7 @@ bool AAEval::runOnFunction(Function &F) {
for (SetVector<Value *>::iterator V = Pointers.begin(), Ve = Pointers.end(); for (SetVector<Value *>::iterator V = Pointers.begin(), Ve = Pointers.end();
V != Ve; ++V) { V != Ve; ++V) {
unsigned Size = AliasAnalysis::UnknownSize; uint64_t Size = AliasAnalysis::UnknownSize;
const Type *ElTy = cast<PointerType>((*V)->getType())->getElementType(); const Type *ElTy = cast<PointerType>((*V)->getType())->getElementType();
if (ElTy->isSized()) Size = AA.getTypeStoreSize(ElTy); if (ElTy->isSized()) Size = AA.getTypeStoreSize(ElTy);

View File

@@ -88,7 +88,7 @@ void AliasSet::removeFromTracker(AliasSetTracker &AST) {
} }
void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry, void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry,
unsigned Size, const MDNode *TBAAInfo, uint64_t Size, const MDNode *TBAAInfo,
bool KnownMustAlias) { bool KnownMustAlias) {
assert(!Entry.hasAliasSet() && "Entry already in set!"); assert(!Entry.hasAliasSet() && "Entry already in set!");
@@ -138,7 +138,7 @@ void AliasSet::addCallSite(CallSite CS, AliasAnalysis &AA) {
/// aliasesPointer - Return true if the specified pointer "may" (or must) /// aliasesPointer - Return true if the specified pointer "may" (or must)
/// alias one of the members in the set. /// alias one of the members in the set.
/// ///
bool AliasSet::aliasesPointer(const Value *Ptr, unsigned Size, bool AliasSet::aliasesPointer(const Value *Ptr, uint64_t Size,
const MDNode *TBAAInfo, const MDNode *TBAAInfo,
AliasAnalysis &AA) const { AliasAnalysis &AA) const {
if (AliasTy == MustAlias) { if (AliasTy == MustAlias) {
@@ -210,7 +210,7 @@ void AliasSetTracker::clear() {
/// that may alias the pointer, merge them together and return the unified set. /// that may alias the pointer, merge them together and return the unified set.
/// ///
AliasSet *AliasSetTracker::findAliasSetForPointer(const Value *Ptr, AliasSet *AliasSetTracker::findAliasSetForPointer(const Value *Ptr,
unsigned Size, uint64_t Size,
const MDNode *TBAAInfo) { const MDNode *TBAAInfo) {
AliasSet *FoundSet = 0; AliasSet *FoundSet = 0;
for (iterator I = begin(), E = end(); I != E; ++I) { for (iterator I = begin(), E = end(); I != E; ++I) {
@@ -229,7 +229,7 @@ AliasSet *AliasSetTracker::findAliasSetForPointer(const Value *Ptr,
/// containsPointer - Return true if the specified location is represented by /// containsPointer - Return true if the specified location is represented by
/// this alias set, false otherwise. This does not modify the AST object or /// this alias set, false otherwise. This does not modify the AST object or
/// alias sets. /// alias sets.
bool AliasSetTracker::containsPointer(Value *Ptr, unsigned Size, bool AliasSetTracker::containsPointer(Value *Ptr, uint64_t Size,
const MDNode *TBAAInfo) const { const MDNode *TBAAInfo) const {
for (const_iterator I = begin(), E = end(); I != E; ++I) 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, TBAAInfo, AA))
@@ -258,7 +258,7 @@ AliasSet *AliasSetTracker::findAliasSetForCallSite(CallSite CS) {
/// getAliasSetForPointer - Return the alias set that the specified pointer /// getAliasSetForPointer - Return the alias set that the specified pointer
/// lives in. /// lives in.
AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, unsigned Size, AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, uint64_t Size,
const MDNode *TBAAInfo, const MDNode *TBAAInfo,
bool *New) { bool *New) {
AliasSet::PointerRec &Entry = getEntryFor(Pointer); AliasSet::PointerRec &Entry = getEntryFor(Pointer);
@@ -283,7 +283,7 @@ AliasSet &AliasSetTracker::getAliasSetForPointer(Value *Pointer, unsigned Size,
return AliasSets.back(); return AliasSets.back();
} }
bool AliasSetTracker::add(Value *Ptr, unsigned Size, const MDNode *TBAAInfo) { bool AliasSetTracker::add(Value *Ptr, uint64_t Size, const MDNode *TBAAInfo) {
bool NewPtr; bool NewPtr;
addPointer(Ptr, Size, TBAAInfo, AliasSet::NoModRef, NewPtr); addPointer(Ptr, Size, TBAAInfo, AliasSet::NoModRef, NewPtr);
return NewPtr; return NewPtr;
@@ -414,7 +414,7 @@ void AliasSetTracker::remove(AliasSet &AS) {
} }
bool bool
AliasSetTracker::remove(Value *Ptr, unsigned Size, const MDNode *TBAAInfo) { AliasSetTracker::remove(Value *Ptr, uint64_t Size, const MDNode *TBAAInfo) {
AliasSet *AS = findAliasSetForPointer(Ptr, Size, TBAAInfo); AliasSet *AS = findAliasSetForPointer(Ptr, Size, TBAAInfo);
if (!AS) return false; if (!AS) return false;
remove(*AS); remove(*AS);
@@ -422,7 +422,7 @@ AliasSetTracker::remove(Value *Ptr, unsigned Size, const MDNode *TBAAInfo) {
} }
bool AliasSetTracker::remove(LoadInst *LI) { bool AliasSetTracker::remove(LoadInst *LI) {
unsigned Size = AA.getTypeStoreSize(LI->getType()); uint64_t Size = AA.getTypeStoreSize(LI->getType());
const MDNode *TBAAInfo = LI->getMetadata(LLVMContext::MD_tbaa); const MDNode *TBAAInfo = LI->getMetadata(LLVMContext::MD_tbaa);
AliasSet *AS = findAliasSetForPointer(LI->getOperand(0), Size, TBAAInfo); AliasSet *AS = findAliasSetForPointer(LI->getOperand(0), Size, TBAAInfo);
if (!AS) return false; if (!AS) return false;
@@ -431,7 +431,7 @@ bool AliasSetTracker::remove(LoadInst *LI) {
} }
bool AliasSetTracker::remove(StoreInst *SI) { bool AliasSetTracker::remove(StoreInst *SI) {
unsigned Size = AA.getTypeStoreSize(SI->getOperand(0)->getType()); uint64_t Size = AA.getTypeStoreSize(SI->getOperand(0)->getType());
const MDNode *TBAAInfo = SI->getMetadata(LLVMContext::MD_tbaa); const MDNode *TBAAInfo = SI->getMetadata(LLVMContext::MD_tbaa);
AliasSet *AS = findAliasSetForPointer(SI->getOperand(1), Size, TBAAInfo); AliasSet *AS = findAliasSetForPointer(SI->getOperand(1), Size, TBAAInfo);
if (!AS) return false; if (!AS) return false;

View File

@@ -98,7 +98,7 @@ static bool isEscapeSource(const Value *V) {
/// isObjectSmallerThan - Return true if we can prove that the object specified /// isObjectSmallerThan - Return true if we can prove that the object specified
/// by V is smaller than Size. /// by V is smaller than Size.
static bool isObjectSmallerThan(const Value *V, unsigned Size, static bool isObjectSmallerThan(const Value *V, uint64_t Size,
const TargetData &TD) { const TargetData &TD) {
const Type *AccessTy; const Type *AccessTy;
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) { if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
@@ -552,27 +552,27 @@ namespace {
// aliasGEP - Provide a bunch of ad-hoc rules to disambiguate a GEP // aliasGEP - Provide a bunch of ad-hoc rules to disambiguate a GEP
// instruction against another. // instruction against another.
AliasResult aliasGEP(const GEPOperator *V1, unsigned V1Size, AliasResult aliasGEP(const GEPOperator *V1, uint64_t V1Size,
const Value *V2, unsigned V2Size, const Value *V2, uint64_t V2Size,
const MDNode *V2TBAAInfo, const MDNode *V2TBAAInfo,
const Value *UnderlyingV1, const Value *UnderlyingV2); const Value *UnderlyingV1, const Value *UnderlyingV2);
// aliasPHI - Provide a bunch of ad-hoc rules to disambiguate a PHI // aliasPHI - Provide a bunch of ad-hoc rules to disambiguate a PHI
// instruction against another. // instruction against another.
AliasResult aliasPHI(const PHINode *PN, unsigned PNSize, AliasResult aliasPHI(const PHINode *PN, uint64_t PNSize,
const MDNode *PNTBAAInfo, const MDNode *PNTBAAInfo,
const Value *V2, unsigned V2Size, const Value *V2, uint64_t V2Size,
const MDNode *V2TBAAInfo); const MDNode *V2TBAAInfo);
/// aliasSelect - Disambiguate a Select instruction against another value. /// aliasSelect - Disambiguate a Select instruction against another value.
AliasResult aliasSelect(const SelectInst *SI, unsigned SISize, AliasResult aliasSelect(const SelectInst *SI, uint64_t SISize,
const MDNode *SITBAAInfo, const MDNode *SITBAAInfo,
const Value *V2, unsigned V2Size, const Value *V2, uint64_t V2Size,
const MDNode *V2TBAAInfo); const MDNode *V2TBAAInfo);
AliasResult aliasCheck(const Value *V1, unsigned V1Size, AliasResult aliasCheck(const Value *V1, uint64_t V1Size,
const MDNode *V1TBAATag, const MDNode *V1TBAATag,
const Value *V2, unsigned V2Size, const Value *V2, uint64_t V2Size,
const MDNode *V2TBAATag); const MDNode *V2TBAATag);
}; };
} // End of anonymous namespace } // End of anonymous namespace
@@ -691,7 +691,7 @@ BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
default: break; default: break;
case Intrinsic::memcpy: case Intrinsic::memcpy:
case Intrinsic::memmove: { case Intrinsic::memmove: {
unsigned Len = UnknownSize; uint64_t Len = UnknownSize;
if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getArgOperand(2))) if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getArgOperand(2)))
Len = LenCI->getZExtValue(); Len = LenCI->getZExtValue();
Value *Dest = II->getArgOperand(0); Value *Dest = II->getArgOperand(0);
@@ -707,7 +707,7 @@ BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
// Since memset is 'accesses arguments' only, the AliasAnalysis base class // Since memset is 'accesses arguments' only, the AliasAnalysis base class
// will handle it for the variable length case. // will handle it for the variable length case.
if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getArgOperand(2))) { if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getArgOperand(2))) {
unsigned Len = LenCI->getZExtValue(); uint64_t Len = LenCI->getZExtValue();
Value *Dest = II->getArgOperand(0); Value *Dest = II->getArgOperand(0);
if (isNoAlias(Location(Dest, Len), Loc)) if (isNoAlias(Location(Dest, Len), Loc))
return NoModRef; return NoModRef;
@@ -727,7 +727,7 @@ BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
case Intrinsic::atomic_load_umin: case Intrinsic::atomic_load_umin:
if (TD) { if (TD) {
Value *Op1 = II->getArgOperand(0); Value *Op1 = II->getArgOperand(0);
unsigned Op1Size = TD->getTypeStoreSize(Op1->getType()); uint64_t Op1Size = TD->getTypeStoreSize(Op1->getType());
MDNode *Tag = II->getMetadata(LLVMContext::MD_tbaa); MDNode *Tag = II->getMetadata(LLVMContext::MD_tbaa);
if (isNoAlias(Location(Op1, Op1Size, Tag), Loc)) if (isNoAlias(Location(Op1, Op1Size, Tag), Loc))
return NoModRef; return NoModRef;
@@ -736,7 +736,7 @@ BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
case Intrinsic::lifetime_start: case Intrinsic::lifetime_start:
case Intrinsic::lifetime_end: case Intrinsic::lifetime_end:
case Intrinsic::invariant_start: { case Intrinsic::invariant_start: {
unsigned PtrSize = uint64_t PtrSize =
cast<ConstantInt>(II->getArgOperand(0))->getZExtValue(); cast<ConstantInt>(II->getArgOperand(0))->getZExtValue();
if (isNoAlias(Location(II->getArgOperand(1), if (isNoAlias(Location(II->getArgOperand(1),
PtrSize, PtrSize,
@@ -746,7 +746,7 @@ BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
break; break;
} }
case Intrinsic::invariant_end: { case Intrinsic::invariant_end: {
unsigned PtrSize = uint64_t PtrSize =
cast<ConstantInt>(II->getArgOperand(1))->getZExtValue(); cast<ConstantInt>(II->getArgOperand(1))->getZExtValue();
if (isNoAlias(Location(II->getArgOperand(2), if (isNoAlias(Location(II->getArgOperand(2),
PtrSize, PtrSize,
@@ -767,8 +767,8 @@ BasicAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
/// UnderlyingV2 is the same for V2. /// UnderlyingV2 is the same for V2.
/// ///
AliasAnalysis::AliasResult AliasAnalysis::AliasResult
BasicAliasAnalysis::aliasGEP(const GEPOperator *GEP1, unsigned V1Size, BasicAliasAnalysis::aliasGEP(const GEPOperator *GEP1, uint64_t V1Size,
const Value *V2, unsigned V2Size, const Value *V2, uint64_t V2Size,
const MDNode *V2TBAAInfo, const MDNode *V2TBAAInfo,
const Value *UnderlyingV1, const Value *UnderlyingV1,
const Value *UnderlyingV2) { const Value *UnderlyingV2) {
@@ -878,8 +878,10 @@ BasicAliasAnalysis::aliasGEP(const GEPOperator *GEP1, unsigned V1Size,
// If our known offset is bigger than the access size, we know we don't have // If our known offset is bigger than the access size, we know we don't have
// an alias. // an alias.
if (GEP1BaseOffset) { if (GEP1BaseOffset) {
if (GEP1BaseOffset >= (int64_t)V2Size || if (GEP1BaseOffset >= 0 ?
GEP1BaseOffset <= -(int64_t)V1Size) (V2Size != UnknownSize && (uint64_t)GEP1BaseOffset >= V2Size) :
(V1Size != UnknownSize && -(uint64_t)GEP1BaseOffset >= V1Size &&
GEP1BaseOffset != INT64_MIN))
return NoAlias; return NoAlias;
} }
@@ -889,9 +891,9 @@ BasicAliasAnalysis::aliasGEP(const GEPOperator *GEP1, unsigned V1Size,
/// aliasSelect - Provide a bunch of ad-hoc rules to disambiguate a Select /// aliasSelect - Provide a bunch of ad-hoc rules to disambiguate a Select
/// instruction against another. /// instruction against another.
AliasAnalysis::AliasResult AliasAnalysis::AliasResult
BasicAliasAnalysis::aliasSelect(const SelectInst *SI, unsigned SISize, BasicAliasAnalysis::aliasSelect(const SelectInst *SI, uint64_t SISize,
const MDNode *SITBAAInfo, const MDNode *SITBAAInfo,
const Value *V2, unsigned V2Size, const Value *V2, uint64_t V2Size,
const MDNode *V2TBAAInfo) { const MDNode *V2TBAAInfo) {
// If this select has been visited before, we're on a use-def cycle. // If this select has been visited before, we're on a use-def cycle.
// Such cycles are only valid when PHI nodes are involved or in unreachable // Such cycles are only valid when PHI nodes are involved or in unreachable
@@ -939,9 +941,9 @@ BasicAliasAnalysis::aliasSelect(const SelectInst *SI, unsigned SISize,
// aliasPHI - Provide a bunch of ad-hoc rules to disambiguate a PHI instruction // aliasPHI - Provide a bunch of ad-hoc rules to disambiguate a PHI instruction
// against another. // against another.
AliasAnalysis::AliasResult AliasAnalysis::AliasResult
BasicAliasAnalysis::aliasPHI(const PHINode *PN, unsigned PNSize, BasicAliasAnalysis::aliasPHI(const PHINode *PN, uint64_t PNSize,
const MDNode *PNTBAAInfo, const MDNode *PNTBAAInfo,
const Value *V2, unsigned V2Size, const Value *V2, uint64_t V2Size,
const MDNode *V2TBAAInfo) { const MDNode *V2TBAAInfo) {
// The PHI node has already been visited, avoid recursion any further. // The PHI node has already been visited, avoid recursion any further.
if (!Visited.insert(PN)) if (!Visited.insert(PN))
@@ -1013,9 +1015,9 @@ BasicAliasAnalysis::aliasPHI(const PHINode *PN, unsigned PNSize,
// such as array references. // such as array references.
// //
AliasAnalysis::AliasResult AliasAnalysis::AliasResult
BasicAliasAnalysis::aliasCheck(const Value *V1, unsigned V1Size, BasicAliasAnalysis::aliasCheck(const Value *V1, uint64_t V1Size,
const MDNode *V1TBAAInfo, const MDNode *V1TBAAInfo,
const Value *V2, unsigned V2Size, const Value *V2, uint64_t V2Size,
const MDNode *V2TBAAInfo) { const MDNode *V2TBAAInfo) {
// If either of the memory references is empty, it doesn't matter what the // If either of the memory references is empty, it doesn't matter what the
// pointer values are. // pointer values are.

View File

@@ -70,7 +70,7 @@ namespace {
void visitCallSite(CallSite CS); void visitCallSite(CallSite CS);
void visitMemoryReference(Instruction &I, Value *Ptr, void visitMemoryReference(Instruction &I, Value *Ptr,
unsigned Size, unsigned Align, uint64_t Size, unsigned Align,
const Type *Ty, unsigned Flags); const Type *Ty, unsigned Flags);
void visitCallInst(CallInst &I); void visitCallInst(CallInst &I);
@@ -277,7 +277,7 @@ void Lint::visitCallSite(CallSite CS) {
// Check that the memcpy arguments don't overlap. The AliasAnalysis API // Check that the memcpy arguments don't overlap. The AliasAnalysis API
// isn't expressive enough for what we really want to do. Known partial // isn't expressive enough for what we really want to do. Known partial
// overlap is not distinguished from the case where nothing is known. // overlap is not distinguished from the case where nothing is known.
unsigned Size = 0; uint64_t Size = 0;
if (const ConstantInt *Len = if (const ConstantInt *Len =
dyn_cast<ConstantInt>(findValue(MCI->getLength(), dyn_cast<ConstantInt>(findValue(MCI->getLength(),
/*OffsetOk=*/false))) /*OffsetOk=*/false)))
@@ -361,7 +361,7 @@ void Lint::visitReturnInst(ReturnInst &I) {
// TODO: Check that the reference is in bounds. // TODO: Check that the reference is in bounds.
// TODO: Check readnone/readonly function attributes. // TODO: Check readnone/readonly function attributes.
void Lint::visitMemoryReference(Instruction &I, void Lint::visitMemoryReference(Instruction &I,
Value *Ptr, unsigned Size, unsigned Align, Value *Ptr, uint64_t Size, unsigned Align,
const Type *Ty, unsigned Flags) { const Type *Ty, unsigned Flags) {
// If no memory is being referenced, it doesn't matter if the pointer // If no memory is being referenced, it doesn't matter if the pointer
// is valid. // is valid.