[llvm] [Transforms] Use range-based for loops (NFC) (PR #98465)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 11 04:30:19 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/98465.diff
4 Files Affected:
- (modified) llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp (+2-5)
- (modified) llvm/lib/Transforms/Scalar/NewGVN.cpp (+2-6)
- (modified) llvm/lib/Transforms/Scalar/Reassociate.cpp (+2-2)
- (modified) llvm/lib/Transforms/Utils/CloneModule.cpp (+2-2)
``````````diff
diff --git a/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp b/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp
index 7af9c39f82363..b4cc00033e720 100644
--- a/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp
+++ b/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp
@@ -220,16 +220,13 @@ static bool findDependencies(DependenceKind Flavor, const Value *Arg,
BasicBlock::iterator StartBBBegin = LocalStartBB->begin();
for (;;) {
if (LocalStartPos == StartBBBegin) {
- pred_iterator PI(LocalStartBB), PE(LocalStartBB, false);
- if (PI == PE)
+ if (pred_empty(LocalStartBB))
// Return if we've reached the function entry.
return false;
// Add the predecessors to the worklist.
- do {
- BasicBlock *PredBB = *PI;
+ for (BasicBlock *PredBB : predecessors(LocalStartBB))
if (Visited.insert(PredBB).second)
Worklist.push_back(std::make_pair(PredBB, PredBB->end()));
- } while (++PI != PE);
break;
}
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index 4cba196ed688a..8f32e97ec251f 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -2525,18 +2525,14 @@ void NewGVN::processOutgoingEdges(Instruction *TI, BasicBlock *B) {
BasicBlock *TargetBlock = Case.getCaseSuccessor();
updateReachableEdge(B, TargetBlock);
} else {
- for (unsigned i = 0, e = SI->getNumSuccessors(); i != e; ++i) {
- BasicBlock *TargetBlock = SI->getSuccessor(i);
+ for (BasicBlock *TargetBlock : successors(SI->getParent()))
updateReachableEdge(B, TargetBlock);
- }
}
} else {
// Otherwise this is either unconditional, or a type we have no
// idea about. Just mark successors as reachable.
- for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) {
- BasicBlock *TargetBlock = TI->getSuccessor(i);
+ for (BasicBlock *TargetBlock : successors(TI->getParent()))
updateReachableEdge(B, TargetBlock);
- }
// This also may be a memory defining terminator, in which case, set it
// equivalent only to itself.
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index cc01d2e59a87e..f7268e8b17d2f 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -1399,8 +1399,8 @@ Value *ReassociatePass::OptimizeXor(Instruction *I,
// the "OpndPtrs" as well. For the similar reason, do not fuse this loop
// with the previous loop --- the iterator of the "Opnds" may be invalidated
// when new elements are added to the vector.
- for (unsigned i = 0, e = Opnds.size(); i != e; ++i)
- OpndPtrs.push_back(&Opnds[i]);
+ for (XorOpnd &Op : Opnds)
+ OpndPtrs.push_back(&Op);
// Step 2: Sort the Xor-Operands in a way such that the operands containing
// the same symbolic value cluster together. For instance, the input operand
diff --git a/llvm/lib/Transforms/Utils/CloneModule.cpp b/llvm/lib/Transforms/Utils/CloneModule.cpp
index 00e40fe73d90b..cabc2ab7933a4 100644
--- a/llvm/lib/Transforms/Utils/CloneModule.cpp
+++ b/llvm/lib/Transforms/Utils/CloneModule.cpp
@@ -208,8 +208,8 @@ std::unique_ptr<Module> llvm::CloneModule(
// And named metadata....
for (const NamedMDNode &NMD : M.named_metadata()) {
NamedMDNode *NewNMD = New->getOrInsertNamedMetadata(NMD.getName());
- for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
- NewNMD->addOperand(MapMetadata(NMD.getOperand(i), VMap));
+ for (const MDNode *N : NMD.operands())
+ NewNMD->addOperand(MapMetadata(N, VMap));
}
return New;
``````````
</details>
https://github.com/llvm/llvm-project/pull/98465
More information about the llvm-commits
mailing list