]>
Commit | Line | Data |
---|---|---|
7bfefa9d | 1 | /* Write and read the cgraph to the memory mapped representation of a |
2 | .o file. | |
3 | ||
711789cc | 4 | Copyright (C) 2009-2013 Free Software Foundation, Inc. |
7bfefa9d | 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" | |
26 | #include "tm.h" | |
7bfefa9d | 27 | #include "tree.h" |
9ed99284 | 28 | #include "stringpool.h" |
bc61cadb | 29 | #include "basic-block.h" |
30 | #include "tree-ssa-alias.h" | |
31 | #include "internal-fn.h" | |
32 | #include "gimple-expr.h" | |
33 | #include "is-a.h" | |
b23fb4cb | 34 | #include "gimple.h" |
7bfefa9d | 35 | #include "expr.h" |
36 | #include "flags.h" | |
37 | #include "params.h" | |
38 | #include "input.h" | |
7bfefa9d | 39 | #include "hashtab.h" |
40 | #include "langhooks.h" | |
073c1fd5 | 41 | #include "bitmap.h" |
7bfefa9d | 42 | #include "function.h" |
852f689e | 43 | #include "diagnostic-core.h" |
7bfefa9d | 44 | #include "except.h" |
7bfefa9d | 45 | #include "timevar.h" |
7bfefa9d | 46 | #include "lto-streamer.h" |
2541503d | 47 | #include "data-streamer.h" |
48 | #include "tree-streamer.h" | |
6c0782b1 | 49 | #include "gcov-io.h" |
b9e2d290 | 50 | #include "tree-pass.h" |
e3ba12e8 | 51 | #include "profile.h" |
3ea50c01 | 52 | #include "context.h" |
53 | #include "pass_manager.h" | |
b855a50e | 54 | #include "ipa-utils.h" |
7bfefa9d | 55 | |
eab36a5a | 56 | static void output_cgraph_opt_summary (void); |
452659af | 57 | static void input_cgraph_opt_summary (vec<symtab_node *> nodes); |
1bf41320 | 58 | |
7857a7b7 | 59 | /* Number of LDPR values known to GCC. */ |
da722561 | 60 | #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1) |
a238367f | 61 | |
f1007c72 | 62 | /* All node orders are ofsetted by ORDER_BASE. */ |
63 | static int order_base; | |
64 | ||
b7e3aeb1 | 65 | /* Cgraph streaming is organized as set of record whose type |
66 | is indicated by a tag. */ | |
70225339 | 67 | enum LTO_symtab_tags |
b7e3aeb1 | 68 | { |
69 | /* Must leave 0 for the stopper. */ | |
70 | ||
71 | /* Cgraph node without body available. */ | |
70225339 | 72 | LTO_symtab_unavail_node = 1, |
b7e3aeb1 | 73 | /* Cgraph node with function body. */ |
70225339 | 74 | LTO_symtab_analyzed_node, |
b7e3aeb1 | 75 | /* Cgraph edges. */ |
70225339 | 76 | LTO_symtab_edge, |
77 | LTO_symtab_indirect_edge, | |
78 | LTO_symtab_variable, | |
79 | LTO_symtab_last_tag | |
b7e3aeb1 | 80 | }; |
81 | ||
b8925abd | 82 | /* Create a new symtab encoder. |
83 | if FOR_INPUT, the encoder allocate only datastructures needed | |
84 | to read the symtab. */ | |
7bfefa9d | 85 | |
70225339 | 86 | lto_symtab_encoder_t |
b8925abd | 87 | lto_symtab_encoder_new (bool for_input) |
7bfefa9d | 88 | { |
70225339 | 89 | lto_symtab_encoder_t encoder = XCNEW (struct lto_symtab_encoder_d); |
b8925abd | 90 | |
91 | if (!for_input) | |
92 | encoder->map = pointer_map_create (); | |
f1f41a6c | 93 | encoder->nodes.create (0); |
7bfefa9d | 94 | return encoder; |
95 | } | |
96 | ||
97 | ||
98 | /* Delete ENCODER and its components. */ | |
99 | ||
100 | void | |
70225339 | 101 | lto_symtab_encoder_delete (lto_symtab_encoder_t encoder) |
7bfefa9d | 102 | { |
f1f41a6c | 103 | encoder->nodes.release (); |
b8925abd | 104 | if (encoder->map) |
105 | pointer_map_destroy (encoder->map); | |
7bfefa9d | 106 | free (encoder); |
107 | } | |
108 | ||
109 | ||
70225339 | 110 | /* Return the existing reference number of NODE in the symtab encoder in |
7bfefa9d | 111 | output block OB. Assign a new reference if this is the first time |
112 | NODE is encoded. */ | |
113 | ||
114 | int | |
70225339 | 115 | lto_symtab_encoder_encode (lto_symtab_encoder_t encoder, |
452659af | 116 | symtab_node *node) |
7bfefa9d | 117 | { |
118 | int ref; | |
119 | void **slot; | |
48e1416a | 120 | |
b8925abd | 121 | if (!encoder->map) |
122 | { | |
123 | lto_encoder_entry entry = {node, false, false, false}; | |
124 | ||
f1f41a6c | 125 | ref = encoder->nodes.length (); |
126 | encoder->nodes.safe_push (entry); | |
b8925abd | 127 | return ref; |
128 | } | |
129 | ||
7bfefa9d | 130 | slot = pointer_map_contains (encoder->map, node); |
5cf7e051 | 131 | if (!slot || !*slot) |
7bfefa9d | 132 | { |
5cf7e051 | 133 | lto_encoder_entry entry = {node, false, false, false}; |
f1f41a6c | 134 | ref = encoder->nodes.length (); |
5cf7e051 | 135 | if (!slot) |
136 | slot = pointer_map_insert (encoder->map, node); | |
137 | *slot = (void *) (intptr_t) (ref + 1); | |
f1f41a6c | 138 | encoder->nodes.safe_push (entry); |
7bfefa9d | 139 | } |
140 | else | |
5cf7e051 | 141 | ref = (size_t) *slot - 1; |
7bfefa9d | 142 | |
143 | return ref; | |
144 | } | |
145 | ||
5cf7e051 | 146 | /* Remove NODE from encoder. */ |
7bfefa9d | 147 | |
5cf7e051 | 148 | bool |
149 | lto_symtab_encoder_delete_node (lto_symtab_encoder_t encoder, | |
452659af | 150 | symtab_node *node) |
7bfefa9d | 151 | { |
5cf7e051 | 152 | void **slot, **last_slot; |
153 | int index; | |
154 | lto_encoder_entry last_node; | |
155 | ||
156 | slot = pointer_map_contains (encoder->map, node); | |
157 | if (slot == NULL || !*slot) | |
158 | return false; | |
159 | ||
160 | index = (size_t) *slot - 1; | |
f1f41a6c | 161 | gcc_checking_assert (encoder->nodes[index].node == node); |
5cf7e051 | 162 | |
163 | /* Remove from vector. We do this by swapping node with the last element | |
164 | of the vector. */ | |
f1f41a6c | 165 | last_node = encoder->nodes.pop (); |
5cf7e051 | 166 | if (last_node.node != node) |
167 | { | |
168 | last_slot = pointer_map_contains (encoder->map, last_node.node); | |
169 | gcc_checking_assert (last_slot && *last_slot); | |
170 | *last_slot = (void *)(size_t) (index + 1); | |
171 | ||
172 | /* Move the last element to the original spot of NODE. */ | |
f1f41a6c | 173 | encoder->nodes[index] = last_node; |
5cf7e051 | 174 | } |
175 | ||
176 | /* Remove element from hash table. */ | |
177 | *slot = NULL; | |
178 | return true; | |
7bfefa9d | 179 | } |
180 | ||
181 | ||
02b2818c | 182 | /* Return TRUE if we should encode initializer of NODE (if any). */ |
7bfefa9d | 183 | |
02b2818c | 184 | bool |
70225339 | 185 | lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t encoder, |
02b2818c | 186 | struct cgraph_node *node) |
187 | { | |
02774f2d | 188 | int index = lto_symtab_encoder_lookup (encoder, node); |
f1f41a6c | 189 | return encoder->nodes[index].body; |
02b2818c | 190 | } |
191 | ||
192 | /* Return TRUE if we should encode body of NODE (if any). */ | |
193 | ||
194 | static void | |
70225339 | 195 | lto_set_symtab_encoder_encode_body (lto_symtab_encoder_t encoder, |
02b2818c | 196 | struct cgraph_node *node) |
7bfefa9d | 197 | { |
02774f2d | 198 | int index = lto_symtab_encoder_encode (encoder, node); |
199 | gcc_checking_assert (encoder->nodes[index].node == node); | |
f1f41a6c | 200 | encoder->nodes[index].body = true; |
7bfefa9d | 201 | } |
202 | ||
a238367f | 203 | /* Return TRUE if we should encode initializer of NODE (if any). */ |
204 | ||
205 | bool | |
70225339 | 206 | lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t encoder, |
207 | struct varpool_node *node) | |
a238367f | 208 | { |
02774f2d | 209 | int index = lto_symtab_encoder_lookup (encoder, node); |
5cf7e051 | 210 | if (index == LCC_NOT_FOUND) |
211 | return false; | |
f1f41a6c | 212 | return encoder->nodes[index].initializer; |
a238367f | 213 | } |
214 | ||
215 | /* Return TRUE if we should encode initializer of NODE (if any). */ | |
216 | ||
217 | static void | |
70225339 | 218 | lto_set_symtab_encoder_encode_initializer (lto_symtab_encoder_t encoder, |
219 | struct varpool_node *node) | |
a238367f | 220 | { |
02774f2d | 221 | int index = lto_symtab_encoder_lookup (encoder, node); |
f1f41a6c | 222 | encoder->nodes[index].initializer = true; |
a238367f | 223 | } |
7bfefa9d | 224 | |
eab36a5a | 225 | /* Return TRUE if we should encode initializer of NODE (if any). */ |
226 | ||
227 | bool | |
228 | lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t encoder, | |
452659af | 229 | symtab_node *node) |
eab36a5a | 230 | { |
02774f2d | 231 | int index = lto_symtab_encoder_lookup (encoder, node); |
5cf7e051 | 232 | if (index == LCC_NOT_FOUND) |
233 | return false; | |
f1f41a6c | 234 | return encoder->nodes[index].in_partition; |
eab36a5a | 235 | } |
236 | ||
237 | /* Return TRUE if we should encode body of NODE (if any). */ | |
238 | ||
239 | void | |
240 | lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder, | |
452659af | 241 | symtab_node *node) |
eab36a5a | 242 | { |
02774f2d | 243 | int index = lto_symtab_encoder_encode (encoder, node); |
f1f41a6c | 244 | encoder->nodes[index].in_partition = true; |
eab36a5a | 245 | } |
246 | ||
7bfefa9d | 247 | /* Output the cgraph EDGE to OB using ENCODER. */ |
248 | ||
249 | static void | |
250 | lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge, | |
70225339 | 251 | lto_symtab_encoder_t encoder) |
7bfefa9d | 252 | { |
253 | unsigned int uid; | |
254 | intptr_t ref; | |
30baba90 | 255 | struct bitpack_d bp; |
7bfefa9d | 256 | |
799c8711 | 257 | if (edge->indirect_unknown_callee) |
70225339 | 258 | streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, |
259 | LTO_symtab_indirect_edge); | |
799c8711 | 260 | else |
70225339 | 261 | streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, |
262 | LTO_symtab_edge); | |
7bfefa9d | 263 | |
02774f2d | 264 | ref = lto_symtab_encoder_lookup (encoder, edge->caller); |
48e1416a | 265 | gcc_assert (ref != LCC_NOT_FOUND); |
7f385784 | 266 | streamer_write_hwi_stream (ob->main_stream, ref); |
7bfefa9d | 267 | |
799c8711 | 268 | if (!edge->indirect_unknown_callee) |
269 | { | |
02774f2d | 270 | ref = lto_symtab_encoder_lookup (encoder, edge->callee); |
799c8711 | 271 | gcc_assert (ref != LCC_NOT_FOUND); |
7f385784 | 272 | streamer_write_hwi_stream (ob->main_stream, ref); |
799c8711 | 273 | } |
7bfefa9d | 274 | |
fc44a215 | 275 | streamer_write_gcov_count_stream (ob->main_stream, edge->count); |
7bfefa9d | 276 | |
30baba90 | 277 | bp = bitpack_create (ob->main_stream); |
02774f2d | 278 | uid = (!gimple_has_body_p (edge->caller->decl) |
4d044066 | 279 | ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt) + 1); |
7857a7b7 | 280 | bp_pack_enum (&bp, cgraph_inline_failed_enum, |
281 | CIF_N_REASONS, edge->inline_failed); | |
282 | bp_pack_var_len_unsigned (&bp, uid); | |
283 | bp_pack_var_len_unsigned (&bp, edge->frequency); | |
30baba90 | 284 | bp_pack_value (&bp, edge->indirect_inlining_edge, 1); |
4d044066 | 285 | bp_pack_value (&bp, edge->speculative, 1); |
30baba90 | 286 | bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1); |
287 | bp_pack_value (&bp, edge->can_throw_external, 1); | |
f8b7e3ec | 288 | if (edge->indirect_unknown_callee) |
289 | { | |
290 | int flags = edge->indirect_info->ecf_flags; | |
30baba90 | 291 | bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1); |
292 | bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1); | |
293 | bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1); | |
294 | bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1); | |
295 | bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1); | |
296 | bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1); | |
f8b7e3ec | 297 | /* Flags that should not appear on indirect calls. */ |
298 | gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE | |
299 | | ECF_MAY_BE_ALLOCA | |
300 | | ECF_SIBCALL | |
c470c5a9 | 301 | | ECF_LEAF |
f8b7e3ec | 302 | | ECF_NOVOPS))); |
303 | } | |
7f385784 | 304 | streamer_write_bitpack (&bp); |
6a261305 | 305 | if (edge->indirect_unknown_callee) |
306 | { | |
307 | streamer_write_hwi_stream (ob->main_stream, | |
308 | edge->indirect_info->common_target_id); | |
309 | if (edge->indirect_info->common_target_id) | |
310 | streamer_write_hwi_stream | |
311 | (ob->main_stream, edge->indirect_info->common_target_probability); | |
312 | } | |
7bfefa9d | 313 | } |
314 | ||
8d810329 | 315 | /* Return if LIST contain references from other partitions. */ |
d97be713 | 316 | |
8d810329 | 317 | bool |
eab36a5a | 318 | referenced_from_other_partition_p (struct ipa_ref_list *list, lto_symtab_encoder_t encoder) |
8d810329 | 319 | { |
320 | int i; | |
321 | struct ipa_ref *ref; | |
04ec15fa | 322 | for (i = 0; ipa_ref_list_referring_iterate (list, i, ref); i++) |
8d810329 | 323 | { |
02774f2d | 324 | if (ref->referring->in_other_partition |
eab36a5a | 325 | || !lto_symtab_encoder_in_partition_p (encoder, ref->referring)) |
326 | return true; | |
8d810329 | 327 | } |
328 | return false; | |
329 | } | |
330 | ||
08843223 | 331 | /* Return true when node is reachable from other partition. */ |
332 | ||
25429dc2 | 333 | bool |
eab36a5a | 334 | reachable_from_other_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder) |
08843223 | 335 | { |
336 | struct cgraph_edge *e; | |
02774f2d | 337 | if (!node->definition) |
08843223 | 338 | return false; |
339 | if (node->global.inlined_to) | |
340 | return false; | |
341 | for (e = node->callers; e; e = e->next_caller) | |
02774f2d | 342 | if (e->caller->in_other_partition |
343 | || !lto_symtab_encoder_in_partition_p (encoder, e->caller)) | |
08843223 | 344 | return true; |
345 | return false; | |
346 | } | |
7bfefa9d | 347 | |
d97be713 | 348 | /* Return if LIST contain references from other partitions. */ |
349 | ||
350 | bool | |
eab36a5a | 351 | referenced_from_this_partition_p (struct ipa_ref_list *list, |
352 | lto_symtab_encoder_t encoder) | |
d97be713 | 353 | { |
354 | int i; | |
355 | struct ipa_ref *ref; | |
04ec15fa | 356 | for (i = 0; ipa_ref_list_referring_iterate (list, i, ref); i++) |
eab36a5a | 357 | if (lto_symtab_encoder_in_partition_p (encoder, ref->referring)) |
358 | return true; | |
d97be713 | 359 | return false; |
360 | } | |
361 | ||
362 | /* Return true when node is reachable from other partition. */ | |
363 | ||
364 | bool | |
eab36a5a | 365 | reachable_from_this_partition_p (struct cgraph_node *node, lto_symtab_encoder_t encoder) |
d97be713 | 366 | { |
367 | struct cgraph_edge *e; | |
d97be713 | 368 | for (e = node->callers; e; e = e->next_caller) |
02774f2d | 369 | if (lto_symtab_encoder_in_partition_p (encoder, e->caller)) |
d97be713 | 370 | return true; |
371 | return false; | |
372 | } | |
373 | ||
7bfefa9d | 374 | /* Output the cgraph NODE to OB. ENCODER is used to find the |
375 | reference number of NODE->inlined_to. SET is the set of nodes we | |
376 | are writing to the current file. If NODE is not in SET, then NODE | |
377 | is a boundary of a cgraph_node_set and we pretend NODE just has a | |
378 | decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs | |
379 | that have had their callgraph node written so far. This is used to | |
380 | determine if NODE is a clone of a previously written node. */ | |
381 | ||
382 | static void | |
383 | lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node, | |
eab36a5a | 384 | lto_symtab_encoder_t encoder) |
7bfefa9d | 385 | { |
386 | unsigned int tag; | |
30baba90 | 387 | struct bitpack_d bp; |
02b2818c | 388 | bool boundary_p; |
7bfefa9d | 389 | intptr_t ref; |
08843223 | 390 | bool in_other_partition = false; |
eaad46f2 | 391 | struct cgraph_node *clone_of, *ultimate_clone_of; |
b23e5d49 | 392 | ipa_opt_pass_d *pass; |
b9e2d290 | 393 | int i; |
48669653 | 394 | bool alias_p; |
7bfefa9d | 395 | |
02774f2d | 396 | boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node); |
7bfefa9d | 397 | |
02774f2d | 398 | if (node->analyzed && !boundary_p) |
70225339 | 399 | tag = LTO_symtab_analyzed_node; |
b7e3aeb1 | 400 | else |
70225339 | 401 | tag = LTO_symtab_unavail_node; |
7bfefa9d | 402 | |
70225339 | 403 | streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, |
7f385784 | 404 | tag); |
02774f2d | 405 | streamer_write_hwi_stream (ob->main_stream, node->order); |
7bfefa9d | 406 | |
7bfefa9d | 407 | /* In WPA mode, we only output part of the call-graph. Also, we |
408 | fake cgraph node attributes. There are two cases that we care. | |
409 | ||
410 | Boundary nodes: There are nodes that are not part of SET but are | |
411 | called from within SET. We artificially make them look like | |
48e1416a | 412 | externally visible nodes with no function body. |
7bfefa9d | 413 | |
414 | Cherry-picked nodes: These are nodes we pulled from other | |
415 | translation units into SET during IPA-inlining. We make them as | |
416 | local static nodes to prevent clashes with other local statics. */ | |
02774f2d | 417 | if (boundary_p && node->analyzed && !DECL_EXTERNAL (node->decl)) |
7bfefa9d | 418 | { |
08843223 | 419 | /* Inline clones can not be part of boundary. |
420 | gcc_assert (!node->global.inlined_to); | |
421 | ||
422 | FIXME: At the moment they can be, when partition contains an inline | |
423 | clone that is clone of inline clone from outside partition. We can | |
424 | reshape the clone tree and make other tree to be the root, but it | |
425 | needs a bit extra work and will be promplty done by cgraph_remove_node | |
426 | after reading back. */ | |
427 | in_other_partition = 1; | |
7bfefa9d | 428 | } |
7bfefa9d | 429 | |
02b2818c | 430 | clone_of = node->clone_of; |
431 | while (clone_of | |
02774f2d | 432 | && (ref = lto_symtab_encoder_lookup (encoder, clone_of)) == LCC_NOT_FOUND) |
02b2818c | 433 | if (clone_of->prev_sibling_clone) |
434 | clone_of = clone_of->prev_sibling_clone; | |
435 | else | |
436 | clone_of = clone_of->clone_of; | |
083e227a | 437 | |
eaad46f2 | 438 | /* See if body of the master function is output. If not, we are seeing only |
439 | an declaration and we do not need to pass down clone tree. */ | |
440 | ultimate_clone_of = clone_of; | |
441 | while (ultimate_clone_of && ultimate_clone_of->clone_of) | |
442 | ultimate_clone_of = ultimate_clone_of->clone_of; | |
443 | ||
444 | if (clone_of && !lto_symtab_encoder_encode_body_p (encoder, ultimate_clone_of)) | |
445 | clone_of = NULL; | |
446 | ||
447 | if (tag == LTO_symtab_analyzed_node) | |
083e227a | 448 | gcc_assert (clone_of || !node->clone_of); |
02b2818c | 449 | if (!clone_of) |
7f385784 | 450 | streamer_write_hwi_stream (ob->main_stream, LCC_NOT_FOUND); |
02b2818c | 451 | else |
7f385784 | 452 | streamer_write_hwi_stream (ob->main_stream, ref); |
7bfefa9d | 453 | |
7bfefa9d | 454 | |
02774f2d | 455 | lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->decl); |
fc44a215 | 456 | streamer_write_gcov_count_stream (ob->main_stream, node->count); |
7f385784 | 457 | streamer_write_hwi_stream (ob->main_stream, node->count_materialization_scale); |
7bfefa9d | 458 | |
b9e2d290 | 459 | streamer_write_hwi_stream (ob->main_stream, |
f1f41a6c | 460 | node->ipa_transforms_to_apply.length ()); |
461 | FOR_EACH_VEC_ELT (node->ipa_transforms_to_apply, i, pass) | |
bcfddb5b | 462 | streamer_write_hwi_stream (ob->main_stream, pass->static_pass_number); |
b9e2d290 | 463 | |
70225339 | 464 | if (tag == LTO_symtab_analyzed_node) |
7bfefa9d | 465 | { |
b7e3aeb1 | 466 | if (node->global.inlined_to) |
467 | { | |
02774f2d | 468 | ref = lto_symtab_encoder_lookup (encoder, node->global.inlined_to); |
b7e3aeb1 | 469 | gcc_assert (ref != LCC_NOT_FOUND); |
470 | } | |
471 | else | |
472 | ref = LCC_NOT_FOUND; | |
7bfefa9d | 473 | |
7f385784 | 474 | streamer_write_hwi_stream (ob->main_stream, ref); |
7bfefa9d | 475 | } |
7bfefa9d | 476 | |
02774f2d | 477 | if (node->same_comdat_group && !boundary_p) |
61c2c7b1 | 478 | { |
70225339 | 479 | ref = lto_symtab_encoder_lookup (encoder, |
02774f2d | 480 | node->same_comdat_group); |
61c2c7b1 | 481 | gcc_assert (ref != LCC_NOT_FOUND); |
482 | } | |
483 | else | |
484 | ref = LCC_NOT_FOUND; | |
7f385784 | 485 | streamer_write_hwi_stream (ob->main_stream, ref); |
61c2c7b1 | 486 | |
38fe12e3 | 487 | streamer_write_hwi_stream (ob->main_stream, node->tp_first_run); |
488 | ||
30baba90 | 489 | bp = bitpack_create (ob->main_stream); |
490 | bp_pack_value (&bp, node->local.local, 1); | |
02774f2d | 491 | bp_pack_value (&bp, node->externally_visible, 1); |
492 | bp_pack_value (&bp, node->definition, 1); | |
c8d92fc1 | 493 | bp_pack_value (&bp, node->local.versionable, 1); |
3c97c75d | 494 | bp_pack_value (&bp, node->local.can_change_signature, 1); |
30baba90 | 495 | bp_pack_value (&bp, node->local.redefined_extern_inline, 1); |
02774f2d | 496 | bp_pack_value (&bp, node->force_output, 1); |
497 | bp_pack_value (&bp, node->forced_by_abi, 1); | |
498 | bp_pack_value (&bp, node->unique_name, 1); | |
499 | bp_pack_value (&bp, node->address_taken, 1); | |
70225339 | 500 | bp_pack_value (&bp, tag == LTO_symtab_analyzed_node |
02774f2d | 501 | && !DECL_EXTERNAL (node->decl) |
502 | && !DECL_COMDAT (node->decl) | |
eab36a5a | 503 | && (reachable_from_other_partition_p (node, encoder) |
02774f2d | 504 | || referenced_from_other_partition_p (&node->ref_list, |
eab36a5a | 505 | encoder)), 1); |
30baba90 | 506 | bp_pack_value (&bp, node->lowered, 1); |
507 | bp_pack_value (&bp, in_other_partition, 1); | |
badeded8 | 508 | /* Real aliases in a boundary become non-aliases. However we still stream |
509 | alias info on weakrefs. | |
510 | TODO: We lose a bit of information here - when we know that variable is | |
511 | defined in other unit, we may use the info on aliases to resolve | |
512 | symbol1 != symbol2 type tests that we can do only for locally defined objects | |
513 | otherwise. */ | |
02774f2d | 514 | alias_p = node->alias && (!boundary_p || node->weakref); |
48669653 | 515 | bp_pack_value (&bp, alias_p, 1); |
02774f2d | 516 | bp_pack_value (&bp, node->weakref, 1); |
30baba90 | 517 | bp_pack_value (&bp, node->frequency, 2); |
0f9fb931 | 518 | bp_pack_value (&bp, node->only_called_at_startup, 1); |
519 | bp_pack_value (&bp, node->only_called_at_exit, 1); | |
ea0e88d1 | 520 | bp_pack_value (&bp, node->tm_clone, 1); |
91bf9d9a | 521 | bp_pack_value (&bp, node->thunk.thunk_p && !boundary_p, 1); |
7857a7b7 | 522 | bp_pack_enum (&bp, ld_plugin_symbol_resolution, |
02774f2d | 523 | LDPR_NUM_KNOWN, node->resolution); |
7f385784 | 524 | streamer_write_bitpack (&bp); |
30baba90 | 525 | |
91bf9d9a | 526 | if (node->thunk.thunk_p && !boundary_p) |
527 | { | |
7f385784 | 528 | streamer_write_uhwi_stream |
91bf9d9a | 529 | (ob->main_stream, |
530 | 1 + (node->thunk.this_adjusting != 0) * 2 | |
531 | + (node->thunk.virtual_offset_p != 0) * 4); | |
7f385784 | 532 | streamer_write_uhwi_stream (ob->main_stream, node->thunk.fixed_offset); |
533 | streamer_write_uhwi_stream (ob->main_stream, node->thunk.virtual_value); | |
91bf9d9a | 534 | } |
6a261305 | 535 | streamer_write_hwi_stream (ob->main_stream, node->profile_id); |
7bfefa9d | 536 | } |
537 | ||
0cddb138 | 538 | /* Output the varpool NODE to OB. |
539 | If NODE is not in SET, then NODE is a boundary. */ | |
540 | ||
541 | static void | |
542 | lto_output_varpool_node (struct lto_simple_output_block *ob, struct varpool_node *node, | |
eab36a5a | 543 | lto_symtab_encoder_t encoder) |
0cddb138 | 544 | { |
02774f2d | 545 | bool boundary_p = !lto_symtab_encoder_in_partition_p (encoder, node); |
30baba90 | 546 | struct bitpack_d bp; |
933b10c6 | 547 | int ref; |
48669653 | 548 | bool alias_p; |
0cddb138 | 549 | |
70225339 | 550 | streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, |
551 | LTO_symtab_variable); | |
02774f2d | 552 | streamer_write_hwi_stream (ob->main_stream, node->order); |
553 | lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->decl); | |
30baba90 | 554 | bp = bitpack_create (ob->main_stream); |
02774f2d | 555 | bp_pack_value (&bp, node->externally_visible, 1); |
556 | bp_pack_value (&bp, node->force_output, 1); | |
557 | bp_pack_value (&bp, node->forced_by_abi, 1); | |
558 | bp_pack_value (&bp, node->unique_name, 1); | |
559 | bp_pack_value (&bp, node->definition, 1); | |
560 | alias_p = node->alias && (!boundary_p || node->weakref); | |
48669653 | 561 | bp_pack_value (&bp, alias_p, 1); |
02774f2d | 562 | bp_pack_value (&bp, node->weakref, 1); |
563 | bp_pack_value (&bp, node->analyzed && !boundary_p, 1); | |
564 | gcc_assert (node->definition || !node->analyzed); | |
da67d826 | 565 | /* Constant pool initializers can be de-unified into individual ltrans units. |
566 | FIXME: Alternatively at -Os we may want to avoid generating for them the local | |
567 | labels and share them across LTRANS partitions. */ | |
02774f2d | 568 | if (DECL_IN_CONSTANT_POOL (node->decl) |
569 | && !DECL_EXTERNAL (node->decl) | |
570 | && !DECL_COMDAT (node->decl)) | |
da67d826 | 571 | { |
30baba90 | 572 | bp_pack_value (&bp, 0, 1); /* used_from_other_parition. */ |
573 | bp_pack_value (&bp, 0, 1); /* in_other_partition. */ | |
da67d826 | 574 | } |
575 | else | |
576 | { | |
02774f2d | 577 | bp_pack_value (&bp, node->definition |
578 | && referenced_from_other_partition_p (&node->ref_list, | |
eab36a5a | 579 | encoder), 1); |
02774f2d | 580 | bp_pack_value (&bp, node->analyzed |
581 | && boundary_p && !DECL_EXTERNAL (node->decl), 1); | |
aa419a52 | 582 | /* in_other_partition. */ |
da67d826 | 583 | } |
7f385784 | 584 | streamer_write_bitpack (&bp); |
02774f2d | 585 | if (node->same_comdat_group && !boundary_p) |
933b10c6 | 586 | { |
70225339 | 587 | ref = lto_symtab_encoder_lookup (encoder, |
02774f2d | 588 | node->same_comdat_group); |
933b10c6 | 589 | gcc_assert (ref != LCC_NOT_FOUND); |
590 | } | |
591 | else | |
592 | ref = LCC_NOT_FOUND; | |
7f385784 | 593 | streamer_write_hwi_stream (ob->main_stream, ref); |
594 | streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution, | |
02774f2d | 595 | LDPR_NUM_KNOWN, node->resolution); |
0cddb138 | 596 | } |
597 | ||
8d810329 | 598 | /* Output the varpool NODE to OB. |
599 | If NODE is not in SET, then NODE is a boundary. */ | |
600 | ||
601 | static void | |
602 | lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref, | |
70225339 | 603 | lto_symtab_encoder_t encoder) |
8d810329 | 604 | { |
30baba90 | 605 | struct bitpack_d bp; |
70225339 | 606 | int nref; |
4d044066 | 607 | int uid = ref->lto_stmt_uid; |
608 | struct cgraph_node *node; | |
70225339 | 609 | |
30baba90 | 610 | bp = bitpack_create (ob->main_stream); |
30baba90 | 611 | bp_pack_value (&bp, ref->use, 2); |
4d044066 | 612 | bp_pack_value (&bp, ref->speculative, 1); |
7f385784 | 613 | streamer_write_bitpack (&bp); |
70225339 | 614 | nref = lto_symtab_encoder_lookup (encoder, ref->referred); |
615 | gcc_assert (nref != LCC_NOT_FOUND); | |
616 | streamer_write_hwi_stream (ob->main_stream, nref); | |
4d044066 | 617 | |
618 | node = dyn_cast <cgraph_node> (ref->referring); | |
619 | if (node) | |
620 | { | |
621 | if (ref->stmt) | |
622 | uid = gimple_uid (ref->stmt) + 1; | |
623 | streamer_write_hwi_stream (ob->main_stream, uid); | |
624 | } | |
8d810329 | 625 | } |
626 | ||
6c0782b1 | 627 | /* Stream out profile_summary to OB. */ |
628 | ||
629 | static void | |
630 | output_profile_summary (struct lto_simple_output_block *ob) | |
631 | { | |
e3ba12e8 | 632 | unsigned h_ix; |
633 | struct bitpack_d bp; | |
634 | ||
6c0782b1 | 635 | if (profile_info) |
636 | { | |
e3ba12e8 | 637 | /* We do not output num and run_max, they are not used by |
638 | GCC profile feedback and they are difficult to merge from multiple | |
639 | units. */ | |
6c0782b1 | 640 | gcc_assert (profile_info->runs); |
7f385784 | 641 | streamer_write_uhwi_stream (ob->main_stream, profile_info->runs); |
9e179a64 | 642 | streamer_write_gcov_count_stream (ob->main_stream, profile_info->sum_max); |
e3ba12e8 | 643 | |
644 | /* sum_all is needed for computing the working set with the | |
645 | histogram. */ | |
9e179a64 | 646 | streamer_write_gcov_count_stream (ob->main_stream, profile_info->sum_all); |
e3ba12e8 | 647 | |
648 | /* Create and output a bitpack of non-zero histogram entries indices. */ | |
649 | bp = bitpack_create (ob->main_stream); | |
650 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
651 | bp_pack_value (&bp, profile_info->histogram[h_ix].num_counters > 0, 1); | |
652 | streamer_write_bitpack (&bp); | |
653 | /* Now stream out only those non-zero entries. */ | |
654 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
655 | { | |
656 | if (!profile_info->histogram[h_ix].num_counters) | |
657 | continue; | |
9e179a64 | 658 | streamer_write_gcov_count_stream (ob->main_stream, |
e3ba12e8 | 659 | profile_info->histogram[h_ix].num_counters); |
9e179a64 | 660 | streamer_write_gcov_count_stream (ob->main_stream, |
e3ba12e8 | 661 | profile_info->histogram[h_ix].min_value); |
9e179a64 | 662 | streamer_write_gcov_count_stream (ob->main_stream, |
e3ba12e8 | 663 | profile_info->histogram[h_ix].cum_value); |
9e179a64 | 664 | } |
665 | /* IPA-profile computes hot bb threshold based on cumulated | |
666 | whole program profile. We need to stream it down to ltrans. */ | |
667 | if (flag_wpa) | |
668 | streamer_write_gcov_count_stream (ob->main_stream, | |
669 | get_hot_bb_threshold ()); | |
6c0782b1 | 670 | } |
671 | else | |
7f385784 | 672 | streamer_write_uhwi_stream (ob->main_stream, 0); |
6c0782b1 | 673 | } |
674 | ||
799c8711 | 675 | /* Output all callees or indirect outgoing edges. EDGE must be the first such |
676 | edge. */ | |
677 | ||
678 | static void | |
679 | output_outgoing_cgraph_edges (struct cgraph_edge *edge, | |
680 | struct lto_simple_output_block *ob, | |
70225339 | 681 | lto_symtab_encoder_t encoder) |
799c8711 | 682 | { |
683 | if (!edge) | |
684 | return; | |
685 | ||
686 | /* Output edges in backward direction, so the reconstructed callgraph match | |
687 | and it is easy to associate call sites in the IPA pass summaries. */ | |
688 | while (edge->next_callee) | |
689 | edge = edge->next_callee; | |
690 | for (; edge; edge = edge->prev_callee) | |
691 | lto_output_edge (ob, edge, encoder); | |
692 | } | |
693 | ||
8d810329 | 694 | /* Output the part of the cgraph in SET. */ |
695 | ||
696 | static void | |
eab36a5a | 697 | output_refs (lto_symtab_encoder_t encoder) |
8d810329 | 698 | { |
eab36a5a | 699 | lto_symtab_encoder_iterator lsei; |
8d810329 | 700 | struct lto_simple_output_block *ob; |
701 | int count; | |
702 | struct ipa_ref *ref; | |
703 | int i; | |
704 | ||
705 | ob = lto_create_simple_output_block (LTO_section_refs); | |
706 | ||
eab36a5a | 707 | for (lsei = lsei_start_in_partition (encoder); !lsei_end_p (lsei); |
708 | lsei_next_in_partition (&lsei)) | |
8d810329 | 709 | { |
452659af | 710 | symtab_node *node = lsei_node (lsei); |
8d810329 | 711 | |
02774f2d | 712 | count = ipa_ref_list_nreferences (&node->ref_list); |
8d810329 | 713 | if (count) |
714 | { | |
6a1c0403 | 715 | streamer_write_gcov_count_stream (ob->main_stream, count); |
7f385784 | 716 | streamer_write_uhwi_stream (ob->main_stream, |
eab36a5a | 717 | lto_symtab_encoder_lookup (encoder, node)); |
02774f2d | 718 | for (i = 0; ipa_ref_list_reference_iterate (&node->ref_list, |
7d0d0ce1 | 719 | i, ref); i++) |
70225339 | 720 | lto_output_ref (ob, ref, encoder); |
8d810329 | 721 | } |
722 | } | |
723 | ||
7f385784 | 724 | streamer_write_uhwi_stream (ob->main_stream, 0); |
8d810329 | 725 | |
726 | lto_destroy_simple_output_block (ob); | |
727 | } | |
728 | ||
724462b0 | 729 | /* Add NODE into encoder as well as nodes it is cloned from. |
730 | Do it in a way so clones appear first. */ | |
731 | ||
732 | static void | |
733 | add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node, | |
734 | bool include_body) | |
735 | { | |
736 | if (node->clone_of) | |
737 | add_node_to (encoder, node->clone_of, include_body); | |
738 | else if (include_body) | |
739 | lto_set_symtab_encoder_encode_body (encoder, node); | |
02774f2d | 740 | lto_symtab_encoder_encode (encoder, node); |
724462b0 | 741 | } |
742 | ||
743 | /* Add all references in LIST to encoders. */ | |
744 | ||
745 | static void | |
746 | add_references (lto_symtab_encoder_t encoder, | |
747 | struct ipa_ref_list *list) | |
748 | { | |
749 | int i; | |
750 | struct ipa_ref *ref; | |
751 | for (i = 0; ipa_ref_list_reference_iterate (list, i, ref); i++) | |
2dc9831f | 752 | if (is_a <cgraph_node> (ref->referred)) |
724462b0 | 753 | add_node_to (encoder, ipa_ref_node (ref), false); |
754 | else | |
c9aa6453 | 755 | lto_symtab_encoder_encode (encoder, ref->referred); |
724462b0 | 756 | } |
757 | ||
758 | /* Find all symbols we want to stream into given partition and insert them | |
759 | to encoders. | |
760 | ||
761 | The function actually replaces IN_ENCODER by new one. The reason is that | |
762 | streaming code needs clone's origin to be streamed before clone. This | |
763 | means that we need to insert the nodes in specific order. This order is | |
764 | ignored by the partitioning logic earlier. */ | |
765 | ||
766 | lto_symtab_encoder_t | |
767 | compute_ltrans_boundary (lto_symtab_encoder_t in_encoder) | |
7bfefa9d | 768 | { |
769 | struct cgraph_node *node; | |
7bfefa9d | 770 | struct cgraph_edge *edge; |
d97be713 | 771 | int i; |
70225339 | 772 | lto_symtab_encoder_t encoder; |
5cf7e051 | 773 | lto_symtab_encoder_iterator lsei; |
b855a50e | 774 | struct pointer_set_t *reachable_call_targets = pointer_set_create (); |
6c0782b1 | 775 | |
b8925abd | 776 | encoder = lto_symtab_encoder_new (false); |
7bfefa9d | 777 | |
5cf7e051 | 778 | /* Go over all entries in the IN_ENCODER and duplicate them to |
779 | ENCODER. At the same time insert masters of clones so | |
780 | every master appears before clone. */ | |
781 | for (lsei = lsei_start_function_in_partition (in_encoder); | |
782 | !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei)) | |
7bfefa9d | 783 | { |
5cf7e051 | 784 | node = lsei_cgraph_node (lsei); |
02b2818c | 785 | add_node_to (encoder, node, true); |
02774f2d | 786 | lto_set_symtab_encoder_in_partition (encoder, node); |
787 | add_references (encoder, &node->ref_list); | |
4df870fd | 788 | /* For proper debug info, we need to ship the origins, too. */ |
02774f2d | 789 | if (DECL_ABSTRACT_ORIGIN (node->decl)) |
4df870fd | 790 | { |
791 | struct cgraph_node *origin_node | |
02774f2d | 792 | = cgraph_get_node (DECL_ABSTRACT_ORIGIN (node->decl)); |
4df870fd | 793 | add_node_to (encoder, origin_node, true); |
794 | } | |
7bfefa9d | 795 | } |
5cf7e051 | 796 | for (lsei = lsei_start_variable_in_partition (in_encoder); |
797 | !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei)) | |
a238367f | 798 | { |
5cf7e051 | 799 | struct varpool_node *vnode = lsei_varpool_node (lsei); |
48669653 | 800 | |
02774f2d | 801 | lto_set_symtab_encoder_in_partition (encoder, vnode); |
70225339 | 802 | lto_set_symtab_encoder_encode_initializer (encoder, vnode); |
02774f2d | 803 | add_references (encoder, &vnode->ref_list); |
4df870fd | 804 | /* For proper debug info, we need to ship the origins, too. */ |
02774f2d | 805 | if (DECL_ABSTRACT_ORIGIN (vnode->decl)) |
4df870fd | 806 | { |
807 | struct varpool_node *origin_node | |
02774f2d | 808 | = varpool_get_node (DECL_ABSTRACT_ORIGIN (node->decl)); |
809 | lto_set_symtab_encoder_in_partition (encoder, origin_node); | |
4df870fd | 810 | } |
a238367f | 811 | } |
a238367f | 812 | /* Pickle in also the initializer of all referenced readonly variables |
813 | to help folding. Constant pool variables are not shared, so we must | |
814 | pickle those too. */ | |
70225339 | 815 | for (i = 0; i < lto_symtab_encoder_size (encoder); i++) |
a238367f | 816 | { |
452659af | 817 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
2dc9831f | 818 | if (varpool_node *vnode = dyn_cast <varpool_node> (node)) |
a238367f | 819 | { |
df8d3e89 | 820 | if (!lto_symtab_encoder_encode_initializer_p (encoder, |
821 | vnode) | |
02774f2d | 822 | && ctor_for_folding (vnode->decl) != error_mark_node) |
70225339 | 823 | { |
824 | lto_set_symtab_encoder_encode_initializer (encoder, vnode); | |
02774f2d | 825 | add_references (encoder, &vnode->ref_list); |
70225339 | 826 | } |
70225339 | 827 | } |
a238367f | 828 | } |
7bfefa9d | 829 | |
830 | /* Go over all the nodes again to include callees that are not in | |
831 | SET. */ | |
5cf7e051 | 832 | for (lsei = lsei_start_function_in_partition (encoder); |
833 | !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei)) | |
7bfefa9d | 834 | { |
5cf7e051 | 835 | node = lsei_cgraph_node (lsei); |
7bfefa9d | 836 | for (edge = node->callees; edge; edge = edge->next_callee) |
837 | { | |
838 | struct cgraph_node *callee = edge->callee; | |
02774f2d | 839 | if (!lto_symtab_encoder_in_partition_p (encoder, callee)) |
7bfefa9d | 840 | { |
841 | /* We should have moved all the inlines. */ | |
842 | gcc_assert (!callee->global.inlined_to); | |
02b2818c | 843 | add_node_to (encoder, callee, false); |
7bfefa9d | 844 | } |
845 | } | |
b855a50e | 846 | /* Add all possible targets for late devirtualization. */ |
847 | if (flag_devirtualize) | |
848 | for (edge = node->indirect_calls; edge; edge = edge->next_callee) | |
849 | if (edge->indirect_info->polymorphic) | |
850 | { | |
851 | unsigned int i; | |
852 | void *cache_token; | |
853 | bool final; | |
854 | vec <cgraph_node *>targets | |
855 | = possible_polymorphic_call_targets | |
856 | (edge, &final, &cache_token); | |
857 | if (!pointer_set_insert (reachable_call_targets, | |
858 | cache_token)) | |
859 | { | |
9af5ce0c | 860 | for (i = 0; i < targets.length (); i++) |
b855a50e | 861 | { |
862 | struct cgraph_node *callee = targets[i]; | |
863 | ||
864 | /* Adding an external declarations into the unit serves | |
865 | no purpose and just increases its boundary. */ | |
02774f2d | 866 | if (callee->definition |
b855a50e | 867 | && !lto_symtab_encoder_in_partition_p |
02774f2d | 868 | (encoder, callee)) |
b855a50e | 869 | { |
870 | gcc_assert (!callee->global.inlined_to); | |
871 | add_node_to (encoder, callee, false); | |
872 | } | |
873 | } | |
874 | } | |
875 | } | |
7bfefa9d | 876 | } |
b855a50e | 877 | lto_symtab_encoder_delete (in_encoder); |
878 | pointer_set_destroy (reachable_call_targets); | |
879 | return encoder; | |
d97be713 | 880 | } |
881 | ||
02b699d5 | 882 | /* Output the part of the symtab in SET and VSET. */ |
d97be713 | 883 | |
884 | void | |
eab36a5a | 885 | output_symtab (void) |
d97be713 | 886 | { |
887 | struct cgraph_node *node; | |
888 | struct lto_simple_output_block *ob; | |
eab36a5a | 889 | lto_symtab_encoder_iterator lsei; |
d97be713 | 890 | int i, n_nodes; |
70225339 | 891 | lto_symtab_encoder_t encoder; |
14c5d106 | 892 | static bool asm_nodes_output = false; |
d97be713 | 893 | |
1bf41320 | 894 | if (flag_wpa) |
eab36a5a | 895 | output_cgraph_opt_summary (); |
1bf41320 | 896 | |
02b699d5 | 897 | ob = lto_create_simple_output_block (LTO_section_symtab_nodes); |
d97be713 | 898 | |
899 | output_profile_summary (ob); | |
900 | ||
901 | /* An encoder for cgraph nodes should have been created by | |
902 | ipa_write_summaries_1. */ | |
70225339 | 903 | gcc_assert (ob->decl_state->symtab_node_encoder); |
904 | encoder = ob->decl_state->symtab_node_encoder; | |
d97be713 | 905 | |
08843223 | 906 | /* Write out the nodes. We must first output a node and then its clones, |
907 | otherwise at a time reading back the node there would be nothing to clone | |
908 | from. */ | |
70225339 | 909 | n_nodes = lto_symtab_encoder_size (encoder); |
7bfefa9d | 910 | for (i = 0; i < n_nodes; i++) |
911 | { | |
452659af | 912 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
2dc9831f | 913 | if (cgraph_node *cnode = dyn_cast <cgraph_node> (node)) |
914 | lto_output_node (ob, cnode, encoder); | |
70225339 | 915 | else |
eab36a5a | 916 | lto_output_varpool_node (ob, varpool (node), encoder); |
70225339 | 917 | |
7bfefa9d | 918 | } |
919 | ||
7bfefa9d | 920 | /* Go over the nodes in SET again to write edges. */ |
eab36a5a | 921 | for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei); |
922 | lsei_next_function_in_partition (&lsei)) | |
7bfefa9d | 923 | { |
eab36a5a | 924 | node = lsei_cgraph_node (lsei); |
799c8711 | 925 | output_outgoing_cgraph_edges (node->callees, ob, encoder); |
926 | output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder); | |
7bfefa9d | 927 | } |
928 | ||
7f385784 | 929 | streamer_write_uhwi_stream (ob->main_stream, 0); |
7bfefa9d | 930 | |
65d1b157 | 931 | lto_destroy_simple_output_block (ob); |
932 | ||
2b7c48a1 | 933 | /* Emit toplevel asms. |
934 | When doing WPA we must output every asm just once. Since we do not partition asm | |
935 | nodes at all, output them to first output. This is kind of hack, but should work | |
936 | well. */ | |
937 | if (!asm_nodes_output) | |
90f477a9 | 938 | { |
2b7c48a1 | 939 | asm_nodes_output = true; |
65d1b157 | 940 | lto_output_toplevel_asms (); |
90f477a9 | 941 | } |
942 | ||
eab36a5a | 943 | output_refs (encoder); |
7bfefa9d | 944 | } |
945 | ||
7bfefa9d | 946 | /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS, |
947 | STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize | |
948 | NODE or to replace the values in it, for instance because the first | |
949 | time we saw it, the function body was not available but now it | |
950 | is. BP is a bitpack with all the bitflags for NODE read from the | |
951 | stream. */ | |
952 | ||
953 | static void | |
954 | input_overwrite_node (struct lto_file_decl_data *file_data, | |
955 | struct cgraph_node *node, | |
70225339 | 956 | enum LTO_symtab_tags tag, |
7857a7b7 | 957 | struct bitpack_d *bp) |
7bfefa9d | 958 | { |
02774f2d | 959 | node->aux = (void *) tag; |
960 | node->lto_file_data = file_data; | |
7bfefa9d | 961 | |
962 | node->local.local = bp_unpack_value (bp, 1); | |
02774f2d | 963 | node->externally_visible = bp_unpack_value (bp, 1); |
964 | node->definition = bp_unpack_value (bp, 1); | |
c8d92fc1 | 965 | node->local.versionable = bp_unpack_value (bp, 1); |
3c97c75d | 966 | node->local.can_change_signature = bp_unpack_value (bp, 1); |
7bfefa9d | 967 | node->local.redefined_extern_inline = bp_unpack_value (bp, 1); |
02774f2d | 968 | node->force_output = bp_unpack_value (bp, 1); |
969 | node->forced_by_abi = bp_unpack_value (bp, 1); | |
970 | node->unique_name = bp_unpack_value (bp, 1); | |
971 | node->address_taken = bp_unpack_value (bp, 1); | |
972 | node->used_from_other_partition = bp_unpack_value (bp, 1); | |
7bfefa9d | 973 | node->lowered = bp_unpack_value (bp, 1); |
02774f2d | 974 | node->analyzed = tag == LTO_symtab_analyzed_node; |
975 | node->in_other_partition = bp_unpack_value (bp, 1); | |
976 | if (node->in_other_partition | |
cdc58a66 | 977 | /* Avoid updating decl when we are seeing just inline clone. |
978 | When inlining function that has functions already inlined into it, | |
979 | we produce clones of inline clones. | |
980 | ||
981 | WPA partitioning might put each clone into different unit and | |
982 | we might end up streaming inline clone from other partition | |
983 | to support clone we are interested in. */ | |
984 | && (!node->clone_of | |
02774f2d | 985 | || node->clone_of->decl != node->decl)) |
eb0bc81b | 986 | { |
02774f2d | 987 | DECL_EXTERNAL (node->decl) = 1; |
988 | TREE_STATIC (node->decl) = 0; | |
eb0bc81b | 989 | } |
02774f2d | 990 | node->alias = bp_unpack_value (bp, 1); |
991 | node->weakref = bp_unpack_value (bp, 1); | |
125b6d78 | 992 | node->frequency = (enum node_frequency)bp_unpack_value (bp, 2); |
0f9fb931 | 993 | node->only_called_at_startup = bp_unpack_value (bp, 1); |
994 | node->only_called_at_exit = bp_unpack_value (bp, 1); | |
ea0e88d1 | 995 | node->tm_clone = bp_unpack_value (bp, 1); |
91bf9d9a | 996 | node->thunk.thunk_p = bp_unpack_value (bp, 1); |
02774f2d | 997 | node->resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution, |
7857a7b7 | 998 | LDPR_NUM_KNOWN); |
7bfefa9d | 999 | } |
1000 | ||
48669653 | 1001 | /* Return string alias is alias of. */ |
1002 | ||
1003 | static tree | |
1004 | get_alias_symbol (tree decl) | |
1005 | { | |
1006 | tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)); | |
48669653 | 1007 | return get_identifier (TREE_STRING_POINTER |
1008 | (TREE_VALUE (TREE_VALUE (alias)))); | |
1009 | } | |
1010 | ||
48e1416a | 1011 | /* Read a node from input_block IB. TAG is the node's tag just read. |
7bfefa9d | 1012 | Return the node read or overwriten. */ |
48e1416a | 1013 | |
7bfefa9d | 1014 | static struct cgraph_node * |
1015 | input_node (struct lto_file_decl_data *file_data, | |
1016 | struct lto_input_block *ib, | |
70225339 | 1017 | enum LTO_symtab_tags tag, |
452659af | 1018 | vec<symtab_node *> nodes) |
7bfefa9d | 1019 | { |
3ea50c01 | 1020 | gcc::pass_manager *passes = g->get_passes (); |
7bfefa9d | 1021 | tree fn_decl; |
1022 | struct cgraph_node *node; | |
30baba90 | 1023 | struct bitpack_d bp; |
7bfefa9d | 1024 | unsigned decl_index; |
61c2c7b1 | 1025 | int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND; |
02b2818c | 1026 | int clone_ref; |
f1007c72 | 1027 | int order; |
b9e2d290 | 1028 | int i, count; |
7bfefa9d | 1029 | |
f1007c72 | 1030 | order = streamer_read_hwi (ib) + order_base; |
7f385784 | 1031 | clone_ref = streamer_read_hwi (ib); |
7bfefa9d | 1032 | |
7f385784 | 1033 | decl_index = streamer_read_uhwi (ib); |
7bfefa9d | 1034 | fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index); |
1035 | ||
02b2818c | 1036 | if (clone_ref != LCC_NOT_FOUND) |
1037 | { | |
f1f41a6c | 1038 | node = cgraph_clone_node (cgraph (nodes[clone_ref]), fn_decl, |
1039 | 0, CGRAPH_FREQ_BASE, false, | |
48f42a9a | 1040 | vNULL, false, NULL); |
02b2818c | 1041 | } |
7bfefa9d | 1042 | else |
9e9c3e92 | 1043 | { |
1044 | /* Declaration of functions can be already merged with a declaration | |
1045 | from other input file. We keep cgraph unmerged until after streaming | |
1046 | of ipa passes is done. Alays forcingly create a fresh node. */ | |
1047 | node = cgraph_create_empty_node (); | |
02774f2d | 1048 | node->decl = fn_decl; |
1049 | symtab_register_node (node); | |
9e9c3e92 | 1050 | } |
7bfefa9d | 1051 | |
02774f2d | 1052 | node->order = order; |
0704fb2e | 1053 | if (order >= symtab_order) |
1054 | symtab_order = order + 1; | |
f1007c72 | 1055 | |
fc44a215 | 1056 | node->count = streamer_read_gcov_count (ib); |
7f385784 | 1057 | node->count_materialization_scale = streamer_read_hwi (ib); |
48e1416a | 1058 | |
b9e2d290 | 1059 | count = streamer_read_hwi (ib); |
1e094109 | 1060 | node->ipa_transforms_to_apply = vNULL; |
b9e2d290 | 1061 | for (i = 0; i < count; i++) |
1062 | { | |
b23e5d49 | 1063 | opt_pass *pass; |
b9e2d290 | 1064 | int pid = streamer_read_hwi (ib); |
1065 | ||
3ea50c01 | 1066 | gcc_assert (pid < passes->passes_by_id_size); |
1067 | pass = passes->passes_by_id[pid]; | |
b23e5d49 | 1068 | node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *) pass); |
b9e2d290 | 1069 | } |
1070 | ||
70225339 | 1071 | if (tag == LTO_symtab_analyzed_node) |
7f385784 | 1072 | ref = streamer_read_hwi (ib); |
7bfefa9d | 1073 | |
7f385784 | 1074 | ref2 = streamer_read_hwi (ib); |
7bfefa9d | 1075 | |
1076 | /* Make sure that we have not read this node before. Nodes that | |
1077 | have already been read will have their tag stored in the 'aux' | |
1078 | field. Since built-in functions can be referenced in multiple | |
1079 | functions, they are expected to be read more than once. */ | |
02774f2d | 1080 | if (node->aux && !DECL_BUILT_IN (node->decl)) |
7bfefa9d | 1081 | internal_error ("bytecode stream: found multiple instances of cgraph " |
15c999e3 | 1082 | "node with uid %d", node->uid); |
7bfefa9d | 1083 | |
38fe12e3 | 1084 | node->tp_first_run = streamer_read_uhwi (ib); |
1085 | ||
7f385784 | 1086 | bp = streamer_read_bitpack (ib); |
38fe12e3 | 1087 | |
7857a7b7 | 1088 | input_overwrite_node (file_data, node, tag, &bp); |
7bfefa9d | 1089 | |
7bfefa9d | 1090 | /* Store a reference for now, and fix up later to be a pointer. */ |
1091 | node->global.inlined_to = (cgraph_node_ptr) (intptr_t) ref; | |
1092 | ||
61c2c7b1 | 1093 | /* Store a reference for now, and fix up later to be a pointer. */ |
452659af | 1094 | node->same_comdat_group = (symtab_node *) (intptr_t) ref2; |
61c2c7b1 | 1095 | |
91bf9d9a | 1096 | if (node->thunk.thunk_p) |
1097 | { | |
7f385784 | 1098 | int type = streamer_read_uhwi (ib); |
1099 | HOST_WIDE_INT fixed_offset = streamer_read_uhwi (ib); | |
1100 | HOST_WIDE_INT virtual_value = streamer_read_uhwi (ib); | |
91bf9d9a | 1101 | |
91bf9d9a | 1102 | node->thunk.fixed_offset = fixed_offset; |
1103 | node->thunk.this_adjusting = (type & 2); | |
1104 | node->thunk.virtual_value = virtual_value; | |
1105 | node->thunk.virtual_offset_p = (type & 4); | |
91bf9d9a | 1106 | } |
02774f2d | 1107 | if (node->alias && !node->analyzed && node->weakref) |
1108 | node->alias_target = get_alias_symbol (node->decl); | |
6a261305 | 1109 | node->profile_id = streamer_read_hwi (ib); |
7bfefa9d | 1110 | return node; |
1111 | } | |
1112 | ||
0cddb138 | 1113 | /* Read a node from input_block IB. TAG is the node's tag just read. |
1114 | Return the node read or overwriten. */ | |
1115 | ||
1116 | static struct varpool_node * | |
1117 | input_varpool_node (struct lto_file_decl_data *file_data, | |
1118 | struct lto_input_block *ib) | |
1119 | { | |
1120 | int decl_index; | |
1121 | tree var_decl; | |
1122 | struct varpool_node *node; | |
30baba90 | 1123 | struct bitpack_d bp; |
933b10c6 | 1124 | int ref = LCC_NOT_FOUND; |
f1007c72 | 1125 | int order; |
0cddb138 | 1126 | |
f1007c72 | 1127 | order = streamer_read_hwi (ib) + order_base; |
7f385784 | 1128 | decl_index = streamer_read_uhwi (ib); |
0cddb138 | 1129 | var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index); |
9e9c3e92 | 1130 | |
1131 | /* Declaration of functions can be already merged with a declaration | |
1132 | from other input file. We keep cgraph unmerged until after streaming | |
1133 | of ipa passes is done. Alays forcingly create a fresh node. */ | |
1134 | node = varpool_create_empty_node (); | |
02774f2d | 1135 | node->decl = var_decl; |
1136 | symtab_register_node (node); | |
9e9c3e92 | 1137 | |
02774f2d | 1138 | node->order = order; |
0704fb2e | 1139 | if (order >= symtab_order) |
1140 | symtab_order = order + 1; | |
02774f2d | 1141 | node->lto_file_data = file_data; |
0cddb138 | 1142 | |
7f385784 | 1143 | bp = streamer_read_bitpack (ib); |
02774f2d | 1144 | node->externally_visible = bp_unpack_value (&bp, 1); |
1145 | node->force_output = bp_unpack_value (&bp, 1); | |
1146 | node->forced_by_abi = bp_unpack_value (&bp, 1); | |
1147 | node->unique_name = bp_unpack_value (&bp, 1); | |
1148 | node->definition = bp_unpack_value (&bp, 1); | |
1149 | node->alias = bp_unpack_value (&bp, 1); | |
1150 | node->weakref = bp_unpack_value (&bp, 1); | |
1151 | node->analyzed = bp_unpack_value (&bp, 1); | |
1152 | node->used_from_other_partition = bp_unpack_value (&bp, 1); | |
1153 | node->in_other_partition = bp_unpack_value (&bp, 1); | |
1154 | if (node->in_other_partition) | |
eb0bc81b | 1155 | { |
02774f2d | 1156 | DECL_EXTERNAL (node->decl) = 1; |
1157 | TREE_STATIC (node->decl) = 0; | |
eb0bc81b | 1158 | } |
02774f2d | 1159 | if (node->alias && !node->analyzed && node->weakref) |
1160 | node->alias_target = get_alias_symbol (node->decl); | |
7f385784 | 1161 | ref = streamer_read_hwi (ib); |
933b10c6 | 1162 | /* Store a reference for now, and fix up later to be a pointer. */ |
452659af | 1163 | node->same_comdat_group = (symtab_node *) (intptr_t) ref; |
02774f2d | 1164 | node->resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution, |
7d0d0ce1 | 1165 | LDPR_NUM_KNOWN); |
e0eaac80 | 1166 | |
0cddb138 | 1167 | return node; |
1168 | } | |
1169 | ||
8d810329 | 1170 | /* Read a node from input_block IB. TAG is the node's tag just read. |
1171 | Return the node read or overwriten. */ | |
1172 | ||
1173 | static void | |
1174 | input_ref (struct lto_input_block *ib, | |
452659af | 1175 | symtab_node *referring_node, |
1176 | vec<symtab_node *> nodes) | |
8d810329 | 1177 | { |
452659af | 1178 | symtab_node *node = NULL; |
30baba90 | 1179 | struct bitpack_d bp; |
8d810329 | 1180 | enum ipa_ref_use use; |
4d044066 | 1181 | bool speculative; |
1182 | struct ipa_ref *ref; | |
8d810329 | 1183 | |
7f385784 | 1184 | bp = streamer_read_bitpack (ib); |
30baba90 | 1185 | use = (enum ipa_ref_use) bp_unpack_value (&bp, 2); |
4d044066 | 1186 | speculative = (enum ipa_ref_use) bp_unpack_value (&bp, 1); |
f1f41a6c | 1187 | node = nodes[streamer_read_hwi (ib)]; |
4d044066 | 1188 | ref = ipa_record_reference (referring_node, node, use, NULL); |
1189 | ref->speculative = speculative; | |
1190 | if (is_a <cgraph_node> (referring_node)) | |
1191 | ref->lto_stmt_uid = streamer_read_hwi (ib); | |
8d810329 | 1192 | } |
7bfefa9d | 1193 | |
799c8711 | 1194 | /* Read an edge from IB. NODES points to a vector of previously read nodes for |
1195 | decoding caller and callee of the edge to be read. If INDIRECT is true, the | |
1196 | edge being read is indirect (in the sense that it has | |
1197 | indirect_unknown_callee set). */ | |
7bfefa9d | 1198 | |
1199 | static void | |
452659af | 1200 | input_edge (struct lto_input_block *ib, vec<symtab_node *> nodes, |
799c8711 | 1201 | bool indirect) |
7bfefa9d | 1202 | { |
1203 | struct cgraph_node *caller, *callee; | |
1204 | struct cgraph_edge *edge; | |
1205 | unsigned int stmt_id; | |
1206 | gcov_type count; | |
1207 | int freq; | |
7bfefa9d | 1208 | cgraph_inline_failed_t inline_failed; |
30baba90 | 1209 | struct bitpack_d bp; |
f8b7e3ec | 1210 | int ecf_flags = 0; |
7bfefa9d | 1211 | |
f1f41a6c | 1212 | caller = cgraph (nodes[streamer_read_hwi (ib)]); |
02774f2d | 1213 | if (caller == NULL || caller->decl == NULL_TREE) |
7bfefa9d | 1214 | internal_error ("bytecode stream: no caller found while reading edge"); |
1215 | ||
799c8711 | 1216 | if (!indirect) |
1217 | { | |
f1f41a6c | 1218 | callee = cgraph (nodes[streamer_read_hwi (ib)]); |
02774f2d | 1219 | if (callee == NULL || callee->decl == NULL_TREE) |
799c8711 | 1220 | internal_error ("bytecode stream: no callee found while reading edge"); |
1221 | } | |
1222 | else | |
1223 | callee = NULL; | |
7bfefa9d | 1224 | |
fc44a215 | 1225 | count = streamer_read_gcov_count (ib); |
7bfefa9d | 1226 | |
7f385784 | 1227 | bp = streamer_read_bitpack (ib); |
7857a7b7 | 1228 | inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_enum, CIF_N_REASONS); |
1229 | stmt_id = bp_unpack_var_len_unsigned (&bp); | |
1230 | freq = (int) bp_unpack_var_len_unsigned (&bp); | |
7bfefa9d | 1231 | |
799c8711 | 1232 | if (indirect) |
0835ad03 | 1233 | edge = cgraph_create_indirect_edge (caller, NULL, 0, count, freq); |
799c8711 | 1234 | else |
0835ad03 | 1235 | edge = cgraph_create_edge (caller, callee, NULL, count, freq); |
799c8711 | 1236 | |
30baba90 | 1237 | edge->indirect_inlining_edge = bp_unpack_value (&bp, 1); |
4d044066 | 1238 | edge->speculative = bp_unpack_value (&bp, 1); |
7bfefa9d | 1239 | edge->lto_stmt_uid = stmt_id; |
1240 | edge->inline_failed = inline_failed; | |
30baba90 | 1241 | edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1); |
1242 | edge->can_throw_external = bp_unpack_value (&bp, 1); | |
f8b7e3ec | 1243 | if (indirect) |
1244 | { | |
30baba90 | 1245 | if (bp_unpack_value (&bp, 1)) |
f8b7e3ec | 1246 | ecf_flags |= ECF_CONST; |
30baba90 | 1247 | if (bp_unpack_value (&bp, 1)) |
f8b7e3ec | 1248 | ecf_flags |= ECF_PURE; |
30baba90 | 1249 | if (bp_unpack_value (&bp, 1)) |
f8b7e3ec | 1250 | ecf_flags |= ECF_NORETURN; |
30baba90 | 1251 | if (bp_unpack_value (&bp, 1)) |
f8b7e3ec | 1252 | ecf_flags |= ECF_MALLOC; |
30baba90 | 1253 | if (bp_unpack_value (&bp, 1)) |
f8b7e3ec | 1254 | ecf_flags |= ECF_NOTHROW; |
30baba90 | 1255 | if (bp_unpack_value (&bp, 1)) |
f8b7e3ec | 1256 | ecf_flags |= ECF_RETURNS_TWICE; |
1257 | edge->indirect_info->ecf_flags = ecf_flags; | |
6a261305 | 1258 | edge->indirect_info->common_target_id = streamer_read_hwi (ib); |
1259 | if (edge->indirect_info->common_target_id) | |
1260 | edge->indirect_info->common_target_probability = streamer_read_hwi (ib); | |
f8b7e3ec | 1261 | } |
7bfefa9d | 1262 | } |
1263 | ||
1264 | ||
1265 | /* Read a cgraph from IB using the info in FILE_DATA. */ | |
1266 | ||
452659af | 1267 | static vec<symtab_node *> |
7bfefa9d | 1268 | input_cgraph_1 (struct lto_file_decl_data *file_data, |
1269 | struct lto_input_block *ib) | |
1270 | { | |
70225339 | 1271 | enum LTO_symtab_tags tag; |
452659af | 1272 | vec<symtab_node *> nodes = vNULL; |
1273 | symtab_node *node; | |
7bfefa9d | 1274 | unsigned i; |
1275 | ||
70225339 | 1276 | tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag); |
0704fb2e | 1277 | order_base = symtab_order; |
7bfefa9d | 1278 | while (tag) |
1279 | { | |
70225339 | 1280 | if (tag == LTO_symtab_edge) |
799c8711 | 1281 | input_edge (ib, nodes, false); |
70225339 | 1282 | else if (tag == LTO_symtab_indirect_edge) |
799c8711 | 1283 | input_edge (ib, nodes, true); |
70225339 | 1284 | else if (tag == LTO_symtab_variable) |
1285 | { | |
02774f2d | 1286 | node = input_varpool_node (file_data, ib); |
f1f41a6c | 1287 | nodes.safe_push (node); |
70225339 | 1288 | lto_symtab_encoder_encode (file_data->symtab_node_encoder, node); |
1289 | } | |
48e1416a | 1290 | else |
7bfefa9d | 1291 | { |
02774f2d | 1292 | node = input_node (file_data, ib, tag, nodes); |
1293 | if (node == NULL || node->decl == NULL_TREE) | |
7bfefa9d | 1294 | internal_error ("bytecode stream: found empty cgraph node"); |
f1f41a6c | 1295 | nodes.safe_push (node); |
70225339 | 1296 | lto_symtab_encoder_encode (file_data->symtab_node_encoder, node); |
7bfefa9d | 1297 | } |
1298 | ||
70225339 | 1299 | tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag); |
7bfefa9d | 1300 | } |
1301 | ||
f1007c72 | 1302 | lto_input_toplevel_asms (file_data, order_base); |
90f477a9 | 1303 | |
70225339 | 1304 | /* AUX pointers should be all non-zero for function nodes read from the stream. */ |
d47cadab | 1305 | #ifdef ENABLE_CHECKING |
f1f41a6c | 1306 | FOR_EACH_VEC_ELT (nodes, i, node) |
02774f2d | 1307 | gcc_assert (node->aux || !is_a <cgraph_node> (node)); |
d47cadab | 1308 | #endif |
f1f41a6c | 1309 | FOR_EACH_VEC_ELT (nodes, i, node) |
7bfefa9d | 1310 | { |
70225339 | 1311 | int ref; |
2dc9831f | 1312 | if (cgraph_node *cnode = dyn_cast <cgraph_node> (node)) |
70225339 | 1313 | { |
2dc9831f | 1314 | ref = (int) (intptr_t) cnode->global.inlined_to; |
70225339 | 1315 | |
1316 | /* We share declaration of builtins, so we may read same node twice. */ | |
02774f2d | 1317 | if (!node->aux) |
70225339 | 1318 | continue; |
02774f2d | 1319 | node->aux = NULL; |
70225339 | 1320 | |
1321 | /* Fixup inlined_to from reference to pointer. */ | |
1322 | if (ref != LCC_NOT_FOUND) | |
f1f41a6c | 1323 | cgraph (node)->global.inlined_to = cgraph (nodes[ref]); |
70225339 | 1324 | else |
2dc9831f | 1325 | cnode->global.inlined_to = NULL; |
70225339 | 1326 | } |
61c2c7b1 | 1327 | |
02774f2d | 1328 | ref = (int) (intptr_t) node->same_comdat_group; |
61c2c7b1 | 1329 | |
1330 | /* Fixup same_comdat_group from reference to pointer. */ | |
1331 | if (ref != LCC_NOT_FOUND) | |
02774f2d | 1332 | node->same_comdat_group = nodes[ref]; |
61c2c7b1 | 1333 | else |
02774f2d | 1334 | node->same_comdat_group = NULL; |
7bfefa9d | 1335 | } |
f1f41a6c | 1336 | FOR_EACH_VEC_ELT (nodes, i, node) |
02774f2d | 1337 | node->aux = is_a <cgraph_node> (node) ? (void *)1 : NULL; |
a238367f | 1338 | return nodes; |
7bfefa9d | 1339 | } |
1340 | ||
8d810329 | 1341 | /* Input ipa_refs. */ |
1342 | ||
1343 | static void | |
1344 | input_refs (struct lto_input_block *ib, | |
452659af | 1345 | vec<symtab_node *> nodes) |
8d810329 | 1346 | { |
1347 | int count; | |
1348 | int idx; | |
1349 | while (true) | |
1350 | { | |
452659af | 1351 | symtab_node *node; |
7f385784 | 1352 | count = streamer_read_uhwi (ib); |
8d810329 | 1353 | if (!count) |
1354 | break; | |
7f385784 | 1355 | idx = streamer_read_uhwi (ib); |
f1f41a6c | 1356 | node = nodes[idx]; |
8d810329 | 1357 | while (count) |
1358 | { | |
eab36a5a | 1359 | input_ref (ib, node, nodes); |
8d810329 | 1360 | count--; |
1361 | } | |
1362 | } | |
1363 | } | |
1364 | ||
a238367f | 1365 | |
6c0782b1 | 1366 | static struct gcov_ctr_summary lto_gcov_summary; |
1367 | ||
1368 | /* Input profile_info from IB. */ | |
1369 | static void | |
c470c5a9 | 1370 | input_profile_summary (struct lto_input_block *ib, |
1371 | struct lto_file_decl_data *file_data) | |
6c0782b1 | 1372 | { |
e3ba12e8 | 1373 | unsigned h_ix; |
1374 | struct bitpack_d bp; | |
7f385784 | 1375 | unsigned int runs = streamer_read_uhwi (ib); |
6c0782b1 | 1376 | if (runs) |
1377 | { | |
c470c5a9 | 1378 | file_data->profile_info.runs = runs; |
9e179a64 | 1379 | file_data->profile_info.sum_max = streamer_read_gcov_count (ib); |
1380 | file_data->profile_info.sum_all = streamer_read_gcov_count (ib); | |
e3ba12e8 | 1381 | |
1382 | memset (file_data->profile_info.histogram, 0, | |
1383 | sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE); | |
1384 | /* Input the bitpack of non-zero histogram indices. */ | |
1385 | bp = streamer_read_bitpack (ib); | |
1386 | /* Read in and unpack the full bitpack, flagging non-zero | |
1387 | histogram entries by setting the num_counters non-zero. */ | |
1388 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
1389 | { | |
1390 | file_data->profile_info.histogram[h_ix].num_counters | |
1391 | = bp_unpack_value (&bp, 1); | |
1392 | } | |
1393 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
1394 | { | |
1395 | if (!file_data->profile_info.histogram[h_ix].num_counters) | |
1396 | continue; | |
1397 | ||
1398 | file_data->profile_info.histogram[h_ix].num_counters | |
9e179a64 | 1399 | = streamer_read_gcov_count (ib); |
e3ba12e8 | 1400 | file_data->profile_info.histogram[h_ix].min_value |
9e179a64 | 1401 | = streamer_read_gcov_count (ib); |
e3ba12e8 | 1402 | file_data->profile_info.histogram[h_ix].cum_value |
9e179a64 | 1403 | = streamer_read_gcov_count (ib); |
e3ba12e8 | 1404 | } |
9e179a64 | 1405 | /* IPA-profile computes hot bb threshold based on cumulated |
1406 | whole program profile. We need to stream it down to ltrans. */ | |
1407 | if (flag_ltrans) | |
1408 | set_hot_bb_threshold (streamer_read_gcov_count (ib)); | |
6c0782b1 | 1409 | } |
1410 | ||
1411 | } | |
7bfefa9d | 1412 | |
c470c5a9 | 1413 | /* Rescale profile summaries to the same number of runs in the whole unit. */ |
1414 | ||
1415 | static void | |
1416 | merge_profile_summaries (struct lto_file_decl_data **file_data_vec) | |
1417 | { | |
1418 | struct lto_file_decl_data *file_data; | |
e3ba12e8 | 1419 | unsigned int j, h_ix; |
c470c5a9 | 1420 | gcov_unsigned_t max_runs = 0; |
1421 | struct cgraph_node *node; | |
1422 | struct cgraph_edge *edge; | |
e3ba12e8 | 1423 | gcov_type saved_sum_all = 0; |
1424 | gcov_ctr_summary *saved_profile_info = 0; | |
1425 | int saved_scale = 0; | |
c470c5a9 | 1426 | |
1427 | /* Find unit with maximal number of runs. If we ever get serious about | |
1428 | roundoff errors, we might also consider computing smallest common | |
1429 | multiply. */ | |
1430 | for (j = 0; (file_data = file_data_vec[j]) != NULL; j++) | |
1431 | if (max_runs < file_data->profile_info.runs) | |
1432 | max_runs = file_data->profile_info.runs; | |
1433 | ||
1434 | if (!max_runs) | |
1435 | return; | |
1436 | ||
1437 | /* Simple overflow check. We probably don't need to support that many train | |
1438 | runs. Such a large value probably imply data corruption anyway. */ | |
1439 | if (max_runs > INT_MAX / REG_BR_PROB_BASE) | |
1440 | { | |
1441 | sorry ("At most %i profile runs is supported. Perhaps corrupted profile?", | |
1442 | INT_MAX / REG_BR_PROB_BASE); | |
1443 | return; | |
1444 | } | |
1445 | ||
1446 | profile_info = <o_gcov_summary; | |
1447 | lto_gcov_summary.runs = max_runs; | |
1448 | lto_gcov_summary.sum_max = 0; | |
e3ba12e8 | 1449 | memset (lto_gcov_summary.histogram, 0, |
1450 | sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE); | |
c470c5a9 | 1451 | |
1452 | /* Rescale all units to the maximal number of runs. | |
1453 | sum_max can not be easily merged, as we have no idea what files come from | |
1454 | the same run. We do not use the info anyway, so leave it 0. */ | |
1455 | for (j = 0; (file_data = file_data_vec[j]) != NULL; j++) | |
1456 | if (file_data->profile_info.runs) | |
1457 | { | |
f9d4b7f4 | 1458 | int scale = GCOV_COMPUTE_SCALE (max_runs, |
1459 | file_data->profile_info.runs); | |
1460 | lto_gcov_summary.sum_max | |
1461 | = MAX (lto_gcov_summary.sum_max, | |
e2bc4ec8 | 1462 | apply_scale (file_data->profile_info.sum_max, scale)); |
f9d4b7f4 | 1463 | lto_gcov_summary.sum_all |
1464 | = MAX (lto_gcov_summary.sum_all, | |
e2bc4ec8 | 1465 | apply_scale (file_data->profile_info.sum_all, scale)); |
e3ba12e8 | 1466 | /* Save a pointer to the profile_info with the largest |
1467 | scaled sum_all and the scale for use in merging the | |
1468 | histogram. */ | |
3672a36a | 1469 | if (!saved_profile_info |
1470 | || lto_gcov_summary.sum_all > saved_sum_all) | |
e3ba12e8 | 1471 | { |
1472 | saved_profile_info = &file_data->profile_info; | |
1473 | saved_sum_all = lto_gcov_summary.sum_all; | |
1474 | saved_scale = scale; | |
1475 | } | |
c470c5a9 | 1476 | } |
1477 | ||
e3ba12e8 | 1478 | gcc_assert (saved_profile_info); |
1479 | ||
1480 | /* Scale up the histogram from the profile that had the largest | |
1481 | scaled sum_all above. */ | |
1482 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
1483 | { | |
1484 | /* Scale up the min value as we did the corresponding sum_all | |
1485 | above. Use that to find the new histogram index. */ | |
f9d4b7f4 | 1486 | gcov_type scaled_min |
e2bc4ec8 | 1487 | = apply_scale (saved_profile_info->histogram[h_ix].min_value, |
1488 | saved_scale); | |
3672a36a | 1489 | /* The new index may be shared with another scaled histogram entry, |
1490 | so we need to account for a non-zero histogram entry at new_ix. */ | |
e3ba12e8 | 1491 | unsigned new_ix = gcov_histo_index (scaled_min); |
3672a36a | 1492 | lto_gcov_summary.histogram[new_ix].min_value |
e90a82bd | 1493 | = (lto_gcov_summary.histogram[new_ix].num_counters |
1494 | ? MIN (lto_gcov_summary.histogram[new_ix].min_value, scaled_min) | |
1495 | : scaled_min); | |
e3ba12e8 | 1496 | /* Some of the scaled counter values would ostensibly need to be placed |
1497 | into different (larger) histogram buckets, but we keep things simple | |
1498 | here and place the scaled cumulative counter value in the bucket | |
1499 | corresponding to the scaled minimum counter value. */ | |
1500 | lto_gcov_summary.histogram[new_ix].cum_value | |
e2bc4ec8 | 1501 | += apply_scale (saved_profile_info->histogram[h_ix].cum_value, |
1502 | saved_scale); | |
e3ba12e8 | 1503 | lto_gcov_summary.histogram[new_ix].num_counters |
3672a36a | 1504 | += saved_profile_info->histogram[h_ix].num_counters; |
e3ba12e8 | 1505 | } |
1506 | ||
c470c5a9 | 1507 | /* Watch roundoff errors. */ |
1508 | if (lto_gcov_summary.sum_max < max_runs) | |
1509 | lto_gcov_summary.sum_max = max_runs; | |
1510 | ||
1511 | /* If merging already happent at WPA time, we are done. */ | |
1512 | if (flag_ltrans) | |
1513 | return; | |
1514 | ||
1515 | /* Now compute count_materialization_scale of each node. | |
1516 | During LTRANS we already have values of count_materialization_scale | |
1517 | computed, so just update them. */ | |
7c455d87 | 1518 | FOR_EACH_FUNCTION (node) |
02774f2d | 1519 | if (node->lto_file_data |
1520 | && node->lto_file_data->profile_info.runs) | |
c470c5a9 | 1521 | { |
1522 | int scale; | |
555491e2 | 1523 | |
e3ba12e8 | 1524 | scale = RDIV (node->count_materialization_scale * max_runs, |
02774f2d | 1525 | node->lto_file_data->profile_info.runs); |
c470c5a9 | 1526 | node->count_materialization_scale = scale; |
1527 | if (scale < 0) | |
1528 | fatal_error ("Profile information in %s corrupted", | |
1529 | file_data->file_name); | |
1530 | ||
1531 | if (scale == REG_BR_PROB_BASE) | |
1532 | continue; | |
1533 | for (edge = node->callees; edge; edge = edge->next_callee) | |
e2bc4ec8 | 1534 | edge->count = apply_scale (edge->count, scale); |
1535 | node->count = apply_scale (node->count, scale); | |
c470c5a9 | 1536 | } |
1537 | } | |
1538 | ||
02b699d5 | 1539 | /* Input and merge the symtab from each of the .o files passed to |
7bfefa9d | 1540 | lto1. */ |
1541 | ||
1542 | void | |
02b699d5 | 1543 | input_symtab (void) |
7bfefa9d | 1544 | { |
1545 | struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); | |
1546 | struct lto_file_decl_data *file_data; | |
1547 | unsigned int j = 0; | |
1548 | struct cgraph_node *node; | |
1549 | ||
1550 | while ((file_data = file_data_vec[j++])) | |
1551 | { | |
1552 | const char *data; | |
1553 | size_t len; | |
1554 | struct lto_input_block *ib; | |
452659af | 1555 | vec<symtab_node *> nodes; |
7bfefa9d | 1556 | |
02b699d5 | 1557 | ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes, |
7bfefa9d | 1558 | &data, &len); |
fd30d60a | 1559 | if (!ib) |
bf776685 | 1560 | fatal_error ("cannot find LTO cgraph in %s", file_data->file_name); |
c470c5a9 | 1561 | input_profile_summary (ib, file_data); |
b8925abd | 1562 | file_data->symtab_node_encoder = lto_symtab_encoder_new (true); |
a238367f | 1563 | nodes = input_cgraph_1 (file_data, ib); |
02b699d5 | 1564 | lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes, |
7bfefa9d | 1565 | ib, data, len); |
48e1416a | 1566 | |
8d810329 | 1567 | ib = lto_create_simple_input_block (file_data, LTO_section_refs, |
1568 | &data, &len); | |
fd30d60a | 1569 | if (!ib) |
9af5ce0c | 1570 | fatal_error ("cannot find LTO section refs in %s", |
1571 | file_data->file_name); | |
70225339 | 1572 | input_refs (ib, nodes); |
8d810329 | 1573 | lto_destroy_simple_input_block (file_data, LTO_section_refs, |
1574 | ib, data, len); | |
1bf41320 | 1575 | if (flag_ltrans) |
1576 | input_cgraph_opt_summary (nodes); | |
f1f41a6c | 1577 | nodes.release (); |
48e1416a | 1578 | } |
30f589a5 | 1579 | |
c470c5a9 | 1580 | merge_profile_summaries (file_data_vec); |
8515a84d | 1581 | get_working_sets (); |
e3ba12e8 | 1582 | |
7bfefa9d | 1583 | |
1584 | /* Clear out the aux field that was used to store enough state to | |
1585 | tell which nodes should be overwritten. */ | |
7c455d87 | 1586 | FOR_EACH_FUNCTION (node) |
7bfefa9d | 1587 | { |
1588 | /* Some nodes may have been created by cgraph_node. This | |
1589 | happens when the callgraph contains nested functions. If the | |
1590 | node for the parent function was never emitted to the gimple | |
1591 | file, cgraph_node will create a node for it when setting the | |
1592 | context of the nested function. */ | |
02774f2d | 1593 | if (node->lto_file_data) |
1594 | node->aux = NULL; | |
7bfefa9d | 1595 | } |
1596 | } | |
1bf41320 | 1597 | |
1598 | /* True when we need optimization summary for NODE. */ | |
1599 | ||
1600 | static int | |
eab36a5a | 1601 | output_cgraph_opt_summary_p (struct cgraph_node *node) |
1bf41320 | 1602 | { |
2b36ac0b | 1603 | return (node->clone_of |
1604 | && (node->clone.tree_map | |
1605 | || node->clone.args_to_skip | |
1606 | || node->clone.combined_args_to_skip)); | |
1bf41320 | 1607 | } |
1608 | ||
9bab6a70 | 1609 | /* Output optimization summary for EDGE to OB. */ |
1610 | static void | |
d4e80e2b | 1611 | output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED, |
1612 | struct cgraph_edge *edge ATTRIBUTE_UNUSED) | |
9bab6a70 | 1613 | { |
9bab6a70 | 1614 | } |
1615 | ||
1bf41320 | 1616 | /* Output optimization summary for NODE to OB. */ |
1617 | ||
1618 | static void | |
1619 | output_node_opt_summary (struct output_block *ob, | |
2b36ac0b | 1620 | struct cgraph_node *node, |
eab36a5a | 1621 | lto_symtab_encoder_t encoder) |
1bf41320 | 1622 | { |
1623 | unsigned int index; | |
1624 | bitmap_iterator bi; | |
1625 | struct ipa_replace_map *map; | |
30baba90 | 1626 | struct bitpack_d bp; |
1bf41320 | 1627 | int i; |
9bab6a70 | 1628 | struct cgraph_edge *e; |
1bf41320 | 1629 | |
29413d70 | 1630 | if (node->clone.args_to_skip) |
1631 | { | |
7f385784 | 1632 | streamer_write_uhwi (ob, bitmap_count_bits (node->clone.args_to_skip)); |
29413d70 | 1633 | EXECUTE_IF_SET_IN_BITMAP (node->clone.args_to_skip, 0, index, bi) |
7f385784 | 1634 | streamer_write_uhwi (ob, index); |
29413d70 | 1635 | } |
1636 | else | |
7f385784 | 1637 | streamer_write_uhwi (ob, 0); |
29413d70 | 1638 | if (node->clone.combined_args_to_skip) |
1639 | { | |
7f385784 | 1640 | streamer_write_uhwi (ob, bitmap_count_bits (node->clone.combined_args_to_skip)); |
29413d70 | 1641 | EXECUTE_IF_SET_IN_BITMAP (node->clone.combined_args_to_skip, 0, index, bi) |
7f385784 | 1642 | streamer_write_uhwi (ob, index); |
29413d70 | 1643 | } |
1644 | else | |
7f385784 | 1645 | streamer_write_uhwi (ob, 0); |
f1f41a6c | 1646 | streamer_write_uhwi (ob, vec_safe_length (node->clone.tree_map)); |
1647 | FOR_EACH_VEC_SAFE_ELT (node->clone.tree_map, i, map) | |
1bf41320 | 1648 | { |
1bf41320 | 1649 | /* At the moment we assume all old trees to be PARM_DECLs, because we have no |
1650 | mechanism to store function local declarations into summaries. */ | |
79e830ee | 1651 | gcc_assert (!map->old_tree); |
1652 | streamer_write_uhwi (ob, map->parm_num); | |
8e7408e3 | 1653 | gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION); |
515cf651 | 1654 | stream_write_tree (ob, map->new_tree, true); |
30baba90 | 1655 | bp = bitpack_create (ob->main_stream); |
1656 | bp_pack_value (&bp, map->replace_p, 1); | |
1657 | bp_pack_value (&bp, map->ref_p, 1); | |
7f385784 | 1658 | streamer_write_bitpack (&bp); |
1bf41320 | 1659 | } |
2b36ac0b | 1660 | |
02774f2d | 1661 | if (lto_symtab_encoder_in_partition_p (encoder, node)) |
2b36ac0b | 1662 | { |
1663 | for (e = node->callees; e; e = e->next_callee) | |
1664 | output_edge_opt_summary (ob, e); | |
1665 | for (e = node->indirect_calls; e; e = e->next_callee) | |
1666 | output_edge_opt_summary (ob, e); | |
1667 | } | |
1bf41320 | 1668 | } |
1669 | ||
1670 | /* Output optimization summaries stored in callgraph. | |
1671 | At the moment it is the clone info structure. */ | |
1672 | ||
1673 | static void | |
eab36a5a | 1674 | output_cgraph_opt_summary (void) |
1bf41320 | 1675 | { |
1bf41320 | 1676 | int i, n_nodes; |
70225339 | 1677 | lto_symtab_encoder_t encoder; |
1bf41320 | 1678 | struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum); |
1679 | unsigned count = 0; | |
1680 | ||
1681 | ob->cgraph_node = NULL; | |
70225339 | 1682 | encoder = ob->decl_state->symtab_node_encoder; |
1683 | n_nodes = lto_symtab_encoder_size (encoder); | |
1bf41320 | 1684 | for (i = 0; i < n_nodes; i++) |
2dc9831f | 1685 | { |
452659af | 1686 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
2dc9831f | 1687 | cgraph_node *cnode = dyn_cast <cgraph_node> (node); |
1688 | if (cnode && output_cgraph_opt_summary_p (cnode)) | |
1689 | count++; | |
1690 | } | |
7f385784 | 1691 | streamer_write_uhwi (ob, count); |
1bf41320 | 1692 | for (i = 0; i < n_nodes; i++) |
1693 | { | |
452659af | 1694 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
2dc9831f | 1695 | cgraph_node *cnode = dyn_cast <cgraph_node> (node); |
1696 | if (cnode && output_cgraph_opt_summary_p (cnode)) | |
1bf41320 | 1697 | { |
7f385784 | 1698 | streamer_write_uhwi (ob, i); |
2dc9831f | 1699 | output_node_opt_summary (ob, cnode, encoder); |
1bf41320 | 1700 | } |
1701 | } | |
1702 | produce_asm (ob, NULL); | |
1703 | destroy_output_block (ob); | |
1704 | } | |
1705 | ||
9bab6a70 | 1706 | /* Input optimisation summary of EDGE. */ |
1707 | ||
1708 | static void | |
d4e80e2b | 1709 | input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED, |
1710 | struct lto_input_block *ib_main ATTRIBUTE_UNUSED) | |
9bab6a70 | 1711 | { |
9bab6a70 | 1712 | } |
1713 | ||
1714 | /* Input optimisation summary of NODE. */ | |
1bf41320 | 1715 | |
1716 | static void | |
1717 | input_node_opt_summary (struct cgraph_node *node, | |
1718 | struct lto_input_block *ib_main, | |
1719 | struct data_in *data_in) | |
1720 | { | |
1721 | int i; | |
1722 | int count; | |
1723 | int bit; | |
30baba90 | 1724 | struct bitpack_d bp; |
9bab6a70 | 1725 | struct cgraph_edge *e; |
1bf41320 | 1726 | |
7f385784 | 1727 | count = streamer_read_uhwi (ib_main); |
1bf41320 | 1728 | if (count) |
1729 | node->clone.args_to_skip = BITMAP_GGC_ALLOC (); | |
1730 | for (i = 0; i < count; i++) | |
1731 | { | |
7f385784 | 1732 | bit = streamer_read_uhwi (ib_main); |
1bf41320 | 1733 | bitmap_set_bit (node->clone.args_to_skip, bit); |
1734 | } | |
7f385784 | 1735 | count = streamer_read_uhwi (ib_main); |
1bf41320 | 1736 | if (count) |
1737 | node->clone.combined_args_to_skip = BITMAP_GGC_ALLOC (); | |
1738 | for (i = 0; i < count; i++) | |
1739 | { | |
7f385784 | 1740 | bit = streamer_read_uhwi (ib_main); |
1bf41320 | 1741 | bitmap_set_bit (node->clone.combined_args_to_skip, bit); |
1742 | } | |
7f385784 | 1743 | count = streamer_read_uhwi (ib_main); |
1bf41320 | 1744 | for (i = 0; i < count; i++) |
1745 | { | |
ba72912a | 1746 | struct ipa_replace_map *map = ggc_alloc_ipa_replace_map (); |
1bf41320 | 1747 | |
f1f41a6c | 1748 | vec_safe_push (node->clone.tree_map, map); |
7f385784 | 1749 | map->parm_num = streamer_read_uhwi (ib_main); |
1bf41320 | 1750 | map->old_tree = NULL; |
515cf651 | 1751 | map->new_tree = stream_read_tree (ib_main, data_in); |
7f385784 | 1752 | bp = streamer_read_bitpack (ib_main); |
30baba90 | 1753 | map->replace_p = bp_unpack_value (&bp, 1); |
1754 | map->ref_p = bp_unpack_value (&bp, 1); | |
1bf41320 | 1755 | } |
9bab6a70 | 1756 | for (e = node->callees; e; e = e->next_callee) |
1757 | input_edge_opt_summary (e, ib_main); | |
1758 | for (e = node->indirect_calls; e; e = e->next_callee) | |
1759 | input_edge_opt_summary (e, ib_main); | |
1bf41320 | 1760 | } |
1761 | ||
1762 | /* Read section in file FILE_DATA of length LEN with data DATA. */ | |
1763 | ||
1764 | static void | |
1765 | input_cgraph_opt_section (struct lto_file_decl_data *file_data, | |
f1f41a6c | 1766 | const char *data, size_t len, |
452659af | 1767 | vec<symtab_node *> nodes) |
1bf41320 | 1768 | { |
1769 | const struct lto_function_header *header = | |
1770 | (const struct lto_function_header *) data; | |
949e5786 | 1771 | const int cfg_offset = sizeof (struct lto_function_header); |
1772 | const int main_offset = cfg_offset + header->cfg_size; | |
1773 | const int string_offset = main_offset + header->main_size; | |
1bf41320 | 1774 | struct data_in *data_in; |
1775 | struct lto_input_block ib_main; | |
1776 | unsigned int i; | |
1777 | unsigned int count; | |
1778 | ||
1779 | LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0, | |
1780 | header->main_size); | |
1781 | ||
1782 | data_in = | |
1783 | lto_data_in_create (file_data, (const char *) data + string_offset, | |
1e094109 | 1784 | header->string_size, vNULL); |
7f385784 | 1785 | count = streamer_read_uhwi (&ib_main); |
1bf41320 | 1786 | |
1787 | for (i = 0; i < count; i++) | |
1788 | { | |
7f385784 | 1789 | int ref = streamer_read_uhwi (&ib_main); |
f1f41a6c | 1790 | input_node_opt_summary (cgraph (nodes[ref]), |
1bf41320 | 1791 | &ib_main, data_in); |
1792 | } | |
783bc09c | 1793 | lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data, |
1bf41320 | 1794 | len); |
1795 | lto_data_in_delete (data_in); | |
1796 | } | |
1797 | ||
1798 | /* Input optimization summary of cgraph. */ | |
1799 | ||
1800 | static void | |
452659af | 1801 | input_cgraph_opt_summary (vec<symtab_node *> nodes) |
1bf41320 | 1802 | { |
1803 | struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); | |
1804 | struct lto_file_decl_data *file_data; | |
1805 | unsigned int j = 0; | |
1806 | ||
1807 | while ((file_data = file_data_vec[j++])) | |
1808 | { | |
1809 | size_t len; | |
1810 | const char *data = | |
1811 | lto_get_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, | |
1812 | &len); | |
1813 | ||
1814 | if (data) | |
1815 | input_cgraph_opt_section (file_data, data, len, nodes); | |
1816 | } | |
1817 | } |