1 /* Write the GIMPLE representation to 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"
33 #include "basic-block.h"
34 #include "tree-flow.h"
35 #include "tree-pass.h"
39 #include "diagnostic-core.h"
42 #include "lto-symtab.h"
43 #include "lto-streamer.h"
44 #include "data-streamer.h"
45 #include "gimple-streamer.h"
46 #include "tree-streamer.h"
47 #include "streamer-hooks.h"
50 /* Clear the line info stored in DATA_IN. */
53 clear_line_info (struct output_block
*ob
)
55 ob
->current_file
= NULL
;
61 /* Create the output block and return it. SECTION_TYPE is
62 LTO_section_function_body or LTO_static_initializer. */
65 create_output_block (enum lto_section_type section_type
)
67 struct output_block
*ob
= XCNEW (struct output_block
);
69 ob
->section_type
= section_type
;
70 ob
->decl_state
= lto_get_out_decl_state ();
71 ob
->main_stream
= XCNEW (struct lto_output_stream
);
72 ob
->string_stream
= XCNEW (struct lto_output_stream
);
73 ob
->writer_cache
= streamer_tree_cache_create ();
75 if (section_type
== LTO_section_function_body
)
76 ob
->cfg_stream
= XCNEW (struct lto_output_stream
);
80 ob
->string_hash_table
= htab_create (37, hash_string_slot_node
,
81 eq_string_slot_node
, NULL
);
82 gcc_obstack_init (&ob
->obstack
);
88 /* Destroy the output block OB. */
91 destroy_output_block (struct output_block
*ob
)
93 enum lto_section_type section_type
= ob
->section_type
;
95 htab_delete (ob
->string_hash_table
);
97 free (ob
->main_stream
);
98 free (ob
->string_stream
);
99 if (section_type
== LTO_section_function_body
)
100 free (ob
->cfg_stream
);
102 streamer_tree_cache_delete (ob
->writer_cache
);
103 obstack_free (&ob
->obstack
, NULL
);
109 /* Look up NODE in the type table and write the index for it to OB. */
112 output_type_ref (struct output_block
*ob
, tree node
)
114 streamer_write_record_start (ob
, LTO_type_ref
);
115 lto_output_type_ref_index (ob
->decl_state
, ob
->main_stream
, node
);
119 /* Return true if tree node T is written to various tables. For these
120 nodes, we sometimes want to write their phyiscal representation
121 (via lto_output_tree), and sometimes we need to emit an index
122 reference into a table (via lto_output_tree_ref). */
125 tree_is_indexable (tree t
)
127 if (TREE_CODE (t
) == PARM_DECL
)
129 else if (TREE_CODE (t
) == VAR_DECL
&& decl_function_context (t
)
133 return (TYPE_P (t
) || DECL_P (t
) || TREE_CODE (t
) == SSA_NAME
);
137 /* Output info about new location into bitpack BP.
138 After outputting bitpack, lto_output_location_data has
139 to be done to output actual data. */
142 lto_output_location_bitpack (struct bitpack_d
*bp
,
143 struct output_block
*ob
,
146 expanded_location xloc
;
148 bp_pack_value (bp
, loc
== UNKNOWN_LOCATION
, 1);
149 if (loc
== UNKNOWN_LOCATION
)
152 xloc
= expand_location (loc
);
154 bp_pack_value (bp
, ob
->current_file
!= xloc
.file
, 1);
155 if (ob
->current_file
!= xloc
.file
)
156 bp_pack_var_len_unsigned (bp
,
157 streamer_string_index (ob
, xloc
.file
,
158 strlen (xloc
.file
) + 1,
160 ob
->current_file
= xloc
.file
;
162 bp_pack_value (bp
, ob
->current_line
!= xloc
.line
, 1);
163 if (ob
->current_line
!= xloc
.line
)
164 bp_pack_var_len_unsigned (bp
, xloc
.line
);
165 ob
->current_line
= xloc
.line
;
167 bp_pack_value (bp
, ob
->current_col
!= xloc
.column
, 1);
168 if (ob
->current_col
!= xloc
.column
)
169 bp_pack_var_len_unsigned (bp
, xloc
.column
);
170 ob
->current_col
= xloc
.column
;
174 /* Emit location LOC to output block OB.
175 If the output_location streamer hook exists, call it.
176 Otherwise, when bitpack is handy, it is more space efficient to call
177 lto_output_location_bitpack with existing bitpack. */
180 lto_output_location (struct output_block
*ob
, location_t loc
)
182 if (streamer_hooks
.output_location
)
183 streamer_hooks
.output_location (ob
, loc
);
186 struct bitpack_d bp
= bitpack_create (ob
->main_stream
);
187 lto_output_location_bitpack (&bp
, ob
, loc
);
188 streamer_write_bitpack (&bp
);
193 /* If EXPR is an indexable tree node, output a reference to it to
194 output block OB. Otherwise, output the physical representation of
198 lto_output_tree_ref (struct output_block
*ob
, tree expr
)
204 output_type_ref (ob
, expr
);
208 code
= TREE_CODE (expr
);
212 streamer_write_record_start (ob
, LTO_ssa_name_ref
);
213 streamer_write_uhwi (ob
, SSA_NAME_VERSION (expr
));
217 streamer_write_record_start (ob
, LTO_field_decl_ref
);
218 lto_output_field_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
222 streamer_write_record_start (ob
, LTO_function_decl_ref
);
223 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
227 case DEBUG_EXPR_DECL
:
228 gcc_assert (decl_function_context (expr
) == NULL
|| TREE_STATIC (expr
));
229 streamer_write_record_start (ob
, LTO_global_decl_ref
);
230 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
234 streamer_write_record_start (ob
, LTO_const_decl_ref
);
235 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
239 gcc_assert (decl_function_context (expr
) == NULL
);
240 streamer_write_record_start (ob
, LTO_imported_decl_ref
);
241 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
245 streamer_write_record_start (ob
, LTO_type_decl_ref
);
246 lto_output_type_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
250 streamer_write_record_start (ob
, LTO_namespace_decl_ref
);
251 lto_output_namespace_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
255 streamer_write_record_start (ob
, LTO_label_decl_ref
);
256 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
260 streamer_write_record_start (ob
, LTO_result_decl_ref
);
261 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
264 case TRANSLATION_UNIT_DECL
:
265 streamer_write_record_start (ob
, LTO_translation_unit_decl_ref
);
266 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
270 /* No other node is indexable, so it should have been handled by
277 /* Return true if EXPR is a tree node that can be written to disk. */
280 lto_is_streamable (tree expr
)
282 enum tree_code code
= TREE_CODE (expr
);
284 /* Notice that we reject SSA_NAMEs as well. We only emit the SSA
285 name version in lto_output_tree_ref (see output_ssa_names). */
286 return !is_lang_specific (expr
)
290 && code
!= MODIFY_EXPR
292 && code
!= TARGET_EXPR
294 && code
!= WITH_CLEANUP_EXPR
295 && code
!= STATEMENT_LIST
296 && code
!= OMP_CLAUSE
297 && code
!= OPTIMIZATION_NODE
298 && (code
== CASE_LABEL_EXPR
300 || TREE_CODE_CLASS (code
) != tcc_statement
);
304 /* Write a physical representation of tree node EXPR to output block
305 OB. If REF_P is true, the leaves of EXPR are emitted as references
306 via lto_output_tree_ref. IX is the index into the streamer cache
307 where EXPR is stored. */
310 lto_write_tree (struct output_block
*ob
, tree expr
, bool ref_p
)
314 if (!lto_is_streamable (expr
))
315 internal_error ("tree code %qs is not supported in LTO streams",
316 tree_code_name
[TREE_CODE (expr
)]);
318 /* Write the header, containing everything needed to materialize
319 EXPR on the reading side. */
320 streamer_write_tree_header (ob
, expr
);
322 /* Pack all the non-pointer fields in EXPR into a bitpack and write
323 the resulting bitpack. */
324 bp
= bitpack_create (ob
->main_stream
);
325 streamer_pack_tree_bitfields (&bp
, expr
);
326 streamer_write_bitpack (&bp
);
328 /* Write all the pointer fields in EXPR. */
329 streamer_write_tree_body (ob
, expr
, ref_p
);
331 /* Write any LTO-specific data to OB. */
333 && TREE_CODE (expr
) != FUNCTION_DECL
334 && TREE_CODE (expr
) != TRANSLATION_UNIT_DECL
)
336 /* Handle DECL_INITIAL for symbols. */
337 tree initial
= DECL_INITIAL (expr
);
338 if (TREE_CODE (expr
) == VAR_DECL
339 && (TREE_STATIC (expr
) || DECL_EXTERNAL (expr
))
342 lto_varpool_encoder_t varpool_encoder
;
343 struct varpool_node
*vnode
;
345 varpool_encoder
= ob
->decl_state
->varpool_node_encoder
;
346 vnode
= varpool_get_node (expr
);
348 initial
= error_mark_node
;
349 else if (!lto_varpool_encoder_encode_initializer_p (varpool_encoder
,
354 stream_write_tree (ob
, initial
, ref_p
);
357 /* Mark the end of EXPR. */
358 streamer_write_zero (ob
);
362 /* Emit the physical representation of tree node EXPR to output block
363 OB. If REF_P is true, the leaves of EXPR are emitted as references
364 via lto_output_tree_ref. */
367 lto_output_tree (struct output_block
*ob
, tree expr
, bool ref_p
)
372 if (expr
== NULL_TREE
)
374 streamer_write_record_start (ob
, LTO_null
);
378 if (ref_p
&& tree_is_indexable (expr
))
380 lto_output_tree_ref (ob
, expr
);
384 /* INTEGER_CST nodes are special because they need their original type
385 to be materialized by the reader (to implement TYPE_CACHED_VALUES). */
386 if (TREE_CODE (expr
) == INTEGER_CST
)
388 streamer_write_integer_cst (ob
, expr
, ref_p
);
392 existed_p
= streamer_tree_cache_insert (ob
->writer_cache
, expr
, &ix
);
395 /* If a node has already been streamed out, make sure that
396 we don't write it more than once. Otherwise, the reader
397 will instantiate two different nodes for the same object. */
398 streamer_write_record_start (ob
, LTO_tree_pickle_reference
);
399 streamer_write_uhwi (ob
, ix
);
400 streamer_write_enum (ob
->main_stream
, LTO_tags
, LTO_NUM_TAGS
,
401 lto_tree_code_to_tag (TREE_CODE (expr
)));
403 else if (streamer_handle_as_builtin_p (expr
))
405 /* MD and NORMAL builtins do not need to be written out
406 completely as they are always instantiated by the
407 compiler on startup. The only builtins that need to
408 be written out are BUILT_IN_FRONTEND. For all other
409 builtins, we simply write the class and code. */
410 streamer_write_builtin (ob
, expr
);
414 /* This is the first time we see EXPR, write its fields
416 lto_write_tree (ob
, expr
, ref_p
);
421 /* Output to OB a list of try/catch handlers starting with FIRST. */
424 output_eh_try_list (struct output_block
*ob
, eh_catch first
)
428 for (n
= first
; n
; n
= n
->next_catch
)
430 streamer_write_record_start (ob
, LTO_eh_catch
);
431 stream_write_tree (ob
, n
->type_list
, true);
432 stream_write_tree (ob
, n
->filter_list
, true);
433 stream_write_tree (ob
, n
->label
, true);
436 streamer_write_record_start (ob
, LTO_null
);
440 /* Output EH region R in function FN to OB. CURR_RN is the slot index
441 that is being emitted in FN->EH->REGION_ARRAY. This is used to
442 detect EH region sharing. */
445 output_eh_region (struct output_block
*ob
, eh_region r
)
451 streamer_write_record_start (ob
, LTO_null
);
455 if (r
->type
== ERT_CLEANUP
)
456 tag
= LTO_ert_cleanup
;
457 else if (r
->type
== ERT_TRY
)
459 else if (r
->type
== ERT_ALLOWED_EXCEPTIONS
)
460 tag
= LTO_ert_allowed_exceptions
;
461 else if (r
->type
== ERT_MUST_NOT_THROW
)
462 tag
= LTO_ert_must_not_throw
;
466 streamer_write_record_start (ob
, tag
);
467 streamer_write_hwi (ob
, r
->index
);
470 streamer_write_hwi (ob
, r
->outer
->index
);
472 streamer_write_zero (ob
);
475 streamer_write_hwi (ob
, r
->inner
->index
);
477 streamer_write_zero (ob
);
480 streamer_write_hwi (ob
, r
->next_peer
->index
);
482 streamer_write_zero (ob
);
484 if (r
->type
== ERT_TRY
)
486 output_eh_try_list (ob
, r
->u
.eh_try
.first_catch
);
488 else if (r
->type
== ERT_ALLOWED_EXCEPTIONS
)
490 stream_write_tree (ob
, r
->u
.allowed
.type_list
, true);
491 stream_write_tree (ob
, r
->u
.allowed
.label
, true);
492 streamer_write_uhwi (ob
, r
->u
.allowed
.filter
);
494 else if (r
->type
== ERT_MUST_NOT_THROW
)
496 stream_write_tree (ob
, r
->u
.must_not_throw
.failure_decl
, true);
497 lto_output_location (ob
, r
->u
.must_not_throw
.failure_loc
);
501 streamer_write_hwi (ob
, r
->landing_pads
->index
);
503 streamer_write_zero (ob
);
507 /* Output landing pad LP to OB. */
510 output_eh_lp (struct output_block
*ob
, eh_landing_pad lp
)
514 streamer_write_record_start (ob
, LTO_null
);
518 streamer_write_record_start (ob
, LTO_eh_landing_pad
);
519 streamer_write_hwi (ob
, lp
->index
);
521 streamer_write_hwi (ob
, lp
->next_lp
->index
);
523 streamer_write_zero (ob
);
526 streamer_write_hwi (ob
, lp
->region
->index
);
528 streamer_write_zero (ob
);
530 stream_write_tree (ob
, lp
->post_landing_pad
, true);
534 /* Output the existing eh_table to OB. */
537 output_eh_regions (struct output_block
*ob
, struct function
*fn
)
539 if (fn
->eh
&& fn
->eh
->region_tree
)
546 streamer_write_record_start (ob
, LTO_eh_table
);
548 /* Emit the index of the root of the EH region tree. */
549 streamer_write_hwi (ob
, fn
->eh
->region_tree
->index
);
551 /* Emit all the EH regions in the region array. */
552 streamer_write_hwi (ob
, VEC_length (eh_region
, fn
->eh
->region_array
));
553 FOR_EACH_VEC_ELT (eh_region
, fn
->eh
->region_array
, i
, eh
)
554 output_eh_region (ob
, eh
);
556 /* Emit all landing pads. */
557 streamer_write_hwi (ob
, VEC_length (eh_landing_pad
, fn
->eh
->lp_array
));
558 FOR_EACH_VEC_ELT (eh_landing_pad
, fn
->eh
->lp_array
, i
, lp
)
559 output_eh_lp (ob
, lp
);
561 /* Emit all the runtime type data. */
562 streamer_write_hwi (ob
, VEC_length (tree
, fn
->eh
->ttype_data
));
563 FOR_EACH_VEC_ELT (tree
, fn
->eh
->ttype_data
, i
, ttype
)
564 stream_write_tree (ob
, ttype
, true);
566 /* Emit the table of action chains. */
567 if (targetm
.arm_eabi_unwinder
)
570 streamer_write_hwi (ob
, VEC_length (tree
,
571 fn
->eh
->ehspec_data
.arm_eabi
));
572 FOR_EACH_VEC_ELT (tree
, fn
->eh
->ehspec_data
.arm_eabi
, i
, t
)
573 stream_write_tree (ob
, t
, true);
578 streamer_write_hwi (ob
, VEC_length (uchar
,
579 fn
->eh
->ehspec_data
.other
));
580 FOR_EACH_VEC_ELT (uchar
, fn
->eh
->ehspec_data
.other
, i
, c
)
581 streamer_write_char_stream (ob
->main_stream
, c
);
585 /* The LTO_null either terminates the record or indicates that there
586 are no eh_records at all. */
587 streamer_write_record_start (ob
, LTO_null
);
591 /* Output all of the active ssa names to the ssa_names stream. */
594 output_ssa_names (struct output_block
*ob
, struct function
*fn
)
598 len
= VEC_length (tree
, SSANAMES (fn
));
599 streamer_write_uhwi (ob
, len
);
601 for (i
= 1; i
< len
; i
++)
603 tree ptr
= VEC_index (tree
, SSANAMES (fn
), i
);
606 || SSA_NAME_IN_FREE_LIST (ptr
)
607 || !is_gimple_reg (ptr
))
610 streamer_write_uhwi (ob
, i
);
611 streamer_write_char_stream (ob
->main_stream
,
612 SSA_NAME_IS_DEFAULT_DEF (ptr
));
613 stream_write_tree (ob
, SSA_NAME_VAR (ptr
), true);
616 streamer_write_zero (ob
);
620 /* Output the cfg. */
623 output_cfg (struct output_block
*ob
, struct function
*fn
)
625 struct lto_output_stream
*tmp_stream
= ob
->main_stream
;
628 ob
->main_stream
= ob
->cfg_stream
;
630 streamer_write_enum (ob
->main_stream
, profile_status_d
, PROFILE_LAST
,
631 profile_status_for_function (fn
));
633 /* Output the number of the highest basic block. */
634 streamer_write_uhwi (ob
, last_basic_block_for_function (fn
));
636 FOR_ALL_BB_FN (bb
, fn
)
641 streamer_write_hwi (ob
, bb
->index
);
643 /* Output the successors and the edge flags. */
644 streamer_write_uhwi (ob
, EDGE_COUNT (bb
->succs
));
645 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
647 streamer_write_uhwi (ob
, e
->dest
->index
);
648 streamer_write_hwi (ob
, e
->probability
);
649 streamer_write_hwi (ob
, e
->count
);
650 streamer_write_uhwi (ob
, e
->flags
);
654 streamer_write_hwi (ob
, -1);
656 bb
= ENTRY_BLOCK_PTR
;
659 streamer_write_hwi (ob
, bb
->next_bb
->index
);
663 streamer_write_hwi (ob
, -1);
665 ob
->main_stream
= tmp_stream
;
669 /* Create the header in the file using OB. If the section type is for
670 a function, set FN to the decl for that function. */
673 produce_asm (struct output_block
*ob
, tree fn
)
675 enum lto_section_type section_type
= ob
->section_type
;
676 struct lto_function_header header
;
678 struct lto_output_stream
*header_stream
;
680 if (section_type
== LTO_section_function_body
)
682 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn
));
683 section_name
= lto_get_section_name (section_type
, name
, NULL
);
686 section_name
= lto_get_section_name (section_type
, NULL
, NULL
);
688 lto_begin_section (section_name
, !flag_wpa
);
691 /* The entire header is stream computed here. */
692 memset (&header
, 0, sizeof (struct lto_function_header
));
694 /* Write the header. */
695 header
.lto_header
.major_version
= LTO_major_version
;
696 header
.lto_header
.minor_version
= LTO_minor_version
;
697 header
.lto_header
.section_type
= section_type
;
699 header
.compressed_size
= 0;
701 if (section_type
== LTO_section_function_body
)
702 header
.cfg_size
= ob
->cfg_stream
->total_size
;
703 header
.main_size
= ob
->main_stream
->total_size
;
704 header
.string_size
= ob
->string_stream
->total_size
;
706 header_stream
= XCNEW (struct lto_output_stream
);
707 lto_output_data_stream (header_stream
, &header
, sizeof header
);
708 lto_write_stream (header_stream
);
709 free (header_stream
);
711 /* Put all of the gimple and the string table out the asm file as a
713 if (section_type
== LTO_section_function_body
)
714 lto_write_stream (ob
->cfg_stream
);
715 lto_write_stream (ob
->main_stream
);
716 lto_write_stream (ob
->string_stream
);
722 /* Output the body of function NODE->DECL. */
725 output_function (struct cgraph_node
*node
)
731 struct output_block
*ob
;
735 function
= node
->decl
;
736 fn
= DECL_STRUCT_FUNCTION (function
);
737 ob
= create_output_block (LTO_section_function_body
);
739 clear_line_info (ob
);
740 ob
->cgraph_node
= node
;
742 gcc_assert (current_function_decl
== NULL_TREE
&& cfun
== NULL
);
744 /* Set current_function_decl and cfun. */
745 current_function_decl
= function
;
748 /* Make string 0 be a NULL string. */
749 streamer_write_char_stream (ob
->string_stream
, 0);
751 streamer_write_record_start (ob
, LTO_function
);
753 /* Write all the attributes for FN. */
754 bp
= bitpack_create (ob
->main_stream
);
755 bp_pack_value (&bp
, fn
->is_thunk
, 1);
756 bp_pack_value (&bp
, fn
->has_local_explicit_reg_vars
, 1);
757 bp_pack_value (&bp
, fn
->after_tree_profile
, 1);
758 bp_pack_value (&bp
, fn
->returns_pcc_struct
, 1);
759 bp_pack_value (&bp
, fn
->returns_struct
, 1);
760 bp_pack_value (&bp
, fn
->can_throw_non_call_exceptions
, 1);
761 bp_pack_value (&bp
, fn
->always_inline_functions_inlined
, 1);
762 bp_pack_value (&bp
, fn
->after_inlining
, 1);
763 bp_pack_value (&bp
, fn
->stdarg
, 1);
764 bp_pack_value (&bp
, fn
->has_nonlocal_label
, 1);
765 bp_pack_value (&bp
, fn
->calls_alloca
, 1);
766 bp_pack_value (&bp
, fn
->calls_setjmp
, 1);
767 bp_pack_value (&bp
, fn
->va_list_fpr_size
, 8);
768 bp_pack_value (&bp
, fn
->va_list_gpr_size
, 8);
769 streamer_write_bitpack (&bp
);
771 /* Output the function start and end loci. */
772 lto_output_location (ob
, fn
->function_start_locus
);
773 lto_output_location (ob
, fn
->function_end_locus
);
775 /* Output current IL state of the function. */
776 streamer_write_uhwi (ob
, fn
->curr_properties
);
778 /* Output the static chain and non-local goto save area. */
779 stream_write_tree (ob
, fn
->static_chain_decl
, true);
780 stream_write_tree (ob
, fn
->nonlocal_goto_save_area
, true);
782 /* Output all the local variables in the function. */
783 streamer_write_hwi (ob
, VEC_length (tree
, fn
->local_decls
));
784 FOR_EACH_VEC_ELT (tree
, fn
->local_decls
, i
, t
)
785 stream_write_tree (ob
, t
, true);
787 /* Output the head of the arguments list. */
788 stream_write_tree (ob
, DECL_ARGUMENTS (function
), true);
790 /* Output all the SSA names used in the function. */
791 output_ssa_names (ob
, fn
);
793 /* Output any exception handling regions. */
794 output_eh_regions (ob
, fn
);
796 /* Output DECL_INITIAL for the function, which contains the tree of
798 stream_write_tree (ob
, DECL_INITIAL (function
), true);
800 /* We will renumber the statements. The code that does this uses
801 the same ordering that we use for serializing them so we can use
802 the same code on the other end and not have to write out the
803 statement numbers. We do not assign UIDs to PHIs here because
804 virtual PHIs get re-computed on-the-fly which would make numbers
806 set_gimple_stmt_max_uid (cfun
, 0);
809 gimple_stmt_iterator gsi
;
810 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
812 gimple stmt
= gsi_stmt (gsi
);
813 gimple_set_uid (stmt
, inc_gimple_stmt_max_uid (cfun
));
817 /* Output the code for the function. */
818 FOR_ALL_BB_FN (bb
, fn
)
819 output_bb (ob
, bb
, fn
);
821 /* The terminator for this function. */
822 streamer_write_record_start (ob
, LTO_null
);
826 /* Create a section to hold the pickled output of this function. */
827 produce_asm (ob
, function
);
829 destroy_output_block (ob
);
831 current_function_decl
= NULL
;
836 /* Used to pass data to trivally_defined_alias callback. */
839 varpool_node_set vset
;
843 /* Return true if alias pair P belongs to the set of cgraph nodes in
844 SET. If P is a an alias for a VAR_DECL, it can always be emitted.
845 However, for FUNCTION_DECL aliases, we should only output the pair
846 if it belongs to a function whose cgraph node is in SET.
847 Otherwise, the LTRANS phase will get into trouble when finalizing
848 aliases because the alias will refer to a function not defined in
849 the file processed by LTRANS. */
852 trivally_defined_alias (tree decl ATTRIBUTE_UNUSED
,
853 tree target
, void *data
)
855 struct sets
*set
= (struct sets
*) data
;
856 struct cgraph_node
*fnode
= NULL
;
857 struct varpool_node
*vnode
= NULL
;
859 fnode
= cgraph_node_for_asm (target
);
861 return cgraph_node_in_set_p (fnode
, set
->set
);
862 vnode
= varpool_node_for_asm (target
);
863 return vnode
&& varpool_node_in_set_p (vnode
, set
->vset
);
866 /* Return true if alias pair P should be output in the current
867 partition contains cgrpah nodes SET and varpool nodes VSET.
868 DEFINED is set of all aliases whose targets are defined in
871 Normal aliases are output when they are defined, while WEAKREF
872 aliases are output when they are used. */
875 output_alias_pair_p (alias_pair
*p
, symbol_alias_set_t
*defined
,
876 cgraph_node_set set
, varpool_node_set vset
)
878 struct cgraph_node
*node
;
879 struct varpool_node
*vnode
;
881 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
883 if (TREE_CODE (p
->decl
) == VAR_DECL
)
885 vnode
= varpool_get_node (p
->decl
);
887 && referenced_from_this_partition_p (&vnode
->ref_list
, set
, vset
));
889 node
= cgraph_get_node (p
->decl
);
891 && (referenced_from_this_partition_p (&node
->ref_list
, set
, vset
)
892 || reachable_from_this_partition_p (node
, set
)));
895 return symbol_alias_set_contains (defined
, p
->decl
);
898 /* Output any unreferenced global symbol defined in SET, alias pairs
902 output_unreferenced_globals (cgraph_node_set set
, varpool_node_set vset
)
904 struct output_block
*ob
;
907 symbol_alias_set_t
*defined
;
913 ob
= create_output_block (LTO_section_static_initializer
);
914 ob
->cgraph_node
= NULL
;
916 clear_line_info (ob
);
918 /* Make string 0 be a NULL string. */
919 streamer_write_char_stream (ob
->string_stream
, 0);
921 /* We really need to propagate in both directoins:
922 for normal aliases we propagate from first defined alias to
923 all aliases defined based on it. For weakrefs we propagate in
924 the oposite direction. */
925 defined
= propagate_aliases_backward (trivally_defined_alias
, &setdata
);
927 /* Emit the alias pairs for the nodes in SET. */
928 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
929 if (output_alias_pair_p (p
, defined
, set
, vset
))
931 stream_write_tree (ob
, p
->decl
, true);
932 stream_write_tree (ob
, p
->target
, true);
934 symbol_alias_set_destroy (defined
);
936 streamer_write_record_start (ob
, LTO_null
);
938 produce_asm (ob
, NULL
);
939 destroy_output_block (ob
);
943 /* Emit toplevel asms. */
946 lto_output_toplevel_asms (void)
948 struct output_block
*ob
;
949 struct cgraph_asm_node
*can
;
951 struct lto_output_stream
*header_stream
;
952 struct lto_asm_header header
;
954 if (! cgraph_asm_nodes
)
957 ob
= create_output_block (LTO_section_asm
);
959 /* Make string 0 be a NULL string. */
960 streamer_write_char_stream (ob
->string_stream
, 0);
962 for (can
= cgraph_asm_nodes
; can
; can
= can
->next
)
964 streamer_write_string_cst (ob
, ob
->main_stream
, can
->asm_str
);
965 streamer_write_hwi (ob
, can
->order
);
968 streamer_write_string_cst (ob
, ob
->main_stream
, NULL_TREE
);
970 section_name
= lto_get_section_name (LTO_section_asm
, NULL
, NULL
);
971 lto_begin_section (section_name
, !flag_wpa
);
974 /* The entire header stream is computed here. */
975 memset (&header
, 0, sizeof (header
));
977 /* Write the header. */
978 header
.lto_header
.major_version
= LTO_major_version
;
979 header
.lto_header
.minor_version
= LTO_minor_version
;
980 header
.lto_header
.section_type
= LTO_section_asm
;
982 header
.main_size
= ob
->main_stream
->total_size
;
983 header
.string_size
= ob
->string_stream
->total_size
;
985 header_stream
= XCNEW (struct lto_output_stream
);
986 lto_output_data_stream (header_stream
, &header
, sizeof (header
));
987 lto_write_stream (header_stream
);
988 free (header_stream
);
990 /* Put all of the gimple and the string table out the asm file as a
992 lto_write_stream (ob
->main_stream
);
993 lto_write_stream (ob
->string_stream
);
997 destroy_output_block (ob
);
1001 /* Copy the function body of NODE without deserializing. */
1004 copy_function (struct cgraph_node
*node
)
1006 tree function
= node
->decl
;
1007 struct lto_file_decl_data
*file_data
= node
->local
.lto_file_data
;
1008 struct lto_output_stream
*output_stream
= XCNEW (struct lto_output_stream
);
1011 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function
));
1012 char *section_name
=
1013 lto_get_section_name (LTO_section_function_body
, name
, NULL
);
1015 struct lto_in_decl_state
*in_state
;
1016 struct lto_out_decl_state
*out_state
= lto_get_out_decl_state ();
1018 lto_begin_section (section_name
, !flag_wpa
);
1019 free (section_name
);
1021 /* We may have renamed the declaration, e.g., a static function. */
1022 name
= lto_get_decl_name_mapping (file_data
, name
);
1024 data
= lto_get_section_data (file_data
, LTO_section_function_body
,
1028 /* Do a bit copy of the function body. */
1029 lto_output_data_stream (output_stream
, data
, len
);
1030 lto_write_stream (output_stream
);
1034 lto_get_function_in_decl_state (node
->local
.lto_file_data
, function
);
1035 gcc_assert (in_state
);
1037 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
1039 size_t n
= in_state
->streams
[i
].size
;
1040 tree
*trees
= in_state
->streams
[i
].trees
;
1041 struct lto_tree_ref_encoder
*encoder
= &(out_state
->streams
[i
]);
1043 /* The out state must have the same indices and the in state.
1044 So just copy the vector. All the encoders in the in state
1045 must be empty where we reach here. */
1046 gcc_assert (lto_tree_ref_encoder_size (encoder
) == 0);
1047 for (j
= 0; j
< n
; j
++)
1048 VEC_safe_push (tree
, heap
, encoder
->trees
, trees
[j
]);
1049 encoder
->next_index
= n
;
1052 lto_free_section_data (file_data
, LTO_section_function_body
, name
,
1054 free (output_stream
);
1059 /* Main entry point from the pass manager. */
1062 lto_output (cgraph_node_set set
, varpool_node_set vset
)
1064 struct cgraph_node
*node
;
1065 struct lto_out_decl_state
*decl_state
;
1066 #ifdef ENABLE_CHECKING
1067 bitmap output
= lto_bitmap_alloc ();
1070 lto_cgraph_encoder_t encoder
= lto_get_out_decl_state ()->cgraph_node_encoder
;
1072 /* Initialize the streamer. */
1073 lto_streamer_init ();
1075 n_nodes
= lto_cgraph_encoder_size (encoder
);
1076 /* Process only the functions with bodies. */
1077 for (i
= 0; i
< n_nodes
; i
++)
1079 node
= lto_cgraph_encoder_deref (encoder
, i
);
1080 if (lto_cgraph_encoder_encode_body_p (encoder
, node
)
1082 && !node
->thunk
.thunk_p
)
1084 #ifdef ENABLE_CHECKING
1085 gcc_assert (!bitmap_bit_p (output
, DECL_UID (node
->decl
)));
1086 bitmap_set_bit (output
, DECL_UID (node
->decl
));
1088 decl_state
= lto_new_out_decl_state ();
1089 lto_push_out_decl_state (decl_state
);
1090 if (gimple_has_body_p (node
->decl
))
1091 output_function (node
);
1093 copy_function (node
);
1094 gcc_assert (lto_get_out_decl_state () == decl_state
);
1095 lto_pop_out_decl_state ();
1096 lto_record_function_out_decl_state (node
->decl
, decl_state
);
1100 /* Emit the callgraph after emitting function bodies. This needs to
1101 be done now to make sure that all the statements in every function
1102 have been renumbered so that edges can be associated with call
1103 statements using the statement UIDs. */
1104 output_cgraph (set
, vset
);
1106 #ifdef ENABLE_CHECKING
1107 lto_bitmap_free (output
);
1111 struct ipa_opt_pass_d pass_ipa_lto_gimple_out
=
1115 "lto_gimple_out", /* name */
1116 gate_lto_out
, /* gate */
1120 0, /* static_pass_number */
1121 TV_IPA_LTO_GIMPLE_OUT
, /* tv_id */
1122 0, /* properties_required */
1123 0, /* properties_provided */
1124 0, /* properties_destroyed */
1125 0, /* todo_flags_start */
1126 0 /* todo_flags_finish */
1128 NULL
, /* generate_summary */
1129 lto_output
, /* write_summary */
1130 NULL
, /* read_summary */
1131 lto_output
, /* write_optimization_summary */
1132 NULL
, /* read_optimization_summary */
1133 NULL
, /* stmt_fixup */
1135 NULL
, /* function_transform */
1136 NULL
/* variable_transform */
1140 /* Write each node in encoded by ENCODER to OB, as well as those reachable
1141 from it and required for correct representation of its semantics.
1142 Each node in ENCODER must be a global declaration or a type. A node
1143 is written only once, even if it appears multiple times in the
1144 vector. Certain transitively-reachable nodes, such as those
1145 representing expressions, may be duplicated, but such nodes
1146 must not appear in ENCODER itself. */
1149 write_global_stream (struct output_block
*ob
,
1150 struct lto_tree_ref_encoder
*encoder
)
1154 const size_t size
= lto_tree_ref_encoder_size (encoder
);
1156 for (index
= 0; index
< size
; index
++)
1158 t
= lto_tree_ref_encoder_get_tree (encoder
, index
);
1159 if (!streamer_tree_cache_lookup (ob
->writer_cache
, t
, NULL
))
1160 stream_write_tree (ob
, t
, false);
1165 /* Write a sequence of indices into the globals vector corresponding
1166 to the trees in ENCODER. These are used by the reader to map the
1167 indices used to refer to global entities within function bodies to
1171 write_global_references (struct output_block
*ob
,
1172 struct lto_output_stream
*ref_stream
,
1173 struct lto_tree_ref_encoder
*encoder
)
1177 const uint32_t size
= lto_tree_ref_encoder_size (encoder
);
1179 /* Write size as 32-bit unsigned. */
1180 lto_output_data_stream (ref_stream
, &size
, sizeof (int32_t));
1182 for (index
= 0; index
< size
; index
++)
1186 t
= lto_tree_ref_encoder_get_tree (encoder
, index
);
1187 streamer_tree_cache_lookup (ob
->writer_cache
, t
, &slot_num
);
1188 gcc_assert (slot_num
!= (unsigned)-1);
1189 lto_output_data_stream (ref_stream
, &slot_num
, sizeof slot_num
);
1194 /* Write all the streams in an lto_out_decl_state STATE using
1195 output block OB and output stream OUT_STREAM. */
1198 lto_output_decl_state_streams (struct output_block
*ob
,
1199 struct lto_out_decl_state
*state
)
1203 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
1204 write_global_stream (ob
, &state
->streams
[i
]);
1208 /* Write all the references in an lto_out_decl_state STATE using
1209 output block OB and output stream OUT_STREAM. */
1212 lto_output_decl_state_refs (struct output_block
*ob
,
1213 struct lto_output_stream
*out_stream
,
1214 struct lto_out_decl_state
*state
)
1220 /* Write reference to FUNCTION_DECL. If there is not function,
1221 write reference to void_type_node. */
1222 decl
= (state
->fn_decl
) ? state
->fn_decl
: void_type_node
;
1223 streamer_tree_cache_lookup (ob
->writer_cache
, decl
, &ref
);
1224 gcc_assert (ref
!= (unsigned)-1);
1225 lto_output_data_stream (out_stream
, &ref
, sizeof (uint32_t));
1227 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
1228 write_global_references (ob
, out_stream
, &state
->streams
[i
]);
1232 /* Return the written size of STATE. */
1235 lto_out_decl_state_written_size (struct lto_out_decl_state
*state
)
1240 size
= sizeof (int32_t); /* fn_ref. */
1241 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
1243 size
+= sizeof (int32_t); /* vector size. */
1244 size
+= (lto_tree_ref_encoder_size (&state
->streams
[i
])
1245 * sizeof (int32_t));
1251 /* Write symbol T into STREAM in CACHE. SEEN specifies symbols we wrote
1255 write_symbol (struct streamer_tree_cache_d
*cache
,
1256 struct lto_output_stream
*stream
,
1257 tree t
, struct pointer_set_t
*seen
, bool alias
)
1260 enum gcc_plugin_symbol_kind kind
;
1261 enum gcc_plugin_symbol_visibility visibility
;
1267 /* None of the following kinds of symbols are needed in the
1269 if (!TREE_PUBLIC (t
)
1270 || is_builtin_fn (t
)
1271 || DECL_ABSTRACT (t
)
1272 || TREE_CODE (t
) == RESULT_DECL
)
1275 gcc_assert (TREE_CODE (t
) == VAR_DECL
1276 || TREE_CODE (t
) == FUNCTION_DECL
);
1278 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t
));
1280 /* This behaves like assemble_name_raw in varasm.c, performing the
1281 same name manipulations that ASM_OUTPUT_LABELREF does. */
1282 name
= IDENTIFIER_POINTER ((*targetm
.asm_out
.mangle_assembler_name
) (name
));
1284 if (pointer_set_contains (seen
, name
))
1286 pointer_set_insert (seen
, name
);
1288 streamer_tree_cache_lookup (cache
, t
, &slot_num
);
1289 gcc_assert (slot_num
!= (unsigned)-1);
1291 if (DECL_EXTERNAL (t
))
1294 kind
= GCCPK_WEAKUNDEF
;
1301 kind
= GCCPK_WEAKDEF
;
1302 else if (DECL_COMMON (t
))
1303 kind
= GCCPK_COMMON
;
1307 /* When something is defined, it should have node attached. */
1308 gcc_assert (alias
|| TREE_CODE (t
) != VAR_DECL
1309 || varpool_get_node (t
)->finalized
);
1310 gcc_assert (alias
|| TREE_CODE (t
) != FUNCTION_DECL
1311 || (cgraph_get_node (t
)
1312 && cgraph_get_node (t
)->analyzed
));
1315 /* Imitate what default_elf_asm_output_external do.
1316 When symbol is external, we need to output it with DEFAULT visibility
1317 when compiling with -fvisibility=default, while with HIDDEN visibility
1318 when symbol has attribute (visibility("hidden")) specified.
1319 targetm.binds_local_p check DECL_VISIBILITY_SPECIFIED and gets this
1322 if (DECL_EXTERNAL (t
)
1323 && !targetm
.binds_local_p (t
))
1324 visibility
= GCCPV_DEFAULT
;
1326 switch (DECL_VISIBILITY(t
))
1328 case VISIBILITY_DEFAULT
:
1329 visibility
= GCCPV_DEFAULT
;
1331 case VISIBILITY_PROTECTED
:
1332 visibility
= GCCPV_PROTECTED
;
1334 case VISIBILITY_HIDDEN
:
1335 visibility
= GCCPV_HIDDEN
;
1337 case VISIBILITY_INTERNAL
:
1338 visibility
= GCCPV_INTERNAL
;
1342 if (kind
== GCCPK_COMMON
1344 && TREE_CODE (DECL_SIZE (t
)) == INTEGER_CST
)
1346 size
= (HOST_BITS_PER_WIDE_INT
>= 64)
1347 ? (uint64_t) int_size_in_bytes (TREE_TYPE (t
))
1348 : (((uint64_t) TREE_INT_CST_HIGH (DECL_SIZE_UNIT (t
))) << 32)
1349 | TREE_INT_CST_LOW (DECL_SIZE_UNIT (t
));
1354 if (DECL_ONE_ONLY (t
))
1355 comdat
= IDENTIFIER_POINTER (DECL_COMDAT_GROUP (t
));
1359 lto_output_data_stream (stream
, name
, strlen (name
) + 1);
1360 lto_output_data_stream (stream
, comdat
, strlen (comdat
) + 1);
1361 c
= (unsigned char) kind
;
1362 lto_output_data_stream (stream
, &c
, 1);
1363 c
= (unsigned char) visibility
;
1364 lto_output_data_stream (stream
, &c
, 1);
1365 lto_output_data_stream (stream
, &size
, 8);
1366 lto_output_data_stream (stream
, &slot_num
, 4);
1370 /* Write an IL symbol table to OB.
1371 SET and VSET are cgraph/varpool node sets we are outputting. */
1374 produce_symtab (struct output_block
*ob
,
1375 cgraph_node_set set
, varpool_node_set vset
)
1377 struct streamer_tree_cache_d
*cache
= ob
->writer_cache
;
1378 char *section_name
= lto_get_section_name (LTO_section_symtab
, NULL
, NULL
);
1379 struct pointer_set_t
*seen
;
1380 struct cgraph_node
*node
;
1381 struct varpool_node
*vnode
;
1382 struct lto_output_stream stream
;
1383 lto_varpool_encoder_t varpool_encoder
= ob
->decl_state
->varpool_node_encoder
;
1384 lto_cgraph_encoder_t encoder
= ob
->decl_state
->cgraph_node_encoder
;
1387 struct sets setdata
;
1388 symbol_alias_set_t
*defined
;
1391 setdata
.vset
= vset
;
1393 lto_begin_section (section_name
, false);
1394 free (section_name
);
1396 seen
= pointer_set_create ();
1397 memset (&stream
, 0, sizeof (stream
));
1399 /* Write all functions.
1400 First write all defined functions and then write all used functions.
1401 This is done so only to handle duplicated symbols in cgraph. */
1402 for (i
= 0; i
< lto_cgraph_encoder_size (encoder
); i
++)
1404 node
= lto_cgraph_encoder_deref (encoder
, i
);
1405 if (DECL_EXTERNAL (node
->decl
))
1407 if (DECL_COMDAT (node
->decl
)
1408 && cgraph_comdat_can_be_unshared_p (node
))
1410 if ((node
->alias
&& !node
->thunk
.alias
) || node
->global
.inlined_to
)
1412 write_symbol (cache
, &stream
, node
->decl
, seen
, false);
1414 for (i
= 0; i
< lto_cgraph_encoder_size (encoder
); i
++)
1416 node
= lto_cgraph_encoder_deref (encoder
, i
);
1417 if (!DECL_EXTERNAL (node
->decl
))
1419 /* We keep around unused extern inlines in order to be able to inline
1420 them indirectly or via vtables. Do not output them to symbol
1421 table: they end up being undefined and just consume space. */
1422 if (!node
->address_taken
&& !node
->callers
)
1424 gcc_assert (node
->analyzed
);
1425 gcc_assert (DECL_DECLARED_INLINE_P (node
->decl
));
1428 if (DECL_COMDAT (node
->decl
)
1429 && cgraph_comdat_can_be_unshared_p (node
))
1431 if ((node
->alias
&& !node
->thunk
.alias
) || node
->global
.inlined_to
)
1433 write_symbol (cache
, &stream
, node
->decl
, seen
, false);
1436 /* Write all variables. */
1437 for (i
= 0; i
< lto_varpool_encoder_size (varpool_encoder
); i
++)
1439 vnode
= lto_varpool_encoder_deref (varpool_encoder
, i
);
1440 if (DECL_EXTERNAL (vnode
->decl
))
1442 /* COMDAT virtual tables can be unshared. Do not declare them
1443 in the LTO symbol table to prevent linker from forcing them
1445 if (DECL_COMDAT (vnode
->decl
)
1446 && !vnode
->force_output
1448 && DECL_VIRTUAL_P (vnode
->decl
))
1450 if (vnode
->alias
&& !vnode
->alias_of
)
1452 write_symbol (cache
, &stream
, vnode
->decl
, seen
, false);
1454 for (i
= 0; i
< lto_varpool_encoder_size (varpool_encoder
); i
++)
1456 vnode
= lto_varpool_encoder_deref (varpool_encoder
, i
);
1457 if (!DECL_EXTERNAL (vnode
->decl
))
1459 if (DECL_COMDAT (vnode
->decl
)
1460 && !vnode
->force_output
1462 && DECL_VIRTUAL_P (vnode
->decl
))
1464 if (vnode
->alias
&& !vnode
->alias_of
)
1466 write_symbol (cache
, &stream
, vnode
->decl
, seen
, false);
1469 /* Write all aliases. */
1470 defined
= propagate_aliases_backward (trivally_defined_alias
, &setdata
);
1471 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
1472 if (output_alias_pair_p (p
, defined
, set
, vset
))
1473 write_symbol (cache
, &stream
, p
->decl
, seen
, true);
1474 symbol_alias_set_destroy (defined
);
1476 lto_write_stream (&stream
);
1477 pointer_set_destroy (seen
);
1483 /* This pass is run after all of the functions are serialized and all
1484 of the IPA passes have written their serialized forms. This pass
1485 causes the vector of all of the global decls and types used from
1486 this file to be written in to a section that can then be read in to
1487 recover these on other side. */
1490 produce_asm_for_decls (cgraph_node_set set
, varpool_node_set vset
)
1492 struct lto_out_decl_state
*out_state
;
1493 struct lto_out_decl_state
*fn_out_state
;
1494 struct lto_decl_header header
;
1496 struct output_block
*ob
;
1497 struct lto_output_stream
*header_stream
, *decl_state_stream
;
1498 unsigned idx
, num_fns
;
1499 size_t decl_state_size
;
1500 int32_t num_decl_states
;
1502 ob
= create_output_block (LTO_section_decls
);
1505 /* Write out unreferenced globals, alias pairs and labels. We defer
1506 doing this until now so that we can write out only what is
1508 output_unreferenced_globals (set
, vset
);
1510 memset (&header
, 0, sizeof (struct lto_decl_header
));
1512 section_name
= lto_get_section_name (LTO_section_decls
, NULL
, NULL
);
1513 lto_begin_section (section_name
, !flag_wpa
);
1514 free (section_name
);
1516 /* Make string 0 be a NULL string. */
1517 streamer_write_char_stream (ob
->string_stream
, 0);
1519 /* Write the global symbols. */
1520 out_state
= lto_get_out_decl_state ();
1521 num_fns
= VEC_length (lto_out_decl_state_ptr
, lto_function_decl_states
);
1522 lto_output_decl_state_streams (ob
, out_state
);
1523 for (idx
= 0; idx
< num_fns
; idx
++)
1526 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
1527 lto_output_decl_state_streams (ob
, fn_out_state
);
1530 header
.lto_header
.major_version
= LTO_major_version
;
1531 header
.lto_header
.minor_version
= LTO_minor_version
;
1532 header
.lto_header
.section_type
= LTO_section_decls
;
1534 /* Currently not used. This field would allow us to preallocate
1535 the globals vector, so that it need not be resized as it is extended. */
1536 header
.num_nodes
= -1;
1538 /* Compute the total size of all decl out states. */
1539 decl_state_size
= sizeof (int32_t);
1540 decl_state_size
+= lto_out_decl_state_written_size (out_state
);
1541 for (idx
= 0; idx
< num_fns
; idx
++)
1544 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
1545 decl_state_size
+= lto_out_decl_state_written_size (fn_out_state
);
1547 header
.decl_state_size
= decl_state_size
;
1549 header
.main_size
= ob
->main_stream
->total_size
;
1550 header
.string_size
= ob
->string_stream
->total_size
;
1552 header_stream
= XCNEW (struct lto_output_stream
);
1553 lto_output_data_stream (header_stream
, &header
, sizeof header
);
1554 lto_write_stream (header_stream
);
1555 free (header_stream
);
1557 /* Write the main out-decl state, followed by out-decl states of
1559 decl_state_stream
= ((struct lto_output_stream
*)
1560 xcalloc (1, sizeof (struct lto_output_stream
)));
1561 num_decl_states
= num_fns
+ 1;
1562 lto_output_data_stream (decl_state_stream
, &num_decl_states
,
1563 sizeof (num_decl_states
));
1564 lto_output_decl_state_refs (ob
, decl_state_stream
, out_state
);
1565 for (idx
= 0; idx
< num_fns
; idx
++)
1568 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
1569 lto_output_decl_state_refs (ob
, decl_state_stream
, fn_out_state
);
1571 lto_write_stream (decl_state_stream
);
1572 free(decl_state_stream
);
1574 lto_write_stream (ob
->main_stream
);
1575 lto_write_stream (ob
->string_stream
);
1579 /* Write the symbol table. It is used by linker to determine dependencies
1580 and thus we can skip it for WPA. */
1582 produce_symtab (ob
, set
, vset
);
1584 /* Write command line opts. */
1585 lto_write_options ();
1587 /* Deallocate memory and clean up. */
1588 for (idx
= 0; idx
< num_fns
; idx
++)
1591 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
1592 lto_delete_out_decl_state (fn_out_state
);
1594 lto_cgraph_encoder_delete (ob
->decl_state
->cgraph_node_encoder
);
1595 lto_varpool_encoder_delete (ob
->decl_state
->varpool_node_encoder
);
1596 VEC_free (lto_out_decl_state_ptr
, heap
, lto_function_decl_states
);
1597 lto_function_decl_states
= NULL
;
1598 destroy_output_block (ob
);
1602 struct ipa_opt_pass_d pass_ipa_lto_finish_out
=
1606 "lto_decls_out", /* name */
1607 gate_lto_out
, /* gate */
1611 0, /* static_pass_number */
1612 TV_IPA_LTO_DECL_OUT
, /* tv_id */
1613 0, /* properties_required */
1614 0, /* properties_provided */
1615 0, /* properties_destroyed */
1616 0, /* todo_flags_start */
1617 0 /* todo_flags_finish */
1619 NULL
, /* generate_summary */
1620 produce_asm_for_decls
, /* write_summary */
1621 NULL
, /* read_summary */
1622 produce_asm_for_decls
, /* write_optimization_summary */
1623 NULL
, /* read_optimization_summary */
1624 NULL
, /* stmt_fixup */
1626 NULL
, /* function_transform */
1627 NULL
/* variable_transform */