1 /* Write and read the cgraph to the memory mapped representation of a
4 Copyright (C) 2009-2015 Free Software Foundation, Inc.
5 Contributed by Kenneth Zadeck <zadeck@naturalbridge.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"
30 #include "double-int.h"
37 #include "fold-const.h"
38 #include "stringpool.h"
40 #include "hard-reg-set.h"
42 #include "basic-block.h"
43 #include "tree-ssa-alias.h"
44 #include "internal-fn.h"
45 #include "gimple-expr.h"
51 #include "statistics.h"
53 #include "fixed-value.h"
54 #include "insn-config.h"
64 #include "langhooks.h"
66 #include "diagnostic-core.h"
70 #include "plugin-api.h"
73 #include "lto-streamer.h"
74 #include "data-streamer.h"
75 #include "tree-streamer.h"
77 #include "tree-pass.h"
80 #include "pass_manager.h"
81 #include "ipa-utils.h"
84 /* True when asm nodes has been output. */
85 bool asm_nodes_output
= false;
87 static void output_cgraph_opt_summary (void);
88 static void input_cgraph_opt_summary (vec
<symtab_node
*> nodes
);
90 /* Number of LDPR values known to GCC. */
91 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
93 /* All node orders are ofsetted by ORDER_BASE. */
94 static int order_base
;
96 /* Cgraph streaming is organized as set of record whose type
97 is indicated by a tag. */
100 /* Must leave 0 for the stopper. */
102 /* Cgraph node without body available. */
103 LTO_symtab_unavail_node
= 1,
104 /* Cgraph node with function body. */
105 LTO_symtab_analyzed_node
,
108 LTO_symtab_indirect_edge
,
113 /* Create a new symtab encoder.
114 if FOR_INPUT, the encoder allocate only datastructures needed
115 to read the symtab. */
118 lto_symtab_encoder_new (bool for_input
)
120 lto_symtab_encoder_t encoder
= XCNEW (struct lto_symtab_encoder_d
);
123 encoder
->map
= new hash_map
<symtab_node
*, size_t>;
124 encoder
->nodes
.create (0);
129 /* Delete ENCODER and its components. */
132 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder
)
134 encoder
->nodes
.release ();
141 /* Return the existing reference number of NODE in the symtab encoder in
142 output block OB. Assign a new reference if this is the first time
146 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder
,
153 lto_encoder_entry entry
= {node
, false, false, false};
155 ref
= encoder
->nodes
.length ();
156 encoder
->nodes
.safe_push (entry
);
160 size_t *slot
= encoder
->map
->get (node
);
163 lto_encoder_entry entry
= {node
, false, false, false};
164 ref
= encoder
->nodes
.length ();
166 encoder
->map
->put (node
, ref
+ 1);
167 encoder
->nodes
.safe_push (entry
);
175 /* Remove NODE from encoder. */
178 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder
,
182 lto_encoder_entry last_node
;
184 size_t *slot
= encoder
->map
->get (node
);
185 if (slot
== NULL
|| !*slot
)
189 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
191 /* Remove from vector. We do this by swapping node with the last element
193 last_node
= encoder
->nodes
.pop ();
194 if (last_node
.node
!= node
)
196 gcc_assert (encoder
->map
->put (last_node
.node
, index
+ 1));
198 /* Move the last element to the original spot of NODE. */
199 encoder
->nodes
[index
] = last_node
;
202 /* Remove element from hash table. */
203 encoder
->map
->remove (node
);
208 /* Return TRUE if we should encode the body of NODE (if any). */
211 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder
,
212 struct cgraph_node
*node
)
214 int index
= lto_symtab_encoder_lookup (encoder
, node
);
215 return encoder
->nodes
[index
].body
;
218 /* Specify that we encode the body of NODE in this partition. */
221 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder
,
222 struct cgraph_node
*node
)
224 int index
= lto_symtab_encoder_encode (encoder
, node
);
225 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
226 encoder
->nodes
[index
].body
= true;
229 /* Return TRUE if we should encode initializer of NODE (if any). */
232 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder
,
235 int index
= lto_symtab_encoder_lookup (encoder
, node
);
236 if (index
== LCC_NOT_FOUND
)
238 return encoder
->nodes
[index
].initializer
;
241 /* Specify that we should encode initializer of NODE (if any). */
244 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder
,
247 int index
= lto_symtab_encoder_lookup (encoder
, node
);
248 encoder
->nodes
[index
].initializer
= true;
251 /* Return TRUE if NODE is in this partition. */
254 lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder
,
257 int index
= lto_symtab_encoder_lookup (encoder
, node
);
258 if (index
== LCC_NOT_FOUND
)
260 return encoder
->nodes
[index
].in_partition
;
263 /* Specify that NODE is in this partition. */
266 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder
,
269 int index
= lto_symtab_encoder_encode (encoder
, node
);
270 encoder
->nodes
[index
].in_partition
= true;
273 /* Output the cgraph EDGE to OB using ENCODER. */
276 lto_output_edge (struct lto_simple_output_block
*ob
, struct cgraph_edge
*edge
,
277 lto_symtab_encoder_t encoder
)
283 if (edge
->indirect_unknown_callee
)
284 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
285 LTO_symtab_indirect_edge
);
287 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
290 ref
= lto_symtab_encoder_lookup (encoder
, edge
->caller
);
291 gcc_assert (ref
!= LCC_NOT_FOUND
);
292 streamer_write_hwi_stream (ob
->main_stream
, ref
);
294 if (!edge
->indirect_unknown_callee
)
296 ref
= lto_symtab_encoder_lookup (encoder
, edge
->callee
);
297 gcc_assert (ref
!= LCC_NOT_FOUND
);
298 streamer_write_hwi_stream (ob
->main_stream
, ref
);
301 streamer_write_gcov_count_stream (ob
->main_stream
, edge
->count
);
303 bp
= bitpack_create (ob
->main_stream
);
304 uid
= (!gimple_has_body_p (edge
->caller
->decl
)
305 ? edge
->lto_stmt_uid
: gimple_uid (edge
->call_stmt
) + 1);
306 bp_pack_enum (&bp
, cgraph_inline_failed_t
,
307 CIF_N_REASONS
, edge
->inline_failed
);
308 bp_pack_var_len_unsigned (&bp
, uid
);
309 bp_pack_var_len_unsigned (&bp
, edge
->frequency
);
310 bp_pack_value (&bp
, edge
->indirect_inlining_edge
, 1);
311 bp_pack_value (&bp
, edge
->speculative
, 1);
312 bp_pack_value (&bp
, edge
->call_stmt_cannot_inline_p
, 1);
313 bp_pack_value (&bp
, edge
->can_throw_external
, 1);
314 bp_pack_value (&bp
, edge
->in_polymorphic_cdtor
, 1);
315 if (edge
->indirect_unknown_callee
)
317 int flags
= edge
->indirect_info
->ecf_flags
;
318 bp_pack_value (&bp
, (flags
& ECF_CONST
) != 0, 1);
319 bp_pack_value (&bp
, (flags
& ECF_PURE
) != 0, 1);
320 bp_pack_value (&bp
, (flags
& ECF_NORETURN
) != 0, 1);
321 bp_pack_value (&bp
, (flags
& ECF_MALLOC
) != 0, 1);
322 bp_pack_value (&bp
, (flags
& ECF_NOTHROW
) != 0, 1);
323 bp_pack_value (&bp
, (flags
& ECF_RETURNS_TWICE
) != 0, 1);
324 /* Flags that should not appear on indirect calls. */
325 gcc_assert (!(flags
& (ECF_LOOPING_CONST_OR_PURE
331 streamer_write_bitpack (&bp
);
332 if (edge
->indirect_unknown_callee
)
334 streamer_write_hwi_stream (ob
->main_stream
,
335 edge
->indirect_info
->common_target_id
);
336 if (edge
->indirect_info
->common_target_id
)
337 streamer_write_hwi_stream
338 (ob
->main_stream
, edge
->indirect_info
->common_target_probability
);
342 /* Return if NODE contain references from other partitions. */
345 referenced_from_other_partition_p (symtab_node
*node
, lto_symtab_encoder_t encoder
)
348 struct ipa_ref
*ref
= NULL
;
350 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
352 /* Ignore references from non-offloadable nodes while streaming NODE into
353 offload LTO section. */
354 if (!ref
->referring
->need_lto_streaming
)
357 if (ref
->referring
->in_other_partition
358 || !lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
364 /* Return true when node is reachable from other partition. */
367 reachable_from_other_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
369 struct cgraph_edge
*e
;
370 if (!node
->definition
)
372 if (node
->global
.inlined_to
)
374 for (e
= node
->callers
; e
; e
= e
->next_caller
)
376 /* Ignore references from non-offloadable nodes while streaming NODE into
377 offload LTO section. */
378 if (!e
->caller
->need_lto_streaming
)
381 if (e
->caller
->in_other_partition
382 || !lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
388 /* Return if NODE contain references from other partitions. */
391 referenced_from_this_partition_p (symtab_node
*node
,
392 lto_symtab_encoder_t encoder
)
395 struct ipa_ref
*ref
= NULL
;
397 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
398 if (lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
403 /* Return true when node is reachable from other partition. */
406 reachable_from_this_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
408 struct cgraph_edge
*e
;
409 for (e
= node
->callers
; e
; e
= e
->next_caller
)
410 if (lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
415 /* Output the cgraph NODE to OB. ENCODER is used to find the
416 reference number of NODE->inlined_to. SET is the set of nodes we
417 are writing to the current file. If NODE is not in SET, then NODE
418 is a boundary of a cgraph_node_set and we pretend NODE just has a
419 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
420 that have had their callgraph node written so far. This is used to
421 determine if NODE is a clone of a previously written node. */
424 lto_output_node (struct lto_simple_output_block
*ob
, struct cgraph_node
*node
,
425 lto_symtab_encoder_t encoder
)
431 bool in_other_partition
= false;
432 struct cgraph_node
*clone_of
, *ultimate_clone_of
;
433 ipa_opt_pass_d
*pass
;
439 boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
441 if (node
->analyzed
&& (!boundary_p
|| node
->alias
|| node
->thunk
.thunk_p
))
442 tag
= LTO_symtab_analyzed_node
;
444 tag
= LTO_symtab_unavail_node
;
446 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
448 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
450 /* In WPA mode, we only output part of the call-graph. Also, we
451 fake cgraph node attributes. There are two cases that we care.
453 Boundary nodes: There are nodes that are not part of SET but are
454 called from within SET. We artificially make them look like
455 externally visible nodes with no function body.
457 Cherry-picked nodes: These are nodes we pulled from other
458 translation units into SET during IPA-inlining. We make them as
459 local static nodes to prevent clashes with other local statics. */
460 if (boundary_p
&& node
->analyzed
461 && node
->get_partitioning_class () == SYMBOL_PARTITION
)
463 /* Inline clones can not be part of boundary.
464 gcc_assert (!node->global.inlined_to);
466 FIXME: At the moment they can be, when partition contains an inline
467 clone that is clone of inline clone from outside partition. We can
468 reshape the clone tree and make other tree to be the root, but it
469 needs a bit extra work and will be promplty done by cgraph_remove_node
470 after reading back. */
471 in_other_partition
= 1;
474 clone_of
= node
->clone_of
;
476 && (ref
= lto_symtab_encoder_lookup (encoder
, clone_of
)) == LCC_NOT_FOUND
)
477 if (clone_of
->prev_sibling_clone
)
478 clone_of
= clone_of
->prev_sibling_clone
;
480 clone_of
= clone_of
->clone_of
;
482 /* See if body of the master function is output. If not, we are seeing only
483 an declaration and we do not need to pass down clone tree. */
484 ultimate_clone_of
= clone_of
;
485 while (ultimate_clone_of
&& ultimate_clone_of
->clone_of
)
486 ultimate_clone_of
= ultimate_clone_of
->clone_of
;
488 if (clone_of
&& !lto_symtab_encoder_encode_body_p (encoder
, ultimate_clone_of
))
491 if (tag
== LTO_symtab_analyzed_node
)
492 gcc_assert (clone_of
|| !node
->clone_of
);
494 streamer_write_hwi_stream (ob
->main_stream
, LCC_NOT_FOUND
);
496 streamer_write_hwi_stream (ob
->main_stream
, ref
);
499 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
500 streamer_write_gcov_count_stream (ob
->main_stream
, node
->count
);
501 streamer_write_hwi_stream (ob
->main_stream
, node
->count_materialization_scale
);
503 streamer_write_hwi_stream (ob
->main_stream
,
504 node
->ipa_transforms_to_apply
.length ());
505 FOR_EACH_VEC_ELT (node
->ipa_transforms_to_apply
, i
, pass
)
506 streamer_write_hwi_stream (ob
->main_stream
, pass
->static_pass_number
);
508 if (tag
== LTO_symtab_analyzed_node
)
510 if (node
->global
.inlined_to
)
512 ref
= lto_symtab_encoder_lookup (encoder
, node
->global
.inlined_to
);
513 gcc_assert (ref
!= LCC_NOT_FOUND
);
518 streamer_write_hwi_stream (ob
->main_stream
, ref
);
521 group
= node
->get_comdat_group ();
523 comdat
= IDENTIFIER_POINTER (group
);
526 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
530 if (node
->same_comdat_group
&& !boundary_p
)
532 ref
= lto_symtab_encoder_lookup (encoder
,
533 node
->same_comdat_group
);
534 gcc_assert (ref
!= LCC_NOT_FOUND
);
538 streamer_write_hwi_stream (ob
->main_stream
, ref
);
541 section
= node
->get_section ();
545 streamer_write_hwi_stream (ob
->main_stream
, node
->tp_first_run
);
547 bp
= bitpack_create (ob
->main_stream
);
548 bp_pack_value (&bp
, node
->local
.local
, 1);
549 bp_pack_value (&bp
, node
->externally_visible
, 1);
550 bp_pack_value (&bp
, node
->no_reorder
, 1);
551 bp_pack_value (&bp
, node
->definition
, 1);
552 bp_pack_value (&bp
, node
->local
.versionable
, 1);
553 bp_pack_value (&bp
, node
->local
.can_change_signature
, 1);
554 bp_pack_value (&bp
, node
->local
.redefined_extern_inline
, 1);
555 bp_pack_value (&bp
, node
->force_output
, 1);
556 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
557 bp_pack_value (&bp
, node
->unique_name
, 1);
558 bp_pack_value (&bp
, node
->body_removed
, 1);
559 bp_pack_value (&bp
, node
->implicit_section
, 1);
560 bp_pack_value (&bp
, node
->address_taken
, 1);
561 bp_pack_value (&bp
, tag
== LTO_symtab_analyzed_node
562 && node
->get_partitioning_class () == SYMBOL_PARTITION
563 && (reachable_from_other_partition_p (node
, encoder
)
564 || referenced_from_other_partition_p (node
, encoder
)), 1);
565 bp_pack_value (&bp
, node
->lowered
, 1);
566 bp_pack_value (&bp
, in_other_partition
, 1);
567 bp_pack_value (&bp
, node
->alias
, 1);
568 bp_pack_value (&bp
, node
->weakref
, 1);
569 bp_pack_value (&bp
, node
->frequency
, 2);
570 bp_pack_value (&bp
, node
->only_called_at_startup
, 1);
571 bp_pack_value (&bp
, node
->only_called_at_exit
, 1);
572 bp_pack_value (&bp
, node
->tm_clone
, 1);
573 bp_pack_value (&bp
, node
->calls_comdat_local
, 1);
574 bp_pack_value (&bp
, node
->icf_merged
, 1);
575 bp_pack_value (&bp
, node
->nonfreeing_fn
, 1);
576 bp_pack_value (&bp
, node
->thunk
.thunk_p
, 1);
577 bp_pack_value (&bp
, node
->parallelized_function
, 1);
578 bp_pack_enum (&bp
, ld_plugin_symbol_resolution
,
579 LDPR_NUM_KNOWN
, node
->resolution
);
580 bp_pack_value (&bp
, node
->instrumentation_clone
, 1);
581 bp_pack_value (&bp
, node
->split_part
, 1);
582 streamer_write_bitpack (&bp
);
583 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
585 if (node
->thunk
.thunk_p
)
587 streamer_write_uhwi_stream
589 1 + (node
->thunk
.this_adjusting
!= 0) * 2
590 + (node
->thunk
.virtual_offset_p
!= 0) * 4
591 + (node
->thunk
.add_pointer_bounds_args
!= 0) * 8);
592 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.fixed_offset
);
593 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.virtual_value
);
595 streamer_write_hwi_stream (ob
->main_stream
, node
->profile_id
);
596 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
597 streamer_write_hwi_stream (ob
->main_stream
, node
->get_init_priority ());
598 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
599 streamer_write_hwi_stream (ob
->main_stream
, node
->get_fini_priority ());
601 if (node
->instrumentation_clone
)
602 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->orig_decl
);
605 /* Output the varpool NODE to OB.
606 If NODE is not in SET, then NODE is a boundary. */
609 lto_output_varpool_node (struct lto_simple_output_block
*ob
, varpool_node
*node
,
610 lto_symtab_encoder_t encoder
)
612 bool boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
613 bool encode_initializer_p
615 && lto_symtab_encoder_encode_initializer_p (encoder
, node
));
622 gcc_assert (!encode_initializer_p
|| node
->definition
);
623 gcc_assert (boundary_p
|| encode_initializer_p
);
625 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
626 LTO_symtab_variable
);
627 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
628 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
629 bp
= bitpack_create (ob
->main_stream
);
630 bp_pack_value (&bp
, node
->externally_visible
, 1);
631 bp_pack_value (&bp
, node
->no_reorder
, 1);
632 bp_pack_value (&bp
, node
->force_output
, 1);
633 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
634 bp_pack_value (&bp
, node
->unique_name
, 1);
637 || (!encode_initializer_p
&& !node
->alias
&& node
->definition
),
639 bp_pack_value (&bp
, node
->implicit_section
, 1);
640 bp_pack_value (&bp
, node
->writeonly
, 1);
641 bp_pack_value (&bp
, node
->definition
&& (encode_initializer_p
|| node
->alias
),
643 bp_pack_value (&bp
, node
->alias
, 1);
644 bp_pack_value (&bp
, node
->weakref
, 1);
645 bp_pack_value (&bp
, node
->analyzed
&& !boundary_p
, 1);
646 gcc_assert (node
->definition
|| !node
->analyzed
);
647 /* Constant pool initializers can be de-unified into individual ltrans units.
648 FIXME: Alternatively at -Os we may want to avoid generating for them the local
649 labels and share them across LTRANS partitions. */
650 if (node
->get_partitioning_class () != SYMBOL_PARTITION
)
652 bp_pack_value (&bp
, 0, 1); /* used_from_other_parition. */
653 bp_pack_value (&bp
, 0, 1); /* in_other_partition. */
657 bp_pack_value (&bp
, node
->definition
658 && referenced_from_other_partition_p (node
, encoder
), 1);
659 bp_pack_value (&bp
, node
->analyzed
660 && boundary_p
&& !DECL_EXTERNAL (node
->decl
), 1);
661 /* in_other_partition. */
663 bp_pack_value (&bp
, node
->tls_model
, 3);
664 bp_pack_value (&bp
, node
->used_by_single_function
, 1);
665 bp_pack_value (&bp
, node
->need_bounds_init
, 1);
666 streamer_write_bitpack (&bp
);
668 group
= node
->get_comdat_group ();
670 comdat
= IDENTIFIER_POINTER (group
);
673 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
677 if (node
->same_comdat_group
&& !boundary_p
)
679 ref
= lto_symtab_encoder_lookup (encoder
,
680 node
->same_comdat_group
);
681 gcc_assert (ref
!= LCC_NOT_FOUND
);
685 streamer_write_hwi_stream (ob
->main_stream
, ref
);
688 section
= node
->get_section ();
691 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
693 streamer_write_enum (ob
->main_stream
, ld_plugin_symbol_resolution
,
694 LDPR_NUM_KNOWN
, node
->resolution
);
697 /* Output the varpool NODE to OB.
698 If NODE is not in SET, then NODE is a boundary. */
701 lto_output_ref (struct lto_simple_output_block
*ob
, struct ipa_ref
*ref
,
702 lto_symtab_encoder_t encoder
)
706 int uid
= ref
->lto_stmt_uid
;
707 struct cgraph_node
*node
;
709 bp
= bitpack_create (ob
->main_stream
);
710 bp_pack_value (&bp
, ref
->use
, 3);
711 bp_pack_value (&bp
, ref
->speculative
, 1);
712 streamer_write_bitpack (&bp
);
713 nref
= lto_symtab_encoder_lookup (encoder
, ref
->referred
);
714 gcc_assert (nref
!= LCC_NOT_FOUND
);
715 streamer_write_hwi_stream (ob
->main_stream
, nref
);
717 node
= dyn_cast
<cgraph_node
*> (ref
->referring
);
721 uid
= gimple_uid (ref
->stmt
) + 1;
722 streamer_write_hwi_stream (ob
->main_stream
, uid
);
726 /* Stream out profile_summary to OB. */
729 output_profile_summary (struct lto_simple_output_block
*ob
)
736 /* We do not output num and run_max, they are not used by
737 GCC profile feedback and they are difficult to merge from multiple
739 gcc_assert (profile_info
->runs
);
740 streamer_write_uhwi_stream (ob
->main_stream
, profile_info
->runs
);
741 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_max
);
743 /* sum_all is needed for computing the working set with the
745 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_all
);
747 /* Create and output a bitpack of non-zero histogram entries indices. */
748 bp
= bitpack_create (ob
->main_stream
);
749 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
750 bp_pack_value (&bp
, profile_info
->histogram
[h_ix
].num_counters
> 0, 1);
751 streamer_write_bitpack (&bp
);
752 /* Now stream out only those non-zero entries. */
753 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
755 if (!profile_info
->histogram
[h_ix
].num_counters
)
757 streamer_write_gcov_count_stream (ob
->main_stream
,
758 profile_info
->histogram
[h_ix
].num_counters
);
759 streamer_write_gcov_count_stream (ob
->main_stream
,
760 profile_info
->histogram
[h_ix
].min_value
);
761 streamer_write_gcov_count_stream (ob
->main_stream
,
762 profile_info
->histogram
[h_ix
].cum_value
);
764 /* IPA-profile computes hot bb threshold based on cumulated
765 whole program profile. We need to stream it down to ltrans. */
767 streamer_write_gcov_count_stream (ob
->main_stream
,
768 get_hot_bb_threshold ());
771 streamer_write_uhwi_stream (ob
->main_stream
, 0);
774 /* Output all callees or indirect outgoing edges. EDGE must be the first such
778 output_outgoing_cgraph_edges (struct cgraph_edge
*edge
,
779 struct lto_simple_output_block
*ob
,
780 lto_symtab_encoder_t encoder
)
785 /* Output edges in backward direction, so the reconstructed callgraph match
786 and it is easy to associate call sites in the IPA pass summaries. */
787 while (edge
->next_callee
)
788 edge
= edge
->next_callee
;
789 for (; edge
; edge
= edge
->prev_callee
)
790 lto_output_edge (ob
, edge
, encoder
);
793 /* Output the part of the cgraph in SET. */
796 output_refs (lto_symtab_encoder_t encoder
)
798 struct lto_simple_output_block
*ob
;
802 ob
= lto_create_simple_output_block (LTO_section_refs
);
804 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
806 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
808 if (!node
->alias
&& !lto_symtab_encoder_in_partition_p (encoder
, node
))
811 count
= node
->ref_list
.nreferences ();
814 streamer_write_gcov_count_stream (ob
->main_stream
, count
);
815 streamer_write_uhwi_stream (ob
->main_stream
,
816 lto_symtab_encoder_lookup (encoder
, node
));
817 for (int i
= 0; node
->iterate_reference (i
, ref
); i
++)
818 lto_output_ref (ob
, ref
, encoder
);
822 streamer_write_uhwi_stream (ob
->main_stream
, 0);
824 lto_destroy_simple_output_block (ob
);
827 /* Add NODE into encoder as well as nodes it is cloned from.
828 Do it in a way so clones appear first. */
831 add_node_to (lto_symtab_encoder_t encoder
, struct cgraph_node
*node
,
835 add_node_to (encoder
, node
->clone_of
, include_body
);
836 else if (include_body
)
837 lto_set_symtab_encoder_encode_body (encoder
, node
);
838 lto_symtab_encoder_encode (encoder
, node
);
841 /* Add all references in NODE to encoders. */
844 create_references (lto_symtab_encoder_t encoder
, symtab_node
*node
)
847 struct ipa_ref
*ref
= NULL
;
848 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
849 if (is_a
<cgraph_node
*> (ref
->referred
))
850 add_node_to (encoder
, dyn_cast
<cgraph_node
*> (ref
->referred
), false);
852 lto_symtab_encoder_encode (encoder
, ref
->referred
);
855 /* Select what needs to be streamed out. In regular lto mode stream everything.
856 In offload lto mode stream only nodes marked as offloadable. */
858 select_what_to_stream (void)
860 struct symtab_node
*snode
;
861 FOR_EACH_SYMBOL (snode
)
862 snode
->need_lto_streaming
= !lto_stream_offload_p
|| snode
->offloadable
;
865 /* Find all symbols we want to stream into given partition and insert them
868 The function actually replaces IN_ENCODER by new one. The reason is that
869 streaming code needs clone's origin to be streamed before clone. This
870 means that we need to insert the nodes in specific order. This order is
871 ignored by the partitioning logic earlier. */
874 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder
)
876 struct cgraph_edge
*edge
;
878 lto_symtab_encoder_t encoder
;
879 lto_symtab_encoder_iterator lsei
;
880 hash_set
<void *> reachable_call_targets
;
882 encoder
= lto_symtab_encoder_new (false);
884 /* Go over all entries in the IN_ENCODER and duplicate them to
885 ENCODER. At the same time insert masters of clones so
886 every master appears before clone. */
887 for (lsei
= lsei_start_function_in_partition (in_encoder
);
888 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
890 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
891 if (!node
->need_lto_streaming
)
893 add_node_to (encoder
, node
, true);
894 lto_set_symtab_encoder_in_partition (encoder
, node
);
895 create_references (encoder
, node
);
896 /* For proper debug info, we need to ship the origins, too. */
897 if (DECL_ABSTRACT_ORIGIN (node
->decl
))
899 struct cgraph_node
*origin_node
900 = cgraph_node::get_create (DECL_ABSTRACT_ORIGIN (node
->decl
));
901 origin_node
->used_as_abstract_origin
= true;
902 add_node_to (encoder
, origin_node
, true);
905 for (lsei
= lsei_start_variable_in_partition (in_encoder
);
906 !lsei_end_p (lsei
); lsei_next_variable_in_partition (&lsei
))
908 varpool_node
*vnode
= lsei_varpool_node (lsei
);
910 if (!vnode
->need_lto_streaming
)
912 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
913 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
914 create_references (encoder
, vnode
);
915 /* For proper debug info, we need to ship the origins, too. */
916 if (DECL_ABSTRACT_ORIGIN (vnode
->decl
))
918 varpool_node
*origin_node
919 = varpool_node::get (DECL_ABSTRACT_ORIGIN (vnode
->decl
));
920 lto_set_symtab_encoder_in_partition (encoder
, origin_node
);
923 /* Pickle in also the initializer of all referenced readonly variables
924 to help folding. Constant pool variables are not shared, so we must
926 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
928 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
929 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
931 if (!lto_symtab_encoder_encode_initializer_p (encoder
,
933 && (((vnode
->ctor_useable_for_folding_p ()
934 && (!DECL_VIRTUAL_P (vnode
->decl
)
936 || flag_ltrans_devirtualize
))
937 || POINTER_BOUNDS_P (vnode
->decl
))))
939 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
940 create_references (encoder
, vnode
);
945 /* Go over all the nodes again to include callees that are not in
947 for (lsei
= lsei_start_function_in_partition (encoder
);
948 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
950 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
951 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
953 struct cgraph_node
*callee
= edge
->callee
;
954 if (!lto_symtab_encoder_in_partition_p (encoder
, callee
))
956 /* We should have moved all the inlines. */
957 gcc_assert (!callee
->global
.inlined_to
);
958 add_node_to (encoder
, callee
, false);
961 /* Add all possible targets for late devirtualization. */
962 if (flag_ltrans_devirtualize
|| !flag_wpa
)
963 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
964 if (edge
->indirect_info
->polymorphic
)
969 vec
<cgraph_node
*>targets
970 = possible_polymorphic_call_targets
971 (edge
, &final
, &cache_token
);
972 if (!reachable_call_targets
.add (cache_token
))
974 for (i
= 0; i
< targets
.length (); i
++)
976 struct cgraph_node
*callee
= targets
[i
];
978 /* Adding an external declarations into the unit serves
979 no purpose and just increases its boundary. */
980 if (callee
->definition
981 && !lto_symtab_encoder_in_partition_p
984 gcc_assert (!callee
->global
.inlined_to
);
985 add_node_to (encoder
, callee
, false);
991 /* Be sure to also insert alias targert and thunk callees. These needs
992 to stay to aid local calling conventions. */
993 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
995 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
996 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
998 if (node
->alias
&& node
->analyzed
)
999 create_references (encoder
, node
);
1001 && cnode
->thunk
.thunk_p
)
1002 add_node_to (encoder
, cnode
->callees
->callee
, false);
1004 lto_symtab_encoder_delete (in_encoder
);
1008 /* Output the part of the symtab in SET and VSET. */
1011 output_symtab (void)
1013 struct cgraph_node
*node
;
1014 struct lto_simple_output_block
*ob
;
1016 lto_symtab_encoder_t encoder
;
1019 output_cgraph_opt_summary ();
1021 ob
= lto_create_simple_output_block (LTO_section_symtab_nodes
);
1023 output_profile_summary (ob
);
1025 /* An encoder for cgraph nodes should have been created by
1026 ipa_write_summaries_1. */
1027 gcc_assert (ob
->decl_state
->symtab_node_encoder
);
1028 encoder
= ob
->decl_state
->symtab_node_encoder
;
1030 /* Write out the nodes. We must first output a node and then its clones,
1031 otherwise at a time reading back the node there would be nothing to clone
1033 n_nodes
= lto_symtab_encoder_size (encoder
);
1034 for (i
= 0; i
< n_nodes
; i
++)
1036 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1037 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1038 lto_output_node (ob
, cnode
, encoder
);
1040 lto_output_varpool_node (ob
, dyn_cast
<varpool_node
*> (node
), encoder
);
1043 /* Go over the nodes in SET again to write edges. */
1044 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
1046 node
= dyn_cast
<cgraph_node
*> (lto_symtab_encoder_deref (encoder
, i
));
1048 && (node
->thunk
.thunk_p
1049 || lto_symtab_encoder_in_partition_p (encoder
, node
)))
1051 output_outgoing_cgraph_edges (node
->callees
, ob
, encoder
);
1052 output_outgoing_cgraph_edges (node
->indirect_calls
, ob
, encoder
);
1056 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1058 lto_destroy_simple_output_block (ob
);
1060 /* Emit toplevel asms.
1061 When doing WPA we must output every asm just once. Since we do not partition asm
1062 nodes at all, output them to first output. This is kind of hack, but should work
1064 if (!asm_nodes_output
)
1066 asm_nodes_output
= true;
1067 lto_output_toplevel_asms ();
1070 output_refs (encoder
);
1073 /* Return identifier encoded in IB as a plain string. */
1076 read_identifier (struct lto_input_block
*ib
)
1078 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1081 if (ib
->data
[ib
->p
+ len
])
1082 lto_section_overrun (ib
);
1088 id
= get_identifier (ib
->data
+ ib
->p
);
1093 /* Return string encoded in IB, NULL if string is empty. */
1096 read_string (struct lto_input_block
*ib
)
1098 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1101 if (ib
->data
[ib
->p
+ len
])
1102 lto_section_overrun (ib
);
1108 str
= ib
->data
+ ib
->p
;
1113 /* Output function/variable tables that will allow libgomp to look up offload
1115 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1116 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1117 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1120 output_offload_tables (void)
1122 if (vec_safe_is_empty (offload_funcs
) && vec_safe_is_empty (offload_vars
))
1125 struct lto_simple_output_block
*ob
1126 = lto_create_simple_output_block (LTO_section_offload_table
);
1128 for (unsigned i
= 0; i
< vec_safe_length (offload_funcs
); i
++)
1130 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1131 LTO_symtab_last_tag
, LTO_symtab_unavail_node
);
1132 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
,
1133 (*offload_funcs
)[i
]);
1136 for (unsigned i
= 0; i
< vec_safe_length (offload_vars
); i
++)
1138 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1139 LTO_symtab_last_tag
, LTO_symtab_variable
);
1140 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
,
1141 (*offload_vars
)[i
]);
1144 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1145 lto_destroy_simple_output_block (ob
);
1147 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1148 streamed to one partition only. That's why we free offload_funcs and
1149 offload_vars after the first call of output_offload_tables. */
1152 vec_free (offload_funcs
);
1153 vec_free (offload_vars
);
1157 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1158 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1159 NODE or to replace the values in it, for instance because the first
1160 time we saw it, the function body was not available but now it
1161 is. BP is a bitpack with all the bitflags for NODE read from the
1165 input_overwrite_node (struct lto_file_decl_data
*file_data
,
1166 struct cgraph_node
*node
,
1167 enum LTO_symtab_tags tag
,
1168 struct bitpack_d
*bp
)
1170 node
->aux
= (void *) tag
;
1171 node
->lto_file_data
= file_data
;
1173 node
->local
.local
= bp_unpack_value (bp
, 1);
1174 node
->externally_visible
= bp_unpack_value (bp
, 1);
1175 node
->no_reorder
= bp_unpack_value (bp
, 1);
1176 node
->definition
= bp_unpack_value (bp
, 1);
1177 node
->local
.versionable
= bp_unpack_value (bp
, 1);
1178 node
->local
.can_change_signature
= bp_unpack_value (bp
, 1);
1179 node
->local
.redefined_extern_inline
= bp_unpack_value (bp
, 1);
1180 node
->force_output
= bp_unpack_value (bp
, 1);
1181 node
->forced_by_abi
= bp_unpack_value (bp
, 1);
1182 node
->unique_name
= bp_unpack_value (bp
, 1);
1183 node
->body_removed
= bp_unpack_value (bp
, 1);
1184 node
->implicit_section
= bp_unpack_value (bp
, 1);
1185 node
->address_taken
= bp_unpack_value (bp
, 1);
1186 node
->used_from_other_partition
= bp_unpack_value (bp
, 1);
1187 node
->lowered
= bp_unpack_value (bp
, 1);
1188 node
->analyzed
= tag
== LTO_symtab_analyzed_node
;
1189 node
->in_other_partition
= bp_unpack_value (bp
, 1);
1190 if (node
->in_other_partition
1191 /* Avoid updating decl when we are seeing just inline clone.
1192 When inlining function that has functions already inlined into it,
1193 we produce clones of inline clones.
1195 WPA partitioning might put each clone into different unit and
1196 we might end up streaming inline clone from other partition
1197 to support clone we are interested in. */
1199 || node
->clone_of
->decl
!= node
->decl
))
1201 DECL_EXTERNAL (node
->decl
) = 1;
1202 TREE_STATIC (node
->decl
) = 0;
1204 node
->alias
= bp_unpack_value (bp
, 1);
1205 node
->weakref
= bp_unpack_value (bp
, 1);
1206 node
->frequency
= (enum node_frequency
)bp_unpack_value (bp
, 2);
1207 node
->only_called_at_startup
= bp_unpack_value (bp
, 1);
1208 node
->only_called_at_exit
= bp_unpack_value (bp
, 1);
1209 node
->tm_clone
= bp_unpack_value (bp
, 1);
1210 node
->calls_comdat_local
= bp_unpack_value (bp
, 1);
1211 node
->icf_merged
= bp_unpack_value (bp
, 1);
1212 node
->nonfreeing_fn
= bp_unpack_value (bp
, 1);
1213 node
->thunk
.thunk_p
= bp_unpack_value (bp
, 1);
1214 node
->parallelized_function
= bp_unpack_value (bp
, 1);
1215 node
->resolution
= bp_unpack_enum (bp
, ld_plugin_symbol_resolution
,
1217 node
->instrumentation_clone
= bp_unpack_value (bp
, 1);
1218 node
->split_part
= bp_unpack_value (bp
, 1);
1219 gcc_assert (flag_ltrans
1220 || (!node
->in_other_partition
1221 && !node
->used_from_other_partition
));
1224 /* Return string alias is alias of. */
1227 get_alias_symbol (tree decl
)
1229 tree alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
1230 return get_identifier (TREE_STRING_POINTER
1231 (TREE_VALUE (TREE_VALUE (alias
))));
1234 /* Read a node from input_block IB. TAG is the node's tag just read.
1235 Return the node read or overwriten. */
1237 static struct cgraph_node
*
1238 input_node (struct lto_file_decl_data
*file_data
,
1239 struct lto_input_block
*ib
,
1240 enum LTO_symtab_tags tag
,
1241 vec
<symtab_node
*> nodes
)
1243 gcc::pass_manager
*passes
= g
->get_passes ();
1245 struct cgraph_node
*node
;
1246 struct bitpack_d bp
;
1247 unsigned decl_index
;
1248 int ref
= LCC_NOT_FOUND
, ref2
= LCC_NOT_FOUND
;
1253 const char *section
;
1254 order
= streamer_read_hwi (ib
) + order_base
;
1255 clone_ref
= streamer_read_hwi (ib
);
1257 decl_index
= streamer_read_uhwi (ib
);
1258 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1260 if (clone_ref
!= LCC_NOT_FOUND
)
1262 node
= dyn_cast
<cgraph_node
*> (nodes
[clone_ref
])->create_clone (fn_decl
,
1263 0, CGRAPH_FREQ_BASE
, false,
1264 vNULL
, false, NULL
, NULL
);
1268 /* Declaration of functions can be already merged with a declaration
1269 from other input file. We keep cgraph unmerged until after streaming
1270 of ipa passes is done. Alays forcingly create a fresh node. */
1271 node
= symtab
->create_empty ();
1272 node
->decl
= fn_decl
;
1273 node
->register_symbol ();
1276 node
->order
= order
;
1277 if (order
>= symtab
->order
)
1278 symtab
->order
= order
+ 1;
1280 node
->count
= streamer_read_gcov_count (ib
);
1281 node
->count_materialization_scale
= streamer_read_hwi (ib
);
1283 count
= streamer_read_hwi (ib
);
1284 node
->ipa_transforms_to_apply
= vNULL
;
1285 for (i
= 0; i
< count
; i
++)
1288 int pid
= streamer_read_hwi (ib
);
1290 gcc_assert (pid
< passes
->passes_by_id_size
);
1291 pass
= passes
->passes_by_id
[pid
];
1292 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*) pass
);
1295 if (tag
== LTO_symtab_analyzed_node
)
1296 ref
= streamer_read_hwi (ib
);
1298 group
= read_identifier (ib
);
1300 ref2
= streamer_read_hwi (ib
);
1302 /* Make sure that we have not read this node before. Nodes that
1303 have already been read will have their tag stored in the 'aux'
1304 field. Since built-in functions can be referenced in multiple
1305 functions, they are expected to be read more than once. */
1306 if (node
->aux
&& !DECL_BUILT_IN (node
->decl
))
1307 internal_error ("bytecode stream: found multiple instances of cgraph "
1308 "node with uid %d", node
->uid
);
1310 node
->tp_first_run
= streamer_read_uhwi (ib
);
1312 bp
= streamer_read_bitpack (ib
);
1314 input_overwrite_node (file_data
, node
, tag
, &bp
);
1316 /* Store a reference for now, and fix up later to be a pointer. */
1317 node
->global
.inlined_to
= (cgraph_node
*) (intptr_t) ref
;
1321 node
->set_comdat_group (group
);
1322 /* Store a reference for now, and fix up later to be a pointer. */
1323 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref2
;
1326 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1327 section
= read_string (ib
);
1329 node
->set_section_for_node (section
);
1331 if (node
->thunk
.thunk_p
)
1333 int type
= streamer_read_uhwi (ib
);
1334 HOST_WIDE_INT fixed_offset
= streamer_read_uhwi (ib
);
1335 HOST_WIDE_INT virtual_value
= streamer_read_uhwi (ib
);
1337 node
->thunk
.fixed_offset
= fixed_offset
;
1338 node
->thunk
.this_adjusting
= (type
& 2);
1339 node
->thunk
.virtual_value
= virtual_value
;
1340 node
->thunk
.virtual_offset_p
= (type
& 4);
1341 node
->thunk
.add_pointer_bounds_args
= (type
& 8);
1343 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1344 node
->alias_target
= get_alias_symbol (node
->decl
);
1345 node
->profile_id
= streamer_read_hwi (ib
);
1346 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
1347 node
->set_init_priority (streamer_read_hwi (ib
));
1348 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
1349 node
->set_fini_priority (streamer_read_hwi (ib
));
1351 if (node
->instrumentation_clone
)
1353 decl_index
= streamer_read_uhwi (ib
);
1354 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1355 node
->orig_decl
= fn_decl
;
1361 /* Read a node from input_block IB. TAG is the node's tag just read.
1362 Return the node read or overwriten. */
1364 static varpool_node
*
1365 input_varpool_node (struct lto_file_decl_data
*file_data
,
1366 struct lto_input_block
*ib
)
1371 struct bitpack_d bp
;
1372 int ref
= LCC_NOT_FOUND
;
1375 const char *section
;
1377 order
= streamer_read_hwi (ib
) + order_base
;
1378 decl_index
= streamer_read_uhwi (ib
);
1379 var_decl
= lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1381 /* Declaration of functions can be already merged with a declaration
1382 from other input file. We keep cgraph unmerged until after streaming
1383 of ipa passes is done. Alays forcingly create a fresh node. */
1384 node
= varpool_node::create_empty ();
1385 node
->decl
= var_decl
;
1386 node
->register_symbol ();
1388 node
->order
= order
;
1389 if (order
>= symtab
->order
)
1390 symtab
->order
= order
+ 1;
1391 node
->lto_file_data
= file_data
;
1393 bp
= streamer_read_bitpack (ib
);
1394 node
->externally_visible
= bp_unpack_value (&bp
, 1);
1395 node
->no_reorder
= bp_unpack_value (&bp
, 1);
1396 node
->force_output
= bp_unpack_value (&bp
, 1);
1397 node
->forced_by_abi
= bp_unpack_value (&bp
, 1);
1398 node
->unique_name
= bp_unpack_value (&bp
, 1);
1399 node
->body_removed
= bp_unpack_value (&bp
, 1);
1400 node
->implicit_section
= bp_unpack_value (&bp
, 1);
1401 node
->writeonly
= bp_unpack_value (&bp
, 1);
1402 node
->definition
= bp_unpack_value (&bp
, 1);
1403 node
->alias
= bp_unpack_value (&bp
, 1);
1404 node
->weakref
= bp_unpack_value (&bp
, 1);
1405 node
->analyzed
= bp_unpack_value (&bp
, 1);
1406 node
->used_from_other_partition
= bp_unpack_value (&bp
, 1);
1407 node
->in_other_partition
= bp_unpack_value (&bp
, 1);
1408 if (node
->in_other_partition
)
1410 DECL_EXTERNAL (node
->decl
) = 1;
1411 TREE_STATIC (node
->decl
) = 0;
1413 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1414 node
->alias_target
= get_alias_symbol (node
->decl
);
1415 node
->tls_model
= (enum tls_model
)bp_unpack_value (&bp
, 3);
1416 node
->used_by_single_function
= (enum tls_model
)bp_unpack_value (&bp
, 1);
1417 node
->need_bounds_init
= bp_unpack_value (&bp
, 1);
1418 group
= read_identifier (ib
);
1421 node
->set_comdat_group (group
);
1422 ref
= streamer_read_hwi (ib
);
1423 /* Store a reference for now, and fix up later to be a pointer. */
1424 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref
;
1427 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1428 section
= read_string (ib
);
1430 node
->set_section_for_node (section
);
1431 node
->resolution
= streamer_read_enum (ib
, ld_plugin_symbol_resolution
,
1433 gcc_assert (flag_ltrans
1434 || (!node
->in_other_partition
1435 && !node
->used_from_other_partition
));
1440 /* Read a node from input_block IB. TAG is the node's tag just read.
1441 Return the node read or overwriten. */
1444 input_ref (struct lto_input_block
*ib
,
1445 symtab_node
*referring_node
,
1446 vec
<symtab_node
*> nodes
)
1448 symtab_node
*node
= NULL
;
1449 struct bitpack_d bp
;
1450 enum ipa_ref_use use
;
1452 struct ipa_ref
*ref
;
1454 bp
= streamer_read_bitpack (ib
);
1455 use
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 3);
1456 speculative
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 1);
1457 node
= nodes
[streamer_read_hwi (ib
)];
1458 ref
= referring_node
->create_reference (node
, use
);
1459 ref
->speculative
= speculative
;
1460 if (is_a
<cgraph_node
*> (referring_node
))
1461 ref
->lto_stmt_uid
= streamer_read_hwi (ib
);
1464 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1465 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1466 edge being read is indirect (in the sense that it has
1467 indirect_unknown_callee set). */
1470 input_edge (struct lto_input_block
*ib
, vec
<symtab_node
*> nodes
,
1473 struct cgraph_node
*caller
, *callee
;
1474 struct cgraph_edge
*edge
;
1475 unsigned int stmt_id
;
1478 cgraph_inline_failed_t inline_failed
;
1479 struct bitpack_d bp
;
1482 caller
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1483 if (caller
== NULL
|| caller
->decl
== NULL_TREE
)
1484 internal_error ("bytecode stream: no caller found while reading edge");
1488 callee
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1489 if (callee
== NULL
|| callee
->decl
== NULL_TREE
)
1490 internal_error ("bytecode stream: no callee found while reading edge");
1495 count
= streamer_read_gcov_count (ib
);
1497 bp
= streamer_read_bitpack (ib
);
1498 inline_failed
= bp_unpack_enum (&bp
, cgraph_inline_failed_t
, CIF_N_REASONS
);
1499 stmt_id
= bp_unpack_var_len_unsigned (&bp
);
1500 freq
= (int) bp_unpack_var_len_unsigned (&bp
);
1503 edge
= caller
->create_indirect_edge (NULL
, 0, count
, freq
);
1505 edge
= caller
->create_edge (callee
, NULL
, count
, freq
);
1507 edge
->indirect_inlining_edge
= bp_unpack_value (&bp
, 1);
1508 edge
->speculative
= bp_unpack_value (&bp
, 1);
1509 edge
->lto_stmt_uid
= stmt_id
;
1510 edge
->inline_failed
= inline_failed
;
1511 edge
->call_stmt_cannot_inline_p
= bp_unpack_value (&bp
, 1);
1512 edge
->can_throw_external
= bp_unpack_value (&bp
, 1);
1513 edge
->in_polymorphic_cdtor
= bp_unpack_value (&bp
, 1);
1516 if (bp_unpack_value (&bp
, 1))
1517 ecf_flags
|= ECF_CONST
;
1518 if (bp_unpack_value (&bp
, 1))
1519 ecf_flags
|= ECF_PURE
;
1520 if (bp_unpack_value (&bp
, 1))
1521 ecf_flags
|= ECF_NORETURN
;
1522 if (bp_unpack_value (&bp
, 1))
1523 ecf_flags
|= ECF_MALLOC
;
1524 if (bp_unpack_value (&bp
, 1))
1525 ecf_flags
|= ECF_NOTHROW
;
1526 if (bp_unpack_value (&bp
, 1))
1527 ecf_flags
|= ECF_RETURNS_TWICE
;
1528 edge
->indirect_info
->ecf_flags
= ecf_flags
;
1529 edge
->indirect_info
->common_target_id
= streamer_read_hwi (ib
);
1530 if (edge
->indirect_info
->common_target_id
)
1531 edge
->indirect_info
->common_target_probability
= streamer_read_hwi (ib
);
1536 /* Read a cgraph from IB using the info in FILE_DATA. */
1538 static vec
<symtab_node
*>
1539 input_cgraph_1 (struct lto_file_decl_data
*file_data
,
1540 struct lto_input_block
*ib
)
1542 enum LTO_symtab_tags tag
;
1543 vec
<symtab_node
*> nodes
= vNULL
;
1547 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1548 order_base
= symtab
->order
;
1551 if (tag
== LTO_symtab_edge
)
1552 input_edge (ib
, nodes
, false);
1553 else if (tag
== LTO_symtab_indirect_edge
)
1554 input_edge (ib
, nodes
, true);
1555 else if (tag
== LTO_symtab_variable
)
1557 node
= input_varpool_node (file_data
, ib
);
1558 nodes
.safe_push (node
);
1559 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1563 node
= input_node (file_data
, ib
, tag
, nodes
);
1564 if (node
== NULL
|| node
->decl
== NULL_TREE
)
1565 internal_error ("bytecode stream: found empty cgraph node");
1566 nodes
.safe_push (node
);
1567 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1570 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1573 lto_input_toplevel_asms (file_data
, order_base
);
1575 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1576 #ifdef ENABLE_CHECKING
1577 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1578 gcc_assert (node
->aux
|| !is_a
<cgraph_node
*> (node
));
1580 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1583 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1585 ref
= (int) (intptr_t) cnode
->global
.inlined_to
;
1587 /* We share declaration of builtins, so we may read same node twice. */
1592 /* Fixup inlined_to from reference to pointer. */
1593 if (ref
!= LCC_NOT_FOUND
)
1594 dyn_cast
<cgraph_node
*> (node
)->global
.inlined_to
1595 = dyn_cast
<cgraph_node
*> (nodes
[ref
]);
1597 cnode
->global
.inlined_to
= NULL
;
1599 /* Compute instrumented_version. */
1600 if (cnode
->instrumentation_clone
)
1602 gcc_assert (cnode
->orig_decl
);
1604 cnode
->instrumented_version
= cgraph_node::get (cnode
->orig_decl
);
1605 if (cnode
->instrumented_version
)
1607 /* We may have multiple nodes for a single function which
1608 will be merged later. To have a proper merge we need
1609 to keep instrumentation_version reference between nodes
1610 consistent: each instrumented_version reference should
1611 have proper reverse reference. Thus don't break existing
1612 instrumented_version reference if it already exists. */
1613 if (cnode
->instrumented_version
->instrumented_version
)
1614 cnode
->instrumented_version
= NULL
;
1616 cnode
->instrumented_version
->instrumented_version
= cnode
;
1619 /* Restore decl names reference. */
1620 IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (cnode
->decl
)) = 1;
1621 TREE_CHAIN (DECL_ASSEMBLER_NAME (cnode
->decl
))
1622 = DECL_ASSEMBLER_NAME (cnode
->orig_decl
);
1626 ref
= (int) (intptr_t) node
->same_comdat_group
;
1628 /* Fixup same_comdat_group from reference to pointer. */
1629 if (ref
!= LCC_NOT_FOUND
)
1630 node
->same_comdat_group
= nodes
[ref
];
1632 node
->same_comdat_group
= NULL
;
1634 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1635 node
->aux
= is_a
<cgraph_node
*> (node
) ? (void *)1 : NULL
;
1639 /* Input ipa_refs. */
1642 input_refs (struct lto_input_block
*ib
,
1643 vec
<symtab_node
*> nodes
)
1650 count
= streamer_read_uhwi (ib
);
1653 idx
= streamer_read_uhwi (ib
);
1657 input_ref (ib
, node
, nodes
);
1664 static struct gcov_ctr_summary lto_gcov_summary
;
1666 /* Input profile_info from IB. */
1668 input_profile_summary (struct lto_input_block
*ib
,
1669 struct lto_file_decl_data
*file_data
)
1672 struct bitpack_d bp
;
1673 unsigned int runs
= streamer_read_uhwi (ib
);
1676 file_data
->profile_info
.runs
= runs
;
1677 file_data
->profile_info
.sum_max
= streamer_read_gcov_count (ib
);
1678 file_data
->profile_info
.sum_all
= streamer_read_gcov_count (ib
);
1680 memset (file_data
->profile_info
.histogram
, 0,
1681 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1682 /* Input the bitpack of non-zero histogram indices. */
1683 bp
= streamer_read_bitpack (ib
);
1684 /* Read in and unpack the full bitpack, flagging non-zero
1685 histogram entries by setting the num_counters non-zero. */
1686 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1688 file_data
->profile_info
.histogram
[h_ix
].num_counters
1689 = bp_unpack_value (&bp
, 1);
1691 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1693 if (!file_data
->profile_info
.histogram
[h_ix
].num_counters
)
1696 file_data
->profile_info
.histogram
[h_ix
].num_counters
1697 = streamer_read_gcov_count (ib
);
1698 file_data
->profile_info
.histogram
[h_ix
].min_value
1699 = streamer_read_gcov_count (ib
);
1700 file_data
->profile_info
.histogram
[h_ix
].cum_value
1701 = streamer_read_gcov_count (ib
);
1703 /* IPA-profile computes hot bb threshold based on cumulated
1704 whole program profile. We need to stream it down to ltrans. */
1706 set_hot_bb_threshold (streamer_read_gcov_count (ib
));
1711 /* Rescale profile summaries to the same number of runs in the whole unit. */
1714 merge_profile_summaries (struct lto_file_decl_data
**file_data_vec
)
1716 struct lto_file_decl_data
*file_data
;
1717 unsigned int j
, h_ix
;
1718 gcov_unsigned_t max_runs
= 0;
1719 struct cgraph_node
*node
;
1720 struct cgraph_edge
*edge
;
1721 gcov_type saved_sum_all
= 0;
1722 gcov_ctr_summary
*saved_profile_info
= 0;
1723 int saved_scale
= 0;
1725 /* Find unit with maximal number of runs. If we ever get serious about
1726 roundoff errors, we might also consider computing smallest common
1728 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1729 if (max_runs
< file_data
->profile_info
.runs
)
1730 max_runs
= file_data
->profile_info
.runs
;
1735 /* Simple overflow check. We probably don't need to support that many train
1736 runs. Such a large value probably imply data corruption anyway. */
1737 if (max_runs
> INT_MAX
/ REG_BR_PROB_BASE
)
1739 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1740 INT_MAX
/ REG_BR_PROB_BASE
);
1744 profile_info
= <o_gcov_summary
;
1745 lto_gcov_summary
.runs
= max_runs
;
1746 lto_gcov_summary
.sum_max
= 0;
1747 memset (lto_gcov_summary
.histogram
, 0,
1748 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1750 /* Rescale all units to the maximal number of runs.
1751 sum_max can not be easily merged, as we have no idea what files come from
1752 the same run. We do not use the info anyway, so leave it 0. */
1753 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1754 if (file_data
->profile_info
.runs
)
1756 int scale
= GCOV_COMPUTE_SCALE (max_runs
,
1757 file_data
->profile_info
.runs
);
1758 lto_gcov_summary
.sum_max
1759 = MAX (lto_gcov_summary
.sum_max
,
1760 apply_scale (file_data
->profile_info
.sum_max
, scale
));
1761 lto_gcov_summary
.sum_all
1762 = MAX (lto_gcov_summary
.sum_all
,
1763 apply_scale (file_data
->profile_info
.sum_all
, scale
));
1764 /* Save a pointer to the profile_info with the largest
1765 scaled sum_all and the scale for use in merging the
1767 if (!saved_profile_info
1768 || lto_gcov_summary
.sum_all
> saved_sum_all
)
1770 saved_profile_info
= &file_data
->profile_info
;
1771 saved_sum_all
= lto_gcov_summary
.sum_all
;
1772 saved_scale
= scale
;
1776 gcc_assert (saved_profile_info
);
1778 /* Scale up the histogram from the profile that had the largest
1779 scaled sum_all above. */
1780 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1782 /* Scale up the min value as we did the corresponding sum_all
1783 above. Use that to find the new histogram index. */
1784 gcov_type scaled_min
1785 = apply_scale (saved_profile_info
->histogram
[h_ix
].min_value
,
1787 /* The new index may be shared with another scaled histogram entry,
1788 so we need to account for a non-zero histogram entry at new_ix. */
1789 unsigned new_ix
= gcov_histo_index (scaled_min
);
1790 lto_gcov_summary
.histogram
[new_ix
].min_value
1791 = (lto_gcov_summary
.histogram
[new_ix
].num_counters
1792 ? MIN (lto_gcov_summary
.histogram
[new_ix
].min_value
, scaled_min
)
1794 /* Some of the scaled counter values would ostensibly need to be placed
1795 into different (larger) histogram buckets, but we keep things simple
1796 here and place the scaled cumulative counter value in the bucket
1797 corresponding to the scaled minimum counter value. */
1798 lto_gcov_summary
.histogram
[new_ix
].cum_value
1799 += apply_scale (saved_profile_info
->histogram
[h_ix
].cum_value
,
1801 lto_gcov_summary
.histogram
[new_ix
].num_counters
1802 += saved_profile_info
->histogram
[h_ix
].num_counters
;
1805 /* Watch roundoff errors. */
1806 if (lto_gcov_summary
.sum_max
< max_runs
)
1807 lto_gcov_summary
.sum_max
= max_runs
;
1809 /* If merging already happent at WPA time, we are done. */
1813 /* Now compute count_materialization_scale of each node.
1814 During LTRANS we already have values of count_materialization_scale
1815 computed, so just update them. */
1816 FOR_EACH_FUNCTION (node
)
1817 if (node
->lto_file_data
1818 && node
->lto_file_data
->profile_info
.runs
)
1822 scale
= RDIV (node
->count_materialization_scale
* max_runs
,
1823 node
->lto_file_data
->profile_info
.runs
);
1824 node
->count_materialization_scale
= scale
;
1826 fatal_error (input_location
, "Profile information in %s corrupted",
1827 file_data
->file_name
);
1829 if (scale
== REG_BR_PROB_BASE
)
1831 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1832 edge
->count
= apply_scale (edge
->count
, scale
);
1833 node
->count
= apply_scale (node
->count
, scale
);
1837 /* Input and merge the symtab from each of the .o files passed to
1843 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1844 struct lto_file_decl_data
*file_data
;
1846 struct cgraph_node
*node
;
1848 while ((file_data
= file_data_vec
[j
++]))
1852 struct lto_input_block
*ib
;
1853 vec
<symtab_node
*> nodes
;
1855 ib
= lto_create_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1858 fatal_error (input_location
,
1859 "cannot find LTO cgraph in %s", file_data
->file_name
);
1860 input_profile_summary (ib
, file_data
);
1861 file_data
->symtab_node_encoder
= lto_symtab_encoder_new (true);
1862 nodes
= input_cgraph_1 (file_data
, ib
);
1863 lto_destroy_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1866 ib
= lto_create_simple_input_block (file_data
, LTO_section_refs
,
1869 fatal_error (input_location
, "cannot find LTO section refs in %s",
1870 file_data
->file_name
);
1871 input_refs (ib
, nodes
);
1872 lto_destroy_simple_input_block (file_data
, LTO_section_refs
,
1875 input_cgraph_opt_summary (nodes
);
1879 merge_profile_summaries (file_data_vec
);
1880 get_working_sets ();
1883 /* Clear out the aux field that was used to store enough state to
1884 tell which nodes should be overwritten. */
1885 FOR_EACH_FUNCTION (node
)
1887 /* Some nodes may have been created by cgraph_node. This
1888 happens when the callgraph contains nested functions. If the
1889 node for the parent function was never emitted to the gimple
1890 file, cgraph_node will create a node for it when setting the
1891 context of the nested function. */
1892 if (node
->lto_file_data
)
1897 /* Input function/variable tables that will allow libgomp to look up offload
1898 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1901 input_offload_tables (void)
1903 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1904 struct lto_file_decl_data
*file_data
;
1907 while ((file_data
= file_data_vec
[j
++]))
1911 struct lto_input_block
*ib
1912 = lto_create_simple_input_block (file_data
, LTO_section_offload_table
,
1917 enum LTO_symtab_tags tag
1918 = streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1921 if (tag
== LTO_symtab_unavail_node
)
1923 int decl_index
= streamer_read_uhwi (ib
);
1925 = lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1926 vec_safe_push (offload_funcs
, fn_decl
);
1928 else if (tag
== LTO_symtab_variable
)
1930 int decl_index
= streamer_read_uhwi (ib
);
1932 = lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1933 vec_safe_push (offload_vars
, var_decl
);
1936 fatal_error (input_location
,
1937 "invalid offload table in %s", file_data
->file_name
);
1939 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1942 lto_destroy_simple_input_block (file_data
, LTO_section_offload_table
,
1947 /* True when we need optimization summary for NODE. */
1950 output_cgraph_opt_summary_p (struct cgraph_node
*node
)
1952 return (node
->clone_of
1953 && (node
->clone
.tree_map
1954 || node
->clone
.args_to_skip
1955 || node
->clone
.combined_args_to_skip
));
1958 /* Output optimization summary for EDGE to OB. */
1960 output_edge_opt_summary (struct output_block
*ob ATTRIBUTE_UNUSED
,
1961 struct cgraph_edge
*edge ATTRIBUTE_UNUSED
)
1965 /* Output optimization summary for NODE to OB. */
1968 output_node_opt_summary (struct output_block
*ob
,
1969 struct cgraph_node
*node
,
1970 lto_symtab_encoder_t encoder
)
1974 struct ipa_replace_map
*map
;
1975 struct bitpack_d bp
;
1977 struct cgraph_edge
*e
;
1979 if (node
->clone
.args_to_skip
)
1981 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.args_to_skip
));
1982 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.args_to_skip
, 0, index
, bi
)
1983 streamer_write_uhwi (ob
, index
);
1986 streamer_write_uhwi (ob
, 0);
1987 if (node
->clone
.combined_args_to_skip
)
1989 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.combined_args_to_skip
));
1990 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.combined_args_to_skip
, 0, index
, bi
)
1991 streamer_write_uhwi (ob
, index
);
1994 streamer_write_uhwi (ob
, 0);
1995 streamer_write_uhwi (ob
, vec_safe_length (node
->clone
.tree_map
));
1996 FOR_EACH_VEC_SAFE_ELT (node
->clone
.tree_map
, i
, map
)
1998 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
1999 mechanism to store function local declarations into summaries. */
2000 gcc_assert (!map
->old_tree
);
2001 streamer_write_uhwi (ob
, map
->parm_num
);
2002 gcc_assert (EXPR_LOCATION (map
->new_tree
) == UNKNOWN_LOCATION
);
2003 stream_write_tree (ob
, map
->new_tree
, true);
2004 bp
= bitpack_create (ob
->main_stream
);
2005 bp_pack_value (&bp
, map
->replace_p
, 1);
2006 bp_pack_value (&bp
, map
->ref_p
, 1);
2007 streamer_write_bitpack (&bp
);
2010 if (lto_symtab_encoder_in_partition_p (encoder
, node
))
2012 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2013 output_edge_opt_summary (ob
, e
);
2014 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2015 output_edge_opt_summary (ob
, e
);
2019 /* Output optimization summaries stored in callgraph.
2020 At the moment it is the clone info structure. */
2023 output_cgraph_opt_summary (void)
2026 lto_symtab_encoder_t encoder
;
2027 struct output_block
*ob
= create_output_block (LTO_section_cgraph_opt_sum
);
2031 encoder
= ob
->decl_state
->symtab_node_encoder
;
2032 n_nodes
= lto_symtab_encoder_size (encoder
);
2033 for (i
= 0; i
< n_nodes
; i
++)
2035 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2036 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2037 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2040 streamer_write_uhwi (ob
, count
);
2041 for (i
= 0; i
< n_nodes
; i
++)
2043 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2044 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2045 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2047 streamer_write_uhwi (ob
, i
);
2048 output_node_opt_summary (ob
, cnode
, encoder
);
2051 produce_asm (ob
, NULL
);
2052 destroy_output_block (ob
);
2055 /* Input optimisation summary of EDGE. */
2058 input_edge_opt_summary (struct cgraph_edge
*edge ATTRIBUTE_UNUSED
,
2059 struct lto_input_block
*ib_main ATTRIBUTE_UNUSED
)
2063 /* Input optimisation summary of NODE. */
2066 input_node_opt_summary (struct cgraph_node
*node
,
2067 struct lto_input_block
*ib_main
,
2068 struct data_in
*data_in
)
2073 struct bitpack_d bp
;
2074 struct cgraph_edge
*e
;
2076 count
= streamer_read_uhwi (ib_main
);
2078 node
->clone
.args_to_skip
= BITMAP_GGC_ALLOC ();
2079 for (i
= 0; i
< count
; i
++)
2081 bit
= streamer_read_uhwi (ib_main
);
2082 bitmap_set_bit (node
->clone
.args_to_skip
, bit
);
2084 count
= streamer_read_uhwi (ib_main
);
2086 node
->clone
.combined_args_to_skip
= BITMAP_GGC_ALLOC ();
2087 for (i
= 0; i
< count
; i
++)
2089 bit
= streamer_read_uhwi (ib_main
);
2090 bitmap_set_bit (node
->clone
.combined_args_to_skip
, bit
);
2092 count
= streamer_read_uhwi (ib_main
);
2093 for (i
= 0; i
< count
; i
++)
2095 struct ipa_replace_map
*map
= ggc_alloc
<ipa_replace_map
> ();
2097 vec_safe_push (node
->clone
.tree_map
, map
);
2098 map
->parm_num
= streamer_read_uhwi (ib_main
);
2099 map
->old_tree
= NULL
;
2100 map
->new_tree
= stream_read_tree (ib_main
, data_in
);
2101 bp
= streamer_read_bitpack (ib_main
);
2102 map
->replace_p
= bp_unpack_value (&bp
, 1);
2103 map
->ref_p
= bp_unpack_value (&bp
, 1);
2105 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2106 input_edge_opt_summary (e
, ib_main
);
2107 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2108 input_edge_opt_summary (e
, ib_main
);
2111 /* Read section in file FILE_DATA of length LEN with data DATA. */
2114 input_cgraph_opt_section (struct lto_file_decl_data
*file_data
,
2115 const char *data
, size_t len
,
2116 vec
<symtab_node
*> nodes
)
2118 const struct lto_function_header
*header
=
2119 (const struct lto_function_header
*) data
;
2120 const int cfg_offset
= sizeof (struct lto_function_header
);
2121 const int main_offset
= cfg_offset
+ header
->cfg_size
;
2122 const int string_offset
= main_offset
+ header
->main_size
;
2123 struct data_in
*data_in
;
2127 lto_input_block
ib_main ((const char *) data
+ main_offset
,
2128 header
->main_size
, file_data
->mode_table
);
2131 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
2132 header
->string_size
, vNULL
);
2133 count
= streamer_read_uhwi (&ib_main
);
2135 for (i
= 0; i
< count
; i
++)
2137 int ref
= streamer_read_uhwi (&ib_main
);
2138 input_node_opt_summary (dyn_cast
<cgraph_node
*> (nodes
[ref
]),
2141 lto_free_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
, data
,
2143 lto_data_in_delete (data_in
);
2146 /* Input optimization summary of cgraph. */
2149 input_cgraph_opt_summary (vec
<symtab_node
*> nodes
)
2151 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
2152 struct lto_file_decl_data
*file_data
;
2155 while ((file_data
= file_data_vec
[j
++]))
2159 lto_get_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
,
2163 input_cgraph_opt_section (file_data
, data
, len
, nodes
);