summaryrefslogtreecommitdiff
path: root/gcc/lto-streamer-out.c
diff options
context:
space:
mode:
authordnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4>2011-06-06 16:49:11 +0000
committerdnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4>2011-06-06 16:49:11 +0000
commita0605d65f057d09d208c6175c8ef78b8809184da (patch)
tree833ac0df274e1c8def946237e10bd907c5de11ee /gcc/lto-streamer-out.c
parenta304f2edf185cc84bf2b77515ab3ad104745ba0e (diff)
downloadgcc-a0605d65f057d09d208c6175c8ef78b8809184da.tar.gz
* Makefile.in (lto-compress.o): Add dependency on LTO_STREAMER_H.
(cgraph.o): Likewise. (cgraphunit.o): Likewise. * cgraphunit.c: Include lto-streamer.h (cgraph_finalize_compilation_unit): Call lto_streamer_hooks_init if LTO is enabled. * lto-streamer-in.c (unpack_value_fields): Call streamer_hooks.unpack_value_fields if set. (lto_materialize_tree): For unhandled nodes, first try to call lto_streamer_hooks.alloc_tree, if it exists. (lto_input_ts_decl_common_tree_pointers): Move reading of DECL_INITIAL to lto_streamer_read_tree. (lto_read_tree): Call lto_streamer_hooks.read_tree if set. (lto_streamer_read_tree): New. (lto_reader_init): Rename from lto_init_reader. Move initialization code to lto/lto.c. * lto-streamer-out.c (pack_value_fields): Call streamer_hooks.pack_value_fields if set. (lto_output_tree_ref): For tree nodes that are not normally indexable, call streamer_hooks.indexable_with_decls_p before giving up. (lto_output_ts_decl_common_tree_pointers): Move handling for FUNCTION_DECL and TRANSLATION_UNIT_DECL to lto_streamer_write_tree. (lto_output_tree_header): Call streamer_hooks.is_streamable instead of lto_is_streamable. Call lto_streamer_hooks.output_tree_header if set. (lto_write_tree): Call lto_streamer_hooks.write_tree if set. (lto_streamer_write_tree): New. (lto_output): Call lto_streamer_init directly. (lto_writer_init): Remove. * lto-streamer.c (streamer_hooks): New. (lto_streamer_cache_create): Call streamer_hooks.preload_common_nodes instead of lto_preload_common_nodes. (lto_is_streamable): Move from lto-streamer.h (lto_streamer_hooks_init): New. (streamer_hooks): New. (streamer_hooks_init): New. * lto-streamer.h (struct output_block): Forward declare. (struct lto_input_block): Likewise. (struct data_in): Likewise. (struct bitpack_d): Likewise. (struct streamer_hooks): Declare. (streamer_hooks): Declare. (lto_streamer_hooks_init): Declare. (lto_streamer_write_tree): Declare. (lto_streamer_read_tree): Declare. (streamer_hooks_init): Declare. (lto_is_streamable): Move to lto-streamer.c lto/ChangeLog * lto.c (lto_init): New. (lto_main): Call it. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@174709 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/lto-streamer-out.c')
-rw-r--r--gcc/lto-streamer-out.c107
1 files changed, 71 insertions, 36 deletions
diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c
index 66b1ac6f100..02ac9583ace 100644
--- a/gcc/lto-streamer-out.c
+++ b/gcc/lto-streamer-out.c
@@ -591,6 +591,9 @@ pack_value_fields (struct bitpack_d *bp, tree expr)
if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
pack_ts_translation_unit_decl_value_fields (bp, expr);
+
+ if (streamer_hooks.pack_value_fields)
+ streamer_hooks.pack_value_fields (bp, expr);
}
@@ -754,9 +757,22 @@ lto_output_tree_ref (struct output_block *ob, tree expr)
break;
default:
- /* No other node is indexable, so it should have been handled
- by lto_output_tree. */
- gcc_unreachable ();
+ {
+ /* See if the streamer allows this node to be indexable
+ like other global declarations. */
+ if (streamer_hooks.indexable_with_decls_p
+ && streamer_hooks.indexable_with_decls_p (expr))
+ {
+ output_record_start (ob, LTO_global_decl_ref);
+ lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
+ }
+ else
+ {
+ /* No other node is indexable, so it should have been
+ handled by lto_output_tree. */
+ gcc_unreachable ();
+ }
+ }
}
}
@@ -865,27 +881,11 @@ lto_output_ts_decl_common_tree_pointers (struct output_block *ob, tree expr,
lto_output_tree_or_ref (ob, DECL_SIZE (expr), ref_p);
lto_output_tree_or_ref (ob, DECL_SIZE_UNIT (expr), ref_p);
- if (TREE_CODE (expr) != FUNCTION_DECL
- && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
- {
- tree initial = DECL_INITIAL (expr);
- if (TREE_CODE (expr) == VAR_DECL
- && (TREE_STATIC (expr) || DECL_EXTERNAL (expr))
- && initial)
- {
- lto_varpool_encoder_t varpool_encoder = ob->decl_state->varpool_node_encoder;
- struct varpool_node *vnode = varpool_get_node (expr);
- if (!vnode)
- initial = error_mark_node;
- else if (!lto_varpool_encoder_encode_initializer_p (varpool_encoder,
- vnode))
- initial = NULL;
- }
-
- lto_output_tree_or_ref (ob, initial, ref_p);
- }
+ /* Note, DECL_INITIAL is not handled here. Since DECL_INITIAL needs
+ special handling in LTO, it must be handled by streamer hooks. */
lto_output_tree_or_ref (ob, DECL_ATTRIBUTES (expr), ref_p);
+
/* Do not stream DECL_ABSTRACT_ORIGIN. We cannot handle debug information
for early inlining so drop it on the floor instead of ICEing in
dwarf2out.c. */
@@ -1261,11 +1261,11 @@ lto_output_tree_header (struct output_block *ob, tree expr)
enum LTO_tags tag;
enum tree_code code;
- /* We should not see any non-GIMPLE tree nodes here. */
+ /* We should not see any tree nodes not handled by the streamer. */
code = TREE_CODE (expr);
- if (!lto_is_streamable (expr))
- internal_error ("tree code %qs is not supported in gimple streams",
- tree_code_name[code]);
+ if (!streamer_hooks.is_streamable (expr))
+ internal_error ("tree code %qs is not supported in %s streams",
+ tree_code_name[code], streamer_hooks.name);
/* The header of a tree node consists of its tag, the size of
the node, and any other information needed to instantiate
@@ -1294,6 +1294,11 @@ lto_output_tree_header (struct output_block *ob, tree expr)
output_sleb128 (ob, TREE_VEC_LENGTH (expr));
else if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
output_uleb128 (ob, BINFO_N_BASE_BINFOS (expr));
+
+ /* Allow the streamer to write any streamer-specific information
+ needed to instantiate the node when reading. */
+ if (streamer_hooks.output_tree_header)
+ streamer_hooks.output_tree_header (ob, expr);
}
@@ -1355,11 +1360,49 @@ lto_write_tree (struct output_block *ob, tree expr, bool ref_p)
/* Write all the pointer fields in EXPR. */
lto_output_tree_pointers (ob, expr, ref_p);
+ /* Call back into the streaming module to see if it needs to write
+ anything that was not written by the common streamer. */
+ if (streamer_hooks.write_tree)
+ streamer_hooks.write_tree (ob, expr, ref_p);
+
/* Mark the end of EXPR. */
output_zero (ob);
}
+/* GIMPLE hook for writing GIMPLE-specific parts of trees. OB, EXPR
+ and REF_P are as in lto_write_tree. */
+
+void
+lto_streamer_write_tree (struct output_block *ob, tree expr, bool ref_p)
+{
+ if (DECL_P (expr)
+ && TREE_CODE (expr) != FUNCTION_DECL
+ && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
+ {
+ /* Handle DECL_INITIAL for symbols. */
+ tree initial = DECL_INITIAL (expr);
+ if (TREE_CODE (expr) == VAR_DECL
+ && (TREE_STATIC (expr) || DECL_EXTERNAL (expr))
+ && initial)
+ {
+ lto_varpool_encoder_t varpool_encoder;
+ struct varpool_node *vnode;
+
+ varpool_encoder = ob->decl_state->varpool_node_encoder;
+ vnode = varpool_get_node (expr);
+ if (!vnode)
+ initial = error_mark_node;
+ else if (!lto_varpool_encoder_encode_initializer_p (varpool_encoder,
+ vnode))
+ initial = NULL;
+ }
+
+ lto_output_tree_or_ref (ob, initial, ref_p);
+ }
+}
+
+
/* Emit the integer constant CST to output block OB. If REF_P is true,
CST's type will be emitted as a reference. */
@@ -2188,15 +2231,6 @@ copy_function (struct cgraph_node *node)
}
-/* Initialize the LTO writer. */
-
-static void
-lto_writer_init (void)
-{
- lto_streamer_init ();
-}
-
-
/* Main entry point from the pass manager. */
static void
@@ -2210,7 +2244,8 @@ lto_output (cgraph_node_set set, varpool_node_set vset)
int i, n_nodes;
lto_cgraph_encoder_t encoder = lto_get_out_decl_state ()->cgraph_node_encoder;
- lto_writer_init ();
+ /* Initialize the streamer. */
+ lto_streamer_init ();
n_nodes = lto_cgraph_encoder_size (encoder);
/* Process only the functions with bodies. */