Line data Source code
1 : /* Pass to free or clear language-specific data structures from
2 : the IL before they reach the middle end.
3 :
4 : Copyright (C) 1987-2026 Free Software Foundation, Inc.
5 :
6 : This file is part of GCC.
7 :
8 : GCC is free software; you can redistribute it and/or modify it under
9 : the terms of the GNU General Public License as published by the Free
10 : Software Foundation; either version 3, or (at your option) any later
11 : version.
12 :
13 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 : for more details.
17 :
18 : You should have received a copy of the GNU General Public License
19 : along with GCC; see the file COPYING3. If not see
20 : <http://www.gnu.org/licenses/>. */
21 :
22 : /* This file contains the low level primitives for operating on tree nodes,
23 : including allocation, list operations, interning of identifiers,
24 : construction of data type nodes and statement nodes,
25 : and construction of type conversion nodes. It also contains
26 : tables index by tree code that describe how to take apart
27 : nodes of that code.
28 :
29 : It is intended to be language-independent but can occasionally
30 : calls language-dependent routines. */
31 :
32 : #include "config.h"
33 : #include "system.h"
34 : #include "coretypes.h"
35 : #include "backend.h"
36 : #include "target.h"
37 : #include "tree.h"
38 : #include "gimple.h"
39 : #include "tree-pass.h"
40 : #include "ssa.h"
41 : #include "cgraph.h"
42 : #include "diagnostic.h"
43 : #include "alias.h"
44 : #include "attribs.h"
45 : #include "langhooks.h"
46 : #include "gimple-iterator.h"
47 : #include "langhooks-def.h"
48 : #include "tree-diagnostic.h"
49 : #include "except.h"
50 : #include "ipa-utils.h"
51 :
52 : namespace {
53 :
54 : /* Data used when collecting DECLs and TYPEs for language data removal. */
55 :
56 : class free_lang_data_d
57 : {
58 : public:
59 239068 : free_lang_data_d () : decls (100), types (100) {}
60 :
61 : /* Worklist to avoid excessive recursion. */
62 : auto_vec<tree> worklist;
63 :
64 : /* Set of traversed objects. Used to avoid duplicate visits. */
65 : hash_set<tree> pset;
66 :
67 : /* Array of symbols to process with free_lang_data_in_decl. */
68 : auto_vec<tree> decls;
69 :
70 : /* Array of types to process with free_lang_data_in_type. */
71 : auto_vec<tree> types;
72 : };
73 :
74 :
75 : /* Add type or decl T to one of the list of tree nodes that need their
76 : language data removed. The lists are held inside FLD. */
77 :
78 : static void
79 2969117 : add_tree_to_fld_list (tree t, class free_lang_data_d *fld)
80 : {
81 2969117 : if (DECL_P (t))
82 2060969 : fld->decls.safe_push (t);
83 908148 : else if (TYPE_P (t))
84 908148 : fld->types.safe_push (t);
85 : else
86 0 : gcc_unreachable ();
87 2969117 : }
88 :
89 : /* Push tree node T into FLD->WORKLIST. */
90 :
91 : static inline void
92 35430190 : fld_worklist_push (tree t, class free_lang_data_d *fld)
93 : {
94 57019769 : if (t && !is_lang_specific (t) && !fld->pset.contains (t))
95 5568081 : fld->worklist.safe_push ((t));
96 35430190 : }
97 :
98 :
99 :
100 : /* Return simplified TYPE_NAME of TYPE. */
101 :
102 : static tree
103 1101907 : fld_simplified_type_name (tree type)
104 : {
105 1101907 : if (!TYPE_NAME (type) || TREE_CODE (TYPE_NAME (type)) != TYPE_DECL)
106 887580 : return TYPE_NAME (type);
107 : /* Drop TYPE_DECLs in TYPE_NAME in favor of the identifier in the
108 : TYPE_DECL if the type doesn't have linkage.
109 : this must match fld_ */
110 214327 : if (type != TYPE_MAIN_VARIANT (type)
111 214327 : || (!DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (type))
112 87103 : && (TREE_CODE (type) != RECORD_TYPE
113 7961 : || !TYPE_BINFO (type)
114 0 : || !BINFO_VTABLE (TYPE_BINFO (type)))))
115 168437 : return DECL_NAME (TYPE_NAME (type));
116 45890 : return TYPE_NAME (type);
117 : }
118 :
119 : /* Do same comparison as check_qualified_type skipping lang part of type
120 : and be more permissive about type names: we only care that names are
121 : same (for diagnostics) and that ODR names are the same.
122 : If INNER_TYPE is non-NULL, be sure that TREE_TYPE match it. */
123 :
124 : static bool
125 107366 : fld_type_variant_equal_p (tree t, tree v, tree inner_type)
126 : {
127 107366 : if (TYPE_QUALS (t) != TYPE_QUALS (v)
128 : /* We want to match incomplete variants with complete types.
129 : In this case we need to ignore alignment. */
130 89881 : || ((!RECORD_OR_UNION_TYPE_P (t) || COMPLETE_TYPE_P (v))
131 66782 : && (TYPE_ALIGN (t) != TYPE_ALIGN (v)
132 66766 : || TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (v)))
133 89865 : || fld_simplified_type_name (t) != fld_simplified_type_name (v)
134 75115 : || !attribute_list_equal (TYPE_ATTRIBUTES (t),
135 75115 : TYPE_ATTRIBUTES (v))
136 75115 : || (inner_type && TREE_TYPE (v) != inner_type))
137 32251 : return false;
138 :
139 : return true;
140 : }
141 :
142 : /* Find variant of FIRST that match T and create new one if necessary.
143 : Set TREE_TYPE to INNER_TYPE if non-NULL. */
144 :
145 : static tree
146 75115 : fld_type_variant (tree first, tree t, class free_lang_data_d *fld,
147 : tree inner_type = NULL)
148 : {
149 75115 : if (first == TYPE_MAIN_VARIANT (t))
150 : return t;
151 98171 : for (tree v = first; v; v = TYPE_NEXT_VARIANT (v))
152 91183 : if (fld_type_variant_equal_p (t, v, inner_type))
153 : {
154 68127 : if (flag_checking)
155 77322 : for (tree v2 = TYPE_NEXT_VARIANT (v); v2; v2 = TYPE_NEXT_VARIANT (v2))
156 9195 : gcc_assert (!fld_type_variant_equal_p (t, v2, inner_type));
157 : return v;
158 : }
159 6988 : tree v = build_variant_type_copy (first);
160 6988 : TYPE_READONLY (v) = TYPE_READONLY (t);
161 6988 : TYPE_VOLATILE (v) = TYPE_VOLATILE (t);
162 6988 : TYPE_ATOMIC (v) = TYPE_ATOMIC (t);
163 6988 : TYPE_RESTRICT (v) = TYPE_RESTRICT (t);
164 6988 : TYPE_ADDR_SPACE (v) = TYPE_ADDR_SPACE (t);
165 6988 : TYPE_NAME (v) = TYPE_NAME (t);
166 6988 : TYPE_ATTRIBUTES (v) = TYPE_ATTRIBUTES (t);
167 6988 : TYPE_CANONICAL (v) = TYPE_CANONICAL (t);
168 : /* Variants of incomplete types should have alignment
169 : set to BITS_PER_UNIT. Do not copy the actual alignment. */
170 6988 : if (!RECORD_OR_UNION_TYPE_P (v) || COMPLETE_TYPE_P (v))
171 : {
172 1631 : SET_TYPE_ALIGN (v, TYPE_ALIGN (t));
173 1631 : TYPE_USER_ALIGN (v) = TYPE_USER_ALIGN (t);
174 : }
175 6988 : if (inner_type)
176 22 : TREE_TYPE (v) = inner_type;
177 6988 : gcc_checking_assert (fld_type_variant_equal_p (t,v, inner_type));
178 6988 : if (!fld->pset.add (v))
179 6988 : add_tree_to_fld_list (v, fld);
180 : return v;
181 : }
182 :
183 : /* Map complete types to incomplete types. */
184 :
185 : static hash_map<tree, tree> *fld_incomplete_types;
186 :
187 : /* Map types to simplified types. */
188 :
189 : static hash_map<tree, tree> *fld_simplified_types;
190 :
191 : /* Produce variant of T whose TREE_TYPE is T2. If it is main variant,
192 : use MAP to prevent duplicates. */
193 :
194 : static tree
195 2869 : fld_process_array_type (tree t, tree t2, hash_map<tree, tree> *map,
196 : class free_lang_data_d *fld)
197 : {
198 2869 : if (TREE_TYPE (t) == t2)
199 : return t;
200 :
201 110 : if (TYPE_MAIN_VARIANT (t) != t)
202 : {
203 22 : return fld_type_variant
204 22 : (fld_process_array_type (TYPE_MAIN_VARIANT (t),
205 22 : TYPE_MAIN_VARIANT (t2), map, fld),
206 22 : t, fld, t2);
207 : }
208 :
209 88 : bool existed;
210 88 : tree &array
211 88 : = map->get_or_insert (t, &existed);
212 88 : if (!existed)
213 : {
214 31 : array
215 31 : = build_array_type_1 (t2, TYPE_DOMAIN (t), TYPE_TYPELESS_STORAGE (t),
216 : false, false);
217 31 : TYPE_CANONICAL (array) = TYPE_CANONICAL (t);
218 31 : if (!fld->pset.add (array))
219 31 : add_tree_to_fld_list (array, fld);
220 : }
221 88 : return array;
222 : }
223 :
224 : /* Return CTX after removal of contexts that are not relevant */
225 :
226 : static tree
227 1948990 : fld_decl_context (tree ctx)
228 : {
229 : /* Variably modified types are needed for tree_is_indexable to decide
230 : whether the type needs to go to local or global section.
231 : This code is semi-broken but for now it is easiest to keep contexts
232 : as expected. */
233 1797983 : if (ctx && TYPE_P (ctx)
234 1986691 : && !variably_modified_type_p (ctx, NULL_TREE))
235 : {
236 80523 : while (ctx && TYPE_P (ctx))
237 42822 : ctx = TYPE_CONTEXT (ctx);
238 : }
239 1948990 : return ctx;
240 : }
241 :
242 : /* For T being aggregate type try to turn it into an incomplete variant.
243 : Return T if no simplification is possible. */
244 :
245 : static tree
246 376980 : fld_incomplete_type_of (tree t, class free_lang_data_d *fld)
247 : {
248 376980 : if (!t)
249 : return NULL;
250 376980 : if (POINTER_TYPE_P (t))
251 : {
252 183175 : tree t2 = fld_incomplete_type_of (TREE_TYPE (t), fld);
253 183175 : if (t2 != TREE_TYPE (t))
254 : {
255 59355 : tree first;
256 59355 : if (TREE_CODE (t) == POINTER_TYPE)
257 48074 : first = build_pointer_type_for_mode (t2, TYPE_MODE (t),
258 48074 : TYPE_REF_CAN_ALIAS_ALL (t));
259 : else
260 11281 : first = build_reference_type_for_mode (t2, TYPE_MODE (t),
261 11281 : TYPE_REF_CAN_ALIAS_ALL (t));
262 59355 : gcc_assert (TYPE_CANONICAL (t2) != t2
263 : && TYPE_CANONICAL (t2) == TYPE_CANONICAL (TREE_TYPE (t)));
264 59355 : if (!fld->pset.add (first))
265 20276 : add_tree_to_fld_list (first, fld);
266 59355 : return fld_type_variant (first, t, fld);
267 : }
268 : return t;
269 : }
270 193805 : if (TREE_CODE (t) == ARRAY_TYPE)
271 2847 : return fld_process_array_type (t,
272 2847 : fld_incomplete_type_of (TREE_TYPE (t), fld),
273 2847 : fld_incomplete_types, fld);
274 190958 : if ((!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
275 190958 : || !COMPLETE_TYPE_P (t))
276 : return t;
277 73375 : if (TYPE_MAIN_VARIANT (t) == t)
278 : {
279 57637 : bool existed;
280 57637 : tree ©
281 57637 : = fld_incomplete_types->get_or_insert (t, &existed);
282 :
283 57637 : if (!existed)
284 : {
285 13906 : copy = build_distinct_type_copy (t);
286 :
287 : /* It is possible that type was not seen by free_lang_data yet. */
288 13906 : if (!fld->pset.add (copy))
289 13906 : add_tree_to_fld_list (copy, fld);
290 13906 : TYPE_SIZE (copy) = NULL;
291 13906 : TYPE_USER_ALIGN (copy) = 0;
292 13906 : TYPE_SIZE_UNIT (copy) = NULL;
293 13906 : TYPE_CANONICAL (copy) = TYPE_CANONICAL (t);
294 13906 : TREE_ADDRESSABLE (copy) = 0;
295 13906 : if (AGGREGATE_TYPE_P (t))
296 : {
297 13832 : SET_TYPE_MODE (copy, VOIDmode);
298 13832 : SET_TYPE_ALIGN (copy, BITS_PER_UNIT);
299 13832 : TYPE_TYPELESS_STORAGE (copy) = 0;
300 13832 : TYPE_FIELDS (copy) = NULL;
301 13832 : TYPE_BINFO (copy) = NULL;
302 13832 : TYPE_FINAL_P (copy) = 0;
303 13832 : TYPE_EMPTY_P (copy) = 0;
304 : }
305 : else
306 : {
307 74 : TYPE_VALUES (copy) = NULL;
308 74 : ENUM_IS_OPAQUE (copy) = 0;
309 74 : ENUM_IS_SCOPED (copy) = 0;
310 : }
311 :
312 : /* Build copy of TYPE_DECL in TYPE_NAME if necessary.
313 : This is needed for ODR violation warnings to come out right (we
314 : want duplicate TYPE_DECLs whenever the type is duplicated because
315 : of ODR violation. Because lang data in the TYPE_DECL may not
316 : have been freed yet, rebuild it from scratch and copy relevant
317 : fields. */
318 13906 : TYPE_NAME (copy) = fld_simplified_type_name (copy);
319 13906 : tree name = TYPE_NAME (copy);
320 :
321 13906 : if (name && TREE_CODE (name) == TYPE_DECL)
322 : {
323 8855 : gcc_checking_assert (TREE_TYPE (name) == t);
324 8855 : tree name2 = build_decl (DECL_SOURCE_LOCATION (name), TYPE_DECL,
325 8855 : DECL_NAME (name), copy);
326 8855 : if (DECL_ASSEMBLER_NAME_SET_P (name))
327 8855 : SET_DECL_ASSEMBLER_NAME (name2, DECL_ASSEMBLER_NAME (name));
328 8855 : SET_DECL_ALIGN (name2, 0);
329 8855 : DECL_CONTEXT (name2) = fld_decl_context
330 8855 : (DECL_CONTEXT (name));
331 8855 : TYPE_NAME (copy) = name2;
332 : }
333 : }
334 57637 : return copy;
335 : }
336 15738 : return (fld_type_variant
337 15738 : (fld_incomplete_type_of (TYPE_MAIN_VARIANT (t), fld), t, fld));
338 : }
339 :
340 : /* Simplify type T for scenarios where we do not need complete pointer
341 : types. */
342 :
343 : static tree
344 1231872 : fld_simplified_type (tree t, class free_lang_data_d *fld)
345 : {
346 1231872 : if (!t)
347 : return t;
348 1231872 : if (POINTER_TYPE_P (t))
349 175220 : return fld_incomplete_type_of (t, fld);
350 : /* FIXME: This triggers verification error, see PR88140. */
351 : #if 0
352 : if (TREE_CODE (t) == ARRAY_TYPE)
353 : return fld_process_array_type (t, fld_simplified_type (TREE_TYPE (t), fld),
354 : fld_simplified_types, fld);
355 : #endif
356 : return t;
357 : }
358 :
359 : /* Reset the expression *EXPR_P, a size or position.
360 :
361 : ??? We could reset all non-constant sizes or positions. But it's cheap
362 : enough to not do so and refrain from adding workarounds to dwarf2out.cc.
363 :
364 : We need to reset self-referential sizes or positions because they cannot
365 : be gimplified and thus can contain a CALL_EXPR after the gimplification
366 : is finished, which will run afoul of LTO streaming. And they need to be
367 : reset to something essentially dummy but not constant, so as to preserve
368 : the properties of the object they are attached to. */
369 :
370 : static inline void
371 6366697 : free_lang_data_in_one_sizepos (tree *expr_p)
372 : {
373 6366697 : tree expr = *expr_p;
374 6366697 : if (CONTAINS_PLACEHOLDER_P (expr))
375 0 : *expr_p = build0 (PLACEHOLDER_EXPR, TREE_TYPE (expr));
376 6366697 : }
377 :
378 :
379 : /* Reset all the fields in a binfo node BINFO. We only keep
380 : BINFO_VTABLE, which is used by gimple_fold_obj_type_ref. */
381 :
382 : static void
383 39568 : free_lang_data_in_binfo (tree binfo)
384 : {
385 39568 : unsigned i;
386 39568 : tree t;
387 :
388 39568 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
389 :
390 39568 : BINFO_VIRTUALS (binfo) = NULL_TREE;
391 39568 : BINFO_BASE_ACCESSES (binfo) = NULL;
392 39568 : BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE;
393 39568 : BINFO_SUBVTT_INDEX (binfo) = NULL_TREE;
394 39568 : BINFO_VPTR_FIELD (binfo) = NULL_TREE;
395 39568 : TREE_PUBLIC (binfo) = 0;
396 :
397 54107 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo), i, t)
398 14539 : free_lang_data_in_binfo (t);
399 39568 : }
400 :
401 :
402 : /* Reset all language specific information still present in TYPE. */
403 :
404 : static void
405 908271 : free_lang_data_in_type (tree type, class free_lang_data_d *fld)
406 : {
407 908271 : gcc_assert (TYPE_P (type));
408 :
409 : /* Give the FE a chance to remove its own data first. */
410 908271 : lang_hooks.free_lang_data (type);
411 :
412 908271 : TREE_LANG_FLAG_0 (type) = 0;
413 908271 : TREE_LANG_FLAG_1 (type) = 0;
414 908271 : TREE_LANG_FLAG_2 (type) = 0;
415 908271 : TREE_LANG_FLAG_3 (type) = 0;
416 908271 : TREE_LANG_FLAG_4 (type) = 0;
417 908271 : TREE_LANG_FLAG_5 (type) = 0;
418 908271 : TREE_LANG_FLAG_6 (type) = 0;
419 :
420 908271 : TYPE_NEEDS_CONSTRUCTING (type) = 0;
421 :
422 : /* Purge non-marked variants from the variants chain, so that they
423 : don't reappear in the IL after free_lang_data. */
424 908271 : while (TYPE_NEXT_VARIANT (type)
425 1395349 : && !fld->pset.contains (TYPE_NEXT_VARIANT (type)))
426 : {
427 487078 : tree t = TYPE_NEXT_VARIANT (type);
428 487078 : TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (t);
429 : /* Turn the removed types into distinct types. */
430 487078 : TYPE_MAIN_VARIANT (t) = t;
431 487078 : TYPE_NEXT_VARIANT (t) = NULL_TREE;
432 : }
433 :
434 908271 : if (TREE_CODE (type) == FUNCTION_TYPE)
435 : {
436 137530 : TREE_TYPE (type) = fld_simplified_type (TREE_TYPE (type), fld);
437 : /* Remove the const and volatile qualifiers from arguments. The
438 : C++ front end removes them, but the C front end does not,
439 : leading to false ODR violation errors when merging two
440 : instances of the same function signature compiled by
441 : different front ends. */
442 619333 : for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
443 : {
444 481803 : tree arg_type = TREE_VALUE (p);
445 481803 : if (TYPE_READONLY (arg_type) || TYPE_VOLATILE (arg_type))
446 : {
447 309 : auto quals = (TYPE_QUALS (arg_type)
448 309 : .without (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE));
449 309 : TREE_VALUE (p) = build_qualified_type (arg_type, quals);
450 309 : if (!fld->pset.add (TREE_VALUE (p)))
451 123 : free_lang_data_in_type (TREE_VALUE (p), fld);
452 : }
453 481803 : TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
454 : /* C++ FE uses TREE_PURPOSE to store initial values. */
455 481803 : TREE_PURPOSE (p) = NULL;
456 : }
457 : }
458 : else if (TREE_CODE (type) == METHOD_TYPE)
459 : {
460 32765 : TREE_TYPE (type) = fld_simplified_type (TREE_TYPE (type), fld);
461 123906 : for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
462 : {
463 : /* C++ FE uses TREE_PURPOSE to store initial values. */
464 91141 : TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
465 91141 : TREE_PURPOSE (p) = NULL;
466 : }
467 : }
468 : else if (RECORD_OR_UNION_TYPE_P (type))
469 : {
470 : /* Remove members that are not FIELD_DECLs from the field list
471 : of an aggregate. These occur in C++. */
472 537112 : for (tree *prev = &TYPE_FIELDS (type), member; (member = *prev);)
473 444184 : if (TREE_CODE (member) == FIELD_DECL)
474 140641 : prev = &DECL_CHAIN (member);
475 : else
476 303543 : *prev = DECL_CHAIN (member);
477 :
478 92928 : TYPE_VFIELD (type) = NULL_TREE;
479 :
480 92928 : if (TYPE_BINFO (type))
481 : {
482 25029 : free_lang_data_in_binfo (TYPE_BINFO (type));
483 : /* We need to preserve link to bases and virtual table for all
484 : polymorphic types to make devirtualization machinery working. */
485 25029 : if (!BINFO_VTABLE (TYPE_BINFO (type)))
486 22747 : TYPE_BINFO (type) = NULL;
487 : }
488 : }
489 : else if (INTEGRAL_TYPE_P (type)
490 : || SCALAR_FLOAT_TYPE_P (type)
491 : || FIXED_POINT_TYPE_P (type))
492 : {
493 160929 : if (TREE_CODE (type) == ENUMERAL_TYPE)
494 : {
495 1212 : ENUM_IS_OPAQUE (type) = 0;
496 1212 : ENUM_IS_SCOPED (type) = 0;
497 : /* Type values are used only for C++ ODR checking. Drop them
498 : for all type variants and non-ODR types.
499 : For ODR types the data is freed in free_odr_warning_data. */
500 1212 : if (!TYPE_VALUES (type))
501 : ;
502 1034 : else if (TYPE_MAIN_VARIANT (type) != type
503 700 : || !type_with_linkage_p (type)
504 1381 : || type_in_anonymous_namespace_p (type))
505 691 : TYPE_VALUES (type) = NULL;
506 : else
507 343 : register_odr_enum (type);
508 : }
509 160929 : free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type));
510 160929 : free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type));
511 : }
512 :
513 908271 : TYPE_LANG_SLOT_1 (type) = NULL_TREE;
514 :
515 908271 : free_lang_data_in_one_sizepos (&TYPE_SIZE (type));
516 908271 : free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type));
517 :
518 908271 : if (TYPE_CONTEXT (type)
519 908271 : && TREE_CODE (TYPE_CONTEXT (type)) == BLOCK)
520 : {
521 0 : tree ctx = TYPE_CONTEXT (type);
522 0 : do
523 : {
524 0 : ctx = BLOCK_SUPERCONTEXT (ctx);
525 : }
526 0 : while (ctx && TREE_CODE (ctx) == BLOCK);
527 0 : TYPE_CONTEXT (type) = ctx;
528 : }
529 :
530 908271 : TYPE_STUB_DECL (type) = NULL;
531 908271 : TYPE_NAME (type) = fld_simplified_type_name (type);
532 908271 : }
533 :
534 : /* Reset all language specific information still present in symbol
535 : DECL. */
536 :
537 : static void
538 2060969 : free_lang_data_in_decl (tree decl, class free_lang_data_d *fld)
539 : {
540 2060969 : gcc_assert (DECL_P (decl));
541 :
542 : /* Give the FE a chance to remove its own data first. */
543 2060969 : lang_hooks.free_lang_data (decl);
544 :
545 2060969 : TREE_LANG_FLAG_0 (decl) = 0;
546 2060969 : TREE_LANG_FLAG_1 (decl) = 0;
547 2060969 : TREE_LANG_FLAG_2 (decl) = 0;
548 2060969 : TREE_LANG_FLAG_3 (decl) = 0;
549 2060969 : TREE_LANG_FLAG_4 (decl) = 0;
550 2060969 : TREE_LANG_FLAG_5 (decl) = 0;
551 2060969 : TREE_LANG_FLAG_6 (decl) = 0;
552 :
553 2060969 : free_lang_data_in_one_sizepos (&DECL_SIZE (decl));
554 2060969 : free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl));
555 2060969 : if (TREE_CODE (decl) == FIELD_DECL)
556 : {
557 106359 : DECL_FCONTEXT (decl) = NULL;
558 106359 : free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl));
559 106359 : if (TREE_CODE (DECL_CONTEXT (decl)) == QUAL_UNION_TYPE)
560 0 : DECL_QUALIFIER (decl) = NULL_TREE;
561 : }
562 :
563 2060969 : if (TREE_CODE (decl) == FUNCTION_DECL)
564 : {
565 382274 : struct cgraph_node *node;
566 : /* Frontends do not set TREE_ADDRESSABLE on public variables even though
567 : the address may be taken in other unit, so this flag has no practical
568 : use for middle-end.
569 :
570 : It would make more sense if frontends set TREE_ADDRESSABLE to 0 only
571 : for public objects that indeed cannot be addressed, but it is not
572 : the case. Set the flag to true so we do not get merge failures for
573 : i.e. virtual tables between units that take address of it and
574 : units that don't. */
575 382274 : if (TREE_PUBLIC (decl))
576 368681 : TREE_ADDRESSABLE (decl) = true;
577 382274 : TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
578 382274 : if (!(node = cgraph_node::get (decl))
579 382274 : || (!node->definition && !node->clones))
580 : {
581 250059 : if (node)
582 238108 : node->release_body ();
583 : else
584 : {
585 11951 : release_function_body (decl);
586 11951 : DECL_ARGUMENTS (decl) = NULL;
587 11951 : DECL_RESULT (decl) = NULL;
588 11951 : DECL_INITIAL (decl) = error_mark_node;
589 : }
590 : }
591 382274 : if (gimple_has_body_p (decl) || (node && node->thunk))
592 : {
593 125494 : tree t;
594 :
595 : /* If DECL has a gimple body, then the context for its
596 : arguments must be DECL. Otherwise, it doesn't really
597 : matter, as we will not be emitting any code for DECL. In
598 : general, there may be other instances of DECL created by
599 : the front end and since PARM_DECLs are generally shared,
600 : their DECL_CONTEXT changes as the replicas of DECL are
601 : created. The only time where DECL_CONTEXT is important
602 : is for the FUNCTION_DECLs that have a gimple body (since
603 : the PARM_DECL will be used in the function's body). */
604 477509 : for (t = DECL_ARGUMENTS (decl); t; t = TREE_CHAIN (t))
605 352015 : DECL_CONTEXT (t) = decl;
606 125494 : if (!DECL_FUNCTION_SPECIFIC_TARGET (decl))
607 125478 : DECL_FUNCTION_SPECIFIC_TARGET (decl)
608 125478 : = target_option_default_node;
609 125494 : if (!DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl))
610 121727 : DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl)
611 121727 : = optimization_default_node;
612 : }
613 :
614 : /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
615 : At this point, it is not needed anymore. */
616 382274 : DECL_SAVED_TREE (decl) = NULL_TREE;
617 :
618 : /* Clear the abstract origin if it refers to a method.
619 : Otherwise dwarf2out.cc will ICE as we splice functions out of
620 : TYPE_FIELDS and thus the origin will not be output
621 : correctly. */
622 382274 : if (DECL_ABSTRACT_ORIGIN (decl)
623 17106 : && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))
624 399380 : && RECORD_OR_UNION_TYPE_P
625 : (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))))
626 12913 : DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
627 :
628 382274 : DECL_VINDEX (decl) = NULL_TREE;
629 : }
630 : else if (VAR_P (decl))
631 : {
632 : /* See comment above why we set the flag for functions. */
633 815124 : if (TREE_PUBLIC (decl))
634 237038 : TREE_ADDRESSABLE (decl) = true;
635 815124 : if ((DECL_EXTERNAL (decl)
636 4784 : && (!TREE_STATIC (decl) || !TREE_READONLY (decl)))
637 817556 : || (decl_function_context (decl) && !TREE_STATIC (decl)))
638 552860 : DECL_INITIAL (decl) = NULL_TREE;
639 : }
640 : else if (TREE_CODE (decl) == TYPE_DECL)
641 : {
642 160806 : DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
643 160806 : DECL_VISIBILITY_SPECIFIED (decl) = 0;
644 160806 : TREE_PUBLIC (decl) = 0;
645 160806 : TREE_PRIVATE (decl) = 0;
646 160806 : DECL_ARTIFICIAL (decl) = 0;
647 160806 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 0;
648 160806 : DECL_INITIAL (decl) = NULL_TREE;
649 160806 : DECL_ORIGINAL_TYPE (decl) = NULL_TREE;
650 160806 : DECL_MODE (decl) = VOIDmode;
651 160806 : SET_DECL_ALIGN (decl, 0);
652 : /* TREE_TYPE is cleared at WPA time in free_odr_warning_data. */
653 : }
654 : else if (TREE_CODE (decl) == FIELD_DECL)
655 : {
656 106359 : TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
657 106359 : DECL_INITIAL (decl) = NULL_TREE;
658 : }
659 : else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL
660 22520 : && DECL_INITIAL (decl)
661 18959 : && TREE_CODE (DECL_INITIAL (decl)) == BLOCK)
662 : {
663 : /* Strip builtins from the translation-unit BLOCK. We still have targets
664 : without builtin_decl_explicit support and also builtins are shared
665 : nodes and thus we can't use TREE_CHAIN in multiple lists. */
666 18959 : tree *nextp = &BLOCK_VARS (DECL_INITIAL (decl));
667 18959 : while (*nextp)
668 : {
669 0 : tree var = *nextp;
670 0 : if (TREE_CODE (var) == FUNCTION_DECL
671 0 : && fndecl_built_in_p (var))
672 0 : *nextp = TREE_CHAIN (var);
673 : else
674 0 : nextp = &TREE_CHAIN (var);
675 : }
676 : }
677 : /* We need to keep field decls associated with their trees. Otherwise tree
678 : merging may merge some fields and keep others disjoint which in turn will
679 : not do well with TREE_CHAIN pointers linking them.
680 :
681 : Also do not drop containing types for virtual methods and tables because
682 : these are needed by devirtualization.
683 : C++ destructors are special because C++ frontends sometimes produces
684 : virtual destructor as an alias of non-virtual destructor. In
685 : devirtualization code we always walk through aliases and we need
686 : context to be preserved too. See PR89335 */
687 2060969 : if (TREE_CODE (decl) != FIELD_DECL
688 2060969 : && ((TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
689 1197398 : || (!DECL_VIRTUAL_P (decl)
690 1189877 : && (TREE_CODE (decl) != FUNCTION_DECL
691 377524 : || !DECL_CXX_DESTRUCTOR_P (decl)))))
692 1940135 : DECL_CONTEXT (decl) = fld_decl_context (DECL_CONTEXT (decl));
693 2060969 : }
694 :
695 :
696 : /* Operand callback helper for free_lang_data_in_node. *TP is the
697 : subtree operand being considered. */
698 :
699 : static tree
700 9957098 : find_decls_types_r (tree *tp, int *ws, void *data)
701 : {
702 9957098 : tree t = *tp;
703 9957098 : class free_lang_data_d *fld = (class free_lang_data_d *) data;
704 :
705 9957098 : if (TREE_CODE (t) == TREE_LIST)
706 : return NULL_TREE;
707 :
708 : /* Language specific nodes will be removed, so there is no need
709 : to gather anything under them. */
710 9282026 : if (is_lang_specific (t))
711 : {
712 16 : *ws = 0;
713 16 : return NULL_TREE;
714 : }
715 :
716 9282010 : if (DECL_P (t))
717 : {
718 : /* Note that walk_tree does not traverse every possible field in
719 : decls, so we have to do our own traversals here. */
720 2060969 : add_tree_to_fld_list (t, fld);
721 :
722 2060969 : fld_worklist_push (DECL_NAME (t), fld);
723 2060969 : fld_worklist_push (DECL_CONTEXT (t), fld);
724 2060969 : fld_worklist_push (DECL_SIZE (t), fld);
725 2060969 : fld_worklist_push (DECL_SIZE_UNIT (t), fld);
726 :
727 : /* We are going to remove everything under DECL_INITIAL for
728 : TYPE_DECLs. No point walking them. */
729 2060969 : if (TREE_CODE (t) != TYPE_DECL)
730 1900163 : fld_worklist_push (DECL_INITIAL (t), fld);
731 :
732 : /* Remove C++ annotations, those aren't needed for LTO and contain
733 : trees we sometimes can't stream. */
734 2060969 : DECL_ATTRIBUTES (t)
735 2060969 : = remove_attribute ("annotation ", DECL_ATTRIBUTES (t));
736 2060969 : fld_worklist_push (DECL_ATTRIBUTES (t), fld);
737 2060969 : fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld);
738 :
739 2060969 : if (TREE_CODE (t) == FUNCTION_DECL)
740 : {
741 779854 : for (tree arg = DECL_ARGUMENTS (t); arg; arg = DECL_CHAIN (arg))
742 397580 : fld_worklist_push (arg, fld);
743 382274 : fld_worklist_push (DECL_RESULT (t), fld);
744 : }
745 1678695 : else if (TREE_CODE (t) == FIELD_DECL)
746 : {
747 106359 : fld_worklist_push (DECL_FIELD_OFFSET (t), fld);
748 106359 : fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld);
749 106359 : fld_worklist_push (DECL_FIELD_BIT_OFFSET (t), fld);
750 106359 : fld_worklist_push (DECL_FCONTEXT (t), fld);
751 : }
752 :
753 2060969 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
754 2060969 : && DECL_HAS_VALUE_EXPR_P (t))
755 6484 : fld_worklist_push (DECL_VALUE_EXPR (t), fld);
756 :
757 2060969 : *ws = 0;
758 : }
759 7221041 : else if (TYPE_P (t))
760 : {
761 : /* Note that walk_tree does not traverse every possible field in
762 : types, so we have to do our own traversals here. */
763 866947 : add_tree_to_fld_list (t, fld);
764 :
765 866947 : if (!RECORD_OR_UNION_TYPE_P (t))
766 793210 : fld_worklist_push (TYPE_CACHED_VALUES (t), fld);
767 866947 : fld_worklist_push (TYPE_SIZE (t), fld);
768 866947 : fld_worklist_push (TYPE_SIZE_UNIT (t), fld);
769 : /* Remove C++ annotations, those aren't needed for LTO and contain
770 : trees we sometimes can't stream. */
771 866947 : TYPE_ATTRIBUTES (t)
772 866947 : = remove_attribute ("annotation ", TYPE_ATTRIBUTES (t));
773 866947 : fld_worklist_push (TYPE_ATTRIBUTES (t), fld);
774 866947 : fld_worklist_push (TYPE_POINTER_TO (t), fld);
775 866947 : fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
776 866947 : fld_worklist_push (TYPE_NAME (t), fld);
777 : /* While we do not stream TYPE_POINTER_TO and TYPE_REFERENCE_TO
778 : lists, we may look types up in these lists and use them while
779 : optimizing the function body. Thus we need to free lang data
780 : in them. */
781 866947 : if (TREE_CODE (t) == POINTER_TYPE)
782 360929 : fld_worklist_push (TYPE_NEXT_PTR_TO (t), fld);
783 866947 : if (TREE_CODE (t) == REFERENCE_TYPE)
784 37131 : fld_worklist_push (TYPE_NEXT_REF_TO (t), fld);
785 866947 : if (!POINTER_TYPE_P (t))
786 468887 : fld_worklist_push (TYPE_MIN_VALUE_RAW (t), fld);
787 : /* TYPE_MAX_VALUE_RAW is TYPE_BINFO for record types. */
788 866947 : if (!RECORD_OR_UNION_TYPE_P (t))
789 793210 : fld_worklist_push (TYPE_MAX_VALUE_RAW (t), fld);
790 866947 : fld_worklist_push (TYPE_MAIN_VARIANT (t), fld);
791 : /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
792 : do not and want not to reach unused variants this way. */
793 866947 : if (TYPE_CONTEXT (t))
794 : {
795 23669 : tree ctx = TYPE_CONTEXT (t);
796 : /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
797 : So push that instead. */
798 23669 : while (ctx && TREE_CODE (ctx) == BLOCK)
799 0 : ctx = BLOCK_SUPERCONTEXT (ctx);
800 23669 : fld_worklist_push (ctx, fld);
801 : }
802 866947 : fld_worklist_push (TYPE_CANONICAL (t), fld);
803 :
804 866947 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t))
805 : {
806 : unsigned i;
807 : tree tem;
808 31836 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t)), i, tem)
809 6807 : fld_worklist_push (TREE_TYPE (tem), fld);
810 25029 : fld_worklist_push (BINFO_TYPE (TYPE_BINFO (t)), fld);
811 25029 : fld_worklist_push (BINFO_VTABLE (TYPE_BINFO (t)), fld);
812 : }
813 866947 : if (RECORD_OR_UNION_TYPE_P (t))
814 : {
815 73737 : tree tem;
816 : /* Push all TYPE_FIELDS - there can be interleaving interesting
817 : and non-interesting things. */
818 73737 : tem = TYPE_FIELDS (t);
819 659484 : while (tem)
820 : {
821 585747 : if (TREE_CODE (tem) == FIELD_DECL)
822 140637 : fld_worklist_push (tem, fld);
823 585747 : tem = TREE_CHAIN (tem);
824 : }
825 : }
826 866947 : if (FUNC_OR_METHOD_TYPE_P (t))
827 170295 : fld_worklist_push (TYPE_METHOD_BASETYPE (t), fld);
828 :
829 866947 : fld_worklist_push (TYPE_STUB_DECL (t), fld);
830 866947 : *ws = 0;
831 : }
832 6354094 : else if (TREE_CODE (t) == BLOCK)
833 : {
834 1066931 : for (tree *tem = &BLOCK_VARS (t); *tem; )
835 : {
836 858656 : if (TREE_CODE (*tem) != LABEL_DECL
837 858656 : && (TREE_CODE (*tem) != VAR_DECL
838 383918 : || !auto_var_in_fn_p (*tem, DECL_CONTEXT (*tem))))
839 : {
840 492893 : gcc_assert (TREE_CODE (*tem) != RESULT_DECL
841 : && TREE_CODE (*tem) != PARM_DECL);
842 492893 : *tem = TREE_CHAIN (*tem);
843 : }
844 : else
845 : {
846 365763 : fld_worklist_push (*tem, fld);
847 365763 : tem = &TREE_CHAIN (*tem);
848 : }
849 : }
850 258774 : for (tree tem = BLOCK_SUBBLOCKS (t); tem; tem = BLOCK_CHAIN (tem))
851 50499 : fld_worklist_push (tem, fld);
852 208275 : fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t), fld);
853 : }
854 : /* walk_tree does not visit ce->index which can be a FIELD_DECL, pulling
855 : in otherwise unused structure fields so handle CTORs explicitly. */
856 6145819 : else if (TREE_CODE (t) == CONSTRUCTOR)
857 : {
858 : unsigned HOST_WIDE_INT idx;
859 : constructor_elt *ce;
860 863674 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce); idx++)
861 : {
862 581878 : if (ce->index)
863 457597 : fld_worklist_push (ce->index, fld);
864 581878 : fld_worklist_push (ce->value, fld);
865 : }
866 281796 : *ws = 0;
867 : }
868 :
869 9282010 : if (TREE_CODE (t) != IDENTIFIER_NODE
870 7849346 : && CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPED))
871 7641071 : fld_worklist_push (TREE_TYPE (t), fld);
872 :
873 : return NULL_TREE;
874 : }
875 :
876 :
877 : /* Find decls and types in T. */
878 :
879 : static void
880 8445268 : find_decls_types (tree t, class free_lang_data_d *fld)
881 : {
882 19581430 : while (1)
883 : {
884 14013349 : if (!fld->pset.contains (t))
885 9701156 : walk_tree (&t, find_decls_types_r, fld, &fld->pset);
886 14013349 : if (fld->worklist.is_empty ())
887 : break;
888 5568081 : t = fld->worklist.pop ();
889 : }
890 8445268 : }
891 :
892 : /* Translate all the types in LIST with the corresponding runtime
893 : types. */
894 :
895 : static tree
896 581 : get_eh_types_for_runtime (tree list)
897 : {
898 581 : tree head, prev;
899 :
900 581 : if (list == NULL_TREE)
901 : return NULL_TREE;
902 :
903 204 : head = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
904 204 : prev = head;
905 204 : list = TREE_CHAIN (list);
906 204 : while (list)
907 : {
908 0 : tree n = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
909 0 : TREE_CHAIN (prev) = n;
910 0 : prev = TREE_CHAIN (prev);
911 0 : list = TREE_CHAIN (list);
912 : }
913 :
914 : return head;
915 : }
916 :
917 :
918 : /* Find decls and types referenced in EH region R and store them in
919 : FLD->DECLS and FLD->TYPES. */
920 :
921 : static void
922 40044 : find_decls_types_in_eh_region (eh_region r, class free_lang_data_d *fld)
923 : {
924 40044 : switch (r->type)
925 : {
926 : case ERT_CLEANUP:
927 : break;
928 :
929 596 : case ERT_TRY:
930 596 : {
931 596 : eh_catch c;
932 :
933 : /* The types referenced in each catch must first be changed to the
934 : EH types used at runtime. This removes references to FE types
935 : in the region. */
936 1010 : for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
937 : {
938 414 : c->type_list = get_eh_types_for_runtime (c->type_list);
939 414 : walk_tree (&c->type_list, find_decls_types_r, fld, &fld->pset);
940 : }
941 : }
942 : break;
943 :
944 167 : case ERT_ALLOWED_EXCEPTIONS:
945 167 : r->u.allowed.type_list
946 167 : = get_eh_types_for_runtime (r->u.allowed.type_list);
947 167 : walk_tree (&r->u.allowed.type_list, find_decls_types_r, fld, &fld->pset);
948 167 : break;
949 :
950 15425 : case ERT_MUST_NOT_THROW:
951 15425 : walk_tree (&r->u.must_not_throw.failure_decl,
952 : find_decls_types_r, fld, &fld->pset);
953 15425 : break;
954 : }
955 40044 : }
956 :
957 :
958 : /* Find decls and types referenced in cgraph node N and store them in
959 : FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
960 : look for *every* kind of DECL and TYPE node reachable from N,
961 : including those embedded inside types and decls (i.e,, TYPE_DECLs,
962 : NAMESPACE_DECLs, etc). */
963 :
964 : static void
965 370323 : find_decls_types_in_node (struct cgraph_node *n, class free_lang_data_d *fld)
966 : {
967 370323 : basic_block bb;
968 370323 : struct function *fn;
969 370323 : unsigned ix;
970 370323 : tree t;
971 :
972 370323 : find_decls_types (n->decl, fld);
973 :
974 370323 : if (!gimple_has_body_p (n->decl))
975 370323 : return;
976 :
977 125316 : gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
978 :
979 125316 : fn = DECL_STRUCT_FUNCTION (n->decl);
980 :
981 : /* Traverse locals. */
982 789632 : FOR_EACH_LOCAL_DECL (fn, ix, t)
983 571022 : find_decls_types (t, fld);
984 :
985 : /* Traverse EH regions in FN. */
986 125316 : {
987 125316 : eh_region r;
988 165360 : FOR_ALL_EH_REGION_FN (r, fn)
989 40044 : find_decls_types_in_eh_region (r, fld);
990 : }
991 :
992 : /* Traverse every statement in FN. */
993 895134 : FOR_EACH_BB_FN (bb, fn)
994 : {
995 769818 : gphi_iterator psi;
996 769818 : gimple_stmt_iterator si;
997 769818 : unsigned i;
998 :
999 769999 : for (psi = gsi_start_phis (bb); !gsi_end_p (psi); gsi_next (&psi))
1000 : {
1001 181 : gphi *phi = psi.phi ();
1002 :
1003 716 : for (i = 0; i < gimple_phi_num_args (phi); i++)
1004 : {
1005 354 : tree *arg_p = gimple_phi_arg_def_ptr (phi, i);
1006 354 : find_decls_types (*arg_p, fld);
1007 : }
1008 : }
1009 :
1010 3861231 : for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
1011 : {
1012 2321595 : gimple *stmt = gsi_stmt (si);
1013 :
1014 2321595 : if (is_gimple_call (stmt))
1015 528656 : find_decls_types (gimple_call_fntype (stmt), fld);
1016 :
1017 9015245 : for (i = 0; i < gimple_num_ops (stmt); i++)
1018 : {
1019 6693650 : tree arg = gimple_op (stmt, i);
1020 6693650 : find_decls_types (arg, fld);
1021 : /* find_decls_types doesn't walk TREE_PURPOSE of TREE_LISTs,
1022 : which we need for asm stmts. */
1023 6693650 : if (arg
1024 5026417 : && TREE_CODE (arg) == TREE_LIST
1025 19808 : && TREE_PURPOSE (arg)
1026 6712132 : && gimple_code (stmt) == GIMPLE_ASM)
1027 18482 : find_decls_types (TREE_PURPOSE (arg), fld);
1028 : }
1029 : }
1030 : }
1031 : }
1032 :
1033 :
1034 : /* Find decls and types referenced in varpool node N and store them in
1035 : FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
1036 : look for *every* kind of DECL and TYPE node reachable from N,
1037 : including those embedded inside types and decls (i.e,, TYPE_DECLs,
1038 : NAMESPACE_DECLs, etc). */
1039 :
1040 : static void
1041 262697 : find_decls_types_in_var (varpool_node *v, class free_lang_data_d *fld)
1042 : {
1043 0 : find_decls_types (v->decl, fld);
1044 0 : }
1045 :
1046 : /* Find decls and types referenced in asm node N and store them in
1047 : FLD->DECLS and FLD->TYPES.
1048 : Asm strings are represented as a C/C++/etc. strings. If there is
1049 : no other string, we would delete/prune/unify the type and cause
1050 : issues in verify_type(tree).
1051 : Likely we could just add the string type, but we scan the whole
1052 : tree to be sure. */
1053 : static void
1054 84 : find_decls_types_in_asm (asm_node *v, class free_lang_data_d *fld)
1055 : {
1056 0 : find_decls_types (v->asm_str, fld);
1057 0 : }
1058 :
1059 : /* Free language specific information for every operand and expression
1060 : in every node of the call graph. This process operates in three stages:
1061 :
1062 : 1- Every callgraph node and varpool node is traversed looking for
1063 : decls and types embedded in them. This is a more exhaustive
1064 : search than that done by find_referenced_vars, because it will
1065 : also collect individual fields, decls embedded in types, etc.
1066 :
1067 : 2- All the decls found are sent to free_lang_data_in_decl.
1068 :
1069 : 3- All the types found are sent to free_lang_data_in_type.
1070 :
1071 : The ordering between decls and types is important because
1072 : free_lang_data_in_decl sets assembler names, which includes
1073 : mangling. So types cannot be freed up until assembler names have
1074 : been set up. */
1075 :
1076 : static void
1077 23919 : free_lang_data_in_cgraph (class free_lang_data_d *fld)
1078 : {
1079 23919 : struct cgraph_node *n;
1080 23919 : varpool_node *v;
1081 23919 : tree t;
1082 23919 : unsigned i;
1083 23919 : alias_pair *p;
1084 :
1085 : /* Find decls and types in the body of every function in the callgraph. */
1086 394242 : FOR_EACH_FUNCTION (n)
1087 370323 : find_decls_types_in_node (n, fld);
1088 :
1089 23919 : FOR_EACH_VEC_SAFE_ELT (alias_pairs, i, p)
1090 0 : find_decls_types (p->decl, fld);
1091 :
1092 : /* Find decls and types in every varpool symbol. */
1093 286616 : FOR_EACH_VARIABLE (v)
1094 262697 : find_decls_types_in_var (v, fld);
1095 :
1096 : /* Find the decls and types in every asm node.
1097 : Should only be a string type. */
1098 24003 : for (asm_node* anode = symtab->first_asm_symbol (); anode;
1099 84 : anode = safe_as_a<asm_node*> (anode->next))
1100 84 : find_decls_types_in_asm (anode, fld);
1101 :
1102 : /* Set the assembler name on every decl found. We need to do this
1103 : now because free_lang_data_in_decl will invalidate data needed
1104 : for mangling. This breaks mangling on interdependent decls. */
1105 2084888 : FOR_EACH_VEC_ELT (fld->decls, i, t)
1106 2060969 : assign_assembler_name_if_needed (t);
1107 :
1108 : /* Traverse every decl found freeing its language data. */
1109 2084888 : FOR_EACH_VEC_ELT (fld->decls, i, t)
1110 2060969 : free_lang_data_in_decl (t, fld);
1111 :
1112 : /* Traverse every type found freeing its language data. */
1113 932067 : FOR_EACH_VEC_ELT (fld->types, i, t)
1114 908148 : free_lang_data_in_type (t, fld);
1115 23919 : }
1116 :
1117 :
1118 : /* Free resources that are used by FE but are not needed once they are done. */
1119 :
1120 : static unsigned
1121 239068 : free_lang_data (void)
1122 : {
1123 239068 : unsigned i;
1124 239068 : class free_lang_data_d fld;
1125 :
1126 : /* If we are the LTO frontend we have freed lang-specific data already. */
1127 239068 : if (in_lto_p
1128 239068 : || (!flag_generate_lto && !flag_generate_offload))
1129 : {
1130 : /* Rebuild type inheritance graph even when not doing LTO to get
1131 : consistent profile data. */
1132 215149 : rebuild_type_inheritance_graph ();
1133 215149 : return 0;
1134 : }
1135 :
1136 23919 : fld_incomplete_types = new hash_map<tree, tree>;
1137 23919 : fld_simplified_types = new hash_map<tree, tree>;
1138 :
1139 : /* Provide a dummy TRANSLATION_UNIT_DECL if the FE failed to provide one. */
1140 23919 : if (vec_safe_is_empty (all_translation_units))
1141 1165 : build_translation_unit_decl (NULL_TREE);
1142 :
1143 : /* Allocate and assign alias sets to the standard integer types
1144 : while the slots are still in the way the frontends generated them. */
1145 478380 : for (i = 0; i < itk_none; ++i)
1146 454461 : if (integer_types[i])
1147 310945 : TYPE_ALIAS_SET (integer_types[i]) = get_alias_set (integer_types[i]);
1148 :
1149 : /* Traverse the IL resetting language specific information for
1150 : operands, expressions, etc. */
1151 23919 : free_lang_data_in_cgraph (&fld);
1152 :
1153 : /* Create gimple variants for common types. */
1154 191352 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
1155 143514 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
1156 :
1157 : /* Reset some langhooks. Do not reset types_compatible_p, it may
1158 : still be used indirectly via the get_alias_set langhook. */
1159 23919 : lang_hooks.dwarf_name = lhd_dwarf_name;
1160 23919 : lang_hooks.decl_printable_name = gimple_decl_printable_name;
1161 23919 : lang_hooks.gimplify_expr = lhd_gimplify_expr;
1162 23919 : lang_hooks.overwrite_decl_assembler_name = lhd_overwrite_decl_assembler_name;
1163 23919 : lang_hooks.print_xnode = lhd_print_tree_nothing;
1164 23919 : lang_hooks.print_decl = lhd_print_tree_nothing;
1165 23919 : lang_hooks.print_type = lhd_print_tree_nothing;
1166 23919 : lang_hooks.print_identifier = lhd_print_tree_nothing;
1167 :
1168 23919 : lang_hooks.tree_inlining.var_mod_type_p = hook_bool_tree_tree_false;
1169 :
1170 23919 : if (flag_checking)
1171 : {
1172 : int i;
1173 : tree t;
1174 :
1175 932007 : FOR_EACH_VEC_ELT (fld.types, i, t)
1176 908094 : verify_type (t);
1177 : }
1178 :
1179 : /* We do not want the default decl_assembler_name implementation,
1180 : rather if we have fixed everything we want a wrapper around it
1181 : asserting that all non-local symbols already got their assembler
1182 : name and only produce assembler names for local symbols. Or rather
1183 : make sure we never call decl_assembler_name on local symbols and
1184 : devise a separate, middle-end private scheme for it. */
1185 :
1186 : /* Reset diagnostic machinery. */
1187 23919 : tree_diagnostics_defaults (global_dc);
1188 :
1189 23919 : rebuild_type_inheritance_graph ();
1190 :
1191 47838 : delete fld_incomplete_types;
1192 47838 : delete fld_simplified_types;
1193 :
1194 : return 0;
1195 239068 : }
1196 :
1197 : const pass_data pass_data_ipa_free_lang_data =
1198 : {
1199 : SIMPLE_IPA_PASS, /* type */
1200 : "*free_lang_data", /* name */
1201 : OPTGROUP_NONE, /* optinfo_flags */
1202 : TV_IPA_FREE_LANG_DATA, /* tv_id */
1203 : 0, /* properties_required */
1204 : 0, /* properties_provided */
1205 : 0, /* properties_destroyed */
1206 : 0, /* todo_flags_start */
1207 : 0, /* todo_flags_finish */
1208 : };
1209 :
1210 : class pass_ipa_free_lang_data : public simple_ipa_opt_pass
1211 : {
1212 : public:
1213 297180 : pass_ipa_free_lang_data (gcc::context *ctxt)
1214 594360 : : simple_ipa_opt_pass (pass_data_ipa_free_lang_data, ctxt)
1215 : {}
1216 :
1217 : /* opt_pass methods: */
1218 239068 : unsigned int execute (function *) final override { return free_lang_data (); }
1219 :
1220 : }; // class pass_ipa_free_lang_data
1221 :
1222 : } // anon namespace
1223 :
1224 : simple_ipa_opt_pass *
1225 297180 : make_pass_ipa_free_lang_data (gcc::context *ctxt)
1226 : {
1227 297180 : return new pass_ipa_free_lang_data (ctxt);
1228 : }
|