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"
31 #include "fold-const.h"
32 #include "stringpool.h"
33 #include "internal-fn.h"
35 #include "insn-config.h"
45 #include "langhooks.h"
46 #include "diagnostic-core.h"
50 #include "lto-streamer.h"
51 #include "data-streamer.h"
52 #include "tree-streamer.h"
54 #include "tree-pass.h"
57 #include "pass_manager.h"
58 #include "ipa-utils.h"
62 /* True when asm nodes has been output. */
63 bool asm_nodes_output
= false;
65 static void output_cgraph_opt_summary (void);
66 static void input_cgraph_opt_summary (vec
<symtab_node
*> nodes
);
68 /* Number of LDPR values known to GCC. */
69 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
71 /* All node orders are ofsetted by ORDER_BASE. */
72 static int order_base
;
74 /* Cgraph streaming is organized as set of record whose type
75 is indicated by a tag. */
78 /* Must leave 0 for the stopper. */
80 /* Cgraph node without body available. */
81 LTO_symtab_unavail_node
= 1,
82 /* Cgraph node with function body. */
83 LTO_symtab_analyzed_node
,
86 LTO_symtab_indirect_edge
,
91 /* Create a new symtab encoder.
92 if FOR_INPUT, the encoder allocate only datastructures needed
93 to read the symtab. */
96 lto_symtab_encoder_new (bool for_input
)
98 lto_symtab_encoder_t encoder
= XCNEW (struct lto_symtab_encoder_d
);
101 encoder
->map
= new hash_map
<symtab_node
*, size_t>;
102 encoder
->nodes
.create (0);
107 /* Delete ENCODER and its components. */
110 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder
)
112 encoder
->nodes
.release ();
119 /* Return the existing reference number of NODE in the symtab encoder in
120 output block OB. Assign a new reference if this is the first time
124 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder
,
131 lto_encoder_entry entry
= {node
, false, false, false};
133 ref
= encoder
->nodes
.length ();
134 encoder
->nodes
.safe_push (entry
);
138 size_t *slot
= encoder
->map
->get (node
);
141 lto_encoder_entry entry
= {node
, false, false, false};
142 ref
= encoder
->nodes
.length ();
144 encoder
->map
->put (node
, ref
+ 1);
145 encoder
->nodes
.safe_push (entry
);
153 /* Remove NODE from encoder. */
156 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder
,
160 lto_encoder_entry last_node
;
162 size_t *slot
= encoder
->map
->get (node
);
163 if (slot
== NULL
|| !*slot
)
167 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
169 /* Remove from vector. We do this by swapping node with the last element
171 last_node
= encoder
->nodes
.pop ();
172 if (last_node
.node
!= node
)
174 gcc_assert (encoder
->map
->put (last_node
.node
, index
+ 1));
176 /* Move the last element to the original spot of NODE. */
177 encoder
->nodes
[index
] = last_node
;
180 /* Remove element from hash table. */
181 encoder
->map
->remove (node
);
186 /* Return TRUE if we should encode the body of NODE (if any). */
189 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder
,
190 struct cgraph_node
*node
)
192 int index
= lto_symtab_encoder_lookup (encoder
, node
);
193 return encoder
->nodes
[index
].body
;
196 /* Specify that we encode the body of NODE in this partition. */
199 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder
,
200 struct cgraph_node
*node
)
202 int index
= lto_symtab_encoder_encode (encoder
, node
);
203 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
204 encoder
->nodes
[index
].body
= true;
207 /* Return TRUE if we should encode initializer of NODE (if any). */
210 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder
,
213 int index
= lto_symtab_encoder_lookup (encoder
, node
);
214 if (index
== LCC_NOT_FOUND
)
216 return encoder
->nodes
[index
].initializer
;
219 /* Specify that we should encode initializer of NODE (if any). */
222 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder
,
225 int index
= lto_symtab_encoder_lookup (encoder
, node
);
226 encoder
->nodes
[index
].initializer
= true;
229 /* Return TRUE if NODE is in this partition. */
232 lto_symtab_encoder_in_partition_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
].in_partition
;
241 /* Specify that NODE is in this partition. */
244 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder
,
247 int index
= lto_symtab_encoder_encode (encoder
, node
);
248 encoder
->nodes
[index
].in_partition
= true;
251 /* Output the cgraph EDGE to OB using ENCODER. */
254 lto_output_edge (struct lto_simple_output_block
*ob
, struct cgraph_edge
*edge
,
255 lto_symtab_encoder_t encoder
)
261 if (edge
->indirect_unknown_callee
)
262 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
263 LTO_symtab_indirect_edge
);
265 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
268 ref
= lto_symtab_encoder_lookup (encoder
, edge
->caller
);
269 gcc_assert (ref
!= LCC_NOT_FOUND
);
270 streamer_write_hwi_stream (ob
->main_stream
, ref
);
272 if (!edge
->indirect_unknown_callee
)
274 ref
= lto_symtab_encoder_lookup (encoder
, edge
->callee
);
275 gcc_assert (ref
!= LCC_NOT_FOUND
);
276 streamer_write_hwi_stream (ob
->main_stream
, ref
);
279 streamer_write_gcov_count_stream (ob
->main_stream
, edge
->count
);
281 bp
= bitpack_create (ob
->main_stream
);
282 uid
= (!gimple_has_body_p (edge
->caller
->decl
)
283 ? edge
->lto_stmt_uid
: gimple_uid (edge
->call_stmt
) + 1);
284 bp_pack_enum (&bp
, cgraph_inline_failed_t
,
285 CIF_N_REASONS
, edge
->inline_failed
);
286 bp_pack_var_len_unsigned (&bp
, uid
);
287 bp_pack_var_len_unsigned (&bp
, edge
->frequency
);
288 bp_pack_value (&bp
, edge
->indirect_inlining_edge
, 1);
289 bp_pack_value (&bp
, edge
->speculative
, 1);
290 bp_pack_value (&bp
, edge
->call_stmt_cannot_inline_p
, 1);
291 bp_pack_value (&bp
, edge
->can_throw_external
, 1);
292 bp_pack_value (&bp
, edge
->in_polymorphic_cdtor
, 1);
293 if (edge
->indirect_unknown_callee
)
295 int flags
= edge
->indirect_info
->ecf_flags
;
296 bp_pack_value (&bp
, (flags
& ECF_CONST
) != 0, 1);
297 bp_pack_value (&bp
, (flags
& ECF_PURE
) != 0, 1);
298 bp_pack_value (&bp
, (flags
& ECF_NORETURN
) != 0, 1);
299 bp_pack_value (&bp
, (flags
& ECF_MALLOC
) != 0, 1);
300 bp_pack_value (&bp
, (flags
& ECF_NOTHROW
) != 0, 1);
301 bp_pack_value (&bp
, (flags
& ECF_RETURNS_TWICE
) != 0, 1);
302 /* Flags that should not appear on indirect calls. */
303 gcc_assert (!(flags
& (ECF_LOOPING_CONST_OR_PURE
309 streamer_write_bitpack (&bp
);
310 if (edge
->indirect_unknown_callee
)
312 streamer_write_hwi_stream (ob
->main_stream
,
313 edge
->indirect_info
->common_target_id
);
314 if (edge
->indirect_info
->common_target_id
)
315 streamer_write_hwi_stream
316 (ob
->main_stream
, edge
->indirect_info
->common_target_probability
);
320 /* Return if NODE contain references from other partitions. */
323 referenced_from_other_partition_p (symtab_node
*node
, lto_symtab_encoder_t encoder
)
326 struct ipa_ref
*ref
= NULL
;
328 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
330 /* Ignore references from non-offloadable nodes while streaming NODE into
331 offload LTO section. */
332 if (!ref
->referring
->need_lto_streaming
)
335 if (ref
->referring
->in_other_partition
336 || !lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
342 /* Return true when node is reachable from other partition. */
345 reachable_from_other_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
347 struct cgraph_edge
*e
;
348 if (!node
->definition
)
350 if (node
->global
.inlined_to
)
352 for (e
= node
->callers
; e
; e
= e
->next_caller
)
354 /* Ignore references from non-offloadable nodes while streaming NODE into
355 offload LTO section. */
356 if (!e
->caller
->need_lto_streaming
)
359 if (e
->caller
->in_other_partition
360 || !lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
366 /* Return if NODE contain references from other partitions. */
369 referenced_from_this_partition_p (symtab_node
*node
,
370 lto_symtab_encoder_t encoder
)
373 struct ipa_ref
*ref
= NULL
;
375 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
376 if (lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
381 /* Return true when node is reachable from other partition. */
384 reachable_from_this_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
386 struct cgraph_edge
*e
;
387 for (e
= node
->callers
; e
; e
= e
->next_caller
)
388 if (lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
393 /* Output the cgraph NODE to OB. ENCODER is used to find the
394 reference number of NODE->inlined_to. SET is the set of nodes we
395 are writing to the current file. If NODE is not in SET, then NODE
396 is a boundary of a cgraph_node_set and we pretend NODE just has a
397 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
398 that have had their callgraph node written so far. This is used to
399 determine if NODE is a clone of a previously written node. */
402 lto_output_node (struct lto_simple_output_block
*ob
, struct cgraph_node
*node
,
403 lto_symtab_encoder_t encoder
)
409 bool in_other_partition
= false;
410 struct cgraph_node
*clone_of
, *ultimate_clone_of
;
411 ipa_opt_pass_d
*pass
;
417 boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
419 if (node
->analyzed
&& (!boundary_p
|| node
->alias
|| node
->thunk
.thunk_p
))
420 tag
= LTO_symtab_analyzed_node
;
422 tag
= LTO_symtab_unavail_node
;
424 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
426 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
428 /* In WPA mode, we only output part of the call-graph. Also, we
429 fake cgraph node attributes. There are two cases that we care.
431 Boundary nodes: There are nodes that are not part of SET but are
432 called from within SET. We artificially make them look like
433 externally visible nodes with no function body.
435 Cherry-picked nodes: These are nodes we pulled from other
436 translation units into SET during IPA-inlining. We make them as
437 local static nodes to prevent clashes with other local statics. */
438 if (boundary_p
&& node
->analyzed
439 && node
->get_partitioning_class () == SYMBOL_PARTITION
)
441 /* Inline clones can not be part of boundary.
442 gcc_assert (!node->global.inlined_to);
444 FIXME: At the moment they can be, when partition contains an inline
445 clone that is clone of inline clone from outside partition. We can
446 reshape the clone tree and make other tree to be the root, but it
447 needs a bit extra work and will be promplty done by cgraph_remove_node
448 after reading back. */
449 in_other_partition
= 1;
452 clone_of
= node
->clone_of
;
454 && (ref
= lto_symtab_encoder_lookup (encoder
, clone_of
)) == LCC_NOT_FOUND
)
455 if (clone_of
->prev_sibling_clone
)
456 clone_of
= clone_of
->prev_sibling_clone
;
458 clone_of
= clone_of
->clone_of
;
460 /* See if body of the master function is output. If not, we are seeing only
461 an declaration and we do not need to pass down clone tree. */
462 ultimate_clone_of
= clone_of
;
463 while (ultimate_clone_of
&& ultimate_clone_of
->clone_of
)
464 ultimate_clone_of
= ultimate_clone_of
->clone_of
;
466 if (clone_of
&& !lto_symtab_encoder_encode_body_p (encoder
, ultimate_clone_of
))
469 if (tag
== LTO_symtab_analyzed_node
)
470 gcc_assert (clone_of
|| !node
->clone_of
);
472 streamer_write_hwi_stream (ob
->main_stream
, LCC_NOT_FOUND
);
474 streamer_write_hwi_stream (ob
->main_stream
, ref
);
477 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
478 streamer_write_gcov_count_stream (ob
->main_stream
, node
->count
);
479 streamer_write_hwi_stream (ob
->main_stream
, node
->count_materialization_scale
);
481 streamer_write_hwi_stream (ob
->main_stream
,
482 node
->ipa_transforms_to_apply
.length ());
483 FOR_EACH_VEC_ELT (node
->ipa_transforms_to_apply
, i
, pass
)
484 streamer_write_hwi_stream (ob
->main_stream
, pass
->static_pass_number
);
486 if (tag
== LTO_symtab_analyzed_node
)
488 if (node
->global
.inlined_to
)
490 ref
= lto_symtab_encoder_lookup (encoder
, node
->global
.inlined_to
);
491 gcc_assert (ref
!= LCC_NOT_FOUND
);
496 streamer_write_hwi_stream (ob
->main_stream
, ref
);
499 group
= node
->get_comdat_group ();
501 comdat
= IDENTIFIER_POINTER (group
);
504 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
508 if (node
->same_comdat_group
&& !boundary_p
)
510 ref
= lto_symtab_encoder_lookup (encoder
,
511 node
->same_comdat_group
);
512 gcc_assert (ref
!= LCC_NOT_FOUND
);
516 streamer_write_hwi_stream (ob
->main_stream
, ref
);
519 section
= node
->get_section ();
523 streamer_write_hwi_stream (ob
->main_stream
, node
->tp_first_run
);
525 bp
= bitpack_create (ob
->main_stream
);
526 bp_pack_value (&bp
, node
->local
.local
, 1);
527 bp_pack_value (&bp
, node
->externally_visible
, 1);
528 bp_pack_value (&bp
, node
->no_reorder
, 1);
529 bp_pack_value (&bp
, node
->definition
, 1);
530 bp_pack_value (&bp
, node
->local
.versionable
, 1);
531 bp_pack_value (&bp
, node
->local
.can_change_signature
, 1);
532 bp_pack_value (&bp
, node
->local
.redefined_extern_inline
, 1);
533 bp_pack_value (&bp
, node
->force_output
, 1);
534 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
535 bp_pack_value (&bp
, node
->unique_name
, 1);
536 bp_pack_value (&bp
, node
->body_removed
, 1);
537 bp_pack_value (&bp
, node
->implicit_section
, 1);
538 bp_pack_value (&bp
, node
->address_taken
, 1);
539 bp_pack_value (&bp
, tag
== LTO_symtab_analyzed_node
540 && node
->get_partitioning_class () == SYMBOL_PARTITION
541 && (reachable_from_other_partition_p (node
, encoder
)
542 || referenced_from_other_partition_p (node
, encoder
)), 1);
543 bp_pack_value (&bp
, node
->lowered
, 1);
544 bp_pack_value (&bp
, in_other_partition
, 1);
545 bp_pack_value (&bp
, node
->alias
, 1);
546 bp_pack_value (&bp
, node
->weakref
, 1);
547 bp_pack_value (&bp
, node
->frequency
, 2);
548 bp_pack_value (&bp
, node
->only_called_at_startup
, 1);
549 bp_pack_value (&bp
, node
->only_called_at_exit
, 1);
550 bp_pack_value (&bp
, node
->tm_clone
, 1);
551 bp_pack_value (&bp
, node
->calls_comdat_local
, 1);
552 bp_pack_value (&bp
, node
->icf_merged
, 1);
553 bp_pack_value (&bp
, node
->nonfreeing_fn
, 1);
554 bp_pack_value (&bp
, node
->thunk
.thunk_p
, 1);
555 bp_pack_value (&bp
, node
->parallelized_function
, 1);
556 bp_pack_enum (&bp
, ld_plugin_symbol_resolution
,
557 LDPR_NUM_KNOWN
, node
->resolution
);
558 bp_pack_value (&bp
, node
->instrumentation_clone
, 1);
559 bp_pack_value (&bp
, node
->split_part
, 1);
560 streamer_write_bitpack (&bp
);
561 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
563 if (node
->thunk
.thunk_p
)
565 streamer_write_uhwi_stream
567 1 + (node
->thunk
.this_adjusting
!= 0) * 2
568 + (node
->thunk
.virtual_offset_p
!= 0) * 4
569 + (node
->thunk
.add_pointer_bounds_args
!= 0) * 8);
570 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.fixed_offset
);
571 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.virtual_value
);
573 streamer_write_hwi_stream (ob
->main_stream
, node
->profile_id
);
574 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
575 streamer_write_hwi_stream (ob
->main_stream
, node
->get_init_priority ());
576 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
577 streamer_write_hwi_stream (ob
->main_stream
, node
->get_fini_priority ());
579 if (node
->instrumentation_clone
)
580 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->orig_decl
);
583 /* Output the varpool NODE to OB.
584 If NODE is not in SET, then NODE is a boundary. */
587 lto_output_varpool_node (struct lto_simple_output_block
*ob
, varpool_node
*node
,
588 lto_symtab_encoder_t encoder
)
590 bool boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
591 bool encode_initializer_p
593 && lto_symtab_encoder_encode_initializer_p (encoder
, node
));
600 gcc_assert (!encode_initializer_p
|| node
->definition
);
601 gcc_assert (boundary_p
|| encode_initializer_p
);
603 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
604 LTO_symtab_variable
);
605 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
606 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
607 bp
= bitpack_create (ob
->main_stream
);
608 bp_pack_value (&bp
, node
->externally_visible
, 1);
609 bp_pack_value (&bp
, node
->no_reorder
, 1);
610 bp_pack_value (&bp
, node
->force_output
, 1);
611 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
612 bp_pack_value (&bp
, node
->unique_name
, 1);
615 || (!encode_initializer_p
&& !node
->alias
&& node
->definition
),
617 bp_pack_value (&bp
, node
->implicit_section
, 1);
618 bp_pack_value (&bp
, node
->writeonly
, 1);
619 bp_pack_value (&bp
, node
->definition
&& (encode_initializer_p
|| node
->alias
),
621 bp_pack_value (&bp
, node
->alias
, 1);
622 bp_pack_value (&bp
, node
->weakref
, 1);
623 bp_pack_value (&bp
, node
->analyzed
&& !boundary_p
, 1);
624 gcc_assert (node
->definition
|| !node
->analyzed
);
625 /* Constant pool initializers can be de-unified into individual ltrans units.
626 FIXME: Alternatively at -Os we may want to avoid generating for them the local
627 labels and share them across LTRANS partitions. */
628 if (node
->get_partitioning_class () != SYMBOL_PARTITION
)
630 bp_pack_value (&bp
, 0, 1); /* used_from_other_parition. */
631 bp_pack_value (&bp
, 0, 1); /* in_other_partition. */
635 bp_pack_value (&bp
, node
->definition
636 && referenced_from_other_partition_p (node
, encoder
), 1);
637 bp_pack_value (&bp
, node
->analyzed
638 && boundary_p
&& !DECL_EXTERNAL (node
->decl
), 1);
639 /* in_other_partition. */
641 bp_pack_value (&bp
, node
->tls_model
, 3);
642 bp_pack_value (&bp
, node
->used_by_single_function
, 1);
643 bp_pack_value (&bp
, node
->need_bounds_init
, 1);
644 streamer_write_bitpack (&bp
);
646 group
= node
->get_comdat_group ();
648 comdat
= IDENTIFIER_POINTER (group
);
651 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
655 if (node
->same_comdat_group
&& !boundary_p
)
657 ref
= lto_symtab_encoder_lookup (encoder
,
658 node
->same_comdat_group
);
659 gcc_assert (ref
!= LCC_NOT_FOUND
);
663 streamer_write_hwi_stream (ob
->main_stream
, ref
);
666 section
= node
->get_section ();
669 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
671 streamer_write_enum (ob
->main_stream
, ld_plugin_symbol_resolution
,
672 LDPR_NUM_KNOWN
, node
->resolution
);
675 /* Output the varpool NODE to OB.
676 If NODE is not in SET, then NODE is a boundary. */
679 lto_output_ref (struct lto_simple_output_block
*ob
, struct ipa_ref
*ref
,
680 lto_symtab_encoder_t encoder
)
684 int uid
= ref
->lto_stmt_uid
;
685 struct cgraph_node
*node
;
687 bp
= bitpack_create (ob
->main_stream
);
688 bp_pack_value (&bp
, ref
->use
, 3);
689 bp_pack_value (&bp
, ref
->speculative
, 1);
690 streamer_write_bitpack (&bp
);
691 nref
= lto_symtab_encoder_lookup (encoder
, ref
->referred
);
692 gcc_assert (nref
!= LCC_NOT_FOUND
);
693 streamer_write_hwi_stream (ob
->main_stream
, nref
);
695 node
= dyn_cast
<cgraph_node
*> (ref
->referring
);
699 uid
= gimple_uid (ref
->stmt
) + 1;
700 streamer_write_hwi_stream (ob
->main_stream
, uid
);
704 /* Stream out profile_summary to OB. */
707 output_profile_summary (struct lto_simple_output_block
*ob
)
714 /* We do not output num and run_max, they are not used by
715 GCC profile feedback and they are difficult to merge from multiple
717 gcc_assert (profile_info
->runs
);
718 streamer_write_uhwi_stream (ob
->main_stream
, profile_info
->runs
);
719 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_max
);
721 /* sum_all is needed for computing the working set with the
723 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_all
);
725 /* Create and output a bitpack of non-zero histogram entries indices. */
726 bp
= bitpack_create (ob
->main_stream
);
727 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
728 bp_pack_value (&bp
, profile_info
->histogram
[h_ix
].num_counters
> 0, 1);
729 streamer_write_bitpack (&bp
);
730 /* Now stream out only those non-zero entries. */
731 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
733 if (!profile_info
->histogram
[h_ix
].num_counters
)
735 streamer_write_gcov_count_stream (ob
->main_stream
,
736 profile_info
->histogram
[h_ix
].num_counters
);
737 streamer_write_gcov_count_stream (ob
->main_stream
,
738 profile_info
->histogram
[h_ix
].min_value
);
739 streamer_write_gcov_count_stream (ob
->main_stream
,
740 profile_info
->histogram
[h_ix
].cum_value
);
742 /* IPA-profile computes hot bb threshold based on cumulated
743 whole program profile. We need to stream it down to ltrans. */
745 streamer_write_gcov_count_stream (ob
->main_stream
,
746 get_hot_bb_threshold ());
749 streamer_write_uhwi_stream (ob
->main_stream
, 0);
752 /* Output all callees or indirect outgoing edges. EDGE must be the first such
756 output_outgoing_cgraph_edges (struct cgraph_edge
*edge
,
757 struct lto_simple_output_block
*ob
,
758 lto_symtab_encoder_t encoder
)
763 /* Output edges in backward direction, so the reconstructed callgraph match
764 and it is easy to associate call sites in the IPA pass summaries. */
765 while (edge
->next_callee
)
766 edge
= edge
->next_callee
;
767 for (; edge
; edge
= edge
->prev_callee
)
768 lto_output_edge (ob
, edge
, encoder
);
771 /* Output the part of the cgraph in SET. */
774 output_refs (lto_symtab_encoder_t encoder
)
776 struct lto_simple_output_block
*ob
;
780 ob
= lto_create_simple_output_block (LTO_section_refs
);
782 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
784 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
786 /* IPA_REF_ALIAS and IPA_REF_CHKP references are always preserved
787 in the boundary. Alias node can't have other references and
788 can be always handled as if it's not in the boundary. */
789 if (!node
->alias
&& !lto_symtab_encoder_in_partition_p (encoder
, node
))
791 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
792 /* Output IPA_REF_CHKP reference. */
794 && cnode
->instrumented_version
795 && !cnode
->instrumentation_clone
)
797 for (int i
= 0; node
->iterate_reference (i
, ref
); i
++)
798 if (ref
->use
== IPA_REF_CHKP
)
800 if (lto_symtab_encoder_lookup (encoder
, ref
->referred
)
803 int nref
= lto_symtab_encoder_lookup (encoder
, node
);
804 streamer_write_gcov_count_stream (ob
->main_stream
, 1);
805 streamer_write_uhwi_stream (ob
->main_stream
, nref
);
806 lto_output_ref (ob
, ref
, encoder
);
814 count
= node
->ref_list
.nreferences ();
817 streamer_write_gcov_count_stream (ob
->main_stream
, count
);
818 streamer_write_uhwi_stream (ob
->main_stream
,
819 lto_symtab_encoder_lookup (encoder
, node
));
820 for (int i
= 0; node
->iterate_reference (i
, ref
); i
++)
821 lto_output_ref (ob
, ref
, encoder
);
825 streamer_write_uhwi_stream (ob
->main_stream
, 0);
827 lto_destroy_simple_output_block (ob
);
830 /* Add NODE into encoder as well as nodes it is cloned from.
831 Do it in a way so clones appear first. */
834 add_node_to (lto_symtab_encoder_t encoder
, struct cgraph_node
*node
,
838 add_node_to (encoder
, node
->clone_of
, include_body
);
839 else if (include_body
)
840 lto_set_symtab_encoder_encode_body (encoder
, node
);
841 lto_symtab_encoder_encode (encoder
, node
);
844 /* Add all references in NODE to encoders. */
847 create_references (lto_symtab_encoder_t encoder
, symtab_node
*node
)
850 struct ipa_ref
*ref
= NULL
;
851 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
852 if (is_a
<cgraph_node
*> (ref
->referred
))
853 add_node_to (encoder
, dyn_cast
<cgraph_node
*> (ref
->referred
), false);
855 lto_symtab_encoder_encode (encoder
, ref
->referred
);
858 /* Select what needs to be streamed out. In regular lto mode stream everything.
859 In offload lto mode stream only nodes marked as offloadable. */
861 select_what_to_stream (void)
863 struct symtab_node
*snode
;
864 FOR_EACH_SYMBOL (snode
)
865 snode
->need_lto_streaming
= !lto_stream_offload_p
|| snode
->offloadable
;
868 /* Find all symbols we want to stream into given partition and insert them
871 The function actually replaces IN_ENCODER by new one. The reason is that
872 streaming code needs clone's origin to be streamed before clone. This
873 means that we need to insert the nodes in specific order. This order is
874 ignored by the partitioning logic earlier. */
877 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder
)
879 struct cgraph_edge
*edge
;
881 lto_symtab_encoder_t encoder
;
882 lto_symtab_encoder_iterator lsei
;
883 hash_set
<void *> reachable_call_targets
;
885 encoder
= lto_symtab_encoder_new (false);
887 /* Go over all entries in the IN_ENCODER and duplicate them to
888 ENCODER. At the same time insert masters of clones so
889 every master appears before clone. */
890 for (lsei
= lsei_start_function_in_partition (in_encoder
);
891 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
893 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
894 if (!node
->need_lto_streaming
)
896 add_node_to (encoder
, node
, true);
897 lto_set_symtab_encoder_in_partition (encoder
, node
);
898 create_references (encoder
, node
);
899 /* For proper debug info, we need to ship the origins, too. */
900 if (DECL_ABSTRACT_ORIGIN (node
->decl
))
902 struct cgraph_node
*origin_node
903 = cgraph_node::get_create (DECL_ABSTRACT_ORIGIN (node
->decl
));
904 origin_node
->used_as_abstract_origin
= true;
905 add_node_to (encoder
, origin_node
, true);
908 for (lsei
= lsei_start_variable_in_partition (in_encoder
);
909 !lsei_end_p (lsei
); lsei_next_variable_in_partition (&lsei
))
911 varpool_node
*vnode
= lsei_varpool_node (lsei
);
913 if (!vnode
->need_lto_streaming
)
915 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
916 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
917 create_references (encoder
, vnode
);
918 /* For proper debug info, we need to ship the origins, too. */
919 if (DECL_ABSTRACT_ORIGIN (vnode
->decl
))
921 varpool_node
*origin_node
922 = varpool_node::get (DECL_ABSTRACT_ORIGIN (vnode
->decl
));
923 lto_set_symtab_encoder_in_partition (encoder
, origin_node
);
926 /* Pickle in also the initializer of all referenced readonly variables
927 to help folding. Constant pool variables are not shared, so we must
929 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
931 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
932 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
934 if (!lto_symtab_encoder_encode_initializer_p (encoder
,
936 && (((vnode
->ctor_useable_for_folding_p ()
937 && (!DECL_VIRTUAL_P (vnode
->decl
)
939 || flag_ltrans_devirtualize
))
940 || POINTER_BOUNDS_P (vnode
->decl
))))
942 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
943 create_references (encoder
, vnode
);
948 /* Go over all the nodes again to include callees that are not in
950 for (lsei
= lsei_start_function_in_partition (encoder
);
951 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
953 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
954 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
956 struct cgraph_node
*callee
= edge
->callee
;
957 if (!lto_symtab_encoder_in_partition_p (encoder
, callee
))
959 /* We should have moved all the inlines. */
960 gcc_assert (!callee
->global
.inlined_to
);
961 add_node_to (encoder
, callee
, false);
964 /* Add all possible targets for late devirtualization. */
965 if (flag_ltrans_devirtualize
|| !flag_wpa
)
966 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
967 if (edge
->indirect_info
->polymorphic
)
972 vec
<cgraph_node
*>targets
973 = possible_polymorphic_call_targets
974 (edge
, &final
, &cache_token
);
975 if (!reachable_call_targets
.add (cache_token
))
977 for (i
= 0; i
< targets
.length (); i
++)
979 struct cgraph_node
*callee
= targets
[i
];
981 /* Adding an external declarations into the unit serves
982 no purpose and just increases its boundary. */
983 if (callee
->definition
984 && !lto_symtab_encoder_in_partition_p
987 gcc_assert (!callee
->global
.inlined_to
);
988 add_node_to (encoder
, callee
, false);
994 /* Be sure to also insert alias targert and thunk callees. These needs
995 to stay to aid local calling conventions. */
996 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
998 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
999 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
1001 if (node
->alias
&& node
->analyzed
)
1002 create_references (encoder
, node
);
1004 && cnode
->thunk
.thunk_p
)
1005 add_node_to (encoder
, cnode
->callees
->callee
, false);
1007 lto_symtab_encoder_delete (in_encoder
);
1011 /* Output the part of the symtab in SET and VSET. */
1014 output_symtab (void)
1016 struct cgraph_node
*node
;
1017 struct lto_simple_output_block
*ob
;
1019 lto_symtab_encoder_t encoder
;
1022 output_cgraph_opt_summary ();
1024 ob
= lto_create_simple_output_block (LTO_section_symtab_nodes
);
1026 output_profile_summary (ob
);
1028 /* An encoder for cgraph nodes should have been created by
1029 ipa_write_summaries_1. */
1030 gcc_assert (ob
->decl_state
->symtab_node_encoder
);
1031 encoder
= ob
->decl_state
->symtab_node_encoder
;
1033 /* Write out the nodes. We must first output a node and then its clones,
1034 otherwise at a time reading back the node there would be nothing to clone
1036 n_nodes
= lto_symtab_encoder_size (encoder
);
1037 for (i
= 0; i
< n_nodes
; i
++)
1039 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1040 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1041 lto_output_node (ob
, cnode
, encoder
);
1043 lto_output_varpool_node (ob
, dyn_cast
<varpool_node
*> (node
), encoder
);
1046 /* Go over the nodes in SET again to write edges. */
1047 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
1049 node
= dyn_cast
<cgraph_node
*> (lto_symtab_encoder_deref (encoder
, i
));
1051 && (node
->thunk
.thunk_p
1052 || lto_symtab_encoder_in_partition_p (encoder
, node
)))
1054 output_outgoing_cgraph_edges (node
->callees
, ob
, encoder
);
1055 output_outgoing_cgraph_edges (node
->indirect_calls
, ob
, encoder
);
1059 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1061 lto_destroy_simple_output_block (ob
);
1063 /* Emit toplevel asms.
1064 When doing WPA we must output every asm just once. Since we do not partition asm
1065 nodes at all, output them to first output. This is kind of hack, but should work
1067 if (!asm_nodes_output
)
1069 asm_nodes_output
= true;
1070 lto_output_toplevel_asms ();
1073 output_refs (encoder
);
1076 /* Return identifier encoded in IB as a plain string. */
1079 read_identifier (struct lto_input_block
*ib
)
1081 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1084 if (ib
->data
[ib
->p
+ len
])
1085 lto_section_overrun (ib
);
1091 id
= get_identifier (ib
->data
+ ib
->p
);
1096 /* Return string encoded in IB, NULL if string is empty. */
1099 read_string (struct lto_input_block
*ib
)
1101 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1104 if (ib
->data
[ib
->p
+ len
])
1105 lto_section_overrun (ib
);
1111 str
= ib
->data
+ ib
->p
;
1116 /* Output function/variable tables that will allow libgomp to look up offload
1118 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1119 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1120 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1123 output_offload_tables (void)
1125 if (vec_safe_is_empty (offload_funcs
) && vec_safe_is_empty (offload_vars
))
1128 struct lto_simple_output_block
*ob
1129 = lto_create_simple_output_block (LTO_section_offload_table
);
1131 for (unsigned i
= 0; i
< vec_safe_length (offload_funcs
); i
++)
1133 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1134 LTO_symtab_last_tag
, LTO_symtab_unavail_node
);
1135 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
,
1136 (*offload_funcs
)[i
]);
1139 for (unsigned i
= 0; i
< vec_safe_length (offload_vars
); i
++)
1141 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1142 LTO_symtab_last_tag
, LTO_symtab_variable
);
1143 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
,
1144 (*offload_vars
)[i
]);
1147 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1148 lto_destroy_simple_output_block (ob
);
1150 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1151 streamed to one partition only. That's why we free offload_funcs and
1152 offload_vars after the first call of output_offload_tables. */
1155 vec_free (offload_funcs
);
1156 vec_free (offload_vars
);
1160 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1161 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1162 NODE or to replace the values in it, for instance because the first
1163 time we saw it, the function body was not available but now it
1164 is. BP is a bitpack with all the bitflags for NODE read from the
1168 input_overwrite_node (struct lto_file_decl_data
*file_data
,
1169 struct cgraph_node
*node
,
1170 enum LTO_symtab_tags tag
,
1171 struct bitpack_d
*bp
)
1173 node
->aux
= (void *) tag
;
1174 node
->lto_file_data
= file_data
;
1176 node
->local
.local
= bp_unpack_value (bp
, 1);
1177 node
->externally_visible
= bp_unpack_value (bp
, 1);
1178 node
->no_reorder
= bp_unpack_value (bp
, 1);
1179 node
->definition
= bp_unpack_value (bp
, 1);
1180 node
->local
.versionable
= bp_unpack_value (bp
, 1);
1181 node
->local
.can_change_signature
= bp_unpack_value (bp
, 1);
1182 node
->local
.redefined_extern_inline
= bp_unpack_value (bp
, 1);
1183 node
->force_output
= bp_unpack_value (bp
, 1);
1184 node
->forced_by_abi
= bp_unpack_value (bp
, 1);
1185 node
->unique_name
= bp_unpack_value (bp
, 1);
1186 node
->body_removed
= bp_unpack_value (bp
, 1);
1187 node
->implicit_section
= bp_unpack_value (bp
, 1);
1188 node
->address_taken
= bp_unpack_value (bp
, 1);
1189 node
->used_from_other_partition
= bp_unpack_value (bp
, 1);
1190 node
->lowered
= bp_unpack_value (bp
, 1);
1191 node
->analyzed
= tag
== LTO_symtab_analyzed_node
;
1192 node
->in_other_partition
= bp_unpack_value (bp
, 1);
1193 if (node
->in_other_partition
1194 /* Avoid updating decl when we are seeing just inline clone.
1195 When inlining function that has functions already inlined into it,
1196 we produce clones of inline clones.
1198 WPA partitioning might put each clone into different unit and
1199 we might end up streaming inline clone from other partition
1200 to support clone we are interested in. */
1202 || node
->clone_of
->decl
!= node
->decl
))
1204 DECL_EXTERNAL (node
->decl
) = 1;
1205 TREE_STATIC (node
->decl
) = 0;
1207 node
->alias
= bp_unpack_value (bp
, 1);
1208 node
->weakref
= bp_unpack_value (bp
, 1);
1209 node
->frequency
= (enum node_frequency
)bp_unpack_value (bp
, 2);
1210 node
->only_called_at_startup
= bp_unpack_value (bp
, 1);
1211 node
->only_called_at_exit
= bp_unpack_value (bp
, 1);
1212 node
->tm_clone
= bp_unpack_value (bp
, 1);
1213 node
->calls_comdat_local
= bp_unpack_value (bp
, 1);
1214 node
->icf_merged
= bp_unpack_value (bp
, 1);
1215 node
->nonfreeing_fn
= bp_unpack_value (bp
, 1);
1216 node
->thunk
.thunk_p
= bp_unpack_value (bp
, 1);
1217 node
->parallelized_function
= bp_unpack_value (bp
, 1);
1218 node
->resolution
= bp_unpack_enum (bp
, ld_plugin_symbol_resolution
,
1220 node
->instrumentation_clone
= bp_unpack_value (bp
, 1);
1221 node
->split_part
= bp_unpack_value (bp
, 1);
1222 gcc_assert (flag_ltrans
1223 || (!node
->in_other_partition
1224 && !node
->used_from_other_partition
));
1227 /* Return string alias is alias of. */
1230 get_alias_symbol (tree decl
)
1232 tree alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
1233 return get_identifier (TREE_STRING_POINTER
1234 (TREE_VALUE (TREE_VALUE (alias
))));
1237 /* Read a node from input_block IB. TAG is the node's tag just read.
1238 Return the node read or overwriten. */
1240 static struct cgraph_node
*
1241 input_node (struct lto_file_decl_data
*file_data
,
1242 struct lto_input_block
*ib
,
1243 enum LTO_symtab_tags tag
,
1244 vec
<symtab_node
*> nodes
)
1246 gcc::pass_manager
*passes
= g
->get_passes ();
1248 struct cgraph_node
*node
;
1249 struct bitpack_d bp
;
1250 unsigned decl_index
;
1251 int ref
= LCC_NOT_FOUND
, ref2
= LCC_NOT_FOUND
;
1256 const char *section
;
1257 order
= streamer_read_hwi (ib
) + order_base
;
1258 clone_ref
= streamer_read_hwi (ib
);
1260 decl_index
= streamer_read_uhwi (ib
);
1261 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1263 if (clone_ref
!= LCC_NOT_FOUND
)
1265 node
= dyn_cast
<cgraph_node
*> (nodes
[clone_ref
])->create_clone (fn_decl
,
1266 0, CGRAPH_FREQ_BASE
, false,
1267 vNULL
, false, NULL
, NULL
);
1271 /* Declaration of functions can be already merged with a declaration
1272 from other input file. We keep cgraph unmerged until after streaming
1273 of ipa passes is done. Alays forcingly create a fresh node. */
1274 node
= symtab
->create_empty ();
1275 node
->decl
= fn_decl
;
1276 node
->register_symbol ();
1279 node
->order
= order
;
1280 if (order
>= symtab
->order
)
1281 symtab
->order
= order
+ 1;
1283 node
->count
= streamer_read_gcov_count (ib
);
1284 node
->count_materialization_scale
= streamer_read_hwi (ib
);
1286 count
= streamer_read_hwi (ib
);
1287 node
->ipa_transforms_to_apply
= vNULL
;
1288 for (i
= 0; i
< count
; i
++)
1291 int pid
= streamer_read_hwi (ib
);
1293 gcc_assert (pid
< passes
->passes_by_id_size
);
1294 pass
= passes
->passes_by_id
[pid
];
1295 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*) pass
);
1298 if (tag
== LTO_symtab_analyzed_node
)
1299 ref
= streamer_read_hwi (ib
);
1301 group
= read_identifier (ib
);
1303 ref2
= streamer_read_hwi (ib
);
1305 /* Make sure that we have not read this node before. Nodes that
1306 have already been read will have their tag stored in the 'aux'
1307 field. Since built-in functions can be referenced in multiple
1308 functions, they are expected to be read more than once. */
1309 if (node
->aux
&& !DECL_BUILT_IN (node
->decl
))
1310 internal_error ("bytecode stream: found multiple instances of cgraph "
1311 "node with uid %d", node
->uid
);
1313 node
->tp_first_run
= streamer_read_uhwi (ib
);
1315 bp
= streamer_read_bitpack (ib
);
1317 input_overwrite_node (file_data
, node
, tag
, &bp
);
1319 /* Store a reference for now, and fix up later to be a pointer. */
1320 node
->global
.inlined_to
= (cgraph_node
*) (intptr_t) ref
;
1324 node
->set_comdat_group (group
);
1325 /* Store a reference for now, and fix up later to be a pointer. */
1326 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref2
;
1329 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1330 section
= read_string (ib
);
1332 node
->set_section_for_node (section
);
1334 if (node
->thunk
.thunk_p
)
1336 int type
= streamer_read_uhwi (ib
);
1337 HOST_WIDE_INT fixed_offset
= streamer_read_uhwi (ib
);
1338 HOST_WIDE_INT virtual_value
= streamer_read_uhwi (ib
);
1340 node
->thunk
.fixed_offset
= fixed_offset
;
1341 node
->thunk
.this_adjusting
= (type
& 2);
1342 node
->thunk
.virtual_value
= virtual_value
;
1343 node
->thunk
.virtual_offset_p
= (type
& 4);
1344 node
->thunk
.add_pointer_bounds_args
= (type
& 8);
1346 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1347 node
->alias_target
= get_alias_symbol (node
->decl
);
1348 node
->profile_id
= streamer_read_hwi (ib
);
1349 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
1350 node
->set_init_priority (streamer_read_hwi (ib
));
1351 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
1352 node
->set_fini_priority (streamer_read_hwi (ib
));
1354 if (node
->instrumentation_clone
)
1356 decl_index
= streamer_read_uhwi (ib
);
1357 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1358 node
->orig_decl
= fn_decl
;
1364 /* Read a node from input_block IB. TAG is the node's tag just read.
1365 Return the node read or overwriten. */
1367 static varpool_node
*
1368 input_varpool_node (struct lto_file_decl_data
*file_data
,
1369 struct lto_input_block
*ib
)
1374 struct bitpack_d bp
;
1375 int ref
= LCC_NOT_FOUND
;
1378 const char *section
;
1380 order
= streamer_read_hwi (ib
) + order_base
;
1381 decl_index
= streamer_read_uhwi (ib
);
1382 var_decl
= lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1384 /* Declaration of functions can be already merged with a declaration
1385 from other input file. We keep cgraph unmerged until after streaming
1386 of ipa passes is done. Alays forcingly create a fresh node. */
1387 node
= varpool_node::create_empty ();
1388 node
->decl
= var_decl
;
1389 node
->register_symbol ();
1391 node
->order
= order
;
1392 if (order
>= symtab
->order
)
1393 symtab
->order
= order
+ 1;
1394 node
->lto_file_data
= file_data
;
1396 bp
= streamer_read_bitpack (ib
);
1397 node
->externally_visible
= bp_unpack_value (&bp
, 1);
1398 node
->no_reorder
= bp_unpack_value (&bp
, 1);
1399 node
->force_output
= bp_unpack_value (&bp
, 1);
1400 node
->forced_by_abi
= bp_unpack_value (&bp
, 1);
1401 node
->unique_name
= bp_unpack_value (&bp
, 1);
1402 node
->body_removed
= bp_unpack_value (&bp
, 1);
1403 node
->implicit_section
= bp_unpack_value (&bp
, 1);
1404 node
->writeonly
= bp_unpack_value (&bp
, 1);
1405 node
->definition
= bp_unpack_value (&bp
, 1);
1406 node
->alias
= bp_unpack_value (&bp
, 1);
1407 node
->weakref
= bp_unpack_value (&bp
, 1);
1408 node
->analyzed
= bp_unpack_value (&bp
, 1);
1409 node
->used_from_other_partition
= bp_unpack_value (&bp
, 1);
1410 node
->in_other_partition
= bp_unpack_value (&bp
, 1);
1411 if (node
->in_other_partition
)
1413 DECL_EXTERNAL (node
->decl
) = 1;
1414 TREE_STATIC (node
->decl
) = 0;
1416 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1417 node
->alias_target
= get_alias_symbol (node
->decl
);
1418 node
->tls_model
= (enum tls_model
)bp_unpack_value (&bp
, 3);
1419 node
->used_by_single_function
= (enum tls_model
)bp_unpack_value (&bp
, 1);
1420 node
->need_bounds_init
= bp_unpack_value (&bp
, 1);
1421 group
= read_identifier (ib
);
1424 node
->set_comdat_group (group
);
1425 ref
= streamer_read_hwi (ib
);
1426 /* Store a reference for now, and fix up later to be a pointer. */
1427 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref
;
1430 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1431 section
= read_string (ib
);
1433 node
->set_section_for_node (section
);
1434 node
->resolution
= streamer_read_enum (ib
, ld_plugin_symbol_resolution
,
1436 gcc_assert (flag_ltrans
1437 || (!node
->in_other_partition
1438 && !node
->used_from_other_partition
));
1443 /* Read a node from input_block IB. TAG is the node's tag just read.
1444 Return the node read or overwriten. */
1447 input_ref (struct lto_input_block
*ib
,
1448 symtab_node
*referring_node
,
1449 vec
<symtab_node
*> nodes
)
1451 symtab_node
*node
= NULL
;
1452 struct bitpack_d bp
;
1453 enum ipa_ref_use use
;
1455 struct ipa_ref
*ref
;
1457 bp
= streamer_read_bitpack (ib
);
1458 use
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 3);
1459 speculative
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 1);
1460 node
= nodes
[streamer_read_hwi (ib
)];
1461 ref
= referring_node
->create_reference (node
, use
);
1462 ref
->speculative
= speculative
;
1463 if (is_a
<cgraph_node
*> (referring_node
))
1464 ref
->lto_stmt_uid
= streamer_read_hwi (ib
);
1467 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1468 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1469 edge being read is indirect (in the sense that it has
1470 indirect_unknown_callee set). */
1473 input_edge (struct lto_input_block
*ib
, vec
<symtab_node
*> nodes
,
1476 struct cgraph_node
*caller
, *callee
;
1477 struct cgraph_edge
*edge
;
1478 unsigned int stmt_id
;
1481 cgraph_inline_failed_t inline_failed
;
1482 struct bitpack_d bp
;
1485 caller
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1486 if (caller
== NULL
|| caller
->decl
== NULL_TREE
)
1487 internal_error ("bytecode stream: no caller found while reading edge");
1491 callee
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1492 if (callee
== NULL
|| callee
->decl
== NULL_TREE
)
1493 internal_error ("bytecode stream: no callee found while reading edge");
1498 count
= streamer_read_gcov_count (ib
);
1500 bp
= streamer_read_bitpack (ib
);
1501 inline_failed
= bp_unpack_enum (&bp
, cgraph_inline_failed_t
, CIF_N_REASONS
);
1502 stmt_id
= bp_unpack_var_len_unsigned (&bp
);
1503 freq
= (int) bp_unpack_var_len_unsigned (&bp
);
1506 edge
= caller
->create_indirect_edge (NULL
, 0, count
, freq
);
1508 edge
= caller
->create_edge (callee
, NULL
, count
, freq
);
1510 edge
->indirect_inlining_edge
= bp_unpack_value (&bp
, 1);
1511 edge
->speculative
= bp_unpack_value (&bp
, 1);
1512 edge
->lto_stmt_uid
= stmt_id
;
1513 edge
->inline_failed
= inline_failed
;
1514 edge
->call_stmt_cannot_inline_p
= bp_unpack_value (&bp
, 1);
1515 edge
->can_throw_external
= bp_unpack_value (&bp
, 1);
1516 edge
->in_polymorphic_cdtor
= bp_unpack_value (&bp
, 1);
1519 if (bp_unpack_value (&bp
, 1))
1520 ecf_flags
|= ECF_CONST
;
1521 if (bp_unpack_value (&bp
, 1))
1522 ecf_flags
|= ECF_PURE
;
1523 if (bp_unpack_value (&bp
, 1))
1524 ecf_flags
|= ECF_NORETURN
;
1525 if (bp_unpack_value (&bp
, 1))
1526 ecf_flags
|= ECF_MALLOC
;
1527 if (bp_unpack_value (&bp
, 1))
1528 ecf_flags
|= ECF_NOTHROW
;
1529 if (bp_unpack_value (&bp
, 1))
1530 ecf_flags
|= ECF_RETURNS_TWICE
;
1531 edge
->indirect_info
->ecf_flags
= ecf_flags
;
1532 edge
->indirect_info
->common_target_id
= streamer_read_hwi (ib
);
1533 if (edge
->indirect_info
->common_target_id
)
1534 edge
->indirect_info
->common_target_probability
= streamer_read_hwi (ib
);
1539 /* Read a cgraph from IB using the info in FILE_DATA. */
1541 static vec
<symtab_node
*>
1542 input_cgraph_1 (struct lto_file_decl_data
*file_data
,
1543 struct lto_input_block
*ib
)
1545 enum LTO_symtab_tags tag
;
1546 vec
<symtab_node
*> nodes
= vNULL
;
1550 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1551 order_base
= symtab
->order
;
1554 if (tag
== LTO_symtab_edge
)
1555 input_edge (ib
, nodes
, false);
1556 else if (tag
== LTO_symtab_indirect_edge
)
1557 input_edge (ib
, nodes
, true);
1558 else if (tag
== LTO_symtab_variable
)
1560 node
= input_varpool_node (file_data
, ib
);
1561 nodes
.safe_push (node
);
1562 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1566 node
= input_node (file_data
, ib
, tag
, nodes
);
1567 if (node
== NULL
|| node
->decl
== NULL_TREE
)
1568 internal_error ("bytecode stream: found empty cgraph node");
1569 nodes
.safe_push (node
);
1570 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1573 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1576 lto_input_toplevel_asms (file_data
, order_base
);
1578 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1579 #ifdef ENABLE_CHECKING
1580 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1581 gcc_assert (node
->aux
|| !is_a
<cgraph_node
*> (node
));
1583 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1586 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1588 ref
= (int) (intptr_t) cnode
->global
.inlined_to
;
1590 /* We share declaration of builtins, so we may read same node twice. */
1595 /* Fixup inlined_to from reference to pointer. */
1596 if (ref
!= LCC_NOT_FOUND
)
1597 dyn_cast
<cgraph_node
*> (node
)->global
.inlined_to
1598 = dyn_cast
<cgraph_node
*> (nodes
[ref
]);
1600 cnode
->global
.inlined_to
= NULL
;
1602 /* Compute instrumented_version. */
1603 if (cnode
->instrumentation_clone
)
1605 gcc_assert (cnode
->orig_decl
);
1607 cnode
->instrumented_version
= cgraph_node::get (cnode
->orig_decl
);
1608 if (cnode
->instrumented_version
)
1610 /* We may have multiple nodes for a single function which
1611 will be merged later. To have a proper merge we need
1612 to keep instrumentation_version reference between nodes
1613 consistent: each instrumented_version reference should
1614 have proper reverse reference. Thus don't break existing
1615 instrumented_version reference if it already exists. */
1616 if (cnode
->instrumented_version
->instrumented_version
)
1617 cnode
->instrumented_version
= NULL
;
1619 cnode
->instrumented_version
->instrumented_version
= cnode
;
1622 /* Restore decl names reference except for wrapper functions. */
1623 if (!chkp_wrap_function (cnode
->orig_decl
))
1625 tree name
= DECL_ASSEMBLER_NAME (cnode
->decl
);
1626 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
1627 TREE_CHAIN (name
) = DECL_ASSEMBLER_NAME (cnode
->orig_decl
);
1632 ref
= (int) (intptr_t) node
->same_comdat_group
;
1634 /* Fixup same_comdat_group from reference to pointer. */
1635 if (ref
!= LCC_NOT_FOUND
)
1636 node
->same_comdat_group
= nodes
[ref
];
1638 node
->same_comdat_group
= NULL
;
1640 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1641 node
->aux
= is_a
<cgraph_node
*> (node
) ? (void *)1 : NULL
;
1645 /* Input ipa_refs. */
1648 input_refs (struct lto_input_block
*ib
,
1649 vec
<symtab_node
*> nodes
)
1656 count
= streamer_read_uhwi (ib
);
1659 idx
= streamer_read_uhwi (ib
);
1663 input_ref (ib
, node
, nodes
);
1670 static struct gcov_ctr_summary lto_gcov_summary
;
1672 /* Input profile_info from IB. */
1674 input_profile_summary (struct lto_input_block
*ib
,
1675 struct lto_file_decl_data
*file_data
)
1678 struct bitpack_d bp
;
1679 unsigned int runs
= streamer_read_uhwi (ib
);
1682 file_data
->profile_info
.runs
= runs
;
1683 file_data
->profile_info
.sum_max
= streamer_read_gcov_count (ib
);
1684 file_data
->profile_info
.sum_all
= streamer_read_gcov_count (ib
);
1686 memset (file_data
->profile_info
.histogram
, 0,
1687 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1688 /* Input the bitpack of non-zero histogram indices. */
1689 bp
= streamer_read_bitpack (ib
);
1690 /* Read in and unpack the full bitpack, flagging non-zero
1691 histogram entries by setting the num_counters non-zero. */
1692 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1694 file_data
->profile_info
.histogram
[h_ix
].num_counters
1695 = bp_unpack_value (&bp
, 1);
1697 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1699 if (!file_data
->profile_info
.histogram
[h_ix
].num_counters
)
1702 file_data
->profile_info
.histogram
[h_ix
].num_counters
1703 = streamer_read_gcov_count (ib
);
1704 file_data
->profile_info
.histogram
[h_ix
].min_value
1705 = streamer_read_gcov_count (ib
);
1706 file_data
->profile_info
.histogram
[h_ix
].cum_value
1707 = streamer_read_gcov_count (ib
);
1709 /* IPA-profile computes hot bb threshold based on cumulated
1710 whole program profile. We need to stream it down to ltrans. */
1712 set_hot_bb_threshold (streamer_read_gcov_count (ib
));
1717 /* Rescale profile summaries to the same number of runs in the whole unit. */
1720 merge_profile_summaries (struct lto_file_decl_data
**file_data_vec
)
1722 struct lto_file_decl_data
*file_data
;
1723 unsigned int j
, h_ix
;
1724 gcov_unsigned_t max_runs
= 0;
1725 struct cgraph_node
*node
;
1726 struct cgraph_edge
*edge
;
1727 gcov_type saved_sum_all
= 0;
1728 gcov_ctr_summary
*saved_profile_info
= 0;
1729 int saved_scale
= 0;
1731 /* Find unit with maximal number of runs. If we ever get serious about
1732 roundoff errors, we might also consider computing smallest common
1734 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1735 if (max_runs
< file_data
->profile_info
.runs
)
1736 max_runs
= file_data
->profile_info
.runs
;
1741 /* Simple overflow check. We probably don't need to support that many train
1742 runs. Such a large value probably imply data corruption anyway. */
1743 if (max_runs
> INT_MAX
/ REG_BR_PROB_BASE
)
1745 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1746 INT_MAX
/ REG_BR_PROB_BASE
);
1750 profile_info
= <o_gcov_summary
;
1751 lto_gcov_summary
.runs
= max_runs
;
1752 lto_gcov_summary
.sum_max
= 0;
1753 memset (lto_gcov_summary
.histogram
, 0,
1754 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1756 /* Rescale all units to the maximal number of runs.
1757 sum_max can not be easily merged, as we have no idea what files come from
1758 the same run. We do not use the info anyway, so leave it 0. */
1759 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1760 if (file_data
->profile_info
.runs
)
1762 int scale
= GCOV_COMPUTE_SCALE (max_runs
,
1763 file_data
->profile_info
.runs
);
1764 lto_gcov_summary
.sum_max
1765 = MAX (lto_gcov_summary
.sum_max
,
1766 apply_scale (file_data
->profile_info
.sum_max
, scale
));
1767 lto_gcov_summary
.sum_all
1768 = MAX (lto_gcov_summary
.sum_all
,
1769 apply_scale (file_data
->profile_info
.sum_all
, scale
));
1770 /* Save a pointer to the profile_info with the largest
1771 scaled sum_all and the scale for use in merging the
1773 if (!saved_profile_info
1774 || lto_gcov_summary
.sum_all
> saved_sum_all
)
1776 saved_profile_info
= &file_data
->profile_info
;
1777 saved_sum_all
= lto_gcov_summary
.sum_all
;
1778 saved_scale
= scale
;
1782 gcc_assert (saved_profile_info
);
1784 /* Scale up the histogram from the profile that had the largest
1785 scaled sum_all above. */
1786 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1788 /* Scale up the min value as we did the corresponding sum_all
1789 above. Use that to find the new histogram index. */
1790 gcov_type scaled_min
1791 = apply_scale (saved_profile_info
->histogram
[h_ix
].min_value
,
1793 /* The new index may be shared with another scaled histogram entry,
1794 so we need to account for a non-zero histogram entry at new_ix. */
1795 unsigned new_ix
= gcov_histo_index (scaled_min
);
1796 lto_gcov_summary
.histogram
[new_ix
].min_value
1797 = (lto_gcov_summary
.histogram
[new_ix
].num_counters
1798 ? MIN (lto_gcov_summary
.histogram
[new_ix
].min_value
, scaled_min
)
1800 /* Some of the scaled counter values would ostensibly need to be placed
1801 into different (larger) histogram buckets, but we keep things simple
1802 here and place the scaled cumulative counter value in the bucket
1803 corresponding to the scaled minimum counter value. */
1804 lto_gcov_summary
.histogram
[new_ix
].cum_value
1805 += apply_scale (saved_profile_info
->histogram
[h_ix
].cum_value
,
1807 lto_gcov_summary
.histogram
[new_ix
].num_counters
1808 += saved_profile_info
->histogram
[h_ix
].num_counters
;
1811 /* Watch roundoff errors. */
1812 if (lto_gcov_summary
.sum_max
< max_runs
)
1813 lto_gcov_summary
.sum_max
= max_runs
;
1815 /* If merging already happent at WPA time, we are done. */
1819 /* Now compute count_materialization_scale of each node.
1820 During LTRANS we already have values of count_materialization_scale
1821 computed, so just update them. */
1822 FOR_EACH_FUNCTION (node
)
1823 if (node
->lto_file_data
1824 && node
->lto_file_data
->profile_info
.runs
)
1828 scale
= RDIV (node
->count_materialization_scale
* max_runs
,
1829 node
->lto_file_data
->profile_info
.runs
);
1830 node
->count_materialization_scale
= scale
;
1832 fatal_error (input_location
, "Profile information in %s corrupted",
1833 file_data
->file_name
);
1835 if (scale
== REG_BR_PROB_BASE
)
1837 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1838 edge
->count
= apply_scale (edge
->count
, scale
);
1839 node
->count
= apply_scale (node
->count
, scale
);
1843 /* Input and merge the symtab from each of the .o files passed to
1849 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1850 struct lto_file_decl_data
*file_data
;
1852 struct cgraph_node
*node
;
1854 while ((file_data
= file_data_vec
[j
++]))
1858 struct lto_input_block
*ib
;
1859 vec
<symtab_node
*> nodes
;
1861 ib
= lto_create_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1864 fatal_error (input_location
,
1865 "cannot find LTO cgraph in %s", file_data
->file_name
);
1866 input_profile_summary (ib
, file_data
);
1867 file_data
->symtab_node_encoder
= lto_symtab_encoder_new (true);
1868 nodes
= input_cgraph_1 (file_data
, ib
);
1869 lto_destroy_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1872 ib
= lto_create_simple_input_block (file_data
, LTO_section_refs
,
1875 fatal_error (input_location
, "cannot find LTO section refs in %s",
1876 file_data
->file_name
);
1877 input_refs (ib
, nodes
);
1878 lto_destroy_simple_input_block (file_data
, LTO_section_refs
,
1881 input_cgraph_opt_summary (nodes
);
1885 merge_profile_summaries (file_data_vec
);
1886 get_working_sets ();
1889 /* Clear out the aux field that was used to store enough state to
1890 tell which nodes should be overwritten. */
1891 FOR_EACH_FUNCTION (node
)
1893 /* Some nodes may have been created by cgraph_node. This
1894 happens when the callgraph contains nested functions. If the
1895 node for the parent function was never emitted to the gimple
1896 file, cgraph_node will create a node for it when setting the
1897 context of the nested function. */
1898 if (node
->lto_file_data
)
1903 /* Input function/variable tables that will allow libgomp to look up offload
1904 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1907 input_offload_tables (void)
1909 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1910 struct lto_file_decl_data
*file_data
;
1913 while ((file_data
= file_data_vec
[j
++]))
1917 struct lto_input_block
*ib
1918 = lto_create_simple_input_block (file_data
, LTO_section_offload_table
,
1923 enum LTO_symtab_tags tag
1924 = streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1927 if (tag
== LTO_symtab_unavail_node
)
1929 int decl_index
= streamer_read_uhwi (ib
);
1931 = lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1932 vec_safe_push (offload_funcs
, fn_decl
);
1934 else if (tag
== LTO_symtab_variable
)
1936 int decl_index
= streamer_read_uhwi (ib
);
1938 = lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1939 vec_safe_push (offload_vars
, var_decl
);
1942 fatal_error (input_location
,
1943 "invalid offload table in %s", file_data
->file_name
);
1945 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1948 lto_destroy_simple_input_block (file_data
, LTO_section_offload_table
,
1953 /* True when we need optimization summary for NODE. */
1956 output_cgraph_opt_summary_p (struct cgraph_node
*node
)
1958 return (node
->clone_of
1959 && (node
->clone
.tree_map
1960 || node
->clone
.args_to_skip
1961 || node
->clone
.combined_args_to_skip
));
1964 /* Output optimization summary for EDGE to OB. */
1966 output_edge_opt_summary (struct output_block
*ob ATTRIBUTE_UNUSED
,
1967 struct cgraph_edge
*edge ATTRIBUTE_UNUSED
)
1971 /* Output optimization summary for NODE to OB. */
1974 output_node_opt_summary (struct output_block
*ob
,
1975 struct cgraph_node
*node
,
1976 lto_symtab_encoder_t encoder
)
1980 struct ipa_replace_map
*map
;
1981 struct bitpack_d bp
;
1983 struct cgraph_edge
*e
;
1985 if (node
->clone
.args_to_skip
)
1987 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.args_to_skip
));
1988 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.args_to_skip
, 0, index
, bi
)
1989 streamer_write_uhwi (ob
, index
);
1992 streamer_write_uhwi (ob
, 0);
1993 if (node
->clone
.combined_args_to_skip
)
1995 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.combined_args_to_skip
));
1996 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.combined_args_to_skip
, 0, index
, bi
)
1997 streamer_write_uhwi (ob
, index
);
2000 streamer_write_uhwi (ob
, 0);
2001 streamer_write_uhwi (ob
, vec_safe_length (node
->clone
.tree_map
));
2002 FOR_EACH_VEC_SAFE_ELT (node
->clone
.tree_map
, i
, map
)
2004 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
2005 mechanism to store function local declarations into summaries. */
2006 gcc_assert (!map
->old_tree
);
2007 streamer_write_uhwi (ob
, map
->parm_num
);
2008 gcc_assert (EXPR_LOCATION (map
->new_tree
) == UNKNOWN_LOCATION
);
2009 stream_write_tree (ob
, map
->new_tree
, true);
2010 bp
= bitpack_create (ob
->main_stream
);
2011 bp_pack_value (&bp
, map
->replace_p
, 1);
2012 bp_pack_value (&bp
, map
->ref_p
, 1);
2013 streamer_write_bitpack (&bp
);
2016 if (lto_symtab_encoder_in_partition_p (encoder
, node
))
2018 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2019 output_edge_opt_summary (ob
, e
);
2020 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2021 output_edge_opt_summary (ob
, e
);
2025 /* Output optimization summaries stored in callgraph.
2026 At the moment it is the clone info structure. */
2029 output_cgraph_opt_summary (void)
2032 lto_symtab_encoder_t encoder
;
2033 struct output_block
*ob
= create_output_block (LTO_section_cgraph_opt_sum
);
2037 encoder
= ob
->decl_state
->symtab_node_encoder
;
2038 n_nodes
= lto_symtab_encoder_size (encoder
);
2039 for (i
= 0; i
< n_nodes
; i
++)
2041 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2042 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2043 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2046 streamer_write_uhwi (ob
, count
);
2047 for (i
= 0; i
< n_nodes
; i
++)
2049 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2050 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2051 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2053 streamer_write_uhwi (ob
, i
);
2054 output_node_opt_summary (ob
, cnode
, encoder
);
2057 produce_asm (ob
, NULL
);
2058 destroy_output_block (ob
);
2061 /* Input optimisation summary of EDGE. */
2064 input_edge_opt_summary (struct cgraph_edge
*edge ATTRIBUTE_UNUSED
,
2065 struct lto_input_block
*ib_main ATTRIBUTE_UNUSED
)
2069 /* Input optimisation summary of NODE. */
2072 input_node_opt_summary (struct cgraph_node
*node
,
2073 struct lto_input_block
*ib_main
,
2074 struct data_in
*data_in
)
2079 struct bitpack_d bp
;
2080 struct cgraph_edge
*e
;
2082 count
= streamer_read_uhwi (ib_main
);
2084 node
->clone
.args_to_skip
= BITMAP_GGC_ALLOC ();
2085 for (i
= 0; i
< count
; i
++)
2087 bit
= streamer_read_uhwi (ib_main
);
2088 bitmap_set_bit (node
->clone
.args_to_skip
, bit
);
2090 count
= streamer_read_uhwi (ib_main
);
2092 node
->clone
.combined_args_to_skip
= BITMAP_GGC_ALLOC ();
2093 for (i
= 0; i
< count
; i
++)
2095 bit
= streamer_read_uhwi (ib_main
);
2096 bitmap_set_bit (node
->clone
.combined_args_to_skip
, bit
);
2098 count
= streamer_read_uhwi (ib_main
);
2099 for (i
= 0; i
< count
; i
++)
2101 struct ipa_replace_map
*map
= ggc_alloc
<ipa_replace_map
> ();
2103 vec_safe_push (node
->clone
.tree_map
, map
);
2104 map
->parm_num
= streamer_read_uhwi (ib_main
);
2105 map
->old_tree
= NULL
;
2106 map
->new_tree
= stream_read_tree (ib_main
, data_in
);
2107 bp
= streamer_read_bitpack (ib_main
);
2108 map
->replace_p
= bp_unpack_value (&bp
, 1);
2109 map
->ref_p
= bp_unpack_value (&bp
, 1);
2111 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2112 input_edge_opt_summary (e
, ib_main
);
2113 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2114 input_edge_opt_summary (e
, ib_main
);
2117 /* Read section in file FILE_DATA of length LEN with data DATA. */
2120 input_cgraph_opt_section (struct lto_file_decl_data
*file_data
,
2121 const char *data
, size_t len
,
2122 vec
<symtab_node
*> nodes
)
2124 const struct lto_function_header
*header
=
2125 (const struct lto_function_header
*) data
;
2126 const int cfg_offset
= sizeof (struct lto_function_header
);
2127 const int main_offset
= cfg_offset
+ header
->cfg_size
;
2128 const int string_offset
= main_offset
+ header
->main_size
;
2129 struct data_in
*data_in
;
2133 lto_input_block
ib_main ((const char *) data
+ main_offset
,
2134 header
->main_size
, file_data
->mode_table
);
2137 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
2138 header
->string_size
, vNULL
);
2139 count
= streamer_read_uhwi (&ib_main
);
2141 for (i
= 0; i
< count
; i
++)
2143 int ref
= streamer_read_uhwi (&ib_main
);
2144 input_node_opt_summary (dyn_cast
<cgraph_node
*> (nodes
[ref
]),
2147 lto_free_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
, data
,
2149 lto_data_in_delete (data_in
);
2152 /* Input optimization summary of cgraph. */
2155 input_cgraph_opt_summary (vec
<symtab_node
*> nodes
)
2157 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
2158 struct lto_file_decl_data
*file_data
;
2161 while ((file_data
= file_data_vec
[j
++]))
2165 lto_get_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
,
2169 input_cgraph_opt_section (file_data
, data
, len
, nodes
);