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