From patchwork Fri Sep 9 20:54:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Novillo X-Patchwork-Id: 114139 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 E7EE2B7010 for ; Sat, 10 Sep 2011 06:56:09 +1000 (EST) Received: (qmail 24553 invoked by alias); 9 Sep 2011 20:56:02 -0000 Received: (qmail 24169 invoked by uid 22791); 9 Sep 2011 20:56:00 -0000 X-SWARE-Spam-Status: No, hits=-2.4 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) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 09 Sep 2011 20:54:37 +0000 Received: from hpaq6.eem.corp.google.com (hpaq6.eem.corp.google.com [172.25.149.6]) by smtp-out.google.com with ESMTP id p89KsZBD008233; Fri, 9 Sep 2011 13:54:35 -0700 Received: from topo.tor.corp.google.com (topo.tor.corp.google.com [172.29.41.2]) by hpaq6.eem.corp.google.com with ESMTP id p89KsXMH017781; Fri, 9 Sep 2011 13:54:33 -0700 Received: by topo.tor.corp.google.com (Postfix, from userid 54752) id 9A2611DA1D9; Fri, 9 Sep 2011 16:54:32 -0400 (EDT) To: reply@codereview.appspotmail.com, crowl@google.com, gcc-patches@gcc.gnu.org Subject: [pph] Do not read pph files more than once (issue4983055) Message-Id: <20110909205432.9A2611DA1D9@topo.tor.corp.google.com> Date: Fri, 9 Sep 2011 16:54:32 -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 This was not causing any failures, but it is pretty wasteful to read the same PPH more than once. We cannot just skip them, however. We need to read the line table to properly modify the line table for the current translation unit. Tested on x86_64. Committed to branch. Diego. * pph-streamer-in.c (pph_image_already_read): New. (pph_read_file_1): Call pph_image_already_read. If it returns true, return after reading the line table. (pph_add_read_image): New. (pph_read_file): Change return value to void. Update all callers. Call pph_add_read_image. * pph-streamer-out.c (pph_add_include): Remove second argument. Update all callers. Do not add INCLUDE to pph_read_images. * pph-streamer.h (pph_add_include): Update prototype. --- This patch is available for review at http://codereview.appspot.com/4983055 diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c index b111850..ea44460 100644 --- a/gcc/cp/pph-streamer-in.c +++ b/gcc/cp/pph-streamer-in.c @@ -1462,7 +1462,6 @@ pph_in_include (pph_stream *stream) { int old_loc_offset; const char *include_name; - pph_stream *include; source_location prev_start_loc = pph_in_source_location (stream); /* Simulate highest_location to be as it would be at this point in a non-pph @@ -1475,8 +1474,7 @@ pph_in_include (pph_stream *stream) old_loc_offset = pph_loc_offset; include_name = pph_in_string (stream); - include = pph_read_file (include_name); - pph_add_include (include, false); + pph_read_file (include_name); pph_loc_offset = old_loc_offset; } @@ -1583,6 +1581,23 @@ pph_in_line_table_and_includes (pph_stream *stream) } +/* If FILENAME has already been read, return the stream associated with it. */ + +static pph_stream * +pph_image_already_read (const char *filename) +{ + pph_stream *include; + unsigned i; + + /* FIXME pph, implement a hash map to avoid this linear search. */ + FOR_EACH_VEC_ELT (pph_stream_ptr, pph_read_images, i, include) + if (strcmp (include->name, filename) == 0) + return include; + + return NULL; +} + + /* Helper for pph_read_file. Read contents of PPH file in STREAM. */ static void @@ -1605,6 +1620,11 @@ pph_read_file_1 (pph_stream *stream) read. */ cpp_token_replay_loc = pph_in_line_table_and_includes (stream); + /* If we have read STREAM before, we do not need to re-read the rest + of its body. We only needed to read its line table. */ + if (pph_image_already_read (stream->name)) + return; + /* Read all the identifiers and pre-processor symbols in the global namespace. */ pph_in_identifiers (stream, &idents_used); @@ -1650,13 +1670,22 @@ pph_read_file_1 (pph_stream *stream) STREAM will need to be read again the next time we want to read the image we are now generating. */ if (pph_out_file && !pph_reading_includes) - pph_add_include (stream, true); + pph_add_include (stream); +} + + +/* Add STREAM to the list of read images. */ + +static void +pph_add_read_image (pph_stream *stream) +{ + VEC_safe_push (pph_stream_ptr, heap, pph_read_images, stream); } /* Read PPH file FILENAME. Return the in-memory pph_stream instance. */ -pph_stream * +void pph_read_file (const char *filename) { pph_stream *stream; @@ -1667,7 +1696,7 @@ pph_read_file (const char *filename) else error ("Cannot open PPH file for reading: %s: %m", filename); - return stream; + pph_add_read_image (stream); } diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c index 264294c..1a32814 100644 --- a/gcc/cp/pph-streamer-out.c +++ b/gcc/cp/pph-streamer-out.c @@ -1845,18 +1845,13 @@ pph_add_decl_to_symtab (tree decl, enum pph_symtab_action action, } -/* Add INCLUDE to the list of files included by the main pph_out_stream - if IS_MAIN_STREAM_INCLUDE, as well as to the global list of all read - includes. */ +/* Add INCLUDE to the list of files included by pph_out_stream. */ void -pph_add_include (pph_stream *include, bool is_main_stream_include) +pph_add_include (pph_stream *include) { - if (is_main_stream_include) - VEC_safe_push (pph_stream_ptr, heap, - pph_out_stream->encoder.w.includes, include); - - VEC_safe_push (pph_stream_ptr, heap, pph_read_images, include); + VEC_safe_push (pph_stream_ptr, heap, pph_out_stream->encoder.w.includes, + include); } diff --git a/gcc/cp/pph-streamer.h b/gcc/cp/pph-streamer.h index 7205d64..7f98764 100644 --- a/gcc/cp/pph-streamer.h +++ b/gcc/cp/pph-streamer.h @@ -255,7 +255,7 @@ void pph_flush_buffers (pph_stream *); void pph_init_write (pph_stream *); void pph_write_tree (struct output_block *, tree, bool); void pph_add_decl_to_symtab (tree, enum pph_symtab_action, bool, bool); -void pph_add_include (pph_stream *, bool); +void pph_add_include (pph_stream *); void pph_writer_init (void); void pph_writer_finish (void); void pph_write_location (struct output_block *, location_t); @@ -269,7 +269,7 @@ struct binding_table_s *pph_in_binding_table (pph_stream *); void pph_init_read (pph_stream *); tree pph_read_tree (struct lto_input_block *, struct data_in *); location_t pph_read_location (struct lto_input_block *, struct data_in *); -pph_stream *pph_read_file (const char *); +void pph_read_file (const char *); void pph_reader_finish (void); /* In pt.c. */