From patchwork Mon Jul 18 16:39:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Novillo X-Patchwork-Id: 105331 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 D68ACB6F70 for ; Tue, 19 Jul 2011 02:39:46 +1000 (EST) Received: (qmail 9865 invoked by alias); 18 Jul 2011 16:39:44 -0000 Received: (qmail 9748 invoked by uid 22791); 18 Jul 2011 16:39:42 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 18 Jul 2011 16:39:07 +0000 Received: from kpbe20.cbf.corp.google.com (kpbe20.cbf.corp.google.com [172.25.105.84]) by smtp-out.google.com with ESMTP id p6IGd5r0028258; Mon, 18 Jul 2011 09:39:05 -0700 Received: from topo.tor.corp.google.com (topo.tor.corp.google.com [172.29.41.2]) by kpbe20.cbf.corp.google.com with ESMTP id p6IGd33P020754; Mon, 18 Jul 2011 09:39:03 -0700 Received: by topo.tor.corp.google.com (Postfix, from userid 54752) id C56811DA1CD; Mon, 18 Jul 2011 12:39:02 -0400 (EDT) To: reply@codereview.appspotmail.com, crowl@google.com, gchare@google.com, gcc-patches@gcc.gnu.org Subject: [pph] Do not emit the same decl more than once in the symbol table (issue4758052) Message-Id: <20110718163902.C56811DA1CD@topo.tor.corp.google.com> Date: Mon, 18 Jul 2011 12:39:02 -0400 (EDT) From: dnovillo@google.com (Diego Novillo) X-System-Of-Record: true 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 A small tweak to avoid inserting the same decl more than once in the symbol table for a pph image. Tested on x86_64. Committed to branch. Diego. * pph-streamer-in.c (pph_in_struct_function): Revert previous change. Do not allow shared struct functions. * pph-streamer-out.c (decls_to_register_t): New type. (decls_to_register): Change type to decls_to_register_t. Update all users. (pph_add_decl_to_register): Do not register the same DECL more than once. --- This patch is available for review at http://codereview.appspot.com/4758052 diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c index 0808cab..f1aa7c9 100644 --- a/gcc/cp/pph-streamer-in.c +++ b/gcc/cp/pph-streamer-in.c @@ -819,18 +819,14 @@ pph_in_struct_function (pph_stream *stream) marker = pph_in_start_record (stream, &ix); if (marker == PPH_RECORD_END) return NULL; - else if (marker == PPH_RECORD_SHARED) - return (struct function *) pph_in_shared_data (stream, ix); - decl = pph_in_tree (stream); + /* Since struct function is embedded in every decl, fn cannot be shared. */ + gcc_assert (marker != PPH_RECORD_SHARED); + decl = pph_in_tree (stream); allocate_struct_function (decl, false); fn = DECL_STRUCT_FUNCTION (decl); - /* Now register it. We would normally use ALLOC_AND_REGISTER, - but retrofit_lang_decl does not return a pointer. */ - pph_register_shared_data (stream, fn, ix); - input_struct_function_base (fn, stream->data_in, stream->ib); /* struct eh_status *eh; -- zero init */ diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c index ee294df..15a0c53 100644 --- a/gcc/cp/pph-streamer-out.c +++ b/gcc/cp/pph-streamer-out.c @@ -43,7 +43,16 @@ static FILE *current_pph_file = NULL; we finish parsing the header file, this array is written out to the PPH image. This way, the reader will be able to instantiate these symbols in the same order that they were instantiated originally. */ -static VEC(tree,heap) *decls_to_register = NULL; +typedef struct decls_to_register_t { + /* Table of all the declarations to register in declaration order. */ + VEC(tree,heap) *v; + + /* Set of declarations to register used to avoid adding duplicate + entries to the table. */ + struct pointer_set_t *m; +} decls_to_register_t; + +static decls_to_register_t decls_to_register = { NULL, NULL }; /* Callback for packing value fields in ASTs. BP is the bitpack we are packing into. EXPR is the tree to pack. */ @@ -1236,8 +1245,8 @@ pph_out_symtab (pph_stream *stream, bool ref_p) tree decl; unsigned i; - pph_out_uint (stream, VEC_length (tree, decls_to_register)); - FOR_EACH_VEC_ELT (tree, decls_to_register, i, decl) + pph_out_uint (stream, VEC_length (tree, decls_to_register.v)); + FOR_EACH_VEC_ELT (tree, decls_to_register.v, i, decl) if (TREE_CODE (decl) == FUNCTION_DECL && DECL_STRUCT_FUNCTION (decl)) { if (DECL_SAVED_TREE (decl)) @@ -1252,7 +1261,12 @@ pph_out_symtab (pph_stream *stream, bool ref_p) pph_out_tree (stream, decl, ref_p); } - VEC_free (tree, heap, decls_to_register); + if (decls_to_register.m) + { + VEC_free (tree, heap, decls_to_register.v); + pointer_set_destroy (decls_to_register.m); + decls_to_register.m = NULL; + } } @@ -1263,6 +1277,8 @@ pph_write_file_contents (pph_stream *stream, cpp_idents_used *idents_used) { /* Emit all the identifiers and symbols in the global namespace. */ pph_out_identifiers (stream, idents_used); + + /* Emit the bindings for the global namespace. */ pph_out_scope_chain (stream, scope_chain, false); if (flag_pph_dump_tree) pph_dump_namespace (pph_logfile, global_namespace); @@ -1665,5 +1681,11 @@ void pph_add_decl_to_register (tree decl) { if (decl) - VEC_safe_push (tree, heap, decls_to_register, decl); + { + if (decls_to_register.m == NULL) + decls_to_register.m = pointer_set_create (); + + if (!pointer_set_insert (decls_to_register.m, decl)) + VEC_safe_push (tree, heap, decls_to_register.v, decl); + } }