From 92fb2d3803a433e50b748dcdf98d2951312686c8 Mon Sep 17 00:00:00 2001 From: Hal Finkel Date: Sun, 15 Feb 2015 15:51:23 +0000 Subject: [PATCH] [ADCE] Use inst_range and range-based fors Convert a few loops to range-based fors; NFC. llvm-svn: 229318 --- llvm/lib/Transforms/Scalar/ADCE.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/ADCE.cpp b/llvm/lib/Transforms/Scalar/ADCE.cpp index 06a4dd9..effd87e 100644 --- a/llvm/lib/Transforms/Scalar/ADCE.cpp +++ b/llvm/lib/Transforms/Scalar/ADCE.cpp @@ -58,14 +58,13 @@ bool ADCE::runOnFunction(Function& F) { SmallVector Worklist; // Collect the set of "root" instructions that are known live. - for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) - if (isa(I.getInstructionIterator()) || - isa(I.getInstructionIterator()) || - isa(I.getInstructionIterator()) || - I->mayHaveSideEffects()) { - Alive.insert(I.getInstructionIterator()); - Worklist.push_back(I.getInstructionIterator()); + for (Instruction &I : inst_range(F)) { + if (isa(I) || isa(I) || + isa(I) || I.mayHaveSideEffects()) { + Alive.insert(&I); + Worklist.push_back(&I); } + } // Propagate liveness backwards to operands. while (!Worklist.empty()) { @@ -81,16 +80,16 @@ bool ADCE::runOnFunction(Function& F) { // which have no side effects and do not influence the control flow or return // value of the function, and may therefore be deleted safely. // NOTE: We reuse the Worklist vector here for memory efficiency. - for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) - if (!Alive.count(I.getInstructionIterator())) { - Worklist.push_back(I.getInstructionIterator()); - I->dropAllReferences(); + for (Instruction &I : inst_range(F)) { + if (!Alive.count(&I)) { + Worklist.push_back(&I); + I.dropAllReferences(); } + } - for (SmallVectorImpl::iterator I = Worklist.begin(), - E = Worklist.end(); I != E; ++I) { + for (Instruction *&I : Worklist) { ++NumRemoved; - (*I)->eraseFromParent(); + I->eraseFromParent(); } return !Worklist.empty(); -- 2.7.4