Skip gcc.dg/guality/example.c on hppa-linux.
[official-gcc.git] / gcc / lto-cgraph.c
blobef3c371c98fd9d18de3dbd3ad1a370a49c56f806
1 /* Write and read the cgraph to the memory mapped representation of a
2 .o file.
4 Copyright (C) 2009-2021 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
12 version.
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
17 for more details.
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/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "backend.h"
27 #include "rtl.h"
28 #include "tree.h"
29 #include "gimple.h"
30 #include "predict.h"
31 #include "stringpool.h"
32 #include "tree-streamer.h"
33 #include "cgraph.h"
34 #include "tree-pass.h"
35 #include "profile.h"
36 #include "context.h"
37 #include "pass_manager.h"
38 #include "ipa-utils.h"
39 #include "omp-offload.h"
40 #include "stringpool.h"
41 #include "attribs.h"
42 #include "alloc-pool.h"
43 #include "symbol-summary.h"
44 #include "symtab-thunks.h"
45 #include "symtab-clones.h"
47 /* True when asm nodes has been output. */
48 bool asm_nodes_output = false;
50 static void output_cgraph_opt_summary (void);
51 static void input_cgraph_opt_summary (vec<symtab_node *> nodes);
53 /* Number of LDPR values known to GCC. */
54 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
56 /* Cgraph streaming is organized as set of record whose type
57 is indicated by a tag. */
58 enum LTO_symtab_tags
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,
66 /* Cgraph edges. */
67 LTO_symtab_edge,
68 LTO_symtab_indirect_edge,
69 LTO_symtab_variable,
70 LTO_symtab_last_tag
73 /* Create a new symtab encoder.
74 if FOR_INPUT, the encoder allocate only datastructures needed
75 to read the symtab. */
77 lto_symtab_encoder_t
78 lto_symtab_encoder_new (bool for_input)
80 lto_symtab_encoder_t encoder = XCNEW (struct lto_symtab_encoder_d);
82 if (!for_input)
83 encoder->map = new hash_map<symtab_node *, size_t>;
84 encoder->nodes.create (0);
85 return encoder;
89 /* Delete ENCODER and its components. */
91 void
92 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder)
94 encoder->nodes.release ();
95 if (encoder->map)
96 delete encoder->map;
97 free (encoder);
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
103 NODE is encoded. */
106 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder,
107 symtab_node *node)
109 int ref;
111 if (!encoder->map)
113 lto_encoder_entry entry = {node, false, false, false};
115 ref = encoder->nodes.length ();
116 encoder->nodes.safe_push (entry);
117 return ref;
120 size_t *slot = encoder->map->get (node);
121 if (!slot || !*slot)
123 lto_encoder_entry entry = {node, false, false, false};
124 ref = encoder->nodes.length ();
125 if (!slot)
126 encoder->map->put (node, ref + 1);
127 encoder->nodes.safe_push (entry);
129 else
130 ref = *slot - 1;
132 return ref;
135 /* Remove NODE from encoder. */
137 bool
138 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder,
139 symtab_node *node)
141 int index;
142 lto_encoder_entry last_node;
144 size_t *slot = encoder->map->get (node);
145 if (slot == NULL || !*slot)
146 return false;
148 index = *slot - 1;
149 gcc_checking_assert (encoder->nodes[index].node == node);
151 /* Remove from vector. We do this by swapping node with the last element
152 of the vector. */
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);
164 return true;
168 /* Return TRUE if we should encode the body of NODE (if any). */
170 bool
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. */
180 static void
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). */
191 bool
192 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder,
193 varpool_node *node)
195 int index = lto_symtab_encoder_lookup (encoder, node);
196 if (index == LCC_NOT_FOUND)
197 return false;
198 return encoder->nodes[index].initializer;
201 /* Specify that we should encode initializer of NODE (if any). */
203 static void
204 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder,
205 varpool_node *node)
207 int index = lto_symtab_encoder_lookup (encoder, node);
208 encoder->nodes[index].initializer = true;
211 /* Return TRUE if NODE is in this partition. */
213 bool
214 lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder,
215 symtab_node *node)
217 int index = lto_symtab_encoder_lookup (encoder, node);
218 if (index == LCC_NOT_FOUND)
219 return false;
220 return encoder->nodes[index].in_partition;
223 /* Specify that NODE is in this partition. */
225 void
226 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder,
227 symtab_node *node)
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. */
235 static void
236 lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
237 lto_symtab_encoder_t encoder)
239 unsigned int uid;
240 intptr_t ref;
241 struct bitpack_d bp;
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);
246 else
247 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
248 LTO_symtab_edge);
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 = !edge->call_stmt ? edge->lto_stmt_uid
265 : gimple_uid (edge->call_stmt) + 1;
266 bp_pack_enum (&bp, cgraph_inline_failed_t,
267 CIF_N_REASONS, edge->inline_failed);
268 gcc_checking_assert (uid || edge->caller->thunk);
269 bp_pack_var_len_unsigned (&bp, uid);
270 bp_pack_value (&bp, edge->speculative_id, 16);
271 bp_pack_value (&bp, edge->indirect_inlining_edge, 1);
272 bp_pack_value (&bp, edge->speculative, 1);
273 bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1);
274 gcc_assert (!edge->call_stmt_cannot_inline_p
275 || edge->inline_failed != CIF_BODY_NOT_AVAILABLE);
276 bp_pack_value (&bp, edge->can_throw_external, 1);
277 bp_pack_value (&bp, edge->in_polymorphic_cdtor, 1);
278 if (edge->indirect_unknown_callee)
280 int flags = edge->indirect_info->ecf_flags;
281 bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1);
282 bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1);
283 bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1);
284 bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1);
285 bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1);
286 bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1);
287 /* Flags that should not appear on indirect calls. */
288 gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE
289 | ECF_MAY_BE_ALLOCA
290 | ECF_SIBCALL
291 | ECF_LEAF
292 | ECF_NOVOPS)));
294 bp_pack_value (&bp, edge->indirect_info->num_speculative_call_targets,
295 16);
297 streamer_write_bitpack (&bp);
300 /* Return if NODE contain references from other partitions. */
302 bool
303 referenced_from_other_partition_p (symtab_node *node, lto_symtab_encoder_t encoder)
305 int i;
306 struct ipa_ref *ref = NULL;
308 for (i = 0; node->iterate_referring (i, ref); i++)
310 /* Ignore references from non-offloadable nodes while streaming NODE into
311 offload LTO section. */
312 if (!ref->referring->need_lto_streaming)
313 continue;
315 if (ref->referring->in_other_partition
316 || !lto_symtab_encoder_in_partition_p (encoder, ref->referring))
317 return true;
319 return false;
322 /* Return true when node is reachable from other partition. */
324 bool
325 reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
327 struct cgraph_edge *e;
328 if (!node->definition)
329 return false;
330 if (node->inlined_to)
331 return false;
332 for (e = node->callers; e; e = e->next_caller)
334 /* Ignore references from non-offloadable nodes while streaming NODE into
335 offload LTO section. */
336 if (!e->caller->need_lto_streaming)
337 continue;
339 if (e->caller->in_other_partition
340 || !lto_symtab_encoder_in_partition_p (encoder, e->caller))
341 return true;
343 return false;
346 /* Return if NODE contain references from other partitions. */
348 bool
349 referenced_from_this_partition_p (symtab_node *node,
350 lto_symtab_encoder_t encoder)
352 int i;
353 struct ipa_ref *ref = NULL;
355 for (i = 0; node->iterate_referring (i, ref); i++)
356 if (lto_symtab_encoder_in_partition_p (encoder, ref->referring))
357 return true;
358 return false;
361 /* Return true when node is reachable from other partition. */
363 bool
364 reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
366 struct cgraph_edge *e;
367 for (e = node->callers; e; e = e->next_caller)
368 if (lto_symtab_encoder_in_partition_p (encoder, e->caller))
369 return true;
370 return false;
373 /* Output the cgraph NODE to OB. ENCODER is used to find the
374 reference number of NODE->inlined_to. SET is the set of nodes we
375 are writing to the current file. If NODE is not in SET, then NODE
376 is a boundary of a cgraph_node_set and we pretend NODE just has a
377 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
378 that have had their callgraph node written so far. This is used to
379 determine if NODE is a clone of a previously written node. */
381 static void
382 lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
383 lto_symtab_encoder_t encoder)
385 unsigned int tag;
386 struct bitpack_d bp;
387 bool boundary_p;
388 intptr_t ref;
389 bool in_other_partition = false;
390 struct cgraph_node *clone_of, *ultimate_clone_of;
391 ipa_opt_pass_d *pass;
392 int i;
393 const char *comdat;
394 const char *section;
395 tree group;
397 boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
399 if (node->analyzed && (!boundary_p || node->alias
400 || (node->thunk && !node->inlined_to)))
401 tag = LTO_symtab_analyzed_node;
402 else
403 tag = LTO_symtab_unavail_node;
405 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
406 tag);
407 streamer_write_hwi_stream (ob->main_stream, node->order);
409 /* In WPA mode, we only output part of the call-graph. Also, we
410 fake cgraph node attributes. There are two cases that we care.
412 Boundary nodes: There are nodes that are not part of SET but are
413 called from within SET. We artificially make them look like
414 externally visible nodes with no function body.
416 Cherry-picked nodes: These are nodes we pulled from other
417 translation units into SET during IPA-inlining. We make them as
418 local static nodes to prevent clashes with other local statics. */
419 if (boundary_p && node->analyzed
420 && node->get_partitioning_class () == SYMBOL_PARTITION)
422 /* Inline clones cannot be part of boundary.
423 gcc_assert (!node->inlined_to);
425 FIXME: At the moment they can be, when partition contains an inline
426 clone that is clone of inline clone from outside partition. We can
427 reshape the clone tree and make other tree to be the root, but it
428 needs a bit extra work and will be promplty done by cgraph_remove_node
429 after reading back. */
430 in_other_partition = 1;
433 clone_of = node->clone_of;
434 while (clone_of
435 && (ref = lto_symtab_encoder_lookup (encoder, clone_of)) == LCC_NOT_FOUND)
436 if (clone_of->prev_sibling_clone)
437 clone_of = clone_of->prev_sibling_clone;
438 else
439 clone_of = clone_of->clone_of;
441 /* See if body of the master function is output. If not, we are seeing only
442 an declaration and we do not need to pass down clone tree. */
443 ultimate_clone_of = clone_of;
444 while (ultimate_clone_of && ultimate_clone_of->clone_of)
445 ultimate_clone_of = ultimate_clone_of->clone_of;
447 if (clone_of && !lto_symtab_encoder_encode_body_p (encoder, ultimate_clone_of))
448 clone_of = NULL;
450 if (tag == LTO_symtab_analyzed_node)
451 gcc_assert (clone_of || !node->clone_of);
452 if (!clone_of)
453 streamer_write_hwi_stream (ob->main_stream, LCC_NOT_FOUND);
454 else
455 streamer_write_hwi_stream (ob->main_stream, ref);
458 lto_output_fn_decl_ref (ob->decl_state, ob->main_stream, node->decl);
459 node->count.stream_out (ob->main_stream);
460 streamer_write_hwi_stream (ob->main_stream, node->count_materialization_scale);
462 streamer_write_hwi_stream (ob->main_stream,
463 node->ipa_transforms_to_apply.length ());
464 FOR_EACH_VEC_ELT (node->ipa_transforms_to_apply, i, pass)
465 streamer_write_hwi_stream (ob->main_stream, pass->static_pass_number);
467 if (tag == LTO_symtab_analyzed_node)
469 if (node->inlined_to)
471 ref = lto_symtab_encoder_lookup (encoder, node->inlined_to);
472 gcc_assert (ref != LCC_NOT_FOUND);
474 else
475 ref = LCC_NOT_FOUND;
477 streamer_write_hwi_stream (ob->main_stream, ref);
480 group = node->get_comdat_group ();
481 if (group)
482 comdat = IDENTIFIER_POINTER (group);
483 else
484 comdat = "";
485 streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
487 if (group)
489 if (node->same_comdat_group)
491 ref = LCC_NOT_FOUND;
492 for (struct symtab_node *n = node->same_comdat_group;
493 ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
494 ref = lto_symtab_encoder_lookup (encoder, n);
496 else
497 ref = LCC_NOT_FOUND;
498 streamer_write_hwi_stream (ob->main_stream, ref);
501 section = node->get_section ();
502 if (!section)
503 section = "";
505 streamer_write_hwi_stream (ob->main_stream, node->tp_first_run);
507 bp = bitpack_create (ob->main_stream);
508 bp_pack_value (&bp, node->local, 1);
509 bp_pack_value (&bp, node->externally_visible, 1);
510 bp_pack_value (&bp, node->no_reorder, 1);
511 bp_pack_value (&bp, node->definition, 1);
512 bp_pack_value (&bp, node->versionable, 1);
513 bp_pack_value (&bp, node->can_change_signature, 1);
514 bp_pack_value (&bp, node->redefined_extern_inline, 1);
515 bp_pack_value (&bp, node->force_output, 1);
516 bp_pack_value (&bp, node->forced_by_abi, 1);
517 bp_pack_value (&bp, node->unique_name, 1);
518 bp_pack_value (&bp, node->body_removed, 1);
519 bp_pack_value (&bp, node->semantic_interposition, 1);
520 bp_pack_value (&bp, node->implicit_section, 1);
521 bp_pack_value (&bp, node->address_taken, 1);
522 bp_pack_value (&bp, tag == LTO_symtab_analyzed_node
523 && node->get_partitioning_class () == SYMBOL_PARTITION
524 && (reachable_from_other_partition_p (node, encoder)
525 || referenced_from_other_partition_p (node, encoder)), 1);
526 bp_pack_value (&bp, node->lowered, 1);
527 bp_pack_value (&bp, in_other_partition, 1);
528 bp_pack_value (&bp, node->alias, 1);
529 bp_pack_value (&bp, node->transparent_alias, 1);
530 bp_pack_value (&bp, node->weakref, 1);
531 bp_pack_value (&bp, node->symver, 1);
532 bp_pack_value (&bp, node->frequency, 2);
533 bp_pack_value (&bp, node->only_called_at_startup, 1);
534 bp_pack_value (&bp, node->only_called_at_exit, 1);
535 bp_pack_value (&bp, node->tm_clone, 1);
536 bp_pack_value (&bp, node->calls_comdat_local, 1);
537 bp_pack_value (&bp, node->icf_merged, 1);
538 bp_pack_value (&bp, node->nonfreeing_fn, 1);
539 bp_pack_value (&bp, node->merged_comdat, 1);
540 bp_pack_value (&bp, node->merged_extern_inline, 1);
541 bp_pack_value (&bp, node->thunk, 1);
542 bp_pack_value (&bp, node->parallelized_function, 1);
543 bp_pack_value (&bp, node->declare_variant_alt, 1);
544 bp_pack_value (&bp, node->calls_declare_variant_alt, 1);
546 /* Stream thunk info always because we use it in
547 ipa_polymorphic_call_context::ipa_polymorphic_call_context
548 to properly interpret THIS pointers for thunks that has been converted
549 to Gimple. */
550 struct thunk_info *thunk = node->definition ? thunk_info::get (node) : NULL;
552 bp_pack_value (&bp, thunk != NULL, 1);
554 bp_pack_enum (&bp, ld_plugin_symbol_resolution,
555 LDPR_NUM_KNOWN,
556 /* When doing incremental link, we will get new resolution
557 info next time we process the file. */
558 flag_incremental_link ? LDPR_UNKNOWN : node->resolution);
559 bp_pack_value (&bp, node->split_part, 1);
560 streamer_write_bitpack (&bp);
561 streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
563 streamer_write_hwi_stream (ob->main_stream, node->profile_id);
564 streamer_write_hwi_stream (ob->main_stream, node->unit_id);
565 if (DECL_STATIC_CONSTRUCTOR (node->decl))
566 streamer_write_hwi_stream (ob->main_stream, node->get_init_priority ());
567 if (DECL_STATIC_DESTRUCTOR (node->decl))
568 streamer_write_hwi_stream (ob->main_stream, node->get_fini_priority ());
570 if (thunk)
571 thunk_info::get (node)->stream_out (ob);
574 /* Output the varpool NODE to OB.
575 If NODE is not in SET, then NODE is a boundary. */
577 static void
578 lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node,
579 lto_symtab_encoder_t encoder)
581 bool boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
582 bool encode_initializer_p
583 = (node->definition
584 && lto_symtab_encoder_encode_initializer_p (encoder, node));
585 struct bitpack_d bp;
586 int ref;
587 const char *comdat;
588 const char *section;
589 tree group;
591 gcc_assert (!encode_initializer_p || node->definition);
592 gcc_assert (boundary_p || encode_initializer_p);
594 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
595 LTO_symtab_variable);
596 streamer_write_hwi_stream (ob->main_stream, node->order);
597 lto_output_var_decl_ref (ob->decl_state, ob->main_stream, node->decl);
598 bp = bitpack_create (ob->main_stream);
599 bp_pack_value (&bp, node->externally_visible, 1);
600 bp_pack_value (&bp, node->no_reorder, 1);
601 bp_pack_value (&bp, node->force_output, 1);
602 bp_pack_value (&bp, node->forced_by_abi, 1);
603 bp_pack_value (&bp, node->unique_name, 1);
604 bp_pack_value (&bp,
605 node->body_removed
606 || (!encode_initializer_p && !node->alias && node->definition),
608 bp_pack_value (&bp, node->semantic_interposition, 1);
609 bp_pack_value (&bp, node->implicit_section, 1);
610 bp_pack_value (&bp, node->writeonly, 1);
611 bp_pack_value (&bp, node->definition && (encode_initializer_p || node->alias),
613 bp_pack_value (&bp, node->alias, 1);
614 bp_pack_value (&bp, node->transparent_alias, 1);
615 bp_pack_value (&bp, node->weakref, 1);
616 bp_pack_value (&bp, node->symver, 1);
617 bp_pack_value (&bp, node->analyzed && (!boundary_p || node->alias), 1);
618 gcc_assert (node->definition || !node->analyzed);
619 /* Constant pool initializers can be de-unified into individual ltrans units.
620 FIXME: Alternatively at -Os we may want to avoid generating for them the local
621 labels and share them across LTRANS partitions. */
622 if (node->get_partitioning_class () != SYMBOL_PARTITION)
624 bp_pack_value (&bp, 0, 1); /* used_from_other_parition. */
625 bp_pack_value (&bp, 0, 1); /* in_other_partition. */
627 else
629 bp_pack_value (&bp, node->definition
630 && referenced_from_other_partition_p (node, encoder), 1);
631 bp_pack_value (&bp, node->analyzed
632 && boundary_p && !DECL_EXTERNAL (node->decl), 1);
633 /* in_other_partition. */
635 bp_pack_value (&bp, node->tls_model, 3);
636 bp_pack_value (&bp, node->used_by_single_function, 1);
637 bp_pack_value (&bp, node->dynamically_initialized, 1);
638 streamer_write_bitpack (&bp);
640 group = node->get_comdat_group ();
641 if (group)
642 comdat = IDENTIFIER_POINTER (group);
643 else
644 comdat = "";
645 streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
647 if (group)
649 if (node->same_comdat_group)
651 ref = LCC_NOT_FOUND;
652 for (struct symtab_node *n = node->same_comdat_group;
653 ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
654 ref = lto_symtab_encoder_lookup (encoder, n);
656 else
657 ref = LCC_NOT_FOUND;
658 streamer_write_hwi_stream (ob->main_stream, ref);
661 section = node->get_section ();
662 if (!section)
663 section = "";
664 streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
666 streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution,
667 LDPR_NUM_KNOWN, node->resolution);
670 /* Output the varpool NODE to OB.
671 If NODE is not in SET, then NODE is a boundary. */
673 static void
674 lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref,
675 lto_symtab_encoder_t encoder)
677 struct bitpack_d bp;
678 int nref;
679 int uid = !ref->stmt ? ref->lto_stmt_uid : gimple_uid (ref->stmt) + 1;
680 struct cgraph_node *node;
682 bp = bitpack_create (ob->main_stream);
683 bp_pack_value (&bp, ref->use, 3);
684 bp_pack_value (&bp, ref->speculative, 1);
685 streamer_write_bitpack (&bp);
686 nref = lto_symtab_encoder_lookup (encoder, ref->referred);
687 gcc_assert (nref != LCC_NOT_FOUND);
688 streamer_write_hwi_stream (ob->main_stream, nref);
690 node = dyn_cast <cgraph_node *> (ref->referring);
691 if (node)
693 if (ref->stmt)
694 uid = gimple_uid (ref->stmt) + 1;
695 streamer_write_hwi_stream (ob->main_stream, uid);
696 bp_pack_value (&bp, ref->speculative_id, 16);
697 streamer_write_bitpack (&bp);
701 /* Stream out profile_summary to OB. */
703 static void
704 output_profile_summary (struct lto_simple_output_block *ob)
706 if (profile_info)
708 /* We do not output num and run_max, they are not used by
709 GCC profile feedback and they are difficult to merge from multiple
710 units. */
711 unsigned runs = (profile_info->runs);
712 streamer_write_uhwi_stream (ob->main_stream, runs);
714 /* IPA-profile computes hot bb threshold based on cumulated
715 whole program profile. We need to stream it down to ltrans. */
716 if (flag_wpa)
717 streamer_write_gcov_count_stream (ob->main_stream,
718 get_hot_bb_threshold ());
720 else
721 streamer_write_uhwi_stream (ob->main_stream, 0);
724 /* Output all callees or indirect outgoing edges. EDGE must be the first such
725 edge. */
727 static void
728 output_outgoing_cgraph_edges (struct cgraph_edge *edge,
729 struct lto_simple_output_block *ob,
730 lto_symtab_encoder_t encoder)
732 if (!edge)
733 return;
735 /* Output edges in backward direction, so the reconstructed callgraph match
736 and it is easy to associate call sites in the IPA pass summaries. */
737 while (edge->next_callee)
738 edge = edge->next_callee;
739 for (; edge; edge = edge->prev_callee)
740 lto_output_edge (ob, edge, encoder);
743 /* Output the part of the cgraph in SET. */
745 static void
746 output_refs (lto_symtab_encoder_t encoder)
748 struct lto_simple_output_block *ob;
749 int count;
750 struct ipa_ref *ref;
752 ob = lto_create_simple_output_block (LTO_section_refs);
754 for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
756 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
758 /* IPA_REF_ALIAS references are always preserved
759 in the boundary. Alias node can't have other references and
760 can be always handled as if it's not in the boundary. */
761 if (!node->alias && !lto_symtab_encoder_in_partition_p (encoder, node))
762 continue;
764 count = node->ref_list.nreferences ();
765 if (count)
767 streamer_write_gcov_count_stream (ob->main_stream, count);
768 streamer_write_uhwi_stream (ob->main_stream,
769 lto_symtab_encoder_lookup (encoder, node));
770 for (int i = 0; node->iterate_reference (i, ref); i++)
771 lto_output_ref (ob, ref, encoder);
773 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
774 if (cnode->declare_variant_alt)
775 omp_lto_output_declare_variant_alt (ob, cnode, encoder);
778 streamer_write_uhwi_stream (ob->main_stream, 0);
780 lto_destroy_simple_output_block (ob);
783 /* Add NODE into encoder as well as nodes it is cloned from.
784 Do it in a way so clones appear first. */
786 static void
787 add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
788 bool include_body)
790 if (node->clone_of)
791 add_node_to (encoder, node->clone_of, include_body);
792 else if (include_body)
793 lto_set_symtab_encoder_encode_body (encoder, node);
794 lto_symtab_encoder_encode (encoder, node);
797 /* Add all references in NODE to encoders. */
799 static void
800 create_references (lto_symtab_encoder_t encoder, symtab_node *node)
802 int i;
803 struct ipa_ref *ref = NULL;
804 for (i = 0; node->iterate_reference (i, ref); i++)
805 if (is_a <cgraph_node *> (ref->referred))
806 add_node_to (encoder, dyn_cast <cgraph_node *> (ref->referred), false);
807 else
808 lto_symtab_encoder_encode (encoder, ref->referred);
811 /* Select what needs to be streamed out. In regular lto mode stream everything.
812 In offload lto mode stream only nodes marked as offloadable. */
813 void
814 select_what_to_stream (void)
816 struct symtab_node *snode;
817 FOR_EACH_SYMBOL (snode)
818 snode->need_lto_streaming = !lto_stream_offload_p || snode->offloadable;
821 /* Find all symbols we want to stream into given partition and insert them
822 to encoders.
824 The function actually replaces IN_ENCODER by new one. The reason is that
825 streaming code needs clone's origin to be streamed before clone. This
826 means that we need to insert the nodes in specific order. This order is
827 ignored by the partitioning logic earlier. */
829 lto_symtab_encoder_t
830 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
832 struct cgraph_edge *edge;
833 int i;
834 lto_symtab_encoder_t encoder;
835 lto_symtab_encoder_iterator lsei;
836 hash_set<void *> reachable_call_targets;
838 encoder = lto_symtab_encoder_new (false);
840 /* Go over all entries in the IN_ENCODER and duplicate them to
841 ENCODER. At the same time insert masters of clones so
842 every master appears before clone. */
843 for (lsei = lsei_start_function_in_partition (in_encoder);
844 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
846 struct cgraph_node *node = lsei_cgraph_node (lsei);
847 if (!node->need_lto_streaming)
848 continue;
849 add_node_to (encoder, node, true);
850 lto_set_symtab_encoder_in_partition (encoder, node);
851 create_references (encoder, node);
853 for (lsei = lsei_start_variable_in_partition (in_encoder);
854 !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei))
856 varpool_node *vnode = lsei_varpool_node (lsei);
858 if (!vnode->need_lto_streaming)
859 continue;
860 lto_set_symtab_encoder_in_partition (encoder, vnode);
861 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
862 create_references (encoder, vnode);
864 /* Pickle in also the initializer of all referenced readonly variables
865 to help folding. Constant pool variables are not shared, so we must
866 pickle those too. */
867 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
869 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
870 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
872 if (!lto_symtab_encoder_encode_initializer_p (encoder,
873 vnode)
874 && (((vnode->ctor_useable_for_folding_p ()
875 && (!DECL_VIRTUAL_P (vnode->decl)
876 || !flag_wpa
877 || flag_ltrans_devirtualize)))))
879 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
880 create_references (encoder, vnode);
885 /* Go over all the nodes again to include callees that are not in
886 SET. */
887 for (lsei = lsei_start_function_in_partition (encoder);
888 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
890 struct cgraph_node *node = lsei_cgraph_node (lsei);
891 for (edge = node->callees; edge; edge = edge->next_callee)
893 struct cgraph_node *callee = edge->callee;
894 if (!lto_symtab_encoder_in_partition_p (encoder, callee))
896 /* We should have moved all the inlines. */
897 gcc_assert (!callee->inlined_to);
898 add_node_to (encoder, callee, false);
901 /* Add all possible targets for late devirtualization. */
902 if (flag_ltrans_devirtualize || !flag_wpa)
903 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
904 if (edge->indirect_info->polymorphic)
906 unsigned int i;
907 void *cache_token;
908 bool final;
909 vec <cgraph_node *>targets
910 = possible_polymorphic_call_targets
911 (edge, &final, &cache_token);
912 if (!reachable_call_targets.add (cache_token))
914 for (i = 0; i < targets.length (); i++)
916 struct cgraph_node *callee = targets[i];
918 /* Adding an external declarations into the unit serves
919 no purpose and just increases its boundary. */
920 if (callee->definition
921 && !lto_symtab_encoder_in_partition_p
922 (encoder, callee))
924 gcc_assert (!callee->inlined_to);
925 add_node_to (encoder, callee, false);
931 /* Be sure to also insert alias targert and thunk callees. These needs
932 to stay to aid local calling conventions. */
933 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
935 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
936 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
938 if (node->alias && node->analyzed)
939 create_references (encoder, node);
940 if (cnode
941 && cnode->thunk && !cnode->inlined_to)
942 add_node_to (encoder, cnode->callees->callee, false);
943 while (node->transparent_alias && node->analyzed)
945 node = node->get_alias_target ();
946 if (is_a <cgraph_node *> (node))
947 add_node_to (encoder, dyn_cast <cgraph_node *> (node),
948 false);
949 else
950 lto_symtab_encoder_encode (encoder, node);
953 lto_symtab_encoder_delete (in_encoder);
954 return encoder;
957 /* Output the part of the symtab in SET and VSET. */
959 void
960 output_symtab (void)
962 struct cgraph_node *node;
963 struct lto_simple_output_block *ob;
964 int i, n_nodes;
965 lto_symtab_encoder_t encoder;
967 if (flag_wpa)
968 output_cgraph_opt_summary ();
970 ob = lto_create_simple_output_block (LTO_section_symtab_nodes);
972 output_profile_summary (ob);
974 /* An encoder for cgraph nodes should have been created by
975 ipa_write_summaries_1. */
976 gcc_assert (ob->decl_state->symtab_node_encoder);
977 encoder = ob->decl_state->symtab_node_encoder;
979 /* Write out the nodes. We must first output a node and then its clones,
980 otherwise at a time reading back the node there would be nothing to clone
981 from. */
982 n_nodes = lto_symtab_encoder_size (encoder);
983 for (i = 0; i < n_nodes; i++)
985 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
986 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
987 lto_output_node (ob, cnode, encoder);
988 else
989 lto_output_varpool_node (ob, dyn_cast<varpool_node *> (node), encoder);
992 /* Go over the nodes in SET again to write edges. */
993 for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
995 node = dyn_cast <cgraph_node *> (lto_symtab_encoder_deref (encoder, i));
996 if (node
997 && ((node->thunk && !node->inlined_to)
998 || lto_symtab_encoder_in_partition_p (encoder, node)))
1000 output_outgoing_cgraph_edges (node->callees, ob, encoder);
1001 output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
1005 streamer_write_uhwi_stream (ob->main_stream, 0);
1007 lto_destroy_simple_output_block (ob);
1009 /* Emit toplevel asms.
1010 When doing WPA we must output every asm just once. Since we do not partition asm
1011 nodes at all, output them to first output. This is kind of hack, but should work
1012 well. */
1013 if (!asm_nodes_output)
1015 asm_nodes_output = true;
1016 lto_output_toplevel_asms ();
1019 output_refs (encoder);
1022 /* Return identifier encoded in IB as a plain string. */
1024 static tree
1025 read_identifier (class lto_input_block *ib)
1027 unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
1028 tree id;
1030 if (ib->data[ib->p + len])
1031 lto_section_overrun (ib);
1032 if (!len)
1034 ib->p++;
1035 return NULL;
1037 id = get_identifier (ib->data + ib->p);
1038 ib->p += len + 1;
1039 return id;
1042 /* Return string encoded in IB, NULL if string is empty. */
1044 static const char *
1045 read_string (class lto_input_block *ib)
1047 unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
1048 const char *str;
1050 if (ib->data[ib->p + len])
1051 lto_section_overrun (ib);
1052 if (!len)
1054 ib->p++;
1055 return NULL;
1057 str = ib->data + ib->p;
1058 ib->p += len + 1;
1059 return str;
1062 /* Output function/variable tables that will allow libgomp to look up offload
1063 target code.
1064 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1065 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1066 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1068 void
1069 output_offload_tables (void)
1071 if (vec_safe_is_empty (offload_funcs) && vec_safe_is_empty (offload_vars))
1072 return;
1074 struct lto_simple_output_block *ob
1075 = lto_create_simple_output_block (LTO_section_offload_table);
1077 for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++)
1079 symtab_node *node = symtab_node::get ((*offload_funcs)[i]);
1080 if (!node)
1081 continue;
1082 node->force_output = true;
1083 streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1084 LTO_symtab_last_tag, LTO_symtab_unavail_node);
1085 lto_output_fn_decl_ref (ob->decl_state, ob->main_stream,
1086 (*offload_funcs)[i]);
1089 for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
1091 symtab_node *node = symtab_node::get ((*offload_vars)[i]);
1092 if (!node)
1093 continue;
1094 node->force_output = true;
1095 streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1096 LTO_symtab_last_tag, LTO_symtab_variable);
1097 lto_output_var_decl_ref (ob->decl_state, ob->main_stream,
1098 (*offload_vars)[i]);
1101 streamer_write_uhwi_stream (ob->main_stream, 0);
1102 lto_destroy_simple_output_block (ob);
1104 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1105 streamed to one partition only. That's why we free offload_funcs and
1106 offload_vars after the first call of output_offload_tables. */
1107 if (flag_wpa)
1109 vec_free (offload_funcs);
1110 vec_free (offload_vars);
1114 /* Verify the partitioning of NODE. */
1116 static inline void
1117 verify_node_partition (symtab_node *node)
1119 if (flag_ltrans)
1120 return;
1122 #ifdef ACCEL_COMPILER
1123 if (node->in_other_partition)
1125 if (TREE_CODE (node->decl) == FUNCTION_DECL)
1126 error_at (DECL_SOURCE_LOCATION (node->decl),
1127 "function %qs has been referenced in offloaded code but"
1128 " hasn%'t been marked to be included in the offloaded code",
1129 node->name ());
1130 else if (VAR_P (node->decl))
1131 error_at (DECL_SOURCE_LOCATION (node->decl),
1132 "variable %qs has been referenced in offloaded code but"
1133 " hasn%'t been marked to be included in the offloaded code",
1134 node->name ());
1135 else
1136 gcc_unreachable ();
1138 #else
1139 gcc_assert (!node->in_other_partition
1140 && !node->used_from_other_partition);
1141 #endif
1144 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1145 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1146 NODE or to replace the values in it, for instance because the first
1147 time we saw it, the function body was not available but now it
1148 is. BP is a bitpack with all the bitflags for NODE read from the
1149 stream. Initialize HAS_THUNK_INFO to indicate if thunk info should
1150 be streamed in. */
1152 static void
1153 input_overwrite_node (struct lto_file_decl_data *file_data,
1154 struct cgraph_node *node,
1155 enum LTO_symtab_tags tag,
1156 struct bitpack_d *bp, bool *has_thunk_info)
1158 node->aux = (void *) tag;
1159 node->lto_file_data = file_data;
1161 node->local = bp_unpack_value (bp, 1);
1162 node->externally_visible = bp_unpack_value (bp, 1);
1163 node->no_reorder = bp_unpack_value (bp, 1);
1164 node->definition = bp_unpack_value (bp, 1);
1165 node->versionable = bp_unpack_value (bp, 1);
1166 node->can_change_signature = bp_unpack_value (bp, 1);
1167 node->redefined_extern_inline = bp_unpack_value (bp, 1);
1168 node->force_output = bp_unpack_value (bp, 1);
1169 node->forced_by_abi = bp_unpack_value (bp, 1);
1170 node->unique_name = bp_unpack_value (bp, 1);
1171 node->body_removed = bp_unpack_value (bp, 1);
1172 node->semantic_interposition = bp_unpack_value (bp, 1);
1173 node->implicit_section = bp_unpack_value (bp, 1);
1174 node->address_taken = bp_unpack_value (bp, 1);
1175 node->used_from_other_partition = bp_unpack_value (bp, 1);
1176 node->lowered = bp_unpack_value (bp, 1);
1177 node->analyzed = tag == LTO_symtab_analyzed_node;
1178 node->in_other_partition = bp_unpack_value (bp, 1);
1179 if (node->in_other_partition
1180 /* Avoid updating decl when we are seeing just inline clone.
1181 When inlining function that has functions already inlined into it,
1182 we produce clones of inline clones.
1184 WPA partitioning might put each clone into different unit and
1185 we might end up streaming inline clone from other partition
1186 to support clone we are interested in. */
1187 && (!node->clone_of
1188 || node->clone_of->decl != node->decl))
1190 DECL_EXTERNAL (node->decl) = 1;
1191 TREE_STATIC (node->decl) = 0;
1193 node->alias = bp_unpack_value (bp, 1);
1194 node->transparent_alias = bp_unpack_value (bp, 1);
1195 node->weakref = bp_unpack_value (bp, 1);
1196 node->symver = bp_unpack_value (bp, 1);
1197 node->frequency = (enum node_frequency)bp_unpack_value (bp, 2);
1198 node->only_called_at_startup = bp_unpack_value (bp, 1);
1199 node->only_called_at_exit = bp_unpack_value (bp, 1);
1200 node->tm_clone = bp_unpack_value (bp, 1);
1201 node->calls_comdat_local = bp_unpack_value (bp, 1);
1202 node->icf_merged = bp_unpack_value (bp, 1);
1203 node->nonfreeing_fn = bp_unpack_value (bp, 1);
1204 node->merged_comdat = bp_unpack_value (bp, 1);
1205 node->merged_extern_inline = bp_unpack_value (bp, 1);
1206 node->thunk = bp_unpack_value (bp, 1);
1207 node->parallelized_function = bp_unpack_value (bp, 1);
1208 node->declare_variant_alt = bp_unpack_value (bp, 1);
1209 node->calls_declare_variant_alt = bp_unpack_value (bp, 1);
1210 *has_thunk_info = bp_unpack_value (bp, 1);
1211 node->resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution,
1212 LDPR_NUM_KNOWN);
1213 node->split_part = bp_unpack_value (bp, 1);
1214 verify_node_partition (node);
1217 /* Return string alias is alias of. */
1219 static tree
1220 get_alias_symbol (tree decl)
1222 tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1223 return get_identifier (TREE_STRING_POINTER
1224 (TREE_VALUE (TREE_VALUE (alias))));
1227 /* Read a node from input_block IB. TAG is the node's tag just read.
1228 Return the node read or overwriten. */
1230 static struct cgraph_node *
1231 input_node (struct lto_file_decl_data *file_data,
1232 class lto_input_block *ib,
1233 enum LTO_symtab_tags tag,
1234 vec<symtab_node *> nodes)
1236 gcc::pass_manager *passes = g->get_passes ();
1237 tree fn_decl;
1238 struct cgraph_node *node;
1239 struct bitpack_d bp;
1240 int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND;
1241 int clone_ref;
1242 int order;
1243 int i, count;
1244 tree group;
1245 const char *section;
1246 order = streamer_read_hwi (ib) + file_data->order_base;
1247 clone_ref = streamer_read_hwi (ib);
1248 bool has_thunk_info;
1250 fn_decl = lto_input_fn_decl_ref (ib, file_data);
1252 if (clone_ref != LCC_NOT_FOUND)
1254 node = dyn_cast<cgraph_node *> (nodes[clone_ref])->create_clone (fn_decl,
1255 profile_count::uninitialized (), false,
1256 vNULL, false, NULL, NULL);
1258 else
1260 /* Declaration of functions can be already merged with a declaration
1261 from other input file. We keep cgraph unmerged until after streaming
1262 of ipa passes is done. Alays forcingly create a fresh node. */
1263 node = symtab->create_empty ();
1264 node->decl = fn_decl;
1265 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (fn_decl)))
1266 node->ifunc_resolver = 1;
1267 node->register_symbol ();
1270 node->order = order;
1271 if (order >= symtab->order)
1272 symtab->order = order + 1;
1274 node->count = profile_count::stream_in (ib);
1275 node->count_materialization_scale = streamer_read_hwi (ib);
1277 count = streamer_read_hwi (ib);
1278 node->ipa_transforms_to_apply = vNULL;
1279 for (i = 0; i < count; i++)
1281 opt_pass *pass;
1282 int pid = streamer_read_hwi (ib);
1284 gcc_assert (pid < passes->passes_by_id_size);
1285 pass = passes->passes_by_id[pid];
1286 node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *) pass);
1289 if (tag == LTO_symtab_analyzed_node)
1290 ref = streamer_read_hwi (ib);
1292 group = read_identifier (ib);
1293 if (group)
1294 ref2 = streamer_read_hwi (ib);
1296 /* Make sure that we have not read this node before. Nodes that
1297 have already been read will have their tag stored in the 'aux'
1298 field. Since built-in functions can be referenced in multiple
1299 functions, they are expected to be read more than once. */
1300 if (node->aux && !fndecl_built_in_p (node->decl))
1301 internal_error ("bytecode stream: found multiple instances of cgraph "
1302 "node with uid %d", node->get_uid ());
1304 node->tp_first_run = streamer_read_uhwi (ib);
1306 bp = streamer_read_bitpack (ib);
1308 input_overwrite_node (file_data, node, tag, &bp, &has_thunk_info);
1310 /* Store a reference for now, and fix up later to be a pointer. */
1311 node->inlined_to = (cgraph_node *) (intptr_t) ref;
1313 if (group)
1315 node->set_comdat_group (group);
1316 /* Store a reference for now, and fix up later to be a pointer. */
1317 node->same_comdat_group = (symtab_node *) (intptr_t) ref2;
1319 else
1320 node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
1321 section = read_string (ib);
1322 if (section)
1323 node->set_section_for_node (section);
1325 if (node->alias && !node->analyzed && node->weakref)
1326 node->alias_target = get_alias_symbol (node->decl);
1327 node->profile_id = streamer_read_hwi (ib);
1328 node->unit_id = streamer_read_hwi (ib) + file_data->unit_base;
1329 if (symtab->max_unit < node->unit_id)
1330 symtab->max_unit = node->unit_id;
1331 if (DECL_STATIC_CONSTRUCTOR (node->decl))
1332 node->set_init_priority (streamer_read_hwi (ib));
1333 if (DECL_STATIC_DESTRUCTOR (node->decl))
1334 node->set_fini_priority (streamer_read_hwi (ib));
1336 if (has_thunk_info)
1337 thunk_info::get_create (node)->stream_in (ib);
1339 return node;
1342 /* Read a node from input_block IB. TAG is the node's tag just read.
1343 Return the node read or overwriten. */
1345 static varpool_node *
1346 input_varpool_node (struct lto_file_decl_data *file_data,
1347 class lto_input_block *ib)
1349 tree var_decl;
1350 varpool_node *node;
1351 struct bitpack_d bp;
1352 int ref = LCC_NOT_FOUND;
1353 int order;
1354 tree group;
1355 const char *section;
1357 order = streamer_read_hwi (ib) + file_data->order_base;
1358 var_decl = lto_input_var_decl_ref (ib, file_data);
1360 /* Declaration of functions can be already merged with a declaration
1361 from other input file. We keep cgraph unmerged until after streaming
1362 of ipa passes is done. Alays forcingly create a fresh node. */
1363 node = varpool_node::create_empty ();
1364 node->decl = var_decl;
1365 node->register_symbol ();
1367 node->order = order;
1368 if (order >= symtab->order)
1369 symtab->order = order + 1;
1370 node->lto_file_data = file_data;
1372 bp = streamer_read_bitpack (ib);
1373 node->externally_visible = bp_unpack_value (&bp, 1);
1374 node->no_reorder = bp_unpack_value (&bp, 1);
1375 node->force_output = bp_unpack_value (&bp, 1);
1376 node->forced_by_abi = bp_unpack_value (&bp, 1);
1377 node->unique_name = bp_unpack_value (&bp, 1);
1378 node->body_removed = bp_unpack_value (&bp, 1);
1379 node->semantic_interposition = bp_unpack_value (&bp, 1);
1380 node->implicit_section = bp_unpack_value (&bp, 1);
1381 node->writeonly = bp_unpack_value (&bp, 1);
1382 node->definition = bp_unpack_value (&bp, 1);
1383 node->alias = bp_unpack_value (&bp, 1);
1384 node->transparent_alias = bp_unpack_value (&bp, 1);
1385 node->weakref = bp_unpack_value (&bp, 1);
1386 node->symver = bp_unpack_value (&bp, 1);
1387 node->analyzed = bp_unpack_value (&bp, 1);
1388 node->used_from_other_partition = bp_unpack_value (&bp, 1);
1389 node->in_other_partition = bp_unpack_value (&bp, 1);
1390 if (node->in_other_partition)
1392 DECL_EXTERNAL (node->decl) = 1;
1393 TREE_STATIC (node->decl) = 0;
1395 if (node->alias && !node->analyzed && node->weakref)
1396 node->alias_target = get_alias_symbol (node->decl);
1397 node->tls_model = (enum tls_model)bp_unpack_value (&bp, 3);
1398 node->used_by_single_function = (enum tls_model)bp_unpack_value (&bp, 1);
1399 node->dynamically_initialized = bp_unpack_value (&bp, 1);
1400 group = read_identifier (ib);
1401 if (group)
1403 node->set_comdat_group (group);
1404 ref = streamer_read_hwi (ib);
1405 /* Store a reference for now, and fix up later to be a pointer. */
1406 node->same_comdat_group = (symtab_node *) (intptr_t) ref;
1408 else
1409 node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
1410 section = read_string (ib);
1411 if (section)
1412 node->set_section_for_node (section);
1413 node->resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution,
1414 LDPR_NUM_KNOWN);
1415 verify_node_partition (node);
1416 return node;
1419 /* Read a node from input_block IB. TAG is the node's tag just read.
1420 Return the node read or overwriten. */
1422 static void
1423 input_ref (class lto_input_block *ib,
1424 symtab_node *referring_node,
1425 vec<symtab_node *> nodes)
1427 symtab_node *node = NULL;
1428 struct bitpack_d bp;
1429 enum ipa_ref_use use;
1430 bool speculative;
1431 struct ipa_ref *ref;
1433 bp = streamer_read_bitpack (ib);
1434 use = (enum ipa_ref_use) bp_unpack_value (&bp, 3);
1435 speculative = (enum ipa_ref_use) bp_unpack_value (&bp, 1);
1436 node = nodes[streamer_read_hwi (ib)];
1437 ref = referring_node->create_reference (node, use);
1438 ref->speculative = speculative;
1439 if (is_a <cgraph_node *> (referring_node))
1441 ref->lto_stmt_uid = streamer_read_hwi (ib);
1442 bp = streamer_read_bitpack (ib);
1443 ref->speculative_id = bp_unpack_value (&bp, 16);
1447 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1448 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1449 edge being read is indirect (in the sense that it has
1450 indirect_unknown_callee set). */
1452 static void
1453 input_edge (class lto_input_block *ib, vec<symtab_node *> nodes,
1454 bool indirect)
1456 struct cgraph_node *caller, *callee;
1457 struct cgraph_edge *edge;
1458 unsigned int stmt_id, speculative_id;
1459 profile_count count;
1460 cgraph_inline_failed_t inline_failed;
1461 struct bitpack_d bp;
1462 int ecf_flags = 0;
1464 caller = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
1465 if (caller == NULL || caller->decl == NULL_TREE)
1466 internal_error ("bytecode stream: no caller found while reading edge");
1468 if (!indirect)
1470 callee = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
1471 if (callee == NULL || callee->decl == NULL_TREE)
1472 internal_error ("bytecode stream: no callee found while reading edge");
1474 else
1475 callee = NULL;
1477 count = profile_count::stream_in (ib);
1479 bp = streamer_read_bitpack (ib);
1480 inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_t, CIF_N_REASONS);
1481 stmt_id = bp_unpack_var_len_unsigned (&bp);
1482 speculative_id = bp_unpack_value (&bp, 16);
1484 if (indirect)
1485 edge = caller->create_indirect_edge (NULL, 0, count);
1486 else
1487 edge = caller->create_edge (callee, NULL, count);
1489 edge->indirect_inlining_edge = bp_unpack_value (&bp, 1);
1490 edge->speculative = bp_unpack_value (&bp, 1);
1491 edge->lto_stmt_uid = stmt_id;
1492 edge->speculative_id = speculative_id;
1493 edge->inline_failed = inline_failed;
1494 edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1);
1495 edge->can_throw_external = bp_unpack_value (&bp, 1);
1496 edge->in_polymorphic_cdtor = bp_unpack_value (&bp, 1);
1497 if (indirect)
1499 if (bp_unpack_value (&bp, 1))
1500 ecf_flags |= ECF_CONST;
1501 if (bp_unpack_value (&bp, 1))
1502 ecf_flags |= ECF_PURE;
1503 if (bp_unpack_value (&bp, 1))
1504 ecf_flags |= ECF_NORETURN;
1505 if (bp_unpack_value (&bp, 1))
1506 ecf_flags |= ECF_MALLOC;
1507 if (bp_unpack_value (&bp, 1))
1508 ecf_flags |= ECF_NOTHROW;
1509 if (bp_unpack_value (&bp, 1))
1510 ecf_flags |= ECF_RETURNS_TWICE;
1511 edge->indirect_info->ecf_flags = ecf_flags;
1513 edge->indirect_info->num_speculative_call_targets
1514 = bp_unpack_value (&bp, 16);
1519 /* Read a cgraph from IB using the info in FILE_DATA. */
1521 static vec<symtab_node *>
1522 input_cgraph_1 (struct lto_file_decl_data *file_data,
1523 class lto_input_block *ib)
1525 enum LTO_symtab_tags tag;
1526 vec<symtab_node *> nodes = vNULL;
1527 symtab_node *node;
1528 unsigned i;
1530 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1531 file_data->order_base = symtab->order;
1532 file_data->unit_base = symtab->max_unit + 1;
1533 while (tag)
1535 if (tag == LTO_symtab_edge)
1536 input_edge (ib, nodes, false);
1537 else if (tag == LTO_symtab_indirect_edge)
1538 input_edge (ib, nodes, true);
1539 else if (tag == LTO_symtab_variable)
1541 node = input_varpool_node (file_data, ib);
1542 nodes.safe_push (node);
1543 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1545 else
1547 node = input_node (file_data, ib, tag, nodes);
1548 if (node == NULL || node->decl == NULL_TREE)
1549 internal_error ("bytecode stream: found empty cgraph node");
1550 nodes.safe_push (node);
1551 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1554 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1557 lto_input_toplevel_asms (file_data, file_data->order_base);
1559 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1560 if (flag_checking)
1562 FOR_EACH_VEC_ELT (nodes, i, node)
1563 gcc_assert (node->aux || !is_a <cgraph_node *> (node));
1565 FOR_EACH_VEC_ELT (nodes, i, node)
1567 int ref;
1568 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
1570 ref = (int) (intptr_t) cnode->inlined_to;
1572 /* We share declaration of builtins, so we may read same node twice. */
1573 if (!node->aux)
1574 continue;
1575 node->aux = NULL;
1577 /* Fixup inlined_to from reference to pointer. */
1578 if (ref != LCC_NOT_FOUND)
1579 dyn_cast<cgraph_node *> (node)->inlined_to
1580 = dyn_cast<cgraph_node *> (nodes[ref]);
1581 else
1582 cnode->inlined_to = NULL;
1585 ref = (int) (intptr_t) node->same_comdat_group;
1587 /* Fixup same_comdat_group from reference to pointer. */
1588 if (ref != LCC_NOT_FOUND)
1589 node->same_comdat_group = nodes[ref];
1590 else
1591 node->same_comdat_group = NULL;
1593 FOR_EACH_VEC_ELT (nodes, i, node)
1594 node->aux = is_a <cgraph_node *> (node) ? (void *)1 : NULL;
1595 return nodes;
1598 /* Input ipa_refs. */
1600 static void
1601 input_refs (class lto_input_block *ib,
1602 vec<symtab_node *> nodes)
1604 int count;
1605 int idx;
1606 while (true)
1608 symtab_node *node;
1609 count = streamer_read_uhwi (ib);
1610 if (!count)
1611 break;
1612 idx = streamer_read_uhwi (ib);
1613 node = nodes[idx];
1614 while (count)
1616 input_ref (ib, node, nodes);
1617 count--;
1619 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
1620 if (cnode->declare_variant_alt)
1621 omp_lto_input_declare_variant_alt (ib, cnode, nodes);
1625 /* Input profile_info from IB. */
1626 static void
1627 input_profile_summary (class lto_input_block *ib,
1628 struct lto_file_decl_data *file_data)
1630 unsigned int runs = streamer_read_uhwi (ib);
1631 if (runs)
1633 file_data->profile_info.runs = runs;
1635 /* IPA-profile computes hot bb threshold based on cumulated
1636 whole program profile. We need to stream it down to ltrans. */
1637 if (flag_ltrans)
1638 set_hot_bb_threshold (streamer_read_gcov_count (ib));
1643 /* Rescale profile summaries to the same number of runs in the whole unit. */
1645 static void
1646 merge_profile_summaries (struct lto_file_decl_data **file_data_vec)
1648 struct lto_file_decl_data *file_data;
1649 unsigned int j;
1650 gcov_unsigned_t max_runs = 0;
1651 struct cgraph_node *node;
1652 struct cgraph_edge *edge;
1654 /* Find unit with maximal number of runs. If we ever get serious about
1655 roundoff errors, we might also consider computing smallest common
1656 multiply. */
1657 for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
1658 if (max_runs < file_data->profile_info.runs)
1659 max_runs = file_data->profile_info.runs;
1661 if (!max_runs)
1662 return;
1664 /* Simple overflow check. We probably don't need to support that many train
1665 runs. Such a large value probably imply data corruption anyway. */
1666 if (max_runs > INT_MAX / REG_BR_PROB_BASE)
1668 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1669 INT_MAX / REG_BR_PROB_BASE);
1670 return;
1673 profile_info = XCNEW (gcov_summary);
1674 profile_info->runs = max_runs;
1676 /* If merging already happent at WPA time, we are done. */
1677 if (flag_ltrans)
1678 return;
1680 /* Now compute count_materialization_scale of each node.
1681 During LTRANS we already have values of count_materialization_scale
1682 computed, so just update them. */
1683 FOR_EACH_FUNCTION (node)
1684 if (node->lto_file_data
1685 && node->lto_file_data->profile_info.runs)
1687 int scale;
1689 scale = RDIV (node->count_materialization_scale * max_runs,
1690 node->lto_file_data->profile_info.runs);
1691 node->count_materialization_scale = scale;
1692 if (scale < 0)
1693 fatal_error (input_location, "Profile information in %s corrupted",
1694 file_data->file_name);
1696 if (scale == REG_BR_PROB_BASE)
1697 continue;
1698 for (edge = node->callees; edge; edge = edge->next_callee)
1699 if (edge->count.ipa ().nonzero_p ())
1700 edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
1701 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
1702 if (edge->count.ipa ().nonzero_p ())
1703 edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
1704 if (node->count.ipa ().nonzero_p ())
1705 node->count = node->count.apply_scale (scale, REG_BR_PROB_BASE);
1709 /* Input and merge the symtab from each of the .o files passed to
1710 lto1. */
1712 void
1713 input_symtab (void)
1715 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1716 struct lto_file_decl_data *file_data;
1717 unsigned int j = 0;
1718 struct cgraph_node *node;
1720 while ((file_data = file_data_vec[j++]))
1722 const char *data;
1723 size_t len;
1724 class lto_input_block *ib;
1725 vec<symtab_node *> nodes;
1727 ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes,
1728 &data, &len);
1729 if (!ib)
1730 fatal_error (input_location,
1731 "cannot find LTO cgraph in %s", file_data->file_name);
1732 input_profile_summary (ib, file_data);
1733 file_data->symtab_node_encoder = lto_symtab_encoder_new (true);
1734 nodes = input_cgraph_1 (file_data, ib);
1735 lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes,
1736 ib, data, len);
1738 ib = lto_create_simple_input_block (file_data, LTO_section_refs,
1739 &data, &len);
1740 if (!ib)
1741 fatal_error (input_location, "cannot find LTO section refs in %s",
1742 file_data->file_name);
1743 input_refs (ib, nodes);
1744 lto_destroy_simple_input_block (file_data, LTO_section_refs,
1745 ib, data, len);
1746 if (flag_ltrans)
1747 input_cgraph_opt_summary (nodes);
1748 nodes.release ();
1751 merge_profile_summaries (file_data_vec);
1753 /* Clear out the aux field that was used to store enough state to
1754 tell which nodes should be overwritten. */
1755 FOR_EACH_FUNCTION (node)
1757 /* Some nodes may have been created by cgraph_node. This
1758 happens when the callgraph contains nested functions. If the
1759 node for the parent function was never emitted to the gimple
1760 file, cgraph_node will create a node for it when setting the
1761 context of the nested function. */
1762 if (node->lto_file_data)
1763 node->aux = NULL;
1767 /* Input function/variable tables that will allow libgomp to look up offload
1768 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1770 void
1771 input_offload_tables (bool do_force_output)
1773 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1774 struct lto_file_decl_data *file_data;
1775 unsigned int j = 0;
1777 while ((file_data = file_data_vec[j++]))
1779 const char *data;
1780 size_t len;
1781 class lto_input_block *ib
1782 = lto_create_simple_input_block (file_data, LTO_section_offload_table,
1783 &data, &len);
1784 if (!ib)
1785 continue;
1787 enum LTO_symtab_tags tag
1788 = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1789 while (tag)
1791 if (tag == LTO_symtab_unavail_node)
1793 tree fn_decl
1794 = lto_input_fn_decl_ref (ib, file_data);
1795 vec_safe_push (offload_funcs, fn_decl);
1797 /* Prevent IPA from removing fn_decl as unreachable, since there
1798 may be no refs from the parent function to child_fn in offload
1799 LTO mode. */
1800 if (do_force_output)
1801 cgraph_node::get (fn_decl)->mark_force_output ();
1803 else if (tag == LTO_symtab_variable)
1805 tree var_decl
1806 = lto_input_var_decl_ref (ib, file_data);
1807 vec_safe_push (offload_vars, var_decl);
1809 /* Prevent IPA from removing var_decl as unused, since there
1810 may be no refs to var_decl in offload LTO mode. */
1811 if (do_force_output)
1812 varpool_node::get (var_decl)->force_output = 1;
1814 else
1815 fatal_error (input_location,
1816 "invalid offload table in %s", file_data->file_name);
1818 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1821 lto_destroy_simple_input_block (file_data, LTO_section_offload_table,
1822 ib, data, len);
1826 /* True when we need optimization summary for NODE. */
1828 static int
1829 output_cgraph_opt_summary_p (struct cgraph_node *node)
1831 if (node->clone_of || node->former_clone_of)
1832 return true;
1833 clone_info *info = clone_info::get (node);
1834 return info && (info->tree_map || info->param_adjustments);
1837 /* Output optimization summary for EDGE to OB. */
1838 static void
1839 output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED,
1840 struct cgraph_edge *edge ATTRIBUTE_UNUSED)
1844 /* Output optimization summary for NODE to OB. */
1846 static void
1847 output_node_opt_summary (struct output_block *ob,
1848 struct cgraph_node *node,
1849 lto_symtab_encoder_t encoder)
1851 struct ipa_replace_map *map;
1852 int i;
1853 struct cgraph_edge *e;
1855 /* TODO: Should this code be moved to ipa-param-manipulation? */
1856 struct bitpack_d bp;
1857 bp = bitpack_create (ob->main_stream);
1858 clone_info *info = clone_info::get (node);
1860 bp_pack_value (&bp, (info && info->param_adjustments != NULL), 1);
1861 streamer_write_bitpack (&bp);
1862 if (ipa_param_adjustments *adjustments
1863 = info ? info->param_adjustments : NULL)
1865 streamer_write_uhwi (ob, vec_safe_length (adjustments->m_adj_params));
1866 ipa_adjusted_param *adj;
1867 FOR_EACH_VEC_SAFE_ELT (adjustments->m_adj_params, i, adj)
1869 bp = bitpack_create (ob->main_stream);
1870 bp_pack_value (&bp, adj->base_index, IPA_PARAM_MAX_INDEX_BITS);
1871 bp_pack_value (&bp, adj->prev_clone_index, IPA_PARAM_MAX_INDEX_BITS);
1872 bp_pack_value (&bp, adj->op, 2);
1873 bp_pack_value (&bp, adj->param_prefix_index, 2);
1874 bp_pack_value (&bp, adj->prev_clone_adjustment, 1);
1875 bp_pack_value (&bp, adj->reverse, 1);
1876 bp_pack_value (&bp, adj->user_flag, 1);
1877 streamer_write_bitpack (&bp);
1878 if (adj->op == IPA_PARAM_OP_SPLIT
1879 || adj->op == IPA_PARAM_OP_NEW)
1881 stream_write_tree (ob, adj->type, true);
1882 if (adj->op == IPA_PARAM_OP_SPLIT)
1884 stream_write_tree (ob, adj->alias_ptr_type, true);
1885 streamer_write_uhwi (ob, adj->unit_offset);
1889 streamer_write_hwi (ob, adjustments->m_always_copy_start);
1890 bp = bitpack_create (ob->main_stream);
1891 bp_pack_value (&bp, info->param_adjustments->m_skip_return, 1);
1892 streamer_write_bitpack (&bp);
1895 streamer_write_uhwi (ob, info ? vec_safe_length (info->tree_map) : 0);
1896 if (info)
1897 FOR_EACH_VEC_SAFE_ELT (info->tree_map, i, map)
1899 streamer_write_uhwi (ob, map->parm_num);
1900 gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION);
1901 stream_write_tree (ob, map->new_tree, true);
1904 if (lto_symtab_encoder_in_partition_p (encoder, node))
1906 for (e = node->callees; e; e = e->next_callee)
1907 output_edge_opt_summary (ob, e);
1908 for (e = node->indirect_calls; e; e = e->next_callee)
1909 output_edge_opt_summary (ob, e);
1913 /* Output optimization summaries stored in callgraph.
1914 At the moment it is the clone info structure. */
1916 static void
1917 output_cgraph_opt_summary (void)
1919 int i, n_nodes;
1920 lto_symtab_encoder_t encoder;
1921 struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum);
1922 unsigned count = 0;
1924 ob->symbol = NULL;
1925 encoder = ob->decl_state->symtab_node_encoder;
1926 n_nodes = lto_symtab_encoder_size (encoder);
1927 for (i = 0; i < n_nodes; i++)
1929 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
1930 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
1931 if (cnode && output_cgraph_opt_summary_p (cnode))
1932 count++;
1934 streamer_write_uhwi (ob, count);
1935 for (i = 0; i < n_nodes; i++)
1937 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
1938 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
1939 if (cnode && output_cgraph_opt_summary_p (cnode))
1941 streamer_write_uhwi (ob, i);
1942 output_node_opt_summary (ob, cnode, encoder);
1945 produce_asm (ob, NULL);
1946 destroy_output_block (ob);
1949 /* Input optimisation summary of EDGE. */
1951 static void
1952 input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED,
1953 class lto_input_block *ib_main ATTRIBUTE_UNUSED)
1957 /* Input optimisation summary of NODE. */
1959 static void
1960 input_node_opt_summary (struct cgraph_node *node,
1961 class lto_input_block *ib_main,
1962 class data_in *data_in)
1964 int i;
1965 int count;
1966 struct cgraph_edge *e;
1968 /* TODO: Should this code be moved to ipa-param-manipulation? */
1969 struct bitpack_d bp;
1970 bp = streamer_read_bitpack (ib_main);
1971 bool have_adjustments = bp_unpack_value (&bp, 1);
1972 clone_info *info = clone_info::get_create (node);
1974 if (have_adjustments)
1976 count = streamer_read_uhwi (ib_main);
1977 vec<ipa_adjusted_param, va_gc> *new_params = NULL;
1978 for (i = 0; i < count; i++)
1980 ipa_adjusted_param adj;
1981 memset (&adj, 0, sizeof (adj));
1982 bp = streamer_read_bitpack (ib_main);
1983 adj.base_index = bp_unpack_value (&bp, IPA_PARAM_MAX_INDEX_BITS);
1984 adj.prev_clone_index
1985 = bp_unpack_value (&bp, IPA_PARAM_MAX_INDEX_BITS);
1986 adj.op = (enum ipa_parm_op) bp_unpack_value (&bp, 2);
1987 adj.param_prefix_index = bp_unpack_value (&bp, 2);
1988 adj.prev_clone_adjustment = bp_unpack_value (&bp, 1);
1989 adj.reverse = bp_unpack_value (&bp, 1);
1990 adj.user_flag = bp_unpack_value (&bp, 1);
1991 if (adj.op == IPA_PARAM_OP_SPLIT
1992 || adj.op == IPA_PARAM_OP_NEW)
1994 adj.type = stream_read_tree (ib_main, data_in);
1995 if (adj.op == IPA_PARAM_OP_SPLIT)
1997 adj.alias_ptr_type = stream_read_tree (ib_main, data_in);
1998 adj.unit_offset = streamer_read_uhwi (ib_main);
2001 vec_safe_push (new_params, adj);
2003 int always_copy_start = streamer_read_hwi (ib_main);
2004 bp = streamer_read_bitpack (ib_main);
2005 bool skip_return = bp_unpack_value (&bp, 1);
2006 info->param_adjustments
2007 = (new (ggc_alloc <ipa_param_adjustments> ())
2008 ipa_param_adjustments (new_params, always_copy_start, skip_return));
2011 count = streamer_read_uhwi (ib_main);
2012 for (i = 0; i < count; i++)
2014 struct ipa_replace_map *map = ggc_alloc<ipa_replace_map> ();
2016 vec_safe_push (info->tree_map, map);
2017 map->parm_num = streamer_read_uhwi (ib_main);
2018 map->new_tree = stream_read_tree (ib_main, data_in);
2020 for (e = node->callees; e; e = e->next_callee)
2021 input_edge_opt_summary (e, ib_main);
2022 for (e = node->indirect_calls; e; e = e->next_callee)
2023 input_edge_opt_summary (e, ib_main);
2026 /* Read section in file FILE_DATA of length LEN with data DATA. */
2028 static void
2029 input_cgraph_opt_section (struct lto_file_decl_data *file_data,
2030 const char *data, size_t len,
2031 vec<symtab_node *> nodes)
2033 const struct lto_function_header *header =
2034 (const struct lto_function_header *) data;
2035 const int cfg_offset = sizeof (struct lto_function_header);
2036 const int main_offset = cfg_offset + header->cfg_size;
2037 const int string_offset = main_offset + header->main_size;
2038 class data_in *data_in;
2039 unsigned int i;
2040 unsigned int count;
2042 lto_input_block ib_main ((const char *) data + main_offset,
2043 header->main_size, file_data->mode_table);
2045 data_in =
2046 lto_data_in_create (file_data, (const char *) data + string_offset,
2047 header->string_size, vNULL);
2048 count = streamer_read_uhwi (&ib_main);
2050 for (i = 0; i < count; i++)
2052 int ref = streamer_read_uhwi (&ib_main);
2053 input_node_opt_summary (dyn_cast<cgraph_node *> (nodes[ref]),
2054 &ib_main, data_in);
2056 lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data,
2057 len);
2058 lto_data_in_delete (data_in);
2061 /* Input optimization summary of cgraph. */
2063 static void
2064 input_cgraph_opt_summary (vec<symtab_node *> nodes)
2066 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
2067 struct lto_file_decl_data *file_data;
2068 unsigned int j = 0;
2070 while ((file_data = file_data_vec[j++]))
2072 size_t len;
2073 const char *data
2074 = lto_get_summary_section_data (file_data, LTO_section_cgraph_opt_sum,
2075 &len);
2076 if (data)
2077 input_cgraph_opt_section (file_data, data, len, nodes);