[llvm] 6885281 - [Support] Do not use `llvm::size` in `getLoopPreheader` (#94540)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 8 00:32:39 PDT 2024


Author: Ben Barham
Date: 2024-06-08T00:32:35-07:00
New Revision: 68852812ff00d915bc96816a1454eb7d25cb0cb5

URL: https://github.com/llvm/llvm-project/commit/68852812ff00d915bc96816a1454eb7d25cb0cb5
DIFF: https://github.com/llvm/llvm-project/commit/68852812ff00d915bc96816a1454eb7d25cb0cb5.diff

LOG: [Support] Do not use `llvm::size` in `getLoopPreheader` (#94540)

`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.

Added: 
    

Modified: 
    llvm/include/llvm/Support/GenericLoopInfoImpl.h

Removed: 
    


################################################################################
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