Reduce memory consumption for push/pop_access_scope.
authorJason Merrill <jason@redhat.com>
Sat, 20 Jul 2019 13:48:38 +0000 (09:48 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 20 Jul 2019 13:48:38 +0000 (09:48 -0400)
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

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/name-lookup.c
gcc/cp/pt.c

index c776243d973e44a7db91641470eae9dc54fe7d82..0c6a7de94d92e214abea716b4653d951bd93364d 100644 (file)
@@ -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
index f77b7f4834b200d4308f21017e407bb1ca32cd68..b61152c7e72f03f7ca1c6597e7dc257ffac4f39f 100644 (file)
@@ -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.  */
 
index ad866298fa5d44c65760663f5e7da2a553ec2c8e..9f278220df30537c164664d7d414178041c2f3a9 100644 (file)
@@ -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)
 {
index b6eda7eb27c38ef320c07ead3bab2fb890577ce3..deaac576468052bfa94d1386fc48342e5ef8543d 100644 (file)
@@ -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 ();