PR c++/60336
[official-gcc.git] / gcc / lto / lto.c
blob748ef02143c129f73706fb99f1b7787eb24e4165
1 /* Top-level LTO routines.
2 Copyright (C) 2009-2017 Free Software Foundation, Inc.
3 Contributed by CodeSourcery, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "function.h"
26 #include "bitmap.h"
27 #include "basic-block.h"
28 #include "tree.h"
29 #include "gimple.h"
30 #include "cfghooks.h"
31 #include "alloc-pool.h"
32 #include "tree-pass.h"
33 #include "tree-streamer.h"
34 #include "cgraph.h"
35 #include "opts.h"
36 #include "toplev.h"
37 #include "stor-layout.h"
38 #include "symbol-summary.h"
39 #include "tree-vrp.h"
40 #include "ipa-prop.h"
41 #include "common.h"
42 #include "debug.h"
43 #include "lto.h"
44 #include "lto-section-names.h"
45 #include "splay-tree.h"
46 #include "lto-partition.h"
47 #include "context.h"
48 #include "pass_manager.h"
49 #include "ipa-fnsummary.h"
50 #include "params.h"
51 #include "ipa-utils.h"
52 #include "gomp-constants.h"
53 #include "lto-symtab.h"
54 #include "stringpool.h"
55 #include "fold-const.h"
56 #include "attribs.h"
59 /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver. */
60 static int lto_parallelism;
62 static GTY(()) tree first_personality_decl;
64 static GTY(()) const unsigned char *lto_mode_identity_table;
66 /* Returns a hash code for P. */
68 static hashval_t
69 hash_name (const void *p)
71 const struct lto_section_slot *ds = (const struct lto_section_slot *) p;
72 return (hashval_t) htab_hash_string (ds->name);
76 /* Returns nonzero if P1 and P2 are equal. */
78 static int
79 eq_name (const void *p1, const void *p2)
81 const struct lto_section_slot *s1 =
82 (const struct lto_section_slot *) p1;
83 const struct lto_section_slot *s2 =
84 (const struct lto_section_slot *) p2;
86 return strcmp (s1->name, s2->name) == 0;
89 /* Free lto_section_slot */
91 static void
92 free_with_string (void *arg)
94 struct lto_section_slot *s = (struct lto_section_slot *)arg;
96 free (CONST_CAST (char *, s->name));
97 free (arg);
100 /* Create section hash table */
102 htab_t
103 lto_obj_create_section_hash_table (void)
105 return htab_create (37, hash_name, eq_name, free_with_string);
108 /* Delete an allocated integer KEY in the splay tree. */
110 static void
111 lto_splay_tree_delete_id (splay_tree_key key)
113 free ((void *) key);
116 /* Compare splay tree node ids A and B. */
118 static int
119 lto_splay_tree_compare_ids (splay_tree_key a, splay_tree_key b)
121 unsigned HOST_WIDE_INT ai;
122 unsigned HOST_WIDE_INT bi;
124 ai = *(unsigned HOST_WIDE_INT *) a;
125 bi = *(unsigned HOST_WIDE_INT *) b;
127 if (ai < bi)
128 return -1;
129 else if (ai > bi)
130 return 1;
131 return 0;
134 /* Look up splay tree node by ID in splay tree T. */
136 static splay_tree_node
137 lto_splay_tree_lookup (splay_tree t, unsigned HOST_WIDE_INT id)
139 return splay_tree_lookup (t, (splay_tree_key) &id);
142 /* Check if KEY has ID. */
144 static bool
145 lto_splay_tree_id_equal_p (splay_tree_key key, unsigned HOST_WIDE_INT id)
147 return *(unsigned HOST_WIDE_INT *) key == id;
150 /* Insert a splay tree node into tree T with ID as key and FILE_DATA as value.
151 The ID is allocated separately because we need HOST_WIDE_INTs which may
152 be wider than a splay_tree_key. */
154 static void
155 lto_splay_tree_insert (splay_tree t, unsigned HOST_WIDE_INT id,
156 struct lto_file_decl_data *file_data)
158 unsigned HOST_WIDE_INT *idp = XCNEW (unsigned HOST_WIDE_INT);
159 *idp = id;
160 splay_tree_insert (t, (splay_tree_key) idp, (splay_tree_value) file_data);
163 /* Create a splay tree. */
165 static splay_tree
166 lto_splay_tree_new (void)
168 return splay_tree_new (lto_splay_tree_compare_ids,
169 lto_splay_tree_delete_id,
170 NULL);
173 /* Return true when NODE has a clone that is analyzed (i.e. we need
174 to load its body even if the node itself is not needed). */
176 static bool
177 has_analyzed_clone_p (struct cgraph_node *node)
179 struct cgraph_node *orig = node;
180 node = node->clones;
181 if (node)
182 while (node != orig)
184 if (node->analyzed)
185 return true;
186 if (node->clones)
187 node = node->clones;
188 else if (node->next_sibling_clone)
189 node = node->next_sibling_clone;
190 else
192 while (node != orig && !node->next_sibling_clone)
193 node = node->clone_of;
194 if (node != orig)
195 node = node->next_sibling_clone;
198 return false;
201 /* Read the function body for the function associated with NODE. */
203 static void
204 lto_materialize_function (struct cgraph_node *node)
206 tree decl;
208 decl = node->decl;
209 /* Read in functions with body (analyzed nodes)
210 and also functions that are needed to produce virtual clones. */
211 if ((node->has_gimple_body_p () && node->analyzed)
212 || node->used_as_abstract_origin
213 || has_analyzed_clone_p (node))
215 /* Clones don't need to be read. */
216 if (node->clone_of)
217 return;
218 if (DECL_FUNCTION_PERSONALITY (decl) && !first_personality_decl)
219 first_personality_decl = DECL_FUNCTION_PERSONALITY (decl);
222 /* Let the middle end know about the function. */
223 rest_of_decl_compilation (decl, 1, 0);
227 /* Decode the content of memory pointed to by DATA in the in decl
228 state object STATE. DATA_IN points to a data_in structure for
229 decoding. Return the address after the decoded object in the
230 input. */
232 static const uint32_t *
233 lto_read_in_decl_state (struct data_in *data_in, const uint32_t *data,
234 struct lto_in_decl_state *state)
236 uint32_t ix;
237 tree decl;
238 uint32_t i, j;
240 ix = *data++;
241 state->compressed = ix & 1;
242 ix /= 2;
243 decl = streamer_tree_cache_get_tree (data_in->reader_cache, ix);
244 if (!VAR_OR_FUNCTION_DECL_P (decl))
246 gcc_assert (decl == void_type_node);
247 decl = NULL_TREE;
249 state->fn_decl = decl;
251 for (i = 0; i < LTO_N_DECL_STREAMS; i++)
253 uint32_t size = *data++;
254 vec<tree, va_gc> *decls = NULL;
255 vec_alloc (decls, size);
257 for (j = 0; j < size; j++)
258 vec_safe_push (decls,
259 streamer_tree_cache_get_tree (data_in->reader_cache,
260 data[j]));
262 state->streams[i] = decls;
263 data += size;
266 return data;
270 /* Global canonical type table. */
271 static htab_t gimple_canonical_types;
272 static hash_map<const_tree, hashval_t> *canonical_type_hash_cache;
273 static unsigned long num_canonical_type_hash_entries;
274 static unsigned long num_canonical_type_hash_queries;
276 static void iterative_hash_canonical_type (tree type, inchash::hash &hstate);
277 static hashval_t gimple_canonical_type_hash (const void *p);
278 static void gimple_register_canonical_type_1 (tree t, hashval_t hash);
280 /* Returning a hash value for gimple type TYPE.
282 The hash value returned is equal for types considered compatible
283 by gimple_canonical_types_compatible_p. */
285 static hashval_t
286 hash_canonical_type (tree type)
288 inchash::hash hstate;
289 enum tree_code code;
291 /* We compute alias sets only for types that needs them.
292 Be sure we do not recurse to something else as we can not hash incomplete
293 types in a way they would have same hash value as compatible complete
294 types. */
295 gcc_checking_assert (type_with_alias_set_p (type));
297 /* Combine a few common features of types so that types are grouped into
298 smaller sets; when searching for existing matching types to merge,
299 only existing types having the same features as the new type will be
300 checked. */
301 code = tree_code_for_canonical_type_merging (TREE_CODE (type));
302 hstate.add_int (code);
303 hstate.add_int (TYPE_MODE (type));
305 /* Incorporate common features of numerical types. */
306 if (INTEGRAL_TYPE_P (type)
307 || SCALAR_FLOAT_TYPE_P (type)
308 || FIXED_POINT_TYPE_P (type)
309 || TREE_CODE (type) == OFFSET_TYPE
310 || POINTER_TYPE_P (type))
312 hstate.add_int (TYPE_PRECISION (type));
313 if (!type_with_interoperable_signedness (type))
314 hstate.add_int (TYPE_UNSIGNED (type));
317 if (VECTOR_TYPE_P (type))
319 hstate.add_int (TYPE_VECTOR_SUBPARTS (type));
320 hstate.add_int (TYPE_UNSIGNED (type));
323 if (TREE_CODE (type) == COMPLEX_TYPE)
324 hstate.add_int (TYPE_UNSIGNED (type));
326 /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
327 interoperable with "signed char". Unless all frontends are revisited to
328 agree on these types, we must ignore the flag completely. */
330 /* Fortran standard define C_PTR type that is compatible with every
331 C pointer. For this reason we need to glob all pointers into one.
332 Still pointers in different address spaces are not compatible. */
333 if (POINTER_TYPE_P (type))
334 hstate.add_int (TYPE_ADDR_SPACE (TREE_TYPE (type)));
336 /* For array types hash the domain bounds and the string flag. */
337 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type))
339 hstate.add_int (TYPE_STRING_FLAG (type));
340 /* OMP lowering can introduce error_mark_node in place of
341 random local decls in types. */
342 if (TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
343 inchash::add_expr (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), hstate);
344 if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
345 inchash::add_expr (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), hstate);
348 /* Recurse for aggregates with a single element type. */
349 if (TREE_CODE (type) == ARRAY_TYPE
350 || TREE_CODE (type) == COMPLEX_TYPE
351 || TREE_CODE (type) == VECTOR_TYPE)
352 iterative_hash_canonical_type (TREE_TYPE (type), hstate);
354 /* Incorporate function return and argument types. */
355 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
357 unsigned na;
358 tree p;
360 iterative_hash_canonical_type (TREE_TYPE (type), hstate);
362 for (p = TYPE_ARG_TYPES (type), na = 0; p; p = TREE_CHAIN (p))
364 iterative_hash_canonical_type (TREE_VALUE (p), hstate);
365 na++;
368 hstate.add_int (na);
371 if (RECORD_OR_UNION_TYPE_P (type))
373 unsigned nf;
374 tree f;
376 for (f = TYPE_FIELDS (type), nf = 0; f; f = TREE_CHAIN (f))
377 if (TREE_CODE (f) == FIELD_DECL
378 && (! DECL_SIZE (f)
379 || ! integer_zerop (DECL_SIZE (f))))
381 iterative_hash_canonical_type (TREE_TYPE (f), hstate);
382 nf++;
385 hstate.add_int (nf);
388 return hstate.end();
391 /* Returning a hash value for gimple type TYPE combined with VAL. */
393 static void
394 iterative_hash_canonical_type (tree type, inchash::hash &hstate)
396 hashval_t v;
398 /* All type variants have same TYPE_CANONICAL. */
399 type = TYPE_MAIN_VARIANT (type);
401 if (!canonical_type_used_p (type))
402 v = hash_canonical_type (type);
403 /* An already processed type. */
404 else if (TYPE_CANONICAL (type))
406 type = TYPE_CANONICAL (type);
407 v = gimple_canonical_type_hash (type);
409 else
411 /* Canonical types should not be able to form SCCs by design, this
412 recursion is just because we do not register canonical types in
413 optimal order. To avoid quadratic behavior also register the
414 type here. */
415 v = hash_canonical_type (type);
416 gimple_register_canonical_type_1 (type, v);
418 hstate.add_int (v);
421 /* Returns the hash for a canonical type P. */
423 static hashval_t
424 gimple_canonical_type_hash (const void *p)
426 num_canonical_type_hash_queries++;
427 hashval_t *slot = canonical_type_hash_cache->get ((const_tree) p);
428 gcc_assert (slot != NULL);
429 return *slot;
434 /* Returns nonzero if P1 and P2 are equal. */
436 static int
437 gimple_canonical_type_eq (const void *p1, const void *p2)
439 const_tree t1 = (const_tree) p1;
440 const_tree t2 = (const_tree) p2;
441 return gimple_canonical_types_compatible_p (CONST_CAST_TREE (t1),
442 CONST_CAST_TREE (t2));
445 /* Main worker for gimple_register_canonical_type. */
447 static void
448 gimple_register_canonical_type_1 (tree t, hashval_t hash)
450 void **slot;
452 gcc_checking_assert (TYPE_P (t) && !TYPE_CANONICAL (t)
453 && type_with_alias_set_p (t)
454 && canonical_type_used_p (t));
456 slot = htab_find_slot_with_hash (gimple_canonical_types, t, hash, INSERT);
457 if (*slot)
459 tree new_type = (tree)(*slot);
460 gcc_checking_assert (new_type != t);
461 TYPE_CANONICAL (t) = new_type;
463 else
465 TYPE_CANONICAL (t) = t;
466 *slot = (void *) t;
467 /* Cache the just computed hash value. */
468 num_canonical_type_hash_entries++;
469 bool existed_p = canonical_type_hash_cache->put (t, hash);
470 gcc_assert (!existed_p);
474 /* Register type T in the global type table gimple_types and set
475 TYPE_CANONICAL of T accordingly.
476 This is used by LTO to merge structurally equivalent types for
477 type-based aliasing purposes across different TUs and languages.
479 ??? This merging does not exactly match how the tree.c middle-end
480 functions will assign TYPE_CANONICAL when new types are created
481 during optimization (which at least happens for pointer and array
482 types). */
484 static void
485 gimple_register_canonical_type (tree t)
487 if (TYPE_CANONICAL (t) || !type_with_alias_set_p (t)
488 || !canonical_type_used_p (t))
489 return;
491 /* Canonical types are same among all complete variants. */
492 if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (t)))
493 TYPE_CANONICAL (t) = TYPE_CANONICAL (TYPE_MAIN_VARIANT (t));
494 else
496 gimple_register_canonical_type_1 (TYPE_MAIN_VARIANT (t),
497 hash_canonical_type (TYPE_MAIN_VARIANT (t)));
498 TYPE_CANONICAL (t) = TYPE_CANONICAL (TYPE_MAIN_VARIANT (t));
502 /* Re-compute TYPE_CANONICAL for NODE and related types. */
504 static void
505 lto_register_canonical_types (tree node, bool first_p)
507 if (!node
508 || !TYPE_P (node))
509 return;
511 if (first_p)
512 TYPE_CANONICAL (node) = NULL_TREE;
514 if (POINTER_TYPE_P (node)
515 || TREE_CODE (node) == COMPLEX_TYPE
516 || TREE_CODE (node) == ARRAY_TYPE)
517 lto_register_canonical_types (TREE_TYPE (node), first_p);
519 if (!first_p)
520 gimple_register_canonical_type (node);
524 /* Remember trees that contains references to declarations. */
525 static GTY(()) vec <tree, va_gc> *tree_with_vars;
527 #define CHECK_VAR(tt) \
528 do \
530 if ((tt) && VAR_OR_FUNCTION_DECL_P (tt) \
531 && (TREE_PUBLIC (tt) || DECL_EXTERNAL (tt))) \
532 return true; \
533 } while (0)
535 #define CHECK_NO_VAR(tt) \
536 gcc_checking_assert (!(tt) || !VAR_OR_FUNCTION_DECL_P (tt))
538 /* Check presence of pointers to decls in fields of a tree_typed T. */
540 static inline bool
541 mentions_vars_p_typed (tree t)
543 CHECK_NO_VAR (TREE_TYPE (t));
544 return false;
547 /* Check presence of pointers to decls in fields of a tree_common T. */
549 static inline bool
550 mentions_vars_p_common (tree t)
552 if (mentions_vars_p_typed (t))
553 return true;
554 CHECK_NO_VAR (TREE_CHAIN (t));
555 return false;
558 /* Check presence of pointers to decls in fields of a decl_minimal T. */
560 static inline bool
561 mentions_vars_p_decl_minimal (tree t)
563 if (mentions_vars_p_common (t))
564 return true;
565 CHECK_NO_VAR (DECL_NAME (t));
566 CHECK_VAR (DECL_CONTEXT (t));
567 return false;
570 /* Check presence of pointers to decls in fields of a decl_common T. */
572 static inline bool
573 mentions_vars_p_decl_common (tree t)
575 if (mentions_vars_p_decl_minimal (t))
576 return true;
577 CHECK_VAR (DECL_SIZE (t));
578 CHECK_VAR (DECL_SIZE_UNIT (t));
579 CHECK_VAR (DECL_INITIAL (t));
580 CHECK_NO_VAR (DECL_ATTRIBUTES (t));
581 CHECK_VAR (DECL_ABSTRACT_ORIGIN (t));
582 return false;
585 /* Check presence of pointers to decls in fields of a decl_with_vis T. */
587 static inline bool
588 mentions_vars_p_decl_with_vis (tree t)
590 if (mentions_vars_p_decl_common (t))
591 return true;
593 /* Accessor macro has side-effects, use field-name here. */
594 CHECK_NO_VAR (DECL_ASSEMBLER_NAME_RAW (t));
595 return false;
598 /* Check presence of pointers to decls in fields of a decl_non_common T. */
600 static inline bool
601 mentions_vars_p_decl_non_common (tree t)
603 if (mentions_vars_p_decl_with_vis (t))
604 return true;
605 CHECK_NO_VAR (DECL_RESULT_FLD (t));
606 return false;
609 /* Check presence of pointers to decls in fields of a decl_non_common T. */
611 static bool
612 mentions_vars_p_function (tree t)
614 if (mentions_vars_p_decl_non_common (t))
615 return true;
616 CHECK_NO_VAR (DECL_ARGUMENTS (t));
617 CHECK_NO_VAR (DECL_VINDEX (t));
618 CHECK_VAR (DECL_FUNCTION_PERSONALITY (t));
619 return false;
622 /* Check presence of pointers to decls in fields of a field_decl T. */
624 static bool
625 mentions_vars_p_field_decl (tree t)
627 if (mentions_vars_p_decl_common (t))
628 return true;
629 CHECK_VAR (DECL_FIELD_OFFSET (t));
630 CHECK_NO_VAR (DECL_BIT_FIELD_TYPE (t));
631 CHECK_NO_VAR (DECL_QUALIFIER (t));
632 CHECK_NO_VAR (DECL_FIELD_BIT_OFFSET (t));
633 CHECK_NO_VAR (DECL_FCONTEXT (t));
634 return false;
637 /* Check presence of pointers to decls in fields of a type T. */
639 static bool
640 mentions_vars_p_type (tree t)
642 if (mentions_vars_p_common (t))
643 return true;
644 CHECK_NO_VAR (TYPE_CACHED_VALUES (t));
645 CHECK_VAR (TYPE_SIZE (t));
646 CHECK_VAR (TYPE_SIZE_UNIT (t));
647 CHECK_NO_VAR (TYPE_ATTRIBUTES (t));
648 CHECK_NO_VAR (TYPE_NAME (t));
650 CHECK_VAR (TYPE_MIN_VALUE_RAW (t));
651 CHECK_VAR (TYPE_MAX_VALUE_RAW (t));
653 /* Accessor is for derived node types only. */
654 CHECK_NO_VAR (TYPE_LANG_SLOT_1 (t));
656 CHECK_VAR (TYPE_CONTEXT (t));
657 CHECK_NO_VAR (TYPE_CANONICAL (t));
658 CHECK_NO_VAR (TYPE_MAIN_VARIANT (t));
659 CHECK_NO_VAR (TYPE_NEXT_VARIANT (t));
660 return false;
663 /* Check presence of pointers to decls in fields of a BINFO T. */
665 static bool
666 mentions_vars_p_binfo (tree t)
668 unsigned HOST_WIDE_INT i, n;
670 if (mentions_vars_p_common (t))
671 return true;
672 CHECK_VAR (BINFO_VTABLE (t));
673 CHECK_NO_VAR (BINFO_OFFSET (t));
674 CHECK_NO_VAR (BINFO_VIRTUALS (t));
675 CHECK_NO_VAR (BINFO_VPTR_FIELD (t));
676 n = vec_safe_length (BINFO_BASE_ACCESSES (t));
677 for (i = 0; i < n; i++)
678 CHECK_NO_VAR (BINFO_BASE_ACCESS (t, i));
679 /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX
680 and BINFO_VPTR_INDEX; these are used by C++ FE only. */
681 n = BINFO_N_BASE_BINFOS (t);
682 for (i = 0; i < n; i++)
683 CHECK_NO_VAR (BINFO_BASE_BINFO (t, i));
684 return false;
687 /* Check presence of pointers to decls in fields of a CONSTRUCTOR T. */
689 static bool
690 mentions_vars_p_constructor (tree t)
692 unsigned HOST_WIDE_INT idx;
693 constructor_elt *ce;
695 if (mentions_vars_p_typed (t))
696 return true;
698 for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce); idx++)
700 CHECK_NO_VAR (ce->index);
701 CHECK_VAR (ce->value);
703 return false;
706 /* Check presence of pointers to decls in fields of an expression tree T. */
708 static bool
709 mentions_vars_p_expr (tree t)
711 int i;
712 if (mentions_vars_p_typed (t))
713 return true;
714 for (i = TREE_OPERAND_LENGTH (t) - 1; i >= 0; --i)
715 CHECK_VAR (TREE_OPERAND (t, i));
716 return false;
719 /* Check presence of pointers to decls in fields of an OMP_CLAUSE T. */
721 static bool
722 mentions_vars_p_omp_clause (tree t)
724 int i;
725 if (mentions_vars_p_common (t))
726 return true;
727 for (i = omp_clause_num_ops[OMP_CLAUSE_CODE (t)] - 1; i >= 0; --i)
728 CHECK_VAR (OMP_CLAUSE_OPERAND (t, i));
729 return false;
732 /* Check presence of pointers to decls that needs later fixup in T. */
734 static bool
735 mentions_vars_p (tree t)
737 switch (TREE_CODE (t))
739 case IDENTIFIER_NODE:
740 break;
742 case TREE_LIST:
743 CHECK_VAR (TREE_VALUE (t));
744 CHECK_VAR (TREE_PURPOSE (t));
745 CHECK_NO_VAR (TREE_CHAIN (t));
746 break;
748 case FIELD_DECL:
749 return mentions_vars_p_field_decl (t);
751 case LABEL_DECL:
752 case CONST_DECL:
753 case PARM_DECL:
754 case RESULT_DECL:
755 case IMPORTED_DECL:
756 case NAMESPACE_DECL:
757 case NAMELIST_DECL:
758 return mentions_vars_p_decl_common (t);
760 case VAR_DECL:
761 return mentions_vars_p_decl_with_vis (t);
763 case TYPE_DECL:
764 return mentions_vars_p_decl_non_common (t);
766 case FUNCTION_DECL:
767 return mentions_vars_p_function (t);
769 case TREE_BINFO:
770 return mentions_vars_p_binfo (t);
772 case PLACEHOLDER_EXPR:
773 return mentions_vars_p_common (t);
775 case BLOCK:
776 case TRANSLATION_UNIT_DECL:
777 case OPTIMIZATION_NODE:
778 case TARGET_OPTION_NODE:
779 break;
781 case CONSTRUCTOR:
782 return mentions_vars_p_constructor (t);
784 case OMP_CLAUSE:
785 return mentions_vars_p_omp_clause (t);
787 default:
788 if (TYPE_P (t))
790 if (mentions_vars_p_type (t))
791 return true;
793 else if (EXPR_P (t))
795 if (mentions_vars_p_expr (t))
796 return true;
798 else if (CONSTANT_CLASS_P (t))
799 CHECK_NO_VAR (TREE_TYPE (t));
800 else
801 gcc_unreachable ();
803 return false;
807 /* Return the resolution for the decl with index INDEX from DATA_IN. */
809 static enum ld_plugin_symbol_resolution
810 get_resolution (struct data_in *data_in, unsigned index)
812 if (data_in->globals_resolution.exists ())
814 ld_plugin_symbol_resolution_t ret;
815 /* We can have references to not emitted functions in
816 DECL_FUNCTION_PERSONALITY at least. So we can and have
817 to indeed return LDPR_UNKNOWN in some cases. */
818 if (data_in->globals_resolution.length () <= index)
819 return LDPR_UNKNOWN;
820 ret = data_in->globals_resolution[index];
821 return ret;
823 else
824 /* Delay resolution finding until decl merging. */
825 return LDPR_UNKNOWN;
828 /* We need to record resolutions until symbol table is read. */
829 static void
830 register_resolution (struct lto_file_decl_data *file_data, tree decl,
831 enum ld_plugin_symbol_resolution resolution)
833 if (resolution == LDPR_UNKNOWN)
834 return;
835 if (!file_data->resolution_map)
836 file_data->resolution_map
837 = new hash_map<tree, ld_plugin_symbol_resolution>;
838 file_data->resolution_map->put (decl, resolution);
841 /* Register DECL with the global symbol table and change its
842 name if necessary to avoid name clashes for static globals across
843 different files. */
845 static void
846 lto_register_var_decl_in_symtab (struct data_in *data_in, tree decl,
847 unsigned ix)
849 tree context;
851 /* Variable has file scope, not local. */
852 if (!TREE_PUBLIC (decl)
853 && !((context = decl_function_context (decl))
854 && auto_var_in_fn_p (decl, context)))
855 rest_of_decl_compilation (decl, 1, 0);
857 /* If this variable has already been declared, queue the
858 declaration for merging. */
859 if (TREE_PUBLIC (decl))
860 register_resolution (data_in->file_data,
861 decl, get_resolution (data_in, ix));
865 /* Register DECL with the global symbol table and change its
866 name if necessary to avoid name clashes for static globals across
867 different files. DATA_IN contains descriptors and tables for the
868 file being read. */
870 static void
871 lto_register_function_decl_in_symtab (struct data_in *data_in, tree decl,
872 unsigned ix)
874 /* If this variable has already been declared, queue the
875 declaration for merging. */
876 if (TREE_PUBLIC (decl) && !DECL_ABSTRACT_P (decl))
877 register_resolution (data_in->file_data,
878 decl, get_resolution (data_in, ix));
882 /* For the type T re-materialize it in the type variant list and
883 the pointer/reference-to chains. */
885 static void
886 lto_fixup_prevailing_type (tree t)
888 /* The following re-creates proper variant lists while fixing up
889 the variant leaders. We do not stream TYPE_NEXT_VARIANT so the
890 variant list state before fixup is broken. */
892 /* If we are not our own variant leader link us into our new leaders
893 variant list. */
894 if (TYPE_MAIN_VARIANT (t) != t)
896 tree mv = TYPE_MAIN_VARIANT (t);
897 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
898 TYPE_NEXT_VARIANT (mv) = t;
901 /* The following reconstructs the pointer chains
902 of the new pointed-to type if we are a main variant. We do
903 not stream those so they are broken before fixup. */
904 if (TREE_CODE (t) == POINTER_TYPE
905 && TYPE_MAIN_VARIANT (t) == t)
907 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (TREE_TYPE (t));
908 TYPE_POINTER_TO (TREE_TYPE (t)) = t;
910 else if (TREE_CODE (t) == REFERENCE_TYPE
911 && TYPE_MAIN_VARIANT (t) == t)
913 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (TREE_TYPE (t));
914 TYPE_REFERENCE_TO (TREE_TYPE (t)) = t;
919 /* We keep prevailing tree SCCs in a hashtable with manual collision
920 handling (in case all hashes compare the same) and keep the colliding
921 entries in the tree_scc->next chain. */
923 struct tree_scc
925 tree_scc *next;
926 /* Hash of the whole SCC. */
927 hashval_t hash;
928 /* Number of trees in the SCC. */
929 unsigned len;
930 /* Number of possible entries into the SCC (tree nodes [0..entry_len-1]
931 which share the same individual tree hash). */
932 unsigned entry_len;
933 /* The members of the SCC.
934 We only need to remember the first entry node candidate for prevailing
935 SCCs (but of course have access to all entries for SCCs we are
936 processing).
937 ??? For prevailing SCCs we really only need hash and the first
938 entry candidate, but that's too awkward to implement. */
939 tree entries[1];
942 struct tree_scc_hasher : nofree_ptr_hash <tree_scc>
944 static inline hashval_t hash (const tree_scc *);
945 static inline bool equal (const tree_scc *, const tree_scc *);
948 hashval_t
949 tree_scc_hasher::hash (const tree_scc *scc)
951 return scc->hash;
954 bool
955 tree_scc_hasher::equal (const tree_scc *scc1, const tree_scc *scc2)
957 if (scc1->hash != scc2->hash
958 || scc1->len != scc2->len
959 || scc1->entry_len != scc2->entry_len)
960 return false;
961 return true;
964 static hash_table<tree_scc_hasher> *tree_scc_hash;
965 static struct obstack tree_scc_hash_obstack;
967 static unsigned long num_merged_types;
968 static unsigned long num_prevailing_types;
969 static unsigned long num_type_scc_trees;
970 static unsigned long total_scc_size;
971 static unsigned long num_sccs_read;
972 static unsigned long total_scc_size_merged;
973 static unsigned long num_sccs_merged;
974 static unsigned long num_scc_compares;
975 static unsigned long num_scc_compare_collisions;
978 /* Compare the two entries T1 and T2 of two SCCs that are possibly equal,
979 recursing through in-SCC tree edges. Returns true if the SCCs entered
980 through T1 and T2 are equal and fills in *MAP with the pairs of
981 SCC entries we visited, starting with (*MAP)[0] = T1 and (*MAP)[1] = T2. */
983 static bool
984 compare_tree_sccs_1 (tree t1, tree t2, tree **map)
986 enum tree_code code;
988 /* Mark already visited nodes. */
989 TREE_ASM_WRITTEN (t2) = 1;
991 /* Push the pair onto map. */
992 (*map)[0] = t1;
993 (*map)[1] = t2;
994 *map = *map + 2;
996 /* Compare value-fields. */
997 #define compare_values(X) \
998 do { \
999 if (X(t1) != X(t2)) \
1000 return false; \
1001 } while (0)
1003 compare_values (TREE_CODE);
1004 code = TREE_CODE (t1);
1006 if (!TYPE_P (t1))
1008 compare_values (TREE_SIDE_EFFECTS);
1009 compare_values (TREE_CONSTANT);
1010 compare_values (TREE_READONLY);
1011 compare_values (TREE_PUBLIC);
1013 compare_values (TREE_ADDRESSABLE);
1014 compare_values (TREE_THIS_VOLATILE);
1015 if (DECL_P (t1))
1016 compare_values (DECL_UNSIGNED);
1017 else if (TYPE_P (t1))
1018 compare_values (TYPE_UNSIGNED);
1019 if (TYPE_P (t1))
1020 compare_values (TYPE_ARTIFICIAL);
1021 else
1022 compare_values (TREE_NO_WARNING);
1023 compare_values (TREE_NOTHROW);
1024 compare_values (TREE_STATIC);
1025 if (code != TREE_BINFO)
1026 compare_values (TREE_PRIVATE);
1027 compare_values (TREE_PROTECTED);
1028 compare_values (TREE_DEPRECATED);
1029 if (TYPE_P (t1))
1031 if (AGGREGATE_TYPE_P (t1))
1032 compare_values (TYPE_REVERSE_STORAGE_ORDER);
1033 else
1034 compare_values (TYPE_SATURATING);
1035 compare_values (TYPE_ADDR_SPACE);
1037 else if (code == SSA_NAME)
1038 compare_values (SSA_NAME_IS_DEFAULT_DEF);
1040 if (CODE_CONTAINS_STRUCT (code, TS_INT_CST))
1042 if (wi::to_wide (t1) != wi::to_wide (t2))
1043 return false;
1046 if (CODE_CONTAINS_STRUCT (code, TS_REAL_CST))
1048 /* ??? No suitable compare routine available. */
1049 REAL_VALUE_TYPE r1 = TREE_REAL_CST (t1);
1050 REAL_VALUE_TYPE r2 = TREE_REAL_CST (t2);
1051 if (r1.cl != r2.cl
1052 || r1.decimal != r2.decimal
1053 || r1.sign != r2.sign
1054 || r1.signalling != r2.signalling
1055 || r1.canonical != r2.canonical
1056 || r1.uexp != r2.uexp)
1057 return false;
1058 for (unsigned i = 0; i < SIGSZ; ++i)
1059 if (r1.sig[i] != r2.sig[i])
1060 return false;
1063 if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST))
1064 if (!fixed_compare (EQ_EXPR,
1065 TREE_FIXED_CST_PTR (t1), TREE_FIXED_CST_PTR (t2)))
1066 return false;
1068 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1070 compare_values (DECL_MODE);
1071 compare_values (DECL_NONLOCAL);
1072 compare_values (DECL_VIRTUAL_P);
1073 compare_values (DECL_IGNORED_P);
1074 compare_values (DECL_ABSTRACT_P);
1075 compare_values (DECL_ARTIFICIAL);
1076 compare_values (DECL_USER_ALIGN);
1077 compare_values (DECL_PRESERVE_P);
1078 compare_values (DECL_EXTERNAL);
1079 compare_values (DECL_GIMPLE_REG_P);
1080 compare_values (DECL_ALIGN);
1081 if (code == LABEL_DECL)
1083 compare_values (EH_LANDING_PAD_NR);
1084 compare_values (LABEL_DECL_UID);
1086 else if (code == FIELD_DECL)
1088 compare_values (DECL_PACKED);
1089 compare_values (DECL_NONADDRESSABLE_P);
1090 compare_values (DECL_PADDING_P);
1091 compare_values (DECL_OFFSET_ALIGN);
1093 else if (code == VAR_DECL)
1095 compare_values (DECL_HAS_DEBUG_EXPR_P);
1096 compare_values (DECL_NONLOCAL_FRAME);
1098 if (code == RESULT_DECL
1099 || code == PARM_DECL
1100 || code == VAR_DECL)
1102 compare_values (DECL_BY_REFERENCE);
1103 if (code == VAR_DECL
1104 || code == PARM_DECL)
1105 compare_values (DECL_HAS_VALUE_EXPR_P);
1109 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
1110 compare_values (DECL_REGISTER);
1112 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1114 compare_values (DECL_COMMON);
1115 compare_values (DECL_DLLIMPORT_P);
1116 compare_values (DECL_WEAK);
1117 compare_values (DECL_SEEN_IN_BIND_EXPR_P);
1118 compare_values (DECL_COMDAT);
1119 compare_values (DECL_VISIBILITY);
1120 compare_values (DECL_VISIBILITY_SPECIFIED);
1121 if (code == VAR_DECL)
1123 compare_values (DECL_HARD_REGISTER);
1124 /* DECL_IN_TEXT_SECTION is set during final asm output only. */
1125 compare_values (DECL_IN_CONSTANT_POOL);
1129 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1131 compare_values (DECL_BUILT_IN_CLASS);
1132 compare_values (DECL_STATIC_CONSTRUCTOR);
1133 compare_values (DECL_STATIC_DESTRUCTOR);
1134 compare_values (DECL_UNINLINABLE);
1135 compare_values (DECL_POSSIBLY_INLINED);
1136 compare_values (DECL_IS_NOVOPS);
1137 compare_values (DECL_IS_RETURNS_TWICE);
1138 compare_values (DECL_IS_MALLOC);
1139 compare_values (DECL_IS_OPERATOR_NEW);
1140 compare_values (DECL_DECLARED_INLINE_P);
1141 compare_values (DECL_STATIC_CHAIN);
1142 compare_values (DECL_NO_INLINE_WARNING_P);
1143 compare_values (DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT);
1144 compare_values (DECL_NO_LIMIT_STACK);
1145 compare_values (DECL_DISREGARD_INLINE_LIMITS);
1146 compare_values (DECL_PURE_P);
1147 compare_values (DECL_LOOPING_CONST_OR_PURE_P);
1148 compare_values (DECL_FINAL_P);
1149 compare_values (DECL_CXX_CONSTRUCTOR_P);
1150 compare_values (DECL_CXX_DESTRUCTOR_P);
1151 if (DECL_BUILT_IN_CLASS (t1) != NOT_BUILT_IN)
1152 compare_values (DECL_FUNCTION_CODE);
1155 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
1157 compare_values (TYPE_MODE);
1158 compare_values (TYPE_STRING_FLAG);
1159 compare_values (TYPE_NEEDS_CONSTRUCTING);
1160 if (RECORD_OR_UNION_TYPE_P (t1))
1162 compare_values (TYPE_TRANSPARENT_AGGR);
1163 compare_values (TYPE_FINAL_P);
1165 else if (code == ARRAY_TYPE)
1166 compare_values (TYPE_NONALIASED_COMPONENT);
1167 if (AGGREGATE_TYPE_P (t1))
1168 compare_values (TYPE_TYPELESS_STORAGE);
1169 compare_values (TYPE_EMPTY_P);
1170 compare_values (TYPE_PACKED);
1171 compare_values (TYPE_RESTRICT);
1172 compare_values (TYPE_USER_ALIGN);
1173 compare_values (TYPE_READONLY);
1174 compare_values (TYPE_PRECISION);
1175 compare_values (TYPE_ALIGN);
1176 /* Do not compare TYPE_ALIAS_SET. Doing so introduce ordering issues
1177 with calls to get_alias_set which may initialize it for streamed
1178 in types. */
1181 /* We don't want to compare locations, so there is nothing do compare
1182 for TS_EXP. */
1184 /* BLOCKs are function local and we don't merge anything there, so
1185 simply refuse to merge. */
1186 if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
1187 return false;
1189 if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
1190 if (strcmp (TRANSLATION_UNIT_LANGUAGE (t1),
1191 TRANSLATION_UNIT_LANGUAGE (t2)) != 0)
1192 return false;
1194 if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION))
1195 if (!cl_target_option_eq (TREE_TARGET_OPTION (t1), TREE_TARGET_OPTION (t2)))
1196 return false;
1198 if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
1199 if (memcmp (TREE_OPTIMIZATION (t1), TREE_OPTIMIZATION (t2),
1200 sizeof (struct cl_optimization)) != 0)
1201 return false;
1203 if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
1204 if (vec_safe_length (BINFO_BASE_ACCESSES (t1))
1205 != vec_safe_length (BINFO_BASE_ACCESSES (t2)))
1206 return false;
1208 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1209 compare_values (CONSTRUCTOR_NELTS);
1211 if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
1212 if (IDENTIFIER_LENGTH (t1) != IDENTIFIER_LENGTH (t2)
1213 || memcmp (IDENTIFIER_POINTER (t1), IDENTIFIER_POINTER (t2),
1214 IDENTIFIER_LENGTH (t1)) != 0)
1215 return false;
1217 if (CODE_CONTAINS_STRUCT (code, TS_STRING))
1218 if (TREE_STRING_LENGTH (t1) != TREE_STRING_LENGTH (t2)
1219 || memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
1220 TREE_STRING_LENGTH (t1)) != 0)
1221 return false;
1223 if (code == OMP_CLAUSE)
1225 compare_values (OMP_CLAUSE_CODE);
1226 switch (OMP_CLAUSE_CODE (t1))
1228 case OMP_CLAUSE_DEFAULT:
1229 compare_values (OMP_CLAUSE_DEFAULT_KIND);
1230 break;
1231 case OMP_CLAUSE_SCHEDULE:
1232 compare_values (OMP_CLAUSE_SCHEDULE_KIND);
1233 break;
1234 case OMP_CLAUSE_DEPEND:
1235 compare_values (OMP_CLAUSE_DEPEND_KIND);
1236 break;
1237 case OMP_CLAUSE_MAP:
1238 compare_values (OMP_CLAUSE_MAP_KIND);
1239 break;
1240 case OMP_CLAUSE_PROC_BIND:
1241 compare_values (OMP_CLAUSE_PROC_BIND_KIND);
1242 break;
1243 case OMP_CLAUSE_REDUCTION:
1244 compare_values (OMP_CLAUSE_REDUCTION_CODE);
1245 compare_values (OMP_CLAUSE_REDUCTION_GIMPLE_INIT);
1246 compare_values (OMP_CLAUSE_REDUCTION_GIMPLE_MERGE);
1247 break;
1248 default:
1249 break;
1253 #undef compare_values
1256 /* Compare pointer fields. */
1258 /* Recurse. Search & Replaced from DFS_write_tree_body.
1259 Folding the early checks into the compare_tree_edges recursion
1260 macro makes debugging way quicker as you are able to break on
1261 compare_tree_sccs_1 and simply finish until a call returns false
1262 to spot the SCC members with the difference. */
1263 #define compare_tree_edges(E1, E2) \
1264 do { \
1265 tree t1_ = (E1), t2_ = (E2); \
1266 if (t1_ != t2_ \
1267 && (!t1_ || !t2_ \
1268 || !TREE_VISITED (t2_) \
1269 || (!TREE_ASM_WRITTEN (t2_) \
1270 && !compare_tree_sccs_1 (t1_, t2_, map)))) \
1271 return false; \
1272 /* Only non-NULL trees outside of the SCC may compare equal. */ \
1273 gcc_checking_assert (t1_ != t2_ || (!t2_ || !TREE_VISITED (t2_))); \
1274 } while (0)
1276 if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
1278 if (code != IDENTIFIER_NODE)
1279 compare_tree_edges (TREE_TYPE (t1), TREE_TYPE (t2));
1282 if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
1284 unsigned i;
1285 /* Note that the number of elements for EXPR has already been emitted
1286 in EXPR's header (see streamer_write_tree_header). */
1287 for (i = 0; i < VECTOR_CST_NELTS (t1); ++i)
1288 compare_tree_edges (VECTOR_CST_ELT (t1, i), VECTOR_CST_ELT (t2, i));
1291 if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
1293 compare_tree_edges (TREE_REALPART (t1), TREE_REALPART (t2));
1294 compare_tree_edges (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
1297 if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
1299 compare_tree_edges (DECL_NAME (t1), DECL_NAME (t2));
1300 /* ??? Global decls from different TUs have non-matching
1301 TRANSLATION_UNIT_DECLs. Only consider a small set of
1302 decls equivalent, we should not end up merging others. */
1303 if ((code == TYPE_DECL
1304 || code == NAMESPACE_DECL
1305 || code == IMPORTED_DECL
1306 || code == CONST_DECL
1307 || (VAR_OR_FUNCTION_DECL_P (t1)
1308 && (TREE_PUBLIC (t1) || DECL_EXTERNAL (t1))))
1309 && DECL_FILE_SCOPE_P (t1) && DECL_FILE_SCOPE_P (t2))
1311 else
1312 compare_tree_edges (DECL_CONTEXT (t1), DECL_CONTEXT (t2));
1315 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1317 compare_tree_edges (DECL_SIZE (t1), DECL_SIZE (t2));
1318 compare_tree_edges (DECL_SIZE_UNIT (t1), DECL_SIZE_UNIT (t2));
1319 compare_tree_edges (DECL_ATTRIBUTES (t1), DECL_ATTRIBUTES (t2));
1320 compare_tree_edges (DECL_ABSTRACT_ORIGIN (t1), DECL_ABSTRACT_ORIGIN (t2));
1321 if ((code == VAR_DECL
1322 || code == PARM_DECL)
1323 && DECL_HAS_VALUE_EXPR_P (t1))
1324 compare_tree_edges (DECL_VALUE_EXPR (t1), DECL_VALUE_EXPR (t2));
1325 if (code == VAR_DECL
1326 && DECL_HAS_DEBUG_EXPR_P (t1))
1327 compare_tree_edges (DECL_DEBUG_EXPR (t1), DECL_DEBUG_EXPR (t2));
1328 /* LTO specific edges. */
1329 if (code != FUNCTION_DECL
1330 && code != TRANSLATION_UNIT_DECL)
1331 compare_tree_edges (DECL_INITIAL (t1), DECL_INITIAL (t2));
1334 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
1336 if (code == FUNCTION_DECL)
1338 tree a1, a2;
1339 for (a1 = DECL_ARGUMENTS (t1), a2 = DECL_ARGUMENTS (t2);
1340 a1 || a2;
1341 a1 = TREE_CHAIN (a1), a2 = TREE_CHAIN (a2))
1342 compare_tree_edges (a1, a2);
1343 compare_tree_edges (DECL_RESULT (t1), DECL_RESULT (t2));
1345 else if (code == TYPE_DECL)
1346 compare_tree_edges (DECL_ORIGINAL_TYPE (t1), DECL_ORIGINAL_TYPE (t2));
1349 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
1351 /* Make sure we don't inadvertently set the assembler name. */
1352 if (DECL_ASSEMBLER_NAME_SET_P (t1))
1353 compare_tree_edges (DECL_ASSEMBLER_NAME (t1),
1354 DECL_ASSEMBLER_NAME (t2));
1357 if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
1359 compare_tree_edges (DECL_FIELD_OFFSET (t1), DECL_FIELD_OFFSET (t2));
1360 compare_tree_edges (DECL_BIT_FIELD_TYPE (t1), DECL_BIT_FIELD_TYPE (t2));
1361 compare_tree_edges (DECL_BIT_FIELD_REPRESENTATIVE (t1),
1362 DECL_BIT_FIELD_REPRESENTATIVE (t2));
1363 compare_tree_edges (DECL_FIELD_BIT_OFFSET (t1),
1364 DECL_FIELD_BIT_OFFSET (t2));
1365 compare_tree_edges (DECL_FCONTEXT (t1), DECL_FCONTEXT (t2));
1368 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
1370 compare_tree_edges (DECL_FUNCTION_PERSONALITY (t1),
1371 DECL_FUNCTION_PERSONALITY (t2));
1372 compare_tree_edges (DECL_VINDEX (t1), DECL_VINDEX (t2));
1373 compare_tree_edges (DECL_FUNCTION_SPECIFIC_TARGET (t1),
1374 DECL_FUNCTION_SPECIFIC_TARGET (t2));
1375 compare_tree_edges (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (t1),
1376 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (t2));
1379 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
1381 compare_tree_edges (TYPE_SIZE (t1), TYPE_SIZE (t2));
1382 compare_tree_edges (TYPE_SIZE_UNIT (t1), TYPE_SIZE_UNIT (t2));
1383 compare_tree_edges (TYPE_ATTRIBUTES (t1), TYPE_ATTRIBUTES (t2));
1384 compare_tree_edges (TYPE_NAME (t1), TYPE_NAME (t2));
1385 /* Do not compare TYPE_POINTER_TO or TYPE_REFERENCE_TO. They will be
1386 reconstructed during fixup. */
1387 /* Do not compare TYPE_NEXT_VARIANT, we reconstruct the variant lists
1388 during fixup. */
1389 compare_tree_edges (TYPE_MAIN_VARIANT (t1), TYPE_MAIN_VARIANT (t2));
1390 /* ??? Global types from different TUs have non-matching
1391 TRANSLATION_UNIT_DECLs. Still merge them if they are otherwise
1392 equal. */
1393 if (TYPE_FILE_SCOPE_P (t1) && TYPE_FILE_SCOPE_P (t2))
1395 else
1396 compare_tree_edges (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2));
1397 /* TYPE_CANONICAL is re-computed during type merging, so do not
1398 compare it here. */
1399 compare_tree_edges (TYPE_STUB_DECL (t1), TYPE_STUB_DECL (t2));
1402 if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
1404 if (code == ENUMERAL_TYPE)
1405 compare_tree_edges (TYPE_VALUES (t1), TYPE_VALUES (t2));
1406 else if (code == ARRAY_TYPE)
1407 compare_tree_edges (TYPE_DOMAIN (t1), TYPE_DOMAIN (t2));
1408 else if (RECORD_OR_UNION_TYPE_P (t1))
1410 tree f1, f2;
1411 for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
1412 f1 || f2;
1413 f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
1414 compare_tree_edges (f1, f2);
1416 else if (code == FUNCTION_TYPE
1417 || code == METHOD_TYPE)
1418 compare_tree_edges (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2));
1420 if (!POINTER_TYPE_P (t1))
1421 compare_tree_edges (TYPE_MIN_VALUE_RAW (t1), TYPE_MIN_VALUE_RAW (t2));
1422 compare_tree_edges (TYPE_MAX_VALUE_RAW (t1), TYPE_MAX_VALUE_RAW (t2));
1425 if (CODE_CONTAINS_STRUCT (code, TS_LIST))
1427 compare_tree_edges (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
1428 compare_tree_edges (TREE_VALUE (t1), TREE_VALUE (t2));
1429 compare_tree_edges (TREE_CHAIN (t1), TREE_CHAIN (t2));
1432 if (CODE_CONTAINS_STRUCT (code, TS_VEC))
1433 for (int i = 0; i < TREE_VEC_LENGTH (t1); i++)
1434 compare_tree_edges (TREE_VEC_ELT (t1, i), TREE_VEC_ELT (t2, i));
1436 if (CODE_CONTAINS_STRUCT (code, TS_EXP))
1438 for (int i = 0; i < TREE_OPERAND_LENGTH (t1); i++)
1439 compare_tree_edges (TREE_OPERAND (t1, i),
1440 TREE_OPERAND (t2, i));
1442 /* BLOCKs are function local and we don't merge anything there. */
1443 if (TREE_BLOCK (t1) || TREE_BLOCK (t2))
1444 return false;
1447 if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
1449 unsigned i;
1450 tree t;
1451 /* Lengths have already been compared above. */
1452 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (t1), i, t)
1453 compare_tree_edges (t, BINFO_BASE_BINFO (t2, i));
1454 FOR_EACH_VEC_SAFE_ELT (BINFO_BASE_ACCESSES (t1), i, t)
1455 compare_tree_edges (t, BINFO_BASE_ACCESS (t2, i));
1456 compare_tree_edges (BINFO_OFFSET (t1), BINFO_OFFSET (t2));
1457 compare_tree_edges (BINFO_VTABLE (t1), BINFO_VTABLE (t2));
1458 compare_tree_edges (BINFO_VPTR_FIELD (t1), BINFO_VPTR_FIELD (t2));
1459 /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX
1460 and BINFO_VPTR_INDEX; these are used by C++ FE only. */
1463 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1465 unsigned i;
1466 tree index, value;
1467 /* Lengths have already been compared above. */
1468 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, index, value)
1470 compare_tree_edges (index, CONSTRUCTOR_ELT (t2, i)->index);
1471 compare_tree_edges (value, CONSTRUCTOR_ELT (t2, i)->value);
1475 if (code == OMP_CLAUSE)
1477 int i;
1479 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (t1)]; i++)
1480 compare_tree_edges (OMP_CLAUSE_OPERAND (t1, i),
1481 OMP_CLAUSE_OPERAND (t2, i));
1482 compare_tree_edges (OMP_CLAUSE_CHAIN (t1), OMP_CLAUSE_CHAIN (t2));
1485 #undef compare_tree_edges
1487 return true;
1490 /* Compare the tree scc SCC to the prevailing candidate PSCC, filling
1491 out MAP if they are equal. */
1493 static bool
1494 compare_tree_sccs (tree_scc *pscc, tree_scc *scc,
1495 tree *map)
1497 /* Assume SCC entry hashes are sorted after their cardinality. Which
1498 means we can simply take the first n-tuple of equal hashes
1499 (which is recorded as entry_len) and do n SCC entry candidate
1500 comparisons. */
1501 for (unsigned i = 0; i < pscc->entry_len; ++i)
1503 tree *mapp = map;
1504 num_scc_compare_collisions++;
1505 if (compare_tree_sccs_1 (pscc->entries[0], scc->entries[i], &mapp))
1507 /* Equal - no need to reset TREE_VISITED or TREE_ASM_WRITTEN
1508 on the scc as all trees will be freed. */
1509 return true;
1511 /* Reset TREE_ASM_WRITTEN on scc for the next compare or in case
1512 the SCC prevails. */
1513 for (unsigned j = 0; j < scc->len; ++j)
1514 TREE_ASM_WRITTEN (scc->entries[j]) = 0;
1517 return false;
1520 /* QSort sort function to sort a map of two pointers after the 2nd
1521 pointer. */
1523 static int
1524 cmp_tree (const void *p1_, const void *p2_)
1526 tree *p1 = (tree *)(const_cast<void *>(p1_));
1527 tree *p2 = (tree *)(const_cast<void *>(p2_));
1528 if (p1[1] == p2[1])
1529 return 0;
1530 return ((uintptr_t)p1[1] < (uintptr_t)p2[1]) ? -1 : 1;
1533 /* Try to unify the SCC with nodes FROM to FROM + LEN in CACHE and
1534 hash value SCC_HASH with an already recorded SCC. Return true if
1535 that was successful, otherwise return false. */
1537 static bool
1538 unify_scc (struct data_in *data_in, unsigned from,
1539 unsigned len, unsigned scc_entry_len, hashval_t scc_hash)
1541 bool unified_p = false;
1542 struct streamer_tree_cache_d *cache = data_in->reader_cache;
1543 tree_scc *scc
1544 = (tree_scc *) alloca (sizeof (tree_scc) + (len - 1) * sizeof (tree));
1545 scc->next = NULL;
1546 scc->hash = scc_hash;
1547 scc->len = len;
1548 scc->entry_len = scc_entry_len;
1549 for (unsigned i = 0; i < len; ++i)
1551 tree t = streamer_tree_cache_get_tree (cache, from + i);
1552 scc->entries[i] = t;
1553 /* Do not merge SCCs with local entities inside them. Also do
1554 not merge TRANSLATION_UNIT_DECLs. */
1555 if (TREE_CODE (t) == TRANSLATION_UNIT_DECL
1556 || (VAR_OR_FUNCTION_DECL_P (t)
1557 && !(TREE_PUBLIC (t) || DECL_EXTERNAL (t)))
1558 || TREE_CODE (t) == LABEL_DECL)
1560 /* Avoid doing any work for these cases and do not worry to
1561 record the SCCs for further merging. */
1562 return false;
1566 /* Look for the list of candidate SCCs to compare against. */
1567 tree_scc **slot;
1568 slot = tree_scc_hash->find_slot_with_hash (scc, scc_hash, INSERT);
1569 if (*slot)
1571 /* Try unifying against each candidate. */
1572 num_scc_compares++;
1574 /* Set TREE_VISITED on the scc so we can easily identify tree nodes
1575 outside of the scc when following tree edges. Make sure
1576 that TREE_ASM_WRITTEN is unset so we can use it as 2nd bit
1577 to track whether we visited the SCC member during the compare.
1578 We cannot use TREE_VISITED on the pscc members as the extended
1579 scc and pscc can overlap. */
1580 for (unsigned i = 0; i < scc->len; ++i)
1582 TREE_VISITED (scc->entries[i]) = 1;
1583 gcc_checking_assert (!TREE_ASM_WRITTEN (scc->entries[i]));
1586 tree *map = XALLOCAVEC (tree, 2 * len);
1587 for (tree_scc *pscc = *slot; pscc; pscc = pscc->next)
1589 if (!compare_tree_sccs (pscc, scc, map))
1590 continue;
1592 /* Found an equal SCC. */
1593 unified_p = true;
1594 num_scc_compare_collisions--;
1595 num_sccs_merged++;
1596 total_scc_size_merged += len;
1598 if (flag_checking)
1599 for (unsigned i = 0; i < len; ++i)
1601 tree t = map[2*i+1];
1602 enum tree_code code = TREE_CODE (t);
1603 /* IDENTIFIER_NODEs should be singletons and are merged by the
1604 streamer. The others should be singletons, too, and we
1605 should not merge them in any way. */
1606 gcc_assert (code != TRANSLATION_UNIT_DECL
1607 && code != IDENTIFIER_NODE);
1610 /* Fixup the streamer cache with the prevailing nodes according
1611 to the tree node mapping computed by compare_tree_sccs. */
1612 if (len == 1)
1613 streamer_tree_cache_replace_tree (cache, pscc->entries[0], from);
1614 else
1616 tree *map2 = XALLOCAVEC (tree, 2 * len);
1617 for (unsigned i = 0; i < len; ++i)
1619 map2[i*2] = (tree)(uintptr_t)(from + i);
1620 map2[i*2+1] = scc->entries[i];
1622 qsort (map2, len, 2 * sizeof (tree), cmp_tree);
1623 qsort (map, len, 2 * sizeof (tree), cmp_tree);
1624 for (unsigned i = 0; i < len; ++i)
1625 streamer_tree_cache_replace_tree (cache, map[2*i],
1626 (uintptr_t)map2[2*i]);
1629 /* Free the tree nodes from the read SCC. */
1630 data_in->location_cache.revert_location_cache ();
1631 for (unsigned i = 0; i < len; ++i)
1633 if (TYPE_P (scc->entries[i]))
1634 num_merged_types++;
1635 free_node (scc->entries[i]);
1638 /* Drop DIE references. */
1639 dref_queue.truncate (0);
1641 break;
1644 /* Reset TREE_VISITED if we didn't unify the SCC with another. */
1645 if (!unified_p)
1646 for (unsigned i = 0; i < scc->len; ++i)
1647 TREE_VISITED (scc->entries[i]) = 0;
1650 /* If we didn't unify it to any candidate duplicate the relevant
1651 pieces to permanent storage and link it into the chain. */
1652 if (!unified_p)
1654 tree_scc *pscc
1655 = XOBNEWVAR (&tree_scc_hash_obstack, tree_scc, sizeof (tree_scc));
1656 memcpy (pscc, scc, sizeof (tree_scc));
1657 pscc->next = (*slot);
1658 *slot = pscc;
1660 return unified_p;
1664 /* Read all the symbols from buffer DATA, using descriptors in DECL_DATA.
1665 RESOLUTIONS is the set of symbols picked by the linker (read from the
1666 resolution file when the linker plugin is being used). */
1668 static void
1669 lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
1670 vec<ld_plugin_symbol_resolution_t> resolutions)
1672 const struct lto_decl_header *header = (const struct lto_decl_header *) data;
1673 const int decl_offset = sizeof (struct lto_decl_header);
1674 const int main_offset = decl_offset + header->decl_state_size;
1675 const int string_offset = main_offset + header->main_size;
1676 struct data_in *data_in;
1677 unsigned int i;
1678 const uint32_t *data_ptr, *data_end;
1679 uint32_t num_decl_states;
1681 lto_input_block ib_main ((const char *) data + main_offset,
1682 header->main_size, decl_data->mode_table);
1684 data_in = lto_data_in_create (decl_data, (const char *) data + string_offset,
1685 header->string_size, resolutions);
1687 /* We do not uniquify the pre-loaded cache entries, those are middle-end
1688 internal types that should not be merged. */
1690 /* Read the global declarations and types. */
1691 while (ib_main.p < ib_main.len)
1693 tree t;
1694 unsigned from = data_in->reader_cache->nodes.length ();
1695 /* Read and uniquify SCCs as in the input stream. */
1696 enum LTO_tags tag = streamer_read_record_start (&ib_main);
1697 if (tag == LTO_tree_scc)
1699 unsigned len_;
1700 unsigned scc_entry_len;
1701 hashval_t scc_hash = lto_input_scc (&ib_main, data_in, &len_,
1702 &scc_entry_len);
1703 unsigned len = data_in->reader_cache->nodes.length () - from;
1704 gcc_assert (len == len_);
1706 total_scc_size += len;
1707 num_sccs_read++;
1709 /* We have the special case of size-1 SCCs that are pre-merged
1710 by means of identifier and string sharing for example.
1711 ??? Maybe we should avoid streaming those as SCCs. */
1712 tree first = streamer_tree_cache_get_tree (data_in->reader_cache,
1713 from);
1714 if (len == 1
1715 && (TREE_CODE (first) == IDENTIFIER_NODE
1716 || TREE_CODE (first) == INTEGER_CST))
1717 continue;
1719 /* Try to unify the SCC with already existing ones. */
1720 if (!flag_ltrans
1721 && unify_scc (data_in, from,
1722 len, scc_entry_len, scc_hash))
1723 continue;
1725 /* Tree merging failed, mark entries in location cache as
1726 permanent. */
1727 data_in->location_cache.accept_location_cache ();
1729 bool seen_type = false;
1730 for (unsigned i = 0; i < len; ++i)
1732 tree t = streamer_tree_cache_get_tree (data_in->reader_cache,
1733 from + i);
1734 /* Reconstruct the type variant and pointer-to/reference-to
1735 chains. */
1736 if (TYPE_P (t))
1738 seen_type = true;
1739 num_prevailing_types++;
1740 lto_fixup_prevailing_type (t);
1742 /* Compute the canonical type of all types.
1743 ??? Should be able to assert that !TYPE_CANONICAL. */
1744 if (TYPE_P (t) && !TYPE_CANONICAL (t))
1746 gimple_register_canonical_type (t);
1747 if (odr_type_p (t))
1748 register_odr_type (t);
1750 /* Link shared INTEGER_CSTs into TYPE_CACHED_VALUEs of its
1751 type which is also member of this SCC. */
1752 if (TREE_CODE (t) == INTEGER_CST
1753 && !TREE_OVERFLOW (t))
1754 cache_integer_cst (t);
1755 if (!flag_ltrans)
1757 /* Register variables and functions with the
1758 symbol table. */
1759 if (TREE_CODE (t) == VAR_DECL)
1760 lto_register_var_decl_in_symtab (data_in, t, from + i);
1761 else if (TREE_CODE (t) == FUNCTION_DECL
1762 && !DECL_BUILT_IN (t))
1763 lto_register_function_decl_in_symtab (data_in, t, from + i);
1764 /* Scan the tree for references to global functions or
1765 variables and record those for later fixup. */
1766 if (mentions_vars_p (t))
1767 vec_safe_push (tree_with_vars, t);
1771 /* Register DECLs with the debuginfo machinery. */
1772 while (!dref_queue.is_empty ())
1774 dref_entry e = dref_queue.pop ();
1775 debug_hooks->register_external_die (e.decl, e.sym, e.off);
1778 if (seen_type)
1779 num_type_scc_trees += len;
1781 else
1783 /* Pickle stray references. */
1784 t = lto_input_tree_1 (&ib_main, data_in, tag, 0);
1785 gcc_assert (t && data_in->reader_cache->nodes.length () == from);
1788 data_in->location_cache.apply_location_cache ();
1790 /* Read in lto_in_decl_state objects. */
1791 data_ptr = (const uint32_t *) ((const char*) data + decl_offset);
1792 data_end =
1793 (const uint32_t *) ((const char*) data_ptr + header->decl_state_size);
1794 num_decl_states = *data_ptr++;
1796 gcc_assert (num_decl_states > 0);
1797 decl_data->global_decl_state = lto_new_in_decl_state ();
1798 data_ptr = lto_read_in_decl_state (data_in, data_ptr,
1799 decl_data->global_decl_state);
1801 /* Read in per-function decl states and enter them in hash table. */
1802 decl_data->function_decl_states =
1803 hash_table<decl_state_hasher>::create_ggc (37);
1805 for (i = 1; i < num_decl_states; i++)
1807 struct lto_in_decl_state *state = lto_new_in_decl_state ();
1809 data_ptr = lto_read_in_decl_state (data_in, data_ptr, state);
1810 lto_in_decl_state **slot
1811 = decl_data->function_decl_states->find_slot (state, INSERT);
1812 gcc_assert (*slot == NULL);
1813 *slot = state;
1816 if (data_ptr != data_end)
1817 internal_error ("bytecode stream: garbage at the end of symbols section");
1819 /* Set the current decl state to be the global state. */
1820 decl_data->current_decl_state = decl_data->global_decl_state;
1822 lto_data_in_delete (data_in);
1825 /* Custom version of strtoll, which is not portable. */
1827 static int64_t
1828 lto_parse_hex (const char *p)
1830 int64_t ret = 0;
1832 for (; *p != '\0'; ++p)
1834 char c = *p;
1835 unsigned char part;
1836 ret <<= 4;
1837 if (c >= '0' && c <= '9')
1838 part = c - '0';
1839 else if (c >= 'a' && c <= 'f')
1840 part = c - 'a' + 10;
1841 else if (c >= 'A' && c <= 'F')
1842 part = c - 'A' + 10;
1843 else
1844 internal_error ("could not parse hex number");
1845 ret |= part;
1848 return ret;
1851 /* Read resolution for file named FILE_NAME. The resolution is read from
1852 RESOLUTION. */
1854 static void
1855 lto_resolution_read (splay_tree file_ids, FILE *resolution, lto_file *file)
1857 /* We require that objects in the resolution file are in the same
1858 order as the lto1 command line. */
1859 unsigned int name_len;
1860 char *obj_name;
1861 unsigned int num_symbols;
1862 unsigned int i;
1863 struct lto_file_decl_data *file_data;
1864 splay_tree_node nd = NULL;
1866 if (!resolution)
1867 return;
1869 name_len = strlen (file->filename);
1870 obj_name = XNEWVEC (char, name_len + 1);
1871 fscanf (resolution, " "); /* Read white space. */
1873 fread (obj_name, sizeof (char), name_len, resolution);
1874 obj_name[name_len] = '\0';
1875 if (filename_cmp (obj_name, file->filename) != 0)
1876 internal_error ("unexpected file name %s in linker resolution file. "
1877 "Expected %s", obj_name, file->filename);
1878 if (file->offset != 0)
1880 int t;
1881 char offset_p[17];
1882 int64_t offset;
1883 t = fscanf (resolution, "@0x%16s", offset_p);
1884 if (t != 1)
1885 internal_error ("could not parse file offset");
1886 offset = lto_parse_hex (offset_p);
1887 if (offset != file->offset)
1888 internal_error ("unexpected offset");
1891 free (obj_name);
1893 fscanf (resolution, "%u", &num_symbols);
1895 for (i = 0; i < num_symbols; i++)
1897 int t;
1898 unsigned index;
1899 unsigned HOST_WIDE_INT id;
1900 char r_str[27];
1901 enum ld_plugin_symbol_resolution r = (enum ld_plugin_symbol_resolution) 0;
1902 unsigned int j;
1903 unsigned int lto_resolution_str_len =
1904 sizeof (lto_resolution_str) / sizeof (char *);
1905 res_pair rp;
1907 t = fscanf (resolution, "%u " HOST_WIDE_INT_PRINT_HEX_PURE " %26s %*[^\n]\n",
1908 &index, &id, r_str);
1909 if (t != 3)
1910 internal_error ("invalid line in the resolution file");
1912 for (j = 0; j < lto_resolution_str_len; j++)
1914 if (strcmp (lto_resolution_str[j], r_str) == 0)
1916 r = (enum ld_plugin_symbol_resolution) j;
1917 break;
1920 if (j == lto_resolution_str_len)
1921 internal_error ("invalid resolution in the resolution file");
1923 if (!(nd && lto_splay_tree_id_equal_p (nd->key, id)))
1925 nd = lto_splay_tree_lookup (file_ids, id);
1926 if (nd == NULL)
1927 internal_error ("resolution sub id %wx not in object file", id);
1930 file_data = (struct lto_file_decl_data *)nd->value;
1931 /* The indexes are very sparse. To save memory save them in a compact
1932 format that is only unpacked later when the subfile is processed. */
1933 rp.res = r;
1934 rp.index = index;
1935 file_data->respairs.safe_push (rp);
1936 if (file_data->max_index < index)
1937 file_data->max_index = index;
1941 /* List of file_decl_datas */
1942 struct file_data_list
1944 struct lto_file_decl_data *first, *last;
1947 /* Is the name for a id'ed LTO section? */
1949 static int
1950 lto_section_with_id (const char *name, unsigned HOST_WIDE_INT *id)
1952 const char *s;
1954 if (strncmp (name, section_name_prefix, strlen (section_name_prefix)))
1955 return 0;
1956 s = strrchr (name, '.');
1957 if (!s)
1958 return 0;
1959 /* If the section is not suffixed with an ID return. */
1960 if ((size_t)(s - name) == strlen (section_name_prefix))
1961 return 0;
1962 return sscanf (s, "." HOST_WIDE_INT_PRINT_HEX_PURE, id) == 1;
1965 /* Create file_data of each sub file id */
1967 static int
1968 create_subid_section_table (struct lto_section_slot *ls, splay_tree file_ids,
1969 struct file_data_list *list)
1971 struct lto_section_slot s_slot, *new_slot;
1972 unsigned HOST_WIDE_INT id;
1973 splay_tree_node nd;
1974 void **hash_slot;
1975 char *new_name;
1976 struct lto_file_decl_data *file_data;
1978 if (!lto_section_with_id (ls->name, &id))
1979 return 1;
1981 /* Find hash table of sub module id */
1982 nd = lto_splay_tree_lookup (file_ids, id);
1983 if (nd != NULL)
1985 file_data = (struct lto_file_decl_data *)nd->value;
1987 else
1989 file_data = ggc_alloc<lto_file_decl_data> ();
1990 memset(file_data, 0, sizeof (struct lto_file_decl_data));
1991 file_data->id = id;
1992 file_data->section_hash_table = lto_obj_create_section_hash_table ();;
1993 lto_splay_tree_insert (file_ids, id, file_data);
1995 /* Maintain list in linker order */
1996 if (!list->first)
1997 list->first = file_data;
1998 if (list->last)
1999 list->last->next = file_data;
2000 list->last = file_data;
2003 /* Copy section into sub module hash table */
2004 new_name = XDUPVEC (char, ls->name, strlen (ls->name) + 1);
2005 s_slot.name = new_name;
2006 hash_slot = htab_find_slot (file_data->section_hash_table, &s_slot, INSERT);
2007 gcc_assert (*hash_slot == NULL);
2009 new_slot = XDUP (struct lto_section_slot, ls);
2010 new_slot->name = new_name;
2011 *hash_slot = new_slot;
2012 return 1;
2015 /* Read declarations and other initializations for a FILE_DATA. */
2017 static void
2018 lto_file_finalize (struct lto_file_decl_data *file_data, lto_file *file)
2020 const char *data;
2021 size_t len;
2022 vec<ld_plugin_symbol_resolution_t>
2023 resolutions = vNULL;
2024 int i;
2025 res_pair *rp;
2027 /* Create vector for fast access of resolution. We do this lazily
2028 to save memory. */
2029 resolutions.safe_grow_cleared (file_data->max_index + 1);
2030 for (i = 0; file_data->respairs.iterate (i, &rp); i++)
2031 resolutions[rp->index] = rp->res;
2032 file_data->respairs.release ();
2034 file_data->renaming_hash_table = lto_create_renaming_table ();
2035 file_data->file_name = file->filename;
2036 #ifdef ACCEL_COMPILER
2037 lto_input_mode_table (file_data);
2038 #else
2039 file_data->mode_table = lto_mode_identity_table;
2040 #endif
2041 data = lto_get_section_data (file_data, LTO_section_decls, NULL, &len);
2042 if (data == NULL)
2044 internal_error ("cannot read LTO decls from %s", file_data->file_name);
2045 return;
2047 /* Frees resolutions */
2048 lto_read_decls (file_data, data, resolutions);
2049 lto_free_section_data (file_data, LTO_section_decls, NULL, data, len);
2052 /* Finalize FILE_DATA in FILE and increase COUNT. */
2054 static int
2055 lto_create_files_from_ids (lto_file *file, struct lto_file_decl_data *file_data,
2056 int *count)
2058 lto_file_finalize (file_data, file);
2059 if (symtab->dump_file)
2060 fprintf (symtab->dump_file,
2061 "Creating file %s with sub id " HOST_WIDE_INT_PRINT_HEX "\n",
2062 file_data->file_name, file_data->id);
2063 (*count)++;
2064 return 0;
2067 /* Generate a TREE representation for all types and external decls
2068 entities in FILE.
2070 Read all of the globals out of the file. Then read the cgraph
2071 and process the .o index into the cgraph nodes so that it can open
2072 the .o file to load the functions and ipa information. */
2074 static struct lto_file_decl_data *
2075 lto_file_read (lto_file *file, FILE *resolution_file, int *count)
2077 struct lto_file_decl_data *file_data = NULL;
2078 splay_tree file_ids;
2079 htab_t section_hash_table;
2080 struct lto_section_slot *section;
2081 struct file_data_list file_list;
2082 struct lto_section_list section_list;
2084 memset (&section_list, 0, sizeof (struct lto_section_list));
2085 section_hash_table = lto_obj_build_section_table (file, &section_list);
2087 /* Find all sub modules in the object and put their sections into new hash
2088 tables in a splay tree. */
2089 file_ids = lto_splay_tree_new ();
2090 memset (&file_list, 0, sizeof (struct file_data_list));
2091 for (section = section_list.first; section != NULL; section = section->next)
2092 create_subid_section_table (section, file_ids, &file_list);
2094 /* Add resolutions to file ids */
2095 lto_resolution_read (file_ids, resolution_file, file);
2097 /* Finalize each lto file for each submodule in the merged object */
2098 for (file_data = file_list.first; file_data != NULL; file_data = file_data->next)
2099 lto_create_files_from_ids (file, file_data, count);
2101 splay_tree_delete (file_ids);
2102 htab_delete (section_hash_table);
2104 return file_list.first;
2107 #if HAVE_MMAP_FILE && HAVE_SYSCONF && defined _SC_PAGE_SIZE
2108 #define LTO_MMAP_IO 1
2109 #endif
2111 #if LTO_MMAP_IO
2112 /* Page size of machine is used for mmap and munmap calls. */
2113 static size_t page_mask;
2114 #endif
2116 /* Get the section data of length LEN from FILENAME starting at
2117 OFFSET. The data segment must be freed by the caller when the
2118 caller is finished. Returns NULL if all was not well. */
2120 static char *
2121 lto_read_section_data (struct lto_file_decl_data *file_data,
2122 intptr_t offset, size_t len)
2124 char *result;
2125 static int fd = -1;
2126 static char *fd_name;
2127 #if LTO_MMAP_IO
2128 intptr_t computed_len;
2129 intptr_t computed_offset;
2130 intptr_t diff;
2131 #endif
2133 /* Keep a single-entry file-descriptor cache. The last file we
2134 touched will get closed at exit.
2135 ??? Eventually we want to add a more sophisticated larger cache
2136 or rather fix function body streaming to not stream them in
2137 practically random order. */
2138 if (fd != -1
2139 && filename_cmp (fd_name, file_data->file_name) != 0)
2141 free (fd_name);
2142 close (fd);
2143 fd = -1;
2145 if (fd == -1)
2147 fd = open (file_data->file_name, O_RDONLY|O_BINARY);
2148 if (fd == -1)
2150 fatal_error (input_location, "Cannot open %s", file_data->file_name);
2151 return NULL;
2153 fd_name = xstrdup (file_data->file_name);
2156 #if LTO_MMAP_IO
2157 if (!page_mask)
2159 size_t page_size = sysconf (_SC_PAGE_SIZE);
2160 page_mask = ~(page_size - 1);
2163 computed_offset = offset & page_mask;
2164 diff = offset - computed_offset;
2165 computed_len = len + diff;
2167 result = (char *) mmap (NULL, computed_len, PROT_READ, MAP_PRIVATE,
2168 fd, computed_offset);
2169 if (result == MAP_FAILED)
2171 fatal_error (input_location, "Cannot map %s", file_data->file_name);
2172 return NULL;
2175 return result + diff;
2176 #else
2177 result = (char *) xmalloc (len);
2178 if (lseek (fd, offset, SEEK_SET) != offset
2179 || read (fd, result, len) != (ssize_t) len)
2181 free (result);
2182 fatal_error (input_location, "Cannot read %s", file_data->file_name);
2183 result = NULL;
2185 #ifdef __MINGW32__
2186 /* Native windows doesn't supports delayed unlink on opened file. So
2187 we close file here again. This produces higher I/O load, but at least
2188 it prevents to have dangling file handles preventing unlink. */
2189 free (fd_name);
2190 fd_name = NULL;
2191 close (fd);
2192 fd = -1;
2193 #endif
2194 return result;
2195 #endif
2199 /* Get the section data from FILE_DATA of SECTION_TYPE with NAME.
2200 NAME will be NULL unless the section type is for a function
2201 body. */
2203 static const char *
2204 get_section_data (struct lto_file_decl_data *file_data,
2205 enum lto_section_type section_type,
2206 const char *name,
2207 size_t *len)
2209 htab_t section_hash_table = file_data->section_hash_table;
2210 struct lto_section_slot *f_slot;
2211 struct lto_section_slot s_slot;
2212 const char *section_name = lto_get_section_name (section_type, name, file_data);
2213 char *data = NULL;
2215 *len = 0;
2216 s_slot.name = section_name;
2217 f_slot = (struct lto_section_slot *) htab_find (section_hash_table, &s_slot);
2218 if (f_slot)
2220 data = lto_read_section_data (file_data, f_slot->start, f_slot->len);
2221 *len = f_slot->len;
2224 free (CONST_CAST (char *, section_name));
2225 return data;
2229 /* Free the section data from FILE_DATA of SECTION_TYPE with NAME that
2230 starts at OFFSET and has LEN bytes. */
2232 static void
2233 free_section_data (struct lto_file_decl_data *file_data ATTRIBUTE_UNUSED,
2234 enum lto_section_type section_type ATTRIBUTE_UNUSED,
2235 const char *name ATTRIBUTE_UNUSED,
2236 const char *offset, size_t len ATTRIBUTE_UNUSED)
2238 #if LTO_MMAP_IO
2239 intptr_t computed_len;
2240 intptr_t computed_offset;
2241 intptr_t diff;
2242 #endif
2244 #if LTO_MMAP_IO
2245 computed_offset = ((intptr_t) offset) & page_mask;
2246 diff = (intptr_t) offset - computed_offset;
2247 computed_len = len + diff;
2249 munmap ((caddr_t) computed_offset, computed_len);
2250 #else
2251 free (CONST_CAST(char *, offset));
2252 #endif
2255 static lto_file *current_lto_file;
2257 /* Helper for qsort; compare partitions and return one with smaller size.
2258 We sort from greatest to smallest so parallel build doesn't stale on the
2259 longest compilation being executed too late. */
2261 static int
2262 cmp_partitions_size (const void *a, const void *b)
2264 const struct ltrans_partition_def *pa
2265 = *(struct ltrans_partition_def *const *)a;
2266 const struct ltrans_partition_def *pb
2267 = *(struct ltrans_partition_def *const *)b;
2268 return pb->insns - pa->insns;
2271 /* Helper for qsort; compare partitions and return one with smaller order. */
2273 static int
2274 cmp_partitions_order (const void *a, const void *b)
2276 const struct ltrans_partition_def *pa
2277 = *(struct ltrans_partition_def *const *)a;
2278 const struct ltrans_partition_def *pb
2279 = *(struct ltrans_partition_def *const *)b;
2280 int ordera = -1, orderb = -1;
2282 if (lto_symtab_encoder_size (pa->encoder))
2283 ordera = lto_symtab_encoder_deref (pa->encoder, 0)->order;
2284 if (lto_symtab_encoder_size (pb->encoder))
2285 orderb = lto_symtab_encoder_deref (pb->encoder, 0)->order;
2286 return orderb - ordera;
2289 /* Actually stream out ENCODER into TEMP_FILENAME. */
2291 static void
2292 do_stream_out (char *temp_filename, lto_symtab_encoder_t encoder)
2294 lto_file *file = lto_obj_file_open (temp_filename, true);
2295 if (!file)
2296 fatal_error (input_location, "lto_obj_file_open() failed");
2297 lto_set_current_out_file (file);
2299 ipa_write_optimization_summaries (encoder);
2301 free (CONST_CAST (char *, file->filename));
2303 lto_set_current_out_file (NULL);
2304 lto_obj_file_close (file);
2305 free (file);
2308 /* Wait for forked process and signal errors. */
2309 #ifdef HAVE_WORKING_FORK
2310 static void
2311 wait_for_child ()
2313 int status;
2316 #ifndef WCONTINUED
2317 #define WCONTINUED 0
2318 #endif
2319 int w = waitpid (0, &status, WUNTRACED | WCONTINUED);
2320 if (w == -1)
2321 fatal_error (input_location, "waitpid failed");
2323 if (WIFEXITED (status) && WEXITSTATUS (status))
2324 fatal_error (input_location, "streaming subprocess failed");
2325 else if (WIFSIGNALED (status))
2326 fatal_error (input_location,
2327 "streaming subprocess was killed by signal");
2329 while (!WIFEXITED (status) && !WIFSIGNALED (status));
2331 #endif
2333 /* Stream out ENCODER into TEMP_FILENAME
2334 Fork if that seems to help. */
2336 static void
2337 stream_out (char *temp_filename, lto_symtab_encoder_t encoder,
2338 bool ARG_UNUSED (last))
2340 #ifdef HAVE_WORKING_FORK
2341 static int nruns;
2343 if (lto_parallelism <= 1)
2345 do_stream_out (temp_filename, encoder);
2346 return;
2349 /* Do not run more than LTO_PARALLELISM streamings
2350 FIXME: we ignore limits on jobserver. */
2351 if (lto_parallelism > 0 && nruns >= lto_parallelism)
2353 wait_for_child ();
2354 nruns --;
2356 /* If this is not the last parallel partition, execute new
2357 streaming process. */
2358 if (!last)
2360 pid_t cpid = fork ();
2362 if (!cpid)
2364 setproctitle ("lto1-wpa-streaming");
2365 do_stream_out (temp_filename, encoder);
2366 exit (0);
2368 /* Fork failed; lets do the job ourseleves. */
2369 else if (cpid == -1)
2370 do_stream_out (temp_filename, encoder);
2371 else
2372 nruns++;
2374 /* Last partition; stream it and wait for all children to die. */
2375 else
2377 int i;
2378 do_stream_out (temp_filename, encoder);
2379 for (i = 0; i < nruns; i++)
2380 wait_for_child ();
2382 asm_nodes_output = true;
2383 #else
2384 do_stream_out (temp_filename, encoder);
2385 #endif
2388 /* Write all output files in WPA mode and the file with the list of
2389 LTRANS units. */
2391 static void
2392 lto_wpa_write_files (void)
2394 unsigned i, n_sets;
2395 ltrans_partition part;
2396 FILE *ltrans_output_list_stream;
2397 char *temp_filename;
2398 vec <char *>temp_filenames = vNULL;
2399 size_t blen;
2401 /* Open the LTRANS output list. */
2402 if (!ltrans_output_list)
2403 fatal_error (input_location, "no LTRANS output list filename provided");
2405 timevar_push (TV_WHOPR_WPA);
2407 FOR_EACH_VEC_ELT (ltrans_partitions, i, part)
2408 lto_stats.num_output_symtab_nodes += lto_symtab_encoder_size (part->encoder);
2410 timevar_pop (TV_WHOPR_WPA);
2412 timevar_push (TV_WHOPR_WPA_IO);
2414 /* Generate a prefix for the LTRANS unit files. */
2415 blen = strlen (ltrans_output_list);
2416 temp_filename = (char *) xmalloc (blen + sizeof ("2147483648.o"));
2417 strcpy (temp_filename, ltrans_output_list);
2418 if (blen > sizeof (".out")
2419 && strcmp (temp_filename + blen - sizeof (".out") + 1,
2420 ".out") == 0)
2421 temp_filename[blen - sizeof (".out") + 1] = '\0';
2422 blen = strlen (temp_filename);
2424 n_sets = ltrans_partitions.length ();
2426 /* Sort partitions by size so small ones are compiled last.
2427 FIXME: Even when not reordering we may want to output one list for parallel make
2428 and other for final link command. */
2430 if (!flag_profile_reorder_functions || !flag_profile_use)
2431 ltrans_partitions.qsort (flag_toplevel_reorder
2432 ? cmp_partitions_size
2433 : cmp_partitions_order);
2435 for (i = 0; i < n_sets; i++)
2437 ltrans_partition part = ltrans_partitions[i];
2439 /* Write all the nodes in SET. */
2440 sprintf (temp_filename + blen, "%u.o", i);
2442 if (!quiet_flag)
2443 fprintf (stderr, " %s (%s %i insns)", temp_filename, part->name, part->insns);
2444 if (symtab->dump_file)
2446 lto_symtab_encoder_iterator lsei;
2448 fprintf (symtab->dump_file, "Writing partition %s to file %s, %i insns\n",
2449 part->name, temp_filename, part->insns);
2450 fprintf (symtab->dump_file, " Symbols in partition: ");
2451 for (lsei = lsei_start_in_partition (part->encoder); !lsei_end_p (lsei);
2452 lsei_next_in_partition (&lsei))
2454 symtab_node *node = lsei_node (lsei);
2455 fprintf (symtab->dump_file, "%s ", node->asm_name ());
2457 fprintf (symtab->dump_file, "\n Symbols in boundary: ");
2458 for (lsei = lsei_start (part->encoder); !lsei_end_p (lsei);
2459 lsei_next (&lsei))
2461 symtab_node *node = lsei_node (lsei);
2462 if (!lto_symtab_encoder_in_partition_p (part->encoder, node))
2464 fprintf (symtab->dump_file, "%s ", node->asm_name ());
2465 cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
2466 if (cnode
2467 && lto_symtab_encoder_encode_body_p (part->encoder, cnode))
2468 fprintf (symtab->dump_file, "(body included)");
2469 else
2471 varpool_node *vnode = dyn_cast <varpool_node *> (node);
2472 if (vnode
2473 && lto_symtab_encoder_encode_initializer_p (part->encoder, vnode))
2474 fprintf (symtab->dump_file, "(initializer included)");
2478 fprintf (symtab->dump_file, "\n");
2480 gcc_checking_assert (lto_symtab_encoder_size (part->encoder) || !i);
2482 stream_out (temp_filename, part->encoder, i == n_sets - 1);
2484 part->encoder = NULL;
2486 temp_filenames.safe_push (xstrdup (temp_filename));
2488 ltrans_output_list_stream = fopen (ltrans_output_list, "w");
2489 if (ltrans_output_list_stream == NULL)
2490 fatal_error (input_location,
2491 "opening LTRANS output list %s: %m", ltrans_output_list);
2492 for (i = 0; i < n_sets; i++)
2494 unsigned int len = strlen (temp_filenames[i]);
2495 if (fwrite (temp_filenames[i], 1, len, ltrans_output_list_stream) < len
2496 || fwrite ("\n", 1, 1, ltrans_output_list_stream) < 1)
2497 fatal_error (input_location, "writing to LTRANS output list %s: %m",
2498 ltrans_output_list);
2499 free (temp_filenames[i]);
2501 temp_filenames.release();
2503 lto_stats.num_output_files += n_sets;
2505 /* Close the LTRANS output list. */
2506 if (fclose (ltrans_output_list_stream))
2507 fatal_error (input_location,
2508 "closing LTRANS output list %s: %m", ltrans_output_list);
2510 free_ltrans_partitions();
2511 free (temp_filename);
2513 timevar_pop (TV_WHOPR_WPA_IO);
2517 /* If TT is a variable or function decl replace it with its
2518 prevailing variant. */
2519 #define LTO_SET_PREVAIL(tt) \
2520 do {\
2521 if ((tt) && VAR_OR_FUNCTION_DECL_P (tt) \
2522 && (TREE_PUBLIC (tt) || DECL_EXTERNAL (tt))) \
2524 tt = lto_symtab_prevailing_decl (tt); \
2525 fixed = true; \
2527 } while (0)
2529 /* Ensure that TT isn't a replacable var of function decl. */
2530 #define LTO_NO_PREVAIL(tt) \
2531 gcc_checking_assert (!(tt) || !VAR_OR_FUNCTION_DECL_P (tt))
2533 /* Given a tree T replace all fields referring to variables or functions
2534 with their prevailing variant. */
2535 static void
2536 lto_fixup_prevailing_decls (tree t)
2538 enum tree_code code = TREE_CODE (t);
2539 bool fixed = false;
2541 gcc_checking_assert (code != TREE_BINFO);
2542 LTO_NO_PREVAIL (TREE_TYPE (t));
2543 if (CODE_CONTAINS_STRUCT (code, TS_COMMON)
2544 /* lto_symtab_prevail_decl use TREE_CHAIN to link to the prevailing decl.
2545 in the case T is a prevailed declaration we would ICE here. */
2546 && !VAR_OR_FUNCTION_DECL_P (t))
2547 LTO_NO_PREVAIL (TREE_CHAIN (t));
2548 if (DECL_P (t))
2550 LTO_NO_PREVAIL (DECL_NAME (t));
2551 LTO_SET_PREVAIL (DECL_CONTEXT (t));
2552 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
2554 LTO_SET_PREVAIL (DECL_SIZE (t));
2555 LTO_SET_PREVAIL (DECL_SIZE_UNIT (t));
2556 LTO_SET_PREVAIL (DECL_INITIAL (t));
2557 LTO_NO_PREVAIL (DECL_ATTRIBUTES (t));
2558 LTO_SET_PREVAIL (DECL_ABSTRACT_ORIGIN (t));
2560 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
2562 LTO_NO_PREVAIL (DECL_ASSEMBLER_NAME_RAW (t));
2564 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
2566 LTO_NO_PREVAIL (DECL_RESULT_FLD (t));
2568 if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
2570 LTO_NO_PREVAIL (DECL_ARGUMENTS (t));
2571 LTO_SET_PREVAIL (DECL_FUNCTION_PERSONALITY (t));
2572 LTO_NO_PREVAIL (DECL_VINDEX (t));
2574 if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
2576 LTO_SET_PREVAIL (DECL_FIELD_OFFSET (t));
2577 LTO_NO_PREVAIL (DECL_BIT_FIELD_TYPE (t));
2578 LTO_NO_PREVAIL (DECL_QUALIFIER (t));
2579 LTO_NO_PREVAIL (DECL_FIELD_BIT_OFFSET (t));
2580 LTO_NO_PREVAIL (DECL_FCONTEXT (t));
2583 else if (TYPE_P (t))
2585 LTO_NO_PREVAIL (TYPE_CACHED_VALUES (t));
2586 LTO_SET_PREVAIL (TYPE_SIZE (t));
2587 LTO_SET_PREVAIL (TYPE_SIZE_UNIT (t));
2588 LTO_NO_PREVAIL (TYPE_ATTRIBUTES (t));
2589 LTO_NO_PREVAIL (TYPE_NAME (t));
2591 LTO_SET_PREVAIL (TYPE_MIN_VALUE_RAW (t));
2592 LTO_SET_PREVAIL (TYPE_MAX_VALUE_RAW (t));
2593 LTO_NO_PREVAIL (TYPE_LANG_SLOT_1 (t));
2595 LTO_SET_PREVAIL (TYPE_CONTEXT (t));
2597 LTO_NO_PREVAIL (TYPE_CANONICAL (t));
2598 LTO_NO_PREVAIL (TYPE_MAIN_VARIANT (t));
2599 LTO_NO_PREVAIL (TYPE_NEXT_VARIANT (t));
2601 else if (EXPR_P (t))
2603 int i;
2604 for (i = TREE_OPERAND_LENGTH (t) - 1; i >= 0; --i)
2605 LTO_SET_PREVAIL (TREE_OPERAND (t, i));
2607 else if (TREE_CODE (t) == CONSTRUCTOR)
2609 unsigned i;
2610 tree val;
2611 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), i, val)
2612 LTO_SET_PREVAIL (val);
2614 else
2616 switch (code)
2618 case TREE_LIST:
2619 LTO_SET_PREVAIL (TREE_VALUE (t));
2620 LTO_SET_PREVAIL (TREE_PURPOSE (t));
2621 LTO_NO_PREVAIL (TREE_PURPOSE (t));
2622 break;
2623 default:
2624 gcc_unreachable ();
2627 /* If we fixed nothing, then we missed something seen by
2628 mentions_vars_p. */
2629 gcc_checking_assert (fixed);
2631 #undef LTO_SET_PREVAIL
2632 #undef LTO_NO_PREVAIL
2634 /* Helper function of lto_fixup_decls. Walks the var and fn streams in STATE,
2635 replaces var and function decls with the corresponding prevailing def. */
2637 static void
2638 lto_fixup_state (struct lto_in_decl_state *state)
2640 unsigned i, si;
2642 /* Although we only want to replace FUNCTION_DECLs and VAR_DECLs,
2643 we still need to walk from all DECLs to find the reachable
2644 FUNCTION_DECLs and VAR_DECLs. */
2645 for (si = 0; si < LTO_N_DECL_STREAMS; si++)
2647 vec<tree, va_gc> *trees = state->streams[si];
2648 for (i = 0; i < vec_safe_length (trees); i++)
2650 tree t = (*trees)[i];
2651 if (flag_checking && TYPE_P (t))
2652 verify_type (t);
2653 if (VAR_OR_FUNCTION_DECL_P (t)
2654 && (TREE_PUBLIC (t) || DECL_EXTERNAL (t)))
2655 (*trees)[i] = lto_symtab_prevailing_decl (t);
2660 /* Fix the decls from all FILES. Replaces each decl with the corresponding
2661 prevailing one. */
2663 static void
2664 lto_fixup_decls (struct lto_file_decl_data **files)
2666 unsigned int i;
2667 tree t;
2669 if (tree_with_vars)
2670 FOR_EACH_VEC_ELT ((*tree_with_vars), i, t)
2671 lto_fixup_prevailing_decls (t);
2673 for (i = 0; files[i]; i++)
2675 struct lto_file_decl_data *file = files[i];
2676 struct lto_in_decl_state *state = file->global_decl_state;
2677 lto_fixup_state (state);
2679 hash_table<decl_state_hasher>::iterator iter;
2680 lto_in_decl_state *elt;
2681 FOR_EACH_HASH_TABLE_ELEMENT (*file->function_decl_states, elt,
2682 lto_in_decl_state *, iter)
2683 lto_fixup_state (elt);
2687 static GTY((length ("lto_stats.num_input_files + 1"))) struct lto_file_decl_data **all_file_decl_data;
2689 /* Turn file datas for sub files into a single array, so that they look
2690 like separate files for further passes. */
2692 static void
2693 lto_flatten_files (struct lto_file_decl_data **orig, int count, int last_file_ix)
2695 struct lto_file_decl_data *n, *next;
2696 int i, k;
2698 lto_stats.num_input_files = count;
2699 all_file_decl_data
2700 = ggc_cleared_vec_alloc<lto_file_decl_data_ptr> (count + 1);
2701 /* Set the hooks so that all of the ipa passes can read in their data. */
2702 lto_set_in_hooks (all_file_decl_data, get_section_data, free_section_data);
2703 for (i = 0, k = 0; i < last_file_ix; i++)
2705 for (n = orig[i]; n != NULL; n = next)
2707 all_file_decl_data[k++] = n;
2708 next = n->next;
2709 n->next = NULL;
2712 all_file_decl_data[k] = NULL;
2713 gcc_assert (k == count);
2716 /* Input file data before flattening (i.e. splitting them to subfiles to support
2717 incremental linking. */
2718 static int real_file_count;
2719 static GTY((length ("real_file_count + 1"))) struct lto_file_decl_data **real_file_decl_data;
2721 static void print_lto_report_1 (void);
2723 /* Read all the symbols from the input files FNAMES. NFILES is the
2724 number of files requested in the command line. Instantiate a
2725 global call graph by aggregating all the sub-graphs found in each
2726 file. */
2728 static void
2729 read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
2731 unsigned int i, last_file_ix;
2732 FILE *resolution;
2733 int count = 0;
2734 struct lto_file_decl_data **decl_data;
2735 symtab_node *snode;
2737 symtab->initialize ();
2739 timevar_push (TV_IPA_LTO_DECL_IN);
2741 #ifdef ACCEL_COMPILER
2742 section_name_prefix = OFFLOAD_SECTION_NAME_PREFIX;
2743 lto_stream_offload_p = true;
2744 #endif
2746 real_file_decl_data
2747 = decl_data = ggc_cleared_vec_alloc<lto_file_decl_data_ptr> (nfiles + 1);
2748 real_file_count = nfiles;
2750 /* Read the resolution file. */
2751 resolution = NULL;
2752 if (resolution_file_name)
2754 int t;
2755 unsigned num_objects;
2757 resolution = fopen (resolution_file_name, "r");
2758 if (resolution == NULL)
2759 fatal_error (input_location,
2760 "could not open symbol resolution file: %m");
2762 t = fscanf (resolution, "%u", &num_objects);
2763 gcc_assert (t == 1);
2765 /* True, since the plugin splits the archives. */
2766 gcc_assert (num_objects == nfiles);
2768 symtab->state = LTO_STREAMING;
2770 canonical_type_hash_cache = new hash_map<const_tree, hashval_t> (251);
2771 gimple_canonical_types = htab_create (16381, gimple_canonical_type_hash,
2772 gimple_canonical_type_eq, NULL);
2773 gcc_obstack_init (&tree_scc_hash_obstack);
2774 tree_scc_hash = new hash_table<tree_scc_hasher> (4096);
2776 /* Register the common node types with the canonical type machinery so
2777 we properly share alias-sets across languages and TUs. Do not
2778 expose the common nodes as type merge target - those that should be
2779 are already exposed so by pre-loading the LTO streamer caches.
2780 Do two passes - first clear TYPE_CANONICAL and then re-compute it. */
2781 for (i = 0; i < itk_none; ++i)
2782 lto_register_canonical_types (integer_types[i], true);
2783 for (i = 0; i < stk_type_kind_last; ++i)
2784 lto_register_canonical_types (sizetype_tab[i], true);
2785 for (i = 0; i < TI_MAX; ++i)
2786 lto_register_canonical_types (global_trees[i], true);
2787 for (i = 0; i < itk_none; ++i)
2788 lto_register_canonical_types (integer_types[i], false);
2789 for (i = 0; i < stk_type_kind_last; ++i)
2790 lto_register_canonical_types (sizetype_tab[i], false);
2791 for (i = 0; i < TI_MAX; ++i)
2792 lto_register_canonical_types (global_trees[i], false);
2794 if (!quiet_flag)
2795 fprintf (stderr, "Reading object files:");
2797 /* Read all of the object files specified on the command line. */
2798 for (i = 0, last_file_ix = 0; i < nfiles; ++i)
2800 struct lto_file_decl_data *file_data = NULL;
2801 if (!quiet_flag)
2803 fprintf (stderr, " %s", fnames[i]);
2804 fflush (stderr);
2807 current_lto_file = lto_obj_file_open (fnames[i], false);
2808 if (!current_lto_file)
2809 break;
2811 file_data = lto_file_read (current_lto_file, resolution, &count);
2812 if (!file_data)
2814 lto_obj_file_close (current_lto_file);
2815 free (current_lto_file);
2816 current_lto_file = NULL;
2817 break;
2820 decl_data[last_file_ix++] = file_data;
2822 lto_obj_file_close (current_lto_file);
2823 free (current_lto_file);
2824 current_lto_file = NULL;
2827 lto_flatten_files (decl_data, count, last_file_ix);
2828 lto_stats.num_input_files = count;
2829 ggc_free(decl_data);
2830 real_file_decl_data = NULL;
2832 if (resolution_file_name)
2833 fclose (resolution);
2835 /* Show the LTO report before launching LTRANS. */
2836 if (flag_lto_report || (flag_wpa && flag_lto_report_wpa))
2837 print_lto_report_1 ();
2839 /* Free gimple type merging datastructures. */
2840 delete tree_scc_hash;
2841 tree_scc_hash = NULL;
2842 obstack_free (&tree_scc_hash_obstack, NULL);
2843 htab_delete (gimple_canonical_types);
2844 gimple_canonical_types = NULL;
2845 delete canonical_type_hash_cache;
2846 canonical_type_hash_cache = NULL;
2848 /* At this stage we know that majority of GGC memory is reachable.
2849 Growing the limits prevents unnecesary invocation of GGC. */
2850 ggc_grow ();
2851 ggc_collect ();
2853 /* Set the hooks so that all of the ipa passes can read in their data. */
2854 lto_set_in_hooks (all_file_decl_data, get_section_data, free_section_data);
2856 timevar_pop (TV_IPA_LTO_DECL_IN);
2858 if (!quiet_flag)
2859 fprintf (stderr, "\nReading the callgraph\n");
2861 timevar_push (TV_IPA_LTO_CGRAPH_IO);
2862 /* Read the symtab. */
2863 input_symtab ();
2865 input_offload_tables (!flag_ltrans);
2867 /* Store resolutions into the symbol table. */
2869 ld_plugin_symbol_resolution_t *res;
2870 FOR_EACH_SYMBOL (snode)
2871 if (snode->real_symbol_p ()
2872 && snode->lto_file_data
2873 && snode->lto_file_data->resolution_map
2874 && (res = snode->lto_file_data->resolution_map->get (snode->decl)))
2875 snode->resolution = *res;
2876 for (i = 0; all_file_decl_data[i]; i++)
2877 if (all_file_decl_data[i]->resolution_map)
2879 delete all_file_decl_data[i]->resolution_map;
2880 all_file_decl_data[i]->resolution_map = NULL;
2883 timevar_pop (TV_IPA_LTO_CGRAPH_IO);
2885 if (!quiet_flag)
2886 fprintf (stderr, "Merging declarations\n");
2888 timevar_push (TV_IPA_LTO_DECL_MERGE);
2889 /* Merge global decls. In ltrans mode we read merged cgraph, we do not
2890 need to care about resolving symbols again, we only need to replace
2891 duplicated declarations read from the callgraph and from function
2892 sections. */
2893 if (!flag_ltrans)
2895 lto_symtab_merge_decls ();
2897 /* If there were errors during symbol merging bail out, we have no
2898 good way to recover here. */
2899 if (seen_error ())
2900 fatal_error (input_location,
2901 "errors during merging of translation units");
2903 /* Fixup all decls. */
2904 lto_fixup_decls (all_file_decl_data);
2906 if (tree_with_vars)
2907 ggc_free (tree_with_vars);
2908 tree_with_vars = NULL;
2909 ggc_collect ();
2911 timevar_pop (TV_IPA_LTO_DECL_MERGE);
2912 /* Each pass will set the appropriate timer. */
2914 if (!quiet_flag)
2915 fprintf (stderr, "Reading summaries\n");
2917 /* Read the IPA summary data. */
2918 if (flag_ltrans)
2919 ipa_read_optimization_summaries ();
2920 else
2921 ipa_read_summaries ();
2923 for (i = 0; all_file_decl_data[i]; i++)
2925 gcc_assert (all_file_decl_data[i]->symtab_node_encoder);
2926 lto_symtab_encoder_delete (all_file_decl_data[i]->symtab_node_encoder);
2927 all_file_decl_data[i]->symtab_node_encoder = NULL;
2928 lto_free_function_in_decl_state (all_file_decl_data[i]->global_decl_state);
2929 all_file_decl_data[i]->global_decl_state = NULL;
2930 all_file_decl_data[i]->current_decl_state = NULL;
2933 /* Finally merge the cgraph according to the decl merging decisions. */
2934 timevar_push (TV_IPA_LTO_CGRAPH_MERGE);
2935 if (symtab->dump_file)
2937 fprintf (symtab->dump_file, "Before merging:\n");
2938 symtab->dump (symtab->dump_file);
2940 if (!flag_ltrans)
2942 lto_symtab_merge_symbols ();
2943 /* Removal of unreachable symbols is needed to make verify_symtab to pass;
2944 we are still having duplicated comdat groups containing local statics.
2945 We could also just remove them while merging. */
2946 symtab->remove_unreachable_nodes (dump_file);
2948 ggc_collect ();
2949 symtab->state = IPA_SSA;
2950 /* FIXME: Technically all node removals happening here are useless, because
2951 WPA should not stream them. */
2952 if (flag_ltrans)
2953 symtab->remove_unreachable_nodes (dump_file);
2955 timevar_pop (TV_IPA_LTO_CGRAPH_MERGE);
2957 /* Indicate that the cgraph is built and ready. */
2958 symtab->function_flags_ready = true;
2960 ggc_free (all_file_decl_data);
2961 all_file_decl_data = NULL;
2965 /* Materialize all the bodies for all the nodes in the callgraph. */
2967 static void
2968 materialize_cgraph (void)
2970 struct cgraph_node *node;
2971 timevar_id_t lto_timer;
2973 if (!quiet_flag)
2974 fprintf (stderr,
2975 flag_wpa ? "Materializing decls:" : "Reading function bodies:");
2978 FOR_EACH_FUNCTION (node)
2980 if (node->lto_file_data)
2982 lto_materialize_function (node);
2983 lto_stats.num_input_cgraph_nodes++;
2988 /* Start the appropriate timer depending on the mode that we are
2989 operating in. */
2990 lto_timer = (flag_wpa) ? TV_WHOPR_WPA
2991 : (flag_ltrans) ? TV_WHOPR_LTRANS
2992 : TV_LTO;
2993 timevar_push (lto_timer);
2995 current_function_decl = NULL;
2996 set_cfun (NULL);
2998 if (!quiet_flag)
2999 fprintf (stderr, "\n");
3001 timevar_pop (lto_timer);
3005 /* Show various memory usage statistics related to LTO. */
3006 static void
3007 print_lto_report_1 (void)
3009 const char *pfx = (flag_lto) ? "LTO" : (flag_wpa) ? "WPA" : "LTRANS";
3010 fprintf (stderr, "%s statistics\n", pfx);
3012 fprintf (stderr, "[%s] read %lu SCCs of average size %f\n",
3013 pfx, num_sccs_read, total_scc_size / (double)num_sccs_read);
3014 fprintf (stderr, "[%s] %lu tree bodies read in total\n", pfx, total_scc_size);
3015 if (flag_wpa && tree_scc_hash)
3017 fprintf (stderr, "[%s] tree SCC table: size %ld, %ld elements, "
3018 "collision ratio: %f\n", pfx,
3019 (long) tree_scc_hash->size (),
3020 (long) tree_scc_hash->elements (),
3021 tree_scc_hash->collisions ());
3022 hash_table<tree_scc_hasher>::iterator hiter;
3023 tree_scc *scc, *max_scc = NULL;
3024 unsigned max_length = 0;
3025 FOR_EACH_HASH_TABLE_ELEMENT (*tree_scc_hash, scc, x, hiter)
3027 unsigned length = 0;
3028 tree_scc *s = scc;
3029 for (; s; s = s->next)
3030 length++;
3031 if (length > max_length)
3033 max_length = length;
3034 max_scc = scc;
3037 fprintf (stderr, "[%s] tree SCC max chain length %u (size %u)\n",
3038 pfx, max_length, max_scc->len);
3039 fprintf (stderr, "[%s] Compared %lu SCCs, %lu collisions (%f)\n", pfx,
3040 num_scc_compares, num_scc_compare_collisions,
3041 num_scc_compare_collisions / (double) num_scc_compares);
3042 fprintf (stderr, "[%s] Merged %lu SCCs\n", pfx, num_sccs_merged);
3043 fprintf (stderr, "[%s] Merged %lu tree bodies\n", pfx,
3044 total_scc_size_merged);
3045 fprintf (stderr, "[%s] Merged %lu types\n", pfx, num_merged_types);
3046 fprintf (stderr, "[%s] %lu types prevailed (%lu associated trees)\n",
3047 pfx, num_prevailing_types, num_type_scc_trees);
3048 fprintf (stderr, "[%s] GIMPLE canonical type table: size %ld, "
3049 "%ld elements, %ld searches, %ld collisions (ratio: %f)\n", pfx,
3050 (long) htab_size (gimple_canonical_types),
3051 (long) htab_elements (gimple_canonical_types),
3052 (long) gimple_canonical_types->searches,
3053 (long) gimple_canonical_types->collisions,
3054 htab_collisions (gimple_canonical_types));
3055 fprintf (stderr, "[%s] GIMPLE canonical type pointer-map: "
3056 "%lu elements, %ld searches\n", pfx,
3057 num_canonical_type_hash_entries,
3058 num_canonical_type_hash_queries);
3061 print_lto_report (pfx);
3064 /* Perform whole program analysis (WPA) on the callgraph and write out the
3065 optimization plan. */
3067 static void
3068 do_whole_program_analysis (void)
3070 symtab_node *node;
3072 lto_parallelism = 1;
3074 /* TODO: jobserver communicatoin is not supported, yet. */
3075 if (!strcmp (flag_wpa, "jobserver"))
3076 lto_parallelism = -1;
3077 else
3079 lto_parallelism = atoi (flag_wpa);
3080 if (lto_parallelism <= 0)
3081 lto_parallelism = 0;
3084 timevar_start (TV_PHASE_OPT_GEN);
3086 /* Note that since we are in WPA mode, materialize_cgraph will not
3087 actually read in all the function bodies. It only materializes
3088 the decls and cgraph nodes so that analysis can be performed. */
3089 materialize_cgraph ();
3091 /* Reading in the cgraph uses different timers, start timing WPA now. */
3092 timevar_push (TV_WHOPR_WPA);
3094 if (pre_ipa_mem_report)
3096 fprintf (stderr, "Memory consumption before IPA\n");
3097 dump_memory_report (false);
3100 symtab->function_flags_ready = true;
3102 if (symtab->dump_file)
3103 symtab->dump (symtab->dump_file);
3104 bitmap_obstack_initialize (NULL);
3105 symtab->state = IPA_SSA;
3107 execute_ipa_pass_list (g->get_passes ()->all_regular_ipa_passes);
3109 /* When WPA analysis raises errors, do not bother to output anything. */
3110 if (seen_error ())
3111 return;
3113 if (symtab->dump_file)
3115 fprintf (symtab->dump_file, "Optimized ");
3116 symtab->dump (symtab->dump_file);
3119 symtab_node::checking_verify_symtab_nodes ();
3120 bitmap_obstack_release (NULL);
3122 /* We are about to launch the final LTRANS phase, stop the WPA timer. */
3123 timevar_pop (TV_WHOPR_WPA);
3125 timevar_push (TV_WHOPR_PARTITIONING);
3126 if (flag_lto_partition == LTO_PARTITION_1TO1)
3127 lto_1_to_1_map ();
3128 else if (flag_lto_partition == LTO_PARTITION_MAX)
3129 lto_max_map ();
3130 else if (flag_lto_partition == LTO_PARTITION_ONE)
3131 lto_balanced_map (1, INT_MAX);
3132 else if (flag_lto_partition == LTO_PARTITION_BALANCED)
3133 lto_balanced_map (PARAM_VALUE (PARAM_LTO_PARTITIONS),
3134 PARAM_VALUE (MAX_PARTITION_SIZE));
3135 else
3136 gcc_unreachable ();
3138 /* Inline summaries are needed for balanced partitioning. Free them now so
3139 the memory can be used for streamer caches. */
3140 ipa_free_fn_summary ();
3142 /* AUX pointers are used by partitioning code to bookkeep number of
3143 partitions symbol is in. This is no longer needed. */
3144 FOR_EACH_SYMBOL (node)
3145 node->aux = NULL;
3147 lto_stats.num_cgraph_partitions += ltrans_partitions.length ();
3149 /* Find out statics that need to be promoted
3150 to globals with hidden visibility because they are accessed from multiple
3151 partitions. */
3152 lto_promote_cross_file_statics ();
3153 timevar_pop (TV_WHOPR_PARTITIONING);
3155 timevar_stop (TV_PHASE_OPT_GEN);
3157 /* Collect a last time - in lto_wpa_write_files we may end up forking
3158 with the idea that this doesn't increase memory usage. So we
3159 absoultely do not want to collect after that. */
3160 ggc_collect ();
3162 timevar_start (TV_PHASE_STREAM_OUT);
3163 if (!quiet_flag)
3165 fprintf (stderr, "\nStreaming out");
3166 fflush (stderr);
3168 lto_wpa_write_files ();
3169 if (!quiet_flag)
3170 fprintf (stderr, "\n");
3171 timevar_stop (TV_PHASE_STREAM_OUT);
3173 if (post_ipa_mem_report)
3175 fprintf (stderr, "Memory consumption after IPA\n");
3176 dump_memory_report (false);
3179 /* Show the LTO report before launching LTRANS. */
3180 if (flag_lto_report || (flag_wpa && flag_lto_report_wpa))
3181 print_lto_report_1 ();
3182 if (mem_report_wpa)
3183 dump_memory_report (true);
3187 static GTY(()) tree lto_eh_personality_decl;
3189 /* Return the LTO personality function decl. */
3191 tree
3192 lto_eh_personality (void)
3194 if (!lto_eh_personality_decl)
3196 /* Use the first personality DECL for our personality if we don't
3197 support multiple ones. This ensures that we don't artificially
3198 create the need for them in a single-language program. */
3199 if (first_personality_decl && !dwarf2out_do_cfi_asm ())
3200 lto_eh_personality_decl = first_personality_decl;
3201 else
3202 lto_eh_personality_decl = lhd_gcc_personality ();
3205 return lto_eh_personality_decl;
3208 /* Set the process name based on the LTO mode. */
3210 static void
3211 lto_process_name (void)
3213 if (flag_lto)
3214 setproctitle ("lto1-lto");
3215 if (flag_wpa)
3216 setproctitle ("lto1-wpa");
3217 if (flag_ltrans)
3218 setproctitle ("lto1-ltrans");
3222 /* Initialize the LTO front end. */
3224 static void
3225 lto_init (void)
3227 lto_process_name ();
3228 lto_streamer_hooks_init ();
3229 lto_reader_init ();
3230 lto_set_in_hooks (NULL, get_section_data, free_section_data);
3231 memset (&lto_stats, 0, sizeof (lto_stats));
3232 bitmap_obstack_initialize (NULL);
3233 gimple_register_cfg_hooks ();
3234 #ifndef ACCEL_COMPILER
3235 unsigned char *table
3236 = ggc_vec_alloc<unsigned char> (MAX_MACHINE_MODE);
3237 for (int m = 0; m < MAX_MACHINE_MODE; m++)
3238 table[m] = m;
3239 lto_mode_identity_table = table;
3240 #endif
3243 /* Create artificial pointers for "omp declare target link" vars. */
3245 static void
3246 offload_handle_link_vars (void)
3248 #ifdef ACCEL_COMPILER
3249 varpool_node *var;
3250 FOR_EACH_VARIABLE (var)
3251 if (lookup_attribute ("omp declare target link",
3252 DECL_ATTRIBUTES (var->decl)))
3254 tree type = build_pointer_type (TREE_TYPE (var->decl));
3255 tree link_ptr_var = make_node (VAR_DECL);
3256 TREE_TYPE (link_ptr_var) = type;
3257 TREE_USED (link_ptr_var) = 1;
3258 TREE_STATIC (link_ptr_var) = 1;
3259 SET_DECL_MODE (link_ptr_var, TYPE_MODE (type));
3260 DECL_SIZE (link_ptr_var) = TYPE_SIZE (type);
3261 DECL_SIZE_UNIT (link_ptr_var) = TYPE_SIZE_UNIT (type);
3262 DECL_ARTIFICIAL (link_ptr_var) = 1;
3263 tree var_name = DECL_ASSEMBLER_NAME (var->decl);
3264 char *new_name
3265 = ACONCAT ((IDENTIFIER_POINTER (var_name), "_linkptr", NULL));
3266 DECL_NAME (link_ptr_var) = get_identifier (new_name);
3267 SET_DECL_ASSEMBLER_NAME (link_ptr_var, DECL_NAME (link_ptr_var));
3268 SET_DECL_VALUE_EXPR (var->decl, build_simple_mem_ref (link_ptr_var));
3269 DECL_HAS_VALUE_EXPR_P (var->decl) = 1;
3271 #endif
3275 /* Main entry point for the GIMPLE front end. This front end has
3276 three main personalities:
3278 - LTO (-flto). All the object files on the command line are
3279 loaded in memory and processed as a single translation unit.
3280 This is the traditional link-time optimization behavior.
3282 - WPA (-fwpa). Only the callgraph and summary information for
3283 files in the command file are loaded. A single callgraph
3284 (without function bodies) is instantiated for the whole set of
3285 files. IPA passes are only allowed to analyze the call graph
3286 and make transformation decisions. The callgraph is
3287 partitioned, each partition is written to a new object file
3288 together with the transformation decisions.
3290 - LTRANS (-fltrans). Similar to -flto but it prevents the IPA
3291 summary files from running again. Since WPA computed summary
3292 information and decided what transformations to apply, LTRANS
3293 simply applies them. */
3295 void
3296 lto_main (void)
3298 /* LTO is called as a front end, even though it is not a front end.
3299 Because it is called as a front end, TV_PHASE_PARSING and
3300 TV_PARSE_GLOBAL are active, and we need to turn them off while
3301 doing LTO. Later we turn them back on so they are active up in
3302 toplev.c. */
3303 timevar_pop (TV_PARSE_GLOBAL);
3304 timevar_stop (TV_PHASE_PARSING);
3306 timevar_start (TV_PHASE_SETUP);
3308 /* Initialize the LTO front end. */
3309 lto_init ();
3311 timevar_stop (TV_PHASE_SETUP);
3312 timevar_start (TV_PHASE_STREAM_IN);
3314 /* Read all the symbols and call graph from all the files in the
3315 command line. */
3316 read_cgraph_and_symbols (num_in_fnames, in_fnames);
3318 timevar_stop (TV_PHASE_STREAM_IN);
3320 if (!seen_error ())
3322 offload_handle_link_vars ();
3324 /* If WPA is enabled analyze the whole call graph and create an
3325 optimization plan. Otherwise, read in all the function
3326 bodies and continue with optimization. */
3327 if (flag_wpa)
3328 do_whole_program_analysis ();
3329 else
3331 timevar_start (TV_PHASE_OPT_GEN);
3333 materialize_cgraph ();
3334 if (!flag_ltrans)
3335 lto_promote_statics_nonwpa ();
3337 /* Annotate the CU DIE and mark the early debug phase as finished. */
3338 debug_hooks->early_finish ("<artificial>");
3340 /* Let the middle end know that we have read and merged all of
3341 the input files. */
3342 symtab->compile ();
3344 timevar_stop (TV_PHASE_OPT_GEN);
3346 /* FIXME lto, if the processes spawned by WPA fail, we miss
3347 the chance to print WPA's report, so WPA will call
3348 print_lto_report before launching LTRANS. If LTRANS was
3349 launched directly by the driver we would not need to do
3350 this. */
3351 if (flag_lto_report || (flag_wpa && flag_lto_report_wpa))
3352 print_lto_report_1 ();
3356 /* Here we make LTO pretend to be a parser. */
3357 timevar_start (TV_PHASE_PARSING);
3358 timevar_push (TV_PARSE_GLOBAL);
3361 #include "gt-lto-lto.h"