This merges making lto_input_block a class, getting rid of LTO_INIT_INPUT_BLOCK. It also simplifies lto headers by removing unused and write-only fields and making them a inheritance hierarchy.
LTO bootstrap running on x86_64-unknown-linux-gnu. Richard. 2014-08-08 Richard Biener <rguent...@suse.de> * lto-streamer.h (struct lto_input_block): Make it a class with a constructor. (LTO_INIT_INPUT_BLOCK, LTO_INIT_INPUT_BLOCK_PTR): Remove. (struct lto_function_header, struct lto_simple_header, struct lto_simple_header_with_strings, struct lto_decl_header, struct lto_function_header): Make a simple inheritance hieararchy. Remove unused fields. (struct lto_asm_header): Remove. * lto-streamer-out.c (produce_asm): Adjust. (lto_output_toplevel_asms): Likewise. (produce_asm_for_decls): Likewise. * lto-section-out.c (lto_destroy_simple_output_block): Likewise. * data-streamer-in.c (string_for_index): Likewise. * ipa-inline-analysis.c (inline_read_section): Likewise. * ipa-prop.c (ipa_prop_read_section): Likewise. (read_replacements_section): Likewise. * lto-cgraph.c (input_cgraph_opt_section): Likewise. * lto-section-in.c (lto_create_simple_input_block): Likewise. (lto_destroy_simple_input_block): Likewise. * lto-streamer-in.c (lto_read_body_or_constructor): Likewise. (lto_input_toplevel_asms): Likewise. lto/ * lto.c (lto_read_decls): Adjust for lto_input_block changes. Index: gcc/lto-streamer.h =================================================================== *** gcc/lto-streamer.h.orig 2014-08-08 12:50:26.203647816 +0200 --- gcc/lto-streamer.h 2014-08-08 13:18:59.566529853 +0200 *************** typedef void (lto_free_section_data_f) ( *** 307,333 **** size_t); /* Structure used as buffer for reading an LTO file. */ ! struct lto_input_block { const char *data; unsigned int p; unsigned int len; }; - #define LTO_INIT_INPUT_BLOCK(BASE,D,P,L) \ - do { \ - BASE.data = D; \ - BASE.p = P; \ - BASE.len = L; \ - } while (0) - - #define LTO_INIT_INPUT_BLOCK_PTR(BASE,D,P,L) \ - do { \ - BASE->data = D; \ - BASE->p = P; \ - BASE->len = L; \ - } while (0) - /* The is the first part of the record for a function or constructor in the .o file. */ --- 307,327 ---- size_t); /* Structure used as buffer for reading an LTO file. */ ! class lto_input_block { + public: + /* Special constructor for the string table, it abuses this to + do random access but use the uhwi decoder. */ + lto_input_block (const char *data_, unsigned int p_, unsigned int len_) + : data (data_), p (p_), len (len_) {} + lto_input_block (const char *data_, unsigned int len_) + : data (data_), p (0), len (len_) {} + const char *data; unsigned int p; unsigned int len; }; /* The is the first part of the record for a function or constructor in the .o file. */ *************** struct lto_header *** 337,363 **** int16_t minor_version; }; ! /* The header for a function body. */ ! struct lto_function_header { ! /* The header for all types of sections. */ ! struct lto_header lto_header; ! ! /* Number of labels with names. */ ! int32_t num_named_labels; ! ! /* Number of labels without names. */ ! int32_t num_unnamed_labels; ! ! /* Size compressed or 0 if not compressed. */ ! int32_t compressed_size; ! ! /* Size of names for named labels. */ ! int32_t named_label_size; ! ! /* Size of the cfg. */ ! int32_t cfg_size; /* Size of main gimple body of function. */ int32_t main_size; --- 331,346 ---- int16_t minor_version; }; ! /* The is the first part of the record in an LTO file for many of the ! IPA passes. */ ! struct lto_simple_header : lto_header { ! /* Size of main gimple body of function. */ ! int32_t main_size; ! }; + struct lto_simple_header_with_strings : lto_simple_header + { /* Size of main gimple body of function. */ int32_t main_size; *************** struct lto_function_header *** 365,405 **** int32_t string_size; }; /* Structure describing a symbol section. */ ! struct lto_decl_header { - /* The header for all types of sections. */ - struct lto_header lto_header; - /* Size of region for decl state. */ int32_t decl_state_size; /* Number of nodes in globals stream. */ int32_t num_nodes; - - /* Size of region for expressions, decls, types, etc. */ - int32_t main_size; - - /* Size of the string table. */ - int32_t string_size; - }; - - - /* Structure describing top level asm()s. */ - struct lto_asm_header - { - /* The header for all types of sections. */ - struct lto_header lto_header; - - /* Size compressed or 0 if not compressed. */ - int32_t compressed_size; - - /* Size of region for expressions, decls, types, etc. */ - int32_t main_size; - - /* Size of the string table. */ - int32_t string_size; }; --- 348,369 ---- int32_t string_size; }; + /* The header for a function body. */ + struct lto_function_header : lto_simple_header_with_strings + { + /* Size of the cfg. */ + int32_t cfg_size; + }; + /* Structure describing a symbol section. */ ! struct lto_decl_header : lto_simple_header_with_strings { /* Size of region for decl state. */ int32_t decl_state_size; /* Number of nodes in globals stream. */ int32_t num_nodes; }; *************** struct lto_output_stream *** 595,614 **** unsigned int total_size; }; - /* The is the first part of the record in an LTO file for many of the - IPA passes. */ - struct lto_simple_header - { - /* The header for all types of sections. */ - struct lto_header lto_header; - - /* Size of main gimple body of function. */ - int32_t main_size; - - /* Size of main stream when compressed. */ - int32_t compressed_size; - }; - /* A simple output block. This can be used for simple IPA passes that do not need more than one stream. */ struct lto_simple_output_block --- 559,564 ---- Index: gcc/lto-streamer-out.c =================================================================== *** gcc/lto-streamer-out.c.orig 2014-08-08 12:50:26.204647815 +0200 --- gcc/lto-streamer-out.c 2014-08-08 13:13:12.703553734 +0200 *************** produce_asm (struct output_block *ob, tr *** 1886,1895 **** memset (&header, 0, sizeof (struct lto_function_header)); /* Write the header. */ ! header.lto_header.major_version = LTO_major_version; ! header.lto_header.minor_version = LTO_minor_version; ! ! header.compressed_size = 0; if (section_type == LTO_section_function_body) header.cfg_size = ob->cfg_stream->total_size; --- 1886,1893 ---- memset (&header, 0, sizeof (struct lto_function_header)); /* Write the header. */ ! header.major_version = LTO_major_version; ! header.minor_version = LTO_minor_version; if (section_type == LTO_section_function_body) header.cfg_size = ob->cfg_stream->total_size; *************** lto_output_toplevel_asms (void) *** 2097,2103 **** struct output_block *ob; struct asm_node *can; char *section_name; ! struct lto_asm_header header; if (! asm_nodes) return; --- 2095,2101 ---- struct output_block *ob; struct asm_node *can; char *section_name; ! struct lto_simple_header_with_strings header; if (! asm_nodes) return; *************** lto_output_toplevel_asms (void) *** 2123,2130 **** memset (&header, 0, sizeof (header)); /* Write the header. */ ! header.lto_header.major_version = LTO_major_version; ! header.lto_header.minor_version = LTO_minor_version; header.main_size = ob->main_stream->total_size; header.string_size = ob->string_stream->total_size; --- 2121,2128 ---- memset (&header, 0, sizeof (header)); /* Write the header. */ ! header.major_version = LTO_major_version; ! header.minor_version = LTO_minor_version; header.main_size = ob->main_stream->total_size; header.string_size = ob->string_stream->total_size; *************** produce_asm_for_decls (void) *** 2657,2664 **** lto_output_decl_state_streams (ob, fn_out_state); } ! header.lto_header.major_version = LTO_major_version; ! header.lto_header.minor_version = LTO_minor_version; /* Currently not used. This field would allow us to preallocate the globals vector, so that it need not be resized as it is extended. */ --- 2655,2662 ---- lto_output_decl_state_streams (ob, fn_out_state); } ! header.major_version = LTO_major_version; ! header.minor_version = LTO_minor_version; /* Currently not used. This field would allow us to preallocate the globals vector, so that it need not be resized as it is extended. */ Index: gcc/lto-section-out.c =================================================================== *** gcc/lto-section-out.c.orig 2014-08-08 12:50:26.205647815 +0200 --- gcc/lto-section-out.c 2014-08-08 13:13:12.703553734 +0200 *************** lto_destroy_simple_output_block (struct *** 278,286 **** /* Write the header which says how to decode the pieces of the t. */ memset (&header, 0, sizeof (struct lto_simple_header)); ! header.lto_header.major_version = LTO_major_version; ! header.lto_header.minor_version = LTO_minor_version; ! header.compressed_size = 0; header.main_size = ob->main_stream->total_size; lto_write_data (&header, sizeof header); --- 278,285 ---- /* Write the header which says how to decode the pieces of the t. */ memset (&header, 0, sizeof (struct lto_simple_header)); ! header.major_version = LTO_major_version; ! header.minor_version = LTO_minor_version; header.main_size = ob->main_stream->total_size; lto_write_data (&header, sizeof header); Index: gcc/data-streamer-in.c =================================================================== *** gcc/data-streamer-in.c.orig 2014-08-08 12:40:58.341686912 +0200 --- gcc/data-streamer-in.c 2014-08-08 13:19:01.894529692 +0200 *************** along with GCC; see the file COPYING3. *** 39,45 **** const char * string_for_index (struct data_in *data_in, unsigned int loc, unsigned int *rlen) { - struct lto_input_block str_tab; unsigned int len; const char *result; --- 39,44 ---- *************** string_for_index (struct data_in *data_i *** 50,57 **** } /* Get the string stored at location LOC in DATA_IN->STRINGS. */ ! LTO_INIT_INPUT_BLOCK (str_tab, data_in->strings, loc - 1, ! data_in->strings_len); len = streamer_read_uhwi (&str_tab); *rlen = len; --- 49,55 ---- } /* Get the string stored at location LOC in DATA_IN->STRINGS. */ ! lto_input_block str_tab (data_in->strings, loc - 1, data_in->strings_len); len = streamer_read_uhwi (&str_tab); *rlen = len; Index: gcc/ipa-inline-analysis.c =================================================================== *** gcc/ipa-inline-analysis.c.orig 2014-08-08 12:40:58.341686912 +0200 --- gcc/ipa-inline-analysis.c 2014-08-08 13:17:33.325535790 +0200 *************** inline_read_section (struct lto_file_dec *** 4086,4097 **** const int main_offset = cfg_offset + header->cfg_size; const int string_offset = main_offset + header->main_size; struct data_in *data_in; - struct lto_input_block ib; unsigned int i, count2, j; unsigned int f_count; ! LTO_INIT_INPUT_BLOCK (ib, (const char *) data + main_offset, 0, ! header->main_size); data_in = lto_data_in_create (file_data, (const char *) data + string_offset, --- 4086,4095 ---- const int main_offset = cfg_offset + header->cfg_size; const int string_offset = main_offset + header->main_size; struct data_in *data_in; unsigned int i, count2, j; unsigned int f_count; ! lto_input_block ib ((const char *) data + main_offset, header->main_size); data_in = lto_data_in_create (file_data, (const char *) data + string_offset, Index: gcc/ipa-prop.c =================================================================== *** gcc/ipa-prop.c.orig 2014-08-08 12:40:58.341686912 +0200 --- gcc/ipa-prop.c 2014-08-08 13:16:11.956541392 +0200 *************** ipa_prop_read_section (struct lto_file_d *** 4930,4941 **** const int main_offset = cfg_offset + header->cfg_size; const int string_offset = main_offset + header->main_size; struct data_in *data_in; - struct lto_input_block ib_main; unsigned int i; unsigned int count; ! LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0, ! header->main_size); data_in = lto_data_in_create (file_data, (const char *) data + string_offset, --- 4930,4940 ---- const int main_offset = cfg_offset + header->cfg_size; const int string_offset = main_offset + header->main_size; struct data_in *data_in; unsigned int i; unsigned int count; ! lto_input_block ib_main ((const char *) data + main_offset, ! header->main_size); data_in = lto_data_in_create (file_data, (const char *) data + string_offset, *************** read_replacements_section (struct lto_fi *** 5108,5119 **** const int main_offset = cfg_offset + header->cfg_size; const int string_offset = main_offset + header->main_size; struct data_in *data_in; - struct lto_input_block ib_main; unsigned int i; unsigned int count; ! LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0, ! header->main_size); data_in = lto_data_in_create (file_data, (const char *) data + string_offset, header->string_size, vNULL); --- 5107,5117 ---- const int main_offset = cfg_offset + header->cfg_size; const int string_offset = main_offset + header->main_size; struct data_in *data_in; unsigned int i; unsigned int count; ! lto_input_block ib_main ((const char *) data + main_offset, ! header->main_size); data_in = lto_data_in_create (file_data, (const char *) data + string_offset, header->string_size, vNULL); Index: gcc/lto-cgraph.c =================================================================== *** gcc/lto-cgraph.c.orig 2014-08-08 12:40:58.341686912 +0200 --- gcc/lto-cgraph.c 2014-08-08 13:16:31.383540055 +0200 *************** input_cgraph_opt_section (struct lto_fil *** 1896,1907 **** const int main_offset = cfg_offset + header->cfg_size; const int string_offset = main_offset + header->main_size; struct data_in *data_in; - struct lto_input_block ib_main; unsigned int i; unsigned int count; ! LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0, ! header->main_size); data_in = lto_data_in_create (file_data, (const char *) data + string_offset, --- 1896,1906 ---- const int main_offset = cfg_offset + header->cfg_size; const int string_offset = main_offset + header->main_size; struct data_in *data_in; unsigned int i; unsigned int count; ! lto_input_block ib_main ((const char *) data + main_offset, ! header->main_size); data_in = lto_data_in_create (file_data, (const char *) data + string_offset, Index: gcc/lto-section-in.c =================================================================== *** gcc/lto-section-in.c.orig 2014-08-08 12:40:58.341686912 +0200 --- gcc/lto-section-in.c 2014-08-08 13:16:46.611539006 +0200 *************** lto_create_simple_input_block (struct lt *** 227,245 **** const struct lto_simple_header * header = (const struct lto_simple_header *) data; - struct lto_input_block* ib_main; int main_offset = sizeof (struct lto_simple_header); if (!data) return NULL; - ib_main = XNEW (struct lto_input_block); - *datar = data; ! LTO_INIT_INPUT_BLOCK_PTR (ib_main, data + main_offset, ! 0, header->main_size); ! ! return ib_main; } --- 227,239 ---- const struct lto_simple_header * header = (const struct lto_simple_header *) data; int main_offset = sizeof (struct lto_simple_header); if (!data) return NULL; *datar = data; ! return new lto_input_block (data + main_offset, header->main_size); } *************** lto_destroy_simple_input_block (struct l *** 255,261 **** struct lto_input_block *ib, const char *data, size_t len) { ! free (ib); lto_free_section_data (file_data, section_type, NULL, data, len); } --- 249,255 ---- struct lto_input_block *ib, const char *data, size_t len) { ! delete ib; lto_free_section_data (file_data, section_type, NULL, data, len); } Index: gcc/lto-streamer-in.c =================================================================== *** gcc/lto-streamer-in.c.orig 2014-08-08 12:40:58.341686912 +0200 --- gcc/lto-streamer-in.c 2014-08-08 13:18:05.405533582 +0200 *************** lto_read_body_or_constructor (struct lto *** 1054,1061 **** int cfg_offset; int main_offset; int string_offset; - struct lto_input_block ib_cfg; - struct lto_input_block ib_main; tree fn_decl = node->decl; header = (const struct lto_function_header *) data; --- 1054,1059 ---- *************** lto_read_body_or_constructor (struct lto *** 1064,1089 **** cfg_offset = sizeof (struct lto_function_header); main_offset = cfg_offset + header->cfg_size; string_offset = main_offset + header->main_size; - - LTO_INIT_INPUT_BLOCK (ib_cfg, - data + cfg_offset, - 0, - header->cfg_size); - - LTO_INIT_INPUT_BLOCK (ib_main, - data + main_offset, - 0, - header->main_size); } else { main_offset = sizeof (struct lto_function_header); string_offset = main_offset + header->main_size; - - LTO_INIT_INPUT_BLOCK (ib_main, - data + main_offset, - 0, - header->main_size); } data_in = lto_data_in_create (file_data, data + string_offset, --- 1062,1072 ---- *************** lto_read_body_or_constructor (struct lto *** 1104,1111 **** /* Set up the struct function. */ from = data_in->reader_cache->nodes.length (); if (TREE_CODE (node->decl) == FUNCTION_DECL) ! input_function (fn_decl, data_in, &ib_main, &ib_cfg); else input_constructor (fn_decl, data_in, &ib_main); /* And fixup types we streamed locally. */ --- 1087,1098 ---- /* Set up the struct function. */ from = data_in->reader_cache->nodes.length (); + lto_input_block ib_main (data + main_offset, header->main_size); if (TREE_CODE (node->decl) == FUNCTION_DECL) ! { ! lto_input_block ib_cfg (data + cfg_offset, header->cfg_size); ! input_function (fn_decl, data_in, &ib_main, &ib_cfg); ! } else input_constructor (fn_decl, data_in, &ib_main); /* And fixup types we streamed locally. */ *************** lto_input_toplevel_asms (struct lto_file *** 1357,1366 **** size_t len; const char *data = lto_get_section_data (file_data, LTO_section_asm, NULL, &len); ! const struct lto_asm_header *header = (const struct lto_asm_header *) data; int string_offset; struct data_in *data_in; - struct lto_input_block ib; tree str; if (! data) --- 1344,1353 ---- size_t len; const char *data = lto_get_section_data (file_data, LTO_section_asm, NULL, &len); ! const struct lto_simple_header_with_strings *header ! = (const struct lto_simple_header_with_strings *) data; int string_offset; struct data_in *data_in; tree str; if (! data) *************** lto_input_toplevel_asms (struct lto_file *** 1368,1377 **** string_offset = sizeof (*header) + header->main_size; ! LTO_INIT_INPUT_BLOCK (ib, ! data + sizeof (*header), ! 0, ! header->main_size); data_in = lto_data_in_create (file_data, data + string_offset, header->string_size, vNULL); --- 1355,1361 ---- string_offset = sizeof (*header) + header->main_size; ! lto_input_block ib (data + sizeof (*header), header->main_size); data_in = lto_data_in_create (file_data, data + string_offset, header->string_size, vNULL); Index: gcc/lto/lto.c =================================================================== *** gcc/lto/lto.c.orig 2014-08-08 12:40:58.341686912 +0200 --- gcc/lto/lto.c 2014-08-08 13:18:41.343531107 +0200 *************** lto_read_decls (struct lto_file_decl_dat *** 1844,1857 **** const int decl_offset = sizeof (struct lto_decl_header); const int main_offset = decl_offset + header->decl_state_size; const int string_offset = main_offset + header->main_size; - struct lto_input_block ib_main; struct data_in *data_in; unsigned int i; const uint32_t *data_ptr, *data_end; uint32_t num_decl_states; ! LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0, ! header->main_size); data_in = lto_data_in_create (decl_data, (const char *) data + string_offset, header->string_size, resolutions); --- 1844,1856 ---- const int decl_offset = sizeof (struct lto_decl_header); const int main_offset = decl_offset + header->decl_state_size; const int string_offset = main_offset + header->main_size; struct data_in *data_in; unsigned int i; const uint32_t *data_ptr, *data_end; uint32_t num_decl_states; ! lto_input_block ib_main ((const char *) data + main_offset, ! header->main_size); data_in = lto_data_in_create (decl_data, (const char *) data + string_offset, header->string_size, resolutions);