From patchwork Sun Aug 26 02:08:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cary Coutant X-Patchwork-Id: 180020 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 431682C0104 for ; Sun, 26 Aug 2012 12:08:29 +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=1346551709; 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=0+GlHQ+ 9Kj8biKlhvE/6HxCBoaM=; b=MZANjJwWdTuqoTVm0gF5s+Fvzi9cM+OvlOZsnWC D45ECOMfvDupTa/vl6wdenZI5TIFHOybA0fDvijIXbnGbX6XGpmOX6RATWELgXzR cduLjsM+TcREsDaF0Q/BfERDnctrhf/WFO03E0s5WKb/2sKM+lSUCLdwSv1iwH9A UAmA= 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=Ka2dbh1TfDyg+18q6Dh6BHVHBWCL24CRYxE9Ncpfq/b1uzVttY7DEMgVztsZ4N 5OdTwNe6gZoxdBkvImX3s0LYl1kPTr59yvZRzFpoksnV7/1pefYHJrIMRTThimk8 14mKQj+rWh0nBQwzKuca+4Jr2mPQsS24KJ59fNC4jrRMQ=; Received: (qmail 25578 invoked by alias); 26 Aug 2012 02:08:24 -0000 Received: (qmail 25566 invoked by uid 22791); 26 Aug 2012 02:08:22 -0000 X-SWARE-Spam-Status: No, hits=-4.3 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-wi0-f201.google.com (HELO mail-wi0-f201.google.com) (209.85.212.201) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 26 Aug 2012 02:08:09 +0000 Received: by wibhm2 with SMTP id hm2so83889wib.2 for ; Sat, 25 Aug 2012 19:08:08 -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=O3CkUeDHwULNQ4oEX2hIYK3nOM4De/bgOzAoyyk53aI=; b=lUXqeOSfs6A8VwTE/r8kZrf00L3SeOe96MWRcf/WKz8MPghr5uH6oJtZaiqZFB5nT7 fkky4Fgy3fRZbq8q/A33Y30i+6bGlX05E5tdRgY+G1u992YnIBWvBk+V/SiE5unB6HDR Zq8PESXtgNg7YfpA2NdCq5lqVFFxO6TUpwG8sWmQMVFhqWgQaRCa+HgC7ISBBPh6YS5J LxnWsFreGutz9hLgM/d7hS9gdf1SmnczQv/ZCbfvKD3YYhgIb7tFP2SziVN63Pz45+rX Bw9w4+YhvVhSXSRA5o/ZGh32zuqNslGhGHtOEltwsHunfsRvIsf3VK+siEcII/4h5IfS vI4w== Received: by 10.180.105.38 with SMTP id gj6mr1043861wib.0.1345946888268; Sat, 25 Aug 2012 19:08:08 -0700 (PDT) Received: by 10.180.105.38 with SMTP id gj6mr1043857wib.0.1345946888213; Sat, 25 Aug 2012 19:08:08 -0700 (PDT) Received: from hpza9.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id e5si681154wiw.0.2012.08.25.19.08.08 (version=TLSv1/SSLv3 cipher=AES128-SHA); Sat, 25 Aug 2012 19:08:08 -0700 (PDT) Received: from ccoutant.mtv.corp.google.com (ccoutant.mtv.corp.google.com [172.18.110.42]) by hpza9.eem.corp.google.com (Postfix) with ESMTP id CA5185C0060; Sat, 25 Aug 2012 19:08:07 -0700 (PDT) Received: by ccoutant.mtv.corp.google.com (Postfix, from userid 62097) id F0D2DE041B; Sat, 25 Aug 2012 19:08:06 -0700 (PDT) To: comdat-type-template-patch.txt@google.com, gcc-patches@gcc.gnu.org, jason@redhat.com, ppluzhnikov@google.com Subject: [google/gcc-4_7, trunk] Fix problem with -fdebug-types-section and template instantiations Message-Id: <20120826020806.F0D2DE041B@ccoutant.mtv.corp.google.com> Date: Sat, 25 Aug 2012 19:08:06 -0700 (PDT) From: ccoutant@google.com (Cary Coutant) X-Gm-Message-State: ALoCoQmECQAOXDopVC/WUjJj7PKiD2JON/syf7PZcZwcO/NoAg4rfHIHZZumhm6NPuGIhUVxlT+dFR/ErYUrLLN5cQhGgZBwZDrvJHGxBpHh9pORvIA9b+TUKWywD3yt+MBbRj28EfVUyasj3I2GmBKbOcEOTZPaK1jBo6z8knnrQico7n9sQZXMjPvCijPvX4ZnP0UQAigBGPd5gSnPiCqdKAjm2av4H0F53mScM5Am99JopFw/GWw= 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. Because instantiations typically happen in .cc files, and the resulting type definition is unlikely to be useful as a comdat type unit, this patch avoids the problem by choosing not to move template instantiations into type units. 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-25 Cary Coutant gcc/ * dwarf2out.c (is_template_instantiation): New function. (should_move_die_to_comdat): Reject types that are template instantiations. Index: gcc/dwarf2out.c =================================================================== --- gcc/dwarf2out.c (revision 190681) +++ gcc/dwarf2out.c (working copy) @@ -7277,6 +7277,21 @@ contains_subprogram_definition (dw_die_r return 0; } +/* Return non-zero if this DIE represents a template instantiation. */ + +static int +is_template_instantiation (dw_die_ref die) +{ + dw_die_ref c; + + FOR_EACH_CHILD (die, c, + if (c->die_tag == DW_TAG_template_type_param + || c->die_tag == DW_TAG_template_value_param + || c->die_tag == DW_TAG_GNU_template_template_param) + return 1); + return 0; +} + /* Return non-zero if this is a type DIE that should be moved to a COMDAT .debug_types section. */ @@ -7294,6 +7309,7 @@ should_move_die_to_comdat (dw_die_ref di if (is_declaration_die (die) || get_AT (die, DW_AT_abstract_origin) || is_nested_in_subprogram (die) + || is_template_instantiation (die) || contains_subprogram_definition (die)) return 0; return 1;