]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tree-streamer.h
arm: Factorize several occurrences of the same code into reg_needs_saving_p
[thirdparty/gcc.git] / gcc / tree-streamer.h
CommitLineData
f0efc7aa
DN
1/* Data structures and functions for streaming trees.
2
8d9254fc 3 Copyright (C) 2011-2020 Free Software Foundation, Inc.
f0efc7aa
DN
4 Contributed by Diego Novillo <dnovillo@google.com>
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
21
22#ifndef GCC_TREE_STREAMER_H
23#define GCC_TREE_STREAMER_H
24
b9393656 25#include "streamer-hooks.h"
db847fa8 26#include "data-streamer.h"
f0efc7aa
DN
27
28/* Cache of pickled nodes. Used to avoid writing the same node more
29 than once. The first time a tree node is streamed out, it is
30 entered in this cache. Subsequent references to the same node are
31 resolved by looking it up in this cache.
32
33 This is used in two ways:
34
35 - On the writing side, the first time T is added to STREAMER_CACHE,
36 a new reference index is created for T and T is emitted on the
37 stream. If T needs to be emitted again to the stream, instead of
38 pickling it again, the reference index is emitted.
39
40 - On the reading side, the first time T is read from the stream, it
41 is reconstructed in memory and a new reference index created for
42 T. The reconstructed T is inserted in some array so that when
43 the reference index for T is found in the input stream, it can be
44 used to look up into the array to get the reconstructed T. */
ee03e71d 45
412288f1 46struct streamer_tree_cache_d
f0efc7aa
DN
47{
48 /* The mapping between tree nodes and slots into the nodes array. */
1eb68d2d 49 hash_map<tree, unsigned> *node_map;
f0efc7aa
DN
50
51 /* The nodes pickled so far. */
9771b263 52 vec<tree> nodes;
ee03e71d
RB
53 /* The node hashes (if available). */
54 vec<hashval_t> hashes;
bdc67fd6
RB
55
56 /* Next index to assign. */
57 unsigned next_idx;
f0efc7aa
DN
58};
59
60/* In tree-streamer-in.c. */
99b1c316
MS
61tree streamer_read_string_cst (class data_in *, class lto_input_block *);
62tree streamer_read_chain (class lto_input_block *, class data_in *);
63tree streamer_alloc_tree (class lto_input_block *, class data_in *,
412288f1 64 enum LTO_tags);
99b1c316
MS
65void streamer_read_tree_body (class lto_input_block *, class data_in *, tree);
66tree streamer_get_pickled_tree (class lto_input_block *, class data_in *);
67void streamer_read_tree_bitfields (class lto_input_block *,
68 class data_in *, tree);
f0efc7aa
DN
69
70/* In tree-streamer-out.c. */
49f836ba
JB
71void streamer_write_string_cst (struct output_block *,
72 struct lto_output_stream *, tree);
412288f1
DN
73void streamer_write_chain (struct output_block *, tree, bool);
74void streamer_write_tree_header (struct output_block *, tree);
b6bf201e 75void streamer_write_tree_bitfields (struct output_block *, tree);
412288f1
DN
76void streamer_write_tree_body (struct output_block *, tree, bool);
77void streamer_write_integer_cst (struct output_block *, tree, bool);
f0efc7aa
DN
78
79/* In tree-streamer.c. */
db847fa8 80extern unsigned char streamer_mode_table[1 << 8];
412288f1
DN
81void streamer_check_handled_ts_structures (void);
82bool streamer_tree_cache_insert (struct streamer_tree_cache_d *, tree,
ee03e71d
RB
83 hashval_t, unsigned *);
84void streamer_tree_cache_replace_tree (struct streamer_tree_cache_d *, tree,
85 unsigned);
86void streamer_tree_cache_append (struct streamer_tree_cache_d *, tree,
87 hashval_t);
412288f1
DN
88bool streamer_tree_cache_lookup (struct streamer_tree_cache_d *, tree,
89 unsigned *);
bdc67fd6 90struct streamer_tree_cache_d *streamer_tree_cache_create (bool, bool, bool);
412288f1 91void streamer_tree_cache_delete (struct streamer_tree_cache_d *);
f0efc7aa 92
58191b2e
RG
93/* Return the tree node at slot IX in CACHE. */
94
95static inline tree
ee03e71d 96streamer_tree_cache_get_tree (struct streamer_tree_cache_d *cache, unsigned ix)
58191b2e 97{
9771b263 98 return cache->nodes[ix];
58191b2e
RG
99}
100
ee03e71d
RB
101/* Return the tree hash value at slot IX in CACHE. */
102
103static inline hashval_t
104streamer_tree_cache_get_hash (struct streamer_tree_cache_d *cache, unsigned ix)
105{
106 return cache->hashes[ix];
107}
108
db847fa8
JJ
109static inline void
110bp_pack_machine_mode (struct bitpack_d *bp, machine_mode mode)
111{
112 streamer_mode_table[mode] = 1;
113 bp_pack_enum (bp, machine_mode, 1 << 8, mode);
114}
115
116static inline machine_mode
117bp_unpack_machine_mode (struct bitpack_d *bp)
118{
119 return (machine_mode)
99b1c316 120 ((class lto_input_block *)
db847fa8
JJ
121 bp->stream)->mode_table[bp_unpack_enum (bp, machine_mode, 1 << 8)];
122}
58191b2e 123
f0efc7aa 124#endif /* GCC_TREE_STREAMER_H */