Skip to content

Commit 7243607

Browse files
[Support] Use llvm::children and llvm::inverse_children (NFC)
1 parent 4aea9f6 commit 7243607

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

llvm/include/llvm/Support/GenericLoopInfoImpl.h

+11-18
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ bool LoopBase<BlockT, LoopT>::hasDedicatedExits() const {
115115
SmallVector<BlockT *, 4> UniqueExitBlocks;
116116
getUniqueExitBlocks(UniqueExitBlocks);
117117
for (BlockT *EB : UniqueExitBlocks)
118-
for (BlockT *Predecessor : children<Inverse<BlockT *>>(EB))
118+
for (BlockT *Predecessor : inverse_children<BlockT *>(EB))
119119
if (!contains(Predecessor))
120120
return false;
121121
// All the requirements are met.
@@ -208,10 +208,7 @@ BlockT *LoopBase<BlockT, LoopT>::getLoopPreheader() const {
208208
return nullptr;
209209

210210
// Make sure there is only one exit out of the preheader.
211-
typedef GraphTraits<BlockT *> BlockTraits;
212-
typename BlockTraits::ChildIteratorType SI = BlockTraits::child_begin(Out);
213-
++SI;
214-
if (SI != BlockTraits::child_end(Out))
211+
if (llvm::size(llvm::children<BlockT *>(Out)) != 1)
215212
return nullptr; // Multiple exits from the block, must not be a preheader.
216213

217214
// The predecessor has exactly one successor, so it is a preheader.
@@ -231,7 +228,7 @@ BlockT *LoopBase<BlockT, LoopT>::getLoopPredecessor() const {
231228

232229
// Loop over the predecessors of the header node...
233230
BlockT *Header = getHeader();
234-
for (const auto Pred : children<Inverse<BlockT *>>(Header)) {
231+
for (const auto Pred : inverse_children<BlockT *>(Header)) {
235232
if (!contains(Pred)) { // If the block is not in the loop...
236233
if (Out && Out != Pred)
237234
return nullptr; // Multiple predecessors outside the loop
@@ -249,7 +246,7 @@ BlockT *LoopBase<BlockT, LoopT>::getLoopLatch() const {
249246
assert(!isInvalid() && "Loop not in a valid state!");
250247
BlockT *Header = getHeader();
251248
BlockT *Latch = nullptr;
252-
for (const auto Pred : children<Inverse<BlockT *>>(Header)) {
249+
for (const auto Pred : inverse_children<BlockT *>(Header)) {
253250
if (contains(Pred)) {
254251
if (Latch)
255252
return nullptr;
@@ -331,20 +328,16 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
331328

332329
// Check the individual blocks.
333330
for (BlockT *BB : depth_first_ext(getHeader(), VisitSet)) {
334-
assert(std::any_of(GraphTraits<BlockT *>::child_begin(BB),
335-
GraphTraits<BlockT *>::child_end(BB),
336-
[&](BlockT *B) { return contains(B); }) &&
331+
assert(llvm::any_of(children<BlockT *>(BB),
332+
[&](BlockT *B) { return contains(B); }) &&
337333
"Loop block has no in-loop successors!");
338334

339-
assert(std::any_of(GraphTraits<Inverse<BlockT *>>::child_begin(BB),
340-
GraphTraits<Inverse<BlockT *>>::child_end(BB),
341-
[&](BlockT *B) { return contains(B); }) &&
335+
assert(llvm::any_of(inverse_children<BlockT *>(BB),
336+
[&](BlockT *B) { return contains(B); }) &&
342337
"Loop block has no in-loop predecessors!");
343338

344339
SmallVector<BlockT *, 2> OutsideLoopPreds;
345-
for (BlockT *B :
346-
llvm::make_range(GraphTraits<Inverse<BlockT *>>::child_begin(BB),
347-
GraphTraits<Inverse<BlockT *>>::child_end(BB)))
340+
for (BlockT *B : inverse_children<BlockT *>(BB))
348341
if (!contains(B))
349342
OutsideLoopPreds.push_back(B);
350343

@@ -496,7 +489,7 @@ static void discoverAndMapSubloop(LoopT *L, ArrayRef<BlockT *> Backedges,
496489
// within this subloop tree itself. Note that a predecessor may directly
497490
// reach another subloop that is not yet discovered to be a subloop of
498491
// this loop, which we must traverse.
499-
for (const auto Pred : children<Inverse<BlockT *>>(PredBB)) {
492+
for (const auto Pred : inverse_children<BlockT *>(PredBB)) {
500493
if (LI->getLoopFor(Pred) != Subloop)
501494
ReverseCFGWorklist.push_back(Pred);
502495
}
@@ -579,7 +572,7 @@ void LoopInfoBase<BlockT, LoopT>::analyze(const DomTreeBase<BlockT> &DomTree) {
579572
SmallVector<BlockT *, 4> Backedges;
580573

581574
// Check each predecessor of the potential loop header.
582-
for (const auto Backedge : children<Inverse<BlockT *>>(Header)) {
575+
for (const auto Backedge : inverse_children<BlockT *>(Header)) {
583576
// If Header dominates predBB, this is a new loop. Collect the backedges.
584577
const DomTreeNodeBase<BlockT> *BackedgeNode = DomTree.getNode(Backedge);
585578
if (BackedgeNode && DomTree.dominates(DomNode, BackedgeNode))

0 commit comments

Comments
 (0)