public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Use vec::reserve before vec_safe_grow_cleared is called
@ 2020-07-25 12:22 Martin Liška
  2020-07-27  7:11 ` Richard Biener
  0 siblings, 1 reply; 40+ messages in thread
From: Martin Liška @ 2020-07-25 12:22 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jan Hubicka

Hello.

When inserting into fast_call_summary (or fast_function_summary), we grow
a vector to a _exact_ size based on cgraph_max_summary_id or edges_max_summary_id.
Problem is that it causes very many reallocation and we should rather use ::reserve
function that selects a reasonable size of a new vector.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Fixes chromium WPA build time:
https://gist.githubusercontent.com/marxin/223890df4d8d8e490b6b2918b77dacad/raw/f766f6546739e739a273639dde90ac6179aa3077/chromium-gcc10-fixed-summary-crash.svg

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

	* symbol-summary.h: Call vec_safe_reserve before grow is called
	in order to grow to a reasonable size.
	* vec.h (vec_safe_reserve): Add missing function for vl_ptr
	type.
---
  gcc/symbol-summary.h | 13 ++++++++++---
  gcc/vec.h            | 11 +++++++++++
  2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/gcc/symbol-summary.h b/gcc/symbol-summary.h
index a38eb1db778..fa1df5c8015 100644
--- a/gcc/symbol-summary.h
+++ b/gcc/symbol-summary.h
@@ -354,8 +354,11 @@ public:
        id = this->m_symtab->assign_summary_id (node);
  
      if ((unsigned int)id >= m_vector->length ())
-      vec_safe_grow_cleared (m_vector,
-			     this->m_symtab->cgraph_max_summary_id);
+      {
+	int newlen = this->m_symtab->cgraph_max_summary_id;
+	vec_safe_reserve (m_vector, newlen - m_vector->length ());
+	m_vector->quick_grow_cleared (newlen);
+      }
  
      if ((*m_vector)[id] == NULL)
        (*m_vector)[id] = this->allocate_new ();
@@ -812,7 +815,11 @@ public:
        id = this->m_symtab->assign_summary_id (edge);
  
      if ((unsigned)id >= m_vector->length ())
-      vec_safe_grow_cleared (m_vector, this->m_symtab->edges_max_summary_id);
+      {
+	int newlen = this->m_symtab->edges_max_summary_id;
+	m_vector->reserve (newlen - m_vector->length ());
+	m_vector->quick_grow_cleared (newlen);
+      }
  
      if ((*m_vector)[id] == NULL)
        (*m_vector)[id] = this->allocate_new ();
diff --git a/gcc/vec.h b/gcc/vec.h
index bd7c7351dcd..3ad99b83690 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -753,6 +753,17 @@ vec_safe_grow_cleared (vec<T, va_heap, vl_ptr> *&v,
    v->safe_grow_cleared (len PASS_MEM_STAT);
  }
  
+/* If V does not have space for NELEMS elements, call
+   V->reserve(NELEMS, EXACT).  */
+
+template<typename T>
+inline bool
+vec_safe_reserve (vec<T, va_heap, vl_ptr> *&v, unsigned nelems, bool exact = false
+		  CXX_MEM_STAT_INFO)
+{
+  return v->reserve (nelems, exact);
+}
+
  
  /* If V is NULL return false, otherwise return V->iterate(IX, PTR).  */
  template<typename T, typename A>
-- 
2.27.0


^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2020-09-01 13:00 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-25 12:22 [PATCH] Use vec::reserve before vec_safe_grow_cleared is called Martin Liška
2020-07-27  7:11 ` Richard Biener
2020-07-27  7:14   ` Martin Liška
2020-07-27  9:51     ` Jan Hubicka
2020-07-27 10:29       ` Martin Liška
2020-07-27 10:48         ` Jan Hubicka
2020-07-27 11:00           ` Martin Liška
2020-07-27 11:03             ` Jan Hubicka
2020-07-27 11:22               ` Martin Liška
2020-07-27 12:49                 ` Andreas Schwab
2020-07-27 12:51                   ` Richard Biener
2020-07-27 12:54                     ` Martin Liška
2020-07-27 12:58                       ` Richard Biener
2020-07-27 11:07           ` Richard Biener
2020-07-27 11:11     ` Jan Hubicka
2020-07-27 11:24       ` Martin Liška
2020-07-27 11:31         ` Richard Biener
2020-07-28 10:23           ` [PATCH] Use exact=false for vec_safe_grow{,_cleared} functions Martin Liška
2020-07-29 13:47             ` Richard Biener
2020-07-30 13:22               ` Martin Liška
2020-08-03 13:47                 ` Richard Biener
2020-08-11 11:36                   ` [PATCH 1/3] vec: add exact argument for various grow functions Martin Liška
2020-08-11 11:37                     ` [PATCH 2/3] vec: default exact = false in " Martin Liška
2020-08-26 21:00                       ` Jeff Law
2020-08-11 11:37                     ` [PATCH 3/3] vec: use inexact growth where possible Martin Liška
2020-08-26 21:02                       ` Jeff Law
2020-08-27  8:54                         ` Richard Biener
2020-09-01 11:25                           ` Martin Liška
2020-09-01 13:00                             ` Richard Biener
2020-08-11 14:58                     ` [PATCH 1/3] vec: add exact argument for various grow functions Martin Sebor
2020-08-12 12:28                       ` Martin Liška
2020-08-13  0:18                         ` Martin Sebor
2020-08-26 13:54                         ` Martin Liška
2020-08-27 23:29                           ` Martin Sebor
2020-08-28  6:49                             ` Martin Liška
2020-08-28 14:35                               ` Martin Sebor
2020-08-26 20:59                     ` Jeff Law
2020-08-28 14:24                     ` Andrew Stubbs
2020-08-28 14:26                       ` Martin Liška
2020-08-28 14:44                         ` Andrew Stubbs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).