Mercurial > hg > CbC > CbC_gcc
comparison gcc/lto/lto.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* Top-level LTO routines. | 1 /* Top-level LTO routines. |
2 Copyright (C) 2009-2017 Free Software Foundation, Inc. | 2 Copyright (C) 2009-2018 Free Software Foundation, Inc. |
3 Contributed by CodeSourcery, Inc. | 3 Contributed by CodeSourcery, Inc. |
4 | 4 |
5 This file is part of GCC. | 5 This file is part of GCC. |
6 | 6 |
7 GCC is free software; you can redistribute it and/or modify it under | 7 GCC is free software; you can redistribute it and/or modify it under |
52 #include "gomp-constants.h" | 52 #include "gomp-constants.h" |
53 #include "lto-symtab.h" | 53 #include "lto-symtab.h" |
54 #include "stringpool.h" | 54 #include "stringpool.h" |
55 #include "fold-const.h" | 55 #include "fold-const.h" |
56 #include "attribs.h" | 56 #include "attribs.h" |
57 #include "builtins.h" | |
57 | 58 |
58 | 59 |
59 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver. */ | 60 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver. */ |
60 static int lto_parallelism; | 61 static int lto_parallelism; |
61 | 62 |
314 hstate.add_int (TYPE_UNSIGNED (type)); | 315 hstate.add_int (TYPE_UNSIGNED (type)); |
315 } | 316 } |
316 | 317 |
317 if (VECTOR_TYPE_P (type)) | 318 if (VECTOR_TYPE_P (type)) |
318 { | 319 { |
319 hstate.add_int (TYPE_VECTOR_SUBPARTS (type)); | 320 hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type)); |
320 hstate.add_int (TYPE_UNSIGNED (type)); | 321 hstate.add_int (TYPE_UNSIGNED (type)); |
321 } | 322 } |
322 | 323 |
323 if (TREE_CODE (type) == COMPLEX_TYPE) | 324 if (TREE_CODE (type) == COMPLEX_TYPE) |
324 hstate.add_int (TYPE_UNSIGNED (type)); | 325 hstate.add_int (TYPE_UNSIGNED (type)); |
828 /* We need to record resolutions until symbol table is read. */ | 829 /* We need to record resolutions until symbol table is read. */ |
829 static void | 830 static void |
830 register_resolution (struct lto_file_decl_data *file_data, tree decl, | 831 register_resolution (struct lto_file_decl_data *file_data, tree decl, |
831 enum ld_plugin_symbol_resolution resolution) | 832 enum ld_plugin_symbol_resolution resolution) |
832 { | 833 { |
834 bool existed; | |
833 if (resolution == LDPR_UNKNOWN) | 835 if (resolution == LDPR_UNKNOWN) |
834 return; | 836 return; |
835 if (!file_data->resolution_map) | 837 if (!file_data->resolution_map) |
836 file_data->resolution_map | 838 file_data->resolution_map |
837 = new hash_map<tree, ld_plugin_symbol_resolution>; | 839 = new hash_map<tree, ld_plugin_symbol_resolution>; |
838 file_data->resolution_map->put (decl, resolution); | 840 ld_plugin_symbol_resolution_t &res |
841 = file_data->resolution_map->get_or_insert (decl, &existed); | |
842 if (!existed | |
843 || resolution == LDPR_PREVAILING_DEF_IRONLY | |
844 || resolution == LDPR_PREVAILING_DEF | |
845 || resolution == LDPR_PREVAILING_DEF_IRONLY_EXP) | |
846 res = resolution; | |
839 } | 847 } |
840 | 848 |
841 /* Register DECL with the global symbol table and change its | 849 /* Register DECL with the global symbol table and change its |
842 name if necessary to avoid name clashes for static globals across | 850 name if necessary to avoid name clashes for static globals across |
843 different files. */ | 851 different files. */ |
874 /* If this variable has already been declared, queue the | 882 /* If this variable has already been declared, queue the |
875 declaration for merging. */ | 883 declaration for merging. */ |
876 if (TREE_PUBLIC (decl) && !DECL_ABSTRACT_P (decl)) | 884 if (TREE_PUBLIC (decl) && !DECL_ABSTRACT_P (decl)) |
877 register_resolution (data_in->file_data, | 885 register_resolution (data_in->file_data, |
878 decl, get_resolution (data_in, ix)); | 886 decl, get_resolution (data_in, ix)); |
887 } | |
888 | |
889 /* Check if T is a decl and needs register its resolution info. */ | |
890 | |
891 static void | |
892 lto_maybe_register_decl (struct data_in *data_in, tree t, unsigned ix) | |
893 { | |
894 if (TREE_CODE (t) == VAR_DECL) | |
895 lto_register_var_decl_in_symtab (data_in, t, ix); | |
896 else if (TREE_CODE (t) == FUNCTION_DECL | |
897 && !fndecl_built_in_p (t)) | |
898 lto_register_function_decl_in_symtab (data_in, t, ix); | |
879 } | 899 } |
880 | 900 |
881 | 901 |
882 /* For the type T re-materialize it in the type variant list and | 902 /* For the type T re-materialize it in the type variant list and |
883 the pointer/reference-to chains. */ | 903 the pointer/reference-to chains. */ |
1063 if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST)) | 1083 if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST)) |
1064 if (!fixed_compare (EQ_EXPR, | 1084 if (!fixed_compare (EQ_EXPR, |
1065 TREE_FIXED_CST_PTR (t1), TREE_FIXED_CST_PTR (t2))) | 1085 TREE_FIXED_CST_PTR (t1), TREE_FIXED_CST_PTR (t2))) |
1066 return false; | 1086 return false; |
1067 | 1087 |
1088 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR)) | |
1089 { | |
1090 compare_values (VECTOR_CST_LOG2_NPATTERNS); | |
1091 compare_values (VECTOR_CST_NELTS_PER_PATTERN); | |
1092 } | |
1093 | |
1068 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON)) | 1094 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON)) |
1069 { | 1095 { |
1070 compare_values (DECL_MODE); | 1096 compare_values (DECL_MODE); |
1071 compare_values (DECL_NONLOCAL); | 1097 compare_values (DECL_NONLOCAL); |
1072 compare_values (DECL_VIRTUAL_P); | 1098 compare_values (DECL_VIRTUAL_P); |
1085 } | 1111 } |
1086 else if (code == FIELD_DECL) | 1112 else if (code == FIELD_DECL) |
1087 { | 1113 { |
1088 compare_values (DECL_PACKED); | 1114 compare_values (DECL_PACKED); |
1089 compare_values (DECL_NONADDRESSABLE_P); | 1115 compare_values (DECL_NONADDRESSABLE_P); |
1116 compare_values (DECL_PADDING_P); | |
1090 compare_values (DECL_OFFSET_ALIGN); | 1117 compare_values (DECL_OFFSET_ALIGN); |
1091 } | 1118 } |
1092 else if (code == VAR_DECL) | 1119 else if (code == VAR_DECL) |
1093 { | 1120 { |
1094 compare_values (DECL_HAS_DEBUG_EXPR_P); | 1121 compare_values (DECL_HAS_DEBUG_EXPR_P); |
1163 } | 1190 } |
1164 else if (code == ARRAY_TYPE) | 1191 else if (code == ARRAY_TYPE) |
1165 compare_values (TYPE_NONALIASED_COMPONENT); | 1192 compare_values (TYPE_NONALIASED_COMPONENT); |
1166 if (AGGREGATE_TYPE_P (t1)) | 1193 if (AGGREGATE_TYPE_P (t1)) |
1167 compare_values (TYPE_TYPELESS_STORAGE); | 1194 compare_values (TYPE_TYPELESS_STORAGE); |
1195 compare_values (TYPE_EMPTY_P); | |
1168 compare_values (TYPE_PACKED); | 1196 compare_values (TYPE_PACKED); |
1169 compare_values (TYPE_RESTRICT); | 1197 compare_values (TYPE_RESTRICT); |
1170 compare_values (TYPE_USER_ALIGN); | 1198 compare_values (TYPE_USER_ALIGN); |
1171 compare_values (TYPE_READONLY); | 1199 compare_values (TYPE_READONLY); |
1172 compare_values (TYPE_PRECISION); | 1200 compare_values (TYPE_PRECISION); |
1192 if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION)) | 1220 if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION)) |
1193 if (!cl_target_option_eq (TREE_TARGET_OPTION (t1), TREE_TARGET_OPTION (t2))) | 1221 if (!cl_target_option_eq (TREE_TARGET_OPTION (t1), TREE_TARGET_OPTION (t2))) |
1194 return false; | 1222 return false; |
1195 | 1223 |
1196 if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION)) | 1224 if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION)) |
1197 if (memcmp (TREE_OPTIMIZATION (t1), TREE_OPTIMIZATION (t2), | 1225 if (!cl_optimization_option_eq (TREE_OPTIMIZATION (t1), |
1198 sizeof (struct cl_optimization)) != 0) | 1226 TREE_OPTIMIZATION (t2))) |
1199 return false; | 1227 return false; |
1200 | 1228 |
1201 if (CODE_CONTAINS_STRUCT (code, TS_BINFO)) | 1229 if (CODE_CONTAINS_STRUCT (code, TS_BINFO)) |
1202 if (vec_safe_length (BINFO_BASE_ACCESSES (t1)) | 1230 if (vec_safe_length (BINFO_BASE_ACCESSES (t1)) |
1203 != vec_safe_length (BINFO_BASE_ACCESSES (t2))) | 1231 != vec_safe_length (BINFO_BASE_ACCESSES (t2))) |
1277 compare_tree_edges (TREE_TYPE (t1), TREE_TYPE (t2)); | 1305 compare_tree_edges (TREE_TYPE (t1), TREE_TYPE (t2)); |
1278 } | 1306 } |
1279 | 1307 |
1280 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR)) | 1308 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR)) |
1281 { | 1309 { |
1282 unsigned i; | |
1283 /* Note that the number of elements for EXPR has already been emitted | 1310 /* Note that the number of elements for EXPR has already been emitted |
1284 in EXPR's header (see streamer_write_tree_header). */ | 1311 in EXPR's header (see streamer_write_tree_header). */ |
1285 for (i = 0; i < VECTOR_CST_NELTS (t1); ++i) | 1312 unsigned int count = vector_cst_encoded_nelts (t1); |
1286 compare_tree_edges (VECTOR_CST_ELT (t1, i), VECTOR_CST_ELT (t2, i)); | 1313 for (unsigned int i = 0; i < count; ++i) |
1314 compare_tree_edges (VECTOR_CST_ENCODED_ELT (t1, i), | |
1315 VECTOR_CST_ENCODED_ELT (t2, i)); | |
1287 } | 1316 } |
1288 | 1317 |
1289 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX)) | 1318 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX)) |
1290 { | 1319 { |
1291 compare_tree_edges (TREE_REALPART (t1), TREE_REALPART (t2)); | 1320 compare_tree_edges (TREE_REALPART (t1), TREE_REALPART (t2)); |
1606 } | 1635 } |
1607 | 1636 |
1608 /* Fixup the streamer cache with the prevailing nodes according | 1637 /* Fixup the streamer cache with the prevailing nodes according |
1609 to the tree node mapping computed by compare_tree_sccs. */ | 1638 to the tree node mapping computed by compare_tree_sccs. */ |
1610 if (len == 1) | 1639 if (len == 1) |
1611 streamer_tree_cache_replace_tree (cache, pscc->entries[0], from); | 1640 { |
1641 /* If we got a debug reference queued, see if the prevailing | |
1642 tree has a debug reference and if not, register the one | |
1643 for the tree we are about to throw away. */ | |
1644 if (dref_queue.length () == 1) | |
1645 { | |
1646 dref_entry e = dref_queue.pop (); | |
1647 gcc_assert (e.decl | |
1648 == streamer_tree_cache_get_tree (cache, from)); | |
1649 const char *sym; | |
1650 unsigned HOST_WIDE_INT off; | |
1651 if (!debug_hooks->die_ref_for_decl (pscc->entries[0], &sym, | |
1652 &off)) | |
1653 debug_hooks->register_external_die (pscc->entries[0], | |
1654 e.sym, e.off); | |
1655 } | |
1656 lto_maybe_register_decl (data_in, pscc->entries[0], from); | |
1657 streamer_tree_cache_replace_tree (cache, pscc->entries[0], from); | |
1658 } | |
1612 else | 1659 else |
1613 { | 1660 { |
1614 tree *map2 = XALLOCAVEC (tree, 2 * len); | 1661 tree *map2 = XALLOCAVEC (tree, 2 * len); |
1615 for (unsigned i = 0; i < len; ++i) | 1662 for (unsigned i = 0; i < len; ++i) |
1616 { | 1663 { |
1618 map2[i*2+1] = scc->entries[i]; | 1665 map2[i*2+1] = scc->entries[i]; |
1619 } | 1666 } |
1620 qsort (map2, len, 2 * sizeof (tree), cmp_tree); | 1667 qsort (map2, len, 2 * sizeof (tree), cmp_tree); |
1621 qsort (map, len, 2 * sizeof (tree), cmp_tree); | 1668 qsort (map, len, 2 * sizeof (tree), cmp_tree); |
1622 for (unsigned i = 0; i < len; ++i) | 1669 for (unsigned i = 0; i < len; ++i) |
1623 streamer_tree_cache_replace_tree (cache, map[2*i], | 1670 { |
1624 (uintptr_t)map2[2*i]); | 1671 lto_maybe_register_decl (data_in, map[2*i], |
1672 (uintptr_t)map2[2*i]); | |
1673 streamer_tree_cache_replace_tree (cache, map[2*i], | |
1674 (uintptr_t)map2[2*i]); | |
1675 } | |
1625 } | 1676 } |
1626 | 1677 |
1627 /* Free the tree nodes from the read SCC. */ | 1678 /* Free the tree nodes from the read SCC. */ |
1628 data_in->location_cache.revert_location_cache (); | 1679 data_in->location_cache.revert_location_cache (); |
1629 for (unsigned i = 0; i < len; ++i) | 1680 for (unsigned i = 0; i < len; ++i) |
1631 if (TYPE_P (scc->entries[i])) | 1682 if (TYPE_P (scc->entries[i])) |
1632 num_merged_types++; | 1683 num_merged_types++; |
1633 free_node (scc->entries[i]); | 1684 free_node (scc->entries[i]); |
1634 } | 1685 } |
1635 | 1686 |
1636 /* Drop DIE references. */ | 1687 /* Drop DIE references. |
1688 ??? Do as in the size-one SCC case which involves sorting | |
1689 the queue. */ | |
1637 dref_queue.truncate (0); | 1690 dref_queue.truncate (0); |
1638 | 1691 |
1639 break; | 1692 break; |
1640 } | 1693 } |
1641 | 1694 |
1656 *slot = pscc; | 1709 *slot = pscc; |
1657 } | 1710 } |
1658 return unified_p; | 1711 return unified_p; |
1659 } | 1712 } |
1660 | 1713 |
1714 | |
1715 /* Compare types based on source file location. */ | |
1716 | |
1717 static int | |
1718 cmp_type_location (const void *p1_, const void *p2_) | |
1719 { | |
1720 tree *p1 = (tree*)(const_cast<void *>(p1_)); | |
1721 tree *p2 = (tree*)(const_cast<void *>(p2_)); | |
1722 if (*p1 == *p2) | |
1723 return 0; | |
1724 | |
1725 tree tname1 = TYPE_NAME (*p1); | |
1726 tree tname2 = TYPE_NAME (*p2); | |
1727 expanded_location xloc1 = expand_location (DECL_SOURCE_LOCATION (tname1)); | |
1728 expanded_location xloc2 = expand_location (DECL_SOURCE_LOCATION (tname2)); | |
1729 | |
1730 const char *f1 = lbasename (xloc1.file); | |
1731 const char *f2 = lbasename (xloc2.file); | |
1732 int r = strcmp (f1, f2); | |
1733 if (r == 0) | |
1734 { | |
1735 int l1 = xloc1.line; | |
1736 int l2 = xloc2.line; | |
1737 if (l1 != l2) | |
1738 return l1 - l2; | |
1739 return xloc1.column - xloc2.column; | |
1740 } | |
1741 else | |
1742 return r; | |
1743 } | |
1661 | 1744 |
1662 /* Read all the symbols from buffer DATA, using descriptors in DECL_DATA. | 1745 /* Read all the symbols from buffer DATA, using descriptors in DECL_DATA. |
1663 RESOLUTIONS is the set of symbols picked by the linker (read from the | 1746 RESOLUTIONS is the set of symbols picked by the linker (read from the |
1664 resolution file when the linker plugin is being used). */ | 1747 resolution file when the linker plugin is being used). */ |
1665 | 1748 |
1673 const int string_offset = main_offset + header->main_size; | 1756 const int string_offset = main_offset + header->main_size; |
1674 struct data_in *data_in; | 1757 struct data_in *data_in; |
1675 unsigned int i; | 1758 unsigned int i; |
1676 const uint32_t *data_ptr, *data_end; | 1759 const uint32_t *data_ptr, *data_end; |
1677 uint32_t num_decl_states; | 1760 uint32_t num_decl_states; |
1761 auto_vec<tree> odr_types; | |
1678 | 1762 |
1679 lto_input_block ib_main ((const char *) data + main_offset, | 1763 lto_input_block ib_main ((const char *) data + main_offset, |
1680 header->main_size, decl_data->mode_table); | 1764 header->main_size, decl_data->mode_table); |
1681 | 1765 |
1682 data_in = lto_data_in_create (decl_data, (const char *) data + string_offset, | 1766 data_in = lto_data_in_create (decl_data, (const char *) data + string_offset, |
1734 if (TYPE_P (t)) | 1818 if (TYPE_P (t)) |
1735 { | 1819 { |
1736 seen_type = true; | 1820 seen_type = true; |
1737 num_prevailing_types++; | 1821 num_prevailing_types++; |
1738 lto_fixup_prevailing_type (t); | 1822 lto_fixup_prevailing_type (t); |
1739 } | 1823 |
1740 /* Compute the canonical type of all types. | 1824 /* Compute the canonical type of all types. |
1741 ??? Should be able to assert that !TYPE_CANONICAL. */ | 1825 Because SCC components are streamed in random (hash) order |
1742 if (TYPE_P (t) && !TYPE_CANONICAL (t)) | 1826 we may have encountered the type before while registering |
1743 { | 1827 type canonical of a derived type in the same SCC. */ |
1744 gimple_register_canonical_type (t); | 1828 if (!TYPE_CANONICAL (t)) |
1829 gimple_register_canonical_type (t); | |
1745 if (odr_type_p (t)) | 1830 if (odr_type_p (t)) |
1746 register_odr_type (t); | 1831 odr_types.safe_push (t); |
1747 } | 1832 } |
1748 /* Link shared INTEGER_CSTs into TYPE_CACHED_VALUEs of its | 1833 /* Link shared INTEGER_CSTs into TYPE_CACHED_VALUEs of its |
1749 type which is also member of this SCC. */ | 1834 type which is also member of this SCC. */ |
1750 if (TREE_CODE (t) == INTEGER_CST | 1835 if (TREE_CODE (t) == INTEGER_CST |
1751 && !TREE_OVERFLOW (t)) | 1836 && !TREE_OVERFLOW (t)) |
1752 cache_integer_cst (t); | 1837 cache_integer_cst (t); |
1753 if (!flag_ltrans) | 1838 if (!flag_ltrans) |
1754 { | 1839 { |
1755 /* Register variables and functions with the | 1840 lto_maybe_register_decl (data_in, t, from + i); |
1756 symbol table. */ | |
1757 if (TREE_CODE (t) == VAR_DECL) | |
1758 lto_register_var_decl_in_symtab (data_in, t, from + i); | |
1759 else if (TREE_CODE (t) == FUNCTION_DECL | |
1760 && !DECL_BUILT_IN (t)) | |
1761 lto_register_function_decl_in_symtab (data_in, t, from + i); | |
1762 /* Scan the tree for references to global functions or | 1841 /* Scan the tree for references to global functions or |
1763 variables and record those for later fixup. */ | 1842 variables and record those for later fixup. */ |
1764 if (mentions_vars_p (t)) | 1843 if (mentions_vars_p (t)) |
1765 vec_safe_push (tree_with_vars, t); | 1844 vec_safe_push (tree_with_vars, t); |
1766 } | 1845 } |
1808 lto_in_decl_state **slot | 1887 lto_in_decl_state **slot |
1809 = decl_data->function_decl_states->find_slot (state, INSERT); | 1888 = decl_data->function_decl_states->find_slot (state, INSERT); |
1810 gcc_assert (*slot == NULL); | 1889 gcc_assert (*slot == NULL); |
1811 *slot = state; | 1890 *slot = state; |
1812 } | 1891 } |
1892 | |
1893 /* Sort types for the file before registering in ODR machinery. */ | |
1894 if (lto_location_cache::current_cache) | |
1895 lto_location_cache::current_cache->apply_location_cache (); | |
1896 odr_types.qsort (cmp_type_location); | |
1897 | |
1898 /* Register ODR types. */ | |
1899 for (unsigned i = 0; i < odr_types.length (); i++) | |
1900 register_odr_type (odr_types[i]); | |
1813 | 1901 |
1814 if (data_ptr != data_end) | 1902 if (data_ptr != data_end) |
1815 internal_error ("bytecode stream: garbage at the end of symbols section"); | 1903 internal_error ("bytecode stream: garbage at the end of symbols section"); |
1816 | 1904 |
1817 /* Set the current decl state to be the global state. */ | 1905 /* Set the current decl state to be the global state. */ |
1985 else | 2073 else |
1986 { | 2074 { |
1987 file_data = ggc_alloc<lto_file_decl_data> (); | 2075 file_data = ggc_alloc<lto_file_decl_data> (); |
1988 memset(file_data, 0, sizeof (struct lto_file_decl_data)); | 2076 memset(file_data, 0, sizeof (struct lto_file_decl_data)); |
1989 file_data->id = id; | 2077 file_data->id = id; |
1990 file_data->section_hash_table = lto_obj_create_section_hash_table ();; | 2078 file_data->section_hash_table = lto_obj_create_section_hash_table (); |
1991 lto_splay_tree_insert (file_ids, id, file_data); | 2079 lto_splay_tree_insert (file_ids, id, file_data); |
1992 | 2080 |
1993 /* Maintain list in linker order */ | 2081 /* Maintain list in linker order */ |
1994 if (!list->first) | 2082 if (!list->first) |
1995 list->first = file_data; | 2083 list->first = file_data; |
2250 #endif | 2338 #endif |
2251 } | 2339 } |
2252 | 2340 |
2253 static lto_file *current_lto_file; | 2341 static lto_file *current_lto_file; |
2254 | 2342 |
2255 /* Helper for qsort; compare partitions and return one with smaller size. | |
2256 We sort from greatest to smallest so parallel build doesn't stale on the | |
2257 longest compilation being executed too late. */ | |
2258 | |
2259 static int | |
2260 cmp_partitions_size (const void *a, const void *b) | |
2261 { | |
2262 const struct ltrans_partition_def *pa | |
2263 = *(struct ltrans_partition_def *const *)a; | |
2264 const struct ltrans_partition_def *pb | |
2265 = *(struct ltrans_partition_def *const *)b; | |
2266 return pb->insns - pa->insns; | |
2267 } | |
2268 | |
2269 /* Helper for qsort; compare partitions and return one with smaller order. */ | |
2270 | |
2271 static int | |
2272 cmp_partitions_order (const void *a, const void *b) | |
2273 { | |
2274 const struct ltrans_partition_def *pa | |
2275 = *(struct ltrans_partition_def *const *)a; | |
2276 const struct ltrans_partition_def *pb | |
2277 = *(struct ltrans_partition_def *const *)b; | |
2278 int ordera = -1, orderb = -1; | |
2279 | |
2280 if (lto_symtab_encoder_size (pa->encoder)) | |
2281 ordera = lto_symtab_encoder_deref (pa->encoder, 0)->order; | |
2282 if (lto_symtab_encoder_size (pb->encoder)) | |
2283 orderb = lto_symtab_encoder_deref (pb->encoder, 0)->order; | |
2284 return orderb - ordera; | |
2285 } | |
2286 | |
2287 /* Actually stream out ENCODER into TEMP_FILENAME. */ | 2343 /* Actually stream out ENCODER into TEMP_FILENAME. */ |
2288 | 2344 |
2289 static void | 2345 static void |
2290 do_stream_out (char *temp_filename, lto_symtab_encoder_t encoder) | 2346 do_stream_out (char *temp_filename, lto_symtab_encoder_t encoder, int part) |
2291 { | 2347 { |
2292 lto_file *file = lto_obj_file_open (temp_filename, true); | 2348 lto_file *file = lto_obj_file_open (temp_filename, true); |
2293 if (!file) | 2349 if (!file) |
2294 fatal_error (input_location, "lto_obj_file_open() failed"); | 2350 fatal_error (input_location, "lto_obj_file_open() failed"); |
2295 lto_set_current_out_file (file); | 2351 lto_set_current_out_file (file); |
2296 | 2352 |
2353 gcc_assert (!dump_file); | |
2354 streamer_dump_file = dump_begin (TDI_lto_stream_out, NULL, part); | |
2297 ipa_write_optimization_summaries (encoder); | 2355 ipa_write_optimization_summaries (encoder); |
2298 | 2356 |
2299 free (CONST_CAST (char *, file->filename)); | 2357 free (CONST_CAST (char *, file->filename)); |
2300 | 2358 |
2301 lto_set_current_out_file (NULL); | 2359 lto_set_current_out_file (NULL); |
2302 lto_obj_file_close (file); | 2360 lto_obj_file_close (file); |
2303 free (file); | 2361 free (file); |
2362 if (streamer_dump_file) | |
2363 { | |
2364 dump_end (TDI_lto_stream_out, streamer_dump_file); | |
2365 streamer_dump_file = NULL; | |
2366 } | |
2304 } | 2367 } |
2305 | 2368 |
2306 /* Wait for forked process and signal errors. */ | 2369 /* Wait for forked process and signal errors. */ |
2307 #ifdef HAVE_WORKING_FORK | 2370 #ifdef HAVE_WORKING_FORK |
2308 static void | 2371 static void |
2331 /* Stream out ENCODER into TEMP_FILENAME | 2394 /* Stream out ENCODER into TEMP_FILENAME |
2332 Fork if that seems to help. */ | 2395 Fork if that seems to help. */ |
2333 | 2396 |
2334 static void | 2397 static void |
2335 stream_out (char *temp_filename, lto_symtab_encoder_t encoder, | 2398 stream_out (char *temp_filename, lto_symtab_encoder_t encoder, |
2336 bool ARG_UNUSED (last)) | 2399 bool ARG_UNUSED (last), int part) |
2337 { | 2400 { |
2338 #ifdef HAVE_WORKING_FORK | 2401 #ifdef HAVE_WORKING_FORK |
2339 static int nruns; | 2402 static int nruns; |
2340 | 2403 |
2341 if (lto_parallelism <= 1) | 2404 if (lto_parallelism <= 1) |
2342 { | 2405 { |
2343 do_stream_out (temp_filename, encoder); | 2406 do_stream_out (temp_filename, encoder, part); |
2344 return; | 2407 return; |
2345 } | 2408 } |
2346 | 2409 |
2347 /* Do not run more than LTO_PARALLELISM streamings | 2410 /* Do not run more than LTO_PARALLELISM streamings |
2348 FIXME: we ignore limits on jobserver. */ | 2411 FIXME: we ignore limits on jobserver. */ |
2358 pid_t cpid = fork (); | 2421 pid_t cpid = fork (); |
2359 | 2422 |
2360 if (!cpid) | 2423 if (!cpid) |
2361 { | 2424 { |
2362 setproctitle ("lto1-wpa-streaming"); | 2425 setproctitle ("lto1-wpa-streaming"); |
2363 do_stream_out (temp_filename, encoder); | 2426 do_stream_out (temp_filename, encoder, part); |
2364 exit (0); | 2427 exit (0); |
2365 } | 2428 } |
2366 /* Fork failed; lets do the job ourseleves. */ | 2429 /* Fork failed; lets do the job ourseleves. */ |
2367 else if (cpid == -1) | 2430 else if (cpid == -1) |
2368 do_stream_out (temp_filename, encoder); | 2431 do_stream_out (temp_filename, encoder, part); |
2369 else | 2432 else |
2370 nruns++; | 2433 nruns++; |
2371 } | 2434 } |
2372 /* Last partition; stream it and wait for all children to die. */ | 2435 /* Last partition; stream it and wait for all children to die. */ |
2373 else | 2436 else |
2374 { | 2437 { |
2375 int i; | 2438 int i; |
2376 do_stream_out (temp_filename, encoder); | 2439 do_stream_out (temp_filename, encoder, part); |
2377 for (i = 0; i < nruns; i++) | 2440 for (i = 0; i < nruns; i++) |
2378 wait_for_child (); | 2441 wait_for_child (); |
2379 } | 2442 } |
2380 asm_nodes_output = true; | 2443 asm_nodes_output = true; |
2381 #else | 2444 #else |
2382 do_stream_out (temp_filename, encoder); | 2445 do_stream_out (temp_filename, encoder, part); |
2383 #endif | 2446 #endif |
2384 } | 2447 } |
2385 | 2448 |
2386 /* Write all output files in WPA mode and the file with the list of | 2449 /* Write all output files in WPA mode and the file with the list of |
2387 LTRANS units. */ | 2450 LTRANS units. */ |
2391 { | 2454 { |
2392 unsigned i, n_sets; | 2455 unsigned i, n_sets; |
2393 ltrans_partition part; | 2456 ltrans_partition part; |
2394 FILE *ltrans_output_list_stream; | 2457 FILE *ltrans_output_list_stream; |
2395 char *temp_filename; | 2458 char *temp_filename; |
2396 vec <char *>temp_filenames = vNULL; | 2459 auto_vec <char *>temp_filenames; |
2460 auto_vec <int>temp_priority; | |
2397 size_t blen; | 2461 size_t blen; |
2398 | 2462 |
2399 /* Open the LTRANS output list. */ | 2463 /* Open the LTRANS output list. */ |
2400 if (!ltrans_output_list) | 2464 if (!ltrans_output_list) |
2401 fatal_error (input_location, "no LTRANS output list filename provided"); | 2465 fatal_error (input_location, "no LTRANS output list filename provided"); |
2418 ".out") == 0) | 2482 ".out") == 0) |
2419 temp_filename[blen - sizeof (".out") + 1] = '\0'; | 2483 temp_filename[blen - sizeof (".out") + 1] = '\0'; |
2420 blen = strlen (temp_filename); | 2484 blen = strlen (temp_filename); |
2421 | 2485 |
2422 n_sets = ltrans_partitions.length (); | 2486 n_sets = ltrans_partitions.length (); |
2423 | |
2424 /* Sort partitions by size so small ones are compiled last. | |
2425 FIXME: Even when not reordering we may want to output one list for parallel make | |
2426 and other for final link command. */ | |
2427 | |
2428 if (!flag_profile_reorder_functions || !flag_profile_use) | |
2429 ltrans_partitions.qsort (flag_toplevel_reorder | |
2430 ? cmp_partitions_size | |
2431 : cmp_partitions_order); | |
2432 | 2487 |
2433 for (i = 0; i < n_sets; i++) | 2488 for (i = 0; i < n_sets; i++) |
2434 { | 2489 { |
2435 ltrans_partition part = ltrans_partitions[i]; | 2490 ltrans_partition part = ltrans_partitions[i]; |
2436 | 2491 |
2475 } | 2530 } |
2476 fprintf (symtab->dump_file, "\n"); | 2531 fprintf (symtab->dump_file, "\n"); |
2477 } | 2532 } |
2478 gcc_checking_assert (lto_symtab_encoder_size (part->encoder) || !i); | 2533 gcc_checking_assert (lto_symtab_encoder_size (part->encoder) || !i); |
2479 | 2534 |
2480 stream_out (temp_filename, part->encoder, i == n_sets - 1); | 2535 stream_out (temp_filename, part->encoder, i == n_sets - 1, i); |
2481 | 2536 |
2482 part->encoder = NULL; | 2537 part->encoder = NULL; |
2483 | 2538 |
2539 temp_priority.safe_push (part->insns); | |
2484 temp_filenames.safe_push (xstrdup (temp_filename)); | 2540 temp_filenames.safe_push (xstrdup (temp_filename)); |
2485 } | 2541 } |
2486 ltrans_output_list_stream = fopen (ltrans_output_list, "w"); | 2542 ltrans_output_list_stream = fopen (ltrans_output_list, "w"); |
2487 if (ltrans_output_list_stream == NULL) | 2543 if (ltrans_output_list_stream == NULL) |
2488 fatal_error (input_location, | 2544 fatal_error (input_location, |
2489 "opening LTRANS output list %s: %m", ltrans_output_list); | 2545 "opening LTRANS output list %s: %m", ltrans_output_list); |
2490 for (i = 0; i < n_sets; i++) | 2546 for (i = 0; i < n_sets; i++) |
2491 { | 2547 { |
2492 unsigned int len = strlen (temp_filenames[i]); | 2548 unsigned int len = strlen (temp_filenames[i]); |
2493 if (fwrite (temp_filenames[i], 1, len, ltrans_output_list_stream) < len | 2549 if (fprintf (ltrans_output_list_stream, "%i\n", temp_priority[i]) < 0 |
2550 || fwrite (temp_filenames[i], 1, len, ltrans_output_list_stream) < len | |
2494 || fwrite ("\n", 1, 1, ltrans_output_list_stream) < 1) | 2551 || fwrite ("\n", 1, 1, ltrans_output_list_stream) < 1) |
2495 fatal_error (input_location, "writing to LTRANS output list %s: %m", | 2552 fatal_error (input_location, "writing to LTRANS output list %s: %m", |
2496 ltrans_output_list); | 2553 ltrans_output_list); |
2497 free (temp_filenames[i]); | 2554 free (temp_filenames[i]); |
2498 } | 2555 } |
2499 temp_filenames.release(); | |
2500 | 2556 |
2501 lto_stats.num_output_files += n_sets; | 2557 lto_stats.num_output_files += n_sets; |
2502 | 2558 |
2503 /* Close the LTRANS output list. */ | 2559 /* Close the LTRANS output list. */ |
2504 if (fclose (ltrans_output_list_stream)) | 2560 if (fclose (ltrans_output_list_stream)) |
2862 | 2918 |
2863 input_offload_tables (!flag_ltrans); | 2919 input_offload_tables (!flag_ltrans); |
2864 | 2920 |
2865 /* Store resolutions into the symbol table. */ | 2921 /* Store resolutions into the symbol table. */ |
2866 | 2922 |
2867 ld_plugin_symbol_resolution_t *res; | |
2868 FOR_EACH_SYMBOL (snode) | 2923 FOR_EACH_SYMBOL (snode) |
2869 if (snode->real_symbol_p () | 2924 if (snode->externally_visible && snode->real_symbol_p () |
2870 && snode->lto_file_data | 2925 && snode->lto_file_data && snode->lto_file_data->resolution_map |
2871 && snode->lto_file_data->resolution_map | 2926 && !(TREE_CODE (snode->decl) == FUNCTION_DECL |
2872 && (res = snode->lto_file_data->resolution_map->get (snode->decl))) | 2927 && fndecl_built_in_p (snode->decl)) |
2873 snode->resolution = *res; | 2928 && !(VAR_P (snode->decl) && DECL_HARD_REGISTER (snode->decl))) |
2929 { | |
2930 ld_plugin_symbol_resolution_t *res; | |
2931 | |
2932 res = snode->lto_file_data->resolution_map->get (snode->decl); | |
2933 if (!res || *res == LDPR_UNKNOWN) | |
2934 { | |
2935 if (snode->output_to_lto_symbol_table_p ()) | |
2936 fatal_error (input_location, "missing resolution data for %s", | |
2937 IDENTIFIER_POINTER | |
2938 (DECL_ASSEMBLER_NAME (snode->decl))); | |
2939 } | |
2940 else | |
2941 snode->resolution = *res; | |
2942 } | |
2874 for (i = 0; all_file_decl_data[i]; i++) | 2943 for (i = 0; all_file_decl_data[i]; i++) |
2875 if (all_file_decl_data[i]->resolution_map) | 2944 if (all_file_decl_data[i]->resolution_map) |
2876 { | 2945 { |
2877 delete all_file_decl_data[i]->resolution_map; | 2946 delete all_file_decl_data[i]->resolution_map; |
2878 all_file_decl_data[i]->resolution_map = NULL; | 2947 all_file_decl_data[i]->resolution_map = NULL; |
2926 lto_free_function_in_decl_state (all_file_decl_data[i]->global_decl_state); | 2995 lto_free_function_in_decl_state (all_file_decl_data[i]->global_decl_state); |
2927 all_file_decl_data[i]->global_decl_state = NULL; | 2996 all_file_decl_data[i]->global_decl_state = NULL; |
2928 all_file_decl_data[i]->current_decl_state = NULL; | 2997 all_file_decl_data[i]->current_decl_state = NULL; |
2929 } | 2998 } |
2930 | 2999 |
2931 /* Finally merge the cgraph according to the decl merging decisions. */ | |
2932 timevar_push (TV_IPA_LTO_CGRAPH_MERGE); | |
2933 if (symtab->dump_file) | |
2934 { | |
2935 fprintf (symtab->dump_file, "Before merging:\n"); | |
2936 symtab->dump (symtab->dump_file); | |
2937 } | |
2938 if (!flag_ltrans) | 3000 if (!flag_ltrans) |
2939 { | 3001 { |
3002 /* Finally merge the cgraph according to the decl merging decisions. */ | |
3003 timevar_push (TV_IPA_LTO_CGRAPH_MERGE); | |
3004 | |
3005 gcc_assert (!dump_file); | |
3006 dump_file = dump_begin (lto_link_dump_id, NULL); | |
3007 | |
3008 if (dump_file) | |
3009 { | |
3010 fprintf (dump_file, "Before merging:\n"); | |
3011 symtab->dump (dump_file); | |
3012 } | |
2940 lto_symtab_merge_symbols (); | 3013 lto_symtab_merge_symbols (); |
2941 /* Removal of unreachable symbols is needed to make verify_symtab to pass; | 3014 /* Removal of unreachable symbols is needed to make verify_symtab to pass; |
2942 we are still having duplicated comdat groups containing local statics. | 3015 we are still having duplicated comdat groups containing local statics. |
2943 We could also just remove them while merging. */ | 3016 We could also just remove them while merging. */ |
2944 symtab->remove_unreachable_nodes (dump_file); | 3017 symtab->remove_unreachable_nodes (dump_file); |
2945 } | 3018 ggc_collect (); |
2946 ggc_collect (); | 3019 |
3020 if (dump_file) | |
3021 dump_end (lto_link_dump_id, dump_file); | |
3022 dump_file = NULL; | |
3023 timevar_pop (TV_IPA_LTO_CGRAPH_MERGE); | |
3024 } | |
2947 symtab->state = IPA_SSA; | 3025 symtab->state = IPA_SSA; |
2948 /* FIXME: Technically all node removals happening here are useless, because | 3026 /* All node removals happening here are useless, because |
2949 WPA should not stream them. */ | 3027 WPA should not stream them. Still always perform remove_unreachable_nodes |
3028 because we may reshape clone tree, get rid of dead masters of inline | |
3029 clones and remove symbol entries for read-only variables we keep around | |
3030 only to be able to constant fold them. */ | |
2950 if (flag_ltrans) | 3031 if (flag_ltrans) |
2951 symtab->remove_unreachable_nodes (dump_file); | 3032 { |
2952 | 3033 if (symtab->dump_file) |
2953 timevar_pop (TV_IPA_LTO_CGRAPH_MERGE); | 3034 symtab->dump (symtab->dump_file); |
3035 symtab->remove_unreachable_nodes (symtab->dump_file); | |
3036 } | |
2954 | 3037 |
2955 /* Indicate that the cgraph is built and ready. */ | 3038 /* Indicate that the cgraph is built and ready. */ |
2956 symtab->function_flags_ready = true; | 3039 symtab->function_flags_ready = true; |
2957 | 3040 |
2958 ggc_free (all_file_decl_data); | 3041 ggc_free (all_file_decl_data); |
3106 | 3189 |
3107 /* When WPA analysis raises errors, do not bother to output anything. */ | 3190 /* When WPA analysis raises errors, do not bother to output anything. */ |
3108 if (seen_error ()) | 3191 if (seen_error ()) |
3109 return; | 3192 return; |
3110 | 3193 |
3111 if (symtab->dump_file) | 3194 /* We are about to launch the final LTRANS phase, stop the WPA timer. */ |
3112 { | 3195 timevar_pop (TV_WHOPR_WPA); |
3113 fprintf (symtab->dump_file, "Optimized "); | 3196 |
3114 symtab->dump (symtab->dump_file); | 3197 timevar_push (TV_WHOPR_PARTITIONING); |
3115 } | 3198 |
3199 gcc_assert (!dump_file); | |
3200 dump_file = dump_begin (partition_dump_id, NULL); | |
3201 | |
3202 if (dump_file) | |
3203 symtab->dump (dump_file); | |
3116 | 3204 |
3117 symtab_node::checking_verify_symtab_nodes (); | 3205 symtab_node::checking_verify_symtab_nodes (); |
3118 bitmap_obstack_release (NULL); | 3206 bitmap_obstack_release (NULL); |
3119 | |
3120 /* We are about to launch the final LTRANS phase, stop the WPA timer. */ | |
3121 timevar_pop (TV_WHOPR_WPA); | |
3122 | |
3123 timevar_push (TV_WHOPR_PARTITIONING); | |
3124 if (flag_lto_partition == LTO_PARTITION_1TO1) | 3207 if (flag_lto_partition == LTO_PARTITION_1TO1) |
3125 lto_1_to_1_map (); | 3208 lto_1_to_1_map (); |
3126 else if (flag_lto_partition == LTO_PARTITION_MAX) | 3209 else if (flag_lto_partition == LTO_PARTITION_MAX) |
3127 lto_max_map (); | 3210 lto_max_map (); |
3128 else if (flag_lto_partition == LTO_PARTITION_ONE) | 3211 else if (flag_lto_partition == LTO_PARTITION_ONE) |
3146 | 3229 |
3147 /* Find out statics that need to be promoted | 3230 /* Find out statics that need to be promoted |
3148 to globals with hidden visibility because they are accessed from multiple | 3231 to globals with hidden visibility because they are accessed from multiple |
3149 partitions. */ | 3232 partitions. */ |
3150 lto_promote_cross_file_statics (); | 3233 lto_promote_cross_file_statics (); |
3234 if (dump_file) | |
3235 dump_end (partition_dump_id, dump_file); | |
3236 dump_file = NULL; | |
3151 timevar_pop (TV_WHOPR_PARTITIONING); | 3237 timevar_pop (TV_WHOPR_PARTITIONING); |
3152 | 3238 |
3153 timevar_stop (TV_PHASE_OPT_GEN); | 3239 timevar_stop (TV_PHASE_OPT_GEN); |
3154 | 3240 |
3155 /* Collect a last time - in lto_wpa_write_files we may end up forking | 3241 /* Collect a last time - in lto_wpa_write_files we may end up forking |
3207 | 3293 |
3208 static void | 3294 static void |
3209 lto_process_name (void) | 3295 lto_process_name (void) |
3210 { | 3296 { |
3211 if (flag_lto) | 3297 if (flag_lto) |
3212 setproctitle ("lto1-lto"); | 3298 setproctitle (flag_incremental_link == INCREMENTAL_LINK_LTO |
3299 ? "lto1-inclink" : "lto1-lto"); | |
3213 if (flag_wpa) | 3300 if (flag_wpa) |
3214 setproctitle ("lto1-wpa"); | 3301 setproctitle ("lto1-wpa"); |
3215 if (flag_ltrans) | 3302 if (flag_ltrans) |
3216 setproctitle ("lto1-ltrans"); | 3303 setproctitle ("lto1-ltrans"); |
3217 } | 3304 } |
3331 materialize_cgraph (); | 3418 materialize_cgraph (); |
3332 if (!flag_ltrans) | 3419 if (!flag_ltrans) |
3333 lto_promote_statics_nonwpa (); | 3420 lto_promote_statics_nonwpa (); |
3334 | 3421 |
3335 /* Annotate the CU DIE and mark the early debug phase as finished. */ | 3422 /* Annotate the CU DIE and mark the early debug phase as finished. */ |
3423 debuginfo_early_start (); | |
3336 debug_hooks->early_finish ("<artificial>"); | 3424 debug_hooks->early_finish ("<artificial>"); |
3425 debuginfo_early_stop (); | |
3337 | 3426 |
3338 /* Let the middle end know that we have read and merged all of | 3427 /* Let the middle end know that we have read and merged all of |
3339 the input files. */ | 3428 the input files. */ |
3340 symtab->compile (); | 3429 symtab->compile (); |
3341 | 3430 |