Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

commit 47d8fec
Author: Kazu Hirata [email protected]
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.

  commit 47d8fec
  Author: Kazu Hirata <[email protected]>
  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.
@kazutakahirata kazutakahirata requested review from kuhar and nikic April 17, 2025 22:03
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Apr 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 17, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Kazu Hirata (kazutakahirata)

Changes

commit 47d8fec
Author: Kazu Hirata <[email protected]>
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 --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());
 

@kazutakahirata kazutakahirata merged commit 69b9ddc into llvm:main Apr 17, 2025
8 of 12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_append_range_restore_reserve branch April 17, 2025 22:09
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
commit 47d8fec
  Author: Kazu Hirata <[email protected]>
  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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants