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"
85 /* True when asm nodes has been output. */
86 bool asm_nodes_output
= false;
88 static void output_cgraph_opt_summary (void);
89 static void input_cgraph_opt_summary (vec
<symtab_node
*> nodes
);
91 /* Number of LDPR values known to GCC. */
92 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
94 /* All node orders are ofsetted by ORDER_BASE. */
95 static int order_base
;
97 /* Cgraph streaming is organized as set of record whose type
98 is indicated by a tag. */
101 /* Must leave 0 for the stopper. */
103 /* Cgraph node without body available. */
104 LTO_symtab_unavail_node
= 1,
105 /* Cgraph node with function body. */
106 LTO_symtab_analyzed_node
,
109 LTO_symtab_indirect_edge
,
114 /* Create a new symtab encoder.
115 if FOR_INPUT, the encoder allocate only datastructures needed
116 to read the symtab. */
119 lto_symtab_encoder_new (bool for_input
)
121 lto_symtab_encoder_t encoder
= XCNEW (struct lto_symtab_encoder_d
);
124 encoder
->map
= new hash_map
<symtab_node
*, size_t>;
125 encoder
->nodes
.create (0);
130 /* Delete ENCODER and its components. */
133 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder
)
135 encoder
->nodes
.release ();
142 /* Return the existing reference number of NODE in the symtab encoder in
143 output block OB. Assign a new reference if this is the first time
147 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder
,
154 lto_encoder_entry entry
= {node
, false, false, false};
156 ref
= encoder
->nodes
.length ();
157 encoder
->nodes
.safe_push (entry
);
161 size_t *slot
= encoder
->map
->get (node
);
164 lto_encoder_entry entry
= {node
, false, false, false};
165 ref
= encoder
->nodes
.length ();
167 encoder
->map
->put (node
, ref
+ 1);
168 encoder
->nodes
.safe_push (entry
);
176 /* Remove NODE from encoder. */
179 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder
,
183 lto_encoder_entry last_node
;
185 size_t *slot
= encoder
->map
->get (node
);
186 if (slot
== NULL
|| !*slot
)
190 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
192 /* Remove from vector. We do this by swapping node with the last element
194 last_node
= encoder
->nodes
.pop ();
195 if (last_node
.node
!= node
)
197 gcc_assert (encoder
->map
->put (last_node
.node
, index
+ 1));
199 /* Move the last element to the original spot of NODE. */
200 encoder
->nodes
[index
] = last_node
;
203 /* Remove element from hash table. */
204 encoder
->map
->remove (node
);
209 /* Return TRUE if we should encode the body of NODE (if any). */
212 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder
,
213 struct cgraph_node
*node
)
215 int index
= lto_symtab_encoder_lookup (encoder
, node
);
216 return encoder
->nodes
[index
].body
;
219 /* Specify that we encode the body of NODE in this partition. */
222 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder
,
223 struct cgraph_node
*node
)
225 int index
= lto_symtab_encoder_encode (encoder
, node
);
226 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
227 encoder
->nodes
[index
].body
= true;
230 /* Return TRUE if we should encode initializer of NODE (if any). */
233 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder
,
236 int index
= lto_symtab_encoder_lookup (encoder
, node
);
237 if (index
== LCC_NOT_FOUND
)
239 return encoder
->nodes
[index
].initializer
;
242 /* Specify that we should encode initializer of NODE (if any). */
245 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder
,
248 int index
= lto_symtab_encoder_lookup (encoder
, node
);
249 encoder
->nodes
[index
].initializer
= true;
252 /* Return TRUE if NODE is in this partition. */
255 lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder
,
258 int index
= lto_symtab_encoder_lookup (encoder
, node
);
259 if (index
== LCC_NOT_FOUND
)
261 return encoder
->nodes
[index
].in_partition
;
264 /* Specify that NODE is in this partition. */
267 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder
,
270 int index
= lto_symtab_encoder_encode (encoder
, node
);
271 encoder
->nodes
[index
].in_partition
= true;
274 /* Output the cgraph EDGE to OB using ENCODER. */
277 lto_output_edge (struct lto_simple_output_block
*ob
, struct cgraph_edge
*edge
,
278 lto_symtab_encoder_t encoder
)
284 if (edge
->indirect_unknown_callee
)
285 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
286 LTO_symtab_indirect_edge
);
288 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
291 ref
= lto_symtab_encoder_lookup (encoder
, edge
->caller
);
292 gcc_assert (ref
!= LCC_NOT_FOUND
);
293 streamer_write_hwi_stream (ob
->main_stream
, ref
);
295 if (!edge
->indirect_unknown_callee
)
297 ref
= lto_symtab_encoder_lookup (encoder
, edge
->callee
);
298 gcc_assert (ref
!= LCC_NOT_FOUND
);
299 streamer_write_hwi_stream (ob
->main_stream
, ref
);
302 streamer_write_gcov_count_stream (ob
->main_stream
, edge
->count
);
304 bp
= bitpack_create (ob
->main_stream
);
305 uid
= (!gimple_has_body_p (edge
->caller
->decl
)
306 ? edge
->lto_stmt_uid
: gimple_uid (edge
->call_stmt
) + 1);
307 bp_pack_enum (&bp
, cgraph_inline_failed_t
,
308 CIF_N_REASONS
, edge
->inline_failed
);
309 bp_pack_var_len_unsigned (&bp
, uid
);
310 bp_pack_var_len_unsigned (&bp
, edge
->frequency
);
311 bp_pack_value (&bp
, edge
->indirect_inlining_edge
, 1);
312 bp_pack_value (&bp
, edge
->speculative
, 1);
313 bp_pack_value (&bp
, edge
->call_stmt_cannot_inline_p
, 1);
314 bp_pack_value (&bp
, edge
->can_throw_external
, 1);
315 bp_pack_value (&bp
, edge
->in_polymorphic_cdtor
, 1);
316 if (edge
->indirect_unknown_callee
)
318 int flags
= edge
->indirect_info
->ecf_flags
;
319 bp_pack_value (&bp
, (flags
& ECF_CONST
) != 0, 1);
320 bp_pack_value (&bp
, (flags
& ECF_PURE
) != 0, 1);
321 bp_pack_value (&bp
, (flags
& ECF_NORETURN
) != 0, 1);
322 bp_pack_value (&bp
, (flags
& ECF_MALLOC
) != 0, 1);
323 bp_pack_value (&bp
, (flags
& ECF_NOTHROW
) != 0, 1);
324 bp_pack_value (&bp
, (flags
& ECF_RETURNS_TWICE
) != 0, 1);
325 /* Flags that should not appear on indirect calls. */
326 gcc_assert (!(flags
& (ECF_LOOPING_CONST_OR_PURE
332 streamer_write_bitpack (&bp
);
333 if (edge
->indirect_unknown_callee
)
335 streamer_write_hwi_stream (ob
->main_stream
,
336 edge
->indirect_info
->common_target_id
);
337 if (edge
->indirect_info
->common_target_id
)
338 streamer_write_hwi_stream
339 (ob
->main_stream
, edge
->indirect_info
->common_target_probability
);
343 /* Return if NODE contain references from other partitions. */
346 referenced_from_other_partition_p (symtab_node
*node
, lto_symtab_encoder_t encoder
)
349 struct ipa_ref
*ref
= NULL
;
351 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
353 /* Ignore references from non-offloadable nodes while streaming NODE into
354 offload LTO section. */
355 if (!ref
->referring
->need_lto_streaming
)
358 if (ref
->referring
->in_other_partition
359 || !lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
365 /* Return true when node is reachable from other partition. */
368 reachable_from_other_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
370 struct cgraph_edge
*e
;
371 if (!node
->definition
)
373 if (node
->global
.inlined_to
)
375 for (e
= node
->callers
; e
; e
= e
->next_caller
)
377 /* Ignore references from non-offloadable nodes while streaming NODE into
378 offload LTO section. */
379 if (!e
->caller
->need_lto_streaming
)
382 if (e
->caller
->in_other_partition
383 || !lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
389 /* Return if NODE contain references from other partitions. */
392 referenced_from_this_partition_p (symtab_node
*node
,
393 lto_symtab_encoder_t encoder
)
396 struct ipa_ref
*ref
= NULL
;
398 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
399 if (lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
404 /* Return true when node is reachable from other partition. */
407 reachable_from_this_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
409 struct cgraph_edge
*e
;
410 for (e
= node
->callers
; e
; e
= e
->next_caller
)
411 if (lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
416 /* Output the cgraph NODE to OB. ENCODER is used to find the
417 reference number of NODE->inlined_to. SET is the set of nodes we
418 are writing to the current file. If NODE is not in SET, then NODE
419 is a boundary of a cgraph_node_set and we pretend NODE just has a
420 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
421 that have had their callgraph node written so far. This is used to
422 determine if NODE is a clone of a previously written node. */
425 lto_output_node (struct lto_simple_output_block
*ob
, struct cgraph_node
*node
,
426 lto_symtab_encoder_t encoder
)
432 bool in_other_partition
= false;
433 struct cgraph_node
*clone_of
, *ultimate_clone_of
;
434 ipa_opt_pass_d
*pass
;
440 boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
442 if (node
->analyzed
&& (!boundary_p
|| node
->alias
|| node
->thunk
.thunk_p
))
443 tag
= LTO_symtab_analyzed_node
;
445 tag
= LTO_symtab_unavail_node
;
447 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
449 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
451 /* In WPA mode, we only output part of the call-graph. Also, we
452 fake cgraph node attributes. There are two cases that we care.
454 Boundary nodes: There are nodes that are not part of SET but are
455 called from within SET. We artificially make them look like
456 externally visible nodes with no function body.
458 Cherry-picked nodes: These are nodes we pulled from other
459 translation units into SET during IPA-inlining. We make them as
460 local static nodes to prevent clashes with other local statics. */
461 if (boundary_p
&& node
->analyzed
462 && node
->get_partitioning_class () == SYMBOL_PARTITION
)
464 /* Inline clones can not be part of boundary.
465 gcc_assert (!node->global.inlined_to);
467 FIXME: At the moment they can be, when partition contains an inline
468 clone that is clone of inline clone from outside partition. We can
469 reshape the clone tree and make other tree to be the root, but it
470 needs a bit extra work and will be promplty done by cgraph_remove_node
471 after reading back. */
472 in_other_partition
= 1;
475 clone_of
= node
->clone_of
;
477 && (ref
= lto_symtab_encoder_lookup (encoder
, clone_of
)) == LCC_NOT_FOUND
)
478 if (clone_of
->prev_sibling_clone
)
479 clone_of
= clone_of
->prev_sibling_clone
;
481 clone_of
= clone_of
->clone_of
;
483 /* See if body of the master function is output. If not, we are seeing only
484 an declaration and we do not need to pass down clone tree. */
485 ultimate_clone_of
= clone_of
;
486 while (ultimate_clone_of
&& ultimate_clone_of
->clone_of
)
487 ultimate_clone_of
= ultimate_clone_of
->clone_of
;
489 if (clone_of
&& !lto_symtab_encoder_encode_body_p (encoder
, ultimate_clone_of
))
492 if (tag
== LTO_symtab_analyzed_node
)
493 gcc_assert (clone_of
|| !node
->clone_of
);
495 streamer_write_hwi_stream (ob
->main_stream
, LCC_NOT_FOUND
);
497 streamer_write_hwi_stream (ob
->main_stream
, ref
);
500 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
501 streamer_write_gcov_count_stream (ob
->main_stream
, node
->count
);
502 streamer_write_hwi_stream (ob
->main_stream
, node
->count_materialization_scale
);
504 streamer_write_hwi_stream (ob
->main_stream
,
505 node
->ipa_transforms_to_apply
.length ());
506 FOR_EACH_VEC_ELT (node
->ipa_transforms_to_apply
, i
, pass
)
507 streamer_write_hwi_stream (ob
->main_stream
, pass
->static_pass_number
);
509 if (tag
== LTO_symtab_analyzed_node
)
511 if (node
->global
.inlined_to
)
513 ref
= lto_symtab_encoder_lookup (encoder
, node
->global
.inlined_to
);
514 gcc_assert (ref
!= LCC_NOT_FOUND
);
519 streamer_write_hwi_stream (ob
->main_stream
, ref
);
522 group
= node
->get_comdat_group ();
524 comdat
= IDENTIFIER_POINTER (group
);
527 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
531 if (node
->same_comdat_group
&& !boundary_p
)
533 ref
= lto_symtab_encoder_lookup (encoder
,
534 node
->same_comdat_group
);
535 gcc_assert (ref
!= LCC_NOT_FOUND
);
539 streamer_write_hwi_stream (ob
->main_stream
, ref
);
542 section
= node
->get_section ();
546 streamer_write_hwi_stream (ob
->main_stream
, node
->tp_first_run
);
548 bp
= bitpack_create (ob
->main_stream
);
549 bp_pack_value (&bp
, node
->local
.local
, 1);
550 bp_pack_value (&bp
, node
->externally_visible
, 1);
551 bp_pack_value (&bp
, node
->no_reorder
, 1);
552 bp_pack_value (&bp
, node
->definition
, 1);
553 bp_pack_value (&bp
, node
->local
.versionable
, 1);
554 bp_pack_value (&bp
, node
->local
.can_change_signature
, 1);
555 bp_pack_value (&bp
, node
->local
.redefined_extern_inline
, 1);
556 bp_pack_value (&bp
, node
->force_output
, 1);
557 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
558 bp_pack_value (&bp
, node
->unique_name
, 1);
559 bp_pack_value (&bp
, node
->body_removed
, 1);
560 bp_pack_value (&bp
, node
->implicit_section
, 1);
561 bp_pack_value (&bp
, node
->address_taken
, 1);
562 bp_pack_value (&bp
, tag
== LTO_symtab_analyzed_node
563 && node
->get_partitioning_class () == SYMBOL_PARTITION
564 && (reachable_from_other_partition_p (node
, encoder
)
565 || referenced_from_other_partition_p (node
, encoder
)), 1);
566 bp_pack_value (&bp
, node
->lowered
, 1);
567 bp_pack_value (&bp
, in_other_partition
, 1);
568 bp_pack_value (&bp
, node
->alias
, 1);
569 bp_pack_value (&bp
, node
->weakref
, 1);
570 bp_pack_value (&bp
, node
->frequency
, 2);
571 bp_pack_value (&bp
, node
->only_called_at_startup
, 1);
572 bp_pack_value (&bp
, node
->only_called_at_exit
, 1);
573 bp_pack_value (&bp
, node
->tm_clone
, 1);
574 bp_pack_value (&bp
, node
->calls_comdat_local
, 1);
575 bp_pack_value (&bp
, node
->icf_merged
, 1);
576 bp_pack_value (&bp
, node
->nonfreeing_fn
, 1);
577 bp_pack_value (&bp
, node
->thunk
.thunk_p
, 1);
578 bp_pack_value (&bp
, node
->parallelized_function
, 1);
579 bp_pack_enum (&bp
, ld_plugin_symbol_resolution
,
580 LDPR_NUM_KNOWN
, node
->resolution
);
581 bp_pack_value (&bp
, node
->instrumentation_clone
, 1);
582 bp_pack_value (&bp
, node
->split_part
, 1);
583 streamer_write_bitpack (&bp
);
584 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
586 if (node
->thunk
.thunk_p
)
588 streamer_write_uhwi_stream
590 1 + (node
->thunk
.this_adjusting
!= 0) * 2
591 + (node
->thunk
.virtual_offset_p
!= 0) * 4
592 + (node
->thunk
.add_pointer_bounds_args
!= 0) * 8);
593 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.fixed_offset
);
594 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.virtual_value
);
596 streamer_write_hwi_stream (ob
->main_stream
, node
->profile_id
);
597 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
598 streamer_write_hwi_stream (ob
->main_stream
, node
->get_init_priority ());
599 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
600 streamer_write_hwi_stream (ob
->main_stream
, node
->get_fini_priority ());
602 if (node
->instrumentation_clone
)
603 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->orig_decl
);
606 /* Output the varpool NODE to OB.
607 If NODE is not in SET, then NODE is a boundary. */
610 lto_output_varpool_node (struct lto_simple_output_block
*ob
, varpool_node
*node
,
611 lto_symtab_encoder_t encoder
)
613 bool boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
614 bool encode_initializer_p
616 && lto_symtab_encoder_encode_initializer_p (encoder
, node
));
623 gcc_assert (!encode_initializer_p
|| node
->definition
);
624 gcc_assert (boundary_p
|| encode_initializer_p
);
626 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
627 LTO_symtab_variable
);
628 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
629 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
630 bp
= bitpack_create (ob
->main_stream
);
631 bp_pack_value (&bp
, node
->externally_visible
, 1);
632 bp_pack_value (&bp
, node
->no_reorder
, 1);
633 bp_pack_value (&bp
, node
->force_output
, 1);
634 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
635 bp_pack_value (&bp
, node
->unique_name
, 1);
638 || (!encode_initializer_p
&& !node
->alias
&& node
->definition
),
640 bp_pack_value (&bp
, node
->implicit_section
, 1);
641 bp_pack_value (&bp
, node
->writeonly
, 1);
642 bp_pack_value (&bp
, node
->definition
&& (encode_initializer_p
|| node
->alias
),
644 bp_pack_value (&bp
, node
->alias
, 1);
645 bp_pack_value (&bp
, node
->weakref
, 1);
646 bp_pack_value (&bp
, node
->analyzed
&& !boundary_p
, 1);
647 gcc_assert (node
->definition
|| !node
->analyzed
);
648 /* Constant pool initializers can be de-unified into individual ltrans units.
649 FIXME: Alternatively at -Os we may want to avoid generating for them the local
650 labels and share them across LTRANS partitions. */
651 if (node
->get_partitioning_class () != SYMBOL_PARTITION
)
653 bp_pack_value (&bp
, 0, 1); /* used_from_other_parition. */
654 bp_pack_value (&bp
, 0, 1); /* in_other_partition. */
658 bp_pack_value (&bp
, node
->definition
659 && referenced_from_other_partition_p (node
, encoder
), 1);
660 bp_pack_value (&bp
, node
->analyzed
661 && boundary_p
&& !DECL_EXTERNAL (node
->decl
), 1);
662 /* in_other_partition. */
664 bp_pack_value (&bp
, node
->tls_model
, 3);
665 bp_pack_value (&bp
, node
->used_by_single_function
, 1);
666 bp_pack_value (&bp
, node
->need_bounds_init
, 1);
667 streamer_write_bitpack (&bp
);
669 group
= node
->get_comdat_group ();
671 comdat
= IDENTIFIER_POINTER (group
);
674 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
678 if (node
->same_comdat_group
&& !boundary_p
)
680 ref
= lto_symtab_encoder_lookup (encoder
,
681 node
->same_comdat_group
);
682 gcc_assert (ref
!= LCC_NOT_FOUND
);
686 streamer_write_hwi_stream (ob
->main_stream
, ref
);
689 section
= node
->get_section ();
692 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
694 streamer_write_enum (ob
->main_stream
, ld_plugin_symbol_resolution
,
695 LDPR_NUM_KNOWN
, node
->resolution
);
698 /* Output the varpool NODE to OB.
699 If NODE is not in SET, then NODE is a boundary. */
702 lto_output_ref (struct lto_simple_output_block
*ob
, struct ipa_ref
*ref
,
703 lto_symtab_encoder_t encoder
)
707 int uid
= ref
->lto_stmt_uid
;
708 struct cgraph_node
*node
;
710 bp
= bitpack_create (ob
->main_stream
);
711 bp_pack_value (&bp
, ref
->use
, 3);
712 bp_pack_value (&bp
, ref
->speculative
, 1);
713 streamer_write_bitpack (&bp
);
714 nref
= lto_symtab_encoder_lookup (encoder
, ref
->referred
);
715 gcc_assert (nref
!= LCC_NOT_FOUND
);
716 streamer_write_hwi_stream (ob
->main_stream
, nref
);
718 node
= dyn_cast
<cgraph_node
*> (ref
->referring
);
722 uid
= gimple_uid (ref
->stmt
) + 1;
723 streamer_write_hwi_stream (ob
->main_stream
, uid
);
727 /* Stream out profile_summary to OB. */
730 output_profile_summary (struct lto_simple_output_block
*ob
)
737 /* We do not output num and run_max, they are not used by
738 GCC profile feedback and they are difficult to merge from multiple
740 gcc_assert (profile_info
->runs
);
741 streamer_write_uhwi_stream (ob
->main_stream
, profile_info
->runs
);
742 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_max
);
744 /* sum_all is needed for computing the working set with the
746 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_all
);
748 /* Create and output a bitpack of non-zero histogram entries indices. */
749 bp
= bitpack_create (ob
->main_stream
);
750 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
751 bp_pack_value (&bp
, profile_info
->histogram
[h_ix
].num_counters
> 0, 1);
752 streamer_write_bitpack (&bp
);
753 /* Now stream out only those non-zero entries. */
754 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
756 if (!profile_info
->histogram
[h_ix
].num_counters
)
758 streamer_write_gcov_count_stream (ob
->main_stream
,
759 profile_info
->histogram
[h_ix
].num_counters
);
760 streamer_write_gcov_count_stream (ob
->main_stream
,
761 profile_info
->histogram
[h_ix
].min_value
);
762 streamer_write_gcov_count_stream (ob
->main_stream
,
763 profile_info
->histogram
[h_ix
].cum_value
);
765 /* IPA-profile computes hot bb threshold based on cumulated
766 whole program profile. We need to stream it down to ltrans. */
768 streamer_write_gcov_count_stream (ob
->main_stream
,
769 get_hot_bb_threshold ());
772 streamer_write_uhwi_stream (ob
->main_stream
, 0);
775 /* Output all callees or indirect outgoing edges. EDGE must be the first such
779 output_outgoing_cgraph_edges (struct cgraph_edge
*edge
,
780 struct lto_simple_output_block
*ob
,
781 lto_symtab_encoder_t encoder
)
786 /* Output edges in backward direction, so the reconstructed callgraph match
787 and it is easy to associate call sites in the IPA pass summaries. */
788 while (edge
->next_callee
)
789 edge
= edge
->next_callee
;
790 for (; edge
; edge
= edge
->prev_callee
)
791 lto_output_edge (ob
, edge
, encoder
);
794 /* Output the part of the cgraph in SET. */
797 output_refs (lto_symtab_encoder_t encoder
)
799 struct lto_simple_output_block
*ob
;
803 ob
= lto_create_simple_output_block (LTO_section_refs
);
805 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
807 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
809 /* IPA_REF_ALIAS and IPA_REF_CHKP references are always preserved
810 in the boundary. Alias node can't have other references and
811 can be always handled as if it's not in the boundary. */
812 if (!node
->alias
&& !lto_symtab_encoder_in_partition_p (encoder
, node
))
814 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
815 /* Output IPA_REF_CHKP reference. */
817 && cnode
->instrumented_version
818 && !cnode
->instrumentation_clone
)
820 for (int i
= 0; node
->iterate_reference (i
, ref
); i
++)
821 if (ref
->use
== IPA_REF_CHKP
)
823 if (lto_symtab_encoder_lookup (encoder
, ref
->referred
)
826 int nref
= lto_symtab_encoder_lookup (encoder
, node
);
827 streamer_write_gcov_count_stream (ob
->main_stream
, 1);
828 streamer_write_uhwi_stream (ob
->main_stream
, nref
);
829 lto_output_ref (ob
, ref
, encoder
);
837 count
= node
->ref_list
.nreferences ();
840 streamer_write_gcov_count_stream (ob
->main_stream
, count
);
841 streamer_write_uhwi_stream (ob
->main_stream
,
842 lto_symtab_encoder_lookup (encoder
, node
));
843 for (int i
= 0; node
->iterate_reference (i
, ref
); i
++)
844 lto_output_ref (ob
, ref
, encoder
);
848 streamer_write_uhwi_stream (ob
->main_stream
, 0);
850 lto_destroy_simple_output_block (ob
);
853 /* Add NODE into encoder as well as nodes it is cloned from.
854 Do it in a way so clones appear first. */
857 add_node_to (lto_symtab_encoder_t encoder
, struct cgraph_node
*node
,
861 add_node_to (encoder
, node
->clone_of
, include_body
);
862 else if (include_body
)
863 lto_set_symtab_encoder_encode_body (encoder
, node
);
864 lto_symtab_encoder_encode (encoder
, node
);
867 /* Add all references in NODE to encoders. */
870 create_references (lto_symtab_encoder_t encoder
, symtab_node
*node
)
873 struct ipa_ref
*ref
= NULL
;
874 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
875 if (is_a
<cgraph_node
*> (ref
->referred
))
876 add_node_to (encoder
, dyn_cast
<cgraph_node
*> (ref
->referred
), false);
878 lto_symtab_encoder_encode (encoder
, ref
->referred
);
881 /* Select what needs to be streamed out. In regular lto mode stream everything.
882 In offload lto mode stream only nodes marked as offloadable. */
884 select_what_to_stream (void)
886 struct symtab_node
*snode
;
887 FOR_EACH_SYMBOL (snode
)
888 snode
->need_lto_streaming
= !lto_stream_offload_p
|| snode
->offloadable
;
891 /* Find all symbols we want to stream into given partition and insert them
894 The function actually replaces IN_ENCODER by new one. The reason is that
895 streaming code needs clone's origin to be streamed before clone. This
896 means that we need to insert the nodes in specific order. This order is
897 ignored by the partitioning logic earlier. */
900 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder
)
902 struct cgraph_edge
*edge
;
904 lto_symtab_encoder_t encoder
;
905 lto_symtab_encoder_iterator lsei
;
906 hash_set
<void *> reachable_call_targets
;
908 encoder
= lto_symtab_encoder_new (false);
910 /* Go over all entries in the IN_ENCODER and duplicate them to
911 ENCODER. At the same time insert masters of clones so
912 every master appears before clone. */
913 for (lsei
= lsei_start_function_in_partition (in_encoder
);
914 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
916 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
917 if (!node
->need_lto_streaming
)
919 add_node_to (encoder
, node
, true);
920 lto_set_symtab_encoder_in_partition (encoder
, node
);
921 create_references (encoder
, node
);
922 /* For proper debug info, we need to ship the origins, too. */
923 if (DECL_ABSTRACT_ORIGIN (node
->decl
))
925 struct cgraph_node
*origin_node
926 = cgraph_node::get_create (DECL_ABSTRACT_ORIGIN (node
->decl
));
927 origin_node
->used_as_abstract_origin
= true;
928 add_node_to (encoder
, origin_node
, true);
931 for (lsei
= lsei_start_variable_in_partition (in_encoder
);
932 !lsei_end_p (lsei
); lsei_next_variable_in_partition (&lsei
))
934 varpool_node
*vnode
= lsei_varpool_node (lsei
);
936 if (!vnode
->need_lto_streaming
)
938 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
939 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
940 create_references (encoder
, vnode
);
941 /* For proper debug info, we need to ship the origins, too. */
942 if (DECL_ABSTRACT_ORIGIN (vnode
->decl
))
944 varpool_node
*origin_node
945 = varpool_node::get (DECL_ABSTRACT_ORIGIN (vnode
->decl
));
946 lto_set_symtab_encoder_in_partition (encoder
, origin_node
);
949 /* Pickle in also the initializer of all referenced readonly variables
950 to help folding. Constant pool variables are not shared, so we must
952 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
954 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
955 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
957 if (!lto_symtab_encoder_encode_initializer_p (encoder
,
959 && (((vnode
->ctor_useable_for_folding_p ()
960 && (!DECL_VIRTUAL_P (vnode
->decl
)
962 || flag_ltrans_devirtualize
))
963 || POINTER_BOUNDS_P (vnode
->decl
))))
965 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
966 create_references (encoder
, vnode
);
971 /* Go over all the nodes again to include callees that are not in
973 for (lsei
= lsei_start_function_in_partition (encoder
);
974 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
976 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
977 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
979 struct cgraph_node
*callee
= edge
->callee
;
980 if (!lto_symtab_encoder_in_partition_p (encoder
, callee
))
982 /* We should have moved all the inlines. */
983 gcc_assert (!callee
->global
.inlined_to
);
984 add_node_to (encoder
, callee
, false);
987 /* Add all possible targets for late devirtualization. */
988 if (flag_ltrans_devirtualize
|| !flag_wpa
)
989 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
990 if (edge
->indirect_info
->polymorphic
)
995 vec
<cgraph_node
*>targets
996 = possible_polymorphic_call_targets
997 (edge
, &final
, &cache_token
);
998 if (!reachable_call_targets
.add (cache_token
))
1000 for (i
= 0; i
< targets
.length (); i
++)
1002 struct cgraph_node
*callee
= targets
[i
];
1004 /* Adding an external declarations into the unit serves
1005 no purpose and just increases its boundary. */
1006 if (callee
->definition
1007 && !lto_symtab_encoder_in_partition_p
1010 gcc_assert (!callee
->global
.inlined_to
);
1011 add_node_to (encoder
, callee
, false);
1017 /* Be sure to also insert alias targert and thunk callees. These needs
1018 to stay to aid local calling conventions. */
1019 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
1021 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1022 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
1024 if (node
->alias
&& node
->analyzed
)
1025 create_references (encoder
, node
);
1027 && cnode
->thunk
.thunk_p
)
1028 add_node_to (encoder
, cnode
->callees
->callee
, false);
1030 lto_symtab_encoder_delete (in_encoder
);
1034 /* Output the part of the symtab in SET and VSET. */
1037 output_symtab (void)
1039 struct cgraph_node
*node
;
1040 struct lto_simple_output_block
*ob
;
1042 lto_symtab_encoder_t encoder
;
1045 output_cgraph_opt_summary ();
1047 ob
= lto_create_simple_output_block (LTO_section_symtab_nodes
);
1049 output_profile_summary (ob
);
1051 /* An encoder for cgraph nodes should have been created by
1052 ipa_write_summaries_1. */
1053 gcc_assert (ob
->decl_state
->symtab_node_encoder
);
1054 encoder
= ob
->decl_state
->symtab_node_encoder
;
1056 /* Write out the nodes. We must first output a node and then its clones,
1057 otherwise at a time reading back the node there would be nothing to clone
1059 n_nodes
= lto_symtab_encoder_size (encoder
);
1060 for (i
= 0; i
< n_nodes
; i
++)
1062 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1063 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1064 lto_output_node (ob
, cnode
, encoder
);
1066 lto_output_varpool_node (ob
, dyn_cast
<varpool_node
*> (node
), encoder
);
1069 /* Go over the nodes in SET again to write edges. */
1070 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
1072 node
= dyn_cast
<cgraph_node
*> (lto_symtab_encoder_deref (encoder
, i
));
1074 && (node
->thunk
.thunk_p
1075 || lto_symtab_encoder_in_partition_p (encoder
, node
)))
1077 output_outgoing_cgraph_edges (node
->callees
, ob
, encoder
);
1078 output_outgoing_cgraph_edges (node
->indirect_calls
, ob
, encoder
);
1082 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1084 lto_destroy_simple_output_block (ob
);
1086 /* Emit toplevel asms.
1087 When doing WPA we must output every asm just once. Since we do not partition asm
1088 nodes at all, output them to first output. This is kind of hack, but should work
1090 if (!asm_nodes_output
)
1092 asm_nodes_output
= true;
1093 lto_output_toplevel_asms ();
1096 output_refs (encoder
);
1099 /* Return identifier encoded in IB as a plain string. */
1102 read_identifier (struct lto_input_block
*ib
)
1104 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1107 if (ib
->data
[ib
->p
+ len
])
1108 lto_section_overrun (ib
);
1114 id
= get_identifier (ib
->data
+ ib
->p
);
1119 /* Return string encoded in IB, NULL if string is empty. */
1122 read_string (struct lto_input_block
*ib
)
1124 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1127 if (ib
->data
[ib
->p
+ len
])
1128 lto_section_overrun (ib
);
1134 str
= ib
->data
+ ib
->p
;
1139 /* Output function/variable tables that will allow libgomp to look up offload
1141 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1142 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1143 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1146 output_offload_tables (void)
1148 if (vec_safe_is_empty (offload_funcs
) && vec_safe_is_empty (offload_vars
))
1151 struct lto_simple_output_block
*ob
1152 = lto_create_simple_output_block (LTO_section_offload_table
);
1154 for (unsigned i
= 0; i
< vec_safe_length (offload_funcs
); i
++)
1156 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1157 LTO_symtab_last_tag
, LTO_symtab_unavail_node
);
1158 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
,
1159 (*offload_funcs
)[i
]);
1162 for (unsigned i
= 0; i
< vec_safe_length (offload_vars
); i
++)
1164 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1165 LTO_symtab_last_tag
, LTO_symtab_variable
);
1166 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
,
1167 (*offload_vars
)[i
]);
1170 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1171 lto_destroy_simple_output_block (ob
);
1173 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1174 streamed to one partition only. That's why we free offload_funcs and
1175 offload_vars after the first call of output_offload_tables. */
1178 vec_free (offload_funcs
);
1179 vec_free (offload_vars
);
1183 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1184 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1185 NODE or to replace the values in it, for instance because the first
1186 time we saw it, the function body was not available but now it
1187 is. BP is a bitpack with all the bitflags for NODE read from the
1191 input_overwrite_node (struct lto_file_decl_data
*file_data
,
1192 struct cgraph_node
*node
,
1193 enum LTO_symtab_tags tag
,
1194 struct bitpack_d
*bp
)
1196 node
->aux
= (void *) tag
;
1197 node
->lto_file_data
= file_data
;
1199 node
->local
.local
= bp_unpack_value (bp
, 1);
1200 node
->externally_visible
= bp_unpack_value (bp
, 1);
1201 node
->no_reorder
= bp_unpack_value (bp
, 1);
1202 node
->definition
= bp_unpack_value (bp
, 1);
1203 node
->local
.versionable
= bp_unpack_value (bp
, 1);
1204 node
->local
.can_change_signature
= bp_unpack_value (bp
, 1);
1205 node
->local
.redefined_extern_inline
= bp_unpack_value (bp
, 1);
1206 node
->force_output
= bp_unpack_value (bp
, 1);
1207 node
->forced_by_abi
= bp_unpack_value (bp
, 1);
1208 node
->unique_name
= bp_unpack_value (bp
, 1);
1209 node
->body_removed
= bp_unpack_value (bp
, 1);
1210 node
->implicit_section
= bp_unpack_value (bp
, 1);
1211 node
->address_taken
= bp_unpack_value (bp
, 1);
1212 node
->used_from_other_partition
= bp_unpack_value (bp
, 1);
1213 node
->lowered
= bp_unpack_value (bp
, 1);
1214 node
->analyzed
= tag
== LTO_symtab_analyzed_node
;
1215 node
->in_other_partition
= bp_unpack_value (bp
, 1);
1216 if (node
->in_other_partition
1217 /* Avoid updating decl when we are seeing just inline clone.
1218 When inlining function that has functions already inlined into it,
1219 we produce clones of inline clones.
1221 WPA partitioning might put each clone into different unit and
1222 we might end up streaming inline clone from other partition
1223 to support clone we are interested in. */
1225 || node
->clone_of
->decl
!= node
->decl
))
1227 DECL_EXTERNAL (node
->decl
) = 1;
1228 TREE_STATIC (node
->decl
) = 0;
1230 node
->alias
= bp_unpack_value (bp
, 1);
1231 node
->weakref
= bp_unpack_value (bp
, 1);
1232 node
->frequency
= (enum node_frequency
)bp_unpack_value (bp
, 2);
1233 node
->only_called_at_startup
= bp_unpack_value (bp
, 1);
1234 node
->only_called_at_exit
= bp_unpack_value (bp
, 1);
1235 node
->tm_clone
= bp_unpack_value (bp
, 1);
1236 node
->calls_comdat_local
= bp_unpack_value (bp
, 1);
1237 node
->icf_merged
= bp_unpack_value (bp
, 1);
1238 node
->nonfreeing_fn
= bp_unpack_value (bp
, 1);
1239 node
->thunk
.thunk_p
= bp_unpack_value (bp
, 1);
1240 node
->parallelized_function
= bp_unpack_value (bp
, 1);
1241 node
->resolution
= bp_unpack_enum (bp
, ld_plugin_symbol_resolution
,
1243 node
->instrumentation_clone
= bp_unpack_value (bp
, 1);
1244 node
->split_part
= bp_unpack_value (bp
, 1);
1245 gcc_assert (flag_ltrans
1246 || (!node
->in_other_partition
1247 && !node
->used_from_other_partition
));
1250 /* Return string alias is alias of. */
1253 get_alias_symbol (tree decl
)
1255 tree alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
1256 return get_identifier (TREE_STRING_POINTER
1257 (TREE_VALUE (TREE_VALUE (alias
))));
1260 /* Read a node from input_block IB. TAG is the node's tag just read.
1261 Return the node read or overwriten. */
1263 static struct cgraph_node
*
1264 input_node (struct lto_file_decl_data
*file_data
,
1265 struct lto_input_block
*ib
,
1266 enum LTO_symtab_tags tag
,
1267 vec
<symtab_node
*> nodes
)
1269 gcc::pass_manager
*passes
= g
->get_passes ();
1271 struct cgraph_node
*node
;
1272 struct bitpack_d bp
;
1273 unsigned decl_index
;
1274 int ref
= LCC_NOT_FOUND
, ref2
= LCC_NOT_FOUND
;
1279 const char *section
;
1280 order
= streamer_read_hwi (ib
) + order_base
;
1281 clone_ref
= streamer_read_hwi (ib
);
1283 decl_index
= streamer_read_uhwi (ib
);
1284 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1286 if (clone_ref
!= LCC_NOT_FOUND
)
1288 node
= dyn_cast
<cgraph_node
*> (nodes
[clone_ref
])->create_clone (fn_decl
,
1289 0, CGRAPH_FREQ_BASE
, false,
1290 vNULL
, false, NULL
, NULL
);
1294 /* Declaration of functions can be already merged with a declaration
1295 from other input file. We keep cgraph unmerged until after streaming
1296 of ipa passes is done. Alays forcingly create a fresh node. */
1297 node
= symtab
->create_empty ();
1298 node
->decl
= fn_decl
;
1299 node
->register_symbol ();
1302 node
->order
= order
;
1303 if (order
>= symtab
->order
)
1304 symtab
->order
= order
+ 1;
1306 node
->count
= streamer_read_gcov_count (ib
);
1307 node
->count_materialization_scale
= streamer_read_hwi (ib
);
1309 count
= streamer_read_hwi (ib
);
1310 node
->ipa_transforms_to_apply
= vNULL
;
1311 for (i
= 0; i
< count
; i
++)
1314 int pid
= streamer_read_hwi (ib
);
1316 gcc_assert (pid
< passes
->passes_by_id_size
);
1317 pass
= passes
->passes_by_id
[pid
];
1318 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*) pass
);
1321 if (tag
== LTO_symtab_analyzed_node
)
1322 ref
= streamer_read_hwi (ib
);
1324 group
= read_identifier (ib
);
1326 ref2
= streamer_read_hwi (ib
);
1328 /* Make sure that we have not read this node before. Nodes that
1329 have already been read will have their tag stored in the 'aux'
1330 field. Since built-in functions can be referenced in multiple
1331 functions, they are expected to be read more than once. */
1332 if (node
->aux
&& !DECL_BUILT_IN (node
->decl
))
1333 internal_error ("bytecode stream: found multiple instances of cgraph "
1334 "node with uid %d", node
->uid
);
1336 node
->tp_first_run
= streamer_read_uhwi (ib
);
1338 bp
= streamer_read_bitpack (ib
);
1340 input_overwrite_node (file_data
, node
, tag
, &bp
);
1342 /* Store a reference for now, and fix up later to be a pointer. */
1343 node
->global
.inlined_to
= (cgraph_node
*) (intptr_t) ref
;
1347 node
->set_comdat_group (group
);
1348 /* Store a reference for now, and fix up later to be a pointer. */
1349 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref2
;
1352 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1353 section
= read_string (ib
);
1355 node
->set_section_for_node (section
);
1357 if (node
->thunk
.thunk_p
)
1359 int type
= streamer_read_uhwi (ib
);
1360 HOST_WIDE_INT fixed_offset
= streamer_read_uhwi (ib
);
1361 HOST_WIDE_INT virtual_value
= streamer_read_uhwi (ib
);
1363 node
->thunk
.fixed_offset
= fixed_offset
;
1364 node
->thunk
.this_adjusting
= (type
& 2);
1365 node
->thunk
.virtual_value
= virtual_value
;
1366 node
->thunk
.virtual_offset_p
= (type
& 4);
1367 node
->thunk
.add_pointer_bounds_args
= (type
& 8);
1369 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1370 node
->alias_target
= get_alias_symbol (node
->decl
);
1371 node
->profile_id
= streamer_read_hwi (ib
);
1372 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
1373 node
->set_init_priority (streamer_read_hwi (ib
));
1374 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
1375 node
->set_fini_priority (streamer_read_hwi (ib
));
1377 if (node
->instrumentation_clone
)
1379 decl_index
= streamer_read_uhwi (ib
);
1380 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1381 node
->orig_decl
= fn_decl
;
1387 /* Read a node from input_block IB. TAG is the node's tag just read.
1388 Return the node read or overwriten. */
1390 static varpool_node
*
1391 input_varpool_node (struct lto_file_decl_data
*file_data
,
1392 struct lto_input_block
*ib
)
1397 struct bitpack_d bp
;
1398 int ref
= LCC_NOT_FOUND
;
1401 const char *section
;
1403 order
= streamer_read_hwi (ib
) + order_base
;
1404 decl_index
= streamer_read_uhwi (ib
);
1405 var_decl
= lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1407 /* Declaration of functions can be already merged with a declaration
1408 from other input file. We keep cgraph unmerged until after streaming
1409 of ipa passes is done. Alays forcingly create a fresh node. */
1410 node
= varpool_node::create_empty ();
1411 node
->decl
= var_decl
;
1412 node
->register_symbol ();
1414 node
->order
= order
;
1415 if (order
>= symtab
->order
)
1416 symtab
->order
= order
+ 1;
1417 node
->lto_file_data
= file_data
;
1419 bp
= streamer_read_bitpack (ib
);
1420 node
->externally_visible
= bp_unpack_value (&bp
, 1);
1421 node
->no_reorder
= bp_unpack_value (&bp
, 1);
1422 node
->force_output
= bp_unpack_value (&bp
, 1);
1423 node
->forced_by_abi
= bp_unpack_value (&bp
, 1);
1424 node
->unique_name
= bp_unpack_value (&bp
, 1);
1425 node
->body_removed
= bp_unpack_value (&bp
, 1);
1426 node
->implicit_section
= bp_unpack_value (&bp
, 1);
1427 node
->writeonly
= bp_unpack_value (&bp
, 1);
1428 node
->definition
= bp_unpack_value (&bp
, 1);
1429 node
->alias
= bp_unpack_value (&bp
, 1);
1430 node
->weakref
= bp_unpack_value (&bp
, 1);
1431 node
->analyzed
= bp_unpack_value (&bp
, 1);
1432 node
->used_from_other_partition
= bp_unpack_value (&bp
, 1);
1433 node
->in_other_partition
= bp_unpack_value (&bp
, 1);
1434 if (node
->in_other_partition
)
1436 DECL_EXTERNAL (node
->decl
) = 1;
1437 TREE_STATIC (node
->decl
) = 0;
1439 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1440 node
->alias_target
= get_alias_symbol (node
->decl
);
1441 node
->tls_model
= (enum tls_model
)bp_unpack_value (&bp
, 3);
1442 node
->used_by_single_function
= (enum tls_model
)bp_unpack_value (&bp
, 1);
1443 node
->need_bounds_init
= bp_unpack_value (&bp
, 1);
1444 group
= read_identifier (ib
);
1447 node
->set_comdat_group (group
);
1448 ref
= streamer_read_hwi (ib
);
1449 /* Store a reference for now, and fix up later to be a pointer. */
1450 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref
;
1453 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1454 section
= read_string (ib
);
1456 node
->set_section_for_node (section
);
1457 node
->resolution
= streamer_read_enum (ib
, ld_plugin_symbol_resolution
,
1459 gcc_assert (flag_ltrans
1460 || (!node
->in_other_partition
1461 && !node
->used_from_other_partition
));
1466 /* Read a node from input_block IB. TAG is the node's tag just read.
1467 Return the node read or overwriten. */
1470 input_ref (struct lto_input_block
*ib
,
1471 symtab_node
*referring_node
,
1472 vec
<symtab_node
*> nodes
)
1474 symtab_node
*node
= NULL
;
1475 struct bitpack_d bp
;
1476 enum ipa_ref_use use
;
1478 struct ipa_ref
*ref
;
1480 bp
= streamer_read_bitpack (ib
);
1481 use
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 3);
1482 speculative
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 1);
1483 node
= nodes
[streamer_read_hwi (ib
)];
1484 ref
= referring_node
->create_reference (node
, use
);
1485 ref
->speculative
= speculative
;
1486 if (is_a
<cgraph_node
*> (referring_node
))
1487 ref
->lto_stmt_uid
= streamer_read_hwi (ib
);
1490 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1491 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1492 edge being read is indirect (in the sense that it has
1493 indirect_unknown_callee set). */
1496 input_edge (struct lto_input_block
*ib
, vec
<symtab_node
*> nodes
,
1499 struct cgraph_node
*caller
, *callee
;
1500 struct cgraph_edge
*edge
;
1501 unsigned int stmt_id
;
1504 cgraph_inline_failed_t inline_failed
;
1505 struct bitpack_d bp
;
1508 caller
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1509 if (caller
== NULL
|| caller
->decl
== NULL_TREE
)
1510 internal_error ("bytecode stream: no caller found while reading edge");
1514 callee
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1515 if (callee
== NULL
|| callee
->decl
== NULL_TREE
)
1516 internal_error ("bytecode stream: no callee found while reading edge");
1521 count
= streamer_read_gcov_count (ib
);
1523 bp
= streamer_read_bitpack (ib
);
1524 inline_failed
= bp_unpack_enum (&bp
, cgraph_inline_failed_t
, CIF_N_REASONS
);
1525 stmt_id
= bp_unpack_var_len_unsigned (&bp
);
1526 freq
= (int) bp_unpack_var_len_unsigned (&bp
);
1529 edge
= caller
->create_indirect_edge (NULL
, 0, count
, freq
);
1531 edge
= caller
->create_edge (callee
, NULL
, count
, freq
);
1533 edge
->indirect_inlining_edge
= bp_unpack_value (&bp
, 1);
1534 edge
->speculative
= bp_unpack_value (&bp
, 1);
1535 edge
->lto_stmt_uid
= stmt_id
;
1536 edge
->inline_failed
= inline_failed
;
1537 edge
->call_stmt_cannot_inline_p
= bp_unpack_value (&bp
, 1);
1538 edge
->can_throw_external
= bp_unpack_value (&bp
, 1);
1539 edge
->in_polymorphic_cdtor
= bp_unpack_value (&bp
, 1);
1542 if (bp_unpack_value (&bp
, 1))
1543 ecf_flags
|= ECF_CONST
;
1544 if (bp_unpack_value (&bp
, 1))
1545 ecf_flags
|= ECF_PURE
;
1546 if (bp_unpack_value (&bp
, 1))
1547 ecf_flags
|= ECF_NORETURN
;
1548 if (bp_unpack_value (&bp
, 1))
1549 ecf_flags
|= ECF_MALLOC
;
1550 if (bp_unpack_value (&bp
, 1))
1551 ecf_flags
|= ECF_NOTHROW
;
1552 if (bp_unpack_value (&bp
, 1))
1553 ecf_flags
|= ECF_RETURNS_TWICE
;
1554 edge
->indirect_info
->ecf_flags
= ecf_flags
;
1555 edge
->indirect_info
->common_target_id
= streamer_read_hwi (ib
);
1556 if (edge
->indirect_info
->common_target_id
)
1557 edge
->indirect_info
->common_target_probability
= streamer_read_hwi (ib
);
1562 /* Read a cgraph from IB using the info in FILE_DATA. */
1564 static vec
<symtab_node
*>
1565 input_cgraph_1 (struct lto_file_decl_data
*file_data
,
1566 struct lto_input_block
*ib
)
1568 enum LTO_symtab_tags tag
;
1569 vec
<symtab_node
*> nodes
= vNULL
;
1573 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1574 order_base
= symtab
->order
;
1577 if (tag
== LTO_symtab_edge
)
1578 input_edge (ib
, nodes
, false);
1579 else if (tag
== LTO_symtab_indirect_edge
)
1580 input_edge (ib
, nodes
, true);
1581 else if (tag
== LTO_symtab_variable
)
1583 node
= input_varpool_node (file_data
, ib
);
1584 nodes
.safe_push (node
);
1585 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1589 node
= input_node (file_data
, ib
, tag
, nodes
);
1590 if (node
== NULL
|| node
->decl
== NULL_TREE
)
1591 internal_error ("bytecode stream: found empty cgraph node");
1592 nodes
.safe_push (node
);
1593 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1596 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1599 lto_input_toplevel_asms (file_data
, order_base
);
1601 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1602 #ifdef ENABLE_CHECKING
1603 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1604 gcc_assert (node
->aux
|| !is_a
<cgraph_node
*> (node
));
1606 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1609 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1611 ref
= (int) (intptr_t) cnode
->global
.inlined_to
;
1613 /* We share declaration of builtins, so we may read same node twice. */
1618 /* Fixup inlined_to from reference to pointer. */
1619 if (ref
!= LCC_NOT_FOUND
)
1620 dyn_cast
<cgraph_node
*> (node
)->global
.inlined_to
1621 = dyn_cast
<cgraph_node
*> (nodes
[ref
]);
1623 cnode
->global
.inlined_to
= NULL
;
1625 /* Compute instrumented_version. */
1626 if (cnode
->instrumentation_clone
)
1628 gcc_assert (cnode
->orig_decl
);
1630 cnode
->instrumented_version
= cgraph_node::get (cnode
->orig_decl
);
1631 if (cnode
->instrumented_version
)
1633 /* We may have multiple nodes for a single function which
1634 will be merged later. To have a proper merge we need
1635 to keep instrumentation_version reference between nodes
1636 consistent: each instrumented_version reference should
1637 have proper reverse reference. Thus don't break existing
1638 instrumented_version reference if it already exists. */
1639 if (cnode
->instrumented_version
->instrumented_version
)
1640 cnode
->instrumented_version
= NULL
;
1642 cnode
->instrumented_version
->instrumented_version
= cnode
;
1645 /* Restore decl names reference except for wrapper functions. */
1646 if (!chkp_wrap_function (cnode
->orig_decl
))
1648 tree name
= DECL_ASSEMBLER_NAME (cnode
->decl
);
1649 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
1650 TREE_CHAIN (name
) = DECL_ASSEMBLER_NAME (cnode
->orig_decl
);
1655 ref
= (int) (intptr_t) node
->same_comdat_group
;
1657 /* Fixup same_comdat_group from reference to pointer. */
1658 if (ref
!= LCC_NOT_FOUND
)
1659 node
->same_comdat_group
= nodes
[ref
];
1661 node
->same_comdat_group
= NULL
;
1663 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1664 node
->aux
= is_a
<cgraph_node
*> (node
) ? (void *)1 : NULL
;
1668 /* Input ipa_refs. */
1671 input_refs (struct lto_input_block
*ib
,
1672 vec
<symtab_node
*> nodes
)
1679 count
= streamer_read_uhwi (ib
);
1682 idx
= streamer_read_uhwi (ib
);
1686 input_ref (ib
, node
, nodes
);
1693 static struct gcov_ctr_summary lto_gcov_summary
;
1695 /* Input profile_info from IB. */
1697 input_profile_summary (struct lto_input_block
*ib
,
1698 struct lto_file_decl_data
*file_data
)
1701 struct bitpack_d bp
;
1702 unsigned int runs
= streamer_read_uhwi (ib
);
1705 file_data
->profile_info
.runs
= runs
;
1706 file_data
->profile_info
.sum_max
= streamer_read_gcov_count (ib
);
1707 file_data
->profile_info
.sum_all
= streamer_read_gcov_count (ib
);
1709 memset (file_data
->profile_info
.histogram
, 0,
1710 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1711 /* Input the bitpack of non-zero histogram indices. */
1712 bp
= streamer_read_bitpack (ib
);
1713 /* Read in and unpack the full bitpack, flagging non-zero
1714 histogram entries by setting the num_counters non-zero. */
1715 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1717 file_data
->profile_info
.histogram
[h_ix
].num_counters
1718 = bp_unpack_value (&bp
, 1);
1720 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1722 if (!file_data
->profile_info
.histogram
[h_ix
].num_counters
)
1725 file_data
->profile_info
.histogram
[h_ix
].num_counters
1726 = streamer_read_gcov_count (ib
);
1727 file_data
->profile_info
.histogram
[h_ix
].min_value
1728 = streamer_read_gcov_count (ib
);
1729 file_data
->profile_info
.histogram
[h_ix
].cum_value
1730 = streamer_read_gcov_count (ib
);
1732 /* IPA-profile computes hot bb threshold based on cumulated
1733 whole program profile. We need to stream it down to ltrans. */
1735 set_hot_bb_threshold (streamer_read_gcov_count (ib
));
1740 /* Rescale profile summaries to the same number of runs in the whole unit. */
1743 merge_profile_summaries (struct lto_file_decl_data
**file_data_vec
)
1745 struct lto_file_decl_data
*file_data
;
1746 unsigned int j
, h_ix
;
1747 gcov_unsigned_t max_runs
= 0;
1748 struct cgraph_node
*node
;
1749 struct cgraph_edge
*edge
;
1750 gcov_type saved_sum_all
= 0;
1751 gcov_ctr_summary
*saved_profile_info
= 0;
1752 int saved_scale
= 0;
1754 /* Find unit with maximal number of runs. If we ever get serious about
1755 roundoff errors, we might also consider computing smallest common
1757 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1758 if (max_runs
< file_data
->profile_info
.runs
)
1759 max_runs
= file_data
->profile_info
.runs
;
1764 /* Simple overflow check. We probably don't need to support that many train
1765 runs. Such a large value probably imply data corruption anyway. */
1766 if (max_runs
> INT_MAX
/ REG_BR_PROB_BASE
)
1768 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1769 INT_MAX
/ REG_BR_PROB_BASE
);
1773 profile_info
= <o_gcov_summary
;
1774 lto_gcov_summary
.runs
= max_runs
;
1775 lto_gcov_summary
.sum_max
= 0;
1776 memset (lto_gcov_summary
.histogram
, 0,
1777 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1779 /* Rescale all units to the maximal number of runs.
1780 sum_max can not be easily merged, as we have no idea what files come from
1781 the same run. We do not use the info anyway, so leave it 0. */
1782 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1783 if (file_data
->profile_info
.runs
)
1785 int scale
= GCOV_COMPUTE_SCALE (max_runs
,
1786 file_data
->profile_info
.runs
);
1787 lto_gcov_summary
.sum_max
1788 = MAX (lto_gcov_summary
.sum_max
,
1789 apply_scale (file_data
->profile_info
.sum_max
, scale
));
1790 lto_gcov_summary
.sum_all
1791 = MAX (lto_gcov_summary
.sum_all
,
1792 apply_scale (file_data
->profile_info
.sum_all
, scale
));
1793 /* Save a pointer to the profile_info with the largest
1794 scaled sum_all and the scale for use in merging the
1796 if (!saved_profile_info
1797 || lto_gcov_summary
.sum_all
> saved_sum_all
)
1799 saved_profile_info
= &file_data
->profile_info
;
1800 saved_sum_all
= lto_gcov_summary
.sum_all
;
1801 saved_scale
= scale
;
1805 gcc_assert (saved_profile_info
);
1807 /* Scale up the histogram from the profile that had the largest
1808 scaled sum_all above. */
1809 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1811 /* Scale up the min value as we did the corresponding sum_all
1812 above. Use that to find the new histogram index. */
1813 gcov_type scaled_min
1814 = apply_scale (saved_profile_info
->histogram
[h_ix
].min_value
,
1816 /* The new index may be shared with another scaled histogram entry,
1817 so we need to account for a non-zero histogram entry at new_ix. */
1818 unsigned new_ix
= gcov_histo_index (scaled_min
);
1819 lto_gcov_summary
.histogram
[new_ix
].min_value
1820 = (lto_gcov_summary
.histogram
[new_ix
].num_counters
1821 ? MIN (lto_gcov_summary
.histogram
[new_ix
].min_value
, scaled_min
)
1823 /* Some of the scaled counter values would ostensibly need to be placed
1824 into different (larger) histogram buckets, but we keep things simple
1825 here and place the scaled cumulative counter value in the bucket
1826 corresponding to the scaled minimum counter value. */
1827 lto_gcov_summary
.histogram
[new_ix
].cum_value
1828 += apply_scale (saved_profile_info
->histogram
[h_ix
].cum_value
,
1830 lto_gcov_summary
.histogram
[new_ix
].num_counters
1831 += saved_profile_info
->histogram
[h_ix
].num_counters
;
1834 /* Watch roundoff errors. */
1835 if (lto_gcov_summary
.sum_max
< max_runs
)
1836 lto_gcov_summary
.sum_max
= max_runs
;
1838 /* If merging already happent at WPA time, we are done. */
1842 /* Now compute count_materialization_scale of each node.
1843 During LTRANS we already have values of count_materialization_scale
1844 computed, so just update them. */
1845 FOR_EACH_FUNCTION (node
)
1846 if (node
->lto_file_data
1847 && node
->lto_file_data
->profile_info
.runs
)
1851 scale
= RDIV (node
->count_materialization_scale
* max_runs
,
1852 node
->lto_file_data
->profile_info
.runs
);
1853 node
->count_materialization_scale
= scale
;
1855 fatal_error (input_location
, "Profile information in %s corrupted",
1856 file_data
->file_name
);
1858 if (scale
== REG_BR_PROB_BASE
)
1860 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1861 edge
->count
= apply_scale (edge
->count
, scale
);
1862 node
->count
= apply_scale (node
->count
, scale
);
1866 /* Input and merge the symtab from each of the .o files passed to
1872 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1873 struct lto_file_decl_data
*file_data
;
1875 struct cgraph_node
*node
;
1877 while ((file_data
= file_data_vec
[j
++]))
1881 struct lto_input_block
*ib
;
1882 vec
<symtab_node
*> nodes
;
1884 ib
= lto_create_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1887 fatal_error (input_location
,
1888 "cannot find LTO cgraph in %s", file_data
->file_name
);
1889 input_profile_summary (ib
, file_data
);
1890 file_data
->symtab_node_encoder
= lto_symtab_encoder_new (true);
1891 nodes
= input_cgraph_1 (file_data
, ib
);
1892 lto_destroy_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1895 ib
= lto_create_simple_input_block (file_data
, LTO_section_refs
,
1898 fatal_error (input_location
, "cannot find LTO section refs in %s",
1899 file_data
->file_name
);
1900 input_refs (ib
, nodes
);
1901 lto_destroy_simple_input_block (file_data
, LTO_section_refs
,
1904 input_cgraph_opt_summary (nodes
);
1908 merge_profile_summaries (file_data_vec
);
1909 get_working_sets ();
1912 /* Clear out the aux field that was used to store enough state to
1913 tell which nodes should be overwritten. */
1914 FOR_EACH_FUNCTION (node
)
1916 /* Some nodes may have been created by cgraph_node. This
1917 happens when the callgraph contains nested functions. If the
1918 node for the parent function was never emitted to the gimple
1919 file, cgraph_node will create a node for it when setting the
1920 context of the nested function. */
1921 if (node
->lto_file_data
)
1926 /* Input function/variable tables that will allow libgomp to look up offload
1927 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1930 input_offload_tables (void)
1932 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1933 struct lto_file_decl_data
*file_data
;
1936 while ((file_data
= file_data_vec
[j
++]))
1940 struct lto_input_block
*ib
1941 = lto_create_simple_input_block (file_data
, LTO_section_offload_table
,
1946 enum LTO_symtab_tags tag
1947 = streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1950 if (tag
== LTO_symtab_unavail_node
)
1952 int decl_index
= streamer_read_uhwi (ib
);
1954 = lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1955 vec_safe_push (offload_funcs
, fn_decl
);
1957 else if (tag
== LTO_symtab_variable
)
1959 int decl_index
= streamer_read_uhwi (ib
);
1961 = lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1962 vec_safe_push (offload_vars
, var_decl
);
1965 fatal_error (input_location
,
1966 "invalid offload table in %s", file_data
->file_name
);
1968 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1971 lto_destroy_simple_input_block (file_data
, LTO_section_offload_table
,
1976 /* True when we need optimization summary for NODE. */
1979 output_cgraph_opt_summary_p (struct cgraph_node
*node
)
1981 return (node
->clone_of
1982 && (node
->clone
.tree_map
1983 || node
->clone
.args_to_skip
1984 || node
->clone
.combined_args_to_skip
));
1987 /* Output optimization summary for EDGE to OB. */
1989 output_edge_opt_summary (struct output_block
*ob ATTRIBUTE_UNUSED
,
1990 struct cgraph_edge
*edge ATTRIBUTE_UNUSED
)
1994 /* Output optimization summary for NODE to OB. */
1997 output_node_opt_summary (struct output_block
*ob
,
1998 struct cgraph_node
*node
,
1999 lto_symtab_encoder_t encoder
)
2003 struct ipa_replace_map
*map
;
2004 struct bitpack_d bp
;
2006 struct cgraph_edge
*e
;
2008 if (node
->clone
.args_to_skip
)
2010 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.args_to_skip
));
2011 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.args_to_skip
, 0, index
, bi
)
2012 streamer_write_uhwi (ob
, index
);
2015 streamer_write_uhwi (ob
, 0);
2016 if (node
->clone
.combined_args_to_skip
)
2018 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.combined_args_to_skip
));
2019 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.combined_args_to_skip
, 0, index
, bi
)
2020 streamer_write_uhwi (ob
, index
);
2023 streamer_write_uhwi (ob
, 0);
2024 streamer_write_uhwi (ob
, vec_safe_length (node
->clone
.tree_map
));
2025 FOR_EACH_VEC_SAFE_ELT (node
->clone
.tree_map
, i
, map
)
2027 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
2028 mechanism to store function local declarations into summaries. */
2029 gcc_assert (!map
->old_tree
);
2030 streamer_write_uhwi (ob
, map
->parm_num
);
2031 gcc_assert (EXPR_LOCATION (map
->new_tree
) == UNKNOWN_LOCATION
);
2032 stream_write_tree (ob
, map
->new_tree
, true);
2033 bp
= bitpack_create (ob
->main_stream
);
2034 bp_pack_value (&bp
, map
->replace_p
, 1);
2035 bp_pack_value (&bp
, map
->ref_p
, 1);
2036 streamer_write_bitpack (&bp
);
2039 if (lto_symtab_encoder_in_partition_p (encoder
, node
))
2041 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2042 output_edge_opt_summary (ob
, e
);
2043 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2044 output_edge_opt_summary (ob
, e
);
2048 /* Output optimization summaries stored in callgraph.
2049 At the moment it is the clone info structure. */
2052 output_cgraph_opt_summary (void)
2055 lto_symtab_encoder_t encoder
;
2056 struct output_block
*ob
= create_output_block (LTO_section_cgraph_opt_sum
);
2060 encoder
= ob
->decl_state
->symtab_node_encoder
;
2061 n_nodes
= lto_symtab_encoder_size (encoder
);
2062 for (i
= 0; i
< n_nodes
; i
++)
2064 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2065 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2066 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2069 streamer_write_uhwi (ob
, count
);
2070 for (i
= 0; i
< n_nodes
; i
++)
2072 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2073 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2074 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2076 streamer_write_uhwi (ob
, i
);
2077 output_node_opt_summary (ob
, cnode
, encoder
);
2080 produce_asm (ob
, NULL
);
2081 destroy_output_block (ob
);
2084 /* Input optimisation summary of EDGE. */
2087 input_edge_opt_summary (struct cgraph_edge
*edge ATTRIBUTE_UNUSED
,
2088 struct lto_input_block
*ib_main ATTRIBUTE_UNUSED
)
2092 /* Input optimisation summary of NODE. */
2095 input_node_opt_summary (struct cgraph_node
*node
,
2096 struct lto_input_block
*ib_main
,
2097 struct data_in
*data_in
)
2102 struct bitpack_d bp
;
2103 struct cgraph_edge
*e
;
2105 count
= streamer_read_uhwi (ib_main
);
2107 node
->clone
.args_to_skip
= BITMAP_GGC_ALLOC ();
2108 for (i
= 0; i
< count
; i
++)
2110 bit
= streamer_read_uhwi (ib_main
);
2111 bitmap_set_bit (node
->clone
.args_to_skip
, bit
);
2113 count
= streamer_read_uhwi (ib_main
);
2115 node
->clone
.combined_args_to_skip
= BITMAP_GGC_ALLOC ();
2116 for (i
= 0; i
< count
; i
++)
2118 bit
= streamer_read_uhwi (ib_main
);
2119 bitmap_set_bit (node
->clone
.combined_args_to_skip
, bit
);
2121 count
= streamer_read_uhwi (ib_main
);
2122 for (i
= 0; i
< count
; i
++)
2124 struct ipa_replace_map
*map
= ggc_alloc
<ipa_replace_map
> ();
2126 vec_safe_push (node
->clone
.tree_map
, map
);
2127 map
->parm_num
= streamer_read_uhwi (ib_main
);
2128 map
->old_tree
= NULL
;
2129 map
->new_tree
= stream_read_tree (ib_main
, data_in
);
2130 bp
= streamer_read_bitpack (ib_main
);
2131 map
->replace_p
= bp_unpack_value (&bp
, 1);
2132 map
->ref_p
= bp_unpack_value (&bp
, 1);
2134 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2135 input_edge_opt_summary (e
, ib_main
);
2136 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2137 input_edge_opt_summary (e
, ib_main
);
2140 /* Read section in file FILE_DATA of length LEN with data DATA. */
2143 input_cgraph_opt_section (struct lto_file_decl_data
*file_data
,
2144 const char *data
, size_t len
,
2145 vec
<symtab_node
*> nodes
)
2147 const struct lto_function_header
*header
=
2148 (const struct lto_function_header
*) data
;
2149 const int cfg_offset
= sizeof (struct lto_function_header
);
2150 const int main_offset
= cfg_offset
+ header
->cfg_size
;
2151 const int string_offset
= main_offset
+ header
->main_size
;
2152 struct data_in
*data_in
;
2156 lto_input_block
ib_main ((const char *) data
+ main_offset
,
2157 header
->main_size
, file_data
->mode_table
);
2160 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
2161 header
->string_size
, vNULL
);
2162 count
= streamer_read_uhwi (&ib_main
);
2164 for (i
= 0; i
< count
; i
++)
2166 int ref
= streamer_read_uhwi (&ib_main
);
2167 input_node_opt_summary (dyn_cast
<cgraph_node
*> (nodes
[ref
]),
2170 lto_free_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
, data
,
2172 lto_data_in_delete (data_in
);
2175 /* Input optimization summary of cgraph. */
2178 input_cgraph_opt_summary (vec
<symtab_node
*> nodes
)
2180 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
2181 struct lto_file_decl_data
*file_data
;
2184 while ((file_data
= file_data_vec
[j
++]))
2188 lto_get_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
,
2192 input_cgraph_opt_section (file_data
, data
, len
, nodes
);