diff options
author | dnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-10-03 21:10:11 +0000 |
---|---|---|
committer | dnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-10-03 21:10:11 +0000 |
commit | 7bfefa9d2c82e804ef4e59772f4060ac325bf99a (patch) | |
tree | 3a9882bd235e5026410e5397a5e46a97ece50b48 /gcc/ipa-pure-const.c | |
parent | 7271d48ec9cd1a9aa3893d1d95e1d4a1c5882c37 (diff) | |
download | gcc-7bfefa9d2c82e804ef4e59772f4060ac325bf99a.tar.gz |
Merge lto branch into trunk.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@152434 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ipa-pure-const.c')
-rw-r--r-- | gcc/ipa-pure-const.c | 146 |
1 files changed, 138 insertions, 8 deletions
diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index 04d4e112ed3..ea1d81ea5e2 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -51,6 +51,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "langhooks.h" #include "target.h" +#include "lto-streamer.h" #include "cfgloop.h" #include "tree-scalar-evolution.h" @@ -648,13 +649,15 @@ remove_node_data (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED) } -/* Analyze each function in the cgraph to see if it is locally PURE or - CONST. */ - -static void -generate_summary (void) +static void +register_hooks (void) { - struct cgraph_node *node; + static bool init_p = false; + + if (init_p) + return; + + init_p = true; node_removal_hook_holder = cgraph_add_node_removal_hook (&remove_node_data, NULL); @@ -662,6 +665,19 @@ generate_summary (void) cgraph_add_node_duplication_hook (&duplicate_node_data, NULL); function_insertion_hook_holder = cgraph_add_function_insertion_hook (&add_new_function, NULL); +} + + +/* Analyze each function in the cgraph to see if it is locally PURE or + CONST. */ + +static void +generate_summary (void) +{ + struct cgraph_node *node; + + register_hooks (); + /* There are some shared nodes, in particular the initializers on static declarations. We do not need to scan them more than once since all we would be interested in are the addressof @@ -682,6 +698,120 @@ generate_summary (void) visited_nodes = NULL; } + +/* Serialize the ipa info for lto. */ + +static void +pure_const_write_summary (cgraph_node_set set) +{ + struct cgraph_node *node; + struct lto_simple_output_block *ob + = lto_create_simple_output_block (LTO_section_ipa_pure_const); + unsigned int count = 0; + cgraph_node_set_iterator csi; + + for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi)) + { + node = csi_node (csi); + if (node->analyzed && get_function_state (node) != NULL) + count++; + } + + lto_output_uleb128_stream (ob->main_stream, count); + + /* Process all of the functions. */ + for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi)) + { + node = csi_node (csi); + if (node->analyzed && get_function_state (node) != NULL) + { + struct bitpack_d *bp; + funct_state fs; + int node_ref; + lto_cgraph_encoder_t encoder; + + fs = get_function_state (node); + + encoder = ob->decl_state->cgraph_node_encoder; + node_ref = lto_cgraph_encoder_encode (encoder, node); + lto_output_uleb128_stream (ob->main_stream, node_ref); + + /* Note that flags will need to be read in the opposite + order as we are pushing the bitflags into FLAGS. */ + bp = bitpack_create (); + bp_pack_value (bp, fs->pure_const_state, 2); + bp_pack_value (bp, fs->state_previously_known, 2); + bp_pack_value (bp, fs->looping_previously_known, 1); + bp_pack_value (bp, fs->looping, 1); + bp_pack_value (bp, fs->can_throw, 1); + lto_output_bitpack (ob->main_stream, bp); + bitpack_delete (bp); + } + } + + lto_destroy_simple_output_block (ob); +} + + +/* Deserialize the ipa info for lto. */ + +static void +pure_const_read_summary (void) +{ + struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); + struct lto_file_decl_data *file_data; + unsigned int j = 0; + + register_hooks (); + while ((file_data = file_data_vec[j++])) + { + const char *data; + size_t len; + struct lto_input_block *ib + = lto_create_simple_input_block (file_data, + LTO_section_ipa_pure_const, + &data, &len); + if (ib) + { + unsigned int i; + unsigned int count = lto_input_uleb128 (ib); + + for (i = 0; i < count; i++) + { + unsigned int index; + struct cgraph_node *node; + struct bitpack_d *bp; + funct_state fs; + lto_cgraph_encoder_t encoder; + + fs = XCNEW (struct funct_state_d); + index = lto_input_uleb128 (ib); + encoder = file_data->cgraph_node_encoder; + node = lto_cgraph_encoder_deref (encoder, index); + set_function_state (node, fs); + + /* Note that the flags must be read in the opposite + order in which they were written (the bitflags were + pushed into FLAGS). */ + bp = lto_input_bitpack (ib); + fs->pure_const_state + = (enum pure_const_state_e) bp_unpack_value (bp, 2); + fs->state_previously_known + = (enum pure_const_state_e) bp_unpack_value (bp, 2); + fs->looping_previously_known = bp_unpack_value (bp, 1); + fs->looping = bp_unpack_value (bp, 1); + fs->can_throw = bp_unpack_value (bp, 1); + bitpack_delete (bp); + } + + lto_destroy_simple_input_block (file_data, + LTO_section_ipa_pure_const, + ib, data, len); + } + } +} + + static bool ignore_edge (struct cgraph_edge *e) { @@ -952,8 +1082,8 @@ struct ipa_opt_pass_d pass_ipa_pure_const = 0 /* todo_flags_finish */ }, generate_summary, /* generate_summary */ - NULL, /* write_summary */ - NULL, /* read_summary */ + pure_const_write_summary, /* write_summary */ + pure_const_read_summary, /* read_summary */ NULL, /* function_read_summary */ 0, /* TODOs */ NULL, /* function_transform */ |