1 /* Top-level LTO routines.
2 Copyright 2009, 2010 Free Software Foundation, Inc.
3 Contributed by CodeSourcery, Inc.
5 This file is part of GCC.
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
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
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/>. */
23 #include "coretypes.h"
27 #include "diagnostic-core.h"
31 #include "tree-ssa-operands.h"
32 #include "tree-pass.h"
33 #include "langhooks.h"
36 #include "pointer-set.h"
44 #include "lto-streamer.h"
45 #include "splay-tree.h"
48 static GTY(()) tree first_personality_decl;
50 /* Returns a hash code for P. */
53 hash_name (const void *p)
55 const struct lto_section_slot *ds = (const struct lto_section_slot *) p;
56 return (hashval_t) htab_hash_string (ds->name);
60 /* Returns nonzero if P1 and P2 are equal. */
63 eq_name (const void *p1, const void *p2)
65 const struct lto_section_slot *s1 =
66 (const struct lto_section_slot *) p1;
67 const struct lto_section_slot *s2 =
68 (const struct lto_section_slot *) p2;
70 return strcmp (s1->name, s2->name) == 0;
73 /* Free lto_section_slot */
76 free_with_string (void *arg)
78 struct lto_section_slot *s = (struct lto_section_slot *)arg;
80 free (CONST_CAST (char *, s->name));
84 /* Create section hash table */
87 lto_obj_create_section_hash_table (void)
89 return htab_create (37, hash_name, eq_name, free_with_string);
92 /* Read the constructors and inits. */
95 lto_materialize_constructors_and_inits (struct lto_file_decl_data * file_data)
98 const char *data = lto_get_section_data (file_data,
99 LTO_section_static_initializer,
101 lto_input_constructors_and_inits (file_data, data);
102 lto_free_section_data (file_data, LTO_section_static_initializer, NULL,
106 /* Return true when NODE has a clone that is analyzed (i.e. we need
107 to load its body even if the node itself is not needed). */
110 has_analyzed_clone_p (struct cgraph_node *node)
112 struct cgraph_node *orig = node;
121 else if (node->next_sibling_clone)
122 node = node->next_sibling_clone;
125 while (node != orig && !node->next_sibling_clone)
126 node = node->clone_of;
128 node = node->next_sibling_clone;
134 /* Read the function body for the function associated with NODE. */
137 lto_materialize_function (struct cgraph_node *node)
140 struct lto_file_decl_data *file_data;
141 const char *data, *name;
145 /* Read in functions with body (analyzed nodes)
146 and also functions that are needed to produce virtual clones. */
147 if (node->analyzed || has_analyzed_clone_p (node))
149 /* Clones don't need to be read. */
152 file_data = node->local.lto_file_data;
153 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
155 /* We may have renamed the declaration, e.g., a static function. */
156 name = lto_get_decl_name_mapping (file_data, name);
158 data = lto_get_section_data (file_data, LTO_section_function_body,
161 fatal_error ("%s: section %s is missing",
162 file_data->file_name,
165 gcc_assert (DECL_STRUCT_FUNCTION (decl) == NULL);
167 /* Load the function body only if not operating in WPA mode. In
168 WPA mode, the body of the function is not needed. */
171 allocate_struct_function (decl, false);
172 announce_function (decl);
173 lto_input_function_body (file_data, decl, data);
174 if (DECL_FUNCTION_PERSONALITY (decl) && !first_personality_decl)
175 first_personality_decl = DECL_FUNCTION_PERSONALITY (decl);
176 lto_stats.num_function_bodies++;
179 lto_free_section_data (file_data, LTO_section_function_body, name,
185 /* Let the middle end know about the function. */
186 rest_of_decl_compilation (decl, 1, 0);
190 /* Decode the content of memory pointed to by DATA in the the
191 in decl state object STATE. DATA_IN points to a data_in structure for
192 decoding. Return the address after the decoded object in the input. */
194 static const uint32_t *
195 lto_read_in_decl_state (struct data_in *data_in, const uint32_t *data,
196 struct lto_in_decl_state *state)
203 decl = lto_streamer_cache_get (data_in->reader_cache, (int) ix);
204 if (TREE_CODE (decl) != FUNCTION_DECL)
206 gcc_assert (decl == void_type_node);
209 state->fn_decl = decl;
211 for (i = 0; i < LTO_N_DECL_STREAMS; i++)
213 uint32_t size = *data++;
214 tree *decls = ggc_alloc_vec_tree (size);
216 for (j = 0; j < size; j++)
218 decls[j] = lto_streamer_cache_get (data_in->reader_cache, data[j]);
220 /* Register every type in the global type table. If the
221 type existed already, use the existing type. */
222 if (TYPE_P (decls[j]))
223 decls[j] = gimple_register_type (decls[j]);
226 state->streams[i].size = size;
227 state->streams[i].trees = decls;
235 /* Read all the symbols from buffer DATA, using descriptors in DECL_DATA.
236 RESOLUTIONS is the set of symbols picked by the linker (read from the
237 resolution file when the linker plugin is being used). */
240 lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
241 VEC(ld_plugin_symbol_resolution_t,heap) *resolutions)
243 const struct lto_decl_header *header = (const struct lto_decl_header *) data;
244 const int32_t decl_offset = sizeof (struct lto_decl_header);
245 const int32_t main_offset = decl_offset + header->decl_state_size;
246 const int32_t string_offset = main_offset + header->main_size;
247 struct lto_input_block ib_main;
248 struct data_in *data_in;
250 const uint32_t *data_ptr, *data_end;
251 uint32_t num_decl_states;
253 LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0,
256 data_in = lto_data_in_create (decl_data, (const char *) data + string_offset,
257 header->string_size, resolutions);
259 /* Read the global declarations and types. */
260 while (ib_main.p < ib_main.len)
262 tree t = lto_input_tree (&ib_main, data_in);
263 gcc_assert (t && ib_main.p <= ib_main.len);
266 /* Read in lto_in_decl_state objects. */
267 data_ptr = (const uint32_t *) ((const char*) data + decl_offset);
269 (const uint32_t *) ((const char*) data_ptr + header->decl_state_size);
270 num_decl_states = *data_ptr++;
272 gcc_assert (num_decl_states > 0);
273 decl_data->global_decl_state = lto_new_in_decl_state ();
274 data_ptr = lto_read_in_decl_state (data_in, data_ptr,
275 decl_data->global_decl_state);
277 /* Read in per-function decl states and enter them in hash table. */
278 decl_data->function_decl_states =
279 htab_create_ggc (37, lto_hash_in_decl_state, lto_eq_in_decl_state, NULL);
281 for (i = 1; i < num_decl_states; i++)
283 struct lto_in_decl_state *state = lto_new_in_decl_state ();
286 data_ptr = lto_read_in_decl_state (data_in, data_ptr, state);
287 slot = htab_find_slot (decl_data->function_decl_states, state, INSERT);
288 gcc_assert (*slot == NULL);
292 if (data_ptr != data_end)
293 internal_error ("bytecode stream: garbage at the end of symbols section");
295 /* Set the current decl state to be the global state. */
296 decl_data->current_decl_state = decl_data->global_decl_state;
298 lto_data_in_delete (data_in);
301 /* strtoll is not portable. */
303 lto_parse_hex (const char *p) {
305 for (; *p != '\0'; ++p)
310 if (c >= '0' && c <= '9')
312 else if (c >= 'a' && c <= 'f')
314 else if (c >= 'A' && c <= 'F')
317 internal_error ("could not parse hex number");
323 /* Read resolution for file named FILE_NAME. The resolution is read from
327 lto_resolution_read (splay_tree file_ids, FILE *resolution, lto_file *file)
329 /* We require that objects in the resolution file are in the same
330 order as the lto1 command line. */
331 unsigned int name_len;
333 unsigned int num_symbols;
335 struct lto_file_decl_data *file_data;
336 unsigned max_index = 0;
337 splay_tree_node nd = NULL;
342 name_len = strlen (file->filename);
343 obj_name = XNEWVEC (char, name_len + 1);
344 fscanf (resolution, " "); /* Read white space. */
346 fread (obj_name, sizeof (char), name_len, resolution);
347 obj_name[name_len] = '\0';
348 if (strcmp (obj_name, file->filename) != 0)
349 internal_error ("unexpected file name %s in linker resolution file. "
350 "Expected %s", obj_name, file->filename);
351 if (file->offset != 0)
356 t = fscanf (resolution, "@0x%16s", offset_p);
358 internal_error ("could not parse file offset");
359 offset = lto_parse_hex (offset_p);
360 if (offset != file->offset)
361 internal_error ("unexpected offset");
366 fscanf (resolution, "%u", &num_symbols);
368 for (i = 0; i < num_symbols; i++)
373 enum ld_plugin_symbol_resolution r = (enum ld_plugin_symbol_resolution) 0;
375 unsigned int lto_resolution_str_len =
376 sizeof (lto_resolution_str) / sizeof (char *);
378 t = fscanf (resolution, "%u %x %26s %*[^\n]\n", &index, &id, r_str);
380 internal_error ("invalid line in the resolution file");
381 if (index > max_index)
384 for (j = 0; j < lto_resolution_str_len; j++)
386 if (strcmp (lto_resolution_str[j], r_str) == 0)
388 r = (enum ld_plugin_symbol_resolution) j;
392 if (j == lto_resolution_str_len)
393 internal_error ("invalid resolution in the resolution file");
395 if (!(nd && nd->key == id))
397 nd = splay_tree_lookup (file_ids, id);
399 internal_error ("resolution sub id %x not in object file", id);
402 file_data = (struct lto_file_decl_data *)nd->value;
403 if (cgraph_dump_file)
404 fprintf (cgraph_dump_file, "Adding resolution %u %u to id %x\n",
405 index, r, file_data->id);
406 VEC_safe_grow_cleared (ld_plugin_symbol_resolution_t, heap,
407 file_data->resolutions,
409 VEC_replace (ld_plugin_symbol_resolution_t,
410 file_data->resolutions, index, r);
414 /* Is the name for a id'ed LTO section? */
417 lto_section_with_id (const char *name, unsigned *id)
421 if (strncmp (name, LTO_SECTION_NAME_PREFIX, strlen (LTO_SECTION_NAME_PREFIX)))
423 s = strrchr (name, '.');
424 return s && sscanf (s, ".%x", id) == 1;
427 /* Create file_data of each sub file id */
430 create_subid_section_table (void **slot, void *data)
432 struct lto_section_slot s_slot, *new_slot;
433 struct lto_section_slot *ls = *(struct lto_section_slot **)slot;
434 splay_tree file_ids = (splay_tree)data;
439 struct lto_file_decl_data *file_data;
441 if (!lto_section_with_id (ls->name, &id))
444 /* Find hash table of sub module id */
445 nd = splay_tree_lookup (file_ids, id);
448 file_data = (struct lto_file_decl_data *)nd->value;
452 file_data = ggc_alloc_lto_file_decl_data ();
453 memset(file_data, 0, sizeof (struct lto_file_decl_data));
455 file_data->section_hash_table = lto_obj_create_section_hash_table ();;
456 splay_tree_insert (file_ids, id, (splay_tree_value)file_data);
459 /* Copy section into sub module hash table */
460 new_name = XDUPVEC (char, ls->name, strlen (ls->name) + 1);
461 s_slot.name = new_name;
462 hash_slot = htab_find_slot (file_data->section_hash_table, &s_slot, INSERT);
463 gcc_assert (*hash_slot == NULL);
465 new_slot = XDUP (struct lto_section_slot, ls);
466 new_slot->name = new_name;
467 *hash_slot = new_slot;
471 /* Read declarations and other initializations for a FILE_DATA. */
474 lto_file_finalize (struct lto_file_decl_data *file_data, lto_file *file)
479 file_data->renaming_hash_table = lto_create_renaming_table ();
480 file_data->file_name = file->filename;
481 data = lto_get_section_data (file_data, LTO_section_decls, NULL, &len);
484 internal_error ("cannot read LTO decls from %s", file_data->file_name);
487 lto_read_decls (file_data, data, file_data->resolutions);
488 lto_free_section_data (file_data, LTO_section_decls, NULL, data, len);
494 struct lto_file_decl_data **file_data;
498 /* Traverse ids and create a list of file_datas out of it. */
500 static int lto_create_files_from_ids (splay_tree_node node, void *data)
502 struct lwstate *lw = (struct lwstate *)data;
503 struct lto_file_decl_data *file_data = (struct lto_file_decl_data *)node->value;
505 lto_file_finalize (file_data, lw->file);
506 if (cgraph_dump_file)
507 fprintf (cgraph_dump_file, "Creating file %s with sub id %x\n",
508 file_data->file_name, file_data->id);
509 file_data->next = *lw->file_data;
510 *lw->file_data = file_data;
515 /* Generate a TREE representation for all types and external decls
518 Read all of the globals out of the file. Then read the cgraph
519 and process the .o index into the cgraph nodes so that it can open
520 the .o file to load the functions and ipa information. */
522 static struct lto_file_decl_data *
523 lto_file_read (lto_file *file, FILE *resolution_file, int *count)
525 struct lto_file_decl_data *file_data = NULL;
527 htab_t section_hash_table;
528 struct lwstate state;
530 section_hash_table = lto_obj_build_section_table (file);
532 /* Find all sub modules in the object and put their sections into new hash
533 tables in a splay tree. */
534 file_ids = splay_tree_new (splay_tree_compare_ints, NULL, NULL);
535 htab_traverse (section_hash_table, create_subid_section_table, file_ids);
537 /* Add resolutions to file ids */
538 lto_resolution_read (file_ids, resolution_file, file);
540 /* Finalize each lto file for each submodule in the merged object
541 and create list for returning. */
543 state.file_data = &file_data;
545 splay_tree_foreach (file_ids, lto_create_files_from_ids, &state);
547 splay_tree_delete (file_ids);
548 htab_delete (section_hash_table);
553 #if HAVE_MMAP_FILE && HAVE_SYSCONF && defined _SC_PAGE_SIZE
554 #define LTO_MMAP_IO 1
558 /* Page size of machine is used for mmap and munmap calls. */
559 static size_t page_mask;
562 /* Get the section data of length LEN from FILENAME starting at
563 OFFSET. The data segment must be freed by the caller when the
564 caller is finished. Returns NULL if all was not well. */
567 lto_read_section_data (struct lto_file_decl_data *file_data,
568 intptr_t offset, size_t len)
572 static char *fd_name;
574 intptr_t computed_len;
575 intptr_t computed_offset;
579 /* Keep a single-entry file-descriptor cache. The last file we
580 touched will get closed at exit.
581 ??? Eventually we want to add a more sophisticated larger cache
582 or rather fix function body streaming to not stream them in
583 practically random order. */
585 && strcmp (fd_name, file_data->file_name) != 0)
593 fd = open (file_data->file_name, O_RDONLY|O_BINARY);
596 fd_name = xstrdup (file_data->file_name);
602 size_t page_size = sysconf (_SC_PAGE_SIZE);
603 page_mask = ~(page_size - 1);
606 computed_offset = offset & page_mask;
607 diff = offset - computed_offset;
608 computed_len = len + diff;
610 result = (char *) mmap (NULL, computed_len, PROT_READ, MAP_PRIVATE,
611 fd, computed_offset);
612 if (result == MAP_FAILED)
615 return result + diff;
617 result = (char *) xmalloc (len);
618 if (lseek (fd, offset, SEEK_SET) != offset
619 || read (fd, result, len) != (ssize_t) len)
625 /* Native windows doesn't supports delayed unlink on opened file. So
626 we close file here again. This produces higher I/O load, but at least
627 it prevents to have dangling file handles preventing unlink. */
638 /* Get the section data from FILE_DATA of SECTION_TYPE with NAME.
639 NAME will be NULL unless the section type is for a function
643 get_section_data (struct lto_file_decl_data *file_data,
644 enum lto_section_type section_type,
648 htab_t section_hash_table = file_data->section_hash_table;
649 struct lto_section_slot *f_slot;
650 struct lto_section_slot s_slot;
651 const char *section_name = lto_get_section_name (section_type, name, file_data);
655 s_slot.name = section_name;
656 f_slot = (struct lto_section_slot *) htab_find (section_hash_table, &s_slot);
659 data = lto_read_section_data (file_data, f_slot->start, f_slot->len);
663 free (CONST_CAST (char *, section_name));
668 /* Free the section data from FILE_DATA of SECTION_TYPE with NAME that
669 starts at OFFSET and has LEN bytes. */
672 free_section_data (struct lto_file_decl_data *file_data ATTRIBUTE_UNUSED,
673 enum lto_section_type section_type ATTRIBUTE_UNUSED,
674 const char *name ATTRIBUTE_UNUSED,
675 const char *offset, size_t len ATTRIBUTE_UNUSED)
678 intptr_t computed_len;
679 intptr_t computed_offset;
684 computed_offset = ((intptr_t) offset) & page_mask;
685 diff = (intptr_t) offset - computed_offset;
686 computed_len = len + diff;
688 munmap ((caddr_t) computed_offset, computed_len);
690 free (CONST_CAST(char *, offset));
694 /* Structure describing ltrans partitions. */
696 struct GTY (()) ltrans_partition_def
698 cgraph_node_set cgraph_set;
699 varpool_node_set varpool_set;
700 const char * GTY ((skip)) name;
704 typedef struct ltrans_partition_def *ltrans_partition;
705 DEF_VEC_P(ltrans_partition);
706 DEF_VEC_ALLOC_P(ltrans_partition,gc);
708 static GTY (()) VEC(ltrans_partition, gc) *ltrans_partitions;
710 static void add_cgraph_node_to_partition (ltrans_partition part, struct cgraph_node *node);
711 static void add_varpool_node_to_partition (ltrans_partition part, struct varpool_node *vnode);
713 /* Create new partition with name NAME. */
714 static ltrans_partition
715 new_partition (const char *name)
717 ltrans_partition part = ggc_alloc_ltrans_partition_def ();
718 part->cgraph_set = cgraph_node_set_new ();
719 part->varpool_set = varpool_node_set_new ();
722 VEC_safe_push (ltrans_partition, gc, ltrans_partitions, part);
726 /* See all references that go to comdat objects and bring them into partition too. */
728 add_references_to_partition (ltrans_partition part, struct ipa_ref_list *refs)
732 for (i = 0; ipa_ref_list_reference_iterate (refs, i, ref); i++)
734 if (ref->refered_type == IPA_REF_CGRAPH
735 && DECL_COMDAT (ipa_ref_node (ref)->decl)
736 && !cgraph_node_in_set_p (ipa_ref_node (ref), part->cgraph_set))
737 add_cgraph_node_to_partition (part, ipa_ref_node (ref));
739 if (ref->refered_type == IPA_REF_VARPOOL
740 && DECL_COMDAT (ipa_ref_varpool_node (ref)->decl)
741 && !varpool_node_in_set_p (ipa_ref_varpool_node (ref), part->varpool_set))
742 add_varpool_node_to_partition (part, ipa_ref_varpool_node (ref));
746 /* Add NODE to partition as well as the inline callees and referred comdats into partition PART. */
749 add_cgraph_node_to_partition (ltrans_partition part, struct cgraph_node *node)
751 struct cgraph_edge *e;
753 part->insns += node->local.inline_summary.self_size;
757 node->in_other_partition = 1;
758 if (cgraph_dump_file)
759 fprintf (cgraph_dump_file, "Node %s/%i now used in multiple partitions\n",
760 cgraph_node_name (node), node->uid);
762 node->aux = (void *)((size_t)node->aux + 1);
764 cgraph_node_set_add (part->cgraph_set, node);
766 for (e = node->callees; e; e = e->next_callee)
767 if ((!e->inline_failed || DECL_COMDAT (e->callee->decl))
768 && !cgraph_node_in_set_p (e->callee, part->cgraph_set))
769 add_cgraph_node_to_partition (part, e->callee);
771 add_references_to_partition (part, &node->ref_list);
773 if (node->same_comdat_group
774 && !cgraph_node_in_set_p (node->same_comdat_group, part->cgraph_set))
775 add_cgraph_node_to_partition (part, node->same_comdat_group);
778 /* Add VNODE to partition as well as comdat references partition PART. */
781 add_varpool_node_to_partition (ltrans_partition part, struct varpool_node *vnode)
783 varpool_node_set_add (part->varpool_set, vnode);
787 vnode->in_other_partition = 1;
788 if (cgraph_dump_file)
789 fprintf (cgraph_dump_file, "Varpool node %s now used in multiple partitions\n",
790 varpool_node_name (vnode));
792 vnode->aux = (void *)((size_t)vnode->aux + 1);
794 add_references_to_partition (part, &vnode->ref_list);
796 if (vnode->same_comdat_group
797 && !varpool_node_in_set_p (vnode->same_comdat_group, part->varpool_set))
798 add_varpool_node_to_partition (part, vnode->same_comdat_group);
801 /* Undo all additions until number of cgraph nodes in PARITION is N_CGRAPH_NODES
802 and number of varpool nodes is N_VARPOOL_NODES. */
805 undo_partition (ltrans_partition partition, unsigned int n_cgraph_nodes,
806 unsigned int n_varpool_nodes)
808 while (VEC_length (cgraph_node_ptr, partition->cgraph_set->nodes) >
811 struct cgraph_node *node = VEC_index (cgraph_node_ptr,
812 partition->cgraph_set->nodes,
814 partition->insns -= node->local.inline_summary.self_size;
815 cgraph_node_set_remove (partition->cgraph_set, node);
816 node->aux = (void *)((size_t)node->aux - 1);
818 while (VEC_length (varpool_node_ptr, partition->varpool_set->nodes) >
821 struct varpool_node *node = VEC_index (varpool_node_ptr,
822 partition->varpool_set->nodes,
824 varpool_node_set_remove (partition->varpool_set, node);
825 node->aux = (void *)((size_t)node->aux - 1);
829 /* Return true if NODE should be partitioned.
830 This means that partitioning algorithm should put NODE into one of partitions.
831 This apply to most functions with bodies. Functions that are not partitions
832 are put into every unit needing them. This is the case of i.e. COMDATs. */
835 partition_cgraph_node_p (struct cgraph_node *node)
837 /* We will get proper partition based on function they are inlined to. */
838 if (node->global.inlined_to)
840 /* Nodes without a body do not need partitioning. */
843 /* Extern inlines and comdat are always only in partitions they are needed. */
844 if (DECL_EXTERNAL (node->decl)
845 || (DECL_COMDAT (node->decl)
846 && !cgraph_used_from_object_file_p (node)))
848 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (node->decl)))
853 /* Return true if VNODE should be partitioned.
854 This means that partitioning algorithm should put VNODE into one of partitions. */
857 partition_varpool_node_p (struct varpool_node *vnode)
859 if (vnode->alias || !vnode->needed)
861 /* Constant pool and comdat are always only in partitions they are needed. */
862 if (DECL_IN_CONSTANT_POOL (vnode->decl)
863 || (DECL_COMDAT (vnode->decl)
864 && !vnode->force_output
865 && !varpool_used_from_object_file_p (vnode)))
867 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (vnode->decl)))
872 /* Group cgrah nodes by input files. This is used mainly for testing
876 lto_1_to_1_map (void)
878 struct cgraph_node *node;
879 struct varpool_node *vnode;
880 struct lto_file_decl_data *file_data;
881 struct pointer_map_t *pmap;
882 ltrans_partition partition;
886 timevar_push (TV_WHOPR_WPA);
888 pmap = pointer_map_create ();
890 for (node = cgraph_nodes; node; node = node->next)
892 if (!partition_cgraph_node_p (node))
895 file_data = node->local.lto_file_data;
896 gcc_assert (!node->same_body_alias);
900 slot = pointer_map_contains (pmap, file_data);
902 partition = (ltrans_partition) *slot;
905 partition = new_partition (file_data->file_name);
906 slot = pointer_map_insert (pmap, file_data);
912 && VEC_length (ltrans_partition, ltrans_partitions))
913 partition = VEC_index (ltrans_partition, ltrans_partitions, 0);
916 partition = new_partition ("");
917 slot = pointer_map_insert (pmap, NULL);
923 add_cgraph_node_to_partition (partition, node);
926 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
928 if (!partition_varpool_node_p (vnode))
930 file_data = vnode->lto_file_data;
931 slot = pointer_map_contains (pmap, file_data);
933 partition = (ltrans_partition) *slot;
936 partition = new_partition (file_data->file_name);
937 slot = pointer_map_insert (pmap, file_data);
943 add_varpool_node_to_partition (partition, vnode);
945 for (node = cgraph_nodes; node; node = node->next)
947 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
950 /* If the cgraph is empty, create one cgraph node set so that there is still
951 an output file for any variables that need to be exported in a DSO. */
953 new_partition ("empty");
955 pointer_map_destroy (pmap);
957 timevar_pop (TV_WHOPR_WPA);
959 lto_stats.num_cgraph_partitions += VEC_length (ltrans_partition,
964 /* Group cgraph nodes in qually sized partitions.
966 The algorithm deciding paritions are simple: nodes are taken in predefined
967 order. The order correspond to order we wish to have functions in final
968 output. In future this will be given by function reordering pass, but at
969 the moment we use topological order that serve a good approximation.
971 The goal is to partition this linear order into intervals (partitions) such
972 that all partitions have approximately the same size and that the number of
973 callgraph or IPA reference edgess crossing boundaries is minimal.
975 This is a lot faster (O(n) in size of callgraph) than algorithms doing
976 priority based graph clustering that are generally O(n^2) and since WHOPR
977 is designed to make things go well across partitions, it leads to good results.
979 We compute the expected size of partition as
980 max (total_size / lto_partitions, min_partition_size).
981 We use dynamic expected size of partition, so small programs
982 are partitioning into enough partitions to allow use of multiple CPUs while
983 large programs are not partitioned too much. Creating too many partition
984 increase streaming overhead significandly.
986 In the future we would like to bound maximal size of partition to avoid
987 ltrans stage consuming too much memory. At the moment however WPA stage is
988 most memory intensive phase at large benchmark since too many types and
989 declarations are read into memory.
991 The function implement simple greedy algorithm. Nodes are begin added into
992 current partition until 3/4th of expected partition size is reached.
993 After this threshold we keep track of boundary size (number of edges going to
994 other partitions) and continue adding functions until the current partition
995 grows into a double of expected partition size. Then the process is undone
996 till the point when minimal ration of boundary size and in partition calls
1000 lto_balanced_map (void)
1003 struct cgraph_node **postorder =
1004 XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
1005 struct cgraph_node **order = XNEWVEC (struct cgraph_node *, cgraph_max_uid);
1006 int i, postorder_len;
1007 struct cgraph_node *node;
1008 int total_size = 0, best_total_size = 0;
1010 ltrans_partition partition;
1011 unsigned int last_visited_cgraph_node = 0, last_visited_varpool_node = 0;
1012 struct varpool_node *vnode;
1013 int cost = 0, internal = 0;
1014 int best_n_nodes = 0, best_n_varpool_nodes = 0, best_i = 0, best_cost =
1015 INT_MAX, best_internal = 0;
1018 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
1019 gcc_assert (!vnode->aux);
1020 /* Until we have better ordering facility, use toplogical order.
1021 Include only nodes we will partition and compute estimate of program
1022 size. Note that since nodes that are not partitioned might be put into
1023 multiple partitions, this is just an estimate of real size. This is why
1024 we keep partition_size updated after every partition is finalized. */
1025 postorder_len = cgraph_postorder (postorder);
1026 for (i = 0; i < postorder_len; i++)
1028 node = postorder[i];
1029 if (partition_cgraph_node_p (node))
1031 order[n_nodes++] = node;
1032 total_size += node->global.size;
1037 /* Compute partition size and create the first partition. */
1038 partition_size = total_size / PARAM_VALUE (PARAM_LTO_PARTITIONS);
1039 if (partition_size < PARAM_VALUE (MIN_PARTITION_SIZE))
1040 partition_size = PARAM_VALUE (MIN_PARTITION_SIZE);
1042 partition = new_partition ("");
1043 if (cgraph_dump_file)
1044 fprintf (cgraph_dump_file, "Total unit size: %i, partition size: %i\n",
1045 total_size, partition_size);
1047 for (i = 0; i < n_nodes; i++)
1050 add_cgraph_node_to_partition (partition, order[i]);
1051 total_size -= order[i]->global.size;
1053 /* Once we added a new node to the partition, we also want to add
1054 all referenced variables unless they was already added into some
1056 add_cgraph_node_to_partition adds possibly multiple nodes and
1057 variables that are needed to satisfy needs of ORDER[i].
1058 We remember last visited cgraph and varpool node from last iteration
1059 of outer loop that allows us to process every new addition.
1061 At the same time we compute size of the boundary into COST. Every
1062 callgraph or IPA reference edge leaving the partition contributes into
1063 COST. Every edge inside partition was earlier computed as one leaving
1064 it and thus we need to subtract it from COST. */
1065 while (last_visited_cgraph_node <
1066 VEC_length (cgraph_node_ptr, partition->cgraph_set->nodes)
1067 || last_visited_varpool_node < VEC_length (varpool_node_ptr,
1068 partition->varpool_set->
1071 struct ipa_ref_list *refs;
1073 struct ipa_ref *ref;
1074 bool cgraph_p = false;
1076 if (last_visited_cgraph_node <
1077 VEC_length (cgraph_node_ptr, partition->cgraph_set->nodes))
1079 struct cgraph_edge *edge;
1082 node = VEC_index (cgraph_node_ptr, partition->cgraph_set->nodes,
1083 last_visited_cgraph_node);
1084 refs = &node->ref_list;
1086 last_visited_cgraph_node++;
1088 gcc_assert (node->analyzed);
1090 /* Compute boundary cost of callgrpah edges. */
1091 for (edge = node->callees; edge; edge = edge->next_callee)
1092 if (edge->callee->analyzed)
1094 int edge_cost = edge->frequency;
1095 cgraph_node_set_iterator csi;
1099 gcc_assert (edge_cost > 0);
1100 csi = cgraph_node_set_find (partition->cgraph_set, edge->callee);
1101 if (!csi_end_p (csi)
1102 && csi.index < last_visited_cgraph_node - 1)
1103 cost -= edge_cost, internal+= edge_cost;
1107 for (edge = node->callers; edge; edge = edge->next_caller)
1109 int edge_cost = edge->frequency;
1110 cgraph_node_set_iterator csi;
1112 gcc_assert (edge->caller->analyzed);
1115 gcc_assert (edge_cost > 0);
1116 csi = cgraph_node_set_find (partition->cgraph_set, edge->caller);
1117 if (!csi_end_p (csi)
1118 && csi.index < last_visited_cgraph_node)
1127 &VEC_index (varpool_node_ptr, partition->varpool_set->nodes,
1128 last_visited_varpool_node)->ref_list;
1129 last_visited_varpool_node++;
1132 /* Compute boundary cost of IPA REF edges and at the same time look into
1133 variables referenced from current partition and try to add them. */
1134 for (j = 0; ipa_ref_list_reference_iterate (refs, j, ref); j++)
1135 if (ref->refered_type == IPA_REF_VARPOOL)
1137 varpool_node_set_iterator vsi;
1139 vnode = ipa_ref_varpool_node (ref);
1140 if (!vnode->finalized)
1142 if (!vnode->aux && partition_varpool_node_p (vnode))
1143 add_varpool_node_to_partition (partition, vnode);
1144 vsi = varpool_node_set_find (partition->varpool_set, vnode);
1145 if (!vsi_end_p (vsi)
1146 && vsi.index < last_visited_varpool_node - !cgraph_p)
1153 cgraph_node_set_iterator csi;
1155 node = ipa_ref_node (ref);
1156 if (!node->analyzed)
1158 csi = cgraph_node_set_find (partition->cgraph_set, node);
1159 if (!csi_end_p (csi)
1160 && csi.index < last_visited_cgraph_node - cgraph_p)
1165 for (j = 0; ipa_ref_list_refering_iterate (refs, j, ref); j++)
1166 if (ref->refering_type == IPA_REF_VARPOOL)
1168 varpool_node_set_iterator vsi;
1170 vnode = ipa_ref_refering_varpool_node (ref);
1171 gcc_assert (vnode->finalized);
1172 if (!vnode->aux && partition_varpool_node_p (vnode))
1173 add_varpool_node_to_partition (partition, vnode);
1174 vsi = varpool_node_set_find (partition->varpool_set, vnode);
1175 if (!vsi_end_p (vsi)
1176 && vsi.index < last_visited_varpool_node)
1183 cgraph_node_set_iterator csi;
1185 node = ipa_ref_refering_node (ref);
1186 gcc_assert (node->analyzed);
1187 csi = cgraph_node_set_find (partition->cgraph_set, node);
1188 if (!csi_end_p (csi)
1189 && csi.index < last_visited_cgraph_node)
1196 /* If the partition is large enough, start looking for smallest boundary cost. */
1197 if (partition->insns < partition_size * 3 / 4
1198 || best_cost == INT_MAX
1200 || (best_internal * (HOST_WIDE_INT) cost
1201 > (internal * (HOST_WIDE_INT)best_cost)))
1202 && partition->insns < partition_size * 5 / 4))
1205 best_internal = internal;
1207 best_n_nodes = VEC_length (cgraph_node_ptr,
1208 partition->cgraph_set->nodes);
1209 best_n_varpool_nodes = VEC_length (varpool_node_ptr,
1210 partition->varpool_set->nodes);
1211 best_total_size = total_size;
1213 if (cgraph_dump_file)
1214 fprintf (cgraph_dump_file, "Step %i: added %s/%i, size %i, cost %i/%i best %i/%i, step %i\n", i,
1215 cgraph_node_name (order[i]), order[i]->uid, partition->insns, cost, internal,
1216 best_cost, best_internal, best_i);
1217 /* Partition is too large, unwind into step when best cost was reached and
1218 start new partition. */
1219 if (partition->insns > 2 * partition_size)
1223 if (cgraph_dump_file)
1224 fprintf (cgraph_dump_file, "Unwinding %i insertions to step %i\n",
1225 i - best_i, best_i);
1226 undo_partition (partition, best_n_nodes, best_n_varpool_nodes);
1229 /* When we are finished, avoid creating empty partition. */
1230 if (i == n_nodes - 1)
1232 partition = new_partition ("");
1233 last_visited_cgraph_node = 0;
1234 last_visited_varpool_node = 0;
1235 total_size = best_total_size;
1238 if (cgraph_dump_file)
1239 fprintf (cgraph_dump_file, "New partition\n");
1241 best_n_varpool_nodes = 0;
1242 best_cost = INT_MAX;
1244 /* Since the size of partitions is just approximate, update the size after
1245 we finished current one. */
1246 if (npartitions < PARAM_VALUE (PARAM_LTO_PARTITIONS))
1247 partition_size = total_size
1248 / (PARAM_VALUE (PARAM_LTO_PARTITIONS) - npartitions);
1250 partition_size = INT_MAX;
1252 if (partition_size < PARAM_VALUE (MIN_PARTITION_SIZE))
1253 partition_size = PARAM_VALUE (MIN_PARTITION_SIZE);
1258 /* Varables that are not reachable from the code go into last partition. */
1259 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
1260 if (partition_varpool_node_p (vnode) && !vnode->aux)
1261 add_varpool_node_to_partition (partition, vnode);
1265 /* Promote variable VNODE to be static. */
1268 promote_var (struct varpool_node *vnode)
1270 if (TREE_PUBLIC (vnode->decl) || DECL_EXTERNAL (vnode->decl))
1272 gcc_assert (flag_wpa);
1273 TREE_PUBLIC (vnode->decl) = 1;
1274 DECL_VISIBILITY (vnode->decl) = VISIBILITY_HIDDEN;
1275 DECL_VISIBILITY_SPECIFIED (vnode->decl) = true;
1276 if (cgraph_dump_file)
1277 fprintf (cgraph_dump_file,
1278 "Promoting var as hidden: %s\n", varpool_node_name (vnode));
1282 /* Promote function NODE to be static. */
1285 promote_fn (struct cgraph_node *node)
1287 gcc_assert (flag_wpa);
1288 if (TREE_PUBLIC (node->decl) || DECL_EXTERNAL (node->decl))
1290 TREE_PUBLIC (node->decl) = 1;
1291 DECL_VISIBILITY (node->decl) = VISIBILITY_HIDDEN;
1292 DECL_VISIBILITY_SPECIFIED (node->decl) = true;
1293 if (node->same_body)
1295 struct cgraph_node *alias;
1296 for (alias = node->same_body;
1297 alias; alias = alias->next)
1299 TREE_PUBLIC (alias->decl) = 1;
1300 DECL_VISIBILITY (alias->decl) = VISIBILITY_HIDDEN;
1301 DECL_VISIBILITY_SPECIFIED (alias->decl) = true;
1304 if (cgraph_dump_file)
1305 fprintf (cgraph_dump_file,
1306 "Promoting function as hidden: %s/%i\n",
1307 cgraph_node_name (node), node->uid);
1311 /* Find out all static decls that need to be promoted to global because
1312 of cross file sharing. This function must be run in the WPA mode after
1313 all inlinees are added. */
1316 lto_promote_cross_file_statics (void)
1318 struct varpool_node *vnode;
1320 cgraph_node_set set;
1321 varpool_node_set vset;
1322 cgraph_node_set_iterator csi;
1323 varpool_node_set_iterator vsi;
1324 VEC(varpool_node_ptr, heap) *promoted_initializers = NULL;
1325 struct pointer_set_t *inserted = pointer_set_create ();
1327 gcc_assert (flag_wpa);
1329 n_sets = VEC_length (ltrans_partition, ltrans_partitions);
1330 for (i = 0; i < n_sets; i++)
1332 ltrans_partition part = VEC_index (ltrans_partition, ltrans_partitions, i);
1333 set = part->cgraph_set;
1334 vset = part->varpool_set;
1336 /* If node has either address taken (and we have no clue from where)
1337 or it is called from other partition, it needs to be globalized. */
1338 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
1340 struct cgraph_node *node = csi_node (csi);
1341 if (node->local.externally_visible)
1343 if (node->global.inlined_to)
1345 if ((!DECL_EXTERNAL (node->decl) && !DECL_COMDAT (node->decl))
1346 && (referenced_from_other_partition_p (&node->ref_list, set, vset)
1347 || reachable_from_other_partition_p (node, set)))
1350 for (vsi = vsi_start (vset); !vsi_end_p (vsi); vsi_next (&vsi))
1352 vnode = vsi_node (vsi);
1353 /* Constant pool references use internal labels and thus can not
1354 be made global. It is sensible to keep those ltrans local to
1355 allow better optimization. */
1356 if (!DECL_IN_CONSTANT_POOL (vnode->decl) && !DECL_COMDAT (vnode->decl)
1357 && !vnode->externally_visible && vnode->analyzed
1358 && referenced_from_other_partition_p (&vnode->ref_list,
1360 promote_var (vnode);
1363 /* We export initializers of read-only var into each partition
1364 referencing it. Folding might take declarations from the
1365 initializers and use it; so everything referenced from the
1366 initializers needs can be accessed from this partition after
1369 This means that we need to promote all variables and functions
1370 referenced from all initializers from readonly vars referenced
1371 from this partition that are not in this partition.
1372 This needs to be done recursively. */
1373 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
1374 if (const_value_known_p (vnode->decl)
1375 && DECL_INITIAL (vnode->decl)
1376 && !varpool_node_in_set_p (vnode, vset)
1377 && referenced_from_this_partition_p (&vnode->ref_list, set, vset)
1378 && !pointer_set_insert (inserted, vnode))
1379 VEC_safe_push (varpool_node_ptr, heap, promoted_initializers, vnode);
1380 while (!VEC_empty (varpool_node_ptr, promoted_initializers))
1383 struct ipa_ref *ref;
1385 vnode = VEC_pop (varpool_node_ptr, promoted_initializers);
1386 for (i = 0; ipa_ref_list_reference_iterate (&vnode->ref_list, i, ref); i++)
1388 if (ref->refered_type == IPA_REF_CGRAPH)
1390 struct cgraph_node *n = ipa_ref_node (ref);
1391 gcc_assert (!n->global.inlined_to);
1392 if (!n->local.externally_visible
1393 && !cgraph_node_in_set_p (n, set))
1398 struct varpool_node *v = ipa_ref_varpool_node (ref);
1399 if (varpool_node_in_set_p (v, vset))
1401 /* Constant pool references use internal labels and thus can not
1402 be made global. It is sensible to keep those ltrans local to
1403 allow better optimization. */
1404 if (DECL_IN_CONSTANT_POOL (v->decl))
1406 if (!pointer_set_insert (inserted, vnode))
1407 VEC_safe_push (varpool_node_ptr, heap,
1408 promoted_initializers, v);
1410 else if (!DECL_IN_CONSTANT_POOL (v->decl)
1411 && !v->externally_visible && v->analyzed)
1414 && DECL_INITIAL (v->decl)
1415 && const_value_known_p (v->decl)
1416 && !pointer_set_insert (inserted, vnode))
1417 VEC_safe_push (varpool_node_ptr, heap,
1418 promoted_initializers, v);
1424 pointer_set_destroy (inserted);
1427 static lto_file *current_lto_file;
1429 /* Helper for qsort; compare partitions and return one with smaller size.
1430 We sort from greatest to smallest so parallel build doesn't stale on the
1431 longest compilation being executed too late. */
1434 cmp_partitions (const void *a, const void *b)
1436 const struct ltrans_partition_def *pa
1437 = *(struct ltrans_partition_def *const *)a;
1438 const struct ltrans_partition_def *pb
1439 = *(struct ltrans_partition_def *const *)b;
1440 return pb->insns - pa->insns;
1443 /* Write all output files in WPA mode and the file with the list of
1447 lto_wpa_write_files (void)
1451 cgraph_node_set set;
1452 varpool_node_set vset;
1453 ltrans_partition part;
1454 FILE *ltrans_output_list_stream;
1455 char *temp_filename;
1458 /* Open the LTRANS output list. */
1459 if (!ltrans_output_list)
1460 fatal_error ("no LTRANS output list filename provided");
1461 ltrans_output_list_stream = fopen (ltrans_output_list, "w");
1462 if (ltrans_output_list_stream == NULL)
1463 fatal_error ("opening LTRANS output list %s: %m", ltrans_output_list);
1465 timevar_push (TV_WHOPR_WPA);
1467 FOR_EACH_VEC_ELT (ltrans_partition, ltrans_partitions, i, part)
1468 lto_stats.num_output_cgraph_nodes += VEC_length (cgraph_node_ptr,
1469 part->cgraph_set->nodes);
1471 /* Find out statics that need to be promoted
1472 to globals with hidden visibility because they are accessed from multiple
1474 lto_promote_cross_file_statics ();
1476 timevar_pop (TV_WHOPR_WPA);
1478 timevar_push (TV_WHOPR_WPA_IO);
1480 /* Generate a prefix for the LTRANS unit files. */
1481 blen = strlen (ltrans_output_list);
1482 temp_filename = (char *) xmalloc (blen + sizeof ("2147483648.o"));
1483 strcpy (temp_filename, ltrans_output_list);
1484 if (blen > sizeof (".out")
1485 && strcmp (temp_filename + blen - sizeof (".out") + 1,
1487 temp_filename[blen - sizeof (".out") + 1] = '\0';
1488 blen = strlen (temp_filename);
1490 n_sets = VEC_length (ltrans_partition, ltrans_partitions);
1491 VEC_qsort (ltrans_partition, ltrans_partitions, cmp_partitions);
1492 for (i = 0; i < n_sets; i++)
1495 ltrans_partition part = VEC_index (ltrans_partition, ltrans_partitions, i);
1497 set = part->cgraph_set;
1498 vset = part->varpool_set;
1500 /* Write all the nodes in SET. */
1501 sprintf (temp_filename + blen, "%u.o", i);
1502 file = lto_obj_file_open (temp_filename, true);
1504 fatal_error ("lto_obj_file_open() failed");
1507 fprintf (stderr, " %s (%s %i insns)", temp_filename, part->name, part->insns);
1508 if (cgraph_dump_file)
1510 fprintf (cgraph_dump_file, "Writting partition %s to file %s, %i insns\n",
1511 part->name, temp_filename, part->insns);
1512 fprintf (cgraph_dump_file, "cgraph nodes:");
1513 dump_cgraph_node_set (cgraph_dump_file, set);
1514 fprintf (cgraph_dump_file, "varpool nodes:");
1515 dump_varpool_node_set (cgraph_dump_file, vset);
1517 gcc_assert (cgraph_node_set_nonempty_p (set)
1518 || varpool_node_set_nonempty_p (vset) || !i);
1520 lto_set_current_out_file (file);
1522 ipa_write_optimization_summaries (set, vset);
1524 lto_set_current_out_file (NULL);
1525 lto_obj_file_close (file);
1527 len = strlen (temp_filename);
1528 if (fwrite (temp_filename, 1, len, ltrans_output_list_stream) < len
1529 || fwrite ("\n", 1, 1, ltrans_output_list_stream) < 1)
1530 fatal_error ("writing to LTRANS output list %s: %m",
1531 ltrans_output_list);
1534 lto_stats.num_output_files += n_sets;
1536 /* Close the LTRANS output list. */
1537 if (fclose (ltrans_output_list_stream))
1538 fatal_error ("closing LTRANS output list %s: %m", ltrans_output_list);
1540 timevar_pop (TV_WHOPR_WPA_IO);
1545 struct pointer_set_t *seen;
1548 #define LTO_FIXUP_SUBTREE(t) \
1550 walk_tree (&(t), lto_fixup_tree, data, NULL); \
1553 #define LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE(t) \
1557 (t) = gimple_register_type (t); \
1558 walk_tree (&(t), lto_fixup_tree, data, NULL); \
1562 static tree lto_fixup_tree (tree *, int *, void *);
1564 /* Return true if T does not need to be fixed up recursively. */
1570 || CONSTANT_CLASS_P (t)
1571 || TREE_CODE (t) == IDENTIFIER_NODE);
1574 /* Fix up fields of a tree_common T. DATA points to fix-up states. */
1577 lto_fixup_common (tree t, void *data)
1579 /* The following re-creates the TYPE_REFERENCE_TO and TYPE_POINTER_TO
1580 lists. We do not stream TYPE_REFERENCE_TO, TYPE_POINTER_TO or
1581 TYPE_NEXT_PTR_TO and TYPE_NEXT_REF_TO.
1582 First remove us from any pointer list we are on. */
1583 if (TREE_CODE (t) == POINTER_TYPE)
1585 if (TYPE_POINTER_TO (TREE_TYPE (t)) == t)
1586 TYPE_POINTER_TO (TREE_TYPE (t)) = TYPE_NEXT_PTR_TO (t);
1589 tree tem = TYPE_POINTER_TO (TREE_TYPE (t));
1590 while (tem && TYPE_NEXT_PTR_TO (tem) != t)
1591 tem = TYPE_NEXT_PTR_TO (tem);
1593 TYPE_NEXT_PTR_TO (tem) = TYPE_NEXT_PTR_TO (t);
1595 TYPE_NEXT_PTR_TO (t) = NULL_TREE;
1597 else if (TREE_CODE (t) == REFERENCE_TYPE)
1599 if (TYPE_REFERENCE_TO (TREE_TYPE (t)) == t)
1600 TYPE_REFERENCE_TO (TREE_TYPE (t)) = TYPE_NEXT_REF_TO (t);
1603 tree tem = TYPE_REFERENCE_TO (TREE_TYPE (t));
1604 while (tem && TYPE_NEXT_REF_TO (tem) != t)
1605 tem = TYPE_NEXT_REF_TO (tem);
1607 TYPE_NEXT_REF_TO (tem) = TYPE_NEXT_REF_TO (t);
1609 TYPE_NEXT_REF_TO (t) = NULL_TREE;
1612 /* Fixup our type. */
1613 LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TREE_TYPE (t));
1615 /* Second put us on the list of pointers of the new pointed-to type
1616 if we are a main variant. This is done in lto_fixup_type after
1617 fixing up our main variant. */
1619 /* This is not very efficient because we cannot do tail-recursion with
1620 a long chain of trees. */
1621 LTO_FIXUP_SUBTREE (TREE_CHAIN (t));
1624 /* Fix up fields of a decl_minimal T. DATA points to fix-up states. */
1627 lto_fixup_decl_minimal (tree t, void *data)
1629 lto_fixup_common (t, data);
1630 LTO_FIXUP_SUBTREE (DECL_NAME (t));
1631 LTO_FIXUP_SUBTREE (DECL_CONTEXT (t));
1634 /* Fix up fields of a decl_common T. DATA points to fix-up states. */
1637 lto_fixup_decl_common (tree t, void *data)
1639 lto_fixup_decl_minimal (t, data);
1640 LTO_FIXUP_SUBTREE (DECL_SIZE (t));
1641 LTO_FIXUP_SUBTREE (DECL_SIZE_UNIT (t));
1642 LTO_FIXUP_SUBTREE (DECL_INITIAL (t));
1643 LTO_FIXUP_SUBTREE (DECL_ATTRIBUTES (t));
1644 LTO_FIXUP_SUBTREE (DECL_ABSTRACT_ORIGIN (t));
1647 /* Fix up fields of a decl_with_vis T. DATA points to fix-up states. */
1650 lto_fixup_decl_with_vis (tree t, void *data)
1652 lto_fixup_decl_common (t, data);
1654 /* Accessor macro has side-effects, use field-name here. */
1655 LTO_FIXUP_SUBTREE (t->decl_with_vis.assembler_name);
1657 gcc_assert (no_fixup_p (DECL_SECTION_NAME (t)));
1660 /* Fix up fields of a decl_non_common T. DATA points to fix-up states. */
1663 lto_fixup_decl_non_common (tree t, void *data)
1665 lto_fixup_decl_with_vis (t, data);
1666 LTO_FIXUP_SUBTREE (DECL_ARGUMENT_FLD (t));
1667 LTO_FIXUP_SUBTREE (DECL_RESULT_FLD (t));
1668 LTO_FIXUP_SUBTREE (DECL_VINDEX (t));
1670 /* SAVED_TREE should not cleared by now. Also no accessor for base type. */
1671 gcc_assert (no_fixup_p (t->decl_non_common.saved_tree));
1674 /* Fix up fields of a decl_non_common T. DATA points to fix-up states. */
1677 lto_fixup_function (tree t, void *data)
1679 lto_fixup_decl_non_common (t, data);
1680 LTO_FIXUP_SUBTREE (DECL_FUNCTION_PERSONALITY (t));
1683 /* Fix up fields of a field_decl T. DATA points to fix-up states. */
1686 lto_fixup_field_decl (tree t, void *data)
1688 lto_fixup_decl_common (t, data);
1689 LTO_FIXUP_SUBTREE (DECL_FIELD_OFFSET (t));
1690 LTO_FIXUP_SUBTREE (DECL_BIT_FIELD_TYPE (t));
1691 LTO_FIXUP_SUBTREE (DECL_QUALIFIER (t));
1692 gcc_assert (no_fixup_p (DECL_FIELD_BIT_OFFSET (t)));
1693 LTO_FIXUP_SUBTREE (DECL_FCONTEXT (t));
1696 /* Fix up fields of a type T. DATA points to fix-up states. */
1699 lto_fixup_type (tree t, void *data)
1703 lto_fixup_common (t, data);
1704 LTO_FIXUP_SUBTREE (TYPE_CACHED_VALUES (t));
1705 LTO_FIXUP_SUBTREE (TYPE_SIZE (t));
1706 LTO_FIXUP_SUBTREE (TYPE_SIZE_UNIT (t));
1707 LTO_FIXUP_SUBTREE (TYPE_ATTRIBUTES (t));
1708 LTO_FIXUP_SUBTREE (TYPE_NAME (t));
1710 /* Accessors are for derived node types only. */
1711 if (!POINTER_TYPE_P (t))
1712 LTO_FIXUP_SUBTREE (t->type.minval);
1713 LTO_FIXUP_SUBTREE (t->type.maxval);
1715 /* Accessor is for derived node types only. */
1716 LTO_FIXUP_SUBTREE (t->type.binfo);
1718 if (TYPE_CONTEXT (t))
1720 if (TYPE_P (TYPE_CONTEXT (t)))
1721 LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TYPE_CONTEXT (t));
1723 LTO_FIXUP_SUBTREE (TYPE_CONTEXT (t));
1726 /* Compute the canonical type of t and fix that up. From this point
1727 there are no longer any types with TYPE_STRUCTURAL_EQUALITY_P
1728 and its type-based alias problems. */
1729 if (!TYPE_CANONICAL (t))
1731 TYPE_CANONICAL (t) = gimple_register_canonical_type (t);
1732 LTO_FIXUP_SUBTREE (TYPE_CANONICAL (t));
1735 /* The following re-creates proper variant lists while fixing up
1736 the variant leaders. We do not stream TYPE_NEXT_VARIANT so the
1737 variant list state before fixup is broken. */
1739 /* Remove us from our main variant list if we are not the variant leader. */
1740 if (TYPE_MAIN_VARIANT (t) != t)
1742 tem = TYPE_MAIN_VARIANT (t);
1743 while (tem && TYPE_NEXT_VARIANT (tem) != t)
1744 tem = TYPE_NEXT_VARIANT (tem);
1746 TYPE_NEXT_VARIANT (tem) = TYPE_NEXT_VARIANT (t);
1747 TYPE_NEXT_VARIANT (t) = NULL_TREE;
1750 /* Query our new main variant. */
1751 mv = gimple_register_type (TYPE_MAIN_VARIANT (t));
1753 /* If we were the variant leader and we get replaced ourselves drop
1754 all variants from our list. */
1755 if (TYPE_MAIN_VARIANT (t) == t
1761 tree tem2 = TYPE_NEXT_VARIANT (tem);
1762 TYPE_NEXT_VARIANT (tem) = NULL_TREE;
1767 /* If we are not our own variant leader link us into our new leaders
1771 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
1772 TYPE_NEXT_VARIANT (mv) = t;
1775 /* Finally adjust our main variant and fix it up. */
1776 TYPE_MAIN_VARIANT (t) = mv;
1777 LTO_FIXUP_SUBTREE (TYPE_MAIN_VARIANT (t));
1779 /* As the second step of reconstructing the pointer chains put us
1780 on the list of pointers of the new pointed-to type
1781 if we are a main variant. See lto_fixup_common for the first step. */
1782 if (TREE_CODE (t) == POINTER_TYPE
1783 && TYPE_MAIN_VARIANT (t) == t)
1785 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (TREE_TYPE (t));
1786 TYPE_POINTER_TO (TREE_TYPE (t)) = t;
1788 else if (TREE_CODE (t) == REFERENCE_TYPE
1789 && TYPE_MAIN_VARIANT (t) == t)
1791 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (TREE_TYPE (t));
1792 TYPE_REFERENCE_TO (TREE_TYPE (t)) = t;
1796 /* Fix up fields of a BINFO T. DATA points to fix-up states. */
1799 lto_fixup_binfo (tree t, void *data)
1801 unsigned HOST_WIDE_INT i, n;
1802 tree base, saved_base;
1804 lto_fixup_common (t, data);
1805 gcc_assert (no_fixup_p (BINFO_OFFSET (t)));
1806 LTO_FIXUP_SUBTREE (BINFO_VTABLE (t));
1807 LTO_FIXUP_SUBTREE (BINFO_VIRTUALS (t));
1808 LTO_FIXUP_SUBTREE (BINFO_VPTR_FIELD (t));
1809 n = VEC_length (tree, BINFO_BASE_ACCESSES (t));
1810 for (i = 0; i < n; i++)
1812 saved_base = base = BINFO_BASE_ACCESS (t, i);
1813 LTO_FIXUP_SUBTREE (base);
1814 if (base != saved_base)
1815 VEC_replace (tree, BINFO_BASE_ACCESSES (t), i, base);
1817 LTO_FIXUP_SUBTREE (BINFO_INHERITANCE_CHAIN (t));
1818 LTO_FIXUP_SUBTREE (BINFO_SUBVTT_INDEX (t));
1819 LTO_FIXUP_SUBTREE (BINFO_VPTR_INDEX (t));
1820 n = BINFO_N_BASE_BINFOS (t);
1821 for (i = 0; i < n; i++)
1823 saved_base = base = BINFO_BASE_BINFO (t, i);
1824 LTO_FIXUP_SUBTREE (base);
1825 if (base != saved_base)
1826 VEC_replace (tree, BINFO_BASE_BINFOS (t), i, base);
1830 /* Fix up fields of a CONSTRUCTOR T. DATA points to fix-up states. */
1833 lto_fixup_constructor (tree t, void *data)
1835 unsigned HOST_WIDE_INT idx;
1836 constructor_elt *ce;
1838 LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TREE_TYPE (t));
1841 VEC_iterate(constructor_elt, CONSTRUCTOR_ELTS (t), idx, ce);
1844 LTO_FIXUP_SUBTREE (ce->index);
1845 LTO_FIXUP_SUBTREE (ce->value);
1849 /* A walk_tree callback used by lto_fixup_state. TP is the pointer to the
1850 current tree. WALK_SUBTREES indicates if the subtrees will be walked.
1851 DATA is a pointer set to record visited nodes. */
1854 lto_fixup_tree (tree *tp, int *walk_subtrees, void *data)
1857 lto_fixup_data_t *fixup_data = (lto_fixup_data_t *) data;
1862 if (!t || pointer_set_contains (fixup_data->seen, t))
1865 if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == FUNCTION_DECL)
1867 prevailing = lto_symtab_prevailing_decl (t);
1869 if (t != prevailing)
1871 /* Also replace t with prevailing defintion. We don't want to
1872 insert the other defintion in the seen set as we want to
1873 replace all instances of it. */
1878 else if (TYPE_P (t))
1880 /* Replace t with the prevailing type. We don't want to insert the
1881 other type in the seen set as we want to replace all instances of it. */
1882 t = gimple_register_type (t);
1886 if (pointer_set_insert (fixup_data->seen, t))
1889 /* walk_tree does not visit all reachable nodes that need to be fixed up.
1890 Hence we do special processing here for those kind of nodes. */
1891 switch (TREE_CODE (t))
1894 lto_fixup_field_decl (t, data);
1902 lto_fixup_decl_common (t, data);
1906 lto_fixup_decl_with_vis (t, data);
1910 lto_fixup_decl_non_common (t, data);
1914 lto_fixup_function (t, data);
1918 lto_fixup_binfo (t, data);
1923 lto_fixup_type (t, data);
1924 else if (TREE_CODE (t) == CONSTRUCTOR)
1925 lto_fixup_constructor (t, data);
1926 else if (CONSTANT_CLASS_P (t))
1927 LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TREE_TYPE (t));
1928 else if (EXPR_P (t))
1930 /* walk_tree only handles TREE_OPERANDs. Do the rest here. */
1931 lto_fixup_common (t, data);
1932 LTO_FIXUP_SUBTREE (t->exp.block);
1937 /* Let walk_tree handle sub-trees. */
1945 /* Helper function of lto_fixup_decls. Walks the var and fn streams in STATE,
1946 replaces var and function decls with the corresponding prevailing def and
1947 records the old decl in the free-list in DATA. We also record visted nodes
1948 in the seen-set in DATA to avoid multiple visit for nodes that need not
1952 lto_fixup_state (struct lto_in_decl_state *state, lto_fixup_data_t *data)
1955 struct lto_tree_ref_table *table;
1957 /* Although we only want to replace FUNCTION_DECLs and VAR_DECLs,
1958 we still need to walk from all DECLs to find the reachable
1959 FUNCTION_DECLs and VAR_DECLs. */
1960 for (si = 0; si < LTO_N_DECL_STREAMS; si++)
1962 table = &state->streams[si];
1963 for (i = 0; i < table->size; i++)
1964 walk_tree (table->trees + i, lto_fixup_tree, data, NULL);
1968 /* A callback of htab_traverse. Just extract a state from SLOT and the
1969 lto_fixup_data_t object from AUX and calls lto_fixup_state. */
1972 lto_fixup_state_aux (void **slot, void *aux)
1974 struct lto_in_decl_state *state = (struct lto_in_decl_state *) *slot;
1975 lto_fixup_state (state, (lto_fixup_data_t *) aux);
1979 /* Fix the decls from all FILES. Replaces each decl with the corresponding
1983 lto_fixup_decls (struct lto_file_decl_data **files)
1987 struct pointer_set_t *seen = pointer_set_create ();
1988 lto_fixup_data_t data;
1991 for (i = 0; files[i]; i++)
1993 struct lto_file_decl_data *file = files[i];
1994 struct lto_in_decl_state *state = file->global_decl_state;
1995 lto_fixup_state (state, &data);
1997 htab_traverse (file->function_decl_states, lto_fixup_state_aux, &data);
2000 FOR_EACH_VEC_ELT (tree, lto_global_var_decls, i, decl)
2002 tree saved_decl = decl;
2003 walk_tree (&decl, lto_fixup_tree, &data, NULL);
2004 if (decl != saved_decl)
2005 VEC_replace (tree, lto_global_var_decls, i, decl);
2008 pointer_set_destroy (seen);
2011 /* Read the options saved from each file in the command line. Called
2012 from lang_hooks.post_options which is called by process_options
2013 right before all the options are used to initialize the compiler.
2014 This assumes that decode_options has already run, so the
2015 num_in_fnames and in_fnames are properly set.
2017 Note that this assumes that all the files had been compiled with
2018 the same options, which is not a good assumption. In general,
2019 options ought to be read from all the files in the set and merged.
2020 However, it is still unclear what the merge rules should be. */
2023 lto_read_all_file_options (void)
2027 /* Clear any file options currently saved. */
2028 lto_clear_file_options ();
2030 /* Set the hooks to read ELF sections. */
2031 lto_set_in_hooks (NULL, get_section_data, free_section_data);
2033 fprintf (stderr, "Reading command line options:");
2035 for (i = 0; i < num_in_fnames; i++)
2037 struct lto_file_decl_data *file_data;
2038 lto_file *file = lto_obj_file_open (in_fnames[i], false);
2043 fprintf (stderr, " %s", in_fnames[i]);
2047 file_data = XCNEW (struct lto_file_decl_data);
2048 file_data->file_name = file->filename;
2049 file_data->section_hash_table = lto_obj_build_section_table (file);
2051 lto_read_file_options (file_data);
2053 lto_obj_file_close (file);
2054 htab_delete (file_data->section_hash_table);
2059 fprintf (stderr, "\n");
2061 /* Apply globally the options read from all the files. */
2062 lto_reissue_options ();
2065 static GTY((length ("lto_stats.num_input_files + 1"))) struct lto_file_decl_data **all_file_decl_data;
2067 /* Turn file datas for sub files into a single array, so that they look
2068 like separate files for further passes. */
2071 lto_flatten_files (struct lto_file_decl_data **orig, int count, int last_file_ix)
2073 struct lto_file_decl_data *n, *next;
2076 lto_stats.num_input_files = count;
2078 = ggc_alloc_cleared_vec_lto_file_decl_data_ptr (count + 1);
2079 /* Set the hooks so that all of the ipa passes can read in their data. */
2080 lto_set_in_hooks (all_file_decl_data, get_section_data, free_section_data);
2081 for (i = 0, k = 0; i < last_file_ix; i++)
2083 for (n = orig[i]; n != NULL; n = next)
2085 all_file_decl_data[k++] = n;
2090 all_file_decl_data[k] = NULL;
2091 gcc_assert (k == count);
2094 /* Input file data before flattening (i.e. splitting them to subfiles to support
2095 incremental linking. */
2096 static int real_file_count;
2097 static GTY((length ("real_file_count + 1"))) struct lto_file_decl_data **real_file_decl_data;
2099 /* Read all the symbols from the input files FNAMES. NFILES is the
2100 number of files requested in the command line. Instantiate a
2101 global call graph by aggregating all the sub-graphs found in each
2105 read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
2107 unsigned int i, last_file_ix;
2109 struct cgraph_node *node;
2111 struct lto_file_decl_data **decl_data;
2115 timevar_push (TV_IPA_LTO_DECL_IN);
2118 = decl_data = ggc_alloc_cleared_vec_lto_file_decl_data_ptr (nfiles + 1);
2119 real_file_count = nfiles;
2121 /* Read the resolution file. */
2123 if (resolution_file_name)
2126 unsigned num_objects;
2128 resolution = fopen (resolution_file_name, "r");
2129 if (resolution == NULL)
2130 fatal_error ("could not open symbol resolution file: %m");
2132 t = fscanf (resolution, "%u", &num_objects);
2133 gcc_assert (t == 1);
2135 /* True, since the plugin splits the archives. */
2136 gcc_assert (num_objects == nfiles);
2140 fprintf (stderr, "Reading object files:");
2142 /* Read all of the object files specified on the command line. */
2143 for (i = 0, last_file_ix = 0; i < nfiles; ++i)
2145 struct lto_file_decl_data *file_data = NULL;
2148 fprintf (stderr, " %s", fnames[i]);
2152 current_lto_file = lto_obj_file_open (fnames[i], false);
2153 if (!current_lto_file)
2156 file_data = lto_file_read (current_lto_file, resolution, &count);
2159 lto_obj_file_close (current_lto_file);
2160 current_lto_file = NULL;
2164 decl_data[last_file_ix++] = file_data;
2166 lto_obj_file_close (current_lto_file);
2167 current_lto_file = NULL;
2171 lto_flatten_files (decl_data, count, last_file_ix);
2172 lto_stats.num_input_files = count;
2173 ggc_free(decl_data);
2174 real_file_decl_data = NULL;
2176 if (resolution_file_name)
2177 fclose (resolution);
2179 /* Set the hooks so that all of the ipa passes can read in their data. */
2180 lto_set_in_hooks (all_file_decl_data, get_section_data, free_section_data);
2182 timevar_pop (TV_IPA_LTO_DECL_IN);
2185 fprintf (stderr, "\nReading the callgraph\n");
2187 timevar_push (TV_IPA_LTO_CGRAPH_IO);
2188 /* Read the callgraph. */
2190 timevar_pop (TV_IPA_LTO_CGRAPH_IO);
2193 fprintf (stderr, "Merging declarations\n");
2195 timevar_push (TV_IPA_LTO_DECL_MERGE);
2196 /* Merge global decls. */
2197 lto_symtab_merge_decls ();
2199 /* If there were errors during symbol merging bail out, we have no
2200 good way to recover here. */
2202 fatal_error ("errors during merging of translation units");
2204 /* Fixup all decls and types and free the type hash tables. */
2205 lto_fixup_decls (all_file_decl_data);
2206 free_gimple_type_tables ();
2209 timevar_pop (TV_IPA_LTO_DECL_MERGE);
2210 /* Each pass will set the appropriate timer. */
2213 fprintf (stderr, "Reading summaries\n");
2215 /* Read the IPA summary data. */
2217 ipa_read_optimization_summaries ();
2219 ipa_read_summaries ();
2221 /* Finally merge the cgraph according to the decl merging decisions. */
2222 timevar_push (TV_IPA_LTO_CGRAPH_MERGE);
2223 if (cgraph_dump_file)
2225 fprintf (cgraph_dump_file, "Before merging:\n");
2226 dump_cgraph (cgraph_dump_file);
2227 dump_varpool (cgraph_dump_file);
2229 lto_symtab_merge_cgraph_nodes ();
2233 for (node = cgraph_nodes; node; node = node->next)
2235 /* FIXME: ipa_transforms_to_apply holds list of passes that have optimization
2236 summaries computed and needs to apply changes. At the moment WHOPR only
2237 supports inlining, so we can push it here by hand. In future we need to stream
2238 this field into ltrans compilation. */
2240 VEC_safe_push (ipa_opt_pass, heap,
2241 node->ipa_transforms_to_apply,
2242 (ipa_opt_pass)&pass_ipa_inline);
2246 timevar_pop (TV_IPA_LTO_CGRAPH_MERGE);
2248 timevar_push (TV_IPA_LTO_DECL_INIT_IO);
2250 /* FIXME lto. This loop needs to be changed to use the pass manager to
2251 call the ipa passes directly. */
2253 for (i = 0; i < last_file_ix; i++)
2255 struct lto_file_decl_data *file_data = all_file_decl_data [i];
2256 lto_materialize_constructors_and_inits (file_data);
2259 /* Indicate that the cgraph is built and ready. */
2260 cgraph_function_flags_ready = true;
2262 timevar_pop (TV_IPA_LTO_DECL_INIT_IO);
2263 ggc_free (all_file_decl_data);
2264 all_file_decl_data = NULL;
2268 /* Materialize all the bodies for all the nodes in the callgraph. */
2271 materialize_cgraph (void)
2274 struct cgraph_node *node;
2276 timevar_id_t lto_timer;
2280 flag_wpa ? "Materializing decls:" : "Reading function bodies:");
2283 /* Now that we have input the cgraph, we need to clear all of the aux
2284 nodes and read the functions if we are not running in WPA mode. */
2285 timevar_push (TV_IPA_LTO_GIMPLE_IN);
2287 for (node = cgraph_nodes; node; node = node->next)
2289 if (node->local.lto_file_data)
2291 lto_materialize_function (node);
2292 lto_stats.num_input_cgraph_nodes++;
2296 timevar_pop (TV_IPA_LTO_GIMPLE_IN);
2298 /* Start the appropriate timer depending on the mode that we are
2300 lto_timer = (flag_wpa) ? TV_WHOPR_WPA
2301 : (flag_ltrans) ? TV_WHOPR_LTRANS
2303 timevar_push (lto_timer);
2305 current_function_decl = NULL;
2308 /* Inform the middle end about the global variables we have seen. */
2309 FOR_EACH_VEC_ELT (tree, lto_global_var_decls, i, decl)
2310 rest_of_decl_compilation (decl, 1, 0);
2313 fprintf (stderr, "\n");
2315 timevar_pop (lto_timer);
2319 /* Perform whole program analysis (WPA) on the callgraph and write out the
2320 optimization plan. */
2323 do_whole_program_analysis (void)
2325 /* Note that since we are in WPA mode, materialize_cgraph will not
2326 actually read in all the function bodies. It only materializes
2327 the decls and cgraph nodes so that analysis can be performed. */
2328 materialize_cgraph ();
2330 /* Reading in the cgraph uses different timers, start timing WPA now. */
2331 timevar_push (TV_WHOPR_WPA);
2333 if (pre_ipa_mem_report)
2335 fprintf (stderr, "Memory consumption before IPA\n");
2336 dump_memory_report (false);
2339 cgraph_function_flags_ready = true;
2341 if (cgraph_dump_file)
2343 dump_cgraph (cgraph_dump_file);
2344 dump_varpool (cgraph_dump_file);
2346 bitmap_obstack_initialize (NULL);
2347 ipa_register_cgraph_hooks ();
2348 cgraph_state = CGRAPH_STATE_IPA_SSA;
2350 execute_ipa_pass_list (all_regular_ipa_passes);
2352 if (cgraph_dump_file)
2354 fprintf (cgraph_dump_file, "Optimized ");
2355 dump_cgraph (cgraph_dump_file);
2356 dump_varpool (cgraph_dump_file);
2359 bitmap_obstack_release (NULL);
2361 /* We are about to launch the final LTRANS phase, stop the WPA timer. */
2362 timevar_pop (TV_WHOPR_WPA);
2364 if (flag_lto_partition_1to1)
2367 lto_balanced_map ();
2371 fprintf (stderr, "\nStreaming out");
2374 lto_wpa_write_files ();
2377 fprintf (stderr, "\n");
2379 if (post_ipa_mem_report)
2381 fprintf (stderr, "Memory consumption after IPA\n");
2382 dump_memory_report (false);
2385 /* Show the LTO report before launching LTRANS. */
2386 if (flag_lto_report)
2387 print_lto_report ();
2391 static GTY(()) tree lto_eh_personality_decl;
2393 /* Return the LTO personality function decl. */
2396 lto_eh_personality (void)
2398 if (!lto_eh_personality_decl)
2400 /* Use the first personality DECL for our personality if we don't
2401 support multiple ones. This ensures that we don't artificially
2402 create the need for them in a single-language program. */
2403 if (first_personality_decl && !dwarf2out_do_cfi_asm ())
2404 lto_eh_personality_decl = first_personality_decl;
2406 lto_eh_personality_decl = lhd_gcc_personality ();
2409 return lto_eh_personality_decl;
2412 /* Set the process name based on the LTO mode. */
2415 lto_process_name (void)
2418 setproctitle ("lto1-lto");
2420 setproctitle ("lto1-wpa");
2422 setproctitle ("lto1-ltrans");
2425 /* Main entry point for the GIMPLE front end. This front end has
2426 three main personalities:
2428 - LTO (-flto). All the object files on the command line are
2429 loaded in memory and processed as a single translation unit.
2430 This is the traditional link-time optimization behavior.
2432 - WPA (-fwpa). Only the callgraph and summary information for
2433 files in the command file are loaded. A single callgraph
2434 (without function bodies) is instantiated for the whole set of
2435 files. IPA passes are only allowed to analyze the call graph
2436 and make transformation decisions. The callgraph is
2437 partitioned, each partition is written to a new object file
2438 together with the transformation decisions.
2440 - LTRANS (-fltrans). Similar to -flto but it prevents the IPA
2441 summary files from running again. Since WPA computed summary
2442 information and decided what transformations to apply, LTRANS
2443 simply applies them. */
2448 lto_process_name ();
2452 /* Read all the symbols and call graph from all the files in the
2454 read_cgraph_and_symbols (num_in_fnames, in_fnames);
2458 /* If WPA is enabled analyze the whole call graph and create an
2459 optimization plan. Otherwise, read in all the function
2460 bodies and continue with optimization. */
2462 do_whole_program_analysis ();
2465 materialize_cgraph ();
2467 /* Let the middle end know that we have read and merged all of
2471 /* FIXME lto, if the processes spawned by WPA fail, we miss
2472 the chance to print WPA's report, so WPA will call
2473 print_lto_report before launching LTRANS. If LTRANS was
2474 launched directly by the driver we would not need to do
2476 if (flag_lto_report)
2477 print_lto_report ();
2482 #include "gt-lto-lto.h"