comparison gcc/lto-streamer-out.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 /* Write the GIMPLE representation to a file stream. 1 /* Write the GIMPLE representation to a file stream.
2 2
3 Copyright (C) 2009-2017 Free Software Foundation, Inc. 3 Copyright (C) 2009-2018 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
39 #include "cgraph.h" 39 #include "cgraph.h"
40 #include "cfgloop.h" 40 #include "cfgloop.h"
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"
45 #include "print-tree.h"
44 46
45 47
46 static void lto_write_tree (struct output_block*, tree, bool); 48 static void lto_write_tree (struct output_block*, tree, bool);
47 49
48 /* Clear the line info stored in DATA_IN. */ 50 /* Clear the line info stored in DATA_IN. */
62 64
63 struct output_block * 65 struct output_block *
64 create_output_block (enum lto_section_type section_type) 66 create_output_block (enum lto_section_type section_type)
65 { 67 {
66 struct output_block *ob = XCNEW (struct output_block); 68 struct output_block *ob = XCNEW (struct output_block);
69 if (streamer_dump_file)
70 fprintf (streamer_dump_file, "Creating output block for %s\n",
71 lto_section_name [section_type]);
67 72
68 ob->section_type = section_type; 73 ob->section_type = section_type;
69 ob->decl_state = lto_get_out_decl_state (); 74 ob->decl_state = lto_get_out_decl_state ();
70 ob->main_stream = XCNEW (struct lto_output_stream); 75 ob->main_stream = XCNEW (struct lto_output_stream);
71 ob->string_stream = XCNEW (struct lto_output_stream); 76 ob->string_stream = XCNEW (struct lto_output_stream);
127 must go to global stream, because they may be used in the type 132 must go to global stream, because they may be used in the type
128 definition. */ 133 definition. */
129 if ((TREE_CODE (t) == PARM_DECL || TREE_CODE (t) == RESULT_DECL) 134 if ((TREE_CODE (t) == PARM_DECL || TREE_CODE (t) == RESULT_DECL)
130 && DECL_CONTEXT (t)) 135 && DECL_CONTEXT (t))
131 return variably_modified_type_p (TREE_TYPE (DECL_CONTEXT (t)), NULL_TREE); 136 return variably_modified_type_p (TREE_TYPE (DECL_CONTEXT (t)), NULL_TREE);
132 /* IMPORTED_DECL is put into BLOCK and thus it never can be shared. */ 137 /* IMPORTED_DECL is put into BLOCK and thus it never can be shared.
138 We should no longer need to stream it. */
133 else if (TREE_CODE (t) == IMPORTED_DECL) 139 else if (TREE_CODE (t) == IMPORTED_DECL)
134 return false; 140 gcc_unreachable ();
141 else if (TREE_CODE (t) == LABEL_DECL)
142 return FORCED_LABEL (t) || DECL_NONLOCAL (t);
135 else if (((VAR_P (t) && !TREE_STATIC (t)) 143 else if (((VAR_P (t) && !TREE_STATIC (t))
136 || TREE_CODE (t) == TYPE_DECL 144 || TREE_CODE (t) == TYPE_DECL
137 || TREE_CODE (t) == CONST_DECL 145 || TREE_CODE (t) == CONST_DECL
138 || TREE_CODE (t) == NAMELIST_DECL) 146 || TREE_CODE (t) == NAMELIST_DECL)
139 && decl_function_context (t)) 147 && decl_function_context (t))
735 #define DFS_follow_tree_edge(DEST) \ 743 #define DFS_follow_tree_edge(DEST) \
736 DFS_write_tree (ob, expr_state, DEST, ref_p, ref_p) 744 DFS_write_tree (ob, expr_state, DEST, ref_p, ref_p)
737 745
738 enum tree_code code; 746 enum tree_code code;
739 747
748 if (streamer_dump_file)
749 {
750 print_node_brief (streamer_dump_file, " Streaming ",
751 expr, 4);
752 fprintf (streamer_dump_file, " to %s\n",
753 lto_section_name [ob->section_type]);
754 }
755
740 code = TREE_CODE (expr); 756 code = TREE_CODE (expr);
741 757
742 if (CODE_CONTAINS_STRUCT (code, TS_TYPED)) 758 if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
743 { 759 {
744 if (TREE_CODE (expr) != IDENTIFIER_NODE) 760 if (TREE_CODE (expr) != IDENTIFIER_NODE)
745 DFS_follow_tree_edge (TREE_TYPE (expr)); 761 DFS_follow_tree_edge (TREE_TYPE (expr));
746 } 762 }
747 763
748 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR)) 764 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
749 { 765 {
750 for (unsigned i = 0; i < VECTOR_CST_NELTS (expr); ++i) 766 unsigned int count = vector_cst_encoded_nelts (expr);
751 DFS_follow_tree_edge (VECTOR_CST_ELT (expr, i)); 767 for (unsigned int i = 0; i < count; ++i)
752 } 768 DFS_follow_tree_edge (VECTOR_CST_ENCODED_ELT (expr, i));
769 }
770
771 if (CODE_CONTAINS_STRUCT (code, TS_POLY_INT_CST))
772 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
773 DFS_follow_tree_edge (POLY_INT_CST_COEFF (expr, i));
753 774
754 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX)) 775 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
755 { 776 {
756 DFS_follow_tree_edge (TREE_REALPART (expr)); 777 DFS_follow_tree_edge (TREE_REALPART (expr));
757 DFS_follow_tree_edge (TREE_IMAGPART (expr)); 778 DFS_follow_tree_edge (TREE_IMAGPART (expr));
781 /* Note, DECL_INITIAL is not handled here. Since DECL_INITIAL needs 802 /* Note, DECL_INITIAL is not handled here. Since DECL_INITIAL needs
782 special handling in LTO, it must be handled by streamer hooks. */ 803 special handling in LTO, it must be handled by streamer hooks. */
783 804
784 DFS_follow_tree_edge (DECL_ATTRIBUTES (expr)); 805 DFS_follow_tree_edge (DECL_ATTRIBUTES (expr));
785 806
786 /* Do not follow DECL_ABSTRACT_ORIGIN. We cannot handle debug information 807 /* We use DECL_ABSTRACT_ORIGIN == error_mark_node to mark
787 for early inlining so drop it on the floor instead of ICEing in
788 dwarf2out.c.
789 We however use DECL_ABSTRACT_ORIGIN == error_mark_node to mark
790 declarations which should be eliminated by decl merging. Be sure none 808 declarations which should be eliminated by decl merging. Be sure none
791 leaks to this point. */ 809 leaks to this point. */
792 gcc_assert (DECL_ABSTRACT_ORIGIN (expr) != error_mark_node); 810 gcc_assert (DECL_ABSTRACT_ORIGIN (expr) != error_mark_node);
793 DFS_follow_tree_edge (DECL_ABSTRACT_ORIGIN (expr)); 811 DFS_follow_tree_edge (DECL_ABSTRACT_ORIGIN (expr));
794 812
795 if ((VAR_P (expr) 813 if ((VAR_P (expr)
796 || TREE_CODE (expr) == PARM_DECL) 814 || TREE_CODE (expr) == PARM_DECL)
797 && DECL_HAS_VALUE_EXPR_P (expr)) 815 && DECL_HAS_VALUE_EXPR_P (expr))
798 DFS_follow_tree_edge (DECL_VALUE_EXPR (expr)); 816 DFS_follow_tree_edge (DECL_VALUE_EXPR (expr));
799 if (VAR_P (expr)) 817 if (VAR_P (expr)
818 && DECL_HAS_DEBUG_EXPR_P (expr))
800 DFS_follow_tree_edge (DECL_DEBUG_EXPR (expr)); 819 DFS_follow_tree_edge (DECL_DEBUG_EXPR (expr));
801 }
802
803 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
804 {
805 if (TREE_CODE (expr) == TYPE_DECL)
806 DFS_follow_tree_edge (DECL_ORIGINAL_TYPE (expr));
807 } 820 }
808 821
809 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS)) 822 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
810 { 823 {
811 /* Make sure we don't inadvertently set the assembler name. */ 824 /* Make sure we don't inadvertently set the assembler name. */
817 { 830 {
818 DFS_follow_tree_edge (DECL_FIELD_OFFSET (expr)); 831 DFS_follow_tree_edge (DECL_FIELD_OFFSET (expr));
819 DFS_follow_tree_edge (DECL_BIT_FIELD_TYPE (expr)); 832 DFS_follow_tree_edge (DECL_BIT_FIELD_TYPE (expr));
820 DFS_follow_tree_edge (DECL_BIT_FIELD_REPRESENTATIVE (expr)); 833 DFS_follow_tree_edge (DECL_BIT_FIELD_REPRESENTATIVE (expr));
821 DFS_follow_tree_edge (DECL_FIELD_BIT_OFFSET (expr)); 834 DFS_follow_tree_edge (DECL_FIELD_BIT_OFFSET (expr));
822 DFS_follow_tree_edge (DECL_FCONTEXT (expr)); 835 gcc_checking_assert (!DECL_FCONTEXT (expr));
823 } 836 }
824 837
825 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL)) 838 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
826 { 839 {
827 DFS_follow_tree_edge (DECL_VINDEX (expr)); 840 gcc_checking_assert (DECL_VINDEX (expr) == NULL);
828 DFS_follow_tree_edge (DECL_FUNCTION_PERSONALITY (expr)); 841 DFS_follow_tree_edge (DECL_FUNCTION_PERSONALITY (expr));
829 DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_TARGET (expr)); 842 DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_TARGET (expr));
830 DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr)); 843 DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr));
831 } 844 }
832 845
842 during fixup. */ 855 during fixup. */
843 DFS_follow_tree_edge (TYPE_MAIN_VARIANT (expr)); 856 DFS_follow_tree_edge (TYPE_MAIN_VARIANT (expr));
844 DFS_follow_tree_edge (TYPE_CONTEXT (expr)); 857 DFS_follow_tree_edge (TYPE_CONTEXT (expr));
845 /* TYPE_CANONICAL is re-computed during type merging, so no need 858 /* TYPE_CANONICAL is re-computed during type merging, so no need
846 to follow it here. */ 859 to follow it here. */
847 DFS_follow_tree_edge (TYPE_STUB_DECL (expr)); 860 /* 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
862 langhooks. */
848 } 863 }
849 864
850 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON)) 865 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
851 { 866 {
852 if (TREE_CODE (expr) == ENUMERAL_TYPE) 867 if (TREE_CODE (expr) == ENUMERAL_TYPE)
886 } 901 }
887 902
888 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK)) 903 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
889 { 904 {
890 for (tree t = BLOCK_VARS (expr); t; t = TREE_CHAIN (t)) 905 for (tree t = BLOCK_VARS (expr); t; t = TREE_CHAIN (t))
891 if (VAR_OR_FUNCTION_DECL_P (t) 906 {
892 && DECL_EXTERNAL (t)) 907 /* We would have to stream externals in the block chain as
893 /* We have to stream externals in the block chain as 908 non-references but we should have dropped them in
894 non-references. See also 909 free-lang-data. */
895 tree-streamer-out.c:streamer_write_chain. */ 910 gcc_assert (!VAR_OR_FUNCTION_DECL_P (t) || !DECL_EXTERNAL (t));
896 DFS_write_tree (ob, expr_state, t, ref_p, false);
897 else
898 DFS_follow_tree_edge (t); 911 DFS_follow_tree_edge (t);
912 }
899 913
900 DFS_follow_tree_edge (BLOCK_SUPERCONTEXT (expr)); 914 DFS_follow_tree_edge (BLOCK_SUPERCONTEXT (expr));
901 915 DFS_follow_tree_edge (BLOCK_ABSTRACT_ORIGIN (expr));
902 /* Follow BLOCK_ABSTRACT_ORIGIN for the limited cases we can 916
903 handle - those that represent inlined function scopes.
904 For the drop rest them on the floor instead of ICEing
905 in dwarf2out.c, but keep the notion of whether the block
906 is an inlined block by refering to itself for the sake of
907 tree_nonartificial_location. */
908 if (inlined_function_outer_scope_p (expr))
909 {
910 tree ultimate_origin = block_ultimate_origin (expr);
911 DFS_follow_tree_edge (ultimate_origin);
912 }
913 else if (BLOCK_ABSTRACT_ORIGIN (expr))
914 DFS_follow_tree_edge (expr);
915 /* Do not follow BLOCK_NONLOCALIZED_VARS. We cannot handle debug 917 /* Do not follow BLOCK_NONLOCALIZED_VARS. We cannot handle debug
916 information for early inlined BLOCKs so drop it on the floor instead 918 information for early inlined BLOCKs so drop it on the floor instead
917 of ICEing in dwarf2out.c. */ 919 of ICEing in dwarf2out.c. */
918 920
919 /* BLOCK_FRAGMENT_ORIGIN and BLOCK_FRAGMENT_CHAIN is not live at LTO 921 /* BLOCK_FRAGMENT_ORIGIN and BLOCK_FRAGMENT_CHAIN is not live at LTO
933 is needed to build the empty BINFO node on the reader side. */ 935 is needed to build the empty BINFO node on the reader side. */
934 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (expr), i, t) 936 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (expr), i, t)
935 DFS_follow_tree_edge (t); 937 DFS_follow_tree_edge (t);
936 DFS_follow_tree_edge (BINFO_OFFSET (expr)); 938 DFS_follow_tree_edge (BINFO_OFFSET (expr));
937 DFS_follow_tree_edge (BINFO_VTABLE (expr)); 939 DFS_follow_tree_edge (BINFO_VTABLE (expr));
938 DFS_follow_tree_edge (BINFO_VPTR_FIELD (expr)); 940
939 941 /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX,
940 /* The number of BINFO_BASE_ACCESSES has already been emitted in 942 BINFO_BASE_ACCESSES and BINFO_VPTR_INDEX; these are used
941 EXPR's bitfield section. */ 943 by C++ FE only. */
942 FOR_EACH_VEC_SAFE_ELT (BINFO_BASE_ACCESSES (expr), i, t)
943 DFS_follow_tree_edge (t);
944
945 /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX
946 and BINFO_VPTR_INDEX; these are used by C++ FE only. */
947 } 944 }
948 945
949 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR)) 946 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
950 { 947 {
951 unsigned i; 948 unsigned i;
1071 } 1068 }
1072 else if (code == FIELD_DECL) 1069 else if (code == FIELD_DECL)
1073 { 1070 {
1074 hstate.add_flag (DECL_PACKED (t)); 1071 hstate.add_flag (DECL_PACKED (t));
1075 hstate.add_flag (DECL_NONADDRESSABLE_P (t)); 1072 hstate.add_flag (DECL_NONADDRESSABLE_P (t));
1073 hstate.add_flag (DECL_PADDING_P (t));
1076 hstate.add_int (DECL_OFFSET_ALIGN (t)); 1074 hstate.add_int (DECL_OFFSET_ALIGN (t));
1077 } 1075 }
1078 else if (code == VAR_DECL) 1076 else if (code == VAR_DECL)
1079 { 1077 {
1080 hstate.add_flag (DECL_HAS_DEBUG_EXPR_P (t)); 1078 hstate.add_flag (DECL_HAS_DEBUG_EXPR_P (t));
1164 if (AGGREGATE_TYPE_P (t)) 1162 if (AGGREGATE_TYPE_P (t))
1165 hstate.add_flag (TYPE_TYPELESS_STORAGE (t)); 1163 hstate.add_flag (TYPE_TYPELESS_STORAGE (t));
1166 hstate.commit_flag (); 1164 hstate.commit_flag ();
1167 hstate.add_int (TYPE_PRECISION (t)); 1165 hstate.add_int (TYPE_PRECISION (t));
1168 hstate.add_int (TYPE_ALIGN (t)); 1166 hstate.add_int (TYPE_ALIGN (t));
1167 hstate.add_int (TYPE_EMPTY_P (t));
1169 } 1168 }
1170 1169
1171 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL)) 1170 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
1172 hstate.add (TRANSLATION_UNIT_LANGUAGE (t), 1171 hstate.add (TRANSLATION_UNIT_LANGUAGE (t),
1173 strlen (TRANSLATION_UNIT_LANGUAGE (t))); 1172 strlen (TRANSLATION_UNIT_LANGUAGE (t)));
1191 if (code != IDENTIFIER_NODE) 1190 if (code != IDENTIFIER_NODE)
1192 visit (TREE_TYPE (t)); 1191 visit (TREE_TYPE (t));
1193 } 1192 }
1194 1193
1195 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR)) 1194 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
1196 for (unsigned i = 0; i < VECTOR_CST_NELTS (t); ++i) 1195 {
1197 visit (VECTOR_CST_ELT (t, i)); 1196 unsigned int count = vector_cst_encoded_nelts (t);
1197 for (unsigned int i = 0; i < count; ++i)
1198 visit (VECTOR_CST_ENCODED_ELT (t, i));
1199 }
1200
1201 if (CODE_CONTAINS_STRUCT (code, TS_POLY_INT_CST))
1202 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1203 visit (POLY_INT_CST_COEFF (t, i));
1198 1204
1199 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX)) 1205 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
1200 { 1206 {
1201 visit (TREE_REALPART (t)); 1207 visit (TREE_REALPART (t));
1202 visit (TREE_IMAGPART (t)); 1208 visit (TREE_IMAGPART (t));
1231 visit (DECL_DEBUG_EXPR (t)); 1237 visit (DECL_DEBUG_EXPR (t));
1232 /* ??? Hash DECL_INITIAL as streamed. Needs the output-block to 1238 /* ??? Hash DECL_INITIAL as streamed. Needs the output-block to
1233 be able to call get_symbol_initial_value. */ 1239 be able to call get_symbol_initial_value. */
1234 } 1240 }
1235 1241
1236 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
1237 {
1238 if (code == TYPE_DECL)
1239 visit (DECL_ORIGINAL_TYPE (t));
1240 }
1241
1242 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS)) 1242 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1243 { 1243 {
1244 if (DECL_ASSEMBLER_NAME_SET_P (t)) 1244 if (DECL_ASSEMBLER_NAME_SET_P (t))
1245 visit (DECL_ASSEMBLER_NAME (t)); 1245 visit (DECL_ASSEMBLER_NAME (t));
1246 } 1246 }
1249 { 1249 {
1250 visit (DECL_FIELD_OFFSET (t)); 1250 visit (DECL_FIELD_OFFSET (t));
1251 visit (DECL_BIT_FIELD_TYPE (t)); 1251 visit (DECL_BIT_FIELD_TYPE (t));
1252 visit (DECL_BIT_FIELD_REPRESENTATIVE (t)); 1252 visit (DECL_BIT_FIELD_REPRESENTATIVE (t));
1253 visit (DECL_FIELD_BIT_OFFSET (t)); 1253 visit (DECL_FIELD_BIT_OFFSET (t));
1254 visit (DECL_FCONTEXT (t));
1255 } 1254 }
1256 1255
1257 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL)) 1256 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1258 { 1257 {
1259 visit (DECL_VINDEX (t));
1260 visit (DECL_FUNCTION_PERSONALITY (t)); 1258 visit (DECL_FUNCTION_PERSONALITY (t));
1261 visit (DECL_FUNCTION_SPECIFIC_TARGET (t)); 1259 visit (DECL_FUNCTION_SPECIFIC_TARGET (t));
1262 visit (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (t)); 1260 visit (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (t));
1263 } 1261 }
1264 1262
1271 visit (TYPE_MAIN_VARIANT (t)); 1269 visit (TYPE_MAIN_VARIANT (t));
1272 if (TYPE_FILE_SCOPE_P (t)) 1270 if (TYPE_FILE_SCOPE_P (t))
1273 ; 1271 ;
1274 else 1272 else
1275 visit (TYPE_CONTEXT (t)); 1273 visit (TYPE_CONTEXT (t));
1276 visit (TYPE_STUB_DECL (t));
1277 } 1274 }
1278 1275
1279 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON)) 1276 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
1280 { 1277 {
1281 if (code == ENUMERAL_TYPE) 1278 if (code == ENUMERAL_TYPE)
1317 tree b; 1314 tree b;
1318 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (t), i, b) 1315 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (t), i, b)
1319 visit (b); 1316 visit (b);
1320 visit (BINFO_OFFSET (t)); 1317 visit (BINFO_OFFSET (t));
1321 visit (BINFO_VTABLE (t)); 1318 visit (BINFO_VTABLE (t));
1322 visit (BINFO_VPTR_FIELD (t));
1323 FOR_EACH_VEC_SAFE_ELT (BINFO_BASE_ACCESSES (t), i, b)
1324 visit (b);
1325 /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX 1319 /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX
1326 and BINFO_VPTR_INDEX; these are used by C++ FE only. */ 1320 BINFO_BASE_ACCESSES and BINFO_VPTR_INDEX; these are used
1321 by C++ FE only. */
1327 } 1322 }
1328 1323
1329 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR)) 1324 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1330 { 1325 {
1331 unsigned i; 1326 unsigned i;
1617 /* Protect against recursion which means disconnect between 1612 /* Protect against recursion which means disconnect between
1618 what tree edges we walk in the DFS walk and what edges 1613 what tree edges we walk in the DFS walk and what edges
1619 we stream out. */ 1614 we stream out. */
1620 gcc_assert (!in_dfs_walk); 1615 gcc_assert (!in_dfs_walk);
1621 1616
1617 if (streamer_dump_file)
1618 {
1619 print_node_brief (streamer_dump_file, " Streaming SCC of ",
1620 expr, 4);
1621 fprintf (streamer_dump_file, "\n");
1622 }
1623
1622 /* Start the DFS walk. */ 1624 /* Start the DFS walk. */
1623 /* Save ob state ... */ 1625 /* Save ob state ... */
1624 /* let's see ... */ 1626 /* let's see ... */
1625 in_dfs_walk = true; 1627 in_dfs_walk = true;
1626 DFS (ob, expr, ref_p, this_ref_p, false); 1628 DFS (ob, expr, ref_p, this_ref_p, false);
1633 gcc_assert (existed_p); 1635 gcc_assert (existed_p);
1634 streamer_write_record_start (ob, LTO_tree_pickle_reference); 1636 streamer_write_record_start (ob, LTO_tree_pickle_reference);
1635 streamer_write_uhwi (ob, ix); 1637 streamer_write_uhwi (ob, ix);
1636 streamer_write_enum (ob->main_stream, LTO_tags, LTO_NUM_TAGS, 1638 streamer_write_enum (ob->main_stream, LTO_tags, LTO_NUM_TAGS,
1637 lto_tree_code_to_tag (TREE_CODE (expr))); 1639 lto_tree_code_to_tag (TREE_CODE (expr)));
1640 if (streamer_dump_file)
1641 {
1642 print_node_brief (streamer_dump_file, " Finished SCC of ",
1643 expr, 4);
1644 fprintf (streamer_dump_file, "\n\n");
1645 }
1638 lto_stats.num_pickle_refs_output++; 1646 lto_stats.num_pickle_refs_output++;
1639 } 1647 }
1640 } 1648 }
1641 1649
1642 1650
1927 if (loop->any_estimate) 1935 if (loop->any_estimate)
1928 streamer_write_widest_int (ob, loop->nb_iterations_estimate); 1936 streamer_write_widest_int (ob, loop->nb_iterations_estimate);
1929 1937
1930 /* Write OMP SIMD related info. */ 1938 /* Write OMP SIMD related info. */
1931 streamer_write_hwi (ob, loop->safelen); 1939 streamer_write_hwi (ob, loop->safelen);
1940 streamer_write_hwi (ob, loop->unroll);
1932 streamer_write_hwi (ob, loop->dont_vectorize); 1941 streamer_write_hwi (ob, loop->dont_vectorize);
1933 streamer_write_hwi (ob, loop->force_vectorize); 1942 streamer_write_hwi (ob, loop->force_vectorize);
1934 stream_write_tree (ob, loop->simduid, true); 1943 stream_write_tree (ob, loop->simduid, true);
1935 } 1944 }
1936 1945
2027 2036
2028 /* Output the function start and end loci. */ 2037 /* Output the function start and end loci. */
2029 stream_output_location (ob, &bp, fn->function_start_locus); 2038 stream_output_location (ob, &bp, fn->function_start_locus);
2030 stream_output_location (ob, &bp, fn->function_end_locus); 2039 stream_output_location (ob, &bp, fn->function_end_locus);
2031 2040
2041 /* Save the instance discriminator if present. */
2042 int *instance_number_p = NULL;
2043 if (decl_to_instance_map)
2044 instance_number_p = decl_to_instance_map->get (fn->decl);
2045 bp_pack_value (&bp, !!instance_number_p, 1);
2046 if (instance_number_p)
2047 bp_pack_value (&bp, *instance_number_p, sizeof (int) * CHAR_BIT);
2048
2032 streamer_write_bitpack (&bp); 2049 streamer_write_bitpack (&bp);
2033 } 2050 }
2034 2051
2035 2052
2036 /* Collect all leaf BLOCKs beyond ROOT into LEAFS. */ 2053 /* Collect all leaf BLOCKs beyond ROOT into LEAFS. */
2052 { 2069 {
2053 tree function; 2070 tree function;
2054 struct function *fn; 2071 struct function *fn;
2055 basic_block bb; 2072 basic_block bb;
2056 struct output_block *ob; 2073 struct output_block *ob;
2074
2075 if (streamer_dump_file)
2076 fprintf (streamer_dump_file, "\nStreaming body of %s\n",
2077 node->name ());
2057 2078
2058 function = node->decl; 2079 function = node->decl;
2059 fn = DECL_STRUCT_FUNCTION (function); 2080 fn = DECL_STRUCT_FUNCTION (function);
2060 ob = create_output_block (LTO_section_function_body); 2081 ob = create_output_block (LTO_section_function_body);
2061 2082
2101 2122
2102 /* We also stream abstract functions where we stream only stuff needed for 2123 /* We also stream abstract functions where we stream only stuff needed for
2103 debug info. */ 2124 debug info. */
2104 if (gimple_has_body_p (function)) 2125 if (gimple_has_body_p (function))
2105 { 2126 {
2127 /* Fixup loops if required to match discovery done in the reader. */
2128 loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
2129
2106 streamer_write_uhwi (ob, 1); 2130 streamer_write_uhwi (ob, 1);
2107 output_struct_function_base (ob, fn); 2131 output_struct_function_base (ob, fn);
2108 2132
2109 /* Output all the SSA names used in the function. */ 2133 /* Output all the SSA names used in the function. */
2110 output_ssa_names (ob, fn); 2134 output_ssa_names (ob, fn);
2158 /* The terminator for this function. */ 2182 /* The terminator for this function. */
2159 streamer_write_record_start (ob, LTO_null); 2183 streamer_write_record_start (ob, LTO_null);
2160 2184
2161 output_cfg (ob, fn); 2185 output_cfg (ob, fn);
2162 2186
2187 loop_optimizer_finalize ();
2163 pop_cfun (); 2188 pop_cfun ();
2164 } 2189 }
2165 else 2190 else
2166 streamer_write_uhwi (ob, 0); 2191 streamer_write_uhwi (ob, 0);
2167 2192
2168 /* Create a section to hold the pickled output of this function. */ 2193 /* Create a section to hold the pickled output of this function. */
2169 produce_asm (ob, function); 2194 produce_asm (ob, function);
2170 2195
2171 destroy_output_block (ob); 2196 destroy_output_block (ob);
2197 if (streamer_dump_file)
2198 fprintf (streamer_dump_file, "Finished streaming %s\n",
2199 node->name ());
2172 } 2200 }
2173 2201
2174 /* Output the body of function NODE->DECL. */ 2202 /* Output the body of function NODE->DECL. */
2175 2203
2176 static void 2204 static void
2177 output_constructor (struct varpool_node *node) 2205 output_constructor (struct varpool_node *node)
2178 { 2206 {
2179 tree var = node->decl; 2207 tree var = node->decl;
2180 struct output_block *ob; 2208 struct output_block *ob;
2209
2210 if (streamer_dump_file)
2211 fprintf (streamer_dump_file, "\nStreaming constructor of %s\n",
2212 node->name ());
2181 2213
2182 ob = create_output_block (LTO_section_function_body); 2214 ob = create_output_block (LTO_section_function_body);
2183 2215
2184 clear_line_info (ob); 2216 clear_line_info (ob);
2185 ob->symbol = node; 2217 ob->symbol = node;
2193 2225
2194 /* Create a section to hold the pickled output of this function. */ 2226 /* Create a section to hold the pickled output of this function. */
2195 produce_asm (ob, var); 2227 produce_asm (ob, var);
2196 2228
2197 destroy_output_block (ob); 2229 destroy_output_block (ob);
2230 if (streamer_dump_file)
2231 fprintf (streamer_dump_file, "Finished streaming %s\n",
2232 node->name ());
2198 } 2233 }
2199 2234
2200 2235
2201 /* Emit toplevel asms. */ 2236 /* Emit toplevel asms. */
2202 2237
2264 lto_get_section_name (LTO_section_function_body, name, NULL); 2299 lto_get_section_name (LTO_section_function_body, name, NULL);
2265 size_t i, j; 2300 size_t i, j;
2266 struct lto_in_decl_state *in_state; 2301 struct lto_in_decl_state *in_state;
2267 struct lto_out_decl_state *out_state = lto_get_out_decl_state (); 2302 struct lto_out_decl_state *out_state = lto_get_out_decl_state ();
2268 2303
2304 if (streamer_dump_file)
2305 fprintf (streamer_dump_file, "Copying section for %s\n", name);
2269 lto_begin_section (section_name, false); 2306 lto_begin_section (section_name, false);
2270 free (section_name); 2307 free (section_name);
2271 2308
2272 /* We may have renamed the declaration, e.g., a static function. */ 2309 /* We may have renamed the declaration, e.g., a static function. */
2273 name = lto_get_decl_name_mapping (file_data, name); 2310 name = lto_get_decl_name_mapping (file_data, name);
2328 else if (!EXPR_P (t)) 2365 else if (!EXPR_P (t))
2329 *ws = 0; 2366 *ws = 0;
2330 return NULL_TREE; 2367 return NULL_TREE;
2331 } 2368 }
2332 2369
2370 /* Remove functions that are no longer used from offload_funcs, and mark the
2371 remaining ones with DECL_PRESERVE_P. */
2372
2373 static void
2374 prune_offload_funcs (void)
2375 {
2376 if (!offload_funcs)
2377 return;
2378
2379 unsigned ix, ix2;
2380 tree *elem_ptr;
2381 VEC_ORDERED_REMOVE_IF (*offload_funcs, ix, ix2, elem_ptr,
2382 cgraph_node::get (*elem_ptr) == NULL);
2383
2384 tree fn_decl;
2385 FOR_EACH_VEC_ELT (*offload_funcs, ix, fn_decl)
2386 DECL_PRESERVE_P (fn_decl) = 1;
2387 }
2388
2333 /* Main entry point from the pass manager. */ 2389 /* Main entry point from the pass manager. */
2334 2390
2335 void 2391 void
2336 lto_output (void) 2392 lto_output (void)
2337 { 2393 {
2338 struct lto_out_decl_state *decl_state; 2394 struct lto_out_decl_state *decl_state;
2339 bitmap output = NULL; 2395 bitmap output = NULL;
2340 int i, n_nodes; 2396 int i, n_nodes;
2341 lto_symtab_encoder_t encoder = lto_get_out_decl_state ()->symtab_node_encoder; 2397 lto_symtab_encoder_t encoder = lto_get_out_decl_state ()->symtab_node_encoder;
2398
2399 prune_offload_funcs ();
2342 2400
2343 if (flag_checking) 2401 if (flag_checking)
2344 output = lto_bitmap_alloc (); 2402 output = lto_bitmap_alloc ();
2345 2403
2346 /* Initialize the streamer. */ 2404 /* Initialize the streamer. */
2362 gcc_assert (!bitmap_bit_p (output, DECL_UID (node->decl))); 2420 gcc_assert (!bitmap_bit_p (output, DECL_UID (node->decl)));
2363 bitmap_set_bit (output, DECL_UID (node->decl)); 2421 bitmap_set_bit (output, DECL_UID (node->decl));
2364 } 2422 }
2365 decl_state = lto_new_out_decl_state (); 2423 decl_state = lto_new_out_decl_state ();
2366 lto_push_out_decl_state (decl_state); 2424 lto_push_out_decl_state (decl_state);
2367 if (gimple_has_body_p (node->decl) || !flag_wpa 2425 if (gimple_has_body_p (node->decl)
2426 || (!flag_wpa
2427 && flag_incremental_link != INCREMENTAL_LINK_LTO)
2368 /* Thunks have no body but they may be synthetized 2428 /* Thunks have no body but they may be synthetized
2369 at WPA time. */ 2429 at WPA time. */
2370 || DECL_ARGUMENTS (node->decl)) 2430 || DECL_ARGUMENTS (node->decl))
2371 output_function (node); 2431 output_function (node);
2372 else 2432 else
2394 bitmap_set_bit (output, DECL_UID (node->decl)); 2454 bitmap_set_bit (output, DECL_UID (node->decl));
2395 } 2455 }
2396 decl_state = lto_new_out_decl_state (); 2456 decl_state = lto_new_out_decl_state ();
2397 lto_push_out_decl_state (decl_state); 2457 lto_push_out_decl_state (decl_state);
2398 if (DECL_INITIAL (node->decl) != error_mark_node 2458 if (DECL_INITIAL (node->decl) != error_mark_node
2399 || !flag_wpa) 2459 || (!flag_wpa
2460 && flag_incremental_link != INCREMENTAL_LINK_LTO))
2400 output_constructor (node); 2461 output_constructor (node);
2401 else 2462 else
2402 copy_function_or_variable (node); 2463 copy_function_or_variable (node);
2403 gcc_assert (lto_get_out_decl_state () == decl_state); 2464 gcc_assert (lto_get_out_decl_state () == decl_state);
2404 lto_pop_out_decl_state (); 2465 lto_pop_out_decl_state ();
2438 const size_t size = lto_tree_ref_encoder_size (encoder); 2499 const size_t size = lto_tree_ref_encoder_size (encoder);
2439 2500
2440 for (index = 0; index < size; index++) 2501 for (index = 0; index < size; index++)
2441 { 2502 {
2442 t = lto_tree_ref_encoder_get_tree (encoder, index); 2503 t = lto_tree_ref_encoder_get_tree (encoder, index);
2504 if (streamer_dump_file)
2505 {
2506 fprintf (streamer_dump_file, " %i:", (int)index);
2507 print_node_brief (streamer_dump_file, "", t, 4);
2508 fprintf (streamer_dump_file, "\n");
2509 }
2443 if (!streamer_tree_cache_lookup (ob->writer_cache, t, NULL)) 2510 if (!streamer_tree_cache_lookup (ob->writer_cache, t, NULL))
2444 stream_write_tree (ob, t, false); 2511 stream_write_tree (ob, t, false);
2445 } 2512 }
2446 } 2513 }
2447 2514
2548 unsigned slot_num; 2615 unsigned slot_num;
2549 uint64_t size; 2616 uint64_t size;
2550 const char *comdat; 2617 const char *comdat;
2551 unsigned char c; 2618 unsigned char c;
2552 2619
2553 /* None of the following kinds of symbols are needed in the 2620 gcc_checking_assert (TREE_PUBLIC (t)
2554 symbol table. */ 2621 && (TREE_CODE (t) != FUNCTION_DECL
2555 if (!TREE_PUBLIC (t) 2622 || !fndecl_built_in_p (t))
2556 || is_builtin_fn (t) 2623 && !DECL_ABSTRACT_P (t)
2557 || DECL_ABSTRACT_P (t) 2624 && (!VAR_P (t) || !DECL_HARD_REGISTER (t)));
2558 || (VAR_P (t) && DECL_HARD_REGISTER (t)))
2559 return;
2560 2625
2561 gcc_assert (VAR_OR_FUNCTION_DECL_P (t)); 2626 gcc_assert (VAR_OR_FUNCTION_DECL_P (t));
2562 2627
2563 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t)); 2628 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t));
2564 2629
2642 lto_write_data (&c, 1); 2707 lto_write_data (&c, 1);
2643 lto_write_data (&size, 8); 2708 lto_write_data (&size, 8);
2644 lto_write_data (&slot_num, 4); 2709 lto_write_data (&slot_num, 4);
2645 } 2710 }
2646 2711
2647 /* Return true if NODE should appear in the plugin symbol table. */
2648
2649 bool
2650 output_symbol_p (symtab_node *node)
2651 {
2652 struct cgraph_node *cnode;
2653 if (!node->real_symbol_p ())
2654 return false;
2655 /* We keep external functions in symtab for sake of inlining
2656 and devirtualization. We do not want to see them in symbol table as
2657 references unless they are really used. */
2658 cnode = dyn_cast <cgraph_node *> (node);
2659 if (cnode && (!node->definition || DECL_EXTERNAL (cnode->decl))
2660 && cnode->callers)
2661 return true;
2662
2663 /* Ignore all references from external vars initializers - they are not really
2664 part of the compilation unit until they are used by folding. Some symbols,
2665 like references to external construction vtables can not be referred to at all.
2666 We decide this at can_refer_decl_in_current_unit_p. */
2667 if (!node->definition || DECL_EXTERNAL (node->decl))
2668 {
2669 int i;
2670 struct ipa_ref *ref;
2671 for (i = 0; node->iterate_referring (i, ref); i++)
2672 {
2673 if (ref->use == IPA_REF_ALIAS)
2674 continue;
2675 if (is_a <cgraph_node *> (ref->referring))
2676 return true;
2677 if (!DECL_EXTERNAL (ref->referring->decl))
2678 return true;
2679 }
2680 return false;
2681 }
2682 return true;
2683 }
2684
2685
2686 /* Write an IL symbol table to OB. 2712 /* Write an IL symbol table to OB.
2687 SET and VSET are cgraph/varpool node sets we are outputting. */ 2713 SET and VSET are cgraph/varpool node sets we are outputting. */
2688 2714
2689 static void 2715 static void
2690 produce_symtab (struct output_block *ob) 2716 produce_symtab (struct output_block *ob)
2705 for (lsei = lsei_start (encoder); 2731 for (lsei = lsei_start (encoder);
2706 !lsei_end_p (lsei); lsei_next (&lsei)) 2732 !lsei_end_p (lsei); lsei_next (&lsei))
2707 { 2733 {
2708 symtab_node *node = lsei_node (lsei); 2734 symtab_node *node = lsei_node (lsei);
2709 2735
2710 if (!output_symbol_p (node) || DECL_EXTERNAL (node->decl)) 2736 if (DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
2711 continue; 2737 continue;
2712 write_symbol (cache, node->decl, &seen, false); 2738 write_symbol (cache, node->decl, &seen, false);
2713 } 2739 }
2714 for (lsei = lsei_start (encoder); 2740 for (lsei = lsei_start (encoder);
2715 !lsei_end_p (lsei); lsei_next (&lsei)) 2741 !lsei_end_p (lsei); lsei_next (&lsei))
2716 { 2742 {
2717 symtab_node *node = lsei_node (lsei); 2743 symtab_node *node = lsei_node (lsei);
2718 2744
2719 if (!output_symbol_p (node) || !DECL_EXTERNAL (node->decl)) 2745 if (!DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
2720 continue; 2746 continue;
2721 write_symbol (cache, node->decl, &seen, false); 2747 write_symbol (cache, node->decl, &seen, false);
2722 } 2748 }
2723 2749
2724 lto_end_section (); 2750 lto_end_section ();
2761 machine_mode m = (machine_mode) i; 2787 machine_mode m = (machine_mode) i;
2762 if ((GET_MODE_INNER (m) == m) ^ (pass == 0)) 2788 if ((GET_MODE_INNER (m) == m) ^ (pass == 0))
2763 continue; 2789 continue;
2764 bp_pack_value (&bp, m, 8); 2790 bp_pack_value (&bp, m, 8);
2765 bp_pack_enum (&bp, mode_class, MAX_MODE_CLASS, GET_MODE_CLASS (m)); 2791 bp_pack_enum (&bp, mode_class, MAX_MODE_CLASS, GET_MODE_CLASS (m));
2766 bp_pack_value (&bp, GET_MODE_SIZE (m), 8); 2792 bp_pack_poly_value (&bp, GET_MODE_SIZE (m), 16);
2767 bp_pack_value (&bp, GET_MODE_PRECISION (m), 16); 2793 bp_pack_poly_value (&bp, GET_MODE_PRECISION (m), 16);
2768 bp_pack_value (&bp, GET_MODE_INNER (m), 8); 2794 bp_pack_value (&bp, GET_MODE_INNER (m), 8);
2769 bp_pack_value (&bp, GET_MODE_NUNITS (m), 8); 2795 bp_pack_poly_value (&bp, GET_MODE_NUNITS (m), 16);
2770 switch (GET_MODE_CLASS (m)) 2796 switch (GET_MODE_CLASS (m))
2771 { 2797 {
2772 case MODE_FRACT: 2798 case MODE_FRACT:
2773 case MODE_UFRACT: 2799 case MODE_UFRACT:
2774 case MODE_ACCUM: 2800 case MODE_ACCUM:
2855 delete out_state->streams[i].tree_hash_table; 2881 delete out_state->streams[i].tree_hash_table;
2856 out_state->streams[i].tree_hash_table = NULL; 2882 out_state->streams[i].tree_hash_table = NULL;
2857 } 2883 }
2858 2884
2859 /* Write the global symbols. */ 2885 /* Write the global symbols. */
2886 if (streamer_dump_file)
2887 fprintf (streamer_dump_file, "Outputting global stream\n");
2860 lto_output_decl_state_streams (ob, out_state); 2888 lto_output_decl_state_streams (ob, out_state);
2861 num_fns = lto_function_decl_states.length (); 2889 num_fns = lto_function_decl_states.length ();
2862 for (idx = 0; idx < num_fns; idx++) 2890 for (idx = 0; idx < num_fns; idx++)
2863 { 2891 {
2864 fn_out_state = 2892 fn_out_state =
2865 lto_function_decl_states[idx]; 2893 lto_function_decl_states[idx];
2894 if (streamer_dump_file)
2895 fprintf (streamer_dump_file, "Outputting stream for %s\n",
2896 IDENTIFIER_POINTER
2897 (DECL_ASSEMBLER_NAME (fn_out_state->fn_decl)));
2866 lto_output_decl_state_streams (ob, fn_out_state); 2898 lto_output_decl_state_streams (ob, fn_out_state);
2867 } 2899 }
2868 2900
2869 header.major_version = LTO_major_version; 2901 header.major_version = LTO_major_version;
2870 header.minor_version = LTO_minor_version; 2902 header.minor_version = LTO_minor_version;