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"
54 /* The table to hold the file names. */
55 static htab_t file_name_hash_table
;
58 /* Check that tag ACTUAL has one of the given values. NUM_TAGS is the
59 number of valid tag values to check. */
62 lto_tag_check_set (enum LTO_tags actual
, int ntags
, ...)
68 for (i
= 0; i
< ntags
; i
++)
69 if ((unsigned) actual
== va_arg (ap
, unsigned))
76 internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual
));
80 /* Read LENGTH bytes from STREAM to ADDR. */
83 lto_input_data_block (struct lto_input_block
*ib
, void *addr
, size_t length
)
86 unsigned char *const buffer
= (unsigned char *const) addr
;
88 for (i
= 0; i
< length
; i
++)
89 buffer
[i
] = streamer_read_uchar (ib
);
93 /* Lookup STRING in file_name_hash_table. If found, return the existing
94 string, otherwise insert STRING as the canonical version. */
97 canon_file_name (const char *string
)
100 struct string_slot s_slot
;
101 size_t len
= strlen (string
);
106 slot
= htab_find_slot (file_name_hash_table
, &s_slot
, INSERT
);
110 struct string_slot
*new_slot
;
112 saved_string
= (char *) xmalloc (len
+ 1);
113 new_slot
= XCNEW (struct string_slot
);
114 memcpy (saved_string
, string
, len
+ 1);
115 new_slot
->s
= saved_string
;
122 struct string_slot
*old_slot
= (struct string_slot
*) *slot
;
128 /* Clear the line info stored in DATA_IN. */
131 clear_line_info (struct data_in
*data_in
)
133 if (data_in
->current_file
)
134 linemap_add (line_table
, LC_LEAVE
, false, NULL
, 0);
135 data_in
->current_file
= NULL
;
136 data_in
->current_line
= 0;
137 data_in
->current_col
= 0;
141 /* Read a location bitpack from input block IB. */
144 lto_input_location_bitpack (struct data_in
*data_in
, struct bitpack_d
*bp
)
146 bool file_change
, line_change
, column_change
;
148 bool prev_file
= data_in
->current_file
!= NULL
;
150 if (bp_unpack_value (bp
, 1))
151 return UNKNOWN_LOCATION
;
153 file_change
= bp_unpack_value (bp
, 1);
155 data_in
->current_file
= canon_file_name
156 (string_for_index (data_in
,
157 bp_unpack_var_len_unsigned (bp
),
160 line_change
= bp_unpack_value (bp
, 1);
162 data_in
->current_line
= bp_unpack_var_len_unsigned (bp
);
164 column_change
= bp_unpack_value (bp
, 1);
166 data_in
->current_col
= bp_unpack_var_len_unsigned (bp
);
171 linemap_add (line_table
, LC_LEAVE
, false, NULL
, 0);
173 linemap_add (line_table
, LC_ENTER
, false, data_in
->current_file
,
174 data_in
->current_line
);
176 else if (line_change
)
177 linemap_line_start (line_table
, data_in
->current_line
, data_in
->current_col
);
179 return linemap_position_for_column (line_table
, data_in
->current_col
);
183 /* Read a location from input block IB. */
186 lto_input_location (struct lto_input_block
*ib
, struct data_in
*data_in
)
190 bp
= streamer_read_bitpack (ib
);
191 return lto_input_location_bitpack (data_in
, &bp
);
195 /* Read a reference to a tree node from DATA_IN using input block IB.
196 TAG is the expected node that should be found in IB, if TAG belongs
197 to one of the indexable trees, expect to read a reference index to
198 be looked up in one of the symbol tables, otherwise read the pysical
199 representation of the tree using stream_read_tree. FN is the
200 function scope for the read tree. */
203 lto_input_tree_ref (struct lto_input_block
*ib
, struct data_in
*data_in
,
204 struct function
*fn
, enum LTO_tags tag
)
206 unsigned HOST_WIDE_INT ix_u
;
207 tree result
= NULL_TREE
;
209 lto_tag_check_range (tag
, LTO_field_decl_ref
, LTO_global_decl_ref
);
214 ix_u
= streamer_read_uhwi (ib
);
215 result
= lto_file_decl_data_get_type (data_in
->file_data
, ix_u
);
218 case LTO_ssa_name_ref
:
219 ix_u
= streamer_read_uhwi (ib
);
220 result
= VEC_index (tree
, SSANAMES (fn
), ix_u
);
223 case LTO_field_decl_ref
:
224 ix_u
= streamer_read_uhwi (ib
);
225 result
= lto_file_decl_data_get_field_decl (data_in
->file_data
, ix_u
);
228 case LTO_function_decl_ref
:
229 ix_u
= streamer_read_uhwi (ib
);
230 result
= lto_file_decl_data_get_fn_decl (data_in
->file_data
, ix_u
);
233 case LTO_type_decl_ref
:
234 ix_u
= streamer_read_uhwi (ib
);
235 result
= lto_file_decl_data_get_type_decl (data_in
->file_data
, ix_u
);
238 case LTO_namespace_decl_ref
:
239 ix_u
= streamer_read_uhwi (ib
);
240 result
= lto_file_decl_data_get_namespace_decl (data_in
->file_data
, ix_u
);
243 case LTO_global_decl_ref
:
244 case LTO_result_decl_ref
:
245 case LTO_const_decl_ref
:
246 case LTO_imported_decl_ref
:
247 case LTO_label_decl_ref
:
248 case LTO_translation_unit_decl_ref
:
249 ix_u
= streamer_read_uhwi (ib
);
250 result
= lto_file_decl_data_get_var_decl (data_in
->file_data
, ix_u
);
263 /* Read and return a double-linked list of catch handlers from input
264 block IB, using descriptors in DATA_IN. */
266 static struct eh_catch_d
*
267 lto_input_eh_catch_list (struct lto_input_block
*ib
, struct data_in
*data_in
,
273 *last_p
= first
= NULL
;
274 tag
= streamer_read_record_start (ib
);
280 lto_tag_check_range (tag
, LTO_eh_catch
, LTO_eh_catch
);
282 /* Read the catch node. */
283 n
= ggc_alloc_cleared_eh_catch_d ();
284 n
->type_list
= stream_read_tree (ib
, data_in
);
285 n
->filter_list
= stream_read_tree (ib
, data_in
);
286 n
->label
= stream_read_tree (ib
, data_in
);
288 /* Register all the types in N->FILTER_LIST. */
289 for (list
= n
->filter_list
; list
; list
= TREE_CHAIN (list
))
290 add_type_for_runtime (TREE_VALUE (list
));
292 /* Chain N to the end of the list. */
294 (*last_p
)->next_catch
= n
;
295 n
->prev_catch
= *last_p
;
298 /* Set the head of the list the first time through the loop. */
302 tag
= streamer_read_record_start (ib
);
309 /* Read and return EH region IX from input block IB, using descriptors
313 input_eh_region (struct lto_input_block
*ib
, struct data_in
*data_in
, int ix
)
318 /* Read the region header. */
319 tag
= streamer_read_record_start (ib
);
323 r
= ggc_alloc_cleared_eh_region_d ();
324 r
->index
= streamer_read_hwi (ib
);
326 gcc_assert (r
->index
== ix
);
328 /* Read all the region pointers as region numbers. We'll fix up
329 the pointers once the whole array has been read. */
330 r
->outer
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
331 r
->inner
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
332 r
->next_peer
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
336 case LTO_ert_cleanup
:
337 r
->type
= ERT_CLEANUP
;
342 struct eh_catch_d
*last_catch
;
344 r
->u
.eh_try
.first_catch
= lto_input_eh_catch_list (ib
, data_in
,
346 r
->u
.eh_try
.last_catch
= last_catch
;
350 case LTO_ert_allowed_exceptions
:
354 r
->type
= ERT_ALLOWED_EXCEPTIONS
;
355 r
->u
.allowed
.type_list
= stream_read_tree (ib
, data_in
);
356 r
->u
.allowed
.label
= stream_read_tree (ib
, data_in
);
357 r
->u
.allowed
.filter
= streamer_read_uhwi (ib
);
359 for (l
= r
->u
.allowed
.type_list
; l
; l
= TREE_CHAIN (l
))
360 add_type_for_runtime (TREE_VALUE (l
));
364 case LTO_ert_must_not_throw
:
365 r
->type
= ERT_MUST_NOT_THROW
;
366 r
->u
.must_not_throw
.failure_decl
= stream_read_tree (ib
, data_in
);
367 r
->u
.must_not_throw
.failure_loc
= lto_input_location (ib
, data_in
);
374 r
->landing_pads
= (eh_landing_pad
) (intptr_t) streamer_read_hwi (ib
);
380 /* Read and return EH landing pad IX from input block IB, using descriptors
383 static eh_landing_pad
384 input_eh_lp (struct lto_input_block
*ib
, struct data_in
*data_in
, int ix
)
389 /* Read the landing pad header. */
390 tag
= streamer_read_record_start (ib
);
394 lto_tag_check_range (tag
, LTO_eh_landing_pad
, LTO_eh_landing_pad
);
396 lp
= ggc_alloc_cleared_eh_landing_pad_d ();
397 lp
->index
= streamer_read_hwi (ib
);
398 gcc_assert (lp
->index
== ix
);
399 lp
->next_lp
= (eh_landing_pad
) (intptr_t) streamer_read_hwi (ib
);
400 lp
->region
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
401 lp
->post_landing_pad
= stream_read_tree (ib
, data_in
);
407 /* After reading the EH regions, pointers to peer and children regions
408 are region numbers. This converts all these region numbers into
409 real pointers into the rematerialized regions for FN. ROOT_REGION
410 is the region number for the root EH region in FN. */
413 fixup_eh_region_pointers (struct function
*fn
, HOST_WIDE_INT root_region
)
416 VEC(eh_region
,gc
) *eh_array
= fn
->eh
->region_array
;
417 VEC(eh_landing_pad
,gc
) *lp_array
= fn
->eh
->lp_array
;
421 gcc_assert (eh_array
&& lp_array
);
423 gcc_assert (root_region
>= 0);
424 fn
->eh
->region_tree
= VEC_index (eh_region
, eh_array
, root_region
);
426 #define FIXUP_EH_REGION(r) (r) = VEC_index (eh_region, eh_array, \
427 (HOST_WIDE_INT) (intptr_t) (r))
428 #define FIXUP_EH_LP(p) (p) = VEC_index (eh_landing_pad, lp_array, \
429 (HOST_WIDE_INT) (intptr_t) (p))
431 /* Convert all the index numbers stored in pointer fields into
432 pointers to the corresponding slots in the EH region array. */
433 FOR_EACH_VEC_ELT (eh_region
, eh_array
, i
, r
)
435 /* The array may contain NULL regions. */
439 gcc_assert (i
== (unsigned) r
->index
);
440 FIXUP_EH_REGION (r
->outer
);
441 FIXUP_EH_REGION (r
->inner
);
442 FIXUP_EH_REGION (r
->next_peer
);
443 FIXUP_EH_LP (r
->landing_pads
);
446 /* Convert all the index numbers stored in pointer fields into
447 pointers to the corresponding slots in the EH landing pad array. */
448 FOR_EACH_VEC_ELT (eh_landing_pad
, lp_array
, i
, lp
)
450 /* The array may contain NULL landing pads. */
454 gcc_assert (i
== (unsigned) lp
->index
);
455 FIXUP_EH_LP (lp
->next_lp
);
456 FIXUP_EH_REGION (lp
->region
);
459 #undef FIXUP_EH_REGION
464 /* Initialize EH support. */
469 static bool eh_initialized_p
= false;
471 if (eh_initialized_p
)
474 /* Contrary to most other FEs, we only initialize EH support when at
475 least one of the files in the set contains exception regions in
476 it. Since this happens much later than the call to init_eh in
477 lang_dependent_init, we have to set flag_exceptions and call
478 init_eh again to initialize the EH tables. */
482 eh_initialized_p
= true;
486 /* Read the exception table for FN from IB using the data descriptors
490 input_eh_regions (struct lto_input_block
*ib
, struct data_in
*data_in
,
493 HOST_WIDE_INT i
, root_region
, len
;
496 tag
= streamer_read_record_start (ib
);
500 lto_tag_check_range (tag
, LTO_eh_table
, LTO_eh_table
);
502 /* If the file contains EH regions, then it was compiled with
503 -fexceptions. In that case, initialize the backend EH
509 root_region
= streamer_read_hwi (ib
);
510 gcc_assert (root_region
== (int) root_region
);
512 /* Read the EH region array. */
513 len
= streamer_read_hwi (ib
);
514 gcc_assert (len
== (int) len
);
517 VEC_safe_grow (eh_region
, gc
, fn
->eh
->region_array
, len
);
518 for (i
= 0; i
< len
; i
++)
520 eh_region r
= input_eh_region (ib
, data_in
, i
);
521 VEC_replace (eh_region
, fn
->eh
->region_array
, i
, r
);
525 /* Read the landing pads. */
526 len
= streamer_read_hwi (ib
);
527 gcc_assert (len
== (int) len
);
530 VEC_safe_grow (eh_landing_pad
, gc
, fn
->eh
->lp_array
, len
);
531 for (i
= 0; i
< len
; i
++)
533 eh_landing_pad lp
= input_eh_lp (ib
, data_in
, i
);
534 VEC_replace (eh_landing_pad
, fn
->eh
->lp_array
, i
, lp
);
538 /* Read the runtime type data. */
539 len
= streamer_read_hwi (ib
);
540 gcc_assert (len
== (int) len
);
543 VEC_safe_grow (tree
, gc
, fn
->eh
->ttype_data
, len
);
544 for (i
= 0; i
< len
; i
++)
546 tree ttype
= stream_read_tree (ib
, data_in
);
547 VEC_replace (tree
, fn
->eh
->ttype_data
, i
, ttype
);
551 /* Read the table of action chains. */
552 len
= streamer_read_hwi (ib
);
553 gcc_assert (len
== (int) len
);
556 if (targetm
.arm_eabi_unwinder
)
558 VEC_safe_grow (tree
, gc
, fn
->eh
->ehspec_data
.arm_eabi
, len
);
559 for (i
= 0; i
< len
; i
++)
561 tree t
= stream_read_tree (ib
, data_in
);
562 VEC_replace (tree
, fn
->eh
->ehspec_data
.arm_eabi
, i
, t
);
567 VEC_safe_grow (uchar
, gc
, fn
->eh
->ehspec_data
.other
, len
);
568 for (i
= 0; i
< len
; i
++)
570 uchar c
= streamer_read_uchar (ib
);
571 VEC_replace (uchar
, fn
->eh
->ehspec_data
.other
, i
, c
);
576 /* Reconstruct the EH region tree by fixing up the peer/children
578 fixup_eh_region_pointers (fn
, root_region
);
580 tag
= streamer_read_record_start (ib
);
581 lto_tag_check_range (tag
, LTO_null
, LTO_null
);
585 /* Make a new basic block with index INDEX in function FN. */
588 make_new_block (struct function
*fn
, unsigned int index
)
590 basic_block bb
= alloc_block ();
592 SET_BASIC_BLOCK_FOR_FUNCTION (fn
, index
, bb
);
593 bb
->il
.gimple
= ggc_alloc_cleared_gimple_bb_info ();
594 n_basic_blocks_for_function (fn
)++;
596 set_bb_seq (bb
, gimple_seq_alloc ());
601 /* Read the CFG for function FN from input block IB. */
604 input_cfg (struct lto_input_block
*ib
, struct function
*fn
,
605 int count_materialization_scale
)
607 unsigned int bb_count
;
612 init_empty_tree_cfg_for_function (fn
);
613 init_ssa_operands ();
615 profile_status_for_function (fn
) = streamer_read_enum (ib
, profile_status_d
,
618 bb_count
= streamer_read_uhwi (ib
);
620 last_basic_block_for_function (fn
) = bb_count
;
621 if (bb_count
> VEC_length (basic_block
, basic_block_info_for_function (fn
)))
622 VEC_safe_grow_cleared (basic_block
, gc
,
623 basic_block_info_for_function (fn
), bb_count
);
625 if (bb_count
> VEC_length (basic_block
, label_to_block_map_for_function (fn
)))
626 VEC_safe_grow_cleared (basic_block
, gc
,
627 label_to_block_map_for_function (fn
), bb_count
);
629 index
= streamer_read_hwi (ib
);
632 basic_block bb
= BASIC_BLOCK_FOR_FUNCTION (fn
, index
);
633 unsigned int edge_count
;
636 bb
= make_new_block (fn
, index
);
638 edge_count
= streamer_read_uhwi (ib
);
640 /* Connect up the CFG. */
641 for (i
= 0; i
< edge_count
; i
++)
643 unsigned int dest_index
;
644 unsigned int edge_flags
;
650 dest_index
= streamer_read_uhwi (ib
);
651 probability
= (int) streamer_read_hwi (ib
);
652 count
= ((gcov_type
) streamer_read_hwi (ib
) * count_materialization_scale
653 + REG_BR_PROB_BASE
/ 2) / REG_BR_PROB_BASE
;
654 edge_flags
= streamer_read_uhwi (ib
);
656 dest
= BASIC_BLOCK_FOR_FUNCTION (fn
, dest_index
);
659 dest
= make_new_block (fn
, dest_index
);
661 e
= make_edge (bb
, dest
, edge_flags
);
662 e
->probability
= probability
;
666 index
= streamer_read_hwi (ib
);
669 p_bb
= ENTRY_BLOCK_PTR_FOR_FUNCTION(fn
);
670 index
= streamer_read_hwi (ib
);
673 basic_block bb
= BASIC_BLOCK_FOR_FUNCTION (fn
, index
);
677 index
= streamer_read_hwi (ib
);
682 /* Read the SSA names array for function FN from DATA_IN using input
686 input_ssa_names (struct lto_input_block
*ib
, struct data_in
*data_in
,
689 unsigned int i
, size
;
691 size
= streamer_read_uhwi (ib
);
692 init_ssanames (fn
, size
);
694 i
= streamer_read_uhwi (ib
);
700 /* Skip over the elements that had been freed. */
701 while (VEC_length (tree
, SSANAMES (fn
)) < i
)
702 VEC_quick_push (tree
, SSANAMES (fn
), NULL_TREE
);
704 is_default_def
= (streamer_read_uchar (ib
) != 0);
705 name
= stream_read_tree (ib
, data_in
);
706 ssa_name
= make_ssa_name_fn (fn
, name
, gimple_build_nop ());
709 set_default_def (SSA_NAME_VAR (ssa_name
), ssa_name
);
711 i
= streamer_read_uhwi (ib
);
716 /* Go through all NODE edges and fixup call_stmt pointers
717 so they point to STMTS. */
720 fixup_call_stmt_edges_1 (struct cgraph_node
*node
, gimple
*stmts
)
722 struct cgraph_edge
*cedge
;
723 for (cedge
= node
->callees
; cedge
; cedge
= cedge
->next_callee
)
724 cedge
->call_stmt
= stmts
[cedge
->lto_stmt_uid
];
725 for (cedge
= node
->indirect_calls
; cedge
; cedge
= cedge
->next_callee
)
726 cedge
->call_stmt
= stmts
[cedge
->lto_stmt_uid
];
729 /* Fixup call_stmt pointers in NODE and all clones. */
732 fixup_call_stmt_edges (struct cgraph_node
*orig
, gimple
*stmts
)
734 struct cgraph_node
*node
;
736 while (orig
->clone_of
)
737 orig
= orig
->clone_of
;
739 fixup_call_stmt_edges_1 (orig
, stmts
);
741 for (node
= orig
->clones
; node
!= orig
;)
743 fixup_call_stmt_edges_1 (node
, stmts
);
746 else if (node
->next_sibling_clone
)
747 node
= node
->next_sibling_clone
;
750 while (node
!= orig
&& !node
->next_sibling_clone
)
751 node
= node
->clone_of
;
753 node
= node
->next_sibling_clone
;
758 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
761 input_function (tree fn_decl
, struct data_in
*data_in
,
762 struct lto_input_block
*ib
)
769 struct cgraph_node
*node
;
770 tree args
, narg
, oarg
;
773 fn
= DECL_STRUCT_FUNCTION (fn_decl
);
774 tag
= streamer_read_record_start (ib
);
775 clear_line_info (data_in
);
777 gimple_register_cfg_hooks ();
778 lto_tag_check (tag
, LTO_function
);
780 /* Read all the attributes for FN. */
781 bp
= streamer_read_bitpack (ib
);
782 fn
->is_thunk
= bp_unpack_value (&bp
, 1);
783 fn
->has_local_explicit_reg_vars
= bp_unpack_value (&bp
, 1);
784 fn
->after_tree_profile
= bp_unpack_value (&bp
, 1);
785 fn
->returns_pcc_struct
= bp_unpack_value (&bp
, 1);
786 fn
->returns_struct
= bp_unpack_value (&bp
, 1);
787 fn
->can_throw_non_call_exceptions
= bp_unpack_value (&bp
, 1);
788 fn
->always_inline_functions_inlined
= bp_unpack_value (&bp
, 1);
789 fn
->after_inlining
= bp_unpack_value (&bp
, 1);
790 fn
->stdarg
= bp_unpack_value (&bp
, 1);
791 fn
->has_nonlocal_label
= bp_unpack_value (&bp
, 1);
792 fn
->calls_alloca
= bp_unpack_value (&bp
, 1);
793 fn
->calls_setjmp
= bp_unpack_value (&bp
, 1);
794 fn
->va_list_fpr_size
= bp_unpack_value (&bp
, 8);
795 fn
->va_list_gpr_size
= bp_unpack_value (&bp
, 8);
797 /* Input the function start and end loci. */
798 fn
->function_start_locus
= lto_input_location (ib
, data_in
);
799 fn
->function_end_locus
= lto_input_location (ib
, data_in
);
801 /* Input the current IL state of the function. */
802 fn
->curr_properties
= streamer_read_uhwi (ib
);
804 /* Read the static chain and non-local goto save area. */
805 fn
->static_chain_decl
= stream_read_tree (ib
, data_in
);
806 fn
->nonlocal_goto_save_area
= stream_read_tree (ib
, data_in
);
808 /* Read all the local symbols. */
809 len
= streamer_read_hwi (ib
);
813 VEC_safe_grow (tree
, gc
, fn
->local_decls
, len
);
814 for (i
= 0; i
< len
; i
++)
816 tree t
= stream_read_tree (ib
, data_in
);
817 VEC_replace (tree
, fn
->local_decls
, i
, t
);
821 /* Read all function arguments. We need to re-map them here to the
822 arguments of the merged function declaration. */
823 args
= stream_read_tree (ib
, data_in
);
824 for (oarg
= args
, narg
= DECL_ARGUMENTS (fn_decl
);
826 oarg
= TREE_CHAIN (oarg
), narg
= TREE_CHAIN (narg
))
830 res
= streamer_tree_cache_lookup (data_in
->reader_cache
, oarg
, &ix
);
832 /* Replace the argument in the streamer cache. */
833 streamer_tree_cache_insert_at (data_in
->reader_cache
, narg
, ix
);
835 gcc_assert (!oarg
&& !narg
);
837 /* Read all the SSA names. */
838 input_ssa_names (ib
, data_in
, fn
);
840 /* Read the exception handling regions in the function. */
841 input_eh_regions (ib
, data_in
, fn
);
843 /* Read the tree of lexical scopes for the function. */
844 DECL_INITIAL (fn_decl
) = stream_read_tree (ib
, data_in
);
845 gcc_assert (DECL_INITIAL (fn_decl
));
846 DECL_SAVED_TREE (fn_decl
) = NULL_TREE
;
847 node
= cgraph_get_create_node (fn_decl
);
849 /* Read all the basic blocks. */
850 tag
= streamer_read_record_start (ib
);
853 input_bb (ib
, tag
, data_in
, fn
,
854 node
->count_materialization_scale
);
855 tag
= streamer_read_record_start (ib
);
858 /* Fix up the call statements that are mentioned in the callgraph
860 set_gimple_stmt_max_uid (cfun
, 0);
863 gimple_stmt_iterator gsi
;
864 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
866 gimple stmt
= gsi_stmt (gsi
);
867 gimple_set_uid (stmt
, inc_gimple_stmt_max_uid (cfun
));
870 stmts
= (gimple
*) xcalloc (gimple_stmt_max_uid (fn
), sizeof (gimple
));
873 gimple_stmt_iterator bsi
= gsi_start_bb (bb
);
874 while (!gsi_end_p (bsi
))
876 gimple stmt
= gsi_stmt (bsi
);
877 /* If we're recompiling LTO objects with debug stmts but
878 we're not supposed to have debug stmts, remove them now.
879 We can't remove them earlier because this would cause uid
880 mismatches in fixups, but we can do it at this point, as
881 long as debug stmts don't require fixups. */
882 if (!MAY_HAVE_DEBUG_STMTS
&& is_gimple_debug (stmt
))
884 gimple_stmt_iterator gsi
= bsi
;
886 gsi_remove (&gsi
, true);
891 stmts
[gimple_uid (stmt
)] = stmt
;
896 /* Set the gimple body to the statement sequence in the entry
897 basic block. FIXME lto, this is fairly hacky. The existence
898 of a gimple body is used by the cgraph routines, but we should
899 really use the presence of the CFG. */
901 edge_iterator ei
= ei_start (ENTRY_BLOCK_PTR
->succs
);
902 gimple_set_body (fn_decl
, bb_seq (ei_edge (ei
)->dest
));
905 fixup_call_stmt_edges (node
, stmts
);
906 execute_all_ipa_stmt_fixups (node
, stmts
);
908 update_ssa (TODO_update_ssa_only_virtuals
);
909 free_dominance_info (CDI_DOMINATORS
);
910 free_dominance_info (CDI_POST_DOMINATORS
);
915 /* Read initializer expressions for public statics. DATA_IN is the
916 file being read. IB is the input block used for reading. */
919 input_alias_pairs (struct lto_input_block
*ib
, struct data_in
*data_in
)
923 clear_line_info (data_in
);
925 var
= stream_read_tree (ib
, data_in
);
928 const char *orig_name
, *new_name
;
931 p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
933 p
->target
= stream_read_tree (ib
, data_in
);
935 /* If the target is a static object, we may have registered a
936 new name for it to avoid clashes between statics coming from
937 different files. In that case, use the new name. */
938 orig_name
= IDENTIFIER_POINTER (p
->target
);
939 new_name
= lto_get_decl_name_mapping (data_in
->file_data
, orig_name
);
940 if (strcmp (orig_name
, new_name
) != 0)
941 p
->target
= get_identifier (new_name
);
943 var
= stream_read_tree (ib
, data_in
);
948 /* Read the body from DATA for function FN_DECL and fill it in.
949 FILE_DATA are the global decls and types. SECTION_TYPE is either
950 LTO_section_function_body or LTO_section_static_initializer. If
951 section type is LTO_section_function_body, FN must be the decl for
955 lto_read_body (struct lto_file_decl_data
*file_data
, tree fn_decl
,
956 const char *data
, enum lto_section_type section_type
)
958 const struct lto_function_header
*header
;
959 struct data_in
*data_in
;
962 int32_t string_offset
;
963 struct lto_input_block ib_cfg
;
964 struct lto_input_block ib_main
;
966 header
= (const struct lto_function_header
*) data
;
967 cfg_offset
= sizeof (struct lto_function_header
);
968 main_offset
= cfg_offset
+ header
->cfg_size
;
969 string_offset
= main_offset
+ header
->main_size
;
971 LTO_INIT_INPUT_BLOCK (ib_cfg
,
976 LTO_INIT_INPUT_BLOCK (ib_main
,
981 data_in
= lto_data_in_create (file_data
, data
+ string_offset
,
982 header
->string_size
, NULL
);
984 /* Make sure the file was generated by the exact same compiler. */
985 lto_check_version (header
->lto_header
.major_version
,
986 header
->lto_header
.minor_version
);
988 if (section_type
== LTO_section_function_body
)
990 struct function
*fn
= DECL_STRUCT_FUNCTION (fn_decl
);
991 struct lto_in_decl_state
*decl_state
;
992 struct cgraph_node
*node
= cgraph_get_node (fn_decl
);
994 gcc_checking_assert (node
);
998 /* Use the function's decl state. */
999 decl_state
= lto_get_function_in_decl_state (file_data
, fn_decl
);
1000 gcc_assert (decl_state
);
1001 file_data
->current_decl_state
= decl_state
;
1003 input_cfg (&ib_cfg
, fn
, node
->count_materialization_scale
);
1005 /* Set up the struct function. */
1006 input_function (fn_decl
, data_in
, &ib_main
);
1008 /* We should now be in SSA. */
1009 cfun
->gimple_df
->in_ssa_p
= true;
1011 /* Restore decl state */
1012 file_data
->current_decl_state
= file_data
->global_decl_state
;
1018 input_alias_pairs (&ib_main
, data_in
);
1021 clear_line_info (data_in
);
1022 lto_data_in_delete (data_in
);
1026 /* Read the body of FN_DECL using DATA. FILE_DATA holds the global
1030 lto_input_function_body (struct lto_file_decl_data
*file_data
,
1031 tree fn_decl
, const char *data
)
1033 current_function_decl
= fn_decl
;
1034 lto_read_body (file_data
, fn_decl
, data
, LTO_section_function_body
);
1038 /* Read in VAR_DECL using DATA. FILE_DATA holds the global decls and
1042 lto_input_constructors_and_inits (struct lto_file_decl_data
*file_data
,
1045 lto_read_body (file_data
, NULL
, data
, LTO_section_static_initializer
);
1049 /* Read the physical representation of a tree node with tag TAG from
1050 input block IB using the per-file context in DATA_IN. */
1053 lto_read_tree (struct lto_input_block
*ib
, struct data_in
*data_in
,
1056 /* Instantiate a new tree node. */
1057 tree result
= streamer_alloc_tree (ib
, data_in
, tag
);
1059 /* Enter RESULT in the reader cache. This will make RESULT
1060 available so that circular references in the rest of the tree
1061 structure can be resolved in subsequent calls to stream_read_tree. */
1062 streamer_tree_cache_append (data_in
->reader_cache
, result
);
1064 /* Read all the bitfield values in RESULT. Note that for LTO, we
1065 only write language-independent bitfields, so no more unpacking is
1067 streamer_read_tree_bitfields (ib
, result
);
1069 /* Read all the pointer fields in RESULT. */
1070 streamer_read_tree_body (ib
, data_in
, result
);
1072 /* Read any LTO-specific data not read by the tree streamer. */
1074 && TREE_CODE (result
) != FUNCTION_DECL
1075 && TREE_CODE (result
) != TRANSLATION_UNIT_DECL
)
1076 DECL_INITIAL (result
) = stream_read_tree (ib
, data_in
);
1078 /* We should never try to instantiate an MD or NORMAL builtin here. */
1079 if (TREE_CODE (result
) == FUNCTION_DECL
)
1080 gcc_assert (!streamer_handle_as_builtin_p (result
));
1082 /* end_marker = */ streamer_read_uchar (ib
);
1084 #ifdef LTO_STREAMER_DEBUG
1085 /* Remove the mapping to RESULT's original address set by
1086 streamer_alloc_tree. */
1087 lto_orig_address_remove (result
);
1094 /* Read a tree from input block IB using the per-file context in
1095 DATA_IN. This context is used, for example, to resolve references
1096 to previously read nodes. */
1099 lto_input_tree (struct lto_input_block
*ib
, struct data_in
*data_in
)
1104 tag
= streamer_read_record_start (ib
);
1105 gcc_assert ((unsigned) tag
< (unsigned) LTO_NUM_TAGS
);
1107 if (tag
== LTO_null
)
1109 else if (tag
>= LTO_field_decl_ref
&& tag
<= LTO_global_decl_ref
)
1111 /* If TAG is a reference to an indexable tree, the next value
1112 in IB is the index into the table where we expect to find
1114 result
= lto_input_tree_ref (ib
, data_in
, cfun
, tag
);
1116 else if (tag
== LTO_tree_pickle_reference
)
1118 /* If TAG is a reference to a previously read tree, look it up in
1119 the reader cache. */
1120 result
= streamer_get_pickled_tree (ib
, data_in
);
1122 else if (tag
== LTO_builtin_decl
)
1124 /* If we are going to read a built-in function, all we need is
1125 the code and class. */
1126 result
= streamer_get_builtin_tree (ib
, data_in
);
1128 else if (tag
== lto_tree_code_to_tag (INTEGER_CST
))
1130 /* For integer constants we only need the type and its hi/low
1132 result
= streamer_read_integer_cst (ib
, data_in
);
1136 /* Otherwise, materialize a new node from IB. */
1137 result
= lto_read_tree (ib
, data_in
, tag
);
1144 /* Initialization for the LTO reader. */
1147 lto_reader_init (void)
1149 lto_streamer_init ();
1150 file_name_hash_table
= htab_create (37, hash_string_slot_node
,
1151 eq_string_slot_node
, free
);
1155 /* Create a new data_in object for FILE_DATA. STRINGS is the string
1156 table to use with LEN strings. RESOLUTIONS is the vector of linker
1157 resolutions (NULL if not using a linker plugin). */
1160 lto_data_in_create (struct lto_file_decl_data
*file_data
, const char *strings
,
1162 VEC(ld_plugin_symbol_resolution_t
,heap
) *resolutions
)
1164 struct data_in
*data_in
= XCNEW (struct data_in
);
1165 data_in
->file_data
= file_data
;
1166 data_in
->strings
= strings
;
1167 data_in
->strings_len
= len
;
1168 data_in
->globals_resolution
= resolutions
;
1169 data_in
->reader_cache
= streamer_tree_cache_create ();
1175 /* Remove DATA_IN. */
1178 lto_data_in_delete (struct data_in
*data_in
)
1180 VEC_free (ld_plugin_symbol_resolution_t
, heap
, data_in
->globals_resolution
);
1181 streamer_tree_cache_delete (data_in
->reader_cache
);
1182 free (data_in
->labels
);