1 /* Data structures and declarations used for reading and writing
2 GIMPLE to a file stream.
4 Copyright (C) 2009-2015 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 /* Define when debugging the LTO streamer. This causes the writer
31 to output the numeric value for the memory address of the tree node
32 being emitted. When debugging a problem in the reader, check the
33 original address that the writer was emitting using lto_orig_address_get.
34 With this value, set a breakpoint in the writer (e.g., lto_output_tree)
35 to trace how the faulty node is being emitted. */
36 /* #define LTO_STREAMER_DEBUG 1 */
38 /* The encoding for a function consists of the following sections:
46 7) Names for the labels that have names
48 9) The control flow graph.
49 10-11)Gimple for local decls.
50 12) Gimple for the function.
54 2-6) THE GLOBAL DECLS AND TYPES.
56 The global decls and types are encoded in the same way. For each
57 entry, there is word with the offset within the section to the
62 Since most labels do not have names, this section my be of zero
63 length. It consists of an array of string table references, one
64 per label. In the lto code, the labels are given either
65 positive or negative indexes. the positive ones have names and
66 the negative ones do not. The positive index can be used to
67 find the name in this array.
71 10) Index into the local decls. Since local decls can have local
72 decls inside them, they must be read in randomly in order to
73 properly restore them.
75 11-12) GIMPLE FOR THE LOCAL DECLS AND THE FUNCTION BODY.
77 The gimple consists of a set of records.
81 At the top level of (8) is the function. It consists of five
84 LTO_function - The tag.
85 eh tree - This is all of the exception handling regions
86 put out in a post order traversial of the
87 tree. Siblings are output as lists terminated
88 by a 0. The set of fields matches the fields
91 last_basic_block - in uleb128 form.
93 basic blocks - This is the set of basic blocks.
95 zero - The termination of the basic blocks.
99 There are two forms of basic blocks depending on if they are
102 The basic block consists of:
104 LTO_bb1 or LTO_bb0 - The tag.
106 bb->index - the index in uleb128 form.
108 #succs - The number of successors un uleb128 form.
110 the successors - For each edge, a pair. The first of the
111 pair is the index of the successor in
112 uleb128 form and the second are the flags in
115 the statements - A gimple tree, as described above.
116 These are only present for LTO_BB1.
117 Following each statement is an optional
118 exception handling record LTO_eh_region
119 which contains the region number (for
122 zero - This is only present for LTO_BB1 and is used
123 to terminate the statements and exception
124 regions within this block.
128 String are represented in the table as pairs, a length in ULEB128
129 form followed by the data for the string. */
131 #define LTO_major_version 5
132 #define LTO_minor_version 0
134 typedef unsigned char lto_decl_flags_t
;
137 /* Tags representing the various IL objects written to the bytecode file
138 (GIMPLE statements, basic blocks, EH regions, tree nodes, etc).
140 NOTE, when adding new LTO tags, also update lto_tag_name. */
145 /* Special for streamer. Reference to previously-streamed node. */
146 LTO_tree_pickle_reference
,
148 /* Reserve enough entries to fit all the tree and gimple codes handled
149 by the streamer. This guarantees that:
151 1- Given a tree code C:
152 enum LTO_tags tag == C + 1
154 2- Given a gimple code C:
155 enum LTO_tags tag == C + NUM_TREE_CODES + 1
157 Conversely, to map between LTO tags and tree/gimple codes, the
158 reverse operation must be applied. */
159 LTO_bb0
= 1 + MAX_TREE_CODES
+ LAST_AND_UNUSED_GIMPLE_CODE
,
162 /* EH region holding the previous statement. */
165 /* An MD or NORMAL builtin. Only the code and class are streamed out. */
168 /* Shared INTEGER_CST node. */
177 /* EH region types. These mirror enum eh_region_type. */
180 LTO_ert_allowed_exceptions
,
181 LTO_ert_must_not_throw
,
183 /* EH landing pad. */
186 /* EH try/catch node. */
189 /* Special for global streamer. A blob of unnamed tree nodes. */
192 /* References to indexable tree nodes. These objects are stored in
193 tables that are written separately from the function bodies that
194 reference them. This way they can be instantiated even when the
195 referencing functions aren't (e.g., during WPA) and it also allows
196 functions to be copied from one file to another without having
197 to unpickle the body first (the references are location
200 NOTE, do not regroup these values as the grouping is exposed
201 in the range checks done in lto_input_tree. */
202 LTO_field_decl_ref
, /* Do not change. */
203 LTO_function_decl_ref
,
205 LTO_namespace_decl_ref
,
211 LTO_imported_decl_ref
,
212 LTO_translation_unit_decl_ref
,
214 LTO_namelist_decl_ref
, /* Do not change. */
216 /* This tag must always be last. */
221 /* Set of section types that are in an LTO file. This list will grow
222 as the number of IPA passes grows since each IPA pass will need its
223 own section type to store its summary information.
225 When adding a new section type, you must also extend the
226 LTO_SECTION_NAME array in lto-section-in.c. */
227 enum lto_section_type
229 LTO_section_decls
= 0,
230 LTO_section_function_body
,
231 LTO_section_static_initializer
,
235 LTO_section_jump_functions
,
236 LTO_section_ipa_pure_const
,
237 LTO_section_ipa_reference
,
238 LTO_section_ipa_profile
,
239 LTO_section_symtab_nodes
,
241 LTO_section_cgraph_opt_sum
,
242 LTO_section_inline_summary
,
243 LTO_section_ipcp_transform
,
245 LTO_section_offload_table
,
246 LTO_section_mode_table
,
247 LTO_N_SECTION_TYPES
/* Must be last. */
250 /* Indices to the various function, type and symbol streams. */
251 enum lto_decl_stream_e_t
253 LTO_DECL_STREAM_TYPE
= 0, /* Must be first. */
254 LTO_DECL_STREAM_FIELD_DECL
,
255 LTO_DECL_STREAM_FN_DECL
,
256 LTO_DECL_STREAM_VAR_DECL
,
257 LTO_DECL_STREAM_TYPE_DECL
,
258 LTO_DECL_STREAM_NAMESPACE_DECL
,
259 LTO_DECL_STREAM_LABEL_DECL
,
263 typedef enum ld_plugin_symbol_resolution ld_plugin_symbol_resolution_t
;
266 /* Macro to define convenience functions for type and decl streams
267 in lto_file_decl_data. */
268 #define DEFINE_DECL_STREAM_FUNCS(UPPER_NAME, name) \
270 lto_file_decl_data_get_ ## name (struct lto_file_decl_data *data, \
273 struct lto_in_decl_state *state = data->current_decl_state; \
274 return (*state->streams[LTO_DECL_STREAM_## UPPER_NAME])[idx]; \
277 static inline unsigned int \
278 lto_file_decl_data_num_ ## name ## s (struct lto_file_decl_data *data) \
280 struct lto_in_decl_state *state = data->current_decl_state; \
281 return vec_safe_length (state->streams[LTO_DECL_STREAM_## UPPER_NAME]); \
285 /* Return a char pointer to the start of a data stream for an lto pass
286 or function. The first parameter is the file data that contains
287 the information. The second parameter is the type of information
288 to be obtained. The third parameter is the name of the function
289 and is only used when finding a function body; otherwise it is
290 NULL. The fourth parameter is the length of the data returned. */
291 typedef const char* (lto_get_section_data_f
) (struct lto_file_decl_data
*,
292 enum lto_section_type
,
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
298 itself and the fifth is the length of the data. */
299 typedef void (lto_free_section_data_f
) (struct lto_file_decl_data
*,
300 enum lto_section_type
,
305 /* The location cache holds expanded locations for streamed in trees.
306 This is done to reduce memory usage of libcpp linemap that strongly preffers
307 locations to be inserted in the soruce order. */
309 class lto_location_cache
312 /* Apply all changes in location cache. Add locations into linemap and patch
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
,
320 struct data_in
*data_in
);
321 lto_location_cache ()
322 : loc_cache (), accepted_length (0), current_file (NULL
), current_line (0),
323 current_col (0), current_sysp (false), current_loc (UNKNOWN_LOCATION
)
325 gcc_assert (!current_cache
);
326 current_cache
= this;
328 ~lto_location_cache ()
330 apply_location_cache ();
331 gcc_assert (current_cache
== this);
332 current_cache
= NULL
;
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
338 static lto_location_cache
*current_cache
;
341 static int cmp_loc (const void *pa
, const void *pb
);
343 struct cached_location
351 /* The location cache. */
353 auto_vec
<cached_location
> loc_cache
;
355 /* Accepted entries are ones used by trees that are known to be not unified
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. */
365 const char *current_file
;
369 location_t current_loc
;
372 /* Structure used as buffer for reading an LTO file. */
373 class lto_input_block
376 /* Special constructor for the string table, it abuses this to
377 do random access but use the uhwi decoder. */
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_
) {}
386 const unsigned char *mode_table
;
392 /* The is the first part of the record for a function or constructor
396 int16_t major_version
;
397 int16_t minor_version
;
400 /* The is the first part of the record in an LTO file for many of the
402 struct lto_simple_header
: lto_header
404 /* Size of main gimple body of function. */
408 struct lto_simple_header_with_strings
: lto_simple_header
410 /* Size of main gimple body of function. */
413 /* Size of the string table. */
417 /* The header for a function body. */
418 struct lto_function_header
: lto_simple_header_with_strings
420 /* Size of the cfg. */
425 /* Structure describing a symbol section. */
426 struct lto_decl_header
: lto_simple_header_with_strings
428 /* Size of region for decl state. */
429 int32_t decl_state_size
;
431 /* Number of nodes in globals stream. */
436 /* Statistics gathered during LTO, WPA and LTRANS. */
439 unsigned HOST_WIDE_INT num_input_cgraph_nodes
;
440 unsigned HOST_WIDE_INT num_output_symtab_nodes
;
441 unsigned HOST_WIDE_INT num_input_files
;
442 unsigned HOST_WIDE_INT num_output_files
;
443 unsigned HOST_WIDE_INT num_cgraph_partitions
;
444 unsigned HOST_WIDE_INT section_size
[LTO_N_SECTION_TYPES
];
445 unsigned HOST_WIDE_INT num_function_bodies
;
446 unsigned HOST_WIDE_INT num_trees
[NUM_TREE_CODES
];
447 unsigned HOST_WIDE_INT num_output_il_bytes
;
448 unsigned HOST_WIDE_INT num_compressed_il_bytes
;
449 unsigned HOST_WIDE_INT num_input_il_bytes
;
450 unsigned HOST_WIDE_INT num_uncompressed_il_bytes
;
451 unsigned HOST_WIDE_INT num_tree_bodies_output
;
452 unsigned HOST_WIDE_INT num_pickle_refs_output
;
455 /* Entry of LTO symtab encoder. */
456 struct lto_encoder_entry
459 /* Is the node in this partition (i.e. ltrans of this partition will
460 be responsible for outputting it)? */
461 unsigned int in_partition
:1;
462 /* Do we encode body in this partition? */
464 /* Do we encode initializer in this partition?
465 For example the readonly variable initializers are encoded to aid
466 constant folding even if they are not in the partition. */
467 unsigned int initializer
:1;
471 /* Encoder data structure used to stream callgraph nodes. */
472 struct lto_symtab_encoder_d
474 vec
<lto_encoder_entry
> nodes
;
475 hash_map
<symtab_node
*, size_t> *map
;
478 typedef struct lto_symtab_encoder_d
*lto_symtab_encoder_t
;
480 /* Iterator structure for cgraph node sets. */
481 struct lto_symtab_encoder_iterator
483 lto_symtab_encoder_t encoder
;
489 /* The lto_tree_ref_encoder struct is used to encode trees into indices. */
491 struct lto_tree_ref_encoder
493 hash_map
<tree
, unsigned> *tree_hash_table
; /* Maps pointers to indices. */
494 vec
<tree
> trees
; /* Maps indices to pointers. */
498 /* Structure to hold states of input scope. */
499 struct GTY((for_user
)) lto_in_decl_state
501 /* Array of lto_in_decl_buffers to store type and decls streams. */
502 vec
<tree
, va_gc
> *streams
[LTO_N_DECL_STREAMS
];
504 /* If this in-decl state is associated with a function. FN_DECL
505 point to the FUNCTION_DECL. */
509 typedef struct lto_in_decl_state
*lto_in_decl_state_ptr
;
511 struct decl_state_hasher
: ggc_ptr_hash
<lto_in_decl_state
>
514 hash (lto_in_decl_state
*s
)
516 return htab_hash_pointer (s
->fn_decl
);
520 equal (lto_in_decl_state
*a
, lto_in_decl_state
*b
)
522 return a
->fn_decl
== b
->fn_decl
;
526 /* The structure that holds all of the vectors of global types,
527 decls and cgraph nodes used in the serialization of this file. */
528 struct lto_out_decl_state
530 /* The buffers contain the sets of decls of various kinds and types we have
531 seen so far and the indexes assigned to them. */
532 struct lto_tree_ref_encoder streams
[LTO_N_DECL_STREAMS
];
534 /* Encoder for cgraph nodes. */
535 lto_symtab_encoder_t symtab_node_encoder
;
537 /* If this out-decl state belongs to a function, fn_decl points to that
538 function. Otherwise, it is NULL. */
542 typedef struct lto_out_decl_state
*lto_out_decl_state_ptr
;
545 /* Compact representation of a index <-> resolution pair. Unpacked to an
549 ld_plugin_symbol_resolution_t res
;
554 /* One of these is allocated for each object file that being compiled
555 by lto. This structure contains the tables that are needed by the
556 serialized functions and ipa passes to connect themselves to the
557 global types and decls as they are reconstituted. */
558 struct GTY(()) lto_file_decl_data
560 /* Decl state currently used. */
561 struct lto_in_decl_state
*current_decl_state
;
563 /* Decl state corresponding to regions outside of any functions
564 in the compilation unit. */
565 struct lto_in_decl_state
*global_decl_state
;
567 /* Table of cgraph nodes present in this file. */
568 lto_symtab_encoder_t
GTY((skip
)) symtab_node_encoder
;
570 /* Hash table maps lto-related section names to location in file. */
571 hash_table
<decl_state_hasher
> *function_decl_states
;
573 /* The .o file that these offsets relate to. */
574 const char *GTY((skip
)) file_name
;
576 /* Hash table maps lto-related section names to location in file. */
577 htab_t
GTY((skip
)) section_hash_table
;
579 /* Hash new name of renamed global declaration to its original name. */
580 htab_t
GTY((skip
)) renaming_hash_table
;
582 /* Linked list used temporarily in reader */
583 struct lto_file_decl_data
*next
;
585 /* Sub ID for merged objects. */
586 unsigned HOST_WIDE_INT id
;
588 /* Symbol resolutions for this file */
589 vec
<res_pair
> GTY((skip
)) respairs
;
592 struct gcov_ctr_summary
GTY((skip
)) profile_info
;
594 /* Map assigning declarations their resolutions. */
595 hash_map
<tree
, ld_plugin_symbol_resolution
> * GTY((skip
)) resolution_map
;
597 /* Mode translation table. */
598 const unsigned char *mode_table
;
601 typedef struct lto_file_decl_data
*lto_file_decl_data_ptr
;
603 struct lto_char_ptr_base
608 /* An incore byte stream to buffer the various parts of the function.
609 The entire structure should be zeroed when created. The record
610 consists of a set of blocks. The first sizeof (ptr) bytes are used
611 as a chain, and the rest store the bytes to be written. */
612 struct lto_output_stream
614 /* The pointer to the first block in the stream. */
615 struct lto_char_ptr_base
* first_block
;
617 /* The pointer to the last and current block in the stream. */
618 struct lto_char_ptr_base
* current_block
;
620 /* The pointer to where the next char should be written. */
621 char * current_pointer
;
623 /* The number of characters left in the current block. */
624 unsigned int left_in_block
;
626 /* The block size of the last block allocated. */
627 unsigned int block_size
;
629 /* The total number of characters written. */
630 unsigned int total_size
;
633 /* A simple output block. This can be used for simple IPA passes that
634 do not need more than one stream. */
635 struct lto_simple_output_block
637 enum lto_section_type section_type
;
638 struct lto_out_decl_state
*decl_state
;
640 /* The stream that the main tree codes are written to. */
641 struct lto_output_stream
*main_stream
;
644 /* String hashing. */
650 unsigned int slot_num
;
653 /* Hashtable helpers. */
655 struct string_slot_hasher
: nofree_ptr_hash
<string_slot
>
657 static inline hashval_t
hash (const string_slot
*);
658 static inline bool equal (const string_slot
*, const string_slot
*);
661 /* Returns a hash code for DS. Adapted from libiberty's htab_hash_string
662 to support strings that may not end in '\0'. */
665 string_slot_hasher::hash (const string_slot
*ds
)
667 hashval_t r
= ds
->len
;
670 for (i
= 0; i
< ds
->len
; i
++)
671 r
= r
* 67 + (unsigned)ds
->s
[i
] - 113;
675 /* Returns nonzero if DS1 and DS2 are equal. */
678 string_slot_hasher::equal (const string_slot
*ds1
, const string_slot
*ds2
)
680 if (ds1
->len
== ds2
->len
)
681 return memcmp (ds1
->s
, ds2
->s
, ds1
->len
) == 0;
686 /* Data structure holding all the data and descriptors used when writing
690 enum lto_section_type section_type
;
691 struct lto_out_decl_state
*decl_state
;
693 /* The stream that the main tree codes are written to. */
694 struct lto_output_stream
*main_stream
;
696 /* The stream that contains the string table. */
697 struct lto_output_stream
*string_stream
;
699 /* The stream that contains the cfg. */
700 struct lto_output_stream
*cfg_stream
;
702 /* The hash table that contains the set of strings we have seen so
703 far and the indexes assigned to them. */
704 hash_table
<string_slot_hasher
> *string_hash_table
;
706 /* The current symbol that we are currently serializing. Null
707 if we are serializing something else. */
710 /* These are the last file and line that were seen in the stream.
711 If the current node differs from these, it needs to insert
712 something into the stream and fix these up. */
713 const char *current_file
;
718 /* Cache of nodes written in this section. */
719 struct streamer_tree_cache_d
*writer_cache
;
721 /* All data persistent across whole duration of output block
723 struct obstack obstack
;
727 /* Data and descriptors used when reading from an LTO file. */
730 /* The global decls and types. */
731 struct lto_file_decl_data
*file_data
;
733 /* The string table. */
736 /* The length of the string table. */
737 unsigned int strings_len
;
739 /* Maps each reference number to the resolution done by the linker. */
740 vec
<ld_plugin_symbol_resolution_t
> globals_resolution
;
742 /* Cache of pickled nodes. */
743 struct streamer_tree_cache_d
*reader_cache
;
745 /* Cache of source code location. */
746 lto_location_cache location_cache
;
750 /* In lto-section-in.c */
751 extern struct lto_input_block
* lto_create_simple_input_block (
752 struct lto_file_decl_data
*,
753 enum lto_section_type
, const char **, size_t *);
755 lto_destroy_simple_input_block (struct lto_file_decl_data
*,
756 enum lto_section_type
,
757 struct lto_input_block
*, const char *, size_t);
758 extern void lto_set_in_hooks (struct lto_file_decl_data
**,
759 lto_get_section_data_f
*,
760 lto_free_section_data_f
*);
761 extern struct lto_file_decl_data
**lto_get_file_decl_data (void);
762 extern const char *lto_get_section_data (struct lto_file_decl_data
*,
763 enum lto_section_type
,
764 const char *, size_t *);
765 extern void lto_free_section_data (struct lto_file_decl_data
*,
766 enum lto_section_type
,
767 const char *, const char *, size_t);
768 extern htab_t
lto_create_renaming_table (void);
769 extern void lto_record_renamed_decl (struct lto_file_decl_data
*,
770 const char *, const char *);
771 extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data
*,
773 extern struct lto_in_decl_state
*lto_new_in_decl_state (void);
774 extern void lto_delete_in_decl_state (struct lto_in_decl_state
*);
775 extern struct lto_in_decl_state
*lto_get_function_in_decl_state (
776 struct lto_file_decl_data
*, tree
);
777 extern void lto_free_function_in_decl_state (struct lto_in_decl_state
*);
778 extern void lto_free_function_in_decl_state_for_node (symtab_node
*);
779 extern void lto_section_overrun (struct lto_input_block
*) ATTRIBUTE_NORETURN
;
780 extern void lto_value_range_error (const char *,
781 HOST_WIDE_INT
, HOST_WIDE_INT
,
782 HOST_WIDE_INT
) ATTRIBUTE_NORETURN
;
784 /* In lto-section-out.c */
785 extern void lto_begin_section (const char *, bool);
786 extern void lto_end_section (void);
787 extern void lto_write_data (const void *, unsigned int);
788 extern void lto_write_stream (struct lto_output_stream
*);
789 extern bool lto_output_decl_index (struct lto_output_stream
*,
790 struct lto_tree_ref_encoder
*,
791 tree
, unsigned int *);
792 extern void lto_output_field_decl_index (struct lto_out_decl_state
*,
793 struct lto_output_stream
*, tree
);
794 extern void lto_output_fn_decl_index (struct lto_out_decl_state
*,
795 struct lto_output_stream
*, tree
);
796 extern void lto_output_namespace_decl_index (struct lto_out_decl_state
*,
797 struct lto_output_stream
*, tree
);
798 extern void lto_output_var_decl_index (struct lto_out_decl_state
*,
799 struct lto_output_stream
*, tree
);
800 extern void lto_output_type_decl_index (struct lto_out_decl_state
*,
801 struct lto_output_stream
*, tree
);
802 extern void lto_output_type_ref_index (struct lto_out_decl_state
*,
803 struct lto_output_stream
*, tree
);
804 extern struct lto_simple_output_block
*lto_create_simple_output_block (
805 enum lto_section_type
);
806 extern void lto_destroy_simple_output_block (struct lto_simple_output_block
*);
807 extern struct lto_out_decl_state
*lto_new_out_decl_state (void);
808 extern void lto_delete_out_decl_state (struct lto_out_decl_state
*);
809 extern struct lto_out_decl_state
*lto_get_out_decl_state (void);
810 extern void lto_push_out_decl_state (struct lto_out_decl_state
*);
811 extern struct lto_out_decl_state
*lto_pop_out_decl_state (void);
812 extern void lto_record_function_out_decl_state (tree
,
813 struct lto_out_decl_state
*);
814 extern void lto_append_block (struct lto_output_stream
*);
817 /* In lto-streamer.c. */
819 /* Set when streaming LTO for offloading compiler. */
820 extern bool lto_stream_offload_p
;
822 extern const char *lto_tag_name (enum LTO_tags
);
823 extern bitmap
lto_bitmap_alloc (void);
824 extern void lto_bitmap_free (bitmap
);
825 extern char *lto_get_section_name (int, const char *, struct lto_file_decl_data
*);
826 extern void print_lto_report (const char *);
827 extern void lto_streamer_init (void);
828 extern bool gate_lto_out (void);
829 #ifdef LTO_STREAMER_DEBUG
830 extern void lto_orig_address_map (tree
, intptr_t);
831 extern intptr_t lto_orig_address_get (tree
);
832 extern void lto_orig_address_remove (tree
);
834 extern void lto_check_version (int, int);
835 extern void lto_streamer_hooks_init (void);
837 /* In lto-streamer-in.c */
838 extern void lto_input_cgraph (struct lto_file_decl_data
*, const char *);
839 extern void lto_reader_init (void);
840 extern void lto_input_function_body (struct lto_file_decl_data
*,
841 struct cgraph_node
*,
843 extern void lto_input_variable_constructor (struct lto_file_decl_data
*,
844 struct varpool_node
*,
846 extern void lto_input_constructors_and_inits (struct lto_file_decl_data
*,
848 extern void lto_input_toplevel_asms (struct lto_file_decl_data
*, int);
849 extern void lto_input_mode_table (struct lto_file_decl_data
*);
850 extern struct data_in
*lto_data_in_create (struct lto_file_decl_data
*,
851 const char *, unsigned,
852 vec
<ld_plugin_symbol_resolution_t
> );
853 extern void lto_data_in_delete (struct data_in
*);
854 extern void lto_input_data_block (struct lto_input_block
*, void *, size_t);
855 void lto_input_location (location_t
*, struct bitpack_d
*, struct data_in
*);
856 location_t
stream_input_location_now (struct bitpack_d
*bp
,
857 struct data_in
*data
);
858 tree
lto_input_tree_ref (struct lto_input_block
*, struct data_in
*,
859 struct function
*, enum LTO_tags
);
860 void lto_tag_check_set (enum LTO_tags
, int, ...);
861 void lto_init_eh (void);
862 hashval_t
lto_input_scc (struct lto_input_block
*, struct data_in
*,
863 unsigned *, unsigned *);
864 tree
lto_input_tree_1 (struct lto_input_block
*, struct data_in
*,
865 enum LTO_tags
, hashval_t hash
);
866 tree
lto_input_tree (struct lto_input_block
*, struct data_in
*);
869 /* In lto-streamer-out.c */
870 extern void lto_register_decl_definition (tree
, struct lto_file_decl_data
*);
871 extern struct output_block
*create_output_block (enum lto_section_type
);
872 extern void destroy_output_block (struct output_block
*);
873 extern void lto_output_tree (struct output_block
*, tree
, bool, bool);
874 extern void lto_output_toplevel_asms (void);
875 extern void produce_asm (struct output_block
*ob
, tree fn
);
876 extern void lto_output ();
877 extern void produce_asm_for_decls ();
878 void lto_output_decl_state_streams (struct output_block
*,
879 struct lto_out_decl_state
*);
880 void lto_output_decl_state_refs (struct output_block
*,
881 struct lto_output_stream
*,
882 struct lto_out_decl_state
*);
883 void lto_output_location (struct output_block
*, struct bitpack_d
*, location_t
);
884 void lto_output_init_mode_table (void);
887 /* In lto-cgraph.c */
888 extern bool asm_nodes_output
;
889 lto_symtab_encoder_t
lto_symtab_encoder_new (bool);
890 int lto_symtab_encoder_encode (lto_symtab_encoder_t
, symtab_node
*);
891 void lto_symtab_encoder_delete (lto_symtab_encoder_t
);
892 bool lto_symtab_encoder_delete_node (lto_symtab_encoder_t
, symtab_node
*);
893 bool lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t
,
894 struct cgraph_node
*);
895 bool lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t
,
897 void lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t
,
900 bool lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t
,
902 void output_symtab (void);
903 void input_symtab (void);
904 void output_offload_tables (void);
905 void input_offload_tables (void);
906 bool referenced_from_other_partition_p (struct ipa_ref_list
*,
907 lto_symtab_encoder_t
);
908 bool reachable_from_other_partition_p (struct cgraph_node
*,
909 lto_symtab_encoder_t
);
910 bool referenced_from_this_partition_p (symtab_node
*,
911 lto_symtab_encoder_t
);
912 bool reachable_from_this_partition_p (struct cgraph_node
*,
913 lto_symtab_encoder_t
);
914 lto_symtab_encoder_t
compute_ltrans_boundary (lto_symtab_encoder_t encoder
);
915 void select_what_to_stream (void);
917 /* In options-save.c. */
918 void cl_target_option_stream_out (struct output_block
*, struct bitpack_d
*,
919 struct cl_target_option
*);
921 void cl_target_option_stream_in (struct data_in
*,
923 struct cl_target_option
*);
925 void cl_optimization_stream_out (struct bitpack_d
*, struct cl_optimization
*);
927 void cl_optimization_stream_in (struct bitpack_d
*, struct cl_optimization
*);
932 extern void lto_write_options (void);
935 /* Statistics gathered during LTO, WPA and LTRANS. */
936 extern struct lto_stats_d lto_stats
;
938 /* Section names corresponding to the values of enum lto_section_type. */
939 extern const char *lto_section_name
[];
941 /* Holds all the out decl states of functions output so far in the
942 current output file. */
943 extern vec
<lto_out_decl_state_ptr
> lto_function_decl_states
;
945 /* Return true if LTO tag TAG corresponds to a tree code. */
947 lto_tag_is_tree_code_p (enum LTO_tags tag
)
949 return tag
> LTO_tree_pickle_reference
&& (unsigned) tag
<= MAX_TREE_CODES
;
953 /* Return true if LTO tag TAG corresponds to a gimple code. */
955 lto_tag_is_gimple_code_p (enum LTO_tags tag
)
957 return (unsigned) tag
>= NUM_TREE_CODES
+ 2
958 && (unsigned) tag
< 2 + NUM_TREE_CODES
+ LAST_AND_UNUSED_GIMPLE_CODE
;
962 /* Return the LTO tag corresponding to gimple code CODE. See enum
963 LTO_tags for details on the conversion. */
964 static inline enum LTO_tags
965 lto_gimple_code_to_tag (enum gimple_code code
)
967 return (enum LTO_tags
) ((unsigned) code
+ NUM_TREE_CODES
+ 2);
971 /* Return the GIMPLE code corresponding to TAG. See enum LTO_tags for
972 details on the conversion. */
973 static inline enum gimple_code
974 lto_tag_to_gimple_code (enum LTO_tags tag
)
976 gcc_assert (lto_tag_is_gimple_code_p (tag
));
977 return (enum gimple_code
) ((unsigned) tag
- NUM_TREE_CODES
- 2);
981 /* Return the LTO tag corresponding to tree code CODE. See enum
982 LTO_tags for details on the conversion. */
983 static inline enum LTO_tags
984 lto_tree_code_to_tag (enum tree_code code
)
986 return (enum LTO_tags
) ((unsigned) code
+ 2);
990 /* Return the tree code corresponding to TAG. See enum LTO_tags for
991 details on the conversion. */
992 static inline enum tree_code
993 lto_tag_to_tree_code (enum LTO_tags tag
)
995 gcc_assert (lto_tag_is_tree_code_p (tag
));
996 return (enum tree_code
) ((unsigned) tag
- 2);
999 /* Check that tag ACTUAL == EXPECTED. */
1001 lto_tag_check (enum LTO_tags actual
, enum LTO_tags expected
)
1003 if (actual
!= expected
)
1004 internal_error ("bytecode stream: expected tag %s instead of %s",
1005 lto_tag_name (expected
), lto_tag_name (actual
));
1008 /* Check that tag ACTUAL is in the range [TAG1, TAG2]. */
1010 lto_tag_check_range (enum LTO_tags actual
, enum LTO_tags tag1
,
1013 if (actual
< tag1
|| actual
> tag2
)
1014 internal_error ("bytecode stream: tag %s is not in the expected range "
1016 lto_tag_name (actual
),
1017 lto_tag_name (tag1
),
1018 lto_tag_name (tag2
));
1021 /* Initialize an lto_out_decl_buffer ENCODER. */
1023 lto_init_tree_ref_encoder (struct lto_tree_ref_encoder
*encoder
)
1025 encoder
->tree_hash_table
= new hash_map
<tree
, unsigned> (251);
1026 encoder
->trees
.create (0);
1030 /* Destroy an lto_tree_ref_encoder ENCODER by freeing its contents. The
1031 memory used by ENCODER is not freed by this function. */
1033 lto_destroy_tree_ref_encoder (struct lto_tree_ref_encoder
*encoder
)
1035 /* Hash table may be delete already. */
1036 delete encoder
->tree_hash_table
;
1037 encoder
->tree_hash_table
= NULL
;
1038 encoder
->trees
.release ();
1041 /* Return the number of trees encoded in ENCODER. */
1042 static inline unsigned int
1043 lto_tree_ref_encoder_size (struct lto_tree_ref_encoder
*encoder
)
1045 return encoder
->trees
.length ();
1048 /* Return the IDX-th tree in ENCODER. */
1050 lto_tree_ref_encoder_get_tree (struct lto_tree_ref_encoder
*encoder
,
1053 return encoder
->trees
[idx
];
1056 /* Return number of encoded nodes in ENCODER. */
1058 lto_symtab_encoder_size (lto_symtab_encoder_t encoder
)
1060 return encoder
->nodes
.length ();
1063 /* Value used to represent failure of lto_symtab_encoder_lookup. */
1064 #define LCC_NOT_FOUND (-1)
1066 /* Look up NODE in encoder. Return NODE's reference if it has been encoded
1067 or LCC_NOT_FOUND if it is not there. */
1070 lto_symtab_encoder_lookup (lto_symtab_encoder_t encoder
,
1073 size_t *slot
= encoder
->map
->get (node
);
1074 return (slot
&& *slot
? *(slot
) - 1 : LCC_NOT_FOUND
);
1077 /* Return true if iterator LSE points to nothing. */
1079 lsei_end_p (lto_symtab_encoder_iterator lsei
)
1081 return lsei
.index
>= (unsigned)lto_symtab_encoder_size (lsei
.encoder
);
1084 /* Advance iterator LSE. */
1086 lsei_next (lto_symtab_encoder_iterator
*lsei
)
1091 /* Return the node pointed to by LSI. */
1092 static inline symtab_node
*
1093 lsei_node (lto_symtab_encoder_iterator lsei
)
1095 return lsei
.encoder
->nodes
[lsei
.index
].node
;
1098 /* Return the node pointed to by LSI. */
1099 static inline struct cgraph_node
*
1100 lsei_cgraph_node (lto_symtab_encoder_iterator lsei
)
1102 return dyn_cast
<cgraph_node
*> (lsei
.encoder
->nodes
[lsei
.index
].node
);
1105 /* Return the node pointed to by LSI. */
1106 static inline varpool_node
*
1107 lsei_varpool_node (lto_symtab_encoder_iterator lsei
)
1109 return dyn_cast
<varpool_node
*> (lsei
.encoder
->nodes
[lsei
.index
].node
);
1112 /* Return the cgraph node corresponding to REF using ENCODER. */
1114 static inline symtab_node
*
1115 lto_symtab_encoder_deref (lto_symtab_encoder_t encoder
, int ref
)
1117 if (ref
== LCC_NOT_FOUND
)
1120 return encoder
->nodes
[ref
].node
;
1123 /* Return an iterator to the first node in LSI. */
1124 static inline lto_symtab_encoder_iterator
1125 lsei_start (lto_symtab_encoder_t encoder
)
1127 lto_symtab_encoder_iterator lsei
;
1129 lsei
.encoder
= encoder
;
1134 /* Advance iterator LSE. */
1136 lsei_next_in_partition (lto_symtab_encoder_iterator
*lsei
)
1139 while (!lsei_end_p (*lsei
)
1140 && !lto_symtab_encoder_in_partition_p (lsei
->encoder
, lsei_node (*lsei
)))
1144 /* Return an iterator to the first node in LSI. */
1145 static inline lto_symtab_encoder_iterator
1146 lsei_start_in_partition (lto_symtab_encoder_t encoder
)
1148 lto_symtab_encoder_iterator lsei
= lsei_start (encoder
);
1150 if (lsei_end_p (lsei
))
1152 if (!lto_symtab_encoder_in_partition_p (encoder
, lsei_node (lsei
)))
1153 lsei_next_in_partition (&lsei
);
1158 /* Advance iterator LSE. */
1160 lsei_next_function_in_partition (lto_symtab_encoder_iterator
*lsei
)
1163 while (!lsei_end_p (*lsei
)
1164 && (!is_a
<cgraph_node
*> (lsei_node (*lsei
))
1165 || !lto_symtab_encoder_in_partition_p (lsei
->encoder
, lsei_node (*lsei
))))
1169 /* Return an iterator to the first node in LSI. */
1170 static inline lto_symtab_encoder_iterator
1171 lsei_start_function_in_partition (lto_symtab_encoder_t encoder
)
1173 lto_symtab_encoder_iterator lsei
= lsei_start (encoder
);
1175 if (lsei_end_p (lsei
))
1177 if (!is_a
<cgraph_node
*> (lsei_node (lsei
))
1178 || !lto_symtab_encoder_in_partition_p (encoder
, lsei_node (lsei
)))
1179 lsei_next_function_in_partition (&lsei
);
1184 /* Advance iterator LSE. */
1186 lsei_next_variable_in_partition (lto_symtab_encoder_iterator
*lsei
)
1189 while (!lsei_end_p (*lsei
)
1190 && (!is_a
<varpool_node
*> (lsei_node (*lsei
))
1191 || !lto_symtab_encoder_in_partition_p (lsei
->encoder
, lsei_node (*lsei
))))
1195 /* Return an iterator to the first node in LSI. */
1196 static inline lto_symtab_encoder_iterator
1197 lsei_start_variable_in_partition (lto_symtab_encoder_t encoder
)
1199 lto_symtab_encoder_iterator lsei
= lsei_start (encoder
);
1201 if (lsei_end_p (lsei
))
1203 if (!is_a
<varpool_node
*> (lsei_node (lsei
))
1204 || !lto_symtab_encoder_in_partition_p (encoder
, lsei_node (lsei
)))
1205 lsei_next_variable_in_partition (&lsei
);
1210 DEFINE_DECL_STREAM_FUNCS (TYPE
, type
)
1211 DEFINE_DECL_STREAM_FUNCS (FIELD_DECL
, field_decl
)
1212 DEFINE_DECL_STREAM_FUNCS (FN_DECL
, fn_decl
)
1213 DEFINE_DECL_STREAM_FUNCS (VAR_DECL
, var_decl
)
1214 DEFINE_DECL_STREAM_FUNCS (TYPE_DECL
, type_decl
)
1215 DEFINE_DECL_STREAM_FUNCS (NAMESPACE_DECL
, namespace_decl
)
1216 DEFINE_DECL_STREAM_FUNCS (LABEL_DECL
, label_decl
)
1218 #endif /* GCC_LTO_STREAMER_H */