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 243271 : 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 2991645 : add_tree_to_fld_list (tree t, class free_lang_data_d *fld)
80 : {
81 2991645 : if (DECL_P (t))
82 2071812 : fld->decls.safe_push (t);
83 919833 : else if (TYPE_P (t))
84 919833 : fld->types.safe_push (t);
85 : else
86 0 : gcc_unreachable ();
87 2991645 : }
88 :
89 : /* Push tree node T into FLD->WORKLIST. */
90 :
91 : static inline void
92 35722966 : fld_worklist_push (tree t, class free_lang_data_d *fld)
93 : {
94 57474731 : if (t && !is_lang_specific (t) && !fld->pset.contains (t))
95 5617921 : fld->worklist.safe_push ((t));
96 35722966 : }
97 :
98 :
99 :
100 : /* Return simplified TYPE_NAME of TYPE. */
101 :
102 : static tree
103 1113945 : fld_simplified_type_name (tree type)
104 : {
105 1113945 : if (!TYPE_NAME (type) || TREE_CODE (TYPE_NAME (type)) != TYPE_DECL)
106 897115 : 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 216830 : if (type != TYPE_MAIN_VARIANT (type)
111 216830 : || (!DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (type))
112 88803 : && (TREE_CODE (type) != RECORD_TYPE
113 7963 : || !TYPE_BINFO (type)
114 0 : || !BINFO_VTABLE (TYPE_BINFO (type)))))
115 170436 : return DECL_NAME (TYPE_NAME (type));
116 46394 : 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 107567 : fld_type_variant_equal_p (tree t, tree v, tree inner_type)
126 : {
127 107567 : 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 90037 : || ((!RECORD_OR_UNION_TYPE_P (t) || COMPLETE_TYPE_P (v))
131 66868 : && (TYPE_ALIGN (t) != TYPE_ALIGN (v)
132 66852 : || TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (v)))
133 90021 : || fld_simplified_type_name (t) != fld_simplified_type_name (v)
134 75240 : || !attribute_list_equal (TYPE_ATTRIBUTES (t),
135 75240 : TYPE_ATTRIBUTES (v))
136 75240 : || (inner_type && TREE_TYPE (v) != inner_type))
137 32327 : 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 75240 : fld_type_variant (tree first, tree t, class free_lang_data_d *fld,
147 : tree inner_type = NULL)
148 : {
149 75240 : if (first == TYPE_MAIN_VARIANT (t))
150 : return t;
151 98355 : for (tree v = first; v; v = TYPE_NEXT_VARIANT (v))
152 91343 : if (fld_type_variant_equal_p (t, v, inner_type))
153 : {
154 68228 : if (flag_checking)
155 77440 : for (tree v2 = TYPE_NEXT_VARIANT (v); v2; v2 = TYPE_NEXT_VARIANT (v2))
156 9212 : gcc_assert (!fld_type_variant_equal_p (t, v2, inner_type));
157 : return v;
158 : }
159 7012 : tree v = build_variant_type_copy (first);
160 7012 : TYPE_READONLY (v) = TYPE_READONLY (t);
161 7012 : TYPE_VOLATILE (v) = TYPE_VOLATILE (t);
162 7012 : TYPE_ATOMIC (v) = TYPE_ATOMIC (t);
163 7012 : TYPE_RESTRICT (v) = TYPE_RESTRICT (t);
164 7012 : TYPE_ADDR_SPACE (v) = TYPE_ADDR_SPACE (t);
165 7012 : TYPE_NAME (v) = TYPE_NAME (t);
166 7012 : TYPE_ATTRIBUTES (v) = TYPE_ATTRIBUTES (t);
167 7012 : 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 7012 : 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 7012 : if (inner_type)
176 22 : TREE_TYPE (v) = inner_type;
177 7012 : gcc_checking_assert (fld_type_variant_equal_p (t,v, inner_type));
178 7012 : if (!fld->pset.add (v))
179 7012 : 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 1959760 : 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 1805431 : if (ctx && TYPE_P (ctx)
234 1997500 : && !variably_modified_type_p (ctx, NULL_TREE))
235 : {
236 80601 : while (ctx && TYPE_P (ctx))
237 42861 : ctx = TYPE_CONTEXT (ctx);
238 : }
239 1959760 : 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 378719 : fld_incomplete_type_of (tree t, class free_lang_data_d *fld)
247 : {
248 378719 : if (!t)
249 : return NULL;
250 378719 : if (POINTER_TYPE_P (t))
251 : {
252 184027 : tree t2 = fld_incomplete_type_of (TREE_TYPE (t), fld);
253 184027 : if (t2 != TREE_TYPE (t))
254 : {
255 59437 : tree first;
256 59437 : if (TREE_CODE (t) == POINTER_TYPE)
257 48123 : first = build_pointer_type_for_mode (t2, TYPE_MODE (t),
258 48123 : TYPE_REF_CAN_ALIAS_ALL (t));
259 : else
260 11314 : first = build_reference_type_for_mode (t2, TYPE_MODE (t),
261 11314 : TYPE_REF_CAN_ALIAS_ALL (t));
262 59437 : gcc_assert (TYPE_CANONICAL (t2) != t2
263 : && TYPE_CANONICAL (t2) == TYPE_CANONICAL (TREE_TYPE (t)));
264 59437 : if (!fld->pset.add (first))
265 20326 : add_tree_to_fld_list (first, fld);
266 59437 : return fld_type_variant (first, t, fld);
267 : }
268 : return t;
269 : }
270 194692 : 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 191845 : if ((!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
275 191845 : || !COMPLETE_TYPE_P (t))
276 : return t;
277 73502 : if (TYPE_MAIN_VARIANT (t) == t)
278 : {
279 57721 : bool existed;
280 57721 : tree ©
281 57721 : = fld_incomplete_types->get_or_insert (t, &existed);
282 :
283 57721 : if (!existed)
284 : {
285 13947 : copy = build_distinct_type_copy (t);
286 :
287 : /* It is possible that type was not seen by free_lang_data yet. */
288 13947 : if (!fld->pset.add (copy))
289 13947 : add_tree_to_fld_list (copy, fld);
290 13947 : TYPE_SIZE (copy) = NULL;
291 13947 : TYPE_USER_ALIGN (copy) = 0;
292 13947 : TYPE_SIZE_UNIT (copy) = NULL;
293 13947 : TYPE_CANONICAL (copy) = TYPE_CANONICAL (t);
294 13947 : TREE_ADDRESSABLE (copy) = 0;
295 13947 : if (AGGREGATE_TYPE_P (t))
296 : {
297 13873 : SET_TYPE_MODE (copy, VOIDmode);
298 13873 : SET_TYPE_ALIGN (copy, BITS_PER_UNIT);
299 13873 : TYPE_TYPELESS_STORAGE (copy) = 0;
300 13873 : TYPE_FIELDS (copy) = NULL;
301 13873 : TYPE_BINFO (copy) = NULL;
302 13873 : TYPE_FINAL_P (copy) = 0;
303 13873 : 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 13947 : TYPE_NAME (copy) = fld_simplified_type_name (copy);
319 13947 : tree name = TYPE_NAME (copy);
320 :
321 13947 : if (name && TREE_CODE (name) == TYPE_DECL)
322 : {
323 8876 : gcc_checking_assert (TREE_TYPE (name) == t);
324 8876 : tree name2 = build_decl (DECL_SOURCE_LOCATION (name), TYPE_DECL,
325 8876 : DECL_NAME (name), copy);
326 8876 : if (DECL_ASSEMBLER_NAME_SET_P (name))
327 8876 : SET_DECL_ASSEMBLER_NAME (name2, DECL_ASSEMBLER_NAME (name));
328 8876 : SET_DECL_ALIGN (name2, 0);
329 8876 : DECL_CONTEXT (name2) = fld_decl_context
330 8876 : (DECL_CONTEXT (name));
331 8876 : TYPE_NAME (copy) = name2;
332 : }
333 : }
334 57721 : return copy;
335 : }
336 15781 : return (fld_type_variant
337 15781 : (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 1240109 : fld_simplified_type (tree t, class free_lang_data_d *fld)
345 : {
346 1240109 : if (!t)
347 : return t;
348 1240109 : if (POINTER_TYPE_P (t))
349 176064 : 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 6418607 : free_lang_data_in_one_sizepos (tree *expr_p)
372 : {
373 6418607 : tree expr = *expr_p;
374 6418607 : if (CONTAINS_PLACEHOLDER_P (expr))
375 0 : *expr_p = build0 (PLACEHOLDER_EXPR, TREE_TYPE (expr));
376 6418607 : }
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 39627 : free_lang_data_in_binfo (tree binfo)
384 : {
385 39627 : unsigned i;
386 39627 : tree t;
387 :
388 39627 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
389 :
390 39627 : BINFO_VIRTUALS (binfo) = NULL_TREE;
391 39627 : BINFO_BASE_ACCESSES (binfo) = NULL;
392 39627 : BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE;
393 39627 : BINFO_SUBVTT_INDEX (binfo) = NULL_TREE;
394 39627 : BINFO_VPTR_FIELD (binfo) = NULL_TREE;
395 39627 : TREE_PUBLIC (binfo) = 0;
396 :
397 54166 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo), i, t)
398 14539 : free_lang_data_in_binfo (t);
399 39627 : }
400 :
401 :
402 : /* Reset all language specific information still present in TYPE. */
403 :
404 : static void
405 919956 : free_lang_data_in_type (tree type, class free_lang_data_d *fld)
406 : {
407 919956 : gcc_assert (TYPE_P (type));
408 :
409 : /* Give the FE a chance to remove its own data first. */
410 919956 : lang_hooks.free_lang_data (type);
411 :
412 919956 : TREE_LANG_FLAG_0 (type) = 0;
413 919956 : TREE_LANG_FLAG_1 (type) = 0;
414 919956 : TREE_LANG_FLAG_2 (type) = 0;
415 919956 : TREE_LANG_FLAG_3 (type) = 0;
416 919956 : TREE_LANG_FLAG_4 (type) = 0;
417 919956 : TREE_LANG_FLAG_5 (type) = 0;
418 919956 : TREE_LANG_FLAG_6 (type) = 0;
419 :
420 919956 : 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 919956 : while (TYPE_NEXT_VARIANT (type)
425 1414955 : && !fld->pset.contains (TYPE_NEXT_VARIANT (type)))
426 : {
427 494999 : tree t = TYPE_NEXT_VARIANT (type);
428 494999 : TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (t);
429 : /* Turn the removed types into distinct types. */
430 494999 : TYPE_MAIN_VARIANT (t) = t;
431 494999 : TYPE_NEXT_VARIANT (t) = NULL_TREE;
432 : }
433 :
434 919956 : if (TREE_CODE (type) == FUNCTION_TYPE)
435 : {
436 139773 : 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 625544 : for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
443 : {
444 485771 : tree arg_type = TREE_VALUE (p);
445 485771 : 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 485771 : TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
454 : /* C++ FE uses TREE_PURPOSE to store initial values. */
455 485771 : TREE_PURPOSE (p) = NULL;
456 : }
457 : }
458 : else if (TREE_CODE (type) == METHOD_TYPE)
459 : {
460 32794 : TREE_TYPE (type) = fld_simplified_type (TREE_TYPE (type), fld);
461 124038 : for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
462 : {
463 : /* C++ FE uses TREE_PURPOSE to store initial values. */
464 91244 : TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
465 91244 : 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 538061 : for (tree *prev = &TYPE_FIELDS (type), member; (member = *prev);)
473 444969 : if (TREE_CODE (member) == FIELD_DECL)
474 140802 : prev = &DECL_CHAIN (member);
475 : else
476 304167 : *prev = DECL_CHAIN (member);
477 :
478 93092 : TYPE_VFIELD (type) = NULL_TREE;
479 :
480 93092 : if (TYPE_BINFO (type))
481 : {
482 25088 : 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 25088 : if (!BINFO_VTABLE (TYPE_BINFO (type)))
486 22808 : 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 164310 : 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 164310 : free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type));
510 164310 : free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type));
511 : }
512 :
513 919956 : TYPE_LANG_SLOT_1 (type) = NULL_TREE;
514 :
515 919956 : free_lang_data_in_one_sizepos (&TYPE_SIZE (type));
516 919956 : free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type));
517 :
518 919956 : if (TYPE_CONTEXT (type)
519 919956 : && 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 919956 : TYPE_STUB_DECL (type) = NULL;
531 919956 : TYPE_NAME (type) = fld_simplified_type_name (type);
532 919956 : }
533 :
534 : /* Reset all language specific information still present in symbol
535 : DECL. */
536 :
537 : static void
538 2071812 : free_lang_data_in_decl (tree decl, class free_lang_data_d *fld)
539 : {
540 2071812 : gcc_assert (DECL_P (decl));
541 :
542 : /* Give the FE a chance to remove its own data first. */
543 2071812 : lang_hooks.free_lang_data (decl);
544 :
545 2071812 : TREE_LANG_FLAG_0 (decl) = 0;
546 2071812 : TREE_LANG_FLAG_1 (decl) = 0;
547 2071812 : TREE_LANG_FLAG_2 (decl) = 0;
548 2071812 : TREE_LANG_FLAG_3 (decl) = 0;
549 2071812 : TREE_LANG_FLAG_4 (decl) = 0;
550 2071812 : TREE_LANG_FLAG_5 (decl) = 0;
551 2071812 : TREE_LANG_FLAG_6 (decl) = 0;
552 :
553 2071812 : free_lang_data_in_one_sizepos (&DECL_SIZE (decl));
554 2071812 : free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl));
555 2071812 : if (TREE_CODE (decl) == FIELD_DECL)
556 : {
557 106451 : DECL_FCONTEXT (decl) = NULL;
558 106451 : free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl));
559 106451 : if (TREE_CODE (DECL_CONTEXT (decl)) == QUAL_UNION_TYPE)
560 0 : DECL_QUALIFIER (decl) = NULL_TREE;
561 : }
562 :
563 2071812 : if (TREE_CODE (decl) == FUNCTION_DECL)
564 : {
565 384076 : 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 384076 : if (TREE_PUBLIC (decl))
576 370307 : TREE_ADDRESSABLE (decl) = true;
577 384076 : TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
578 384076 : if (!(node = cgraph_node::get (decl))
579 384076 : || (!node->definition && !node->clones))
580 : {
581 250490 : if (node)
582 238515 : node->release_body ();
583 : else
584 : {
585 11975 : release_function_body (decl);
586 11975 : DECL_ARGUMENTS (decl) = NULL;
587 11975 : DECL_RESULT (decl) = NULL;
588 11975 : DECL_INITIAL (decl) = error_mark_node;
589 : }
590 : }
591 384076 : if (gimple_has_body_p (decl) || (node && node->thunk))
592 : {
593 126859 : 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 479777 : for (t = DECL_ARGUMENTS (decl); t; t = TREE_CHAIN (t))
605 352918 : DECL_CONTEXT (t) = decl;
606 126859 : if (!DECL_FUNCTION_SPECIFIC_TARGET (decl))
607 126843 : DECL_FUNCTION_SPECIFIC_TARGET (decl)
608 126843 : = target_option_default_node;
609 126859 : if (!DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl))
610 123092 : DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl)
611 123092 : = 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 384076 : 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 384076 : if (DECL_ABSTRACT_ORIGIN (decl)
623 17122 : && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))
624 401198 : && RECORD_OR_UNION_TYPE_P
625 : (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))))
626 12923 : DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
627 :
628 384076 : 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 817663 : if (TREE_PUBLIC (decl))
634 237162 : TREE_ADDRESSABLE (decl) = true;
635 817663 : if ((DECL_EXTERNAL (decl)
636 4786 : && (!TREE_STATIC (decl) || !TREE_READONLY (decl)))
637 820095 : || (decl_function_context (decl) && !TREE_STATIC (decl)))
638 555251 : DECL_INITIAL (decl) = NULL_TREE;
639 : }
640 : else if (TREE_CODE (decl) == TYPE_DECL)
641 : {
642 163107 : DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
643 163107 : DECL_VISIBILITY_SPECIFIED (decl) = 0;
644 163107 : TREE_PUBLIC (decl) = 0;
645 163107 : TREE_PRIVATE (decl) = 0;
646 163107 : DECL_ARTIFICIAL (decl) = 0;
647 163107 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 0;
648 163107 : DECL_INITIAL (decl) = NULL_TREE;
649 163107 : DECL_ORIGINAL_TYPE (decl) = NULL_TREE;
650 163107 : DECL_MODE (decl) = VOIDmode;
651 163107 : 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 106451 : TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
657 106451 : DECL_INITIAL (decl) = NULL_TREE;
658 : }
659 : else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL
660 23422 : && DECL_INITIAL (decl)
661 19378 : && 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 19378 : tree *nextp = &BLOCK_VARS (DECL_INITIAL (decl));
667 19378 : 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 2071812 : if (TREE_CODE (decl) != FIELD_DECL
688 2071812 : && ((TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
689 1201739 : || (!DECL_VIRTUAL_P (decl)
690 1194222 : && (TREE_CODE (decl) != FUNCTION_DECL
691 379329 : || !DECL_CXX_DESTRUCTOR_P (decl)))))
692 1950884 : DECL_CONTEXT (decl) = fld_decl_context (DECL_CONTEXT (decl));
693 2071812 : }
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 10044243 : find_decls_types_r (tree *tp, int *ws, void *data)
701 : {
702 10044243 : tree t = *tp;
703 10044243 : class free_lang_data_d *fld = (class free_lang_data_d *) data;
704 :
705 10044243 : 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 9363448 : if (is_lang_specific (t))
711 : {
712 16 : *ws = 0;
713 16 : return NULL_TREE;
714 : }
715 :
716 9363432 : 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 2071812 : add_tree_to_fld_list (t, fld);
721 :
722 2071812 : fld_worklist_push (DECL_NAME (t), fld);
723 2071812 : fld_worklist_push (DECL_CONTEXT (t), fld);
724 2071812 : fld_worklist_push (DECL_SIZE (t), fld);
725 2071812 : 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 2071812 : if (TREE_CODE (t) != TYPE_DECL)
730 1908705 : 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 2071812 : DECL_ATTRIBUTES (t)
735 2071812 : = remove_attribute ("annotation ", DECL_ATTRIBUTES (t));
736 2071812 : fld_worklist_push (DECL_ATTRIBUTES (t), fld);
737 2071812 : fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld);
738 :
739 2071812 : if (TREE_CODE (t) == FUNCTION_DECL)
740 : {
741 782877 : for (tree arg = DECL_ARGUMENTS (t); arg; arg = DECL_CHAIN (arg))
742 398801 : fld_worklist_push (arg, fld);
743 384076 : fld_worklist_push (DECL_RESULT (t), fld);
744 : }
745 1687736 : else if (TREE_CODE (t) == FIELD_DECL)
746 : {
747 106451 : fld_worklist_push (DECL_FIELD_OFFSET (t), fld);
748 106451 : fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld);
749 106451 : fld_worklist_push (DECL_FIELD_BIT_OFFSET (t), fld);
750 106451 : fld_worklist_push (DECL_FCONTEXT (t), fld);
751 : }
752 :
753 2071812 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
754 2071812 : && DECL_HAS_VALUE_EXPR_P (t))
755 6491 : fld_worklist_push (DECL_VALUE_EXPR (t), fld);
756 :
757 2071812 : *ws = 0;
758 : }
759 7291620 : 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 878517 : add_tree_to_fld_list (t, fld);
764 :
765 878517 : if (!RECORD_OR_UNION_TYPE_P (t))
766 804681 : fld_worklist_push (TYPE_CACHED_VALUES (t), fld);
767 878517 : fld_worklist_push (TYPE_SIZE (t), fld);
768 878517 : 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 878517 : TYPE_ATTRIBUTES (t)
772 878517 : = remove_attribute ("annotation ", TYPE_ATTRIBUTES (t));
773 878517 : fld_worklist_push (TYPE_ATTRIBUTES (t), fld);
774 878517 : fld_worklist_push (TYPE_POINTER_TO (t), fld);
775 878517 : fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
776 878517 : 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 878517 : if (TREE_CODE (t) == POINTER_TYPE)
782 365485 : fld_worklist_push (TYPE_NEXT_PTR_TO (t), fld);
783 878517 : if (TREE_CODE (t) == REFERENCE_TYPE)
784 37260 : fld_worklist_push (TYPE_NEXT_REF_TO (t), fld);
785 878517 : if (!POINTER_TYPE_P (t))
786 475772 : fld_worklist_push (TYPE_MIN_VALUE_RAW (t), fld);
787 : /* TYPE_MAX_VALUE_RAW is TYPE_BINFO for record types. */
788 878517 : if (!RECORD_OR_UNION_TYPE_P (t))
789 804681 : fld_worklist_push (TYPE_MAX_VALUE_RAW (t), fld);
790 878517 : 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 878517 : if (TYPE_CONTEXT (t))
794 : {
795 23726 : tree ctx = TYPE_CONTEXT (t);
796 : /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
797 : So push that instead. */
798 23726 : while (ctx && TREE_CODE (ctx) == BLOCK)
799 0 : ctx = BLOCK_SUPERCONTEXT (ctx);
800 23726 : fld_worklist_push (ctx, fld);
801 : }
802 878517 : fld_worklist_push (TYPE_CANONICAL (t), fld);
803 :
804 878517 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t))
805 : {
806 : unsigned i;
807 : tree tem;
808 31895 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t)), i, tem)
809 6807 : fld_worklist_push (TREE_TYPE (tem), fld);
810 25088 : fld_worklist_push (BINFO_TYPE (TYPE_BINFO (t)), fld);
811 25088 : fld_worklist_push (BINFO_VTABLE (TYPE_BINFO (t)), fld);
812 : }
813 878517 : if (RECORD_OR_UNION_TYPE_P (t))
814 : {
815 73836 : tree tem;
816 : /* Push all TYPE_FIELDS - there can be interleaving interesting
817 : and non-interesting things. */
818 73836 : tem = TYPE_FIELDS (t);
819 661487 : while (tem)
820 : {
821 587651 : if (TREE_CODE (tem) == FIELD_DECL)
822 140798 : fld_worklist_push (tem, fld);
823 587651 : tem = TREE_CHAIN (tem);
824 : }
825 : }
826 878517 : if (FUNC_OR_METHOD_TYPE_P (t))
827 172567 : fld_worklist_push (TYPE_METHOD_BASETYPE (t), fld);
828 :
829 878517 : fld_worklist_push (TYPE_STUB_DECL (t), fld);
830 878517 : *ws = 0;
831 : }
832 6413103 : else if (TREE_CODE (t) == BLOCK)
833 : {
834 1081073 : for (tree *tem = &BLOCK_VARS (t); *tem; )
835 : {
836 870711 : if (TREE_CODE (*tem) != LABEL_DECL
837 870711 : && (TREE_CODE (*tem) != VAR_DECL
838 385196 : || !auto_var_in_fn_p (*tem, DECL_CONTEXT (*tem))))
839 : {
840 503686 : gcc_assert (TREE_CODE (*tem) != RESULT_DECL
841 : && TREE_CODE (*tem) != PARM_DECL);
842 503686 : *tem = TREE_CHAIN (*tem);
843 : }
844 : else
845 : {
846 367025 : fld_worklist_push (*tem, fld);
847 367025 : tem = &TREE_CHAIN (*tem);
848 : }
849 : }
850 261146 : for (tree tem = BLOCK_SUBBLOCKS (t); tem; tem = BLOCK_CHAIN (tem))
851 50784 : fld_worklist_push (tem, fld);
852 210362 : 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 6202741 : else if (TREE_CODE (t) == CONSTRUCTOR)
857 : {
858 : unsigned HOST_WIDE_INT idx;
859 : constructor_elt *ce;
860 864078 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce); idx++)
861 : {
862 581960 : if (ce->index)
863 457683 : fld_worklist_push (ce->index, fld);
864 581960 : fld_worklist_push (ce->value, fld);
865 : }
866 282118 : *ws = 0;
867 : }
868 :
869 9363432 : if (TREE_CODE (t) != IDENTIFIER_NODE
870 7922159 : && CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPED))
871 7711797 : 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 8476028 : find_decls_types (tree t, class free_lang_data_d *fld)
881 : {
882 19711870 : while (1)
883 : {
884 14093949 : if (!fld->pset.contains (t))
885 9761001 : walk_tree (&t, find_decls_types_r, fld, &fld->pset);
886 14093949 : if (fld->worklist.is_empty ())
887 : break;
888 5617921 : t = fld->worklist.pop ();
889 : }
890 8476028 : }
891 :
892 : /* Translate all the types in LIST with the corresponding runtime
893 : types. */
894 :
895 : static tree
896 582 : get_eh_types_for_runtime (tree list)
897 : {
898 582 : tree head, prev;
899 :
900 582 : if (list == NULL_TREE)
901 : return NULL_TREE;
902 :
903 206 : head = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
904 206 : prev = head;
905 206 : list = TREE_CHAIN (list);
906 206 : 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 40132 : find_decls_types_in_eh_region (eh_region r, class free_lang_data_d *fld)
923 : {
924 40132 : switch (r->type)
925 : {
926 : case ERT_CLEANUP:
927 : break;
928 :
929 597 : case ERT_TRY:
930 597 : {
931 597 : 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 1012 : for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
937 : {
938 415 : c->type_list = get_eh_types_for_runtime (c->type_list);
939 415 : 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 15469 : case ERT_MUST_NOT_THROW:
951 15469 : walk_tree (&r->u.must_not_throw.failure_decl,
952 : find_decls_types_r, fld, &fld->pset);
953 15469 : break;
954 : }
955 40132 : }
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 372101 : find_decls_types_in_node (struct cgraph_node *n, class free_lang_data_d *fld)
966 : {
967 372101 : basic_block bb;
968 372101 : struct function *fn;
969 372101 : unsigned ix;
970 372101 : tree t;
971 :
972 372101 : find_decls_types (n->decl, fld);
973 :
974 372101 : if (!gimple_has_body_p (n->decl))
975 372101 : return;
976 :
977 126681 : gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
978 :
979 126681 : fn = DECL_STRUCT_FUNCTION (n->decl);
980 :
981 : /* Traverse locals. */
982 794481 : FOR_EACH_LOCAL_DECL (fn, ix, t)
983 573416 : find_decls_types (t, fld);
984 :
985 : /* Traverse EH regions in FN. */
986 126681 : {
987 126681 : eh_region r;
988 166813 : FOR_ALL_EH_REGION_FN (r, fn)
989 40132 : find_decls_types_in_eh_region (r, fld);
990 : }
991 :
992 : /* Traverse every statement in FN. */
993 900527 : FOR_EACH_BB_FN (bb, fn)
994 : {
995 773846 : gphi_iterator psi;
996 773846 : gimple_stmt_iterator si;
997 773846 : unsigned i;
998 :
999 774027 : 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 3879127 : for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
1011 : {
1012 2331435 : gimple *stmt = gsi_stmt (si);
1013 :
1014 2331435 : if (is_gimple_call (stmt))
1015 529854 : find_decls_types (gimple_call_fntype (stmt), fld);
1016 :
1017 9049973 : for (i = 0; i < gimple_num_ops (stmt); i++)
1018 : {
1019 6718538 : tree arg = gimple_op (stmt, i);
1020 6718538 : 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 6718538 : if (arg
1024 5045965 : && TREE_CODE (arg) == TREE_LIST
1025 20170 : && TREE_PURPOSE (arg)
1026 6737377 : && gimple_code (stmt) == GIMPLE_ASM)
1027 18839 : 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 262842 : 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 24821 : free_lang_data_in_cgraph (class free_lang_data_d *fld)
1078 : {
1079 24821 : struct cgraph_node *n;
1080 24821 : varpool_node *v;
1081 24821 : tree t;
1082 24821 : unsigned i;
1083 24821 : alias_pair *p;
1084 :
1085 : /* Find decls and types in the body of every function in the callgraph. */
1086 396922 : FOR_EACH_FUNCTION (n)
1087 372101 : find_decls_types_in_node (n, fld);
1088 :
1089 24821 : 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 287663 : FOR_EACH_VARIABLE (v)
1094 262842 : 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 24905 : 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 2096633 : FOR_EACH_VEC_ELT (fld->decls, i, t)
1106 2071812 : assign_assembler_name_if_needed (t);
1107 :
1108 : /* Traverse every decl found freeing its language data. */
1109 2096633 : FOR_EACH_VEC_ELT (fld->decls, i, t)
1110 2071812 : free_lang_data_in_decl (t, fld);
1111 :
1112 : /* Traverse every type found freeing its language data. */
1113 944654 : FOR_EACH_VEC_ELT (fld->types, i, t)
1114 919833 : free_lang_data_in_type (t, fld);
1115 24821 : }
1116 :
1117 :
1118 : /* Free resources that are used by FE but are not needed once they are done. */
1119 :
1120 : static unsigned
1121 243271 : free_lang_data (void)
1122 : {
1123 243271 : unsigned i;
1124 243271 : class free_lang_data_d fld;
1125 :
1126 : /* If we are the LTO frontend we have freed lang-specific data already. */
1127 243271 : if (in_lto_p
1128 243271 : || (!flag_generate_lto && !flag_generate_offload))
1129 : {
1130 : /* Rebuild type inheritance graph even when not doing LTO to get
1131 : consistent profile data. */
1132 218450 : rebuild_type_inheritance_graph ();
1133 218450 : return 0;
1134 : }
1135 :
1136 24821 : fld_incomplete_types = new hash_map<tree, tree>;
1137 24821 : fld_simplified_types = new hash_map<tree, tree>;
1138 :
1139 : /* Provide a dummy TRANSLATION_UNIT_DECL if the FE failed to provide one. */
1140 24821 : 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 496420 : for (i = 0; i < itk_none; ++i)
1146 471599 : if (integer_types[i])
1147 322671 : 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 24821 : free_lang_data_in_cgraph (&fld);
1152 :
1153 : /* Create gimple variants for common types. */
1154 198568 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
1155 148926 : 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 24821 : lang_hooks.dwarf_name = lhd_dwarf_name;
1160 24821 : lang_hooks.decl_printable_name = gimple_decl_printable_name;
1161 24821 : lang_hooks.gimplify_expr = lhd_gimplify_expr;
1162 24821 : lang_hooks.overwrite_decl_assembler_name = lhd_overwrite_decl_assembler_name;
1163 24821 : lang_hooks.print_xnode = lhd_print_tree_nothing;
1164 24821 : lang_hooks.print_decl = lhd_print_tree_nothing;
1165 24821 : lang_hooks.print_type = lhd_print_tree_nothing;
1166 24821 : lang_hooks.print_identifier = lhd_print_tree_nothing;
1167 :
1168 24821 : lang_hooks.tree_inlining.var_mod_type_p = hook_bool_tree_tree_false;
1169 :
1170 24821 : if (flag_checking)
1171 : {
1172 : int i;
1173 : tree t;
1174 :
1175 944594 : FOR_EACH_VEC_ELT (fld.types, i, t)
1176 919779 : 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 24821 : tree_diagnostics_defaults (global_dc);
1188 :
1189 24821 : rebuild_type_inheritance_graph ();
1190 :
1191 49642 : delete fld_incomplete_types;
1192 49642 : delete fld_simplified_types;
1193 :
1194 : return 0;
1195 243271 : }
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 302985 : pass_ipa_free_lang_data (gcc::context *ctxt)
1214 605970 : : simple_ipa_opt_pass (pass_data_ipa_free_lang_data, ctxt)
1215 : {}
1216 :
1217 : /* opt_pass methods: */
1218 243271 : 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 302985 : make_pass_ipa_free_lang_data (gcc::context *ctxt)
1226 : {
1227 302985 : return new pass_ipa_free_lang_data (ctxt);
1228 : }
|