Commit 1ab1f350 by Jason Merrill Committed by Jason Merrill

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
parent 554a530f
2019-07-20 Jason Merrill <jason@redhat.com>
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 <jakub@redhat.com> 2019-07-20 Jakub Jelinek <jakub@redhat.com>
* cp-tree.h (OMP_FOR_GIMPLIFYING_P): Use OMP_LOOPING_CHECK * cp-tree.h (OMP_FOR_GIMPLIFYING_P): Use OMP_LOOPING_CHECK
......
...@@ -7588,16 +7588,6 @@ pushclass (tree type) ...@@ -7588,16 +7588,6 @@ pushclass (tree type)
restore_class_cache (); 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 /* Get out of the current class scope. If we were in a class scope
previously, that is the one popped to. */ previously, that is the one popped to. */
......
...@@ -3392,7 +3392,7 @@ leave_scope (void) ...@@ -3392,7 +3392,7 @@ leave_scope (void)
namespace. For classes, we cache some binding levels. For other namespace. For classes, we cache some binding levels. For other
scopes, we just make the structure available for reuse. */ scopes, we just make the structure available for reuse. */
if (scope->kind != sk_namespace if (scope->kind != sk_namespace
&& scope->kind != sk_class) && scope != previous_class_level)
{ {
scope->level_chain = free_binding_level; scope->level_chain = free_binding_level;
gcc_assert (!ENABLE_SCOPE_CHECKING gcc_assert (!ENABLE_SCOPE_CHECKING
...@@ -3420,6 +3420,18 @@ leave_scope (void) ...@@ -3420,6 +3420,18 @@ leave_scope (void)
return current_binding_level; 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 static void
resume_scope (cp_binding_level* b) resume_scope (cp_binding_level* b)
{ {
......
...@@ -67,7 +67,7 @@ static vec<int> inline_parm_levels; ...@@ -67,7 +67,7 @@ static vec<int> inline_parm_levels;
static GTY(()) struct tinst_level *current_tinst_level; static GTY(()) struct tinst_level *current_tinst_level;
static GTY(()) tree saved_access_scope; static GTY(()) vec<tree, va_gc> *saved_access_scope;
/* Live only within one (recursive) call to tsubst_expr. We use /* Live only within one (recursive) call to tsubst_expr. We use
this to pass the statement expression node from the STMT_EXPR this to pass the statement expression node from the STMT_EXPR
...@@ -247,8 +247,7 @@ push_access_scope (tree t) ...@@ -247,8 +247,7 @@ push_access_scope (tree t)
if (TREE_CODE (t) == FUNCTION_DECL) if (TREE_CODE (t) == FUNCTION_DECL)
{ {
saved_access_scope = tree_cons vec_safe_push (saved_access_scope, current_function_decl);
(NULL_TREE, current_function_decl, saved_access_scope);
current_function_decl = t; current_function_decl = t;
} }
} }
...@@ -260,10 +259,7 @@ static void ...@@ -260,10 +259,7 @@ static void
pop_access_scope (tree t) pop_access_scope (tree t)
{ {
if (TREE_CODE (t) == FUNCTION_DECL) if (TREE_CODE (t) == FUNCTION_DECL)
{ current_function_decl = saved_access_scope->pop();
current_function_decl = TREE_VALUE (saved_access_scope);
saved_access_scope = TREE_CHAIN (saved_access_scope);
}
if (DECL_FRIEND_CONTEXT (t) || DECL_CLASS_SCOPE_P (t)) if (DECL_FRIEND_CONTEXT (t) || DECL_CLASS_SCOPE_P (t))
pop_nested_class (); pop_nested_class ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment