lto-cgraph.c (output_cgraph): Remove loop adding all varpool nodes into every boundary.
[gcc.git] / gcc / lto-cgraph.c
1 /* Write and read the cgraph to the memory mapped representation of a
2 .o file.
3
4 Copyright 2009 Free Software Foundation, Inc.
5 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
6
7 This file is part of GCC.
8
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.
13
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.
18
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/>. */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "toplev.h"
28 #include "tree.h"
29 #include "expr.h"
30 #include "flags.h"
31 #include "params.h"
32 #include "input.h"
33 #include "hashtab.h"
34 #include "langhooks.h"
35 #include "basic-block.h"
36 #include "tree-flow.h"
37 #include "cgraph.h"
38 #include "function.h"
39 #include "ggc.h"
40 #include "diagnostic.h"
41 #include "except.h"
42 #include "vec.h"
43 #include "timevar.h"
44 #include "output.h"
45 #include "pointer-set.h"
46 #include "lto-streamer.h"
47 #include "gcov-io.h"
48
49 static void output_varpool (cgraph_node_set, varpool_node_set);
50
51 /* Cgraph streaming is organized as set of record whose type
52 is indicated by a tag. */
53 enum LTO_cgraph_tags
54 {
55 /* Must leave 0 for the stopper. */
56
57 /* Cgraph node without body available. */
58 LTO_cgraph_unavail_node = 1,
59 /* Cgraph node with function body. */
60 LTO_cgraph_analyzed_node,
61 /* Cgraph edges. */
62 LTO_cgraph_edge,
63 LTO_cgraph_indirect_edge
64 };
65
66 /* Create a new cgraph encoder. */
67
68 lto_cgraph_encoder_t
69 lto_cgraph_encoder_new (void)
70 {
71 lto_cgraph_encoder_t encoder = XCNEW (struct lto_cgraph_encoder_d);
72 encoder->map = pointer_map_create ();
73 encoder->nodes = NULL;
74 return encoder;
75 }
76
77
78 /* Delete ENCODER and its components. */
79
80 void
81 lto_cgraph_encoder_delete (lto_cgraph_encoder_t encoder)
82 {
83 VEC_free (cgraph_node_ptr, heap, encoder->nodes);
84 pointer_map_destroy (encoder->map);
85 free (encoder);
86 }
87
88
89 /* Return the existing reference number of NODE in the cgraph encoder in
90 output block OB. Assign a new reference if this is the first time
91 NODE is encoded. */
92
93 int
94 lto_cgraph_encoder_encode (lto_cgraph_encoder_t encoder,
95 struct cgraph_node *node)
96 {
97 int ref;
98 void **slot;
99
100 slot = pointer_map_contains (encoder->map, node);
101 if (!slot)
102 {
103 ref = VEC_length (cgraph_node_ptr, encoder->nodes);
104 slot = pointer_map_insert (encoder->map, node);
105 *slot = (void *) (intptr_t) ref;
106 VEC_safe_push (cgraph_node_ptr, heap, encoder->nodes, node);
107 }
108 else
109 ref = (int) (intptr_t) *slot;
110
111 return ref;
112 }
113
114 #define LCC_NOT_FOUND (-1)
115
116 /* Look up NODE in encoder. Return NODE's reference if it has been encoded
117 or LCC_NOT_FOUND if it is not there. */
118
119 int
120 lto_cgraph_encoder_lookup (lto_cgraph_encoder_t encoder,
121 struct cgraph_node *node)
122 {
123 void **slot = pointer_map_contains (encoder->map, node);
124 return (slot ? (int) (intptr_t) *slot : LCC_NOT_FOUND);
125 }
126
127
128 /* Return the cgraph node corresponding to REF using ENCODER. */
129
130 struct cgraph_node *
131 lto_cgraph_encoder_deref (lto_cgraph_encoder_t encoder, int ref)
132 {
133 if (ref == LCC_NOT_FOUND)
134 return NULL;
135
136 return VEC_index (cgraph_node_ptr, encoder->nodes, ref);
137 }
138
139
140 /* Return number of encoded nodes in ENCODER. */
141
142 static int
143 lto_cgraph_encoder_size (lto_cgraph_encoder_t encoder)
144 {
145 return VEC_length (cgraph_node_ptr, encoder->nodes);
146 }
147
148 /* Create a new varpool encoder. */
149
150 lto_varpool_encoder_t
151 lto_varpool_encoder_new (void)
152 {
153 lto_varpool_encoder_t encoder = XCNEW (struct lto_varpool_encoder_d);
154 encoder->map = pointer_map_create ();
155 encoder->initializer = pointer_set_create ();
156 encoder->nodes = NULL;
157 return encoder;
158 }
159
160
161 /* Delete ENCODER and its components. */
162
163 void
164 lto_varpool_encoder_delete (lto_varpool_encoder_t encoder)
165 {
166 VEC_free (varpool_node_ptr, heap, encoder->nodes);
167 pointer_map_destroy (encoder->map);
168 pointer_set_destroy (encoder->initializer);
169 free (encoder);
170 }
171
172
173 /* Return the existing reference number of NODE in the varpool encoder in
174 output block OB. Assign a new reference if this is the first time
175 NODE is encoded. */
176
177 int
178 lto_varpool_encoder_encode (lto_varpool_encoder_t encoder,
179 struct varpool_node *node)
180 {
181 int ref;
182 void **slot;
183
184 slot = pointer_map_contains (encoder->map, node);
185 if (!slot)
186 {
187 ref = VEC_length (varpool_node_ptr, encoder->nodes);
188 slot = pointer_map_insert (encoder->map, node);
189 *slot = (void *) (intptr_t) ref;
190 VEC_safe_push (varpool_node_ptr, heap, encoder->nodes, node);
191 }
192 else
193 ref = (int) (intptr_t) *slot;
194
195 return ref;
196 }
197
198 /* Look up NODE in encoder. Return NODE's reference if it has been encoded
199 or LCC_NOT_FOUND if it is not there. */
200
201 int
202 lto_varpool_encoder_lookup (lto_varpool_encoder_t encoder,
203 struct varpool_node *node)
204 {
205 void **slot = pointer_map_contains (encoder->map, node);
206 return (slot ? (int) (intptr_t) *slot : LCC_NOT_FOUND);
207 }
208
209
210 /* Return the varpool node corresponding to REF using ENCODER. */
211
212 struct varpool_node *
213 lto_varpool_encoder_deref (lto_varpool_encoder_t encoder, int ref)
214 {
215 if (ref == LCC_NOT_FOUND)
216 return NULL;
217
218 return VEC_index (varpool_node_ptr, encoder->nodes, ref);
219 }
220
221
222 /* Return number of encoded nodes in ENCODER. */
223
224 static int
225 lto_varpool_encoder_size (lto_varpool_encoder_t encoder)
226 {
227 return VEC_length (varpool_node_ptr, encoder->nodes);
228 }
229
230 /* Return TRUE if we should encode initializer of NODE (if any). */
231
232 bool
233 lto_varpool_encoder_encode_initializer_p (lto_varpool_encoder_t encoder,
234 struct varpool_node *node)
235 {
236 return pointer_set_contains (encoder->initializer, node);
237 }
238
239 /* Return TRUE if we should encode initializer of NODE (if any). */
240
241 static void
242 lto_set_varpool_encoder_encode_initializer (lto_varpool_encoder_t encoder,
243 struct varpool_node *node)
244 {
245 pointer_set_insert (encoder->initializer, node);
246 }
247
248 /* Output the cgraph EDGE to OB using ENCODER. */
249
250 static void
251 lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
252 lto_cgraph_encoder_t encoder)
253 {
254 unsigned int uid;
255 intptr_t ref;
256 struct bitpack_d *bp;
257
258 if (edge->indirect_unknown_callee)
259 lto_output_uleb128_stream (ob->main_stream, LTO_cgraph_indirect_edge);
260 else
261 lto_output_uleb128_stream (ob->main_stream, LTO_cgraph_edge);
262
263 ref = lto_cgraph_encoder_lookup (encoder, edge->caller);
264 gcc_assert (ref != LCC_NOT_FOUND);
265 lto_output_sleb128_stream (ob->main_stream, ref);
266
267 if (!edge->indirect_unknown_callee)
268 {
269 ref = lto_cgraph_encoder_lookup (encoder, edge->callee);
270 gcc_assert (ref != LCC_NOT_FOUND);
271 lto_output_sleb128_stream (ob->main_stream, ref);
272 }
273
274 lto_output_sleb128_stream (ob->main_stream, edge->count);
275
276 bp = bitpack_create ();
277 uid = flag_wpa ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt);
278 bp_pack_value (bp, uid, HOST_BITS_PER_INT);
279 bp_pack_value (bp, edge->inline_failed, HOST_BITS_PER_INT);
280 bp_pack_value (bp, edge->frequency, HOST_BITS_PER_INT);
281 bp_pack_value (bp, edge->loop_nest, 30);
282 bp_pack_value (bp, edge->indirect_inlining_edge, 1);
283 bp_pack_value (bp, edge->call_stmt_cannot_inline_p, 1);
284 bp_pack_value (bp, edge->can_throw_external, 1);
285 lto_output_bitpack (ob->main_stream, bp);
286 bitpack_delete (bp);
287 }
288
289 /* Return if LIST contain references from other partitions. */
290 bool
291 referenced_from_other_partition_p (struct ipa_ref_list *list, cgraph_node_set set,
292 varpool_node_set vset)
293 {
294 int i;
295 struct ipa_ref *ref;
296 for (i = 0; ipa_ref_list_refering_iterate (list, i, ref); i++)
297 {
298 if (ref->refering_type == IPA_REF_CGRAPH)
299 {
300 if (!cgraph_node_in_set_p (ipa_ref_refering_node (ref), set))
301 return true;
302 }
303 else
304 {
305 if (!varpool_node_in_set_p (ipa_ref_refering_varpool_node (ref),
306 vset))
307 return true;
308 }
309 }
310 return false;
311 }
312
313 /* Return true when node is reachable from other partition. */
314
315 static bool
316 reachable_from_other_partition_p (struct cgraph_node *node, cgraph_node_set set)
317 {
318 struct cgraph_edge *e;
319 if (node->needed)
320 return true;
321 if (!node->analyzed)
322 return false;
323 if (node->global.inlined_to)
324 return false;
325 for (e = node->callers; e; e = e->next_caller)
326 if (!cgraph_node_in_set_p (e->caller, set))
327 return true;
328 return false;
329 }
330
331 /* Output the cgraph NODE to OB. ENCODER is used to find the
332 reference number of NODE->inlined_to. SET is the set of nodes we
333 are writing to the current file. If NODE is not in SET, then NODE
334 is a boundary of a cgraph_node_set and we pretend NODE just has a
335 decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs
336 that have had their callgraph node written so far. This is used to
337 determine if NODE is a clone of a previously written node. */
338
339 static void
340 lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
341 lto_cgraph_encoder_t encoder, cgraph_node_set set,
342 bitmap written_decls)
343 {
344 unsigned int tag;
345 struct bitpack_d *bp;
346 bool boundary_p, wrote_decl_p;
347 intptr_t ref;
348 bool in_other_partition = false;
349
350 boundary_p = !cgraph_node_in_set_p (node, set);
351 wrote_decl_p = bitmap_bit_p (written_decls, DECL_UID (node->decl));
352
353 if (node->analyzed && !boundary_p)
354 tag = LTO_cgraph_analyzed_node;
355 else
356 tag = LTO_cgraph_unavail_node;
357
358 lto_output_uleb128_stream (ob->main_stream, tag);
359
360 /* In WPA mode, we only output part of the call-graph. Also, we
361 fake cgraph node attributes. There are two cases that we care.
362
363 Boundary nodes: There are nodes that are not part of SET but are
364 called from within SET. We artificially make them look like
365 externally visible nodes with no function body.
366
367 Cherry-picked nodes: These are nodes we pulled from other
368 translation units into SET during IPA-inlining. We make them as
369 local static nodes to prevent clashes with other local statics. */
370 if (boundary_p && node->analyzed)
371 {
372 /* Inline clones can not be part of boundary.
373 gcc_assert (!node->global.inlined_to);
374
375 FIXME: At the moment they can be, when partition contains an inline
376 clone that is clone of inline clone from outside partition. We can
377 reshape the clone tree and make other tree to be the root, but it
378 needs a bit extra work and will be promplty done by cgraph_remove_node
379 after reading back. */
380 in_other_partition = 1;
381 }
382
383 lto_output_uleb128_stream (ob->main_stream, wrote_decl_p);
384
385 if (!wrote_decl_p)
386 bitmap_set_bit (written_decls, DECL_UID (node->decl));
387
388 lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->decl);
389 lto_output_sleb128_stream (ob->main_stream, node->count);
390
391 bp = bitpack_create ();
392 bp_pack_value (bp, node->local.local, 1);
393 bp_pack_value (bp, node->local.externally_visible, 1);
394 bp_pack_value (bp, node->local.finalized, 1);
395 bp_pack_value (bp, node->local.inlinable, 1);
396 bp_pack_value (bp, node->local.disregard_inline_limits, 1);
397 bp_pack_value (bp, node->local.redefined_extern_inline, 1);
398 bp_pack_value (bp, node->local.vtable_method, 1);
399 bp_pack_value (bp, node->needed, 1);
400 bp_pack_value (bp, node->address_taken, 1);
401 bp_pack_value (bp, node->abstract_and_needed, 1);
402 bp_pack_value (bp, tag == LTO_cgraph_analyzed_node
403 && reachable_from_other_partition_p (node, set), 1);
404 bp_pack_value (bp, node->lowered, 1);
405 bp_pack_value (bp, in_other_partition, 1);
406 bp_pack_value (bp, node->alias, 1);
407 bp_pack_value (bp, node->finalized_by_frontend, 1);
408 bp_pack_value (bp, node->frequency, 2);
409 lto_output_bitpack (ob->main_stream, bp);
410 bitpack_delete (bp);
411
412 if (tag == LTO_cgraph_analyzed_node)
413 {
414 lto_output_sleb128_stream (ob->main_stream,
415 node->local.inline_summary.estimated_self_stack_size);
416 lto_output_sleb128_stream (ob->main_stream,
417 node->local.inline_summary.self_size);
418 lto_output_sleb128_stream (ob->main_stream,
419 node->local.inline_summary.size_inlining_benefit);
420 lto_output_sleb128_stream (ob->main_stream,
421 node->local.inline_summary.self_time);
422 lto_output_sleb128_stream (ob->main_stream,
423 node->local.inline_summary.time_inlining_benefit);
424 if (node->global.inlined_to)
425 {
426 ref = lto_cgraph_encoder_lookup (encoder, node->global.inlined_to);
427 gcc_assert (ref != LCC_NOT_FOUND);
428 }
429 else
430 ref = LCC_NOT_FOUND;
431
432 lto_output_sleb128_stream (ob->main_stream, ref);
433 }
434
435 if (node->same_comdat_group && !boundary_p)
436 {
437 ref = lto_cgraph_encoder_lookup (encoder, node->same_comdat_group);
438 gcc_assert (ref != LCC_NOT_FOUND);
439 }
440 else
441 ref = LCC_NOT_FOUND;
442 lto_output_sleb128_stream (ob->main_stream, ref);
443
444 if (node->same_body)
445 {
446 struct cgraph_node *alias;
447 unsigned long alias_count = 1;
448 for (alias = node->same_body; alias->next; alias = alias->next)
449 alias_count++;
450 lto_output_uleb128_stream (ob->main_stream, alias_count);
451 do
452 {
453 lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
454 alias->decl);
455 if (alias->thunk.thunk_p)
456 {
457 lto_output_uleb128_stream
458 (ob->main_stream,
459 1 + (alias->thunk.this_adjusting != 0) * 2
460 + (alias->thunk.virtual_offset_p != 0) * 4);
461 lto_output_uleb128_stream (ob->main_stream,
462 alias->thunk.fixed_offset);
463 lto_output_uleb128_stream (ob->main_stream,
464 alias->thunk.virtual_value);
465 lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
466 alias->thunk.alias);
467 }
468 else
469 {
470 lto_output_uleb128_stream (ob->main_stream, 0);
471 lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
472 alias->thunk.alias);
473 }
474 alias = alias->previous;
475 }
476 while (alias);
477 }
478 else
479 lto_output_uleb128_stream (ob->main_stream, 0);
480 }
481
482 /* Output the varpool NODE to OB.
483 If NODE is not in SET, then NODE is a boundary. */
484
485 static void
486 lto_output_varpool_node (struct lto_simple_output_block *ob, struct varpool_node *node,
487 cgraph_node_set set, varpool_node_set vset)
488 {
489 bool boundary_p = !varpool_node_in_set_p (node, vset) && node->analyzed;
490 struct bitpack_d *bp;
491 struct varpool_node *alias;
492 int count = 0;
493
494 lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->decl);
495 bp = bitpack_create ();
496 bp_pack_value (bp, node->externally_visible, 1);
497 bp_pack_value (bp, node->force_output, 1);
498 bp_pack_value (bp, node->finalized, 1);
499 bp_pack_value (bp, node->alias, 1);
500 gcc_assert (!node->alias || !node->extra_name);
501 gcc_assert (node->finalized || !node->analyzed);
502 gcc_assert (node->needed);
503 /* Constant pool initializers can be de-unified into individual ltrans units.
504 FIXME: Alternatively at -Os we may want to avoid generating for them the local
505 labels and share them across LTRANS partitions. */
506 if (DECL_IN_CONSTANT_POOL (node->decl))
507 {
508 bp_pack_value (bp, 0, 1); /* used_from_other_parition. */
509 bp_pack_value (bp, 0, 1); /* in_other_partition. */
510 }
511 else
512 {
513 bp_pack_value (bp, node->analyzed
514 && referenced_from_other_partition_p (&node->ref_list,
515 set, vset), 1);
516 bp_pack_value (bp, boundary_p, 1); /* in_other_partition. */
517 }
518 /* Also emit any extra name aliases. */
519 for (alias = node->extra_name; alias; alias = alias->next)
520 count++;
521 bp_pack_value (bp, count != 0, 1);
522 lto_output_bitpack (ob->main_stream, bp);
523 bitpack_delete (bp);
524
525 if (count)
526 {
527 lto_output_uleb128_stream (ob->main_stream, count);
528 for (alias = node->extra_name; alias; alias = alias->next)
529 lto_output_var_decl_index (ob->decl_state, ob->main_stream, alias->decl);
530 }
531 }
532
533 /* Output the varpool NODE to OB.
534 If NODE is not in SET, then NODE is a boundary. */
535
536 static void
537 lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref,
538 lto_cgraph_encoder_t encoder,
539 lto_varpool_encoder_t varpool_encoder)
540 {
541 struct bitpack_d *bp = bitpack_create ();
542 bp_pack_value (bp, ref->refered_type, 1);
543 bp_pack_value (bp, ref->use, 2);
544 lto_output_bitpack (ob->main_stream, bp);
545 bitpack_delete (bp);
546 if (ref->refered_type == IPA_REF_CGRAPH)
547 {
548 int nref = lto_cgraph_encoder_lookup (encoder, ipa_ref_node (ref));
549 gcc_assert (nref != LCC_NOT_FOUND);
550 lto_output_sleb128_stream (ob->main_stream, nref);
551 }
552 else
553 {
554 int nref = lto_varpool_encoder_lookup (varpool_encoder,
555 ipa_ref_varpool_node (ref));
556 gcc_assert (nref != LCC_NOT_FOUND);
557 lto_output_sleb128_stream (ob->main_stream, nref);
558 }
559 }
560
561 /* Stream out profile_summary to OB. */
562
563 static void
564 output_profile_summary (struct lto_simple_output_block *ob)
565 {
566 if (profile_info)
567 {
568 /* We do not output num, it is not terribly useful. */
569 gcc_assert (profile_info->runs);
570 lto_output_uleb128_stream (ob->main_stream, profile_info->runs);
571 lto_output_sleb128_stream (ob->main_stream, profile_info->sum_all);
572 lto_output_sleb128_stream (ob->main_stream, profile_info->run_max);
573 lto_output_sleb128_stream (ob->main_stream, profile_info->sum_max);
574 }
575 else
576 lto_output_uleb128_stream (ob->main_stream, 0);
577 }
578
579 /* Add NODE into encoder as well as nodes it is cloned from.
580 Do it in a way so clones appear first. */
581 static void
582 add_node_to (lto_cgraph_encoder_t encoder, struct cgraph_node *node)
583 {
584 if (node->clone_of)
585 add_node_to (encoder, node->clone_of);
586 lto_cgraph_encoder_encode (encoder, node);
587 }
588
589 /* Add all references in LIST to encoders. */
590
591 static void
592 add_references (lto_cgraph_encoder_t encoder,
593 lto_varpool_encoder_t varpool_encoder,
594 struct ipa_ref_list *list)
595 {
596 int i;
597 struct ipa_ref *ref;
598 for (i = 0; ipa_ref_list_reference_iterate (list, i, ref); i++)
599 if (ref->refered_type == IPA_REF_CGRAPH)
600 add_node_to (encoder, ipa_ref_node (ref));
601 else
602 {
603 struct varpool_node *vnode = ipa_ref_varpool_node (ref);
604 lto_varpool_encoder_encode (varpool_encoder, vnode);
605 }
606 }
607
608 /* Output all callees or indirect outgoing edges. EDGE must be the first such
609 edge. */
610
611 static void
612 output_outgoing_cgraph_edges (struct cgraph_edge *edge,
613 struct lto_simple_output_block *ob,
614 lto_cgraph_encoder_t encoder)
615 {
616 if (!edge)
617 return;
618
619 /* Output edges in backward direction, so the reconstructed callgraph match
620 and it is easy to associate call sites in the IPA pass summaries. */
621 while (edge->next_callee)
622 edge = edge->next_callee;
623 for (; edge; edge = edge->prev_callee)
624 lto_output_edge (ob, edge, encoder);
625 }
626
627 /* Output the part of the cgraph in SET. */
628
629 static void
630 output_refs (cgraph_node_set set, varpool_node_set vset,
631 lto_cgraph_encoder_t encoder,
632 lto_varpool_encoder_t varpool_encoder)
633 {
634 cgraph_node_set_iterator csi;
635 varpool_node_set_iterator vsi;
636 struct lto_simple_output_block *ob;
637 int count;
638 struct ipa_ref *ref;
639 int i;
640
641 ob = lto_create_simple_output_block (LTO_section_refs);
642
643 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
644 {
645 struct cgraph_node *node = csi_node (csi);
646
647 count = ipa_ref_list_nreferences (&node->ref_list);
648 if (count)
649 {
650 lto_output_uleb128_stream (ob->main_stream, count);
651 lto_output_uleb128_stream (ob->main_stream,
652 lto_cgraph_encoder_lookup (encoder, node));
653 for (i = 0; ipa_ref_list_reference_iterate (&node->ref_list, i, ref); i++)
654 lto_output_ref (ob, ref, encoder, varpool_encoder);
655 }
656 }
657
658 lto_output_uleb128_stream (ob->main_stream, 0);
659
660 for (vsi = vsi_start (vset); !vsi_end_p (vsi); vsi_next (&vsi))
661 {
662 struct varpool_node *node = vsi_node (vsi);
663
664 count = ipa_ref_list_nreferences (&node->ref_list);
665 if (count)
666 {
667 lto_output_uleb128_stream (ob->main_stream, count);
668 lto_output_uleb128_stream (ob->main_stream,
669 lto_varpool_encoder_lookup (varpool_encoder,
670 node));
671 for (i = 0; ipa_ref_list_reference_iterate (&node->ref_list, i, ref); i++)
672 lto_output_ref (ob, ref, encoder, varpool_encoder);
673 }
674 }
675
676 lto_output_uleb128_stream (ob->main_stream, 0);
677
678 lto_destroy_simple_output_block (ob);
679 }
680
681
682 /* Output the part of the cgraph in SET. */
683
684 void
685 output_cgraph (cgraph_node_set set, varpool_node_set vset)
686 {
687 struct cgraph_node *node;
688 struct lto_simple_output_block *ob;
689 cgraph_node_set_iterator csi;
690 varpool_node_set_iterator vsi;
691 struct cgraph_edge *edge;
692 int i, n_nodes;
693 bitmap written_decls;
694 lto_cgraph_encoder_t encoder;
695 lto_varpool_encoder_t varpool_encoder;
696 struct cgraph_asm_node *can;
697
698 ob = lto_create_simple_output_block (LTO_section_cgraph);
699
700 output_profile_summary (ob);
701
702 /* An encoder for cgraph nodes should have been created by
703 ipa_write_summaries_1. */
704 gcc_assert (ob->decl_state->cgraph_node_encoder);
705 gcc_assert (ob->decl_state->varpool_node_encoder);
706 encoder = ob->decl_state->cgraph_node_encoder;
707 varpool_encoder = ob->decl_state->varpool_node_encoder;
708
709 /* The FUNCTION_DECLs for which we have written a node. The first
710 node found is written as the "original" node, the remaining nodes
711 are considered its clones. */
712 written_decls = lto_bitmap_alloc ();
713
714 /* Go over all the nodes in SET and assign references. */
715 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
716 {
717 node = csi_node (csi);
718 add_node_to (encoder, node);
719 add_references (encoder, varpool_encoder, &node->ref_list);
720 }
721 for (vsi = vsi_start (vset); !vsi_end_p (vsi); vsi_next (&vsi))
722 {
723 struct varpool_node *vnode = vsi_node (vsi);
724 gcc_assert (!vnode->alias);
725 lto_varpool_encoder_encode (varpool_encoder, vnode);
726 lto_set_varpool_encoder_encode_initializer (varpool_encoder, vnode);
727 add_references (encoder, varpool_encoder, &vnode->ref_list);
728 }
729 /* Pickle in also the initializer of all referenced readonly variables
730 to help folding. Constant pool variables are not shared, so we must
731 pickle those too. */
732 for (i = 0; i < lto_varpool_encoder_size (varpool_encoder); i++)
733 {
734 struct varpool_node *vnode = lto_varpool_encoder_deref (varpool_encoder, i);
735 if (DECL_INITIAL (vnode->decl)
736 && !lto_varpool_encoder_encode_initializer_p (varpool_encoder,
737 vnode)
738 && (DECL_IN_CONSTANT_POOL (vnode->decl)
739 || TREE_READONLY (vnode->decl)))
740 {
741 lto_set_varpool_encoder_encode_initializer (varpool_encoder, vnode);
742 add_references (encoder, varpool_encoder, &vnode->ref_list);
743 }
744 }
745
746 /* Go over all the nodes again to include callees that are not in
747 SET. */
748 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
749 {
750 node = csi_node (csi);
751 for (edge = node->callees; edge; edge = edge->next_callee)
752 {
753 struct cgraph_node *callee = edge->callee;
754 if (!cgraph_node_in_set_p (callee, set))
755 {
756 /* We should have moved all the inlines. */
757 gcc_assert (!callee->global.inlined_to);
758 add_node_to (encoder, callee);
759 }
760 }
761 }
762
763 /* Write out the nodes. We must first output a node and then its clones,
764 otherwise at a time reading back the node there would be nothing to clone
765 from. */
766 n_nodes = lto_cgraph_encoder_size (encoder);
767 for (i = 0; i < n_nodes; i++)
768 {
769 node = lto_cgraph_encoder_deref (encoder, i);
770 lto_output_node (ob, node, encoder, set, written_decls);
771 }
772
773 lto_bitmap_free (written_decls);
774
775 /* Go over the nodes in SET again to write edges. */
776 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
777 {
778 node = csi_node (csi);
779 output_outgoing_cgraph_edges (node->callees, ob, encoder);
780 output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
781 }
782
783 lto_output_uleb128_stream (ob->main_stream, 0);
784
785 /* Emit toplevel asms. */
786 for (can = cgraph_asm_nodes; can; can = can->next)
787 {
788 int len = TREE_STRING_LENGTH (can->asm_str);
789 lto_output_uleb128_stream (ob->main_stream, len);
790 for (i = 0; i < len; ++i)
791 lto_output_1_stream (ob->main_stream,
792 TREE_STRING_POINTER (can->asm_str)[i]);
793 }
794
795 lto_output_uleb128_stream (ob->main_stream, 0);
796
797 lto_destroy_simple_output_block (ob);
798 output_varpool (set, vset);
799 output_refs (set, vset, encoder, varpool_encoder);
800 }
801
802 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
803 STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
804 NODE or to replace the values in it, for instance because the first
805 time we saw it, the function body was not available but now it
806 is. BP is a bitpack with all the bitflags for NODE read from the
807 stream. */
808
809 static void
810 input_overwrite_node (struct lto_file_decl_data *file_data,
811 struct cgraph_node *node,
812 enum LTO_cgraph_tags tag,
813 struct bitpack_d *bp,
814 unsigned int stack_size,
815 unsigned int self_time,
816 unsigned int time_inlining_benefit,
817 unsigned int self_size,
818 unsigned int size_inlining_benefit)
819 {
820 node->aux = (void *) tag;
821 node->local.inline_summary.estimated_self_stack_size = stack_size;
822 node->local.inline_summary.self_time = self_time;
823 node->local.inline_summary.time_inlining_benefit = time_inlining_benefit;
824 node->local.inline_summary.self_size = self_size;
825 node->local.inline_summary.size_inlining_benefit = size_inlining_benefit;
826 node->global.time = self_time;
827 node->global.size = self_size;
828 node->global.estimated_stack_size = stack_size;
829 node->global.estimated_growth = INT_MIN;
830 node->local.lto_file_data = file_data;
831
832 node->local.local = bp_unpack_value (bp, 1);
833 node->local.externally_visible = bp_unpack_value (bp, 1);
834 node->local.finalized = bp_unpack_value (bp, 1);
835 node->local.inlinable = bp_unpack_value (bp, 1);
836 node->local.disregard_inline_limits = bp_unpack_value (bp, 1);
837 node->local.redefined_extern_inline = bp_unpack_value (bp, 1);
838 node->local.vtable_method = bp_unpack_value (bp, 1);
839 node->needed = bp_unpack_value (bp, 1);
840 node->address_taken = bp_unpack_value (bp, 1);
841 node->abstract_and_needed = bp_unpack_value (bp, 1);
842 node->reachable_from_other_partition = bp_unpack_value (bp, 1);
843 node->lowered = bp_unpack_value (bp, 1);
844 node->analyzed = tag == LTO_cgraph_analyzed_node;
845 node->in_other_partition = bp_unpack_value (bp, 1);
846 node->alias = bp_unpack_value (bp, 1);
847 node->finalized_by_frontend = bp_unpack_value (bp, 1);
848 node->frequency = (enum node_frequency)bp_unpack_value (bp, 2);
849 }
850
851 /* Output the part of the cgraph in SET. */
852
853 static void
854 output_varpool (cgraph_node_set set, varpool_node_set vset)
855 {
856 struct lto_simple_output_block *ob = lto_create_simple_output_block (LTO_section_varpool);
857 lto_varpool_encoder_t varpool_encoder = ob->decl_state->varpool_node_encoder;
858 int len = lto_varpool_encoder_size (varpool_encoder), i;
859
860 lto_output_uleb128_stream (ob->main_stream, len);
861
862 /* Write out the nodes. We must first output a node and then its clones,
863 otherwise at a time reading back the node there would be nothing to clone
864 from. */
865 for (i = 0; i < len; i++)
866 {
867 lto_output_varpool_node (ob, lto_varpool_encoder_deref (varpool_encoder, i),
868 set, vset);
869 }
870
871 lto_destroy_simple_output_block (ob);
872 }
873
874 /* Read a node from input_block IB. TAG is the node's tag just read.
875 Return the node read or overwriten. */
876
877 static struct cgraph_node *
878 input_node (struct lto_file_decl_data *file_data,
879 struct lto_input_block *ib,
880 enum LTO_cgraph_tags tag)
881 {
882 tree fn_decl;
883 struct cgraph_node *node;
884 struct bitpack_d *bp;
885 int stack_size = 0;
886 unsigned decl_index;
887 bool clone_p;
888 int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND;
889 int self_time = 0;
890 int self_size = 0;
891 int time_inlining_benefit = 0;
892 int size_inlining_benefit = 0;
893 unsigned long same_body_count = 0;
894
895 clone_p = (lto_input_uleb128 (ib) != 0);
896
897 decl_index = lto_input_uleb128 (ib);
898 fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
899
900 if (clone_p)
901 node = cgraph_clone_node (cgraph_node (fn_decl), 0,
902 CGRAPH_FREQ_BASE, 0, false, NULL);
903
904 else
905 node = cgraph_node (fn_decl);
906
907 node->count = lto_input_sleb128 (ib);
908 bp = lto_input_bitpack (ib);
909
910 if (tag == LTO_cgraph_analyzed_node)
911 {
912 stack_size = lto_input_sleb128 (ib);
913 self_size = lto_input_sleb128 (ib);
914 size_inlining_benefit = lto_input_sleb128 (ib);
915 self_time = lto_input_sleb128 (ib);
916 time_inlining_benefit = lto_input_sleb128 (ib);
917
918 ref = lto_input_sleb128 (ib);
919 }
920
921 ref2 = lto_input_sleb128 (ib);
922 same_body_count = lto_input_uleb128 (ib);
923
924 /* Make sure that we have not read this node before. Nodes that
925 have already been read will have their tag stored in the 'aux'
926 field. Since built-in functions can be referenced in multiple
927 functions, they are expected to be read more than once. */
928 if (node->aux && !DECL_IS_BUILTIN (node->decl))
929 internal_error ("bytecode stream: found multiple instances of cgraph "
930 "node %d", node->uid);
931
932 input_overwrite_node (file_data, node, tag, bp, stack_size, self_time,
933 time_inlining_benefit, self_size,
934 size_inlining_benefit);
935 bitpack_delete (bp);
936
937 /* Store a reference for now, and fix up later to be a pointer. */
938 node->global.inlined_to = (cgraph_node_ptr) (intptr_t) ref;
939
940 /* Store a reference for now, and fix up later to be a pointer. */
941 node->same_comdat_group = (cgraph_node_ptr) (intptr_t) ref2;
942
943 while (same_body_count-- > 0)
944 {
945 tree alias_decl;
946 int type;
947 decl_index = lto_input_uleb128 (ib);
948 alias_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
949 type = lto_input_uleb128 (ib);
950 if (!type)
951 {
952 tree real_alias;
953 decl_index = lto_input_uleb128 (ib);
954 real_alias = lto_file_decl_data_get_fn_decl (file_data, decl_index);
955 cgraph_same_body_alias (alias_decl, real_alias);
956 }
957 else
958 {
959 HOST_WIDE_INT fixed_offset = lto_input_uleb128 (ib);
960 HOST_WIDE_INT virtual_value = lto_input_uleb128 (ib);
961 tree real_alias;
962 decl_index = lto_input_uleb128 (ib);
963 real_alias = lto_file_decl_data_get_fn_decl (file_data, decl_index);
964 cgraph_add_thunk (alias_decl, fn_decl, type & 2, fixed_offset,
965 virtual_value,
966 (type & 4) ? size_int (virtual_value) : NULL_TREE,
967 real_alias);
968 }
969 }
970 return node;
971 }
972
973 /* Read a node from input_block IB. TAG is the node's tag just read.
974 Return the node read or overwriten. */
975
976 static struct varpool_node *
977 input_varpool_node (struct lto_file_decl_data *file_data,
978 struct lto_input_block *ib)
979 {
980 int decl_index;
981 tree var_decl;
982 struct varpool_node *node;
983 struct bitpack_d *bp;
984 bool aliases_p;
985 int count;
986
987 decl_index = lto_input_uleb128 (ib);
988 var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index);
989 node = varpool_node (var_decl);
990
991 bp = lto_input_bitpack (ib);
992 node->externally_visible = bp_unpack_value (bp, 1);
993 node->force_output = bp_unpack_value (bp, 1);
994 node->finalized = bp_unpack_value (bp, 1);
995 node->alias = bp_unpack_value (bp, 1);
996 node->analyzed = node->finalized;
997 node->used_from_other_partition = bp_unpack_value (bp, 1);
998 node->in_other_partition = bp_unpack_value (bp, 1);
999 aliases_p = bp_unpack_value (bp, 1);
1000 if (node->finalized)
1001 varpool_mark_needed_node (node);
1002 bitpack_delete (bp);
1003 if (aliases_p)
1004 {
1005 count = lto_input_uleb128 (ib);
1006 for (; count > 0; count --)
1007 {
1008 tree decl = lto_file_decl_data_get_var_decl (file_data,
1009 lto_input_uleb128 (ib));
1010 varpool_extra_name_alias (decl, var_decl);
1011 }
1012 }
1013 return node;
1014 }
1015
1016 /* Read a node from input_block IB. TAG is the node's tag just read.
1017 Return the node read or overwriten. */
1018
1019 static void
1020 input_ref (struct lto_input_block *ib,
1021 struct cgraph_node *refering_node,
1022 struct varpool_node *refering_varpool_node,
1023 VEC(cgraph_node_ptr, heap) *nodes,
1024 VEC(varpool_node_ptr, heap) *varpool_nodes)
1025 {
1026 struct cgraph_node *node = NULL;
1027 struct varpool_node *varpool_node = NULL;
1028 struct bitpack_d *bp;
1029 enum ipa_ref_type type;
1030 enum ipa_ref_use use;
1031
1032 bp = lto_input_bitpack (ib);
1033 type = (enum ipa_ref_type) bp_unpack_value (bp, 1);
1034 use = (enum ipa_ref_use) bp_unpack_value (bp, 2);
1035 bitpack_delete (bp);
1036 if (type == IPA_REF_CGRAPH)
1037 node = VEC_index (cgraph_node_ptr, nodes, lto_input_sleb128 (ib));
1038 else
1039 varpool_node = VEC_index (varpool_node_ptr, varpool_nodes, lto_input_sleb128 (ib));
1040 ipa_record_reference (refering_node, refering_varpool_node,
1041 node, varpool_node, use, NULL);
1042 }
1043
1044 /* Read an edge from IB. NODES points to a vector of previously read nodes for
1045 decoding caller and callee of the edge to be read. If INDIRECT is true, the
1046 edge being read is indirect (in the sense that it has
1047 indirect_unknown_callee set). */
1048
1049 static void
1050 input_edge (struct lto_input_block *ib, VEC(cgraph_node_ptr, heap) *nodes,
1051 bool indirect)
1052 {
1053 struct cgraph_node *caller, *callee;
1054 struct cgraph_edge *edge;
1055 unsigned int stmt_id;
1056 gcov_type count;
1057 int freq;
1058 unsigned int nest;
1059 cgraph_inline_failed_t inline_failed;
1060 struct bitpack_d *bp;
1061 enum ld_plugin_symbol_resolution caller_resolution;
1062
1063 caller = VEC_index (cgraph_node_ptr, nodes, lto_input_sleb128 (ib));
1064 if (caller == NULL || caller->decl == NULL_TREE)
1065 internal_error ("bytecode stream: no caller found while reading edge");
1066
1067 if (!indirect)
1068 {
1069 callee = VEC_index (cgraph_node_ptr, nodes, lto_input_sleb128 (ib));
1070 if (callee == NULL || callee->decl == NULL_TREE)
1071 internal_error ("bytecode stream: no callee found while reading edge");
1072 }
1073 else
1074 callee = NULL;
1075
1076 count = (gcov_type) lto_input_sleb128 (ib);
1077
1078 bp = lto_input_bitpack (ib);
1079 stmt_id = (unsigned int) bp_unpack_value (bp, HOST_BITS_PER_INT);
1080 inline_failed = (cgraph_inline_failed_t) bp_unpack_value (bp,
1081 HOST_BITS_PER_INT);
1082 freq = (int) bp_unpack_value (bp, HOST_BITS_PER_INT);
1083 nest = (unsigned) bp_unpack_value (bp, 30);
1084
1085 /* If the caller was preempted, don't create the edge.
1086 ??? Should we ever have edges from a preempted caller? */
1087 caller_resolution = lto_symtab_get_resolution (caller->decl);
1088 if (caller_resolution == LDPR_PREEMPTED_REG
1089 || caller_resolution == LDPR_PREEMPTED_IR)
1090 return;
1091
1092 if (indirect)
1093 edge = cgraph_create_indirect_edge (caller, NULL, count, freq, nest);
1094 else
1095 edge = cgraph_create_edge (caller, callee, NULL, count, freq, nest);
1096
1097 edge->indirect_inlining_edge = bp_unpack_value (bp, 1);
1098 edge->lto_stmt_uid = stmt_id;
1099 edge->inline_failed = inline_failed;
1100 edge->call_stmt_cannot_inline_p = bp_unpack_value (bp, 1);
1101 edge->can_throw_external = bp_unpack_value (bp, 1);
1102 bitpack_delete (bp);
1103 }
1104
1105
1106 /* Read a cgraph from IB using the info in FILE_DATA. */
1107
1108 static VEC(cgraph_node_ptr, heap) *
1109 input_cgraph_1 (struct lto_file_decl_data *file_data,
1110 struct lto_input_block *ib)
1111 {
1112 enum LTO_cgraph_tags tag;
1113 VEC(cgraph_node_ptr, heap) *nodes = NULL;
1114 struct cgraph_node *node;
1115 unsigned i;
1116 unsigned HOST_WIDE_INT len;
1117
1118 tag = (enum LTO_cgraph_tags) lto_input_uleb128 (ib);
1119 while (tag)
1120 {
1121 if (tag == LTO_cgraph_edge)
1122 input_edge (ib, nodes, false);
1123 else if (tag == LTO_cgraph_indirect_edge)
1124 input_edge (ib, nodes, true);
1125 else
1126 {
1127 node = input_node (file_data, ib, tag);
1128 if (node == NULL || node->decl == NULL_TREE)
1129 internal_error ("bytecode stream: found empty cgraph node");
1130 VEC_safe_push (cgraph_node_ptr, heap, nodes, node);
1131 lto_cgraph_encoder_encode (file_data->cgraph_node_encoder, node);
1132 }
1133
1134 tag = (enum LTO_cgraph_tags) lto_input_uleb128 (ib);
1135 }
1136
1137 /* Input toplevel asms. */
1138 len = lto_input_uleb128 (ib);
1139 while (len)
1140 {
1141 char *str = (char *)xmalloc (len + 1);
1142 for (i = 0; i < len; ++i)
1143 str[i] = lto_input_1_unsigned (ib);
1144 cgraph_add_asm_node (build_string (len, str));
1145 free (str);
1146
1147 len = lto_input_uleb128 (ib);
1148 }
1149
1150 for (i = 0; VEC_iterate (cgraph_node_ptr, nodes, i, node); i++)
1151 {
1152 int ref = (int) (intptr_t) node->global.inlined_to;
1153
1154 /* Fixup inlined_to from reference to pointer. */
1155 if (ref != LCC_NOT_FOUND)
1156 node->global.inlined_to = VEC_index (cgraph_node_ptr, nodes, ref);
1157 else
1158 node->global.inlined_to = NULL;
1159
1160 ref = (int) (intptr_t) node->same_comdat_group;
1161
1162 /* Fixup same_comdat_group from reference to pointer. */
1163 if (ref != LCC_NOT_FOUND)
1164 node->same_comdat_group = VEC_index (cgraph_node_ptr, nodes, ref);
1165 else
1166 node->same_comdat_group = NULL;
1167 }
1168 return nodes;
1169 }
1170
1171 /* Read a varpool from IB using the info in FILE_DATA. */
1172
1173 static VEC(varpool_node_ptr, heap) *
1174 input_varpool_1 (struct lto_file_decl_data *file_data,
1175 struct lto_input_block *ib)
1176 {
1177 unsigned HOST_WIDE_INT len;
1178 VEC(varpool_node_ptr, heap) *varpool = NULL;
1179
1180 len = lto_input_uleb128 (ib);
1181 while (len)
1182 {
1183 VEC_safe_push (varpool_node_ptr, heap, varpool,
1184 input_varpool_node (file_data, ib));
1185 len--;
1186 }
1187 return varpool;
1188 }
1189
1190 /* Input ipa_refs. */
1191
1192 static void
1193 input_refs (struct lto_input_block *ib,
1194 VEC(cgraph_node_ptr, heap) *nodes,
1195 VEC(varpool_node_ptr, heap) *varpool)
1196 {
1197 int count;
1198 int idx;
1199 while (true)
1200 {
1201 struct cgraph_node *node;
1202 count = lto_input_uleb128 (ib);
1203 if (!count)
1204 break;
1205 idx = lto_input_uleb128 (ib);
1206 node = VEC_index (cgraph_node_ptr, nodes, idx);
1207 while (count)
1208 {
1209 input_ref (ib, node, NULL, nodes, varpool);
1210 count--;
1211 }
1212 }
1213 while (true)
1214 {
1215 struct varpool_node *node;
1216 count = lto_input_uleb128 (ib);
1217 if (!count)
1218 break;
1219 node = VEC_index (varpool_node_ptr, varpool, lto_input_uleb128 (ib));
1220 while (count)
1221 {
1222 input_ref (ib, NULL, node, nodes, varpool);
1223 count--;
1224 }
1225 }
1226 }
1227
1228
1229 static struct gcov_ctr_summary lto_gcov_summary;
1230
1231 /* Input profile_info from IB. */
1232 static void
1233 input_profile_summary (struct lto_input_block *ib)
1234 {
1235 unsigned int runs = lto_input_uleb128 (ib);
1236 if (runs)
1237 {
1238 if (!profile_info)
1239 {
1240 profile_info = &lto_gcov_summary;
1241 lto_gcov_summary.runs = runs;
1242 lto_gcov_summary.sum_all = lto_input_sleb128 (ib);
1243 lto_gcov_summary.run_max = lto_input_sleb128 (ib);
1244 lto_gcov_summary.sum_max = lto_input_sleb128 (ib);
1245 }
1246 /* We can support this by scaling all counts to nearest common multiple
1247 of all different runs, but it is perhaps not worth the effort. */
1248 else if (profile_info->runs != runs
1249 || profile_info->sum_all != lto_input_sleb128 (ib)
1250 || profile_info->run_max != lto_input_sleb128 (ib)
1251 || profile_info->sum_max != lto_input_sleb128 (ib))
1252 sorry ("Combining units with different profiles is not supported.");
1253 /* We allow some units to have profile and other to not have one. This will
1254 just make unprofiled units to be size optimized that is sane. */
1255 }
1256
1257 }
1258
1259 /* Input and merge the cgraph from each of the .o files passed to
1260 lto1. */
1261
1262 void
1263 input_cgraph (void)
1264 {
1265 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1266 struct lto_file_decl_data *file_data;
1267 unsigned int j = 0;
1268 struct cgraph_node *node;
1269
1270 while ((file_data = file_data_vec[j++]))
1271 {
1272 const char *data;
1273 size_t len;
1274 struct lto_input_block *ib;
1275 VEC(cgraph_node_ptr, heap) *nodes;
1276 VEC(varpool_node_ptr, heap) *varpool;
1277
1278 ib = lto_create_simple_input_block (file_data, LTO_section_cgraph,
1279 &data, &len);
1280 input_profile_summary (ib);
1281 file_data->cgraph_node_encoder = lto_cgraph_encoder_new ();
1282 nodes = input_cgraph_1 (file_data, ib);
1283 lto_destroy_simple_input_block (file_data, LTO_section_cgraph,
1284 ib, data, len);
1285
1286 ib = lto_create_simple_input_block (file_data, LTO_section_varpool,
1287 &data, &len);
1288 varpool = input_varpool_1 (file_data, ib);
1289 lto_destroy_simple_input_block (file_data, LTO_section_varpool,
1290 ib, data, len);
1291
1292 ib = lto_create_simple_input_block (file_data, LTO_section_refs,
1293 &data, &len);
1294 input_refs (ib, nodes, varpool);
1295 lto_destroy_simple_input_block (file_data, LTO_section_refs,
1296 ib, data, len);
1297 VEC_free (cgraph_node_ptr, heap, nodes);
1298 VEC_free (varpool_node_ptr, heap, varpool);
1299 }
1300
1301 /* Clear out the aux field that was used to store enough state to
1302 tell which nodes should be overwritten. */
1303 for (node = cgraph_nodes; node; node = node->next)
1304 {
1305 /* Some nodes may have been created by cgraph_node. This
1306 happens when the callgraph contains nested functions. If the
1307 node for the parent function was never emitted to the gimple
1308 file, cgraph_node will create a node for it when setting the
1309 context of the nested function. */
1310 if (node->local.lto_file_data)
1311 node->aux = NULL;
1312 }
1313 }