From: Martin Liska Date: Fri, 24 Jul 2020 12:33:27 +0000 (+0200) Subject: Use vec::reserve before vec_safe_grow_cleared is called X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7f5c0f328eced560a204bb8e3eae0d45795dd235;p=gcc.git Use vec::reserve before vec_safe_grow_cleared is called 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. --- 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 *&v, v->safe_grow_cleared (len PASS_MEM_STAT); } +/* If V does not have space for NELEMS elements, call + V->reserve(NELEMS, EXACT). */ + +template +inline bool +vec_safe_reserve (vec *&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