From bb3abf41a868357e95b639b34baebf802199e190 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Wed, 8 Aug 2007 17:50:09 +0000 Subject: [PATCH] Add some comments, remove a dead argument, and simplify some control flow. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40932 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/DeadStoreElimination.cpp | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index 1e3ca868c23..39a0aba2c95 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -51,9 +51,9 @@ namespace { Instruction* dependency, SetVector& possiblyDead); bool handleEndBlock(BasicBlock& BB, SetVector& possiblyDead); - bool RemoveUndeadPointers(Value* pointer, unsigned pointerSize, + bool RemoveUndeadPointers(Value* pointer, BasicBlock::iterator& BBI, - SmallPtrSet& deadPointers, + SmallPtrSet& deadPointers, SetVector& possiblyDead); void DeleteDeadInstructionChains(Instruction *I, SetVector &DeadInsts); @@ -222,7 +222,11 @@ bool DSE::handleFreeWithNonTrivialDependency(FreeInst* F, Instruction* dep, } /// handleEndBlock - Remove dead stores to stack-allocated locations in the -/// function end block +/// function end block. Ex: +/// %A = alloca i32 +/// ... +/// store i32 1, i32* %A +/// ret void bool DSE::handleEndBlock(BasicBlock& BB, SetVector& possiblyDead) { TargetData &TD = getAnalysis(); @@ -232,7 +236,7 @@ bool DSE::handleEndBlock(BasicBlock& BB, bool MadeChange = false; // Pointers alloca'd in this function are dead in the end block - SmallPtrSet deadPointers; + SmallPtrSet deadPointers; // Find all of the alloca'd pointers in the entry block BasicBlock *Entry = BB.getParent()->begin(); @@ -247,9 +251,6 @@ bool DSE::handleEndBlock(BasicBlock& BB, if (deadPointers.empty()) break; - Value* killPointer = 0; - unsigned killPointerSize = 0; - // If we find a store whose pointer is dead... if (StoreInst* S = dyn_cast(BBI)) { Value* pointerOperand = S->getPointerOperand(); @@ -271,24 +272,24 @@ bool DSE::handleEndBlock(BasicBlock& BB, NumFastStores++; MadeChange = true; } + + continue; + } + + Value* killPointer = 0; // If we encounter a use of the pointer, it is no longer considered dead - } else if (LoadInst* L = dyn_cast(BBI)) { + if (LoadInst* L = dyn_cast(BBI)) { killPointer = L->getPointerOperand(); - killPointerSize = TD.getTypeSize(L->getType()); } else if (VAArgInst* V = dyn_cast(BBI)) { killPointer = V->getOperand(0); - killPointerSize = TD.getTypeSize(V->getType()); - } else if (FreeInst* F = dyn_cast(BBI)) { - killPointer = F->getPointerOperand(); - killPointerSize = ~0UL; } else if (AllocaInst* A = dyn_cast(BBI)) { deadPointers.erase(A); continue; } else if (CallSite::get(BBI).getInstruction() != 0) { // Remove any pointers made undead by the call from the dead set std::vector dead; - for (SmallPtrSet::iterator I = deadPointers.begin(), + for (SmallPtrSet::iterator I = deadPointers.begin(), E = deadPointers.end(); I != E; ++I) { // Get size information for the alloca unsigned pointerSize = ~0UL; @@ -314,16 +315,20 @@ bool DSE::handleEndBlock(BasicBlock& BB, continue; // Deal with undead pointers - MadeChange |= RemoveUndeadPointers(killPointer, killPointerSize, BBI, + MadeChange |= RemoveUndeadPointers(killPointer, BBI, deadPointers, possiblyDead); } return MadeChange; } -bool DSE::RemoveUndeadPointers(Value* killPointer, unsigned killPointerSize, +/// RemoveUndeadPointers - takes an instruction and a setvector of +/// dead instructions. If I is dead, it is erased, and its operands are +/// checked for deadness. If they are dead, they are added to the dead +/// setvector. +bool DSE::RemoveUndeadPointers(Value* killPointer, BasicBlock::iterator& BBI, - SmallPtrSet& deadPointers, + SmallPtrSet& deadPointers, SetVector& possiblyDead) { TargetData &TD = getAnalysis(); AliasAnalysis &AA = getAnalysis(); @@ -333,7 +338,7 @@ bool DSE::RemoveUndeadPointers(Value* killPointer, unsigned killPointerSize, std::vector undead; - for (SmallPtrSet::iterator I = deadPointers.begin(), + for (SmallPtrSet::iterator I = deadPointers.begin(), E = deadPointers.end(); I != E; ++I) { // Get size information for the alloca unsigned pointerSize = ~0UL; @@ -343,7 +348,7 @@ bool DSE::RemoveUndeadPointers(Value* killPointer, unsigned killPointerSize, // See if this pointer could alias it AliasAnalysis::AliasResult A = AA.alias(*I, pointerSize, - killPointer, killPointerSize); + killPointer, ~0UL); // If it must-alias and a store, we can delete it if (isa(BBI) && A == AliasAnalysis::MustAlias) { @@ -377,6 +382,10 @@ bool DSE::RemoveUndeadPointers(Value* killPointer, unsigned killPointerSize, return MadeChange; } +/// DeleteDeadInstructionChains - takes an instruction and a setvector of +/// dead instructions. If I is dead, it is erased, and its operands are +/// checked for deadness. If they are dead, they are added to the dead +/// setvector. void DSE::DeleteDeadInstructionChains(Instruction *I, SetVector &DeadInsts) { // Instruction must be dead. -- 2.34.1