]>
Commit | Line | Data |
---|---|---|
d7f09764 DN |
1 | /* Data structures and declarations used for reading and writing |
2 | GIMPLE to a file stream. | |
3 | ||
8d9254fc | 4 | Copyright (C) 2009-2020 Free Software Foundation, Inc. |
d7f09764 DN |
5 | Contributed by Doug Kwan <dougkwan@google.com> |
6 | ||
7 | This file is part of GCC. | |
8 | ||
9 | GCC is free software; you can redistribute it and/or modify it under | |
10 | the terms of the GNU General Public License as published by the Free | |
11 | Software Foundation; either version 3, or (at your option) any later | |
12 | version. | |
13 | ||
14 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
15 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 | for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with GCC; see the file COPYING3. If not see | |
21 | <http://www.gnu.org/licenses/>. */ | |
22 | ||
23 | #ifndef GCC_LTO_STREAMER_H | |
24 | #define GCC_LTO_STREAMER_H | |
25 | ||
26 | #include "plugin-api.h" | |
db0bf14f | 27 | #include "gcov-io.h" |
f0efc7aa | 28 | #include "diagnostic.h" |
47c79d56 | 29 | |
d7f09764 DN |
30 | /* The encoding for a function consists of the following sections: |
31 | ||
32 | 1) The header. | |
33 | 2) FIELD_DECLS. | |
34 | 3) FUNCTION_DECLS. | |
35 | 4) global VAR_DECLS. | |
36 | 5) type_decls | |
37 | 6) types. | |
38 | 7) Names for the labels that have names | |
39 | 8) The SSA names. | |
40 | 9) The control flow graph. | |
41 | 10-11)Gimple for local decls. | |
42 | 12) Gimple for the function. | |
43 | 13) Strings. | |
44 | ||
45 | 1) THE HEADER. | |
46 | 2-6) THE GLOBAL DECLS AND TYPES. | |
47 | ||
48 | The global decls and types are encoded in the same way. For each | |
49 | entry, there is word with the offset within the section to the | |
50 | entry. | |
51 | ||
b8698a0f | 52 | 7) THE LABEL NAMES. |
d7f09764 DN |
53 | |
54 | Since most labels do not have names, this section my be of zero | |
55 | length. It consists of an array of string table references, one | |
56 | per label. In the lto code, the labels are given either | |
57 | positive or negative indexes. the positive ones have names and | |
58 | the negative ones do not. The positive index can be used to | |
59 | find the name in this array. | |
60 | ||
b8698a0f | 61 | 9) THE CFG. |
d7f09764 DN |
62 | |
63 | 10) Index into the local decls. Since local decls can have local | |
64 | decls inside them, they must be read in randomly in order to | |
b8698a0f | 65 | properly restore them. |
d7f09764 DN |
66 | |
67 | 11-12) GIMPLE FOR THE LOCAL DECLS AND THE FUNCTION BODY. | |
68 | ||
69 | The gimple consists of a set of records. | |
70 | ||
71 | THE FUNCTION | |
b8698a0f | 72 | |
d7f09764 DN |
73 | At the top level of (8) is the function. It consists of five |
74 | pieces: | |
75 | ||
76 | LTO_function - The tag. | |
77 | eh tree - This is all of the exception handling regions | |
78 | put out in a post order traversial of the | |
79 | tree. Siblings are output as lists terminated | |
80 | by a 0. The set of fields matches the fields | |
81 | defined in except.c. | |
82 | ||
83 | last_basic_block - in uleb128 form. | |
84 | ||
85 | basic blocks - This is the set of basic blocks. | |
86 | ||
87 | zero - The termination of the basic blocks. | |
88 | ||
89 | BASIC BLOCKS | |
90 | ||
91 | There are two forms of basic blocks depending on if they are | |
92 | empty or not. | |
93 | ||
94 | The basic block consists of: | |
95 | ||
96 | LTO_bb1 or LTO_bb0 - The tag. | |
97 | ||
98 | bb->index - the index in uleb128 form. | |
99 | ||
100 | #succs - The number of successors un uleb128 form. | |
101 | ||
102 | the successors - For each edge, a pair. The first of the | |
103 | pair is the index of the successor in | |
104 | uleb128 form and the second are the flags in | |
105 | uleb128 form. | |
106 | ||
107 | the statements - A gimple tree, as described above. | |
108 | These are only present for LTO_BB1. | |
109 | Following each statement is an optional | |
110 | exception handling record LTO_eh_region | |
111 | which contains the region number (for | |
112 | regions >= 0). | |
113 | ||
114 | zero - This is only present for LTO_BB1 and is used | |
115 | to terminate the statements and exception | |
116 | regions within this block. | |
117 | ||
118 | 12) STRINGS | |
119 | ||
120 | String are represented in the table as pairs, a length in ULEB128 | |
121 | form followed by the data for the string. */ | |
122 | ||
86c23d93 | 123 | #define LTO_major_version 9 |
15b25b24 | 124 | #define LTO_minor_version 0 |
d7f09764 DN |
125 | |
126 | typedef unsigned char lto_decl_flags_t; | |
127 | ||
a746f952 JH |
128 | /* Stream additional data to LTO object files to make it easier to debug |
129 | streaming code. This changes object files. */ | |
130 | static const bool streamer_debugging = false; | |
d7f09764 | 131 | |
d7f09764 DN |
132 | /* Tags representing the various IL objects written to the bytecode file |
133 | (GIMPLE statements, basic blocks, EH regions, tree nodes, etc). | |
134 | ||
135 | NOTE, when adding new LTO tags, also update lto_tag_name. */ | |
b8698a0f | 136 | enum LTO_tags |
d7f09764 DN |
137 | { |
138 | LTO_null = 0, | |
139 | ||
15d16c8a RB |
140 | /* Special for streamer. Reference to previously-streamed node. */ |
141 | LTO_tree_pickle_reference, | |
142 | ||
d7f09764 DN |
143 | /* Reserve enough entries to fit all the tree and gimple codes handled |
144 | by the streamer. This guarantees that: | |
145 | ||
146 | 1- Given a tree code C: | |
147 | enum LTO_tags tag == C + 1 | |
148 | ||
149 | 2- Given a gimple code C: | |
150 | enum LTO_tags tag == C + NUM_TREE_CODES + 1 | |
151 | ||
152 | Conversely, to map between LTO tags and tree/gimple codes, the | |
153 | reverse operation must be applied. */ | |
07233947 | 154 | LTO_bb0 = 1 + MAX_TREE_CODES + LAST_AND_UNUSED_GIMPLE_CODE, |
d7f09764 DN |
155 | LTO_bb1, |
156 | ||
157 | /* EH region holding the previous statement. */ | |
158 | LTO_eh_region, | |
159 | ||
c61f8c3b RG |
160 | /* Shared INTEGER_CST node. */ |
161 | LTO_integer_cst, | |
162 | ||
d7f09764 DN |
163 | /* Function body. */ |
164 | LTO_function, | |
165 | ||
166 | /* EH table. */ | |
167 | LTO_eh_table, | |
168 | ||
169 | /* EH region types. These mirror enum eh_region_type. */ | |
170 | LTO_ert_cleanup, | |
171 | LTO_ert_try, | |
172 | LTO_ert_allowed_exceptions, | |
173 | LTO_ert_must_not_throw, | |
174 | ||
175 | /* EH landing pad. */ | |
176 | LTO_eh_landing_pad, | |
177 | ||
178 | /* EH try/catch node. */ | |
179 | LTO_eh_catch, | |
180 | ||
ee03e71d RB |
181 | /* Special for global streamer. A blob of unnamed tree nodes. */ |
182 | LTO_tree_scc, | |
183 | ||
03d90a20 JH |
184 | /* Sequence of trees. */ |
185 | LTO_trees, | |
186 | ||
d7f09764 | 187 | /* References to indexable tree nodes. These objects are stored in |
1746d5f3 JH |
188 | tables that are written separately from the function bodies |
189 | and variable constructors that reference them. This way they can be | |
190 | instantiated even when the referencing functions aren't (e.g., during WPA) | |
191 | and it also allows functions to be copied from one file to another without | |
192 | having to unpickle the body first (the references are location | |
193 | independent). */ | |
194 | LTO_global_stream_ref, | |
195 | ||
d7f09764 | 196 | LTO_ssa_name_ref, |
d7f09764 DN |
197 | |
198 | /* This tag must always be last. */ | |
199 | LTO_NUM_TAGS | |
200 | }; | |
201 | ||
202 | ||
203 | /* Set of section types that are in an LTO file. This list will grow | |
204 | as the number of IPA passes grows since each IPA pass will need its | |
205 | own section type to store its summary information. | |
206 | ||
207 | When adding a new section type, you must also extend the | |
208 | LTO_SECTION_NAME array in lto-section-in.c. */ | |
209 | enum lto_section_type | |
210 | { | |
211 | LTO_section_decls = 0, | |
212 | LTO_section_function_body, | |
213 | LTO_section_static_initializer, | |
ab96cc5b | 214 | LTO_section_symtab, |
c8429c2a | 215 | LTO_section_symtab_extension, |
369451ec | 216 | LTO_section_refs, |
49f836ba | 217 | LTO_section_asm, |
fb3f88cc | 218 | LTO_section_jump_functions, |
d7f09764 DN |
219 | LTO_section_ipa_pure_const, |
220 | LTO_section_ipa_reference, | |
0208f7da | 221 | LTO_section_ipa_profile, |
ab96cc5b | 222 | LTO_section_symtab_nodes, |
d7f09764 | 223 | LTO_section_opts, |
922f15c2 | 224 | LTO_section_cgraph_opt_sum, |
0bceb671 | 225 | LTO_section_ipa_fn_summary, |
2c9561b5 | 226 | LTO_section_ipcp_transform, |
b84d4347 | 227 | LTO_section_ipa_icf, |
ec6fe917 | 228 | LTO_section_offload_table, |
db847fa8 | 229 | LTO_section_mode_table, |
b2b40051 | 230 | LTO_section_ipa_hsa, |
88614dfa | 231 | LTO_section_lto, |
ff6686d2 | 232 | LTO_section_ipa_sra, |
d7f09764 DN |
233 | LTO_N_SECTION_TYPES /* Must be last. */ |
234 | }; | |
235 | ||
236 | /* Indices to the various function, type and symbol streams. */ | |
84562394 | 237 | enum lto_decl_stream_e_t |
d7f09764 | 238 | { |
ff7da2b5 | 239 | LTO_DECL_STREAM = 0, /* Must be first. */ |
d7f09764 | 240 | LTO_N_DECL_STREAMS |
84562394 | 241 | }; |
d7f09764 DN |
242 | |
243 | typedef enum ld_plugin_symbol_resolution ld_plugin_symbol_resolution_t; | |
d7f09764 | 244 | |
d7f09764 DN |
245 | /* Return a char pointer to the start of a data stream for an lto pass |
246 | or function. The first parameter is the file data that contains | |
247 | the information. The second parameter is the type of information | |
248 | to be obtained. The third parameter is the name of the function | |
b8698a0f | 249 | and is only used when finding a function body; otherwise it is |
d7f09764 | 250 | NULL. The fourth parameter is the length of the data returned. */ |
b8698a0f | 251 | typedef const char* (lto_get_section_data_f) (struct lto_file_decl_data *, |
d7f09764 | 252 | enum lto_section_type, |
b8698a0f | 253 | const char *, |
3c56d8d8 | 254 | int, |
d7f09764 DN |
255 | size_t *); |
256 | ||
257 | /* Return the data found from the above call. The first three | |
258 | parameters are the same as above. The fourth parameter is the data | |
073a8998 | 259 | itself and the fifth is the length of the data. */ |
b8698a0f | 260 | typedef void (lto_free_section_data_f) (struct lto_file_decl_data *, |
d7f09764 DN |
261 | enum lto_section_type, |
262 | const char *, | |
263 | const char *, | |
264 | size_t); | |
265 | ||
eaeec5ec | 266 | /* The location cache holds expanded locations for streamed in trees. |
e4112065 | 267 | This is done to reduce memory usage of libcpp linemap that strongly prefers |
eaeec5ec JH |
268 | locations to be inserted in the soruce order. */ |
269 | ||
270 | class lto_location_cache | |
271 | { | |
272 | public: | |
273 | /* Apply all changes in location cache. Add locations into linemap and patch | |
274 | trees. */ | |
275 | bool apply_location_cache (); | |
276 | /* Tree merging did not suceed; mark all changes in the cache as accepted. */ | |
277 | void accept_location_cache (); | |
278 | /* Tree merging did suceed; throw away recent changes. */ | |
279 | void revert_location_cache (); | |
280 | void input_location (location_t *loc, struct bitpack_d *bp, | |
99b1c316 | 281 | class data_in *data_in); |
eaeec5ec JH |
282 | lto_location_cache () |
283 | : loc_cache (), accepted_length (0), current_file (NULL), current_line (0), | |
a9dfad6d | 284 | current_col (0), current_sysp (false), current_loc (UNKNOWN_LOCATION) |
eaeec5ec JH |
285 | { |
286 | gcc_assert (!current_cache); | |
287 | current_cache = this; | |
288 | } | |
289 | ~lto_location_cache () | |
290 | { | |
291 | apply_location_cache (); | |
292 | gcc_assert (current_cache == this); | |
293 | current_cache = NULL; | |
294 | } | |
295 | ||
296 | /* There can be at most one instance of location cache (combining multiple | |
297 | would bring it out of sync with libcpp linemap); point to current | |
298 | one. */ | |
299 | static lto_location_cache *current_cache; | |
300 | ||
301 | private: | |
302 | static int cmp_loc (const void *pa, const void *pb); | |
303 | ||
304 | struct cached_location | |
305 | { | |
306 | const char *file; | |
307 | location_t *loc; | |
308 | int line, col; | |
6c1bc27c | 309 | bool sysp; |
eaeec5ec JH |
310 | }; |
311 | ||
312 | /* The location cache. */ | |
313 | ||
50cfd44e | 314 | auto_vec<cached_location> loc_cache; |
eaeec5ec JH |
315 | |
316 | /* Accepted entries are ones used by trees that are known to be not unified | |
317 | by tree merging. */ | |
318 | ||
319 | int accepted_length; | |
320 | ||
321 | /* Bookkeeping to remember state in between calls to lto_apply_location_cache | |
322 | When streaming gimple, the location cache is not used and thus | |
323 | lto_apply_location_cache happens per location basis. It is then | |
324 | useful to avoid redundant calls of linemap API. */ | |
325 | ||
326 | const char *current_file; | |
327 | int current_line; | |
328 | int current_col; | |
6c1bc27c | 329 | bool current_sysp; |
eaeec5ec JH |
330 | location_t current_loc; |
331 | }; | |
332 | ||
d7f09764 | 333 | /* Structure used as buffer for reading an LTO file. */ |
207c68cd | 334 | class lto_input_block |
d7f09764 | 335 | { |
207c68cd RB |
336 | public: |
337 | /* Special constructor for the string table, it abuses this to | |
338 | do random access but use the uhwi decoder. */ | |
db847fa8 JJ |
339 | lto_input_block (const char *data_, unsigned int p_, unsigned int len_, |
340 | const unsigned char *mode_table_) | |
341 | : data (data_), mode_table (mode_table_), p (p_), len (len_) {} | |
342 | lto_input_block (const char *data_, unsigned int len_, | |
343 | const unsigned char *mode_table_) | |
344 | : data (data_), mode_table (mode_table_), p (0), len (len_) {} | |
207c68cd | 345 | |
d7f09764 | 346 | const char *data; |
db847fa8 | 347 | const unsigned char *mode_table; |
d7f09764 DN |
348 | unsigned int p; |
349 | unsigned int len; | |
350 | }; | |
351 | ||
88614dfa | 352 | /* Compression algorithm used for compression of LTO bytecode. */ |
d7f09764 | 353 | |
88614dfa ML |
354 | enum lto_compression |
355 | { | |
356 | ZLIB, | |
357 | ZSTD | |
358 | }; | |
359 | ||
360 | /* Structure that represents LTO ELF section with information | |
361 | about the format. */ | |
362 | ||
363 | struct lto_section | |
d7f09764 DN |
364 | { |
365 | int16_t major_version; | |
366 | int16_t minor_version; | |
d1caf05a ML |
367 | unsigned char slim_object; |
368 | ||
369 | /* Flags is a private field that is not defined publicly. */ | |
370 | uint16_t flags; | |
371 | ||
372 | /* Set compression to FLAGS. */ | |
373 | inline void set_compression (lto_compression c) | |
374 | { | |
375 | flags = c; | |
376 | } | |
377 | ||
378 | /* Get compression from FLAGS. */ | |
379 | inline lto_compression get_compression () | |
380 | { | |
381 | return (lto_compression) flags; | |
382 | } | |
d7f09764 DN |
383 | }; |
384 | ||
88614dfa ML |
385 | STATIC_ASSERT (sizeof (lto_section) == 8); |
386 | ||
207c68cd RB |
387 | /* The is the first part of the record in an LTO file for many of the |
388 | IPA passes. */ | |
88614dfa | 389 | struct lto_simple_header |
d7f09764 | 390 | { |
207c68cd RB |
391 | /* Size of main gimple body of function. */ |
392 | int32_t main_size; | |
393 | }; | |
d7f09764 | 394 | |
207c68cd RB |
395 | struct lto_simple_header_with_strings : lto_simple_header |
396 | { | |
d7f09764 DN |
397 | /* Size of the string table. */ |
398 | int32_t string_size; | |
399 | }; | |
400 | ||
207c68cd RB |
401 | /* The header for a function body. */ |
402 | struct lto_function_header : lto_simple_header_with_strings | |
403 | { | |
404 | /* Size of the cfg. */ | |
405 | int32_t cfg_size; | |
406 | }; | |
407 | ||
d7f09764 DN |
408 | |
409 | /* Structure describing a symbol section. */ | |
207c68cd | 410 | struct lto_decl_header : lto_simple_header_with_strings |
d7f09764 | 411 | { |
d7f09764 DN |
412 | /* Size of region for decl state. */ |
413 | int32_t decl_state_size; | |
414 | ||
415 | /* Number of nodes in globals stream. */ | |
416 | int32_t num_nodes; | |
49f836ba JB |
417 | }; |
418 | ||
419 | ||
d7f09764 DN |
420 | /* Statistics gathered during LTO, WPA and LTRANS. */ |
421 | struct lto_stats_d | |
422 | { | |
423 | unsigned HOST_WIDE_INT num_input_cgraph_nodes; | |
7b99cca4 | 424 | unsigned HOST_WIDE_INT num_output_symtab_nodes; |
d7f09764 DN |
425 | unsigned HOST_WIDE_INT num_input_files; |
426 | unsigned HOST_WIDE_INT num_output_files; | |
427 | unsigned HOST_WIDE_INT num_cgraph_partitions; | |
428 | unsigned HOST_WIDE_INT section_size[LTO_N_SECTION_TYPES]; | |
429 | unsigned HOST_WIDE_INT num_function_bodies; | |
430 | unsigned HOST_WIDE_INT num_trees[NUM_TREE_CODES]; | |
431 | unsigned HOST_WIDE_INT num_output_il_bytes; | |
432 | unsigned HOST_WIDE_INT num_compressed_il_bytes; | |
433 | unsigned HOST_WIDE_INT num_input_il_bytes; | |
434 | unsigned HOST_WIDE_INT num_uncompressed_il_bytes; | |
ee03e71d RB |
435 | unsigned HOST_WIDE_INT num_tree_bodies_output; |
436 | unsigned HOST_WIDE_INT num_pickle_refs_output; | |
d7f09764 DN |
437 | }; |
438 | ||
7b99cca4 | 439 | /* Entry of LTO symtab encoder. */ |
84562394 | 440 | struct lto_encoder_entry |
7b99cca4 | 441 | { |
5e20cdc9 | 442 | symtab_node *node; |
7b99cca4 JH |
443 | /* Is the node in this partition (i.e. ltrans of this partition will |
444 | be responsible for outputting it)? */ | |
445 | unsigned int in_partition:1; | |
446 | /* Do we encode body in this partition? */ | |
447 | unsigned int body:1; | |
448 | /* Do we encode initializer in this partition? | |
449 | For example the readonly variable initializers are encoded to aid | |
450 | constant folding even if they are not in the partition. */ | |
451 | unsigned int initializer:1; | |
84562394 | 452 | }; |
7b99cca4 | 453 | |
7b99cca4 | 454 | |
d7f09764 | 455 | /* Encoder data structure used to stream callgraph nodes. */ |
7380e6ef | 456 | struct lto_symtab_encoder_d |
d7f09764 | 457 | { |
9771b263 | 458 | vec<lto_encoder_entry> nodes; |
b787e7a2 | 459 | hash_map<symtab_node *, size_t> *map; |
2f41ecf5 | 460 | }; |
7380e6ef JH |
461 | |
462 | typedef struct lto_symtab_encoder_d *lto_symtab_encoder_t; | |
2f41ecf5 | 463 | |
f27c1867 | 464 | /* Iterator structure for cgraph node sets. */ |
84562394 | 465 | struct lto_symtab_encoder_iterator |
703e95cf | 466 | { |
f27c1867 JH |
467 | lto_symtab_encoder_t encoder; |
468 | unsigned index; | |
84562394 | 469 | }; |
f27c1867 JH |
470 | |
471 | ||
472 | ||
d7f09764 DN |
473 | /* The lto_tree_ref_encoder struct is used to encode trees into indices. */ |
474 | ||
475 | struct lto_tree_ref_encoder | |
476 | { | |
1eb68d2d | 477 | hash_map<tree, unsigned> *tree_hash_table; /* Maps pointers to indices. */ |
d579fcda | 478 | vec<tree> trees; /* Maps indices to pointers. */ |
d7f09764 DN |
479 | }; |
480 | ||
481 | ||
482 | /* Structure to hold states of input scope. */ | |
907dadbd | 483 | struct GTY((for_user)) lto_in_decl_state |
d7f09764 DN |
484 | { |
485 | /* Array of lto_in_decl_buffers to store type and decls streams. */ | |
9c71e9df | 486 | vec<tree, va_gc> *streams[LTO_N_DECL_STREAMS]; |
d7f09764 DN |
487 | |
488 | /* If this in-decl state is associated with a function. FN_DECL | |
489 | point to the FUNCTION_DECL. */ | |
490 | tree fn_decl; | |
ca834876 JH |
491 | |
492 | /* True if decl state is compressed. */ | |
493 | bool compressed; | |
d7f09764 DN |
494 | }; |
495 | ||
496 | typedef struct lto_in_decl_state *lto_in_decl_state_ptr; | |
497 | ||
ca752f39 | 498 | struct decl_state_hasher : ggc_ptr_hash<lto_in_decl_state> |
907dadbd TS |
499 | { |
500 | static hashval_t | |
501 | hash (lto_in_decl_state *s) | |
502 | { | |
503 | return htab_hash_pointer (s->fn_decl); | |
504 | } | |
505 | ||
506 | static bool | |
507 | equal (lto_in_decl_state *a, lto_in_decl_state *b) | |
508 | { | |
509 | return a->fn_decl == b->fn_decl; | |
510 | } | |
511 | }; | |
d7f09764 DN |
512 | |
513 | /* The structure that holds all of the vectors of global types, | |
514 | decls and cgraph nodes used in the serialization of this file. */ | |
515 | struct lto_out_decl_state | |
516 | { | |
517 | /* The buffers contain the sets of decls of various kinds and types we have | |
518 | seen so far and the indexes assigned to them. */ | |
519 | struct lto_tree_ref_encoder streams[LTO_N_DECL_STREAMS]; | |
520 | ||
521 | /* Encoder for cgraph nodes. */ | |
7380e6ef | 522 | lto_symtab_encoder_t symtab_node_encoder; |
2f41ecf5 | 523 | |
d7f09764 DN |
524 | /* If this out-decl state belongs to a function, fn_decl points to that |
525 | function. Otherwise, it is NULL. */ | |
526 | tree fn_decl; | |
ca834876 JH |
527 | |
528 | /* True if decl state is compressed. */ | |
529 | bool compressed; | |
d7f09764 DN |
530 | }; |
531 | ||
532 | typedef struct lto_out_decl_state *lto_out_decl_state_ptr; | |
533 | ||
d7f09764 | 534 | |
aed7d7cf AK |
535 | /* Compact representation of a index <-> resolution pair. Unpacked to an |
536 | vector later. */ | |
537 | struct res_pair | |
538 | { | |
539 | ld_plugin_symbol_resolution_t res; | |
540 | unsigned index; | |
541 | }; | |
aed7d7cf | 542 | |
aed7d7cf | 543 | |
d7f09764 DN |
544 | /* One of these is allocated for each object file that being compiled |
545 | by lto. This structure contains the tables that are needed by the | |
546 | serialized functions and ipa passes to connect themselves to the | |
547 | global types and decls as they are reconstituted. */ | |
49ba8180 | 548 | struct GTY(()) lto_file_decl_data |
d7f09764 DN |
549 | { |
550 | /* Decl state currently used. */ | |
551 | struct lto_in_decl_state *current_decl_state; | |
552 | ||
553 | /* Decl state corresponding to regions outside of any functions | |
554 | in the compilation unit. */ | |
555 | struct lto_in_decl_state *global_decl_state; | |
556 | ||
557 | /* Table of cgraph nodes present in this file. */ | |
7380e6ef | 558 | lto_symtab_encoder_t GTY((skip)) symtab_node_encoder; |
2f41ecf5 | 559 | |
d7f09764 | 560 | /* Hash table maps lto-related section names to location in file. */ |
907dadbd | 561 | hash_table<decl_state_hasher> *function_decl_states; |
d7f09764 DN |
562 | |
563 | /* The .o file that these offsets relate to. */ | |
49ba8180 | 564 | const char *GTY((skip)) file_name; |
d7f09764 | 565 | |
d7f09764 | 566 | /* Hash table maps lto-related section names to location in file. */ |
49ba8180 | 567 | htab_t GTY((skip)) section_hash_table; |
d7f09764 DN |
568 | |
569 | /* Hash new name of renamed global declaration to its original name. */ | |
49ba8180 | 570 | htab_t GTY((skip)) renaming_hash_table; |
73ce4d1e AK |
571 | |
572 | /* Linked list used temporarily in reader */ | |
573 | struct lto_file_decl_data *next; | |
574 | ||
ebad2eee JH |
575 | /* Order in which the file appears on the command line. */ |
576 | int order; | |
577 | ||
73ce4d1e | 578 | /* Sub ID for merged objects. */ |
dde8b360 | 579 | unsigned HOST_WIDE_INT id; |
73ce4d1e AK |
580 | |
581 | /* Symbol resolutions for this file */ | |
9771b263 | 582 | vec<res_pair> GTY((skip)) respairs; |
aed7d7cf | 583 | unsigned max_index; |
db0bf14f | 584 | |
7f3577f5 | 585 | gcov_summary GTY((skip)) profile_info; |
bbf9ad07 JH |
586 | |
587 | /* Map assigning declarations their resolutions. */ | |
39c8aaa4 | 588 | hash_map<tree, ld_plugin_symbol_resolution> * GTY((skip)) resolution_map; |
db847fa8 JJ |
589 | |
590 | /* Mode translation table. */ | |
591 | const unsigned char *mode_table; | |
88614dfa ML |
592 | |
593 | /* Read LTO section. */ | |
594 | lto_section lto_section_header; | |
3c56d8d8 ML |
595 | |
596 | int order_base; | |
b74d8dc4 JH |
597 | |
598 | int unit_base; | |
d7f09764 DN |
599 | }; |
600 | ||
a9429e29 LB |
601 | typedef struct lto_file_decl_data *lto_file_decl_data_ptr; |
602 | ||
d7f09764 DN |
603 | struct lto_char_ptr_base |
604 | { | |
605 | char *ptr; | |
606 | }; | |
607 | ||
608 | /* An incore byte stream to buffer the various parts of the function. | |
609 | The entire structure should be zeroed when created. The record | |
610 | consists of a set of blocks. The first sizeof (ptr) bytes are used | |
611 | as a chain, and the rest store the bytes to be written. */ | |
612 | struct lto_output_stream | |
613 | { | |
614 | /* The pointer to the first block in the stream. */ | |
615 | struct lto_char_ptr_base * first_block; | |
616 | ||
617 | /* The pointer to the last and current block in the stream. */ | |
618 | struct lto_char_ptr_base * current_block; | |
619 | ||
620 | /* The pointer to where the next char should be written. */ | |
621 | char * current_pointer; | |
622 | ||
623 | /* The number of characters left in the current block. */ | |
624 | unsigned int left_in_block; | |
625 | ||
626 | /* The block size of the last block allocated. */ | |
627 | unsigned int block_size; | |
628 | ||
629 | /* The total number of characters written. */ | |
630 | unsigned int total_size; | |
631 | }; | |
632 | ||
d7f09764 DN |
633 | /* A simple output block. This can be used for simple IPA passes that |
634 | do not need more than one stream. */ | |
635 | struct lto_simple_output_block | |
636 | { | |
637 | enum lto_section_type section_type; | |
638 | struct lto_out_decl_state *decl_state; | |
639 | ||
640 | /* The stream that the main tree codes are written to. */ | |
641 | struct lto_output_stream *main_stream; | |
642 | }; | |
643 | ||
4a8fb1a1 LC |
644 | /* String hashing. */ |
645 | ||
646 | struct string_slot | |
647 | { | |
648 | const char *s; | |
649 | int len; | |
650 | unsigned int slot_num; | |
651 | }; | |
652 | ||
653 | /* Hashtable helpers. */ | |
654 | ||
8d67ee55 | 655 | struct string_slot_hasher : nofree_ptr_hash <string_slot> |
4a8fb1a1 | 656 | { |
67f58944 TS |
657 | static inline hashval_t hash (const string_slot *); |
658 | static inline bool equal (const string_slot *, const string_slot *); | |
4a8fb1a1 LC |
659 | }; |
660 | ||
661 | /* Returns a hash code for DS. Adapted from libiberty's htab_hash_string | |
662 | to support strings that may not end in '\0'. */ | |
663 | ||
664 | inline hashval_t | |
67f58944 | 665 | string_slot_hasher::hash (const string_slot *ds) |
4a8fb1a1 LC |
666 | { |
667 | hashval_t r = ds->len; | |
668 | int i; | |
669 | ||
670 | for (i = 0; i < ds->len; i++) | |
671 | r = r * 67 + (unsigned)ds->s[i] - 113; | |
672 | return r; | |
673 | } | |
674 | ||
675 | /* Returns nonzero if DS1 and DS2 are equal. */ | |
676 | ||
677 | inline bool | |
67f58944 | 678 | string_slot_hasher::equal (const string_slot *ds1, const string_slot *ds2) |
4a8fb1a1 LC |
679 | { |
680 | if (ds1->len == ds2->len) | |
681 | return memcmp (ds1->s, ds2->s, ds1->len) == 0; | |
682 | ||
683 | return 0; | |
684 | } | |
685 | ||
d7f09764 DN |
686 | /* Data structure holding all the data and descriptors used when writing |
687 | an LTO file. */ | |
688 | struct output_block | |
689 | { | |
690 | enum lto_section_type section_type; | |
691 | struct lto_out_decl_state *decl_state; | |
692 | ||
693 | /* The stream that the main tree codes are written to. */ | |
694 | struct lto_output_stream *main_stream; | |
695 | ||
696 | /* The stream that contains the string table. */ | |
697 | struct lto_output_stream *string_stream; | |
698 | ||
699 | /* The stream that contains the cfg. */ | |
700 | struct lto_output_stream *cfg_stream; | |
701 | ||
702 | /* The hash table that contains the set of strings we have seen so | |
703 | far and the indexes assigned to them. */ | |
c203e8a7 | 704 | hash_table<string_slot_hasher> *string_hash_table; |
d7f09764 | 705 | |
0b83e688 | 706 | /* The current symbol that we are currently serializing. Null |
d7f09764 | 707 | if we are serializing something else. */ |
f473c082 | 708 | symtab_node *symbol; |
d7f09764 DN |
709 | |
710 | /* These are the last file and line that were seen in the stream. | |
711 | If the current node differs from these, it needs to insert | |
712 | something into the stream and fix these up. */ | |
713 | const char *current_file; | |
714 | int current_line; | |
715 | int current_col; | |
6c1bc27c | 716 | bool current_sysp; |
d7f09764 | 717 | |
d7f09764 | 718 | /* Cache of nodes written in this section. */ |
412288f1 | 719 | struct streamer_tree_cache_d *writer_cache; |
fac009a8 | 720 | |
03d90a20 JH |
721 | /* All trees identified as local to the unit streamed. */ |
722 | hash_set<tree> *local_trees; | |
723 | ||
fac009a8 JH |
724 | /* All data persistent across whole duration of output block |
725 | can go here. */ | |
726 | struct obstack obstack; | |
d7f09764 DN |
727 | }; |
728 | ||
729 | ||
730 | /* Data and descriptors used when reading from an LTO file. */ | |
6c1dae73 | 731 | class data_in |
d7f09764 | 732 | { |
6c1dae73 | 733 | public: |
d7f09764 DN |
734 | /* The global decls and types. */ |
735 | struct lto_file_decl_data *file_data; | |
736 | ||
d7f09764 DN |
737 | /* The string table. */ |
738 | const char *strings; | |
739 | ||
740 | /* The length of the string table. */ | |
741 | unsigned int strings_len; | |
742 | ||
d7f09764 | 743 | /* Maps each reference number to the resolution done by the linker. */ |
9771b263 | 744 | vec<ld_plugin_symbol_resolution_t> globals_resolution; |
d7f09764 DN |
745 | |
746 | /* Cache of pickled nodes. */ | |
412288f1 | 747 | struct streamer_tree_cache_d *reader_cache; |
eaeec5ec JH |
748 | |
749 | /* Cache of source code location. */ | |
750 | lto_location_cache location_cache; | |
d7f09764 DN |
751 | }; |
752 | ||
753 | ||
754 | /* In lto-section-in.c */ | |
99b1c316 | 755 | extern class lto_input_block * lto_create_simple_input_block ( |
b8698a0f | 756 | struct lto_file_decl_data *, |
d7f09764 DN |
757 | enum lto_section_type, const char **, size_t *); |
758 | extern void | |
b8698a0f | 759 | lto_destroy_simple_input_block (struct lto_file_decl_data *, |
d7f09764 | 760 | enum lto_section_type, |
99b1c316 | 761 | class lto_input_block *, const char *, size_t); |
b8698a0f | 762 | extern void lto_set_in_hooks (struct lto_file_decl_data **, |
d7f09764 DN |
763 | lto_get_section_data_f *, |
764 | lto_free_section_data_f *); | |
765 | extern struct lto_file_decl_data **lto_get_file_decl_data (void); | |
766 | extern const char *lto_get_section_data (struct lto_file_decl_data *, | |
767 | enum lto_section_type, | |
3c56d8d8 | 768 | const char *, int, size_t *, |
ca834876 | 769 | bool decompress = false); |
3c56d8d8 ML |
770 | extern const char *lto_get_summary_section_data (struct lto_file_decl_data *, |
771 | enum lto_section_type, | |
772 | size_t *); | |
ca834876 JH |
773 | extern const char *lto_get_raw_section_data (struct lto_file_decl_data *, |
774 | enum lto_section_type, | |
3c56d8d8 | 775 | const char *, int, size_t *); |
d7f09764 | 776 | extern void lto_free_section_data (struct lto_file_decl_data *, |
ca834876 JH |
777 | enum lto_section_type, |
778 | const char *, const char *, size_t, | |
779 | bool decompress = false); | |
780 | extern void lto_free_raw_section_data (struct lto_file_decl_data *, | |
781 | enum lto_section_type, | |
782 | const char *, const char *, size_t); | |
d7f09764 DN |
783 | extern htab_t lto_create_renaming_table (void); |
784 | extern void lto_record_renamed_decl (struct lto_file_decl_data *, | |
785 | const char *, const char *); | |
786 | extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data *, | |
787 | const char *); | |
788 | extern struct lto_in_decl_state *lto_new_in_decl_state (void); | |
789 | extern void lto_delete_in_decl_state (struct lto_in_decl_state *); | |
d7f09764 DN |
790 | extern struct lto_in_decl_state *lto_get_function_in_decl_state ( |
791 | struct lto_file_decl_data *, tree); | |
82e9d642 | 792 | extern void lto_free_function_in_decl_state (struct lto_in_decl_state *); |
5e20cdc9 | 793 | extern void lto_free_function_in_decl_state_for_node (symtab_node *); |
99b1c316 | 794 | extern void lto_section_overrun (class lto_input_block *) ATTRIBUTE_NORETURN; |
f242c0a5 JH |
795 | extern void lto_value_range_error (const char *, |
796 | HOST_WIDE_INT, HOST_WIDE_INT, | |
797 | HOST_WIDE_INT) ATTRIBUTE_NORETURN; | |
d7f09764 DN |
798 | |
799 | /* In lto-section-out.c */ | |
d7f09764 DN |
800 | extern void lto_begin_section (const char *, bool); |
801 | extern void lto_end_section (void); | |
f6bcdb5e | 802 | extern void lto_write_data (const void *, unsigned int); |
ca834876 | 803 | extern void lto_write_raw_data (const void *, unsigned int); |
d7f09764 | 804 | extern void lto_write_stream (struct lto_output_stream *); |
d7f09764 DN |
805 | extern struct lto_simple_output_block *lto_create_simple_output_block ( |
806 | enum lto_section_type); | |
807 | extern void lto_destroy_simple_output_block (struct lto_simple_output_block *); | |
808 | extern struct lto_out_decl_state *lto_new_out_decl_state (void); | |
809 | extern void lto_delete_out_decl_state (struct lto_out_decl_state *); | |
810 | extern struct lto_out_decl_state *lto_get_out_decl_state (void); | |
811 | extern void lto_push_out_decl_state (struct lto_out_decl_state *); | |
812 | extern struct lto_out_decl_state *lto_pop_out_decl_state (void); | |
813 | extern void lto_record_function_out_decl_state (tree, | |
814 | struct lto_out_decl_state *); | |
bc0fe8cb | 815 | extern void lto_append_block (struct lto_output_stream *); |
d7f09764 DN |
816 | |
817 | ||
818 | /* In lto-streamer.c. */ | |
1b34e6e2 BS |
819 | |
820 | /* Set when streaming LTO for offloading compiler. */ | |
821 | extern bool lto_stream_offload_p; | |
822 | ||
d7f09764 | 823 | extern const char *lto_tag_name (enum LTO_tags); |
3c56d8d8 ML |
824 | extern char *lto_get_section_name (int, const char *, int, |
825 | struct lto_file_decl_data *); | |
b8f4e58f | 826 | extern void print_lto_report (const char *); |
d7f09764 DN |
827 | extern void lto_streamer_init (void); |
828 | extern bool gate_lto_out (void); | |
b898d037 | 829 | extern void lto_check_version (int, int, const char *); |
47c79d56 | 830 | extern void lto_streamer_hooks_init (void); |
d7f09764 DN |
831 | |
832 | /* In lto-streamer-in.c */ | |
d7f09764 | 833 | extern void lto_input_cgraph (struct lto_file_decl_data *, const char *); |
47c79d56 | 834 | extern void lto_reader_init (void); |
c38ee9a2 | 835 | extern void lto_free_file_name_hash (void); |
5e581212 JH |
836 | extern void lto_input_function_body (struct lto_file_decl_data *, |
837 | struct cgraph_node *, | |
d7f09764 | 838 | const char *); |
0b83e688 JH |
839 | extern void lto_input_variable_constructor (struct lto_file_decl_data *, |
840 | struct varpool_node *, | |
841 | const char *); | |
d7f09764 DN |
842 | extern void lto_input_constructors_and_inits (struct lto_file_decl_data *, |
843 | const char *); | |
398f05da | 844 | extern void lto_input_toplevel_asms (struct lto_file_decl_data *, int); |
db847fa8 | 845 | extern void lto_input_mode_table (struct lto_file_decl_data *); |
99b1c316 | 846 | extern class data_in *lto_data_in_create (struct lto_file_decl_data *, |
d7f09764 | 847 | const char *, unsigned, |
9771b263 | 848 | vec<ld_plugin_symbol_resolution_t> ); |
99b1c316 MS |
849 | extern void lto_data_in_delete (class data_in *); |
850 | extern void lto_input_data_block (class lto_input_block *, void *, size_t); | |
851 | void lto_input_location (location_t *, struct bitpack_d *, class data_in *); | |
eaeec5ec | 852 | location_t stream_input_location_now (struct bitpack_d *bp, |
99b1c316 MS |
853 | class data_in *data); |
854 | tree lto_input_tree_ref (class lto_input_block *, class data_in *, | |
f0efc7aa DN |
855 | struct function *, enum LTO_tags); |
856 | void lto_tag_check_set (enum LTO_tags, int, ...); | |
857 | void lto_init_eh (void); | |
99b1c316 | 858 | hashval_t lto_input_scc (class lto_input_block *, class data_in *, |
03d90a20 | 859 | unsigned *, unsigned *, bool); |
99b1c316 | 860 | tree lto_input_tree_1 (class lto_input_block *, class data_in *, |
ee03e71d | 861 | enum LTO_tags, hashval_t hash); |
99b1c316 | 862 | tree lto_input_tree (class lto_input_block *, class data_in *); |
33e23881 | 863 | tree stream_read_tree_ref (class lto_input_block *, class data_in *); |
d7f09764 DN |
864 | |
865 | ||
866 | /* In lto-streamer-out.c */ | |
867 | extern void lto_register_decl_definition (tree, struct lto_file_decl_data *); | |
868 | extern struct output_block *create_output_block (enum lto_section_type); | |
869 | extern void destroy_output_block (struct output_block *); | |
7e54c608 | 870 | extern void lto_output_tree (struct output_block *, tree, bool, bool); |
33e23881 | 871 | extern void stream_write_tree_ref (struct output_block *, tree); |
ff7da2b5 JH |
872 | extern void lto_output_var_decl_ref (struct lto_out_decl_state *, |
873 | struct lto_output_stream *, tree); | |
874 | extern void lto_output_fn_decl_ref (struct lto_out_decl_state *, | |
875 | struct lto_output_stream *, tree); | |
876 | extern tree lto_input_var_decl_ref (lto_input_block *, lto_file_decl_data *); | |
877 | extern tree lto_input_fn_decl_ref (lto_input_block *, lto_file_decl_data *); | |
49f836ba | 878 | extern void lto_output_toplevel_asms (void); |
fb3f88cc | 879 | extern void produce_asm (struct output_block *ob, tree fn); |
38f4f02f BS |
880 | extern void lto_output (); |
881 | extern void produce_asm_for_decls (); | |
a183b5c7 DN |
882 | void lto_output_decl_state_streams (struct output_block *, |
883 | struct lto_out_decl_state *); | |
884 | void lto_output_decl_state_refs (struct output_block *, | |
885 | struct lto_output_stream *, | |
886 | struct lto_out_decl_state *); | |
7cb7d208 | 887 | void lto_output_location (struct output_block *, struct bitpack_d *, location_t); |
db847fa8 | 888 | void lto_output_init_mode_table (void); |
1fcf52a6 | 889 | void lto_prepare_function_for_streaming (cgraph_node *); |
d7f09764 DN |
890 | |
891 | ||
892 | /* In lto-cgraph.c */ | |
9cf7975d | 893 | extern bool asm_nodes_output; |
e75f8f79 | 894 | lto_symtab_encoder_t lto_symtab_encoder_new (bool); |
5e20cdc9 | 895 | int lto_symtab_encoder_encode (lto_symtab_encoder_t, symtab_node *); |
7380e6ef | 896 | void lto_symtab_encoder_delete (lto_symtab_encoder_t); |
5e20cdc9 | 897 | bool lto_symtab_encoder_delete_node (lto_symtab_encoder_t, symtab_node *); |
7380e6ef | 898 | bool lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t, |
91fbf0c7 | 899 | struct cgraph_node *); |
f27c1867 | 900 | bool lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t, |
5e20cdc9 | 901 | symtab_node *); |
f27c1867 | 902 | void lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t, |
5e20cdc9 | 903 | symtab_node *); |
91fbf0c7 | 904 | |
7380e6ef | 905 | bool lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t, |
2c8326a5 | 906 | varpool_node *); |
f27c1867 | 907 | void output_symtab (void); |
ab96cc5b | 908 | void input_symtab (void); |
ec6fe917 | 909 | void output_offload_tables (void); |
ed5d948d | 910 | void input_offload_tables (bool); |
369451ec | 911 | bool referenced_from_other_partition_p (struct ipa_ref_list *, |
f27c1867 | 912 | lto_symtab_encoder_t); |
9a809897 | 913 | bool reachable_from_other_partition_p (struct cgraph_node *, |
f27c1867 | 914 | lto_symtab_encoder_t); |
f473c082 | 915 | bool referenced_from_this_partition_p (symtab_node *, |
f27c1867 | 916 | lto_symtab_encoder_t); |
f3380641 | 917 | bool reachable_from_this_partition_p (struct cgraph_node *, |
f27c1867 | 918 | lto_symtab_encoder_t); |
b4661bfe | 919 | lto_symtab_encoder_t compute_ltrans_boundary (lto_symtab_encoder_t encoder); |
837bac8c | 920 | void select_what_to_stream (void); |
d7f09764 | 921 | |
325fe981 JH |
922 | /* In options-save.c. */ |
923 | void cl_target_option_stream_out (struct output_block *, struct bitpack_d *, | |
924 | struct cl_target_option *); | |
925 | ||
99b1c316 | 926 | void cl_target_option_stream_in (class data_in *, |
325fe981 JH |
927 | struct bitpack_d *, |
928 | struct cl_target_option *); | |
929 | ||
c518c102 ML |
930 | void cl_optimization_stream_out (struct output_block *, |
931 | struct bitpack_d *, struct cl_optimization *); | |
ca9a04da | 932 | |
99b1c316 | 933 | void cl_optimization_stream_in (class data_in *, |
c518c102 | 934 | struct bitpack_d *, struct cl_optimization *); |
ca9a04da | 935 | |
d7f09764 | 936 | |
d7f09764 DN |
937 | |
938 | /* In lto-opts.c. */ | |
d7f09764 | 939 | extern void lto_write_options (void); |
d7f09764 DN |
940 | |
941 | ||
d7f09764 DN |
942 | /* Statistics gathered during LTO, WPA and LTRANS. */ |
943 | extern struct lto_stats_d lto_stats; | |
944 | ||
945 | /* Section names corresponding to the values of enum lto_section_type. */ | |
946 | extern const char *lto_section_name[]; | |
947 | ||
948 | /* Holds all the out decl states of functions output so far in the | |
949 | current output file. */ | |
9771b263 | 950 | extern vec<lto_out_decl_state_ptr> lto_function_decl_states; |
d7f09764 DN |
951 | |
952 | /* Return true if LTO tag TAG corresponds to a tree code. */ | |
953 | static inline bool | |
954 | lto_tag_is_tree_code_p (enum LTO_tags tag) | |
955 | { | |
15d16c8a | 956 | return tag > LTO_tree_pickle_reference && (unsigned) tag <= MAX_TREE_CODES; |
d7f09764 DN |
957 | } |
958 | ||
959 | ||
960 | /* Return true if LTO tag TAG corresponds to a gimple code. */ | |
961 | static inline bool | |
962 | lto_tag_is_gimple_code_p (enum LTO_tags tag) | |
963 | { | |
15d16c8a RB |
964 | return (unsigned) tag >= NUM_TREE_CODES + 2 |
965 | && (unsigned) tag < 2 + NUM_TREE_CODES + LAST_AND_UNUSED_GIMPLE_CODE; | |
d7f09764 DN |
966 | } |
967 | ||
968 | ||
969 | /* Return the LTO tag corresponding to gimple code CODE. See enum | |
970 | LTO_tags for details on the conversion. */ | |
971 | static inline enum LTO_tags | |
972 | lto_gimple_code_to_tag (enum gimple_code code) | |
973 | { | |
15d16c8a | 974 | return (enum LTO_tags) ((unsigned) code + NUM_TREE_CODES + 2); |
d7f09764 DN |
975 | } |
976 | ||
977 | ||
978 | /* Return the GIMPLE code corresponding to TAG. See enum LTO_tags for | |
979 | details on the conversion. */ | |
980 | static inline enum gimple_code | |
981 | lto_tag_to_gimple_code (enum LTO_tags tag) | |
982 | { | |
983 | gcc_assert (lto_tag_is_gimple_code_p (tag)); | |
15d16c8a | 984 | return (enum gimple_code) ((unsigned) tag - NUM_TREE_CODES - 2); |
d7f09764 DN |
985 | } |
986 | ||
987 | ||
988 | /* Return the LTO tag corresponding to tree code CODE. See enum | |
989 | LTO_tags for details on the conversion. */ | |
990 | static inline enum LTO_tags | |
991 | lto_tree_code_to_tag (enum tree_code code) | |
992 | { | |
15d16c8a | 993 | return (enum LTO_tags) ((unsigned) code + 2); |
d7f09764 DN |
994 | } |
995 | ||
996 | ||
997 | /* Return the tree code corresponding to TAG. See enum LTO_tags for | |
998 | details on the conversion. */ | |
999 | static inline enum tree_code | |
1000 | lto_tag_to_tree_code (enum LTO_tags tag) | |
1001 | { | |
1002 | gcc_assert (lto_tag_is_tree_code_p (tag)); | |
15d16c8a | 1003 | return (enum tree_code) ((unsigned) tag - 2); |
d7f09764 DN |
1004 | } |
1005 | ||
f0efc7aa DN |
1006 | /* Check that tag ACTUAL == EXPECTED. */ |
1007 | static inline void | |
1008 | lto_tag_check (enum LTO_tags actual, enum LTO_tags expected) | |
1009 | { | |
1010 | if (actual != expected) | |
1011 | internal_error ("bytecode stream: expected tag %s instead of %s", | |
1012 | lto_tag_name (expected), lto_tag_name (actual)); | |
1013 | } | |
1014 | ||
1015 | /* Check that tag ACTUAL is in the range [TAG1, TAG2]. */ | |
1016 | static inline void | |
1017 | lto_tag_check_range (enum LTO_tags actual, enum LTO_tags tag1, | |
1018 | enum LTO_tags tag2) | |
1019 | { | |
1020 | if (actual < tag1 || actual > tag2) | |
1021 | internal_error ("bytecode stream: tag %s is not in the expected range " | |
1022 | "[%s, %s]", | |
1023 | lto_tag_name (actual), | |
1024 | lto_tag_name (tag1), | |
1025 | lto_tag_name (tag2)); | |
1026 | } | |
1027 | ||
d7f09764 DN |
1028 | /* Initialize an lto_out_decl_buffer ENCODER. */ |
1029 | static inline void | |
d579fcda | 1030 | lto_init_tree_ref_encoder (struct lto_tree_ref_encoder *encoder) |
d7f09764 | 1031 | { |
1eb68d2d | 1032 | encoder->tree_hash_table = new hash_map<tree, unsigned> (251); |
9771b263 | 1033 | encoder->trees.create (0); |
d7f09764 DN |
1034 | } |
1035 | ||
1036 | ||
073a8998 | 1037 | /* Destroy an lto_tree_ref_encoder ENCODER by freeing its contents. The |
d7f09764 DN |
1038 | memory used by ENCODER is not freed by this function. */ |
1039 | static inline void | |
1040 | lto_destroy_tree_ref_encoder (struct lto_tree_ref_encoder *encoder) | |
1041 | { | |
1042 | /* Hash table may be delete already. */ | |
1eb68d2d TS |
1043 | delete encoder->tree_hash_table; |
1044 | encoder->tree_hash_table = NULL; | |
9771b263 | 1045 | encoder->trees.release (); |
d7f09764 DN |
1046 | } |
1047 | ||
1048 | /* Return the number of trees encoded in ENCODER. */ | |
1049 | static inline unsigned int | |
1050 | lto_tree_ref_encoder_size (struct lto_tree_ref_encoder *encoder) | |
1051 | { | |
9771b263 | 1052 | return encoder->trees.length (); |
d7f09764 DN |
1053 | } |
1054 | ||
1055 | /* Return the IDX-th tree in ENCODER. */ | |
1056 | static inline tree | |
1057 | lto_tree_ref_encoder_get_tree (struct lto_tree_ref_encoder *encoder, | |
1058 | unsigned int idx) | |
1059 | { | |
9771b263 | 1060 | return encoder->trees[idx]; |
d7f09764 DN |
1061 | } |
1062 | ||
f27c1867 JH |
1063 | /* Return number of encoded nodes in ENCODER. */ |
1064 | static inline int | |
1065 | lto_symtab_encoder_size (lto_symtab_encoder_t encoder) | |
1066 | { | |
9771b263 | 1067 | return encoder->nodes.length (); |
7b99cca4 JH |
1068 | } |
1069 | ||
1070 | /* Value used to represent failure of lto_symtab_encoder_lookup. */ | |
1071 | #define LCC_NOT_FOUND (-1) | |
1072 | ||
1073 | /* Look up NODE in encoder. Return NODE's reference if it has been encoded | |
1074 | or LCC_NOT_FOUND if it is not there. */ | |
1075 | ||
1076 | static inline int | |
1077 | lto_symtab_encoder_lookup (lto_symtab_encoder_t encoder, | |
5e20cdc9 | 1078 | symtab_node *node) |
7b99cca4 | 1079 | { |
b787e7a2 TS |
1080 | size_t *slot = encoder->map->get (node); |
1081 | return (slot && *slot ? *(slot) - 1 : LCC_NOT_FOUND); | |
f27c1867 JH |
1082 | } |
1083 | ||
1084 | /* Return true if iterator LSE points to nothing. */ | |
1085 | static inline bool | |
1086 | lsei_end_p (lto_symtab_encoder_iterator lsei) | |
1087 | { | |
1088 | return lsei.index >= (unsigned)lto_symtab_encoder_size (lsei.encoder); | |
1089 | } | |
1090 | ||
1091 | /* Advance iterator LSE. */ | |
1092 | static inline void | |
1093 | lsei_next (lto_symtab_encoder_iterator *lsei) | |
1094 | { | |
1095 | lsei->index++; | |
1096 | } | |
1097 | ||
1098 | /* Return the node pointed to by LSI. */ | |
5e20cdc9 | 1099 | static inline symtab_node * |
f27c1867 JH |
1100 | lsei_node (lto_symtab_encoder_iterator lsei) |
1101 | { | |
9771b263 | 1102 | return lsei.encoder->nodes[lsei.index].node; |
f27c1867 JH |
1103 | } |
1104 | ||
1105 | /* Return the node pointed to by LSI. */ | |
1106 | static inline struct cgraph_node * | |
1107 | lsei_cgraph_node (lto_symtab_encoder_iterator lsei) | |
1108 | { | |
d52f5295 | 1109 | return dyn_cast<cgraph_node *> (lsei.encoder->nodes[lsei.index].node); |
f27c1867 JH |
1110 | } |
1111 | ||
1112 | /* Return the node pointed to by LSI. */ | |
2c8326a5 | 1113 | static inline varpool_node * |
f27c1867 JH |
1114 | lsei_varpool_node (lto_symtab_encoder_iterator lsei) |
1115 | { | |
d52f5295 | 1116 | return dyn_cast<varpool_node *> (lsei.encoder->nodes[lsei.index].node); |
f27c1867 JH |
1117 | } |
1118 | ||
f27c1867 JH |
1119 | /* Return the cgraph node corresponding to REF using ENCODER. */ |
1120 | ||
5e20cdc9 | 1121 | static inline symtab_node * |
f27c1867 JH |
1122 | lto_symtab_encoder_deref (lto_symtab_encoder_t encoder, int ref) |
1123 | { | |
1124 | if (ref == LCC_NOT_FOUND) | |
1125 | return NULL; | |
1126 | ||
9771b263 | 1127 | return encoder->nodes[ref].node; |
f27c1867 JH |
1128 | } |
1129 | ||
1130 | /* Return an iterator to the first node in LSI. */ | |
1131 | static inline lto_symtab_encoder_iterator | |
1132 | lsei_start (lto_symtab_encoder_t encoder) | |
1133 | { | |
1134 | lto_symtab_encoder_iterator lsei; | |
1135 | ||
1136 | lsei.encoder = encoder; | |
1137 | lsei.index = 0; | |
1138 | return lsei; | |
1139 | } | |
1140 | ||
1141 | /* Advance iterator LSE. */ | |
1142 | static inline void | |
1143 | lsei_next_in_partition (lto_symtab_encoder_iterator *lsei) | |
1144 | { | |
1145 | lsei_next (lsei); | |
1146 | while (!lsei_end_p (*lsei) | |
1147 | && !lto_symtab_encoder_in_partition_p (lsei->encoder, lsei_node (*lsei))) | |
1148 | lsei_next (lsei); | |
1149 | } | |
1150 | ||
1151 | /* Return an iterator to the first node in LSI. */ | |
1152 | static inline lto_symtab_encoder_iterator | |
1153 | lsei_start_in_partition (lto_symtab_encoder_t encoder) | |
1154 | { | |
1155 | lto_symtab_encoder_iterator lsei = lsei_start (encoder); | |
1156 | ||
1157 | if (lsei_end_p (lsei)) | |
1158 | return lsei; | |
1159 | if (!lto_symtab_encoder_in_partition_p (encoder, lsei_node (lsei))) | |
1160 | lsei_next_in_partition (&lsei); | |
1161 | ||
1162 | return lsei; | |
1163 | } | |
1164 | ||
1165 | /* Advance iterator LSE. */ | |
1166 | static inline void | |
1167 | lsei_next_function_in_partition (lto_symtab_encoder_iterator *lsei) | |
1168 | { | |
1169 | lsei_next (lsei); | |
1170 | while (!lsei_end_p (*lsei) | |
7de90a6c | 1171 | && (!is_a <cgraph_node *> (lsei_node (*lsei)) |
f27c1867 JH |
1172 | || !lto_symtab_encoder_in_partition_p (lsei->encoder, lsei_node (*lsei)))) |
1173 | lsei_next (lsei); | |
1174 | } | |
1175 | ||
1176 | /* Return an iterator to the first node in LSI. */ | |
1177 | static inline lto_symtab_encoder_iterator | |
1178 | lsei_start_function_in_partition (lto_symtab_encoder_t encoder) | |
1179 | { | |
1180 | lto_symtab_encoder_iterator lsei = lsei_start (encoder); | |
1181 | ||
1182 | if (lsei_end_p (lsei)) | |
1183 | return lsei; | |
7de90a6c | 1184 | if (!is_a <cgraph_node *> (lsei_node (lsei)) |
f27c1867 JH |
1185 | || !lto_symtab_encoder_in_partition_p (encoder, lsei_node (lsei))) |
1186 | lsei_next_function_in_partition (&lsei); | |
1187 | ||
1188 | return lsei; | |
1189 | } | |
1190 | ||
1191 | /* Advance iterator LSE. */ | |
1192 | static inline void | |
1193 | lsei_next_variable_in_partition (lto_symtab_encoder_iterator *lsei) | |
1194 | { | |
1195 | lsei_next (lsei); | |
1196 | while (!lsei_end_p (*lsei) | |
7de90a6c | 1197 | && (!is_a <varpool_node *> (lsei_node (*lsei)) |
f27c1867 JH |
1198 | || !lto_symtab_encoder_in_partition_p (lsei->encoder, lsei_node (*lsei)))) |
1199 | lsei_next (lsei); | |
1200 | } | |
1201 | ||
1202 | /* Return an iterator to the first node in LSI. */ | |
1203 | static inline lto_symtab_encoder_iterator | |
1204 | lsei_start_variable_in_partition (lto_symtab_encoder_t encoder) | |
1205 | { | |
1206 | lto_symtab_encoder_iterator lsei = lsei_start (encoder); | |
1207 | ||
1208 | if (lsei_end_p (lsei)) | |
1209 | return lsei; | |
7de90a6c | 1210 | if (!is_a <varpool_node *> (lsei_node (lsei)) |
f27c1867 JH |
1211 | || !lto_symtab_encoder_in_partition_p (encoder, lsei_node (lsei))) |
1212 | lsei_next_variable_in_partition (&lsei); | |
1213 | ||
1214 | return lsei; | |
1215 | } | |
1216 | ||
1ea85365 RB |
1217 | /* Entry for the delayed registering of decl -> DIE references. */ |
1218 | struct dref_entry { | |
1219 | tree decl; | |
1220 | const char *sym; | |
1221 | unsigned HOST_WIDE_INT off; | |
1222 | }; | |
1223 | ||
1224 | extern vec<dref_entry> dref_queue; | |
1225 | ||
b4da704c | 1226 | extern FILE *streamer_dump_file; |
1ea85365 | 1227 | |
d7f09764 | 1228 | #endif /* GCC_LTO_STREAMER_H */ |