Use vec::reserve before vec_safe_grow_cleared is called
authorMartin Liska <mliska@suse.cz>
Fri, 24 Jul 2020 12:33:27 +0000 (14:33 +0200)
committerMartin Liska <mliska@suse.cz>
Mon, 27 Jul 2020 07:16:16 +0000 (09:16 +0200)
gcc/ChangeLog:

PR lto/45375
* 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
gcc/vec.h

index a38eb1db7787e62e888be8921af9309d85ba5d4f..fa1df5c8015698787c9593d263d1cae1bd53e2ba 100644 (file)
@@ -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 ();
index bd7c7351dcd98c0809956de5511a52d318f74723..3ad99b8369047056509c5ad1d5ec4ee311d06b70 100644 (file)
--- 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>