cp/ChangeLog.pph
[official-gcc.git] / gcc / lto-streamer.h
blob242850fa129f0d2bcf4d8b0383e6a2b2e6c5cc1d
1 /* Data structures and declarations used for reading and writing
2 GIMPLE to a file stream.
4 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
5 Contributed by Doug Kwan <dougkwan@google.com>
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 #ifndef GCC_LTO_STREAMER_H
24 #define GCC_LTO_STREAMER_H
26 #include "plugin-api.h"
27 #include "tree.h"
28 #include "gimple.h"
29 #include "target.h"
30 #include "cgraph.h"
31 #include "vec.h"
32 #include "vecprim.h"
33 #include "alloc-pool.h"
34 #include "gcov-io.h"
36 /* Forward declarations to avoid included unnecessary headers. */
37 struct output_block;
38 struct lto_input_block;
39 struct data_in;
40 struct bitpack_d;
42 /* Define when debugging the LTO streamer. This causes the writer
43 to output the numeric value for the memory address of the tree node
44 being emitted. When debugging a problem in the reader, check the
45 original address that the writer was emitting using lto_orig_address_get.
46 With this value, set a breakpoint in the writer (e.g., lto_output_tree)
47 to trace how the faulty node is being emitted. */
48 /* #define LTO_STREAMER_DEBUG 1 */
50 /* Streamer hooks. These functions do additional processing as
51 needed by the module. There are two types of callbacks, those that
52 replace the default behavior and those that supplement it. Any
53 or all of these hooks can be NULL. */
54 typedef struct lto_streamer_hooks {
55 /* A string identifying this streamer. */
56 const char *name;
58 /* Called by lto_reader_init after it does basic initialization. */
59 void (*reader_init) (void);
61 /* Called by lto_writer_init after it does basic initalization. */
62 void (*writer_init) (void);
64 /* Return true if the given tree is supported by this streamer. */
65 bool (*is_streamable) (tree);
67 /* Called by lto_write_tree after writing all the common parts of
68 a tree. If defined, the callback is in charge of writing all
69 the fields that lto_write_tree did not write out. Arguments
70 are as in lto_write_tree.
72 The following tree fields are not handled by common code:
74 DECL_ABSTRACT_ORIGIN
75 DECL_INITIAL
76 DECL_SAVED_TREE
78 Callbacks may choose to ignore or handle them. If handled,
79 the reader should read them in the exact same sequence written
80 by the writer. */
81 void (*write_tree) (struct output_block *, tree, bool);
83 /* Called by lto_read_tree after reading all the common parts of
84 a tree. If defined, the callback is in charge of reading all
85 the fields that lto_read_tree did not read in. Arguments
86 are as in lto_read_tree. */
87 void (*read_tree) (struct lto_input_block *, struct data_in *, tree);
89 /* Called by pack_value_fields to store any non-pointer fields
90 in the tree structure. The arguments are as in pack_value_fields. */
91 void (*pack_value_fields) (struct bitpack_d *, tree);
93 /* Called by unpack_value_fields to retrieve any non-pointer fields
94 in the tree structure. The arguments are as in unpack_value_fields. */
95 void (*unpack_value_fields) (struct bitpack_d *, tree);
96 } lto_streamer_hooks;
99 /* The encoding for a function consists of the following sections:
101 1) The header.
102 2) FIELD_DECLS.
103 3) FUNCTION_DECLS.
104 4) global VAR_DECLS.
105 5) type_decls
106 6) types.
107 7) Names for the labels that have names
108 8) The SSA names.
109 9) The control flow graph.
110 10-11)Gimple for local decls.
111 12) Gimple for the function.
112 13) Strings.
114 1) THE HEADER.
115 2-6) THE GLOBAL DECLS AND TYPES.
117 The global decls and types are encoded in the same way. For each
118 entry, there is word with the offset within the section to the
119 entry.
121 7) THE LABEL NAMES.
123 Since most labels do not have names, this section my be of zero
124 length. It consists of an array of string table references, one
125 per label. In the lto code, the labels are given either
126 positive or negative indexes. the positive ones have names and
127 the negative ones do not. The positive index can be used to
128 find the name in this array.
130 9) THE CFG.
132 10) Index into the local decls. Since local decls can have local
133 decls inside them, they must be read in randomly in order to
134 properly restore them.
136 11-12) GIMPLE FOR THE LOCAL DECLS AND THE FUNCTION BODY.
138 The gimple consists of a set of records.
140 THE FUNCTION
142 At the top level of (8) is the function. It consists of five
143 pieces:
145 LTO_function - The tag.
146 eh tree - This is all of the exception handling regions
147 put out in a post order traversial of the
148 tree. Siblings are output as lists terminated
149 by a 0. The set of fields matches the fields
150 defined in except.c.
152 last_basic_block - in uleb128 form.
154 basic blocks - This is the set of basic blocks.
156 zero - The termination of the basic blocks.
158 BASIC BLOCKS
160 There are two forms of basic blocks depending on if they are
161 empty or not.
163 The basic block consists of:
165 LTO_bb1 or LTO_bb0 - The tag.
167 bb->index - the index in uleb128 form.
169 #succs - The number of successors un uleb128 form.
171 the successors - For each edge, a pair. The first of the
172 pair is the index of the successor in
173 uleb128 form and the second are the flags in
174 uleb128 form.
176 the statements - A gimple tree, as described above.
177 These are only present for LTO_BB1.
178 Following each statement is an optional
179 exception handling record LTO_eh_region
180 which contains the region number (for
181 regions >= 0).
183 zero - This is only present for LTO_BB1 and is used
184 to terminate the statements and exception
185 regions within this block.
187 12) STRINGS
189 String are represented in the table as pairs, a length in ULEB128
190 form followed by the data for the string. */
192 /* The string that is the prefix on the section names we make for lto.
193 For decls the DECL_ASSEMBLER_NAME is appended to make the section
194 name for the functions and static_initializers. For other types of
195 sections a '.' and the section type are appended. */
196 #define LTO_SECTION_NAME_PREFIX ".gnu.lto_"
198 #define LTO_major_version 2
199 #define LTO_minor_version 0
201 typedef unsigned char lto_decl_flags_t;
204 /* Data structures used to pack values and bitflags into a vector of
205 words. Used to stream values of a fixed number of bits in a space
206 efficient way. */
207 static unsigned const BITS_PER_BITPACK_WORD = HOST_BITS_PER_WIDE_INT;
209 typedef unsigned HOST_WIDE_INT bitpack_word_t;
210 DEF_VEC_I(bitpack_word_t);
211 DEF_VEC_ALLOC_I(bitpack_word_t, heap);
213 struct bitpack_d
215 /* The position of the first unused or unconsumed bit in the word. */
216 unsigned pos;
218 /* The current word we are (un)packing. */
219 bitpack_word_t word;
221 /* The lto_output_stream or the lto_input_block we are streaming to/from. */
222 void *stream;
225 /* Tags representing the various IL objects written to the bytecode file
226 (GIMPLE statements, basic blocks, EH regions, tree nodes, etc).
228 NOTE, when adding new LTO tags, also update lto_tag_name. */
229 enum LTO_tags
231 LTO_null = 0,
233 /* Reserve enough entries to fit all the tree and gimple codes handled
234 by the streamer. This guarantees that:
236 1- Given a tree code C:
237 enum LTO_tags tag == C + 1
239 2- Given a gimple code C:
240 enum LTO_tags tag == C + NUM_TREE_CODES + 1
242 Conversely, to map between LTO tags and tree/gimple codes, the
243 reverse operation must be applied. */
244 LTO_bb0 = 1 + NUM_TREE_CODES + LAST_AND_UNUSED_GIMPLE_CODE,
245 LTO_bb1,
247 /* EH region holding the previous statement. */
248 LTO_eh_region,
250 /* An MD or NORMAL builtin. Only the code and class are streamed out. */
251 LTO_builtin_decl,
253 /* Function body. */
254 LTO_function,
256 /* EH table. */
257 LTO_eh_table,
259 /* EH region types. These mirror enum eh_region_type. */
260 LTO_ert_cleanup,
261 LTO_ert_try,
262 LTO_ert_allowed_exceptions,
263 LTO_ert_must_not_throw,
265 /* EH landing pad. */
266 LTO_eh_landing_pad,
268 /* EH try/catch node. */
269 LTO_eh_catch,
271 /* Special for global streamer. Reference to previously-streamed node. */
272 LTO_tree_pickle_reference,
274 /* References to indexable tree nodes. These objects are stored in
275 tables that are written separately from the function bodies that
276 reference them. This way they can be instantiated even when the
277 referencing functions aren't (e.g., during WPA) and it also allows
278 functions to be copied from one file to another without having
279 to unpickle the body first (the references are location
280 independent).
282 NOTE, do not regroup these values as the grouping is exposed
283 in the range checks done in lto_input_tree. */
284 LTO_field_decl_ref, /* Do not change. */
285 LTO_function_decl_ref,
286 LTO_label_decl_ref,
287 LTO_namespace_decl_ref,
288 LTO_result_decl_ref,
289 LTO_ssa_name_ref,
290 LTO_type_decl_ref,
291 LTO_type_ref,
292 LTO_const_decl_ref,
293 LTO_imported_decl_ref,
294 LTO_translation_unit_decl_ref,
295 LTO_global_decl_ref, /* Do not change. */
297 /* This tag must always be last. */
298 LTO_NUM_TAGS
302 /* Set of section types that are in an LTO file. This list will grow
303 as the number of IPA passes grows since each IPA pass will need its
304 own section type to store its summary information.
306 When adding a new section type, you must also extend the
307 LTO_SECTION_NAME array in lto-section-in.c. */
308 enum lto_section_type
310 LTO_section_decls = 0,
311 LTO_section_function_body,
312 LTO_section_static_initializer,
313 LTO_section_cgraph,
314 LTO_section_varpool,
315 LTO_section_refs,
316 LTO_section_jump_functions,
317 LTO_section_ipa_pure_const,
318 LTO_section_ipa_reference,
319 LTO_section_symtab,
320 LTO_section_opts,
321 LTO_section_cgraph_opt_sum,
322 LTO_N_SECTION_TYPES /* Must be last. */
325 /* Indices to the various function, type and symbol streams. */
326 typedef enum
328 LTO_DECL_STREAM_TYPE = 0, /* Must be first. */
329 LTO_DECL_STREAM_FIELD_DECL,
330 LTO_DECL_STREAM_FN_DECL,
331 LTO_DECL_STREAM_VAR_DECL,
332 LTO_DECL_STREAM_TYPE_DECL,
333 LTO_DECL_STREAM_NAMESPACE_DECL,
334 LTO_DECL_STREAM_LABEL_DECL,
335 LTO_N_DECL_STREAMS
336 } lto_decl_stream_e_t;
338 typedef enum ld_plugin_symbol_resolution ld_plugin_symbol_resolution_t;
339 DEF_VEC_I(ld_plugin_symbol_resolution_t);
340 DEF_VEC_ALLOC_I(ld_plugin_symbol_resolution_t, heap);
343 /* Macro to define convenience functions for type and decl streams
344 in lto_file_decl_data. */
345 #define DEFINE_DECL_STREAM_FUNCS(UPPER_NAME, name) \
346 static inline tree \
347 lto_file_decl_data_get_ ## name (struct lto_file_decl_data *data, \
348 unsigned int idx) \
350 struct lto_in_decl_state *state = data->current_decl_state; \
351 gcc_assert (idx < state->streams[LTO_DECL_STREAM_## UPPER_NAME].size); \
352 return state->streams[LTO_DECL_STREAM_## UPPER_NAME].trees[idx]; \
355 static inline unsigned int \
356 lto_file_decl_data_num_ ## name ## s (struct lto_file_decl_data *data) \
358 struct lto_in_decl_state *state = data->current_decl_state; \
359 return state->streams[LTO_DECL_STREAM_## UPPER_NAME].size; \
363 /* Return a char pointer to the start of a data stream for an lto pass
364 or function. The first parameter is the file data that contains
365 the information. The second parameter is the type of information
366 to be obtained. The third parameter is the name of the function
367 and is only used when finding a function body; otherwise it is
368 NULL. The fourth parameter is the length of the data returned. */
369 typedef const char* (lto_get_section_data_f) (struct lto_file_decl_data *,
370 enum lto_section_type,
371 const char *,
372 size_t *);
374 /* Return the data found from the above call. The first three
375 parameters are the same as above. The fourth parameter is the data
376 itself and the fifth is the lenght of the data. */
377 typedef void (lto_free_section_data_f) (struct lto_file_decl_data *,
378 enum lto_section_type,
379 const char *,
380 const char *,
381 size_t);
383 /* Cache of pickled nodes. Used to avoid writing the same node more
384 than once. The first time a tree node is streamed out, it is
385 entered in this cache. Subsequent references to the same node are
386 resolved by looking it up in this cache.
388 This is used in two ways:
390 - On the writing side, the first time T is added to STREAMER_CACHE,
391 a new reference index is created for T and T is emitted on the
392 stream. If T needs to be emitted again to the stream, instead of
393 pickling it again, the reference index is emitted.
395 - On the reading side, the first time T is read from the stream, it
396 is reconstructed in memory and a new reference index created for
397 T. The reconstructed T is inserted in some array so that when
398 the reference index for T is found in the input stream, it can be
399 used to look up into the array to get the reconstructed T. */
400 struct lto_streamer_cache_d
402 /* The mapping between tree nodes and slots into the nodes array. */
403 htab_t node_map;
405 /* Node map to store entries into. */
406 alloc_pool node_map_entries;
408 /* Next available slot in the nodes and offsets arrays. */
409 unsigned next_slot;
411 /* The nodes pickled so far. */
412 VEC(tree,heap) *nodes;
414 /* Offset into the stream where the nodes have been written. */
415 VEC(unsigned,heap) *offsets;
419 /* Structure used as buffer for reading an LTO file. */
420 struct lto_input_block
422 const char *data;
423 unsigned int p;
424 unsigned int len;
427 #define LTO_INIT_INPUT_BLOCK(BASE,D,P,L) \
428 do { \
429 BASE.data = D; \
430 BASE.p = P; \
431 BASE.len = L; \
432 } while (0)
434 #define LTO_INIT_INPUT_BLOCK_PTR(BASE,D,P,L) \
435 do { \
436 BASE->data = D; \
437 BASE->p = P; \
438 BASE->len = L; \
439 } while (0)
442 /* The is the first part of the record for a function or constructor
443 in the .o file. */
444 struct lto_header
446 int16_t major_version;
447 int16_t minor_version;
448 enum lto_section_type section_type;
451 /* The header for a function body. */
452 struct lto_function_header
454 /* The header for all types of sections. */
455 struct lto_header lto_header;
457 /* Number of labels with names. */
458 int32_t num_named_labels;
460 /* Number of labels without names. */
461 int32_t num_unnamed_labels;
463 /* Size compressed or 0 if not compressed. */
464 int32_t compressed_size;
466 /* Size of names for named labels. */
467 int32_t named_label_size;
469 /* Size of the cfg. */
470 int32_t cfg_size;
472 /* Size of main gimple body of function. */
473 int32_t main_size;
475 /* Size of the string table. */
476 int32_t string_size;
480 /* Structure describing a symbol section. */
481 struct lto_decl_header
483 /* The header for all types of sections. */
484 struct lto_header lto_header;
486 /* Size of region for decl state. */
487 int32_t decl_state_size;
489 /* Number of nodes in globals stream. */
490 int32_t num_nodes;
492 /* Size of region for expressions, decls, types, etc. */
493 int32_t main_size;
495 /* Size of the string table. */
496 int32_t string_size;
500 /* Statistics gathered during LTO, WPA and LTRANS. */
501 struct lto_stats_d
503 unsigned HOST_WIDE_INT num_input_cgraph_nodes;
504 unsigned HOST_WIDE_INT num_output_cgraph_nodes;
505 unsigned HOST_WIDE_INT num_input_files;
506 unsigned HOST_WIDE_INT num_output_files;
507 unsigned HOST_WIDE_INT num_cgraph_partitions;
508 unsigned HOST_WIDE_INT section_size[LTO_N_SECTION_TYPES];
509 unsigned HOST_WIDE_INT num_function_bodies;
510 unsigned HOST_WIDE_INT num_trees[NUM_TREE_CODES];
511 unsigned HOST_WIDE_INT num_output_il_bytes;
512 unsigned HOST_WIDE_INT num_compressed_il_bytes;
513 unsigned HOST_WIDE_INT num_input_il_bytes;
514 unsigned HOST_WIDE_INT num_uncompressed_il_bytes;
517 /* Encoder data structure used to stream callgraph nodes. */
518 struct lto_cgraph_encoder_d
520 /* Map nodes to reference number. */
521 struct pointer_map_t *map;
523 /* Map reference number to node. */
524 VEC(cgraph_node_ptr,heap) *nodes;
526 /* Map of nodes where we want to output body. */
527 struct pointer_set_t *body;
530 typedef struct lto_cgraph_encoder_d *lto_cgraph_encoder_t;
532 /* Return number of encoded nodes in ENCODER. */
534 static inline int
535 lto_cgraph_encoder_size (lto_cgraph_encoder_t encoder)
537 return VEC_length (cgraph_node_ptr, encoder->nodes);
541 /* Encoder data structure used to stream callgraph nodes. */
542 struct lto_varpool_encoder_d
544 /* Map nodes to reference number. */
545 struct pointer_map_t *map;
547 /* Map reference number to node. */
548 VEC(varpool_node_ptr,heap) *nodes;
550 /* Map of nodes where we want to output initializer. */
551 struct pointer_set_t *initializer;
553 typedef struct lto_varpool_encoder_d *lto_varpool_encoder_t;
555 /* Return number of encoded nodes in ENCODER. */
557 static inline int
558 lto_varpool_encoder_size (lto_varpool_encoder_t encoder)
560 return VEC_length (varpool_node_ptr, encoder->nodes);
563 /* Mapping from indices to trees. */
564 struct GTY(()) lto_tree_ref_table
566 /* Array of referenced trees . */
567 tree * GTY((length ("%h.size"))) trees;
569 /* Size of array. */
570 unsigned int size;
574 /* Mapping between trees and slots in an array. */
575 struct lto_decl_slot
577 tree t;
578 int slot_num;
582 /* The lto_tree_ref_encoder struct is used to encode trees into indices. */
584 struct lto_tree_ref_encoder
586 htab_t tree_hash_table; /* Maps pointers to indices. */
587 unsigned int next_index; /* Next available index. */
588 VEC(tree,heap) *trees; /* Maps indices to pointers. */
592 /* Structure to hold states of input scope. */
593 struct GTY(()) lto_in_decl_state
595 /* Array of lto_in_decl_buffers to store type and decls streams. */
596 struct lto_tree_ref_table streams[LTO_N_DECL_STREAMS];
598 /* If this in-decl state is associated with a function. FN_DECL
599 point to the FUNCTION_DECL. */
600 tree fn_decl;
603 typedef struct lto_in_decl_state *lto_in_decl_state_ptr;
606 /* The structure that holds all of the vectors of global types,
607 decls and cgraph nodes used in the serialization of this file. */
608 struct lto_out_decl_state
610 /* The buffers contain the sets of decls of various kinds and types we have
611 seen so far and the indexes assigned to them. */
612 struct lto_tree_ref_encoder streams[LTO_N_DECL_STREAMS];
614 /* Encoder for cgraph nodes. */
615 lto_cgraph_encoder_t cgraph_node_encoder;
617 /* Encoder for varpool nodes. */
618 lto_varpool_encoder_t varpool_node_encoder;
620 /* If this out-decl state belongs to a function, fn_decl points to that
621 function. Otherwise, it is NULL. */
622 tree fn_decl;
625 typedef struct lto_out_decl_state *lto_out_decl_state_ptr;
627 DEF_VEC_P(lto_out_decl_state_ptr);
628 DEF_VEC_ALLOC_P(lto_out_decl_state_ptr, heap);
630 /* One of these is allocated for each object file that being compiled
631 by lto. This structure contains the tables that are needed by the
632 serialized functions and ipa passes to connect themselves to the
633 global types and decls as they are reconstituted. */
634 struct GTY(()) lto_file_decl_data
636 /* Decl state currently used. */
637 struct lto_in_decl_state *current_decl_state;
639 /* Decl state corresponding to regions outside of any functions
640 in the compilation unit. */
641 struct lto_in_decl_state *global_decl_state;
643 /* Table of cgraph nodes present in this file. */
644 lto_cgraph_encoder_t GTY((skip)) cgraph_node_encoder;
646 /* Table of varpool nodes present in this file. */
647 lto_varpool_encoder_t GTY((skip)) varpool_node_encoder;
649 /* Hash table maps lto-related section names to location in file. */
650 htab_t GTY((param_is (struct lto_in_decl_state))) function_decl_states;
652 /* The .o file that these offsets relate to. */
653 const char *GTY((skip)) file_name;
655 /* Hash table maps lto-related section names to location in file. */
656 htab_t GTY((skip)) section_hash_table;
658 /* Hash new name of renamed global declaration to its original name. */
659 htab_t GTY((skip)) renaming_hash_table;
661 /* Linked list used temporarily in reader */
662 struct lto_file_decl_data *next;
664 /* Sub ID for merged objects. */
665 unsigned id;
667 /* Symbol resolutions for this file */
668 VEC(ld_plugin_symbol_resolution_t,heap) * GTY((skip)) resolutions;
670 struct gcov_ctr_summary GTY((skip)) profile_info;
673 typedef struct lto_file_decl_data *lto_file_decl_data_ptr;
675 struct lto_char_ptr_base
677 char *ptr;
680 /* An incore byte stream to buffer the various parts of the function.
681 The entire structure should be zeroed when created. The record
682 consists of a set of blocks. The first sizeof (ptr) bytes are used
683 as a chain, and the rest store the bytes to be written. */
684 struct lto_output_stream
686 /* The pointer to the first block in the stream. */
687 struct lto_char_ptr_base * first_block;
689 /* The pointer to the last and current block in the stream. */
690 struct lto_char_ptr_base * current_block;
692 /* The pointer to where the next char should be written. */
693 char * current_pointer;
695 /* The number of characters left in the current block. */
696 unsigned int left_in_block;
698 /* The block size of the last block allocated. */
699 unsigned int block_size;
701 /* The total number of characters written. */
702 unsigned int total_size;
705 /* The is the first part of the record in an LTO file for many of the
706 IPA passes. */
707 struct lto_simple_header
709 /* The header for all types of sections. */
710 struct lto_header lto_header;
712 /* Size of main gimple body of function. */
713 int32_t main_size;
715 /* Size of main stream when compressed. */
716 int32_t compressed_size;
719 /* A simple output block. This can be used for simple IPA passes that
720 do not need more than one stream. */
721 struct lto_simple_output_block
723 enum lto_section_type section_type;
724 struct lto_out_decl_state *decl_state;
726 /* The stream that the main tree codes are written to. */
727 struct lto_output_stream *main_stream;
730 /* Data structure holding all the data and descriptors used when writing
731 an LTO file. */
732 struct output_block
734 enum lto_section_type section_type;
735 struct lto_out_decl_state *decl_state;
737 /* The stream that the main tree codes are written to. */
738 struct lto_output_stream *main_stream;
740 /* The stream that contains the string table. */
741 struct lto_output_stream *string_stream;
743 /* The stream that contains the cfg. */
744 struct lto_output_stream *cfg_stream;
746 /* The hash table that contains the set of strings we have seen so
747 far and the indexes assigned to them. */
748 htab_t string_hash_table;
750 /* The current cgraph_node that we are currently serializing. Null
751 if we are serializing something else. */
752 struct cgraph_node *cgraph_node;
754 /* These are the last file and line that were seen in the stream.
755 If the current node differs from these, it needs to insert
756 something into the stream and fix these up. */
757 const char *current_file;
758 int current_line;
759 int current_col;
761 /* True if writing globals and types. */
762 bool global;
764 /* Cache of nodes written in this section. */
765 struct lto_streamer_cache_d *writer_cache;
769 /* Data and descriptors used when reading from an LTO file. */
770 struct data_in
772 /* The global decls and types. */
773 struct lto_file_decl_data *file_data;
775 /* All of the labels. */
776 tree *labels;
778 /* The string table. */
779 const char *strings;
781 /* The length of the string table. */
782 unsigned int strings_len;
784 /* Number of named labels. Used to find the index of unnamed labels
785 since they share space with the named labels. */
786 unsigned int num_named_labels;
788 /* Number of unnamed labels. */
789 unsigned int num_unnamed_labels;
791 const char *current_file;
792 int current_line;
793 int current_col;
795 /* Maps each reference number to the resolution done by the linker. */
796 VEC(ld_plugin_symbol_resolution_t,heap) *globals_resolution;
798 /* Cache of pickled nodes. */
799 struct lto_streamer_cache_d *reader_cache;
803 /* In lto-section-in.c */
804 extern struct lto_input_block * lto_create_simple_input_block (
805 struct lto_file_decl_data *,
806 enum lto_section_type, const char **, size_t *);
807 extern void
808 lto_destroy_simple_input_block (struct lto_file_decl_data *,
809 enum lto_section_type,
810 struct lto_input_block *, const char *, size_t);
811 extern void lto_set_in_hooks (struct lto_file_decl_data **,
812 lto_get_section_data_f *,
813 lto_free_section_data_f *);
814 extern struct lto_file_decl_data **lto_get_file_decl_data (void);
815 extern const char *lto_get_section_data (struct lto_file_decl_data *,
816 enum lto_section_type,
817 const char *, size_t *);
818 extern void lto_free_section_data (struct lto_file_decl_data *,
819 enum lto_section_type,
820 const char *, const char *, size_t);
821 extern unsigned char lto_input_1_unsigned (struct lto_input_block *);
822 extern unsigned HOST_WIDE_INT lto_input_uleb128 (struct lto_input_block *);
823 extern unsigned HOST_WIDEST_INT lto_input_widest_uint_uleb128 (
824 struct lto_input_block *);
825 extern HOST_WIDE_INT lto_input_sleb128 (struct lto_input_block *);
826 extern htab_t lto_create_renaming_table (void);
827 extern void lto_record_renamed_decl (struct lto_file_decl_data *,
828 const char *, const char *);
829 extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data *,
830 const char *);
831 extern struct lto_in_decl_state *lto_new_in_decl_state (void);
832 extern void lto_delete_in_decl_state (struct lto_in_decl_state *);
833 extern hashval_t lto_hash_in_decl_state (const void *);
834 extern int lto_eq_in_decl_state (const void *, const void *);
835 extern struct lto_in_decl_state *lto_get_function_in_decl_state (
836 struct lto_file_decl_data *, tree);
838 /* In lto-section-out.c */
839 extern hashval_t lto_hash_decl_slot_node (const void *);
840 extern int lto_eq_decl_slot_node (const void *, const void *);
841 extern hashval_t lto_hash_type_slot_node (const void *);
842 extern int lto_eq_type_slot_node (const void *, const void *);
843 extern void lto_begin_section (const char *, bool);
844 extern void lto_end_section (void);
845 extern void lto_write_stream (struct lto_output_stream *);
846 extern void lto_output_1_stream (struct lto_output_stream *, char);
847 extern void lto_output_data_stream (struct lto_output_stream *, const void *,
848 size_t);
849 extern void lto_output_uleb128_stream (struct lto_output_stream *,
850 unsigned HOST_WIDE_INT);
851 extern void lto_output_widest_uint_uleb128_stream (struct lto_output_stream *,
852 unsigned HOST_WIDEST_INT);
853 extern void lto_output_sleb128_stream (struct lto_output_stream *,
854 HOST_WIDE_INT);
855 extern bool lto_output_decl_index (struct lto_output_stream *,
856 struct lto_tree_ref_encoder *,
857 tree, unsigned int *);
858 extern void lto_output_field_decl_index (struct lto_out_decl_state *,
859 struct lto_output_stream *, tree);
860 extern void lto_output_fn_decl_index (struct lto_out_decl_state *,
861 struct lto_output_stream *, tree);
862 extern void lto_output_namespace_decl_index (struct lto_out_decl_state *,
863 struct lto_output_stream *, tree);
864 extern void lto_output_var_decl_index (struct lto_out_decl_state *,
865 struct lto_output_stream *, tree);
866 extern void lto_output_type_decl_index (struct lto_out_decl_state *,
867 struct lto_output_stream *, tree);
868 extern void lto_output_type_ref_index (struct lto_out_decl_state *,
869 struct lto_output_stream *, tree);
870 extern struct lto_simple_output_block *lto_create_simple_output_block (
871 enum lto_section_type);
872 extern void lto_destroy_simple_output_block (struct lto_simple_output_block *);
873 extern struct lto_out_decl_state *lto_new_out_decl_state (void);
874 extern void lto_delete_out_decl_state (struct lto_out_decl_state *);
875 extern struct lto_out_decl_state *lto_get_out_decl_state (void);
876 extern void lto_push_out_decl_state (struct lto_out_decl_state *);
877 extern struct lto_out_decl_state *lto_pop_out_decl_state (void);
878 extern void lto_record_function_out_decl_state (tree,
879 struct lto_out_decl_state *);
882 /* In lto-streamer.c. */
883 extern const char *lto_tag_name (enum LTO_tags);
884 extern bitmap lto_bitmap_alloc (void);
885 extern void lto_bitmap_free (bitmap);
886 extern char *lto_get_section_name (int, const char *, struct lto_file_decl_data *);
887 extern void print_lto_report (void);
888 extern bool lto_streamer_cache_insert (struct lto_streamer_cache_d *, tree,
889 int *, unsigned *);
890 extern bool lto_streamer_cache_insert_at (struct lto_streamer_cache_d *, tree,
891 int);
892 extern bool lto_streamer_cache_lookup (struct lto_streamer_cache_d *, tree,
893 int *);
894 extern tree lto_streamer_cache_get (struct lto_streamer_cache_d *, int);
895 extern struct lto_streamer_cache_d *lto_streamer_cache_create (void);
896 extern void lto_streamer_cache_delete (struct lto_streamer_cache_d *);
897 extern void lto_streamer_init (void);
898 extern bool gate_lto_out (void);
899 #ifdef LTO_STREAMER_DEBUG
900 extern void lto_orig_address_map (tree, intptr_t);
901 extern intptr_t lto_orig_address_get (tree);
902 extern void lto_orig_address_remove (tree);
903 #endif
904 extern void lto_check_version (int, int);
905 extern void gimple_streamer_hooks_init (void);
906 extern void gimple_streamer_write_tree (struct output_block *, tree, bool);
907 extern void gimple_streamer_read_tree (struct lto_input_block *,
908 struct data_in *, tree);
909 extern lto_streamer_hooks *streamer_hooks (void);
910 extern lto_streamer_hooks *streamer_hooks_init (void);
912 /* In lto-streamer-in.c */
913 extern void lto_input_cgraph (struct lto_file_decl_data *, const char *);
914 extern void lto_reader_init (void);
915 extern tree lto_input_tree (struct lto_input_block *, struct data_in *);
916 extern void lto_input_function_body (struct lto_file_decl_data *, tree,
917 const char *);
918 extern void lto_input_constructors_and_inits (struct lto_file_decl_data *,
919 const char *);
920 extern struct data_in *lto_data_in_create (struct lto_file_decl_data *,
921 const char *, unsigned,
922 VEC(ld_plugin_symbol_resolution_t,heap) *);
923 extern void lto_data_in_delete (struct data_in *);
924 extern const char *lto_input_string (struct data_in *,
925 struct lto_input_block *);
926 extern void lto_input_data_block (struct lto_input_block *, void *, size_t);
927 extern void gimple_streamer_reader_init (void);
930 /* In lto-streamer-out.c */
931 extern void lto_writer_init (void);
932 extern void lto_register_decl_definition (tree, struct lto_file_decl_data *);
933 extern struct output_block *create_output_block (enum lto_section_type);
934 extern void destroy_output_block (struct output_block *);
935 extern void lto_output_tree (struct output_block *, tree, bool);
936 extern void lto_output_tree_or_ref (struct output_block *, tree, bool);
937 extern void produce_asm (struct output_block *ob, tree fn);
938 extern void lto_output_string (struct output_block *,
939 struct lto_output_stream *,
940 const char *);
941 extern void lto_output_string_with_length (struct output_block *,
942 struct lto_output_stream *,
943 const char *,
944 unsigned int);
945 void lto_output_decl_state_streams (struct output_block *,
946 struct lto_out_decl_state *);
947 void lto_output_decl_state_refs (struct output_block *,
948 struct lto_output_stream *,
949 struct lto_out_decl_state *);
952 /* In lto-cgraph.c */
953 struct cgraph_node *lto_cgraph_encoder_deref (lto_cgraph_encoder_t, int);
954 int lto_cgraph_encoder_lookup (lto_cgraph_encoder_t, struct cgraph_node *);
955 lto_cgraph_encoder_t lto_cgraph_encoder_new (void);
956 int lto_cgraph_encoder_encode (lto_cgraph_encoder_t, struct cgraph_node *);
957 void lto_cgraph_encoder_delete (lto_cgraph_encoder_t);
958 bool lto_cgraph_encoder_encode_body_p (lto_cgraph_encoder_t,
959 struct cgraph_node *);
961 bool lto_varpool_encoder_encode_body_p (lto_varpool_encoder_t,
962 struct varpool_node *);
963 struct varpool_node *lto_varpool_encoder_deref (lto_varpool_encoder_t, int);
964 int lto_varpool_encoder_lookup (lto_varpool_encoder_t, struct varpool_node *);
965 lto_varpool_encoder_t lto_varpool_encoder_new (void);
966 int lto_varpool_encoder_encode (lto_varpool_encoder_t, struct varpool_node *);
967 void lto_varpool_encoder_delete (lto_varpool_encoder_t);
968 bool lto_varpool_encoder_encode_initializer_p (lto_varpool_encoder_t,
969 struct varpool_node *);
970 void output_cgraph (cgraph_node_set, varpool_node_set);
971 void input_cgraph (void);
972 bool referenced_from_other_partition_p (struct ipa_ref_list *,
973 cgraph_node_set,
974 varpool_node_set vset);
975 bool reachable_from_other_partition_p (struct cgraph_node *,
976 cgraph_node_set);
977 bool referenced_from_this_partition_p (struct ipa_ref_list *,
978 cgraph_node_set,
979 varpool_node_set vset);
980 bool reachable_from_this_partition_p (struct cgraph_node *,
981 cgraph_node_set);
982 void compute_ltrans_boundary (struct lto_out_decl_state *state,
983 cgraph_node_set, varpool_node_set);
986 /* In lto-symtab.c. */
987 extern void lto_symtab_register_decl (tree, ld_plugin_symbol_resolution_t,
988 struct lto_file_decl_data *);
989 extern void lto_symtab_merge_decls (void);
990 extern void lto_symtab_merge_cgraph_nodes (void);
991 extern tree lto_symtab_prevailing_decl (tree decl);
992 extern enum ld_plugin_symbol_resolution lto_symtab_get_resolution (tree decl);
993 extern void lto_symtab_free (void);
994 extern GTY(()) VEC(tree,gc) *lto_global_var_decls;
997 /* In lto-opts.c. */
998 extern void lto_register_user_option (size_t, const char *, int, int);
999 extern void lto_read_file_options (struct lto_file_decl_data *);
1000 extern void lto_write_options (void);
1001 extern void lto_reissue_options (void);
1002 void lto_clear_user_options (void);
1003 void lto_clear_file_options (void);
1006 /* In lto-wpa-fixup.c */
1007 void lto_mark_nothrow_fndecl (tree);
1008 void lto_fixup_nothrow_decls (void);
1011 /* Statistics gathered during LTO, WPA and LTRANS. */
1012 extern struct lto_stats_d lto_stats;
1014 /* Section names corresponding to the values of enum lto_section_type. */
1015 extern const char *lto_section_name[];
1017 /* Holds all the out decl states of functions output so far in the
1018 current output file. */
1019 extern VEC(lto_out_decl_state_ptr, heap) *lto_function_decl_states;
1021 /* Return true if LTO tag TAG corresponds to a tree code. */
1022 static inline bool
1023 lto_tag_is_tree_code_p (enum LTO_tags tag)
1025 return tag > LTO_null && (unsigned) tag <= NUM_TREE_CODES;
1029 /* Return true if LTO tag TAG corresponds to a gimple code. */
1030 static inline bool
1031 lto_tag_is_gimple_code_p (enum LTO_tags tag)
1033 return (unsigned) tag >= NUM_TREE_CODES + 1
1034 && (unsigned) tag < 1 + NUM_TREE_CODES + LAST_AND_UNUSED_GIMPLE_CODE;
1038 /* Return the LTO tag corresponding to gimple code CODE. See enum
1039 LTO_tags for details on the conversion. */
1040 static inline enum LTO_tags
1041 lto_gimple_code_to_tag (enum gimple_code code)
1043 return (enum LTO_tags) ((unsigned) code + NUM_TREE_CODES + 1);
1047 /* Return the GIMPLE code corresponding to TAG. See enum LTO_tags for
1048 details on the conversion. */
1049 static inline enum gimple_code
1050 lto_tag_to_gimple_code (enum LTO_tags tag)
1052 gcc_assert (lto_tag_is_gimple_code_p (tag));
1053 return (enum gimple_code) ((unsigned) tag - NUM_TREE_CODES - 1);
1057 /* Return the LTO tag corresponding to tree code CODE. See enum
1058 LTO_tags for details on the conversion. */
1059 static inline enum LTO_tags
1060 lto_tree_code_to_tag (enum tree_code code)
1062 return (enum LTO_tags) ((unsigned) code + 1);
1066 /* Return the tree code corresponding to TAG. See enum LTO_tags for
1067 details on the conversion. */
1068 static inline enum tree_code
1069 lto_tag_to_tree_code (enum LTO_tags tag)
1071 gcc_assert (lto_tag_is_tree_code_p (tag));
1072 return (enum tree_code) ((unsigned) tag - 1);
1075 /* Initialize an lto_out_decl_buffer ENCODER. */
1076 static inline void
1077 lto_init_tree_ref_encoder (struct lto_tree_ref_encoder *encoder,
1078 htab_hash hash_fn, htab_eq eq_fn)
1080 encoder->tree_hash_table = htab_create (37, hash_fn, eq_fn, free);
1081 encoder->next_index = 0;
1082 encoder->trees = NULL;
1086 /* Destory an lto_tree_ref_encoder ENCODER by freeing its contents. The
1087 memory used by ENCODER is not freed by this function. */
1088 static inline void
1089 lto_destroy_tree_ref_encoder (struct lto_tree_ref_encoder *encoder)
1091 /* Hash table may be delete already. */
1092 if (encoder->tree_hash_table)
1093 htab_delete (encoder->tree_hash_table);
1094 VEC_free (tree, heap, encoder->trees);
1097 /* Return the number of trees encoded in ENCODER. */
1098 static inline unsigned int
1099 lto_tree_ref_encoder_size (struct lto_tree_ref_encoder *encoder)
1101 return VEC_length (tree, encoder->trees);
1104 /* Return the IDX-th tree in ENCODER. */
1105 static inline tree
1106 lto_tree_ref_encoder_get_tree (struct lto_tree_ref_encoder *encoder,
1107 unsigned int idx)
1109 return VEC_index (tree, encoder->trees, idx);
1113 /* Return true if LABEL should be emitted in the global context. */
1114 static inline bool
1115 emit_label_in_global_context_p (tree label)
1117 return DECL_NONLOCAL (label) || FORCED_LABEL (label);
1120 /* Return true if tree node EXPR should be streamed as a builtin. For
1121 these nodes, we just emit the class and function code. */
1122 static inline bool
1123 lto_stream_as_builtin_p (tree expr)
1125 return (TREE_CODE (expr) == FUNCTION_DECL
1126 && DECL_IS_BUILTIN (expr)
1127 && (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_NORMAL
1128 || DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD));
1131 DEFINE_DECL_STREAM_FUNCS (TYPE, type)
1132 DEFINE_DECL_STREAM_FUNCS (FIELD_DECL, field_decl)
1133 DEFINE_DECL_STREAM_FUNCS (FN_DECL, fn_decl)
1134 DEFINE_DECL_STREAM_FUNCS (VAR_DECL, var_decl)
1135 DEFINE_DECL_STREAM_FUNCS (TYPE_DECL, type_decl)
1136 DEFINE_DECL_STREAM_FUNCS (NAMESPACE_DECL, namespace_decl)
1137 DEFINE_DECL_STREAM_FUNCS (LABEL_DECL, label_decl)
1139 /* Returns a new bit-packing context for bit-packing into S. */
1140 static inline struct bitpack_d
1141 bitpack_create (struct lto_output_stream *s)
1143 struct bitpack_d bp;
1144 bp.pos = 0;
1145 bp.word = 0;
1146 bp.stream = (void *)s;
1147 return bp;
1150 /* Pack the NBITS bit sized value VAL into the bit-packing context BP. */
1151 static inline void
1152 bp_pack_value (struct bitpack_d *bp, bitpack_word_t val, unsigned nbits)
1154 bitpack_word_t word = bp->word;
1155 int pos = bp->pos;
1156 /* If val does not fit into the current bitpack word switch to the
1157 next one. */
1158 if (pos + nbits > BITS_PER_BITPACK_WORD)
1160 lto_output_uleb128_stream ((struct lto_output_stream *) bp->stream, word);
1161 word = val;
1162 pos = nbits;
1164 else
1166 word |= val << pos;
1167 pos += nbits;
1169 bp->word = word;
1170 bp->pos = pos;
1173 /* Finishes bit-packing of BP. */
1174 static inline void
1175 lto_output_bitpack (struct bitpack_d *bp)
1177 lto_output_uleb128_stream ((struct lto_output_stream *) bp->stream,
1178 bp->word);
1179 bp->word = 0;
1180 bp->pos = 0;
1183 /* Returns a new bit-packing context for bit-unpacking from IB. */
1184 static inline struct bitpack_d
1185 lto_input_bitpack (struct lto_input_block *ib)
1187 struct bitpack_d bp;
1188 bp.word = lto_input_uleb128 (ib);
1189 bp.pos = 0;
1190 bp.stream = (void *)ib;
1191 return bp;
1194 /* Unpacks NBITS bits from the bit-packing context BP and returns them. */
1195 static inline bitpack_word_t
1196 bp_unpack_value (struct bitpack_d *bp, unsigned nbits)
1198 bitpack_word_t mask, val;
1199 int pos = bp->pos;
1201 mask = (nbits == BITS_PER_BITPACK_WORD
1202 ? (bitpack_word_t) -1
1203 : ((bitpack_word_t) 1 << nbits) - 1);
1205 /* If there are not continuous nbits in the current bitpack word
1206 switch to the next one. */
1207 if (pos + nbits > BITS_PER_BITPACK_WORD)
1209 bp->word = val = lto_input_uleb128 ((struct lto_input_block *)bp->stream);
1210 bp->pos = nbits;
1211 return val & mask;
1213 val = bp->word;
1214 val >>= pos;
1215 bp->pos = pos + nbits;
1217 return val & mask;
1220 #endif /* GCC_LTO_STREAMER_H */