From 8244243a31d636ce8838a81d4c402274fd391d2b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 18 Feb 2008 07:42:56 +0000 Subject: [PATCH] switch simplifycfg from using vectors for most things to smallvectors, this speeds it up 2.3% on eon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47261 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SimplifyCFG.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index f19adbd263c..c89ec60d695 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -158,7 +158,7 @@ static bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, // If there is more than one pred of succ, and there are PHI nodes in // the successor, then we need to add incoming edges for the PHI nodes // - const std::vector BBPreds(pred_begin(BB), pred_end(BB)); + const SmallVector BBPreds(pred_begin(BB), pred_end(BB)); // Loop over all of the PHI nodes in the successor of BB. for (BasicBlock::iterator I = Succ->begin(); isa(I); ++I) { @@ -174,17 +174,15 @@ static bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, PN->addIncoming(OldValPN->getIncomingValue(i), OldValPN->getIncomingBlock(i)); } else { - for (std::vector::const_iterator PredI = BBPreds.begin(), - End = BBPreds.end(); PredI != End; ++PredI) { - // Add an incoming value for each of the new incoming values... - PN->addIncoming(OldVal, *PredI); - } + // Add an incoming value for each of the new incoming values. + for (unsigned i = 0, e = BBPreds.size(); i != e; ++i) + PN->addIncoming(OldVal, BBPreds[i]); } } } if (isa(&BB->front())) { - std::vector + SmallVector OldSuccPreds(pred_begin(Succ), pred_end(Succ)); // Move all PHI nodes in BB to Succ if they are alive, otherwise @@ -464,7 +462,7 @@ static bool GatherValueComparisons(Instruction *Cond, Value *&CompVal, static void ErasePossiblyDeadInstructionTree(Instruction *I) { if (!isInstructionTriviallyDead(I)) return; - std::vector InstrsToInspect; + SmallVector InstrsToInspect; InstrsToInspect.push_back(I); while (!InstrsToInspect.empty()) { @@ -713,7 +711,7 @@ static bool FoldValueComparisonIntoPredecessors(TerminatorInst *TI) { assert(CV && "Not a comparison?"); bool Changed = false; - std::vector Preds(pred_begin(BB), pred_end(BB)); + SmallVector Preds(pred_begin(BB), pred_end(BB)); while (!Preds.empty()) { BasicBlock *Pred = Preds.back(); Preds.pop_back(); @@ -733,7 +731,7 @@ static bool FoldValueComparisonIntoPredecessors(TerminatorInst *TI) { // Based on whether the default edge from PTI goes to BB or not, fill in // PredCases and PredDefault with the new switch cases we would like to // build. - std::vector NewSuccessors; + SmallVector NewSuccessors; if (PredDefault == BB) { // If this is the default destination from PTI, only the edges in TI @@ -1233,8 +1231,8 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { BasicBlock::iterator BBI = BB->getTerminator(); if (BBI == BB->begin() || isa(--BBI)) { // Find predecessors that end with branches. - std::vector UncondBranchPreds; - std::vector CondBranchPreds; + SmallVector UncondBranchPreds; + SmallVector CondBranchPreds; for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { TerminatorInst *PTI = (*PI)->getTerminator(); if (BranchInst *BI = dyn_cast(PTI)) @@ -1357,7 +1355,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { // destination with call instructions, and any unconditional branch // predecessor with an unwind. // - std::vector Preds(pred_begin(BB), pred_end(BB)); + SmallVector Preds(pred_begin(BB), pred_end(BB)); while (!Preds.empty()) { BasicBlock *Pred = Preds.back(); if (BranchInst *BI = dyn_cast(Pred->getTerminator())) { @@ -1676,7 +1674,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { // If the unreachable instruction is the first in the block, take a gander // at all of the predecessors of this instruction, and simplify them. if (&BB->front() == Unreachable) { - std::vector Preds(pred_begin(BB), pred_end(BB)); + SmallVector Preds(pred_begin(BB), pred_end(BB)); for (unsigned i = 0, e = Preds.size(); i != e; ++i) { TerminatorInst *TI = Preds[i]->getTerminator();