[llvm] [GenericDomTree] Use range-based for loops (NFC) (PR #96404)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 22 12:17:47 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/96404

None

>From 0004cbf0eca7015a0b05e32a68ba84b0bf3181ef Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 22 Jun 2024 11:51:55 -0700
Subject: [PATCH] [GenericDomTree] Use range-based for loops (NFC)

---
 llvm/include/llvm/Support/GenericDomTree.h    | 19 ++++++++-----------
 .../llvm/Support/GenericDomTreeConstruction.h |  7 ++-----
 2 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/llvm/include/llvm/Support/GenericDomTree.h b/llvm/include/llvm/Support/GenericDomTree.h
index 4fce9d8bfb2b6..ec4796a7b5652 100644
--- a/llvm/include/llvm/Support/GenericDomTree.h
+++ b/llvm/include/llvm/Support/GenericDomTree.h
@@ -187,10 +187,8 @@ template <class NodeT>
 void PrintDomTree(const DomTreeNodeBase<NodeT> *N, raw_ostream &O,
                   unsigned Lev) {
   O.indent(2 * Lev) << "[" << Lev << "] " << N;
-  for (typename DomTreeNodeBase<NodeT>::const_iterator I = N->begin(),
-                                                       E = N->end();
-       I != E; ++I)
-    PrintDomTree<NodeT>(*I, O, Lev + 1);
+  for (const auto &I : *N)
+    PrintDomTree<NodeT>(I, O, Lev + 1);
 }
 
 namespace DomTreeBuilder {
@@ -870,10 +868,9 @@ class DominatorTreeBase {
     // Find NewBB's immediate dominator and create new dominator tree node for
     // NewBB.
     NodeT *NewBBIDom = nullptr;
-    unsigned i = 0;
-    for (i = 0; i < PredBlocks.size(); ++i)
-      if (isReachableFromEntry(PredBlocks[i])) {
-        NewBBIDom = PredBlocks[i];
+    for (const auto &Pred : PredBlocks)
+      if (isReachableFromEntry(Pred)) {
+        NewBBIDom = Pred;
         break;
       }
 
@@ -882,9 +879,9 @@ class DominatorTreeBase {
     // changed.
     if (!NewBBIDom) return;
 
-    for (i = i + 1; i < PredBlocks.size(); ++i) {
-      if (isReachableFromEntry(PredBlocks[i]))
-        NewBBIDom = findNearestCommonDominator(NewBBIDom, PredBlocks[i]);
+    for (const auto &Pred : llvm::drop_begin(PredBlocks)) {
+      if (isReachableFromEntry(Pred))
+        NewBBIDom = findNearestCommonDominator(NewBBIDom, Pred);
     }
 
     // Create the new dominator tree node... and set the idom of NewBB.
diff --git a/llvm/include/llvm/Support/GenericDomTreeConstruction.h b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
index a216cd2a03596..401cc4eb0ec1b 100644
--- a/llvm/include/llvm/Support/GenericDomTreeConstruction.h
+++ b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
@@ -595,9 +595,7 @@ struct SemiNCAInfo {
     // Attach the first unreachable block to AttachTo.
     NodeToInfo[NumToNode[1]].IDom = AttachTo->getBlock();
     // Loop over all of the discovered blocks in the function...
-    for (size_t i = 1, e = NumToNode.size(); i != e; ++i) {
-      NodePtr W = NumToNode[i];
-
+    for (NodePtr W : llvm::drop_begin(NumToNode)) {
       // Don't replace this with 'count', the insertion side effect is important
       if (DT.DomTreeNodes[W]) continue;  // Haven't calculated this node yet?
 
@@ -614,8 +612,7 @@ struct SemiNCAInfo {
 
   void reattachExistingSubtree(DomTreeT &DT, const TreeNodePtr AttachTo) {
     NodeToInfo[NumToNode[1]].IDom = AttachTo->getBlock();
-    for (size_t i = 1, e = NumToNode.size(); i != e; ++i) {
-      const NodePtr N = NumToNode[i];
+    for (const NodePtr N : llvm::drop_begin(NumToNode)) {
       const TreeNodePtr TN = DT.getNode(N);
       assert(TN);
       const TreeNodePtr NewIDom = DT.getNode(NodeToInfo[N].IDom);



More information about the llvm-commits mailing list