-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[GenericDomTree] Use range-based for loops (NFC) #96404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-support Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/96404.diff 2 Files Affected:
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);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one optional nit
for (const auto &Pred : PredBlocks) | ||
if (isReachableFromEntry(Pred)) { | ||
NewBBIDom = Pred; | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be llvm::find_if
, perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/42/builds/109 Here is the relevant piece of the build log for the reference:
|
No description provided.