[ADCE] Use inst_range and range-based fors

Convert a few loops to range-based fors; NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229318 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Hal Finkel 2015-02-15 15:51:23 +00:00
parent 4090dfd7ba
commit 6f0a9df3e3

View File

@ -58,14 +58,13 @@ bool ADCE::runOnFunction(Function& F) {
SmallVector<Instruction*, 128> 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<TerminatorInst>(I.getInstructionIterator()) ||
isa<DbgInfoIntrinsic>(I.getInstructionIterator()) ||
isa<LandingPadInst>(I.getInstructionIterator()) ||
I->mayHaveSideEffects()) {
Alive.insert(I.getInstructionIterator());
Worklist.push_back(I.getInstructionIterator());
for (Instruction &I : inst_range(F)) {
if (isa<TerminatorInst>(I) || isa<DbgInfoIntrinsic>(I) ||
isa<LandingPadInst>(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<Instruction *>::iterator I = Worklist.begin(),
E = Worklist.end(); I != E; ++I) {
for (Instruction *&I : Worklist) {
++NumRemoved;
(*I)->eraseFromParent();
I->eraseFromParent();
}
return !Worklist.empty();