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