OSDN Git Service

40f3c30fb640712f056651bca4971bcef6481487
[pf3gnuchains/gcc-fork.git] / gcc / lto / lto.c
1 /* Top-level LTO routines.
2    Copyright 2009 Free Software Foundation, Inc.
3    Contributed by CodeSourcery, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "opts.h"
25 #include "toplev.h"
26 #include "tree.h"
27 #include "diagnostic.h"
28 #include "tm.h"
29 #include "libiberty.h"
30 #include "cgraph.h"
31 #include "ggc.h"
32 #include "tree-ssa-operands.h"
33 #include "tree-pass.h"
34 #include "langhooks.h"
35 #include "vec.h"
36 #include "bitmap.h"
37 #include "pointer-set.h"
38 #include "ipa-prop.h"
39 #include "common.h"
40 #include "timevar.h"
41 #include "gimple.h"
42 #include "lto.h"
43 #include "lto-tree.h"
44 #include "lto-streamer.h"
45
46 /* This needs to be included after config.h.  Otherwise, _GNU_SOURCE will not
47    be defined in time to set __USE_GNU in the system headers, and strsignal
48    will not be declared.  */
49 #if HAVE_MMAP_FILE
50 #include <sys/mman.h>
51 #endif
52
53 DEF_VEC_P(bitmap);
54 DEF_VEC_ALLOC_P(bitmap,heap);
55
56 /* Read the constructors and inits.  */
57
58 static void
59 lto_materialize_constructors_and_inits (struct lto_file_decl_data * file_data)
60 {
61   size_t len;
62   const char *data = lto_get_section_data (file_data, 
63                                            LTO_section_static_initializer,
64                                            NULL, &len);
65   lto_input_constructors_and_inits (file_data, data);
66   lto_free_section_data (file_data, LTO_section_static_initializer, NULL,
67                          data, len);
68 }
69
70 /* Read the function body for the function associated with NODE if possible.  */
71
72 static void
73 lto_materialize_function (struct cgraph_node *node)
74 {
75   tree decl;
76   struct lto_file_decl_data *file_data;
77   const char *data, *name;
78   size_t len;
79   tree step;
80
81   /* Ignore clone nodes.  Read the body only from the original one.
82      We may find clone nodes during LTRANS after WPA has made inlining
83      decisions.  */
84   if (node->clone_of)
85     return;
86
87   decl = node->decl;
88   file_data = node->local.lto_file_data;
89   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); 
90
91   /* We may have renamed the declaration, e.g., a static function.  */
92   name = lto_get_decl_name_mapping (file_data, name);
93
94   data = lto_get_section_data (file_data, LTO_section_function_body,
95                                name, &len);
96   if (data)
97     {
98       struct function *fn;
99
100       gcc_assert (!DECL_IS_BUILTIN (decl));
101
102       /* This function has a definition.  */
103       TREE_STATIC (decl) = 1;
104
105       gcc_assert (DECL_STRUCT_FUNCTION (decl) == NULL);
106       allocate_struct_function (decl, false);
107
108       /* Load the function body only if not operating in WPA mode.  In
109          WPA mode, the body of the function is not needed.  */
110       if (!flag_wpa)
111         {
112           lto_input_function_body (file_data, decl, data);
113           lto_stats.num_function_bodies++;
114         }
115
116       fn = DECL_STRUCT_FUNCTION (decl);
117       lto_free_section_data (file_data, LTO_section_function_body, name,
118                              data, len);
119
120       /* Look for initializers of constant variables and private
121          statics.  */
122       for (step = fn->local_decls; step; step = TREE_CHAIN (step))
123         {
124           tree decl = TREE_VALUE (step);
125           if (TREE_CODE (decl) == VAR_DECL
126               && (TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
127               && flag_unit_at_a_time)
128             varpool_finalize_decl (decl);
129         }
130     }
131   else
132     DECL_EXTERNAL (decl) = 1;
133
134   /* Let the middle end know about the function.  */
135   rest_of_decl_compilation (decl, 1, 0);
136   if (cgraph_node (decl)->needed)
137     cgraph_mark_reachable_node (cgraph_node (decl));
138 }
139
140
141 /* Decode the content of memory pointed to by DATA in the the
142    in decl state object STATE. DATA_IN points to a data_in structure for
143    decoding. Return the address after the decoded object in the input.  */
144
145 static const uint32_t *
146 lto_read_in_decl_state (struct data_in *data_in, const uint32_t *data,
147                         struct lto_in_decl_state *state)
148 {
149   uint32_t ix;
150   tree decl;
151   uint32_t i, j;
152   
153   ix = *data++;
154   decl = lto_streamer_cache_get (data_in->reader_cache, (int) ix);
155   if (TREE_CODE (decl) != FUNCTION_DECL)
156     {
157       gcc_assert (decl == void_type_node);
158       decl = NULL_TREE;
159     }
160   state->fn_decl = decl;
161
162   for (i = 0; i < LTO_N_DECL_STREAMS; i++)
163     {
164       uint32_t size = *data++;
165       tree *decls = (tree *) xcalloc (size, sizeof (tree));
166
167       for (j = 0; j < size; j++)
168         {
169           decls[j] = lto_streamer_cache_get (data_in->reader_cache, data[j]);
170
171           /* Register every type in the global type table.  If the
172              type existed already, use the existing type.  */
173           if (TYPE_P (decls[j]))
174             decls[j] = gimple_register_type (decls[j]);
175         }
176
177       state->streams[i].size = size;
178       state->streams[i].trees = decls;
179       data += size;
180     }
181
182   return data;
183 }
184
185
186 /* Read all the symbols from buffer DATA, using descriptors in DECL_DATA.
187    RESOLUTIONS is the set of symbols picked by the linker (read from the
188    resolution file when the linker plugin is being used).  */
189
190 static void
191 lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
192                 VEC(ld_plugin_symbol_resolution_t,heap) *resolutions)
193 {
194   const struct lto_decl_header *header = (const struct lto_decl_header *) data;
195   const int32_t decl_offset = sizeof (struct lto_decl_header);
196   const int32_t main_offset = decl_offset + header->decl_state_size;
197   const int32_t string_offset = main_offset + header->main_size;
198   struct lto_input_block ib_main;
199   struct data_in *data_in;
200   unsigned int i;
201   const uint32_t *data_ptr, *data_end;
202   uint32_t num_decl_states;
203
204   LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0,
205                         header->main_size);
206
207   data_in = lto_data_in_create (decl_data, (const char *) data + string_offset,
208                                 header->string_size, resolutions);
209
210   /* Read the global declarations and types.  */
211   while (ib_main.p < ib_main.len)
212     {
213       tree t = lto_input_tree (&ib_main, data_in);
214       gcc_assert (t && ib_main.p <= ib_main.len);
215     }
216
217   /* Read in lto_in_decl_state objects.  */
218   data_ptr = (const uint32_t *) ((const char*) data + decl_offset); 
219   data_end =
220      (const uint32_t *) ((const char*) data_ptr + header->decl_state_size);
221   num_decl_states = *data_ptr++;
222   
223   gcc_assert (num_decl_states > 0);
224   decl_data->global_decl_state = lto_new_in_decl_state ();
225   data_ptr = lto_read_in_decl_state (data_in, data_ptr,
226                                      decl_data->global_decl_state);
227
228   /* Read in per-function decl states and enter them in hash table.  */
229   decl_data->function_decl_states =
230     htab_create (37, lto_hash_in_decl_state, lto_eq_in_decl_state, free);
231
232   for (i = 1; i < num_decl_states; i++)
233     {
234       struct lto_in_decl_state *state = lto_new_in_decl_state ();
235       void **slot;
236
237       data_ptr = lto_read_in_decl_state (data_in, data_ptr, state);
238       slot = htab_find_slot (decl_data->function_decl_states, state, INSERT);
239       gcc_assert (*slot == NULL);
240       *slot = state;
241     }
242
243   if (data_ptr != data_end)
244     internal_error ("bytecode stream: garbage at the end of symbols section");
245   
246   /* Set the current decl state to be the global state. */
247   decl_data->current_decl_state = decl_data->global_decl_state;
248
249   lto_data_in_delete (data_in);
250 }
251
252 /* Read resolution for file named FILE_NAME. The resolution is read from
253    RESOLUTION. An array with the symbol resolution is returned. The array
254    size is written to SIZE. */
255
256 static VEC(ld_plugin_symbol_resolution_t,heap) *
257 lto_resolution_read (FILE *resolution, const char *file_name)
258 {
259   /* We require that objects in the resolution file are in the same
260      order as the lto1 command line. */
261   unsigned int name_len;
262   char *obj_name;
263   unsigned int num_symbols;
264   unsigned int i;
265   VEC(ld_plugin_symbol_resolution_t,heap) *ret = NULL;
266   unsigned max_index = 0;
267
268   if (!resolution)
269     return NULL;
270
271   name_len = strlen (file_name);
272   obj_name = XNEWVEC (char, name_len + 1);
273   fscanf (resolution, " ");   /* Read white space. */
274
275   fread (obj_name, sizeof (char), name_len, resolution);
276   obj_name[name_len] = '\0';
277   if (strcmp (obj_name, file_name) != 0)
278     internal_error ("unexpected file name %s in linker resolution file. "
279                     "Expected %s", obj_name, file_name);
280
281   free (obj_name);
282
283   fscanf (resolution, "%u", &num_symbols);
284
285   for (i = 0; i < num_symbols; i++)
286     {
287       int t;
288       unsigned index;
289       char r_str[27];
290       enum ld_plugin_symbol_resolution r;
291       unsigned int j;
292       unsigned int lto_resolution_str_len =
293         sizeof (lto_resolution_str) / sizeof (char *);
294
295       t = fscanf (resolution, "%u %26s %*[^\n]\n", &index, r_str);
296       if (t != 2)
297         internal_error ("Invalid line in the resolution file.");
298       if (index > max_index)
299         max_index = index;
300
301       for (j = 0; j < lto_resolution_str_len; j++)
302         {
303           if (strcmp (lto_resolution_str[j], r_str) == 0)
304             {
305               r = (enum ld_plugin_symbol_resolution) j;
306               break;
307             }
308         }
309       if (j == lto_resolution_str_len)
310         internal_error ("Invalid resolution in the resolution file.");
311
312       VEC_safe_grow_cleared (ld_plugin_symbol_resolution_t, heap, ret,
313                              index + 1);
314       VEC_replace (ld_plugin_symbol_resolution_t, ret, index, r);
315     }
316
317   return ret;
318 }
319
320 /* Generate a TREE representation for all types and external decls
321    entities in FILE.  
322
323    Read all of the globals out of the file.  Then read the cgraph
324    and process the .o index into the cgraph nodes so that it can open
325    the .o file to load the functions and ipa information.   */
326
327 static struct lto_file_decl_data *
328 lto_file_read (lto_file *file, FILE *resolution_file)
329 {
330   struct lto_file_decl_data *file_data;
331   const char *data;
332   size_t len;
333   VEC(ld_plugin_symbol_resolution_t,heap) *resolutions;
334   
335   resolutions = lto_resolution_read (resolution_file, file->filename);
336
337   file_data = XCNEW (struct lto_file_decl_data);
338   file_data->file_name = file->filename;
339   file_data->section_hash_table = lto_elf_build_section_table (file);
340   file_data->renaming_hash_table = lto_create_renaming_table ();
341
342   data = lto_get_section_data (file_data, LTO_section_decls, NULL, &len);
343   lto_read_decls (file_data, data, resolutions);
344   lto_free_section_data (file_data, LTO_section_decls, NULL, data, len);
345
346   return file_data;
347 }
348
349 #if HAVE_MMAP_FILE && HAVE_SYSCONF && defined _SC_PAGE_SIZE
350 #define LTO_MMAP_IO 1
351 #endif
352
353 #if LTO_MMAP_IO
354 /* Page size of machine is used for mmap and munmap calls.  */
355 static size_t page_mask;
356 #endif
357
358 /* Get the section data of length LEN from FILENAME starting at
359    OFFSET.  The data segment must be freed by the caller when the
360    caller is finished.  Returns NULL if all was not well.  */
361
362 static char *
363 lto_read_section_data (struct lto_file_decl_data *file_data,
364                        intptr_t offset, size_t len)
365 {
366   char *result;
367   static int fd = -1;
368   static char *fd_name;
369 #if LTO_MMAP_IO
370   intptr_t computed_len;
371   intptr_t computed_offset;
372   intptr_t diff;
373 #endif
374
375   /* Keep a single-entry file-descriptor cache.  The last file we
376      touched will get closed at exit.
377      ???  Eventually we want to add a more sophisticated larger cache
378      or rather fix function body streaming to not stream them in
379      practically random order.  */
380   if (fd != -1
381       && strcmp (fd_name, file_data->file_name) != 0)
382     {
383       free (fd_name);
384       close (fd);
385       fd = -1;
386     }
387   if (fd == -1)
388     {
389       fd_name = xstrdup (file_data->file_name);
390       fd = open (file_data->file_name, O_RDONLY);
391       if (fd == -1)
392         return NULL;
393     }
394
395 #if LTO_MMAP_IO
396   if (!page_mask)
397     {
398       size_t page_size = sysconf (_SC_PAGE_SIZE);
399       page_mask = ~(page_size - 1);
400     }
401
402   computed_offset = offset & page_mask;
403   diff = offset - computed_offset;
404   computed_len = len + diff;
405
406   result = (char *) mmap (NULL, computed_len, PROT_READ, MAP_PRIVATE,
407                           fd, computed_offset);
408   if (result == MAP_FAILED)
409     return NULL;
410
411   return result + diff;
412 #else
413   result = (char *) xmalloc (len);
414   if (lseek (fd, offset, SEEK_SET) != offset
415       || read (fd, result, len) != (ssize_t) len)
416     {
417       free (result);
418       return NULL;
419     }
420
421   return result;
422 #endif
423 }    
424
425
426 /* Get the section data from FILE_DATA of SECTION_TYPE with NAME.
427    NAME will be NULL unless the section type is for a function
428    body.  */
429
430 static const char *
431 get_section_data (struct lto_file_decl_data *file_data,
432                       enum lto_section_type section_type,
433                       const char *name,
434                       size_t *len)
435 {
436   htab_t section_hash_table = file_data->section_hash_table;
437   struct lto_section_slot *f_slot;
438   struct lto_section_slot s_slot;
439   const char *section_name = lto_get_section_name (section_type, name);
440   char *data = NULL;
441
442   *len = 0;
443   s_slot.name = section_name;
444   f_slot = (struct lto_section_slot *) htab_find (section_hash_table, &s_slot);
445   if (f_slot)
446     {
447       data = lto_read_section_data (file_data, f_slot->start, f_slot->len);
448       *len = f_slot->len;
449     }
450
451   free (CONST_CAST (char *, section_name));
452   return data;
453 }
454
455
456 /* Free the section data from FILE_DATA of SECTION_TYPE with NAME that
457    starts at OFFSET and has LEN bytes.  */
458
459 static void
460 free_section_data (struct lto_file_decl_data *file_data ATTRIBUTE_UNUSED,
461                    enum lto_section_type section_type ATTRIBUTE_UNUSED,
462                    const char *name ATTRIBUTE_UNUSED,
463                    const char *offset, size_t len ATTRIBUTE_UNUSED)
464 {
465 #if LTO_MMAP_IO
466   intptr_t computed_len;
467   intptr_t computed_offset;
468   intptr_t diff;
469 #endif
470
471 #if LTO_MMAP_IO
472   computed_offset = ((intptr_t) offset) & page_mask;
473   diff = (intptr_t) offset - computed_offset;
474   computed_len = len + diff;
475
476   munmap ((caddr_t) computed_offset, computed_len);
477 #else
478   free (CONST_CAST(char *, offset));
479 #endif
480 }
481
482 /* Vector of all cgraph node sets. */
483 static GTY (()) VEC(cgraph_node_set, gc) *lto_cgraph_node_sets;
484
485
486 /* Group cgrah nodes by input files.  This is used mainly for testing
487    right now.  */
488
489 static void
490 lto_1_to_1_map (void)
491 {
492   struct cgraph_node *node;
493   struct lto_file_decl_data *file_data;
494   struct pointer_map_t *pmap;
495   cgraph_node_set set;
496   void **slot;
497
498   timevar_push (TV_WHOPR_WPA);
499
500   lto_cgraph_node_sets = VEC_alloc (cgraph_node_set, gc, 1);
501
502   /* If the cgraph is empty, create one cgraph node set so that there is still
503      an output file for any variables that need to be exported in a DSO.  */
504   if (!cgraph_nodes)
505     {
506       set = cgraph_node_set_new ();
507       VEC_safe_push (cgraph_node_set, gc, lto_cgraph_node_sets, set);
508       goto finish;
509     }
510
511   pmap = pointer_map_create ();
512
513   for (node = cgraph_nodes; node; node = node->next)
514     {
515       /* We only need to partition the nodes that we read from the
516          gimple bytecode files.  */
517       file_data = node->local.lto_file_data;
518       if (file_data == NULL)
519         continue;
520
521       slot = pointer_map_contains (pmap, file_data);
522       if (slot)
523         set = (cgraph_node_set) *slot;
524       else
525         {
526           set = cgraph_node_set_new ();
527           slot = pointer_map_insert (pmap, file_data);
528           *slot = set;
529           VEC_safe_push (cgraph_node_set, gc, lto_cgraph_node_sets, set);
530         }
531
532       cgraph_node_set_add (set, node);
533     }
534
535   pointer_map_destroy (pmap);
536
537 finish:
538   timevar_pop (TV_WHOPR_WPA);
539
540   lto_stats.num_cgraph_partitions += VEC_length (cgraph_node_set, 
541                                                  lto_cgraph_node_sets);
542 }
543
544
545 /* Add inlined clone NODE and its master clone to SET, if NODE itself has
546    inlined callees, recursively add the callees.  */
547
548 static void
549 lto_add_inline_clones (cgraph_node_set set, struct cgraph_node *node,
550                        bitmap original_decls, bitmap inlined_decls)
551 {
552    struct cgraph_node *callee;
553    struct cgraph_edge *edge;
554
555    cgraph_node_set_add (set, node);
556
557    if (!bitmap_bit_p (original_decls, DECL_UID (node->decl)))
558      bitmap_set_bit (inlined_decls, DECL_UID (node->decl));
559
560    /* Check to see if NODE has any inlined callee.  */
561    for (edge = node->callees; edge != NULL; edge = edge->next_callee)
562      {
563         callee = edge->callee;
564         if (callee->global.inlined_to != NULL)
565           lto_add_inline_clones (set, callee, original_decls, inlined_decls);
566      }
567 }
568
569 /* Compute the transitive closure of inlining of SET based on the
570    information in the callgraph.  Returns a bitmap of decls that have
571    been inlined into SET indexed by UID.  */
572
573 static bitmap
574 lto_add_all_inlinees (cgraph_node_set set)
575 {
576   cgraph_node_set_iterator csi;
577   struct cgraph_node *node;
578   bitmap original_nodes = lto_bitmap_alloc ();
579   bitmap original_decls = lto_bitmap_alloc ();
580   bitmap inlined_decls = lto_bitmap_alloc ();
581   bool changed;
582
583   /* We are going to iterate SET while adding to it, mark all original
584      nodes so that we only add node inlined to original nodes.  */
585   for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
586     {
587       bitmap_set_bit (original_nodes, csi_node (csi)->uid);
588       bitmap_set_bit (original_decls, DECL_UID (csi_node (csi)->decl));
589     }
590
591   /* Some of the original nodes might not be needed anymore.  
592      Remove them.  */
593   do
594     {
595       changed = false;
596       for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
597         {
598           struct cgraph_node *inlined_to;
599           node = csi_node (csi);
600
601           /* NODE was not inlined.  We still need it.  */
602           if (!node->global.inlined_to)
603             continue;
604
605           inlined_to = node->global.inlined_to;
606
607           /* NODE should have only one caller.  */
608           gcc_assert (!node->callers->next_caller);
609
610           if (!bitmap_bit_p (original_nodes, inlined_to->uid))
611             {
612               bitmap_clear_bit (original_nodes, node->uid);
613               cgraph_node_set_remove (set, node);
614               changed = true;
615             }
616         }
617     }
618   while (changed);
619
620   /* Transitively add to SET all the inline clones for every node that
621      has been inlined.  */
622   for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
623     {
624       node = csi_node (csi);
625       if (bitmap_bit_p (original_nodes, node->uid))
626         lto_add_inline_clones (set, node, original_decls, inlined_decls);
627     }
628
629   lto_bitmap_free (original_nodes);
630   lto_bitmap_free (original_decls);
631
632   return inlined_decls;
633 }
634
635 /* Owing to inlining, we may need to promote a file-scope variable
636    to a global variable.  Consider this case:
637
638    a.c:
639    static int var;
640
641    void
642    foo (void)
643    {
644      var++;
645    }
646
647    b.c:
648
649    extern void foo (void);
650
651    void
652    bar (void)
653    {
654      foo ();
655    }
656
657    If WPA inlines FOO inside BAR, then the static variable VAR needs to
658    be promoted to global because BAR and VAR may be in different LTRANS
659    files. */
660
661 /* This struct keeps track of states used in globalization.  */
662
663 typedef struct
664 {
665   /* Current cgraph node set.  */  
666   cgraph_node_set set;
667
668   /* Function DECLs of cgraph nodes seen.  */
669   bitmap seen_node_decls;
670
671   /* Use in walk_tree to avoid multiple visits of a node.  */
672   struct pointer_set_t *visited;
673
674   /* static vars in this set.  */
675   bitmap static_vars_in_set;
676
677   /* static vars in all previous set.  */
678   bitmap all_static_vars;
679
680   /* all vars in all previous set.  */
681   bitmap all_vars;
682 } globalize_context_t;
683
684 /* Callback for walk_tree.  Examine the tree pointer to by TP and see if
685    if its a file-scope static variable of function that need to be turned
686    into a global.  */
687
688 static tree
689 globalize_cross_file_statics (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
690                               void *data)
691 {
692   globalize_context_t *context = (globalize_context_t *) data;
693   tree t = *tp;
694
695   if (t == NULL_TREE)
696     return NULL;
697
698   /* The logic for globalization of VAR_DECLs and FUNCTION_DECLs are
699      different.  For functions, we can simply look at the cgraph node sets
700      to tell if there are references to static functions outside the set.
701      The cgraph node sets do not keep track of vars, we need to traverse
702      the trees to determine what vars need to be globalized.  */
703   if (TREE_CODE (t) == VAR_DECL)
704     {
705       if (!TREE_PUBLIC (t))
706         {
707           /* This file-scope static variable is reachable from more
708              that one set.  Make it global but with hidden visibility
709              so that we do not export it in dynamic linking.  */
710           if (bitmap_bit_p (context->all_static_vars, DECL_UID (t)))
711             {
712               TREE_PUBLIC (t) = 1;
713               DECL_VISIBILITY (t) = VISIBILITY_HIDDEN;
714             }
715           bitmap_set_bit (context->static_vars_in_set, DECL_UID (t));
716         }
717       bitmap_set_bit (context->all_vars, DECL_UID (t));
718       walk_tree (&DECL_INITIAL (t), globalize_cross_file_statics, context,
719                  context->visited);
720     }
721   else if (TREE_CODE (t) == FUNCTION_DECL && !TREE_PUBLIC (t))
722     {
723       if (!cgraph_node_in_set_p (cgraph_node (t), context->set))
724         {
725           /* This file-scope static function is reachable from a set
726              which does not contain the function DECL.  Make it global
727              but with hidden visibility.  */
728           TREE_PUBLIC (t) = 1;
729           DECL_VISIBILITY (t) = VISIBILITY_HIDDEN;
730         }
731     }
732
733   return NULL; 
734 }
735
736 /* Helper of lto_scan_statics_in_cgraph_node below.  Scan TABLE for
737    static decls that may be used in more than one LTRANS file.
738    CONTEXT is a globalize_context_t for storing scanning states.  */
739
740 static void
741 lto_scan_statics_in_ref_table (struct lto_tree_ref_table *table,
742                                globalize_context_t *context)
743 {
744   unsigned i;
745
746   for (i = 0; i < table->size; i++)
747     walk_tree (&table->trees[i], globalize_cross_file_statics, context,
748                context->visited);
749 }
750
751 /* Promote file-scope decl reachable from NODE if necessary to global.
752    CONTEXT is a globalize_context_t storing scanning states.  */
753
754 static void
755 lto_scan_statics_in_cgraph_node (struct cgraph_node *node,
756                                  globalize_context_t *context)
757 {
758   struct lto_in_decl_state *state;
759   
760   /* Do nothing if NODE has no function body.  */
761   if (!node->analyzed)
762     return;
763   
764   /* Return if the DECL of nodes has been visited before.  */
765   if (bitmap_bit_p (context->seen_node_decls, DECL_UID (node->decl)))
766     return;
767
768   bitmap_set_bit (context->seen_node_decls, DECL_UID (node->decl));
769
770   state = lto_get_function_in_decl_state (node->local.lto_file_data,
771                                           node->decl);
772   gcc_assert (state);
773
774   lto_scan_statics_in_ref_table (&state->streams[LTO_DECL_STREAM_VAR_DECL],
775                                  context);
776   lto_scan_statics_in_ref_table (&state->streams[LTO_DECL_STREAM_FN_DECL],
777                                  context);
778 }
779
780 /* Scan all global variables that we have not yet seen so far.  CONTEXT
781    is a globalize_context_t storing scanning states.  */
782
783 static void
784 lto_scan_statics_in_remaining_global_vars (globalize_context_t *context)
785 {
786   tree var, var_context;
787   struct varpool_node *vnode;
788
789   FOR_EACH_STATIC_VARIABLE (vnode)
790     {
791       var = vnode->decl;
792       var_context = DECL_CONTEXT (var);
793       if (TREE_STATIC (var)
794           && TREE_PUBLIC (var)
795           && (!var_context || TREE_CODE (var_context) != FUNCTION_DECL)
796           && !bitmap_bit_p (context->all_vars, DECL_UID (var)))
797         walk_tree (&var, globalize_cross_file_statics, context,
798                    context->visited);
799     }
800 }
801
802 /* Find out all static decls that need to be promoted to global because
803    of cross file sharing.  This function must be run in the WPA mode after
804    all inlinees are added.  */
805
806 static void
807 lto_promote_cross_file_statics (void)
808 {
809   unsigned i, n_sets;
810   cgraph_node_set set;
811   cgraph_node_set_iterator csi;
812   globalize_context_t context;
813
814   memset (&context, 0, sizeof (context));
815   context.all_vars = lto_bitmap_alloc ();
816   context.all_static_vars = lto_bitmap_alloc ();
817
818   n_sets = VEC_length (cgraph_node_set, lto_cgraph_node_sets);
819   for (i = 0; i < n_sets; i++)
820     {
821       set = VEC_index (cgraph_node_set, lto_cgraph_node_sets, i);
822       context.set = set;
823       context.visited = pointer_set_create ();
824       context.static_vars_in_set = lto_bitmap_alloc ();
825       context.seen_node_decls = lto_bitmap_alloc ();
826
827       for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
828         lto_scan_statics_in_cgraph_node (csi_node (csi), &context);
829
830       if (i == n_sets - 1)
831         lto_scan_statics_in_remaining_global_vars (&context);
832
833       bitmap_ior_into (context.all_static_vars, context.static_vars_in_set);
834
835       pointer_set_destroy (context.visited);
836       lto_bitmap_free (context.static_vars_in_set);
837       lto_bitmap_free (context.seen_node_decls);
838     }
839
840   lto_bitmap_free (context.all_vars);
841   lto_bitmap_free (context.all_static_vars);
842 }
843
844
845 /* Given a file name FNAME, return a string with FNAME prefixed with '*'.  */
846
847 static char *
848 prefix_name_with_star (const char *fname)
849 {
850   char *star_fname;
851   size_t len;
852   
853   len = strlen (fname) + 1 + 1;
854   star_fname = XNEWVEC (char, len);
855   snprintf (star_fname, len, "*%s", fname);
856
857   return star_fname;
858 }
859
860
861 /* Return a copy of FNAME without the .o extension.  */
862
863 static char *
864 strip_extension (const char *fname)
865 {
866   char *s = XNEWVEC (char, strlen (fname) - 2 + 1);
867   gcc_assert (strstr (fname, ".o"));
868   snprintf (s, strlen (fname) - 2 + 1, "%s", fname);
869
870   return s;
871 }
872
873
874 /* Return a file name associated with cgraph node set SET.  This may
875    be a new temporary file name if SET needs to be processed by
876    LTRANS, or the original file name if all the nodes in SET belong to
877    the same input file.  */
878
879 static char *
880 get_filename_for_set (cgraph_node_set set)
881 {
882   char *fname = NULL;
883   static const size_t max_fname_len = 100;
884
885   if (cgraph_node_set_needs_ltrans_p (set))
886     {
887       /* Create a new temporary file to store SET.  To facilitate
888          debugging, use file names from SET as part of the new
889          temporary file name.  */
890       cgraph_node_set_iterator si;
891       struct pointer_set_t *pset = pointer_set_create ();
892       for (si = csi_start (set); !csi_end_p (si); csi_next (&si))
893         {
894           struct cgraph_node *n = csi_node (si);
895           const char *node_fname;
896           char *f;
897
898           /* Don't use the same file name more than once.  */
899           if (pointer_set_insert (pset, n->local.lto_file_data))
900             continue;
901
902           /* The first file name found in SET determines the output
903              directory.  For the remaining files, we use their
904              base names.  */
905           node_fname = n->local.lto_file_data->file_name;
906           if (fname == NULL)
907             {
908               fname = strip_extension (node_fname);
909               continue;
910             }
911
912           f = strip_extension (lbasename (node_fname));
913
914           /* If the new name causes an excessively long file name,
915              make the last component "___" to indicate overflow.  */
916           if (strlen (fname) + strlen (f) > max_fname_len - 3)
917             {
918               fname = reconcat (fname, fname, "___", NULL);
919               break;
920             }
921           else
922             {
923               fname = reconcat (fname, fname, "_", f, NULL);
924               free (f);
925             }
926         }
927
928       pointer_set_destroy (pset);
929
930       /* Add the extension .wpa.o to indicate that this file has been
931          produced by WPA.  */
932       fname = reconcat (fname, fname, ".wpa.o", NULL);
933       gcc_assert (fname);
934     }
935   else
936     {
937       /* Since SET does not need to be processed by LTRANS, use
938          the original file name and mark it with a '*' prefix so that
939          lto_execute_ltrans knows not to process it.  */
940       cgraph_node_set_iterator si = csi_start (set);
941       struct cgraph_node *first = csi_node (si);
942       fname = prefix_name_with_star (first->local.lto_file_data->file_name);
943     }
944
945   return fname;
946 }
947
948 static lto_file *current_lto_file;
949
950
951 /* Write all output files in WPA mode.  Returns a NULL-terminated array of
952    output file names.  */
953
954 static char **
955 lto_wpa_write_files (void)
956 {
957   char **output_files;
958   unsigned i, n_sets, last_out_file_ix, num_out_files;
959   lto_file *file;
960   cgraph_node_set set;
961   bitmap decls;
962   VEC(bitmap,heap) *inlined_decls = NULL;
963
964   timevar_push (TV_WHOPR_WPA);
965
966   /* Include all inlined functions and determine what sets need to be
967      compiled by LTRANS.  After this loop, only those sets that
968      contain callgraph nodes from more than one file will need to be
969      compiled by LTRANS.  */
970   for (i = 0; VEC_iterate (cgraph_node_set, lto_cgraph_node_sets, i, set); i++)
971     {
972       decls = lto_add_all_inlinees (set);
973       VEC_safe_push (bitmap, heap, inlined_decls, decls);
974       lto_stats.num_output_cgraph_nodes += VEC_length (cgraph_node_ptr,
975                                                        set->nodes);
976     }
977
978   /* After adding all inlinees, find out statics that need to be promoted
979      to globals because of cross-file inlining.  */
980   lto_promote_cross_file_statics ();
981
982   timevar_pop (TV_WHOPR_WPA);
983
984   timevar_push (TV_WHOPR_WPA_IO);
985
986   /* The number of output files depends on the number of input files
987      and how many callgraph node sets we create.  Reserve enough space
988      for the maximum of these two.  */
989   num_out_files = MAX (VEC_length (cgraph_node_set, lto_cgraph_node_sets),
990                        num_in_fnames);
991   output_files = XNEWVEC (char *, num_out_files + 1);
992
993   n_sets = VEC_length (cgraph_node_set, lto_cgraph_node_sets);
994   for (i = 0; i < n_sets; i++)
995     {
996       char *temp_filename;
997
998       set = VEC_index (cgraph_node_set, lto_cgraph_node_sets, i);
999       temp_filename = get_filename_for_set (set);
1000       output_files[i] = temp_filename;
1001
1002       if (cgraph_node_set_needs_ltrans_p (set))
1003         {
1004           /* Write all the nodes in SET to TEMP_FILENAME.  */
1005           file = lto_elf_file_open (temp_filename, true);
1006           if (!file)
1007             fatal_error ("lto_elf_file_open() failed");
1008
1009           lto_set_current_out_file (file);
1010           lto_new_extern_inline_states ();
1011
1012           decls = VEC_index (bitmap, inlined_decls, i);
1013           lto_force_functions_extern_inline (decls);
1014
1015           ipa_write_summaries_of_cgraph_node_set (set);
1016           lto_delete_extern_inline_states ();
1017
1018           lto_set_current_out_file (NULL);
1019           lto_elf_file_close (file);
1020         }
1021     }
1022
1023   last_out_file_ix = n_sets;
1024
1025   lto_stats.num_output_files += n_sets;
1026
1027   output_files[last_out_file_ix] = NULL;
1028
1029   for (i = 0; VEC_iterate (bitmap, inlined_decls, i, decls); i++)
1030     lto_bitmap_free (decls);
1031   VEC_free (bitmap, heap, inlined_decls);
1032
1033   timevar_pop (TV_WHOPR_WPA_IO);
1034
1035   return output_files;
1036 }
1037
1038
1039 /* Perform local transformations (LTRANS) on the files in the NULL-terminated
1040    FILES array.  These should have been written previously by
1041    lto_wpa_write_files ().  Transformations are performed via executing
1042    COLLECT_GCC for reach file.  */
1043
1044 static void
1045 lto_execute_ltrans (char *const *files)
1046 {
1047   struct pex_obj *pex;
1048   const char *collect_gcc_options, *collect_gcc;
1049   struct obstack env_obstack;
1050   const char **argv;
1051   const char **argv_ptr;
1052   const char *errmsg;
1053   size_t i, j;
1054   int err;
1055   int status;
1056   FILE *ltrans_output_list_stream = NULL;
1057
1058   timevar_push (TV_WHOPR_WPA_LTRANS_EXEC);
1059
1060   /* Get the driver and options.  */
1061   collect_gcc = getenv ("COLLECT_GCC");
1062   if (!collect_gcc)
1063     fatal_error ("environment variable COLLECT_GCC must be set");
1064
1065   /* Set the CFLAGS environment variable.  */
1066   collect_gcc_options = getenv ("COLLECT_GCC_OPTIONS");
1067   if (!collect_gcc_options)
1068     fatal_error ("environment variable COLLECT_GCC_OPTIONS must be set");
1069
1070   /* Count arguments.  */
1071   i = 0;
1072   for (j = 0; collect_gcc_options[j] != '\0'; ++j)
1073     if (collect_gcc_options[j] == '\'')
1074       ++i;
1075
1076   if (i % 2 != 0)
1077     fatal_error ("malformed COLLECT_GCC_OPTIONS");
1078
1079   /* Initalize the arguments for the LTRANS driver.  */
1080   argv = XNEWVEC (const char *, 8 + i / 2);
1081   argv_ptr = argv;
1082   *argv_ptr++ = collect_gcc;
1083   *argv_ptr++ = "-xlto";
1084   for (j = 0; collect_gcc_options[j] != '\0'; ++j)
1085     if (collect_gcc_options[j] == '\'')
1086       {
1087         char *option;
1088
1089         ++j;
1090         i = j;
1091         while (collect_gcc_options[j] != '\'')
1092           ++j;
1093         obstack_init (&env_obstack);
1094         obstack_grow (&env_obstack, &collect_gcc_options[i], j - i);
1095         obstack_1grow (&env_obstack, 0);
1096         option = XOBFINISH (&env_obstack, char *);
1097
1098         /* LTRANS does not need -fwpa nor -fltrans-*.  */
1099         if (strncmp (option, "-fwpa", 5) != 0
1100             && strncmp (option, "-fltrans-", 9) != 0)
1101           *argv_ptr++ = option;
1102       }
1103   *argv_ptr++ = "-fltrans";
1104
1105   /* Open the LTRANS output list.  */
1106   if (ltrans_output_list)
1107     {
1108       ltrans_output_list_stream = fopen (ltrans_output_list, "w");
1109       if (ltrans_output_list_stream == NULL)
1110         error ("opening LTRANS output list %s: %m", ltrans_output_list);
1111     }
1112
1113   for (i = 0; files[i]; ++i)
1114     {
1115       size_t len;
1116
1117       /* If the file is prefixed with a '*', it means that we do not
1118          need to re-compile it with LTRANS because it has not been
1119          modified by WPA.  Skip it from the command line to
1120          lto_execute_ltrans, but add it to ltrans_output_list_stream
1121          so it is linked after we are done.  */
1122       if (files[i][0] == '*')
1123         {
1124           size_t len = strlen (files[i]) - 1;
1125           if (ltrans_output_list_stream)
1126             if (fwrite (&files[i][1], 1, len, ltrans_output_list_stream) < len
1127                 || fwrite ("\n", 1, 1, ltrans_output_list_stream) < 1)
1128               error ("writing to LTRANS output list %s: %m",
1129                      ltrans_output_list);
1130         }
1131       else
1132         {
1133           char *output_name;
1134
1135           /* Otherwise, add FILES[I] to lto_execute_ltrans command line
1136              and add the resulting file to LTRANS output list.  */
1137
1138           /* Replace the .o suffix with a .ltrans.o suffix and write
1139              the resulting name to the LTRANS output list.  */
1140           obstack_init (&env_obstack);
1141           obstack_grow (&env_obstack, files[i], strlen (files[i]) - 2);
1142           obstack_grow (&env_obstack, ".ltrans.o", sizeof (".ltrans.o"));
1143           output_name = XOBFINISH (&env_obstack, char *);
1144           if (ltrans_output_list_stream)
1145             {
1146               len = strlen (output_name);
1147
1148               if (fwrite (output_name, 1, len, ltrans_output_list_stream) < len
1149                   || fwrite ("\n", 1, 1, ltrans_output_list_stream) < 1)
1150                 error ("writing to LTRANS output list %s: %m",
1151                        ltrans_output_list);
1152             }
1153
1154           argv_ptr[0] = "-o";
1155           argv_ptr[1] = output_name;
1156           argv_ptr[2] = files[i];
1157           argv_ptr[3] = NULL;
1158
1159           /* Execute the driver.  */
1160           pex = pex_init (0, "lto1", NULL);
1161           if (pex == NULL)
1162             fatal_error ("pex_init failed: %s", xstrerror (errno));
1163
1164           errmsg = pex_run (pex, PEX_LAST | PEX_SEARCH, argv[0],
1165                             CONST_CAST (char **, argv), NULL, NULL, &err);
1166           if (errmsg)
1167             fatal_error ("%s: %s", errmsg, xstrerror (err));
1168
1169           if (!pex_get_status (pex, 1, &status))
1170             fatal_error ("can't get program status: %s", xstrerror (errno));
1171
1172           if (status)
1173             {
1174               if (WIFSIGNALED (status))
1175                 {
1176                   int sig = WTERMSIG (status);
1177                   fatal_error ("%s terminated with signal %d [%s]%s",
1178                                argv[0], sig, strsignal (sig),
1179                                WCOREDUMP (status) ? ", core dumped" : "");
1180                 }
1181               else
1182                 fatal_error ("%s terminated with status %d", argv[0], status);
1183             }
1184
1185           pex_free (pex);
1186         }
1187     }
1188
1189   /* Close the LTRANS output list.  */
1190   if (ltrans_output_list_stream && fclose (ltrans_output_list_stream))
1191     error ("closing LTRANS output list %s: %m", ltrans_output_list);
1192
1193   obstack_free (&env_obstack, NULL);
1194   free (argv);
1195
1196   timevar_pop (TV_WHOPR_WPA_LTRANS_EXEC);
1197 }
1198
1199
1200 typedef struct {
1201   struct pointer_set_t *seen;
1202 } lto_fixup_data_t;
1203
1204 #define LTO_FIXUP_SUBTREE(t) \
1205   do \
1206     walk_tree (&(t), lto_fixup_tree, data, NULL); \
1207   while (0)
1208
1209 #define LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE(t) \
1210   do \
1211     { \
1212       if (t) \
1213         (t) = gimple_register_type (t); \
1214       walk_tree (&(t), lto_fixup_tree, data, NULL); \
1215     } \
1216   while (0)
1217
1218 static tree lto_fixup_tree (tree *, int *, void *);
1219
1220 /* Return true if T does not need to be fixed up recursively.  */
1221
1222 static inline bool
1223 no_fixup_p (tree t)
1224 {
1225   return (t == NULL
1226           || CONSTANT_CLASS_P (t)
1227           || TREE_CODE (t) == IDENTIFIER_NODE);
1228 }
1229
1230 /* Fix up fields of a tree_common T.  DATA points to fix-up states.  */
1231
1232 static void
1233 lto_fixup_common (tree t, void *data)
1234 {
1235   /* The following re-creates the TYPE_REFERENCE_TO and TYPE_POINTER_TO
1236      lists.  We do not stream TYPE_REFERENCE_TO, TYPE_POINTER_TO or
1237      TYPE_NEXT_PTR_TO and TYPE_NEXT_REF_TO.
1238      First remove us from any pointer list we are on.  */
1239   if (TREE_CODE (t) == POINTER_TYPE)
1240     {
1241       if (TYPE_POINTER_TO (TREE_TYPE (t)) == t)
1242         TYPE_POINTER_TO (TREE_TYPE (t)) = TYPE_NEXT_PTR_TO (t);
1243       else
1244         {
1245           tree tem = TYPE_POINTER_TO (TREE_TYPE (t));
1246           while (tem && TYPE_NEXT_PTR_TO (tem) != t)
1247             tem = TYPE_NEXT_PTR_TO (tem);
1248           if (tem)
1249             TYPE_NEXT_PTR_TO (tem) = TYPE_NEXT_PTR_TO (t);
1250         }
1251       TYPE_NEXT_PTR_TO (t) = NULL_TREE;
1252     }
1253   else if (TREE_CODE (t) == REFERENCE_TYPE)
1254     {
1255       if (TYPE_REFERENCE_TO (TREE_TYPE (t)) == t)
1256         TYPE_REFERENCE_TO (TREE_TYPE (t)) = TYPE_NEXT_REF_TO (t);
1257       else
1258         {
1259           tree tem = TYPE_REFERENCE_TO (TREE_TYPE (t));
1260           while (tem && TYPE_NEXT_REF_TO (tem) != t)
1261             tem = TYPE_NEXT_REF_TO (tem);
1262           if (tem)
1263             TYPE_NEXT_REF_TO (tem) = TYPE_NEXT_REF_TO (t);
1264         }
1265       TYPE_NEXT_REF_TO (t) = NULL_TREE;
1266     }
1267
1268   /* Fixup our type.  */
1269   LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TREE_TYPE (t));
1270
1271   /* Second put us on the list of pointers of the new pointed-to type
1272      if we are a main variant.  This is done in lto_fixup_type after
1273      fixing up our main variant.  */
1274
1275   /* This is not very efficient because we cannot do tail-recursion with
1276      a long chain of trees. */
1277   LTO_FIXUP_SUBTREE (TREE_CHAIN (t));
1278 }
1279
1280 /* Fix up fields of a decl_minimal T.  DATA points to fix-up states.  */
1281
1282 static void
1283 lto_fixup_decl_minimal (tree t, void *data)
1284 {
1285   lto_fixup_common (t, data);
1286   LTO_FIXUP_SUBTREE (DECL_NAME (t));
1287   LTO_FIXUP_SUBTREE (DECL_CONTEXT (t));
1288 }
1289
1290 /* Fix up fields of a decl_common T.  DATA points to fix-up states.  */
1291
1292 static void
1293 lto_fixup_decl_common (tree t, void *data)
1294 {
1295   lto_fixup_decl_minimal (t, data);
1296   LTO_FIXUP_SUBTREE (DECL_SIZE (t));
1297   LTO_FIXUP_SUBTREE (DECL_SIZE_UNIT (t));
1298   LTO_FIXUP_SUBTREE (DECL_INITIAL (t));
1299   LTO_FIXUP_SUBTREE (DECL_ATTRIBUTES (t));
1300   LTO_FIXUP_SUBTREE (DECL_ABSTRACT_ORIGIN (t));
1301 }
1302
1303 /* Fix up fields of a decl_with_vis T.  DATA points to fix-up states.  */
1304
1305 static void
1306 lto_fixup_decl_with_vis (tree t, void *data)
1307 {
1308   lto_fixup_decl_common (t, data);
1309
1310   /* Accessor macro has side-effects, use field-name here. */
1311   LTO_FIXUP_SUBTREE (t->decl_with_vis.assembler_name);
1312
1313   gcc_assert (no_fixup_p (DECL_SECTION_NAME (t)));
1314 }
1315
1316 /* Fix up fields of a decl_non_common T.  DATA points to fix-up states.  */
1317
1318 static void
1319 lto_fixup_decl_non_common (tree t, void *data)
1320 {
1321   lto_fixup_decl_with_vis (t, data);
1322   LTO_FIXUP_SUBTREE (DECL_ARGUMENT_FLD (t));
1323   LTO_FIXUP_SUBTREE (DECL_RESULT_FLD (t));
1324   LTO_FIXUP_SUBTREE (DECL_VINDEX (t));
1325
1326   /* SAVED_TREE should not cleared by now.  Also no accessor for base type. */
1327   gcc_assert (no_fixup_p (t->decl_non_common.saved_tree));
1328 }
1329
1330 /* Fix up fields of a decl_non_common T.  DATA points to fix-up states.  */
1331
1332 static void
1333 lto_fixup_function (tree t, void *data)
1334 {
1335   lto_fixup_decl_non_common (t, data);
1336   LTO_FIXUP_SUBTREE (DECL_FUNCTION_PERSONALITY (t));
1337 }
1338
1339 /* Fix up fields of a field_decl T.  DATA points to fix-up states.  */
1340
1341 static void
1342 lto_fixup_field_decl (tree t, void *data)
1343 {
1344   lto_fixup_decl_common (t, data);
1345   gcc_assert (no_fixup_p (DECL_FIELD_OFFSET (t)));
1346   LTO_FIXUP_SUBTREE (DECL_BIT_FIELD_TYPE (t));
1347   LTO_FIXUP_SUBTREE (DECL_QUALIFIER (t));
1348   gcc_assert (no_fixup_p (DECL_FIELD_BIT_OFFSET (t)));
1349   LTO_FIXUP_SUBTREE (DECL_FCONTEXT (t));
1350 }
1351
1352 /* Fix up fields of a type T.  DATA points to fix-up states.  */
1353
1354 static void
1355 lto_fixup_type (tree t, void *data)
1356 {
1357   tree tem, mv;
1358
1359   lto_fixup_common (t, data);
1360   LTO_FIXUP_SUBTREE (TYPE_CACHED_VALUES (t));
1361   LTO_FIXUP_SUBTREE (TYPE_SIZE (t));
1362   LTO_FIXUP_SUBTREE (TYPE_SIZE_UNIT (t));
1363   LTO_FIXUP_SUBTREE (TYPE_ATTRIBUTES (t));
1364   LTO_FIXUP_SUBTREE (TYPE_NAME (t));
1365
1366   /* Accessors are for derived node types only. */
1367   if (!POINTER_TYPE_P (t))
1368     LTO_FIXUP_SUBTREE (t->type.minval);
1369   LTO_FIXUP_SUBTREE (t->type.maxval);
1370
1371   /* Accessor is for derived node types only. */
1372   LTO_FIXUP_SUBTREE (t->type.binfo);
1373
1374   LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TYPE_CONTEXT (t));
1375   LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TYPE_CANONICAL (t));
1376
1377   /* The following re-creates proper variant lists while fixing up
1378      the variant leaders.  We do not stream TYPE_NEXT_VARIANT so the
1379      variant list state before fixup is broken.  */
1380
1381   /* Remove us from our main variant list if we are not the variant leader.  */
1382   if (TYPE_MAIN_VARIANT (t) != t)
1383     {
1384       tem = TYPE_MAIN_VARIANT (t);
1385       while (tem && TYPE_NEXT_VARIANT (tem) != t)
1386         tem = TYPE_NEXT_VARIANT (tem);
1387       if (tem)
1388         TYPE_NEXT_VARIANT (tem) = TYPE_NEXT_VARIANT (t);
1389       TYPE_NEXT_VARIANT (t) = NULL_TREE;
1390     }
1391
1392   /* Query our new main variant.  */
1393   mv = gimple_register_type (TYPE_MAIN_VARIANT (t));
1394
1395   /* If we were the variant leader and we get replaced ourselves drop
1396      all variants from our list.  */
1397   if (TYPE_MAIN_VARIANT (t) == t
1398       && mv != t)
1399     {
1400       tem = t;
1401       while (tem)
1402         {
1403           tree tem2 = TYPE_NEXT_VARIANT (tem);
1404           TYPE_NEXT_VARIANT (tem) = NULL_TREE;
1405           tem = tem2;
1406         }
1407     }
1408
1409   /* If we are not our own variant leader link us into our new leaders
1410      variant list.  */
1411   if (mv != t)
1412     {
1413       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
1414       TYPE_NEXT_VARIANT (mv) = t;
1415     }
1416
1417   /* Finally adjust our main variant and fix it up.  */
1418   TYPE_MAIN_VARIANT (t) = mv;
1419   LTO_FIXUP_SUBTREE (TYPE_MAIN_VARIANT (t));
1420
1421   /* As the second step of reconstructing the pointer chains put us
1422      on the list of pointers of the new pointed-to type
1423      if we are a main variant.  See lto_fixup_common for the first step.  */
1424   if (TREE_CODE (t) == POINTER_TYPE
1425       && TYPE_MAIN_VARIANT (t) == t)
1426     {
1427       TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (TREE_TYPE (t));
1428       TYPE_POINTER_TO (TREE_TYPE (t)) = t;
1429     }
1430   else if (TREE_CODE (t) == REFERENCE_TYPE
1431            && TYPE_MAIN_VARIANT (t) == t)
1432     {
1433       TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (TREE_TYPE (t));
1434       TYPE_REFERENCE_TO (TREE_TYPE (t)) = t;
1435     }
1436 }
1437
1438 /* Fix up fields of a BINFO T.  DATA points to fix-up states.  */
1439
1440 static void
1441 lto_fixup_binfo (tree t, void *data)
1442 {
1443   unsigned HOST_WIDE_INT i, n;
1444   tree base, saved_base;
1445
1446   lto_fixup_common (t, data);
1447   gcc_assert (no_fixup_p (BINFO_OFFSET (t)));
1448   LTO_FIXUP_SUBTREE (BINFO_VTABLE (t));
1449   LTO_FIXUP_SUBTREE (BINFO_VIRTUALS (t));
1450   LTO_FIXUP_SUBTREE (BINFO_VPTR_FIELD (t));
1451   n = VEC_length (tree, BINFO_BASE_ACCESSES (t));
1452   for (i = 0; i < n; i++)
1453     {
1454       saved_base = base = BINFO_BASE_ACCESS (t, i);
1455       LTO_FIXUP_SUBTREE (base);
1456       if (base != saved_base)
1457         VEC_replace (tree, BINFO_BASE_ACCESSES (t), i, base);
1458     }
1459   LTO_FIXUP_SUBTREE (BINFO_INHERITANCE_CHAIN (t));
1460   LTO_FIXUP_SUBTREE (BINFO_SUBVTT_INDEX (t));
1461   LTO_FIXUP_SUBTREE (BINFO_VPTR_INDEX (t));
1462   n = BINFO_N_BASE_BINFOS (t);
1463   for (i = 0; i < n; i++)
1464     {
1465       saved_base = base = BINFO_BASE_BINFO (t, i);
1466       LTO_FIXUP_SUBTREE (base);
1467       if (base != saved_base)
1468         VEC_replace (tree, BINFO_BASE_BINFOS (t), i, base);
1469     }
1470 }
1471
1472 /* Fix up fields of a CONSTRUCTOR T.  DATA points to fix-up states.  */
1473
1474 static void
1475 lto_fixup_constructor (tree t, void *data)
1476 {
1477   unsigned HOST_WIDE_INT idx;
1478   constructor_elt *ce;
1479
1480   LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TREE_TYPE (t));
1481
1482   for (idx = 0;
1483        VEC_iterate(constructor_elt, CONSTRUCTOR_ELTS (t), idx, ce);
1484        idx++)
1485     {
1486       LTO_FIXUP_SUBTREE (ce->index);
1487       LTO_FIXUP_SUBTREE (ce->value);
1488     }
1489 }
1490
1491 /* A walk_tree callback used by lto_fixup_state. TP is the pointer to the
1492    current tree. WALK_SUBTREES indicates if the subtrees will be walked.
1493    DATA is a pointer set to record visited nodes. */
1494
1495 static tree
1496 lto_fixup_tree (tree *tp, int *walk_subtrees, void *data)
1497 {
1498   tree t;
1499   lto_fixup_data_t *fixup_data = (lto_fixup_data_t *) data;
1500   tree prevailing;
1501
1502   t = *tp;
1503   *walk_subtrees = 0;
1504   if (pointer_set_contains (fixup_data->seen, t))
1505     return NULL;
1506
1507   if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == FUNCTION_DECL)
1508     {
1509       prevailing = lto_symtab_prevailing_decl (t);
1510
1511       if (t != prevailing)
1512         {
1513           if (TREE_CODE (t) == FUNCTION_DECL
1514               && TREE_NOTHROW (prevailing) != TREE_NOTHROW (t))
1515             {
1516               /* If the prevailing definition does not throw but the
1517                  declaration (T) was considered throwing, then we
1518                  simply add PREVAILING to the list of throwing
1519                  functions.  However, if the opposite is true, then
1520                  the call to PREVAILING was generated assuming that
1521                  the function didn't throw, which means that CFG
1522                  cleanup may have removed surrounding try/catch
1523                  regions.
1524
1525                  Note that we currently accept these cases even when
1526                  they occur within a single file.  It's certainly a
1527                  user error, but we silently allow the compiler to
1528                  remove surrounding try/catch regions.  Perhaps we
1529                  could emit a warning here, instead of silently
1530                  accepting the conflicting declaration.  */
1531               if (TREE_NOTHROW (prevailing))
1532                 lto_mark_nothrow_fndecl (prevailing);
1533             }
1534
1535            /* Also replace t with prevailing defintion.  We don't want to
1536               insert the other defintion in the seen set as we want to
1537               replace all instances of it.  */
1538           *tp = prevailing;
1539           t = prevailing;
1540         }
1541     }
1542   else if (TYPE_P (t))
1543     {
1544       /* Replace t with the prevailing type.  We don't want to insert the
1545          other type in the seen set as we want to replace all instances of it.  */
1546       t = gimple_register_type (t);
1547       *tp = t;
1548     }
1549
1550   if (pointer_set_insert (fixup_data->seen, t))
1551     return NULL;
1552
1553   /* walk_tree does not visit all reachable nodes that need to be fixed up.
1554      Hence we do special processing here for those kind of nodes. */
1555   switch (TREE_CODE (t))
1556     {
1557     case FIELD_DECL:
1558       lto_fixup_field_decl (t, data);
1559       break;
1560
1561     case LABEL_DECL:
1562     case CONST_DECL:
1563     case PARM_DECL:
1564     case RESULT_DECL:
1565     case IMPORTED_DECL:
1566       lto_fixup_decl_common (t, data);
1567       break;
1568
1569     case VAR_DECL:
1570       lto_fixup_decl_with_vis (t, data);
1571       break;    
1572
1573     case TYPE_DECL:
1574       lto_fixup_decl_non_common (t, data);
1575       break;
1576
1577     case FUNCTION_DECL:
1578       lto_fixup_function (t, data);
1579       break;
1580
1581     case TREE_BINFO:
1582       lto_fixup_binfo (t, data);
1583       break;
1584
1585     default:
1586       if (TYPE_P (t))
1587         lto_fixup_type (t, data);
1588       else if (TREE_CODE (t) == CONSTRUCTOR)
1589         lto_fixup_constructor (t, data);
1590       else if (CONSTANT_CLASS_P (t))
1591         LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TREE_TYPE (t));
1592       else if (EXPR_P (t))
1593         {
1594           /* walk_tree only handles TREE_OPERANDs. Do the rest here.  */
1595           lto_fixup_common (t, data);
1596           LTO_FIXUP_SUBTREE (t->exp.block);
1597           *walk_subtrees = 1;
1598         }
1599       else
1600         {
1601           /* Let walk_tree handle sub-trees.  */
1602           *walk_subtrees = 1;
1603         }
1604     }
1605
1606   return NULL;
1607 }
1608
1609 /* Helper function of lto_fixup_decls. Walks the var and fn streams in STATE,
1610    replaces var and function decls with the corresponding prevailing def and
1611    records the old decl in the free-list in DATA. We also record visted nodes
1612    in the seen-set in DATA to avoid multiple visit for nodes that need not
1613    to be replaced.  */
1614
1615 static void
1616 lto_fixup_state (struct lto_in_decl_state *state, lto_fixup_data_t *data)
1617 {
1618   unsigned i, si;
1619   struct lto_tree_ref_table *table;
1620
1621   /* Although we only want to replace FUNCTION_DECLs and VAR_DECLs,
1622      we still need to walk from all DECLs to find the reachable
1623      FUNCTION_DECLs and VAR_DECLs.  */
1624   for (si = 0; si < LTO_N_DECL_STREAMS; si++)
1625     {
1626       table = &state->streams[si];
1627       for (i = 0; i < table->size; i++)
1628         walk_tree (table->trees + i, lto_fixup_tree, data, NULL);
1629     }
1630 }
1631
1632 /* A callback of htab_traverse. Just extract a state from SLOT and the
1633    lto_fixup_data_t object from AUX and calls lto_fixup_state. */
1634
1635 static int
1636 lto_fixup_state_aux (void **slot, void *aux)
1637 {
1638   struct lto_in_decl_state *state = (struct lto_in_decl_state *) *slot;
1639   lto_fixup_state (state, (lto_fixup_data_t *) aux);
1640   return 1;
1641 }
1642
1643 /* Fix the decls from all FILES. Replaces each decl with the corresponding
1644    prevailing one.  */
1645
1646 static void
1647 lto_fixup_decls (struct lto_file_decl_data **files)
1648 {
1649   unsigned int i;
1650   tree decl;
1651   struct pointer_set_t *seen = pointer_set_create ();
1652   lto_fixup_data_t data;
1653
1654   data.seen = seen;
1655   for (i = 0; files[i]; i++)
1656     {
1657       struct lto_file_decl_data *file = files[i];
1658       struct lto_in_decl_state *state = file->global_decl_state;
1659       lto_fixup_state (state, &data);
1660
1661       htab_traverse (file->function_decl_states, lto_fixup_state_aux, &data);
1662     }
1663
1664   for (i = 0; VEC_iterate (tree, lto_global_var_decls, i, decl); i++)
1665     {
1666       tree saved_decl = decl;
1667       walk_tree (&decl, lto_fixup_tree, &data, NULL);
1668       if (decl != saved_decl)
1669         VEC_replace (tree, lto_global_var_decls, i, decl);
1670     }
1671
1672   pointer_set_destroy (seen);
1673 }
1674
1675 /* Unlink a temporary LTRANS file unless requested otherwise.  */
1676
1677 static void
1678 lto_maybe_unlink (const char *file)
1679 {
1680   if (!getenv ("WPA_SAVE_LTRANS"))
1681     {
1682       if (unlink_if_ordinary (file))
1683         error ("deleting LTRANS input file %s: %m", file);
1684     }
1685   else
1686     fprintf (stderr, "[Leaving LTRANS input file %s]\n", file);
1687 }
1688
1689 /* Read the options saved from each file in the command line.  Called
1690    from lang_hooks.post_options which is called by process_options
1691    right before all the options are used to initialize the compiler.
1692    This assumes that decode_options has already run, so the
1693    num_in_fnames and in_fnames are properly set.
1694
1695    Note that this assumes that all the files had been compiled with
1696    the same options, which is not a good assumption.  In general,
1697    options ought to be read from all the files in the set and merged.
1698    However, it is still unclear what the merge rules should be.  */
1699
1700 void
1701 lto_read_all_file_options (void)
1702 {
1703   size_t i;
1704
1705   /* Clear any file options currently saved.  */
1706   lto_clear_file_options ();
1707
1708   /* Set the hooks to read ELF sections.  */
1709   lto_set_in_hooks (NULL, get_section_data, free_section_data);
1710
1711   for (i = 0; i < num_in_fnames; i++)
1712     {
1713       struct lto_file_decl_data *file_data;
1714       lto_file *file = lto_elf_file_open (in_fnames[i], false);
1715       if (!file)
1716         break;
1717
1718       file_data = XCNEW (struct lto_file_decl_data);
1719       file_data->file_name = file->filename;
1720       file_data->section_hash_table = lto_elf_build_section_table (file);
1721
1722       lto_read_file_options (file_data);
1723
1724       lto_elf_file_close (file);
1725       htab_delete (file_data->section_hash_table);
1726       free (file_data);
1727     }
1728
1729   /* Apply globally the options read from all the files.  */
1730   lto_reissue_options ();
1731 }
1732
1733
1734 /* Read all the symbols from the input files FNAMES.  NFILES is the
1735    number of files requested in the command line.  Instantiate a
1736    global call graph by aggregating all the sub-graphs found in each
1737    file.  */
1738
1739 static void
1740 read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
1741 {
1742   unsigned int i, last_file_ix;
1743   struct lto_file_decl_data **all_file_decl_data;
1744   FILE *resolution;
1745   struct cgraph_node *node;
1746
1747   lto_stats.num_input_files = nfiles;
1748
1749   timevar_push (TV_IPA_LTO_DECL_IO);
1750
1751   /* Set the hooks so that all of the ipa passes can read in their data.  */
1752   all_file_decl_data = XNEWVEC (struct lto_file_decl_data *, nfiles + 1);
1753   lto_set_in_hooks (all_file_decl_data, get_section_data, free_section_data);
1754
1755   /* Read the resolution file.  */
1756   resolution = NULL;
1757   if (resolution_file_name)
1758     {
1759       int t;
1760       unsigned num_objects;
1761
1762       resolution = fopen (resolution_file_name, "r");
1763       if (resolution == NULL)
1764         fatal_error ("could not open symbol resolution file: %s",
1765                      xstrerror (errno));
1766
1767       t = fscanf (resolution, "%u", &num_objects);
1768       gcc_assert (t == 1);
1769
1770       /* True, since the plugin splits the archives.  */
1771       gcc_assert (num_objects == nfiles);
1772     }
1773
1774   /* Read all of the object files specified on the command line.  */
1775   for (i = 0, last_file_ix = 0; i < nfiles; ++i)
1776     {
1777       struct lto_file_decl_data *file_data = NULL;
1778
1779       current_lto_file = lto_elf_file_open (fnames[i], false);
1780       if (!current_lto_file)
1781         break;
1782
1783       file_data = lto_file_read (current_lto_file, resolution);
1784       if (!file_data)
1785         break;
1786
1787       all_file_decl_data[last_file_ix++] = file_data;
1788
1789       lto_elf_file_close (current_lto_file);
1790       current_lto_file = NULL;
1791     }
1792
1793   if (resolution_file_name)
1794     fclose (resolution);
1795
1796   all_file_decl_data[last_file_ix] = NULL;
1797
1798   /* Set the hooks so that all of the ipa passes can read in their data.  */
1799   lto_set_in_hooks (all_file_decl_data, get_section_data, free_section_data);
1800
1801   /* Each pass will set the appropriate timer.  */
1802   timevar_pop (TV_IPA_LTO_DECL_IO);
1803
1804   /* Read the callgraph.  */
1805   input_cgraph ();
1806
1807   /* Merge global decls.  */
1808   lto_symtab_merge_decls ();
1809
1810   /* Fixup all decls and types and free the type hash tables.  */
1811   lto_fixup_decls (all_file_decl_data);
1812   free_gimple_type_tables ();
1813
1814   /* Read the IPA summary data.  */
1815   ipa_read_summaries ();
1816
1817   /* Finally merge the cgraph according to the decl merging decisions.  */
1818   lto_symtab_merge_cgraph_nodes ();
1819
1820   /* Mark cgraph nodes needed in the merged cgraph
1821      This normally happens in whole-program pass, but for
1822      ltrans the pass was already run at WPA phase.
1823      
1824      FIXME:  This is not valid way to do so; nodes can be needed
1825      for non-obvious reasons.  We should stream the flags from WPA
1826      phase. */
1827   if (flag_ltrans)
1828     for (node = cgraph_nodes; node; node = node->next)
1829       {
1830         if (!node->global.inlined_to
1831             && cgraph_decide_is_function_needed (node, node->decl))
1832           cgraph_mark_needed_node (node);
1833         /* FIXME: ipa_transforms_to_apply holds list of passes that have optimization
1834            summaries computed and needs to apply changes.  At the moment WHOPR only
1835            supports inlining, so we can push it here by hand.  In future we need to stream
1836            this field into ltrans compilation.  */
1837         if (node->analyzed)
1838           VEC_safe_push (ipa_opt_pass, heap,
1839                          node->ipa_transforms_to_apply,
1840                          (ipa_opt_pass)&pass_ipa_inline);
1841       }
1842
1843   timevar_push (TV_IPA_LTO_DECL_IO);
1844
1845   /* FIXME lto. This loop needs to be changed to use the pass manager to
1846      call the ipa passes directly.  */
1847   if (!errorcount)
1848     for (i = 0; i < last_file_ix; i++)
1849       {
1850         struct lto_file_decl_data *file_data = all_file_decl_data [i];
1851         lto_materialize_constructors_and_inits (file_data);
1852       }
1853
1854   /* Indicate that the cgraph is built and ready.  */
1855   cgraph_function_flags_ready = true;
1856
1857   timevar_pop (TV_IPA_LTO_DECL_IO);
1858 }
1859
1860
1861 /* Materialize all the bodies for all the nodes in the callgraph.  */
1862
1863 static void
1864 materialize_cgraph (void)
1865 {
1866   tree decl;
1867   struct cgraph_node *node; 
1868   unsigned i;
1869   timevar_id_t lto_timer;
1870
1871   /* Now that we have input the cgraph, we need to clear all of the aux
1872      nodes and read the functions if we are not running in WPA mode.  */
1873   timevar_push (TV_IPA_LTO_GIMPLE_IO);
1874
1875   for (node = cgraph_nodes; node; node = node->next)
1876     {
1877       /* Some cgraph nodes get created on the fly, and they don't need
1878          to be materialized.  For instance, nodes for nested functions
1879          where the parent function was not streamed out or builtin
1880          functions.  Additionally, builtin functions should not be
1881          materialized and may, in fact, cause confusion because there
1882          may be a regular function in the file whose assembler name
1883          matches that of the function.
1884          See gcc.c-torture/execute/20030125-1.c and
1885          gcc.c-torture/execute/921215-1.c.  */
1886       if (node->local.lto_file_data
1887           && !DECL_IS_BUILTIN (node->decl))
1888         {
1889           lto_materialize_function (node);
1890           lto_stats.num_input_cgraph_nodes++;
1891         }
1892     }
1893
1894   timevar_pop (TV_IPA_LTO_GIMPLE_IO);
1895
1896   /* Start the appropriate timer depending on the mode that we are
1897      operating in.  */
1898   lto_timer = (flag_wpa) ? TV_WHOPR_WPA
1899               : (flag_ltrans) ? TV_WHOPR_LTRANS
1900               : TV_LTO;
1901   timevar_push (lto_timer);
1902
1903   current_function_decl = NULL;
1904   set_cfun (NULL);
1905
1906   /* Inform the middle end about the global variables we have seen.  */
1907   for (i = 0; VEC_iterate (tree, lto_global_var_decls, i, decl); i++)
1908     rest_of_decl_compilation (decl, 1, 0);
1909
1910   /* Fix up any calls to DECLs that have become not exception throwing.  */
1911   lto_fixup_nothrow_decls ();
1912
1913   timevar_pop (lto_timer);
1914 }
1915
1916
1917 /* Perform whole program analysis (WPA) on the callgraph and write out the
1918    optimization plan.  */
1919
1920 static void
1921 do_whole_program_analysis (void)
1922 {
1923   char **output_files;
1924   size_t i;
1925   struct cgraph_node *node; 
1926
1927   lto_1_to_1_map ();
1928
1929   /* Note that since we are in WPA mode, materialize_cgraph will not
1930      actually read in all the function bodies.  It only materializes
1931      the decls and cgraph nodes so that analysis can be performed.  */
1932   materialize_cgraph ();
1933
1934   /* Reading in the cgraph uses different timers, start timing WPA now.  */
1935   timevar_push (TV_WHOPR_WPA);
1936
1937   /* FIXME lto. Hack. We should use the IPA passes.  There are a
1938      number of issues with this now. 1. There is no convenient way to
1939      do this. 2. Some passes may depend on properties that requires
1940      the function bodies to compute.  */
1941   cgraph_function_flags_ready = true;
1942   bitmap_obstack_initialize (NULL);
1943   ipa_register_cgraph_hooks ();
1944
1945   /* Reset inlining information before running IPA inliner.  */
1946   for (node = cgraph_nodes; node; node = node->next)
1947     reset_inline_failed (node);
1948
1949   /* FIXME lto.  We should not call this function directly. */
1950   pass_ipa_inline.pass.execute ();
1951
1952   verify_cgraph ();
1953   bitmap_obstack_release (NULL);
1954
1955   /* We are about to launch the final LTRANS phase, stop the WPA timer.  */
1956   timevar_pop (TV_WHOPR_WPA);
1957
1958   output_files = lto_wpa_write_files ();
1959
1960   /* Show the LTO report before launching LTRANS.  */
1961   if (flag_lto_report)
1962     print_lto_report ();
1963
1964   lto_execute_ltrans (output_files);
1965
1966   for (i = 0; output_files[i]; ++i)
1967     {
1968       if (output_files[i][0] != '*')
1969         lto_maybe_unlink (output_files[i]);
1970
1971       free (output_files[i]);
1972     }
1973
1974   XDELETEVEC (output_files);
1975 }
1976
1977
1978 /* Main entry point for the GIMPLE front end.  This front end has
1979    three main personalities:
1980
1981    - LTO (-flto).  All the object files on the command line are
1982      loaded in memory and processed as a single translation unit.
1983      This is the traditional link-time optimization behavior.
1984
1985    - WPA (-fwpa).  Only the callgraph and summary information for
1986      files in the command file are loaded.  A single callgraph
1987      (without function bodies) is instantiated for the whole set of
1988      files.  IPA passes are only allowed to analyze the call graph
1989      and make transformation decisions.  The callgraph is
1990      partitioned, each partition is written to a new object file
1991      together with the transformation decisions.
1992
1993    - LTRANS (-fltrans).  Similar to -flto but it prevents the IPA
1994      summary files from running again.  Since WPA computed summary
1995      information and decided what transformations to apply, LTRANS
1996      simply applies them.  */
1997
1998 void
1999 lto_main (int debug_p ATTRIBUTE_UNUSED)
2000 {
2001   lto_init_reader ();
2002
2003   /* Read all the symbols and call graph from all the files in the
2004      command line.  */
2005   read_cgraph_and_symbols (num_in_fnames, in_fnames);
2006
2007   if (!errorcount)
2008     {
2009       /* If WPA is enabled analyze the whole call graph and create an
2010          optimization plan.  Otherwise, read in all the function
2011          bodies and continue with optimization.  */
2012       if (flag_wpa)
2013         do_whole_program_analysis ();
2014       else
2015         {
2016           materialize_cgraph ();
2017
2018           /* Let the middle end know that we have read and merged all of
2019              the input files.  */ 
2020           cgraph_optimize ();
2021
2022           /* FIXME lto, if the processes spawned by WPA fail, we miss
2023              the chance to print WPA's report, so WPA will call
2024              print_lto_report before launching LTRANS.  If LTRANS was
2025              launched directly by the driver we would not need to do
2026              this.  */
2027           if (flag_lto_report)
2028             print_lto_report ();
2029         }
2030     }
2031 }
2032
2033 #include "gt-lto-lto.h"