1 /* Write and read the cgraph to the memory mapped representation of a
4 Copyright (C) 2009-2017 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 "stringpool.h"
32 #include "tree-streamer.h"
34 #include "tree-pass.h"
37 #include "pass_manager.h"
38 #include "ipa-utils.h"
39 #include "omp-offload.h"
41 #include "stringpool.h"
44 /* True when asm nodes has been output. */
45 bool asm_nodes_output
= false;
47 static void output_cgraph_opt_summary (void);
48 static void input_cgraph_opt_summary (vec
<symtab_node
*> nodes
);
50 /* Number of LDPR values known to GCC. */
51 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
53 /* All node orders are ofsetted by ORDER_BASE. */
54 static int order_base
;
56 /* Cgraph streaming is organized as set of record whose type
57 is indicated by a tag. */
60 /* Must leave 0 for the stopper. */
62 /* Cgraph node without body available. */
63 LTO_symtab_unavail_node
= 1,
64 /* Cgraph node with function body. */
65 LTO_symtab_analyzed_node
,
68 LTO_symtab_indirect_edge
,
73 /* Create a new symtab encoder.
74 if FOR_INPUT, the encoder allocate only datastructures needed
75 to read the symtab. */
78 lto_symtab_encoder_new (bool for_input
)
80 lto_symtab_encoder_t encoder
= XCNEW (struct lto_symtab_encoder_d
);
83 encoder
->map
= new hash_map
<symtab_node
*, size_t>;
84 encoder
->nodes
.create (0);
89 /* Delete ENCODER and its components. */
92 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder
)
94 encoder
->nodes
.release ();
101 /* Return the existing reference number of NODE in the symtab encoder in
102 output block OB. Assign a new reference if this is the first time
106 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder
,
113 lto_encoder_entry entry
= {node
, false, false, false};
115 ref
= encoder
->nodes
.length ();
116 encoder
->nodes
.safe_push (entry
);
120 size_t *slot
= encoder
->map
->get (node
);
123 lto_encoder_entry entry
= {node
, false, false, false};
124 ref
= encoder
->nodes
.length ();
126 encoder
->map
->put (node
, ref
+ 1);
127 encoder
->nodes
.safe_push (entry
);
135 /* Remove NODE from encoder. */
138 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder
,
142 lto_encoder_entry last_node
;
144 size_t *slot
= encoder
->map
->get (node
);
145 if (slot
== NULL
|| !*slot
)
149 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
151 /* Remove from vector. We do this by swapping node with the last element
153 last_node
= encoder
->nodes
.pop ();
154 if (last_node
.node
!= node
)
156 gcc_assert (encoder
->map
->put (last_node
.node
, index
+ 1));
158 /* Move the last element to the original spot of NODE. */
159 encoder
->nodes
[index
] = last_node
;
162 /* Remove element from hash table. */
163 encoder
->map
->remove (node
);
168 /* Return TRUE if we should encode the body of NODE (if any). */
171 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder
,
172 struct cgraph_node
*node
)
174 int index
= lto_symtab_encoder_lookup (encoder
, node
);
175 return encoder
->nodes
[index
].body
;
178 /* Specify that we encode the body of NODE in this partition. */
181 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder
,
182 struct cgraph_node
*node
)
184 int index
= lto_symtab_encoder_encode (encoder
, node
);
185 gcc_checking_assert (encoder
->nodes
[index
].node
== node
);
186 encoder
->nodes
[index
].body
= true;
189 /* Return TRUE if we should encode initializer of NODE (if any). */
192 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder
,
195 int index
= lto_symtab_encoder_lookup (encoder
, node
);
196 if (index
== LCC_NOT_FOUND
)
198 return encoder
->nodes
[index
].initializer
;
201 /* Specify that we should encode initializer of NODE (if any). */
204 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder
,
207 int index
= lto_symtab_encoder_lookup (encoder
, node
);
208 encoder
->nodes
[index
].initializer
= true;
211 /* Return TRUE if NODE is in this partition. */
214 lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder
,
217 int index
= lto_symtab_encoder_lookup (encoder
, node
);
218 if (index
== LCC_NOT_FOUND
)
220 return encoder
->nodes
[index
].in_partition
;
223 /* Specify that NODE is in this partition. */
226 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder
,
229 int index
= lto_symtab_encoder_encode (encoder
, node
);
230 encoder
->nodes
[index
].in_partition
= true;
233 /* Output the cgraph EDGE to OB using ENCODER. */
236 lto_output_edge (struct lto_simple_output_block
*ob
, struct cgraph_edge
*edge
,
237 lto_symtab_encoder_t encoder
)
243 if (edge
->indirect_unknown_callee
)
244 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
245 LTO_symtab_indirect_edge
);
247 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
250 ref
= lto_symtab_encoder_lookup (encoder
, edge
->caller
);
251 gcc_assert (ref
!= LCC_NOT_FOUND
);
252 streamer_write_hwi_stream (ob
->main_stream
, ref
);
254 if (!edge
->indirect_unknown_callee
)
256 ref
= lto_symtab_encoder_lookup (encoder
, edge
->callee
);
257 gcc_assert (ref
!= LCC_NOT_FOUND
);
258 streamer_write_hwi_stream (ob
->main_stream
, ref
);
261 edge
->count
.stream_out (ob
->main_stream
);
263 bp
= bitpack_create (ob
->main_stream
);
264 uid
= (!gimple_has_body_p (edge
->caller
->decl
) || edge
->caller
->thunk
.thunk_p
265 ? edge
->lto_stmt_uid
: gimple_uid (edge
->call_stmt
) + 1);
266 bp_pack_enum (&bp
, cgraph_inline_failed_t
,
267 CIF_N_REASONS
, edge
->inline_failed
);
268 bp_pack_var_len_unsigned (&bp
, uid
);
269 bp_pack_value (&bp
, edge
->indirect_inlining_edge
, 1);
270 bp_pack_value (&bp
, edge
->speculative
, 1);
271 bp_pack_value (&bp
, edge
->call_stmt_cannot_inline_p
, 1);
272 gcc_assert (!edge
->call_stmt_cannot_inline_p
273 || edge
->inline_failed
!= CIF_BODY_NOT_AVAILABLE
);
274 bp_pack_value (&bp
, edge
->can_throw_external
, 1);
275 bp_pack_value (&bp
, edge
->in_polymorphic_cdtor
, 1);
276 if (edge
->indirect_unknown_callee
)
278 int flags
= edge
->indirect_info
->ecf_flags
;
279 bp_pack_value (&bp
, (flags
& ECF_CONST
) != 0, 1);
280 bp_pack_value (&bp
, (flags
& ECF_PURE
) != 0, 1);
281 bp_pack_value (&bp
, (flags
& ECF_NORETURN
) != 0, 1);
282 bp_pack_value (&bp
, (flags
& ECF_MALLOC
) != 0, 1);
283 bp_pack_value (&bp
, (flags
& ECF_NOTHROW
) != 0, 1);
284 bp_pack_value (&bp
, (flags
& ECF_RETURNS_TWICE
) != 0, 1);
285 /* Flags that should not appear on indirect calls. */
286 gcc_assert (!(flags
& (ECF_LOOPING_CONST_OR_PURE
292 streamer_write_bitpack (&bp
);
293 if (edge
->indirect_unknown_callee
)
295 streamer_write_hwi_stream (ob
->main_stream
,
296 edge
->indirect_info
->common_target_id
);
297 if (edge
->indirect_info
->common_target_id
)
298 streamer_write_hwi_stream
299 (ob
->main_stream
, edge
->indirect_info
->common_target_probability
);
303 /* Return if NODE contain references from other partitions. */
306 referenced_from_other_partition_p (symtab_node
*node
, lto_symtab_encoder_t encoder
)
309 struct ipa_ref
*ref
= NULL
;
311 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
313 /* Ignore references from non-offloadable nodes while streaming NODE into
314 offload LTO section. */
315 if (!ref
->referring
->need_lto_streaming
)
318 if (ref
->referring
->in_other_partition
319 || !lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
325 /* Return true when node is reachable from other partition. */
328 reachable_from_other_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
330 struct cgraph_edge
*e
;
331 if (!node
->definition
)
333 if (node
->global
.inlined_to
)
335 for (e
= node
->callers
; e
; e
= e
->next_caller
)
337 /* Ignore references from non-offloadable nodes while streaming NODE into
338 offload LTO section. */
339 if (!e
->caller
->need_lto_streaming
)
342 if (e
->caller
->in_other_partition
343 || !lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
349 /* Return if NODE contain references from other partitions. */
352 referenced_from_this_partition_p (symtab_node
*node
,
353 lto_symtab_encoder_t encoder
)
356 struct ipa_ref
*ref
= NULL
;
358 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
359 if (lto_symtab_encoder_in_partition_p (encoder
, ref
->referring
))
364 /* Return true when node is reachable from other partition. */
367 reachable_from_this_partition_p (struct cgraph_node
*node
, lto_symtab_encoder_t encoder
)
369 struct cgraph_edge
*e
;
370 for (e
= node
->callers
; e
; e
= e
->next_caller
)
371 if (lto_symtab_encoder_in_partition_p (encoder
, e
->caller
))
376 /* Output the cgraph NODE to OB. ENCODER is used to find the
377 reference number of NODE->inlined_to. SET is the set of nodes we
378 are writing to the current file. If NODE is not in SET, then NODE
379 is a boundary of a cgraph_node_set and we pretend NODE just has a
380 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
381 that have had their callgraph node written so far. This is used to
382 determine if NODE is a clone of a previously written node. */
385 lto_output_node (struct lto_simple_output_block
*ob
, struct cgraph_node
*node
,
386 lto_symtab_encoder_t encoder
)
392 bool in_other_partition
= false;
393 struct cgraph_node
*clone_of
, *ultimate_clone_of
;
394 ipa_opt_pass_d
*pass
;
400 boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
402 if (node
->analyzed
&& (!boundary_p
|| node
->alias
403 || (node
->thunk
.thunk_p
&& !node
->global
.inlined_to
)))
404 tag
= LTO_symtab_analyzed_node
;
406 tag
= LTO_symtab_unavail_node
;
408 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
410 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
412 /* In WPA mode, we only output part of the call-graph. Also, we
413 fake cgraph node attributes. There are two cases that we care.
415 Boundary nodes: There are nodes that are not part of SET but are
416 called from within SET. We artificially make them look like
417 externally visible nodes with no function body.
419 Cherry-picked nodes: These are nodes we pulled from other
420 translation units into SET during IPA-inlining. We make them as
421 local static nodes to prevent clashes with other local statics. */
422 if (boundary_p
&& node
->analyzed
423 && node
->get_partitioning_class () == SYMBOL_PARTITION
)
425 /* Inline clones can not be part of boundary.
426 gcc_assert (!node->global.inlined_to);
428 FIXME: At the moment they can be, when partition contains an inline
429 clone that is clone of inline clone from outside partition. We can
430 reshape the clone tree and make other tree to be the root, but it
431 needs a bit extra work and will be promplty done by cgraph_remove_node
432 after reading back. */
433 in_other_partition
= 1;
436 clone_of
= node
->clone_of
;
438 && (ref
= lto_symtab_encoder_lookup (encoder
, clone_of
)) == LCC_NOT_FOUND
)
439 if (clone_of
->prev_sibling_clone
)
440 clone_of
= clone_of
->prev_sibling_clone
;
442 clone_of
= clone_of
->clone_of
;
444 /* See if body of the master function is output. If not, we are seeing only
445 an declaration and we do not need to pass down clone tree. */
446 ultimate_clone_of
= clone_of
;
447 while (ultimate_clone_of
&& ultimate_clone_of
->clone_of
)
448 ultimate_clone_of
= ultimate_clone_of
->clone_of
;
450 if (clone_of
&& !lto_symtab_encoder_encode_body_p (encoder
, ultimate_clone_of
))
453 if (tag
== LTO_symtab_analyzed_node
)
454 gcc_assert (clone_of
|| !node
->clone_of
);
456 streamer_write_hwi_stream (ob
->main_stream
, LCC_NOT_FOUND
);
458 streamer_write_hwi_stream (ob
->main_stream
, ref
);
461 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
462 node
->count
.stream_out (ob
->main_stream
);
463 streamer_write_hwi_stream (ob
->main_stream
, node
->count_materialization_scale
);
465 streamer_write_hwi_stream (ob
->main_stream
,
466 node
->ipa_transforms_to_apply
.length ());
467 FOR_EACH_VEC_ELT (node
->ipa_transforms_to_apply
, i
, pass
)
468 streamer_write_hwi_stream (ob
->main_stream
, pass
->static_pass_number
);
470 if (tag
== LTO_symtab_analyzed_node
)
472 if (node
->global
.inlined_to
)
474 ref
= lto_symtab_encoder_lookup (encoder
, node
->global
.inlined_to
);
475 gcc_assert (ref
!= LCC_NOT_FOUND
);
480 streamer_write_hwi_stream (ob
->main_stream
, ref
);
483 group
= node
->get_comdat_group ();
485 comdat
= IDENTIFIER_POINTER (group
);
488 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
492 if (node
->same_comdat_group
)
495 for (struct symtab_node
*n
= node
->same_comdat_group
;
496 ref
== LCC_NOT_FOUND
&& n
!= node
; n
= n
->same_comdat_group
)
497 ref
= lto_symtab_encoder_lookup (encoder
, n
);
501 streamer_write_hwi_stream (ob
->main_stream
, ref
);
504 section
= node
->get_section ();
508 streamer_write_hwi_stream (ob
->main_stream
, node
->tp_first_run
);
510 bp
= bitpack_create (ob
->main_stream
);
511 bp_pack_value (&bp
, node
->local
.local
, 1);
512 bp_pack_value (&bp
, node
->externally_visible
, 1);
513 bp_pack_value (&bp
, node
->no_reorder
, 1);
514 bp_pack_value (&bp
, node
->definition
, 1);
515 bp_pack_value (&bp
, node
->local
.versionable
, 1);
516 bp_pack_value (&bp
, node
->local
.can_change_signature
, 1);
517 bp_pack_value (&bp
, node
->local
.redefined_extern_inline
, 1);
518 bp_pack_value (&bp
, node
->force_output
, 1);
519 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
520 bp_pack_value (&bp
, node
->unique_name
, 1);
521 bp_pack_value (&bp
, node
->body_removed
, 1);
522 bp_pack_value (&bp
, node
->implicit_section
, 1);
523 bp_pack_value (&bp
, node
->address_taken
, 1);
524 bp_pack_value (&bp
, tag
== LTO_symtab_analyzed_node
525 && node
->get_partitioning_class () == SYMBOL_PARTITION
526 && (reachable_from_other_partition_p (node
, encoder
)
527 || referenced_from_other_partition_p (node
, encoder
)), 1);
528 bp_pack_value (&bp
, node
->lowered
, 1);
529 bp_pack_value (&bp
, in_other_partition
, 1);
530 bp_pack_value (&bp
, node
->alias
, 1);
531 bp_pack_value (&bp
, node
->transparent_alias
, 1);
532 bp_pack_value (&bp
, node
->weakref
, 1);
533 bp_pack_value (&bp
, node
->frequency
, 2);
534 bp_pack_value (&bp
, node
->only_called_at_startup
, 1);
535 bp_pack_value (&bp
, node
->only_called_at_exit
, 1);
536 bp_pack_value (&bp
, node
->tm_clone
, 1);
537 bp_pack_value (&bp
, node
->calls_comdat_local
, 1);
538 bp_pack_value (&bp
, node
->icf_merged
, 1);
539 bp_pack_value (&bp
, node
->nonfreeing_fn
, 1);
540 bp_pack_value (&bp
, node
->thunk
.thunk_p
, 1);
541 bp_pack_value (&bp
, node
->parallelized_function
, 1);
542 bp_pack_enum (&bp
, ld_plugin_symbol_resolution
,
543 LDPR_NUM_KNOWN
, node
->resolution
);
544 bp_pack_value (&bp
, node
->instrumentation_clone
, 1);
545 bp_pack_value (&bp
, node
->split_part
, 1);
546 streamer_write_bitpack (&bp
);
547 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
549 if (node
->thunk
.thunk_p
)
551 streamer_write_uhwi_stream
553 1 + (node
->thunk
.this_adjusting
!= 0) * 2
554 + (node
->thunk
.virtual_offset_p
!= 0) * 4
555 + (node
->thunk
.add_pointer_bounds_args
!= 0) * 8);
556 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.fixed_offset
);
557 streamer_write_uhwi_stream (ob
->main_stream
, node
->thunk
.virtual_value
);
559 streamer_write_hwi_stream (ob
->main_stream
, node
->profile_id
);
560 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
561 streamer_write_hwi_stream (ob
->main_stream
, node
->get_init_priority ());
562 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
563 streamer_write_hwi_stream (ob
->main_stream
, node
->get_fini_priority ());
565 if (node
->instrumentation_clone
)
566 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, node
->orig_decl
);
569 /* Output the varpool NODE to OB.
570 If NODE is not in SET, then NODE is a boundary. */
573 lto_output_varpool_node (struct lto_simple_output_block
*ob
, varpool_node
*node
,
574 lto_symtab_encoder_t encoder
)
576 bool boundary_p
= !lto_symtab_encoder_in_partition_p (encoder
, node
);
577 bool encode_initializer_p
579 && lto_symtab_encoder_encode_initializer_p (encoder
, node
));
586 gcc_assert (!encode_initializer_p
|| node
->definition
);
587 gcc_assert (boundary_p
|| encode_initializer_p
);
589 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
, LTO_symtab_last_tag
,
590 LTO_symtab_variable
);
591 streamer_write_hwi_stream (ob
->main_stream
, node
->order
);
592 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, node
->decl
);
593 bp
= bitpack_create (ob
->main_stream
);
594 bp_pack_value (&bp
, node
->externally_visible
, 1);
595 bp_pack_value (&bp
, node
->no_reorder
, 1);
596 bp_pack_value (&bp
, node
->force_output
, 1);
597 bp_pack_value (&bp
, node
->forced_by_abi
, 1);
598 bp_pack_value (&bp
, node
->unique_name
, 1);
601 || (!encode_initializer_p
&& !node
->alias
&& node
->definition
),
603 bp_pack_value (&bp
, node
->implicit_section
, 1);
604 bp_pack_value (&bp
, node
->writeonly
, 1);
605 bp_pack_value (&bp
, node
->definition
&& (encode_initializer_p
|| node
->alias
),
607 bp_pack_value (&bp
, node
->alias
, 1);
608 bp_pack_value (&bp
, node
->transparent_alias
, 1);
609 bp_pack_value (&bp
, node
->weakref
, 1);
610 bp_pack_value (&bp
, node
->analyzed
&& (!boundary_p
|| node
->alias
), 1);
611 gcc_assert (node
->definition
|| !node
->analyzed
);
612 /* Constant pool initializers can be de-unified into individual ltrans units.
613 FIXME: Alternatively at -Os we may want to avoid generating for them the local
614 labels and share them across LTRANS partitions. */
615 if (node
->get_partitioning_class () != SYMBOL_PARTITION
)
617 bp_pack_value (&bp
, 0, 1); /* used_from_other_parition. */
618 bp_pack_value (&bp
, 0, 1); /* in_other_partition. */
622 bp_pack_value (&bp
, node
->definition
623 && referenced_from_other_partition_p (node
, encoder
), 1);
624 bp_pack_value (&bp
, node
->analyzed
625 && boundary_p
&& !DECL_EXTERNAL (node
->decl
), 1);
626 /* in_other_partition. */
628 bp_pack_value (&bp
, node
->tls_model
, 3);
629 bp_pack_value (&bp
, node
->used_by_single_function
, 1);
630 bp_pack_value (&bp
, node
->dynamically_initialized
, 1);
631 bp_pack_value (&bp
, node
->need_bounds_init
, 1);
632 streamer_write_bitpack (&bp
);
634 group
= node
->get_comdat_group ();
636 comdat
= IDENTIFIER_POINTER (group
);
639 streamer_write_data_stream (ob
->main_stream
, comdat
, strlen (comdat
) + 1);
643 if (node
->same_comdat_group
)
646 for (struct symtab_node
*n
= node
->same_comdat_group
;
647 ref
== LCC_NOT_FOUND
&& n
!= node
; n
= n
->same_comdat_group
)
648 ref
= lto_symtab_encoder_lookup (encoder
, n
);
652 streamer_write_hwi_stream (ob
->main_stream
, ref
);
655 section
= node
->get_section ();
658 streamer_write_data_stream (ob
->main_stream
, section
, strlen (section
) + 1);
660 streamer_write_enum (ob
->main_stream
, ld_plugin_symbol_resolution
,
661 LDPR_NUM_KNOWN
, node
->resolution
);
664 /* Output the varpool NODE to OB.
665 If NODE is not in SET, then NODE is a boundary. */
668 lto_output_ref (struct lto_simple_output_block
*ob
, struct ipa_ref
*ref
,
669 lto_symtab_encoder_t encoder
)
673 int uid
= ref
->lto_stmt_uid
;
674 struct cgraph_node
*node
;
676 bp
= bitpack_create (ob
->main_stream
);
677 bp_pack_value (&bp
, ref
->use
, 3);
678 bp_pack_value (&bp
, ref
->speculative
, 1);
679 streamer_write_bitpack (&bp
);
680 nref
= lto_symtab_encoder_lookup (encoder
, ref
->referred
);
681 gcc_assert (nref
!= LCC_NOT_FOUND
);
682 streamer_write_hwi_stream (ob
->main_stream
, nref
);
684 node
= dyn_cast
<cgraph_node
*> (ref
->referring
);
688 uid
= gimple_uid (ref
->stmt
) + 1;
689 streamer_write_hwi_stream (ob
->main_stream
, uid
);
693 /* Stream out profile_summary to OB. */
696 output_profile_summary (struct lto_simple_output_block
*ob
)
703 /* We do not output num and run_max, they are not used by
704 GCC profile feedback and they are difficult to merge from multiple
706 gcc_assert (profile_info
->runs
);
707 streamer_write_uhwi_stream (ob
->main_stream
, profile_info
->runs
);
708 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_max
);
710 /* sum_all is needed for computing the working set with the
712 streamer_write_gcov_count_stream (ob
->main_stream
, profile_info
->sum_all
);
714 /* Create and output a bitpack of non-zero histogram entries indices. */
715 bp
= bitpack_create (ob
->main_stream
);
716 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
717 bp_pack_value (&bp
, profile_info
->histogram
[h_ix
].num_counters
> 0, 1);
718 streamer_write_bitpack (&bp
);
719 /* Now stream out only those non-zero entries. */
720 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
722 if (!profile_info
->histogram
[h_ix
].num_counters
)
724 streamer_write_gcov_count_stream (ob
->main_stream
,
725 profile_info
->histogram
[h_ix
].num_counters
);
726 streamer_write_gcov_count_stream (ob
->main_stream
,
727 profile_info
->histogram
[h_ix
].min_value
);
728 streamer_write_gcov_count_stream (ob
->main_stream
,
729 profile_info
->histogram
[h_ix
].cum_value
);
731 /* IPA-profile computes hot bb threshold based on cumulated
732 whole program profile. We need to stream it down to ltrans. */
734 streamer_write_gcov_count_stream (ob
->main_stream
,
735 get_hot_bb_threshold ());
738 streamer_write_uhwi_stream (ob
->main_stream
, 0);
741 /* Output all callees or indirect outgoing edges. EDGE must be the first such
745 output_outgoing_cgraph_edges (struct cgraph_edge
*edge
,
746 struct lto_simple_output_block
*ob
,
747 lto_symtab_encoder_t encoder
)
752 /* Output edges in backward direction, so the reconstructed callgraph match
753 and it is easy to associate call sites in the IPA pass summaries. */
754 while (edge
->next_callee
)
755 edge
= edge
->next_callee
;
756 for (; edge
; edge
= edge
->prev_callee
)
757 lto_output_edge (ob
, edge
, encoder
);
760 /* Output the part of the cgraph in SET. */
763 output_refs (lto_symtab_encoder_t encoder
)
765 struct lto_simple_output_block
*ob
;
769 ob
= lto_create_simple_output_block (LTO_section_refs
);
771 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
773 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
775 /* IPA_REF_ALIAS and IPA_REF_CHKP references are always preserved
776 in the boundary. Alias node can't have other references and
777 can be always handled as if it's not in the boundary. */
778 if (!node
->alias
&& !lto_symtab_encoder_in_partition_p (encoder
, node
))
780 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
781 /* Output IPA_REF_CHKP reference. */
783 && cnode
->instrumented_version
784 && !cnode
->instrumentation_clone
)
786 for (int i
= 0; node
->iterate_reference (i
, ref
); i
++)
787 if (ref
->use
== IPA_REF_CHKP
)
789 if (lto_symtab_encoder_lookup (encoder
, ref
->referred
)
792 int nref
= lto_symtab_encoder_lookup (encoder
, node
);
793 streamer_write_gcov_count_stream (ob
->main_stream
, 1);
794 streamer_write_uhwi_stream (ob
->main_stream
, nref
);
795 lto_output_ref (ob
, ref
, encoder
);
803 count
= node
->ref_list
.nreferences ();
806 streamer_write_gcov_count_stream (ob
->main_stream
, count
);
807 streamer_write_uhwi_stream (ob
->main_stream
,
808 lto_symtab_encoder_lookup (encoder
, node
));
809 for (int i
= 0; node
->iterate_reference (i
, ref
); i
++)
810 lto_output_ref (ob
, ref
, encoder
);
814 streamer_write_uhwi_stream (ob
->main_stream
, 0);
816 lto_destroy_simple_output_block (ob
);
819 /* Add NODE into encoder as well as nodes it is cloned from.
820 Do it in a way so clones appear first. */
823 add_node_to (lto_symtab_encoder_t encoder
, struct cgraph_node
*node
,
827 add_node_to (encoder
, node
->clone_of
, include_body
);
828 else if (include_body
)
829 lto_set_symtab_encoder_encode_body (encoder
, node
);
830 lto_symtab_encoder_encode (encoder
, node
);
833 /* Add all references in NODE to encoders. */
836 create_references (lto_symtab_encoder_t encoder
, symtab_node
*node
)
839 struct ipa_ref
*ref
= NULL
;
840 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
841 if (is_a
<cgraph_node
*> (ref
->referred
))
842 add_node_to (encoder
, dyn_cast
<cgraph_node
*> (ref
->referred
), false);
844 lto_symtab_encoder_encode (encoder
, ref
->referred
);
847 /* Select what needs to be streamed out. In regular lto mode stream everything.
848 In offload lto mode stream only nodes marked as offloadable. */
850 select_what_to_stream (void)
852 struct symtab_node
*snode
;
853 FOR_EACH_SYMBOL (snode
)
854 snode
->need_lto_streaming
= !lto_stream_offload_p
|| snode
->offloadable
;
857 /* Find all symbols we want to stream into given partition and insert them
860 The function actually replaces IN_ENCODER by new one. The reason is that
861 streaming code needs clone's origin to be streamed before clone. This
862 means that we need to insert the nodes in specific order. This order is
863 ignored by the partitioning logic earlier. */
866 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder
)
868 struct cgraph_edge
*edge
;
870 lto_symtab_encoder_t encoder
;
871 lto_symtab_encoder_iterator lsei
;
872 hash_set
<void *> reachable_call_targets
;
874 encoder
= lto_symtab_encoder_new (false);
876 /* Go over all entries in the IN_ENCODER and duplicate them to
877 ENCODER. At the same time insert masters of clones so
878 every master appears before clone. */
879 for (lsei
= lsei_start_function_in_partition (in_encoder
);
880 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
882 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
883 if (!node
->need_lto_streaming
)
885 add_node_to (encoder
, node
, true);
886 lto_set_symtab_encoder_in_partition (encoder
, node
);
887 create_references (encoder
, node
);
889 for (lsei
= lsei_start_variable_in_partition (in_encoder
);
890 !lsei_end_p (lsei
); lsei_next_variable_in_partition (&lsei
))
892 varpool_node
*vnode
= lsei_varpool_node (lsei
);
894 if (!vnode
->need_lto_streaming
)
896 lto_set_symtab_encoder_in_partition (encoder
, vnode
);
897 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
898 create_references (encoder
, vnode
);
900 /* Pickle in also the initializer of all referenced readonly variables
901 to help folding. Constant pool variables are not shared, so we must
903 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
905 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
906 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
908 if (!lto_symtab_encoder_encode_initializer_p (encoder
,
910 && (((vnode
->ctor_useable_for_folding_p ()
911 && (!DECL_VIRTUAL_P (vnode
->decl
)
913 || flag_ltrans_devirtualize
))
914 || POINTER_BOUNDS_P (vnode
->decl
))))
916 lto_set_symtab_encoder_encode_initializer (encoder
, vnode
);
917 create_references (encoder
, vnode
);
922 /* Go over all the nodes again to include callees that are not in
924 for (lsei
= lsei_start_function_in_partition (encoder
);
925 !lsei_end_p (lsei
); lsei_next_function_in_partition (&lsei
))
927 struct cgraph_node
*node
= lsei_cgraph_node (lsei
);
928 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
930 struct cgraph_node
*callee
= edge
->callee
;
931 if (!lto_symtab_encoder_in_partition_p (encoder
, callee
))
933 /* We should have moved all the inlines. */
934 gcc_assert (!callee
->global
.inlined_to
);
935 add_node_to (encoder
, callee
, false);
938 /* Add all possible targets for late devirtualization. */
939 if (flag_ltrans_devirtualize
|| !flag_wpa
)
940 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
941 if (edge
->indirect_info
->polymorphic
)
946 vec
<cgraph_node
*>targets
947 = possible_polymorphic_call_targets
948 (edge
, &final
, &cache_token
);
949 if (!reachable_call_targets
.add (cache_token
))
951 for (i
= 0; i
< targets
.length (); i
++)
953 struct cgraph_node
*callee
= targets
[i
];
955 /* Adding an external declarations into the unit serves
956 no purpose and just increases its boundary. */
957 if (callee
->definition
958 && !lto_symtab_encoder_in_partition_p
961 gcc_assert (!callee
->global
.inlined_to
);
962 add_node_to (encoder
, callee
, false);
968 /* Be sure to also insert alias targert and thunk callees. These needs
969 to stay to aid local calling conventions. */
970 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
972 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
973 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
975 if (node
->alias
&& node
->analyzed
)
976 create_references (encoder
, node
);
978 && cnode
->thunk
.thunk_p
&& !cnode
->global
.inlined_to
)
979 add_node_to (encoder
, cnode
->callees
->callee
, false);
980 while (node
->transparent_alias
&& node
->analyzed
)
982 node
= node
->get_alias_target ();
983 if (is_a
<cgraph_node
*> (node
))
984 add_node_to (encoder
, dyn_cast
<cgraph_node
*> (node
),
987 lto_symtab_encoder_encode (encoder
, node
);
990 lto_symtab_encoder_delete (in_encoder
);
994 /* Output the part of the symtab in SET and VSET. */
999 struct cgraph_node
*node
;
1000 struct lto_simple_output_block
*ob
;
1002 lto_symtab_encoder_t encoder
;
1005 output_cgraph_opt_summary ();
1007 ob
= lto_create_simple_output_block (LTO_section_symtab_nodes
);
1009 output_profile_summary (ob
);
1011 /* An encoder for cgraph nodes should have been created by
1012 ipa_write_summaries_1. */
1013 gcc_assert (ob
->decl_state
->symtab_node_encoder
);
1014 encoder
= ob
->decl_state
->symtab_node_encoder
;
1016 /* Write out the nodes. We must first output a node and then its clones,
1017 otherwise at a time reading back the node there would be nothing to clone
1019 n_nodes
= lto_symtab_encoder_size (encoder
);
1020 for (i
= 0; i
< n_nodes
; i
++)
1022 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
1023 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1024 lto_output_node (ob
, cnode
, encoder
);
1026 lto_output_varpool_node (ob
, dyn_cast
<varpool_node
*> (node
), encoder
);
1029 /* Go over the nodes in SET again to write edges. */
1030 for (int i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
1032 node
= dyn_cast
<cgraph_node
*> (lto_symtab_encoder_deref (encoder
, i
));
1034 && ((node
->thunk
.thunk_p
&& !node
->global
.inlined_to
)
1035 || lto_symtab_encoder_in_partition_p (encoder
, node
)))
1037 output_outgoing_cgraph_edges (node
->callees
, ob
, encoder
);
1038 output_outgoing_cgraph_edges (node
->indirect_calls
, ob
, encoder
);
1042 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1044 lto_destroy_simple_output_block (ob
);
1046 /* Emit toplevel asms.
1047 When doing WPA we must output every asm just once. Since we do not partition asm
1048 nodes at all, output them to first output. This is kind of hack, but should work
1050 if (!asm_nodes_output
)
1052 asm_nodes_output
= true;
1053 lto_output_toplevel_asms ();
1056 output_refs (encoder
);
1059 /* Return identifier encoded in IB as a plain string. */
1062 read_identifier (struct lto_input_block
*ib
)
1064 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1067 if (ib
->data
[ib
->p
+ len
])
1068 lto_section_overrun (ib
);
1074 id
= get_identifier (ib
->data
+ ib
->p
);
1079 /* Return string encoded in IB, NULL if string is empty. */
1082 read_string (struct lto_input_block
*ib
)
1084 unsigned int len
= strnlen (ib
->data
+ ib
->p
, ib
->len
- ib
->p
- 1);
1087 if (ib
->data
[ib
->p
+ len
])
1088 lto_section_overrun (ib
);
1094 str
= ib
->data
+ ib
->p
;
1099 /* Output function/variable tables that will allow libgomp to look up offload
1101 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1102 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1103 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1106 output_offload_tables (void)
1108 if (vec_safe_is_empty (offload_funcs
) && vec_safe_is_empty (offload_vars
))
1111 struct lto_simple_output_block
*ob
1112 = lto_create_simple_output_block (LTO_section_offload_table
);
1114 for (unsigned i
= 0; i
< vec_safe_length (offload_funcs
); i
++)
1116 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1117 LTO_symtab_last_tag
, LTO_symtab_unavail_node
);
1118 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
,
1119 (*offload_funcs
)[i
]);
1122 for (unsigned i
= 0; i
< vec_safe_length (offload_vars
); i
++)
1124 streamer_write_enum (ob
->main_stream
, LTO_symtab_tags
,
1125 LTO_symtab_last_tag
, LTO_symtab_variable
);
1126 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
,
1127 (*offload_vars
)[i
]);
1130 streamer_write_uhwi_stream (ob
->main_stream
, 0);
1131 lto_destroy_simple_output_block (ob
);
1133 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1134 streamed to one partition only. That's why we free offload_funcs and
1135 offload_vars after the first call of output_offload_tables. */
1138 vec_free (offload_funcs
);
1139 vec_free (offload_vars
);
1143 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1144 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1145 NODE or to replace the values in it, for instance because the first
1146 time we saw it, the function body was not available but now it
1147 is. BP is a bitpack with all the bitflags for NODE read from the
1151 input_overwrite_node (struct lto_file_decl_data
*file_data
,
1152 struct cgraph_node
*node
,
1153 enum LTO_symtab_tags tag
,
1154 struct bitpack_d
*bp
)
1156 node
->aux
= (void *) tag
;
1157 node
->lto_file_data
= file_data
;
1159 node
->local
.local
= bp_unpack_value (bp
, 1);
1160 node
->externally_visible
= bp_unpack_value (bp
, 1);
1161 node
->no_reorder
= bp_unpack_value (bp
, 1);
1162 node
->definition
= bp_unpack_value (bp
, 1);
1163 node
->local
.versionable
= bp_unpack_value (bp
, 1);
1164 node
->local
.can_change_signature
= bp_unpack_value (bp
, 1);
1165 node
->local
.redefined_extern_inline
= bp_unpack_value (bp
, 1);
1166 node
->force_output
= bp_unpack_value (bp
, 1);
1167 node
->forced_by_abi
= bp_unpack_value (bp
, 1);
1168 node
->unique_name
= bp_unpack_value (bp
, 1);
1169 node
->body_removed
= bp_unpack_value (bp
, 1);
1170 node
->implicit_section
= bp_unpack_value (bp
, 1);
1171 node
->address_taken
= bp_unpack_value (bp
, 1);
1172 node
->used_from_other_partition
= bp_unpack_value (bp
, 1);
1173 node
->lowered
= bp_unpack_value (bp
, 1);
1174 node
->analyzed
= tag
== LTO_symtab_analyzed_node
;
1175 node
->in_other_partition
= bp_unpack_value (bp
, 1);
1176 if (node
->in_other_partition
1177 /* Avoid updating decl when we are seeing just inline clone.
1178 When inlining function that has functions already inlined into it,
1179 we produce clones of inline clones.
1181 WPA partitioning might put each clone into different unit and
1182 we might end up streaming inline clone from other partition
1183 to support clone we are interested in. */
1185 || node
->clone_of
->decl
!= node
->decl
))
1187 DECL_EXTERNAL (node
->decl
) = 1;
1188 TREE_STATIC (node
->decl
) = 0;
1190 node
->alias
= bp_unpack_value (bp
, 1);
1191 node
->transparent_alias
= bp_unpack_value (bp
, 1);
1192 node
->weakref
= bp_unpack_value (bp
, 1);
1193 node
->frequency
= (enum node_frequency
)bp_unpack_value (bp
, 2);
1194 node
->only_called_at_startup
= bp_unpack_value (bp
, 1);
1195 node
->only_called_at_exit
= bp_unpack_value (bp
, 1);
1196 node
->tm_clone
= bp_unpack_value (bp
, 1);
1197 node
->calls_comdat_local
= bp_unpack_value (bp
, 1);
1198 node
->icf_merged
= bp_unpack_value (bp
, 1);
1199 node
->nonfreeing_fn
= bp_unpack_value (bp
, 1);
1200 node
->thunk
.thunk_p
= bp_unpack_value (bp
, 1);
1201 node
->parallelized_function
= bp_unpack_value (bp
, 1);
1202 node
->resolution
= bp_unpack_enum (bp
, ld_plugin_symbol_resolution
,
1204 node
->instrumentation_clone
= bp_unpack_value (bp
, 1);
1205 node
->split_part
= bp_unpack_value (bp
, 1);
1206 gcc_assert (flag_ltrans
1207 || (!node
->in_other_partition
1208 && !node
->used_from_other_partition
));
1211 /* Return string alias is alias of. */
1214 get_alias_symbol (tree decl
)
1216 tree alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
1217 return get_identifier (TREE_STRING_POINTER
1218 (TREE_VALUE (TREE_VALUE (alias
))));
1221 /* Read a node from input_block IB. TAG is the node's tag just read.
1222 Return the node read or overwriten. */
1224 static struct cgraph_node
*
1225 input_node (struct lto_file_decl_data
*file_data
,
1226 struct lto_input_block
*ib
,
1227 enum LTO_symtab_tags tag
,
1228 vec
<symtab_node
*> nodes
)
1230 gcc::pass_manager
*passes
= g
->get_passes ();
1232 struct cgraph_node
*node
;
1233 struct bitpack_d bp
;
1234 unsigned decl_index
;
1235 int ref
= LCC_NOT_FOUND
, ref2
= LCC_NOT_FOUND
;
1240 const char *section
;
1241 order
= streamer_read_hwi (ib
) + order_base
;
1242 clone_ref
= streamer_read_hwi (ib
);
1244 decl_index
= streamer_read_uhwi (ib
);
1245 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1247 if (clone_ref
!= LCC_NOT_FOUND
)
1249 node
= dyn_cast
<cgraph_node
*> (nodes
[clone_ref
])->create_clone (fn_decl
,
1250 profile_count::uninitialized (), false,
1251 vNULL
, false, NULL
, NULL
);
1255 /* Declaration of functions can be already merged with a declaration
1256 from other input file. We keep cgraph unmerged until after streaming
1257 of ipa passes is done. Alays forcingly create a fresh node. */
1258 node
= symtab
->create_empty ();
1259 node
->decl
= fn_decl
;
1260 node
->register_symbol ();
1263 node
->order
= order
;
1264 if (order
>= symtab
->order
)
1265 symtab
->order
= order
+ 1;
1267 node
->count
= profile_count::stream_in (ib
);
1268 node
->count_materialization_scale
= streamer_read_hwi (ib
);
1270 count
= streamer_read_hwi (ib
);
1271 node
->ipa_transforms_to_apply
= vNULL
;
1272 for (i
= 0; i
< count
; i
++)
1275 int pid
= streamer_read_hwi (ib
);
1277 gcc_assert (pid
< passes
->passes_by_id_size
);
1278 pass
= passes
->passes_by_id
[pid
];
1279 node
->ipa_transforms_to_apply
.safe_push ((ipa_opt_pass_d
*) pass
);
1282 if (tag
== LTO_symtab_analyzed_node
)
1283 ref
= streamer_read_hwi (ib
);
1285 group
= read_identifier (ib
);
1287 ref2
= streamer_read_hwi (ib
);
1289 /* Make sure that we have not read this node before. Nodes that
1290 have already been read will have their tag stored in the 'aux'
1291 field. Since built-in functions can be referenced in multiple
1292 functions, they are expected to be read more than once. */
1293 if (node
->aux
&& !DECL_BUILT_IN (node
->decl
))
1294 internal_error ("bytecode stream: found multiple instances of cgraph "
1295 "node with uid %d", node
->uid
);
1297 node
->tp_first_run
= streamer_read_uhwi (ib
);
1299 bp
= streamer_read_bitpack (ib
);
1301 input_overwrite_node (file_data
, node
, tag
, &bp
);
1303 /* Store a reference for now, and fix up later to be a pointer. */
1304 node
->global
.inlined_to
= (cgraph_node
*) (intptr_t) ref
;
1308 node
->set_comdat_group (group
);
1309 /* Store a reference for now, and fix up later to be a pointer. */
1310 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref2
;
1313 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1314 section
= read_string (ib
);
1316 node
->set_section_for_node (section
);
1318 if (node
->thunk
.thunk_p
)
1320 int type
= streamer_read_uhwi (ib
);
1321 HOST_WIDE_INT fixed_offset
= streamer_read_uhwi (ib
);
1322 HOST_WIDE_INT virtual_value
= streamer_read_uhwi (ib
);
1324 node
->thunk
.fixed_offset
= fixed_offset
;
1325 node
->thunk
.this_adjusting
= (type
& 2);
1326 node
->thunk
.virtual_value
= virtual_value
;
1327 node
->thunk
.virtual_offset_p
= (type
& 4);
1328 node
->thunk
.add_pointer_bounds_args
= (type
& 8);
1330 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1331 node
->alias_target
= get_alias_symbol (node
->decl
);
1332 node
->profile_id
= streamer_read_hwi (ib
);
1333 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
1334 node
->set_init_priority (streamer_read_hwi (ib
));
1335 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
1336 node
->set_fini_priority (streamer_read_hwi (ib
));
1338 if (node
->instrumentation_clone
)
1340 decl_index
= streamer_read_uhwi (ib
);
1341 fn_decl
= lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1342 node
->orig_decl
= fn_decl
;
1348 /* Read a node from input_block IB. TAG is the node's tag just read.
1349 Return the node read or overwriten. */
1351 static varpool_node
*
1352 input_varpool_node (struct lto_file_decl_data
*file_data
,
1353 struct lto_input_block
*ib
)
1358 struct bitpack_d bp
;
1359 int ref
= LCC_NOT_FOUND
;
1362 const char *section
;
1364 order
= streamer_read_hwi (ib
) + order_base
;
1365 decl_index
= streamer_read_uhwi (ib
);
1366 var_decl
= lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1368 /* Declaration of functions can be already merged with a declaration
1369 from other input file. We keep cgraph unmerged until after streaming
1370 of ipa passes is done. Alays forcingly create a fresh node. */
1371 node
= varpool_node::create_empty ();
1372 node
->decl
= var_decl
;
1373 node
->register_symbol ();
1375 node
->order
= order
;
1376 if (order
>= symtab
->order
)
1377 symtab
->order
= order
+ 1;
1378 node
->lto_file_data
= file_data
;
1380 bp
= streamer_read_bitpack (ib
);
1381 node
->externally_visible
= bp_unpack_value (&bp
, 1);
1382 node
->no_reorder
= bp_unpack_value (&bp
, 1);
1383 node
->force_output
= bp_unpack_value (&bp
, 1);
1384 node
->forced_by_abi
= bp_unpack_value (&bp
, 1);
1385 node
->unique_name
= bp_unpack_value (&bp
, 1);
1386 node
->body_removed
= bp_unpack_value (&bp
, 1);
1387 node
->implicit_section
= bp_unpack_value (&bp
, 1);
1388 node
->writeonly
= bp_unpack_value (&bp
, 1);
1389 node
->definition
= bp_unpack_value (&bp
, 1);
1390 node
->alias
= bp_unpack_value (&bp
, 1);
1391 node
->transparent_alias
= bp_unpack_value (&bp
, 1);
1392 node
->weakref
= bp_unpack_value (&bp
, 1);
1393 node
->analyzed
= bp_unpack_value (&bp
, 1);
1394 node
->used_from_other_partition
= bp_unpack_value (&bp
, 1);
1395 node
->in_other_partition
= bp_unpack_value (&bp
, 1);
1396 if (node
->in_other_partition
)
1398 DECL_EXTERNAL (node
->decl
) = 1;
1399 TREE_STATIC (node
->decl
) = 0;
1401 if (node
->alias
&& !node
->analyzed
&& node
->weakref
)
1402 node
->alias_target
= get_alias_symbol (node
->decl
);
1403 node
->tls_model
= (enum tls_model
)bp_unpack_value (&bp
, 3);
1404 node
->used_by_single_function
= (enum tls_model
)bp_unpack_value (&bp
, 1);
1405 node
->dynamically_initialized
= bp_unpack_value (&bp
, 1);
1406 node
->need_bounds_init
= bp_unpack_value (&bp
, 1);
1407 group
= read_identifier (ib
);
1410 node
->set_comdat_group (group
);
1411 ref
= streamer_read_hwi (ib
);
1412 /* Store a reference for now, and fix up later to be a pointer. */
1413 node
->same_comdat_group
= (symtab_node
*) (intptr_t) ref
;
1416 node
->same_comdat_group
= (symtab_node
*) (intptr_t) LCC_NOT_FOUND
;
1417 section
= read_string (ib
);
1419 node
->set_section_for_node (section
);
1420 node
->resolution
= streamer_read_enum (ib
, ld_plugin_symbol_resolution
,
1422 gcc_assert (flag_ltrans
1423 || (!node
->in_other_partition
1424 && !node
->used_from_other_partition
));
1429 /* Read a node from input_block IB. TAG is the node's tag just read.
1430 Return the node read or overwriten. */
1433 input_ref (struct lto_input_block
*ib
,
1434 symtab_node
*referring_node
,
1435 vec
<symtab_node
*> nodes
)
1437 symtab_node
*node
= NULL
;
1438 struct bitpack_d bp
;
1439 enum ipa_ref_use use
;
1441 struct ipa_ref
*ref
;
1443 bp
= streamer_read_bitpack (ib
);
1444 use
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 3);
1445 speculative
= (enum ipa_ref_use
) bp_unpack_value (&bp
, 1);
1446 node
= nodes
[streamer_read_hwi (ib
)];
1447 ref
= referring_node
->create_reference (node
, use
);
1448 ref
->speculative
= speculative
;
1449 if (is_a
<cgraph_node
*> (referring_node
))
1450 ref
->lto_stmt_uid
= streamer_read_hwi (ib
);
1453 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1454 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1455 edge being read is indirect (in the sense that it has
1456 indirect_unknown_callee set). */
1459 input_edge (struct lto_input_block
*ib
, vec
<symtab_node
*> nodes
,
1462 struct cgraph_node
*caller
, *callee
;
1463 struct cgraph_edge
*edge
;
1464 unsigned int stmt_id
;
1465 profile_count count
;
1466 cgraph_inline_failed_t inline_failed
;
1467 struct bitpack_d bp
;
1470 caller
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1471 if (caller
== NULL
|| caller
->decl
== NULL_TREE
)
1472 internal_error ("bytecode stream: no caller found while reading edge");
1476 callee
= dyn_cast
<cgraph_node
*> (nodes
[streamer_read_hwi (ib
)]);
1477 if (callee
== NULL
|| callee
->decl
== NULL_TREE
)
1478 internal_error ("bytecode stream: no callee found while reading edge");
1483 count
= profile_count::stream_in (ib
);
1485 bp
= streamer_read_bitpack (ib
);
1486 inline_failed
= bp_unpack_enum (&bp
, cgraph_inline_failed_t
, CIF_N_REASONS
);
1487 stmt_id
= bp_unpack_var_len_unsigned (&bp
);
1490 edge
= caller
->create_indirect_edge (NULL
, 0, count
);
1492 edge
= caller
->create_edge (callee
, NULL
, count
);
1494 edge
->indirect_inlining_edge
= bp_unpack_value (&bp
, 1);
1495 edge
->speculative
= bp_unpack_value (&bp
, 1);
1496 edge
->lto_stmt_uid
= stmt_id
;
1497 edge
->inline_failed
= inline_failed
;
1498 edge
->call_stmt_cannot_inline_p
= bp_unpack_value (&bp
, 1);
1499 edge
->can_throw_external
= bp_unpack_value (&bp
, 1);
1500 edge
->in_polymorphic_cdtor
= bp_unpack_value (&bp
, 1);
1503 if (bp_unpack_value (&bp
, 1))
1504 ecf_flags
|= ECF_CONST
;
1505 if (bp_unpack_value (&bp
, 1))
1506 ecf_flags
|= ECF_PURE
;
1507 if (bp_unpack_value (&bp
, 1))
1508 ecf_flags
|= ECF_NORETURN
;
1509 if (bp_unpack_value (&bp
, 1))
1510 ecf_flags
|= ECF_MALLOC
;
1511 if (bp_unpack_value (&bp
, 1))
1512 ecf_flags
|= ECF_NOTHROW
;
1513 if (bp_unpack_value (&bp
, 1))
1514 ecf_flags
|= ECF_RETURNS_TWICE
;
1515 edge
->indirect_info
->ecf_flags
= ecf_flags
;
1516 edge
->indirect_info
->common_target_id
= streamer_read_hwi (ib
);
1517 if (edge
->indirect_info
->common_target_id
)
1518 edge
->indirect_info
->common_target_probability
= streamer_read_hwi (ib
);
1523 /* Read a cgraph from IB using the info in FILE_DATA. */
1525 static vec
<symtab_node
*>
1526 input_cgraph_1 (struct lto_file_decl_data
*file_data
,
1527 struct lto_input_block
*ib
)
1529 enum LTO_symtab_tags tag
;
1530 vec
<symtab_node
*> nodes
= vNULL
;
1534 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1535 order_base
= symtab
->order
;
1538 if (tag
== LTO_symtab_edge
)
1539 input_edge (ib
, nodes
, false);
1540 else if (tag
== LTO_symtab_indirect_edge
)
1541 input_edge (ib
, nodes
, true);
1542 else if (tag
== LTO_symtab_variable
)
1544 node
= input_varpool_node (file_data
, ib
);
1545 nodes
.safe_push (node
);
1546 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1550 node
= input_node (file_data
, ib
, tag
, nodes
);
1551 if (node
== NULL
|| node
->decl
== NULL_TREE
)
1552 internal_error ("bytecode stream: found empty cgraph node");
1553 nodes
.safe_push (node
);
1554 lto_symtab_encoder_encode (file_data
->symtab_node_encoder
, node
);
1557 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1560 lto_input_toplevel_asms (file_data
, order_base
);
1562 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1565 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1566 gcc_assert (node
->aux
|| !is_a
<cgraph_node
*> (node
));
1568 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1571 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1573 ref
= (int) (intptr_t) cnode
->global
.inlined_to
;
1575 /* We share declaration of builtins, so we may read same node twice. */
1580 /* Fixup inlined_to from reference to pointer. */
1581 if (ref
!= LCC_NOT_FOUND
)
1582 dyn_cast
<cgraph_node
*> (node
)->global
.inlined_to
1583 = dyn_cast
<cgraph_node
*> (nodes
[ref
]);
1585 cnode
->global
.inlined_to
= NULL
;
1587 /* Compute instrumented_version. */
1588 if (cnode
->instrumentation_clone
)
1590 gcc_assert (cnode
->orig_decl
);
1592 cnode
->instrumented_version
= cgraph_node::get (cnode
->orig_decl
);
1593 if (cnode
->instrumented_version
)
1595 /* We may have multiple nodes for a single function which
1596 will be merged later. To have a proper merge we need
1597 to keep instrumentation_version reference between nodes
1598 consistent: each instrumented_version reference should
1599 have proper reverse reference. Thus don't break existing
1600 instrumented_version reference if it already exists. */
1601 if (cnode
->instrumented_version
->instrumented_version
)
1602 cnode
->instrumented_version
= NULL
;
1604 cnode
->instrumented_version
->instrumented_version
= cnode
;
1607 /* Restore decl names reference except for wrapper functions. */
1608 if (!chkp_wrap_function (cnode
->orig_decl
))
1610 tree name
= DECL_ASSEMBLER_NAME (cnode
->decl
);
1611 IDENTIFIER_TRANSPARENT_ALIAS (name
) = 1;
1612 TREE_CHAIN (name
) = DECL_ASSEMBLER_NAME (cnode
->orig_decl
);
1617 ref
= (int) (intptr_t) node
->same_comdat_group
;
1619 /* Fixup same_comdat_group from reference to pointer. */
1620 if (ref
!= LCC_NOT_FOUND
)
1621 node
->same_comdat_group
= nodes
[ref
];
1623 node
->same_comdat_group
= NULL
;
1625 FOR_EACH_VEC_ELT (nodes
, i
, node
)
1626 node
->aux
= is_a
<cgraph_node
*> (node
) ? (void *)1 : NULL
;
1630 /* Input ipa_refs. */
1633 input_refs (struct lto_input_block
*ib
,
1634 vec
<symtab_node
*> nodes
)
1641 count
= streamer_read_uhwi (ib
);
1644 idx
= streamer_read_uhwi (ib
);
1648 input_ref (ib
, node
, nodes
);
1655 static struct gcov_ctr_summary lto_gcov_summary
;
1657 /* Input profile_info from IB. */
1659 input_profile_summary (struct lto_input_block
*ib
,
1660 struct lto_file_decl_data
*file_data
)
1663 struct bitpack_d bp
;
1664 unsigned int runs
= streamer_read_uhwi (ib
);
1667 file_data
->profile_info
.runs
= runs
;
1668 file_data
->profile_info
.sum_max
= streamer_read_gcov_count (ib
);
1669 file_data
->profile_info
.sum_all
= streamer_read_gcov_count (ib
);
1671 memset (file_data
->profile_info
.histogram
, 0,
1672 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1673 /* Input the bitpack of non-zero histogram indices. */
1674 bp
= streamer_read_bitpack (ib
);
1675 /* Read in and unpack the full bitpack, flagging non-zero
1676 histogram entries by setting the num_counters non-zero. */
1677 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1679 file_data
->profile_info
.histogram
[h_ix
].num_counters
1680 = bp_unpack_value (&bp
, 1);
1682 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1684 if (!file_data
->profile_info
.histogram
[h_ix
].num_counters
)
1687 file_data
->profile_info
.histogram
[h_ix
].num_counters
1688 = streamer_read_gcov_count (ib
);
1689 file_data
->profile_info
.histogram
[h_ix
].min_value
1690 = streamer_read_gcov_count (ib
);
1691 file_data
->profile_info
.histogram
[h_ix
].cum_value
1692 = streamer_read_gcov_count (ib
);
1694 /* IPA-profile computes hot bb threshold based on cumulated
1695 whole program profile. We need to stream it down to ltrans. */
1697 set_hot_bb_threshold (streamer_read_gcov_count (ib
));
1702 /* Rescale profile summaries to the same number of runs in the whole unit. */
1705 merge_profile_summaries (struct lto_file_decl_data
**file_data_vec
)
1707 struct lto_file_decl_data
*file_data
;
1708 unsigned int j
, h_ix
;
1709 gcov_unsigned_t max_runs
= 0;
1710 struct cgraph_node
*node
;
1711 struct cgraph_edge
*edge
;
1712 gcov_type saved_sum_all
= 0;
1713 gcov_ctr_summary
*saved_profile_info
= 0;
1714 int saved_scale
= 0;
1716 /* Find unit with maximal number of runs. If we ever get serious about
1717 roundoff errors, we might also consider computing smallest common
1719 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1720 if (max_runs
< file_data
->profile_info
.runs
)
1721 max_runs
= file_data
->profile_info
.runs
;
1726 /* Simple overflow check. We probably don't need to support that many train
1727 runs. Such a large value probably imply data corruption anyway. */
1728 if (max_runs
> INT_MAX
/ REG_BR_PROB_BASE
)
1730 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1731 INT_MAX
/ REG_BR_PROB_BASE
);
1735 profile_info
= <o_gcov_summary
;
1736 lto_gcov_summary
.runs
= max_runs
;
1737 lto_gcov_summary
.sum_max
= 0;
1738 memset (lto_gcov_summary
.histogram
, 0,
1739 sizeof (gcov_bucket_type
) * GCOV_HISTOGRAM_SIZE
);
1741 /* Rescale all units to the maximal number of runs.
1742 sum_max can not be easily merged, as we have no idea what files come from
1743 the same run. We do not use the info anyway, so leave it 0. */
1744 for (j
= 0; (file_data
= file_data_vec
[j
]) != NULL
; j
++)
1745 if (file_data
->profile_info
.runs
)
1747 int scale
= GCOV_COMPUTE_SCALE (max_runs
,
1748 file_data
->profile_info
.runs
);
1749 lto_gcov_summary
.sum_max
1750 = MAX (lto_gcov_summary
.sum_max
,
1751 apply_scale (file_data
->profile_info
.sum_max
, scale
));
1752 lto_gcov_summary
.sum_all
1753 = MAX (lto_gcov_summary
.sum_all
,
1754 apply_scale (file_data
->profile_info
.sum_all
, scale
));
1755 /* Save a pointer to the profile_info with the largest
1756 scaled sum_all and the scale for use in merging the
1758 if (!saved_profile_info
1759 || lto_gcov_summary
.sum_all
> saved_sum_all
)
1761 saved_profile_info
= &file_data
->profile_info
;
1762 saved_sum_all
= lto_gcov_summary
.sum_all
;
1763 saved_scale
= scale
;
1767 gcc_assert (saved_profile_info
);
1769 /* Scale up the histogram from the profile that had the largest
1770 scaled sum_all above. */
1771 for (h_ix
= 0; h_ix
< GCOV_HISTOGRAM_SIZE
; h_ix
++)
1773 /* Scale up the min value as we did the corresponding sum_all
1774 above. Use that to find the new histogram index. */
1775 gcov_type scaled_min
1776 = apply_scale (saved_profile_info
->histogram
[h_ix
].min_value
,
1778 /* The new index may be shared with another scaled histogram entry,
1779 so we need to account for a non-zero histogram entry at new_ix. */
1780 unsigned new_ix
= gcov_histo_index (scaled_min
);
1781 lto_gcov_summary
.histogram
[new_ix
].min_value
1782 = (lto_gcov_summary
.histogram
[new_ix
].num_counters
1783 ? MIN (lto_gcov_summary
.histogram
[new_ix
].min_value
, scaled_min
)
1785 /* Some of the scaled counter values would ostensibly need to be placed
1786 into different (larger) histogram buckets, but we keep things simple
1787 here and place the scaled cumulative counter value in the bucket
1788 corresponding to the scaled minimum counter value. */
1789 lto_gcov_summary
.histogram
[new_ix
].cum_value
1790 += apply_scale (saved_profile_info
->histogram
[h_ix
].cum_value
,
1792 lto_gcov_summary
.histogram
[new_ix
].num_counters
1793 += saved_profile_info
->histogram
[h_ix
].num_counters
;
1796 /* Watch roundoff errors. */
1797 if (lto_gcov_summary
.sum_max
< max_runs
)
1798 lto_gcov_summary
.sum_max
= max_runs
;
1800 /* If merging already happent at WPA time, we are done. */
1804 /* Now compute count_materialization_scale of each node.
1805 During LTRANS we already have values of count_materialization_scale
1806 computed, so just update them. */
1807 FOR_EACH_FUNCTION (node
)
1808 if (node
->lto_file_data
1809 && node
->lto_file_data
->profile_info
.runs
)
1813 scale
= RDIV (node
->count_materialization_scale
* max_runs
,
1814 node
->lto_file_data
->profile_info
.runs
);
1815 node
->count_materialization_scale
= scale
;
1817 fatal_error (input_location
, "Profile information in %s corrupted",
1818 file_data
->file_name
);
1820 if (scale
== REG_BR_PROB_BASE
)
1822 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1823 if (edge
->count
.ipa ().nonzero_p ())
1824 edge
->count
= edge
->count
.apply_scale (scale
, REG_BR_PROB_BASE
);
1825 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
1826 if (edge
->count
.ipa ().nonzero_p ())
1827 edge
->count
= edge
->count
.apply_scale (scale
, REG_BR_PROB_BASE
);
1828 if (node
->count
.ipa ().nonzero_p ())
1829 node
->count
= node
->count
.apply_scale (scale
, REG_BR_PROB_BASE
);
1833 /* Input and merge the symtab from each of the .o files passed to
1839 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1840 struct lto_file_decl_data
*file_data
;
1842 struct cgraph_node
*node
;
1844 while ((file_data
= file_data_vec
[j
++]))
1848 struct lto_input_block
*ib
;
1849 vec
<symtab_node
*> nodes
;
1851 ib
= lto_create_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1854 fatal_error (input_location
,
1855 "cannot find LTO cgraph in %s", file_data
->file_name
);
1856 input_profile_summary (ib
, file_data
);
1857 file_data
->symtab_node_encoder
= lto_symtab_encoder_new (true);
1858 nodes
= input_cgraph_1 (file_data
, ib
);
1859 lto_destroy_simple_input_block (file_data
, LTO_section_symtab_nodes
,
1862 ib
= lto_create_simple_input_block (file_data
, LTO_section_refs
,
1865 fatal_error (input_location
, "cannot find LTO section refs in %s",
1866 file_data
->file_name
);
1867 input_refs (ib
, nodes
);
1868 lto_destroy_simple_input_block (file_data
, LTO_section_refs
,
1871 input_cgraph_opt_summary (nodes
);
1875 merge_profile_summaries (file_data_vec
);
1877 if (!flag_auto_profile
)
1878 get_working_sets ();
1881 /* Clear out the aux field that was used to store enough state to
1882 tell which nodes should be overwritten. */
1883 FOR_EACH_FUNCTION (node
)
1885 /* Some nodes may have been created by cgraph_node. This
1886 happens when the callgraph contains nested functions. If the
1887 node for the parent function was never emitted to the gimple
1888 file, cgraph_node will create a node for it when setting the
1889 context of the nested function. */
1890 if (node
->lto_file_data
)
1895 /* Input function/variable tables that will allow libgomp to look up offload
1896 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1899 input_offload_tables (bool do_force_output
)
1901 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
1902 struct lto_file_decl_data
*file_data
;
1905 while ((file_data
= file_data_vec
[j
++]))
1909 struct lto_input_block
*ib
1910 = lto_create_simple_input_block (file_data
, LTO_section_offload_table
,
1915 enum LTO_symtab_tags tag
1916 = streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1919 if (tag
== LTO_symtab_unavail_node
)
1921 int decl_index
= streamer_read_uhwi (ib
);
1923 = lto_file_decl_data_get_fn_decl (file_data
, decl_index
);
1924 vec_safe_push (offload_funcs
, fn_decl
);
1926 /* Prevent IPA from removing fn_decl as unreachable, since there
1927 may be no refs from the parent function to child_fn in offload
1929 if (do_force_output
)
1930 cgraph_node::get (fn_decl
)->mark_force_output ();
1932 else if (tag
== LTO_symtab_variable
)
1934 int decl_index
= streamer_read_uhwi (ib
);
1936 = lto_file_decl_data_get_var_decl (file_data
, decl_index
);
1937 vec_safe_push (offload_vars
, var_decl
);
1939 /* Prevent IPA from removing var_decl as unused, since there
1940 may be no refs to var_decl in offload LTO mode. */
1941 if (do_force_output
)
1942 varpool_node::get (var_decl
)->force_output
= 1;
1945 fatal_error (input_location
,
1946 "invalid offload table in %s", file_data
->file_name
);
1948 tag
= streamer_read_enum (ib
, LTO_symtab_tags
, LTO_symtab_last_tag
);
1951 lto_destroy_simple_input_block (file_data
, LTO_section_offload_table
,
1956 /* True when we need optimization summary for NODE. */
1959 output_cgraph_opt_summary_p (struct cgraph_node
*node
)
1961 return ((node
->clone_of
|| node
->former_clone_of
)
1962 && (node
->clone
.tree_map
1963 || node
->clone
.args_to_skip
1964 || node
->clone
.combined_args_to_skip
));
1967 /* Output optimization summary for EDGE to OB. */
1969 output_edge_opt_summary (struct output_block
*ob ATTRIBUTE_UNUSED
,
1970 struct cgraph_edge
*edge ATTRIBUTE_UNUSED
)
1974 /* Output optimization summary for NODE to OB. */
1977 output_node_opt_summary (struct output_block
*ob
,
1978 struct cgraph_node
*node
,
1979 lto_symtab_encoder_t encoder
)
1983 struct ipa_replace_map
*map
;
1984 struct bitpack_d bp
;
1986 struct cgraph_edge
*e
;
1988 if (node
->clone
.args_to_skip
)
1990 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.args_to_skip
));
1991 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.args_to_skip
, 0, index
, bi
)
1992 streamer_write_uhwi (ob
, index
);
1995 streamer_write_uhwi (ob
, 0);
1996 if (node
->clone
.combined_args_to_skip
)
1998 streamer_write_uhwi (ob
, bitmap_count_bits (node
->clone
.combined_args_to_skip
));
1999 EXECUTE_IF_SET_IN_BITMAP (node
->clone
.combined_args_to_skip
, 0, index
, bi
)
2000 streamer_write_uhwi (ob
, index
);
2003 streamer_write_uhwi (ob
, 0);
2004 streamer_write_uhwi (ob
, vec_safe_length (node
->clone
.tree_map
));
2005 FOR_EACH_VEC_SAFE_ELT (node
->clone
.tree_map
, i
, map
)
2007 /* At the moment we assume all old trees to be PARM_DECLs, because we have no
2008 mechanism to store function local declarations into summaries. */
2009 gcc_assert (!map
->old_tree
);
2010 streamer_write_uhwi (ob
, map
->parm_num
);
2011 gcc_assert (EXPR_LOCATION (map
->new_tree
) == UNKNOWN_LOCATION
);
2012 stream_write_tree (ob
, map
->new_tree
, true);
2013 bp
= bitpack_create (ob
->main_stream
);
2014 bp_pack_value (&bp
, map
->replace_p
, 1);
2015 bp_pack_value (&bp
, map
->ref_p
, 1);
2016 streamer_write_bitpack (&bp
);
2019 if (lto_symtab_encoder_in_partition_p (encoder
, node
))
2021 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2022 output_edge_opt_summary (ob
, e
);
2023 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2024 output_edge_opt_summary (ob
, e
);
2028 /* Output optimization summaries stored in callgraph.
2029 At the moment it is the clone info structure. */
2032 output_cgraph_opt_summary (void)
2035 lto_symtab_encoder_t encoder
;
2036 struct output_block
*ob
= create_output_block (LTO_section_cgraph_opt_sum
);
2040 encoder
= ob
->decl_state
->symtab_node_encoder
;
2041 n_nodes
= lto_symtab_encoder_size (encoder
);
2042 for (i
= 0; i
< n_nodes
; i
++)
2044 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2045 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2046 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2049 streamer_write_uhwi (ob
, count
);
2050 for (i
= 0; i
< n_nodes
; i
++)
2052 symtab_node
*node
= lto_symtab_encoder_deref (encoder
, i
);
2053 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
2054 if (cnode
&& output_cgraph_opt_summary_p (cnode
))
2056 streamer_write_uhwi (ob
, i
);
2057 output_node_opt_summary (ob
, cnode
, encoder
);
2060 produce_asm (ob
, NULL
);
2061 destroy_output_block (ob
);
2064 /* Input optimisation summary of EDGE. */
2067 input_edge_opt_summary (struct cgraph_edge
*edge ATTRIBUTE_UNUSED
,
2068 struct lto_input_block
*ib_main ATTRIBUTE_UNUSED
)
2072 /* Input optimisation summary of NODE. */
2075 input_node_opt_summary (struct cgraph_node
*node
,
2076 struct lto_input_block
*ib_main
,
2077 struct data_in
*data_in
)
2082 struct bitpack_d bp
;
2083 struct cgraph_edge
*e
;
2085 count
= streamer_read_uhwi (ib_main
);
2087 node
->clone
.args_to_skip
= BITMAP_GGC_ALLOC ();
2088 for (i
= 0; i
< count
; i
++)
2090 bit
= streamer_read_uhwi (ib_main
);
2091 bitmap_set_bit (node
->clone
.args_to_skip
, bit
);
2093 count
= streamer_read_uhwi (ib_main
);
2095 node
->clone
.combined_args_to_skip
= BITMAP_GGC_ALLOC ();
2096 for (i
= 0; i
< count
; i
++)
2098 bit
= streamer_read_uhwi (ib_main
);
2099 bitmap_set_bit (node
->clone
.combined_args_to_skip
, bit
);
2101 count
= streamer_read_uhwi (ib_main
);
2102 for (i
= 0; i
< count
; i
++)
2104 struct ipa_replace_map
*map
= ggc_alloc
<ipa_replace_map
> ();
2106 vec_safe_push (node
->clone
.tree_map
, map
);
2107 map
->parm_num
= streamer_read_uhwi (ib_main
);
2108 map
->old_tree
= NULL
;
2109 map
->new_tree
= stream_read_tree (ib_main
, data_in
);
2110 bp
= streamer_read_bitpack (ib_main
);
2111 map
->replace_p
= bp_unpack_value (&bp
, 1);
2112 map
->ref_p
= bp_unpack_value (&bp
, 1);
2114 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2115 input_edge_opt_summary (e
, ib_main
);
2116 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2117 input_edge_opt_summary (e
, ib_main
);
2120 /* Read section in file FILE_DATA of length LEN with data DATA. */
2123 input_cgraph_opt_section (struct lto_file_decl_data
*file_data
,
2124 const char *data
, size_t len
,
2125 vec
<symtab_node
*> nodes
)
2127 const struct lto_function_header
*header
=
2128 (const struct lto_function_header
*) data
;
2129 const int cfg_offset
= sizeof (struct lto_function_header
);
2130 const int main_offset
= cfg_offset
+ header
->cfg_size
;
2131 const int string_offset
= main_offset
+ header
->main_size
;
2132 struct data_in
*data_in
;
2136 lto_input_block
ib_main ((const char *) data
+ main_offset
,
2137 header
->main_size
, file_data
->mode_table
);
2140 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
2141 header
->string_size
, vNULL
);
2142 count
= streamer_read_uhwi (&ib_main
);
2144 for (i
= 0; i
< count
; i
++)
2146 int ref
= streamer_read_uhwi (&ib_main
);
2147 input_node_opt_summary (dyn_cast
<cgraph_node
*> (nodes
[ref
]),
2150 lto_free_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
, data
,
2152 lto_data_in_delete (data_in
);
2155 /* Input optimization summary of cgraph. */
2158 input_cgraph_opt_summary (vec
<symtab_node
*> nodes
)
2160 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
2161 struct lto_file_decl_data
*file_data
;
2164 while ((file_data
= file_data_vec
[j
++]))
2168 lto_get_section_data (file_data
, LTO_section_cgraph_opt_sum
, NULL
,
2172 input_cgraph_opt_section (file_data
, data
, len
, nodes
);