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"
32 #include "fold-const.h"
33 #include "stringpool.h"
34 #include "internal-fn.h"
36 #include "insn-config.h"
46 #include "langhooks.h"
47 #include "diagnostic-core.h"
51 #include "lto-streamer.h"
52 #include "data-streamer.h"
53 #include "tree-streamer.h"
55 #include "tree-pass.h"
58 #include "pass_manager.h"
59 #include "ipa-utils.h"
63 /* True when asm nodes has been output. */
64 bool asm_nodes_output
= false;
66 static void output_cgraph_opt_summary (void);
67 static void input_cgraph_opt_summary (vec
<symtab_node
*> nodes
);
69 /* Number of LDPR values known to GCC. */
70 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
72 /* All node orders are ofsetted by ORDER_BASE. */
73 static int order_base
;
75 /* Cgraph streaming is organized as set of record whose type
76 is indicated by a tag. */
79 /* Must leave 0 for the stopper. */
81 /* Cgraph node without body available. */
82 LTO_symtab_unavail_node
= 1,
83 /* Cgraph node with function body. */
84 LTO_symtab_analyzed_node
,
87 LTO_symtab_indirect_edge
,
92 /* Create a new symtab encoder.
93 if FOR_INPUT, the encoder allocate only datastructures needed
94 to read the symtab. */
97 lto_symtab_encoder_new (bool for_input
)
99 lto_symtab_encoder_t encoder
= XCNEW (struct lto_symtab_encoder_d
);
102 encoder
->map
= new hash_map
<symtab_node
*, size_t>;
103 encoder
->nodes
.create (0);
108 /* Delete ENCODER and its components. */
111 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder
)
113 encoder
->nodes
.release ();
120 /* Return the existing reference number of NODE in the symtab encoder in
121 output block OB. Assign a new reference if this is the first time
125 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder
,
132 lto_encoder_entry entry
= {node
, false, false, false};
134 ref
= encoder
->nodes
.length ();
135 encoder
->nodes
.safe_push (entry
);
139 size_t *slot
= encoder
->map
->get (node
);
142 lto_encoder_entry entry
= {node
, false, false, false};
143 ref
= encoder
->nodes
.length ();
145 encoder
->map
->put (node
, ref
+ 1);
146 encoder
->nodes
.safe_push (entry
);
154 /* Remove NODE from encoder. */
157 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder
,
161 lto_encoder_entry last_node
;
163 size_t *slot
= encoder
->map
->get (node
);
164 if (slot
== NULL
|| !*slot
)
168 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
170 /* Remove from vector. We do this by swapping node with the last element
172 last_node
= encoder
->nodes
.pop ();
173 if (last_node
.node
!= node
)
175 gcc_assert (encoder
->map
->put (last_node
.node
, index
+ 1));
177 /* Move the last element to the original spot of NODE. */
178 encoder
->nodes
[index
] = last_node
;
181 /* Remove element from hash table. */
182 encoder
->map
->remove (node
);
187 /* Return TRUE if we should encode the body of NODE (if any). */
190 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder
,
191 struct cgraph_node
*node
)
193 int index
= lto_symtab_encoder_lookup (encoder
, node
);
194 return encoder
->nodes
[index
].body
;
197 /* Specify that we encode the body of NODE in this partition. */
200 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder
,
201 struct cgraph_node
*node
)
203 int index
= lto_symtab_encoder_encode (encoder
, node
);
204 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
205 encoder
->nodes
[index
].body
= true;
208 /* Return TRUE if we should encode initializer of NODE (if any). */
211 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder
,
214 int index
= lto_symtab_encoder_lookup (encoder
, node
);
215 if (index
== LCC_NOT_FOUND
)
217 return encoder
->nodes
[index
].initializer
;
220 /* Specify that we should encode initializer of NODE (if any). */
223 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder
,
226 int index
= lto_symtab_encoder_lookup (encoder
, node
);
227 encoder
->nodes
[index
].initializer
= true;
230 /* Return TRUE if NODE is in this partition. */
233 lto_symtab_encoder_in_partition_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
].in_partition
;
242 /* Specify that NODE is in this partition. */
245 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder
,
248 int index
= lto_symtab_encoder_encode (encoder
, node
);
249 encoder
->nodes
[index
].in_partition
= true;
252 /* Output the cgraph EDGE to OB using ENCODER. */
255 lto_output_edge (struct lto_simple_output_block
*ob
, struct cgraph_edge
*edge
,
256 lto_symtab_encoder_t encoder
)
262 if (edge
->indirect_unknown_callee
)
263 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
264 LTO_symtab_indirect_edge
);
266 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
269 ref
= lto_symtab_encoder_lookup (encoder
, edge
->caller
);
270 gcc_assert (ref
!= LCC_NOT_FOUND
);
271 streamer_write_hwi_stream (ob
->main_stream
, ref
);
273 if (!edge
->indirect_unknown_callee
)
275 ref
= lto_symtab_encoder_lookup (encoder
, edge
->callee
);
276 gcc_assert (ref
!= LCC_NOT_FOUND
);
277 streamer_write_hwi_stream (ob
->main_stream
, ref
);
280 streamer_write_gcov_count_stream (ob
->main_stream
, edge
->count
);
282 bp
= bitpack_create (ob
->main_stream
);
283 uid
= (!gimple_has_body_p (edge
->caller
->decl
)
284 ? edge
->lto_stmt_uid
: gimple_uid (edge
->call_stmt
) + 1);
285 bp_pack_enum (&bp
, cgraph_inline_failed_t
,
286 CIF_N_REASONS
, edge
->inline_failed
);
287 bp_pack_var_len_unsigned (&bp
, uid
);
288 bp_pack_var_len_unsigned (&bp
, edge
->frequency
);
289 bp_pack_value (&bp
, edge
->indirect_inlining_edge
, 1);
290 bp_pack_value (&bp
, edge
->speculative
, 1);
291 bp_pack_value (&bp
, edge
->call_stmt_cannot_inline_p
, 1);
292 bp_pack_value (&bp
, edge
->can_throw_external
, 1);
293 bp_pack_value (&bp
, edge
->in_polymorphic_cdtor
, 1);
294 if (edge
->indirect_unknown_callee
)
296 int flags
= edge
->indirect_info
->ecf_flags
;
297 bp_pack_value (&bp
, (flags
& ECF_CONST
) != 0, 1);
298 bp_pack_value (&bp
, (flags
& ECF_PURE
) != 0, 1);
299 bp_pack_value (&bp
, (flags
& ECF_NORETURN
) != 0, 1);
300 bp_pack_value (&bp
, (flags
& ECF_MALLOC
) != 0, 1);
301 bp_pack_value (&bp
, (flags
& ECF_NOTHROW
) != 0, 1);
302 bp_pack_value (&bp
, (flags
& ECF_RETURNS_TWICE
) != 0, 1);
303 /* Flags that should not appear on indirect calls. */
304 gcc_assert (!(flags
& (ECF_LOOPING_CONST_OR_PURE
310 streamer_write_bitpack (&bp
);
311 if (edge
->indirect_unknown_callee
)
313 streamer_write_hwi_stream (ob
->main_stream
,
314 edge
->indirect_info
->common_target_id
);
315 if (edge
->indirect_info
->common_target_id
)
316 streamer_write_hwi_stream
317 (ob
->main_stream
, edge
->indirect_info
->common_target_probability
);
321 /* Return if NODE contain references from other partitions. */
324 referenced_from_other_partition_p (symtab_node
*node
, lto_symtab_encoder_t encoder
)
327 struct ipa_ref
*ref
= NULL
;
329 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
331 /* Ignore references from non-offloadable nodes while streaming NODE into
332 offload LTO section. */
333 if (!ref
->referring
->need_lto_streaming
)
336 if (ref
->referring
->in_other_partition
337 || !lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
343 /* Return true when node is reachable from other partition. */
346 reachable_from_other_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
348 struct cgraph_edge
*e
;
349 if (!node
->definition
)
351 if (node
->global
.inlined_to
)
353 for (e
= node
->callers
; e
; e
= e
->next_caller
)
355 /* Ignore references from non-offloadable nodes while streaming NODE into
356 offload LTO section. */
357 if (!e
->caller
->need_lto_streaming
)
360 if (e
->caller
->in_other_partition
361 || !lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
367 /* Return if NODE contain references from other partitions. */
370 referenced_from_this_partition_p (symtab_node
*node
,
371 lto_symtab_encoder_t encoder
)
374 struct ipa_ref
*ref
= NULL
;
376 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
377 if (lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
382 /* Return true when node is reachable from other partition. */
385 reachable_from_this_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
387 struct cgraph_edge
*e
;
388 for (e
= node
->callers
; e
; e
= e
->next_caller
)
389 if (lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
394 /* Output the cgraph NODE to OB. ENCODER is used to find the
395 reference number of NODE->inlined_to. SET is the set of nodes we
396 are writing to the current file. If NODE is not in SET, then NODE
397 is a boundary of a cgraph_node_set and we pretend NODE just has a
398 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
399 that have had their callgraph node written so far. This is used to
400 determine if NODE is a clone of a previously written node. */
403 lto_output_node (struct lto_simple_output_block
*ob
, struct cgraph_node
*node
,
404 lto_symtab_encoder_t encoder
)
410 bool in_other_partition
= false;
411 struct cgraph_node
*clone_of
, *ultimate_clone_of
;
412 ipa_opt_pass_d
*pass
;
418 boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
420 if (node
->analyzed
&& (!boundary_p
|| node
->alias
|| node
->thunk
.thunk_p
))
421 tag
= LTO_symtab_analyzed_node
;
423 tag
= LTO_symtab_unavail_node
;
425 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
427 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
429 /* In WPA mode, we only output part of the call-graph. Also, we
430 fake cgraph node attributes. There are two cases that we care.
432 Boundary nodes: There are nodes that are not part of SET but are
433 called from within SET. We artificially make them look like
434 externally visible nodes with no function body.
436 Cherry-picked nodes: These are nodes we pulled from other
437 translation units into SET during IPA-inlining. We make them as
438 local static nodes to prevent clashes with other local statics. */
439 if (boundary_p
&& node
->analyzed
440 && node
->get_partitioning_class () == SYMBOL_PARTITION
)
442 /* Inline clones can not be part of boundary.
443 gcc_assert (!node->global.inlined_to);
445 FIXME: At the moment they can be, when partition contains an inline
446 clone that is clone of inline clone from outside partition. We can
447 reshape the clone tree and make other tree to be the root, but it
448 needs a bit extra work and will be promplty done by cgraph_remove_node
449 after reading back. */
450 in_other_partition
= 1;
453 clone_of
= node
->clone_of
;
455 && (ref
= lto_symtab_encoder_lookup (encoder
, clone_of
)) == LCC_NOT_FOUND
)
456 if (clone_of
->prev_sibling_clone
)
457 clone_of
= clone_of
->prev_sibling_clone
;
459 clone_of
= clone_of
->clone_of
;
461 /* See if body of the master function is output. If not, we are seeing only
462 an declaration and we do not need to pass down clone tree. */
463 ultimate_clone_of
= clone_of
;
464 while (ultimate_clone_of
&& ultimate_clone_of
->clone_of
)
465 ultimate_clone_of
= ultimate_clone_of
->clone_of
;
467 if (clone_of
&& !lto_symtab_encoder_encode_body_p (encoder
, ultimate_clone_of
))
470 if (tag
== LTO_symtab_analyzed_node
)
471 gcc_assert (clone_of
|| !node
->clone_of
);
473 streamer_write_hwi_stream (ob
->main_stream
, LCC_NOT_FOUND
);
475 streamer_write_hwi_stream (ob
->main_stream
, ref
);
478 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
479 streamer_write_gcov_count_stream (ob
->main_stream
, node
->count
);
480 streamer_write_hwi_stream (ob
->main_stream
, node
->count_materialization_scale
);
482 streamer_write_hwi_stream (ob
->main_stream
,
483 node
->ipa_transforms_to_apply
.length ());
484 FOR_EACH_VEC_ELT (node
->ipa_transforms_to_apply
, i
, pass
)
485 streamer_write_hwi_stream (ob
->main_stream
, pass
->static_pass_number
);
487 if (tag
== LTO_symtab_analyzed_node
)
489 if (node
->global
.inlined_to
)
491 ref
= lto_symtab_encoder_lookup (encoder
, node
->global
.inlined_to
);
492 gcc_assert (ref
!= LCC_NOT_FOUND
);
497 streamer_write_hwi_stream (ob
->main_stream
, ref
);
500 group
= node
->get_comdat_group ();
502 comdat
= IDENTIFIER_POINTER (group
);
505 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
509 if (node
->same_comdat_group
&& !boundary_p
)
511 ref
= lto_symtab_encoder_lookup (encoder
,
512 node
->same_comdat_group
);
513 gcc_assert (ref
!= LCC_NOT_FOUND
);
517 streamer_write_hwi_stream (ob
->main_stream
, ref
);
520 section
= node
->get_section ();
524 streamer_write_hwi_stream (ob
->main_stream
, node
->tp_first_run
);
526 bp
= bitpack_create (ob
->main_stream
);
527 bp_pack_value (&bp
, node
->local
.local
, 1);
528 bp_pack_value (&bp
, node
->externally_visible
, 1);
529 bp_pack_value (&bp
, node
->no_reorder
, 1);
530 bp_pack_value (&bp
, node
->definition
, 1);
531 bp_pack_value (&bp
, node
->local
.versionable
, 1);
532 bp_pack_value (&bp
, node
->local
.can_change_signature
, 1);
533 bp_pack_value (&bp
, node
->local
.redefined_extern_inline
, 1);
534 bp_pack_value (&bp
, node
->force_output
, 1);
535 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
536 bp_pack_value (&bp
, node
->unique_name
, 1);
537 bp_pack_value (&bp
, node
->body_removed
, 1);
538 bp_pack_value (&bp
, node
->implicit_section
, 1);
539 bp_pack_value (&bp
, node
->address_taken
, 1);
540 bp_pack_value (&bp
, tag
== LTO_symtab_analyzed_node
541 && node
->get_partitioning_class () == SYMBOL_PARTITION
542 && (reachable_from_other_partition_p (node
, encoder
)
543 || referenced_from_other_partition_p (node
, encoder
)), 1);
544 bp_pack_value (&bp
, node
->lowered
, 1);
545 bp_pack_value (&bp
, in_other_partition
, 1);
546 bp_pack_value (&bp
, node
->alias
, 1);
547 bp_pack_value (&bp
, node
->weakref
, 1);
548 bp_pack_value (&bp
, node
->frequency
, 2);
549 bp_pack_value (&bp
, node
->only_called_at_startup
, 1);
550 bp_pack_value (&bp
, node
->only_called_at_exit
, 1);
551 bp_pack_value (&bp
, node
->tm_clone
, 1);
552 bp_pack_value (&bp
, node
->calls_comdat_local
, 1);
553 bp_pack_value (&bp
, node
->icf_merged
, 1);
554 bp_pack_value (&bp
, node
->nonfreeing_fn
, 1);
555 bp_pack_value (&bp
, node
->thunk
.thunk_p
, 1);
556 bp_pack_value (&bp
, node
->parallelized_function
, 1);
557 bp_pack_enum (&bp
, ld_plugin_symbol_resolution
,
558 LDPR_NUM_KNOWN
, node
->resolution
);
559 bp_pack_value (&bp
, node
->instrumentation_clone
, 1);
560 bp_pack_value (&bp
, node
->split_part
, 1);
561 streamer_write_bitpack (&bp
);
562 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
564 if (node
->thunk
.thunk_p
)
566 streamer_write_uhwi_stream
568 1 + (node
->thunk
.this_adjusting
!= 0) * 2
569 + (node
->thunk
.virtual_offset_p
!= 0) * 4
570 + (node
->thunk
.add_pointer_bounds_args
!= 0) * 8);
571 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.fixed_offset
);
572 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.virtual_value
);
574 streamer_write_hwi_stream (ob
->main_stream
, node
->profile_id
);
575 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
576 streamer_write_hwi_stream (ob
->main_stream
, node
->get_init_priority ());
577 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
578 streamer_write_hwi_stream (ob
->main_stream
, node
->get_fini_priority ());
580 if (node
->instrumentation_clone
)
581 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->orig_decl
);
584 /* Output the varpool NODE to OB.
585 If NODE is not in SET, then NODE is a boundary. */
588 lto_output_varpool_node (struct lto_simple_output_block
*ob
, varpool_node
*node
,
589 lto_symtab_encoder_t encoder
)
591 bool boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
592 bool encode_initializer_p
594 && lto_symtab_encoder_encode_initializer_p (encoder
, node
));
601 gcc_assert (!encode_initializer_p
|| node
->definition
);
602 gcc_assert (boundary_p
|| encode_initializer_p
);
604 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
605 LTO_symtab_variable
);
606 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
607 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
608 bp
= bitpack_create (ob
->main_stream
);
609 bp_pack_value (&bp
, node
->externally_visible
, 1);
610 bp_pack_value (&bp
, node
->no_reorder
, 1);
611 bp_pack_value (&bp
, node
->force_output
, 1);
612 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
613 bp_pack_value (&bp
, node
->unique_name
, 1);
616 || (!encode_initializer_p
&& !node
->alias
&& node
->definition
),
618 bp_pack_value (&bp
, node
->implicit_section
, 1);
619 bp_pack_value (&bp
, node
->writeonly
, 1);
620 bp_pack_value (&bp
, node
->definition
&& (encode_initializer_p
|| node
->alias
),
622 bp_pack_value (&bp
, node
->alias
, 1);
623 bp_pack_value (&bp
, node
->weakref
, 1);
624 bp_pack_value (&bp
, node
->analyzed
&& !boundary_p
, 1);
625 gcc_assert (node
->definition
|| !node
->analyzed
);
626 /* Constant pool initializers can be de-unified into individual ltrans units.
627 FIXME: Alternatively at -Os we may want to avoid generating for them the local
628 labels and share them across LTRANS partitions. */
629 if (node
->get_partitioning_class () != SYMBOL_PARTITION
)
631 bp_pack_value (&bp
, 0, 1); /* used_from_other_parition. */
632 bp_pack_value (&bp
, 0, 1); /* in_other_partition. */
636 bp_pack_value (&bp
, node
->definition
637 && referenced_from_other_partition_p (node
, encoder
), 1);
638 bp_pack_value (&bp
, node
->analyzed
639 && boundary_p
&& !DECL_EXTERNAL (node
->decl
), 1);
640 /* in_other_partition. */
642 bp_pack_value (&bp
, node
->tls_model
, 3);
643 bp_pack_value (&bp
, node
->used_by_single_function
, 1);
644 bp_pack_value (&bp
, node
->need_bounds_init
, 1);
645 streamer_write_bitpack (&bp
);
647 group
= node
->get_comdat_group ();
649 comdat
= IDENTIFIER_POINTER (group
);
652 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
656 if (node
->same_comdat_group
&& !boundary_p
)
658 ref
= lto_symtab_encoder_lookup (encoder
,
659 node
->same_comdat_group
);
660 gcc_assert (ref
!= LCC_NOT_FOUND
);
664 streamer_write_hwi_stream (ob
->main_stream
, ref
);
667 section
= node
->get_section ();
670 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
672 streamer_write_enum (ob
->main_stream
, ld_plugin_symbol_resolution
,
673 LDPR_NUM_KNOWN
, node
->resolution
);
676 /* Output the varpool NODE to OB.
677 If NODE is not in SET, then NODE is a boundary. */
680 lto_output_ref (struct lto_simple_output_block
*ob
, struct ipa_ref
*ref
,
681 lto_symtab_encoder_t encoder
)
685 int uid
= ref
->lto_stmt_uid
;
686 struct cgraph_node
*node
;
688 bp
= bitpack_create (ob
->main_stream
);
689 bp_pack_value (&bp
, ref
->use
, 3);
690 bp_pack_value (&bp
, ref
->speculative
, 1);
691 streamer_write_bitpack (&bp
);
692 nref
= lto_symtab_encoder_lookup (encoder
, ref
->referred
);
693 gcc_assert (nref
!= LCC_NOT_FOUND
);
694 streamer_write_hwi_stream (ob
->main_stream
, nref
);
696 node
= dyn_cast
<cgraph_node
*> (ref
->referring
);
700 uid
= gimple_uid (ref
->stmt
) + 1;
701 streamer_write_hwi_stream (ob
->main_stream
, uid
);
705 /* Stream out profile_summary to OB. */
708 output_profile_summary (struct lto_simple_output_block
*ob
)
715 /* We do not output num and run_max, they are not used by
716 GCC profile feedback and they are difficult to merge from multiple
718 gcc_assert (profile_info
->runs
);
719 streamer_write_uhwi_stream (ob
->main_stream
, profile_info
->runs
);
720 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_max
);
722 /* sum_all is needed for computing the working set with the
724 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_all
);
726 /* Create and output a bitpack of non-zero histogram entries indices. */
727 bp
= bitpack_create (ob
->main_stream
);
728 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
729 bp_pack_value (&bp
, profile_info
->histogram
[h_ix
].num_counters
> 0, 1);
730 streamer_write_bitpack (&bp
);
731 /* Now stream out only those non-zero entries. */
732 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
734 if (!profile_info
->histogram
[h_ix
].num_counters
)
736 streamer_write_gcov_count_stream (ob
->main_stream
,
737 profile_info
->histogram
[h_ix
].num_counters
);
738 streamer_write_gcov_count_stream (ob
->main_stream
,
739 profile_info
->histogram
[h_ix
].min_value
);
740 streamer_write_gcov_count_stream (ob
->main_stream
,
741 profile_info
->histogram
[h_ix
].cum_value
);
743 /* IPA-profile computes hot bb threshold based on cumulated
744 whole program profile. We need to stream it down to ltrans. */
746 streamer_write_gcov_count_stream (ob
->main_stream
,
747 get_hot_bb_threshold ());
750 streamer_write_uhwi_stream (ob
->main_stream
, 0);
753 /* Output all callees or indirect outgoing edges. EDGE must be the first such
757 output_outgoing_cgraph_edges (struct cgraph_edge
*edge
,
758 struct lto_simple_output_block
*ob
,
759 lto_symtab_encoder_t encoder
)
764 /* Output edges in backward direction, so the reconstructed callgraph match
765 and it is easy to associate call sites in the IPA pass summaries. */
766 while (edge
->next_callee
)
767 edge
= edge
->next_callee
;
768 for (; edge
; edge
= edge
->prev_callee
)
769 lto_output_edge (ob
, edge
, encoder
);
772 /* Output the part of the cgraph in SET. */
775 output_refs (lto_symtab_encoder_t encoder
)
777 struct lto_simple_output_block
*ob
;
781 ob
= lto_create_simple_output_block (LTO_section_refs
);
783 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
785 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
787 /* IPA_REF_ALIAS and IPA_REF_CHKP references are always preserved
788 in the boundary. Alias node can't have other references and
789 can be always handled as if it's not in the boundary. */
790 if (!node
->alias
&& !lto_symtab_encoder_in_partition_p (encoder
, node
))
792 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
793 /* Output IPA_REF_CHKP reference. */
795 && cnode
->instrumented_version
796 && !cnode
->instrumentation_clone
)
798 for (int i
= 0; node
->iterate_reference (i
, ref
); i
++)
799 if (ref
->use
== IPA_REF_CHKP
)
801 if (lto_symtab_encoder_lookup (encoder
, ref
->referred
)
804 int nref
= lto_symtab_encoder_lookup (encoder
, node
);
805 streamer_write_gcov_count_stream (ob
->main_stream
, 1);
806 streamer_write_uhwi_stream (ob
->main_stream
, nref
);
807 lto_output_ref (ob
, ref
, encoder
);
815 count
= node
->ref_list
.nreferences ();
818 streamer_write_gcov_count_stream (ob
->main_stream
, count
);
819 streamer_write_uhwi_stream (ob
->main_stream
,
820 lto_symtab_encoder_lookup (encoder
, node
));
821 for (int i
= 0; node
->iterate_reference (i
, ref
); i
++)
822 lto_output_ref (ob
, ref
, encoder
);
826 streamer_write_uhwi_stream (ob
->main_stream
, 0);
828 lto_destroy_simple_output_block (ob
);
831 /* Add NODE into encoder as well as nodes it is cloned from.
832 Do it in a way so clones appear first. */
835 add_node_to (lto_symtab_encoder_t encoder
, struct cgraph_node
*node
,
839 add_node_to (encoder
, node
->clone_of
, include_body
);
840 else if (include_body
)
841 lto_set_symtab_encoder_encode_body (encoder
, node
);
842 lto_symtab_encoder_encode (encoder
, node
);
845 /* Add all references in NODE to encoders. */
848 create_references (lto_symtab_encoder_t encoder
, symtab_node
*node
)
851 struct ipa_ref
*ref
= NULL
;
852 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
853 if (is_a
<cgraph_node
*> (ref
->referred
))
854 add_node_to (encoder
, dyn_cast
<cgraph_node
*> (ref
->referred
), false);
856 lto_symtab_encoder_encode (encoder
, ref
->referred
);
859 /* Select what needs to be streamed out. In regular lto mode stream everything.
860 In offload lto mode stream only nodes marked as offloadable. */
862 select_what_to_stream (void)
864 struct symtab_node
*snode
;
865 FOR_EACH_SYMBOL (snode
)
866 snode
->need_lto_streaming
= !lto_stream_offload_p
|| snode
->offloadable
;
869 /* Find all symbols we want to stream into given partition and insert them
872 The function actually replaces IN_ENCODER by new one. The reason is that
873 streaming code needs clone's origin to be streamed before clone. This
874 means that we need to insert the nodes in specific order. This order is
875 ignored by the partitioning logic earlier. */
878 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder
)
880 struct cgraph_edge
*edge
;
882 lto_symtab_encoder_t encoder
;
883 lto_symtab_encoder_iterator lsei
;
884 hash_set
<void *> reachable_call_targets
;
886 encoder
= lto_symtab_encoder_new (false);
888 /* Go over all entries in the IN_ENCODER and duplicate them to
889 ENCODER. At the same time insert masters of clones so
890 every master appears before clone. */
891 for (lsei
= lsei_start_function_in_partition (in_encoder
);
892 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
894 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
895 if (!node
->need_lto_streaming
)
897 add_node_to (encoder
, node
, true);
898 lto_set_symtab_encoder_in_partition (encoder
, node
);
899 create_references (encoder
, node
);
900 /* For proper debug info, we need to ship the origins, too. */
901 if (DECL_ABSTRACT_ORIGIN (node
->decl
))
903 struct cgraph_node
*origin_node
904 = cgraph_node::get_create (DECL_ABSTRACT_ORIGIN (node
->decl
));
905 origin_node
->used_as_abstract_origin
= true;
906 add_node_to (encoder
, origin_node
, true);
909 for (lsei
= lsei_start_variable_in_partition (in_encoder
);
910 !lsei_end_p (lsei
); lsei_next_variable_in_partition (&lsei
))
912 varpool_node
*vnode
= lsei_varpool_node (lsei
);
914 if (!vnode
->need_lto_streaming
)
916 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
917 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
918 create_references (encoder
, vnode
);
919 /* For proper debug info, we need to ship the origins, too. */
920 if (DECL_ABSTRACT_ORIGIN (vnode
->decl
))
922 varpool_node
*origin_node
923 = varpool_node::get (DECL_ABSTRACT_ORIGIN (vnode
->decl
));
924 lto_set_symtab_encoder_in_partition (encoder
, origin_node
);
927 /* Pickle in also the initializer of all referenced readonly variables
928 to help folding. Constant pool variables are not shared, so we must
930 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
932 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
933 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
935 if (!lto_symtab_encoder_encode_initializer_p (encoder
,
937 && (((vnode
->ctor_useable_for_folding_p ()
938 && (!DECL_VIRTUAL_P (vnode
->decl
)
940 || flag_ltrans_devirtualize
))
941 || POINTER_BOUNDS_P (vnode
->decl
))))
943 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
944 create_references (encoder
, vnode
);
949 /* Go over all the nodes again to include callees that are not in
951 for (lsei
= lsei_start_function_in_partition (encoder
);
952 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
954 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
955 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
957 struct cgraph_node
*callee
= edge
->callee
;
958 if (!lto_symtab_encoder_in_partition_p (encoder
, callee
))
960 /* We should have moved all the inlines. */
961 gcc_assert (!callee
->global
.inlined_to
);
962 add_node_to (encoder
, callee
, false);
965 /* Add all possible targets for late devirtualization. */
966 if (flag_ltrans_devirtualize
|| !flag_wpa
)
967 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
968 if (edge
->indirect_info
->polymorphic
)
973 vec
<cgraph_node
*>targets
974 = possible_polymorphic_call_targets
975 (edge
, &final
, &cache_token
);
976 if (!reachable_call_targets
.add (cache_token
))
978 for (i
= 0; i
< targets
.length (); i
++)
980 struct cgraph_node
*callee
= targets
[i
];
982 /* Adding an external declarations into the unit serves
983 no purpose and just increases its boundary. */
984 if (callee
->definition
985 && !lto_symtab_encoder_in_partition_p
988 gcc_assert (!callee
->global
.inlined_to
);
989 add_node_to (encoder
, callee
, false);
995 /* Be sure to also insert alias targert and thunk callees. These needs
996 to stay to aid local calling conventions. */
997 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
999 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1000 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
1002 if (node
->alias
&& node
->analyzed
)
1003 create_references (encoder
, node
);
1005 && cnode
->thunk
.thunk_p
)
1006 add_node_to (encoder
, cnode
->callees
->callee
, false);
1008 lto_symtab_encoder_delete (in_encoder
);
1012 /* Output the part of the symtab in SET and VSET. */
1015 output_symtab (void)
1017 struct cgraph_node
*node
;
1018 struct lto_simple_output_block
*ob
;
1020 lto_symtab_encoder_t encoder
;
1023 output_cgraph_opt_summary ();
1025 ob
= lto_create_simple_output_block (LTO_section_symtab_nodes
);
1027 output_profile_summary (ob
);
1029 /* An encoder for cgraph nodes should have been created by
1030 ipa_write_summaries_1. */
1031 gcc_assert (ob
->decl_state
->symtab_node_encoder
);
1032 encoder
= ob
->decl_state
->symtab_node_encoder
;
1034 /* Write out the nodes. We must first output a node and then its clones,
1035 otherwise at a time reading back the node there would be nothing to clone
1037 n_nodes
= lto_symtab_encoder_size (encoder
);
1038 for (i
= 0; i
< n_nodes
; i
++)
1040 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1041 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1042 lto_output_node (ob
, cnode
, encoder
);
1044 lto_output_varpool_node (ob
, dyn_cast
<varpool_node
*> (node
), encoder
);
1047 /* Go over the nodes in SET again to write edges. */
1048 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
1050 node
= dyn_cast
<cgraph_node
*> (lto_symtab_encoder_deref (encoder
, i
));
1052 && (node
->thunk
.thunk_p
1053 || lto_symtab_encoder_in_partition_p (encoder
, node
)))
1055 output_outgoing_cgraph_edges (node
->callees
, ob
, encoder
);
1056 output_outgoing_cgraph_edges (node
->indirect_calls
, ob
, encoder
);
1060 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1062 lto_destroy_simple_output_block (ob
);
1064 /* Emit toplevel asms.
1065 When doing WPA we must output every asm just once. Since we do not partition asm
1066 nodes at all, output them to first output. This is kind of hack, but should work
1068 if (!asm_nodes_output
)
1070 asm_nodes_output
= true;
1071 lto_output_toplevel_asms ();
1074 output_refs (encoder
);
1077 /* Return identifier encoded in IB as a plain string. */
1080 read_identifier (struct lto_input_block
*ib
)
1082 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1085 if (ib
->data
[ib
->p
+ len
])
1086 lto_section_overrun (ib
);
1092 id
= get_identifier (ib
->data
+ ib
->p
);
1097 /* Return string encoded in IB, NULL if string is empty. */
1100 read_string (struct lto_input_block
*ib
)
1102 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1105 if (ib
->data
[ib
->p
+ len
])
1106 lto_section_overrun (ib
);
1112 str
= ib
->data
+ ib
->p
;
1117 /* Output function/variable tables that will allow libgomp to look up offload
1119 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1120 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1121 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1124 output_offload_tables (void)
1126 if (vec_safe_is_empty (offload_funcs
) && vec_safe_is_empty (offload_vars
))
1129 struct lto_simple_output_block
*ob
1130 = lto_create_simple_output_block (LTO_section_offload_table
);
1132 for (unsigned i
= 0; i
< vec_safe_length (offload_funcs
); i
++)
1134 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1135 LTO_symtab_last_tag
, LTO_symtab_unavail_node
);
1136 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
,
1137 (*offload_funcs
)[i
]);
1140 for (unsigned i
= 0; i
< vec_safe_length (offload_vars
); i
++)
1142 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1143 LTO_symtab_last_tag
, LTO_symtab_variable
);
1144 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
,
1145 (*offload_vars
)[i
]);
1148 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1149 lto_destroy_simple_output_block (ob
);
1151 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1152 streamed to one partition only. That's why we free offload_funcs and
1153 offload_vars after the first call of output_offload_tables. */
1156 vec_free (offload_funcs
);
1157 vec_free (offload_vars
);
1161 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1162 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1163 NODE or to replace the values in it, for instance because the first
1164 time we saw it, the function body was not available but now it
1165 is. BP is a bitpack with all the bitflags for NODE read from the
1169 input_overwrite_node (struct lto_file_decl_data
*file_data
,
1170 struct cgraph_node
*node
,
1171 enum LTO_symtab_tags tag
,
1172 struct bitpack_d
*bp
)
1174 node
->aux
= (void *) tag
;
1175 node
->lto_file_data
= file_data
;
1177 node
->local
.local
= bp_unpack_value (bp
, 1);
1178 node
->externally_visible
= bp_unpack_value (bp
, 1);
1179 node
->no_reorder
= bp_unpack_value (bp
, 1);
1180 node
->definition
= bp_unpack_value (bp
, 1);
1181 node
->local
.versionable
= bp_unpack_value (bp
, 1);
1182 node
->local
.can_change_signature
= bp_unpack_value (bp
, 1);
1183 node
->local
.redefined_extern_inline
= bp_unpack_value (bp
, 1);
1184 node
->force_output
= bp_unpack_value (bp
, 1);
1185 node
->forced_by_abi
= bp_unpack_value (bp
, 1);
1186 node
->unique_name
= bp_unpack_value (bp
, 1);
1187 node
->body_removed
= bp_unpack_value (bp
, 1);
1188 node
->implicit_section
= bp_unpack_value (bp
, 1);
1189 node
->address_taken
= bp_unpack_value (bp
, 1);
1190 node
->used_from_other_partition
= bp_unpack_value (bp
, 1);
1191 node
->lowered
= bp_unpack_value (bp
, 1);
1192 node
->analyzed
= tag
== LTO_symtab_analyzed_node
;
1193 node
->in_other_partition
= bp_unpack_value (bp
, 1);
1194 if (node
->in_other_partition
1195 /* Avoid updating decl when we are seeing just inline clone.
1196 When inlining function that has functions already inlined into it,
1197 we produce clones of inline clones.
1199 WPA partitioning might put each clone into different unit and
1200 we might end up streaming inline clone from other partition
1201 to support clone we are interested in. */
1203 || node
->clone_of
->decl
!= node
->decl
))
1205 DECL_EXTERNAL (node
->decl
) = 1;
1206 TREE_STATIC (node
->decl
) = 0;
1208 node
->alias
= bp_unpack_value (bp
, 1);
1209 node
->weakref
= bp_unpack_value (bp
, 1);
1210 node
->frequency
= (enum node_frequency
)bp_unpack_value (bp
, 2);
1211 node
->only_called_at_startup
= bp_unpack_value (bp
, 1);
1212 node
->only_called_at_exit
= bp_unpack_value (bp
, 1);
1213 node
->tm_clone
= bp_unpack_value (bp
, 1);
1214 node
->calls_comdat_local
= bp_unpack_value (bp
, 1);
1215 node
->icf_merged
= bp_unpack_value (bp
, 1);
1216 node
->nonfreeing_fn
= bp_unpack_value (bp
, 1);
1217 node
->thunk
.thunk_p
= bp_unpack_value (bp
, 1);
1218 node
->parallelized_function
= bp_unpack_value (bp
, 1);
1219 node
->resolution
= bp_unpack_enum (bp
, ld_plugin_symbol_resolution
,
1221 node
->instrumentation_clone
= bp_unpack_value (bp
, 1);
1222 node
->split_part
= bp_unpack_value (bp
, 1);
1223 gcc_assert (flag_ltrans
1224 || (!node
->in_other_partition
1225 && !node
->used_from_other_partition
));
1228 /* Return string alias is alias of. */
1231 get_alias_symbol (tree decl
)
1233 tree alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
1234 return get_identifier (TREE_STRING_POINTER
1235 (TREE_VALUE (TREE_VALUE (alias
))));
1238 /* Read a node from input_block IB. TAG is the node's tag just read.
1239 Return the node read or overwriten. */
1241 static struct cgraph_node
*
1242 input_node (struct lto_file_decl_data
*file_data
,
1243 struct lto_input_block
*ib
,
1244 enum LTO_symtab_tags tag
,
1245 vec
<symtab_node
*> nodes
)
1247 gcc::pass_manager
*passes
= g
->get_passes ();
1249 struct cgraph_node
*node
;
1250 struct bitpack_d bp
;
1251 unsigned decl_index
;
1252 int ref
= LCC_NOT_FOUND
, ref2
= LCC_NOT_FOUND
;
1257 const char *section
;
1258 order
= streamer_read_hwi (ib
) + order_base
;
1259 clone_ref
= streamer_read_hwi (ib
);
1261 decl_index
= streamer_read_uhwi (ib
);
1262 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1264 if (clone_ref
!= LCC_NOT_FOUND
)
1266 node
= dyn_cast
<cgraph_node
*> (nodes
[clone_ref
])->create_clone (fn_decl
,
1267 0, CGRAPH_FREQ_BASE
, false,
1268 vNULL
, false, NULL
, NULL
);
1272 /* Declaration of functions can be already merged with a declaration
1273 from other input file. We keep cgraph unmerged until after streaming
1274 of ipa passes is done. Alays forcingly create a fresh node. */
1275 node
= symtab
->create_empty ();
1276 node
->decl
= fn_decl
;
1277 node
->register_symbol ();
1280 node
->order
= order
;
1281 if (order
>= symtab
->order
)
1282 symtab
->order
= order
+ 1;
1284 node
->count
= streamer_read_gcov_count (ib
);
1285 node
->count_materialization_scale
= streamer_read_hwi (ib
);
1287 count
= streamer_read_hwi (ib
);
1288 node
->ipa_transforms_to_apply
= vNULL
;
1289 for (i
= 0; i
< count
; i
++)
1292 int pid
= streamer_read_hwi (ib
);
1294 gcc_assert (pid
< passes
->passes_by_id_size
);
1295 pass
= passes
->passes_by_id
[pid
];
1296 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*) pass
);
1299 if (tag
== LTO_symtab_analyzed_node
)
1300 ref
= streamer_read_hwi (ib
);
1302 group
= read_identifier (ib
);
1304 ref2
= streamer_read_hwi (ib
);
1306 /* Make sure that we have not read this node before. Nodes that
1307 have already been read will have their tag stored in the 'aux'
1308 field. Since built-in functions can be referenced in multiple
1309 functions, they are expected to be read more than once. */
1310 if (node
->aux
&& !DECL_BUILT_IN (node
->decl
))
1311 internal_error ("bytecode stream: found multiple instances of cgraph "
1312 "node with uid %d", node
->uid
);
1314 node
->tp_first_run
= streamer_read_uhwi (ib
);
1316 bp
= streamer_read_bitpack (ib
);
1318 input_overwrite_node (file_data
, node
, tag
, &bp
);
1320 /* Store a reference for now, and fix up later to be a pointer. */
1321 node
->global
.inlined_to
= (cgraph_node
*) (intptr_t) ref
;
1325 node
->set_comdat_group (group
);
1326 /* Store a reference for now, and fix up later to be a pointer. */
1327 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref2
;
1330 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1331 section
= read_string (ib
);
1333 node
->set_section_for_node (section
);
1335 if (node
->thunk
.thunk_p
)
1337 int type
= streamer_read_uhwi (ib
);
1338 HOST_WIDE_INT fixed_offset
= streamer_read_uhwi (ib
);
1339 HOST_WIDE_INT virtual_value
= streamer_read_uhwi (ib
);
1341 node
->thunk
.fixed_offset
= fixed_offset
;
1342 node
->thunk
.this_adjusting
= (type
& 2);
1343 node
->thunk
.virtual_value
= virtual_value
;
1344 node
->thunk
.virtual_offset_p
= (type
& 4);
1345 node
->thunk
.add_pointer_bounds_args
= (type
& 8);
1347 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1348 node
->alias_target
= get_alias_symbol (node
->decl
);
1349 node
->profile_id
= streamer_read_hwi (ib
);
1350 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
1351 node
->set_init_priority (streamer_read_hwi (ib
));
1352 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
1353 node
->set_fini_priority (streamer_read_hwi (ib
));
1355 if (node
->instrumentation_clone
)
1357 decl_index
= streamer_read_uhwi (ib
);
1358 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1359 node
->orig_decl
= fn_decl
;
1365 /* Read a node from input_block IB. TAG is the node's tag just read.
1366 Return the node read or overwriten. */
1368 static varpool_node
*
1369 input_varpool_node (struct lto_file_decl_data
*file_data
,
1370 struct lto_input_block
*ib
)
1375 struct bitpack_d bp
;
1376 int ref
= LCC_NOT_FOUND
;
1379 const char *section
;
1381 order
= streamer_read_hwi (ib
) + order_base
;
1382 decl_index
= streamer_read_uhwi (ib
);
1383 var_decl
= lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1385 /* Declaration of functions can be already merged with a declaration
1386 from other input file. We keep cgraph unmerged until after streaming
1387 of ipa passes is done. Alays forcingly create a fresh node. */
1388 node
= varpool_node::create_empty ();
1389 node
->decl
= var_decl
;
1390 node
->register_symbol ();
1392 node
->order
= order
;
1393 if (order
>= symtab
->order
)
1394 symtab
->order
= order
+ 1;
1395 node
->lto_file_data
= file_data
;
1397 bp
= streamer_read_bitpack (ib
);
1398 node
->externally_visible
= bp_unpack_value (&bp
, 1);
1399 node
->no_reorder
= bp_unpack_value (&bp
, 1);
1400 node
->force_output
= bp_unpack_value (&bp
, 1);
1401 node
->forced_by_abi
= bp_unpack_value (&bp
, 1);
1402 node
->unique_name
= bp_unpack_value (&bp
, 1);
1403 node
->body_removed
= bp_unpack_value (&bp
, 1);
1404 node
->implicit_section
= bp_unpack_value (&bp
, 1);
1405 node
->writeonly
= bp_unpack_value (&bp
, 1);
1406 node
->definition
= bp_unpack_value (&bp
, 1);
1407 node
->alias
= bp_unpack_value (&bp
, 1);
1408 node
->weakref
= bp_unpack_value (&bp
, 1);
1409 node
->analyzed
= bp_unpack_value (&bp
, 1);
1410 node
->used_from_other_partition
= bp_unpack_value (&bp
, 1);
1411 node
->in_other_partition
= bp_unpack_value (&bp
, 1);
1412 if (node
->in_other_partition
)
1414 DECL_EXTERNAL (node
->decl
) = 1;
1415 TREE_STATIC (node
->decl
) = 0;
1417 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1418 node
->alias_target
= get_alias_symbol (node
->decl
);
1419 node
->tls_model
= (enum tls_model
)bp_unpack_value (&bp
, 3);
1420 node
->used_by_single_function
= (enum tls_model
)bp_unpack_value (&bp
, 1);
1421 node
->need_bounds_init
= bp_unpack_value (&bp
, 1);
1422 group
= read_identifier (ib
);
1425 node
->set_comdat_group (group
);
1426 ref
= streamer_read_hwi (ib
);
1427 /* Store a reference for now, and fix up later to be a pointer. */
1428 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref
;
1431 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1432 section
= read_string (ib
);
1434 node
->set_section_for_node (section
);
1435 node
->resolution
= streamer_read_enum (ib
, ld_plugin_symbol_resolution
,
1437 gcc_assert (flag_ltrans
1438 || (!node
->in_other_partition
1439 && !node
->used_from_other_partition
));
1444 /* Read a node from input_block IB. TAG is the node's tag just read.
1445 Return the node read or overwriten. */
1448 input_ref (struct lto_input_block
*ib
,
1449 symtab_node
*referring_node
,
1450 vec
<symtab_node
*> nodes
)
1452 symtab_node
*node
= NULL
;
1453 struct bitpack_d bp
;
1454 enum ipa_ref_use use
;
1456 struct ipa_ref
*ref
;
1458 bp
= streamer_read_bitpack (ib
);
1459 use
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 3);
1460 speculative
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 1);
1461 node
= nodes
[streamer_read_hwi (ib
)];
1462 ref
= referring_node
->create_reference (node
, use
);
1463 ref
->speculative
= speculative
;
1464 if (is_a
<cgraph_node
*> (referring_node
))
1465 ref
->lto_stmt_uid
= streamer_read_hwi (ib
);
1468 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1469 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1470 edge being read is indirect (in the sense that it has
1471 indirect_unknown_callee set). */
1474 input_edge (struct lto_input_block
*ib
, vec
<symtab_node
*> nodes
,
1477 struct cgraph_node
*caller
, *callee
;
1478 struct cgraph_edge
*edge
;
1479 unsigned int stmt_id
;
1482 cgraph_inline_failed_t inline_failed
;
1483 struct bitpack_d bp
;
1486 caller
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1487 if (caller
== NULL
|| caller
->decl
== NULL_TREE
)
1488 internal_error ("bytecode stream: no caller found while reading edge");
1492 callee
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1493 if (callee
== NULL
|| callee
->decl
== NULL_TREE
)
1494 internal_error ("bytecode stream: no callee found while reading edge");
1499 count
= streamer_read_gcov_count (ib
);
1501 bp
= streamer_read_bitpack (ib
);
1502 inline_failed
= bp_unpack_enum (&bp
, cgraph_inline_failed_t
, CIF_N_REASONS
);
1503 stmt_id
= bp_unpack_var_len_unsigned (&bp
);
1504 freq
= (int) bp_unpack_var_len_unsigned (&bp
);
1507 edge
= caller
->create_indirect_edge (NULL
, 0, count
, freq
);
1509 edge
= caller
->create_edge (callee
, NULL
, count
, freq
);
1511 edge
->indirect_inlining_edge
= bp_unpack_value (&bp
, 1);
1512 edge
->speculative
= bp_unpack_value (&bp
, 1);
1513 edge
->lto_stmt_uid
= stmt_id
;
1514 edge
->inline_failed
= inline_failed
;
1515 edge
->call_stmt_cannot_inline_p
= bp_unpack_value (&bp
, 1);
1516 edge
->can_throw_external
= bp_unpack_value (&bp
, 1);
1517 edge
->in_polymorphic_cdtor
= bp_unpack_value (&bp
, 1);
1520 if (bp_unpack_value (&bp
, 1))
1521 ecf_flags
|= ECF_CONST
;
1522 if (bp_unpack_value (&bp
, 1))
1523 ecf_flags
|= ECF_PURE
;
1524 if (bp_unpack_value (&bp
, 1))
1525 ecf_flags
|= ECF_NORETURN
;
1526 if (bp_unpack_value (&bp
, 1))
1527 ecf_flags
|= ECF_MALLOC
;
1528 if (bp_unpack_value (&bp
, 1))
1529 ecf_flags
|= ECF_NOTHROW
;
1530 if (bp_unpack_value (&bp
, 1))
1531 ecf_flags
|= ECF_RETURNS_TWICE
;
1532 edge
->indirect_info
->ecf_flags
= ecf_flags
;
1533 edge
->indirect_info
->common_target_id
= streamer_read_hwi (ib
);
1534 if (edge
->indirect_info
->common_target_id
)
1535 edge
->indirect_info
->common_target_probability
= streamer_read_hwi (ib
);
1540 /* Read a cgraph from IB using the info in FILE_DATA. */
1542 static vec
<symtab_node
*>
1543 input_cgraph_1 (struct lto_file_decl_data
*file_data
,
1544 struct lto_input_block
*ib
)
1546 enum LTO_symtab_tags tag
;
1547 vec
<symtab_node
*> nodes
= vNULL
;
1551 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1552 order_base
= symtab
->order
;
1555 if (tag
== LTO_symtab_edge
)
1556 input_edge (ib
, nodes
, false);
1557 else if (tag
== LTO_symtab_indirect_edge
)
1558 input_edge (ib
, nodes
, true);
1559 else if (tag
== LTO_symtab_variable
)
1561 node
= input_varpool_node (file_data
, ib
);
1562 nodes
.safe_push (node
);
1563 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1567 node
= input_node (file_data
, ib
, tag
, nodes
);
1568 if (node
== NULL
|| node
->decl
== NULL_TREE
)
1569 internal_error ("bytecode stream: found empty cgraph node");
1570 nodes
.safe_push (node
);
1571 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1574 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1577 lto_input_toplevel_asms (file_data
, order_base
);
1579 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1580 #ifdef ENABLE_CHECKING
1581 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1582 gcc_assert (node
->aux
|| !is_a
<cgraph_node
*> (node
));
1584 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1587 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1589 ref
= (int) (intptr_t) cnode
->global
.inlined_to
;
1591 /* We share declaration of builtins, so we may read same node twice. */
1596 /* Fixup inlined_to from reference to pointer. */
1597 if (ref
!= LCC_NOT_FOUND
)
1598 dyn_cast
<cgraph_node
*> (node
)->global
.inlined_to
1599 = dyn_cast
<cgraph_node
*> (nodes
[ref
]);
1601 cnode
->global
.inlined_to
= NULL
;
1603 /* Compute instrumented_version. */
1604 if (cnode
->instrumentation_clone
)
1606 gcc_assert (cnode
->orig_decl
);
1608 cnode
->instrumented_version
= cgraph_node::get (cnode
->orig_decl
);
1609 if (cnode
->instrumented_version
)
1611 /* We may have multiple nodes for a single function which
1612 will be merged later. To have a proper merge we need
1613 to keep instrumentation_version reference between nodes
1614 consistent: each instrumented_version reference should
1615 have proper reverse reference. Thus don't break existing
1616 instrumented_version reference if it already exists. */
1617 if (cnode
->instrumented_version
->instrumented_version
)
1618 cnode
->instrumented_version
= NULL
;
1620 cnode
->instrumented_version
->instrumented_version
= cnode
;
1623 /* Restore decl names reference except for wrapper functions. */
1624 if (!chkp_wrap_function (cnode
->orig_decl
))
1626 tree name
= DECL_ASSEMBLER_NAME (cnode
->decl
);
1627 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
1628 TREE_CHAIN (name
) = DECL_ASSEMBLER_NAME (cnode
->orig_decl
);
1633 ref
= (int) (intptr_t) node
->same_comdat_group
;
1635 /* Fixup same_comdat_group from reference to pointer. */
1636 if (ref
!= LCC_NOT_FOUND
)
1637 node
->same_comdat_group
= nodes
[ref
];
1639 node
->same_comdat_group
= NULL
;
1641 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1642 node
->aux
= is_a
<cgraph_node
*> (node
) ? (void *)1 : NULL
;
1646 /* Input ipa_refs. */
1649 input_refs (struct lto_input_block
*ib
,
1650 vec
<symtab_node
*> nodes
)
1657 count
= streamer_read_uhwi (ib
);
1660 idx
= streamer_read_uhwi (ib
);
1664 input_ref (ib
, node
, nodes
);
1671 static struct gcov_ctr_summary lto_gcov_summary
;
1673 /* Input profile_info from IB. */
1675 input_profile_summary (struct lto_input_block
*ib
,
1676 struct lto_file_decl_data
*file_data
)
1679 struct bitpack_d bp
;
1680 unsigned int runs
= streamer_read_uhwi (ib
);
1683 file_data
->profile_info
.runs
= runs
;
1684 file_data
->profile_info
.sum_max
= streamer_read_gcov_count (ib
);
1685 file_data
->profile_info
.sum_all
= streamer_read_gcov_count (ib
);
1687 memset (file_data
->profile_info
.histogram
, 0,
1688 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1689 /* Input the bitpack of non-zero histogram indices. */
1690 bp
= streamer_read_bitpack (ib
);
1691 /* Read in and unpack the full bitpack, flagging non-zero
1692 histogram entries by setting the num_counters non-zero. */
1693 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1695 file_data
->profile_info
.histogram
[h_ix
].num_counters
1696 = bp_unpack_value (&bp
, 1);
1698 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1700 if (!file_data
->profile_info
.histogram
[h_ix
].num_counters
)
1703 file_data
->profile_info
.histogram
[h_ix
].num_counters
1704 = streamer_read_gcov_count (ib
);
1705 file_data
->profile_info
.histogram
[h_ix
].min_value
1706 = streamer_read_gcov_count (ib
);
1707 file_data
->profile_info
.histogram
[h_ix
].cum_value
1708 = streamer_read_gcov_count (ib
);
1710 /* IPA-profile computes hot bb threshold based on cumulated
1711 whole program profile. We need to stream it down to ltrans. */
1713 set_hot_bb_threshold (streamer_read_gcov_count (ib
));
1718 /* Rescale profile summaries to the same number of runs in the whole unit. */
1721 merge_profile_summaries (struct lto_file_decl_data
**file_data_vec
)
1723 struct lto_file_decl_data
*file_data
;
1724 unsigned int j
, h_ix
;
1725 gcov_unsigned_t max_runs
= 0;
1726 struct cgraph_node
*node
;
1727 struct cgraph_edge
*edge
;
1728 gcov_type saved_sum_all
= 0;
1729 gcov_ctr_summary
*saved_profile_info
= 0;
1730 int saved_scale
= 0;
1732 /* Find unit with maximal number of runs. If we ever get serious about
1733 roundoff errors, we might also consider computing smallest common
1735 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1736 if (max_runs
< file_data
->profile_info
.runs
)
1737 max_runs
= file_data
->profile_info
.runs
;
1742 /* Simple overflow check. We probably don't need to support that many train
1743 runs. Such a large value probably imply data corruption anyway. */
1744 if (max_runs
> INT_MAX
/ REG_BR_PROB_BASE
)
1746 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1747 INT_MAX
/ REG_BR_PROB_BASE
);
1751 profile_info
= <o_gcov_summary
;
1752 lto_gcov_summary
.runs
= max_runs
;
1753 lto_gcov_summary
.sum_max
= 0;
1754 memset (lto_gcov_summary
.histogram
, 0,
1755 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1757 /* Rescale all units to the maximal number of runs.
1758 sum_max can not be easily merged, as we have no idea what files come from
1759 the same run. We do not use the info anyway, so leave it 0. */
1760 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1761 if (file_data
->profile_info
.runs
)
1763 int scale
= GCOV_COMPUTE_SCALE (max_runs
,
1764 file_data
->profile_info
.runs
);
1765 lto_gcov_summary
.sum_max
1766 = MAX (lto_gcov_summary
.sum_max
,
1767 apply_scale (file_data
->profile_info
.sum_max
, scale
));
1768 lto_gcov_summary
.sum_all
1769 = MAX (lto_gcov_summary
.sum_all
,
1770 apply_scale (file_data
->profile_info
.sum_all
, scale
));
1771 /* Save a pointer to the profile_info with the largest
1772 scaled sum_all and the scale for use in merging the
1774 if (!saved_profile_info
1775 || lto_gcov_summary
.sum_all
> saved_sum_all
)
1777 saved_profile_info
= &file_data
->profile_info
;
1778 saved_sum_all
= lto_gcov_summary
.sum_all
;
1779 saved_scale
= scale
;
1783 gcc_assert (saved_profile_info
);
1785 /* Scale up the histogram from the profile that had the largest
1786 scaled sum_all above. */
1787 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1789 /* Scale up the min value as we did the corresponding sum_all
1790 above. Use that to find the new histogram index. */
1791 gcov_type scaled_min
1792 = apply_scale (saved_profile_info
->histogram
[h_ix
].min_value
,
1794 /* The new index may be shared with another scaled histogram entry,
1795 so we need to account for a non-zero histogram entry at new_ix. */
1796 unsigned new_ix
= gcov_histo_index (scaled_min
);
1797 lto_gcov_summary
.histogram
[new_ix
].min_value
1798 = (lto_gcov_summary
.histogram
[new_ix
].num_counters
1799 ? MIN (lto_gcov_summary
.histogram
[new_ix
].min_value
, scaled_min
)
1801 /* Some of the scaled counter values would ostensibly need to be placed
1802 into different (larger) histogram buckets, but we keep things simple
1803 here and place the scaled cumulative counter value in the bucket
1804 corresponding to the scaled minimum counter value. */
1805 lto_gcov_summary
.histogram
[new_ix
].cum_value
1806 += apply_scale (saved_profile_info
->histogram
[h_ix
].cum_value
,
1808 lto_gcov_summary
.histogram
[new_ix
].num_counters
1809 += saved_profile_info
->histogram
[h_ix
].num_counters
;
1812 /* Watch roundoff errors. */
1813 if (lto_gcov_summary
.sum_max
< max_runs
)
1814 lto_gcov_summary
.sum_max
= max_runs
;
1816 /* If merging already happent at WPA time, we are done. */
1820 /* Now compute count_materialization_scale of each node.
1821 During LTRANS we already have values of count_materialization_scale
1822 computed, so just update them. */
1823 FOR_EACH_FUNCTION (node
)
1824 if (node
->lto_file_data
1825 && node
->lto_file_data
->profile_info
.runs
)
1829 scale
= RDIV (node
->count_materialization_scale
* max_runs
,
1830 node
->lto_file_data
->profile_info
.runs
);
1831 node
->count_materialization_scale
= scale
;
1833 fatal_error (input_location
, "Profile information in %s corrupted",
1834 file_data
->file_name
);
1836 if (scale
== REG_BR_PROB_BASE
)
1838 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1839 edge
->count
= apply_scale (edge
->count
, scale
);
1840 node
->count
= apply_scale (node
->count
, scale
);
1844 /* Input and merge the symtab from each of the .o files passed to
1850 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1851 struct lto_file_decl_data
*file_data
;
1853 struct cgraph_node
*node
;
1855 while ((file_data
= file_data_vec
[j
++]))
1859 struct lto_input_block
*ib
;
1860 vec
<symtab_node
*> nodes
;
1862 ib
= lto_create_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1865 fatal_error (input_location
,
1866 "cannot find LTO cgraph in %s", file_data
->file_name
);
1867 input_profile_summary (ib
, file_data
);
1868 file_data
->symtab_node_encoder
= lto_symtab_encoder_new (true);
1869 nodes
= input_cgraph_1 (file_data
, ib
);
1870 lto_destroy_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1873 ib
= lto_create_simple_input_block (file_data
, LTO_section_refs
,
1876 fatal_error (input_location
, "cannot find LTO section refs in %s",
1877 file_data
->file_name
);
1878 input_refs (ib
, nodes
);
1879 lto_destroy_simple_input_block (file_data
, LTO_section_refs
,
1882 input_cgraph_opt_summary (nodes
);
1886 merge_profile_summaries (file_data_vec
);
1887 get_working_sets ();
1890 /* Clear out the aux field that was used to store enough state to
1891 tell which nodes should be overwritten. */
1892 FOR_EACH_FUNCTION (node
)
1894 /* Some nodes may have been created by cgraph_node. This
1895 happens when the callgraph contains nested functions. If the
1896 node for the parent function was never emitted to the gimple
1897 file, cgraph_node will create a node for it when setting the
1898 context of the nested function. */
1899 if (node
->lto_file_data
)
1904 /* Input function/variable tables that will allow libgomp to look up offload
1905 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1908 input_offload_tables (void)
1910 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1911 struct lto_file_decl_data
*file_data
;
1914 while ((file_data
= file_data_vec
[j
++]))
1918 struct lto_input_block
*ib
1919 = lto_create_simple_input_block (file_data
, LTO_section_offload_table
,
1924 enum LTO_symtab_tags tag
1925 = streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1928 if (tag
== LTO_symtab_unavail_node
)
1930 int decl_index
= streamer_read_uhwi (ib
);
1932 = lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1933 vec_safe_push (offload_funcs
, fn_decl
);
1935 else if (tag
== LTO_symtab_variable
)
1937 int decl_index
= streamer_read_uhwi (ib
);
1939 = lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1940 vec_safe_push (offload_vars
, var_decl
);
1943 fatal_error (input_location
,
1944 "invalid offload table in %s", file_data
->file_name
);
1946 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1949 lto_destroy_simple_input_block (file_data
, LTO_section_offload_table
,
1954 /* True when we need optimization summary for NODE. */
1957 output_cgraph_opt_summary_p (struct cgraph_node
*node
)
1959 return (node
->clone_of
1960 && (node
->clone
.tree_map
1961 || node
->clone
.args_to_skip
1962 || node
->clone
.combined_args_to_skip
));
1965 /* Output optimization summary for EDGE to OB. */
1967 output_edge_opt_summary (struct output_block
*ob ATTRIBUTE_UNUSED
,
1968 struct cgraph_edge
*edge ATTRIBUTE_UNUSED
)
1972 /* Output optimization summary for NODE to OB. */
1975 output_node_opt_summary (struct output_block
*ob
,
1976 struct cgraph_node
*node
,
1977 lto_symtab_encoder_t encoder
)
1981 struct ipa_replace_map
*map
;
1982 struct bitpack_d bp
;
1984 struct cgraph_edge
*e
;
1986 if (node
->clone
.args_to_skip
)
1988 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.args_to_skip
));
1989 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.args_to_skip
, 0, index
, bi
)
1990 streamer_write_uhwi (ob
, index
);
1993 streamer_write_uhwi (ob
, 0);
1994 if (node
->clone
.combined_args_to_skip
)
1996 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.combined_args_to_skip
));
1997 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.combined_args_to_skip
, 0, index
, bi
)
1998 streamer_write_uhwi (ob
, index
);
2001 streamer_write_uhwi (ob
, 0);
2002 streamer_write_uhwi (ob
, vec_safe_length (node
->clone
.tree_map
));
2003 FOR_EACH_VEC_SAFE_ELT (node
->clone
.tree_map
, i
, map
)
2005 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
2006 mechanism to store function local declarations into summaries. */
2007 gcc_assert (!map
->old_tree
);
2008 streamer_write_uhwi (ob
, map
->parm_num
);
2009 gcc_assert (EXPR_LOCATION (map
->new_tree
) == UNKNOWN_LOCATION
);
2010 stream_write_tree (ob
, map
->new_tree
, true);
2011 bp
= bitpack_create (ob
->main_stream
);
2012 bp_pack_value (&bp
, map
->replace_p
, 1);
2013 bp_pack_value (&bp
, map
->ref_p
, 1);
2014 streamer_write_bitpack (&bp
);
2017 if (lto_symtab_encoder_in_partition_p (encoder
, node
))
2019 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2020 output_edge_opt_summary (ob
, e
);
2021 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2022 output_edge_opt_summary (ob
, e
);
2026 /* Output optimization summaries stored in callgraph.
2027 At the moment it is the clone info structure. */
2030 output_cgraph_opt_summary (void)
2033 lto_symtab_encoder_t encoder
;
2034 struct output_block
*ob
= create_output_block (LTO_section_cgraph_opt_sum
);
2038 encoder
= ob
->decl_state
->symtab_node_encoder
;
2039 n_nodes
= lto_symtab_encoder_size (encoder
);
2040 for (i
= 0; i
< n_nodes
; i
++)
2042 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2043 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2044 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2047 streamer_write_uhwi (ob
, count
);
2048 for (i
= 0; i
< n_nodes
; i
++)
2050 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2051 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2052 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2054 streamer_write_uhwi (ob
, i
);
2055 output_node_opt_summary (ob
, cnode
, encoder
);
2058 produce_asm (ob
, NULL
);
2059 destroy_output_block (ob
);
2062 /* Input optimisation summary of EDGE. */
2065 input_edge_opt_summary (struct cgraph_edge
*edge ATTRIBUTE_UNUSED
,
2066 struct lto_input_block
*ib_main ATTRIBUTE_UNUSED
)
2070 /* Input optimisation summary of NODE. */
2073 input_node_opt_summary (struct cgraph_node
*node
,
2074 struct lto_input_block
*ib_main
,
2075 struct data_in
*data_in
)
2080 struct bitpack_d bp
;
2081 struct cgraph_edge
*e
;
2083 count
= streamer_read_uhwi (ib_main
);
2085 node
->clone
.args_to_skip
= BITMAP_GGC_ALLOC ();
2086 for (i
= 0; i
< count
; i
++)
2088 bit
= streamer_read_uhwi (ib_main
);
2089 bitmap_set_bit (node
->clone
.args_to_skip
, bit
);
2091 count
= streamer_read_uhwi (ib_main
);
2093 node
->clone
.combined_args_to_skip
= BITMAP_GGC_ALLOC ();
2094 for (i
= 0; i
< count
; i
++)
2096 bit
= streamer_read_uhwi (ib_main
);
2097 bitmap_set_bit (node
->clone
.combined_args_to_skip
, bit
);
2099 count
= streamer_read_uhwi (ib_main
);
2100 for (i
= 0; i
< count
; i
++)
2102 struct ipa_replace_map
*map
= ggc_alloc
<ipa_replace_map
> ();
2104 vec_safe_push (node
->clone
.tree_map
, map
);
2105 map
->parm_num
= streamer_read_uhwi (ib_main
);
2106 map
->old_tree
= NULL
;
2107 map
->new_tree
= stream_read_tree (ib_main
, data_in
);
2108 bp
= streamer_read_bitpack (ib_main
);
2109 map
->replace_p
= bp_unpack_value (&bp
, 1);
2110 map
->ref_p
= bp_unpack_value (&bp
, 1);
2112 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2113 input_edge_opt_summary (e
, ib_main
);
2114 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2115 input_edge_opt_summary (e
, ib_main
);
2118 /* Read section in file FILE_DATA of length LEN with data DATA. */
2121 input_cgraph_opt_section (struct lto_file_decl_data
*file_data
,
2122 const char *data
, size_t len
,
2123 vec
<symtab_node
*> nodes
)
2125 const struct lto_function_header
*header
=
2126 (const struct lto_function_header
*) data
;
2127 const int cfg_offset
= sizeof (struct lto_function_header
);
2128 const int main_offset
= cfg_offset
+ header
->cfg_size
;
2129 const int string_offset
= main_offset
+ header
->main_size
;
2130 struct data_in
*data_in
;
2134 lto_input_block
ib_main ((const char *) data
+ main_offset
,
2135 header
->main_size
, file_data
->mode_table
);
2138 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
2139 header
->string_size
, vNULL
);
2140 count
= streamer_read_uhwi (&ib_main
);
2142 for (i
= 0; i
< count
; i
++)
2144 int ref
= streamer_read_uhwi (&ib_main
);
2145 input_node_opt_summary (dyn_cast
<cgraph_node
*> (nodes
[ref
]),
2148 lto_free_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
, data
,
2150 lto_data_in_delete (data_in
);
2153 /* Input optimization summary of cgraph. */
2156 input_cgraph_opt_summary (vec
<symtab_node
*> nodes
)
2158 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
2159 struct lto_file_decl_data
*file_data
;
2162 while ((file_data
= file_data_vec
[j
++]))
2166 lto_get_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
,
2170 input_cgraph_opt_section (file_data
, data
, len
, nodes
);