From 7f5c0f328eced560a204bb8e3eae0d45795dd235 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 24 Jul 2020 14:33:27 +0200 Subject: [PATCH] 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. --- 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 a38eb1d..fa1df5c 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 bd7c7351..3ad99b8 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 -- 2.7.4