OSDN Git Service

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