]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/lto-streamer.c
Allow automatics in equivalences
[thirdparty/gcc.git] / gcc / lto-streamer.c
CommitLineData
7bfefa9d 1/* Miscellaneous utilities for GIMPLE streaming. Things that are used
2 in both input and output are here.
3
fbd26352 4 Copyright (C) 2009-2019 Free Software Foundation, Inc.
7bfefa9d 5 Contributed by Doug Kwan <dougkwan@google.com>
6
7This file is part of GCC.
8
9GCC is free software; you can redistribute it and/or modify it under
10the terms of the GNU General Public License as published by the Free
11Software Foundation; either version 3, or (at your option) any later
12version.
13
14GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17for more details.
18
19You should have received a copy of the GNU General Public License
20along with GCC; see the file COPYING3. If not see
21<http://www.gnu.org/licenses/>. */
22
23#include "config.h"
24#include "system.h"
25#include "coretypes.h"
9ef16211 26#include "backend.h"
27#include "tree.h"
28#include "gimple.h"
7c29e30e 29#include "tree-streamer.h"
30#include "cgraph.h"
31#include "lto-streamer.h"
7bfefa9d 32#include "toplev.h"
47131315 33#include "lto-section-names.h"
7bfefa9d 34
35/* Statistics gathered during LTO, WPA and LTRANS. */
36struct lto_stats_d lto_stats;
37
b0c5e347 38const char *section_name_prefix = LTO_SECTION_NAME_PREFIX;
ba000093 39/* Set when streaming LTO for offloading compiler. */
40bool lto_stream_offload_p;
7bfefa9d 41
7858a084 42FILE *streamer_dump_file;
43
7bfefa9d 44/* Return a string representing LTO tag TAG. */
45
46const char *
47lto_tag_name (enum LTO_tags tag)
48{
49 if (lto_tag_is_tree_code_p (tag))
50 {
51 /* For tags representing tree nodes, return the name of the
52 associated tree code. */
f3d35d4d 53 return get_tree_code_name (lto_tag_to_tree_code (tag));
7bfefa9d 54 }
55
56 if (lto_tag_is_gimple_code_p (tag))
57 {
58 /* For tags representing gimple statements, return the name of
59 the associated gimple code. */
60 return gimple_code_name[lto_tag_to_gimple_code (tag)];
61 }
62
63 switch (tag)
64 {
65 case LTO_null:
66 return "LTO_null";
67 case LTO_bb0:
68 return "LTO_bb0";
69 case LTO_bb1:
70 return "LTO_bb1";
71 case LTO_eh_region:
72 return "LTO_eh_region";
73 case LTO_function:
74 return "LTO_function";
75 case LTO_eh_table:
76 return "LTO_eh_table";
77 case LTO_ert_cleanup:
78 return "LTO_ert_cleanup";
79 case LTO_ert_try:
80 return "LTO_ert_try";
81 case LTO_ert_allowed_exceptions:
82 return "LTO_ert_allowed_exceptions";
83 case LTO_ert_must_not_throw:
84 return "LTO_ert_must_not_throw";
85 case LTO_tree_pickle_reference:
86 return "LTO_tree_pickle_reference";
87 case LTO_field_decl_ref:
88 return "LTO_field_decl_ref";
89 case LTO_function_decl_ref:
90 return "LTO_function_decl_ref";
91 case LTO_label_decl_ref:
92 return "LTO_label_decl_ref";
93 case LTO_namespace_decl_ref:
94 return "LTO_namespace_decl_ref";
95 case LTO_result_decl_ref:
96 return "LTO_result_decl_ref";
97 case LTO_ssa_name_ref:
98 return "LTO_ssa_name_ref";
99 case LTO_type_decl_ref:
100 return "LTO_type_decl_ref";
101 case LTO_type_ref:
102 return "LTO_type_ref";
103 case LTO_global_decl_ref:
104 return "LTO_global_decl_ref";
105 default:
106 return "LTO_UNKNOWN";
107 }
108}
109
110
7bfefa9d 111/* Get a section name for a particular type or name. The NAME field
f18bad33 112 is only used if SECTION_TYPE is LTO_section_function_body. For all
113 others it is ignored. The callee of this function is responsible
114 to free the returned name. */
7bfefa9d 115
116char *
f18bad33 117lto_get_section_name (int section_type, const char *name, struct lto_file_decl_data *f)
7bfefa9d 118{
f18bad33 119 const char *add;
120 char post[32];
121 const char *sep;
122
123 if (section_type == LTO_section_function_body)
7bfefa9d 124 {
151a56e7 125 gcc_assert (name != NULL);
126 if (name[0] == '*')
127 name++;
f18bad33 128 add = name;
129 sep = "";
130 }
131 else if (section_type < LTO_N_SECTION_TYPES)
132 {
133 add = lto_section_name[section_type];
134 sep = ".";
135 }
136 else
137 internal_error ("bytecode stream: unexpected LTO section %s", name);
7bfefa9d 138
f18bad33 139 /* Make the section name unique so that ld -r combining sections
140 doesn't confuse the reader with merged sections.
7bfefa9d 141
f18bad33 142 For options don't add a ID, the option reader cannot deal with them
badc6cfa 143 and merging should be ok here. */
f18bad33 144 if (section_type == LTO_section_opts)
145 strcpy (post, "");
badc6cfa 146 else if (f != NULL)
147 sprintf (post, "." HOST_WIDE_INT_PRINT_HEX_PURE, f->id);
f18bad33 148 else
badc6cfa 149 sprintf (post, "." HOST_WIDE_INT_PRINT_HEX_PURE, get_random_seed (false));
b0c5e347 150 return concat (section_name_prefix, sep, add, post, NULL);
7bfefa9d 151}
152
153
154/* Show various memory usage statistics related to LTO. */
155
156void
bdaea387 157print_lto_report (const char *s)
7bfefa9d 158{
7bfefa9d 159 unsigned i;
160
7bfefa9d 161 fprintf (stderr, "[%s] # of input files: "
162 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s, lto_stats.num_input_files);
163
48e1416a 164 fprintf (stderr, "[%s] # of input cgraph nodes: "
7bfefa9d 165 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
166 lto_stats.num_input_cgraph_nodes);
167
168 fprintf (stderr, "[%s] # of function bodies: "
169 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
170 lto_stats.num_function_bodies);
171
7bfefa9d 172 for (i = 0; i < NUM_TREE_CODES; i++)
173 if (lto_stats.num_trees[i])
174 fprintf (stderr, "[%s] # of '%s' objects read: "
175 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
f3d35d4d 176 get_tree_code_name ((enum tree_code) i), lto_stats.num_trees[i]);
7bfefa9d 177
178 if (flag_lto)
179 {
180 fprintf (stderr, "[%s] Compression: "
181 HOST_WIDE_INT_PRINT_UNSIGNED " output bytes, "
182 HOST_WIDE_INT_PRINT_UNSIGNED " compressed bytes", s,
183 lto_stats.num_output_il_bytes,
184 lto_stats.num_compressed_il_bytes);
185 if (lto_stats.num_output_il_bytes > 0)
186 {
187 const float dividend = (float) lto_stats.num_compressed_il_bytes;
188 const float divisor = (float) lto_stats.num_output_il_bytes;
189 fprintf (stderr, " (ratio: %f)", dividend / divisor);
190 }
191 fprintf (stderr, "\n");
192 }
193
194 if (flag_wpa)
195 {
196 fprintf (stderr, "[%s] # of output files: "
197 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
198 lto_stats.num_output_files);
199
5cf7e051 200 fprintf (stderr, "[%s] # of output symtab nodes: "
7bfefa9d 201 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
5cf7e051 202 lto_stats.num_output_symtab_nodes);
7bfefa9d 203
8ceff600 204 fprintf (stderr, "[%s] # of output tree pickle references: "
205 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
206 lto_stats.num_pickle_refs_output);
207 fprintf (stderr, "[%s] # of output tree bodies: "
208 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
209 lto_stats.num_tree_bodies_output);
210
7bfefa9d 211 fprintf (stderr, "[%s] # callgraph partitions: "
212 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
213 lto_stats.num_cgraph_partitions);
214
215 fprintf (stderr, "[%s] Compression: "
216 HOST_WIDE_INT_PRINT_UNSIGNED " input bytes, "
217 HOST_WIDE_INT_PRINT_UNSIGNED " uncompressed bytes", s,
218 lto_stats.num_input_il_bytes,
219 lto_stats.num_uncompressed_il_bytes);
220 if (lto_stats.num_input_il_bytes > 0)
221 {
222 const float dividend = (float) lto_stats.num_uncompressed_il_bytes;
223 const float divisor = (float) lto_stats.num_input_il_bytes;
224 fprintf (stderr, " (ratio: %f)", dividend / divisor);
225 }
226 fprintf (stderr, "\n");
227 }
228
229 for (i = 0; i < LTO_N_SECTION_TYPES; i++)
230 fprintf (stderr, "[%s] Size of mmap'd section %s: "
231 HOST_WIDE_INT_PRINT_UNSIGNED " bytes\n", s,
232 lto_section_name[i], lto_stats.section_size[i]);
233}
234
7bfefa9d 235/* Initialization common to the LTO reader and writer. */
236
237void
238lto_streamer_init (void)
239{
240 /* Check that all the TS_* handled by the reader and writer routines
241 match exactly the structures defined in treestruct.def. When a
242 new TS_* astructure is added, the streamer should be updated to
243 handle it. */
382ecba7 244 if (flag_checking)
245 streamer_check_handled_ts_structures ();
7bfefa9d 246}
247
248
249/* Gate function for all LTO streaming passes. */
250
251bool
252gate_lto_out (void)
253{
9f28dc4c 254 return ((flag_generate_lto || flag_generate_offload || in_lto_p)
7bfefa9d 255 /* Don't bother doing anything if the program has errors. */
852f689e 256 && !seen_error ());
7bfefa9d 257}
258
7bfefa9d 259/* Check that the version MAJOR.MINOR is the correct version number. */
260
261void
374d90a7 262lto_check_version (int major, int minor, const char *file_name)
7bfefa9d 263{
264 if (major != LTO_major_version || minor != LTO_minor_version)
c05be867 265 fatal_error (input_location,
c92412d2 266 "bytecode stream in file %qs generated with LTO version "
374d90a7 267 "%d.%d instead of the expected %d.%d",
268 file_name,
7bfefa9d 269 major, minor,
270 LTO_major_version, LTO_minor_version);
271}
a0605d65 272
273
a0605d65 274/* Initialize all the streamer hooks used for streaming GIMPLE. */
275
276void
277lto_streamer_hooks_init (void)
278{
279 streamer_hooks_init ();
515cf651 280 streamer_hooks.write_tree = lto_output_tree;
281 streamer_hooks.read_tree = lto_input_tree;
ec180527 282 streamer_hooks.input_location = lto_input_location;
283 streamer_hooks.output_location = lto_output_location;
a0605d65 284}