From: Jason Merrill Date: Sat, 20 Jul 2019 13:48:38 +0000 (-0400) Subject: Reduce memory consumption for push/pop_access_scope. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1ab1f3502038323f6f5cd8c16c0ac1b1416e3545;p=gcc.git Reduce memory consumption for push/pop_access_scope. I was seeing memory consumption issues on the concepts-cxx2a branch. push_scope was, surprisingly, at the top of -fmem-report, and push_access_scope was pretty high. Fixing them was pretty simple. * name-lookup.c (leave_scope): Do add class levels other than previous_class_level to free_binding_level. (invalidate_class_lookup_cache): Move from class.c, add to free_binding_level. * pt.c (saved_access_scope): Change from list to vec. From-SVN: r273622 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c776243d973..0c6a7de94d9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2019-07-20 Jason Merrill + + Reduce memory consumption for push/pop_access_scope. + * name-lookup.c (leave_scope): Do add class levels other than + previous_class_level to free_binding_level. + (invalidate_class_lookup_cache): Move from class.c, add to + free_binding_level. + * pt.c (saved_access_scope): Change from list to vec. + 2019-07-20 Jakub Jelinek * cp-tree.h (OMP_FOR_GIMPLIFYING_P): Use OMP_LOOPING_CHECK diff --git a/gcc/cp/class.c b/gcc/cp/class.c index f77b7f4834b..b61152c7e72 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -7588,16 +7588,6 @@ pushclass (tree type) restore_class_cache (); } -/* When we exit a toplevel class scope, we save its binding level so - that we can restore it quickly. Here, we've entered some other - class, so we must invalidate our cache. */ - -void -invalidate_class_lookup_cache (void) -{ - previous_class_level = NULL; -} - /* Get out of the current class scope. If we were in a class scope previously, that is the one popped to. */ diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index ad866298fa5..9f278220df3 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -3392,7 +3392,7 @@ leave_scope (void) namespace. For classes, we cache some binding levels. For other scopes, we just make the structure available for reuse. */ if (scope->kind != sk_namespace - && scope->kind != sk_class) + && scope != previous_class_level) { scope->level_chain = free_binding_level; gcc_assert (!ENABLE_SCOPE_CHECKING @@ -3420,6 +3420,18 @@ leave_scope (void) return current_binding_level; } +/* When we exit a toplevel class scope, we save its binding level so + that we can restore it quickly. Here, we've entered some other + class, so we must invalidate our cache. */ + +void +invalidate_class_lookup_cache (void) +{ + previous_class_level->level_chain = free_binding_level; + free_binding_level = previous_class_level; + previous_class_level = NULL; +} + static void resume_scope (cp_binding_level* b) { diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b6eda7eb27c..deaac576468 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -67,7 +67,7 @@ static vec inline_parm_levels; static GTY(()) struct tinst_level *current_tinst_level; -static GTY(()) tree saved_access_scope; +static GTY(()) vec *saved_access_scope; /* Live only within one (recursive) call to tsubst_expr. We use this to pass the statement expression node from the STMT_EXPR @@ -247,8 +247,7 @@ push_access_scope (tree t) if (TREE_CODE (t) == FUNCTION_DECL) { - saved_access_scope = tree_cons - (NULL_TREE, current_function_decl, saved_access_scope); + vec_safe_push (saved_access_scope, current_function_decl); current_function_decl = t; } } @@ -260,10 +259,7 @@ static void pop_access_scope (tree t) { if (TREE_CODE (t) == FUNCTION_DECL) - { - current_function_decl = TREE_VALUE (saved_access_scope); - saved_access_scope = TREE_CHAIN (saved_access_scope); - } + current_function_decl = saved_access_scope->pop(); if (DECL_FRIEND_CONTEXT (t) || DECL_CLASS_SCOPE_P (t)) pop_nested_class ();