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