From patchwork Thu Jun 21 18:16:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 932876 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-480221-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="Afrsytdj"; 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 41BVKQ6rkGz9s47 for ; Fri, 22 Jun 2018 04:17:13 +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 :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=MXghd7uG1Jduu9kVVH+RWqDQ5N1r/SjWRGlKakAtfGyRLq sLuqanr60JIn8g12vEx0hg0oIpjgZeM4LhKGH4crl7Czg92H4SRB/66AuFrBAlL6 nIl9zOGOAOcTzU+X6/WFaxJdEWA/LLevS8ydRHB9CJ3lq/1TUvNDLEvsp1Qko= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=3todhka8V3wW//mlet1suB4dNc8=; b=AfrsytdjDNXZ6pUkcRvJ QljIKbIC4INfEytb7kj3jQ+9h0vcQhPiHHUvnTvvoVDTb75W5H3GwIW52FkDeRfq Cx/fNdmPYOUdOqllaP/c7hRp7f1x9Rf/3f/zqsvKwL9EDbHdjBd5mCA/Utzzclfr AqhQdFHWe5okr7mIhE5GR/8= Received: (qmail 104760 invoked by alias); 21 Jun 2018 18:17:06 -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 104749 invoked by uid 89); 21 Jun 2018 18:17:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=peak, UD:lex.c, lexc, lex.c X-HELO: mail-ot0-f179.google.com Received: from mail-ot0-f179.google.com (HELO mail-ot0-f179.google.com) (74.125.82.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Jun 2018 18:17:03 +0000 Received: by mail-ot0-f179.google.com with SMTP id 101-v6so4639806oth.4 for ; Thu, 21 Jun 2018 11:17:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=l4UxWJYUqYq2XaFFfhCRsDNaelpP3+UxMECK5BlmelE=; b=gd+cFyHwwZtcVdyR50nd391/ltWGCLd9GJwQ0n5yeOvtLTiow69fYu6plZv9Z82tEk 3qIJoeyWIgPgT9jmKqKU1ITDxOcp4oXwFLK0kw6Q3j/7GcWpbUAbImHjbOi93QQP49ca ihFvZuassc4R2fdFLmG+6uLzsOdKhRzCc5FjiSs9ALroMAkd94QL97gcgEz3XzJNl74C IQwzceI5JfhebJsOXMZhlpUxABS3u3i3lcNrSX3pZMBrpJSYFchTO5tTT55yGhsD/MwM AAg88UIi9zpJ8O9dQjz8A/YJ/KhMmrY4DOM7GaP+Bnn4/andCLNlDgslwmLw/EH5iJux F+Qg== X-Gm-Message-State: APt69E0ILfIoV4p+TGiQPuPueJt2keawmM2cCtFe+fJAI6TZ0YVZkXdD ZjSel3sXKsoGm9ozVPQRAODhmt2QNhneyNLKzV6kvyYk X-Google-Smtp-Source: ADUXVKJpeYs1i4CeXG74PCTacC1tw4P3Ost9clo4rwh4OBCTn73wYXv6Nd4CPKwcP4iWcwk514txc5nRaimA5GefMT8= X-Received: by 2002:a9d:5302:: with SMTP id g2-v6mr15564100oth.277.1529605021877; Thu, 21 Jun 2018 11:17:01 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ac9:dd0:0:0:0:0:0 with HTTP; Thu, 21 Jun 2018 11:16:41 -0700 (PDT) From: Jason Merrill Date: Thu, 21 Jun 2018 14:16:41 -0400 Message-ID: Subject: C++ PATCHes for improved template memory use To: gcc-patches List X-IsSubscribed: yes I've been looking at -fmem-report for a testcase from someone on the committee, and found a couple of low-hanging fruits. The first patch doesn't change any allocation, just makes it so -fmem-report can see who's calling cxx_make_type. The second patch avoids creating a vector (which we then never freed) every time we push_to_top_level for doing template instantiation. This alone improved peak memory use by 30%. The third patch avoids redundantly creating level-lowered versions of TEMPLATE_TYPE_PARM, as we had already been doing for non-type parameters. This improved peak memory use by another 20%. Unfortunately, these don't affect the 80290 testcase significantly. Tested x86_64-pc-linux-gnu, applying to trunk. commit 93ca12c981968b5d545f1428d7b6d47557f207f7 Author: Jason Merrill Date: Wed Jun 20 12:36:29 2018 -0400 * pt.c (tsubst) [TEMPLATE_TYPE_PARM]: Use TEMPLATE_PARM_DESCENDANTS. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index c5433dc46ae..69e9479302e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14472,6 +14472,15 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) && !PLACEHOLDER_TYPE_CONSTRAINTS (r)) /* Break infinite recursion when substituting the constraints of a constrained placeholder. */; + else if (TREE_CODE (t) == TEMPLATE_TYPE_PARM + && !PLACEHOLDER_TYPE_CONSTRAINTS (t) + && !CLASS_PLACEHOLDER_TEMPLATE (t) + && (arg = TEMPLATE_TYPE_PARM_INDEX (t), + r = TEMPLATE_PARM_DESCENDANTS (arg)) + && (TEMPLATE_PARM_LEVEL (r) + == TEMPLATE_PARM_LEVEL (arg) - levels)) + /* Cache the simple case of lowering a type parameter. */ + r = TREE_TYPE (r); else { r = copy_type (t);