1 /* Write the GIMPLE representation to a file stream.
3 Copyright (C) 2009-2015 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"
31 #include "fold-const.h"
32 #include "stor-layout.h"
33 #include "stringpool.h"
34 #include "hard-reg-set.h"
38 #include "insn-config.h"
49 #include "dominance.h"
51 #include "basic-block.h"
52 #include "tree-ssa-alias.h"
53 #include "internal-fn.h"
54 #include "gimple-expr.h"
57 #include "gimple-iterator.h"
58 #include "gimple-ssa.h"
59 #include "tree-ssanames.h"
60 #include "tree-pass.h"
61 #include "diagnostic-core.h"
63 #include "lto-symtab.h"
64 #include "plugin-api.h"
67 #include "lto-streamer.h"
68 #include "data-streamer.h"
69 #include "gimple-streamer.h"
70 #include "tree-streamer.h"
71 #include "streamer-hooks.h"
74 #include "gomp-constants.h"
77 static void lto_write_tree (struct output_block
*, tree
, bool);
79 /* Clear the line info stored in DATA_IN. */
82 clear_line_info (struct output_block
*ob
)
84 ob
->current_file
= NULL
;
90 /* Create the output block and return it. SECTION_TYPE is
91 LTO_section_function_body or LTO_static_initializer. */
94 create_output_block (enum lto_section_type section_type
)
96 struct output_block
*ob
= XCNEW (struct output_block
);
98 ob
->section_type
= section_type
;
99 ob
->decl_state
= lto_get_out_decl_state ();
100 ob
->main_stream
= XCNEW (struct lto_output_stream
);
101 ob
->string_stream
= XCNEW (struct lto_output_stream
);
102 ob
->writer_cache
= streamer_tree_cache_create (!flag_wpa
, true, false);
104 if (section_type
== LTO_section_function_body
)
105 ob
->cfg_stream
= XCNEW (struct lto_output_stream
);
107 clear_line_info (ob
);
109 ob
->string_hash_table
= new hash_table
<string_slot_hasher
> (37);
110 gcc_obstack_init (&ob
->obstack
);
116 /* Destroy the output block OB. */
119 destroy_output_block (struct output_block
*ob
)
121 enum lto_section_type section_type
= ob
->section_type
;
123 delete ob
->string_hash_table
;
124 ob
->string_hash_table
= NULL
;
126 free (ob
->main_stream
);
127 free (ob
->string_stream
);
128 if (section_type
== LTO_section_function_body
)
129 free (ob
->cfg_stream
);
131 streamer_tree_cache_delete (ob
->writer_cache
);
132 obstack_free (&ob
->obstack
, NULL
);
138 /* Look up NODE in the type table and write the index for it to OB. */
141 output_type_ref (struct output_block
*ob
, tree node
)
143 streamer_write_record_start (ob
, LTO_type_ref
);
144 lto_output_type_ref_index (ob
->decl_state
, ob
->main_stream
, node
);
148 /* Return true if tree node T is written to various tables. For these
149 nodes, we sometimes want to write their phyiscal representation
150 (via lto_output_tree), and sometimes we need to emit an index
151 reference into a table (via lto_output_tree_ref). */
154 tree_is_indexable (tree t
)
156 /* Parameters and return values of functions of variably modified types
157 must go to global stream, because they may be used in the type
159 if ((TREE_CODE (t
) == PARM_DECL
|| TREE_CODE (t
) == RESULT_DECL
)
161 return variably_modified_type_p (TREE_TYPE (DECL_CONTEXT (t
)), NULL_TREE
);
162 /* IMPORTED_DECL is put into BLOCK and thus it never can be shared. */
163 else if (TREE_CODE (t
) == IMPORTED_DECL
)
165 else if (((TREE_CODE (t
) == VAR_DECL
&& !TREE_STATIC (t
))
166 || TREE_CODE (t
) == TYPE_DECL
167 || TREE_CODE (t
) == CONST_DECL
168 || TREE_CODE (t
) == NAMELIST_DECL
)
169 && decl_function_context (t
))
171 else if (TREE_CODE (t
) == DEBUG_EXPR_DECL
)
173 /* Variably modified types need to be streamed alongside function
174 bodies because they can refer to local entities. Together with
175 them we have to localize their members as well.
176 ??? In theory that includes non-FIELD_DECLs as well. */
178 && variably_modified_type_p (t
, NULL_TREE
))
180 else if (TREE_CODE (t
) == FIELD_DECL
181 && variably_modified_type_p (DECL_CONTEXT (t
), NULL_TREE
))
184 return (TYPE_P (t
) || DECL_P (t
) || TREE_CODE (t
) == SSA_NAME
);
188 /* Output info about new location into bitpack BP.
189 After outputting bitpack, lto_output_location_data has
190 to be done to output actual data. */
193 lto_output_location (struct output_block
*ob
, struct bitpack_d
*bp
,
196 expanded_location xloc
;
198 loc
= LOCATION_LOCUS (loc
);
199 bp_pack_int_in_range (bp
, 0, RESERVED_LOCATION_COUNT
,
200 loc
< RESERVED_LOCATION_COUNT
201 ? loc
: RESERVED_LOCATION_COUNT
);
202 if (loc
< RESERVED_LOCATION_COUNT
)
205 xloc
= expand_location (loc
);
207 bp_pack_value (bp
, ob
->current_file
!= xloc
.file
, 1);
208 bp_pack_value (bp
, ob
->current_line
!= xloc
.line
, 1);
209 bp_pack_value (bp
, ob
->current_col
!= xloc
.column
, 1);
211 if (ob
->current_file
!= xloc
.file
)
212 bp_pack_string (ob
, bp
, xloc
.file
, true);
213 ob
->current_file
= xloc
.file
;
215 if (ob
->current_line
!= xloc
.line
)
216 bp_pack_var_len_unsigned (bp
, xloc
.line
);
217 ob
->current_line
= xloc
.line
;
219 if (ob
->current_col
!= xloc
.column
)
220 bp_pack_var_len_unsigned (bp
, xloc
.column
);
221 ob
->current_col
= xloc
.column
;
225 /* If EXPR is an indexable tree node, output a reference to it to
226 output block OB. Otherwise, output the physical representation of
230 lto_output_tree_ref (struct output_block
*ob
, tree expr
)
236 output_type_ref (ob
, expr
);
240 code
= TREE_CODE (expr
);
244 streamer_write_record_start (ob
, LTO_ssa_name_ref
);
245 streamer_write_uhwi (ob
, SSA_NAME_VERSION (expr
));
249 streamer_write_record_start (ob
, LTO_field_decl_ref
);
250 lto_output_field_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
254 streamer_write_record_start (ob
, LTO_function_decl_ref
);
255 lto_output_fn_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
259 case DEBUG_EXPR_DECL
:
260 gcc_assert (decl_function_context (expr
) == NULL
|| TREE_STATIC (expr
));
262 streamer_write_record_start (ob
, LTO_global_decl_ref
);
263 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
267 streamer_write_record_start (ob
, LTO_const_decl_ref
);
268 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
272 gcc_assert (decl_function_context (expr
) == NULL
);
273 streamer_write_record_start (ob
, LTO_imported_decl_ref
);
274 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
278 streamer_write_record_start (ob
, LTO_type_decl_ref
);
279 lto_output_type_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
283 streamer_write_record_start (ob
, LTO_namelist_decl_ref
);
284 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
288 streamer_write_record_start (ob
, LTO_namespace_decl_ref
);
289 lto_output_namespace_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
293 streamer_write_record_start (ob
, LTO_label_decl_ref
);
294 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
298 streamer_write_record_start (ob
, LTO_result_decl_ref
);
299 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
302 case TRANSLATION_UNIT_DECL
:
303 streamer_write_record_start (ob
, LTO_translation_unit_decl_ref
);
304 lto_output_var_decl_index (ob
->decl_state
, ob
->main_stream
, expr
);
308 /* No other node is indexable, so it should have been handled by
315 /* Return true if EXPR is a tree node that can be written to disk. */
318 lto_is_streamable (tree expr
)
320 enum tree_code code
= TREE_CODE (expr
);
322 /* Notice that we reject SSA_NAMEs as well. We only emit the SSA
323 name version in lto_output_tree_ref (see output_ssa_names). */
324 return !is_lang_specific (expr
)
328 && code
!= MODIFY_EXPR
330 && code
!= TARGET_EXPR
332 && code
!= WITH_CLEANUP_EXPR
333 && code
!= STATEMENT_LIST
334 && (code
== CASE_LABEL_EXPR
336 || TREE_CODE_CLASS (code
) != tcc_statement
);
340 /* For EXPR lookup and return what we want to stream to OB as DECL_INITIAL. */
343 get_symbol_initial_value (lto_symtab_encoder_t encoder
, tree expr
)
345 gcc_checking_assert (DECL_P (expr
)
346 && TREE_CODE (expr
) != FUNCTION_DECL
347 && TREE_CODE (expr
) != TRANSLATION_UNIT_DECL
);
349 /* Handle DECL_INITIAL for symbols. */
350 tree initial
= DECL_INITIAL (expr
);
351 if (TREE_CODE (expr
) == VAR_DECL
352 && (TREE_STATIC (expr
) || DECL_EXTERNAL (expr
))
353 && !DECL_IN_CONSTANT_POOL (expr
)
357 /* Extra section needs about 30 bytes; do not produce it for simple
359 if (TREE_CODE (DECL_INITIAL (expr
)) == CONSTRUCTOR
360 || !(vnode
= varpool_node::get (expr
))
361 || !lto_symtab_encoder_encode_initializer_p (encoder
, vnode
))
362 initial
= error_mark_node
;
369 /* Write a physical representation of tree node EXPR to output block
370 OB. If REF_P is true, the leaves of EXPR are emitted as references
371 via lto_output_tree_ref. IX is the index into the streamer cache
372 where EXPR is stored. */
375 lto_write_tree_1 (struct output_block
*ob
, tree expr
, bool ref_p
)
377 /* Pack all the non-pointer fields in EXPR into a bitpack and write
378 the resulting bitpack. */
379 streamer_write_tree_bitfields (ob
, expr
);
381 /* Write all the pointer fields in EXPR. */
382 streamer_write_tree_body (ob
, expr
, ref_p
);
384 /* Write any LTO-specific data to OB. */
386 && TREE_CODE (expr
) != FUNCTION_DECL
387 && TREE_CODE (expr
) != TRANSLATION_UNIT_DECL
)
389 /* Handle DECL_INITIAL for symbols. */
390 tree initial
= get_symbol_initial_value
391 (ob
->decl_state
->symtab_node_encoder
, expr
);
392 stream_write_tree (ob
, initial
, ref_p
);
396 /* Write a physical representation of tree node EXPR to output block
397 OB. If REF_P is true, the leaves of EXPR are emitted as references
398 via lto_output_tree_ref. IX is the index into the streamer cache
399 where EXPR is stored. */
402 lto_write_tree (struct output_block
*ob
, tree expr
, bool ref_p
)
404 if (!lto_is_streamable (expr
))
405 internal_error ("tree code %qs is not supported in LTO streams",
406 get_tree_code_name (TREE_CODE (expr
)));
408 /* Write the header, containing everything needed to materialize
409 EXPR on the reading side. */
410 streamer_write_tree_header (ob
, expr
);
412 lto_write_tree_1 (ob
, expr
, ref_p
);
414 /* Mark the end of EXPR. */
415 streamer_write_zero (ob
);
418 /* Emit the physical representation of tree node EXPR to output block
419 OB. If THIS_REF_P is true, the leaves of EXPR are emitted as references
420 via lto_output_tree_ref. REF_P is used for streaming siblings of EXPR. */
423 lto_output_tree_1 (struct output_block
*ob
, tree expr
, hashval_t hash
,
424 bool ref_p
, bool this_ref_p
)
428 gcc_checking_assert (expr
!= NULL_TREE
429 && !(this_ref_p
&& tree_is_indexable (expr
)));
431 bool exists_p
= streamer_tree_cache_insert (ob
->writer_cache
,
433 gcc_assert (!exists_p
);
434 if (streamer_handle_as_builtin_p (expr
))
436 /* MD and NORMAL builtins do not need to be written out
437 completely as they are always instantiated by the
438 compiler on startup. The only builtins that need to
439 be written out are BUILT_IN_FRONTEND. For all other
440 builtins, we simply write the class and code. */
441 streamer_write_builtin (ob
, expr
);
443 else if (TREE_CODE (expr
) == INTEGER_CST
444 && !TREE_OVERFLOW (expr
))
446 /* Shared INTEGER_CST nodes are special because they need their
447 original type to be materialized by the reader (to implement
448 TYPE_CACHED_VALUES). */
449 streamer_write_integer_cst (ob
, expr
, ref_p
);
453 /* This is the first time we see EXPR, write its fields
455 lto_write_tree (ob
, expr
, ref_p
);
462 DFS (struct output_block
*ob
, tree expr
, bool ref_p
, bool this_ref_p
,
471 vec
<scc_entry
> sccstack
;
488 static int scc_entry_compare (const void *, const void *);
490 void DFS_write_tree_body (struct output_block
*ob
,
491 tree expr
, sccs
*expr_state
, bool ref_p
);
493 void DFS_write_tree (struct output_block
*ob
, sccs
*from_state
,
494 tree expr
, bool ref_p
, bool this_ref_p
);
497 hash_scc (struct output_block
*ob
, unsigned first
, unsigned size
);
499 hash_map
<tree
, sccs
*> sccstate
;
500 vec
<worklist
> worklist_vec
;
501 struct obstack sccstate_obstack
;
504 DFS::DFS (struct output_block
*ob
, tree expr
, bool ref_p
, bool this_ref_p
,
507 unsigned int next_dfs_num
= 1;
509 gcc_obstack_init (&sccstate_obstack
);
510 worklist_vec
= vNULL
;
511 DFS_write_tree (ob
, NULL
, expr
, ref_p
, this_ref_p
);
512 while (!worklist_vec
.is_empty ())
514 worklist
&w
= worklist_vec
.last ();
516 sccs
*from_state
= w
.from_state
;
517 sccs
*cstate
= w
.cstate
;
519 this_ref_p
= w
.this_ref_p
;
522 sccs
**slot
= &sccstate
.get_or_insert (expr
);
526 gcc_checking_assert (from_state
);
527 if (cstate
->dfsnum
< from_state
->dfsnum
)
528 from_state
->low
= MIN (cstate
->dfsnum
, from_state
->low
);
533 scc_entry e
= { expr
, 0 };
534 /* Not yet visited. DFS recurse and push it onto the stack. */
535 *slot
= cstate
= XOBNEW (&sccstate_obstack
, struct sccs
);
536 sccstack
.safe_push (e
);
537 cstate
->dfsnum
= next_dfs_num
++;
538 cstate
->low
= cstate
->dfsnum
;
541 if (streamer_handle_as_builtin_p (expr
))
543 else if (TREE_CODE (expr
) == INTEGER_CST
544 && !TREE_OVERFLOW (expr
))
545 DFS_write_tree (ob
, cstate
, TREE_TYPE (expr
), ref_p
, ref_p
);
548 DFS_write_tree_body (ob
, expr
, cstate
, ref_p
);
550 /* Walk any LTO-specific edges. */
552 && TREE_CODE (expr
) != FUNCTION_DECL
553 && TREE_CODE (expr
) != TRANSLATION_UNIT_DECL
)
555 /* Handle DECL_INITIAL for symbols. */
557 = get_symbol_initial_value (ob
->decl_state
->symtab_node_encoder
,
559 DFS_write_tree (ob
, cstate
, initial
, ref_p
, ref_p
);
565 /* See if we found an SCC. */
566 if (cstate
->low
== cstate
->dfsnum
)
568 unsigned first
, size
;
571 /* If we are re-walking a single leaf-SCC just pop it,
572 let earlier worklist item access the sccstack. */
579 /* Pop the SCC and compute its size. */
580 first
= sccstack
.length ();
583 x
= sccstack
[--first
].t
;
586 size
= sccstack
.length () - first
;
588 /* No need to compute hashes for LTRANS units, we don't perform
589 any merging there. */
590 hashval_t scc_hash
= 0;
591 unsigned scc_entry_len
= 0;
594 scc_hash
= hash_scc (ob
, first
, size
);
596 /* Put the entries with the least number of collisions first. */
597 unsigned entry_start
= 0;
598 scc_entry_len
= size
+ 1;
599 for (unsigned i
= 0; i
< size
;)
602 for (i
= i
+ 1; i
< size
603 && (sccstack
[first
+ i
].hash
604 == sccstack
[first
+ from
].hash
); ++i
)
606 if (i
- from
< scc_entry_len
)
608 scc_entry_len
= i
- from
;
612 for (unsigned i
= 0; i
< scc_entry_len
; ++i
)
614 scc_entry tem
= sccstack
[first
+ i
];
615 sccstack
[first
+ i
] = sccstack
[first
+ entry_start
+ i
];
616 sccstack
[first
+ entry_start
+ i
] = tem
;
619 if (scc_entry_len
== 1)
620 ; /* We already sorted SCC deterministically in hash_scc. */
622 /* Check that we have only one SCC.
623 Naturally we may have conflicts if hash function is not
624 strong enough. Lets see how far this gets. */
626 #ifdef ENABLE_CHECKING
632 /* Write LTO_tree_scc. */
633 streamer_write_record_start (ob
, LTO_tree_scc
);
634 streamer_write_uhwi (ob
, size
);
635 streamer_write_uhwi (ob
, scc_hash
);
637 /* Write size-1 SCCs without wrapping them inside SCC bundles.
638 All INTEGER_CSTs need to be handled this way as we need
639 their type to materialize them. Also builtins are handled
641 ??? We still wrap these in LTO_tree_scc so at the
642 input side we can properly identify the tree we want
643 to ultimatively return. */
645 lto_output_tree_1 (ob
, expr
, scc_hash
, ref_p
, this_ref_p
);
648 /* Write the size of the SCC entry candidates. */
649 streamer_write_uhwi (ob
, scc_entry_len
);
651 /* Write all headers and populate the streamer cache. */
652 for (unsigned i
= 0; i
< size
; ++i
)
654 hashval_t hash
= sccstack
[first
+i
].hash
;
655 tree t
= sccstack
[first
+i
].t
;
656 bool exists_p
= streamer_tree_cache_insert (ob
->writer_cache
,
658 gcc_assert (!exists_p
);
660 if (!lto_is_streamable (t
))
661 internal_error ("tree code %qs is not supported "
663 get_tree_code_name (TREE_CODE (t
)));
665 gcc_checking_assert (!streamer_handle_as_builtin_p (t
));
667 /* Write the header, containing everything needed to
668 materialize EXPR on the reading side. */
669 streamer_write_tree_header (ob
, t
);
672 /* Write the bitpacks and tree references. */
673 for (unsigned i
= 0; i
< size
; ++i
)
675 lto_write_tree_1 (ob
, sccstack
[first
+i
].t
, ref_p
);
677 /* Mark the end of the tree. */
678 streamer_write_zero (ob
);
682 /* Finally truncate the vector. */
683 sccstack
.truncate (first
);
686 from_state
->low
= MIN (from_state
->low
, cstate
->low
);
691 gcc_checking_assert (from_state
);
692 from_state
->low
= MIN (from_state
->low
, cstate
->low
);
693 if (cstate
->dfsnum
< from_state
->dfsnum
)
694 from_state
->low
= MIN (cstate
->dfsnum
, from_state
->low
);
697 worklist_vec
.release ();
703 obstack_free (&sccstate_obstack
, NULL
);
706 /* Handle the tree EXPR in the DFS walk with SCC state EXPR_STATE and
707 DFS recurse for all tree edges originating from it. */
710 DFS::DFS_write_tree_body (struct output_block
*ob
,
711 tree expr
, sccs
*expr_state
, bool ref_p
)
713 #define DFS_follow_tree_edge(DEST) \
714 DFS_write_tree (ob, expr_state, DEST, ref_p, ref_p)
718 code
= TREE_CODE (expr
);
720 if (CODE_CONTAINS_STRUCT (code
, TS_TYPED
))
722 if (TREE_CODE (expr
) != IDENTIFIER_NODE
)
723 DFS_follow_tree_edge (TREE_TYPE (expr
));
726 if (CODE_CONTAINS_STRUCT (code
, TS_VECTOR
))
728 for (unsigned i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
729 DFS_follow_tree_edge (VECTOR_CST_ELT (expr
, i
));
732 if (CODE_CONTAINS_STRUCT (code
, TS_COMPLEX
))
734 DFS_follow_tree_edge (TREE_REALPART (expr
));
735 DFS_follow_tree_edge (TREE_IMAGPART (expr
));
738 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_MINIMAL
))
740 /* Drop names that were created for anonymous entities. */
742 && TREE_CODE (DECL_NAME (expr
)) == IDENTIFIER_NODE
743 && ANON_AGGRNAME_P (DECL_NAME (expr
)))
746 DFS_follow_tree_edge (DECL_NAME (expr
));
747 DFS_follow_tree_edge (DECL_CONTEXT (expr
));
750 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
752 DFS_follow_tree_edge (DECL_SIZE (expr
));
753 DFS_follow_tree_edge (DECL_SIZE_UNIT (expr
));
755 /* Note, DECL_INITIAL is not handled here. Since DECL_INITIAL needs
756 special handling in LTO, it must be handled by streamer hooks. */
758 DFS_follow_tree_edge (DECL_ATTRIBUTES (expr
));
760 /* Do not follow DECL_ABSTRACT_ORIGIN. We cannot handle debug information
761 for early inlining so drop it on the floor instead of ICEing in
764 if ((TREE_CODE (expr
) == VAR_DECL
765 || TREE_CODE (expr
) == PARM_DECL
)
766 && DECL_HAS_VALUE_EXPR_P (expr
))
767 DFS_follow_tree_edge (DECL_VALUE_EXPR (expr
));
768 if (TREE_CODE (expr
) == VAR_DECL
)
769 DFS_follow_tree_edge (DECL_DEBUG_EXPR (expr
));
772 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_NON_COMMON
))
774 if (TREE_CODE (expr
) == TYPE_DECL
)
775 DFS_follow_tree_edge (DECL_ORIGINAL_TYPE (expr
));
778 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
780 /* Make sure we don't inadvertently set the assembler name. */
781 if (DECL_ASSEMBLER_NAME_SET_P (expr
))
782 DFS_follow_tree_edge (DECL_ASSEMBLER_NAME (expr
));
785 if (CODE_CONTAINS_STRUCT (code
, TS_FIELD_DECL
))
787 DFS_follow_tree_edge (DECL_FIELD_OFFSET (expr
));
788 DFS_follow_tree_edge (DECL_BIT_FIELD_TYPE (expr
));
789 DFS_follow_tree_edge (DECL_BIT_FIELD_REPRESENTATIVE (expr
));
790 DFS_follow_tree_edge (DECL_FIELD_BIT_OFFSET (expr
));
791 DFS_follow_tree_edge (DECL_FCONTEXT (expr
));
794 if (CODE_CONTAINS_STRUCT (code
, TS_FUNCTION_DECL
))
796 DFS_follow_tree_edge (DECL_VINDEX (expr
));
797 DFS_follow_tree_edge (DECL_FUNCTION_PERSONALITY (expr
));
798 DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_TARGET (expr
));
799 DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr
));
802 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_COMMON
))
804 DFS_follow_tree_edge (TYPE_SIZE (expr
));
805 DFS_follow_tree_edge (TYPE_SIZE_UNIT (expr
));
806 DFS_follow_tree_edge (TYPE_ATTRIBUTES (expr
));
807 DFS_follow_tree_edge (TYPE_NAME (expr
));
808 /* Do not follow TYPE_POINTER_TO or TYPE_REFERENCE_TO. They will be
809 reconstructed during fixup. */
810 /* Do not follow TYPE_NEXT_VARIANT, we reconstruct the variant lists
812 DFS_follow_tree_edge (TYPE_MAIN_VARIANT (expr
));
813 DFS_follow_tree_edge (TYPE_CONTEXT (expr
));
814 /* TYPE_CANONICAL is re-computed during type merging, so no need
815 to follow it here. */
816 DFS_follow_tree_edge (TYPE_STUB_DECL (expr
));
819 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_NON_COMMON
))
821 if (TREE_CODE (expr
) == ENUMERAL_TYPE
)
822 DFS_follow_tree_edge (TYPE_VALUES (expr
));
823 else if (TREE_CODE (expr
) == ARRAY_TYPE
)
824 DFS_follow_tree_edge (TYPE_DOMAIN (expr
));
825 else if (RECORD_OR_UNION_TYPE_P (expr
))
826 for (tree t
= TYPE_FIELDS (expr
); t
; t
= TREE_CHAIN (t
))
827 DFS_follow_tree_edge (t
);
828 else if (TREE_CODE (expr
) == FUNCTION_TYPE
829 || TREE_CODE (expr
) == METHOD_TYPE
)
830 DFS_follow_tree_edge (TYPE_ARG_TYPES (expr
));
832 if (!POINTER_TYPE_P (expr
))
833 DFS_follow_tree_edge (TYPE_MINVAL (expr
));
834 DFS_follow_tree_edge (TYPE_MAXVAL (expr
));
835 if (RECORD_OR_UNION_TYPE_P (expr
))
836 DFS_follow_tree_edge (TYPE_BINFO (expr
));
839 if (CODE_CONTAINS_STRUCT (code
, TS_LIST
))
841 DFS_follow_tree_edge (TREE_PURPOSE (expr
));
842 DFS_follow_tree_edge (TREE_VALUE (expr
));
843 DFS_follow_tree_edge (TREE_CHAIN (expr
));
846 if (CODE_CONTAINS_STRUCT (code
, TS_VEC
))
848 for (int i
= 0; i
< TREE_VEC_LENGTH (expr
); i
++)
849 DFS_follow_tree_edge (TREE_VEC_ELT (expr
, i
));
852 if (CODE_CONTAINS_STRUCT (code
, TS_EXP
))
854 for (int i
= 0; i
< TREE_OPERAND_LENGTH (expr
); i
++)
855 DFS_follow_tree_edge (TREE_OPERAND (expr
, i
));
856 DFS_follow_tree_edge (TREE_BLOCK (expr
));
859 if (CODE_CONTAINS_STRUCT (code
, TS_BLOCK
))
861 for (tree t
= BLOCK_VARS (expr
); t
; t
= TREE_CHAIN (t
))
862 if (VAR_OR_FUNCTION_DECL_P (t
)
863 && DECL_EXTERNAL (t
))
864 /* We have to stream externals in the block chain as
865 non-references. See also
866 tree-streamer-out.c:streamer_write_chain. */
867 DFS_write_tree (ob
, expr_state
, t
, ref_p
, false);
869 DFS_follow_tree_edge (t
);
871 DFS_follow_tree_edge (BLOCK_SUPERCONTEXT (expr
));
873 /* Follow BLOCK_ABSTRACT_ORIGIN for the limited cases we can
874 handle - those that represent inlined function scopes.
875 For the drop rest them on the floor instead of ICEing
877 if (inlined_function_outer_scope_p (expr
))
879 tree ultimate_origin
= block_ultimate_origin (expr
);
880 DFS_follow_tree_edge (ultimate_origin
);
882 /* Do not follow BLOCK_NONLOCALIZED_VARS. We cannot handle debug
883 information for early inlined BLOCKs so drop it on the floor instead
884 of ICEing in dwarf2out.c. */
886 /* BLOCK_FRAGMENT_ORIGIN and BLOCK_FRAGMENT_CHAIN is not live at LTO
889 /* Do not output BLOCK_SUBBLOCKS. Instead on streaming-in this
890 list is re-constructed from BLOCK_SUPERCONTEXT. */
893 if (CODE_CONTAINS_STRUCT (code
, TS_BINFO
))
898 /* Note that the number of BINFO slots has already been emitted in
899 EXPR's header (see streamer_write_tree_header) because this length
900 is needed to build the empty BINFO node on the reader side. */
901 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (expr
), i
, t
)
902 DFS_follow_tree_edge (t
);
903 DFS_follow_tree_edge (BINFO_OFFSET (expr
));
904 DFS_follow_tree_edge (BINFO_VTABLE (expr
));
905 DFS_follow_tree_edge (BINFO_VPTR_FIELD (expr
));
907 /* The number of BINFO_BASE_ACCESSES has already been emitted in
908 EXPR's bitfield section. */
909 FOR_EACH_VEC_SAFE_ELT (BINFO_BASE_ACCESSES (expr
), i
, t
)
910 DFS_follow_tree_edge (t
);
912 /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX
913 and BINFO_VPTR_INDEX; these are used by C++ FE only. */
916 if (CODE_CONTAINS_STRUCT (code
, TS_CONSTRUCTOR
))
921 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (expr
), i
, index
, value
)
923 DFS_follow_tree_edge (index
);
924 DFS_follow_tree_edge (value
);
928 if (code
== OMP_CLAUSE
)
931 for (i
= 0; i
< omp_clause_num_ops
[OMP_CLAUSE_CODE (expr
)]; i
++)
932 DFS_follow_tree_edge (OMP_CLAUSE_OPERAND (expr
, i
));
933 DFS_follow_tree_edge (OMP_CLAUSE_CHAIN (expr
));
936 #undef DFS_follow_tree_edge
939 /* Return a hash value for the tree T.
940 CACHE holds hash values of trees outside current SCC. MAP, if non-NULL,
941 may hold hash values if trees inside current SCC. */
944 hash_tree (struct streamer_tree_cache_d
*cache
, hash_map
<tree
, hashval_t
> *map
, tree t
)
946 inchash::hash hstate
;
948 #define visit(SIBLING) \
952 hstate.add_int (0); \
953 else if (streamer_tree_cache_lookup (cache, SIBLING, &ix)) \
954 hstate.add_int (streamer_tree_cache_get_hash (cache, ix)); \
956 hstate.add_int (*map->get (SIBLING)); \
958 hstate.add_int (1); \
962 enum tree_code code
= TREE_CODE (t
);
963 hstate
.add_int (code
);
966 hstate
.add_flag (TREE_SIDE_EFFECTS (t
));
967 hstate
.add_flag (TREE_CONSTANT (t
));
968 hstate
.add_flag (TREE_READONLY (t
));
969 hstate
.add_flag (TREE_PUBLIC (t
));
971 hstate
.add_flag (TREE_ADDRESSABLE (t
));
972 hstate
.add_flag (TREE_THIS_VOLATILE (t
));
974 hstate
.add_flag (DECL_UNSIGNED (t
));
976 hstate
.add_flag (TYPE_UNSIGNED (t
));
978 hstate
.add_flag (TYPE_ARTIFICIAL (t
));
980 hstate
.add_flag (TREE_NO_WARNING (t
));
981 hstate
.add_flag (TREE_NOTHROW (t
));
982 hstate
.add_flag (TREE_STATIC (t
));
983 hstate
.add_flag (TREE_PROTECTED (t
));
984 hstate
.add_flag (TREE_DEPRECATED (t
));
985 if (code
!= TREE_BINFO
)
986 hstate
.add_flag (TREE_PRIVATE (t
));
989 hstate
.add_flag (TYPE_SATURATING (t
));
990 hstate
.add_flag (TYPE_ADDR_SPACE (t
));
992 else if (code
== SSA_NAME
)
993 hstate
.add_flag (SSA_NAME_IS_DEFAULT_DEF (t
));
994 hstate
.commit_flag ();
996 if (CODE_CONTAINS_STRUCT (code
, TS_INT_CST
))
999 hstate
.add_wide_int (TREE_INT_CST_NUNITS (t
));
1000 hstate
.add_wide_int (TREE_INT_CST_EXT_NUNITS (t
));
1001 for (i
= 0; i
< TREE_INT_CST_NUNITS (t
); i
++)
1002 hstate
.add_wide_int (TREE_INT_CST_ELT (t
, i
));
1005 if (CODE_CONTAINS_STRUCT (code
, TS_REAL_CST
))
1007 REAL_VALUE_TYPE r
= TREE_REAL_CST (t
);
1008 hstate
.add_flag (r
.cl
);
1009 hstate
.add_flag (r
.sign
);
1010 hstate
.add_flag (r
.signalling
);
1011 hstate
.add_flag (r
.canonical
);
1012 hstate
.commit_flag ();
1013 hstate
.add_int (r
.uexp
);
1014 hstate
.add (r
.sig
, sizeof (r
.sig
));
1017 if (CODE_CONTAINS_STRUCT (code
, TS_FIXED_CST
))
1019 FIXED_VALUE_TYPE f
= TREE_FIXED_CST (t
);
1020 hstate
.add_int (f
.mode
);
1021 hstate
.add_int (f
.data
.low
);
1022 hstate
.add_int (f
.data
.high
);
1025 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
1027 hstate
.add_wide_int (DECL_MODE (t
));
1028 hstate
.add_flag (DECL_NONLOCAL (t
));
1029 hstate
.add_flag (DECL_VIRTUAL_P (t
));
1030 hstate
.add_flag (DECL_IGNORED_P (t
));
1031 hstate
.add_flag (DECL_ABSTRACT_P (t
));
1032 hstate
.add_flag (DECL_ARTIFICIAL (t
));
1033 hstate
.add_flag (DECL_USER_ALIGN (t
));
1034 hstate
.add_flag (DECL_PRESERVE_P (t
));
1035 hstate
.add_flag (DECL_EXTERNAL (t
));
1036 hstate
.add_flag (DECL_GIMPLE_REG_P (t
));
1037 hstate
.commit_flag ();
1038 hstate
.add_int (DECL_ALIGN (t
));
1039 if (code
== LABEL_DECL
)
1041 hstate
.add_int (EH_LANDING_PAD_NR (t
));
1042 hstate
.add_int (LABEL_DECL_UID (t
));
1044 else if (code
== FIELD_DECL
)
1046 hstate
.add_flag (DECL_PACKED (t
));
1047 hstate
.add_flag (DECL_NONADDRESSABLE_P (t
));
1048 hstate
.add_int (DECL_OFFSET_ALIGN (t
));
1050 else if (code
== VAR_DECL
)
1052 hstate
.add_flag (DECL_HAS_DEBUG_EXPR_P (t
));
1053 hstate
.add_flag (DECL_NONLOCAL_FRAME (t
));
1055 if (code
== RESULT_DECL
1056 || code
== PARM_DECL
1057 || code
== VAR_DECL
)
1059 hstate
.add_flag (DECL_BY_REFERENCE (t
));
1060 if (code
== VAR_DECL
1061 || code
== PARM_DECL
)
1062 hstate
.add_flag (DECL_HAS_VALUE_EXPR_P (t
));
1064 hstate
.commit_flag ();
1067 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WRTL
))
1068 hstate
.add_int (DECL_REGISTER (t
));
1070 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
1072 hstate
.add_flag (DECL_COMMON (t
));
1073 hstate
.add_flag (DECL_DLLIMPORT_P (t
));
1074 hstate
.add_flag (DECL_WEAK (t
));
1075 hstate
.add_flag (DECL_SEEN_IN_BIND_EXPR_P (t
));
1076 hstate
.add_flag (DECL_COMDAT (t
));
1077 hstate
.add_flag (DECL_VISIBILITY_SPECIFIED (t
));
1078 hstate
.add_int (DECL_VISIBILITY (t
));
1079 if (code
== VAR_DECL
)
1081 /* DECL_IN_TEXT_SECTION is set during final asm output only. */
1082 hstate
.add_flag (DECL_HARD_REGISTER (t
));
1083 hstate
.add_flag (DECL_IN_CONSTANT_POOL (t
));
1085 if (TREE_CODE (t
) == FUNCTION_DECL
)
1087 hstate
.add_flag (DECL_FINAL_P (t
));
1088 hstate
.add_flag (DECL_CXX_CONSTRUCTOR_P (t
));
1089 hstate
.add_flag (DECL_CXX_DESTRUCTOR_P (t
));
1091 hstate
.commit_flag ();
1094 if (CODE_CONTAINS_STRUCT (code
, TS_FUNCTION_DECL
))
1096 hstate
.add_int (DECL_BUILT_IN_CLASS (t
));
1097 hstate
.add_flag (DECL_STATIC_CONSTRUCTOR (t
));
1098 hstate
.add_flag (DECL_STATIC_DESTRUCTOR (t
));
1099 hstate
.add_flag (DECL_UNINLINABLE (t
));
1100 hstate
.add_flag (DECL_POSSIBLY_INLINED (t
));
1101 hstate
.add_flag (DECL_IS_NOVOPS (t
));
1102 hstate
.add_flag (DECL_IS_RETURNS_TWICE (t
));
1103 hstate
.add_flag (DECL_IS_MALLOC (t
));
1104 hstate
.add_flag (DECL_IS_OPERATOR_NEW (t
));
1105 hstate
.add_flag (DECL_DECLARED_INLINE_P (t
));
1106 hstate
.add_flag (DECL_STATIC_CHAIN (t
));
1107 hstate
.add_flag (DECL_NO_INLINE_WARNING_P (t
));
1108 hstate
.add_flag (DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (t
));
1109 hstate
.add_flag (DECL_NO_LIMIT_STACK (t
));
1110 hstate
.add_flag (DECL_DISREGARD_INLINE_LIMITS (t
));
1111 hstate
.add_flag (DECL_PURE_P (t
));
1112 hstate
.add_flag (DECL_LOOPING_CONST_OR_PURE_P (t
));
1113 hstate
.commit_flag ();
1114 if (DECL_BUILT_IN_CLASS (t
) != NOT_BUILT_IN
)
1115 hstate
.add_int (DECL_FUNCTION_CODE (t
));
1118 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_COMMON
))
1120 hstate
.add_wide_int (TYPE_MODE (t
));
1121 hstate
.add_flag (TYPE_STRING_FLAG (t
));
1122 hstate
.add_flag (TYPE_NO_FORCE_BLK (t
));
1123 hstate
.add_flag (TYPE_NEEDS_CONSTRUCTING (t
));
1124 hstate
.add_flag (TYPE_PACKED (t
));
1125 hstate
.add_flag (TYPE_RESTRICT (t
));
1126 hstate
.add_flag (TYPE_USER_ALIGN (t
));
1127 hstate
.add_flag (TYPE_READONLY (t
));
1128 if (RECORD_OR_UNION_TYPE_P (t
))
1130 hstate
.add_flag (TYPE_TRANSPARENT_AGGR (t
));
1131 hstate
.add_flag (TYPE_FINAL_P (t
));
1133 else if (code
== ARRAY_TYPE
)
1134 hstate
.add_flag (TYPE_NONALIASED_COMPONENT (t
));
1135 hstate
.commit_flag ();
1136 hstate
.add_int (TYPE_PRECISION (t
));
1137 hstate
.add_int (TYPE_ALIGN (t
));
1138 hstate
.add_int ((TYPE_ALIAS_SET (t
) == 0
1140 && get_alias_set (t
) == 0))
1144 if (CODE_CONTAINS_STRUCT (code
, TS_TRANSLATION_UNIT_DECL
))
1145 hstate
.add (TRANSLATION_UNIT_LANGUAGE (t
),
1146 strlen (TRANSLATION_UNIT_LANGUAGE (t
)));
1148 if (CODE_CONTAINS_STRUCT (code
, TS_TARGET_OPTION
)
1149 /* We don't stream these when passing things to a different target. */
1150 && !lto_stream_offload_p
)
1151 hstate
.add_wide_int (cl_target_option_hash (TREE_TARGET_OPTION (t
)));
1153 if (CODE_CONTAINS_STRUCT (code
, TS_OPTIMIZATION
))
1154 hstate
.add_wide_int (cl_optimization_hash (TREE_OPTIMIZATION (t
)));
1156 if (CODE_CONTAINS_STRUCT (code
, TS_IDENTIFIER
))
1157 hstate
.merge_hash (IDENTIFIER_HASH_VALUE (t
));
1159 if (CODE_CONTAINS_STRUCT (code
, TS_STRING
))
1160 hstate
.add (TREE_STRING_POINTER (t
), TREE_STRING_LENGTH (t
));
1162 if (CODE_CONTAINS_STRUCT (code
, TS_TYPED
))
1164 if (code
!= IDENTIFIER_NODE
)
1165 visit (TREE_TYPE (t
));
1168 if (CODE_CONTAINS_STRUCT (code
, TS_VECTOR
))
1169 for (unsigned i
= 0; i
< VECTOR_CST_NELTS (t
); ++i
)
1170 visit (VECTOR_CST_ELT (t
, i
));
1172 if (CODE_CONTAINS_STRUCT (code
, TS_COMPLEX
))
1174 visit (TREE_REALPART (t
));
1175 visit (TREE_IMAGPART (t
));
1178 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_MINIMAL
))
1180 /* Drop names that were created for anonymous entities. */
1182 && TREE_CODE (DECL_NAME (t
)) == IDENTIFIER_NODE
1183 && ANON_AGGRNAME_P (DECL_NAME (t
)))
1186 visit (DECL_NAME (t
));
1187 if (DECL_FILE_SCOPE_P (t
))
1190 visit (DECL_CONTEXT (t
));
1193 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
1195 visit (DECL_SIZE (t
));
1196 visit (DECL_SIZE_UNIT (t
));
1197 visit (DECL_ATTRIBUTES (t
));
1198 if ((code
== VAR_DECL
1199 || code
== PARM_DECL
)
1200 && DECL_HAS_VALUE_EXPR_P (t
))
1201 visit (DECL_VALUE_EXPR (t
));
1202 if (code
== VAR_DECL
1203 && DECL_HAS_DEBUG_EXPR_P (t
))
1204 visit (DECL_DEBUG_EXPR (t
));
1205 /* ??? Hash DECL_INITIAL as streamed. Needs the output-block to
1206 be able to call get_symbol_initial_value. */
1209 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_NON_COMMON
))
1211 if (code
== TYPE_DECL
)
1212 visit (DECL_ORIGINAL_TYPE (t
));
1215 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
1217 if (DECL_ASSEMBLER_NAME_SET_P (t
))
1218 visit (DECL_ASSEMBLER_NAME (t
));
1221 if (CODE_CONTAINS_STRUCT (code
, TS_FIELD_DECL
))
1223 visit (DECL_FIELD_OFFSET (t
));
1224 visit (DECL_BIT_FIELD_TYPE (t
));
1225 visit (DECL_BIT_FIELD_REPRESENTATIVE (t
));
1226 visit (DECL_FIELD_BIT_OFFSET (t
));
1227 visit (DECL_FCONTEXT (t
));
1230 if (CODE_CONTAINS_STRUCT (code
, TS_FUNCTION_DECL
))
1232 visit (DECL_VINDEX (t
));
1233 visit (DECL_FUNCTION_PERSONALITY (t
));
1234 visit (DECL_FUNCTION_SPECIFIC_TARGET (t
));
1235 visit (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (t
));
1238 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_COMMON
))
1240 visit (TYPE_SIZE (t
));
1241 visit (TYPE_SIZE_UNIT (t
));
1242 visit (TYPE_ATTRIBUTES (t
));
1243 visit (TYPE_NAME (t
));
1244 visit (TYPE_MAIN_VARIANT (t
));
1245 if (TYPE_FILE_SCOPE_P (t
))
1248 visit (TYPE_CONTEXT (t
));
1249 visit (TYPE_STUB_DECL (t
));
1252 if (CODE_CONTAINS_STRUCT (code
, TS_TYPE_NON_COMMON
))
1254 if (code
== ENUMERAL_TYPE
)
1255 visit (TYPE_VALUES (t
));
1256 else if (code
== ARRAY_TYPE
)
1257 visit (TYPE_DOMAIN (t
));
1258 else if (RECORD_OR_UNION_TYPE_P (t
))
1259 for (tree f
= TYPE_FIELDS (t
); f
; f
= TREE_CHAIN (f
))
1261 else if (code
== FUNCTION_TYPE
1262 || code
== METHOD_TYPE
)
1263 visit (TYPE_ARG_TYPES (t
));
1264 if (!POINTER_TYPE_P (t
))
1265 visit (TYPE_MINVAL (t
));
1266 visit (TYPE_MAXVAL (t
));
1267 if (RECORD_OR_UNION_TYPE_P (t
))
1268 visit (TYPE_BINFO (t
));
1271 if (CODE_CONTAINS_STRUCT (code
, TS_LIST
))
1273 visit (TREE_PURPOSE (t
));
1274 visit (TREE_VALUE (t
));
1275 visit (TREE_CHAIN (t
));
1278 if (CODE_CONTAINS_STRUCT (code
, TS_VEC
))
1279 for (int i
= 0; i
< TREE_VEC_LENGTH (t
); ++i
)
1280 visit (TREE_VEC_ELT (t
, i
));
1282 if (CODE_CONTAINS_STRUCT (code
, TS_EXP
))
1284 hstate
.add_wide_int (TREE_OPERAND_LENGTH (t
));
1285 for (int i
= 0; i
< TREE_OPERAND_LENGTH (t
); ++i
)
1286 visit (TREE_OPERAND (t
, i
));
1289 if (CODE_CONTAINS_STRUCT (code
, TS_BINFO
))
1293 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (t
), i
, b
)
1295 visit (BINFO_OFFSET (t
));
1296 visit (BINFO_VTABLE (t
));
1297 visit (BINFO_VPTR_FIELD (t
));
1298 FOR_EACH_VEC_SAFE_ELT (BINFO_BASE_ACCESSES (t
), i
, b
)
1300 /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX
1301 and BINFO_VPTR_INDEX; these are used by C++ FE only. */
1304 if (CODE_CONTAINS_STRUCT (code
, TS_CONSTRUCTOR
))
1308 hstate
.add_wide_int (CONSTRUCTOR_NELTS (t
));
1309 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), i
, index
, value
)
1316 if (code
== OMP_CLAUSE
)
1321 hstate
.add_wide_int (OMP_CLAUSE_CODE (t
));
1322 switch (OMP_CLAUSE_CODE (t
))
1324 case OMP_CLAUSE_DEFAULT
:
1325 val
= OMP_CLAUSE_DEFAULT_KIND (t
);
1327 case OMP_CLAUSE_SCHEDULE
:
1328 val
= OMP_CLAUSE_SCHEDULE_KIND (t
);
1330 case OMP_CLAUSE_DEPEND
:
1331 val
= OMP_CLAUSE_DEPEND_KIND (t
);
1333 case OMP_CLAUSE_MAP
:
1334 val
= OMP_CLAUSE_MAP_KIND (t
);
1336 case OMP_CLAUSE_PROC_BIND
:
1337 val
= OMP_CLAUSE_PROC_BIND_KIND (t
);
1339 case OMP_CLAUSE_REDUCTION
:
1340 val
= OMP_CLAUSE_REDUCTION_CODE (t
);
1346 hstate
.add_wide_int (val
);
1347 for (i
= 0; i
< omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)]; i
++)
1348 visit (OMP_CLAUSE_OPERAND (t
, i
));
1349 visit (OMP_CLAUSE_CHAIN (t
));
1352 return hstate
.end ();
1357 /* Compare two SCC entries by their hash value for qsorting them. */
1360 DFS::scc_entry_compare (const void *p1_
, const void *p2_
)
1362 const scc_entry
*p1
= (const scc_entry
*) p1_
;
1363 const scc_entry
*p2
= (const scc_entry
*) p2_
;
1364 if (p1
->hash
< p2
->hash
)
1366 else if (p1
->hash
> p2
->hash
)
1371 /* Return a hash value for the SCC on the SCC stack from FIRST with
1375 DFS::hash_scc (struct output_block
*ob
,
1376 unsigned first
, unsigned size
)
1378 unsigned int last_classes
= 0, iterations
= 0;
1380 /* Compute hash values for the SCC members. */
1381 for (unsigned i
= 0; i
< size
; ++i
)
1382 sccstack
[first
+i
].hash
= hash_tree (ob
->writer_cache
, NULL
,
1383 sccstack
[first
+i
].t
);
1386 return sccstack
[first
].hash
;
1388 /* We aim to get unique hash for every tree within SCC and compute hash value
1389 of the whole SCC by combing all values together in an stable (entry point
1390 independent) order. This guarantees that the same SCC regions within
1391 different translation units will get the same hash values and therefore
1392 will be merged at WPA time.
1394 Often the hashes are already unique. In that case we compute scc hash
1395 by combining individual hash values in an increasing order.
1397 If thre are duplicates we seek at least one tree with unique hash (and
1398 pick one with minimal hash and this property). Then we obtain stable
1399 order by DFS walk starting from this unique tree and then use index
1400 within this order to make individual hash values unique.
1402 If there is no tree with unique hash, we iteratively propagate the hash
1403 values across the internal edges of SCC. This usually quickly leads
1404 to unique hashes. Consider, for example, an SCC containing two pointers
1405 that are identical except for type they point and assume that these
1406 types are also part of the SCC.
1407 The propagation will add the points-to type information into their hash
1411 /* Sort the SCC so we can easily see check for uniqueness. */
1412 qsort (&sccstack
[first
], size
, sizeof (scc_entry
), scc_entry_compare
);
1414 unsigned int classes
= 1;
1415 int firstunique
= -1;
1417 /* Find tree with lowest unique hash (if it exists) and compute
1418 number of equivalence classes. */
1419 if (sccstack
[first
].hash
!= sccstack
[first
+1].hash
)
1421 for (unsigned i
= 1; i
< size
; ++i
)
1422 if (sccstack
[first
+i
-1].hash
!= sccstack
[first
+i
].hash
)
1425 if (firstunique
== -1
1427 || sccstack
[first
+i
+1].hash
!= sccstack
[first
+i
].hash
))
1431 /* If we found tree with unique hash; stop the iteration. */
1432 if (firstunique
!= -1
1433 /* Also terminate if we run out of iterations or if the number of
1434 equivalence classes is no longer increasing.
1435 For example a cyclic list of trees that are all equivalent will
1436 never have unique entry point; we however do not build such SCCs
1438 || classes
<= last_classes
|| iterations
> 16)
1442 /* If some hashes are not unique (CLASSES != SIZE), use the DFS walk
1443 starting from FIRSTUNIQUE to obstain stable order. */
1444 if (classes
!= size
&& firstunique
!= -1)
1446 hash_map
<tree
, hashval_t
> map(size
*2);
1448 /* Store hash values into a map, so we can associate them with
1450 for (unsigned i
= 0; i
< size
; ++i
)
1451 map
.put (sccstack
[first
+i
].t
, sccstack
[first
+i
].hash
);
1453 DFS
again (ob
, sccstack
[first
+firstunique
].t
, false, false, true);
1454 gcc_assert (again
.sccstack
.length () == size
);
1456 memcpy (sccstack
.address () + first
,
1457 again
.sccstack
.address (),
1458 sizeof (scc_entry
) * size
);
1460 /* Update hash values of individual members by hashing in the
1461 index within the stable order. This ensures uniqueness.
1462 Also compute the scc_hash by mixing in all hash values in the
1463 stable order we obtained. */
1464 sccstack
[first
].hash
= *map
.get (sccstack
[first
].t
);
1465 scc_hash
= sccstack
[first
].hash
;
1466 for (unsigned i
= 1; i
< size
; ++i
)
1468 sccstack
[first
+i
].hash
1469 = iterative_hash_hashval_t (i
,
1470 *map
.get (sccstack
[first
+i
].t
));
1471 scc_hash
= iterative_hash_hashval_t (scc_hash
,
1472 sccstack
[first
+i
].hash
);
1475 /* If we got unique hash values for each tree, then sort already
1476 ensured entry point independent order. Only compute the final
1479 If we failed to find the unique entry point, we go by the same
1480 route. We will eventually introduce unwanted hash conflicts. */
1483 scc_hash
= sccstack
[first
].hash
;
1484 for (unsigned i
= 1; i
< size
; ++i
)
1485 scc_hash
= iterative_hash_hashval_t (scc_hash
,
1486 sccstack
[first
+i
].hash
);
1487 /* We can not 100% guarantee that the hash will not conflict in
1488 in a way so the unique hash is not found. This however
1489 should be extremely rare situation. ICE for now so possible
1490 issues are found and evaulated. */
1491 gcc_checking_assert (classes
== size
);
1494 /* To avoid conflicts across SCCs iteratively hash the whole SCC
1495 hash into the hash of each of the elements. */
1496 for (unsigned i
= 0; i
< size
; ++i
)
1497 sccstack
[first
+i
].hash
1498 = iterative_hash_hashval_t (sccstack
[first
+i
].hash
, scc_hash
);
1502 last_classes
= classes
;
1505 /* We failed to identify the entry point; propagate hash values across
1508 hash_map
<tree
, hashval_t
> map(size
*2);
1509 for (unsigned i
= 0; i
< size
; ++i
)
1510 map
.put (sccstack
[first
+i
].t
, sccstack
[first
+i
].hash
);
1512 for (unsigned i
= 0; i
< size
; i
++)
1513 sccstack
[first
+i
].hash
= hash_tree (ob
->writer_cache
, &map
,
1514 sccstack
[first
+i
].t
);
1520 /* DFS walk EXPR and stream SCCs of tree bodies if they are not
1521 already in the streamer cache. Main routine called for
1522 each visit of EXPR. */
1525 DFS::DFS_write_tree (struct output_block
*ob
, sccs
*from_state
,
1526 tree expr
, bool ref_p
, bool this_ref_p
)
1528 /* Handle special cases. */
1529 if (expr
== NULL_TREE
)
1532 /* Do not DFS walk into indexable trees. */
1533 if (this_ref_p
&& tree_is_indexable (expr
))
1536 /* Check if we already streamed EXPR. */
1537 if (streamer_tree_cache_lookup (ob
->writer_cache
, expr
, NULL
))
1542 w
.from_state
= from_state
;
1545 w
.this_ref_p
= this_ref_p
;
1546 worklist_vec
.safe_push (w
);
1550 /* Emit the physical representation of tree node EXPR to output block
1551 OB. If THIS_REF_P is true, the leaves of EXPR are emitted as references
1552 via lto_output_tree_ref. REF_P is used for streaming siblings of EXPR. */
1555 lto_output_tree (struct output_block
*ob
, tree expr
,
1556 bool ref_p
, bool this_ref_p
)
1561 if (expr
== NULL_TREE
)
1563 streamer_write_record_start (ob
, LTO_null
);
1567 if (this_ref_p
&& tree_is_indexable (expr
))
1569 lto_output_tree_ref (ob
, expr
);
1573 existed_p
= streamer_tree_cache_lookup (ob
->writer_cache
, expr
, &ix
);
1576 /* If a node has already been streamed out, make sure that
1577 we don't write it more than once. Otherwise, the reader
1578 will instantiate two different nodes for the same object. */
1579 streamer_write_record_start (ob
, LTO_tree_pickle_reference
);
1580 streamer_write_uhwi (ob
, ix
);
1581 streamer_write_enum (ob
->main_stream
, LTO_tags
, LTO_NUM_TAGS
,
1582 lto_tree_code_to_tag (TREE_CODE (expr
)));
1583 lto_stats
.num_pickle_refs_output
++;
1587 /* This is the first time we see EXPR, write all reachable
1589 static bool in_dfs_walk
;
1591 /* Protect against recursion which means disconnect between
1592 what tree edges we walk in the DFS walk and what edges
1594 gcc_assert (!in_dfs_walk
);
1596 /* Start the DFS walk. */
1597 /* Save ob state ... */
1600 DFS (ob
, expr
, ref_p
, this_ref_p
, false);
1601 in_dfs_walk
= false;
1603 /* Finally append a reference to the tree we were writing.
1604 ??? If expr ended up as a singleton we could have
1605 inlined it here and avoid outputting a reference. */
1606 existed_p
= streamer_tree_cache_lookup (ob
->writer_cache
, expr
, &ix
);
1607 gcc_assert (existed_p
);
1608 streamer_write_record_start (ob
, LTO_tree_pickle_reference
);
1609 streamer_write_uhwi (ob
, ix
);
1610 streamer_write_enum (ob
->main_stream
, LTO_tags
, LTO_NUM_TAGS
,
1611 lto_tree_code_to_tag (TREE_CODE (expr
)));
1612 lto_stats
.num_pickle_refs_output
++;
1617 /* Output to OB a list of try/catch handlers starting with FIRST. */
1620 output_eh_try_list (struct output_block
*ob
, eh_catch first
)
1624 for (n
= first
; n
; n
= n
->next_catch
)
1626 streamer_write_record_start (ob
, LTO_eh_catch
);
1627 stream_write_tree (ob
, n
->type_list
, true);
1628 stream_write_tree (ob
, n
->filter_list
, true);
1629 stream_write_tree (ob
, n
->label
, true);
1632 streamer_write_record_start (ob
, LTO_null
);
1636 /* Output EH region R in function FN to OB. CURR_RN is the slot index
1637 that is being emitted in FN->EH->REGION_ARRAY. This is used to
1638 detect EH region sharing. */
1641 output_eh_region (struct output_block
*ob
, eh_region r
)
1647 streamer_write_record_start (ob
, LTO_null
);
1651 if (r
->type
== ERT_CLEANUP
)
1652 tag
= LTO_ert_cleanup
;
1653 else if (r
->type
== ERT_TRY
)
1655 else if (r
->type
== ERT_ALLOWED_EXCEPTIONS
)
1656 tag
= LTO_ert_allowed_exceptions
;
1657 else if (r
->type
== ERT_MUST_NOT_THROW
)
1658 tag
= LTO_ert_must_not_throw
;
1662 streamer_write_record_start (ob
, tag
);
1663 streamer_write_hwi (ob
, r
->index
);
1666 streamer_write_hwi (ob
, r
->outer
->index
);
1668 streamer_write_zero (ob
);
1671 streamer_write_hwi (ob
, r
->inner
->index
);
1673 streamer_write_zero (ob
);
1676 streamer_write_hwi (ob
, r
->next_peer
->index
);
1678 streamer_write_zero (ob
);
1680 if (r
->type
== ERT_TRY
)
1682 output_eh_try_list (ob
, r
->u
.eh_try
.first_catch
);
1684 else if (r
->type
== ERT_ALLOWED_EXCEPTIONS
)
1686 stream_write_tree (ob
, r
->u
.allowed
.type_list
, true);
1687 stream_write_tree (ob
, r
->u
.allowed
.label
, true);
1688 streamer_write_uhwi (ob
, r
->u
.allowed
.filter
);
1690 else if (r
->type
== ERT_MUST_NOT_THROW
)
1692 stream_write_tree (ob
, r
->u
.must_not_throw
.failure_decl
, true);
1693 bitpack_d bp
= bitpack_create (ob
->main_stream
);
1694 stream_output_location (ob
, &bp
, r
->u
.must_not_throw
.failure_loc
);
1695 streamer_write_bitpack (&bp
);
1698 if (r
->landing_pads
)
1699 streamer_write_hwi (ob
, r
->landing_pads
->index
);
1701 streamer_write_zero (ob
);
1705 /* Output landing pad LP to OB. */
1708 output_eh_lp (struct output_block
*ob
, eh_landing_pad lp
)
1712 streamer_write_record_start (ob
, LTO_null
);
1716 streamer_write_record_start (ob
, LTO_eh_landing_pad
);
1717 streamer_write_hwi (ob
, lp
->index
);
1719 streamer_write_hwi (ob
, lp
->next_lp
->index
);
1721 streamer_write_zero (ob
);
1724 streamer_write_hwi (ob
, lp
->region
->index
);
1726 streamer_write_zero (ob
);
1728 stream_write_tree (ob
, lp
->post_landing_pad
, true);
1732 /* Output the existing eh_table to OB. */
1735 output_eh_regions (struct output_block
*ob
, struct function
*fn
)
1737 if (fn
->eh
&& fn
->eh
->region_tree
)
1744 streamer_write_record_start (ob
, LTO_eh_table
);
1746 /* Emit the index of the root of the EH region tree. */
1747 streamer_write_hwi (ob
, fn
->eh
->region_tree
->index
);
1749 /* Emit all the EH regions in the region array. */
1750 streamer_write_hwi (ob
, vec_safe_length (fn
->eh
->region_array
));
1751 FOR_EACH_VEC_SAFE_ELT (fn
->eh
->region_array
, i
, eh
)
1752 output_eh_region (ob
, eh
);
1754 /* Emit all landing pads. */
1755 streamer_write_hwi (ob
, vec_safe_length (fn
->eh
->lp_array
));
1756 FOR_EACH_VEC_SAFE_ELT (fn
->eh
->lp_array
, i
, lp
)
1757 output_eh_lp (ob
, lp
);
1759 /* Emit all the runtime type data. */
1760 streamer_write_hwi (ob
, vec_safe_length (fn
->eh
->ttype_data
));
1761 FOR_EACH_VEC_SAFE_ELT (fn
->eh
->ttype_data
, i
, ttype
)
1762 stream_write_tree (ob
, ttype
, true);
1764 /* Emit the table of action chains. */
1765 if (targetm
.arm_eabi_unwinder
)
1768 streamer_write_hwi (ob
, vec_safe_length (fn
->eh
->ehspec_data
.arm_eabi
));
1769 FOR_EACH_VEC_SAFE_ELT (fn
->eh
->ehspec_data
.arm_eabi
, i
, t
)
1770 stream_write_tree (ob
, t
, true);
1775 streamer_write_hwi (ob
, vec_safe_length (fn
->eh
->ehspec_data
.other
));
1776 FOR_EACH_VEC_SAFE_ELT (fn
->eh
->ehspec_data
.other
, i
, c
)
1777 streamer_write_char_stream (ob
->main_stream
, c
);
1781 /* The LTO_null either terminates the record or indicates that there
1782 are no eh_records at all. */
1783 streamer_write_record_start (ob
, LTO_null
);
1787 /* Output all of the active ssa names to the ssa_names stream. */
1790 output_ssa_names (struct output_block
*ob
, struct function
*fn
)
1792 unsigned int i
, len
;
1794 len
= vec_safe_length (SSANAMES (fn
));
1795 streamer_write_uhwi (ob
, len
);
1797 for (i
= 1; i
< len
; i
++)
1799 tree ptr
= (*SSANAMES (fn
))[i
];
1801 if (ptr
== NULL_TREE
1802 || SSA_NAME_IN_FREE_LIST (ptr
)
1803 || virtual_operand_p (ptr
))
1806 streamer_write_uhwi (ob
, i
);
1807 streamer_write_char_stream (ob
->main_stream
,
1808 SSA_NAME_IS_DEFAULT_DEF (ptr
));
1809 if (SSA_NAME_VAR (ptr
))
1810 stream_write_tree (ob
, SSA_NAME_VAR (ptr
), true);
1812 /* ??? This drops SSA_NAME_IDENTIFIER on the floor. */
1813 stream_write_tree (ob
, TREE_TYPE (ptr
), true);
1816 streamer_write_zero (ob
);
1820 /* Output a wide-int. */
1823 streamer_write_wi (struct output_block
*ob
,
1824 const widest_int
&w
)
1826 int len
= w
.get_len ();
1828 streamer_write_uhwi (ob
, w
.get_precision ());
1829 streamer_write_uhwi (ob
, len
);
1830 for (int i
= 0; i
< len
; i
++)
1831 streamer_write_hwi (ob
, w
.elt (i
));
1835 /* Output the cfg. */
1838 output_cfg (struct output_block
*ob
, struct function
*fn
)
1840 struct lto_output_stream
*tmp_stream
= ob
->main_stream
;
1843 ob
->main_stream
= ob
->cfg_stream
;
1845 streamer_write_enum (ob
->main_stream
, profile_status_d
, PROFILE_LAST
,
1846 profile_status_for_fn (fn
));
1848 /* Output the number of the highest basic block. */
1849 streamer_write_uhwi (ob
, last_basic_block_for_fn (fn
));
1851 FOR_ALL_BB_FN (bb
, fn
)
1856 streamer_write_hwi (ob
, bb
->index
);
1858 /* Output the successors and the edge flags. */
1859 streamer_write_uhwi (ob
, EDGE_COUNT (bb
->succs
));
1860 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1862 streamer_write_uhwi (ob
, e
->dest
->index
);
1863 streamer_write_hwi (ob
, e
->probability
);
1864 streamer_write_gcov_count (ob
, e
->count
);
1865 streamer_write_uhwi (ob
, e
->flags
);
1869 streamer_write_hwi (ob
, -1);
1871 bb
= ENTRY_BLOCK_PTR_FOR_FN (cfun
);
1874 streamer_write_hwi (ob
, bb
->next_bb
->index
);
1878 streamer_write_hwi (ob
, -1);
1880 /* ??? The cfgloop interface is tied to cfun. */
1881 gcc_assert (cfun
== fn
);
1883 /* Output the number of loops. */
1884 streamer_write_uhwi (ob
, number_of_loops (fn
));
1886 /* Output each loop, skipping the tree root which has number zero. */
1887 for (unsigned i
= 1; i
< number_of_loops (fn
); ++i
)
1889 struct loop
*loop
= get_loop (fn
, i
);
1891 /* Write the index of the loop header. That's enough to rebuild
1892 the loop tree on the reader side. Stream -1 for an unused
1896 streamer_write_hwi (ob
, -1);
1900 streamer_write_hwi (ob
, loop
->header
->index
);
1902 /* Write everything copy_loop_info copies. */
1903 streamer_write_enum (ob
->main_stream
,
1904 loop_estimation
, EST_LAST
, loop
->estimate_state
);
1905 streamer_write_hwi (ob
, loop
->any_upper_bound
);
1906 if (loop
->any_upper_bound
)
1907 streamer_write_wi (ob
, loop
->nb_iterations_upper_bound
);
1908 streamer_write_hwi (ob
, loop
->any_estimate
);
1909 if (loop
->any_estimate
)
1910 streamer_write_wi (ob
, loop
->nb_iterations_estimate
);
1912 /* Write OMP SIMD related info. */
1913 streamer_write_hwi (ob
, loop
->safelen
);
1914 streamer_write_hwi (ob
, loop
->dont_vectorize
);
1915 streamer_write_hwi (ob
, loop
->force_vectorize
);
1916 stream_write_tree (ob
, loop
->simduid
, true);
1919 ob
->main_stream
= tmp_stream
;
1923 /* Create the header in the file using OB. If the section type is for
1924 a function, set FN to the decl for that function. */
1927 produce_asm (struct output_block
*ob
, tree fn
)
1929 enum lto_section_type section_type
= ob
->section_type
;
1930 struct lto_function_header header
;
1933 if (section_type
== LTO_section_function_body
)
1935 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn
));
1936 section_name
= lto_get_section_name (section_type
, name
, NULL
);
1939 section_name
= lto_get_section_name (section_type
, NULL
, NULL
);
1941 lto_begin_section (section_name
, !flag_wpa
);
1942 free (section_name
);
1944 /* The entire header is stream computed here. */
1945 memset (&header
, 0, sizeof (struct lto_function_header
));
1947 /* Write the header. */
1948 header
.major_version
= LTO_major_version
;
1949 header
.minor_version
= LTO_minor_version
;
1951 if (section_type
== LTO_section_function_body
)
1952 header
.cfg_size
= ob
->cfg_stream
->total_size
;
1953 header
.main_size
= ob
->main_stream
->total_size
;
1954 header
.string_size
= ob
->string_stream
->total_size
;
1955 lto_write_data (&header
, sizeof header
);
1957 /* Put all of the gimple and the string table out the asm file as a
1959 if (section_type
== LTO_section_function_body
)
1960 lto_write_stream (ob
->cfg_stream
);
1961 lto_write_stream (ob
->main_stream
);
1962 lto_write_stream (ob
->string_stream
);
1968 /* Output the base body of struct function FN using output block OB. */
1971 output_struct_function_base (struct output_block
*ob
, struct function
*fn
)
1973 struct bitpack_d bp
;
1977 /* Output the static chain and non-local goto save area. */
1978 stream_write_tree (ob
, fn
->static_chain_decl
, true);
1979 stream_write_tree (ob
, fn
->nonlocal_goto_save_area
, true);
1981 /* Output all the local variables in the function. */
1982 streamer_write_hwi (ob
, vec_safe_length (fn
->local_decls
));
1983 FOR_EACH_VEC_SAFE_ELT (fn
->local_decls
, i
, t
)
1984 stream_write_tree (ob
, t
, true);
1986 /* Output current IL state of the function. */
1987 streamer_write_uhwi (ob
, fn
->curr_properties
);
1989 /* Write all the attributes for FN. */
1990 bp
= bitpack_create (ob
->main_stream
);
1991 bp_pack_value (&bp
, fn
->is_thunk
, 1);
1992 bp_pack_value (&bp
, fn
->has_local_explicit_reg_vars
, 1);
1993 bp_pack_value (&bp
, fn
->returns_pcc_struct
, 1);
1994 bp_pack_value (&bp
, fn
->returns_struct
, 1);
1995 bp_pack_value (&bp
, fn
->can_throw_non_call_exceptions
, 1);
1996 bp_pack_value (&bp
, fn
->can_delete_dead_exceptions
, 1);
1997 bp_pack_value (&bp
, fn
->always_inline_functions_inlined
, 1);
1998 bp_pack_value (&bp
, fn
->after_inlining
, 1);
1999 bp_pack_value (&bp
, fn
->stdarg
, 1);
2000 bp_pack_value (&bp
, fn
->has_nonlocal_label
, 1);
2001 bp_pack_value (&bp
, fn
->calls_alloca
, 1);
2002 bp_pack_value (&bp
, fn
->calls_setjmp
, 1);
2003 bp_pack_value (&bp
, fn
->has_force_vectorize_loops
, 1);
2004 bp_pack_value (&bp
, fn
->has_simduid_loops
, 1);
2005 bp_pack_value (&bp
, fn
->va_list_fpr_size
, 8);
2006 bp_pack_value (&bp
, fn
->va_list_gpr_size
, 8);
2007 bp_pack_value (&bp
, fn
->last_clique
, sizeof (short) * 8);
2009 /* Output the function start and end loci. */
2010 stream_output_location (ob
, &bp
, fn
->function_start_locus
);
2011 stream_output_location (ob
, &bp
, fn
->function_end_locus
);
2013 streamer_write_bitpack (&bp
);
2017 /* Output the body of function NODE->DECL. */
2020 output_function (struct cgraph_node
*node
)
2023 struct function
*fn
;
2025 struct output_block
*ob
;
2027 function
= node
->decl
;
2028 fn
= DECL_STRUCT_FUNCTION (function
);
2029 ob
= create_output_block (LTO_section_function_body
);
2031 clear_line_info (ob
);
2034 gcc_assert (current_function_decl
== NULL_TREE
&& cfun
== NULL
);
2036 /* Set current_function_decl and cfun. */
2039 /* Make string 0 be a NULL string. */
2040 streamer_write_char_stream (ob
->string_stream
, 0);
2042 streamer_write_record_start (ob
, LTO_function
);
2044 /* Output decls for parameters and args. */
2045 stream_write_tree (ob
, DECL_RESULT (function
), true);
2046 streamer_write_chain (ob
, DECL_ARGUMENTS (function
), true);
2048 /* Output DECL_INITIAL for the function, which contains the tree of
2050 stream_write_tree (ob
, DECL_INITIAL (function
), true);
2052 /* We also stream abstract functions where we stream only stuff needed for
2054 if (gimple_has_body_p (function
))
2056 streamer_write_uhwi (ob
, 1);
2057 output_struct_function_base (ob
, fn
);
2059 /* Output all the SSA names used in the function. */
2060 output_ssa_names (ob
, fn
);
2062 /* Output any exception handling regions. */
2063 output_eh_regions (ob
, fn
);
2066 /* We will renumber the statements. The code that does this uses
2067 the same ordering that we use for serializing them so we can use
2068 the same code on the other end and not have to write out the
2069 statement numbers. We do not assign UIDs to PHIs here because
2070 virtual PHIs get re-computed on-the-fly which would make numbers
2072 set_gimple_stmt_max_uid (cfun
, 0);
2073 FOR_ALL_BB_FN (bb
, cfun
)
2075 for (gphi_iterator gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
);
2078 gphi
*stmt
= gsi
.phi ();
2080 /* Virtual PHIs are not going to be streamed. */
2081 if (!virtual_operand_p (gimple_phi_result (stmt
)))
2082 gimple_set_uid (stmt
, inc_gimple_stmt_max_uid (cfun
));
2084 for (gimple_stmt_iterator gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
);
2087 gimple stmt
= gsi_stmt (gsi
);
2088 gimple_set_uid (stmt
, inc_gimple_stmt_max_uid (cfun
));
2091 /* To avoid keeping duplicate gimple IDs in the statements, renumber
2092 virtual phis now. */
2093 FOR_ALL_BB_FN (bb
, cfun
)
2095 for (gphi_iterator gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
);
2098 gphi
*stmt
= gsi
.phi ();
2099 if (virtual_operand_p (gimple_phi_result (stmt
)))
2100 gimple_set_uid (stmt
, inc_gimple_stmt_max_uid (cfun
));
2104 /* Output the code for the function. */
2105 FOR_ALL_BB_FN (bb
, fn
)
2106 output_bb (ob
, bb
, fn
);
2108 /* The terminator for this function. */
2109 streamer_write_record_start (ob
, LTO_null
);
2111 output_cfg (ob
, fn
);
2116 streamer_write_uhwi (ob
, 0);
2118 /* Create a section to hold the pickled output of this function. */
2119 produce_asm (ob
, function
);
2121 destroy_output_block (ob
);
2124 /* Output the body of function NODE->DECL. */
2127 output_constructor (struct varpool_node
*node
)
2129 tree var
= node
->decl
;
2130 struct output_block
*ob
;
2132 ob
= create_output_block (LTO_section_function_body
);
2134 clear_line_info (ob
);
2137 /* Make string 0 be a NULL string. */
2138 streamer_write_char_stream (ob
->string_stream
, 0);
2140 /* Output DECL_INITIAL for the function, which contains the tree of
2142 stream_write_tree (ob
, DECL_INITIAL (var
), true);
2144 /* Create a section to hold the pickled output of this function. */
2145 produce_asm (ob
, var
);
2147 destroy_output_block (ob
);
2151 /* Emit toplevel asms. */
2154 lto_output_toplevel_asms (void)
2156 struct output_block
*ob
;
2157 struct asm_node
*can
;
2159 struct lto_simple_header_with_strings header
;
2161 if (!symtab
->first_asm_symbol ())
2164 ob
= create_output_block (LTO_section_asm
);
2166 /* Make string 0 be a NULL string. */
2167 streamer_write_char_stream (ob
->string_stream
, 0);
2169 for (can
= symtab
->first_asm_symbol (); can
; can
= can
->next
)
2171 streamer_write_string_cst (ob
, ob
->main_stream
, can
->asm_str
);
2172 streamer_write_hwi (ob
, can
->order
);
2175 streamer_write_string_cst (ob
, ob
->main_stream
, NULL_TREE
);
2177 section_name
= lto_get_section_name (LTO_section_asm
, NULL
, NULL
);
2178 lto_begin_section (section_name
, !flag_wpa
);
2179 free (section_name
);
2181 /* The entire header stream is computed here. */
2182 memset (&header
, 0, sizeof (header
));
2184 /* Write the header. */
2185 header
.major_version
= LTO_major_version
;
2186 header
.minor_version
= LTO_minor_version
;
2188 header
.main_size
= ob
->main_stream
->total_size
;
2189 header
.string_size
= ob
->string_stream
->total_size
;
2190 lto_write_data (&header
, sizeof header
);
2192 /* Put all of the gimple and the string table out the asm file as a
2194 lto_write_stream (ob
->main_stream
);
2195 lto_write_stream (ob
->string_stream
);
2199 destroy_output_block (ob
);
2203 /* Copy the function body or variable constructor of NODE without deserializing. */
2206 copy_function_or_variable (struct symtab_node
*node
)
2208 tree function
= node
->decl
;
2209 struct lto_file_decl_data
*file_data
= node
->lto_file_data
;
2212 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function
));
2213 char *section_name
=
2214 lto_get_section_name (LTO_section_function_body
, name
, NULL
);
2216 struct lto_in_decl_state
*in_state
;
2217 struct lto_out_decl_state
*out_state
= lto_get_out_decl_state ();
2219 lto_begin_section (section_name
, !flag_wpa
);
2220 free (section_name
);
2222 /* We may have renamed the declaration, e.g., a static function. */
2223 name
= lto_get_decl_name_mapping (file_data
, name
);
2225 data
= lto_get_section_data (file_data
, LTO_section_function_body
,
2229 /* Do a bit copy of the function body. */
2230 lto_write_data (data
, len
);
2234 lto_get_function_in_decl_state (node
->lto_file_data
, function
);
2235 gcc_assert (in_state
);
2237 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2239 size_t n
= vec_safe_length (in_state
->streams
[i
]);
2240 vec
<tree
, va_gc
> *trees
= in_state
->streams
[i
];
2241 struct lto_tree_ref_encoder
*encoder
= &(out_state
->streams
[i
]);
2243 /* The out state must have the same indices and the in state.
2244 So just copy the vector. All the encoders in the in state
2245 must be empty where we reach here. */
2246 gcc_assert (lto_tree_ref_encoder_size (encoder
) == 0);
2247 encoder
->trees
.reserve_exact (n
);
2248 for (j
= 0; j
< n
; j
++)
2249 encoder
->trees
.safe_push ((*trees
)[j
]);
2252 lto_free_section_data (file_data
, LTO_section_function_body
, name
,
2257 /* Wrap symbol references in *TP inside a type-preserving MEM_REF. */
2260 wrap_refs (tree
*tp
, int *ws
, void *)
2263 if (handled_component_p (t
)
2264 && TREE_CODE (TREE_OPERAND (t
, 0)) == VAR_DECL
)
2266 tree decl
= TREE_OPERAND (t
, 0);
2267 tree ptrtype
= build_pointer_type (TREE_TYPE (decl
));
2268 TREE_OPERAND (t
, 0) = build2 (MEM_REF
, TREE_TYPE (decl
),
2269 build1 (ADDR_EXPR
, ptrtype
, decl
),
2270 build_int_cst (ptrtype
, 0));
2271 TREE_THIS_VOLATILE (TREE_OPERAND (t
, 0)) = TREE_THIS_VOLATILE (decl
);
2274 else if (TREE_CODE (t
) == CONSTRUCTOR
)
2276 else if (!EXPR_P (t
))
2281 /* Main entry point from the pass manager. */
2286 struct lto_out_decl_state
*decl_state
;
2287 #ifdef ENABLE_CHECKING
2288 bitmap output
= lto_bitmap_alloc ();
2291 lto_symtab_encoder_t encoder
= lto_get_out_decl_state ()->symtab_node_encoder
;
2293 /* Initialize the streamer. */
2294 lto_streamer_init ();
2296 n_nodes
= lto_symtab_encoder_size (encoder
);
2297 /* Process only the functions with bodies. */
2298 for (i
= 0; i
< n_nodes
; i
++)
2300 symtab_node
*snode
= lto_symtab_encoder_deref (encoder
, i
);
2301 if (cgraph_node
*node
= dyn_cast
<cgraph_node
*> (snode
))
2303 if (lto_symtab_encoder_encode_body_p (encoder
, node
)
2306 #ifdef ENABLE_CHECKING
2307 gcc_assert (!bitmap_bit_p (output
, DECL_UID (node
->decl
)));
2308 bitmap_set_bit (output
, DECL_UID (node
->decl
));
2310 decl_state
= lto_new_out_decl_state ();
2311 lto_push_out_decl_state (decl_state
);
2312 if (gimple_has_body_p (node
->decl
) || !flag_wpa
2313 /* Thunks have no body but they may be synthetized
2315 || DECL_ARGUMENTS (node
->decl
))
2316 output_function (node
);
2318 copy_function_or_variable (node
);
2319 gcc_assert (lto_get_out_decl_state () == decl_state
);
2320 lto_pop_out_decl_state ();
2321 lto_record_function_out_decl_state (node
->decl
, decl_state
);
2324 else if (varpool_node
*node
= dyn_cast
<varpool_node
*> (snode
))
2326 /* Wrap symbol references inside the ctor in a type
2327 preserving MEM_REF. */
2328 tree ctor
= DECL_INITIAL (node
->decl
);
2329 if (ctor
&& !in_lto_p
)
2330 walk_tree (&ctor
, wrap_refs
, NULL
, NULL
);
2331 if (get_symbol_initial_value (encoder
, node
->decl
) == error_mark_node
2332 && lto_symtab_encoder_encode_initializer_p (encoder
, node
)
2335 timevar_push (TV_IPA_LTO_CTORS_OUT
);
2336 #ifdef ENABLE_CHECKING
2337 gcc_assert (!bitmap_bit_p (output
, DECL_UID (node
->decl
)));
2338 bitmap_set_bit (output
, DECL_UID (node
->decl
));
2340 decl_state
= lto_new_out_decl_state ();
2341 lto_push_out_decl_state (decl_state
);
2342 if (DECL_INITIAL (node
->decl
) != error_mark_node
2344 output_constructor (node
);
2346 copy_function_or_variable (node
);
2347 gcc_assert (lto_get_out_decl_state () == decl_state
);
2348 lto_pop_out_decl_state ();
2349 lto_record_function_out_decl_state (node
->decl
, decl_state
);
2350 timevar_pop (TV_IPA_LTO_CTORS_OUT
);
2355 /* Emit the callgraph after emitting function bodies. This needs to
2356 be done now to make sure that all the statements in every function
2357 have been renumbered so that edges can be associated with call
2358 statements using the statement UIDs. */
2361 output_offload_tables ();
2363 #ifdef ENABLE_CHECKING
2364 lto_bitmap_free (output
);
2368 /* Write each node in encoded by ENCODER to OB, as well as those reachable
2369 from it and required for correct representation of its semantics.
2370 Each node in ENCODER must be a global declaration or a type. A node
2371 is written only once, even if it appears multiple times in the
2372 vector. Certain transitively-reachable nodes, such as those
2373 representing expressions, may be duplicated, but such nodes
2374 must not appear in ENCODER itself. */
2377 write_global_stream (struct output_block
*ob
,
2378 struct lto_tree_ref_encoder
*encoder
)
2382 const size_t size
= lto_tree_ref_encoder_size (encoder
);
2384 for (index
= 0; index
< size
; index
++)
2386 t
= lto_tree_ref_encoder_get_tree (encoder
, index
);
2387 if (!streamer_tree_cache_lookup (ob
->writer_cache
, t
, NULL
))
2388 stream_write_tree (ob
, t
, false);
2393 /* Write a sequence of indices into the globals vector corresponding
2394 to the trees in ENCODER. These are used by the reader to map the
2395 indices used to refer to global entities within function bodies to
2399 write_global_references (struct output_block
*ob
,
2400 struct lto_tree_ref_encoder
*encoder
)
2404 const uint32_t size
= lto_tree_ref_encoder_size (encoder
);
2406 /* Write size and slot indexes as 32-bit unsigned numbers. */
2407 uint32_t *data
= XNEWVEC (uint32_t, size
+ 1);
2410 for (index
= 0; index
< size
; index
++)
2414 t
= lto_tree_ref_encoder_get_tree (encoder
, index
);
2415 streamer_tree_cache_lookup (ob
->writer_cache
, t
, &slot_num
);
2416 gcc_assert (slot_num
!= (unsigned)-1);
2417 data
[index
+ 1] = slot_num
;
2420 lto_write_data (data
, sizeof (int32_t) * (size
+ 1));
2425 /* Write all the streams in an lto_out_decl_state STATE using
2426 output block OB and output stream OUT_STREAM. */
2429 lto_output_decl_state_streams (struct output_block
*ob
,
2430 struct lto_out_decl_state
*state
)
2434 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2435 write_global_stream (ob
, &state
->streams
[i
]);
2439 /* Write all the references in an lto_out_decl_state STATE using
2440 output block OB and output stream OUT_STREAM. */
2443 lto_output_decl_state_refs (struct output_block
*ob
,
2444 struct lto_out_decl_state
*state
)
2450 /* Write reference to FUNCTION_DECL. If there is not function,
2451 write reference to void_type_node. */
2452 decl
= (state
->fn_decl
) ? state
->fn_decl
: void_type_node
;
2453 streamer_tree_cache_lookup (ob
->writer_cache
, decl
, &ref
);
2454 gcc_assert (ref
!= (unsigned)-1);
2455 lto_write_data (&ref
, sizeof (uint32_t));
2457 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2458 write_global_references (ob
, &state
->streams
[i
]);
2462 /* Return the written size of STATE. */
2465 lto_out_decl_state_written_size (struct lto_out_decl_state
*state
)
2470 size
= sizeof (int32_t); /* fn_ref. */
2471 for (i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2473 size
+= sizeof (int32_t); /* vector size. */
2474 size
+= (lto_tree_ref_encoder_size (&state
->streams
[i
])
2475 * sizeof (int32_t));
2481 /* Write symbol T into STREAM in CACHE. SEEN specifies symbols we wrote
2485 write_symbol (struct streamer_tree_cache_d
*cache
,
2486 tree t
, hash_set
<const char *> *seen
, bool alias
)
2489 enum gcc_plugin_symbol_kind kind
;
2490 enum gcc_plugin_symbol_visibility visibility
= GCCPV_DEFAULT
;
2496 /* None of the following kinds of symbols are needed in the
2498 if (!TREE_PUBLIC (t
)
2499 || is_builtin_fn (t
)
2500 || DECL_ABSTRACT_P (t
)
2501 || (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
)))
2503 gcc_assert (TREE_CODE (t
) != RESULT_DECL
);
2505 gcc_assert (TREE_CODE (t
) == VAR_DECL
2506 || TREE_CODE (t
) == FUNCTION_DECL
);
2508 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t
));
2510 /* This behaves like assemble_name_raw in varasm.c, performing the
2511 same name manipulations that ASM_OUTPUT_LABELREF does. */
2512 name
= IDENTIFIER_POINTER ((*targetm
.asm_out
.mangle_assembler_name
) (name
));
2514 if (seen
->add (name
))
2517 streamer_tree_cache_lookup (cache
, t
, &slot_num
);
2518 gcc_assert (slot_num
!= (unsigned)-1);
2520 if (DECL_EXTERNAL (t
))
2523 kind
= GCCPK_WEAKUNDEF
;
2530 kind
= GCCPK_WEAKDEF
;
2531 else if (DECL_COMMON (t
))
2532 kind
= GCCPK_COMMON
;
2536 /* When something is defined, it should have node attached. */
2537 gcc_assert (alias
|| TREE_CODE (t
) != VAR_DECL
2538 || varpool_node::get (t
)->definition
);
2539 gcc_assert (alias
|| TREE_CODE (t
) != FUNCTION_DECL
2540 || (cgraph_node::get (t
)
2541 && cgraph_node::get (t
)->definition
));
2544 /* Imitate what default_elf_asm_output_external do.
2545 When symbol is external, we need to output it with DEFAULT visibility
2546 when compiling with -fvisibility=default, while with HIDDEN visibility
2547 when symbol has attribute (visibility("hidden")) specified.
2548 targetm.binds_local_p check DECL_VISIBILITY_SPECIFIED and gets this
2551 if (DECL_EXTERNAL (t
)
2552 && !targetm
.binds_local_p (t
))
2553 visibility
= GCCPV_DEFAULT
;
2555 switch (DECL_VISIBILITY (t
))
2557 case VISIBILITY_DEFAULT
:
2558 visibility
= GCCPV_DEFAULT
;
2560 case VISIBILITY_PROTECTED
:
2561 visibility
= GCCPV_PROTECTED
;
2563 case VISIBILITY_HIDDEN
:
2564 visibility
= GCCPV_HIDDEN
;
2566 case VISIBILITY_INTERNAL
:
2567 visibility
= GCCPV_INTERNAL
;
2571 if (kind
== GCCPK_COMMON
2572 && DECL_SIZE_UNIT (t
)
2573 && TREE_CODE (DECL_SIZE_UNIT (t
)) == INTEGER_CST
)
2574 size
= TREE_INT_CST_LOW (DECL_SIZE_UNIT (t
));
2578 if (DECL_ONE_ONLY (t
))
2579 comdat
= IDENTIFIER_POINTER (decl_comdat_group_id (t
));
2583 lto_write_data (name
, strlen (name
) + 1);
2584 lto_write_data (comdat
, strlen (comdat
) + 1);
2585 c
= (unsigned char) kind
;
2586 lto_write_data (&c
, 1);
2587 c
= (unsigned char) visibility
;
2588 lto_write_data (&c
, 1);
2589 lto_write_data (&size
, 8);
2590 lto_write_data (&slot_num
, 4);
2593 /* Return true if NODE should appear in the plugin symbol table. */
2596 output_symbol_p (symtab_node
*node
)
2598 struct cgraph_node
*cnode
;
2599 if (!node
->real_symbol_p ())
2601 /* We keep external functions in symtab for sake of inlining
2602 and devirtualization. We do not want to see them in symbol table as
2603 references unless they are really used. */
2604 cnode
= dyn_cast
<cgraph_node
*> (node
);
2605 if (cnode
&& (!node
->definition
|| DECL_EXTERNAL (cnode
->decl
))
2609 /* Ignore all references from external vars initializers - they are not really
2610 part of the compilation unit until they are used by folding. Some symbols,
2611 like references to external construction vtables can not be referred to at all.
2612 We decide this at can_refer_decl_in_current_unit_p. */
2613 if (!node
->definition
|| DECL_EXTERNAL (node
->decl
))
2616 struct ipa_ref
*ref
;
2617 for (i
= 0; node
->iterate_referring (i
, ref
); i
++)
2619 if (ref
->use
== IPA_REF_ALIAS
)
2621 if (is_a
<cgraph_node
*> (ref
->referring
))
2623 if (!DECL_EXTERNAL (ref
->referring
->decl
))
2632 /* Write an IL symbol table to OB.
2633 SET and VSET are cgraph/varpool node sets we are outputting. */
2636 produce_symtab (struct output_block
*ob
)
2638 struct streamer_tree_cache_d
*cache
= ob
->writer_cache
;
2639 char *section_name
= lto_get_section_name (LTO_section_symtab
, NULL
, NULL
);
2640 lto_symtab_encoder_t encoder
= ob
->decl_state
->symtab_node_encoder
;
2641 lto_symtab_encoder_iterator lsei
;
2643 lto_begin_section (section_name
, false);
2644 free (section_name
);
2646 hash_set
<const char *> seen
;
2648 /* Write the symbol table.
2649 First write everything defined and then all declarations.
2650 This is necessary to handle cases where we have duplicated symbols. */
2651 for (lsei
= lsei_start (encoder
);
2652 !lsei_end_p (lsei
); lsei_next (&lsei
))
2654 symtab_node
*node
= lsei_node (lsei
);
2656 if (!output_symbol_p (node
) || DECL_EXTERNAL (node
->decl
))
2658 write_symbol (cache
, node
->decl
, &seen
, false);
2660 for (lsei
= lsei_start (encoder
);
2661 !lsei_end_p (lsei
); lsei_next (&lsei
))
2663 symtab_node
*node
= lsei_node (lsei
);
2665 if (!output_symbol_p (node
) || !DECL_EXTERNAL (node
->decl
))
2667 write_symbol (cache
, node
->decl
, &seen
, false);
2674 /* Init the streamer_mode_table for output, where we collect info on what
2675 machine_mode values have been streamed. */
2677 lto_output_init_mode_table (void)
2679 memset (streamer_mode_table
, '\0', MAX_MACHINE_MODE
);
2683 /* Write the mode table. */
2685 lto_write_mode_table (void)
2687 struct output_block
*ob
;
2688 ob
= create_output_block (LTO_section_mode_table
);
2689 bitpack_d bp
= bitpack_create (ob
->main_stream
);
2691 /* Ensure that for GET_MODE_INNER (m) != VOIDmode we have
2692 also the inner mode marked. */
2693 for (int i
= 0; i
< (int) MAX_MACHINE_MODE
; i
++)
2694 if (streamer_mode_table
[i
])
2696 machine_mode m
= (machine_mode
) i
;
2697 if (GET_MODE_INNER (m
) != VOIDmode
)
2698 streamer_mode_table
[(int) GET_MODE_INNER (m
)] = 1;
2700 /* First stream modes that have GET_MODE_INNER (m) == VOIDmode,
2701 so that we can refer to them afterwards. */
2702 for (int pass
= 0; pass
< 2; pass
++)
2703 for (int i
= 0; i
< (int) MAX_MACHINE_MODE
; i
++)
2704 if (streamer_mode_table
[i
] && i
!= (int) VOIDmode
&& i
!= (int) BLKmode
)
2706 machine_mode m
= (machine_mode
) i
;
2707 if ((GET_MODE_INNER (m
) == VOIDmode
) ^ (pass
== 0))
2709 bp_pack_value (&bp
, m
, 8);
2710 bp_pack_enum (&bp
, mode_class
, MAX_MODE_CLASS
, GET_MODE_CLASS (m
));
2711 bp_pack_value (&bp
, GET_MODE_SIZE (m
), 8);
2712 bp_pack_value (&bp
, GET_MODE_PRECISION (m
), 16);
2713 bp_pack_value (&bp
, GET_MODE_INNER (m
), 8);
2714 bp_pack_value (&bp
, GET_MODE_NUNITS (m
), 8);
2715 switch (GET_MODE_CLASS (m
))
2721 bp_pack_value (&bp
, GET_MODE_IBIT (m
), 8);
2722 bp_pack_value (&bp
, GET_MODE_FBIT (m
), 8);
2725 case MODE_DECIMAL_FLOAT
:
2726 bp_pack_string (ob
, &bp
, REAL_MODE_FORMAT (m
)->name
, true);
2731 bp_pack_string (ob
, &bp
, GET_MODE_NAME (m
), true);
2733 bp_pack_value (&bp
, VOIDmode
, 8);
2735 streamer_write_bitpack (&bp
);
2738 = lto_get_section_name (LTO_section_mode_table
, NULL
, NULL
);
2739 lto_begin_section (section_name
, !flag_wpa
);
2740 free (section_name
);
2742 /* The entire header stream is computed here. */
2743 struct lto_simple_header_with_strings header
;
2744 memset (&header
, 0, sizeof (header
));
2746 /* Write the header. */
2747 header
.major_version
= LTO_major_version
;
2748 header
.minor_version
= LTO_minor_version
;
2750 header
.main_size
= ob
->main_stream
->total_size
;
2751 header
.string_size
= ob
->string_stream
->total_size
;
2752 lto_write_data (&header
, sizeof header
);
2754 /* Put all of the gimple and the string table out the asm file as a
2756 lto_write_stream (ob
->main_stream
);
2757 lto_write_stream (ob
->string_stream
);
2760 destroy_output_block (ob
);
2764 /* This pass is run after all of the functions are serialized and all
2765 of the IPA passes have written their serialized forms. This pass
2766 causes the vector of all of the global decls and types used from
2767 this file to be written in to a section that can then be read in to
2768 recover these on other side. */
2771 produce_asm_for_decls (void)
2773 struct lto_out_decl_state
*out_state
;
2774 struct lto_out_decl_state
*fn_out_state
;
2775 struct lto_decl_header header
;
2777 struct output_block
*ob
;
2778 unsigned idx
, num_fns
;
2779 size_t decl_state_size
;
2780 int32_t num_decl_states
;
2782 ob
= create_output_block (LTO_section_decls
);
2784 memset (&header
, 0, sizeof (struct lto_decl_header
));
2786 section_name
= lto_get_section_name (LTO_section_decls
, NULL
, NULL
);
2787 lto_begin_section (section_name
, !flag_wpa
);
2788 free (section_name
);
2790 /* Make string 0 be a NULL string. */
2791 streamer_write_char_stream (ob
->string_stream
, 0);
2793 gcc_assert (!alias_pairs
);
2795 /* Get rid of the global decl state hash tables to save some memory. */
2796 out_state
= lto_get_out_decl_state ();
2797 for (int i
= 0; i
< LTO_N_DECL_STREAMS
; i
++)
2798 if (out_state
->streams
[i
].tree_hash_table
)
2800 delete out_state
->streams
[i
].tree_hash_table
;
2801 out_state
->streams
[i
].tree_hash_table
= NULL
;
2804 /* Write the global symbols. */
2805 lto_output_decl_state_streams (ob
, out_state
);
2806 num_fns
= lto_function_decl_states
.length ();
2807 for (idx
= 0; idx
< num_fns
; idx
++)
2810 lto_function_decl_states
[idx
];
2811 lto_output_decl_state_streams (ob
, fn_out_state
);
2814 header
.major_version
= LTO_major_version
;
2815 header
.minor_version
= LTO_minor_version
;
2817 /* Currently not used. This field would allow us to preallocate
2818 the globals vector, so that it need not be resized as it is extended. */
2819 header
.num_nodes
= -1;
2821 /* Compute the total size of all decl out states. */
2822 decl_state_size
= sizeof (int32_t);
2823 decl_state_size
+= lto_out_decl_state_written_size (out_state
);
2824 for (idx
= 0; idx
< num_fns
; idx
++)
2827 lto_function_decl_states
[idx
];
2828 decl_state_size
+= lto_out_decl_state_written_size (fn_out_state
);
2830 header
.decl_state_size
= decl_state_size
;
2832 header
.main_size
= ob
->main_stream
->total_size
;
2833 header
.string_size
= ob
->string_stream
->total_size
;
2835 lto_write_data (&header
, sizeof header
);
2837 /* Write the main out-decl state, followed by out-decl states of
2839 num_decl_states
= num_fns
+ 1;
2840 lto_write_data (&num_decl_states
, sizeof (num_decl_states
));
2841 lto_output_decl_state_refs (ob
, out_state
);
2842 for (idx
= 0; idx
< num_fns
; idx
++)
2844 fn_out_state
= lto_function_decl_states
[idx
];
2845 lto_output_decl_state_refs (ob
, fn_out_state
);
2848 lto_write_stream (ob
->main_stream
);
2849 lto_write_stream (ob
->string_stream
);
2853 /* Write the symbol table. It is used by linker to determine dependencies
2854 and thus we can skip it for WPA. */
2856 produce_symtab (ob
);
2858 /* Write command line opts. */
2859 lto_write_options ();
2861 /* Deallocate memory and clean up. */
2862 for (idx
= 0; idx
< num_fns
; idx
++)
2865 lto_function_decl_states
[idx
];
2866 lto_delete_out_decl_state (fn_out_state
);
2868 lto_symtab_encoder_delete (ob
->decl_state
->symtab_node_encoder
);
2869 lto_function_decl_states
.release ();
2870 destroy_output_block (ob
);
2871 if (lto_stream_offload_p
)
2872 lto_write_mode_table ();