From patchwork Sat Jul 20 13:48:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1134380 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-505363-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="YnhZBvm6"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45rTjZ5sQsz9sNC for ; Sat, 20 Jul 2019 23:48:32 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version :content-transfer-encoding; q=dns; s=default; b=o4GMbMAciadKJFBL vk5PEpbE6SwPEjM0XmzUPv/tpJjJqK+3n0SaHosqzvMD27B+CVkusYsnzUFj9vtn dEDTaOhRQosXtgihywDqI0URA1S4NgyKCgHxzsJt9s7AIEbZYC/+thG+kxqL4nI2 zSZ2sZJ99QhN6YXi0jPp6fLZq6s= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version :content-transfer-encoding; s=default; bh=4EzypX3HYswoiMywH2AFw8 fuBcU=; b=YnhZBvm6Z6pkZWlQMvUabQqVOLy/llAlm/IZFB9o4l/bI6Zjup7gF+ OT1K3s1uTK8JyTvd2DO6Bd5J0pVOtChaIWx6pK5si6Gj5MHmNI6u1aQtkuJaOizJ 1M6OY5XPTTy7ERLSCDwWaKPbCwuDcCOabe6KqpLmYRRhRcUsB8Hy8= Received: (qmail 105429 invoked by alias); 20 Jul 2019 13:48:22 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 105409 invoked by uid 89); 20 Jul 2019 13:48:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=our X-HELO: mail-wm1-f65.google.com Received: from mail-wm1-f65.google.com (HELO mail-wm1-f65.google.com) (209.85.128.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 20 Jul 2019 13:48:19 +0000 Received: by mail-wm1-f65.google.com with SMTP id s3so31145067wms.2 for ; Sat, 20 Jul 2019 06:48:19 -0700 (PDT) Received: from localhost.localdomain ([46.183.103.8]) by smtp.gmail.com with ESMTPSA id k124sm53297596wmk.47.2019.07.20.06.48.14 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 20 Jul 2019 06:48:15 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Reduce memory consumption for push/pop_access_scope. Date: Sat, 20 Jul 2019 15:48:11 +0200 Message-Id: <20190720134811.21998-1-jason@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes 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. Tested x86_64-pc-linux-gnu, applying to trunk. * 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. --- gcc/cp/class.c | 10 ---------- gcc/cp/name-lookup.c | 14 +++++++++++++- gcc/cp/pt.c | 10 +++------- gcc/cp/ChangeLog | 9 +++++++++ 4 files changed, 25 insertions(+), 18 deletions(-) base-commit: 31890b5844874e62a52e52b4edf6fc558a9dc8d6 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 (); 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