]>
Commit | Line | Data |
---|---|---|
d7f09764 DN |
1 | /* Write and read the cgraph to the memory mapped representation of a |
2 | .o file. | |
3 | ||
1da2ed5f | 4 | Copyright 2009, 2010 Free Software Foundation, Inc. |
d7f09764 DN |
5 | Contributed by Kenneth Zadeck <zadeck@naturalbridge.com> |
6 | ||
7 | This file is part of GCC. | |
8 | ||
9 | GCC is free software; you can redistribute it and/or modify it under | |
10 | the terms of the GNU General Public License as published by the Free | |
11 | Software Foundation; either version 3, or (at your option) any later | |
12 | version. | |
13 | ||
14 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
15 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 | for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with GCC; see the file COPYING3. If not see | |
21 | <http://www.gnu.org/licenses/>. */ | |
22 | ||
23 | #include "config.h" | |
24 | #include "system.h" | |
25 | #include "coretypes.h" | |
26 | #include "tm.h" | |
27 | #include "toplev.h" | |
28 | #include "tree.h" | |
29 | #include "expr.h" | |
30 | #include "flags.h" | |
31 | #include "params.h" | |
32 | #include "input.h" | |
d7f09764 DN |
33 | #include "hashtab.h" |
34 | #include "langhooks.h" | |
35 | #include "basic-block.h" | |
36 | #include "tree-flow.h" | |
37 | #include "cgraph.h" | |
38 | #include "function.h" | |
39 | #include "ggc.h" | |
1da2ed5f | 40 | #include "diagnostic-core.h" |
d7f09764 DN |
41 | #include "except.h" |
42 | #include "vec.h" | |
43 | #include "timevar.h" | |
44 | #include "output.h" | |
45 | #include "pointer-set.h" | |
46 | #include "lto-streamer.h" | |
0bc1b77f | 47 | #include "gcov-io.h" |
d7f09764 | 48 | |
369451ec | 49 | static void output_varpool (cgraph_node_set, varpool_node_set); |
922f15c2 JH |
50 | static void output_cgraph_opt_summary (void); |
51 | static void input_cgraph_opt_summary (VEC (cgraph_node_ptr, heap) * nodes); | |
52 | ||
2f41ecf5 | 53 | |
8b4765bf JH |
54 | /* Cgraph streaming is organized as set of record whose type |
55 | is indicated by a tag. */ | |
56 | enum LTO_cgraph_tags | |
57 | { | |
58 | /* Must leave 0 for the stopper. */ | |
59 | ||
60 | /* Cgraph node without body available. */ | |
61 | LTO_cgraph_unavail_node = 1, | |
62 | /* Cgraph node with function body. */ | |
63 | LTO_cgraph_analyzed_node, | |
64 | /* Cgraph edges. */ | |
65 | LTO_cgraph_edge, | |
66 | LTO_cgraph_indirect_edge | |
67 | }; | |
68 | ||
d7f09764 DN |
69 | /* Create a new cgraph encoder. */ |
70 | ||
71 | lto_cgraph_encoder_t | |
72 | lto_cgraph_encoder_new (void) | |
73 | { | |
74 | lto_cgraph_encoder_t encoder = XCNEW (struct lto_cgraph_encoder_d); | |
75 | encoder->map = pointer_map_create (); | |
76 | encoder->nodes = NULL; | |
91fbf0c7 | 77 | encoder->body = pointer_set_create (); |
d7f09764 DN |
78 | return encoder; |
79 | } | |
80 | ||
81 | ||
82 | /* Delete ENCODER and its components. */ | |
83 | ||
84 | void | |
85 | lto_cgraph_encoder_delete (lto_cgraph_encoder_t encoder) | |
86 | { | |
87 | VEC_free (cgraph_node_ptr, heap, encoder->nodes); | |
88 | pointer_map_destroy (encoder->map); | |
91fbf0c7 | 89 | pointer_set_destroy (encoder->body); |
d7f09764 DN |
90 | free (encoder); |
91 | } | |
92 | ||
93 | ||
94 | /* Return the existing reference number of NODE in the cgraph encoder in | |
95 | output block OB. Assign a new reference if this is the first time | |
96 | NODE is encoded. */ | |
97 | ||
98 | int | |
99 | lto_cgraph_encoder_encode (lto_cgraph_encoder_t encoder, | |
100 | struct cgraph_node *node) | |
101 | { | |
102 | int ref; | |
103 | void **slot; | |
b8698a0f | 104 | |
d7f09764 DN |
105 | slot = pointer_map_contains (encoder->map, node); |
106 | if (!slot) | |
107 | { | |
108 | ref = VEC_length (cgraph_node_ptr, encoder->nodes); | |
109 | slot = pointer_map_insert (encoder->map, node); | |
110 | *slot = (void *) (intptr_t) ref; | |
111 | VEC_safe_push (cgraph_node_ptr, heap, encoder->nodes, node); | |
112 | } | |
113 | else | |
114 | ref = (int) (intptr_t) *slot; | |
115 | ||
116 | return ref; | |
117 | } | |
118 | ||
8b4765bf | 119 | #define LCC_NOT_FOUND (-1) |
d7f09764 DN |
120 | |
121 | /* Look up NODE in encoder. Return NODE's reference if it has been encoded | |
122 | or LCC_NOT_FOUND if it is not there. */ | |
123 | ||
124 | int | |
125 | lto_cgraph_encoder_lookup (lto_cgraph_encoder_t encoder, | |
126 | struct cgraph_node *node) | |
127 | { | |
128 | void **slot = pointer_map_contains (encoder->map, node); | |
129 | return (slot ? (int) (intptr_t) *slot : LCC_NOT_FOUND); | |
130 | } | |
131 | ||
132 | ||
133 | /* Return the cgraph node corresponding to REF using ENCODER. */ | |
134 | ||
135 | struct cgraph_node * | |
136 | lto_cgraph_encoder_deref (lto_cgraph_encoder_t encoder, int ref) | |
137 | { | |
138 | if (ref == LCC_NOT_FOUND) | |
139 | return NULL; | |
140 | ||
b8698a0f | 141 | return VEC_index (cgraph_node_ptr, encoder->nodes, ref); |
d7f09764 DN |
142 | } |
143 | ||
144 | ||
91fbf0c7 | 145 | /* Return TRUE if we should encode initializer of NODE (if any). */ |
d7f09764 | 146 | |
91fbf0c7 JH |
147 | bool |
148 | lto_cgraph_encoder_encode_body_p (lto_cgraph_encoder_t encoder, | |
149 | struct cgraph_node *node) | |
150 | { | |
151 | return pointer_set_contains (encoder->body, node); | |
152 | } | |
153 | ||
154 | /* Return TRUE if we should encode body of NODE (if any). */ | |
155 | ||
156 | static void | |
157 | lto_set_cgraph_encoder_encode_body (lto_cgraph_encoder_t encoder, | |
158 | struct cgraph_node *node) | |
d7f09764 | 159 | { |
91fbf0c7 | 160 | pointer_set_insert (encoder->body, node); |
d7f09764 DN |
161 | } |
162 | ||
2f41ecf5 JH |
163 | /* Create a new varpool encoder. */ |
164 | ||
165 | lto_varpool_encoder_t | |
166 | lto_varpool_encoder_new (void) | |
167 | { | |
168 | lto_varpool_encoder_t encoder = XCNEW (struct lto_varpool_encoder_d); | |
169 | encoder->map = pointer_map_create (); | |
170 | encoder->initializer = pointer_set_create (); | |
171 | encoder->nodes = NULL; | |
172 | return encoder; | |
173 | } | |
174 | ||
175 | ||
176 | /* Delete ENCODER and its components. */ | |
177 | ||
178 | void | |
179 | lto_varpool_encoder_delete (lto_varpool_encoder_t encoder) | |
180 | { | |
181 | VEC_free (varpool_node_ptr, heap, encoder->nodes); | |
182 | pointer_map_destroy (encoder->map); | |
183 | pointer_set_destroy (encoder->initializer); | |
184 | free (encoder); | |
185 | } | |
186 | ||
187 | ||
188 | /* Return the existing reference number of NODE in the varpool encoder in | |
189 | output block OB. Assign a new reference if this is the first time | |
190 | NODE is encoded. */ | |
191 | ||
192 | int | |
193 | lto_varpool_encoder_encode (lto_varpool_encoder_t encoder, | |
194 | struct varpool_node *node) | |
195 | { | |
196 | int ref; | |
197 | void **slot; | |
198 | ||
199 | slot = pointer_map_contains (encoder->map, node); | |
200 | if (!slot) | |
201 | { | |
202 | ref = VEC_length (varpool_node_ptr, encoder->nodes); | |
203 | slot = pointer_map_insert (encoder->map, node); | |
204 | *slot = (void *) (intptr_t) ref; | |
205 | VEC_safe_push (varpool_node_ptr, heap, encoder->nodes, node); | |
206 | } | |
207 | else | |
208 | ref = (int) (intptr_t) *slot; | |
209 | ||
210 | return ref; | |
211 | } | |
212 | ||
213 | /* Look up NODE in encoder. Return NODE's reference if it has been encoded | |
214 | or LCC_NOT_FOUND if it is not there. */ | |
215 | ||
216 | int | |
217 | lto_varpool_encoder_lookup (lto_varpool_encoder_t encoder, | |
218 | struct varpool_node *node) | |
219 | { | |
220 | void **slot = pointer_map_contains (encoder->map, node); | |
221 | return (slot ? (int) (intptr_t) *slot : LCC_NOT_FOUND); | |
222 | } | |
223 | ||
224 | ||
225 | /* Return the varpool node corresponding to REF using ENCODER. */ | |
226 | ||
227 | struct varpool_node * | |
228 | lto_varpool_encoder_deref (lto_varpool_encoder_t encoder, int ref) | |
229 | { | |
230 | if (ref == LCC_NOT_FOUND) | |
231 | return NULL; | |
232 | ||
233 | return VEC_index (varpool_node_ptr, encoder->nodes, ref); | |
234 | } | |
235 | ||
236 | ||
2f41ecf5 JH |
237 | /* Return TRUE if we should encode initializer of NODE (if any). */ |
238 | ||
239 | bool | |
240 | lto_varpool_encoder_encode_initializer_p (lto_varpool_encoder_t encoder, | |
241 | struct varpool_node *node) | |
242 | { | |
243 | return pointer_set_contains (encoder->initializer, node); | |
244 | } | |
245 | ||
246 | /* Return TRUE if we should encode initializer of NODE (if any). */ | |
247 | ||
248 | static void | |
249 | lto_set_varpool_encoder_encode_initializer (lto_varpool_encoder_t encoder, | |
250 | struct varpool_node *node) | |
251 | { | |
252 | pointer_set_insert (encoder->initializer, node); | |
253 | } | |
d7f09764 DN |
254 | |
255 | /* Output the cgraph EDGE to OB using ENCODER. */ | |
256 | ||
257 | static void | |
258 | lto_output_edge (struct lto_simple_output_block *ob, struct cgraph_edge *edge, | |
259 | lto_cgraph_encoder_t encoder) | |
260 | { | |
261 | unsigned int uid; | |
262 | intptr_t ref; | |
2465dcc2 | 263 | struct bitpack_d bp; |
d7f09764 | 264 | |
e33c6cd6 MJ |
265 | if (edge->indirect_unknown_callee) |
266 | lto_output_uleb128_stream (ob->main_stream, LTO_cgraph_indirect_edge); | |
267 | else | |
268 | lto_output_uleb128_stream (ob->main_stream, LTO_cgraph_edge); | |
d7f09764 DN |
269 | |
270 | ref = lto_cgraph_encoder_lookup (encoder, edge->caller); | |
b8698a0f | 271 | gcc_assert (ref != LCC_NOT_FOUND); |
d7f09764 DN |
272 | lto_output_sleb128_stream (ob->main_stream, ref); |
273 | ||
e33c6cd6 MJ |
274 | if (!edge->indirect_unknown_callee) |
275 | { | |
276 | ref = lto_cgraph_encoder_lookup (encoder, edge->callee); | |
277 | gcc_assert (ref != LCC_NOT_FOUND); | |
278 | lto_output_sleb128_stream (ob->main_stream, ref); | |
279 | } | |
d7f09764 DN |
280 | |
281 | lto_output_sleb128_stream (ob->main_stream, edge->count); | |
282 | ||
2465dcc2 | 283 | bp = bitpack_create (ob->main_stream); |
f1395d4a JH |
284 | uid = (!gimple_has_body_p (edge->caller->decl) |
285 | ? edge->lto_stmt_uid : gimple_uid (edge->call_stmt)); | |
2465dcc2 RG |
286 | bp_pack_value (&bp, uid, HOST_BITS_PER_INT); |
287 | bp_pack_value (&bp, edge->inline_failed, HOST_BITS_PER_INT); | |
288 | bp_pack_value (&bp, edge->frequency, HOST_BITS_PER_INT); | |
289 | bp_pack_value (&bp, edge->loop_nest, 30); | |
290 | bp_pack_value (&bp, edge->indirect_inlining_edge, 1); | |
291 | bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1); | |
292 | bp_pack_value (&bp, edge->can_throw_external, 1); | |
5f902d76 JH |
293 | if (edge->indirect_unknown_callee) |
294 | { | |
295 | int flags = edge->indirect_info->ecf_flags; | |
2465dcc2 RG |
296 | bp_pack_value (&bp, (flags & ECF_CONST) != 0, 1); |
297 | bp_pack_value (&bp, (flags & ECF_PURE) != 0, 1); | |
298 | bp_pack_value (&bp, (flags & ECF_NORETURN) != 0, 1); | |
299 | bp_pack_value (&bp, (flags & ECF_MALLOC) != 0, 1); | |
300 | bp_pack_value (&bp, (flags & ECF_NOTHROW) != 0, 1); | |
301 | bp_pack_value (&bp, (flags & ECF_RETURNS_TWICE) != 0, 1); | |
5f902d76 JH |
302 | /* Flags that should not appear on indirect calls. */ |
303 | gcc_assert (!(flags & (ECF_LOOPING_CONST_OR_PURE | |
304 | | ECF_MAY_BE_ALLOCA | |
305 | | ECF_SIBCALL | |
306 | | ECF_NOVOPS))); | |
307 | } | |
2465dcc2 | 308 | lto_output_bitpack (&bp); |
d7f09764 DN |
309 | } |
310 | ||
369451ec | 311 | /* Return if LIST contain references from other partitions. */ |
f3380641 | 312 | |
369451ec JH |
313 | bool |
314 | referenced_from_other_partition_p (struct ipa_ref_list *list, cgraph_node_set set, | |
315 | varpool_node_set vset) | |
316 | { | |
317 | int i; | |
318 | struct ipa_ref *ref; | |
319 | for (i = 0; ipa_ref_list_refering_iterate (list, i, ref); i++) | |
320 | { | |
321 | if (ref->refering_type == IPA_REF_CGRAPH) | |
322 | { | |
92eb4438 JH |
323 | if (ipa_ref_refering_node (ref)->in_other_partition |
324 | || !cgraph_node_in_set_p (ipa_ref_refering_node (ref), set)) | |
369451ec JH |
325 | return true; |
326 | } | |
327 | else | |
328 | { | |
92eb4438 JH |
329 | if (ipa_ref_refering_varpool_node (ref)->in_other_partition |
330 | || !varpool_node_in_set_p (ipa_ref_refering_varpool_node (ref), | |
331 | vset)) | |
369451ec JH |
332 | return true; |
333 | } | |
334 | } | |
335 | return false; | |
336 | } | |
337 | ||
a837268b JH |
338 | /* Return true when node is reachable from other partition. */ |
339 | ||
9a809897 | 340 | bool |
a837268b JH |
341 | reachable_from_other_partition_p (struct cgraph_node *node, cgraph_node_set set) |
342 | { | |
343 | struct cgraph_edge *e; | |
a837268b JH |
344 | if (!node->analyzed) |
345 | return false; | |
346 | if (node->global.inlined_to) | |
347 | return false; | |
348 | for (e = node->callers; e; e = e->next_caller) | |
92eb4438 JH |
349 | if (e->caller->in_other_partition |
350 | || !cgraph_node_in_set_p (e->caller, set)) | |
a837268b JH |
351 | return true; |
352 | return false; | |
353 | } | |
d7f09764 | 354 | |
f3380641 JH |
355 | /* Return if LIST contain references from other partitions. */ |
356 | ||
357 | bool | |
358 | referenced_from_this_partition_p (struct ipa_ref_list *list, cgraph_node_set set, | |
359 | varpool_node_set vset) | |
360 | { | |
361 | int i; | |
362 | struct ipa_ref *ref; | |
363 | for (i = 0; ipa_ref_list_refering_iterate (list, i, ref); i++) | |
364 | { | |
365 | if (ref->refering_type == IPA_REF_CGRAPH) | |
366 | { | |
367 | if (cgraph_node_in_set_p (ipa_ref_refering_node (ref), set)) | |
368 | return true; | |
369 | } | |
370 | else | |
371 | { | |
372 | if (varpool_node_in_set_p (ipa_ref_refering_varpool_node (ref), | |
373 | vset)) | |
374 | return true; | |
375 | } | |
376 | } | |
377 | return false; | |
378 | } | |
379 | ||
380 | /* Return true when node is reachable from other partition. */ | |
381 | ||
382 | bool | |
383 | reachable_from_this_partition_p (struct cgraph_node *node, cgraph_node_set set) | |
384 | { | |
385 | struct cgraph_edge *e; | |
386 | if (!node->analyzed) | |
387 | return false; | |
388 | if (node->global.inlined_to) | |
389 | return false; | |
390 | for (e = node->callers; e; e = e->next_caller) | |
391 | if (cgraph_node_in_set_p (e->caller, set)) | |
392 | return true; | |
393 | return false; | |
394 | } | |
395 | ||
d7f09764 DN |
396 | /* Output the cgraph NODE to OB. ENCODER is used to find the |
397 | reference number of NODE->inlined_to. SET is the set of nodes we | |
398 | are writing to the current file. If NODE is not in SET, then NODE | |
399 | is a boundary of a cgraph_node_set and we pretend NODE just has a | |
400 | decl and no callees. WRITTEN_DECLS is the set of FUNCTION_DECLs | |
401 | that have had their callgraph node written so far. This is used to | |
402 | determine if NODE is a clone of a previously written node. */ | |
403 | ||
404 | static void | |
405 | lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node, | |
406 | lto_cgraph_encoder_t encoder, cgraph_node_set set, | |
91fbf0c7 | 407 | varpool_node_set vset) |
d7f09764 DN |
408 | { |
409 | unsigned int tag; | |
2465dcc2 | 410 | struct bitpack_d bp; |
91fbf0c7 | 411 | bool boundary_p; |
d7f09764 | 412 | intptr_t ref; |
a837268b | 413 | bool in_other_partition = false; |
91fbf0c7 | 414 | struct cgraph_node *clone_of; |
d7f09764 DN |
415 | |
416 | boundary_p = !cgraph_node_in_set_p (node, set); | |
d7f09764 | 417 | |
8b4765bf JH |
418 | if (node->analyzed && !boundary_p) |
419 | tag = LTO_cgraph_analyzed_node; | |
420 | else | |
d7f09764 DN |
421 | tag = LTO_cgraph_unavail_node; |
422 | ||
423 | lto_output_uleb128_stream (ob->main_stream, tag); | |
424 | ||
d7f09764 DN |
425 | /* In WPA mode, we only output part of the call-graph. Also, we |
426 | fake cgraph node attributes. There are two cases that we care. | |
427 | ||
428 | Boundary nodes: There are nodes that are not part of SET but are | |
429 | called from within SET. We artificially make them look like | |
b8698a0f | 430 | externally visible nodes with no function body. |
d7f09764 DN |
431 | |
432 | Cherry-picked nodes: These are nodes we pulled from other | |
433 | translation units into SET during IPA-inlining. We make them as | |
434 | local static nodes to prevent clashes with other local statics. */ | |
8b4765bf | 435 | if (boundary_p && node->analyzed) |
d7f09764 | 436 | { |
a837268b JH |
437 | /* Inline clones can not be part of boundary. |
438 | gcc_assert (!node->global.inlined_to); | |
439 | ||
440 | FIXME: At the moment they can be, when partition contains an inline | |
441 | clone that is clone of inline clone from outside partition. We can | |
442 | reshape the clone tree and make other tree to be the root, but it | |
443 | needs a bit extra work and will be promplty done by cgraph_remove_node | |
444 | after reading back. */ | |
445 | in_other_partition = 1; | |
d7f09764 | 446 | } |
d7f09764 | 447 | |
91fbf0c7 JH |
448 | clone_of = node->clone_of; |
449 | while (clone_of | |
0cac82a0 | 450 | && (ref = lto_cgraph_encoder_lookup (encoder, clone_of)) == LCC_NOT_FOUND) |
91fbf0c7 JH |
451 | if (clone_of->prev_sibling_clone) |
452 | clone_of = clone_of->prev_sibling_clone; | |
453 | else | |
454 | clone_of = clone_of->clone_of; | |
0cac82a0 JH |
455 | |
456 | if (LTO_cgraph_analyzed_node) | |
457 | gcc_assert (clone_of || !node->clone_of); | |
91fbf0c7 JH |
458 | if (!clone_of) |
459 | lto_output_sleb128_stream (ob->main_stream, LCC_NOT_FOUND); | |
460 | else | |
461 | lto_output_sleb128_stream (ob->main_stream, ref); | |
d7f09764 | 462 | |
d7f09764 DN |
463 | |
464 | lto_output_fn_decl_index (ob->decl_state, ob->main_stream, node->decl); | |
465 | lto_output_sleb128_stream (ob->main_stream, node->count); | |
466 | ||
8b4765bf | 467 | if (tag == LTO_cgraph_analyzed_node) |
d7f09764 | 468 | { |
b8698a0f | 469 | lto_output_sleb128_stream (ob->main_stream, |
d7f09764 | 470 | node->local.inline_summary.estimated_self_stack_size); |
b8698a0f | 471 | lto_output_sleb128_stream (ob->main_stream, |
d7f09764 | 472 | node->local.inline_summary.self_size); |
b8698a0f | 473 | lto_output_sleb128_stream (ob->main_stream, |
d7f09764 | 474 | node->local.inline_summary.size_inlining_benefit); |
b8698a0f | 475 | lto_output_sleb128_stream (ob->main_stream, |
d7f09764 | 476 | node->local.inline_summary.self_time); |
b8698a0f | 477 | lto_output_sleb128_stream (ob->main_stream, |
d7f09764 | 478 | node->local.inline_summary.time_inlining_benefit); |
8b4765bf JH |
479 | if (node->global.inlined_to) |
480 | { | |
481 | ref = lto_cgraph_encoder_lookup (encoder, node->global.inlined_to); | |
482 | gcc_assert (ref != LCC_NOT_FOUND); | |
483 | } | |
484 | else | |
485 | ref = LCC_NOT_FOUND; | |
d7f09764 | 486 | |
8b4765bf | 487 | lto_output_sleb128_stream (ob->main_stream, ref); |
d7f09764 | 488 | } |
d7f09764 | 489 | |
ecd03d10 | 490 | if (node->same_comdat_group && !boundary_p) |
b66887e4 JJ |
491 | { |
492 | ref = lto_cgraph_encoder_lookup (encoder, node->same_comdat_group); | |
493 | gcc_assert (ref != LCC_NOT_FOUND); | |
494 | } | |
495 | else | |
496 | ref = LCC_NOT_FOUND; | |
497 | lto_output_sleb128_stream (ob->main_stream, ref); | |
498 | ||
2465dcc2 RG |
499 | bp = bitpack_create (ob->main_stream); |
500 | bp_pack_value (&bp, node->local.local, 1); | |
501 | bp_pack_value (&bp, node->local.externally_visible, 1); | |
502 | bp_pack_value (&bp, node->local.finalized, 1); | |
503 | bp_pack_value (&bp, node->local.inlinable, 1); | |
504 | bp_pack_value (&bp, node->local.versionable, 1); | |
505 | bp_pack_value (&bp, node->local.disregard_inline_limits, 1); | |
506 | bp_pack_value (&bp, node->local.redefined_extern_inline, 1); | |
507 | bp_pack_value (&bp, node->local.vtable_method, 1); | |
508 | bp_pack_value (&bp, node->needed, 1); | |
509 | bp_pack_value (&bp, node->address_taken, 1); | |
510 | bp_pack_value (&bp, node->abstract_and_needed, 1); | |
511 | bp_pack_value (&bp, tag == LTO_cgraph_analyzed_node | |
512 | && !DECL_EXTERNAL (node->decl) | |
92eb4438 | 513 | && !DECL_COMDAT (node->decl) |
2465dcc2 RG |
514 | && (reachable_from_other_partition_p (node, set) |
515 | || referenced_from_other_partition_p (&node->ref_list, set, vset)), 1); | |
516 | bp_pack_value (&bp, node->lowered, 1); | |
517 | bp_pack_value (&bp, in_other_partition, 1); | |
518 | bp_pack_value (&bp, node->alias, 1); | |
519 | bp_pack_value (&bp, node->finalized_by_frontend, 1); | |
520 | bp_pack_value (&bp, node->frequency, 2); | |
521 | lto_output_bitpack (&bp); | |
051f8cc6 | 522 | lto_output_uleb128_stream (ob->main_stream, node->resolution); |
2465dcc2 | 523 | |
b2583345 JJ |
524 | if (node->same_body) |
525 | { | |
526 | struct cgraph_node *alias; | |
527 | unsigned long alias_count = 1; | |
528 | for (alias = node->same_body; alias->next; alias = alias->next) | |
529 | alias_count++; | |
530 | lto_output_uleb128_stream (ob->main_stream, alias_count); | |
531 | do | |
532 | { | |
533 | lto_output_fn_decl_index (ob->decl_state, ob->main_stream, | |
534 | alias->decl); | |
6744a6ab JH |
535 | if (alias->thunk.thunk_p) |
536 | { | |
537 | lto_output_uleb128_stream | |
538 | (ob->main_stream, | |
539 | 1 + (alias->thunk.this_adjusting != 0) * 2 | |
540 | + (alias->thunk.virtual_offset_p != 0) * 4); | |
541 | lto_output_uleb128_stream (ob->main_stream, | |
542 | alias->thunk.fixed_offset); | |
543 | lto_output_uleb128_stream (ob->main_stream, | |
544 | alias->thunk.virtual_value); | |
545 | lto_output_fn_decl_index (ob->decl_state, ob->main_stream, | |
546 | alias->thunk.alias); | |
547 | } | |
548 | else | |
ede51b1f RG |
549 | { |
550 | lto_output_uleb128_stream (ob->main_stream, 0); | |
551 | lto_output_fn_decl_index (ob->decl_state, ob->main_stream, | |
552 | alias->thunk.alias); | |
553 | } | |
051f8cc6 | 554 | lto_output_uleb128_stream (ob->main_stream, alias->resolution); |
b2583345 JJ |
555 | alias = alias->previous; |
556 | } | |
557 | while (alias); | |
558 | } | |
559 | else | |
560 | lto_output_uleb128_stream (ob->main_stream, 0); | |
d7f09764 DN |
561 | } |
562 | ||
2942c502 JH |
563 | /* Output the varpool NODE to OB. |
564 | If NODE is not in SET, then NODE is a boundary. */ | |
565 | ||
566 | static void | |
567 | lto_output_varpool_node (struct lto_simple_output_block *ob, struct varpool_node *node, | |
9f90e80a | 568 | lto_varpool_encoder_t varpool_encoder, |
369451ec | 569 | cgraph_node_set set, varpool_node_set vset) |
2942c502 | 570 | { |
369451ec | 571 | bool boundary_p = !varpool_node_in_set_p (node, vset) && node->analyzed; |
2465dcc2 | 572 | struct bitpack_d bp; |
2942c502 JH |
573 | struct varpool_node *alias; |
574 | int count = 0; | |
9f90e80a | 575 | int ref; |
2942c502 JH |
576 | |
577 | lto_output_var_decl_index (ob->decl_state, ob->main_stream, node->decl); | |
2465dcc2 RG |
578 | bp = bitpack_create (ob->main_stream); |
579 | bp_pack_value (&bp, node->externally_visible, 1); | |
580 | bp_pack_value (&bp, node->force_output, 1); | |
581 | bp_pack_value (&bp, node->finalized, 1); | |
582 | bp_pack_value (&bp, node->alias, 1); | |
5b042919 | 583 | gcc_assert (!node->alias || !node->extra_name); |
2942c502 JH |
584 | gcc_assert (node->finalized || !node->analyzed); |
585 | gcc_assert (node->needed); | |
05575e07 JH |
586 | /* Constant pool initializers can be de-unified into individual ltrans units. |
587 | FIXME: Alternatively at -Os we may want to avoid generating for them the local | |
588 | labels and share them across LTRANS partitions. */ | |
92eb4438 JH |
589 | if (DECL_IN_CONSTANT_POOL (node->decl) |
590 | && !DECL_COMDAT (node->decl)) | |
05575e07 | 591 | { |
2465dcc2 RG |
592 | bp_pack_value (&bp, 0, 1); /* used_from_other_parition. */ |
593 | bp_pack_value (&bp, 0, 1); /* in_other_partition. */ | |
05575e07 JH |
594 | } |
595 | else | |
596 | { | |
2465dcc2 | 597 | bp_pack_value (&bp, node->analyzed |
369451ec JH |
598 | && referenced_from_other_partition_p (&node->ref_list, |
599 | set, vset), 1); | |
2465dcc2 | 600 | bp_pack_value (&bp, boundary_p, 1); /* in_other_partition. */ |
05575e07 | 601 | } |
2942c502 JH |
602 | /* Also emit any extra name aliases. */ |
603 | for (alias = node->extra_name; alias; alias = alias->next) | |
604 | count++; | |
2465dcc2 RG |
605 | bp_pack_value (&bp, count != 0, 1); |
606 | lto_output_bitpack (&bp); | |
9f90e80a JH |
607 | if (node->same_comdat_group && !boundary_p) |
608 | { | |
609 | ref = lto_varpool_encoder_lookup (varpool_encoder, node->same_comdat_group); | |
610 | gcc_assert (ref != LCC_NOT_FOUND); | |
611 | } | |
612 | else | |
613 | ref = LCC_NOT_FOUND; | |
614 | lto_output_sleb128_stream (ob->main_stream, ref); | |
051f8cc6 | 615 | lto_output_uleb128_stream (ob->main_stream, node->resolution); |
2942c502 JH |
616 | |
617 | if (count) | |
618 | { | |
619 | lto_output_uleb128_stream (ob->main_stream, count); | |
620 | for (alias = node->extra_name; alias; alias = alias->next) | |
051f8cc6 JH |
621 | { |
622 | lto_output_var_decl_index (ob->decl_state, ob->main_stream, alias->decl); | |
623 | lto_output_uleb128_stream (ob->main_stream, alias->resolution); | |
624 | } | |
2942c502 JH |
625 | } |
626 | } | |
627 | ||
369451ec JH |
628 | /* Output the varpool NODE to OB. |
629 | If NODE is not in SET, then NODE is a boundary. */ | |
630 | ||
631 | static void | |
632 | lto_output_ref (struct lto_simple_output_block *ob, struct ipa_ref *ref, | |
633 | lto_cgraph_encoder_t encoder, | |
634 | lto_varpool_encoder_t varpool_encoder) | |
635 | { | |
2465dcc2 RG |
636 | struct bitpack_d bp; |
637 | bp = bitpack_create (ob->main_stream); | |
638 | bp_pack_value (&bp, ref->refered_type, 1); | |
639 | bp_pack_value (&bp, ref->use, 2); | |
640 | lto_output_bitpack (&bp); | |
369451ec JH |
641 | if (ref->refered_type == IPA_REF_CGRAPH) |
642 | { | |
643 | int nref = lto_cgraph_encoder_lookup (encoder, ipa_ref_node (ref)); | |
644 | gcc_assert (nref != LCC_NOT_FOUND); | |
645 | lto_output_sleb128_stream (ob->main_stream, nref); | |
646 | } | |
647 | else | |
648 | { | |
649 | int nref = lto_varpool_encoder_lookup (varpool_encoder, | |
650 | ipa_ref_varpool_node (ref)); | |
651 | gcc_assert (nref != LCC_NOT_FOUND); | |
652 | lto_output_sleb128_stream (ob->main_stream, nref); | |
653 | } | |
654 | } | |
655 | ||
0bc1b77f JH |
656 | /* Stream out profile_summary to OB. */ |
657 | ||
658 | static void | |
659 | output_profile_summary (struct lto_simple_output_block *ob) | |
660 | { | |
661 | if (profile_info) | |
662 | { | |
663 | /* We do not output num, it is not terribly useful. */ | |
664 | gcc_assert (profile_info->runs); | |
665 | lto_output_uleb128_stream (ob->main_stream, profile_info->runs); | |
666 | lto_output_sleb128_stream (ob->main_stream, profile_info->sum_all); | |
667 | lto_output_sleb128_stream (ob->main_stream, profile_info->run_max); | |
668 | lto_output_sleb128_stream (ob->main_stream, profile_info->sum_max); | |
669 | } | |
670 | else | |
671 | lto_output_uleb128_stream (ob->main_stream, 0); | |
672 | } | |
673 | ||
a837268b JH |
674 | /* Add NODE into encoder as well as nodes it is cloned from. |
675 | Do it in a way so clones appear first. */ | |
91fbf0c7 | 676 | |
a837268b | 677 | static void |
91fbf0c7 JH |
678 | add_node_to (lto_cgraph_encoder_t encoder, struct cgraph_node *node, |
679 | bool include_body) | |
a837268b JH |
680 | { |
681 | if (node->clone_of) | |
91fbf0c7 JH |
682 | add_node_to (encoder, node->clone_of, include_body); |
683 | else if (include_body) | |
684 | lto_set_cgraph_encoder_encode_body (encoder, node); | |
a837268b JH |
685 | lto_cgraph_encoder_encode (encoder, node); |
686 | } | |
d7f09764 | 687 | |
369451ec JH |
688 | /* Add all references in LIST to encoders. */ |
689 | ||
690 | static void | |
691 | add_references (lto_cgraph_encoder_t encoder, | |
692 | lto_varpool_encoder_t varpool_encoder, | |
693 | struct ipa_ref_list *list) | |
694 | { | |
695 | int i; | |
696 | struct ipa_ref *ref; | |
697 | for (i = 0; ipa_ref_list_reference_iterate (list, i, ref); i++) | |
698 | if (ref->refered_type == IPA_REF_CGRAPH) | |
91fbf0c7 | 699 | add_node_to (encoder, ipa_ref_node (ref), false); |
369451ec JH |
700 | else |
701 | { | |
702 | struct varpool_node *vnode = ipa_ref_varpool_node (ref); | |
703 | lto_varpool_encoder_encode (varpool_encoder, vnode); | |
704 | } | |
705 | } | |
706 | ||
e33c6cd6 MJ |
707 | /* Output all callees or indirect outgoing edges. EDGE must be the first such |
708 | edge. */ | |
709 | ||
710 | static void | |
711 | output_outgoing_cgraph_edges (struct cgraph_edge *edge, | |
712 | struct lto_simple_output_block *ob, | |
713 | lto_cgraph_encoder_t encoder) | |
714 | { | |
715 | if (!edge) | |
716 | return; | |
717 | ||
718 | /* Output edges in backward direction, so the reconstructed callgraph match | |
719 | and it is easy to associate call sites in the IPA pass summaries. */ | |
720 | while (edge->next_callee) | |
721 | edge = edge->next_callee; | |
722 | for (; edge; edge = edge->prev_callee) | |
723 | lto_output_edge (ob, edge, encoder); | |
724 | } | |
725 | ||
369451ec JH |
726 | /* Output the part of the cgraph in SET. */ |
727 | ||
728 | static void | |
729 | output_refs (cgraph_node_set set, varpool_node_set vset, | |
730 | lto_cgraph_encoder_t encoder, | |
731 | lto_varpool_encoder_t varpool_encoder) | |
732 | { | |
733 | cgraph_node_set_iterator csi; | |
734 | varpool_node_set_iterator vsi; | |
735 | struct lto_simple_output_block *ob; | |
736 | int count; | |
737 | struct ipa_ref *ref; | |
738 | int i; | |
739 | ||
740 | ob = lto_create_simple_output_block (LTO_section_refs); | |
741 | ||
742 | for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi)) | |
743 | { | |
744 | struct cgraph_node *node = csi_node (csi); | |
745 | ||
746 | count = ipa_ref_list_nreferences (&node->ref_list); | |
747 | if (count) | |
748 | { | |
749 | lto_output_uleb128_stream (ob->main_stream, count); | |
750 | lto_output_uleb128_stream (ob->main_stream, | |
751 | lto_cgraph_encoder_lookup (encoder, node)); | |
752 | for (i = 0; ipa_ref_list_reference_iterate (&node->ref_list, i, ref); i++) | |
753 | lto_output_ref (ob, ref, encoder, varpool_encoder); | |
754 | } | |
755 | } | |
756 | ||
757 | lto_output_uleb128_stream (ob->main_stream, 0); | |
758 | ||
759 | for (vsi = vsi_start (vset); !vsi_end_p (vsi); vsi_next (&vsi)) | |
760 | { | |
761 | struct varpool_node *node = vsi_node (vsi); | |
762 | ||
763 | count = ipa_ref_list_nreferences (&node->ref_list); | |
764 | if (count) | |
765 | { | |
766 | lto_output_uleb128_stream (ob->main_stream, count); | |
767 | lto_output_uleb128_stream (ob->main_stream, | |
768 | lto_varpool_encoder_lookup (varpool_encoder, | |
769 | node)); | |
770 | for (i = 0; ipa_ref_list_reference_iterate (&node->ref_list, i, ref); i++) | |
771 | lto_output_ref (ob, ref, encoder, varpool_encoder); | |
772 | } | |
773 | } | |
774 | ||
775 | lto_output_uleb128_stream (ob->main_stream, 0); | |
776 | ||
777 | lto_destroy_simple_output_block (ob); | |
778 | } | |
779 | ||
f3380641 JH |
780 | /* Find out all cgraph and varpool nodes we want to encode in current unit |
781 | and insert them to encoders. */ | |
d7f09764 | 782 | void |
f3380641 JH |
783 | compute_ltrans_boundary (struct lto_out_decl_state *state, |
784 | cgraph_node_set set, varpool_node_set vset) | |
d7f09764 DN |
785 | { |
786 | struct cgraph_node *node; | |
d7f09764 | 787 | cgraph_node_set_iterator csi; |
2f41ecf5 | 788 | varpool_node_set_iterator vsi; |
d7f09764 | 789 | struct cgraph_edge *edge; |
f3380641 | 790 | int i; |
d7f09764 | 791 | lto_cgraph_encoder_t encoder; |
2f41ecf5 | 792 | lto_varpool_encoder_t varpool_encoder; |
0bc1b77f | 793 | |
f3380641 JH |
794 | encoder = state->cgraph_node_encoder = lto_cgraph_encoder_new (); |
795 | varpool_encoder = state->varpool_node_encoder = lto_varpool_encoder_new (); | |
d7f09764 DN |
796 | |
797 | /* Go over all the nodes in SET and assign references. */ | |
798 | for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi)) | |
799 | { | |
800 | node = csi_node (csi); | |
91fbf0c7 | 801 | add_node_to (encoder, node, true); |
369451ec | 802 | add_references (encoder, varpool_encoder, &node->ref_list); |
d7f09764 | 803 | } |
2f41ecf5 JH |
804 | for (vsi = vsi_start (vset); !vsi_end_p (vsi); vsi_next (&vsi)) |
805 | { | |
806 | struct varpool_node *vnode = vsi_node (vsi); | |
807 | gcc_assert (!vnode->alias); | |
808 | lto_varpool_encoder_encode (varpool_encoder, vnode); | |
809 | lto_set_varpool_encoder_encode_initializer (varpool_encoder, vnode); | |
369451ec | 810 | add_references (encoder, varpool_encoder, &vnode->ref_list); |
2f41ecf5 | 811 | } |
2f41ecf5 JH |
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. */ | |
815 | for (i = 0; i < lto_varpool_encoder_size (varpool_encoder); i++) | |
816 | { | |
817 | struct varpool_node *vnode = lto_varpool_encoder_deref (varpool_encoder, i); | |
818 | if (DECL_INITIAL (vnode->decl) | |
819 | && !lto_varpool_encoder_encode_initializer_p (varpool_encoder, | |
820 | vnode) | |
64e0f5ff | 821 | && const_value_known_p (vnode->decl)) |
2f41ecf5 JH |
822 | { |
823 | lto_set_varpool_encoder_encode_initializer (varpool_encoder, vnode); | |
369451ec | 824 | add_references (encoder, varpool_encoder, &vnode->ref_list); |
2f41ecf5 JH |
825 | } |
826 | } | |
d7f09764 DN |
827 | |
828 | /* Go over all the nodes again to include callees that are not in | |
829 | SET. */ | |
830 | for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi)) | |
831 | { | |
832 | node = csi_node (csi); | |
833 | for (edge = node->callees; edge; edge = edge->next_callee) | |
834 | { | |
835 | struct cgraph_node *callee = edge->callee; | |
836 | if (!cgraph_node_in_set_p (callee, set)) | |
837 | { | |
838 | /* We should have moved all the inlines. */ | |
839 | gcc_assert (!callee->global.inlined_to); | |
91fbf0c7 | 840 | add_node_to (encoder, callee, false); |
d7f09764 DN |
841 | } |
842 | } | |
843 | } | |
f3380641 JH |
844 | } |
845 | ||
846 | /* Output the part of the cgraph in SET. */ | |
847 | ||
848 | void | |
849 | output_cgraph (cgraph_node_set set, varpool_node_set vset) | |
850 | { | |
851 | struct cgraph_node *node; | |
852 | struct lto_simple_output_block *ob; | |
853 | cgraph_node_set_iterator csi; | |
854 | int i, n_nodes; | |
f3380641 JH |
855 | lto_cgraph_encoder_t encoder; |
856 | lto_varpool_encoder_t varpool_encoder; | |
857 | struct cgraph_asm_node *can; | |
86353474 | 858 | static bool asm_nodes_output = false; |
f3380641 | 859 | |
922f15c2 JH |
860 | if (flag_wpa) |
861 | output_cgraph_opt_summary (); | |
862 | ||
f3380641 JH |
863 | ob = lto_create_simple_output_block (LTO_section_cgraph); |
864 | ||
865 | output_profile_summary (ob); | |
866 | ||
867 | /* An encoder for cgraph nodes should have been created by | |
868 | ipa_write_summaries_1. */ | |
869 | gcc_assert (ob->decl_state->cgraph_node_encoder); | |
870 | gcc_assert (ob->decl_state->varpool_node_encoder); | |
871 | encoder = ob->decl_state->cgraph_node_encoder; | |
872 | varpool_encoder = ob->decl_state->varpool_node_encoder; | |
873 | ||
a837268b JH |
874 | /* Write out the nodes. We must first output a node and then its clones, |
875 | otherwise at a time reading back the node there would be nothing to clone | |
876 | from. */ | |
d7f09764 DN |
877 | n_nodes = lto_cgraph_encoder_size (encoder); |
878 | for (i = 0; i < n_nodes; i++) | |
879 | { | |
880 | node = lto_cgraph_encoder_deref (encoder, i); | |
91fbf0c7 | 881 | lto_output_node (ob, node, encoder, set, vset); |
d7f09764 DN |
882 | } |
883 | ||
d7f09764 DN |
884 | /* Go over the nodes in SET again to write edges. */ |
885 | for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi)) | |
886 | { | |
887 | node = csi_node (csi); | |
e33c6cd6 MJ |
888 | output_outgoing_cgraph_edges (node->callees, ob, encoder); |
889 | output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder); | |
d7f09764 DN |
890 | } |
891 | ||
892 | lto_output_uleb128_stream (ob->main_stream, 0); | |
893 | ||
b0d9e663 JH |
894 | /* Emit toplevel asms. |
895 | When doing WPA we must output every asm just once. Since we do not partition asm | |
896 | nodes at all, output them to first output. This is kind of hack, but should work | |
897 | well. */ | |
898 | if (!asm_nodes_output) | |
a9cc4458 | 899 | { |
b0d9e663 JH |
900 | asm_nodes_output = true; |
901 | for (can = cgraph_asm_nodes; can; can = can->next) | |
902 | { | |
903 | int len = TREE_STRING_LENGTH (can->asm_str); | |
904 | lto_output_uleb128_stream (ob->main_stream, len); | |
905 | for (i = 0; i < len; ++i) | |
906 | lto_output_1_stream (ob->main_stream, | |
907 | TREE_STRING_POINTER (can->asm_str)[i]); | |
908 | } | |
a9cc4458 RG |
909 | } |
910 | ||
911 | lto_output_uleb128_stream (ob->main_stream, 0); | |
912 | ||
d7f09764 | 913 | lto_destroy_simple_output_block (ob); |
369451ec JH |
914 | output_varpool (set, vset); |
915 | output_refs (set, vset, encoder, varpool_encoder); | |
d7f09764 DN |
916 | } |
917 | ||
d7f09764 DN |
918 | /* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS, |
919 | STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize | |
920 | NODE or to replace the values in it, for instance because the first | |
921 | time we saw it, the function body was not available but now it | |
922 | is. BP is a bitpack with all the bitflags for NODE read from the | |
923 | stream. */ | |
924 | ||
925 | static void | |
926 | input_overwrite_node (struct lto_file_decl_data *file_data, | |
927 | struct cgraph_node *node, | |
928 | enum LTO_cgraph_tags tag, | |
929 | struct bitpack_d *bp, | |
930 | unsigned int stack_size, | |
931 | unsigned int self_time, | |
932 | unsigned int time_inlining_benefit, | |
933 | unsigned int self_size, | |
051f8cc6 JH |
934 | unsigned int size_inlining_benefit, |
935 | enum ld_plugin_symbol_resolution resolution) | |
d7f09764 DN |
936 | { |
937 | node->aux = (void *) tag; | |
938 | node->local.inline_summary.estimated_self_stack_size = stack_size; | |
939 | node->local.inline_summary.self_time = self_time; | |
940 | node->local.inline_summary.time_inlining_benefit = time_inlining_benefit; | |
941 | node->local.inline_summary.self_size = self_size; | |
942 | node->local.inline_summary.size_inlining_benefit = size_inlining_benefit; | |
943 | node->global.time = self_time; | |
944 | node->global.size = self_size; | |
8b4765bf JH |
945 | node->global.estimated_stack_size = stack_size; |
946 | node->global.estimated_growth = INT_MIN; | |
d7f09764 DN |
947 | node->local.lto_file_data = file_data; |
948 | ||
949 | node->local.local = bp_unpack_value (bp, 1); | |
950 | node->local.externally_visible = bp_unpack_value (bp, 1); | |
951 | node->local.finalized = bp_unpack_value (bp, 1); | |
952 | node->local.inlinable = bp_unpack_value (bp, 1); | |
ccbbf8a2 | 953 | node->local.versionable = bp_unpack_value (bp, 1); |
d7f09764 DN |
954 | node->local.disregard_inline_limits = bp_unpack_value (bp, 1); |
955 | node->local.redefined_extern_inline = bp_unpack_value (bp, 1); | |
d7f09764 DN |
956 | node->local.vtable_method = bp_unpack_value (bp, 1); |
957 | node->needed = bp_unpack_value (bp, 1); | |
958 | node->address_taken = bp_unpack_value (bp, 1); | |
959 | node->abstract_and_needed = bp_unpack_value (bp, 1); | |
a837268b | 960 | node->reachable_from_other_partition = bp_unpack_value (bp, 1); |
d7f09764 | 961 | node->lowered = bp_unpack_value (bp, 1); |
8b4765bf | 962 | node->analyzed = tag == LTO_cgraph_analyzed_node; |
a837268b | 963 | node->in_other_partition = bp_unpack_value (bp, 1); |
52b3b3c7 JH |
964 | if (node->in_other_partition |
965 | /* Avoid updating decl when we are seeing just inline clone. | |
966 | When inlining function that has functions already inlined into it, | |
967 | we produce clones of inline clones. | |
968 | ||
969 | WPA partitioning might put each clone into different unit and | |
970 | we might end up streaming inline clone from other partition | |
971 | to support clone we are interested in. */ | |
972 | && (!node->clone_of | |
973 | || node->clone_of->decl != node->decl)) | |
1c7b11d2 JH |
974 | { |
975 | DECL_EXTERNAL (node->decl) = 1; | |
976 | TREE_STATIC (node->decl) = 0; | |
977 | } | |
d7f09764 DN |
978 | node->alias = bp_unpack_value (bp, 1); |
979 | node->finalized_by_frontend = bp_unpack_value (bp, 1); | |
5fefcf92 | 980 | node->frequency = (enum node_frequency)bp_unpack_value (bp, 2); |
051f8cc6 | 981 | node->resolution = resolution; |
d7f09764 DN |
982 | } |
983 | ||
2942c502 JH |
984 | /* Output the part of the cgraph in SET. */ |
985 | ||
2f41ecf5 | 986 | static void |
369451ec | 987 | output_varpool (cgraph_node_set set, varpool_node_set vset) |
2942c502 | 988 | { |
2f41ecf5 JH |
989 | struct lto_simple_output_block *ob = lto_create_simple_output_block (LTO_section_varpool); |
990 | lto_varpool_encoder_t varpool_encoder = ob->decl_state->varpool_node_encoder; | |
991 | int len = lto_varpool_encoder_size (varpool_encoder), i; | |
2942c502 JH |
992 | |
993 | lto_output_uleb128_stream (ob->main_stream, len); | |
994 | ||
995 | /* Write out the nodes. We must first output a node and then its clones, | |
996 | otherwise at a time reading back the node there would be nothing to clone | |
997 | from. */ | |
2f41ecf5 JH |
998 | for (i = 0; i < len; i++) |
999 | { | |
1000 | lto_output_varpool_node (ob, lto_varpool_encoder_deref (varpool_encoder, i), | |
9f90e80a | 1001 | varpool_encoder, |
369451ec | 1002 | set, vset); |
2f41ecf5 | 1003 | } |
2942c502 JH |
1004 | |
1005 | lto_destroy_simple_output_block (ob); | |
1006 | } | |
d7f09764 | 1007 | |
b8698a0f | 1008 | /* Read a node from input_block IB. TAG is the node's tag just read. |
d7f09764 | 1009 | Return the node read or overwriten. */ |
b8698a0f | 1010 | |
d7f09764 DN |
1011 | static struct cgraph_node * |
1012 | input_node (struct lto_file_decl_data *file_data, | |
1013 | struct lto_input_block *ib, | |
91fbf0c7 JH |
1014 | enum LTO_cgraph_tags tag, |
1015 | VEC(cgraph_node_ptr, heap) *nodes) | |
d7f09764 DN |
1016 | { |
1017 | tree fn_decl; | |
1018 | struct cgraph_node *node; | |
2465dcc2 | 1019 | struct bitpack_d bp; |
d7f09764 DN |
1020 | int stack_size = 0; |
1021 | unsigned decl_index; | |
b66887e4 | 1022 | int ref = LCC_NOT_FOUND, ref2 = LCC_NOT_FOUND; |
d7f09764 DN |
1023 | int self_time = 0; |
1024 | int self_size = 0; | |
1025 | int time_inlining_benefit = 0; | |
1026 | int size_inlining_benefit = 0; | |
b2583345 | 1027 | unsigned long same_body_count = 0; |
91fbf0c7 | 1028 | int clone_ref; |
051f8cc6 | 1029 | enum ld_plugin_symbol_resolution resolution; |
d7f09764 | 1030 | |
91fbf0c7 | 1031 | clone_ref = lto_input_sleb128 (ib); |
d7f09764 DN |
1032 | |
1033 | decl_index = lto_input_uleb128 (ib); | |
1034 | fn_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index); | |
1035 | ||
91fbf0c7 JH |
1036 | if (clone_ref != LCC_NOT_FOUND) |
1037 | { | |
1038 | node = cgraph_clone_node (VEC_index (cgraph_node_ptr, nodes, clone_ref), fn_decl, | |
1039 | 0, CGRAPH_FREQ_BASE, 0, false, NULL); | |
1040 | } | |
d7f09764 DN |
1041 | else |
1042 | node = cgraph_node (fn_decl); | |
1043 | ||
1044 | node->count = lto_input_sleb128 (ib); | |
b8698a0f | 1045 | |
8b4765bf | 1046 | if (tag == LTO_cgraph_analyzed_node) |
d7f09764 DN |
1047 | { |
1048 | stack_size = lto_input_sleb128 (ib); | |
1049 | self_size = lto_input_sleb128 (ib); | |
1050 | size_inlining_benefit = lto_input_sleb128 (ib); | |
1051 | self_time = lto_input_sleb128 (ib); | |
1052 | time_inlining_benefit = lto_input_sleb128 (ib); | |
8b4765bf JH |
1053 | |
1054 | ref = lto_input_sleb128 (ib); | |
d7f09764 DN |
1055 | } |
1056 | ||
b66887e4 | 1057 | ref2 = lto_input_sleb128 (ib); |
d7f09764 DN |
1058 | |
1059 | /* Make sure that we have not read this node before. Nodes that | |
1060 | have already been read will have their tag stored in the 'aux' | |
1061 | field. Since built-in functions can be referenced in multiple | |
1062 | functions, they are expected to be read more than once. */ | |
1063 | if (node->aux && !DECL_IS_BUILTIN (node->decl)) | |
1064 | internal_error ("bytecode stream: found multiple instances of cgraph " | |
1065 | "node %d", node->uid); | |
1066 | ||
2465dcc2 | 1067 | bp = lto_input_bitpack (ib); |
051f8cc6 | 1068 | resolution = (enum ld_plugin_symbol_resolution)lto_input_uleb128 (ib); |
2465dcc2 | 1069 | input_overwrite_node (file_data, node, tag, &bp, stack_size, self_time, |
d7f09764 | 1070 | time_inlining_benefit, self_size, |
051f8cc6 | 1071 | size_inlining_benefit, resolution); |
d7f09764 | 1072 | |
d7f09764 DN |
1073 | /* Store a reference for now, and fix up later to be a pointer. */ |
1074 | node->global.inlined_to = (cgraph_node_ptr) (intptr_t) ref; | |
1075 | ||
b66887e4 JJ |
1076 | /* Store a reference for now, and fix up later to be a pointer. */ |
1077 | node->same_comdat_group = (cgraph_node_ptr) (intptr_t) ref2; | |
1078 | ||
2465dcc2 | 1079 | same_body_count = lto_input_uleb128 (ib); |
b2583345 JJ |
1080 | while (same_body_count-- > 0) |
1081 | { | |
1082 | tree alias_decl; | |
6744a6ab | 1083 | int type; |
051f8cc6 | 1084 | struct cgraph_node *alias; |
b2583345 JJ |
1085 | decl_index = lto_input_uleb128 (ib); |
1086 | alias_decl = lto_file_decl_data_get_fn_decl (file_data, decl_index); | |
6744a6ab JH |
1087 | type = lto_input_uleb128 (ib); |
1088 | if (!type) | |
ede51b1f RG |
1089 | { |
1090 | tree real_alias; | |
1091 | decl_index = lto_input_uleb128 (ib); | |
1092 | real_alias = lto_file_decl_data_get_fn_decl (file_data, decl_index); | |
051f8cc6 | 1093 | alias = cgraph_same_body_alias (alias_decl, real_alias); |
ede51b1f | 1094 | } |
6744a6ab JH |
1095 | else |
1096 | { | |
1097 | HOST_WIDE_INT fixed_offset = lto_input_uleb128 (ib); | |
1098 | HOST_WIDE_INT virtual_value = lto_input_uleb128 (ib); | |
1099 | tree real_alias; | |
1100 | decl_index = lto_input_uleb128 (ib); | |
1101 | real_alias = lto_file_decl_data_get_fn_decl (file_data, decl_index); | |
051f8cc6 JH |
1102 | alias = cgraph_add_thunk (alias_decl, fn_decl, type & 2, fixed_offset, |
1103 | virtual_value, | |
1104 | (type & 4) ? size_int (virtual_value) : NULL_TREE, | |
1105 | real_alias); | |
6744a6ab | 1106 | } |
051f8cc6 | 1107 | alias->resolution = (enum ld_plugin_symbol_resolution)lto_input_uleb128 (ib); |
b2583345 | 1108 | } |
d7f09764 DN |
1109 | return node; |
1110 | } | |
1111 | ||
2942c502 JH |
1112 | /* Read a node from input_block IB. TAG is the node's tag just read. |
1113 | Return the node read or overwriten. */ | |
1114 | ||
1115 | static struct varpool_node * | |
1116 | input_varpool_node (struct lto_file_decl_data *file_data, | |
1117 | struct lto_input_block *ib) | |
1118 | { | |
1119 | int decl_index; | |
1120 | tree var_decl; | |
1121 | struct varpool_node *node; | |
2465dcc2 | 1122 | struct bitpack_d bp; |
2942c502 JH |
1123 | bool aliases_p; |
1124 | int count; | |
9f90e80a | 1125 | int ref = LCC_NOT_FOUND; |
2942c502 JH |
1126 | |
1127 | decl_index = lto_input_uleb128 (ib); | |
1128 | var_decl = lto_file_decl_data_get_var_decl (file_data, decl_index); | |
1129 | node = varpool_node (var_decl); | |
d4c0c9f6 | 1130 | node->lto_file_data = file_data; |
2942c502 JH |
1131 | |
1132 | bp = lto_input_bitpack (ib); | |
2465dcc2 RG |
1133 | node->externally_visible = bp_unpack_value (&bp, 1); |
1134 | node->force_output = bp_unpack_value (&bp, 1); | |
1135 | node->finalized = bp_unpack_value (&bp, 1); | |
1136 | node->alias = bp_unpack_value (&bp, 1); | |
2f41ecf5 | 1137 | node->analyzed = node->finalized; |
2465dcc2 RG |
1138 | node->used_from_other_partition = bp_unpack_value (&bp, 1); |
1139 | node->in_other_partition = bp_unpack_value (&bp, 1); | |
1c7b11d2 JH |
1140 | if (node->in_other_partition) |
1141 | { | |
1142 | DECL_EXTERNAL (node->decl) = 1; | |
1143 | TREE_STATIC (node->decl) = 0; | |
1144 | } | |
2465dcc2 | 1145 | aliases_p = bp_unpack_value (&bp, 1); |
2942c502 JH |
1146 | if (node->finalized) |
1147 | varpool_mark_needed_node (node); | |
9f90e80a JH |
1148 | ref = lto_input_sleb128 (ib); |
1149 | /* Store a reference for now, and fix up later to be a pointer. */ | |
1150 | node->same_comdat_group = (struct varpool_node *) (intptr_t) ref; | |
051f8cc6 | 1151 | node->resolution = (enum ld_plugin_symbol_resolution)lto_input_uleb128 (ib); |
2942c502 JH |
1152 | if (aliases_p) |
1153 | { | |
1154 | count = lto_input_uleb128 (ib); | |
1155 | for (; count > 0; count --) | |
1156 | { | |
1157 | tree decl = lto_file_decl_data_get_var_decl (file_data, | |
1158 | lto_input_uleb128 (ib)); | |
051f8cc6 JH |
1159 | struct varpool_node *alias; |
1160 | alias = varpool_extra_name_alias (decl, var_decl); | |
1161 | alias->resolution = (enum ld_plugin_symbol_resolution)lto_input_uleb128 (ib); | |
2942c502 JH |
1162 | } |
1163 | } | |
1164 | return node; | |
1165 | } | |
1166 | ||
369451ec JH |
1167 | /* Read a node from input_block IB. TAG is the node's tag just read. |
1168 | Return the node read or overwriten. */ | |
1169 | ||
1170 | static void | |
1171 | input_ref (struct lto_input_block *ib, | |
1172 | struct cgraph_node *refering_node, | |
1173 | struct varpool_node *refering_varpool_node, | |
1174 | VEC(cgraph_node_ptr, heap) *nodes, | |
1175 | VEC(varpool_node_ptr, heap) *varpool_nodes) | |
1176 | { | |
1177 | struct cgraph_node *node = NULL; | |
1178 | struct varpool_node *varpool_node = NULL; | |
2465dcc2 | 1179 | struct bitpack_d bp; |
369451ec JH |
1180 | enum ipa_ref_type type; |
1181 | enum ipa_ref_use use; | |
1182 | ||
1183 | bp = lto_input_bitpack (ib); | |
2465dcc2 RG |
1184 | type = (enum ipa_ref_type) bp_unpack_value (&bp, 1); |
1185 | use = (enum ipa_ref_use) bp_unpack_value (&bp, 2); | |
369451ec JH |
1186 | if (type == IPA_REF_CGRAPH) |
1187 | node = VEC_index (cgraph_node_ptr, nodes, lto_input_sleb128 (ib)); | |
1188 | else | |
1189 | varpool_node = VEC_index (varpool_node_ptr, varpool_nodes, lto_input_sleb128 (ib)); | |
1190 | ipa_record_reference (refering_node, refering_varpool_node, | |
1191 | node, varpool_node, use, NULL); | |
1192 | } | |
d7f09764 | 1193 | |
e33c6cd6 MJ |
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). */ | |
d7f09764 DN |
1198 | |
1199 | static void | |
e33c6cd6 MJ |
1200 | input_edge (struct lto_input_block *ib, VEC(cgraph_node_ptr, heap) *nodes, |
1201 | bool indirect) | |
d7f09764 DN |
1202 | { |
1203 | struct cgraph_node *caller, *callee; | |
1204 | struct cgraph_edge *edge; | |
1205 | unsigned int stmt_id; | |
1206 | gcov_type count; | |
1207 | int freq; | |
1208 | unsigned int nest; | |
1209 | cgraph_inline_failed_t inline_failed; | |
2465dcc2 | 1210 | struct bitpack_d bp; |
5f902d76 | 1211 | int ecf_flags = 0; |
d7f09764 DN |
1212 | |
1213 | caller = VEC_index (cgraph_node_ptr, nodes, lto_input_sleb128 (ib)); | |
1214 | if (caller == NULL || caller->decl == NULL_TREE) | |
1215 | internal_error ("bytecode stream: no caller found while reading edge"); | |
1216 | ||
e33c6cd6 MJ |
1217 | if (!indirect) |
1218 | { | |
1219 | callee = VEC_index (cgraph_node_ptr, nodes, lto_input_sleb128 (ib)); | |
1220 | if (callee == NULL || callee->decl == NULL_TREE) | |
1221 | internal_error ("bytecode stream: no callee found while reading edge"); | |
1222 | } | |
1223 | else | |
1224 | callee = NULL; | |
d7f09764 | 1225 | |
d7f09764 DN |
1226 | count = (gcov_type) lto_input_sleb128 (ib); |
1227 | ||
1228 | bp = lto_input_bitpack (ib); | |
2465dcc2 RG |
1229 | stmt_id = (unsigned int) bp_unpack_value (&bp, HOST_BITS_PER_INT); |
1230 | inline_failed = (cgraph_inline_failed_t) bp_unpack_value (&bp, | |
d7f09764 | 1231 | HOST_BITS_PER_INT); |
2465dcc2 RG |
1232 | freq = (int) bp_unpack_value (&bp, HOST_BITS_PER_INT); |
1233 | nest = (unsigned) bp_unpack_value (&bp, 30); | |
d7f09764 | 1234 | |
e33c6cd6 | 1235 | if (indirect) |
5f902d76 | 1236 | edge = cgraph_create_indirect_edge (caller, NULL, 0, count, freq, nest); |
e33c6cd6 MJ |
1237 | else |
1238 | edge = cgraph_create_edge (caller, callee, NULL, count, freq, nest); | |
1239 | ||
2465dcc2 | 1240 | edge->indirect_inlining_edge = bp_unpack_value (&bp, 1); |
d7f09764 DN |
1241 | edge->lto_stmt_uid = stmt_id; |
1242 | edge->inline_failed = inline_failed; | |
2465dcc2 RG |
1243 | edge->call_stmt_cannot_inline_p = bp_unpack_value (&bp, 1); |
1244 | edge->can_throw_external = bp_unpack_value (&bp, 1); | |
5f902d76 JH |
1245 | if (indirect) |
1246 | { | |
2465dcc2 | 1247 | if (bp_unpack_value (&bp, 1)) |
5f902d76 | 1248 | ecf_flags |= ECF_CONST; |
2465dcc2 | 1249 | if (bp_unpack_value (&bp, 1)) |
5f902d76 | 1250 | ecf_flags |= ECF_PURE; |
2465dcc2 | 1251 | if (bp_unpack_value (&bp, 1)) |
5f902d76 | 1252 | ecf_flags |= ECF_NORETURN; |
2465dcc2 | 1253 | if (bp_unpack_value (&bp, 1)) |
5f902d76 | 1254 | ecf_flags |= ECF_MALLOC; |
2465dcc2 | 1255 | if (bp_unpack_value (&bp, 1)) |
5f902d76 | 1256 | ecf_flags |= ECF_NOTHROW; |
2465dcc2 | 1257 | if (bp_unpack_value (&bp, 1)) |
5f902d76 JH |
1258 | ecf_flags |= ECF_RETURNS_TWICE; |
1259 | edge->indirect_info->ecf_flags = ecf_flags; | |
1260 | } | |
d7f09764 DN |
1261 | } |
1262 | ||
1263 | ||
1264 | /* Read a cgraph from IB using the info in FILE_DATA. */ | |
1265 | ||
2f41ecf5 | 1266 | static VEC(cgraph_node_ptr, heap) * |
d7f09764 DN |
1267 | input_cgraph_1 (struct lto_file_decl_data *file_data, |
1268 | struct lto_input_block *ib) | |
1269 | { | |
1270 | enum LTO_cgraph_tags tag; | |
1271 | VEC(cgraph_node_ptr, heap) *nodes = NULL; | |
1272 | struct cgraph_node *node; | |
1273 | unsigned i; | |
a9cc4458 | 1274 | unsigned HOST_WIDE_INT len; |
d7f09764 DN |
1275 | |
1276 | tag = (enum LTO_cgraph_tags) lto_input_uleb128 (ib); | |
1277 | while (tag) | |
1278 | { | |
1279 | if (tag == LTO_cgraph_edge) | |
e33c6cd6 MJ |
1280 | input_edge (ib, nodes, false); |
1281 | else if (tag == LTO_cgraph_indirect_edge) | |
1282 | input_edge (ib, nodes, true); | |
b8698a0f | 1283 | else |
d7f09764 | 1284 | { |
91fbf0c7 | 1285 | node = input_node (file_data, ib, tag,nodes); |
d7f09764 DN |
1286 | if (node == NULL || node->decl == NULL_TREE) |
1287 | internal_error ("bytecode stream: found empty cgraph node"); | |
1288 | VEC_safe_push (cgraph_node_ptr, heap, nodes, node); | |
1289 | lto_cgraph_encoder_encode (file_data->cgraph_node_encoder, node); | |
1290 | } | |
1291 | ||
1292 | tag = (enum LTO_cgraph_tags) lto_input_uleb128 (ib); | |
1293 | } | |
1294 | ||
a9cc4458 RG |
1295 | /* Input toplevel asms. */ |
1296 | len = lto_input_uleb128 (ib); | |
1297 | while (len) | |
1298 | { | |
1299 | char *str = (char *)xmalloc (len + 1); | |
1300 | for (i = 0; i < len; ++i) | |
1301 | str[i] = lto_input_1_unsigned (ib); | |
1302 | cgraph_add_asm_node (build_string (len, str)); | |
1303 | free (str); | |
1304 | ||
1305 | len = lto_input_uleb128 (ib); | |
1306 | } | |
d1f6261f JH |
1307 | /* AUX pointers should be all non-zero for nodes read from the stream. */ |
1308 | #ifdef ENABLE_CHECKING | |
1309 | FOR_EACH_VEC_ELT (cgraph_node_ptr, nodes, i, node) | |
1310 | gcc_assert (node->aux); | |
1311 | #endif | |
ac47786e | 1312 | FOR_EACH_VEC_ELT (cgraph_node_ptr, nodes, i, node) |
d7f09764 | 1313 | { |
b66887e4 | 1314 | int ref = (int) (intptr_t) node->global.inlined_to; |
d7f09764 | 1315 | |
d1f6261f JH |
1316 | /* We share declaration of builtins, so we may read same node twice. */ |
1317 | if (!node->aux) | |
1318 | continue; | |
1319 | node->aux = NULL; | |
1320 | ||
d7f09764 DN |
1321 | /* Fixup inlined_to from reference to pointer. */ |
1322 | if (ref != LCC_NOT_FOUND) | |
1323 | node->global.inlined_to = VEC_index (cgraph_node_ptr, nodes, ref); | |
1324 | else | |
1325 | node->global.inlined_to = NULL; | |
b66887e4 JJ |
1326 | |
1327 | ref = (int) (intptr_t) node->same_comdat_group; | |
1328 | ||
1329 | /* Fixup same_comdat_group from reference to pointer. */ | |
1330 | if (ref != LCC_NOT_FOUND) | |
1331 | node->same_comdat_group = VEC_index (cgraph_node_ptr, nodes, ref); | |
1332 | else | |
1333 | node->same_comdat_group = NULL; | |
d7f09764 | 1334 | } |
d1f6261f JH |
1335 | FOR_EACH_VEC_ELT (cgraph_node_ptr, nodes, i, node) |
1336 | node->aux = (void *)1; | |
2f41ecf5 | 1337 | return nodes; |
d7f09764 DN |
1338 | } |
1339 | ||
2942c502 JH |
1340 | /* Read a varpool from IB using the info in FILE_DATA. */ |
1341 | ||
2f41ecf5 | 1342 | static VEC(varpool_node_ptr, heap) * |
2942c502 JH |
1343 | input_varpool_1 (struct lto_file_decl_data *file_data, |
1344 | struct lto_input_block *ib) | |
1345 | { | |
1346 | unsigned HOST_WIDE_INT len; | |
2f41ecf5 | 1347 | VEC(varpool_node_ptr, heap) *varpool = NULL; |
9f90e80a JH |
1348 | int i; |
1349 | struct varpool_node *node; | |
2942c502 JH |
1350 | |
1351 | len = lto_input_uleb128 (ib); | |
1352 | while (len) | |
1353 | { | |
2f41ecf5 JH |
1354 | VEC_safe_push (varpool_node_ptr, heap, varpool, |
1355 | input_varpool_node (file_data, ib)); | |
2942c502 JH |
1356 | len--; |
1357 | } | |
d1f6261f JH |
1358 | #ifdef ENABLE_CHECKING |
1359 | FOR_EACH_VEC_ELT (varpool_node_ptr, varpool, i, node) | |
1360 | gcc_assert (!node->aux); | |
1361 | #endif | |
ac47786e | 1362 | FOR_EACH_VEC_ELT (varpool_node_ptr, varpool, i, node) |
9f90e80a JH |
1363 | { |
1364 | int ref = (int) (intptr_t) node->same_comdat_group; | |
d1f6261f JH |
1365 | /* We share declaration of builtins, so we may read same node twice. */ |
1366 | if (node->aux) | |
1367 | continue; | |
1368 | node->aux = (void *)1; | |
9f90e80a JH |
1369 | |
1370 | /* Fixup same_comdat_group from reference to pointer. */ | |
1371 | if (ref != LCC_NOT_FOUND) | |
1372 | node->same_comdat_group = VEC_index (varpool_node_ptr, varpool, ref); | |
1373 | else | |
1374 | node->same_comdat_group = NULL; | |
1375 | } | |
d1f6261f JH |
1376 | FOR_EACH_VEC_ELT (varpool_node_ptr, varpool, i, node) |
1377 | node->aux = NULL; | |
2f41ecf5 | 1378 | return varpool; |
2942c502 JH |
1379 | } |
1380 | ||
369451ec JH |
1381 | /* Input ipa_refs. */ |
1382 | ||
1383 | static void | |
1384 | input_refs (struct lto_input_block *ib, | |
1385 | VEC(cgraph_node_ptr, heap) *nodes, | |
1386 | VEC(varpool_node_ptr, heap) *varpool) | |
1387 | { | |
1388 | int count; | |
1389 | int idx; | |
1390 | while (true) | |
1391 | { | |
1392 | struct cgraph_node *node; | |
1393 | count = lto_input_uleb128 (ib); | |
1394 | if (!count) | |
1395 | break; | |
1396 | idx = lto_input_uleb128 (ib); | |
1397 | node = VEC_index (cgraph_node_ptr, nodes, idx); | |
1398 | while (count) | |
1399 | { | |
1400 | input_ref (ib, node, NULL, nodes, varpool); | |
1401 | count--; | |
1402 | } | |
1403 | } | |
1404 | while (true) | |
1405 | { | |
1406 | struct varpool_node *node; | |
1407 | count = lto_input_uleb128 (ib); | |
1408 | if (!count) | |
1409 | break; | |
1410 | node = VEC_index (varpool_node_ptr, varpool, lto_input_uleb128 (ib)); | |
1411 | while (count) | |
1412 | { | |
1413 | input_ref (ib, NULL, node, nodes, varpool); | |
1414 | count--; | |
1415 | } | |
1416 | } | |
1417 | } | |
1418 | ||
2f41ecf5 | 1419 | |
0bc1b77f JH |
1420 | static struct gcov_ctr_summary lto_gcov_summary; |
1421 | ||
1422 | /* Input profile_info from IB. */ | |
1423 | static void | |
1424 | input_profile_summary (struct lto_input_block *ib) | |
1425 | { | |
1426 | unsigned int runs = lto_input_uleb128 (ib); | |
1427 | if (runs) | |
1428 | { | |
1429 | if (!profile_info) | |
1430 | { | |
1431 | profile_info = <o_gcov_summary; | |
1432 | lto_gcov_summary.runs = runs; | |
1433 | lto_gcov_summary.sum_all = lto_input_sleb128 (ib); | |
1434 | lto_gcov_summary.run_max = lto_input_sleb128 (ib); | |
1435 | lto_gcov_summary.sum_max = lto_input_sleb128 (ib); | |
1436 | } | |
1437 | /* We can support this by scaling all counts to nearest common multiple | |
1438 | of all different runs, but it is perhaps not worth the effort. */ | |
1439 | else if (profile_info->runs != runs | |
1440 | || profile_info->sum_all != lto_input_sleb128 (ib) | |
1441 | || profile_info->run_max != lto_input_sleb128 (ib) | |
1442 | || profile_info->sum_max != lto_input_sleb128 (ib)) | |
1443 | sorry ("Combining units with different profiles is not supported."); | |
1444 | /* We allow some units to have profile and other to not have one. This will | |
1445 | just make unprofiled units to be size optimized that is sane. */ | |
1446 | } | |
1447 | ||
1448 | } | |
d7f09764 DN |
1449 | |
1450 | /* Input and merge the cgraph from each of the .o files passed to | |
1451 | lto1. */ | |
1452 | ||
1453 | void | |
1454 | input_cgraph (void) | |
1455 | { | |
1456 | struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); | |
1457 | struct lto_file_decl_data *file_data; | |
1458 | unsigned int j = 0; | |
1459 | struct cgraph_node *node; | |
1460 | ||
1461 | while ((file_data = file_data_vec[j++])) | |
1462 | { | |
1463 | const char *data; | |
1464 | size_t len; | |
1465 | struct lto_input_block *ib; | |
2f41ecf5 JH |
1466 | VEC(cgraph_node_ptr, heap) *nodes; |
1467 | VEC(varpool_node_ptr, heap) *varpool; | |
d7f09764 | 1468 | |
b8698a0f | 1469 | ib = lto_create_simple_input_block (file_data, LTO_section_cgraph, |
d7f09764 | 1470 | &data, &len); |
0bc1b77f | 1471 | input_profile_summary (ib); |
d7f09764 | 1472 | file_data->cgraph_node_encoder = lto_cgraph_encoder_new (); |
2f41ecf5 | 1473 | nodes = input_cgraph_1 (file_data, ib); |
b8698a0f | 1474 | lto_destroy_simple_input_block (file_data, LTO_section_cgraph, |
d7f09764 | 1475 | ib, data, len); |
b8698a0f | 1476 | |
2942c502 JH |
1477 | ib = lto_create_simple_input_block (file_data, LTO_section_varpool, |
1478 | &data, &len); | |
2f41ecf5 | 1479 | varpool = input_varpool_1 (file_data, ib); |
2942c502 JH |
1480 | lto_destroy_simple_input_block (file_data, LTO_section_varpool, |
1481 | ib, data, len); | |
2f41ecf5 | 1482 | |
369451ec JH |
1483 | ib = lto_create_simple_input_block (file_data, LTO_section_refs, |
1484 | &data, &len); | |
1485 | input_refs (ib, nodes, varpool); | |
1486 | lto_destroy_simple_input_block (file_data, LTO_section_refs, | |
1487 | ib, data, len); | |
922f15c2 JH |
1488 | if (flag_ltrans) |
1489 | input_cgraph_opt_summary (nodes); | |
2f41ecf5 JH |
1490 | VEC_free (cgraph_node_ptr, heap, nodes); |
1491 | VEC_free (varpool_node_ptr, heap, varpool); | |
b8698a0f | 1492 | } |
d7f09764 DN |
1493 | |
1494 | /* Clear out the aux field that was used to store enough state to | |
1495 | tell which nodes should be overwritten. */ | |
1496 | for (node = cgraph_nodes; node; node = node->next) | |
1497 | { | |
1498 | /* Some nodes may have been created by cgraph_node. This | |
1499 | happens when the callgraph contains nested functions. If the | |
1500 | node for the parent function was never emitted to the gimple | |
1501 | file, cgraph_node will create a node for it when setting the | |
1502 | context of the nested function. */ | |
1503 | if (node->local.lto_file_data) | |
1504 | node->aux = NULL; | |
1505 | } | |
1506 | } | |
922f15c2 JH |
1507 | |
1508 | /* True when we need optimization summary for NODE. */ | |
1509 | ||
1510 | static int | |
1511 | output_cgraph_opt_summary_p (struct cgraph_node *node) | |
1512 | { | |
1513 | if (!node->clone_of) | |
1514 | return false; | |
1515 | return (node->clone.tree_map | |
1516 | || node->clone.args_to_skip | |
1517 | || node->clone.combined_args_to_skip); | |
1518 | } | |
1519 | ||
1520 | /* Output optimization summary for NODE to OB. */ | |
1521 | ||
1522 | static void | |
1523 | output_node_opt_summary (struct output_block *ob, | |
1524 | struct cgraph_node *node) | |
1525 | { | |
1526 | unsigned int index; | |
1527 | bitmap_iterator bi; | |
1528 | struct ipa_replace_map *map; | |
2465dcc2 | 1529 | struct bitpack_d bp; |
922f15c2 JH |
1530 | int i; |
1531 | ||
1532 | lto_output_uleb128_stream (ob->main_stream, | |
1533 | bitmap_count_bits (node->clone.args_to_skip)); | |
1534 | EXECUTE_IF_SET_IN_BITMAP (node->clone.args_to_skip, 0, index, bi) | |
1535 | lto_output_uleb128_stream (ob->main_stream, index); | |
1536 | lto_output_uleb128_stream (ob->main_stream, | |
1537 | bitmap_count_bits (node->clone.combined_args_to_skip)); | |
1538 | EXECUTE_IF_SET_IN_BITMAP (node->clone.combined_args_to_skip, 0, index, bi) | |
1539 | lto_output_uleb128_stream (ob->main_stream, index); | |
1540 | lto_output_uleb128_stream (ob->main_stream, | |
1541 | VEC_length (ipa_replace_map_p, node->clone.tree_map)); | |
ac47786e | 1542 | FOR_EACH_VEC_ELT (ipa_replace_map_p, node->clone.tree_map, i, map) |
922f15c2 JH |
1543 | { |
1544 | int parm_num; | |
1545 | tree parm; | |
1546 | ||
1547 | for (parm_num = 0, parm = DECL_ARGUMENTS (node->decl); parm; | |
910ad8de | 1548 | parm = DECL_CHAIN (parm), parm_num++) |
922f15c2 JH |
1549 | if (map->old_tree == parm) |
1550 | break; | |
1551 | /* At the moment we assume all old trees to be PARM_DECLs, because we have no | |
1552 | mechanism to store function local declarations into summaries. */ | |
1553 | gcc_assert (parm); | |
1554 | lto_output_uleb128_stream (ob->main_stream, parm_num); | |
1555 | lto_output_tree (ob, map->new_tree, true); | |
2465dcc2 RG |
1556 | bp = bitpack_create (ob->main_stream); |
1557 | bp_pack_value (&bp, map->replace_p, 1); | |
1558 | bp_pack_value (&bp, map->ref_p, 1); | |
1559 | lto_output_bitpack (&bp); | |
922f15c2 JH |
1560 | } |
1561 | } | |
1562 | ||
1563 | /* Output optimization summaries stored in callgraph. | |
1564 | At the moment it is the clone info structure. */ | |
1565 | ||
1566 | static void | |
1567 | output_cgraph_opt_summary (void) | |
1568 | { | |
1569 | struct cgraph_node *node; | |
1570 | int i, n_nodes; | |
1571 | lto_cgraph_encoder_t encoder; | |
1572 | struct output_block *ob = create_output_block (LTO_section_cgraph_opt_sum); | |
1573 | unsigned count = 0; | |
1574 | ||
1575 | ob->cgraph_node = NULL; | |
1576 | encoder = ob->decl_state->cgraph_node_encoder; | |
1577 | n_nodes = lto_cgraph_encoder_size (encoder); | |
1578 | for (i = 0; i < n_nodes; i++) | |
1579 | if (output_cgraph_opt_summary_p (lto_cgraph_encoder_deref (encoder, i))) | |
1580 | count++; | |
1581 | lto_output_uleb128_stream (ob->main_stream, count); | |
1582 | for (i = 0; i < n_nodes; i++) | |
1583 | { | |
1584 | node = lto_cgraph_encoder_deref (encoder, i); | |
1585 | if (output_cgraph_opt_summary_p (node)) | |
1586 | { | |
1587 | lto_output_uleb128_stream (ob->main_stream, i); | |
1588 | output_node_opt_summary (ob, node); | |
1589 | } | |
1590 | } | |
1591 | produce_asm (ob, NULL); | |
1592 | destroy_output_block (ob); | |
1593 | } | |
1594 | ||
1595 | /* Input optimiation summary of NODE. */ | |
1596 | ||
1597 | static void | |
1598 | input_node_opt_summary (struct cgraph_node *node, | |
1599 | struct lto_input_block *ib_main, | |
1600 | struct data_in *data_in) | |
1601 | { | |
1602 | int i; | |
1603 | int count; | |
1604 | int bit; | |
2465dcc2 | 1605 | struct bitpack_d bp; |
922f15c2 JH |
1606 | |
1607 | count = lto_input_uleb128 (ib_main); | |
1608 | if (count) | |
1609 | node->clone.args_to_skip = BITMAP_GGC_ALLOC (); | |
1610 | for (i = 0; i < count; i++) | |
1611 | { | |
1612 | bit = lto_input_uleb128 (ib_main); | |
1613 | bitmap_set_bit (node->clone.args_to_skip, bit); | |
1614 | } | |
1615 | count = lto_input_uleb128 (ib_main); | |
1616 | if (count) | |
1617 | node->clone.combined_args_to_skip = BITMAP_GGC_ALLOC (); | |
1618 | for (i = 0; i < count; i++) | |
1619 | { | |
1620 | bit = lto_input_uleb128 (ib_main); | |
1621 | bitmap_set_bit (node->clone.combined_args_to_skip, bit); | |
1622 | } | |
1623 | count = lto_input_uleb128 (ib_main); | |
1624 | for (i = 0; i < count; i++) | |
1625 | { | |
1626 | int parm_num; | |
1627 | tree parm; | |
a9429e29 | 1628 | struct ipa_replace_map *map = ggc_alloc_ipa_replace_map (); |
922f15c2 JH |
1629 | |
1630 | VEC_safe_push (ipa_replace_map_p, gc, node->clone.tree_map, map); | |
1631 | for (parm_num = 0, parm = DECL_ARGUMENTS (node->decl); parm_num; | |
910ad8de | 1632 | parm = DECL_CHAIN (parm)) |
922f15c2 JH |
1633 | parm_num --; |
1634 | map->parm_num = lto_input_uleb128 (ib_main); | |
1635 | map->old_tree = NULL; | |
1636 | map->new_tree = lto_input_tree (ib_main, data_in); | |
1637 | bp = lto_input_bitpack (ib_main); | |
2465dcc2 RG |
1638 | map->replace_p = bp_unpack_value (&bp, 1); |
1639 | map->ref_p = bp_unpack_value (&bp, 1); | |
922f15c2 JH |
1640 | } |
1641 | } | |
1642 | ||
1643 | /* Read section in file FILE_DATA of length LEN with data DATA. */ | |
1644 | ||
1645 | static void | |
1646 | input_cgraph_opt_section (struct lto_file_decl_data *file_data, | |
1647 | const char *data, size_t len, VEC (cgraph_node_ptr, | |
1648 | heap) * nodes) | |
1649 | { | |
1650 | const struct lto_function_header *header = | |
1651 | (const struct lto_function_header *) data; | |
1652 | const int32_t cfg_offset = sizeof (struct lto_function_header); | |
1653 | const int32_t main_offset = cfg_offset + header->cfg_size; | |
1654 | const int32_t string_offset = main_offset + header->main_size; | |
1655 | struct data_in *data_in; | |
1656 | struct lto_input_block ib_main; | |
1657 | unsigned int i; | |
1658 | unsigned int count; | |
1659 | ||
1660 | LTO_INIT_INPUT_BLOCK (ib_main, (const char *) data + main_offset, 0, | |
1661 | header->main_size); | |
1662 | ||
1663 | data_in = | |
1664 | lto_data_in_create (file_data, (const char *) data + string_offset, | |
1665 | header->string_size, NULL); | |
1666 | count = lto_input_uleb128 (&ib_main); | |
1667 | ||
1668 | for (i = 0; i < count; i++) | |
1669 | { | |
1670 | int ref = lto_input_uleb128 (&ib_main); | |
1671 | input_node_opt_summary (VEC_index (cgraph_node_ptr, nodes, ref), | |
1672 | &ib_main, data_in); | |
1673 | } | |
1674 | lto_free_section_data (file_data, LTO_section_jump_functions, NULL, data, | |
1675 | len); | |
1676 | lto_data_in_delete (data_in); | |
1677 | } | |
1678 | ||
1679 | /* Input optimization summary of cgraph. */ | |
1680 | ||
1681 | static void | |
1682 | input_cgraph_opt_summary (VEC (cgraph_node_ptr, heap) * nodes) | |
1683 | { | |
1684 | struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); | |
1685 | struct lto_file_decl_data *file_data; | |
1686 | unsigned int j = 0; | |
1687 | ||
1688 | while ((file_data = file_data_vec[j++])) | |
1689 | { | |
1690 | size_t len; | |
1691 | const char *data = | |
1692 | lto_get_section_data (file_data, LTO_section_cgraph_opt_sum, NULL, | |
1693 | &len); | |
1694 | ||
1695 | if (data) | |
1696 | input_cgraph_opt_section (file_data, data, len, nodes); | |
1697 | } | |
1698 | } |