2011-05-31 Gabriel Charette <gchare@google.com>
[official-gcc.git] / gcc / lto-streamer.h
blob26162525c5183c54eee41c8576d17a294a2d0f35
1 /* Data structures and declarations used for reading and writing
2 GIMPLE to a file stream.
4 Copyright (C) 2009, 2010, 2011 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 including 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 /* The encoding for a function consists of the following sections:
52 1) The header.
53 2) FIELD_DECLS.
54 3) FUNCTION_DECLS.
55 4) global VAR_DECLS.
56 5) type_decls
57 6) types.
58 7) Names for the labels that have names
59 8) The SSA names.
60 9) The control flow graph.
61 10-11)Gimple for local decls.
62 12) Gimple for the function.
63 13) Strings.
65 1) THE HEADER.
66 2-6) THE GLOBAL DECLS AND TYPES.
68 The global decls and types are encoded in the same way. For each
69 entry, there is word with the offset within the section to the
70 entry.
72 7) THE LABEL NAMES.
74 Since most labels do not have names, this section my be of zero
75 length. It consists of an array of string table references, one
76 per label. In the lto code, the labels are given either
77 positive or negative indexes. the positive ones have names and
78 the negative ones do not. The positive index can be used to
79 find the name in this array.
81 9) THE CFG.
83 10) Index into the local decls. Since local decls can have local
84 decls inside them, they must be read in randomly in order to
85 properly restore them.
87 11-12) GIMPLE FOR THE LOCAL DECLS AND THE FUNCTION BODY.
89 The gimple consists of a set of records.
91 THE FUNCTION
93 At the top level of (8) is the function. It consists of five
94 pieces:
96 LTO_function - The tag.
97 eh tree - This is all of the exception handling regions
98 put out in a post order traversial of the
99 tree. Siblings are output as lists terminated
100 by a 0. The set of fields matches the fields
101 defined in except.c.
103 last_basic_block - in uleb128 form.
105 basic blocks - This is the set of basic blocks.
107 zero - The termination of the basic blocks.
109 BASIC BLOCKS
111 There are two forms of basic blocks depending on if they are
112 empty or not.
114 The basic block consists of:
116 LTO_bb1 or LTO_bb0 - The tag.
118 bb->index - the index in uleb128 form.
120 #succs - The number of successors un uleb128 form.
122 the successors - For each edge, a pair. The first of the
123 pair is the index of the successor in
124 uleb128 form and the second are the flags in
125 uleb128 form.
127 the statements - A gimple tree, as described above.
128 These are only present for LTO_BB1.
129 Following each statement is an optional
130 exception handling record LTO_eh_region
131 which contains the region number (for
132 regions >= 0).
134 zero - This is only present for LTO_BB1 and is used
135 to terminate the statements and exception
136 regions within this block.
138 12) STRINGS
140 String are represented in the table as pairs, a length in ULEB128
141 form followed by the data for the string. */
143 /* The string that is the prefix on the section names we make for lto.
144 For decls the DECL_ASSEMBLER_NAME is appended to make the section
145 name for the functions and static_initializers. For other types of
146 sections a '.' and the section type are appended. */
147 #define LTO_SECTION_NAME_PREFIX ".gnu.lto_"
149 #define LTO_major_version 2
150 #define LTO_minor_version 0
152 typedef unsigned char lto_decl_flags_t;
155 /* Data structures used to pack values and bitflags into a vector of
156 words. Used to stream values of a fixed number of bits in a space
157 efficient way. */
158 static unsigned const BITS_PER_BITPACK_WORD = HOST_BITS_PER_WIDE_INT;
160 typedef unsigned HOST_WIDE_INT bitpack_word_t;
161 DEF_VEC_I(bitpack_word_t);
162 DEF_VEC_ALLOC_I(bitpack_word_t, heap);
164 struct bitpack_d
166 /* The position of the first unused or unconsumed bit in the word. */
167 unsigned pos;
169 /* The current word we are (un)packing. */
170 bitpack_word_t word;
172 /* The lto_output_stream or the lto_input_block we are streaming to/from. */
173 void *stream;
176 /* Tags representing the various IL objects written to the bytecode file
177 (GIMPLE statements, basic blocks, EH regions, tree nodes, etc).
179 NOTE, when adding new LTO tags, also update lto_tag_name. */
180 enum LTO_tags
182 LTO_null = 0,
184 /* Reserve enough entries to fit all the tree and gimple codes handled
185 by the streamer. This guarantees that:
187 1- Given a tree code C:
188 enum LTO_tags tag == C + 1
190 2- Given a gimple code C:
191 enum LTO_tags tag == C + NUM_TREE_CODES + 1
193 Conversely, to map between LTO tags and tree/gimple codes, the
194 reverse operation must be applied. */
195 LTO_bb0 = 1 + MAX_TREE_CODES + LAST_AND_UNUSED_GIMPLE_CODE,
196 LTO_bb1,
198 /* EH region holding the previous statement. */
199 LTO_eh_region,
201 /* An MD or NORMAL builtin. Only the code and class are streamed out. */
202 LTO_builtin_decl,
204 /* Function body. */
205 LTO_function,
207 /* EH table. */
208 LTO_eh_table,
210 /* EH region types. These mirror enum eh_region_type. */
211 LTO_ert_cleanup,
212 LTO_ert_try,
213 LTO_ert_allowed_exceptions,
214 LTO_ert_must_not_throw,
216 /* EH landing pad. */
217 LTO_eh_landing_pad,
219 /* EH try/catch node. */
220 LTO_eh_catch,
222 /* Special for global streamer. Reference to previously-streamed node. */
223 LTO_tree_pickle_reference,
225 /* References to indexable tree nodes. These objects are stored in
226 tables that are written separately from the function bodies that
227 reference them. This way they can be instantiated even when the
228 referencing functions aren't (e.g., during WPA) and it also allows
229 functions to be copied from one file to another without having
230 to unpickle the body first (the references are location
231 independent).
233 NOTE, do not regroup these values as the grouping is exposed
234 in the range checks done in lto_input_tree. */
235 LTO_field_decl_ref, /* Do not change. */
236 LTO_function_decl_ref,
237 LTO_label_decl_ref,
238 LTO_namespace_decl_ref,
239 LTO_result_decl_ref,
240 LTO_ssa_name_ref,
241 LTO_type_decl_ref,
242 LTO_type_ref,
243 LTO_const_decl_ref,
244 LTO_imported_decl_ref,
245 LTO_translation_unit_decl_ref,
246 LTO_global_decl_ref, /* Do not change. */
248 /* This tag must always be last. */
249 LTO_NUM_TAGS
253 /* Set of section types that are in an LTO file. This list will grow
254 as the number of IPA passes grows since each IPA pass will need its
255 own section type to store its summary information.
257 When adding a new section type, you must also extend the
258 LTO_SECTION_NAME array in lto-section-in.c. */
259 enum lto_section_type
261 LTO_section_decls = 0,
262 LTO_section_function_body,
263 LTO_section_static_initializer,
264 LTO_section_cgraph,
265 LTO_section_varpool,
266 LTO_section_refs,
267 LTO_section_jump_functions,
268 LTO_section_ipa_pure_const,
269 LTO_section_ipa_reference,
270 LTO_section_symtab,
271 LTO_section_opts,
272 LTO_section_cgraph_opt_sum,
273 LTO_section_inline_summary,
274 LTO_N_SECTION_TYPES /* Must be last. */
277 /* Indices to the various function, type and symbol streams. */
278 typedef enum
280 LTO_DECL_STREAM_TYPE = 0, /* Must be first. */
281 LTO_DECL_STREAM_FIELD_DECL,
282 LTO_DECL_STREAM_FN_DECL,
283 LTO_DECL_STREAM_VAR_DECL,
284 LTO_DECL_STREAM_TYPE_DECL,
285 LTO_DECL_STREAM_NAMESPACE_DECL,
286 LTO_DECL_STREAM_LABEL_DECL,
287 LTO_N_DECL_STREAMS
288 } lto_decl_stream_e_t;
290 typedef enum ld_plugin_symbol_resolution ld_plugin_symbol_resolution_t;
291 DEF_VEC_I(ld_plugin_symbol_resolution_t);
292 DEF_VEC_ALLOC_I(ld_plugin_symbol_resolution_t, heap);
295 /* Macro to define convenience functions for type and decl streams
296 in lto_file_decl_data. */
297 #define DEFINE_DECL_STREAM_FUNCS(UPPER_NAME, name) \
298 static inline tree \
299 lto_file_decl_data_get_ ## name (struct lto_file_decl_data *data, \
300 unsigned int idx) \
302 struct lto_in_decl_state *state = data->current_decl_state; \
303 gcc_assert (idx < state->streams[LTO_DECL_STREAM_## UPPER_NAME].size); \
304 return state->streams[LTO_DECL_STREAM_## UPPER_NAME].trees[idx]; \
307 static inline unsigned int \
308 lto_file_decl_data_num_ ## name ## s (struct lto_file_decl_data *data) \
310 struct lto_in_decl_state *state = data->current_decl_state; \
311 return state->streams[LTO_DECL_STREAM_## UPPER_NAME].size; \
315 /* Return a char pointer to the start of a data stream for an lto pass
316 or function. The first parameter is the file data that contains
317 the information. The second parameter is the type of information
318 to be obtained. The third parameter is the name of the function
319 and is only used when finding a function body; otherwise it is
320 NULL. The fourth parameter is the length of the data returned. */
321 typedef const char* (lto_get_section_data_f) (struct lto_file_decl_data *,
322 enum lto_section_type,
323 const char *,
324 size_t *);
326 /* Return the data found from the above call. The first three
327 parameters are the same as above. The fourth parameter is the data
328 itself and the fifth is the lenght of the data. */
329 typedef void (lto_free_section_data_f) (struct lto_file_decl_data *,
330 enum lto_section_type,
331 const char *,
332 const char *,
333 size_t);
335 /* Cache of pickled nodes. Used to avoid writing the same node more
336 than once. The first time a tree node is streamed out, it is
337 entered in this cache. Subsequent references to the same node are
338 resolved by looking it up in this cache.
340 This is used in two ways:
342 - On the writing side, the first time T is added to STREAMER_CACHE,
343 a new reference index is created for T and T is emitted on the
344 stream. If T needs to be emitted again to the stream, instead of
345 pickling it again, the reference index is emitted.
347 - On the reading side, the first time T is read from the stream, it
348 is reconstructed in memory and a new reference index created for
349 T. The reconstructed T is inserted in some array so that when
350 the reference index for T is found in the input stream, it can be
351 used to look up into the array to get the reconstructed T. */
352 struct lto_streamer_cache_d
354 /* The mapping between tree nodes and slots into the nodes array. */
355 struct pointer_map_t *node_map;
357 /* The nodes pickled so far. */
358 VEC(tree,heap) *nodes;
362 /* Structure used as buffer for reading an LTO file. */
363 struct lto_input_block
365 const char *data;
366 unsigned int p;
367 unsigned int len;
370 #define LTO_INIT_INPUT_BLOCK(BASE,D,P,L) \
371 do { \
372 BASE.data = D; \
373 BASE.p = P; \
374 BASE.len = L; \
375 } while (0)
377 #define LTO_INIT_INPUT_BLOCK_PTR(BASE,D,P,L) \
378 do { \
379 BASE->data = D; \
380 BASE->p = P; \
381 BASE->len = L; \
382 } while (0)
385 /* The is the first part of the record for a function or constructor
386 in the .o file. */
387 struct lto_header
389 int16_t major_version;
390 int16_t minor_version;
391 enum lto_section_type section_type;
394 /* The header for a function body. */
395 struct lto_function_header
397 /* The header for all types of sections. */
398 struct lto_header lto_header;
400 /* Number of labels with names. */
401 int32_t num_named_labels;
403 /* Number of labels without names. */
404 int32_t num_unnamed_labels;
406 /* Size compressed or 0 if not compressed. */
407 int32_t compressed_size;
409 /* Size of names for named labels. */
410 int32_t named_label_size;
412 /* Size of the cfg. */
413 int32_t cfg_size;
415 /* Size of main gimple body of function. */
416 int32_t main_size;
418 /* Size of the string table. */
419 int32_t string_size;
423 /* Structure describing a symbol section. */
424 struct lto_decl_header
426 /* The header for all types of sections. */
427 struct lto_header lto_header;
429 /* Size of region for decl state. */
430 int32_t decl_state_size;
432 /* Number of nodes in globals stream. */
433 int32_t num_nodes;
435 /* Size of region for expressions, decls, types, etc. */
436 int32_t main_size;
438 /* Size of the string table. */
439 int32_t string_size;
443 /* Statistics gathered during LTO, WPA and LTRANS. */
444 struct lto_stats_d
446 unsigned HOST_WIDE_INT num_input_cgraph_nodes;
447 unsigned HOST_WIDE_INT num_output_cgraph_nodes;
448 unsigned HOST_WIDE_INT num_input_files;
449 unsigned HOST_WIDE_INT num_output_files;
450 unsigned HOST_WIDE_INT num_cgraph_partitions;
451 unsigned HOST_WIDE_INT section_size[LTO_N_SECTION_TYPES];
452 unsigned HOST_WIDE_INT num_function_bodies;
453 unsigned HOST_WIDE_INT num_trees[NUM_TREE_CODES];
454 unsigned HOST_WIDE_INT num_output_il_bytes;
455 unsigned HOST_WIDE_INT num_compressed_il_bytes;
456 unsigned HOST_WIDE_INT num_input_il_bytes;
457 unsigned HOST_WIDE_INT num_uncompressed_il_bytes;
460 /* Encoder data structure used to stream callgraph nodes. */
461 struct lto_cgraph_encoder_d
463 /* Map nodes to reference number. */
464 struct pointer_map_t *map;
466 /* Map reference number to node. */
467 VEC(cgraph_node_ptr,heap) *nodes;
469 /* Map of nodes where we want to output body. */
470 struct pointer_set_t *body;
473 typedef struct lto_cgraph_encoder_d *lto_cgraph_encoder_t;
475 /* Return number of encoded nodes in ENCODER. */
477 static inline int
478 lto_cgraph_encoder_size (lto_cgraph_encoder_t encoder)
480 return VEC_length (cgraph_node_ptr, encoder->nodes);
484 /* Encoder data structure used to stream callgraph nodes. */
485 struct lto_varpool_encoder_d
487 /* Map nodes to reference number. */
488 struct pointer_map_t *map;
490 /* Map reference number to node. */
491 VEC(varpool_node_ptr,heap) *nodes;
493 /* Map of nodes where we want to output initializer. */
494 struct pointer_set_t *initializer;
496 typedef struct lto_varpool_encoder_d *lto_varpool_encoder_t;
498 /* Return number of encoded nodes in ENCODER. */
500 static inline int
501 lto_varpool_encoder_size (lto_varpool_encoder_t encoder)
503 return VEC_length (varpool_node_ptr, encoder->nodes);
506 /* Mapping from indices to trees. */
507 struct GTY(()) lto_tree_ref_table
509 /* Array of referenced trees . */
510 tree * GTY((length ("%h.size"))) trees;
512 /* Size of array. */
513 unsigned int size;
517 /* Mapping between trees and slots in an array. */
518 struct lto_decl_slot
520 tree t;
521 int slot_num;
525 /* The lto_tree_ref_encoder struct is used to encode trees into indices. */
527 struct lto_tree_ref_encoder
529 htab_t tree_hash_table; /* Maps pointers to indices. */
530 unsigned int next_index; /* Next available index. */
531 VEC(tree,heap) *trees; /* Maps indices to pointers. */
535 /* Structure to hold states of input scope. */
536 struct GTY(()) lto_in_decl_state
538 /* Array of lto_in_decl_buffers to store type and decls streams. */
539 struct lto_tree_ref_table streams[LTO_N_DECL_STREAMS];
541 /* If this in-decl state is associated with a function. FN_DECL
542 point to the FUNCTION_DECL. */
543 tree fn_decl;
546 typedef struct lto_in_decl_state *lto_in_decl_state_ptr;
549 /* The structure that holds all of the vectors of global types,
550 decls and cgraph nodes used in the serialization of this file. */
551 struct lto_out_decl_state
553 /* The buffers contain the sets of decls of various kinds and types we have
554 seen so far and the indexes assigned to them. */
555 struct lto_tree_ref_encoder streams[LTO_N_DECL_STREAMS];
557 /* Encoder for cgraph nodes. */
558 lto_cgraph_encoder_t cgraph_node_encoder;
560 /* Encoder for varpool nodes. */
561 lto_varpool_encoder_t varpool_node_encoder;
563 /* If this out-decl state belongs to a function, fn_decl points to that
564 function. Otherwise, it is NULL. */
565 tree fn_decl;
568 typedef struct lto_out_decl_state *lto_out_decl_state_ptr;
570 DEF_VEC_P(lto_out_decl_state_ptr);
571 DEF_VEC_ALLOC_P(lto_out_decl_state_ptr, heap);
573 /* One of these is allocated for each object file that being compiled
574 by lto. This structure contains the tables that are needed by the
575 serialized functions and ipa passes to connect themselves to the
576 global types and decls as they are reconstituted. */
577 struct GTY(()) lto_file_decl_data
579 /* Decl state currently used. */
580 struct lto_in_decl_state *current_decl_state;
582 /* Decl state corresponding to regions outside of any functions
583 in the compilation unit. */
584 struct lto_in_decl_state *global_decl_state;
586 /* Table of cgraph nodes present in this file. */
587 lto_cgraph_encoder_t GTY((skip)) cgraph_node_encoder;
589 /* Table of varpool nodes present in this file. */
590 lto_varpool_encoder_t GTY((skip)) varpool_node_encoder;
592 /* Hash table maps lto-related section names to location in file. */
593 htab_t GTY((param_is (struct lto_in_decl_state))) function_decl_states;
595 /* The .o file that these offsets relate to. */
596 const char *GTY((skip)) file_name;
598 /* Hash table maps lto-related section names to location in file. */
599 htab_t GTY((skip)) section_hash_table;
601 /* Hash new name of renamed global declaration to its original name. */
602 htab_t GTY((skip)) renaming_hash_table;
604 /* Linked list used temporarily in reader */
605 struct lto_file_decl_data *next;
607 /* Sub ID for merged objects. */
608 unsigned id;
610 /* Symbol resolutions for this file */
611 VEC(ld_plugin_symbol_resolution_t,heap) * GTY((skip)) resolutions;
613 struct gcov_ctr_summary GTY((skip)) profile_info;
615 /* Any other streamer-specific data needed by the streamer. */
616 void * GTY((skip)) sdata;
619 typedef struct lto_file_decl_data *lto_file_decl_data_ptr;
621 struct lto_char_ptr_base
623 char *ptr;
626 /* An incore byte stream to buffer the various parts of the function.
627 The entire structure should be zeroed when created. The record
628 consists of a set of blocks. The first sizeof (ptr) bytes are used
629 as a chain, and the rest store the bytes to be written. */
630 struct lto_output_stream
632 /* The pointer to the first block in the stream. */
633 struct lto_char_ptr_base * first_block;
635 /* The pointer to the last and current block in the stream. */
636 struct lto_char_ptr_base * current_block;
638 /* The pointer to where the next char should be written. */
639 char * current_pointer;
641 /* The number of characters left in the current block. */
642 unsigned int left_in_block;
644 /* The block size of the last block allocated. */
645 unsigned int block_size;
647 /* The total number of characters written. */
648 unsigned int total_size;
651 /* The is the first part of the record in an LTO file for many of the
652 IPA passes. */
653 struct lto_simple_header
655 /* The header for all types of sections. */
656 struct lto_header lto_header;
658 /* Size of main gimple body of function. */
659 int32_t main_size;
661 /* Size of main stream when compressed. */
662 int32_t compressed_size;
665 /* A simple output block. This can be used for simple IPA passes that
666 do not need more than one stream. */
667 struct lto_simple_output_block
669 enum lto_section_type section_type;
670 struct lto_out_decl_state *decl_state;
672 /* The stream that the main tree codes are written to. */
673 struct lto_output_stream *main_stream;
676 /* Data structure holding all the data and descriptors used when writing
677 an LTO file. */
678 struct output_block
680 enum lto_section_type section_type;
681 struct lto_out_decl_state *decl_state;
683 /* The stream that the main tree codes are written to. */
684 struct lto_output_stream *main_stream;
686 /* The stream that contains the string table. */
687 struct lto_output_stream *string_stream;
689 /* The stream that contains the cfg. */
690 struct lto_output_stream *cfg_stream;
692 /* The hash table that contains the set of strings we have seen so
693 far and the indexes assigned to them. */
694 htab_t string_hash_table;
696 /* The current cgraph_node that we are currently serializing. Null
697 if we are serializing something else. */
698 struct cgraph_node *cgraph_node;
700 /* These are the last file and line that were seen in the stream.
701 If the current node differs from these, it needs to insert
702 something into the stream and fix these up. */
703 const char *current_file;
704 int current_line;
705 int current_col;
707 /* True if writing globals and types. */
708 bool global;
710 /* Cache of nodes written in this section. */
711 struct lto_streamer_cache_d *writer_cache;
713 /* Any other streamer-specific data needed by the streamer. */
714 void *sdata;
718 /* Data and descriptors used when reading from an LTO file. */
719 struct data_in
721 /* The global decls and types. */
722 struct lto_file_decl_data *file_data;
724 /* All of the labels. */
725 tree *labels;
727 /* The string table. */
728 const char *strings;
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 const char *current_file;
741 int current_line;
742 int current_col;
744 /* Maps each reference number to the resolution done by the linker. */
745 VEC(ld_plugin_symbol_resolution_t,heap) *globals_resolution;
747 /* Cache of pickled nodes. */
748 struct lto_streamer_cache_d *reader_cache;
750 /* Any other streamer-specific data needed by the streamer. */
751 void *sdata;
755 /* Streamer hooks. These functions do additional processing as
756 needed by the module. There are two types of callbacks, those that
757 replace the default behavior and those that supplement it. Any
758 or all of these hooks can be NULL. */
759 typedef struct lto_streamer_hooks {
760 /* A string identifying this streamer. */
761 const char *name;
763 /* Called by lto_streamer_cache_create to instantiate a cache of
764 well-known nodes. These are tree nodes that are always
765 instantiated by the compiler on startup. Additionally, these
766 nodes need to be shared. This function should call
767 lto_streamer_cache_append on every tree node that it wishes to
768 preload in the streamer cache. This way, the writer will only
769 write out a reference to the tree and the reader will instantiate
770 the tree out of this pre-populated cache. */
771 void (*preload_common_nodes) (struct lto_streamer_cache_d *);
773 /* Called by lto_reader_init after it does basic initialization. */
774 void (*reader_init) (void);
776 /* Called by lto_writer_init after it does basic initalization. */
777 void (*writer_init) (void);
779 /* Return true if the given tree is supported by this streamer. */
780 bool (*is_streamable) (tree);
782 /* Called by lto_write_tree after writing all the common parts of
783 a tree. If defined, the callback is in charge of writing all
784 the fields that lto_write_tree did not write out. Arguments
785 are as in lto_write_tree.
787 The following tree fields are not handled by common code:
789 DECL_ABSTRACT_ORIGIN
790 DECL_INITIAL
791 DECL_SAVED_TREE
793 Callbacks may choose to ignore or handle them. If handled,
794 the reader should read them in the exact same sequence written
795 by the writer. */
796 void (*write_tree) (struct output_block *, tree, bool);
798 /* Called by lto_read_tree after reading all the common parts of
799 a tree. If defined, the callback is in charge of reading all
800 the fields that lto_read_tree did not read in. Arguments
801 are as in lto_read_tree. */
802 void (*read_tree) (struct lto_input_block *, struct data_in *, tree);
804 /* Called by lto_output_tree_ref to determine if the given tree node
805 should be emitted as a reference to the table of declarations
806 (the same table that holds VAR_DECLs). */
807 bool (*indexable_with_decls_p) (tree);
809 /* Called by pack_value_fields to store any non-pointer fields
810 in the tree structure. The arguments are as in pack_value_fields. */
811 void (*pack_value_fields) (struct bitpack_d *, tree);
813 /* Called by unpack_value_fields to retrieve any non-pointer fields
814 in the tree structure. The arguments are as in unpack_value_fields. */
815 void (*unpack_value_fields) (struct bitpack_d *, tree);
817 /* Non-zero if the streamer should register decls in the LTO
818 global symbol tables. */
819 unsigned register_decls_in_symtab_p : 1;
821 /* Non-zero if the streamer has special constants that cannot be
822 shared and are used in pointer-equality tests (e.g., void_zero_node,
823 truthvalue_false_node, etc). These constants will be present in
824 the streamer cache and should be streamed as references. */
825 unsigned has_unique_integer_csts_p : 1;
827 /* Called by lto_materialize_tree for tree nodes that it does not
828 know how to allocate memory for. If defined, this hook should
829 return a new tree node of the given code. The data_in and
830 input_block arguments are passed in case the hook needs to
831 read more data from the stream to allocate the node.
832 If this hook returns NULL, then lto_materialize_tree will attempt
833 to allocate the tree by calling make_node directly. */
834 tree (*alloc_tree) (enum tree_code, struct lto_input_block *,
835 struct data_in *);
837 /* Called by lto_output_tree_header to write any streamer-specific
838 information needed to allocate the tree. This hook may assume
839 that the basic header data (tree code, etc) has already been
840 written. It should only write any extra data needed to allocate
841 the node (e.g., in the case of CALL_EXPR, this hook would write
842 the number of arguments to the CALL_EXPR). */
843 void (*output_tree_header) (struct output_block *, tree);
844 } lto_streamer_hooks;
847 /* In lto-section-in.c */
848 extern struct lto_input_block * lto_create_simple_input_block (
849 struct lto_file_decl_data *,
850 enum lto_section_type, const char **, size_t *);
851 extern void
852 lto_destroy_simple_input_block (struct lto_file_decl_data *,
853 enum lto_section_type,
854 struct lto_input_block *, const char *, size_t);
855 extern void lto_set_in_hooks (struct lto_file_decl_data **,
856 lto_get_section_data_f *,
857 lto_free_section_data_f *);
858 extern struct lto_file_decl_data **lto_get_file_decl_data (void);
859 extern const char *lto_get_section_data (struct lto_file_decl_data *,
860 enum lto_section_type,
861 const char *, size_t *);
862 extern void lto_free_section_data (struct lto_file_decl_data *,
863 enum lto_section_type,
864 const char *, const char *, size_t);
865 extern unsigned HOST_WIDE_INT lto_input_uleb128 (struct lto_input_block *);
866 extern unsigned HOST_WIDEST_INT lto_input_widest_uint_uleb128 (
867 struct lto_input_block *);
868 extern HOST_WIDE_INT lto_input_sleb128 (struct lto_input_block *);
869 extern htab_t lto_create_renaming_table (void);
870 extern void lto_record_renamed_decl (struct lto_file_decl_data *,
871 const char *, const char *);
872 extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data *,
873 const char *);
874 extern struct lto_in_decl_state *lto_new_in_decl_state (void);
875 extern void lto_delete_in_decl_state (struct lto_in_decl_state *);
876 extern hashval_t lto_hash_in_decl_state (const void *);
877 extern int lto_eq_in_decl_state (const void *, const void *);
878 extern struct lto_in_decl_state *lto_get_function_in_decl_state (
879 struct lto_file_decl_data *, tree);
880 extern void lto_section_overrun (struct lto_input_block *) ATTRIBUTE_NORETURN;
881 extern void lto_value_range_error (const char *,
882 HOST_WIDE_INT, HOST_WIDE_INT,
883 HOST_WIDE_INT) ATTRIBUTE_NORETURN;
884 extern void bp_pack_var_len_unsigned (struct bitpack_d *, unsigned HOST_WIDE_INT);
885 extern void bp_pack_var_len_int (struct bitpack_d *, HOST_WIDE_INT);
886 extern unsigned HOST_WIDE_INT bp_unpack_var_len_unsigned (struct bitpack_d *);
887 extern HOST_WIDE_INT bp_unpack_var_len_int (struct bitpack_d *);
889 /* In lto-section-out.c */
890 extern hashval_t lto_hash_decl_slot_node (const void *);
891 extern int lto_eq_decl_slot_node (const void *, const void *);
892 extern hashval_t lto_hash_type_slot_node (const void *);
893 extern int lto_eq_type_slot_node (const void *, const void *);
894 extern void lto_begin_section (const char *, bool);
895 extern void lto_end_section (void);
896 extern void lto_write_stream (struct lto_output_stream *);
897 extern void lto_output_data_stream (struct lto_output_stream *, const void *,
898 size_t);
899 extern void lto_output_uleb128_stream (struct lto_output_stream *,
900 unsigned HOST_WIDE_INT);
901 extern void lto_output_widest_uint_uleb128_stream (struct lto_output_stream *,
902 unsigned HOST_WIDEST_INT);
903 extern void lto_output_sleb128_stream (struct lto_output_stream *,
904 HOST_WIDE_INT);
905 extern bool lto_output_decl_index (struct lto_output_stream *,
906 struct lto_tree_ref_encoder *,
907 tree, unsigned int *);
908 extern void lto_output_field_decl_index (struct lto_out_decl_state *,
909 struct lto_output_stream *, tree);
910 extern void lto_output_fn_decl_index (struct lto_out_decl_state *,
911 struct lto_output_stream *, tree);
912 extern void lto_output_namespace_decl_index (struct lto_out_decl_state *,
913 struct lto_output_stream *, tree);
914 extern void lto_output_var_decl_index (struct lto_out_decl_state *,
915 struct lto_output_stream *, tree);
916 extern void lto_output_type_decl_index (struct lto_out_decl_state *,
917 struct lto_output_stream *, tree);
918 extern void lto_output_type_ref_index (struct lto_out_decl_state *,
919 struct lto_output_stream *, tree);
920 extern struct lto_simple_output_block *lto_create_simple_output_block (
921 enum lto_section_type);
922 extern void lto_destroy_simple_output_block (struct lto_simple_output_block *);
923 extern struct lto_out_decl_state *lto_new_out_decl_state (void);
924 extern void lto_delete_out_decl_state (struct lto_out_decl_state *);
925 extern struct lto_out_decl_state *lto_get_out_decl_state (void);
926 extern void lto_push_out_decl_state (struct lto_out_decl_state *);
927 extern struct lto_out_decl_state *lto_pop_out_decl_state (void);
928 extern void lto_record_function_out_decl_state (tree,
929 struct lto_out_decl_state *);
930 extern void lto_append_block (struct lto_output_stream *);
933 /* In lto-streamer.c. */
934 extern const char *lto_tag_name (enum LTO_tags);
935 extern bitmap lto_bitmap_alloc (void);
936 extern void lto_bitmap_free (bitmap);
937 extern char *lto_get_section_name (int, const char *, struct lto_file_decl_data *);
938 extern void print_lto_report (void);
939 extern bool lto_streamer_cache_insert (struct lto_streamer_cache_d *, tree,
940 unsigned *);
941 extern bool lto_streamer_cache_insert_at (struct lto_streamer_cache_d *, tree,
942 unsigned);
943 extern void lto_streamer_cache_append (struct lto_streamer_cache_d *, tree);
944 extern bool lto_streamer_cache_lookup (struct lto_streamer_cache_d *, tree,
945 unsigned *);
946 extern tree lto_streamer_cache_get (struct lto_streamer_cache_d *, unsigned);
947 extern struct lto_streamer_cache_d *lto_streamer_cache_create (void);
948 extern void lto_streamer_cache_delete (struct lto_streamer_cache_d *);
949 extern void lto_streamer_init (void);
950 extern bool gate_lto_out (void);
951 #ifdef LTO_STREAMER_DEBUG
952 extern void lto_orig_address_map (tree, intptr_t);
953 extern intptr_t lto_orig_address_get (tree);
954 extern void lto_orig_address_remove (tree);
955 #endif
956 extern void lto_check_version (int, int);
957 extern void gimple_streamer_hooks_init (void);
958 extern void gimple_streamer_write_tree (struct output_block *, tree, bool);
959 extern void gimple_streamer_read_tree (struct lto_input_block *,
960 struct data_in *, tree);
961 extern lto_streamer_hooks *streamer_hooks (void);
962 extern lto_streamer_hooks *streamer_hooks_init (void);
964 /* In lto-streamer-in.c */
965 extern void lto_input_cgraph (struct lto_file_decl_data *, const char *);
966 extern void lto_reader_init (void);
967 extern tree lto_input_tree (struct lto_input_block *, struct data_in *);
968 extern tree lto_input_chain (struct lto_input_block *, struct data_in *);
969 extern void lto_input_function_body (struct lto_file_decl_data *, tree,
970 const char *);
971 extern void lto_input_constructors_and_inits (struct lto_file_decl_data *,
972 const char *);
973 extern struct data_in *lto_data_in_create (struct lto_file_decl_data *,
974 const char *, unsigned,
975 VEC(ld_plugin_symbol_resolution_t,heap) *);
976 extern void lto_data_in_delete (struct data_in *);
977 extern const char *lto_input_string (struct data_in *,
978 struct lto_input_block *);
979 extern void lto_input_data_block (struct lto_input_block *, void *, size_t);
980 extern void gimple_streamer_reader_init (void);
983 /* In lto-streamer-out.c */
984 extern void lto_writer_init (void);
985 extern void lto_register_decl_definition (tree, struct lto_file_decl_data *);
986 extern struct output_block *create_output_block (enum lto_section_type);
987 extern void destroy_output_block (struct output_block *);
988 extern void lto_output_tree (struct output_block *, tree, bool);
989 extern void lto_output_tree_or_ref (struct output_block *, tree, bool);
990 extern void lto_output_chain (struct output_block *, tree, bool);
991 extern void produce_asm (struct output_block *ob, tree fn);
992 extern void lto_output_string (struct output_block *,
993 struct lto_output_stream *,
994 const char *);
995 extern void lto_output_string_with_length (struct output_block *,
996 struct lto_output_stream *,
997 const char *,
998 unsigned int);
999 void lto_output_decl_state_streams (struct output_block *,
1000 struct lto_out_decl_state *);
1001 void lto_output_decl_state_refs (struct output_block *,
1002 struct lto_output_stream *,
1003 struct lto_out_decl_state *);
1006 /* In lto-cgraph.c */
1007 struct cgraph_node *lto_cgraph_encoder_deref (lto_cgraph_encoder_t, int);
1008 int lto_cgraph_encoder_lookup (lto_cgraph_encoder_t, struct cgraph_node *);
1009 lto_cgraph_encoder_t lto_cgraph_encoder_new (void);
1010 int lto_cgraph_encoder_encode (lto_cgraph_encoder_t, struct cgraph_node *);
1011 void lto_cgraph_encoder_delete (lto_cgraph_encoder_t);
1012 bool lto_cgraph_encoder_encode_body_p (lto_cgraph_encoder_t,
1013 struct cgraph_node *);
1015 bool lto_varpool_encoder_encode_body_p (lto_varpool_encoder_t,
1016 struct varpool_node *);
1017 struct varpool_node *lto_varpool_encoder_deref (lto_varpool_encoder_t, int);
1018 int lto_varpool_encoder_lookup (lto_varpool_encoder_t, struct varpool_node *);
1019 lto_varpool_encoder_t lto_varpool_encoder_new (void);
1020 int lto_varpool_encoder_encode (lto_varpool_encoder_t, struct varpool_node *);
1021 void lto_varpool_encoder_delete (lto_varpool_encoder_t);
1022 bool lto_varpool_encoder_encode_initializer_p (lto_varpool_encoder_t,
1023 struct varpool_node *);
1024 void output_cgraph (cgraph_node_set, varpool_node_set);
1025 void input_cgraph (void);
1026 bool referenced_from_other_partition_p (struct ipa_ref_list *,
1027 cgraph_node_set,
1028 varpool_node_set vset);
1029 bool reachable_from_other_partition_p (struct cgraph_node *,
1030 cgraph_node_set);
1031 bool referenced_from_this_partition_p (struct ipa_ref_list *,
1032 cgraph_node_set,
1033 varpool_node_set vset);
1034 bool reachable_from_this_partition_p (struct cgraph_node *,
1035 cgraph_node_set);
1036 void compute_ltrans_boundary (struct lto_out_decl_state *state,
1037 cgraph_node_set, varpool_node_set);
1040 /* In lto-symtab.c. */
1041 extern void lto_symtab_register_decl (tree, ld_plugin_symbol_resolution_t,
1042 struct lto_file_decl_data *);
1043 extern void lto_symtab_merge_decls (void);
1044 extern void lto_symtab_merge_cgraph_nodes (void);
1045 extern tree lto_symtab_prevailing_decl (tree decl);
1046 extern enum ld_plugin_symbol_resolution lto_symtab_get_resolution (tree decl);
1047 extern void lto_symtab_free (void);
1048 extern GTY(()) VEC(tree,gc) *lto_global_var_decls;
1051 /* In lto-opts.c. */
1052 extern void lto_register_user_option (size_t, const char *, int, unsigned int);
1053 extern void lto_read_file_options (struct lto_file_decl_data *);
1054 extern void lto_write_options (void);
1055 extern void lto_reissue_options (void);
1056 void lto_clear_user_options (void);
1057 void lto_clear_file_options (void);
1060 /* In lto-wpa-fixup.c */
1061 void lto_mark_nothrow_fndecl (tree);
1062 void lto_fixup_nothrow_decls (void);
1065 /* Statistics gathered during LTO, WPA and LTRANS. */
1066 extern struct lto_stats_d lto_stats;
1068 /* Section names corresponding to the values of enum lto_section_type. */
1069 extern const char *lto_section_name[];
1071 /* Holds all the out decl states of functions output so far in the
1072 current output file. */
1073 extern VEC(lto_out_decl_state_ptr, heap) *lto_function_decl_states;
1075 /* Return true if LTO tag TAG corresponds to a tree code. */
1076 static inline bool
1077 lto_tag_is_tree_code_p (enum LTO_tags tag)
1079 return tag > LTO_null && (unsigned) tag <= MAX_TREE_CODES;
1083 /* Return true if LTO tag TAG corresponds to a gimple code. */
1084 static inline bool
1085 lto_tag_is_gimple_code_p (enum LTO_tags tag)
1087 return (unsigned) tag >= NUM_TREE_CODES + 1
1088 && (unsigned) tag < 1 + NUM_TREE_CODES + LAST_AND_UNUSED_GIMPLE_CODE;
1092 /* Return the LTO tag corresponding to gimple code CODE. See enum
1093 LTO_tags for details on the conversion. */
1094 static inline enum LTO_tags
1095 lto_gimple_code_to_tag (enum gimple_code code)
1097 return (enum LTO_tags) ((unsigned) code + NUM_TREE_CODES + 1);
1101 /* Return the GIMPLE code corresponding to TAG. See enum LTO_tags for
1102 details on the conversion. */
1103 static inline enum gimple_code
1104 lto_tag_to_gimple_code (enum LTO_tags tag)
1106 gcc_assert (lto_tag_is_gimple_code_p (tag));
1107 return (enum gimple_code) ((unsigned) tag - NUM_TREE_CODES - 1);
1111 /* Return the LTO tag corresponding to tree code CODE. See enum
1112 LTO_tags for details on the conversion. */
1113 static inline enum LTO_tags
1114 lto_tree_code_to_tag (enum tree_code code)
1116 return (enum LTO_tags) ((unsigned) code + 1);
1120 /* Return the tree code corresponding to TAG. See enum LTO_tags for
1121 details on the conversion. */
1122 static inline enum tree_code
1123 lto_tag_to_tree_code (enum LTO_tags tag)
1125 gcc_assert (lto_tag_is_tree_code_p (tag));
1126 return (enum tree_code) ((unsigned) tag - 1);
1129 /* Initialize an lto_out_decl_buffer ENCODER. */
1130 static inline void
1131 lto_init_tree_ref_encoder (struct lto_tree_ref_encoder *encoder,
1132 htab_hash hash_fn, htab_eq eq_fn)
1134 encoder->tree_hash_table = htab_create (37, hash_fn, eq_fn, free);
1135 encoder->next_index = 0;
1136 encoder->trees = NULL;
1140 /* Destory an lto_tree_ref_encoder ENCODER by freeing its contents. The
1141 memory used by ENCODER is not freed by this function. */
1142 static inline void
1143 lto_destroy_tree_ref_encoder (struct lto_tree_ref_encoder *encoder)
1145 /* Hash table may be delete already. */
1146 if (encoder->tree_hash_table)
1147 htab_delete (encoder->tree_hash_table);
1148 VEC_free (tree, heap, encoder->trees);
1151 /* Return the number of trees encoded in ENCODER. */
1152 static inline unsigned int
1153 lto_tree_ref_encoder_size (struct lto_tree_ref_encoder *encoder)
1155 return VEC_length (tree, encoder->trees);
1158 /* Return the IDX-th tree in ENCODER. */
1159 static inline tree
1160 lto_tree_ref_encoder_get_tree (struct lto_tree_ref_encoder *encoder,
1161 unsigned int idx)
1163 return VEC_index (tree, encoder->trees, idx);
1167 /* Return true if LABEL should be emitted in the global context. */
1168 static inline bool
1169 emit_label_in_global_context_p (tree label)
1171 return DECL_NONLOCAL (label) || FORCED_LABEL (label);
1174 /* Return true if tree node EXPR should be streamed as a builtin. For
1175 these nodes, we just emit the class and function code. */
1176 static inline bool
1177 lto_stream_as_builtin_p (tree expr)
1179 return (TREE_CODE (expr) == FUNCTION_DECL
1180 && DECL_IS_BUILTIN (expr)
1181 && (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_NORMAL
1182 || DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD));
1185 DEFINE_DECL_STREAM_FUNCS (TYPE, type)
1186 DEFINE_DECL_STREAM_FUNCS (FIELD_DECL, field_decl)
1187 DEFINE_DECL_STREAM_FUNCS (FN_DECL, fn_decl)
1188 DEFINE_DECL_STREAM_FUNCS (VAR_DECL, var_decl)
1189 DEFINE_DECL_STREAM_FUNCS (TYPE_DECL, type_decl)
1190 DEFINE_DECL_STREAM_FUNCS (NAMESPACE_DECL, namespace_decl)
1191 DEFINE_DECL_STREAM_FUNCS (LABEL_DECL, label_decl)
1193 /* Returns a new bit-packing context for bit-packing into S. */
1194 static inline struct bitpack_d
1195 bitpack_create (struct lto_output_stream *s)
1197 struct bitpack_d bp;
1198 bp.pos = 0;
1199 bp.word = 0;
1200 bp.stream = (void *)s;
1201 return bp;
1204 /* Pack the NBITS bit sized value VAL into the bit-packing context BP. */
1205 static inline void
1206 bp_pack_value (struct bitpack_d *bp, bitpack_word_t val, unsigned nbits)
1208 bitpack_word_t word = bp->word;
1209 int pos = bp->pos;
1211 /* Verify that VAL fits in the NBITS. */
1212 gcc_checking_assert (nbits == BITS_PER_BITPACK_WORD
1213 || !(val & ~(((bitpack_word_t)1<<nbits)-1)));
1215 /* If val does not fit into the current bitpack word switch to the
1216 next one. */
1217 if (pos + nbits > BITS_PER_BITPACK_WORD)
1219 lto_output_uleb128_stream ((struct lto_output_stream *) bp->stream, word);
1220 word = val;
1221 pos = nbits;
1223 else
1225 word |= val << pos;
1226 pos += nbits;
1228 bp->word = word;
1229 bp->pos = pos;
1232 /* Finishes bit-packing of BP. */
1233 static inline void
1234 lto_output_bitpack (struct bitpack_d *bp)
1236 lto_output_uleb128_stream ((struct lto_output_stream *) bp->stream,
1237 bp->word);
1238 bp->word = 0;
1239 bp->pos = 0;
1242 /* Returns a new bit-packing context for bit-unpacking from IB. */
1243 static inline struct bitpack_d
1244 lto_input_bitpack (struct lto_input_block *ib)
1246 struct bitpack_d bp;
1247 bp.word = lto_input_uleb128 (ib);
1248 bp.pos = 0;
1249 bp.stream = (void *)ib;
1250 return bp;
1253 /* Unpacks NBITS bits from the bit-packing context BP and returns them. */
1254 static inline bitpack_word_t
1255 bp_unpack_value (struct bitpack_d *bp, unsigned nbits)
1257 bitpack_word_t mask, val;
1258 int pos = bp->pos;
1260 mask = (nbits == BITS_PER_BITPACK_WORD
1261 ? (bitpack_word_t) -1
1262 : ((bitpack_word_t) 1 << nbits) - 1);
1264 /* If there are not continuous nbits in the current bitpack word
1265 switch to the next one. */
1266 if (pos + nbits > BITS_PER_BITPACK_WORD)
1268 bp->word = val = lto_input_uleb128 ((struct lto_input_block *)bp->stream);
1269 bp->pos = nbits;
1270 return val & mask;
1272 val = bp->word;
1273 val >>= pos;
1274 bp->pos = pos + nbits;
1276 return val & mask;
1280 /* Write a character to the output block. */
1282 static inline void
1283 lto_output_1_stream (struct lto_output_stream *obs, char c)
1285 /* No space left. */
1286 if (obs->left_in_block == 0)
1287 lto_append_block (obs);
1289 /* Write the actual character. */
1290 *obs->current_pointer = c;
1291 obs->current_pointer++;
1292 obs->total_size++;
1293 obs->left_in_block--;
1297 /* Read byte from the input block. */
1299 static inline unsigned char
1300 lto_input_1_unsigned (struct lto_input_block *ib)
1302 if (ib->p >= ib->len)
1303 lto_section_overrun (ib);
1304 return (ib->data[ib->p++]);
1307 /* Output VAL into OBS and verify it is in range MIN...MAX that is supposed
1308 to be compile time constant.
1309 Be host independent, limit range to 31bits. */
1311 static inline void
1312 lto_output_int_in_range (struct lto_output_stream *obs,
1313 HOST_WIDE_INT min,
1314 HOST_WIDE_INT max,
1315 HOST_WIDE_INT val)
1317 HOST_WIDE_INT range = max - min;
1319 gcc_checking_assert (val >= min && val <= max && range > 0
1320 && range < 0x7fffffff);
1322 val -= min;
1323 lto_output_1_stream (obs, val & 255);
1324 if (range >= 0xff)
1325 lto_output_1_stream (obs, (val >> 8) & 255);
1326 if (range >= 0xffff)
1327 lto_output_1_stream (obs, (val >> 16) & 255);
1328 if (range >= 0xffffff)
1329 lto_output_1_stream (obs, (val >> 24) & 255);
1332 /* Input VAL into OBS and verify it is in range MIN...MAX that is supposed
1333 to be compile time constant. PURPOSE is used for error reporting. */
1335 static inline HOST_WIDE_INT
1336 lto_input_int_in_range (struct lto_input_block *ib,
1337 const char *purpose,
1338 HOST_WIDE_INT min,
1339 HOST_WIDE_INT max)
1341 HOST_WIDE_INT range = max - min;
1342 HOST_WIDE_INT val = lto_input_1_unsigned (ib);
1344 gcc_checking_assert (range > 0 && range < 0x7fffffff);
1346 if (range >= 0xff)
1347 val |= ((HOST_WIDE_INT)lto_input_1_unsigned (ib)) << 8;
1348 if (range >= 0xffff)
1349 val |= ((HOST_WIDE_INT)lto_input_1_unsigned (ib)) << 16;
1350 if (range >= 0xffffff)
1351 val |= ((HOST_WIDE_INT)lto_input_1_unsigned (ib)) << 24;
1352 val += min;
1353 if (val < min || val > max)
1354 lto_value_range_error (purpose, val, min, max);
1355 return val;
1358 /* Output VAL of type "enum enum_name" into OBS.
1359 Assume range 0...ENUM_LAST - 1. */
1360 #define lto_output_enum(obs,enum_name,enum_last,val) \
1361 lto_output_int_in_range ((obs), 0, (int)(enum_last) - 1, (int)(val))
1363 /* Input enum of type "enum enum_name" from IB.
1364 Assume range 0...ENUM_LAST - 1. */
1365 #define lto_input_enum(ib,enum_name,enum_last) \
1366 (enum enum_name)lto_input_int_in_range ((ib), #enum_name, 0, \
1367 (int)(enum_last) - 1)
1369 #endif /* GCC_LTO_STREAMER_H */