aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2019-07-20 09:48:38 -0400
committerJason Merrill <jason@gcc.gnu.org>2019-07-20 09:48:38 -0400
commit1ab1f3502038323f6f5cd8c16c0ac1b1416e3545 (patch)
tree2728d6a496766f5f19f687cb4c31bd09a0435041
parent554a530ff81870098572832eed8ca00b3593bb41 (diff)
downloadgcc-1ab1f3502038323f6f5cd8c16c0ac1b1416e3545.zip
gcc-1ab1f3502038323f6f5cd8c16c0ac1b1416e3545.tar.gz
gcc-1ab1f3502038323f6f5cd8c16c0ac1b1416e3545.tar.bz2
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
-rw-r--r--gcc/cp/ChangeLog9
-rw-r--r--gcc/cp/class.c10
-rw-r--r--gcc/cp/name-lookup.c14
-rw-r--r--gcc/cp/pt.c10
4 files changed, 25 insertions, 18 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c776243..0c6a7de 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,12 @@
+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>
* cp-tree.h (OMP_FOR_GIMPLIFYING_P): Use OMP_LOOPING_CHECK
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index f77b7f4..b61152c 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 ad86629..9f27822 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 b6eda7e..deaac57 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -67,7 +67,7 @@ static vec<int> inline_parm_levels;
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
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 ();