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