]>
Commit | Line | Data |
---|---|---|
d7f09764 DN |
1 | /* Write and read the cgraph to the memory mapped representation of a |
2 | .o file. | |
3 | ||
85ec4feb | 4 | Copyright (C) 2009-2018 Free Software Foundation, Inc. |
d7f09764 DN |
5 | Contributed by Kenneth Zadeck <zadeck@naturalbridge.com> |
6 | ||
7 | This file is part of GCC. | |
8 | ||
9 | GCC is free software; you can redistribute it and/or modify it under | |
10 | the terms of the GNU General Public License as published by the Free | |
11 | Software Foundation; either version 3, or (at your option) any later | |
12 | version. | |
13 | ||
14 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
15 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 | for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along 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 | 26 | #include "backend.h" |
957060b5 | 27 | #include "rtl.h" |
d7f09764 | 28 | #include "tree.h" |
c7131fb2 | 29 | #include "gimple.h" |
957060b5 | 30 | #include "predict.h" |
957060b5 | 31 | #include "stringpool.h" |
957060b5 AM |
32 | #include "tree-streamer.h" |
33 | #include "cgraph.h" | |
7d57274b | 34 | #include "tree-pass.h" |
2730ada7 | 35 | #include "profile.h" |
315f8c0e DM |
36 | #include "context.h" |
37 | #include "pass_manager.h" | |
82d618d3 | 38 | #include "ipa-utils.h" |
629b3d75 | 39 | #include "omp-offload.h" |
314e6352 ML |
40 | #include "stringpool.h" |
41 | #include "attribs.h" | |
d7f09764 | 42 | |
f300e7b8 JH |
43 | /* True when asm nodes has been output. */ |
44 | bool asm_nodes_output = false; | |
45 | ||
f27c1867 | 46 | static void output_cgraph_opt_summary (void); |
5e20cdc9 | 47 | static void input_cgraph_opt_summary (vec<symtab_node *> nodes); |
922f15c2 | 48 | |
533c07c5 | 49 | /* Number of LDPR values known to GCC. */ |
ed0d2da0 | 50 | #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1) |
2f41ecf5 | 51 | |
398f05da JH |
52 | /* All node orders are ofsetted by ORDER_BASE. */ |
53 | static int order_base; | |
54 | ||
8b4765bf JH |
55 | /* Cgraph streaming is organized as set of record whose type |
56 | is indicated by a tag. */ | |
7380e6ef | 57 | enum LTO_symtab_tags |
8b4765bf JH |
58 | { |
59 | /* Must leave 0 for the stopper. */ | |
60 | ||
61 | /* Cgraph node without body available. */ | |
7380e6ef | 62 | LTO_symtab_unavail_node = 1, |
8b4765bf | 63 | /* Cgraph node with function body. */ |
7380e6ef | 64 | LTO_symtab_analyzed_node, |
8b4765bf | 65 | /* Cgraph edges. */ |
7380e6ef JH |
66 | LTO_symtab_edge, |
67 | LTO_symtab_indirect_edge, | |
68 | LTO_symtab_variable, | |
69 | LTO_symtab_last_tag | |
8b4765bf JH |
70 | }; |
71 | ||
e75f8f79 JH |
72 | /* Create a new symtab encoder. |
73 | if FOR_INPUT, the encoder allocate only datastructures needed | |
74 | to read the symtab. */ | |
d7f09764 | 75 | |
7380e6ef | 76 | lto_symtab_encoder_t |
e75f8f79 | 77 | lto_symtab_encoder_new (bool for_input) |
d7f09764 | 78 | { |
7380e6ef | 79 | lto_symtab_encoder_t encoder = XCNEW (struct lto_symtab_encoder_d); |
e75f8f79 JH |
80 | |
81 | if (!for_input) | |
b787e7a2 | 82 | encoder->map = new hash_map<symtab_node *, size_t>; |
9771b263 | 83 | encoder->nodes.create (0); |
d7f09764 DN |
84 | return encoder; |
85 | } | |
86 | ||
87 | ||
88 | /* Delete ENCODER and its components. */ | |
89 | ||
90 | void | |
7380e6ef | 91 | lto_symtab_encoder_delete (lto_symtab_encoder_t encoder) |
d7f09764 | 92 | { |
9771b263 | 93 | encoder->nodes.release (); |
e75f8f79 | 94 | if (encoder->map) |
b787e7a2 | 95 | delete encoder->map; |
d7f09764 DN |
96 | free (encoder); |
97 | } | |
98 | ||
99 | ||
7380e6ef | 100 | /* Return the existing reference number of NODE in the symtab encoder in |
d7f09764 DN |
101 | output block OB. Assign a new reference if this is the first time |
102 | NODE is encoded. */ | |
103 | ||
104 | int | |
7380e6ef | 105 | lto_symtab_encoder_encode (lto_symtab_encoder_t encoder, |
5e20cdc9 | 106 | symtab_node *node) |
d7f09764 DN |
107 | { |
108 | int ref; | |
b8698a0f | 109 | |
e75f8f79 JH |
110 | if (!encoder->map) |
111 | { | |
112 | lto_encoder_entry entry = {node, false, false, false}; | |
113 | ||
9771b263 DN |
114 | ref = encoder->nodes.length (); |
115 | encoder->nodes.safe_push (entry); | |
e75f8f79 JH |
116 | return ref; |
117 | } | |
118 | ||
b787e7a2 | 119 | size_t *slot = encoder->map->get (node); |
7b99cca4 | 120 | if (!slot || !*slot) |
d7f09764 | 121 | { |
7b99cca4 | 122 | lto_encoder_entry entry = {node, false, false, false}; |
9771b263 | 123 | ref = encoder->nodes.length (); |
7b99cca4 | 124 | if (!slot) |
b787e7a2 | 125 | encoder->map->put (node, ref + 1); |
9771b263 | 126 | encoder->nodes.safe_push (entry); |
d7f09764 DN |
127 | } |
128 | else | |
b787e7a2 | 129 | ref = *slot - 1; |
d7f09764 DN |
130 | |
131 | return ref; | |
132 | } | |
133 | ||
7b99cca4 | 134 | /* Remove NODE from encoder. */ |
d7f09764 | 135 | |
7b99cca4 JH |
136 | bool |
137 | lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder, | |
5e20cdc9 | 138 | symtab_node *node) |
d7f09764 | 139 | { |
7b99cca4 JH |
140 | int index; |
141 | lto_encoder_entry last_node; | |
142 | ||
b787e7a2 | 143 | size_t *slot = encoder->map->get (node); |
7b99cca4 JH |
144 | if (slot == NULL || !*slot) |
145 | return false; | |
146 | ||
b787e7a2 | 147 | index = *slot - 1; |
9771b263 | 148 | gcc_checking_assert (encoder->nodes[index].node == node); |
7b99cca4 JH |
149 | |
150 | /* Remove from vector. We do this by swapping node with the last element | |
151 | of the vector. */ | |
9771b263 | 152 | last_node = encoder->nodes.pop (); |
7b99cca4 JH |
153 | if (last_node.node != node) |
154 | { | |
b787e7a2 | 155 | gcc_assert (encoder->map->put (last_node.node, index + 1)); |
7b99cca4 JH |
156 | |
157 | /* Move the last element to the original spot of NODE. */ | |
9771b263 | 158 | encoder->nodes[index] = last_node; |
7b99cca4 JH |
159 | } |
160 | ||
161 | /* Remove element from hash table. */ | |
b787e7a2 | 162 | encoder->map->remove (node); |
7b99cca4 | 163 | return true; |
d7f09764 DN |
164 | } |
165 | ||
166 | ||
2ead7928 | 167 | /* Return TRUE if we should encode the body of NODE (if any). */ |
d7f09764 | 168 | |
91fbf0c7 | 169 | bool |
7380e6ef | 170 | lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder, |
91fbf0c7 JH |
171 | struct cgraph_node *node) |
172 | { | |
67348ccc | 173 | int index = lto_symtab_encoder_lookup (encoder, node); |
9771b263 | 174 | return encoder->nodes[index].body; |
91fbf0c7 JH |
175 | } |
176 | ||
2ead7928 | 177 | /* Specify that we encode the body of NODE in this partition. */ |
91fbf0c7 JH |
178 | |
179 | static void | |
7380e6ef | 180 | lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder, |
91fbf0c7 | 181 | struct cgraph_node *node) |
d7f09764 | 182 | { |
67348ccc DM |
183 | int index = lto_symtab_encoder_encode (encoder, node); |
184 | gcc_checking_assert (encoder->nodes[index].node == node); | |
9771b263 | 185 | encoder->nodes[index].body = true; |
d7f09764 DN |
186 | } |
187 | ||
2f41ecf5 JH |
188 | /* Return TRUE if we should encode initializer of NODE (if any). */ |
189 | ||
190 | bool | |
7380e6ef | 191 | lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder, |
2c8326a5 | 192 | varpool_node *node) |
2f41ecf5 | 193 | { |
67348ccc | 194 | int index = lto_symtab_encoder_lookup (encoder, node); |
7b99cca4 JH |
195 | if (index == LCC_NOT_FOUND) |
196 | return false; | |
9771b263 | 197 | return encoder->nodes[index].initializer; |
2f41ecf5 JH |
198 | } |
199 | ||
2ead7928 | 200 | /* Specify that we should encode initializer of NODE (if any). */ |
2f41ecf5 JH |
201 | |
202 | static void | |
7380e6ef | 203 | lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder, |
2c8326a5 | 204 | varpool_node *node) |
2f41ecf5 | 205 | { |
67348ccc | 206 | int index = lto_symtab_encoder_lookup (encoder, node); |
9771b263 | 207 | encoder->nodes[index].initializer = true; |
2f41ecf5 | 208 | } |
d7f09764 | 209 | |
2ead7928 | 210 | /* Return TRUE if NODE is in this partition. */ |
f27c1867 JH |
211 | |
212 | bool | |
213 | lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder, | |
5e20cdc9 | 214 | symtab_node *node) |
f27c1867 | 215 | { |
67348ccc | 216 | int index = lto_symtab_encoder_lookup (encoder, node); |
7b99cca4 JH |
217 | if (index == LCC_NOT_FOUND) |
218 | return false; | |
9771b263 | 219 | return encoder->nodes[index].in_partition; |
f27c1867 JH |
220 | } |
221 | ||
2ead7928 | 222 | /* Specify that NODE is in this partition. */ |
f27c1867 JH |
223 | |
224 | void | |
225 | lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder, | |
5e20cdc9 | 226 | symtab_node *node) |
f27c1867 | 227 | { |
67348ccc | 228 | int index = lto_symtab_encoder_encode (encoder, node); |
9771b263 | 229 | encoder->nodes[index].in_partition = true; |
f27c1867 JH |
230 | } |
231 | ||
d7f09764 DN |
232 | /* Output the cgraph EDGE to OB using ENCODER. */ |
233 | ||
234 | static void | |
235 | lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge, | |
7380e6ef | 236 | lto_symtab_encoder_t encoder) |
d7f09764 DN |
237 | { |
238 | unsigned int uid; | |
239 | intptr_t ref; | |
2465dcc2 | 240 | struct bitpack_d bp; |
d7f09764 | 241 | |
e33c6cd6 | 242 | if (edge->indirect_unknown_callee) |
7380e6ef JH |
243 | streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, |
244 | LTO_symtab_indirect_edge); | |
e33c6cd6 | 245 | else |
7380e6ef JH |
246 | streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, |
247 | LTO_symtab_edge); | |
d7f09764 | 248 | |
67348ccc | 249 | ref = lto_symtab_encoder_lookup (encoder, edge->caller); |
b8698a0f | 250 | gcc_assert (ref != LCC_NOT_FOUND); |
412288f1 | 251 | streamer_write_hwi_stream (ob->main_stream, ref); |
d7f09764 | 252 | |
e33c6cd6 MJ |
253 | if (!edge->indirect_unknown_callee) |
254 | { | |
67348ccc | 255 | ref = lto_symtab_encoder_lookup (encoder, edge->callee); |
e33c6cd6 | 256 | gcc_assert (ref != LCC_NOT_FOUND); |
412288f1 | 257 | streamer_write_hwi_stream (ob->main_stream, ref); |
e33c6cd6 | 258 | } |
d7f09764 | 259 | |
3995f3a2 | 260 | edge->count.stream_out (ob->main_stream); |
d7f09764 | 261 | |
2465dcc2 | 262 | bp = bitpack_create (ob->main_stream); |
ec6a1e35 | 263 | uid = (!gimple_has_body_p (edge->caller->decl) || edge->caller->thunk.thunk_p |
042ae7d2 | 264 | ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt) + 1); |
84562394 | 265 | bp_pack_enum (&bp, cgraph_inline_failed_t, |
533c07c5 JH |
266 | CIF_N_REASONS, edge->inline_failed); |
267 | bp_pack_var_len_unsigned (&bp, uid); | |
2465dcc2 | 268 | bp_pack_value (&bp, edge->indirect_inlining_edge, 1); |
042ae7d2 | 269 | bp_pack_value (&bp, edge->speculative, 1); |
2465dcc2 | 270 | bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1); |
1a0bf5e1 JH |
271 | gcc_assert (!edge->call_stmt_cannot_inline_p |
272 | || edge->inline_failed != CIF_BODY_NOT_AVAILABLE); | |
2465dcc2 | 273 | bp_pack_value (&bp, edge->can_throw_external, 1); |
f9bb202b | 274 | bp_pack_value (&bp, edge->in_polymorphic_cdtor, 1); |
5f902d76 JH |
275 | if (edge->indirect_unknown_callee) |
276 | { | |
277 | int flags = edge->indirect_info->ecf_flags; | |
2465dcc2 RG |
278 | bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1); |
279 | bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1); | |
280 | bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1); | |
281 | bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1); | |
282 | bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1); | |
283 | bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1); | |
5f902d76 JH |
284 | /* Flags that should not appear on indirect calls. */ |
285 | gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE | |
286 | | ECF_MAY_BE_ALLOCA | |
287 | | ECF_SIBCALL | |
db0bf14f | 288 | | ECF_LEAF |
5f902d76 JH |
289 | | ECF_NOVOPS))); |
290 | } | |
412288f1 | 291 | streamer_write_bitpack (&bp); |
634ab819 JH |
292 | if (edge->indirect_unknown_callee) |
293 | { | |
294 | streamer_write_hwi_stream (ob->main_stream, | |
295 | edge->indirect_info->common_target_id); | |
296 | if (edge->indirect_info->common_target_id) | |
297 | streamer_write_hwi_stream | |
298 | (ob->main_stream, edge->indirect_info->common_target_probability); | |
299 | } | |
d7f09764 DN |
300 | } |
301 | ||
d122681a | 302 | /* Return if NODE contain references from other partitions. */ |
f3380641 | 303 | |
369451ec | 304 | bool |
d122681a | 305 | referenced_from_other_partition_p (symtab_node *node, lto_symtab_encoder_t encoder) |
369451ec JH |
306 | { |
307 | int i; | |
d122681a ML |
308 | struct ipa_ref *ref = NULL; |
309 | ||
310 | for (i = 0; node->iterate_referring (i, ref); i++) | |
369451ec | 311 | { |
1f6be682 IV |
312 | /* Ignore references from non-offloadable nodes while streaming NODE into |
313 | offload LTO section. */ | |
314 | if (!ref->referring->need_lto_streaming) | |
315 | continue; | |
316 | ||
67348ccc | 317 | if (ref->referring->in_other_partition |
f27c1867 JH |
318 | || !lto_symtab_encoder_in_partition_p (encoder, ref->referring)) |
319 | return true; | |
369451ec JH |
320 | } |
321 | return false; | |
322 | } | |
323 | ||
a837268b JH |
324 | /* Return true when node is reachable from other partition. */ |
325 | ||
9a809897 | 326 | bool |
f27c1867 | 327 | reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder) |
a837268b JH |
328 | { |
329 | struct cgraph_edge *e; | |
67348ccc | 330 | if (!node->definition) |
a837268b JH |
331 | return false; |
332 | if (node->global.inlined_to) | |
333 | return false; | |
334 | for (e = node->callers; e; e = e->next_caller) | |
1f6be682 IV |
335 | { |
336 | /* Ignore references from non-offloadable nodes while streaming NODE into | |
337 | offload LTO section. */ | |
338 | if (!e->caller->need_lto_streaming) | |
339 | continue; | |
340 | ||
341 | if (e->caller->in_other_partition | |
342 | || !lto_symtab_encoder_in_partition_p (encoder, e->caller)) | |
343 | return true; | |
344 | } | |
a837268b JH |
345 | return false; |
346 | } | |
d7f09764 | 347 | |
d122681a | 348 | /* Return if NODE contain references from other partitions. */ |
f3380641 JH |
349 | |
350 | bool | |
d122681a | 351 | referenced_from_this_partition_p (symtab_node *node, |
f27c1867 | 352 | lto_symtab_encoder_t encoder) |
f3380641 JH |
353 | { |
354 | int i; | |
d122681a ML |
355 | struct ipa_ref *ref = NULL; |
356 | ||
357 | for (i = 0; node->iterate_referring (i, ref); i++) | |
f27c1867 JH |
358 | if (lto_symtab_encoder_in_partition_p (encoder, ref->referring)) |
359 | return true; | |
f3380641 JH |
360 | return false; |
361 | } | |
362 | ||
363 | /* Return true when node is reachable from other partition. */ | |
364 | ||
365 | bool | |
f27c1867 | 366 | reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder) |
f3380641 JH |
367 | { |
368 | struct cgraph_edge *e; | |
f3380641 | 369 | for (e = node->callers; e; e = e->next_caller) |
67348ccc | 370 | if (lto_symtab_encoder_in_partition_p (encoder, e->caller)) |
f3380641 JH |
371 | return true; |
372 | return false; | |
373 | } | |
374 | ||
d7f09764 DN |
375 | /* Output the cgraph NODE to OB. ENCODER is used to find the |
376 | reference number of NODE->inlined_to. SET is the set of nodes we | |
377 | are writing to the current file. If NODE is not in SET, then NODE | |
378 | is a boundary of a cgraph_node_set and we pretend NODE just has a | |
379 | decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs | |
380 | that have had their callgraph node written so far. This is used to | |
381 | determine if NODE is a clone of a previously written node. */ | |
382 | ||
383 | static void | |
384 | lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node, | |
f27c1867 | 385 | lto_symtab_encoder_t encoder) |
d7f09764 DN |
386 | { |
387 | unsigned int tag; | |
2465dcc2 | 388 | struct bitpack_d bp; |
91fbf0c7 | 389 | bool boundary_p; |
d7f09764 | 390 | intptr_t ref; |
a837268b | 391 | bool in_other_partition = false; |
a2e2a668 | 392 | struct cgraph_node *clone_of, *ultimate_clone_of; |
6a5ac314 | 393 | ipa_opt_pass_d *pass; |
7d57274b | 394 | int i; |
aede2c10 | 395 | const char *comdat; |
24d047a3 | 396 | const char *section; |
aede2c10 | 397 | tree group; |
d7f09764 | 398 | |
67348ccc | 399 | boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node); |
d7f09764 | 400 | |
ec6a1e35 JH |
401 | if (node->analyzed && (!boundary_p || node->alias |
402 | || (node->thunk.thunk_p && !node->global.inlined_to))) | |
7380e6ef | 403 | tag = LTO_symtab_analyzed_node; |
8b4765bf | 404 | else |
7380e6ef | 405 | tag = LTO_symtab_unavail_node; |
d7f09764 | 406 | |
7380e6ef | 407 | streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, |
412288f1 | 408 | tag); |
67348ccc | 409 | streamer_write_hwi_stream (ob->main_stream, node->order); |
d7f09764 | 410 | |
d7f09764 DN |
411 | /* In WPA mode, we only output part of the call-graph. Also, we |
412 | fake cgraph node attributes. There are two cases that we care. | |
413 | ||
414 | Boundary nodes: There are nodes that are not part of SET but are | |
415 | called from within SET. We artificially make them look like | |
b8698a0f | 416 | externally visible nodes with no function body. |
d7f09764 DN |
417 | |
418 | Cherry-picked nodes: These are nodes we pulled from other | |
419 | translation units into SET during IPA-inlining. We make them as | |
420 | local static nodes to prevent clashes with other local statics. */ | |
96451279 | 421 | if (boundary_p && node->analyzed |
d52f5295 | 422 | && node->get_partitioning_class () == SYMBOL_PARTITION) |
d7f09764 | 423 | { |
a837268b JH |
424 | /* Inline clones can not be part of boundary. |
425 | gcc_assert (!node->global.inlined_to); | |
426 | ||
427 | FIXME: At the moment they can be, when partition contains an inline | |
428 | clone that is clone of inline clone from outside partition. We can | |
429 | reshape the clone tree and make other tree to be the root, but it | |
430 | needs a bit extra work and will be promplty done by cgraph_remove_node | |
431 | after reading back. */ | |
432 | in_other_partition = 1; | |
d7f09764 | 433 | } |
d7f09764 | 434 | |
91fbf0c7 JH |
435 | clone_of = node->clone_of; |
436 | while (clone_of | |
67348ccc | 437 | && (ref = lto_symtab_encoder_lookup (encoder, clone_of)) == LCC_NOT_FOUND) |
91fbf0c7 JH |
438 | if (clone_of->prev_sibling_clone) |
439 | clone_of = clone_of->prev_sibling_clone; | |
440 | else | |
441 | clone_of = clone_of->clone_of; | |
0cac82a0 | 442 | |
a2e2a668 JH |
443 | /* See if body of the master function is output. If not, we are seeing only |
444 | an declaration and we do not need to pass down clone tree. */ | |
445 | ultimate_clone_of = clone_of; | |
446 | while (ultimate_clone_of && ultimate_clone_of->clone_of) | |
447 | ultimate_clone_of = ultimate_clone_of->clone_of; | |
448 | ||
449 | if (clone_of && !lto_symtab_encoder_encode_body_p (encoder, ultimate_clone_of)) | |
450 | clone_of = NULL; | |
451 | ||
452 | if (tag == LTO_symtab_analyzed_node) | |
0cac82a0 | 453 | gcc_assert (clone_of || !node->clone_of); |
91fbf0c7 | 454 | if (!clone_of) |
412288f1 | 455 | streamer_write_hwi_stream (ob->main_stream, LCC_NOT_FOUND); |
91fbf0c7 | 456 | else |
412288f1 | 457 | streamer_write_hwi_stream (ob->main_stream, ref); |
d7f09764 | 458 | |
d7f09764 | 459 | |
67348ccc | 460 | lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->decl); |
3995f3a2 | 461 | node->count.stream_out (ob->main_stream); |
412288f1 | 462 | streamer_write_hwi_stream (ob->main_stream, node->count_materialization_scale); |
d7f09764 | 463 | |
7d57274b | 464 | streamer_write_hwi_stream (ob->main_stream, |
9771b263 DN |
465 | node->ipa_transforms_to_apply.length ()); |
466 | FOR_EACH_VEC_ELT (node->ipa_transforms_to_apply, i, pass) | |
f7695dbf | 467 | streamer_write_hwi_stream (ob->main_stream, pass->static_pass_number); |
7d57274b | 468 | |
7380e6ef | 469 | if (tag == LTO_symtab_analyzed_node) |
d7f09764 | 470 | { |
8b4765bf JH |
471 | if (node->global.inlined_to) |
472 | { | |
67348ccc | 473 | ref = lto_symtab_encoder_lookup (encoder, node->global.inlined_to); |
8b4765bf JH |
474 | gcc_assert (ref != LCC_NOT_FOUND); |
475 | } | |
476 | else | |
477 | ref = LCC_NOT_FOUND; | |
d7f09764 | 478 | |
412288f1 | 479 | streamer_write_hwi_stream (ob->main_stream, ref); |
d7f09764 | 480 | } |
d7f09764 | 481 | |
aede2c10 JH |
482 | group = node->get_comdat_group (); |
483 | if (group) | |
484 | comdat = IDENTIFIER_POINTER (group); | |
485 | else | |
486 | comdat = ""; | |
bfa2ebe3 | 487 | streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1); |
24d047a3 | 488 | |
aede2c10 | 489 | if (group) |
b66887e4 | 490 | { |
71e54687 | 491 | if (node->same_comdat_group) |
aede2c10 | 492 | { |
71e54687 JH |
493 | ref = LCC_NOT_FOUND; |
494 | for (struct symtab_node *n = node->same_comdat_group; | |
495 | ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group) | |
496 | ref = lto_symtab_encoder_lookup (encoder, n); | |
aede2c10 JH |
497 | } |
498 | else | |
499 | ref = LCC_NOT_FOUND; | |
500 | streamer_write_hwi_stream (ob->main_stream, ref); | |
b66887e4 | 501 | } |
b66887e4 | 502 | |
e257a17c JH |
503 | section = node->get_section (); |
504 | if (!section) | |
24d047a3 | 505 | section = ""; |
24d047a3 | 506 | |
86ce5d2f ML |
507 | streamer_write_hwi_stream (ob->main_stream, node->tp_first_run); |
508 | ||
2465dcc2 RG |
509 | bp = bitpack_create (ob->main_stream); |
510 | bp_pack_value (&bp, node->local.local, 1); | |
67348ccc | 511 | bp_pack_value (&bp, node->externally_visible, 1); |
7861b648 | 512 | bp_pack_value (&bp, node->no_reorder, 1); |
67348ccc | 513 | bp_pack_value (&bp, node->definition, 1); |
124f1be6 | 514 | bp_pack_value (&bp, node->local.versionable, 1); |
61e03ffc | 515 | bp_pack_value (&bp, node->local.can_change_signature, 1); |
2465dcc2 | 516 | bp_pack_value (&bp, node->local.redefined_extern_inline, 1); |
67348ccc DM |
517 | bp_pack_value (&bp, node->force_output, 1); |
518 | bp_pack_value (&bp, node->forced_by_abi, 1); | |
519 | bp_pack_value (&bp, node->unique_name, 1); | |
4a5798de | 520 | bp_pack_value (&bp, node->body_removed, 1); |
e257a17c | 521 | bp_pack_value (&bp, node->implicit_section, 1); |
67348ccc | 522 | bp_pack_value (&bp, node->address_taken, 1); |
7380e6ef | 523 | bp_pack_value (&bp, tag == LTO_symtab_analyzed_node |
d52f5295 | 524 | && node->get_partitioning_class () == SYMBOL_PARTITION |
f27c1867 | 525 | && (reachable_from_other_partition_p (node, encoder) |
d122681a | 526 | || referenced_from_other_partition_p (node, encoder)), 1); |
2465dcc2 RG |
527 | bp_pack_value (&bp, node->lowered, 1); |
528 | bp_pack_value (&bp, in_other_partition, 1); | |
4bd019b8 | 529 | bp_pack_value (&bp, node->alias, 1); |
71e54687 | 530 | bp_pack_value (&bp, node->transparent_alias, 1); |
67348ccc | 531 | bp_pack_value (&bp, node->weakref, 1); |
2465dcc2 | 532 | bp_pack_value (&bp, node->frequency, 2); |
844db5d0 JH |
533 | bp_pack_value (&bp, node->only_called_at_startup, 1); |
534 | bp_pack_value (&bp, node->only_called_at_exit, 1); | |
57ac2606 | 535 | bp_pack_value (&bp, node->tm_clone, 1); |
1f26ac87 | 536 | bp_pack_value (&bp, node->calls_comdat_local, 1); |
b84d4347 | 537 | bp_pack_value (&bp, node->icf_merged, 1); |
8413ca87 | 538 | bp_pack_value (&bp, node->nonfreeing_fn, 1); |
4bd019b8 | 539 | bp_pack_value (&bp, node->thunk.thunk_p, 1); |
a79b7ec5 | 540 | bp_pack_value (&bp, node->parallelized_function, 1); |
533c07c5 | 541 | bp_pack_enum (&bp, ld_plugin_symbol_resolution, |
5b42d196 JH |
542 | LDPR_NUM_KNOWN, |
543 | /* When doing incremental link, we will get new resolution | |
544 | info next time we process the file. */ | |
545 | flag_incremental_link ? LDPR_UNKNOWN : node->resolution); | |
41f669d8 | 546 | bp_pack_value (&bp, node->split_part, 1); |
412288f1 | 547 | streamer_write_bitpack (&bp); |
bfa2ebe3 | 548 | streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1); |
2465dcc2 | 549 | |
4bd019b8 | 550 | if (node->thunk.thunk_p) |
c47d0034 | 551 | { |
412288f1 | 552 | streamer_write_uhwi_stream |
c47d0034 JH |
553 | (ob->main_stream, |
554 | 1 + (node->thunk.this_adjusting != 0) * 2 | |
d5e254e1 IE |
555 | + (node->thunk.virtual_offset_p != 0) * 4 |
556 | + (node->thunk.add_pointer_bounds_args != 0) * 8); | |
412288f1 DN |
557 | streamer_write_uhwi_stream (ob->main_stream, node->thunk.fixed_offset); |
558 | streamer_write_uhwi_stream (ob->main_stream, node->thunk.virtual_value); | |
c47d0034 | 559 | } |
634ab819 | 560 | streamer_write_hwi_stream (ob->main_stream, node->profile_id); |
569b1784 | 561 | if (DECL_STATIC_CONSTRUCTOR (node->decl)) |
1cff83e2 | 562 | streamer_write_hwi_stream (ob->main_stream, node->get_init_priority ()); |
569b1784 | 563 | if (DECL_STATIC_DESTRUCTOR (node->decl)) |
1cff83e2 | 564 | streamer_write_hwi_stream (ob->main_stream, node->get_fini_priority ()); |
d7f09764 DN |
565 | } |
566 | ||
2942c502 JH |
567 | /* Output the varpool NODE to OB. |
568 | If NODE is not in SET, then NODE is a boundary. */ | |
569 | ||
570 | static void | |
2c8326a5 | 571 | lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node, |
f27c1867 | 572 | lto_symtab_encoder_t encoder) |
2942c502 | 573 | { |
67348ccc | 574 | bool boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node); |
87be7f0c JH |
575 | bool encode_initializer_p |
576 | = (node->definition | |
577 | && lto_symtab_encoder_encode_initializer_p (encoder, node)); | |
2465dcc2 | 578 | struct bitpack_d bp; |
9f90e80a | 579 | int ref; |
aede2c10 | 580 | const char *comdat; |
24d047a3 | 581 | const char *section; |
aede2c10 | 582 | tree group; |
2942c502 | 583 | |
87be7f0c JH |
584 | gcc_assert (!encode_initializer_p || node->definition); |
585 | gcc_assert (boundary_p || encode_initializer_p); | |
586 | ||
7380e6ef JH |
587 | streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, |
588 | LTO_symtab_variable); | |
67348ccc DM |
589 | streamer_write_hwi_stream (ob->main_stream, node->order); |
590 | lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->decl); | |
2465dcc2 | 591 | bp = bitpack_create (ob->main_stream); |
67348ccc | 592 | bp_pack_value (&bp, node->externally_visible, 1); |
7861b648 | 593 | bp_pack_value (&bp, node->no_reorder, 1); |
67348ccc DM |
594 | bp_pack_value (&bp, node->force_output, 1); |
595 | bp_pack_value (&bp, node->forced_by_abi, 1); | |
596 | bp_pack_value (&bp, node->unique_name, 1); | |
87be7f0c JH |
597 | bp_pack_value (&bp, |
598 | node->body_removed | |
599 | || (!encode_initializer_p && !node->alias && node->definition), | |
600 | 1); | |
e257a17c | 601 | bp_pack_value (&bp, node->implicit_section, 1); |
6de88c6a | 602 | bp_pack_value (&bp, node->writeonly, 1); |
87be7f0c JH |
603 | bp_pack_value (&bp, node->definition && (encode_initializer_p || node->alias), |
604 | 1); | |
4bd019b8 | 605 | bp_pack_value (&bp, node->alias, 1); |
71e54687 | 606 | bp_pack_value (&bp, node->transparent_alias, 1); |
67348ccc | 607 | bp_pack_value (&bp, node->weakref, 1); |
71e54687 | 608 | bp_pack_value (&bp, node->analyzed && (!boundary_p || node->alias), 1); |
67348ccc | 609 | gcc_assert (node->definition || !node->analyzed); |
05575e07 JH |
610 | /* Constant pool initializers can be de-unified into individual ltrans units. |
611 | FIXME: Alternatively at -Os we may want to avoid generating for them the local | |
612 | labels and share them across LTRANS partitions. */ | |
d52f5295 | 613 | if (node->get_partitioning_class () != SYMBOL_PARTITION) |
05575e07 | 614 | { |
2465dcc2 RG |
615 | bp_pack_value (&bp, 0, 1); /* used_from_other_parition. */ |
616 | bp_pack_value (&bp, 0, 1); /* in_other_partition. */ | |
05575e07 JH |
617 | } |
618 | else | |
619 | { | |
67348ccc | 620 | bp_pack_value (&bp, node->definition |
d122681a | 621 | && referenced_from_other_partition_p (node, encoder), 1); |
67348ccc DM |
622 | bp_pack_value (&bp, node->analyzed |
623 | && boundary_p && !DECL_EXTERNAL (node->decl), 1); | |
6649df51 | 624 | /* in_other_partition. */ |
05575e07 | 625 | } |
56363ffd | 626 | bp_pack_value (&bp, node->tls_model, 3); |
eb6a09a7 | 627 | bp_pack_value (&bp, node->used_by_single_function, 1); |
ca280d38 | 628 | bp_pack_value (&bp, node->dynamically_initialized, 1); |
d5e254e1 | 629 | bp_pack_value (&bp, node->need_bounds_init, 1); |
412288f1 | 630 | streamer_write_bitpack (&bp); |
24d047a3 | 631 | |
aede2c10 JH |
632 | group = node->get_comdat_group (); |
633 | if (group) | |
634 | comdat = IDENTIFIER_POINTER (group); | |
635 | else | |
636 | comdat = ""; | |
bfa2ebe3 | 637 | streamer_write_data_stream (ob->main_stream, comdat, strlen (comdat) + 1); |
24d047a3 | 638 | |
aede2c10 | 639 | if (group) |
9f90e80a | 640 | { |
71e54687 | 641 | if (node->same_comdat_group) |
aede2c10 | 642 | { |
71e54687 JH |
643 | ref = LCC_NOT_FOUND; |
644 | for (struct symtab_node *n = node->same_comdat_group; | |
645 | ref == LCC_NOT_FOUND && n != node; n = n->same_comdat_group) | |
646 | ref = lto_symtab_encoder_lookup (encoder, n); | |
aede2c10 JH |
647 | } |
648 | else | |
649 | ref = LCC_NOT_FOUND; | |
650 | streamer_write_hwi_stream (ob->main_stream, ref); | |
9f90e80a | 651 | } |
24d047a3 | 652 | |
e257a17c JH |
653 | section = node->get_section (); |
654 | if (!section) | |
24d047a3 | 655 | section = ""; |
bfa2ebe3 | 656 | streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1); |
24d047a3 | 657 | |
412288f1 | 658 | streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution, |
67348ccc | 659 | LDPR_NUM_KNOWN, node->resolution); |
2942c502 JH |
660 | } |
661 | ||
369451ec JH |
662 | /* Output the varpool NODE to OB. |
663 | If NODE is not in SET, then NODE is a boundary. */ | |
664 | ||
665 | static void | |
666 | lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref, | |
7380e6ef | 667 | lto_symtab_encoder_t encoder) |
369451ec | 668 | { |
2465dcc2 | 669 | struct bitpack_d bp; |
7380e6ef | 670 | int nref; |
042ae7d2 JH |
671 | int uid = ref->lto_stmt_uid; |
672 | struct cgraph_node *node; | |
7380e6ef | 673 | |
2465dcc2 | 674 | bp = bitpack_create (ob->main_stream); |
d5e254e1 | 675 | bp_pack_value (&bp, ref->use, 3); |
042ae7d2 | 676 | bp_pack_value (&bp, ref->speculative, 1); |
412288f1 | 677 | streamer_write_bitpack (&bp); |
7380e6ef JH |
678 | nref = lto_symtab_encoder_lookup (encoder, ref->referred); |
679 | gcc_assert (nref != LCC_NOT_FOUND); | |
680 | streamer_write_hwi_stream (ob->main_stream, nref); | |
042ae7d2 | 681 | |
7de90a6c | 682 | node = dyn_cast <cgraph_node *> (ref->referring); |
042ae7d2 JH |
683 | if (node) |
684 | { | |
685 | if (ref->stmt) | |
686 | uid = gimple_uid (ref->stmt) + 1; | |
687 | streamer_write_hwi_stream (ob->main_stream, uid); | |
688 | } | |
369451ec JH |
689 | } |
690 | ||
0bc1b77f JH |
691 | /* Stream out profile_summary to OB. */ |
692 | ||
693 | static void | |
694 | output_profile_summary (struct lto_simple_output_block *ob) | |
695 | { | |
2730ada7 TJ |
696 | unsigned h_ix; |
697 | struct bitpack_d bp; | |
698 | ||
0bc1b77f JH |
699 | if (profile_info) |
700 | { | |
2730ada7 TJ |
701 | /* We do not output num and run_max, they are not used by |
702 | GCC profile feedback and they are difficult to merge from multiple | |
703 | units. */ | |
0bc1b77f | 704 | gcc_assert (profile_info->runs); |
412288f1 | 705 | streamer_write_uhwi_stream (ob->main_stream, profile_info->runs); |
0208f7da | 706 | streamer_write_gcov_count_stream (ob->main_stream, profile_info->sum_max); |
2730ada7 TJ |
707 | |
708 | /* sum_all is needed for computing the working set with the | |
709 | histogram. */ | |
0208f7da | 710 | streamer_write_gcov_count_stream (ob->main_stream, profile_info->sum_all); |
2730ada7 TJ |
711 | |
712 | /* Create and output a bitpack of non-zero histogram entries indices. */ | |
713 | bp = bitpack_create (ob->main_stream); | |
714 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
715 | bp_pack_value (&bp, profile_info->histogram[h_ix].num_counters > 0, 1); | |
716 | streamer_write_bitpack (&bp); | |
717 | /* Now stream out only those non-zero entries. */ | |
718 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
719 | { | |
720 | if (!profile_info->histogram[h_ix].num_counters) | |
721 | continue; | |
0208f7da | 722 | streamer_write_gcov_count_stream (ob->main_stream, |
2730ada7 | 723 | profile_info->histogram[h_ix].num_counters); |
0208f7da | 724 | streamer_write_gcov_count_stream (ob->main_stream, |
2730ada7 | 725 | profile_info->histogram[h_ix].min_value); |
0208f7da | 726 | streamer_write_gcov_count_stream (ob->main_stream, |
2730ada7 | 727 | profile_info->histogram[h_ix].cum_value); |
0208f7da JH |
728 | } |
729 | /* IPA-profile computes hot bb threshold based on cumulated | |
730 | whole program profile. We need to stream it down to ltrans. */ | |
731 | if (flag_wpa) | |
732 | streamer_write_gcov_count_stream (ob->main_stream, | |
733 | get_hot_bb_threshold ()); | |
0bc1b77f JH |
734 | } |
735 | else | |
412288f1 | 736 | streamer_write_uhwi_stream (ob->main_stream, 0); |
0bc1b77f JH |
737 | } |
738 | ||
e33c6cd6 MJ |
739 | /* Output all callees or indirect outgoing edges. EDGE must be the first such |
740 | edge. */ | |
741 | ||
742 | static void | |
743 | output_outgoing_cgraph_edges (struct cgraph_edge *edge, | |
744 | struct lto_simple_output_block *ob, | |
7380e6ef | 745 | lto_symtab_encoder_t encoder) |
e33c6cd6 MJ |
746 | { |
747 | if (!edge) | |
748 | return; | |
749 | ||
750 | /* Output edges in backward direction, so the reconstructed callgraph match | |
751 | and it is easy to associate call sites in the IPA pass summaries. */ | |
752 | while (edge->next_callee) | |
753 | edge = edge->next_callee; | |
754 | for (; edge; edge = edge->prev_callee) | |
755 | lto_output_edge (ob, edge, encoder); | |
756 | } | |
757 | ||
369451ec JH |
758 | /* Output the part of the cgraph in SET. */ |
759 | ||
760 | static void | |
f27c1867 | 761 | output_refs (lto_symtab_encoder_t encoder) |
369451ec | 762 | { |
369451ec JH |
763 | struct lto_simple_output_block *ob; |
764 | int count; | |
765 | struct ipa_ref *ref; | |
369451ec JH |
766 | |
767 | ob = lto_create_simple_output_block (LTO_section_refs); | |
768 | ||
4bd019b8 | 769 | for (int i = 0; i < lto_symtab_encoder_size (encoder); i++) |
369451ec | 770 | { |
4bd019b8 JH |
771 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
772 | ||
31db0fe0 | 773 | /* IPA_REF_ALIAS references are always preserved |
48de5d37 IE |
774 | in the boundary. Alias node can't have other references and |
775 | can be always handled as if it's not in the boundary. */ | |
4bd019b8 | 776 | if (!node->alias && !lto_symtab_encoder_in_partition_p (encoder, node)) |
31db0fe0 | 777 | continue; |
369451ec | 778 | |
d122681a | 779 | count = node->ref_list.nreferences (); |
369451ec JH |
780 | if (count) |
781 | { | |
edb983b2 | 782 | streamer_write_gcov_count_stream (ob->main_stream, count); |
412288f1 | 783 | streamer_write_uhwi_stream (ob->main_stream, |
f27c1867 | 784 | lto_symtab_encoder_lookup (encoder, node)); |
4bd019b8 | 785 | for (int i = 0; node->iterate_reference (i, ref); i++) |
7380e6ef | 786 | lto_output_ref (ob, ref, encoder); |
369451ec JH |
787 | } |
788 | } | |
789 | ||
412288f1 | 790 | streamer_write_uhwi_stream (ob->main_stream, 0); |
369451ec JH |
791 | |
792 | lto_destroy_simple_output_block (ob); | |
793 | } | |
794 | ||
b4661bfe JH |
795 | /* Add NODE into encoder as well as nodes it is cloned from. |
796 | Do it in a way so clones appear first. */ | |
797 | ||
798 | static void | |
799 | add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node, | |
800 | bool include_body) | |
801 | { | |
802 | if (node->clone_of) | |
803 | add_node_to (encoder, node->clone_of, include_body); | |
804 | else if (include_body) | |
805 | lto_set_symtab_encoder_encode_body (encoder, node); | |
67348ccc | 806 | lto_symtab_encoder_encode (encoder, node); |
b4661bfe JH |
807 | } |
808 | ||
d122681a | 809 | /* Add all references in NODE to encoders. */ |
b4661bfe JH |
810 | |
811 | static void | |
3dafb85c | 812 | create_references (lto_symtab_encoder_t encoder, symtab_node *node) |
b4661bfe JH |
813 | { |
814 | int i; | |
d122681a ML |
815 | struct ipa_ref *ref = NULL; |
816 | for (i = 0; node->iterate_reference (i, ref); i++) | |
7de90a6c | 817 | if (is_a <cgraph_node *> (ref->referred)) |
d122681a | 818 | add_node_to (encoder, dyn_cast <cgraph_node *> (ref->referred), false); |
b4661bfe | 819 | else |
b5493fb2 | 820 | lto_symtab_encoder_encode (encoder, ref->referred); |
b4661bfe JH |
821 | } |
822 | ||
1f6be682 IV |
823 | /* Select what needs to be streamed out. In regular lto mode stream everything. |
824 | In offload lto mode stream only nodes marked as offloadable. */ | |
825 | void | |
837bac8c | 826 | select_what_to_stream (void) |
1f6be682 IV |
827 | { |
828 | struct symtab_node *snode; | |
829 | FOR_EACH_SYMBOL (snode) | |
837bac8c | 830 | snode->need_lto_streaming = !lto_stream_offload_p || snode->offloadable; |
1f6be682 IV |
831 | } |
832 | ||
b4661bfe JH |
833 | /* Find all symbols we want to stream into given partition and insert them |
834 | to encoders. | |
835 | ||
836 | The function actually replaces IN_ENCODER by new one. The reason is that | |
837 | streaming code needs clone's origin to be streamed before clone. This | |
838 | means that we need to insert the nodes in specific order. This order is | |
839 | ignored by the partitioning logic earlier. */ | |
840 | ||
841 | lto_symtab_encoder_t | |
842 | compute_ltrans_boundary (lto_symtab_encoder_t in_encoder) | |
d7f09764 | 843 | { |
d7f09764 | 844 | struct cgraph_edge *edge; |
f3380641 | 845 | int i; |
7380e6ef | 846 | lto_symtab_encoder_t encoder; |
7b99cca4 | 847 | lto_symtab_encoder_iterator lsei; |
6e2830c3 | 848 | hash_set<void *> reachable_call_targets; |
0bc1b77f | 849 | |
e75f8f79 | 850 | encoder = lto_symtab_encoder_new (false); |
d7f09764 | 851 | |
7b99cca4 JH |
852 | /* Go over all entries in the IN_ENCODER and duplicate them to |
853 | ENCODER. At the same time insert masters of clones so | |
854 | every master appears before clone. */ | |
855 | for (lsei = lsei_start_function_in_partition (in_encoder); | |
856 | !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei)) | |
d7f09764 | 857 | { |
224dbc07 | 858 | struct cgraph_node *node = lsei_cgraph_node (lsei); |
1f6be682 IV |
859 | if (!node->need_lto_streaming) |
860 | continue; | |
91fbf0c7 | 861 | add_node_to (encoder, node, true); |
67348ccc | 862 | lto_set_symtab_encoder_in_partition (encoder, node); |
3dafb85c | 863 | create_references (encoder, node); |
d7f09764 | 864 | } |
7b99cca4 JH |
865 | for (lsei = lsei_start_variable_in_partition (in_encoder); |
866 | !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei)) | |
2f41ecf5 | 867 | { |
2c8326a5 | 868 | varpool_node *vnode = lsei_varpool_node (lsei); |
40a7fe1e | 869 | |
1f6be682 IV |
870 | if (!vnode->need_lto_streaming) |
871 | continue; | |
67348ccc | 872 | lto_set_symtab_encoder_in_partition (encoder, vnode); |
7380e6ef | 873 | lto_set_symtab_encoder_encode_initializer (encoder, vnode); |
3dafb85c | 874 | create_references (encoder, vnode); |
2f41ecf5 | 875 | } |
2f41ecf5 JH |
876 | /* Pickle in also the initializer of all referenced readonly variables |
877 | to help folding. Constant pool variables are not shared, so we must | |
878 | pickle those too. */ | |
7380e6ef | 879 | for (i = 0; i < lto_symtab_encoder_size (encoder); i++) |
2f41ecf5 | 880 | { |
5e20cdc9 | 881 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
7de90a6c | 882 | if (varpool_node *vnode = dyn_cast <varpool_node *> (node)) |
2f41ecf5 | 883 | { |
6a6dac52 JH |
884 | if (!lto_symtab_encoder_encode_initializer_p (encoder, |
885 | vnode) | |
1e29e4d3 JH |
886 | && (((vnode->ctor_useable_for_folding_p () |
887 | && (!DECL_VIRTUAL_P (vnode->decl) | |
888 | || !flag_wpa | |
31db0fe0 | 889 | || flag_ltrans_devirtualize))))) |
7380e6ef JH |
890 | { |
891 | lto_set_symtab_encoder_encode_initializer (encoder, vnode); | |
3dafb85c | 892 | create_references (encoder, vnode); |
7380e6ef | 893 | } |
7380e6ef | 894 | } |
2f41ecf5 | 895 | } |
d7f09764 DN |
896 | |
897 | /* Go over all the nodes again to include callees that are not in | |
898 | SET. */ | |
7b99cca4 JH |
899 | for (lsei = lsei_start_function_in_partition (encoder); |
900 | !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei)) | |
d7f09764 | 901 | { |
224dbc07 | 902 | struct cgraph_node *node = lsei_cgraph_node (lsei); |
d7f09764 DN |
903 | for (edge = node->callees; edge; edge = edge->next_callee) |
904 | { | |
905 | struct cgraph_node *callee = edge->callee; | |
67348ccc | 906 | if (!lto_symtab_encoder_in_partition_p (encoder, callee)) |
d7f09764 DN |
907 | { |
908 | /* We should have moved all the inlines. */ | |
909 | gcc_assert (!callee->global.inlined_to); | |
91fbf0c7 | 910 | add_node_to (encoder, callee, false); |
d7f09764 DN |
911 | } |
912 | } | |
82d618d3 | 913 | /* Add all possible targets for late devirtualization. */ |
1e29e4d3 | 914 | if (flag_ltrans_devirtualize || !flag_wpa) |
82d618d3 JH |
915 | for (edge = node->indirect_calls; edge; edge = edge->next_callee) |
916 | if (edge->indirect_info->polymorphic) | |
917 | { | |
918 | unsigned int i; | |
919 | void *cache_token; | |
920 | bool final; | |
921 | vec <cgraph_node *>targets | |
922 | = possible_polymorphic_call_targets | |
923 | (edge, &final, &cache_token); | |
6e2830c3 | 924 | if (!reachable_call_targets.add (cache_token)) |
82d618d3 | 925 | { |
c3284718 | 926 | for (i = 0; i < targets.length (); i++) |
82d618d3 JH |
927 | { |
928 | struct cgraph_node *callee = targets[i]; | |
929 | ||
930 | /* Adding an external declarations into the unit serves | |
931 | no purpose and just increases its boundary. */ | |
67348ccc | 932 | if (callee->definition |
82d618d3 | 933 | && !lto_symtab_encoder_in_partition_p |
67348ccc | 934 | (encoder, callee)) |
82d618d3 JH |
935 | { |
936 | gcc_assert (!callee->global.inlined_to); | |
937 | add_node_to (encoder, callee, false); | |
938 | } | |
939 | } | |
940 | } | |
941 | } | |
d7f09764 | 942 | } |
4bd019b8 JH |
943 | /* Be sure to also insert alias targert and thunk callees. These needs |
944 | to stay to aid local calling conventions. */ | |
945 | for (i = 0; i < lto_symtab_encoder_size (encoder); i++) | |
946 | { | |
947 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); | |
948 | cgraph_node *cnode = dyn_cast <cgraph_node *> (node); | |
949 | ||
950 | if (node->alias && node->analyzed) | |
951 | create_references (encoder, node); | |
952 | if (cnode | |
479f99c9 | 953 | && cnode->thunk.thunk_p && !cnode->global.inlined_to) |
4bd019b8 | 954 | add_node_to (encoder, cnode->callees->callee, false); |
2b73ad1d JH |
955 | while (node->transparent_alias && node->analyzed) |
956 | { | |
957 | node = node->get_alias_target (); | |
958 | if (is_a <cgraph_node *> (node)) | |
959 | add_node_to (encoder, dyn_cast <cgraph_node *> (node), | |
960 | false); | |
961 | else | |
962 | lto_symtab_encoder_encode (encoder, node); | |
963 | } | |
4bd019b8 | 964 | } |
82d618d3 | 965 | lto_symtab_encoder_delete (in_encoder); |
82d618d3 | 966 | return encoder; |
f3380641 JH |
967 | } |
968 | ||
ab96cc5b | 969 | /* Output the part of the symtab in SET and VSET. */ |
f3380641 JH |
970 | |
971 | void | |
f27c1867 | 972 | output_symtab (void) |
f3380641 JH |
973 | { |
974 | struct cgraph_node *node; | |
975 | struct lto_simple_output_block *ob; | |
f3380641 | 976 | int i, n_nodes; |
7380e6ef | 977 | lto_symtab_encoder_t encoder; |
f3380641 | 978 | |
922f15c2 | 979 | if (flag_wpa) |
f27c1867 | 980 | output_cgraph_opt_summary (); |
922f15c2 | 981 | |
ab96cc5b | 982 | ob = lto_create_simple_output_block (LTO_section_symtab_nodes); |
f3380641 JH |
983 | |
984 | output_profile_summary (ob); | |
985 | ||
986 | /* An encoder for cgraph nodes should have been created by | |
987 | ipa_write_summaries_1. */ | |
7380e6ef JH |
988 | gcc_assert (ob->decl_state->symtab_node_encoder); |
989 | encoder = ob->decl_state->symtab_node_encoder; | |
f3380641 | 990 | |
a837268b JH |
991 | /* Write out the nodes. We must first output a node and then its clones, |
992 | otherwise at a time reading back the node there would be nothing to clone | |
993 | from. */ | |
7380e6ef | 994 | n_nodes = lto_symtab_encoder_size (encoder); |
d7f09764 DN |
995 | for (i = 0; i < n_nodes; i++) |
996 | { | |
5e20cdc9 | 997 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
7de90a6c | 998 | if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node)) |
5d59b5e1 | 999 | lto_output_node (ob, cnode, encoder); |
7380e6ef | 1000 | else |
d52f5295 | 1001 | lto_output_varpool_node (ob, dyn_cast<varpool_node *> (node), encoder); |
d7f09764 DN |
1002 | } |
1003 | ||
d7f09764 | 1004 | /* Go over the nodes in SET again to write edges. */ |
4bd019b8 | 1005 | for (int i = 0; i < lto_symtab_encoder_size (encoder); i++) |
d7f09764 | 1006 | { |
4bd019b8 JH |
1007 | node = dyn_cast <cgraph_node *> (lto_symtab_encoder_deref (encoder, i)); |
1008 | if (node | |
479f99c9 | 1009 | && ((node->thunk.thunk_p && !node->global.inlined_to) |
4bd019b8 JH |
1010 | || lto_symtab_encoder_in_partition_p (encoder, node))) |
1011 | { | |
1012 | output_outgoing_cgraph_edges (node->callees, ob, encoder); | |
1013 | output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder); | |
1014 | } | |
d7f09764 DN |
1015 | } |
1016 | ||
412288f1 | 1017 | streamer_write_uhwi_stream (ob->main_stream, 0); |
d7f09764 | 1018 | |
49f836ba JB |
1019 | lto_destroy_simple_output_block (ob); |
1020 | ||
b0d9e663 JH |
1021 | /* Emit toplevel asms. |
1022 | When doing WPA we must output every asm just once. Since we do not partition asm | |
1023 | nodes at all, output them to first output. This is kind of hack, but should work | |
1024 | well. */ | |
1025 | if (!asm_nodes_output) | |
a9cc4458 | 1026 | { |
b0d9e663 | 1027 | asm_nodes_output = true; |
49f836ba | 1028 | lto_output_toplevel_asms (); |
a9cc4458 RG |
1029 | } |
1030 | ||
f27c1867 | 1031 | output_refs (encoder); |
d7f09764 DN |
1032 | } |
1033 | ||
24d047a3 | 1034 | /* Return identifier encoded in IB as a plain string. */ |
aede2c10 JH |
1035 | |
1036 | static tree | |
24d047a3 | 1037 | read_identifier (struct lto_input_block *ib) |
aede2c10 JH |
1038 | { |
1039 | unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1); | |
24d047a3 JH |
1040 | tree id; |
1041 | ||
1042 | if (ib->data[ib->p + len]) | |
1043 | lto_section_overrun (ib); | |
1044 | if (!len) | |
1045 | { | |
1046 | ib->p++; | |
1047 | return NULL; | |
1048 | } | |
1049 | id = get_identifier (ib->data + ib->p); | |
1050 | ib->p += len + 1; | |
1051 | return id; | |
1052 | } | |
1053 | ||
f961457f | 1054 | /* Return string encoded in IB, NULL if string is empty. */ |
24d047a3 | 1055 | |
f961457f JH |
1056 | static const char * |
1057 | read_string (struct lto_input_block *ib) | |
24d047a3 JH |
1058 | { |
1059 | unsigned int len = strnlen (ib->data + ib->p, ib->len - ib->p - 1); | |
f961457f | 1060 | const char *str; |
aede2c10 JH |
1061 | |
1062 | if (ib->data[ib->p + len]) | |
1063 | lto_section_overrun (ib); | |
1064 | if (!len) | |
1065 | { | |
1066 | ib->p++; | |
1067 | return NULL; | |
1068 | } | |
f961457f | 1069 | str = ib->data + ib->p; |
aede2c10 | 1070 | ib->p += len + 1; |
f961457f | 1071 | return str; |
aede2c10 JH |
1072 | } |
1073 | ||
ec6fe917 IV |
1074 | /* Output function/variable tables that will allow libgomp to look up offload |
1075 | target code. | |
1076 | OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in | |
1077 | varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage | |
1078 | both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */ | |
1079 | ||
1080 | void | |
1081 | output_offload_tables (void) | |
1082 | { | |
1083 | if (vec_safe_is_empty (offload_funcs) && vec_safe_is_empty (offload_vars)) | |
1084 | return; | |
1085 | ||
1086 | struct lto_simple_output_block *ob | |
1087 | = lto_create_simple_output_block (LTO_section_offload_table); | |
1088 | ||
1089 | for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++) | |
1090 | { | |
1091 | streamer_write_enum (ob->main_stream, LTO_symtab_tags, | |
1092 | LTO_symtab_last_tag, LTO_symtab_unavail_node); | |
1093 | lto_output_fn_decl_index (ob->decl_state, ob->main_stream, | |
1094 | (*offload_funcs)[i]); | |
1095 | } | |
1096 | ||
1097 | for (unsigned i = 0; i < vec_safe_length (offload_vars); i++) | |
1098 | { | |
1099 | streamer_write_enum (ob->main_stream, LTO_symtab_tags, | |
1100 | LTO_symtab_last_tag, LTO_symtab_variable); | |
1101 | lto_output_var_decl_index (ob->decl_state, ob->main_stream, | |
1102 | (*offload_vars)[i]); | |
1103 | } | |
1104 | ||
1105 | streamer_write_uhwi_stream (ob->main_stream, 0); | |
1106 | lto_destroy_simple_output_block (ob); | |
1107 | ||
1108 | /* In WHOPR mode during the WPA stage the joint offload tables need to be | |
1109 | streamed to one partition only. That's why we free offload_funcs and | |
1110 | offload_vars after the first call of output_offload_tables. */ | |
1111 | if (flag_wpa) | |
1112 | { | |
1113 | vec_free (offload_funcs); | |
1114 | vec_free (offload_vars); | |
1115 | } | |
1116 | } | |
1117 | ||
d7f09764 DN |
1118 | /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS, |
1119 | STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize | |
1120 | NODE or to replace the values in it, for instance because the first | |
1121 | time we saw it, the function body was not available but now it | |
1122 | is. BP is a bitpack with all the bitflags for NODE read from the | |
1123 | stream. */ | |
1124 | ||
1125 | static void | |
1126 | input_overwrite_node (struct lto_file_decl_data *file_data, | |
1127 | struct cgraph_node *node, | |
7380e6ef | 1128 | enum LTO_symtab_tags tag, |
533c07c5 | 1129 | struct bitpack_d *bp) |
d7f09764 | 1130 | { |
67348ccc DM |
1131 | node->aux = (void *) tag; |
1132 | node->lto_file_data = file_data; | |
d7f09764 DN |
1133 | |
1134 | node->local.local = bp_unpack_value (bp, 1); | |
67348ccc | 1135 | node->externally_visible = bp_unpack_value (bp, 1); |
7861b648 | 1136 | node->no_reorder = bp_unpack_value (bp, 1); |
67348ccc | 1137 | node->definition = bp_unpack_value (bp, 1); |
124f1be6 | 1138 | node->local.versionable = bp_unpack_value (bp, 1); |
61e03ffc | 1139 | node->local.can_change_signature = bp_unpack_value (bp, 1); |
d7f09764 | 1140 | node->local.redefined_extern_inline = bp_unpack_value (bp, 1); |
67348ccc DM |
1141 | node->force_output = bp_unpack_value (bp, 1); |
1142 | node->forced_by_abi = bp_unpack_value (bp, 1); | |
1143 | node->unique_name = bp_unpack_value (bp, 1); | |
4a5798de | 1144 | node->body_removed = bp_unpack_value (bp, 1); |
e257a17c | 1145 | node->implicit_section = bp_unpack_value (bp, 1); |
67348ccc DM |
1146 | node->address_taken = bp_unpack_value (bp, 1); |
1147 | node->used_from_other_partition = bp_unpack_value (bp, 1); | |
d7f09764 | 1148 | node->lowered = bp_unpack_value (bp, 1); |
67348ccc DM |
1149 | node->analyzed = tag == LTO_symtab_analyzed_node; |
1150 | node->in_other_partition = bp_unpack_value (bp, 1); | |
1151 | if (node->in_other_partition | |
52b3b3c7 JH |
1152 | /* Avoid updating decl when we are seeing just inline clone. |
1153 | When inlining function that has functions already inlined into it, | |
1154 | we produce clones of inline clones. | |
1155 | ||
1156 | WPA partitioning might put each clone into different unit and | |
1157 | we might end up streaming inline clone from other partition | |
1158 | to support clone we are interested in. */ | |
1159 | && (!node->clone_of | |
67348ccc | 1160 | || node->clone_of->decl != node->decl)) |
1c7b11d2 | 1161 | { |
67348ccc DM |
1162 | DECL_EXTERNAL (node->decl) = 1; |
1163 | TREE_STATIC (node->decl) = 0; | |
1c7b11d2 | 1164 | } |
67348ccc | 1165 | node->alias = bp_unpack_value (bp, 1); |
71e54687 | 1166 | node->transparent_alias = bp_unpack_value (bp, 1); |
67348ccc | 1167 | node->weakref = bp_unpack_value (bp, 1); |
5fefcf92 | 1168 | node->frequency = (enum node_frequency)bp_unpack_value (bp, 2); |
844db5d0 JH |
1169 | node->only_called_at_startup = bp_unpack_value (bp, 1); |
1170 | node->only_called_at_exit = bp_unpack_value (bp, 1); | |
57ac2606 | 1171 | node->tm_clone = bp_unpack_value (bp, 1); |
1f26ac87 | 1172 | node->calls_comdat_local = bp_unpack_value (bp, 1); |
b84d4347 | 1173 | node->icf_merged = bp_unpack_value (bp, 1); |
8413ca87 | 1174 | node->nonfreeing_fn = bp_unpack_value (bp, 1); |
c47d0034 | 1175 | node->thunk.thunk_p = bp_unpack_value (bp, 1); |
a79b7ec5 | 1176 | node->parallelized_function = bp_unpack_value (bp, 1); |
67348ccc | 1177 | node->resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution, |
533c07c5 | 1178 | LDPR_NUM_KNOWN); |
41f669d8 | 1179 | node->split_part = bp_unpack_value (bp, 1); |
8fe91ca8 JH |
1180 | gcc_assert (flag_ltrans |
1181 | || (!node->in_other_partition | |
1182 | && !node->used_from_other_partition)); | |
d7f09764 DN |
1183 | } |
1184 | ||
40a7fe1e JH |
1185 | /* Return string alias is alias of. */ |
1186 | ||
1187 | static tree | |
1188 | get_alias_symbol (tree decl) | |
1189 | { | |
1190 | tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)); | |
40a7fe1e JH |
1191 | return get_identifier (TREE_STRING_POINTER |
1192 | (TREE_VALUE (TREE_VALUE (alias)))); | |
1193 | } | |
1194 | ||
b8698a0f | 1195 | /* Read a node from input_block IB. TAG is the node's tag just read. |
d7f09764 | 1196 | Return the node read or overwriten. */ |
b8698a0f | 1197 | |
d7f09764 DN |
1198 | static struct cgraph_node * |
1199 | input_node (struct lto_file_decl_data *file_data, | |
1200 | struct lto_input_block *ib, | |
7380e6ef | 1201 | enum LTO_symtab_tags tag, |
5e20cdc9 | 1202 | vec<symtab_node *> nodes) |
d7f09764 | 1203 | { |
315f8c0e | 1204 | gcc::pass_manager *passes = g->get_passes (); |
d7f09764 DN |
1205 | tree fn_decl; |
1206 | struct cgraph_node *node; | |
2465dcc2 | 1207 | struct bitpack_d bp; |
d7f09764 | 1208 | unsigned decl_index; |
b66887e4 | 1209 | int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND; |
91fbf0c7 | 1210 | int clone_ref; |
398f05da | 1211 | int order; |
7d57274b | 1212 | int i, count; |
aede2c10 | 1213 | tree group; |
f961457f | 1214 | const char *section; |
398f05da | 1215 | order = streamer_read_hwi (ib) + order_base; |
412288f1 | 1216 | clone_ref = streamer_read_hwi (ib); |
d7f09764 | 1217 | |
412288f1 | 1218 | decl_index = streamer_read_uhwi (ib); |
d7f09764 DN |
1219 | fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index); |
1220 | ||
91fbf0c7 JH |
1221 | if (clone_ref != LCC_NOT_FOUND) |
1222 | { | |
d52f5295 | 1223 | node = dyn_cast<cgraph_node *> (nodes[clone_ref])->create_clone (fn_decl, |
1bad9c18 | 1224 | profile_count::uninitialized (), false, |
d52f5295 | 1225 | vNULL, false, NULL, NULL); |
91fbf0c7 | 1226 | } |
d7f09764 | 1227 | else |
bbf9ad07 JH |
1228 | { |
1229 | /* Declaration of functions can be already merged with a declaration | |
1230 | from other input file. We keep cgraph unmerged until after streaming | |
1231 | of ipa passes is done. Alays forcingly create a fresh node. */ | |
3dafb85c | 1232 | node = symtab->create_empty (); |
67348ccc | 1233 | node->decl = fn_decl; |
aab778d3 L |
1234 | if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (fn_decl))) |
1235 | node->ifunc_resolver = 1; | |
d52f5295 | 1236 | node->register_symbol (); |
bbf9ad07 | 1237 | } |
d7f09764 | 1238 | |
67348ccc | 1239 | node->order = order; |
3dafb85c ML |
1240 | if (order >= symtab->order) |
1241 | symtab->order = order + 1; | |
398f05da | 1242 | |
3995f3a2 | 1243 | node->count = profile_count::stream_in (ib); |
412288f1 | 1244 | node->count_materialization_scale = streamer_read_hwi (ib); |
b8698a0f | 1245 | |
7d57274b | 1246 | count = streamer_read_hwi (ib); |
6e1aa848 | 1247 | node->ipa_transforms_to_apply = vNULL; |
7d57274b MJ |
1248 | for (i = 0; i < count; i++) |
1249 | { | |
6a5ac314 | 1250 | opt_pass *pass; |
7d57274b MJ |
1251 | int pid = streamer_read_hwi (ib); |
1252 | ||
315f8c0e DM |
1253 | gcc_assert (pid < passes->passes_by_id_size); |
1254 | pass = passes->passes_by_id[pid]; | |
6a5ac314 | 1255 | node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *) pass); |
7d57274b MJ |
1256 | } |
1257 | ||
7380e6ef | 1258 | if (tag == LTO_symtab_analyzed_node) |
412288f1 | 1259 | ref = streamer_read_hwi (ib); |
d7f09764 | 1260 | |
24d047a3 | 1261 | group = read_identifier (ib); |
aede2c10 JH |
1262 | if (group) |
1263 | ref2 = streamer_read_hwi (ib); | |
d7f09764 DN |
1264 | |
1265 | /* Make sure that we have not read this node before. Nodes that | |
1266 | have already been read will have their tag stored in the 'aux' | |
1267 | field. Since built-in functions can be referenced in multiple | |
1268 | functions, they are expected to be read more than once. */ | |
3d78e008 | 1269 | if (node->aux && !fndecl_built_in_p (node->decl)) |
d7f09764 | 1270 | internal_error ("bytecode stream: found multiple instances of cgraph " |
4325656f | 1271 | "node with uid %d", node->get_uid ()); |
d7f09764 | 1272 | |
86ce5d2f ML |
1273 | node->tp_first_run = streamer_read_uhwi (ib); |
1274 | ||
412288f1 | 1275 | bp = streamer_read_bitpack (ib); |
86ce5d2f | 1276 | |
533c07c5 | 1277 | input_overwrite_node (file_data, node, tag, &bp); |
d7f09764 | 1278 | |
d7f09764 | 1279 | /* Store a reference for now, and fix up later to be a pointer. */ |
d52f5295 | 1280 | node->global.inlined_to = (cgraph_node *) (intptr_t) ref; |
d7f09764 | 1281 | |
aede2c10 JH |
1282 | if (group) |
1283 | { | |
1284 | node->set_comdat_group (group); | |
1285 | /* Store a reference for now, and fix up later to be a pointer. */ | |
1286 | node->same_comdat_group = (symtab_node *) (intptr_t) ref2; | |
1287 | } | |
1288 | else | |
1289 | node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND; | |
f961457f | 1290 | section = read_string (ib); |
24d047a3 | 1291 | if (section) |
e257a17c | 1292 | node->set_section_for_node (section); |
b66887e4 | 1293 | |
c47d0034 JH |
1294 | if (node->thunk.thunk_p) |
1295 | { | |
412288f1 DN |
1296 | int type = streamer_read_uhwi (ib); |
1297 | HOST_WIDE_INT fixed_offset = streamer_read_uhwi (ib); | |
1298 | HOST_WIDE_INT virtual_value = streamer_read_uhwi (ib); | |
c47d0034 | 1299 | |
c47d0034 JH |
1300 | node->thunk.fixed_offset = fixed_offset; |
1301 | node->thunk.this_adjusting = (type & 2); | |
1302 | node->thunk.virtual_value = virtual_value; | |
1303 | node->thunk.virtual_offset_p = (type & 4); | |
d5e254e1 | 1304 | node->thunk.add_pointer_bounds_args = (type & 8); |
c47d0034 | 1305 | } |
67348ccc DM |
1306 | if (node->alias && !node->analyzed && node->weakref) |
1307 | node->alias_target = get_alias_symbol (node->decl); | |
634ab819 | 1308 | node->profile_id = streamer_read_hwi (ib); |
569b1784 | 1309 | if (DECL_STATIC_CONSTRUCTOR (node->decl)) |
1cff83e2 | 1310 | node->set_init_priority (streamer_read_hwi (ib)); |
569b1784 | 1311 | if (DECL_STATIC_DESTRUCTOR (node->decl)) |
1cff83e2 | 1312 | node->set_fini_priority (streamer_read_hwi (ib)); |
d5e254e1 | 1313 | |
d7f09764 DN |
1314 | return node; |
1315 | } | |
1316 | ||
2942c502 JH |
1317 | /* Read a node from input_block IB. TAG is the node's tag just read. |
1318 | Return the node read or overwriten. */ | |
1319 | ||
2c8326a5 | 1320 | static varpool_node * |
2942c502 JH |
1321 | input_varpool_node (struct lto_file_decl_data *file_data, |
1322 | struct lto_input_block *ib) | |
1323 | { | |
1324 | int decl_index; | |
1325 | tree var_decl; | |
2c8326a5 | 1326 | varpool_node *node; |
2465dcc2 | 1327 | struct bitpack_d bp; |
9f90e80a | 1328 | int ref = LCC_NOT_FOUND; |
398f05da | 1329 | int order; |
aede2c10 | 1330 | tree group; |
f961457f | 1331 | const char *section; |
2942c502 | 1332 | |
398f05da | 1333 | order = streamer_read_hwi (ib) + order_base; |
412288f1 | 1334 | decl_index = streamer_read_uhwi (ib); |
2942c502 | 1335 | var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index); |
bbf9ad07 JH |
1336 | |
1337 | /* Declaration of functions can be already merged with a declaration | |
1338 | from other input file. We keep cgraph unmerged until after streaming | |
1339 | of ipa passes is done. Alays forcingly create a fresh node. */ | |
9041d2e6 | 1340 | node = varpool_node::create_empty (); |
67348ccc | 1341 | node->decl = var_decl; |
d52f5295 | 1342 | node->register_symbol (); |
bbf9ad07 | 1343 | |
67348ccc | 1344 | node->order = order; |
3dafb85c ML |
1345 | if (order >= symtab->order) |
1346 | symtab->order = order + 1; | |
67348ccc | 1347 | node->lto_file_data = file_data; |
2942c502 | 1348 | |
412288f1 | 1349 | bp = streamer_read_bitpack (ib); |
67348ccc | 1350 | node->externally_visible = bp_unpack_value (&bp, 1); |
7861b648 | 1351 | node->no_reorder = bp_unpack_value (&bp, 1); |
67348ccc DM |
1352 | node->force_output = bp_unpack_value (&bp, 1); |
1353 | node->forced_by_abi = bp_unpack_value (&bp, 1); | |
1354 | node->unique_name = bp_unpack_value (&bp, 1); | |
4a5798de | 1355 | node->body_removed = bp_unpack_value (&bp, 1); |
e257a17c | 1356 | node->implicit_section = bp_unpack_value (&bp, 1); |
6de88c6a | 1357 | node->writeonly = bp_unpack_value (&bp, 1); |
67348ccc DM |
1358 | node->definition = bp_unpack_value (&bp, 1); |
1359 | node->alias = bp_unpack_value (&bp, 1); | |
71e54687 | 1360 | node->transparent_alias = bp_unpack_value (&bp, 1); |
67348ccc DM |
1361 | node->weakref = bp_unpack_value (&bp, 1); |
1362 | node->analyzed = bp_unpack_value (&bp, 1); | |
1363 | node->used_from_other_partition = bp_unpack_value (&bp, 1); | |
1364 | node->in_other_partition = bp_unpack_value (&bp, 1); | |
1365 | if (node->in_other_partition) | |
1c7b11d2 | 1366 | { |
67348ccc DM |
1367 | DECL_EXTERNAL (node->decl) = 1; |
1368 | TREE_STATIC (node->decl) = 0; | |
1c7b11d2 | 1369 | } |
67348ccc DM |
1370 | if (node->alias && !node->analyzed && node->weakref) |
1371 | node->alias_target = get_alias_symbol (node->decl); | |
56363ffd | 1372 | node->tls_model = (enum tls_model)bp_unpack_value (&bp, 3); |
eb6a09a7 | 1373 | node->used_by_single_function = (enum tls_model)bp_unpack_value (&bp, 1); |
ca280d38 | 1374 | node->dynamically_initialized = bp_unpack_value (&bp, 1); |
d5e254e1 | 1375 | node->need_bounds_init = bp_unpack_value (&bp, 1); |
24d047a3 | 1376 | group = read_identifier (ib); |
aede2c10 JH |
1377 | if (group) |
1378 | { | |
1379 | node->set_comdat_group (group); | |
1380 | ref = streamer_read_hwi (ib); | |
1381 | /* Store a reference for now, and fix up later to be a pointer. */ | |
1382 | node->same_comdat_group = (symtab_node *) (intptr_t) ref; | |
1383 | } | |
1384 | else | |
1385 | node->same_comdat_group = (symtab_node *) (intptr_t) LCC_NOT_FOUND; | |
f961457f | 1386 | section = read_string (ib); |
24d047a3 | 1387 | if (section) |
e257a17c | 1388 | node->set_section_for_node (section); |
67348ccc | 1389 | node->resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution, |
960bfb69 | 1390 | LDPR_NUM_KNOWN); |
8fe91ca8 JH |
1391 | gcc_assert (flag_ltrans |
1392 | || (!node->in_other_partition | |
1393 | && !node->used_from_other_partition)); | |
cd35bcf7 | 1394 | |
2942c502 JH |
1395 | return node; |
1396 | } | |
1397 | ||
369451ec JH |
1398 | /* Read a node from input_block IB. TAG is the node's tag just read. |
1399 | Return the node read or overwriten. */ | |
1400 | ||
1401 | static void | |
1402 | input_ref (struct lto_input_block *ib, | |
5e20cdc9 DM |
1403 | symtab_node *referring_node, |
1404 | vec<symtab_node *> nodes) | |
369451ec | 1405 | { |
5e20cdc9 | 1406 | symtab_node *node = NULL; |
2465dcc2 | 1407 | struct bitpack_d bp; |
369451ec | 1408 | enum ipa_ref_use use; |
042ae7d2 JH |
1409 | bool speculative; |
1410 | struct ipa_ref *ref; | |
369451ec | 1411 | |
412288f1 | 1412 | bp = streamer_read_bitpack (ib); |
d5e254e1 | 1413 | use = (enum ipa_ref_use) bp_unpack_value (&bp, 3); |
042ae7d2 | 1414 | speculative = (enum ipa_ref_use) bp_unpack_value (&bp, 1); |
9771b263 | 1415 | node = nodes[streamer_read_hwi (ib)]; |
3dafb85c | 1416 | ref = referring_node->create_reference (node, use); |
042ae7d2 | 1417 | ref->speculative = speculative; |
7de90a6c | 1418 | if (is_a <cgraph_node *> (referring_node)) |
042ae7d2 | 1419 | ref->lto_stmt_uid = streamer_read_hwi (ib); |
369451ec | 1420 | } |
d7f09764 | 1421 | |
e33c6cd6 MJ |
1422 | /* Read an edge from IB. NODES points to a vector of previously read nodes for |
1423 | decoding caller and callee of the edge to be read. If INDIRECT is true, the | |
1424 | edge being read is indirect (in the sense that it has | |
1425 | indirect_unknown_callee set). */ | |
d7f09764 DN |
1426 | |
1427 | static void | |
5e20cdc9 | 1428 | input_edge (struct lto_input_block *ib, vec<symtab_node *> nodes, |
e33c6cd6 | 1429 | bool indirect) |
d7f09764 DN |
1430 | { |
1431 | struct cgraph_node *caller, *callee; | |
1432 | struct cgraph_edge *edge; | |
1433 | unsigned int stmt_id; | |
3995f3a2 | 1434 | profile_count count; |
d7f09764 | 1435 | cgraph_inline_failed_t inline_failed; |
2465dcc2 | 1436 | struct bitpack_d bp; |
5f902d76 | 1437 | int ecf_flags = 0; |
d7f09764 | 1438 | |
d52f5295 | 1439 | caller = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]); |
67348ccc | 1440 | if (caller == NULL || caller->decl == NULL_TREE) |
d7f09764 DN |
1441 | internal_error ("bytecode stream: no caller found while reading edge"); |
1442 | ||
e33c6cd6 MJ |
1443 | if (!indirect) |
1444 | { | |
d52f5295 | 1445 | callee = dyn_cast<cgraph_node *> (nodes[streamer_read_hwi (ib)]); |
67348ccc | 1446 | if (callee == NULL || callee->decl == NULL_TREE) |
e33c6cd6 MJ |
1447 | internal_error ("bytecode stream: no callee found while reading edge"); |
1448 | } | |
1449 | else | |
1450 | callee = NULL; | |
d7f09764 | 1451 | |
3995f3a2 | 1452 | count = profile_count::stream_in (ib); |
d7f09764 | 1453 | |
412288f1 | 1454 | bp = streamer_read_bitpack (ib); |
84562394 | 1455 | inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_t, CIF_N_REASONS); |
533c07c5 | 1456 | stmt_id = bp_unpack_var_len_unsigned (&bp); |
d7f09764 | 1457 | |
e33c6cd6 | 1458 | if (indirect) |
1bad9c18 | 1459 | edge = caller->create_indirect_edge (NULL, 0, count); |
e33c6cd6 | 1460 | else |
1bad9c18 | 1461 | edge = caller->create_edge (callee, NULL, count); |
e33c6cd6 | 1462 | |
2465dcc2 | 1463 | edge->indirect_inlining_edge = bp_unpack_value (&bp, 1); |
042ae7d2 | 1464 | edge->speculative = bp_unpack_value (&bp, 1); |
d7f09764 DN |
1465 | edge->lto_stmt_uid = stmt_id; |
1466 | edge->inline_failed = inline_failed; | |
2465dcc2 RG |
1467 | edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1); |
1468 | edge->can_throw_external = bp_unpack_value (&bp, 1); | |
f9bb202b | 1469 | edge->in_polymorphic_cdtor = bp_unpack_value (&bp, 1); |
5f902d76 JH |
1470 | if (indirect) |
1471 | { | |
2465dcc2 | 1472 | if (bp_unpack_value (&bp, 1)) |
5f902d76 | 1473 | ecf_flags |= ECF_CONST; |
2465dcc2 | 1474 | if (bp_unpack_value (&bp, 1)) |
5f902d76 | 1475 | ecf_flags |= ECF_PURE; |
2465dcc2 | 1476 | if (bp_unpack_value (&bp, 1)) |
5f902d76 | 1477 | ecf_flags |= ECF_NORETURN; |
2465dcc2 | 1478 | if (bp_unpack_value (&bp, 1)) |
5f902d76 | 1479 | ecf_flags |= ECF_MALLOC; |
2465dcc2 | 1480 | if (bp_unpack_value (&bp, 1)) |
5f902d76 | 1481 | ecf_flags |= ECF_NOTHROW; |
2465dcc2 | 1482 | if (bp_unpack_value (&bp, 1)) |
5f902d76 JH |
1483 | ecf_flags |= ECF_RETURNS_TWICE; |
1484 | edge->indirect_info->ecf_flags = ecf_flags; | |
634ab819 JH |
1485 | edge->indirect_info->common_target_id = streamer_read_hwi (ib); |
1486 | if (edge->indirect_info->common_target_id) | |
1487 | edge->indirect_info->common_target_probability = streamer_read_hwi (ib); | |
5f902d76 | 1488 | } |
d7f09764 DN |
1489 | } |
1490 | ||
1491 | ||
1492 | /* Read a cgraph from IB using the info in FILE_DATA. */ | |
1493 | ||
5e20cdc9 | 1494 | static vec<symtab_node *> |
d7f09764 DN |
1495 | input_cgraph_1 (struct lto_file_decl_data *file_data, |
1496 | struct lto_input_block *ib) | |
1497 | { | |
7380e6ef | 1498 | enum LTO_symtab_tags tag; |
5e20cdc9 DM |
1499 | vec<symtab_node *> nodes = vNULL; |
1500 | symtab_node *node; | |
d7f09764 DN |
1501 | unsigned i; |
1502 | ||
7380e6ef | 1503 | tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag); |
3dafb85c | 1504 | order_base = symtab->order; |
d7f09764 DN |
1505 | while (tag) |
1506 | { | |
7380e6ef | 1507 | if (tag == LTO_symtab_edge) |
e33c6cd6 | 1508 | input_edge (ib, nodes, false); |
7380e6ef | 1509 | else if (tag == LTO_symtab_indirect_edge) |
e33c6cd6 | 1510 | input_edge (ib, nodes, true); |
7380e6ef JH |
1511 | else if (tag == LTO_symtab_variable) |
1512 | { | |
67348ccc | 1513 | node = input_varpool_node (file_data, ib); |
9771b263 | 1514 | nodes.safe_push (node); |
7380e6ef JH |
1515 | lto_symtab_encoder_encode (file_data->symtab_node_encoder, node); |
1516 | } | |
b8698a0f | 1517 | else |
d7f09764 | 1518 | { |
67348ccc DM |
1519 | node = input_node (file_data, ib, tag, nodes); |
1520 | if (node == NULL || node->decl == NULL_TREE) | |
d7f09764 | 1521 | internal_error ("bytecode stream: found empty cgraph node"); |
9771b263 | 1522 | nodes.safe_push (node); |
7380e6ef | 1523 | lto_symtab_encoder_encode (file_data->symtab_node_encoder, node); |
d7f09764 DN |
1524 | } |
1525 | ||
7380e6ef | 1526 | tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag); |
d7f09764 DN |
1527 | } |
1528 | ||
398f05da | 1529 | lto_input_toplevel_asms (file_data, order_base); |
a9cc4458 | 1530 | |
7380e6ef | 1531 | /* AUX pointers should be all non-zero for function nodes read from the stream. */ |
b2b29377 MM |
1532 | if (flag_checking) |
1533 | { | |
1534 | FOR_EACH_VEC_ELT (nodes, i, node) | |
1535 | gcc_assert (node->aux || !is_a <cgraph_node *> (node)); | |
1536 | } | |
9771b263 | 1537 | FOR_EACH_VEC_ELT (nodes, i, node) |
d7f09764 | 1538 | { |
7380e6ef | 1539 | int ref; |
7de90a6c | 1540 | if (cgraph_node *cnode = dyn_cast <cgraph_node *> (node)) |
7380e6ef | 1541 | { |
5d59b5e1 | 1542 | ref = (int) (intptr_t) cnode->global.inlined_to; |
7380e6ef JH |
1543 | |
1544 | /* We share declaration of builtins, so we may read same node twice. */ | |
67348ccc | 1545 | if (!node->aux) |
7380e6ef | 1546 | continue; |
67348ccc | 1547 | node->aux = NULL; |
7380e6ef JH |
1548 | |
1549 | /* Fixup inlined_to from reference to pointer. */ | |
1550 | if (ref != LCC_NOT_FOUND) | |
d52f5295 ML |
1551 | dyn_cast<cgraph_node *> (node)->global.inlined_to |
1552 | = dyn_cast<cgraph_node *> (nodes[ref]); | |
7380e6ef | 1553 | else |
5d59b5e1 | 1554 | cnode->global.inlined_to = NULL; |
7380e6ef | 1555 | } |
b66887e4 | 1556 | |
67348ccc | 1557 | ref = (int) (intptr_t) node->same_comdat_group; |
b66887e4 JJ |
1558 | |
1559 | /* Fixup same_comdat_group from reference to pointer. */ | |
1560 | if (ref != LCC_NOT_FOUND) | |
67348ccc | 1561 | node->same_comdat_group = nodes[ref]; |
b66887e4 | 1562 | else |
67348ccc | 1563 | node->same_comdat_group = NULL; |
d7f09764 | 1564 | } |
9771b263 | 1565 | FOR_EACH_VEC_ELT (nodes, i, node) |
7de90a6c | 1566 | node->aux = is_a <cgraph_node *> (node) ? (void *)1 : NULL; |
2f41ecf5 | 1567 | return nodes; |
d7f09764 DN |
1568 | } |
1569 | ||
369451ec JH |
1570 | /* Input ipa_refs. */ |
1571 | ||
1572 | static void | |
1573 | input_refs (struct lto_input_block *ib, | |
5e20cdc9 | 1574 | vec<symtab_node *> nodes) |
369451ec JH |
1575 | { |
1576 | int count; | |
1577 | int idx; | |
1578 | while (true) | |
1579 | { | |
5e20cdc9 | 1580 | symtab_node *node; |
412288f1 | 1581 | count = streamer_read_uhwi (ib); |
369451ec JH |
1582 | if (!count) |
1583 | break; | |
412288f1 | 1584 | idx = streamer_read_uhwi (ib); |
9771b263 | 1585 | node = nodes[idx]; |
369451ec JH |
1586 | while (count) |
1587 | { | |
f27c1867 | 1588 | input_ref (ib, node, nodes); |
369451ec JH |
1589 | count--; |
1590 | } | |
1591 | } | |
1592 | } | |
1593 | ||
2f41ecf5 | 1594 | |
7f3577f5 | 1595 | static gcov_summary lto_gcov_summary; |
0bc1b77f JH |
1596 | |
1597 | /* Input profile_info from IB. */ | |
1598 | static void | |
db0bf14f JH |
1599 | input_profile_summary (struct lto_input_block *ib, |
1600 | struct lto_file_decl_data *file_data) | |
0bc1b77f | 1601 | { |
2730ada7 TJ |
1602 | unsigned h_ix; |
1603 | struct bitpack_d bp; | |
412288f1 | 1604 | unsigned int runs = streamer_read_uhwi (ib); |
0bc1b77f JH |
1605 | if (runs) |
1606 | { | |
db0bf14f | 1607 | file_data->profile_info.runs = runs; |
0208f7da JH |
1608 | file_data->profile_info.sum_max = streamer_read_gcov_count (ib); |
1609 | file_data->profile_info.sum_all = streamer_read_gcov_count (ib); | |
2730ada7 TJ |
1610 | |
1611 | memset (file_data->profile_info.histogram, 0, | |
1612 | sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE); | |
1613 | /* Input the bitpack of non-zero histogram indices. */ | |
1614 | bp = streamer_read_bitpack (ib); | |
1615 | /* Read in and unpack the full bitpack, flagging non-zero | |
1616 | histogram entries by setting the num_counters non-zero. */ | |
1617 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
1618 | { | |
1619 | file_data->profile_info.histogram[h_ix].num_counters | |
1620 | = bp_unpack_value (&bp, 1); | |
1621 | } | |
1622 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
1623 | { | |
1624 | if (!file_data->profile_info.histogram[h_ix].num_counters) | |
1625 | continue; | |
1626 | ||
1627 | file_data->profile_info.histogram[h_ix].num_counters | |
0208f7da | 1628 | = streamer_read_gcov_count (ib); |
2730ada7 | 1629 | file_data->profile_info.histogram[h_ix].min_value |
0208f7da | 1630 | = streamer_read_gcov_count (ib); |
2730ada7 | 1631 | file_data->profile_info.histogram[h_ix].cum_value |
0208f7da | 1632 | = streamer_read_gcov_count (ib); |
2730ada7 | 1633 | } |
0208f7da JH |
1634 | /* IPA-profile computes hot bb threshold based on cumulated |
1635 | whole program profile. We need to stream it down to ltrans. */ | |
1636 | if (flag_ltrans) | |
1637 | set_hot_bb_threshold (streamer_read_gcov_count (ib)); | |
0bc1b77f JH |
1638 | } |
1639 | ||
1640 | } | |
d7f09764 | 1641 | |
db0bf14f JH |
1642 | /* Rescale profile summaries to the same number of runs in the whole unit. */ |
1643 | ||
1644 | static void | |
1645 | merge_profile_summaries (struct lto_file_decl_data **file_data_vec) | |
1646 | { | |
1647 | struct lto_file_decl_data *file_data; | |
2730ada7 | 1648 | unsigned int j, h_ix; |
db0bf14f JH |
1649 | gcov_unsigned_t max_runs = 0; |
1650 | struct cgraph_node *node; | |
1651 | struct cgraph_edge *edge; | |
2730ada7 | 1652 | gcov_type saved_sum_all = 0; |
7f3577f5 | 1653 | gcov_summary *saved_profile_info = 0; |
2730ada7 | 1654 | int saved_scale = 0; |
db0bf14f JH |
1655 | |
1656 | /* Find unit with maximal number of runs. If we ever get serious about | |
1657 | roundoff errors, we might also consider computing smallest common | |
1658 | multiply. */ | |
1659 | for (j = 0; (file_data = file_data_vec[j]) != NULL; j++) | |
1660 | if (max_runs < file_data->profile_info.runs) | |
1661 | max_runs = file_data->profile_info.runs; | |
1662 | ||
1663 | if (!max_runs) | |
1664 | return; | |
1665 | ||
1666 | /* Simple overflow check. We probably don't need to support that many train | |
1667 | runs. Such a large value probably imply data corruption anyway. */ | |
1668 | if (max_runs > INT_MAX / REG_BR_PROB_BASE) | |
1669 | { | |
1670 | sorry ("At most %i profile runs is supported. Perhaps corrupted profile?", | |
1671 | INT_MAX / REG_BR_PROB_BASE); | |
1672 | return; | |
1673 | } | |
1674 | ||
1675 | profile_info = <o_gcov_summary; | |
1676 | lto_gcov_summary.runs = max_runs; | |
1677 | lto_gcov_summary.sum_max = 0; | |
2730ada7 TJ |
1678 | memset (lto_gcov_summary.histogram, 0, |
1679 | sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE); | |
db0bf14f JH |
1680 | |
1681 | /* Rescale all units to the maximal number of runs. | |
1682 | sum_max can not be easily merged, as we have no idea what files come from | |
1683 | the same run. We do not use the info anyway, so leave it 0. */ | |
1684 | for (j = 0; (file_data = file_data_vec[j]) != NULL; j++) | |
1685 | if (file_data->profile_info.runs) | |
1686 | { | |
8ddb5a29 TJ |
1687 | int scale = GCOV_COMPUTE_SCALE (max_runs, |
1688 | file_data->profile_info.runs); | |
1689 | lto_gcov_summary.sum_max | |
1690 | = MAX (lto_gcov_summary.sum_max, | |
f41f80f9 | 1691 | apply_scale (file_data->profile_info.sum_max, scale)); |
8ddb5a29 TJ |
1692 | lto_gcov_summary.sum_all |
1693 | = MAX (lto_gcov_summary.sum_all, | |
f41f80f9 | 1694 | apply_scale (file_data->profile_info.sum_all, scale)); |
2730ada7 TJ |
1695 | /* Save a pointer to the profile_info with the largest |
1696 | scaled sum_all and the scale for use in merging the | |
1697 | histogram. */ | |
bde8c962 TJ |
1698 | if (!saved_profile_info |
1699 | || lto_gcov_summary.sum_all > saved_sum_all) | |
2730ada7 TJ |
1700 | { |
1701 | saved_profile_info = &file_data->profile_info; | |
1702 | saved_sum_all = lto_gcov_summary.sum_all; | |
1703 | saved_scale = scale; | |
1704 | } | |
db0bf14f JH |
1705 | } |
1706 | ||
2730ada7 TJ |
1707 | gcc_assert (saved_profile_info); |
1708 | ||
1709 | /* Scale up the histogram from the profile that had the largest | |
1710 | scaled sum_all above. */ | |
1711 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
1712 | { | |
1713 | /* Scale up the min value as we did the corresponding sum_all | |
1714 | above. Use that to find the new histogram index. */ | |
8ddb5a29 | 1715 | gcov_type scaled_min |
f41f80f9 TJ |
1716 | = apply_scale (saved_profile_info->histogram[h_ix].min_value, |
1717 | saved_scale); | |
bde8c962 TJ |
1718 | /* The new index may be shared with another scaled histogram entry, |
1719 | so we need to account for a non-zero histogram entry at new_ix. */ | |
2730ada7 | 1720 | unsigned new_ix = gcov_histo_index (scaled_min); |
bde8c962 | 1721 | lto_gcov_summary.histogram[new_ix].min_value |
ebd3e642 TJ |
1722 | = (lto_gcov_summary.histogram[new_ix].num_counters |
1723 | ? MIN (lto_gcov_summary.histogram[new_ix].min_value, scaled_min) | |
1724 | : scaled_min); | |
2730ada7 TJ |
1725 | /* Some of the scaled counter values would ostensibly need to be placed |
1726 | into different (larger) histogram buckets, but we keep things simple | |
1727 | here and place the scaled cumulative counter value in the bucket | |
1728 | corresponding to the scaled minimum counter value. */ | |
1729 | lto_gcov_summary.histogram[new_ix].cum_value | |
f41f80f9 TJ |
1730 | += apply_scale (saved_profile_info->histogram[h_ix].cum_value, |
1731 | saved_scale); | |
2730ada7 | 1732 | lto_gcov_summary.histogram[new_ix].num_counters |
bde8c962 | 1733 | += saved_profile_info->histogram[h_ix].num_counters; |
2730ada7 TJ |
1734 | } |
1735 | ||
db0bf14f JH |
1736 | /* Watch roundoff errors. */ |
1737 | if (lto_gcov_summary.sum_max < max_runs) | |
1738 | lto_gcov_summary.sum_max = max_runs; | |
1739 | ||
1740 | /* If merging already happent at WPA time, we are done. */ | |
1741 | if (flag_ltrans) | |
1742 | return; | |
1743 | ||
1744 | /* Now compute count_materialization_scale of each node. | |
1745 | During LTRANS we already have values of count_materialization_scale | |
1746 | computed, so just update them. */ | |
65c70e6b | 1747 | FOR_EACH_FUNCTION (node) |
67348ccc DM |
1748 | if (node->lto_file_data |
1749 | && node->lto_file_data->profile_info.runs) | |
db0bf14f JH |
1750 | { |
1751 | int scale; | |
40e584a1 | 1752 | |
2730ada7 | 1753 | scale = RDIV (node->count_materialization_scale * max_runs, |
67348ccc | 1754 | node->lto_file_data->profile_info.runs); |
db0bf14f JH |
1755 | node->count_materialization_scale = scale; |
1756 | if (scale < 0) | |
40fecdd6 | 1757 | fatal_error (input_location, "Profile information in %s corrupted", |
db0bf14f JH |
1758 | file_data->file_name); |
1759 | ||
1760 | if (scale == REG_BR_PROB_BASE) | |
1761 | continue; | |
1762 | for (edge = node->callees; edge; edge = edge->next_callee) | |
1bad9c18 JH |
1763 | if (edge->count.ipa ().nonzero_p ()) |
1764 | edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE); | |
1765 | for (edge = node->indirect_calls; edge; edge = edge->next_callee) | |
1766 | if (edge->count.ipa ().nonzero_p ()) | |
1767 | edge->count = edge->count.apply_scale (scale, REG_BR_PROB_BASE); | |
1768 | if (node->count.ipa ().nonzero_p ()) | |
1769 | node->count = node->count.apply_scale (scale, REG_BR_PROB_BASE); | |
db0bf14f JH |
1770 | } |
1771 | } | |
1772 | ||
ab96cc5b | 1773 | /* Input and merge the symtab from each of the .o files passed to |
d7f09764 DN |
1774 | lto1. */ |
1775 | ||
1776 | void | |
ab96cc5b | 1777 | input_symtab (void) |
d7f09764 DN |
1778 | { |
1779 | struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); | |
1780 | struct lto_file_decl_data *file_data; | |
1781 | unsigned int j = 0; | |
1782 | struct cgraph_node *node; | |
1783 | ||
1784 | while ((file_data = file_data_vec[j++])) | |
1785 | { | |
1786 | const char *data; | |
1787 | size_t len; | |
1788 | struct lto_input_block *ib; | |
5e20cdc9 | 1789 | vec<symtab_node *> nodes; |
d7f09764 | 1790 | |
ab96cc5b | 1791 | ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes, |
d7f09764 | 1792 | &data, &len); |
f1e92a43 | 1793 | if (!ib) |
40fecdd6 JM |
1794 | fatal_error (input_location, |
1795 | "cannot find LTO cgraph in %s", file_data->file_name); | |
db0bf14f | 1796 | input_profile_summary (ib, file_data); |
e75f8f79 | 1797 | file_data->symtab_node_encoder = lto_symtab_encoder_new (true); |
2f41ecf5 | 1798 | nodes = input_cgraph_1 (file_data, ib); |
ab96cc5b | 1799 | lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes, |
d7f09764 | 1800 | ib, data, len); |
b8698a0f | 1801 | |
369451ec JH |
1802 | ib = lto_create_simple_input_block (file_data, LTO_section_refs, |
1803 | &data, &len); | |
f1e92a43 | 1804 | if (!ib) |
40fecdd6 | 1805 | fatal_error (input_location, "cannot find LTO section refs in %s", |
c3284718 | 1806 | file_data->file_name); |
7380e6ef | 1807 | input_refs (ib, nodes); |
369451ec JH |
1808 | lto_destroy_simple_input_block (file_data, LTO_section_refs, |
1809 | ib, data, len); | |
922f15c2 JH |
1810 | if (flag_ltrans) |
1811 | input_cgraph_opt_summary (nodes); | |
9771b263 | 1812 | nodes.release (); |
b8698a0f | 1813 | } |
beb628e1 | 1814 | |
db0bf14f | 1815 | merge_profile_summaries (file_data_vec); |
10c9ea62 ML |
1816 | |
1817 | if (!flag_auto_profile) | |
1818 | get_working_sets (); | |
2730ada7 | 1819 | |
d7f09764 DN |
1820 | |
1821 | /* Clear out the aux field that was used to store enough state to | |
1822 | tell which nodes should be overwritten. */ | |
65c70e6b | 1823 | FOR_EACH_FUNCTION (node) |
d7f09764 DN |
1824 | { |
1825 | /* Some nodes may have been created by cgraph_node. This | |
1826 | happens when the callgraph contains nested functions. If the | |
1827 | node for the parent function was never emitted to the gimple | |
1828 | file, cgraph_node will create a node for it when setting the | |
1829 | context of the nested function. */ | |
67348ccc DM |
1830 | if (node->lto_file_data) |
1831 | node->aux = NULL; | |
d7f09764 DN |
1832 | } |
1833 | } | |
922f15c2 | 1834 | |
ec6fe917 IV |
1835 | /* Input function/variable tables that will allow libgomp to look up offload |
1836 | target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */ | |
1837 | ||
1838 | void | |
ed5d948d | 1839 | input_offload_tables (bool do_force_output) |
ec6fe917 IV |
1840 | { |
1841 | struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); | |
1842 | struct lto_file_decl_data *file_data; | |
1843 | unsigned int j = 0; | |
1844 | ||
1845 | while ((file_data = file_data_vec[j++])) | |
1846 | { | |
1847 | const char *data; | |
1848 | size_t len; | |
1849 | struct lto_input_block *ib | |
1850 | = lto_create_simple_input_block (file_data, LTO_section_offload_table, | |
1851 | &data, &len); | |
1852 | if (!ib) | |
1853 | continue; | |
1854 | ||
1855 | enum LTO_symtab_tags tag | |
1856 | = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag); | |
1857 | while (tag) | |
1858 | { | |
1859 | if (tag == LTO_symtab_unavail_node) | |
1860 | { | |
1861 | int decl_index = streamer_read_uhwi (ib); | |
1862 | tree fn_decl | |
1863 | = lto_file_decl_data_get_fn_decl (file_data, decl_index); | |
1864 | vec_safe_push (offload_funcs, fn_decl); | |
e6d6ec9e TV |
1865 | |
1866 | /* Prevent IPA from removing fn_decl as unreachable, since there | |
1867 | may be no refs from the parent function to child_fn in offload | |
1868 | LTO mode. */ | |
ed5d948d TV |
1869 | if (do_force_output) |
1870 | cgraph_node::get (fn_decl)->mark_force_output (); | |
ec6fe917 IV |
1871 | } |
1872 | else if (tag == LTO_symtab_variable) | |
1873 | { | |
1874 | int decl_index = streamer_read_uhwi (ib); | |
1875 | tree var_decl | |
1876 | = lto_file_decl_data_get_var_decl (file_data, decl_index); | |
1877 | vec_safe_push (offload_vars, var_decl); | |
e6d6ec9e TV |
1878 | |
1879 | /* Prevent IPA from removing var_decl as unused, since there | |
1880 | may be no refs to var_decl in offload LTO mode. */ | |
ed5d948d TV |
1881 | if (do_force_output) |
1882 | varpool_node::get (var_decl)->force_output = 1; | |
ec6fe917 IV |
1883 | } |
1884 | else | |
40fecdd6 JM |
1885 | fatal_error (input_location, |
1886 | "invalid offload table in %s", file_data->file_name); | |
ec6fe917 IV |
1887 | |
1888 | tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag); | |
1889 | } | |
1890 | ||
1891 | lto_destroy_simple_input_block (file_data, LTO_section_offload_table, | |
1892 | ib, data, len); | |
1893 | } | |
1894 | } | |
1895 | ||
922f15c2 JH |
1896 | /* True when we need optimization summary for NODE. */ |
1897 | ||
1898 | static int | |
f27c1867 | 1899 | output_cgraph_opt_summary_p (struct cgraph_node *node) |
922f15c2 | 1900 | { |
a50e9b2f | 1901 | return ((node->clone_of || node->former_clone_of) |
644e637f MJ |
1902 | && (node->clone.tree_map |
1903 | || node->clone.args_to_skip | |
1904 | || node->clone.combined_args_to_skip)); | |
922f15c2 JH |
1905 | } |
1906 | ||
ce47fda3 MJ |
1907 | /* Output optimization summary for EDGE to OB. */ |
1908 | static void | |
81fa35bd MJ |
1909 | output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED, |
1910 | struct cgraph_edge *edge ATTRIBUTE_UNUSED) | |
ce47fda3 | 1911 | { |
ce47fda3 MJ |
1912 | } |
1913 | ||
922f15c2 JH |
1914 | /* Output optimization summary for NODE to OB. */ |
1915 | ||
1916 | static void | |
1917 | output_node_opt_summary (struct output_block *ob, | |
644e637f | 1918 | struct cgraph_node *node, |
f27c1867 | 1919 | lto_symtab_encoder_t encoder) |
922f15c2 JH |
1920 | { |
1921 | unsigned int index; | |
1922 | bitmap_iterator bi; | |
1923 | struct ipa_replace_map *map; | |
2465dcc2 | 1924 | struct bitpack_d bp; |
922f15c2 | 1925 | int i; |
ce47fda3 | 1926 | struct cgraph_edge *e; |
922f15c2 | 1927 | |
26740835 JH |
1928 | if (node->clone.args_to_skip) |
1929 | { | |
412288f1 | 1930 | streamer_write_uhwi (ob, bitmap_count_bits (node->clone.args_to_skip)); |
26740835 | 1931 | EXECUTE_IF_SET_IN_BITMAP (node->clone.args_to_skip, 0, index, bi) |
412288f1 | 1932 | streamer_write_uhwi (ob, index); |
26740835 JH |
1933 | } |
1934 | else | |
412288f1 | 1935 | streamer_write_uhwi (ob, 0); |
26740835 JH |
1936 | if (node->clone.combined_args_to_skip) |
1937 | { | |
412288f1 | 1938 | streamer_write_uhwi (ob, bitmap_count_bits (node->clone.combined_args_to_skip)); |
26740835 | 1939 | EXECUTE_IF_SET_IN_BITMAP (node->clone.combined_args_to_skip, 0, index, bi) |
412288f1 | 1940 | streamer_write_uhwi (ob, index); |
26740835 JH |
1941 | } |
1942 | else | |
412288f1 | 1943 | streamer_write_uhwi (ob, 0); |
9771b263 DN |
1944 | streamer_write_uhwi (ob, vec_safe_length (node->clone.tree_map)); |
1945 | FOR_EACH_VEC_SAFE_ELT (node->clone.tree_map, i, map) | |
922f15c2 | 1946 | { |
922f15c2 JH |
1947 | /* At the moment we assume all old trees to be PARM_DECLs, because we have no |
1948 | mechanism to store function local declarations into summaries. */ | |
49bde175 JH |
1949 | gcc_assert (!map->old_tree); |
1950 | streamer_write_uhwi (ob, map->parm_num); | |
2f13f2de | 1951 | gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION); |
b9393656 | 1952 | stream_write_tree (ob, map->new_tree, true); |
2465dcc2 RG |
1953 | bp = bitpack_create (ob->main_stream); |
1954 | bp_pack_value (&bp, map->replace_p, 1); | |
1955 | bp_pack_value (&bp, map->ref_p, 1); | |
412288f1 | 1956 | streamer_write_bitpack (&bp); |
922f15c2 | 1957 | } |
644e637f | 1958 | |
67348ccc | 1959 | if (lto_symtab_encoder_in_partition_p (encoder, node)) |
644e637f MJ |
1960 | { |
1961 | for (e = node->callees; e; e = e->next_callee) | |
1962 | output_edge_opt_summary (ob, e); | |
1963 | for (e = node->indirect_calls; e; e = e->next_callee) | |
1964 | output_edge_opt_summary (ob, e); | |
1965 | } | |
922f15c2 JH |
1966 | } |
1967 | ||
1968 | /* Output optimization summaries stored in callgraph. | |
1969 | At the moment it is the clone info structure. */ | |
1970 | ||
1971 | static void | |
f27c1867 | 1972 | output_cgraph_opt_summary (void) |
922f15c2 | 1973 | { |
922f15c2 | 1974 | int i, n_nodes; |
7380e6ef | 1975 | lto_symtab_encoder_t encoder; |
922f15c2 JH |
1976 | struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum); |
1977 | unsigned count = 0; | |
1978 | ||
0b83e688 | 1979 | ob->symbol = NULL; |
7380e6ef JH |
1980 | encoder = ob->decl_state->symtab_node_encoder; |
1981 | n_nodes = lto_symtab_encoder_size (encoder); | |
922f15c2 | 1982 | for (i = 0; i < n_nodes; i++) |
5d59b5e1 | 1983 | { |
5e20cdc9 | 1984 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
7de90a6c | 1985 | cgraph_node *cnode = dyn_cast <cgraph_node *> (node); |
5d59b5e1 LC |
1986 | if (cnode && output_cgraph_opt_summary_p (cnode)) |
1987 | count++; | |
1988 | } | |
412288f1 | 1989 | streamer_write_uhwi (ob, count); |
922f15c2 JH |
1990 | for (i = 0; i < n_nodes; i++) |
1991 | { | |
5e20cdc9 | 1992 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
7de90a6c | 1993 | cgraph_node *cnode = dyn_cast <cgraph_node *> (node); |
5d59b5e1 | 1994 | if (cnode && output_cgraph_opt_summary_p (cnode)) |
922f15c2 | 1995 | { |
412288f1 | 1996 | streamer_write_uhwi (ob, i); |
5d59b5e1 | 1997 | output_node_opt_summary (ob, cnode, encoder); |
922f15c2 JH |
1998 | } |
1999 | } | |
2000 | produce_asm (ob, NULL); | |
2001 | destroy_output_block (ob); | |
2002 | } | |
2003 | ||
ce47fda3 MJ |
2004 | /* Input optimisation summary of EDGE. */ |
2005 | ||
2006 | static void | |
81fa35bd MJ |
2007 | input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED, |
2008 | struct lto_input_block *ib_main ATTRIBUTE_UNUSED) | |
ce47fda3 | 2009 | { |
ce47fda3 MJ |
2010 | } |
2011 | ||
2012 | /* Input optimisation summary of NODE. */ | |
922f15c2 JH |
2013 | |
2014 | static void | |
2015 | input_node_opt_summary (struct cgraph_node *node, | |
2016 | struct lto_input_block *ib_main, | |
2017 | struct data_in *data_in) | |
2018 | { | |
2019 | int i; | |
2020 | int count; | |
2021 | int bit; | |
2465dcc2 | 2022 | struct bitpack_d bp; |
ce47fda3 | 2023 | struct cgraph_edge *e; |
922f15c2 | 2024 | |
412288f1 | 2025 | count = streamer_read_uhwi (ib_main); |
922f15c2 JH |
2026 | if (count) |
2027 | node->clone.args_to_skip = BITMAP_GGC_ALLOC (); | |
2028 | for (i = 0; i < count; i++) | |
2029 | { | |
412288f1 | 2030 | bit = streamer_read_uhwi (ib_main); |
922f15c2 JH |
2031 | bitmap_set_bit (node->clone.args_to_skip, bit); |
2032 | } | |
412288f1 | 2033 | count = streamer_read_uhwi (ib_main); |
922f15c2 JH |
2034 | if (count) |
2035 | node->clone.combined_args_to_skip = BITMAP_GGC_ALLOC (); | |
2036 | for (i = 0; i < count; i++) | |
2037 | { | |
412288f1 | 2038 | bit = streamer_read_uhwi (ib_main); |
922f15c2 JH |
2039 | bitmap_set_bit (node->clone.combined_args_to_skip, bit); |
2040 | } | |
412288f1 | 2041 | count = streamer_read_uhwi (ib_main); |
922f15c2 JH |
2042 | for (i = 0; i < count; i++) |
2043 | { | |
766090c2 | 2044 | struct ipa_replace_map *map = ggc_alloc<ipa_replace_map> (); |
922f15c2 | 2045 | |
9771b263 | 2046 | vec_safe_push (node->clone.tree_map, map); |
412288f1 | 2047 | map->parm_num = streamer_read_uhwi (ib_main); |
922f15c2 | 2048 | map->old_tree = NULL; |
b9393656 | 2049 | map->new_tree = stream_read_tree (ib_main, data_in); |
412288f1 | 2050 | bp = streamer_read_bitpack (ib_main); |
2465dcc2 RG |
2051 | map->replace_p = bp_unpack_value (&bp, 1); |
2052 | map->ref_p = bp_unpack_value (&bp, 1); | |
922f15c2 | 2053 | } |
ce47fda3 MJ |
2054 | for (e = node->callees; e; e = e->next_callee) |
2055 | input_edge_opt_summary (e, ib_main); | |
2056 | for (e = node->indirect_calls; e; e = e->next_callee) | |
2057 | input_edge_opt_summary (e, ib_main); | |
922f15c2 JH |
2058 | } |
2059 | ||
2060 | /* Read section in file FILE_DATA of length LEN with data DATA. */ | |
2061 | ||
2062 | static void | |
2063 | input_cgraph_opt_section (struct lto_file_decl_data *file_data, | |
9771b263 | 2064 | const char *data, size_t len, |
5e20cdc9 | 2065 | vec<symtab_node *> nodes) |
922f15c2 JH |
2066 | { |
2067 | const struct lto_function_header *header = | |
2068 | (const struct lto_function_header *) data; | |
4ad9a9de EB |
2069 | const int cfg_offset = sizeof (struct lto_function_header); |
2070 | const int main_offset = cfg_offset + header->cfg_size; | |
2071 | const int string_offset = main_offset + header->main_size; | |
922f15c2 | 2072 | struct data_in *data_in; |
922f15c2 JH |
2073 | unsigned int i; |
2074 | unsigned int count; | |
2075 | ||
207c68cd | 2076 | lto_input_block ib_main ((const char *) data + main_offset, |
db847fa8 | 2077 | header->main_size, file_data->mode_table); |
922f15c2 JH |
2078 | |
2079 | data_in = | |
2080 | lto_data_in_create (file_data, (const char *) data + string_offset, | |
6e1aa848 | 2081 | header->string_size, vNULL); |
412288f1 | 2082 | count = streamer_read_uhwi (&ib_main); |
922f15c2 JH |
2083 | |
2084 | for (i = 0; i < count; i++) | |
2085 | { | |
412288f1 | 2086 | int ref = streamer_read_uhwi (&ib_main); |
d52f5295 | 2087 | input_node_opt_summary (dyn_cast<cgraph_node *> (nodes[ref]), |
922f15c2 JH |
2088 | &ib_main, data_in); |
2089 | } | |
839d549b | 2090 | lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data, |
922f15c2 JH |
2091 | len); |
2092 | lto_data_in_delete (data_in); | |
2093 | } | |
2094 | ||
2095 | /* Input optimization summary of cgraph. */ | |
2096 | ||
2097 | static void | |
5e20cdc9 | 2098 | input_cgraph_opt_summary (vec<symtab_node *> nodes) |
922f15c2 JH |
2099 | { |
2100 | struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); | |
2101 | struct lto_file_decl_data *file_data; | |
2102 | unsigned int j = 0; | |
2103 | ||
2104 | while ((file_data = file_data_vec[j++])) | |
2105 | { | |
2106 | size_t len; | |
2107 | const char *data = | |
2108 | lto_get_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, | |
2109 | &len); | |
2110 | ||
2111 | if (data) | |
2112 | input_cgraph_opt_section (file_data, data, len, nodes); | |
2113 | } | |
2114 | } |