switch RemoveAccessedObjects to use AliasAnalysis::Location to simplify

the code.  We now get accurate sizes on Loads, though it surely doesn't
matter in practice.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120469 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-11-30 21:47:58 +00:00
parent 42cb684f8d
commit d8d35316de

View File

@ -64,8 +64,8 @@ namespace {
bool runOnBasicBlock(BasicBlock &BB); bool runOnBasicBlock(BasicBlock &BB);
bool HandleFree(CallInst *F); bool HandleFree(CallInst *F);
bool handleEndBlock(BasicBlock &BB); bool handleEndBlock(BasicBlock &BB);
void RemoveAccessedObjects(Value *Ptr, uint64_t killPointerSize, void RemoveAccessedObjects(const AliasAnalysis::Location &LoadedLoc,
SmallPtrSet<Value*, 16> &deadPointers); SmallPtrSet<Value*, 16> &DeadStackObjects);
void DeleteDeadInstruction(Instruction *I, void DeleteDeadInstruction(Instruction *I,
SmallPtrSet<Value*, 16> *deadPointers = 0); SmallPtrSet<Value*, 16> *deadPointers = 0);
@ -494,18 +494,15 @@ bool DSE::handleEndBlock(BasicBlock &BB) {
continue; continue;
} }
Value *KillPointer = 0; AliasAnalysis::Location LoadedLoc;
uint64_t 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)) {
KillPointer = L->getPointerOperand(); LoadedLoc = AA->getLocation(L);
} else if (VAArgInst *V = dyn_cast<VAArgInst>(BBI)) { } else if (VAArgInst *V = dyn_cast<VAArgInst>(BBI)) {
KillPointer = V->getOperand(0); LoadedLoc = AA->getLocation(V);
} else if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(BBI)) { } else if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(BBI)) {
KillPointer = cast<MemTransferInst>(BBI)->getSource(); LoadedLoc = AA->getLocationForSource(MTI);
if (ConstantInt *Len = dyn_cast<ConstantInt>(MTI->getLength()))
KillPointerSize = Len->getZExtValue();
} else { } else {
// Not a loading instruction. // Not a loading instruction.
continue; continue;
@ -513,7 +510,7 @@ bool DSE::handleEndBlock(BasicBlock &BB) {
// Remove any allocas from the DeadPointer set that are loaded, as this // Remove any allocas from the DeadPointer set that are loaded, as this
// makes any stores above the access live. // makes any stores above the access live.
RemoveAccessedObjects(KillPointer, KillPointerSize, DeadStackObjects); RemoveAccessedObjects(LoadedLoc, DeadStackObjects);
// If all of the allocas were clobbered by the access then we're not going // If all of the allocas were clobbered by the access then we're not going
// to find anything else to process. // to find anything else to process.
@ -527,9 +524,9 @@ bool DSE::handleEndBlock(BasicBlock &BB) {
/// RemoveAccessedObjects - Check to see if the specified location may alias any /// RemoveAccessedObjects - Check to see if the specified location may alias any
/// of the stack objects in the DeadStackObjects set. If so, they become live /// of the stack objects in the DeadStackObjects set. If so, they become live
/// because the location is being loaded. /// because the location is being loaded.
void DSE::RemoveAccessedObjects(Value *KillPointer, uint64_t KillPointerSize, void DSE::RemoveAccessedObjects(const AliasAnalysis::Location &LoadedLoc,
SmallPtrSet<Value*, 16> &DeadStackObjects) { SmallPtrSet<Value*, 16> &DeadStackObjects) {
Value *UnderlyingPointer = KillPointer->getUnderlyingObject(); const Value *UnderlyingPointer = LoadedLoc.Ptr->getUnderlyingObject();
// A constant can't be in the dead pointer set. // A constant can't be in the dead pointer set.
if (isa<Constant>(UnderlyingPointer)) if (isa<Constant>(UnderlyingPointer))
@ -538,17 +535,16 @@ void DSE::RemoveAccessedObjects(Value *KillPointer, uint64_t KillPointerSize,
// If the kill pointer can be easily reduced to an alloca, don't bother doing // If the kill pointer can be easily reduced to an alloca, don't bother doing
// extraneous AA queries. // extraneous AA queries.
if (isa<AllocaInst>(UnderlyingPointer) || isa<Argument>(UnderlyingPointer)) { if (isa<AllocaInst>(UnderlyingPointer) || isa<Argument>(UnderlyingPointer)) {
DeadStackObjects.erase(UnderlyingPointer); DeadStackObjects.erase(const_cast<Value*>(UnderlyingPointer));
return; return;
} }
SmallVector<Value*, 16> NowLive; SmallVector<Value*, 16> NowLive;
for (SmallPtrSet<Value*, 16>::iterator I = DeadStackObjects.begin(), for (SmallPtrSet<Value*, 16>::iterator I = DeadStackObjects.begin(),
E = DeadStackObjects.end(); I != E; ++I) { E = DeadStackObjects.end(); I != E; ++I) {
// See if this pointer could alias it // See if the loaded location could alias the stack location.
AliasAnalysis::AliasResult A = AA->alias(*I, getPointerSize(*I, *AA), AliasAnalysis::Location StackLoc(*I, getPointerSize(*I, *AA));
KillPointer, KillPointerSize); if (!AA->isNoAlias(StackLoc, LoadedLoc))
if (A != AliasAnalysis::NoAlias)
NowLive.push_back(*I); NowLive.push_back(*I);
} }