Branch data 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-2025 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 : 228754 : 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 : 13566938 : add_tree_to_fld_list (tree t, class free_lang_data_d *fld)
80 : : {
81 : 13566938 : if (DECL_P (t))
82 : 9770908 : fld->decls.safe_push (t);
83 : 3796030 : else if (TYPE_P (t))
84 : 3796030 : fld->types.safe_push (t);
85 : : else
86 : 0 : gcc_unreachable ();
87 : 13566938 : }
88 : :
89 : : /* Push tree node T into FLD->WORKLIST. */
90 : :
91 : : static inline void
92 : 160039926 : fld_worklist_push (tree t, class free_lang_data_d *fld)
93 : : {
94 : 237981337 : if (t && !is_lang_specific (t) && !fld->pset.contains (t))
95 : 36351302 : fld->worklist.safe_push ((t));
96 : 160039926 : }
97 : :
98 : :
99 : :
100 : : /* Return simplified TYPE_NAME of TYPE. */
101 : :
102 : : static tree
103 : 4612970 : fld_simplified_type_name (tree type)
104 : : {
105 : 4612970 : if (!TYPE_NAME (type) || TREE_CODE (TYPE_NAME (type)) != TYPE_DECL)
106 : 4070226 : 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 : 542744 : if (type != TYPE_MAIN_VARIANT (type)
111 : 542744 : || (!DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (type))
112 : 245201 : && (TREE_CODE (type) != RECORD_TYPE
113 : 26576 : || !TYPE_BINFO (type)
114 : 0 : || !BINFO_VTABLE (TYPE_BINFO (type)))))
115 : 482150 : return DECL_NAME (TYPE_NAME (type));
116 : 60594 : return TYPE_NAME (type);
117 : : }
118 : :
119 : : /* Do same comparsion 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 : 518722 : fld_type_variant_equal_p (tree t, tree v, tree inner_type)
126 : : {
127 : 518722 : 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 : 391060 : || ((!RECORD_OR_UNION_TYPE_P (t) || COMPLETE_TYPE_P (v))
131 : 273772 : && (TYPE_ALIGN (t) != TYPE_ALIGN (v)
132 : 273760 : || TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (v)))
133 : 391048 : || fld_simplified_type_name (t) != fld_simplified_type_name (v)
134 : 326627 : || !attribute_list_equal (TYPE_ATTRIBUTES (t),
135 : 326627 : TYPE_ATTRIBUTES (v))
136 : 845349 : || (inner_type && TREE_TYPE (v) != inner_type))
137 : 192095 : 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 : 326627 : fld_type_variant (tree first, tree t, class free_lang_data_d *fld,
147 : : tree inner_type = NULL)
148 : : {
149 : 326627 : if (first == TYPE_MAIN_VARIANT (t))
150 : : return t;
151 : 472156 : for (tree v = first; v; v = TYPE_NEXT_VARIANT (v))
152 : 430790 : if (fld_type_variant_equal_p (t, v, inner_type))
153 : : {
154 : 285261 : if (flag_checking)
155 : 331827 : for (tree v2 = TYPE_NEXT_VARIANT (v); v2; v2 = TYPE_NEXT_VARIANT (v2))
156 : 46566 : gcc_assert (!fld_type_variant_equal_p (t, v2, inner_type));
157 : 285261 : return v;
158 : : }
159 : 41366 : tree v = build_variant_type_copy (first);
160 : 41366 : TYPE_READONLY (v) = TYPE_READONLY (t);
161 : 41366 : TYPE_VOLATILE (v) = TYPE_VOLATILE (t);
162 : 41366 : TYPE_ATOMIC (v) = TYPE_ATOMIC (t);
163 : 41366 : TYPE_RESTRICT (v) = TYPE_RESTRICT (t);
164 : 41366 : TYPE_ADDR_SPACE (v) = TYPE_ADDR_SPACE (t);
165 : 41366 : TYPE_NAME (v) = TYPE_NAME (t);
166 : 41366 : TYPE_ATTRIBUTES (v) = TYPE_ATTRIBUTES (t);
167 : 41366 : 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 : 41366 : if (!RECORD_OR_UNION_TYPE_P (v) || COMPLETE_TYPE_P (v))
171 : : {
172 : 19349 : SET_TYPE_ALIGN (v, TYPE_ALIGN (t));
173 : 19349 : TYPE_USER_ALIGN (v) = TYPE_USER_ALIGN (t);
174 : : }
175 : 41366 : if (inner_type)
176 : 18 : TREE_TYPE (v) = inner_type;
177 : 41366 : gcc_checking_assert (fld_type_variant_equal_p (t,v, inner_type));
178 : 41366 : if (!fld->pset.add (v))
179 : 41366 : 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 : 2881 : fld_process_array_type (tree t, tree t2, hash_map<tree, tree> *map,
196 : : class free_lang_data_d *fld)
197 : : {
198 : 2881 : if (TREE_TYPE (t) == t2)
199 : : return t;
200 : :
201 : 142 : if (TYPE_MAIN_VARIANT (t) != t)
202 : : {
203 : 18 : return fld_type_variant
204 : 18 : (fld_process_array_type (TYPE_MAIN_VARIANT (t),
205 : 18 : TYPE_MAIN_VARIANT (t2), map, fld),
206 : 18 : t, fld, t2);
207 : : }
208 : :
209 : 124 : bool existed;
210 : 124 : tree &array
211 : 124 : = map->get_or_insert (t, &existed);
212 : 124 : if (!existed)
213 : : {
214 : 27 : array
215 : 27 : = build_array_type_1 (t2, TYPE_DOMAIN (t), TYPE_TYPELESS_STORAGE (t),
216 : : false, false);
217 : 27 : TYPE_CANONICAL (array) = TYPE_CANONICAL (t);
218 : 27 : if (!fld->pset.add (array))
219 : 27 : add_tree_to_fld_list (array, fld);
220 : : }
221 : 124 : return array;
222 : : }
223 : :
224 : : /* Return CTX after removal of contexts that are not relevant */
225 : :
226 : : static tree
227 : 9496398 : 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 : 8008061 : if (ctx && TYPE_P (ctx)
234 : 9564357 : && !variably_modified_type_p (ctx, NULL_TREE))
235 : : {
236 : 143963 : while (ctx && TYPE_P (ctx))
237 : 76004 : ctx = TYPE_CONTEXT (ctx);
238 : : }
239 : 9496398 : 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 : 5603577 : fld_incomplete_type_of (tree t, class free_lang_data_d *fld)
247 : : {
248 : 5603577 : if (!t)
249 : : return NULL;
250 : 5603577 : if (POINTER_TYPE_P (t))
251 : : {
252 : 2799832 : tree t2 = fld_incomplete_type_of (TREE_TYPE (t), fld);
253 : 2799832 : if (t2 != TREE_TYPE (t))
254 : : {
255 : 258528 : tree first;
256 : 258528 : if (TREE_CODE (t) == POINTER_TYPE)
257 : 233446 : first = build_pointer_type_for_mode (t2, TYPE_MODE (t),
258 : 233446 : TYPE_REF_CAN_ALIAS_ALL (t));
259 : : else
260 : 25082 : first = build_reference_type_for_mode (t2, TYPE_MODE (t),
261 : 25082 : TYPE_REF_CAN_ALIAS_ALL (t));
262 : 258528 : gcc_assert (TYPE_CANONICAL (t2) != t2
263 : : && TYPE_CANONICAL (t2) == TYPE_CANONICAL (TREE_TYPE (t)));
264 : 258528 : if (!fld->pset.add (first))
265 : 56998 : add_tree_to_fld_list (first, fld);
266 : 258528 : return fld_type_variant (first, t, fld);
267 : : }
268 : : return t;
269 : : }
270 : 2803745 : if (TREE_CODE (t) == ARRAY_TYPE)
271 : 2863 : return fld_process_array_type (t,
272 : 2863 : fld_incomplete_type_of (TREE_TYPE (t), fld),
273 : 2863 : fld_incomplete_types, fld);
274 : 2800882 : if ((!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
275 : 2800882 : || !COMPLETE_TYPE_P (t))
276 : : return t;
277 : 324417 : if (TYPE_MAIN_VARIANT (t) == t)
278 : : {
279 : 256336 : bool existed;
280 : 256336 : tree ©
281 : 256336 : = fld_incomplete_types->get_or_insert (t, &existed);
282 : :
283 : 256336 : if (!existed)
284 : : {
285 : 33202 : copy = build_distinct_type_copy (t);
286 : :
287 : : /* It is possible that type was not seen by free_lang_data yet. */
288 : 33202 : if (!fld->pset.add (copy))
289 : 33202 : add_tree_to_fld_list (copy, fld);
290 : 33202 : TYPE_SIZE (copy) = NULL;
291 : 33202 : TYPE_USER_ALIGN (copy) = 0;
292 : 33202 : TYPE_SIZE_UNIT (copy) = NULL;
293 : 33202 : TYPE_CANONICAL (copy) = TYPE_CANONICAL (t);
294 : 33202 : TREE_ADDRESSABLE (copy) = 0;
295 : 33202 : if (AGGREGATE_TYPE_P (t))
296 : : {
297 : 33134 : SET_TYPE_MODE (copy, VOIDmode);
298 : 33134 : SET_TYPE_ALIGN (copy, BITS_PER_UNIT);
299 : 33134 : TYPE_TYPELESS_STORAGE (copy) = 0;
300 : 33134 : TYPE_FIELDS (copy) = NULL;
301 : 33134 : TYPE_BINFO (copy) = NULL;
302 : 33134 : TYPE_FINAL_P (copy) = 0;
303 : 33134 : TYPE_EMPTY_P (copy) = 0;
304 : : }
305 : : else
306 : : {
307 : 68 : TYPE_VALUES (copy) = NULL;
308 : 68 : ENUM_IS_OPAQUE (copy) = 0;
309 : 68 : 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 : 33202 : TYPE_NAME (copy) = fld_simplified_type_name (copy);
319 : 33202 : tree name = TYPE_NAME (copy);
320 : :
321 : 33202 : if (name && TREE_CODE (name) == TYPE_DECL)
322 : : {
323 : 8917 : gcc_checking_assert (TREE_TYPE (name) == t);
324 : 8917 : tree name2 = build_decl (DECL_SOURCE_LOCATION (name), TYPE_DECL,
325 : 8917 : DECL_NAME (name), copy);
326 : 8917 : if (DECL_ASSEMBLER_NAME_SET_P (name))
327 : 8917 : SET_DECL_ASSEMBLER_NAME (name2, DECL_ASSEMBLER_NAME (name));
328 : 8917 : SET_DECL_ALIGN (name2, 0);
329 : 8917 : DECL_CONTEXT (name2) = fld_decl_context
330 : 8917 : (DECL_CONTEXT (name));
331 : 8917 : TYPE_NAME (copy) = name2;
332 : : }
333 : : }
334 : 256336 : return copy;
335 : : }
336 : 68081 : return (fld_type_variant
337 : 68081 : (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 : 17635343 : fld_simplified_type (tree t, class free_lang_data_d *fld)
345 : : {
346 : 17635343 : if (!t)
347 : : return t;
348 : 17635343 : if (POINTER_TYPE_P (t))
349 : 2732801 : 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 : 28076819 : free_lang_data_in_one_sizepos (tree *expr_p)
372 : : {
373 : 28076819 : tree expr = *expr_p;
374 : 28076819 : if (CONTAINS_PLACEHOLDER_P (expr))
375 : 0 : *expr_p = build0 (PLACEHOLDER_EXPR, TREE_TYPE (expr));
376 : 28076819 : }
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 : 55956 : free_lang_data_in_binfo (tree binfo)
384 : : {
385 : 55956 : unsigned i;
386 : 55956 : tree t;
387 : :
388 : 55956 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
389 : :
390 : 55956 : BINFO_VIRTUALS (binfo) = NULL_TREE;
391 : 55956 : BINFO_BASE_ACCESSES (binfo) = NULL;
392 : 55956 : BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE;
393 : 55956 : BINFO_SUBVTT_INDEX (binfo) = NULL_TREE;
394 : 55956 : BINFO_VPTR_FIELD (binfo) = NULL_TREE;
395 : 55956 : TREE_PUBLIC (binfo) = 0;
396 : :
397 : 79259 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo), i, t)
398 : 23303 : free_lang_data_in_binfo (t);
399 : 55956 : }
400 : :
401 : :
402 : : /* Reset all language specific information still present in TYPE. */
403 : :
404 : : static void
405 : 3797672 : free_lang_data_in_type (tree type, class free_lang_data_d *fld)
406 : : {
407 : 3797672 : gcc_assert (TYPE_P (type));
408 : :
409 : : /* Give the FE a chance to remove its own data first. */
410 : 3797672 : lang_hooks.free_lang_data (type);
411 : :
412 : 3797672 : TREE_LANG_FLAG_0 (type) = 0;
413 : 3797672 : TREE_LANG_FLAG_1 (type) = 0;
414 : 3797672 : TREE_LANG_FLAG_2 (type) = 0;
415 : 3797672 : TREE_LANG_FLAG_3 (type) = 0;
416 : 3797672 : TREE_LANG_FLAG_4 (type) = 0;
417 : 3797672 : TREE_LANG_FLAG_5 (type) = 0;
418 : 3797672 : TREE_LANG_FLAG_6 (type) = 0;
419 : :
420 : 3797672 : 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 : 3797672 : while (TYPE_NEXT_VARIANT (type)
425 : 4334003 : && !fld->pset.contains (TYPE_NEXT_VARIANT (type)))
426 : : {
427 : 536331 : tree t = TYPE_NEXT_VARIANT (type);
428 : 536331 : TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (t);
429 : : /* Turn the removed types into distinct types. */
430 : 536331 : TYPE_MAIN_VARIANT (t) = t;
431 : 536331 : TYPE_NEXT_VARIANT (t) = NULL_TREE;
432 : : }
433 : :
434 : 3797672 : if (TREE_CODE (type) == FUNCTION_TYPE)
435 : : {
436 : 2352942 : 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 : 9749911 : for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
443 : : {
444 : 7396969 : tree arg_type = TREE_VALUE (p);
445 : 7396969 : if (TYPE_READONLY (arg_type) || TYPE_VOLATILE (arg_type))
446 : : {
447 : 23543 : int quals = TYPE_QUALS (arg_type)
448 : : & ~TYPE_QUAL_CONST
449 : 23543 : & ~TYPE_QUAL_VOLATILE;
450 : 23543 : TREE_VALUE (p) = build_qualified_type (arg_type, quals);
451 : 23543 : if (!fld->pset.add (TREE_VALUE (p)))
452 : 1642 : free_lang_data_in_type (TREE_VALUE (p), fld);
453 : : }
454 : 7396969 : TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
455 : : /* C++ FE uses TREE_PURPOSE to store initial values. */
456 : 7396969 : TREE_PURPOSE (p) = NULL;
457 : : }
458 : : }
459 : : else if (TREE_CODE (type) == METHOD_TYPE)
460 : : {
461 : 57194 : TREE_TYPE (type) = fld_simplified_type (TREE_TYPE (type), fld);
462 : 224416 : for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
463 : : {
464 : : /* C++ FE uses TREE_PURPOSE to store initial values. */
465 : 167222 : TREE_VALUE (p) = fld_simplified_type (TREE_VALUE (p), fld);
466 : 167222 : TREE_PURPOSE (p) = NULL;
467 : : }
468 : : }
469 : : else if (RECORD_OR_UNION_TYPE_P (type))
470 : : {
471 : : /* Remove members that are not FIELD_DECLs from the field list
472 : : of an aggregate. These occur in C++. */
473 : 901972 : for (tree *prev = &TYPE_FIELDS (type), member; (member = *prev);)
474 : 714321 : if (TREE_CODE (member) == FIELD_DECL)
475 : 362893 : prev = &DECL_CHAIN (member);
476 : : else
477 : 351428 : *prev = DECL_CHAIN (member);
478 : :
479 : 187651 : TYPE_VFIELD (type) = NULL_TREE;
480 : :
481 : 187651 : if (TYPE_BINFO (type))
482 : : {
483 : 32653 : free_lang_data_in_binfo (TYPE_BINFO (type));
484 : : /* We need to preserve link to bases and virtual table for all
485 : : polymorphic types to make devirtualization machinery working. */
486 : 32653 : if (!BINFO_VTABLE (TYPE_BINFO (type)))
487 : 28613 : TYPE_BINFO (type) = NULL;
488 : : }
489 : : }
490 : : else if (INTEGRAL_TYPE_P (type)
491 : : || SCALAR_FLOAT_TYPE_P (type)
492 : : || FIXED_POINT_TYPE_P (type))
493 : : {
494 : 337692 : if (TREE_CODE (type) == ENUMERAL_TYPE)
495 : : {
496 : 3514 : ENUM_IS_OPAQUE (type) = 0;
497 : 3514 : ENUM_IS_SCOPED (type) = 0;
498 : : /* Type values are used only for C++ ODR checking. Drop them
499 : : for all type variants and non-ODR types.
500 : : For ODR types the data is freed in free_odr_warning_data. */
501 : 3514 : if (!TYPE_VALUES (type))
502 : : ;
503 : 1095 : else if (TYPE_MAIN_VARIANT (type) != type
504 : 754 : || !type_with_linkage_p (type)
505 : 1463 : || type_in_anonymous_namespace_p (type))
506 : 758 : TYPE_VALUES (type) = NULL;
507 : : else
508 : 337 : register_odr_enum (type);
509 : : }
510 : 337692 : free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type));
511 : 337692 : free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type));
512 : : }
513 : :
514 : 3797672 : TYPE_LANG_SLOT_1 (type) = NULL_TREE;
515 : :
516 : 3797672 : free_lang_data_in_one_sizepos (&TYPE_SIZE (type));
517 : 3797672 : free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type));
518 : :
519 : 3797672 : if (TYPE_CONTEXT (type)
520 : 3797672 : && TREE_CODE (TYPE_CONTEXT (type)) == BLOCK)
521 : : {
522 : 0 : tree ctx = TYPE_CONTEXT (type);
523 : 0 : do
524 : : {
525 : 0 : ctx = BLOCK_SUPERCONTEXT (ctx);
526 : : }
527 : 0 : while (ctx && TREE_CODE (ctx) == BLOCK);
528 : 0 : TYPE_CONTEXT (type) = ctx;
529 : : }
530 : :
531 : 3797672 : TYPE_STUB_DECL (type) = NULL;
532 : 3797672 : TYPE_NAME (type) = fld_simplified_type_name (type);
533 : 3797672 : }
534 : :
535 : : /* Reset all language specific information still present in symbol
536 : : DECL. */
537 : :
538 : : static void
539 : 9770908 : free_lang_data_in_decl (tree decl, class free_lang_data_d *fld)
540 : : {
541 : 9770908 : gcc_assert (DECL_P (decl));
542 : :
543 : : /* Give the FE a chance to remove its own data first. */
544 : 9770908 : lang_hooks.free_lang_data (decl);
545 : :
546 : 9770908 : TREE_LANG_FLAG_0 (decl) = 0;
547 : 9770908 : TREE_LANG_FLAG_1 (decl) = 0;
548 : 9770908 : TREE_LANG_FLAG_2 (decl) = 0;
549 : 9770908 : TREE_LANG_FLAG_3 (decl) = 0;
550 : 9770908 : TREE_LANG_FLAG_4 (decl) = 0;
551 : 9770908 : TREE_LANG_FLAG_5 (decl) = 0;
552 : 9770908 : TREE_LANG_FLAG_6 (decl) = 0;
553 : :
554 : 9770908 : free_lang_data_in_one_sizepos (&DECL_SIZE (decl));
555 : 9770908 : free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl));
556 : 9770908 : if (TREE_CODE (decl) == FIELD_DECL)
557 : : {
558 : 264275 : DECL_FCONTEXT (decl) = NULL;
559 : 264275 : free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl));
560 : 264275 : if (TREE_CODE (DECL_CONTEXT (decl)) == QUAL_UNION_TYPE)
561 : 0 : DECL_QUALIFIER (decl) = NULL_TREE;
562 : : }
563 : :
564 : 9770908 : if (TREE_CODE (decl) == FUNCTION_DECL)
565 : : {
566 : 7396741 : struct cgraph_node *node;
567 : : /* Frontends do not set TREE_ADDRESSABLE on public variables even though
568 : : the address may be taken in other unit, so this flag has no practical
569 : : use for middle-end.
570 : :
571 : : It would make more sense if frontends set TREE_ADDRESSABLE to 0 only
572 : : for public objects that indeed cannot be adressed, but it is not
573 : : the case. Set the flag to true so we do not get merge failures for
574 : : i.e. virtual tables between units that take address of it and
575 : : units that don't. */
576 : 7396741 : if (TREE_PUBLIC (decl))
577 : 7383313 : TREE_ADDRESSABLE (decl) = true;
578 : 7396741 : TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
579 : 7396741 : if (!(node = cgraph_node::get (decl))
580 : 7396741 : || (!node->definition && !node->clones))
581 : : {
582 : 7271288 : if (node)
583 : 235497 : node->release_body ();
584 : : else
585 : : {
586 : 7035791 : release_function_body (decl);
587 : 7035791 : DECL_ARGUMENTS (decl) = NULL;
588 : 7035791 : DECL_RESULT (decl) = NULL;
589 : 7035791 : DECL_INITIAL (decl) = error_mark_node;
590 : : }
591 : : }
592 : 7396741 : if (gimple_has_body_p (decl) || (node && node->thunk))
593 : : {
594 : 119005 : tree t;
595 : :
596 : : /* If DECL has a gimple body, then the context for its
597 : : arguments must be DECL. Otherwise, it doesn't really
598 : : matter, as we will not be emitting any code for DECL. In
599 : : general, there may be other instances of DECL created by
600 : : the front end and since PARM_DECLs are generally shared,
601 : : their DECL_CONTEXT changes as the replicas of DECL are
602 : : created. The only time where DECL_CONTEXT is important
603 : : is for the FUNCTION_DECLs that have a gimple body (since
604 : : the PARM_DECL will be used in the function's body). */
605 : 458938 : for (t = DECL_ARGUMENTS (decl); t; t = TREE_CHAIN (t))
606 : 339933 : DECL_CONTEXT (t) = decl;
607 : 119005 : if (!DECL_FUNCTION_SPECIFIC_TARGET (decl))
608 : 118991 : DECL_FUNCTION_SPECIFIC_TARGET (decl)
609 : 118991 : = target_option_default_node;
610 : 119005 : if (!DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl))
611 : 115266 : DECL_FUNCTION_SPECIFIC_OPTIMIZATION (decl)
612 : 115266 : = optimization_default_node;
613 : : }
614 : :
615 : : /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
616 : : At this point, it is not needed anymore. */
617 : 7396741 : DECL_SAVED_TREE (decl) = NULL_TREE;
618 : :
619 : : /* Clear the abstract origin if it refers to a method.
620 : : Otherwise dwarf2out.cc will ICE as we splice functions out of
621 : : TYPE_FIELDS and thus the origin will not be output
622 : : correctly. */
623 : 7396741 : if (DECL_ABSTRACT_ORIGIN (decl)
624 : 25661 : && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))
625 : 7422402 : && RECORD_OR_UNION_TYPE_P
626 : : (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))))
627 : 13570 : DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
628 : :
629 : 7396741 : DECL_VINDEX (decl) = NULL_TREE;
630 : : }
631 : : else if (VAR_P (decl))
632 : : {
633 : : /* See comment above why we set the flag for functions. */
634 : 794951 : if (TREE_PUBLIC (decl))
635 : 241855 : TREE_ADDRESSABLE (decl) = true;
636 : 794951 : if ((DECL_EXTERNAL (decl)
637 : 7790 : && (!TREE_STATIC (decl) || !TREE_READONLY (decl)))
638 : 799304 : || (decl_function_context (decl) && !TREE_STATIC (decl)))
639 : 529420 : DECL_INITIAL (decl) = NULL_TREE;
640 : : }
641 : : else if (TREE_CODE (decl) == TYPE_DECL)
642 : : {
643 : 389168 : DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
644 : 389168 : DECL_VISIBILITY_SPECIFIED (decl) = 0;
645 : 389168 : TREE_PUBLIC (decl) = 0;
646 : 389168 : TREE_PRIVATE (decl) = 0;
647 : 389168 : DECL_ARTIFICIAL (decl) = 0;
648 : 389168 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 0;
649 : 389168 : DECL_INITIAL (decl) = NULL_TREE;
650 : 389168 : DECL_ORIGINAL_TYPE (decl) = NULL_TREE;
651 : 389168 : DECL_MODE (decl) = VOIDmode;
652 : 389168 : SET_DECL_ALIGN (decl, 0);
653 : : /* TREE_TYPE is cleared at WPA time in free_odr_warning_data. */
654 : : }
655 : : else if (TREE_CODE (decl) == FIELD_DECL)
656 : : {
657 : 264275 : TREE_TYPE (decl) = fld_simplified_type (TREE_TYPE (decl), fld);
658 : 264275 : DECL_INITIAL (decl) = NULL_TREE;
659 : : }
660 : : else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL
661 : 22654 : && DECL_INITIAL (decl)
662 : 19178 : && TREE_CODE (DECL_INITIAL (decl)) == BLOCK)
663 : : {
664 : : /* Strip builtins from the translation-unit BLOCK. We still have targets
665 : : without builtin_decl_explicit support and also builtins are shared
666 : : nodes and thus we can't use TREE_CHAIN in multiple lists. */
667 : 19178 : tree *nextp = &BLOCK_VARS (DECL_INITIAL (decl));
668 : 19178 : while (*nextp)
669 : : {
670 : 0 : tree var = *nextp;
671 : 0 : if (TREE_CODE (var) == FUNCTION_DECL
672 : 0 : && fndecl_built_in_p (var))
673 : 0 : *nextp = TREE_CHAIN (var);
674 : : else
675 : 0 : nextp = &TREE_CHAIN (var);
676 : : }
677 : : }
678 : : /* We need to keep field decls associated with their trees. Otherwise tree
679 : : merging may merge some fields and keep others disjoint which in turn will
680 : : not do well with TREE_CHAIN pointers linking them.
681 : :
682 : : Also do not drop containing types for virtual methods and tables because
683 : : these are needed by devirtualization.
684 : : C++ destructors are special because C++ frontends sometimes produces
685 : : virtual destructor as an alias of non-virtual destructor. In
686 : : devirutalization code we always walk through aliases and we need
687 : : context to be preserved too. See PR89335 */
688 : 9770908 : if (TREE_CODE (decl) != FIELD_DECL
689 : 9770908 : && ((TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
690 : 8191692 : || (!DECL_VIRTUAL_P (decl)
691 : 8180200 : && (TREE_CODE (decl) != FUNCTION_DECL
692 : 7391635 : || !DECL_CXX_DESTRUCTOR_P (decl)))))
693 : 9487481 : DECL_CONTEXT (decl) = fld_decl_context (DECL_CONTEXT (decl));
694 : 9770908 : }
695 : :
696 : :
697 : : /* Operand callback helper for free_lang_data_in_node. *TP is the
698 : : subtree operand being considered. */
699 : :
700 : : static tree
701 : 48055444 : find_decls_types_r (tree *tp, int *ws, void *data)
702 : : {
703 : 48055444 : tree t = *tp;
704 : 48055444 : class free_lang_data_d *fld = (class free_lang_data_d *) data;
705 : :
706 : 48055444 : if (TREE_CODE (t) == TREE_LIST)
707 : : return NULL_TREE;
708 : :
709 : : /* Language specific nodes will be removed, so there is no need
710 : : to gather anything under them. */
711 : 27370956 : if (is_lang_specific (t))
712 : : {
713 : 15 : *ws = 0;
714 : 15 : return NULL_TREE;
715 : : }
716 : :
717 : 27370941 : if (DECL_P (t))
718 : : {
719 : : /* Note that walk_tree does not traverse every possible field in
720 : : decls, so we have to do our own traversals here. */
721 : 9770908 : add_tree_to_fld_list (t, fld);
722 : :
723 : 9770908 : fld_worklist_push (DECL_NAME (t), fld);
724 : 9770908 : fld_worklist_push (DECL_CONTEXT (t), fld);
725 : 9770908 : fld_worklist_push (DECL_SIZE (t), fld);
726 : 9770908 : fld_worklist_push (DECL_SIZE_UNIT (t), fld);
727 : :
728 : : /* We are going to remove everything under DECL_INITIAL for
729 : : TYPE_DECLs. No point walking them. */
730 : 9770908 : if (TREE_CODE (t) != TYPE_DECL)
731 : 9381740 : fld_worklist_push (DECL_INITIAL (t), fld);
732 : :
733 : 9770908 : fld_worklist_push (DECL_ATTRIBUTES (t), fld);
734 : 9770908 : fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld);
735 : :
736 : 9770908 : if (TREE_CODE (t) == FUNCTION_DECL)
737 : : {
738 : 7396741 : fld_worklist_push (DECL_ARGUMENTS (t), fld);
739 : 7396741 : fld_worklist_push (DECL_RESULT (t), fld);
740 : : }
741 : 2374167 : else if (TREE_CODE (t) == FIELD_DECL)
742 : : {
743 : 264275 : fld_worklist_push (DECL_FIELD_OFFSET (t), fld);
744 : 264275 : fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld);
745 : 264275 : fld_worklist_push (DECL_FIELD_BIT_OFFSET (t), fld);
746 : 264275 : fld_worklist_push (DECL_FCONTEXT (t), fld);
747 : : }
748 : :
749 : 9770908 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
750 : 9770908 : && DECL_HAS_VALUE_EXPR_P (t))
751 : 6257 : fld_worklist_push (DECL_VALUE_EXPR (t), fld);
752 : :
753 : 9770908 : if (TREE_CODE (t) != FIELD_DECL
754 : 9770908 : && TREE_CODE (t) != TYPE_DECL)
755 : 9117465 : fld_worklist_push (TREE_CHAIN (t), fld);
756 : 9770908 : *ws = 0;
757 : : }
758 : 17600033 : else if (TYPE_P (t))
759 : : {
760 : : /* Note that walk_tree does not traverse every possible field in
761 : : types, so we have to do our own traversals here. */
762 : 3664437 : add_tree_to_fld_list (t, fld);
763 : :
764 : 3664437 : if (!RECORD_OR_UNION_TYPE_P (t))
765 : 3531939 : fld_worklist_push (TYPE_CACHED_VALUES (t), fld);
766 : 3664437 : fld_worklist_push (TYPE_SIZE (t), fld);
767 : 3664437 : fld_worklist_push (TYPE_SIZE_UNIT (t), fld);
768 : 3664437 : fld_worklist_push (TYPE_ATTRIBUTES (t), fld);
769 : 3664437 : fld_worklist_push (TYPE_POINTER_TO (t), fld);
770 : 3664437 : fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
771 : 3664437 : fld_worklist_push (TYPE_NAME (t), fld);
772 : : /* While we do not stream TYPE_POINTER_TO and TYPE_REFERENCE_TO
773 : : lists, we may look types up in these lists and use them while
774 : : optimizing the function body. Thus we need to free lang data
775 : : in them. */
776 : 3664437 : if (TREE_CODE (t) == POINTER_TYPE)
777 : 612537 : fld_worklist_push (TYPE_NEXT_PTR_TO (t), fld);
778 : 3664437 : if (TREE_CODE (t) == REFERENCE_TYPE)
779 : 43218 : fld_worklist_push (TYPE_NEXT_REF_TO (t), fld);
780 : 3664437 : if (!POINTER_TYPE_P (t))
781 : 3008682 : fld_worklist_push (TYPE_MIN_VALUE_RAW (t), fld);
782 : : /* TYPE_MAX_VALUE_RAW is TYPE_BINFO for record types. */
783 : 3664437 : if (!RECORD_OR_UNION_TYPE_P (t))
784 : 3531939 : fld_worklist_push (TYPE_MAX_VALUE_RAW (t), fld);
785 : 3664437 : fld_worklist_push (TYPE_MAIN_VARIANT (t), fld);
786 : : /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
787 : : do not and want not to reach unused variants this way. */
788 : 3664437 : if (TYPE_CONTEXT (t))
789 : : {
790 : 34207 : tree ctx = TYPE_CONTEXT (t);
791 : : /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
792 : : So push that instead. */
793 : 34207 : while (ctx && TREE_CODE (ctx) == BLOCK)
794 : 0 : ctx = BLOCK_SUPERCONTEXT (ctx);
795 : 34207 : fld_worklist_push (ctx, fld);
796 : : }
797 : 3664437 : fld_worklist_push (TYPE_CANONICAL (t), fld);
798 : :
799 : 3664437 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t))
800 : : {
801 : : unsigned i;
802 : : tree tem;
803 : 42269 : FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t)), i, tem)
804 : 9616 : fld_worklist_push (TREE_TYPE (tem), fld);
805 : 32653 : fld_worklist_push (BINFO_TYPE (TYPE_BINFO (t)), fld);
806 : 32653 : fld_worklist_push (BINFO_VTABLE (TYPE_BINFO (t)), fld);
807 : : }
808 : 3664437 : if (RECORD_OR_UNION_TYPE_P (t))
809 : : {
810 : 132498 : tree tem;
811 : : /* Push all TYPE_FIELDS - there can be interleaving interesting
812 : : and non-interesting things. */
813 : 132498 : tem = TYPE_FIELDS (t);
814 : 1087714 : while (tem)
815 : : {
816 : 955216 : if (TREE_CODE (tem) == FIELD_DECL)
817 : 362889 : fld_worklist_push (tem, fld);
818 : 955216 : tem = TREE_CHAIN (tem);
819 : : }
820 : : }
821 : 3664437 : if (FUNC_OR_METHOD_TYPE_P (t))
822 : 2410136 : fld_worklist_push (TYPE_METHOD_BASETYPE (t), fld);
823 : :
824 : 3664437 : fld_worklist_push (TYPE_STUB_DECL (t), fld);
825 : 3664437 : *ws = 0;
826 : : }
827 : 13935596 : else if (TREE_CODE (t) == BLOCK)
828 : : {
829 : 984107 : for (tree *tem = &BLOCK_VARS (t); *tem; )
830 : : {
831 : 789714 : if (TREE_CODE (*tem) != LABEL_DECL
832 : 789714 : && (TREE_CODE (*tem) != VAR_DECL
833 : 373020 : || !auto_var_in_fn_p (*tem, DECL_CONTEXT (*tem))))
834 : : {
835 : 434920 : gcc_assert (TREE_CODE (*tem) != RESULT_DECL
836 : : && TREE_CODE (*tem) != PARM_DECL);
837 : 434920 : *tem = TREE_CHAIN (*tem);
838 : : }
839 : : else
840 : : {
841 : 354794 : fld_worklist_push (*tem, fld);
842 : 354794 : tem = &TREE_CHAIN (*tem);
843 : : }
844 : : }
845 : 237695 : for (tree tem = BLOCK_SUBBLOCKS (t); tem; tem = BLOCK_CHAIN (tem))
846 : 43302 : fld_worklist_push (tem, fld);
847 : 194393 : fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t), fld);
848 : : }
849 : : /* walk_tree does not visit ce->index which can be a FIELD_DECL, pulling
850 : : in otherwise unused structure fields so handle CTORs explicitly. */
851 : 13741203 : else if (TREE_CODE (t) == CONSTRUCTOR)
852 : : {
853 : : unsigned HOST_WIDE_INT idx;
854 : : constructor_elt *ce;
855 : 1335192 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce); idx++)
856 : : {
857 : 1053768 : if (ce->index)
858 : 459944 : fld_worklist_push (ce->index, fld);
859 : 1053768 : fld_worklist_push (ce->value, fld);
860 : : }
861 : 281424 : *ws = 0;
862 : : }
863 : :
864 : 27370941 : if (TREE_CODE (t) != IDENTIFIER_NODE
865 : 18556224 : && CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPED))
866 : 18361831 : fld_worklist_push (TREE_TYPE (t), fld);
867 : :
868 : : return NULL_TREE;
869 : : }
870 : :
871 : :
872 : : /* Find decls and types in T. */
873 : :
874 : : static void
875 : 8081385 : find_decls_types (tree t, class free_lang_data_d *fld)
876 : : {
877 : 80783989 : while (1)
878 : : {
879 : 44432687 : if (!fld->pset.contains (t))
880 : 35827084 : walk_tree (&t, find_decls_types_r, fld, &fld->pset);
881 : 44432687 : if (fld->worklist.is_empty ())
882 : : break;
883 : 36351302 : t = fld->worklist.pop ();
884 : : }
885 : 8081385 : }
886 : :
887 : : /* Translate all the types in LIST with the corresponding runtime
888 : : types. */
889 : :
890 : : static tree
891 : 564 : get_eh_types_for_runtime (tree list)
892 : : {
893 : 564 : tree head, prev;
894 : :
895 : 564 : if (list == NULL_TREE)
896 : : return NULL_TREE;
897 : :
898 : 200 : head = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
899 : 200 : prev = head;
900 : 200 : list = TREE_CHAIN (list);
901 : 200 : while (list)
902 : : {
903 : 0 : tree n = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
904 : 0 : TREE_CHAIN (prev) = n;
905 : 0 : prev = TREE_CHAIN (prev);
906 : 0 : list = TREE_CHAIN (list);
907 : : }
908 : :
909 : : return head;
910 : : }
911 : :
912 : :
913 : : /* Find decls and types referenced in EH region R and store them in
914 : : FLD->DECLS and FLD->TYPES. */
915 : :
916 : : static void
917 : 37176 : find_decls_types_in_eh_region (eh_region r, class free_lang_data_d *fld)
918 : : {
919 : 37176 : switch (r->type)
920 : : {
921 : : case ERT_CLEANUP:
922 : : break;
923 : :
924 : 574 : case ERT_TRY:
925 : 574 : {
926 : 574 : eh_catch c;
927 : :
928 : : /* The types referenced in each catch must first be changed to the
929 : : EH types used at runtime. This removes references to FE types
930 : : in the region. */
931 : 971 : for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
932 : : {
933 : 397 : c->type_list = get_eh_types_for_runtime (c->type_list);
934 : 397 : walk_tree (&c->type_list, find_decls_types_r, fld, &fld->pset);
935 : : }
936 : : }
937 : : break;
938 : :
939 : 167 : case ERT_ALLOWED_EXCEPTIONS:
940 : 167 : r->u.allowed.type_list
941 : 167 : = get_eh_types_for_runtime (r->u.allowed.type_list);
942 : 167 : walk_tree (&r->u.allowed.type_list, find_decls_types_r, fld, &fld->pset);
943 : 167 : break;
944 : :
945 : 13949 : case ERT_MUST_NOT_THROW:
946 : 13949 : walk_tree (&r->u.must_not_throw.failure_decl,
947 : : find_decls_types_r, fld, &fld->pset);
948 : 13949 : break;
949 : : }
950 : 37176 : }
951 : :
952 : :
953 : : /* Find decls and types referenced in cgraph node N and store them in
954 : : FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
955 : : look for *every* kind of DECL and TYPE node reachable from N,
956 : : including those embedded inside types and decls (i.e,, TYPE_DECLs,
957 : : NAMESPACE_DECLs, etc). */
958 : :
959 : : static void
960 : 360950 : find_decls_types_in_node (struct cgraph_node *n, class free_lang_data_d *fld)
961 : : {
962 : 360950 : basic_block bb;
963 : 360950 : struct function *fn;
964 : 360950 : unsigned ix;
965 : 360950 : tree t;
966 : :
967 : 360950 : find_decls_types (n->decl, fld);
968 : :
969 : 360950 : if (!gimple_has_body_p (n->decl))
970 : 360950 : return;
971 : :
972 : 118835 : gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
973 : :
974 : 118835 : fn = DECL_STRUCT_FUNCTION (n->decl);
975 : :
976 : : /* Traverse locals. */
977 : 752836 : FOR_EACH_LOCAL_DECL (fn, ix, t)
978 : 546392 : find_decls_types (t, fld);
979 : :
980 : : /* Traverse EH regions in FN. */
981 : 118835 : {
982 : 118835 : eh_region r;
983 : 156011 : FOR_ALL_EH_REGION_FN (r, fn)
984 : 37176 : find_decls_types_in_eh_region (r, fld);
985 : : }
986 : :
987 : : /* Traverse every statement in FN. */
988 : 852613 : FOR_EACH_BB_FN (bb, fn)
989 : : {
990 : 733778 : gphi_iterator psi;
991 : 733778 : gimple_stmt_iterator si;
992 : 733778 : unsigned i;
993 : :
994 : 733820 : for (psi = gsi_start_phis (bb); !gsi_end_p (psi); gsi_next (&psi))
995 : : {
996 : 42 : gphi *phi = psi.phi ();
997 : :
998 : 122 : for (i = 0; i < gimple_phi_num_args (phi); i++)
999 : : {
1000 : 80 : tree *arg_p = gimple_phi_arg_def_ptr (phi, i);
1001 : 80 : find_decls_types (*arg_p, fld);
1002 : : }
1003 : : }
1004 : :
1005 : 3675342 : for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
1006 : : {
1007 : 2207786 : gimple *stmt = gsi_stmt (si);
1008 : :
1009 : 2207786 : if (is_gimple_call (stmt))
1010 : 511505 : find_decls_types (gimple_call_fntype (stmt), fld);
1011 : :
1012 : 8593839 : for (i = 0; i < gimple_num_ops (stmt); i++)
1013 : : {
1014 : 6386053 : tree arg = gimple_op (stmt, i);
1015 : 6386053 : find_decls_types (arg, fld);
1016 : : /* find_decls_types doesn't walk TREE_PURPOSE of TREE_LISTs,
1017 : : which we need for asm stmts. */
1018 : 6386053 : if (arg
1019 : 4779052 : && TREE_CODE (arg) == TREE_LIST
1020 : 17676 : && TREE_PURPOSE (arg)
1021 : 6402423 : && gimple_code (stmt) == GIMPLE_ASM)
1022 : 16370 : find_decls_types (TREE_PURPOSE (arg), fld);
1023 : : }
1024 : : }
1025 : : }
1026 : : }
1027 : :
1028 : :
1029 : : /* Find decls and types referenced in varpool node N and store them in
1030 : : FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
1031 : : look for *every* kind of DECL and TYPE node reachable from N,
1032 : : including those embedded inside types and decls (i.e,, TYPE_DECLs,
1033 : : NAMESPACE_DECLs, etc). */
1034 : :
1035 : : static void
1036 : 260035 : find_decls_types_in_var (varpool_node *v, class free_lang_data_d *fld)
1037 : : {
1038 : 0 : find_decls_types (v->decl, fld);
1039 : 0 : }
1040 : :
1041 : : /* Free language specific information for every operand and expression
1042 : : in every node of the call graph. This process operates in three stages:
1043 : :
1044 : : 1- Every callgraph node and varpool node is traversed looking for
1045 : : decls and types embedded in them. This is a more exhaustive
1046 : : search than that done by find_referenced_vars, because it will
1047 : : also collect individual fields, decls embedded in types, etc.
1048 : :
1049 : : 2- All the decls found are sent to free_lang_data_in_decl.
1050 : :
1051 : : 3- All the types found are sent to free_lang_data_in_type.
1052 : :
1053 : : The ordering between decls and types is important because
1054 : : free_lang_data_in_decl sets assembler names, which includes
1055 : : mangling. So types cannot be freed up until assembler names have
1056 : : been set up. */
1057 : :
1058 : : static void
1059 : 23831 : free_lang_data_in_cgraph (class free_lang_data_d *fld)
1060 : : {
1061 : 23831 : struct cgraph_node *n;
1062 : 23831 : varpool_node *v;
1063 : 23831 : tree t;
1064 : 23831 : unsigned i;
1065 : 23831 : alias_pair *p;
1066 : :
1067 : : /* Find decls and types in the body of every function in the callgraph. */
1068 : 769562 : FOR_EACH_FUNCTION (n)
1069 : 360950 : find_decls_types_in_node (n, fld);
1070 : :
1071 : 23831 : FOR_EACH_VEC_SAFE_ELT (alias_pairs, i, p)
1072 : 0 : find_decls_types (p->decl, fld);
1073 : :
1074 : : /* Find decls and types in every varpool symbol. */
1075 : 307697 : FOR_EACH_VARIABLE (v)
1076 : 260035 : find_decls_types_in_var (v, fld);
1077 : :
1078 : : /* Set the assembler name on every decl found. We need to do this
1079 : : now because free_lang_data_in_decl will invalidate data needed
1080 : : for mangling. This breaks mangling on interdependent decls. */
1081 : 9794739 : FOR_EACH_VEC_ELT (fld->decls, i, t)
1082 : 9770908 : assign_assembler_name_if_needed (t);
1083 : :
1084 : : /* Traverse every decl found freeing its language data. */
1085 : 9794739 : FOR_EACH_VEC_ELT (fld->decls, i, t)
1086 : 9770908 : free_lang_data_in_decl (t, fld);
1087 : :
1088 : : /* Traverse every type found freeing its language data. */
1089 : 3819861 : FOR_EACH_VEC_ELT (fld->types, i, t)
1090 : 3796030 : free_lang_data_in_type (t, fld);
1091 : 23831 : }
1092 : :
1093 : :
1094 : : /* Free resources that are used by FE but are not needed once they are done. */
1095 : :
1096 : : static unsigned
1097 : 228754 : free_lang_data (void)
1098 : : {
1099 : 228754 : unsigned i;
1100 : 228754 : class free_lang_data_d fld;
1101 : :
1102 : : /* If we are the LTO frontend we have freed lang-specific data already. */
1103 : 228754 : if (in_lto_p
1104 : 228754 : || (!flag_generate_lto && !flag_generate_offload))
1105 : : {
1106 : : /* Rebuild type inheritance graph even when not doing LTO to get
1107 : : consistent profile data. */
1108 : 204923 : rebuild_type_inheritance_graph ();
1109 : 204923 : return 0;
1110 : : }
1111 : :
1112 : 23831 : fld_incomplete_types = new hash_map<tree, tree>;
1113 : 23831 : fld_simplified_types = new hash_map<tree, tree>;
1114 : :
1115 : : /* Provide a dummy TRANSLATION_UNIT_DECL if the FE failed to provide one. */
1116 : 23831 : if (vec_safe_is_empty (all_translation_units))
1117 : 949 : build_translation_unit_decl (NULL_TREE);
1118 : :
1119 : : /* Allocate and assign alias sets to the standard integer types
1120 : : while the slots are still in the way the frontends generated them. */
1121 : 476620 : for (i = 0; i < itk_none; ++i)
1122 : 452789 : if (integer_types[i])
1123 : 309803 : TYPE_ALIAS_SET (integer_types[i]) = get_alias_set (integer_types[i]);
1124 : :
1125 : : /* Traverse the IL resetting language specific information for
1126 : : operands, expressions, etc. */
1127 : 23831 : free_lang_data_in_cgraph (&fld);
1128 : :
1129 : : /* Create gimple variants for common types. */
1130 : 166817 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
1131 : 142986 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
1132 : :
1133 : : /* Reset some langhooks. Do not reset types_compatible_p, it may
1134 : : still be used indirectly via the get_alias_set langhook. */
1135 : 23831 : lang_hooks.dwarf_name = lhd_dwarf_name;
1136 : 23831 : lang_hooks.decl_printable_name = gimple_decl_printable_name;
1137 : 23831 : lang_hooks.gimplify_expr = lhd_gimplify_expr;
1138 : 23831 : lang_hooks.overwrite_decl_assembler_name = lhd_overwrite_decl_assembler_name;
1139 : 23831 : lang_hooks.print_xnode = lhd_print_tree_nothing;
1140 : 23831 : lang_hooks.print_decl = lhd_print_tree_nothing;
1141 : 23831 : lang_hooks.print_type = lhd_print_tree_nothing;
1142 : 23831 : lang_hooks.print_identifier = lhd_print_tree_nothing;
1143 : :
1144 : 23831 : lang_hooks.tree_inlining.var_mod_type_p = hook_bool_tree_tree_false;
1145 : :
1146 : 23831 : if (flag_checking)
1147 : : {
1148 : : int i;
1149 : : tree t;
1150 : :
1151 : 3819753 : FOR_EACH_VEC_ELT (fld.types, i, t)
1152 : 3795928 : verify_type (t);
1153 : : }
1154 : :
1155 : : /* We do not want the default decl_assembler_name implementation,
1156 : : rather if we have fixed everything we want a wrapper around it
1157 : : asserting that all non-local symbols already got their assembler
1158 : : name and only produce assembler names for local symbols. Or rather
1159 : : make sure we never call decl_assembler_name on local symbols and
1160 : : devise a separate, middle-end private scheme for it. */
1161 : :
1162 : : /* Reset diagnostic machinery. */
1163 : 23831 : tree_diagnostics_defaults (global_dc);
1164 : :
1165 : 23831 : rebuild_type_inheritance_graph ();
1166 : :
1167 : 47662 : delete fld_incomplete_types;
1168 : 47662 : delete fld_simplified_types;
1169 : :
1170 : : return 0;
1171 : 228754 : }
1172 : :
1173 : : const pass_data pass_data_ipa_free_lang_data =
1174 : : {
1175 : : SIMPLE_IPA_PASS, /* type */
1176 : : "*free_lang_data", /* name */
1177 : : OPTGROUP_NONE, /* optinfo_flags */
1178 : : TV_IPA_FREE_LANG_DATA, /* tv_id */
1179 : : 0, /* properties_required */
1180 : : 0, /* properties_provided */
1181 : : 0, /* properties_destroyed */
1182 : : 0, /* todo_flags_start */
1183 : : 0, /* todo_flags_finish */
1184 : : };
1185 : :
1186 : : class pass_ipa_free_lang_data : public simple_ipa_opt_pass
1187 : : {
1188 : : public:
1189 : 285081 : pass_ipa_free_lang_data (gcc::context *ctxt)
1190 : 570162 : : simple_ipa_opt_pass (pass_data_ipa_free_lang_data, ctxt)
1191 : : {}
1192 : :
1193 : : /* opt_pass methods: */
1194 : 228754 : unsigned int execute (function *) final override { return free_lang_data (); }
1195 : :
1196 : : }; // class pass_ipa_free_lang_data
1197 : :
1198 : : } // anon namespace
1199 : :
1200 : : simple_ipa_opt_pass *
1201 : 285081 : make_pass_ipa_free_lang_data (gcc::context *ctxt)
1202 : : {
1203 : 285081 : return new pass_ipa_free_lang_data (ctxt);
1204 : : }
|