Mercurial > hg > CbC > CbC_gcc
comparison gcc/lto-streamer-out.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* Write the GIMPLE representation to a file stream. | 1 /* Write the GIMPLE representation to a file stream. |
2 | 2 |
3 Copyright (C) 2009-2018 Free Software Foundation, Inc. | 3 Copyright (C) 2009-2020 Free Software Foundation, Inc. |
4 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com> | 4 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com> |
5 Re-implemented by Diego Novillo <dnovillo@google.com> | 5 Re-implemented by Diego Novillo <dnovillo@google.com> |
6 | 6 |
7 This file is part of GCC. | 7 This file is part of GCC. |
8 | 8 |
41 #include "builtins.h" | 41 #include "builtins.h" |
42 #include "gomp-constants.h" | 42 #include "gomp-constants.h" |
43 #include "debug.h" | 43 #include "debug.h" |
44 #include "omp-offload.h" | 44 #include "omp-offload.h" |
45 #include "print-tree.h" | 45 #include "print-tree.h" |
46 #include "tree-dfa.h" | |
46 | 47 |
47 | 48 |
48 static void lto_write_tree (struct output_block*, tree, bool); | 49 static void lto_write_tree (struct output_block*, tree, bool); |
49 | 50 |
50 /* Clear the line info stored in DATA_IN. */ | 51 /* Clear the line info stored in DATA_IN. */ |
117 { | 118 { |
118 streamer_write_record_start (ob, LTO_type_ref); | 119 streamer_write_record_start (ob, LTO_type_ref); |
119 lto_output_type_ref_index (ob->decl_state, ob->main_stream, node); | 120 lto_output_type_ref_index (ob->decl_state, ob->main_stream, node); |
120 } | 121 } |
121 | 122 |
123 /* Wrapper around variably_modified_type_p avoiding type modification | |
124 during WPA streaming. */ | |
125 | |
126 static bool | |
127 lto_variably_modified_type_p (tree type) | |
128 { | |
129 return (in_lto_p | |
130 ? TYPE_LANG_FLAG_0 (TYPE_MAIN_VARIANT (type)) | |
131 : variably_modified_type_p (type, NULL_TREE)); | |
132 } | |
133 | |
122 | 134 |
123 /* Return true if tree node T is written to various tables. For these | 135 /* Return true if tree node T is written to various tables. For these |
124 nodes, we sometimes want to write their phyiscal representation | 136 nodes, we sometimes want to write their phyiscal representation |
125 (via lto_output_tree), and sometimes we need to emit an index | 137 (via lto_output_tree), and sometimes we need to emit an index |
126 reference into a table (via lto_output_tree_ref). */ | 138 reference into a table (via lto_output_tree_ref). */ |
131 /* Parameters and return values of functions of variably modified types | 143 /* Parameters and return values of functions of variably modified types |
132 must go to global stream, because they may be used in the type | 144 must go to global stream, because they may be used in the type |
133 definition. */ | 145 definition. */ |
134 if ((TREE_CODE (t) == PARM_DECL || TREE_CODE (t) == RESULT_DECL) | 146 if ((TREE_CODE (t) == PARM_DECL || TREE_CODE (t) == RESULT_DECL) |
135 && DECL_CONTEXT (t)) | 147 && DECL_CONTEXT (t)) |
136 return variably_modified_type_p (TREE_TYPE (DECL_CONTEXT (t)), NULL_TREE); | 148 return lto_variably_modified_type_p (TREE_TYPE (DECL_CONTEXT (t))); |
137 /* IMPORTED_DECL is put into BLOCK and thus it never can be shared. | 149 /* IMPORTED_DECL is put into BLOCK and thus it never can be shared. |
138 We should no longer need to stream it. */ | 150 We should no longer need to stream it. */ |
139 else if (TREE_CODE (t) == IMPORTED_DECL) | 151 else if (TREE_CODE (t) == IMPORTED_DECL) |
140 gcc_unreachable (); | 152 gcc_unreachable (); |
141 else if (TREE_CODE (t) == LABEL_DECL) | 153 else if (TREE_CODE (t) == LABEL_DECL) |
151 /* Variably modified types need to be streamed alongside function | 163 /* Variably modified types need to be streamed alongside function |
152 bodies because they can refer to local entities. Together with | 164 bodies because they can refer to local entities. Together with |
153 them we have to localize their members as well. | 165 them we have to localize their members as well. |
154 ??? In theory that includes non-FIELD_DECLs as well. */ | 166 ??? In theory that includes non-FIELD_DECLs as well. */ |
155 else if (TYPE_P (t) | 167 else if (TYPE_P (t) |
156 && variably_modified_type_p (t, NULL_TREE)) | 168 && lto_variably_modified_type_p (t)) |
157 return false; | 169 return false; |
158 else if (TREE_CODE (t) == FIELD_DECL | 170 else if (TREE_CODE (t) == FIELD_DECL |
159 && variably_modified_type_p (DECL_CONTEXT (t), NULL_TREE)) | 171 && lto_variably_modified_type_p (DECL_CONTEXT (t))) |
160 return false; | 172 return false; |
161 else | 173 else |
162 return (TYPE_P (t) || DECL_P (t) || TREE_CODE (t) == SSA_NAME); | 174 return (TYPE_P (t) || DECL_P (t) || TREE_CODE (t) == SSA_NAME); |
163 } | 175 } |
164 | 176 |
304 | 316 |
305 /* Notice that we reject SSA_NAMEs as well. We only emit the SSA | 317 /* Notice that we reject SSA_NAMEs as well. We only emit the SSA |
306 name version in lto_output_tree_ref (see output_ssa_names). */ | 318 name version in lto_output_tree_ref (see output_ssa_names). */ |
307 return !is_lang_specific (expr) | 319 return !is_lang_specific (expr) |
308 && code != SSA_NAME | 320 && code != SSA_NAME |
309 && code != CALL_EXPR | |
310 && code != LANG_TYPE | 321 && code != LANG_TYPE |
311 && code != MODIFY_EXPR | 322 && code != MODIFY_EXPR |
312 && code != INIT_EXPR | 323 && code != INIT_EXPR |
313 && code != TARGET_EXPR | 324 && code != TARGET_EXPR |
314 && code != BIND_EXPR | 325 && code != BIND_EXPR |
501 struct scc_entry | 512 struct scc_entry |
502 { | 513 { |
503 tree t; | 514 tree t; |
504 hashval_t hash; | 515 hashval_t hash; |
505 }; | 516 }; |
506 vec<scc_entry> sccstack; | 517 auto_vec<scc_entry,32> sccstack; |
507 | 518 |
508 private: | 519 private: |
509 struct sccs | 520 struct sccs |
510 { | 521 { |
511 unsigned int dfsnum; | 522 unsigned int dfsnum; |
531 hashval_t | 542 hashval_t |
532 hash_scc (struct output_block *ob, unsigned first, unsigned size, | 543 hash_scc (struct output_block *ob, unsigned first, unsigned size, |
533 bool ref_p, bool this_ref_p); | 544 bool ref_p, bool this_ref_p); |
534 | 545 |
535 hash_map<tree, sccs *> sccstate; | 546 hash_map<tree, sccs *> sccstate; |
536 vec<worklist> worklist_vec; | 547 auto_vec<worklist, 32> worklist_vec; |
537 struct obstack sccstate_obstack; | 548 struct obstack sccstate_obstack; |
538 }; | 549 }; |
539 | 550 |
540 /* Emit the physical representation of tree node EXPR to output block OB, | 551 /* Emit the physical representation of tree node EXPR to output block OB, |
541 using depth-first search on the subgraph. If THIS_REF_P is true, the | 552 using depth-first search on the subgraph. If THIS_REF_P is true, the |
545 | 556 |
546 DFS::DFS (struct output_block *ob, tree expr, bool ref_p, bool this_ref_p, | 557 DFS::DFS (struct output_block *ob, tree expr, bool ref_p, bool this_ref_p, |
547 bool single_p) | 558 bool single_p) |
548 { | 559 { |
549 unsigned int next_dfs_num = 1; | 560 unsigned int next_dfs_num = 1; |
550 sccstack.create (0); | |
551 gcc_obstack_init (&sccstate_obstack); | 561 gcc_obstack_init (&sccstate_obstack); |
552 worklist_vec = vNULL; | |
553 DFS_write_tree (ob, NULL, expr, ref_p, this_ref_p); | 562 DFS_write_tree (ob, NULL, expr, ref_p, this_ref_p); |
554 while (!worklist_vec.is_empty ()) | 563 while (!worklist_vec.is_empty ()) |
555 { | 564 { |
556 worklist &w = worklist_vec.last (); | 565 worklist &w = worklist_vec.last (); |
557 expr = w.expr; | 566 expr = w.expr; |
722 from_state->low = MIN (from_state->low, cstate->low); | 731 from_state->low = MIN (from_state->low, cstate->low); |
723 if (cstate->dfsnum < from_state->dfsnum) | 732 if (cstate->dfsnum < from_state->dfsnum) |
724 from_state->low = MIN (cstate->dfsnum, from_state->low); | 733 from_state->low = MIN (cstate->dfsnum, from_state->low); |
725 worklist_vec.pop (); | 734 worklist_vec.pop (); |
726 } | 735 } |
727 worklist_vec.release (); | |
728 } | 736 } |
729 | 737 |
730 DFS::~DFS () | 738 DFS::~DFS () |
731 { | 739 { |
732 sccstack.release (); | |
733 obstack_free (&sccstate_obstack, NULL); | 740 obstack_free (&sccstate_obstack, NULL); |
734 } | 741 } |
735 | 742 |
736 /* Handle the tree EXPR in the DFS walk with SCC state EXPR_STATE and | 743 /* Handle the tree EXPR in the DFS walk with SCC state EXPR_STATE and |
737 DFS recurse for all tree edges originating from it. */ | 744 DFS recurse for all tree edges originating from it. */ |
781 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL)) | 788 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL)) |
782 { | 789 { |
783 /* Drop names that were created for anonymous entities. */ | 790 /* Drop names that were created for anonymous entities. */ |
784 if (DECL_NAME (expr) | 791 if (DECL_NAME (expr) |
785 && TREE_CODE (DECL_NAME (expr)) == IDENTIFIER_NODE | 792 && TREE_CODE (DECL_NAME (expr)) == IDENTIFIER_NODE |
786 && anon_aggrname_p (DECL_NAME (expr))) | 793 && IDENTIFIER_ANON_P (DECL_NAME (expr))) |
787 ; | 794 ; |
788 else | 795 else |
789 DFS_follow_tree_edge (DECL_NAME (expr)); | 796 DFS_follow_tree_edge (DECL_NAME (expr)); |
790 if (TREE_CODE (expr) != TRANSLATION_UNIT_DECL | 797 if (TREE_CODE (expr) != TRANSLATION_UNIT_DECL |
791 && ! DECL_CONTEXT (expr)) | 798 && ! DECL_CONTEXT (expr)) |
856 DFS_follow_tree_edge (TYPE_MAIN_VARIANT (expr)); | 863 DFS_follow_tree_edge (TYPE_MAIN_VARIANT (expr)); |
857 DFS_follow_tree_edge (TYPE_CONTEXT (expr)); | 864 DFS_follow_tree_edge (TYPE_CONTEXT (expr)); |
858 /* TYPE_CANONICAL is re-computed during type merging, so no need | 865 /* TYPE_CANONICAL is re-computed during type merging, so no need |
859 to follow it here. */ | 866 to follow it here. */ |
860 /* Do not stream TYPE_STUB_DECL; it is not needed by LTO but currently | 867 /* Do not stream TYPE_STUB_DECL; it is not needed by LTO but currently |
861 it can not be freed by free_lang_data without triggering ICEs in | 868 it cannot be freed by free_lang_data without triggering ICEs in |
862 langhooks. */ | 869 langhooks. */ |
863 } | 870 } |
864 | 871 |
865 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON)) | 872 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON)) |
866 { | 873 { |
1120 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL)) | 1127 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL)) |
1121 { | 1128 { |
1122 hstate.add_int (DECL_BUILT_IN_CLASS (t)); | 1129 hstate.add_int (DECL_BUILT_IN_CLASS (t)); |
1123 hstate.add_flag (DECL_STATIC_CONSTRUCTOR (t)); | 1130 hstate.add_flag (DECL_STATIC_CONSTRUCTOR (t)); |
1124 hstate.add_flag (DECL_STATIC_DESTRUCTOR (t)); | 1131 hstate.add_flag (DECL_STATIC_DESTRUCTOR (t)); |
1132 hstate.add_flag (FUNCTION_DECL_DECL_TYPE (t)); | |
1125 hstate.add_flag (DECL_UNINLINABLE (t)); | 1133 hstate.add_flag (DECL_UNINLINABLE (t)); |
1126 hstate.add_flag (DECL_POSSIBLY_INLINED (t)); | 1134 hstate.add_flag (DECL_POSSIBLY_INLINED (t)); |
1127 hstate.add_flag (DECL_IS_NOVOPS (t)); | 1135 hstate.add_flag (DECL_IS_NOVOPS (t)); |
1128 hstate.add_flag (DECL_IS_RETURNS_TWICE (t)); | 1136 hstate.add_flag (DECL_IS_RETURNS_TWICE (t)); |
1129 hstate.add_flag (DECL_IS_MALLOC (t)); | 1137 hstate.add_flag (DECL_IS_MALLOC (t)); |
1130 hstate.add_flag (DECL_IS_OPERATOR_NEW (t)); | |
1131 hstate.add_flag (DECL_DECLARED_INLINE_P (t)); | 1138 hstate.add_flag (DECL_DECLARED_INLINE_P (t)); |
1132 hstate.add_flag (DECL_STATIC_CHAIN (t)); | 1139 hstate.add_flag (DECL_STATIC_CHAIN (t)); |
1133 hstate.add_flag (DECL_NO_INLINE_WARNING_P (t)); | 1140 hstate.add_flag (DECL_NO_INLINE_WARNING_P (t)); |
1134 hstate.add_flag (DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (t)); | 1141 hstate.add_flag (DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (t)); |
1135 hstate.add_flag (DECL_NO_LIMIT_STACK (t)); | 1142 hstate.add_flag (DECL_NO_LIMIT_STACK (t)); |
1136 hstate.add_flag (DECL_DISREGARD_INLINE_LIMITS (t)); | 1143 hstate.add_flag (DECL_DISREGARD_INLINE_LIMITS (t)); |
1137 hstate.add_flag (DECL_PURE_P (t)); | 1144 hstate.add_flag (DECL_PURE_P (t)); |
1138 hstate.add_flag (DECL_LOOPING_CONST_OR_PURE_P (t)); | 1145 hstate.add_flag (DECL_LOOPING_CONST_OR_PURE_P (t)); |
1139 hstate.commit_flag (); | 1146 hstate.commit_flag (); |
1140 if (DECL_BUILT_IN_CLASS (t) != NOT_BUILT_IN) | 1147 if (DECL_BUILT_IN_CLASS (t) != NOT_BUILT_IN) |
1141 hstate.add_int (DECL_FUNCTION_CODE (t)); | 1148 hstate.add_int (DECL_UNCHECKED_FUNCTION_CODE (t)); |
1142 } | 1149 } |
1143 | 1150 |
1144 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON)) | 1151 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON)) |
1145 { | 1152 { |
1146 hstate.add_hwi (TYPE_MODE (t)); | 1153 hstate.add_hwi (TYPE_MODE (t)); |
1147 hstate.add_flag (TYPE_STRING_FLAG (t)); | |
1148 /* TYPE_NO_FORCE_BLK is private to stor-layout and need | 1154 /* TYPE_NO_FORCE_BLK is private to stor-layout and need |
1149 no streaming. */ | 1155 no streaming. */ |
1150 hstate.add_flag (TYPE_NEEDS_CONSTRUCTING (t)); | |
1151 hstate.add_flag (TYPE_PACKED (t)); | 1156 hstate.add_flag (TYPE_PACKED (t)); |
1152 hstate.add_flag (TYPE_RESTRICT (t)); | 1157 hstate.add_flag (TYPE_RESTRICT (t)); |
1153 hstate.add_flag (TYPE_USER_ALIGN (t)); | 1158 hstate.add_flag (TYPE_USER_ALIGN (t)); |
1154 hstate.add_flag (TYPE_READONLY (t)); | 1159 hstate.add_flag (TYPE_READONLY (t)); |
1155 if (RECORD_OR_UNION_TYPE_P (t)) | 1160 if (RECORD_OR_UNION_TYPE_P (t)) |
1156 { | 1161 { |
1157 hstate.add_flag (TYPE_TRANSPARENT_AGGR (t)); | 1162 hstate.add_flag (TYPE_TRANSPARENT_AGGR (t)); |
1158 hstate.add_flag (TYPE_FINAL_P (t)); | 1163 hstate.add_flag (TYPE_FINAL_P (t)); |
1164 hstate.add_flag (TYPE_CXX_ODR_P (t)); | |
1159 } | 1165 } |
1160 else if (code == ARRAY_TYPE) | 1166 else if (code == ARRAY_TYPE) |
1161 hstate.add_flag (TYPE_NONALIASED_COMPONENT (t)); | 1167 hstate.add_flag (TYPE_NONALIASED_COMPONENT (t)); |
1168 if (code == ARRAY_TYPE || code == INTEGER_TYPE) | |
1169 hstate.add_flag (TYPE_STRING_FLAG (t)); | |
1162 if (AGGREGATE_TYPE_P (t)) | 1170 if (AGGREGATE_TYPE_P (t)) |
1163 hstate.add_flag (TYPE_TYPELESS_STORAGE (t)); | 1171 hstate.add_flag (TYPE_TYPELESS_STORAGE (t)); |
1164 hstate.commit_flag (); | 1172 hstate.commit_flag (); |
1165 hstate.add_int (TYPE_PRECISION (t)); | 1173 hstate.add_int (TYPE_PRECISION (t)); |
1166 hstate.add_int (TYPE_ALIGN (t)); | 1174 hstate.add_int (TYPE_ALIGN (t)); |
1211 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL)) | 1219 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL)) |
1212 { | 1220 { |
1213 /* Drop names that were created for anonymous entities. */ | 1221 /* Drop names that were created for anonymous entities. */ |
1214 if (DECL_NAME (t) | 1222 if (DECL_NAME (t) |
1215 && TREE_CODE (DECL_NAME (t)) == IDENTIFIER_NODE | 1223 && TREE_CODE (DECL_NAME (t)) == IDENTIFIER_NODE |
1216 && anon_aggrname_p (DECL_NAME (t))) | 1224 && IDENTIFIER_ANON_P (DECL_NAME (t))) |
1217 ; | 1225 ; |
1218 else | 1226 else |
1219 visit (DECL_NAME (t)); | 1227 visit (DECL_NAME (t)); |
1220 if (DECL_FILE_SCOPE_P (t)) | 1228 if (DECL_FILE_SCOPE_P (t)) |
1221 ; | 1229 ; |
1355 break; | 1363 break; |
1356 case OMP_CLAUSE_PROC_BIND: | 1364 case OMP_CLAUSE_PROC_BIND: |
1357 val = OMP_CLAUSE_PROC_BIND_KIND (t); | 1365 val = OMP_CLAUSE_PROC_BIND_KIND (t); |
1358 break; | 1366 break; |
1359 case OMP_CLAUSE_REDUCTION: | 1367 case OMP_CLAUSE_REDUCTION: |
1368 case OMP_CLAUSE_TASK_REDUCTION: | |
1369 case OMP_CLAUSE_IN_REDUCTION: | |
1360 val = OMP_CLAUSE_REDUCTION_CODE (t); | 1370 val = OMP_CLAUSE_REDUCTION_CODE (t); |
1361 break; | 1371 break; |
1362 default: | 1372 default: |
1363 val = 0; | 1373 val = 0; |
1364 break; | 1374 break; |
1889 } | 1899 } |
1890 } | 1900 } |
1891 | 1901 |
1892 streamer_write_hwi (ob, -1); | 1902 streamer_write_hwi (ob, -1); |
1893 | 1903 |
1894 bb = ENTRY_BLOCK_PTR_FOR_FN (cfun); | 1904 bb = ENTRY_BLOCK_PTR_FOR_FN (fn); |
1895 while (bb->next_bb) | 1905 while (bb->next_bb) |
1896 { | 1906 { |
1897 streamer_write_hwi (ob, bb->next_bb->index); | 1907 streamer_write_hwi (ob, bb->next_bb->index); |
1898 bb = bb->next_bb; | 1908 bb = bb->next_bb; |
1899 } | 1909 } |
1900 | 1910 |
1901 streamer_write_hwi (ob, -1); | 1911 streamer_write_hwi (ob, -1); |
1902 | 1912 |
1903 /* ??? The cfgloop interface is tied to cfun. */ | |
1904 gcc_assert (cfun == fn); | |
1905 | |
1906 /* Output the number of loops. */ | 1913 /* Output the number of loops. */ |
1907 streamer_write_uhwi (ob, number_of_loops (fn)); | 1914 streamer_write_uhwi (ob, number_of_loops (fn)); |
1908 | 1915 |
1909 /* Output each loop, skipping the tree root which has number zero. */ | 1916 /* Output each loop, skipping the tree root which has number zero. */ |
1910 for (unsigned i = 1; i < number_of_loops (fn); ++i) | 1917 for (unsigned i = 1; i < number_of_loops (fn); ++i) |
1911 { | 1918 { |
1912 struct loop *loop = get_loop (fn, i); | 1919 class loop *loop = get_loop (fn, i); |
1913 | 1920 |
1914 /* Write the index of the loop header. That's enough to rebuild | 1921 /* Write the index of the loop header. That's enough to rebuild |
1915 the loop tree on the reader side. Stream -1 for an unused | 1922 the loop tree on the reader side. Stream -1 for an unused |
1916 loop entry. */ | 1923 loop entry. */ |
1917 if (!loop) | 1924 if (!loop) |
1936 streamer_write_widest_int (ob, loop->nb_iterations_estimate); | 1943 streamer_write_widest_int (ob, loop->nb_iterations_estimate); |
1937 | 1944 |
1938 /* Write OMP SIMD related info. */ | 1945 /* Write OMP SIMD related info. */ |
1939 streamer_write_hwi (ob, loop->safelen); | 1946 streamer_write_hwi (ob, loop->safelen); |
1940 streamer_write_hwi (ob, loop->unroll); | 1947 streamer_write_hwi (ob, loop->unroll); |
1948 streamer_write_hwi (ob, loop->owned_clique); | |
1941 streamer_write_hwi (ob, loop->dont_vectorize); | 1949 streamer_write_hwi (ob, loop->dont_vectorize); |
1942 streamer_write_hwi (ob, loop->force_vectorize); | 1950 streamer_write_hwi (ob, loop->force_vectorize); |
1943 stream_write_tree (ob, loop->simduid, true); | 1951 stream_write_tree (ob, loop->simduid, true); |
1944 } | 1952 } |
1945 | 1953 |
1958 char *section_name; | 1966 char *section_name; |
1959 | 1967 |
1960 if (section_type == LTO_section_function_body) | 1968 if (section_type == LTO_section_function_body) |
1961 { | 1969 { |
1962 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn)); | 1970 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn)); |
1963 section_name = lto_get_section_name (section_type, name, NULL); | 1971 section_name = lto_get_section_name (section_type, name, |
1972 symtab_node::get (fn)->order, | |
1973 NULL); | |
1964 } | 1974 } |
1965 else | 1975 else |
1966 section_name = lto_get_section_name (section_type, NULL, NULL); | 1976 section_name = lto_get_section_name (section_type, NULL, 0, NULL); |
1967 | 1977 |
1968 lto_begin_section (section_name, !flag_wpa); | 1978 lto_begin_section (section_name, !flag_wpa); |
1969 free (section_name); | 1979 free (section_name); |
1970 | 1980 |
1971 /* The entire header is stream computed here. */ | 1981 /* The entire header is stream computed here. */ |
1972 memset (&header, 0, sizeof (struct lto_function_header)); | 1982 memset (&header, 0, sizeof (struct lto_function_header)); |
1973 | |
1974 /* Write the header. */ | |
1975 header.major_version = LTO_major_version; | |
1976 header.minor_version = LTO_minor_version; | |
1977 | 1983 |
1978 if (section_type == LTO_section_function_body) | 1984 if (section_type == LTO_section_function_body) |
1979 header.cfg_size = ob->cfg_stream->total_size; | 1985 header.cfg_size = ob->cfg_stream->total_size; |
1980 header.main_size = ob->main_stream->total_size; | 1986 header.main_size = ob->main_stream->total_size; |
1981 header.string_size = ob->string_stream->total_size; | 1987 header.string_size = ob->string_stream->total_size; |
2026 bp_pack_value (&bp, fn->stdarg, 1); | 2032 bp_pack_value (&bp, fn->stdarg, 1); |
2027 bp_pack_value (&bp, fn->has_nonlocal_label, 1); | 2033 bp_pack_value (&bp, fn->has_nonlocal_label, 1); |
2028 bp_pack_value (&bp, fn->has_forced_label_in_static, 1); | 2034 bp_pack_value (&bp, fn->has_forced_label_in_static, 1); |
2029 bp_pack_value (&bp, fn->calls_alloca, 1); | 2035 bp_pack_value (&bp, fn->calls_alloca, 1); |
2030 bp_pack_value (&bp, fn->calls_setjmp, 1); | 2036 bp_pack_value (&bp, fn->calls_setjmp, 1); |
2037 bp_pack_value (&bp, fn->calls_eh_return, 1); | |
2031 bp_pack_value (&bp, fn->has_force_vectorize_loops, 1); | 2038 bp_pack_value (&bp, fn->has_force_vectorize_loops, 1); |
2032 bp_pack_value (&bp, fn->has_simduid_loops, 1); | 2039 bp_pack_value (&bp, fn->has_simduid_loops, 1); |
2033 bp_pack_value (&bp, fn->va_list_fpr_size, 8); | 2040 bp_pack_value (&bp, fn->va_list_fpr_size, 8); |
2034 bp_pack_value (&bp, fn->va_list_gpr_size, 8); | 2041 bp_pack_value (&bp, fn->va_list_gpr_size, 8); |
2035 bp_pack_value (&bp, fn->last_clique, sizeof (short) * 8); | 2042 bp_pack_value (&bp, fn->last_clique, sizeof (short) * 8); |
2060 leafs.safe_push (root); | 2067 leafs.safe_push (root); |
2061 else | 2068 else |
2062 collect_block_tree_leafs (BLOCK_SUBBLOCKS (root), leafs); | 2069 collect_block_tree_leafs (BLOCK_SUBBLOCKS (root), leafs); |
2063 } | 2070 } |
2064 | 2071 |
2072 /* This performs function body modifications that are needed for streaming | |
2073 to work. */ | |
2074 | |
2075 void | |
2076 lto_prepare_function_for_streaming (struct cgraph_node *node) | |
2077 { | |
2078 struct function *fn = DECL_STRUCT_FUNCTION (node->decl); | |
2079 basic_block bb; | |
2080 | |
2081 if (number_of_loops (fn)) | |
2082 { | |
2083 push_cfun (fn); | |
2084 loop_optimizer_init (AVOID_CFG_MODIFICATIONS); | |
2085 loop_optimizer_finalize (); | |
2086 pop_cfun (); | |
2087 } | |
2088 /* We will renumber the statements. The code that does this uses | |
2089 the same ordering that we use for serializing them so we can use | |
2090 the same code on the other end and not have to write out the | |
2091 statement numbers. We do not assign UIDs to PHIs here because | |
2092 virtual PHIs get re-computed on-the-fly which would make numbers | |
2093 inconsistent. */ | |
2094 set_gimple_stmt_max_uid (fn, 0); | |
2095 FOR_ALL_BB_FN (bb, fn) | |
2096 { | |
2097 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi); | |
2098 gsi_next (&gsi)) | |
2099 { | |
2100 gphi *stmt = gsi.phi (); | |
2101 | |
2102 /* Virtual PHIs are not going to be streamed. */ | |
2103 if (!virtual_operand_p (gimple_phi_result (stmt))) | |
2104 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn)); | |
2105 } | |
2106 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi); | |
2107 gsi_next (&gsi)) | |
2108 { | |
2109 gimple *stmt = gsi_stmt (gsi); | |
2110 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn)); | |
2111 } | |
2112 } | |
2113 /* To avoid keeping duplicate gimple IDs in the statements, renumber | |
2114 virtual phis now. */ | |
2115 FOR_ALL_BB_FN (bb, fn) | |
2116 { | |
2117 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi); | |
2118 gsi_next (&gsi)) | |
2119 { | |
2120 gphi *stmt = gsi.phi (); | |
2121 if (virtual_operand_p (gimple_phi_result (stmt))) | |
2122 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn)); | |
2123 } | |
2124 } | |
2125 | |
2126 } | |
2127 | |
2065 /* Output the body of function NODE->DECL. */ | 2128 /* Output the body of function NODE->DECL. */ |
2066 | 2129 |
2067 static void | 2130 static void |
2068 output_function (struct cgraph_node *node) | 2131 output_function (struct cgraph_node *node) |
2069 { | 2132 { |
2072 basic_block bb; | 2135 basic_block bb; |
2073 struct output_block *ob; | 2136 struct output_block *ob; |
2074 | 2137 |
2075 if (streamer_dump_file) | 2138 if (streamer_dump_file) |
2076 fprintf (streamer_dump_file, "\nStreaming body of %s\n", | 2139 fprintf (streamer_dump_file, "\nStreaming body of %s\n", |
2077 node->name ()); | 2140 node->dump_name ()); |
2078 | 2141 |
2079 function = node->decl; | 2142 function = node->decl; |
2080 fn = DECL_STRUCT_FUNCTION (function); | 2143 fn = DECL_STRUCT_FUNCTION (function); |
2081 ob = create_output_block (LTO_section_function_body); | 2144 ob = create_output_block (LTO_section_function_body); |
2082 | 2145 |
2083 clear_line_info (ob); | 2146 clear_line_info (ob); |
2084 ob->symbol = node; | 2147 ob->symbol = node; |
2085 | 2148 |
2086 gcc_assert (current_function_decl == NULL_TREE && cfun == NULL); | 2149 gcc_assert (current_function_decl == NULL_TREE && cfun == NULL); |
2087 | |
2088 /* Set current_function_decl and cfun. */ | |
2089 push_cfun (fn); | |
2090 | 2150 |
2091 /* Make string 0 be a NULL string. */ | 2151 /* Make string 0 be a NULL string. */ |
2092 streamer_write_char_stream (ob->string_stream, 0); | 2152 streamer_write_char_stream (ob->string_stream, 0); |
2093 | 2153 |
2094 streamer_write_record_start (ob, LTO_function); | 2154 streamer_write_record_start (ob, LTO_function); |
2122 | 2182 |
2123 /* We also stream abstract functions where we stream only stuff needed for | 2183 /* We also stream abstract functions where we stream only stuff needed for |
2124 debug info. */ | 2184 debug info. */ |
2125 if (gimple_has_body_p (function)) | 2185 if (gimple_has_body_p (function)) |
2126 { | 2186 { |
2127 /* Fixup loops if required to match discovery done in the reader. */ | |
2128 loop_optimizer_init (AVOID_CFG_MODIFICATIONS); | |
2129 | |
2130 streamer_write_uhwi (ob, 1); | 2187 streamer_write_uhwi (ob, 1); |
2131 output_struct_function_base (ob, fn); | 2188 output_struct_function_base (ob, fn); |
2132 | 2189 |
2133 /* Output all the SSA names used in the function. */ | 2190 /* Output all the SSA names used in the function. */ |
2134 output_ssa_names (ob, fn); | 2191 output_ssa_names (ob, fn); |
2135 | 2192 |
2136 /* Output any exception handling regions. */ | 2193 /* Output any exception handling regions. */ |
2137 output_eh_regions (ob, fn); | 2194 output_eh_regions (ob, fn); |
2138 | |
2139 | |
2140 /* We will renumber the statements. The code that does this uses | |
2141 the same ordering that we use for serializing them so we can use | |
2142 the same code on the other end and not have to write out the | |
2143 statement numbers. We do not assign UIDs to PHIs here because | |
2144 virtual PHIs get re-computed on-the-fly which would make numbers | |
2145 inconsistent. */ | |
2146 set_gimple_stmt_max_uid (cfun, 0); | |
2147 FOR_ALL_BB_FN (bb, cfun) | |
2148 { | |
2149 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi); | |
2150 gsi_next (&gsi)) | |
2151 { | |
2152 gphi *stmt = gsi.phi (); | |
2153 | |
2154 /* Virtual PHIs are not going to be streamed. */ | |
2155 if (!virtual_operand_p (gimple_phi_result (stmt))) | |
2156 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun)); | |
2157 } | |
2158 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi); | |
2159 gsi_next (&gsi)) | |
2160 { | |
2161 gimple *stmt = gsi_stmt (gsi); | |
2162 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun)); | |
2163 } | |
2164 } | |
2165 /* To avoid keeping duplicate gimple IDs in the statements, renumber | |
2166 virtual phis now. */ | |
2167 FOR_ALL_BB_FN (bb, cfun) | |
2168 { | |
2169 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi); | |
2170 gsi_next (&gsi)) | |
2171 { | |
2172 gphi *stmt = gsi.phi (); | |
2173 if (virtual_operand_p (gimple_phi_result (stmt))) | |
2174 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun)); | |
2175 } | |
2176 } | |
2177 | 2195 |
2178 /* Output the code for the function. */ | 2196 /* Output the code for the function. */ |
2179 FOR_ALL_BB_FN (bb, fn) | 2197 FOR_ALL_BB_FN (bb, fn) |
2180 output_bb (ob, bb, fn); | 2198 output_bb (ob, bb, fn); |
2181 | 2199 |
2182 /* The terminator for this function. */ | 2200 /* The terminator for this function. */ |
2183 streamer_write_record_start (ob, LTO_null); | 2201 streamer_write_record_start (ob, LTO_null); |
2184 | 2202 |
2185 output_cfg (ob, fn); | 2203 output_cfg (ob, fn); |
2186 | |
2187 loop_optimizer_finalize (); | |
2188 pop_cfun (); | |
2189 } | 2204 } |
2190 else | 2205 else |
2191 streamer_write_uhwi (ob, 0); | 2206 streamer_write_uhwi (ob, 0); |
2192 | 2207 |
2193 /* Create a section to hold the pickled output of this function. */ | 2208 /* Create a section to hold the pickled output of this function. */ |
2194 produce_asm (ob, function); | 2209 produce_asm (ob, function); |
2195 | 2210 |
2196 destroy_output_block (ob); | 2211 destroy_output_block (ob); |
2197 if (streamer_dump_file) | 2212 if (streamer_dump_file) |
2198 fprintf (streamer_dump_file, "Finished streaming %s\n", | 2213 fprintf (streamer_dump_file, "Finished streaming %s\n", |
2199 node->name ()); | 2214 node->dump_name ()); |
2200 } | 2215 } |
2201 | 2216 |
2202 /* Output the body of function NODE->DECL. */ | 2217 /* Output the body of function NODE->DECL. */ |
2203 | 2218 |
2204 static void | 2219 static void |
2207 tree var = node->decl; | 2222 tree var = node->decl; |
2208 struct output_block *ob; | 2223 struct output_block *ob; |
2209 | 2224 |
2210 if (streamer_dump_file) | 2225 if (streamer_dump_file) |
2211 fprintf (streamer_dump_file, "\nStreaming constructor of %s\n", | 2226 fprintf (streamer_dump_file, "\nStreaming constructor of %s\n", |
2212 node->name ()); | 2227 node->dump_name ()); |
2213 | 2228 |
2229 timevar_push (TV_IPA_LTO_CTORS_OUT); | |
2214 ob = create_output_block (LTO_section_function_body); | 2230 ob = create_output_block (LTO_section_function_body); |
2215 | 2231 |
2216 clear_line_info (ob); | 2232 clear_line_info (ob); |
2217 ob->symbol = node; | 2233 ob->symbol = node; |
2218 | 2234 |
2227 produce_asm (ob, var); | 2243 produce_asm (ob, var); |
2228 | 2244 |
2229 destroy_output_block (ob); | 2245 destroy_output_block (ob); |
2230 if (streamer_dump_file) | 2246 if (streamer_dump_file) |
2231 fprintf (streamer_dump_file, "Finished streaming %s\n", | 2247 fprintf (streamer_dump_file, "Finished streaming %s\n", |
2232 node->name ()); | 2248 node->dump_name ()); |
2249 timevar_pop (TV_IPA_LTO_CTORS_OUT); | |
2233 } | 2250 } |
2234 | 2251 |
2235 | 2252 |
2236 /* Emit toplevel asms. */ | 2253 /* Emit toplevel asms. */ |
2237 | 2254 |
2257 streamer_write_hwi (ob, can->order); | 2274 streamer_write_hwi (ob, can->order); |
2258 } | 2275 } |
2259 | 2276 |
2260 streamer_write_string_cst (ob, ob->main_stream, NULL_TREE); | 2277 streamer_write_string_cst (ob, ob->main_stream, NULL_TREE); |
2261 | 2278 |
2262 section_name = lto_get_section_name (LTO_section_asm, NULL, NULL); | 2279 section_name = lto_get_section_name (LTO_section_asm, NULL, 0, NULL); |
2263 lto_begin_section (section_name, !flag_wpa); | 2280 lto_begin_section (section_name, !flag_wpa); |
2264 free (section_name); | 2281 free (section_name); |
2265 | 2282 |
2266 /* The entire header stream is computed here. */ | 2283 /* The entire header stream is computed here. */ |
2267 memset (&header, 0, sizeof (header)); | 2284 memset (&header, 0, sizeof (header)); |
2268 | |
2269 /* Write the header. */ | |
2270 header.major_version = LTO_major_version; | |
2271 header.minor_version = LTO_minor_version; | |
2272 | 2285 |
2273 header.main_size = ob->main_stream->total_size; | 2286 header.main_size = ob->main_stream->total_size; |
2274 header.string_size = ob->string_stream->total_size; | 2287 header.string_size = ob->string_stream->total_size; |
2275 lto_write_data (&header, sizeof header); | 2288 lto_write_data (&header, sizeof header); |
2276 | 2289 |
2294 struct lto_file_decl_data *file_data = node->lto_file_data; | 2307 struct lto_file_decl_data *file_data = node->lto_file_data; |
2295 const char *data; | 2308 const char *data; |
2296 size_t len; | 2309 size_t len; |
2297 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function)); | 2310 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function)); |
2298 char *section_name = | 2311 char *section_name = |
2299 lto_get_section_name (LTO_section_function_body, name, NULL); | 2312 lto_get_section_name (LTO_section_function_body, name, node->order, NULL); |
2300 size_t i, j; | 2313 size_t i, j; |
2301 struct lto_in_decl_state *in_state; | 2314 struct lto_in_decl_state *in_state; |
2302 struct lto_out_decl_state *out_state = lto_get_out_decl_state (); | 2315 struct lto_out_decl_state *out_state = lto_get_out_decl_state (); |
2303 | 2316 |
2304 if (streamer_dump_file) | 2317 if (streamer_dump_file) |
2308 | 2321 |
2309 /* We may have renamed the declaration, e.g., a static function. */ | 2322 /* We may have renamed the declaration, e.g., a static function. */ |
2310 name = lto_get_decl_name_mapping (file_data, name); | 2323 name = lto_get_decl_name_mapping (file_data, name); |
2311 | 2324 |
2312 data = lto_get_raw_section_data (file_data, LTO_section_function_body, | 2325 data = lto_get_raw_section_data (file_data, LTO_section_function_body, |
2313 name, &len); | 2326 name, node->order - file_data->order_base, |
2327 &len); | |
2314 gcc_assert (data); | 2328 gcc_assert (data); |
2315 | 2329 |
2316 /* Do a bit copy of the function body. */ | 2330 /* Do a bit copy of the function body. */ |
2317 lto_write_raw_data (data, len); | 2331 lto_write_raw_data (data, len); |
2318 | 2332 |
2384 tree fn_decl; | 2398 tree fn_decl; |
2385 FOR_EACH_VEC_ELT (*offload_funcs, ix, fn_decl) | 2399 FOR_EACH_VEC_ELT (*offload_funcs, ix, fn_decl) |
2386 DECL_PRESERVE_P (fn_decl) = 1; | 2400 DECL_PRESERVE_P (fn_decl) = 1; |
2387 } | 2401 } |
2388 | 2402 |
2403 /* Produce LTO section that contains global information | |
2404 about LTO bytecode. */ | |
2405 | |
2406 static void | |
2407 produce_lto_section () | |
2408 { | |
2409 /* Stream LTO meta section. */ | |
2410 output_block *ob = create_output_block (LTO_section_lto); | |
2411 | |
2412 char * section_name = lto_get_section_name (LTO_section_lto, NULL, 0, NULL); | |
2413 lto_begin_section (section_name, false); | |
2414 free (section_name); | |
2415 | |
2416 #ifdef HAVE_ZSTD_H | |
2417 lto_compression compression = ZSTD; | |
2418 #else | |
2419 lto_compression compression = ZLIB; | |
2420 #endif | |
2421 | |
2422 bool slim_object = flag_generate_lto && !flag_fat_lto_objects; | |
2423 lto_section s | |
2424 = { LTO_major_version, LTO_minor_version, slim_object, 0 }; | |
2425 s.set_compression (compression); | |
2426 lto_write_data (&s, sizeof s); | |
2427 lto_end_section (); | |
2428 destroy_output_block (ob); | |
2429 } | |
2430 | |
2431 /* Compare symbols to get them sorted by filename (to optimize streaming) */ | |
2432 | |
2433 static int | |
2434 cmp_symbol_files (const void *pn1, const void *pn2) | |
2435 { | |
2436 const symtab_node *n1 = *(const symtab_node * const *)pn1; | |
2437 const symtab_node *n2 = *(const symtab_node * const *)pn2; | |
2438 | |
2439 int file_order1 = n1->lto_file_data ? n1->lto_file_data->order : -1; | |
2440 int file_order2 = n2->lto_file_data ? n2->lto_file_data->order : -1; | |
2441 | |
2442 /* Order files same way as they appeared in the command line to reduce | |
2443 seeking while copying sections. */ | |
2444 if (file_order1 != file_order2) | |
2445 return file_order1 - file_order2; | |
2446 | |
2447 /* Order within static library. */ | |
2448 if (n1->lto_file_data && n1->lto_file_data->id != n2->lto_file_data->id) | |
2449 { | |
2450 if (n1->lto_file_data->id > n2->lto_file_data->id) | |
2451 return 1; | |
2452 if (n1->lto_file_data->id < n2->lto_file_data->id) | |
2453 return -1; | |
2454 } | |
2455 | |
2456 /* And finaly order by the definition order. */ | |
2457 return n1->order - n2->order; | |
2458 } | |
2459 | |
2389 /* Main entry point from the pass manager. */ | 2460 /* Main entry point from the pass manager. */ |
2390 | 2461 |
2391 void | 2462 void |
2392 lto_output (void) | 2463 lto_output (void) |
2393 { | 2464 { |
2394 struct lto_out_decl_state *decl_state; | 2465 struct lto_out_decl_state *decl_state; |
2395 bitmap output = NULL; | 2466 bitmap output = NULL; |
2396 int i, n_nodes; | 2467 bitmap_obstack output_obstack; |
2468 unsigned int i, n_nodes; | |
2397 lto_symtab_encoder_t encoder = lto_get_out_decl_state ()->symtab_node_encoder; | 2469 lto_symtab_encoder_t encoder = lto_get_out_decl_state ()->symtab_node_encoder; |
2470 auto_vec<symtab_node *> symbols_to_copy; | |
2398 | 2471 |
2399 prune_offload_funcs (); | 2472 prune_offload_funcs (); |
2400 | 2473 |
2401 if (flag_checking) | 2474 if (flag_checking) |
2402 output = lto_bitmap_alloc (); | 2475 { |
2476 bitmap_obstack_initialize (&output_obstack); | |
2477 output = BITMAP_ALLOC (&output_obstack); | |
2478 } | |
2403 | 2479 |
2404 /* Initialize the streamer. */ | 2480 /* Initialize the streamer. */ |
2405 lto_streamer_init (); | 2481 lto_streamer_init (); |
2406 | 2482 |
2483 produce_lto_section (); | |
2484 | |
2407 n_nodes = lto_symtab_encoder_size (encoder); | 2485 n_nodes = lto_symtab_encoder_size (encoder); |
2408 /* Process only the functions with bodies. */ | 2486 /* Prepare vector of functions to output and then sort it to optimize |
2487 section copying. */ | |
2409 for (i = 0; i < n_nodes; i++) | 2488 for (i = 0; i < n_nodes; i++) |
2410 { | 2489 { |
2411 symtab_node *snode = lto_symtab_encoder_deref (encoder, i); | 2490 symtab_node *snode = lto_symtab_encoder_deref (encoder, i); |
2491 if (snode->alias) | |
2492 continue; | |
2412 if (cgraph_node *node = dyn_cast <cgraph_node *> (snode)) | 2493 if (cgraph_node *node = dyn_cast <cgraph_node *> (snode)) |
2413 { | 2494 { |
2414 if (lto_symtab_encoder_encode_body_p (encoder, node) | 2495 if (lto_symtab_encoder_encode_body_p (encoder, node)) |
2415 && !node->alias | 2496 symbols_to_copy.safe_push (node); |
2416 && (!node->thunk.thunk_p || !node->thunk.add_pointer_bounds_args)) | |
2417 { | |
2418 if (flag_checking) | |
2419 { | |
2420 gcc_assert (!bitmap_bit_p (output, DECL_UID (node->decl))); | |
2421 bitmap_set_bit (output, DECL_UID (node->decl)); | |
2422 } | |
2423 decl_state = lto_new_out_decl_state (); | |
2424 lto_push_out_decl_state (decl_state); | |
2425 if (gimple_has_body_p (node->decl) | |
2426 || (!flag_wpa | |
2427 && flag_incremental_link != INCREMENTAL_LINK_LTO) | |
2428 /* Thunks have no body but they may be synthetized | |
2429 at WPA time. */ | |
2430 || DECL_ARGUMENTS (node->decl)) | |
2431 output_function (node); | |
2432 else | |
2433 copy_function_or_variable (node); | |
2434 gcc_assert (lto_get_out_decl_state () == decl_state); | |
2435 lto_pop_out_decl_state (); | |
2436 lto_record_function_out_decl_state (node->decl, decl_state); | |
2437 } | |
2438 } | 2497 } |
2439 else if (varpool_node *node = dyn_cast <varpool_node *> (snode)) | 2498 else if (varpool_node *node = dyn_cast <varpool_node *> (snode)) |
2440 { | 2499 { |
2441 /* Wrap symbol references inside the ctor in a type | 2500 /* Wrap symbol references inside the ctor in a type |
2442 preserving MEM_REF. */ | 2501 preserving MEM_REF. */ |
2443 tree ctor = DECL_INITIAL (node->decl); | 2502 tree ctor = DECL_INITIAL (node->decl); |
2444 if (ctor && !in_lto_p) | 2503 if (ctor && !in_lto_p) |
2445 walk_tree (&ctor, wrap_refs, NULL, NULL); | 2504 walk_tree (&ctor, wrap_refs, NULL, NULL); |
2446 if (get_symbol_initial_value (encoder, node->decl) == error_mark_node | 2505 if (get_symbol_initial_value (encoder, node->decl) == error_mark_node |
2447 && lto_symtab_encoder_encode_initializer_p (encoder, node) | 2506 && lto_symtab_encoder_encode_initializer_p (encoder, node)) |
2448 && !node->alias) | 2507 symbols_to_copy.safe_push (node); |
2449 { | |
2450 timevar_push (TV_IPA_LTO_CTORS_OUT); | |
2451 if (flag_checking) | |
2452 { | |
2453 gcc_assert (!bitmap_bit_p (output, DECL_UID (node->decl))); | |
2454 bitmap_set_bit (output, DECL_UID (node->decl)); | |
2455 } | |
2456 decl_state = lto_new_out_decl_state (); | |
2457 lto_push_out_decl_state (decl_state); | |
2458 if (DECL_INITIAL (node->decl) != error_mark_node | |
2459 || (!flag_wpa | |
2460 && flag_incremental_link != INCREMENTAL_LINK_LTO)) | |
2461 output_constructor (node); | |
2462 else | |
2463 copy_function_or_variable (node); | |
2464 gcc_assert (lto_get_out_decl_state () == decl_state); | |
2465 lto_pop_out_decl_state (); | |
2466 lto_record_function_out_decl_state (node->decl, decl_state); | |
2467 timevar_pop (TV_IPA_LTO_CTORS_OUT); | |
2468 } | |
2469 } | 2508 } |
2509 } | |
2510 symbols_to_copy.qsort (cmp_symbol_files); | |
2511 for (i = 0; i < symbols_to_copy.length (); i++) | |
2512 { | |
2513 symtab_node *snode = symbols_to_copy[i]; | |
2514 cgraph_node *cnode; | |
2515 varpool_node *vnode; | |
2516 | |
2517 if (flag_checking) | |
2518 gcc_assert (bitmap_set_bit (output, DECL_UID (snode->decl))); | |
2519 | |
2520 decl_state = lto_new_out_decl_state (); | |
2521 lto_push_out_decl_state (decl_state); | |
2522 | |
2523 if ((cnode = dyn_cast <cgraph_node *> (snode)) | |
2524 && (gimple_has_body_p (cnode->decl) | |
2525 || (!flag_wpa | |
2526 && flag_incremental_link != INCREMENTAL_LINK_LTO) | |
2527 /* Thunks have no body but they may be synthetized | |
2528 at WPA time. */ | |
2529 || DECL_ARGUMENTS (cnode->decl))) | |
2530 output_function (cnode); | |
2531 else if ((vnode = dyn_cast <varpool_node *> (snode)) | |
2532 && (DECL_INITIAL (vnode->decl) != error_mark_node | |
2533 || (!flag_wpa | |
2534 && flag_incremental_link != INCREMENTAL_LINK_LTO))) | |
2535 output_constructor (vnode); | |
2536 else | |
2537 copy_function_or_variable (snode); | |
2538 gcc_assert (lto_get_out_decl_state () == decl_state); | |
2539 lto_pop_out_decl_state (); | |
2540 lto_record_function_out_decl_state (snode->decl, decl_state); | |
2470 } | 2541 } |
2471 | 2542 |
2472 /* Emit the callgraph after emitting function bodies. This needs to | 2543 /* Emit the callgraph after emitting function bodies. This needs to |
2473 be done now to make sure that all the statements in every function | 2544 be done now to make sure that all the statements in every function |
2474 have been renumbered so that edges can be associated with call | 2545 have been renumbered so that edges can be associated with call |
2475 statements using the statement UIDs. */ | 2546 statements using the statement UIDs. */ |
2476 output_symtab (); | 2547 output_symtab (); |
2477 | 2548 |
2478 output_offload_tables (); | 2549 output_offload_tables (); |
2479 | 2550 |
2480 #if CHECKING_P | 2551 if (flag_checking) |
2481 lto_bitmap_free (output); | 2552 { |
2482 #endif | 2553 BITMAP_FREE (output); |
2554 bitmap_obstack_release (&output_obstack); | |
2555 } | |
2483 } | 2556 } |
2484 | 2557 |
2485 /* Write each node in encoded by ENCODER to OB, as well as those reachable | 2558 /* Write each node in encoded by ENCODER to OB, as well as those reachable |
2486 from it and required for correct representation of its semantics. | 2559 from it and required for correct representation of its semantics. |
2487 Each node in ENCODER must be a global declaration or a type. A node | 2560 Each node in ENCODER must be a global declaration or a type. A node |
2614 enum gcc_plugin_symbol_visibility visibility = GCCPV_DEFAULT; | 2687 enum gcc_plugin_symbol_visibility visibility = GCCPV_DEFAULT; |
2615 unsigned slot_num; | 2688 unsigned slot_num; |
2616 uint64_t size; | 2689 uint64_t size; |
2617 const char *comdat; | 2690 const char *comdat; |
2618 unsigned char c; | 2691 unsigned char c; |
2619 | |
2620 gcc_checking_assert (TREE_PUBLIC (t) | |
2621 && (TREE_CODE (t) != FUNCTION_DECL | |
2622 || !fndecl_built_in_p (t)) | |
2623 && !DECL_ABSTRACT_P (t) | |
2624 && (!VAR_P (t) || !DECL_HARD_REGISTER (t))); | |
2625 | 2692 |
2626 gcc_assert (VAR_OR_FUNCTION_DECL_P (t)); | 2693 gcc_assert (VAR_OR_FUNCTION_DECL_P (t)); |
2627 | 2694 |
2628 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t)); | 2695 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t)); |
2629 | 2696 |
2714 | 2781 |
2715 static void | 2782 static void |
2716 produce_symtab (struct output_block *ob) | 2783 produce_symtab (struct output_block *ob) |
2717 { | 2784 { |
2718 struct streamer_tree_cache_d *cache = ob->writer_cache; | 2785 struct streamer_tree_cache_d *cache = ob->writer_cache; |
2719 char *section_name = lto_get_section_name (LTO_section_symtab, NULL, NULL); | 2786 char *section_name = lto_get_section_name (LTO_section_symtab, NULL, 0, NULL); |
2720 lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder; | 2787 lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder; |
2721 lto_symtab_encoder_iterator lsei; | 2788 lto_symtab_encoder_iterator lsei; |
2722 | 2789 |
2723 lto_begin_section (section_name, false); | 2790 lto_begin_section (section_name, false); |
2724 free (section_name); | 2791 free (section_name); |
2814 bp_pack_value (&bp, VOIDmode, 8); | 2881 bp_pack_value (&bp, VOIDmode, 8); |
2815 | 2882 |
2816 streamer_write_bitpack (&bp); | 2883 streamer_write_bitpack (&bp); |
2817 | 2884 |
2818 char *section_name | 2885 char *section_name |
2819 = lto_get_section_name (LTO_section_mode_table, NULL, NULL); | 2886 = lto_get_section_name (LTO_section_mode_table, NULL, 0, NULL); |
2820 lto_begin_section (section_name, !flag_wpa); | 2887 lto_begin_section (section_name, !flag_wpa); |
2821 free (section_name); | 2888 free (section_name); |
2822 | 2889 |
2823 /* The entire header stream is computed here. */ | 2890 /* The entire header stream is computed here. */ |
2824 struct lto_simple_header_with_strings header; | 2891 struct lto_simple_header_with_strings header; |
2825 memset (&header, 0, sizeof (header)); | 2892 memset (&header, 0, sizeof (header)); |
2826 | |
2827 /* Write the header. */ | |
2828 header.major_version = LTO_major_version; | |
2829 header.minor_version = LTO_minor_version; | |
2830 | 2893 |
2831 header.main_size = ob->main_stream->total_size; | 2894 header.main_size = ob->main_stream->total_size; |
2832 header.string_size = ob->string_stream->total_size; | 2895 header.string_size = ob->string_stream->total_size; |
2833 lto_write_data (&header, sizeof header); | 2896 lto_write_data (&header, sizeof header); |
2834 | 2897 |
2862 | 2925 |
2863 ob = create_output_block (LTO_section_decls); | 2926 ob = create_output_block (LTO_section_decls); |
2864 | 2927 |
2865 memset (&header, 0, sizeof (struct lto_decl_header)); | 2928 memset (&header, 0, sizeof (struct lto_decl_header)); |
2866 | 2929 |
2867 section_name = lto_get_section_name (LTO_section_decls, NULL, NULL); | 2930 section_name = lto_get_section_name (LTO_section_decls, NULL, 0, NULL); |
2868 lto_begin_section (section_name, !flag_wpa); | 2931 lto_begin_section (section_name, !flag_wpa); |
2869 free (section_name); | 2932 free (section_name); |
2870 | 2933 |
2871 /* Make string 0 be a NULL string. */ | 2934 /* Make string 0 be a NULL string. */ |
2872 streamer_write_char_stream (ob->string_stream, 0); | 2935 streamer_write_char_stream (ob->string_stream, 0); |
2896 IDENTIFIER_POINTER | 2959 IDENTIFIER_POINTER |
2897 (DECL_ASSEMBLER_NAME (fn_out_state->fn_decl))); | 2960 (DECL_ASSEMBLER_NAME (fn_out_state->fn_decl))); |
2898 lto_output_decl_state_streams (ob, fn_out_state); | 2961 lto_output_decl_state_streams (ob, fn_out_state); |
2899 } | 2962 } |
2900 | 2963 |
2901 header.major_version = LTO_major_version; | |
2902 header.minor_version = LTO_minor_version; | |
2903 | |
2904 /* Currently not used. This field would allow us to preallocate | 2964 /* Currently not used. This field would allow us to preallocate |
2905 the globals vector, so that it need not be resized as it is extended. */ | 2965 the globals vector, so that it need not be resized as it is extended. */ |
2906 header.num_nodes = -1; | 2966 header.num_nodes = -1; |
2907 | 2967 |
2908 /* Compute the total size of all decl out states. */ | 2968 /* Compute the total size of all decl out states. */ |