1 /* Write the GIMPLE representation to a file stream.
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>
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
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
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/>. */
25 #include "coretypes.h"
34 #include "basic-block.h"
35 #include "tree-flow.h"
36 #include "tree-pass.h"
40 #include "diagnostic-core.h"
43 #include "lto-symtab.h"
44 #include "lto-streamer.h"
51 unsigned int slot_num
;
55 /* Returns a hash code for P. */
58 hash_string_slot_node (const void *p
)
60 const struct string_slot
*ds
= (const struct string_slot
*) p
;
61 return (hashval_t
) htab_hash_string (ds
->s
);
65 /* Returns nonzero if P1 and P2 are equal. */
68 eq_string_slot_node (const void *p1
, const void *p2
)
70 const struct string_slot
*ds1
= (const struct string_slot
*) p1
;
71 const struct string_slot
*ds2
= (const struct string_slot
*) p2
;
73 if (ds1
->len
== ds2
->len
)
76 for (i
= 0; i
< ds1
->len
; i
++)
77 if (ds1
->s
[i
] != ds2
->s
[i
])
86 /* Free the string slot pointed-to by P. */
89 string_slot_free (void *p
)
91 struct string_slot
*slot
= (struct string_slot
*) p
;
92 free (CONST_CAST (void *, (const void *) slot
->s
));
97 /* Clear the line info stored in DATA_IN. */
100 clear_line_info (struct output_block
*ob
)
102 ob
->current_file
= NULL
;
103 ob
->current_line
= 0;
108 /* Create the output block and return it. SECTION_TYPE is
109 LTO_section_function_body or LTO_static_initializer. */
111 struct output_block
*
112 create_output_block (enum lto_section_type section_type
)
114 struct output_block
*ob
= XCNEW (struct output_block
);
116 ob
->section_type
= section_type
;
117 ob
->decl_state
= lto_get_out_decl_state ();
118 ob
->main_stream
= XCNEW (struct lto_output_stream
);
119 ob
->string_stream
= XCNEW (struct lto_output_stream
);
120 ob
->writer_cache
= lto_streamer_cache_create ();
122 if (section_type
== LTO_section_function_body
)
123 ob
->cfg_stream
= XCNEW (struct lto_output_stream
);
125 clear_line_info (ob
);
127 ob
->string_hash_table
= htab_create (37, hash_string_slot_node
,
128 eq_string_slot_node
, string_slot_free
);
134 /* Destroy the output block OB. */
137 destroy_output_block (struct output_block
*ob
)
139 enum lto_section_type section_type
= ob
->section_type
;
141 htab_delete (ob
->string_hash_table
);
143 free (ob
->main_stream
);
144 free (ob
->string_stream
);
145 if (section_type
== LTO_section_function_body
)
146 free (ob
->cfg_stream
);
148 lto_streamer_cache_delete (ob
->writer_cache
);
154 /* Output bitpack BP to output stream S. */
157 lto_output_bitpack (struct lto_output_stream
*s
, struct bitpack_d
*bp
)
162 lto_output_uleb128_stream (s
, VEC_length (bitpack_word_t
, bp
->values
));
163 for (i
= 0; VEC_iterate (bitpack_word_t
, bp
->values
, i
, v
); i
++)
164 lto_output_uleb128_stream (s
, v
);
168 /* Output STRING of LEN characters to the string
169 table in OB. The string might or might not include a trailing '\0'.
170 Then put the index onto the INDEX_STREAM. */
173 output_string_with_length (struct output_block
*ob
,
174 struct lto_output_stream
*index_stream
,
178 struct string_slot
**slot
;
179 struct string_slot s_slot
;
180 char *string
= (char *) xmalloc (len
+ 1);
181 memcpy (string
, s
, len
);
188 slot
= (struct string_slot
**) htab_find_slot (ob
->string_hash_table
,
192 struct lto_output_stream
*string_stream
= ob
->string_stream
;
193 unsigned int start
= string_stream
->total_size
;
194 struct string_slot
*new_slot
195 = (struct string_slot
*) xmalloc (sizeof (struct string_slot
));
198 new_slot
->s
= string
;
200 new_slot
->slot_num
= start
;
202 lto_output_uleb128_stream (index_stream
, start
);
203 lto_output_uleb128_stream (string_stream
, len
);
204 for (i
= 0; i
< len
; i
++)
205 lto_output_1_stream (string_stream
, string
[i
]);
209 struct string_slot
*old_slot
= (struct string_slot
*)*slot
;
210 lto_output_uleb128_stream (index_stream
, old_slot
->slot_num
);
215 /* Output the '\0' terminated STRING to the string
216 table in OB. Then put the index onto the INDEX_STREAM. */
219 output_string (struct output_block
*ob
,
220 struct lto_output_stream
*index_stream
,
225 lto_output_uleb128_stream (index_stream
, 0);
226 output_string_with_length (ob
, index_stream
, string
, strlen (string
) + 1);
229 lto_output_uleb128_stream (index_stream
, 1);
233 /* Output the STRING constant to the string
234 table in OB. Then put the index onto the INDEX_STREAM. */
237 output_string_cst (struct output_block
*ob
,
238 struct lto_output_stream
*index_stream
,
243 lto_output_uleb128_stream (index_stream
, 0);
244 output_string_with_length (ob
, index_stream
,
245 TREE_STRING_POINTER (string
),
246 TREE_STRING_LENGTH (string
));
249 lto_output_uleb128_stream (index_stream
, 1);
253 /* Output the identifier ID to the string
254 table in OB. Then put the index onto the INDEX_STREAM. */
257 output_identifier (struct output_block
*ob
,
258 struct lto_output_stream
*index_stream
,
263 lto_output_uleb128_stream (index_stream
, 0);
264 output_string_with_length (ob
, index_stream
,
265 IDENTIFIER_POINTER (id
),
266 IDENTIFIER_LENGTH (id
));
269 lto_output_uleb128_stream (index_stream
, 1);
272 /* Write a zero to the output stream. */
275 output_zero (struct output_block
*ob
)
277 lto_output_1_stream (ob
->main_stream
, 0);
281 /* Output an unsigned LEB128 quantity to OB->main_stream. */
284 output_uleb128 (struct output_block
*ob
, unsigned HOST_WIDE_INT work
)
286 lto_output_uleb128_stream (ob
->main_stream
, work
);
290 /* Output a signed LEB128 quantity to OB->main_stream. */
293 output_sleb128 (struct output_block
*ob
, HOST_WIDE_INT work
)
295 lto_output_sleb128_stream (ob
->main_stream
, work
);
299 /* Output the start of a record with TAG to output block OB. */
302 output_record_start (struct output_block
*ob
, enum LTO_tags tag
)
304 /* Make sure TAG fits inside an unsigned int. */
305 gcc_assert (tag
== (enum LTO_tags
) (unsigned) tag
);
306 output_uleb128 (ob
, tag
);
310 /* Look up NODE in the type table and write the index for it to OB. */
313 output_type_ref (struct output_block
*ob
, tree node
)
315 output_record_start (ob
, LTO_type_ref
);
316 lto_output_type_ref_index (ob
->decl_state
, ob
->main_stream
, node
);
320 /* Pack all the non-pointer fields of the TS_BASE structure of
321 expression EXPR into bitpack BP. */
324 pack_ts_base_value_fields (struct bitpack_d
*bp
, tree expr
)
326 bp_pack_value (bp
, TREE_CODE (expr
), 16);
329 bp_pack_value (bp
, TREE_SIDE_EFFECTS (expr
), 1);
330 bp_pack_value (bp
, TREE_CONSTANT (expr
), 1);
331 bp_pack_value (bp
, TREE_READONLY (expr
), 1);
333 /* TREE_PUBLIC is used on types to indicate that the type
334 has a TYPE_CACHED_VALUES vector. This is not streamed out,
335 so we skip it here. */
336 bp_pack_value (bp
, TREE_PUBLIC (expr
), 1);
338 bp_pack_value (bp
, TREE_ADDRESSABLE (expr
), 1);
339 bp_pack_value (bp
, TREE_THIS_VOLATILE (expr
), 1);
341 bp_pack_value (bp
, DECL_UNSIGNED (expr
), 1);
342 else if (TYPE_P (expr
))
343 bp_pack_value (bp
, TYPE_UNSIGNED (expr
), 1);
344 /* We write debug info two times, do not confuse the second one. */
345 bp_pack_value (bp
, TYPE_P (expr
) ? 0 : TREE_ASM_WRITTEN (expr
), 1);
346 bp_pack_value (bp
, TREE_NO_WARNING (expr
), 1);
347 bp_pack_value (bp
, TREE_USED (expr
), 1);
348 bp_pack_value (bp
, TREE_NOTHROW (expr
), 1);
349 bp_pack_value (bp
, TREE_STATIC (expr
), 1);
350 bp_pack_value (bp
, TREE_PRIVATE (expr
), 1);
351 bp_pack_value (bp
, TREE_PROTECTED (expr
), 1);
352 bp_pack_value (bp
, TREE_DEPRECATED (expr
), 1);
354 bp_pack_value (bp
, TYPE_SATURATING (expr
), 1);
355 if (TREE_CODE (expr
) == SSA_NAME
)
356 bp_pack_value (bp
, SSA_NAME_IS_DEFAULT_DEF (expr
), 1);
360 /* Pack all the non-pointer fields of the TS_REAL_CST structure of
361 expression EXPR into bitpack BP. */
364 pack_ts_real_cst_value_fields (struct bitpack_d
*bp
, tree expr
)
369 r
= TREE_REAL_CST (expr
);
370 bp_pack_value (bp
, r
.cl
, 2);
371 bp_pack_value (bp
, r
.decimal
, 1);
372 bp_pack_value (bp
, r
.sign
, 1);
373 bp_pack_value (bp
, r
.signalling
, 1);
374 bp_pack_value (bp
, r
.canonical
, 1);
375 bp_pack_value (bp
, r
.uexp
, EXP_BITS
);
376 for (i
= 0; i
< SIGSZ
; i
++)
377 bp_pack_value (bp
, r
.sig
[i
], HOST_BITS_PER_LONG
);
381 /* Pack all the non-pointer fields of the TS_FIXED_CST structure of
382 expression EXPR into bitpack BP. */
385 pack_ts_fixed_cst_value_fields (struct bitpack_d
*bp
, tree expr
)
387 struct fixed_value fv
= TREE_FIXED_CST (expr
);
388 bp_pack_value (bp
, fv
.data
.low
, HOST_BITS_PER_WIDE_INT
);
389 bp_pack_value (bp
, fv
.data
.high
, HOST_BITS_PER_WIDE_INT
);
390 bp_pack_value (bp
, fv
.mode
, HOST_BITS_PER_INT
);
394 /* Pack all the non-pointer fields of the TS_DECL_COMMON structure
395 of expression EXPR into bitpack BP. */
398 pack_ts_decl_common_value_fields (struct bitpack_d
*bp
, tree expr
)
400 bp_pack_value (bp
, DECL_MODE (expr
), 8);
401 bp_pack_value (bp
, DECL_NONLOCAL (expr
), 1);
402 bp_pack_value (bp
, DECL_VIRTUAL_P (expr
), 1);
403 bp_pack_value (bp
, DECL_IGNORED_P (expr
), 1);
404 bp_pack_value (bp
, DECL_ABSTRACT (expr
), 1);
405 bp_pack_value (bp
, DECL_ARTIFICIAL (expr
), 1);
406 bp_pack_value (bp
, DECL_USER_ALIGN (expr
), 1);
407 bp_pack_value (bp
, DECL_PRESERVE_P (expr
), 1);
408 bp_pack_value (bp
, DECL_DEBUG_EXPR_IS_FROM (expr
), 1);
409 bp_pack_value (bp
, DECL_EXTERNAL (expr
), 1);
410 bp_pack_value (bp
, DECL_GIMPLE_REG_P (expr
), 1);
411 bp_pack_value (bp
, DECL_ALIGN (expr
), HOST_BITS_PER_INT
);
413 if (TREE_CODE (expr
) == LABEL_DECL
)
415 /* Note that we do not write LABEL_DECL_UID. The reader will
416 always assume an initial value of -1 so that the
417 label_to_block_map is recreated by gimple_set_bb. */
418 bp_pack_value (bp
, DECL_ERROR_ISSUED (expr
), 1);
419 bp_pack_value (bp
, EH_LANDING_PAD_NR (expr
), HOST_BITS_PER_INT
);
422 if (TREE_CODE (expr
) == FIELD_DECL
)
424 bp_pack_value (bp
, DECL_PACKED (expr
), 1);
425 bp_pack_value (bp
, DECL_NONADDRESSABLE_P (expr
), 1);
426 bp_pack_value (bp
, DECL_OFFSET_ALIGN (expr
), 8);
429 if (TREE_CODE (expr
) == RESULT_DECL
430 || TREE_CODE (expr
) == PARM_DECL
431 || TREE_CODE (expr
) == VAR_DECL
)
433 bp_pack_value (bp
, DECL_BY_REFERENCE (expr
), 1);
434 if (TREE_CODE (expr
) == VAR_DECL
435 || TREE_CODE (expr
) == PARM_DECL
)
436 bp_pack_value (bp
, DECL_HAS_VALUE_EXPR_P (expr
), 1);
437 bp_pack_value (bp
, DECL_RESTRICTED_P (expr
), 1);
442 /* Pack all the non-pointer fields of the TS_DECL_WRTL structure
443 of expression EXPR into bitpack BP. */
446 pack_ts_decl_wrtl_value_fields (struct bitpack_d
*bp
, tree expr
)
448 bp_pack_value (bp
, DECL_REGISTER (expr
), 1);
452 /* Pack all the non-pointer fields of the TS_DECL_WITH_VIS structure
453 of expression EXPR into bitpack BP. */
456 pack_ts_decl_with_vis_value_fields (struct bitpack_d
*bp
, tree expr
)
458 bp_pack_value (bp
, DECL_DEFER_OUTPUT (expr
), 1);
459 bp_pack_value (bp
, DECL_COMMON (expr
), 1);
460 bp_pack_value (bp
, DECL_DLLIMPORT_P (expr
), 1);
461 bp_pack_value (bp
, DECL_WEAK (expr
), 1);
462 bp_pack_value (bp
, DECL_SEEN_IN_BIND_EXPR_P (expr
), 1);
463 bp_pack_value (bp
, DECL_COMDAT (expr
), 1);
464 bp_pack_value (bp
, DECL_VISIBILITY (expr
), 2);
465 bp_pack_value (bp
, DECL_VISIBILITY_SPECIFIED (expr
), 1);
467 if (TREE_CODE (expr
) == VAR_DECL
)
469 bp_pack_value (bp
, DECL_HARD_REGISTER (expr
), 1);
470 bp_pack_value (bp
, DECL_IN_TEXT_SECTION (expr
), 1);
471 bp_pack_value (bp
, DECL_IN_CONSTANT_POOL (expr
), 1);
472 bp_pack_value (bp
, DECL_TLS_MODEL (expr
), 3);
475 if (VAR_OR_FUNCTION_DECL_P (expr
))
476 bp_pack_value (bp
, DECL_INIT_PRIORITY (expr
), HOST_BITS_PER_SHORT
);
480 /* Pack all the non-pointer fields of the TS_FUNCTION_DECL structure
481 of expression EXPR into bitpack BP. */
484 pack_ts_function_decl_value_fields (struct bitpack_d
*bp
, tree expr
)
486 /* For normal/md builtins we only write the class and code, so they
487 should never be handled here. */
488 gcc_assert (!lto_stream_as_builtin_p (expr
));
490 bp_pack_value (bp
, DECL_FUNCTION_CODE (expr
), 11);
491 bp_pack_value (bp
, DECL_BUILT_IN_CLASS (expr
), 2);
492 bp_pack_value (bp
, DECL_STATIC_CONSTRUCTOR (expr
), 1);
493 bp_pack_value (bp
, DECL_STATIC_DESTRUCTOR (expr
), 1);
494 bp_pack_value (bp
, DECL_UNINLINABLE (expr
), 1);
495 bp_pack_value (bp
, DECL_POSSIBLY_INLINED (expr
), 1);
496 bp_pack_value (bp
, DECL_IS_NOVOPS (expr
), 1);
497 bp_pack_value (bp
, DECL_IS_RETURNS_TWICE (expr
), 1);
498 bp_pack_value (bp
, DECL_IS_MALLOC (expr
), 1);
499 bp_pack_value (bp
, DECL_IS_OPERATOR_NEW (expr
), 1);
500 bp_pack_value (bp
, DECL_DECLARED_INLINE_P (expr
), 1);
501 bp_pack_value (bp
, DECL_STATIC_CHAIN (expr
), 1);
502 bp_pack_value (bp
, DECL_NO_INLINE_WARNING_P (expr
), 1);
503 bp_pack_value (bp
, DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (expr
), 1);
504 bp_pack_value (bp
, DECL_NO_LIMIT_STACK (expr
), 1);
505 bp_pack_value (bp
, DECL_DISREGARD_INLINE_LIMITS (expr
), 1);
506 bp_pack_value (bp
, DECL_PURE_P (expr
), 1);
507 bp_pack_value (bp
, DECL_LOOPING_CONST_OR_PURE_P (expr
), 1);
511 /* Pack all the non-pointer fields of the TS_TYPE structure
512 of expression EXPR into bitpack BP. */
515 pack_ts_type_value_fields (struct bitpack_d
*bp
, tree expr
)
517 bp_pack_value (bp
, TYPE_PRECISION (expr
), 10);
518 bp_pack_value (bp
, TYPE_MODE (expr
), 8);
519 bp_pack_value (bp
, TYPE_STRING_FLAG (expr
), 1);
520 bp_pack_value (bp
, TYPE_NO_FORCE_BLK (expr
), 1);
521 bp_pack_value (bp
, TYPE_NEEDS_CONSTRUCTING (expr
), 1);
522 if (RECORD_OR_UNION_TYPE_P (expr
))
523 bp_pack_value (bp
, TYPE_TRANSPARENT_AGGR (expr
), 1);
524 bp_pack_value (bp
, TYPE_PACKED (expr
), 1);
525 bp_pack_value (bp
, TYPE_RESTRICT (expr
), 1);
526 bp_pack_value (bp
, TYPE_CONTAINS_PLACEHOLDER_INTERNAL (expr
), 2);
527 bp_pack_value (bp
, TYPE_USER_ALIGN (expr
), 1);
528 bp_pack_value (bp
, TYPE_READONLY (expr
), 1);
529 bp_pack_value (bp
, TYPE_ALIGN (expr
), HOST_BITS_PER_INT
);
530 bp_pack_value (bp
, TYPE_ALIAS_SET (expr
) == 0 ? 0 : -1, HOST_BITS_PER_INT
);
534 /* Pack all the non-pointer fields of the TS_BLOCK structure
535 of expression EXPR into bitpack BP. */
538 pack_ts_block_value_fields (struct bitpack_d
*bp
, tree expr
)
540 bp_pack_value (bp
, BLOCK_ABSTRACT (expr
), 1);
541 bp_pack_value (bp
, BLOCK_NUMBER (expr
), 31);
545 /* Pack all the non-pointer fields in EXPR into a bit pack. */
547 static struct bitpack_d
*
548 pack_value_fields (tree expr
)
551 struct bitpack_d
*bp
;
553 code
= TREE_CODE (expr
);
554 bp
= bitpack_create ();
556 /* Note that all these functions are highly sensitive to changes in
557 the types and sizes of each of the fields being packed. */
558 pack_ts_base_value_fields (bp
, expr
);
560 if (CODE_CONTAINS_STRUCT (code
, TS_REAL_CST
))
561 pack_ts_real_cst_value_fields (bp
, expr
);
563 if (CODE_CONTAINS_STRUCT (code
, TS_FIXED_CST
))
564 pack_ts_fixed_cst_value_fields (bp
, expr
);
566 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
567 pack_ts_decl_common_value_fields (bp
, expr
);
569 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WRTL
))
570 pack_ts_decl_wrtl_value_fields (bp
, expr
);
572 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
573 pack_ts_decl_with_vis_value_fields (bp
, expr
);
575 if (CODE_CONTAINS_STRUCT (code
, TS_FUNCTION_DECL
))
576 pack_ts_function_decl_value_fields (bp
, expr
);
578 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE
))
579 pack_ts_type_value_fields (bp
, expr
);
581 if (CODE_CONTAINS_STRUCT (code
, TS_BLOCK
))
582 pack_ts_block_value_fields (bp
, expr
);
584 if (CODE_CONTAINS_STRUCT (code
, TS_SSA_NAME
))
586 /* We only stream the version number of SSA names. */
590 if (CODE_CONTAINS_STRUCT (code
, TS_STATEMENT_LIST
))
592 /* This is only used by GENERIC. */
596 if (CODE_CONTAINS_STRUCT (code
, TS_OMP_CLAUSE
))
598 /* This is only used by High GIMPLE. */
606 /* Emit location LOC to output block OB. */
609 lto_output_location (struct output_block
*ob
, location_t loc
)
611 expanded_location xloc
;
613 if (loc
== UNKNOWN_LOCATION
)
615 output_string (ob
, ob
->main_stream
, NULL
);
619 xloc
= expand_location (loc
);
621 output_string (ob
, ob
->main_stream
, xloc
.file
);
622 output_sleb128 (ob
, xloc
.line
);
623 output_sleb128 (ob
, xloc
.column
);
624 output_sleb128 (ob
, xloc
.sysp
);
626 ob
->current_file
= xloc
.file
;
627 ob
->current_line
= xloc
.line
;
628 ob
->current_col
= xloc
.column
;
632 /* Return true if tree node T is written to various tables. For these
633 nodes, we sometimes want to write their phyiscal representation
634 (via lto_output_tree), and sometimes we need to emit an index
635 reference into a table (via lto_output_tree_ref). */
638 tree_is_indexable (tree t
)
640 if (TREE_CODE (t
) == PARM_DECL
)
642 else if (TREE_CODE (t
) == VAR_DECL
&& decl_function_context (t
)
646 return (TYPE_P (t
) || DECL_P (t
) || TREE_CODE (t
) == SSA_NAME
);
650 /* If EXPR is an indexable tree node, output a reference to it to
651 output block OB. Otherwise, output the physical representation of
655 lto_output_tree_ref (struct output_block
*ob
, tree expr
)
659 if (expr
== NULL_TREE
)
665 if (!tree_is_indexable (expr
))
667 /* Even though we are emitting the physical representation of
668 EXPR, its leaves must be emitted as references. */
669 lto_output_tree (ob
, expr
, true);
675 output_type_ref (ob
, expr
);
679 code
= TREE_CODE (expr
);
683 output_record_start (ob
, LTO_ssa_name_ref
);
684 output_uleb128 (ob
, SSA_NAME_VERSION (expr
));
688 output_record_start (ob
, LTO_field_decl_ref
);
689 lto_output_field_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
693 output_record_start (ob
, LTO_function_decl_ref
);
694 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
698 case DEBUG_EXPR_DECL
:
699 gcc_assert (decl_function_context (expr
) == NULL
700 || TREE_STATIC (expr
));
701 output_record_start (ob
, LTO_global_decl_ref
);
702 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
706 output_record_start (ob
, LTO_const_decl_ref
);
707 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
711 gcc_assert (decl_function_context (expr
) == NULL
);
712 output_record_start (ob
, LTO_imported_decl_ref
);
713 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
717 output_record_start (ob
, LTO_type_decl_ref
);
718 lto_output_type_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
722 output_record_start (ob
, LTO_namespace_decl_ref
);
723 lto_output_namespace_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
727 output_record_start (ob
, LTO_label_decl_ref
);
728 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
732 output_record_start (ob
, LTO_result_decl_ref
);
733 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
737 /* No other node is indexable, so it should have been handled
738 by lto_output_tree. */
744 /* If REF_P is true, emit a reference to EXPR in output block OB,
745 otherwise emit the physical representation of EXPR in OB. */
748 lto_output_tree_or_ref (struct output_block
*ob
, tree expr
, bool ref_p
)
751 lto_output_tree_ref (ob
, expr
);
753 lto_output_tree (ob
, expr
, false);
757 /* Emit the chain of tree nodes starting at T. OB is the output block
758 to write to. REF_P is true if chain elements should be emitted
762 lto_output_chain (struct output_block
*ob
, tree t
, bool ref_p
)
766 count
= list_length (t
);
767 output_sleb128 (ob
, count
);
768 for (i
= 0; i
< count
; i
++)
772 /* Clear TREE_CHAIN to avoid blindly recursing into the rest
774 saved_chain
= TREE_CHAIN (t
);
775 TREE_CHAIN (t
) = NULL_TREE
;
777 lto_output_tree_or_ref (ob
, t
, ref_p
);
779 TREE_CHAIN (t
) = saved_chain
;
785 /* Write all pointer fields in the TS_COMMON structure of EXPR to output
786 block OB. If REF_P is true, write a reference to EXPR's pointer
790 lto_output_ts_common_tree_pointers (struct output_block
*ob
, tree expr
,
793 lto_output_tree_or_ref (ob
, TREE_TYPE (expr
), ref_p
);
797 /* Write all pointer fields in the TS_VECTOR structure of EXPR to output
798 block OB. If REF_P is true, write a reference to EXPR's pointer
802 lto_output_ts_vector_tree_pointers (struct output_block
*ob
, tree expr
,
805 lto_output_chain (ob
, TREE_VECTOR_CST_ELTS (expr
), ref_p
);
809 /* Write all pointer fields in the TS_COMPLEX structure of EXPR to output
810 block OB. If REF_P is true, write a reference to EXPR's pointer
814 lto_output_ts_complex_tree_pointers (struct output_block
*ob
, tree expr
,
817 lto_output_tree_or_ref (ob
, TREE_REALPART (expr
), ref_p
);
818 lto_output_tree_or_ref (ob
, TREE_IMAGPART (expr
), ref_p
);
822 /* Write all pointer fields in the TS_DECL_MINIMAL structure of EXPR
823 to output block OB. If REF_P is true, write a reference to EXPR's
827 lto_output_ts_decl_minimal_tree_pointers (struct output_block
*ob
, tree expr
,
830 lto_output_tree_or_ref (ob
, DECL_NAME (expr
), ref_p
);
831 lto_output_tree_or_ref (ob
, DECL_CONTEXT (expr
), ref_p
);
832 lto_output_location (ob
, DECL_SOURCE_LOCATION (expr
));
836 /* Write all pointer fields in the TS_DECL_COMMON structure of EXPR to
837 output block OB. If REF_P is true, write a reference to EXPR's
841 lto_output_ts_decl_common_tree_pointers (struct output_block
*ob
, tree expr
,
844 lto_output_tree_or_ref (ob
, DECL_SIZE (expr
), ref_p
);
845 lto_output_tree_or_ref (ob
, DECL_SIZE_UNIT (expr
), ref_p
);
847 if (TREE_CODE (expr
) != FUNCTION_DECL
)
849 tree initial
= DECL_INITIAL (expr
);
850 if (TREE_CODE (expr
) == VAR_DECL
851 && (TREE_STATIC (expr
) || DECL_EXTERNAL (expr
))
854 lto_varpool_encoder_t varpool_encoder
= ob
->decl_state
->varpool_node_encoder
;
855 struct varpool_node
*vnode
= varpool_get_node (expr
);
857 initial
= error_mark_node
;
858 else if (!lto_varpool_encoder_encode_initializer_p (varpool_encoder
,
863 lto_output_tree_or_ref (ob
, initial
, ref_p
);
866 lto_output_tree_or_ref (ob
, DECL_ATTRIBUTES (expr
), ref_p
);
867 lto_output_tree_or_ref (ob
, DECL_ABSTRACT_ORIGIN (expr
), ref_p
);
869 if (TREE_CODE (expr
) == PARM_DECL
)
870 lto_output_chain (ob
, TREE_CHAIN (expr
), ref_p
);
872 if ((TREE_CODE (expr
) == VAR_DECL
873 || TREE_CODE (expr
) == PARM_DECL
)
874 && DECL_HAS_VALUE_EXPR_P (expr
))
875 lto_output_tree_or_ref (ob
, DECL_VALUE_EXPR (expr
), ref_p
);
879 /* Write all pointer fields in the TS_DECL_NON_COMMON structure of
880 EXPR to output block OB. If REF_P is true, write a reference to EXPR's
884 lto_output_ts_decl_non_common_tree_pointers (struct output_block
*ob
,
885 tree expr
, bool ref_p
)
887 if (TREE_CODE (expr
) == FUNCTION_DECL
)
889 /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
890 At this point, it should not exist. Either because it was
891 converted to gimple or because DECL didn't have a GENERIC
892 representation in this TU. */
893 gcc_assert (DECL_SAVED_TREE (expr
) == NULL_TREE
);
894 lto_output_tree_or_ref (ob
, DECL_ARGUMENTS (expr
), ref_p
);
895 lto_output_tree_or_ref (ob
, DECL_RESULT (expr
), ref_p
);
897 lto_output_tree_or_ref (ob
, DECL_VINDEX (expr
), ref_p
);
901 /* Write all pointer fields in the TS_DECL_WITH_VIS structure of EXPR
902 to output block OB. If REF_P is true, write a reference to EXPR's
906 lto_output_ts_decl_with_vis_tree_pointers (struct output_block
*ob
, tree expr
,
909 /* Make sure we don't inadvertently set the assembler name. */
910 if (DECL_ASSEMBLER_NAME_SET_P (expr
))
911 lto_output_tree_or_ref (ob
, DECL_ASSEMBLER_NAME (expr
), ref_p
);
915 lto_output_tree_or_ref (ob
, DECL_SECTION_NAME (expr
), ref_p
);
916 lto_output_tree_or_ref (ob
, DECL_COMDAT_GROUP (expr
), ref_p
);
920 /* Write all pointer fields in the TS_FIELD_DECL structure of EXPR to
921 output block OB. If REF_P is true, write a reference to EXPR's
925 lto_output_ts_field_decl_tree_pointers (struct output_block
*ob
, tree expr
,
928 lto_output_tree_or_ref (ob
, DECL_FIELD_OFFSET (expr
), ref_p
);
929 lto_output_tree_or_ref (ob
, DECL_BIT_FIELD_TYPE (expr
), ref_p
);
930 lto_output_tree_or_ref (ob
, DECL_QUALIFIER (expr
), ref_p
);
931 lto_output_tree_or_ref (ob
, DECL_FIELD_BIT_OFFSET (expr
), ref_p
);
932 lto_output_tree_or_ref (ob
, DECL_FCONTEXT (expr
), ref_p
);
933 lto_output_chain (ob
, TREE_CHAIN (expr
), ref_p
);
937 /* Write all pointer fields in the TS_FUNCTION_DECL structure of EXPR
938 to output block OB. If REF_P is true, write a reference to EXPR's
942 lto_output_ts_function_decl_tree_pointers (struct output_block
*ob
, tree expr
,
945 /* DECL_STRUCT_FUNCTION is handled by lto_output_function. FIXME lto,
946 maybe it should be handled here? */
947 lto_output_tree_or_ref (ob
, DECL_FUNCTION_PERSONALITY (expr
), ref_p
);
948 lto_output_tree_or_ref (ob
, DECL_FUNCTION_SPECIFIC_TARGET (expr
), ref_p
);
949 lto_output_tree_or_ref (ob
, DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr
),
954 /* Write all pointer fields in the TS_TYPE structure of EXPR to output
955 block OB. If REF_P is true, write a reference to EXPR's pointer
959 lto_output_ts_type_tree_pointers (struct output_block
*ob
, tree expr
,
962 if (TREE_CODE (expr
) == ENUMERAL_TYPE
)
963 lto_output_tree_or_ref (ob
, TYPE_VALUES (expr
), ref_p
);
964 else if (TREE_CODE (expr
) == ARRAY_TYPE
)
965 lto_output_tree_or_ref (ob
, TYPE_DOMAIN (expr
), ref_p
);
966 else if (RECORD_OR_UNION_TYPE_P (expr
))
967 lto_output_tree_or_ref (ob
, TYPE_FIELDS (expr
), ref_p
);
968 else if (TREE_CODE (expr
) == FUNCTION_TYPE
969 || TREE_CODE (expr
) == METHOD_TYPE
)
970 lto_output_tree_or_ref (ob
, TYPE_ARG_TYPES (expr
), ref_p
);
971 else if (TREE_CODE (expr
) == VECTOR_TYPE
)
972 lto_output_tree_or_ref (ob
, TYPE_DEBUG_REPRESENTATION_TYPE (expr
), ref_p
);
974 lto_output_tree_or_ref (ob
, TYPE_SIZE (expr
), ref_p
);
975 lto_output_tree_or_ref (ob
, TYPE_SIZE_UNIT (expr
), ref_p
);
976 lto_output_tree_or_ref (ob
, TYPE_ATTRIBUTES (expr
), ref_p
);
977 lto_output_tree_or_ref (ob
, TYPE_NAME (expr
), ref_p
);
978 /* Do not stream TYPE_POINTER_TO or TYPE_REFERENCE_TO nor
979 TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. */
980 if (!POINTER_TYPE_P (expr
))
981 lto_output_tree_or_ref (ob
, TYPE_MINVAL (expr
), ref_p
);
982 lto_output_tree_or_ref (ob
, TYPE_MAXVAL (expr
), ref_p
);
983 lto_output_tree_or_ref (ob
, TYPE_MAIN_VARIANT (expr
), ref_p
);
984 /* Do not stream TYPE_NEXT_VARIANT, we reconstruct the variant lists
986 if (RECORD_OR_UNION_TYPE_P (expr
))
987 lto_output_tree_or_ref (ob
, TYPE_BINFO (expr
), ref_p
);
988 lto_output_tree_or_ref (ob
, TYPE_CONTEXT (expr
), ref_p
);
989 /* TYPE_CANONICAL is re-computed during type merging, so no need
990 to stream it here. */
991 lto_output_tree_or_ref (ob
, TYPE_STUB_DECL (expr
), ref_p
);
995 /* Write all pointer fields in the TS_LIST structure of EXPR to output
996 block OB. If REF_P is true, write a reference to EXPR's pointer
1000 lto_output_ts_list_tree_pointers (struct output_block
*ob
, tree expr
,
1003 lto_output_tree_or_ref (ob
, TREE_PURPOSE (expr
), ref_p
);
1004 lto_output_tree_or_ref (ob
, TREE_VALUE (expr
), ref_p
);
1005 lto_output_chain (ob
, TREE_CHAIN (expr
), ref_p
);
1009 /* Write all pointer fields in the TS_VEC structure of EXPR to output
1010 block OB. If REF_P is true, write a reference to EXPR's pointer
1014 lto_output_ts_vec_tree_pointers (struct output_block
*ob
, tree expr
, bool ref_p
)
1018 /* Note that the number of slots for EXPR has already been emitted
1019 in EXPR's header (see lto_output_tree_header). */
1020 for (i
= 0; i
< TREE_VEC_LENGTH (expr
); i
++)
1021 lto_output_tree_or_ref (ob
, TREE_VEC_ELT (expr
, i
), ref_p
);
1025 /* Write all pointer fields in the TS_EXP structure of EXPR to output
1026 block OB. If REF_P is true, write a reference to EXPR's pointer
1030 lto_output_ts_exp_tree_pointers (struct output_block
*ob
, tree expr
, bool ref_p
)
1034 output_sleb128 (ob
, TREE_OPERAND_LENGTH (expr
));
1035 for (i
= 0; i
< TREE_OPERAND_LENGTH (expr
); i
++)
1036 lto_output_tree_or_ref (ob
, TREE_OPERAND (expr
, i
), ref_p
);
1037 lto_output_location (ob
, EXPR_LOCATION (expr
));
1038 lto_output_tree_or_ref (ob
, TREE_BLOCK (expr
), ref_p
);
1042 /* Write all pointer fields in the TS_BLOCK structure of EXPR to output
1043 block OB. If REF_P is true, write a reference to EXPR's pointer
1047 lto_output_ts_block_tree_pointers (struct output_block
*ob
, tree expr
,
1053 lto_output_location (ob
, BLOCK_SOURCE_LOCATION (expr
));
1054 lto_output_chain (ob
, BLOCK_VARS (expr
), ref_p
);
1056 output_uleb128 (ob
, VEC_length (tree
, BLOCK_NONLOCALIZED_VARS (expr
)));
1057 for (i
= 0; VEC_iterate (tree
, BLOCK_NONLOCALIZED_VARS (expr
), i
, t
); i
++)
1058 lto_output_tree_or_ref (ob
, t
, ref_p
);
1060 lto_output_tree_or_ref (ob
, BLOCK_SUPERCONTEXT (expr
), ref_p
);
1061 lto_output_tree_or_ref (ob
, BLOCK_ABSTRACT_ORIGIN (expr
), ref_p
);
1062 lto_output_tree_or_ref (ob
, BLOCK_FRAGMENT_ORIGIN (expr
), ref_p
);
1063 lto_output_tree_or_ref (ob
, BLOCK_FRAGMENT_CHAIN (expr
), ref_p
);
1064 lto_output_chain (ob
, BLOCK_SUBBLOCKS (expr
), ref_p
);
1068 /* Write all pointer fields in the TS_BINFO structure of EXPR to output
1069 block OB. If REF_P is true, write a reference to EXPR's pointer
1073 lto_output_ts_binfo_tree_pointers (struct output_block
*ob
, tree expr
,
1079 /* Note that the number of BINFO slots has already been emitted in
1080 EXPR's header (see lto_output_tree_header) because this length
1081 is needed to build the empty BINFO node on the reader side. */
1082 for (i
= 0; VEC_iterate (tree
, BINFO_BASE_BINFOS (expr
), i
, t
); i
++)
1083 lto_output_tree_or_ref (ob
, t
, ref_p
);
1086 lto_output_tree_or_ref (ob
, BINFO_OFFSET (expr
), ref_p
);
1087 lto_output_tree_or_ref (ob
, BINFO_VTABLE (expr
), ref_p
);
1088 lto_output_tree_or_ref (ob
, BINFO_VIRTUALS (expr
), ref_p
);
1089 lto_output_tree_or_ref (ob
, BINFO_VPTR_FIELD (expr
), ref_p
);
1091 output_uleb128 (ob
, VEC_length (tree
, BINFO_BASE_ACCESSES (expr
)));
1092 for (i
= 0; VEC_iterate (tree
, BINFO_BASE_ACCESSES (expr
), i
, t
); i
++)
1093 lto_output_tree_or_ref (ob
, t
, ref_p
);
1095 lto_output_tree_or_ref (ob
, BINFO_INHERITANCE_CHAIN (expr
), ref_p
);
1096 lto_output_tree_or_ref (ob
, BINFO_SUBVTT_INDEX (expr
), ref_p
);
1097 lto_output_tree_or_ref (ob
, BINFO_VPTR_INDEX (expr
), ref_p
);
1101 /* Write all pointer fields in the TS_CONSTRUCTOR structure of EXPR to
1102 output block OB. If REF_P is true, write a reference to EXPR's
1106 lto_output_ts_constructor_tree_pointers (struct output_block
*ob
, tree expr
,
1112 output_uleb128 (ob
, CONSTRUCTOR_NELTS (expr
));
1113 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (expr
), i
, index
, value
)
1115 lto_output_tree_or_ref (ob
, index
, ref_p
);
1116 lto_output_tree_or_ref (ob
, value
, ref_p
);
1121 /* Helper for lto_output_tree. Write all pointer fields in EXPR to output
1122 block OB. If REF_P is true, the leaves of EXPR are emitted as
1126 lto_output_tree_pointers (struct output_block
*ob
, tree expr
, bool ref_p
)
1128 enum tree_code code
;
1130 code
= TREE_CODE (expr
);
1132 if (CODE_CONTAINS_STRUCT (code
, TS_COMMON
))
1133 lto_output_ts_common_tree_pointers (ob
, expr
, ref_p
);
1135 if (CODE_CONTAINS_STRUCT (code
, TS_VECTOR
))
1136 lto_output_ts_vector_tree_pointers (ob
, expr
, ref_p
);
1138 if (CODE_CONTAINS_STRUCT (code
, TS_COMPLEX
))
1139 lto_output_ts_complex_tree_pointers (ob
, expr
, ref_p
);
1141 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_MINIMAL
))
1142 lto_output_ts_decl_minimal_tree_pointers (ob
, expr
, ref_p
);
1144 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
1145 lto_output_ts_decl_common_tree_pointers (ob
, expr
, ref_p
);
1147 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_NON_COMMON
))
1148 lto_output_ts_decl_non_common_tree_pointers (ob
, expr
, ref_p
);
1150 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
1151 lto_output_ts_decl_with_vis_tree_pointers (ob
, expr
, ref_p
);
1153 if (CODE_CONTAINS_STRUCT (code
, TS_FIELD_DECL
))
1154 lto_output_ts_field_decl_tree_pointers (ob
, expr
, ref_p
);
1156 if (CODE_CONTAINS_STRUCT (code
, TS_FUNCTION_DECL
))
1157 lto_output_ts_function_decl_tree_pointers (ob
, expr
, ref_p
);
1159 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE
))
1160 lto_output_ts_type_tree_pointers (ob
, expr
, ref_p
);
1162 if (CODE_CONTAINS_STRUCT (code
, TS_LIST
))
1163 lto_output_ts_list_tree_pointers (ob
, expr
, ref_p
);
1165 if (CODE_CONTAINS_STRUCT (code
, TS_VEC
))
1166 lto_output_ts_vec_tree_pointers (ob
, expr
, ref_p
);
1168 if (CODE_CONTAINS_STRUCT (code
, TS_EXP
))
1169 lto_output_ts_exp_tree_pointers (ob
, expr
, ref_p
);
1171 if (CODE_CONTAINS_STRUCT (code
, TS_SSA_NAME
))
1173 /* We only stream the version number of SSA names. */
1177 if (CODE_CONTAINS_STRUCT (code
, TS_BLOCK
))
1178 lto_output_ts_block_tree_pointers (ob
, expr
, ref_p
);
1180 if (CODE_CONTAINS_STRUCT (code
, TS_BINFO
))
1181 lto_output_ts_binfo_tree_pointers (ob
, expr
, ref_p
);
1183 if (CODE_CONTAINS_STRUCT (code
, TS_CONSTRUCTOR
))
1184 lto_output_ts_constructor_tree_pointers (ob
, expr
, ref_p
);
1186 if (CODE_CONTAINS_STRUCT (code
, TS_STATEMENT_LIST
))
1188 /* This should only appear in GENERIC. */
1192 if (CODE_CONTAINS_STRUCT (code
, TS_OMP_CLAUSE
))
1194 /* This should only appear in High GIMPLE. */
1198 if (CODE_CONTAINS_STRUCT (code
, TS_OPTIMIZATION
))
1199 sorry ("gimple bytecode streams do not support the optimization attribute");
1201 if (CODE_CONTAINS_STRUCT (code
, TS_TARGET_OPTION
))
1202 sorry ("gimple bytecode streams do not support the target attribute");
1206 /* Emit header information for tree EXPR to output block OB. The header
1207 contains everything needed to instantiate an empty skeleton for
1208 EXPR on the reading side. IX is the index into the streamer cache
1209 where EXPR is stored. REF_P is as in lto_output_tree. */
1212 lto_output_tree_header (struct output_block
*ob
, tree expr
, int ix
)
1215 enum tree_code code
;
1217 /* We should not see any non-GIMPLE tree nodes here. */
1218 code
= TREE_CODE (expr
);
1219 if (!lto_is_streamable (expr
))
1220 internal_error ("tree code %qs is not supported in gimple streams",
1221 tree_code_name
[code
]);
1223 /* The header of a tree node consists of its tag, the size of
1224 the node, and any other information needed to instantiate
1225 EXPR on the reading side (such as the number of slots in
1226 variable sized nodes). */
1227 tag
= lto_tree_code_to_tag (code
);
1228 output_record_start (ob
, tag
);
1229 output_sleb128 (ob
, ix
);
1231 /* The following will cause bootstrap miscomparisons. Enable with care. */
1232 #ifdef LTO_STREAMER_DEBUG
1233 /* This is used mainly for debugging purposes. When the reader
1234 and the writer do not agree on a streamed node, the pointer
1235 value for EXPR can be used to track down the differences in
1237 gcc_assert ((HOST_WIDEST_INT
) (intptr_t) expr
== (intptr_t) expr
);
1238 output_sleb128 (ob
, (HOST_WIDEST_INT
) (intptr_t) expr
);
1241 /* The text in strings and identifiers are completely emitted in
1243 if (CODE_CONTAINS_STRUCT (code
, TS_STRING
))
1244 output_string_cst (ob
, ob
->main_stream
, expr
);
1245 else if (CODE_CONTAINS_STRUCT (code
, TS_IDENTIFIER
))
1246 output_identifier (ob
, ob
->main_stream
, expr
);
1247 else if (CODE_CONTAINS_STRUCT (code
, TS_VEC
))
1248 output_sleb128 (ob
, TREE_VEC_LENGTH (expr
));
1249 else if (CODE_CONTAINS_STRUCT (code
, TS_BINFO
))
1250 output_uleb128 (ob
, BINFO_N_BASE_BINFOS (expr
));
1254 /* Write the code and class of builtin EXPR to output block OB. IX is
1255 the index into the streamer cache where EXPR is stored.*/
1258 lto_output_builtin_tree (struct output_block
*ob
, tree expr
, int ix
)
1260 gcc_assert (lto_stream_as_builtin_p (expr
));
1262 if (DECL_BUILT_IN_CLASS (expr
) == BUILT_IN_MD
1263 && !targetm
.builtin_decl
)
1264 sorry ("gimple bytecode streams do not support machine specific builtin "
1265 "functions on this target");
1267 output_record_start (ob
, LTO_builtin_decl
);
1268 output_uleb128 (ob
, DECL_BUILT_IN_CLASS (expr
));
1269 output_uleb128 (ob
, DECL_FUNCTION_CODE (expr
));
1270 output_sleb128 (ob
, ix
);
1272 if (DECL_ASSEMBLER_NAME_SET_P (expr
))
1274 /* When the assembler name of a builtin gets a user name,
1275 the new name is always prefixed with '*' by
1276 set_builtin_user_assembler_name. So, to prevent the
1277 reader side from adding a second '*', we omit it here. */
1278 const char *str
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (expr
));
1279 if (strlen (str
) > 1 && str
[0] == '*')
1280 output_string (ob
, ob
->main_stream
, &str
[1]);
1282 output_string (ob
, ob
->main_stream
, NULL
);
1285 output_string (ob
, ob
->main_stream
, NULL
);
1289 /* Write a physical representation of tree node EXPR to output block
1290 OB. If REF_P is true, the leaves of EXPR are emitted as references
1291 via lto_output_tree_ref. IX is the index into the streamer cache
1292 where EXPR is stored. */
1295 lto_write_tree (struct output_block
*ob
, tree expr
, bool ref_p
, int ix
)
1297 struct bitpack_d
*bp
;
1299 /* Write the header, containing everything needed to materialize
1300 EXPR on the reading side. */
1301 lto_output_tree_header (ob
, expr
, ix
);
1303 /* Pack all the non-pointer fields in EXPR into a bitpack and write
1304 the resulting bitpack. */
1305 bp
= pack_value_fields (expr
);
1306 lto_output_bitpack (ob
->main_stream
, bp
);
1307 bitpack_delete (bp
);
1309 /* Write all the pointer fields in EXPR. */
1310 lto_output_tree_pointers (ob
, expr
, ref_p
);
1312 /* Mark the end of EXPR. */
1317 /* Emit the integer constant CST to output block OB. If REF_P is true,
1318 CST's type will be emitted as a reference. */
1321 lto_output_integer_cst (struct output_block
*ob
, tree cst
, bool ref_p
)
1323 output_record_start (ob
, lto_tree_code_to_tag (INTEGER_CST
));
1324 lto_output_tree_or_ref (ob
, TREE_TYPE (cst
), ref_p
);
1325 lto_output_1_stream (ob
->main_stream
, TREE_OVERFLOW_P (cst
));
1326 output_uleb128 (ob
, TREE_INT_CST_LOW (cst
));
1327 output_uleb128 (ob
, TREE_INT_CST_HIGH (cst
));
1331 /* Emit the physical representation of tree node EXPR to output block
1332 OB. If REF_P is true, the leaves of EXPR are emitted as references
1333 via lto_output_tree_ref. */
1336 lto_output_tree (struct output_block
*ob
, tree expr
, bool ref_p
)
1342 if (expr
== NULL_TREE
)
1348 /* INTEGER_CST nodes are special because they need their original type
1349 to be materialized by the reader (to implement TYPE_CACHED_VALUES). */
1350 if (TREE_CODE (expr
) == INTEGER_CST
)
1352 lto_output_integer_cst (ob
, expr
, ref_p
);
1356 /* Determine the offset in the stream where EXPR will be written.
1357 This is used when emitting pickle references so the reader knows
1358 where to reconstruct the pickled object from. This allows
1359 circular and forward references within the same stream. */
1360 offset
= ob
->main_stream
->total_size
;
1362 existed_p
= lto_streamer_cache_insert (ob
->writer_cache
, expr
, &ix
, &offset
);
1365 /* If a node has already been streamed out, make sure that
1366 we don't write it more than once. Otherwise, the reader
1367 will instantiate two different nodes for the same object. */
1368 output_record_start (ob
, LTO_tree_pickle_reference
);
1369 output_sleb128 (ob
, ix
);
1370 output_uleb128 (ob
, lto_tree_code_to_tag (TREE_CODE (expr
)));
1371 output_uleb128 (ob
, offset
);
1373 else if (lto_stream_as_builtin_p (expr
))
1375 /* MD and NORMAL builtins do not need to be written out
1376 completely as they are always instantiated by the
1377 compiler on startup. The only builtins that need to
1378 be written out are BUILT_IN_FRONTEND. For all other
1379 builtins, we simply write the class and code. */
1380 lto_output_builtin_tree (ob
, expr
, ix
);
1384 /* This is the first time we see EXPR, write its fields
1386 lto_write_tree (ob
, expr
, ref_p
, ix
);
1391 /* Output to OB a list of try/catch handlers starting with FIRST. */
1394 output_eh_try_list (struct output_block
*ob
, eh_catch first
)
1398 for (n
= first
; n
; n
= n
->next_catch
)
1400 output_record_start (ob
, LTO_eh_catch
);
1401 lto_output_tree_ref (ob
, n
->type_list
);
1402 lto_output_tree_ref (ob
, n
->filter_list
);
1403 lto_output_tree_ref (ob
, n
->label
);
1410 /* Output EH region R in function FN to OB. CURR_RN is the slot index
1411 that is being emitted in FN->EH->REGION_ARRAY. This is used to
1412 detect EH region sharing. */
1415 output_eh_region (struct output_block
*ob
, eh_region r
)
1425 if (r
->type
== ERT_CLEANUP
)
1426 tag
= LTO_ert_cleanup
;
1427 else if (r
->type
== ERT_TRY
)
1429 else if (r
->type
== ERT_ALLOWED_EXCEPTIONS
)
1430 tag
= LTO_ert_allowed_exceptions
;
1431 else if (r
->type
== ERT_MUST_NOT_THROW
)
1432 tag
= LTO_ert_must_not_throw
;
1436 output_record_start (ob
, tag
);
1437 output_sleb128 (ob
, r
->index
);
1440 output_sleb128 (ob
, r
->outer
->index
);
1445 output_sleb128 (ob
, r
->inner
->index
);
1450 output_sleb128 (ob
, r
->next_peer
->index
);
1454 if (r
->type
== ERT_TRY
)
1456 output_eh_try_list (ob
, r
->u
.eh_try
.first_catch
);
1458 else if (r
->type
== ERT_ALLOWED_EXCEPTIONS
)
1460 lto_output_tree_ref (ob
, r
->u
.allowed
.type_list
);
1461 lto_output_tree_ref (ob
, r
->u
.allowed
.label
);
1462 output_uleb128 (ob
, r
->u
.allowed
.filter
);
1464 else if (r
->type
== ERT_MUST_NOT_THROW
)
1466 lto_output_tree_ref (ob
, r
->u
.must_not_throw
.failure_decl
);
1467 lto_output_location (ob
, r
->u
.must_not_throw
.failure_loc
);
1470 if (r
->landing_pads
)
1471 output_sleb128 (ob
, r
->landing_pads
->index
);
1477 /* Output landing pad LP to OB. */
1480 output_eh_lp (struct output_block
*ob
, eh_landing_pad lp
)
1488 output_record_start (ob
, LTO_eh_landing_pad
);
1489 output_sleb128 (ob
, lp
->index
);
1491 output_sleb128 (ob
, lp
->next_lp
->index
);
1496 output_sleb128 (ob
, lp
->region
->index
);
1500 lto_output_tree_ref (ob
, lp
->post_landing_pad
);
1504 /* Output the existing eh_table to OB. */
1507 output_eh_regions (struct output_block
*ob
, struct function
*fn
)
1509 if (fn
->eh
&& fn
->eh
->region_tree
)
1516 output_record_start (ob
, LTO_eh_table
);
1518 /* Emit the index of the root of the EH region tree. */
1519 output_sleb128 (ob
, fn
->eh
->region_tree
->index
);
1521 /* Emit all the EH regions in the region array. */
1522 output_sleb128 (ob
, VEC_length (eh_region
, fn
->eh
->region_array
));
1523 for (i
= 0; VEC_iterate (eh_region
, fn
->eh
->region_array
, i
, eh
); i
++)
1524 output_eh_region (ob
, eh
);
1526 /* Emit all landing pads. */
1527 output_sleb128 (ob
, VEC_length (eh_landing_pad
, fn
->eh
->lp_array
));
1528 for (i
= 0; VEC_iterate (eh_landing_pad
, fn
->eh
->lp_array
, i
, lp
); i
++)
1529 output_eh_lp (ob
, lp
);
1531 /* Emit all the runtime type data. */
1532 output_sleb128 (ob
, VEC_length (tree
, fn
->eh
->ttype_data
));
1533 for (i
= 0; VEC_iterate (tree
, fn
->eh
->ttype_data
, i
, ttype
); i
++)
1534 lto_output_tree_ref (ob
, ttype
);
1536 /* Emit the table of action chains. */
1537 if (targetm
.arm_eabi_unwinder
)
1540 output_sleb128 (ob
, VEC_length (tree
, fn
->eh
->ehspec_data
.arm_eabi
));
1542 VEC_iterate (tree
, fn
->eh
->ehspec_data
.arm_eabi
, i
, t
);
1544 lto_output_tree_ref (ob
, t
);
1549 output_sleb128 (ob
, VEC_length (uchar
, fn
->eh
->ehspec_data
.other
));
1550 for (i
= 0; VEC_iterate (uchar
, fn
->eh
->ehspec_data
.other
, i
, c
); i
++)
1551 lto_output_1_stream (ob
->main_stream
, c
);
1555 /* The 0 either terminates the record or indicates that there are no
1556 eh_records at all. */
1561 /* Output all of the active ssa names to the ssa_names stream. */
1564 output_ssa_names (struct output_block
*ob
, struct function
*fn
)
1566 unsigned int i
, len
;
1568 len
= VEC_length (tree
, SSANAMES (fn
));
1569 output_uleb128 (ob
, len
);
1571 for (i
= 1; i
< len
; i
++)
1573 tree ptr
= VEC_index (tree
, SSANAMES (fn
), i
);
1575 if (ptr
== NULL_TREE
1576 || SSA_NAME_IN_FREE_LIST (ptr
)
1577 || !is_gimple_reg (ptr
))
1580 output_uleb128 (ob
, i
);
1581 lto_output_1_stream (ob
->main_stream
, SSA_NAME_IS_DEFAULT_DEF (ptr
));
1582 lto_output_tree_ref (ob
, SSA_NAME_VAR (ptr
));
1589 /* Output the cfg. */
1592 output_cfg (struct output_block
*ob
, struct function
*fn
)
1594 struct lto_output_stream
*tmp_stream
= ob
->main_stream
;
1597 ob
->main_stream
= ob
->cfg_stream
;
1599 output_uleb128 (ob
, profile_status_for_function (fn
));
1601 /* Output the number of the highest basic block. */
1602 output_uleb128 (ob
, last_basic_block_for_function (fn
));
1604 FOR_ALL_BB_FN (bb
, fn
)
1609 output_sleb128 (ob
, bb
->index
);
1611 /* Output the successors and the edge flags. */
1612 output_uleb128 (ob
, EDGE_COUNT (bb
->succs
));
1613 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1615 output_uleb128 (ob
, e
->dest
->index
);
1616 output_sleb128 (ob
, e
->probability
);
1617 output_sleb128 (ob
, e
->count
);
1618 output_uleb128 (ob
, e
->flags
);
1622 output_sleb128 (ob
, -1);
1624 bb
= ENTRY_BLOCK_PTR
;
1627 output_sleb128 (ob
, bb
->next_bb
->index
);
1631 output_sleb128 (ob
, -1);
1633 ob
->main_stream
= tmp_stream
;
1637 /* Output PHI function PHI to the main stream in OB. */
1640 output_phi (struct output_block
*ob
, gimple phi
)
1642 unsigned i
, len
= gimple_phi_num_args (phi
);
1644 output_record_start (ob
, lto_gimple_code_to_tag (GIMPLE_PHI
));
1645 output_uleb128 (ob
, SSA_NAME_VERSION (PHI_RESULT (phi
)));
1647 for (i
= 0; i
< len
; i
++)
1649 lto_output_tree_ref (ob
, gimple_phi_arg_def (phi
, i
));
1650 output_uleb128 (ob
, gimple_phi_arg_edge (phi
, i
)->src
->index
);
1651 lto_output_location (ob
, gimple_phi_arg_location (phi
, i
));
1656 /* Emit statement STMT on the main stream of output block OB. */
1659 output_gimple_stmt (struct output_block
*ob
, gimple stmt
)
1662 enum gimple_code code
;
1664 struct bitpack_d
*bp
;
1666 /* Emit identifying tag. */
1667 code
= gimple_code (stmt
);
1668 tag
= lto_gimple_code_to_tag (code
);
1669 output_record_start (ob
, tag
);
1671 /* Emit the tuple header. */
1672 bp
= bitpack_create ();
1673 bp_pack_value (bp
, gimple_num_ops (stmt
), sizeof (unsigned) * 8);
1674 bp_pack_value (bp
, gimple_no_warning_p (stmt
), 1);
1675 if (is_gimple_assign (stmt
))
1676 bp_pack_value (bp
, gimple_assign_nontemporal_move_p (stmt
), 1);
1677 bp_pack_value (bp
, gimple_has_volatile_ops (stmt
), 1);
1678 bp_pack_value (bp
, stmt
->gsbase
.subcode
, 16);
1679 lto_output_bitpack (ob
->main_stream
, bp
);
1680 bitpack_delete (bp
);
1682 /* Emit location information for the statement. */
1683 lto_output_location (ob
, gimple_location (stmt
));
1685 /* Emit the lexical block holding STMT. */
1686 lto_output_tree (ob
, gimple_block (stmt
), true);
1688 /* Emit the operands. */
1689 switch (gimple_code (stmt
))
1692 output_sleb128 (ob
, gimple_resx_region (stmt
));
1695 case GIMPLE_EH_MUST_NOT_THROW
:
1696 lto_output_tree_ref (ob
, gimple_eh_must_not_throw_fndecl (stmt
));
1699 case GIMPLE_EH_DISPATCH
:
1700 output_sleb128 (ob
, gimple_eh_dispatch_region (stmt
));
1704 lto_output_uleb128_stream (ob
->main_stream
, gimple_asm_ninputs (stmt
));
1705 lto_output_uleb128_stream (ob
->main_stream
, gimple_asm_noutputs (stmt
));
1706 lto_output_uleb128_stream (ob
->main_stream
, gimple_asm_nclobbers (stmt
));
1707 lto_output_uleb128_stream (ob
->main_stream
, gimple_asm_nlabels (stmt
));
1708 output_string (ob
, ob
->main_stream
, gimple_asm_string (stmt
));
1719 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
1721 tree op
= gimple_op (stmt
, i
);
1722 lto_output_tree_ref (ob
, op
);
1727 case GIMPLE_PREDICT
:
1736 /* Output a basic block BB to the main stream in OB for this FN. */
1739 output_bb (struct output_block
*ob
, basic_block bb
, struct function
*fn
)
1741 gimple_stmt_iterator bsi
= gsi_start_bb (bb
);
1743 output_record_start (ob
,
1744 (!gsi_end_p (bsi
)) || phi_nodes (bb
)
1748 output_uleb128 (ob
, bb
->index
);
1749 output_sleb128 (ob
, bb
->count
);
1750 output_sleb128 (ob
, bb
->loop_depth
);
1751 output_sleb128 (ob
, bb
->frequency
);
1752 output_sleb128 (ob
, bb
->flags
);
1754 if (!gsi_end_p (bsi
) || phi_nodes (bb
))
1756 /* Output the statements. The list of statements is terminated
1758 for (bsi
= gsi_start_bb (bb
); !gsi_end_p (bsi
); gsi_next (&bsi
))
1761 gimple stmt
= gsi_stmt (bsi
);
1763 output_gimple_stmt (ob
, stmt
);
1765 /* Emit the EH region holding STMT. */
1766 region
= lookup_stmt_eh_lp_fn (fn
, stmt
);
1769 output_record_start (ob
, LTO_eh_region
);
1770 output_sleb128 (ob
, region
);
1778 for (bsi
= gsi_start_phis (bb
); !gsi_end_p (bsi
); gsi_next (&bsi
))
1780 gimple phi
= gsi_stmt (bsi
);
1782 /* Only emit PHIs for gimple registers. PHI nodes for .MEM
1783 will be filled in on reading when the SSA form is
1785 if (is_gimple_reg (gimple_phi_result (phi
)))
1786 output_phi (ob
, phi
);
1793 /* Create the header in the file using OB. If the section type is for
1794 a function, set FN to the decl for that function. */
1797 produce_asm (struct output_block
*ob
, tree fn
)
1799 enum lto_section_type section_type
= ob
->section_type
;
1800 struct lto_function_header header
;
1802 struct lto_output_stream
*header_stream
;
1804 if (section_type
== LTO_section_function_body
)
1806 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn
));
1807 section_name
= lto_get_section_name (section_type
, name
);
1810 section_name
= lto_get_section_name (section_type
, NULL
);
1812 lto_begin_section (section_name
, !flag_wpa
);
1813 free (section_name
);
1815 /* The entire header is stream computed here. */
1816 memset (&header
, 0, sizeof (struct lto_function_header
));
1818 /* Write the header. */
1819 header
.lto_header
.major_version
= LTO_major_version
;
1820 header
.lto_header
.minor_version
= LTO_minor_version
;
1821 header
.lto_header
.section_type
= section_type
;
1823 header
.compressed_size
= 0;
1825 if (section_type
== LTO_section_function_body
)
1826 header
.cfg_size
= ob
->cfg_stream
->total_size
;
1827 header
.main_size
= ob
->main_stream
->total_size
;
1828 header
.string_size
= ob
->string_stream
->total_size
;
1830 header_stream
= XCNEW (struct lto_output_stream
);
1831 lto_output_data_stream (header_stream
, &header
, sizeof header
);
1832 lto_write_stream (header_stream
);
1833 free (header_stream
);
1835 /* Put all of the gimple and the string table out the asm file as a
1837 if (section_type
== LTO_section_function_body
)
1838 lto_write_stream (ob
->cfg_stream
);
1839 lto_write_stream (ob
->main_stream
);
1840 lto_write_stream (ob
->string_stream
);
1846 /* Output the body of function NODE->DECL. */
1849 output_function (struct cgraph_node
*node
)
1851 struct bitpack_d
*bp
;
1853 struct function
*fn
;
1855 struct output_block
*ob
;
1857 function
= node
->decl
;
1858 fn
= DECL_STRUCT_FUNCTION (function
);
1859 ob
= create_output_block (LTO_section_function_body
);
1861 clear_line_info (ob
);
1862 ob
->cgraph_node
= node
;
1864 gcc_assert (current_function_decl
== NULL_TREE
&& cfun
== NULL
);
1866 /* Set current_function_decl and cfun. */
1867 current_function_decl
= function
;
1870 /* Make string 0 be a NULL string. */
1871 lto_output_1_stream (ob
->string_stream
, 0);
1873 output_record_start (ob
, LTO_function
);
1875 /* Write all the attributes for FN. */
1876 bp
= bitpack_create ();
1877 bp_pack_value (bp
, fn
->is_thunk
, 1);
1878 bp_pack_value (bp
, fn
->has_local_explicit_reg_vars
, 1);
1879 bp_pack_value (bp
, fn
->after_tree_profile
, 1);
1880 bp_pack_value (bp
, fn
->returns_pcc_struct
, 1);
1881 bp_pack_value (bp
, fn
->returns_struct
, 1);
1882 bp_pack_value (bp
, fn
->can_throw_non_call_exceptions
, 1);
1883 bp_pack_value (bp
, fn
->always_inline_functions_inlined
, 1);
1884 bp_pack_value (bp
, fn
->after_inlining
, 1);
1885 bp_pack_value (bp
, fn
->dont_save_pending_sizes_p
, 1);
1886 bp_pack_value (bp
, fn
->stdarg
, 1);
1887 bp_pack_value (bp
, fn
->has_nonlocal_label
, 1);
1888 bp_pack_value (bp
, fn
->calls_alloca
, 1);
1889 bp_pack_value (bp
, fn
->calls_setjmp
, 1);
1890 bp_pack_value (bp
, fn
->va_list_fpr_size
, 8);
1891 bp_pack_value (bp
, fn
->va_list_gpr_size
, 8);
1892 lto_output_bitpack (ob
->main_stream
, bp
);
1893 bitpack_delete (bp
);
1895 /* Output current IL state of the function. */
1896 output_uleb128 (ob
, fn
->curr_properties
);
1898 /* Output the static chain and non-local goto save area. */
1899 lto_output_tree_ref (ob
, fn
->static_chain_decl
);
1900 lto_output_tree_ref (ob
, fn
->nonlocal_goto_save_area
);
1902 /* Output all the local variables in the function. */
1903 lto_output_tree_ref (ob
, fn
->local_decls
);
1905 /* Output the head of the arguments list. */
1906 lto_output_tree_ref (ob
, DECL_ARGUMENTS (function
));
1908 /* Output all the SSA names used in the function. */
1909 output_ssa_names (ob
, fn
);
1911 /* Output any exception handling regions. */
1912 output_eh_regions (ob
, fn
);
1914 /* Output DECL_INITIAL for the function, which contains the tree of
1916 lto_output_tree (ob
, DECL_INITIAL (function
), true);
1918 /* We will renumber the statements. The code that does this uses
1919 the same ordering that we use for serializing them so we can use
1920 the same code on the other end and not have to write out the
1921 statement numbers. */
1922 renumber_gimple_stmt_uids ();
1924 /* Output the code for the function. */
1925 FOR_ALL_BB_FN (bb
, fn
)
1926 output_bb (ob
, bb
, fn
);
1928 /* The terminator for this function. */
1931 output_cfg (ob
, fn
);
1933 /* Create a section to hold the pickled output of this function. */
1934 produce_asm (ob
, function
);
1936 destroy_output_block (ob
);
1938 current_function_decl
= NULL
;
1943 /* Return true if alias pair P belongs to the set of cgraph nodes in
1944 SET. If P is a an alias for a VAR_DECL, it can always be emitted.
1945 However, for FUNCTION_DECL aliases, we should only output the pair
1946 if it belongs to a function whose cgraph node is in SET.
1947 Otherwise, the LTRANS phase will get into trouble when finalizing
1948 aliases because the alias will refer to a function not defined in
1949 the file processed by LTRANS. */
1952 output_alias_pair_p (alias_pair
*p
, cgraph_node_set set
, varpool_node_set vset
)
1954 if (TREE_CODE (p
->decl
) == VAR_DECL
)
1955 return varpool_node_in_set_p (varpool_node_for_asm (p
->target
), vset
);
1957 /* Check if the assembler name for P->TARGET has its cgraph node in SET. */
1958 gcc_assert (TREE_CODE (p
->decl
) == FUNCTION_DECL
);
1959 return cgraph_node_in_set_p (cgraph_node_for_asm (p
->target
), set
);
1963 /* Output any unreferenced global symbol defined in SET, alias pairs
1967 output_unreferenced_globals (cgraph_node_set set
, varpool_node_set vset
)
1969 struct output_block
*ob
;
1972 struct varpool_node
*vnode
;
1974 ob
= create_output_block (LTO_section_static_initializer
);
1975 ob
->cgraph_node
= NULL
;
1977 clear_line_info (ob
);
1979 /* Make string 0 be a NULL string. */
1980 lto_output_1_stream (ob
->string_stream
, 0);
1982 /* Emit references for all the global symbols. If a global symbol
1983 was never referenced in any of the functions of this file, it
1984 would not be emitted otherwise. This will result in unreferenced
1985 symbols at link time if a file defines a global symbol but
1986 never references it. */
1987 FOR_EACH_STATIC_VARIABLE (vnode
)
1988 if (vnode
->needed
&& varpool_node_in_set_p (vnode
, vset
))
1990 tree var
= vnode
->decl
;
1992 if (TREE_CODE (var
) == VAR_DECL
)
1994 /* Output the object in order to output references used in the
1996 lto_output_tree (ob
, var
, true);
1998 /* If it is public we also need a reference to the object itself. */
1999 if (TREE_PUBLIC (var
))
2000 lto_output_tree_ref (ob
, var
);
2006 /* Emit the alias pairs for the nodes in SET. */
2007 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
2009 if (output_alias_pair_p (p
, set
, vset
))
2011 lto_output_tree_ref (ob
, p
->decl
);
2012 lto_output_tree_ref (ob
, p
->target
);
2018 produce_asm (ob
, NULL
);
2019 destroy_output_block (ob
);
2023 /* Copy the function body of NODE without deserializing. */
2026 copy_function (struct cgraph_node
*node
)
2028 tree function
= node
->decl
;
2029 struct lto_file_decl_data
*file_data
= node
->local
.lto_file_data
;
2030 struct lto_output_stream
*output_stream
= XCNEW (struct lto_output_stream
);
2033 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function
));
2034 char *section_name
=
2035 lto_get_section_name (LTO_section_function_body
, name
);
2037 struct lto_in_decl_state
*in_state
;
2038 struct lto_out_decl_state
*out_state
= lto_get_out_decl_state ();
2040 lto_begin_section (section_name
, !flag_wpa
);
2041 free (section_name
);
2043 /* We may have renamed the declaration, e.g., a static function. */
2044 name
= lto_get_decl_name_mapping (file_data
, name
);
2046 data
= lto_get_section_data (file_data
, LTO_section_function_body
,
2050 /* Do a bit copy of the function body. */
2051 lto_output_data_stream (output_stream
, data
, len
);
2052 lto_write_stream (output_stream
);
2056 lto_get_function_in_decl_state (node
->local
.lto_file_data
, function
);
2057 gcc_assert (in_state
);
2059 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2061 size_t n
= in_state
->streams
[i
].size
;
2062 tree
*trees
= in_state
->streams
[i
].trees
;
2063 struct lto_tree_ref_encoder
*encoder
= &(out_state
->streams
[i
]);
2065 /* The out state must have the same indices and the in state.
2066 So just copy the vector. All the encoders in the in state
2067 must be empty where we reach here. */
2068 gcc_assert (lto_tree_ref_encoder_size (encoder
) == 0);
2069 for (j
= 0; j
< n
; j
++)
2070 VEC_safe_push (tree
, heap
, encoder
->trees
, trees
[j
]);
2071 encoder
->next_index
= n
;
2074 lto_free_section_data (file_data
, LTO_section_function_body
, name
,
2076 free (output_stream
);
2081 /* Initialize the LTO writer. */
2084 lto_writer_init (void)
2086 lto_streamer_init ();
2090 /* Main entry point from the pass manager. */
2093 lto_output (cgraph_node_set set
, varpool_node_set vset
)
2095 struct cgraph_node
*node
;
2096 struct lto_out_decl_state
*decl_state
;
2097 #ifdef ENABLE_CHECKING
2098 bitmap output
= lto_bitmap_alloc ();
2101 lto_cgraph_encoder_t encoder
= lto_get_out_decl_state ()->cgraph_node_encoder
;
2105 n_nodes
= lto_cgraph_encoder_size (encoder
);
2106 /* Process only the functions with bodies. */
2107 for (i
= 0; i
< n_nodes
; i
++)
2109 node
= lto_cgraph_encoder_deref (encoder
, i
);
2110 if (lto_cgraph_encoder_encode_body_p (encoder
, node
))
2112 #ifdef ENABLE_CHECKING
2113 gcc_assert (!bitmap_bit_p (output
, DECL_UID (node
->decl
)));
2114 bitmap_set_bit (output
, DECL_UID (node
->decl
));
2116 decl_state
= lto_new_out_decl_state ();
2117 lto_push_out_decl_state (decl_state
);
2119 output_function (node
);
2121 copy_function (node
);
2122 gcc_assert (lto_get_out_decl_state () == decl_state
);
2123 lto_pop_out_decl_state ();
2124 lto_record_function_out_decl_state (node
->decl
, decl_state
);
2128 /* Emit the callgraph after emitting function bodies. This needs to
2129 be done now to make sure that all the statements in every function
2130 have been renumbered so that edges can be associated with call
2131 statements using the statement UIDs. */
2132 output_cgraph (set
, vset
);
2134 #ifdef ENABLE_CHECKING
2135 lto_bitmap_free (output
);
2139 struct ipa_opt_pass_d pass_ipa_lto_gimple_out
=
2143 "lto_gimple_out", /* name */
2144 gate_lto_out
, /* gate */
2148 0, /* static_pass_number */
2149 TV_IPA_LTO_GIMPLE_IO
, /* tv_id */
2150 0, /* properties_required */
2151 0, /* properties_provided */
2152 0, /* properties_destroyed */
2153 0, /* todo_flags_start */
2154 TODO_dump_func
/* todo_flags_finish */
2156 NULL
, /* generate_summary */
2157 lto_output
, /* write_summary */
2158 NULL
, /* read_summary */
2159 lto_output
, /* write_optimization_summary */
2160 NULL
, /* read_optimization_summary */
2161 NULL
, /* stmt_fixup */
2163 NULL
, /* function_transform */
2164 NULL
/* variable_transform */
2168 /* Write each node in encoded by ENCODER to OB, as well as those reachable
2169 from it and required for correct representation of its semantics.
2170 Each node in ENCODER must be a global declaration or a type. A node
2171 is written only once, even if it appears multiple times in the
2172 vector. Certain transitively-reachable nodes, such as those
2173 representing expressions, may be duplicated, but such nodes
2174 must not appear in ENCODER itself. */
2177 write_global_stream (struct output_block
*ob
,
2178 struct lto_tree_ref_encoder
*encoder
)
2182 const size_t size
= lto_tree_ref_encoder_size (encoder
);
2184 for (index
= 0; index
< size
; index
++)
2186 t
= lto_tree_ref_encoder_get_tree (encoder
, index
);
2187 if (!lto_streamer_cache_lookup (ob
->writer_cache
, t
, NULL
))
2188 lto_output_tree (ob
, t
, false);
2193 /* Write a sequence of indices into the globals vector corresponding
2194 to the trees in ENCODER. These are used by the reader to map the
2195 indices used to refer to global entities within function bodies to
2199 write_global_references (struct output_block
*ob
,
2200 struct lto_output_stream
*ref_stream
,
2201 struct lto_tree_ref_encoder
*encoder
)
2205 const int32_t size
= lto_tree_ref_encoder_size (encoder
);
2207 /* Write size as 32-bit unsigned. */
2208 lto_output_data_stream (ref_stream
, &size
, sizeof (int32_t));
2210 for (index
= 0; index
< size
; index
++)
2214 t
= lto_tree_ref_encoder_get_tree (encoder
, index
);
2215 lto_streamer_cache_lookup (ob
->writer_cache
, t
, &slot_num
);
2216 gcc_assert (slot_num
>= 0);
2217 lto_output_data_stream (ref_stream
, &slot_num
, sizeof slot_num
);
2222 /* Write all the streams in an lto_out_decl_state STATE using
2223 output block OB and output stream OUT_STREAM. */
2226 lto_output_decl_state_streams (struct output_block
*ob
,
2227 struct lto_out_decl_state
*state
)
2231 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2232 write_global_stream (ob
, &state
->streams
[i
]);
2236 /* Write all the references in an lto_out_decl_state STATE using
2237 output block OB and output stream OUT_STREAM. */
2240 lto_output_decl_state_refs (struct output_block
*ob
,
2241 struct lto_output_stream
*out_stream
,
2242 struct lto_out_decl_state
*state
)
2248 /* Write reference to FUNCTION_DECL. If there is not function,
2249 write reference to void_type_node. */
2250 decl
= (state
->fn_decl
) ? state
->fn_decl
: void_type_node
;
2251 lto_streamer_cache_lookup (ob
->writer_cache
, decl
, &ref
);
2252 gcc_assert (ref
>= 0);
2253 lto_output_data_stream (out_stream
, &ref
, sizeof (int32_t));
2255 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2256 write_global_references (ob
, out_stream
, &state
->streams
[i
]);
2260 /* Return the written size of STATE. */
2263 lto_out_decl_state_written_size (struct lto_out_decl_state
*state
)
2268 size
= sizeof (int32_t); /* fn_ref. */
2269 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2271 size
+= sizeof (int32_t); /* vector size. */
2272 size
+= (lto_tree_ref_encoder_size (&state
->streams
[i
])
2273 * sizeof (int32_t));
2279 /* Helper function of write_symbols_of_kind. CACHE is the streamer
2280 cache with all the pickled nodes. STREAM is the stream where to
2281 write the table. V is a vector with the DECLs that should be on
2282 the table. SEEN is a bitmap of symbols written so far. */
2285 write_symbol_vec (struct lto_streamer_cache_d
*cache
,
2286 struct lto_output_stream
*stream
,
2287 VEC(tree
,heap
) *v
, bitmap seen
)
2292 for (index
= 0; VEC_iterate(tree
, v
, index
, t
); index
++)
2295 enum gcc_plugin_symbol_kind kind
;
2296 enum gcc_plugin_symbol_visibility visibility
;
2301 /* None of the following kinds of symbols are needed in the
2303 if (!TREE_PUBLIC (t
)
2304 || is_builtin_fn (t
)
2305 || DECL_ABSTRACT (t
)
2306 || TREE_CODE (t
) == RESULT_DECL
)
2309 gcc_assert (TREE_CODE (t
) == VAR_DECL
2310 || TREE_CODE (t
) == FUNCTION_DECL
);
2312 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t
));
2314 /* FIXME lto: this is from assemble_name_raw in varasm.c. For some
2315 architectures we might have to do the same name manipulations that
2316 ASM_OUTPUT_LABELREF does. */
2320 lto_streamer_cache_lookup (cache
, t
, &slot_num
);
2321 gcc_assert (slot_num
>= 0);
2323 /* Avoid duplicate symbols. */
2324 if (bitmap_bit_p (seen
, slot_num
))
2327 bitmap_set_bit (seen
, slot_num
);
2329 if (DECL_EXTERNAL (t
))
2332 kind
= GCCPK_WEAKUNDEF
;
2339 kind
= GCCPK_WEAKDEF
;
2340 else if (DECL_COMMON (t
))
2341 kind
= GCCPK_COMMON
;
2346 switch (DECL_VISIBILITY(t
))
2348 case VISIBILITY_DEFAULT
:
2349 visibility
= GCCPV_DEFAULT
;
2351 case VISIBILITY_PROTECTED
:
2352 visibility
= GCCPV_PROTECTED
;
2354 case VISIBILITY_HIDDEN
:
2355 visibility
= GCCPV_HIDDEN
;
2357 case VISIBILITY_INTERNAL
:
2358 visibility
= GCCPV_INTERNAL
;
2362 if (kind
== GCCPK_COMMON
2364 && TREE_CODE (DECL_SIZE (t
)) == INTEGER_CST
)
2365 size
= (((uint64_t) TREE_INT_CST_HIGH (DECL_SIZE (t
))) << 32)
2366 | TREE_INT_CST_LOW (DECL_SIZE (t
));
2370 if (DECL_ONE_ONLY (t
))
2371 comdat
= IDENTIFIER_POINTER (DECL_COMDAT_GROUP (t
));
2375 lto_output_data_stream (stream
, name
, strlen (name
) + 1);
2376 lto_output_data_stream (stream
, comdat
, strlen (comdat
) + 1);
2377 lto_output_data_stream (stream
, &kind
, 1);
2378 lto_output_data_stream (stream
, &visibility
, 1);
2379 lto_output_data_stream (stream
, &size
, 8);
2380 lto_output_data_stream (stream
, &slot_num
, 4);
2385 /* Write IL symbols of KIND. CACHE is the streamer cache with all the
2386 pickled nodes. SEEN is a bitmap of symbols written so far. */
2389 write_symbols_of_kind (lto_decl_stream_e_t kind
,
2390 struct lto_streamer_cache_d
*cache
, bitmap seen
)
2392 struct lto_out_decl_state
*out_state
;
2393 struct lto_output_stream stream
;
2395 VEC_length (lto_out_decl_state_ptr
, lto_function_decl_states
);
2398 memset (&stream
, 0, sizeof (stream
));
2399 out_state
= lto_get_out_decl_state ();
2400 write_symbol_vec (cache
, &stream
, out_state
->streams
[kind
].trees
, seen
);
2402 for (idx
= 0; idx
< num_fns
; idx
++)
2405 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
2406 write_symbol_vec (cache
, &stream
, out_state
->streams
[kind
].trees
, seen
);
2409 lto_write_stream (&stream
);
2413 /* Write an IL symbol table. CACHE is the streamer cache with all the
2417 produce_symtab (struct lto_streamer_cache_d
*cache
)
2419 char *section_name
= lto_get_section_name (LTO_section_symtab
, NULL
);
2422 lto_begin_section (section_name
, false);
2423 free (section_name
);
2425 seen
= lto_bitmap_alloc ();
2426 write_symbols_of_kind (LTO_DECL_STREAM_FN_DECL
, cache
, seen
);
2427 write_symbols_of_kind (LTO_DECL_STREAM_VAR_DECL
, cache
, seen
);
2428 lto_bitmap_free (seen
);
2434 /* This pass is run after all of the functions are serialized and all
2435 of the IPA passes have written their serialized forms. This pass
2436 causes the vector of all of the global decls and types used from
2437 this file to be written in to a section that can then be read in to
2438 recover these on other side. */
2441 produce_asm_for_decls (cgraph_node_set set
, varpool_node_set vset
)
2443 struct lto_out_decl_state
*out_state
;
2444 struct lto_out_decl_state
*fn_out_state
;
2445 struct lto_decl_header header
;
2447 struct output_block
*ob
;
2448 struct lto_output_stream
*header_stream
, *decl_state_stream
;
2449 unsigned idx
, num_fns
;
2450 size_t decl_state_size
;
2451 int32_t num_decl_states
;
2453 ob
= create_output_block (LTO_section_decls
);
2456 /* Write out unreferenced globals, alias pairs and labels. We defer
2457 doing this until now so that we can write out only what is
2459 output_unreferenced_globals (set
, vset
);
2461 memset (&header
, 0, sizeof (struct lto_decl_header
));
2463 section_name
= lto_get_section_name (LTO_section_decls
, NULL
);
2464 lto_begin_section (section_name
, !flag_wpa
);
2465 free (section_name
);
2467 /* Make string 0 be a NULL string. */
2468 lto_output_1_stream (ob
->string_stream
, 0);
2470 /* Write the global symbols. */
2471 out_state
= lto_get_out_decl_state ();
2472 num_fns
= VEC_length (lto_out_decl_state_ptr
, lto_function_decl_states
);
2473 lto_output_decl_state_streams (ob
, out_state
);
2474 for (idx
= 0; idx
< num_fns
; idx
++)
2477 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
2478 lto_output_decl_state_streams (ob
, fn_out_state
);
2481 header
.lto_header
.major_version
= LTO_major_version
;
2482 header
.lto_header
.minor_version
= LTO_minor_version
;
2483 header
.lto_header
.section_type
= LTO_section_decls
;
2485 /* Currently not used. This field would allow us to preallocate
2486 the globals vector, so that it need not be resized as it is extended. */
2487 header
.num_nodes
= -1;
2489 /* Compute the total size of all decl out states. */
2490 decl_state_size
= sizeof (int32_t);
2491 decl_state_size
+= lto_out_decl_state_written_size (out_state
);
2492 for (idx
= 0; idx
< num_fns
; idx
++)
2495 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
2496 decl_state_size
+= lto_out_decl_state_written_size (fn_out_state
);
2498 header
.decl_state_size
= decl_state_size
;
2500 header
.main_size
= ob
->main_stream
->total_size
;
2501 header
.string_size
= ob
->string_stream
->total_size
;
2503 header_stream
= XCNEW (struct lto_output_stream
);
2504 lto_output_data_stream (header_stream
, &header
, sizeof header
);
2505 lto_write_stream (header_stream
);
2506 free (header_stream
);
2508 /* Write the main out-decl state, followed by out-decl states of
2510 decl_state_stream
= ((struct lto_output_stream
*)
2511 xcalloc (1, sizeof (struct lto_output_stream
)));
2512 num_decl_states
= num_fns
+ 1;
2513 lto_output_data_stream (decl_state_stream
, &num_decl_states
,
2514 sizeof (num_decl_states
));
2515 lto_output_decl_state_refs (ob
, decl_state_stream
, out_state
);
2516 for (idx
= 0; idx
< num_fns
; idx
++)
2519 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
2520 lto_output_decl_state_refs (ob
, decl_state_stream
, fn_out_state
);
2522 lto_write_stream (decl_state_stream
);
2523 free(decl_state_stream
);
2525 lto_write_stream (ob
->main_stream
);
2526 lto_write_stream (ob
->string_stream
);
2530 /* Write the symbol table. */
2531 produce_symtab (ob
->writer_cache
);
2533 /* Write command line opts. */
2534 lto_write_options ();
2536 /* Deallocate memory and clean up. */
2537 for (idx
= 0; idx
< num_fns
; idx
++)
2540 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
2541 lto_delete_out_decl_state (fn_out_state
);
2543 lto_cgraph_encoder_delete (ob
->decl_state
->cgraph_node_encoder
);
2544 lto_varpool_encoder_delete (ob
->decl_state
->varpool_node_encoder
);
2545 VEC_free (lto_out_decl_state_ptr
, heap
, lto_function_decl_states
);
2546 lto_function_decl_states
= NULL
;
2547 destroy_output_block (ob
);
2551 struct ipa_opt_pass_d pass_ipa_lto_finish_out
=
2555 "lto_decls_out", /* name */
2556 gate_lto_out
, /* gate */
2560 0, /* static_pass_number */
2561 TV_IPA_LTO_DECL_IO
, /* tv_id */
2562 0, /* properties_required */
2563 0, /* properties_provided */
2564 0, /* properties_destroyed */
2565 0, /* todo_flags_start */
2566 0 /* todo_flags_finish */
2568 NULL
, /* generate_summary */
2569 produce_asm_for_decls
, /* write_summary */
2570 NULL
, /* read_summary */
2571 produce_asm_for_decls
, /* write_optimization_summary */
2572 NULL
, /* read_optimization_summary */
2573 NULL
, /* stmt_fixup */
2575 NULL
, /* function_transform */
2576 NULL
/* variable_transform */