From fd358997b3e6f0400b9d4570d5075d729f11484f Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 14 Jan 2024 00:53:28 -0800 Subject: [PATCH] [IR] Use range-based for loops (NFC) --- llvm/lib/IR/Dominators.cpp | 5 ++--- llvm/lib/IR/StructuralHash.cpp | 9 +++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/llvm/lib/IR/Dominators.cpp b/llvm/lib/IR/Dominators.cpp index 0f4d112c69c1..cc51b4905a62 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 ce2b5a38b2f3..b6de1ed725d7 100644 --- a/llvm/lib/IR/StructuralHash.cpp +++ b/llvm/lib/IR/StructuralHash.cpp @@ -125,12 +125,9 @@ public: 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); } } -- 2.11.4.GIT