Small cleanups, refactor some duplicated code into a single method. No

functionality change.

llvm-svn: 92445
This commit is contained in:
Nick Lewycky 2010-01-03 04:39:07 +00:00
parent fca0c8f93a
commit 475d3d1215
1 changed files with 35 additions and 44 deletions

View File

@ -70,6 +70,8 @@ namespace {
AU.addPreserved<AliasAnalysis>();
AU.addPreserved<MemoryDependenceAnalysis>();
}
unsigned getPointerSize(Value *V) const;
};
}
@ -413,22 +415,9 @@ bool DSE::handleEndBlock(BasicBlock &BB) {
return MadeChange;
}
// Get size information for the alloca
unsigned pointerSize = ~0U;
if (TD) {
if (AllocaInst* A = dyn_cast<AllocaInst>(*I)) {
if (ConstantInt* C = dyn_cast<ConstantInt>(A->getArraySize()))
pointerSize = C->getZExtValue() *
TD->getTypeAllocSize(A->getAllocatedType());
} else {
const PointerType* PT = cast<PointerType>(
cast<Argument>(*I)->getType());
pointerSize = TD->getTypeAllocSize(PT->getElementType());
}
}
// See if the call site touches it
AliasAnalysis::ModRefResult A = AA.getModRefInfo(CS, *I, pointerSize);
AliasAnalysis::ModRefResult A = AA.getModRefInfo(CS, *I,
getPointerSize(*I));
if (A == AliasAnalysis::ModRef)
modRef++;
@ -491,21 +480,8 @@ bool DSE::RemoveUndeadPointers(Value* killPointer, uint64_t killPointerSize,
for (SmallPtrSet<Value*, 64>::iterator I = deadPointers.begin(),
E = deadPointers.end(); I != E; ++I) {
// Get size information for the alloca.
unsigned pointerSize = ~0U;
if (TD) {
if (AllocaInst* A = dyn_cast<AllocaInst>(*I)) {
if (ConstantInt* C = dyn_cast<ConstantInt>(A->getArraySize()))
pointerSize = C->getZExtValue() *
TD->getTypeAllocSize(A->getAllocatedType());
} else {
const PointerType* PT = cast<PointerType>(cast<Argument>(*I)->getType());
pointerSize = TD->getTypeAllocSize(PT->getElementType());
}
}
// See if this pointer could alias it
AliasAnalysis::AliasResult A = AA.alias(*I, pointerSize,
AliasAnalysis::AliasResult A = AA.alias(*I, getPointerSize(*I),
killPointer, killPointerSize);
// If it must-alias and a store, we can delete it
@ -513,7 +489,7 @@ bool DSE::RemoveUndeadPointers(Value* killPointer, uint64_t killPointerSize,
StoreInst *S = cast<StoreInst>(BBI);
// Remove it!
BBI++;
++BBI;
DeleteDeadInstruction(S, &deadPointers);
NumFastStores++;
MadeChange = true;
@ -575,3 +551,18 @@ void DSE::DeleteDeadInstruction(Instruction *I,
if (ValueSet) ValueSet->erase(DeadInst);
}
}
unsigned DSE::getPointerSize(Value *V) const {
if (TD) {
if (AllocaInst *A = dyn_cast<AllocaInst>(V)) {
// Get size information for the alloca
if (ConstantInt *C = dyn_cast<ConstantInt>(A->getArraySize()))
return C->getZExtValue() * TD->getTypeAllocSize(A->getAllocatedType());
} else {
assert(isa<Argument>(V) && "Expected AllocaInst or Argument!");
const PointerType *PT = cast<PointerType>(V->getType());
return TD->getTypeAllocSize(PT->getElementType());
}
}
return ~0U;
}