OSDN Git Service

Merge lto branch into trunk.
[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 "varray.h"
34 #include "hashtab.h"
35 #include "langhooks.h"
36 #include "basic-block.h"
37 #include "tree-flow.h"
38 #include "cgraph.h"
39 #include "function.h"
40 #include "ggc.h"
41 #include "diagnostic.h"
42 #include "except.h"
43 #include "vec.h"
44 #include "timevar.h"
45 #include "output.h"
46 #include "pointer-set.h"
47 #include "lto-streamer.h"
48
49 /* Create a new cgraph encoder.  */
50
51 lto_cgraph_encoder_t
52 lto_cgraph_encoder_new (void)
53 {
54   lto_cgraph_encoder_t encoder = XCNEW (struct lto_cgraph_encoder_d);
55   encoder->map = pointer_map_create ();
56   encoder->nodes = NULL;
57   return encoder;
58 }
59
60
61 /* Delete ENCODER and its components.  */
62
63 void
64 lto_cgraph_encoder_delete (lto_cgraph_encoder_t encoder)
65 {
66    VEC_free (cgraph_node_ptr, heap, encoder->nodes);
67    pointer_map_destroy (encoder->map);
68    free (encoder);
69 }
70
71
72 /* Return the existing reference number of NODE in the cgraph encoder in
73    output block OB.  Assign a new reference if this is the first time
74    NODE is encoded.  */
75
76 int
77 lto_cgraph_encoder_encode (lto_cgraph_encoder_t encoder,
78                            struct cgraph_node *node)
79 {
80   int ref;
81   void **slot;
82   
83   slot = pointer_map_contains (encoder->map, node);
84   if (!slot)
85     {
86       ref = VEC_length (cgraph_node_ptr, encoder->nodes);
87       slot = pointer_map_insert (encoder->map, node);
88       *slot = (void *) (intptr_t) ref;
89       VEC_safe_push (cgraph_node_ptr, heap, encoder->nodes, node);
90     }
91   else
92     ref = (int) (intptr_t) *slot;
93
94   return ref;
95 }
96
97
98 /* Look up NODE in encoder.  Return NODE's reference if it has been encoded
99    or LCC_NOT_FOUND if it is not there.  */
100
101 int
102 lto_cgraph_encoder_lookup (lto_cgraph_encoder_t encoder,
103                            struct cgraph_node *node)
104 {
105   void **slot = pointer_map_contains (encoder->map, node);
106   return (slot ? (int) (intptr_t) *slot : LCC_NOT_FOUND);
107 }
108
109
110 /* Return the cgraph node corresponding to REF using ENCODER.  */
111
112 struct cgraph_node *
113 lto_cgraph_encoder_deref (lto_cgraph_encoder_t encoder, int ref)
114 {
115   if (ref == LCC_NOT_FOUND)
116     return NULL;
117
118   return VEC_index (cgraph_node_ptr, encoder->nodes, ref); 
119 }
120
121
122 /* Return number of encoded nodes in ENCODER.  */
123
124 static int
125 lto_cgraph_encoder_size (lto_cgraph_encoder_t encoder)
126 {
127   return VEC_length (cgraph_node_ptr, encoder->nodes);
128 }
129
130
131 /* Output the cgraph EDGE to OB using ENCODER.  */
132
133 static void
134 lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge,
135                  lto_cgraph_encoder_t encoder)
136 {
137   unsigned int uid;
138   intptr_t ref;
139   struct bitpack_d *bp;
140
141   lto_output_uleb128_stream (ob->main_stream, LTO_cgraph_edge);
142
143   ref = lto_cgraph_encoder_lookup (encoder, edge->caller);
144   gcc_assert (ref != LCC_NOT_FOUND); 
145   lto_output_sleb128_stream (ob->main_stream, ref);
146
147   ref = lto_cgraph_encoder_lookup (encoder, edge->callee);
148   gcc_assert (ref != LCC_NOT_FOUND); 
149   lto_output_sleb128_stream (ob->main_stream, ref);
150
151   lto_output_sleb128_stream (ob->main_stream, edge->count);
152
153   bp = bitpack_create ();
154   uid = flag_wpa ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt);
155   bp_pack_value (bp, uid, HOST_BITS_PER_INT);
156   bp_pack_value (bp, edge->inline_failed, HOST_BITS_PER_INT);
157   bp_pack_value (bp, edge->frequency, HOST_BITS_PER_INT);
158   bp_pack_value (bp, edge->loop_nest, 30);
159   bp_pack_value (bp, edge->indirect_call, 1);
160   bp_pack_value (bp, edge->call_stmt_cannot_inline_p, 1);
161   bp_pack_value (bp, edge->can_throw_external, 1);
162   lto_output_bitpack (ob->main_stream, bp);
163   bitpack_delete (bp);
164 }
165
166
167 /* Output the cgraph NODE to OB.  ENCODER is used to find the
168    reference number of NODE->inlined_to.  SET is the set of nodes we
169    are writing to the current file.  If NODE is not in SET, then NODE
170    is a boundary of a cgraph_node_set and we pretend NODE just has a
171    decl and no callees.  WRITTEN_DECLS is the set of FUNCTION_DECLs
172    that have had their callgraph node written so far.  This is used to
173    determine if NODE is a clone of a previously written node.  */
174
175 static void
176 lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
177                  lto_cgraph_encoder_t encoder, cgraph_node_set set,
178                  bitmap written_decls)
179 {
180   unsigned int tag;
181   struct bitpack_d *bp;
182   unsigned local, externally_visible, inlinable, analyzed;
183   bool boundary_p, wrote_decl_p;
184   intptr_t ref;
185
186   boundary_p = !cgraph_node_in_set_p (node, set);
187   wrote_decl_p = bitmap_bit_p (written_decls, DECL_UID (node->decl));
188
189   switch (cgraph_function_body_availability (node))
190     {
191     case AVAIL_NOT_AVAILABLE:
192       tag = LTO_cgraph_unavail_node;
193       break;
194
195     case AVAIL_AVAILABLE:
196     case AVAIL_LOCAL:
197       tag = LTO_cgraph_avail_node;
198       break;
199     
200     case AVAIL_OVERWRITABLE:
201       tag = LTO_cgraph_overwritable_node;
202       break;
203       
204     default:
205       gcc_unreachable ();
206     }
207  
208   if (boundary_p)
209     tag = LTO_cgraph_unavail_node;
210
211   lto_output_uleb128_stream (ob->main_stream, tag);
212
213   local = node->local.local;
214   externally_visible = node->local.externally_visible;
215   inlinable = node->local.inlinable;
216   analyzed = node->analyzed;
217
218   /* In WPA mode, we only output part of the call-graph.  Also, we
219      fake cgraph node attributes.  There are two cases that we care.
220
221      Boundary nodes: There are nodes that are not part of SET but are
222      called from within SET.  We artificially make them look like
223      externally visible nodes with no function body. 
224
225      Cherry-picked nodes:  These are nodes we pulled from other
226      translation units into SET during IPA-inlining.  We make them as
227      local static nodes to prevent clashes with other local statics.  */
228   if (boundary_p)
229     {
230       local = 0;
231       externally_visible = 1;
232       inlinable = 0;
233       analyzed = 0;
234     }
235   else if (lto_forced_extern_inline_p (node->decl))
236     {
237       local = 1;
238       externally_visible = 0;
239       inlinable = 1;
240     }
241
242   lto_output_uleb128_stream (ob->main_stream, wrote_decl_p);
243
244   if (!wrote_decl_p)
245     bitmap_set_bit (written_decls, DECL_UID (node->decl));
246
247   lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->decl);
248   lto_output_sleb128_stream (ob->main_stream, node->count);
249
250   bp = bitpack_create ();
251   bp_pack_value (bp, local, 1);
252   bp_pack_value (bp, externally_visible, 1);
253   bp_pack_value (bp, node->local.finalized, 1);
254   bp_pack_value (bp, inlinable, 1);
255   bp_pack_value (bp, node->local.disregard_inline_limits, 1);
256   bp_pack_value (bp, node->local.redefined_extern_inline, 1);
257   bp_pack_value (bp, node->local.for_functions_valid, 1);
258   bp_pack_value (bp, node->local.vtable_method, 1);
259   bp_pack_value (bp, node->needed, 1);
260   bp_pack_value (bp, node->address_taken, 1);
261   bp_pack_value (bp, node->abstract_and_needed, 1);
262   bp_pack_value (bp, node->reachable, 1);
263   bp_pack_value (bp, node->lowered, 1);
264   bp_pack_value (bp, analyzed, 1);
265   bp_pack_value (bp, node->process, 1);
266   bp_pack_value (bp, node->alias, 1);
267   bp_pack_value (bp, node->finalized_by_frontend, 1);
268   lto_output_bitpack (ob->main_stream, bp);
269   bitpack_delete (bp);
270
271   if (tag != LTO_cgraph_unavail_node)
272     {
273       lto_output_sleb128_stream (ob->main_stream, 
274                                  node->local.inline_summary.estimated_self_stack_size);
275       lto_output_sleb128_stream (ob->main_stream, 
276                                  node->local.inline_summary.self_size);
277       lto_output_sleb128_stream (ob->main_stream, 
278                                  node->local.inline_summary.size_inlining_benefit);
279       lto_output_sleb128_stream (ob->main_stream, 
280                                  node->local.inline_summary.self_time);
281       lto_output_sleb128_stream (ob->main_stream, 
282                                  node->local.inline_summary.time_inlining_benefit);
283     }
284
285   /* FIXME lto: Outputting global info is not neccesary until after
286      inliner was run.  Global structure holds results of propagation
287      done by inliner.  */
288   lto_output_sleb128_stream (ob->main_stream,
289                              node->global.estimated_stack_size);
290   lto_output_sleb128_stream (ob->main_stream,
291                              node->global.stack_frame_offset);
292   if (node->global.inlined_to && !boundary_p)
293     {
294       ref = lto_cgraph_encoder_lookup (encoder, node->global.inlined_to);
295       gcc_assert (ref != LCC_NOT_FOUND);
296     }
297   else
298     ref = LCC_NOT_FOUND;
299   lto_output_sleb128_stream (ob->main_stream, ref);
300
301   lto_output_sleb128_stream (ob->main_stream, node->global.time);
302   lto_output_sleb128_stream (ob->main_stream, node->global.size);
303   lto_output_sleb128_stream (ob->main_stream,
304                              node->global.estimated_growth);
305   lto_output_uleb128_stream (ob->main_stream, node->global.inlined);
306 }
307
308
309 /* Output the part of the cgraph in SET.  */
310
311 void
312 output_cgraph (cgraph_node_set set)
313 {
314   struct cgraph_node *node;
315   struct lto_simple_output_block *ob;
316   cgraph_node_set_iterator csi;
317   struct cgraph_edge *edge;
318   int i, n_nodes;
319   bitmap written_decls;
320   lto_cgraph_encoder_t encoder;
321
322   ob = lto_create_simple_output_block (LTO_section_cgraph);
323
324   /* An encoder for cgraph nodes should have been created by
325      ipa_write_summaries_1.  */
326   gcc_assert (ob->decl_state->cgraph_node_encoder);
327   encoder = ob->decl_state->cgraph_node_encoder;
328
329   /* The FUNCTION_DECLs for which we have written a node.  The first
330      node found is written as the "original" node, the remaining nodes
331      are considered its clones.  */
332   written_decls = lto_bitmap_alloc ();
333
334   /* Go over all the nodes in SET and assign references.  */
335   for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
336     {
337       node = csi_node (csi);
338       lto_cgraph_encoder_encode (encoder, node);
339     }
340
341   /* Go over all the nodes again to include callees that are not in
342      SET.  */
343   for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
344     {
345       node = csi_node (csi);
346       for (edge = node->callees; edge; edge = edge->next_callee)
347         {
348           struct cgraph_node *callee = edge->callee;
349           if (!cgraph_node_in_set_p (callee, set))
350             {
351               /* We should have moved all the inlines.  */
352               gcc_assert (!callee->global.inlined_to);
353               lto_cgraph_encoder_encode (encoder, callee);
354             }
355         }
356     }
357
358   /* Write out the nodes.  */
359   n_nodes = lto_cgraph_encoder_size (encoder);
360   for (i = 0; i < n_nodes; i++)
361     {
362       node = lto_cgraph_encoder_deref (encoder, i);
363       lto_output_node (ob, node, encoder, set, written_decls);
364     }
365
366   lto_bitmap_free (written_decls);
367
368   /* Go over the nodes in SET again to write edges.  */
369   for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
370     {
371       node = csi_node (csi);
372       for (edge = node->callees; edge; edge = edge->next_callee)
373         lto_output_edge (ob, edge, encoder);
374     }
375
376   lto_output_uleb128_stream (ob->main_stream, 0);
377
378   lto_destroy_simple_output_block (ob);
379 }
380
381
382 /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
383    STACK_SIZE, SELF_TIME and SELF_SIZE.  This is called either to initialize
384    NODE or to replace the values in it, for instance because the first
385    time we saw it, the function body was not available but now it
386    is.  BP is a bitpack with all the bitflags for NODE read from the
387    stream.  */
388
389 static void
390 input_overwrite_node (struct lto_file_decl_data *file_data,
391                       struct cgraph_node *node,
392                       enum LTO_cgraph_tags tag,
393                       struct bitpack_d *bp,
394                       unsigned int stack_size,
395                       unsigned int self_time,
396                       unsigned int time_inlining_benefit,
397                       unsigned int self_size,
398                       unsigned int size_inlining_benefit)
399 {
400   node->aux = (void *) tag;
401   node->local.inline_summary.estimated_self_stack_size = stack_size;
402   node->local.inline_summary.self_time = self_time;
403   node->local.inline_summary.time_inlining_benefit = time_inlining_benefit;
404   node->local.inline_summary.self_size = self_size;
405   node->local.inline_summary.size_inlining_benefit = size_inlining_benefit;
406   node->global.time = self_time;
407   node->global.size = self_size;
408   node->local.lto_file_data = file_data;
409
410   node->local.local = bp_unpack_value (bp, 1);
411   node->local.externally_visible = bp_unpack_value (bp, 1);
412   node->local.finalized = bp_unpack_value (bp, 1);
413   node->local.inlinable = bp_unpack_value (bp, 1);
414   node->local.disregard_inline_limits = bp_unpack_value (bp, 1);
415   node->local.redefined_extern_inline = bp_unpack_value (bp, 1);
416   node->local.for_functions_valid = bp_unpack_value (bp, 1);
417   node->local.vtable_method = bp_unpack_value (bp, 1);
418   node->needed = bp_unpack_value (bp, 1);
419   node->address_taken = bp_unpack_value (bp, 1);
420   node->abstract_and_needed = bp_unpack_value (bp, 1);
421   node->reachable = bp_unpack_value (bp, 1);
422   node->lowered = bp_unpack_value (bp, 1);
423   node->analyzed = bp_unpack_value (bp, 1);
424   node->process = bp_unpack_value (bp, 1);
425   node->alias = bp_unpack_value (bp, 1);
426   node->finalized_by_frontend = bp_unpack_value (bp, 1);
427 }
428
429
430 /* Read a node from input_block IB.  TAG is the node's tag just read. 
431    Return the node read or overwriten.  */
432  
433 static struct cgraph_node *
434 input_node (struct lto_file_decl_data *file_data,
435             struct lto_input_block *ib,
436             enum LTO_cgraph_tags tag)
437 {
438   tree fn_decl;
439   struct cgraph_node *node;
440   struct bitpack_d *bp;
441   int stack_size = 0;
442   unsigned decl_index;
443   bool clone_p;
444   int estimated_stack_size = 0;
445   int stack_frame_offset = 0;
446   int ref = LCC_NOT_FOUND;
447   int estimated_growth = 0;
448   int time = 0;
449   int size = 0;
450   int self_time = 0;
451   int self_size = 0;
452   int time_inlining_benefit = 0;
453   int size_inlining_benefit = 0;
454   bool inlined = false;
455
456   clone_p = (lto_input_uleb128 (ib) != 0);
457
458   decl_index = lto_input_uleb128 (ib);
459   fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index);
460
461   if (clone_p)
462     node = cgraph_clone_node (cgraph_node (fn_decl), 0,
463                               CGRAPH_FREQ_BASE, 0, false, NULL);
464
465   else
466     node = cgraph_node (fn_decl);
467
468   node->count = lto_input_sleb128 (ib);
469   bp = lto_input_bitpack (ib);
470   
471   if (tag != LTO_cgraph_unavail_node)
472     {
473       stack_size = lto_input_sleb128 (ib);
474       self_size = lto_input_sleb128 (ib);
475       size_inlining_benefit = lto_input_sleb128 (ib);
476       self_time = lto_input_sleb128 (ib);
477       time_inlining_benefit = lto_input_sleb128 (ib);
478     }
479
480   estimated_stack_size = lto_input_sleb128 (ib);
481   stack_frame_offset = lto_input_sleb128 (ib);
482   ref = lto_input_sleb128 (ib);
483   time = lto_input_sleb128 (ib);
484   size = lto_input_sleb128 (ib);
485   estimated_growth = lto_input_sleb128 (ib);
486   inlined = lto_input_uleb128 (ib);
487
488   /* Make sure that we have not read this node before.  Nodes that
489      have already been read will have their tag stored in the 'aux'
490      field.  Since built-in functions can be referenced in multiple
491      functions, they are expected to be read more than once.  */
492   if (node->aux && !DECL_IS_BUILTIN (node->decl))
493     internal_error ("bytecode stream: found multiple instances of cgraph "
494                     "node %d", node->uid);
495
496   input_overwrite_node (file_data, node, tag, bp, stack_size, self_time,
497                         time_inlining_benefit, self_size,
498                         size_inlining_benefit);
499   bitpack_delete (bp);
500
501   node->global.estimated_stack_size = estimated_stack_size;
502   node->global.stack_frame_offset = stack_frame_offset;
503   node->global.time = time;
504   node->global.size = size;
505
506   /* Store a reference for now, and fix up later to be a pointer.  */
507   node->global.inlined_to = (cgraph_node_ptr) (intptr_t) ref;
508
509   node->global.estimated_growth = estimated_growth;
510   node->global.inlined = inlined;
511
512   return node;
513 }
514
515
516 /* Read an edge from IB.  NODES points to a vector of previously read
517    nodes for decoding caller and callee of the edge to be read.  */
518
519 static void
520 input_edge (struct lto_input_block *ib, VEC(cgraph_node_ptr, heap) *nodes)
521 {
522   struct cgraph_node *caller, *callee;
523   struct cgraph_edge *edge;
524   unsigned int stmt_id;
525   gcov_type count;
526   int freq;
527   unsigned int nest;
528   cgraph_inline_failed_t inline_failed;
529   struct bitpack_d *bp;
530   tree prevailing_callee;
531   tree prevailing_caller;
532   enum ld_plugin_symbol_resolution caller_resolution;
533
534   caller = VEC_index (cgraph_node_ptr, nodes, lto_input_sleb128 (ib));
535   if (caller == NULL || caller->decl == NULL_TREE)
536     internal_error ("bytecode stream: no caller found while reading edge");
537
538   callee = VEC_index (cgraph_node_ptr, nodes, lto_input_sleb128 (ib));
539   if (callee == NULL || callee->decl == NULL_TREE)
540     internal_error ("bytecode stream: no callee found while reading edge");
541
542   caller_resolution = lto_symtab_get_resolution (caller->decl);
543
544   count = (gcov_type) lto_input_sleb128 (ib);
545
546   bp = lto_input_bitpack (ib);
547   stmt_id = (unsigned int) bp_unpack_value (bp, HOST_BITS_PER_INT);
548   inline_failed = (cgraph_inline_failed_t) bp_unpack_value (bp,
549                                                             HOST_BITS_PER_INT);
550   freq = (int) bp_unpack_value (bp, HOST_BITS_PER_INT);
551   nest = (unsigned) bp_unpack_value (bp, 30);
552
553   /* If the caller was preempted, don't create the edge.  */
554   if (caller_resolution == LDPR_PREEMPTED_REG
555       || caller_resolution == LDPR_PREEMPTED_IR)
556     return;
557
558   prevailing_callee = lto_symtab_prevailing_decl (callee->decl);
559
560   /* Make sure the caller is the prevailing decl.  */
561   prevailing_caller = lto_symtab_prevailing_decl (caller->decl);
562
563   if (prevailing_callee != callee->decl)
564     {
565       struct lto_file_decl_data *file_data;
566
567       /* We cannot replace a clone!  */
568       gcc_assert (callee == cgraph_node (callee->decl));
569
570       callee = cgraph_node (prevailing_callee);
571       gcc_assert (callee);
572
573       /* If LGEN (cc1 or cc1plus) had nothing to do with the node, it
574          might not have created it. In this case, we just created a
575          new node in the above call to cgraph_node. Mark the file it
576          came from. */
577       file_data = lto_symtab_get_file_data (prevailing_callee);
578       if (callee->local.lto_file_data)
579         gcc_assert (callee->local.lto_file_data == file_data);
580       else
581         callee->local.lto_file_data = file_data;
582     }
583
584   edge = cgraph_create_edge (caller, callee, NULL, count, freq, nest);
585   edge->lto_stmt_uid = stmt_id;
586   edge->inline_failed = inline_failed;
587   edge->indirect_call = bp_unpack_value (bp, 1);
588   edge->call_stmt_cannot_inline_p = bp_unpack_value (bp, 1);
589   edge->can_throw_external = bp_unpack_value (bp, 1);
590   bitpack_delete (bp);
591 }
592
593
594 /* Read a cgraph from IB using the info in FILE_DATA.  */
595
596 static void
597 input_cgraph_1 (struct lto_file_decl_data *file_data,
598                 struct lto_input_block *ib)
599 {
600   enum LTO_cgraph_tags tag;
601   VEC(cgraph_node_ptr, heap) *nodes = NULL;
602   struct cgraph_node *node;
603   unsigned i;
604
605   tag = (enum LTO_cgraph_tags) lto_input_uleb128 (ib);
606   while (tag)
607     {
608       if (tag == LTO_cgraph_edge)
609         input_edge (ib, nodes);
610       else 
611         {
612           node = input_node (file_data, ib, tag);
613           if (node == NULL || node->decl == NULL_TREE)
614             internal_error ("bytecode stream: found empty cgraph node");
615           VEC_safe_push (cgraph_node_ptr, heap, nodes, node);
616           lto_cgraph_encoder_encode (file_data->cgraph_node_encoder, node);
617         }
618
619       tag = (enum LTO_cgraph_tags) lto_input_uleb128 (ib);
620     }
621
622   for (i = 0; VEC_iterate (cgraph_node_ptr, nodes, i, node); i++)
623     {
624       const int ref = (int) (intptr_t) node->global.inlined_to;
625
626       /* Fixup inlined_to from reference to pointer.  */
627       if (ref != LCC_NOT_FOUND)
628         node->global.inlined_to = VEC_index (cgraph_node_ptr, nodes, ref);
629       else
630         node->global.inlined_to = NULL;
631     }
632
633   for (i = 0; VEC_iterate (cgraph_node_ptr, nodes, i, node); i++)
634     {
635       tree prevailing = lto_symtab_prevailing_decl (node->decl);
636
637       if (prevailing != node->decl)
638         {
639           cgraph_remove_node (node);
640           VEC_replace (cgraph_node_ptr, nodes, i, NULL);
641         }
642     }
643
644   for (i = 0; VEC_iterate (cgraph_node_ptr, nodes, i, node); i++)
645     if (node && cgraph_decide_is_function_needed (node, node->decl))
646       cgraph_mark_needed_node (node);
647
648   VEC_free (cgraph_node_ptr, heap, nodes);
649 }
650
651
652 /* Input and merge the cgraph from each of the .o files passed to
653    lto1.  */
654
655 void
656 input_cgraph (void)
657 {
658   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
659   struct lto_file_decl_data *file_data;
660   unsigned int j = 0;
661   struct cgraph_node *node;
662
663   while ((file_data = file_data_vec[j++]))
664     {
665       const char *data;
666       size_t len;
667       struct lto_input_block *ib;
668
669       ib = lto_create_simple_input_block (file_data, LTO_section_cgraph, 
670                                           &data, &len);
671       file_data->cgraph_node_encoder = lto_cgraph_encoder_new ();
672       input_cgraph_1 (file_data, ib);
673       lto_destroy_simple_input_block (file_data, LTO_section_cgraph, 
674                                       ib, data, len);
675       
676       /* Assume that every file read needs to be processed by LTRANS.  */
677       if (flag_wpa)
678         lto_mark_file_for_ltrans (file_data);
679     } 
680
681   /* Clear out the aux field that was used to store enough state to
682      tell which nodes should be overwritten.  */
683   for (node = cgraph_nodes; node; node = node->next)
684     {
685       /* Some nodes may have been created by cgraph_node.  This
686          happens when the callgraph contains nested functions.  If the
687          node for the parent function was never emitted to the gimple
688          file, cgraph_node will create a node for it when setting the
689          context of the nested function.  */
690       if (node->local.lto_file_data)
691         node->aux = NULL;
692     }
693 }