From: Chris Lattner Date: Thu, 28 Apr 2011 16:18:52 +0000 (+0000) Subject: Promote toErase to be an ivar of the GVN class. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=f07054d98a5fcd59f3a30853f4b54a74a74986e5;p=oota-llvm.git Promote toErase to be an ivar of the GVN class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130401 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index ad3df6a8ed1..faed9ce8530 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -418,6 +418,8 @@ namespace { DenseMap LeaderTable; BumpPtrAllocator TableAllocator; + SmallVector InstrsToErase; + /// addToLeaderTable - Push a new Value to the LeaderTable onto the list for /// its value number. void addToLeaderTable(uint32_t N, Value *V, BasicBlock *BB) { @@ -477,16 +479,13 @@ namespace { // Helper fuctions // FIXME: eliminate or document these better - bool processLoad(LoadInst* L, - SmallVectorImpl &toErase); - bool processInstruction(Instruction *I, - SmallVectorImpl &toErase); - bool processNonLocalLoad(LoadInst* L, - SmallVectorImpl &toErase); + bool processLoad(LoadInst *L); + bool processInstruction(Instruction *I); + bool processNonLocalLoad(LoadInst *L); bool processBlock(BasicBlock *BB); - void dump(DenseMap& d); + void dump(DenseMap &d); bool iterateOnFunction(Function &F); - bool performPRE(Function& F); + bool performPRE(Function &F); Value *findLeader(BasicBlock *BB, uint32_t num); void cleanupGlobalSets(); void verifyRemoved(const Instruction *I) const; @@ -1189,8 +1188,7 @@ static bool isLifetimeStart(const Instruction *Inst) { /// processNonLocalLoad - Attempt to eliminate a load whose dependencies are /// non-local by performing PHI construction. -bool GVN::processNonLocalLoad(LoadInst *LI, - SmallVectorImpl &toErase) { +bool GVN::processNonLocalLoad(LoadInst *LI) { // Find the non-local dependencies of the load. SmallVector Deps; AliasAnalysis::Location Loc = VN.getAliasAnalysis()->getLocation(LI); @@ -1354,7 +1352,7 @@ bool GVN::processNonLocalLoad(LoadInst *LI, if (V->getType()->isPointerTy()) MD->invalidateCachedPointerInfo(V); VN.erase(LI); - toErase.push_back(LI); + InstrsToErase.push_back(LI); ++NumGVNLoad; return true; } @@ -1576,14 +1574,14 @@ bool GVN::processNonLocalLoad(LoadInst *LI, if (V->getType()->isPointerTy()) MD->invalidateCachedPointerInfo(V); VN.erase(LI); - toErase.push_back(LI); + InstrsToErase.push_back(LI); ++NumPRELoad; return true; } /// processLoad - Attempt to eliminate a load, first by eliminating it /// locally, and then attempting non-local elimination if that fails. -bool GVN::processLoad(LoadInst *L, SmallVectorImpl &toErase) { +bool GVN::processLoad(LoadInst *L) { if (!MD) return false; @@ -1652,7 +1650,7 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl &toErase) { if (AvailVal->getType()->isPointerTy()) MD->invalidateCachedPointerInfo(AvailVal); VN.erase(L); - toErase.push_back(L); + InstrsToErase.push_back(L); ++NumGVNLoad; return true; } @@ -1672,7 +1670,7 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl &toErase) { // If it is defined in another block, try harder. if (Dep.isNonLocal()) - return processNonLocalLoad(L, toErase); + return processNonLocalLoad(L); Instruction *DepInst = Dep.getInst(); if (StoreInst *DepSI = dyn_cast(DepInst)) { @@ -1700,7 +1698,7 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl &toErase) { if (StoredVal->getType()->isPointerTy()) MD->invalidateCachedPointerInfo(StoredVal); VN.erase(L); - toErase.push_back(L); + InstrsToErase.push_back(L); ++NumGVNLoad; return true; } @@ -1730,7 +1728,7 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl &toErase) { if (DepLI->getType()->isPointerTy()) MD->invalidateCachedPointerInfo(DepLI); VN.erase(L); - toErase.push_back(L); + InstrsToErase.push_back(L); ++NumGVNLoad; return true; } @@ -1741,7 +1739,7 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl &toErase) { if (isa(DepInst) || isMalloc(DepInst)) { L->replaceAllUsesWith(UndefValue::get(L->getType())); VN.erase(L); - toErase.push_back(L); + InstrsToErase.push_back(L); ++NumGVNLoad; return true; } @@ -1752,7 +1750,7 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl &toErase) { if (II->getIntrinsicID() == Intrinsic::lifetime_start) { L->replaceAllUsesWith(UndefValue::get(L->getType())); VN.erase(L); - toErase.push_back(L); + InstrsToErase.push_back(L); ++NumGVNLoad; return true; } @@ -1792,8 +1790,7 @@ Value *GVN::findLeader(BasicBlock *BB, uint32_t num) { /// processInstruction - When calculating availability, handle an instruction /// by inserting it into the appropriate sets -bool GVN::processInstruction(Instruction *I, - SmallVectorImpl &toErase) { +bool GVN::processInstruction(Instruction *I) { // Ignore dbg info intrinsics. if (isa(I)) return false; @@ -1807,19 +1804,17 @@ bool GVN::processInstruction(Instruction *I, if (MD && V->getType()->isPointerTy()) MD->invalidateCachedPointerInfo(V); VN.erase(I); - toErase.push_back(I); + InstrsToErase.push_back(I); return true; } if (LoadInst *LI = dyn_cast(I)) { - bool Changed = processLoad(LI, toErase); - - if (!Changed) { - unsigned Num = VN.lookup_or_add(LI); - addToLeaderTable(Num, LI, LI->getParent()); - } + if (processLoad(LI)) + return true; - return Changed; + unsigned Num = VN.lookup_or_add(LI); + addToLeaderTable(Num, LI, LI->getParent()); + return false; } // For conditions branches, we can perform simple conditional propagation on @@ -1882,7 +1877,7 @@ bool GVN::processInstruction(Instruction *I, I->replaceAllUsesWith(repl); if (MD && repl->getType()->isPointerTy()) MD->invalidateCachedPointerInfo(repl); - toErase.push_back(I); + InstrsToErase.push_back(I); return true; } @@ -1939,35 +1934,36 @@ bool GVN::runOnFunction(Function& F) { bool GVN::processBlock(BasicBlock *BB) { - // FIXME: Kill off toErase by doing erasing eagerly in a helper function (and - // incrementing BI before processing an instruction). - SmallVector toErase; + // FIXME: Kill off InstrsToErase by doing erasing eagerly in a helper function + // (and incrementing BI before processing an instruction). + assert(InstrsToErase.empty() && + "We expect InstrsToErase to be empty across iterations"); bool ChangedFunction = false; for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) { - ChangedFunction |= processInstruction(BI, toErase); - if (toErase.empty()) { + ChangedFunction |= processInstruction(BI); + if (InstrsToErase.empty()) { ++BI; continue; } // If we need some instructions deleted, do it now. - NumGVNInstr += toErase.size(); + NumGVNInstr += InstrsToErase.size(); // Avoid iterator invalidation. bool AtStart = BI == BB->begin(); if (!AtStart) --BI; - for (SmallVector::iterator I = toErase.begin(), - E = toErase.end(); I != E; ++I) { + for (SmallVector::iterator I = InstrsToErase.begin(), + E = InstrsToErase.end(); I != E; ++I) { DEBUG(dbgs() << "GVN removed: " << **I << '\n'); if (MD) MD->removeInstruction(*I); (*I)->eraseFromParent(); DEBUG(verifyRemoved(*I)); } - toErase.clear(); + InstrsToErase.clear(); if (AtStart) BI = BB->begin();