Skip to content

Commit 37d3f44

Browse files
[Transforms] Use range-based for loops (NFC) (#98465)
1 parent ef8819e commit 37d3f44

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,13 @@ static bool findDependencies(DependenceKind Flavor, const Value *Arg,
220220
BasicBlock::iterator StartBBBegin = LocalStartBB->begin();
221221
for (;;) {
222222
if (LocalStartPos == StartBBBegin) {
223-
pred_iterator PI(LocalStartBB), PE(LocalStartBB, false);
224-
if (PI == PE)
223+
if (pred_empty(LocalStartBB))
225224
// Return if we've reached the function entry.
226225
return false;
227226
// Add the predecessors to the worklist.
228-
do {
229-
BasicBlock *PredBB = *PI;
227+
for (BasicBlock *PredBB : predecessors(LocalStartBB))
230228
if (Visited.insert(PredBB).second)
231229
Worklist.push_back(std::make_pair(PredBB, PredBB->end()));
232-
} while (++PI != PE);
233230
break;
234231
}
235232

llvm/lib/Transforms/Scalar/NewGVN.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,18 +2525,14 @@ void NewGVN::processOutgoingEdges(Instruction *TI, BasicBlock *B) {
25252525
BasicBlock *TargetBlock = Case.getCaseSuccessor();
25262526
updateReachableEdge(B, TargetBlock);
25272527
} else {
2528-
for (unsigned i = 0, e = SI->getNumSuccessors(); i != e; ++i) {
2529-
BasicBlock *TargetBlock = SI->getSuccessor(i);
2528+
for (BasicBlock *TargetBlock : successors(SI->getParent()))
25302529
updateReachableEdge(B, TargetBlock);
2531-
}
25322530
}
25332531
} else {
25342532
// Otherwise this is either unconditional, or a type we have no
25352533
// idea about. Just mark successors as reachable.
2536-
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) {
2537-
BasicBlock *TargetBlock = TI->getSuccessor(i);
2534+
for (BasicBlock *TargetBlock : successors(TI->getParent()))
25382535
updateReachableEdge(B, TargetBlock);
2539-
}
25402536

25412537
// This also may be a memory defining terminator, in which case, set it
25422538
// equivalent only to itself.

llvm/lib/Transforms/Scalar/Reassociate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,8 +1399,8 @@ Value *ReassociatePass::OptimizeXor(Instruction *I,
13991399
// the "OpndPtrs" as well. For the similar reason, do not fuse this loop
14001400
// with the previous loop --- the iterator of the "Opnds" may be invalidated
14011401
// when new elements are added to the vector.
1402-
for (unsigned i = 0, e = Opnds.size(); i != e; ++i)
1403-
OpndPtrs.push_back(&Opnds[i]);
1402+
for (XorOpnd &Op : Opnds)
1403+
OpndPtrs.push_back(&Op);
14041404

14051405
// Step 2: Sort the Xor-Operands in a way such that the operands containing
14061406
// the same symbolic value cluster together. For instance, the input operand

llvm/lib/Transforms/Utils/CloneModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ std::unique_ptr<Module> llvm::CloneModule(
208208
// And named metadata....
209209
for (const NamedMDNode &NMD : M.named_metadata()) {
210210
NamedMDNode *NewNMD = New->getOrInsertNamedMetadata(NMD.getName());
211-
for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
212-
NewNMD->addOperand(MapMetadata(NMD.getOperand(i), VMap));
211+
for (const MDNode *N : NMD.operands())
212+
NewNMD->addOperand(MapMetadata(N, VMap));
213213
}
214214

215215
return New;

0 commit comments

Comments
 (0)