Skip to content

Commit

Permalink
[Support] Use llvm::inverse_children (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Jan 18, 2024
1 parent ac6d2f1 commit 9a817b8
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions llvm/include/llvm/Support/GenericLoopInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,24 +241,14 @@ template <class BlockT, class LoopT> class LoopBase {
bool isLoopLatch(const BlockT *BB) const {
assert(!isInvalid() && "Loop not in a valid state!");
assert(contains(BB) && "block does not belong to the loop");

BlockT *Header = getHeader();
auto PredBegin = GraphTraits<Inverse<BlockT *>>::child_begin(Header);
auto PredEnd = GraphTraits<Inverse<BlockT *>>::child_end(Header);
return std::find(PredBegin, PredEnd, BB) != PredEnd;
return llvm::is_contained(inverse_children<BlockT *>(getHeader()), BB);
}

/// Calculate the number of back edges to the loop header.
unsigned getNumBackEdges() const {
assert(!isInvalid() && "Loop not in a valid state!");
unsigned NumBackEdges = 0;
BlockT *H = getHeader();

for (const auto Pred : children<Inverse<BlockT *>>(H))
if (contains(Pred))
++NumBackEdges;

return NumBackEdges;
return llvm::count_if(inverse_children<BlockT *>(getHeader()),
[&](BlockT *Pred) { return contains(Pred); });
}

//===--------------------------------------------------------------------===//
Expand Down Expand Up @@ -336,7 +326,7 @@ template <class BlockT, class LoopT> class LoopBase {
void getLoopLatches(SmallVectorImpl<BlockT *> &LoopLatches) const {
assert(!isInvalid() && "Loop not in a valid state!");
BlockT *H = getHeader();
for (const auto Pred : children<Inverse<BlockT *>>(H))
for (const auto Pred : inverse_children<BlockT *>(H))
if (contains(Pred))
LoopLatches.push_back(Pred);
}
Expand Down

0 comments on commit 9a817b8

Please sign in to comment.