[lto]: Patch to serialize cgraph and other changes.

Kenneth Zadeck zadeck@naturalbridge.com
Wed Mar 5 21:52:00 GMT 2008


The main purpose of this patch is to serialize the cgraph.  However
there were several major changes that had to be done along the way to
make that work.

1) The only code that uses the older elf utilities in lto/lto-elf.c is
the dwarf reader for types and globals.  All of the other elf sections
are read by new code that reads the elf dictionary once and puts all of
the lto entries into a hash table that can be used later.

The required major surgery to get working.   libelf does not really want
to just give out a pointer to an elf section.   It generally copies it,
applying some transformations based on the source and destination
architecture.    This is unnecessary for the lto functions, and the ipa
sections because they are just in byte encoded streams so the
transformation will always be a memory copy.   But the elf reader copies
it anyway, just in case.   The new code stores an entry with filename,
start and length, so the section reader can just open the file and lseek
to it. 

The current code builds the hash table with the real start byte of the
lto section.   This table for a particular .o is then put into the
cgraph entry for the functions for that file so that the file can be
read later.   This code should work and we should be able to play the
same games with other .o formats except for one caveat:  archives will
require some work because the current offset used is to the beginning of
the .o file, not the beginning of the archive.

2) The big loop now looks like:

for each file:
   {
       read the globals and types.
       read the cgraph
  }

Process the cgraph,

for each node in the cgraph
    read in the function body.

Of course reading every function is not what we want to do in the long
run, but this patch now separates the reading of the functions from the
building of the cgraph and the merging of the types and decls so a
rational policy could now be implemented.  Honza plans to add smarts to
the cgraph analyzing code to read functions on demand and cache the
little ones (or some such policy) and he can now go off and do that
independently loading/merging the globals and types.

3) There was some generalization of the streams debugging so that the
same debugging interface can be used for any ipa stream, not just the
function bodies. 

4) There is still a lot of code in the wrong place.  lto/lto.c contains
a lot of code to read in the cgraph.   This is just going to have to
stay this way until honza makes some changes to the pass manager to
properly support passes that serialize/deserialize/analyze ipa like
passes.  

5) There is now even more bogosity to make local static vars work
properly.  This will be fixed when all of the statics, including the
locals are serialized at one time, and properly restored. 

committed as revision 132954.

Kenny


2008-03-05  Kenneth Zadeck <zadeck@naturalbridge.com>
        Jan Hubicka  <jh@suse.cz>

    * cgraph.h (cgraph_local_info): Added lto_file_data.
    (cgraph_decide_is_function_needed): Made public.
    * tree-pass.h (pass_ipa_lto_cgraph_out): New lto pass.   
    * lto-function-out.c (LTO_tag_names): Renamed to LTO_tree_tag_names.
    (current_stmt_uid): Removed.
    (create_output_block): Moved call to lto_get_output_decl_state and set
    lto_debug_context.tag_names.
    (output_expr_operand, output_bb, output_constructors_and_inits):
    Removed current_stmt_id.
    (lto_static_init): Renamed LTO_tag_names to LTO_tree_tag_names
    (output_function): Added debugging code.
    * cgraphunit.c (decide_is_function_needed): Renamed to
    cgraph_decide_is_function_needed and made public.
    (cgraph_analyze_functions): Only analyze unanalyzed functions.
    * lto-cgraph.h: New file.
    * lto-header.h (LTO_DEBUG_FN_NAME): New macro.
    (struct lto_debug_context.tag_names): New field.
    (lto_debug_fn_name): New function.
    * lto-tags.h (LTO_last_tag): Renamed to LTO_tree_last_tag.
    * lto-stream-debug.c (lto_debug_indent): Get tag from context.
    (lto_debug_fn_name): New function.
    * Makefile.in (lto-stream-debug.o, lto-cgraph-out.o, varpool.o):
    Fixed dependencies.
    * passes.c (init_optimization_passes): New
    pass_ipa_lto_cgraph_out.
    * lto-cgraph-out.c: New file.
    * varpool.c (decide_is_variable_needed): Check for in_lto_p.
       
2008-03-05  Kenneth Zadeck <zadeck@naturalbridge.com>
        Jan Hubicka  <jh@suse.cz>

    * lto.c (lto_info_fd_init, lto_info_fd_close): Get rid of
    fd->unmaterialized_fndecls.
    (lto_get_file_name, lto_materialize_cgraph): New function.
    (lto_materialize_constructors_and_inits,
    lto_materialize_function): Read info directly from elf file.
    (lto_file_read): Made local and initialize dictionary so that
    other lto sections can be read without reprocessing the elf file.
    (lto_main): Read all functions after all files have been processed
    for their types, globals and cgraph.  
    * Make-lang.in (lto.o, lto-cgraph-in.c, lto-section-in): Changed
    dependencies.
    * lto-elf.c (lto_elf_file): Removed strtab, symtab fields.
    (hash_name, eq_name, lto_elf_build_section_table): New functions.
    (lto_elf_read_symtab): Removed function.
    (lto_elf_file_open): Removed call to lto_elf_read_symtab.
    * lto.h (lto_info_fd_struct): Removed unmaterialized_fndecls.
    (lto_file_read): Made local.
    (lto_get_file_name, lto_elf_build_section_table,
    lto_input_cgraph):
    New function.
    * lto-section-in.c (lto_read_section_data, lto_get_section_data):
    New functions.
    (lto_read_decls): Get the file name.
    * lto-cgraph-in.c: New file.
    * lto-function-in.c (tag_to_expr): Stops at LTO_tree_last_tag.
    (input_expr_operand, lto_read_body): Set lto_debug_context.tag_names.
    (input_labels): Fixed latent sizeof issue.
    (input_function): Build stmt array to set call sites into cgraph
    edges.
    (lto_read_body): Reset cfun->curr_properties.
    * lto_section_in.h (lto_section_slot): New structure.
    (section_hash_table.lto_file_decl_data): New field.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: cgraph3.diff
Type: text/x-patch
Size: 65611 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080305/cedeb1db/attachment.bin>


More information about the Gcc-patches mailing list