]>
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; |
b9e2d290 | 392 | struct ipa_opt_pass_d *pass; |
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 | } |
e43059ff | 584 | bp_pack_value (&bp, node->need_bounds_init, 1); |
7f385784 | 585 | streamer_write_bitpack (&bp); |
02774f2d | 586 | if (node->same_comdat_group && !boundary_p) |
933b10c6 | 587 | { |
70225339 | 588 | ref = lto_symtab_encoder_lookup (encoder, |
02774f2d | 589 | node->same_comdat_group); |
933b10c6 | 590 | gcc_assert (ref != LCC_NOT_FOUND); |
591 | } | |
592 | else | |
593 | ref = LCC_NOT_FOUND; | |
7f385784 | 594 | streamer_write_hwi_stream (ob->main_stream, ref); |
595 | streamer_write_enum (ob->main_stream, ld_plugin_symbol_resolution, | |
02774f2d | 596 | LDPR_NUM_KNOWN, node->resolution); |
0cddb138 | 597 | } |
598 | ||
8d810329 | 599 | /* Output the varpool NODE to OB. |
600 | If NODE is not in SET, then NODE is a boundary. */ | |
601 | ||
602 | static void | |
603 | lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref, | |
70225339 | 604 | lto_symtab_encoder_t encoder) |
8d810329 | 605 | { |
30baba90 | 606 | struct bitpack_d bp; |
70225339 | 607 | int nref; |
4d044066 | 608 | int uid = ref->lto_stmt_uid; |
609 | struct cgraph_node *node; | |
70225339 | 610 | |
30baba90 | 611 | bp = bitpack_create (ob->main_stream); |
30baba90 | 612 | bp_pack_value (&bp, ref->use, 2); |
4d044066 | 613 | bp_pack_value (&bp, ref->speculative, 1); |
7f385784 | 614 | streamer_write_bitpack (&bp); |
70225339 | 615 | nref = lto_symtab_encoder_lookup (encoder, ref->referred); |
616 | gcc_assert (nref != LCC_NOT_FOUND); | |
617 | streamer_write_hwi_stream (ob->main_stream, nref); | |
4d044066 | 618 | |
619 | node = dyn_cast <cgraph_node> (ref->referring); | |
620 | if (node) | |
621 | { | |
622 | if (ref->stmt) | |
623 | uid = gimple_uid (ref->stmt) + 1; | |
624 | streamer_write_hwi_stream (ob->main_stream, uid); | |
625 | } | |
8d810329 | 626 | } |
627 | ||
6c0782b1 | 628 | /* Stream out profile_summary to OB. */ |
629 | ||
630 | static void | |
631 | output_profile_summary (struct lto_simple_output_block *ob) | |
632 | { | |
e3ba12e8 | 633 | unsigned h_ix; |
634 | struct bitpack_d bp; | |
635 | ||
6c0782b1 | 636 | if (profile_info) |
637 | { | |
e3ba12e8 | 638 | /* We do not output num and run_max, they are not used by |
639 | GCC profile feedback and they are difficult to merge from multiple | |
640 | units. */ | |
6c0782b1 | 641 | gcc_assert (profile_info->runs); |
7f385784 | 642 | streamer_write_uhwi_stream (ob->main_stream, profile_info->runs); |
9e179a64 | 643 | streamer_write_gcov_count_stream (ob->main_stream, profile_info->sum_max); |
e3ba12e8 | 644 | |
645 | /* sum_all is needed for computing the working set with the | |
646 | histogram. */ | |
9e179a64 | 647 | streamer_write_gcov_count_stream (ob->main_stream, profile_info->sum_all); |
e3ba12e8 | 648 | |
649 | /* Create and output a bitpack of non-zero histogram entries indices. */ | |
650 | bp = bitpack_create (ob->main_stream); | |
651 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
652 | bp_pack_value (&bp, profile_info->histogram[h_ix].num_counters > 0, 1); | |
653 | streamer_write_bitpack (&bp); | |
654 | /* Now stream out only those non-zero entries. */ | |
655 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
656 | { | |
657 | if (!profile_info->histogram[h_ix].num_counters) | |
658 | continue; | |
9e179a64 | 659 | streamer_write_gcov_count_stream (ob->main_stream, |
e3ba12e8 | 660 | profile_info->histogram[h_ix].num_counters); |
9e179a64 | 661 | streamer_write_gcov_count_stream (ob->main_stream, |
e3ba12e8 | 662 | profile_info->histogram[h_ix].min_value); |
9e179a64 | 663 | streamer_write_gcov_count_stream (ob->main_stream, |
e3ba12e8 | 664 | profile_info->histogram[h_ix].cum_value); |
9e179a64 | 665 | } |
666 | /* IPA-profile computes hot bb threshold based on cumulated | |
667 | whole program profile. We need to stream it down to ltrans. */ | |
668 | if (flag_wpa) | |
669 | streamer_write_gcov_count_stream (ob->main_stream, | |
670 | get_hot_bb_threshold ()); | |
6c0782b1 | 671 | } |
672 | else | |
7f385784 | 673 | streamer_write_uhwi_stream (ob->main_stream, 0); |
6c0782b1 | 674 | } |
675 | ||
799c8711 | 676 | /* Output all callees or indirect outgoing edges. EDGE must be the first such |
677 | edge. */ | |
678 | ||
679 | static void | |
680 | output_outgoing_cgraph_edges (struct cgraph_edge *edge, | |
681 | struct lto_simple_output_block *ob, | |
70225339 | 682 | lto_symtab_encoder_t encoder) |
799c8711 | 683 | { |
684 | if (!edge) | |
685 | return; | |
686 | ||
687 | /* Output edges in backward direction, so the reconstructed callgraph match | |
688 | and it is easy to associate call sites in the IPA pass summaries. */ | |
689 | while (edge->next_callee) | |
690 | edge = edge->next_callee; | |
691 | for (; edge; edge = edge->prev_callee) | |
692 | lto_output_edge (ob, edge, encoder); | |
693 | } | |
694 | ||
8d810329 | 695 | /* Output the part of the cgraph in SET. */ |
696 | ||
697 | static void | |
eab36a5a | 698 | output_refs (lto_symtab_encoder_t encoder) |
8d810329 | 699 | { |
eab36a5a | 700 | lto_symtab_encoder_iterator lsei; |
8d810329 | 701 | struct lto_simple_output_block *ob; |
702 | int count; | |
703 | struct ipa_ref *ref; | |
704 | int i; | |
705 | ||
706 | ob = lto_create_simple_output_block (LTO_section_refs); | |
707 | ||
eab36a5a | 708 | for (lsei = lsei_start_in_partition (encoder); !lsei_end_p (lsei); |
709 | lsei_next_in_partition (&lsei)) | |
8d810329 | 710 | { |
452659af | 711 | symtab_node *node = lsei_node (lsei); |
8d810329 | 712 | |
02774f2d | 713 | count = ipa_ref_list_nreferences (&node->ref_list); |
8d810329 | 714 | if (count) |
715 | { | |
6a1c0403 | 716 | streamer_write_gcov_count_stream (ob->main_stream, count); |
7f385784 | 717 | streamer_write_uhwi_stream (ob->main_stream, |
eab36a5a | 718 | lto_symtab_encoder_lookup (encoder, node)); |
02774f2d | 719 | for (i = 0; ipa_ref_list_reference_iterate (&node->ref_list, |
7d0d0ce1 | 720 | i, ref); i++) |
70225339 | 721 | lto_output_ref (ob, ref, encoder); |
8d810329 | 722 | } |
723 | } | |
724 | ||
7f385784 | 725 | streamer_write_uhwi_stream (ob->main_stream, 0); |
8d810329 | 726 | |
727 | lto_destroy_simple_output_block (ob); | |
728 | } | |
729 | ||
724462b0 | 730 | /* Add NODE into encoder as well as nodes it is cloned from. |
731 | Do it in a way so clones appear first. */ | |
732 | ||
733 | static void | |
734 | add_node_to (lto_symtab_encoder_t encoder, struct cgraph_node *node, | |
735 | bool include_body) | |
736 | { | |
737 | if (node->clone_of) | |
738 | add_node_to (encoder, node->clone_of, include_body); | |
739 | else if (include_body) | |
740 | lto_set_symtab_encoder_encode_body (encoder, node); | |
02774f2d | 741 | lto_symtab_encoder_encode (encoder, node); |
724462b0 | 742 | } |
743 | ||
744 | /* Add all references in LIST to encoders. */ | |
745 | ||
746 | static void | |
747 | add_references (lto_symtab_encoder_t encoder, | |
748 | struct ipa_ref_list *list) | |
749 | { | |
750 | int i; | |
751 | struct ipa_ref *ref; | |
752 | for (i = 0; ipa_ref_list_reference_iterate (list, i, ref); i++) | |
2dc9831f | 753 | if (is_a <cgraph_node> (ref->referred)) |
724462b0 | 754 | add_node_to (encoder, ipa_ref_node (ref), false); |
755 | else | |
c9aa6453 | 756 | lto_symtab_encoder_encode (encoder, ref->referred); |
724462b0 | 757 | } |
758 | ||
759 | /* Find all symbols we want to stream into given partition and insert them | |
760 | to encoders. | |
761 | ||
762 | The function actually replaces IN_ENCODER by new one. The reason is that | |
763 | streaming code needs clone's origin to be streamed before clone. This | |
764 | means that we need to insert the nodes in specific order. This order is | |
765 | ignored by the partitioning logic earlier. */ | |
766 | ||
767 | lto_symtab_encoder_t | |
768 | compute_ltrans_boundary (lto_symtab_encoder_t in_encoder) | |
7bfefa9d | 769 | { |
770 | struct cgraph_node *node; | |
7bfefa9d | 771 | struct cgraph_edge *edge; |
d97be713 | 772 | int i; |
70225339 | 773 | lto_symtab_encoder_t encoder; |
5cf7e051 | 774 | lto_symtab_encoder_iterator lsei; |
b855a50e | 775 | struct pointer_set_t *reachable_call_targets = pointer_set_create (); |
6c0782b1 | 776 | |
b8925abd | 777 | encoder = lto_symtab_encoder_new (false); |
7bfefa9d | 778 | |
5cf7e051 | 779 | /* Go over all entries in the IN_ENCODER and duplicate them to |
780 | ENCODER. At the same time insert masters of clones so | |
781 | every master appears before clone. */ | |
782 | for (lsei = lsei_start_function_in_partition (in_encoder); | |
783 | !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei)) | |
7bfefa9d | 784 | { |
5cf7e051 | 785 | node = lsei_cgraph_node (lsei); |
02b2818c | 786 | add_node_to (encoder, node, true); |
02774f2d | 787 | lto_set_symtab_encoder_in_partition (encoder, node); |
788 | add_references (encoder, &node->ref_list); | |
4df870fd | 789 | /* For proper debug info, we need to ship the origins, too. */ |
02774f2d | 790 | if (DECL_ABSTRACT_ORIGIN (node->decl)) |
4df870fd | 791 | { |
792 | struct cgraph_node *origin_node | |
02774f2d | 793 | = cgraph_get_node (DECL_ABSTRACT_ORIGIN (node->decl)); |
4df870fd | 794 | add_node_to (encoder, origin_node, true); |
795 | } | |
7bfefa9d | 796 | } |
5cf7e051 | 797 | for (lsei = lsei_start_variable_in_partition (in_encoder); |
798 | !lsei_end_p (lsei); lsei_next_variable_in_partition (&lsei)) | |
a238367f | 799 | { |
5cf7e051 | 800 | struct varpool_node *vnode = lsei_varpool_node (lsei); |
48669653 | 801 | |
02774f2d | 802 | lto_set_symtab_encoder_in_partition (encoder, vnode); |
70225339 | 803 | lto_set_symtab_encoder_encode_initializer (encoder, vnode); |
02774f2d | 804 | add_references (encoder, &vnode->ref_list); |
4df870fd | 805 | /* For proper debug info, we need to ship the origins, too. */ |
02774f2d | 806 | if (DECL_ABSTRACT_ORIGIN (vnode->decl)) |
4df870fd | 807 | { |
808 | struct varpool_node *origin_node | |
02774f2d | 809 | = varpool_get_node (DECL_ABSTRACT_ORIGIN (node->decl)); |
810 | lto_set_symtab_encoder_in_partition (encoder, origin_node); | |
4df870fd | 811 | } |
a238367f | 812 | } |
a238367f | 813 | /* Pickle in also the initializer of all referenced readonly variables |
814 | to help folding. Constant pool variables are not shared, so we must | |
815 | pickle those too. */ | |
70225339 | 816 | for (i = 0; i < lto_symtab_encoder_size (encoder); i++) |
a238367f | 817 | { |
452659af | 818 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
2dc9831f | 819 | if (varpool_node *vnode = dyn_cast <varpool_node> (node)) |
a238367f | 820 | { |
df8d3e89 | 821 | if (!lto_symtab_encoder_encode_initializer_p (encoder, |
822 | vnode) | |
02774f2d | 823 | && ctor_for_folding (vnode->decl) != error_mark_node) |
70225339 | 824 | { |
825 | lto_set_symtab_encoder_encode_initializer (encoder, vnode); | |
02774f2d | 826 | add_references (encoder, &vnode->ref_list); |
70225339 | 827 | } |
70225339 | 828 | } |
a238367f | 829 | } |
7bfefa9d | 830 | |
831 | /* Go over all the nodes again to include callees that are not in | |
832 | SET. */ | |
5cf7e051 | 833 | for (lsei = lsei_start_function_in_partition (encoder); |
834 | !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei)) | |
7bfefa9d | 835 | { |
5cf7e051 | 836 | node = lsei_cgraph_node (lsei); |
7bfefa9d | 837 | for (edge = node->callees; edge; edge = edge->next_callee) |
838 | { | |
839 | struct cgraph_node *callee = edge->callee; | |
02774f2d | 840 | if (!lto_symtab_encoder_in_partition_p (encoder, callee)) |
7bfefa9d | 841 | { |
842 | /* We should have moved all the inlines. */ | |
843 | gcc_assert (!callee->global.inlined_to); | |
02b2818c | 844 | add_node_to (encoder, callee, false); |
7bfefa9d | 845 | } |
846 | } | |
b855a50e | 847 | /* Add all possible targets for late devirtualization. */ |
848 | if (flag_devirtualize) | |
849 | for (edge = node->indirect_calls; edge; edge = edge->next_callee) | |
850 | if (edge->indirect_info->polymorphic) | |
851 | { | |
852 | unsigned int i; | |
853 | void *cache_token; | |
854 | bool final; | |
855 | vec <cgraph_node *>targets | |
856 | = possible_polymorphic_call_targets | |
857 | (edge, &final, &cache_token); | |
858 | if (!pointer_set_insert (reachable_call_targets, | |
859 | cache_token)) | |
860 | { | |
9af5ce0c | 861 | for (i = 0; i < targets.length (); i++) |
b855a50e | 862 | { |
863 | struct cgraph_node *callee = targets[i]; | |
864 | ||
865 | /* Adding an external declarations into the unit serves | |
866 | no purpose and just increases its boundary. */ | |
02774f2d | 867 | if (callee->definition |
b855a50e | 868 | && !lto_symtab_encoder_in_partition_p |
02774f2d | 869 | (encoder, callee)) |
b855a50e | 870 | { |
871 | gcc_assert (!callee->global.inlined_to); | |
872 | add_node_to (encoder, callee, false); | |
873 | } | |
874 | } | |
875 | } | |
876 | } | |
7bfefa9d | 877 | } |
b855a50e | 878 | lto_symtab_encoder_delete (in_encoder); |
879 | pointer_set_destroy (reachable_call_targets); | |
880 | return encoder; | |
d97be713 | 881 | } |
882 | ||
02b699d5 | 883 | /* Output the part of the symtab in SET and VSET. */ |
d97be713 | 884 | |
885 | void | |
eab36a5a | 886 | output_symtab (void) |
d97be713 | 887 | { |
888 | struct cgraph_node *node; | |
889 | struct lto_simple_output_block *ob; | |
eab36a5a | 890 | lto_symtab_encoder_iterator lsei; |
d97be713 | 891 | int i, n_nodes; |
70225339 | 892 | lto_symtab_encoder_t encoder; |
14c5d106 | 893 | static bool asm_nodes_output = false; |
d97be713 | 894 | |
1bf41320 | 895 | if (flag_wpa) |
eab36a5a | 896 | output_cgraph_opt_summary (); |
1bf41320 | 897 | |
02b699d5 | 898 | ob = lto_create_simple_output_block (LTO_section_symtab_nodes); |
d97be713 | 899 | |
900 | output_profile_summary (ob); | |
901 | ||
902 | /* An encoder for cgraph nodes should have been created by | |
903 | ipa_write_summaries_1. */ | |
70225339 | 904 | gcc_assert (ob->decl_state->symtab_node_encoder); |
905 | encoder = ob->decl_state->symtab_node_encoder; | |
d97be713 | 906 | |
08843223 | 907 | /* Write out the nodes. We must first output a node and then its clones, |
908 | otherwise at a time reading back the node there would be nothing to clone | |
909 | from. */ | |
70225339 | 910 | n_nodes = lto_symtab_encoder_size (encoder); |
7bfefa9d | 911 | for (i = 0; i < n_nodes; i++) |
912 | { | |
452659af | 913 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
2dc9831f | 914 | if (cgraph_node *cnode = dyn_cast <cgraph_node> (node)) |
915 | lto_output_node (ob, cnode, encoder); | |
70225339 | 916 | else |
eab36a5a | 917 | lto_output_varpool_node (ob, varpool (node), encoder); |
70225339 | 918 | |
7bfefa9d | 919 | } |
920 | ||
7bfefa9d | 921 | /* Go over the nodes in SET again to write edges. */ |
eab36a5a | 922 | for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei); |
923 | lsei_next_function_in_partition (&lsei)) | |
7bfefa9d | 924 | { |
eab36a5a | 925 | node = lsei_cgraph_node (lsei); |
799c8711 | 926 | output_outgoing_cgraph_edges (node->callees, ob, encoder); |
927 | output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder); | |
7bfefa9d | 928 | } |
929 | ||
7f385784 | 930 | streamer_write_uhwi_stream (ob->main_stream, 0); |
7bfefa9d | 931 | |
65d1b157 | 932 | lto_destroy_simple_output_block (ob); |
933 | ||
2b7c48a1 | 934 | /* Emit toplevel asms. |
935 | When doing WPA we must output every asm just once. Since we do not partition asm | |
936 | nodes at all, output them to first output. This is kind of hack, but should work | |
937 | well. */ | |
938 | if (!asm_nodes_output) | |
90f477a9 | 939 | { |
2b7c48a1 | 940 | asm_nodes_output = true; |
65d1b157 | 941 | lto_output_toplevel_asms (); |
90f477a9 | 942 | } |
943 | ||
eab36a5a | 944 | output_refs (encoder); |
7bfefa9d | 945 | } |
946 | ||
7bfefa9d | 947 | /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS, |
948 | STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize | |
949 | NODE or to replace the values in it, for instance because the first | |
950 | time we saw it, the function body was not available but now it | |
951 | is. BP is a bitpack with all the bitflags for NODE read from the | |
952 | stream. */ | |
953 | ||
954 | static void | |
955 | input_overwrite_node (struct lto_file_decl_data *file_data, | |
956 | struct cgraph_node *node, | |
70225339 | 957 | enum LTO_symtab_tags tag, |
7857a7b7 | 958 | struct bitpack_d *bp) |
7bfefa9d | 959 | { |
02774f2d | 960 | node->aux = (void *) tag; |
961 | node->lto_file_data = file_data; | |
7bfefa9d | 962 | |
963 | node->local.local = bp_unpack_value (bp, 1); | |
02774f2d | 964 | node->externally_visible = bp_unpack_value (bp, 1); |
965 | node->definition = bp_unpack_value (bp, 1); | |
c8d92fc1 | 966 | node->local.versionable = bp_unpack_value (bp, 1); |
3c97c75d | 967 | node->local.can_change_signature = bp_unpack_value (bp, 1); |
7bfefa9d | 968 | node->local.redefined_extern_inline = bp_unpack_value (bp, 1); |
02774f2d | 969 | node->force_output = bp_unpack_value (bp, 1); |
970 | node->forced_by_abi = bp_unpack_value (bp, 1); | |
971 | node->unique_name = bp_unpack_value (bp, 1); | |
972 | node->address_taken = bp_unpack_value (bp, 1); | |
973 | node->used_from_other_partition = bp_unpack_value (bp, 1); | |
7bfefa9d | 974 | node->lowered = bp_unpack_value (bp, 1); |
02774f2d | 975 | node->analyzed = tag == LTO_symtab_analyzed_node; |
976 | node->in_other_partition = bp_unpack_value (bp, 1); | |
977 | if (node->in_other_partition | |
cdc58a66 | 978 | /* Avoid updating decl when we are seeing just inline clone. |
979 | When inlining function that has functions already inlined into it, | |
980 | we produce clones of inline clones. | |
981 | ||
982 | WPA partitioning might put each clone into different unit and | |
983 | we might end up streaming inline clone from other partition | |
984 | to support clone we are interested in. */ | |
985 | && (!node->clone_of | |
02774f2d | 986 | || node->clone_of->decl != node->decl)) |
eb0bc81b | 987 | { |
02774f2d | 988 | DECL_EXTERNAL (node->decl) = 1; |
989 | TREE_STATIC (node->decl) = 0; | |
eb0bc81b | 990 | } |
02774f2d | 991 | node->alias = bp_unpack_value (bp, 1); |
992 | node->weakref = bp_unpack_value (bp, 1); | |
125b6d78 | 993 | node->frequency = (enum node_frequency)bp_unpack_value (bp, 2); |
0f9fb931 | 994 | node->only_called_at_startup = bp_unpack_value (bp, 1); |
995 | node->only_called_at_exit = bp_unpack_value (bp, 1); | |
ea0e88d1 | 996 | node->tm_clone = bp_unpack_value (bp, 1); |
91bf9d9a | 997 | node->thunk.thunk_p = bp_unpack_value (bp, 1); |
02774f2d | 998 | node->resolution = bp_unpack_enum (bp, ld_plugin_symbol_resolution, |
7857a7b7 | 999 | LDPR_NUM_KNOWN); |
7bfefa9d | 1000 | } |
1001 | ||
48669653 | 1002 | /* Return string alias is alias of. */ |
1003 | ||
1004 | static tree | |
1005 | get_alias_symbol (tree decl) | |
1006 | { | |
1007 | tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)); | |
48669653 | 1008 | return get_identifier (TREE_STRING_POINTER |
1009 | (TREE_VALUE (TREE_VALUE (alias)))); | |
1010 | } | |
1011 | ||
48e1416a | 1012 | /* Read a node from input_block IB. TAG is the node's tag just read. |
7bfefa9d | 1013 | Return the node read or overwriten. */ |
48e1416a | 1014 | |
7bfefa9d | 1015 | static struct cgraph_node * |
1016 | input_node (struct lto_file_decl_data *file_data, | |
1017 | struct lto_input_block *ib, | |
70225339 | 1018 | enum LTO_symtab_tags tag, |
452659af | 1019 | vec<symtab_node *> nodes) |
7bfefa9d | 1020 | { |
3ea50c01 | 1021 | gcc::pass_manager *passes = g->get_passes (); |
7bfefa9d | 1022 | tree fn_decl; |
1023 | struct cgraph_node *node; | |
30baba90 | 1024 | struct bitpack_d bp; |
7bfefa9d | 1025 | unsigned decl_index; |
61c2c7b1 | 1026 | int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND; |
02b2818c | 1027 | int clone_ref; |
f1007c72 | 1028 | int order; |
b9e2d290 | 1029 | int i, count; |
7bfefa9d | 1030 | |
f1007c72 | 1031 | order = streamer_read_hwi (ib) + order_base; |
7f385784 | 1032 | clone_ref = streamer_read_hwi (ib); |
7bfefa9d | 1033 | |
7f385784 | 1034 | decl_index = streamer_read_uhwi (ib); |
7bfefa9d | 1035 | fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index); |
1036 | ||
02b2818c | 1037 | if (clone_ref != LCC_NOT_FOUND) |
1038 | { | |
f1f41a6c | 1039 | node = cgraph_clone_node (cgraph (nodes[clone_ref]), fn_decl, |
1040 | 0, CGRAPH_FREQ_BASE, false, | |
48f42a9a | 1041 | vNULL, false, NULL); |
02b2818c | 1042 | } |
7bfefa9d | 1043 | else |
9e9c3e92 | 1044 | { |
1045 | /* Declaration of functions can be already merged with a declaration | |
1046 | from other input file. We keep cgraph unmerged until after streaming | |
1047 | of ipa passes is done. Alays forcingly create a fresh node. */ | |
1048 | node = cgraph_create_empty_node (); | |
02774f2d | 1049 | node->decl = fn_decl; |
1050 | symtab_register_node (node); | |
9e9c3e92 | 1051 | } |
7bfefa9d | 1052 | |
02774f2d | 1053 | node->order = order; |
0704fb2e | 1054 | if (order >= symtab_order) |
1055 | symtab_order = order + 1; | |
f1007c72 | 1056 | |
fc44a215 | 1057 | node->count = streamer_read_gcov_count (ib); |
7f385784 | 1058 | node->count_materialization_scale = streamer_read_hwi (ib); |
48e1416a | 1059 | |
b9e2d290 | 1060 | count = streamer_read_hwi (ib); |
1e094109 | 1061 | node->ipa_transforms_to_apply = vNULL; |
b9e2d290 | 1062 | for (i = 0; i < count; i++) |
1063 | { | |
1064 | struct opt_pass *pass; | |
1065 | int pid = streamer_read_hwi (ib); | |
1066 | ||
3ea50c01 | 1067 | gcc_assert (pid < passes->passes_by_id_size); |
1068 | pass = passes->passes_by_id[pid]; | |
f1f41a6c | 1069 | node->ipa_transforms_to_apply.safe_push ((struct ipa_opt_pass_d *) pass); |
b9e2d290 | 1070 | } |
1071 | ||
70225339 | 1072 | if (tag == LTO_symtab_analyzed_node) |
7f385784 | 1073 | ref = streamer_read_hwi (ib); |
7bfefa9d | 1074 | |
7f385784 | 1075 | ref2 = streamer_read_hwi (ib); |
7bfefa9d | 1076 | |
1077 | /* Make sure that we have not read this node before. Nodes that | |
1078 | have already been read will have their tag stored in the 'aux' | |
1079 | field. Since built-in functions can be referenced in multiple | |
1080 | functions, they are expected to be read more than once. */ | |
02774f2d | 1081 | if (node->aux && !DECL_BUILT_IN (node->decl)) |
7bfefa9d | 1082 | internal_error ("bytecode stream: found multiple instances of cgraph " |
15c999e3 | 1083 | "node with uid %d", node->uid); |
7bfefa9d | 1084 | |
38fe12e3 | 1085 | node->tp_first_run = streamer_read_uhwi (ib); |
1086 | ||
7f385784 | 1087 | bp = streamer_read_bitpack (ib); |
38fe12e3 | 1088 | |
7857a7b7 | 1089 | input_overwrite_node (file_data, node, tag, &bp); |
7bfefa9d | 1090 | |
7bfefa9d | 1091 | /* Store a reference for now, and fix up later to be a pointer. */ |
1092 | node->global.inlined_to = (cgraph_node_ptr) (intptr_t) ref; | |
1093 | ||
61c2c7b1 | 1094 | /* Store a reference for now, and fix up later to be a pointer. */ |
452659af | 1095 | node->same_comdat_group = (symtab_node *) (intptr_t) ref2; |
61c2c7b1 | 1096 | |
91bf9d9a | 1097 | if (node->thunk.thunk_p) |
1098 | { | |
7f385784 | 1099 | int type = streamer_read_uhwi (ib); |
1100 | HOST_WIDE_INT fixed_offset = streamer_read_uhwi (ib); | |
1101 | HOST_WIDE_INT virtual_value = streamer_read_uhwi (ib); | |
91bf9d9a | 1102 | |
91bf9d9a | 1103 | node->thunk.fixed_offset = fixed_offset; |
1104 | node->thunk.this_adjusting = (type & 2); | |
1105 | node->thunk.virtual_value = virtual_value; | |
1106 | node->thunk.virtual_offset_p = (type & 4); | |
91bf9d9a | 1107 | } |
02774f2d | 1108 | if (node->alias && !node->analyzed && node->weakref) |
1109 | node->alias_target = get_alias_symbol (node->decl); | |
6a261305 | 1110 | node->profile_id = streamer_read_hwi (ib); |
7bfefa9d | 1111 | return node; |
1112 | } | |
1113 | ||
0cddb138 | 1114 | /* Read a node from input_block IB. TAG is the node's tag just read. |
1115 | Return the node read or overwriten. */ | |
1116 | ||
1117 | static struct varpool_node * | |
1118 | input_varpool_node (struct lto_file_decl_data *file_data, | |
1119 | struct lto_input_block *ib) | |
1120 | { | |
1121 | int decl_index; | |
1122 | tree var_decl; | |
1123 | struct varpool_node *node; | |
30baba90 | 1124 | struct bitpack_d bp; |
933b10c6 | 1125 | int ref = LCC_NOT_FOUND; |
f1007c72 | 1126 | int order; |
0cddb138 | 1127 | |
f1007c72 | 1128 | order = streamer_read_hwi (ib) + order_base; |
7f385784 | 1129 | decl_index = streamer_read_uhwi (ib); |
0cddb138 | 1130 | var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index); |
9e9c3e92 | 1131 | |
1132 | /* Declaration of functions can be already merged with a declaration | |
1133 | from other input file. We keep cgraph unmerged until after streaming | |
1134 | of ipa passes is done. Alays forcingly create a fresh node. */ | |
1135 | node = varpool_create_empty_node (); | |
02774f2d | 1136 | node->decl = var_decl; |
1137 | symtab_register_node (node); | |
9e9c3e92 | 1138 | |
02774f2d | 1139 | node->order = order; |
0704fb2e | 1140 | if (order >= symtab_order) |
1141 | symtab_order = order + 1; | |
02774f2d | 1142 | node->lto_file_data = file_data; |
0cddb138 | 1143 | |
7f385784 | 1144 | bp = streamer_read_bitpack (ib); |
02774f2d | 1145 | node->externally_visible = bp_unpack_value (&bp, 1); |
1146 | node->force_output = bp_unpack_value (&bp, 1); | |
1147 | node->forced_by_abi = bp_unpack_value (&bp, 1); | |
1148 | node->unique_name = bp_unpack_value (&bp, 1); | |
1149 | node->definition = bp_unpack_value (&bp, 1); | |
1150 | node->alias = bp_unpack_value (&bp, 1); | |
1151 | node->weakref = bp_unpack_value (&bp, 1); | |
1152 | node->analyzed = bp_unpack_value (&bp, 1); | |
1153 | node->used_from_other_partition = bp_unpack_value (&bp, 1); | |
1154 | node->in_other_partition = bp_unpack_value (&bp, 1); | |
e43059ff | 1155 | node->need_bounds_init = bp_unpack_value (&bp, 1); |
02774f2d | 1156 | if (node->in_other_partition) |
eb0bc81b | 1157 | { |
02774f2d | 1158 | DECL_EXTERNAL (node->decl) = 1; |
1159 | TREE_STATIC (node->decl) = 0; | |
eb0bc81b | 1160 | } |
02774f2d | 1161 | if (node->alias && !node->analyzed && node->weakref) |
1162 | node->alias_target = get_alias_symbol (node->decl); | |
7f385784 | 1163 | ref = streamer_read_hwi (ib); |
933b10c6 | 1164 | /* Store a reference for now, and fix up later to be a pointer. */ |
452659af | 1165 | node->same_comdat_group = (symtab_node *) (intptr_t) ref; |
02774f2d | 1166 | node->resolution = streamer_read_enum (ib, ld_plugin_symbol_resolution, |
7d0d0ce1 | 1167 | LDPR_NUM_KNOWN); |
e0eaac80 | 1168 | |
0cddb138 | 1169 | return node; |
1170 | } | |
1171 | ||
8d810329 | 1172 | /* Read a node from input_block IB. TAG is the node's tag just read. |
1173 | Return the node read or overwriten. */ | |
1174 | ||
1175 | static void | |
1176 | input_ref (struct lto_input_block *ib, | |
452659af | 1177 | symtab_node *referring_node, |
1178 | vec<symtab_node *> nodes) | |
8d810329 | 1179 | { |
452659af | 1180 | symtab_node *node = NULL; |
30baba90 | 1181 | struct bitpack_d bp; |
8d810329 | 1182 | enum ipa_ref_use use; |
4d044066 | 1183 | bool speculative; |
1184 | struct ipa_ref *ref; | |
8d810329 | 1185 | |
7f385784 | 1186 | bp = streamer_read_bitpack (ib); |
30baba90 | 1187 | use = (enum ipa_ref_use) bp_unpack_value (&bp, 2); |
4d044066 | 1188 | speculative = (enum ipa_ref_use) bp_unpack_value (&bp, 1); |
f1f41a6c | 1189 | node = nodes[streamer_read_hwi (ib)]; |
4d044066 | 1190 | ref = ipa_record_reference (referring_node, node, use, NULL); |
1191 | ref->speculative = speculative; | |
1192 | if (is_a <cgraph_node> (referring_node)) | |
1193 | ref->lto_stmt_uid = streamer_read_hwi (ib); | |
8d810329 | 1194 | } |
7bfefa9d | 1195 | |
799c8711 | 1196 | /* Read an edge from IB. NODES points to a vector of previously read nodes for |
1197 | decoding caller and callee of the edge to be read. If INDIRECT is true, the | |
1198 | edge being read is indirect (in the sense that it has | |
1199 | indirect_unknown_callee set). */ | |
7bfefa9d | 1200 | |
1201 | static void | |
452659af | 1202 | input_edge (struct lto_input_block *ib, vec<symtab_node *> nodes, |
799c8711 | 1203 | bool indirect) |
7bfefa9d | 1204 | { |
1205 | struct cgraph_node *caller, *callee; | |
1206 | struct cgraph_edge *edge; | |
1207 | unsigned int stmt_id; | |
1208 | gcov_type count; | |
1209 | int freq; | |
7bfefa9d | 1210 | cgraph_inline_failed_t inline_failed; |
30baba90 | 1211 | struct bitpack_d bp; |
f8b7e3ec | 1212 | int ecf_flags = 0; |
7bfefa9d | 1213 | |
f1f41a6c | 1214 | caller = cgraph (nodes[streamer_read_hwi (ib)]); |
02774f2d | 1215 | if (caller == NULL || caller->decl == NULL_TREE) |
7bfefa9d | 1216 | internal_error ("bytecode stream: no caller found while reading edge"); |
1217 | ||
799c8711 | 1218 | if (!indirect) |
1219 | { | |
f1f41a6c | 1220 | callee = cgraph (nodes[streamer_read_hwi (ib)]); |
02774f2d | 1221 | if (callee == NULL || callee->decl == NULL_TREE) |
799c8711 | 1222 | internal_error ("bytecode stream: no callee found while reading edge"); |
1223 | } | |
1224 | else | |
1225 | callee = NULL; | |
7bfefa9d | 1226 | |
fc44a215 | 1227 | count = streamer_read_gcov_count (ib); |
7bfefa9d | 1228 | |
7f385784 | 1229 | bp = streamer_read_bitpack (ib); |
7857a7b7 | 1230 | inline_failed = bp_unpack_enum (&bp, cgraph_inline_failed_enum, CIF_N_REASONS); |
1231 | stmt_id = bp_unpack_var_len_unsigned (&bp); | |
1232 | freq = (int) bp_unpack_var_len_unsigned (&bp); | |
7bfefa9d | 1233 | |
799c8711 | 1234 | if (indirect) |
0835ad03 | 1235 | edge = cgraph_create_indirect_edge (caller, NULL, 0, count, freq); |
799c8711 | 1236 | else |
0835ad03 | 1237 | edge = cgraph_create_edge (caller, callee, NULL, count, freq); |
799c8711 | 1238 | |
30baba90 | 1239 | edge->indirect_inlining_edge = bp_unpack_value (&bp, 1); |
4d044066 | 1240 | edge->speculative = bp_unpack_value (&bp, 1); |
7bfefa9d | 1241 | edge->lto_stmt_uid = stmt_id; |
1242 | edge->inline_failed = inline_failed; | |
30baba90 | 1243 | edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1); |
1244 | edge->can_throw_external = bp_unpack_value (&bp, 1); | |
f8b7e3ec | 1245 | if (indirect) |
1246 | { | |
30baba90 | 1247 | if (bp_unpack_value (&bp, 1)) |
f8b7e3ec | 1248 | ecf_flags |= ECF_CONST; |
30baba90 | 1249 | if (bp_unpack_value (&bp, 1)) |
f8b7e3ec | 1250 | ecf_flags |= ECF_PURE; |
30baba90 | 1251 | if (bp_unpack_value (&bp, 1)) |
f8b7e3ec | 1252 | ecf_flags |= ECF_NORETURN; |
30baba90 | 1253 | if (bp_unpack_value (&bp, 1)) |
f8b7e3ec | 1254 | ecf_flags |= ECF_MALLOC; |
30baba90 | 1255 | if (bp_unpack_value (&bp, 1)) |
f8b7e3ec | 1256 | ecf_flags |= ECF_NOTHROW; |
30baba90 | 1257 | if (bp_unpack_value (&bp, 1)) |
f8b7e3ec | 1258 | ecf_flags |= ECF_RETURNS_TWICE; |
1259 | edge->indirect_info->ecf_flags = ecf_flags; | |
6a261305 | 1260 | edge->indirect_info->common_target_id = streamer_read_hwi (ib); |
1261 | if (edge->indirect_info->common_target_id) | |
1262 | edge->indirect_info->common_target_probability = streamer_read_hwi (ib); | |
f8b7e3ec | 1263 | } |
7bfefa9d | 1264 | } |
1265 | ||
1266 | ||
1267 | /* Read a cgraph from IB using the info in FILE_DATA. */ | |
1268 | ||
452659af | 1269 | static vec<symtab_node *> |
7bfefa9d | 1270 | input_cgraph_1 (struct lto_file_decl_data *file_data, |
1271 | struct lto_input_block *ib) | |
1272 | { | |
70225339 | 1273 | enum LTO_symtab_tags tag; |
452659af | 1274 | vec<symtab_node *> nodes = vNULL; |
1275 | symtab_node *node; | |
7bfefa9d | 1276 | unsigned i; |
1277 | ||
70225339 | 1278 | tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag); |
0704fb2e | 1279 | order_base = symtab_order; |
7bfefa9d | 1280 | while (tag) |
1281 | { | |
70225339 | 1282 | if (tag == LTO_symtab_edge) |
799c8711 | 1283 | input_edge (ib, nodes, false); |
70225339 | 1284 | else if (tag == LTO_symtab_indirect_edge) |
799c8711 | 1285 | input_edge (ib, nodes, true); |
70225339 | 1286 | else if (tag == LTO_symtab_variable) |
1287 | { | |
02774f2d | 1288 | node = input_varpool_node (file_data, ib); |
f1f41a6c | 1289 | nodes.safe_push (node); |
70225339 | 1290 | lto_symtab_encoder_encode (file_data->symtab_node_encoder, node); |
1291 | } | |
48e1416a | 1292 | else |
7bfefa9d | 1293 | { |
02774f2d | 1294 | node = input_node (file_data, ib, tag, nodes); |
1295 | if (node == NULL || node->decl == NULL_TREE) | |
7bfefa9d | 1296 | internal_error ("bytecode stream: found empty cgraph node"); |
f1f41a6c | 1297 | nodes.safe_push (node); |
70225339 | 1298 | lto_symtab_encoder_encode (file_data->symtab_node_encoder, node); |
7bfefa9d | 1299 | } |
1300 | ||
70225339 | 1301 | tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag); |
7bfefa9d | 1302 | } |
1303 | ||
f1007c72 | 1304 | lto_input_toplevel_asms (file_data, order_base); |
90f477a9 | 1305 | |
70225339 | 1306 | /* AUX pointers should be all non-zero for function nodes read from the stream. */ |
d47cadab | 1307 | #ifdef ENABLE_CHECKING |
f1f41a6c | 1308 | FOR_EACH_VEC_ELT (nodes, i, node) |
02774f2d | 1309 | gcc_assert (node->aux || !is_a <cgraph_node> (node)); |
d47cadab | 1310 | #endif |
f1f41a6c | 1311 | FOR_EACH_VEC_ELT (nodes, i, node) |
7bfefa9d | 1312 | { |
70225339 | 1313 | int ref; |
2dc9831f | 1314 | if (cgraph_node *cnode = dyn_cast <cgraph_node> (node)) |
70225339 | 1315 | { |
2dc9831f | 1316 | ref = (int) (intptr_t) cnode->global.inlined_to; |
70225339 | 1317 | |
1318 | /* We share declaration of builtins, so we may read same node twice. */ | |
02774f2d | 1319 | if (!node->aux) |
70225339 | 1320 | continue; |
02774f2d | 1321 | node->aux = NULL; |
70225339 | 1322 | |
1323 | /* Fixup inlined_to from reference to pointer. */ | |
1324 | if (ref != LCC_NOT_FOUND) | |
f1f41a6c | 1325 | cgraph (node)->global.inlined_to = cgraph (nodes[ref]); |
70225339 | 1326 | else |
2dc9831f | 1327 | cnode->global.inlined_to = NULL; |
70225339 | 1328 | } |
61c2c7b1 | 1329 | |
02774f2d | 1330 | ref = (int) (intptr_t) node->same_comdat_group; |
61c2c7b1 | 1331 | |
1332 | /* Fixup same_comdat_group from reference to pointer. */ | |
1333 | if (ref != LCC_NOT_FOUND) | |
02774f2d | 1334 | node->same_comdat_group = nodes[ref]; |
61c2c7b1 | 1335 | else |
02774f2d | 1336 | node->same_comdat_group = NULL; |
7bfefa9d | 1337 | } |
f1f41a6c | 1338 | FOR_EACH_VEC_ELT (nodes, i, node) |
02774f2d | 1339 | node->aux = is_a <cgraph_node> (node) ? (void *)1 : NULL; |
a238367f | 1340 | return nodes; |
7bfefa9d | 1341 | } |
1342 | ||
8d810329 | 1343 | /* Input ipa_refs. */ |
1344 | ||
1345 | static void | |
1346 | input_refs (struct lto_input_block *ib, | |
452659af | 1347 | vec<symtab_node *> nodes) |
8d810329 | 1348 | { |
1349 | int count; | |
1350 | int idx; | |
1351 | while (true) | |
1352 | { | |
452659af | 1353 | symtab_node *node; |
7f385784 | 1354 | count = streamer_read_uhwi (ib); |
8d810329 | 1355 | if (!count) |
1356 | break; | |
7f385784 | 1357 | idx = streamer_read_uhwi (ib); |
f1f41a6c | 1358 | node = nodes[idx]; |
8d810329 | 1359 | while (count) |
1360 | { | |
eab36a5a | 1361 | input_ref (ib, node, nodes); |
8d810329 | 1362 | count--; |
1363 | } | |
1364 | } | |
1365 | } | |
1366 | ||
a238367f | 1367 | |
6c0782b1 | 1368 | static struct gcov_ctr_summary lto_gcov_summary; |
1369 | ||
1370 | /* Input profile_info from IB. */ | |
1371 | static void | |
c470c5a9 | 1372 | input_profile_summary (struct lto_input_block *ib, |
1373 | struct lto_file_decl_data *file_data) | |
6c0782b1 | 1374 | { |
e3ba12e8 | 1375 | unsigned h_ix; |
1376 | struct bitpack_d bp; | |
7f385784 | 1377 | unsigned int runs = streamer_read_uhwi (ib); |
6c0782b1 | 1378 | if (runs) |
1379 | { | |
c470c5a9 | 1380 | file_data->profile_info.runs = runs; |
9e179a64 | 1381 | file_data->profile_info.sum_max = streamer_read_gcov_count (ib); |
1382 | file_data->profile_info.sum_all = streamer_read_gcov_count (ib); | |
e3ba12e8 | 1383 | |
1384 | memset (file_data->profile_info.histogram, 0, | |
1385 | sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE); | |
1386 | /* Input the bitpack of non-zero histogram indices. */ | |
1387 | bp = streamer_read_bitpack (ib); | |
1388 | /* Read in and unpack the full bitpack, flagging non-zero | |
1389 | histogram entries by setting the num_counters non-zero. */ | |
1390 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
1391 | { | |
1392 | file_data->profile_info.histogram[h_ix].num_counters | |
1393 | = bp_unpack_value (&bp, 1); | |
1394 | } | |
1395 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
1396 | { | |
1397 | if (!file_data->profile_info.histogram[h_ix].num_counters) | |
1398 | continue; | |
1399 | ||
1400 | file_data->profile_info.histogram[h_ix].num_counters | |
9e179a64 | 1401 | = streamer_read_gcov_count (ib); |
e3ba12e8 | 1402 | file_data->profile_info.histogram[h_ix].min_value |
9e179a64 | 1403 | = streamer_read_gcov_count (ib); |
e3ba12e8 | 1404 | file_data->profile_info.histogram[h_ix].cum_value |
9e179a64 | 1405 | = streamer_read_gcov_count (ib); |
e3ba12e8 | 1406 | } |
9e179a64 | 1407 | /* IPA-profile computes hot bb threshold based on cumulated |
1408 | whole program profile. We need to stream it down to ltrans. */ | |
1409 | if (flag_ltrans) | |
1410 | set_hot_bb_threshold (streamer_read_gcov_count (ib)); | |
6c0782b1 | 1411 | } |
1412 | ||
1413 | } | |
7bfefa9d | 1414 | |
c470c5a9 | 1415 | /* Rescale profile summaries to the same number of runs in the whole unit. */ |
1416 | ||
1417 | static void | |
1418 | merge_profile_summaries (struct lto_file_decl_data **file_data_vec) | |
1419 | { | |
1420 | struct lto_file_decl_data *file_data; | |
e3ba12e8 | 1421 | unsigned int j, h_ix; |
c470c5a9 | 1422 | gcov_unsigned_t max_runs = 0; |
1423 | struct cgraph_node *node; | |
1424 | struct cgraph_edge *edge; | |
e3ba12e8 | 1425 | gcov_type saved_sum_all = 0; |
1426 | gcov_ctr_summary *saved_profile_info = 0; | |
1427 | int saved_scale = 0; | |
c470c5a9 | 1428 | |
1429 | /* Find unit with maximal number of runs. If we ever get serious about | |
1430 | roundoff errors, we might also consider computing smallest common | |
1431 | multiply. */ | |
1432 | for (j = 0; (file_data = file_data_vec[j]) != NULL; j++) | |
1433 | if (max_runs < file_data->profile_info.runs) | |
1434 | max_runs = file_data->profile_info.runs; | |
1435 | ||
1436 | if (!max_runs) | |
1437 | return; | |
1438 | ||
1439 | /* Simple overflow check. We probably don't need to support that many train | |
1440 | runs. Such a large value probably imply data corruption anyway. */ | |
1441 | if (max_runs > INT_MAX / REG_BR_PROB_BASE) | |
1442 | { | |
1443 | sorry ("At most %i profile runs is supported. Perhaps corrupted profile?", | |
1444 | INT_MAX / REG_BR_PROB_BASE); | |
1445 | return; | |
1446 | } | |
1447 | ||
1448 | profile_info = <o_gcov_summary; | |
1449 | lto_gcov_summary.runs = max_runs; | |
1450 | lto_gcov_summary.sum_max = 0; | |
e3ba12e8 | 1451 | memset (lto_gcov_summary.histogram, 0, |
1452 | sizeof (gcov_bucket_type) * GCOV_HISTOGRAM_SIZE); | |
c470c5a9 | 1453 | |
1454 | /* Rescale all units to the maximal number of runs. | |
1455 | sum_max can not be easily merged, as we have no idea what files come from | |
1456 | the same run. We do not use the info anyway, so leave it 0. */ | |
1457 | for (j = 0; (file_data = file_data_vec[j]) != NULL; j++) | |
1458 | if (file_data->profile_info.runs) | |
1459 | { | |
f9d4b7f4 | 1460 | int scale = GCOV_COMPUTE_SCALE (max_runs, |
1461 | file_data->profile_info.runs); | |
1462 | lto_gcov_summary.sum_max | |
1463 | = MAX (lto_gcov_summary.sum_max, | |
e2bc4ec8 | 1464 | apply_scale (file_data->profile_info.sum_max, scale)); |
f9d4b7f4 | 1465 | lto_gcov_summary.sum_all |
1466 | = MAX (lto_gcov_summary.sum_all, | |
e2bc4ec8 | 1467 | apply_scale (file_data->profile_info.sum_all, scale)); |
e3ba12e8 | 1468 | /* Save a pointer to the profile_info with the largest |
1469 | scaled sum_all and the scale for use in merging the | |
1470 | histogram. */ | |
3672a36a | 1471 | if (!saved_profile_info |
1472 | || lto_gcov_summary.sum_all > saved_sum_all) | |
e3ba12e8 | 1473 | { |
1474 | saved_profile_info = &file_data->profile_info; | |
1475 | saved_sum_all = lto_gcov_summary.sum_all; | |
1476 | saved_scale = scale; | |
1477 | } | |
c470c5a9 | 1478 | } |
1479 | ||
e3ba12e8 | 1480 | gcc_assert (saved_profile_info); |
1481 | ||
1482 | /* Scale up the histogram from the profile that had the largest | |
1483 | scaled sum_all above. */ | |
1484 | for (h_ix = 0; h_ix < GCOV_HISTOGRAM_SIZE; h_ix++) | |
1485 | { | |
1486 | /* Scale up the min value as we did the corresponding sum_all | |
1487 | above. Use that to find the new histogram index. */ | |
f9d4b7f4 | 1488 | gcov_type scaled_min |
e2bc4ec8 | 1489 | = apply_scale (saved_profile_info->histogram[h_ix].min_value, |
1490 | saved_scale); | |
3672a36a | 1491 | /* The new index may be shared with another scaled histogram entry, |
1492 | so we need to account for a non-zero histogram entry at new_ix. */ | |
e3ba12e8 | 1493 | unsigned new_ix = gcov_histo_index (scaled_min); |
3672a36a | 1494 | lto_gcov_summary.histogram[new_ix].min_value |
e90a82bd | 1495 | = (lto_gcov_summary.histogram[new_ix].num_counters |
1496 | ? MIN (lto_gcov_summary.histogram[new_ix].min_value, scaled_min) | |
1497 | : scaled_min); | |
e3ba12e8 | 1498 | /* Some of the scaled counter values would ostensibly need to be placed |
1499 | into different (larger) histogram buckets, but we keep things simple | |
1500 | here and place the scaled cumulative counter value in the bucket | |
1501 | corresponding to the scaled minimum counter value. */ | |
1502 | lto_gcov_summary.histogram[new_ix].cum_value | |
e2bc4ec8 | 1503 | += apply_scale (saved_profile_info->histogram[h_ix].cum_value, |
1504 | saved_scale); | |
e3ba12e8 | 1505 | lto_gcov_summary.histogram[new_ix].num_counters |
3672a36a | 1506 | += saved_profile_info->histogram[h_ix].num_counters; |
e3ba12e8 | 1507 | } |
1508 | ||
c470c5a9 | 1509 | /* Watch roundoff errors. */ |
1510 | if (lto_gcov_summary.sum_max < max_runs) | |
1511 | lto_gcov_summary.sum_max = max_runs; | |
1512 | ||
1513 | /* If merging already happent at WPA time, we are done. */ | |
1514 | if (flag_ltrans) | |
1515 | return; | |
1516 | ||
1517 | /* Now compute count_materialization_scale of each node. | |
1518 | During LTRANS we already have values of count_materialization_scale | |
1519 | computed, so just update them. */ | |
7c455d87 | 1520 | FOR_EACH_FUNCTION (node) |
02774f2d | 1521 | if (node->lto_file_data |
1522 | && node->lto_file_data->profile_info.runs) | |
c470c5a9 | 1523 | { |
1524 | int scale; | |
555491e2 | 1525 | |
e3ba12e8 | 1526 | scale = RDIV (node->count_materialization_scale * max_runs, |
02774f2d | 1527 | node->lto_file_data->profile_info.runs); |
c470c5a9 | 1528 | node->count_materialization_scale = scale; |
1529 | if (scale < 0) | |
1530 | fatal_error ("Profile information in %s corrupted", | |
1531 | file_data->file_name); | |
1532 | ||
1533 | if (scale == REG_BR_PROB_BASE) | |
1534 | continue; | |
1535 | for (edge = node->callees; edge; edge = edge->next_callee) | |
e2bc4ec8 | 1536 | edge->count = apply_scale (edge->count, scale); |
1537 | node->count = apply_scale (node->count, scale); | |
c470c5a9 | 1538 | } |
1539 | } | |
1540 | ||
02b699d5 | 1541 | /* Input and merge the symtab from each of the .o files passed to |
7bfefa9d | 1542 | lto1. */ |
1543 | ||
1544 | void | |
02b699d5 | 1545 | input_symtab (void) |
7bfefa9d | 1546 | { |
1547 | struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); | |
1548 | struct lto_file_decl_data *file_data; | |
1549 | unsigned int j = 0; | |
1550 | struct cgraph_node *node; | |
1551 | ||
1552 | while ((file_data = file_data_vec[j++])) | |
1553 | { | |
1554 | const char *data; | |
1555 | size_t len; | |
1556 | struct lto_input_block *ib; | |
452659af | 1557 | vec<symtab_node *> nodes; |
7bfefa9d | 1558 | |
02b699d5 | 1559 | ib = lto_create_simple_input_block (file_data, LTO_section_symtab_nodes, |
7bfefa9d | 1560 | &data, &len); |
fd30d60a | 1561 | if (!ib) |
bf776685 | 1562 | fatal_error ("cannot find LTO cgraph in %s", file_data->file_name); |
c470c5a9 | 1563 | input_profile_summary (ib, file_data); |
b8925abd | 1564 | file_data->symtab_node_encoder = lto_symtab_encoder_new (true); |
a238367f | 1565 | nodes = input_cgraph_1 (file_data, ib); |
02b699d5 | 1566 | lto_destroy_simple_input_block (file_data, LTO_section_symtab_nodes, |
7bfefa9d | 1567 | ib, data, len); |
48e1416a | 1568 | |
8d810329 | 1569 | ib = lto_create_simple_input_block (file_data, LTO_section_refs, |
1570 | &data, &len); | |
fd30d60a | 1571 | if (!ib) |
9af5ce0c | 1572 | fatal_error ("cannot find LTO section refs in %s", |
1573 | file_data->file_name); | |
70225339 | 1574 | input_refs (ib, nodes); |
8d810329 | 1575 | lto_destroy_simple_input_block (file_data, LTO_section_refs, |
1576 | ib, data, len); | |
1bf41320 | 1577 | if (flag_ltrans) |
1578 | input_cgraph_opt_summary (nodes); | |
f1f41a6c | 1579 | nodes.release (); |
48e1416a | 1580 | } |
30f589a5 | 1581 | |
c470c5a9 | 1582 | merge_profile_summaries (file_data_vec); |
8515a84d | 1583 | get_working_sets (); |
e3ba12e8 | 1584 | |
7bfefa9d | 1585 | |
1586 | /* Clear out the aux field that was used to store enough state to | |
1587 | tell which nodes should be overwritten. */ | |
7c455d87 | 1588 | FOR_EACH_FUNCTION (node) |
7bfefa9d | 1589 | { |
1590 | /* Some nodes may have been created by cgraph_node. This | |
1591 | happens when the callgraph contains nested functions. If the | |
1592 | node for the parent function was never emitted to the gimple | |
1593 | file, cgraph_node will create a node for it when setting the | |
1594 | context of the nested function. */ | |
02774f2d | 1595 | if (node->lto_file_data) |
1596 | node->aux = NULL; | |
7bfefa9d | 1597 | } |
1598 | } | |
1bf41320 | 1599 | |
1600 | /* True when we need optimization summary for NODE. */ | |
1601 | ||
1602 | static int | |
eab36a5a | 1603 | output_cgraph_opt_summary_p (struct cgraph_node *node) |
1bf41320 | 1604 | { |
2b36ac0b | 1605 | return (node->clone_of |
1606 | && (node->clone.tree_map | |
1607 | || node->clone.args_to_skip | |
1608 | || node->clone.combined_args_to_skip)); | |
1bf41320 | 1609 | } |
1610 | ||
9bab6a70 | 1611 | /* Output optimization summary for EDGE to OB. */ |
1612 | static void | |
d4e80e2b | 1613 | output_edge_opt_summary (struct output_block *ob ATTRIBUTE_UNUSED, |
1614 | struct cgraph_edge *edge ATTRIBUTE_UNUSED) | |
9bab6a70 | 1615 | { |
9bab6a70 | 1616 | } |
1617 | ||
1bf41320 | 1618 | /* Output optimization summary for NODE to OB. */ |
1619 | ||
1620 | static void | |
1621 | output_node_opt_summary (struct output_block *ob, | |
2b36ac0b | 1622 | struct cgraph_node *node, |
eab36a5a | 1623 | lto_symtab_encoder_t encoder) |
1bf41320 | 1624 | { |
1625 | unsigned int index; | |
1626 | bitmap_iterator bi; | |
1627 | struct ipa_replace_map *map; | |
30baba90 | 1628 | struct bitpack_d bp; |
1bf41320 | 1629 | int i; |
9bab6a70 | 1630 | struct cgraph_edge *e; |
1bf41320 | 1631 | |
29413d70 | 1632 | if (node->clone.args_to_skip) |
1633 | { | |
7f385784 | 1634 | streamer_write_uhwi (ob, bitmap_count_bits (node->clone.args_to_skip)); |
29413d70 | 1635 | EXECUTE_IF_SET_IN_BITMAP (node->clone.args_to_skip, 0, index, bi) |
7f385784 | 1636 | streamer_write_uhwi (ob, index); |
29413d70 | 1637 | } |
1638 | else | |
7f385784 | 1639 | streamer_write_uhwi (ob, 0); |
29413d70 | 1640 | if (node->clone.combined_args_to_skip) |
1641 | { | |
7f385784 | 1642 | streamer_write_uhwi (ob, bitmap_count_bits (node->clone.combined_args_to_skip)); |
29413d70 | 1643 | EXECUTE_IF_SET_IN_BITMAP (node->clone.combined_args_to_skip, 0, index, bi) |
7f385784 | 1644 | streamer_write_uhwi (ob, index); |
29413d70 | 1645 | } |
1646 | else | |
7f385784 | 1647 | streamer_write_uhwi (ob, 0); |
f1f41a6c | 1648 | streamer_write_uhwi (ob, vec_safe_length (node->clone.tree_map)); |
1649 | FOR_EACH_VEC_SAFE_ELT (node->clone.tree_map, i, map) | |
1bf41320 | 1650 | { |
1bf41320 | 1651 | /* At the moment we assume all old trees to be PARM_DECLs, because we have no |
1652 | mechanism to store function local declarations into summaries. */ | |
79e830ee | 1653 | gcc_assert (!map->old_tree); |
1654 | streamer_write_uhwi (ob, map->parm_num); | |
8e7408e3 | 1655 | gcc_assert (EXPR_LOCATION (map->new_tree) == UNKNOWN_LOCATION); |
515cf651 | 1656 | stream_write_tree (ob, map->new_tree, true); |
30baba90 | 1657 | bp = bitpack_create (ob->main_stream); |
1658 | bp_pack_value (&bp, map->replace_p, 1); | |
1659 | bp_pack_value (&bp, map->ref_p, 1); | |
7f385784 | 1660 | streamer_write_bitpack (&bp); |
1bf41320 | 1661 | } |
2b36ac0b | 1662 | |
02774f2d | 1663 | if (lto_symtab_encoder_in_partition_p (encoder, node)) |
2b36ac0b | 1664 | { |
1665 | for (e = node->callees; e; e = e->next_callee) | |
1666 | output_edge_opt_summary (ob, e); | |
1667 | for (e = node->indirect_calls; e; e = e->next_callee) | |
1668 | output_edge_opt_summary (ob, e); | |
1669 | } | |
1bf41320 | 1670 | } |
1671 | ||
1672 | /* Output optimization summaries stored in callgraph. | |
1673 | At the moment it is the clone info structure. */ | |
1674 | ||
1675 | static void | |
eab36a5a | 1676 | output_cgraph_opt_summary (void) |
1bf41320 | 1677 | { |
1bf41320 | 1678 | int i, n_nodes; |
70225339 | 1679 | lto_symtab_encoder_t encoder; |
1bf41320 | 1680 | struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum); |
1681 | unsigned count = 0; | |
1682 | ||
1683 | ob->cgraph_node = NULL; | |
70225339 | 1684 | encoder = ob->decl_state->symtab_node_encoder; |
1685 | n_nodes = lto_symtab_encoder_size (encoder); | |
1bf41320 | 1686 | for (i = 0; i < n_nodes; i++) |
2dc9831f | 1687 | { |
452659af | 1688 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
2dc9831f | 1689 | cgraph_node *cnode = dyn_cast <cgraph_node> (node); |
1690 | if (cnode && output_cgraph_opt_summary_p (cnode)) | |
1691 | count++; | |
1692 | } | |
7f385784 | 1693 | streamer_write_uhwi (ob, count); |
1bf41320 | 1694 | for (i = 0; i < n_nodes; i++) |
1695 | { | |
452659af | 1696 | symtab_node *node = lto_symtab_encoder_deref (encoder, i); |
2dc9831f | 1697 | cgraph_node *cnode = dyn_cast <cgraph_node> (node); |
1698 | if (cnode && output_cgraph_opt_summary_p (cnode)) | |
1bf41320 | 1699 | { |
7f385784 | 1700 | streamer_write_uhwi (ob, i); |
2dc9831f | 1701 | output_node_opt_summary (ob, cnode, encoder); |
1bf41320 | 1702 | } |
1703 | } | |
1704 | produce_asm (ob, NULL); | |
1705 | destroy_output_block (ob); | |
1706 | } | |
1707 | ||
9bab6a70 | 1708 | /* Input optimisation summary of EDGE. */ |
1709 | ||
1710 | static void | |
d4e80e2b | 1711 | input_edge_opt_summary (struct cgraph_edge *edge ATTRIBUTE_UNUSED, |
1712 | struct lto_input_block *ib_main ATTRIBUTE_UNUSED) | |
9bab6a70 | 1713 | { |
9bab6a70 | 1714 | } |
1715 | ||
1716 | /* Input optimisation summary of NODE. */ | |
1bf41320 | 1717 | |
1718 | static void | |
1719 | input_node_opt_summary (struct cgraph_node *node, | |
1720 | struct lto_input_block *ib_main, | |
1721 | struct data_in *data_in) | |
1722 | { | |
1723 | int i; | |
1724 | int count; | |
1725 | int bit; | |
30baba90 | 1726 | struct bitpack_d bp; |
9bab6a70 | 1727 | struct cgraph_edge *e; |
1bf41320 | 1728 | |
7f385784 | 1729 | count = streamer_read_uhwi (ib_main); |
1bf41320 | 1730 | if (count) |
1731 | node->clone.args_to_skip = BITMAP_GGC_ALLOC (); | |
1732 | for (i = 0; i < count; i++) | |
1733 | { | |
7f385784 | 1734 | bit = streamer_read_uhwi (ib_main); |
1bf41320 | 1735 | bitmap_set_bit (node->clone.args_to_skip, bit); |
1736 | } | |
7f385784 | 1737 | count = streamer_read_uhwi (ib_main); |
1bf41320 | 1738 | if (count) |
1739 | node->clone.combined_args_to_skip = BITMAP_GGC_ALLOC (); | |
1740 | for (i = 0; i < count; i++) | |
1741 | { | |
7f385784 | 1742 | bit = streamer_read_uhwi (ib_main); |
1bf41320 | 1743 | bitmap_set_bit (node->clone.combined_args_to_skip, bit); |
1744 | } | |
7f385784 | 1745 | count = streamer_read_uhwi (ib_main); |
1bf41320 | 1746 | for (i = 0; i < count; i++) |
1747 | { | |
ba72912a | 1748 | struct ipa_replace_map *map = ggc_alloc_ipa_replace_map (); |
1bf41320 | 1749 | |
f1f41a6c | 1750 | vec_safe_push (node->clone.tree_map, map); |
7f385784 | 1751 | map->parm_num = streamer_read_uhwi (ib_main); |
1bf41320 | 1752 | map->old_tree = NULL; |
515cf651 | 1753 | map->new_tree = stream_read_tree (ib_main, data_in); |
7f385784 | 1754 | bp = streamer_read_bitpack (ib_main); |
30baba90 | 1755 | map->replace_p = bp_unpack_value (&bp, 1); |
1756 | map->ref_p = bp_unpack_value (&bp, 1); | |
1bf41320 | 1757 | } |
9bab6a70 | 1758 | for (e = node->callees; e; e = e->next_callee) |
1759 | input_edge_opt_summary (e, ib_main); | |
1760 | for (e = node->indirect_calls; e; e = e->next_callee) | |
1761 | input_edge_opt_summary (e, ib_main); | |
1bf41320 | 1762 | } |
1763 | ||
1764 | /* Read section in file FILE_DATA of length LEN with data DATA. */ | |
1765 | ||
1766 | static void | |
1767 | input_cgraph_opt_section (struct lto_file_decl_data *file_data, | |
f1f41a6c | 1768 | const char *data, size_t len, |
452659af | 1769 | vec<symtab_node *> nodes) |
1bf41320 | 1770 | { |
1771 | const struct lto_function_header *header = | |
1772 | (const struct lto_function_header *) data; | |
949e5786 | 1773 | const int cfg_offset = sizeof (struct lto_function_header); |
1774 | const int main_offset = cfg_offset + header->cfg_size; | |
1775 | const int string_offset = main_offset + header->main_size; | |
1bf41320 | 1776 | struct data_in *data_in; |
1777 | struct lto_input_block ib_main; | |
1778 | unsigned int i; | |
1779 | unsigned int count; | |
1780 | ||
1781 | LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0, | |
1782 | header->main_size); | |
1783 | ||
1784 | data_in = | |
1785 | lto_data_in_create (file_data, (const char *) data + string_offset, | |
1e094109 | 1786 | header->string_size, vNULL); |
7f385784 | 1787 | count = streamer_read_uhwi (&ib_main); |
1bf41320 | 1788 | |
1789 | for (i = 0; i < count; i++) | |
1790 | { | |
7f385784 | 1791 | int ref = streamer_read_uhwi (&ib_main); |
f1f41a6c | 1792 | input_node_opt_summary (cgraph (nodes[ref]), |
1bf41320 | 1793 | &ib_main, data_in); |
1794 | } | |
783bc09c | 1795 | lto_free_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, data, |
1bf41320 | 1796 | len); |
1797 | lto_data_in_delete (data_in); | |
1798 | } | |
1799 | ||
1800 | /* Input optimization summary of cgraph. */ | |
1801 | ||
1802 | static void | |
452659af | 1803 | input_cgraph_opt_summary (vec<symtab_node *> nodes) |
1bf41320 | 1804 | { |
1805 | struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); | |
1806 | struct lto_file_decl_data *file_data; | |
1807 | unsigned int j = 0; | |
1808 | ||
1809 | while ((file_data = file_data_vec[j++])) | |
1810 | { | |
1811 | size_t len; | |
1812 | const char *data = | |
1813 | lto_get_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, | |
1814 | &len); | |
1815 | ||
1816 | if (data) | |
1817 | input_cgraph_opt_section (file_data, data, len, nodes); | |
1818 | } | |
1819 | } |