8sa1-gcc/gcc/tree-streamer.c
Diego Novillo 412288f1c0 data-streamer.h (streamer_write_zero): Rename from output_zero.
* data-streamer.h (streamer_write_zero): Rename from output_zero.
 	(streamer_write_uhwi): Rename from lto_output_uleb128.
 	(streamer_write_hwi): Rename from output_sleb128.
 	(streamer_write_string): Rename from lto_output_string.
 	(streamer_string_index): Rename from lto_string_index.
 	(streamer_write_string_with_length): Rename from
 	lto_output_string_with_length.
 	(streamer_write_uhwi_stream): Rename from lto_output_uleb128_stream.
 	(streamer_write_hwi_stream): Rename from lto_output_sleb128_stream.
 	(streamer_read_string): Rename from lto_input_string.
 	(streamer_read_indexed_string): Rename from input_string_internal.
 	(streamer_read_uhwi): Rename from lto_input_uleb128.
 	(streamer_read_hwi): Rename from lto_input_sleb128.
 	(streamer_write_hwi_in_range): Rename from lto_output_int_in_range.
 	(streamer_read_hwi_in_range): Rename from lto_input_int_in_range.
 	(streamer_write_enum): Rename from lto_output_enum.
 	(streamer_read_enum): Rename from lto_input_enum.
 	(streamer_write_record_start): Rename from output_record_start.
 	(streamer_read_record_start): Rename from input_record_start.
 	(streamer_write_bitpack): Rename from lto_output_bitpack.
 	(streamer_read_bitpack): Rename from lto_input_bitpack.
 	(streamer_write_char_stream): Rename from lto_output_1_stream.
 	(streamer_read_uchar): Rename from lto_input_1_unsigned.
 	* tree-streamer.h (streamer_cache_d): Rename from lto_streamer_cache_d.
 	(streamer_handle_as_builtin_p): Rename from lto_stream_as_builtin_p.
 	(streamer_read_string_cst): Rename from input_string_cst.
 	(streamer_read_chain): Rename from lto_input_chain.
 	(streamer_alloc_tree): Rename from lto_materialize_tree.
 	(streamer_read_tree_body): Rename from lto_input_tree_pointers.
 	(streamer_get_pickled_tree): Rename from lto_get_pickled_tree.
 	(streamer_get_builtin_tree): Rename from lto_get_builtin_tree.
 	(streamer_read_integer_cst): Rename from lto_input_integer_cst.
 	(streamer_read_tree_bitfields): Rename from tree_read_bitfields.
 	(streamer_write_chain): Rename from lto_output_chain.
 	(streamer_write_tree_header): Rename from lto_output_tree_header.
 	(streamer_pack_tree_bitfields): Rename from pack_value_fields.
 	(streamer_write_tree_body): Rename from lto_output_tree_pointers.
 	(streamer_write_integer_cst): Rename from lto_output_integer_cst.
 	(streamer_write_builtin): Rename from lto_output_builtin_tree.
 	(streamer_check_handled_ts_structures): Rename from
 	check_handled_ts_structures.
 	(streamer_tree_cache_insert): Rename from lto_streamer_cache_insert.
 	(streamer_tree_cache_insert_at): Rename from
 	lto_streamer_cache_insert_at.
 	(streamer_tree_cache_append): Rename from lto_streamer_cache_append.
 	(streamer_tree_cache_lookup): Rename from lto_streamer_cache_lookup.
 	(streamer_tree_cache_get): Rename from lto_streamer_cache_get.
 	(streamer_tree_cache_create): Rename from lto_streamer_cache_create.
 	(streamer_tree_cache_delete): Rename from lto_streamer_cache_delete.
 	* tree-streamer-out.c (write_string_cst): Rename from output_string_cst.
 	(write_identifier): Rename from output_identifier.
 	(write_ts_common_tree_pointers): Rename from
 	lto_output_ts_common_tree_pointers.
 	(write_ts_vector_tree_pointers): Rename from
 	lto_output_ts_vector_tree_pointers.
 	(write_ts_complex_tree_pointers): Rename from
 	lto_output_ts_complex_tree_pointers.
 	(write_ts_decl_minimal_tree_pointers): Rename from
 	lto_output_ts_decl_minimal_tree_pointers.
 	(write_ts_decl_common_tree_pointers): Rename from
 	lto_output_ts_decl_common_tree_pointers.
 	(write_ts_decl_non_common_tree_pointers): Rename from
 	lto_output_ts_decl_non_common_tree_pointers.
 	(write_ts_decl_with_vis_tree_pointers): Rename from
 	lto_output_ts_decl_with_vis_tree_pointers.
 	(write_ts_field_decl_tree_pointers): Rename from
 	lto_output_ts_field_decl_tree_pointers.
 	(write_ts_function_decl_tree_pointers): Rename from
 	lto_output_ts_function_decl_tree_pointers.
 	(write_ts_type_common_tree_pointers): Rename from
 	lto_output_ts_type_common_tree_pointers.
 	(write_ts_type_non_common_tree_pointers): Rename from
 	lto_output_ts_type_non_common_tree_pointers.
 	(write_ts_list_tree_pointers): Rename from
 	lto_output_ts_list_tree_pointers.
 	(write_ts_vec_tree_pointers): Rename from
 	lto_output_ts_vec_tree_pointers.
 	(write_ts_exp_tree_pointers): Rename from
 	lto_output_ts_exp_tree_pointers.
 	(write_ts_block_tree_pointers): Rename from
 	lto_output_ts_block_tree_pointers.
 	(write_ts_binfo_tree_pointers): Rename from
 	lto_output_ts_binfo_tree_pointers.
 	(write_ts_constructor_tree_pointers): Rename from
 	lto_output_ts_constructor_tree_pointers.
 	(write_ts_target_option): Rename from
 	lto_output_ts_target_option.
 	(write_ts_translation_unit_decl_tree_pointers): Rename from
 	lto_output_ts_translation_unit_decl_tree_pointers.
 	* tree-streamer.c (streamer_tree_cache_add_to_node_array):
 	Rename from lto_streamer_cache_add_to_node_array.
 	(streamer_tree_cache_insert_1): Rename from lto_streamer_cache_insert_1.
 	(record_common_node): Rename from lto_record_common_node.

	* streamer-hooks.h (bitpack_d, lto_streamer_cache_d): Remove forward
	declarations.
	* data-streamer-in.c (lto_input_widest_uint_uleb128): Remove unused
	function.
	* data-streamer-out.c (lto_output_widest_uint_uleb128_stream): Remove
	unused function.
	* Makefile.in (lto-section-out.o): Add dependency on DATA_STREAMER_H.
	(ipa-reference.o): Likewise.
	* lto-section-out.c: Include data-streamer.h.
	* ipa-reference.c: Include data-streamer.h.

From-SVN: r177704
2011-08-12 12:42:13 -04:00

340 lines
9.2 KiB
C

/* Miscellaneous utilities for tree streaming. Things that are used
in both input and output are here.
Copyright 2011 Free Software Foundation, Inc.
Contributed by Diego Novillo <dnovillo@google.com>
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "streamer-hooks.h"
#include "tree-streamer.h"
/* Check that all the TS_* structures handled by the streamer_write_* and
streamer_read_* routines are exactly ALL the structures defined in
treestruct.def. */
void
streamer_check_handled_ts_structures (void)
{
bool handled_p[LAST_TS_ENUM];
unsigned i;
memset (&handled_p, 0, sizeof (handled_p));
/* These are the TS_* structures that are either handled or
explicitly ignored by the streamer routines. */
handled_p[TS_BASE] = true;
handled_p[TS_TYPED] = true;
handled_p[TS_COMMON] = true;
handled_p[TS_INT_CST] = true;
handled_p[TS_REAL_CST] = true;
handled_p[TS_FIXED_CST] = true;
handled_p[TS_VECTOR] = true;
handled_p[TS_STRING] = true;
handled_p[TS_COMPLEX] = true;
handled_p[TS_IDENTIFIER] = true;
handled_p[TS_DECL_MINIMAL] = true;
handled_p[TS_DECL_COMMON] = true;
handled_p[TS_DECL_WRTL] = true;
handled_p[TS_DECL_NON_COMMON] = true;
handled_p[TS_DECL_WITH_VIS] = true;
handled_p[TS_FIELD_DECL] = true;
handled_p[TS_VAR_DECL] = true;
handled_p[TS_PARM_DECL] = true;
handled_p[TS_LABEL_DECL] = true;
handled_p[TS_RESULT_DECL] = true;
handled_p[TS_CONST_DECL] = true;
handled_p[TS_TYPE_DECL] = true;
handled_p[TS_FUNCTION_DECL] = true;
handled_p[TS_TYPE_COMMON] = true;
handled_p[TS_TYPE_WITH_LANG_SPECIFIC] = true;
handled_p[TS_TYPE_NON_COMMON] = true;
handled_p[TS_LIST] = true;
handled_p[TS_VEC] = true;
handled_p[TS_EXP] = true;
handled_p[TS_SSA_NAME] = true;
handled_p[TS_BLOCK] = true;
handled_p[TS_BINFO] = true;
handled_p[TS_STATEMENT_LIST] = true;
handled_p[TS_CONSTRUCTOR] = true;
handled_p[TS_OMP_CLAUSE] = true;
handled_p[TS_OPTIMIZATION] = true;
handled_p[TS_TARGET_OPTION] = true;
handled_p[TS_TRANSLATION_UNIT_DECL] = true;
/* Anything not marked above will trigger the following assertion.
If this assertion triggers, it means that there is a new TS_*
structure that should be handled by the streamer. */
for (i = 0; i < LAST_TS_ENUM; i++)
gcc_assert (handled_p[i]);
}
/* Helper for streamer_tree_cache_insert_1. Add T to CACHE->NODES at
slot IX. */
static void
streamer_tree_cache_add_to_node_array (struct streamer_tree_cache_d *cache,
unsigned ix, tree t)
{
/* Make sure we're either replacing an old element or
appending consecutively. */
gcc_assert (ix <= VEC_length (tree, cache->nodes));
if (ix == VEC_length (tree, cache->nodes))
VEC_safe_push (tree, heap, cache->nodes, t);
else
VEC_replace (tree, cache->nodes, ix, t);
}
/* Helper for streamer_tree_cache_insert and streamer_tree_cache_insert_at.
CACHE, T, and IX_P are as in streamer_tree_cache_insert.
If INSERT_AT_NEXT_SLOT_P is true, T is inserted at the next available
slot in the cache. Otherwise, T is inserted at the position indicated
in *IX_P.
If T already existed in CACHE, return true. Otherwise,
return false. */
static bool
streamer_tree_cache_insert_1 (struct streamer_tree_cache_d *cache,
tree t, unsigned *ix_p,
bool insert_at_next_slot_p)
{
void **slot;
unsigned ix;
bool existed_p;
gcc_assert (t);
slot = pointer_map_insert (cache->node_map, t);
if (!*slot)
{
/* Determine the next slot to use in the cache. */
if (insert_at_next_slot_p)
ix = VEC_length (tree, cache->nodes);
else
ix = *ix_p;
*slot = (void *)(size_t) (ix + 1);
streamer_tree_cache_add_to_node_array (cache, ix, t);
/* Indicate that the item was not present in the cache. */
existed_p = false;
}
else
{
ix = (size_t) *slot - 1;
if (!insert_at_next_slot_p && ix != *ix_p)
{
/* If the caller wants to insert T at a specific slot
location, and ENTRY->TO does not match *IX_P, add T to
the requested location slot. */
ix = *ix_p;
streamer_tree_cache_add_to_node_array (cache, ix, t);
}
/* Indicate that T was already in the cache. */
existed_p = true;
}
if (ix_p)
*ix_p = ix;
return existed_p;
}
/* Insert tree node T in CACHE. If T already existed in the cache
return true. Otherwise, return false.
If IX_P is non-null, update it with the index into the cache where
T has been stored. */
bool
streamer_tree_cache_insert (struct streamer_tree_cache_d *cache, tree t,
unsigned *ix_p)
{
return streamer_tree_cache_insert_1 (cache, t, ix_p, true);
}
/* Insert tree node T in CACHE at slot IX. If T already
existed in the cache return true. Otherwise, return false. */
bool
streamer_tree_cache_insert_at (struct streamer_tree_cache_d *cache,
tree t, unsigned ix)
{
return streamer_tree_cache_insert_1 (cache, t, &ix, false);
}
/* Appends tree node T to CACHE, even if T already existed in it. */
void
streamer_tree_cache_append (struct streamer_tree_cache_d *cache, tree t)
{
unsigned ix = VEC_length (tree, cache->nodes);
streamer_tree_cache_insert_1 (cache, t, &ix, false);
}
/* Return true if tree node T exists in CACHE, otherwise false. If IX_P is
not NULL, write to *IX_P the index into the cache where T is stored
((unsigned)-1 if T is not found). */
bool
streamer_tree_cache_lookup (struct streamer_tree_cache_d *cache, tree t,
unsigned *ix_p)
{
void **slot;
bool retval;
unsigned ix;
gcc_assert (t);
slot = pointer_map_contains (cache->node_map, t);
if (slot == NULL)
{
retval = false;
ix = -1;
}
else
{
retval = true;
ix = (size_t) *slot - 1;
}
if (ix_p)
*ix_p = ix;
return retval;
}
/* Return the tree node at slot IX in CACHE. */
tree
streamer_tree_cache_get (struct streamer_tree_cache_d *cache, unsigned ix)
{
gcc_assert (cache);
/* Make sure we're not requesting something we don't have. */
gcc_assert (ix < VEC_length (tree, cache->nodes));
return VEC_index (tree, cache->nodes, ix);
}
/* Record NODE in CACHE. */
static void
record_common_node (struct streamer_tree_cache_d *cache, tree node)
{
/* We have to make sure to fill exactly the same number of
elements for all frontends. That can include NULL trees.
As our hash table can't deal with zero entries we'll simply stream
a random other tree. A NULL tree never will be looked up so it
doesn't matter which tree we replace it with, just to be sure
use error_mark_node. */
if (!node)
node = error_mark_node;
streamer_tree_cache_append (cache, node);
if (POINTER_TYPE_P (node)
|| TREE_CODE (node) == COMPLEX_TYPE
|| TREE_CODE (node) == ARRAY_TYPE)
record_common_node (cache, TREE_TYPE (node));
else if (TREE_CODE (node) == RECORD_TYPE)
{
/* The FIELD_DECLs of structures should be shared, so that every
COMPONENT_REF uses the same tree node when referencing a field.
Pointer equality between FIELD_DECLs is used by the alias
machinery to compute overlapping memory references (See
nonoverlapping_component_refs_p). */
tree f;
for (f = TYPE_FIELDS (node); f; f = TREE_CHAIN (f))
record_common_node (cache, f);
}
}
/* Preload common nodes into CACHE and make sure they are merged
properly according to the gimple type table. */
static void
preload_common_nodes (struct streamer_tree_cache_d *cache)
{
unsigned i;
for (i = 0; i < itk_none; i++)
/* Skip itk_char. char_type_node is dependent on -f[un]signed-char. */
if (i != itk_char)
record_common_node (cache, integer_types[i]);
for (i = 0; i < TYPE_KIND_LAST; i++)
record_common_node (cache, sizetype_tab[i]);
for (i = 0; i < TI_MAX; i++)
/* Skip boolean type and constants, they are frontend dependent. */
if (i != TI_BOOLEAN_TYPE
&& i != TI_BOOLEAN_FALSE
&& i != TI_BOOLEAN_TRUE)
record_common_node (cache, global_trees[i]);
}
/* Create a cache of pickled nodes. */
struct streamer_tree_cache_d *
streamer_tree_cache_create (void)
{
struct streamer_tree_cache_d *cache;
cache = XCNEW (struct streamer_tree_cache_d);
cache->node_map = pointer_map_create ();
/* Load all the well-known tree nodes that are always created by
the compiler on startup. This prevents writing them out
unnecessarily. */
preload_common_nodes (cache);
return cache;
}
/* Delete the streamer cache C. */
void
streamer_tree_cache_delete (struct streamer_tree_cache_d *c)
{
if (c == NULL)
return;
pointer_map_destroy (c->node_map);
VEC_free (tree, heap, c->nodes);
free (c);
}