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 STRING of LEN characters to the string
155 table in OB. The string might or might not include a trailing '\0'.
156 Then put the index onto the INDEX_STREAM. */
159 output_string_with_length (struct output_block
*ob
,
160 struct lto_output_stream
*index_stream
,
164 struct string_slot
**slot
;
165 struct string_slot s_slot
;
166 char *string
= (char *) xmalloc (len
+ 1);
167 memcpy (string
, s
, len
);
174 slot
= (struct string_slot
**) htab_find_slot (ob
->string_hash_table
,
178 struct lto_output_stream
*string_stream
= ob
->string_stream
;
179 unsigned int start
= string_stream
->total_size
;
180 struct string_slot
*new_slot
181 = (struct string_slot
*) xmalloc (sizeof (struct string_slot
));
184 new_slot
->s
= string
;
186 new_slot
->slot_num
= start
;
188 lto_output_uleb128_stream (index_stream
, start
);
189 lto_output_uleb128_stream (string_stream
, len
);
190 for (i
= 0; i
< len
; i
++)
191 lto_output_1_stream (string_stream
, string
[i
]);
195 struct string_slot
*old_slot
= (struct string_slot
*)*slot
;
196 lto_output_uleb128_stream (index_stream
, old_slot
->slot_num
);
201 /* Output the '\0' terminated STRING to the string
202 table in OB. Then put the index onto the INDEX_STREAM. */
205 output_string (struct output_block
*ob
,
206 struct lto_output_stream
*index_stream
,
211 lto_output_uleb128_stream (index_stream
, 0);
212 output_string_with_length (ob
, index_stream
, string
, strlen (string
) + 1);
215 lto_output_uleb128_stream (index_stream
, 1);
219 /* Output the STRING constant to the string
220 table in OB. Then put the index onto the INDEX_STREAM. */
223 output_string_cst (struct output_block
*ob
,
224 struct lto_output_stream
*index_stream
,
229 lto_output_uleb128_stream (index_stream
, 0);
230 output_string_with_length (ob
, index_stream
,
231 TREE_STRING_POINTER (string
),
232 TREE_STRING_LENGTH (string
));
235 lto_output_uleb128_stream (index_stream
, 1);
239 /* Output the identifier ID to the string
240 table in OB. Then put the index onto the INDEX_STREAM. */
243 output_identifier (struct output_block
*ob
,
244 struct lto_output_stream
*index_stream
,
249 lto_output_uleb128_stream (index_stream
, 0);
250 output_string_with_length (ob
, index_stream
,
251 IDENTIFIER_POINTER (id
),
252 IDENTIFIER_LENGTH (id
));
255 lto_output_uleb128_stream (index_stream
, 1);
258 /* Write a zero to the output stream. */
261 output_zero (struct output_block
*ob
)
263 lto_output_1_stream (ob
->main_stream
, 0);
267 /* Output an unsigned LEB128 quantity to OB->main_stream. */
270 output_uleb128 (struct output_block
*ob
, unsigned HOST_WIDE_INT work
)
272 lto_output_uleb128_stream (ob
->main_stream
, work
);
276 /* Output a signed LEB128 quantity to OB->main_stream. */
279 output_sleb128 (struct output_block
*ob
, HOST_WIDE_INT work
)
281 lto_output_sleb128_stream (ob
->main_stream
, work
);
285 /* Output the start of a record with TAG to output block OB. */
288 output_record_start (struct output_block
*ob
, enum LTO_tags tag
)
290 /* Make sure TAG fits inside an unsigned int. */
291 gcc_assert (tag
== (enum LTO_tags
) (unsigned) tag
);
292 output_uleb128 (ob
, tag
);
296 /* Look up NODE in the type table and write the index for it to OB. */
299 output_type_ref (struct output_block
*ob
, tree node
)
301 output_record_start (ob
, LTO_type_ref
);
302 lto_output_type_ref_index (ob
->decl_state
, ob
->main_stream
, node
);
306 /* Pack all the non-pointer fields of the TS_BASE structure of
307 expression EXPR into bitpack BP. */
310 pack_ts_base_value_fields (struct bitpack_d
*bp
, tree expr
)
312 bp_pack_value (bp
, TREE_CODE (expr
), 16);
315 bp_pack_value (bp
, TREE_SIDE_EFFECTS (expr
), 1);
316 bp_pack_value (bp
, TREE_CONSTANT (expr
), 1);
317 bp_pack_value (bp
, TREE_READONLY (expr
), 1);
319 /* TREE_PUBLIC is used on types to indicate that the type
320 has a TYPE_CACHED_VALUES vector. This is not streamed out,
321 so we skip it here. */
322 bp_pack_value (bp
, TREE_PUBLIC (expr
), 1);
325 bp_pack_value (bp
, 0, 4);
326 bp_pack_value (bp
, TREE_ADDRESSABLE (expr
), 1);
327 bp_pack_value (bp
, TREE_THIS_VOLATILE (expr
), 1);
329 bp_pack_value (bp
, DECL_UNSIGNED (expr
), 1);
330 else if (TYPE_P (expr
))
331 bp_pack_value (bp
, TYPE_UNSIGNED (expr
), 1);
333 bp_pack_value (bp
, 0, 1);
334 /* We write debug info two times, do not confuse the second one. */
335 bp_pack_value (bp
, TYPE_P (expr
) ? 0 : TREE_ASM_WRITTEN (expr
), 1);
336 bp_pack_value (bp
, TREE_NO_WARNING (expr
), 1);
337 bp_pack_value (bp
, TREE_USED (expr
), 1);
338 bp_pack_value (bp
, TREE_NOTHROW (expr
), 1);
339 bp_pack_value (bp
, TREE_STATIC (expr
), 1);
340 bp_pack_value (bp
, TREE_PRIVATE (expr
), 1);
341 bp_pack_value (bp
, TREE_PROTECTED (expr
), 1);
342 bp_pack_value (bp
, TREE_DEPRECATED (expr
), 1);
344 bp_pack_value (bp
, TYPE_SATURATING (expr
), 1);
345 else if (TREE_CODE (expr
) == SSA_NAME
)
346 bp_pack_value (bp
, SSA_NAME_IS_DEFAULT_DEF (expr
), 1);
348 bp_pack_value (bp
, 0, 1);
352 /* Pack all the non-pointer fields of the TS_REAL_CST structure of
353 expression EXPR into bitpack BP. */
356 pack_ts_real_cst_value_fields (struct bitpack_d
*bp
, tree expr
)
361 r
= TREE_REAL_CST (expr
);
362 bp_pack_value (bp
, r
.cl
, 2);
363 bp_pack_value (bp
, r
.decimal
, 1);
364 bp_pack_value (bp
, r
.sign
, 1);
365 bp_pack_value (bp
, r
.signalling
, 1);
366 bp_pack_value (bp
, r
.canonical
, 1);
367 bp_pack_value (bp
, r
.uexp
, EXP_BITS
);
368 for (i
= 0; i
< SIGSZ
; i
++)
369 bp_pack_value (bp
, r
.sig
[i
], HOST_BITS_PER_LONG
);
373 /* Pack all the non-pointer fields of the TS_FIXED_CST structure of
374 expression EXPR into bitpack BP. */
377 pack_ts_fixed_cst_value_fields (struct bitpack_d
*bp
, tree expr
)
379 struct fixed_value fv
= TREE_FIXED_CST (expr
);
380 bp_pack_value (bp
, fv
.data
.low
, HOST_BITS_PER_WIDE_INT
);
381 bp_pack_value (bp
, fv
.data
.high
, HOST_BITS_PER_WIDE_INT
);
382 bp_pack_value (bp
, fv
.mode
, HOST_BITS_PER_INT
);
386 /* Pack all the non-pointer fields of the TS_DECL_COMMON structure
387 of expression EXPR into bitpack BP. */
390 pack_ts_decl_common_value_fields (struct bitpack_d
*bp
, tree expr
)
392 bp_pack_value (bp
, DECL_MODE (expr
), 8);
393 bp_pack_value (bp
, DECL_NONLOCAL (expr
), 1);
394 bp_pack_value (bp
, DECL_VIRTUAL_P (expr
), 1);
395 bp_pack_value (bp
, DECL_IGNORED_P (expr
), 1);
396 bp_pack_value (bp
, DECL_ABSTRACT (expr
), 1);
397 bp_pack_value (bp
, DECL_ARTIFICIAL (expr
), 1);
398 bp_pack_value (bp
, DECL_USER_ALIGN (expr
), 1);
399 bp_pack_value (bp
, DECL_PRESERVE_P (expr
), 1);
400 bp_pack_value (bp
, DECL_DEBUG_EXPR_IS_FROM (expr
), 1);
401 bp_pack_value (bp
, DECL_EXTERNAL (expr
), 1);
402 bp_pack_value (bp
, DECL_GIMPLE_REG_P (expr
), 1);
403 bp_pack_value (bp
, DECL_ALIGN (expr
), HOST_BITS_PER_INT
);
405 if (TREE_CODE (expr
) == LABEL_DECL
)
407 /* Note that we do not write LABEL_DECL_UID. The reader will
408 always assume an initial value of -1 so that the
409 label_to_block_map is recreated by gimple_set_bb. */
410 bp_pack_value (bp
, DECL_ERROR_ISSUED (expr
), 1);
411 bp_pack_value (bp
, EH_LANDING_PAD_NR (expr
), HOST_BITS_PER_INT
);
414 if (TREE_CODE (expr
) == FIELD_DECL
)
416 bp_pack_value (bp
, DECL_PACKED (expr
), 1);
417 bp_pack_value (bp
, DECL_NONADDRESSABLE_P (expr
), 1);
418 bp_pack_value (bp
, DECL_OFFSET_ALIGN (expr
), 8);
421 if (TREE_CODE (expr
) == RESULT_DECL
422 || TREE_CODE (expr
) == PARM_DECL
423 || TREE_CODE (expr
) == VAR_DECL
)
425 bp_pack_value (bp
, DECL_BY_REFERENCE (expr
), 1);
426 if (TREE_CODE (expr
) == VAR_DECL
427 || TREE_CODE (expr
) == PARM_DECL
)
428 bp_pack_value (bp
, DECL_HAS_VALUE_EXPR_P (expr
), 1);
429 bp_pack_value (bp
, DECL_RESTRICTED_P (expr
), 1);
434 /* Pack all the non-pointer fields of the TS_DECL_WRTL structure
435 of expression EXPR into bitpack BP. */
438 pack_ts_decl_wrtl_value_fields (struct bitpack_d
*bp
, tree expr
)
440 bp_pack_value (bp
, DECL_REGISTER (expr
), 1);
444 /* Pack all the non-pointer fields of the TS_DECL_WITH_VIS structure
445 of expression EXPR into bitpack BP. */
448 pack_ts_decl_with_vis_value_fields (struct bitpack_d
*bp
, tree expr
)
450 bp_pack_value (bp
, DECL_DEFER_OUTPUT (expr
), 1);
451 bp_pack_value (bp
, DECL_COMMON (expr
), 1);
452 bp_pack_value (bp
, DECL_DLLIMPORT_P (expr
), 1);
453 bp_pack_value (bp
, DECL_WEAK (expr
), 1);
454 bp_pack_value (bp
, DECL_SEEN_IN_BIND_EXPR_P (expr
), 1);
455 bp_pack_value (bp
, DECL_COMDAT (expr
), 1);
456 bp_pack_value (bp
, DECL_VISIBILITY (expr
), 2);
457 bp_pack_value (bp
, DECL_VISIBILITY_SPECIFIED (expr
), 1);
459 if (TREE_CODE (expr
) == VAR_DECL
)
461 bp_pack_value (bp
, DECL_HARD_REGISTER (expr
), 1);
462 bp_pack_value (bp
, DECL_IN_TEXT_SECTION (expr
), 1);
463 bp_pack_value (bp
, DECL_IN_CONSTANT_POOL (expr
), 1);
464 bp_pack_value (bp
, DECL_TLS_MODEL (expr
), 3);
467 if (VAR_OR_FUNCTION_DECL_P (expr
))
468 bp_pack_value (bp
, DECL_INIT_PRIORITY (expr
), HOST_BITS_PER_SHORT
);
472 /* Pack all the non-pointer fields of the TS_FUNCTION_DECL structure
473 of expression EXPR into bitpack BP. */
476 pack_ts_function_decl_value_fields (struct bitpack_d
*bp
, tree expr
)
478 /* For normal/md builtins we only write the class and code, so they
479 should never be handled here. */
480 gcc_assert (!lto_stream_as_builtin_p (expr
));
482 bp_pack_value (bp
, DECL_FUNCTION_CODE (expr
), 11);
483 bp_pack_value (bp
, DECL_BUILT_IN_CLASS (expr
), 2);
484 bp_pack_value (bp
, DECL_STATIC_CONSTRUCTOR (expr
), 1);
485 bp_pack_value (bp
, DECL_STATIC_DESTRUCTOR (expr
), 1);
486 bp_pack_value (bp
, DECL_UNINLINABLE (expr
), 1);
487 bp_pack_value (bp
, DECL_POSSIBLY_INLINED (expr
), 1);
488 bp_pack_value (bp
, DECL_IS_NOVOPS (expr
), 1);
489 bp_pack_value (bp
, DECL_IS_RETURNS_TWICE (expr
), 1);
490 bp_pack_value (bp
, DECL_IS_MALLOC (expr
), 1);
491 bp_pack_value (bp
, DECL_IS_OPERATOR_NEW (expr
), 1);
492 bp_pack_value (bp
, DECL_DECLARED_INLINE_P (expr
), 1);
493 bp_pack_value (bp
, DECL_STATIC_CHAIN (expr
), 1);
494 bp_pack_value (bp
, DECL_NO_INLINE_WARNING_P (expr
), 1);
495 bp_pack_value (bp
, DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (expr
), 1);
496 bp_pack_value (bp
, DECL_NO_LIMIT_STACK (expr
), 1);
497 bp_pack_value (bp
, DECL_DISREGARD_INLINE_LIMITS (expr
), 1);
498 bp_pack_value (bp
, DECL_PURE_P (expr
), 1);
499 bp_pack_value (bp
, DECL_LOOPING_CONST_OR_PURE_P (expr
), 1);
503 /* Pack all the non-pointer fields of the TS_TYPE structure
504 of expression EXPR into bitpack BP. */
507 pack_ts_type_value_fields (struct bitpack_d
*bp
, tree expr
)
509 bp_pack_value (bp
, TYPE_PRECISION (expr
), 10);
510 bp_pack_value (bp
, TYPE_MODE (expr
), 8);
511 bp_pack_value (bp
, TYPE_STRING_FLAG (expr
), 1);
512 bp_pack_value (bp
, TYPE_NO_FORCE_BLK (expr
), 1);
513 bp_pack_value (bp
, TYPE_NEEDS_CONSTRUCTING (expr
), 1);
514 if (RECORD_OR_UNION_TYPE_P (expr
))
515 bp_pack_value (bp
, TYPE_TRANSPARENT_AGGR (expr
), 1);
516 bp_pack_value (bp
, TYPE_PACKED (expr
), 1);
517 bp_pack_value (bp
, TYPE_RESTRICT (expr
), 1);
518 bp_pack_value (bp
, TYPE_CONTAINS_PLACEHOLDER_INTERNAL (expr
), 2);
519 bp_pack_value (bp
, TYPE_USER_ALIGN (expr
), 1);
520 bp_pack_value (bp
, TYPE_READONLY (expr
), 1);
521 bp_pack_value (bp
, TYPE_ALIGN (expr
), HOST_BITS_PER_INT
);
522 bp_pack_value (bp
, TYPE_ALIAS_SET (expr
) == 0 ? 0 : -1, HOST_BITS_PER_INT
);
526 /* Pack all the non-pointer fields of the TS_BLOCK structure
527 of expression EXPR into bitpack BP. */
530 pack_ts_block_value_fields (struct bitpack_d
*bp
, tree expr
)
532 bp_pack_value (bp
, BLOCK_ABSTRACT (expr
), 1);
533 bp_pack_value (bp
, BLOCK_NUMBER (expr
), 31);
536 /* Pack all the non-pointer fields of the TS_TRANSLATION_UNIT_DECL structure
537 of expression EXPR into bitpack BP. */
540 pack_ts_translation_unit_decl_value_fields (struct bitpack_d
*bp ATTRIBUTE_UNUSED
, tree expr ATTRIBUTE_UNUSED
)
544 /* Pack all the non-pointer fields in EXPR into a bit pack. */
547 pack_value_fields (struct bitpack_d
*bp
, tree expr
)
551 code
= TREE_CODE (expr
);
553 /* Note that all these functions are highly sensitive to changes in
554 the types and sizes of each of the fields being packed. */
555 pack_ts_base_value_fields (bp
, expr
);
557 if (CODE_CONTAINS_STRUCT (code
, TS_REAL_CST
))
558 pack_ts_real_cst_value_fields (bp
, expr
);
560 if (CODE_CONTAINS_STRUCT (code
, TS_FIXED_CST
))
561 pack_ts_fixed_cst_value_fields (bp
, expr
);
563 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
564 pack_ts_decl_common_value_fields (bp
, expr
);
566 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WRTL
))
567 pack_ts_decl_wrtl_value_fields (bp
, expr
);
569 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
570 pack_ts_decl_with_vis_value_fields (bp
, expr
);
572 if (CODE_CONTAINS_STRUCT (code
, TS_FUNCTION_DECL
))
573 pack_ts_function_decl_value_fields (bp
, expr
);
575 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE
))
576 pack_ts_type_value_fields (bp
, expr
);
578 if (CODE_CONTAINS_STRUCT (code
, TS_BLOCK
))
579 pack_ts_block_value_fields (bp
, expr
);
581 if (CODE_CONTAINS_STRUCT (code
, TS_SSA_NAME
))
583 /* We only stream the version number of SSA names. */
587 if (CODE_CONTAINS_STRUCT (code
, TS_STATEMENT_LIST
))
589 /* This is only used by GENERIC. */
593 if (CODE_CONTAINS_STRUCT (code
, TS_OMP_CLAUSE
))
595 /* This is only used by High GIMPLE. */
599 if (CODE_CONTAINS_STRUCT (code
, TS_TRANSLATION_UNIT_DECL
))
600 pack_ts_translation_unit_decl_value_fields (bp
, expr
);
604 /* Emit location LOC to output block OB. */
607 lto_output_location (struct output_block
*ob
, location_t loc
)
609 expanded_location xloc
;
611 if (loc
== UNKNOWN_LOCATION
)
613 output_string (ob
, ob
->main_stream
, NULL
);
617 xloc
= expand_location (loc
);
619 output_string (ob
, ob
->main_stream
, xloc
.file
);
620 output_sleb128 (ob
, xloc
.line
);
621 output_sleb128 (ob
, xloc
.column
);
622 output_sleb128 (ob
, xloc
.sysp
);
624 ob
->current_file
= xloc
.file
;
625 ob
->current_line
= xloc
.line
;
626 ob
->current_col
= xloc
.column
;
630 /* Return true if tree node T is written to various tables. For these
631 nodes, we sometimes want to write their phyiscal representation
632 (via lto_output_tree), and sometimes we need to emit an index
633 reference into a table (via lto_output_tree_ref). */
636 tree_is_indexable (tree t
)
638 if (TREE_CODE (t
) == PARM_DECL
)
640 else if (TREE_CODE (t
) == VAR_DECL
&& decl_function_context (t
)
644 return (TYPE_P (t
) || DECL_P (t
) || TREE_CODE (t
) == SSA_NAME
);
648 /* If EXPR is an indexable tree node, output a reference to it to
649 output block OB. Otherwise, output the physical representation of
653 lto_output_tree_ref (struct output_block
*ob
, tree expr
)
657 if (expr
== NULL_TREE
)
663 if (!tree_is_indexable (expr
))
665 /* Even though we are emitting the physical representation of
666 EXPR, its leaves must be emitted as references. */
667 lto_output_tree (ob
, expr
, true);
673 output_type_ref (ob
, expr
);
677 code
= TREE_CODE (expr
);
681 output_record_start (ob
, LTO_ssa_name_ref
);
682 output_uleb128 (ob
, SSA_NAME_VERSION (expr
));
686 output_record_start (ob
, LTO_field_decl_ref
);
687 lto_output_field_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
691 output_record_start (ob
, LTO_function_decl_ref
);
692 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
696 case DEBUG_EXPR_DECL
:
697 gcc_assert (decl_function_context (expr
) == NULL
698 || TREE_STATIC (expr
));
699 output_record_start (ob
, LTO_global_decl_ref
);
700 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
704 output_record_start (ob
, LTO_const_decl_ref
);
705 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
709 gcc_assert (decl_function_context (expr
) == NULL
);
710 output_record_start (ob
, LTO_imported_decl_ref
);
711 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
715 output_record_start (ob
, LTO_type_decl_ref
);
716 lto_output_type_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
720 output_record_start (ob
, LTO_namespace_decl_ref
);
721 lto_output_namespace_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
725 output_record_start (ob
, LTO_label_decl_ref
);
726 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
730 output_record_start (ob
, LTO_result_decl_ref
);
731 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
734 case TRANSLATION_UNIT_DECL
:
735 output_record_start (ob
, LTO_translation_unit_decl_ref
);
736 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
740 /* No other node is indexable, so it should have been handled
741 by lto_output_tree. */
747 /* If REF_P is true, emit a reference to EXPR in output block OB,
748 otherwise emit the physical representation of EXPR in OB. */
751 lto_output_tree_or_ref (struct output_block
*ob
, tree expr
, bool ref_p
)
754 lto_output_tree_ref (ob
, expr
);
756 lto_output_tree (ob
, expr
, false);
760 /* Emit the chain of tree nodes starting at T. OB is the output block
761 to write to. REF_P is true if chain elements should be emitted
765 lto_output_chain (struct output_block
*ob
, tree t
, bool ref_p
)
769 count
= list_length (t
);
770 output_sleb128 (ob
, count
);
771 for (i
= 0; i
< count
; i
++)
775 /* Clear TREE_CHAIN to avoid blindly recursing into the rest
777 saved_chain
= TREE_CHAIN (t
);
778 TREE_CHAIN (t
) = NULL_TREE
;
780 lto_output_tree_or_ref (ob
, t
, ref_p
);
782 TREE_CHAIN (t
) = saved_chain
;
788 /* Write all pointer fields in the TS_COMMON structure of EXPR to output
789 block OB. If REF_P is true, write a reference to EXPR's pointer
793 lto_output_ts_common_tree_pointers (struct output_block
*ob
, tree expr
,
796 if (TREE_CODE (expr
) != IDENTIFIER_NODE
)
797 lto_output_tree_or_ref (ob
, TREE_TYPE (expr
), ref_p
);
801 /* Write all pointer fields in the TS_VECTOR structure of EXPR to output
802 block OB. If REF_P is true, write a reference to EXPR's pointer
806 lto_output_ts_vector_tree_pointers (struct output_block
*ob
, tree expr
,
809 lto_output_chain (ob
, TREE_VECTOR_CST_ELTS (expr
), ref_p
);
813 /* Write all pointer fields in the TS_COMPLEX structure of EXPR to output
814 block OB. If REF_P is true, write a reference to EXPR's pointer
818 lto_output_ts_complex_tree_pointers (struct output_block
*ob
, tree expr
,
821 lto_output_tree_or_ref (ob
, TREE_REALPART (expr
), ref_p
);
822 lto_output_tree_or_ref (ob
, TREE_IMAGPART (expr
), ref_p
);
826 /* Write all pointer fields in the TS_DECL_MINIMAL structure of EXPR
827 to output block OB. If REF_P is true, write a reference to EXPR's
831 lto_output_ts_decl_minimal_tree_pointers (struct output_block
*ob
, tree expr
,
834 lto_output_tree_or_ref (ob
, DECL_NAME (expr
), ref_p
);
835 lto_output_tree_or_ref (ob
, DECL_CONTEXT (expr
), ref_p
);
836 lto_output_location (ob
, DECL_SOURCE_LOCATION (expr
));
840 /* Write all pointer fields in the TS_DECL_COMMON structure of EXPR to
841 output block OB. If REF_P is true, write a reference to EXPR's
845 lto_output_ts_decl_common_tree_pointers (struct output_block
*ob
, tree expr
,
848 lto_output_tree_or_ref (ob
, DECL_SIZE (expr
), ref_p
);
849 lto_output_tree_or_ref (ob
, DECL_SIZE_UNIT (expr
), ref_p
);
851 if (TREE_CODE (expr
) != FUNCTION_DECL
)
853 tree initial
= DECL_INITIAL (expr
);
854 if (TREE_CODE (expr
) == VAR_DECL
855 && (TREE_STATIC (expr
) || DECL_EXTERNAL (expr
))
858 lto_varpool_encoder_t varpool_encoder
= ob
->decl_state
->varpool_node_encoder
;
859 struct varpool_node
*vnode
= varpool_get_node (expr
);
861 initial
= error_mark_node
;
862 else if (!lto_varpool_encoder_encode_initializer_p (varpool_encoder
,
867 lto_output_tree_or_ref (ob
, initial
, ref_p
);
870 lto_output_tree_or_ref (ob
, DECL_ATTRIBUTES (expr
), ref_p
);
871 lto_output_tree_or_ref (ob
, DECL_ABSTRACT_ORIGIN (expr
), ref_p
);
873 if (TREE_CODE (expr
) == PARM_DECL
)
874 lto_output_chain (ob
, TREE_CHAIN (expr
), ref_p
);
876 if ((TREE_CODE (expr
) == VAR_DECL
877 || TREE_CODE (expr
) == PARM_DECL
)
878 && DECL_HAS_VALUE_EXPR_P (expr
))
879 lto_output_tree_or_ref (ob
, DECL_VALUE_EXPR (expr
), ref_p
);
881 if (TREE_CODE (expr
) == VAR_DECL
)
882 lto_output_tree_or_ref (ob
, DECL_DEBUG_EXPR (expr
), ref_p
);
886 /* Write all pointer fields in the TS_DECL_NON_COMMON structure of
887 EXPR to output block OB. If REF_P is true, write a reference to EXPR's
891 lto_output_ts_decl_non_common_tree_pointers (struct output_block
*ob
,
892 tree expr
, bool ref_p
)
894 if (TREE_CODE (expr
) == FUNCTION_DECL
)
896 /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
897 At this point, it should not exist. Either because it was
898 converted to gimple or because DECL didn't have a GENERIC
899 representation in this TU. */
900 gcc_assert (DECL_SAVED_TREE (expr
) == NULL_TREE
);
901 lto_output_tree_or_ref (ob
, DECL_ARGUMENTS (expr
), ref_p
);
902 lto_output_tree_or_ref (ob
, DECL_RESULT (expr
), ref_p
);
904 lto_output_tree_or_ref (ob
, DECL_VINDEX (expr
), ref_p
);
908 /* Write all pointer fields in the TS_DECL_WITH_VIS structure of EXPR
909 to output block OB. If REF_P is true, write a reference to EXPR's
913 lto_output_ts_decl_with_vis_tree_pointers (struct output_block
*ob
, tree expr
,
916 /* Make sure we don't inadvertently set the assembler name. */
917 if (DECL_ASSEMBLER_NAME_SET_P (expr
))
918 lto_output_tree_or_ref (ob
, DECL_ASSEMBLER_NAME (expr
), ref_p
);
922 lto_output_tree_or_ref (ob
, DECL_SECTION_NAME (expr
), ref_p
);
923 lto_output_tree_or_ref (ob
, DECL_COMDAT_GROUP (expr
), ref_p
);
927 /* Write all pointer fields in the TS_FIELD_DECL structure of EXPR to
928 output block OB. If REF_P is true, write a reference to EXPR's
932 lto_output_ts_field_decl_tree_pointers (struct output_block
*ob
, tree expr
,
935 lto_output_tree_or_ref (ob
, DECL_FIELD_OFFSET (expr
), ref_p
);
936 lto_output_tree_or_ref (ob
, DECL_BIT_FIELD_TYPE (expr
), ref_p
);
937 lto_output_tree_or_ref (ob
, DECL_QUALIFIER (expr
), ref_p
);
938 lto_output_tree_or_ref (ob
, DECL_FIELD_BIT_OFFSET (expr
), ref_p
);
939 lto_output_tree_or_ref (ob
, DECL_FCONTEXT (expr
), ref_p
);
940 lto_output_chain (ob
, TREE_CHAIN (expr
), ref_p
);
944 /* Write all pointer fields in the TS_FUNCTION_DECL structure of EXPR
945 to output block OB. If REF_P is true, write a reference to EXPR's
949 lto_output_ts_function_decl_tree_pointers (struct output_block
*ob
, tree expr
,
952 /* DECL_STRUCT_FUNCTION is handled by lto_output_function. FIXME lto,
953 maybe it should be handled here? */
954 lto_output_tree_or_ref (ob
, DECL_FUNCTION_PERSONALITY (expr
), ref_p
);
955 lto_output_tree_or_ref (ob
, DECL_FUNCTION_SPECIFIC_TARGET (expr
), ref_p
);
956 lto_output_tree_or_ref (ob
, DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr
),
961 /* Write all pointer fields in the TS_TYPE structure of EXPR to output
962 block OB. If REF_P is true, write a reference to EXPR's pointer
966 lto_output_ts_type_tree_pointers (struct output_block
*ob
, tree expr
,
969 if (TREE_CODE (expr
) == ENUMERAL_TYPE
)
970 lto_output_tree_or_ref (ob
, TYPE_VALUES (expr
), ref_p
);
971 else if (TREE_CODE (expr
) == ARRAY_TYPE
)
972 lto_output_tree_or_ref (ob
, TYPE_DOMAIN (expr
), ref_p
);
973 else if (RECORD_OR_UNION_TYPE_P (expr
))
974 lto_output_tree_or_ref (ob
, TYPE_FIELDS (expr
), ref_p
);
975 else if (TREE_CODE (expr
) == FUNCTION_TYPE
976 || TREE_CODE (expr
) == METHOD_TYPE
)
977 lto_output_tree_or_ref (ob
, TYPE_ARG_TYPES (expr
), ref_p
);
979 lto_output_tree_or_ref (ob
, TYPE_SIZE (expr
), ref_p
);
980 lto_output_tree_or_ref (ob
, TYPE_SIZE_UNIT (expr
), ref_p
);
981 lto_output_tree_or_ref (ob
, TYPE_ATTRIBUTES (expr
), ref_p
);
982 lto_output_tree_or_ref (ob
, TYPE_NAME (expr
), ref_p
);
983 /* Do not stream TYPE_POINTER_TO or TYPE_REFERENCE_TO nor
984 TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. */
985 if (!POINTER_TYPE_P (expr
))
986 lto_output_tree_or_ref (ob
, TYPE_MINVAL (expr
), ref_p
);
987 lto_output_tree_or_ref (ob
, TYPE_MAXVAL (expr
), ref_p
);
988 lto_output_tree_or_ref (ob
, TYPE_MAIN_VARIANT (expr
), ref_p
);
989 /* Do not stream TYPE_NEXT_VARIANT, we reconstruct the variant lists
991 if (RECORD_OR_UNION_TYPE_P (expr
))
992 lto_output_tree_or_ref (ob
, TYPE_BINFO (expr
), ref_p
);
993 lto_output_tree_or_ref (ob
, TYPE_CONTEXT (expr
), ref_p
);
994 /* TYPE_CANONICAL is re-computed during type merging, so no need
995 to stream it here. */
996 lto_output_tree_or_ref (ob
, TYPE_STUB_DECL (expr
), ref_p
);
1000 /* Write all pointer fields in the TS_LIST structure of EXPR to output
1001 block OB. If REF_P is true, write a reference to EXPR's pointer
1005 lto_output_ts_list_tree_pointers (struct output_block
*ob
, tree expr
,
1008 lto_output_tree_or_ref (ob
, TREE_PURPOSE (expr
), ref_p
);
1009 lto_output_tree_or_ref (ob
, TREE_VALUE (expr
), ref_p
);
1010 lto_output_chain (ob
, TREE_CHAIN (expr
), ref_p
);
1014 /* Write all pointer fields in the TS_VEC structure of EXPR to output
1015 block OB. If REF_P is true, write a reference to EXPR's pointer
1019 lto_output_ts_vec_tree_pointers (struct output_block
*ob
, tree expr
, bool ref_p
)
1023 /* Note that the number of slots for EXPR has already been emitted
1024 in EXPR's header (see lto_output_tree_header). */
1025 for (i
= 0; i
< TREE_VEC_LENGTH (expr
); i
++)
1026 lto_output_tree_or_ref (ob
, TREE_VEC_ELT (expr
, i
), ref_p
);
1030 /* Write all pointer fields in the TS_EXP structure of EXPR to output
1031 block OB. If REF_P is true, write a reference to EXPR's pointer
1035 lto_output_ts_exp_tree_pointers (struct output_block
*ob
, tree expr
, bool ref_p
)
1039 output_sleb128 (ob
, TREE_OPERAND_LENGTH (expr
));
1040 for (i
= 0; i
< TREE_OPERAND_LENGTH (expr
); i
++)
1041 lto_output_tree_or_ref (ob
, TREE_OPERAND (expr
, i
), ref_p
);
1042 lto_output_location (ob
, EXPR_LOCATION (expr
));
1043 lto_output_tree_or_ref (ob
, TREE_BLOCK (expr
), ref_p
);
1047 /* Write all pointer fields in the TS_BLOCK structure of EXPR to output
1048 block OB. If REF_P is true, write a reference to EXPR's pointer
1052 lto_output_ts_block_tree_pointers (struct output_block
*ob
, tree expr
,
1058 lto_output_location (ob
, BLOCK_SOURCE_LOCATION (expr
));
1059 /* We do not stream BLOCK_VARS but lazily construct it when reading
1062 output_uleb128 (ob
, VEC_length (tree
, BLOCK_NONLOCALIZED_VARS (expr
)));
1063 FOR_EACH_VEC_ELT (tree
, BLOCK_NONLOCALIZED_VARS (expr
), i
, t
)
1065 gcc_assert (DECL_CONTEXT (t
) != expr
);
1066 lto_output_tree_or_ref (ob
, t
, ref_p
);
1069 lto_output_tree_or_ref (ob
, BLOCK_SUPERCONTEXT (expr
), ref_p
);
1070 lto_output_tree_or_ref (ob
, BLOCK_ABSTRACT_ORIGIN (expr
), ref_p
);
1071 lto_output_tree_or_ref (ob
, BLOCK_FRAGMENT_ORIGIN (expr
), ref_p
);
1072 lto_output_tree_or_ref (ob
, BLOCK_FRAGMENT_CHAIN (expr
), ref_p
);
1073 /* Do not output BLOCK_SUBBLOCKS. Instead on streaming-in this
1074 list is re-constructed from BLOCK_SUPERCONTEXT. */
1078 /* Write all pointer fields in the TS_BINFO structure of EXPR to output
1079 block OB. If REF_P is true, write a reference to EXPR's pointer
1083 lto_output_ts_binfo_tree_pointers (struct output_block
*ob
, tree expr
,
1089 /* Note that the number of BINFO slots has already been emitted in
1090 EXPR's header (see lto_output_tree_header) because this length
1091 is needed to build the empty BINFO node on the reader side. */
1092 FOR_EACH_VEC_ELT (tree
, BINFO_BASE_BINFOS (expr
), i
, t
)
1093 lto_output_tree_or_ref (ob
, t
, ref_p
);
1096 lto_output_tree_or_ref (ob
, BINFO_OFFSET (expr
), ref_p
);
1097 lto_output_tree_or_ref (ob
, BINFO_VTABLE (expr
), ref_p
);
1098 lto_output_tree_or_ref (ob
, BINFO_VIRTUALS (expr
), ref_p
);
1099 lto_output_tree_or_ref (ob
, BINFO_VPTR_FIELD (expr
), ref_p
);
1101 output_uleb128 (ob
, VEC_length (tree
, BINFO_BASE_ACCESSES (expr
)));
1102 FOR_EACH_VEC_ELT (tree
, BINFO_BASE_ACCESSES (expr
), i
, t
)
1103 lto_output_tree_or_ref (ob
, t
, ref_p
);
1105 lto_output_tree_or_ref (ob
, BINFO_INHERITANCE_CHAIN (expr
), ref_p
);
1106 lto_output_tree_or_ref (ob
, BINFO_SUBVTT_INDEX (expr
), ref_p
);
1107 lto_output_tree_or_ref (ob
, BINFO_VPTR_INDEX (expr
), ref_p
);
1111 /* Write all pointer fields in the TS_CONSTRUCTOR structure of EXPR to
1112 output block OB. If REF_P is true, write a reference to EXPR's
1116 lto_output_ts_constructor_tree_pointers (struct output_block
*ob
, tree expr
,
1122 output_uleb128 (ob
, CONSTRUCTOR_NELTS (expr
));
1123 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (expr
), i
, index
, value
)
1125 lto_output_tree_or_ref (ob
, index
, ref_p
);
1126 lto_output_tree_or_ref (ob
, value
, ref_p
);
1130 /* Write a TS_TARGET_OPTION tree in EXPR to OB. */
1133 lto_output_ts_target_option (struct output_block
*ob
, tree expr
)
1135 struct cl_target_option
*t
= TREE_TARGET_OPTION (expr
);
1136 struct bitpack_d bp
;
1139 /* The cl_target_option is target specific and generated by the options
1140 awk script, so we just recreate a byte-by-byte copy here. */
1142 bp
= bitpack_create (ob
->main_stream
);
1143 len
= sizeof (struct cl_target_option
);
1144 for (i
= 0; i
< len
; i
++)
1145 bp_pack_value (&bp
, ((unsigned char *)t
)[i
], 8);
1146 /* Catch struct size mismatches between reader and writer. */
1147 bp_pack_value (&bp
, 0x12345678, 32);
1148 lto_output_bitpack (&bp
);
1151 /* Write a TS_TRANSLATION_UNIT_DECL tree in EXPR to OB. */
1154 lto_output_ts_translation_unit_decl_tree_pointers (struct output_block
*ob
,
1157 output_string (ob
, ob
->main_stream
, TRANSLATION_UNIT_LANGUAGE (expr
));
1160 /* Helper for lto_output_tree. Write all pointer fields in EXPR to output
1161 block OB. If REF_P is true, the leaves of EXPR are emitted as
1165 lto_output_tree_pointers (struct output_block
*ob
, tree expr
, bool ref_p
)
1167 enum tree_code code
;
1169 code
= TREE_CODE (expr
);
1171 if (CODE_CONTAINS_STRUCT (code
, TS_COMMON
))
1172 lto_output_ts_common_tree_pointers (ob
, expr
, ref_p
);
1174 if (CODE_CONTAINS_STRUCT (code
, TS_VECTOR
))
1175 lto_output_ts_vector_tree_pointers (ob
, expr
, ref_p
);
1177 if (CODE_CONTAINS_STRUCT (code
, TS_COMPLEX
))
1178 lto_output_ts_complex_tree_pointers (ob
, expr
, ref_p
);
1180 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_MINIMAL
))
1181 lto_output_ts_decl_minimal_tree_pointers (ob
, expr
, ref_p
);
1183 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
1184 lto_output_ts_decl_common_tree_pointers (ob
, expr
, ref_p
);
1186 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_NON_COMMON
))
1187 lto_output_ts_decl_non_common_tree_pointers (ob
, expr
, ref_p
);
1189 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
1190 lto_output_ts_decl_with_vis_tree_pointers (ob
, expr
, ref_p
);
1192 if (CODE_CONTAINS_STRUCT (code
, TS_FIELD_DECL
))
1193 lto_output_ts_field_decl_tree_pointers (ob
, expr
, ref_p
);
1195 if (CODE_CONTAINS_STRUCT (code
, TS_FUNCTION_DECL
))
1196 lto_output_ts_function_decl_tree_pointers (ob
, expr
, ref_p
);
1198 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE
))
1199 lto_output_ts_type_tree_pointers (ob
, expr
, ref_p
);
1201 if (CODE_CONTAINS_STRUCT (code
, TS_LIST
))
1202 lto_output_ts_list_tree_pointers (ob
, expr
, ref_p
);
1204 if (CODE_CONTAINS_STRUCT (code
, TS_VEC
))
1205 lto_output_ts_vec_tree_pointers (ob
, expr
, ref_p
);
1207 if (CODE_CONTAINS_STRUCT (code
, TS_EXP
))
1208 lto_output_ts_exp_tree_pointers (ob
, expr
, ref_p
);
1210 if (CODE_CONTAINS_STRUCT (code
, TS_SSA_NAME
))
1212 /* We only stream the version number of SSA names. */
1216 if (CODE_CONTAINS_STRUCT (code
, TS_BLOCK
))
1217 lto_output_ts_block_tree_pointers (ob
, expr
, ref_p
);
1219 if (CODE_CONTAINS_STRUCT (code
, TS_BINFO
))
1220 lto_output_ts_binfo_tree_pointers (ob
, expr
, ref_p
);
1222 if (CODE_CONTAINS_STRUCT (code
, TS_CONSTRUCTOR
))
1223 lto_output_ts_constructor_tree_pointers (ob
, expr
, ref_p
);
1225 if (CODE_CONTAINS_STRUCT (code
, TS_STATEMENT_LIST
))
1227 /* This should only appear in GENERIC. */
1231 if (CODE_CONTAINS_STRUCT (code
, TS_OMP_CLAUSE
))
1233 /* This should only appear in High GIMPLE. */
1237 if (CODE_CONTAINS_STRUCT (code
, TS_OPTIMIZATION
))
1238 sorry ("gimple bytecode streams do not support the optimization attribute");
1240 if (CODE_CONTAINS_STRUCT (code
, TS_TARGET_OPTION
))
1241 lto_output_ts_target_option (ob
, expr
);
1243 if (CODE_CONTAINS_STRUCT (code
, TS_TRANSLATION_UNIT_DECL
))
1244 lto_output_ts_translation_unit_decl_tree_pointers (ob
, expr
);
1248 /* Emit header information for tree EXPR to output block OB. The header
1249 contains everything needed to instantiate an empty skeleton for
1250 EXPR on the reading side. IX is the index into the streamer cache
1251 where EXPR is stored. REF_P is as in lto_output_tree. */
1254 lto_output_tree_header (struct output_block
*ob
, tree expr
, int ix
)
1257 enum tree_code code
;
1259 /* We should not see any non-GIMPLE tree nodes here. */
1260 code
= TREE_CODE (expr
);
1261 if (!lto_is_streamable (expr
))
1262 internal_error ("tree code %qs is not supported in gimple streams",
1263 tree_code_name
[code
]);
1265 /* The header of a tree node consists of its tag, the size of
1266 the node, and any other information needed to instantiate
1267 EXPR on the reading side (such as the number of slots in
1268 variable sized nodes). */
1269 tag
= lto_tree_code_to_tag (code
);
1270 output_record_start (ob
, tag
);
1271 output_sleb128 (ob
, ix
);
1273 /* The following will cause bootstrap miscomparisons. Enable with care. */
1274 #ifdef LTO_STREAMER_DEBUG
1275 /* This is used mainly for debugging purposes. When the reader
1276 and the writer do not agree on a streamed node, the pointer
1277 value for EXPR can be used to track down the differences in
1279 gcc_assert ((HOST_WIDEST_INT
) (intptr_t) expr
== (intptr_t) expr
);
1280 output_sleb128 (ob
, (HOST_WIDEST_INT
) (intptr_t) expr
);
1283 /* The text in strings and identifiers are completely emitted in
1285 if (CODE_CONTAINS_STRUCT (code
, TS_STRING
))
1286 output_string_cst (ob
, ob
->main_stream
, expr
);
1287 else if (CODE_CONTAINS_STRUCT (code
, TS_IDENTIFIER
))
1288 output_identifier (ob
, ob
->main_stream
, expr
);
1289 else if (CODE_CONTAINS_STRUCT (code
, TS_VEC
))
1290 output_sleb128 (ob
, TREE_VEC_LENGTH (expr
));
1291 else if (CODE_CONTAINS_STRUCT (code
, TS_BINFO
))
1292 output_uleb128 (ob
, BINFO_N_BASE_BINFOS (expr
));
1296 /* Write the code and class of builtin EXPR to output block OB. IX is
1297 the index into the streamer cache where EXPR is stored.*/
1300 lto_output_builtin_tree (struct output_block
*ob
, tree expr
, int ix
)
1302 gcc_assert (lto_stream_as_builtin_p (expr
));
1304 if (DECL_BUILT_IN_CLASS (expr
) == BUILT_IN_MD
1305 && !targetm
.builtin_decl
)
1306 sorry ("gimple bytecode streams do not support machine specific builtin "
1307 "functions on this target");
1309 output_record_start (ob
, LTO_builtin_decl
);
1310 output_uleb128 (ob
, DECL_BUILT_IN_CLASS (expr
));
1311 output_uleb128 (ob
, DECL_FUNCTION_CODE (expr
));
1312 output_sleb128 (ob
, ix
);
1314 if (DECL_ASSEMBLER_NAME_SET_P (expr
))
1316 /* When the assembler name of a builtin gets a user name,
1317 the new name is always prefixed with '*' by
1318 set_builtin_user_assembler_name. So, to prevent the
1319 reader side from adding a second '*', we omit it here. */
1320 const char *str
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (expr
));
1321 if (strlen (str
) > 1 && str
[0] == '*')
1322 output_string (ob
, ob
->main_stream
, &str
[1]);
1324 output_string (ob
, ob
->main_stream
, NULL
);
1327 output_string (ob
, ob
->main_stream
, NULL
);
1331 /* Write a 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. IX is the index into the streamer cache
1334 where EXPR is stored. */
1337 lto_write_tree (struct output_block
*ob
, tree expr
, bool ref_p
, int ix
)
1339 struct bitpack_d bp
;
1341 /* Write the header, containing everything needed to materialize
1342 EXPR on the reading side. */
1343 lto_output_tree_header (ob
, expr
, ix
);
1345 /* Pack all the non-pointer fields in EXPR into a bitpack and write
1346 the resulting bitpack. */
1347 bp
= bitpack_create (ob
->main_stream
);
1348 pack_value_fields (&bp
, expr
);
1349 lto_output_bitpack (&bp
);
1351 /* Write all the pointer fields in EXPR. */
1352 lto_output_tree_pointers (ob
, expr
, ref_p
);
1354 /* Mark the end of EXPR. */
1359 /* Emit the integer constant CST to output block OB. If REF_P is true,
1360 CST's type will be emitted as a reference. */
1363 lto_output_integer_cst (struct output_block
*ob
, tree cst
, bool ref_p
)
1365 output_record_start (ob
, lto_tree_code_to_tag (INTEGER_CST
));
1366 lto_output_tree_or_ref (ob
, TREE_TYPE (cst
), ref_p
);
1367 lto_output_1_stream (ob
->main_stream
, TREE_OVERFLOW_P (cst
));
1368 output_uleb128 (ob
, TREE_INT_CST_LOW (cst
));
1369 output_uleb128 (ob
, TREE_INT_CST_HIGH (cst
));
1373 /* Emit the physical representation of tree node EXPR to output block
1374 OB. If REF_P is true, the leaves of EXPR are emitted as references
1375 via lto_output_tree_ref. */
1378 lto_output_tree (struct output_block
*ob
, tree expr
, bool ref_p
)
1384 if (expr
== NULL_TREE
)
1390 /* INTEGER_CST nodes are special because they need their original type
1391 to be materialized by the reader (to implement TYPE_CACHED_VALUES). */
1392 if (TREE_CODE (expr
) == INTEGER_CST
)
1394 lto_output_integer_cst (ob
, expr
, ref_p
);
1398 /* Determine the offset in the stream where EXPR will be written.
1399 This is used when emitting pickle references so the reader knows
1400 where to reconstruct the pickled object from. This allows
1401 circular and forward references within the same stream. */
1402 offset
= ob
->main_stream
->total_size
;
1404 existed_p
= lto_streamer_cache_insert (ob
->writer_cache
, expr
, &ix
, &offset
);
1407 /* If a node has already been streamed out, make sure that
1408 we don't write it more than once. Otherwise, the reader
1409 will instantiate two different nodes for the same object. */
1410 output_record_start (ob
, LTO_tree_pickle_reference
);
1411 output_sleb128 (ob
, ix
);
1412 output_uleb128 (ob
, lto_tree_code_to_tag (TREE_CODE (expr
)));
1413 output_uleb128 (ob
, offset
);
1415 else if (lto_stream_as_builtin_p (expr
))
1417 /* MD and NORMAL builtins do not need to be written out
1418 completely as they are always instantiated by the
1419 compiler on startup. The only builtins that need to
1420 be written out are BUILT_IN_FRONTEND. For all other
1421 builtins, we simply write the class and code. */
1422 lto_output_builtin_tree (ob
, expr
, ix
);
1426 /* This is the first time we see EXPR, write its fields
1428 lto_write_tree (ob
, expr
, ref_p
, ix
);
1433 /* Output to OB a list of try/catch handlers starting with FIRST. */
1436 output_eh_try_list (struct output_block
*ob
, eh_catch first
)
1440 for (n
= first
; n
; n
= n
->next_catch
)
1442 output_record_start (ob
, LTO_eh_catch
);
1443 lto_output_tree_ref (ob
, n
->type_list
);
1444 lto_output_tree_ref (ob
, n
->filter_list
);
1445 lto_output_tree_ref (ob
, n
->label
);
1452 /* Output EH region R in function FN to OB. CURR_RN is the slot index
1453 that is being emitted in FN->EH->REGION_ARRAY. This is used to
1454 detect EH region sharing. */
1457 output_eh_region (struct output_block
*ob
, eh_region r
)
1467 if (r
->type
== ERT_CLEANUP
)
1468 tag
= LTO_ert_cleanup
;
1469 else if (r
->type
== ERT_TRY
)
1471 else if (r
->type
== ERT_ALLOWED_EXCEPTIONS
)
1472 tag
= LTO_ert_allowed_exceptions
;
1473 else if (r
->type
== ERT_MUST_NOT_THROW
)
1474 tag
= LTO_ert_must_not_throw
;
1478 output_record_start (ob
, tag
);
1479 output_sleb128 (ob
, r
->index
);
1482 output_sleb128 (ob
, r
->outer
->index
);
1487 output_sleb128 (ob
, r
->inner
->index
);
1492 output_sleb128 (ob
, r
->next_peer
->index
);
1496 if (r
->type
== ERT_TRY
)
1498 output_eh_try_list (ob
, r
->u
.eh_try
.first_catch
);
1500 else if (r
->type
== ERT_ALLOWED_EXCEPTIONS
)
1502 lto_output_tree_ref (ob
, r
->u
.allowed
.type_list
);
1503 lto_output_tree_ref (ob
, r
->u
.allowed
.label
);
1504 output_uleb128 (ob
, r
->u
.allowed
.filter
);
1506 else if (r
->type
== ERT_MUST_NOT_THROW
)
1508 lto_output_tree_ref (ob
, r
->u
.must_not_throw
.failure_decl
);
1509 lto_output_location (ob
, r
->u
.must_not_throw
.failure_loc
);
1512 if (r
->landing_pads
)
1513 output_sleb128 (ob
, r
->landing_pads
->index
);
1519 /* Output landing pad LP to OB. */
1522 output_eh_lp (struct output_block
*ob
, eh_landing_pad lp
)
1530 output_record_start (ob
, LTO_eh_landing_pad
);
1531 output_sleb128 (ob
, lp
->index
);
1533 output_sleb128 (ob
, lp
->next_lp
->index
);
1538 output_sleb128 (ob
, lp
->region
->index
);
1542 lto_output_tree_ref (ob
, lp
->post_landing_pad
);
1546 /* Output the existing eh_table to OB. */
1549 output_eh_regions (struct output_block
*ob
, struct function
*fn
)
1551 if (fn
->eh
&& fn
->eh
->region_tree
)
1558 output_record_start (ob
, LTO_eh_table
);
1560 /* Emit the index of the root of the EH region tree. */
1561 output_sleb128 (ob
, fn
->eh
->region_tree
->index
);
1563 /* Emit all the EH regions in the region array. */
1564 output_sleb128 (ob
, VEC_length (eh_region
, fn
->eh
->region_array
));
1565 FOR_EACH_VEC_ELT (eh_region
, fn
->eh
->region_array
, i
, eh
)
1566 output_eh_region (ob
, eh
);
1568 /* Emit all landing pads. */
1569 output_sleb128 (ob
, VEC_length (eh_landing_pad
, fn
->eh
->lp_array
));
1570 FOR_EACH_VEC_ELT (eh_landing_pad
, fn
->eh
->lp_array
, i
, lp
)
1571 output_eh_lp (ob
, lp
);
1573 /* Emit all the runtime type data. */
1574 output_sleb128 (ob
, VEC_length (tree
, fn
->eh
->ttype_data
));
1575 FOR_EACH_VEC_ELT (tree
, fn
->eh
->ttype_data
, i
, ttype
)
1576 lto_output_tree_ref (ob
, ttype
);
1578 /* Emit the table of action chains. */
1579 if (targetm
.arm_eabi_unwinder
)
1582 output_sleb128 (ob
, VEC_length (tree
, fn
->eh
->ehspec_data
.arm_eabi
));
1583 FOR_EACH_VEC_ELT (tree
, fn
->eh
->ehspec_data
.arm_eabi
, i
, t
)
1584 lto_output_tree_ref (ob
, t
);
1589 output_sleb128 (ob
, VEC_length (uchar
, fn
->eh
->ehspec_data
.other
));
1590 FOR_EACH_VEC_ELT (uchar
, fn
->eh
->ehspec_data
.other
, i
, c
)
1591 lto_output_1_stream (ob
->main_stream
, c
);
1595 /* The 0 either terminates the record or indicates that there are no
1596 eh_records at all. */
1601 /* Output all of the active ssa names to the ssa_names stream. */
1604 output_ssa_names (struct output_block
*ob
, struct function
*fn
)
1606 unsigned int i
, len
;
1608 len
= VEC_length (tree
, SSANAMES (fn
));
1609 output_uleb128 (ob
, len
);
1611 for (i
= 1; i
< len
; i
++)
1613 tree ptr
= VEC_index (tree
, SSANAMES (fn
), i
);
1615 if (ptr
== NULL_TREE
1616 || SSA_NAME_IN_FREE_LIST (ptr
)
1617 || !is_gimple_reg (ptr
))
1620 output_uleb128 (ob
, i
);
1621 lto_output_1_stream (ob
->main_stream
, SSA_NAME_IS_DEFAULT_DEF (ptr
));
1622 lto_output_tree_ref (ob
, SSA_NAME_VAR (ptr
));
1629 /* Output the cfg. */
1632 output_cfg (struct output_block
*ob
, struct function
*fn
)
1634 struct lto_output_stream
*tmp_stream
= ob
->main_stream
;
1637 ob
->main_stream
= ob
->cfg_stream
;
1639 output_uleb128 (ob
, profile_status_for_function (fn
));
1641 /* Output the number of the highest basic block. */
1642 output_uleb128 (ob
, last_basic_block_for_function (fn
));
1644 FOR_ALL_BB_FN (bb
, fn
)
1649 output_sleb128 (ob
, bb
->index
);
1651 /* Output the successors and the edge flags. */
1652 output_uleb128 (ob
, EDGE_COUNT (bb
->succs
));
1653 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1655 output_uleb128 (ob
, e
->dest
->index
);
1656 output_sleb128 (ob
, e
->probability
);
1657 output_sleb128 (ob
, e
->count
);
1658 output_uleb128 (ob
, e
->flags
);
1662 output_sleb128 (ob
, -1);
1664 bb
= ENTRY_BLOCK_PTR
;
1667 output_sleb128 (ob
, bb
->next_bb
->index
);
1671 output_sleb128 (ob
, -1);
1673 ob
->main_stream
= tmp_stream
;
1677 /* Output PHI function PHI to the main stream in OB. */
1680 output_phi (struct output_block
*ob
, gimple phi
)
1682 unsigned i
, len
= gimple_phi_num_args (phi
);
1684 output_record_start (ob
, lto_gimple_code_to_tag (GIMPLE_PHI
));
1685 output_uleb128 (ob
, SSA_NAME_VERSION (PHI_RESULT (phi
)));
1687 for (i
= 0; i
< len
; i
++)
1689 lto_output_tree_ref (ob
, gimple_phi_arg_def (phi
, i
));
1690 output_uleb128 (ob
, gimple_phi_arg_edge (phi
, i
)->src
->index
);
1691 lto_output_location (ob
, gimple_phi_arg_location (phi
, i
));
1696 /* Emit statement STMT on the main stream of output block OB. */
1699 output_gimple_stmt (struct output_block
*ob
, gimple stmt
)
1702 enum gimple_code code
;
1704 struct bitpack_d bp
;
1706 /* Emit identifying tag. */
1707 code
= gimple_code (stmt
);
1708 tag
= lto_gimple_code_to_tag (code
);
1709 output_record_start (ob
, tag
);
1711 /* Emit the tuple header. */
1712 bp
= bitpack_create (ob
->main_stream
);
1713 bp_pack_value (&bp
, gimple_num_ops (stmt
), sizeof (unsigned) * 8);
1714 bp_pack_value (&bp
, gimple_no_warning_p (stmt
), 1);
1715 if (is_gimple_assign (stmt
))
1716 bp_pack_value (&bp
, gimple_assign_nontemporal_move_p (stmt
), 1);
1717 bp_pack_value (&bp
, gimple_has_volatile_ops (stmt
), 1);
1718 bp_pack_value (&bp
, stmt
->gsbase
.subcode
, 16);
1719 lto_output_bitpack (&bp
);
1721 /* Emit location information for the statement. */
1722 lto_output_location (ob
, gimple_location (stmt
));
1724 /* Emit the lexical block holding STMT. */
1725 lto_output_tree (ob
, gimple_block (stmt
), true);
1727 /* Emit the operands. */
1728 switch (gimple_code (stmt
))
1731 output_sleb128 (ob
, gimple_resx_region (stmt
));
1734 case GIMPLE_EH_MUST_NOT_THROW
:
1735 lto_output_tree_ref (ob
, gimple_eh_must_not_throw_fndecl (stmt
));
1738 case GIMPLE_EH_DISPATCH
:
1739 output_sleb128 (ob
, gimple_eh_dispatch_region (stmt
));
1743 lto_output_uleb128_stream (ob
->main_stream
, gimple_asm_ninputs (stmt
));
1744 lto_output_uleb128_stream (ob
->main_stream
, gimple_asm_noutputs (stmt
));
1745 lto_output_uleb128_stream (ob
->main_stream
, gimple_asm_nclobbers (stmt
));
1746 lto_output_uleb128_stream (ob
->main_stream
, gimple_asm_nlabels (stmt
));
1747 output_string (ob
, ob
->main_stream
, gimple_asm_string (stmt
));
1758 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
1760 tree op
= gimple_op (stmt
, i
);
1761 /* Wrap all uses of non-automatic variables inside MEM_REFs
1762 so that we do not have to deal with type mismatches on
1763 merged symbols during IL read in. */
1767 while (handled_component_p (*basep
))
1768 basep
= &TREE_OPERAND (*basep
, 0);
1769 if (TREE_CODE (*basep
) == VAR_DECL
1770 && !auto_var_in_fn_p (*basep
, current_function_decl
))
1772 bool volatilep
= TREE_THIS_VOLATILE (*basep
);
1773 *basep
= build2 (MEM_REF
, TREE_TYPE (*basep
),
1774 build_fold_addr_expr (*basep
),
1775 build_int_cst (build_pointer_type
1776 (TREE_TYPE (*basep
)), 0));
1777 TREE_THIS_VOLATILE (*basep
) = volatilep
;
1780 lto_output_tree_ref (ob
, op
);
1785 case GIMPLE_PREDICT
:
1794 /* Output a basic block BB to the main stream in OB for this FN. */
1797 output_bb (struct output_block
*ob
, basic_block bb
, struct function
*fn
)
1799 gimple_stmt_iterator bsi
= gsi_start_bb (bb
);
1801 output_record_start (ob
,
1802 (!gsi_end_p (bsi
)) || phi_nodes (bb
)
1806 output_uleb128 (ob
, bb
->index
);
1807 output_sleb128 (ob
, bb
->count
);
1808 output_sleb128 (ob
, bb
->loop_depth
);
1809 output_sleb128 (ob
, bb
->frequency
);
1810 output_sleb128 (ob
, bb
->flags
);
1812 if (!gsi_end_p (bsi
) || phi_nodes (bb
))
1814 /* Output the statements. The list of statements is terminated
1816 for (bsi
= gsi_start_bb (bb
); !gsi_end_p (bsi
); gsi_next (&bsi
))
1819 gimple stmt
= gsi_stmt (bsi
);
1821 output_gimple_stmt (ob
, stmt
);
1823 /* Emit the EH region holding STMT. */
1824 region
= lookup_stmt_eh_lp_fn (fn
, stmt
);
1827 output_record_start (ob
, LTO_eh_region
);
1828 output_sleb128 (ob
, region
);
1836 for (bsi
= gsi_start_phis (bb
); !gsi_end_p (bsi
); gsi_next (&bsi
))
1838 gimple phi
= gsi_stmt (bsi
);
1840 /* Only emit PHIs for gimple registers. PHI nodes for .MEM
1841 will be filled in on reading when the SSA form is
1843 if (is_gimple_reg (gimple_phi_result (phi
)))
1844 output_phi (ob
, phi
);
1851 /* Create the header in the file using OB. If the section type is for
1852 a function, set FN to the decl for that function. */
1855 produce_asm (struct output_block
*ob
, tree fn
)
1857 enum lto_section_type section_type
= ob
->section_type
;
1858 struct lto_function_header header
;
1860 struct lto_output_stream
*header_stream
;
1862 if (section_type
== LTO_section_function_body
)
1864 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn
));
1865 section_name
= lto_get_section_name (section_type
, name
, NULL
);
1868 section_name
= lto_get_section_name (section_type
, NULL
, NULL
);
1870 lto_begin_section (section_name
, !flag_wpa
);
1871 free (section_name
);
1873 /* The entire header is stream computed here. */
1874 memset (&header
, 0, sizeof (struct lto_function_header
));
1876 /* Write the header. */
1877 header
.lto_header
.major_version
= LTO_major_version
;
1878 header
.lto_header
.minor_version
= LTO_minor_version
;
1879 header
.lto_header
.section_type
= section_type
;
1881 header
.compressed_size
= 0;
1883 if (section_type
== LTO_section_function_body
)
1884 header
.cfg_size
= ob
->cfg_stream
->total_size
;
1885 header
.main_size
= ob
->main_stream
->total_size
;
1886 header
.string_size
= ob
->string_stream
->total_size
;
1888 header_stream
= XCNEW (struct lto_output_stream
);
1889 lto_output_data_stream (header_stream
, &header
, sizeof header
);
1890 lto_write_stream (header_stream
);
1891 free (header_stream
);
1893 /* Put all of the gimple and the string table out the asm file as a
1895 if (section_type
== LTO_section_function_body
)
1896 lto_write_stream (ob
->cfg_stream
);
1897 lto_write_stream (ob
->main_stream
);
1898 lto_write_stream (ob
->string_stream
);
1904 /* Output the body of function NODE->DECL. */
1907 output_function (struct cgraph_node
*node
)
1909 struct bitpack_d bp
;
1911 struct function
*fn
;
1913 struct output_block
*ob
;
1917 function
= node
->decl
;
1918 fn
= DECL_STRUCT_FUNCTION (function
);
1919 ob
= create_output_block (LTO_section_function_body
);
1921 clear_line_info (ob
);
1922 ob
->cgraph_node
= node
;
1924 gcc_assert (current_function_decl
== NULL_TREE
&& cfun
== NULL
);
1926 /* Set current_function_decl and cfun. */
1927 current_function_decl
= function
;
1930 /* Make string 0 be a NULL string. */
1931 lto_output_1_stream (ob
->string_stream
, 0);
1933 output_record_start (ob
, LTO_function
);
1935 /* Write all the attributes for FN. */
1936 bp
= bitpack_create (ob
->main_stream
);
1937 bp_pack_value (&bp
, fn
->is_thunk
, 1);
1938 bp_pack_value (&bp
, fn
->has_local_explicit_reg_vars
, 1);
1939 bp_pack_value (&bp
, fn
->after_tree_profile
, 1);
1940 bp_pack_value (&bp
, fn
->returns_pcc_struct
, 1);
1941 bp_pack_value (&bp
, fn
->returns_struct
, 1);
1942 bp_pack_value (&bp
, fn
->can_throw_non_call_exceptions
, 1);
1943 bp_pack_value (&bp
, fn
->always_inline_functions_inlined
, 1);
1944 bp_pack_value (&bp
, fn
->after_inlining
, 1);
1945 bp_pack_value (&bp
, fn
->dont_save_pending_sizes_p
, 1);
1946 bp_pack_value (&bp
, fn
->stdarg
, 1);
1947 bp_pack_value (&bp
, fn
->has_nonlocal_label
, 1);
1948 bp_pack_value (&bp
, fn
->calls_alloca
, 1);
1949 bp_pack_value (&bp
, fn
->calls_setjmp
, 1);
1950 bp_pack_value (&bp
, fn
->va_list_fpr_size
, 8);
1951 bp_pack_value (&bp
, fn
->va_list_gpr_size
, 8);
1952 lto_output_bitpack (&bp
);
1954 /* Output the function start and end loci. */
1955 lto_output_location (ob
, fn
->function_start_locus
);
1956 lto_output_location (ob
, fn
->function_end_locus
);
1958 /* Output current IL state of the function. */
1959 output_uleb128 (ob
, fn
->curr_properties
);
1961 /* Output the static chain and non-local goto save area. */
1962 lto_output_tree_ref (ob
, fn
->static_chain_decl
);
1963 lto_output_tree_ref (ob
, fn
->nonlocal_goto_save_area
);
1965 /* Output all the local variables in the function. */
1966 output_sleb128 (ob
, VEC_length (tree
, fn
->local_decls
));
1967 FOR_EACH_VEC_ELT (tree
, fn
->local_decls
, i
, t
)
1968 lto_output_tree_ref (ob
, t
);
1970 /* Output the head of the arguments list. */
1971 lto_output_tree_ref (ob
, DECL_ARGUMENTS (function
));
1973 /* Output all the SSA names used in the function. */
1974 output_ssa_names (ob
, fn
);
1976 /* Output any exception handling regions. */
1977 output_eh_regions (ob
, fn
);
1979 /* Output DECL_INITIAL for the function, which contains the tree of
1981 lto_output_tree (ob
, DECL_INITIAL (function
), true);
1983 /* We will renumber the statements. The code that does this uses
1984 the same ordering that we use for serializing them so we can use
1985 the same code on the other end and not have to write out the
1986 statement numbers. */
1987 renumber_gimple_stmt_uids ();
1989 /* Output the code for the function. */
1990 FOR_ALL_BB_FN (bb
, fn
)
1991 output_bb (ob
, bb
, fn
);
1993 /* The terminator for this function. */
1996 output_cfg (ob
, fn
);
1998 /* Create a section to hold the pickled output of this function. */
1999 produce_asm (ob
, function
);
2001 destroy_output_block (ob
);
2003 current_function_decl
= NULL
;
2008 /* Return true if alias pair P belongs to the set of cgraph nodes in
2009 SET. If P is a an alias for a VAR_DECL, it can always be emitted.
2010 However, for FUNCTION_DECL aliases, we should only output the pair
2011 if it belongs to a function whose cgraph node is in SET.
2012 Otherwise, the LTRANS phase will get into trouble when finalizing
2013 aliases because the alias will refer to a function not defined in
2014 the file processed by LTRANS. */
2017 output_alias_pair_p (alias_pair
*p
, cgraph_node_set set
, varpool_node_set vset
)
2019 if (TREE_CODE (p
->decl
) == VAR_DECL
)
2020 return varpool_node_in_set_p (varpool_node_for_asm (p
->target
), vset
);
2022 /* Check if the assembler name for P->TARGET has its cgraph node in SET. */
2023 gcc_assert (TREE_CODE (p
->decl
) == FUNCTION_DECL
);
2024 return cgraph_node_in_set_p (cgraph_node_for_asm (p
->target
), set
);
2028 /* Output any unreferenced global symbol defined in SET, alias pairs
2032 output_unreferenced_globals (cgraph_node_set set
, varpool_node_set vset
)
2034 struct output_block
*ob
;
2037 struct varpool_node
*vnode
;
2039 ob
= create_output_block (LTO_section_static_initializer
);
2040 ob
->cgraph_node
= NULL
;
2042 clear_line_info (ob
);
2044 /* Make string 0 be a NULL string. */
2045 lto_output_1_stream (ob
->string_stream
, 0);
2047 /* Emit references for all the global symbols. If a global symbol
2048 was never referenced in any of the functions of this file, it
2049 would not be emitted otherwise. This will result in unreferenced
2050 symbols at link time if a file defines a global symbol but
2051 never references it. */
2052 FOR_EACH_STATIC_VARIABLE (vnode
)
2053 if (vnode
->needed
&& varpool_node_in_set_p (vnode
, vset
))
2055 tree var
= vnode
->decl
;
2057 if (TREE_CODE (var
) == VAR_DECL
)
2059 /* Output the object in order to output references used in the
2061 lto_output_tree (ob
, var
, true);
2063 /* If it is public we also need a reference to the object itself. */
2064 if (TREE_PUBLIC (var
))
2065 lto_output_tree_ref (ob
, var
);
2071 /* Emit the alias pairs for the nodes in SET. */
2072 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
2074 if (output_alias_pair_p (p
, set
, vset
))
2076 lto_output_tree_ref (ob
, p
->decl
);
2077 lto_output_tree_ref (ob
, p
->target
);
2083 produce_asm (ob
, NULL
);
2084 destroy_output_block (ob
);
2088 /* Copy the function body of NODE without deserializing. */
2091 copy_function (struct cgraph_node
*node
)
2093 tree function
= node
->decl
;
2094 struct lto_file_decl_data
*file_data
= node
->local
.lto_file_data
;
2095 struct lto_output_stream
*output_stream
= XCNEW (struct lto_output_stream
);
2098 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function
));
2099 char *section_name
=
2100 lto_get_section_name (LTO_section_function_body
, name
, NULL
);
2102 struct lto_in_decl_state
*in_state
;
2103 struct lto_out_decl_state
*out_state
= lto_get_out_decl_state ();
2105 lto_begin_section (section_name
, !flag_wpa
);
2106 free (section_name
);
2108 /* We may have renamed the declaration, e.g., a static function. */
2109 name
= lto_get_decl_name_mapping (file_data
, name
);
2111 data
= lto_get_section_data (file_data
, LTO_section_function_body
,
2115 /* Do a bit copy of the function body. */
2116 lto_output_data_stream (output_stream
, data
, len
);
2117 lto_write_stream (output_stream
);
2121 lto_get_function_in_decl_state (node
->local
.lto_file_data
, function
);
2122 gcc_assert (in_state
);
2124 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2126 size_t n
= in_state
->streams
[i
].size
;
2127 tree
*trees
= in_state
->streams
[i
].trees
;
2128 struct lto_tree_ref_encoder
*encoder
= &(out_state
->streams
[i
]);
2130 /* The out state must have the same indices and the in state.
2131 So just copy the vector. All the encoders in the in state
2132 must be empty where we reach here. */
2133 gcc_assert (lto_tree_ref_encoder_size (encoder
) == 0);
2134 for (j
= 0; j
< n
; j
++)
2135 VEC_safe_push (tree
, heap
, encoder
->trees
, trees
[j
]);
2136 encoder
->next_index
= n
;
2139 lto_free_section_data (file_data
, LTO_section_function_body
, name
,
2141 free (output_stream
);
2146 /* Initialize the LTO writer. */
2149 lto_writer_init (void)
2151 lto_streamer_init ();
2155 /* Main entry point from the pass manager. */
2158 lto_output (cgraph_node_set set
, varpool_node_set vset
)
2160 struct cgraph_node
*node
;
2161 struct lto_out_decl_state
*decl_state
;
2162 #ifdef ENABLE_CHECKING
2163 bitmap output
= lto_bitmap_alloc ();
2166 lto_cgraph_encoder_t encoder
= lto_get_out_decl_state ()->cgraph_node_encoder
;
2170 n_nodes
= lto_cgraph_encoder_size (encoder
);
2171 /* Process only the functions with bodies. */
2172 for (i
= 0; i
< n_nodes
; i
++)
2174 node
= lto_cgraph_encoder_deref (encoder
, i
);
2175 if (lto_cgraph_encoder_encode_body_p (encoder
, node
))
2177 #ifdef ENABLE_CHECKING
2178 gcc_assert (!bitmap_bit_p (output
, DECL_UID (node
->decl
)));
2179 bitmap_set_bit (output
, DECL_UID (node
->decl
));
2181 decl_state
= lto_new_out_decl_state ();
2182 lto_push_out_decl_state (decl_state
);
2183 if (gimple_has_body_p (node
->decl
))
2184 output_function (node
);
2186 copy_function (node
);
2187 gcc_assert (lto_get_out_decl_state () == decl_state
);
2188 lto_pop_out_decl_state ();
2189 lto_record_function_out_decl_state (node
->decl
, decl_state
);
2193 /* Emit the callgraph after emitting function bodies. This needs to
2194 be done now to make sure that all the statements in every function
2195 have been renumbered so that edges can be associated with call
2196 statements using the statement UIDs. */
2197 output_cgraph (set
, vset
);
2199 #ifdef ENABLE_CHECKING
2200 lto_bitmap_free (output
);
2204 struct ipa_opt_pass_d pass_ipa_lto_gimple_out
=
2208 "lto_gimple_out", /* name */
2209 gate_lto_out
, /* gate */
2213 0, /* static_pass_number */
2214 TV_IPA_LTO_GIMPLE_OUT
, /* tv_id */
2215 0, /* properties_required */
2216 0, /* properties_provided */
2217 0, /* properties_destroyed */
2218 0, /* todo_flags_start */
2219 TODO_dump_func
/* todo_flags_finish */
2221 NULL
, /* generate_summary */
2222 lto_output
, /* write_summary */
2223 NULL
, /* read_summary */
2224 lto_output
, /* write_optimization_summary */
2225 NULL
, /* read_optimization_summary */
2226 NULL
, /* stmt_fixup */
2228 NULL
, /* function_transform */
2229 NULL
/* variable_transform */
2233 /* Write each node in encoded by ENCODER to OB, as well as those reachable
2234 from it and required for correct representation of its semantics.
2235 Each node in ENCODER must be a global declaration or a type. A node
2236 is written only once, even if it appears multiple times in the
2237 vector. Certain transitively-reachable nodes, such as those
2238 representing expressions, may be duplicated, but such nodes
2239 must not appear in ENCODER itself. */
2242 write_global_stream (struct output_block
*ob
,
2243 struct lto_tree_ref_encoder
*encoder
)
2247 const size_t size
= lto_tree_ref_encoder_size (encoder
);
2249 for (index
= 0; index
< size
; index
++)
2251 t
= lto_tree_ref_encoder_get_tree (encoder
, index
);
2252 if (!lto_streamer_cache_lookup (ob
->writer_cache
, t
, NULL
))
2253 lto_output_tree (ob
, t
, false);
2258 /* Write a sequence of indices into the globals vector corresponding
2259 to the trees in ENCODER. These are used by the reader to map the
2260 indices used to refer to global entities within function bodies to
2264 write_global_references (struct output_block
*ob
,
2265 struct lto_output_stream
*ref_stream
,
2266 struct lto_tree_ref_encoder
*encoder
)
2270 const int32_t size
= lto_tree_ref_encoder_size (encoder
);
2272 /* Write size as 32-bit unsigned. */
2273 lto_output_data_stream (ref_stream
, &size
, sizeof (int32_t));
2275 for (index
= 0; index
< size
; index
++)
2279 t
= lto_tree_ref_encoder_get_tree (encoder
, index
);
2280 lto_streamer_cache_lookup (ob
->writer_cache
, t
, &slot_num
);
2281 gcc_assert (slot_num
>= 0);
2282 lto_output_data_stream (ref_stream
, &slot_num
, sizeof slot_num
);
2287 /* Write all the streams in an lto_out_decl_state STATE using
2288 output block OB and output stream OUT_STREAM. */
2291 lto_output_decl_state_streams (struct output_block
*ob
,
2292 struct lto_out_decl_state
*state
)
2296 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2297 write_global_stream (ob
, &state
->streams
[i
]);
2301 /* Write all the references in an lto_out_decl_state STATE using
2302 output block OB and output stream OUT_STREAM. */
2305 lto_output_decl_state_refs (struct output_block
*ob
,
2306 struct lto_output_stream
*out_stream
,
2307 struct lto_out_decl_state
*state
)
2313 /* Write reference to FUNCTION_DECL. If there is not function,
2314 write reference to void_type_node. */
2315 decl
= (state
->fn_decl
) ? state
->fn_decl
: void_type_node
;
2316 lto_streamer_cache_lookup (ob
->writer_cache
, decl
, &ref
);
2317 gcc_assert (ref
>= 0);
2318 lto_output_data_stream (out_stream
, &ref
, sizeof (int32_t));
2320 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2321 write_global_references (ob
, out_stream
, &state
->streams
[i
]);
2325 /* Return the written size of STATE. */
2328 lto_out_decl_state_written_size (struct lto_out_decl_state
*state
)
2333 size
= sizeof (int32_t); /* fn_ref. */
2334 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2336 size
+= sizeof (int32_t); /* vector size. */
2337 size
+= (lto_tree_ref_encoder_size (&state
->streams
[i
])
2338 * sizeof (int32_t));
2344 /* Write symbol T into STREAM in CACHE. SEEN specifies symbols we wrote
2348 write_symbol (struct lto_streamer_cache_d
*cache
,
2349 struct lto_output_stream
*stream
,
2350 tree t
, struct pointer_set_t
*seen
, bool alias
)
2353 enum gcc_plugin_symbol_kind kind
;
2354 enum gcc_plugin_symbol_visibility visibility
;
2359 /* None of the following kinds of symbols are needed in the
2361 if (!TREE_PUBLIC (t
)
2362 || is_builtin_fn (t
)
2363 || DECL_ABSTRACT (t
)
2364 || TREE_CODE (t
) == RESULT_DECL
)
2367 gcc_assert (TREE_CODE (t
) == VAR_DECL
2368 || TREE_CODE (t
) == FUNCTION_DECL
);
2370 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t
));
2372 if (pointer_set_contains (seen
, name
))
2374 pointer_set_insert (seen
, name
);
2376 /* FIXME lto: this is from assemble_name_raw in varasm.c. For some
2377 architectures we might have to do the same name manipulations that
2378 ASM_OUTPUT_LABELREF does. */
2382 lto_streamer_cache_lookup (cache
, t
, &slot_num
);
2383 gcc_assert (slot_num
>= 0);
2385 if (DECL_EXTERNAL (t
))
2388 kind
= GCCPK_WEAKUNDEF
;
2395 kind
= GCCPK_WEAKDEF
;
2396 else if (DECL_COMMON (t
))
2397 kind
= GCCPK_COMMON
;
2401 /* When something is defined, it should have node attached. */
2402 gcc_assert (alias
|| TREE_CODE (t
) != VAR_DECL
2403 || varpool_get_node (t
)->finalized
);
2404 gcc_assert (alias
|| TREE_CODE (t
) != FUNCTION_DECL
2405 || (cgraph_get_node (t
)
2406 && cgraph_get_node (t
)->analyzed
));
2409 /* Imitate what default_elf_asm_output_external do.
2410 When symbol is external, we need to output it with DEFAULT visibility
2411 when compiling with -fvisibility=default, while with HIDDEN visibility
2412 when symbol has attribute (visibility("hidden")) specified.
2413 targetm.binds_local_p check DECL_VISIBILITY_SPECIFIED and gets this
2416 if (DECL_EXTERNAL (t
)
2417 && !targetm
.binds_local_p (t
))
2418 visibility
= GCCPV_DEFAULT
;
2420 switch (DECL_VISIBILITY(t
))
2422 case VISIBILITY_DEFAULT
:
2423 visibility
= GCCPV_DEFAULT
;
2425 case VISIBILITY_PROTECTED
:
2426 visibility
= GCCPV_PROTECTED
;
2428 case VISIBILITY_HIDDEN
:
2429 visibility
= GCCPV_HIDDEN
;
2431 case VISIBILITY_INTERNAL
:
2432 visibility
= GCCPV_INTERNAL
;
2436 if (kind
== GCCPK_COMMON
2438 && TREE_CODE (DECL_SIZE (t
)) == INTEGER_CST
)
2440 size
= (HOST_BITS_PER_WIDE_INT
>= 64)
2441 ? (uint64_t) int_size_in_bytes (TREE_TYPE (t
))
2442 : (((uint64_t) TREE_INT_CST_HIGH (DECL_SIZE_UNIT (t
))) << 32)
2443 | TREE_INT_CST_LOW (DECL_SIZE_UNIT (t
));
2448 if (DECL_ONE_ONLY (t
))
2449 comdat
= IDENTIFIER_POINTER (DECL_COMDAT_GROUP (t
));
2453 lto_output_data_stream (stream
, name
, strlen (name
) + 1);
2454 lto_output_data_stream (stream
, comdat
, strlen (comdat
) + 1);
2455 lto_output_data_stream (stream
, &kind
, 1);
2456 lto_output_data_stream (stream
, &visibility
, 1);
2457 lto_output_data_stream (stream
, &size
, 8);
2458 lto_output_data_stream (stream
, &slot_num
, 4);
2462 /* Write an IL symbol table to OB.
2463 SET and VSET are cgraph/varpool node sets we are outputting. */
2466 produce_symtab (struct output_block
*ob
,
2467 cgraph_node_set set
, varpool_node_set vset
)
2469 struct lto_streamer_cache_d
*cache
= ob
->writer_cache
;
2470 char *section_name
= lto_get_section_name (LTO_section_symtab
, NULL
, NULL
);
2471 struct pointer_set_t
*seen
;
2472 struct cgraph_node
*node
, *alias
;
2473 struct varpool_node
*vnode
, *valias
;
2474 struct lto_output_stream stream
;
2475 lto_varpool_encoder_t varpool_encoder
= ob
->decl_state
->varpool_node_encoder
;
2476 lto_cgraph_encoder_t encoder
= ob
->decl_state
->cgraph_node_encoder
;
2480 lto_begin_section (section_name
, false);
2481 free (section_name
);
2483 seen
= pointer_set_create ();
2484 memset (&stream
, 0, sizeof (stream
));
2486 /* Write all functions.
2487 First write all defined functions and the write all used functions.
2488 This is done so only to handle duplicated symbols in cgraph. */
2489 for (i
= 0; i
< lto_cgraph_encoder_size (encoder
); i
++)
2491 node
= lto_cgraph_encoder_deref (encoder
, i
);
2492 if (DECL_EXTERNAL (node
->decl
))
2494 if (DECL_COMDAT (node
->decl
)
2495 && cgraph_comdat_can_be_unshared_p (node
))
2497 if (node
->alias
|| node
->global
.inlined_to
)
2499 write_symbol (cache
, &stream
, node
->decl
, seen
, false);
2500 for (alias
= node
->same_body
; alias
; alias
= alias
->next
)
2501 write_symbol (cache
, &stream
, alias
->decl
, seen
, true);
2503 for (i
= 0; i
< lto_cgraph_encoder_size (encoder
); i
++)
2505 node
= lto_cgraph_encoder_deref (encoder
, i
);
2506 if (!DECL_EXTERNAL (node
->decl
))
2508 if (DECL_COMDAT (node
->decl
)
2509 && cgraph_comdat_can_be_unshared_p (node
))
2511 if (node
->alias
|| node
->global
.inlined_to
)
2513 write_symbol (cache
, &stream
, node
->decl
, seen
, false);
2514 for (alias
= node
->same_body
; alias
; alias
= alias
->next
)
2515 write_symbol (cache
, &stream
, alias
->decl
, seen
, true);
2518 /* Write all variables. */
2519 for (i
= 0; i
< lto_varpool_encoder_size (varpool_encoder
); i
++)
2521 vnode
= lto_varpool_encoder_deref (varpool_encoder
, i
);
2522 if (DECL_EXTERNAL (vnode
->decl
))
2524 /* COMDAT virtual tables can be unshared. Do not declare them
2525 in the LTO symbol table to prevent linker from forcing them
2527 if (DECL_COMDAT (vnode
->decl
)
2528 && !vnode
->force_output
2530 && DECL_VIRTUAL_P (vnode
->decl
))
2534 write_symbol (cache
, &stream
, vnode
->decl
, seen
, false);
2535 for (valias
= vnode
->extra_name
; valias
; valias
= valias
->next
)
2536 write_symbol (cache
, &stream
, valias
->decl
, seen
, true);
2538 for (i
= 0; i
< lto_varpool_encoder_size (varpool_encoder
); i
++)
2540 vnode
= lto_varpool_encoder_deref (varpool_encoder
, i
);
2541 if (!DECL_EXTERNAL (vnode
->decl
))
2543 if (DECL_COMDAT (vnode
->decl
)
2544 && !vnode
->force_output
2546 && DECL_VIRTUAL_P (vnode
->decl
))
2550 write_symbol (cache
, &stream
, vnode
->decl
, seen
, false);
2551 for (valias
= vnode
->extra_name
; valias
; valias
= valias
->next
)
2552 write_symbol (cache
, &stream
, valias
->decl
, seen
, true);
2555 /* Write all aliases. */
2556 FOR_EACH_VEC_ELT (alias_pair
, alias_pairs
, i
, p
)
2557 if (output_alias_pair_p (p
, set
, vset
))
2558 write_symbol (cache
, &stream
, p
->decl
, seen
, true);
2560 lto_write_stream (&stream
);
2561 pointer_set_destroy (seen
);
2567 /* This pass is run after all of the functions are serialized and all
2568 of the IPA passes have written their serialized forms. This pass
2569 causes the vector of all of the global decls and types used from
2570 this file to be written in to a section that can then be read in to
2571 recover these on other side. */
2574 produce_asm_for_decls (cgraph_node_set set
, varpool_node_set vset
)
2576 struct lto_out_decl_state
*out_state
;
2577 struct lto_out_decl_state
*fn_out_state
;
2578 struct lto_decl_header header
;
2580 struct output_block
*ob
;
2581 struct lto_output_stream
*header_stream
, *decl_state_stream
;
2582 unsigned idx
, num_fns
;
2583 size_t decl_state_size
;
2584 int32_t num_decl_states
;
2586 ob
= create_output_block (LTO_section_decls
);
2589 /* Write out unreferenced globals, alias pairs and labels. We defer
2590 doing this until now so that we can write out only what is
2592 output_unreferenced_globals (set
, vset
);
2594 memset (&header
, 0, sizeof (struct lto_decl_header
));
2596 section_name
= lto_get_section_name (LTO_section_decls
, NULL
, NULL
);
2597 lto_begin_section (section_name
, !flag_wpa
);
2598 free (section_name
);
2600 /* Make string 0 be a NULL string. */
2601 lto_output_1_stream (ob
->string_stream
, 0);
2603 /* Write the global symbols. */
2604 out_state
= lto_get_out_decl_state ();
2605 num_fns
= VEC_length (lto_out_decl_state_ptr
, lto_function_decl_states
);
2606 lto_output_decl_state_streams (ob
, out_state
);
2607 for (idx
= 0; idx
< num_fns
; idx
++)
2610 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
2611 lto_output_decl_state_streams (ob
, fn_out_state
);
2614 header
.lto_header
.major_version
= LTO_major_version
;
2615 header
.lto_header
.minor_version
= LTO_minor_version
;
2616 header
.lto_header
.section_type
= LTO_section_decls
;
2618 /* Currently not used. This field would allow us to preallocate
2619 the globals vector, so that it need not be resized as it is extended. */
2620 header
.num_nodes
= -1;
2622 /* Compute the total size of all decl out states. */
2623 decl_state_size
= sizeof (int32_t);
2624 decl_state_size
+= lto_out_decl_state_written_size (out_state
);
2625 for (idx
= 0; idx
< num_fns
; idx
++)
2628 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
2629 decl_state_size
+= lto_out_decl_state_written_size (fn_out_state
);
2631 header
.decl_state_size
= decl_state_size
;
2633 header
.main_size
= ob
->main_stream
->total_size
;
2634 header
.string_size
= ob
->string_stream
->total_size
;
2636 header_stream
= XCNEW (struct lto_output_stream
);
2637 lto_output_data_stream (header_stream
, &header
, sizeof header
);
2638 lto_write_stream (header_stream
);
2639 free (header_stream
);
2641 /* Write the main out-decl state, followed by out-decl states of
2643 decl_state_stream
= ((struct lto_output_stream
*)
2644 xcalloc (1, sizeof (struct lto_output_stream
)));
2645 num_decl_states
= num_fns
+ 1;
2646 lto_output_data_stream (decl_state_stream
, &num_decl_states
,
2647 sizeof (num_decl_states
));
2648 lto_output_decl_state_refs (ob
, decl_state_stream
, out_state
);
2649 for (idx
= 0; idx
< num_fns
; idx
++)
2652 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
2653 lto_output_decl_state_refs (ob
, decl_state_stream
, fn_out_state
);
2655 lto_write_stream (decl_state_stream
);
2656 free(decl_state_stream
);
2658 lto_write_stream (ob
->main_stream
);
2659 lto_write_stream (ob
->string_stream
);
2663 /* Write the symbol table. It is used by linker to determine dependencies
2664 and thus we can skip it for WPA. */
2666 produce_symtab (ob
, set
, vset
);
2668 /* Write command line opts. */
2669 lto_write_options ();
2671 /* Deallocate memory and clean up. */
2672 for (idx
= 0; idx
< num_fns
; idx
++)
2675 VEC_index (lto_out_decl_state_ptr
, lto_function_decl_states
, idx
);
2676 lto_delete_out_decl_state (fn_out_state
);
2678 lto_cgraph_encoder_delete (ob
->decl_state
->cgraph_node_encoder
);
2679 lto_varpool_encoder_delete (ob
->decl_state
->varpool_node_encoder
);
2680 VEC_free (lto_out_decl_state_ptr
, heap
, lto_function_decl_states
);
2681 lto_function_decl_states
= NULL
;
2682 destroy_output_block (ob
);
2686 struct ipa_opt_pass_d pass_ipa_lto_finish_out
=
2690 "lto_decls_out", /* name */
2691 gate_lto_out
, /* gate */
2695 0, /* static_pass_number */
2696 TV_IPA_LTO_DECL_OUT
, /* tv_id */
2697 0, /* properties_required */
2698 0, /* properties_provided */
2699 0, /* properties_destroyed */
2700 0, /* todo_flags_start */
2701 0 /* todo_flags_finish */
2703 NULL
, /* generate_summary */
2704 produce_asm_for_decls
, /* write_summary */
2705 NULL
, /* read_summary */
2706 produce_asm_for_decls
, /* write_optimization_summary */
2707 NULL
, /* read_optimization_summary */
2708 NULL
, /* stmt_fixup */
2710 NULL
, /* function_transform */
2711 NULL
/* variable_transform */