Remove deprecated DW_FORM_sig8 define.
[official-gcc.git] / gcc / lto-streamer-in.c
blob383bfc230600e4c2c466bb1a44777eca0526d3c3
1 /* Read the GIMPLE representation from a file stream.
3 Copyright 2009, 2010 Free Software Foundation, Inc.
4 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
5 Re-implemented by Diego Novillo <dnovillo@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 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "toplev.h"
28 #include "tree.h"
29 #include "expr.h"
30 #include "flags.h"
31 #include "params.h"
32 #include "input.h"
33 #include "hashtab.h"
34 #include "basic-block.h"
35 #include "tree-flow.h"
36 #include "tree-pass.h"
37 #include "cgraph.h"
38 #include "function.h"
39 #include "ggc.h"
40 #include "diagnostic.h"
41 #include "libfuncs.h"
42 #include "except.h"
43 #include "debug.h"
44 #include "vec.h"
45 #include "timevar.h"
46 #include "output.h"
47 #include "ipa-utils.h"
48 #include "lto-streamer.h"
49 #include "tree-pass.h"
51 /* Data structure used to hash file names in the source_location field. */
52 struct string_slot
54 const char *s;
55 unsigned int slot_num;
58 /* The table to hold the file names. */
59 static htab_t file_name_hash_table;
62 /* Check that tag ACTUAL has one of the given values. NUM_TAGS is the
63 number of valid tag values to check. */
65 static void
66 lto_tag_check_set (enum LTO_tags actual, int ntags, ...)
68 va_list ap;
69 int i;
71 va_start (ap, ntags);
72 for (i = 0; i < ntags; i++)
73 if ((unsigned) actual == va_arg (ap, unsigned))
75 va_end (ap);
76 return;
79 va_end (ap);
80 internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual));
84 /* Check that tag ACTUAL is in the range [TAG1, TAG2]. */
86 static void
87 lto_tag_check_range (enum LTO_tags actual, enum LTO_tags tag1,
88 enum LTO_tags tag2)
90 if (actual < tag1 || actual > tag2)
91 internal_error ("bytecode stream: tag %s is not in the expected range "
92 "[%s, %s]",
93 lto_tag_name (actual),
94 lto_tag_name (tag1),
95 lto_tag_name (tag2));
99 /* Check that tag ACTUAL == EXPECTED. */
101 static void
102 lto_tag_check (enum LTO_tags actual, enum LTO_tags expected)
104 if (actual != expected)
105 internal_error ("bytecode stream: expected tag %s instead of %s",
106 lto_tag_name (expected), lto_tag_name (actual));
110 /* Return a hash code for P. */
112 static hashval_t
113 hash_string_slot_node (const void *p)
115 const struct string_slot *ds = (const struct string_slot *) p;
116 return (hashval_t) htab_hash_string (ds->s);
120 /* Returns nonzero if P1 and P2 are equal. */
122 static int
123 eq_string_slot_node (const void *p1, const void *p2)
125 const struct string_slot *ds1 = (const struct string_slot *) p1;
126 const struct string_slot *ds2 = (const struct string_slot *) p2;
127 return strcmp (ds1->s, ds2->s) == 0;
131 /* Read a string from the string table in DATA_IN using input block
132 IB. Write the length to RLEN. */
134 static const char *
135 input_string_internal (struct data_in *data_in, struct lto_input_block *ib,
136 unsigned int *rlen)
138 struct lto_input_block str_tab;
139 unsigned int len;
140 unsigned int loc;
141 const char *result;
143 /* Read the location of the string from IB. */
144 loc = lto_input_uleb128 (ib);
146 /* Get the string stored at location LOC in DATA_IN->STRINGS. */
147 LTO_INIT_INPUT_BLOCK (str_tab, data_in->strings, loc, data_in->strings_len);
148 len = lto_input_uleb128 (&str_tab);
149 *rlen = len;
151 if (str_tab.p + len > data_in->strings_len)
152 internal_error ("bytecode stream: string too long for the string table");
154 result = (const char *)(data_in->strings + str_tab.p);
156 return result;
160 /* Read a STRING_CST from the string table in DATA_IN using input
161 block IB. */
163 static tree
164 input_string_cst (struct data_in *data_in, struct lto_input_block *ib)
166 unsigned int len;
167 const char * ptr;
168 unsigned int is_null;
170 is_null = lto_input_uleb128 (ib);
171 if (is_null)
172 return NULL;
174 ptr = input_string_internal (data_in, ib, &len);
175 return build_string (len, ptr);
179 /* Read an IDENTIFIER from the string table in DATA_IN using input
180 block IB. */
182 static tree
183 input_identifier (struct data_in *data_in, struct lto_input_block *ib)
185 unsigned int len;
186 const char *ptr;
187 unsigned int is_null;
189 is_null = lto_input_uleb128 (ib);
190 if (is_null)
191 return NULL;
193 ptr = input_string_internal (data_in, ib, &len);
194 return get_identifier_with_length (ptr, len);
198 /* Read LENGTH bytes from STREAM to ADDR. */
200 void
201 lto_input_data_block (struct lto_input_block *ib, void *addr, size_t length)
203 size_t i;
204 unsigned char *const buffer = (unsigned char *const) addr;
206 for (i = 0; i < length; i++)
207 buffer[i] = lto_input_1_unsigned (ib);
211 /* Read a NULL terminated string from the string table in DATA_IN. */
213 const char *
214 lto_input_string (struct data_in *data_in, struct lto_input_block *ib)
216 unsigned int len;
217 const char *ptr;
218 unsigned int is_null;
220 is_null = lto_input_uleb128 (ib);
221 if (is_null)
222 return NULL;
224 ptr = input_string_internal (data_in, ib, &len);
225 if (ptr[len - 1] != '\0')
226 internal_error ("bytecode stream: found non-null terminated string");
228 return ptr;
232 /* Return the next tag in the input block IB. */
234 static enum LTO_tags
235 input_record_start (struct lto_input_block *ib)
237 enum LTO_tags tag = (enum LTO_tags) lto_input_uleb128 (ib);
238 return tag;
242 /* Lookup STRING in file_name_hash_table. If found, return the existing
243 string, otherwise insert STRING as the canonical version. */
245 static const char *
246 canon_file_name (const char *string)
248 void **slot;
249 struct string_slot s_slot;
250 s_slot.s = string;
252 slot = htab_find_slot (file_name_hash_table, &s_slot, INSERT);
253 if (*slot == NULL)
255 size_t len;
256 char *saved_string;
257 struct string_slot *new_slot;
259 len = strlen (string);
260 saved_string = (char *) xmalloc (len + 1);
261 new_slot = XCNEW (struct string_slot);
262 strcpy (saved_string, string);
263 new_slot->s = saved_string;
264 *slot = new_slot;
265 return saved_string;
267 else
269 struct string_slot *old_slot = (struct string_slot *) *slot;
270 return old_slot->s;
275 /* Clear the line info stored in DATA_IN. */
277 static void
278 clear_line_info (struct data_in *data_in)
280 if (data_in->current_file)
281 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
282 data_in->current_file = NULL;
283 data_in->current_line = 0;
284 data_in->current_col = 0;
288 /* Read a location from input block IB. */
290 static location_t
291 lto_input_location (struct lto_input_block *ib, struct data_in *data_in)
293 expanded_location xloc;
295 xloc.file = lto_input_string (data_in, ib);
296 if (xloc.file == NULL)
297 return UNKNOWN_LOCATION;
299 xloc.file = canon_file_name (xloc.file);
300 xloc.line = lto_input_sleb128 (ib);
301 xloc.column = lto_input_sleb128 (ib);
302 xloc.sysp = lto_input_sleb128 (ib);
304 if (data_in->current_file != xloc.file)
306 if (data_in->current_file)
307 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
309 linemap_add (line_table, LC_ENTER, xloc.sysp, xloc.file, xloc.line);
311 else if (data_in->current_line != xloc.line)
312 linemap_line_start (line_table, xloc.line, xloc.column);
314 data_in->current_file = xloc.file;
315 data_in->current_line = xloc.line;
316 data_in->current_col = xloc.column;
318 return linemap_position_for_column (line_table, xloc.column);
322 /* Read a reference to a tree node from DATA_IN using input block IB.
323 TAG is the expected node that should be found in IB, if TAG belongs
324 to one of the indexable trees, expect to read a reference index to
325 be looked up in one of the symbol tables, otherwise read the pysical
326 representation of the tree using lto_input_tree. FN is the
327 function scope for the read tree. */
329 static tree
330 lto_input_tree_ref (struct lto_input_block *ib, struct data_in *data_in,
331 struct function *fn, enum LTO_tags tag)
333 unsigned HOST_WIDE_INT ix_u;
334 tree result = NULL_TREE;
336 lto_tag_check_range (tag, LTO_field_decl_ref, LTO_global_decl_ref);
338 switch (tag)
340 case LTO_type_ref:
341 ix_u = lto_input_uleb128 (ib);
342 result = lto_file_decl_data_get_type (data_in->file_data, ix_u);
343 break;
345 case LTO_ssa_name_ref:
346 ix_u = lto_input_uleb128 (ib);
347 result = VEC_index (tree, SSANAMES (fn), ix_u);
348 break;
350 case LTO_field_decl_ref:
351 ix_u = lto_input_uleb128 (ib);
352 result = lto_file_decl_data_get_field_decl (data_in->file_data, ix_u);
353 break;
355 case LTO_function_decl_ref:
356 ix_u = lto_input_uleb128 (ib);
357 result = lto_file_decl_data_get_fn_decl (data_in->file_data, ix_u);
358 break;
360 case LTO_type_decl_ref:
361 ix_u = lto_input_uleb128 (ib);
362 result = lto_file_decl_data_get_type_decl (data_in->file_data, ix_u);
363 break;
365 case LTO_namespace_decl_ref:
366 ix_u = lto_input_uleb128 (ib);
367 result = lto_file_decl_data_get_namespace_decl (data_in->file_data, ix_u);
368 break;
370 case LTO_global_decl_ref:
371 case LTO_result_decl_ref:
372 case LTO_const_decl_ref:
373 case LTO_imported_decl_ref:
374 case LTO_label_decl_ref:
375 case LTO_translation_unit_decl_ref:
376 ix_u = lto_input_uleb128 (ib);
377 result = lto_file_decl_data_get_var_decl (data_in->file_data, ix_u);
378 break;
380 default:
381 gcc_unreachable ();
384 gcc_assert (result);
386 return result;
390 /* Read and return a double-linked list of catch handlers from input
391 block IB, using descriptors in DATA_IN. */
393 static struct eh_catch_d *
394 lto_input_eh_catch_list (struct lto_input_block *ib, struct data_in *data_in,
395 eh_catch *last_p)
397 eh_catch first;
398 enum LTO_tags tag;
400 *last_p = first = NULL;
401 tag = input_record_start (ib);
402 while (tag)
404 tree list;
405 eh_catch n;
407 lto_tag_check_range (tag, LTO_eh_catch, LTO_eh_catch);
409 /* Read the catch node. */
410 n = ggc_alloc_cleared_eh_catch_d ();
411 n->type_list = lto_input_tree (ib, data_in);
412 n->filter_list = lto_input_tree (ib, data_in);
413 n->label = lto_input_tree (ib, data_in);
415 /* Register all the types in N->FILTER_LIST. */
416 for (list = n->filter_list; list; list = TREE_CHAIN (list))
417 add_type_for_runtime (TREE_VALUE (list));
419 /* Chain N to the end of the list. */
420 if (*last_p)
421 (*last_p)->next_catch = n;
422 n->prev_catch = *last_p;
423 *last_p = n;
425 /* Set the head of the list the first time through the loop. */
426 if (first == NULL)
427 first = n;
429 tag = input_record_start (ib);
432 return first;
436 /* Read and return EH region IX from input block IB, using descriptors
437 in DATA_IN. */
439 static eh_region
440 input_eh_region (struct lto_input_block *ib, struct data_in *data_in, int ix)
442 enum LTO_tags tag;
443 eh_region r;
445 /* Read the region header. */
446 tag = input_record_start (ib);
447 if (tag == LTO_null)
448 return NULL;
450 r = ggc_alloc_cleared_eh_region_d ();
451 r->index = lto_input_sleb128 (ib);
453 gcc_assert (r->index == ix);
455 /* Read all the region pointers as region numbers. We'll fix up
456 the pointers once the whole array has been read. */
457 r->outer = (eh_region) (intptr_t) lto_input_sleb128 (ib);
458 r->inner = (eh_region) (intptr_t) lto_input_sleb128 (ib);
459 r->next_peer = (eh_region) (intptr_t) lto_input_sleb128 (ib);
461 switch (tag)
463 case LTO_ert_cleanup:
464 r->type = ERT_CLEANUP;
465 break;
467 case LTO_ert_try:
469 struct eh_catch_d *last_catch;
470 r->type = ERT_TRY;
471 r->u.eh_try.first_catch = lto_input_eh_catch_list (ib, data_in,
472 &last_catch);
473 r->u.eh_try.last_catch = last_catch;
474 break;
477 case LTO_ert_allowed_exceptions:
479 tree l;
481 r->type = ERT_ALLOWED_EXCEPTIONS;
482 r->u.allowed.type_list = lto_input_tree (ib, data_in);
483 r->u.allowed.label = lto_input_tree (ib, data_in);
484 r->u.allowed.filter = lto_input_uleb128 (ib);
486 for (l = r->u.allowed.type_list; l ; l = TREE_CHAIN (l))
487 add_type_for_runtime (TREE_VALUE (l));
489 break;
491 case LTO_ert_must_not_throw:
492 r->type = ERT_MUST_NOT_THROW;
493 r->u.must_not_throw.failure_decl = lto_input_tree (ib, data_in);
494 r->u.must_not_throw.failure_loc = lto_input_location (ib, data_in);
495 break;
497 default:
498 gcc_unreachable ();
501 r->landing_pads = (eh_landing_pad) (intptr_t) lto_input_sleb128 (ib);
503 return r;
507 /* Read and return EH landing pad IX from input block IB, using descriptors
508 in DATA_IN. */
510 static eh_landing_pad
511 input_eh_lp (struct lto_input_block *ib, struct data_in *data_in, int ix)
513 enum LTO_tags tag;
514 eh_landing_pad lp;
516 /* Read the landing pad header. */
517 tag = input_record_start (ib);
518 if (tag == LTO_null)
519 return NULL;
521 lto_tag_check_range (tag, LTO_eh_landing_pad, LTO_eh_landing_pad);
523 lp = ggc_alloc_cleared_eh_landing_pad_d ();
524 lp->index = lto_input_sleb128 (ib);
525 gcc_assert (lp->index == ix);
526 lp->next_lp = (eh_landing_pad) (intptr_t) lto_input_sleb128 (ib);
527 lp->region = (eh_region) (intptr_t) lto_input_sleb128 (ib);
528 lp->post_landing_pad = lto_input_tree (ib, data_in);
530 return lp;
534 /* After reading the EH regions, pointers to peer and children regions
535 are region numbers. This converts all these region numbers into
536 real pointers into the rematerialized regions for FN. ROOT_REGION
537 is the region number for the root EH region in FN. */
539 static void
540 fixup_eh_region_pointers (struct function *fn, HOST_WIDE_INT root_region)
542 unsigned i;
543 VEC(eh_region,gc) *eh_array = fn->eh->region_array;
544 VEC(eh_landing_pad,gc) *lp_array = fn->eh->lp_array;
545 eh_region r;
546 eh_landing_pad lp;
548 gcc_assert (eh_array && lp_array);
550 gcc_assert (root_region >= 0);
551 fn->eh->region_tree = VEC_index (eh_region, eh_array, root_region);
553 #define FIXUP_EH_REGION(r) (r) = VEC_index (eh_region, eh_array, \
554 (HOST_WIDE_INT) (intptr_t) (r))
555 #define FIXUP_EH_LP(p) (p) = VEC_index (eh_landing_pad, lp_array, \
556 (HOST_WIDE_INT) (intptr_t) (p))
558 /* Convert all the index numbers stored in pointer fields into
559 pointers to the corresponding slots in the EH region array. */
560 FOR_EACH_VEC_ELT (eh_region, eh_array, i, r)
562 /* The array may contain NULL regions. */
563 if (r == NULL)
564 continue;
566 gcc_assert (i == (unsigned) r->index);
567 FIXUP_EH_REGION (r->outer);
568 FIXUP_EH_REGION (r->inner);
569 FIXUP_EH_REGION (r->next_peer);
570 FIXUP_EH_LP (r->landing_pads);
573 /* Convert all the index numbers stored in pointer fields into
574 pointers to the corresponding slots in the EH landing pad array. */
575 FOR_EACH_VEC_ELT (eh_landing_pad, lp_array, i, lp)
577 /* The array may contain NULL landing pads. */
578 if (lp == NULL)
579 continue;
581 gcc_assert (i == (unsigned) lp->index);
582 FIXUP_EH_LP (lp->next_lp);
583 FIXUP_EH_REGION (lp->region);
586 #undef FIXUP_EH_REGION
587 #undef FIXUP_EH_LP
591 /* Initialize EH support. */
593 static void
594 lto_init_eh (void)
596 static bool eh_initialized_p = false;
598 if (eh_initialized_p)
599 return;
601 /* Contrary to most other FEs, we only initialize EH support when at
602 least one of the files in the set contains exception regions in
603 it. Since this happens much later than the call to init_eh in
604 lang_dependent_init, we have to set flag_exceptions and call
605 init_eh again to initialize the EH tables. */
606 flag_exceptions = 1;
607 init_eh ();
609 /* Initialize dwarf2 tables. Since dwarf2out_do_frame() returns
610 true only when exceptions are enabled, this initialization is
611 never done during lang_dependent_init. */
612 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
613 if (dwarf2out_do_frame ())
614 dwarf2out_frame_init ();
615 #endif
617 eh_initialized_p = true;
621 /* Read the exception table for FN from IB using the data descriptors
622 in DATA_IN. */
624 static void
625 input_eh_regions (struct lto_input_block *ib, struct data_in *data_in,
626 struct function *fn)
628 HOST_WIDE_INT i, root_region, len;
629 enum LTO_tags tag;
631 tag = input_record_start (ib);
632 if (tag == LTO_null)
633 return;
635 lto_tag_check_range (tag, LTO_eh_table, LTO_eh_table);
637 /* If the file contains EH regions, then it was compiled with
638 -fexceptions. In that case, initialize the backend EH
639 machinery. */
640 lto_init_eh ();
642 gcc_assert (fn->eh);
644 root_region = lto_input_sleb128 (ib);
645 gcc_assert (root_region == (int) root_region);
647 /* Read the EH region array. */
648 len = lto_input_sleb128 (ib);
649 gcc_assert (len == (int) len);
650 if (len > 0)
652 VEC_safe_grow (eh_region, gc, fn->eh->region_array, len);
653 for (i = 0; i < len; i++)
655 eh_region r = input_eh_region (ib, data_in, i);
656 VEC_replace (eh_region, fn->eh->region_array, i, r);
660 /* Read the landing pads. */
661 len = lto_input_sleb128 (ib);
662 gcc_assert (len == (int) len);
663 if (len > 0)
665 VEC_safe_grow (eh_landing_pad, gc, fn->eh->lp_array, len);
666 for (i = 0; i < len; i++)
668 eh_landing_pad lp = input_eh_lp (ib, data_in, i);
669 VEC_replace (eh_landing_pad, fn->eh->lp_array, i, lp);
673 /* Read the runtime type data. */
674 len = lto_input_sleb128 (ib);
675 gcc_assert (len == (int) len);
676 if (len > 0)
678 VEC_safe_grow (tree, gc, fn->eh->ttype_data, len);
679 for (i = 0; i < len; i++)
681 tree ttype = lto_input_tree (ib, data_in);
682 VEC_replace (tree, fn->eh->ttype_data, i, ttype);
686 /* Read the table of action chains. */
687 len = lto_input_sleb128 (ib);
688 gcc_assert (len == (int) len);
689 if (len > 0)
691 if (targetm.arm_eabi_unwinder)
693 VEC_safe_grow (tree, gc, fn->eh->ehspec_data.arm_eabi, len);
694 for (i = 0; i < len; i++)
696 tree t = lto_input_tree (ib, data_in);
697 VEC_replace (tree, fn->eh->ehspec_data.arm_eabi, i, t);
700 else
702 VEC_safe_grow (uchar, gc, fn->eh->ehspec_data.other, len);
703 for (i = 0; i < len; i++)
705 uchar c = lto_input_1_unsigned (ib);
706 VEC_replace (uchar, fn->eh->ehspec_data.other, i, c);
711 /* Reconstruct the EH region tree by fixing up the peer/children
712 pointers. */
713 fixup_eh_region_pointers (fn, root_region);
715 tag = input_record_start (ib);
716 lto_tag_check_range (tag, LTO_null, LTO_null);
720 /* Make a new basic block with index INDEX in function FN. */
722 static basic_block
723 make_new_block (struct function *fn, unsigned int index)
725 basic_block bb = alloc_block ();
726 bb->index = index;
727 SET_BASIC_BLOCK_FOR_FUNCTION (fn, index, bb);
728 bb->il.gimple = ggc_alloc_cleared_gimple_bb_info ();
729 n_basic_blocks_for_function (fn)++;
730 bb->flags = 0;
731 set_bb_seq (bb, gimple_seq_alloc ());
732 return bb;
736 /* Read the CFG for function FN from input block IB. */
738 static void
739 input_cfg (struct lto_input_block *ib, struct function *fn,
740 int count_materialization_scale)
742 unsigned int bb_count;
743 basic_block p_bb;
744 unsigned int i;
745 int index;
747 init_empty_tree_cfg_for_function (fn);
748 init_ssa_operands ();
750 profile_status_for_function (fn) =
751 (enum profile_status_d) lto_input_uleb128 (ib);
753 bb_count = lto_input_uleb128 (ib);
755 last_basic_block_for_function (fn) = bb_count;
756 if (bb_count > VEC_length (basic_block, basic_block_info_for_function (fn)))
757 VEC_safe_grow_cleared (basic_block, gc,
758 basic_block_info_for_function (fn), bb_count);
760 if (bb_count > VEC_length (basic_block, label_to_block_map_for_function (fn)))
761 VEC_safe_grow_cleared (basic_block, gc,
762 label_to_block_map_for_function (fn), bb_count);
764 index = lto_input_sleb128 (ib);
765 while (index != -1)
767 basic_block bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
768 unsigned int edge_count;
770 if (bb == NULL)
771 bb = make_new_block (fn, index);
773 edge_count = lto_input_uleb128 (ib);
775 /* Connect up the CFG. */
776 for (i = 0; i < edge_count; i++)
778 unsigned int dest_index;
779 unsigned int edge_flags;
780 basic_block dest;
781 int probability;
782 gcov_type count;
783 edge e;
785 dest_index = lto_input_uleb128 (ib);
786 probability = (int) lto_input_sleb128 (ib);
787 count = ((gcov_type) lto_input_sleb128 (ib) * count_materialization_scale
788 + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE;
789 edge_flags = lto_input_uleb128 (ib);
791 dest = BASIC_BLOCK_FOR_FUNCTION (fn, dest_index);
793 if (dest == NULL)
794 dest = make_new_block (fn, dest_index);
796 e = make_edge (bb, dest, edge_flags);
797 e->probability = probability;
798 e->count = count;
801 index = lto_input_sleb128 (ib);
804 p_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(fn);
805 index = lto_input_sleb128 (ib);
806 while (index != -1)
808 basic_block bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
809 bb->prev_bb = p_bb;
810 p_bb->next_bb = bb;
811 p_bb = bb;
812 index = lto_input_sleb128 (ib);
817 /* Read a PHI function for basic block BB in function FN. DATA_IN is
818 the file being read. IB is the input block to use for reading. */
820 static gimple
821 input_phi (struct lto_input_block *ib, basic_block bb, struct data_in *data_in,
822 struct function *fn)
824 unsigned HOST_WIDE_INT ix;
825 tree phi_result;
826 int i, len;
827 gimple result;
829 ix = lto_input_uleb128 (ib);
830 phi_result = VEC_index (tree, SSANAMES (fn), ix);
831 len = EDGE_COUNT (bb->preds);
832 result = create_phi_node (phi_result, bb);
833 SSA_NAME_DEF_STMT (phi_result) = result;
835 /* We have to go through a lookup process here because the preds in the
836 reconstructed graph are generally in a different order than they
837 were in the original program. */
838 for (i = 0; i < len; i++)
840 tree def = lto_input_tree (ib, data_in);
841 int src_index = lto_input_uleb128 (ib);
842 location_t arg_loc = lto_input_location (ib, data_in);
843 basic_block sbb = BASIC_BLOCK_FOR_FUNCTION (fn, src_index);
845 edge e = NULL;
846 int j;
848 for (j = 0; j < len; j++)
849 if (EDGE_PRED (bb, j)->src == sbb)
851 e = EDGE_PRED (bb, j);
852 break;
855 add_phi_arg (result, def, e, arg_loc);
858 return result;
862 /* Read the SSA names array for function FN from DATA_IN using input
863 block IB. */
865 static void
866 input_ssa_names (struct lto_input_block *ib, struct data_in *data_in,
867 struct function *fn)
869 unsigned int i, size;
871 size = lto_input_uleb128 (ib);
872 init_ssanames (fn, size);
874 i = lto_input_uleb128 (ib);
875 while (i)
877 tree ssa_name, name;
878 bool is_default_def;
880 /* Skip over the elements that had been freed. */
881 while (VEC_length (tree, SSANAMES (fn)) < i)
882 VEC_quick_push (tree, SSANAMES (fn), NULL_TREE);
884 is_default_def = (lto_input_1_unsigned (ib) != 0);
885 name = lto_input_tree (ib, data_in);
886 ssa_name = make_ssa_name_fn (fn, name, gimple_build_nop ());
888 if (is_default_def)
889 set_default_def (SSA_NAME_VAR (ssa_name), ssa_name);
891 i = lto_input_uleb128 (ib);
895 /* Read a statement with tag TAG in function FN from block IB using
896 descriptors in DATA_IN. */
898 static gimple
899 input_gimple_stmt (struct lto_input_block *ib, struct data_in *data_in,
900 struct function *fn, enum LTO_tags tag)
902 gimple stmt;
903 enum gimple_code code;
904 unsigned HOST_WIDE_INT num_ops;
905 size_t i;
906 struct bitpack_d bp;
908 code = lto_tag_to_gimple_code (tag);
910 /* Read the tuple header. */
911 bp = lto_input_bitpack (ib);
912 num_ops = bp_unpack_value (&bp, sizeof (unsigned) * 8);
913 stmt = gimple_alloc (code, num_ops);
914 stmt->gsbase.no_warning = bp_unpack_value (&bp, 1);
915 if (is_gimple_assign (stmt))
916 stmt->gsbase.nontemporal_move = bp_unpack_value (&bp, 1);
917 stmt->gsbase.has_volatile_ops = bp_unpack_value (&bp, 1);
918 stmt->gsbase.subcode = bp_unpack_value (&bp, 16);
920 /* Read location information. */
921 gimple_set_location (stmt, lto_input_location (ib, data_in));
923 /* Read lexical block reference. */
924 gimple_set_block (stmt, lto_input_tree (ib, data_in));
926 /* Read in all the operands. */
927 switch (code)
929 case GIMPLE_RESX:
930 gimple_resx_set_region (stmt, lto_input_sleb128 (ib));
931 break;
933 case GIMPLE_EH_MUST_NOT_THROW:
934 gimple_eh_must_not_throw_set_fndecl (stmt, lto_input_tree (ib, data_in));
935 break;
937 case GIMPLE_EH_DISPATCH:
938 gimple_eh_dispatch_set_region (stmt, lto_input_sleb128 (ib));
939 break;
941 case GIMPLE_ASM:
943 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
944 tree str;
945 stmt->gimple_asm.ni = lto_input_uleb128 (ib);
946 stmt->gimple_asm.no = lto_input_uleb128 (ib);
947 stmt->gimple_asm.nc = lto_input_uleb128 (ib);
948 stmt->gimple_asm.nl = lto_input_uleb128 (ib);
949 str = input_string_cst (data_in, ib);
950 stmt->gimple_asm.string = TREE_STRING_POINTER (str);
952 /* Fallthru */
954 case GIMPLE_ASSIGN:
955 case GIMPLE_CALL:
956 case GIMPLE_RETURN:
957 case GIMPLE_SWITCH:
958 case GIMPLE_LABEL:
959 case GIMPLE_COND:
960 case GIMPLE_GOTO:
961 case GIMPLE_DEBUG:
962 for (i = 0; i < num_ops; i++)
964 tree op = lto_input_tree (ib, data_in);
965 gimple_set_op (stmt, i, op);
966 if (!op)
967 continue;
969 /* Fixup FIELD_DECLs in COMPONENT_REFs, they are not handled
970 by decl merging. */
971 if (TREE_CODE (op) == ADDR_EXPR)
972 op = TREE_OPERAND (op, 0);
973 while (handled_component_p (op))
975 if (TREE_CODE (op) == COMPONENT_REF)
977 tree field, type, tem;
978 tree closest_match = NULL_TREE;
979 field = TREE_OPERAND (op, 1);
980 type = DECL_CONTEXT (field);
981 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
983 if (tem == field)
984 break;
985 if (DECL_NONADDRESSABLE_P (tem)
986 == DECL_NONADDRESSABLE_P (field)
987 && gimple_compare_field_offset (tem, field))
989 if (types_compatible_p (TREE_TYPE (tem),
990 TREE_TYPE (field)))
991 break;
992 else
993 closest_match = tem;
996 /* In case of type mismatches across units we can fail
997 to unify some types and thus not find a proper
998 field-decl here. */
999 if (tem == NULL_TREE)
1001 /* Thus, emit a ODR violation warning. */
1002 if (warning_at (gimple_location (stmt), 0,
1003 "use of type %<%E%> with two mismatching "
1004 "declarations at field %<%E%>",
1005 type, TREE_OPERAND (op, 1)))
1007 if (TYPE_FIELDS (type))
1008 inform (DECL_SOURCE_LOCATION (TYPE_FIELDS (type)),
1009 "original type declared here");
1010 inform (DECL_SOURCE_LOCATION (TREE_OPERAND (op, 1)),
1011 "field in mismatching type declared here");
1012 if (TYPE_NAME (TREE_TYPE (field))
1013 && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
1014 == TYPE_DECL))
1015 inform (DECL_SOURCE_LOCATION
1016 (TYPE_NAME (TREE_TYPE (field))),
1017 "type of field declared here");
1018 if (closest_match
1019 && TYPE_NAME (TREE_TYPE (closest_match))
1020 && (TREE_CODE (TYPE_NAME
1021 (TREE_TYPE (closest_match))) == TYPE_DECL))
1022 inform (DECL_SOURCE_LOCATION
1023 (TYPE_NAME (TREE_TYPE (closest_match))),
1024 "type of mismatching field declared here");
1026 /* And finally fixup the types. */
1027 TREE_OPERAND (op, 0)
1028 = build1 (VIEW_CONVERT_EXPR, type,
1029 TREE_OPERAND (op, 0));
1031 else
1032 TREE_OPERAND (op, 1) = tem;
1035 op = TREE_OPERAND (op, 0);
1038 break;
1040 case GIMPLE_NOP:
1041 case GIMPLE_PREDICT:
1042 break;
1044 default:
1045 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
1046 lto_tag_name (tag));
1049 /* Update the properties of symbols, SSA names and labels associated
1050 with STMT. */
1051 if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
1053 tree lhs = gimple_get_lhs (stmt);
1054 if (lhs && TREE_CODE (lhs) == SSA_NAME)
1055 SSA_NAME_DEF_STMT (lhs) = stmt;
1057 else if (code == GIMPLE_LABEL)
1058 gcc_assert (emit_label_in_global_context_p (gimple_label_label (stmt))
1059 || DECL_CONTEXT (gimple_label_label (stmt)) == fn->decl);
1060 else if (code == GIMPLE_ASM)
1062 unsigned i;
1064 for (i = 0; i < gimple_asm_noutputs (stmt); i++)
1066 tree op = TREE_VALUE (gimple_asm_output_op (stmt, i));
1067 if (TREE_CODE (op) == SSA_NAME)
1068 SSA_NAME_DEF_STMT (op) = stmt;
1072 /* Reset alias information. */
1073 if (code == GIMPLE_CALL)
1074 gimple_call_reset_alias_info (stmt);
1076 /* Mark the statement modified so its operand vectors can be filled in. */
1077 gimple_set_modified (stmt, true);
1079 return stmt;
1083 /* Read a basic block with tag TAG from DATA_IN using input block IB.
1084 FN is the function being processed. */
1086 static void
1087 input_bb (struct lto_input_block *ib, enum LTO_tags tag,
1088 struct data_in *data_in, struct function *fn,
1089 int count_materialization_scale)
1091 unsigned int index;
1092 basic_block bb;
1093 gimple_stmt_iterator bsi;
1095 /* This routine assumes that CFUN is set to FN, as it needs to call
1096 basic GIMPLE routines that use CFUN. */
1097 gcc_assert (cfun == fn);
1099 index = lto_input_uleb128 (ib);
1100 bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
1102 bb->count = (lto_input_sleb128 (ib) * count_materialization_scale
1103 + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE;
1104 bb->loop_depth = lto_input_sleb128 (ib);
1105 bb->frequency = lto_input_sleb128 (ib);
1106 bb->flags = lto_input_sleb128 (ib);
1108 /* LTO_bb1 has statements. LTO_bb0 does not. */
1109 if (tag == LTO_bb0)
1110 return;
1112 bsi = gsi_start_bb (bb);
1113 tag = input_record_start (ib);
1114 while (tag)
1116 gimple stmt = input_gimple_stmt (ib, data_in, fn, tag);
1117 if (!is_gimple_debug (stmt))
1118 find_referenced_vars_in (stmt);
1119 gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
1121 /* After the statement, expect a 0 delimiter or the EH region
1122 that the previous statement belongs to. */
1123 tag = input_record_start (ib);
1124 lto_tag_check_set (tag, 2, LTO_eh_region, LTO_null);
1126 if (tag == LTO_eh_region)
1128 HOST_WIDE_INT region = lto_input_sleb128 (ib);
1129 gcc_assert (region == (int) region);
1130 add_stmt_to_eh_lp (stmt, region);
1133 tag = input_record_start (ib);
1136 tag = input_record_start (ib);
1137 while (tag)
1139 gimple phi = input_phi (ib, bb, data_in, fn);
1140 find_referenced_vars_in (phi);
1141 tag = input_record_start (ib);
1145 /* Go through all NODE edges and fixup call_stmt pointers
1146 so they point to STMTS. */
1148 static void
1149 fixup_call_stmt_edges_1 (struct cgraph_node *node, gimple *stmts)
1151 struct cgraph_edge *cedge;
1152 for (cedge = node->callees; cedge; cedge = cedge->next_callee)
1153 cedge->call_stmt = stmts[cedge->lto_stmt_uid];
1154 for (cedge = node->indirect_calls; cedge; cedge = cedge->next_callee)
1155 cedge->call_stmt = stmts[cedge->lto_stmt_uid];
1158 /* Fixup call_stmt pointers in NODE and all clones. */
1160 static void
1161 fixup_call_stmt_edges (struct cgraph_node *orig, gimple *stmts)
1163 struct cgraph_node *node;
1165 while (orig->clone_of)
1166 orig = orig->clone_of;
1168 fixup_call_stmt_edges_1 (orig, stmts);
1169 if (orig->clones)
1170 for (node = orig->clones; node != orig;)
1172 fixup_call_stmt_edges_1 (node, stmts);
1173 if (node->clones)
1174 node = node->clones;
1175 else if (node->next_sibling_clone)
1176 node = node->next_sibling_clone;
1177 else
1179 while (node != orig && !node->next_sibling_clone)
1180 node = node->clone_of;
1181 if (node != orig)
1182 node = node->next_sibling_clone;
1187 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1189 static void
1190 input_function (tree fn_decl, struct data_in *data_in,
1191 struct lto_input_block *ib)
1193 struct function *fn;
1194 enum LTO_tags tag;
1195 gimple *stmts;
1196 basic_block bb;
1197 struct bitpack_d bp;
1198 struct cgraph_node *node;
1199 tree args, narg, oarg;
1200 int len;
1202 fn = DECL_STRUCT_FUNCTION (fn_decl);
1203 tag = input_record_start (ib);
1204 clear_line_info (data_in);
1206 gimple_register_cfg_hooks ();
1207 lto_tag_check (tag, LTO_function);
1209 /* Read all the attributes for FN. */
1210 bp = lto_input_bitpack (ib);
1211 fn->is_thunk = bp_unpack_value (&bp, 1);
1212 fn->has_local_explicit_reg_vars = bp_unpack_value (&bp, 1);
1213 fn->after_tree_profile = bp_unpack_value (&bp, 1);
1214 fn->returns_pcc_struct = bp_unpack_value (&bp, 1);
1215 fn->returns_struct = bp_unpack_value (&bp, 1);
1216 fn->can_throw_non_call_exceptions = bp_unpack_value (&bp, 1);
1217 fn->always_inline_functions_inlined = bp_unpack_value (&bp, 1);
1218 fn->after_inlining = bp_unpack_value (&bp, 1);
1219 fn->dont_save_pending_sizes_p = bp_unpack_value (&bp, 1);
1220 fn->stdarg = bp_unpack_value (&bp, 1);
1221 fn->has_nonlocal_label = bp_unpack_value (&bp, 1);
1222 fn->calls_alloca = bp_unpack_value (&bp, 1);
1223 fn->calls_setjmp = bp_unpack_value (&bp, 1);
1224 fn->va_list_fpr_size = bp_unpack_value (&bp, 8);
1225 fn->va_list_gpr_size = bp_unpack_value (&bp, 8);
1227 /* Input the function start and end loci. */
1228 fn->function_start_locus = lto_input_location (ib, data_in);
1229 fn->function_end_locus = lto_input_location (ib, data_in);
1231 /* Input the current IL state of the function. */
1232 fn->curr_properties = lto_input_uleb128 (ib);
1234 /* Read the static chain and non-local goto save area. */
1235 fn->static_chain_decl = lto_input_tree (ib, data_in);
1236 fn->nonlocal_goto_save_area = lto_input_tree (ib, data_in);
1238 /* Read all the local symbols. */
1239 len = lto_input_sleb128 (ib);
1240 if (len > 0)
1242 int i;
1243 VEC_safe_grow (tree, gc, fn->local_decls, len);
1244 for (i = 0; i < len; i++)
1246 tree t = lto_input_tree (ib, data_in);
1247 VEC_replace (tree, fn->local_decls, i, t);
1251 /* Read all function arguments. We need to re-map them here to the
1252 arguments of the merged function declaration. */
1253 args = lto_input_tree (ib, data_in);
1254 for (oarg = args, narg = DECL_ARGUMENTS (fn_decl);
1255 oarg && narg;
1256 oarg = TREE_CHAIN (oarg), narg = TREE_CHAIN (narg))
1258 int ix;
1259 bool res;
1260 res = lto_streamer_cache_lookup (data_in->reader_cache, oarg, &ix);
1261 gcc_assert (res);
1262 /* Replace the argument in the streamer cache. */
1263 lto_streamer_cache_insert_at (data_in->reader_cache, narg, ix);
1265 gcc_assert (!oarg && !narg);
1267 /* Read all the SSA names. */
1268 input_ssa_names (ib, data_in, fn);
1270 /* Read the exception handling regions in the function. */
1271 input_eh_regions (ib, data_in, fn);
1273 /* Read the tree of lexical scopes for the function. */
1274 DECL_INITIAL (fn_decl) = lto_input_tree (ib, data_in);
1275 gcc_assert (DECL_INITIAL (fn_decl));
1276 DECL_SAVED_TREE (fn_decl) = NULL_TREE;
1277 node = cgraph_node (fn_decl);
1279 /* Read all the basic blocks. */
1280 tag = input_record_start (ib);
1281 while (tag)
1283 input_bb (ib, tag, data_in, fn,
1284 node->count_materialization_scale);
1285 tag = input_record_start (ib);
1288 /* Fix up the call statements that are mentioned in the callgraph
1289 edges. */
1290 renumber_gimple_stmt_uids ();
1291 stmts = (gimple *) xcalloc (gimple_stmt_max_uid (fn), sizeof (gimple));
1292 FOR_ALL_BB (bb)
1294 gimple_stmt_iterator bsi = gsi_start_bb (bb);
1295 while (!gsi_end_p (bsi))
1297 gimple stmt = gsi_stmt (bsi);
1298 /* If we're recompiling LTO objects with debug stmts but
1299 we're not supposed to have debug stmts, remove them now.
1300 We can't remove them earlier because this would cause uid
1301 mismatches in fixups, but we can do it at this point, as
1302 long as debug stmts don't require fixups. */
1303 if (!MAY_HAVE_DEBUG_STMTS && is_gimple_debug (stmt))
1305 gimple_stmt_iterator gsi = bsi;
1306 gsi_next (&bsi);
1307 gsi_remove (&gsi, true);
1309 else
1311 gsi_next (&bsi);
1312 stmts[gimple_uid (stmt)] = stmt;
1317 /* Set the gimple body to the statement sequence in the entry
1318 basic block. FIXME lto, this is fairly hacky. The existence
1319 of a gimple body is used by the cgraph routines, but we should
1320 really use the presence of the CFG. */
1322 edge_iterator ei = ei_start (ENTRY_BLOCK_PTR->succs);
1323 gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest));
1326 fixup_call_stmt_edges (node, stmts);
1327 execute_all_ipa_stmt_fixups (node, stmts);
1329 update_ssa (TODO_update_ssa_only_virtuals);
1330 free_dominance_info (CDI_DOMINATORS);
1331 free_dominance_info (CDI_POST_DOMINATORS);
1332 free (stmts);
1336 /* Read initializer expressions for public statics. DATA_IN is the
1337 file being read. IB is the input block used for reading. */
1339 static void
1340 input_alias_pairs (struct lto_input_block *ib, struct data_in *data_in)
1342 tree var;
1344 clear_line_info (data_in);
1346 /* Skip over all the unreferenced globals. */
1348 var = lto_input_tree (ib, data_in);
1349 while (var);
1351 var = lto_input_tree (ib, data_in);
1352 while (var)
1354 const char *orig_name, *new_name;
1355 alias_pair *p;
1357 p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
1358 p->decl = var;
1359 p->target = lto_input_tree (ib, data_in);
1361 /* If the target is a static object, we may have registered a
1362 new name for it to avoid clashes between statics coming from
1363 different files. In that case, use the new name. */
1364 orig_name = IDENTIFIER_POINTER (p->target);
1365 new_name = lto_get_decl_name_mapping (data_in->file_data, orig_name);
1366 if (strcmp (orig_name, new_name) != 0)
1367 p->target = get_identifier (new_name);
1369 var = lto_input_tree (ib, data_in);
1374 /* Read the body from DATA for function FN_DECL and fill it in.
1375 FILE_DATA are the global decls and types. SECTION_TYPE is either
1376 LTO_section_function_body or LTO_section_static_initializer. If
1377 section type is LTO_section_function_body, FN must be the decl for
1378 that function. */
1380 static void
1381 lto_read_body (struct lto_file_decl_data *file_data, tree fn_decl,
1382 const char *data, enum lto_section_type section_type)
1384 const struct lto_function_header *header;
1385 struct data_in *data_in;
1386 int32_t cfg_offset;
1387 int32_t main_offset;
1388 int32_t string_offset;
1389 struct lto_input_block ib_cfg;
1390 struct lto_input_block ib_main;
1392 header = (const struct lto_function_header *) data;
1393 cfg_offset = sizeof (struct lto_function_header);
1394 main_offset = cfg_offset + header->cfg_size;
1395 string_offset = main_offset + header->main_size;
1397 LTO_INIT_INPUT_BLOCK (ib_cfg,
1398 data + cfg_offset,
1400 header->cfg_size);
1402 LTO_INIT_INPUT_BLOCK (ib_main,
1403 data + main_offset,
1405 header->main_size);
1407 data_in = lto_data_in_create (file_data, data + string_offset,
1408 header->string_size, NULL);
1410 /* Make sure the file was generated by the exact same compiler. */
1411 lto_check_version (header->lto_header.major_version,
1412 header->lto_header.minor_version);
1414 if (section_type == LTO_section_function_body)
1416 struct function *fn = DECL_STRUCT_FUNCTION (fn_decl);
1417 struct lto_in_decl_state *decl_state;
1418 struct cgraph_node *node = cgraph_node (fn_decl);
1420 push_cfun (fn);
1421 init_tree_ssa (fn);
1423 /* Use the function's decl state. */
1424 decl_state = lto_get_function_in_decl_state (file_data, fn_decl);
1425 gcc_assert (decl_state);
1426 file_data->current_decl_state = decl_state;
1428 input_cfg (&ib_cfg, fn, node->count_materialization_scale);
1430 /* Set up the struct function. */
1431 input_function (fn_decl, data_in, &ib_main);
1433 /* We should now be in SSA. */
1434 cfun->gimple_df->in_ssa_p = true;
1436 /* Restore decl state */
1437 file_data->current_decl_state = file_data->global_decl_state;
1439 pop_cfun ();
1441 else
1443 input_alias_pairs (&ib_main, data_in);
1446 clear_line_info (data_in);
1447 lto_data_in_delete (data_in);
1451 /* Read the body of FN_DECL using DATA. FILE_DATA holds the global
1452 decls and types. */
1454 void
1455 lto_input_function_body (struct lto_file_decl_data *file_data,
1456 tree fn_decl, const char *data)
1458 current_function_decl = fn_decl;
1459 lto_read_body (file_data, fn_decl, data, LTO_section_function_body);
1463 /* Read in VAR_DECL using DATA. FILE_DATA holds the global decls and
1464 types. */
1466 void
1467 lto_input_constructors_and_inits (struct lto_file_decl_data *file_data,
1468 const char *data)
1470 lto_read_body (file_data, NULL, data, LTO_section_static_initializer);
1474 /* Return the resolution for the decl with index INDEX from DATA_IN. */
1476 static enum ld_plugin_symbol_resolution
1477 get_resolution (struct data_in *data_in, unsigned index)
1479 if (data_in->globals_resolution)
1481 ld_plugin_symbol_resolution_t ret;
1482 /* We can have references to not emitted functions in
1483 DECL_FUNCTION_PERSONALITY at least. So we can and have
1484 to indeed return LDPR_UNKNOWN in some cases. */
1485 if (VEC_length (ld_plugin_symbol_resolution_t,
1486 data_in->globals_resolution) <= index)
1487 return LDPR_UNKNOWN;
1488 ret = VEC_index (ld_plugin_symbol_resolution_t,
1489 data_in->globals_resolution,
1490 index);
1491 return ret;
1493 else
1494 /* Delay resolution finding until decl merging. */
1495 return LDPR_UNKNOWN;
1499 /* Unpack all the non-pointer fields of the TS_BASE structure of
1500 expression EXPR from bitpack BP. */
1502 static void
1503 unpack_ts_base_value_fields (struct bitpack_d *bp, tree expr)
1505 /* Note that the code for EXPR has already been unpacked to create EXPR in
1506 lto_materialize_tree. */
1507 if (!TYPE_P (expr))
1509 TREE_SIDE_EFFECTS (expr) = (unsigned) bp_unpack_value (bp, 1);
1510 TREE_CONSTANT (expr) = (unsigned) bp_unpack_value (bp, 1);
1511 TREE_READONLY (expr) = (unsigned) bp_unpack_value (bp, 1);
1513 /* TREE_PUBLIC is used on types to indicate that the type
1514 has a TYPE_CACHED_VALUES vector. This is not streamed out,
1515 so we skip it here. */
1516 TREE_PUBLIC (expr) = (unsigned) bp_unpack_value (bp, 1);
1518 else
1519 bp_unpack_value (bp, 4);
1520 TREE_ADDRESSABLE (expr) = (unsigned) bp_unpack_value (bp, 1);
1521 TREE_THIS_VOLATILE (expr) = (unsigned) bp_unpack_value (bp, 1);
1522 if (DECL_P (expr))
1523 DECL_UNSIGNED (expr) = (unsigned) bp_unpack_value (bp, 1);
1524 else if (TYPE_P (expr))
1525 TYPE_UNSIGNED (expr) = (unsigned) bp_unpack_value (bp, 1);
1526 else
1527 bp_unpack_value (bp, 1);
1528 TREE_ASM_WRITTEN (expr) = (unsigned) bp_unpack_value (bp, 1);
1529 TREE_NO_WARNING (expr) = (unsigned) bp_unpack_value (bp, 1);
1530 TREE_USED (expr) = (unsigned) bp_unpack_value (bp, 1);
1531 TREE_NOTHROW (expr) = (unsigned) bp_unpack_value (bp, 1);
1532 TREE_STATIC (expr) = (unsigned) bp_unpack_value (bp, 1);
1533 TREE_PRIVATE (expr) = (unsigned) bp_unpack_value (bp, 1);
1534 TREE_PROTECTED (expr) = (unsigned) bp_unpack_value (bp, 1);
1535 TREE_DEPRECATED (expr) = (unsigned) bp_unpack_value (bp, 1);
1536 if (TYPE_P (expr))
1537 TYPE_SATURATING (expr) = (unsigned) bp_unpack_value (bp, 1);
1538 else if (TREE_CODE (expr) == SSA_NAME)
1539 SSA_NAME_IS_DEFAULT_DEF (expr) = (unsigned) bp_unpack_value (bp, 1);
1540 else
1541 bp_unpack_value (bp, 1);
1545 /* Unpack all the non-pointer fields of the TS_REAL_CST structure of
1546 expression EXPR from bitpack BP. */
1548 static void
1549 unpack_ts_real_cst_value_fields (struct bitpack_d *bp, tree expr)
1551 unsigned i;
1552 REAL_VALUE_TYPE r;
1553 REAL_VALUE_TYPE *rp;
1555 r.cl = (unsigned) bp_unpack_value (bp, 2);
1556 r.decimal = (unsigned) bp_unpack_value (bp, 1);
1557 r.sign = (unsigned) bp_unpack_value (bp, 1);
1558 r.signalling = (unsigned) bp_unpack_value (bp, 1);
1559 r.canonical = (unsigned) bp_unpack_value (bp, 1);
1560 r.uexp = (unsigned) bp_unpack_value (bp, EXP_BITS);
1561 for (i = 0; i < SIGSZ; i++)
1562 r.sig[i] = (unsigned long) bp_unpack_value (bp, HOST_BITS_PER_LONG);
1564 rp = ggc_alloc_real_value ();
1565 memcpy (rp, &r, sizeof (REAL_VALUE_TYPE));
1566 TREE_REAL_CST_PTR (expr) = rp;
1570 /* Unpack all the non-pointer fields of the TS_FIXED_CST structure of
1571 expression EXPR from bitpack BP. */
1573 static void
1574 unpack_ts_fixed_cst_value_fields (struct bitpack_d *bp, tree expr)
1576 struct fixed_value fv;
1578 fv.data.low = (HOST_WIDE_INT) bp_unpack_value (bp, HOST_BITS_PER_WIDE_INT);
1579 fv.data.high = (HOST_WIDE_INT) bp_unpack_value (bp, HOST_BITS_PER_WIDE_INT);
1580 fv.mode = (enum machine_mode) bp_unpack_value (bp, HOST_BITS_PER_INT);
1581 TREE_FIXED_CST (expr) = fv;
1585 /* Unpack all the non-pointer fields of the TS_DECL_COMMON structure
1586 of expression EXPR from bitpack BP. */
1588 static void
1589 unpack_ts_decl_common_value_fields (struct bitpack_d *bp, tree expr)
1591 DECL_MODE (expr) = (enum machine_mode) bp_unpack_value (bp, 8);
1592 DECL_NONLOCAL (expr) = (unsigned) bp_unpack_value (bp, 1);
1593 DECL_VIRTUAL_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1594 DECL_IGNORED_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1595 DECL_ABSTRACT (expr) = (unsigned) bp_unpack_value (bp, 1);
1596 DECL_ARTIFICIAL (expr) = (unsigned) bp_unpack_value (bp, 1);
1597 DECL_USER_ALIGN (expr) = (unsigned) bp_unpack_value (bp, 1);
1598 DECL_PRESERVE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1599 DECL_DEBUG_EXPR_IS_FROM (expr) = (unsigned) bp_unpack_value (bp, 1);
1600 DECL_EXTERNAL (expr) = (unsigned) bp_unpack_value (bp, 1);
1601 DECL_GIMPLE_REG_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1602 DECL_ALIGN (expr) = (unsigned) bp_unpack_value (bp, HOST_BITS_PER_INT);
1604 if (TREE_CODE (expr) == LABEL_DECL)
1606 DECL_ERROR_ISSUED (expr) = (unsigned) bp_unpack_value (bp, 1);
1607 EH_LANDING_PAD_NR (expr) = (int) bp_unpack_value (bp, HOST_BITS_PER_INT);
1609 /* Always assume an initial value of -1 for LABEL_DECL_UID to
1610 force gimple_set_bb to recreate label_to_block_map. */
1611 LABEL_DECL_UID (expr) = -1;
1614 if (TREE_CODE (expr) == FIELD_DECL)
1616 unsigned HOST_WIDE_INT off_align;
1617 DECL_PACKED (expr) = (unsigned) bp_unpack_value (bp, 1);
1618 DECL_NONADDRESSABLE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1619 off_align = (unsigned HOST_WIDE_INT) bp_unpack_value (bp, 8);
1620 SET_DECL_OFFSET_ALIGN (expr, off_align);
1623 if (TREE_CODE (expr) == RESULT_DECL
1624 || TREE_CODE (expr) == PARM_DECL
1625 || TREE_CODE (expr) == VAR_DECL)
1627 DECL_BY_REFERENCE (expr) = (unsigned) bp_unpack_value (bp, 1);
1628 if (TREE_CODE (expr) == VAR_DECL
1629 || TREE_CODE (expr) == PARM_DECL)
1630 DECL_HAS_VALUE_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1631 DECL_RESTRICTED_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1636 /* Unpack all the non-pointer fields of the TS_DECL_WRTL structure
1637 of expression EXPR from bitpack BP. */
1639 static void
1640 unpack_ts_decl_wrtl_value_fields (struct bitpack_d *bp, tree expr)
1642 DECL_REGISTER (expr) = (unsigned) bp_unpack_value (bp, 1);
1646 /* Unpack all the non-pointer fields of the TS_DECL_WITH_VIS structure
1647 of expression EXPR from bitpack BP. */
1649 static void
1650 unpack_ts_decl_with_vis_value_fields (struct bitpack_d *bp, tree expr)
1652 DECL_DEFER_OUTPUT (expr) = (unsigned) bp_unpack_value (bp, 1);
1653 DECL_COMMON (expr) = (unsigned) bp_unpack_value (bp, 1);
1654 DECL_DLLIMPORT_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1655 DECL_WEAK (expr) = (unsigned) bp_unpack_value (bp, 1);
1656 DECL_SEEN_IN_BIND_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1657 DECL_COMDAT (expr) = (unsigned) bp_unpack_value (bp, 1);
1658 DECL_VISIBILITY (expr) = (enum symbol_visibility) bp_unpack_value (bp, 2);
1659 DECL_VISIBILITY_SPECIFIED (expr) = (unsigned) bp_unpack_value (bp, 1);
1661 if (TREE_CODE (expr) == VAR_DECL)
1663 DECL_HARD_REGISTER (expr) = (unsigned) bp_unpack_value (bp, 1);
1664 DECL_IN_TEXT_SECTION (expr) = (unsigned) bp_unpack_value (bp, 1);
1665 DECL_IN_CONSTANT_POOL (expr) = (unsigned) bp_unpack_value (bp, 1);
1666 DECL_TLS_MODEL (expr) = (enum tls_model) bp_unpack_value (bp, 3);
1669 if (VAR_OR_FUNCTION_DECL_P (expr))
1671 priority_type p;
1672 p = (priority_type) bp_unpack_value (bp, HOST_BITS_PER_SHORT);
1673 SET_DECL_INIT_PRIORITY (expr, p);
1678 /* Unpack all the non-pointer fields of the TS_FUNCTION_DECL structure
1679 of expression EXPR from bitpack BP. */
1681 static void
1682 unpack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
1684 DECL_FUNCTION_CODE (expr) = (enum built_in_function) bp_unpack_value (bp, 11);
1685 DECL_BUILT_IN_CLASS (expr) = (enum built_in_class) bp_unpack_value (bp, 2);
1686 DECL_STATIC_CONSTRUCTOR (expr) = (unsigned) bp_unpack_value (bp, 1);
1687 DECL_STATIC_DESTRUCTOR (expr) = (unsigned) bp_unpack_value (bp, 1);
1688 DECL_UNINLINABLE (expr) = (unsigned) bp_unpack_value (bp, 1);
1689 DECL_POSSIBLY_INLINED (expr) = (unsigned) bp_unpack_value (bp, 1);
1690 DECL_IS_NOVOPS (expr) = (unsigned) bp_unpack_value (bp, 1);
1691 DECL_IS_RETURNS_TWICE (expr) = (unsigned) bp_unpack_value (bp, 1);
1692 DECL_IS_MALLOC (expr) = (unsigned) bp_unpack_value (bp, 1);
1693 DECL_IS_OPERATOR_NEW (expr) = (unsigned) bp_unpack_value (bp, 1);
1694 DECL_DECLARED_INLINE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1695 DECL_STATIC_CHAIN (expr) = (unsigned) bp_unpack_value (bp, 1);
1696 DECL_NO_INLINE_WARNING_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1697 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (expr)
1698 = (unsigned) bp_unpack_value (bp, 1);
1699 DECL_NO_LIMIT_STACK (expr) = (unsigned) bp_unpack_value (bp, 1);
1700 DECL_DISREGARD_INLINE_LIMITS (expr) = (unsigned) bp_unpack_value (bp, 1);
1701 DECL_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1702 DECL_LOOPING_CONST_OR_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1703 if (DECL_STATIC_DESTRUCTOR (expr))
1705 priority_type p = (priority_type) bp_unpack_value (bp, HOST_BITS_PER_SHORT);
1706 SET_DECL_FINI_PRIORITY (expr, p);
1711 /* Unpack all the non-pointer fields of the TS_TYPE structure
1712 of expression EXPR from bitpack BP. */
1714 static void
1715 unpack_ts_type_value_fields (struct bitpack_d *bp, tree expr)
1717 enum machine_mode mode;
1719 TYPE_PRECISION (expr) = (unsigned) bp_unpack_value (bp, 10);
1720 mode = (enum machine_mode) bp_unpack_value (bp, 8);
1721 SET_TYPE_MODE (expr, mode);
1722 TYPE_STRING_FLAG (expr) = (unsigned) bp_unpack_value (bp, 1);
1723 TYPE_NO_FORCE_BLK (expr) = (unsigned) bp_unpack_value (bp, 1);
1724 TYPE_NEEDS_CONSTRUCTING (expr) = (unsigned) bp_unpack_value (bp, 1);
1725 if (RECORD_OR_UNION_TYPE_P (expr))
1726 TYPE_TRANSPARENT_AGGR (expr) = (unsigned) bp_unpack_value (bp, 1);
1727 TYPE_PACKED (expr) = (unsigned) bp_unpack_value (bp, 1);
1728 TYPE_RESTRICT (expr) = (unsigned) bp_unpack_value (bp, 1);
1729 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (expr)
1730 = (unsigned) bp_unpack_value (bp, 2);
1731 TYPE_USER_ALIGN (expr) = (unsigned) bp_unpack_value (bp, 1);
1732 TYPE_READONLY (expr) = (unsigned) bp_unpack_value (bp, 1);
1733 TYPE_ALIGN (expr) = (unsigned) bp_unpack_value (bp, HOST_BITS_PER_INT);
1734 TYPE_ALIAS_SET (expr) = bp_unpack_value (bp, HOST_BITS_PER_INT);
1738 /* Unpack all the non-pointer fields of the TS_BLOCK structure
1739 of expression EXPR from bitpack BP. */
1741 static void
1742 unpack_ts_block_value_fields (struct bitpack_d *bp, tree expr)
1744 BLOCK_ABSTRACT (expr) = (unsigned) bp_unpack_value (bp, 1);
1745 BLOCK_NUMBER (expr) = (unsigned) bp_unpack_value (bp, 31);
1748 /* Unpack all the non-pointer fields of the TS_TRANSLATION_UNIT_DECL
1749 structure of expression EXPR from bitpack BP. */
1751 static void
1752 unpack_ts_translation_unit_decl_value_fields (struct bitpack_d *bp ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1756 /* Unpack all the non-pointer fields in EXPR into a bit pack. */
1758 static void
1759 unpack_value_fields (struct bitpack_d *bp, tree expr)
1761 enum tree_code code;
1763 code = TREE_CODE (expr);
1765 /* Note that all these functions are highly sensitive to changes in
1766 the types and sizes of each of the fields being packed. */
1767 unpack_ts_base_value_fields (bp, expr);
1769 if (CODE_CONTAINS_STRUCT (code, TS_REAL_CST))
1770 unpack_ts_real_cst_value_fields (bp, expr);
1772 if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST))
1773 unpack_ts_fixed_cst_value_fields (bp, expr);
1775 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1776 unpack_ts_decl_common_value_fields (bp, expr);
1778 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
1779 unpack_ts_decl_wrtl_value_fields (bp, expr);
1781 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1782 unpack_ts_decl_with_vis_value_fields (bp, expr);
1784 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1785 unpack_ts_function_decl_value_fields (bp, expr);
1787 if (CODE_CONTAINS_STRUCT (code, TS_TYPE))
1788 unpack_ts_type_value_fields (bp, expr);
1790 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
1791 unpack_ts_block_value_fields (bp, expr);
1793 if (CODE_CONTAINS_STRUCT (code, TS_SSA_NAME))
1795 /* We only stream the version number of SSA names. */
1796 gcc_unreachable ();
1799 if (CODE_CONTAINS_STRUCT (code, TS_STATEMENT_LIST))
1801 /* This is only used by GENERIC. */
1802 gcc_unreachable ();
1805 if (CODE_CONTAINS_STRUCT (code, TS_OMP_CLAUSE))
1807 /* This is only used by High GIMPLE. */
1808 gcc_unreachable ();
1811 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
1812 unpack_ts_translation_unit_decl_value_fields (bp, expr);
1816 /* Materialize a new tree from input block IB using descriptors in
1817 DATA_IN. The code for the new tree should match TAG. Store in
1818 *IX_P the index into the reader cache where the new tree is stored. */
1820 static tree
1821 lto_materialize_tree (struct lto_input_block *ib, struct data_in *data_in,
1822 enum LTO_tags tag, int *ix_p)
1824 struct bitpack_d bp;
1825 enum tree_code code;
1826 tree result;
1827 #ifdef LTO_STREAMER_DEBUG
1828 HOST_WIDEST_INT orig_address_in_writer;
1829 #endif
1830 HOST_WIDE_INT ix;
1832 result = NULL_TREE;
1834 /* Read the header of the node we are about to create. */
1835 ix = lto_input_sleb128 (ib);
1836 gcc_assert ((int) ix == ix);
1837 *ix_p = (int) ix;
1839 #ifdef LTO_STREAMER_DEBUG
1840 /* Read the word representing the memory address for the tree
1841 as it was written by the writer. This is useful when
1842 debugging differences between the writer and reader. */
1843 orig_address_in_writer = lto_input_sleb128 (ib);
1844 gcc_assert ((intptr_t) orig_address_in_writer == orig_address_in_writer);
1845 #endif
1847 code = lto_tag_to_tree_code (tag);
1849 /* We should never see an SSA_NAME tree. Only the version numbers of
1850 SSA names are ever written out. See input_ssa_names. */
1851 gcc_assert (code != SSA_NAME);
1853 /* Instantiate a new tree using the header data. */
1854 if (CODE_CONTAINS_STRUCT (code, TS_STRING))
1855 result = input_string_cst (data_in, ib);
1856 else if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
1857 result = input_identifier (data_in, ib);
1858 else if (CODE_CONTAINS_STRUCT (code, TS_VEC))
1860 HOST_WIDE_INT len = lto_input_sleb128 (ib);
1861 result = make_tree_vec (len);
1863 else if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
1865 unsigned HOST_WIDE_INT len = lto_input_uleb128 (ib);
1866 result = make_tree_binfo (len);
1868 else
1870 /* All other nodes can be materialized with a raw make_node
1871 call. */
1872 result = make_node (code);
1875 #ifdef LTO_STREAMER_DEBUG
1876 /* Store the original address of the tree as seen by the writer
1877 in RESULT's aux field. This is useful when debugging streaming
1878 problems. This way, a debugging session can be started on
1879 both writer and reader with a breakpoint using this address
1880 value in both. */
1881 lto_orig_address_map (result, (intptr_t) orig_address_in_writer);
1882 #endif
1884 /* Read the bitpack of non-pointer values from IB. */
1885 bp = lto_input_bitpack (ib);
1887 /* The first word in BP contains the code of the tree that we
1888 are about to read. */
1889 code = (enum tree_code) bp_unpack_value (&bp, 16);
1890 lto_tag_check (lto_tree_code_to_tag (code), tag);
1892 /* Unpack all the value fields from BP. */
1893 unpack_value_fields (&bp, result);
1895 /* Enter RESULT in the reader cache. This will make RESULT
1896 available so that circular references in the rest of the tree
1897 structure can be resolved in subsequent calls to lto_input_tree. */
1898 lto_streamer_cache_insert_at (data_in->reader_cache, result, ix);
1900 return result;
1904 /* Read a chain of tree nodes from input block IB. DATA_IN contains
1905 tables and descriptors for the file being read. */
1907 static tree
1908 lto_input_chain (struct lto_input_block *ib, struct data_in *data_in)
1910 int i, count;
1911 tree first, prev, curr;
1913 first = prev = NULL_TREE;
1914 count = lto_input_sleb128 (ib);
1915 for (i = 0; i < count; i++)
1917 curr = lto_input_tree (ib, data_in);
1918 if (prev)
1919 TREE_CHAIN (prev) = curr;
1920 else
1921 first = curr;
1923 TREE_CHAIN (curr) = NULL_TREE;
1924 prev = curr;
1927 return first;
1931 /* Read all pointer fields in the TS_COMMON structure of EXPR from input
1932 block IB. DATA_IN contains tables and descriptors for the
1933 file being read. */
1936 static void
1937 lto_input_ts_common_tree_pointers (struct lto_input_block *ib,
1938 struct data_in *data_in, tree expr)
1940 if (TREE_CODE (expr) != IDENTIFIER_NODE)
1941 TREE_TYPE (expr) = lto_input_tree (ib, data_in);
1945 /* Read all pointer fields in the TS_VECTOR structure of EXPR from input
1946 block IB. DATA_IN contains tables and descriptors for the
1947 file being read. */
1949 static void
1950 lto_input_ts_vector_tree_pointers (struct lto_input_block *ib,
1951 struct data_in *data_in, tree expr)
1953 TREE_VECTOR_CST_ELTS (expr) = lto_input_chain (ib, data_in);
1957 /* Read all pointer fields in the TS_COMPLEX structure of EXPR from input
1958 block IB. DATA_IN contains tables and descriptors for the
1959 file being read. */
1961 static void
1962 lto_input_ts_complex_tree_pointers (struct lto_input_block *ib,
1963 struct data_in *data_in, tree expr)
1965 TREE_REALPART (expr) = lto_input_tree (ib, data_in);
1966 TREE_IMAGPART (expr) = lto_input_tree (ib, data_in);
1970 /* Read all pointer fields in the TS_DECL_MINIMAL structure of EXPR
1971 from input block IB. DATA_IN contains tables and descriptors for the
1972 file being read. */
1974 static void
1975 lto_input_ts_decl_minimal_tree_pointers (struct lto_input_block *ib,
1976 struct data_in *data_in, tree expr)
1978 DECL_NAME (expr) = lto_input_tree (ib, data_in);
1979 DECL_CONTEXT (expr) = lto_input_tree (ib, data_in);
1980 DECL_SOURCE_LOCATION (expr) = lto_input_location (ib, data_in);
1984 /* Read all pointer fields in the TS_DECL_COMMON structure of EXPR from
1985 input block IB. DATA_IN contains tables and descriptors for the
1986 file being read. */
1988 static void
1989 lto_input_ts_decl_common_tree_pointers (struct lto_input_block *ib,
1990 struct data_in *data_in, tree expr)
1992 DECL_SIZE (expr) = lto_input_tree (ib, data_in);
1993 DECL_SIZE_UNIT (expr) = lto_input_tree (ib, data_in);
1995 if (TREE_CODE (expr) != FUNCTION_DECL
1996 && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
1997 DECL_INITIAL (expr) = lto_input_tree (ib, data_in);
1999 DECL_ATTRIBUTES (expr) = lto_input_tree (ib, data_in);
2000 /* Do not stream DECL_ABSTRACT_ORIGIN. We cannot handle debug information
2001 for early inlining so drop it on the floor instead of ICEing in
2002 dwarf2out.c. */
2004 if (TREE_CODE (expr) == PARM_DECL)
2005 TREE_CHAIN (expr) = lto_input_chain (ib, data_in);
2007 if ((TREE_CODE (expr) == VAR_DECL
2008 || TREE_CODE (expr) == PARM_DECL)
2009 && DECL_HAS_VALUE_EXPR_P (expr))
2010 SET_DECL_VALUE_EXPR (expr, lto_input_tree (ib, data_in));
2012 if (TREE_CODE (expr) == VAR_DECL)
2014 tree dexpr = lto_input_tree (ib, data_in);
2015 if (dexpr)
2016 SET_DECL_DEBUG_EXPR (expr, dexpr);
2021 /* Read all pointer fields in the TS_DECL_NON_COMMON structure of
2022 EXPR from input block IB. DATA_IN contains tables and descriptors for the
2023 file being read. */
2025 static void
2026 lto_input_ts_decl_non_common_tree_pointers (struct lto_input_block *ib,
2027 struct data_in *data_in, tree expr)
2029 if (TREE_CODE (expr) == FUNCTION_DECL)
2031 DECL_ARGUMENTS (expr) = lto_input_tree (ib, data_in);
2032 DECL_RESULT (expr) = lto_input_tree (ib, data_in);
2034 DECL_VINDEX (expr) = lto_input_tree (ib, data_in);
2038 /* Read all pointer fields in the TS_DECL_WITH_VIS structure of EXPR
2039 from input block IB. DATA_IN contains tables and descriptors for the
2040 file being read. */
2042 static void
2043 lto_input_ts_decl_with_vis_tree_pointers (struct lto_input_block *ib,
2044 struct data_in *data_in, tree expr)
2046 tree id;
2048 id = lto_input_tree (ib, data_in);
2049 if (id)
2051 gcc_assert (TREE_CODE (id) == IDENTIFIER_NODE);
2052 SET_DECL_ASSEMBLER_NAME (expr, id);
2055 DECL_SECTION_NAME (expr) = lto_input_tree (ib, data_in);
2056 DECL_COMDAT_GROUP (expr) = lto_input_tree (ib, data_in);
2060 /* Read all pointer fields in the TS_FIELD_DECL structure of EXPR from
2061 input block IB. DATA_IN contains tables and descriptors for the
2062 file being read. */
2064 static void
2065 lto_input_ts_field_decl_tree_pointers (struct lto_input_block *ib,
2066 struct data_in *data_in, tree expr)
2068 DECL_FIELD_OFFSET (expr) = lto_input_tree (ib, data_in);
2069 DECL_BIT_FIELD_TYPE (expr) = lto_input_tree (ib, data_in);
2070 DECL_QUALIFIER (expr) = lto_input_tree (ib, data_in);
2071 DECL_FIELD_BIT_OFFSET (expr) = lto_input_tree (ib, data_in);
2072 DECL_FCONTEXT (expr) = lto_input_tree (ib, data_in);
2073 TREE_CHAIN (expr) = lto_input_chain (ib, data_in);
2077 /* Read all pointer fields in the TS_FUNCTION_DECL structure of EXPR
2078 from input block IB. DATA_IN contains tables and descriptors for the
2079 file being read. */
2081 static void
2082 lto_input_ts_function_decl_tree_pointers (struct lto_input_block *ib,
2083 struct data_in *data_in, tree expr)
2085 /* DECL_STRUCT_FUNCTION is handled by lto_input_function. FIXME lto,
2086 maybe it should be handled here? */
2087 DECL_FUNCTION_PERSONALITY (expr) = lto_input_tree (ib, data_in);
2088 DECL_FUNCTION_SPECIFIC_TARGET (expr) = lto_input_tree (ib, data_in);
2089 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr) = lto_input_tree (ib, data_in);
2091 /* If the file contains a function with an EH personality set,
2092 then it was compiled with -fexceptions. In that case, initialize
2093 the backend EH machinery. */
2094 if (DECL_FUNCTION_PERSONALITY (expr))
2095 lto_init_eh ();
2099 /* Read all pointer fields in the TS_TYPE structure of EXPR from input
2100 block IB. DATA_IN contains tables and descriptors for the
2101 file being read. */
2103 static void
2104 lto_input_ts_type_tree_pointers (struct lto_input_block *ib,
2105 struct data_in *data_in, tree expr)
2107 if (TREE_CODE (expr) == ENUMERAL_TYPE)
2108 TYPE_VALUES (expr) = lto_input_tree (ib, data_in);
2109 else if (TREE_CODE (expr) == ARRAY_TYPE)
2110 TYPE_DOMAIN (expr) = lto_input_tree (ib, data_in);
2111 else if (RECORD_OR_UNION_TYPE_P (expr))
2112 TYPE_FIELDS (expr) = lto_input_tree (ib, data_in);
2113 else if (TREE_CODE (expr) == FUNCTION_TYPE
2114 || TREE_CODE (expr) == METHOD_TYPE)
2115 TYPE_ARG_TYPES (expr) = lto_input_tree (ib, data_in);
2117 TYPE_SIZE (expr) = lto_input_tree (ib, data_in);
2118 TYPE_SIZE_UNIT (expr) = lto_input_tree (ib, data_in);
2119 TYPE_ATTRIBUTES (expr) = lto_input_tree (ib, data_in);
2120 TYPE_NAME (expr) = lto_input_tree (ib, data_in);
2121 /* Do not stream TYPE_POINTER_TO or TYPE_REFERENCE_TO nor
2122 TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. */
2123 if (!POINTER_TYPE_P (expr))
2124 TYPE_MINVAL (expr) = lto_input_tree (ib, data_in);
2125 TYPE_MAXVAL (expr) = lto_input_tree (ib, data_in);
2126 TYPE_MAIN_VARIANT (expr) = lto_input_tree (ib, data_in);
2127 /* Do not stream TYPE_NEXT_VARIANT, we reconstruct the variant lists
2128 during fixup. */
2129 if (RECORD_OR_UNION_TYPE_P (expr))
2130 TYPE_BINFO (expr) = lto_input_tree (ib, data_in);
2131 TYPE_CONTEXT (expr) = lto_input_tree (ib, data_in);
2132 /* TYPE_CANONICAL gets re-computed during type merging. */
2133 TYPE_CANONICAL (expr) = NULL_TREE;
2134 TYPE_STUB_DECL (expr) = lto_input_tree (ib, data_in);
2138 /* Read all pointer fields in the TS_LIST structure of EXPR from input
2139 block IB. DATA_IN contains tables and descriptors for the
2140 file being read. */
2142 static void
2143 lto_input_ts_list_tree_pointers (struct lto_input_block *ib,
2144 struct data_in *data_in, tree expr)
2146 TREE_PURPOSE (expr) = lto_input_tree (ib, data_in);
2147 TREE_VALUE (expr) = lto_input_tree (ib, data_in);
2148 TREE_CHAIN (expr) = lto_input_chain (ib, data_in);
2152 /* Read all pointer fields in the TS_VEC structure of EXPR from input
2153 block IB. DATA_IN contains tables and descriptors for the
2154 file being read. */
2156 static void
2157 lto_input_ts_vec_tree_pointers (struct lto_input_block *ib,
2158 struct data_in *data_in, tree expr)
2160 int i;
2162 /* Note that TREE_VEC_LENGTH was read by lto_materialize_tree to
2163 instantiate EXPR. */
2164 for (i = 0; i < TREE_VEC_LENGTH (expr); i++)
2165 TREE_VEC_ELT (expr, i) = lto_input_tree (ib, data_in);
2169 /* Read all pointer fields in the TS_EXP structure of EXPR from input
2170 block IB. DATA_IN contains tables and descriptors for the
2171 file being read. */
2174 static void
2175 lto_input_ts_exp_tree_pointers (struct lto_input_block *ib,
2176 struct data_in *data_in, tree expr)
2178 int i, length;
2179 location_t loc;
2181 length = lto_input_sleb128 (ib);
2182 gcc_assert (length == TREE_OPERAND_LENGTH (expr));
2184 for (i = 0; i < length; i++)
2185 TREE_OPERAND (expr, i) = lto_input_tree (ib, data_in);
2187 loc = lto_input_location (ib, data_in);
2188 SET_EXPR_LOCATION (expr, loc);
2189 TREE_BLOCK (expr) = lto_input_tree (ib, data_in);
2193 /* Read all pointer fields in the TS_BLOCK structure of EXPR from input
2194 block IB. DATA_IN contains tables and descriptors for the
2195 file being read. */
2197 static void
2198 lto_input_ts_block_tree_pointers (struct lto_input_block *ib,
2199 struct data_in *data_in, tree expr)
2201 /* Do not stream BLOCK_SOURCE_LOCATION. We cannot handle debug information
2202 for early inlining so drop it on the floor instead of ICEing in
2203 dwarf2out.c. */
2204 BLOCK_VARS (expr) = lto_input_chain (ib, data_in);
2206 /* Do not stream BLOCK_NONLOCALIZED_VARS. We cannot handle debug information
2207 for early inlining so drop it on the floor instead of ICEing in
2208 dwarf2out.c. */
2210 BLOCK_SUPERCONTEXT (expr) = lto_input_tree (ib, data_in);
2211 /* Do not stream BLOCK_ABSTRACT_ORIGIN. We cannot handle debug information
2212 for early inlining so drop it on the floor instead of ICEing in
2213 dwarf2out.c. */
2214 BLOCK_FRAGMENT_ORIGIN (expr) = lto_input_tree (ib, data_in);
2215 BLOCK_FRAGMENT_CHAIN (expr) = lto_input_tree (ib, data_in);
2216 /* We re-compute BLOCK_SUBBLOCKS of our parent here instead
2217 of streaming it. For non-BLOCK BLOCK_SUPERCONTEXTs we still
2218 stream the child relationship explicitly. */
2219 if (BLOCK_SUPERCONTEXT (expr)
2220 && TREE_CODE (BLOCK_SUPERCONTEXT (expr)) == BLOCK)
2222 BLOCK_CHAIN (expr) = BLOCK_SUBBLOCKS (BLOCK_SUPERCONTEXT (expr));
2223 BLOCK_SUBBLOCKS (BLOCK_SUPERCONTEXT (expr)) = expr;
2225 /* The global block is rooted at the TU decl. Hook it here to
2226 avoid the need to stream in this block during WPA time. */
2227 else if (BLOCK_SUPERCONTEXT (expr)
2228 && TREE_CODE (BLOCK_SUPERCONTEXT (expr)) == TRANSLATION_UNIT_DECL)
2229 DECL_INITIAL (BLOCK_SUPERCONTEXT (expr)) = expr;
2230 /* The function-level block is connected at the time we read in
2231 function bodies for the same reason. */
2235 /* Read all pointer fields in the TS_BINFO structure of EXPR from input
2236 block IB. DATA_IN contains tables and descriptors for the
2237 file being read. */
2239 static void
2240 lto_input_ts_binfo_tree_pointers (struct lto_input_block *ib,
2241 struct data_in *data_in, tree expr)
2243 unsigned i, len;
2244 tree t;
2246 /* Note that the number of slots in EXPR was read in
2247 lto_materialize_tree when instantiating EXPR. However, the
2248 vector is empty so we cannot rely on VEC_length to know how many
2249 elements to read. So, this list is emitted as a 0-terminated
2250 list on the writer side. */
2253 t = lto_input_tree (ib, data_in);
2254 if (t)
2255 VEC_quick_push (tree, BINFO_BASE_BINFOS (expr), t);
2257 while (t);
2259 BINFO_OFFSET (expr) = lto_input_tree (ib, data_in);
2260 BINFO_VTABLE (expr) = lto_input_tree (ib, data_in);
2261 BINFO_VIRTUALS (expr) = lto_input_tree (ib, data_in);
2262 BINFO_VPTR_FIELD (expr) = lto_input_tree (ib, data_in);
2264 len = lto_input_uleb128 (ib);
2265 if (len > 0)
2267 VEC_reserve_exact (tree, gc, BINFO_BASE_ACCESSES (expr), len);
2268 for (i = 0; i < len; i++)
2270 tree a = lto_input_tree (ib, data_in);
2271 VEC_quick_push (tree, BINFO_BASE_ACCESSES (expr), a);
2275 BINFO_INHERITANCE_CHAIN (expr) = lto_input_tree (ib, data_in);
2276 BINFO_SUBVTT_INDEX (expr) = lto_input_tree (ib, data_in);
2277 BINFO_VPTR_INDEX (expr) = lto_input_tree (ib, data_in);
2281 /* Read all pointer fields in the TS_CONSTRUCTOR structure of EXPR from
2282 input block IB. DATA_IN contains tables and descriptors for the
2283 file being read. */
2285 static void
2286 lto_input_ts_constructor_tree_pointers (struct lto_input_block *ib,
2287 struct data_in *data_in, tree expr)
2289 unsigned i, len;
2291 len = lto_input_uleb128 (ib);
2292 for (i = 0; i < len; i++)
2294 tree index, value;
2296 index = lto_input_tree (ib, data_in);
2297 value = lto_input_tree (ib, data_in);
2298 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (expr), index, value);
2303 /* Input a TS_TARGET_OPTION tree from IB into EXPR. */
2305 static void
2306 lto_input_ts_target_option (struct lto_input_block *ib, tree expr)
2308 unsigned i, len;
2309 struct bitpack_d bp;
2310 struct cl_target_option *t = TREE_TARGET_OPTION (expr);
2312 bp = lto_input_bitpack (ib);
2313 len = sizeof (struct cl_target_option);
2314 for (i = 0; i < len; i++)
2315 ((unsigned char *)t)[i] = bp_unpack_value (&bp, 8);
2316 if (bp_unpack_value (&bp, 32) != 0x12345678)
2317 fatal_error ("cl_target_option size mismatch in LTO reader and writer");
2320 /* Input a TS_TRANSLATION_UNIT_DECL tree from IB and DATA_IN into EXPR. */
2322 static void
2323 lto_input_ts_translation_unit_decl_tree_pointers (struct lto_input_block *ib,
2324 struct data_in *data_in,
2325 tree expr)
2327 TRANSLATION_UNIT_LANGUAGE (expr) = xstrdup (lto_input_string (data_in, ib));
2328 VEC_safe_push (tree, gc, all_translation_units, expr);
2331 /* Helper for lto_input_tree. Read all pointer fields in EXPR from
2332 input block IB. DATA_IN contains tables and descriptors for the
2333 file being read. */
2335 static void
2336 lto_input_tree_pointers (struct lto_input_block *ib, struct data_in *data_in,
2337 tree expr)
2339 enum tree_code code;
2341 code = TREE_CODE (expr);
2343 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
2344 lto_input_ts_common_tree_pointers (ib, data_in, expr);
2346 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
2347 lto_input_ts_vector_tree_pointers (ib, data_in, expr);
2349 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
2350 lto_input_ts_complex_tree_pointers (ib, data_in, expr);
2352 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
2353 lto_input_ts_decl_minimal_tree_pointers (ib, data_in, expr);
2355 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
2356 lto_input_ts_decl_common_tree_pointers (ib, data_in, expr);
2358 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
2359 lto_input_ts_decl_non_common_tree_pointers (ib, data_in, expr);
2361 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
2362 lto_input_ts_decl_with_vis_tree_pointers (ib, data_in, expr);
2364 if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
2365 lto_input_ts_field_decl_tree_pointers (ib, data_in, expr);
2367 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
2368 lto_input_ts_function_decl_tree_pointers (ib, data_in, expr);
2370 if (CODE_CONTAINS_STRUCT (code, TS_TYPE))
2371 lto_input_ts_type_tree_pointers (ib, data_in, expr);
2373 if (CODE_CONTAINS_STRUCT (code, TS_LIST))
2374 lto_input_ts_list_tree_pointers (ib, data_in, expr);
2376 if (CODE_CONTAINS_STRUCT (code, TS_VEC))
2377 lto_input_ts_vec_tree_pointers (ib, data_in, expr);
2379 if (CODE_CONTAINS_STRUCT (code, TS_EXP))
2380 lto_input_ts_exp_tree_pointers (ib, data_in, expr);
2382 if (CODE_CONTAINS_STRUCT (code, TS_SSA_NAME))
2384 /* We only stream the version number of SSA names. */
2385 gcc_unreachable ();
2388 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
2389 lto_input_ts_block_tree_pointers (ib, data_in, expr);
2391 if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
2392 lto_input_ts_binfo_tree_pointers (ib, data_in, expr);
2394 if (CODE_CONTAINS_STRUCT (code, TS_STATEMENT_LIST))
2396 /* This should only appear in GENERIC. */
2397 gcc_unreachable ();
2400 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
2401 lto_input_ts_constructor_tree_pointers (ib, data_in, expr);
2403 if (CODE_CONTAINS_STRUCT (code, TS_OMP_CLAUSE))
2405 /* This should only appear in High GIMPLE. */
2406 gcc_unreachable ();
2409 if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
2411 sorry ("optimization options not supported yet");
2414 if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION))
2415 lto_input_ts_target_option (ib, expr);
2417 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
2418 lto_input_ts_translation_unit_decl_tree_pointers (ib, data_in, expr);
2422 /* Register DECL with the global symbol table and change its
2423 name if necessary to avoid name clashes for static globals across
2424 different files. */
2426 static void
2427 lto_register_var_decl_in_symtab (struct data_in *data_in, tree decl)
2429 tree context;
2431 /* Variable has file scope, not local. Need to ensure static variables
2432 between different files don't clash unexpectedly. */
2433 if (!TREE_PUBLIC (decl)
2434 && !((context = decl_function_context (decl))
2435 && auto_var_in_fn_p (decl, context)))
2437 /* ??? We normally pre-mangle names before we serialize them
2438 out. Here, in lto1, we do not know the language, and
2439 thus cannot do the mangling again. Instead, we just
2440 append a suffix to the mangled name. The resulting name,
2441 however, is not a properly-formed mangled name, and will
2442 confuse any attempt to unmangle it. */
2443 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2444 char *label;
2446 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
2447 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (label));
2448 rest_of_decl_compilation (decl, 1, 0);
2450 VEC_safe_push (tree, gc, lto_global_var_decls, decl);
2453 /* If this variable has already been declared, queue the
2454 declaration for merging. */
2455 if (TREE_PUBLIC (decl))
2457 int ix;
2458 if (!lto_streamer_cache_lookup (data_in->reader_cache, decl, &ix))
2459 gcc_unreachable ();
2460 lto_symtab_register_decl (decl, get_resolution (data_in, ix),
2461 data_in->file_data);
2467 /* Register DECL with the global symbol table and change its
2468 name if necessary to avoid name clashes for static globals across
2469 different files. DATA_IN contains descriptors and tables for the
2470 file being read. */
2472 static void
2473 lto_register_function_decl_in_symtab (struct data_in *data_in, tree decl)
2475 /* Need to ensure static entities between different files
2476 don't clash unexpectedly. */
2477 if (!TREE_PUBLIC (decl))
2479 /* We must not use the DECL_ASSEMBLER_NAME macro here, as it
2480 may set the assembler name where it was previously empty. */
2481 tree old_assembler_name = decl->decl_with_vis.assembler_name;
2483 /* FIXME lto: We normally pre-mangle names before we serialize
2484 them out. Here, in lto1, we do not know the language, and
2485 thus cannot do the mangling again. Instead, we just append a
2486 suffix to the mangled name. The resulting name, however, is
2487 not a properly-formed mangled name, and will confuse any
2488 attempt to unmangle it. */
2489 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2490 char *label;
2492 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
2493 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (label));
2495 /* We may arrive here with the old assembler name not set
2496 if the function body is not needed, e.g., it has been
2497 inlined away and does not appear in the cgraph. */
2498 if (old_assembler_name)
2500 tree new_assembler_name = DECL_ASSEMBLER_NAME (decl);
2502 /* Make the original assembler name available for later use.
2503 We may have used it to indicate the section within its
2504 object file where the function body may be found.
2505 FIXME lto: Find a better way to maintain the function decl
2506 to body section mapping so we don't need this hack. */
2507 lto_record_renamed_decl (data_in->file_data,
2508 IDENTIFIER_POINTER (old_assembler_name),
2509 IDENTIFIER_POINTER (new_assembler_name));
2511 /* Also register the reverse mapping so that we can find the
2512 new name given to an existing assembler name (used when
2513 restoring alias pairs in input_constructors_or_inits. */
2514 lto_record_renamed_decl (data_in->file_data,
2515 IDENTIFIER_POINTER (new_assembler_name),
2516 IDENTIFIER_POINTER (old_assembler_name));
2520 /* If this variable has already been declared, queue the
2521 declaration for merging. */
2522 if (TREE_PUBLIC (decl) && !DECL_ABSTRACT (decl))
2524 int ix;
2525 if (!lto_streamer_cache_lookup (data_in->reader_cache, decl, &ix))
2526 gcc_unreachable ();
2527 lto_symtab_register_decl (decl, get_resolution (data_in, ix),
2528 data_in->file_data);
2533 /* Read an index IX from input block IB and return the tree node at
2534 DATA_IN->FILE_DATA->GLOBALS_INDEX[IX]. */
2536 static tree
2537 lto_get_pickled_tree (struct lto_input_block *ib, struct data_in *data_in)
2539 HOST_WIDE_INT ix;
2540 tree result;
2541 enum LTO_tags expected_tag;
2542 unsigned HOST_WIDE_INT orig_offset;
2544 ix = lto_input_sleb128 (ib);
2545 expected_tag = (enum LTO_tags) lto_input_uleb128 (ib);
2547 orig_offset = lto_input_uleb128 (ib);
2548 gcc_assert (orig_offset == (unsigned) orig_offset);
2550 result = lto_streamer_cache_get (data_in->reader_cache, ix);
2551 if (result == NULL_TREE)
2553 /* We have not yet read the cache slot IX. Go to the offset
2554 in the stream where the physical tree node is, and materialize
2555 it from there. */
2556 struct lto_input_block fwd_ib;
2558 /* If we are trying to go back in the stream, something is wrong.
2559 We should've read the node at the earlier position already. */
2560 if (ib->p >= orig_offset)
2561 internal_error ("bytecode stream: tried to jump backwards in the "
2562 "stream");
2564 LTO_INIT_INPUT_BLOCK (fwd_ib, ib->data, orig_offset, ib->len);
2565 result = lto_input_tree (&fwd_ib, data_in);
2568 gcc_assert (result
2569 && TREE_CODE (result) == lto_tag_to_tree_code (expected_tag));
2571 return result;
2575 /* Read a code and class from input block IB and return the
2576 corresponding builtin. DATA_IN is as in lto_input_tree. */
2578 static tree
2579 lto_get_builtin_tree (struct lto_input_block *ib, struct data_in *data_in)
2581 enum built_in_class fclass;
2582 enum built_in_function fcode;
2583 const char *asmname;
2584 tree result;
2585 int ix;
2587 fclass = (enum built_in_class) lto_input_uleb128 (ib);
2588 gcc_assert (fclass == BUILT_IN_NORMAL || fclass == BUILT_IN_MD);
2590 fcode = (enum built_in_function) lto_input_uleb128 (ib);
2592 ix = lto_input_sleb128 (ib);
2593 gcc_assert (ix == (int) ix);
2595 if (fclass == BUILT_IN_NORMAL)
2597 gcc_assert (fcode < END_BUILTINS);
2598 result = built_in_decls[fcode];
2599 gcc_assert (result);
2601 else if (fclass == BUILT_IN_MD)
2603 result = targetm.builtin_decl (fcode, true);
2604 if (!result || result == error_mark_node)
2605 fatal_error ("target specific builtin not available");
2607 else
2608 gcc_unreachable ();
2610 asmname = lto_input_string (data_in, ib);
2611 if (asmname)
2612 set_builtin_user_assembler_name (result, asmname);
2614 lto_streamer_cache_insert_at (data_in->reader_cache, result, ix);
2616 return result;
2620 /* Read the physical representation of a tree node with tag TAG from
2621 input block IB using the per-file context in DATA_IN. */
2623 static tree
2624 lto_read_tree (struct lto_input_block *ib, struct data_in *data_in,
2625 enum LTO_tags tag)
2627 tree result;
2628 int ix;
2630 result = lto_materialize_tree (ib, data_in, tag, &ix);
2632 /* Read all the pointer fields in RESULT. */
2633 lto_input_tree_pointers (ib, data_in, result);
2635 /* We should never try to instantiate an MD or NORMAL builtin here. */
2636 if (TREE_CODE (result) == FUNCTION_DECL)
2637 gcc_assert (!lto_stream_as_builtin_p (result));
2639 if (TREE_CODE (result) == VAR_DECL)
2640 lto_register_var_decl_in_symtab (data_in, result);
2641 else if (TREE_CODE (result) == FUNCTION_DECL && !DECL_BUILT_IN (result))
2642 lto_register_function_decl_in_symtab (data_in, result);
2644 /* end_marker = */ lto_input_1_unsigned (ib);
2646 #ifdef LTO_STREAMER_DEBUG
2647 /* Remove the mapping to RESULT's original address set by
2648 lto_materialize_tree. */
2649 lto_orig_address_remove (result);
2650 #endif
2652 return result;
2656 /* Read and INTEGER_CST node from input block IB using the per-file
2657 context in DATA_IN. */
2659 static tree
2660 lto_input_integer_cst (struct lto_input_block *ib, struct data_in *data_in)
2662 tree result, type;
2663 HOST_WIDE_INT low, high;
2664 bool overflow_p;
2666 type = lto_input_tree (ib, data_in);
2667 overflow_p = (lto_input_1_unsigned (ib) != 0);
2668 low = lto_input_uleb128 (ib);
2669 high = lto_input_uleb128 (ib);
2670 result = build_int_cst_wide (type, low, high);
2672 /* If the original constant had overflown, build a replica of RESULT to
2673 avoid modifying the shared constant returned by build_int_cst_wide. */
2674 if (overflow_p)
2676 result = copy_node (result);
2677 TREE_OVERFLOW (result) = 1;
2680 return result;
2684 /* Read a tree from input block IB using the per-file context in
2685 DATA_IN. This context is used, for example, to resolve references
2686 to previously read nodes. */
2688 tree
2689 lto_input_tree (struct lto_input_block *ib, struct data_in *data_in)
2691 enum LTO_tags tag;
2692 tree result;
2694 tag = input_record_start (ib);
2695 gcc_assert ((unsigned) tag < (unsigned) LTO_NUM_TAGS);
2697 if (tag == LTO_null)
2698 result = NULL_TREE;
2699 else if (tag >= LTO_field_decl_ref && tag <= LTO_global_decl_ref)
2701 /* If TAG is a reference to an indexable tree, the next value
2702 in IB is the index into the table where we expect to find
2703 that tree. */
2704 result = lto_input_tree_ref (ib, data_in, cfun, tag);
2706 else if (tag == LTO_tree_pickle_reference)
2708 /* If TAG is a reference to a previously read tree, look it up in
2709 the reader cache. */
2710 result = lto_get_pickled_tree (ib, data_in);
2712 else if (tag == LTO_builtin_decl)
2714 /* If we are going to read a built-in function, all we need is
2715 the code and class. */
2716 result = lto_get_builtin_tree (ib, data_in);
2718 else if (tag == lto_tree_code_to_tag (INTEGER_CST))
2720 /* For integer constants we only need the type and its hi/low
2721 words. */
2722 result = lto_input_integer_cst (ib, data_in);
2724 else
2726 /* Otherwise, materialize a new node from IB. */
2727 result = lto_read_tree (ib, data_in, tag);
2730 return result;
2734 /* Initialization for the LTO reader. */
2736 void
2737 lto_init_reader (void)
2739 lto_streamer_init ();
2741 memset (&lto_stats, 0, sizeof (lto_stats));
2742 bitmap_obstack_initialize (NULL);
2744 file_name_hash_table = htab_create (37, hash_string_slot_node,
2745 eq_string_slot_node, free);
2747 gimple_register_cfg_hooks ();
2751 /* Create a new data_in object for FILE_DATA. STRINGS is the string
2752 table to use with LEN strings. RESOLUTIONS is the vector of linker
2753 resolutions (NULL if not using a linker plugin). */
2755 struct data_in *
2756 lto_data_in_create (struct lto_file_decl_data *file_data, const char *strings,
2757 unsigned len,
2758 VEC(ld_plugin_symbol_resolution_t,heap) *resolutions)
2760 struct data_in *data_in = XCNEW (struct data_in);
2761 data_in->file_data = file_data;
2762 data_in->strings = strings;
2763 data_in->strings_len = len;
2764 data_in->globals_resolution = resolutions;
2765 data_in->reader_cache = lto_streamer_cache_create ();
2767 return data_in;
2771 /* Remove DATA_IN. */
2773 void
2774 lto_data_in_delete (struct data_in *data_in)
2776 VEC_free (ld_plugin_symbol_resolution_t, heap, data_in->globals_resolution);
2777 lto_streamer_cache_delete (data_in->reader_cache);
2778 free (data_in->labels);
2779 free (data_in);