aboutsummaryrefslogtreecommitdiff
path: root/gcc/lto-streamer.h
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2011-06-06 16:49:11 +0000
committerDiego Novillo <dnovillo@google.com>2011-06-06 16:49:11 +0000
commitd1c025e187c91456289edf221496aaae0d3fbc79 (patch)
tree833ac0df274e1c8def946237e10bd907c5de11ee /gcc/lto-streamer.h
parent89511ff3eafae8d32e2026af884bba6d210e27fc (diff)
* 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: https://gcc.gnu.org/svn/gcc/trunk@174709 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/lto-streamer.h')
-rw-r--r--gcc/lto-streamer.h120
1 files changed, 92 insertions, 28 deletions
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
index 5f69655fb98..157e5c0052e 100644
--- a/gcc/lto-streamer.h
+++ b/gcc/lto-streamer.h
@@ -33,6 +33,12 @@ along with GCC; see the file COPYING3. If not see
#include "alloc-pool.h"
#include "gcov-io.h"
+/* Forward declarations to avoid including unnecessary headers. */
+struct output_block;
+struct lto_input_block;
+struct data_in;
+struct bitpack_d;
+
/* Define when debugging the LTO streamer. This causes the writer
to output the numeric value for the memory address of the tree node
being emitted. When debugging a problem in the reader, check the
@@ -741,6 +747,86 @@ struct data_in
};
+/* Streamer hooks. These functions do additional processing as
+ needed by the module. There are two types of callbacks, those that
+ replace the default behavior and those that supplement it.
+
+ Hooks marked [REQ] are required to be set. Those marked [OPT] may
+ be NULL, if the streamer does not need to implement them. */
+struct streamer_hooks {
+ /* [REQ] A string identifying this streamer. */
+ const char *name;
+
+ /* [REQ] Called by lto_streamer_cache_create to instantiate a cache of
+ well-known nodes. These are tree nodes that are always
+ instantiated by the compiler on startup. Additionally, these
+ nodes need to be shared. This function should call
+ lto_streamer_cache_append on every tree node that it wishes to
+ preload in the streamer cache. This way, the writer will only
+ write out a reference to the tree and the reader will instantiate
+ the tree out of this pre-populated cache. */
+ void (*preload_common_nodes) (struct lto_streamer_cache_d *);
+
+ /* [REQ] Return true if the given tree is supported by this streamer. */
+ bool (*is_streamable) (tree);
+
+ /* [OPT] Called by lto_write_tree after writing all the common parts of
+ a tree. If defined, the callback is in charge of writing all
+ the fields that lto_write_tree did not write out. Arguments
+ are as in lto_write_tree.
+
+ The following tree fields are not handled by common code:
+
+ DECL_ABSTRACT_ORIGIN
+ DECL_INITIAL
+ DECL_SAVED_TREE
+
+ Callbacks may choose to ignore or handle them. If handled,
+ the reader should read them in the exact same sequence written
+ by the writer. */
+ void (*write_tree) (struct output_block *, tree, bool);
+
+ /* [OPT] Called by lto_read_tree after reading all the common parts of
+ a tree. If defined, the callback is in charge of reading all
+ the fields that lto_read_tree did not read in. Arguments
+ are as in lto_read_tree. */
+ void (*read_tree) (struct lto_input_block *, struct data_in *, tree);
+
+ /* [OPT] Called by lto_output_tree_ref to determine if the given tree node
+ should be emitted as a reference to the table of declarations
+ (the same table that holds global declarations). */
+ bool (*indexable_with_decls_p) (tree);
+
+ /* [OPT] Called by pack_value_fields to store any non-pointer fields
+ in the tree structure. The arguments are as in pack_value_fields. */
+ void (*pack_value_fields) (struct bitpack_d *, tree);
+
+ /* [OPT] Called by unpack_value_fields to retrieve any non-pointer fields
+ in the tree structure. The arguments are as in unpack_value_fields. */
+ void (*unpack_value_fields) (struct bitpack_d *, tree);
+
+ /* [OPT] Called by lto_materialize_tree for tree nodes that it does not
+ know how to allocate memory for. If defined, this hook should
+ return a new tree node of the given code. The data_in and
+ input_block arguments are passed in case the hook needs to
+ read more data from the stream to allocate the node.
+ If this hook returns NULL, then lto_materialize_tree will attempt
+ to allocate the tree by calling make_node directly. */
+ tree (*alloc_tree) (enum tree_code, struct lto_input_block *,
+ struct data_in *);
+
+ /* [OPT] Called by lto_output_tree_header to write any streamer-specific
+ information needed to allocate the tree. This hook may assume
+ that the basic header data (tree code, etc) has already been
+ written. It should only write any extra data needed to allocate
+ the node (e.g., in the case of CALL_EXPR, this hook would write
+ the number of arguments to the CALL_EXPR). */
+ void (*output_tree_header) (struct output_block *, tree);
+};
+
+/* Streamer hooks. */
+extern struct streamer_hooks streamer_hooks;
+
/* In lto-section-in.c */
extern struct lto_input_block * lto_create_simple_input_block (
struct lto_file_decl_data *,
@@ -851,17 +937,20 @@ extern intptr_t lto_orig_address_get (tree);
extern void lto_orig_address_remove (tree);
#endif
extern void lto_check_version (int, int);
-
+extern void lto_streamer_hooks_init (void);
+extern void lto_streamer_write_tree (struct output_block *, tree, bool);
+extern void lto_streamer_read_tree (struct lto_input_block *,
+ struct data_in *, tree);
+extern void streamer_hooks_init (void);
/* In lto-streamer-in.c */
extern void lto_input_cgraph (struct lto_file_decl_data *, const char *);
-extern void lto_init_reader (void);
+extern void lto_reader_init (void);
extern tree lto_input_tree (struct lto_input_block *, struct data_in *);
extern void lto_input_function_body (struct lto_file_decl_data *, tree,
const char *);
extern void lto_input_constructors_and_inits (struct lto_file_decl_data *,
const char *);
-extern void lto_init_reader (void);
extern struct data_in *lto_data_in_create (struct lto_file_decl_data *,
const char *, unsigned,
VEC(ld_plugin_symbol_resolution_t,heap) *);
@@ -1063,31 +1152,6 @@ lto_stream_as_builtin_p (tree expr)
|| DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD));
}
-/* Return true if EXPR is a tree node that can be written to disk. */
-static inline bool
-lto_is_streamable (tree expr)
-{
- enum tree_code code = TREE_CODE (expr);
-
- /* Notice that we reject SSA_NAMEs as well. We only emit the SSA
- name version in lto_output_tree_ref (see output_ssa_names). */
- return !is_lang_specific (expr)
- && code != SSA_NAME
- && code != CALL_EXPR
- && code != LANG_TYPE
- && code != MODIFY_EXPR
- && code != INIT_EXPR
- && code != TARGET_EXPR
- && code != BIND_EXPR
- && code != WITH_CLEANUP_EXPR
- && code != STATEMENT_LIST
- && code != OMP_CLAUSE
- && code != OPTIMIZATION_NODE
- && (code == CASE_LABEL_EXPR
- || code == DECL_EXPR
- || TREE_CODE_CLASS (code) != tcc_statement);
-}
-
DEFINE_DECL_STREAM_FUNCS (TYPE, type)
DEFINE_DECL_STREAM_FUNCS (FIELD_DECL, field_decl)
DEFINE_DECL_STREAM_FUNCS (FN_DECL, fn_decl)