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"
47 #include "ipa-inline.h"
49 static GTY(()) tree first_personality_decl;
51 /* Returns a hash code for P. */
54 hash_name (const void *p)
56 const struct lto_section_slot *ds = (const struct lto_section_slot *) p;
57 return (hashval_t) htab_hash_string (ds->name);
61 /* Returns nonzero if P1 and P2 are equal. */
64 eq_name (const void *p1, const void *p2)
66 const struct lto_section_slot *s1 =
67 (const struct lto_section_slot *) p1;
68 const struct lto_section_slot *s2 =
69 (const struct lto_section_slot *) p2;
71 return strcmp (s1->name, s2->name) == 0;
74 /* Free lto_section_slot */
77 free_with_string (void *arg)
79 struct lto_section_slot *s = (struct lto_section_slot *)arg;
81 free (CONST_CAST (char *, s->name));
85 /* Create section hash table */
88 lto_obj_create_section_hash_table (void)
90 return htab_create (37, hash_name, eq_name, free_with_string);
93 /* Read the constructors and inits. */
96 lto_materialize_constructors_and_inits (struct lto_file_decl_data * file_data)
99 const char *data = lto_get_section_data (file_data,
100 LTO_section_static_initializer,
102 lto_input_constructors_and_inits (file_data, data);
103 lto_free_section_data (file_data, LTO_section_static_initializer, NULL,
107 /* Return true when NODE has a clone that is analyzed (i.e. we need
108 to load its body even if the node itself is not needed). */
111 has_analyzed_clone_p (struct cgraph_node *node)
113 struct cgraph_node *orig = node;
122 else if (node->next_sibling_clone)
123 node = node->next_sibling_clone;
126 while (node != orig && !node->next_sibling_clone)
127 node = node->clone_of;
129 node = node->next_sibling_clone;
135 /* Read the function body for the function associated with NODE. */
138 lto_materialize_function (struct cgraph_node *node)
141 struct lto_file_decl_data *file_data;
142 const char *data, *name;
146 /* Read in functions with body (analyzed nodes)
147 and also functions that are needed to produce virtual clones. */
148 if (node->analyzed || has_analyzed_clone_p (node))
150 /* Clones don't need to be read. */
154 /* Load the function body only if not operating in WPA mode. In
155 WPA mode, the body of the function is not needed. */
158 file_data = node->local.lto_file_data;
159 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
161 /* We may have renamed the declaration, e.g., a static function. */
162 name = lto_get_decl_name_mapping (file_data, name);
164 data = lto_get_section_data (file_data, LTO_section_function_body,
167 fatal_error ("%s: section %s is missing",
168 file_data->file_name,
171 gcc_assert (DECL_STRUCT_FUNCTION (decl) == NULL);
173 allocate_struct_function (decl, false);
174 announce_function (decl);
175 lto_input_function_body (file_data, decl, data);
176 if (DECL_FUNCTION_PERSONALITY (decl) && !first_personality_decl)
177 first_personality_decl = DECL_FUNCTION_PERSONALITY (decl);
178 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 in decl
191 state object STATE. DATA_IN points to a data_in structure for
192 decoding. Return the address after the decoded object in the
195 static const uint32_t *
196 lto_read_in_decl_state (struct data_in *data_in, const uint32_t *data,
197 struct lto_in_decl_state *state)
204 decl = lto_streamer_cache_get (data_in->reader_cache, ix);
205 if (TREE_CODE (decl) != FUNCTION_DECL)
207 gcc_assert (decl == void_type_node);
210 state->fn_decl = decl;
212 for (i = 0; i < LTO_N_DECL_STREAMS; i++)
214 uint32_t size = *data++;
215 tree *decls = ggc_alloc_vec_tree (size);
217 for (j = 0; j < size; j++)
219 decls[j] = lto_streamer_cache_get (data_in->reader_cache, data[j]);
221 /* Register every type in the global type table. If the
222 type existed already, use the existing type. */
223 if (TYPE_P (decls[j]))
224 decls[j] = gimple_register_type (decls[j]);
227 state->streams[i].size = size;
228 state->streams[i].trees = decls;
236 /* Read all the symbols from buffer DATA, using descriptors in DECL_DATA.
237 RESOLUTIONS is the set of symbols picked by the linker (read from the
238 resolution file when the linker plugin is being used). */
241 lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
242 VEC(ld_plugin_symbol_resolution_t,heap) *resolutions)
244 const struct lto_decl_header *header = (const struct lto_decl_header *) data;
245 const int32_t decl_offset = sizeof (struct lto_decl_header);
246 const int32_t main_offset = decl_offset + header->decl_state_size;
247 const int32_t string_offset = main_offset + header->main_size;
248 struct lto_input_block ib_main;
249 struct data_in *data_in;
251 const uint32_t *data_ptr, *data_end;
252 uint32_t num_decl_states;
254 LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0,
257 data_in = lto_data_in_create (decl_data, (const char *) data + string_offset,
258 header->string_size, resolutions);
260 /* Read the global declarations and types. */
261 while (ib_main.p < ib_main.len)
263 tree t = lto_input_tree (&ib_main, data_in);
264 gcc_assert (t && ib_main.p <= ib_main.len);
267 /* Read in lto_in_decl_state objects. */
268 data_ptr = (const uint32_t *) ((const char*) data + decl_offset);
270 (const uint32_t *) ((const char*) data_ptr + header->decl_state_size);
271 num_decl_states = *data_ptr++;
273 gcc_assert (num_decl_states > 0);
274 decl_data->global_decl_state = lto_new_in_decl_state ();
275 data_ptr = lto_read_in_decl_state (data_in, data_ptr,
276 decl_data->global_decl_state);
278 /* Read in per-function decl states and enter them in hash table. */
279 decl_data->function_decl_states =
280 htab_create_ggc (37, lto_hash_in_decl_state, lto_eq_in_decl_state, NULL);
282 for (i = 1; i < num_decl_states; i++)
284 struct lto_in_decl_state *state = lto_new_in_decl_state ();
287 data_ptr = lto_read_in_decl_state (data_in, data_ptr, state);
288 slot = htab_find_slot (decl_data->function_decl_states, state, INSERT);
289 gcc_assert (*slot == NULL);
293 if (data_ptr != data_end)
294 internal_error ("bytecode stream: garbage at the end of symbols section");
296 /* Set the current decl state to be the global state. */
297 decl_data->current_decl_state = decl_data->global_decl_state;
299 lto_data_in_delete (data_in);
302 /* strtoll is not portable. */
304 lto_parse_hex (const char *p) {
306 for (; *p != '\0'; ++p)
311 if (c >= '0' && c <= '9')
313 else if (c >= 'a' && c <= 'f')
315 else if (c >= 'A' && c <= 'F')
318 internal_error ("could not parse hex number");
324 /* Read resolution for file named FILE_NAME. The resolution is read from
328 lto_resolution_read (splay_tree file_ids, FILE *resolution, lto_file *file)
330 /* We require that objects in the resolution file are in the same
331 order as the lto1 command line. */
332 unsigned int name_len;
334 unsigned int num_symbols;
336 struct lto_file_decl_data *file_data;
337 unsigned max_index = 0;
338 splay_tree_node nd = NULL;
343 name_len = strlen (file->filename);
344 obj_name = XNEWVEC (char, name_len + 1);
345 fscanf (resolution, " "); /* Read white space. */
347 fread (obj_name, sizeof (char), name_len, resolution);
348 obj_name[name_len] = '\0';
349 if (filename_cmp (obj_name, file->filename) != 0)
350 internal_error ("unexpected file name %s in linker resolution file. "
351 "Expected %s", obj_name, file->filename);
352 if (file->offset != 0)
357 t = fscanf (resolution, "@0x%16s", offset_p);
359 internal_error ("could not parse file offset");
360 offset = lto_parse_hex (offset_p);
361 if (offset != file->offset)
362 internal_error ("unexpected offset");
367 fscanf (resolution, "%u", &num_symbols);
369 for (i = 0; i < num_symbols; i++)
374 enum ld_plugin_symbol_resolution r = (enum ld_plugin_symbol_resolution) 0;
376 unsigned int lto_resolution_str_len =
377 sizeof (lto_resolution_str) / sizeof (char *);
379 t = fscanf (resolution, "%u %x %26s %*[^\n]\n", &index, &id, r_str);
381 internal_error ("invalid line in the resolution file");
382 if (index > max_index)
385 for (j = 0; j < lto_resolution_str_len; j++)
387 if (strcmp (lto_resolution_str[j], r_str) == 0)
389 r = (enum ld_plugin_symbol_resolution) j;
393 if (j == lto_resolution_str_len)
394 internal_error ("invalid resolution in the resolution file");
396 if (!(nd && nd->key == id))
398 nd = splay_tree_lookup (file_ids, id);
400 internal_error ("resolution sub id %x not in object file", id);
403 file_data = (struct lto_file_decl_data *)nd->value;
404 if (cgraph_dump_file)
405 fprintf (cgraph_dump_file, "Adding resolution %u %u to id %x\n",
406 index, r, file_data->id);
407 VEC_safe_grow_cleared (ld_plugin_symbol_resolution_t, heap,
408 file_data->resolutions,
410 VEC_replace (ld_plugin_symbol_resolution_t,
411 file_data->resolutions, index, r);
415 /* Is the name for a id'ed LTO section? */
418 lto_section_with_id (const char *name, unsigned *id)
422 if (strncmp (name, LTO_SECTION_NAME_PREFIX, strlen (LTO_SECTION_NAME_PREFIX)))
424 s = strrchr (name, '.');
425 return s && sscanf (s, ".%x", id) == 1;
428 /* Create file_data of each sub file id */
431 create_subid_section_table (void **slot, void *data)
433 struct lto_section_slot s_slot, *new_slot;
434 struct lto_section_slot *ls = *(struct lto_section_slot **)slot;
435 splay_tree file_ids = (splay_tree)data;
440 struct lto_file_decl_data *file_data;
442 if (!lto_section_with_id (ls->name, &id))
445 /* Find hash table of sub module id */
446 nd = splay_tree_lookup (file_ids, id);
449 file_data = (struct lto_file_decl_data *)nd->value;
453 file_data = ggc_alloc_lto_file_decl_data ();
454 memset(file_data, 0, sizeof (struct lto_file_decl_data));
456 file_data->section_hash_table = lto_obj_create_section_hash_table ();;
457 splay_tree_insert (file_ids, id, (splay_tree_value)file_data);
460 /* Copy section into sub module hash table */
461 new_name = XDUPVEC (char, ls->name, strlen (ls->name) + 1);
462 s_slot.name = new_name;
463 hash_slot = htab_find_slot (file_data->section_hash_table, &s_slot, INSERT);
464 gcc_assert (*hash_slot == NULL);
466 new_slot = XDUP (struct lto_section_slot, ls);
467 new_slot->name = new_name;
468 *hash_slot = new_slot;
472 /* Read declarations and other initializations for a FILE_DATA. */
475 lto_file_finalize (struct lto_file_decl_data *file_data, lto_file *file)
480 file_data->renaming_hash_table = lto_create_renaming_table ();
481 file_data->file_name = file->filename;
482 data = lto_get_section_data (file_data, LTO_section_decls, NULL, &len);
485 internal_error ("cannot read LTO decls from %s", file_data->file_name);
488 lto_read_decls (file_data, data, file_data->resolutions);
489 lto_free_section_data (file_data, LTO_section_decls, NULL, data, len);
495 struct lto_file_decl_data **file_data;
499 /* Traverse ids and create a list of file_datas out of it. */
501 static int lto_create_files_from_ids (splay_tree_node node, void *data)
503 struct lwstate *lw = (struct lwstate *)data;
504 struct lto_file_decl_data *file_data = (struct lto_file_decl_data *)node->value;
506 lto_file_finalize (file_data, lw->file);
507 if (cgraph_dump_file)
508 fprintf (cgraph_dump_file, "Creating file %s with sub id %x\n",
509 file_data->file_name, file_data->id);
510 file_data->next = *lw->file_data;
511 *lw->file_data = file_data;
516 /* Generate a TREE representation for all types and external decls
519 Read all of the globals out of the file. Then read the cgraph
520 and process the .o index into the cgraph nodes so that it can open
521 the .o file to load the functions and ipa information. */
523 static struct lto_file_decl_data *
524 lto_file_read (lto_file *file, FILE *resolution_file, int *count)
526 struct lto_file_decl_data *file_data = NULL;
528 htab_t section_hash_table;
529 struct lwstate state;
531 section_hash_table = lto_obj_build_section_table (file);
533 /* Find all sub modules in the object and put their sections into new hash
534 tables in a splay tree. */
535 file_ids = splay_tree_new (splay_tree_compare_ints, NULL, NULL);
536 htab_traverse (section_hash_table, create_subid_section_table, file_ids);
538 /* Add resolutions to file ids */
539 lto_resolution_read (file_ids, resolution_file, file);
541 /* Finalize each lto file for each submodule in the merged object
542 and create list for returning. */
544 state.file_data = &file_data;
546 splay_tree_foreach (file_ids, lto_create_files_from_ids, &state);
548 splay_tree_delete (file_ids);
549 htab_delete (section_hash_table);
554 #if HAVE_MMAP_FILE && HAVE_SYSCONF && defined _SC_PAGE_SIZE
555 #define LTO_MMAP_IO 1
559 /* Page size of machine is used for mmap and munmap calls. */
560 static size_t page_mask;
563 /* Get the section data of length LEN from FILENAME starting at
564 OFFSET. The data segment must be freed by the caller when the
565 caller is finished. Returns NULL if all was not well. */
568 lto_read_section_data (struct lto_file_decl_data *file_data,
569 intptr_t offset, size_t len)
573 static char *fd_name;
575 intptr_t computed_len;
576 intptr_t computed_offset;
580 /* Keep a single-entry file-descriptor cache. The last file we
581 touched will get closed at exit.
582 ??? Eventually we want to add a more sophisticated larger cache
583 or rather fix function body streaming to not stream them in
584 practically random order. */
586 && filename_cmp (fd_name, file_data->file_name) != 0)
594 fd = open (file_data->file_name, O_RDONLY|O_BINARY);
597 fd_name = xstrdup (file_data->file_name);
603 size_t page_size = sysconf (_SC_PAGE_SIZE);
604 page_mask = ~(page_size - 1);
607 computed_offset = offset & page_mask;
608 diff = offset - computed_offset;
609 computed_len = len + diff;
611 result = (char *) mmap (NULL, computed_len, PROT_READ, MAP_PRIVATE,
612 fd, computed_offset);
613 if (result == MAP_FAILED)
616 return result + diff;
618 result = (char *) xmalloc (len);
619 if (lseek (fd, offset, SEEK_SET) != offset
620 || read (fd, result, len) != (ssize_t) len)
626 /* Native windows doesn't supports delayed unlink on opened file. So
627 we close file here again. This produces higher I/O load, but at least
628 it prevents to have dangling file handles preventing unlink. */
639 /* Get the section data from FILE_DATA of SECTION_TYPE with NAME.
640 NAME will be NULL unless the section type is for a function
644 get_section_data (struct lto_file_decl_data *file_data,
645 enum lto_section_type section_type,
649 htab_t section_hash_table = file_data->section_hash_table;
650 struct lto_section_slot *f_slot;
651 struct lto_section_slot s_slot;
652 const char *section_name = lto_get_section_name (section_type, name, file_data);
656 s_slot.name = section_name;
657 f_slot = (struct lto_section_slot *) htab_find (section_hash_table, &s_slot);
660 data = lto_read_section_data (file_data, f_slot->start, f_slot->len);
664 free (CONST_CAST (char *, section_name));
669 /* Free the section data from FILE_DATA of SECTION_TYPE with NAME that
670 starts at OFFSET and has LEN bytes. */
673 free_section_data (struct lto_file_decl_data *file_data ATTRIBUTE_UNUSED,
674 enum lto_section_type section_type ATTRIBUTE_UNUSED,
675 const char *name ATTRIBUTE_UNUSED,
676 const char *offset, size_t len ATTRIBUTE_UNUSED)
679 intptr_t computed_len;
680 intptr_t computed_offset;
685 computed_offset = ((intptr_t) offset) & page_mask;
686 diff = (intptr_t) offset - computed_offset;
687 computed_len = len + diff;
689 munmap ((caddr_t) computed_offset, computed_len);
691 free (CONST_CAST(char *, offset));
695 /* Structure describing ltrans partitions. */
697 struct GTY (()) ltrans_partition_def
699 cgraph_node_set cgraph_set;
700 varpool_node_set varpool_set;
701 const char * GTY ((skip)) name;
705 typedef struct ltrans_partition_def *ltrans_partition;
706 DEF_VEC_P(ltrans_partition);
707 DEF_VEC_ALLOC_P(ltrans_partition,gc);
709 static GTY (()) VEC(ltrans_partition, gc) *ltrans_partitions;
711 static void add_cgraph_node_to_partition (ltrans_partition part, struct cgraph_node *node);
712 static void add_varpool_node_to_partition (ltrans_partition part, struct varpool_node *vnode);
714 /* Create new partition with name NAME. */
715 static ltrans_partition
716 new_partition (const char *name)
718 ltrans_partition part = ggc_alloc_ltrans_partition_def ();
719 part->cgraph_set = cgraph_node_set_new ();
720 part->varpool_set = varpool_node_set_new ();
723 VEC_safe_push (ltrans_partition, gc, ltrans_partitions, part);
727 /* See all references that go to comdat objects and bring them into partition too. */
729 add_references_to_partition (ltrans_partition part, struct ipa_ref_list *refs)
733 for (i = 0; ipa_ref_list_reference_iterate (refs, i, ref); i++)
735 if (ref->refered_type == IPA_REF_CGRAPH
736 && DECL_COMDAT (ipa_ref_node (ref)->decl)
737 && !cgraph_node_in_set_p (ipa_ref_node (ref), part->cgraph_set))
738 add_cgraph_node_to_partition (part, ipa_ref_node (ref));
740 if (ref->refered_type == IPA_REF_VARPOOL
741 && DECL_COMDAT (ipa_ref_varpool_node (ref)->decl)
742 && !varpool_node_in_set_p (ipa_ref_varpool_node (ref), part->varpool_set))
743 add_varpool_node_to_partition (part, ipa_ref_varpool_node (ref));
747 /* Add NODE to partition as well as the inline callees and referred comdats into partition PART. */
750 add_cgraph_node_to_partition (ltrans_partition part, struct cgraph_node *node)
752 struct cgraph_edge *e;
754 part->insns += inline_summary (node)->self_size;
758 node->in_other_partition = 1;
759 if (cgraph_dump_file)
760 fprintf (cgraph_dump_file, "Node %s/%i now used in multiple partitions\n",
761 cgraph_node_name (node), node->uid);
763 node->aux = (void *)((size_t)node->aux + 1);
765 cgraph_node_set_add (part->cgraph_set, node);
767 for (e = node->callees; e; e = e->next_callee)
768 if ((!e->inline_failed || DECL_COMDAT (e->callee->decl))
769 && !cgraph_node_in_set_p (e->callee, part->cgraph_set))
770 add_cgraph_node_to_partition (part, e->callee);
772 add_references_to_partition (part, &node->ref_list);
774 if (node->same_comdat_group
775 && !cgraph_node_in_set_p (node->same_comdat_group, part->cgraph_set))
776 add_cgraph_node_to_partition (part, node->same_comdat_group);
779 /* Add VNODE to partition as well as comdat references partition PART. */
782 add_varpool_node_to_partition (ltrans_partition part, struct varpool_node *vnode)
784 varpool_node_set_add (part->varpool_set, vnode);
788 vnode->in_other_partition = 1;
789 if (cgraph_dump_file)
790 fprintf (cgraph_dump_file, "Varpool node %s now used in multiple partitions\n",
791 varpool_node_name (vnode));
793 vnode->aux = (void *)((size_t)vnode->aux + 1);
795 add_references_to_partition (part, &vnode->ref_list);
797 if (vnode->same_comdat_group
798 && !varpool_node_in_set_p (vnode->same_comdat_group, part->varpool_set))
799 add_varpool_node_to_partition (part, vnode->same_comdat_group);
802 /* Undo all additions until number of cgraph nodes in PARITION is N_CGRAPH_NODES
803 and number of varpool nodes is N_VARPOOL_NODES. */
806 undo_partition (ltrans_partition partition, unsigned int n_cgraph_nodes,
807 unsigned int n_varpool_nodes)
809 while (VEC_length (cgraph_node_ptr, partition->cgraph_set->nodes) >
812 struct cgraph_node *node = VEC_index (cgraph_node_ptr,
813 partition->cgraph_set->nodes,
815 partition->insns -= inline_summary (node)->self_size;
816 cgraph_node_set_remove (partition->cgraph_set, node);
817 node->aux = (void *)((size_t)node->aux - 1);
819 while (VEC_length (varpool_node_ptr, partition->varpool_set->nodes) >
822 struct varpool_node *node = VEC_index (varpool_node_ptr,
823 partition->varpool_set->nodes,
825 varpool_node_set_remove (partition->varpool_set, node);
826 node->aux = (void *)((size_t)node->aux - 1);
830 /* Return true if NODE should be partitioned.
831 This means that partitioning algorithm should put NODE into one of partitions.
832 This apply to most functions with bodies. Functions that are not partitions
833 are put into every unit needing them. This is the case of i.e. COMDATs. */
836 partition_cgraph_node_p (struct cgraph_node *node)
838 /* We will get proper partition based on function they are inlined to. */
839 if (node->global.inlined_to)
841 /* Nodes without a body do not need partitioning. */
844 /* Extern inlines and comdat are always only in partitions they are needed. */
845 if (DECL_EXTERNAL (node->decl)
846 || (DECL_COMDAT (node->decl)
847 && !cgraph_used_from_object_file_p (node)))
849 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (node->decl)))
854 /* Return true if VNODE should be partitioned.
855 This means that partitioning algorithm should put VNODE into one of partitions. */
858 partition_varpool_node_p (struct varpool_node *vnode)
860 if (vnode->alias || !vnode->needed)
862 /* Constant pool and comdat are always only in partitions they are needed. */
863 if (DECL_IN_CONSTANT_POOL (vnode->decl)
864 || (DECL_COMDAT (vnode->decl)
865 && !vnode->force_output
866 && !varpool_used_from_object_file_p (vnode)))
868 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (vnode->decl)))
873 /* Group cgrah nodes by input files. This is used mainly for testing
877 lto_1_to_1_map (void)
879 struct cgraph_node *node;
880 struct varpool_node *vnode;
881 struct lto_file_decl_data *file_data;
882 struct pointer_map_t *pmap;
883 ltrans_partition partition;
887 timevar_push (TV_WHOPR_WPA);
889 pmap = pointer_map_create ();
891 for (node = cgraph_nodes; node; node = node->next)
893 if (!partition_cgraph_node_p (node))
896 file_data = node->local.lto_file_data;
897 gcc_assert (!node->same_body_alias);
901 slot = pointer_map_contains (pmap, file_data);
903 partition = (ltrans_partition) *slot;
906 partition = new_partition (file_data->file_name);
907 slot = pointer_map_insert (pmap, file_data);
913 && VEC_length (ltrans_partition, ltrans_partitions))
914 partition = VEC_index (ltrans_partition, ltrans_partitions, 0);
917 partition = new_partition ("");
918 slot = pointer_map_insert (pmap, NULL);
924 add_cgraph_node_to_partition (partition, node);
927 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
929 if (!partition_varpool_node_p (vnode))
931 file_data = vnode->lto_file_data;
932 slot = pointer_map_contains (pmap, file_data);
934 partition = (ltrans_partition) *slot;
937 partition = new_partition (file_data->file_name);
938 slot = pointer_map_insert (pmap, file_data);
944 add_varpool_node_to_partition (partition, vnode);
946 for (node = cgraph_nodes; node; node = node->next)
948 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
951 /* If the cgraph is empty, create one cgraph node set so that there is still
952 an output file for any variables that need to be exported in a DSO. */
954 new_partition ("empty");
956 pointer_map_destroy (pmap);
958 timevar_pop (TV_WHOPR_WPA);
960 lto_stats.num_cgraph_partitions += VEC_length (ltrans_partition,
965 /* Group cgraph nodes in qually sized partitions.
967 The algorithm deciding paritions are simple: nodes are taken in predefined
968 order. The order correspond to order we wish to have functions in final
969 output. In future this will be given by function reordering pass, but at
970 the moment we use topological order that serve a good approximation.
972 The goal is to partition this linear order into intervals (partitions) such
973 that all partitions have approximately the same size and that the number of
974 callgraph or IPA reference edgess crossing boundaries is minimal.
976 This is a lot faster (O(n) in size of callgraph) than algorithms doing
977 priority based graph clustering that are generally O(n^2) and since WHOPR
978 is designed to make things go well across partitions, it leads to good results.
980 We compute the expected size of partition as
981 max (total_size / lto_partitions, min_partition_size).
982 We use dynamic expected size of partition, so small programs
983 are partitioning into enough partitions to allow use of multiple CPUs while
984 large programs are not partitioned too much. Creating too many partition
985 increase streaming overhead significandly.
987 In the future we would like to bound maximal size of partition to avoid
988 ltrans stage consuming too much memory. At the moment however WPA stage is
989 most memory intensive phase at large benchmark since too many types and
990 declarations are read into memory.
992 The function implement simple greedy algorithm. Nodes are begin added into
993 current partition until 3/4th of expected partition size is reached.
994 After this threshold we keep track of boundary size (number of edges going to
995 other partitions) and continue adding functions until the current partition
996 grows into a double of expected partition size. Then the process is undone
997 till the point when minimal ration of boundary size and in partition calls
1001 lto_balanced_map (void)
1004 struct cgraph_node **postorder =
1005 XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
1006 struct cgraph_node **order = XNEWVEC (struct cgraph_node *, cgraph_max_uid);
1007 int i, postorder_len;
1008 struct cgraph_node *node;
1009 int total_size = 0, best_total_size = 0;
1011 ltrans_partition partition;
1012 unsigned int last_visited_cgraph_node = 0, last_visited_varpool_node = 0;
1013 struct varpool_node *vnode;
1014 int cost = 0, internal = 0;
1015 int best_n_nodes = 0, best_n_varpool_nodes = 0, best_i = 0, best_cost =
1016 INT_MAX, best_internal = 0;
1019 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
1020 gcc_assert (!vnode->aux);
1021 /* Until we have better ordering facility, use toplogical order.
1022 Include only nodes we will partition and compute estimate of program
1023 size. Note that since nodes that are not partitioned might be put into
1024 multiple partitions, this is just an estimate of real size. This is why
1025 we keep partition_size updated after every partition is finalized. */
1026 postorder_len = cgraph_postorder (postorder);
1027 for (i = 0; i < postorder_len; i++)
1029 node = postorder[i];
1030 if (partition_cgraph_node_p (node))
1032 order[n_nodes++] = node;
1033 total_size += node->global.size;
1038 /* Compute partition size and create the first partition. */
1039 partition_size = total_size / PARAM_VALUE (PARAM_LTO_PARTITIONS);
1040 if (partition_size < PARAM_VALUE (MIN_PARTITION_SIZE))
1041 partition_size = PARAM_VALUE (MIN_PARTITION_SIZE);
1043 partition = new_partition ("");
1044 if (cgraph_dump_file)
1045 fprintf (cgraph_dump_file, "Total unit size: %i, partition size: %i\n",
1046 total_size, partition_size);
1048 for (i = 0; i < n_nodes; i++)
1051 add_cgraph_node_to_partition (partition, order[i]);
1052 total_size -= order[i]->global.size;
1054 /* Once we added a new node to the partition, we also want to add
1055 all referenced variables unless they was already added into some
1057 add_cgraph_node_to_partition adds possibly multiple nodes and
1058 variables that are needed to satisfy needs of ORDER[i].
1059 We remember last visited cgraph and varpool node from last iteration
1060 of outer loop that allows us to process every new addition.
1062 At the same time we compute size of the boundary into COST. Every
1063 callgraph or IPA reference edge leaving the partition contributes into
1064 COST. Every edge inside partition was earlier computed as one leaving
1065 it and thus we need to subtract it from COST. */
1066 while (last_visited_cgraph_node <
1067 VEC_length (cgraph_node_ptr, partition->cgraph_set->nodes)
1068 || last_visited_varpool_node < VEC_length (varpool_node_ptr,
1069 partition->varpool_set->
1072 struct ipa_ref_list *refs;
1074 struct ipa_ref *ref;
1075 bool cgraph_p = false;
1077 if (last_visited_cgraph_node <
1078 VEC_length (cgraph_node_ptr, partition->cgraph_set->nodes))
1080 struct cgraph_edge *edge;
1083 node = VEC_index (cgraph_node_ptr, partition->cgraph_set->nodes,
1084 last_visited_cgraph_node);
1085 refs = &node->ref_list;
1087 last_visited_cgraph_node++;
1089 gcc_assert (node->analyzed);
1091 /* Compute boundary cost of callgrpah edges. */
1092 for (edge = node->callees; edge; edge = edge->next_callee)
1093 if (edge->callee->analyzed)
1095 int edge_cost = edge->frequency;
1096 cgraph_node_set_iterator csi;
1100 gcc_assert (edge_cost > 0);
1101 csi = cgraph_node_set_find (partition->cgraph_set, edge->callee);
1102 if (!csi_end_p (csi)
1103 && csi.index < last_visited_cgraph_node - 1)
1104 cost -= edge_cost, internal+= edge_cost;
1108 for (edge = node->callers; edge; edge = edge->next_caller)
1110 int edge_cost = edge->frequency;
1111 cgraph_node_set_iterator csi;
1113 gcc_assert (edge->caller->analyzed);
1116 gcc_assert (edge_cost > 0);
1117 csi = cgraph_node_set_find (partition->cgraph_set, edge->caller);
1118 if (!csi_end_p (csi)
1119 && csi.index < last_visited_cgraph_node)
1128 &VEC_index (varpool_node_ptr, partition->varpool_set->nodes,
1129 last_visited_varpool_node)->ref_list;
1130 last_visited_varpool_node++;
1133 /* Compute boundary cost of IPA REF edges and at the same time look into
1134 variables referenced from current partition and try to add them. */
1135 for (j = 0; ipa_ref_list_reference_iterate (refs, j, ref); j++)
1136 if (ref->refered_type == IPA_REF_VARPOOL)
1138 varpool_node_set_iterator vsi;
1140 vnode = ipa_ref_varpool_node (ref);
1141 if (!vnode->finalized)
1143 if (!vnode->aux && partition_varpool_node_p (vnode))
1144 add_varpool_node_to_partition (partition, vnode);
1145 vsi = varpool_node_set_find (partition->varpool_set, vnode);
1146 if (!vsi_end_p (vsi)
1147 && vsi.index < last_visited_varpool_node - !cgraph_p)
1154 cgraph_node_set_iterator csi;
1156 node = ipa_ref_node (ref);
1157 if (!node->analyzed)
1159 csi = cgraph_node_set_find (partition->cgraph_set, node);
1160 if (!csi_end_p (csi)
1161 && csi.index < last_visited_cgraph_node - cgraph_p)
1166 for (j = 0; ipa_ref_list_refering_iterate (refs, j, ref); j++)
1167 if (ref->refering_type == IPA_REF_VARPOOL)
1169 varpool_node_set_iterator vsi;
1171 vnode = ipa_ref_refering_varpool_node (ref);
1172 gcc_assert (vnode->finalized);
1173 if (!vnode->aux && partition_varpool_node_p (vnode))
1174 add_varpool_node_to_partition (partition, vnode);
1175 vsi = varpool_node_set_find (partition->varpool_set, vnode);
1176 if (!vsi_end_p (vsi)
1177 && vsi.index < last_visited_varpool_node)
1184 cgraph_node_set_iterator csi;
1186 node = ipa_ref_refering_node (ref);
1187 gcc_assert (node->analyzed);
1188 csi = cgraph_node_set_find (partition->cgraph_set, node);
1189 if (!csi_end_p (csi)
1190 && csi.index < last_visited_cgraph_node)
1197 /* If the partition is large enough, start looking for smallest boundary cost. */
1198 if (partition->insns < partition_size * 3 / 4
1199 || best_cost == INT_MAX
1201 || (best_internal * (HOST_WIDE_INT) cost
1202 > (internal * (HOST_WIDE_INT)best_cost)))
1203 && partition->insns < partition_size * 5 / 4))
1206 best_internal = internal;
1208 best_n_nodes = VEC_length (cgraph_node_ptr,
1209 partition->cgraph_set->nodes);
1210 best_n_varpool_nodes = VEC_length (varpool_node_ptr,
1211 partition->varpool_set->nodes);
1212 best_total_size = total_size;
1214 if (cgraph_dump_file)
1215 fprintf (cgraph_dump_file, "Step %i: added %s/%i, size %i, cost %i/%i best %i/%i, step %i\n", i,
1216 cgraph_node_name (order[i]), order[i]->uid, partition->insns, cost, internal,
1217 best_cost, best_internal, best_i);
1218 /* Partition is too large, unwind into step when best cost was reached and
1219 start new partition. */
1220 if (partition->insns > 2 * partition_size)
1224 if (cgraph_dump_file)
1225 fprintf (cgraph_dump_file, "Unwinding %i insertions to step %i\n",
1226 i - best_i, best_i);
1227 undo_partition (partition, best_n_nodes, best_n_varpool_nodes);
1230 /* When we are finished, avoid creating empty partition. */
1231 if (i == n_nodes - 1)
1233 partition = new_partition ("");
1234 last_visited_cgraph_node = 0;
1235 last_visited_varpool_node = 0;
1236 total_size = best_total_size;
1239 if (cgraph_dump_file)
1240 fprintf (cgraph_dump_file, "New partition\n");
1242 best_n_varpool_nodes = 0;
1243 best_cost = INT_MAX;
1245 /* Since the size of partitions is just approximate, update the size after
1246 we finished current one. */
1247 if (npartitions < PARAM_VALUE (PARAM_LTO_PARTITIONS))
1248 partition_size = total_size
1249 / (PARAM_VALUE (PARAM_LTO_PARTITIONS) - npartitions);
1251 partition_size = INT_MAX;
1253 if (partition_size < PARAM_VALUE (MIN_PARTITION_SIZE))
1254 partition_size = PARAM_VALUE (MIN_PARTITION_SIZE);
1259 /* Varables that are not reachable from the code go into last partition. */
1260 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
1261 if (partition_varpool_node_p (vnode) && !vnode->aux)
1262 add_varpool_node_to_partition (partition, vnode);
1266 /* Promote variable VNODE to be static. */
1269 promote_var (struct varpool_node *vnode)
1271 if (TREE_PUBLIC (vnode->decl) || DECL_EXTERNAL (vnode->decl))
1273 gcc_assert (flag_wpa);
1274 TREE_PUBLIC (vnode->decl) = 1;
1275 DECL_VISIBILITY (vnode->decl) = VISIBILITY_HIDDEN;
1276 DECL_VISIBILITY_SPECIFIED (vnode->decl) = true;
1277 if (cgraph_dump_file)
1278 fprintf (cgraph_dump_file,
1279 "Promoting var as hidden: %s\n", varpool_node_name (vnode));
1283 /* Promote function NODE to be static. */
1286 promote_fn (struct cgraph_node *node)
1288 gcc_assert (flag_wpa);
1289 if (TREE_PUBLIC (node->decl) || DECL_EXTERNAL (node->decl))
1291 TREE_PUBLIC (node->decl) = 1;
1292 DECL_VISIBILITY (node->decl) = VISIBILITY_HIDDEN;
1293 DECL_VISIBILITY_SPECIFIED (node->decl) = true;
1294 if (node->same_body)
1296 struct cgraph_node *alias;
1297 for (alias = node->same_body;
1298 alias; alias = alias->next)
1300 TREE_PUBLIC (alias->decl) = 1;
1301 DECL_VISIBILITY (alias->decl) = VISIBILITY_HIDDEN;
1302 DECL_VISIBILITY_SPECIFIED (alias->decl) = true;
1305 if (cgraph_dump_file)
1306 fprintf (cgraph_dump_file,
1307 "Promoting function as hidden: %s/%i\n",
1308 cgraph_node_name (node), node->uid);
1312 /* Find out all static decls that need to be promoted to global because
1313 of cross file sharing. This function must be run in the WPA mode after
1314 all inlinees are added. */
1317 lto_promote_cross_file_statics (void)
1319 struct varpool_node *vnode;
1321 cgraph_node_set set;
1322 varpool_node_set vset;
1323 cgraph_node_set_iterator csi;
1324 varpool_node_set_iterator vsi;
1325 VEC(varpool_node_ptr, heap) *promoted_initializers = NULL;
1326 struct pointer_set_t *inserted = pointer_set_create ();
1328 gcc_assert (flag_wpa);
1330 n_sets = VEC_length (ltrans_partition, ltrans_partitions);
1331 for (i = 0; i < n_sets; i++)
1333 ltrans_partition part = VEC_index (ltrans_partition, ltrans_partitions, i);
1334 set = part->cgraph_set;
1335 vset = part->varpool_set;
1337 /* If node has either address taken (and we have no clue from where)
1338 or it is called from other partition, it needs to be globalized. */
1339 for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
1341 struct cgraph_node *node = csi_node (csi);
1342 if (node->local.externally_visible)
1344 if (node->global.inlined_to)
1346 if ((!DECL_EXTERNAL (node->decl) && !DECL_COMDAT (node->decl))
1347 && (referenced_from_other_partition_p (&node->ref_list, set, vset)
1348 || reachable_from_other_partition_p (node, set)))
1351 for (vsi = vsi_start (vset); !vsi_end_p (vsi); vsi_next (&vsi))
1353 vnode = vsi_node (vsi);
1354 /* Constant pool references use internal labels and thus can not
1355 be made global. It is sensible to keep those ltrans local to
1356 allow better optimization. */
1357 if (!DECL_IN_CONSTANT_POOL (vnode->decl) && !DECL_COMDAT (vnode->decl)
1358 && !vnode->externally_visible && vnode->analyzed
1359 && referenced_from_other_partition_p (&vnode->ref_list,
1361 promote_var (vnode);
1364 /* We export initializers of read-only var into each partition
1365 referencing it. Folding might take declarations from the
1366 initializers and use it; so everything referenced from the
1367 initializers needs can be accessed from this partition after
1370 This means that we need to promote all variables and functions
1371 referenced from all initializers from readonly vars referenced
1372 from this partition that are not in this partition.
1373 This needs to be done recursively. */
1374 for (vnode = varpool_nodes; vnode; vnode = vnode->next)
1375 if (const_value_known_p (vnode->decl)
1376 && DECL_INITIAL (vnode->decl)
1377 && !varpool_node_in_set_p (vnode, vset)
1378 && referenced_from_this_partition_p (&vnode->ref_list, set, vset)
1379 && !pointer_set_insert (inserted, vnode))
1380 VEC_safe_push (varpool_node_ptr, heap, promoted_initializers, vnode);
1381 while (!VEC_empty (varpool_node_ptr, promoted_initializers))
1384 struct ipa_ref *ref;
1386 vnode = VEC_pop (varpool_node_ptr, promoted_initializers);
1387 for (i = 0; ipa_ref_list_reference_iterate (&vnode->ref_list, i, ref); i++)
1389 if (ref->refered_type == IPA_REF_CGRAPH)
1391 struct cgraph_node *n = ipa_ref_node (ref);
1392 gcc_assert (!n->global.inlined_to);
1393 if (!n->local.externally_visible
1394 && !cgraph_node_in_set_p (n, set))
1399 struct varpool_node *v = ipa_ref_varpool_node (ref);
1400 if (varpool_node_in_set_p (v, vset))
1402 /* Constant pool references use internal labels and thus can not
1403 be made global. It is sensible to keep those ltrans local to
1404 allow better optimization. */
1405 if (DECL_IN_CONSTANT_POOL (v->decl))
1407 if (!pointer_set_insert (inserted, vnode))
1408 VEC_safe_push (varpool_node_ptr, heap,
1409 promoted_initializers, v);
1411 else if (!DECL_IN_CONSTANT_POOL (v->decl)
1412 && !v->externally_visible && v->analyzed)
1415 && DECL_INITIAL (v->decl)
1416 && const_value_known_p (v->decl)
1417 && !pointer_set_insert (inserted, vnode))
1418 VEC_safe_push (varpool_node_ptr, heap,
1419 promoted_initializers, v);
1425 pointer_set_destroy (inserted);
1428 static lto_file *current_lto_file;
1430 /* Helper for qsort; compare partitions and return one with smaller size.
1431 We sort from greatest to smallest so parallel build doesn't stale on the
1432 longest compilation being executed too late. */
1435 cmp_partitions (const void *a, const void *b)
1437 const struct ltrans_partition_def *pa
1438 = *(struct ltrans_partition_def *const *)a;
1439 const struct ltrans_partition_def *pb
1440 = *(struct ltrans_partition_def *const *)b;
1441 return pb->insns - pa->insns;
1444 /* Write all output files in WPA mode and the file with the list of
1448 lto_wpa_write_files (void)
1452 cgraph_node_set set;
1453 varpool_node_set vset;
1454 ltrans_partition part;
1455 FILE *ltrans_output_list_stream;
1456 char *temp_filename;
1459 /* Open the LTRANS output list. */
1460 if (!ltrans_output_list)
1461 fatal_error ("no LTRANS output list filename provided");
1462 ltrans_output_list_stream = fopen (ltrans_output_list, "w");
1463 if (ltrans_output_list_stream == NULL)
1464 fatal_error ("opening LTRANS output list %s: %m", ltrans_output_list);
1466 timevar_push (TV_WHOPR_WPA);
1468 FOR_EACH_VEC_ELT (ltrans_partition, ltrans_partitions, i, part)
1469 lto_stats.num_output_cgraph_nodes += VEC_length (cgraph_node_ptr,
1470 part->cgraph_set->nodes);
1472 /* Find out statics that need to be promoted
1473 to globals with hidden visibility because they are accessed from multiple
1475 lto_promote_cross_file_statics ();
1477 timevar_pop (TV_WHOPR_WPA);
1479 timevar_push (TV_WHOPR_WPA_IO);
1481 /* Generate a prefix for the LTRANS unit files. */
1482 blen = strlen (ltrans_output_list);
1483 temp_filename = (char *) xmalloc (blen + sizeof ("2147483648.o"));
1484 strcpy (temp_filename, ltrans_output_list);
1485 if (blen > sizeof (".out")
1486 && strcmp (temp_filename + blen - sizeof (".out") + 1,
1488 temp_filename[blen - sizeof (".out") + 1] = '\0';
1489 blen = strlen (temp_filename);
1491 n_sets = VEC_length (ltrans_partition, ltrans_partitions);
1492 VEC_qsort (ltrans_partition, ltrans_partitions, cmp_partitions);
1493 for (i = 0; i < n_sets; i++)
1496 ltrans_partition part = VEC_index (ltrans_partition, ltrans_partitions, i);
1498 set = part->cgraph_set;
1499 vset = part->varpool_set;
1501 /* Write all the nodes in SET. */
1502 sprintf (temp_filename + blen, "%u.o", i);
1503 file = lto_obj_file_open (temp_filename, true);
1505 fatal_error ("lto_obj_file_open() failed");
1508 fprintf (stderr, " %s (%s %i insns)", temp_filename, part->name, part->insns);
1509 if (cgraph_dump_file)
1511 fprintf (cgraph_dump_file, "Writting partition %s to file %s, %i insns\n",
1512 part->name, temp_filename, part->insns);
1513 fprintf (cgraph_dump_file, "cgraph nodes:");
1514 dump_cgraph_node_set (cgraph_dump_file, set);
1515 fprintf (cgraph_dump_file, "varpool nodes:");
1516 dump_varpool_node_set (cgraph_dump_file, vset);
1518 gcc_checking_assert (cgraph_node_set_nonempty_p (set)
1519 || varpool_node_set_nonempty_p (vset) || !i);
1521 lto_set_current_out_file (file);
1523 ipa_write_optimization_summaries (set, vset);
1525 lto_set_current_out_file (NULL);
1526 lto_obj_file_close (file);
1528 len = strlen (temp_filename);
1529 if (fwrite (temp_filename, 1, len, ltrans_output_list_stream) < len
1530 || fwrite ("\n", 1, 1, ltrans_output_list_stream) < 1)
1531 fatal_error ("writing to LTRANS output list %s: %m",
1532 ltrans_output_list);
1535 lto_stats.num_output_files += n_sets;
1537 /* Close the LTRANS output list. */
1538 if (fclose (ltrans_output_list_stream))
1539 fatal_error ("closing LTRANS output list %s: %m", ltrans_output_list);
1541 timevar_pop (TV_WHOPR_WPA_IO);
1546 struct pointer_set_t *seen;
1549 #define LTO_FIXUP_SUBTREE(t) \
1551 walk_tree (&(t), lto_fixup_tree, data, NULL); \
1554 #define LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE(t) \
1558 (t) = gimple_register_type (t); \
1559 walk_tree (&(t), lto_fixup_tree, data, NULL); \
1563 static tree lto_fixup_tree (tree *, int *, void *);
1565 /* Return true if T does not need to be fixed up recursively. */
1571 || CONSTANT_CLASS_P (t)
1572 || TREE_CODE (t) == IDENTIFIER_NODE);
1575 /* Fix up fields of a tree_common T. DATA points to fix-up states. */
1578 lto_fixup_common (tree t, void *data)
1580 /* The following re-creates the TYPE_REFERENCE_TO and TYPE_POINTER_TO
1581 lists. We do not stream TYPE_REFERENCE_TO, TYPE_POINTER_TO or
1582 TYPE_NEXT_PTR_TO and TYPE_NEXT_REF_TO.
1583 First remove us from any pointer list we are on. */
1584 if (TREE_CODE (t) == POINTER_TYPE)
1586 if (TYPE_POINTER_TO (TREE_TYPE (t)) == t)
1587 TYPE_POINTER_TO (TREE_TYPE (t)) = TYPE_NEXT_PTR_TO (t);
1590 tree tem = TYPE_POINTER_TO (TREE_TYPE (t));
1591 while (tem && TYPE_NEXT_PTR_TO (tem) != t)
1592 tem = TYPE_NEXT_PTR_TO (tem);
1594 TYPE_NEXT_PTR_TO (tem) = TYPE_NEXT_PTR_TO (t);
1596 TYPE_NEXT_PTR_TO (t) = NULL_TREE;
1598 else if (TREE_CODE (t) == REFERENCE_TYPE)
1600 if (TYPE_REFERENCE_TO (TREE_TYPE (t)) == t)
1601 TYPE_REFERENCE_TO (TREE_TYPE (t)) = TYPE_NEXT_REF_TO (t);
1604 tree tem = TYPE_REFERENCE_TO (TREE_TYPE (t));
1605 while (tem && TYPE_NEXT_REF_TO (tem) != t)
1606 tem = TYPE_NEXT_REF_TO (tem);
1608 TYPE_NEXT_REF_TO (tem) = TYPE_NEXT_REF_TO (t);
1610 TYPE_NEXT_REF_TO (t) = NULL_TREE;
1613 /* Fixup our type. */
1614 LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TREE_TYPE (t));
1616 /* Second put us on the list of pointers of the new pointed-to type
1617 if we are a main variant. This is done in lto_fixup_type after
1618 fixing up our main variant. */
1620 /* This is not very efficient because we cannot do tail-recursion with
1621 a long chain of trees. */
1622 if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_COMMON))
1623 LTO_FIXUP_SUBTREE (TREE_CHAIN (t));
1626 /* Fix up fields of a decl_minimal T. DATA points to fix-up states. */
1629 lto_fixup_decl_minimal (tree t, void *data)
1631 lto_fixup_common (t, data);
1632 LTO_FIXUP_SUBTREE (DECL_NAME (t));
1633 LTO_FIXUP_SUBTREE (DECL_CONTEXT (t));
1636 /* Fix up fields of a decl_common T. DATA points to fix-up states. */
1639 lto_fixup_decl_common (tree t, void *data)
1641 lto_fixup_decl_minimal (t, data);
1642 LTO_FIXUP_SUBTREE (DECL_SIZE (t));
1643 LTO_FIXUP_SUBTREE (DECL_SIZE_UNIT (t));
1644 LTO_FIXUP_SUBTREE (DECL_INITIAL (t));
1645 LTO_FIXUP_SUBTREE (DECL_ATTRIBUTES (t));
1646 LTO_FIXUP_SUBTREE (DECL_ABSTRACT_ORIGIN (t));
1649 /* Fix up fields of a decl_with_vis T. DATA points to fix-up states. */
1652 lto_fixup_decl_with_vis (tree t, void *data)
1654 lto_fixup_decl_common (t, data);
1656 /* Accessor macro has side-effects, use field-name here. */
1657 LTO_FIXUP_SUBTREE (t->decl_with_vis.assembler_name);
1659 gcc_assert (no_fixup_p (DECL_SECTION_NAME (t)));
1662 /* Fix up fields of a decl_non_common T. DATA points to fix-up states. */
1665 lto_fixup_decl_non_common (tree t, void *data)
1667 lto_fixup_decl_with_vis (t, data);
1668 LTO_FIXUP_SUBTREE (DECL_ARGUMENT_FLD (t));
1669 LTO_FIXUP_SUBTREE (DECL_RESULT_FLD (t));
1670 LTO_FIXUP_SUBTREE (DECL_VINDEX (t));
1672 /* SAVED_TREE should not cleared by now. Also no accessor for base type. */
1673 gcc_assert (no_fixup_p (t->decl_non_common.saved_tree));
1676 /* Fix up fields of a decl_non_common T. DATA points to fix-up states. */
1679 lto_fixup_function (tree t, void *data)
1681 lto_fixup_decl_non_common (t, data);
1682 LTO_FIXUP_SUBTREE (DECL_FUNCTION_PERSONALITY (t));
1685 /* Fix up fields of a field_decl T. DATA points to fix-up states. */
1688 lto_fixup_field_decl (tree t, void *data)
1690 lto_fixup_decl_common (t, data);
1691 LTO_FIXUP_SUBTREE (DECL_FIELD_OFFSET (t));
1692 LTO_FIXUP_SUBTREE (DECL_BIT_FIELD_TYPE (t));
1693 LTO_FIXUP_SUBTREE (DECL_QUALIFIER (t));
1694 gcc_assert (no_fixup_p (DECL_FIELD_BIT_OFFSET (t)));
1695 LTO_FIXUP_SUBTREE (DECL_FCONTEXT (t));
1698 /* Fix up fields of a type T. DATA points to fix-up states. */
1701 lto_fixup_type (tree t, void *data)
1705 lto_fixup_common (t, data);
1706 LTO_FIXUP_SUBTREE (TYPE_CACHED_VALUES (t));
1707 LTO_FIXUP_SUBTREE (TYPE_SIZE (t));
1708 LTO_FIXUP_SUBTREE (TYPE_SIZE_UNIT (t));
1709 LTO_FIXUP_SUBTREE (TYPE_ATTRIBUTES (t));
1710 LTO_FIXUP_SUBTREE (TYPE_NAME (t));
1712 /* Accessors are for derived node types only. */
1713 if (!POINTER_TYPE_P (t))
1714 LTO_FIXUP_SUBTREE (t->type.minval);
1715 LTO_FIXUP_SUBTREE (t->type.maxval);
1717 /* Accessor is for derived node types only. */
1718 LTO_FIXUP_SUBTREE (t->type.binfo);
1720 if (TYPE_CONTEXT (t))
1722 if (TYPE_P (TYPE_CONTEXT (t)))
1723 LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TYPE_CONTEXT (t));
1725 LTO_FIXUP_SUBTREE (TYPE_CONTEXT (t));
1728 /* Compute the canonical type of t and fix that up. From this point
1729 there are no longer any types with TYPE_STRUCTURAL_EQUALITY_P
1730 and its type-based alias problems. */
1731 if (!TYPE_CANONICAL (t))
1733 TYPE_CANONICAL (t) = gimple_register_canonical_type (t);
1734 LTO_FIXUP_SUBTREE (TYPE_CANONICAL (t));
1737 /* The following re-creates proper variant lists while fixing up
1738 the variant leaders. We do not stream TYPE_NEXT_VARIANT so the
1739 variant list state before fixup is broken. */
1741 /* Remove us from our main variant list if we are not the variant leader. */
1742 if (TYPE_MAIN_VARIANT (t) != t)
1744 tem = TYPE_MAIN_VARIANT (t);
1745 while (tem && TYPE_NEXT_VARIANT (tem) != t)
1746 tem = TYPE_NEXT_VARIANT (tem);
1748 TYPE_NEXT_VARIANT (tem) = TYPE_NEXT_VARIANT (t);
1749 TYPE_NEXT_VARIANT (t) = NULL_TREE;
1752 /* Query our new main variant. */
1753 mv = gimple_register_type (TYPE_MAIN_VARIANT (t));
1755 /* If we were the variant leader and we get replaced ourselves drop
1756 all variants from our list. */
1757 if (TYPE_MAIN_VARIANT (t) == t
1763 tree tem2 = TYPE_NEXT_VARIANT (tem);
1764 TYPE_NEXT_VARIANT (tem) = NULL_TREE;
1769 /* If we are not our own variant leader link us into our new leaders
1773 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
1774 TYPE_NEXT_VARIANT (mv) = t;
1777 /* Finally adjust our main variant and fix it up. */
1778 TYPE_MAIN_VARIANT (t) = mv;
1779 LTO_FIXUP_SUBTREE (TYPE_MAIN_VARIANT (t));
1781 /* As the second step of reconstructing the pointer chains put us
1782 on the list of pointers of the new pointed-to type
1783 if we are a main variant. See lto_fixup_common for the first step. */
1784 if (TREE_CODE (t) == POINTER_TYPE
1785 && TYPE_MAIN_VARIANT (t) == t)
1787 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (TREE_TYPE (t));
1788 TYPE_POINTER_TO (TREE_TYPE (t)) = t;
1790 else if (TREE_CODE (t) == REFERENCE_TYPE
1791 && TYPE_MAIN_VARIANT (t) == t)
1793 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (TREE_TYPE (t));
1794 TYPE_REFERENCE_TO (TREE_TYPE (t)) = t;
1798 /* Fix up fields of a BINFO T. DATA points to fix-up states. */
1801 lto_fixup_binfo (tree t, void *data)
1803 unsigned HOST_WIDE_INT i, n;
1804 tree base, saved_base;
1806 lto_fixup_common (t, data);
1807 gcc_assert (no_fixup_p (BINFO_OFFSET (t)));
1808 LTO_FIXUP_SUBTREE (BINFO_VTABLE (t));
1809 LTO_FIXUP_SUBTREE (BINFO_VIRTUALS (t));
1810 LTO_FIXUP_SUBTREE (BINFO_VPTR_FIELD (t));
1811 n = VEC_length (tree, BINFO_BASE_ACCESSES (t));
1812 for (i = 0; i < n; i++)
1814 saved_base = base = BINFO_BASE_ACCESS (t, i);
1815 LTO_FIXUP_SUBTREE (base);
1816 if (base != saved_base)
1817 VEC_replace (tree, BINFO_BASE_ACCESSES (t), i, base);
1819 LTO_FIXUP_SUBTREE (BINFO_INHERITANCE_CHAIN (t));
1820 LTO_FIXUP_SUBTREE (BINFO_SUBVTT_INDEX (t));
1821 LTO_FIXUP_SUBTREE (BINFO_VPTR_INDEX (t));
1822 n = BINFO_N_BASE_BINFOS (t);
1823 for (i = 0; i < n; i++)
1825 saved_base = base = BINFO_BASE_BINFO (t, i);
1826 LTO_FIXUP_SUBTREE (base);
1827 if (base != saved_base)
1828 VEC_replace (tree, BINFO_BASE_BINFOS (t), i, base);
1832 /* Fix up fields of a CONSTRUCTOR T. DATA points to fix-up states. */
1835 lto_fixup_constructor (tree t, void *data)
1837 unsigned HOST_WIDE_INT idx;
1838 constructor_elt *ce;
1840 LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TREE_TYPE (t));
1843 VEC_iterate(constructor_elt, CONSTRUCTOR_ELTS (t), idx, ce);
1846 LTO_FIXUP_SUBTREE (ce->index);
1847 LTO_FIXUP_SUBTREE (ce->value);
1851 /* A walk_tree callback used by lto_fixup_state. TP is the pointer to the
1852 current tree. WALK_SUBTREES indicates if the subtrees will be walked.
1853 DATA is a pointer set to record visited nodes. */
1856 lto_fixup_tree (tree *tp, int *walk_subtrees, void *data)
1859 lto_fixup_data_t *fixup_data = (lto_fixup_data_t *) data;
1864 if (!t || pointer_set_contains (fixup_data->seen, t))
1867 if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == FUNCTION_DECL)
1869 prevailing = lto_symtab_prevailing_decl (t);
1871 if (t != prevailing)
1873 /* Also replace t with prevailing defintion. We don't want to
1874 insert the other defintion in the seen set as we want to
1875 replace all instances of it. */
1880 else if (TYPE_P (t))
1882 /* Replace t with the prevailing type. We don't want to insert the
1883 other type in the seen set as we want to replace all instances of it. */
1884 t = gimple_register_type (t);
1888 if (pointer_set_insert (fixup_data->seen, t))
1891 /* walk_tree does not visit all reachable nodes that need to be fixed up.
1892 Hence we do special processing here for those kind of nodes. */
1893 switch (TREE_CODE (t))
1896 lto_fixup_field_decl (t, data);
1904 lto_fixup_decl_common (t, data);
1908 lto_fixup_decl_with_vis (t, data);
1912 lto_fixup_decl_non_common (t, data);
1916 lto_fixup_function (t, data);
1920 lto_fixup_binfo (t, data);
1925 lto_fixup_type (t, data);
1926 else if (TREE_CODE (t) == CONSTRUCTOR)
1927 lto_fixup_constructor (t, data);
1928 else if (CONSTANT_CLASS_P (t))
1929 LTO_REGISTER_TYPE_AND_FIXUP_SUBTREE (TREE_TYPE (t));
1930 else if (EXPR_P (t))
1932 /* walk_tree only handles TREE_OPERANDs. Do the rest here. */
1933 lto_fixup_common (t, data);
1934 LTO_FIXUP_SUBTREE (t->exp.block);
1939 /* Let walk_tree handle sub-trees. */
1947 /* Helper function of lto_fixup_decls. Walks the var and fn streams in STATE,
1948 replaces var and function decls with the corresponding prevailing def and
1949 records the old decl in the free-list in DATA. We also record visted nodes
1950 in the seen-set in DATA to avoid multiple visit for nodes that need not
1954 lto_fixup_state (struct lto_in_decl_state *state, lto_fixup_data_t *data)
1957 struct lto_tree_ref_table *table;
1959 /* Although we only want to replace FUNCTION_DECLs and VAR_DECLs,
1960 we still need to walk from all DECLs to find the reachable
1961 FUNCTION_DECLs and VAR_DECLs. */
1962 for (si = 0; si < LTO_N_DECL_STREAMS; si++)
1964 table = &state->streams[si];
1965 for (i = 0; i < table->size; i++)
1966 walk_tree (table->trees + i, lto_fixup_tree, data, NULL);
1970 /* A callback of htab_traverse. Just extract a state from SLOT and the
1971 lto_fixup_data_t object from AUX and calls lto_fixup_state. */
1974 lto_fixup_state_aux (void **slot, void *aux)
1976 struct lto_in_decl_state *state = (struct lto_in_decl_state *) *slot;
1977 lto_fixup_state (state, (lto_fixup_data_t *) aux);
1981 /* Fix the decls from all FILES. Replaces each decl with the corresponding
1985 lto_fixup_decls (struct lto_file_decl_data **files)
1989 struct pointer_set_t *seen = pointer_set_create ();
1990 lto_fixup_data_t data;
1993 for (i = 0; files[i]; i++)
1995 struct lto_file_decl_data *file = files[i];
1996 struct lto_in_decl_state *state = file->global_decl_state;
1997 lto_fixup_state (state, &data);
1999 htab_traverse (file->function_decl_states, lto_fixup_state_aux, &data);
2002 FOR_EACH_VEC_ELT (tree, lto_global_var_decls, i, decl)
2004 tree saved_decl = decl;
2005 walk_tree (&decl, lto_fixup_tree, &data, NULL);
2006 if (decl != saved_decl)
2007 VEC_replace (tree, lto_global_var_decls, i, decl);
2010 pointer_set_destroy (seen);
2013 /* Read the options saved from each file in the command line. Called
2014 from lang_hooks.post_options which is called by process_options
2015 right before all the options are used to initialize the compiler.
2016 This assumes that decode_options has already run, so the
2017 num_in_fnames and in_fnames are properly set.
2019 Note that this assumes that all the files had been compiled with
2020 the same options, which is not a good assumption. In general,
2021 options ought to be read from all the files in the set and merged.
2022 However, it is still unclear what the merge rules should be. */
2025 lto_read_all_file_options (void)
2029 /* Clear any file options currently saved. */
2030 lto_clear_file_options ();
2032 /* Set the hooks to read ELF sections. */
2033 lto_set_in_hooks (NULL, get_section_data, free_section_data);
2035 fprintf (stderr, "Reading command line options:");
2037 for (i = 0; i < num_in_fnames; i++)
2039 struct lto_file_decl_data *file_data;
2040 lto_file *file = lto_obj_file_open (in_fnames[i], false);
2045 fprintf (stderr, " %s", in_fnames[i]);
2049 file_data = XCNEW (struct lto_file_decl_data);
2050 file_data->file_name = file->filename;
2051 file_data->section_hash_table = lto_obj_build_section_table (file);
2053 lto_read_file_options (file_data);
2055 lto_obj_file_close (file);
2056 htab_delete (file_data->section_hash_table);
2061 fprintf (stderr, "\n");
2063 /* Apply globally the options read from all the files. */
2064 lto_reissue_options ();
2067 static GTY((length ("lto_stats.num_input_files + 1"))) struct lto_file_decl_data **all_file_decl_data;
2069 /* Turn file datas for sub files into a single array, so that they look
2070 like separate files for further passes. */
2073 lto_flatten_files (struct lto_file_decl_data **orig, int count, int last_file_ix)
2075 struct lto_file_decl_data *n, *next;
2078 lto_stats.num_input_files = count;
2080 = ggc_alloc_cleared_vec_lto_file_decl_data_ptr (count + 1);
2081 /* Set the hooks so that all of the ipa passes can read in their data. */
2082 lto_set_in_hooks (all_file_decl_data, get_section_data, free_section_data);
2083 for (i = 0, k = 0; i < last_file_ix; i++)
2085 for (n = orig[i]; n != NULL; n = next)
2087 all_file_decl_data[k++] = n;
2092 all_file_decl_data[k] = NULL;
2093 gcc_assert (k == count);
2096 /* Input file data before flattening (i.e. splitting them to subfiles to support
2097 incremental linking. */
2098 static int real_file_count;
2099 static GTY((length ("real_file_count + 1"))) struct lto_file_decl_data **real_file_decl_data;
2101 /* Read all the symbols from the input files FNAMES. NFILES is the
2102 number of files requested in the command line. Instantiate a
2103 global call graph by aggregating all the sub-graphs found in each
2107 read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
2109 unsigned int i, last_file_ix;
2111 struct cgraph_node *node;
2113 struct lto_file_decl_data **decl_data;
2117 timevar_push (TV_IPA_LTO_DECL_IN);
2120 = decl_data = ggc_alloc_cleared_vec_lto_file_decl_data_ptr (nfiles + 1);
2121 real_file_count = nfiles;
2123 /* Read the resolution file. */
2125 if (resolution_file_name)
2128 unsigned num_objects;
2130 resolution = fopen (resolution_file_name, "r");
2131 if (resolution == NULL)
2132 fatal_error ("could not open symbol resolution file: %m");
2134 t = fscanf (resolution, "%u", &num_objects);
2135 gcc_assert (t == 1);
2137 /* True, since the plugin splits the archives. */
2138 gcc_assert (num_objects == nfiles);
2142 fprintf (stderr, "Reading object files:");
2144 /* Read all of the object files specified on the command line. */
2145 for (i = 0, last_file_ix = 0; i < nfiles; ++i)
2147 struct lto_file_decl_data *file_data = NULL;
2150 fprintf (stderr, " %s", fnames[i]);
2154 current_lto_file = lto_obj_file_open (fnames[i], false);
2155 if (!current_lto_file)
2158 file_data = lto_file_read (current_lto_file, resolution, &count);
2161 lto_obj_file_close (current_lto_file);
2162 current_lto_file = NULL;
2166 decl_data[last_file_ix++] = file_data;
2168 lto_obj_file_close (current_lto_file);
2169 current_lto_file = NULL;
2173 lto_flatten_files (decl_data, count, last_file_ix);
2174 lto_stats.num_input_files = count;
2175 ggc_free(decl_data);
2176 real_file_decl_data = NULL;
2178 if (resolution_file_name)
2179 fclose (resolution);
2181 /* Set the hooks so that all of the ipa passes can read in their data. */
2182 lto_set_in_hooks (all_file_decl_data, get_section_data, free_section_data);
2184 timevar_pop (TV_IPA_LTO_DECL_IN);
2187 fprintf (stderr, "\nReading the callgraph\n");
2189 timevar_push (TV_IPA_LTO_CGRAPH_IO);
2190 /* Read the callgraph. */
2192 timevar_pop (TV_IPA_LTO_CGRAPH_IO);
2195 fprintf (stderr, "Merging declarations\n");
2197 timevar_push (TV_IPA_LTO_DECL_MERGE);
2198 /* Merge global decls. */
2199 lto_symtab_merge_decls ();
2201 /* If there were errors during symbol merging bail out, we have no
2202 good way to recover here. */
2204 fatal_error ("errors during merging of translation units");
2206 /* Fixup all decls and types and free the type hash tables. */
2207 lto_fixup_decls (all_file_decl_data);
2208 free_gimple_type_tables ();
2211 timevar_pop (TV_IPA_LTO_DECL_MERGE);
2212 /* Each pass will set the appropriate timer. */
2215 fprintf (stderr, "Reading summaries\n");
2217 /* Read the IPA summary data. */
2219 ipa_read_optimization_summaries ();
2221 ipa_read_summaries ();
2223 /* Finally merge the cgraph according to the decl merging decisions. */
2224 timevar_push (TV_IPA_LTO_CGRAPH_MERGE);
2225 if (cgraph_dump_file)
2227 fprintf (cgraph_dump_file, "Before merging:\n");
2228 dump_cgraph (cgraph_dump_file);
2229 dump_varpool (cgraph_dump_file);
2231 lto_symtab_merge_cgraph_nodes ();
2235 for (node = cgraph_nodes; node; node = node->next)
2237 /* FIXME: ipa_transforms_to_apply holds list of passes that have optimization
2238 summaries computed and needs to apply changes. At the moment WHOPR only
2239 supports inlining, so we can push it here by hand. In future we need to stream
2240 this field into ltrans compilation. */
2242 VEC_safe_push (ipa_opt_pass, heap,
2243 node->ipa_transforms_to_apply,
2244 (ipa_opt_pass)&pass_ipa_inline);
2248 timevar_pop (TV_IPA_LTO_CGRAPH_MERGE);
2250 timevar_push (TV_IPA_LTO_DECL_INIT_IO);
2252 /* FIXME lto. This loop needs to be changed to use the pass manager to
2253 call the ipa passes directly. */
2255 for (i = 0; i < last_file_ix; i++)
2257 struct lto_file_decl_data *file_data = all_file_decl_data [i];
2258 lto_materialize_constructors_and_inits (file_data);
2261 /* Indicate that the cgraph is built and ready. */
2262 cgraph_function_flags_ready = true;
2264 timevar_pop (TV_IPA_LTO_DECL_INIT_IO);
2265 ggc_free (all_file_decl_data);
2266 all_file_decl_data = NULL;
2270 /* Materialize all the bodies for all the nodes in the callgraph. */
2273 materialize_cgraph (void)
2276 struct cgraph_node *node;
2278 timevar_id_t lto_timer;
2282 flag_wpa ? "Materializing decls:" : "Reading function bodies:");
2285 /* Now that we have input the cgraph, we need to clear all of the aux
2286 nodes and read the functions if we are not running in WPA mode. */
2287 timevar_push (TV_IPA_LTO_GIMPLE_IN);
2289 for (node = cgraph_nodes; node; node = node->next)
2291 if (node->local.lto_file_data)
2293 lto_materialize_function (node);
2294 lto_stats.num_input_cgraph_nodes++;
2298 timevar_pop (TV_IPA_LTO_GIMPLE_IN);
2300 /* Start the appropriate timer depending on the mode that we are
2302 lto_timer = (flag_wpa) ? TV_WHOPR_WPA
2303 : (flag_ltrans) ? TV_WHOPR_LTRANS
2305 timevar_push (lto_timer);
2307 current_function_decl = NULL;
2310 /* Inform the middle end about the global variables we have seen. */
2311 FOR_EACH_VEC_ELT (tree, lto_global_var_decls, i, decl)
2312 rest_of_decl_compilation (decl, 1, 0);
2315 fprintf (stderr, "\n");
2317 timevar_pop (lto_timer);
2321 /* Perform whole program analysis (WPA) on the callgraph and write out the
2322 optimization plan. */
2325 do_whole_program_analysis (void)
2327 /* Note that since we are in WPA mode, materialize_cgraph will not
2328 actually read in all the function bodies. It only materializes
2329 the decls and cgraph nodes so that analysis can be performed. */
2330 materialize_cgraph ();
2332 /* Reading in the cgraph uses different timers, start timing WPA now. */
2333 timevar_push (TV_WHOPR_WPA);
2335 if (pre_ipa_mem_report)
2337 fprintf (stderr, "Memory consumption before IPA\n");
2338 dump_memory_report (false);
2341 cgraph_function_flags_ready = true;
2343 if (cgraph_dump_file)
2345 dump_cgraph (cgraph_dump_file);
2346 dump_varpool (cgraph_dump_file);
2348 bitmap_obstack_initialize (NULL);
2349 ipa_register_cgraph_hooks ();
2350 cgraph_state = CGRAPH_STATE_IPA_SSA;
2352 execute_ipa_pass_list (all_regular_ipa_passes);
2354 if (cgraph_dump_file)
2356 fprintf (cgraph_dump_file, "Optimized ");
2357 dump_cgraph (cgraph_dump_file);
2358 dump_varpool (cgraph_dump_file);
2361 bitmap_obstack_release (NULL);
2363 /* We are about to launch the final LTRANS phase, stop the WPA timer. */
2364 timevar_pop (TV_WHOPR_WPA);
2366 if (flag_lto_partition_1to1)
2369 lto_balanced_map ();
2373 fprintf (stderr, "\nStreaming out");
2376 lto_wpa_write_files ();
2379 fprintf (stderr, "\n");
2381 if (post_ipa_mem_report)
2383 fprintf (stderr, "Memory consumption after IPA\n");
2384 dump_memory_report (false);
2387 /* Show the LTO report before launching LTRANS. */
2388 if (flag_lto_report)
2389 print_lto_report ();
2393 static GTY(()) tree lto_eh_personality_decl;
2395 /* Return the LTO personality function decl. */
2398 lto_eh_personality (void)
2400 if (!lto_eh_personality_decl)
2402 /* Use the first personality DECL for our personality if we don't
2403 support multiple ones. This ensures that we don't artificially
2404 create the need for them in a single-language program. */
2405 if (first_personality_decl && !dwarf2out_do_cfi_asm ())
2406 lto_eh_personality_decl = first_personality_decl;
2408 lto_eh_personality_decl = lhd_gcc_personality ();
2411 return lto_eh_personality_decl;
2414 /* Set the process name based on the LTO mode. */
2417 lto_process_name (void)
2420 setproctitle ("lto1-lto");
2422 setproctitle ("lto1-wpa");
2424 setproctitle ("lto1-ltrans");
2427 /* Main entry point for the GIMPLE front end. This front end has
2428 three main personalities:
2430 - LTO (-flto). All the object files on the command line are
2431 loaded in memory and processed as a single translation unit.
2432 This is the traditional link-time optimization behavior.
2434 - WPA (-fwpa). Only the callgraph and summary information for
2435 files in the command file are loaded. A single callgraph
2436 (without function bodies) is instantiated for the whole set of
2437 files. IPA passes are only allowed to analyze the call graph
2438 and make transformation decisions. The callgraph is
2439 partitioned, each partition is written to a new object file
2440 together with the transformation decisions.
2442 - LTRANS (-fltrans). Similar to -flto but it prevents the IPA
2443 summary files from running again. Since WPA computed summary
2444 information and decided what transformations to apply, LTRANS
2445 simply applies them. */
2450 lto_process_name ();
2454 /* Read all the symbols and call graph from all the files in the
2456 read_cgraph_and_symbols (num_in_fnames, in_fnames);
2460 /* If WPA is enabled analyze the whole call graph and create an
2461 optimization plan. Otherwise, read in all the function
2462 bodies and continue with optimization. */
2464 do_whole_program_analysis ();
2467 materialize_cgraph ();
2469 /* Let the middle end know that we have read and merged all of
2473 /* FIXME lto, if the processes spawned by WPA fail, we miss
2474 the chance to print WPA's report, so WPA will call
2475 print_lto_report before launching LTRANS. If LTRANS was
2476 launched directly by the driver we would not need to do
2478 if (flag_lto_report)
2479 print_lto_report ();
2484 #include "gt-lto-lto.h"