[llvm] [GenericDomTree] Use range-based for loops (NFC) (PR #96404)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 22 12:18:14 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/96404.diff
2 Files Affected:
- (modified) llvm/include/llvm/Support/GenericDomTree.h (+8-11)
- (modified) llvm/include/llvm/Support/GenericDomTreeConstruction.h (+2-5)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/96404
More information about the llvm-commits
mailing list