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. 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 -- This patch is available for review at http://codereview.appspot.com/5169052