From patchwork Wed Aug 29 05:56:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cary Coutant X-Patchwork-Id: 180623 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 97FD62C00AD for ; Wed, 29 Aug 2012 15:57:17 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1346824639; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:Received:To:Subject:Message-Id:Date: From:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=4ZUroL4 YG+ccAspycuKnzMJ+Oyw=; b=tOw1tDIRZfu/6YKaTxGQEC2N5uO+ie2TTX2470R uFNvZqOy+n25dVoOw1NJH7GWCmKUgWLjGIamdgtXAJ/ngDpIdzYhqBiXkcg+imuy HgTMDpEw32YiS5rVC90E0bJwre+V0JDXOyXrVB9hL4TX2rRH02tT/sN0jywkOfYw 1d/0= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:Received:Received:Received:To:Subject:Message-Id:Date:From:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=wW28b5vyG03AIzBGW0n0oQXPaqNVhzztkmc6BWrMicGuJyL+Kgj+mvUa9JEMcl fW0kvvJ/I+prAIBfNsCxKe6/UTjojlaHAbQ8KabLkkzew4ynqTwrCGkOdYU7F2eA eww0gJiKFmo5KTnUWvM5FT1Npcb2PlRV87hquZ5T2pIVQ=; Received: (qmail 25614 invoked by alias); 29 Aug 2012 05:57:11 -0000 Received: (qmail 25606 invoked by uid 22791); 29 Aug 2012 05:57:09 -0000 X-SWARE-Spam-Status: No, hits=-3.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-yx0-f201.google.com (HELO mail-yx0-f201.google.com) (209.85.213.201) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 29 Aug 2012 05:56:56 +0000 Received: by yenr11 with SMTP id r11so20074yen.2 for ; Tue, 28 Aug 2012 22:56:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=to:subject:message-id:date:from:x-gm-message-state; bh=SLAHbRdNbmDJjuSsFCe4PrlVsloZw0d/Qd+JV8fKdlM=; b=SBEG7Ds2PZZFxZmSmYJIW6zw8GWaMKuRPLVbKxq9VgqpayI63tYcNpCBpmrYRJcGq8 Yjnoq2jXcYVJWfdm1Y91FUcfy9fu9SZxGFqEuCUoF6jwRSG9UakS8Gl0FpaM2aJqUHuj cg3wYDWf974kR2DlCUsJj6OQtyqBGAuA0N8E0PqLfoubqfc/SmbcjSM37nb7lAz86bK+ CkN1bit8SGd8GYxY4g2q+k2aBSg25NkaGdVty1MCOPzlKabYNHzhT1J7FMrdZxbgkr4y lGROQgBWWXmVgjR+CX9Fw9cNl30bqyowCiH54GkGYVoRNvyLt87UYzmokVoL5qwm7l6M /tkQ== Received: by 10.236.185.103 with SMTP id t67mr302175yhm.49.1346219815396; Tue, 28 Aug 2012 22:56:55 -0700 (PDT) Received: by 10.236.185.103 with SMTP id t67mr302166yhm.49.1346219815332; Tue, 28 Aug 2012 22:56:55 -0700 (PDT) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id t29si6739224yha.0.2012.08.28.22.56.55 (version=TLSv1/SSLv3 cipher=AES128-SHA); Tue, 28 Aug 2012 22:56:55 -0700 (PDT) Received: from ccoutant.mtv.corp.google.com (ccoutant.mtv.corp.google.com [172.18.110.42]) by wpzn4.hot.corp.google.com (Postfix) with ESMTP id 246821E0043; Tue, 28 Aug 2012 22:56:55 -0700 (PDT) Received: by ccoutant.mtv.corp.google.com (Postfix, from userid 62097) id B777DE0838; Tue, 28 Aug 2012 22:56:54 -0700 (PDT) To: gcc-patches@gcc.gnu.org, jason@redhat.com, saugustine@google.com Subject: [google/gcc-4_7, trunk] Fix problem with -fdebug-types-section and template instantiations, take 2 Message-Id: <20120829055654.B777DE0838@ccoutant.mtv.corp.google.com> Date: Tue, 28 Aug 2012 22:56:54 -0700 (PDT) From: ccoutant@google.com (Cary Coutant) X-Gm-Message-State: ALoCoQluaZFuymicdphuKXKpj/Z/mLPeR30RHaUF3dWAh18yGYYEs/off1mM6eCZkXBlN5d41veD9mB7X7EB2NMJIV1HIXYjh5nsy3me08vvL5AEVBm9tVCi9R+rFTG3A/hZLTjkps4mR5AW7Ms/byRdlt+14beMfBEpEbl2SOUmFjuJfXGUsSTgXMTorCOkrgeojGHzqf0ZaIuv7fGFVuAaMZZ37yBeOweImg6Y7ULYfegDWQ0GB9Q= X-IsSubscribed: yes 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 This patch is for trunk and the google/gcc-4_7 branch. When a class template instantiation is moved into a separate type unit, it can bring along a lot of other referenced types into the type unit, especially if the template is derived from another (large) type that does not have an actually have a type definition in a type unit of its own. When there are many instantiations of the same template, we get a lot of duplication, and in the worst case (a template with several parameters, instantiated multiple times along each dimension), GCC can end up taking a long time and exhausting available memory. This combinatorial explosion is being caused by copy_decls_walk, where it finds a type DIE that is referenced by the type unit, but is not itself a type unit, and copies a declaration for that type into the type unit in order to resolve the reference within the type unit. In the process, copy_decls_walk also copies all of the children of that DIE. In the case of a base class with member function templates, every one of the instantiated member functions is copied into every type unit that references the base class. I don't believe that it's necessary to copy the children of the class declaration at all, and this patch simply removes the code that copies those children. If there's a reference in the type unit to one of the children of that class, that one child will get copied in as needed. Bootstraps and passes regression tests. Also tested with a large internal test case that previously resulted in out-of-memory during compilation. Google ref b/7041390. 2012-08-28 Cary Coutant * gcc/dwarf2out.c (clone_tree_partial): Remove. (copy_decls_walk): Don't copy children of a declaration into a type unit. Index: gcc/dwarf2out.c =================================================================== --- gcc/dwarf2out.c (revision 190681) +++ gcc/dwarf2out.c (working copy) @@ -7745,40 +7745,6 @@ copy_ancestor_tree (dw_die_ref unit, dw_ return copy; } -/* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations. - Enter all the cloned children into the hash table decl_table. */ - -static dw_die_ref -clone_tree_partial (dw_die_ref die, htab_t decl_table) -{ - dw_die_ref c; - dw_die_ref clone; - struct decl_table_entry *entry; - void **slot; - - if (die->die_tag == DW_TAG_subprogram) - clone = clone_as_declaration (die); - else - clone = clone_die (die); - - slot = htab_find_slot_with_hash (decl_table, die, - htab_hash_pointer (die), INSERT); - /* Assert that DIE isn't in the hash table yet. If it would be there - before, the ancestors would be necessarily there as well, therefore - clone_tree_partial wouldn't be called. */ - gcc_assert (*slot == HTAB_EMPTY_ENTRY); - entry = XCNEW (struct decl_table_entry); - entry->orig = die; - entry->copy = clone; - *slot = entry; - - if (die->die_tag != DW_TAG_subprogram) - FOR_EACH_CHILD (die, c, - add_child_die (clone, clone_tree_partial (c, decl_table))); - - return clone; -} - /* Walk the DIE and its children, looking for references to incomplete or trivial types that are unmarked (i.e., that are not in the current type_unit). */ @@ -7826,11 +7792,6 @@ copy_decls_walk (dw_die_ref unit, dw_die entry->copy = copy; *slot = entry; - FOR_EACH_CHILD (targ, c, - add_child_die (copy, - clone_tree_partial (c, - decl_table))); - /* Make sure the cloned tree is marked as part of the type unit. */ mark_dies (copy);