aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-streamer.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/tree-streamer.c')
-rw-r--r--gcc/tree-streamer.c54
1 files changed, 36 insertions, 18 deletions
diff --git a/gcc/tree-streamer.c b/gcc/tree-streamer.c
index e4d948b..fcdf432 100644
--- a/gcc/tree-streamer.c
+++ b/gcc/tree-streamer.c
@@ -92,16 +92,24 @@ streamer_check_handled_ts_structures (void)
static void
streamer_tree_cache_add_to_node_array (struct streamer_tree_cache_d *cache,
- unsigned ix, tree t)
+ unsigned ix, tree t, hashval_t hash)
{
/* Make sure we're either replacing an old element or
appending consecutively. */
gcc_assert (ix <= cache->nodes.length ());
if (ix == cache->nodes.length ())
- cache->nodes.safe_push (t);
+ {
+ cache->nodes.safe_push (t);
+ if (cache->hashes.exists ())
+ cache->hashes.safe_push (hash);
+ }
else
- cache->nodes[ix] = t;
+ {
+ cache->nodes[ix] = t;
+ if (cache->hashes.exists ())
+ cache->hashes[ix] = hash;
+ }
}
@@ -117,7 +125,7 @@ streamer_tree_cache_add_to_node_array (struct streamer_tree_cache_d *cache,
static bool
streamer_tree_cache_insert_1 (struct streamer_tree_cache_d *cache,
- tree t, unsigned *ix_p,
+ tree t, hashval_t hash, unsigned *ix_p,
bool insert_at_next_slot_p)
{
void **slot;
@@ -136,7 +144,7 @@ streamer_tree_cache_insert_1 (struct streamer_tree_cache_d *cache,
ix = *ix_p;
*slot = (void *)(size_t) (ix + 1);
- streamer_tree_cache_add_to_node_array (cache, ix, t);
+ streamer_tree_cache_add_to_node_array (cache, ix, t, hash);
/* Indicate that the item was not present in the cache. */
existed_p = false;
@@ -151,7 +159,7 @@ streamer_tree_cache_insert_1 (struct streamer_tree_cache_d *cache,
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);
+ streamer_tree_cache_add_to_node_array (cache, ix, t, hash);
*slot = (void *)(size_t) (ix + 1);
}
@@ -174,30 +182,33 @@ streamer_tree_cache_insert_1 (struct streamer_tree_cache_d *cache,
bool
streamer_tree_cache_insert (struct streamer_tree_cache_d *cache, tree t,
- unsigned *ix_p)
+ hashval_t hash, unsigned *ix_p)
{
- return streamer_tree_cache_insert_1 (cache, t, ix_p, true);
+ return streamer_tree_cache_insert_1 (cache, t, hash, ix_p, true);
}
-/* Insert tree node T in CACHE at slot IX. If T already
- existed in the cache return true. Otherwise, return false. */
+/* Replace the tree node with T in CACHE at slot IX. */
-bool
-streamer_tree_cache_insert_at (struct streamer_tree_cache_d *cache,
- tree t, unsigned ix)
+void
+streamer_tree_cache_replace_tree (struct streamer_tree_cache_d *cache,
+ tree t, unsigned ix)
{
- return streamer_tree_cache_insert_1 (cache, t, &ix, false);
+ hashval_t hash = 0;
+ if (cache->hashes.exists ())
+ hash = streamer_tree_cache_get_hash (cache, ix);
+ streamer_tree_cache_insert_1 (cache, t, hash, &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)
+streamer_tree_cache_append (struct streamer_tree_cache_d *cache,
+ tree t, hashval_t hash)
{
unsigned ix = cache->nodes.length ();
- streamer_tree_cache_insert_1 (cache, t, &ix, false);
+ streamer_tree_cache_insert_1 (cache, t, hash, &ix, false);
}
/* Return true if tree node T exists in CACHE, otherwise false. If IX_P is
@@ -257,7 +268,10 @@ record_common_node (struct streamer_tree_cache_d *cache, tree node)
if (!node)
node = error_mark_node;
- streamer_tree_cache_append (cache, node);
+ /* ??? FIXME, devise a better hash value. But the hash needs to be equal
+ for all frontend and lto1 invocations. So just use the position
+ in the cache as hash value. */
+ streamer_tree_cache_append (cache, node, cache->nodes.length ());
if (POINTER_TYPE_P (node)
|| TREE_CODE (node) == COMPLEX_TYPE
@@ -305,13 +319,16 @@ preload_common_nodes (struct streamer_tree_cache_d *cache)
/* Create a cache of pickled nodes. */
struct streamer_tree_cache_d *
-streamer_tree_cache_create (void)
+streamer_tree_cache_create (bool with_hashes)
{
struct streamer_tree_cache_d *cache;
cache = XCNEW (struct streamer_tree_cache_d);
cache->node_map = pointer_map_create ();
+ cache->nodes.create (165);
+ if (with_hashes)
+ cache->hashes.create (165);
/* Load all the well-known tree nodes that are always created by
the compiler on startup. This prevents writing them out
@@ -332,5 +349,6 @@ streamer_tree_cache_delete (struct streamer_tree_cache_d *c)
pointer_map_destroy (c->node_map);
c->nodes.release ();
+ c->hashes.release ();
free (c);
}