Daily bump.
[official-gcc.git] / gcc / lto-cgraph.c
blob621607499e1fd47e68f74e665061db4782b919d0
1 /* Write and read the cgraph to the memory mapped representation of a
2 .o file.
4 Copyright (C) 2009-2020 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"
43 /* True when asm nodes has been output. */
44 bool asm_nodes_output = false;
46 static void output_cgraph_opt_summary (void);
47 static void input_cgraph_opt_summary (vec<symtab_node *> nodes);
49 /* Number of LDPR values known to GCC. */
50 #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
52 /* Cgraph streaming is organized as set of record whose type
53 is indicated by a tag. */
54 enum LTO_symtab_tags
56 /* Must leave 0 for the stopper. */
58 /* Cgraph node without body available. */
59 LTO_symtab_unavail_node = 1,
60 /* Cgraph node with function body. */
61 LTO_symtab_analyzed_node,
62 /* Cgraph edges. */
63 LTO_symtab_edge,
64 LTO_symtab_indirect_edge,
65 LTO_symtab_variable,
66 LTO_symtab_last_tag
69 /* Create a new symtab encoder.
70 if FOR_INPUT, the encoder allocate only datastructures needed
71 to read the symtab. */
73 lto_symtab_encoder_t
74 lto_symtab_encoder_new (bool for_input)
76 lto_symtab_encoder_t encoder = XCNEW (struct lto_symtab_encoder_d);
78 if (!for_input)
79 encoder->map = new hash_map<symtab_node *, size_t>;
80 encoder->nodes.create (0);
81 return encoder;
85 /* Delete ENCODER and its components. */
87 void
88 lto_symtab_encoder_delete (lto_symtab_encoder_t encoder)
90 encoder->nodes.release ();
91 if (encoder->map)
92 delete encoder->map;
93 free (encoder);
97 /* Return the existing reference number of NODE in the symtab encoder in
98 output block OB. Assign a new reference if this is the first time
99 NODE is encoded. */
102 lto_symtab_encoder_encode (lto_symtab_encoder_t encoder,
103 symtab_node *node)
105 int ref;
107 if (!encoder->map)
109 lto_encoder_entry entry = {node, false, false, false};
111 ref = encoder->nodes.length ();
112 encoder->nodes.safe_push (entry);
113 return ref;
116 size_t *slot = encoder->map->get (node);
117 if (!slot || !*slot)
119 lto_encoder_entry entry = {node, false, false, false};
120 ref = encoder->nodes.length ();
121 if (!slot)
122 encoder->map->put (node, ref + 1);
123 encoder->nodes.safe_push (entry);
125 else
126 ref = *slot - 1;
128 return ref;
131 /* Remove NODE from encoder. */
133 bool
134 lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder,
135 symtab_node *node)
137 int index;
138 lto_encoder_entry last_node;
140 size_t *slot = encoder->map->get (node);
141 if (slot == NULL || !*slot)
142 return false;
144 index = *slot - 1;
145 gcc_checking_assert (encoder->nodes[index].node == node);
147 /* Remove from vector. We do this by swapping node with the last element
148 of the vector. */
149 last_node = encoder->nodes.pop ();
150 if (last_node.node != node)
152 gcc_assert (encoder->map->put (last_node.node, index + 1));
154 /* Move the last element to the original spot of NODE. */
155 encoder->nodes[index] = last_node;
158 /* Remove element from hash table. */
159 encoder->map->remove (node);
160 return true;
164 /* Return TRUE if we should encode the body of NODE (if any). */
166 bool
167 lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder,
168 struct cgraph_node *node)
170 int index = lto_symtab_encoder_lookup (encoder, node);
171 return encoder->nodes[index].body;
174 /* Specify that we encode the body of NODE in this partition. */
176 static void
177 lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder,
178 struct cgraph_node *node)
180 int index = lto_symtab_encoder_encode (encoder, node);
181 gcc_checking_assert (encoder->nodes[index].node == node);
182 encoder->nodes[index].body = true;
185 /* Return TRUE if we should encode initializer of NODE (if any). */
187 bool
188 lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder,
189 varpool_node *node)
191 int index = lto_symtab_encoder_lookup (encoder, node);
192 if (index == LCC_NOT_FOUND)
193 return false;
194 return encoder->nodes[index].initializer;
197 /* Specify that we should encode initializer of NODE (if any). */
199 static void
200 lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder,
201 varpool_node *node)
203 int index = lto_symtab_encoder_lookup (encoder, node);
204 encoder->nodes[index].initializer = true;
207 /* Return TRUE if NODE is in this partition. */
209 bool
210 lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder,
211 symtab_node *node)
213 int index = lto_symtab_encoder_lookup (encoder, node);
214 if (index == LCC_NOT_FOUND)
215 return false;
216 return encoder->nodes[index].in_partition;
219 /* Specify that NODE is in this partition. */
221 void
222 lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder,
223 symtab_node *node)
225 int index = lto_symtab_encoder_encode (encoder, node);
226 encoder->nodes[index].in_partition = true;
229 /* Output the cgraph EDGE to OB using ENCODER. */
231 static void
232 lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
233 lto_symtab_encoder_t encoder)
235 unsigned int uid;
236 intptr_t ref;
237 struct bitpack_d bp;
239 if (edge->indirect_unknown_callee)
240 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
241 LTO_symtab_indirect_edge);
242 else
243 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
244 LTO_symtab_edge);
246 ref = lto_symtab_encoder_lookup (encoder, edge->caller);
247 gcc_assert (ref != LCC_NOT_FOUND);
248 streamer_write_hwi_stream (ob->main_stream, ref);
250 if (!edge->indirect_unknown_callee)
252 ref = lto_symtab_encoder_lookup (encoder, edge->callee);
253 gcc_assert (ref != LCC_NOT_FOUND);
254 streamer_write_hwi_stream (ob->main_stream, ref);
257 edge->count.stream_out (ob->main_stream);
259 bp = bitpack_create (ob->main_stream);
260 uid = (!gimple_has_body_p (edge->caller->decl) || edge->caller->thunk.thunk_p
261 ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt) + 1);
262 bp_pack_enum (&bp, cgraph_inline_failed_t,
263 CIF_N_REASONS, edge->inline_failed);
264 bp_pack_var_len_unsigned (&bp, uid);
265 bp_pack_value (&bp, edge->speculative_id, 16);
266 bp_pack_value (&bp, edge->indirect_inlining_edge, 1);
267 bp_pack_value (&bp, edge->speculative, 1);
268 bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1);
269 gcc_assert (!edge->call_stmt_cannot_inline_p
270 || edge->inline_failed != CIF_BODY_NOT_AVAILABLE);
271 bp_pack_value (&bp, edge->can_throw_external, 1);
272 bp_pack_value (&bp, edge->in_polymorphic_cdtor, 1);
273 if (edge->indirect_unknown_callee)
275 int flags = edge->indirect_info->ecf_flags;
276 bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1);
277 bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1);
278 bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1);
279 bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1);
280 bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1);
281 bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1);
282 /* Flags that should not appear on indirect calls. */
283 gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE
284 | ECF_MAY_BE_ALLOCA
285 | ECF_SIBCALL
286 | ECF_LEAF
287 | ECF_NOVOPS)));
289 bp_pack_value (&bp, edge->indirect_info->num_speculative_call_targets,
290 16);
292 streamer_write_bitpack (&bp);
295 /* Return if NODE contain references from other partitions. */
297 bool
298 referenced_from_other_partition_p (symtab_node *node, lto_symtab_encoder_t encoder)
300 int i;
301 struct ipa_ref *ref = NULL;
303 for (i = 0; node->iterate_referring (i, ref); i++)
305 /* Ignore references from non-offloadable nodes while streaming NODE into
306 offload LTO section. */
307 if (!ref->referring->need_lto_streaming)
308 continue;
310 if (ref->referring->in_other_partition
311 || !lto_symtab_encoder_in_partition_p (encoder, ref->referring))
312 return true;
314 return false;
317 /* Return true when node is reachable from other partition. */
319 bool
320 reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
322 struct cgraph_edge *e;
323 if (!node->definition)
324 return false;
325 if (node->inlined_to)
326 return false;
327 for (e = node->callers; e; e = e->next_caller)
329 /* Ignore references from non-offloadable nodes while streaming NODE into
330 offload LTO section. */
331 if (!e->caller->need_lto_streaming)
332 continue;
334 if (e->caller->in_other_partition
335 || !lto_symtab_encoder_in_partition_p (encoder, e->caller))
336 return true;
338 return false;
341 /* Return if NODE contain references from other partitions. */
343 bool
344 referenced_from_this_partition_p (symtab_node *node,
345 lto_symtab_encoder_t encoder)
347 int i;
348 struct ipa_ref *ref = NULL;
350 for (i = 0; node->iterate_referring (i, ref); i++)
351 if (lto_symtab_encoder_in_partition_p (encoder, ref->referring))
352 return true;
353 return false;
356 /* Return true when node is reachable from other partition. */
358 bool
359 reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder)
361 struct cgraph_edge *e;
362 for (e = node->callers; e; e = e->next_caller)
363 if (lto_symtab_encoder_in_partition_p (encoder, e->caller))
364 return true;
365 return false;
368 /* Output the cgraph NODE to OB. ENCODER is used to find the
369 reference number of NODE->inlined_to. SET is the set of nodes we
370 are writing to the current file. If NODE is not in SET, then NODE
371 is a boundary of a cgraph_node_set and we pretend NODE just has a
372 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
373 that have had their callgraph node written so far. This is used to
374 determine if NODE is a clone of a previously written node. */
376 static void
377 lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
378 lto_symtab_encoder_t encoder)
380 unsigned int tag;
381 struct bitpack_d bp;
382 bool boundary_p;
383 intptr_t ref;
384 bool in_other_partition = false;
385 struct cgraph_node *clone_of, *ultimate_clone_of;
386 ipa_opt_pass_d *pass;
387 int i;
388 const char *comdat;
389 const char *section;
390 tree group;
392 boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
394 if (node->analyzed && (!boundary_p || node->alias
395 || (node->thunk.thunk_p && !node->inlined_to)))
396 tag = LTO_symtab_analyzed_node;
397 else
398 tag = LTO_symtab_unavail_node;
400 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
401 tag);
402 streamer_write_hwi_stream (ob->main_stream, node->order);
404 /* In WPA mode, we only output part of the call-graph. Also, we
405 fake cgraph node attributes. There are two cases that we care.
407 Boundary nodes: There are nodes that are not part of SET but are
408 called from within SET. We artificially make them look like
409 externally visible nodes with no function body.
411 Cherry-picked nodes: These are nodes we pulled from other
412 translation units into SET during IPA-inlining. We make them as
413 local static nodes to prevent clashes with other local statics. */
414 if (boundary_p && node->analyzed
415 && node->get_partitioning_class () == SYMBOL_PARTITION)
417 /* Inline clones cannot be part of boundary.
418 gcc_assert (!node->inlined_to);
420 FIXME: At the moment they can be, when partition contains an inline
421 clone that is clone of inline clone from outside partition. We can
422 reshape the clone tree and make other tree to be the root, but it
423 needs a bit extra work and will be promplty done by cgraph_remove_node
424 after reading back. */
425 in_other_partition = 1;
428 clone_of = node->clone_of;
429 while (clone_of
430 && (ref = lto_symtab_encoder_lookup (encoder, clone_of)) == LCC_NOT_FOUND)
431 if (clone_of->prev_sibling_clone)
432 clone_of = clone_of->prev_sibling_clone;
433 else
434 clone_of = clone_of->clone_of;
436 /* See if body of the master function is output. If not, we are seeing only
437 an declaration and we do not need to pass down clone tree. */
438 ultimate_clone_of = clone_of;
439 while (ultimate_clone_of && ultimate_clone_of->clone_of)
440 ultimate_clone_of = ultimate_clone_of->clone_of;
442 if (clone_of && !lto_symtab_encoder_encode_body_p (encoder, ultimate_clone_of))
443 clone_of = NULL;
445 if (tag == LTO_symtab_analyzed_node)
446 gcc_assert (clone_of || !node->clone_of);
447 if (!clone_of)
448 streamer_write_hwi_stream (ob->main_stream, LCC_NOT_FOUND);
449 else
450 streamer_write_hwi_stream (ob->main_stream, ref);
453 lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->decl);
454 node->count.stream_out (ob->main_stream);
455 streamer_write_hwi_stream (ob->main_stream, node->count_materialization_scale);
457 streamer_write_hwi_stream (ob->main_stream,
458 node->ipa_transforms_to_apply.length ());
459 FOR_EACH_VEC_ELT (node->ipa_transforms_to_apply, i, pass)
460 streamer_write_hwi_stream (ob->main_stream, pass->static_pass_number);
462 if (tag == LTO_symtab_analyzed_node)
464 if (node->inlined_to)
466 ref = lto_symtab_encoder_lookup (encoder, node->inlined_to);
467 gcc_assert (ref != LCC_NOT_FOUND);
469 else
470 ref = LCC_NOT_FOUND;
472 streamer_write_hwi_stream (ob->main_stream, ref);
475 group = node->get_comdat_group ();
476 if (group)
477 comdat = IDENTIFIER_POINTER (group);
478 else
479 comdat = "";
480 streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
482 if (group)
484 if (node->same_comdat_group)
486 ref = LCC_NOT_FOUND;
487 for (struct symtab_node *n = node->same_comdat_group;
488 ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
489 ref = lto_symtab_encoder_lookup (encoder, n);
491 else
492 ref = LCC_NOT_FOUND;
493 streamer_write_hwi_stream (ob->main_stream, ref);
496 section = node->get_section ();
497 if (!section)
498 section = "";
500 streamer_write_hwi_stream (ob->main_stream, node->tp_first_run);
502 bp = bitpack_create (ob->main_stream);
503 bp_pack_value (&bp, node->local, 1);
504 bp_pack_value (&bp, node->externally_visible, 1);
505 bp_pack_value (&bp, node->no_reorder, 1);
506 bp_pack_value (&bp, node->definition, 1);
507 bp_pack_value (&bp, node->versionable, 1);
508 bp_pack_value (&bp, node->can_change_signature, 1);
509 bp_pack_value (&bp, node->redefined_extern_inline, 1);
510 bp_pack_value (&bp, node->force_output, 1);
511 bp_pack_value (&bp, node->forced_by_abi, 1);
512 bp_pack_value (&bp, node->unique_name, 1);
513 bp_pack_value (&bp, node->body_removed, 1);
514 bp_pack_value (&bp, node->implicit_section, 1);
515 bp_pack_value (&bp, node->address_taken, 1);
516 bp_pack_value (&bp, tag == LTO_symtab_analyzed_node
517 && node->get_partitioning_class () == SYMBOL_PARTITION
518 && (reachable_from_other_partition_p (node, encoder)
519 || referenced_from_other_partition_p (node, encoder)), 1);
520 bp_pack_value (&bp, node->lowered, 1);
521 bp_pack_value (&bp, in_other_partition, 1);
522 bp_pack_value (&bp, node->alias, 1);
523 bp_pack_value (&bp, node->transparent_alias, 1);
524 bp_pack_value (&bp, node->weakref, 1);
525 bp_pack_value (&bp, node->symver, 1);
526 bp_pack_value (&bp, node->frequency, 2);
527 bp_pack_value (&bp, node->only_called_at_startup, 1);
528 bp_pack_value (&bp, node->only_called_at_exit, 1);
529 bp_pack_value (&bp, node->tm_clone, 1);
530 bp_pack_value (&bp, node->calls_comdat_local, 1);
531 bp_pack_value (&bp, node->icf_merged, 1);
532 bp_pack_value (&bp, node->nonfreeing_fn, 1);
533 bp_pack_value (&bp, node->merged_comdat, 1);
534 bp_pack_value (&bp, node->merged_extern_inline, 1);
535 bp_pack_value (&bp, node->thunk.thunk_p, 1);
536 bp_pack_value (&bp, node->parallelized_function, 1);
537 bp_pack_enum (&bp, ld_plugin_symbol_resolution,
538 LDPR_NUM_KNOWN,
539 /* When doing incremental link, we will get new resolution
540 info next time we process the file. */
541 flag_incremental_link ? LDPR_UNKNOWN : node->resolution);
542 bp_pack_value (&bp, node->split_part, 1);
543 streamer_write_bitpack (&bp);
544 streamer_write_data_stream (ob->main_stream, section, strlen (section) + 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 if (node->definition)
552 streamer_write_uhwi_stream
553 (ob->main_stream,
554 1 + (node->thunk.this_adjusting != 0) * 2
555 + (node->thunk.virtual_offset_p != 0) * 4);
556 streamer_write_uhwi_stream (ob->main_stream, node->thunk.fixed_offset);
557 streamer_write_uhwi_stream (ob->main_stream, node->thunk.virtual_value);
558 streamer_write_uhwi_stream (ob->main_stream, node->thunk.indirect_offset);
560 streamer_write_hwi_stream (ob->main_stream, node->profile_id);
561 streamer_write_hwi_stream (ob->main_stream, node->unit_id);
562 if (DECL_STATIC_CONSTRUCTOR (node->decl))
563 streamer_write_hwi_stream (ob->main_stream, node->get_init_priority ());
564 if (DECL_STATIC_DESTRUCTOR (node->decl))
565 streamer_write_hwi_stream (ob->main_stream, node->get_fini_priority ());
568 /* Output the varpool NODE to OB.
569 If NODE is not in SET, then NODE is a boundary. */
571 static void
572 lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node,
573 lto_symtab_encoder_t encoder)
575 bool boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node);
576 bool encode_initializer_p
577 = (node->definition
578 && lto_symtab_encoder_encode_initializer_p (encoder, node));
579 struct bitpack_d bp;
580 int ref;
581 const char *comdat;
582 const char *section;
583 tree group;
585 gcc_assert (!encode_initializer_p || node->definition);
586 gcc_assert (boundary_p || encode_initializer_p);
588 streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag,
589 LTO_symtab_variable);
590 streamer_write_hwi_stream (ob->main_stream, node->order);
591 lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->decl);
592 bp = bitpack_create (ob->main_stream);
593 bp_pack_value (&bp, node->externally_visible, 1);
594 bp_pack_value (&bp, node->no_reorder, 1);
595 bp_pack_value (&bp, node->force_output, 1);
596 bp_pack_value (&bp, node->forced_by_abi, 1);
597 bp_pack_value (&bp, node->unique_name, 1);
598 bp_pack_value (&bp,
599 node->body_removed
600 || (!encode_initializer_p && !node->alias && node->definition),
602 bp_pack_value (&bp, node->implicit_section, 1);
603 bp_pack_value (&bp, node->writeonly, 1);
604 bp_pack_value (&bp, node->definition && (encode_initializer_p || node->alias),
606 bp_pack_value (&bp, node->alias, 1);
607 bp_pack_value (&bp, node->transparent_alias, 1);
608 bp_pack_value (&bp, node->weakref, 1);
609 bp_pack_value (&bp, node->symver, 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. */
620 else
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 streamer_write_bitpack (&bp);
633 group = node->get_comdat_group ();
634 if (group)
635 comdat = IDENTIFIER_POINTER (group);
636 else
637 comdat = "";
638 streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1);
640 if (group)
642 if (node->same_comdat_group)
644 ref = LCC_NOT_FOUND;
645 for (struct symtab_node *n = node->same_comdat_group;
646 ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group)
647 ref = lto_symtab_encoder_lookup (encoder, n);
649 else
650 ref = LCC_NOT_FOUND;
651 streamer_write_hwi_stream (ob->main_stream, ref);
654 section = node->get_section ();
655 if (!section)
656 section = "";
657 streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
659 streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution,
660 LDPR_NUM_KNOWN, node->resolution);
663 /* Output the varpool NODE to OB.
664 If NODE is not in SET, then NODE is a boundary. */
666 static void
667 lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref,
668 lto_symtab_encoder_t encoder)
670 struct bitpack_d bp;
671 int nref;
672 int uid = ref->lto_stmt_uid;
673 struct cgraph_node *node;
675 bp = bitpack_create (ob->main_stream);
676 bp_pack_value (&bp, ref->use, 3);
677 bp_pack_value (&bp, ref->speculative, 1);
678 streamer_write_bitpack (&bp);
679 nref = lto_symtab_encoder_lookup (encoder, ref->referred);
680 gcc_assert (nref != LCC_NOT_FOUND);
681 streamer_write_hwi_stream (ob->main_stream, nref);
683 node = dyn_cast <cgraph_node *> (ref->referring);
684 if (node)
686 if (ref->stmt)
687 uid = gimple_uid (ref->stmt) + 1;
688 streamer_write_hwi_stream (ob->main_stream, uid);
689 bp_pack_value (&bp, ref->speculative_id, 16);
690 streamer_write_bitpack (&bp);
694 /* Stream out profile_summary to OB. */
696 static void
697 output_profile_summary (struct lto_simple_output_block *ob)
699 if (profile_info)
701 /* We do not output num and run_max, they are not used by
702 GCC profile feedback and they are difficult to merge from multiple
703 units. */
704 unsigned runs = (profile_info->runs);
705 streamer_write_uhwi_stream (ob->main_stream, runs);
707 /* IPA-profile computes hot bb threshold based on cumulated
708 whole program profile. We need to stream it down to ltrans. */
709 if (flag_wpa)
710 streamer_write_gcov_count_stream (ob->main_stream,
711 get_hot_bb_threshold ());
713 else
714 streamer_write_uhwi_stream (ob->main_stream, 0);
717 /* Output all callees or indirect outgoing edges. EDGE must be the first such
718 edge. */
720 static void
721 output_outgoing_cgraph_edges (struct cgraph_edge *edge,
722 struct lto_simple_output_block *ob,
723 lto_symtab_encoder_t encoder)
725 if (!edge)
726 return;
728 /* Output edges in backward direction, so the reconstructed callgraph match
729 and it is easy to associate call sites in the IPA pass summaries. */
730 while (edge->next_callee)
731 edge = edge->next_callee;
732 for (; edge; edge = edge->prev_callee)
733 lto_output_edge (ob, edge, encoder);
736 /* Output the part of the cgraph in SET. */
738 static void
739 output_refs (lto_symtab_encoder_t encoder)
741 struct lto_simple_output_block *ob;
742 int count;
743 struct ipa_ref *ref;
745 ob = lto_create_simple_output_block (LTO_section_refs);
747 for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
749 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
751 /* IPA_REF_ALIAS references are always preserved
752 in the boundary. Alias node can't have other references and
753 can be always handled as if it's not in the boundary. */
754 if (!node->alias && !lto_symtab_encoder_in_partition_p (encoder, node))
755 continue;
757 count = node->ref_list.nreferences ();
758 if (count)
760 streamer_write_gcov_count_stream (ob->main_stream, count);
761 streamer_write_uhwi_stream (ob->main_stream,
762 lto_symtab_encoder_lookup (encoder, node));
763 for (int i = 0; node->iterate_reference (i, ref); i++)
764 lto_output_ref (ob, ref, encoder);
768 streamer_write_uhwi_stream (ob->main_stream, 0);
770 lto_destroy_simple_output_block (ob);
773 /* Add NODE into encoder as well as nodes it is cloned from.
774 Do it in a way so clones appear first. */
776 static void
777 add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node,
778 bool include_body)
780 if (node->clone_of)
781 add_node_to (encoder, node->clone_of, include_body);
782 else if (include_body)
783 lto_set_symtab_encoder_encode_body (encoder, node);
784 lto_symtab_encoder_encode (encoder, node);
787 /* Add all references in NODE to encoders. */
789 static void
790 create_references (lto_symtab_encoder_t encoder, symtab_node *node)
792 int i;
793 struct ipa_ref *ref = NULL;
794 for (i = 0; node->iterate_reference (i, ref); i++)
795 if (is_a <cgraph_node *> (ref->referred))
796 add_node_to (encoder, dyn_cast <cgraph_node *> (ref->referred), false);
797 else
798 lto_symtab_encoder_encode (encoder, ref->referred);
801 /* Select what needs to be streamed out. In regular lto mode stream everything.
802 In offload lto mode stream only nodes marked as offloadable. */
803 void
804 select_what_to_stream (void)
806 struct symtab_node *snode;
807 FOR_EACH_SYMBOL (snode)
808 snode->need_lto_streaming = !lto_stream_offload_p || snode->offloadable;
811 /* Find all symbols we want to stream into given partition and insert them
812 to encoders.
814 The function actually replaces IN_ENCODER by new one. The reason is that
815 streaming code needs clone's origin to be streamed before clone. This
816 means that we need to insert the nodes in specific order. This order is
817 ignored by the partitioning logic earlier. */
819 lto_symtab_encoder_t
820 compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
822 struct cgraph_edge *edge;
823 int i;
824 lto_symtab_encoder_t encoder;
825 lto_symtab_encoder_iterator lsei;
826 hash_set<void *> reachable_call_targets;
828 encoder = lto_symtab_encoder_new (false);
830 /* Go over all entries in the IN_ENCODER and duplicate them to
831 ENCODER. At the same time insert masters of clones so
832 every master appears before clone. */
833 for (lsei = lsei_start_function_in_partition (in_encoder);
834 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
836 struct cgraph_node *node = lsei_cgraph_node (lsei);
837 if (!node->need_lto_streaming)
838 continue;
839 add_node_to (encoder, node, true);
840 lto_set_symtab_encoder_in_partition (encoder, node);
841 create_references (encoder, node);
843 for (lsei = lsei_start_variable_in_partition (in_encoder);
844 !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei))
846 varpool_node *vnode = lsei_varpool_node (lsei);
848 if (!vnode->need_lto_streaming)
849 continue;
850 lto_set_symtab_encoder_in_partition (encoder, vnode);
851 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
852 create_references (encoder, vnode);
854 /* Pickle in also the initializer of all referenced readonly variables
855 to help folding. Constant pool variables are not shared, so we must
856 pickle those too. */
857 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
859 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
860 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
862 if (!lto_symtab_encoder_encode_initializer_p (encoder,
863 vnode)
864 && (((vnode->ctor_useable_for_folding_p ()
865 && (!DECL_VIRTUAL_P (vnode->decl)
866 || !flag_wpa
867 || flag_ltrans_devirtualize)))))
869 lto_set_symtab_encoder_encode_initializer (encoder, vnode);
870 create_references (encoder, vnode);
875 /* Go over all the nodes again to include callees that are not in
876 SET. */
877 for (lsei = lsei_start_function_in_partition (encoder);
878 !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei))
880 struct cgraph_node *node = lsei_cgraph_node (lsei);
881 for (edge = node->callees; edge; edge = edge->next_callee)
883 struct cgraph_node *callee = edge->callee;
884 if (!lto_symtab_encoder_in_partition_p (encoder, callee))
886 /* We should have moved all the inlines. */
887 gcc_assert (!callee->inlined_to);
888 add_node_to (encoder, callee, false);
891 /* Add all possible targets for late devirtualization. */
892 if (flag_ltrans_devirtualize || !flag_wpa)
893 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
894 if (edge->indirect_info->polymorphic)
896 unsigned int i;
897 void *cache_token;
898 bool final;
899 vec <cgraph_node *>targets
900 = possible_polymorphic_call_targets
901 (edge, &final, &cache_token);
902 if (!reachable_call_targets.add (cache_token))
904 for (i = 0; i < targets.length (); i++)
906 struct cgraph_node *callee = targets[i];
908 /* Adding an external declarations into the unit serves
909 no purpose and just increases its boundary. */
910 if (callee->definition
911 && !lto_symtab_encoder_in_partition_p
912 (encoder, callee))
914 gcc_assert (!callee->inlined_to);
915 add_node_to (encoder, callee, false);
921 /* Be sure to also insert alias targert and thunk callees. These needs
922 to stay to aid local calling conventions. */
923 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
925 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
926 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
928 if (node->alias && node->analyzed)
929 create_references (encoder, node);
930 if (cnode
931 && cnode->thunk.thunk_p && !cnode->inlined_to)
932 add_node_to (encoder, cnode->callees->callee, false);
933 while (node->transparent_alias && node->analyzed)
935 node = node->get_alias_target ();
936 if (is_a <cgraph_node *> (node))
937 add_node_to (encoder, dyn_cast <cgraph_node *> (node),
938 false);
939 else
940 lto_symtab_encoder_encode (encoder, node);
943 lto_symtab_encoder_delete (in_encoder);
944 return encoder;
947 /* Output the part of the symtab in SET and VSET. */
949 void
950 output_symtab (void)
952 struct cgraph_node *node;
953 struct lto_simple_output_block *ob;
954 int i, n_nodes;
955 lto_symtab_encoder_t encoder;
957 if (flag_wpa)
958 output_cgraph_opt_summary ();
960 ob = lto_create_simple_output_block (LTO_section_symtab_nodes);
962 output_profile_summary (ob);
964 /* An encoder for cgraph nodes should have been created by
965 ipa_write_summaries_1. */
966 gcc_assert (ob->decl_state->symtab_node_encoder);
967 encoder = ob->decl_state->symtab_node_encoder;
969 /* Write out the nodes. We must first output a node and then its clones,
970 otherwise at a time reading back the node there would be nothing to clone
971 from. */
972 n_nodes = lto_symtab_encoder_size (encoder);
973 for (i = 0; i < n_nodes; i++)
975 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
976 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
977 lto_output_node (ob, cnode, encoder);
978 else
979 lto_output_varpool_node (ob, dyn_cast<varpool_node *> (node), encoder);
982 /* Go over the nodes in SET again to write edges. */
983 for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
985 node = dyn_cast <cgraph_node *> (lto_symtab_encoder_deref (encoder, i));
986 if (node
987 && ((node->thunk.thunk_p && !node->inlined_to)
988 || lto_symtab_encoder_in_partition_p (encoder, node)))
990 output_outgoing_cgraph_edges (node->callees, ob, encoder);
991 output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
995 streamer_write_uhwi_stream (ob->main_stream, 0);
997 lto_destroy_simple_output_block (ob);
999 /* Emit toplevel asms.
1000 When doing WPA we must output every asm just once. Since we do not partition asm
1001 nodes at all, output them to first output. This is kind of hack, but should work
1002 well. */
1003 if (!asm_nodes_output)
1005 asm_nodes_output = true;
1006 lto_output_toplevel_asms ();
1009 output_refs (encoder);
1012 /* Return identifier encoded in IB as a plain string. */
1014 static tree
1015 read_identifier (class lto_input_block *ib)
1017 unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
1018 tree id;
1020 if (ib->data[ib->p + len])
1021 lto_section_overrun (ib);
1022 if (!len)
1024 ib->p++;
1025 return NULL;
1027 id = get_identifier (ib->data + ib->p);
1028 ib->p += len + 1;
1029 return id;
1032 /* Return string encoded in IB, NULL if string is empty. */
1034 static const char *
1035 read_string (class lto_input_block *ib)
1037 unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1);
1038 const char *str;
1040 if (ib->data[ib->p + len])
1041 lto_section_overrun (ib);
1042 if (!len)
1044 ib->p++;
1045 return NULL;
1047 str = ib->data + ib->p;
1048 ib->p += len + 1;
1049 return str;
1052 /* Output function/variable tables that will allow libgomp to look up offload
1053 target code.
1054 OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
1055 varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
1056 both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
1058 void
1059 output_offload_tables (void)
1061 if (vec_safe_is_empty (offload_funcs) && vec_safe_is_empty (offload_vars))
1062 return;
1064 struct lto_simple_output_block *ob
1065 = lto_create_simple_output_block (LTO_section_offload_table);
1067 for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++)
1069 streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1070 LTO_symtab_last_tag, LTO_symtab_unavail_node);
1071 lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
1072 (*offload_funcs)[i]);
1075 for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
1077 streamer_write_enum (ob->main_stream, LTO_symtab_tags,
1078 LTO_symtab_last_tag, LTO_symtab_variable);
1079 lto_output_var_decl_index (ob->decl_state, ob->main_stream,
1080 (*offload_vars)[i]);
1083 streamer_write_uhwi_stream (ob->main_stream, 0);
1084 lto_destroy_simple_output_block (ob);
1086 /* In WHOPR mode during the WPA stage the joint offload tables need to be
1087 streamed to one partition only. That's why we free offload_funcs and
1088 offload_vars after the first call of output_offload_tables. */
1089 if (flag_wpa)
1091 vec_free (offload_funcs);
1092 vec_free (offload_vars);
1096 /* Verify the partitioning of NODE. */
1098 static inline void
1099 verify_node_partition (symtab_node *node)
1101 if (flag_ltrans)
1102 return;
1104 #ifdef ACCEL_COMPILER
1105 if (node->in_other_partition)
1107 if (TREE_CODE (node->decl) == FUNCTION_DECL)
1108 error_at (DECL_SOURCE_LOCATION (node->decl),
1109 "function %qs has been referenced in offloaded code but"
1110 " hasn%'t been marked to be included in the offloaded code",
1111 node->name ());
1112 else if (VAR_P (node->decl))
1113 error_at (DECL_SOURCE_LOCATION (node->decl),
1114 "variable %qs has been referenced in offloaded code but"
1115 " hasn%'t been marked to be included in the offloaded code",
1116 node->name ());
1117 else
1118 gcc_unreachable ();
1120 #else
1121 gcc_assert (!node->in_other_partition
1122 && !node->used_from_other_partition);
1123 #endif
1126 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
1127 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
1128 NODE or to replace the values in it, for instance because the first
1129 time we saw it, the function body was not available but now it
1130 is. BP is a bitpack with all the bitflags for NODE read from the
1131 stream. */
1133 static void
1134 input_overwrite_node (struct lto_file_decl_data *file_data,
1135 struct cgraph_node *node,
1136 enum LTO_symtab_tags tag,
1137 struct bitpack_d *bp)
1139 node->aux = (void *) tag;
1140 node->lto_file_data = file_data;
1142 node->local = bp_unpack_value (bp, 1);
1143 node->externally_visible = bp_unpack_value (bp, 1);
1144 node->no_reorder = bp_unpack_value (bp, 1);
1145 node->definition = bp_unpack_value (bp, 1);
1146 node->versionable = bp_unpack_value (bp, 1);
1147 node->can_change_signature = bp_unpack_value (bp, 1);
1148 node->redefined_extern_inline = bp_unpack_value (bp, 1);
1149 node->force_output = bp_unpack_value (bp, 1);
1150 node->forced_by_abi = bp_unpack_value (bp, 1);
1151 node->unique_name = bp_unpack_value (bp, 1);
1152 node->body_removed = bp_unpack_value (bp, 1);
1153 node->implicit_section = bp_unpack_value (bp, 1);
1154 node->address_taken = bp_unpack_value (bp, 1);
1155 node->used_from_other_partition = bp_unpack_value (bp, 1);
1156 node->lowered = bp_unpack_value (bp, 1);
1157 node->analyzed = tag == LTO_symtab_analyzed_node;
1158 node->in_other_partition = bp_unpack_value (bp, 1);
1159 if (node->in_other_partition
1160 /* Avoid updating decl when we are seeing just inline clone.
1161 When inlining function that has functions already inlined into it,
1162 we produce clones of inline clones.
1164 WPA partitioning might put each clone into different unit and
1165 we might end up streaming inline clone from other partition
1166 to support clone we are interested in. */
1167 && (!node->clone_of
1168 || node->clone_of->decl != node->decl))
1170 DECL_EXTERNAL (node->decl) = 1;
1171 TREE_STATIC (node->decl) = 0;
1173 node->alias = bp_unpack_value (bp, 1);
1174 node->transparent_alias = bp_unpack_value (bp, 1);
1175 node->weakref = bp_unpack_value (bp, 1);
1176 node->symver = bp_unpack_value (bp, 1);
1177 node->frequency = (enum node_frequency)bp_unpack_value (bp, 2);
1178 node->only_called_at_startup = bp_unpack_value (bp, 1);
1179 node->only_called_at_exit = bp_unpack_value (bp, 1);
1180 node->tm_clone = bp_unpack_value (bp, 1);
1181 node->calls_comdat_local = bp_unpack_value (bp, 1);
1182 node->icf_merged = bp_unpack_value (bp, 1);
1183 node->nonfreeing_fn = bp_unpack_value (bp, 1);
1184 node->merged_comdat = bp_unpack_value (bp, 1);
1185 node->merged_extern_inline = bp_unpack_value (bp, 1);
1186 node->thunk.thunk_p = bp_unpack_value (bp, 1);
1187 node->parallelized_function = bp_unpack_value (bp, 1);
1188 node->resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution,
1189 LDPR_NUM_KNOWN);
1190 node->split_part = bp_unpack_value (bp, 1);
1191 verify_node_partition (node);
1194 /* Return string alias is alias of. */
1196 static tree
1197 get_alias_symbol (tree decl)
1199 tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1200 return get_identifier (TREE_STRING_POINTER
1201 (TREE_VALUE (TREE_VALUE (alias))));
1204 /* Read a node from input_block IB. TAG is the node's tag just read.
1205 Return the node read or overwriten. */
1207 static struct cgraph_node *
1208 input_node (struct lto_file_decl_data *file_data,
1209 class lto_input_block *ib,
1210 enum LTO_symtab_tags tag,
1211 vec<symtab_node *> nodes)
1213 gcc::pass_manager *passes = g->get_passes ();
1214 tree fn_decl;
1215 struct cgraph_node *node;
1216 struct bitpack_d bp;
1217 unsigned decl_index;
1218 int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND;
1219 int clone_ref;
1220 int order;
1221 int i, count;
1222 tree group;
1223 const char *section;
1224 order = streamer_read_hwi (ib) + file_data->order_base;
1225 clone_ref = streamer_read_hwi (ib);
1227 decl_index = streamer_read_uhwi (ib);
1228 fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1230 if (clone_ref != LCC_NOT_FOUND)
1232 node = dyn_cast<cgraph_node *> (nodes[clone_ref])->create_clone (fn_decl,
1233 profile_count::uninitialized (), false,
1234 vNULL, false, NULL, NULL);
1236 else
1238 /* Declaration of functions can be already merged with a declaration
1239 from other input file. We keep cgraph unmerged until after streaming
1240 of ipa passes is done. Alays forcingly create a fresh node. */
1241 node = symtab->create_empty ();
1242 node->decl = fn_decl;
1243 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (fn_decl)))
1244 node->ifunc_resolver = 1;
1245 node->register_symbol ();
1248 node->order = order;
1249 if (order >= symtab->order)
1250 symtab->order = order + 1;
1252 node->count = profile_count::stream_in (ib);
1253 node->count_materialization_scale = streamer_read_hwi (ib);
1255 count = streamer_read_hwi (ib);
1256 node->ipa_transforms_to_apply = vNULL;
1257 for (i = 0; i < count; i++)
1259 opt_pass *pass;
1260 int pid = streamer_read_hwi (ib);
1262 gcc_assert (pid < passes->passes_by_id_size);
1263 pass = passes->passes_by_id[pid];
1264 node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *) pass);
1267 if (tag == LTO_symtab_analyzed_node)
1268 ref = streamer_read_hwi (ib);
1270 group = read_identifier (ib);
1271 if (group)
1272 ref2 = streamer_read_hwi (ib);
1274 /* Make sure that we have not read this node before. Nodes that
1275 have already been read will have their tag stored in the 'aux'
1276 field. Since built-in functions can be referenced in multiple
1277 functions, they are expected to be read more than once. */
1278 if (node->aux && !fndecl_built_in_p (node->decl))
1279 internal_error ("bytecode stream: found multiple instances of cgraph "
1280 "node with uid %d", node->get_uid ());
1282 node->tp_first_run = streamer_read_uhwi (ib);
1284 bp = streamer_read_bitpack (ib);
1286 input_overwrite_node (file_data, node, tag, &bp);
1288 /* Store a reference for now, and fix up later to be a pointer. */
1289 node->inlined_to = (cgraph_node *) (intptr_t) ref;
1291 if (group)
1293 node->set_comdat_group (group);
1294 /* Store a reference for now, and fix up later to be a pointer. */
1295 node->same_comdat_group = (symtab_node *) (intptr_t) ref2;
1297 else
1298 node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
1299 section = read_string (ib);
1300 if (section)
1301 node->set_section_for_node (section);
1303 if (node->definition)
1305 int type = streamer_read_uhwi (ib);
1306 HOST_WIDE_INT fixed_offset = streamer_read_uhwi (ib);
1307 HOST_WIDE_INT virtual_value = streamer_read_uhwi (ib);
1308 HOST_WIDE_INT indirect_offset = streamer_read_uhwi (ib);
1310 node->thunk.fixed_offset = fixed_offset;
1311 node->thunk.virtual_value = virtual_value;
1312 node->thunk.indirect_offset = indirect_offset;
1313 node->thunk.this_adjusting = (type & 2);
1314 node->thunk.virtual_offset_p = (type & 4);
1316 if (node->alias && !node->analyzed && node->weakref)
1317 node->alias_target = get_alias_symbol (node->decl);
1318 node->profile_id = streamer_read_hwi (ib);
1319 node->unit_id = streamer_read_hwi (ib) + file_data->unit_base;
1320 if (symtab->max_unit < node->unit_id)
1321 symtab->max_unit = node->unit_id;
1322 if (DECL_STATIC_CONSTRUCTOR (node->decl))
1323 node->set_init_priority (streamer_read_hwi (ib));
1324 if (DECL_STATIC_DESTRUCTOR (node->decl))
1325 node->set_fini_priority (streamer_read_hwi (ib));
1327 return node;
1330 /* Read a node from input_block IB. TAG is the node's tag just read.
1331 Return the node read or overwriten. */
1333 static varpool_node *
1334 input_varpool_node (struct lto_file_decl_data *file_data,
1335 class lto_input_block *ib)
1337 int decl_index;
1338 tree var_decl;
1339 varpool_node *node;
1340 struct bitpack_d bp;
1341 int ref = LCC_NOT_FOUND;
1342 int order;
1343 tree group;
1344 const char *section;
1346 order = streamer_read_hwi (ib) + file_data->order_base;
1347 decl_index = streamer_read_uhwi (ib);
1348 var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index);
1350 /* Declaration of functions can be already merged with a declaration
1351 from other input file. We keep cgraph unmerged until after streaming
1352 of ipa passes is done. Alays forcingly create a fresh node. */
1353 node = varpool_node::create_empty ();
1354 node->decl = var_decl;
1355 node->register_symbol ();
1357 node->order = order;
1358 if (order >= symtab->order)
1359 symtab->order = order + 1;
1360 node->lto_file_data = file_data;
1362 bp = streamer_read_bitpack (ib);
1363 node->externally_visible = bp_unpack_value (&bp, 1);
1364 node->no_reorder = bp_unpack_value (&bp, 1);
1365 node->force_output = bp_unpack_value (&bp, 1);
1366 node->forced_by_abi = bp_unpack_value (&bp, 1);
1367 node->unique_name = bp_unpack_value (&bp, 1);
1368 node->body_removed = bp_unpack_value (&bp, 1);
1369 node->implicit_section = bp_unpack_value (&bp, 1);
1370 node->writeonly = bp_unpack_value (&bp, 1);
1371 node->definition = bp_unpack_value (&bp, 1);
1372 node->alias = bp_unpack_value (&bp, 1);
1373 node->transparent_alias = bp_unpack_value (&bp, 1);
1374 node->weakref = bp_unpack_value (&bp, 1);
1375 node->symver = bp_unpack_value (&bp, 1);
1376 node->analyzed = bp_unpack_value (&bp, 1);
1377 node->used_from_other_partition = bp_unpack_value (&bp, 1);
1378 node->in_other_partition = bp_unpack_value (&bp, 1);
1379 if (node->in_other_partition)
1381 DECL_EXTERNAL (node->decl) = 1;
1382 TREE_STATIC (node->decl) = 0;
1384 if (node->alias && !node->analyzed && node->weakref)
1385 node->alias_target = get_alias_symbol (node->decl);
1386 node->tls_model = (enum tls_model)bp_unpack_value (&bp, 3);
1387 node->used_by_single_function = (enum tls_model)bp_unpack_value (&bp, 1);
1388 node->dynamically_initialized = bp_unpack_value (&bp, 1);
1389 group = read_identifier (ib);
1390 if (group)
1392 node->set_comdat_group (group);
1393 ref = streamer_read_hwi (ib);
1394 /* Store a reference for now, and fix up later to be a pointer. */
1395 node->same_comdat_group = (symtab_node *) (intptr_t) ref;
1397 else
1398 node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND;
1399 section = read_string (ib);
1400 if (section)
1401 node->set_section_for_node (section);
1402 node->resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution,
1403 LDPR_NUM_KNOWN);
1404 verify_node_partition (node);
1405 return node;
1408 /* Read a node from input_block IB. TAG is the node's tag just read.
1409 Return the node read or overwriten. */
1411 static void
1412 input_ref (class lto_input_block *ib,
1413 symtab_node *referring_node,
1414 vec<symtab_node *> nodes)
1416 symtab_node *node = NULL;
1417 struct bitpack_d bp;
1418 enum ipa_ref_use use;
1419 bool speculative;
1420 struct ipa_ref *ref;
1422 bp = streamer_read_bitpack (ib);
1423 use = (enum ipa_ref_use) bp_unpack_value (&bp, 3);
1424 speculative = (enum ipa_ref_use) bp_unpack_value (&bp, 1);
1425 node = nodes[streamer_read_hwi (ib)];
1426 ref = referring_node->create_reference (node, use);
1427 ref->speculative = speculative;
1428 if (is_a <cgraph_node *> (referring_node))
1430 ref->lto_stmt_uid = streamer_read_hwi (ib);
1431 bp = streamer_read_bitpack (ib);
1432 ref->speculative_id = bp_unpack_value (&bp, 16);
1436 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1437 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1438 edge being read is indirect (in the sense that it has
1439 indirect_unknown_callee set). */
1441 static void
1442 input_edge (class lto_input_block *ib, vec<symtab_node *> nodes,
1443 bool indirect)
1445 struct cgraph_node *caller, *callee;
1446 struct cgraph_edge *edge;
1447 unsigned int stmt_id, speculative_id;
1448 profile_count count;
1449 cgraph_inline_failed_t inline_failed;
1450 struct bitpack_d bp;
1451 int ecf_flags = 0;
1453 caller = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
1454 if (caller == NULL || caller->decl == NULL_TREE)
1455 internal_error ("bytecode stream: no caller found while reading edge");
1457 if (!indirect)
1459 callee = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]);
1460 if (callee == NULL || callee->decl == NULL_TREE)
1461 internal_error ("bytecode stream: no callee found while reading edge");
1463 else
1464 callee = NULL;
1466 count = profile_count::stream_in (ib);
1468 bp = streamer_read_bitpack (ib);
1469 inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_t, CIF_N_REASONS);
1470 stmt_id = bp_unpack_var_len_unsigned (&bp);
1471 speculative_id = bp_unpack_value (&bp, 16);
1473 if (indirect)
1474 edge = caller->create_indirect_edge (NULL, 0, count);
1475 else
1476 edge = caller->create_edge (callee, NULL, count);
1478 edge->indirect_inlining_edge = bp_unpack_value (&bp, 1);
1479 edge->speculative = bp_unpack_value (&bp, 1);
1480 edge->lto_stmt_uid = stmt_id;
1481 edge->speculative_id = speculative_id;
1482 edge->inline_failed = inline_failed;
1483 edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1);
1484 edge->can_throw_external = bp_unpack_value (&bp, 1);
1485 edge->in_polymorphic_cdtor = bp_unpack_value (&bp, 1);
1486 if (indirect)
1488 if (bp_unpack_value (&bp, 1))
1489 ecf_flags |= ECF_CONST;
1490 if (bp_unpack_value (&bp, 1))
1491 ecf_flags |= ECF_PURE;
1492 if (bp_unpack_value (&bp, 1))
1493 ecf_flags |= ECF_NORETURN;
1494 if (bp_unpack_value (&bp, 1))
1495 ecf_flags |= ECF_MALLOC;
1496 if (bp_unpack_value (&bp, 1))
1497 ecf_flags |= ECF_NOTHROW;
1498 if (bp_unpack_value (&bp, 1))
1499 ecf_flags |= ECF_RETURNS_TWICE;
1500 edge->indirect_info->ecf_flags = ecf_flags;
1502 edge->indirect_info->num_speculative_call_targets
1503 = bp_unpack_value (&bp, 16);
1508 /* Read a cgraph from IB using the info in FILE_DATA. */
1510 static vec<symtab_node *>
1511 input_cgraph_1 (struct lto_file_decl_data *file_data,
1512 class lto_input_block *ib)
1514 enum LTO_symtab_tags tag;
1515 vec<symtab_node *> nodes = vNULL;
1516 symtab_node *node;
1517 unsigned i;
1519 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1520 file_data->order_base = symtab->order;
1521 file_data->unit_base = symtab->max_unit + 1;
1522 while (tag)
1524 if (tag == LTO_symtab_edge)
1525 input_edge (ib, nodes, false);
1526 else if (tag == LTO_symtab_indirect_edge)
1527 input_edge (ib, nodes, true);
1528 else if (tag == LTO_symtab_variable)
1530 node = input_varpool_node (file_data, ib);
1531 nodes.safe_push (node);
1532 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1534 else
1536 node = input_node (file_data, ib, tag, nodes);
1537 if (node == NULL || node->decl == NULL_TREE)
1538 internal_error ("bytecode stream: found empty cgraph node");
1539 nodes.safe_push (node);
1540 lto_symtab_encoder_encode (file_data->symtab_node_encoder, node);
1543 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1546 lto_input_toplevel_asms (file_data, file_data->order_base);
1548 /* AUX pointers should be all non-zero for function nodes read from the stream. */
1549 if (flag_checking)
1551 FOR_EACH_VEC_ELT (nodes, i, node)
1552 gcc_assert (node->aux || !is_a <cgraph_node *> (node));
1554 FOR_EACH_VEC_ELT (nodes, i, node)
1556 int ref;
1557 if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node))
1559 ref = (int) (intptr_t) cnode->inlined_to;
1561 /* We share declaration of builtins, so we may read same node twice. */
1562 if (!node->aux)
1563 continue;
1564 node->aux = NULL;
1566 /* Fixup inlined_to from reference to pointer. */
1567 if (ref != LCC_NOT_FOUND)
1568 dyn_cast<cgraph_node *> (node)->inlined_to
1569 = dyn_cast<cgraph_node *> (nodes[ref]);
1570 else
1571 cnode->inlined_to = NULL;
1574 ref = (int) (intptr_t) node->same_comdat_group;
1576 /* Fixup same_comdat_group from reference to pointer. */
1577 if (ref != LCC_NOT_FOUND)
1578 node->same_comdat_group = nodes[ref];
1579 else
1580 node->same_comdat_group = NULL;
1582 FOR_EACH_VEC_ELT (nodes, i, node)
1583 node->aux = is_a <cgraph_node *> (node) ? (void *)1 : NULL;
1584 return nodes;
1587 /* Input ipa_refs. */
1589 static void
1590 input_refs (class lto_input_block *ib,
1591 vec<symtab_node *> nodes)
1593 int count;
1594 int idx;
1595 while (true)
1597 symtab_node *node;
1598 count = streamer_read_uhwi (ib);
1599 if (!count)
1600 break;
1601 idx = streamer_read_uhwi (ib);
1602 node = nodes[idx];
1603 while (count)
1605 input_ref (ib, node, nodes);
1606 count--;
1611 /* Input profile_info from IB. */
1612 static void
1613 input_profile_summary (class lto_input_block *ib,
1614 struct lto_file_decl_data *file_data)
1616 unsigned int runs = streamer_read_uhwi (ib);
1617 if (runs)
1619 file_data->profile_info.runs = runs;
1621 /* IPA-profile computes hot bb threshold based on cumulated
1622 whole program profile. We need to stream it down to ltrans. */
1623 if (flag_ltrans)
1624 set_hot_bb_threshold (streamer_read_gcov_count (ib));
1629 /* Rescale profile summaries to the same number of runs in the whole unit. */
1631 static void
1632 merge_profile_summaries (struct lto_file_decl_data **file_data_vec)
1634 struct lto_file_decl_data *file_data;
1635 unsigned int j;
1636 gcov_unsigned_t max_runs = 0;
1637 struct cgraph_node *node;
1638 struct cgraph_edge *edge;
1640 /* Find unit with maximal number of runs. If we ever get serious about
1641 roundoff errors, we might also consider computing smallest common
1642 multiply. */
1643 for (j = 0; (file_data = file_data_vec[j]) != NULL; j++)
1644 if (max_runs < file_data->profile_info.runs)
1645 max_runs = file_data->profile_info.runs;
1647 if (!max_runs)
1648 return;
1650 /* Simple overflow check. We probably don't need to support that many train
1651 runs. Such a large value probably imply data corruption anyway. */
1652 if (max_runs > INT_MAX / REG_BR_PROB_BASE)
1654 sorry ("At most %i profile runs is supported. Perhaps corrupted profile?",
1655 INT_MAX / REG_BR_PROB_BASE);
1656 return;
1659 profile_info = XCNEW (gcov_summary);
1660 profile_info->runs = max_runs;
1662 /* If merging already happent at WPA time, we are done. */
1663 if (flag_ltrans)
1664 return;
1666 /* Now compute count_materialization_scale of each node.
1667 During LTRANS we already have values of count_materialization_scale
1668 computed, so just update them. */
1669 FOR_EACH_FUNCTION (node)
1670 if (node->lto_file_data
1671 && node->lto_file_data->profile_info.runs)
1673 int scale;
1675 scale = RDIV (node->count_materialization_scale * max_runs,
1676 node->lto_file_data->profile_info.runs);
1677 node->count_materialization_scale = scale;
1678 if (scale < 0)
1679 fatal_error (input_location, "Profile information in %s corrupted",
1680 file_data->file_name);
1682 if (scale == REG_BR_PROB_BASE)
1683 continue;
1684 for (edge = node->callees; edge; edge = edge->next_callee)
1685 if (edge->count.ipa ().nonzero_p ())
1686 edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
1687 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
1688 if (edge->count.ipa ().nonzero_p ())
1689 edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE);
1690 if (node->count.ipa ().nonzero_p ())
1691 node->count = node->count.apply_scale (scale, REG_BR_PROB_BASE);
1695 /* Input and merge the symtab from each of the .o files passed to
1696 lto1. */
1698 void
1699 input_symtab (void)
1701 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1702 struct lto_file_decl_data *file_data;
1703 unsigned int j = 0;
1704 struct cgraph_node *node;
1706 while ((file_data = file_data_vec[j++]))
1708 const char *data;
1709 size_t len;
1710 class lto_input_block *ib;
1711 vec<symtab_node *> nodes;
1713 ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes,
1714 &data, &len);
1715 if (!ib)
1716 fatal_error (input_location,
1717 "cannot find LTO cgraph in %s", file_data->file_name);
1718 input_profile_summary (ib, file_data);
1719 file_data->symtab_node_encoder = lto_symtab_encoder_new (true);
1720 nodes = input_cgraph_1 (file_data, ib);
1721 lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes,
1722 ib, data, len);
1724 ib = lto_create_simple_input_block (file_data, LTO_section_refs,
1725 &data, &len);
1726 if (!ib)
1727 fatal_error (input_location, "cannot find LTO section refs in %s",
1728 file_data->file_name);
1729 input_refs (ib, nodes);
1730 lto_destroy_simple_input_block (file_data, LTO_section_refs,
1731 ib, data, len);
1732 if (flag_ltrans)
1733 input_cgraph_opt_summary (nodes);
1734 nodes.release ();
1737 merge_profile_summaries (file_data_vec);
1739 /* Clear out the aux field that was used to store enough state to
1740 tell which nodes should be overwritten. */
1741 FOR_EACH_FUNCTION (node)
1743 /* Some nodes may have been created by cgraph_node. This
1744 happens when the callgraph contains nested functions. If the
1745 node for the parent function was never emitted to the gimple
1746 file, cgraph_node will create a node for it when setting the
1747 context of the nested function. */
1748 if (node->lto_file_data)
1749 node->aux = NULL;
1753 /* Input function/variable tables that will allow libgomp to look up offload
1754 target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
1756 void
1757 input_offload_tables (bool do_force_output)
1759 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1760 struct lto_file_decl_data *file_data;
1761 unsigned int j = 0;
1763 while ((file_data = file_data_vec[j++]))
1765 const char *data;
1766 size_t len;
1767 class lto_input_block *ib
1768 = lto_create_simple_input_block (file_data, LTO_section_offload_table,
1769 &data, &len);
1770 if (!ib)
1771 continue;
1773 enum LTO_symtab_tags tag
1774 = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1775 while (tag)
1777 if (tag == LTO_symtab_unavail_node)
1779 int decl_index = streamer_read_uhwi (ib);
1780 tree fn_decl
1781 = lto_file_decl_data_get_fn_decl (file_data, decl_index);
1782 vec_safe_push (offload_funcs, fn_decl);
1784 /* Prevent IPA from removing fn_decl as unreachable, since there
1785 may be no refs from the parent function to child_fn in offload
1786 LTO mode. */
1787 if (do_force_output)
1788 cgraph_node::get (fn_decl)->mark_force_output ();
1790 else if (tag == LTO_symtab_variable)
1792 int decl_index = streamer_read_uhwi (ib);
1793 tree var_decl
1794 = lto_file_decl_data_get_var_decl (file_data, decl_index);
1795 vec_safe_push (offload_vars, var_decl);
1797 /* Prevent IPA from removing var_decl as unused, since there
1798 may be no refs to var_decl in offload LTO mode. */
1799 if (do_force_output)
1800 varpool_node::get (var_decl)->force_output = 1;
1802 else
1803 fatal_error (input_location,
1804 "invalid offload table in %s", file_data->file_name);
1806 tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
1809 lto_destroy_simple_input_block (file_data, LTO_section_offload_table,
1810 ib, data, len);
1814 /* True when we need optimization summary for NODE. */
1816 static int
1817 output_cgraph_opt_summary_p (struct cgraph_node *node)
1819 return ((node->clone_of || node->former_clone_of)
1820 && (node->clone.tree_map
1821 || node->clone.param_adjustments));
1824 /* Output optimization summary for EDGE to OB. */
1825 static void
1826 output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED,
1827 struct cgraph_edge *edge ATTRIBUTE_UNUSED)
1831 /* Output optimization summary for NODE to OB. */
1833 static void
1834 output_node_opt_summary (struct output_block *ob,
1835 struct cgraph_node *node,
1836 lto_symtab_encoder_t encoder)
1838 struct ipa_replace_map *map;
1839 int i;
1840 struct cgraph_edge *e;
1842 /* TODO: Should this code be moved to ipa-param-manipulation? */
1843 struct bitpack_d bp;
1844 bp = bitpack_create (ob->main_stream);
1845 bp_pack_value (&bp, (node->clone.param_adjustments != NULL), 1);
1846 streamer_write_bitpack (&bp);
1847 if (ipa_param_adjustments *adjustments = node->clone.param_adjustments)
1849 streamer_write_uhwi (ob, vec_safe_length (adjustments->m_adj_params));
1850 ipa_adjusted_param *adj;
1851 FOR_EACH_VEC_SAFE_ELT (adjustments->m_adj_params, i, adj)
1853 bp = bitpack_create (ob->main_stream);
1854 bp_pack_value (&bp, adj->base_index, IPA_PARAM_MAX_INDEX_BITS);
1855 bp_pack_value (&bp, adj->prev_clone_index, IPA_PARAM_MAX_INDEX_BITS);
1856 bp_pack_value (&bp, adj->op, 2);
1857 bp_pack_value (&bp, adj->param_prefix_index, 2);
1858 bp_pack_value (&bp, adj->prev_clone_adjustment, 1);
1859 bp_pack_value (&bp, adj->reverse, 1);
1860 bp_pack_value (&bp, adj->user_flag, 1);
1861 streamer_write_bitpack (&bp);
1862 if (adj->op == IPA_PARAM_OP_SPLIT
1863 || adj->op == IPA_PARAM_OP_NEW)
1865 stream_write_tree (ob, adj->type, true);
1866 if (adj->op == IPA_PARAM_OP_SPLIT)
1868 stream_write_tree (ob, adj->alias_ptr_type, true);
1869 streamer_write_uhwi (ob, adj->unit_offset);
1873 streamer_write_hwi (ob, adjustments->m_always_copy_start);
1874 bp = bitpack_create (ob->main_stream);
1875 bp_pack_value (&bp, node->clone.param_adjustments->m_skip_return, 1);
1876 streamer_write_bitpack (&bp);
1879 streamer_write_uhwi (ob, vec_safe_length (node->clone.tree_map));
1880 FOR_EACH_VEC_SAFE_ELT (node->clone.tree_map, i, map)
1882 streamer_write_uhwi (ob, map->parm_num);
1883 gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION);
1884 stream_write_tree (ob, map->new_tree, true);
1887 if (lto_symtab_encoder_in_partition_p (encoder, node))
1889 for (e = node->callees; e; e = e->next_callee)
1890 output_edge_opt_summary (ob, e);
1891 for (e = node->indirect_calls; e; e = e->next_callee)
1892 output_edge_opt_summary (ob, e);
1896 /* Output optimization summaries stored in callgraph.
1897 At the moment it is the clone info structure. */
1899 static void
1900 output_cgraph_opt_summary (void)
1902 int i, n_nodes;
1903 lto_symtab_encoder_t encoder;
1904 struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum);
1905 unsigned count = 0;
1907 ob->symbol = NULL;
1908 encoder = ob->decl_state->symtab_node_encoder;
1909 n_nodes = lto_symtab_encoder_size (encoder);
1910 for (i = 0; i < n_nodes; i++)
1912 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
1913 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
1914 if (cnode && output_cgraph_opt_summary_p (cnode))
1915 count++;
1917 streamer_write_uhwi (ob, count);
1918 for (i = 0; i < n_nodes; i++)
1920 symtab_node *node = lto_symtab_encoder_deref (encoder, i);
1921 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
1922 if (cnode && output_cgraph_opt_summary_p (cnode))
1924 streamer_write_uhwi (ob, i);
1925 output_node_opt_summary (ob, cnode, encoder);
1928 produce_asm (ob, NULL);
1929 destroy_output_block (ob);
1932 /* Input optimisation summary of EDGE. */
1934 static void
1935 input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED,
1936 class lto_input_block *ib_main ATTRIBUTE_UNUSED)
1940 /* Input optimisation summary of NODE. */
1942 static void
1943 input_node_opt_summary (struct cgraph_node *node,
1944 class lto_input_block *ib_main,
1945 class data_in *data_in)
1947 int i;
1948 int count;
1949 struct cgraph_edge *e;
1951 /* TODO: Should this code be moved to ipa-param-manipulation? */
1952 struct bitpack_d bp;
1953 bp = streamer_read_bitpack (ib_main);
1954 bool have_adjustments = bp_unpack_value (&bp, 1);
1955 if (have_adjustments)
1957 count = streamer_read_uhwi (ib_main);
1958 vec<ipa_adjusted_param, va_gc> *new_params = NULL;
1959 for (i = 0; i < count; i++)
1961 ipa_adjusted_param adj;
1962 memset (&adj, 0, sizeof (adj));
1963 bp = streamer_read_bitpack (ib_main);
1964 adj.base_index = bp_unpack_value (&bp, IPA_PARAM_MAX_INDEX_BITS);
1965 adj.prev_clone_index
1966 = bp_unpack_value (&bp, IPA_PARAM_MAX_INDEX_BITS);
1967 adj.op = (enum ipa_parm_op) bp_unpack_value (&bp, 2);
1968 adj.param_prefix_index = bp_unpack_value (&bp, 2);
1969 adj.prev_clone_adjustment = bp_unpack_value (&bp, 1);
1970 adj.reverse = bp_unpack_value (&bp, 1);
1971 adj.user_flag = bp_unpack_value (&bp, 1);
1972 if (adj.op == IPA_PARAM_OP_SPLIT
1973 || adj.op == IPA_PARAM_OP_NEW)
1975 adj.type = stream_read_tree (ib_main, data_in);
1976 if (adj.op == IPA_PARAM_OP_SPLIT)
1978 adj.alias_ptr_type = stream_read_tree (ib_main, data_in);
1979 adj.unit_offset = streamer_read_uhwi (ib_main);
1982 vec_safe_push (new_params, adj);
1984 int always_copy_start = streamer_read_hwi (ib_main);
1985 bp = streamer_read_bitpack (ib_main);
1986 bool skip_return = bp_unpack_value (&bp, 1);
1987 node->clone.param_adjustments
1988 = (new (ggc_alloc <ipa_param_adjustments> ())
1989 ipa_param_adjustments (new_params, always_copy_start, skip_return));
1992 count = streamer_read_uhwi (ib_main);
1993 for (i = 0; i < count; i++)
1995 struct ipa_replace_map *map = ggc_alloc<ipa_replace_map> ();
1997 vec_safe_push (node->clone.tree_map, map);
1998 map->parm_num = streamer_read_uhwi (ib_main);
1999 map->new_tree = stream_read_tree (ib_main, data_in);
2001 for (e = node->callees; e; e = e->next_callee)
2002 input_edge_opt_summary (e, ib_main);
2003 for (e = node->indirect_calls; e; e = e->next_callee)
2004 input_edge_opt_summary (e, ib_main);
2007 /* Read section in file FILE_DATA of length LEN with data DATA. */
2009 static void
2010 input_cgraph_opt_section (struct lto_file_decl_data *file_data,
2011 const char *data, size_t len,
2012 vec<symtab_node *> nodes)
2014 const struct lto_function_header *header =
2015 (const struct lto_function_header *) data;
2016 const int cfg_offset = sizeof (struct lto_function_header);
2017 const int main_offset = cfg_offset + header->cfg_size;
2018 const int string_offset = main_offset + header->main_size;
2019 class data_in *data_in;
2020 unsigned int i;
2021 unsigned int count;
2023 lto_input_block ib_main ((const char *) data + main_offset,
2024 header->main_size, file_data->mode_table);
2026 data_in =
2027 lto_data_in_create (file_data, (const char *) data + string_offset,
2028 header->string_size, vNULL);
2029 count = streamer_read_uhwi (&ib_main);
2031 for (i = 0; i < count; i++)
2033 int ref = streamer_read_uhwi (&ib_main);
2034 input_node_opt_summary (dyn_cast<cgraph_node *> (nodes[ref]),
2035 &ib_main, data_in);
2037 lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data,
2038 len);
2039 lto_data_in_delete (data_in);
2042 /* Input optimization summary of cgraph. */
2044 static void
2045 input_cgraph_opt_summary (vec<symtab_node *> nodes)
2047 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
2048 struct lto_file_decl_data *file_data;
2049 unsigned int j = 0;
2051 while ((file_data = file_data_vec[j++]))
2053 size_t len;
2054 const char *data
2055 = lto_get_summary_section_data (file_data, LTO_section_cgraph_opt_sum,
2056 &len);
2057 if (data)
2058 input_cgraph_opt_section (file_data, data, len, nodes);