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
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
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"
28 #include "diagnostic.h"
30 /* The encoding for a function consists of the following sections:
38 7) Names for the labels that have names
40 9) The control flow graph.
41 10-11)Gimple for local decls.
42 12) Gimple for the function.
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
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.
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.
73 At the top level of (8) is the function. It consists of five
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
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.
91 There are two forms of basic blocks depending on if they are
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
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
114 zero - This is only present for LTO_BB1 and is used
115 to terminate the statements and exception
116 regions within this block.
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
;
129 /* Tags representing the various IL objects written to the bytecode file
130 (GIMPLE statements, basic blocks, EH regions, tree nodes, etc).
132 NOTE, when adding new LTO tags, also update lto_tag_name. */
137 /* Special for streamer. Reference to previously-streamed node. */
138 LTO_tree_pickle_reference
,
140 /* Reserve enough entries to fit all the tree and gimple codes handled
141 by the streamer. This guarantees that:
143 1- Given a tree code C:
144 enum LTO_tags tag == C + 1
146 2- Given a gimple code C:
147 enum LTO_tags tag == C + NUM_TREE_CODES + 1
149 Conversely, to map between LTO tags and tree/gimple codes, the
150 reverse operation must be applied. */
151 LTO_bb0
= 1 + MAX_TREE_CODES
+ LAST_AND_UNUSED_GIMPLE_CODE
,
154 /* EH region holding the previous statement. */
157 /* Shared INTEGER_CST node. */
166 /* EH region types. These mirror enum eh_region_type. */
169 LTO_ert_allowed_exceptions
,
170 LTO_ert_must_not_throw
,
172 /* EH landing pad. */
175 /* EH try/catch node. */
178 /* Special for global streamer. A blob of unnamed tree nodes. */
181 /* References to indexable tree nodes. These objects are stored in
182 tables that are written separately from the function bodies that
183 reference them. This way they can be instantiated even when the
184 referencing functions aren't (e.g., during WPA) and it also allows
185 functions to be copied from one file to another without having
186 to unpickle the body first (the references are location
189 NOTE, do not regroup these values as the grouping is exposed
190 in the range checks done in lto_input_tree. */
191 LTO_field_decl_ref
, /* Do not change. */
192 LTO_function_decl_ref
,
194 LTO_namespace_decl_ref
,
200 LTO_imported_decl_ref
,
201 LTO_translation_unit_decl_ref
,
203 LTO_namelist_decl_ref
, /* Do not change. */
205 /* This tag must always be last. */
210 /* Set of section types that are in an LTO file. This list will grow
211 as the number of IPA passes grows since each IPA pass will need its
212 own section type to store its summary information.
214 When adding a new section type, you must also extend the
215 LTO_SECTION_NAME array in lto-section-in.c. */
216 enum lto_section_type
218 LTO_section_decls
= 0,
219 LTO_section_function_body
,
220 LTO_section_static_initializer
,
224 LTO_section_jump_functions
,
225 LTO_section_ipa_pure_const
,
226 LTO_section_ipa_reference
,
227 LTO_section_ipa_profile
,
228 LTO_section_symtab_nodes
,
230 LTO_section_cgraph_opt_sum
,
231 LTO_section_ipa_fn_summary
,
232 LTO_section_ipcp_transform
,
234 LTO_section_offload_table
,
235 LTO_section_mode_table
,
239 LTO_N_SECTION_TYPES
/* Must be last. */
242 /* Indices to the various function, type and symbol streams. */
243 enum lto_decl_stream_e_t
245 LTO_DECL_STREAM_TYPE
= 0, /* Must be first. */
246 LTO_DECL_STREAM_FIELD_DECL
,
247 LTO_DECL_STREAM_FN_DECL
,
248 LTO_DECL_STREAM_VAR_DECL
,
249 LTO_DECL_STREAM_TYPE_DECL
,
250 LTO_DECL_STREAM_NAMESPACE_DECL
,
251 LTO_DECL_STREAM_LABEL_DECL
,
255 typedef enum ld_plugin_symbol_resolution ld_plugin_symbol_resolution_t
;
258 /* Macro to define convenience functions for type and decl streams
259 in lto_file_decl_data. */
260 #define DEFINE_DECL_STREAM_FUNCS(UPPER_NAME, name) \
262 lto_file_decl_data_get_ ## name (struct lto_file_decl_data *data, \
265 struct lto_in_decl_state *state = data->current_decl_state; \
266 return (*state->streams[LTO_DECL_STREAM_## UPPER_NAME])[idx]; \
269 static inline unsigned int \
270 lto_file_decl_data_num_ ## name ## s (struct lto_file_decl_data *data) \
272 struct lto_in_decl_state *state = data->current_decl_state; \
273 return vec_safe_length (state->streams[LTO_DECL_STREAM_## UPPER_NAME]); \
277 /* Return a char pointer to the start of a data stream for an lto pass
278 or function. The first parameter is the file data that contains
279 the information. The second parameter is the type of information
280 to be obtained. The third parameter is the name of the function
281 and is only used when finding a function body; otherwise it is
282 NULL. The fourth parameter is the length of the data returned. */
283 typedef const char* (lto_get_section_data_f
) (struct lto_file_decl_data
*,
284 enum lto_section_type
,
289 /* Return the data found from the above call. The first three
290 parameters are the same as above. The fourth parameter is the data
291 itself and the fifth is the length of the data. */
292 typedef void (lto_free_section_data_f
) (struct lto_file_decl_data
*,
293 enum lto_section_type
,
298 /* The location cache holds expanded locations for streamed in trees.
299 This is done to reduce memory usage of libcpp linemap that strongly prefers
300 locations to be inserted in the soruce order. */
302 class lto_location_cache
305 /* Apply all changes in location cache. Add locations into linemap and patch
307 bool apply_location_cache ();
308 /* Tree merging did not suceed; mark all changes in the cache as accepted. */
309 void accept_location_cache ();
310 /* Tree merging did suceed; throw away recent changes. */
311 void revert_location_cache ();
312 void input_location (location_t
*loc
, struct bitpack_d
*bp
,
313 class data_in
*data_in
);
314 lto_location_cache ()
315 : loc_cache (), accepted_length (0), current_file (NULL
), current_line (0),
316 current_col (0), current_sysp (false), current_loc (UNKNOWN_LOCATION
)
318 gcc_assert (!current_cache
);
319 current_cache
= this;
321 ~lto_location_cache ()
323 apply_location_cache ();
324 gcc_assert (current_cache
== this);
325 current_cache
= NULL
;
328 /* There can be at most one instance of location cache (combining multiple
329 would bring it out of sync with libcpp linemap); point to current
331 static lto_location_cache
*current_cache
;
334 static int cmp_loc (const void *pa
, const void *pb
);
336 struct cached_location
344 /* The location cache. */
346 auto_vec
<cached_location
> loc_cache
;
348 /* Accepted entries are ones used by trees that are known to be not unified
353 /* Bookkeeping to remember state in between calls to lto_apply_location_cache
354 When streaming gimple, the location cache is not used and thus
355 lto_apply_location_cache happens per location basis. It is then
356 useful to avoid redundant calls of linemap API. */
358 const char *current_file
;
362 location_t current_loc
;
365 /* Structure used as buffer for reading an LTO file. */
366 class lto_input_block
369 /* Special constructor for the string table, it abuses this to
370 do random access but use the uhwi decoder. */
371 lto_input_block (const char *data_
, unsigned int p_
, unsigned int len_
,
372 const unsigned char *mode_table_
)
373 : data (data_
), mode_table (mode_table_
), p (p_
), len (len_
) {}
374 lto_input_block (const char *data_
, unsigned int len_
,
375 const unsigned char *mode_table_
)
376 : data (data_
), mode_table (mode_table_
), p (0), len (len_
) {}
379 const unsigned char *mode_table
;
384 /* Compression algorithm used for compression of LTO bytecode. */
392 /* Structure that represents LTO ELF section with information
397 int16_t major_version
;
398 int16_t minor_version
;
399 unsigned char slim_object
;
401 /* Flags is a private field that is not defined publicly. */
404 /* Set compression to FLAGS. */
405 inline void set_compression (lto_compression c
)
410 /* Get compression from FLAGS. */
411 inline lto_compression
get_compression ()
413 return (lto_compression
) flags
;
417 STATIC_ASSERT (sizeof (lto_section
) == 8);
419 /* The is the first part of the record in an LTO file for many of the
421 struct lto_simple_header
423 /* Size of main gimple body of function. */
427 struct lto_simple_header_with_strings
: lto_simple_header
429 /* Size of the string table. */
433 /* The header for a function body. */
434 struct lto_function_header
: lto_simple_header_with_strings
436 /* Size of the cfg. */
441 /* Structure describing a symbol section. */
442 struct lto_decl_header
: lto_simple_header_with_strings
444 /* Size of region for decl state. */
445 int32_t decl_state_size
;
447 /* Number of nodes in globals stream. */
452 /* Statistics gathered during LTO, WPA and LTRANS. */
455 unsigned HOST_WIDE_INT num_input_cgraph_nodes
;
456 unsigned HOST_WIDE_INT num_output_symtab_nodes
;
457 unsigned HOST_WIDE_INT num_input_files
;
458 unsigned HOST_WIDE_INT num_output_files
;
459 unsigned HOST_WIDE_INT num_cgraph_partitions
;
460 unsigned HOST_WIDE_INT section_size
[LTO_N_SECTION_TYPES
];
461 unsigned HOST_WIDE_INT num_function_bodies
;
462 unsigned HOST_WIDE_INT num_trees
[NUM_TREE_CODES
];
463 unsigned HOST_WIDE_INT num_output_il_bytes
;
464 unsigned HOST_WIDE_INT num_compressed_il_bytes
;
465 unsigned HOST_WIDE_INT num_input_il_bytes
;
466 unsigned HOST_WIDE_INT num_uncompressed_il_bytes
;
467 unsigned HOST_WIDE_INT num_tree_bodies_output
;
468 unsigned HOST_WIDE_INT num_pickle_refs_output
;
471 /* Entry of LTO symtab encoder. */
472 struct lto_encoder_entry
475 /* Is the node in this partition (i.e. ltrans of this partition will
476 be responsible for outputting it)? */
477 unsigned int in_partition
:1;
478 /* Do we encode body in this partition? */
480 /* Do we encode initializer in this partition?
481 For example the readonly variable initializers are encoded to aid
482 constant folding even if they are not in the partition. */
483 unsigned int initializer
:1;
487 /* Encoder data structure used to stream callgraph nodes. */
488 struct lto_symtab_encoder_d
490 vec
<lto_encoder_entry
> nodes
;
491 hash_map
<symtab_node
*, size_t> *map
;
494 typedef struct lto_symtab_encoder_d
*lto_symtab_encoder_t
;
496 /* Iterator structure for cgraph node sets. */
497 struct lto_symtab_encoder_iterator
499 lto_symtab_encoder_t encoder
;
505 /* The lto_tree_ref_encoder struct is used to encode trees into indices. */
507 struct lto_tree_ref_encoder
509 hash_map
<tree
, unsigned> *tree_hash_table
; /* Maps pointers to indices. */
510 vec
<tree
> trees
; /* Maps indices to pointers. */
514 /* Structure to hold states of input scope. */
515 struct GTY((for_user
)) lto_in_decl_state
517 /* Array of lto_in_decl_buffers to store type and decls streams. */
518 vec
<tree
, va_gc
> *streams
[LTO_N_DECL_STREAMS
];
520 /* If this in-decl state is associated with a function. FN_DECL
521 point to the FUNCTION_DECL. */
524 /* True if decl state is compressed. */
528 typedef struct lto_in_decl_state
*lto_in_decl_state_ptr
;
530 struct decl_state_hasher
: ggc_ptr_hash
<lto_in_decl_state
>
533 hash (lto_in_decl_state
*s
)
535 return htab_hash_pointer (s
->fn_decl
);
539 equal (lto_in_decl_state
*a
, lto_in_decl_state
*b
)
541 return a
->fn_decl
== b
->fn_decl
;
545 /* The structure that holds all of the vectors of global types,
546 decls and cgraph nodes used in the serialization of this file. */
547 struct lto_out_decl_state
549 /* The buffers contain the sets of decls of various kinds and types we have
550 seen so far and the indexes assigned to them. */
551 struct lto_tree_ref_encoder streams
[LTO_N_DECL_STREAMS
];
553 /* Encoder for cgraph nodes. */
554 lto_symtab_encoder_t symtab_node_encoder
;
556 /* If this out-decl state belongs to a function, fn_decl points to that
557 function. Otherwise, it is NULL. */
560 /* True if decl state is compressed. */
564 typedef struct lto_out_decl_state
*lto_out_decl_state_ptr
;
567 /* Compact representation of a index <-> resolution pair. Unpacked to an
571 ld_plugin_symbol_resolution_t res
;
576 /* One of these is allocated for each object file that being compiled
577 by lto. This structure contains the tables that are needed by the
578 serialized functions and ipa passes to connect themselves to the
579 global types and decls as they are reconstituted. */
580 struct GTY(()) lto_file_decl_data
582 /* Decl state currently used. */
583 struct lto_in_decl_state
*current_decl_state
;
585 /* Decl state corresponding to regions outside of any functions
586 in the compilation unit. */
587 struct lto_in_decl_state
*global_decl_state
;
589 /* Table of cgraph nodes present in this file. */
590 lto_symtab_encoder_t
GTY((skip
)) symtab_node_encoder
;
592 /* Hash table maps lto-related section names to location in file. */
593 hash_table
<decl_state_hasher
> *function_decl_states
;
595 /* The .o file that these offsets relate to. */
596 const char *GTY((skip
)) file_name
;
598 /* Hash table maps lto-related section names to location in file. */
599 htab_t
GTY((skip
)) section_hash_table
;
601 /* Hash new name of renamed global declaration to its original name. */
602 htab_t
GTY((skip
)) renaming_hash_table
;
604 /* Linked list used temporarily in reader */
605 struct lto_file_decl_data
*next
;
607 /* Order in which the file appears on the command line. */
610 /* Sub ID for merged objects. */
611 unsigned HOST_WIDE_INT id
;
613 /* Symbol resolutions for this file */
614 vec
<res_pair
> GTY((skip
)) respairs
;
617 gcov_summary
GTY((skip
)) profile_info
;
619 /* Map assigning declarations their resolutions. */
620 hash_map
<tree
, ld_plugin_symbol_resolution
> * GTY((skip
)) resolution_map
;
622 /* Mode translation table. */
623 const unsigned char *mode_table
;
625 /* Read LTO section. */
626 lto_section lto_section_header
;
633 typedef struct lto_file_decl_data
*lto_file_decl_data_ptr
;
635 struct lto_char_ptr_base
640 /* An incore byte stream to buffer the various parts of the function.
641 The entire structure should be zeroed when created. The record
642 consists of a set of blocks. The first sizeof (ptr) bytes are used
643 as a chain, and the rest store the bytes to be written. */
644 struct lto_output_stream
646 /* The pointer to the first block in the stream. */
647 struct lto_char_ptr_base
* first_block
;
649 /* The pointer to the last and current block in the stream. */
650 struct lto_char_ptr_base
* current_block
;
652 /* The pointer to where the next char should be written. */
653 char * current_pointer
;
655 /* The number of characters left in the current block. */
656 unsigned int left_in_block
;
658 /* The block size of the last block allocated. */
659 unsigned int block_size
;
661 /* The total number of characters written. */
662 unsigned int total_size
;
665 /* A simple output block. This can be used for simple IPA passes that
666 do not need more than one stream. */
667 struct lto_simple_output_block
669 enum lto_section_type section_type
;
670 struct lto_out_decl_state
*decl_state
;
672 /* The stream that the main tree codes are written to. */
673 struct lto_output_stream
*main_stream
;
676 /* String hashing. */
682 unsigned int slot_num
;
685 /* Hashtable helpers. */
687 struct string_slot_hasher
: nofree_ptr_hash
<string_slot
>
689 static inline hashval_t
hash (const string_slot
*);
690 static inline bool equal (const string_slot
*, const string_slot
*);
693 /* Returns a hash code for DS. Adapted from libiberty's htab_hash_string
694 to support strings that may not end in '\0'. */
697 string_slot_hasher::hash (const string_slot
*ds
)
699 hashval_t r
= ds
->len
;
702 for (i
= 0; i
< ds
->len
; i
++)
703 r
= r
* 67 + (unsigned)ds
->s
[i
] - 113;
707 /* Returns nonzero if DS1 and DS2 are equal. */
710 string_slot_hasher::equal (const string_slot
*ds1
, const string_slot
*ds2
)
712 if (ds1
->len
== ds2
->len
)
713 return memcmp (ds1
->s
, ds2
->s
, ds1
->len
) == 0;
718 /* Data structure holding all the data and descriptors used when writing
722 enum lto_section_type section_type
;
723 struct lto_out_decl_state
*decl_state
;
725 /* The stream that the main tree codes are written to. */
726 struct lto_output_stream
*main_stream
;
728 /* The stream that contains the string table. */
729 struct lto_output_stream
*string_stream
;
731 /* The stream that contains the cfg. */
732 struct lto_output_stream
*cfg_stream
;
734 /* The hash table that contains the set of strings we have seen so
735 far and the indexes assigned to them. */
736 hash_table
<string_slot_hasher
> *string_hash_table
;
738 /* The current symbol that we are currently serializing. Null
739 if we are serializing something else. */
742 /* These are the last file and line that were seen in the stream.
743 If the current node differs from these, it needs to insert
744 something into the stream and fix these up. */
745 const char *current_file
;
750 /* Cache of nodes written in this section. */
751 struct streamer_tree_cache_d
*writer_cache
;
753 /* All data persistent across whole duration of output block
755 struct obstack obstack
;
759 /* Data and descriptors used when reading from an LTO file. */
763 /* The global decls and types. */
764 struct lto_file_decl_data
*file_data
;
766 /* The string table. */
769 /* The length of the string table. */
770 unsigned int strings_len
;
772 /* Maps each reference number to the resolution done by the linker. */
773 vec
<ld_plugin_symbol_resolution_t
> globals_resolution
;
775 /* Cache of pickled nodes. */
776 struct streamer_tree_cache_d
*reader_cache
;
778 /* Cache of source code location. */
779 lto_location_cache location_cache
;
783 /* In lto-section-in.c */
784 extern class lto_input_block
* lto_create_simple_input_block (
785 struct lto_file_decl_data
*,
786 enum lto_section_type
, const char **, size_t *);
788 lto_destroy_simple_input_block (struct lto_file_decl_data
*,
789 enum lto_section_type
,
790 class lto_input_block
*, const char *, size_t);
791 extern void lto_set_in_hooks (struct lto_file_decl_data
**,
792 lto_get_section_data_f
*,
793 lto_free_section_data_f
*);
794 extern struct lto_file_decl_data
**lto_get_file_decl_data (void);
795 extern const char *lto_get_section_data (struct lto_file_decl_data
*,
796 enum lto_section_type
,
797 const char *, int, size_t *,
798 bool decompress
= false);
799 extern const char *lto_get_summary_section_data (struct lto_file_decl_data
*,
800 enum lto_section_type
,
802 extern const char *lto_get_raw_section_data (struct lto_file_decl_data
*,
803 enum lto_section_type
,
804 const char *, int, size_t *);
805 extern void lto_free_section_data (struct lto_file_decl_data
*,
806 enum lto_section_type
,
807 const char *, const char *, size_t,
808 bool decompress
= false);
809 extern void lto_free_raw_section_data (struct lto_file_decl_data
*,
810 enum lto_section_type
,
811 const char *, const char *, size_t);
812 extern htab_t
lto_create_renaming_table (void);
813 extern void lto_record_renamed_decl (struct lto_file_decl_data
*,
814 const char *, const char *);
815 extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data
*,
817 extern struct lto_in_decl_state
*lto_new_in_decl_state (void);
818 extern void lto_delete_in_decl_state (struct lto_in_decl_state
*);
819 extern struct lto_in_decl_state
*lto_get_function_in_decl_state (
820 struct lto_file_decl_data
*, tree
);
821 extern void lto_free_function_in_decl_state (struct lto_in_decl_state
*);
822 extern void lto_free_function_in_decl_state_for_node (symtab_node
*);
823 extern void lto_section_overrun (class lto_input_block
*) ATTRIBUTE_NORETURN
;
824 extern void lto_value_range_error (const char *,
825 HOST_WIDE_INT
, HOST_WIDE_INT
,
826 HOST_WIDE_INT
) ATTRIBUTE_NORETURN
;
828 /* In lto-section-out.c */
829 extern void lto_begin_section (const char *, bool);
830 extern void lto_end_section (void);
831 extern void lto_write_data (const void *, unsigned int);
832 extern void lto_write_raw_data (const void *, unsigned int);
833 extern void lto_write_stream (struct lto_output_stream
*);
834 extern bool lto_output_decl_index (struct lto_output_stream
*,
835 struct lto_tree_ref_encoder
*,
836 tree
, unsigned int *);
837 extern void lto_output_field_decl_index (struct lto_out_decl_state
*,
838 struct lto_output_stream
*, tree
);
839 extern void lto_output_fn_decl_index (struct lto_out_decl_state
*,
840 struct lto_output_stream
*, tree
);
841 extern void lto_output_namespace_decl_index (struct lto_out_decl_state
*,
842 struct lto_output_stream
*, tree
);
843 extern void lto_output_var_decl_index (struct lto_out_decl_state
*,
844 struct lto_output_stream
*, tree
);
845 extern void lto_output_type_decl_index (struct lto_out_decl_state
*,
846 struct lto_output_stream
*, tree
);
847 extern void lto_output_type_ref_index (struct lto_out_decl_state
*,
848 struct lto_output_stream
*, tree
);
849 extern struct lto_simple_output_block
*lto_create_simple_output_block (
850 enum lto_section_type
);
851 extern void lto_destroy_simple_output_block (struct lto_simple_output_block
*);
852 extern struct lto_out_decl_state
*lto_new_out_decl_state (void);
853 extern void lto_delete_out_decl_state (struct lto_out_decl_state
*);
854 extern struct lto_out_decl_state
*lto_get_out_decl_state (void);
855 extern void lto_push_out_decl_state (struct lto_out_decl_state
*);
856 extern struct lto_out_decl_state
*lto_pop_out_decl_state (void);
857 extern void lto_record_function_out_decl_state (tree
,
858 struct lto_out_decl_state
*);
859 extern void lto_append_block (struct lto_output_stream
*);
862 /* In lto-streamer.c. */
864 /* Set when streaming LTO for offloading compiler. */
865 extern bool lto_stream_offload_p
;
867 extern const char *lto_tag_name (enum LTO_tags
);
868 extern char *lto_get_section_name (int, const char *, int,
869 struct lto_file_decl_data
*);
870 extern void print_lto_report (const char *);
871 extern void lto_streamer_init (void);
872 extern bool gate_lto_out (void);
873 extern void lto_check_version (int, int, const char *);
874 extern void lto_streamer_hooks_init (void);
876 /* In lto-streamer-in.c */
877 extern void lto_input_cgraph (struct lto_file_decl_data
*, const char *);
878 extern void lto_reader_init (void);
879 extern void lto_free_file_name_hash (void);
880 extern void lto_input_function_body (struct lto_file_decl_data
*,
881 struct cgraph_node
*,
883 extern void lto_input_variable_constructor (struct lto_file_decl_data
*,
884 struct varpool_node
*,
886 extern void lto_input_constructors_and_inits (struct lto_file_decl_data
*,
888 extern void lto_input_toplevel_asms (struct lto_file_decl_data
*, int);
889 extern void lto_input_mode_table (struct lto_file_decl_data
*);
890 extern class data_in
*lto_data_in_create (struct lto_file_decl_data
*,
891 const char *, unsigned,
892 vec
<ld_plugin_symbol_resolution_t
> );
893 extern void lto_data_in_delete (class data_in
*);
894 extern void lto_input_data_block (class lto_input_block
*, void *, size_t);
895 void lto_input_location (location_t
*, struct bitpack_d
*, class data_in
*);
896 location_t
stream_input_location_now (struct bitpack_d
*bp
,
897 class data_in
*data
);
898 tree
lto_input_tree_ref (class lto_input_block
*, class data_in
*,
899 struct function
*, enum LTO_tags
);
900 void lto_tag_check_set (enum LTO_tags
, int, ...);
901 void lto_init_eh (void);
902 hashval_t
lto_input_scc (class lto_input_block
*, class data_in
*,
903 unsigned *, unsigned *);
904 tree
lto_input_tree_1 (class lto_input_block
*, class data_in
*,
905 enum LTO_tags
, hashval_t hash
);
906 tree
lto_input_tree (class lto_input_block
*, class data_in
*);
909 /* In lto-streamer-out.c */
910 extern void lto_register_decl_definition (tree
, struct lto_file_decl_data
*);
911 extern struct output_block
*create_output_block (enum lto_section_type
);
912 extern void destroy_output_block (struct output_block
*);
913 extern void lto_output_tree (struct output_block
*, tree
, bool, bool);
914 extern void lto_output_toplevel_asms (void);
915 extern void produce_asm (struct output_block
*ob
, tree fn
);
916 extern void lto_output ();
917 extern void produce_asm_for_decls ();
918 void lto_output_decl_state_streams (struct output_block
*,
919 struct lto_out_decl_state
*);
920 void lto_output_decl_state_refs (struct output_block
*,
921 struct lto_output_stream
*,
922 struct lto_out_decl_state
*);
923 void lto_output_location (struct output_block
*, struct bitpack_d
*, location_t
);
924 void lto_output_init_mode_table (void);
925 void lto_prepare_function_for_streaming (cgraph_node
*);
928 /* In lto-cgraph.c */
929 extern bool asm_nodes_output
;
930 lto_symtab_encoder_t
lto_symtab_encoder_new (bool);
931 int lto_symtab_encoder_encode (lto_symtab_encoder_t
, symtab_node
*);
932 void lto_symtab_encoder_delete (lto_symtab_encoder_t
);
933 bool lto_symtab_encoder_delete_node (lto_symtab_encoder_t
, symtab_node
*);
934 bool lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t
,
935 struct cgraph_node
*);
936 bool lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t
,
938 void lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t
,
941 bool lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t
,
943 void output_symtab (void);
944 void input_symtab (void);
945 void output_offload_tables (void);
946 void input_offload_tables (bool);
947 bool referenced_from_other_partition_p (struct ipa_ref_list
*,
948 lto_symtab_encoder_t
);
949 bool reachable_from_other_partition_p (struct cgraph_node
*,
950 lto_symtab_encoder_t
);
951 bool referenced_from_this_partition_p (symtab_node
*,
952 lto_symtab_encoder_t
);
953 bool reachable_from_this_partition_p (struct cgraph_node
*,
954 lto_symtab_encoder_t
);
955 lto_symtab_encoder_t
compute_ltrans_boundary (lto_symtab_encoder_t encoder
);
956 void select_what_to_stream (void);
958 /* In options-save.c. */
959 void cl_target_option_stream_out (struct output_block
*, struct bitpack_d
*,
960 struct cl_target_option
*);
962 void cl_target_option_stream_in (class data_in
*,
964 struct cl_target_option
*);
966 void cl_optimization_stream_out (struct output_block
*,
967 struct bitpack_d
*, struct cl_optimization
*);
969 void cl_optimization_stream_in (class data_in
*,
970 struct bitpack_d
*, struct cl_optimization
*);
975 extern void lto_write_options (void);
978 /* Statistics gathered during LTO, WPA and LTRANS. */
979 extern struct lto_stats_d lto_stats
;
981 /* Section names corresponding to the values of enum lto_section_type. */
982 extern const char *lto_section_name
[];
984 /* Holds all the out decl states of functions output so far in the
985 current output file. */
986 extern vec
<lto_out_decl_state_ptr
> lto_function_decl_states
;
988 /* Return true if LTO tag TAG corresponds to a tree code. */
990 lto_tag_is_tree_code_p (enum LTO_tags tag
)
992 return tag
> LTO_tree_pickle_reference
&& (unsigned) tag
<= MAX_TREE_CODES
;
996 /* Return true if LTO tag TAG corresponds to a gimple code. */
998 lto_tag_is_gimple_code_p (enum LTO_tags tag
)
1000 return (unsigned) tag
>= NUM_TREE_CODES
+ 2
1001 && (unsigned) tag
< 2 + NUM_TREE_CODES
+ LAST_AND_UNUSED_GIMPLE_CODE
;
1005 /* Return the LTO tag corresponding to gimple code CODE. See enum
1006 LTO_tags for details on the conversion. */
1007 static inline enum LTO_tags
1008 lto_gimple_code_to_tag (enum gimple_code code
)
1010 return (enum LTO_tags
) ((unsigned) code
+ NUM_TREE_CODES
+ 2);
1014 /* Return the GIMPLE code corresponding to TAG. See enum LTO_tags for
1015 details on the conversion. */
1016 static inline enum gimple_code
1017 lto_tag_to_gimple_code (enum LTO_tags tag
)
1019 gcc_assert (lto_tag_is_gimple_code_p (tag
));
1020 return (enum gimple_code
) ((unsigned) tag
- NUM_TREE_CODES
- 2);
1024 /* Return the LTO tag corresponding to tree code CODE. See enum
1025 LTO_tags for details on the conversion. */
1026 static inline enum LTO_tags
1027 lto_tree_code_to_tag (enum tree_code code
)
1029 return (enum LTO_tags
) ((unsigned) code
+ 2);
1033 /* Return the tree code corresponding to TAG. See enum LTO_tags for
1034 details on the conversion. */
1035 static inline enum tree_code
1036 lto_tag_to_tree_code (enum LTO_tags tag
)
1038 gcc_assert (lto_tag_is_tree_code_p (tag
));
1039 return (enum tree_code
) ((unsigned) tag
- 2);
1042 /* Check that tag ACTUAL == EXPECTED. */
1044 lto_tag_check (enum LTO_tags actual
, enum LTO_tags expected
)
1046 if (actual
!= expected
)
1047 internal_error ("bytecode stream: expected tag %s instead of %s",
1048 lto_tag_name (expected
), lto_tag_name (actual
));
1051 /* Check that tag ACTUAL is in the range [TAG1, TAG2]. */
1053 lto_tag_check_range (enum LTO_tags actual
, enum LTO_tags tag1
,
1056 if (actual
< tag1
|| actual
> tag2
)
1057 internal_error ("bytecode stream: tag %s is not in the expected range "
1059 lto_tag_name (actual
),
1060 lto_tag_name (tag1
),
1061 lto_tag_name (tag2
));
1064 /* Initialize an lto_out_decl_buffer ENCODER. */
1066 lto_init_tree_ref_encoder (struct lto_tree_ref_encoder
*encoder
)
1068 encoder
->tree_hash_table
= new hash_map
<tree
, unsigned> (251);
1069 encoder
->trees
.create (0);
1073 /* Destroy an lto_tree_ref_encoder ENCODER by freeing its contents. The
1074 memory used by ENCODER is not freed by this function. */
1076 lto_destroy_tree_ref_encoder (struct lto_tree_ref_encoder
*encoder
)
1078 /* Hash table may be delete already. */
1079 delete encoder
->tree_hash_table
;
1080 encoder
->tree_hash_table
= NULL
;
1081 encoder
->trees
.release ();
1084 /* Return the number of trees encoded in ENCODER. */
1085 static inline unsigned int
1086 lto_tree_ref_encoder_size (struct lto_tree_ref_encoder
*encoder
)
1088 return encoder
->trees
.length ();
1091 /* Return the IDX-th tree in ENCODER. */
1093 lto_tree_ref_encoder_get_tree (struct lto_tree_ref_encoder
*encoder
,
1096 return encoder
->trees
[idx
];
1099 /* Return number of encoded nodes in ENCODER. */
1101 lto_symtab_encoder_size (lto_symtab_encoder_t encoder
)
1103 return encoder
->nodes
.length ();
1106 /* Value used to represent failure of lto_symtab_encoder_lookup. */
1107 #define LCC_NOT_FOUND (-1)
1109 /* Look up NODE in encoder. Return NODE's reference if it has been encoded
1110 or LCC_NOT_FOUND if it is not there. */
1113 lto_symtab_encoder_lookup (lto_symtab_encoder_t encoder
,
1116 size_t *slot
= encoder
->map
->get (node
);
1117 return (slot
&& *slot
? *(slot
) - 1 : LCC_NOT_FOUND
);
1120 /* Return true if iterator LSE points to nothing. */
1122 lsei_end_p (lto_symtab_encoder_iterator lsei
)
1124 return lsei
.index
>= (unsigned)lto_symtab_encoder_size (lsei
.encoder
);
1127 /* Advance iterator LSE. */
1129 lsei_next (lto_symtab_encoder_iterator
*lsei
)
1134 /* Return the node pointed to by LSI. */
1135 static inline symtab_node
*
1136 lsei_node (lto_symtab_encoder_iterator lsei
)
1138 return lsei
.encoder
->nodes
[lsei
.index
].node
;
1141 /* Return the node pointed to by LSI. */
1142 static inline struct cgraph_node
*
1143 lsei_cgraph_node (lto_symtab_encoder_iterator lsei
)
1145 return dyn_cast
<cgraph_node
*> (lsei
.encoder
->nodes
[lsei
.index
].node
);
1148 /* Return the node pointed to by LSI. */
1149 static inline varpool_node
*
1150 lsei_varpool_node (lto_symtab_encoder_iterator lsei
)
1152 return dyn_cast
<varpool_node
*> (lsei
.encoder
->nodes
[lsei
.index
].node
);
1155 /* Return the cgraph node corresponding to REF using ENCODER. */
1157 static inline symtab_node
*
1158 lto_symtab_encoder_deref (lto_symtab_encoder_t encoder
, int ref
)
1160 if (ref
== LCC_NOT_FOUND
)
1163 return encoder
->nodes
[ref
].node
;
1166 /* Return an iterator to the first node in LSI. */
1167 static inline lto_symtab_encoder_iterator
1168 lsei_start (lto_symtab_encoder_t encoder
)
1170 lto_symtab_encoder_iterator lsei
;
1172 lsei
.encoder
= encoder
;
1177 /* Advance iterator LSE. */
1179 lsei_next_in_partition (lto_symtab_encoder_iterator
*lsei
)
1182 while (!lsei_end_p (*lsei
)
1183 && !lto_symtab_encoder_in_partition_p (lsei
->encoder
, lsei_node (*lsei
)))
1187 /* Return an iterator to the first node in LSI. */
1188 static inline lto_symtab_encoder_iterator
1189 lsei_start_in_partition (lto_symtab_encoder_t encoder
)
1191 lto_symtab_encoder_iterator lsei
= lsei_start (encoder
);
1193 if (lsei_end_p (lsei
))
1195 if (!lto_symtab_encoder_in_partition_p (encoder
, lsei_node (lsei
)))
1196 lsei_next_in_partition (&lsei
);
1201 /* Advance iterator LSE. */
1203 lsei_next_function_in_partition (lto_symtab_encoder_iterator
*lsei
)
1206 while (!lsei_end_p (*lsei
)
1207 && (!is_a
<cgraph_node
*> (lsei_node (*lsei
))
1208 || !lto_symtab_encoder_in_partition_p (lsei
->encoder
, lsei_node (*lsei
))))
1212 /* Return an iterator to the first node in LSI. */
1213 static inline lto_symtab_encoder_iterator
1214 lsei_start_function_in_partition (lto_symtab_encoder_t encoder
)
1216 lto_symtab_encoder_iterator lsei
= lsei_start (encoder
);
1218 if (lsei_end_p (lsei
))
1220 if (!is_a
<cgraph_node
*> (lsei_node (lsei
))
1221 || !lto_symtab_encoder_in_partition_p (encoder
, lsei_node (lsei
)))
1222 lsei_next_function_in_partition (&lsei
);
1227 /* Advance iterator LSE. */
1229 lsei_next_variable_in_partition (lto_symtab_encoder_iterator
*lsei
)
1232 while (!lsei_end_p (*lsei
)
1233 && (!is_a
<varpool_node
*> (lsei_node (*lsei
))
1234 || !lto_symtab_encoder_in_partition_p (lsei
->encoder
, lsei_node (*lsei
))))
1238 /* Return an iterator to the first node in LSI. */
1239 static inline lto_symtab_encoder_iterator
1240 lsei_start_variable_in_partition (lto_symtab_encoder_t encoder
)
1242 lto_symtab_encoder_iterator lsei
= lsei_start (encoder
);
1244 if (lsei_end_p (lsei
))
1246 if (!is_a
<varpool_node
*> (lsei_node (lsei
))
1247 || !lto_symtab_encoder_in_partition_p (encoder
, lsei_node (lsei
)))
1248 lsei_next_variable_in_partition (&lsei
);
1253 DEFINE_DECL_STREAM_FUNCS (TYPE
, type
)
1254 DEFINE_DECL_STREAM_FUNCS (FIELD_DECL
, field_decl
)
1255 DEFINE_DECL_STREAM_FUNCS (FN_DECL
, fn_decl
)
1256 DEFINE_DECL_STREAM_FUNCS (VAR_DECL
, var_decl
)
1257 DEFINE_DECL_STREAM_FUNCS (TYPE_DECL
, type_decl
)
1258 DEFINE_DECL_STREAM_FUNCS (NAMESPACE_DECL
, namespace_decl
)
1259 DEFINE_DECL_STREAM_FUNCS (LABEL_DECL
, label_decl
)
1261 /* Entry for the delayed registering of decl -> DIE references. */
1265 unsigned HOST_WIDE_INT off
;
1268 extern vec
<dref_entry
> dref_queue
;
1270 extern FILE *streamer_dump_file
;
1272 #endif /* GCC_LTO_STREAMER_H */