Consistently use AliasAnalysis::UnknownSize instead of hardcoding ~0u.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116815 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2010-10-19 17:06:23 +00:00
parent 99fca5de96
commit f3a925dc7a
5 changed files with 34 additions and 25 deletions

View File

@@ -284,7 +284,7 @@ void AliasAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
/// if known, or a conservative value otherwise. /// if known, or a conservative value otherwise.
/// ///
unsigned AliasAnalysis::getTypeStoreSize(const Type *Ty) { unsigned AliasAnalysis::getTypeStoreSize(const Type *Ty) {
return TD ? TD->getTypeStoreSize(Ty) : ~0u; return TD ? TD->getTypeStoreSize(Ty) : UnknownSize;
} }
/// canBasicBlockModify - Return true if it is possible for execution of the /// canBasicBlockModify - Return true if it is possible for execution of the

View File

@@ -166,12 +166,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 = ~0u; unsigned 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 = ~0u; unsigned 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);
@@ -198,7 +198,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 = ~0u; unsigned 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

@@ -191,7 +191,8 @@ void Lint::visitCallSite(CallSite CS) {
Instruction &I = *CS.getInstruction(); Instruction &I = *CS.getInstruction();
Value *Callee = CS.getCalledValue(); Value *Callee = CS.getCalledValue();
visitMemoryReference(I, Callee, ~0u, 0, 0, MemRef::Callee); visitMemoryReference(I, Callee, AliasAnalysis::UnknownSize,
0, 0, MemRef::Callee);
if (Function *F = dyn_cast<Function>(findValue(Callee, /*OffsetOk=*/false))) { if (Function *F = dyn_cast<Function>(findValue(Callee, /*OffsetOk=*/false))) {
Assert1(CS.getCallingConv() == F->getCallingConv(), Assert1(CS.getCallingConv() == F->getCallingConv(),
@@ -264,9 +265,11 @@ void Lint::visitCallSite(CallSite CS) {
case Intrinsic::memcpy: { case Intrinsic::memcpy: {
MemCpyInst *MCI = cast<MemCpyInst>(&I); MemCpyInst *MCI = cast<MemCpyInst>(&I);
// TODO: If the size is known, use it. // TODO: If the size is known, use it.
visitMemoryReference(I, MCI->getDest(), ~0u, MCI->getAlignment(), 0, visitMemoryReference(I, MCI->getDest(), AliasAnalysis::UnknownSize,
MCI->getAlignment(), 0,
MemRef::Write); MemRef::Write);
visitMemoryReference(I, MCI->getSource(), ~0u, MCI->getAlignment(), 0, visitMemoryReference(I, MCI->getSource(), AliasAnalysis::UnknownSize,
MCI->getAlignment(), 0,
MemRef::Read); MemRef::Read);
// Check that the memcpy arguments don't overlap. The AliasAnalysis API // Check that the memcpy arguments don't overlap. The AliasAnalysis API
@@ -286,16 +289,19 @@ void Lint::visitCallSite(CallSite CS) {
case Intrinsic::memmove: { case Intrinsic::memmove: {
MemMoveInst *MMI = cast<MemMoveInst>(&I); MemMoveInst *MMI = cast<MemMoveInst>(&I);
// TODO: If the size is known, use it. // TODO: If the size is known, use it.
visitMemoryReference(I, MMI->getDest(), ~0u, MMI->getAlignment(), 0, visitMemoryReference(I, MMI->getDest(), AliasAnalysis::UnknownSize,
MMI->getAlignment(), 0,
MemRef::Write); MemRef::Write);
visitMemoryReference(I, MMI->getSource(), ~0u, MMI->getAlignment(), 0, visitMemoryReference(I, MMI->getSource(), AliasAnalysis::UnknownSize,
MMI->getAlignment(), 0,
MemRef::Read); MemRef::Read);
break; break;
} }
case Intrinsic::memset: { case Intrinsic::memset: {
MemSetInst *MSI = cast<MemSetInst>(&I); MemSetInst *MSI = cast<MemSetInst>(&I);
// TODO: If the size is known, use it. // TODO: If the size is known, use it.
visitMemoryReference(I, MSI->getDest(), ~0u, MSI->getAlignment(), 0, visitMemoryReference(I, MSI->getDest(), AliasAnalysis::UnknownSize,
MSI->getAlignment(), 0,
MemRef::Write); MemRef::Write);
break; break;
} }
@@ -305,24 +311,26 @@ void Lint::visitCallSite(CallSite CS) {
"Undefined behavior: va_start called in a non-varargs function", "Undefined behavior: va_start called in a non-varargs function",
&I); &I);
visitMemoryReference(I, CS.getArgument(0), ~0u, 0, 0, visitMemoryReference(I, CS.getArgument(0), AliasAnalysis::UnknownSize,
MemRef::Read | MemRef::Write); 0, 0, MemRef::Read | MemRef::Write);
break; break;
case Intrinsic::vacopy: case Intrinsic::vacopy:
visitMemoryReference(I, CS.getArgument(0), ~0u, 0, 0, MemRef::Write); visitMemoryReference(I, CS.getArgument(0), AliasAnalysis::UnknownSize,
visitMemoryReference(I, CS.getArgument(1), ~0u, 0, 0, MemRef::Read); 0, 0, MemRef::Write);
visitMemoryReference(I, CS.getArgument(1), AliasAnalysis::UnknownSize,
0, 0, MemRef::Read);
break; break;
case Intrinsic::vaend: case Intrinsic::vaend:
visitMemoryReference(I, CS.getArgument(0), ~0u, 0, 0, visitMemoryReference(I, CS.getArgument(0), AliasAnalysis::UnknownSize,
MemRef::Read | MemRef::Write); 0, 0, MemRef::Read | MemRef::Write);
break; break;
case Intrinsic::stackrestore: case Intrinsic::stackrestore:
// Stackrestore doesn't read or write memory, but it sets the // Stackrestore doesn't read or write memory, but it sets the
// stack pointer, which the compiler may read from or write to // stack pointer, which the compiler may read from or write to
// at any time, so check it for both readability and writeability. // at any time, so check it for both readability and writeability.
visitMemoryReference(I, CS.getArgument(0), ~0u, 0, 0, visitMemoryReference(I, CS.getArgument(0), AliasAnalysis::UnknownSize,
MemRef::Read | MemRef::Write); 0, 0, MemRef::Read | MemRef::Write);
break; break;
} }
} }
@@ -495,12 +503,13 @@ void Lint::visitAllocaInst(AllocaInst &I) {
} }
void Lint::visitVAArgInst(VAArgInst &I) { void Lint::visitVAArgInst(VAArgInst &I) {
visitMemoryReference(I, I.getOperand(0), ~0u, 0, 0, visitMemoryReference(I, I.getOperand(0), AliasAnalysis::UnknownSize, 0, 0,
MemRef::Read | MemRef::Write); MemRef::Read | MemRef::Write);
} }
void Lint::visitIndirectBrInst(IndirectBrInst &I) { void Lint::visitIndirectBrInst(IndirectBrInst &I) {
visitMemoryReference(I, I.getAddress(), ~0u, 0, 0, MemRef::Branchee); visitMemoryReference(I, I.getAddress(), AliasAnalysis::UnknownSize, 0, 0,
MemRef::Branchee);
Assert1(I.getNumDestinations() != 0, Assert1(I.getNumDestinations() != 0,
"Undefined behavior: indirectbr with no destinations", &I); "Undefined behavior: indirectbr with no destinations", &I);

View File

@@ -59,7 +59,7 @@ namespace {
bool handleFreeWithNonTrivialDependency(const CallInst *F, bool handleFreeWithNonTrivialDependency(const CallInst *F,
MemDepResult Dep); MemDepResult Dep);
bool handleEndBlock(BasicBlock &BB); bool handleEndBlock(BasicBlock &BB);
bool RemoveUndeadPointers(Value *Ptr, uint64_t killPointerSize, bool RemoveUndeadPointers(Value *Ptr, unsigned killPointerSize,
BasicBlock::iterator &BBI, BasicBlock::iterator &BBI,
SmallPtrSet<Value*, 64> &deadPointers); SmallPtrSet<Value*, 64> &deadPointers);
void DeleteDeadInstruction(Instruction *I, void DeleteDeadInstruction(Instruction *I,
@@ -371,7 +371,7 @@ bool DSE::handleEndBlock(BasicBlock &BB) {
} }
Value *killPointer = 0; Value *killPointer = 0;
uint64_t killPointerSize = ~0UL; unsigned killPointerSize = AliasAnalysis::UnknownSize;
// If we encounter a use of the pointer, it is no longer considered dead // If we encounter a use of the pointer, it is no longer considered dead
if (LoadInst *L = dyn_cast<LoadInst>(BBI)) { if (LoadInst *L = dyn_cast<LoadInst>(BBI)) {
@@ -470,7 +470,7 @@ bool DSE::handleEndBlock(BasicBlock &BB) {
/// RemoveUndeadPointers - check for uses of a pointer that make it /// RemoveUndeadPointers - check for uses of a pointer that make it
/// undead when scanning for dead stores to alloca's. /// undead when scanning for dead stores to alloca's.
bool DSE::RemoveUndeadPointers(Value *killPointer, uint64_t killPointerSize, bool DSE::RemoveUndeadPointers(Value *killPointer, unsigned killPointerSize,
BasicBlock::iterator &BBI, BasicBlock::iterator &BBI,
SmallPtrSet<Value*, 64> &deadPointers) { SmallPtrSet<Value*, 64> &deadPointers) {
AliasAnalysis &AA = getAnalysis<AliasAnalysis>(); AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
@@ -575,5 +575,5 @@ unsigned DSE::getPointerSize(Value *V) const {
return TD->getTypeAllocSize(PT->getElementType()); return TD->getTypeAllocSize(PT->getElementType());
} }
} }
return ~0U; return AliasAnalysis::UnknownSize;
} }

View File

@@ -770,7 +770,7 @@ bool MemCpyOpt::processMemMove(MemMoveInst *M) {
// If the memmove is a constant size, use it for the alias query, this allows // If the memmove is a constant size, use it for the alias query, this allows
// us to optimize things like: memmove(P, P+64, 64); // us to optimize things like: memmove(P, P+64, 64);
uint64_t MemMoveSize = ~0ULL; unsigned MemMoveSize = AliasAnalysis::UnknownSize;
if (ConstantInt *Len = dyn_cast<ConstantInt>(M->getLength())) if (ConstantInt *Len = dyn_cast<ConstantInt>(M->getLength()))
MemMoveSize = Len->getZExtValue(); MemMoveSize = Len->getZExtValue();