[llvm] [Support] Do not use `llvm::size` in `getLoopPreheader` (PR #94540)
Ben Barham via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 7 21:09:48 PDT 2024
https://github.com/bnbarham updated https://github.com/llvm/llvm-project/pull/94540
>From 3d0d61496e0b592e79dd92aa74bedfa2e2ddd5c2 Mon Sep 17 00:00:00 2001
From: Ben Barham <ben_barham at apple.com>
Date: Sun, 28 Apr 2024 18:55:09 -0700
Subject: [PATCH] [Support] Do not use `llvm::size` in `getLoopPreheader`
`BlockT *LoopBase<BlockT, LoopT>::getLoopPreheader()` was changed in
7243607867393a2b8ccd477e95e6f62d00f3206f to use `llvm::size` rather than
the checking that `child_begin() + 1 == child_end()`. `llvm::size`
requires that `std::distance` be O(1) and hence that clients support
random access. Use `llvm::hasSingleElement` instead.
---
llvm/include/llvm/Support/GenericLoopInfoImpl.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/Support/GenericLoopInfoImpl.h b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
index 1e0d0ee446fc4..d19022729ace3 100644
--- a/llvm/include/llvm/Support/GenericLoopInfoImpl.h
+++ b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
@@ -208,7 +208,7 @@ BlockT *LoopBase<BlockT, LoopT>::getLoopPreheader() const {
return nullptr;
// Make sure there is only one exit out of the preheader.
- if (llvm::size(llvm::children<BlockT *>(Out)) != 1)
+ if (!llvm::hasSingleElement(llvm::children<BlockT *>(Out)))
return nullptr; // Multiple exits from the block, must not be a preheader.
// The predecessor has exactly one successor, so it is a preheader.
More information about the llvm-commits
mailing list