[llvm] [Transforms] Use range-based for loops (NFC) (PR #98465)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 11 04:29:46 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/98465
None
>From 006f713a8b85d76ea85f598ffd62e50d9639cad4 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 11 Jul 2024 04:05:00 -0700
Subject: [PATCH] [Transforms] Use range-based for loops (NFC)
---
llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp | 7 ++-----
llvm/lib/Transforms/Scalar/NewGVN.cpp | 8 ++------
llvm/lib/Transforms/Scalar/Reassociate.cpp | 4 ++--
llvm/lib/Transforms/Utils/CloneModule.cpp | 4 ++--
4 files changed, 8 insertions(+), 15 deletions(-)
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;
More information about the llvm-commits
mailing list