1 /* Data structures and declarations used for reading and writing
2 GIMPLE to a file stream.
4 Copyright (C) 2009-2013 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"
27 #include "hash-table.h"
33 #include "alloc-pool.h"
35 #include "diagnostic.h"
37 /* Define when debugging the LTO streamer. This causes the writer
38 to output the numeric value for the memory address of the tree node
39 being emitted. When debugging a problem in the reader, check the
40 original address that the writer was emitting using lto_orig_address_get.
41 With this value, set a breakpoint in the writer (e.g., lto_output_tree)
42 to trace how the faulty node is being emitted. */
43 /* #define LTO_STREAMER_DEBUG 1 */
45 /* The encoding for a function consists of the following sections:
53 7) Names for the labels that have names
55 9) The control flow graph.
56 10-11)Gimple for local decls.
57 12) Gimple for the function.
61 2-6) THE GLOBAL DECLS AND TYPES.
63 The global decls and types are encoded in the same way. For each
64 entry, there is word with the offset within the section to the
69 Since most labels do not have names, this section my be of zero
70 length. It consists of an array of string table references, one
71 per label. In the lto code, the labels are given either
72 positive or negative indexes. the positive ones have names and
73 the negative ones do not. The positive index can be used to
74 find the name in this array.
78 10) Index into the local decls. Since local decls can have local
79 decls inside them, they must be read in randomly in order to
80 properly restore them.
82 11-12) GIMPLE FOR THE LOCAL DECLS AND THE FUNCTION BODY.
84 The gimple consists of a set of records.
88 At the top level of (8) is the function. It consists of five
91 LTO_function - The tag.
92 eh tree - This is all of the exception handling regions
93 put out in a post order traversial of the
94 tree. Siblings are output as lists terminated
95 by a 0. The set of fields matches the fields
98 last_basic_block - in uleb128 form.
100 basic blocks - This is the set of basic blocks.
102 zero - The termination of the basic blocks.
106 There are two forms of basic blocks depending on if they are
109 The basic block consists of:
111 LTO_bb1 or LTO_bb0 - The tag.
113 bb->index - the index in uleb128 form.
115 #succs - The number of successors un uleb128 form.
117 the successors - For each edge, a pair. The first of the
118 pair is the index of the successor in
119 uleb128 form and the second are the flags in
122 the statements - A gimple tree, as described above.
123 These are only present for LTO_BB1.
124 Following each statement is an optional
125 exception handling record LTO_eh_region
126 which contains the region number (for
129 zero - This is only present for LTO_BB1 and is used
130 to terminate the statements and exception
131 regions within this block.
135 String are represented in the table as pairs, a length in ULEB128
136 form followed by the data for the string. */
138 /* The string that is the prefix on the section names we make for lto.
139 For decls the DECL_ASSEMBLER_NAME is appended to make the section
140 name for the functions and static_initializers. For other types of
141 sections a '.' and the section type are appended. */
142 #define LTO_SECTION_NAME_PREFIX ".gnu.lto_"
144 #define LTO_major_version 2
145 #define LTO_minor_version 2
147 typedef unsigned char lto_decl_flags_t
;
150 /* Tags representing the various IL objects written to the bytecode file
151 (GIMPLE statements, basic blocks, EH regions, tree nodes, etc).
153 NOTE, when adding new LTO tags, also update lto_tag_name. */
158 /* Special for streamer. Reference to previously-streamed node. */
159 LTO_tree_pickle_reference
,
161 /* Reserve enough entries to fit all the tree and gimple codes handled
162 by the streamer. This guarantees that:
164 1- Given a tree code C:
165 enum LTO_tags tag == C + 1
167 2- Given a gimple code C:
168 enum LTO_tags tag == C + NUM_TREE_CODES + 1
170 Conversely, to map between LTO tags and tree/gimple codes, the
171 reverse operation must be applied. */
172 LTO_bb0
= 1 + MAX_TREE_CODES
+ LAST_AND_UNUSED_GIMPLE_CODE
,
175 /* EH region holding the previous statement. */
178 /* An MD or NORMAL builtin. Only the code and class are streamed out. */
181 /* Shared INTEGER_CST node. */
190 /* EH region types. These mirror enum eh_region_type. */
193 LTO_ert_allowed_exceptions
,
194 LTO_ert_must_not_throw
,
196 /* EH landing pad. */
199 /* EH try/catch node. */
202 /* Special for global streamer. A blob of unnamed tree nodes. */
205 /* References to indexable tree nodes. These objects are stored in
206 tables that are written separately from the function bodies that
207 reference them. This way they can be instantiated even when the
208 referencing functions aren't (e.g., during WPA) and it also allows
209 functions to be copied from one file to another without having
210 to unpickle the body first (the references are location
213 NOTE, do not regroup these values as the grouping is exposed
214 in the range checks done in lto_input_tree. */
215 LTO_field_decl_ref
, /* Do not change. */
216 LTO_function_decl_ref
,
218 LTO_namespace_decl_ref
,
224 LTO_imported_decl_ref
,
225 LTO_translation_unit_decl_ref
,
226 LTO_global_decl_ref
, /* Do not change. */
228 /* This tag must always be last. */
233 /* Set of section types that are in an LTO file. This list will grow
234 as the number of IPA passes grows since each IPA pass will need its
235 own section type to store its summary information.
237 When adding a new section type, you must also extend the
238 LTO_SECTION_NAME array in lto-section-in.c. */
239 enum lto_section_type
241 LTO_section_decls
= 0,
242 LTO_section_function_body
,
243 LTO_section_static_initializer
,
247 LTO_section_jump_functions
,
248 LTO_section_ipa_pure_const
,
249 LTO_section_ipa_reference
,
250 LTO_section_ipa_profile
,
251 LTO_section_symtab_nodes
,
253 LTO_section_cgraph_opt_sum
,
254 LTO_section_inline_summary
,
255 LTO_section_ipcp_transform
,
256 LTO_N_SECTION_TYPES
/* Must be last. */
259 /* Indices to the various function, type and symbol streams. */
262 LTO_DECL_STREAM_TYPE
= 0, /* Must be first. */
263 LTO_DECL_STREAM_FIELD_DECL
,
264 LTO_DECL_STREAM_FN_DECL
,
265 LTO_DECL_STREAM_VAR_DECL
,
266 LTO_DECL_STREAM_TYPE_DECL
,
267 LTO_DECL_STREAM_NAMESPACE_DECL
,
268 LTO_DECL_STREAM_LABEL_DECL
,
270 } lto_decl_stream_e_t
;
272 typedef enum ld_plugin_symbol_resolution ld_plugin_symbol_resolution_t
;
275 /* Macro to define convenience functions for type and decl streams
276 in lto_file_decl_data. */
277 #define DEFINE_DECL_STREAM_FUNCS(UPPER_NAME, name) \
279 lto_file_decl_data_get_ ## name (struct lto_file_decl_data *data, \
282 struct lto_in_decl_state *state = data->current_decl_state; \
283 gcc_assert (idx < state->streams[LTO_DECL_STREAM_## UPPER_NAME].size); \
284 return state->streams[LTO_DECL_STREAM_## UPPER_NAME].trees[idx]; \
287 static inline unsigned int \
288 lto_file_decl_data_num_ ## name ## s (struct lto_file_decl_data *data) \
290 struct lto_in_decl_state *state = data->current_decl_state; \
291 return state->streams[LTO_DECL_STREAM_## UPPER_NAME].size; \
295 /* Return a char pointer to the start of a data stream for an lto pass
296 or function. The first parameter is the file data that contains
297 the information. The second parameter is the type of information
298 to be obtained. The third parameter is the name of the function
299 and is only used when finding a function body; otherwise it is
300 NULL. The fourth parameter is the length of the data returned. */
301 typedef const char* (lto_get_section_data_f
) (struct lto_file_decl_data
*,
302 enum lto_section_type
,
306 /* Return the data found from the above call. The first three
307 parameters are the same as above. The fourth parameter is the data
308 itself and the fifth is the length of the data. */
309 typedef void (lto_free_section_data_f
) (struct lto_file_decl_data
*,
310 enum lto_section_type
,
315 /* Structure used as buffer for reading an LTO file. */
316 struct lto_input_block
323 #define LTO_INIT_INPUT_BLOCK(BASE,D,P,L) \
330 #define LTO_INIT_INPUT_BLOCK_PTR(BASE,D,P,L) \
338 /* The is the first part of the record for a function or constructor
342 int16_t major_version
;
343 int16_t minor_version
;
346 /* The header for a function body. */
347 struct lto_function_header
349 /* The header for all types of sections. */
350 struct lto_header lto_header
;
352 /* Number of labels with names. */
353 int32_t num_named_labels
;
355 /* Number of labels without names. */
356 int32_t num_unnamed_labels
;
358 /* Size compressed or 0 if not compressed. */
359 int32_t compressed_size
;
361 /* Size of names for named labels. */
362 int32_t named_label_size
;
364 /* Size of the cfg. */
367 /* Size of main gimple body of function. */
370 /* Size of the string table. */
375 /* Structure describing a symbol section. */
376 struct lto_decl_header
378 /* The header for all types of sections. */
379 struct lto_header lto_header
;
381 /* Size of region for decl state. */
382 int32_t decl_state_size
;
384 /* Number of nodes in globals stream. */
387 /* Size of region for expressions, decls, types, etc. */
390 /* Size of the string table. */
395 /* Structure describing top level asm()s. */
396 struct lto_asm_header
398 /* The header for all types of sections. */
399 struct lto_header lto_header
;
401 /* Size compressed or 0 if not compressed. */
402 int32_t compressed_size
;
404 /* Size of region for expressions, decls, types, etc. */
407 /* Size of the string table. */
412 /* Statistics gathered during LTO, WPA and LTRANS. */
415 unsigned HOST_WIDE_INT num_input_cgraph_nodes
;
416 unsigned HOST_WIDE_INT num_output_symtab_nodes
;
417 unsigned HOST_WIDE_INT num_input_files
;
418 unsigned HOST_WIDE_INT num_output_files
;
419 unsigned HOST_WIDE_INT num_cgraph_partitions
;
420 unsigned HOST_WIDE_INT section_size
[LTO_N_SECTION_TYPES
];
421 unsigned HOST_WIDE_INT num_function_bodies
;
422 unsigned HOST_WIDE_INT num_trees
[NUM_TREE_CODES
];
423 unsigned HOST_WIDE_INT num_output_il_bytes
;
424 unsigned HOST_WIDE_INT num_compressed_il_bytes
;
425 unsigned HOST_WIDE_INT num_input_il_bytes
;
426 unsigned HOST_WIDE_INT num_uncompressed_il_bytes
;
427 unsigned HOST_WIDE_INT num_tree_bodies_output
;
428 unsigned HOST_WIDE_INT num_pickle_refs_output
;
431 /* Entry of LTO symtab encoder. */
435 /* Is the node in this partition (i.e. ltrans of this partition will
436 be responsible for outputting it)? */
437 unsigned int in_partition
:1;
438 /* Do we encode body in this partition? */
440 /* Do we encode initializer in this partition?
441 For example the readonly variable initializers are encoded to aid
442 constant folding even if they are not in the partition. */
443 unsigned int initializer
:1;
447 /* Encoder data structure used to stream callgraph nodes. */
448 struct lto_symtab_encoder_d
450 vec
<lto_encoder_entry
> nodes
;
454 typedef struct lto_symtab_encoder_d
*lto_symtab_encoder_t
;
456 /* Iterator structure for cgraph node sets. */
459 lto_symtab_encoder_t encoder
;
461 } lto_symtab_encoder_iterator
;
466 /* Mapping from indices to trees. */
467 struct GTY(()) lto_tree_ref_table
469 /* Array of referenced trees . */
470 tree
* GTY((length ("%h.size"))) trees
;
477 /* Mapping between trees and slots in an array. */
485 /* The lto_tree_ref_encoder struct is used to encode trees into indices. */
487 struct lto_tree_ref_encoder
489 htab_t tree_hash_table
; /* Maps pointers to indices. */
490 unsigned int next_index
; /* Next available index. */
491 vec
<tree
> trees
; /* Maps indices to pointers. */
495 /* Structure to hold states of input scope. */
496 struct GTY(()) lto_in_decl_state
498 /* Array of lto_in_decl_buffers to store type and decls streams. */
499 struct lto_tree_ref_table streams
[LTO_N_DECL_STREAMS
];
501 /* If this in-decl state is associated with a function. FN_DECL
502 point to the FUNCTION_DECL. */
506 typedef struct lto_in_decl_state
*lto_in_decl_state_ptr
;
509 /* The structure that holds all of the vectors of global types,
510 decls and cgraph nodes used in the serialization of this file. */
511 struct lto_out_decl_state
513 /* The buffers contain the sets of decls of various kinds and types we have
514 seen so far and the indexes assigned to them. */
515 struct lto_tree_ref_encoder streams
[LTO_N_DECL_STREAMS
];
517 /* Encoder for cgraph nodes. */
518 lto_symtab_encoder_t symtab_node_encoder
;
520 /* If this out-decl state belongs to a function, fn_decl points to that
521 function. Otherwise, it is NULL. */
525 typedef struct lto_out_decl_state
*lto_out_decl_state_ptr
;
528 /* Compact representation of a index <-> resolution pair. Unpacked to an
532 ld_plugin_symbol_resolution_t res
;
535 typedef struct res_pair res_pair
;
538 /* One of these is allocated for each object file that being compiled
539 by lto. This structure contains the tables that are needed by the
540 serialized functions and ipa passes to connect themselves to the
541 global types and decls as they are reconstituted. */
542 struct GTY(()) lto_file_decl_data
544 /* Decl state currently used. */
545 struct lto_in_decl_state
*current_decl_state
;
547 /* Decl state corresponding to regions outside of any functions
548 in the compilation unit. */
549 struct lto_in_decl_state
*global_decl_state
;
551 /* Table of cgraph nodes present in this file. */
552 lto_symtab_encoder_t
GTY((skip
)) symtab_node_encoder
;
554 /* Hash table maps lto-related section names to location in file. */
555 htab_t
GTY((param_is (struct lto_in_decl_state
))) function_decl_states
;
557 /* The .o file that these offsets relate to. */
558 const char *GTY((skip
)) file_name
;
560 /* Hash table maps lto-related section names to location in file. */
561 htab_t
GTY((skip
)) section_hash_table
;
563 /* Hash new name of renamed global declaration to its original name. */
564 htab_t
GTY((skip
)) renaming_hash_table
;
566 /* Linked list used temporarily in reader */
567 struct lto_file_decl_data
*next
;
569 /* Sub ID for merged objects. */
570 unsigned HOST_WIDE_INT id
;
572 /* Symbol resolutions for this file */
573 vec
<res_pair
> GTY((skip
)) respairs
;
576 struct gcov_ctr_summary
GTY((skip
)) profile_info
;
578 /* Map assigning declarations their resolutions. */
579 pointer_map_t
* GTY((skip
)) resolution_map
;
582 typedef struct lto_file_decl_data
*lto_file_decl_data_ptr
;
584 struct lto_char_ptr_base
589 /* An incore byte stream to buffer the various parts of the function.
590 The entire structure should be zeroed when created. The record
591 consists of a set of blocks. The first sizeof (ptr) bytes are used
592 as a chain, and the rest store the bytes to be written. */
593 struct lto_output_stream
595 /* The pointer to the first block in the stream. */
596 struct lto_char_ptr_base
* first_block
;
598 /* The pointer to the last and current block in the stream. */
599 struct lto_char_ptr_base
* current_block
;
601 /* The pointer to where the next char should be written. */
602 char * current_pointer
;
604 /* The number of characters left in the current block. */
605 unsigned int left_in_block
;
607 /* The block size of the last block allocated. */
608 unsigned int block_size
;
610 /* The total number of characters written. */
611 unsigned int total_size
;
614 /* The is the first part of the record in an LTO file for many of the
616 struct lto_simple_header
618 /* The header for all types of sections. */
619 struct lto_header lto_header
;
621 /* Size of main gimple body of function. */
624 /* Size of main stream when compressed. */
625 int32_t compressed_size
;
628 /* A simple output block. This can be used for simple IPA passes that
629 do not need more than one stream. */
630 struct lto_simple_output_block
632 enum lto_section_type section_type
;
633 struct lto_out_decl_state
*decl_state
;
635 /* The stream that the main tree codes are written to. */
636 struct lto_output_stream
*main_stream
;
639 /* String hashing. */
645 unsigned int slot_num
;
648 /* Hashtable helpers. */
650 struct string_slot_hasher
: typed_noop_remove
<string_slot
>
652 typedef string_slot value_type
;
653 typedef string_slot compare_type
;
654 static inline hashval_t
hash (const value_type
*);
655 static inline bool equal (const value_type
*, const compare_type
*);
658 /* Returns a hash code for DS. Adapted from libiberty's htab_hash_string
659 to support strings that may not end in '\0'. */
662 string_slot_hasher::hash (const value_type
*ds
)
664 hashval_t r
= ds
->len
;
667 for (i
= 0; i
< ds
->len
; i
++)
668 r
= r
* 67 + (unsigned)ds
->s
[i
] - 113;
672 /* Returns nonzero if DS1 and DS2 are equal. */
675 string_slot_hasher::equal (const value_type
*ds1
, const compare_type
*ds2
)
677 if (ds1
->len
== ds2
->len
)
678 return memcmp (ds1
->s
, ds2
->s
, ds1
->len
) == 0;
683 /* Data structure holding all the data and descriptors used when writing
687 enum lto_section_type section_type
;
688 struct lto_out_decl_state
*decl_state
;
690 /* The stream that the main tree codes are written to. */
691 struct lto_output_stream
*main_stream
;
693 /* The stream that contains the string table. */
694 struct lto_output_stream
*string_stream
;
696 /* The stream that contains the cfg. */
697 struct lto_output_stream
*cfg_stream
;
699 /* The hash table that contains the set of strings we have seen so
700 far and the indexes assigned to them. */
701 hash_table
<string_slot_hasher
> string_hash_table
;
703 /* The current cgraph_node that we are currently serializing. Null
704 if we are serializing something else. */
705 struct cgraph_node
*cgraph_node
;
707 /* These are the last file and line that were seen in the stream.
708 If the current node differs from these, it needs to insert
709 something into the stream and fix these up. */
710 const char *current_file
;
714 /* True if writing globals and types. */
717 /* Cache of nodes written in this section. */
718 struct streamer_tree_cache_d
*writer_cache
;
720 /* All data persistent across whole duration of output block
722 struct obstack obstack
;
726 /* Data and descriptors used when reading from an LTO file. */
729 /* The global decls and types. */
730 struct lto_file_decl_data
*file_data
;
732 /* All of the labels. */
735 /* The string table. */
738 /* The length of the string table. */
739 unsigned int strings_len
;
741 /* Number of named labels. Used to find the index of unnamed labels
742 since they share space with the named labels. */
743 unsigned int num_named_labels
;
745 /* Number of unnamed labels. */
746 unsigned int num_unnamed_labels
;
748 /* Maps each reference number to the resolution done by the linker. */
749 vec
<ld_plugin_symbol_resolution_t
> globals_resolution
;
751 /* Cache of pickled nodes. */
752 struct streamer_tree_cache_d
*reader_cache
;
756 /* In lto-section-in.c */
757 extern struct lto_input_block
* lto_create_simple_input_block (
758 struct lto_file_decl_data
*,
759 enum lto_section_type
, const char **, size_t *);
761 lto_destroy_simple_input_block (struct lto_file_decl_data
*,
762 enum lto_section_type
,
763 struct lto_input_block
*, const char *, size_t);
764 extern void lto_set_in_hooks (struct lto_file_decl_data
**,
765 lto_get_section_data_f
*,
766 lto_free_section_data_f
*);
767 extern struct lto_file_decl_data
**lto_get_file_decl_data (void);
768 extern const char *lto_get_section_data (struct lto_file_decl_data
*,
769 enum lto_section_type
,
770 const char *, size_t *);
771 extern void lto_free_section_data (struct lto_file_decl_data
*,
772 enum lto_section_type
,
773 const char *, const char *, size_t);
774 extern htab_t
lto_create_renaming_table (void);
775 extern void lto_record_renamed_decl (struct lto_file_decl_data
*,
776 const char *, const char *);
777 extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data
*,
779 extern struct lto_in_decl_state
*lto_new_in_decl_state (void);
780 extern void lto_delete_in_decl_state (struct lto_in_decl_state
*);
781 extern hashval_t
lto_hash_in_decl_state (const void *);
782 extern int lto_eq_in_decl_state (const void *, const void *);
783 extern struct lto_in_decl_state
*lto_get_function_in_decl_state (
784 struct lto_file_decl_data
*, tree
);
785 extern void lto_section_overrun (struct lto_input_block
*) ATTRIBUTE_NORETURN
;
786 extern void lto_value_range_error (const char *,
787 HOST_WIDE_INT
, HOST_WIDE_INT
,
788 HOST_WIDE_INT
) ATTRIBUTE_NORETURN
;
790 /* In lto-section-out.c */
791 extern hashval_t
lto_hash_decl_slot_node (const void *);
792 extern int lto_eq_decl_slot_node (const void *, const void *);
793 extern hashval_t
lto_hash_type_slot_node (const void *);
794 extern int lto_eq_type_slot_node (const void *, const void *);
795 extern void lto_begin_section (const char *, bool);
796 extern void lto_end_section (void);
797 extern void lto_write_stream (struct lto_output_stream
*);
798 extern void lto_output_data_stream (struct lto_output_stream
*, const void *,
800 extern bool lto_output_decl_index (struct lto_output_stream
*,
801 struct lto_tree_ref_encoder
*,
802 tree
, unsigned int *);
803 extern void lto_output_field_decl_index (struct lto_out_decl_state
*,
804 struct lto_output_stream
*, tree
);
805 extern void lto_output_fn_decl_index (struct lto_out_decl_state
*,
806 struct lto_output_stream
*, tree
);
807 extern void lto_output_namespace_decl_index (struct lto_out_decl_state
*,
808 struct lto_output_stream
*, tree
);
809 extern void lto_output_var_decl_index (struct lto_out_decl_state
*,
810 struct lto_output_stream
*, tree
);
811 extern void lto_output_type_decl_index (struct lto_out_decl_state
*,
812 struct lto_output_stream
*, tree
);
813 extern void lto_output_type_ref_index (struct lto_out_decl_state
*,
814 struct lto_output_stream
*, tree
);
815 extern struct lto_simple_output_block
*lto_create_simple_output_block (
816 enum lto_section_type
);
817 extern void lto_destroy_simple_output_block (struct lto_simple_output_block
*);
818 extern struct lto_out_decl_state
*lto_new_out_decl_state (void);
819 extern void lto_delete_out_decl_state (struct lto_out_decl_state
*);
820 extern struct lto_out_decl_state
*lto_get_out_decl_state (void);
821 extern void lto_push_out_decl_state (struct lto_out_decl_state
*);
822 extern struct lto_out_decl_state
*lto_pop_out_decl_state (void);
823 extern void lto_record_function_out_decl_state (tree
,
824 struct lto_out_decl_state
*);
825 extern void lto_append_block (struct lto_output_stream
*);
828 /* In lto-streamer.c. */
829 extern const char *lto_tag_name (enum LTO_tags
);
830 extern bitmap
lto_bitmap_alloc (void);
831 extern void lto_bitmap_free (bitmap
);
832 extern char *lto_get_section_name (int, const char *, struct lto_file_decl_data
*);
833 extern void print_lto_report (const char *);
834 extern void lto_streamer_init (void);
835 extern bool gate_lto_out (void);
836 #ifdef LTO_STREAMER_DEBUG
837 extern void lto_orig_address_map (tree
, intptr_t);
838 extern intptr_t lto_orig_address_get (tree
);
839 extern void lto_orig_address_remove (tree
);
841 extern void lto_check_version (int, int);
842 extern void lto_streamer_hooks_init (void);
844 /* In lto-streamer-in.c */
845 extern void lto_input_cgraph (struct lto_file_decl_data
*, const char *);
846 extern void lto_reader_init (void);
847 extern void lto_input_function_body (struct lto_file_decl_data
*, tree
,
849 extern void lto_input_constructors_and_inits (struct lto_file_decl_data
*,
851 extern void lto_input_toplevel_asms (struct lto_file_decl_data
*, int);
852 extern struct data_in
*lto_data_in_create (struct lto_file_decl_data
*,
853 const char *, unsigned,
854 vec
<ld_plugin_symbol_resolution_t
> );
855 extern void lto_data_in_delete (struct data_in
*);
856 extern void lto_input_data_block (struct lto_input_block
*, void *, size_t);
857 location_t
lto_input_location (struct bitpack_d
*, struct data_in
*);
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 void lto_output_decl_state_streams (struct output_block
*,
877 struct lto_out_decl_state
*);
878 void lto_output_decl_state_refs (struct output_block
*,
879 struct lto_output_stream
*,
880 struct lto_out_decl_state
*);
881 void lto_output_location (struct output_block
*, struct bitpack_d
*, location_t
);
884 /* In lto-cgraph.c */
885 lto_symtab_encoder_t
lto_symtab_encoder_new (bool);
886 int lto_symtab_encoder_encode (lto_symtab_encoder_t
, symtab_node
);
887 void lto_symtab_encoder_delete (lto_symtab_encoder_t
);
888 bool lto_symtab_encoder_delete_node (lto_symtab_encoder_t
, symtab_node
);
889 bool lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t
,
890 struct cgraph_node
*);
891 bool lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t
,
893 void lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t
,
896 bool lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t
,
897 struct varpool_node
*);
898 void output_symtab (void);
899 void input_symtab (void);
900 bool referenced_from_other_partition_p (struct ipa_ref_list
*,
901 lto_symtab_encoder_t
);
902 bool reachable_from_other_partition_p (struct cgraph_node
*,
903 lto_symtab_encoder_t
);
904 bool referenced_from_this_partition_p (struct ipa_ref_list
*,
905 lto_symtab_encoder_t
);
906 bool reachable_from_this_partition_p (struct cgraph_node
*,
907 lto_symtab_encoder_t
);
908 lto_symtab_encoder_t
compute_ltrans_boundary (lto_symtab_encoder_t encoder
);
911 /* In lto-symtab.c. */
912 extern void lto_symtab_merge_decls (void);
913 extern void lto_symtab_merge_symbols (void);
914 extern tree
lto_symtab_prevailing_decl (tree decl
);
915 extern GTY(()) vec
<tree
, va_gc
> *lto_global_var_decls
;
919 extern void lto_write_options (void);
922 /* Statistics gathered during LTO, WPA and LTRANS. */
923 extern struct lto_stats_d lto_stats
;
925 /* Section names corresponding to the values of enum lto_section_type. */
926 extern const char *lto_section_name
[];
928 /* Holds all the out decl states of functions output so far in the
929 current output file. */
930 extern vec
<lto_out_decl_state_ptr
> lto_function_decl_states
;
932 /* Return true if LTO tag TAG corresponds to a tree code. */
934 lto_tag_is_tree_code_p (enum LTO_tags tag
)
936 return tag
> LTO_tree_pickle_reference
&& (unsigned) tag
<= MAX_TREE_CODES
;
940 /* Return true if LTO tag TAG corresponds to a gimple code. */
942 lto_tag_is_gimple_code_p (enum LTO_tags tag
)
944 return (unsigned) tag
>= NUM_TREE_CODES
+ 2
945 && (unsigned) tag
< 2 + NUM_TREE_CODES
+ LAST_AND_UNUSED_GIMPLE_CODE
;
949 /* Return the LTO tag corresponding to gimple code CODE. See enum
950 LTO_tags for details on the conversion. */
951 static inline enum LTO_tags
952 lto_gimple_code_to_tag (enum gimple_code code
)
954 return (enum LTO_tags
) ((unsigned) code
+ NUM_TREE_CODES
+ 2);
958 /* Return the GIMPLE code corresponding to TAG. See enum LTO_tags for
959 details on the conversion. */
960 static inline enum gimple_code
961 lto_tag_to_gimple_code (enum LTO_tags tag
)
963 gcc_assert (lto_tag_is_gimple_code_p (tag
));
964 return (enum gimple_code
) ((unsigned) tag
- NUM_TREE_CODES
- 2);
968 /* Return the LTO tag corresponding to tree code CODE. See enum
969 LTO_tags for details on the conversion. */
970 static inline enum LTO_tags
971 lto_tree_code_to_tag (enum tree_code code
)
973 return (enum LTO_tags
) ((unsigned) code
+ 2);
977 /* Return the tree code corresponding to TAG. See enum LTO_tags for
978 details on the conversion. */
979 static inline enum tree_code
980 lto_tag_to_tree_code (enum LTO_tags tag
)
982 gcc_assert (lto_tag_is_tree_code_p (tag
));
983 return (enum tree_code
) ((unsigned) tag
- 2);
986 /* Check that tag ACTUAL == EXPECTED. */
988 lto_tag_check (enum LTO_tags actual
, enum LTO_tags expected
)
990 if (actual
!= expected
)
991 internal_error ("bytecode stream: expected tag %s instead of %s",
992 lto_tag_name (expected
), lto_tag_name (actual
));
995 /* Check that tag ACTUAL is in the range [TAG1, TAG2]. */
997 lto_tag_check_range (enum LTO_tags actual
, enum LTO_tags tag1
,
1000 if (actual
< tag1
|| actual
> tag2
)
1001 internal_error ("bytecode stream: tag %s is not in the expected range "
1003 lto_tag_name (actual
),
1004 lto_tag_name (tag1
),
1005 lto_tag_name (tag2
));
1008 /* Initialize an lto_out_decl_buffer ENCODER. */
1010 lto_init_tree_ref_encoder (struct lto_tree_ref_encoder
*encoder
,
1011 htab_hash hash_fn
, htab_eq eq_fn
)
1013 encoder
->tree_hash_table
= htab_create (37, hash_fn
, eq_fn
, free
);
1014 encoder
->next_index
= 0;
1015 encoder
->trees
.create (0);
1019 /* Destroy an lto_tree_ref_encoder ENCODER by freeing its contents. The
1020 memory used by ENCODER is not freed by this function. */
1022 lto_destroy_tree_ref_encoder (struct lto_tree_ref_encoder
*encoder
)
1024 /* Hash table may be delete already. */
1025 if (encoder
->tree_hash_table
)
1026 htab_delete (encoder
->tree_hash_table
);
1027 encoder
->trees
.release ();
1030 /* Return the number of trees encoded in ENCODER. */
1031 static inline unsigned int
1032 lto_tree_ref_encoder_size (struct lto_tree_ref_encoder
*encoder
)
1034 return encoder
->trees
.length ();
1037 /* Return the IDX-th tree in ENCODER. */
1039 lto_tree_ref_encoder_get_tree (struct lto_tree_ref_encoder
*encoder
,
1042 return encoder
->trees
[idx
];
1046 /* Return true if LABEL should be emitted in the global context. */
1048 emit_label_in_global_context_p (tree label
)
1050 return DECL_NONLOCAL (label
) || FORCED_LABEL (label
);
1053 /* Return number of encoded nodes in ENCODER. */
1055 lto_symtab_encoder_size (lto_symtab_encoder_t encoder
)
1057 return encoder
->nodes
.length ();
1060 /* Value used to represent failure of lto_symtab_encoder_lookup. */
1061 #define LCC_NOT_FOUND (-1)
1063 /* Look up NODE in encoder. Return NODE's reference if it has been encoded
1064 or LCC_NOT_FOUND if it is not there. */
1067 lto_symtab_encoder_lookup (lto_symtab_encoder_t encoder
,
1070 void **slot
= pointer_map_contains (encoder
->map
, node
);
1071 return (slot
&& *slot
? (size_t) *(slot
) - 1 : LCC_NOT_FOUND
);
1074 /* Return true if iterator LSE points to nothing. */
1076 lsei_end_p (lto_symtab_encoder_iterator lsei
)
1078 return lsei
.index
>= (unsigned)lto_symtab_encoder_size (lsei
.encoder
);
1081 /* Advance iterator LSE. */
1083 lsei_next (lto_symtab_encoder_iterator
*lsei
)
1088 /* Return the node pointed to by LSI. */
1089 static inline symtab_node
1090 lsei_node (lto_symtab_encoder_iterator lsei
)
1092 return lsei
.encoder
->nodes
[lsei
.index
].node
;
1095 /* Return the node pointed to by LSI. */
1096 static inline struct cgraph_node
*
1097 lsei_cgraph_node (lto_symtab_encoder_iterator lsei
)
1099 return cgraph (lsei
.encoder
->nodes
[lsei
.index
].node
);
1102 /* Return the node pointed to by LSI. */
1103 static inline struct varpool_node
*
1104 lsei_varpool_node (lto_symtab_encoder_iterator lsei
)
1106 return varpool (lsei
.encoder
->nodes
[lsei
.index
].node
);
1109 /* Return the cgraph node corresponding to REF using ENCODER. */
1111 static inline symtab_node
1112 lto_symtab_encoder_deref (lto_symtab_encoder_t encoder
, int ref
)
1114 if (ref
== LCC_NOT_FOUND
)
1117 return encoder
->nodes
[ref
].node
;
1120 /* Return an iterator to the first node in LSI. */
1121 static inline lto_symtab_encoder_iterator
1122 lsei_start (lto_symtab_encoder_t encoder
)
1124 lto_symtab_encoder_iterator lsei
;
1126 lsei
.encoder
= encoder
;
1131 /* Advance iterator LSE. */
1133 lsei_next_in_partition (lto_symtab_encoder_iterator
*lsei
)
1136 while (!lsei_end_p (*lsei
)
1137 && !lto_symtab_encoder_in_partition_p (lsei
->encoder
, lsei_node (*lsei
)))
1141 /* Return an iterator to the first node in LSI. */
1142 static inline lto_symtab_encoder_iterator
1143 lsei_start_in_partition (lto_symtab_encoder_t encoder
)
1145 lto_symtab_encoder_iterator lsei
= lsei_start (encoder
);
1147 if (lsei_end_p (lsei
))
1149 if (!lto_symtab_encoder_in_partition_p (encoder
, lsei_node (lsei
)))
1150 lsei_next_in_partition (&lsei
);
1155 /* Advance iterator LSE. */
1157 lsei_next_function_in_partition (lto_symtab_encoder_iterator
*lsei
)
1160 while (!lsei_end_p (*lsei
)
1161 && (!is_a
<cgraph_node
> (lsei_node (*lsei
))
1162 || !lto_symtab_encoder_in_partition_p (lsei
->encoder
, lsei_node (*lsei
))))
1166 /* Return an iterator to the first node in LSI. */
1167 static inline lto_symtab_encoder_iterator
1168 lsei_start_function_in_partition (lto_symtab_encoder_t encoder
)
1170 lto_symtab_encoder_iterator lsei
= lsei_start (encoder
);
1172 if (lsei_end_p (lsei
))
1174 if (!is_a
<cgraph_node
> (lsei_node (lsei
))
1175 || !lto_symtab_encoder_in_partition_p (encoder
, lsei_node (lsei
)))
1176 lsei_next_function_in_partition (&lsei
);
1181 /* Advance iterator LSE. */
1183 lsei_next_variable_in_partition (lto_symtab_encoder_iterator
*lsei
)
1186 while (!lsei_end_p (*lsei
)
1187 && (!is_a
<varpool_node
> (lsei_node (*lsei
))
1188 || !lto_symtab_encoder_in_partition_p (lsei
->encoder
, lsei_node (*lsei
))))
1192 /* Return an iterator to the first node in LSI. */
1193 static inline lto_symtab_encoder_iterator
1194 lsei_start_variable_in_partition (lto_symtab_encoder_t encoder
)
1196 lto_symtab_encoder_iterator lsei
= lsei_start (encoder
);
1198 if (lsei_end_p (lsei
))
1200 if (!is_a
<varpool_node
> (lsei_node (lsei
))
1201 || !lto_symtab_encoder_in_partition_p (encoder
, lsei_node (lsei
)))
1202 lsei_next_variable_in_partition (&lsei
);
1207 DEFINE_DECL_STREAM_FUNCS (TYPE
, type
)
1208 DEFINE_DECL_STREAM_FUNCS (FIELD_DECL
, field_decl
)
1209 DEFINE_DECL_STREAM_FUNCS (FN_DECL
, fn_decl
)
1210 DEFINE_DECL_STREAM_FUNCS (VAR_DECL
, var_decl
)
1211 DEFINE_DECL_STREAM_FUNCS (TYPE_DECL
, type_decl
)
1212 DEFINE_DECL_STREAM_FUNCS (NAMESPACE_DECL
, namespace_decl
)
1213 DEFINE_DECL_STREAM_FUNCS (LABEL_DECL
, label_decl
)
1215 #endif /* GCC_LTO_STREAMER_H */