From patchwork Tue Oct 4 15:12:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Novillo X-Patchwork-Id: 117649 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 A0C0EB6F75 for ; Wed, 5 Oct 2011 02:13:01 +1100 (EST) Received: (qmail 28150 invoked by alias); 4 Oct 2011 15:12:57 -0000 Received: (qmail 28135 invoked by uid 22791); 4 Oct 2011 15:12:52 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_CX, TW_FN 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; Tue, 04 Oct 2011 15:12:34 +0000 Received: from wpaz37.hot.corp.google.com (wpaz37.hot.corp.google.com [172.24.198.101]) by smtp-out.google.com with ESMTP id p94FCU5V008277; Tue, 4 Oct 2011 08:12:31 -0700 Received: from topo.tor.corp.google.com (topo.tor.corp.google.com [172.29.41.2]) by wpaz37.hot.corp.google.com with ESMTP id p94FCTWV018638; Tue, 4 Oct 2011 08:12:29 -0700 Received: by topo.tor.corp.google.com (Postfix, from userid 54752) id F2DDC1DA1C2; Tue, 4 Oct 2011 11:12:28 -0400 (EDT) To: reply@codereview.appspotmail.com, crowl@google.com, gcharette1@gmail.com, gcc-patches@gcc.gnu.org Subject: [pph] Add pph_cache_find (issue5169052) Message-Id: <20111004151228.F2DDC1DA1C2@topo.tor.corp.google.com> Date: Tue, 4 Oct 2011 11:12:28 -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 implements the clean up Gab suggested in http://gcc.gnu.org/ml/gcc-patches/2011-09/msg01882.html Tested on x86_64. Committed. Diego. * pph-streamer.h (pph_cache_find): New. Replace pph_cache_select/pph_cache_get combinations with it. --- This patch is available for review at http://codereview.appspot.com/5169052 diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c index 197937c..66af782 100644 --- a/gcc/cp/pph-streamer-in.c +++ b/gcc/cp/pph-streamer-in.c @@ -442,10 +442,8 @@ pph_in_cxx_binding_1 (pph_stream *stream) if (marker == PPH_RECORD_END) return NULL; else if (pph_is_reference_marker (marker)) - { - pph_cache *cache = pph_cache_select (stream, marker, image_ix); - return (cxx_binding *) pph_cache_get (cache, ix); - } + return (cxx_binding *) pph_cache_find (stream, marker, image_ix, ix, + PPH_cxx_binding); value = pph_in_tree (stream); type = pph_in_tree (stream); @@ -494,10 +492,8 @@ pph_in_class_binding (pph_stream *stream) if (marker == PPH_RECORD_END) return NULL; else if (pph_is_reference_marker (marker)) - { - pph_cache *cache = pph_cache_select (stream, marker, image_ix); - return (cp_class_binding *) pph_cache_get (cache, ix); - } + return (cp_class_binding *) pph_cache_find (stream, marker, image_ix, ix, + PPH_cp_class_binding); ALLOC_AND_REGISTER (&stream->cache, ix, PPH_cp_class_binding, cb, ggc_alloc_cleared_cp_class_binding ()); @@ -521,10 +517,8 @@ pph_in_label_binding (pph_stream *stream) if (marker == PPH_RECORD_END) return NULL; else if (pph_is_reference_marker (marker)) - { - pph_cache *cache = pph_cache_select (stream, marker, image_ix); - return (cp_label_binding *) pph_cache_get (cache, ix); - } + return (cp_label_binding *) pph_cache_find (stream, marker, image_ix, ix, + PPH_cp_label_binding); ALLOC_AND_REGISTER (&stream->cache, ix, PPH_cp_label_binding, lb, ggc_alloc_cleared_cp_label_binding ()); @@ -566,10 +560,8 @@ pph_in_binding_level (pph_stream *stream, cp_binding_level *to_register) if (marker == PPH_RECORD_END) return NULL; else if (pph_is_reference_marker (marker)) - { - pph_cache *cache = pph_cache_select (stream, marker, image_ix); - return (cp_binding_level *) pph_cache_get (cache, ix); - } + return (cp_binding_level *) pph_cache_find (stream, marker, image_ix, ix, + PPH_cp_binding_level); /* If TO_REGISTER is set, register that binding level instead of the newly allocated binding level into slot IX. */ @@ -656,10 +648,9 @@ pph_in_language_function (pph_stream *stream) if (marker == PPH_RECORD_END) return NULL; else if (pph_is_reference_marker (marker)) - { - pph_cache *cache = pph_cache_select (stream, marker, image_ix); - return (struct language_function *) pph_cache_get (cache, ix); - } + return (struct language_function *) pph_cache_find (stream, marker, + image_ix, ix, + PPH_language_function); ALLOC_AND_REGISTER (&stream->cache, ix, PPH_language_function, lf, ggc_alloc_cleared_language_function ()); @@ -753,8 +744,8 @@ pph_in_struct_function (pph_stream *stream, tree decl) return; else if (pph_is_reference_marker (marker)) { - pph_cache *cache = pph_cache_select (stream, marker, image_ix); - fn = (struct function *) pph_cache_get (cache, ix); + fn = (struct function *) pph_cache_find (stream, marker, image_ix, ix, + PPH_function); gcc_assert (DECL_STRUCT_FUNCTION (decl) == fn); return; } @@ -863,9 +854,9 @@ pph_in_lang_specific (pph_stream *stream, tree decl) return; else if (pph_is_reference_marker (marker)) { - pph_cache *cache = pph_cache_select (stream, marker, image_ix); - DECL_LANG_SPECIFIC (decl) = (struct lang_decl *) pph_cache_get (cache, - ix); + DECL_LANG_SPECIFIC (decl) = + (struct lang_decl *) pph_cache_find (stream, marker, image_ix, ix, + PPH_lang_decl); return; } @@ -959,10 +950,8 @@ pph_in_sorted_fields_type (pph_stream *stream) if (marker == PPH_RECORD_END) return NULL; else if (pph_is_reference_marker (marker)) - { - pph_cache *cache = pph_cache_select (stream, marker, image_ix); - return (struct sorted_fields_type *) pph_cache_get (cache, ix); - } + return (struct sorted_fields_type *) + pph_cache_find (stream, marker, image_ix, ix, PPH_sorted_fields_type); num_fields = pph_in_uint (stream); ALLOC_AND_REGISTER (&stream->cache, ix, PPH_sorted_fields_type, v, @@ -1044,10 +1033,9 @@ pph_in_lang_type_class (pph_stream *stream, struct lang_type_class *ltc) PPH_binding_table); } else if (pph_is_reference_marker (marker)) - { - pph_cache *cache = pph_cache_select (stream, marker, image_ix); - ltc->nested_udts = (binding_table) pph_cache_get (cache, ix); - } + ltc->nested_udts = (binding_table) pph_cache_find (stream, marker, + image_ix, ix, + PPH_binding_table); ltc->as_base = pph_in_tree (stream); ltc->pure_virtuals = pph_in_tree_vec (stream); @@ -1086,10 +1074,8 @@ pph_in_lang_type (pph_stream *stream) if (marker == PPH_RECORD_END) return NULL; else if (pph_is_reference_marker (marker)) - { - pph_cache *cache = pph_cache_select (stream, marker, image_ix); - return (struct lang_type *) pph_cache_get (cache, ix); - } + return (struct lang_type *) pph_cache_find (stream, marker, image_ix, ix, + PPH_lang_type); ALLOC_AND_REGISTER (&stream->cache, ix, PPH_lang_type, lt, ggc_alloc_cleared_lang_type (sizeof (struct lang_type))); @@ -1303,10 +1289,8 @@ pph_in_cgraph_node (pph_stream *stream) if (marker == PPH_RECORD_END) return NULL; else if (pph_is_reference_marker (marker)) - { - pph_cache *cache = pph_cache_select (stream, marker, image_ix); - return (struct cgraph_node *) pph_cache_get (cache, ix); - } + return (struct cgraph_node *) pph_cache_find (stream, marker, image_ix, + ix, PPH_cgraph_node); fndecl = pph_in_tree (stream); ALLOC_AND_REGISTER (&stream->cache, ix, PPH_cgraph_node, node, @@ -2094,12 +2078,8 @@ pph_read_namespace_tree (pph_stream *stream, tree enclosing_namespace) if (marker == PPH_RECORD_END) return NULL; else if (pph_is_reference_marker (marker)) - { - pph_cache *cache = pph_cache_select (stream, marker, image_ix); - return (tree) pph_cache_get (cache, ix); - } - else if (marker == PPH_RECORD_START - || marker == PPH_RECORD_START_NO_CACHE) + return (tree) pph_cache_find (stream, marker, image_ix, ix, PPH_any_tree); + else if (marker == PPH_RECORD_START || marker == PPH_RECORD_START_NO_CACHE) { /* This is a new tree that we need to allocate. Start by reading the header fields, so we know how to allocate it @@ -2144,14 +2124,11 @@ pph_read_namespace_tree (pph_stream *stream, tree enclosing_namespace) if (marker == PPH_RECORD_START_MUTATED) { - pph_cache *cache; - /* When reading a mutated tree, we only need to re-read its body, the tree itself is already in the cache for another PPH image. */ - gcc_assert (marker == PPH_RECORD_START_MUTATED); - cache = pph_cache_select (stream, PPH_RECORD_XREF, image_ix); - expr = (tree) pph_cache_get (cache, ix); + expr = (tree) pph_cache_find (stream, PPH_RECORD_XREF, image_ix, ix, + PPH_any_tree); /* Read the internal cache slot where EXPR should be stored at. */ ix = pph_in_uint (stream); diff --git a/gcc/cp/pph-streamer.c b/gcc/cp/pph-streamer.c index ed5b66e..05d1d5f 100644 --- a/gcc/cp/pph-streamer.c +++ b/gcc/cp/pph-streamer.c @@ -573,6 +573,8 @@ pph_cache_sign (pph_cache *cache, unsigned ix, unsigned crc, size_t nbytes) { pph_cache_entry *e; + /* Needed because xcrc32 requires an int to specify the length but + tree_size returns size_t values. */ gcc_assert (nbytes == (size_t) (int) nbytes); e = pph_cache_get_entry (cache, ix); diff --git a/gcc/cp/pph-streamer.h b/gcc/cp/pph-streamer.h index fd1b267..2a8ef6f 100644 --- a/gcc/cp/pph-streamer.h +++ b/gcc/cp/pph-streamer.h @@ -421,6 +421,24 @@ pph_cache_get (pph_cache *cache, unsigned ix) return e->data; } +/* Return the data pointer in one of STREAM's caches (determined by + MARKER, IMAGE_IX and IX. Expect data to have type tag TAG. */ +static inline void * +pph_cache_find (pph_stream *stream, enum pph_record_marker marker, + unsigned image_ix, unsigned ix, enum pph_tag tag) +{ + pph_cache *cache = pph_cache_select (stream, marker, image_ix); + pph_cache_entry *e = pph_cache_get_entry (cache, ix); + + /* If the caller expects any tree, make sure we get a valid tree code. */ + if (tag == PPH_any_tree) + gcc_assert (e->tag < PPH_any_tree); + else + gcc_assert (e->tag == tag); + + return e->data; +} + /* Output array A of cardinality C of ASTs to STREAM. */ /* FIXME pph: hold for alternate routine. */ #if 0