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
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
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/>. */
25 #include "coretypes.h"
34 #include "basic-block.h"
35 #include "tree-flow.h"
36 #include "tree-pass.h"
40 #include "diagnostic.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. */
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. */
66 lto_tag_check_set (enum LTO_tags actual, int ntags, ...)
72 for (i = 0; i < ntags; i++)
73 if ((unsigned) actual == va_arg (ap, unsigned))
80 internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual));
84 /* Check that tag ACTUAL is in the range [TAG1, TAG2]. */
87 lto_tag_check_range (enum LTO_tags actual, enum LTO_tags tag1,
90 if (actual < tag1 || actual > tag2)
91 internal_error ("bytecode stream: tag %s is not in the expected range "
93 lto_tag_name (actual),
99 /* Check that tag ACTUAL == EXPECTED. */
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. */
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. */
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. */
135 input_string_internal (struct data_in *data_in, struct lto_input_block *ib,
138 struct lto_input_block str_tab;
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);
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);
160 /* Read a STRING_CST from the string table in DATA_IN using input
164 input_string_cst (struct data_in *data_in, struct lto_input_block *ib)
168 unsigned int is_null;
170 is_null = lto_input_uleb128 (ib);
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
183 input_identifier (struct data_in *data_in, struct lto_input_block *ib)
187 unsigned int is_null;
189 is_null = lto_input_uleb128 (ib);
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. */
201 lto_input_data_block (struct lto_input_block *ib, void *addr, size_t length)
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. */
214 lto_input_string (struct data_in *data_in, struct lto_input_block *ib)
218 unsigned int is_null;
220 is_null = lto_input_uleb128 (ib);
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");
232 /* Return the next tag in the input block IB. */
235 input_record_start (struct lto_input_block *ib)
237 enum LTO_tags tag = (enum LTO_tags) lto_input_uleb128 (ib);
242 /* Lookup STRING in file_name_hash_table. If found, return the existing
243 string, otherwise insert STRING as the canonical version. */
246 canon_file_name (const char *string)
249 struct string_slot s_slot;
252 slot = htab_find_slot (file_name_hash_table, &s_slot, INSERT);
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;
269 struct string_slot *old_slot = (struct string_slot *) *slot;
275 /* Clear the line info stored in DATA_IN. */
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. */
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. */
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);
341 ix_u = lto_input_uleb128 (ib);
342 result = lto_file_decl_data_get_type (data_in->file_data, ix_u);
345 case LTO_ssa_name_ref:
346 ix_u = lto_input_uleb128 (ib);
347 result = VEC_index (tree, SSANAMES (fn), ix_u);
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);
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);
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);
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);
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);
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,
400 *last_p = first = NULL;
401 tag = input_record_start (ib);
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. */
421 (*last_p)->next_catch = n;
422 n->prev_catch = *last_p;
425 /* Set the head of the list the first time through the loop. */
429 tag = input_record_start (ib);
436 /* Read and return EH region IX from input block IB, using descriptors
440 input_eh_region (struct lto_input_block *ib, struct data_in *data_in, int ix)
445 /* Read the region header. */
446 tag = input_record_start (ib);
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);
463 case LTO_ert_cleanup:
464 r->type = ERT_CLEANUP;
469 struct eh_catch_d *last_catch;
471 r->u.eh_try.first_catch = lto_input_eh_catch_list (ib, data_in,
473 r->u.eh_try.last_catch = last_catch;
477 case LTO_ert_allowed_exceptions:
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));
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);
501 r->landing_pads = (eh_landing_pad) (intptr_t) lto_input_sleb128 (ib);
507 /* Read and return EH landing pad IX from input block IB, using descriptors
510 static eh_landing_pad
511 input_eh_lp (struct lto_input_block *ib, struct data_in *data_in, int ix)
516 /* Read the landing pad header. */
517 tag = input_record_start (ib);
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);
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. */
540 fixup_eh_region_pointers (struct function *fn, HOST_WIDE_INT root_region)
543 VEC(eh_region,gc) *eh_array = fn->eh->region_array;
544 VEC(eh_landing_pad,gc) *lp_array = fn->eh->lp_array;
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. */
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. */
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
591 /* Initialize EH support. */
596 static bool eh_initialized_p = false;
598 if (eh_initialized_p)
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. */
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 ();
617 eh_initialized_p = true;
621 /* Read the exception table for FN from IB using the data descriptors
625 input_eh_regions (struct lto_input_block *ib, struct data_in *data_in,
628 HOST_WIDE_INT i, root_region, len;
631 tag = input_record_start (ib);
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
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);
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);
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);
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);
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);
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
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. */
723 make_new_block (struct function *fn, unsigned int index)
725 basic_block bb = alloc_block ();
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)++;
731 set_bb_seq (bb, gimple_seq_alloc ());
736 /* Read the CFG for function FN from input block IB. */
739 input_cfg (struct lto_input_block *ib, struct function *fn,
740 int count_materialization_scale)
742 unsigned int bb_count;
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);
767 basic_block bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
768 unsigned int edge_count;
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;
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);
794 dest = make_new_block (fn, dest_index);
796 e = make_edge (bb, dest, edge_flags);
797 e->probability = probability;
801 index = lto_input_sleb128 (ib);
804 p_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(fn);
805 index = lto_input_sleb128 (ib);
808 basic_block bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
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. */
821 input_phi (struct lto_input_block *ib, basic_block bb, struct data_in *data_in,
824 unsigned HOST_WIDE_INT ix;
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);
848 for (j = 0; j < len; j++)
849 if (EDGE_PRED (bb, j)->src == sbb)
851 e = EDGE_PRED (bb, j);
855 add_phi_arg (result, def, e, arg_loc);
862 /* Read the SSA names array for function FN from DATA_IN using input
866 input_ssa_names (struct lto_input_block *ib, struct data_in *data_in,
869 unsigned int i, size;
871 size = lto_input_uleb128 (ib);
872 init_ssanames (fn, size);
874 i = lto_input_uleb128 (ib);
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 ());
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. */
899 input_gimple_stmt (struct lto_input_block *ib, struct data_in *data_in,
900 struct function *fn, enum LTO_tags tag)
903 enum gimple_code code;
904 unsigned HOST_WIDE_INT num_ops;
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. */
930 gimple_resx_set_region (stmt, lto_input_sleb128 (ib));
933 case GIMPLE_EH_MUST_NOT_THROW:
934 gimple_eh_must_not_throw_set_fndecl (stmt, lto_input_tree (ib, data_in));
937 case GIMPLE_EH_DISPATCH:
938 gimple_eh_dispatch_set_region (stmt, lto_input_sleb128 (ib));
943 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
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);
962 for (i = 0; i < num_ops; i++)
964 tree op = lto_input_tree (ib, data_in);
965 gimple_set_op (stmt, i, op);
969 /* Fixup FIELD_DECLs in COMPONENT_REFs, they are not handled
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))
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),
996 /* In case of type mismatches across units we can fail
997 to unify some types and thus not find a proper
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)))
1015 inform (DECL_SOURCE_LOCATION
1016 (TYPE_NAME (TREE_TYPE (field))),
1017 "type of field declared here");
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));
1032 TREE_OPERAND (op, 1) = tem;
1035 op = TREE_OPERAND (op, 0);
1041 case GIMPLE_PREDICT:
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
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)
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);
1083 /* Read a basic block with tag TAG from DATA_IN using input block IB.
1084 FN is the function being processed. */
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)
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. */
1112 bsi = gsi_start_bb (bb);
1113 tag = input_record_start (ib);
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);
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. */
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. */
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);
1170 for (node = orig->clones; node != orig;)
1172 fixup_call_stmt_edges_1 (node, stmts);
1174 node = node->clones;
1175 else if (node->next_sibling_clone)
1176 node = node->next_sibling_clone;
1179 while (node != orig && !node->next_sibling_clone)
1180 node = node->clone_of;
1182 node = node->next_sibling_clone;
1187 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
1190 input_function (tree fn_decl, struct data_in *data_in,
1191 struct lto_input_block *ib)
1193 struct function *fn;
1197 struct bitpack_d bp;
1198 struct cgraph_node *node;
1199 tree args, narg, oarg;
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);
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);
1256 oarg = TREE_CHAIN (oarg), narg = TREE_CHAIN (narg))
1260 res = lto_streamer_cache_lookup (data_in->reader_cache, oarg, &ix);
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);
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
1290 set_gimple_stmt_max_uid (cfun, 0);
1293 gimple_stmt_iterator gsi;
1294 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1296 gimple stmt = gsi_stmt (gsi);
1297 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
1300 stmts = (gimple *) xcalloc (gimple_stmt_max_uid (fn), sizeof (gimple));
1303 gimple_stmt_iterator bsi = gsi_start_bb (bb);
1304 while (!gsi_end_p (bsi))
1306 gimple stmt = gsi_stmt (bsi);
1307 /* If we're recompiling LTO objects with debug stmts but
1308 we're not supposed to have debug stmts, remove them now.
1309 We can't remove them earlier because this would cause uid
1310 mismatches in fixups, but we can do it at this point, as
1311 long as debug stmts don't require fixups. */
1312 if (!MAY_HAVE_DEBUG_STMTS && is_gimple_debug (stmt))
1314 gimple_stmt_iterator gsi = bsi;
1316 gsi_remove (&gsi, true);
1321 stmts[gimple_uid (stmt)] = stmt;
1326 /* Set the gimple body to the statement sequence in the entry
1327 basic block. FIXME lto, this is fairly hacky. The existence
1328 of a gimple body is used by the cgraph routines, but we should
1329 really use the presence of the CFG. */
1331 edge_iterator ei = ei_start (ENTRY_BLOCK_PTR->succs);
1332 gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest));
1335 fixup_call_stmt_edges (node, stmts);
1336 execute_all_ipa_stmt_fixups (node, stmts);
1338 update_ssa (TODO_update_ssa_only_virtuals);
1339 free_dominance_info (CDI_DOMINATORS);
1340 free_dominance_info (CDI_POST_DOMINATORS);
1345 /* Read initializer expressions for public statics. DATA_IN is the
1346 file being read. IB is the input block used for reading. */
1349 input_alias_pairs (struct lto_input_block *ib, struct data_in *data_in)
1353 clear_line_info (data_in);
1355 /* Skip over all the unreferenced globals. */
1357 var = lto_input_tree (ib, data_in);
1360 var = lto_input_tree (ib, data_in);
1363 const char *orig_name, *new_name;
1366 p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL);
1368 p->target = lto_input_tree (ib, data_in);
1370 /* If the target is a static object, we may have registered a
1371 new name for it to avoid clashes between statics coming from
1372 different files. In that case, use the new name. */
1373 orig_name = IDENTIFIER_POINTER (p->target);
1374 new_name = lto_get_decl_name_mapping (data_in->file_data, orig_name);
1375 if (strcmp (orig_name, new_name) != 0)
1376 p->target = get_identifier (new_name);
1378 var = lto_input_tree (ib, data_in);
1383 /* Read the body from DATA for function FN_DECL and fill it in.
1384 FILE_DATA are the global decls and types. SECTION_TYPE is either
1385 LTO_section_function_body or LTO_section_static_initializer. If
1386 section type is LTO_section_function_body, FN must be the decl for
1390 lto_read_body (struct lto_file_decl_data *file_data, tree fn_decl,
1391 const char *data, enum lto_section_type section_type)
1393 const struct lto_function_header *header;
1394 struct data_in *data_in;
1396 int32_t main_offset;
1397 int32_t string_offset;
1398 struct lto_input_block ib_cfg;
1399 struct lto_input_block ib_main;
1401 header = (const struct lto_function_header *) data;
1402 cfg_offset = sizeof (struct lto_function_header);
1403 main_offset = cfg_offset + header->cfg_size;
1404 string_offset = main_offset + header->main_size;
1406 LTO_INIT_INPUT_BLOCK (ib_cfg,
1411 LTO_INIT_INPUT_BLOCK (ib_main,
1416 data_in = lto_data_in_create (file_data, data + string_offset,
1417 header->string_size, NULL);
1419 /* Make sure the file was generated by the exact same compiler. */
1420 lto_check_version (header->lto_header.major_version,
1421 header->lto_header.minor_version);
1423 if (section_type == LTO_section_function_body)
1425 struct function *fn = DECL_STRUCT_FUNCTION (fn_decl);
1426 struct lto_in_decl_state *decl_state;
1427 struct cgraph_node *node = cgraph_node (fn_decl);
1432 /* Use the function's decl state. */
1433 decl_state = lto_get_function_in_decl_state (file_data, fn_decl);
1434 gcc_assert (decl_state);
1435 file_data->current_decl_state = decl_state;
1437 input_cfg (&ib_cfg, fn, node->count_materialization_scale);
1439 /* Set up the struct function. */
1440 input_function (fn_decl, data_in, &ib_main);
1442 /* We should now be in SSA. */
1443 cfun->gimple_df->in_ssa_p = true;
1445 /* Restore decl state */
1446 file_data->current_decl_state = file_data->global_decl_state;
1452 input_alias_pairs (&ib_main, data_in);
1455 clear_line_info (data_in);
1456 lto_data_in_delete (data_in);
1460 /* Read the body of FN_DECL using DATA. FILE_DATA holds the global
1464 lto_input_function_body (struct lto_file_decl_data *file_data,
1465 tree fn_decl, const char *data)
1467 current_function_decl = fn_decl;
1468 lto_read_body (file_data, fn_decl, data, LTO_section_function_body);
1472 /* Read in VAR_DECL using DATA. FILE_DATA holds the global decls and
1476 lto_input_constructors_and_inits (struct lto_file_decl_data *file_data,
1479 lto_read_body (file_data, NULL, data, LTO_section_static_initializer);
1483 /* Return the resolution for the decl with index INDEX from DATA_IN. */
1485 static enum ld_plugin_symbol_resolution
1486 get_resolution (struct data_in *data_in, unsigned index)
1488 if (data_in->globals_resolution)
1490 ld_plugin_symbol_resolution_t ret;
1491 /* We can have references to not emitted functions in
1492 DECL_FUNCTION_PERSONALITY at least. So we can and have
1493 to indeed return LDPR_UNKNOWN in some cases. */
1494 if (VEC_length (ld_plugin_symbol_resolution_t,
1495 data_in->globals_resolution) <= index)
1496 return LDPR_UNKNOWN;
1497 ret = VEC_index (ld_plugin_symbol_resolution_t,
1498 data_in->globals_resolution,
1503 /* Delay resolution finding until decl merging. */
1504 return LDPR_UNKNOWN;
1508 /* Unpack all the non-pointer fields of the TS_BASE structure of
1509 expression EXPR from bitpack BP. */
1512 unpack_ts_base_value_fields (struct bitpack_d *bp, tree expr)
1514 /* Note that the code for EXPR has already been unpacked to create EXPR in
1515 lto_materialize_tree. */
1518 TREE_SIDE_EFFECTS (expr) = (unsigned) bp_unpack_value (bp, 1);
1519 TREE_CONSTANT (expr) = (unsigned) bp_unpack_value (bp, 1);
1520 TREE_READONLY (expr) = (unsigned) bp_unpack_value (bp, 1);
1522 /* TREE_PUBLIC is used on types to indicate that the type
1523 has a TYPE_CACHED_VALUES vector. This is not streamed out,
1524 so we skip it here. */
1525 TREE_PUBLIC (expr) = (unsigned) bp_unpack_value (bp, 1);
1528 bp_unpack_value (bp, 4);
1529 TREE_ADDRESSABLE (expr) = (unsigned) bp_unpack_value (bp, 1);
1530 TREE_THIS_VOLATILE (expr) = (unsigned) bp_unpack_value (bp, 1);
1532 DECL_UNSIGNED (expr) = (unsigned) bp_unpack_value (bp, 1);
1533 else if (TYPE_P (expr))
1534 TYPE_UNSIGNED (expr) = (unsigned) bp_unpack_value (bp, 1);
1536 bp_unpack_value (bp, 1);
1537 TREE_ASM_WRITTEN (expr) = (unsigned) bp_unpack_value (bp, 1);
1538 TREE_NO_WARNING (expr) = (unsigned) bp_unpack_value (bp, 1);
1539 TREE_USED (expr) = (unsigned) bp_unpack_value (bp, 1);
1540 TREE_NOTHROW (expr) = (unsigned) bp_unpack_value (bp, 1);
1541 TREE_STATIC (expr) = (unsigned) bp_unpack_value (bp, 1);
1542 TREE_PRIVATE (expr) = (unsigned) bp_unpack_value (bp, 1);
1543 TREE_PROTECTED (expr) = (unsigned) bp_unpack_value (bp, 1);
1544 TREE_DEPRECATED (expr) = (unsigned) bp_unpack_value (bp, 1);
1546 TYPE_SATURATING (expr) = (unsigned) bp_unpack_value (bp, 1);
1547 else if (TREE_CODE (expr) == SSA_NAME)
1548 SSA_NAME_IS_DEFAULT_DEF (expr) = (unsigned) bp_unpack_value (bp, 1);
1550 bp_unpack_value (bp, 1);
1554 /* Unpack all the non-pointer fields of the TS_REAL_CST structure of
1555 expression EXPR from bitpack BP. */
1558 unpack_ts_real_cst_value_fields (struct bitpack_d *bp, tree expr)
1562 REAL_VALUE_TYPE *rp;
1564 r.cl = (unsigned) bp_unpack_value (bp, 2);
1565 r.decimal = (unsigned) bp_unpack_value (bp, 1);
1566 r.sign = (unsigned) bp_unpack_value (bp, 1);
1567 r.signalling = (unsigned) bp_unpack_value (bp, 1);
1568 r.canonical = (unsigned) bp_unpack_value (bp, 1);
1569 r.uexp = (unsigned) bp_unpack_value (bp, EXP_BITS);
1570 for (i = 0; i < SIGSZ; i++)
1571 r.sig[i] = (unsigned long) bp_unpack_value (bp, HOST_BITS_PER_LONG);
1573 rp = ggc_alloc_real_value ();
1574 memcpy (rp, &r, sizeof (REAL_VALUE_TYPE));
1575 TREE_REAL_CST_PTR (expr) = rp;
1579 /* Unpack all the non-pointer fields of the TS_FIXED_CST structure of
1580 expression EXPR from bitpack BP. */
1583 unpack_ts_fixed_cst_value_fields (struct bitpack_d *bp, tree expr)
1585 struct fixed_value fv;
1587 fv.data.low = (HOST_WIDE_INT) bp_unpack_value (bp, HOST_BITS_PER_WIDE_INT);
1588 fv.data.high = (HOST_WIDE_INT) bp_unpack_value (bp, HOST_BITS_PER_WIDE_INT);
1589 fv.mode = (enum machine_mode) bp_unpack_value (bp, HOST_BITS_PER_INT);
1590 TREE_FIXED_CST (expr) = fv;
1594 /* Unpack all the non-pointer fields of the TS_DECL_COMMON structure
1595 of expression EXPR from bitpack BP. */
1598 unpack_ts_decl_common_value_fields (struct bitpack_d *bp, tree expr)
1600 DECL_MODE (expr) = (enum machine_mode) bp_unpack_value (bp, 8);
1601 DECL_NONLOCAL (expr) = (unsigned) bp_unpack_value (bp, 1);
1602 DECL_VIRTUAL_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1603 DECL_IGNORED_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1604 DECL_ABSTRACT (expr) = (unsigned) bp_unpack_value (bp, 1);
1605 DECL_ARTIFICIAL (expr) = (unsigned) bp_unpack_value (bp, 1);
1606 DECL_USER_ALIGN (expr) = (unsigned) bp_unpack_value (bp, 1);
1607 DECL_PRESERVE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1608 DECL_DEBUG_EXPR_IS_FROM (expr) = (unsigned) bp_unpack_value (bp, 1);
1609 DECL_EXTERNAL (expr) = (unsigned) bp_unpack_value (bp, 1);
1610 DECL_GIMPLE_REG_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1611 DECL_ALIGN (expr) = (unsigned) bp_unpack_value (bp, HOST_BITS_PER_INT);
1613 if (TREE_CODE (expr) == LABEL_DECL)
1615 DECL_ERROR_ISSUED (expr) = (unsigned) bp_unpack_value (bp, 1);
1616 EH_LANDING_PAD_NR (expr) = (int) bp_unpack_value (bp, HOST_BITS_PER_INT);
1618 /* Always assume an initial value of -1 for LABEL_DECL_UID to
1619 force gimple_set_bb to recreate label_to_block_map. */
1620 LABEL_DECL_UID (expr) = -1;
1623 if (TREE_CODE (expr) == FIELD_DECL)
1625 unsigned HOST_WIDE_INT off_align;
1626 DECL_PACKED (expr) = (unsigned) bp_unpack_value (bp, 1);
1627 DECL_NONADDRESSABLE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1628 off_align = (unsigned HOST_WIDE_INT) bp_unpack_value (bp, 8);
1629 SET_DECL_OFFSET_ALIGN (expr, off_align);
1632 if (TREE_CODE (expr) == RESULT_DECL
1633 || TREE_CODE (expr) == PARM_DECL
1634 || TREE_CODE (expr) == VAR_DECL)
1636 DECL_BY_REFERENCE (expr) = (unsigned) bp_unpack_value (bp, 1);
1637 if (TREE_CODE (expr) == VAR_DECL
1638 || TREE_CODE (expr) == PARM_DECL)
1639 DECL_HAS_VALUE_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1640 DECL_RESTRICTED_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1645 /* Unpack all the non-pointer fields of the TS_DECL_WRTL structure
1646 of expression EXPR from bitpack BP. */
1649 unpack_ts_decl_wrtl_value_fields (struct bitpack_d *bp, tree expr)
1651 DECL_REGISTER (expr) = (unsigned) bp_unpack_value (bp, 1);
1655 /* Unpack all the non-pointer fields of the TS_DECL_WITH_VIS structure
1656 of expression EXPR from bitpack BP. */
1659 unpack_ts_decl_with_vis_value_fields (struct bitpack_d *bp, tree expr)
1661 DECL_DEFER_OUTPUT (expr) = (unsigned) bp_unpack_value (bp, 1);
1662 DECL_COMMON (expr) = (unsigned) bp_unpack_value (bp, 1);
1663 DECL_DLLIMPORT_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1664 DECL_WEAK (expr) = (unsigned) bp_unpack_value (bp, 1);
1665 DECL_SEEN_IN_BIND_EXPR_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1666 DECL_COMDAT (expr) = (unsigned) bp_unpack_value (bp, 1);
1667 DECL_VISIBILITY (expr) = (enum symbol_visibility) bp_unpack_value (bp, 2);
1668 DECL_VISIBILITY_SPECIFIED (expr) = (unsigned) bp_unpack_value (bp, 1);
1670 if (TREE_CODE (expr) == VAR_DECL)
1672 DECL_HARD_REGISTER (expr) = (unsigned) bp_unpack_value (bp, 1);
1673 DECL_IN_TEXT_SECTION (expr) = (unsigned) bp_unpack_value (bp, 1);
1674 DECL_IN_CONSTANT_POOL (expr) = (unsigned) bp_unpack_value (bp, 1);
1675 DECL_TLS_MODEL (expr) = (enum tls_model) bp_unpack_value (bp, 3);
1678 if (VAR_OR_FUNCTION_DECL_P (expr))
1681 p = (priority_type) bp_unpack_value (bp, HOST_BITS_PER_SHORT);
1682 SET_DECL_INIT_PRIORITY (expr, p);
1687 /* Unpack all the non-pointer fields of the TS_FUNCTION_DECL structure
1688 of expression EXPR from bitpack BP. */
1691 unpack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
1693 DECL_FUNCTION_CODE (expr) = (enum built_in_function) bp_unpack_value (bp, 11);
1694 DECL_BUILT_IN_CLASS (expr) = (enum built_in_class) bp_unpack_value (bp, 2);
1695 DECL_STATIC_CONSTRUCTOR (expr) = (unsigned) bp_unpack_value (bp, 1);
1696 DECL_STATIC_DESTRUCTOR (expr) = (unsigned) bp_unpack_value (bp, 1);
1697 DECL_UNINLINABLE (expr) = (unsigned) bp_unpack_value (bp, 1);
1698 DECL_POSSIBLY_INLINED (expr) = (unsigned) bp_unpack_value (bp, 1);
1699 DECL_IS_NOVOPS (expr) = (unsigned) bp_unpack_value (bp, 1);
1700 DECL_IS_RETURNS_TWICE (expr) = (unsigned) bp_unpack_value (bp, 1);
1701 DECL_IS_MALLOC (expr) = (unsigned) bp_unpack_value (bp, 1);
1702 DECL_IS_OPERATOR_NEW (expr) = (unsigned) bp_unpack_value (bp, 1);
1703 DECL_DECLARED_INLINE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1704 DECL_STATIC_CHAIN (expr) = (unsigned) bp_unpack_value (bp, 1);
1705 DECL_NO_INLINE_WARNING_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1706 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (expr)
1707 = (unsigned) bp_unpack_value (bp, 1);
1708 DECL_NO_LIMIT_STACK (expr) = (unsigned) bp_unpack_value (bp, 1);
1709 DECL_DISREGARD_INLINE_LIMITS (expr) = (unsigned) bp_unpack_value (bp, 1);
1710 DECL_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1711 DECL_LOOPING_CONST_OR_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
1712 if (DECL_STATIC_DESTRUCTOR (expr))
1714 priority_type p = (priority_type) bp_unpack_value (bp, HOST_BITS_PER_SHORT);
1715 SET_DECL_FINI_PRIORITY (expr, p);
1720 /* Unpack all the non-pointer fields of the TS_TYPE structure
1721 of expression EXPR from bitpack BP. */
1724 unpack_ts_type_value_fields (struct bitpack_d *bp, tree expr)
1726 enum machine_mode mode;
1728 TYPE_PRECISION (expr) = (unsigned) bp_unpack_value (bp, 10);
1729 mode = (enum machine_mode) bp_unpack_value (bp, 8);
1730 SET_TYPE_MODE (expr, mode);
1731 TYPE_STRING_FLAG (expr) = (unsigned) bp_unpack_value (bp, 1);
1732 TYPE_NO_FORCE_BLK (expr) = (unsigned) bp_unpack_value (bp, 1);
1733 TYPE_NEEDS_CONSTRUCTING (expr) = (unsigned) bp_unpack_value (bp, 1);
1734 if (RECORD_OR_UNION_TYPE_P (expr))
1735 TYPE_TRANSPARENT_AGGR (expr) = (unsigned) bp_unpack_value (bp, 1);
1736 TYPE_PACKED (expr) = (unsigned) bp_unpack_value (bp, 1);
1737 TYPE_RESTRICT (expr) = (unsigned) bp_unpack_value (bp, 1);
1738 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (expr)
1739 = (unsigned) bp_unpack_value (bp, 2);
1740 TYPE_USER_ALIGN (expr) = (unsigned) bp_unpack_value (bp, 1);
1741 TYPE_READONLY (expr) = (unsigned) bp_unpack_value (bp, 1);
1742 TYPE_ALIGN (expr) = (unsigned) bp_unpack_value (bp, HOST_BITS_PER_INT);
1743 TYPE_ALIAS_SET (expr) = bp_unpack_value (bp, HOST_BITS_PER_INT);
1747 /* Unpack all the non-pointer fields of the TS_BLOCK structure
1748 of expression EXPR from bitpack BP. */
1751 unpack_ts_block_value_fields (struct bitpack_d *bp, tree expr)
1753 BLOCK_ABSTRACT (expr) = (unsigned) bp_unpack_value (bp, 1);
1754 BLOCK_NUMBER (expr) = (unsigned) bp_unpack_value (bp, 31);
1757 /* Unpack all the non-pointer fields of the TS_TRANSLATION_UNIT_DECL
1758 structure of expression EXPR from bitpack BP. */
1761 unpack_ts_translation_unit_decl_value_fields (struct bitpack_d *bp ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1765 /* Unpack all the non-pointer fields in EXPR into a bit pack. */
1768 unpack_value_fields (struct bitpack_d *bp, tree expr)
1770 enum tree_code code;
1772 code = TREE_CODE (expr);
1774 /* Note that all these functions are highly sensitive to changes in
1775 the types and sizes of each of the fields being packed. */
1776 unpack_ts_base_value_fields (bp, expr);
1778 if (CODE_CONTAINS_STRUCT (code, TS_REAL_CST))
1779 unpack_ts_real_cst_value_fields (bp, expr);
1781 if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST))
1782 unpack_ts_fixed_cst_value_fields (bp, expr);
1784 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1785 unpack_ts_decl_common_value_fields (bp, expr);
1787 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
1788 unpack_ts_decl_wrtl_value_fields (bp, expr);
1790 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1791 unpack_ts_decl_with_vis_value_fields (bp, expr);
1793 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1794 unpack_ts_function_decl_value_fields (bp, expr);
1796 if (CODE_CONTAINS_STRUCT (code, TS_TYPE))
1797 unpack_ts_type_value_fields (bp, expr);
1799 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
1800 unpack_ts_block_value_fields (bp, expr);
1802 if (CODE_CONTAINS_STRUCT (code, TS_SSA_NAME))
1804 /* We only stream the version number of SSA names. */
1808 if (CODE_CONTAINS_STRUCT (code, TS_STATEMENT_LIST))
1810 /* This is only used by GENERIC. */
1814 if (CODE_CONTAINS_STRUCT (code, TS_OMP_CLAUSE))
1816 /* This is only used by High GIMPLE. */
1820 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
1821 unpack_ts_translation_unit_decl_value_fields (bp, expr);
1825 /* Materialize a new tree from input block IB using descriptors in
1826 DATA_IN. The code for the new tree should match TAG. Store in
1827 *IX_P the index into the reader cache where the new tree is stored. */
1830 lto_materialize_tree (struct lto_input_block *ib, struct data_in *data_in,
1831 enum LTO_tags tag, int *ix_p)
1833 struct bitpack_d bp;
1834 enum tree_code code;
1836 #ifdef LTO_STREAMER_DEBUG
1837 HOST_WIDEST_INT orig_address_in_writer;
1843 /* Read the header of the node we are about to create. */
1844 ix = lto_input_sleb128 (ib);
1845 gcc_assert ((int) ix == ix);
1848 #ifdef LTO_STREAMER_DEBUG
1849 /* Read the word representing the memory address for the tree
1850 as it was written by the writer. This is useful when
1851 debugging differences between the writer and reader. */
1852 orig_address_in_writer = lto_input_sleb128 (ib);
1853 gcc_assert ((intptr_t) orig_address_in_writer == orig_address_in_writer);
1856 code = lto_tag_to_tree_code (tag);
1858 /* We should never see an SSA_NAME tree. Only the version numbers of
1859 SSA names are ever written out. See input_ssa_names. */
1860 gcc_assert (code != SSA_NAME);
1862 /* Instantiate a new tree using the header data. */
1863 if (CODE_CONTAINS_STRUCT (code, TS_STRING))
1864 result = input_string_cst (data_in, ib);
1865 else if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
1866 result = input_identifier (data_in, ib);
1867 else if (CODE_CONTAINS_STRUCT (code, TS_VEC))
1869 HOST_WIDE_INT len = lto_input_sleb128 (ib);
1870 result = make_tree_vec (len);
1872 else if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
1874 unsigned HOST_WIDE_INT len = lto_input_uleb128 (ib);
1875 result = make_tree_binfo (len);
1879 /* All other nodes can be materialized with a raw make_node
1881 result = make_node (code);
1884 #ifdef LTO_STREAMER_DEBUG
1885 /* Store the original address of the tree as seen by the writer
1886 in RESULT's aux field. This is useful when debugging streaming
1887 problems. This way, a debugging session can be started on
1888 both writer and reader with a breakpoint using this address
1890 lto_orig_address_map (result, (intptr_t) orig_address_in_writer);
1893 /* Read the bitpack of non-pointer values from IB. */
1894 bp = lto_input_bitpack (ib);
1896 /* The first word in BP contains the code of the tree that we
1897 are about to read. */
1898 code = (enum tree_code) bp_unpack_value (&bp, 16);
1899 lto_tag_check (lto_tree_code_to_tag (code), tag);
1901 /* Unpack all the value fields from BP. */
1902 unpack_value_fields (&bp, result);
1904 /* Enter RESULT in the reader cache. This will make RESULT
1905 available so that circular references in the rest of the tree
1906 structure can be resolved in subsequent calls to lto_input_tree. */
1907 lto_streamer_cache_insert_at (data_in->reader_cache, result, ix);
1913 /* Read a chain of tree nodes from input block IB. DATA_IN contains
1914 tables and descriptors for the file being read. */
1917 lto_input_chain (struct lto_input_block *ib, struct data_in *data_in)
1920 tree first, prev, curr;
1922 first = prev = NULL_TREE;
1923 count = lto_input_sleb128 (ib);
1924 for (i = 0; i < count; i++)
1926 curr = lto_input_tree (ib, data_in);
1928 TREE_CHAIN (prev) = curr;
1932 TREE_CHAIN (curr) = NULL_TREE;
1940 /* Read all pointer fields in the TS_COMMON structure of EXPR from input
1941 block IB. DATA_IN contains tables and descriptors for the
1946 lto_input_ts_common_tree_pointers (struct lto_input_block *ib,
1947 struct data_in *data_in, tree expr)
1949 if (TREE_CODE (expr) != IDENTIFIER_NODE)
1950 TREE_TYPE (expr) = lto_input_tree (ib, data_in);
1954 /* Read all pointer fields in the TS_VECTOR structure of EXPR from input
1955 block IB. DATA_IN contains tables and descriptors for the
1959 lto_input_ts_vector_tree_pointers (struct lto_input_block *ib,
1960 struct data_in *data_in, tree expr)
1962 TREE_VECTOR_CST_ELTS (expr) = lto_input_chain (ib, data_in);
1966 /* Read all pointer fields in the TS_COMPLEX structure of EXPR from input
1967 block IB. DATA_IN contains tables and descriptors for the
1971 lto_input_ts_complex_tree_pointers (struct lto_input_block *ib,
1972 struct data_in *data_in, tree expr)
1974 TREE_REALPART (expr) = lto_input_tree (ib, data_in);
1975 TREE_IMAGPART (expr) = lto_input_tree (ib, data_in);
1979 /* Read all pointer fields in the TS_DECL_MINIMAL structure of EXPR
1980 from input block IB. DATA_IN contains tables and descriptors for the
1984 lto_input_ts_decl_minimal_tree_pointers (struct lto_input_block *ib,
1985 struct data_in *data_in, tree expr)
1987 DECL_NAME (expr) = lto_input_tree (ib, data_in);
1988 DECL_CONTEXT (expr) = lto_input_tree (ib, data_in);
1989 DECL_SOURCE_LOCATION (expr) = lto_input_location (ib, data_in);
1993 /* Read all pointer fields in the TS_DECL_COMMON structure of EXPR from
1994 input block IB. DATA_IN contains tables and descriptors for the
1998 lto_input_ts_decl_common_tree_pointers (struct lto_input_block *ib,
1999 struct data_in *data_in, tree expr)
2001 DECL_SIZE (expr) = lto_input_tree (ib, data_in);
2002 DECL_SIZE_UNIT (expr) = lto_input_tree (ib, data_in);
2004 if (TREE_CODE (expr) != FUNCTION_DECL
2005 && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
2006 DECL_INITIAL (expr) = lto_input_tree (ib, data_in);
2008 DECL_ATTRIBUTES (expr) = lto_input_tree (ib, data_in);
2009 /* Do not stream DECL_ABSTRACT_ORIGIN. We cannot handle debug information
2010 for early inlining so drop it on the floor instead of ICEing in
2013 if (TREE_CODE (expr) == PARM_DECL)
2014 TREE_CHAIN (expr) = lto_input_chain (ib, data_in);
2016 if ((TREE_CODE (expr) == VAR_DECL
2017 || TREE_CODE (expr) == PARM_DECL)
2018 && DECL_HAS_VALUE_EXPR_P (expr))
2019 SET_DECL_VALUE_EXPR (expr, lto_input_tree (ib, data_in));
2021 if (TREE_CODE (expr) == VAR_DECL)
2023 tree dexpr = lto_input_tree (ib, data_in);
2025 SET_DECL_DEBUG_EXPR (expr, dexpr);
2030 /* Read all pointer fields in the TS_DECL_NON_COMMON structure of
2031 EXPR from input block IB. DATA_IN contains tables and descriptors for the
2035 lto_input_ts_decl_non_common_tree_pointers (struct lto_input_block *ib,
2036 struct data_in *data_in, tree expr)
2038 if (TREE_CODE (expr) == FUNCTION_DECL)
2040 DECL_ARGUMENTS (expr) = lto_input_tree (ib, data_in);
2041 DECL_RESULT (expr) = lto_input_tree (ib, data_in);
2043 DECL_VINDEX (expr) = lto_input_tree (ib, data_in);
2047 /* Read all pointer fields in the TS_DECL_WITH_VIS structure of EXPR
2048 from input block IB. DATA_IN contains tables and descriptors for the
2052 lto_input_ts_decl_with_vis_tree_pointers (struct lto_input_block *ib,
2053 struct data_in *data_in, tree expr)
2057 id = lto_input_tree (ib, data_in);
2060 gcc_assert (TREE_CODE (id) == IDENTIFIER_NODE);
2061 SET_DECL_ASSEMBLER_NAME (expr, id);
2064 DECL_SECTION_NAME (expr) = lto_input_tree (ib, data_in);
2065 DECL_COMDAT_GROUP (expr) = lto_input_tree (ib, data_in);
2069 /* Read all pointer fields in the TS_FIELD_DECL structure of EXPR from
2070 input block IB. DATA_IN contains tables and descriptors for the
2074 lto_input_ts_field_decl_tree_pointers (struct lto_input_block *ib,
2075 struct data_in *data_in, tree expr)
2077 DECL_FIELD_OFFSET (expr) = lto_input_tree (ib, data_in);
2078 DECL_BIT_FIELD_TYPE (expr) = lto_input_tree (ib, data_in);
2079 DECL_QUALIFIER (expr) = lto_input_tree (ib, data_in);
2080 DECL_FIELD_BIT_OFFSET (expr) = lto_input_tree (ib, data_in);
2081 DECL_FCONTEXT (expr) = lto_input_tree (ib, data_in);
2082 TREE_CHAIN (expr) = lto_input_chain (ib, data_in);
2086 /* Read all pointer fields in the TS_FUNCTION_DECL structure of EXPR
2087 from input block IB. DATA_IN contains tables and descriptors for the
2091 lto_input_ts_function_decl_tree_pointers (struct lto_input_block *ib,
2092 struct data_in *data_in, tree expr)
2094 /* DECL_STRUCT_FUNCTION is handled by lto_input_function. FIXME lto,
2095 maybe it should be handled here? */
2096 DECL_FUNCTION_PERSONALITY (expr) = lto_input_tree (ib, data_in);
2097 DECL_FUNCTION_SPECIFIC_TARGET (expr) = lto_input_tree (ib, data_in);
2098 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr) = lto_input_tree (ib, data_in);
2100 /* If the file contains a function with an EH personality set,
2101 then it was compiled with -fexceptions. In that case, initialize
2102 the backend EH machinery. */
2103 if (DECL_FUNCTION_PERSONALITY (expr))
2108 /* Read all pointer fields in the TS_TYPE structure of EXPR from input
2109 block IB. DATA_IN contains tables and descriptors for the
2113 lto_input_ts_type_tree_pointers (struct lto_input_block *ib,
2114 struct data_in *data_in, tree expr)
2116 if (TREE_CODE (expr) == ENUMERAL_TYPE)
2117 TYPE_VALUES (expr) = lto_input_tree (ib, data_in);
2118 else if (TREE_CODE (expr) == ARRAY_TYPE)
2119 TYPE_DOMAIN (expr) = lto_input_tree (ib, data_in);
2120 else if (RECORD_OR_UNION_TYPE_P (expr))
2121 TYPE_FIELDS (expr) = lto_input_tree (ib, data_in);
2122 else if (TREE_CODE (expr) == FUNCTION_TYPE
2123 || TREE_CODE (expr) == METHOD_TYPE)
2124 TYPE_ARG_TYPES (expr) = lto_input_tree (ib, data_in);
2126 TYPE_SIZE (expr) = lto_input_tree (ib, data_in);
2127 TYPE_SIZE_UNIT (expr) = lto_input_tree (ib, data_in);
2128 TYPE_ATTRIBUTES (expr) = lto_input_tree (ib, data_in);
2129 TYPE_NAME (expr) = lto_input_tree (ib, data_in);
2130 /* Do not stream TYPE_POINTER_TO or TYPE_REFERENCE_TO nor
2131 TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. */
2132 if (!POINTER_TYPE_P (expr))
2133 TYPE_MINVAL (expr) = lto_input_tree (ib, data_in);
2134 TYPE_MAXVAL (expr) = lto_input_tree (ib, data_in);
2135 TYPE_MAIN_VARIANT (expr) = lto_input_tree (ib, data_in);
2136 /* Do not stream TYPE_NEXT_VARIANT, we reconstruct the variant lists
2138 if (RECORD_OR_UNION_TYPE_P (expr))
2139 TYPE_BINFO (expr) = lto_input_tree (ib, data_in);
2140 TYPE_CONTEXT (expr) = lto_input_tree (ib, data_in);
2141 /* TYPE_CANONICAL gets re-computed during type merging. */
2142 TYPE_CANONICAL (expr) = NULL_TREE;
2143 TYPE_STUB_DECL (expr) = lto_input_tree (ib, data_in);
2147 /* Read all pointer fields in the TS_LIST structure of EXPR from input
2148 block IB. DATA_IN contains tables and descriptors for the
2152 lto_input_ts_list_tree_pointers (struct lto_input_block *ib,
2153 struct data_in *data_in, tree expr)
2155 TREE_PURPOSE (expr) = lto_input_tree (ib, data_in);
2156 TREE_VALUE (expr) = lto_input_tree (ib, data_in);
2157 TREE_CHAIN (expr) = lto_input_chain (ib, data_in);
2161 /* Read all pointer fields in the TS_VEC structure of EXPR from input
2162 block IB. DATA_IN contains tables and descriptors for the
2166 lto_input_ts_vec_tree_pointers (struct lto_input_block *ib,
2167 struct data_in *data_in, tree expr)
2171 /* Note that TREE_VEC_LENGTH was read by lto_materialize_tree to
2172 instantiate EXPR. */
2173 for (i = 0; i < TREE_VEC_LENGTH (expr); i++)
2174 TREE_VEC_ELT (expr, i) = lto_input_tree (ib, data_in);
2178 /* Read all pointer fields in the TS_EXP structure of EXPR from input
2179 block IB. DATA_IN contains tables and descriptors for the
2184 lto_input_ts_exp_tree_pointers (struct lto_input_block *ib,
2185 struct data_in *data_in, tree expr)
2190 length = lto_input_sleb128 (ib);
2191 gcc_assert (length == TREE_OPERAND_LENGTH (expr));
2193 for (i = 0; i < length; i++)
2194 TREE_OPERAND (expr, i) = lto_input_tree (ib, data_in);
2196 loc = lto_input_location (ib, data_in);
2197 SET_EXPR_LOCATION (expr, loc);
2198 TREE_BLOCK (expr) = lto_input_tree (ib, data_in);
2202 /* Read all pointer fields in the TS_BLOCK structure of EXPR from input
2203 block IB. DATA_IN contains tables and descriptors for the
2207 lto_input_ts_block_tree_pointers (struct lto_input_block *ib,
2208 struct data_in *data_in, tree expr)
2210 /* Do not stream BLOCK_SOURCE_LOCATION. We cannot handle debug information
2211 for early inlining so drop it on the floor instead of ICEing in
2213 BLOCK_VARS (expr) = lto_input_chain (ib, data_in);
2215 /* Do not stream BLOCK_NONLOCALIZED_VARS. We cannot handle debug information
2216 for early inlining so drop it on the floor instead of ICEing in
2219 BLOCK_SUPERCONTEXT (expr) = lto_input_tree (ib, data_in);
2220 /* Do not stream BLOCK_ABSTRACT_ORIGIN. We cannot handle debug information
2221 for early inlining so drop it on the floor instead of ICEing in
2223 BLOCK_FRAGMENT_ORIGIN (expr) = lto_input_tree (ib, data_in);
2224 BLOCK_FRAGMENT_CHAIN (expr) = lto_input_tree (ib, data_in);
2225 /* We re-compute BLOCK_SUBBLOCKS of our parent here instead
2226 of streaming it. For non-BLOCK BLOCK_SUPERCONTEXTs we still
2227 stream the child relationship explicitly. */
2228 if (BLOCK_SUPERCONTEXT (expr)
2229 && TREE_CODE (BLOCK_SUPERCONTEXT (expr)) == BLOCK)
2231 BLOCK_CHAIN (expr) = BLOCK_SUBBLOCKS (BLOCK_SUPERCONTEXT (expr));
2232 BLOCK_SUBBLOCKS (BLOCK_SUPERCONTEXT (expr)) = expr;
2234 /* The global block is rooted at the TU decl. Hook it here to
2235 avoid the need to stream in this block during WPA time. */
2236 else if (BLOCK_SUPERCONTEXT (expr)
2237 && TREE_CODE (BLOCK_SUPERCONTEXT (expr)) == TRANSLATION_UNIT_DECL)
2238 DECL_INITIAL (BLOCK_SUPERCONTEXT (expr)) = expr;
2239 /* The function-level block is connected at the time we read in
2240 function bodies for the same reason. */
2244 /* Read all pointer fields in the TS_BINFO structure of EXPR from input
2245 block IB. DATA_IN contains tables and descriptors for the
2249 lto_input_ts_binfo_tree_pointers (struct lto_input_block *ib,
2250 struct data_in *data_in, tree expr)
2255 /* Note that the number of slots in EXPR was read in
2256 lto_materialize_tree when instantiating EXPR. However, the
2257 vector is empty so we cannot rely on VEC_length to know how many
2258 elements to read. So, this list is emitted as a 0-terminated
2259 list on the writer side. */
2262 t = lto_input_tree (ib, data_in);
2264 VEC_quick_push (tree, BINFO_BASE_BINFOS (expr), t);
2268 BINFO_OFFSET (expr) = lto_input_tree (ib, data_in);
2269 BINFO_VTABLE (expr) = lto_input_tree (ib, data_in);
2270 BINFO_VIRTUALS (expr) = lto_input_tree (ib, data_in);
2271 BINFO_VPTR_FIELD (expr) = lto_input_tree (ib, data_in);
2273 len = lto_input_uleb128 (ib);
2276 VEC_reserve_exact (tree, gc, BINFO_BASE_ACCESSES (expr), len);
2277 for (i = 0; i < len; i++)
2279 tree a = lto_input_tree (ib, data_in);
2280 VEC_quick_push (tree, BINFO_BASE_ACCESSES (expr), a);
2284 BINFO_INHERITANCE_CHAIN (expr) = lto_input_tree (ib, data_in);
2285 BINFO_SUBVTT_INDEX (expr) = lto_input_tree (ib, data_in);
2286 BINFO_VPTR_INDEX (expr) = lto_input_tree (ib, data_in);
2290 /* Read all pointer fields in the TS_CONSTRUCTOR structure of EXPR from
2291 input block IB. DATA_IN contains tables and descriptors for the
2295 lto_input_ts_constructor_tree_pointers (struct lto_input_block *ib,
2296 struct data_in *data_in, tree expr)
2300 len = lto_input_uleb128 (ib);
2301 for (i = 0; i < len; i++)
2305 index = lto_input_tree (ib, data_in);
2306 value = lto_input_tree (ib, data_in);
2307 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (expr), index, value);
2312 /* Input a TS_TARGET_OPTION tree from IB into EXPR. */
2315 lto_input_ts_target_option (struct lto_input_block *ib, tree expr)
2318 struct bitpack_d bp;
2319 struct cl_target_option *t = TREE_TARGET_OPTION (expr);
2321 bp = lto_input_bitpack (ib);
2322 len = sizeof (struct cl_target_option);
2323 for (i = 0; i < len; i++)
2324 ((unsigned char *)t)[i] = bp_unpack_value (&bp, 8);
2325 if (bp_unpack_value (&bp, 32) != 0x12345678)
2326 fatal_error ("cl_target_option size mismatch in LTO reader and writer");
2329 /* Input a TS_TRANSLATION_UNIT_DECL tree from IB and DATA_IN into EXPR. */
2332 lto_input_ts_translation_unit_decl_tree_pointers (struct lto_input_block *ib,
2333 struct data_in *data_in,
2336 TRANSLATION_UNIT_LANGUAGE (expr) = xstrdup (lto_input_string (data_in, ib));
2337 VEC_safe_push (tree, gc, all_translation_units, expr);
2340 /* Helper for lto_input_tree. Read all pointer fields in EXPR from
2341 input block IB. DATA_IN contains tables and descriptors for the
2345 lto_input_tree_pointers (struct lto_input_block *ib, struct data_in *data_in,
2348 enum tree_code code;
2350 code = TREE_CODE (expr);
2352 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
2353 lto_input_ts_common_tree_pointers (ib, data_in, expr);
2355 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
2356 lto_input_ts_vector_tree_pointers (ib, data_in, expr);
2358 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
2359 lto_input_ts_complex_tree_pointers (ib, data_in, expr);
2361 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
2362 lto_input_ts_decl_minimal_tree_pointers (ib, data_in, expr);
2364 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
2365 lto_input_ts_decl_common_tree_pointers (ib, data_in, expr);
2367 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
2368 lto_input_ts_decl_non_common_tree_pointers (ib, data_in, expr);
2370 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
2371 lto_input_ts_decl_with_vis_tree_pointers (ib, data_in, expr);
2373 if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
2374 lto_input_ts_field_decl_tree_pointers (ib, data_in, expr);
2376 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
2377 lto_input_ts_function_decl_tree_pointers (ib, data_in, expr);
2379 if (CODE_CONTAINS_STRUCT (code, TS_TYPE))
2380 lto_input_ts_type_tree_pointers (ib, data_in, expr);
2382 if (CODE_CONTAINS_STRUCT (code, TS_LIST))
2383 lto_input_ts_list_tree_pointers (ib, data_in, expr);
2385 if (CODE_CONTAINS_STRUCT (code, TS_VEC))
2386 lto_input_ts_vec_tree_pointers (ib, data_in, expr);
2388 if (CODE_CONTAINS_STRUCT (code, TS_EXP))
2389 lto_input_ts_exp_tree_pointers (ib, data_in, expr);
2391 if (CODE_CONTAINS_STRUCT (code, TS_SSA_NAME))
2393 /* We only stream the version number of SSA names. */
2397 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
2398 lto_input_ts_block_tree_pointers (ib, data_in, expr);
2400 if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
2401 lto_input_ts_binfo_tree_pointers (ib, data_in, expr);
2403 if (CODE_CONTAINS_STRUCT (code, TS_STATEMENT_LIST))
2405 /* This should only appear in GENERIC. */
2409 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
2410 lto_input_ts_constructor_tree_pointers (ib, data_in, expr);
2412 if (CODE_CONTAINS_STRUCT (code, TS_OMP_CLAUSE))
2414 /* This should only appear in High GIMPLE. */
2418 if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
2420 sorry ("optimization options not supported yet");
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
2436 lto_register_var_decl_in_symtab (struct data_in *data_in, tree decl)
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));
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))
2467 if (!lto_streamer_cache_lookup (data_in->reader_cache, decl, &ix))
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
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));
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))
2534 if (!lto_streamer_cache_lookup (data_in->reader_cache, decl, &ix))
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]. */
2546 lto_get_pickled_tree (struct lto_input_block *ib, struct data_in *data_in)
2550 enum LTO_tags expected_tag;
2551 unsigned HOST_WIDE_INT orig_offset;
2553 ix = lto_input_sleb128 (ib);
2554 expected_tag = (enum LTO_tags) lto_input_uleb128 (ib);
2556 orig_offset = lto_input_uleb128 (ib);
2557 gcc_assert (orig_offset == (unsigned) orig_offset);
2559 result = lto_streamer_cache_get (data_in->reader_cache, ix);
2560 if (result == NULL_TREE)
2562 /* We have not yet read the cache slot IX. Go to the offset
2563 in the stream where the physical tree node is, and materialize
2565 struct lto_input_block fwd_ib;
2567 /* If we are trying to go back in the stream, something is wrong.
2568 We should've read the node at the earlier position already. */
2569 if (ib->p >= orig_offset)
2570 internal_error ("bytecode stream: tried to jump backwards in the "
2573 LTO_INIT_INPUT_BLOCK (fwd_ib, ib->data, orig_offset, ib->len);
2574 result = lto_input_tree (&fwd_ib, data_in);
2578 && TREE_CODE (result) == lto_tag_to_tree_code (expected_tag));
2584 /* Read a code and class from input block IB and return the
2585 corresponding builtin. DATA_IN is as in lto_input_tree. */
2588 lto_get_builtin_tree (struct lto_input_block *ib, struct data_in *data_in)
2590 enum built_in_class fclass;
2591 enum built_in_function fcode;
2592 const char *asmname;
2596 fclass = (enum built_in_class) lto_input_uleb128 (ib);
2597 gcc_assert (fclass == BUILT_IN_NORMAL || fclass == BUILT_IN_MD);
2599 fcode = (enum built_in_function) lto_input_uleb128 (ib);
2601 ix = lto_input_sleb128 (ib);
2602 gcc_assert (ix == (int) ix);
2604 if (fclass == BUILT_IN_NORMAL)
2606 gcc_assert (fcode < END_BUILTINS);
2607 result = built_in_decls[fcode];
2608 gcc_assert (result);
2610 else if (fclass == BUILT_IN_MD)
2612 result = targetm.builtin_decl (fcode, true);
2613 if (!result || result == error_mark_node)
2614 fatal_error ("target specific builtin not available");
2619 asmname = lto_input_string (data_in, ib);
2621 set_builtin_user_assembler_name (result, asmname);
2623 lto_streamer_cache_insert_at (data_in->reader_cache, result, ix);
2629 /* Read the physical representation of a tree node with tag TAG from
2630 input block IB using the per-file context in DATA_IN. */
2633 lto_read_tree (struct lto_input_block *ib, struct data_in *data_in,
2639 result = lto_materialize_tree (ib, data_in, tag, &ix);
2641 /* Read all the pointer fields in RESULT. */
2642 lto_input_tree_pointers (ib, data_in, result);
2644 /* We should never try to instantiate an MD or NORMAL builtin here. */
2645 if (TREE_CODE (result) == FUNCTION_DECL)
2646 gcc_assert (!lto_stream_as_builtin_p (result));
2648 if (TREE_CODE (result) == VAR_DECL)
2649 lto_register_var_decl_in_symtab (data_in, result);
2650 else if (TREE_CODE (result) == FUNCTION_DECL && !DECL_BUILT_IN (result))
2651 lto_register_function_decl_in_symtab (data_in, result);
2653 /* end_marker = */ lto_input_1_unsigned (ib);
2655 #ifdef LTO_STREAMER_DEBUG
2656 /* Remove the mapping to RESULT's original address set by
2657 lto_materialize_tree. */
2658 lto_orig_address_remove (result);
2665 /* Read and INTEGER_CST node from input block IB using the per-file
2666 context in DATA_IN. */
2669 lto_input_integer_cst (struct lto_input_block *ib, struct data_in *data_in)
2672 HOST_WIDE_INT low, high;
2675 type = lto_input_tree (ib, data_in);
2676 overflow_p = (lto_input_1_unsigned (ib) != 0);
2677 low = lto_input_uleb128 (ib);
2678 high = lto_input_uleb128 (ib);
2679 result = build_int_cst_wide (type, low, high);
2681 /* If the original constant had overflown, build a replica of RESULT to
2682 avoid modifying the shared constant returned by build_int_cst_wide. */
2685 result = copy_node (result);
2686 TREE_OVERFLOW (result) = 1;
2693 /* Read a tree from input block IB using the per-file context in
2694 DATA_IN. This context is used, for example, to resolve references
2695 to previously read nodes. */
2698 lto_input_tree (struct lto_input_block *ib, struct data_in *data_in)
2703 tag = input_record_start (ib);
2704 gcc_assert ((unsigned) tag < (unsigned) LTO_NUM_TAGS);
2706 if (tag == LTO_null)
2708 else if (tag >= LTO_field_decl_ref && tag <= LTO_global_decl_ref)
2710 /* If TAG is a reference to an indexable tree, the next value
2711 in IB is the index into the table where we expect to find
2713 result = lto_input_tree_ref (ib, data_in, cfun, tag);
2715 else if (tag == LTO_tree_pickle_reference)
2717 /* If TAG is a reference to a previously read tree, look it up in
2718 the reader cache. */
2719 result = lto_get_pickled_tree (ib, data_in);
2721 else if (tag == LTO_builtin_decl)
2723 /* If we are going to read a built-in function, all we need is
2724 the code and class. */
2725 result = lto_get_builtin_tree (ib, data_in);
2727 else if (tag == lto_tree_code_to_tag (INTEGER_CST))
2729 /* For integer constants we only need the type and its hi/low
2731 result = lto_input_integer_cst (ib, data_in);
2735 /* Otherwise, materialize a new node from IB. */
2736 result = lto_read_tree (ib, data_in, tag);
2743 /* Initialization for the LTO reader. */
2746 lto_init_reader (void)
2748 lto_streamer_init ();
2750 memset (<o_stats, 0, sizeof (lto_stats));
2751 bitmap_obstack_initialize (NULL);
2753 file_name_hash_table = htab_create (37, hash_string_slot_node,
2754 eq_string_slot_node, free);
2756 gimple_register_cfg_hooks ();
2760 /* Create a new data_in object for FILE_DATA. STRINGS is the string
2761 table to use with LEN strings. RESOLUTIONS is the vector of linker
2762 resolutions (NULL if not using a linker plugin). */
2765 lto_data_in_create (struct lto_file_decl_data *file_data, const char *strings,
2767 VEC(ld_plugin_symbol_resolution_t,heap) *resolutions)
2769 struct data_in *data_in = XCNEW (struct data_in);
2770 data_in->file_data = file_data;
2771 data_in->strings = strings;
2772 data_in->strings_len = len;
2773 data_in->globals_resolution = resolutions;
2774 data_in->reader_cache = lto_streamer_cache_create ();
2780 /* Remove DATA_IN. */
2783 lto_data_in_delete (struct data_in *data_in)
2785 VEC_free (ld_plugin_symbol_resolution_t, heap, data_in->globals_resolution);
2786 lto_streamer_cache_delete (data_in->reader_cache);
2787 free (data_in->labels);