Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.678 -> 1.679 --- Log message: switch AddReachableCodeToWorklist from being recursive to being iterative. --- Diffs of the changes: (+54 -46) InstructionCombining.cpp | 100 +++++++++++++++++++++++++---------------------- 1 files changed, 54 insertions(+), 46 deletions(-) Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.678 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.679 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.678 Fri Mar 23 13:46:34 2007 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Mar 23 14:17:18 2007 @@ -9989,58 +9989,66 @@ SmallPtrSet<BasicBlock*, 64> &Visited, InstCombiner &IC, const TargetData *TD) { - // We have now visited this block! If we've already been here, bail out. - if (!Visited.insert(BB)) return; - - for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E; ) { - Instruction *Inst = BBI++; + std::vector<BasicBlock*> Worklist; + Worklist.push_back(BB); + + while (!Worklist.empty()) { + BB = Worklist.back(); + Worklist.pop_back(); - // DCE instruction if trivially dead. - if (isInstructionTriviallyDead(Inst)) { - ++NumDeadInst; - DOUT << "IC: DCE: " << *Inst; - Inst->eraseFromParent(); - continue; - } + // We have now visited this block! If we've already been here, ignore it. + if (!Visited.insert(BB)) continue; - // ConstantProp instruction if trivially constant. - if (Constant *C = ConstantFoldInstruction(Inst, TD)) { - DOUT << "IC: ConstFold to: " << *C << " from: " << *Inst; - Inst->replaceAllUsesWith(C); - ++NumConstProp; - Inst->eraseFromParent(); - continue; + for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E; ) { + Instruction *Inst = BBI++; + + // DCE instruction if trivially dead. + if (isInstructionTriviallyDead(Inst)) { + ++NumDeadInst; + DOUT << "IC: DCE: " << *Inst; + Inst->eraseFromParent(); + continue; + } + + // ConstantProp instruction if trivially constant. + if (Constant *C = ConstantFoldInstruction(Inst, TD)) { + DOUT << "IC: ConstFold to: " << *C << " from: " << *Inst; + Inst->replaceAllUsesWith(C); + ++NumConstProp; + Inst->eraseFromParent(); + continue; + } + + IC.AddToWorkList(Inst); } - - IC.AddToWorkList(Inst); - } - // Recursively visit successors. If this is a branch or switch on a constant, - // only visit the reachable successor. - TerminatorInst *TI = BB->getTerminator(); - if (BranchInst *BI = dyn_cast<BranchInst>(TI)) { - if (BI->isConditional() && isa<ConstantInt>(BI->getCondition())) { - bool CondVal = cast<ConstantInt>(BI->getCondition())->getZExtValue(); - AddReachableCodeToWorklist(BI->getSuccessor(!CondVal), Visited, IC, TD); - return; - } - } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) { - if (ConstantInt *Cond = dyn_cast<ConstantInt>(SI->getCondition())) { - // See if this is an explicit destination. - for (unsigned i = 1, e = SI->getNumSuccessors(); i != e; ++i) - if (SI->getCaseValue(i) == Cond) { - AddReachableCodeToWorklist(SI->getSuccessor(i), Visited, IC, TD); - return; - } - - // Otherwise it is the default destination. - AddReachableCodeToWorklist(SI->getSuccessor(0), Visited, IC, TD); - return; + // Recursively visit successors. If this is a branch or switch on a + // constant, only visit the reachable successor. + TerminatorInst *TI = BB->getTerminator(); + if (BranchInst *BI = dyn_cast<BranchInst>(TI)) { + if (BI->isConditional() && isa<ConstantInt>(BI->getCondition())) { + bool CondVal = cast<ConstantInt>(BI->getCondition())->getZExtValue(); + Worklist.push_back(BI->getSuccessor(!CondVal)); + continue; + } + } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) { + if (ConstantInt *Cond = dyn_cast<ConstantInt>(SI->getCondition())) { + // See if this is an explicit destination. + for (unsigned i = 1, e = SI->getNumSuccessors(); i != e; ++i) + if (SI->getCaseValue(i) == Cond) { + Worklist.push_back(SI->getSuccessor(i)); + continue; + } + + // Otherwise it is the default destination. + Worklist.push_back(SI->getSuccessor(0)); + continue; + } } + + for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) + Worklist.push_back(TI->getSuccessor(i)); } - - for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) - AddReachableCodeToWorklist(TI->getSuccessor(i), Visited, IC, TD); } bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) { _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits