2013-05-02 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / lto-streamer-out.c
blobdfaf2806b7471d9973436f3df7d6a0205879bc08
1 /* Write the GIMPLE representation to a file stream.
3 Copyright (C) 2009-2013 Free Software Foundation, Inc.
4 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
5 Re-implemented by Diego Novillo <dnovillo@google.com>
7 This file is part of GCC.
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.
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.
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/>. */
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 #include "cfgloop.h"
51 /* Clear the line info stored in DATA_IN. */
53 static void
54 clear_line_info (struct output_block *ob)
56 ob->current_file = NULL;
57 ob->current_line = 0;
58 ob->current_col = 0;
62 /* Create the output block and return it. SECTION_TYPE is
63 LTO_section_function_body or LTO_static_initializer. */
65 struct output_block *
66 create_output_block (enum lto_section_type section_type)
68 struct output_block *ob = XCNEW (struct output_block);
70 ob->section_type = section_type;
71 ob->decl_state = lto_get_out_decl_state ();
72 ob->main_stream = XCNEW (struct lto_output_stream);
73 ob->string_stream = XCNEW (struct lto_output_stream);
74 ob->writer_cache = streamer_tree_cache_create ();
76 if (section_type == LTO_section_function_body)
77 ob->cfg_stream = XCNEW (struct lto_output_stream);
79 clear_line_info (ob);
81 ob->string_hash_table.create (37);
82 gcc_obstack_init (&ob->obstack);
84 return ob;
88 /* Destroy the output block OB. */
90 void
91 destroy_output_block (struct output_block *ob)
93 enum lto_section_type section_type = ob->section_type;
95 ob->string_hash_table.dispose ();
97 free (ob->main_stream);
98 free (ob->string_stream);
99 if (section_type == LTO_section_function_body)
100 free (ob->cfg_stream);
102 streamer_tree_cache_delete (ob->writer_cache);
103 obstack_free (&ob->obstack, NULL);
105 free (ob);
109 /* Look up NODE in the type table and write the index for it to OB. */
111 static void
112 output_type_ref (struct output_block *ob, tree node)
114 streamer_write_record_start (ob, LTO_type_ref);
115 lto_output_type_ref_index (ob->decl_state, ob->main_stream, node);
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). */
124 static bool
125 tree_is_indexable (tree t)
127 if (TREE_CODE (t) == PARM_DECL)
128 return true;
129 else if (TREE_CODE (t) == VAR_DECL && decl_function_context (t)
130 && !TREE_STATIC (t))
131 return false;
132 /* Variably modified types need to be streamed alongside function
133 bodies because they can refer to local entities. Together with
134 them we have to localize their members as well.
135 ??? In theory that includes non-FIELD_DECLs as well. */
136 else if (TYPE_P (t)
137 && variably_modified_type_p (t, NULL_TREE))
138 return false;
139 else if (TREE_CODE (t) == FIELD_DECL
140 && variably_modified_type_p (DECL_CONTEXT (t), NULL_TREE))
141 return false;
142 else
143 return (TYPE_P (t) || DECL_P (t) || TREE_CODE (t) == SSA_NAME);
147 /* Output info about new location into bitpack BP.
148 After outputting bitpack, lto_output_location_data has
149 to be done to output actual data. */
151 void
152 lto_output_location (struct output_block *ob, struct bitpack_d *bp,
153 location_t loc)
155 expanded_location xloc;
157 loc = LOCATION_LOCUS (loc);
158 bp_pack_value (bp, loc == UNKNOWN_LOCATION, 1);
159 if (loc == UNKNOWN_LOCATION)
160 return;
162 xloc = expand_location (loc);
164 bp_pack_value (bp, ob->current_file != xloc.file, 1);
165 bp_pack_value (bp, ob->current_line != xloc.line, 1);
166 bp_pack_value (bp, ob->current_col != xloc.column, 1);
168 if (ob->current_file != xloc.file)
169 bp_pack_var_len_unsigned (bp,
170 streamer_string_index (ob, xloc.file,
171 strlen (xloc.file) + 1,
172 true));
173 ob->current_file = xloc.file;
175 if (ob->current_line != xloc.line)
176 bp_pack_var_len_unsigned (bp, xloc.line);
177 ob->current_line = xloc.line;
179 if (ob->current_col != xloc.column)
180 bp_pack_var_len_unsigned (bp, xloc.column);
181 ob->current_col = xloc.column;
185 /* If EXPR is an indexable tree node, output a reference to it to
186 output block OB. Otherwise, output the physical representation of
187 EXPR to OB. */
189 static void
190 lto_output_tree_ref (struct output_block *ob, tree expr)
192 enum tree_code code;
194 if (TYPE_P (expr))
196 output_type_ref (ob, expr);
197 return;
200 code = TREE_CODE (expr);
201 switch (code)
203 case SSA_NAME:
204 streamer_write_record_start (ob, LTO_ssa_name_ref);
205 streamer_write_uhwi (ob, SSA_NAME_VERSION (expr));
206 break;
208 case FIELD_DECL:
209 streamer_write_record_start (ob, LTO_field_decl_ref);
210 lto_output_field_decl_index (ob->decl_state, ob->main_stream, expr);
211 break;
213 case FUNCTION_DECL:
214 streamer_write_record_start (ob, LTO_function_decl_ref);
215 lto_output_fn_decl_index (ob->decl_state, ob->main_stream, expr);
216 break;
218 case VAR_DECL:
219 case DEBUG_EXPR_DECL:
220 gcc_assert (decl_function_context (expr) == NULL || TREE_STATIC (expr));
221 case PARM_DECL:
222 streamer_write_record_start (ob, LTO_global_decl_ref);
223 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
224 break;
226 case CONST_DECL:
227 streamer_write_record_start (ob, LTO_const_decl_ref);
228 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
229 break;
231 case IMPORTED_DECL:
232 gcc_assert (decl_function_context (expr) == NULL);
233 streamer_write_record_start (ob, LTO_imported_decl_ref);
234 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
235 break;
237 case TYPE_DECL:
238 streamer_write_record_start (ob, LTO_type_decl_ref);
239 lto_output_type_decl_index (ob->decl_state, ob->main_stream, expr);
240 break;
242 case NAMESPACE_DECL:
243 streamer_write_record_start (ob, LTO_namespace_decl_ref);
244 lto_output_namespace_decl_index (ob->decl_state, ob->main_stream, expr);
245 break;
247 case LABEL_DECL:
248 streamer_write_record_start (ob, LTO_label_decl_ref);
249 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
250 break;
252 case RESULT_DECL:
253 streamer_write_record_start (ob, LTO_result_decl_ref);
254 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
255 break;
257 case TRANSLATION_UNIT_DECL:
258 streamer_write_record_start (ob, LTO_translation_unit_decl_ref);
259 lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
260 break;
262 default:
263 /* No other node is indexable, so it should have been handled by
264 lto_output_tree. */
265 gcc_unreachable ();
270 /* Return true if EXPR is a tree node that can be written to disk. */
272 static inline bool
273 lto_is_streamable (tree expr)
275 enum tree_code code = TREE_CODE (expr);
277 /* Notice that we reject SSA_NAMEs as well. We only emit the SSA
278 name version in lto_output_tree_ref (see output_ssa_names). */
279 return !is_lang_specific (expr)
280 && code != SSA_NAME
281 && code != CALL_EXPR
282 && code != LANG_TYPE
283 && code != MODIFY_EXPR
284 && code != INIT_EXPR
285 && code != TARGET_EXPR
286 && code != BIND_EXPR
287 && code != WITH_CLEANUP_EXPR
288 && code != STATEMENT_LIST
289 && code != OMP_CLAUSE
290 && (code == CASE_LABEL_EXPR
291 || code == DECL_EXPR
292 || TREE_CODE_CLASS (code) != tcc_statement);
296 /* Write a physical representation of tree node EXPR to output block
297 OB. If REF_P is true, the leaves of EXPR are emitted as references
298 via lto_output_tree_ref. IX is the index into the streamer cache
299 where EXPR is stored. */
301 static void
302 lto_write_tree (struct output_block *ob, tree expr, bool ref_p)
304 struct bitpack_d bp;
306 if (!lto_is_streamable (expr))
307 internal_error ("tree code %qs is not supported in LTO streams",
308 tree_code_name[TREE_CODE (expr)]);
310 /* Write the header, containing everything needed to materialize
311 EXPR on the reading side. */
312 streamer_write_tree_header (ob, expr);
314 /* Pack all the non-pointer fields in EXPR into a bitpack and write
315 the resulting bitpack. */
316 bp = bitpack_create (ob->main_stream);
317 streamer_pack_tree_bitfields (ob, &bp, expr);
318 streamer_write_bitpack (&bp);
320 /* Write all the pointer fields in EXPR. */
321 streamer_write_tree_body (ob, expr, ref_p);
323 /* Write any LTO-specific data to OB. */
324 if (DECL_P (expr)
325 && TREE_CODE (expr) != FUNCTION_DECL
326 && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
328 /* Handle DECL_INITIAL for symbols. */
329 tree initial = DECL_INITIAL (expr);
330 if (TREE_CODE (expr) == VAR_DECL
331 && (TREE_STATIC (expr) || DECL_EXTERNAL (expr))
332 && !DECL_IN_CONSTANT_POOL (expr)
333 && initial)
335 lto_symtab_encoder_t encoder;
336 struct varpool_node *vnode;
338 encoder = ob->decl_state->symtab_node_encoder;
339 vnode = varpool_get_node (expr);
340 if (!vnode
341 || !lto_symtab_encoder_encode_initializer_p (encoder,
342 vnode))
343 initial = error_mark_node;
346 stream_write_tree (ob, initial, ref_p);
349 /* Mark the end of EXPR. */
350 streamer_write_zero (ob);
354 /* Emit the physical representation of tree node EXPR to output block
355 OB. If THIS_REF_P is true, the leaves of EXPR are emitted as references
356 via lto_output_tree_ref. REF_P is used for streaming siblings of EXPR. */
358 void
359 lto_output_tree (struct output_block *ob, tree expr,
360 bool ref_p, bool this_ref_p)
362 unsigned ix;
363 bool existed_p;
365 if (expr == NULL_TREE)
367 streamer_write_record_start (ob, LTO_null);
368 return;
371 if (this_ref_p && tree_is_indexable (expr))
373 lto_output_tree_ref (ob, expr);
374 return;
377 /* Shared INTEGER_CST nodes are special because they need their original type
378 to be materialized by the reader (to implement TYPE_CACHED_VALUES). */
379 if (TREE_CODE (expr) == INTEGER_CST
380 && !TREE_OVERFLOW (expr))
382 streamer_write_integer_cst (ob, expr, ref_p);
383 return;
386 existed_p = streamer_tree_cache_insert (ob->writer_cache, expr, &ix);
387 if (existed_p)
389 /* If a node has already been streamed out, make sure that
390 we don't write it more than once. Otherwise, the reader
391 will instantiate two different nodes for the same object. */
392 streamer_write_record_start (ob, LTO_tree_pickle_reference);
393 streamer_write_uhwi (ob, ix);
394 streamer_write_enum (ob->main_stream, LTO_tags, LTO_NUM_TAGS,
395 lto_tree_code_to_tag (TREE_CODE (expr)));
397 else if (streamer_handle_as_builtin_p (expr))
399 /* MD and NORMAL builtins do not need to be written out
400 completely as they are always instantiated by the
401 compiler on startup. The only builtins that need to
402 be written out are BUILT_IN_FRONTEND. For all other
403 builtins, we simply write the class and code. */
404 streamer_write_builtin (ob, expr);
406 else
408 /* This is the first time we see EXPR, write its fields
409 to OB. */
410 lto_write_tree (ob, expr, ref_p);
415 /* Output to OB a list of try/catch handlers starting with FIRST. */
417 static void
418 output_eh_try_list (struct output_block *ob, eh_catch first)
420 eh_catch n;
422 for (n = first; n; n = n->next_catch)
424 streamer_write_record_start (ob, LTO_eh_catch);
425 stream_write_tree (ob, n->type_list, true);
426 stream_write_tree (ob, n->filter_list, true);
427 stream_write_tree (ob, n->label, true);
430 streamer_write_record_start (ob, LTO_null);
434 /* Output EH region R in function FN to OB. CURR_RN is the slot index
435 that is being emitted in FN->EH->REGION_ARRAY. This is used to
436 detect EH region sharing. */
438 static void
439 output_eh_region (struct output_block *ob, eh_region r)
441 enum LTO_tags tag;
443 if (r == NULL)
445 streamer_write_record_start (ob, LTO_null);
446 return;
449 if (r->type == ERT_CLEANUP)
450 tag = LTO_ert_cleanup;
451 else if (r->type == ERT_TRY)
452 tag = LTO_ert_try;
453 else if (r->type == ERT_ALLOWED_EXCEPTIONS)
454 tag = LTO_ert_allowed_exceptions;
455 else if (r->type == ERT_MUST_NOT_THROW)
456 tag = LTO_ert_must_not_throw;
457 else
458 gcc_unreachable ();
460 streamer_write_record_start (ob, tag);
461 streamer_write_hwi (ob, r->index);
463 if (r->outer)
464 streamer_write_hwi (ob, r->outer->index);
465 else
466 streamer_write_zero (ob);
468 if (r->inner)
469 streamer_write_hwi (ob, r->inner->index);
470 else
471 streamer_write_zero (ob);
473 if (r->next_peer)
474 streamer_write_hwi (ob, r->next_peer->index);
475 else
476 streamer_write_zero (ob);
478 if (r->type == ERT_TRY)
480 output_eh_try_list (ob, r->u.eh_try.first_catch);
482 else if (r->type == ERT_ALLOWED_EXCEPTIONS)
484 stream_write_tree (ob, r->u.allowed.type_list, true);
485 stream_write_tree (ob, r->u.allowed.label, true);
486 streamer_write_uhwi (ob, r->u.allowed.filter);
488 else if (r->type == ERT_MUST_NOT_THROW)
490 stream_write_tree (ob, r->u.must_not_throw.failure_decl, true);
491 bitpack_d bp = bitpack_create (ob->main_stream);
492 stream_output_location (ob, &bp, r->u.must_not_throw.failure_loc);
493 streamer_write_bitpack (&bp);
496 if (r->landing_pads)
497 streamer_write_hwi (ob, r->landing_pads->index);
498 else
499 streamer_write_zero (ob);
503 /* Output landing pad LP to OB. */
505 static void
506 output_eh_lp (struct output_block *ob, eh_landing_pad lp)
508 if (lp == NULL)
510 streamer_write_record_start (ob, LTO_null);
511 return;
514 streamer_write_record_start (ob, LTO_eh_landing_pad);
515 streamer_write_hwi (ob, lp->index);
516 if (lp->next_lp)
517 streamer_write_hwi (ob, lp->next_lp->index);
518 else
519 streamer_write_zero (ob);
521 if (lp->region)
522 streamer_write_hwi (ob, lp->region->index);
523 else
524 streamer_write_zero (ob);
526 stream_write_tree (ob, lp->post_landing_pad, true);
530 /* Output the existing eh_table to OB. */
532 static void
533 output_eh_regions (struct output_block *ob, struct function *fn)
535 if (fn->eh && fn->eh->region_tree)
537 unsigned i;
538 eh_region eh;
539 eh_landing_pad lp;
540 tree ttype;
542 streamer_write_record_start (ob, LTO_eh_table);
544 /* Emit the index of the root of the EH region tree. */
545 streamer_write_hwi (ob, fn->eh->region_tree->index);
547 /* Emit all the EH regions in the region array. */
548 streamer_write_hwi (ob, vec_safe_length (fn->eh->region_array));
549 FOR_EACH_VEC_SAFE_ELT (fn->eh->region_array, i, eh)
550 output_eh_region (ob, eh);
552 /* Emit all landing pads. */
553 streamer_write_hwi (ob, vec_safe_length (fn->eh->lp_array));
554 FOR_EACH_VEC_SAFE_ELT (fn->eh->lp_array, i, lp)
555 output_eh_lp (ob, lp);
557 /* Emit all the runtime type data. */
558 streamer_write_hwi (ob, vec_safe_length (fn->eh->ttype_data));
559 FOR_EACH_VEC_SAFE_ELT (fn->eh->ttype_data, i, ttype)
560 stream_write_tree (ob, ttype, true);
562 /* Emit the table of action chains. */
563 if (targetm.arm_eabi_unwinder)
565 tree t;
566 streamer_write_hwi (ob, vec_safe_length (fn->eh->ehspec_data.arm_eabi));
567 FOR_EACH_VEC_SAFE_ELT (fn->eh->ehspec_data.arm_eabi, i, t)
568 stream_write_tree (ob, t, true);
570 else
572 uchar c;
573 streamer_write_hwi (ob, vec_safe_length (fn->eh->ehspec_data.other));
574 FOR_EACH_VEC_SAFE_ELT (fn->eh->ehspec_data.other, i, c)
575 streamer_write_char_stream (ob->main_stream, c);
579 /* The LTO_null either terminates the record or indicates that there
580 are no eh_records at all. */
581 streamer_write_record_start (ob, LTO_null);
585 /* Output all of the active ssa names to the ssa_names stream. */
587 static void
588 output_ssa_names (struct output_block *ob, struct function *fn)
590 unsigned int i, len;
592 len = vec_safe_length (SSANAMES (fn));
593 streamer_write_uhwi (ob, len);
595 for (i = 1; i < len; i++)
597 tree ptr = (*SSANAMES (fn))[i];
599 if (ptr == NULL_TREE
600 || SSA_NAME_IN_FREE_LIST (ptr)
601 || virtual_operand_p (ptr))
602 continue;
604 streamer_write_uhwi (ob, i);
605 streamer_write_char_stream (ob->main_stream,
606 SSA_NAME_IS_DEFAULT_DEF (ptr));
607 if (SSA_NAME_VAR (ptr))
608 stream_write_tree (ob, SSA_NAME_VAR (ptr), true);
609 else
610 /* ??? This drops SSA_NAME_IDENTIFIER on the floor. */
611 stream_write_tree (ob, TREE_TYPE (ptr), true);
614 streamer_write_zero (ob);
618 /* Output the cfg. */
620 static void
621 output_cfg (struct output_block *ob, struct function *fn)
623 struct lto_output_stream *tmp_stream = ob->main_stream;
624 basic_block bb;
626 ob->main_stream = ob->cfg_stream;
628 streamer_write_enum (ob->main_stream, profile_status_d, PROFILE_LAST,
629 profile_status_for_function (fn));
631 /* Output the number of the highest basic block. */
632 streamer_write_uhwi (ob, last_basic_block_for_function (fn));
634 FOR_ALL_BB_FN (bb, fn)
636 edge_iterator ei;
637 edge e;
639 streamer_write_hwi (ob, bb->index);
641 /* Output the successors and the edge flags. */
642 streamer_write_uhwi (ob, EDGE_COUNT (bb->succs));
643 FOR_EACH_EDGE (e, ei, bb->succs)
645 streamer_write_uhwi (ob, e->dest->index);
646 streamer_write_hwi (ob, e->probability);
647 streamer_write_gcov_count (ob, e->count);
648 streamer_write_uhwi (ob, e->flags);
652 streamer_write_hwi (ob, -1);
654 bb = ENTRY_BLOCK_PTR;
655 while (bb->next_bb)
657 streamer_write_hwi (ob, bb->next_bb->index);
658 bb = bb->next_bb;
661 streamer_write_hwi (ob, -1);
663 /* ??? The cfgloop interface is tied to cfun. */
664 gcc_assert (cfun == fn);
666 /* Output the number of loops. */
667 streamer_write_uhwi (ob, number_of_loops (fn));
669 /* Output each loop, skipping the tree root which has number zero. */
670 for (unsigned i = 1; i < number_of_loops (fn); ++i)
672 struct loop *loop = get_loop (fn, i);
674 /* Write the index of the loop header. That's enough to rebuild
675 the loop tree on the reader side. Stream -1 for an unused
676 loop entry. */
677 if (!loop)
679 streamer_write_hwi (ob, -1);
680 continue;
682 else
683 streamer_write_hwi (ob, loop->header->index);
685 /* Write everything copy_loop_info copies. */
686 streamer_write_enum (ob->main_stream,
687 loop_estimation, EST_LAST, loop->estimate_state);
688 streamer_write_hwi (ob, loop->any_upper_bound);
689 if (loop->any_upper_bound)
691 streamer_write_uhwi (ob, loop->nb_iterations_upper_bound.low);
692 streamer_write_hwi (ob, loop->nb_iterations_upper_bound.high);
694 streamer_write_hwi (ob, loop->any_estimate);
695 if (loop->any_estimate)
697 streamer_write_uhwi (ob, loop->nb_iterations_estimate.low);
698 streamer_write_hwi (ob, loop->nb_iterations_estimate.high);
702 ob->main_stream = tmp_stream;
706 /* Create the header in the file using OB. If the section type is for
707 a function, set FN to the decl for that function. */
709 void
710 produce_asm (struct output_block *ob, tree fn)
712 enum lto_section_type section_type = ob->section_type;
713 struct lto_function_header header;
714 char *section_name;
715 struct lto_output_stream *header_stream;
717 if (section_type == LTO_section_function_body)
719 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn));
720 section_name = lto_get_section_name (section_type, name, NULL);
722 else
723 section_name = lto_get_section_name (section_type, NULL, NULL);
725 lto_begin_section (section_name, !flag_wpa);
726 free (section_name);
728 /* The entire header is stream computed here. */
729 memset (&header, 0, sizeof (struct lto_function_header));
731 /* Write the header. */
732 header.lto_header.major_version = LTO_major_version;
733 header.lto_header.minor_version = LTO_minor_version;
735 header.compressed_size = 0;
737 if (section_type == LTO_section_function_body)
738 header.cfg_size = ob->cfg_stream->total_size;
739 header.main_size = ob->main_stream->total_size;
740 header.string_size = ob->string_stream->total_size;
742 header_stream = XCNEW (struct lto_output_stream);
743 lto_output_data_stream (header_stream, &header, sizeof header);
744 lto_write_stream (header_stream);
745 free (header_stream);
747 /* Put all of the gimple and the string table out the asm file as a
748 block of text. */
749 if (section_type == LTO_section_function_body)
750 lto_write_stream (ob->cfg_stream);
751 lto_write_stream (ob->main_stream);
752 lto_write_stream (ob->string_stream);
754 lto_end_section ();
758 /* Output the base body of struct function FN using output block OB. */
760 static void
761 output_struct_function_base (struct output_block *ob, struct function *fn)
763 struct bitpack_d bp;
764 unsigned i;
765 tree t;
767 /* Output the static chain and non-local goto save area. */
768 stream_write_tree (ob, fn->static_chain_decl, true);
769 stream_write_tree (ob, fn->nonlocal_goto_save_area, true);
771 /* Output all the local variables in the function. */
772 streamer_write_hwi (ob, vec_safe_length (fn->local_decls));
773 FOR_EACH_VEC_SAFE_ELT (fn->local_decls, i, t)
774 stream_write_tree (ob, t, true);
776 /* Output current IL state of the function. */
777 streamer_write_uhwi (ob, fn->curr_properties);
779 /* Write all the attributes for FN. */
780 bp = bitpack_create (ob->main_stream);
781 bp_pack_value (&bp, fn->is_thunk, 1);
782 bp_pack_value (&bp, fn->has_local_explicit_reg_vars, 1);
783 bp_pack_value (&bp, fn->returns_pcc_struct, 1);
784 bp_pack_value (&bp, fn->returns_struct, 1);
785 bp_pack_value (&bp, fn->can_throw_non_call_exceptions, 1);
786 bp_pack_value (&bp, fn->can_delete_dead_exceptions, 1);
787 bp_pack_value (&bp, fn->always_inline_functions_inlined, 1);
788 bp_pack_value (&bp, fn->after_inlining, 1);
789 bp_pack_value (&bp, fn->stdarg, 1);
790 bp_pack_value (&bp, fn->has_nonlocal_label, 1);
791 bp_pack_value (&bp, fn->calls_alloca, 1);
792 bp_pack_value (&bp, fn->calls_setjmp, 1);
793 bp_pack_value (&bp, fn->va_list_fpr_size, 8);
794 bp_pack_value (&bp, fn->va_list_gpr_size, 8);
796 /* Output the function start and end loci. */
797 stream_output_location (ob, &bp, fn->function_start_locus);
798 stream_output_location (ob, &bp, fn->function_end_locus);
800 streamer_write_bitpack (&bp);
804 /* Output the body of function NODE->DECL. */
806 static void
807 output_function (struct cgraph_node *node)
809 tree function;
810 struct function *fn;
811 basic_block bb;
812 struct output_block *ob;
814 function = node->symbol.decl;
815 fn = DECL_STRUCT_FUNCTION (function);
816 ob = create_output_block (LTO_section_function_body);
818 clear_line_info (ob);
819 ob->cgraph_node = node;
821 gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
823 /* Set current_function_decl and cfun. */
824 push_cfun (fn);
826 /* Make string 0 be a NULL string. */
827 streamer_write_char_stream (ob->string_stream, 0);
829 streamer_write_record_start (ob, LTO_function);
831 output_struct_function_base (ob, fn);
833 /* Output all the SSA names used in the function. */
834 output_ssa_names (ob, fn);
836 /* Output any exception handling regions. */
837 output_eh_regions (ob, fn);
839 /* Output DECL_INITIAL for the function, which contains the tree of
840 lexical scopes. */
841 stream_write_tree (ob, DECL_INITIAL (function), true);
843 /* We will renumber the statements. The code that does this uses
844 the same ordering that we use for serializing them so we can use
845 the same code on the other end and not have to write out the
846 statement numbers. We do not assign UIDs to PHIs here because
847 virtual PHIs get re-computed on-the-fly which would make numbers
848 inconsistent. */
849 set_gimple_stmt_max_uid (cfun, 0);
850 FOR_ALL_BB (bb)
852 gimple_stmt_iterator gsi;
853 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
855 gimple stmt = gsi_stmt (gsi);
856 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
860 /* Output the code for the function. */
861 FOR_ALL_BB_FN (bb, fn)
862 output_bb (ob, bb, fn);
864 /* The terminator for this function. */
865 streamer_write_record_start (ob, LTO_null);
867 output_cfg (ob, fn);
869 /* Create a section to hold the pickled output of this function. */
870 produce_asm (ob, function);
872 destroy_output_block (ob);
874 pop_cfun ();
878 /* Emit toplevel asms. */
880 void
881 lto_output_toplevel_asms (void)
883 struct output_block *ob;
884 struct asm_node *can;
885 char *section_name;
886 struct lto_output_stream *header_stream;
887 struct lto_asm_header header;
889 if (! asm_nodes)
890 return;
892 ob = create_output_block (LTO_section_asm);
894 /* Make string 0 be a NULL string. */
895 streamer_write_char_stream (ob->string_stream, 0);
897 for (can = asm_nodes; can; can = can->next)
899 streamer_write_string_cst (ob, ob->main_stream, can->asm_str);
900 streamer_write_hwi (ob, can->order);
903 streamer_write_string_cst (ob, ob->main_stream, NULL_TREE);
905 section_name = lto_get_section_name (LTO_section_asm, NULL, NULL);
906 lto_begin_section (section_name, !flag_wpa);
907 free (section_name);
909 /* The entire header stream is computed here. */
910 memset (&header, 0, sizeof (header));
912 /* Write the header. */
913 header.lto_header.major_version = LTO_major_version;
914 header.lto_header.minor_version = LTO_minor_version;
916 header.main_size = ob->main_stream->total_size;
917 header.string_size = ob->string_stream->total_size;
919 header_stream = XCNEW (struct lto_output_stream);
920 lto_output_data_stream (header_stream, &header, sizeof (header));
921 lto_write_stream (header_stream);
922 free (header_stream);
924 /* Put all of the gimple and the string table out the asm file as a
925 block of text. */
926 lto_write_stream (ob->main_stream);
927 lto_write_stream (ob->string_stream);
929 lto_end_section ();
931 destroy_output_block (ob);
935 /* Copy the function body of NODE without deserializing. */
937 static void
938 copy_function (struct cgraph_node *node)
940 tree function = node->symbol.decl;
941 struct lto_file_decl_data *file_data = node->symbol.lto_file_data;
942 struct lto_output_stream *output_stream = XCNEW (struct lto_output_stream);
943 const char *data;
944 size_t len;
945 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function));
946 char *section_name =
947 lto_get_section_name (LTO_section_function_body, name, NULL);
948 size_t i, j;
949 struct lto_in_decl_state *in_state;
950 struct lto_out_decl_state *out_state = lto_get_out_decl_state ();
952 lto_begin_section (section_name, !flag_wpa);
953 free (section_name);
955 /* We may have renamed the declaration, e.g., a static function. */
956 name = lto_get_decl_name_mapping (file_data, name);
958 data = lto_get_section_data (file_data, LTO_section_function_body,
959 name, &len);
960 gcc_assert (data);
962 /* Do a bit copy of the function body. */
963 lto_output_data_stream (output_stream, data, len);
964 lto_write_stream (output_stream);
966 /* Copy decls. */
967 in_state =
968 lto_get_function_in_decl_state (node->symbol.lto_file_data, function);
969 gcc_assert (in_state);
971 for (i = 0; i < LTO_N_DECL_STREAMS; i++)
973 size_t n = in_state->streams[i].size;
974 tree *trees = in_state->streams[i].trees;
975 struct lto_tree_ref_encoder *encoder = &(out_state->streams[i]);
977 /* The out state must have the same indices and the in state.
978 So just copy the vector. All the encoders in the in state
979 must be empty where we reach here. */
980 gcc_assert (lto_tree_ref_encoder_size (encoder) == 0);
981 for (j = 0; j < n; j++)
982 encoder->trees.safe_push (trees[j]);
983 encoder->next_index = n;
986 lto_free_section_data (file_data, LTO_section_function_body, name,
987 data, len);
988 free (output_stream);
989 lto_end_section ();
993 /* Main entry point from the pass manager. */
995 static void
996 lto_output (void)
998 struct lto_out_decl_state *decl_state;
999 #ifdef ENABLE_CHECKING
1000 bitmap output = lto_bitmap_alloc ();
1001 #endif
1002 int i, n_nodes;
1003 lto_symtab_encoder_t encoder = lto_get_out_decl_state ()->symtab_node_encoder;
1005 /* Initialize the streamer. */
1006 lto_streamer_init ();
1008 n_nodes = lto_symtab_encoder_size (encoder);
1009 /* Process only the functions with bodies. */
1010 for (i = 0; i < n_nodes; i++)
1012 symtab_node snode = lto_symtab_encoder_deref (encoder, i);
1013 cgraph_node *node = dyn_cast <cgraph_node> (snode);
1014 if (node
1015 && lto_symtab_encoder_encode_body_p (encoder, node)
1016 && !node->alias
1017 && !node->thunk.thunk_p)
1019 #ifdef ENABLE_CHECKING
1020 gcc_assert (!bitmap_bit_p (output, DECL_UID (node->symbol.decl)));
1021 bitmap_set_bit (output, DECL_UID (node->symbol.decl));
1022 #endif
1023 decl_state = lto_new_out_decl_state ();
1024 lto_push_out_decl_state (decl_state);
1025 if (gimple_has_body_p (node->symbol.decl))
1026 output_function (node);
1027 else
1028 copy_function (node);
1029 gcc_assert (lto_get_out_decl_state () == decl_state);
1030 lto_pop_out_decl_state ();
1031 lto_record_function_out_decl_state (node->symbol.decl, decl_state);
1035 /* Emit the callgraph after emitting function bodies. This needs to
1036 be done now to make sure that all the statements in every function
1037 have been renumbered so that edges can be associated with call
1038 statements using the statement UIDs. */
1039 output_symtab ();
1041 #ifdef ENABLE_CHECKING
1042 lto_bitmap_free (output);
1043 #endif
1046 struct ipa_opt_pass_d pass_ipa_lto_gimple_out =
1049 IPA_PASS,
1050 "lto_gimple_out", /* name */
1051 OPTGROUP_NONE, /* optinfo_flags */
1052 gate_lto_out, /* gate */
1053 NULL, /* execute */
1054 NULL, /* sub */
1055 NULL, /* next */
1056 0, /* static_pass_number */
1057 TV_IPA_LTO_GIMPLE_OUT, /* tv_id */
1058 0, /* properties_required */
1059 0, /* properties_provided */
1060 0, /* properties_destroyed */
1061 0, /* todo_flags_start */
1062 0 /* todo_flags_finish */
1064 NULL, /* generate_summary */
1065 lto_output, /* write_summary */
1066 NULL, /* read_summary */
1067 lto_output, /* write_optimization_summary */
1068 NULL, /* read_optimization_summary */
1069 NULL, /* stmt_fixup */
1070 0, /* TODOs */
1071 NULL, /* function_transform */
1072 NULL /* variable_transform */
1076 /* Write each node in encoded by ENCODER to OB, as well as those reachable
1077 from it and required for correct representation of its semantics.
1078 Each node in ENCODER must be a global declaration or a type. A node
1079 is written only once, even if it appears multiple times in the
1080 vector. Certain transitively-reachable nodes, such as those
1081 representing expressions, may be duplicated, but such nodes
1082 must not appear in ENCODER itself. */
1084 static void
1085 write_global_stream (struct output_block *ob,
1086 struct lto_tree_ref_encoder *encoder)
1088 tree t;
1089 size_t index;
1090 const size_t size = lto_tree_ref_encoder_size (encoder);
1092 for (index = 0; index < size; index++)
1094 t = lto_tree_ref_encoder_get_tree (encoder, index);
1095 if (!streamer_tree_cache_lookup (ob->writer_cache, t, NULL))
1096 stream_write_tree (ob, t, false);
1101 /* Write a sequence of indices into the globals vector corresponding
1102 to the trees in ENCODER. These are used by the reader to map the
1103 indices used to refer to global entities within function bodies to
1104 their referents. */
1106 static void
1107 write_global_references (struct output_block *ob,
1108 struct lto_output_stream *ref_stream,
1109 struct lto_tree_ref_encoder *encoder)
1111 tree t;
1112 uint32_t index;
1113 const uint32_t size = lto_tree_ref_encoder_size (encoder);
1115 /* Write size as 32-bit unsigned. */
1116 lto_output_data_stream (ref_stream, &size, sizeof (int32_t));
1118 for (index = 0; index < size; index++)
1120 uint32_t slot_num;
1122 t = lto_tree_ref_encoder_get_tree (encoder, index);
1123 streamer_tree_cache_lookup (ob->writer_cache, t, &slot_num);
1124 gcc_assert (slot_num != (unsigned)-1);
1125 lto_output_data_stream (ref_stream, &slot_num, sizeof slot_num);
1130 /* Write all the streams in an lto_out_decl_state STATE using
1131 output block OB and output stream OUT_STREAM. */
1133 void
1134 lto_output_decl_state_streams (struct output_block *ob,
1135 struct lto_out_decl_state *state)
1137 int i;
1139 for (i = 0; i < LTO_N_DECL_STREAMS; i++)
1140 write_global_stream (ob, &state->streams[i]);
1144 /* Write all the references in an lto_out_decl_state STATE using
1145 output block OB and output stream OUT_STREAM. */
1147 void
1148 lto_output_decl_state_refs (struct output_block *ob,
1149 struct lto_output_stream *out_stream,
1150 struct lto_out_decl_state *state)
1152 unsigned i;
1153 uint32_t ref;
1154 tree decl;
1156 /* Write reference to FUNCTION_DECL. If there is not function,
1157 write reference to void_type_node. */
1158 decl = (state->fn_decl) ? state->fn_decl : void_type_node;
1159 streamer_tree_cache_lookup (ob->writer_cache, decl, &ref);
1160 gcc_assert (ref != (unsigned)-1);
1161 lto_output_data_stream (out_stream, &ref, sizeof (uint32_t));
1163 for (i = 0; i < LTO_N_DECL_STREAMS; i++)
1164 write_global_references (ob, out_stream, &state->streams[i]);
1168 /* Return the written size of STATE. */
1170 static size_t
1171 lto_out_decl_state_written_size (struct lto_out_decl_state *state)
1173 int i;
1174 size_t size;
1176 size = sizeof (int32_t); /* fn_ref. */
1177 for (i = 0; i < LTO_N_DECL_STREAMS; i++)
1179 size += sizeof (int32_t); /* vector size. */
1180 size += (lto_tree_ref_encoder_size (&state->streams[i])
1181 * sizeof (int32_t));
1183 return size;
1187 /* Write symbol T into STREAM in CACHE. SEEN specifies symbols we wrote
1188 so far. */
1190 static void
1191 write_symbol (struct streamer_tree_cache_d *cache,
1192 struct lto_output_stream *stream,
1193 tree t, struct pointer_set_t *seen, bool alias)
1195 const char *name;
1196 enum gcc_plugin_symbol_kind kind;
1197 enum gcc_plugin_symbol_visibility visibility;
1198 unsigned slot_num;
1199 unsigned HOST_WIDEST_INT size;
1200 const char *comdat;
1201 unsigned char c;
1203 /* None of the following kinds of symbols are needed in the
1204 symbol table. */
1205 if (!TREE_PUBLIC (t)
1206 || is_builtin_fn (t)
1207 || DECL_ABSTRACT (t)
1208 || TREE_CODE (t) == RESULT_DECL
1209 || (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t)))
1210 return;
1212 gcc_assert (TREE_CODE (t) == VAR_DECL
1213 || TREE_CODE (t) == FUNCTION_DECL);
1215 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t));
1217 /* This behaves like assemble_name_raw in varasm.c, performing the
1218 same name manipulations that ASM_OUTPUT_LABELREF does. */
1219 name = IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name) (name));
1221 if (pointer_set_contains (seen, name))
1222 return;
1223 pointer_set_insert (seen, name);
1225 streamer_tree_cache_lookup (cache, t, &slot_num);
1226 gcc_assert (slot_num != (unsigned)-1);
1228 if (DECL_EXTERNAL (t))
1230 if (DECL_WEAK (t))
1231 kind = GCCPK_WEAKUNDEF;
1232 else
1233 kind = GCCPK_UNDEF;
1235 else
1237 if (DECL_WEAK (t))
1238 kind = GCCPK_WEAKDEF;
1239 else if (DECL_COMMON (t))
1240 kind = GCCPK_COMMON;
1241 else
1242 kind = GCCPK_DEF;
1244 /* When something is defined, it should have node attached. */
1245 gcc_assert (alias || TREE_CODE (t) != VAR_DECL
1246 || varpool_get_node (t)->finalized);
1247 gcc_assert (alias || TREE_CODE (t) != FUNCTION_DECL
1248 || (cgraph_get_node (t)
1249 && cgraph_get_node (t)->analyzed));
1252 /* Imitate what default_elf_asm_output_external do.
1253 When symbol is external, we need to output it with DEFAULT visibility
1254 when compiling with -fvisibility=default, while with HIDDEN visibility
1255 when symbol has attribute (visibility("hidden")) specified.
1256 targetm.binds_local_p check DECL_VISIBILITY_SPECIFIED and gets this
1257 right. */
1259 if (DECL_EXTERNAL (t)
1260 && !targetm.binds_local_p (t))
1261 visibility = GCCPV_DEFAULT;
1262 else
1263 switch (DECL_VISIBILITY(t))
1265 case VISIBILITY_DEFAULT:
1266 visibility = GCCPV_DEFAULT;
1267 break;
1268 case VISIBILITY_PROTECTED:
1269 visibility = GCCPV_PROTECTED;
1270 break;
1271 case VISIBILITY_HIDDEN:
1272 visibility = GCCPV_HIDDEN;
1273 break;
1274 case VISIBILITY_INTERNAL:
1275 visibility = GCCPV_INTERNAL;
1276 break;
1279 if (kind == GCCPK_COMMON
1280 && DECL_SIZE_UNIT (t)
1281 && TREE_CODE (DECL_SIZE_UNIT (t)) == INTEGER_CST)
1282 size = TREE_INT_CST_LOW (DECL_SIZE_UNIT (t));
1283 else
1284 size = 0;
1286 if (DECL_ONE_ONLY (t))
1287 comdat = IDENTIFIER_POINTER (DECL_COMDAT_GROUP (t));
1288 else
1289 comdat = "";
1291 lto_output_data_stream (stream, name, strlen (name) + 1);
1292 lto_output_data_stream (stream, comdat, strlen (comdat) + 1);
1293 c = (unsigned char) kind;
1294 lto_output_data_stream (stream, &c, 1);
1295 c = (unsigned char) visibility;
1296 lto_output_data_stream (stream, &c, 1);
1297 lto_output_data_stream (stream, &size, 8);
1298 lto_output_data_stream (stream, &slot_num, 4);
1301 /* Return true if NODE should appear in the plugin symbol table. */
1303 bool
1304 output_symbol_p (symtab_node node)
1306 struct cgraph_node *cnode;
1307 if (!symtab_real_symbol_p (node))
1308 return false;
1309 /* We keep external functions in symtab for sake of inlining
1310 and devirtualization. We do not want to see them in symbol table as
1311 references unless they are really used. */
1312 cnode = dyn_cast <cgraph_node> (node);
1313 if (cnode && DECL_EXTERNAL (cnode->symbol.decl)
1314 && cnode->callers)
1315 return true;
1317 /* Ignore all references from external vars initializers - they are not really
1318 part of the compilation unit until they are used by folding. Some symbols,
1319 like references to external construction vtables can not be referred to at all.
1320 We decide this at can_refer_decl_in_current_unit_p. */
1321 if (DECL_EXTERNAL (node->symbol.decl))
1323 int i;
1324 struct ipa_ref *ref;
1325 for (i = 0; ipa_ref_list_referring_iterate (&node->symbol.ref_list,
1326 i, ref); i++)
1328 if (ref->use == IPA_REF_ALIAS)
1329 continue;
1330 if (is_a <cgraph_node> (ref->referring))
1331 return true;
1332 if (!DECL_EXTERNAL (ref->referring->symbol.decl))
1333 return true;
1335 return false;
1337 return true;
1341 /* Write an IL symbol table to OB.
1342 SET and VSET are cgraph/varpool node sets we are outputting. */
1344 static void
1345 produce_symtab (struct output_block *ob)
1347 struct streamer_tree_cache_d *cache = ob->writer_cache;
1348 char *section_name = lto_get_section_name (LTO_section_symtab, NULL, NULL);
1349 struct pointer_set_t *seen;
1350 struct lto_output_stream stream;
1351 lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
1352 lto_symtab_encoder_iterator lsei;
1354 lto_begin_section (section_name, false);
1355 free (section_name);
1357 seen = pointer_set_create ();
1358 memset (&stream, 0, sizeof (stream));
1360 /* Write the symbol table.
1361 First write everything defined and then all declarations.
1362 This is neccesary to handle cases where we have duplicated symbols. */
1363 for (lsei = lsei_start (encoder);
1364 !lsei_end_p (lsei); lsei_next (&lsei))
1366 symtab_node node = lsei_node (lsei);
1368 if (!output_symbol_p (node) || DECL_EXTERNAL (node->symbol.decl))
1369 continue;
1370 write_symbol (cache, &stream, node->symbol.decl, seen, false);
1372 for (lsei = lsei_start (encoder);
1373 !lsei_end_p (lsei); lsei_next (&lsei))
1375 symtab_node node = lsei_node (lsei);
1377 if (!output_symbol_p (node) || !DECL_EXTERNAL (node->symbol.decl))
1378 continue;
1379 write_symbol (cache, &stream, node->symbol.decl, seen, false);
1382 lto_write_stream (&stream);
1383 pointer_set_destroy (seen);
1385 lto_end_section ();
1389 /* This pass is run after all of the functions are serialized and all
1390 of the IPA passes have written their serialized forms. This pass
1391 causes the vector of all of the global decls and types used from
1392 this file to be written in to a section that can then be read in to
1393 recover these on other side. */
1395 static void
1396 produce_asm_for_decls (void)
1398 struct lto_out_decl_state *out_state;
1399 struct lto_out_decl_state *fn_out_state;
1400 struct lto_decl_header header;
1401 char *section_name;
1402 struct output_block *ob;
1403 struct lto_output_stream *header_stream, *decl_state_stream;
1404 unsigned idx, num_fns;
1405 size_t decl_state_size;
1406 int32_t num_decl_states;
1408 ob = create_output_block (LTO_section_decls);
1409 ob->global = true;
1411 memset (&header, 0, sizeof (struct lto_decl_header));
1413 section_name = lto_get_section_name (LTO_section_decls, NULL, NULL);
1414 lto_begin_section (section_name, !flag_wpa);
1415 free (section_name);
1417 /* Make string 0 be a NULL string. */
1418 streamer_write_char_stream (ob->string_stream, 0);
1420 gcc_assert (!alias_pairs);
1422 /* Write the global symbols. */
1423 out_state = lto_get_out_decl_state ();
1424 num_fns = lto_function_decl_states.length ();
1425 lto_output_decl_state_streams (ob, out_state);
1426 for (idx = 0; idx < num_fns; idx++)
1428 fn_out_state =
1429 lto_function_decl_states[idx];
1430 lto_output_decl_state_streams (ob, fn_out_state);
1433 header.lto_header.major_version = LTO_major_version;
1434 header.lto_header.minor_version = LTO_minor_version;
1436 /* Currently not used. This field would allow us to preallocate
1437 the globals vector, so that it need not be resized as it is extended. */
1438 header.num_nodes = -1;
1440 /* Compute the total size of all decl out states. */
1441 decl_state_size = sizeof (int32_t);
1442 decl_state_size += lto_out_decl_state_written_size (out_state);
1443 for (idx = 0; idx < num_fns; idx++)
1445 fn_out_state =
1446 lto_function_decl_states[idx];
1447 decl_state_size += lto_out_decl_state_written_size (fn_out_state);
1449 header.decl_state_size = decl_state_size;
1451 header.main_size = ob->main_stream->total_size;
1452 header.string_size = ob->string_stream->total_size;
1454 header_stream = XCNEW (struct lto_output_stream);
1455 lto_output_data_stream (header_stream, &header, sizeof header);
1456 lto_write_stream (header_stream);
1457 free (header_stream);
1459 /* Write the main out-decl state, followed by out-decl states of
1460 functions. */
1461 decl_state_stream = XCNEW (struct lto_output_stream);
1462 num_decl_states = num_fns + 1;
1463 lto_output_data_stream (decl_state_stream, &num_decl_states,
1464 sizeof (num_decl_states));
1465 lto_output_decl_state_refs (ob, decl_state_stream, out_state);
1466 for (idx = 0; idx < num_fns; idx++)
1468 fn_out_state =
1469 lto_function_decl_states[idx];
1470 lto_output_decl_state_refs (ob, decl_state_stream, fn_out_state);
1472 lto_write_stream (decl_state_stream);
1473 free(decl_state_stream);
1475 lto_write_stream (ob->main_stream);
1476 lto_write_stream (ob->string_stream);
1478 lto_end_section ();
1480 /* Write the symbol table. It is used by linker to determine dependencies
1481 and thus we can skip it for WPA. */
1482 if (!flag_wpa)
1483 produce_symtab (ob);
1485 /* Write command line opts. */
1486 lto_write_options ();
1488 /* Deallocate memory and clean up. */
1489 for (idx = 0; idx < num_fns; idx++)
1491 fn_out_state =
1492 lto_function_decl_states[idx];
1493 lto_delete_out_decl_state (fn_out_state);
1495 lto_symtab_encoder_delete (ob->decl_state->symtab_node_encoder);
1496 lto_function_decl_states.release ();
1497 destroy_output_block (ob);
1501 struct ipa_opt_pass_d pass_ipa_lto_finish_out =
1504 IPA_PASS,
1505 "lto_decls_out", /* name */
1506 OPTGROUP_NONE, /* optinfo_flags */
1507 gate_lto_out, /* gate */
1508 NULL, /* execute */
1509 NULL, /* sub */
1510 NULL, /* next */
1511 0, /* static_pass_number */
1512 TV_IPA_LTO_DECL_OUT, /* tv_id */
1513 0, /* properties_required */
1514 0, /* properties_provided */
1515 0, /* properties_destroyed */
1516 0, /* todo_flags_start */
1517 0 /* todo_flags_finish */
1519 NULL, /* generate_summary */
1520 produce_asm_for_decls, /* write_summary */
1521 NULL, /* read_summary */
1522 produce_asm_for_decls, /* write_optimization_summary */
1523 NULL, /* read_optimization_summary */
1524 NULL, /* stmt_fixup */
1525 0, /* TODOs */
1526 NULL, /* function_transform */
1527 NULL /* variable_transform */