]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/lto-streamer.c
[Ada] Improved support for aspect alignment in CCG
[thirdparty/gcc.git] / gcc / lto-streamer.c
CommitLineData
d7f09764
DN
1/* Miscellaneous utilities for GIMPLE streaming. Things that are used
2 in both input and output are here.
3
8d9254fc 4 Copyright (C) 2009-2020 Free Software Foundation, Inc.
d7f09764
DN
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"
c7131fb2
AM
26#include "backend.h"
27#include "tree.h"
28#include "gimple.h"
957060b5
AM
29#include "tree-streamer.h"
30#include "cgraph.h"
31#include "lto-streamer.h"
d7f09764 32#include "toplev.h"
4000360e 33#include "lto-section-names.h"
d7f09764
DN
34
35/* Statistics gathered during LTO, WPA and LTRANS. */
36struct lto_stats_d lto_stats;
37
1f6be682 38const char *section_name_prefix = LTO_SECTION_NAME_PREFIX;
1b34e6e2
BS
39/* Set when streaming LTO for offloading compiler. */
40bool lto_stream_offload_p;
d7f09764 41
b4da704c
JH
42FILE *streamer_dump_file;
43
d7f09764
DN
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. */
5806f481 53 return get_tree_code_name (lto_tag_to_tree_code (tag));
d7f09764
DN
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";
1746d5f3
JH
87 case LTO_global_stream_ref:
88 return "LTO_global_sream_ref";
d7f09764
DN
89 case LTO_ssa_name_ref:
90 return "LTO_ssa_name_ref";
d7f09764
DN
91 default:
92 return "LTO_UNKNOWN";
93 }
94}
95
96
d7f09764 97/* Get a section name for a particular type or name. The NAME field
73ce4d1e
AK
98 is only used if SECTION_TYPE is LTO_section_function_body. For all
99 others it is ignored. The callee of this function is responsible
100 to free the returned name. */
d7f09764
DN
101
102char *
3c56d8d8
ML
103lto_get_section_name (int section_type, const char *name,
104 int node_order, struct lto_file_decl_data *f)
d7f09764 105{
73ce4d1e
AK
106 const char *add;
107 char post[32];
108 const char *sep;
109
110 if (section_type == LTO_section_function_body)
d7f09764 111 {
91539475
L
112 gcc_assert (name != NULL);
113 if (name[0] == '*')
114 name++;
3c56d8d8
ML
115
116 char *buffer = (char *)xmalloc (strlen (name) + 32);
117 sprintf (buffer, "%s.%d", name, node_order);
118
119 add = buffer;
73ce4d1e
AK
120 sep = "";
121 }
122 else if (section_type < LTO_N_SECTION_TYPES)
123 {
124 add = lto_section_name[section_type];
125 sep = ".";
126 }
127 else
128 internal_error ("bytecode stream: unexpected LTO section %s", name);
d7f09764 129
73ce4d1e
AK
130 /* Make the section name unique so that ld -r combining sections
131 doesn't confuse the reader with merged sections.
d7f09764 132
73ce4d1e 133 For options don't add a ID, the option reader cannot deal with them
dde8b360 134 and merging should be ok here. */
73ce4d1e
AK
135 if (section_type == LTO_section_opts)
136 strcpy (post, "");
dde8b360
AK
137 else if (f != NULL)
138 sprintf (post, "." HOST_WIDE_INT_PRINT_HEX_PURE, f->id);
73ce4d1e 139 else
dde8b360 140 sprintf (post, "." HOST_WIDE_INT_PRINT_HEX_PURE, get_random_seed (false));
1f6be682 141 return concat (section_name_prefix, sep, add, post, NULL);
d7f09764
DN
142}
143
144
145/* Show various memory usage statistics related to LTO. */
146
147void
b8f4e58f 148print_lto_report (const char *s)
d7f09764 149{
d7f09764
DN
150 unsigned i;
151
d7f09764
DN
152 fprintf (stderr, "[%s] # of input files: "
153 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s, lto_stats.num_input_files);
154
b8698a0f 155 fprintf (stderr, "[%s] # of input cgraph nodes: "
d7f09764
DN
156 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
157 lto_stats.num_input_cgraph_nodes);
158
159 fprintf (stderr, "[%s] # of function bodies: "
160 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
161 lto_stats.num_function_bodies);
162
d7f09764
DN
163 for (i = 0; i < NUM_TREE_CODES; i++)
164 if (lto_stats.num_trees[i])
165 fprintf (stderr, "[%s] # of '%s' objects read: "
166 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
5806f481 167 get_tree_code_name ((enum tree_code) i), lto_stats.num_trees[i]);
d7f09764
DN
168
169 if (flag_lto)
170 {
171 fprintf (stderr, "[%s] Compression: "
172 HOST_WIDE_INT_PRINT_UNSIGNED " output bytes, "
173 HOST_WIDE_INT_PRINT_UNSIGNED " compressed bytes", s,
174 lto_stats.num_output_il_bytes,
175 lto_stats.num_compressed_il_bytes);
176 if (lto_stats.num_output_il_bytes > 0)
177 {
178 const float dividend = (float) lto_stats.num_compressed_il_bytes;
179 const float divisor = (float) lto_stats.num_output_il_bytes;
180 fprintf (stderr, " (ratio: %f)", dividend / divisor);
181 }
182 fprintf (stderr, "\n");
183 }
184
185 if (flag_wpa)
186 {
187 fprintf (stderr, "[%s] # of output files: "
188 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
189 lto_stats.num_output_files);
190
7b99cca4 191 fprintf (stderr, "[%s] # of output symtab nodes: "
d7f09764 192 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
7b99cca4 193 lto_stats.num_output_symtab_nodes);
d7f09764 194
ee03e71d
RB
195 fprintf (stderr, "[%s] # of output tree pickle references: "
196 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
197 lto_stats.num_pickle_refs_output);
198 fprintf (stderr, "[%s] # of output tree bodies: "
199 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
200 lto_stats.num_tree_bodies_output);
201
d7f09764
DN
202 fprintf (stderr, "[%s] # callgraph partitions: "
203 HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
204 lto_stats.num_cgraph_partitions);
205
206 fprintf (stderr, "[%s] Compression: "
207 HOST_WIDE_INT_PRINT_UNSIGNED " input bytes, "
208 HOST_WIDE_INT_PRINT_UNSIGNED " uncompressed bytes", s,
209 lto_stats.num_input_il_bytes,
210 lto_stats.num_uncompressed_il_bytes);
211 if (lto_stats.num_input_il_bytes > 0)
212 {
213 const float dividend = (float) lto_stats.num_uncompressed_il_bytes;
214 const float divisor = (float) lto_stats.num_input_il_bytes;
215 fprintf (stderr, " (ratio: %f)", dividend / divisor);
216 }
217 fprintf (stderr, "\n");
218 }
219
220 for (i = 0; i < LTO_N_SECTION_TYPES; i++)
221 fprintf (stderr, "[%s] Size of mmap'd section %s: "
222 HOST_WIDE_INT_PRINT_UNSIGNED " bytes\n", s,
223 lto_section_name[i], lto_stats.section_size[i]);
224}
225
d7f09764
DN
226/* Initialization common to the LTO reader and writer. */
227
228void
229lto_streamer_init (void)
230{
231 /* Check that all the TS_* handled by the reader and writer routines
232 match exactly the structures defined in treestruct.def. When a
233 new TS_* astructure is added, the streamer should be updated to
234 handle it. */
b2b29377
MM
235 if (flag_checking)
236 streamer_check_handled_ts_structures ();
d7f09764
DN
237}
238
239
240/* Gate function for all LTO streaming passes. */
241
242bool
243gate_lto_out (void)
244{
f0d78df9 245 return ((flag_generate_lto || flag_generate_offload || in_lto_p)
d7f09764 246 /* Don't bother doing anything if the program has errors. */
1da2ed5f 247 && !seen_error ());
d7f09764
DN
248}
249
d7f09764
DN
250/* Check that the version MAJOR.MINOR is the correct version number. */
251
252void
b898d037 253lto_check_version (int major, int minor, const char *file_name)
d7f09764
DN
254{
255 if (major != LTO_major_version || minor != LTO_minor_version)
40fecdd6 256 fatal_error (input_location,
84671705 257 "bytecode stream in file %qs generated with LTO version "
b898d037
ML
258 "%d.%d instead of the expected %d.%d",
259 file_name,
d7f09764
DN
260 major, minor,
261 LTO_major_version, LTO_minor_version);
262}
47c79d56
DN
263
264
47c79d56
DN
265/* Initialize all the streamer hooks used for streaming GIMPLE. */
266
267void
268lto_streamer_hooks_init (void)
269{
270 streamer_hooks_init ();
b9393656
DN
271 streamer_hooks.write_tree = lto_output_tree;
272 streamer_hooks.read_tree = lto_input_tree;
7cb7d208
RB
273 streamer_hooks.input_location = lto_input_location;
274 streamer_hooks.output_location = lto_output_location;
47c79d56 275}