[llvm] fd35899 - [IR] Use range-based for loops (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 14 00:53:38 PST 2024


Author: Kazu Hirata
Date: 2024-01-14T00:53:28-08:00
New Revision: fd358997b3e6f0400b9d4570d5075d729f11484f

URL: https://github.com/llvm/llvm-project/commit/fd358997b3e6f0400b9d4570d5075d729f11484f
DIFF: https://github.com/llvm/llvm-project/commit/fd358997b3e6f0400b9d4570d5075d729f11484f.diff

LOG: [IR] Use range-based for loops (NFC)

Added: 
    

Modified: 
    llvm/lib/IR/Dominators.cpp
    llvm/lib/IR/StructuralHash.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Dominators.cpp b/llvm/lib/IR/Dominators.cpp
index 0f4d112c69c188..cc51b4905a628e 100644
--- a/llvm/lib/IR/Dominators.cpp
+++ b/llvm/lib/IR/Dominators.cpp
@@ -49,10 +49,9 @@ static constexpr bool ExpensiveChecksEnabled = false;
 #endif
 
 bool BasicBlockEdge::isSingleEdge() const {
-  const Instruction *TI = Start->getTerminator();
   unsigned NumEdgesToEnd = 0;
-  for (unsigned int i = 0, n = TI->getNumSuccessors(); i < n; ++i) {
-    if (TI->getSuccessor(i) == End)
+  for (const BasicBlock *Succ : successors(Start)) {
+    if (Succ == End)
       ++NumEdgesToEnd;
     if (NumEdgesToEnd >= 2)
       return false;

diff  --git a/llvm/lib/IR/StructuralHash.cpp b/llvm/lib/IR/StructuralHash.cpp
index ce2b5a38b2f3a7..b6de1ed725d7d4 100644
--- a/llvm/lib/IR/StructuralHash.cpp
+++ b/llvm/lib/IR/StructuralHash.cpp
@@ -125,12 +125,9 @@ class StructuralHashImpl {
       for (auto &Inst : *BB)
         updateInstruction(Inst, DetailedHash);
 
-      const Instruction *Term = BB->getTerminator();
-      for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) {
-        if (!VisitedBBs.insert(Term->getSuccessor(i)).second)
-          continue;
-        BBs.push_back(Term->getSuccessor(i));
-      }
+      for (const BasicBlock *Succ : successors(BB))
+        if (VisitedBBs.insert(Succ).second)
+          BBs.push_back(Succ);
     }
   }
 


        


More information about the llvm-commits mailing list