rename doesClobberMemory -> hasMemoryWrite to be more specific, and

remove an actively-wrong comment.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120378 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-11-30 01:37:52 +00:00
parent 1ab4285b72
commit 72987a2742

View File

@ -91,9 +91,9 @@ INITIALIZE_PASS_END(DSE, "dse", "Dead Store Elimination", false, false)
FunctionPass *llvm::createDeadStoreEliminationPass() { return new DSE(); } FunctionPass *llvm::createDeadStoreEliminationPass() { return new DSE(); }
/// doesClobberMemory - Does this instruction clobber (write without reading) /// hasMemoryWrite - Does this instruction write some memory? This only returns
/// some memory? /// true for things that we can analyze with other helpers below.
static bool doesClobberMemory(Instruction *I) { static bool hasMemoryWrite(Instruction *I) {
if (isa<StoreInst>(I)) if (isa<StoreInst>(I))
return true; return true;
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) { if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
@ -114,7 +114,7 @@ static bool doesClobberMemory(Instruction *I) {
/// isElidable - If the value of this instruction and the memory it writes to is /// isElidable - If the value of this instruction and the memory it writes to is
/// unused, may we delete this instrtction? /// unused, may we delete this instrtction?
static bool isElidable(Instruction *I) { static bool isElidable(Instruction *I) {
assert(doesClobberMemory(I)); assert(hasMemoryWrite(I));
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I))
return II->getIntrinsicID() != Intrinsic::lifetime_end; return II->getIntrinsicID() != Intrinsic::lifetime_end;
if (StoreInst *SI = dyn_cast<StoreInst>(I)) if (StoreInst *SI = dyn_cast<StoreInst>(I))
@ -124,7 +124,7 @@ static bool isElidable(Instruction *I) {
/// getPointerOperand - Return the pointer that is being written to. /// getPointerOperand - Return the pointer that is being written to.
static Value *getPointerOperand(Instruction *I) { static Value *getPointerOperand(Instruction *I) {
assert(doesClobberMemory(I)); assert(hasMemoryWrite(I));
if (StoreInst *SI = dyn_cast<StoreInst>(I)) if (StoreInst *SI = dyn_cast<StoreInst>(I))
return SI->getPointerOperand(); return SI->getPointerOperand();
if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(I)) if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(I))
@ -143,7 +143,7 @@ static Value *getPointerOperand(Instruction *I) {
/// getStoreSize - Return the length in bytes of the write by the clobbering /// getStoreSize - Return the length in bytes of the write by the clobbering
/// instruction. If variable or unknown, returns AliasAnalysis::UnknownSize. /// instruction. If variable or unknown, returns AliasAnalysis::UnknownSize.
static uint64_t getStoreSize(Instruction *I, const TargetData *TD) { static uint64_t getStoreSize(Instruction *I, const TargetData *TD) {
assert(doesClobberMemory(I)); assert(hasMemoryWrite(I));
if (StoreInst *SI = dyn_cast<StoreInst>(I)) { if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
if (!TD) return AliasAnalysis::UnknownSize; if (!TD) return AliasAnalysis::UnknownSize;
return TD->getTypeStoreSize(SI->getOperand(0)->getType()); return TD->getTypeStoreSize(SI->getOperand(0)->getType());
@ -206,8 +206,8 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
continue; continue;
} }
// If we find a store, get its memory dependence. // If we find something that writes memory, get its memory dependence.
if (!doesClobberMemory(Inst)) if (!hasMemoryWrite(Inst))
continue; continue;
MemDepResult InstDep = MD.getDependency(Inst); MemDepResult InstDep = MD.getDependency(Inst);
@ -264,7 +264,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
// If this is a store-store dependence, then the previous store is dead so // If this is a store-store dependence, then the previous store is dead so
// long as this store is at least as big as it. // long as this store is at least as big as it.
if (InstDep.isDef() && doesClobberMemory(InstDep.getInst())) { if (InstDep.isDef() && hasMemoryWrite(InstDep.getInst())) {
Instruction *DepStore = InstDep.getInst(); Instruction *DepStore = InstDep.getInst();
if (isStoreAtLeastAsWideAs(Inst, DepStore, TD) && isElidable(DepStore)) { if (isStoreAtLeastAsWideAs(Inst, DepStore, TD) && isElidable(DepStore)) {
// Delete the store and now-dead instructions that feed it. // Delete the store and now-dead instructions that feed it.
@ -301,7 +301,7 @@ bool DSE::HandleFree(CallInst *F) {
if (Dep.isNonLocal()) return false; if (Dep.isNonLocal()) return false;
Instruction *Dependency = Dep.getInst(); Instruction *Dependency = Dep.getInst();
if (!doesClobberMemory(Dependency) || !isElidable(Dependency)) if (!hasMemoryWrite(Dependency) || !isElidable(Dependency))
return false; return false;
Value *DepPointer = getPointerOperand(Dependency)->getUnderlyingObject(); Value *DepPointer = getPointerOperand(Dependency)->getUnderlyingObject();
@ -358,7 +358,7 @@ bool DSE::handleEndBlock(BasicBlock &BB) {
--BBI; --BBI;
// If we find a store whose pointer is dead. // If we find a store whose pointer is dead.
if (doesClobberMemory(BBI)) { if (hasMemoryWrite(BBI)) {
if (isElidable(BBI)) { if (isElidable(BBI)) {
// See through pointer-to-pointer bitcasts // See through pointer-to-pointer bitcasts
Value *pointerOperand = getPointerOperand(BBI)->getUnderlyingObject(); Value *pointerOperand = getPointerOperand(BBI)->getUnderlyingObject();