2011-05-31 Gabriel Charette <gchare@google.com>
[official-gcc.git] / gcc / lto-streamer-in.c
blobe7cbb9a6fc9f5032f566fbe76478880cd8293a25
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 string_for_index (struct data_in *data_in,
136 unsigned int loc,
137 unsigned int *rlen)
139 struct lto_input_block str_tab;
140 unsigned int len;
141 const char *result;
143 if (!loc)
145 *rlen = 0;
146 return NULL;
149 /* Get the string stored at location LOC in DATA_IN->STRINGS. */
150 LTO_INIT_INPUT_BLOCK (str_tab, data_in->strings, loc - 1, data_in->strings_len);
151 len = lto_input_uleb128 (&str_tab);
152 *rlen = len;
154 if (str_tab.p + len > data_in->strings_len)
155 internal_error ("bytecode stream: string too long for the string table");
157 result = (const char *)(data_in->strings + str_tab.p);
159 return result;
163 /* Read a string from the string table in DATA_IN using input block
164 IB. Write the length to RLEN. */
166 static const char *
167 input_string_internal (struct data_in *data_in, struct lto_input_block *ib,
168 unsigned int *rlen)
170 return string_for_index (data_in, lto_input_uleb128 (ib), rlen);
174 /* Read a STRING_CST from the string table in DATA_IN using input
175 block IB. */
177 static tree
178 input_string_cst (struct data_in *data_in, struct lto_input_block *ib)
180 unsigned int len;
181 const char * ptr;
183 ptr = input_string_internal (data_in, ib, &len);
184 if (!ptr)
185 return NULL;
186 return build_string (len, ptr);
190 /* Read an IDENTIFIER from the string table in DATA_IN using input
191 block IB. */
193 static tree
194 input_identifier (struct data_in *data_in, struct lto_input_block *ib)
196 unsigned int len;
197 const char *ptr;
199 ptr = input_string_internal (data_in, ib, &len);
200 if (!ptr)
201 return NULL;
202 return get_identifier_with_length (ptr, len);
206 /* Read LENGTH bytes from STREAM to ADDR. */
208 void
209 lto_input_data_block (struct lto_input_block *ib, void *addr, size_t length)
211 size_t i;
212 unsigned char *const buffer = (unsigned char *const) addr;
214 for (i = 0; i < length; i++)
215 buffer[i] = lto_input_1_unsigned (ib);
219 /* Read a NULL terminated string from the string table in DATA_IN. */
221 const char *
222 lto_input_string (struct data_in *data_in, struct lto_input_block *ib)
224 unsigned int len;
225 const char *ptr;
227 ptr = input_string_internal (data_in, ib, &len);
228 if (!ptr)
229 return NULL;
230 if (ptr[len - 1] != '\0')
231 internal_error ("bytecode stream: found non-null terminated string");
233 return ptr;
237 /* Return the next tag in the input block IB. */
239 static inline enum LTO_tags
240 input_record_start (struct lto_input_block *ib)
242 return lto_input_enum (ib, LTO_tags, LTO_NUM_TAGS);
246 /* Lookup STRING in file_name_hash_table. If found, return the existing
247 string, otherwise insert STRING as the canonical version. */
249 static const char *
250 canon_file_name (const char *string)
252 void **slot;
253 struct string_slot s_slot;
254 s_slot.s = string;
256 slot = htab_find_slot (file_name_hash_table, &s_slot, INSERT);
257 if (*slot == NULL)
259 size_t len;
260 char *saved_string;
261 struct string_slot *new_slot;
263 len = strlen (string);
264 saved_string = (char *) xmalloc (len + 1);
265 new_slot = XCNEW (struct string_slot);
266 strcpy (saved_string, string);
267 new_slot->s = saved_string;
268 *slot = new_slot;
269 return saved_string;
271 else
273 struct string_slot *old_slot = (struct string_slot *) *slot;
274 return old_slot->s;
279 /* Clear the line info stored in DATA_IN. */
281 static void
282 clear_line_info (struct data_in *data_in)
284 if (data_in->current_file)
285 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
286 data_in->current_file = NULL;
287 data_in->current_line = 0;
288 data_in->current_col = 0;
292 /* Read a location bitpack from input block IB. */
294 static location_t
295 lto_input_location_bitpack (struct data_in *data_in, struct bitpack_d *bp)
297 bool file_change, line_change, column_change;
298 unsigned len;
299 bool prev_file = data_in->current_file != NULL;
301 if (bp_unpack_value (bp, 1))
302 return UNKNOWN_LOCATION;
304 file_change = bp_unpack_value (bp, 1);
305 if (file_change)
306 data_in->current_file = canon_file_name
307 (string_for_index (data_in,
308 bp_unpack_var_len_unsigned (bp),
309 &len));
311 line_change = bp_unpack_value (bp, 1);
312 if (line_change)
313 data_in->current_line = bp_unpack_var_len_unsigned (bp);
315 column_change = bp_unpack_value (bp, 1);
316 if (column_change)
317 data_in->current_col = bp_unpack_var_len_unsigned (bp);
319 if (file_change)
321 if (prev_file)
322 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
324 linemap_add (line_table, LC_ENTER, false, data_in->current_file,
325 data_in->current_line);
327 else if (line_change)
328 linemap_line_start (line_table, data_in->current_line, data_in->current_col);
330 return linemap_position_for_column (line_table, data_in->current_col);
334 /* Read a location from input block IB. */
336 static location_t
337 lto_input_location (struct lto_input_block *ib, struct data_in *data_in)
339 struct bitpack_d bp;
341 bp = lto_input_bitpack (ib);
342 return lto_input_location_bitpack (data_in, &bp);
346 /* Read a reference to a tree node from DATA_IN using input block IB.
347 TAG is the expected node that should be found in IB, if TAG belongs
348 to one of the indexable trees, expect to read a reference index to
349 be looked up in one of the symbol tables, otherwise read the pysical
350 representation of the tree using lto_input_tree. FN is the
351 function scope for the read tree. */
353 static tree
354 lto_input_tree_ref (struct lto_input_block *ib, struct data_in *data_in,
355 struct function *fn, enum LTO_tags tag)
357 unsigned HOST_WIDE_INT ix_u;
358 tree result = NULL_TREE;
360 lto_tag_check_range (tag, LTO_field_decl_ref, LTO_global_decl_ref);
362 switch (tag)
364 case LTO_type_ref:
365 ix_u = lto_input_uleb128 (ib);
366 result = lto_file_decl_data_get_type (data_in->file_data, ix_u);
367 break;
369 case LTO_ssa_name_ref:
370 ix_u = lto_input_uleb128 (ib);
371 result = VEC_index (tree, SSANAMES (fn), ix_u);
372 break;
374 case LTO_field_decl_ref:
375 ix_u = lto_input_uleb128 (ib);
376 result = lto_file_decl_data_get_field_decl (data_in->file_data, ix_u);
377 break;
379 case LTO_function_decl_ref:
380 ix_u = lto_input_uleb128 (ib);
381 result = lto_file_decl_data_get_fn_decl (data_in->file_data, ix_u);
382 break;
384 case LTO_type_decl_ref:
385 ix_u = lto_input_uleb128 (ib);
386 result = lto_file_decl_data_get_type_decl (data_in->file_data, ix_u);
387 break;
389 case LTO_namespace_decl_ref:
390 ix_u = lto_input_uleb128 (ib);
391 result = lto_file_decl_data_get_namespace_decl (data_in->file_data, ix_u);
392 break;
394 case LTO_global_decl_ref:
395 case LTO_result_decl_ref:
396 case LTO_const_decl_ref:
397 case LTO_imported_decl_ref:
398 case LTO_label_decl_ref:
399 case LTO_translation_unit_decl_ref:
400 ix_u = lto_input_uleb128 (ib);
401 result = lto_file_decl_data_get_var_decl (data_in->file_data, ix_u);
402 break;
404 default:
405 gcc_unreachable ();
408 gcc_assert (result);
410 return result;
414 /* Read a chain of tree nodes from input block IB. DATA_IN contains
415 tables and descriptors for the file being read. */
417 tree
418 lto_input_chain (struct lto_input_block *ib, struct data_in *data_in)
420 int i, count;
421 tree first, prev, curr;
423 first = prev = NULL_TREE;
424 count = lto_input_sleb128 (ib);
425 for (i = 0; i < count; i++)
427 curr = lto_input_tree (ib, data_in);
428 if (prev)
429 TREE_CHAIN (prev) = curr;
430 else
431 first = curr;
433 TREE_CHAIN (curr) = NULL_TREE;
434 prev = curr;
437 return first;
441 /* Read and return a double-linked list of catch handlers from input
442 block IB, using descriptors in DATA_IN. */
444 static struct eh_catch_d *
445 lto_input_eh_catch_list (struct lto_input_block *ib, struct data_in *data_in,
446 eh_catch *last_p)
448 eh_catch first;
449 enum LTO_tags tag;
451 *last_p = first = NULL;
452 tag = input_record_start (ib);
453 while (tag)
455 tree list;
456 eh_catch n;
458 lto_tag_check_range (tag, LTO_eh_catch, LTO_eh_catch);
460 /* Read the catch node. */
461 n = ggc_alloc_cleared_eh_catch_d ();
462 n->type_list = lto_input_tree (ib, data_in);
463 n->filter_list = lto_input_tree (ib, data_in);
464 n->label = lto_input_tree (ib, data_in);
466 /* Register all the types in N->FILTER_LIST. */
467 for (list = n->filter_list; list; list = TREE_CHAIN (list))
468 add_type_for_runtime (TREE_VALUE (list));
470 /* Chain N to the end of the list. */
471 if (*last_p)
472 (*last_p)->next_catch = n;
473 n->prev_catch = *last_p;
474 *last_p = n;
476 /* Set the head of the list the first time through the loop. */
477 if (first == NULL)
478 first = n;
480 tag = input_record_start (ib);
483 return first;
487 /* Read and return EH region IX from input block IB, using descriptors
488 in DATA_IN. */
490 static eh_region
491 input_eh_region (struct lto_input_block *ib, struct data_in *data_in, int ix)
493 enum LTO_tags tag;
494 eh_region r;
496 /* Read the region header. */
497 tag = input_record_start (ib);
498 if (tag == LTO_null)
499 return NULL;
501 r = ggc_alloc_cleared_eh_region_d ();
502 r->index = lto_input_sleb128 (ib);
504 gcc_assert (r->index == ix);
506 /* Read all the region pointers as region numbers. We'll fix up
507 the pointers once the whole array has been read. */
508 r->outer = (eh_region) (intptr_t) lto_input_sleb128 (ib);
509 r->inner = (eh_region) (intptr_t) lto_input_sleb128 (ib);
510 r->next_peer = (eh_region) (intptr_t) lto_input_sleb128 (ib);
512 switch (tag)
514 case LTO_ert_cleanup:
515 r->type = ERT_CLEANUP;
516 break;
518 case LTO_ert_try:
520 struct eh_catch_d *last_catch;
521 r->type = ERT_TRY;
522 r->u.eh_try.first_catch = lto_input_eh_catch_list (ib, data_in,
523 &last_catch);
524 r->u.eh_try.last_catch = last_catch;
525 break;
528 case LTO_ert_allowed_exceptions:
530 tree l;
532 r->type = ERT_ALLOWED_EXCEPTIONS;
533 r->u.allowed.type_list = lto_input_tree (ib, data_in);
534 r->u.allowed.label = lto_input_tree (ib, data_in);
535 r->u.allowed.filter = lto_input_uleb128 (ib);
537 for (l = r->u.allowed.type_list; l ; l = TREE_CHAIN (l))
538 add_type_for_runtime (TREE_VALUE (l));
540 break;
542 case LTO_ert_must_not_throw:
543 r->type = ERT_MUST_NOT_THROW;
544 r->u.must_not_throw.failure_decl = lto_input_tree (ib, data_in);
545 r->u.must_not_throw.failure_loc = lto_input_location (ib, data_in);
546 break;
548 default:
549 gcc_unreachable ();
552 r->landing_pads = (eh_landing_pad) (intptr_t) lto_input_sleb128 (ib);
554 return r;
558 /* Read and return EH landing pad IX from input block IB, using descriptors
559 in DATA_IN. */
561 static eh_landing_pad
562 input_eh_lp (struct lto_input_block *ib, struct data_in *data_in, int ix)
564 enum LTO_tags tag;
565 eh_landing_pad lp;
567 /* Read the landing pad header. */
568 tag = input_record_start (ib);
569 if (tag == LTO_null)
570 return NULL;
572 lto_tag_check_range (tag, LTO_eh_landing_pad, LTO_eh_landing_pad);
574 lp = ggc_alloc_cleared_eh_landing_pad_d ();
575 lp->index = lto_input_sleb128 (ib);
576 gcc_assert (lp->index == ix);
577 lp->next_lp = (eh_landing_pad) (intptr_t) lto_input_sleb128 (ib);
578 lp->region = (eh_region) (intptr_t) lto_input_sleb128 (ib);
579 lp->post_landing_pad = lto_input_tree (ib, data_in);
581 return lp;
585 /* After reading the EH regions, pointers to peer and children regions
586 are region numbers. This converts all these region numbers into
587 real pointers into the rematerialized regions for FN. ROOT_REGION
588 is the region number for the root EH region in FN. */
590 static void
591 fixup_eh_region_pointers (struct function *fn, HOST_WIDE_INT root_region)
593 unsigned i;
594 VEC(eh_region,gc) *eh_array = fn->eh->region_array;
595 VEC(eh_landing_pad,gc) *lp_array = fn->eh->lp_array;
596 eh_region r;
597 eh_landing_pad lp;
599 gcc_assert (eh_array && lp_array);
601 gcc_assert (root_region >= 0);
602 fn->eh->region_tree = VEC_index (eh_region, eh_array, root_region);
604 #define FIXUP_EH_REGION(r) (r) = VEC_index (eh_region, eh_array, \
605 (HOST_WIDE_INT) (intptr_t) (r))
606 #define FIXUP_EH_LP(p) (p) = VEC_index (eh_landing_pad, lp_array, \
607 (HOST_WIDE_INT) (intptr_t) (p))
609 /* Convert all the index numbers stored in pointer fields into
610 pointers to the corresponding slots in the EH region array. */
611 FOR_EACH_VEC_ELT (eh_region, eh_array, i, r)
613 /* The array may contain NULL regions. */
614 if (r == NULL)
615 continue;
617 gcc_assert (i == (unsigned) r->index);
618 FIXUP_EH_REGION (r->outer);
619 FIXUP_EH_REGION (r->inner);
620 FIXUP_EH_REGION (r->next_peer);
621 FIXUP_EH_LP (r->landing_pads);
624 /* Convert all the index numbers stored in pointer fields into
625 pointers to the corresponding slots in the EH landing pad array. */
626 FOR_EACH_VEC_ELT (eh_landing_pad, lp_array, i, lp)
628 /* The array may contain NULL landing pads. */
629 if (lp == NULL)
630 continue;
632 gcc_assert (i == (unsigned) lp->index);
633 FIXUP_EH_LP (lp->next_lp);
634 FIXUP_EH_REGION (lp->region);
637 #undef FIXUP_EH_REGION
638 #undef FIXUP_EH_LP
642 /* Initialize EH support. */
644 static void
645 lto_init_eh (void)
647 static bool eh_initialized_p = false;
649 if (eh_initialized_p)
650 return;
652 /* Contrary to most other FEs, we only initialize EH support when at
653 least one of the files in the set contains exception regions in
654 it. Since this happens much later than the call to init_eh in
655 lang_dependent_init, we have to set flag_exceptions and call
656 init_eh again to initialize the EH tables. */
657 flag_exceptions = 1;
658 init_eh ();
660 /* Initialize dwarf2 tables. Since dwarf2out_do_frame() returns
661 true only when exceptions are enabled, this initialization is
662 never done during lang_dependent_init. */
663 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
664 if (dwarf2out_do_frame ())
665 dwarf2out_frame_init ();
666 #endif
668 eh_initialized_p = true;
672 /* Read the exception table for FN from IB using the data descriptors
673 in DATA_IN. */
675 static void
676 input_eh_regions (struct lto_input_block *ib, struct data_in *data_in,
677 struct function *fn)
679 HOST_WIDE_INT i, root_region, len;
680 enum LTO_tags tag;
682 tag = input_record_start (ib);
683 if (tag == LTO_null)
684 return;
686 lto_tag_check_range (tag, LTO_eh_table, LTO_eh_table);
688 /* If the file contains EH regions, then it was compiled with
689 -fexceptions. In that case, initialize the backend EH
690 machinery. */
691 lto_init_eh ();
693 gcc_assert (fn->eh);
695 root_region = lto_input_sleb128 (ib);
696 gcc_assert (root_region == (int) root_region);
698 /* Read the EH region array. */
699 len = lto_input_sleb128 (ib);
700 gcc_assert (len == (int) len);
701 if (len > 0)
703 VEC_safe_grow (eh_region, gc, fn->eh->region_array, len);
704 for (i = 0; i < len; i++)
706 eh_region r = input_eh_region (ib, data_in, i);
707 VEC_replace (eh_region, fn->eh->region_array, i, r);
711 /* Read the landing pads. */
712 len = lto_input_sleb128 (ib);
713 gcc_assert (len == (int) len);
714 if (len > 0)
716 VEC_safe_grow (eh_landing_pad, gc, fn->eh->lp_array, len);
717 for (i = 0; i < len; i++)
719 eh_landing_pad lp = input_eh_lp (ib, data_in, i);
720 VEC_replace (eh_landing_pad, fn->eh->lp_array, i, lp);
724 /* Read the runtime type data. */
725 len = lto_input_sleb128 (ib);
726 gcc_assert (len == (int) len);
727 if (len > 0)
729 VEC_safe_grow (tree, gc, fn->eh->ttype_data, len);
730 for (i = 0; i < len; i++)
732 tree ttype = lto_input_tree (ib, data_in);
733 VEC_replace (tree, fn->eh->ttype_data, i, ttype);
737 /* Read the table of action chains. */
738 len = lto_input_sleb128 (ib);
739 gcc_assert (len == (int) len);
740 if (len > 0)
742 if (targetm.arm_eabi_unwinder)
744 VEC_safe_grow (tree, gc, fn->eh->ehspec_data.arm_eabi, len);
745 for (i = 0; i < len; i++)
747 tree t = lto_input_tree (ib, data_in);
748 VEC_replace (tree, fn->eh->ehspec_data.arm_eabi, i, t);
751 else
753 VEC_safe_grow (uchar, gc, fn->eh->ehspec_data.other, len);
754 for (i = 0; i < len; i++)
756 uchar c = lto_input_1_unsigned (ib);
757 VEC_replace (uchar, fn->eh->ehspec_data.other, i, c);
762 /* Reconstruct the EH region tree by fixing up the peer/children
763 pointers. */
764 fixup_eh_region_pointers (fn, root_region);
766 tag = input_record_start (ib);
767 lto_tag_check_range (tag, LTO_null, LTO_null);
771 /* Make a new basic block with index INDEX in function FN. */
773 static basic_block
774 make_new_block (struct function *fn, unsigned int index)
776 basic_block bb = alloc_block ();
777 bb->index = index;
778 SET_BASIC_BLOCK_FOR_FUNCTION (fn, index, bb);
779 bb->il.gimple = ggc_alloc_cleared_gimple_bb_info ();
780 n_basic_blocks_for_function (fn)++;
781 bb->flags = 0;
782 set_bb_seq (bb, gimple_seq_alloc ());
783 return bb;
787 /* Read the CFG for function FN from input block IB. */
789 static void
790 input_cfg (struct lto_input_block *ib, struct function *fn,
791 int count_materialization_scale)
793 unsigned int bb_count;
794 basic_block p_bb;
795 unsigned int i;
796 int index;
798 init_empty_tree_cfg_for_function (fn);
799 init_ssa_operands ();
801 profile_status_for_function (fn) =
802 (enum profile_status_d) lto_input_uleb128 (ib);
804 bb_count = lto_input_uleb128 (ib);
806 last_basic_block_for_function (fn) = bb_count;
807 if (bb_count > VEC_length (basic_block, basic_block_info_for_function (fn)))
808 VEC_safe_grow_cleared (basic_block, gc,
809 basic_block_info_for_function (fn), bb_count);
811 if (bb_count > VEC_length (basic_block, label_to_block_map_for_function (fn)))
812 VEC_safe_grow_cleared (basic_block, gc,
813 label_to_block_map_for_function (fn), bb_count);
815 index = lto_input_sleb128 (ib);
816 while (index != -1)
818 basic_block bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
819 unsigned int edge_count;
821 if (bb == NULL)
822 bb = make_new_block (fn, index);
824 edge_count = lto_input_uleb128 (ib);
826 /* Connect up the CFG. */
827 for (i = 0; i < edge_count; i++)
829 unsigned int dest_index;
830 unsigned int edge_flags;
831 basic_block dest;
832 int probability;
833 gcov_type count;
834 edge e;
836 dest_index = lto_input_uleb128 (ib);
837 probability = (int) lto_input_sleb128 (ib);
838 count = ((gcov_type) lto_input_sleb128 (ib) * count_materialization_scale
839 + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE;
840 edge_flags = lto_input_uleb128 (ib);
842 dest = BASIC_BLOCK_FOR_FUNCTION (fn, dest_index);
844 if (dest == NULL)
845 dest = make_new_block (fn, dest_index);
847 e = make_edge (bb, dest, edge_flags);
848 e->probability = probability;
849 e->count = count;
852 index = lto_input_sleb128 (ib);
855 p_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(fn);
856 index = lto_input_sleb128 (ib);
857 while (index != -1)
859 basic_block bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
860 bb->prev_bb = p_bb;
861 p_bb->next_bb = bb;
862 p_bb = bb;
863 index = lto_input_sleb128 (ib);
868 /* Read a PHI function for basic block BB in function FN. DATA_IN is
869 the file being read. IB is the input block to use for reading. */
871 static gimple
872 input_phi (struct lto_input_block *ib, basic_block bb, struct data_in *data_in,
873 struct function *fn)
875 unsigned HOST_WIDE_INT ix;
876 tree phi_result;
877 int i, len;
878 gimple result;
880 ix = lto_input_uleb128 (ib);
881 phi_result = VEC_index (tree, SSANAMES (fn), ix);
882 len = EDGE_COUNT (bb->preds);
883 result = create_phi_node (phi_result, bb);
884 SSA_NAME_DEF_STMT (phi_result) = result;
886 /* We have to go through a lookup process here because the preds in the
887 reconstructed graph are generally in a different order than they
888 were in the original program. */
889 for (i = 0; i < len; i++)
891 tree def = lto_input_tree (ib, data_in);
892 int src_index = lto_input_uleb128 (ib);
893 location_t arg_loc = lto_input_location (ib, data_in);
894 basic_block sbb = BASIC_BLOCK_FOR_FUNCTION (fn, src_index);
896 edge e = NULL;
897 int j;
899 for (j = 0; j < len; j++)
900 if (EDGE_PRED (bb, j)->src == sbb)
902 e = EDGE_PRED (bb, j);
903 break;
906 add_phi_arg (result, def, e, arg_loc);
909 return result;
913 /* Read the SSA names array for function FN from DATA_IN using input
914 block IB. */
916 static void
917 input_ssa_names (struct lto_input_block *ib, struct data_in *data_in,
918 struct function *fn)
920 unsigned int i, size;
922 size = lto_input_uleb128 (ib);
923 init_ssanames (fn, size);
925 i = lto_input_uleb128 (ib);
926 while (i)
928 tree ssa_name, name;
929 bool is_default_def;
931 /* Skip over the elements that had been freed. */
932 while (VEC_length (tree, SSANAMES (fn)) < i)
933 VEC_quick_push (tree, SSANAMES (fn), NULL_TREE);
935 is_default_def = (lto_input_1_unsigned (ib) != 0);
936 name = lto_input_tree (ib, data_in);
937 ssa_name = make_ssa_name_fn (fn, name, gimple_build_nop ());
939 if (is_default_def)
940 set_default_def (SSA_NAME_VAR (ssa_name), ssa_name);
942 i = lto_input_uleb128 (ib);
946 /* Read a statement with tag TAG in function FN from block IB using
947 descriptors in DATA_IN. */
949 static gimple
950 input_gimple_stmt (struct lto_input_block *ib, struct data_in *data_in,
951 struct function *fn, enum LTO_tags tag)
953 gimple stmt;
954 enum gimple_code code;
955 unsigned HOST_WIDE_INT num_ops;
956 size_t i;
957 struct bitpack_d bp;
959 code = lto_tag_to_gimple_code (tag);
961 /* Read the tuple header. */
962 bp = lto_input_bitpack (ib);
963 num_ops = bp_unpack_value (&bp, sizeof (unsigned) * 8);
964 stmt = gimple_alloc (code, num_ops);
965 stmt->gsbase.no_warning = bp_unpack_value (&bp, 1);
966 if (is_gimple_assign (stmt))
967 stmt->gsbase.nontemporal_move = bp_unpack_value (&bp, 1);
968 stmt->gsbase.has_volatile_ops = bp_unpack_value (&bp, 1);
969 stmt->gsbase.subcode = bp_unpack_value (&bp, 16);
971 /* Read location information. */
972 gimple_set_location (stmt, lto_input_location (ib, data_in));
974 /* Read lexical block reference. */
975 gimple_set_block (stmt, lto_input_tree (ib, data_in));
977 /* Read in all the operands. */
978 switch (code)
980 case GIMPLE_RESX:
981 gimple_resx_set_region (stmt, lto_input_sleb128 (ib));
982 break;
984 case GIMPLE_EH_MUST_NOT_THROW:
985 gimple_eh_must_not_throw_set_fndecl (stmt, lto_input_tree (ib, data_in));
986 break;
988 case GIMPLE_EH_DISPATCH:
989 gimple_eh_dispatch_set_region (stmt, lto_input_sleb128 (ib));
990 break;
992 case GIMPLE_ASM:
994 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
995 tree str;
996 stmt->gimple_asm.ni = lto_input_uleb128 (ib);
997 stmt->gimple_asm.no = lto_input_uleb128 (ib);
998 stmt->gimple_asm.nc = lto_input_uleb128 (ib);
999 stmt->gimple_asm.nl = lto_input_uleb128 (ib);
1000 str = input_string_cst (data_in, ib);
1001 stmt->gimple_asm.string = TREE_STRING_POINTER (str);
1003 /* Fallthru */
1005 case GIMPLE_ASSIGN:
1006 case GIMPLE_CALL:
1007 case GIMPLE_RETURN:
1008 case GIMPLE_SWITCH:
1009 case GIMPLE_LABEL:
1010 case GIMPLE_COND:
1011 case GIMPLE_GOTO:
1012 case GIMPLE_DEBUG:
1013 for (i = 0; i < num_ops; i++)
1015 tree op = lto_input_tree (ib, data_in);
1016 gimple_set_op (stmt, i, op);
1017 if (!op)
1018 continue;
1020 /* Fixup FIELD_DECLs in COMPONENT_REFs, they are not handled
1021 by decl merging. */
1022 if (TREE_CODE (op) == ADDR_EXPR)
1023 op = TREE_OPERAND (op, 0);
1024 while (handled_component_p (op))
1026 if (TREE_CODE (op) == COMPONENT_REF)
1028 tree field, type, tem;
1029 tree closest_match = NULL_TREE;
1030 field = TREE_OPERAND (op, 1);
1031 type = DECL_CONTEXT (field);
1032 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1034 if (tem == field)
1035 break;
1036 if (DECL_NONADDRESSABLE_P (tem)
1037 == DECL_NONADDRESSABLE_P (field)
1038 && gimple_compare_field_offset (tem, field))
1040 if (types_compatible_p (TREE_TYPE (tem),
1041 TREE_TYPE (field)))
1042 break;
1043 else
1044 closest_match = tem;
1047 /* In case of type mismatches across units we can fail
1048 to unify some types and thus not find a proper
1049 field-decl here. */
1050 if (tem == NULL_TREE)
1052 /* Thus, emit a ODR violation warning. */
1053 if (warning_at (gimple_location (stmt), 0,
1054 "use of type %<%E%> with two mismatching "
1055 "declarations at field %<%E%>",
1056 type, TREE_OPERAND (op, 1)))
1058 if (TYPE_FIELDS (type))
1059 inform (DECL_SOURCE_LOCATION (TYPE_FIELDS (type)),
1060 "original type declared here");
1061 inform (DECL_SOURCE_LOCATION (TREE_OPERAND (op, 1)),
1062 "field in mismatching type declared here");
1063 if (TYPE_NAME (TREE_TYPE (field))
1064 && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
1065 == TYPE_DECL))
1066 inform (DECL_SOURCE_LOCATION
1067 (TYPE_NAME (TREE_TYPE (field))),
1068 "type of field declared here");
1069 if (closest_match
1070 && TYPE_NAME (TREE_TYPE (closest_match))
1071 && (TREE_CODE (TYPE_NAME
1072 (TREE_TYPE (closest_match))) == TYPE_DECL))
1073 inform (DECL_SOURCE_LOCATION
1074 (TYPE_NAME (TREE_TYPE (closest_match))),
1075 "type of mismatching field declared here");
1077 /* And finally fixup the types. */
1078 TREE_OPERAND (op, 0)
1079 = build1 (VIEW_CONVERT_EXPR, type,
1080 TREE_OPERAND (op, 0));
1082 else
1083 TREE_OPERAND (op, 1) = tem;
1086 op = TREE_OPERAND (op, 0);
1089 if (is_gimple_call (stmt))
1091 if (gimple_call_internal_p (stmt))
1092 gimple_call_set_internal_fn
1093 (stmt, (enum internal_fn) lto_input_sleb128 (ib));
1094 else
1095 gimple_call_set_fntype (stmt, lto_input_tree (ib, data_in));
1097 break;
1099 case GIMPLE_NOP:
1100 case GIMPLE_PREDICT:
1101 break;
1103 default:
1104 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
1105 lto_tag_name (tag));
1108 /* Update the properties of symbols, SSA names and labels associated
1109 with STMT. */
1110 if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
1112 tree lhs = gimple_get_lhs (stmt);
1113 if (lhs && TREE_CODE (lhs) == SSA_NAME)
1114 SSA_NAME_DEF_STMT (lhs) = stmt;
1116 else if (code == GIMPLE_LABEL)
1117 gcc_assert (emit_label_in_global_context_p (gimple_label_label (stmt))
1118 || DECL_CONTEXT (gimple_label_label (stmt)) == fn->decl);
1119 else if (code == GIMPLE_ASM)
1121 unsigned i;
1123 for (i = 0; i < gimple_asm_noutputs (stmt); i++)
1125 tree op = TREE_VALUE (gimple_asm_output_op (stmt, i));
1126 if (TREE_CODE (op) == SSA_NAME)
1127 SSA_NAME_DEF_STMT (op) = stmt;
1131 /* Reset alias information. */
1132 if (code == GIMPLE_CALL)
1133 gimple_call_reset_alias_info (stmt);
1135 /* Mark the statement modified so its operand vectors can be filled in. */
1136 gimple_set_modified (stmt, true);
1138 return stmt;
1142 /* Read a basic block with tag TAG from DATA_IN using input block IB.
1143 FN is the function being processed. */
1145 static void
1146 input_bb (struct lto_input_block *ib, enum LTO_tags tag,
1147 struct data_in *data_in, struct function *fn,
1148 int count_materialization_scale)
1150 unsigned int index;
1151 basic_block bb;
1152 gimple_stmt_iterator bsi;
1154 /* This routine assumes that CFUN is set to FN, as it needs to call
1155 basic GIMPLE routines that use CFUN. */
1156 gcc_assert (cfun == fn);
1158 index = lto_input_uleb128 (ib);
1159 bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
1161 bb->count = (lto_input_sleb128 (ib) * count_materialization_scale
1162 + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE;
1163 bb->loop_depth = lto_input_sleb128 (ib);
1164 bb->frequency = lto_input_sleb128 (ib);
1165 bb->flags = lto_input_sleb128 (ib);
1167 /* LTO_bb1 has statements. LTO_bb0 does not. */
1168 if (tag == LTO_bb0)
1169 return;
1171 bsi = gsi_start_bb (bb);
1172 tag = input_record_start (ib);
1173 while (tag)
1175 gimple stmt = input_gimple_stmt (ib, data_in, fn, tag);
1176 if (!is_gimple_debug (stmt))
1177 find_referenced_vars_in (stmt);
1178 gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
1180 /* After the statement, expect a 0 delimiter or the EH region
1181 that the previous statement belongs to. */
1182 tag = input_record_start (ib);
1183 lto_tag_check_set (tag, 2, LTO_eh_region, LTO_null);
1185 if (tag == LTO_eh_region)
1187 HOST_WIDE_INT region = lto_input_sleb128 (ib);
1188 gcc_assert (region == (int) region);
1189 add_stmt_to_eh_lp (stmt, region);
1192 tag = input_record_start (ib);
1195 tag = input_record_start (ib);
1196 while (tag)
1198 gimple phi = input_phi (ib, bb, data_in, fn);
1199 find_referenced_vars_in (phi);
1200 tag = input_record_start (ib);
1204 /* Go through all NODE edges and fixup call_stmt pointers
1205 so they point to STMTS. */
1207 static void
1208 fixup_call_stmt_edges_1 (struct cgraph_node *node, gimple *stmts)
1210 struct cgraph_edge *cedge;
1211 for (cedge = node->callees; cedge; cedge = cedge->next_callee)
1212 cedge->call_stmt = stmts[cedge->lto_stmt_uid];
1213 for (cedge = node->indirect_calls; cedge; cedge = cedge->next_callee)
1214 cedge->call_stmt = stmts[cedge->lto_stmt_uid];
1217 /* Fixup call_stmt pointers in NODE and all clones. */
1219 static void
1220 fixup_call_stmt_edges (struct cgraph_node *orig, gimple *stmts)
1222 struct cgraph_node *node;
1224 while (orig->clone_of)
1225 orig = orig->clone_of;
1227 fixup_call_stmt_edges_1 (orig, stmts);
1228 if (orig->clones)
1229 for (node = orig->clones; node != orig;)
1231 fixup_call_stmt_edges_1 (node, stmts);
1232 if (node->clones)
1233 node = node->clones;
1234 else if (node->next_sibling_clone)
1235 node = node->next_sibling_clone;
1236 else
1238 while (node != orig && !node->next_sibling_clone)
1239 node = node->clone_of;
1240 if (node != orig)
1241 node = node->next_sibling_clone;
1246 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1248 static void
1249 input_function (tree fn_decl, struct data_in *data_in,
1250 struct lto_input_block *ib)
1252 struct function *fn;
1253 enum LTO_tags tag;
1254 gimple *stmts;
1255 basic_block bb;
1256 struct bitpack_d bp;
1257 struct cgraph_node *node;
1258 tree args, narg, oarg;
1259 int len;
1261 fn = DECL_STRUCT_FUNCTION (fn_decl);
1262 tag = input_record_start (ib);
1263 clear_line_info (data_in);
1265 gimple_register_cfg_hooks ();
1266 lto_tag_check (tag, LTO_function);
1268 /* Read all the attributes for FN. */
1269 bp = lto_input_bitpack (ib);
1270 fn->is_thunk = bp_unpack_value (&bp, 1);
1271 fn->has_local_explicit_reg_vars = bp_unpack_value (&bp, 1);
1272 fn->after_tree_profile = bp_unpack_value (&bp, 1);
1273 fn->returns_pcc_struct = bp_unpack_value (&bp, 1);
1274 fn->returns_struct = bp_unpack_value (&bp, 1);
1275 fn->can_throw_non_call_exceptions = bp_unpack_value (&bp, 1);
1276 fn->always_inline_functions_inlined = bp_unpack_value (&bp, 1);
1277 fn->after_inlining = bp_unpack_value (&bp, 1);
1278 fn->stdarg = bp_unpack_value (&bp, 1);
1279 fn->has_nonlocal_label = bp_unpack_value (&bp, 1);
1280 fn->calls_alloca = bp_unpack_value (&bp, 1);
1281 fn->calls_setjmp = bp_unpack_value (&bp, 1);
1282 fn->va_list_fpr_size = bp_unpack_value (&bp, 8);
1283 fn->va_list_gpr_size = bp_unpack_value (&bp, 8);
1285 /* Input the function start and end loci. */
1286 fn->function_start_locus = lto_input_location (ib, data_in);
1287 fn->function_end_locus = lto_input_location (ib, data_in);
1289 /* Input the current IL state of the function. */
1290 fn->curr_properties = lto_input_uleb128 (ib);
1292 /* Read the static chain and non-local goto save area. */
1293 fn->static_chain_decl = lto_input_tree (ib, data_in);
1294 fn->nonlocal_goto_save_area = lto_input_tree (ib, data_in);
1296 /* Read all the local symbols. */
1297 len = lto_input_sleb128 (ib);
1298 if (len > 0)
1300 int i;
1301 VEC_safe_grow (tree, gc, fn->local_decls, len);
1302 for (i = 0; i < len; i++)
1304 tree t = lto_input_tree (ib, data_in);
1305 VEC_replace (tree, fn->local_decls, i, t);
1309 /* Read all function arguments. We need to re-map them here to the
1310 arguments of the merged function declaration. */
1311 args = lto_input_tree (ib, data_in);
1312 for (oarg = args, narg = DECL_ARGUMENTS (fn_decl);
1313 oarg && narg;
1314 oarg = TREE_CHAIN (oarg), narg = TREE_CHAIN (narg))
1316 unsigned ix;
1317 bool res;
1318 res = lto_streamer_cache_lookup (data_in->reader_cache, oarg, &ix);
1319 gcc_assert (res);
1320 /* Replace the argument in the streamer cache. */
1321 lto_streamer_cache_insert_at (data_in->reader_cache, narg, ix);
1323 gcc_assert (!oarg && !narg);
1325 /* Read all the SSA names. */
1326 input_ssa_names (ib, data_in, fn);
1328 /* Read the exception handling regions in the function. */
1329 input_eh_regions (ib, data_in, fn);
1331 /* Read the tree of lexical scopes for the function. */
1332 DECL_INITIAL (fn_decl) = lto_input_tree (ib, data_in);
1333 gcc_assert (DECL_INITIAL (fn_decl));
1334 DECL_SAVED_TREE (fn_decl) = NULL_TREE;
1335 node = cgraph_get_create_node (fn_decl);
1337 /* Read all the basic blocks. */
1338 tag = input_record_start (ib);
1339 while (tag)
1341 input_bb (ib, tag, data_in, fn,
1342 node->count_materialization_scale);
1343 tag = input_record_start (ib);
1346 /* Fix up the call statements that are mentioned in the callgraph
1347 edges. */
1348 set_gimple_stmt_max_uid (cfun, 0);
1349 FOR_ALL_BB (bb)
1351 gimple_stmt_iterator gsi;
1352 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1354 gimple stmt = gsi_stmt (gsi);
1355 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
1358 stmts = (gimple *) xcalloc (gimple_stmt_max_uid (fn), sizeof (gimple));
1359 FOR_ALL_BB (bb)
1361 gimple_stmt_iterator bsi = gsi_start_bb (bb);
1362 while (!gsi_end_p (bsi))
1364 gimple stmt = gsi_stmt (bsi);
1365 /* If we're recompiling LTO objects with debug stmts but
1366 we're not supposed to have debug stmts, remove them now.
1367 We can't remove them earlier because this would cause uid
1368 mismatches in fixups, but we can do it at this point, as
1369 long as debug stmts don't require fixups. */
1370 if (!MAY_HAVE_DEBUG_STMTS && is_gimple_debug (stmt))
1372 gimple_stmt_iterator gsi = bsi;
1373 gsi_next (&bsi);
1374 gsi_remove (&gsi, true);
1376 else
1378 gsi_next (&bsi);
1379 stmts[gimple_uid (stmt)] = stmt;
1384 /* Set the gimple body to the statement sequence in the entry
1385 basic block. FIXME lto, this is fairly hacky. The existence
1386 of a gimple body is used by the cgraph routines, but we should
1387 really use the presence of the CFG. */
1389 edge_iterator ei = ei_start (ENTRY_BLOCK_PTR->succs);
1390 gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest));
1393 fixup_call_stmt_edges (node, stmts);
1394 execute_all_ipa_stmt_fixups (node, stmts);
1396 update_ssa (TODO_update_ssa_only_virtuals);
1397 free_dominance_info (CDI_DOMINATORS);
1398 free_dominance_info (CDI_POST_DOMINATORS);
1399 free (stmts);
1403 /* Read initializer expressions for public statics. DATA_IN is the
1404 file being read. IB is the input block used for reading. */
1406 static void
1407 input_alias_pairs (struct lto_input_block *ib, struct data_in *data_in)
1409 tree var;
1411 clear_line_info (data_in);
1413 var = lto_input_tree (ib, data_in);
1414 while (var)
1416 const char *orig_name, *new_name;
1417 alias_pair *p;
1419 p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
1420 p->decl = var;
1421 p->target = lto_input_tree (ib, data_in);
1423 /* If the target is a static object, we may have registered a
1424 new name for it to avoid clashes between statics coming from
1425 different files. In that case, use the new name. */
1426 orig_name = IDENTIFIER_POINTER (p->target);
1427 new_name = lto_get_decl_name_mapping (data_in->file_data, orig_name);
1428 if (strcmp (orig_name, new_name) != 0)
1429 p->target = get_identifier (new_name);
1431 var = lto_input_tree (ib, data_in);
1436 /* Read the body from DATA for function FN_DECL and fill it in.
1437 FILE_DATA are the global decls and types. SECTION_TYPE is either
1438 LTO_section_function_body or LTO_section_static_initializer. If
1439 section type is LTO_section_function_body, FN must be the decl for
1440 that function. */
1442 static void
1443 lto_read_body (struct lto_file_decl_data *file_data, tree fn_decl,
1444 const char *data, enum lto_section_type section_type)
1446 const struct lto_function_header *header;
1447 struct data_in *data_in;
1448 int32_t cfg_offset;
1449 int32_t main_offset;
1450 int32_t string_offset;
1451 struct lto_input_block ib_cfg;
1452 struct lto_input_block ib_main;
1454 header = (const struct lto_function_header *) data;
1455 cfg_offset = sizeof (struct lto_function_header);
1456 main_offset = cfg_offset + header->cfg_size;
1457 string_offset = main_offset + header->main_size;
1459 LTO_INIT_INPUT_BLOCK (ib_cfg,
1460 data + cfg_offset,
1462 header->cfg_size);
1464 LTO_INIT_INPUT_BLOCK (ib_main,
1465 data + main_offset,
1467 header->main_size);
1469 data_in = lto_data_in_create (file_data, data + string_offset,
1470 header->string_size, NULL);
1472 /* Make sure the file was generated by the exact same compiler. */
1473 lto_check_version (header->lto_header.major_version,
1474 header->lto_header.minor_version);
1476 if (section_type == LTO_section_function_body)
1478 struct function *fn = DECL_STRUCT_FUNCTION (fn_decl);
1479 struct lto_in_decl_state *decl_state;
1480 struct cgraph_node *node = cgraph_get_node (fn_decl);
1482 gcc_checking_assert (node);
1483 push_cfun (fn);
1484 init_tree_ssa (fn);
1486 /* Use the function's decl state. */
1487 decl_state = lto_get_function_in_decl_state (file_data, fn_decl);
1488 gcc_assert (decl_state);
1489 file_data->current_decl_state = decl_state;
1491 input_cfg (&ib_cfg, fn, node->count_materialization_scale);
1493 /* Set up the struct function. */
1494 input_function (fn_decl, data_in, &ib_main);
1496 /* We should now be in SSA. */
1497 cfun->gimple_df->in_ssa_p = true;
1499 /* Restore decl state */
1500 file_data->current_decl_state = file_data->global_decl_state;
1502 pop_cfun ();
1504 else
1506 input_alias_pairs (&ib_main, data_in);
1509 clear_line_info (data_in);
1510 lto_data_in_delete (data_in);
1514 /* Read the body of FN_DECL using DATA. FILE_DATA holds the global
1515 decls and types. */
1517 void
1518 lto_input_function_body (struct lto_file_decl_data *file_data,
1519 tree fn_decl, const char *data)
1521 current_function_decl = fn_decl;
1522 lto_read_body (file_data, fn_decl, data, LTO_section_function_body);
1526 /* Read in VAR_DECL using DATA. FILE_DATA holds the global decls and
1527 types. */
1529 void
1530 lto_input_constructors_and_inits (struct lto_file_decl_data *file_data,
1531 const char *data)
1533 lto_read_body (file_data, NULL, data, LTO_section_static_initializer);
1537 /* Return the resolution for the decl with index INDEX from DATA_IN. */
1539 static enum ld_plugin_symbol_resolution
1540 get_resolution (struct data_in *data_in, unsigned index)
1542 if (data_in->globals_resolution)
1544 ld_plugin_symbol_resolution_t ret;
1545 /* We can have references to not emitted functions in
1546 DECL_FUNCTION_PERSONALITY at least. So we can and have
1547 to indeed return LDPR_UNKNOWN in some cases. */
1548 if (VEC_length (ld_plugin_symbol_resolution_t,
1549 data_in->globals_resolution) <= index)
1550 return LDPR_UNKNOWN;
1551 ret = VEC_index (ld_plugin_symbol_resolution_t,
1552 data_in->globals_resolution,
1553 index);
1554 return ret;
1556 else
1557 /* Delay resolution finding until decl merging. */
1558 return LDPR_UNKNOWN;
1562 /* Unpack all the non-pointer fields of the TS_BASE structure of
1563 expression EXPR from bitpack BP. */
1565 static void
1566 unpack_ts_base_value_fields (struct bitpack_d *bp, tree expr)
1568 /* Note that the code for EXPR has already been unpacked to create EXPR in
1569 lto_materialize_tree. */
1570 if (!TYPE_P (expr))
1572 TREE_SIDE_EFFECTS (expr) = (unsigned) bp_unpack_value (bp, 1);
1573 TREE_CONSTANT (expr) = (unsigned) bp_unpack_value (bp, 1);
1574 TREE_READONLY (expr) = (unsigned) bp_unpack_value (bp, 1);
1576 /* TREE_PUBLIC is used on types to indicate that the type
1577 has a TYPE_CACHED_VALUES vector. This is not streamed out,
1578 so we skip it here. */
1579 TREE_PUBLIC (expr) = (unsigned) bp_unpack_value (bp, 1);
1581 else
1582 bp_unpack_value (bp, 4);
1583 TREE_ADDRESSABLE (expr) = (unsigned) bp_unpack_value (bp, 1);
1584 TREE_THIS_VOLATILE (expr) = (unsigned) bp_unpack_value (bp, 1);
1585 if (DECL_P (expr))
1586 DECL_UNSIGNED (expr) = (unsigned) bp_unpack_value (bp, 1);
1587 else if (TYPE_P (expr))
1588 TYPE_UNSIGNED (expr) = (unsigned) bp_unpack_value (bp, 1);
1589 else
1590 bp_unpack_value (bp, 1);
1591 TREE_ASM_WRITTEN (expr) = (unsigned) bp_unpack_value (bp, 1);
1592 TREE_NO_WARNING (expr) = (unsigned) bp_unpack_value (bp, 1);
1593 TREE_USED (expr) = (unsigned) bp_unpack_value (bp, 1);
1594 TREE_NOTHROW (expr) = (unsigned) bp_unpack_value (bp, 1);
1595 TREE_STATIC (expr) = (unsigned) bp_unpack_value (bp, 1);
1596 TREE_PRIVATE (expr) = (unsigned) bp_unpack_value (bp, 1);
1597 TREE_PROTECTED (expr) = (unsigned) bp_unpack_value (bp, 1);
1598 TREE_DEPRECATED (expr) = (unsigned) bp_unpack_value (bp, 1);
1599 if (TYPE_P (expr))
1601 TYPE_SATURATING (expr) = (unsigned) bp_unpack_value (bp, 1);
1602 TYPE_ADDR_SPACE (expr) = (unsigned) bp_unpack_value (bp, 8);
1604 else if (TREE_CODE (expr) == SSA_NAME)
1605 SSA_NAME_IS_DEFAULT_DEF (expr) = (unsigned) bp_unpack_value (bp, 1);
1606 else
1607 bp_unpack_value (bp, 1);
1611 /* Unpack all the non-pointer fields of the TS_REAL_CST structure of
1612 expression EXPR from bitpack BP. */
1614 static void
1615 unpack_ts_real_cst_value_fields (struct bitpack_d *bp, tree expr)
1617 unsigned i;
1618 REAL_VALUE_TYPE r;
1619 REAL_VALUE_TYPE *rp;
1621 r.cl = (unsigned) bp_unpack_value (bp, 2);
1622 r.decimal = (unsigned) bp_unpack_value (bp, 1);
1623 r.sign = (unsigned) bp_unpack_value (bp, 1);
1624 r.signalling = (unsigned) bp_unpack_value (bp, 1);
1625 r.canonical = (unsigned) bp_unpack_value (bp, 1);
1626 r.uexp = (unsigned) bp_unpack_value (bp, EXP_BITS);
1627 for (i = 0; i < SIGSZ; i++)
1628 r.sig[i] = (unsigned long) bp_unpack_value (bp, HOST_BITS_PER_LONG);
1630 rp = ggc_alloc_real_value ();
1631 memcpy (rp, &r, sizeof (REAL_VALUE_TYPE));
1632 TREE_REAL_CST_PTR (expr) = rp;
1636 /* Unpack all the non-pointer fields of the TS_FIXED_CST structure of
1637 expression EXPR from bitpack BP. */
1639 static void
1640 unpack_ts_fixed_cst_value_fields (struct bitpack_d *bp, tree expr)
1642 struct fixed_value fv;
1644 fv.data.low = (HOST_WIDE_INT) bp_unpack_value (bp, HOST_BITS_PER_WIDE_INT);
1645 fv.data.high = (HOST_WIDE_INT) bp_unpack_value (bp, HOST_BITS_PER_WIDE_INT);
1646 fv.mode = (enum machine_mode) bp_unpack_value (bp, HOST_BITS_PER_INT);
1647 TREE_FIXED_CST (expr) = fv;
1651 /* Unpack all the non-pointer fields of the TS_DECL_COMMON structure
1652 of expression EXPR from bitpack BP. */
1654 static void
1655 unpack_ts_decl_common_value_fields (struct bitpack_d *bp, tree expr)
1657 DECL_MODE (expr) = (enum machine_mode) bp_unpack_value (bp, 8);
1658 DECL_NONLOCAL (expr) = (unsigned) bp_unpack_value (bp, 1);
1659 DECL_VIRTUAL_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1660 DECL_IGNORED_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1661 DECL_ABSTRACT (expr) = (unsigned) bp_unpack_value (bp, 1);
1662 DECL_ARTIFICIAL (expr) = (unsigned) bp_unpack_value (bp, 1);
1663 DECL_USER_ALIGN (expr) = (unsigned) bp_unpack_value (bp, 1);
1664 DECL_PRESERVE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1665 DECL_DEBUG_EXPR_IS_FROM (expr) = (unsigned) bp_unpack_value (bp, 1);
1666 DECL_EXTERNAL (expr) = (unsigned) bp_unpack_value (bp, 1);
1667 DECL_GIMPLE_REG_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1668 DECL_ALIGN (expr) = (unsigned) bp_unpack_value (bp, HOST_BITS_PER_INT);
1670 if (TREE_CODE (expr) == LABEL_DECL)
1672 DECL_ERROR_ISSUED (expr) = (unsigned) bp_unpack_value (bp, 1);
1673 EH_LANDING_PAD_NR (expr) = (int) bp_unpack_value (bp, HOST_BITS_PER_INT);
1675 /* Always assume an initial value of -1 for LABEL_DECL_UID to
1676 force gimple_set_bb to recreate label_to_block_map. */
1677 LABEL_DECL_UID (expr) = -1;
1680 if (TREE_CODE (expr) == FIELD_DECL)
1682 DECL_PACKED (expr) = (unsigned) bp_unpack_value (bp, 1);
1683 DECL_NONADDRESSABLE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1684 expr->decl_common.off_align = bp_unpack_value (bp, 8);
1687 if (TREE_CODE (expr) == RESULT_DECL
1688 || TREE_CODE (expr) == PARM_DECL
1689 || TREE_CODE (expr) == VAR_DECL)
1691 DECL_BY_REFERENCE (expr) = (unsigned) bp_unpack_value (bp, 1);
1692 if (TREE_CODE (expr) == VAR_DECL
1693 || TREE_CODE (expr) == PARM_DECL)
1694 DECL_HAS_VALUE_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1695 DECL_RESTRICTED_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1700 /* Unpack all the non-pointer fields of the TS_DECL_WRTL structure
1701 of expression EXPR from bitpack BP. */
1703 static void
1704 unpack_ts_decl_wrtl_value_fields (struct bitpack_d *bp, tree expr)
1706 DECL_REGISTER (expr) = (unsigned) bp_unpack_value (bp, 1);
1710 /* Unpack all the non-pointer fields of the TS_DECL_WITH_VIS structure
1711 of expression EXPR from bitpack BP. */
1713 static void
1714 unpack_ts_decl_with_vis_value_fields (struct bitpack_d *bp, tree expr)
1716 DECL_DEFER_OUTPUT (expr) = (unsigned) bp_unpack_value (bp, 1);
1717 DECL_COMMON (expr) = (unsigned) bp_unpack_value (bp, 1);
1718 DECL_DLLIMPORT_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1719 DECL_WEAK (expr) = (unsigned) bp_unpack_value (bp, 1);
1720 DECL_SEEN_IN_BIND_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1721 DECL_COMDAT (expr) = (unsigned) bp_unpack_value (bp, 1);
1722 DECL_VISIBILITY (expr) = (enum symbol_visibility) bp_unpack_value (bp, 2);
1723 DECL_VISIBILITY_SPECIFIED (expr) = (unsigned) bp_unpack_value (bp, 1);
1725 if (TREE_CODE (expr) == VAR_DECL)
1727 DECL_HARD_REGISTER (expr) = (unsigned) bp_unpack_value (bp, 1);
1728 DECL_IN_TEXT_SECTION (expr) = (unsigned) bp_unpack_value (bp, 1);
1729 DECL_IN_CONSTANT_POOL (expr) = (unsigned) bp_unpack_value (bp, 1);
1730 DECL_TLS_MODEL (expr) = (enum tls_model) bp_unpack_value (bp, 3);
1733 if (VAR_OR_FUNCTION_DECL_P (expr))
1735 priority_type p;
1736 p = (priority_type) bp_unpack_value (bp, HOST_BITS_PER_SHORT);
1737 SET_DECL_INIT_PRIORITY (expr, p);
1742 /* Unpack all the non-pointer fields of the TS_FUNCTION_DECL structure
1743 of expression EXPR from bitpack BP. */
1745 static void
1746 unpack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
1748 DECL_FUNCTION_CODE (expr) = (enum built_in_function) bp_unpack_value (bp, 11);
1749 DECL_BUILT_IN_CLASS (expr) = (enum built_in_class) bp_unpack_value (bp, 2);
1750 DECL_STATIC_CONSTRUCTOR (expr) = (unsigned) bp_unpack_value (bp, 1);
1751 DECL_STATIC_DESTRUCTOR (expr) = (unsigned) bp_unpack_value (bp, 1);
1752 DECL_UNINLINABLE (expr) = (unsigned) bp_unpack_value (bp, 1);
1753 DECL_POSSIBLY_INLINED (expr) = (unsigned) bp_unpack_value (bp, 1);
1754 DECL_IS_NOVOPS (expr) = (unsigned) bp_unpack_value (bp, 1);
1755 DECL_IS_RETURNS_TWICE (expr) = (unsigned) bp_unpack_value (bp, 1);
1756 DECL_IS_MALLOC (expr) = (unsigned) bp_unpack_value (bp, 1);
1757 DECL_IS_OPERATOR_NEW (expr) = (unsigned) bp_unpack_value (bp, 1);
1758 DECL_DECLARED_INLINE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1759 DECL_STATIC_CHAIN (expr) = (unsigned) bp_unpack_value (bp, 1);
1760 DECL_NO_INLINE_WARNING_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1761 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (expr)
1762 = (unsigned) bp_unpack_value (bp, 1);
1763 DECL_NO_LIMIT_STACK (expr) = (unsigned) bp_unpack_value (bp, 1);
1764 DECL_DISREGARD_INLINE_LIMITS (expr) = (unsigned) bp_unpack_value (bp, 1);
1765 DECL_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1766 DECL_LOOPING_CONST_OR_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1767 if (DECL_STATIC_DESTRUCTOR (expr))
1769 priority_type p = (priority_type) bp_unpack_value (bp, HOST_BITS_PER_SHORT);
1770 SET_DECL_FINI_PRIORITY (expr, p);
1775 /* Unpack all the non-pointer fields of the TS_TYPE_COMMON structure
1776 of expression EXPR from bitpack BP. */
1778 static void
1779 unpack_ts_type_common_value_fields (struct bitpack_d *bp, tree expr)
1781 enum machine_mode mode;
1783 TYPE_PRECISION (expr) = (unsigned) bp_unpack_value (bp, 10);
1784 mode = (enum machine_mode) bp_unpack_value (bp, 8);
1785 SET_TYPE_MODE (expr, mode);
1786 TYPE_STRING_FLAG (expr) = (unsigned) bp_unpack_value (bp, 1);
1787 TYPE_NO_FORCE_BLK (expr) = (unsigned) bp_unpack_value (bp, 1);
1788 TYPE_NEEDS_CONSTRUCTING (expr) = (unsigned) bp_unpack_value (bp, 1);
1789 if (RECORD_OR_UNION_TYPE_P (expr))
1790 TYPE_TRANSPARENT_AGGR (expr) = (unsigned) bp_unpack_value (bp, 1);
1791 TYPE_PACKED (expr) = (unsigned) bp_unpack_value (bp, 1);
1792 TYPE_RESTRICT (expr) = (unsigned) bp_unpack_value (bp, 1);
1793 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (expr)
1794 = (unsigned) bp_unpack_value (bp, 2);
1795 TYPE_USER_ALIGN (expr) = (unsigned) bp_unpack_value (bp, 1);
1796 TYPE_READONLY (expr) = (unsigned) bp_unpack_value (bp, 1);
1797 TYPE_ALIGN (expr) = bp_unpack_var_len_unsigned (bp);
1798 TYPE_ALIAS_SET (expr) = bp_unpack_var_len_int (bp);
1802 /* Unpack all the non-pointer fields of the TS_BLOCK structure
1803 of expression EXPR from bitpack BP. */
1805 static void
1806 unpack_ts_block_value_fields (struct bitpack_d *bp, tree expr)
1808 BLOCK_ABSTRACT (expr) = (unsigned) bp_unpack_value (bp, 1);
1809 BLOCK_NUMBER (expr) = (unsigned) bp_unpack_value (bp, 31);
1812 /* Unpack all the non-pointer fields of the TS_TRANSLATION_UNIT_DECL
1813 structure of expression EXPR from bitpack BP. */
1815 static void
1816 unpack_ts_translation_unit_decl_value_fields (struct bitpack_d *bp ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1820 /* Unpack all the non-pointer fields in EXPR into a bit pack. */
1822 static void
1823 unpack_value_fields (struct bitpack_d *bp, tree expr)
1825 enum tree_code code;
1827 code = TREE_CODE (expr);
1829 /* Note that all these functions are highly sensitive to changes in
1830 the types and sizes of each of the fields being packed. */
1831 unpack_ts_base_value_fields (bp, expr);
1833 if (CODE_CONTAINS_STRUCT (code, TS_REAL_CST))
1834 unpack_ts_real_cst_value_fields (bp, expr);
1836 if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST))
1837 unpack_ts_fixed_cst_value_fields (bp, expr);
1839 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1840 unpack_ts_decl_common_value_fields (bp, expr);
1842 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
1843 unpack_ts_decl_wrtl_value_fields (bp, expr);
1845 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1846 unpack_ts_decl_with_vis_value_fields (bp, expr);
1848 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1849 unpack_ts_function_decl_value_fields (bp, expr);
1851 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
1852 unpack_ts_type_common_value_fields (bp, expr);
1854 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
1855 unpack_ts_block_value_fields (bp, expr);
1857 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
1858 unpack_ts_translation_unit_decl_value_fields (bp, expr);
1860 if (streamer_hooks ()->unpack_value_fields)
1861 streamer_hooks ()->unpack_value_fields (bp, expr);
1865 /* Materialize a new tree from input block IB using descriptors in
1866 DATA_IN. The code for the new tree should match TAG. Store in
1867 *IX_P the index into the reader cache where the new tree is stored. */
1869 static tree
1870 lto_materialize_tree (struct lto_input_block *ib, struct data_in *data_in,
1871 enum LTO_tags tag)
1873 struct bitpack_d bp;
1874 enum tree_code code;
1875 tree result;
1876 #ifdef LTO_STREAMER_DEBUG
1877 HOST_WIDEST_INT orig_address_in_writer;
1878 #endif
1880 result = NULL_TREE;
1882 #ifdef LTO_STREAMER_DEBUG
1883 /* Read the word representing the memory address for the tree
1884 as it was written by the writer. This is useful when
1885 debugging differences between the writer and reader. */
1886 orig_address_in_writer = lto_input_sleb128 (ib);
1887 gcc_assert ((intptr_t) orig_address_in_writer == orig_address_in_writer);
1888 #endif
1890 code = lto_tag_to_tree_code (tag);
1892 /* We should never see an SSA_NAME tree. Only the version numbers of
1893 SSA names are ever written out. See input_ssa_names. */
1894 gcc_assert (code != SSA_NAME);
1896 /* Instantiate a new tree using the header data. */
1897 if (CODE_CONTAINS_STRUCT (code, TS_STRING))
1898 result = input_string_cst (data_in, ib);
1899 else if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
1900 result = input_identifier (data_in, ib);
1901 else if (CODE_CONTAINS_STRUCT (code, TS_VEC))
1903 HOST_WIDE_INT len = lto_input_sleb128 (ib);
1904 result = make_tree_vec (len);
1906 else if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
1908 unsigned HOST_WIDE_INT len = lto_input_uleb128 (ib);
1909 result = make_tree_binfo (len);
1911 else
1913 /* For all other nodes, see if the streamer knows how to allocate
1914 it. */
1915 if (streamer_hooks ()->alloc_tree)
1916 result = streamer_hooks ()->alloc_tree (code, ib, data_in);
1918 /* If the hook did not handle it, materialize the tree with a raw
1919 make_node call. */
1920 if (result == NULL_TREE)
1921 result = make_node (code);
1924 #ifdef LTO_STREAMER_DEBUG
1925 /* Store the original address of the tree as seen by the writer
1926 in RESULT's aux field. This is useful when debugging streaming
1927 problems. This way, a debugging session can be started on
1928 both writer and reader with a breakpoint using this address
1929 value in both. */
1930 lto_orig_address_map (result, (intptr_t) orig_address_in_writer);
1931 #endif
1933 /* Read the bitpack of non-pointer values from IB. */
1934 bp = lto_input_bitpack (ib);
1936 /* The first word in BP contains the code of the tree that we
1937 are about to read. */
1938 code = (enum tree_code) bp_unpack_value (&bp, 16);
1939 lto_tag_check (lto_tree_code_to_tag (code), tag);
1941 /* Unpack all the value fields from BP. */
1942 unpack_value_fields (&bp, result);
1944 /* Enter RESULT in the reader cache. This will make RESULT
1945 available so that circular references in the rest of the tree
1946 structure can be resolved in subsequent calls to lto_input_tree. */
1947 lto_streamer_cache_append (data_in->reader_cache, result);
1949 return result;
1953 /* Read all pointer fields in the TS_COMMON structure of EXPR from input
1954 block IB. DATA_IN contains tables and descriptors for the
1955 file being read. */
1958 static void
1959 lto_input_ts_common_tree_pointers (struct lto_input_block *ib,
1960 struct data_in *data_in, tree expr)
1962 if (TREE_CODE (expr) != IDENTIFIER_NODE)
1963 TREE_TYPE (expr) = lto_input_tree (ib, data_in);
1967 /* Read all pointer fields in the TS_VECTOR structure of EXPR from input
1968 block IB. DATA_IN contains tables and descriptors for the
1969 file being read. */
1971 static void
1972 lto_input_ts_vector_tree_pointers (struct lto_input_block *ib,
1973 struct data_in *data_in, tree expr)
1975 TREE_VECTOR_CST_ELTS (expr) = lto_input_chain (ib, data_in);
1979 /* Read all pointer fields in the TS_COMPLEX structure of EXPR from input
1980 block IB. DATA_IN contains tables and descriptors for the
1981 file being read. */
1983 static void
1984 lto_input_ts_complex_tree_pointers (struct lto_input_block *ib,
1985 struct data_in *data_in, tree expr)
1987 TREE_REALPART (expr) = lto_input_tree (ib, data_in);
1988 TREE_IMAGPART (expr) = lto_input_tree (ib, data_in);
1992 /* Read all pointer fields in the TS_DECL_MINIMAL structure of EXPR
1993 from input block IB. DATA_IN contains tables and descriptors for the
1994 file being read. */
1996 static void
1997 lto_input_ts_decl_minimal_tree_pointers (struct lto_input_block *ib,
1998 struct data_in *data_in, tree expr)
2000 DECL_NAME (expr) = lto_input_tree (ib, data_in);
2001 DECL_CONTEXT (expr) = lto_input_tree (ib, data_in);
2002 DECL_SOURCE_LOCATION (expr) = lto_input_location (ib, data_in);
2006 /* Read all pointer fields in the TS_DECL_COMMON structure of EXPR from
2007 input block IB. DATA_IN contains tables and descriptors for the
2008 file being read. */
2010 static void
2011 lto_input_ts_decl_common_tree_pointers (struct lto_input_block *ib,
2012 struct data_in *data_in, tree expr)
2014 DECL_SIZE (expr) = lto_input_tree (ib, data_in);
2015 DECL_SIZE_UNIT (expr) = lto_input_tree (ib, data_in);
2016 DECL_ATTRIBUTES (expr) = lto_input_tree (ib, data_in);
2018 /* Do not stream DECL_ABSTRACT_ORIGIN. We cannot handle debug information
2019 for early inlining so drop it on the floor instead of ICEing in
2020 dwarf2out.c. */
2022 if (TREE_CODE (expr) == PARM_DECL)
2023 TREE_CHAIN (expr) = lto_input_chain (ib, data_in);
2025 if ((TREE_CODE (expr) == VAR_DECL
2026 || TREE_CODE (expr) == PARM_DECL)
2027 && DECL_HAS_VALUE_EXPR_P (expr))
2028 SET_DECL_VALUE_EXPR (expr, lto_input_tree (ib, data_in));
2030 if (TREE_CODE (expr) == VAR_DECL)
2032 tree dexpr = lto_input_tree (ib, data_in);
2033 if (dexpr)
2034 SET_DECL_DEBUG_EXPR (expr, dexpr);
2039 /* Read all pointer fields in the TS_DECL_NON_COMMON structure of
2040 EXPR from input block IB. DATA_IN contains tables and descriptors for the
2041 file being read. */
2043 static void
2044 lto_input_ts_decl_non_common_tree_pointers (struct lto_input_block *ib,
2045 struct data_in *data_in, tree expr)
2047 if (TREE_CODE (expr) == FUNCTION_DECL)
2049 DECL_ARGUMENTS (expr) = lto_input_tree (ib, data_in);
2050 DECL_RESULT (expr) = lto_input_tree (ib, data_in);
2052 DECL_VINDEX (expr) = lto_input_tree (ib, data_in);
2056 /* Read all pointer fields in the TS_DECL_WITH_VIS structure of EXPR
2057 from input block IB. DATA_IN contains tables and descriptors for the
2058 file being read. */
2060 static void
2061 lto_input_ts_decl_with_vis_tree_pointers (struct lto_input_block *ib,
2062 struct data_in *data_in, tree expr)
2064 tree id;
2066 id = lto_input_tree (ib, data_in);
2067 if (id)
2069 gcc_assert (TREE_CODE (id) == IDENTIFIER_NODE);
2070 SET_DECL_ASSEMBLER_NAME (expr, id);
2073 DECL_SECTION_NAME (expr) = lto_input_tree (ib, data_in);
2074 DECL_COMDAT_GROUP (expr) = lto_input_tree (ib, data_in);
2078 /* Read all pointer fields in the TS_FIELD_DECL structure of EXPR from
2079 input block IB. DATA_IN contains tables and descriptors for the
2080 file being read. */
2082 static void
2083 lto_input_ts_field_decl_tree_pointers (struct lto_input_block *ib,
2084 struct data_in *data_in, tree expr)
2086 DECL_FIELD_OFFSET (expr) = lto_input_tree (ib, data_in);
2087 DECL_BIT_FIELD_TYPE (expr) = lto_input_tree (ib, data_in);
2088 DECL_QUALIFIER (expr) = lto_input_tree (ib, data_in);
2089 DECL_FIELD_BIT_OFFSET (expr) = lto_input_tree (ib, data_in);
2090 DECL_FCONTEXT (expr) = lto_input_tree (ib, data_in);
2091 TREE_CHAIN (expr) = lto_input_chain (ib, data_in);
2095 /* Read all pointer fields in the TS_FUNCTION_DECL structure of EXPR
2096 from input block IB. DATA_IN contains tables and descriptors for the
2097 file being read. */
2099 static void
2100 lto_input_ts_function_decl_tree_pointers (struct lto_input_block *ib,
2101 struct data_in *data_in, tree expr)
2103 /* DECL_STRUCT_FUNCTION is handled by lto_input_function. FIXME lto,
2104 maybe it should be handled here? */
2105 DECL_FUNCTION_PERSONALITY (expr) = lto_input_tree (ib, data_in);
2106 DECL_FUNCTION_SPECIFIC_TARGET (expr) = lto_input_tree (ib, data_in);
2107 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr) = lto_input_tree (ib, data_in);
2109 /* If the file contains a function with an EH personality set,
2110 then it was compiled with -fexceptions. In that case, initialize
2111 the backend EH machinery. */
2112 if (DECL_FUNCTION_PERSONALITY (expr))
2113 lto_init_eh ();
2117 /* Read all pointer fields in the TS_TYPE_COMMON structure of EXPR from
2118 input block IB. DATA_IN contains tables and descriptors for the file
2119 being read. */
2121 static void
2122 lto_input_ts_type_common_tree_pointers (struct lto_input_block *ib,
2123 struct data_in *data_in, tree expr)
2125 TYPE_SIZE (expr) = lto_input_tree (ib, data_in);
2126 TYPE_SIZE_UNIT (expr) = lto_input_tree (ib, data_in);
2127 TYPE_ATTRIBUTES (expr) = lto_input_tree (ib, data_in);
2128 TYPE_NAME (expr) = lto_input_tree (ib, data_in);
2129 /* Do not stream TYPE_POINTER_TO or TYPE_REFERENCE_TO. They will be
2130 reconstructed during fixup. */
2131 /* Do not stream TYPE_NEXT_VARIANT, we reconstruct the variant lists
2132 during fixup. */
2133 TYPE_MAIN_VARIANT (expr) = lto_input_tree (ib, data_in);
2134 TYPE_CONTEXT (expr) = lto_input_tree (ib, data_in);
2135 /* TYPE_CANONICAL gets re-computed during type merging. */
2136 TYPE_CANONICAL (expr) = NULL_TREE;
2137 TYPE_STUB_DECL (expr) = lto_input_tree (ib, data_in);
2140 /* Read all pointer fields in the TS_TYPE_NON_COMMON structure of EXPR
2141 from input block IB. DATA_IN contains tables and descriptors for the
2142 file being read. */
2144 static void
2145 lto_input_ts_type_non_common_tree_pointers (struct lto_input_block *ib,
2146 struct data_in *data_in,
2147 tree expr)
2149 if (TREE_CODE (expr) == ENUMERAL_TYPE)
2150 TYPE_VALUES (expr) = lto_input_tree (ib, data_in);
2151 else if (TREE_CODE (expr) == ARRAY_TYPE)
2152 TYPE_DOMAIN (expr) = lto_input_tree (ib, data_in);
2153 else if (RECORD_OR_UNION_TYPE_P (expr))
2154 TYPE_FIELDS (expr) = lto_input_tree (ib, data_in);
2155 else if (TREE_CODE (expr) == FUNCTION_TYPE
2156 || TREE_CODE (expr) == METHOD_TYPE)
2157 TYPE_ARG_TYPES (expr) = lto_input_tree (ib, data_in);
2159 if (!POINTER_TYPE_P (expr))
2160 TYPE_MINVAL (expr) = lto_input_tree (ib, data_in);
2161 TYPE_MAXVAL (expr) = lto_input_tree (ib, data_in);
2162 if (RECORD_OR_UNION_TYPE_P (expr))
2163 TYPE_BINFO (expr) = lto_input_tree (ib, data_in);
2167 /* Read all pointer fields in the TS_LIST structure of EXPR from input
2168 block IB. DATA_IN contains tables and descriptors for the
2169 file being read. */
2171 static void
2172 lto_input_ts_list_tree_pointers (struct lto_input_block *ib,
2173 struct data_in *data_in, tree expr)
2175 TREE_PURPOSE (expr) = lto_input_tree (ib, data_in);
2176 TREE_VALUE (expr) = lto_input_tree (ib, data_in);
2177 TREE_CHAIN (expr) = lto_input_chain (ib, data_in);
2181 /* Read all pointer fields in the TS_VEC structure of EXPR from input
2182 block IB. DATA_IN contains tables and descriptors for the
2183 file being read. */
2185 static void
2186 lto_input_ts_vec_tree_pointers (struct lto_input_block *ib,
2187 struct data_in *data_in, tree expr)
2189 int i;
2191 /* Note that TREE_VEC_LENGTH was read by lto_materialize_tree to
2192 instantiate EXPR. */
2193 for (i = 0; i < TREE_VEC_LENGTH (expr); i++)
2194 TREE_VEC_ELT (expr, i) = lto_input_tree (ib, data_in);
2198 /* Read all pointer fields in the TS_EXP structure of EXPR from input
2199 block IB. DATA_IN contains tables and descriptors for the
2200 file being read. */
2203 static void
2204 lto_input_ts_exp_tree_pointers (struct lto_input_block *ib,
2205 struct data_in *data_in, tree expr)
2207 int i, length;
2208 location_t loc;
2210 length = lto_input_sleb128 (ib);
2211 gcc_assert (length == TREE_OPERAND_LENGTH (expr));
2213 for (i = 0; i < length; i++)
2214 TREE_OPERAND (expr, i) = lto_input_tree (ib, data_in);
2216 loc = lto_input_location (ib, data_in);
2217 SET_EXPR_LOCATION (expr, loc);
2218 TREE_BLOCK (expr) = lto_input_tree (ib, data_in);
2222 /* Read all pointer fields in the TS_BLOCK structure of EXPR from input
2223 block IB. DATA_IN contains tables and descriptors for the
2224 file being read. */
2226 static void
2227 lto_input_ts_block_tree_pointers (struct lto_input_block *ib,
2228 struct data_in *data_in, tree expr)
2230 /* Do not stream BLOCK_SOURCE_LOCATION. We cannot handle debug information
2231 for early inlining so drop it on the floor instead of ICEing in
2232 dwarf2out.c. */
2233 BLOCK_VARS (expr) = lto_input_chain (ib, data_in);
2235 /* Do not stream BLOCK_NONLOCALIZED_VARS. We cannot handle debug information
2236 for early inlining so drop it on the floor instead of ICEing in
2237 dwarf2out.c. */
2239 BLOCK_SUPERCONTEXT (expr) = lto_input_tree (ib, data_in);
2240 /* Do not stream BLOCK_ABSTRACT_ORIGIN. We cannot handle debug information
2241 for early inlining so drop it on the floor instead of ICEing in
2242 dwarf2out.c. */
2243 BLOCK_FRAGMENT_ORIGIN (expr) = lto_input_tree (ib, data_in);
2244 BLOCK_FRAGMENT_CHAIN (expr) = lto_input_tree (ib, data_in);
2245 /* We re-compute BLOCK_SUBBLOCKS of our parent here instead
2246 of streaming it. For non-BLOCK BLOCK_SUPERCONTEXTs we still
2247 stream the child relationship explicitly. */
2248 if (BLOCK_SUPERCONTEXT (expr)
2249 && TREE_CODE (BLOCK_SUPERCONTEXT (expr)) == BLOCK)
2251 BLOCK_CHAIN (expr) = BLOCK_SUBBLOCKS (BLOCK_SUPERCONTEXT (expr));
2252 BLOCK_SUBBLOCKS (BLOCK_SUPERCONTEXT (expr)) = expr;
2254 /* The global block is rooted at the TU decl. Hook it here to
2255 avoid the need to stream in this block during WPA time. */
2256 else if (BLOCK_SUPERCONTEXT (expr)
2257 && TREE_CODE (BLOCK_SUPERCONTEXT (expr)) == TRANSLATION_UNIT_DECL)
2258 DECL_INITIAL (BLOCK_SUPERCONTEXT (expr)) = expr;
2259 /* The function-level block is connected at the time we read in
2260 function bodies for the same reason. */
2264 /* Read all pointer fields in the TS_BINFO structure of EXPR from input
2265 block IB. DATA_IN contains tables and descriptors for the
2266 file being read. */
2268 static void
2269 lto_input_ts_binfo_tree_pointers (struct lto_input_block *ib,
2270 struct data_in *data_in, tree expr)
2272 unsigned i, len;
2273 tree t;
2275 /* Note that the number of slots in EXPR was read in
2276 lto_materialize_tree when instantiating EXPR. However, the
2277 vector is empty so we cannot rely on VEC_length to know how many
2278 elements to read. So, this list is emitted as a 0-terminated
2279 list on the writer side. */
2282 t = lto_input_tree (ib, data_in);
2283 if (t)
2284 VEC_quick_push (tree, BINFO_BASE_BINFOS (expr), t);
2286 while (t);
2288 BINFO_OFFSET (expr) = lto_input_tree (ib, data_in);
2289 BINFO_VTABLE (expr) = lto_input_tree (ib, data_in);
2290 BINFO_VIRTUALS (expr) = lto_input_tree (ib, data_in);
2291 BINFO_VPTR_FIELD (expr) = lto_input_tree (ib, data_in);
2293 len = lto_input_uleb128 (ib);
2294 if (len > 0)
2296 VEC_reserve_exact (tree, gc, BINFO_BASE_ACCESSES (expr), len);
2297 for (i = 0; i < len; i++)
2299 tree a = lto_input_tree (ib, data_in);
2300 VEC_quick_push (tree, BINFO_BASE_ACCESSES (expr), a);
2304 BINFO_INHERITANCE_CHAIN (expr) = lto_input_tree (ib, data_in);
2305 BINFO_SUBVTT_INDEX (expr) = lto_input_tree (ib, data_in);
2306 BINFO_VPTR_INDEX (expr) = lto_input_tree (ib, data_in);
2310 /* Read all pointer fields in the TS_CONSTRUCTOR structure of EXPR from
2311 input block IB. DATA_IN contains tables and descriptors for the
2312 file being read. */
2314 static void
2315 lto_input_ts_constructor_tree_pointers (struct lto_input_block *ib,
2316 struct data_in *data_in, tree expr)
2318 unsigned i, len;
2320 len = lto_input_uleb128 (ib);
2321 for (i = 0; i < len; i++)
2323 tree index, value;
2325 index = lto_input_tree (ib, data_in);
2326 value = lto_input_tree (ib, data_in);
2327 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (expr), index, value);
2332 /* Input a TS_TARGET_OPTION tree from IB into EXPR. */
2334 static void
2335 lto_input_ts_target_option (struct lto_input_block *ib, tree expr)
2337 unsigned i, len;
2338 struct bitpack_d bp;
2339 struct cl_target_option *t = TREE_TARGET_OPTION (expr);
2341 bp = lto_input_bitpack (ib);
2342 len = sizeof (struct cl_target_option);
2343 for (i = 0; i < len; i++)
2344 ((unsigned char *)t)[i] = bp_unpack_value (&bp, 8);
2345 if (bp_unpack_value (&bp, 32) != 0x12345678)
2346 fatal_error ("cl_target_option size mismatch in LTO reader and writer");
2349 /* Input a TS_TRANSLATION_UNIT_DECL tree from IB and DATA_IN into EXPR. */
2351 static void
2352 lto_input_ts_translation_unit_decl_tree_pointers (struct lto_input_block *ib,
2353 struct data_in *data_in,
2354 tree expr)
2356 TRANSLATION_UNIT_LANGUAGE (expr) = xstrdup (lto_input_string (data_in, ib));
2357 VEC_safe_push (tree, gc, all_translation_units, expr);
2360 /* Helper for lto_input_tree. Read all pointer fields in EXPR from
2361 input block IB. DATA_IN contains tables and descriptors for the
2362 file being read. */
2364 static void
2365 lto_input_tree_pointers (struct lto_input_block *ib, struct data_in *data_in,
2366 tree expr)
2368 enum tree_code code;
2370 code = TREE_CODE (expr);
2372 if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
2373 lto_input_ts_common_tree_pointers (ib, data_in, expr);
2375 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
2376 lto_input_ts_vector_tree_pointers (ib, data_in, expr);
2378 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
2379 lto_input_ts_complex_tree_pointers (ib, data_in, expr);
2381 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
2382 lto_input_ts_decl_minimal_tree_pointers (ib, data_in, expr);
2384 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
2385 lto_input_ts_decl_common_tree_pointers (ib, data_in, expr);
2387 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
2388 lto_input_ts_decl_non_common_tree_pointers (ib, data_in, expr);
2390 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
2391 lto_input_ts_decl_with_vis_tree_pointers (ib, data_in, expr);
2393 if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
2394 lto_input_ts_field_decl_tree_pointers (ib, data_in, expr);
2396 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
2397 lto_input_ts_function_decl_tree_pointers (ib, data_in, expr);
2399 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
2400 lto_input_ts_type_common_tree_pointers (ib, data_in, expr);
2402 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
2403 lto_input_ts_type_non_common_tree_pointers (ib, data_in, expr);
2405 if (CODE_CONTAINS_STRUCT (code, TS_LIST))
2406 lto_input_ts_list_tree_pointers (ib, data_in, expr);
2408 if (CODE_CONTAINS_STRUCT (code, TS_VEC))
2409 lto_input_ts_vec_tree_pointers (ib, data_in, expr);
2411 if (CODE_CONTAINS_STRUCT (code, TS_EXP))
2412 lto_input_ts_exp_tree_pointers (ib, data_in, expr);
2414 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
2415 lto_input_ts_block_tree_pointers (ib, data_in, expr);
2417 if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
2418 lto_input_ts_binfo_tree_pointers (ib, data_in, expr);
2420 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
2421 lto_input_ts_constructor_tree_pointers (ib, data_in, expr);
2423 if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION))
2424 lto_input_ts_target_option (ib, expr);
2426 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
2427 lto_input_ts_translation_unit_decl_tree_pointers (ib, data_in, expr);
2431 /* Register DECL with the global symbol table and change its
2432 name if necessary to avoid name clashes for static globals across
2433 different files. */
2435 static void
2436 lto_register_var_decl_in_symtab (struct data_in *data_in, tree decl)
2438 tree context;
2440 /* Variable has file scope, not local. Need to ensure static variables
2441 between different files don't clash unexpectedly. */
2442 if (!TREE_PUBLIC (decl)
2443 && !((context = decl_function_context (decl))
2444 && auto_var_in_fn_p (decl, context)))
2446 /* ??? We normally pre-mangle names before we serialize them
2447 out. Here, in lto1, we do not know the language, and
2448 thus cannot do the mangling again. Instead, we just
2449 append a suffix to the mangled name. The resulting name,
2450 however, is not a properly-formed mangled name, and will
2451 confuse any attempt to unmangle it. */
2452 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2453 char *label;
2455 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
2456 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (label));
2457 rest_of_decl_compilation (decl, 1, 0);
2459 VEC_safe_push (tree, gc, lto_global_var_decls, decl);
2462 /* If this variable has already been declared, queue the
2463 declaration for merging. */
2464 if (TREE_PUBLIC (decl))
2466 unsigned ix;
2467 if (!lto_streamer_cache_lookup (data_in->reader_cache, decl, &ix))
2468 gcc_unreachable ();
2469 lto_symtab_register_decl (decl, get_resolution (data_in, ix),
2470 data_in->file_data);
2476 /* Register DECL with the global symbol table and change its
2477 name if necessary to avoid name clashes for static globals across
2478 different files. DATA_IN contains descriptors and tables for the
2479 file being read. */
2481 static void
2482 lto_register_function_decl_in_symtab (struct data_in *data_in, tree decl)
2484 /* Need to ensure static entities between different files
2485 don't clash unexpectedly. */
2486 if (!TREE_PUBLIC (decl))
2488 /* We must not use the DECL_ASSEMBLER_NAME macro here, as it
2489 may set the assembler name where it was previously empty. */
2490 tree old_assembler_name = decl->decl_with_vis.assembler_name;
2492 /* FIXME lto: We normally pre-mangle names before we serialize
2493 them out. Here, in lto1, we do not know the language, and
2494 thus cannot do the mangling again. Instead, we just append a
2495 suffix to the mangled name. The resulting name, however, is
2496 not a properly-formed mangled name, and will confuse any
2497 attempt to unmangle it. */
2498 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2499 char *label;
2501 ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
2502 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (label));
2504 /* We may arrive here with the old assembler name not set
2505 if the function body is not needed, e.g., it has been
2506 inlined away and does not appear in the cgraph. */
2507 if (old_assembler_name)
2509 tree new_assembler_name = DECL_ASSEMBLER_NAME (decl);
2511 /* Make the original assembler name available for later use.
2512 We may have used it to indicate the section within its
2513 object file where the function body may be found.
2514 FIXME lto: Find a better way to maintain the function decl
2515 to body section mapping so we don't need this hack. */
2516 lto_record_renamed_decl (data_in->file_data,
2517 IDENTIFIER_POINTER (old_assembler_name),
2518 IDENTIFIER_POINTER (new_assembler_name));
2520 /* Also register the reverse mapping so that we can find the
2521 new name given to an existing assembler name (used when
2522 restoring alias pairs in input_constructors_or_inits. */
2523 lto_record_renamed_decl (data_in->file_data,
2524 IDENTIFIER_POINTER (new_assembler_name),
2525 IDENTIFIER_POINTER (old_assembler_name));
2529 /* If this variable has already been declared, queue the
2530 declaration for merging. */
2531 if (TREE_PUBLIC (decl) && !DECL_ABSTRACT (decl))
2533 unsigned ix;
2534 if (!lto_streamer_cache_lookup (data_in->reader_cache, decl, &ix))
2535 gcc_unreachable ();
2536 lto_symtab_register_decl (decl, get_resolution (data_in, ix),
2537 data_in->file_data);
2542 /* Read an index IX from input block IB and return the tree node at
2543 DATA_IN->FILE_DATA->GLOBALS_INDEX[IX]. */
2545 static tree
2546 lto_get_pickled_tree (struct lto_input_block *ib, struct data_in *data_in)
2548 unsigned HOST_WIDE_INT ix;
2549 tree result;
2550 enum LTO_tags expected_tag;
2552 ix = lto_input_uleb128 (ib);
2553 expected_tag = lto_input_enum (ib, LTO_tags, LTO_NUM_TAGS);
2555 result = lto_streamer_cache_get (data_in->reader_cache, ix);
2556 gcc_assert (result
2557 && TREE_CODE (result) == lto_tag_to_tree_code (expected_tag));
2559 return result;
2563 /* Read a code and class from input block IB and return the
2564 corresponding builtin. DATA_IN is as in lto_input_tree. */
2566 static tree
2567 lto_get_builtin_tree (struct lto_input_block *ib, struct data_in *data_in)
2569 enum built_in_class fclass;
2570 enum built_in_function fcode;
2571 const char *asmname;
2572 tree result;
2574 fclass = (enum built_in_class) lto_input_uleb128 (ib);
2575 gcc_assert (fclass == BUILT_IN_NORMAL || fclass == BUILT_IN_MD);
2577 fcode = (enum built_in_function) lto_input_uleb128 (ib);
2579 if (fclass == BUILT_IN_NORMAL)
2581 gcc_assert (fcode < END_BUILTINS);
2582 result = built_in_decls[fcode];
2583 gcc_assert (result);
2585 else if (fclass == BUILT_IN_MD)
2587 result = targetm.builtin_decl (fcode, true);
2588 if (!result || result == error_mark_node)
2589 fatal_error ("target specific builtin not available");
2591 else
2592 gcc_unreachable ();
2594 asmname = lto_input_string (data_in, ib);
2595 if (asmname)
2596 set_builtin_user_assembler_name (result, asmname);
2598 lto_streamer_cache_append (data_in->reader_cache, result);
2600 return result;
2604 /* Read the physical representation of a tree node with tag TAG from
2605 input block IB using the per-file context in DATA_IN. */
2607 static tree
2608 lto_read_tree (struct lto_input_block *ib, struct data_in *data_in,
2609 enum LTO_tags tag)
2611 tree result;
2613 result = lto_materialize_tree (ib, data_in, tag);
2615 /* Read all the pointer fields in RESULT. */
2616 lto_input_tree_pointers (ib, data_in, result);
2618 /* Call back into the streaming module to read anything else it
2619 may need. */
2620 if (streamer_hooks ()->read_tree)
2621 streamer_hooks ()->read_tree (ib, data_in, result);
2623 /* We should never try to instantiate an MD or NORMAL builtin here. */
2624 if (TREE_CODE (result) == FUNCTION_DECL)
2625 gcc_assert (!lto_stream_as_builtin_p (result));
2627 if (streamer_hooks ()->register_decls_in_symtab_p)
2629 if (TREE_CODE (result) == VAR_DECL)
2630 lto_register_var_decl_in_symtab (data_in, result);
2631 else if (TREE_CODE (result) == FUNCTION_DECL && !DECL_BUILT_IN (result))
2632 lto_register_function_decl_in_symtab (data_in, result);
2635 /* end_marker = */ lto_input_1_unsigned (ib);
2637 #ifdef LTO_STREAMER_DEBUG
2638 /* Remove the mapping to RESULT's original address set by
2639 lto_materialize_tree. */
2640 lto_orig_address_remove (result);
2641 #endif
2643 return result;
2647 /* LTO streamer hook for reading GIMPLE trees. IB and DATA_IN are as in
2648 lto_read_tree. EXPR is the tree was materialized by lto_read_tree and
2649 needs GIMPLE specific data to be filled in. */
2651 void
2652 gimple_streamer_read_tree (struct lto_input_block *ib,
2653 struct data_in *data_in,
2654 tree expr)
2656 if (DECL_P (expr)
2657 && TREE_CODE (expr) != FUNCTION_DECL
2658 && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
2659 DECL_INITIAL (expr) = lto_input_tree (ib, data_in);
2663 /* Read and INTEGER_CST node from input block IB using the per-file
2664 context in DATA_IN. */
2666 static tree
2667 lto_input_integer_cst (struct lto_input_block *ib, struct data_in *data_in)
2669 tree result, type;
2670 HOST_WIDE_INT low, high;
2671 bool overflow_p;
2673 type = lto_input_tree (ib, data_in);
2674 overflow_p = (lto_input_1_unsigned (ib) != 0);
2675 low = lto_input_uleb128 (ib);
2676 high = lto_input_uleb128 (ib);
2677 result = build_int_cst_wide (type, low, high);
2679 /* If the original constant had overflown, build a replica of RESULT to
2680 avoid modifying the shared constant returned by build_int_cst_wide. */
2681 if (overflow_p)
2683 result = copy_node (result);
2684 TREE_OVERFLOW (result) = 1;
2687 return result;
2691 /* Read a tree from input block IB using the per-file context in
2692 DATA_IN. This context is used, for example, to resolve references
2693 to previously read nodes. */
2695 tree
2696 lto_input_tree (struct lto_input_block *ib, struct data_in *data_in)
2698 enum LTO_tags tag;
2699 tree result;
2701 tag = input_record_start (ib);
2702 gcc_assert ((unsigned) tag < (unsigned) LTO_NUM_TAGS);
2704 if (tag == LTO_null)
2705 result = NULL_TREE;
2706 else if (tag >= LTO_field_decl_ref && tag <= LTO_global_decl_ref)
2708 /* If TAG is a reference to an indexable tree, the next value
2709 in IB is the index into the table where we expect to find
2710 that tree. */
2711 result = lto_input_tree_ref (ib, data_in, cfun, tag);
2713 else if (tag == LTO_tree_pickle_reference)
2715 /* If TAG is a reference to a previously read tree, look it up in
2716 the reader cache. */
2717 result = lto_get_pickled_tree (ib, data_in);
2719 else if (tag == LTO_builtin_decl)
2721 /* If we are going to read a built-in function, all we need is
2722 the code and class. */
2723 result = lto_get_builtin_tree (ib, data_in);
2725 else if (tag == lto_tree_code_to_tag (INTEGER_CST))
2727 /* For integer constants we only need the type and its hi/low
2728 words. */
2729 result = lto_input_integer_cst (ib, data_in);
2731 else
2733 /* Otherwise, materialize a new node from IB. */
2734 result = lto_read_tree (ib, data_in, tag);
2737 return result;
2741 /* Initialization for the LTO reader. */
2743 void
2744 lto_reader_init (void)
2746 lto_streamer_init ();
2747 file_name_hash_table = htab_create (37, hash_string_slot_node,
2748 eq_string_slot_node, free);
2749 if (streamer_hooks ()->reader_init)
2750 streamer_hooks ()->reader_init ();
2754 /* GIMPLE streamer hook for initializing the LTO reader. */
2756 void
2757 gimple_streamer_reader_init (void)
2759 memset (&lto_stats, 0, sizeof (lto_stats));
2760 bitmap_obstack_initialize (NULL);
2761 gimple_register_cfg_hooks ();
2765 /* Create a new data_in object for FILE_DATA. STRINGS is the string
2766 table to use with LEN strings. RESOLUTIONS is the vector of linker
2767 resolutions (NULL if not using a linker plugin). */
2769 struct data_in *
2770 lto_data_in_create (struct lto_file_decl_data *file_data, const char *strings,
2771 unsigned len,
2772 VEC(ld_plugin_symbol_resolution_t,heap) *resolutions)
2774 struct data_in *data_in = XCNEW (struct data_in);
2775 data_in->file_data = file_data;
2776 data_in->strings = strings;
2777 data_in->strings_len = len;
2778 data_in->globals_resolution = resolutions;
2779 data_in->reader_cache = lto_streamer_cache_create ();
2781 return data_in;
2785 /* Remove DATA_IN. */
2787 void
2788 lto_data_in_delete (struct data_in *data_in)
2790 VEC_free (ld_plugin_symbol_resolution_t, heap, data_in->globals_resolution);
2791 lto_streamer_cache_delete (data_in->reader_cache);
2792 free (data_in->labels);
2793 free (data_in);