[llvm] [Analysis] Restore the call to reserve (PR #136215)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 17 15:04:21 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

  commit 47d8fec9b8bd5425af17711317a41743a30a8cef
  Author: Kazu Hirata <kazu@<!-- -->google.com>
  Date:   Wed Apr 16 19:30:01 2025 -0700

has removed the call to reserve here.  This patch restores it as
std::vector::insert, called by llvm::append_range, may not be able to
deduce the size of the range.  For example, std::vector in libc++
distinguishes has two versions of std::vector::insert depending on
whether the iterator is an input iterator or a foward iterator.


---
Full diff: https://github.com/llvm/llvm-project/pull/136215.diff


1 Files Affected:

- (modified) llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h (+1) 


``````````diff
diff --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index 57c408968b19a..2237f105e328b 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -1159,6 +1159,7 @@ void BlockFrequencyInfoImpl<BT>::setBlockFreq(const BlockT *BB,
 
 template <class BT> void BlockFrequencyInfoImpl<BT>::initializeRPOT() {
   const BlockT *Entry = &F->front();
+  RPOT.reserve(F->size());
   llvm::append_range(RPOT, post_order(Entry));
   std::reverse(RPOT.begin(), RPOT.end());
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/136215


More information about the llvm-commits mailing list