From patchwork Wed Jun 22 22:16:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gab Charette X-Patchwork-Id: 101557 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 C8F01B6F84 for ; Thu, 23 Jun 2011 08:16:25 +1000 (EST) Received: (qmail 12050 invoked by alias); 22 Jun 2011 22:16:24 -0000 Received: (qmail 12036 invoked by uid 22791); 22 Jun 2011 22:16:22 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 22 Jun 2011 22:16:07 +0000 Received: from wpaz9.hot.corp.google.com (wpaz9.hot.corp.google.com [172.24.198.73]) by smtp-out.google.com with ESMTP id p5MMG6dw001656; Wed, 22 Jun 2011 15:16:07 -0700 Received: from gchare.mtv.corp.google.com (gchare.mtv.corp.google.com [172.18.111.122]) by wpaz9.hot.corp.google.com with ESMTP id p5MMG5G0012775; Wed, 22 Jun 2011 15:16:06 -0700 Received: by gchare.mtv.corp.google.com (Postfix, from userid 138564) id A91481C1707; Wed, 22 Jun 2011 15:16:05 -0700 (PDT) To: reply@codereview.appspotmail.com, gcc-patches@gcc.gnu.org Subject: [pph] Stream scope_chain->bindings instead of global namespace (issue4661045) Message-Id: <20110622221605.A91481C1707@gchare.mtv.corp.google.com> Date: Wed, 22 Jun 2011 15:16:05 -0700 (PDT) From: gchare@google.com (Gabriel Charette) 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 gcc/cp/pph-streamer-in.c:1003: namespace. 1001 /* FIXME pph: this carried over from pph_add_names_to_namespace, 1002 » it only makes sense to use this when merging names in an existing 1003 » namespace. pph_add_names_to_namespace does not exist anymore. I don't understand this comment. What I meant is that pph_add_bindings_to_namespace is just a modified version of the old pph_add_names_to_namespace in which this recursive call was made (and was already useless before, i.e. commenting it out wouldn't introduce any changes in the test results...). I changed the comment, adding it to the FIXME just above it which mentions we should check if this namespace already exists (i.e. it only makes sense to add bindings in the "streamed in" namespace to the actual namespace IF they are NOT the same object (otherwise the bindings are already part of the "streamed in" namespace so this call is useless). ###################################### gcc/cp/pph-streamer-out.c:947: gcc_assert ( ss->old_namespace == global_namespace 945 /* old_namespace should be global_namespace and all entries listed below 946 should be NULL or 0; otherwise the header parsed was incomplete. */ 947 gcc_assert ( ss->old_namespace == global_namespace No space after '('. FIXED. ###################################### gcc/cp/pph-streamer-out.c:949: || ss->function_decl || ss->template_parms || ss->x_saved_tree 948 && !(ss->class_name || ss->class_type || ss->access_specifier 949 || ss->function_decl || ss->template_parms || ss->x_saved_tree Align '&&' vertically with the open brace. FIXED. ###################################### gcc/cp/pph-streamer.c:34: #include "name-lookup.h" 33 #include "cppbuiltin.h" + 34 #include "name-lookup.h" You also need to add cp/name-lookup.h to the list of dependencies for cp/pph.o in cp/Make-lang.in. I simply removed the include, I originally added it because it holds global_namespace, but it compiles without it (which I guess is fine if we don't try to stick to "include what you use"). 2011-06-22 Gabriel Charette * gcc/cp/pph-streamer-in.c (pph_add_names_to_namespace): Replaced by pph_add_bindings_to_namespace. (pph_add_bindings_to_namespace): New. (pph_in_scope_chain): New. (pph_read_file_contents): Remove unused variable file_ns. (pph_read_file_contents): Call pph_in_scope_chain. * gcc/cp/pph-streamer-out.c (pph_out_scope_chain): New. (pph_write_file_contents): Call pph_out_scope_chain. * gcc/cp/pph-streamer.c (pph_preload_common_nodes): Call lto_streamer_cache_append. --- This patch is available for review at http://codereview.appspot.com/4661045 diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c index e71f744..c16b88d 100644 --- a/gcc/cp/pph-streamer-in.c +++ b/gcc/cp/pph-streamer-in.c @@ -976,15 +976,14 @@ pph_in_lang_type (pph_stream *stream) } -/* Add all the new names declared in NEW_NS to NS. */ +/* Add all bindings declared in BL to NS. */ static void -pph_add_names_to_namespace (tree ns, tree new_ns) +pph_add_bindings_to_namespace (struct cp_binding_level *bl, tree ns) { tree t, chain; - struct cp_binding_level *level = NAMESPACE_LEVEL (new_ns); - for (t = level->names; t; t = chain) + for (t = bl->names; t; t = chain) { /* Pushing a decl into a scope clobbers its DECL_CHAIN. Preserve it. */ @@ -992,18 +991,33 @@ pph_add_names_to_namespace (tree ns, tree new_ns) pushdecl_into_namespace (t, ns); } - for (t = level->namespaces; t; t = chain) + for (t = bl->namespaces; t; t = chain) { /* Pushing a decl into a scope clobbers its DECL_CHAIN. Preserve it. */ - /* FIXME pph: we should first check to see if it isn't already there. */ + /* FIXME pph: we should first check to see if it isn't already there. + If it is, we should use this function recursively to merge + the bindings in T in the corresponding namespace. */ chain = DECL_CHAIN (t); pushdecl_into_namespace (t, ns); - pph_add_names_to_namespace (t, t); } } +/* Merge scope_chain bindings from the stream into SS. */ + +static void +pph_in_scope_chain (pph_stream *stream) +{ + struct cp_binding_level *pph_bindings; + + pph_bindings = pph_in_binding_level (stream); + + /* Merge the bindings obtained from STREAM in the global namespace. */ + pph_add_bindings_to_namespace (pph_bindings, global_namespace); +} + + /* Wrap a macro DEFINITION for printing in an error. */ static char * @@ -1128,7 +1142,6 @@ pph_read_file_contents (pph_stream *stream) cpp_ident_use *bad_use; const char *cur_def; cpp_idents_used idents_used; - tree file_ns; pth_load_identifiers (&idents_used, stream); @@ -1141,12 +1154,12 @@ pph_read_file_contents (pph_stream *stream) /* Re-instantiate all the pre-processor symbols defined by STREAM. */ cpp_lt_replay (parse_in, &idents_used); - /* Read global_namespace from STREAM and add all the names defined - there to the current global_namespace. */ - file_ns = pph_in_tree (stream); + /* Read the bindings from STREAM and merge them with the current bindings. */ + pph_in_scope_chain (stream); + if (flag_pph_dump_tree) - pph_dump_namespace (pph_logfile, file_ns); - pph_add_names_to_namespace (global_namespace, file_ns); + pph_dump_namespace (pph_logfile, global_namespace); + keyed_classes = pph_in_tree (stream); unemitted_tinfo_decls = pph_in_tree_vec (stream); /* FIXME pph: This call replaces the tinfo, we should merge instead. diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c index 3187338..4c3e4a5 100644 --- a/gcc/cp/pph-streamer-out.c +++ b/gcc/cp/pph-streamer-out.c @@ -935,6 +935,34 @@ pph_out_lang_type (pph_stream *stream, tree type, bool ref_p) } +/* Write saved_scope information stored in SS, does NOT output all fields, + meant to be used for the global variable "scope_chain" only. + Output bindings as references if REF_P is true. */ + +static void +pph_out_scope_chain (pph_stream *stream, struct saved_scope *ss, bool ref_p) +{ + /* old_namespace should be global_namespace and all entries listed below + should be NULL or 0; otherwise the header parsed was incomplete. */ + gcc_assert (ss->old_namespace == global_namespace + && !(ss->class_name || ss->class_type || ss->access_specifier + || ss->function_decl || ss->template_parms + || ss->x_saved_tree || ss->class_bindings || ss->prev + || ss->unevaluated_operand + || ss->inhibit_evaluation_warnings + || ss->x_processing_template_decl + || ss->x_processing_specialization + || ss->x_processing_explicit_instantiation + || ss->need_pop_function_context + || ss->x_stmt_tree.x_cur_stmt_list + || ss->x_stmt_tree.stmts_are_full_exprs_p)); + + /* We only need to write out the bindings, everything else should + be NULL or be some temporary disposable state. */ + pph_out_binding_level (stream, ss->bindings, ref_p); +} + + /* Save the IDENTIFIERS to the STREAM. */ static void @@ -991,9 +1019,9 @@ static void pph_write_file_contents (pph_stream *stream, cpp_idents_used *idents_used) { pth_save_identifiers (idents_used, stream); + pph_out_scope_chain (stream, scope_chain, false); if (flag_pph_dump_tree) pph_dump_namespace (pph_logfile, global_namespace); - pph_out_tree (stream, global_namespace, false); pph_out_tree (stream, keyed_classes, false); pph_out_tree_vec (stream, unemitted_tinfo_decls, false); } diff --git a/gcc/cp/pph-streamer.c b/gcc/cp/pph-streamer.c index 7c9b862..e919baf 100644 --- a/gcc/cp/pph-streamer.c +++ b/gcc/cp/pph-streamer.c @@ -78,6 +78,8 @@ pph_preload_common_nodes (struct lto_streamer_cache_d *cache) for (i = 0; i < CTI_MAX; i++) if (c_global_trees[i]) lto_streamer_cache_append (cache, c_global_trees[i]); + + lto_streamer_cache_append (cache, global_namespace); }