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 "data-streamer.h"
49 #include "gimple-streamer.h"
50 #include "lto-streamer.h"
51 #include "tree-streamer.h"
52 #include "tree-pass.h"
53 #include "streamer-hooks.h"
55 /* The table to hold the file names. */
56 static htab_t file_name_hash_table;
59 /* Check that tag ACTUAL has one of the given values. NUM_TAGS is the
60 number of valid tag values to check. */
63 lto_tag_check_set (enum LTO_tags actual, int ntags, ...)
69 for (i = 0; i < ntags; i++)
70 if ((unsigned) actual == va_arg (ap, unsigned))
77 internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual));
81 /* Read LENGTH bytes from STREAM to ADDR. */
84 lto_input_data_block (struct lto_input_block *ib, void *addr, size_t length)
87 unsigned char *const buffer = (unsigned char *const) addr;
89 for (i = 0; i < length; i++)
90 buffer[i] = streamer_read_uchar (ib);
94 /* Lookup STRING in file_name_hash_table. If found, return the existing
95 string, otherwise insert STRING as the canonical version. */
98 canon_file_name (const char *string)
101 struct string_slot s_slot;
102 size_t len = strlen (string);
107 slot = htab_find_slot (file_name_hash_table, &s_slot, INSERT);
111 struct string_slot *new_slot;
113 saved_string = (char *) xmalloc (len + 1);
114 new_slot = XCNEW (struct string_slot);
115 memcpy (saved_string, string, len + 1);
116 new_slot->s = saved_string;
123 struct string_slot *old_slot = (struct string_slot *) *slot;
129 /* Clear the line info stored in DATA_IN. */
132 clear_line_info (struct data_in *data_in)
134 if (data_in->current_file)
135 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
136 data_in->current_file = NULL;
137 data_in->current_line = 0;
138 data_in->current_col = 0;
142 /* Read a location bitpack from input block IB. */
145 lto_input_location_bitpack (struct data_in *data_in, struct bitpack_d *bp)
147 bool file_change, line_change, column_change;
149 bool prev_file = data_in->current_file != NULL;
151 if (bp_unpack_value (bp, 1))
152 return UNKNOWN_LOCATION;
154 file_change = bp_unpack_value (bp, 1);
156 data_in->current_file = canon_file_name
157 (string_for_index (data_in,
158 bp_unpack_var_len_unsigned (bp),
161 line_change = bp_unpack_value (bp, 1);
163 data_in->current_line = bp_unpack_var_len_unsigned (bp);
165 column_change = bp_unpack_value (bp, 1);
167 data_in->current_col = bp_unpack_var_len_unsigned (bp);
172 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
174 linemap_add (line_table, LC_ENTER, false, data_in->current_file,
175 data_in->current_line);
177 else if (line_change)
178 linemap_line_start (line_table, data_in->current_line, data_in->current_col);
180 return linemap_position_for_column (line_table, data_in->current_col);
184 /* Read a location from input block IB.
185 If the input_location streamer hook exists, call it.
186 Otherwise, proceed with reading the location from the
187 expanded location bitpack. */
190 lto_input_location (struct lto_input_block *ib, struct data_in *data_in)
192 if (streamer_hooks.input_location)
193 return streamer_hooks.input_location (ib, data_in);
198 bp = streamer_read_bitpack (ib);
199 return lto_input_location_bitpack (data_in, &bp);
204 /* Read a reference to a tree node from DATA_IN using input block IB.
205 TAG is the expected node that should be found in IB, if TAG belongs
206 to one of the indexable trees, expect to read a reference index to
207 be looked up in one of the symbol tables, otherwise read the pysical
208 representation of the tree using stream_read_tree. FN is the
209 function scope for the read tree. */
212 lto_input_tree_ref (struct lto_input_block *ib, struct data_in *data_in,
213 struct function *fn, enum LTO_tags tag)
215 unsigned HOST_WIDE_INT ix_u;
216 tree result = NULL_TREE;
218 lto_tag_check_range (tag, LTO_field_decl_ref, LTO_global_decl_ref);
223 ix_u = streamer_read_uhwi (ib);
224 result = lto_file_decl_data_get_type (data_in->file_data, ix_u);
227 case LTO_ssa_name_ref:
228 ix_u = streamer_read_uhwi (ib);
229 result = VEC_index (tree, SSANAMES (fn), ix_u);
232 case LTO_field_decl_ref:
233 ix_u = streamer_read_uhwi (ib);
234 result = lto_file_decl_data_get_field_decl (data_in->file_data, ix_u);
237 case LTO_function_decl_ref:
238 ix_u = streamer_read_uhwi (ib);
239 result = lto_file_decl_data_get_fn_decl (data_in->file_data, ix_u);
242 case LTO_type_decl_ref:
243 ix_u = streamer_read_uhwi (ib);
244 result = lto_file_decl_data_get_type_decl (data_in->file_data, ix_u);
247 case LTO_namespace_decl_ref:
248 ix_u = streamer_read_uhwi (ib);
249 result = lto_file_decl_data_get_namespace_decl (data_in->file_data, ix_u);
252 case LTO_global_decl_ref:
253 case LTO_result_decl_ref:
254 case LTO_const_decl_ref:
255 case LTO_imported_decl_ref:
256 case LTO_label_decl_ref:
257 case LTO_translation_unit_decl_ref:
258 ix_u = streamer_read_uhwi (ib);
259 result = lto_file_decl_data_get_var_decl (data_in->file_data, ix_u);
272 /* Read and return a double-linked list of catch handlers from input
273 block IB, using descriptors in DATA_IN. */
275 static struct eh_catch_d *
276 lto_input_eh_catch_list (struct lto_input_block *ib, struct data_in *data_in,
282 *last_p = first = NULL;
283 tag = streamer_read_record_start (ib);
289 lto_tag_check_range (tag, LTO_eh_catch, LTO_eh_catch);
291 /* Read the catch node. */
292 n = ggc_alloc_cleared_eh_catch_d ();
293 n->type_list = stream_read_tree (ib, data_in);
294 n->filter_list = stream_read_tree (ib, data_in);
295 n->label = stream_read_tree (ib, data_in);
297 /* Register all the types in N->FILTER_LIST. */
298 for (list = n->filter_list; list; list = TREE_CHAIN (list))
299 add_type_for_runtime (TREE_VALUE (list));
301 /* Chain N to the end of the list. */
303 (*last_p)->next_catch = n;
304 n->prev_catch = *last_p;
307 /* Set the head of the list the first time through the loop. */
311 tag = streamer_read_record_start (ib);
318 /* Read and return EH region IX from input block IB, using descriptors
322 input_eh_region (struct lto_input_block *ib, struct data_in *data_in, int ix)
327 /* Read the region header. */
328 tag = streamer_read_record_start (ib);
332 r = ggc_alloc_cleared_eh_region_d ();
333 r->index = streamer_read_hwi (ib);
335 gcc_assert (r->index == ix);
337 /* Read all the region pointers as region numbers. We'll fix up
338 the pointers once the whole array has been read. */
339 r->outer = (eh_region) (intptr_t) streamer_read_hwi (ib);
340 r->inner = (eh_region) (intptr_t) streamer_read_hwi (ib);
341 r->next_peer = (eh_region) (intptr_t) streamer_read_hwi (ib);
345 case LTO_ert_cleanup:
346 r->type = ERT_CLEANUP;
351 struct eh_catch_d *last_catch;
353 r->u.eh_try.first_catch = lto_input_eh_catch_list (ib, data_in,
355 r->u.eh_try.last_catch = last_catch;
359 case LTO_ert_allowed_exceptions:
363 r->type = ERT_ALLOWED_EXCEPTIONS;
364 r->u.allowed.type_list = stream_read_tree (ib, data_in);
365 r->u.allowed.label = stream_read_tree (ib, data_in);
366 r->u.allowed.filter = streamer_read_uhwi (ib);
368 for (l = r->u.allowed.type_list; l ; l = TREE_CHAIN (l))
369 add_type_for_runtime (TREE_VALUE (l));
373 case LTO_ert_must_not_throw:
374 r->type = ERT_MUST_NOT_THROW;
375 r->u.must_not_throw.failure_decl = stream_read_tree (ib, data_in);
376 r->u.must_not_throw.failure_loc = lto_input_location (ib, data_in);
383 r->landing_pads = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib);
389 /* Read and return EH landing pad IX from input block IB, using descriptors
392 static eh_landing_pad
393 input_eh_lp (struct lto_input_block *ib, struct data_in *data_in, int ix)
398 /* Read the landing pad header. */
399 tag = streamer_read_record_start (ib);
403 lto_tag_check_range (tag, LTO_eh_landing_pad, LTO_eh_landing_pad);
405 lp = ggc_alloc_cleared_eh_landing_pad_d ();
406 lp->index = streamer_read_hwi (ib);
407 gcc_assert (lp->index == ix);
408 lp->next_lp = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib);
409 lp->region = (eh_region) (intptr_t) streamer_read_hwi (ib);
410 lp->post_landing_pad = stream_read_tree (ib, data_in);
416 /* After reading the EH regions, pointers to peer and children regions
417 are region numbers. This converts all these region numbers into
418 real pointers into the rematerialized regions for FN. ROOT_REGION
419 is the region number for the root EH region in FN. */
422 fixup_eh_region_pointers (struct function *fn, HOST_WIDE_INT root_region)
425 VEC(eh_region,gc) *eh_array = fn->eh->region_array;
426 VEC(eh_landing_pad,gc) *lp_array = fn->eh->lp_array;
430 gcc_assert (eh_array && lp_array);
432 gcc_assert (root_region >= 0);
433 fn->eh->region_tree = VEC_index (eh_region, eh_array, root_region);
435 #define FIXUP_EH_REGION(r) (r) = VEC_index (eh_region, eh_array, \
436 (HOST_WIDE_INT) (intptr_t) (r))
437 #define FIXUP_EH_LP(p) (p) = VEC_index (eh_landing_pad, lp_array, \
438 (HOST_WIDE_INT) (intptr_t) (p))
440 /* Convert all the index numbers stored in pointer fields into
441 pointers to the corresponding slots in the EH region array. */
442 FOR_EACH_VEC_ELT (eh_region, eh_array, i, r)
444 /* The array may contain NULL regions. */
448 gcc_assert (i == (unsigned) r->index);
449 FIXUP_EH_REGION (r->outer);
450 FIXUP_EH_REGION (r->inner);
451 FIXUP_EH_REGION (r->next_peer);
452 FIXUP_EH_LP (r->landing_pads);
455 /* Convert all the index numbers stored in pointer fields into
456 pointers to the corresponding slots in the EH landing pad array. */
457 FOR_EACH_VEC_ELT (eh_landing_pad, lp_array, i, lp)
459 /* The array may contain NULL landing pads. */
463 gcc_assert (i == (unsigned) lp->index);
464 FIXUP_EH_LP (lp->next_lp);
465 FIXUP_EH_REGION (lp->region);
468 #undef FIXUP_EH_REGION
473 /* Initialize EH support. */
478 static bool eh_initialized_p = false;
480 if (eh_initialized_p)
483 /* Contrary to most other FEs, we only initialize EH support when at
484 least one of the files in the set contains exception regions in
485 it. Since this happens much later than the call to init_eh in
486 lang_dependent_init, we have to set flag_exceptions and call
487 init_eh again to initialize the EH tables. */
491 eh_initialized_p = true;
495 /* Read the exception table for FN from IB using the data descriptors
499 input_eh_regions (struct lto_input_block *ib, struct data_in *data_in,
502 HOST_WIDE_INT i, root_region, len;
505 tag = streamer_read_record_start (ib);
509 lto_tag_check_range (tag, LTO_eh_table, LTO_eh_table);
511 /* If the file contains EH regions, then it was compiled with
512 -fexceptions. In that case, initialize the backend EH
518 root_region = streamer_read_hwi (ib);
519 gcc_assert (root_region == (int) root_region);
521 /* Read the EH region array. */
522 len = streamer_read_hwi (ib);
523 gcc_assert (len == (int) len);
526 VEC_safe_grow (eh_region, gc, fn->eh->region_array, len);
527 for (i = 0; i < len; i++)
529 eh_region r = input_eh_region (ib, data_in, i);
530 VEC_replace (eh_region, fn->eh->region_array, i, r);
534 /* Read the landing pads. */
535 len = streamer_read_hwi (ib);
536 gcc_assert (len == (int) len);
539 VEC_safe_grow (eh_landing_pad, gc, fn->eh->lp_array, len);
540 for (i = 0; i < len; i++)
542 eh_landing_pad lp = input_eh_lp (ib, data_in, i);
543 VEC_replace (eh_landing_pad, fn->eh->lp_array, i, lp);
547 /* Read the runtime type data. */
548 len = streamer_read_hwi (ib);
549 gcc_assert (len == (int) len);
552 VEC_safe_grow (tree, gc, fn->eh->ttype_data, len);
553 for (i = 0; i < len; i++)
555 tree ttype = stream_read_tree (ib, data_in);
556 VEC_replace (tree, fn->eh->ttype_data, i, ttype);
560 /* Read the table of action chains. */
561 len = streamer_read_hwi (ib);
562 gcc_assert (len == (int) len);
565 if (targetm.arm_eabi_unwinder)
567 VEC_safe_grow (tree, gc, fn->eh->ehspec_data.arm_eabi, len);
568 for (i = 0; i < len; i++)
570 tree t = stream_read_tree (ib, data_in);
571 VEC_replace (tree, fn->eh->ehspec_data.arm_eabi, i, t);
576 VEC_safe_grow (uchar, gc, fn->eh->ehspec_data.other, len);
577 for (i = 0; i < len; i++)
579 uchar c = streamer_read_uchar (ib);
580 VEC_replace (uchar, fn->eh->ehspec_data.other, i, c);
585 /* Reconstruct the EH region tree by fixing up the peer/children
587 fixup_eh_region_pointers (fn, root_region);
589 tag = streamer_read_record_start (ib);
590 lto_tag_check_range (tag, LTO_null, LTO_null);
594 /* Make a new basic block with index INDEX in function FN. */
597 make_new_block (struct function *fn, unsigned int index)
599 basic_block bb = alloc_block ();
601 SET_BASIC_BLOCK_FOR_FUNCTION (fn, index, bb);
602 n_basic_blocks_for_function (fn)++;
607 /* Read the CFG for function FN from input block IB. */
610 input_cfg (struct lto_input_block *ib, struct function *fn,
611 int count_materialization_scale)
613 unsigned int bb_count;
618 init_empty_tree_cfg_for_function (fn);
619 init_ssa_operands (fn);
621 profile_status_for_function (fn) = streamer_read_enum (ib, profile_status_d,
624 bb_count = streamer_read_uhwi (ib);
626 last_basic_block_for_function (fn) = bb_count;
627 if (bb_count > VEC_length (basic_block, basic_block_info_for_function (fn)))
628 VEC_safe_grow_cleared (basic_block, gc,
629 basic_block_info_for_function (fn), bb_count);
631 if (bb_count > VEC_length (basic_block, label_to_block_map_for_function (fn)))
632 VEC_safe_grow_cleared (basic_block, gc,
633 label_to_block_map_for_function (fn), bb_count);
635 index = streamer_read_hwi (ib);
638 basic_block bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
639 unsigned int edge_count;
642 bb = make_new_block (fn, index);
644 edge_count = streamer_read_uhwi (ib);
646 /* Connect up the CFG. */
647 for (i = 0; i < edge_count; i++)
649 unsigned int dest_index;
650 unsigned int edge_flags;
656 dest_index = streamer_read_uhwi (ib);
657 probability = (int) streamer_read_hwi (ib);
658 count = ((gcov_type) streamer_read_hwi (ib) * count_materialization_scale
659 + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE;
660 edge_flags = streamer_read_uhwi (ib);
662 dest = BASIC_BLOCK_FOR_FUNCTION (fn, dest_index);
665 dest = make_new_block (fn, dest_index);
667 e = make_edge (bb, dest, edge_flags);
668 e->probability = probability;
672 index = streamer_read_hwi (ib);
675 p_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(fn);
676 index = streamer_read_hwi (ib);
679 basic_block bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
683 index = streamer_read_hwi (ib);
688 /* Read the SSA names array for function FN from DATA_IN using input
692 input_ssa_names (struct lto_input_block *ib, struct data_in *data_in,
695 unsigned int i, size;
697 size = streamer_read_uhwi (ib);
698 init_ssanames (fn, size);
700 i = streamer_read_uhwi (ib);
706 /* Skip over the elements that had been freed. */
707 while (VEC_length (tree, SSANAMES (fn)) < i)
708 VEC_quick_push (tree, SSANAMES (fn), NULL_TREE);
710 is_default_def = (streamer_read_uchar (ib) != 0);
711 name = stream_read_tree (ib, data_in);
712 ssa_name = make_ssa_name_fn (fn, name, gimple_build_nop ());
715 set_default_def (SSA_NAME_VAR (ssa_name), ssa_name);
717 i = streamer_read_uhwi (ib);
722 /* Go through all NODE edges and fixup call_stmt pointers
723 so they point to STMTS. */
726 fixup_call_stmt_edges_1 (struct cgraph_node *node, gimple *stmts)
728 struct cgraph_edge *cedge;
729 for (cedge = node->callees; cedge; cedge = cedge->next_callee)
730 cedge->call_stmt = stmts[cedge->lto_stmt_uid];
731 for (cedge = node->indirect_calls; cedge; cedge = cedge->next_callee)
732 cedge->call_stmt = stmts[cedge->lto_stmt_uid];
735 /* Fixup call_stmt pointers in NODE and all clones. */
738 fixup_call_stmt_edges (struct cgraph_node *orig, gimple *stmts)
740 struct cgraph_node *node;
742 while (orig->clone_of)
743 orig = orig->clone_of;
745 fixup_call_stmt_edges_1 (orig, stmts);
747 for (node = orig->clones; node != orig;)
749 fixup_call_stmt_edges_1 (node, stmts);
752 else if (node->next_sibling_clone)
753 node = node->next_sibling_clone;
756 while (node != orig && !node->next_sibling_clone)
757 node = node->clone_of;
759 node = node->next_sibling_clone;
765 /* Input the base body of struct function FN from DATA_IN
766 using input block IB. */
769 input_struct_function_base (struct function *fn, struct data_in *data_in,
770 struct lto_input_block *ib)
775 /* Read the static chain and non-local goto save area. */
776 fn->static_chain_decl = stream_read_tree (ib, data_in);
777 fn->nonlocal_goto_save_area = stream_read_tree (ib, data_in);
779 /* Read all the local symbols. */
780 len = streamer_read_hwi (ib);
784 VEC_safe_grow (tree, gc, fn->local_decls, len);
785 for (i = 0; i < len; i++)
787 tree t = stream_read_tree (ib, data_in);
788 VEC_replace (tree, fn->local_decls, i, t);
792 /* Input the function start and end loci. */
793 fn->function_start_locus = lto_input_location (ib, data_in);
794 fn->function_end_locus = lto_input_location (ib, data_in);
796 /* Input the current IL state of the function. */
797 fn->curr_properties = streamer_read_uhwi (ib);
799 /* Read all the attributes for FN. */
800 bp = streamer_read_bitpack (ib);
801 fn->is_thunk = bp_unpack_value (&bp, 1);
802 fn->has_local_explicit_reg_vars = bp_unpack_value (&bp, 1);
803 fn->after_tree_profile = bp_unpack_value (&bp, 1);
804 fn->returns_pcc_struct = bp_unpack_value (&bp, 1);
805 fn->returns_struct = bp_unpack_value (&bp, 1);
806 fn->can_throw_non_call_exceptions = bp_unpack_value (&bp, 1);
807 fn->always_inline_functions_inlined = bp_unpack_value (&bp, 1);
808 fn->after_inlining = bp_unpack_value (&bp, 1);
809 fn->stdarg = bp_unpack_value (&bp, 1);
810 fn->has_nonlocal_label = bp_unpack_value (&bp, 1);
811 fn->calls_alloca = bp_unpack_value (&bp, 1);
812 fn->calls_setjmp = bp_unpack_value (&bp, 1);
813 fn->va_list_fpr_size = bp_unpack_value (&bp, 8);
814 fn->va_list_gpr_size = bp_unpack_value (&bp, 8);
818 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
821 input_function (tree fn_decl, struct data_in *data_in,
822 struct lto_input_block *ib)
828 struct cgraph_node *node;
829 tree args, narg, oarg;
831 fn = DECL_STRUCT_FUNCTION (fn_decl);
832 tag = streamer_read_record_start (ib);
833 clear_line_info (data_in);
835 gimple_register_cfg_hooks ();
836 lto_tag_check (tag, LTO_function);
838 input_struct_function_base (fn, data_in, ib);
840 /* Read all function arguments. We need to re-map them here to the
841 arguments of the merged function declaration. */
842 args = stream_read_tree (ib, data_in);
843 for (oarg = args, narg = DECL_ARGUMENTS (fn_decl);
845 oarg = TREE_CHAIN (oarg), narg = TREE_CHAIN (narg))
849 res = streamer_tree_cache_lookup (data_in->reader_cache, oarg, &ix);
851 /* Replace the argument in the streamer cache. */
852 streamer_tree_cache_insert_at (data_in->reader_cache, narg, ix);
854 gcc_assert (!oarg && !narg);
856 /* Read all the SSA names. */
857 input_ssa_names (ib, data_in, fn);
859 /* Read the exception handling regions in the function. */
860 input_eh_regions (ib, data_in, fn);
862 /* Read the tree of lexical scopes for the function. */
863 DECL_INITIAL (fn_decl) = stream_read_tree (ib, data_in);
864 gcc_assert (DECL_INITIAL (fn_decl));
865 DECL_SAVED_TREE (fn_decl) = NULL_TREE;
866 node = cgraph_get_create_node (fn_decl);
868 /* Read all the basic blocks. */
869 tag = streamer_read_record_start (ib);
872 input_bb (ib, tag, data_in, fn,
873 node->count_materialization_scale);
874 tag = streamer_read_record_start (ib);
877 /* Fix up the call statements that are mentioned in the callgraph
879 set_gimple_stmt_max_uid (cfun, 0);
882 gimple_stmt_iterator gsi;
883 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
885 gimple stmt = gsi_stmt (gsi);
886 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
889 stmts = (gimple *) xcalloc (gimple_stmt_max_uid (fn), sizeof (gimple));
892 gimple_stmt_iterator bsi = gsi_start_bb (bb);
893 while (!gsi_end_p (bsi))
895 gimple stmt = gsi_stmt (bsi);
896 /* If we're recompiling LTO objects with debug stmts but
897 we're not supposed to have debug stmts, remove them now.
898 We can't remove them earlier because this would cause uid
899 mismatches in fixups, but we can do it at this point, as
900 long as debug stmts don't require fixups. */
901 if (!MAY_HAVE_DEBUG_STMTS && is_gimple_debug (stmt))
903 gimple_stmt_iterator gsi = bsi;
905 gsi_remove (&gsi, true);
910 stmts[gimple_uid (stmt)] = stmt;
915 /* Set the gimple body to the statement sequence in the entry
916 basic block. FIXME lto, this is fairly hacky. The existence
917 of a gimple body is used by the cgraph routines, but we should
918 really use the presence of the CFG. */
920 edge_iterator ei = ei_start (ENTRY_BLOCK_PTR->succs);
921 gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest));
924 fixup_call_stmt_edges (node, stmts);
925 execute_all_ipa_stmt_fixups (node, stmts);
927 update_ssa (TODO_update_ssa_only_virtuals);
928 free_dominance_info (CDI_DOMINATORS);
929 free_dominance_info (CDI_POST_DOMINATORS);
934 /* Read the body from DATA for function FN_DECL and fill it in.
935 FILE_DATA are the global decls and types. SECTION_TYPE is either
936 LTO_section_function_body or LTO_section_static_initializer. If
937 section type is LTO_section_function_body, FN must be the decl for
941 lto_read_body (struct lto_file_decl_data *file_data, tree fn_decl,
942 const char *data, enum lto_section_type section_type)
944 const struct lto_function_header *header;
945 struct data_in *data_in;
949 struct lto_input_block ib_cfg;
950 struct lto_input_block ib_main;
952 header = (const struct lto_function_header *) data;
953 cfg_offset = sizeof (struct lto_function_header);
954 main_offset = cfg_offset + header->cfg_size;
955 string_offset = main_offset + header->main_size;
957 LTO_INIT_INPUT_BLOCK (ib_cfg,
962 LTO_INIT_INPUT_BLOCK (ib_main,
967 data_in = lto_data_in_create (file_data, data + string_offset,
968 header->string_size, NULL);
970 /* Make sure the file was generated by the exact same compiler. */
971 lto_check_version (header->lto_header.major_version,
972 header->lto_header.minor_version);
974 if (section_type == LTO_section_function_body)
976 struct function *fn = DECL_STRUCT_FUNCTION (fn_decl);
977 struct lto_in_decl_state *decl_state;
978 struct cgraph_node *node = cgraph_get_node (fn_decl);
981 gcc_checking_assert (node);
985 /* Use the function's decl state. */
986 decl_state = lto_get_function_in_decl_state (file_data, fn_decl);
987 gcc_assert (decl_state);
988 file_data->current_decl_state = decl_state;
990 input_cfg (&ib_cfg, fn, node->count_materialization_scale);
992 /* Set up the struct function. */
993 from = VEC_length (tree, data_in->reader_cache->nodes);
994 input_function (fn_decl, data_in, &ib_main);
995 /* And fixup types we streamed locally. */
997 struct streamer_tree_cache_d *cache = data_in->reader_cache;
998 unsigned len = VEC_length (tree, cache->nodes);
1000 for (i = len; i-- > from;)
1002 tree t = VEC_index (tree, cache->nodes, i);
1008 gcc_assert (TYPE_CANONICAL (t) == NULL_TREE);
1009 TYPE_CANONICAL (t) = TYPE_MAIN_VARIANT (t);
1010 if (TYPE_MAIN_VARIANT (t) != t)
1012 gcc_assert (TYPE_NEXT_VARIANT (t) == NULL_TREE);
1013 TYPE_NEXT_VARIANT (t)
1014 = TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t));
1015 TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t)) = t;
1021 /* We should now be in SSA. */
1022 cfun->gimple_df->in_ssa_p = true;
1024 /* Restore decl state */
1025 file_data->current_decl_state = file_data->global_decl_state;
1030 clear_line_info (data_in);
1031 lto_data_in_delete (data_in);
1035 /* Read the body of FN_DECL using DATA. FILE_DATA holds the global
1039 lto_input_function_body (struct lto_file_decl_data *file_data,
1040 tree fn_decl, const char *data)
1042 current_function_decl = fn_decl;
1043 lto_read_body (file_data, fn_decl, data, LTO_section_function_body);
1047 /* Read the physical representation of a tree node with tag TAG from
1048 input block IB using the per-file context in DATA_IN. */
1051 lto_read_tree (struct lto_input_block *ib, struct data_in *data_in,
1054 /* Instantiate a new tree node. */
1055 tree result = streamer_alloc_tree (ib, data_in, tag);
1057 /* Enter RESULT in the reader cache. This will make RESULT
1058 available so that circular references in the rest of the tree
1059 structure can be resolved in subsequent calls to stream_read_tree. */
1060 streamer_tree_cache_append (data_in->reader_cache, result);
1062 /* Read all the bitfield values in RESULT. Note that for LTO, we
1063 only write language-independent bitfields, so no more unpacking is
1065 streamer_read_tree_bitfields (ib, result);
1067 /* Read all the pointer fields in RESULT. */
1068 streamer_read_tree_body (ib, data_in, result);
1070 /* Read any LTO-specific data not read by the tree streamer. */
1072 && TREE_CODE (result) != FUNCTION_DECL
1073 && TREE_CODE (result) != TRANSLATION_UNIT_DECL)
1074 DECL_INITIAL (result) = stream_read_tree (ib, data_in);
1076 /* We should never try to instantiate an MD or NORMAL builtin here. */
1077 if (TREE_CODE (result) == FUNCTION_DECL)
1078 gcc_assert (!streamer_handle_as_builtin_p (result));
1080 /* end_marker = */ streamer_read_uchar (ib);
1082 #ifdef LTO_STREAMER_DEBUG
1083 /* Remove the mapping to RESULT's original address set by
1084 streamer_alloc_tree. */
1085 lto_orig_address_remove (result);
1092 /* Read a tree from input block IB using the per-file context in
1093 DATA_IN. This context is used, for example, to resolve references
1094 to previously read nodes. */
1097 lto_input_tree (struct lto_input_block *ib, struct data_in *data_in)
1102 tag = streamer_read_record_start (ib);
1103 gcc_assert ((unsigned) tag < (unsigned) LTO_NUM_TAGS);
1105 if (tag == LTO_null)
1107 else if (tag >= LTO_field_decl_ref && tag <= LTO_global_decl_ref)
1109 /* If TAG is a reference to an indexable tree, the next value
1110 in IB is the index into the table where we expect to find
1112 result = lto_input_tree_ref (ib, data_in, cfun, tag);
1114 else if (tag == LTO_tree_pickle_reference)
1116 /* If TAG is a reference to a previously read tree, look it up in
1117 the reader cache. */
1118 result = streamer_get_pickled_tree (ib, data_in);
1120 else if (tag == LTO_builtin_decl)
1122 /* If we are going to read a built-in function, all we need is
1123 the code and class. */
1124 result = streamer_get_builtin_tree (ib, data_in);
1126 else if (tag == lto_tree_code_to_tag (INTEGER_CST))
1128 /* For integer constants we only need the type and its hi/low
1130 result = streamer_read_integer_cst (ib, data_in);
1134 /* Otherwise, materialize a new node from IB. */
1135 result = lto_read_tree (ib, data_in, tag);
1142 /* Input toplevel asms. */
1145 lto_input_toplevel_asms (struct lto_file_decl_data *file_data, int order_base)
1148 const char *data = lto_get_section_data (file_data, LTO_section_asm,
1150 const struct lto_asm_header *header = (const struct lto_asm_header *) data;
1152 struct data_in *data_in;
1153 struct lto_input_block ib;
1159 string_offset = sizeof (*header) + header->main_size;
1161 LTO_INIT_INPUT_BLOCK (ib,
1162 data + sizeof (*header),
1166 data_in = lto_data_in_create (file_data, data + string_offset,
1167 header->string_size, NULL);
1169 /* Make sure the file was generated by the exact same compiler. */
1170 lto_check_version (header->lto_header.major_version,
1171 header->lto_header.minor_version);
1173 while ((str = streamer_read_string_cst (data_in, &ib)))
1175 struct asm_node *node = add_asm_node (str);
1176 node->order = streamer_read_hwi (&ib) + order_base;
1177 if (node->order >= symtab_order)
1178 symtab_order = node->order + 1;
1181 clear_line_info (data_in);
1182 lto_data_in_delete (data_in);
1184 lto_free_section_data (file_data, LTO_section_asm, NULL, data, len);
1188 /* Initialization for the LTO reader. */
1191 lto_reader_init (void)
1193 lto_streamer_init ();
1194 file_name_hash_table = htab_create (37, hash_string_slot_node,
1195 eq_string_slot_node, free);
1199 /* Create a new data_in object for FILE_DATA. STRINGS is the string
1200 table to use with LEN strings. RESOLUTIONS is the vector of linker
1201 resolutions (NULL if not using a linker plugin). */
1204 lto_data_in_create (struct lto_file_decl_data *file_data, const char *strings,
1206 VEC(ld_plugin_symbol_resolution_t,heap) *resolutions)
1208 struct data_in *data_in = XCNEW (struct data_in);
1209 data_in->file_data = file_data;
1210 data_in->strings = strings;
1211 data_in->strings_len = len;
1212 data_in->globals_resolution = resolutions;
1213 data_in->reader_cache = streamer_tree_cache_create ();
1219 /* Remove DATA_IN. */
1222 lto_data_in_delete (struct data_in *data_in)
1224 VEC_free (ld_plugin_symbol_resolution_t, heap, data_in->globals_resolution);
1225 streamer_tree_cache_delete (data_in->reader_cache);
1226 free (data_in->labels);