testsuite: remove SPE tests.
[official-gcc.git] / gcc / lto-streamer.h
blobb17137f0f9a80a30aa16b4ede4ccd667dd4516a9
1 /* Data structures and declarations used for reading and writing
2 GIMPLE to a file stream.
4 Copyright (C) 2009-2020 Free Software Foundation, Inc.
5 Contributed by Doug Kwan <dougkwan@google.com>
7 This file is part of GCC.
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.
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.
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/>. */
23 #ifndef GCC_LTO_STREAMER_H
24 #define GCC_LTO_STREAMER_H
26 #include "plugin-api.h"
27 #include "gcov-io.h"
28 #include "diagnostic.h"
30 /* The encoding for a function consists of the following sections:
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.
45 1) THE HEADER.
46 2-6) THE GLOBAL DECLS AND TYPES.
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.
52 7) THE LABEL NAMES.
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.
61 9) THE CFG.
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
65 properly restore them.
67 11-12) GIMPLE FOR THE LOCAL DECLS AND THE FUNCTION BODY.
69 The gimple consists of a set of records.
71 THE FUNCTION
73 At the top level of (8) is the function. It consists of five
74 pieces:
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.
83 last_basic_block - in uleb128 form.
85 basic blocks - This is the set of basic blocks.
87 zero - The termination of the basic blocks.
89 BASIC BLOCKS
91 There are two forms of basic blocks depending on if they are
92 empty or not.
94 The basic block consists of:
96 LTO_bb1 or LTO_bb0 - The tag.
98 bb->index - the index in uleb128 form.
100 #succs - The number of successors un uleb128 form.
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.
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).
114 zero - This is only present for LTO_BB1 and is used
115 to terminate the statements and exception
116 regions within this block.
118 12) STRINGS
120 String are represented in the table as pairs, a length in ULEB128
121 form followed by the data for the string. */
123 #define LTO_major_version 9
124 #define LTO_minor_version 0
126 typedef unsigned char lto_decl_flags_t;
128 /* Stream additional data to LTO object files to make it easier to debug
129 streaming code. This changes object files. */
130 static const bool streamer_debugging = false;
132 /* Tags representing the various IL objects written to the bytecode file
133 (GIMPLE statements, basic blocks, EH regions, tree nodes, etc).
135 NOTE, when adding new LTO tags, also update lto_tag_name. */
136 enum LTO_tags
138 LTO_null = 0,
140 /* Reference to previously-streamed node. */
141 LTO_tree_pickle_reference,
143 /* References to indexable tree nodes. These objects are stored in
144 tables that are written separately from the function bodies
145 and variable constructors that reference them. This way they can be
146 instantiated even when the referencing functions aren't (e.g., during WPA)
147 and it also allows functions to be copied from one file to another without
148 having to unpickle the body first (the references are location
149 independent). */
150 LTO_global_stream_ref,
152 LTO_ssa_name_ref,
154 /* Special for global streamer. A blob of unnamed tree nodes. */
155 LTO_tree_scc,
157 /* Sequence of trees. */
158 LTO_trees,
160 /* Shared INTEGER_CST node. */
161 LTO_integer_cst,
163 /* Tags of trees are encoded as
164 LTO_first_tree_tag + TREE_CODE. */
165 LTO_first_tree_tag,
166 /* Tags of gimple typles are encoded as
167 LTO_first_gimple_tag + gimple_code. */
168 LTO_first_gimple_tag = LTO_first_tree_tag + MAX_TREE_CODES,
170 /* Entry and exit basic blocks. */
171 LTO_bb0 = LTO_first_gimple_tag + LAST_AND_UNUSED_GIMPLE_CODE,
172 LTO_bb1,
174 /* EH region holding the previous statement. */
175 LTO_eh_region,
177 /* Function body. */
178 LTO_function,
180 /* EH table. */
181 LTO_eh_table,
183 /* EH region types. These mirror enum eh_region_type. */
184 LTO_ert_cleanup,
185 LTO_ert_try,
186 LTO_ert_allowed_exceptions,
187 LTO_ert_must_not_throw,
189 /* EH landing pad. */
190 LTO_eh_landing_pad,
192 /* EH try/catch node. */
193 LTO_eh_catch,
195 /* This tag must always be last. */
196 LTO_NUM_TAGS
200 /* Set of section types that are in an LTO file. This list will grow
201 as the number of IPA passes grows since each IPA pass will need its
202 own section type to store its summary information.
204 When adding a new section type, you must also extend the
205 LTO_SECTION_NAME array in lto-section-in.c. */
206 enum lto_section_type
208 LTO_section_decls = 0,
209 LTO_section_function_body,
210 LTO_section_static_initializer,
211 LTO_section_symtab,
212 LTO_section_symtab_extension,
213 LTO_section_refs,
214 LTO_section_asm,
215 LTO_section_jump_functions,
216 LTO_section_ipa_pure_const,
217 LTO_section_ipa_reference,
218 LTO_section_ipa_profile,
219 LTO_section_symtab_nodes,
220 LTO_section_opts,
221 LTO_section_cgraph_opt_sum,
222 LTO_section_ipa_fn_summary,
223 LTO_section_ipcp_transform,
224 LTO_section_ipa_icf,
225 LTO_section_offload_table,
226 LTO_section_mode_table,
227 LTO_section_ipa_hsa,
228 LTO_section_lto,
229 LTO_section_ipa_sra,
230 LTO_section_odr_types,
231 LTO_N_SECTION_TYPES /* Must be last. */
234 /* Indices to the various function, type and symbol streams. */
235 enum lto_decl_stream_e_t
237 LTO_DECL_STREAM = 0, /* Must be first. */
238 LTO_N_DECL_STREAMS
241 typedef enum ld_plugin_symbol_resolution ld_plugin_symbol_resolution_t;
243 /* Return a char pointer to the start of a data stream for an lto pass
244 or function. The first parameter is the file data that contains
245 the information. The second parameter is the type of information
246 to be obtained. The third parameter is the name of the function
247 and is only used when finding a function body; otherwise it is
248 NULL. The fourth parameter is the length of the data returned. */
249 typedef const char* (lto_get_section_data_f) (struct lto_file_decl_data *,
250 enum lto_section_type,
251 const char *,
252 int,
253 size_t *);
255 /* Return the data found from the above call. The first three
256 parameters are the same as above. The fourth parameter is the data
257 itself and the fifth is the length of the data. */
258 typedef void (lto_free_section_data_f) (struct lto_file_decl_data *,
259 enum lto_section_type,
260 const char *,
261 const char *,
262 size_t);
264 /* The location cache holds expanded locations for streamed in trees.
265 This is done to reduce memory usage of libcpp linemap that strongly prefers
266 locations to be inserted in the soruce order. */
268 class lto_location_cache
270 public:
271 /* Apply all changes in location cache. Add locations into linemap and patch
272 trees. */
273 bool apply_location_cache ();
274 /* Tree merging did not suceed; mark all changes in the cache as accepted. */
275 void accept_location_cache ();
276 /* Tree merging did suceed; throw away recent changes. */
277 void revert_location_cache ();
278 void input_location (location_t *loc, struct bitpack_d *bp,
279 class data_in *data_in);
280 lto_location_cache ()
281 : loc_cache (), accepted_length (0), current_file (NULL), current_line (0),
282 current_col (0), current_sysp (false), current_loc (UNKNOWN_LOCATION)
284 gcc_assert (!current_cache);
285 current_cache = this;
287 ~lto_location_cache ()
289 apply_location_cache ();
290 gcc_assert (current_cache == this);
291 current_cache = NULL;
294 /* There can be at most one instance of location cache (combining multiple
295 would bring it out of sync with libcpp linemap); point to current
296 one. */
297 static lto_location_cache *current_cache;
299 private:
300 static int cmp_loc (const void *pa, const void *pb);
302 struct cached_location
304 const char *file;
305 location_t *loc;
306 int line, col;
307 bool sysp;
310 /* The location cache. */
312 auto_vec<cached_location> loc_cache;
314 /* Accepted entries are ones used by trees that are known to be not unified
315 by tree merging. */
317 int accepted_length;
319 /* Bookkeeping to remember state in between calls to lto_apply_location_cache
320 When streaming gimple, the location cache is not used and thus
321 lto_apply_location_cache happens per location basis. It is then
322 useful to avoid redundant calls of linemap API. */
324 const char *current_file;
325 int current_line;
326 int current_col;
327 bool current_sysp;
328 location_t current_loc;
331 /* Structure used as buffer for reading an LTO file. */
332 class lto_input_block
334 public:
335 /* Special constructor for the string table, it abuses this to
336 do random access but use the uhwi decoder. */
337 lto_input_block (const char *data_, unsigned int p_, unsigned int len_,
338 const unsigned char *mode_table_)
339 : data (data_), mode_table (mode_table_), p (p_), len (len_) {}
340 lto_input_block (const char *data_, unsigned int len_,
341 const unsigned char *mode_table_)
342 : data (data_), mode_table (mode_table_), p (0), len (len_) {}
344 const char *data;
345 const unsigned char *mode_table;
346 unsigned int p;
347 unsigned int len;
350 /* Compression algorithm used for compression of LTO bytecode. */
352 enum lto_compression
354 ZLIB,
355 ZSTD
358 /* Structure that represents LTO ELF section with information
359 about the format. */
361 struct lto_section
363 int16_t major_version;
364 int16_t minor_version;
365 unsigned char slim_object;
367 /* Flags is a private field that is not defined publicly. */
368 uint16_t flags;
370 /* Set compression to FLAGS. */
371 inline void set_compression (lto_compression c)
373 flags = c;
376 /* Get compression from FLAGS. */
377 inline lto_compression get_compression ()
379 return (lto_compression) flags;
383 STATIC_ASSERT (sizeof (lto_section) == 8);
385 /* The is the first part of the record in an LTO file for many of the
386 IPA passes. */
387 struct lto_simple_header
389 /* Size of main gimple body of function. */
390 int32_t main_size;
393 struct lto_simple_header_with_strings : lto_simple_header
395 /* Size of the string table. */
396 int32_t string_size;
399 /* The header for a function body. */
400 struct lto_function_header : lto_simple_header_with_strings
402 /* Size of the cfg. */
403 int32_t cfg_size;
407 /* Structure describing a symbol section. */
408 struct lto_decl_header : lto_simple_header_with_strings
410 /* Size of region for decl state. */
411 int32_t decl_state_size;
413 /* Number of nodes in globals stream. */
414 int32_t num_nodes;
418 /* Statistics gathered during LTO, WPA and LTRANS. */
419 struct lto_stats_d
421 unsigned HOST_WIDE_INT num_input_cgraph_nodes;
422 unsigned HOST_WIDE_INT num_output_symtab_nodes;
423 unsigned HOST_WIDE_INT num_input_files;
424 unsigned HOST_WIDE_INT num_output_files;
425 unsigned HOST_WIDE_INT num_cgraph_partitions;
426 unsigned HOST_WIDE_INT section_size[LTO_N_SECTION_TYPES];
427 unsigned HOST_WIDE_INT num_function_bodies;
428 unsigned HOST_WIDE_INT num_trees[NUM_TREE_CODES];
429 unsigned HOST_WIDE_INT num_output_il_bytes;
430 unsigned HOST_WIDE_INT num_compressed_il_bytes;
431 unsigned HOST_WIDE_INT num_input_il_bytes;
432 unsigned HOST_WIDE_INT num_uncompressed_il_bytes;
433 unsigned HOST_WIDE_INT num_tree_bodies_output;
434 unsigned HOST_WIDE_INT num_pickle_refs_output;
437 /* Entry of LTO symtab encoder. */
438 struct lto_encoder_entry
440 symtab_node *node;
441 /* Is the node in this partition (i.e. ltrans of this partition will
442 be responsible for outputting it)? */
443 unsigned int in_partition:1;
444 /* Do we encode body in this partition? */
445 unsigned int body:1;
446 /* Do we encode initializer in this partition?
447 For example the readonly variable initializers are encoded to aid
448 constant folding even if they are not in the partition. */
449 unsigned int initializer:1;
453 /* Encoder data structure used to stream callgraph nodes. */
454 struct lto_symtab_encoder_d
456 vec<lto_encoder_entry> nodes;
457 hash_map<symtab_node *, size_t> *map;
460 typedef struct lto_symtab_encoder_d *lto_symtab_encoder_t;
462 /* Iterator structure for cgraph node sets. */
463 struct lto_symtab_encoder_iterator
465 lto_symtab_encoder_t encoder;
466 unsigned index;
471 /* The lto_tree_ref_encoder struct is used to encode trees into indices. */
473 struct lto_tree_ref_encoder
475 hash_map<tree, unsigned> *tree_hash_table; /* Maps pointers to indices. */
476 vec<tree> trees; /* Maps indices to pointers. */
480 /* Structure to hold states of input scope. */
481 struct GTY((for_user)) lto_in_decl_state
483 /* Array of lto_in_decl_buffers to store type and decls streams. */
484 vec<tree, va_gc> *streams[LTO_N_DECL_STREAMS];
486 /* If this in-decl state is associated with a function. FN_DECL
487 point to the FUNCTION_DECL. */
488 tree fn_decl;
490 /* True if decl state is compressed. */
491 bool compressed;
494 typedef struct lto_in_decl_state *lto_in_decl_state_ptr;
496 struct decl_state_hasher : ggc_ptr_hash<lto_in_decl_state>
498 static hashval_t
499 hash (lto_in_decl_state *s)
501 return htab_hash_pointer (s->fn_decl);
504 static bool
505 equal (lto_in_decl_state *a, lto_in_decl_state *b)
507 return a->fn_decl == b->fn_decl;
511 /* The structure that holds all of the vectors of global types,
512 decls and cgraph nodes used in the serialization of this file. */
513 struct lto_out_decl_state
515 /* The buffers contain the sets of decls of various kinds and types we have
516 seen so far and the indexes assigned to them. */
517 struct lto_tree_ref_encoder streams[LTO_N_DECL_STREAMS];
519 /* Encoder for cgraph nodes. */
520 lto_symtab_encoder_t symtab_node_encoder;
522 /* If this out-decl state belongs to a function, fn_decl points to that
523 function. Otherwise, it is NULL. */
524 tree fn_decl;
526 /* True if decl state is compressed. */
527 bool compressed;
530 typedef struct lto_out_decl_state *lto_out_decl_state_ptr;
533 /* Compact representation of a index <-> resolution pair. Unpacked to an
534 vector later. */
535 struct res_pair
537 ld_plugin_symbol_resolution_t res;
538 unsigned index;
542 /* One of these is allocated for each object file that being compiled
543 by lto. This structure contains the tables that are needed by the
544 serialized functions and ipa passes to connect themselves to the
545 global types and decls as they are reconstituted. */
546 struct GTY(()) lto_file_decl_data
548 /* Decl state currently used. */
549 struct lto_in_decl_state *current_decl_state;
551 /* Decl state corresponding to regions outside of any functions
552 in the compilation unit. */
553 struct lto_in_decl_state *global_decl_state;
555 /* Table of cgraph nodes present in this file. */
556 lto_symtab_encoder_t GTY((skip)) symtab_node_encoder;
558 /* Hash table maps lto-related section names to location in file. */
559 hash_table<decl_state_hasher> *function_decl_states;
561 /* The .o file that these offsets relate to. */
562 const char *GTY((skip)) file_name;
564 /* Hash table maps lto-related section names to location in file. */
565 htab_t GTY((skip)) section_hash_table;
567 /* Hash new name of renamed global declaration to its original name. */
568 htab_t GTY((skip)) renaming_hash_table;
570 /* Linked list used temporarily in reader */
571 struct lto_file_decl_data *next;
573 /* Order in which the file appears on the command line. */
574 int order;
576 /* Sub ID for merged objects. */
577 unsigned HOST_WIDE_INT id;
579 /* Symbol resolutions for this file */
580 vec<res_pair> GTY((skip)) respairs;
581 unsigned max_index;
583 gcov_summary GTY((skip)) profile_info;
585 /* Map assigning declarations their resolutions. */
586 hash_map<tree, ld_plugin_symbol_resolution> * GTY((skip)) resolution_map;
588 /* Mode translation table. */
589 const unsigned char *mode_table;
591 /* Read LTO section. */
592 lto_section lto_section_header;
594 int order_base;
596 int unit_base;
599 typedef struct lto_file_decl_data *lto_file_decl_data_ptr;
601 struct lto_char_ptr_base
603 char *ptr;
606 /* An incore byte stream to buffer the various parts of the function.
607 The entire structure should be zeroed when created. The record
608 consists of a set of blocks. The first sizeof (ptr) bytes are used
609 as a chain, and the rest store the bytes to be written. */
610 struct lto_output_stream
612 /* The pointer to the first block in the stream. */
613 struct lto_char_ptr_base * first_block;
615 /* The pointer to the last and current block in the stream. */
616 struct lto_char_ptr_base * current_block;
618 /* The pointer to where the next char should be written. */
619 char * current_pointer;
621 /* The number of characters left in the current block. */
622 unsigned int left_in_block;
624 /* The block size of the last block allocated. */
625 unsigned int block_size;
627 /* The total number of characters written. */
628 unsigned int total_size;
631 /* A simple output block. This can be used for simple IPA passes that
632 do not need more than one stream. */
633 struct lto_simple_output_block
635 enum lto_section_type section_type;
636 struct lto_out_decl_state *decl_state;
638 /* The stream that the main tree codes are written to. */
639 struct lto_output_stream *main_stream;
642 /* String hashing. */
644 struct string_slot
646 const char *s;
647 int len;
648 unsigned int slot_num;
651 /* Hashtable helpers. */
653 struct string_slot_hasher : nofree_ptr_hash <string_slot>
655 static inline hashval_t hash (const string_slot *);
656 static inline bool equal (const string_slot *, const string_slot *);
659 /* Returns a hash code for DS. Adapted from libiberty's htab_hash_string
660 to support strings that may not end in '\0'. */
662 inline hashval_t
663 string_slot_hasher::hash (const string_slot *ds)
665 hashval_t r = ds->len;
666 int i;
668 for (i = 0; i < ds->len; i++)
669 r = r * 67 + (unsigned)ds->s[i] - 113;
670 return r;
673 /* Returns nonzero if DS1 and DS2 are equal. */
675 inline bool
676 string_slot_hasher::equal (const string_slot *ds1, const string_slot *ds2)
678 if (ds1->len == ds2->len)
679 return memcmp (ds1->s, ds2->s, ds1->len) == 0;
681 return 0;
684 /* Data structure holding all the data and descriptors used when writing
685 an LTO file. */
686 struct output_block
688 enum lto_section_type section_type;
689 struct lto_out_decl_state *decl_state;
691 /* The stream that the main tree codes are written to. */
692 struct lto_output_stream *main_stream;
694 /* The stream that contains the string table. */
695 struct lto_output_stream *string_stream;
697 /* The stream that contains the cfg. */
698 struct lto_output_stream *cfg_stream;
700 /* The hash table that contains the set of strings we have seen so
701 far and the indexes assigned to them. */
702 hash_table<string_slot_hasher> *string_hash_table;
704 /* The current symbol that we are currently serializing. Null
705 if we are serializing something else. */
706 symtab_node *symbol;
708 /* These are the last file and line that were seen in the stream.
709 If the current node differs from these, it needs to insert
710 something into the stream and fix these up. */
711 const char *current_file;
712 int current_line;
713 int current_col;
714 bool current_sysp;
716 /* Cache of nodes written in this section. */
717 struct streamer_tree_cache_d *writer_cache;
719 /* All trees identified as local to the unit streamed. */
720 hash_set<tree> *local_trees;
722 /* All data persistent across whole duration of output block
723 can go here. */
724 struct obstack obstack;
728 /* Data and descriptors used when reading from an LTO file. */
729 class data_in
731 public:
732 /* The global decls and types. */
733 struct lto_file_decl_data *file_data;
735 /* The string table. */
736 const char *strings;
738 /* The length of the string table. */
739 unsigned int strings_len;
741 /* Maps each reference number to the resolution done by the linker. */
742 vec<ld_plugin_symbol_resolution_t> globals_resolution;
744 /* Cache of pickled nodes. */
745 struct streamer_tree_cache_d *reader_cache;
747 /* Cache of source code location. */
748 lto_location_cache location_cache;
752 /* In lto-section-in.c */
753 extern class lto_input_block * lto_create_simple_input_block (
754 struct lto_file_decl_data *,
755 enum lto_section_type, const char **, size_t *);
756 extern void
757 lto_destroy_simple_input_block (struct lto_file_decl_data *,
758 enum lto_section_type,
759 class lto_input_block *, const char *, size_t);
760 extern void lto_set_in_hooks (struct lto_file_decl_data **,
761 lto_get_section_data_f *,
762 lto_free_section_data_f *);
763 extern struct lto_file_decl_data **lto_get_file_decl_data (void);
764 extern const char *lto_get_section_data (struct lto_file_decl_data *,
765 enum lto_section_type,
766 const char *, int, size_t *,
767 bool decompress = false);
768 extern const char *lto_get_summary_section_data (struct lto_file_decl_data *,
769 enum lto_section_type,
770 size_t *);
771 extern const char *lto_get_raw_section_data (struct lto_file_decl_data *,
772 enum lto_section_type,
773 const char *, int, size_t *);
774 extern void lto_free_section_data (struct lto_file_decl_data *,
775 enum lto_section_type,
776 const char *, const char *, size_t,
777 bool decompress = false);
778 extern void lto_free_raw_section_data (struct lto_file_decl_data *,
779 enum lto_section_type,
780 const char *, const char *, size_t);
781 extern htab_t lto_create_renaming_table (void);
782 extern void lto_record_renamed_decl (struct lto_file_decl_data *,
783 const char *, const char *);
784 extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data *,
785 const char *);
786 extern struct lto_in_decl_state *lto_new_in_decl_state (void);
787 extern void lto_delete_in_decl_state (struct lto_in_decl_state *);
788 extern struct lto_in_decl_state *lto_get_function_in_decl_state (
789 struct lto_file_decl_data *, tree);
790 extern void lto_free_function_in_decl_state (struct lto_in_decl_state *);
791 extern void lto_free_function_in_decl_state_for_node (symtab_node *);
792 extern void lto_section_overrun (class lto_input_block *) ATTRIBUTE_NORETURN;
793 extern void lto_value_range_error (const char *,
794 HOST_WIDE_INT, HOST_WIDE_INT,
795 HOST_WIDE_INT) ATTRIBUTE_NORETURN;
797 /* In lto-section-out.c */
798 extern void lto_begin_section (const char *, bool);
799 extern void lto_end_section (void);
800 extern void lto_write_data (const void *, unsigned int);
801 extern void lto_write_raw_data (const void *, unsigned int);
802 extern void lto_write_stream (struct lto_output_stream *);
803 extern struct lto_simple_output_block *lto_create_simple_output_block (
804 enum lto_section_type);
805 extern void lto_destroy_simple_output_block (struct lto_simple_output_block *);
806 extern struct lto_out_decl_state *lto_new_out_decl_state (void);
807 extern void lto_delete_out_decl_state (struct lto_out_decl_state *);
808 extern struct lto_out_decl_state *lto_get_out_decl_state (void);
809 extern void lto_push_out_decl_state (struct lto_out_decl_state *);
810 extern struct lto_out_decl_state *lto_pop_out_decl_state (void);
811 extern void lto_record_function_out_decl_state (tree,
812 struct lto_out_decl_state *);
813 extern void lto_append_block (struct lto_output_stream *);
816 /* In lto-streamer.c. */
818 /* Set when streaming LTO for offloading compiler. */
819 extern bool lto_stream_offload_p;
821 extern const char *lto_tag_name (enum LTO_tags);
822 extern char *lto_get_section_name (int, const char *, int,
823 struct lto_file_decl_data *);
824 extern void print_lto_report (const char *);
825 extern void lto_streamer_init (void);
826 extern bool gate_lto_out (void);
827 extern void lto_check_version (int, int, const char *);
828 extern void lto_streamer_hooks_init (void);
830 /* In lto-streamer-in.c */
831 extern void lto_input_cgraph (struct lto_file_decl_data *, const char *);
832 extern void lto_reader_init (void);
833 extern void lto_free_file_name_hash (void);
834 extern void lto_input_function_body (struct lto_file_decl_data *,
835 struct cgraph_node *,
836 const char *);
837 extern void lto_input_variable_constructor (struct lto_file_decl_data *,
838 struct varpool_node *,
839 const char *);
840 extern void lto_input_constructors_and_inits (struct lto_file_decl_data *,
841 const char *);
842 extern void lto_input_toplevel_asms (struct lto_file_decl_data *, int);
843 extern void lto_input_mode_table (struct lto_file_decl_data *);
844 extern class data_in *lto_data_in_create (struct lto_file_decl_data *,
845 const char *, unsigned,
846 vec<ld_plugin_symbol_resolution_t> );
847 extern void lto_data_in_delete (class data_in *);
848 extern void lto_input_data_block (class lto_input_block *, void *, size_t);
849 void lto_input_location (location_t *, struct bitpack_d *, class data_in *);
850 location_t stream_input_location_now (struct bitpack_d *bp,
851 class data_in *data);
852 tree lto_input_tree_ref (class lto_input_block *, class data_in *,
853 struct function *, enum LTO_tags);
854 void lto_tag_check_set (enum LTO_tags, int, ...);
855 void lto_init_eh (void);
856 hashval_t lto_input_scc (class lto_input_block *, class data_in *,
857 unsigned *, unsigned *, bool);
858 tree lto_input_tree_1 (class lto_input_block *, class data_in *,
859 enum LTO_tags, hashval_t hash);
860 tree lto_input_tree (class lto_input_block *, class data_in *);
861 tree stream_read_tree_ref (class lto_input_block *, class data_in *);
864 /* In lto-streamer-out.c */
865 extern void lto_register_decl_definition (tree, struct lto_file_decl_data *);
866 extern struct output_block *create_output_block (enum lto_section_type);
867 extern void destroy_output_block (struct output_block *);
868 extern void lto_output_tree (struct output_block *, tree, bool, bool);
869 extern void stream_write_tree_ref (struct output_block *, tree);
870 extern void lto_output_var_decl_ref (struct lto_out_decl_state *,
871 struct lto_output_stream *, tree);
872 extern void lto_output_fn_decl_ref (struct lto_out_decl_state *,
873 struct lto_output_stream *, tree);
874 extern tree lto_input_var_decl_ref (lto_input_block *, lto_file_decl_data *);
875 extern tree lto_input_fn_decl_ref (lto_input_block *, lto_file_decl_data *);
876 extern void lto_output_toplevel_asms (void);
877 extern void produce_asm (struct output_block *ob, tree fn);
878 extern void lto_output ();
879 extern void produce_asm_for_decls ();
880 void lto_output_decl_state_streams (struct output_block *,
881 struct lto_out_decl_state *);
882 void lto_output_decl_state_refs (struct output_block *,
883 struct lto_output_stream *,
884 struct lto_out_decl_state *);
885 void lto_output_location (struct output_block *, struct bitpack_d *, location_t);
886 void lto_output_init_mode_table (void);
887 void lto_prepare_function_for_streaming (cgraph_node *);
890 /* In lto-cgraph.c */
891 extern bool asm_nodes_output;
892 lto_symtab_encoder_t lto_symtab_encoder_new (bool);
893 int lto_symtab_encoder_encode (lto_symtab_encoder_t, symtab_node *);
894 void lto_symtab_encoder_delete (lto_symtab_encoder_t);
895 bool lto_symtab_encoder_delete_node (lto_symtab_encoder_t, symtab_node *);
896 bool lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t,
897 struct cgraph_node *);
898 bool lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t,
899 symtab_node *);
900 void lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t,
901 symtab_node *);
903 bool lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t,
904 varpool_node *);
905 void output_symtab (void);
906 void input_symtab (void);
907 void output_offload_tables (void);
908 void input_offload_tables (bool);
909 bool referenced_from_other_partition_p (struct ipa_ref_list *,
910 lto_symtab_encoder_t);
911 bool reachable_from_other_partition_p (struct cgraph_node *,
912 lto_symtab_encoder_t);
913 bool referenced_from_this_partition_p (symtab_node *,
914 lto_symtab_encoder_t);
915 bool reachable_from_this_partition_p (struct cgraph_node *,
916 lto_symtab_encoder_t);
917 lto_symtab_encoder_t compute_ltrans_boundary (lto_symtab_encoder_t encoder);
918 void select_what_to_stream (void);
920 /* In options-save.c. */
921 void cl_target_option_stream_out (struct output_block *, struct bitpack_d *,
922 struct cl_target_option *);
924 void cl_target_option_stream_in (class data_in *,
925 struct bitpack_d *,
926 struct cl_target_option *);
928 void cl_optimization_stream_out (struct output_block *,
929 struct bitpack_d *, struct cl_optimization *);
931 void cl_optimization_stream_in (class data_in *,
932 struct bitpack_d *, struct cl_optimization *);
936 /* In lto-opts.c. */
937 extern void lto_write_options (void);
940 /* Statistics gathered during LTO, WPA and LTRANS. */
941 extern struct lto_stats_d lto_stats;
943 /* Section names corresponding to the values of enum lto_section_type. */
944 extern const char *lto_section_name[];
946 /* Holds all the out decl states of functions output so far in the
947 current output file. */
948 extern vec<lto_out_decl_state_ptr> lto_function_decl_states;
950 /* Return true if LTO tag TAG corresponds to a tree code. */
951 static inline bool
952 lto_tag_is_tree_code_p (enum LTO_tags tag)
954 return tag > LTO_first_tree_tag && (unsigned) tag <= MAX_TREE_CODES;
958 /* Return true if LTO tag TAG corresponds to a gimple code. */
959 static inline bool
960 lto_tag_is_gimple_code_p (enum LTO_tags tag)
962 return (unsigned) tag >= LTO_first_gimple_tag
963 && (unsigned) tag
964 < LTO_first_gimple_tag + LAST_AND_UNUSED_GIMPLE_CODE;
968 /* Return the LTO tag corresponding to gimple code CODE. See enum
969 LTO_tags for details on the conversion. */
970 static inline enum LTO_tags
971 lto_gimple_code_to_tag (enum gimple_code code)
973 return (enum LTO_tags) ((unsigned) code + LTO_first_gimple_tag);
977 /* Return the GIMPLE code corresponding to TAG. See enum LTO_tags for
978 details on the conversion. */
979 static inline enum gimple_code
980 lto_tag_to_gimple_code (enum LTO_tags tag)
982 gcc_assert (lto_tag_is_gimple_code_p (tag));
983 return (enum gimple_code) ((unsigned) tag - LTO_first_gimple_tag);
987 /* Return the LTO tag corresponding to tree code CODE. See enum
988 LTO_tags for details on the conversion. */
989 static inline enum LTO_tags
990 lto_tree_code_to_tag (enum tree_code code)
992 return (enum LTO_tags) ((unsigned) code + LTO_first_tree_tag);
996 /* Return the tree code corresponding to TAG. See enum LTO_tags for
997 details on the conversion. */
998 static inline enum tree_code
999 lto_tag_to_tree_code (enum LTO_tags tag)
1001 gcc_assert (lto_tag_is_tree_code_p (tag));
1002 return (enum tree_code) ((unsigned) tag - LTO_first_tree_tag);
1005 /* Check that tag ACTUAL == EXPECTED. */
1006 static inline void
1007 lto_tag_check (enum LTO_tags actual, enum LTO_tags expected)
1009 if (actual != expected)
1010 internal_error ("bytecode stream: expected tag %s instead of %s",
1011 lto_tag_name (expected), lto_tag_name (actual));
1014 /* Check that tag ACTUAL is in the range [TAG1, TAG2]. */
1015 static inline void
1016 lto_tag_check_range (enum LTO_tags actual, enum LTO_tags tag1,
1017 enum LTO_tags tag2)
1019 if (actual < tag1 || actual > tag2)
1020 internal_error ("bytecode stream: tag %s is not in the expected range "
1021 "[%s, %s]",
1022 lto_tag_name (actual),
1023 lto_tag_name (tag1),
1024 lto_tag_name (tag2));
1027 /* Initialize an lto_out_decl_buffer ENCODER. */
1028 static inline void
1029 lto_init_tree_ref_encoder (struct lto_tree_ref_encoder *encoder)
1031 encoder->tree_hash_table = new hash_map<tree, unsigned> (251);
1032 encoder->trees.create (0);
1036 /* Destroy an lto_tree_ref_encoder ENCODER by freeing its contents. The
1037 memory used by ENCODER is not freed by this function. */
1038 static inline void
1039 lto_destroy_tree_ref_encoder (struct lto_tree_ref_encoder *encoder)
1041 /* Hash table may be delete already. */
1042 delete encoder->tree_hash_table;
1043 encoder->tree_hash_table = NULL;
1044 encoder->trees.release ();
1047 /* Return the number of trees encoded in ENCODER. */
1048 static inline unsigned int
1049 lto_tree_ref_encoder_size (struct lto_tree_ref_encoder *encoder)
1051 return encoder->trees.length ();
1054 /* Return the IDX-th tree in ENCODER. */
1055 static inline tree
1056 lto_tree_ref_encoder_get_tree (struct lto_tree_ref_encoder *encoder,
1057 unsigned int idx)
1059 return encoder->trees[idx];
1062 /* Return number of encoded nodes in ENCODER. */
1063 static inline int
1064 lto_symtab_encoder_size (lto_symtab_encoder_t encoder)
1066 return encoder->nodes.length ();
1069 /* Value used to represent failure of lto_symtab_encoder_lookup. */
1070 #define LCC_NOT_FOUND (-1)
1072 /* Look up NODE in encoder. Return NODE's reference if it has been encoded
1073 or LCC_NOT_FOUND if it is not there. */
1075 static inline int
1076 lto_symtab_encoder_lookup (lto_symtab_encoder_t encoder,
1077 symtab_node *node)
1079 size_t *slot = encoder->map->get (node);
1080 return (slot && *slot ? *(slot) - 1 : LCC_NOT_FOUND);
1083 /* Return true if iterator LSE points to nothing. */
1084 static inline bool
1085 lsei_end_p (lto_symtab_encoder_iterator lsei)
1087 return lsei.index >= (unsigned)lto_symtab_encoder_size (lsei.encoder);
1090 /* Advance iterator LSE. */
1091 static inline void
1092 lsei_next (lto_symtab_encoder_iterator *lsei)
1094 lsei->index++;
1097 /* Return the node pointed to by LSI. */
1098 static inline symtab_node *
1099 lsei_node (lto_symtab_encoder_iterator lsei)
1101 return lsei.encoder->nodes[lsei.index].node;
1104 /* Return the node pointed to by LSI. */
1105 static inline struct cgraph_node *
1106 lsei_cgraph_node (lto_symtab_encoder_iterator lsei)
1108 return dyn_cast<cgraph_node *> (lsei.encoder->nodes[lsei.index].node);
1111 /* Return the node pointed to by LSI. */
1112 static inline varpool_node *
1113 lsei_varpool_node (lto_symtab_encoder_iterator lsei)
1115 return dyn_cast<varpool_node *> (lsei.encoder->nodes[lsei.index].node);
1118 /* Return the cgraph node corresponding to REF using ENCODER. */
1120 static inline symtab_node *
1121 lto_symtab_encoder_deref (lto_symtab_encoder_t encoder, int ref)
1123 if (ref == LCC_NOT_FOUND)
1124 return NULL;
1126 return encoder->nodes[ref].node;
1129 /* Return an iterator to the first node in LSI. */
1130 static inline lto_symtab_encoder_iterator
1131 lsei_start (lto_symtab_encoder_t encoder)
1133 lto_symtab_encoder_iterator lsei;
1135 lsei.encoder = encoder;
1136 lsei.index = 0;
1137 return lsei;
1140 /* Advance iterator LSE. */
1141 static inline void
1142 lsei_next_in_partition (lto_symtab_encoder_iterator *lsei)
1144 lsei_next (lsei);
1145 while (!lsei_end_p (*lsei)
1146 && !lto_symtab_encoder_in_partition_p (lsei->encoder, lsei_node (*lsei)))
1147 lsei_next (lsei);
1150 /* Return an iterator to the first node in LSI. */
1151 static inline lto_symtab_encoder_iterator
1152 lsei_start_in_partition (lto_symtab_encoder_t encoder)
1154 lto_symtab_encoder_iterator lsei = lsei_start (encoder);
1156 if (lsei_end_p (lsei))
1157 return lsei;
1158 if (!lto_symtab_encoder_in_partition_p (encoder, lsei_node (lsei)))
1159 lsei_next_in_partition (&lsei);
1161 return lsei;
1164 /* Advance iterator LSE. */
1165 static inline void
1166 lsei_next_function_in_partition (lto_symtab_encoder_iterator *lsei)
1168 lsei_next (lsei);
1169 while (!lsei_end_p (*lsei)
1170 && (!is_a <cgraph_node *> (lsei_node (*lsei))
1171 || !lto_symtab_encoder_in_partition_p (lsei->encoder, lsei_node (*lsei))))
1172 lsei_next (lsei);
1175 /* Return an iterator to the first node in LSI. */
1176 static inline lto_symtab_encoder_iterator
1177 lsei_start_function_in_partition (lto_symtab_encoder_t encoder)
1179 lto_symtab_encoder_iterator lsei = lsei_start (encoder);
1181 if (lsei_end_p (lsei))
1182 return lsei;
1183 if (!is_a <cgraph_node *> (lsei_node (lsei))
1184 || !lto_symtab_encoder_in_partition_p (encoder, lsei_node (lsei)))
1185 lsei_next_function_in_partition (&lsei);
1187 return lsei;
1190 /* Advance iterator LSE. */
1191 static inline void
1192 lsei_next_variable_in_partition (lto_symtab_encoder_iterator *lsei)
1194 lsei_next (lsei);
1195 while (!lsei_end_p (*lsei)
1196 && (!is_a <varpool_node *> (lsei_node (*lsei))
1197 || !lto_symtab_encoder_in_partition_p (lsei->encoder, lsei_node (*lsei))))
1198 lsei_next (lsei);
1201 /* Return an iterator to the first node in LSI. */
1202 static inline lto_symtab_encoder_iterator
1203 lsei_start_variable_in_partition (lto_symtab_encoder_t encoder)
1205 lto_symtab_encoder_iterator lsei = lsei_start (encoder);
1207 if (lsei_end_p (lsei))
1208 return lsei;
1209 if (!is_a <varpool_node *> (lsei_node (lsei))
1210 || !lto_symtab_encoder_in_partition_p (encoder, lsei_node (lsei)))
1211 lsei_next_variable_in_partition (&lsei);
1213 return lsei;
1216 /* Entry for the delayed registering of decl -> DIE references. */
1217 struct dref_entry {
1218 tree decl;
1219 const char *sym;
1220 unsigned HOST_WIDE_INT off;
1223 extern vec<dref_entry> dref_queue;
1225 extern FILE *streamer_dump_file;
1227 #endif /* GCC_LTO_STREAMER_H */