Skip to content

[Analysis] Restore the call to reserve #136215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

commit 47d8fec
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.

  commit 47d8fec
  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.
@llvmbot
Copy link
Member

llvmbot commented Apr 17, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Kazu Hirata (kazutakahirata)

Changes

commit 47d8fec
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 --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 <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.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
commit 47d8fec
  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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants