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