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"
36 #include "pointer-set.h"
38 /* Define when debugging the LTO streamer. This causes the writer
39 to output the numeric value for the memory address of the tree node
40 being emitted. When debugging a problem in the reader, check the
41 original address that the writer was emitting using lto_orig_address_get.
42 With this value, set a breakpoint in the writer (e.g., lto_output_tree)
43 to trace how the faulty node is being emitted. */
44 /* #define LTO_STREAMER_DEBUG 1 */
46 /* The encoding for a function consists of the following sections:
54 7) Names for the labels that have names
56 9) The control flow graph.
57 10-11)Gimple for local decls.
58 12) Gimple for the function.
62 2-6) THE GLOBAL DECLS AND TYPES.
64 The global decls and types are encoded in the same way. For each
65 entry, there is word with the offset within the section to the
70 Since most labels do not have names, this section my be of zero
71 length. It consists of an array of string table references, one
72 per label. In the lto code, the labels are given either
73 positive or negative indexes. the positive ones have names and
74 the negative ones do not. The positive index can be used to
75 find the name in this array.
79 10) Index into the local decls. Since local decls can have local
80 decls inside them, they must be read in randomly in order to
81 properly restore them.
83 11-12) GIMPLE FOR THE LOCAL DECLS AND THE FUNCTION BODY.
85 The gimple consists of a set of records.
89 At the top level of (8) is the function. It consists of five
92 LTO_function - The tag.
93 eh tree - This is all of the exception handling regions
94 put out in a post order traversial of the
95 tree. Siblings are output as lists terminated
96 by a 0. The set of fields matches the fields
99 last_basic_block - in uleb128 form.
101 basic blocks - This is the set of basic blocks.
103 zero - The termination of the basic blocks.
107 There are two forms of basic blocks depending on if they are
110 The basic block consists of:
112 LTO_bb1 or LTO_bb0 - The tag.
114 bb->index - the index in uleb128 form.
116 #succs - The number of successors un uleb128 form.
118 the successors - For each edge, a pair. The first of the
119 pair is the index of the successor in
120 uleb128 form and the second are the flags in
123 the statements - A gimple tree, as described above.
124 These are only present for LTO_BB1.
125 Following each statement is an optional
126 exception handling record LTO_eh_region
127 which contains the region number (for
130 zero - This is only present for LTO_BB1 and is used
131 to terminate the statements and exception
132 regions within this block.
136 String are represented in the table as pairs, a length in ULEB128
137 form followed by the data for the string. */
139 /* The string that is the prefix on the section names we make for lto.
140 For decls the DECL_ASSEMBLER_NAME is appended to make the section
141 name for the functions and static_initializers. For other types of
142 sections a '.' and the section type are appended. */
143 #define LTO_SECTION_NAME_PREFIX ".gnu.lto_"
145 #define LTO_major_version 2
146 #define LTO_minor_version 2
148 typedef unsigned char lto_decl_flags_t
;
151 /* Tags representing the various IL objects written to the bytecode file
152 (GIMPLE statements, basic blocks, EH regions, tree nodes, etc).
154 NOTE, when adding new LTO tags, also update lto_tag_name. */
159 /* Special for streamer. Reference to previously-streamed node. */
160 LTO_tree_pickle_reference
,
162 /* Reserve enough entries to fit all the tree and gimple codes handled
163 by the streamer. This guarantees that:
165 1- Given a tree code C:
166 enum LTO_tags tag == C + 1
168 2- Given a gimple code C:
169 enum LTO_tags tag == C + NUM_TREE_CODES + 1
171 Conversely, to map between LTO tags and tree/gimple codes, the
172 reverse operation must be applied. */
173 LTO_bb0
= 1 + MAX_TREE_CODES
+ LAST_AND_UNUSED_GIMPLE_CODE
,
176 /* EH region holding the previous statement. */
179 /* An MD or NORMAL builtin. Only the code and class are streamed out. */
182 /* Shared INTEGER_CST node. */
191 /* EH region types. These mirror enum eh_region_type. */
194 LTO_ert_allowed_exceptions
,
195 LTO_ert_must_not_throw
,
197 /* EH landing pad. */
200 /* EH try/catch node. */
203 /* Special for global streamer. A blob of unnamed tree nodes. */
206 /* References to indexable tree nodes. These objects are stored in
207 tables that are written separately from the function bodies that
208 reference them. This way they can be instantiated even when the
209 referencing functions aren't (e.g., during WPA) and it also allows
210 functions to be copied from one file to another without having
211 to unpickle the body first (the references are location
214 NOTE, do not regroup these values as the grouping is exposed
215 in the range checks done in lto_input_tree. */
216 LTO_field_decl_ref
, /* Do not change. */
217 LTO_function_decl_ref
,
219 LTO_namespace_decl_ref
,
225 LTO_imported_decl_ref
,
226 LTO_translation_unit_decl_ref
,
227 LTO_global_decl_ref
, /* Do not change. */
229 /* This tag must always be last. */
234 /* Set of section types that are in an LTO file. This list will grow
235 as the number of IPA passes grows since each IPA pass will need its
236 own section type to store its summary information.
238 When adding a new section type, you must also extend the
239 LTO_SECTION_NAME array in lto-section-in.c. */
240 enum lto_section_type
242 LTO_section_decls
= 0,
243 LTO_section_function_body
,
244 LTO_section_static_initializer
,
248 LTO_section_jump_functions
,
249 LTO_section_ipa_pure_const
,
250 LTO_section_ipa_reference
,
251 LTO_section_ipa_profile
,
252 LTO_section_symtab_nodes
,
254 LTO_section_cgraph_opt_sum
,
255 LTO_section_inline_summary
,
256 LTO_section_ipcp_transform
,
257 LTO_N_SECTION_TYPES
/* Must be last. */
260 /* Indices to the various function, type and symbol streams. */
263 LTO_DECL_STREAM_TYPE
= 0, /* Must be first. */
264 LTO_DECL_STREAM_FIELD_DECL
,
265 LTO_DECL_STREAM_FN_DECL
,
266 LTO_DECL_STREAM_VAR_DECL
,
267 LTO_DECL_STREAM_TYPE_DECL
,
268 LTO_DECL_STREAM_NAMESPACE_DECL
,
269 LTO_DECL_STREAM_LABEL_DECL
,
271 } lto_decl_stream_e_t
;
273 typedef enum ld_plugin_symbol_resolution ld_plugin_symbol_resolution_t
;
276 /* Macro to define convenience functions for type and decl streams
277 in lto_file_decl_data. */
278 #define DEFINE_DECL_STREAM_FUNCS(UPPER_NAME, name) \
280 lto_file_decl_data_get_ ## name (struct lto_file_decl_data *data, \
283 struct lto_in_decl_state *state = data->current_decl_state; \
284 gcc_assert (idx < state->streams[LTO_DECL_STREAM_## UPPER_NAME].size); \
285 return state->streams[LTO_DECL_STREAM_## UPPER_NAME].trees[idx]; \
288 static inline unsigned int \
289 lto_file_decl_data_num_ ## name ## s (struct lto_file_decl_data *data) \
291 struct lto_in_decl_state *state = data->current_decl_state; \
292 return state->streams[LTO_DECL_STREAM_## UPPER_NAME].size; \
296 /* Return a char pointer to the start of a data stream for an lto pass
297 or function. The first parameter is the file data that contains
298 the information. The second parameter is the type of information
299 to be obtained. The third parameter is the name of the function
300 and is only used when finding a function body; otherwise it is
301 NULL. The fourth parameter is the length of the data returned. */
302 typedef const char* (lto_get_section_data_f
) (struct lto_file_decl_data
*,
303 enum lto_section_type
,
307 /* Return the data found from the above call. The first three
308 parameters are the same as above. The fourth parameter is the data
309 itself and the fifth is the length of the data. */
310 typedef void (lto_free_section_data_f
) (struct lto_file_decl_data
*,
311 enum lto_section_type
,
316 /* Structure used as buffer for reading an LTO file. */
317 struct lto_input_block
324 #define LTO_INIT_INPUT_BLOCK(BASE,D,P,L) \
331 #define LTO_INIT_INPUT_BLOCK_PTR(BASE,D,P,L) \
339 /* The is the first part of the record for a function or constructor
343 int16_t major_version
;
344 int16_t minor_version
;
347 /* The header for a function body. */
348 struct lto_function_header
350 /* The header for all types of sections. */
351 struct lto_header lto_header
;
353 /* Number of labels with names. */
354 int32_t num_named_labels
;
356 /* Number of labels without names. */
357 int32_t num_unnamed_labels
;
359 /* Size compressed or 0 if not compressed. */
360 int32_t compressed_size
;
362 /* Size of names for named labels. */
363 int32_t named_label_size
;
365 /* Size of the cfg. */
368 /* Size of main gimple body of function. */
371 /* Size of the string table. */
376 /* Structure describing a symbol section. */
377 struct lto_decl_header
379 /* The header for all types of sections. */
380 struct lto_header lto_header
;
382 /* Size of region for decl state. */
383 int32_t decl_state_size
;
385 /* Number of nodes in globals stream. */
388 /* Size of region for expressions, decls, types, etc. */
391 /* Size of the string table. */
396 /* Structure describing top level asm()s. */
397 struct lto_asm_header
399 /* The header for all types of sections. */
400 struct lto_header lto_header
;
402 /* Size compressed or 0 if not compressed. */
403 int32_t compressed_size
;
405 /* Size of region for expressions, decls, types, etc. */
408 /* Size of the string table. */
413 /* Statistics gathered during LTO, WPA and LTRANS. */
416 unsigned HOST_WIDE_INT num_input_cgraph_nodes
;
417 unsigned HOST_WIDE_INT num_output_symtab_nodes
;
418 unsigned HOST_WIDE_INT num_input_files
;
419 unsigned HOST_WIDE_INT num_output_files
;
420 unsigned HOST_WIDE_INT num_cgraph_partitions
;
421 unsigned HOST_WIDE_INT section_size
[LTO_N_SECTION_TYPES
];
422 unsigned HOST_WIDE_INT num_function_bodies
;
423 unsigned HOST_WIDE_INT num_trees
[NUM_TREE_CODES
];
424 unsigned HOST_WIDE_INT num_output_il_bytes
;
425 unsigned HOST_WIDE_INT num_compressed_il_bytes
;
426 unsigned HOST_WIDE_INT num_input_il_bytes
;
427 unsigned HOST_WIDE_INT num_uncompressed_il_bytes
;
428 unsigned HOST_WIDE_INT num_tree_bodies_output
;
429 unsigned HOST_WIDE_INT num_pickle_refs_output
;
432 /* Entry of LTO symtab encoder. */
436 /* Is the node in this partition (i.e. ltrans of this partition will
437 be responsible for outputting it)? */
438 unsigned int in_partition
:1;
439 /* Do we encode body in this partition? */
441 /* Do we encode initializer in this partition?
442 For example the readonly variable initializers are encoded to aid
443 constant folding even if they are not in the partition. */
444 unsigned int initializer
:1;
448 /* Encoder data structure used to stream callgraph nodes. */
449 struct lto_symtab_encoder_d
451 vec
<lto_encoder_entry
> nodes
;
455 typedef struct lto_symtab_encoder_d
*lto_symtab_encoder_t
;
457 /* Iterator structure for cgraph node sets. */
460 lto_symtab_encoder_t encoder
;
462 } lto_symtab_encoder_iterator
;
467 /* Mapping from indices to trees. */
468 struct GTY(()) lto_tree_ref_table
470 /* Array of referenced trees . */
471 tree
* GTY((length ("%h.size"))) trees
;
478 /* The lto_tree_ref_encoder struct is used to encode trees into indices. */
480 struct lto_tree_ref_encoder
482 pointer_map
<unsigned> *tree_hash_table
; /* Maps pointers to indices. */
483 vec
<tree
> trees
; /* Maps indices to pointers. */
487 /* Structure to hold states of input scope. */
488 struct GTY(()) lto_in_decl_state
490 /* Array of lto_in_decl_buffers to store type and decls streams. */
491 struct lto_tree_ref_table streams
[LTO_N_DECL_STREAMS
];
493 /* If this in-decl state is associated with a function. FN_DECL
494 point to the FUNCTION_DECL. */
498 typedef struct lto_in_decl_state
*lto_in_decl_state_ptr
;
501 /* The structure that holds all of the vectors of global types,
502 decls and cgraph nodes used in the serialization of this file. */
503 struct lto_out_decl_state
505 /* The buffers contain the sets of decls of various kinds and types we have
506 seen so far and the indexes assigned to them. */
507 struct lto_tree_ref_encoder streams
[LTO_N_DECL_STREAMS
];
509 /* Encoder for cgraph nodes. */
510 lto_symtab_encoder_t symtab_node_encoder
;
512 /* If this out-decl state belongs to a function, fn_decl points to that
513 function. Otherwise, it is NULL. */
517 typedef struct lto_out_decl_state
*lto_out_decl_state_ptr
;
520 /* Compact representation of a index <-> resolution pair. Unpacked to an
524 ld_plugin_symbol_resolution_t res
;
527 typedef struct res_pair res_pair
;
530 /* One of these is allocated for each object file that being compiled
531 by lto. This structure contains the tables that are needed by the
532 serialized functions and ipa passes to connect themselves to the
533 global types and decls as they are reconstituted. */
534 struct GTY(()) lto_file_decl_data
536 /* Decl state currently used. */
537 struct lto_in_decl_state
*current_decl_state
;
539 /* Decl state corresponding to regions outside of any functions
540 in the compilation unit. */
541 struct lto_in_decl_state
*global_decl_state
;
543 /* Table of cgraph nodes present in this file. */
544 lto_symtab_encoder_t
GTY((skip
)) symtab_node_encoder
;
546 /* Hash table maps lto-related section names to location in file. */
547 htab_t
GTY((param_is (struct lto_in_decl_state
))) function_decl_states
;
549 /* The .o file that these offsets relate to. */
550 const char *GTY((skip
)) file_name
;
552 /* Hash table maps lto-related section names to location in file. */
553 htab_t
GTY((skip
)) section_hash_table
;
555 /* Hash new name of renamed global declaration to its original name. */
556 htab_t
GTY((skip
)) renaming_hash_table
;
558 /* Linked list used temporarily in reader */
559 struct lto_file_decl_data
*next
;
561 /* Sub ID for merged objects. */
562 unsigned HOST_WIDE_INT id
;
564 /* Symbol resolutions for this file */
565 vec
<res_pair
> GTY((skip
)) respairs
;
568 struct gcov_ctr_summary
GTY((skip
)) profile_info
;
570 /* Map assigning declarations their resolutions. */
571 pointer_map_t
* GTY((skip
)) resolution_map
;
574 typedef struct lto_file_decl_data
*lto_file_decl_data_ptr
;
576 struct lto_char_ptr_base
581 /* An incore byte stream to buffer the various parts of the function.
582 The entire structure should be zeroed when created. The record
583 consists of a set of blocks. The first sizeof (ptr) bytes are used
584 as a chain, and the rest store the bytes to be written. */
585 struct lto_output_stream
587 /* The pointer to the first block in the stream. */
588 struct lto_char_ptr_base
* first_block
;
590 /* The pointer to the last and current block in the stream. */
591 struct lto_char_ptr_base
* current_block
;
593 /* The pointer to where the next char should be written. */
594 char * current_pointer
;
596 /* The number of characters left in the current block. */
597 unsigned int left_in_block
;
599 /* The block size of the last block allocated. */
600 unsigned int block_size
;
602 /* The total number of characters written. */
603 unsigned int total_size
;
606 /* The is the first part of the record in an LTO file for many of the
608 struct lto_simple_header
610 /* The header for all types of sections. */
611 struct lto_header lto_header
;
613 /* Size of main gimple body of function. */
616 /* Size of main stream when compressed. */
617 int32_t compressed_size
;
620 /* A simple output block. This can be used for simple IPA passes that
621 do not need more than one stream. */
622 struct lto_simple_output_block
624 enum lto_section_type section_type
;
625 struct lto_out_decl_state
*decl_state
;
627 /* The stream that the main tree codes are written to. */
628 struct lto_output_stream
*main_stream
;
631 /* String hashing. */
637 unsigned int slot_num
;
640 /* Hashtable helpers. */
642 struct string_slot_hasher
: typed_noop_remove
<string_slot
>
644 typedef string_slot value_type
;
645 typedef string_slot compare_type
;
646 static inline hashval_t
hash (const value_type
*);
647 static inline bool equal (const value_type
*, const compare_type
*);
650 /* Returns a hash code for DS. Adapted from libiberty's htab_hash_string
651 to support strings that may not end in '\0'. */
654 string_slot_hasher::hash (const value_type
*ds
)
656 hashval_t r
= ds
->len
;
659 for (i
= 0; i
< ds
->len
; i
++)
660 r
= r
* 67 + (unsigned)ds
->s
[i
] - 113;
664 /* Returns nonzero if DS1 and DS2 are equal. */
667 string_slot_hasher::equal (const value_type
*ds1
, const compare_type
*ds2
)
669 if (ds1
->len
== ds2
->len
)
670 return memcmp (ds1
->s
, ds2
->s
, ds1
->len
) == 0;
675 /* Data structure holding all the data and descriptors used when writing
679 enum lto_section_type section_type
;
680 struct lto_out_decl_state
*decl_state
;
682 /* The stream that the main tree codes are written to. */
683 struct lto_output_stream
*main_stream
;
685 /* The stream that contains the string table. */
686 struct lto_output_stream
*string_stream
;
688 /* The stream that contains the cfg. */
689 struct lto_output_stream
*cfg_stream
;
691 /* The hash table that contains the set of strings we have seen so
692 far and the indexes assigned to them. */
693 hash_table
<string_slot_hasher
> string_hash_table
;
695 /* The current cgraph_node that we are currently serializing. Null
696 if we are serializing something else. */
697 struct cgraph_node
*cgraph_node
;
699 /* These are the last file and line that were seen in the stream.
700 If the current node differs from these, it needs to insert
701 something into the stream and fix these up. */
702 const char *current_file
;
706 /* True if writing globals and types. */
709 /* Cache of nodes written in this section. */
710 struct streamer_tree_cache_d
*writer_cache
;
712 /* All data persistent across whole duration of output block
714 struct obstack obstack
;
718 /* Data and descriptors used when reading from an LTO file. */
721 /* The global decls and types. */
722 struct lto_file_decl_data
*file_data
;
724 /* All of the labels. */
727 /* The string table. */
730 /* The length of the string table. */
731 unsigned int strings_len
;
733 /* Number of named labels. Used to find the index of unnamed labels
734 since they share space with the named labels. */
735 unsigned int num_named_labels
;
737 /* Number of unnamed labels. */
738 unsigned int num_unnamed_labels
;
740 /* Maps each reference number to the resolution done by the linker. */
741 vec
<ld_plugin_symbol_resolution_t
> globals_resolution
;
743 /* Cache of pickled nodes. */
744 struct streamer_tree_cache_d
*reader_cache
;
748 /* In lto-section-in.c */
749 extern struct lto_input_block
* lto_create_simple_input_block (
750 struct lto_file_decl_data
*,
751 enum lto_section_type
, const char **, size_t *);
753 lto_destroy_simple_input_block (struct lto_file_decl_data
*,
754 enum lto_section_type
,
755 struct lto_input_block
*, const char *, size_t);
756 extern void lto_set_in_hooks (struct lto_file_decl_data
**,
757 lto_get_section_data_f
*,
758 lto_free_section_data_f
*);
759 extern struct lto_file_decl_data
**lto_get_file_decl_data (void);
760 extern const char *lto_get_section_data (struct lto_file_decl_data
*,
761 enum lto_section_type
,
762 const char *, size_t *);
763 extern void lto_free_section_data (struct lto_file_decl_data
*,
764 enum lto_section_type
,
765 const char *, const char *, size_t);
766 extern htab_t
lto_create_renaming_table (void);
767 extern void lto_record_renamed_decl (struct lto_file_decl_data
*,
768 const char *, const char *);
769 extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data
*,
771 extern struct lto_in_decl_state
*lto_new_in_decl_state (void);
772 extern void lto_delete_in_decl_state (struct lto_in_decl_state
*);
773 extern hashval_t
lto_hash_in_decl_state (const void *);
774 extern int lto_eq_in_decl_state (const void *, const void *);
775 extern struct lto_in_decl_state
*lto_get_function_in_decl_state (
776 struct lto_file_decl_data
*, tree
);
777 extern void lto_section_overrun (struct lto_input_block
*) ATTRIBUTE_NORETURN
;
778 extern void lto_value_range_error (const char *,
779 HOST_WIDE_INT
, HOST_WIDE_INT
,
780 HOST_WIDE_INT
) ATTRIBUTE_NORETURN
;
782 /* In lto-section-out.c */
783 extern void lto_begin_section (const char *, bool);
784 extern void lto_end_section (void);
785 extern void lto_write_stream (struct lto_output_stream
*);
786 extern void lto_output_data_stream (struct lto_output_stream
*, const void *,
788 extern bool lto_output_decl_index (struct lto_output_stream
*,
789 struct lto_tree_ref_encoder
*,
790 tree
, unsigned int *);
791 extern void lto_output_field_decl_index (struct lto_out_decl_state
*,
792 struct lto_output_stream
*, tree
);
793 extern void lto_output_fn_decl_index (struct lto_out_decl_state
*,
794 struct lto_output_stream
*, tree
);
795 extern void lto_output_namespace_decl_index (struct lto_out_decl_state
*,
796 struct lto_output_stream
*, tree
);
797 extern void lto_output_var_decl_index (struct lto_out_decl_state
*,
798 struct lto_output_stream
*, tree
);
799 extern void lto_output_type_decl_index (struct lto_out_decl_state
*,
800 struct lto_output_stream
*, tree
);
801 extern void lto_output_type_ref_index (struct lto_out_decl_state
*,
802 struct lto_output_stream
*, tree
);
803 extern struct lto_simple_output_block
*lto_create_simple_output_block (
804 enum lto_section_type
);
805 extern void lto_destroy_simple_output_block (struct lto_simple_output_block
*);
806 extern struct lto_out_decl_state
*lto_new_out_decl_state (void);
807 extern void lto_delete_out_decl_state (struct lto_out_decl_state
*);
808 extern struct lto_out_decl_state
*lto_get_out_decl_state (void);
809 extern void lto_push_out_decl_state (struct lto_out_decl_state
*);
810 extern struct lto_out_decl_state
*lto_pop_out_decl_state (void);
811 extern void lto_record_function_out_decl_state (tree
,
812 struct lto_out_decl_state
*);
813 extern void lto_append_block (struct lto_output_stream
*);
816 /* In lto-streamer.c. */
817 extern const char *lto_tag_name (enum LTO_tags
);
818 extern bitmap
lto_bitmap_alloc (void);
819 extern void lto_bitmap_free (bitmap
);
820 extern char *lto_get_section_name (int, const char *, struct lto_file_decl_data
*);
821 extern void print_lto_report (const char *);
822 extern void lto_streamer_init (void);
823 extern bool gate_lto_out (void);
824 #ifdef LTO_STREAMER_DEBUG
825 extern void lto_orig_address_map (tree
, intptr_t);
826 extern intptr_t lto_orig_address_get (tree
);
827 extern void lto_orig_address_remove (tree
);
829 extern void lto_check_version (int, int);
830 extern void lto_streamer_hooks_init (void);
832 /* In lto-streamer-in.c */
833 extern void lto_input_cgraph (struct lto_file_decl_data
*, const char *);
834 extern void lto_reader_init (void);
835 extern void lto_input_function_body (struct lto_file_decl_data
*, tree
,
837 extern void lto_input_constructors_and_inits (struct lto_file_decl_data
*,
839 extern void lto_input_toplevel_asms (struct lto_file_decl_data
*, int);
840 extern struct data_in
*lto_data_in_create (struct lto_file_decl_data
*,
841 const char *, unsigned,
842 vec
<ld_plugin_symbol_resolution_t
> );
843 extern void lto_data_in_delete (struct data_in
*);
844 extern void lto_input_data_block (struct lto_input_block
*, void *, size_t);
845 location_t
lto_input_location (struct bitpack_d
*, struct data_in
*);
846 tree
lto_input_tree_ref (struct lto_input_block
*, struct data_in
*,
847 struct function
*, enum LTO_tags
);
848 void lto_tag_check_set (enum LTO_tags
, int, ...);
849 void lto_init_eh (void);
850 hashval_t
lto_input_scc (struct lto_input_block
*, struct data_in
*,
851 unsigned *, unsigned *);
852 tree
lto_input_tree_1 (struct lto_input_block
*, struct data_in
*,
853 enum LTO_tags
, hashval_t hash
);
854 tree
lto_input_tree (struct lto_input_block
*, struct data_in
*);
857 /* In lto-streamer-out.c */
858 extern void lto_register_decl_definition (tree
, struct lto_file_decl_data
*);
859 extern struct output_block
*create_output_block (enum lto_section_type
);
860 extern void destroy_output_block (struct output_block
*);
861 extern void lto_output_tree (struct output_block
*, tree
, bool, bool);
862 extern void lto_output_toplevel_asms (void);
863 extern void produce_asm (struct output_block
*ob
, tree fn
);
864 void lto_output_decl_state_streams (struct output_block
*,
865 struct lto_out_decl_state
*);
866 void lto_output_decl_state_refs (struct output_block
*,
867 struct lto_output_stream
*,
868 struct lto_out_decl_state
*);
869 void lto_output_location (struct output_block
*, struct bitpack_d
*, location_t
);
872 /* In lto-cgraph.c */
873 lto_symtab_encoder_t
lto_symtab_encoder_new (bool);
874 int lto_symtab_encoder_encode (lto_symtab_encoder_t
, symtab_node
);
875 void lto_symtab_encoder_delete (lto_symtab_encoder_t
);
876 bool lto_symtab_encoder_delete_node (lto_symtab_encoder_t
, symtab_node
);
877 bool lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t
,
878 struct cgraph_node
*);
879 bool lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t
,
881 void lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t
,
884 bool lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t
,
885 struct varpool_node
*);
886 void output_symtab (void);
887 void input_symtab (void);
888 bool referenced_from_other_partition_p (struct ipa_ref_list
*,
889 lto_symtab_encoder_t
);
890 bool reachable_from_other_partition_p (struct cgraph_node
*,
891 lto_symtab_encoder_t
);
892 bool referenced_from_this_partition_p (struct ipa_ref_list
*,
893 lto_symtab_encoder_t
);
894 bool reachable_from_this_partition_p (struct cgraph_node
*,
895 lto_symtab_encoder_t
);
896 lto_symtab_encoder_t
compute_ltrans_boundary (lto_symtab_encoder_t encoder
);
899 /* In lto-symtab.c. */
900 extern void lto_symtab_merge_decls (void);
901 extern void lto_symtab_merge_symbols (void);
902 extern tree
lto_symtab_prevailing_decl (tree decl
);
903 extern GTY(()) vec
<tree
, va_gc
> *lto_global_var_decls
;
907 extern void lto_write_options (void);
910 /* Statistics gathered during LTO, WPA and LTRANS. */
911 extern struct lto_stats_d lto_stats
;
913 /* Section names corresponding to the values of enum lto_section_type. */
914 extern const char *lto_section_name
[];
916 /* Holds all the out decl states of functions output so far in the
917 current output file. */
918 extern vec
<lto_out_decl_state_ptr
> lto_function_decl_states
;
920 /* Return true if LTO tag TAG corresponds to a tree code. */
922 lto_tag_is_tree_code_p (enum LTO_tags tag
)
924 return tag
> LTO_tree_pickle_reference
&& (unsigned) tag
<= MAX_TREE_CODES
;
928 /* Return true if LTO tag TAG corresponds to a gimple code. */
930 lto_tag_is_gimple_code_p (enum LTO_tags tag
)
932 return (unsigned) tag
>= NUM_TREE_CODES
+ 2
933 && (unsigned) tag
< 2 + NUM_TREE_CODES
+ LAST_AND_UNUSED_GIMPLE_CODE
;
937 /* Return the LTO tag corresponding to gimple code CODE. See enum
938 LTO_tags for details on the conversion. */
939 static inline enum LTO_tags
940 lto_gimple_code_to_tag (enum gimple_code code
)
942 return (enum LTO_tags
) ((unsigned) code
+ NUM_TREE_CODES
+ 2);
946 /* Return the GIMPLE code corresponding to TAG. See enum LTO_tags for
947 details on the conversion. */
948 static inline enum gimple_code
949 lto_tag_to_gimple_code (enum LTO_tags tag
)
951 gcc_assert (lto_tag_is_gimple_code_p (tag
));
952 return (enum gimple_code
) ((unsigned) tag
- NUM_TREE_CODES
- 2);
956 /* Return the LTO tag corresponding to tree code CODE. See enum
957 LTO_tags for details on the conversion. */
958 static inline enum LTO_tags
959 lto_tree_code_to_tag (enum tree_code code
)
961 return (enum LTO_tags
) ((unsigned) code
+ 2);
965 /* Return the tree code corresponding to TAG. See enum LTO_tags for
966 details on the conversion. */
967 static inline enum tree_code
968 lto_tag_to_tree_code (enum LTO_tags tag
)
970 gcc_assert (lto_tag_is_tree_code_p (tag
));
971 return (enum tree_code
) ((unsigned) tag
- 2);
974 /* Check that tag ACTUAL == EXPECTED. */
976 lto_tag_check (enum LTO_tags actual
, enum LTO_tags expected
)
978 if (actual
!= expected
)
979 internal_error ("bytecode stream: expected tag %s instead of %s",
980 lto_tag_name (expected
), lto_tag_name (actual
));
983 /* Check that tag ACTUAL is in the range [TAG1, TAG2]. */
985 lto_tag_check_range (enum LTO_tags actual
, enum LTO_tags tag1
,
988 if (actual
< tag1
|| actual
> tag2
)
989 internal_error ("bytecode stream: tag %s is not in the expected range "
991 lto_tag_name (actual
),
993 lto_tag_name (tag2
));
996 /* Initialize an lto_out_decl_buffer ENCODER. */
998 lto_init_tree_ref_encoder (struct lto_tree_ref_encoder
*encoder
)
1000 encoder
->tree_hash_table
= new pointer_map
<unsigned>;
1001 encoder
->trees
.create (0);
1005 /* Destroy an lto_tree_ref_encoder ENCODER by freeing its contents. The
1006 memory used by ENCODER is not freed by this function. */
1008 lto_destroy_tree_ref_encoder (struct lto_tree_ref_encoder
*encoder
)
1010 /* Hash table may be delete already. */
1011 if (encoder
->tree_hash_table
)
1012 delete encoder
->tree_hash_table
;
1013 encoder
->trees
.release ();
1016 /* Return the number of trees encoded in ENCODER. */
1017 static inline unsigned int
1018 lto_tree_ref_encoder_size (struct lto_tree_ref_encoder
*encoder
)
1020 return encoder
->trees
.length ();
1023 /* Return the IDX-th tree in ENCODER. */
1025 lto_tree_ref_encoder_get_tree (struct lto_tree_ref_encoder
*encoder
,
1028 return encoder
->trees
[idx
];
1032 /* Return true if LABEL should be emitted in the global context. */
1034 emit_label_in_global_context_p (tree label
)
1036 return DECL_NONLOCAL (label
) || FORCED_LABEL (label
);
1039 /* Return number of encoded nodes in ENCODER. */
1041 lto_symtab_encoder_size (lto_symtab_encoder_t encoder
)
1043 return encoder
->nodes
.length ();
1046 /* Value used to represent failure of lto_symtab_encoder_lookup. */
1047 #define LCC_NOT_FOUND (-1)
1049 /* Look up NODE in encoder. Return NODE's reference if it has been encoded
1050 or LCC_NOT_FOUND if it is not there. */
1053 lto_symtab_encoder_lookup (lto_symtab_encoder_t encoder
,
1056 void **slot
= pointer_map_contains (encoder
->map
, node
);
1057 return (slot
&& *slot
? (size_t) *(slot
) - 1 : LCC_NOT_FOUND
);
1060 /* Return true if iterator LSE points to nothing. */
1062 lsei_end_p (lto_symtab_encoder_iterator lsei
)
1064 return lsei
.index
>= (unsigned)lto_symtab_encoder_size (lsei
.encoder
);
1067 /* Advance iterator LSE. */
1069 lsei_next (lto_symtab_encoder_iterator
*lsei
)
1074 /* Return the node pointed to by LSI. */
1075 static inline symtab_node
1076 lsei_node (lto_symtab_encoder_iterator lsei
)
1078 return lsei
.encoder
->nodes
[lsei
.index
].node
;
1081 /* Return the node pointed to by LSI. */
1082 static inline struct cgraph_node
*
1083 lsei_cgraph_node (lto_symtab_encoder_iterator lsei
)
1085 return cgraph (lsei
.encoder
->nodes
[lsei
.index
].node
);
1088 /* Return the node pointed to by LSI. */
1089 static inline struct varpool_node
*
1090 lsei_varpool_node (lto_symtab_encoder_iterator lsei
)
1092 return varpool (lsei
.encoder
->nodes
[lsei
.index
].node
);
1095 /* Return the cgraph node corresponding to REF using ENCODER. */
1097 static inline symtab_node
1098 lto_symtab_encoder_deref (lto_symtab_encoder_t encoder
, int ref
)
1100 if (ref
== LCC_NOT_FOUND
)
1103 return encoder
->nodes
[ref
].node
;
1106 /* Return an iterator to the first node in LSI. */
1107 static inline lto_symtab_encoder_iterator
1108 lsei_start (lto_symtab_encoder_t encoder
)
1110 lto_symtab_encoder_iterator lsei
;
1112 lsei
.encoder
= encoder
;
1117 /* Advance iterator LSE. */
1119 lsei_next_in_partition (lto_symtab_encoder_iterator
*lsei
)
1122 while (!lsei_end_p (*lsei
)
1123 && !lto_symtab_encoder_in_partition_p (lsei
->encoder
, lsei_node (*lsei
)))
1127 /* Return an iterator to the first node in LSI. */
1128 static inline lto_symtab_encoder_iterator
1129 lsei_start_in_partition (lto_symtab_encoder_t encoder
)
1131 lto_symtab_encoder_iterator lsei
= lsei_start (encoder
);
1133 if (lsei_end_p (lsei
))
1135 if (!lto_symtab_encoder_in_partition_p (encoder
, lsei_node (lsei
)))
1136 lsei_next_in_partition (&lsei
);
1141 /* Advance iterator LSE. */
1143 lsei_next_function_in_partition (lto_symtab_encoder_iterator
*lsei
)
1146 while (!lsei_end_p (*lsei
)
1147 && (!is_a
<cgraph_node
> (lsei_node (*lsei
))
1148 || !lto_symtab_encoder_in_partition_p (lsei
->encoder
, lsei_node (*lsei
))))
1152 /* Return an iterator to the first node in LSI. */
1153 static inline lto_symtab_encoder_iterator
1154 lsei_start_function_in_partition (lto_symtab_encoder_t encoder
)
1156 lto_symtab_encoder_iterator lsei
= lsei_start (encoder
);
1158 if (lsei_end_p (lsei
))
1160 if (!is_a
<cgraph_node
> (lsei_node (lsei
))
1161 || !lto_symtab_encoder_in_partition_p (encoder
, lsei_node (lsei
)))
1162 lsei_next_function_in_partition (&lsei
);
1167 /* Advance iterator LSE. */
1169 lsei_next_variable_in_partition (lto_symtab_encoder_iterator
*lsei
)
1172 while (!lsei_end_p (*lsei
)
1173 && (!is_a
<varpool_node
> (lsei_node (*lsei
))
1174 || !lto_symtab_encoder_in_partition_p (lsei
->encoder
, lsei_node (*lsei
))))
1178 /* Return an iterator to the first node in LSI. */
1179 static inline lto_symtab_encoder_iterator
1180 lsei_start_variable_in_partition (lto_symtab_encoder_t encoder
)
1182 lto_symtab_encoder_iterator lsei
= lsei_start (encoder
);
1184 if (lsei_end_p (lsei
))
1186 if (!is_a
<varpool_node
> (lsei_node (lsei
))
1187 || !lto_symtab_encoder_in_partition_p (encoder
, lsei_node (lsei
)))
1188 lsei_next_variable_in_partition (&lsei
);
1193 DEFINE_DECL_STREAM_FUNCS (TYPE
, type
)
1194 DEFINE_DECL_STREAM_FUNCS (FIELD_DECL
, field_decl
)
1195 DEFINE_DECL_STREAM_FUNCS (FN_DECL
, fn_decl
)
1196 DEFINE_DECL_STREAM_FUNCS (VAR_DECL
, var_decl
)
1197 DEFINE_DECL_STREAM_FUNCS (TYPE_DECL
, type_decl
)
1198 DEFINE_DECL_STREAM_FUNCS (NAMESPACE_DECL
, namespace_decl
)
1199 DEFINE_DECL_STREAM_FUNCS (LABEL_DECL
, label_decl
)
1201 #endif /* GCC_LTO_STREAMER_H */