comparison gcc/lto-streamer.h @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Data structures and declarations used for reading and writing 1 /* Data structures and declarations used for reading and writing
2 GIMPLE to a file stream. 2 GIMPLE to a file stream.
3 3
4 Copyright (C) 2009, 2010 Free Software Foundation, Inc. 4 Copyright (C) 2009-2017 Free Software Foundation, Inc.
5 Contributed by Doug Kwan <dougkwan@google.com> 5 Contributed by Doug Kwan <dougkwan@google.com>
6 6
7 This file is part of GCC. 7 This file is part of GCC.
8 8
9 GCC is free software; you can redistribute it and/or modify it under 9 GCC is free software; you can redistribute it and/or modify it under
22 22
23 #ifndef GCC_LTO_STREAMER_H 23 #ifndef GCC_LTO_STREAMER_H
24 #define GCC_LTO_STREAMER_H 24 #define GCC_LTO_STREAMER_H
25 25
26 #include "plugin-api.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" 27 #include "gcov-io.h"
35 28 #include "diagnostic.h"
36 /* Define when debugging the LTO streamer. This causes the writer
37 to output the numeric value for the memory address of the tree node
38 being emitted. When debugging a problem in the reader, check the
39 original address that the writer was emitting using lto_orig_address_get.
40 With this value, set a breakpoint in the writer (e.g., lto_output_tree)
41 to trace how the faulty node is being emitted. */
42 /* #define LTO_STREAMER_DEBUG 1 */
43 29
44 /* The encoding for a function consists of the following sections: 30 /* The encoding for a function consists of the following sections:
45 31
46 1) The header. 32 1) The header.
47 2) FIELD_DECLS. 33 2) FIELD_DECLS.
132 12) STRINGS 118 12) STRINGS
133 119
134 String are represented in the table as pairs, a length in ULEB128 120 String are represented in the table as pairs, a length in ULEB128
135 form followed by the data for the string. */ 121 form followed by the data for the string. */
136 122
137 /* The string that is the prefix on the section names we make for lto. 123 #define LTO_major_version 7
138 For decls the DECL_ASSEMBLER_NAME is appended to make the section
139 name for the functions and static_initializers. For other types of
140 sections a '.' and the section type are appended. */
141 #define LTO_SECTION_NAME_PREFIX ".gnu.lto_"
142
143 #define LTO_major_version 2
144 #define LTO_minor_version 0 124 #define LTO_minor_version 0
145 125
146 typedef unsigned char lto_decl_flags_t; 126 typedef unsigned char lto_decl_flags_t;
147 127
148
149 /* Data structures used to pack values and bitflags into a vector of
150 words. Used to stream values of a fixed number of bits in a space
151 efficient way. */
152 static unsigned const BITS_PER_BITPACK_WORD = HOST_BITS_PER_WIDE_INT;
153
154 typedef unsigned HOST_WIDE_INT bitpack_word_t;
155 DEF_VEC_I(bitpack_word_t);
156 DEF_VEC_ALLOC_I(bitpack_word_t, heap);
157
158 struct bitpack_d
159 {
160 /* The position of the first unused or unconsumed bit in the word. */
161 unsigned pos;
162
163 /* The current word we are (un)packing. */
164 bitpack_word_t word;
165
166 /* The lto_output_stream or the lto_input_block we are streaming to/from. */
167 void *stream;
168 };
169 128
170 /* Tags representing the various IL objects written to the bytecode file 129 /* Tags representing the various IL objects written to the bytecode file
171 (GIMPLE statements, basic blocks, EH regions, tree nodes, etc). 130 (GIMPLE statements, basic blocks, EH regions, tree nodes, etc).
172 131
173 NOTE, when adding new LTO tags, also update lto_tag_name. */ 132 NOTE, when adding new LTO tags, also update lto_tag_name. */
174 enum LTO_tags 133 enum LTO_tags
175 { 134 {
176 LTO_null = 0, 135 LTO_null = 0,
177 136
137 /* Special for streamer. Reference to previously-streamed node. */
138 LTO_tree_pickle_reference,
139
178 /* Reserve enough entries to fit all the tree and gimple codes handled 140 /* Reserve enough entries to fit all the tree and gimple codes handled
179 by the streamer. This guarantees that: 141 by the streamer. This guarantees that:
180 142
181 1- Given a tree code C: 143 1- Given a tree code C:
182 enum LTO_tags tag == C + 1 144 enum LTO_tags tag == C + 1
184 2- Given a gimple code C: 146 2- Given a gimple code C:
185 enum LTO_tags tag == C + NUM_TREE_CODES + 1 147 enum LTO_tags tag == C + NUM_TREE_CODES + 1
186 148
187 Conversely, to map between LTO tags and tree/gimple codes, the 149 Conversely, to map between LTO tags and tree/gimple codes, the
188 reverse operation must be applied. */ 150 reverse operation must be applied. */
189 LTO_bb0 = 1 + NUM_TREE_CODES + LAST_AND_UNUSED_GIMPLE_CODE, 151 LTO_bb0 = 1 + MAX_TREE_CODES + LAST_AND_UNUSED_GIMPLE_CODE,
190 LTO_bb1, 152 LTO_bb1,
191 153
192 /* EH region holding the previous statement. */ 154 /* EH region holding the previous statement. */
193 LTO_eh_region, 155 LTO_eh_region,
194 156
195 /* An MD or NORMAL builtin. Only the code and class are streamed out. */ 157 /* Shared INTEGER_CST node. */
196 LTO_builtin_decl, 158 LTO_integer_cst,
197 159
198 /* Function body. */ 160 /* Function body. */
199 LTO_function, 161 LTO_function,
200 162
201 /* EH table. */ 163 /* EH table. */
211 LTO_eh_landing_pad, 173 LTO_eh_landing_pad,
212 174
213 /* EH try/catch node. */ 175 /* EH try/catch node. */
214 LTO_eh_catch, 176 LTO_eh_catch,
215 177
216 /* Special for global streamer. Reference to previously-streamed node. */ 178 /* Special for global streamer. A blob of unnamed tree nodes. */
217 LTO_tree_pickle_reference, 179 LTO_tree_scc,
218 180
219 /* References to indexable tree nodes. These objects are stored in 181 /* References to indexable tree nodes. These objects are stored in
220 tables that are written separately from the function bodies that 182 tables that are written separately from the function bodies that
221 reference them. This way they can be instantiated even when the 183 reference them. This way they can be instantiated even when the
222 referencing functions aren't (e.g., during WPA) and it also allows 184 referencing functions aren't (e.g., during WPA) and it also allows
235 LTO_type_decl_ref, 197 LTO_type_decl_ref,
236 LTO_type_ref, 198 LTO_type_ref,
237 LTO_const_decl_ref, 199 LTO_const_decl_ref,
238 LTO_imported_decl_ref, 200 LTO_imported_decl_ref,
239 LTO_translation_unit_decl_ref, 201 LTO_translation_unit_decl_ref,
240 LTO_global_decl_ref, /* Do not change. */ 202 LTO_global_decl_ref,
203 LTO_namelist_decl_ref, /* Do not change. */
241 204
242 /* This tag must always be last. */ 205 /* This tag must always be last. */
243 LTO_NUM_TAGS 206 LTO_NUM_TAGS
244 }; 207 };
245 208
253 enum lto_section_type 216 enum lto_section_type
254 { 217 {
255 LTO_section_decls = 0, 218 LTO_section_decls = 0,
256 LTO_section_function_body, 219 LTO_section_function_body,
257 LTO_section_static_initializer, 220 LTO_section_static_initializer,
258 LTO_section_cgraph, 221 LTO_section_symtab,
259 LTO_section_varpool,
260 LTO_section_refs, 222 LTO_section_refs,
223 LTO_section_asm,
261 LTO_section_jump_functions, 224 LTO_section_jump_functions,
262 LTO_section_ipa_pure_const, 225 LTO_section_ipa_pure_const,
263 LTO_section_ipa_reference, 226 LTO_section_ipa_reference,
264 LTO_section_symtab, 227 LTO_section_ipa_profile,
228 LTO_section_symtab_nodes,
265 LTO_section_opts, 229 LTO_section_opts,
266 LTO_section_cgraph_opt_sum, 230 LTO_section_cgraph_opt_sum,
231 LTO_section_ipa_fn_summary,
232 LTO_section_ipcp_transform,
233 LTO_section_ipa_icf,
234 LTO_section_offload_table,
235 LTO_section_mode_table,
236 LTO_section_ipa_hsa,
267 LTO_N_SECTION_TYPES /* Must be last. */ 237 LTO_N_SECTION_TYPES /* Must be last. */
268 }; 238 };
269 239
270 /* Indices to the various function, type and symbol streams. */ 240 /* Indices to the various function, type and symbol streams. */
271 typedef enum 241 enum lto_decl_stream_e_t
272 { 242 {
273 LTO_DECL_STREAM_TYPE = 0, /* Must be first. */ 243 LTO_DECL_STREAM_TYPE = 0, /* Must be first. */
274 LTO_DECL_STREAM_FIELD_DECL, 244 LTO_DECL_STREAM_FIELD_DECL,
275 LTO_DECL_STREAM_FN_DECL, 245 LTO_DECL_STREAM_FN_DECL,
276 LTO_DECL_STREAM_VAR_DECL, 246 LTO_DECL_STREAM_VAR_DECL,
277 LTO_DECL_STREAM_TYPE_DECL, 247 LTO_DECL_STREAM_TYPE_DECL,
278 LTO_DECL_STREAM_NAMESPACE_DECL, 248 LTO_DECL_STREAM_NAMESPACE_DECL,
279 LTO_DECL_STREAM_LABEL_DECL, 249 LTO_DECL_STREAM_LABEL_DECL,
280 LTO_N_DECL_STREAMS 250 LTO_N_DECL_STREAMS
281 } lto_decl_stream_e_t; 251 };
282 252
283 typedef enum ld_plugin_symbol_resolution ld_plugin_symbol_resolution_t; 253 typedef enum ld_plugin_symbol_resolution ld_plugin_symbol_resolution_t;
284 DEF_VEC_I(ld_plugin_symbol_resolution_t);
285 DEF_VEC_ALLOC_I(ld_plugin_symbol_resolution_t, heap);
286 254
287 255
288 /* Macro to define convenience functions for type and decl streams 256 /* Macro to define convenience functions for type and decl streams
289 in lto_file_decl_data. */ 257 in lto_file_decl_data. */
290 #define DEFINE_DECL_STREAM_FUNCS(UPPER_NAME, name) \ 258 #define DEFINE_DECL_STREAM_FUNCS(UPPER_NAME, name) \
291 static inline tree \ 259 static inline tree \
292 lto_file_decl_data_get_ ## name (struct lto_file_decl_data *data, \ 260 lto_file_decl_data_get_ ## name (struct lto_file_decl_data *data, \
293 unsigned int idx) \ 261 unsigned int idx) \
294 { \ 262 { \
295 struct lto_in_decl_state *state = data->current_decl_state; \ 263 struct lto_in_decl_state *state = data->current_decl_state; \
296 gcc_assert (idx < state->streams[LTO_DECL_STREAM_## UPPER_NAME].size); \ 264 return (*state->streams[LTO_DECL_STREAM_## UPPER_NAME])[idx]; \
297 return state->streams[LTO_DECL_STREAM_## UPPER_NAME].trees[idx]; \
298 } \ 265 } \
299 \ 266 \
300 static inline unsigned int \ 267 static inline unsigned int \
301 lto_file_decl_data_num_ ## name ## s (struct lto_file_decl_data *data) \ 268 lto_file_decl_data_num_ ## name ## s (struct lto_file_decl_data *data) \
302 { \ 269 { \
303 struct lto_in_decl_state *state = data->current_decl_state; \ 270 struct lto_in_decl_state *state = data->current_decl_state; \
304 return state->streams[LTO_DECL_STREAM_## UPPER_NAME].size; \ 271 return vec_safe_length (state->streams[LTO_DECL_STREAM_## UPPER_NAME]); \
305 } 272 }
306 273
307 274
308 /* Return a char pointer to the start of a data stream for an lto pass 275 /* Return a char pointer to the start of a data stream for an lto pass
309 or function. The first parameter is the file data that contains 276 or function. The first parameter is the file data that contains
316 const char *, 283 const char *,
317 size_t *); 284 size_t *);
318 285
319 /* Return the data found from the above call. The first three 286 /* Return the data found from the above call. The first three
320 parameters are the same as above. The fourth parameter is the data 287 parameters are the same as above. The fourth parameter is the data
321 itself and the fifth is the lenght of the data. */ 288 itself and the fifth is the length of the data. */
322 typedef void (lto_free_section_data_f) (struct lto_file_decl_data *, 289 typedef void (lto_free_section_data_f) (struct lto_file_decl_data *,
323 enum lto_section_type, 290 enum lto_section_type,
324 const char *, 291 const char *,
325 const char *, 292 const char *,
326 size_t); 293 size_t);
327 294
328 /* Cache of pickled nodes. Used to avoid writing the same node more 295 /* The location cache holds expanded locations for streamed in trees.
329 than once. The first time a tree node is streamed out, it is 296 This is done to reduce memory usage of libcpp linemap that strongly preffers
330 entered in this cache. Subsequent references to the same node are 297 locations to be inserted in the soruce order. */
331 resolved by looking it up in this cache. 298
332 299 class lto_location_cache
333 This is used in two ways: 300 {
334 301 public:
335 - On the writing side, the first time T is added to STREAMER_CACHE, 302 /* Apply all changes in location cache. Add locations into linemap and patch
336 a new reference index is created for T and T is emitted on the 303 trees. */
337 stream. If T needs to be emitted again to the stream, instead of 304 bool apply_location_cache ();
338 pickling it again, the reference index is emitted. 305 /* Tree merging did not suceed; mark all changes in the cache as accepted. */
339 306 void accept_location_cache ();
340 - On the reading side, the first time T is read from the stream, it 307 /* Tree merging did suceed; throw away recent changes. */
341 is reconstructed in memory and a new reference index created for 308 void revert_location_cache ();
342 T. The reconstructed T is inserted in some array so that when 309 void input_location (location_t *loc, struct bitpack_d *bp,
343 the reference index for T is found in the input stream, it can be 310 struct data_in *data_in);
344 used to look up into the array to get the reconstructed T. */ 311 lto_location_cache ()
345 struct lto_streamer_cache_d 312 : loc_cache (), accepted_length (0), current_file (NULL), current_line (0),
346 { 313 current_col (0), current_sysp (false), current_loc (UNKNOWN_LOCATION)
347 /* The mapping between tree nodes and slots into the nodes array. */ 314 {
348 htab_t node_map; 315 gcc_assert (!current_cache);
349 316 current_cache = this;
350 /* Node map to store entries into. */ 317 }
351 alloc_pool node_map_entries; 318 ~lto_location_cache ()
352 319 {
353 /* Next available slot in the nodes and offsets arrays. */ 320 apply_location_cache ();
354 unsigned next_slot; 321 gcc_assert (current_cache == this);
355 322 current_cache = NULL;
356 /* The nodes pickled so far. */ 323 }
357 VEC(tree,heap) *nodes; 324
358 325 /* There can be at most one instance of location cache (combining multiple
359 /* Offset into the stream where the nodes have been written. */ 326 would bring it out of sync with libcpp linemap); point to current
360 VEC(unsigned,heap) *offsets; 327 one. */
361 }; 328 static lto_location_cache *current_cache;
362 329
330 private:
331 static int cmp_loc (const void *pa, const void *pb);
332
333 struct cached_location
334 {
335 const char *file;
336 location_t *loc;
337 int line, col;
338 bool sysp;
339 };
340
341 /* The location cache. */
342
343 auto_vec<cached_location> loc_cache;
344
345 /* Accepted entries are ones used by trees that are known to be not unified
346 by tree merging. */
347
348 int accepted_length;
349
350 /* Bookkeeping to remember state in between calls to lto_apply_location_cache
351 When streaming gimple, the location cache is not used and thus
352 lto_apply_location_cache happens per location basis. It is then
353 useful to avoid redundant calls of linemap API. */
354
355 const char *current_file;
356 int current_line;
357 int current_col;
358 bool current_sysp;
359 location_t current_loc;
360 };
363 361
364 /* Structure used as buffer for reading an LTO file. */ 362 /* Structure used as buffer for reading an LTO file. */
365 struct lto_input_block 363 class lto_input_block
366 { 364 {
365 public:
366 /* Special constructor for the string table, it abuses this to
367 do random access but use the uhwi decoder. */
368 lto_input_block (const char *data_, unsigned int p_, unsigned int len_,
369 const unsigned char *mode_table_)
370 : data (data_), mode_table (mode_table_), p (p_), len (len_) {}
371 lto_input_block (const char *data_, unsigned int len_,
372 const unsigned char *mode_table_)
373 : data (data_), mode_table (mode_table_), p (0), len (len_) {}
374
367 const char *data; 375 const char *data;
376 const unsigned char *mode_table;
368 unsigned int p; 377 unsigned int p;
369 unsigned int len; 378 unsigned int len;
370 }; 379 };
371
372 #define LTO_INIT_INPUT_BLOCK(BASE,D,P,L) \
373 do { \
374 BASE.data = D; \
375 BASE.p = P; \
376 BASE.len = L; \
377 } while (0)
378
379 #define LTO_INIT_INPUT_BLOCK_PTR(BASE,D,P,L) \
380 do { \
381 BASE->data = D; \
382 BASE->p = P; \
383 BASE->len = L; \
384 } while (0)
385 380
386 381
387 /* The is the first part of the record for a function or constructor 382 /* The is the first part of the record for a function or constructor
388 in the .o file. */ 383 in the .o file. */
389 struct lto_header 384 struct lto_header
390 { 385 {
391 int16_t major_version; 386 int16_t major_version;
392 int16_t minor_version; 387 int16_t minor_version;
393 enum lto_section_type section_type; 388 };
389
390 /* The is the first part of the record in an LTO file for many of the
391 IPA passes. */
392 struct lto_simple_header : lto_header
393 {
394 /* Size of main gimple body of function. */
395 int32_t main_size;
396 };
397
398 struct lto_simple_header_with_strings : lto_simple_header
399 {
400 /* Size of the string table. */
401 int32_t string_size;
394 }; 402 };
395 403
396 /* The header for a function body. */ 404 /* The header for a function body. */
397 struct lto_function_header 405 struct lto_function_header : lto_simple_header_with_strings
398 { 406 {
399 /* The header for all types of sections. */
400 struct lto_header lto_header;
401
402 /* Number of labels with names. */
403 int32_t num_named_labels;
404
405 /* Number of labels without names. */
406 int32_t num_unnamed_labels;
407
408 /* Size compressed or 0 if not compressed. */
409 int32_t compressed_size;
410
411 /* Size of names for named labels. */
412 int32_t named_label_size;
413
414 /* Size of the cfg. */ 407 /* Size of the cfg. */
415 int32_t cfg_size; 408 int32_t cfg_size;
416
417 /* Size of main gimple body of function. */
418 int32_t main_size;
419
420 /* Size of the string table. */
421 int32_t string_size;
422 }; 409 };
423 410
424 411
425 /* Structure describing a symbol section. */ 412 /* Structure describing a symbol section. */
426 struct lto_decl_header 413 struct lto_decl_header : lto_simple_header_with_strings
427 { 414 {
428 /* The header for all types of sections. */
429 struct lto_header lto_header;
430
431 /* Size of region for decl state. */ 415 /* Size of region for decl state. */
432 int32_t decl_state_size; 416 int32_t decl_state_size;
433 417
434 /* Number of nodes in globals stream. */ 418 /* Number of nodes in globals stream. */
435 int32_t num_nodes; 419 int32_t num_nodes;
436
437 /* Size of region for expressions, decls, types, etc. */
438 int32_t main_size;
439
440 /* Size of the string table. */
441 int32_t string_size;
442 }; 420 };
443 421
444 422
445 /* Statistics gathered during LTO, WPA and LTRANS. */ 423 /* Statistics gathered during LTO, WPA and LTRANS. */
446 struct lto_stats_d 424 struct lto_stats_d
447 { 425 {
448 unsigned HOST_WIDE_INT num_input_cgraph_nodes; 426 unsigned HOST_WIDE_INT num_input_cgraph_nodes;
449 unsigned HOST_WIDE_INT num_output_cgraph_nodes; 427 unsigned HOST_WIDE_INT num_output_symtab_nodes;
450 unsigned HOST_WIDE_INT num_input_files; 428 unsigned HOST_WIDE_INT num_input_files;
451 unsigned HOST_WIDE_INT num_output_files; 429 unsigned HOST_WIDE_INT num_output_files;
452 unsigned HOST_WIDE_INT num_cgraph_partitions; 430 unsigned HOST_WIDE_INT num_cgraph_partitions;
453 unsigned HOST_WIDE_INT section_size[LTO_N_SECTION_TYPES]; 431 unsigned HOST_WIDE_INT section_size[LTO_N_SECTION_TYPES];
454 unsigned HOST_WIDE_INT num_function_bodies; 432 unsigned HOST_WIDE_INT num_function_bodies;
455 unsigned HOST_WIDE_INT num_trees[NUM_TREE_CODES]; 433 unsigned HOST_WIDE_INT num_trees[NUM_TREE_CODES];
456 unsigned HOST_WIDE_INT num_output_il_bytes; 434 unsigned HOST_WIDE_INT num_output_il_bytes;
457 unsigned HOST_WIDE_INT num_compressed_il_bytes; 435 unsigned HOST_WIDE_INT num_compressed_il_bytes;
458 unsigned HOST_WIDE_INT num_input_il_bytes; 436 unsigned HOST_WIDE_INT num_input_il_bytes;
459 unsigned HOST_WIDE_INT num_uncompressed_il_bytes; 437 unsigned HOST_WIDE_INT num_uncompressed_il_bytes;
460 }; 438 unsigned HOST_WIDE_INT num_tree_bodies_output;
439 unsigned HOST_WIDE_INT num_pickle_refs_output;
440 };
441
442 /* Entry of LTO symtab encoder. */
443 struct lto_encoder_entry
444 {
445 symtab_node *node;
446 /* Is the node in this partition (i.e. ltrans of this partition will
447 be responsible for outputting it)? */
448 unsigned int in_partition:1;
449 /* Do we encode body in this partition? */
450 unsigned int body:1;
451 /* Do we encode initializer in this partition?
452 For example the readonly variable initializers are encoded to aid
453 constant folding even if they are not in the partition. */
454 unsigned int initializer:1;
455 };
456
461 457
462 /* Encoder data structure used to stream callgraph nodes. */ 458 /* Encoder data structure used to stream callgraph nodes. */
463 struct lto_cgraph_encoder_d 459 struct lto_symtab_encoder_d
464 { 460 {
465 /* Map nodes to reference number. */ 461 vec<lto_encoder_entry> nodes;
466 struct pointer_map_t *map; 462 hash_map<symtab_node *, size_t> *map;
467 463 };
468 /* Map reference number to node. */ 464
469 VEC(cgraph_node_ptr,heap) *nodes; 465 typedef struct lto_symtab_encoder_d *lto_symtab_encoder_t;
470 466
471 /* Map of nodes where we want to output body. */ 467 /* Iterator structure for cgraph node sets. */
472 struct pointer_set_t *body; 468 struct lto_symtab_encoder_iterator
473 }; 469 {
474 470 lto_symtab_encoder_t encoder;
475 typedef struct lto_cgraph_encoder_d *lto_cgraph_encoder_t; 471 unsigned index;
476 472 };
477 /* Return number of encoded nodes in ENCODER. */ 473
478
479 static inline int
480 lto_cgraph_encoder_size (lto_cgraph_encoder_t encoder)
481 {
482 return VEC_length (cgraph_node_ptr, encoder->nodes);
483 }
484
485
486 /* Encoder data structure used to stream callgraph nodes. */
487 struct lto_varpool_encoder_d
488 {
489 /* Map nodes to reference number. */
490 struct pointer_map_t *map;
491
492 /* Map reference number to node. */
493 VEC(varpool_node_ptr,heap) *nodes;
494
495 /* Map of nodes where we want to output initializer. */
496 struct pointer_set_t *initializer;
497 };
498 typedef struct lto_varpool_encoder_d *lto_varpool_encoder_t;
499
500 /* Return number of encoded nodes in ENCODER. */
501
502 static inline int
503 lto_varpool_encoder_size (lto_varpool_encoder_t encoder)
504 {
505 return VEC_length (varpool_node_ptr, encoder->nodes);
506 }
507
508 /* Mapping from indices to trees. */
509 struct GTY(()) lto_tree_ref_table
510 {
511 /* Array of referenced trees . */
512 tree * GTY((length ("%h.size"))) trees;
513
514 /* Size of array. */
515 unsigned int size;
516 };
517
518
519 /* Mapping between trees and slots in an array. */
520 struct lto_decl_slot
521 {
522 tree t;
523 int slot_num;
524 };
525 474
526 475
527 /* The lto_tree_ref_encoder struct is used to encode trees into indices. */ 476 /* The lto_tree_ref_encoder struct is used to encode trees into indices. */
528 477
529 struct lto_tree_ref_encoder 478 struct lto_tree_ref_encoder
530 { 479 {
531 htab_t tree_hash_table; /* Maps pointers to indices. */ 480 hash_map<tree, unsigned> *tree_hash_table; /* Maps pointers to indices. */
532 unsigned int next_index; /* Next available index. */ 481 vec<tree> trees; /* Maps indices to pointers. */
533 VEC(tree,heap) *trees; /* Maps indices to pointers. */
534 }; 482 };
535 483
536 484
537 /* Structure to hold states of input scope. */ 485 /* Structure to hold states of input scope. */
538 struct GTY(()) lto_in_decl_state 486 struct GTY((for_user)) lto_in_decl_state
539 { 487 {
540 /* Array of lto_in_decl_buffers to store type and decls streams. */ 488 /* Array of lto_in_decl_buffers to store type and decls streams. */
541 struct lto_tree_ref_table streams[LTO_N_DECL_STREAMS]; 489 vec<tree, va_gc> *streams[LTO_N_DECL_STREAMS];
542 490
543 /* If this in-decl state is associated with a function. FN_DECL 491 /* If this in-decl state is associated with a function. FN_DECL
544 point to the FUNCTION_DECL. */ 492 point to the FUNCTION_DECL. */
545 tree fn_decl; 493 tree fn_decl;
494
495 /* True if decl state is compressed. */
496 bool compressed;
546 }; 497 };
547 498
548 typedef struct lto_in_decl_state *lto_in_decl_state_ptr; 499 typedef struct lto_in_decl_state *lto_in_decl_state_ptr;
549 500
501 struct decl_state_hasher : ggc_ptr_hash<lto_in_decl_state>
502 {
503 static hashval_t
504 hash (lto_in_decl_state *s)
505 {
506 return htab_hash_pointer (s->fn_decl);
507 }
508
509 static bool
510 equal (lto_in_decl_state *a, lto_in_decl_state *b)
511 {
512 return a->fn_decl == b->fn_decl;
513 }
514 };
550 515
551 /* The structure that holds all of the vectors of global types, 516 /* The structure that holds all of the vectors of global types,
552 decls and cgraph nodes used in the serialization of this file. */ 517 decls and cgraph nodes used in the serialization of this file. */
553 struct lto_out_decl_state 518 struct lto_out_decl_state
554 { 519 {
555 /* The buffers contain the sets of decls of various kinds and types we have 520 /* The buffers contain the sets of decls of various kinds and types we have
556 seen so far and the indexes assigned to them. */ 521 seen so far and the indexes assigned to them. */
557 struct lto_tree_ref_encoder streams[LTO_N_DECL_STREAMS]; 522 struct lto_tree_ref_encoder streams[LTO_N_DECL_STREAMS];
558 523
559 /* Encoder for cgraph nodes. */ 524 /* Encoder for cgraph nodes. */
560 lto_cgraph_encoder_t cgraph_node_encoder; 525 lto_symtab_encoder_t symtab_node_encoder;
561
562 /* Encoder for varpool nodes. */
563 lto_varpool_encoder_t varpool_node_encoder;
564 526
565 /* If this out-decl state belongs to a function, fn_decl points to that 527 /* If this out-decl state belongs to a function, fn_decl points to that
566 function. Otherwise, it is NULL. */ 528 function. Otherwise, it is NULL. */
567 tree fn_decl; 529 tree fn_decl;
530
531 /* True if decl state is compressed. */
532 bool compressed;
568 }; 533 };
569 534
570 typedef struct lto_out_decl_state *lto_out_decl_state_ptr; 535 typedef struct lto_out_decl_state *lto_out_decl_state_ptr;
571 536
572 DEF_VEC_P(lto_out_decl_state_ptr); 537
573 DEF_VEC_ALLOC_P(lto_out_decl_state_ptr, heap); 538 /* Compact representation of a index <-> resolution pair. Unpacked to an
539 vector later. */
540 struct res_pair
541 {
542 ld_plugin_symbol_resolution_t res;
543 unsigned index;
544 };
545
574 546
575 /* One of these is allocated for each object file that being compiled 547 /* One of these is allocated for each object file that being compiled
576 by lto. This structure contains the tables that are needed by the 548 by lto. This structure contains the tables that are needed by the
577 serialized functions and ipa passes to connect themselves to the 549 serialized functions and ipa passes to connect themselves to the
578 global types and decls as they are reconstituted. */ 550 global types and decls as they are reconstituted. */
584 /* Decl state corresponding to regions outside of any functions 556 /* Decl state corresponding to regions outside of any functions
585 in the compilation unit. */ 557 in the compilation unit. */
586 struct lto_in_decl_state *global_decl_state; 558 struct lto_in_decl_state *global_decl_state;
587 559
588 /* Table of cgraph nodes present in this file. */ 560 /* Table of cgraph nodes present in this file. */
589 lto_cgraph_encoder_t GTY((skip)) cgraph_node_encoder; 561 lto_symtab_encoder_t GTY((skip)) symtab_node_encoder;
590
591 /* Table of varpool nodes present in this file. */
592 lto_varpool_encoder_t GTY((skip)) varpool_node_encoder;
593 562
594 /* Hash table maps lto-related section names to location in file. */ 563 /* Hash table maps lto-related section names to location in file. */
595 htab_t GTY((param_is (struct lto_in_decl_state))) function_decl_states; 564 hash_table<decl_state_hasher> *function_decl_states;
596 565
597 /* The .o file that these offsets relate to. */ 566 /* The .o file that these offsets relate to. */
598 const char *GTY((skip)) file_name; 567 const char *GTY((skip)) file_name;
599 568
600 /* Hash table maps lto-related section names to location in file. */ 569 /* Hash table maps lto-related section names to location in file. */
605 574
606 /* Linked list used temporarily in reader */ 575 /* Linked list used temporarily in reader */
607 struct lto_file_decl_data *next; 576 struct lto_file_decl_data *next;
608 577
609 /* Sub ID for merged objects. */ 578 /* Sub ID for merged objects. */
610 unsigned id; 579 unsigned HOST_WIDE_INT id;
611 580
612 /* Symbol resolutions for this file */ 581 /* Symbol resolutions for this file */
613 VEC(ld_plugin_symbol_resolution_t,heap) * GTY((skip)) resolutions; 582 vec<res_pair> GTY((skip)) respairs;
583 unsigned max_index;
614 584
615 struct gcov_ctr_summary GTY((skip)) profile_info; 585 struct gcov_ctr_summary GTY((skip)) profile_info;
586
587 /* Map assigning declarations their resolutions. */
588 hash_map<tree, ld_plugin_symbol_resolution> * GTY((skip)) resolution_map;
589
590 /* Mode translation table. */
591 const unsigned char *mode_table;
616 }; 592 };
617 593
618 typedef struct lto_file_decl_data *lto_file_decl_data_ptr; 594 typedef struct lto_file_decl_data *lto_file_decl_data_ptr;
619 595
620 struct lto_char_ptr_base 596 struct lto_char_ptr_base
645 621
646 /* The total number of characters written. */ 622 /* The total number of characters written. */
647 unsigned int total_size; 623 unsigned int total_size;
648 }; 624 };
649 625
650 /* The is the first part of the record in an LTO file for many of the
651 IPA passes. */
652 struct lto_simple_header
653 {
654 /* The header for all types of sections. */
655 struct lto_header lto_header;
656
657 /* Size of main gimple body of function. */
658 int32_t main_size;
659
660 /* Size of main stream when compressed. */
661 int32_t compressed_size;
662 };
663
664 /* A simple output block. This can be used for simple IPA passes that 626 /* A simple output block. This can be used for simple IPA passes that
665 do not need more than one stream. */ 627 do not need more than one stream. */
666 struct lto_simple_output_block 628 struct lto_simple_output_block
667 { 629 {
668 enum lto_section_type section_type; 630 enum lto_section_type section_type;
670 632
671 /* The stream that the main tree codes are written to. */ 633 /* The stream that the main tree codes are written to. */
672 struct lto_output_stream *main_stream; 634 struct lto_output_stream *main_stream;
673 }; 635 };
674 636
637 /* String hashing. */
638
639 struct string_slot
640 {
641 const char *s;
642 int len;
643 unsigned int slot_num;
644 };
645
646 /* Hashtable helpers. */
647
648 struct string_slot_hasher : nofree_ptr_hash <string_slot>
649 {
650 static inline hashval_t hash (const string_slot *);
651 static inline bool equal (const string_slot *, const string_slot *);
652 };
653
654 /* Returns a hash code for DS. Adapted from libiberty's htab_hash_string
655 to support strings that may not end in '\0'. */
656
657 inline hashval_t
658 string_slot_hasher::hash (const string_slot *ds)
659 {
660 hashval_t r = ds->len;
661 int i;
662
663 for (i = 0; i < ds->len; i++)
664 r = r * 67 + (unsigned)ds->s[i] - 113;
665 return r;
666 }
667
668 /* Returns nonzero if DS1 and DS2 are equal. */
669
670 inline bool
671 string_slot_hasher::equal (const string_slot *ds1, const string_slot *ds2)
672 {
673 if (ds1->len == ds2->len)
674 return memcmp (ds1->s, ds2->s, ds1->len) == 0;
675
676 return 0;
677 }
678
675 /* Data structure holding all the data and descriptors used when writing 679 /* Data structure holding all the data and descriptors used when writing
676 an LTO file. */ 680 an LTO file. */
677 struct output_block 681 struct output_block
678 { 682 {
679 enum lto_section_type section_type; 683 enum lto_section_type section_type;
688 /* The stream that contains the cfg. */ 692 /* The stream that contains the cfg. */
689 struct lto_output_stream *cfg_stream; 693 struct lto_output_stream *cfg_stream;
690 694
691 /* The hash table that contains the set of strings we have seen so 695 /* The hash table that contains the set of strings we have seen so
692 far and the indexes assigned to them. */ 696 far and the indexes assigned to them. */
693 htab_t string_hash_table; 697 hash_table<string_slot_hasher> *string_hash_table;
694 698
695 /* The current cgraph_node that we are currently serializing. Null 699 /* The current symbol that we are currently serializing. Null
696 if we are serializing something else. */ 700 if we are serializing something else. */
697 struct cgraph_node *cgraph_node; 701 symtab_node *symbol;
698 702
699 /* These are the last file and line that were seen in the stream. 703 /* 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 704 If the current node differs from these, it needs to insert
701 something into the stream and fix these up. */ 705 something into the stream and fix these up. */
702 const char *current_file; 706 const char *current_file;
703 int current_line; 707 int current_line;
704 int current_col; 708 int current_col;
705 709 bool current_sysp;
706 /* True if writing globals and types. */
707 bool global;
708 710
709 /* Cache of nodes written in this section. */ 711 /* Cache of nodes written in this section. */
710 struct lto_streamer_cache_d *writer_cache; 712 struct streamer_tree_cache_d *writer_cache;
713
714 /* All data persistent across whole duration of output block
715 can go here. */
716 struct obstack obstack;
711 }; 717 };
712 718
713 719
714 /* Data and descriptors used when reading from an LTO file. */ 720 /* Data and descriptors used when reading from an LTO file. */
715 struct data_in 721 struct data_in
716 { 722 {
717 /* The global decls and types. */ 723 /* The global decls and types. */
718 struct lto_file_decl_data *file_data; 724 struct lto_file_decl_data *file_data;
719 725
720 /* All of the labels. */
721 tree *labels;
722
723 /* The string table. */ 726 /* The string table. */
724 const char *strings; 727 const char *strings;
725 728
726 /* The length of the string table. */ 729 /* The length of the string table. */
727 unsigned int strings_len; 730 unsigned int strings_len;
728 731
729 /* Number of named labels. Used to find the index of unnamed labels
730 since they share space with the named labels. */
731 unsigned int num_named_labels;
732
733 /* Number of unnamed labels. */
734 unsigned int num_unnamed_labels;
735
736 const char *current_file;
737 int current_line;
738 int current_col;
739
740 /* Maps each reference number to the resolution done by the linker. */ 732 /* Maps each reference number to the resolution done by the linker. */
741 VEC(ld_plugin_symbol_resolution_t,heap) *globals_resolution; 733 vec<ld_plugin_symbol_resolution_t> globals_resolution;
742 734
743 /* Cache of pickled nodes. */ 735 /* Cache of pickled nodes. */
744 struct lto_streamer_cache_d *reader_cache; 736 struct streamer_tree_cache_d *reader_cache;
737
738 /* Cache of source code location. */
739 lto_location_cache location_cache;
745 }; 740 };
746 741
747 742
748 /* In lto-section-in.c */ 743 /* In lto-section-in.c */
749 extern struct lto_input_block * lto_create_simple_input_block ( 744 extern struct lto_input_block * lto_create_simple_input_block (
757 lto_get_section_data_f *, 752 lto_get_section_data_f *,
758 lto_free_section_data_f *); 753 lto_free_section_data_f *);
759 extern struct lto_file_decl_data **lto_get_file_decl_data (void); 754 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 *, 755 extern const char *lto_get_section_data (struct lto_file_decl_data *,
761 enum lto_section_type, 756 enum lto_section_type,
762 const char *, size_t *); 757 const char *, size_t *,
758 bool decompress = false);
759 extern const char *lto_get_raw_section_data (struct lto_file_decl_data *,
760 enum lto_section_type,
761 const char *, size_t *);
763 extern void lto_free_section_data (struct lto_file_decl_data *, 762 extern void lto_free_section_data (struct lto_file_decl_data *,
764 enum lto_section_type, 763 enum lto_section_type,
765 const char *, const char *, size_t); 764 const char *, const char *, size_t,
766 extern unsigned char lto_input_1_unsigned (struct lto_input_block *); 765 bool decompress = false);
767 extern unsigned HOST_WIDE_INT lto_input_uleb128 (struct lto_input_block *); 766 extern void lto_free_raw_section_data (struct lto_file_decl_data *,
768 extern unsigned HOST_WIDEST_INT lto_input_widest_uint_uleb128 ( 767 enum lto_section_type,
769 struct lto_input_block *); 768 const char *, const char *, size_t);
770 extern HOST_WIDE_INT lto_input_sleb128 (struct lto_input_block *);
771 extern htab_t lto_create_renaming_table (void); 769 extern htab_t lto_create_renaming_table (void);
772 extern void lto_record_renamed_decl (struct lto_file_decl_data *, 770 extern void lto_record_renamed_decl (struct lto_file_decl_data *,
773 const char *, const char *); 771 const char *, const char *);
774 extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data *, 772 extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data *,
775 const char *); 773 const char *);
776 extern struct lto_in_decl_state *lto_new_in_decl_state (void); 774 extern struct lto_in_decl_state *lto_new_in_decl_state (void);
777 extern void lto_delete_in_decl_state (struct lto_in_decl_state *); 775 extern void lto_delete_in_decl_state (struct lto_in_decl_state *);
778 extern hashval_t lto_hash_in_decl_state (const void *);
779 extern int lto_eq_in_decl_state (const void *, const void *);
780 extern struct lto_in_decl_state *lto_get_function_in_decl_state ( 776 extern struct lto_in_decl_state *lto_get_function_in_decl_state (
781 struct lto_file_decl_data *, tree); 777 struct lto_file_decl_data *, tree);
778 extern void lto_free_function_in_decl_state (struct lto_in_decl_state *);
779 extern void lto_free_function_in_decl_state_for_node (symtab_node *);
780 extern void lto_section_overrun (struct lto_input_block *) ATTRIBUTE_NORETURN;
781 extern void lto_value_range_error (const char *,
782 HOST_WIDE_INT, HOST_WIDE_INT,
783 HOST_WIDE_INT) ATTRIBUTE_NORETURN;
782 784
783 /* In lto-section-out.c */ 785 /* In lto-section-out.c */
784 extern hashval_t lto_hash_decl_slot_node (const void *);
785 extern int lto_eq_decl_slot_node (const void *, const void *);
786 extern hashval_t lto_hash_type_slot_node (const void *);
787 extern int lto_eq_type_slot_node (const void *, const void *);
788 extern void lto_begin_section (const char *, bool); 786 extern void lto_begin_section (const char *, bool);
789 extern void lto_end_section (void); 787 extern void lto_end_section (void);
788 extern void lto_write_data (const void *, unsigned int);
789 extern void lto_write_raw_data (const void *, unsigned int);
790 extern void lto_write_stream (struct lto_output_stream *); 790 extern void lto_write_stream (struct lto_output_stream *);
791 extern void lto_output_1_stream (struct lto_output_stream *, char);
792 extern void lto_output_data_stream (struct lto_output_stream *, const void *,
793 size_t);
794 extern void lto_output_uleb128_stream (struct lto_output_stream *,
795 unsigned HOST_WIDE_INT);
796 extern void lto_output_widest_uint_uleb128_stream (struct lto_output_stream *,
797 unsigned HOST_WIDEST_INT);
798 extern void lto_output_sleb128_stream (struct lto_output_stream *,
799 HOST_WIDE_INT);
800 extern bool lto_output_decl_index (struct lto_output_stream *, 791 extern bool lto_output_decl_index (struct lto_output_stream *,
801 struct lto_tree_ref_encoder *, 792 struct lto_tree_ref_encoder *,
802 tree, unsigned int *); 793 tree, unsigned int *);
803 extern void lto_output_field_decl_index (struct lto_out_decl_state *, 794 extern void lto_output_field_decl_index (struct lto_out_decl_state *,
804 struct lto_output_stream *, tree); 795 struct lto_output_stream *, tree);
820 extern struct lto_out_decl_state *lto_get_out_decl_state (void); 811 extern struct lto_out_decl_state *lto_get_out_decl_state (void);
821 extern void lto_push_out_decl_state (struct lto_out_decl_state *); 812 extern void lto_push_out_decl_state (struct lto_out_decl_state *);
822 extern struct lto_out_decl_state *lto_pop_out_decl_state (void); 813 extern struct lto_out_decl_state *lto_pop_out_decl_state (void);
823 extern void lto_record_function_out_decl_state (tree, 814 extern void lto_record_function_out_decl_state (tree,
824 struct lto_out_decl_state *); 815 struct lto_out_decl_state *);
816 extern void lto_append_block (struct lto_output_stream *);
825 817
826 818
827 /* In lto-streamer.c. */ 819 /* In lto-streamer.c. */
820
821 /* Set when streaming LTO for offloading compiler. */
822 extern bool lto_stream_offload_p;
823
828 extern const char *lto_tag_name (enum LTO_tags); 824 extern const char *lto_tag_name (enum LTO_tags);
829 extern bitmap lto_bitmap_alloc (void); 825 extern bitmap lto_bitmap_alloc (void);
830 extern void lto_bitmap_free (bitmap); 826 extern void lto_bitmap_free (bitmap);
831 extern char *lto_get_section_name (int, const char *, struct lto_file_decl_data *); 827 extern char *lto_get_section_name (int, const char *, struct lto_file_decl_data *);
832 extern void print_lto_report (void); 828 extern void print_lto_report (const char *);
833 extern bool lto_streamer_cache_insert (struct lto_streamer_cache_d *, tree,
834 int *, unsigned *);
835 extern bool lto_streamer_cache_insert_at (struct lto_streamer_cache_d *, tree,
836 int);
837 extern bool lto_streamer_cache_lookup (struct lto_streamer_cache_d *, tree,
838 int *);
839 extern tree lto_streamer_cache_get (struct lto_streamer_cache_d *, int);
840 extern struct lto_streamer_cache_d *lto_streamer_cache_create (void);
841 extern void lto_streamer_cache_delete (struct lto_streamer_cache_d *);
842 extern void lto_streamer_init (void); 829 extern void lto_streamer_init (void);
843 extern bool gate_lto_out (void); 830 extern bool gate_lto_out (void);
844 #ifdef LTO_STREAMER_DEBUG 831 extern void lto_check_version (int, int, const char *);
845 extern void lto_orig_address_map (tree, intptr_t); 832 extern void lto_streamer_hooks_init (void);
846 extern intptr_t lto_orig_address_get (tree);
847 extern void lto_orig_address_remove (tree);
848 #endif
849 extern void lto_check_version (int, int);
850
851 833
852 /* In lto-streamer-in.c */ 834 /* In lto-streamer-in.c */
853 extern void lto_input_cgraph (struct lto_file_decl_data *, const char *); 835 extern void lto_input_cgraph (struct lto_file_decl_data *, const char *);
854 extern void lto_init_reader (void); 836 extern void lto_reader_init (void);
855 extern tree lto_input_tree (struct lto_input_block *, struct data_in *); 837 extern void lto_input_function_body (struct lto_file_decl_data *,
856 extern void lto_input_function_body (struct lto_file_decl_data *, tree, 838 struct cgraph_node *,
857 const char *); 839 const char *);
840 extern void lto_input_variable_constructor (struct lto_file_decl_data *,
841 struct varpool_node *,
842 const char *);
858 extern void lto_input_constructors_and_inits (struct lto_file_decl_data *, 843 extern void lto_input_constructors_and_inits (struct lto_file_decl_data *,
859 const char *); 844 const char *);
860 extern void lto_init_reader (void); 845 extern void lto_input_toplevel_asms (struct lto_file_decl_data *, int);
846 extern void lto_input_mode_table (struct lto_file_decl_data *);
861 extern struct data_in *lto_data_in_create (struct lto_file_decl_data *, 847 extern struct data_in *lto_data_in_create (struct lto_file_decl_data *,
862 const char *, unsigned, 848 const char *, unsigned,
863 VEC(ld_plugin_symbol_resolution_t,heap) *); 849 vec<ld_plugin_symbol_resolution_t> );
864 extern void lto_data_in_delete (struct data_in *); 850 extern void lto_data_in_delete (struct data_in *);
851 extern void lto_input_data_block (struct lto_input_block *, void *, size_t);
852 void lto_input_location (location_t *, struct bitpack_d *, struct data_in *);
853 location_t stream_input_location_now (struct bitpack_d *bp,
854 struct data_in *data);
855 tree lto_input_tree_ref (struct lto_input_block *, struct data_in *,
856 struct function *, enum LTO_tags);
857 void lto_tag_check_set (enum LTO_tags, int, ...);
858 void lto_init_eh (void);
859 hashval_t lto_input_scc (struct lto_input_block *, struct data_in *,
860 unsigned *, unsigned *);
861 tree lto_input_tree_1 (struct lto_input_block *, struct data_in *,
862 enum LTO_tags, hashval_t hash);
863 tree lto_input_tree (struct lto_input_block *, struct data_in *);
865 864
866 865
867 /* In lto-streamer-out.c */ 866 /* In lto-streamer-out.c */
868 extern void lto_register_decl_definition (tree, struct lto_file_decl_data *); 867 extern void lto_register_decl_definition (tree, struct lto_file_decl_data *);
869 extern struct output_block *create_output_block (enum lto_section_type); 868 extern struct output_block *create_output_block (enum lto_section_type);
870 extern void destroy_output_block (struct output_block *); 869 extern void destroy_output_block (struct output_block *);
871 extern void lto_output_tree (struct output_block *, tree, bool); 870 extern void lto_output_tree (struct output_block *, tree, bool, bool);
871 extern void lto_output_toplevel_asms (void);
872 extern void produce_asm (struct output_block *ob, tree fn); 872 extern void produce_asm (struct output_block *ob, tree fn);
873 extern void lto_output ();
874 extern void produce_asm_for_decls ();
875 void lto_output_decl_state_streams (struct output_block *,
876 struct lto_out_decl_state *);
877 void lto_output_decl_state_refs (struct output_block *,
878 struct lto_output_stream *,
879 struct lto_out_decl_state *);
880 void lto_output_location (struct output_block *, struct bitpack_d *, location_t);
881 void lto_output_init_mode_table (void);
873 882
874 883
875 /* In lto-cgraph.c */ 884 /* In lto-cgraph.c */
876 struct cgraph_node *lto_cgraph_encoder_deref (lto_cgraph_encoder_t, int); 885 extern bool asm_nodes_output;
877 int lto_cgraph_encoder_lookup (lto_cgraph_encoder_t, struct cgraph_node *); 886 lto_symtab_encoder_t lto_symtab_encoder_new (bool);
878 lto_cgraph_encoder_t lto_cgraph_encoder_new (void); 887 int lto_symtab_encoder_encode (lto_symtab_encoder_t, symtab_node *);
879 int lto_cgraph_encoder_encode (lto_cgraph_encoder_t, struct cgraph_node *); 888 void lto_symtab_encoder_delete (lto_symtab_encoder_t);
880 void lto_cgraph_encoder_delete (lto_cgraph_encoder_t); 889 bool lto_symtab_encoder_delete_node (lto_symtab_encoder_t, symtab_node *);
881 bool lto_cgraph_encoder_encode_body_p (lto_cgraph_encoder_t, 890 bool lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t,
882 struct cgraph_node *); 891 struct cgraph_node *);
883 892 bool lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t,
884 bool lto_varpool_encoder_encode_body_p (lto_varpool_encoder_t, 893 symtab_node *);
885 struct varpool_node *); 894 void lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t,
886 struct varpool_node *lto_varpool_encoder_deref (lto_varpool_encoder_t, int); 895 symtab_node *);
887 int lto_varpool_encoder_lookup (lto_varpool_encoder_t, struct varpool_node *); 896
888 lto_varpool_encoder_t lto_varpool_encoder_new (void); 897 bool lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t,
889 int lto_varpool_encoder_encode (lto_varpool_encoder_t, struct varpool_node *); 898 varpool_node *);
890 void lto_varpool_encoder_delete (lto_varpool_encoder_t); 899 void output_symtab (void);
891 bool lto_varpool_encoder_encode_initializer_p (lto_varpool_encoder_t, 900 void input_symtab (void);
892 struct varpool_node *); 901 void output_offload_tables (void);
893 void output_cgraph (cgraph_node_set, varpool_node_set); 902 void input_offload_tables (bool);
894 void input_cgraph (void);
895 bool referenced_from_other_partition_p (struct ipa_ref_list *, 903 bool referenced_from_other_partition_p (struct ipa_ref_list *,
896 cgraph_node_set, 904 lto_symtab_encoder_t);
897 varpool_node_set vset);
898 bool reachable_from_other_partition_p (struct cgraph_node *, 905 bool reachable_from_other_partition_p (struct cgraph_node *,
899 cgraph_node_set); 906 lto_symtab_encoder_t);
900 bool referenced_from_this_partition_p (struct ipa_ref_list *, 907 bool referenced_from_this_partition_p (symtab_node *,
901 cgraph_node_set, 908 lto_symtab_encoder_t);
902 varpool_node_set vset);
903 bool reachable_from_this_partition_p (struct cgraph_node *, 909 bool reachable_from_this_partition_p (struct cgraph_node *,
904 cgraph_node_set); 910 lto_symtab_encoder_t);
905 void compute_ltrans_boundary (struct lto_out_decl_state *state, 911 lto_symtab_encoder_t compute_ltrans_boundary (lto_symtab_encoder_t encoder);
906 cgraph_node_set, varpool_node_set); 912 void select_what_to_stream (void);
907 913
908 914 /* In options-save.c. */
909 /* In lto-symtab.c. */ 915 void cl_target_option_stream_out (struct output_block *, struct bitpack_d *,
910 extern void lto_symtab_register_decl (tree, ld_plugin_symbol_resolution_t, 916 struct cl_target_option *);
911 struct lto_file_decl_data *); 917
912 extern void lto_symtab_merge_decls (void); 918 void cl_target_option_stream_in (struct data_in *,
913 extern void lto_symtab_merge_cgraph_nodes (void); 919 struct bitpack_d *,
914 extern tree lto_symtab_prevailing_decl (tree decl); 920 struct cl_target_option *);
915 extern enum ld_plugin_symbol_resolution lto_symtab_get_resolution (tree decl); 921
916 extern void lto_symtab_free (void); 922 void cl_optimization_stream_out (struct bitpack_d *, struct cl_optimization *);
917 extern GTY(()) VEC(tree,gc) *lto_global_var_decls; 923
924 void cl_optimization_stream_in (struct bitpack_d *, struct cl_optimization *);
925
918 926
919 927
920 /* In lto-opts.c. */ 928 /* In lto-opts.c. */
921 extern void lto_register_user_option (size_t, const char *, int, int);
922 extern void lto_read_file_options (struct lto_file_decl_data *);
923 extern void lto_write_options (void); 929 extern void lto_write_options (void);
924 extern void lto_reissue_options (void);
925 void lto_clear_user_options (void);
926 void lto_clear_file_options (void);
927
928
929 /* In lto-wpa-fixup.c */
930 void lto_mark_nothrow_fndecl (tree);
931 void lto_fixup_nothrow_decls (void);
932 930
933 931
934 /* Statistics gathered during LTO, WPA and LTRANS. */ 932 /* Statistics gathered during LTO, WPA and LTRANS. */
935 extern struct lto_stats_d lto_stats; 933 extern struct lto_stats_d lto_stats;
936 934
937 /* Section names corresponding to the values of enum lto_section_type. */ 935 /* Section names corresponding to the values of enum lto_section_type. */
938 extern const char *lto_section_name[]; 936 extern const char *lto_section_name[];
939 937
940 /* Holds all the out decl states of functions output so far in the 938 /* Holds all the out decl states of functions output so far in the
941 current output file. */ 939 current output file. */
942 extern VEC(lto_out_decl_state_ptr, heap) *lto_function_decl_states; 940 extern vec<lto_out_decl_state_ptr> lto_function_decl_states;
943 941
944 /* Return true if LTO tag TAG corresponds to a tree code. */ 942 /* Return true if LTO tag TAG corresponds to a tree code. */
945 static inline bool 943 static inline bool
946 lto_tag_is_tree_code_p (enum LTO_tags tag) 944 lto_tag_is_tree_code_p (enum LTO_tags tag)
947 { 945 {
948 return tag > LTO_null && (unsigned) tag <= NUM_TREE_CODES; 946 return tag > LTO_tree_pickle_reference && (unsigned) tag <= MAX_TREE_CODES;
949 } 947 }
950 948
951 949
952 /* Return true if LTO tag TAG corresponds to a gimple code. */ 950 /* Return true if LTO tag TAG corresponds to a gimple code. */
953 static inline bool 951 static inline bool
954 lto_tag_is_gimple_code_p (enum LTO_tags tag) 952 lto_tag_is_gimple_code_p (enum LTO_tags tag)
955 { 953 {
956 return (unsigned) tag >= NUM_TREE_CODES + 1 954 return (unsigned) tag >= NUM_TREE_CODES + 2
957 && (unsigned) tag < 1 + NUM_TREE_CODES + LAST_AND_UNUSED_GIMPLE_CODE; 955 && (unsigned) tag < 2 + NUM_TREE_CODES + LAST_AND_UNUSED_GIMPLE_CODE;
958 } 956 }
959 957
960 958
961 /* Return the LTO tag corresponding to gimple code CODE. See enum 959 /* Return the LTO tag corresponding to gimple code CODE. See enum
962 LTO_tags for details on the conversion. */ 960 LTO_tags for details on the conversion. */
963 static inline enum LTO_tags 961 static inline enum LTO_tags
964 lto_gimple_code_to_tag (enum gimple_code code) 962 lto_gimple_code_to_tag (enum gimple_code code)
965 { 963 {
966 return (enum LTO_tags) ((unsigned) code + NUM_TREE_CODES + 1); 964 return (enum LTO_tags) ((unsigned) code + NUM_TREE_CODES + 2);
967 } 965 }
968 966
969 967
970 /* Return the GIMPLE code corresponding to TAG. See enum LTO_tags for 968 /* Return the GIMPLE code corresponding to TAG. See enum LTO_tags for
971 details on the conversion. */ 969 details on the conversion. */
972 static inline enum gimple_code 970 static inline enum gimple_code
973 lto_tag_to_gimple_code (enum LTO_tags tag) 971 lto_tag_to_gimple_code (enum LTO_tags tag)
974 { 972 {
975 gcc_assert (lto_tag_is_gimple_code_p (tag)); 973 gcc_assert (lto_tag_is_gimple_code_p (tag));
976 return (enum gimple_code) ((unsigned) tag - NUM_TREE_CODES - 1); 974 return (enum gimple_code) ((unsigned) tag - NUM_TREE_CODES - 2);
977 } 975 }
978 976
979 977
980 /* Return the LTO tag corresponding to tree code CODE. See enum 978 /* Return the LTO tag corresponding to tree code CODE. See enum
981 LTO_tags for details on the conversion. */ 979 LTO_tags for details on the conversion. */
982 static inline enum LTO_tags 980 static inline enum LTO_tags
983 lto_tree_code_to_tag (enum tree_code code) 981 lto_tree_code_to_tag (enum tree_code code)
984 { 982 {
985 return (enum LTO_tags) ((unsigned) code + 1); 983 return (enum LTO_tags) ((unsigned) code + 2);
986 } 984 }
987 985
988 986
989 /* Return the tree code corresponding to TAG. See enum LTO_tags for 987 /* Return the tree code corresponding to TAG. See enum LTO_tags for
990 details on the conversion. */ 988 details on the conversion. */
991 static inline enum tree_code 989 static inline enum tree_code
992 lto_tag_to_tree_code (enum LTO_tags tag) 990 lto_tag_to_tree_code (enum LTO_tags tag)
993 { 991 {
994 gcc_assert (lto_tag_is_tree_code_p (tag)); 992 gcc_assert (lto_tag_is_tree_code_p (tag));
995 return (enum tree_code) ((unsigned) tag - 1); 993 return (enum tree_code) ((unsigned) tag - 2);
994 }
995
996 /* Check that tag ACTUAL == EXPECTED. */
997 static inline void
998 lto_tag_check (enum LTO_tags actual, enum LTO_tags expected)
999 {
1000 if (actual != expected)
1001 internal_error ("bytecode stream: expected tag %s instead of %s",
1002 lto_tag_name (expected), lto_tag_name (actual));
1003 }
1004
1005 /* Check that tag ACTUAL is in the range [TAG1, TAG2]. */
1006 static inline void
1007 lto_tag_check_range (enum LTO_tags actual, enum LTO_tags tag1,
1008 enum LTO_tags tag2)
1009 {
1010 if (actual < tag1 || actual > tag2)
1011 internal_error ("bytecode stream: tag %s is not in the expected range "
1012 "[%s, %s]",
1013 lto_tag_name (actual),
1014 lto_tag_name (tag1),
1015 lto_tag_name (tag2));
996 } 1016 }
997 1017
998 /* Initialize an lto_out_decl_buffer ENCODER. */ 1018 /* Initialize an lto_out_decl_buffer ENCODER. */
999 static inline void 1019 static inline void
1000 lto_init_tree_ref_encoder (struct lto_tree_ref_encoder *encoder, 1020 lto_init_tree_ref_encoder (struct lto_tree_ref_encoder *encoder)
1001 htab_hash hash_fn, htab_eq eq_fn) 1021 {
1002 { 1022 encoder->tree_hash_table = new hash_map<tree, unsigned> (251);
1003 encoder->tree_hash_table = htab_create (37, hash_fn, eq_fn, free); 1023 encoder->trees.create (0);
1004 encoder->next_index = 0; 1024 }
1005 encoder->trees = NULL; 1025
1006 } 1026
1007 1027 /* Destroy an lto_tree_ref_encoder ENCODER by freeing its contents. The
1008
1009 /* Destory an lto_tree_ref_encoder ENCODER by freeing its contents. The
1010 memory used by ENCODER is not freed by this function. */ 1028 memory used by ENCODER is not freed by this function. */
1011 static inline void 1029 static inline void
1012 lto_destroy_tree_ref_encoder (struct lto_tree_ref_encoder *encoder) 1030 lto_destroy_tree_ref_encoder (struct lto_tree_ref_encoder *encoder)
1013 { 1031 {
1014 /* Hash table may be delete already. */ 1032 /* Hash table may be delete already. */
1015 if (encoder->tree_hash_table) 1033 delete encoder->tree_hash_table;
1016 htab_delete (encoder->tree_hash_table); 1034 encoder->tree_hash_table = NULL;
1017 VEC_free (tree, heap, encoder->trees); 1035 encoder->trees.release ();
1018 } 1036 }
1019 1037
1020 /* Return the number of trees encoded in ENCODER. */ 1038 /* Return the number of trees encoded in ENCODER. */
1021 static inline unsigned int 1039 static inline unsigned int
1022 lto_tree_ref_encoder_size (struct lto_tree_ref_encoder *encoder) 1040 lto_tree_ref_encoder_size (struct lto_tree_ref_encoder *encoder)
1023 { 1041 {
1024 return VEC_length (tree, encoder->trees); 1042 return encoder->trees.length ();
1025 } 1043 }
1026 1044
1027 /* Return the IDX-th tree in ENCODER. */ 1045 /* Return the IDX-th tree in ENCODER. */
1028 static inline tree 1046 static inline tree
1029 lto_tree_ref_encoder_get_tree (struct lto_tree_ref_encoder *encoder, 1047 lto_tree_ref_encoder_get_tree (struct lto_tree_ref_encoder *encoder,
1030 unsigned int idx) 1048 unsigned int idx)
1031 { 1049 {
1032 return VEC_index (tree, encoder->trees, idx); 1050 return encoder->trees[idx];
1033 } 1051 }
1034 1052
1035 1053 /* Return number of encoded nodes in ENCODER. */
1036 /* Return true if LABEL should be emitted in the global context. */ 1054 static inline int
1055 lto_symtab_encoder_size (lto_symtab_encoder_t encoder)
1056 {
1057 return encoder->nodes.length ();
1058 }
1059
1060 /* Value used to represent failure of lto_symtab_encoder_lookup. */
1061 #define LCC_NOT_FOUND (-1)
1062
1063 /* Look up NODE in encoder. Return NODE's reference if it has been encoded
1064 or LCC_NOT_FOUND if it is not there. */
1065
1066 static inline int
1067 lto_symtab_encoder_lookup (lto_symtab_encoder_t encoder,
1068 symtab_node *node)
1069 {
1070 size_t *slot = encoder->map->get (node);
1071 return (slot && *slot ? *(slot) - 1 : LCC_NOT_FOUND);
1072 }
1073
1074 /* Return true if iterator LSE points to nothing. */
1037 static inline bool 1075 static inline bool
1038 emit_label_in_global_context_p (tree label) 1076 lsei_end_p (lto_symtab_encoder_iterator lsei)
1039 { 1077 {
1040 return DECL_NONLOCAL (label) || FORCED_LABEL (label); 1078 return lsei.index >= (unsigned)lto_symtab_encoder_size (lsei.encoder);
1041 } 1079 }
1042 1080
1043 /* Return true if tree node EXPR should be streamed as a builtin. For 1081 /* Advance iterator LSE. */
1044 these nodes, we just emit the class and function code. */ 1082 static inline void
1045 static inline bool 1083 lsei_next (lto_symtab_encoder_iterator *lsei)
1046 lto_stream_as_builtin_p (tree expr) 1084 {
1047 { 1085 lsei->index++;
1048 return (TREE_CODE (expr) == FUNCTION_DECL 1086 }
1049 && DECL_IS_BUILTIN (expr) 1087
1050 && (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_NORMAL 1088 /* Return the node pointed to by LSI. */
1051 || DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD)); 1089 static inline symtab_node *
1052 } 1090 lsei_node (lto_symtab_encoder_iterator lsei)
1053 1091 {
1054 /* Return true if EXPR is a tree node that can be written to disk. */ 1092 return lsei.encoder->nodes[lsei.index].node;
1055 static inline bool 1093 }
1056 lto_is_streamable (tree expr) 1094
1057 { 1095 /* Return the node pointed to by LSI. */
1058 enum tree_code code = TREE_CODE (expr); 1096 static inline struct cgraph_node *
1059 1097 lsei_cgraph_node (lto_symtab_encoder_iterator lsei)
1060 /* Notice that we reject SSA_NAMEs as well. We only emit the SSA 1098 {
1061 name version in lto_output_tree_ref (see output_ssa_names). */ 1099 return dyn_cast<cgraph_node *> (lsei.encoder->nodes[lsei.index].node);
1062 return !is_lang_specific (expr) 1100 }
1063 && code != SSA_NAME 1101
1064 && code != CALL_EXPR 1102 /* Return the node pointed to by LSI. */
1065 && code != LANG_TYPE 1103 static inline varpool_node *
1066 && code != MODIFY_EXPR 1104 lsei_varpool_node (lto_symtab_encoder_iterator lsei)
1067 && code != INIT_EXPR 1105 {
1068 && code != TARGET_EXPR 1106 return dyn_cast<varpool_node *> (lsei.encoder->nodes[lsei.index].node);
1069 && code != BIND_EXPR 1107 }
1070 && code != WITH_CLEANUP_EXPR 1108
1071 && code != STATEMENT_LIST 1109 /* Return the cgraph node corresponding to REF using ENCODER. */
1072 && (code == CASE_LABEL_EXPR 1110
1073 || code == DECL_EXPR 1111 static inline symtab_node *
1074 || TREE_CODE_CLASS (code) != tcc_statement); 1112 lto_symtab_encoder_deref (lto_symtab_encoder_t encoder, int ref)
1113 {
1114 if (ref == LCC_NOT_FOUND)
1115 return NULL;
1116
1117 return encoder->nodes[ref].node;
1118 }
1119
1120 /* Return an iterator to the first node in LSI. */
1121 static inline lto_symtab_encoder_iterator
1122 lsei_start (lto_symtab_encoder_t encoder)
1123 {
1124 lto_symtab_encoder_iterator lsei;
1125
1126 lsei.encoder = encoder;
1127 lsei.index = 0;
1128 return lsei;
1129 }
1130
1131 /* Advance iterator LSE. */
1132 static inline void
1133 lsei_next_in_partition (lto_symtab_encoder_iterator *lsei)
1134 {
1135 lsei_next (lsei);
1136 while (!lsei_end_p (*lsei)
1137 && !lto_symtab_encoder_in_partition_p (lsei->encoder, lsei_node (*lsei)))
1138 lsei_next (lsei);
1139 }
1140
1141 /* Return an iterator to the first node in LSI. */
1142 static inline lto_symtab_encoder_iterator
1143 lsei_start_in_partition (lto_symtab_encoder_t encoder)
1144 {
1145 lto_symtab_encoder_iterator lsei = lsei_start (encoder);
1146
1147 if (lsei_end_p (lsei))
1148 return lsei;
1149 if (!lto_symtab_encoder_in_partition_p (encoder, lsei_node (lsei)))
1150 lsei_next_in_partition (&lsei);
1151
1152 return lsei;
1153 }
1154
1155 /* Advance iterator LSE. */
1156 static inline void
1157 lsei_next_function_in_partition (lto_symtab_encoder_iterator *lsei)
1158 {
1159 lsei_next (lsei);
1160 while (!lsei_end_p (*lsei)
1161 && (!is_a <cgraph_node *> (lsei_node (*lsei))
1162 || !lto_symtab_encoder_in_partition_p (lsei->encoder, lsei_node (*lsei))))
1163 lsei_next (lsei);
1164 }
1165
1166 /* Return an iterator to the first node in LSI. */
1167 static inline lto_symtab_encoder_iterator
1168 lsei_start_function_in_partition (lto_symtab_encoder_t encoder)
1169 {
1170 lto_symtab_encoder_iterator lsei = lsei_start (encoder);
1171
1172 if (lsei_end_p (lsei))
1173 return lsei;
1174 if (!is_a <cgraph_node *> (lsei_node (lsei))
1175 || !lto_symtab_encoder_in_partition_p (encoder, lsei_node (lsei)))
1176 lsei_next_function_in_partition (&lsei);
1177
1178 return lsei;
1179 }
1180
1181 /* Advance iterator LSE. */
1182 static inline void
1183 lsei_next_variable_in_partition (lto_symtab_encoder_iterator *lsei)
1184 {
1185 lsei_next (lsei);
1186 while (!lsei_end_p (*lsei)
1187 && (!is_a <varpool_node *> (lsei_node (*lsei))
1188 || !lto_symtab_encoder_in_partition_p (lsei->encoder, lsei_node (*lsei))))
1189 lsei_next (lsei);
1190 }
1191
1192 /* Return an iterator to the first node in LSI. */
1193 static inline lto_symtab_encoder_iterator
1194 lsei_start_variable_in_partition (lto_symtab_encoder_t encoder)
1195 {
1196 lto_symtab_encoder_iterator lsei = lsei_start (encoder);
1197
1198 if (lsei_end_p (lsei))
1199 return lsei;
1200 if (!is_a <varpool_node *> (lsei_node (lsei))
1201 || !lto_symtab_encoder_in_partition_p (encoder, lsei_node (lsei)))
1202 lsei_next_variable_in_partition (&lsei);
1203
1204 return lsei;
1075 } 1205 }
1076 1206
1077 DEFINE_DECL_STREAM_FUNCS (TYPE, type) 1207 DEFINE_DECL_STREAM_FUNCS (TYPE, type)
1078 DEFINE_DECL_STREAM_FUNCS (FIELD_DECL, field_decl) 1208 DEFINE_DECL_STREAM_FUNCS (FIELD_DECL, field_decl)
1079 DEFINE_DECL_STREAM_FUNCS (FN_DECL, fn_decl) 1209 DEFINE_DECL_STREAM_FUNCS (FN_DECL, fn_decl)
1080 DEFINE_DECL_STREAM_FUNCS (VAR_DECL, var_decl) 1210 DEFINE_DECL_STREAM_FUNCS (VAR_DECL, var_decl)
1081 DEFINE_DECL_STREAM_FUNCS (TYPE_DECL, type_decl) 1211 DEFINE_DECL_STREAM_FUNCS (TYPE_DECL, type_decl)
1082 DEFINE_DECL_STREAM_FUNCS (NAMESPACE_DECL, namespace_decl) 1212 DEFINE_DECL_STREAM_FUNCS (NAMESPACE_DECL, namespace_decl)
1083 DEFINE_DECL_STREAM_FUNCS (LABEL_DECL, label_decl) 1213 DEFINE_DECL_STREAM_FUNCS (LABEL_DECL, label_decl)
1084 1214
1085 /* Returns a new bit-packing context for bit-packing into S. */ 1215 /* Entry for the delayed registering of decl -> DIE references. */
1086 static inline struct bitpack_d 1216 struct dref_entry {
1087 bitpack_create (struct lto_output_stream *s) 1217 tree decl;
1088 { 1218 const char *sym;
1089 struct bitpack_d bp; 1219 unsigned HOST_WIDE_INT off;
1090 bp.pos = 0; 1220 };
1091 bp.word = 0; 1221
1092 bp.stream = (void *)s; 1222 extern vec<dref_entry> dref_queue;
1093 return bp; 1223
1094 }
1095
1096 /* Pack the NBITS bit sized value VAL into the bit-packing context BP. */
1097 static inline void
1098 bp_pack_value (struct bitpack_d *bp, bitpack_word_t val, unsigned nbits)
1099 {
1100 bitpack_word_t word = bp->word;
1101 int pos = bp->pos;
1102 /* If val does not fit into the current bitpack word switch to the
1103 next one. */
1104 if (pos + nbits > BITS_PER_BITPACK_WORD)
1105 {
1106 lto_output_uleb128_stream ((struct lto_output_stream *) bp->stream, word);
1107 word = val;
1108 pos = nbits;
1109 }
1110 else
1111 {
1112 word |= val << pos;
1113 pos += nbits;
1114 }
1115 bp->word = word;
1116 bp->pos = pos;
1117 }
1118
1119 /* Finishes bit-packing of BP. */
1120 static inline void
1121 lto_output_bitpack (struct bitpack_d *bp)
1122 {
1123 lto_output_uleb128_stream ((struct lto_output_stream *) bp->stream,
1124 bp->word);
1125 bp->word = 0;
1126 bp->pos = 0;
1127 }
1128
1129 /* Returns a new bit-packing context for bit-unpacking from IB. */
1130 static inline struct bitpack_d
1131 lto_input_bitpack (struct lto_input_block *ib)
1132 {
1133 struct bitpack_d bp;
1134 bp.word = lto_input_uleb128 (ib);
1135 bp.pos = 0;
1136 bp.stream = (void *)ib;
1137 return bp;
1138 }
1139
1140 /* Unpacks NBITS bits from the bit-packing context BP and returns them. */
1141 static inline bitpack_word_t
1142 bp_unpack_value (struct bitpack_d *bp, unsigned nbits)
1143 {
1144 bitpack_word_t mask, val;
1145 int pos = bp->pos;
1146
1147 mask = (nbits == BITS_PER_BITPACK_WORD
1148 ? (bitpack_word_t) -1
1149 : ((bitpack_word_t) 1 << nbits) - 1);
1150
1151 /* If there are not continuous nbits in the current bitpack word
1152 switch to the next one. */
1153 if (pos + nbits > BITS_PER_BITPACK_WORD)
1154 {
1155 bp->word = val = lto_input_uleb128 ((struct lto_input_block *)bp->stream);
1156 bp->pos = nbits;
1157 return val & mask;
1158 }
1159 val = bp->word;
1160 val >>= pos;
1161 bp->pos = pos + nbits;
1162
1163 return val & mask;
1164 }
1165 1224
1166 #endif /* GCC_LTO_STREAMER_H */ 1225 #endif /* GCC_LTO_STREAMER_H */