1 /* Read the GIMPLE representation from a file stream.
3 Copyright (C) 2009-2013 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"
44 #include "ipa-utils.h"
45 #include "data-streamer.h"
46 #include "gimple-streamer.h"
47 #include "lto-streamer.h"
48 #include "tree-streamer.h"
49 #include "tree-pass.h"
50 #include "streamer-hooks.h"
54 struct freeing_string_slot_hasher
: string_slot_hasher
56 static inline void remove (value_type
*);
60 freeing_string_slot_hasher::remove (value_type
*v
)
65 /* The table to hold the file names. */
66 static hash_table
<freeing_string_slot_hasher
> file_name_hash_table
;
69 /* Check that tag ACTUAL has one of the given values. NUM_TAGS is the
70 number of valid tag values to check. */
73 lto_tag_check_set (enum LTO_tags actual
, int ntags
, ...)
79 for (i
= 0; i
< ntags
; i
++)
80 if ((unsigned) actual
== va_arg (ap
, unsigned))
87 internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual
));
91 /* Read LENGTH bytes from STREAM to ADDR. */
94 lto_input_data_block (struct lto_input_block
*ib
, void *addr
, size_t length
)
97 unsigned char *const buffer
= (unsigned char *const) addr
;
99 for (i
= 0; i
< length
; i
++)
100 buffer
[i
] = streamer_read_uchar (ib
);
104 /* Lookup STRING in file_name_hash_table. If found, return the existing
105 string, otherwise insert STRING as the canonical version. */
108 canon_file_name (const char *string
)
111 struct string_slot s_slot
;
112 size_t len
= strlen (string
);
117 slot
= file_name_hash_table
.find_slot (&s_slot
, INSERT
);
121 struct string_slot
*new_slot
;
123 saved_string
= (char *) xmalloc (len
+ 1);
124 new_slot
= XCNEW (struct string_slot
);
125 memcpy (saved_string
, string
, len
+ 1);
126 new_slot
->s
= saved_string
;
133 struct string_slot
*old_slot
= *slot
;
139 /* Read a location bitpack from input block IB. */
142 lto_input_location (struct bitpack_d
*bp
, struct data_in
*data_in
)
144 static const char *current_file
;
145 static int current_line
;
146 static int current_col
;
147 bool file_change
, line_change
, column_change
;
149 bool prev_file
= current_file
!= NULL
;
151 if (bp_unpack_value (bp
, 1))
152 return UNKNOWN_LOCATION
;
154 file_change
= bp_unpack_value (bp
, 1);
155 line_change
= bp_unpack_value (bp
, 1);
156 column_change
= bp_unpack_value (bp
, 1);
159 current_file
= canon_file_name
160 (string_for_index (data_in
,
161 bp_unpack_var_len_unsigned (bp
),
165 current_line
= bp_unpack_var_len_unsigned (bp
);
168 current_col
= bp_unpack_var_len_unsigned (bp
);
173 linemap_add (line_table
, LC_LEAVE
, false, NULL
, 0);
175 linemap_add (line_table
, LC_ENTER
, false, current_file
, current_line
);
177 else if (line_change
)
178 linemap_line_start (line_table
, current_line
, current_col
);
180 return linemap_position_for_column (line_table
, current_col
);
184 /* Read a reference to a tree node from DATA_IN using input block IB.
185 TAG is the expected node that should be found in IB, if TAG belongs
186 to one of the indexable trees, expect to read a reference index to
187 be looked up in one of the symbol tables, otherwise read the pysical
188 representation of the tree using stream_read_tree. FN is the
189 function scope for the read tree. */
192 lto_input_tree_ref (struct lto_input_block
*ib
, struct data_in
*data_in
,
193 struct function
*fn
, enum LTO_tags tag
)
195 unsigned HOST_WIDE_INT ix_u
;
196 tree result
= NULL_TREE
;
198 lto_tag_check_range (tag
, LTO_field_decl_ref
, LTO_global_decl_ref
);
203 ix_u
= streamer_read_uhwi (ib
);
204 result
= lto_file_decl_data_get_type (data_in
->file_data
, ix_u
);
207 case LTO_ssa_name_ref
:
208 ix_u
= streamer_read_uhwi (ib
);
209 result
= (*SSANAMES (fn
))[ix_u
];
212 case LTO_field_decl_ref
:
213 ix_u
= streamer_read_uhwi (ib
);
214 result
= lto_file_decl_data_get_field_decl (data_in
->file_data
, ix_u
);
217 case LTO_function_decl_ref
:
218 ix_u
= streamer_read_uhwi (ib
);
219 result
= lto_file_decl_data_get_fn_decl (data_in
->file_data
, ix_u
);
222 case LTO_type_decl_ref
:
223 ix_u
= streamer_read_uhwi (ib
);
224 result
= lto_file_decl_data_get_type_decl (data_in
->file_data
, ix_u
);
227 case LTO_namespace_decl_ref
:
228 ix_u
= streamer_read_uhwi (ib
);
229 result
= lto_file_decl_data_get_namespace_decl (data_in
->file_data
, ix_u
);
232 case LTO_global_decl_ref
:
233 case LTO_result_decl_ref
:
234 case LTO_const_decl_ref
:
235 case LTO_imported_decl_ref
:
236 case LTO_label_decl_ref
:
237 case LTO_translation_unit_decl_ref
:
238 ix_u
= streamer_read_uhwi (ib
);
239 result
= lto_file_decl_data_get_var_decl (data_in
->file_data
, ix_u
);
252 /* Read and return a double-linked list of catch handlers from input
253 block IB, using descriptors in DATA_IN. */
255 static struct eh_catch_d
*
256 lto_input_eh_catch_list (struct lto_input_block
*ib
, struct data_in
*data_in
,
262 *last_p
= first
= NULL
;
263 tag
= streamer_read_record_start (ib
);
269 lto_tag_check_range (tag
, LTO_eh_catch
, LTO_eh_catch
);
271 /* Read the catch node. */
272 n
= ggc_alloc_cleared_eh_catch_d ();
273 n
->type_list
= stream_read_tree (ib
, data_in
);
274 n
->filter_list
= stream_read_tree (ib
, data_in
);
275 n
->label
= stream_read_tree (ib
, data_in
);
277 /* Register all the types in N->FILTER_LIST. */
278 for (list
= n
->filter_list
; list
; list
= TREE_CHAIN (list
))
279 add_type_for_runtime (TREE_VALUE (list
));
281 /* Chain N to the end of the list. */
283 (*last_p
)->next_catch
= n
;
284 n
->prev_catch
= *last_p
;
287 /* Set the head of the list the first time through the loop. */
291 tag
= streamer_read_record_start (ib
);
298 /* Read and return EH region IX from input block IB, using descriptors
302 input_eh_region (struct lto_input_block
*ib
, struct data_in
*data_in
, int ix
)
307 /* Read the region header. */
308 tag
= streamer_read_record_start (ib
);
312 r
= ggc_alloc_cleared_eh_region_d ();
313 r
->index
= streamer_read_hwi (ib
);
315 gcc_assert (r
->index
== ix
);
317 /* Read all the region pointers as region numbers. We'll fix up
318 the pointers once the whole array has been read. */
319 r
->outer
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
320 r
->inner
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
321 r
->next_peer
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
325 case LTO_ert_cleanup
:
326 r
->type
= ERT_CLEANUP
;
331 struct eh_catch_d
*last_catch
;
333 r
->u
.eh_try
.first_catch
= lto_input_eh_catch_list (ib
, data_in
,
335 r
->u
.eh_try
.last_catch
= last_catch
;
339 case LTO_ert_allowed_exceptions
:
343 r
->type
= ERT_ALLOWED_EXCEPTIONS
;
344 r
->u
.allowed
.type_list
= stream_read_tree (ib
, data_in
);
345 r
->u
.allowed
.label
= stream_read_tree (ib
, data_in
);
346 r
->u
.allowed
.filter
= streamer_read_uhwi (ib
);
348 for (l
= r
->u
.allowed
.type_list
; l
; l
= TREE_CHAIN (l
))
349 add_type_for_runtime (TREE_VALUE (l
));
353 case LTO_ert_must_not_throw
:
355 r
->type
= ERT_MUST_NOT_THROW
;
356 r
->u
.must_not_throw
.failure_decl
= stream_read_tree (ib
, data_in
);
357 bitpack_d bp
= streamer_read_bitpack (ib
);
358 r
->u
.must_not_throw
.failure_loc
359 = stream_input_location (&bp
, data_in
);
367 r
->landing_pads
= (eh_landing_pad
) (intptr_t) streamer_read_hwi (ib
);
373 /* Read and return EH landing pad IX from input block IB, using descriptors
376 static eh_landing_pad
377 input_eh_lp (struct lto_input_block
*ib
, struct data_in
*data_in
, int ix
)
382 /* Read the landing pad header. */
383 tag
= streamer_read_record_start (ib
);
387 lto_tag_check_range (tag
, LTO_eh_landing_pad
, LTO_eh_landing_pad
);
389 lp
= ggc_alloc_cleared_eh_landing_pad_d ();
390 lp
->index
= streamer_read_hwi (ib
);
391 gcc_assert (lp
->index
== ix
);
392 lp
->next_lp
= (eh_landing_pad
) (intptr_t) streamer_read_hwi (ib
);
393 lp
->region
= (eh_region
) (intptr_t) streamer_read_hwi (ib
);
394 lp
->post_landing_pad
= stream_read_tree (ib
, data_in
);
400 /* After reading the EH regions, pointers to peer and children regions
401 are region numbers. This converts all these region numbers into
402 real pointers into the rematerialized regions for FN. ROOT_REGION
403 is the region number for the root EH region in FN. */
406 fixup_eh_region_pointers (struct function
*fn
, HOST_WIDE_INT root_region
)
409 vec
<eh_region
, va_gc
> *eh_array
= fn
->eh
->region_array
;
410 vec
<eh_landing_pad
, va_gc
> *lp_array
= fn
->eh
->lp_array
;
414 gcc_assert (eh_array
&& lp_array
);
416 gcc_assert (root_region
>= 0);
417 fn
->eh
->region_tree
= (*eh_array
)[root_region
];
419 #define FIXUP_EH_REGION(r) (r) = (*eh_array)[(HOST_WIDE_INT) (intptr_t) (r)]
420 #define FIXUP_EH_LP(p) (p) = (*lp_array)[(HOST_WIDE_INT) (intptr_t) (p)]
422 /* Convert all the index numbers stored in pointer fields into
423 pointers to the corresponding slots in the EH region array. */
424 FOR_EACH_VEC_ELT (*eh_array
, i
, r
)
426 /* The array may contain NULL regions. */
430 gcc_assert (i
== (unsigned) r
->index
);
431 FIXUP_EH_REGION (r
->outer
);
432 FIXUP_EH_REGION (r
->inner
);
433 FIXUP_EH_REGION (r
->next_peer
);
434 FIXUP_EH_LP (r
->landing_pads
);
437 /* Convert all the index numbers stored in pointer fields into
438 pointers to the corresponding slots in the EH landing pad array. */
439 FOR_EACH_VEC_ELT (*lp_array
, i
, lp
)
441 /* The array may contain NULL landing pads. */
445 gcc_assert (i
== (unsigned) lp
->index
);
446 FIXUP_EH_LP (lp
->next_lp
);
447 FIXUP_EH_REGION (lp
->region
);
450 #undef FIXUP_EH_REGION
455 /* Initialize EH support. */
460 static bool eh_initialized_p
= false;
462 if (eh_initialized_p
)
465 /* Contrary to most other FEs, we only initialize EH support when at
466 least one of the files in the set contains exception regions in
467 it. Since this happens much later than the call to init_eh in
468 lang_dependent_init, we have to set flag_exceptions and call
469 init_eh again to initialize the EH tables. */
473 eh_initialized_p
= true;
477 /* Read the exception table for FN from IB using the data descriptors
481 input_eh_regions (struct lto_input_block
*ib
, struct data_in
*data_in
,
484 HOST_WIDE_INT i
, root_region
, len
;
487 tag
= streamer_read_record_start (ib
);
491 lto_tag_check_range (tag
, LTO_eh_table
, LTO_eh_table
);
493 /* If the file contains EH regions, then it was compiled with
494 -fexceptions. In that case, initialize the backend EH
500 root_region
= streamer_read_hwi (ib
);
501 gcc_assert (root_region
== (int) root_region
);
503 /* Read the EH region array. */
504 len
= streamer_read_hwi (ib
);
505 gcc_assert (len
== (int) len
);
508 vec_safe_grow_cleared (fn
->eh
->region_array
, len
);
509 for (i
= 0; i
< len
; i
++)
511 eh_region r
= input_eh_region (ib
, data_in
, i
);
512 (*fn
->eh
->region_array
)[i
] = r
;
516 /* Read the landing pads. */
517 len
= streamer_read_hwi (ib
);
518 gcc_assert (len
== (int) len
);
521 vec_safe_grow_cleared (fn
->eh
->lp_array
, len
);
522 for (i
= 0; i
< len
; i
++)
524 eh_landing_pad lp
= input_eh_lp (ib
, data_in
, i
);
525 (*fn
->eh
->lp_array
)[i
] = lp
;
529 /* Read the runtime type data. */
530 len
= streamer_read_hwi (ib
);
531 gcc_assert (len
== (int) len
);
534 vec_safe_grow_cleared (fn
->eh
->ttype_data
, len
);
535 for (i
= 0; i
< len
; i
++)
537 tree ttype
= stream_read_tree (ib
, data_in
);
538 (*fn
->eh
->ttype_data
)[i
] = ttype
;
542 /* Read the table of action chains. */
543 len
= streamer_read_hwi (ib
);
544 gcc_assert (len
== (int) len
);
547 if (targetm
.arm_eabi_unwinder
)
549 vec_safe_grow_cleared (fn
->eh
->ehspec_data
.arm_eabi
, len
);
550 for (i
= 0; i
< len
; i
++)
552 tree t
= stream_read_tree (ib
, data_in
);
553 (*fn
->eh
->ehspec_data
.arm_eabi
)[i
] = t
;
558 vec_safe_grow_cleared (fn
->eh
->ehspec_data
.other
, len
);
559 for (i
= 0; i
< len
; i
++)
561 uchar c
= streamer_read_uchar (ib
);
562 (*fn
->eh
->ehspec_data
.other
)[i
] = c
;
567 /* Reconstruct the EH region tree by fixing up the peer/children
569 fixup_eh_region_pointers (fn
, root_region
);
571 tag
= streamer_read_record_start (ib
);
572 lto_tag_check_range (tag
, LTO_null
, LTO_null
);
576 /* Make a new basic block with index INDEX in function FN. */
579 make_new_block (struct function
*fn
, unsigned int index
)
581 basic_block bb
= alloc_block ();
583 SET_BASIC_BLOCK_FOR_FUNCTION (fn
, index
, bb
);
584 n_basic_blocks_for_function (fn
)++;
589 /* Read the CFG for function FN from input block IB. */
592 input_cfg (struct lto_input_block
*ib
, struct function
*fn
,
593 int count_materialization_scale
)
595 unsigned int bb_count
;
600 init_empty_tree_cfg_for_function (fn
);
601 init_ssa_operands (fn
);
603 profile_status_for_function (fn
) = streamer_read_enum (ib
, profile_status_d
,
606 bb_count
= streamer_read_uhwi (ib
);
608 last_basic_block_for_function (fn
) = bb_count
;
609 if (bb_count
> basic_block_info_for_function (fn
)->length ())
610 vec_safe_grow_cleared (basic_block_info_for_function (fn
), bb_count
);
612 if (bb_count
> label_to_block_map_for_function (fn
)->length ())
613 vec_safe_grow_cleared (label_to_block_map_for_function (fn
), bb_count
);
615 index
= streamer_read_hwi (ib
);
618 basic_block bb
= BASIC_BLOCK_FOR_FUNCTION (fn
, index
);
619 unsigned int edge_count
;
622 bb
= make_new_block (fn
, index
);
624 edge_count
= streamer_read_uhwi (ib
);
626 /* Connect up the CFG. */
627 for (i
= 0; i
< edge_count
; i
++)
629 unsigned int dest_index
;
630 unsigned int edge_flags
;
636 dest_index
= streamer_read_uhwi (ib
);
637 probability
= (int) streamer_read_hwi (ib
);
638 count
= apply_scale ((gcov_type
) streamer_read_gcov_count (ib
),
639 count_materialization_scale
);
640 edge_flags
= streamer_read_uhwi (ib
);
642 dest
= BASIC_BLOCK_FOR_FUNCTION (fn
, dest_index
);
645 dest
= make_new_block (fn
, dest_index
);
647 e
= make_edge (bb
, dest
, edge_flags
);
648 e
->probability
= probability
;
652 index
= streamer_read_hwi (ib
);
655 p_bb
= ENTRY_BLOCK_PTR_FOR_FUNCTION(fn
);
656 index
= streamer_read_hwi (ib
);
659 basic_block bb
= BASIC_BLOCK_FOR_FUNCTION (fn
, index
);
663 index
= streamer_read_hwi (ib
);
666 /* ??? The cfgloop interface is tied to cfun. */
667 gcc_assert (cfun
== fn
);
669 /* Input the loop tree. */
670 unsigned n_loops
= streamer_read_uhwi (ib
);
674 struct loops
*loops
= ggc_alloc_cleared_loops ();
675 init_loops_structure (fn
, loops
, n_loops
);
676 set_loops_for_fn (fn
, loops
);
678 /* Input each loop and associate it with its loop header so
679 flow_loops_find can rebuild the loop tree. */
680 for (unsigned i
= 1; i
< n_loops
; ++i
)
682 int header_index
= streamer_read_hwi (ib
);
683 if (header_index
== -1)
685 loops
->larray
->quick_push (NULL
);
689 struct loop
*loop
= alloc_loop ();
690 loop
->header
= BASIC_BLOCK_FOR_FUNCTION (fn
, header_index
);
691 loop
->header
->loop_father
= loop
;
693 /* Read everything copy_loop_info copies. */
694 loop
->estimate_state
= streamer_read_enum (ib
, loop_estimation
, EST_LAST
);
695 loop
->any_upper_bound
= streamer_read_hwi (ib
);
696 if (loop
->any_upper_bound
)
698 loop
->nb_iterations_upper_bound
.low
= streamer_read_uhwi (ib
);
699 loop
->nb_iterations_upper_bound
.high
= streamer_read_hwi (ib
);
701 loop
->any_estimate
= streamer_read_hwi (ib
);
702 if (loop
->any_estimate
)
704 loop
->nb_iterations_estimate
.low
= streamer_read_uhwi (ib
);
705 loop
->nb_iterations_estimate
.high
= streamer_read_hwi (ib
);
708 place_new_loop (fn
, loop
);
710 /* flow_loops_find doesn't like loops not in the tree, hook them
711 all as siblings of the tree root temporarily. */
712 flow_loop_tree_node_add (loops
->tree_root
, loop
);
715 /* Rebuild the loop tree. */
716 flow_loops_find (loops
);
720 /* Read the SSA names array for function FN from DATA_IN using input
724 input_ssa_names (struct lto_input_block
*ib
, struct data_in
*data_in
,
727 unsigned int i
, size
;
729 size
= streamer_read_uhwi (ib
);
730 init_ssanames (fn
, size
);
732 i
= streamer_read_uhwi (ib
);
738 /* Skip over the elements that had been freed. */
739 while (SSANAMES (fn
)->length () < i
)
740 SSANAMES (fn
)->quick_push (NULL_TREE
);
742 is_default_def
= (streamer_read_uchar (ib
) != 0);
743 name
= stream_read_tree (ib
, data_in
);
744 ssa_name
= make_ssa_name_fn (fn
, name
, gimple_build_nop ());
747 set_ssa_default_def (cfun
, SSA_NAME_VAR (ssa_name
), ssa_name
);
749 i
= streamer_read_uhwi (ib
);
754 /* Go through all NODE edges and fixup call_stmt pointers
755 so they point to STMTS. */
758 fixup_call_stmt_edges_1 (struct cgraph_node
*node
, gimple
*stmts
)
760 struct cgraph_edge
*cedge
;
761 for (cedge
= node
->callees
; cedge
; cedge
= cedge
->next_callee
)
762 cedge
->call_stmt
= stmts
[cedge
->lto_stmt_uid
];
763 for (cedge
= node
->indirect_calls
; cedge
; cedge
= cedge
->next_callee
)
764 cedge
->call_stmt
= stmts
[cedge
->lto_stmt_uid
];
767 /* Fixup call_stmt pointers in NODE and all clones. */
770 fixup_call_stmt_edges (struct cgraph_node
*orig
, gimple
*stmts
)
772 struct cgraph_node
*node
;
774 while (orig
->clone_of
)
775 orig
= orig
->clone_of
;
777 fixup_call_stmt_edges_1 (orig
, stmts
);
779 for (node
= orig
->clones
; node
!= orig
;)
781 fixup_call_stmt_edges_1 (node
, stmts
);
784 else if (node
->next_sibling_clone
)
785 node
= node
->next_sibling_clone
;
788 while (node
!= orig
&& !node
->next_sibling_clone
)
789 node
= node
->clone_of
;
791 node
= node
->next_sibling_clone
;
797 /* Input the base body of struct function FN from DATA_IN
798 using input block IB. */
801 input_struct_function_base (struct function
*fn
, struct data_in
*data_in
,
802 struct lto_input_block
*ib
)
807 /* Read the static chain and non-local goto save area. */
808 fn
->static_chain_decl
= stream_read_tree (ib
, data_in
);
809 fn
->nonlocal_goto_save_area
= stream_read_tree (ib
, data_in
);
811 /* Read all the local symbols. */
812 len
= streamer_read_hwi (ib
);
816 vec_safe_grow_cleared (fn
->local_decls
, len
);
817 for (i
= 0; i
< len
; i
++)
819 tree t
= stream_read_tree (ib
, data_in
);
820 (*fn
->local_decls
)[i
] = t
;
824 /* Input the current IL state of the function. */
825 fn
->curr_properties
= streamer_read_uhwi (ib
);
827 /* Read all the attributes for FN. */
828 bp
= streamer_read_bitpack (ib
);
829 fn
->is_thunk
= bp_unpack_value (&bp
, 1);
830 fn
->has_local_explicit_reg_vars
= bp_unpack_value (&bp
, 1);
831 fn
->returns_pcc_struct
= bp_unpack_value (&bp
, 1);
832 fn
->returns_struct
= bp_unpack_value (&bp
, 1);
833 fn
->can_throw_non_call_exceptions
= bp_unpack_value (&bp
, 1);
834 fn
->can_delete_dead_exceptions
= bp_unpack_value (&bp
, 1);
835 fn
->always_inline_functions_inlined
= bp_unpack_value (&bp
, 1);
836 fn
->after_inlining
= bp_unpack_value (&bp
, 1);
837 fn
->stdarg
= bp_unpack_value (&bp
, 1);
838 fn
->has_nonlocal_label
= bp_unpack_value (&bp
, 1);
839 fn
->calls_alloca
= bp_unpack_value (&bp
, 1);
840 fn
->calls_setjmp
= bp_unpack_value (&bp
, 1);
841 fn
->va_list_fpr_size
= bp_unpack_value (&bp
, 8);
842 fn
->va_list_gpr_size
= bp_unpack_value (&bp
, 8);
844 /* Input the function start and end loci. */
845 fn
->function_start_locus
= stream_input_location (&bp
, data_in
);
846 fn
->function_end_locus
= stream_input_location (&bp
, data_in
);
850 /* Read the body of function FN_DECL from DATA_IN using input block IB. */
853 input_function (tree fn_decl
, struct data_in
*data_in
,
854 struct lto_input_block
*ib
, struct lto_input_block
*ib_cfg
)
860 struct cgraph_node
*node
;
862 tag
= streamer_read_record_start (ib
);
863 lto_tag_check (tag
, LTO_function
);
865 /* Read decls for parameters and args. */
866 DECL_RESULT (fn_decl
) = stream_read_tree (ib
, data_in
);
867 DECL_ARGUMENTS (fn_decl
) = streamer_read_chain (ib
, data_in
);
869 /* Read the tree of lexical scopes for the function. */
870 DECL_INITIAL (fn_decl
) = stream_read_tree (ib
, data_in
);
872 if (!streamer_read_uhwi (ib
))
875 push_struct_function (fn_decl
);
876 fn
= DECL_STRUCT_FUNCTION (fn_decl
);
878 /* We input IL in SSA form. */
879 cfun
->gimple_df
->in_ssa_p
= true;
881 gimple_register_cfg_hooks ();
883 node
= cgraph_get_create_node (fn_decl
);
884 input_struct_function_base (fn
, data_in
, ib
);
885 input_cfg (ib_cfg
, fn
, node
->count_materialization_scale
);
887 /* Read all the SSA names. */
888 input_ssa_names (ib
, data_in
, fn
);
890 /* Read the exception handling regions in the function. */
891 input_eh_regions (ib
, data_in
, fn
);
893 gcc_assert (DECL_INITIAL (fn_decl
));
894 DECL_SAVED_TREE (fn_decl
) = NULL_TREE
;
896 /* Read all the basic blocks. */
897 tag
= streamer_read_record_start (ib
);
900 input_bb (ib
, tag
, data_in
, fn
,
901 node
->count_materialization_scale
);
902 tag
= streamer_read_record_start (ib
);
905 /* Fix up the call statements that are mentioned in the callgraph
907 set_gimple_stmt_max_uid (cfun
, 0);
910 gimple_stmt_iterator gsi
;
911 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
913 gimple stmt
= gsi_stmt (gsi
);
914 gimple_set_uid (stmt
, inc_gimple_stmt_max_uid (cfun
));
917 stmts
= (gimple
*) xcalloc (gimple_stmt_max_uid (fn
), sizeof (gimple
));
920 gimple_stmt_iterator bsi
= gsi_start_bb (bb
);
921 while (!gsi_end_p (bsi
))
923 gimple stmt
= gsi_stmt (bsi
);
924 /* If we're recompiling LTO objects with debug stmts but
925 we're not supposed to have debug stmts, remove them now.
926 We can't remove them earlier because this would cause uid
927 mismatches in fixups, but we can do it at this point, as
928 long as debug stmts don't require fixups. */
929 if (!MAY_HAVE_DEBUG_STMTS
&& is_gimple_debug (stmt
))
931 gimple_stmt_iterator gsi
= bsi
;
933 gsi_remove (&gsi
, true);
938 stmts
[gimple_uid (stmt
)] = stmt
;
943 /* Set the gimple body to the statement sequence in the entry
944 basic block. FIXME lto, this is fairly hacky. The existence
945 of a gimple body is used by the cgraph routines, but we should
946 really use the presence of the CFG. */
948 edge_iterator ei
= ei_start (ENTRY_BLOCK_PTR
->succs
);
949 gimple_set_body (fn_decl
, bb_seq (ei_edge (ei
)->dest
));
952 fixup_call_stmt_edges (node
, stmts
);
953 execute_all_ipa_stmt_fixups (node
, stmts
);
955 update_ssa (TODO_update_ssa_only_virtuals
);
956 free_dominance_info (CDI_DOMINATORS
);
957 free_dominance_info (CDI_POST_DOMINATORS
);
962 /* Read the body from DATA for function FN_DECL and fill it in.
963 FILE_DATA are the global decls and types. SECTION_TYPE is either
964 LTO_section_function_body or LTO_section_static_initializer. If
965 section type is LTO_section_function_body, FN must be the decl for
969 lto_read_body (struct lto_file_decl_data
*file_data
, tree fn_decl
,
970 const char *data
, enum lto_section_type section_type
)
972 const struct lto_function_header
*header
;
973 struct data_in
*data_in
;
977 struct lto_input_block ib_cfg
;
978 struct lto_input_block ib_main
;
980 header
= (const struct lto_function_header
*) data
;
981 cfg_offset
= sizeof (struct lto_function_header
);
982 main_offset
= cfg_offset
+ header
->cfg_size
;
983 string_offset
= main_offset
+ header
->main_size
;
985 LTO_INIT_INPUT_BLOCK (ib_cfg
,
990 LTO_INIT_INPUT_BLOCK (ib_main
,
995 data_in
= lto_data_in_create (file_data
, data
+ string_offset
,
996 header
->string_size
, vNULL
);
998 /* Make sure the file was generated by the exact same compiler. */
999 lto_check_version (header
->lto_header
.major_version
,
1000 header
->lto_header
.minor_version
);
1002 if (section_type
== LTO_section_function_body
)
1004 struct lto_in_decl_state
*decl_state
;
1005 struct cgraph_node
*node
= cgraph_get_node (fn_decl
);
1008 gcc_checking_assert (node
);
1010 /* Use the function's decl state. */
1011 decl_state
= lto_get_function_in_decl_state (file_data
, fn_decl
);
1012 gcc_assert (decl_state
);
1013 file_data
->current_decl_state
= decl_state
;
1016 /* Set up the struct function. */
1017 from
= data_in
->reader_cache
->nodes
.length ();
1018 input_function (fn_decl
, data_in
, &ib_main
, &ib_cfg
);
1019 /* And fixup types we streamed locally. */
1021 struct streamer_tree_cache_d
*cache
= data_in
->reader_cache
;
1022 unsigned len
= cache
->nodes
.length ();
1024 for (i
= len
; i
-- > from
;)
1026 tree t
= streamer_tree_cache_get_tree (cache
, i
);
1032 gcc_assert (TYPE_CANONICAL (t
) == NULL_TREE
);
1033 TYPE_CANONICAL (t
) = TYPE_MAIN_VARIANT (t
);
1034 if (TYPE_MAIN_VARIANT (t
) != t
)
1036 gcc_assert (TYPE_NEXT_VARIANT (t
) == NULL_TREE
);
1037 TYPE_NEXT_VARIANT (t
)
1038 = TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t
));
1039 TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t
)) = t
;
1045 /* Restore decl state */
1046 file_data
->current_decl_state
= file_data
->global_decl_state
;
1051 lto_data_in_delete (data_in
);
1055 /* Read the body of FN_DECL using DATA. FILE_DATA holds the global
1059 lto_input_function_body (struct lto_file_decl_data
*file_data
,
1060 tree fn_decl
, const char *data
)
1062 lto_read_body (file_data
, fn_decl
, data
, LTO_section_function_body
);
1066 /* Read the physical representation of a tree node EXPR from
1067 input block IB using the per-file context in DATA_IN. */
1070 lto_read_tree_1 (struct lto_input_block
*ib
, struct data_in
*data_in
, tree expr
)
1072 /* Read all the bitfield values in EXPR. Note that for LTO, we
1073 only write language-independent bitfields, so no more unpacking is
1075 streamer_read_tree_bitfields (ib
, data_in
, expr
);
1077 /* Read all the pointer fields in EXPR. */
1078 streamer_read_tree_body (ib
, data_in
, expr
);
1080 /* Read any LTO-specific data not read by the tree streamer. */
1082 && TREE_CODE (expr
) != FUNCTION_DECL
1083 && TREE_CODE (expr
) != TRANSLATION_UNIT_DECL
)
1084 DECL_INITIAL (expr
) = stream_read_tree (ib
, data_in
);
1086 /* We should never try to instantiate an MD or NORMAL builtin here. */
1087 if (TREE_CODE (expr
) == FUNCTION_DECL
)
1088 gcc_assert (!streamer_handle_as_builtin_p (expr
));
1090 #ifdef LTO_STREAMER_DEBUG
1091 /* Remove the mapping to RESULT's original address set by
1092 streamer_alloc_tree. */
1093 lto_orig_address_remove (expr
);
1097 /* Read the physical representation of a tree node with tag TAG from
1098 input block IB using the per-file context in DATA_IN. */
1101 lto_read_tree (struct lto_input_block
*ib
, struct data_in
*data_in
,
1102 enum LTO_tags tag
, hashval_t hash
)
1104 /* Instantiate a new tree node. */
1105 tree result
= streamer_alloc_tree (ib
, data_in
, tag
);
1107 /* Enter RESULT in the reader cache. This will make RESULT
1108 available so that circular references in the rest of the tree
1109 structure can be resolved in subsequent calls to stream_read_tree. */
1110 streamer_tree_cache_append (data_in
->reader_cache
, result
, hash
);
1112 lto_read_tree_1 (ib
, data_in
, result
);
1114 /* end_marker = */ streamer_read_uchar (ib
);
1120 /* Populate the reader cache with trees materialized from the SCC
1121 following in the IB, DATA_IN stream. */
1124 lto_input_scc (struct lto_input_block
*ib
, struct data_in
*data_in
,
1125 unsigned *len
, unsigned *entry_len
)
1127 /* A blob of unnamed tree nodes, fill the cache from it and
1129 unsigned size
= streamer_read_uhwi (ib
);
1130 hashval_t scc_hash
= streamer_read_uhwi (ib
);
1131 unsigned scc_entry_len
= 1;
1135 enum LTO_tags tag
= streamer_read_record_start (ib
);
1136 lto_input_tree_1 (ib
, data_in
, tag
, scc_hash
);
1140 unsigned int first
= data_in
->reader_cache
->nodes
.length ();
1143 scc_entry_len
= streamer_read_uhwi (ib
);
1145 /* Materialize size trees by reading their headers. */
1146 for (unsigned i
= 0; i
< size
; ++i
)
1148 enum LTO_tags tag
= streamer_read_record_start (ib
);
1150 || (tag
>= LTO_field_decl_ref
&& tag
<= LTO_global_decl_ref
)
1151 || tag
== LTO_tree_pickle_reference
1152 || tag
== LTO_builtin_decl
1153 || tag
== LTO_integer_cst
1154 || tag
== LTO_tree_scc
)
1157 result
= streamer_alloc_tree (ib
, data_in
, tag
);
1158 streamer_tree_cache_append (data_in
->reader_cache
, result
, 0);
1161 /* Read the tree bitpacks and references. */
1162 for (unsigned i
= 0; i
< size
; ++i
)
1164 result
= streamer_tree_cache_get_tree (data_in
->reader_cache
,
1166 lto_read_tree_1 (ib
, data_in
, result
);
1167 /* end_marker = */ streamer_read_uchar (ib
);
1172 *entry_len
= scc_entry_len
;
1177 /* Read a tree from input block IB using the per-file context in
1178 DATA_IN. This context is used, for example, to resolve references
1179 to previously read nodes. */
1182 lto_input_tree_1 (struct lto_input_block
*ib
, struct data_in
*data_in
,
1183 enum LTO_tags tag
, hashval_t hash
)
1187 gcc_assert ((unsigned) tag
< (unsigned) LTO_NUM_TAGS
);
1189 if (tag
== LTO_null
)
1191 else if (tag
>= LTO_field_decl_ref
&& tag
<= LTO_global_decl_ref
)
1193 /* If TAG is a reference to an indexable tree, the next value
1194 in IB is the index into the table where we expect to find
1196 result
= lto_input_tree_ref (ib
, data_in
, cfun
, tag
);
1198 else if (tag
== LTO_tree_pickle_reference
)
1200 /* If TAG is a reference to a previously read tree, look it up in
1201 the reader cache. */
1202 result
= streamer_get_pickled_tree (ib
, data_in
);
1204 else if (tag
== LTO_builtin_decl
)
1206 /* If we are going to read a built-in function, all we need is
1207 the code and class. */
1208 result
= streamer_get_builtin_tree (ib
, data_in
);
1210 else if (tag
== LTO_integer_cst
)
1212 /* For shared integer constants in singletons we can use the existing
1213 tree integer constant merging code. */
1214 tree type
= stream_read_tree (ib
, data_in
);
1215 unsigned HOST_WIDE_INT low
= streamer_read_uhwi (ib
);
1216 HOST_WIDE_INT high
= streamer_read_hwi (ib
);
1217 result
= build_int_cst_wide (type
, low
, high
);
1218 streamer_tree_cache_append (data_in
->reader_cache
, result
, hash
);
1220 else if (tag
== LTO_tree_scc
)
1222 unsigned len
, entry_len
;
1224 /* Input and skip the SCC. */
1225 lto_input_scc (ib
, data_in
, &len
, &entry_len
);
1228 return lto_input_tree (ib
, data_in
);
1232 /* Otherwise, materialize a new node from IB. */
1233 result
= lto_read_tree (ib
, data_in
, tag
, hash
);
1240 lto_input_tree (struct lto_input_block
*ib
, struct data_in
*data_in
)
1242 return lto_input_tree_1 (ib
, data_in
, streamer_read_record_start (ib
), 0);
1246 /* Input toplevel asms. */
1249 lto_input_toplevel_asms (struct lto_file_decl_data
*file_data
, int order_base
)
1252 const char *data
= lto_get_section_data (file_data
, LTO_section_asm
,
1254 const struct lto_asm_header
*header
= (const struct lto_asm_header
*) data
;
1256 struct data_in
*data_in
;
1257 struct lto_input_block ib
;
1263 string_offset
= sizeof (*header
) + header
->main_size
;
1265 LTO_INIT_INPUT_BLOCK (ib
,
1266 data
+ sizeof (*header
),
1270 data_in
= lto_data_in_create (file_data
, data
+ string_offset
,
1271 header
->string_size
, vNULL
);
1273 /* Make sure the file was generated by the exact same compiler. */
1274 lto_check_version (header
->lto_header
.major_version
,
1275 header
->lto_header
.minor_version
);
1277 while ((str
= streamer_read_string_cst (data_in
, &ib
)))
1279 struct asm_node
*node
= add_asm_node (str
);
1280 node
->order
= streamer_read_hwi (&ib
) + order_base
;
1281 if (node
->order
>= symtab_order
)
1282 symtab_order
= node
->order
+ 1;
1285 lto_data_in_delete (data_in
);
1287 lto_free_section_data (file_data
, LTO_section_asm
, NULL
, data
, len
);
1291 /* Initialization for the LTO reader. */
1294 lto_reader_init (void)
1296 lto_streamer_init ();
1297 file_name_hash_table
.create (37);
1301 /* Create a new data_in object for FILE_DATA. STRINGS is the string
1302 table to use with LEN strings. RESOLUTIONS is the vector of linker
1303 resolutions (NULL if not using a linker plugin). */
1306 lto_data_in_create (struct lto_file_decl_data
*file_data
, const char *strings
,
1308 vec
<ld_plugin_symbol_resolution_t
> resolutions
)
1310 struct data_in
*data_in
= XCNEW (struct data_in
);
1311 data_in
->file_data
= file_data
;
1312 data_in
->strings
= strings
;
1313 data_in
->strings_len
= len
;
1314 data_in
->globals_resolution
= resolutions
;
1315 data_in
->reader_cache
= streamer_tree_cache_create (false, false);
1321 /* Remove DATA_IN. */
1324 lto_data_in_delete (struct data_in
*data_in
)
1326 data_in
->globals_resolution
.release ();
1327 streamer_tree_cache_delete (data_in
->reader_cache
);
1328 free (data_in
->labels
);