rebase
[gcc.git] / gcc / lto-streamer-out.c
1 /* Write the GIMPLE representation to a file stream.
2
3 Copyright 2009, 2010 Free Software Foundation, Inc.
4 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
5 Re-implemented by Diego Novillo <dnovillo@google.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 "tree.h"
28 #include "expr.h"
29 #include "flags.h"
30 #include "params.h"
31 #include "input.h"
32 #include "hashtab.h"
33 #include "basic-block.h"
34 #include "tree-flow.h"
35 #include "tree-pass.h"
36 #include "cgraph.h"
37 #include "function.h"
38 #include "ggc.h"
39 #include "diagnostic-core.h"
40 #include "except.h"
41 #include "vec.h"
42 #include "lto-symtab.h"
43 #include "lto-streamer.h"
44 #include "data-streamer.h"
45 #include "gimple-streamer.h"
46 #include "tree-streamer.h"
47 #include "streamer-hooks.h"
48
49
50 /* Clear the line info stored in DATA_IN. */
51
52 static void
53 clear_line_info (struct output_block *ob)
54 {
55 ob->current_file = NULL;
56 ob->current_line = 0;
57 ob->current_col = 0;
58 }
59
60
61 /* Create the output block and return it. SECTION_TYPE is
62 LTO_section_function_body or LTO_static_initializer. */
63
64 struct output_block *
65 create_output_block (enum lto_section_type section_type)
66 {
67 struct output_block *ob = XCNEW (struct output_block);
68
69 ob->section_type = section_type;
70 ob->decl_state = lto_get_out_decl_state ();
71 ob->main_stream = XCNEW (struct lto_output_stream);
72 ob->string_stream = XCNEW (struct lto_output_stream);
73 ob->writer_cache = lto_streamer_cache_create ();
74
75 if (section_type == LTO_section_function_body)
76 ob->cfg_stream = XCNEW (struct lto_output_stream);
77
78 clear_line_info (ob);
79
80 ob->string_hash_table = htab_create (37, hash_string_slot_node,
81 eq_string_slot_node, NULL);
82 gcc_obstack_init (&ob->obstack);
83
84 return ob;
85 }
86
87
88 /* Destroy the output block OB. */
89
90 void
91 destroy_output_block (struct output_block *ob)
92 {
93 enum lto_section_type section_type = ob->section_type;
94
95 htab_delete (ob->string_hash_table);
96
97 free (ob->main_stream);
98 free (ob->string_stream);
99 if (section_type == LTO_section_function_body)
100 free (ob->cfg_stream);
101
102 lto_streamer_cache_delete (ob->writer_cache);
103 obstack_free (&ob->obstack, NULL);
104
105 free (ob);
106 }
107
108
109 /* Look up NODE in the type table and write the index for it to OB. */
110
111 static void
112 output_type_ref (struct output_block *ob, tree node)
113 {
114 output_record_start (ob, LTO_type_ref);
115 lto_output_type_ref_index (ob->decl_state, ob->main_stream, node);
116 }
117
118
119 /* Return true if tree node T is written to various tables. For these
120 nodes, we sometimes want to write their phyiscal representation
121 (via lto_output_tree), and sometimes we need to emit an index
122 reference into a table (via lto_output_tree_ref). */
123
124 static bool
125 tree_is_indexable (tree t)
126 {
127 if (TREE_CODE (t) == PARM_DECL)
128 return false;
129 else if (TREE_CODE (t) == VAR_DECL && decl_function_context (t)
130 && !TREE_STATIC (t))
131 return false;
132 else
133 return (TYPE_P (t) || DECL_P (t) || TREE_CODE (t) == SSA_NAME);
134 }
135
136
137 /* Output info about new location into bitpack BP.
138 After outputting bitpack, lto_output_location_data has
139 to be done to output actual data. */
140
141 static inline void
142 lto_output_location_bitpack (struct bitpack_d *bp,
143 struct output_block *ob,
144 location_t loc)
145 {
146 expanded_location xloc;
147
148 bp_pack_value (bp, loc == UNKNOWN_LOCATION, 1);
149 if (loc == UNKNOWN_LOCATION)
150 return;
151
152 xloc = expand_location (loc);
153
154 bp_pack_value (bp, ob->current_file != xloc.file, 1);
155 if (ob->current_file != xloc.file)
156 bp_pack_var_len_unsigned (bp, lto_string_index (ob,
157 xloc.file,
158 strlen (xloc.file) + 1,
159 true));
160 ob->current_file = xloc.file;
161
162 bp_pack_value (bp, ob->current_line != xloc.line, 1);
163 if (ob->current_line != xloc.line)
164 bp_pack_var_len_unsigned (bp, xloc.line);
165 ob->current_line = xloc.line;
166
167 bp_pack_value (bp, ob->current_col != xloc.column, 1);
168 if (ob->current_col != xloc.column)
169 bp_pack_var_len_unsigned (bp, xloc.column);
170 ob->current_col = xloc.column;
171 }
172
173
174 /* Emit location LOC to output block OB.
175 When bitpack is handy, it is more space effecient to call
176 lto_output_location_bitpack with existing bitpack. */
177
178 void
179 lto_output_location (struct output_block *ob, location_t loc)
180 {
181 struct bitpack_d bp = bitpack_create (ob->main_stream);
182 lto_output_location_bitpack (&bp, ob, loc);
183 lto_output_bitpack (&bp);
184 }
185
186
187 /* If EXPR is an indexable tree node, output a reference to it to
188 output block OB. Otherwise, output the physical representation of
189 EXPR to OB. */
190
191 void
192 lto_output_tree_ref (struct output_block *ob, tree expr)
193 {
194 enum tree_code code;
195
196 if (expr == NULL_TREE)
197 {
198 output_record_start (ob, LTO_null);
199 return;
200 }
201
202 if (!tree_is_indexable (expr))
203 {
204 /* Even though we are emitting the physical representation of
205 EXPR, its leaves must be emitted as references. */
206 lto_output_tree (ob, expr, true);
207 return;
208 }
209
210 if (TYPE_P (expr))
211 {
212 output_type_ref (ob, expr);
213 return;
214 }
215
216 code = TREE_CODE (expr);
217 switch (code)
218 {
219 case SSA_NAME:
220 output_record_start (ob, LTO_ssa_name_ref);
221 output_uleb128 (ob, SSA_NAME_VERSION (expr));
222 break;
223
224 case FIELD_DECL:
225 output_record_start (ob, LTO_field_decl_ref);
226 lto_output_field_decl_index (ob->decl_state, ob->main_stream, expr);
227 break;
228
229 case FUNCTION_DECL:
230 output_record_start (ob, LTO_function_decl_ref);
231 lto_output_fn_decl_index (ob->decl_state, ob->main_stream, expr);
232 break;
233
234 case VAR_DECL:
235 case DEBUG_EXPR_DECL:
236 gcc_assert (decl_function_context (expr) == NULL
237 || TREE_STATIC (expr));
238 output_record_start (ob, LTO_global_decl_ref);
239 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
240 break;
241
242 case CONST_DECL:
243 output_record_start (ob, LTO_const_decl_ref);
244 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
245 break;
246
247 case IMPORTED_DECL:
248 gcc_assert (decl_function_context (expr) == NULL);
249 output_record_start (ob, LTO_imported_decl_ref);
250 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
251 break;
252
253 case TYPE_DECL:
254 output_record_start (ob, LTO_type_decl_ref);
255 lto_output_type_decl_index (ob->decl_state, ob->main_stream, expr);
256 break;
257
258 case NAMESPACE_DECL:
259 output_record_start (ob, LTO_namespace_decl_ref);
260 lto_output_namespace_decl_index (ob->decl_state, ob->main_stream, expr);
261 break;
262
263 case LABEL_DECL:
264 output_record_start (ob, LTO_label_decl_ref);
265 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
266 break;
267
268 case RESULT_DECL:
269 output_record_start (ob, LTO_result_decl_ref);
270 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
271 break;
272
273 case TRANSLATION_UNIT_DECL:
274 output_record_start (ob, LTO_translation_unit_decl_ref);
275 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
276 break;
277
278 default:
279 {
280 /* See if the streamer allows this node to be indexable
281 like other global declarations. */
282 if (streamer_hooks.indexable_with_decls_p
283 && streamer_hooks.indexable_with_decls_p (expr))
284 {
285 output_record_start (ob, LTO_global_decl_ref);
286 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
287 }
288 else
289 {
290 /* No other node is indexable, so it should have been
291 handled by lto_output_tree. */
292 gcc_unreachable ();
293 }
294 }
295 }
296 }
297
298
299 /* Output to OB a list of try/catch handlers starting with FIRST. */
300
301 static void
302 output_eh_try_list (struct output_block *ob, eh_catch first)
303 {
304 eh_catch n;
305
306 for (n = first; n; n = n->next_catch)
307 {
308 output_record_start (ob, LTO_eh_catch);
309 lto_output_tree_ref (ob, n->type_list);
310 lto_output_tree_ref (ob, n->filter_list);
311 lto_output_tree_ref (ob, n->label);
312 }
313
314 output_record_start (ob, LTO_null);
315 }
316
317
318 /* Output EH region R in function FN to OB. CURR_RN is the slot index
319 that is being emitted in FN->EH->REGION_ARRAY. This is used to
320 detect EH region sharing. */
321
322 static void
323 output_eh_region (struct output_block *ob, eh_region r)
324 {
325 enum LTO_tags tag;
326
327 if (r == NULL)
328 {
329 output_record_start (ob, LTO_null);
330 return;
331 }
332
333 if (r->type == ERT_CLEANUP)
334 tag = LTO_ert_cleanup;
335 else if (r->type == ERT_TRY)
336 tag = LTO_ert_try;
337 else if (r->type == ERT_ALLOWED_EXCEPTIONS)
338 tag = LTO_ert_allowed_exceptions;
339 else if (r->type == ERT_MUST_NOT_THROW)
340 tag = LTO_ert_must_not_throw;
341 else
342 gcc_unreachable ();
343
344 output_record_start (ob, tag);
345 output_sleb128 (ob, r->index);
346
347 if (r->outer)
348 output_sleb128 (ob, r->outer->index);
349 else
350 output_zero (ob);
351
352 if (r->inner)
353 output_sleb128 (ob, r->inner->index);
354 else
355 output_zero (ob);
356
357 if (r->next_peer)
358 output_sleb128 (ob, r->next_peer->index);
359 else
360 output_zero (ob);
361
362 if (r->type == ERT_TRY)
363 {
364 output_eh_try_list (ob, r->u.eh_try.first_catch);
365 }
366 else if (r->type == ERT_ALLOWED_EXCEPTIONS)
367 {
368 lto_output_tree_ref (ob, r->u.allowed.type_list);
369 lto_output_tree_ref (ob, r->u.allowed.label);
370 output_uleb128 (ob, r->u.allowed.filter);
371 }
372 else if (r->type == ERT_MUST_NOT_THROW)
373 {
374 lto_output_tree_ref (ob, r->u.must_not_throw.failure_decl);
375 lto_output_location (ob, r->u.must_not_throw.failure_loc);
376 }
377
378 if (r->landing_pads)
379 output_sleb128 (ob, r->landing_pads->index);
380 else
381 output_zero (ob);
382 }
383
384
385 /* Output landing pad LP to OB. */
386
387 static void
388 output_eh_lp (struct output_block *ob, eh_landing_pad lp)
389 {
390 if (lp == NULL)
391 {
392 output_record_start (ob, LTO_null);
393 return;
394 }
395
396 output_record_start (ob, LTO_eh_landing_pad);
397 output_sleb128 (ob, lp->index);
398 if (lp->next_lp)
399 output_sleb128 (ob, lp->next_lp->index);
400 else
401 output_zero (ob);
402
403 if (lp->region)
404 output_sleb128 (ob, lp->region->index);
405 else
406 output_zero (ob);
407
408 lto_output_tree_ref (ob, lp->post_landing_pad);
409 }
410
411
412 /* Output the existing eh_table to OB. */
413
414 static void
415 output_eh_regions (struct output_block *ob, struct function *fn)
416 {
417 if (fn->eh && fn->eh->region_tree)
418 {
419 unsigned i;
420 eh_region eh;
421 eh_landing_pad lp;
422 tree ttype;
423
424 output_record_start (ob, LTO_eh_table);
425
426 /* Emit the index of the root of the EH region tree. */
427 output_sleb128 (ob, fn->eh->region_tree->index);
428
429 /* Emit all the EH regions in the region array. */
430 output_sleb128 (ob, VEC_length (eh_region, fn->eh->region_array));
431 FOR_EACH_VEC_ELT (eh_region, fn->eh->region_array, i, eh)
432 output_eh_region (ob, eh);
433
434 /* Emit all landing pads. */
435 output_sleb128 (ob, VEC_length (eh_landing_pad, fn->eh->lp_array));
436 FOR_EACH_VEC_ELT (eh_landing_pad, fn->eh->lp_array, i, lp)
437 output_eh_lp (ob, lp);
438
439 /* Emit all the runtime type data. */
440 output_sleb128 (ob, VEC_length (tree, fn->eh->ttype_data));
441 FOR_EACH_VEC_ELT (tree, fn->eh->ttype_data, i, ttype)
442 lto_output_tree_ref (ob, ttype);
443
444 /* Emit the table of action chains. */
445 if (targetm.arm_eabi_unwinder)
446 {
447 tree t;
448 output_sleb128 (ob, VEC_length (tree, fn->eh->ehspec_data.arm_eabi));
449 FOR_EACH_VEC_ELT (tree, fn->eh->ehspec_data.arm_eabi, i, t)
450 lto_output_tree_ref (ob, t);
451 }
452 else
453 {
454 uchar c;
455 output_sleb128 (ob, VEC_length (uchar, fn->eh->ehspec_data.other));
456 FOR_EACH_VEC_ELT (uchar, fn->eh->ehspec_data.other, i, c)
457 lto_output_1_stream (ob->main_stream, c);
458 }
459 }
460
461 /* The LTO_null either terminates the record or indicates that there
462 are no eh_records at all. */
463 output_record_start (ob, LTO_null);
464 }
465
466
467 /* Output all of the active ssa names to the ssa_names stream. */
468
469 static void
470 output_ssa_names (struct output_block *ob, struct function *fn)
471 {
472 unsigned int i, len;
473
474 len = VEC_length (tree, SSANAMES (fn));
475 output_uleb128 (ob, len);
476
477 for (i = 1; i < len; i++)
478 {
479 tree ptr = VEC_index (tree, SSANAMES (fn), i);
480
481 if (ptr == NULL_TREE
482 || SSA_NAME_IN_FREE_LIST (ptr)
483 || !is_gimple_reg (ptr))
484 continue;
485
486 output_uleb128 (ob, i);
487 lto_output_1_stream (ob->main_stream, SSA_NAME_IS_DEFAULT_DEF (ptr));
488 lto_output_tree_ref (ob, SSA_NAME_VAR (ptr));
489 }
490
491 output_zero (ob);
492 }
493
494
495 /* Output the cfg. */
496
497 static void
498 output_cfg (struct output_block *ob, struct function *fn)
499 {
500 struct lto_output_stream *tmp_stream = ob->main_stream;
501 basic_block bb;
502
503 ob->main_stream = ob->cfg_stream;
504
505 lto_output_enum (ob->main_stream, profile_status_d, PROFILE_LAST,
506 profile_status_for_function (fn));
507
508 /* Output the number of the highest basic block. */
509 output_uleb128 (ob, last_basic_block_for_function (fn));
510
511 FOR_ALL_BB_FN (bb, fn)
512 {
513 edge_iterator ei;
514 edge e;
515
516 output_sleb128 (ob, bb->index);
517
518 /* Output the successors and the edge flags. */
519 output_uleb128 (ob, EDGE_COUNT (bb->succs));
520 FOR_EACH_EDGE (e, ei, bb->succs)
521 {
522 output_uleb128 (ob, e->dest->index);
523 output_sleb128 (ob, e->probability);
524 output_sleb128 (ob, e->count);
525 output_uleb128 (ob, e->flags);
526 }
527 }
528
529 output_sleb128 (ob, -1);
530
531 bb = ENTRY_BLOCK_PTR;
532 while (bb->next_bb)
533 {
534 output_sleb128 (ob, bb->next_bb->index);
535 bb = bb->next_bb;
536 }
537
538 output_sleb128 (ob, -1);
539
540 ob->main_stream = tmp_stream;
541 }
542
543
544 /* Create the header in the file using OB. If the section type is for
545 a function, set FN to the decl for that function. */
546
547 void
548 produce_asm (struct output_block *ob, tree fn)
549 {
550 enum lto_section_type section_type = ob->section_type;
551 struct lto_function_header header;
552 char *section_name;
553 struct lto_output_stream *header_stream;
554
555 if (section_type == LTO_section_function_body)
556 {
557 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn));
558 section_name = lto_get_section_name (section_type, name, NULL);
559 }
560 else
561 section_name = lto_get_section_name (section_type, NULL, NULL);
562
563 lto_begin_section (section_name, !flag_wpa);
564 free (section_name);
565
566 /* The entire header is stream computed here. */
567 memset (&header, 0, sizeof (struct lto_function_header));
568
569 /* Write the header. */
570 header.lto_header.major_version = LTO_major_version;
571 header.lto_header.minor_version = LTO_minor_version;
572 header.lto_header.section_type = section_type;
573
574 header.compressed_size = 0;
575
576 if (section_type == LTO_section_function_body)
577 header.cfg_size = ob->cfg_stream->total_size;
578 header.main_size = ob->main_stream->total_size;
579 header.string_size = ob->string_stream->total_size;
580
581 header_stream = XCNEW (struct lto_output_stream);
582 lto_output_data_stream (header_stream, &header, sizeof header);
583 lto_write_stream (header_stream);
584 free (header_stream);
585
586 /* Put all of the gimple and the string table out the asm file as a
587 block of text. */
588 if (section_type == LTO_section_function_body)
589 lto_write_stream (ob->cfg_stream);
590 lto_write_stream (ob->main_stream);
591 lto_write_stream (ob->string_stream);
592
593 lto_end_section ();
594 }
595
596
597 /* Output the body of function NODE->DECL. */
598
599 static void
600 output_function (struct cgraph_node *node)
601 {
602 struct bitpack_d bp;
603 tree function;
604 struct function *fn;
605 basic_block bb;
606 struct output_block *ob;
607 unsigned i;
608 tree t;
609
610 function = node->decl;
611 fn = DECL_STRUCT_FUNCTION (function);
612 ob = create_output_block (LTO_section_function_body);
613
614 clear_line_info (ob);
615 ob->cgraph_node = node;
616
617 gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
618
619 /* Set current_function_decl and cfun. */
620 current_function_decl = function;
621 push_cfun (fn);
622
623 /* Make string 0 be a NULL string. */
624 lto_output_1_stream (ob->string_stream, 0);
625
626 output_record_start (ob, LTO_function);
627
628 /* Write all the attributes for FN. */
629 bp = bitpack_create (ob->main_stream);
630 bp_pack_value (&bp, fn->is_thunk, 1);
631 bp_pack_value (&bp, fn->has_local_explicit_reg_vars, 1);
632 bp_pack_value (&bp, fn->after_tree_profile, 1);
633 bp_pack_value (&bp, fn->returns_pcc_struct, 1);
634 bp_pack_value (&bp, fn->returns_struct, 1);
635 bp_pack_value (&bp, fn->can_throw_non_call_exceptions, 1);
636 bp_pack_value (&bp, fn->always_inline_functions_inlined, 1);
637 bp_pack_value (&bp, fn->after_inlining, 1);
638 bp_pack_value (&bp, fn->stdarg, 1);
639 bp_pack_value (&bp, fn->has_nonlocal_label, 1);
640 bp_pack_value (&bp, fn->calls_alloca, 1);
641 bp_pack_value (&bp, fn->calls_setjmp, 1);
642 bp_pack_value (&bp, fn->va_list_fpr_size, 8);
643 bp_pack_value (&bp, fn->va_list_gpr_size, 8);
644 lto_output_bitpack (&bp);
645
646 /* Output the function start and end loci. */
647 lto_output_location (ob, fn->function_start_locus);
648 lto_output_location (ob, fn->function_end_locus);
649
650 /* Output current IL state of the function. */
651 output_uleb128 (ob, fn->curr_properties);
652
653 /* Output the static chain and non-local goto save area. */
654 lto_output_tree_ref (ob, fn->static_chain_decl);
655 lto_output_tree_ref (ob, fn->nonlocal_goto_save_area);
656
657 /* Output all the local variables in the function. */
658 output_sleb128 (ob, VEC_length (tree, fn->local_decls));
659 FOR_EACH_VEC_ELT (tree, fn->local_decls, i, t)
660 lto_output_tree_ref (ob, t);
661
662 /* Output the head of the arguments list. */
663 lto_output_tree_ref (ob, DECL_ARGUMENTS (function));
664
665 /* Output all the SSA names used in the function. */
666 output_ssa_names (ob, fn);
667
668 /* Output any exception handling regions. */
669 output_eh_regions (ob, fn);
670
671 /* Output DECL_INITIAL for the function, which contains the tree of
672 lexical scopes. */
673 lto_output_tree (ob, DECL_INITIAL (function), true);
674
675 /* We will renumber the statements. The code that does this uses
676 the same ordering that we use for serializing them so we can use
677 the same code on the other end and not have to write out the
678 statement numbers. We do not assign UIDs to PHIs here because
679 virtual PHIs get re-computed on-the-fly which would make numbers
680 inconsistent. */
681 set_gimple_stmt_max_uid (cfun, 0);
682 FOR_ALL_BB (bb)
683 {
684 gimple_stmt_iterator gsi;
685 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
686 {
687 gimple stmt = gsi_stmt (gsi);
688 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
689 }
690 }
691
692 /* Output the code for the function. */
693 FOR_ALL_BB_FN (bb, fn)
694 output_bb (ob, bb, fn);
695
696 /* The terminator for this function. */
697 output_record_start (ob, LTO_null);
698
699 output_cfg (ob, fn);
700
701 /* Create a section to hold the pickled output of this function. */
702 produce_asm (ob, function);
703
704 destroy_output_block (ob);
705
706 current_function_decl = NULL;
707 pop_cfun ();
708 }
709
710
711 /* Used to pass data to trivally_defined_alias callback. */
712 struct sets {
713 cgraph_node_set set;
714 varpool_node_set vset;
715 };
716
717
718 /* Return true if alias pair P belongs to the set of cgraph nodes in
719 SET. If P is a an alias for a VAR_DECL, it can always be emitted.
720 However, for FUNCTION_DECL aliases, we should only output the pair
721 if it belongs to a function whose cgraph node is in SET.
722 Otherwise, the LTRANS phase will get into trouble when finalizing
723 aliases because the alias will refer to a function not defined in
724 the file processed by LTRANS. */
725
726 static bool
727 trivally_defined_alias (tree decl ATTRIBUTE_UNUSED,
728 tree target, void *data)
729 {
730 struct sets *set = (struct sets *) data;
731 struct cgraph_node *fnode = NULL;
732 struct varpool_node *vnode = NULL;
733
734 fnode = cgraph_node_for_asm (target);
735 if (fnode)
736 return cgraph_node_in_set_p (fnode, set->set);
737 vnode = varpool_node_for_asm (target);
738 return vnode && varpool_node_in_set_p (vnode, set->vset);
739 }
740
741 /* Return true if alias pair P should be output in the current
742 partition contains cgrpah nodes SET and varpool nodes VSET.
743 DEFINED is set of all aliases whose targets are defined in
744 the partition.
745
746 Normal aliases are output when they are defined, while WEAKREF
747 aliases are output when they are used. */
748
749 static bool
750 output_alias_pair_p (alias_pair *p, symbol_alias_set_t *defined,
751 cgraph_node_set set, varpool_node_set vset)
752 {
753 struct cgraph_node *node;
754 struct varpool_node *vnode;
755
756 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
757 {
758 if (TREE_CODE (p->decl) == VAR_DECL)
759 {
760 vnode = varpool_get_node (p->decl);
761 return (vnode
762 && referenced_from_this_partition_p (&vnode->ref_list, set, vset));
763 }
764 node = cgraph_get_node (p->decl);
765 return (node
766 && (referenced_from_this_partition_p (&node->ref_list, set, vset)
767 || reachable_from_this_partition_p (node, set)));
768 }
769 else
770 return symbol_alias_set_contains (defined, p->decl);
771 }
772
773 /* Output any unreferenced global symbol defined in SET, alias pairs
774 and labels. */
775
776 static void
777 output_unreferenced_globals (cgraph_node_set set, varpool_node_set vset)
778 {
779 struct output_block *ob;
780 alias_pair *p;
781 unsigned i;
782 symbol_alias_set_t *defined;
783 struct sets setdata;
784
785 setdata.set = set;
786 setdata.vset = vset;
787
788 ob = create_output_block (LTO_section_static_initializer);
789 ob->cgraph_node = NULL;
790
791 clear_line_info (ob);
792
793 /* Make string 0 be a NULL string. */
794 lto_output_1_stream (ob->string_stream, 0);
795
796 /* We really need to propagate in both directoins:
797 for normal aliases we propagate from first defined alias to
798 all aliases defined based on it. For weakrefs we propagate in
799 the oposite direction. */
800 defined = propagate_aliases_backward (trivally_defined_alias, &setdata);
801
802 /* Emit the alias pairs for the nodes in SET. */
803 FOR_EACH_VEC_ELT (alias_pair, alias_pairs, i, p)
804 if (output_alias_pair_p (p, defined, set, vset))
805 {
806 lto_output_tree_ref (ob, p->decl);
807 lto_output_tree_ref (ob, p->target);
808 }
809 symbol_alias_set_destroy (defined);
810
811 output_record_start (ob, LTO_null);
812
813 produce_asm (ob, NULL);
814 destroy_output_block (ob);
815 }
816
817
818 /* Copy the function body of NODE without deserializing. */
819
820 static void
821 copy_function (struct cgraph_node *node)
822 {
823 tree function = node->decl;
824 struct lto_file_decl_data *file_data = node->local.lto_file_data;
825 struct lto_output_stream *output_stream = XCNEW (struct lto_output_stream);
826 const char *data;
827 size_t len;
828 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function));
829 char *section_name =
830 lto_get_section_name (LTO_section_function_body, name, NULL);
831 size_t i, j;
832 struct lto_in_decl_state *in_state;
833 struct lto_out_decl_state *out_state = lto_get_out_decl_state ();
834
835 lto_begin_section (section_name, !flag_wpa);
836 free (section_name);
837
838 /* We may have renamed the declaration, e.g., a static function. */
839 name = lto_get_decl_name_mapping (file_data, name);
840
841 data = lto_get_section_data (file_data, LTO_section_function_body,
842 name, &len);
843 gcc_assert (data);
844
845 /* Do a bit copy of the function body. */
846 lto_output_data_stream (output_stream, data, len);
847 lto_write_stream (output_stream);
848
849 /* Copy decls. */
850 in_state =
851 lto_get_function_in_decl_state (node->local.lto_file_data, function);
852 gcc_assert (in_state);
853
854 for (i = 0; i < LTO_N_DECL_STREAMS; i++)
855 {
856 size_t n = in_state->streams[i].size;
857 tree *trees = in_state->streams[i].trees;
858 struct lto_tree_ref_encoder *encoder = &(out_state->streams[i]);
859
860 /* The out state must have the same indices and the in state.
861 So just copy the vector. All the encoders in the in state
862 must be empty where we reach here. */
863 gcc_assert (lto_tree_ref_encoder_size (encoder) == 0);
864 for (j = 0; j < n; j++)
865 VEC_safe_push (tree, heap, encoder->trees, trees[j]);
866 encoder->next_index = n;
867 }
868
869 lto_free_section_data (file_data, LTO_section_function_body, name,
870 data, len);
871 free (output_stream);
872 lto_end_section ();
873 }
874
875
876 /* Main entry point from the pass manager. */
877
878 static void
879 lto_output (cgraph_node_set set, varpool_node_set vset)
880 {
881 struct cgraph_node *node;
882 struct lto_out_decl_state *decl_state;
883 #ifdef ENABLE_CHECKING
884 bitmap output = lto_bitmap_alloc ();
885 #endif
886 int i, n_nodes;
887 lto_cgraph_encoder_t encoder = lto_get_out_decl_state ()->cgraph_node_encoder;
888
889 /* Initialize the streamer. */
890 lto_streamer_init ();
891
892 n_nodes = lto_cgraph_encoder_size (encoder);
893 /* Process only the functions with bodies. */
894 for (i = 0; i < n_nodes; i++)
895 {
896 node = lto_cgraph_encoder_deref (encoder, i);
897 if (lto_cgraph_encoder_encode_body_p (encoder, node)
898 && !node->alias
899 && !node->thunk.thunk_p)
900 {
901 #ifdef ENABLE_CHECKING
902 gcc_assert (!bitmap_bit_p (output, DECL_UID (node->decl)));
903 bitmap_set_bit (output, DECL_UID (node->decl));
904 #endif
905 decl_state = lto_new_out_decl_state ();
906 lto_push_out_decl_state (decl_state);
907 if (gimple_has_body_p (node->decl))
908 output_function (node);
909 else
910 copy_function (node);
911 gcc_assert (lto_get_out_decl_state () == decl_state);
912 lto_pop_out_decl_state ();
913 lto_record_function_out_decl_state (node->decl, decl_state);
914 }
915 }
916
917 /* Emit the callgraph after emitting function bodies. This needs to
918 be done now to make sure that all the statements in every function
919 have been renumbered so that edges can be associated with call
920 statements using the statement UIDs. */
921 output_cgraph (set, vset);
922
923 #ifdef ENABLE_CHECKING
924 lto_bitmap_free (output);
925 #endif
926 }
927
928 struct ipa_opt_pass_d pass_ipa_lto_gimple_out =
929 {
930 {
931 IPA_PASS,
932 "lto_gimple_out", /* name */
933 gate_lto_out, /* gate */
934 NULL, /* execute */
935 NULL, /* sub */
936 NULL, /* next */
937 0, /* static_pass_number */
938 TV_IPA_LTO_GIMPLE_OUT, /* tv_id */
939 0, /* properties_required */
940 0, /* properties_provided */
941 0, /* properties_destroyed */
942 0, /* todo_flags_start */
943 0 /* todo_flags_finish */
944 },
945 NULL, /* generate_summary */
946 lto_output, /* write_summary */
947 NULL, /* read_summary */
948 lto_output, /* write_optimization_summary */
949 NULL, /* read_optimization_summary */
950 NULL, /* stmt_fixup */
951 0, /* TODOs */
952 NULL, /* function_transform */
953 NULL /* variable_transform */
954 };
955
956
957 /* Write each node in encoded by ENCODER to OB, as well as those reachable
958 from it and required for correct representation of its semantics.
959 Each node in ENCODER must be a global declaration or a type. A node
960 is written only once, even if it appears multiple times in the
961 vector. Certain transitively-reachable nodes, such as those
962 representing expressions, may be duplicated, but such nodes
963 must not appear in ENCODER itself. */
964
965 static void
966 write_global_stream (struct output_block *ob,
967 struct lto_tree_ref_encoder *encoder)
968 {
969 tree t;
970 size_t index;
971 const size_t size = lto_tree_ref_encoder_size (encoder);
972
973 for (index = 0; index < size; index++)
974 {
975 t = lto_tree_ref_encoder_get_tree (encoder, index);
976 if (!lto_streamer_cache_lookup (ob->writer_cache, t, NULL))
977 lto_output_tree (ob, t, false);
978 }
979 }
980
981
982 /* Write a sequence of indices into the globals vector corresponding
983 to the trees in ENCODER. These are used by the reader to map the
984 indices used to refer to global entities within function bodies to
985 their referents. */
986
987 static void
988 write_global_references (struct output_block *ob,
989 struct lto_output_stream *ref_stream,
990 struct lto_tree_ref_encoder *encoder)
991 {
992 tree t;
993 uint32_t index;
994 const uint32_t size = lto_tree_ref_encoder_size (encoder);
995
996 /* Write size as 32-bit unsigned. */
997 lto_output_data_stream (ref_stream, &size, sizeof (int32_t));
998
999 for (index = 0; index < size; index++)
1000 {
1001 uint32_t slot_num;
1002
1003 t = lto_tree_ref_encoder_get_tree (encoder, index);
1004 lto_streamer_cache_lookup (ob->writer_cache, t, &slot_num);
1005 gcc_assert (slot_num != (unsigned)-1);
1006 lto_output_data_stream (ref_stream, &slot_num, sizeof slot_num);
1007 }
1008 }
1009
1010
1011 /* Write all the streams in an lto_out_decl_state STATE using
1012 output block OB and output stream OUT_STREAM. */
1013
1014 void
1015 lto_output_decl_state_streams (struct output_block *ob,
1016 struct lto_out_decl_state *state)
1017 {
1018 int i;
1019
1020 for (i = 0; i < LTO_N_DECL_STREAMS; i++)
1021 write_global_stream (ob, &state->streams[i]);
1022 }
1023
1024
1025 /* Write all the references in an lto_out_decl_state STATE using
1026 output block OB and output stream OUT_STREAM. */
1027
1028 void
1029 lto_output_decl_state_refs (struct output_block *ob,
1030 struct lto_output_stream *out_stream,
1031 struct lto_out_decl_state *state)
1032 {
1033 unsigned i;
1034 uint32_t ref;
1035 tree decl;
1036
1037 /* Write reference to FUNCTION_DECL. If there is not function,
1038 write reference to void_type_node. */
1039 decl = (state->fn_decl) ? state->fn_decl : void_type_node;
1040 lto_streamer_cache_lookup (ob->writer_cache, decl, &ref);
1041 gcc_assert (ref != (unsigned)-1);
1042 lto_output_data_stream (out_stream, &ref, sizeof (uint32_t));
1043
1044 for (i = 0; i < LTO_N_DECL_STREAMS; i++)
1045 write_global_references (ob, out_stream, &state->streams[i]);
1046 }
1047
1048
1049 /* Return the written size of STATE. */
1050
1051 static size_t
1052 lto_out_decl_state_written_size (struct lto_out_decl_state *state)
1053 {
1054 int i;
1055 size_t size;
1056
1057 size = sizeof (int32_t); /* fn_ref. */
1058 for (i = 0; i < LTO_N_DECL_STREAMS; i++)
1059 {
1060 size += sizeof (int32_t); /* vector size. */
1061 size += (lto_tree_ref_encoder_size (&state->streams[i])
1062 * sizeof (int32_t));
1063 }
1064 return size;
1065 }
1066
1067
1068 /* Write symbol T into STREAM in CACHE. SEEN specifies symbols we wrote
1069 so far. */
1070
1071 static void
1072 write_symbol (struct lto_streamer_cache_d *cache,
1073 struct lto_output_stream *stream,
1074 tree t, struct pointer_set_t *seen, bool alias)
1075 {
1076 const char *name;
1077 enum gcc_plugin_symbol_kind kind;
1078 enum gcc_plugin_symbol_visibility visibility;
1079 unsigned slot_num;
1080 uint64_t size;
1081 const char *comdat;
1082 unsigned char c;
1083
1084 /* None of the following kinds of symbols are needed in the
1085 symbol table. */
1086 if (!TREE_PUBLIC (t)
1087 || is_builtin_fn (t)
1088 || DECL_ABSTRACT (t)
1089 || TREE_CODE (t) == RESULT_DECL)
1090 return;
1091
1092 gcc_assert (TREE_CODE (t) == VAR_DECL
1093 || TREE_CODE (t) == FUNCTION_DECL);
1094
1095 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t));
1096
1097 /* This behaves like assemble_name_raw in varasm.c, performing the
1098 same name manipulations that ASM_OUTPUT_LABELREF does. */
1099 name = IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name) (name));
1100
1101 if (pointer_set_contains (seen, name))
1102 return;
1103 pointer_set_insert (seen, name);
1104
1105 lto_streamer_cache_lookup (cache, t, &slot_num);
1106 gcc_assert (slot_num != (unsigned)-1);
1107
1108 if (DECL_EXTERNAL (t))
1109 {
1110 if (DECL_WEAK (t))
1111 kind = GCCPK_WEAKUNDEF;
1112 else
1113 kind = GCCPK_UNDEF;
1114 }
1115 else
1116 {
1117 if (DECL_WEAK (t))
1118 kind = GCCPK_WEAKDEF;
1119 else if (DECL_COMMON (t))
1120 kind = GCCPK_COMMON;
1121 else
1122 kind = GCCPK_DEF;
1123
1124 /* When something is defined, it should have node attached. */
1125 gcc_assert (alias || TREE_CODE (t) != VAR_DECL
1126 || varpool_get_node (t)->finalized);
1127 gcc_assert (alias || TREE_CODE (t) != FUNCTION_DECL
1128 || (cgraph_get_node (t)
1129 && cgraph_get_node (t)->analyzed));
1130 }
1131
1132 /* Imitate what default_elf_asm_output_external do.
1133 When symbol is external, we need to output it with DEFAULT visibility
1134 when compiling with -fvisibility=default, while with HIDDEN visibility
1135 when symbol has attribute (visibility("hidden")) specified.
1136 targetm.binds_local_p check DECL_VISIBILITY_SPECIFIED and gets this
1137 right. */
1138
1139 if (DECL_EXTERNAL (t)
1140 && !targetm.binds_local_p (t))
1141 visibility = GCCPV_DEFAULT;
1142 else
1143 switch (DECL_VISIBILITY(t))
1144 {
1145 case VISIBILITY_DEFAULT:
1146 visibility = GCCPV_DEFAULT;
1147 break;
1148 case VISIBILITY_PROTECTED:
1149 visibility = GCCPV_PROTECTED;
1150 break;
1151 case VISIBILITY_HIDDEN:
1152 visibility = GCCPV_HIDDEN;
1153 break;
1154 case VISIBILITY_INTERNAL:
1155 visibility = GCCPV_INTERNAL;
1156 break;
1157 }
1158
1159 if (kind == GCCPK_COMMON
1160 && DECL_SIZE (t)
1161 && TREE_CODE (DECL_SIZE (t)) == INTEGER_CST)
1162 {
1163 size = (HOST_BITS_PER_WIDE_INT >= 64)
1164 ? (uint64_t) int_size_in_bytes (TREE_TYPE (t))
1165 : (((uint64_t) TREE_INT_CST_HIGH (DECL_SIZE_UNIT (t))) << 32)
1166 | TREE_INT_CST_LOW (DECL_SIZE_UNIT (t));
1167 }
1168 else
1169 size = 0;
1170
1171 if (DECL_ONE_ONLY (t))
1172 comdat = IDENTIFIER_POINTER (DECL_COMDAT_GROUP (t));
1173 else
1174 comdat = "";
1175
1176 lto_output_data_stream (stream, name, strlen (name) + 1);
1177 lto_output_data_stream (stream, comdat, strlen (comdat) + 1);
1178 c = (unsigned char) kind;
1179 lto_output_data_stream (stream, &c, 1);
1180 c = (unsigned char) visibility;
1181 lto_output_data_stream (stream, &c, 1);
1182 lto_output_data_stream (stream, &size, 8);
1183 lto_output_data_stream (stream, &slot_num, 4);
1184 }
1185
1186
1187 /* Write an IL symbol table to OB.
1188 SET and VSET are cgraph/varpool node sets we are outputting. */
1189
1190 static void
1191 produce_symtab (struct output_block *ob,
1192 cgraph_node_set set, varpool_node_set vset)
1193 {
1194 struct lto_streamer_cache_d *cache = ob->writer_cache;
1195 char *section_name = lto_get_section_name (LTO_section_symtab, NULL, NULL);
1196 struct pointer_set_t *seen;
1197 struct cgraph_node *node;
1198 struct varpool_node *vnode;
1199 struct lto_output_stream stream;
1200 lto_varpool_encoder_t varpool_encoder = ob->decl_state->varpool_node_encoder;
1201 lto_cgraph_encoder_t encoder = ob->decl_state->cgraph_node_encoder;
1202 int i;
1203 alias_pair *p;
1204 struct sets setdata;
1205 symbol_alias_set_t *defined;
1206
1207 setdata.set = set;
1208 setdata.vset = vset;
1209
1210 lto_begin_section (section_name, false);
1211 free (section_name);
1212
1213 seen = pointer_set_create ();
1214 memset (&stream, 0, sizeof (stream));
1215
1216 /* Write all functions.
1217 First write all defined functions and then write all used functions.
1218 This is done so only to handle duplicated symbols in cgraph. */
1219 for (i = 0; i < lto_cgraph_encoder_size (encoder); i++)
1220 {
1221 node = lto_cgraph_encoder_deref (encoder, i);
1222 if (DECL_EXTERNAL (node->decl))
1223 continue;
1224 if (DECL_COMDAT (node->decl)
1225 && cgraph_comdat_can_be_unshared_p (node))
1226 continue;
1227 if ((node->alias && !node->thunk.alias) || node->global.inlined_to)
1228 continue;
1229 write_symbol (cache, &stream, node->decl, seen, false);
1230 }
1231 for (i = 0; i < lto_cgraph_encoder_size (encoder); i++)
1232 {
1233 node = lto_cgraph_encoder_deref (encoder, i);
1234 if (!DECL_EXTERNAL (node->decl))
1235 continue;
1236 if (DECL_COMDAT (node->decl)
1237 && cgraph_comdat_can_be_unshared_p (node))
1238 continue;
1239 if ((node->alias && !node->thunk.alias) || node->global.inlined_to)
1240 continue;
1241 write_symbol (cache, &stream, node->decl, seen, false);
1242 }
1243
1244 /* Write all variables. */
1245 for (i = 0; i < lto_varpool_encoder_size (varpool_encoder); i++)
1246 {
1247 vnode = lto_varpool_encoder_deref (varpool_encoder, i);
1248 if (DECL_EXTERNAL (vnode->decl))
1249 continue;
1250 /* COMDAT virtual tables can be unshared. Do not declare them
1251 in the LTO symbol table to prevent linker from forcing them
1252 into the output. */
1253 if (DECL_COMDAT (vnode->decl)
1254 && !vnode->force_output
1255 && vnode->finalized
1256 && DECL_VIRTUAL_P (vnode->decl))
1257 continue;
1258 if (vnode->alias && !vnode->alias_of)
1259 continue;
1260 write_symbol (cache, &stream, vnode->decl, seen, false);
1261 }
1262 for (i = 0; i < lto_varpool_encoder_size (varpool_encoder); i++)
1263 {
1264 vnode = lto_varpool_encoder_deref (varpool_encoder, i);
1265 if (!DECL_EXTERNAL (vnode->decl))
1266 continue;
1267 if (DECL_COMDAT (vnode->decl)
1268 && !vnode->force_output
1269 && vnode->finalized
1270 && DECL_VIRTUAL_P (vnode->decl))
1271 continue;
1272 if (vnode->alias && !vnode->alias_of)
1273 continue;
1274 write_symbol (cache, &stream, vnode->decl, seen, false);
1275 }
1276
1277 /* Write all aliases. */
1278 defined = propagate_aliases_backward (trivally_defined_alias, &setdata);
1279 FOR_EACH_VEC_ELT (alias_pair, alias_pairs, i, p)
1280 if (output_alias_pair_p (p, defined, set, vset))
1281 write_symbol (cache, &stream, p->decl, seen, true);
1282 symbol_alias_set_destroy (defined);
1283
1284 lto_write_stream (&stream);
1285 pointer_set_destroy (seen);
1286
1287 lto_end_section ();
1288 }
1289
1290
1291 /* This pass is run after all of the functions are serialized and all
1292 of the IPA passes have written their serialized forms. This pass
1293 causes the vector of all of the global decls and types used from
1294 this file to be written in to a section that can then be read in to
1295 recover these on other side. */
1296
1297 static void
1298 produce_asm_for_decls (cgraph_node_set set, varpool_node_set vset)
1299 {
1300 struct lto_out_decl_state *out_state;
1301 struct lto_out_decl_state *fn_out_state;
1302 struct lto_decl_header header;
1303 char *section_name;
1304 struct output_block *ob;
1305 struct lto_output_stream *header_stream, *decl_state_stream;
1306 unsigned idx, num_fns;
1307 size_t decl_state_size;
1308 int32_t num_decl_states;
1309
1310 ob = create_output_block (LTO_section_decls);
1311 ob->global = true;
1312
1313 /* Write out unreferenced globals, alias pairs and labels. We defer
1314 doing this until now so that we can write out only what is
1315 needed. */
1316 output_unreferenced_globals (set, vset);
1317
1318 memset (&header, 0, sizeof (struct lto_decl_header));
1319
1320 section_name = lto_get_section_name (LTO_section_decls, NULL, NULL);
1321 lto_begin_section (section_name, !flag_wpa);
1322 free (section_name);
1323
1324 /* Make string 0 be a NULL string. */
1325 lto_output_1_stream (ob->string_stream, 0);
1326
1327 /* Write the global symbols. */
1328 out_state = lto_get_out_decl_state ();
1329 num_fns = VEC_length (lto_out_decl_state_ptr, lto_function_decl_states);
1330 lto_output_decl_state_streams (ob, out_state);
1331 for (idx = 0; idx < num_fns; idx++)
1332 {
1333 fn_out_state =
1334 VEC_index (lto_out_decl_state_ptr, lto_function_decl_states, idx);
1335 lto_output_decl_state_streams (ob, fn_out_state);
1336 }
1337
1338 header.lto_header.major_version = LTO_major_version;
1339 header.lto_header.minor_version = LTO_minor_version;
1340 header.lto_header.section_type = LTO_section_decls;
1341
1342 /* Currently not used. This field would allow us to preallocate
1343 the globals vector, so that it need not be resized as it is extended. */
1344 header.num_nodes = -1;
1345
1346 /* Compute the total size of all decl out states. */
1347 decl_state_size = sizeof (int32_t);
1348 decl_state_size += lto_out_decl_state_written_size (out_state);
1349 for (idx = 0; idx < num_fns; idx++)
1350 {
1351 fn_out_state =
1352 VEC_index (lto_out_decl_state_ptr, lto_function_decl_states, idx);
1353 decl_state_size += lto_out_decl_state_written_size (fn_out_state);
1354 }
1355 header.decl_state_size = decl_state_size;
1356
1357 header.main_size = ob->main_stream->total_size;
1358 header.string_size = ob->string_stream->total_size;
1359
1360 header_stream = XCNEW (struct lto_output_stream);
1361 lto_output_data_stream (header_stream, &header, sizeof header);
1362 lto_write_stream (header_stream);
1363 free (header_stream);
1364
1365 /* Write the main out-decl state, followed by out-decl states of
1366 functions. */
1367 decl_state_stream = ((struct lto_output_stream *)
1368 xcalloc (1, sizeof (struct lto_output_stream)));
1369 num_decl_states = num_fns + 1;
1370 lto_output_data_stream (decl_state_stream, &num_decl_states,
1371 sizeof (num_decl_states));
1372 lto_output_decl_state_refs (ob, decl_state_stream, out_state);
1373 for (idx = 0; idx < num_fns; idx++)
1374 {
1375 fn_out_state =
1376 VEC_index (lto_out_decl_state_ptr, lto_function_decl_states, idx);
1377 lto_output_decl_state_refs (ob, decl_state_stream, fn_out_state);
1378 }
1379 lto_write_stream (decl_state_stream);
1380 free(decl_state_stream);
1381
1382 lto_write_stream (ob->main_stream);
1383 lto_write_stream (ob->string_stream);
1384
1385 lto_end_section ();
1386
1387 /* Write the symbol table. It is used by linker to determine dependencies
1388 and thus we can skip it for WPA. */
1389 if (!flag_wpa)
1390 produce_symtab (ob, set, vset);
1391
1392 /* Write command line opts. */
1393 lto_write_options ();
1394
1395 /* Deallocate memory and clean up. */
1396 for (idx = 0; idx < num_fns; idx++)
1397 {
1398 fn_out_state =
1399 VEC_index (lto_out_decl_state_ptr, lto_function_decl_states, idx);
1400 lto_delete_out_decl_state (fn_out_state);
1401 }
1402 lto_cgraph_encoder_delete (ob->decl_state->cgraph_node_encoder);
1403 lto_varpool_encoder_delete (ob->decl_state->varpool_node_encoder);
1404 VEC_free (lto_out_decl_state_ptr, heap, lto_function_decl_states);
1405 lto_function_decl_states = NULL;
1406 destroy_output_block (ob);
1407 }
1408
1409
1410 struct ipa_opt_pass_d pass_ipa_lto_finish_out =
1411 {
1412 {
1413 IPA_PASS,
1414 "lto_decls_out", /* name */
1415 gate_lto_out, /* gate */
1416 NULL, /* execute */
1417 NULL, /* sub */
1418 NULL, /* next */
1419 0, /* static_pass_number */
1420 TV_IPA_LTO_DECL_OUT, /* tv_id */
1421 0, /* properties_required */
1422 0, /* properties_provided */
1423 0, /* properties_destroyed */
1424 0, /* todo_flags_start */
1425 0 /* todo_flags_finish */
1426 },
1427 NULL, /* generate_summary */
1428 produce_asm_for_decls, /* write_summary */
1429 NULL, /* read_summary */
1430 produce_asm_for_decls, /* write_optimization_summary */
1431 NULL, /* read_optimization_summary */
1432 NULL, /* stmt_fixup */
1433 0, /* TODOs */
1434 NULL, /* function_transform */
1435 NULL /* variable_transform */
1436 };