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