diff options
author | Dan Gohman <gohman@apple.com> | 2010-01-05 16:27:25 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-01-05 16:27:25 +0000 |
commit | 321a813c536e2f1f2f05bbe78a7fbf64046f0557 (patch) | |
tree | 550286e12d0329b7e1ab4b88483a741672bd9515 | |
parent | b7a9f2b5042589db89e521a4f86fd2fd70845e0f (diff) | |
download | external_llvm-321a813c536e2f1f2f05bbe78a7fbf64046f0557.zip external_llvm-321a813c536e2f1f2f05bbe78a7fbf64046f0557.tar.gz external_llvm-321a813c536e2f1f2f05bbe78a7fbf64046f0557.tar.bz2 |
Use do+while instead of while for loops which obviously have a
non-zero trip count. Use SmallVector's pop_back_val().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92734 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/InstCombine/InstructionCombining.cpp | 7 | ||||
-rw-r--r-- | lib/Transforms/Scalar/ADCE.cpp | 3 | ||||
-rw-r--r-- | lib/Transforms/Scalar/DeadStoreElimination.cpp | 7 | ||||
-rw-r--r-- | lib/Transforms/Scalar/GVN.cpp | 4 | ||||
-rw-r--r-- | lib/Transforms/Scalar/LoopIndexSplit.cpp | 4 | ||||
-rw-r--r-- | lib/Transforms/Scalar/MemCpyOptimizer.cpp | 3 | ||||
-rw-r--r-- | lib/Transforms/Scalar/SCCVN.cpp | 3 | ||||
-rw-r--r-- | lib/Transforms/Scalar/ScalarReplAggregates.cpp | 2 | ||||
-rw-r--r-- | lib/Transforms/Scalar/SimplifyCFGPass.cpp | 7 | ||||
-rw-r--r-- | lib/Transforms/Utils/CloneLoop.cpp | 4 | ||||
-rw-r--r-- | lib/Transforms/Utils/Local.cpp | 4 | ||||
-rw-r--r-- | lib/Transforms/Utils/PromoteMemoryToRegister.cpp | 4 |
12 files changed, 23 insertions, 29 deletions
diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 218e7ae..8e59c01 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1000,9 +1000,8 @@ static bool AddReachableCodeToWorklist(BasicBlock *BB, SmallPtrSet<ConstantExpr*, 64> FoldedConstants; - while (!Worklist.empty()) { - BB = Worklist.back(); - Worklist.pop_back(); + do { + BB = Worklist.pop_back_val(); // We have now visited this block! If we've already been here, ignore it. if (!Visited.insert(BB)) continue; @@ -1082,7 +1081,7 @@ static bool AddReachableCodeToWorklist(BasicBlock *BB, for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) Worklist.push_back(TI->getSuccessor(i)); - } + } while (!Worklist.empty()); // Once we've found all of the instructions to add to instcombine's worklist, // add them in reverse order. This way instcombine will visit from the top diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index 37f383f..5a49841 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -62,8 +62,7 @@ bool ADCE::runOnFunction(Function& F) { // Propagate liveness backwards to operands. while (!worklist.empty()) { - Instruction* curr = worklist.back(); - worklist.pop_back(); + Instruction* curr = worklist.pop_back_val(); for (Instruction::op_iterator OI = curr->op_begin(), OE = curr->op_end(); OI != OE; ++OI) diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index f84735d..320afa1 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -523,9 +523,8 @@ void DSE::DeleteDeadInstruction(Instruction *I, // Before we touch this instruction, remove it from memdep! MemoryDependenceAnalysis &MDA = getAnalysis<MemoryDependenceAnalysis>(); - while (!NowDeadInsts.empty()) { - Instruction *DeadInst = NowDeadInsts.back(); - NowDeadInsts.pop_back(); + do { + Instruction *DeadInst = NowDeadInsts.pop_back_val(); ++NumFastOther; @@ -549,7 +548,7 @@ void DSE::DeleteDeadInstruction(Instruction *I, DeadInst->eraseFromParent(); if (ValueSet) ValueSet->erase(DeadInst); - } + } while (!NowDeadInsts.empty()); } unsigned DSE::getPointerSize(Value *V) const { diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 85b21e1..ac0d850 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -829,7 +829,7 @@ SpeculationFailure: SmallVector<BasicBlock*, 32> BBWorklist; BBWorklist.push_back(BB); - while (!BBWorklist.empty()) { + do { BasicBlock *Entry = BBWorklist.pop_back_val(); // Note that this sets blocks to 0 (unavailable) if they happen to not // already be in FullyAvailableBlocks. This is safe. @@ -841,7 +841,7 @@ SpeculationFailure: for (succ_iterator I = succ_begin(Entry), E = succ_end(Entry); I != E; ++I) BBWorklist.push_back(*I); - } + } while (!BBWorklist.empty()); return false; } diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index 1d9dd68..16d3f2f 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -708,7 +708,7 @@ void LoopIndexSplit::removeBlocks(BasicBlock *DeadBB, Loop *LP, } while (!WorkList.empty()) { - BasicBlock *BB = WorkList.back(); WorkList.pop_back(); + BasicBlock *BB = WorkList.pop_back_val(); LPM->deleteSimpleAnalysisValue(BB, LP); for(BasicBlock::iterator BBI = BB->begin(), BBE = BB->end(); BBI != BBE; ) { @@ -726,7 +726,7 @@ void LoopIndexSplit::removeBlocks(BasicBlock *DeadBB, Loop *LP, // Update Frontier BBs' dominator info. while (!FrontierBBs.empty()) { - BasicBlock *FBB = FrontierBBs.back(); FrontierBBs.pop_back(); + BasicBlock *FBB = FrontierBBs.pop_back_val(); BasicBlock *NewDominator = FBB->getSinglePredecessor(); if (!NewDominator) { pred_iterator PI = pred_begin(FBB), PE = pred_end(FBB); diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp index c675693..5f3fbbf 100644 --- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -562,8 +562,7 @@ bool MemCpyOpt::performCallSlotOptzn(MemCpyInst *cpy, CallInst *C) { SmallVector<User*, 8> srcUseList(srcAlloca->use_begin(), srcAlloca->use_end()); while (!srcUseList.empty()) { - User *UI = srcUseList.back(); - srcUseList.pop_back(); + User *UI = srcUseList.pop_back_val(); if (isa<BitCastInst>(UI)) { for (User::use_iterator I = UI->use_begin(), E = UI->use_end(); diff --git a/lib/Transforms/Scalar/SCCVN.cpp b/lib/Transforms/Scalar/SCCVN.cpp index f91fbda..9685a29 100644 --- a/lib/Transforms/Scalar/SCCVN.cpp +++ b/lib/Transforms/Scalar/SCCVN.cpp @@ -678,8 +678,7 @@ bool SCCVN::runOnFunction(Function& F) { stack.push_back(*PI); while (!stack.empty()) { - BasicBlock* CurrBB = stack.back(); - stack.pop_back(); + BasicBlock* CurrBB = stack.pop_back_val(); visited.insert(CurrBB); ValueNumberScope* S = BBMap[CurrBB]; diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp index 604c210..9e1e79a 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -1181,7 +1181,7 @@ void SROA::CleanupAllocaUsers(Value *V) { if (!isa<StoreInst>(I) && OnlyUsedByDbgInfoIntrinsics(I, &DbgInUses)) { // Safe to remove debug info uses. while (!DbgInUses.empty()) { - DbgInfoIntrinsic *DI = DbgInUses.back(); DbgInUses.pop_back(); + DbgInfoIntrinsic *DI = DbgInUses.pop_back_val(); DI->eraseFromParent(); } I->eraseFromParent(); diff --git a/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/lib/Transforms/Scalar/SimplifyCFGPass.cpp index a36da78..43447de 100644 --- a/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -99,9 +99,8 @@ static bool MarkAliveBlocks(BasicBlock *BB, SmallVector<BasicBlock*, 128> Worklist; Worklist.push_back(BB); bool Changed = false; - while (!Worklist.empty()) { - BB = Worklist.back(); - Worklist.pop_back(); + do { + BB = Worklist.pop_back_val(); if (!Reachable.insert(BB)) continue; @@ -150,7 +149,7 @@ static bool MarkAliveBlocks(BasicBlock *BB, Changed |= ConstantFoldTerminator(BB); for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) Worklist.push_back(*SI); - } + } while (!Worklist.empty()); return Changed; } diff --git a/lib/Transforms/Utils/CloneLoop.cpp b/lib/Transforms/Utils/CloneLoop.cpp index 7e000a1..38928dc 100644 --- a/lib/Transforms/Utils/CloneLoop.cpp +++ b/lib/Transforms/Utils/CloneLoop.cpp @@ -91,7 +91,7 @@ Loop *llvm::CloneLoop(Loop *OrigL, LPPassManager *LPM, LoopInfo *LI, Loop *NewParentLoop = NULL; - while (!LoopNest.empty()) { + do { Loop *L = LoopNest.pop_back_val(); Loop *NewLoop = new Loop(); @@ -123,7 +123,7 @@ Loop *llvm::CloneLoop(Loop *OrigL, LPPassManager *LPM, LoopInfo *LI, // Process sub loops for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I) LoopNest.push_back(*I); - } + } while (!LoopNest.empty()); // Remap instructions to reference operands from ValueMap. for(SmallVector<BasicBlock *, 16>::iterator NBItr = NewBlocks.begin(), diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index 27d9a06..30fe802 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -278,7 +278,7 @@ bool llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V) { SmallVector<Instruction*, 16> DeadInsts; DeadInsts.push_back(I); - while (!DeadInsts.empty()) { + do { I = DeadInsts.pop_back_val(); // Null out all of the instruction's operands to see if any operand becomes @@ -298,7 +298,7 @@ bool llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V) { } I->eraseFromParent(); - } + } while (!DeadInsts.empty()); return true; } diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index 846e432..baaa130 100644 --- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -448,13 +448,13 @@ void PromoteMem2Reg::run() { // std::vector<RenamePassData> RenamePassWorkList; RenamePassWorkList.push_back(RenamePassData(F.begin(), 0, Values)); - while (!RenamePassWorkList.empty()) { + do { RenamePassData RPD; RPD.swap(RenamePassWorkList.back()); RenamePassWorkList.pop_back(); // RenamePass may add new worklist entries. RenamePass(RPD.BB, RPD.Pred, RPD.Values, RenamePassWorkList); - } + } while (!RenamePassWorkList.empty()); // The renamer uses the Visited set to avoid infinite loops. Clear it now. Visited.clear(); |