Branch data Line data Source code
1 : : /* Language-independent node constructors for parse phase of GNU compiler.
2 : : Copyright (C) 1987-2025 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify it under
7 : : the terms of the GNU General Public License as published by the Free
8 : : Software Foundation; either version 3, or (at your option) any later
9 : : version.
10 : :
11 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : : /* This file contains the low level primitives for operating on tree nodes,
21 : : including allocation, list operations, interning of identifiers,
22 : : construction of data type nodes and statement nodes,
23 : : and construction of type conversion nodes. It also contains
24 : : tables index by tree code that describe how to take apart
25 : : nodes of that code.
26 : :
27 : : It is intended to be language-independent but can occasionally
28 : : calls language-dependent routines. */
29 : :
30 : : #include "config.h"
31 : : #include "system.h"
32 : : #include "coretypes.h"
33 : : #include "backend.h"
34 : : #include "target.h"
35 : : #include "memmodel.h"
36 : : #include "tm_p.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 "flags.h"
44 : : #include "alias.h"
45 : : #include "fold-const.h"
46 : : #include "stor-layout.h"
47 : : #include "calls.h"
48 : : #include "attribs.h"
49 : : #include "toplev.h" /* get_random_seed */
50 : : #include "output.h"
51 : : #include "common/common-target.h"
52 : : #include "langhooks.h"
53 : : #include "tree-inline.h"
54 : : #include "tree-iterator.h"
55 : : #include "internal-fn.h"
56 : : #include "gimple-iterator.h"
57 : : #include "gimplify.h"
58 : : #include "tree-dfa.h"
59 : : #include "langhooks-def.h"
60 : : #include "tree-diagnostic.h"
61 : : #include "except.h"
62 : : #include "builtins.h"
63 : : #include "print-tree.h"
64 : : #include "ipa-utils.h"
65 : : #include "selftest.h"
66 : : #include "stringpool.h"
67 : : #include "attribs.h"
68 : : #include "rtl.h"
69 : : #include "regs.h"
70 : : #include "tree-vector-builder.h"
71 : : #include "gimple-fold.h"
72 : : #include "escaped_string.h"
73 : : #include "gimple-range.h"
74 : : #include "gomp-constants.h"
75 : : #include "dfp.h"
76 : : #include "asan.h"
77 : : #include "ubsan.h"
78 : :
79 : : /* Names of tree components.
80 : : Used for printing out the tree and error messages. */
81 : : #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
82 : : #define END_OF_BASE_TREE_CODES "@dummy",
83 : :
84 : : static const char *const tree_code_name[] = {
85 : : #include "all-tree.def"
86 : : };
87 : :
88 : : #undef DEFTREECODE
89 : : #undef END_OF_BASE_TREE_CODES
90 : :
91 : : /* Each tree code class has an associated string representation.
92 : : These must correspond to the tree_code_class entries. */
93 : :
94 : : const char *const tree_code_class_strings[] =
95 : : {
96 : : "exceptional",
97 : : "constant",
98 : : "type",
99 : : "declaration",
100 : : "reference",
101 : : "comparison",
102 : : "unary",
103 : : "binary",
104 : : "statement",
105 : : "vl_exp",
106 : : "expression"
107 : : };
108 : :
109 : : /* obstack.[ch] explicitly declined to prototype this. */
110 : : extern int _obstack_allocated_p (struct obstack *h, void *obj);
111 : :
112 : : /* Statistics-gathering stuff. */
113 : :
114 : : static uint64_t tree_code_counts[MAX_TREE_CODES];
115 : : uint64_t tree_node_counts[(int) all_kinds];
116 : : uint64_t tree_node_sizes[(int) all_kinds];
117 : :
118 : : /* Keep in sync with tree.h:enum tree_node_kind. */
119 : : static const char * const tree_node_kind_names[] = {
120 : : "decls",
121 : : "types",
122 : : "blocks",
123 : : "stmts",
124 : : "refs",
125 : : "exprs",
126 : : "constants",
127 : : "identifiers",
128 : : "vecs",
129 : : "binfos",
130 : : "ssa names",
131 : : "constructors",
132 : : "random kinds",
133 : : "lang_decl kinds",
134 : : "lang_type kinds",
135 : : "omp clauses",
136 : : };
137 : :
138 : : /* Unique id for next decl created. */
139 : : static GTY(()) int next_decl_uid;
140 : : /* Unique id for next type created. */
141 : : static GTY(()) unsigned next_type_uid = 1;
142 : : /* Unique id for next debug decl created. Use negative numbers,
143 : : to catch erroneous uses. */
144 : : static GTY(()) int next_debug_decl_uid;
145 : :
146 : : /* Since we cannot rehash a type after it is in the table, we have to
147 : : keep the hash code. */
148 : :
149 : : struct GTY((for_user)) type_hash {
150 : : unsigned long hash;
151 : : tree type;
152 : : };
153 : :
154 : : /* Initial size of the hash table (rounded to next prime). */
155 : : #define TYPE_HASH_INITIAL_SIZE 1000
156 : :
157 : : struct type_cache_hasher : ggc_cache_ptr_hash<type_hash>
158 : : {
159 : 8025670876 : static hashval_t hash (type_hash *t) { return t->hash; }
160 : : static bool equal (type_hash *a, type_hash *b);
161 : :
162 : : static int
163 : 1717825506 : keep_cache_entry (type_hash *&t)
164 : : {
165 : 1717825506 : return ggc_marked_p (t->type);
166 : : }
167 : : };
168 : :
169 : : /* Now here is the hash table. When recording a type, it is added to
170 : : the slot whose index is the hash code. Note that the hash table is
171 : : used for several kinds of types (function types, array types and
172 : : array index range types, for now). While all these live in the
173 : : same table, they are completely independent, and the hash code is
174 : : computed differently for each of these. */
175 : :
176 : : static GTY ((cache)) hash_table<type_cache_hasher> *type_hash_table;
177 : :
178 : : /* Hash table and temporary node for larger integer const values. */
179 : : static GTY (()) tree int_cst_node;
180 : :
181 : : struct int_cst_hasher : ggc_cache_ptr_hash<tree_node>
182 : : {
183 : : static hashval_t hash (tree t);
184 : : static bool equal (tree x, tree y);
185 : : };
186 : :
187 : : static GTY ((cache)) hash_table<int_cst_hasher> *int_cst_hash_table;
188 : :
189 : : /* Class and variable for making sure that there is a single POLY_INT_CST
190 : : for a given value. */
191 : : struct poly_int_cst_hasher : ggc_cache_ptr_hash<tree_node>
192 : : {
193 : : typedef std::pair<tree, const poly_wide_int *> compare_type;
194 : : static hashval_t hash (tree t);
195 : : static bool equal (tree x, const compare_type &y);
196 : : };
197 : :
198 : : static GTY ((cache)) hash_table<poly_int_cst_hasher> *poly_int_cst_hash_table;
199 : :
200 : : /* Hash table for optimization flags and target option flags. Use the same
201 : : hash table for both sets of options. Nodes for building the current
202 : : optimization and target option nodes. The assumption is most of the time
203 : : the options created will already be in the hash table, so we avoid
204 : : allocating and freeing up a node repeatably. */
205 : : static GTY (()) tree cl_optimization_node;
206 : : static GTY (()) tree cl_target_option_node;
207 : :
208 : : struct cl_option_hasher : ggc_cache_ptr_hash<tree_node>
209 : : {
210 : : static hashval_t hash (tree t);
211 : : static bool equal (tree x, tree y);
212 : : };
213 : :
214 : : static GTY ((cache)) hash_table<cl_option_hasher> *cl_option_hash_table;
215 : :
216 : 715251 : struct gt_value_expr_mark_data {
217 : : hash_set<tree> pset;
218 : : auto_vec<tree, 16> to_mark;
219 : : };
220 : :
221 : : /* Callback called through walk_tree_1 to discover DECL_HAS_VALUE_EXPR_P
222 : : VAR_DECLs which weren't marked yet, in that case marks them and
223 : : walks their DECL_VALUE_EXPR expressions. */
224 : :
225 : : static tree
226 : 13401580 : gt_value_expr_mark_2 (tree *tp, int *, void *data)
227 : : {
228 : 13401580 : tree t = *tp;
229 : 13401580 : if (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t) && !ggc_marked_p (t))
230 : : {
231 : 1044 : tree dve = DECL_VALUE_EXPR (t);
232 : 1044 : gt_value_expr_mark_data *d = (gt_value_expr_mark_data *) data;
233 : 1044 : walk_tree_1 (&dve, gt_value_expr_mark_2, data, &d->pset, NULL);
234 : 1044 : d->to_mark.safe_push (t);
235 : : }
236 : 13401580 : return NULL_TREE;
237 : : }
238 : :
239 : : /* Callback called through traverse_noresize on the
240 : : value_expr_for_decl hash table. */
241 : :
242 : : int
243 : 5555428 : gt_value_expr_mark_1 (tree_decl_map **e, gt_value_expr_mark_data *data)
244 : : {
245 : 5555428 : if (ggc_marked_p ((*e)->base.from))
246 : 4786794 : walk_tree_1 (&(*e)->to, gt_value_expr_mark_2, data, &data->pset, NULL);
247 : 5555428 : return 1;
248 : : }
249 : :
250 : : /* The value_expr_for_decl hash table can have mappings for trees
251 : : which are only referenced from mappings of other trees in the
252 : : same table, see PR118790. Without this routine, gt_cleare_cache
253 : : could clear hash table slot of a tree which isn't marked but
254 : : will be marked when processing later hash table slot of another
255 : : tree which is marked. This function marks with the above
256 : : helpers marks all the not yet marked DECL_HAS_VALUE_EXPR_P
257 : : VAR_DECLs mentioned in DECL_VALUE_EXPR expressions of marked
258 : : trees and in that case also recurses on their DECL_VALUE_EXPR. */
259 : :
260 : : void
261 : 715251 : gt_value_expr_mark (hash_table<tree_decl_map_cache_hasher> *h)
262 : : {
263 : 715251 : if (!h)
264 : 0 : return;
265 : :
266 : 715251 : gt_value_expr_mark_data data;
267 : 715251 : h->traverse_noresize<gt_value_expr_mark_data *,
268 : 6270679 : gt_value_expr_mark_1> (&data);
269 : 2146797 : for (auto v : data.to_mark)
270 : 1044 : gt_ggc_mx (v);
271 : 715251 : }
272 : :
273 : : /* General tree->tree mapping structure for use in hash tables. */
274 : :
275 : :
276 : : static GTY ((cache))
277 : : hash_table<tree_decl_map_cache_hasher> *debug_expr_for_decl;
278 : :
279 : : static GTY ((cache ("gt_value_expr_mark")))
280 : : hash_table<tree_decl_map_cache_hasher> *value_expr_for_decl;
281 : :
282 : : static GTY ((cache))
283 : : hash_table<tree_vec_map_cache_hasher> *debug_args_for_decl;
284 : :
285 : : static void set_type_quals (tree, int);
286 : : static void print_type_hash_statistics (void);
287 : : static void print_debug_expr_statistics (void);
288 : : static void print_value_expr_statistics (void);
289 : :
290 : : tree global_trees[TI_MAX];
291 : : tree integer_types[itk_none];
292 : :
293 : : bool int_n_enabled_p[NUM_INT_N_ENTS];
294 : : struct int_n_trees_t int_n_trees [NUM_INT_N_ENTS];
295 : :
296 : : bool tree_contains_struct[MAX_TREE_CODES][64];
297 : :
298 : : /* Number of operands for each OMP clause. */
299 : : unsigned const char omp_clause_num_ops[] =
300 : : {
301 : : 0, /* OMP_CLAUSE_ERROR */
302 : : 1, /* OMP_CLAUSE_PRIVATE */
303 : : 1, /* OMP_CLAUSE_SHARED */
304 : : 1, /* OMP_CLAUSE_FIRSTPRIVATE */
305 : : 2, /* OMP_CLAUSE_LASTPRIVATE */
306 : : 5, /* OMP_CLAUSE_REDUCTION */
307 : : 5, /* OMP_CLAUSE_TASK_REDUCTION */
308 : : 5, /* OMP_CLAUSE_IN_REDUCTION */
309 : : 1, /* OMP_CLAUSE_COPYIN */
310 : : 1, /* OMP_CLAUSE_COPYPRIVATE */
311 : : 3, /* OMP_CLAUSE_LINEAR */
312 : : 1, /* OMP_CLAUSE_AFFINITY */
313 : : 2, /* OMP_CLAUSE_ALIGNED */
314 : : 3, /* OMP_CLAUSE_ALLOCATE */
315 : : 1, /* OMP_CLAUSE_DEPEND */
316 : : 1, /* OMP_CLAUSE_NONTEMPORAL */
317 : : 1, /* OMP_CLAUSE_UNIFORM */
318 : : 1, /* OMP_CLAUSE_ENTER */
319 : : 1, /* OMP_CLAUSE_LINK */
320 : : 1, /* OMP_CLAUSE_DETACH */
321 : : 1, /* OMP_CLAUSE_USE_DEVICE_PTR */
322 : : 1, /* OMP_CLAUSE_USE_DEVICE_ADDR */
323 : : 1, /* OMP_CLAUSE_IS_DEVICE_PTR */
324 : : 1, /* OMP_CLAUSE_INCLUSIVE */
325 : : 1, /* OMP_CLAUSE_EXCLUSIVE */
326 : : 3, /* OMP_CLAUSE_FROM */
327 : : 3, /* OMP_CLAUSE_TO */
328 : : 3, /* OMP_CLAUSE_MAP (update walk_tree_1 if this is changed) */
329 : : 1, /* OMP_CLAUSE_HAS_DEVICE_ADDR */
330 : : 1, /* OMP_CLAUSE_DOACROSS */
331 : : 3, /* OMP_CLAUSE__MAPPER_BINDING_ */
332 : : 2, /* OMP_CLAUSE__CACHE_ */
333 : : 1, /* OMP_CLAUSE_DESTROY */
334 : : 2, /* OMP_CLAUSE_INIT */
335 : : 1, /* OMP_CLAUSE_USE */
336 : : 1, /* OMP_CLAUSE_INTEROP */
337 : : 2, /* OMP_CLAUSE_GANG */
338 : : 1, /* OMP_CLAUSE_ASYNC */
339 : : 1, /* OMP_CLAUSE_WAIT */
340 : : 0, /* OMP_CLAUSE_AUTO */
341 : : 0, /* OMP_CLAUSE_SEQ */
342 : : 1, /* OMP_CLAUSE__LOOPTEMP_ */
343 : : 1, /* OMP_CLAUSE__REDUCTEMP_ */
344 : : 1, /* OMP_CLAUSE__CONDTEMP_ */
345 : : 1, /* OMP_CLAUSE__SCANTEMP_ */
346 : : 1, /* OMP_CLAUSE_IF */
347 : : 1, /* OMP_CLAUSE_SELF */
348 : : 1, /* OMP_CLAUSE_NUM_THREADS */
349 : : 1, /* OMP_CLAUSE_SCHEDULE */
350 : : 0, /* OMP_CLAUSE_NOWAIT */
351 : : 1, /* OMP_CLAUSE_ORDERED */
352 : : 0, /* OMP_CLAUSE_DEFAULT */
353 : : 3, /* OMP_CLAUSE_COLLAPSE */
354 : : 0, /* OMP_CLAUSE_UNTIED */
355 : : 1, /* OMP_CLAUSE_FINAL */
356 : : 0, /* OMP_CLAUSE_MERGEABLE */
357 : : 1, /* OMP_CLAUSE_DEVICE */
358 : : 1, /* OMP_CLAUSE_DIST_SCHEDULE */
359 : : 0, /* OMP_CLAUSE_INBRANCH */
360 : : 0, /* OMP_CLAUSE_NOTINBRANCH */
361 : : 2, /* OMP_CLAUSE_NUM_TEAMS */
362 : : 1, /* OMP_CLAUSE_THREAD_LIMIT */
363 : : 0, /* OMP_CLAUSE_PROC_BIND */
364 : : 1, /* OMP_CLAUSE_SAFELEN */
365 : : 1, /* OMP_CLAUSE_SIMDLEN */
366 : : 0, /* OMP_CLAUSE_DEVICE_TYPE */
367 : : 0, /* OMP_CLAUSE_FOR */
368 : : 0, /* OMP_CLAUSE_PARALLEL */
369 : : 0, /* OMP_CLAUSE_SECTIONS */
370 : : 0, /* OMP_CLAUSE_TASKGROUP */
371 : : 1, /* OMP_CLAUSE_PRIORITY */
372 : : 1, /* OMP_CLAUSE_GRAINSIZE */
373 : : 1, /* OMP_CLAUSE_NUM_TASKS */
374 : : 0, /* OMP_CLAUSE_NOGROUP */
375 : : 0, /* OMP_CLAUSE_THREADS */
376 : : 0, /* OMP_CLAUSE_SIMD */
377 : : 1, /* OMP_CLAUSE_HINT */
378 : : 0, /* OMP_CLAUSE_DEFAULTMAP */
379 : : 0, /* OMP_CLAUSE_ORDER */
380 : : 0, /* OMP_CLAUSE_BIND */
381 : : 1, /* OMP_CLAUSE_FILTER */
382 : : 1, /* OMP_CLAUSE_INDIRECT */
383 : : 1, /* OMP_CLAUSE_PARTIAL */
384 : : 0, /* OMP_CLAUSE_FULL */
385 : : 1, /* OMP_CLAUSE_SIZES */
386 : : 1, /* OMP_CLAUSE__SIMDUID_ */
387 : : 0, /* OMP_CLAUSE__SIMT_ */
388 : : 0, /* OMP_CLAUSE_INDEPENDENT */
389 : : 1, /* OMP_CLAUSE_WORKER */
390 : : 1, /* OMP_CLAUSE_VECTOR */
391 : : 1, /* OMP_CLAUSE_NUM_GANGS */
392 : : 1, /* OMP_CLAUSE_NUM_WORKERS */
393 : : 1, /* OMP_CLAUSE_VECTOR_LENGTH */
394 : : 3, /* OMP_CLAUSE_TILE */
395 : : 0, /* OMP_CLAUSE_IF_PRESENT */
396 : : 0, /* OMP_CLAUSE_FINALIZE */
397 : : 0, /* OMP_CLAUSE_NOHOST */
398 : : 1, /* OMP_CLAUSE_NOVARIANTS */
399 : : 1, /* OMP_CLAUSE_NOCONTEXT */
400 : : };
401 : :
402 : : const char * const omp_clause_code_name[] =
403 : : {
404 : : "error_clause",
405 : : "private",
406 : : "shared",
407 : : "firstprivate",
408 : : "lastprivate",
409 : : "reduction",
410 : : "task_reduction",
411 : : "in_reduction",
412 : : "copyin",
413 : : "copyprivate",
414 : : "linear",
415 : : "affinity",
416 : : "aligned",
417 : : "allocate",
418 : : "depend",
419 : : "nontemporal",
420 : : "uniform",
421 : : "enter",
422 : : "link",
423 : : "detach",
424 : : "use_device_ptr",
425 : : "use_device_addr",
426 : : "is_device_ptr",
427 : : "inclusive",
428 : : "exclusive",
429 : : "from",
430 : : "to",
431 : : "map",
432 : : "has_device_addr",
433 : : "doacross",
434 : : "_mapper_binding_",
435 : : "_cache_",
436 : : "destroy",
437 : : "init",
438 : : "use",
439 : : "interop",
440 : : "gang",
441 : : "async",
442 : : "wait",
443 : : "auto",
444 : : "seq",
445 : : "_looptemp_",
446 : : "_reductemp_",
447 : : "_condtemp_",
448 : : "_scantemp_",
449 : : "if",
450 : : "self",
451 : : "num_threads",
452 : : "schedule",
453 : : "nowait",
454 : : "ordered",
455 : : "default",
456 : : "collapse",
457 : : "untied",
458 : : "final",
459 : : "mergeable",
460 : : "device",
461 : : "dist_schedule",
462 : : "inbranch",
463 : : "notinbranch",
464 : : "num_teams",
465 : : "thread_limit",
466 : : "proc_bind",
467 : : "safelen",
468 : : "simdlen",
469 : : "device_type",
470 : : "for",
471 : : "parallel",
472 : : "sections",
473 : : "taskgroup",
474 : : "priority",
475 : : "grainsize",
476 : : "num_tasks",
477 : : "nogroup",
478 : : "threads",
479 : : "simd",
480 : : "hint",
481 : : "defaultmap",
482 : : "order",
483 : : "bind",
484 : : "filter",
485 : : "indirect",
486 : : "partial",
487 : : "full",
488 : : "sizes",
489 : : "_simduid_",
490 : : "_simt_",
491 : : "independent",
492 : : "worker",
493 : : "vector",
494 : : "num_gangs",
495 : : "num_workers",
496 : : "vector_length",
497 : : "tile",
498 : : "if_present",
499 : : "finalize",
500 : : "nohost",
501 : : "novariants",
502 : : "nocontext",
503 : : };
504 : :
505 : : /* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric
506 : : clause names, but for use in diagnostics etc. would like to use the "user"
507 : : clause names. */
508 : :
509 : : const char *
510 : 465 : user_omp_clause_code_name (tree clause, bool oacc)
511 : : {
512 : : /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to
513 : : distinguish clauses as seen by the user. See also where front ends do
514 : : 'build_omp_clause' with 'OMP_CLAUSE_MAP'. */
515 : 930 : if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
516 : 465 : switch (OMP_CLAUSE_MAP_KIND (clause))
517 : : {
518 : : case GOMP_MAP_FORCE_ALLOC:
519 : : case GOMP_MAP_ALLOC: return "create";
520 : 0 : case GOMP_MAP_FORCE_TO:
521 : 0 : case GOMP_MAP_TO: return "copyin";
522 : 0 : case GOMP_MAP_FORCE_FROM:
523 : 0 : case GOMP_MAP_FROM: return "copyout";
524 : 381 : case GOMP_MAP_FORCE_TOFROM:
525 : 381 : case GOMP_MAP_TOFROM: return "copy";
526 : 0 : case GOMP_MAP_RELEASE: return "delete";
527 : 0 : case GOMP_MAP_FORCE_PRESENT: return "present";
528 : 42 : case GOMP_MAP_ATTACH: return "attach";
529 : 42 : case GOMP_MAP_FORCE_DETACH:
530 : 42 : case GOMP_MAP_DETACH: return "detach";
531 : 0 : case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
532 : 0 : case GOMP_MAP_LINK: return "link";
533 : 0 : case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
534 : : default: break;
535 : : }
536 : :
537 : 0 : return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
538 : : }
539 : :
540 : :
541 : : /* Return the tree node structure used by tree code CODE. */
542 : :
543 : : static inline enum tree_node_structure_enum
544 : 36779008601 : tree_node_structure_for_code (enum tree_code code)
545 : : {
546 : 36779008601 : switch (TREE_CODE_CLASS (code))
547 : : {
548 : 9180813600 : case tcc_declaration:
549 : 9180813600 : switch (code)
550 : : {
551 : : case CONST_DECL: return TS_CONST_DECL;
552 : : case DEBUG_EXPR_DECL: return TS_DECL_WRTL;
553 : : case FIELD_DECL: return TS_FIELD_DECL;
554 : : case FUNCTION_DECL: return TS_FUNCTION_DECL;
555 : : case LABEL_DECL: return TS_LABEL_DECL;
556 : : case PARM_DECL: return TS_PARM_DECL;
557 : : case RESULT_DECL: return TS_RESULT_DECL;
558 : : case TRANSLATION_UNIT_DECL: return TS_TRANSLATION_UNIT_DECL;
559 : : case TYPE_DECL: return TS_TYPE_DECL;
560 : : case VAR_DECL: return TS_VAR_DECL;
561 : : default: return TS_DECL_NON_COMMON;
562 : : }
563 : :
564 : : case tcc_type: return TS_TYPE_NON_COMMON;
565 : :
566 : 9321188041 : case tcc_binary:
567 : 9321188041 : case tcc_comparison:
568 : 9321188041 : case tcc_expression:
569 : 9321188041 : case tcc_reference:
570 : 9321188041 : case tcc_statement:
571 : 9321188041 : case tcc_unary:
572 : 9321188041 : case tcc_vl_exp: return TS_EXP;
573 : :
574 : 13182160519 : default: /* tcc_constant and tcc_exceptional */
575 : 13182160519 : break;
576 : : }
577 : :
578 : 13182160519 : switch (code)
579 : : {
580 : : /* tcc_constant cases. */
581 : : case COMPLEX_CST: return TS_COMPLEX;
582 : 285689 : case FIXED_CST: return TS_FIXED_CST;
583 : 429390679 : case INTEGER_CST: return TS_INT_CST;
584 : 285689 : case POLY_INT_CST: return TS_POLY_INT_CST;
585 : 40017550 : case REAL_CST: return TS_REAL_CST;
586 : 226482986 : case STRING_CST: return TS_STRING;
587 : 11448217 : case VECTOR_CST: return TS_VECTOR;
588 : 1001810 : case VOID_CST: return TS_TYPED;
589 : 285862 : case RAW_DATA_CST: return TS_RAW_DATA_CST;
590 : :
591 : : /* tcc_exceptional cases. */
592 : 612274735 : case BLOCK: return TS_BLOCK;
593 : 115769985 : case CONSTRUCTOR: return TS_CONSTRUCTOR;
594 : : case ERROR_MARK: return TS_COMMON;
595 : 8694842 : case IDENTIFIER_NODE: return TS_IDENTIFIER;
596 : 815597 : case OMP_CLAUSE: return TS_OMP_CLAUSE;
597 : 1730216 : case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
598 : : case PLACEHOLDER_EXPR: return TS_COMMON;
599 : 252896650 : case SSA_NAME: return TS_SSA_NAME;
600 : 636778357 : case STATEMENT_LIST: return TS_STATEMENT_LIST;
601 : 3615025 : case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
602 : 241210125 : case TREE_BINFO: return TS_BINFO;
603 : 8811929042 : case TREE_LIST: return TS_LIST;
604 : 1785476284 : case TREE_VEC: return TS_VEC;
605 : :
606 : 0 : default:
607 : 0 : gcc_unreachable ();
608 : : }
609 : : }
610 : :
611 : :
612 : : /* Initialize tree_contains_struct to describe the hierarchy of tree
613 : : nodes. */
614 : :
615 : : static void
616 : 285689 : initialize_tree_contains_struct (void)
617 : : {
618 : 285689 : unsigned i;
619 : :
620 : 70279494 : for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
621 : : {
622 : 69993805 : enum tree_code code;
623 : 69993805 : enum tree_node_structure_enum ts_code;
624 : :
625 : 69993805 : code = (enum tree_code) i;
626 : 69993805 : ts_code = tree_node_structure_for_code (code);
627 : :
628 : : /* Mark the TS structure itself. */
629 : 69993805 : tree_contains_struct[code][ts_code] = 1;
630 : :
631 : : /* Mark all the structures that TS is derived from. */
632 : 69993805 : switch (ts_code)
633 : : {
634 : 1142756 : case TS_TYPED:
635 : 1142756 : case TS_BLOCK:
636 : 1142756 : case TS_OPTIMIZATION:
637 : 1142756 : case TS_TARGET_OPTION:
638 : 1142756 : MARK_TS_BASE (code);
639 : 1142756 : break;
640 : :
641 : 57709178 : case TS_COMMON:
642 : 57709178 : case TS_INT_CST:
643 : 57709178 : case TS_POLY_INT_CST:
644 : 57709178 : case TS_REAL_CST:
645 : 57709178 : case TS_FIXED_CST:
646 : 57709178 : case TS_VECTOR:
647 : 57709178 : case TS_STRING:
648 : 57709178 : case TS_RAW_DATA_CST:
649 : 57709178 : case TS_COMPLEX:
650 : 57709178 : case TS_SSA_NAME:
651 : 57709178 : case TS_CONSTRUCTOR:
652 : 57709178 : case TS_EXP:
653 : 57709178 : case TS_STATEMENT_LIST:
654 : 57709178 : MARK_TS_TYPED (code);
655 : 57709178 : break;
656 : :
657 : 1428445 : case TS_IDENTIFIER:
658 : 1428445 : case TS_DECL_MINIMAL:
659 : 1428445 : case TS_TYPE_COMMON:
660 : 1428445 : case TS_LIST:
661 : 1428445 : case TS_VEC:
662 : 1428445 : case TS_BINFO:
663 : 1428445 : case TS_OMP_CLAUSE:
664 : 1428445 : MARK_TS_COMMON (code);
665 : 1428445 : break;
666 : :
667 : 0 : case TS_TYPE_WITH_LANG_SPECIFIC:
668 : 0 : MARK_TS_TYPE_COMMON (code);
669 : 0 : break;
670 : :
671 : 5999469 : case TS_TYPE_NON_COMMON:
672 : 5999469 : MARK_TS_TYPE_WITH_LANG_SPECIFIC (code);
673 : 5999469 : break;
674 : :
675 : 0 : case TS_DECL_COMMON:
676 : 0 : MARK_TS_DECL_MINIMAL (code);
677 : 0 : break;
678 : :
679 : 571378 : case TS_DECL_WRTL:
680 : 571378 : case TS_CONST_DECL:
681 : 571378 : MARK_TS_DECL_COMMON (code);
682 : 571378 : break;
683 : :
684 : 857067 : case TS_DECL_NON_COMMON:
685 : 857067 : MARK_TS_DECL_WITH_VIS (code);
686 : 857067 : break;
687 : :
688 : 857067 : case TS_DECL_WITH_VIS:
689 : 857067 : case TS_PARM_DECL:
690 : 857067 : case TS_LABEL_DECL:
691 : 857067 : case TS_RESULT_DECL:
692 : 857067 : MARK_TS_DECL_WRTL (code);
693 : 857067 : break;
694 : :
695 : 285689 : case TS_FIELD_DECL:
696 : 285689 : MARK_TS_DECL_COMMON (code);
697 : 285689 : break;
698 : :
699 : 285689 : case TS_VAR_DECL:
700 : 285689 : MARK_TS_DECL_WITH_VIS (code);
701 : 285689 : break;
702 : :
703 : 571378 : case TS_TYPE_DECL:
704 : 571378 : case TS_FUNCTION_DECL:
705 : 571378 : MARK_TS_DECL_NON_COMMON (code);
706 : 571378 : break;
707 : :
708 : 285689 : case TS_TRANSLATION_UNIT_DECL:
709 : 285689 : MARK_TS_DECL_COMMON (code);
710 : 285689 : break;
711 : :
712 : : default:
713 : : gcc_unreachable ();
714 : : }
715 : : }
716 : :
717 : : /* Basic consistency checks for attributes used in fold. */
718 : 285689 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
719 : 285689 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
720 : 285689 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
721 : 285689 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
722 : 285689 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
723 : 285689 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
724 : 285689 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
725 : 285689 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
726 : 285689 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
727 : 285689 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
728 : 285689 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
729 : 285689 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
730 : 285689 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
731 : 285689 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
732 : 285689 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
733 : 285689 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
734 : 285689 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
735 : 285689 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
736 : 285689 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
737 : 285689 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
738 : 285689 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
739 : 285689 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
740 : 285689 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
741 : 285689 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
742 : 285689 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
743 : 285689 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
744 : 285689 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
745 : 285689 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
746 : 285689 : gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
747 : 285689 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
748 : 285689 : gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
749 : 285689 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
750 : 285689 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
751 : 285689 : gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
752 : 285689 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
753 : 285689 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
754 : 285689 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
755 : 285689 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
756 : 285689 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_MINIMAL]);
757 : 285689 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_COMMON]);
758 : 285689 : }
759 : :
760 : :
761 : : /* Init tree.cc. */
762 : :
763 : : void
764 : 285689 : init_ttree (void)
765 : : {
766 : : /* Initialize the hash table of types. */
767 : 285689 : type_hash_table
768 : 285689 : = hash_table<type_cache_hasher>::create_ggc (TYPE_HASH_INITIAL_SIZE);
769 : :
770 : 285689 : debug_expr_for_decl
771 : 285689 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
772 : :
773 : 285689 : value_expr_for_decl
774 : 285689 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
775 : :
776 : 285689 : int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024);
777 : :
778 : 285689 : poly_int_cst_hash_table = hash_table<poly_int_cst_hasher>::create_ggc (64);
779 : :
780 : 285689 : int_cst_node = make_int_cst (1, 1);
781 : :
782 : 285689 : cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64);
783 : :
784 : 285689 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
785 : 285689 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
786 : :
787 : : /* Initialize the tree_contains_struct array. */
788 : 285689 : initialize_tree_contains_struct ();
789 : 285689 : lang_hooks.init_ts ();
790 : 285689 : }
791 : :
792 : :
793 : : /* Mapping from prefix to label number. */
794 : :
795 : : struct identifier_hash : ggc_ptr_hash <tree_node>
796 : : {
797 : 33745 : static inline hashval_t hash (tree t)
798 : : {
799 : 33745 : return IDENTIFIER_HASH_VALUE (t);
800 : : }
801 : : };
802 : : struct identifier_count_traits
803 : : : simple_hashmap_traits<identifier_hash, long> {};
804 : : typedef hash_map<tree, long, identifier_count_traits> internal_label_map;
805 : : static GTY(()) internal_label_map *internal_label_nums;
806 : :
807 : : /* Generates an identifier intended to be used internally with the
808 : : given PREFIX. This is intended to be used by the frontend so that
809 : : C++ modules can regenerate appropriate (non-clashing) identifiers on
810 : : stream-in. */
811 : :
812 : : tree
813 : 33562 : generate_internal_label (const char *prefix)
814 : : {
815 : 33562 : tree prefix_id = get_identifier (prefix);
816 : 33562 : if (!internal_label_nums)
817 : 2644 : internal_label_nums = internal_label_map::create_ggc();
818 : 33562 : long &num = internal_label_nums->get_or_insert (prefix_id);
819 : :
820 : 33562 : char tmp[32];
821 : 33562 : ASM_GENERATE_INTERNAL_LABEL (tmp, prefix, num++);
822 : :
823 : 33562 : tree id = get_identifier (tmp);
824 : 33562 : IDENTIFIER_INTERNAL_P (id) = true;
825 : :
826 : : /* Cache the prefix on the identifier so we can retrieve it later. */
827 : 33562 : TREE_CHAIN (id) = prefix_id;
828 : :
829 : 33562 : return id;
830 : : }
831 : :
832 : : /* Get the PREFIX we created the internal identifier LABEL with. */
833 : :
834 : : const char *
835 : 7 : prefix_for_internal_label (tree label)
836 : : {
837 : 7 : gcc_assert (IDENTIFIER_INTERNAL_P (label)
838 : : && !IDENTIFIER_TRANSPARENT_ALIAS (label)
839 : : && TREE_CHAIN (label)
840 : : && TREE_CODE (TREE_CHAIN (label)) == IDENTIFIER_NODE);
841 : 7 : return IDENTIFIER_POINTER (TREE_CHAIN (label));
842 : : }
843 : :
844 : : /* The name of the object as the assembler will see it (but before any
845 : : translations made by ASM_OUTPUT_LABELREF). Often this is the same
846 : : as DECL_NAME. It is an IDENTIFIER_NODE. */
847 : : tree
848 : 1607215362 : decl_assembler_name (tree decl)
849 : : {
850 : 1607215362 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
851 : 136544891 : lang_hooks.set_decl_assembler_name (decl);
852 : 1607215362 : return DECL_ASSEMBLER_NAME_RAW (decl);
853 : : }
854 : :
855 : : /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
856 : : (either of which may be NULL). Inform the FE, if this changes the
857 : : name. */
858 : :
859 : : void
860 : 779105567 : overwrite_decl_assembler_name (tree decl, tree name)
861 : : {
862 : 779105567 : if (DECL_ASSEMBLER_NAME_RAW (decl) != name)
863 : 408123051 : lang_hooks.overwrite_decl_assembler_name (decl, name);
864 : 779105567 : }
865 : :
866 : : /* Return true if DECL may need an assembler name to be set. */
867 : :
868 : : static inline bool
869 : 5074251 : need_assembler_name_p (tree decl)
870 : : {
871 : : /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
872 : : Rule merging. This makes type_odr_p to return true on those types during
873 : : LTO and by comparing the mangled name, we can say what types are intended
874 : : to be equivalent across compilation unit.
875 : :
876 : : We do not store names of type_in_anonymous_namespace_p.
877 : :
878 : : Record, union and enumeration type have linkage that allows use
879 : : to check type_in_anonymous_namespace_p. We do not mangle compound types
880 : : that always can be compared structurally.
881 : :
882 : : Similarly for builtin types, we compare properties of their main variant.
883 : : A special case are integer types where mangling do make differences
884 : : between char/signed char/unsigned char etc. Storing name for these makes
885 : : e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
886 : : See cp/mangle.cc:write_builtin_type for details. */
887 : :
888 : 5074251 : if (TREE_CODE (decl) == TYPE_DECL)
889 : : {
890 : 153085 : if (DECL_NAME (decl)
891 : 123975 : && decl == TYPE_NAME (TREE_TYPE (decl))
892 : 123824 : && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
893 : 105366 : && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
894 : 102346 : && ((TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
895 : 84968 : && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE)
896 : 17616 : || TYPE_CXX_ODR_P (TREE_TYPE (decl)))
897 : 100947 : && (type_with_linkage_p (TREE_TYPE (decl))
898 : 86527 : || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
899 : 220011 : && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
900 : 66926 : return !DECL_ASSEMBLER_NAME_SET_P (decl);
901 : 86159 : return false;
902 : : }
903 : : /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
904 : 4921166 : if (!VAR_OR_FUNCTION_DECL_P (decl))
905 : : return false;
906 : :
907 : : /* If DECL already has its assembler name set, it does not need a
908 : : new one. */
909 : 4252180 : if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
910 : 4252180 : || DECL_ASSEMBLER_NAME_SET_P (decl))
911 : : return false;
912 : :
913 : : /* Abstract decls do not need an assembler name, except they
914 : : can be looked up by autofdo. */
915 : 1685483 : if (DECL_ABSTRACT_P (decl) && !flag_auto_profile)
916 : : return false;
917 : :
918 : : /* For VAR_DECLs, only static, public and external symbols need an
919 : : assembler name. */
920 : 1684164 : if (VAR_P (decl)
921 : 532135 : && !TREE_STATIC (decl)
922 : 531807 : && !TREE_PUBLIC (decl)
923 : 2215971 : && !DECL_EXTERNAL (decl))
924 : : return false;
925 : :
926 : 1152357 : if (TREE_CODE (decl) == FUNCTION_DECL)
927 : : {
928 : : /* Do not set assembler name on builtins. Allow RTL expansion to
929 : : decide whether to expand inline or via a regular call. */
930 : 1152029 : if (fndecl_built_in_p (decl)
931 : 1152029 : && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
932 : : return false;
933 : :
934 : : /* Functions represented in the callgraph need an assembler name. */
935 : 1147388 : if (cgraph_node::get (decl) != NULL)
936 : : return true;
937 : :
938 : : /* Unused and not public functions don't need an assembler name. */
939 : 3169 : if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
940 : : return false;
941 : : }
942 : :
943 : : return true;
944 : : }
945 : :
946 : : /* If T needs an assembler name, have one created for it. */
947 : :
948 : : void
949 : 5074251 : assign_assembler_name_if_needed (tree t)
950 : : {
951 : 5074251 : if (need_assembler_name_p (t))
952 : : {
953 : : /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
954 : : diagnostics that use input_location to show locus
955 : : information. The problem here is that, at this point,
956 : : input_location is generally anchored to the end of the file
957 : : (since the parser is long gone), so we don't have a good
958 : : position to pin it to.
959 : :
960 : : To alleviate this problem, this uses the location of T's
961 : : declaration. Examples of this are
962 : : testsuite/g++.dg/template/cond2.C and
963 : : testsuite/g++.dg/template/pr35240.C. */
964 : 1214616 : location_t saved_location = input_location;
965 : 1214616 : input_location = DECL_SOURCE_LOCATION (t);
966 : :
967 : 1214616 : decl_assembler_name (t);
968 : :
969 : 1214616 : input_location = saved_location;
970 : : }
971 : 5074251 : }
972 : :
973 : : /* When the target supports COMDAT groups, this indicates which group the
974 : : DECL is associated with. This can be either an IDENTIFIER_NODE or a
975 : : decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
976 : : tree
977 : 372863437 : decl_comdat_group (const_tree node)
978 : : {
979 : 372863437 : struct symtab_node *snode = symtab_node::get (node);
980 : 372863437 : if (!snode)
981 : : return NULL;
982 : 355985332 : return snode->get_comdat_group ();
983 : : }
984 : :
985 : : /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
986 : : tree
987 : 11745 : decl_comdat_group_id (const_tree node)
988 : : {
989 : 11745 : struct symtab_node *snode = symtab_node::get (node);
990 : 11745 : if (!snode)
991 : : return NULL;
992 : 11745 : return snode->get_comdat_group_id ();
993 : : }
994 : :
995 : : /* When the target supports named section, return its name as IDENTIFIER_NODE
996 : : or NULL if it is in no section. */
997 : : const char *
998 : 702985798 : decl_section_name (const_tree node)
999 : : {
1000 : 702985798 : struct symtab_node *snode = symtab_node::get (node);
1001 : 702985798 : if (!snode)
1002 : : return NULL;
1003 : 552153567 : return snode->get_section ();
1004 : : }
1005 : :
1006 : : /* Set section name of NODE to VALUE (that is expected to be
1007 : : identifier node) */
1008 : : void
1009 : 1813756 : set_decl_section_name (tree node, const char *value)
1010 : : {
1011 : 1813756 : struct symtab_node *snode;
1012 : :
1013 : 1813756 : if (value == NULL)
1014 : : {
1015 : 46 : snode = symtab_node::get (node);
1016 : 46 : if (!snode)
1017 : : return;
1018 : : }
1019 : 1813710 : else if (VAR_P (node))
1020 : 1556567 : snode = varpool_node::get_create (node);
1021 : : else
1022 : 257143 : snode = cgraph_node::get_create (node);
1023 : 1813756 : snode->set_section (value);
1024 : : }
1025 : :
1026 : : /* Set section name of NODE to match the section name of OTHER.
1027 : :
1028 : : set_decl_section_name (decl, other) is equivalent to
1029 : : set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more
1030 : : efficient. */
1031 : : void
1032 : 14107997 : set_decl_section_name (tree decl, const_tree other)
1033 : : {
1034 : 14107997 : struct symtab_node *other_node = symtab_node::get (other);
1035 : 14107997 : if (other_node)
1036 : : {
1037 : 14107699 : struct symtab_node *decl_node;
1038 : 14107699 : if (VAR_P (decl))
1039 : 23 : decl_node = varpool_node::get_create (decl);
1040 : : else
1041 : 14107676 : decl_node = cgraph_node::get_create (decl);
1042 : 14107699 : decl_node->set_section (*other_node);
1043 : : }
1044 : : else
1045 : : {
1046 : 298 : struct symtab_node *decl_node = symtab_node::get (decl);
1047 : 298 : if (!decl_node)
1048 : : return;
1049 : 0 : decl_node->set_section (NULL);
1050 : : }
1051 : : }
1052 : :
1053 : : /* Return TLS model of a variable NODE. */
1054 : : enum tls_model
1055 : 247691664 : decl_tls_model (const_tree node)
1056 : : {
1057 : 247691664 : struct varpool_node *snode = varpool_node::get (node);
1058 : 247691664 : if (!snode)
1059 : : return TLS_MODEL_NONE;
1060 : 207492352 : return snode->tls_model;
1061 : : }
1062 : :
1063 : : /* Set TLS model of variable NODE to MODEL. */
1064 : : void
1065 : 58954 : set_decl_tls_model (tree node, enum tls_model model)
1066 : : {
1067 : 58954 : struct varpool_node *vnode;
1068 : :
1069 : 58954 : if (model == TLS_MODEL_NONE)
1070 : : {
1071 : 6028 : vnode = varpool_node::get (node);
1072 : 6028 : if (!vnode)
1073 : : return;
1074 : : }
1075 : : else
1076 : 52926 : vnode = varpool_node::get_create (node);
1077 : 52926 : vnode->tls_model = model;
1078 : : }
1079 : :
1080 : : /* Compute the number of bytes occupied by a tree with code CODE.
1081 : : This function cannot be used for nodes that have variable sizes,
1082 : : including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
1083 : : size_t
1084 : 16162764117 : tree_code_size (enum tree_code code)
1085 : : {
1086 : 16162764117 : switch (TREE_CODE_CLASS (code))
1087 : : {
1088 : 3983842666 : case tcc_declaration: /* A decl node */
1089 : 3983842666 : switch (code)
1090 : : {
1091 : : case FIELD_DECL: return sizeof (tree_field_decl);
1092 : : case PARM_DECL: return sizeof (tree_parm_decl);
1093 : 224312257 : case VAR_DECL: return sizeof (tree_var_decl);
1094 : : case LABEL_DECL: return sizeof (tree_label_decl);
1095 : : case RESULT_DECL: return sizeof (tree_result_decl);
1096 : 32171199 : case CONST_DECL: return sizeof (tree_const_decl);
1097 : : case TYPE_DECL: return sizeof (tree_type_decl);
1098 : 1347674522 : case FUNCTION_DECL: return sizeof (tree_function_decl);
1099 : : case DEBUG_EXPR_DECL: return sizeof (tree_decl_with_rtl);
1100 : : case TRANSLATION_UNIT_DECL: return sizeof (tree_translation_unit_decl);
1101 : : case NAMESPACE_DECL:
1102 : : case IMPORTED_DECL:
1103 : : case NAMELIST_DECL: return sizeof (tree_decl_non_common);
1104 : 242130588 : default:
1105 : 242130588 : gcc_checking_assert (code >= NUM_TREE_CODES);
1106 : 242130588 : return lang_hooks.tree_size (code);
1107 : : }
1108 : :
1109 : 2758577816 : case tcc_type: /* a type node */
1110 : 2758577816 : switch (code)
1111 : : {
1112 : : case OFFSET_TYPE:
1113 : : case ENUMERAL_TYPE:
1114 : : case BOOLEAN_TYPE:
1115 : : case INTEGER_TYPE:
1116 : : case REAL_TYPE:
1117 : : case OPAQUE_TYPE:
1118 : : case POINTER_TYPE:
1119 : : case REFERENCE_TYPE:
1120 : : case NULLPTR_TYPE:
1121 : : case FIXED_POINT_TYPE:
1122 : : case COMPLEX_TYPE:
1123 : : case VECTOR_TYPE:
1124 : : case ARRAY_TYPE:
1125 : : case RECORD_TYPE:
1126 : : case UNION_TYPE:
1127 : : case QUAL_UNION_TYPE:
1128 : : case VOID_TYPE:
1129 : : case FUNCTION_TYPE:
1130 : : case METHOD_TYPE:
1131 : : case BITINT_TYPE:
1132 : : case LANG_TYPE: return sizeof (tree_type_non_common);
1133 : 650947049 : default:
1134 : 650947049 : gcc_checking_assert (code >= NUM_TREE_CODES);
1135 : 650947049 : return lang_hooks.tree_size (code);
1136 : : }
1137 : :
1138 : 4176732914 : case tcc_reference: /* a reference */
1139 : 4176732914 : case tcc_expression: /* an expression */
1140 : 4176732914 : case tcc_statement: /* an expression with side effects */
1141 : 4176732914 : case tcc_comparison: /* a comparison expression */
1142 : 4176732914 : case tcc_unary: /* a unary arithmetic expression */
1143 : 4176732914 : case tcc_binary: /* a binary arithmetic expression */
1144 : 4176732914 : return (sizeof (struct tree_exp)
1145 : 4176732914 : + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
1146 : :
1147 : 43733775 : case tcc_constant: /* a constant */
1148 : 43733775 : switch (code)
1149 : : {
1150 : : case VOID_CST: return sizeof (tree_typed);
1151 : 0 : case INTEGER_CST: gcc_unreachable ();
1152 : : case POLY_INT_CST: return sizeof (tree_poly_int_cst);
1153 : 42888280 : case REAL_CST: return sizeof (tree_real_cst);
1154 : : case FIXED_CST: return sizeof (tree_fixed_cst);
1155 : : case COMPLEX_CST: return sizeof (tree_complex);
1156 : : case RAW_DATA_CST: return sizeof (tree_raw_data);
1157 : 0 : case VECTOR_CST: gcc_unreachable ();
1158 : 0 : case STRING_CST: gcc_unreachable ();
1159 : 66922 : default:
1160 : 66922 : gcc_checking_assert (code >= NUM_TREE_CODES);
1161 : 66922 : return lang_hooks.tree_size (code);
1162 : : }
1163 : :
1164 : 5199876946 : case tcc_exceptional: /* something random, like an identifier. */
1165 : 5199876946 : switch (code)
1166 : : {
1167 : 1633324037 : case IDENTIFIER_NODE: return lang_hooks.identifier_size;
1168 : : case TREE_LIST: return sizeof (tree_list);
1169 : :
1170 : : case ERROR_MARK:
1171 : : case PLACEHOLDER_EXPR: return sizeof (tree_common);
1172 : :
1173 : 0 : case TREE_VEC: gcc_unreachable ();
1174 : 0 : case OMP_CLAUSE: gcc_unreachable ();
1175 : :
1176 : : case SSA_NAME: return sizeof (tree_ssa_name);
1177 : :
1178 : : case STATEMENT_LIST: return sizeof (tree_statement_list);
1179 : 274340924 : case BLOCK: return sizeof (struct tree_block);
1180 : : case CONSTRUCTOR: return sizeof (tree_constructor);
1181 : : case OPTIMIZATION_NODE: return sizeof (tree_optimization_option);
1182 : : case TARGET_OPTION_NODE: return sizeof (tree_target_option);
1183 : :
1184 : 1361993042 : default:
1185 : 1361993042 : gcc_checking_assert (code >= NUM_TREE_CODES);
1186 : 1361993042 : return lang_hooks.tree_size (code);
1187 : : }
1188 : :
1189 : 0 : default:
1190 : 0 : gcc_unreachable ();
1191 : : }
1192 : : }
1193 : :
1194 : : /* Compute the number of bytes occupied by NODE. This routine only
1195 : : looks at TREE_CODE, except for those nodes that have variable sizes. */
1196 : : size_t
1197 : 3671943342 : tree_size (const_tree node)
1198 : : {
1199 : 3671943342 : const enum tree_code code = TREE_CODE (node);
1200 : 3671943342 : switch (code)
1201 : : {
1202 : 11355200 : case INTEGER_CST:
1203 : 11355200 : return (sizeof (struct tree_int_cst)
1204 : 11355200 : + (TREE_INT_CST_EXT_NUNITS (node) - 1) * sizeof (HOST_WIDE_INT));
1205 : :
1206 : 0 : case TREE_BINFO:
1207 : 0 : return (offsetof (struct tree_binfo, base_binfos)
1208 : : + vec<tree, va_gc>
1209 : 0 : ::embedded_size (BINFO_N_BASE_BINFOS (node)));
1210 : :
1211 : 365283085 : case TREE_VEC:
1212 : 365283085 : return (sizeof (struct tree_vec)
1213 : 365283085 : + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
1214 : :
1215 : 0 : case VECTOR_CST:
1216 : 0 : return (sizeof (struct tree_vector)
1217 : 0 : + (vector_cst_encoded_nelts (node) - 1) * sizeof (tree));
1218 : :
1219 : 22437 : case STRING_CST:
1220 : 22437 : return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
1221 : :
1222 : 32735 : case OMP_CLAUSE:
1223 : 32735 : return (sizeof (struct tree_omp_clause)
1224 : 32735 : + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
1225 : 32735 : * sizeof (tree));
1226 : :
1227 : 3295249885 : default:
1228 : 3295249885 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
1229 : 147072551 : return (sizeof (struct tree_exp)
1230 : 147072551 : + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
1231 : : else
1232 : 3148177334 : return tree_code_size (code);
1233 : : }
1234 : : }
1235 : :
1236 : : /* Return tree node kind based on tree CODE. */
1237 : :
1238 : : static tree_node_kind
1239 : 0 : get_stats_node_kind (enum tree_code code)
1240 : : {
1241 : 0 : enum tree_code_class type = TREE_CODE_CLASS (code);
1242 : :
1243 : 0 : switch (type)
1244 : : {
1245 : : case tcc_declaration: /* A decl node */
1246 : : return d_kind;
1247 : 0 : case tcc_type: /* a type node */
1248 : 0 : return t_kind;
1249 : 0 : case tcc_statement: /* an expression with side effects */
1250 : 0 : return s_kind;
1251 : 0 : case tcc_reference: /* a reference */
1252 : 0 : return r_kind;
1253 : : case tcc_expression: /* an expression */
1254 : : case tcc_comparison: /* a comparison expression */
1255 : : case tcc_unary: /* a unary arithmetic expression */
1256 : : case tcc_binary: /* a binary arithmetic expression */
1257 : : return e_kind;
1258 : 0 : case tcc_constant: /* a constant */
1259 : 0 : return c_kind;
1260 : 0 : case tcc_exceptional: /* something random, like an identifier. */
1261 : 0 : switch (code)
1262 : : {
1263 : : case IDENTIFIER_NODE:
1264 : : return id_kind;
1265 : 0 : case TREE_VEC:
1266 : 0 : return vec_kind;
1267 : 0 : case TREE_BINFO:
1268 : 0 : return binfo_kind;
1269 : 0 : case SSA_NAME:
1270 : 0 : return ssa_name_kind;
1271 : 0 : case BLOCK:
1272 : 0 : return b_kind;
1273 : 0 : case CONSTRUCTOR:
1274 : 0 : return constr_kind;
1275 : 0 : case OMP_CLAUSE:
1276 : 0 : return omp_clause_kind;
1277 : 0 : default:
1278 : 0 : return x_kind;
1279 : : }
1280 : : break;
1281 : : case tcc_vl_exp:
1282 : : return e_kind;
1283 : 0 : default:
1284 : 0 : gcc_unreachable ();
1285 : : }
1286 : : }
1287 : :
1288 : : /* Record interesting allocation statistics for a tree node with CODE
1289 : : and LENGTH. */
1290 : :
1291 : : static void
1292 : 0 : record_node_allocation_statistics (enum tree_code code, size_t length)
1293 : : {
1294 : 0 : if (!GATHER_STATISTICS)
1295 : 0 : return;
1296 : :
1297 : : tree_node_kind kind = get_stats_node_kind (code);
1298 : :
1299 : : tree_code_counts[(int) code]++;
1300 : : tree_node_counts[(int) kind]++;
1301 : : tree_node_sizes[(int) kind] += length;
1302 : : }
1303 : :
1304 : : /* Allocate and return a new UID from the DECL_UID namespace. */
1305 : :
1306 : : int
1307 : 3977491012 : allocate_decl_uid (void)
1308 : : {
1309 : 3977491012 : return next_decl_uid++;
1310 : : }
1311 : :
1312 : : /* Return a newly allocated node of code CODE. For decl and type
1313 : : nodes, some other fields are initialized. The rest of the node is
1314 : : initialized to zero. This function cannot be used for TREE_VEC,
1315 : : INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
1316 : : tree_code_size.
1317 : :
1318 : : Achoo! I got a code in the node. */
1319 : :
1320 : : tree
1321 : 13009252994 : make_node (enum tree_code code MEM_STAT_DECL)
1322 : : {
1323 : 13009252994 : tree t;
1324 : 13009252994 : enum tree_code_class type = TREE_CODE_CLASS (code);
1325 : 13009252994 : size_t length = tree_code_size (code);
1326 : :
1327 : 13009252994 : record_node_allocation_statistics (code, length);
1328 : :
1329 : 13009252994 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1330 : 13009252994 : TREE_SET_CODE (t, code);
1331 : :
1332 : 13009252994 : switch (type)
1333 : : {
1334 : 646229521 : case tcc_statement:
1335 : 646229521 : if (code != DEBUG_BEGIN_STMT)
1336 : 336781226 : TREE_SIDE_EFFECTS (t) = 1;
1337 : : break;
1338 : :
1339 : 2927414380 : case tcc_declaration:
1340 : 2927414380 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1341 : : {
1342 : 2927414380 : if (code == FUNCTION_DECL)
1343 : : {
1344 : 1078694122 : SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
1345 : 1078694122 : SET_DECL_MODE (t, FUNCTION_MODE);
1346 : : }
1347 : : else
1348 : 1848720258 : SET_DECL_ALIGN (t, 1);
1349 : : }
1350 : 2927414380 : DECL_SOURCE_LOCATION (t) = input_location;
1351 : 2927414380 : if (TREE_CODE (t) == DEBUG_EXPR_DECL)
1352 : 2002646 : DECL_UID (t) = --next_debug_decl_uid;
1353 : : else
1354 : : {
1355 : 2925411734 : DECL_UID (t) = allocate_decl_uid ();
1356 : 2925411734 : SET_DECL_PT_UID (t, -1);
1357 : : }
1358 : 2927414380 : if (TREE_CODE (t) == LABEL_DECL)
1359 : 33745439 : LABEL_DECL_UID (t) = -1;
1360 : :
1361 : : break;
1362 : :
1363 : 2051982843 : case tcc_type:
1364 : 2051982843 : TYPE_UID (t) = next_type_uid++;
1365 : 2051982843 : SET_TYPE_ALIGN (t, BITS_PER_UNIT);
1366 : 2051982843 : TYPE_USER_ALIGN (t) = 0;
1367 : 2051982843 : TYPE_MAIN_VARIANT (t) = t;
1368 : 2051982843 : TYPE_CANONICAL (t) = t;
1369 : :
1370 : : /* Default to no attributes for type, but let target change that. */
1371 : 2051982843 : TYPE_ATTRIBUTES (t) = NULL_TREE;
1372 : 2051982843 : targetm.set_default_type_attributes (t);
1373 : :
1374 : : /* We have not yet computed the alias set for this type. */
1375 : 2051982843 : TYPE_ALIAS_SET (t) = -1;
1376 : 2051982843 : break;
1377 : :
1378 : 43732510 : case tcc_constant:
1379 : 43732510 : TREE_CONSTANT (t) = 1;
1380 : 43732510 : break;
1381 : :
1382 : 1101672432 : case tcc_expression:
1383 : 1101672432 : switch (code)
1384 : : {
1385 : 258554773 : case INIT_EXPR:
1386 : 258554773 : case MODIFY_EXPR:
1387 : 258554773 : case VA_ARG_EXPR:
1388 : 258554773 : case PREDECREMENT_EXPR:
1389 : 258554773 : case PREINCREMENT_EXPR:
1390 : 258554773 : case POSTDECREMENT_EXPR:
1391 : 258554773 : case POSTINCREMENT_EXPR:
1392 : : /* All of these have side-effects, no matter what their
1393 : : operands are. */
1394 : 258554773 : TREE_SIDE_EFFECTS (t) = 1;
1395 : 258554773 : break;
1396 : :
1397 : : default:
1398 : : break;
1399 : : }
1400 : : break;
1401 : :
1402 : 4994949183 : case tcc_exceptional:
1403 : 4994949183 : switch (code)
1404 : : {
1405 : 1086593 : case TARGET_OPTION_NODE:
1406 : 2173186 : TREE_TARGET_OPTION(t)
1407 : 1086593 : = ggc_cleared_alloc<struct cl_target_option> ();
1408 : 1086593 : break;
1409 : :
1410 : 595435 : case OPTIMIZATION_NODE:
1411 : 1190870 : TREE_OPTIMIZATION (t)
1412 : 595435 : = ggc_cleared_alloc<struct cl_optimization> ();
1413 : 595435 : break;
1414 : :
1415 : : default:
1416 : : break;
1417 : : }
1418 : : break;
1419 : :
1420 : : default:
1421 : : /* Other classes need no special treatment. */
1422 : : break;
1423 : : }
1424 : :
1425 : 13009252994 : return t;
1426 : : }
1427 : :
1428 : : /* Free tree node. */
1429 : :
1430 : : void
1431 : 626317479 : free_node (tree node)
1432 : : {
1433 : 626317479 : enum tree_code code = TREE_CODE (node);
1434 : 626317479 : if (GATHER_STATISTICS)
1435 : : {
1436 : : enum tree_node_kind kind = get_stats_node_kind (code);
1437 : :
1438 : : gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
1439 : : gcc_checking_assert (tree_node_counts[(int) kind] != 0);
1440 : : gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
1441 : :
1442 : : tree_code_counts[(int) TREE_CODE (node)]--;
1443 : : tree_node_counts[(int) kind]--;
1444 : : tree_node_sizes[(int) kind] -= tree_size (node);
1445 : : }
1446 : 626317479 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1447 : 349 : vec_free (CONSTRUCTOR_ELTS (node));
1448 : 626317286 : else if (code == BLOCK)
1449 : 0 : vec_free (BLOCK_NONLOCALIZED_VARS (node));
1450 : 626317286 : else if (code == TREE_BINFO)
1451 : 363 : vec_free (BINFO_BASE_ACCESSES (node));
1452 : 626316923 : else if (code == OPTIMIZATION_NODE)
1453 : 813 : cl_optimization_option_free (TREE_OPTIMIZATION (node));
1454 : 626316110 : else if (code == TARGET_OPTION_NODE)
1455 : 878 : cl_target_option_free (TREE_TARGET_OPTION (node));
1456 : 626317479 : ggc_free (node);
1457 : 626317479 : }
1458 : :
1459 : : /* Return a new node with the same contents as NODE except that its
1460 : : TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1461 : :
1462 : : tree
1463 : 3588953550 : copy_node (tree node MEM_STAT_DECL)
1464 : : {
1465 : 3588953550 : tree t;
1466 : 3588953550 : enum tree_code code = TREE_CODE (node);
1467 : 3588953550 : size_t length;
1468 : :
1469 : 3588953550 : gcc_assert (code != STATEMENT_LIST);
1470 : :
1471 : 3588953550 : length = tree_size (node);
1472 : 3588953550 : record_node_allocation_statistics (code, length);
1473 : 3588953550 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
1474 : 3588953550 : memcpy (t, node, length);
1475 : :
1476 : 3588953550 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
1477 : 2176645278 : TREE_CHAIN (t) = 0;
1478 : 3588953550 : TREE_ASM_WRITTEN (t) = 0;
1479 : 3588953550 : TREE_VISITED (t) = 0;
1480 : :
1481 : 3588953550 : if (TREE_CODE_CLASS (code) == tcc_declaration)
1482 : : {
1483 : 1051094497 : if (code == DEBUG_EXPR_DECL)
1484 : 0 : DECL_UID (t) = --next_debug_decl_uid;
1485 : : else
1486 : : {
1487 : 1051094497 : DECL_UID (t) = allocate_decl_uid ();
1488 : 1051094497 : if (DECL_PT_UID_SET_P (node))
1489 : 3482 : SET_DECL_PT_UID (t, DECL_PT_UID (node));
1490 : : }
1491 : 518060569 : if ((TREE_CODE (node) == PARM_DECL || VAR_P (node))
1492 : 1113248831 : && DECL_HAS_VALUE_EXPR_P (node))
1493 : : {
1494 : 907270 : SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
1495 : 907270 : DECL_HAS_VALUE_EXPR_P (t) = 1;
1496 : : }
1497 : : /* DECL_DEBUG_EXPR is copied explicitly by callers. */
1498 : 1051094497 : if (VAR_P (node))
1499 : : {
1500 : 62154334 : DECL_HAS_DEBUG_EXPR_P (t) = 0;
1501 : 62154334 : t->decl_with_vis.symtab_node = NULL;
1502 : : }
1503 : 1051094497 : if (VAR_P (node) && DECL_HAS_INIT_PRIORITY_P (node))
1504 : : {
1505 : 0 : SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
1506 : 0 : DECL_HAS_INIT_PRIORITY_P (t) = 1;
1507 : : }
1508 : 1051094497 : if (TREE_CODE (node) == FUNCTION_DECL)
1509 : : {
1510 : 264136585 : DECL_STRUCT_FUNCTION (t) = NULL;
1511 : 264136585 : t->decl_with_vis.symtab_node = NULL;
1512 : : }
1513 : : }
1514 : 2537859053 : else if (TREE_CODE_CLASS (code) == tcc_type)
1515 : : {
1516 : 706594973 : TYPE_UID (t) = next_type_uid++;
1517 : : /* The following is so that the debug code for
1518 : : the copy is different from the original type.
1519 : : The two statements usually duplicate each other
1520 : : (because they clear fields of the same union),
1521 : : but the optimizer should catch that. */
1522 : 706594973 : TYPE_SYMTAB_ADDRESS (t) = 0;
1523 : 706594973 : TYPE_SYMTAB_DIE (t) = 0;
1524 : :
1525 : : /* Do not copy the values cache. */
1526 : 706594973 : if (TYPE_CACHED_VALUES_P (t))
1527 : : {
1528 : 17765147 : TYPE_CACHED_VALUES_P (t) = 0;
1529 : 17765147 : TYPE_CACHED_VALUES (t) = NULL_TREE;
1530 : : }
1531 : : }
1532 : 1831264080 : else if (code == TARGET_OPTION_NODE)
1533 : : {
1534 : 0 : TREE_TARGET_OPTION (t) = ggc_alloc<struct cl_target_option>();
1535 : 0 : memcpy (TREE_TARGET_OPTION (t), TREE_TARGET_OPTION (node),
1536 : : sizeof (struct cl_target_option));
1537 : : }
1538 : 1831264080 : else if (code == OPTIMIZATION_NODE)
1539 : : {
1540 : 0 : TREE_OPTIMIZATION (t) = ggc_alloc<struct cl_optimization>();
1541 : 0 : memcpy (TREE_OPTIMIZATION (t), TREE_OPTIMIZATION (node),
1542 : : sizeof (struct cl_optimization));
1543 : : }
1544 : :
1545 : 3588953550 : return t;
1546 : : }
1547 : :
1548 : : /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1549 : : For example, this can copy a list made of TREE_LIST nodes. */
1550 : :
1551 : : tree
1552 : 138860375 : copy_list (tree list)
1553 : : {
1554 : 138860375 : tree head;
1555 : 138860375 : tree prev, next;
1556 : :
1557 : 138860375 : if (list == 0)
1558 : : return 0;
1559 : :
1560 : 133811776 : head = prev = copy_node (list);
1561 : 133811776 : next = TREE_CHAIN (list);
1562 : 265208071 : while (next)
1563 : : {
1564 : 131396295 : TREE_CHAIN (prev) = copy_node (next);
1565 : 131396295 : prev = TREE_CHAIN (prev);
1566 : 131396295 : next = TREE_CHAIN (next);
1567 : : }
1568 : : return head;
1569 : : }
1570 : :
1571 : :
1572 : : /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1573 : : INTEGER_CST with value CST and type TYPE. */
1574 : :
1575 : : static unsigned int
1576 : 9181997599 : get_int_cst_ext_nunits (tree type, const wide_int &cst)
1577 : : {
1578 : 9181997599 : gcc_checking_assert (cst.get_precision () == TYPE_PRECISION (type));
1579 : : /* We need extra HWIs if CST is an unsigned integer with its
1580 : : upper bit set. */
1581 : 9181997599 : if (TYPE_UNSIGNED (type) && wi::neg_p (cst))
1582 : 168918338 : return cst.get_precision () / HOST_BITS_PER_WIDE_INT + 1;
1583 : 9013079261 : return cst.get_len ();
1584 : : }
1585 : :
1586 : : /* Return a new INTEGER_CST with value CST and type TYPE. */
1587 : :
1588 : : static tree
1589 : 124430076 : build_new_int_cst (tree type, const wide_int &cst)
1590 : : {
1591 : 124430076 : unsigned int len = cst.get_len ();
1592 : 124430076 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1593 : 124430076 : tree nt = make_int_cst (len, ext_len);
1594 : :
1595 : 124430076 : if (len < ext_len)
1596 : : {
1597 : 61645877 : --ext_len;
1598 : 123291754 : TREE_INT_CST_ELT (nt, ext_len)
1599 : 61645877 : = zext_hwi (-1, cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1600 : 80775630 : for (unsigned int i = len; i < ext_len; ++i)
1601 : 19129753 : TREE_INT_CST_ELT (nt, i) = -1;
1602 : : }
1603 : 62784199 : else if (TYPE_UNSIGNED (type)
1604 : 62784199 : && cst.get_precision () < len * HOST_BITS_PER_WIDE_INT)
1605 : : {
1606 : 12962290 : len--;
1607 : 25924580 : TREE_INT_CST_ELT (nt, len)
1608 : 12962290 : = zext_hwi (cst.elt (len),
1609 : 12962290 : cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1610 : : }
1611 : :
1612 : 257667050 : for (unsigned int i = 0; i < len; i++)
1613 : 133236974 : TREE_INT_CST_ELT (nt, i) = cst.elt (i);
1614 : 124430076 : TREE_TYPE (nt) = type;
1615 : 124430076 : return nt;
1616 : : }
1617 : :
1618 : : /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE. */
1619 : :
1620 : : static tree
1621 : 0 : build_new_poly_int_cst (tree type, tree (&coeffs)[NUM_POLY_INT_COEFFS]
1622 : : CXX_MEM_STAT_INFO)
1623 : : {
1624 : 0 : size_t length = sizeof (struct tree_poly_int_cst);
1625 : 0 : record_node_allocation_statistics (POLY_INT_CST, length);
1626 : :
1627 : 0 : tree t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1628 : :
1629 : 0 : TREE_SET_CODE (t, POLY_INT_CST);
1630 : 0 : TREE_CONSTANT (t) = 1;
1631 : 0 : TREE_TYPE (t) = type;
1632 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1633 : 0 : POLY_INT_CST_COEFF (t, i) = coeffs[i];
1634 : 0 : return t;
1635 : : }
1636 : :
1637 : : /* Create a constant tree that contains CST sign-extended to TYPE. */
1638 : :
1639 : : tree
1640 : 6126194495 : build_int_cst (tree type, poly_int64 cst)
1641 : : {
1642 : : /* Support legacy code. */
1643 : 6126194495 : if (!type)
1644 : 2002491817 : type = integer_type_node;
1645 : :
1646 : 6126194495 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1647 : : }
1648 : :
1649 : : /* Create a constant tree that contains CST zero-extended to TYPE. */
1650 : :
1651 : : tree
1652 : 9387160 : build_int_cstu (tree type, poly_uint64 cst)
1653 : : {
1654 : 9387160 : return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type)));
1655 : : }
1656 : :
1657 : : /* Create a constant tree that contains CST sign-extended to TYPE. */
1658 : :
1659 : : tree
1660 : 25250473 : build_int_cst_type (tree type, poly_int64 cst)
1661 : : {
1662 : 25250473 : gcc_assert (type);
1663 : 25250473 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1664 : : }
1665 : :
1666 : : /* Constructs tree in type TYPE from with value given by CST. Signedness
1667 : : of CST is assumed to be the same as the signedness of TYPE. */
1668 : :
1669 : : tree
1670 : 7287762 : double_int_to_tree (tree type, double_int cst)
1671 : : {
1672 : 7287762 : return wide_int_to_tree (type, widest_int::from (cst, TYPE_SIGN (type)));
1673 : : }
1674 : :
1675 : : /* We force the wide_int CST to the range of the type TYPE by sign or
1676 : : zero extending it. OVERFLOWABLE indicates if we are interested in
1677 : : overflow of the value, when >0 we are only interested in signed
1678 : : overflow, for <0 we are interested in any overflow. OVERFLOWED
1679 : : indicates whether overflow has already occurred. CONST_OVERFLOWED
1680 : : indicates whether constant overflow has already occurred. We force
1681 : : T's value to be within range of T's type (by setting to 0 or 1 all
1682 : : the bits outside the type's range). We set TREE_OVERFLOWED if,
1683 : : OVERFLOWED is nonzero,
1684 : : or OVERFLOWABLE is >0 and signed overflow occurs
1685 : : or OVERFLOWABLE is <0 and any overflow occurs
1686 : : We return a new tree node for the extended wide_int. The node
1687 : : is shared if no overflow flags are set. */
1688 : :
1689 : :
1690 : : tree
1691 : 2372754448 : force_fit_type (tree type, const poly_wide_int_ref &cst,
1692 : : int overflowable, bool overflowed)
1693 : : {
1694 : 2372754448 : signop sign = TYPE_SIGN (type);
1695 : :
1696 : : /* If we need to set overflow flags, return a new unshared node. */
1697 : 2372754448 : if (overflowed || !wi::fits_to_tree_p (cst, type))
1698 : : {
1699 : 6616787 : if (overflowed
1700 : 6616787 : || overflowable < 0
1701 : 5380680 : || (overflowable > 0 && sign == SIGNED))
1702 : : {
1703 : 1283885 : poly_wide_int tmp = poly_wide_int::from (cst, TYPE_PRECISION (type),
1704 : 1283885 : sign);
1705 : 1283885 : tree t;
1706 : 1283885 : if (tmp.is_constant ())
1707 : 1283885 : t = build_new_int_cst (type, tmp.coeffs[0]);
1708 : : else
1709 : : {
1710 : : tree coeffs[NUM_POLY_INT_COEFFS];
1711 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1712 : : {
1713 : : coeffs[i] = build_new_int_cst (type, tmp.coeffs[i]);
1714 : : TREE_OVERFLOW (coeffs[i]) = 1;
1715 : : }
1716 : : t = build_new_poly_int_cst (type, coeffs);
1717 : : }
1718 : 1283885 : TREE_OVERFLOW (t) = 1;
1719 : 1283885 : return t;
1720 : 1283885 : }
1721 : : }
1722 : :
1723 : : /* Else build a shared node. */
1724 : 2371470563 : return wide_int_to_tree (type, cst);
1725 : : }
1726 : :
1727 : : /* These are the hash table functions for the hash table of INTEGER_CST
1728 : : nodes of a sizetype. */
1729 : :
1730 : : /* Return the hash code X, an INTEGER_CST. */
1731 : :
1732 : : hashval_t
1733 : 1625343024 : int_cst_hasher::hash (tree x)
1734 : : {
1735 : 1625343024 : const_tree const t = x;
1736 : 1625343024 : hashval_t code = TYPE_UID (TREE_TYPE (t));
1737 : 1625343024 : int i;
1738 : :
1739 : 3309506851 : for (i = 0; i < TREE_INT_CST_NUNITS (t); i++)
1740 : 1684163827 : code = iterative_hash_host_wide_int (TREE_INT_CST_ELT(t, i), code);
1741 : :
1742 : 1625343024 : return code;
1743 : : }
1744 : :
1745 : : /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1746 : : is the same as that given by *Y, which is the same. */
1747 : :
1748 : : bool
1749 : 1630123259 : int_cst_hasher::equal (tree x, tree y)
1750 : : {
1751 : 1630123259 : const_tree const xt = x;
1752 : 1630123259 : const_tree const yt = y;
1753 : :
1754 : 1630123259 : if (TREE_TYPE (xt) != TREE_TYPE (yt)
1755 : 590170278 : || TREE_INT_CST_NUNITS (xt) != TREE_INT_CST_NUNITS (yt)
1756 : 2220240009 : || TREE_INT_CST_EXT_NUNITS (xt) != TREE_INT_CST_EXT_NUNITS (yt))
1757 : : return false;
1758 : :
1759 : 875055782 : for (int i = 0; i < TREE_INT_CST_NUNITS (xt); i++)
1760 : 561505135 : if (TREE_INT_CST_ELT (xt, i) != TREE_INT_CST_ELT (yt, i))
1761 : : return false;
1762 : :
1763 : : return true;
1764 : : }
1765 : :
1766 : : /* Cache wide_int CST into the TYPE_CACHED_VALUES cache for TYPE.
1767 : : SLOT is the slot entry to store it in, and MAX_SLOTS is the maximum
1768 : : number of slots that can be cached for the type. */
1769 : :
1770 : : static inline tree
1771 : 8670433115 : cache_wide_int_in_type_cache (tree type, const wide_int &cst,
1772 : : int slot, int max_slots)
1773 : : {
1774 : 8670433115 : gcc_checking_assert (slot >= 0);
1775 : : /* Initialize cache. */
1776 : 8670433115 : if (!TYPE_CACHED_VALUES_P (type))
1777 : : {
1778 : 17803885 : TYPE_CACHED_VALUES_P (type) = 1;
1779 : 17803885 : TYPE_CACHED_VALUES (type) = make_tree_vec (max_slots);
1780 : : }
1781 : 8670433115 : tree t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot);
1782 : 8670433115 : if (!t)
1783 : : {
1784 : : /* Create a new shared int. */
1785 : 56413750 : t = build_new_int_cst (type, cst);
1786 : 56413750 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot) = t;
1787 : : }
1788 : 8670433115 : return t;
1789 : : }
1790 : :
1791 : : /* Create an INT_CST node of TYPE and value CST.
1792 : : The returned node is always shared. For small integers we use a
1793 : : per-type vector cache, for larger ones we use a single hash table.
1794 : : The value is extended from its precision according to the sign of
1795 : : the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1796 : : the upper bits and ensures that hashing and value equality based
1797 : : upon the underlying HOST_WIDE_INTs works without masking. */
1798 : :
1799 : : static tree
1800 : 9057567523 : wide_int_to_tree_1 (tree type, const wide_int_ref &pcst)
1801 : : {
1802 : 9057567523 : tree t;
1803 : 9057567523 : int ix = -1;
1804 : 9057567523 : int limit = 0;
1805 : :
1806 : 9057567523 : gcc_assert (type);
1807 : 9057567523 : unsigned int prec = TYPE_PRECISION (type);
1808 : 9057567523 : signop sgn = TYPE_SIGN (type);
1809 : :
1810 : : /* Verify that everything is canonical. */
1811 : 9057567523 : int l = pcst.get_len ();
1812 : 9057567523 : if (l > 1)
1813 : : {
1814 : 6748502 : if (pcst.elt (l - 1) == 0)
1815 : 1092982 : gcc_checking_assert (pcst.elt (l - 2) < 0);
1816 : 6748502 : if (pcst.elt (l - 1) == HOST_WIDE_INT_M1)
1817 : 11781 : gcc_checking_assert (pcst.elt (l - 2) >= 0);
1818 : : }
1819 : :
1820 : 9057567523 : wide_int cst = wide_int::from (pcst, prec, sgn);
1821 : 9057567523 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1822 : :
1823 : 9057567523 : enum tree_code code = TREE_CODE (type);
1824 : 9057567523 : if (code == POINTER_TYPE || code == REFERENCE_TYPE)
1825 : : {
1826 : : /* Cache NULL pointer and zero bounds. */
1827 : 170286835 : if (cst == 0)
1828 : : ix = 0;
1829 : : /* Cache upper bounds of pointers. */
1830 : 33416978 : else if (cst == wi::max_value (prec, sgn))
1831 : : ix = 1;
1832 : : /* Cache 1 which is used for a non-zero range. */
1833 : 31330014 : else if (cst == 1)
1834 : : ix = 2;
1835 : :
1836 : : if (ix >= 0)
1837 : : {
1838 : 142980986 : t = cache_wide_int_in_type_cache (type, cst, ix, 3);
1839 : : /* Make sure no one is clobbering the shared constant. */
1840 : 142980986 : gcc_checking_assert (TREE_TYPE (t) == type
1841 : : && cst == wi::to_wide (t));
1842 : 142980986 : return t;
1843 : : }
1844 : : }
1845 : 8914586537 : if (ext_len == 1)
1846 : : {
1847 : : /* We just need to store a single HOST_WIDE_INT. */
1848 : 8847854096 : HOST_WIDE_INT hwi;
1849 : 8847854096 : if (TYPE_UNSIGNED (type))
1850 : 6014872868 : hwi = cst.to_uhwi ();
1851 : : else
1852 : 2832981606 : hwi = cst.to_shwi ();
1853 : :
1854 : 8847854096 : switch (code)
1855 : : {
1856 : 206832 : case NULLPTR_TYPE:
1857 : 206832 : gcc_assert (hwi == 0);
1858 : : /* Fallthru. */
1859 : :
1860 : : case POINTER_TYPE:
1861 : : case REFERENCE_TYPE:
1862 : : /* Ignore pointers, as they were already handled above. */
1863 : : break;
1864 : :
1865 : 110490699 : case BOOLEAN_TYPE:
1866 : : /* Cache false or true. */
1867 : 110490699 : limit = 2;
1868 : 110490699 : if (IN_RANGE (hwi, 0, 1))
1869 : 110331610 : ix = hwi;
1870 : : break;
1871 : :
1872 : 8705979336 : case INTEGER_TYPE:
1873 : 8705979336 : case OFFSET_TYPE:
1874 : 8705979336 : case BITINT_TYPE:
1875 : 8705979336 : if (TYPE_SIGN (type) == UNSIGNED)
1876 : : {
1877 : : /* Cache [0, N). */
1878 : 5876359475 : limit = param_integer_share_limit;
1879 : 5876359475 : if (IN_RANGE (hwi, 0, param_integer_share_limit - 1))
1880 : 5693072762 : ix = hwi;
1881 : : }
1882 : : else
1883 : : {
1884 : : /* Cache [-1, N). */
1885 : 2829619861 : limit = param_integer_share_limit + 1;
1886 : 2829619861 : if (IN_RANGE (hwi, -1, param_integer_share_limit - 1))
1887 : 2724047757 : ix = hwi + 1;
1888 : : }
1889 : : break;
1890 : :
1891 : : case ENUMERAL_TYPE:
1892 : : break;
1893 : :
1894 : 0 : default:
1895 : 0 : gcc_unreachable ();
1896 : : }
1897 : :
1898 : 8847854096 : if (ix >= 0)
1899 : : {
1900 : 8527452129 : t = cache_wide_int_in_type_cache (type, cst, ix, limit);
1901 : : /* Make sure no one is clobbering the shared constant. */
1902 : 17054904258 : gcc_checking_assert (TREE_TYPE (t) == type
1903 : : && TREE_INT_CST_NUNITS (t) == 1
1904 : : && TREE_INT_CST_EXT_NUNITS (t) == 1
1905 : : && TREE_INT_CST_ELT (t, 0) == hwi);
1906 : : return t;
1907 : : }
1908 : : else
1909 : : {
1910 : : /* Use the cache of larger shared ints, using int_cst_node as
1911 : : a temporary. */
1912 : :
1913 : 320401967 : TREE_INT_CST_ELT (int_cst_node, 0) = hwi;
1914 : 320401967 : TREE_TYPE (int_cst_node) = type;
1915 : :
1916 : 320401967 : tree *slot = int_cst_hash_table->find_slot (int_cst_node, INSERT);
1917 : 320401967 : t = *slot;
1918 : 320401967 : if (!t)
1919 : : {
1920 : : /* Insert this one into the hash table. */
1921 : 63475921 : t = int_cst_node;
1922 : 63475921 : *slot = t;
1923 : : /* Make a new node for next time round. */
1924 : 63475921 : int_cst_node = make_int_cst (1, 1);
1925 : : }
1926 : : }
1927 : : }
1928 : : else
1929 : : {
1930 : : /* The value either hashes properly or we drop it on the floor
1931 : : for the gc to take care of. There will not be enough of them
1932 : : to worry about. */
1933 : :
1934 : 66732441 : tree nt = build_new_int_cst (type, cst);
1935 : 66732441 : tree *slot = int_cst_hash_table->find_slot (nt, INSERT);
1936 : 66732441 : t = *slot;
1937 : 66732441 : if (!t)
1938 : : {
1939 : : /* Insert this one into the hash table. */
1940 : 13747317 : t = nt;
1941 : 13747317 : *slot = t;
1942 : : }
1943 : : else
1944 : 52985124 : ggc_free (nt);
1945 : : }
1946 : :
1947 : : return t;
1948 : 9057567523 : }
1949 : :
1950 : : hashval_t
1951 : 0 : poly_int_cst_hasher::hash (tree t)
1952 : : {
1953 : 0 : inchash::hash hstate;
1954 : :
1955 : 0 : hstate.add_int (TYPE_UID (TREE_TYPE (t)));
1956 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1957 : 0 : hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
1958 : :
1959 : 0 : return hstate.end ();
1960 : : }
1961 : :
1962 : : bool
1963 : 0 : poly_int_cst_hasher::equal (tree x, const compare_type &y)
1964 : : {
1965 : 0 : if (TREE_TYPE (x) != y.first)
1966 : : return false;
1967 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1968 : 0 : if (wi::to_wide (POLY_INT_CST_COEFF (x, i)) != y.second->coeffs[i])
1969 : : return false;
1970 : : return true;
1971 : : }
1972 : :
1973 : : /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
1974 : : The elements must also have type TYPE. */
1975 : :
1976 : : tree
1977 : 0 : build_poly_int_cst (tree type, const poly_wide_int_ref &values)
1978 : : {
1979 : 0 : unsigned int prec = TYPE_PRECISION (type);
1980 : 0 : gcc_assert (prec <= values.coeffs[0].get_precision ());
1981 : 0 : poly_wide_int c = poly_wide_int::from (values, prec, SIGNED);
1982 : :
1983 : 0 : inchash::hash h;
1984 : 0 : h.add_int (TYPE_UID (type));
1985 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1986 : 0 : h.add_wide_int (c.coeffs[i]);
1987 : 0 : poly_int_cst_hasher::compare_type comp (type, &c);
1988 : 0 : tree *slot = poly_int_cst_hash_table->find_slot_with_hash (comp, h.end (),
1989 : : INSERT);
1990 : 0 : if (*slot == NULL_TREE)
1991 : : {
1992 : : tree coeffs[NUM_POLY_INT_COEFFS];
1993 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1994 : 0 : coeffs[i] = wide_int_to_tree_1 (type, c.coeffs[i]);
1995 : 0 : *slot = build_new_poly_int_cst (type, coeffs);
1996 : : }
1997 : 0 : return *slot;
1998 : 0 : }
1999 : :
2000 : : /* Create a constant tree with value VALUE in type TYPE. */
2001 : :
2002 : : tree
2003 : 9057567523 : wide_int_to_tree (tree type, const poly_wide_int_ref &value)
2004 : : {
2005 : 9057567523 : if (value.is_constant ())
2006 : 9057567523 : return wide_int_to_tree_1 (type, value.coeffs[0]);
2007 : : return build_poly_int_cst (type, value);
2008 : : }
2009 : :
2010 : : /* Insert INTEGER_CST T into a cache of integer constants. And return
2011 : : the cached constant (which may or may not be T). If MIGHT_DUPLICATE
2012 : : is false, and T falls into the type's 'smaller values' range, there
2013 : : cannot be an existing entry. Otherwise, if MIGHT_DUPLICATE is true,
2014 : : or the value is large, should an existing entry exist, it is
2015 : : returned (rather than inserting T). */
2016 : :
2017 : : tree
2018 : 458485 : cache_integer_cst (tree t, bool might_duplicate ATTRIBUTE_UNUSED)
2019 : : {
2020 : 458485 : tree type = TREE_TYPE (t);
2021 : 458485 : int ix = -1;
2022 : 458485 : int limit = 0;
2023 : 458485 : int prec = TYPE_PRECISION (type);
2024 : :
2025 : 458485 : gcc_assert (!TREE_OVERFLOW (t));
2026 : :
2027 : : /* The caching indices here must match those in
2028 : : wide_int_to_type_1. */
2029 : 458485 : switch (TREE_CODE (type))
2030 : : {
2031 : 0 : case NULLPTR_TYPE:
2032 : 0 : gcc_checking_assert (integer_zerop (t));
2033 : : /* Fallthru. */
2034 : :
2035 : 3047 : case POINTER_TYPE:
2036 : 3047 : case REFERENCE_TYPE:
2037 : 3047 : {
2038 : 3047 : if (integer_zerop (t))
2039 : : ix = 0;
2040 : 1256 : else if (integer_onep (t))
2041 : : ix = 2;
2042 : :
2043 : : if (ix >= 0)
2044 : : limit = 3;
2045 : : }
2046 : : break;
2047 : :
2048 : 10033 : case BOOLEAN_TYPE:
2049 : : /* Cache false or true. */
2050 : 10033 : limit = 2;
2051 : 10033 : if (wi::ltu_p (wi::to_wide (t), 2))
2052 : 0 : ix = TREE_INT_CST_ELT (t, 0);
2053 : : break;
2054 : :
2055 : 433917 : case INTEGER_TYPE:
2056 : 433917 : case OFFSET_TYPE:
2057 : 433917 : case BITINT_TYPE:
2058 : 433917 : if (TYPE_UNSIGNED (type))
2059 : : {
2060 : : /* Cache 0..N */
2061 : 322237 : limit = param_integer_share_limit;
2062 : :
2063 : : /* This is a little hokie, but if the prec is smaller than
2064 : : what is necessary to hold param_integer_share_limit, then the
2065 : : obvious test will not get the correct answer. */
2066 : 322237 : if (prec < HOST_BITS_PER_WIDE_INT)
2067 : : {
2068 : 71974 : if (tree_to_uhwi (t)
2069 : 71974 : < (unsigned HOST_WIDE_INT) param_integer_share_limit)
2070 : 10489 : ix = tree_to_uhwi (t);
2071 : : }
2072 : 250263 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2073 : 189012 : ix = tree_to_uhwi (t);
2074 : : }
2075 : : else
2076 : : {
2077 : : /* Cache -1..N */
2078 : 111680 : limit = param_integer_share_limit + 1;
2079 : :
2080 : 111680 : if (integer_minus_onep (t))
2081 : : ix = 0;
2082 : 111308 : else if (!wi::neg_p (wi::to_wide (t)))
2083 : : {
2084 : 97268 : if (prec < HOST_BITS_PER_WIDE_INT)
2085 : : {
2086 : 93065 : if (tree_to_shwi (t) < param_integer_share_limit)
2087 : 85606 : ix = tree_to_shwi (t) + 1;
2088 : : }
2089 : 4203 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2090 : 3414 : ix = tree_to_shwi (t) + 1;
2091 : : }
2092 : : }
2093 : : break;
2094 : :
2095 : : case ENUMERAL_TYPE:
2096 : : /* The slot used by TYPE_CACHED_VALUES is used for the enum
2097 : : members. */
2098 : : break;
2099 : :
2100 : 0 : default:
2101 : 0 : gcc_unreachable ();
2102 : : }
2103 : :
2104 : 290312 : if (ix >= 0)
2105 : : {
2106 : : /* Look for it in the type's vector of small shared ints. */
2107 : 290965 : if (!TYPE_CACHED_VALUES_P (type))
2108 : : {
2109 : 12524 : TYPE_CACHED_VALUES_P (type) = 1;
2110 : 12524 : TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
2111 : : }
2112 : :
2113 : 290965 : if (tree r = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix))
2114 : : {
2115 : 269691 : gcc_checking_assert (might_duplicate);
2116 : 269691 : t = r;
2117 : : }
2118 : : else
2119 : 21274 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
2120 : : }
2121 : : else
2122 : : {
2123 : : /* Use the cache of larger shared ints. */
2124 : 167520 : tree *slot = int_cst_hash_table->find_slot (t, INSERT);
2125 : 167520 : if (tree r = *slot)
2126 : : {
2127 : : /* If there is already an entry for the number verify it's the
2128 : : same value. */
2129 : 98709 : gcc_checking_assert (wi::to_wide (tree (r)) == wi::to_wide (t));
2130 : : /* And return the cached value. */
2131 : 98709 : t = r;
2132 : : }
2133 : : else
2134 : : /* Otherwise insert this one into the hash table. */
2135 : 68811 : *slot = t;
2136 : : }
2137 : :
2138 : 458485 : return t;
2139 : : }
2140 : :
2141 : :
2142 : : /* Builds an integer constant in TYPE such that lowest BITS bits are ones
2143 : : and the rest are zeros. */
2144 : :
2145 : : tree
2146 : 9255084 : build_low_bits_mask (tree type, unsigned bits)
2147 : : {
2148 : 9255084 : gcc_assert (bits <= TYPE_PRECISION (type));
2149 : :
2150 : 9255084 : return wide_int_to_tree (type, wi::mask (bits, false,
2151 : 9255084 : TYPE_PRECISION (type)));
2152 : : }
2153 : :
2154 : : /* Checks that X is integer constant that can be expressed in (unsigned)
2155 : : HOST_WIDE_INT without loss of precision. */
2156 : :
2157 : : bool
2158 : 618438779 : cst_and_fits_in_hwi (const_tree x)
2159 : : {
2160 : 618438779 : return (TREE_CODE (x) == INTEGER_CST
2161 : 618438779 : && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
2162 : : }
2163 : :
2164 : : /* Build a newly constructed VECTOR_CST with the given values of
2165 : : (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN. */
2166 : :
2167 : : tree
2168 : 3172647 : make_vector (unsigned log2_npatterns,
2169 : : unsigned int nelts_per_pattern MEM_STAT_DECL)
2170 : : {
2171 : 3172647 : gcc_assert (IN_RANGE (nelts_per_pattern, 1, 3));
2172 : 3172647 : tree t;
2173 : 3172647 : unsigned npatterns = 1 << log2_npatterns;
2174 : 3172647 : unsigned encoded_nelts = npatterns * nelts_per_pattern;
2175 : 3172647 : unsigned length = (sizeof (struct tree_vector)
2176 : : + (encoded_nelts - 1) * sizeof (tree));
2177 : :
2178 : 3172647 : record_node_allocation_statistics (VECTOR_CST, length);
2179 : :
2180 : 3172647 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2181 : :
2182 : 3172647 : TREE_SET_CODE (t, VECTOR_CST);
2183 : 3172647 : TREE_CONSTANT (t) = 1;
2184 : 3172647 : VECTOR_CST_LOG2_NPATTERNS (t) = log2_npatterns;
2185 : 3172647 : VECTOR_CST_NELTS_PER_PATTERN (t) = nelts_per_pattern;
2186 : :
2187 : 3172647 : return t;
2188 : : }
2189 : :
2190 : : /* Return a new VECTOR_CST node whose type is TYPE and whose values
2191 : : are extracted from V, a vector of CONSTRUCTOR_ELT. */
2192 : :
2193 : : tree
2194 : 656543 : build_vector_from_ctor (tree type, const vec<constructor_elt, va_gc> *v)
2195 : : {
2196 : 656543 : if (vec_safe_length (v) == 0)
2197 : 685 : return build_zero_cst (type);
2198 : :
2199 : 655858 : unsigned HOST_WIDE_INT idx, nelts, step = 1;
2200 : 655858 : tree value;
2201 : :
2202 : : /* If the vector is a VLA, build a VLA constant vector. */
2203 : 655858 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts))
2204 : : {
2205 : : nelts = constant_lower_bound (TYPE_VECTOR_SUBPARTS (type));
2206 : : gcc_assert (vec_safe_length (v) <= nelts);
2207 : : step = 2;
2208 : : }
2209 : :
2210 : 655858 : tree_vector_builder vec (type, nelts, step);
2211 : 4361556 : FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
2212 : : {
2213 : 3705698 : if (TREE_CODE (value) == VECTOR_CST)
2214 : : {
2215 : : /* If NELTS is constant then this must be too. */
2216 : 366 : unsigned int sub_nelts = VECTOR_CST_NELTS (value).to_constant ();
2217 : 1418 : for (unsigned i = 0; i < sub_nelts; ++i)
2218 : 1052 : vec.quick_push (VECTOR_CST_ELT (value, i));
2219 : : }
2220 : : else
2221 : 3705332 : vec.quick_push (value);
2222 : : }
2223 : 1853956 : while (vec.length () < nelts * step)
2224 : 271120 : vec.quick_push (build_zero_cst (TREE_TYPE (type)));
2225 : :
2226 : 655858 : return vec.build ();
2227 : 655858 : }
2228 : :
2229 : : /* Build a vector of type VECTYPE where all the elements are SCs. */
2230 : : tree
2231 : 615421 : build_vector_from_val (tree vectype, tree sc)
2232 : : {
2233 : 615421 : unsigned HOST_WIDE_INT i, nunits;
2234 : :
2235 : 615421 : if (sc == error_mark_node)
2236 : : return sc;
2237 : :
2238 : : /* Verify that the vector type is suitable for SC. Note that there
2239 : : is some inconsistency in the type-system with respect to restrict
2240 : : qualifications of pointers. Vector types always have a main-variant
2241 : : element type and the qualification is applied to the vector-type.
2242 : : So TREE_TYPE (vector-type) does not return a properly qualified
2243 : : vector element-type. */
2244 : 615421 : gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
2245 : : TREE_TYPE (vectype)));
2246 : :
2247 : 615421 : if (CONSTANT_CLASS_P (sc))
2248 : : {
2249 : 587231 : tree_vector_builder v (vectype, 1, 1);
2250 : 587231 : v.quick_push (sc);
2251 : 587231 : return v.build ();
2252 : 587231 : }
2253 : 28190 : else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
2254 : : return fold_build1 (VEC_DUPLICATE_EXPR, vectype, sc);
2255 : : else
2256 : : {
2257 : 28190 : vec<constructor_elt, va_gc> *v;
2258 : 28190 : vec_alloc (v, nunits);
2259 : 131072 : for (i = 0; i < nunits; ++i)
2260 : 102882 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
2261 : 28190 : return build_constructor (vectype, v);
2262 : : }
2263 : : }
2264 : :
2265 : : /* If TYPE is not a vector type, just return SC, otherwise return
2266 : : build_vector_from_val (TYPE, SC). */
2267 : :
2268 : : tree
2269 : 5114451 : build_uniform_cst (tree type, tree sc)
2270 : : {
2271 : 5114451 : if (!VECTOR_TYPE_P (type))
2272 : : return sc;
2273 : :
2274 : 249 : return build_vector_from_val (type, sc);
2275 : : }
2276 : :
2277 : : /* Build a vector series of type TYPE in which element I has the value
2278 : : BASE + I * STEP. The result is a constant if BASE and STEP are constant
2279 : : and a VEC_SERIES_EXPR otherwise. */
2280 : :
2281 : : tree
2282 : 18 : build_vec_series (tree type, tree base, tree step)
2283 : : {
2284 : 18 : if (integer_zerop (step))
2285 : 0 : return build_vector_from_val (type, base);
2286 : 18 : if (TREE_CODE (base) == INTEGER_CST && TREE_CODE (step) == INTEGER_CST)
2287 : : {
2288 : 18 : tree_vector_builder builder (type, 1, 3);
2289 : 18 : tree elt1 = wide_int_to_tree (TREE_TYPE (base),
2290 : 36 : wi::to_wide (base) + wi::to_wide (step));
2291 : 18 : tree elt2 = wide_int_to_tree (TREE_TYPE (base),
2292 : 36 : wi::to_wide (elt1) + wi::to_wide (step));
2293 : 18 : builder.quick_push (base);
2294 : 18 : builder.quick_push (elt1);
2295 : 18 : builder.quick_push (elt2);
2296 : 18 : return builder.build ();
2297 : 18 : }
2298 : 0 : return build2 (VEC_SERIES_EXPR, type, base, step);
2299 : : }
2300 : :
2301 : : /* Return a vector with the same number of units and number of bits
2302 : : as VEC_TYPE, but in which the elements are a linear series of unsigned
2303 : : integers { BASE, BASE + STEP, BASE + STEP * 2, ... }. */
2304 : :
2305 : : tree
2306 : 1783 : build_index_vector (tree vec_type, poly_uint64 base, poly_uint64 step)
2307 : : {
2308 : 1783 : tree index_vec_type = vec_type;
2309 : 1783 : tree index_elt_type = TREE_TYPE (vec_type);
2310 : 1783 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vec_type);
2311 : 1783 : if (!INTEGRAL_TYPE_P (index_elt_type) || !TYPE_UNSIGNED (index_elt_type))
2312 : : {
2313 : 4 : index_elt_type = build_nonstandard_integer_type
2314 : 8 : (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type)), true);
2315 : 4 : index_vec_type = build_vector_type (index_elt_type, nunits);
2316 : : }
2317 : :
2318 : 1783 : tree_vector_builder v (index_vec_type, 1, 3);
2319 : 7132 : for (unsigned int i = 0; i < 3; ++i)
2320 : 5349 : v.quick_push (build_int_cstu (index_elt_type, base + i * step));
2321 : 1783 : return v.build ();
2322 : 1783 : }
2323 : :
2324 : : /* Return a VECTOR_CST of type VEC_TYPE in which the first NUM_A
2325 : : elements are A and the rest are B. */
2326 : :
2327 : : tree
2328 : 0 : build_vector_a_then_b (tree vec_type, unsigned int num_a, tree a, tree b)
2329 : : {
2330 : 0 : gcc_assert (known_le (num_a, TYPE_VECTOR_SUBPARTS (vec_type)));
2331 : 0 : unsigned int count = constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_type));
2332 : : /* Optimize the constant case. */
2333 : 0 : if ((count & 1) == 0 && TYPE_VECTOR_SUBPARTS (vec_type).is_constant ())
2334 : 0 : count /= 2;
2335 : 0 : tree_vector_builder builder (vec_type, count, 2);
2336 : 0 : for (unsigned int i = 0; i < count * 2; ++i)
2337 : 0 : builder.quick_push (i < num_a ? a : b);
2338 : 0 : return builder.build ();
2339 : 0 : }
2340 : :
2341 : : /* Something has messed with the elements of CONSTRUCTOR C after it was built;
2342 : : calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
2343 : :
2344 : : void
2345 : 90434306 : recompute_constructor_flags (tree c)
2346 : : {
2347 : 90434306 : unsigned int i;
2348 : 90434306 : tree val;
2349 : 90434306 : bool constant_p = true;
2350 : 90434306 : bool side_effects_p = false;
2351 : 90434306 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2352 : :
2353 : 196891488 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2354 : : {
2355 : : /* Mostly ctors will have elts that don't have side-effects, so
2356 : : the usual case is to scan all the elements. Hence a single
2357 : : loop for both const and side effects, rather than one loop
2358 : : each (with early outs). */
2359 : 106457182 : if (!TREE_CONSTANT (val))
2360 : 15512355 : constant_p = false;
2361 : 106457182 : if (TREE_SIDE_EFFECTS (val))
2362 : 3097947 : side_effects_p = true;
2363 : : }
2364 : :
2365 : 90434306 : TREE_SIDE_EFFECTS (c) = side_effects_p;
2366 : 90434306 : TREE_CONSTANT (c) = constant_p;
2367 : 90434306 : }
2368 : :
2369 : : /* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
2370 : : CONSTRUCTOR C. */
2371 : :
2372 : : void
2373 : 14190938 : verify_constructor_flags (tree c)
2374 : : {
2375 : 14190938 : unsigned int i;
2376 : 14190938 : tree val;
2377 : 14190938 : bool constant_p = TREE_CONSTANT (c);
2378 : 14190938 : bool side_effects_p = TREE_SIDE_EFFECTS (c);
2379 : 14190938 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2380 : :
2381 : 64135741 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2382 : : {
2383 : 49944803 : if (constant_p && !TREE_CONSTANT (val))
2384 : 0 : internal_error ("non-constant element in constant CONSTRUCTOR");
2385 : 49944803 : if (!side_effects_p && TREE_SIDE_EFFECTS (val))
2386 : 0 : internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
2387 : : }
2388 : 14190938 : }
2389 : :
2390 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2391 : : are in the vec pointed to by VALS. */
2392 : : tree
2393 : 75180243 : build_constructor (tree type, vec<constructor_elt, va_gc> *vals MEM_STAT_DECL)
2394 : : {
2395 : 75180243 : tree c = make_node (CONSTRUCTOR PASS_MEM_STAT);
2396 : :
2397 : 75180243 : TREE_TYPE (c) = type;
2398 : 75180243 : CONSTRUCTOR_ELTS (c) = vals;
2399 : :
2400 : 75180243 : recompute_constructor_flags (c);
2401 : :
2402 : 75180243 : return c;
2403 : : }
2404 : :
2405 : : /* Build a CONSTRUCTOR node made of a single initializer, with the specified
2406 : : INDEX and VALUE. */
2407 : : tree
2408 : 3746 : build_constructor_single (tree type, tree index, tree value)
2409 : : {
2410 : 3746 : vec<constructor_elt, va_gc> *v;
2411 : 3746 : constructor_elt elt = {index, value};
2412 : :
2413 : 3746 : vec_alloc (v, 1);
2414 : 3746 : v->quick_push (elt);
2415 : :
2416 : 3746 : return build_constructor (type, v);
2417 : : }
2418 : :
2419 : :
2420 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2421 : : are in a list pointed to by VALS. */
2422 : : tree
2423 : 992 : build_constructor_from_list (tree type, tree vals)
2424 : : {
2425 : 992 : tree t;
2426 : 992 : vec<constructor_elt, va_gc> *v = NULL;
2427 : :
2428 : 992 : if (vals)
2429 : : {
2430 : 992 : vec_alloc (v, list_length (vals));
2431 : 20809 : for (t = vals; t; t = TREE_CHAIN (t))
2432 : 19817 : CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
2433 : : }
2434 : :
2435 : 992 : return build_constructor (type, v);
2436 : : }
2437 : :
2438 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2439 : : are in a vector pointed to by VALS. Note that the TREE_PURPOSE
2440 : : fields in the constructor remain null. */
2441 : :
2442 : : tree
2443 : 1405 : build_constructor_from_vec (tree type, const vec<tree, va_gc> *vals)
2444 : : {
2445 : 1405 : vec<constructor_elt, va_gc> *v = NULL;
2446 : :
2447 : 72754 : for (tree t : vals)
2448 : 71349 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
2449 : :
2450 : 1405 : return build_constructor (type, v);
2451 : : }
2452 : :
2453 : : /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
2454 : : of elements, provided as index/value pairs. */
2455 : :
2456 : : tree
2457 : 38302 : build_constructor_va (tree type, int nelts, ...)
2458 : : {
2459 : 38302 : vec<constructor_elt, va_gc> *v = NULL;
2460 : 38302 : va_list p;
2461 : :
2462 : 38302 : va_start (p, nelts);
2463 : 38302 : vec_alloc (v, nelts);
2464 : 38302 : while (nelts--)
2465 : : {
2466 : 115099 : tree index = va_arg (p, tree);
2467 : 115099 : tree value = va_arg (p, tree);
2468 : 268500 : CONSTRUCTOR_APPEND_ELT (v, index, value);
2469 : : }
2470 : 38302 : va_end (p);
2471 : 38302 : return build_constructor (type, v);
2472 : : }
2473 : :
2474 : : /* Return a node of type TYPE for which TREE_CLOBBER_P is true. */
2475 : :
2476 : : tree
2477 : 12067020 : build_clobber (tree type, enum clobber_kind kind)
2478 : : {
2479 : 12067020 : tree clobber = build_constructor (type, NULL);
2480 : 12067020 : TREE_THIS_VOLATILE (clobber) = true;
2481 : 12067020 : CLOBBER_KIND (clobber) = kind;
2482 : 12067020 : return clobber;
2483 : : }
2484 : :
2485 : : /* Return a new FIXED_CST node whose type is TYPE and value is F. */
2486 : :
2487 : : tree
2488 : 54 : build_fixed (tree type, FIXED_VALUE_TYPE f)
2489 : : {
2490 : 54 : tree v;
2491 : 54 : FIXED_VALUE_TYPE *fp;
2492 : :
2493 : 54 : v = make_node (FIXED_CST);
2494 : 54 : fp = ggc_alloc<fixed_value> ();
2495 : 54 : memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
2496 : :
2497 : 54 : TREE_TYPE (v) = type;
2498 : 54 : TREE_FIXED_CST_PTR (v) = fp;
2499 : 54 : return v;
2500 : : }
2501 : :
2502 : : /* Return a new REAL_CST node whose type is TYPE and value is D. */
2503 : :
2504 : : tree
2505 : 42772162 : build_real (tree type, REAL_VALUE_TYPE d)
2506 : : {
2507 : 42772162 : tree v;
2508 : 42772162 : int overflow = 0;
2509 : :
2510 : : /* dconst{0,1,2,m1,half} are used in various places in
2511 : : the middle-end and optimizers, allow them here
2512 : : even for decimal floating point types as an exception
2513 : : by converting them to decimal. */
2514 : 42772162 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))
2515 : 610198 : && (d.cl == rvc_normal || d.cl == rvc_zero)
2516 : 43380314 : && !d.decimal)
2517 : : {
2518 : 568 : if (memcmp (&d, &dconst1, sizeof (d)) == 0)
2519 : 0 : decimal_real_from_string (&d, "1");
2520 : 568 : else if (memcmp (&d, &dconst2, sizeof (d)) == 0)
2521 : 22 : decimal_real_from_string (&d, "2");
2522 : 546 : else if (memcmp (&d, &dconstm1, sizeof (d)) == 0)
2523 : 90 : decimal_real_from_string (&d, "-1");
2524 : 456 : else if (memcmp (&d, &dconsthalf, sizeof (d)) == 0)
2525 : 0 : decimal_real_from_string (&d, "0.5");
2526 : 456 : else if (memcmp (&d, &dconst0, sizeof (d)) == 0)
2527 : : {
2528 : : /* Make sure to give zero the minimum quantum exponent for
2529 : : the type (which corresponds to all bits zero). */
2530 : 456 : const struct real_format *fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
2531 : 456 : char buf[16];
2532 : 456 : sprintf (buf, "0e%d", fmt->emin - fmt->p);
2533 : 456 : decimal_real_from_string (&d, buf);
2534 : : }
2535 : : else
2536 : 0 : gcc_unreachable ();
2537 : : }
2538 : :
2539 : : /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
2540 : : Consider doing it via real_convert now. */
2541 : :
2542 : 42772162 : v = make_node (REAL_CST);
2543 : 42772162 : TREE_TYPE (v) = type;
2544 : 42772162 : memcpy (TREE_REAL_CST_PTR (v), &d, sizeof (REAL_VALUE_TYPE));
2545 : 42772162 : TREE_OVERFLOW (v) = overflow;
2546 : 42772162 : return v;
2547 : : }
2548 : :
2549 : : /* Like build_real, but first truncate D to the type. */
2550 : :
2551 : : tree
2552 : 176289 : build_real_truncate (tree type, REAL_VALUE_TYPE d)
2553 : : {
2554 : 176289 : return build_real (type, real_value_truncate (TYPE_MODE (type), d));
2555 : : }
2556 : :
2557 : : /* Return a new REAL_CST node whose type is TYPE
2558 : : and whose value is the integer value of the INTEGER_CST node I. */
2559 : :
2560 : : REAL_VALUE_TYPE
2561 : 24999274 : real_value_from_int_cst (const_tree type, const_tree i)
2562 : : {
2563 : 24999274 : REAL_VALUE_TYPE d;
2564 : :
2565 : : /* Clear all bits of the real value type so that we can later do
2566 : : bitwise comparisons to see if two values are the same. */
2567 : 24999274 : memset (&d, 0, sizeof d);
2568 : :
2569 : 24999274 : real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, wi::to_wide (i),
2570 : 24999274 : TYPE_SIGN (TREE_TYPE (i)));
2571 : 24999274 : return d;
2572 : : }
2573 : :
2574 : : /* Given a tree representing an integer constant I, return a tree
2575 : : representing the same value as a floating-point constant of type TYPE. */
2576 : :
2577 : : tree
2578 : 24423243 : build_real_from_int_cst (tree type, const_tree i)
2579 : : {
2580 : 24423243 : tree v;
2581 : 24423243 : int overflow = TREE_OVERFLOW (i);
2582 : :
2583 : 24423243 : v = build_real (type, real_value_from_int_cst (type, i));
2584 : :
2585 : 24423243 : TREE_OVERFLOW (v) |= overflow;
2586 : 24423243 : return v;
2587 : : }
2588 : :
2589 : : /* Return a new REAL_CST node whose type is TYPE
2590 : : and whose value is the integer value I which has sign SGN. */
2591 : :
2592 : : tree
2593 : 133 : build_real_from_wide (tree type, const wide_int_ref &i, signop sgn)
2594 : : {
2595 : 133 : REAL_VALUE_TYPE d;
2596 : :
2597 : : /* Clear all bits of the real value type so that we can later do
2598 : : bitwise comparisons to see if two values are the same. */
2599 : 133 : memset (&d, 0, sizeof d);
2600 : :
2601 : 133 : real_from_integer (&d, TYPE_MODE (type), i, sgn);
2602 : 133 : return build_real (type, d);
2603 : : }
2604 : :
2605 : : /* Return a newly constructed STRING_CST node whose value is the LEN
2606 : : characters at STR when STR is nonnull, or all zeros otherwise.
2607 : : Note that for a C string literal, LEN should include the trailing NUL.
2608 : : The TREE_TYPE is not initialized. */
2609 : :
2610 : : tree
2611 : 92222628 : build_string (unsigned len, const char *str /*= NULL */)
2612 : : {
2613 : : /* Do not waste bytes provided by padding of struct tree_string. */
2614 : 92222628 : unsigned size = len + offsetof (struct tree_string, str) + 1;
2615 : :
2616 : 92222628 : record_node_allocation_statistics (STRING_CST, size);
2617 : :
2618 : 92222628 : tree s = (tree) ggc_internal_alloc (size);
2619 : :
2620 : 92222628 : memset (s, 0, sizeof (struct tree_typed));
2621 : 92222628 : TREE_SET_CODE (s, STRING_CST);
2622 : 92222628 : TREE_CONSTANT (s) = 1;
2623 : 92222628 : TREE_STRING_LENGTH (s) = len;
2624 : 92222628 : if (str)
2625 : 92213443 : memcpy (s->string.str, str, len);
2626 : : else
2627 : 9185 : memset (s->string.str, 0, len);
2628 : 92222628 : s->string.str[len] = '\0';
2629 : :
2630 : 92222628 : return s;
2631 : : }
2632 : :
2633 : : /* Return a newly constructed COMPLEX_CST node whose value is
2634 : : specified by the real and imaginary parts REAL and IMAG.
2635 : : Both REAL and IMAG should be constant nodes. TYPE, if specified,
2636 : : will be the type of the COMPLEX_CST; otherwise a new type will be made. */
2637 : :
2638 : : tree
2639 : 484752 : build_complex (tree type, tree real, tree imag)
2640 : : {
2641 : 484752 : gcc_assert (CONSTANT_CLASS_P (real));
2642 : 484752 : gcc_assert (CONSTANT_CLASS_P (imag));
2643 : :
2644 : 484752 : tree t = make_node (COMPLEX_CST);
2645 : :
2646 : 484752 : TREE_REALPART (t) = real;
2647 : 484752 : TREE_IMAGPART (t) = imag;
2648 : 484752 : TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
2649 : 484752 : TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
2650 : 484752 : return t;
2651 : : }
2652 : :
2653 : : /* Build a complex (inf +- 0i), such as for the result of cproj.
2654 : : TYPE is the complex tree type of the result. If NEG is true, the
2655 : : imaginary zero is negative. */
2656 : :
2657 : : tree
2658 : 840 : build_complex_inf (tree type, bool neg)
2659 : : {
2660 : 840 : REAL_VALUE_TYPE rzero = dconst0;
2661 : :
2662 : 840 : rzero.sign = neg;
2663 : 840 : return build_complex (type, build_real (TREE_TYPE (type), dconstinf),
2664 : 840 : build_real (TREE_TYPE (type), rzero));
2665 : : }
2666 : :
2667 : : /* Return the constant 1 in type TYPE. If TYPE has several elements, each
2668 : : element is set to 1. In particular, this is 1 + i for complex types. */
2669 : :
2670 : : tree
2671 : 4168 : build_each_one_cst (tree type)
2672 : : {
2673 : 4168 : if (TREE_CODE (type) == COMPLEX_TYPE)
2674 : : {
2675 : 0 : tree scalar = build_one_cst (TREE_TYPE (type));
2676 : 0 : return build_complex (type, scalar, scalar);
2677 : : }
2678 : : else
2679 : 4168 : return build_one_cst (type);
2680 : : }
2681 : :
2682 : : /* Return a constant of arithmetic type TYPE which is the
2683 : : multiplicative identity of the set TYPE. */
2684 : :
2685 : : tree
2686 : 9406544 : build_one_cst (tree type)
2687 : : {
2688 : 9406544 : switch (TREE_CODE (type))
2689 : : {
2690 : 9392699 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2691 : 9392699 : case POINTER_TYPE: case REFERENCE_TYPE:
2692 : 9392699 : case OFFSET_TYPE: case BITINT_TYPE:
2693 : 9392699 : return build_int_cst (type, 1);
2694 : :
2695 : 10503 : case REAL_TYPE:
2696 : 10503 : return build_real (type, dconst1);
2697 : :
2698 : 0 : case FIXED_POINT_TYPE:
2699 : : /* We can only generate 1 for accum types. */
2700 : 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2701 : 0 : return build_fixed (type, FCONST1 (TYPE_MODE (type)));
2702 : :
2703 : 339 : case VECTOR_TYPE:
2704 : 339 : {
2705 : 339 : tree scalar = build_one_cst (TREE_TYPE (type));
2706 : :
2707 : 339 : return build_vector_from_val (type, scalar);
2708 : : }
2709 : :
2710 : 3003 : case COMPLEX_TYPE:
2711 : 6006 : return build_complex (type,
2712 : 3003 : build_one_cst (TREE_TYPE (type)),
2713 : 6006 : build_zero_cst (TREE_TYPE (type)));
2714 : :
2715 : 0 : default:
2716 : 0 : gcc_unreachable ();
2717 : : }
2718 : : }
2719 : :
2720 : : /* Return an integer of type TYPE containing all 1's in as much precision as
2721 : : it contains, or a complex or vector whose subparts are such integers. */
2722 : :
2723 : : tree
2724 : 1739835 : build_all_ones_cst (tree type)
2725 : : {
2726 : 1739835 : if (TREE_CODE (type) == COMPLEX_TYPE)
2727 : : {
2728 : 0 : tree scalar = build_all_ones_cst (TREE_TYPE (type));
2729 : 0 : return build_complex (type, scalar, scalar);
2730 : : }
2731 : : else
2732 : 1739835 : return build_minus_one_cst (type);
2733 : : }
2734 : :
2735 : : /* Return a constant of arithmetic type TYPE which is the
2736 : : opposite of the multiplicative identity of the set TYPE. */
2737 : :
2738 : : tree
2739 : 2333840 : build_minus_one_cst (tree type)
2740 : : {
2741 : 2333840 : switch (TREE_CODE (type))
2742 : : {
2743 : 2218468 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2744 : 2218468 : case POINTER_TYPE: case REFERENCE_TYPE:
2745 : 2218468 : case OFFSET_TYPE: case BITINT_TYPE:
2746 : 2218468 : return build_int_cst (type, -1);
2747 : :
2748 : 9786 : case REAL_TYPE:
2749 : 9786 : return build_real (type, dconstm1);
2750 : :
2751 : 0 : case FIXED_POINT_TYPE:
2752 : : /* We can only generate 1 for accum types. */
2753 : 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2754 : 0 : return build_fixed (type,
2755 : : fixed_from_double_int (double_int_minus_one,
2756 : 0 : SCALAR_TYPE_MODE (type)));
2757 : :
2758 : 105586 : case VECTOR_TYPE:
2759 : 105586 : {
2760 : 105586 : tree scalar = build_minus_one_cst (TREE_TYPE (type));
2761 : :
2762 : 105586 : return build_vector_from_val (type, scalar);
2763 : : }
2764 : :
2765 : 0 : case COMPLEX_TYPE:
2766 : 0 : return build_complex (type,
2767 : 0 : build_minus_one_cst (TREE_TYPE (type)),
2768 : 0 : build_zero_cst (TREE_TYPE (type)));
2769 : :
2770 : 0 : default:
2771 : 0 : gcc_unreachable ();
2772 : : }
2773 : : }
2774 : :
2775 : : /* Build 0 constant of type TYPE. This is used by constructor folding
2776 : : and thus the constant should be represented in memory by
2777 : : zero(es). */
2778 : :
2779 : : tree
2780 : 82382566 : build_zero_cst (tree type)
2781 : : {
2782 : 82382566 : switch (TREE_CODE (type))
2783 : : {
2784 : 81816844 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2785 : 81816844 : case POINTER_TYPE: case REFERENCE_TYPE:
2786 : 81816844 : case OFFSET_TYPE: case NULLPTR_TYPE: case BITINT_TYPE:
2787 : 81816844 : return build_int_cst (type, 0);
2788 : :
2789 : 223524 : case REAL_TYPE:
2790 : 223524 : return build_real (type, dconst0);
2791 : :
2792 : 0 : case FIXED_POINT_TYPE:
2793 : 0 : return build_fixed (type, FCONST0 (TYPE_MODE (type)));
2794 : :
2795 : 153049 : case VECTOR_TYPE:
2796 : 153049 : {
2797 : 153049 : tree scalar = build_zero_cst (TREE_TYPE (type));
2798 : :
2799 : 153049 : return build_vector_from_val (type, scalar);
2800 : : }
2801 : :
2802 : 3024 : case COMPLEX_TYPE:
2803 : 3024 : {
2804 : 3024 : tree zero = build_zero_cst (TREE_TYPE (type));
2805 : :
2806 : 3024 : return build_complex (type, zero, zero);
2807 : : }
2808 : :
2809 : 186125 : default:
2810 : 186125 : if (!AGGREGATE_TYPE_P (type))
2811 : 1 : return fold_convert (type, integer_zero_node);
2812 : 186124 : return build_constructor (type, NULL);
2813 : : }
2814 : : }
2815 : :
2816 : : /* Build a constant of integer type TYPE, made of VALUE's bits replicated
2817 : : every WIDTH bits to fit TYPE's precision. */
2818 : :
2819 : : tree
2820 : 14 : build_replicated_int_cst (tree type, unsigned int width, HOST_WIDE_INT value)
2821 : : {
2822 : 14 : int n = ((TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
2823 : 14 : / HOST_BITS_PER_WIDE_INT);
2824 : 14 : unsigned HOST_WIDE_INT low, mask;
2825 : 14 : HOST_WIDE_INT a[WIDE_INT_MAX_INL_ELTS];
2826 : 14 : int i;
2827 : :
2828 : 14 : gcc_assert (n && n <= WIDE_INT_MAX_INL_ELTS);
2829 : :
2830 : 14 : if (width == HOST_BITS_PER_WIDE_INT)
2831 : 0 : low = value;
2832 : : else
2833 : : {
2834 : 14 : mask = (HOST_WIDE_INT_1U << width) - 1;
2835 : 14 : low = (unsigned HOST_WIDE_INT) ~0 / mask * (value & mask);
2836 : : }
2837 : :
2838 : 28 : for (i = 0; i < n; i++)
2839 : 14 : a[i] = low;
2840 : :
2841 : 14 : gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
2842 : 14 : return wide_int_to_tree (type, wide_int::from_array (a, n,
2843 : 14 : TYPE_PRECISION (type)));
2844 : : }
2845 : :
2846 : : /* If floating-point type TYPE has an IEEE-style sign bit, return an
2847 : : unsigned constant in which only the sign bit is set. Return null
2848 : : otherwise. */
2849 : :
2850 : : tree
2851 : 0 : sign_mask_for (tree type)
2852 : : {
2853 : : /* Avoid having to choose between a real-only sign and a pair of signs.
2854 : : This could be relaxed if the choice becomes obvious later. */
2855 : 0 : if (TREE_CODE (type) == COMPLEX_TYPE)
2856 : : return NULL_TREE;
2857 : :
2858 : 0 : auto eltmode = as_a<scalar_float_mode> (element_mode (type));
2859 : 0 : auto bits = REAL_MODE_FORMAT (eltmode)->ieee_bits;
2860 : 0 : if (!bits || !pow2p_hwi (bits))
2861 : : return NULL_TREE;
2862 : :
2863 : 0 : tree inttype = unsigned_type_for (type);
2864 : 0 : if (!inttype)
2865 : : return NULL_TREE;
2866 : :
2867 : 0 : auto mask = wi::set_bit_in_zero (bits - 1, bits);
2868 : 0 : if (VECTOR_TYPE_P (inttype))
2869 : : {
2870 : 0 : tree elt = wide_int_to_tree (TREE_TYPE (inttype), mask);
2871 : 0 : return build_vector_from_val (inttype, elt);
2872 : : }
2873 : 0 : return wide_int_to_tree (inttype, mask);
2874 : 0 : }
2875 : :
2876 : : /* Build a BINFO with LEN language slots. */
2877 : :
2878 : : tree
2879 : 90208032 : make_tree_binfo (unsigned base_binfos MEM_STAT_DECL)
2880 : : {
2881 : 90208032 : tree t;
2882 : 90208032 : size_t length = (offsetof (struct tree_binfo, base_binfos)
2883 : 90208032 : + vec<tree, va_gc>::embedded_size (base_binfos));
2884 : :
2885 : 90208032 : record_node_allocation_statistics (TREE_BINFO, length);
2886 : :
2887 : 90208032 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
2888 : :
2889 : 90208032 : memset (t, 0, offsetof (struct tree_binfo, base_binfos));
2890 : :
2891 : 90208032 : TREE_SET_CODE (t, TREE_BINFO);
2892 : :
2893 : 90208032 : BINFO_BASE_BINFOS (t)->embedded_init (base_binfos);
2894 : :
2895 : 90208032 : return t;
2896 : : }
2897 : :
2898 : : /* Create a CASE_LABEL_EXPR tree node and return it. */
2899 : :
2900 : : tree
2901 : 4840261 : build_case_label (tree low_value, tree high_value, tree label_decl)
2902 : : {
2903 : 4840261 : tree t = make_node (CASE_LABEL_EXPR);
2904 : :
2905 : 4840261 : TREE_TYPE (t) = void_type_node;
2906 : 4840261 : SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl));
2907 : :
2908 : 4840261 : CASE_LOW (t) = low_value;
2909 : 4840261 : CASE_HIGH (t) = high_value;
2910 : 4840261 : CASE_LABEL (t) = label_decl;
2911 : 4840261 : CASE_CHAIN (t) = NULL_TREE;
2912 : :
2913 : 4840261 : return t;
2914 : : }
2915 : :
2916 : : /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2917 : : values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2918 : : The latter determines the length of the HOST_WIDE_INT vector. */
2919 : :
2920 : : tree
2921 : 188857582 : make_int_cst (int len, int ext_len MEM_STAT_DECL)
2922 : : {
2923 : 188857582 : tree t;
2924 : 188857582 : int length = ((ext_len - 1) * sizeof (HOST_WIDE_INT)
2925 : 188857582 : + sizeof (struct tree_int_cst));
2926 : :
2927 : 188857582 : gcc_assert (len);
2928 : 188857582 : record_node_allocation_statistics (INTEGER_CST, length);
2929 : :
2930 : 188857582 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2931 : :
2932 : 188857582 : TREE_SET_CODE (t, INTEGER_CST);
2933 : 188857582 : TREE_INT_CST_NUNITS (t) = len;
2934 : 188857582 : TREE_INT_CST_EXT_NUNITS (t) = ext_len;
2935 : 188857582 : TREE_CONSTANT (t) = 1;
2936 : :
2937 : 188857582 : return t;
2938 : : }
2939 : :
2940 : : /* Build a newly constructed TREE_VEC node of length LEN. */
2941 : :
2942 : : tree
2943 : 2480386690 : make_tree_vec (int len MEM_STAT_DECL)
2944 : : {
2945 : 2480386690 : tree t;
2946 : 2480386690 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2947 : :
2948 : 2480386690 : record_node_allocation_statistics (TREE_VEC, length);
2949 : :
2950 : 2480386690 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2951 : :
2952 : 2480386690 : TREE_SET_CODE (t, TREE_VEC);
2953 : 2480386690 : TREE_VEC_LENGTH (t) = len;
2954 : :
2955 : 2480386690 : return t;
2956 : : }
2957 : :
2958 : : /* Grow a TREE_VEC node to new length LEN. */
2959 : :
2960 : : tree
2961 : 139342 : grow_tree_vec (tree v, int len MEM_STAT_DECL)
2962 : : {
2963 : 139342 : gcc_assert (TREE_CODE (v) == TREE_VEC);
2964 : :
2965 : 139342 : int oldlen = TREE_VEC_LENGTH (v);
2966 : 139342 : gcc_assert (len > oldlen);
2967 : :
2968 : 139342 : size_t oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
2969 : 139342 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2970 : :
2971 : 139342 : record_node_allocation_statistics (TREE_VEC, length - oldlength);
2972 : :
2973 : 139342 : v = (tree) ggc_realloc (v, length PASS_MEM_STAT);
2974 : :
2975 : 139342 : TREE_VEC_LENGTH (v) = len;
2976 : :
2977 : 139342 : return v;
2978 : : }
2979 : :
2980 : : /* Return true if EXPR is the constant zero, whether it is integral, float or
2981 : : fixed, and scalar, complex or vector. */
2982 : :
2983 : : bool
2984 : 16005977 : zerop (const_tree expr)
2985 : : {
2986 : 16005977 : return (integer_zerop (expr)
2987 : 10944713 : || real_zerop (expr)
2988 : 26538782 : || fixed_zerop (expr));
2989 : : }
2990 : :
2991 : : /* Return true if EXPR is the integer constant zero or a complex constant
2992 : : of zero, or a location wrapper for such a constant. */
2993 : :
2994 : : bool
2995 : 5551984754 : integer_zerop (const_tree expr)
2996 : : {
2997 : 5551984754 : STRIP_ANY_LOCATION_WRAPPER (expr);
2998 : :
2999 : 5551984754 : switch (TREE_CODE (expr))
3000 : : {
3001 : 4649909133 : case INTEGER_CST:
3002 : 4649909133 : return wi::to_wide (expr) == 0;
3003 : 1202746 : case COMPLEX_CST:
3004 : 1202746 : return (integer_zerop (TREE_REALPART (expr))
3005 : 1224868 : && integer_zerop (TREE_IMAGPART (expr)));
3006 : 2457408 : case VECTOR_CST:
3007 : 2457408 : return (VECTOR_CST_NPATTERNS (expr) == 1
3008 : 2348381 : && VECTOR_CST_DUPLICATE_P (expr)
3009 : 4412507 : && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
3010 : : default:
3011 : : return false;
3012 : : }
3013 : : }
3014 : :
3015 : : /* Return true if EXPR is the integer constant one or the corresponding
3016 : : complex constant, or a location wrapper for such a constant. */
3017 : :
3018 : : bool
3019 : 925109038 : integer_onep (const_tree expr)
3020 : : {
3021 : 925109038 : STRIP_ANY_LOCATION_WRAPPER (expr);
3022 : :
3023 : 925109038 : switch (TREE_CODE (expr))
3024 : : {
3025 : 789655048 : case INTEGER_CST:
3026 : 789655048 : return wi::eq_p (wi::to_widest (expr), 1);
3027 : 21352 : case COMPLEX_CST:
3028 : 21352 : return (integer_onep (TREE_REALPART (expr))
3029 : 21372 : && integer_zerop (TREE_IMAGPART (expr)));
3030 : 140524 : case VECTOR_CST:
3031 : 140524 : return (VECTOR_CST_NPATTERNS (expr) == 1
3032 : 125663 : && VECTOR_CST_DUPLICATE_P (expr)
3033 : 255117 : && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3034 : : default:
3035 : : return false;
3036 : : }
3037 : : }
3038 : :
3039 : : /* Return true if EXPR is the integer constant one. For complex and vector,
3040 : : return true if every piece is the integer constant one.
3041 : : Also return true for location wrappers for such a constant. */
3042 : :
3043 : : bool
3044 : 739608 : integer_each_onep (const_tree expr)
3045 : : {
3046 : 739608 : STRIP_ANY_LOCATION_WRAPPER (expr);
3047 : :
3048 : 739608 : if (TREE_CODE (expr) == COMPLEX_CST)
3049 : 34 : return (integer_onep (TREE_REALPART (expr))
3050 : 48 : && integer_onep (TREE_IMAGPART (expr)));
3051 : : else
3052 : 739574 : return integer_onep (expr);
3053 : : }
3054 : :
3055 : : /* Return true if EXPR is an integer containing all 1's in as much precision
3056 : : as it contains, or a complex or vector whose subparts are such integers,
3057 : : or a location wrapper for such a constant. */
3058 : :
3059 : : bool
3060 : 270707533 : integer_all_onesp (const_tree expr)
3061 : : {
3062 : 270707533 : STRIP_ANY_LOCATION_WRAPPER (expr);
3063 : :
3064 : 270707533 : if (TREE_CODE (expr) == COMPLEX_CST
3065 : 926 : && integer_all_onesp (TREE_REALPART (expr))
3066 : 270707573 : && integer_all_onesp (TREE_IMAGPART (expr)))
3067 : : return true;
3068 : :
3069 : 270707497 : else if (TREE_CODE (expr) == VECTOR_CST)
3070 : 428918 : return (VECTOR_CST_NPATTERNS (expr) == 1
3071 : 413847 : && VECTOR_CST_DUPLICATE_P (expr)
3072 : 826430 : && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
3073 : :
3074 : 270278579 : else if (TREE_CODE (expr) != INTEGER_CST)
3075 : : return false;
3076 : :
3077 : 178037981 : return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED)
3078 : 356076404 : == wi::to_wide (expr));
3079 : : }
3080 : :
3081 : : /* Return true if EXPR is the integer constant minus one, or a location
3082 : : wrapper for such a constant. */
3083 : :
3084 : : bool
3085 : 196961948 : integer_minus_onep (const_tree expr)
3086 : : {
3087 : 196961948 : STRIP_ANY_LOCATION_WRAPPER (expr);
3088 : :
3089 : 196961948 : if (TREE_CODE (expr) == COMPLEX_CST)
3090 : 9060 : return (integer_all_onesp (TREE_REALPART (expr))
3091 : 9064 : && integer_zerop (TREE_IMAGPART (expr)));
3092 : : else
3093 : 196952888 : return integer_all_onesp (expr);
3094 : : }
3095 : :
3096 : : /* Return true if EXPR is an integer constant that is a power of 2 (i.e., has
3097 : : only one bit on), or a location wrapper for such a constant. */
3098 : :
3099 : : bool
3100 : 21029772 : integer_pow2p (const_tree expr)
3101 : : {
3102 : 21029772 : STRIP_ANY_LOCATION_WRAPPER (expr);
3103 : :
3104 : 21029772 : if (TREE_CODE (expr) == COMPLEX_CST
3105 : 543 : && integer_pow2p (TREE_REALPART (expr))
3106 : 21029999 : && integer_zerop (TREE_IMAGPART (expr)))
3107 : : return true;
3108 : :
3109 : 21029619 : if (TREE_CODE (expr) != INTEGER_CST)
3110 : : return false;
3111 : :
3112 : 14518665 : return wi::popcount (wi::to_wide (expr)) == 1;
3113 : : }
3114 : :
3115 : : /* Return true if EXPR is an integer constant other than zero or a
3116 : : complex constant other than zero, or a location wrapper for such a
3117 : : constant. */
3118 : :
3119 : : bool
3120 : 136476449 : integer_nonzerop (const_tree expr)
3121 : : {
3122 : 136476449 : STRIP_ANY_LOCATION_WRAPPER (expr);
3123 : :
3124 : 136476449 : return ((TREE_CODE (expr) == INTEGER_CST
3125 : 63459691 : && wi::to_wide (expr) != 0)
3126 : 150068856 : || (TREE_CODE (expr) == COMPLEX_CST
3127 : 242 : && (integer_nonzerop (TREE_REALPART (expr))
3128 : 182 : || integer_nonzerop (TREE_IMAGPART (expr)))));
3129 : : }
3130 : :
3131 : : /* Return true if EXPR is the integer constant one. For vector,
3132 : : return true if every piece is the integer constant minus one
3133 : : (representing the value TRUE).
3134 : : Also return true for location wrappers for such a constant. */
3135 : :
3136 : : bool
3137 : 1101851 : integer_truep (const_tree expr)
3138 : : {
3139 : 1101851 : STRIP_ANY_LOCATION_WRAPPER (expr);
3140 : :
3141 : 1101851 : if (TREE_CODE (expr) == VECTOR_CST)
3142 : 12480 : return integer_all_onesp (expr);
3143 : 1089371 : return integer_onep (expr);
3144 : : }
3145 : :
3146 : : /* Return true if EXPR is the fixed-point constant zero, or a location wrapper
3147 : : for such a constant. */
3148 : :
3149 : : bool
3150 : 24278126 : fixed_zerop (const_tree expr)
3151 : : {
3152 : 24278126 : STRIP_ANY_LOCATION_WRAPPER (expr);
3153 : :
3154 : 24278126 : return (TREE_CODE (expr) == FIXED_CST
3155 : 24278126 : && TREE_FIXED_CST (expr).data.is_zero ());
3156 : : }
3157 : :
3158 : : /* Return the power of two represented by a tree node known to be a
3159 : : power of two. */
3160 : :
3161 : : int
3162 : 698596 : tree_log2 (const_tree expr)
3163 : : {
3164 : 698596 : if (TREE_CODE (expr) == COMPLEX_CST)
3165 : 0 : return tree_log2 (TREE_REALPART (expr));
3166 : :
3167 : 698596 : return wi::exact_log2 (wi::to_wide (expr));
3168 : : }
3169 : :
3170 : : /* Similar, but return the largest integer Y such that 2 ** Y is less
3171 : : than or equal to EXPR. */
3172 : :
3173 : : int
3174 : 2739229 : tree_floor_log2 (const_tree expr)
3175 : : {
3176 : 2739229 : if (TREE_CODE (expr) == COMPLEX_CST)
3177 : 0 : return tree_log2 (TREE_REALPART (expr));
3178 : :
3179 : 2739229 : return wi::floor_log2 (wi::to_wide (expr));
3180 : : }
3181 : :
3182 : : /* Return number of known trailing zero bits in EXPR, or, if the value of
3183 : : EXPR is known to be zero, the precision of it's type. */
3184 : :
3185 : : unsigned int
3186 : 81746747 : tree_ctz (const_tree expr)
3187 : : {
3188 : 163491872 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
3189 : 81754193 : && !POINTER_TYPE_P (TREE_TYPE (expr)))
3190 : : return 0;
3191 : :
3192 : 81746735 : unsigned int ret1, ret2, prec = TYPE_PRECISION (TREE_TYPE (expr));
3193 : 81746735 : switch (TREE_CODE (expr))
3194 : : {
3195 : 43512847 : case INTEGER_CST:
3196 : 43512847 : ret1 = wi::ctz (wi::to_wide (expr));
3197 : 43512847 : return MIN (ret1, prec);
3198 : 12462961 : case SSA_NAME:
3199 : 12462961 : ret1 = wi::ctz (get_nonzero_bits (expr));
3200 : 12462961 : return MIN (ret1, prec);
3201 : 2008144 : case PLUS_EXPR:
3202 : 2008144 : case MINUS_EXPR:
3203 : 2008144 : case BIT_IOR_EXPR:
3204 : 2008144 : case BIT_XOR_EXPR:
3205 : 2008144 : case MIN_EXPR:
3206 : 2008144 : case MAX_EXPR:
3207 : 2008144 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3208 : 2008144 : if (ret1 == 0)
3209 : : return ret1;
3210 : 908923 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3211 : 908923 : return MIN (ret1, ret2);
3212 : 0 : case POINTER_PLUS_EXPR:
3213 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3214 : 0 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3215 : : /* Second operand is sizetype, which could be in theory
3216 : : wider than pointer's precision. Make sure we never
3217 : : return more than prec. */
3218 : 0 : ret2 = MIN (ret2, prec);
3219 : 0 : return MIN (ret1, ret2);
3220 : 270 : case BIT_AND_EXPR:
3221 : 270 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3222 : 270 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3223 : 270 : return MAX (ret1, ret2);
3224 : 11590708 : case MULT_EXPR:
3225 : 11590708 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3226 : 11590708 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3227 : 11590708 : return MIN (ret1 + ret2, prec);
3228 : 0 : case LSHIFT_EXPR:
3229 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3230 : 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3231 : 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3232 : : {
3233 : 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3234 : 0 : return MIN (ret1 + ret2, prec);
3235 : : }
3236 : : return ret1;
3237 : 0 : case RSHIFT_EXPR:
3238 : 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3239 : 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3240 : : {
3241 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3242 : 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3243 : 0 : if (ret1 > ret2)
3244 : 0 : return ret1 - ret2;
3245 : : }
3246 : : return 0;
3247 : 5730 : case TRUNC_DIV_EXPR:
3248 : 5730 : case CEIL_DIV_EXPR:
3249 : 5730 : case FLOOR_DIV_EXPR:
3250 : 5730 : case ROUND_DIV_EXPR:
3251 : 5730 : case EXACT_DIV_EXPR:
3252 : 5730 : if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
3253 : 5730 : && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) == 1)
3254 : : {
3255 : 5730 : int l = tree_log2 (TREE_OPERAND (expr, 1));
3256 : 5730 : if (l >= 0)
3257 : : {
3258 : 4576 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3259 : 4576 : ret2 = l;
3260 : 4576 : if (ret1 > ret2)
3261 : 0 : return ret1 - ret2;
3262 : : }
3263 : : }
3264 : : return 0;
3265 : 12142404 : CASE_CONVERT:
3266 : 12142404 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3267 : 12142404 : if (ret1 && ret1 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
3268 : : ret1 = prec;
3269 : 12142404 : return MIN (ret1, prec);
3270 : 0 : case SAVE_EXPR:
3271 : 0 : return tree_ctz (TREE_OPERAND (expr, 0));
3272 : 9658 : case COND_EXPR:
3273 : 9658 : ret1 = tree_ctz (TREE_OPERAND (expr, 1));
3274 : 9658 : if (ret1 == 0)
3275 : : return 0;
3276 : 186 : ret2 = tree_ctz (TREE_OPERAND (expr, 2));
3277 : 186 : return MIN (ret1, ret2);
3278 : 0 : case COMPOUND_EXPR:
3279 : 0 : return tree_ctz (TREE_OPERAND (expr, 1));
3280 : 198 : case ADDR_EXPR:
3281 : 198 : ret1 = get_pointer_alignment (CONST_CAST_TREE (expr));
3282 : 198 : if (ret1 > BITS_PER_UNIT)
3283 : : {
3284 : 198 : ret1 = ctz_hwi (ret1 / BITS_PER_UNIT);
3285 : 198 : return MIN (ret1, prec);
3286 : : }
3287 : : return 0;
3288 : : default:
3289 : : return 0;
3290 : : }
3291 : : }
3292 : :
3293 : : /* Return true if EXPR is the real constant zero. Trailing zeroes matter for
3294 : : decimal float constants, so don't return true for them.
3295 : : Also return true for location wrappers around such a constant. */
3296 : :
3297 : : bool
3298 : 562469847 : real_zerop (const_tree expr)
3299 : : {
3300 : 562469847 : STRIP_ANY_LOCATION_WRAPPER (expr);
3301 : :
3302 : 562469847 : switch (TREE_CODE (expr))
3303 : : {
3304 : 19789592 : case REAL_CST:
3305 : 19789592 : return real_equal (&TREE_REAL_CST (expr), &dconst0)
3306 : 19789592 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3307 : 44633 : case COMPLEX_CST:
3308 : 44633 : return real_zerop (TREE_REALPART (expr))
3309 : 57685 : && real_zerop (TREE_IMAGPART (expr));
3310 : 439113 : case VECTOR_CST:
3311 : 439113 : {
3312 : : /* Don't simply check for a duplicate because the predicate
3313 : : accepts both +0.0 and -0.0. */
3314 : 439113 : unsigned count = vector_cst_encoded_nelts (expr);
3315 : 471670 : for (unsigned int i = 0; i < count; ++i)
3316 : 448405 : if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3317 : : return false;
3318 : : return true;
3319 : : }
3320 : : default:
3321 : : return false;
3322 : : }
3323 : : }
3324 : :
3325 : : /* Return true if EXPR is the real constant one in real or complex form.
3326 : : Trailing zeroes matter for decimal float constants, so don't return
3327 : : true for them.
3328 : : Also return true for location wrappers around such a constant. */
3329 : :
3330 : : bool
3331 : 116565838 : real_onep (const_tree expr)
3332 : : {
3333 : 116565838 : STRIP_ANY_LOCATION_WRAPPER (expr);
3334 : :
3335 : 116565838 : switch (TREE_CODE (expr))
3336 : : {
3337 : 7439902 : case REAL_CST:
3338 : 7439902 : return real_equal (&TREE_REAL_CST (expr), &dconst1)
3339 : 7439902 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3340 : 12622 : case COMPLEX_CST:
3341 : 12622 : return real_onep (TREE_REALPART (expr))
3342 : 16111 : && real_zerop (TREE_IMAGPART (expr));
3343 : 58778 : case VECTOR_CST:
3344 : 58778 : return (VECTOR_CST_NPATTERNS (expr) == 1
3345 : 50614 : && VECTOR_CST_DUPLICATE_P (expr)
3346 : 100653 : && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3347 : : default:
3348 : : return false;
3349 : : }
3350 : : }
3351 : :
3352 : : /* Return true if EXPR is the real constant minus one. Trailing zeroes
3353 : : matter for decimal float constants, so don't return true for them.
3354 : : Also return true for location wrappers around such a constant. */
3355 : :
3356 : : bool
3357 : 117561697 : real_minus_onep (const_tree expr)
3358 : : {
3359 : 117561697 : STRIP_ANY_LOCATION_WRAPPER (expr);
3360 : :
3361 : 117561697 : switch (TREE_CODE (expr))
3362 : : {
3363 : 7376681 : case REAL_CST:
3364 : 7376681 : return real_equal (&TREE_REAL_CST (expr), &dconstm1)
3365 : 7376681 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3366 : 12602 : case COMPLEX_CST:
3367 : 12602 : return real_minus_onep (TREE_REALPART (expr))
3368 : 14974 : && real_zerop (TREE_IMAGPART (expr));
3369 : 60514 : case VECTOR_CST:
3370 : 60514 : return (VECTOR_CST_NPATTERNS (expr) == 1
3371 : 51782 : && VECTOR_CST_DUPLICATE_P (expr)
3372 : 103402 : && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3373 : : default:
3374 : : return false;
3375 : : }
3376 : : }
3377 : :
3378 : : /* Return true if T could be a floating point zero. */
3379 : :
3380 : : bool
3381 : 687620 : real_maybe_zerop (const_tree expr)
3382 : : {
3383 : 687620 : switch (TREE_CODE (expr))
3384 : : {
3385 : 471929 : case REAL_CST:
3386 : : /* Can't use real_zerop here, as it always returns false for decimal
3387 : : floats. And can't use TREE_REAL_CST (expr).cl == rvc_zero
3388 : : either, as decimal zeros are rvc_normal. */
3389 : 471929 : return real_equal (&TREE_REAL_CST (expr), &dconst0);
3390 : 0 : case COMPLEX_CST:
3391 : 0 : return (real_maybe_zerop (TREE_REALPART (expr))
3392 : 0 : || real_maybe_zerop (TREE_IMAGPART (expr)));
3393 : 0 : case VECTOR_CST:
3394 : 0 : {
3395 : 0 : unsigned count = vector_cst_encoded_nelts (expr);
3396 : 0 : for (unsigned int i = 0; i < count; ++i)
3397 : 0 : if (real_maybe_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3398 : : return true;
3399 : : return false;
3400 : : }
3401 : : default:
3402 : : /* Perhaps for SSA_NAMEs we could query frange. */
3403 : : return true;
3404 : : }
3405 : : }
3406 : :
3407 : : /* True if EXP is a constant or a cast of a constant. */
3408 : :
3409 : : bool
3410 : 3667 : really_constant_p (const_tree exp)
3411 : : {
3412 : : /* This is not quite the same as STRIP_NOPS. It does more. */
3413 : 7342 : while (CONVERT_EXPR_P (exp)
3414 : 7394 : || TREE_CODE (exp) == NON_LVALUE_EXPR)
3415 : 60 : exp = TREE_OPERAND (exp, 0);
3416 : 3667 : return TREE_CONSTANT (exp);
3417 : : }
3418 : :
3419 : : /* Return true if T holds a polynomial pointer difference, storing it in
3420 : : *VALUE if so. A true return means that T's precision is no greater
3421 : : than 64 bits, which is the largest address space we support, so *VALUE
3422 : : never loses precision. However, the signedness of the result does
3423 : : not necessarily match the signedness of T: sometimes an unsigned type
3424 : : like sizetype is used to encode a value that is actually negative. */
3425 : :
3426 : : bool
3427 : 10873253 : ptrdiff_tree_p (const_tree t, poly_int64 *value)
3428 : : {
3429 : 10873253 : if (!t)
3430 : : return false;
3431 : 10873253 : if (TREE_CODE (t) == INTEGER_CST)
3432 : : {
3433 : 3156572 : if (!cst_and_fits_in_hwi (t))
3434 : : return false;
3435 : 3155810 : *value = int_cst_value (t);
3436 : 3155810 : return true;
3437 : : }
3438 : : if (POLY_INT_CST_P (t))
3439 : : {
3440 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3441 : : if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t, i)))
3442 : : return false;
3443 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3444 : : value->coeffs[i] = int_cst_value (POLY_INT_CST_COEFF (t, i));
3445 : : return true;
3446 : : }
3447 : : return false;
3448 : : }
3449 : :
3450 : : poly_int64
3451 : 428100149 : tree_to_poly_int64 (const_tree t)
3452 : : {
3453 : 428100149 : gcc_assert (tree_fits_poly_int64_p (t));
3454 : 428100149 : if (POLY_INT_CST_P (t))
3455 : : return poly_int_cst_value (t).force_shwi ();
3456 : 428100149 : return TREE_INT_CST_LOW (t);
3457 : : }
3458 : :
3459 : : poly_uint64
3460 : 454475955 : tree_to_poly_uint64 (const_tree t)
3461 : : {
3462 : 454475955 : gcc_assert (tree_fits_poly_uint64_p (t));
3463 : 454475955 : if (POLY_INT_CST_P (t))
3464 : : return poly_int_cst_value (t).force_uhwi ();
3465 : 454475955 : return TREE_INT_CST_LOW (t);
3466 : : }
3467 : :
3468 : : /* Return first list element whose TREE_VALUE is ELEM.
3469 : : Return 0 if ELEM is not in LIST. */
3470 : :
3471 : : tree
3472 : 7929298 : value_member (tree elem, tree list)
3473 : : {
3474 : 23188305 : while (list)
3475 : : {
3476 : 20149751 : if (elem == TREE_VALUE (list))
3477 : : return list;
3478 : 15259007 : list = TREE_CHAIN (list);
3479 : : }
3480 : : return NULL_TREE;
3481 : : }
3482 : :
3483 : : /* Return first list element whose TREE_PURPOSE is ELEM.
3484 : : Return 0 if ELEM is not in LIST. */
3485 : :
3486 : : tree
3487 : 142968082 : purpose_member (const_tree elem, tree list)
3488 : : {
3489 : 323743998 : while (list)
3490 : : {
3491 : 194965110 : if (elem == TREE_PURPOSE (list))
3492 : : return list;
3493 : 180775916 : list = TREE_CHAIN (list);
3494 : : }
3495 : : return NULL_TREE;
3496 : : }
3497 : :
3498 : : /* Return true if ELEM is in V. */
3499 : :
3500 : : bool
3501 : 1937141 : vec_member (const_tree elem, vec<tree, va_gc> *v)
3502 : : {
3503 : 1937141 : unsigned ix;
3504 : 1937141 : tree t;
3505 : 3520148 : FOR_EACH_VEC_SAFE_ELT (v, ix, t)
3506 : 1585294 : if (elem == t)
3507 : : return true;
3508 : : return false;
3509 : : }
3510 : :
3511 : : /* Returns element number IDX (zero-origin) of chain CHAIN, or
3512 : : NULL_TREE. */
3513 : :
3514 : : tree
3515 : 18012870 : chain_index (int idx, tree chain)
3516 : : {
3517 : 23055985 : for (; chain && idx > 0; --idx)
3518 : 5043115 : chain = TREE_CHAIN (chain);
3519 : 18012870 : return chain;
3520 : : }
3521 : :
3522 : : /* Return true if ELEM is part of the chain CHAIN. */
3523 : :
3524 : : bool
3525 : 183909 : chain_member (const_tree elem, const_tree chain)
3526 : : {
3527 : 359302 : while (chain)
3528 : : {
3529 : 357994 : if (elem == chain)
3530 : : return true;
3531 : 175393 : chain = DECL_CHAIN (chain);
3532 : : }
3533 : :
3534 : : return false;
3535 : : }
3536 : :
3537 : : /* Return the length of a chain of nodes chained through TREE_CHAIN.
3538 : : We expect a null pointer to mark the end of the chain.
3539 : : This is the Lisp primitive `length'. */
3540 : :
3541 : : int
3542 : 1904998031 : list_length (const_tree t)
3543 : : {
3544 : 1904998031 : const_tree p = t;
3545 : : #ifdef ENABLE_TREE_CHECKING
3546 : 1904998031 : const_tree q = t;
3547 : : #endif
3548 : 1904998031 : int len = 0;
3549 : :
3550 : 3019586456 : while (p)
3551 : : {
3552 : 1114588425 : p = TREE_CHAIN (p);
3553 : : #ifdef ENABLE_TREE_CHECKING
3554 : 1114588425 : if (len % 2)
3555 : 360950610 : q = TREE_CHAIN (q);
3556 : 1114588425 : gcc_assert (p != q);
3557 : : #endif
3558 : 1114588425 : len++;
3559 : : }
3560 : :
3561 : 1904998031 : return len;
3562 : : }
3563 : :
3564 : : /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3565 : : UNION_TYPE TYPE, or NULL_TREE if none. */
3566 : :
3567 : : tree
3568 : 60592 : first_field (const_tree type)
3569 : : {
3570 : 60592 : tree t = TYPE_FIELDS (type);
3571 : 3015360 : while (t && TREE_CODE (t) != FIELD_DECL)
3572 : 2954768 : t = TREE_CHAIN (t);
3573 : 60592 : return t;
3574 : : }
3575 : :
3576 : : /* Returns the last FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3577 : : UNION_TYPE TYPE, or NULL_TREE if none. */
3578 : :
3579 : : tree
3580 : 2755349 : last_field (const_tree type)
3581 : : {
3582 : 2755349 : tree last = NULL_TREE;
3583 : :
3584 : 63678912 : for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
3585 : : {
3586 : 60923563 : if (TREE_CODE (fld) != FIELD_DECL)
3587 : 52422709 : continue;
3588 : :
3589 : : last = fld;
3590 : : }
3591 : :
3592 : 2755349 : return last;
3593 : : }
3594 : :
3595 : : /* Concatenate two chains of nodes (chained through TREE_CHAIN)
3596 : : by modifying the last node in chain 1 to point to chain 2.
3597 : : This is the Lisp primitive `nconc'. */
3598 : :
3599 : : tree
3600 : 3900078995 : chainon (tree op1, tree op2)
3601 : : {
3602 : 3900078995 : tree t1;
3603 : :
3604 : 3900078995 : if (!op1)
3605 : : return op2;
3606 : 708951054 : if (!op2)
3607 : : return op1;
3608 : :
3609 : 1465091543 : for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
3610 : 829986788 : continue;
3611 : 635104755 : TREE_CHAIN (t1) = op2;
3612 : :
3613 : : #ifdef ENABLE_TREE_CHECKING
3614 : 635104755 : {
3615 : 635104755 : tree t2;
3616 : 1655449839 : for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
3617 : 1020345084 : gcc_assert (t2 != t1);
3618 : : }
3619 : : #endif
3620 : :
3621 : : return op1;
3622 : 829986788 : }
3623 : :
3624 : : /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
3625 : :
3626 : : tree
3627 : 92628638 : tree_last (tree chain)
3628 : : {
3629 : 92628638 : tree next;
3630 : 92628638 : if (chain)
3631 : 174034487 : while ((next = TREE_CHAIN (chain)))
3632 : : chain = next;
3633 : 92628638 : return chain;
3634 : : }
3635 : :
3636 : : /* Reverse the order of elements in the chain T,
3637 : : and return the new head of the chain (old last element). */
3638 : :
3639 : : tree
3640 : 1335938732 : nreverse (tree t)
3641 : : {
3642 : 1335938732 : tree prev = 0, decl, next;
3643 : 3434204597 : for (decl = t; decl; decl = next)
3644 : : {
3645 : : /* We shouldn't be using this function to reverse BLOCK chains; we
3646 : : have blocks_nreverse for that. */
3647 : 2098265865 : gcc_checking_assert (TREE_CODE (decl) != BLOCK);
3648 : 2098265865 : next = TREE_CHAIN (decl);
3649 : 2098265865 : TREE_CHAIN (decl) = prev;
3650 : 2098265865 : prev = decl;
3651 : : }
3652 : 1335938732 : return prev;
3653 : : }
3654 : :
3655 : : /* Return a newly created TREE_LIST node whose
3656 : : purpose and value fields are PARM and VALUE. */
3657 : :
3658 : : tree
3659 : 1243547201 : build_tree_list (tree parm, tree value MEM_STAT_DECL)
3660 : : {
3661 : 1243547201 : tree t = make_node (TREE_LIST PASS_MEM_STAT);
3662 : 1243547201 : TREE_PURPOSE (t) = parm;
3663 : 1243547201 : TREE_VALUE (t) = value;
3664 : 1243547201 : return t;
3665 : : }
3666 : :
3667 : : /* Build a chain of TREE_LIST nodes from a vector. */
3668 : :
3669 : : tree
3670 : 83623151 : build_tree_list_vec (const vec<tree, va_gc> *vec MEM_STAT_DECL)
3671 : : {
3672 : 83623151 : tree ret = NULL_TREE;
3673 : 83623151 : tree *pp = &ret;
3674 : 83623151 : unsigned int i;
3675 : 83623151 : tree t;
3676 : 176579197 : FOR_EACH_VEC_SAFE_ELT (vec, i, t)
3677 : : {
3678 : 92956046 : *pp = build_tree_list (NULL, t PASS_MEM_STAT);
3679 : 92956046 : pp = &TREE_CHAIN (*pp);
3680 : : }
3681 : 83623151 : return ret;
3682 : : }
3683 : :
3684 : : /* Return a newly created TREE_LIST node whose
3685 : : purpose and value fields are PURPOSE and VALUE
3686 : : and whose TREE_CHAIN is CHAIN. */
3687 : :
3688 : : tree
3689 : 4962680182 : tree_cons (tree purpose, tree value, tree chain MEM_STAT_DECL)
3690 : : {
3691 : 4962680182 : tree node;
3692 : :
3693 : 4962680182 : node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT);
3694 : 4962680182 : memset (node, 0, sizeof (struct tree_common));
3695 : :
3696 : 4962680182 : record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
3697 : :
3698 : 4962680182 : TREE_SET_CODE (node, TREE_LIST);
3699 : 4962680182 : TREE_CHAIN (node) = chain;
3700 : 4962680182 : TREE_PURPOSE (node) = purpose;
3701 : 4962680182 : TREE_VALUE (node) = value;
3702 : 4962680182 : return node;
3703 : : }
3704 : :
3705 : : /* Return the values of the elements of a CONSTRUCTOR as a vector of
3706 : : trees. */
3707 : :
3708 : : vec<tree, va_gc> *
3709 : 0 : ctor_to_vec (tree ctor)
3710 : : {
3711 : 0 : vec<tree, va_gc> *vec;
3712 : 0 : vec_alloc (vec, CONSTRUCTOR_NELTS (ctor));
3713 : 0 : unsigned int ix;
3714 : 0 : tree val;
3715 : :
3716 : 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
3717 : 0 : vec->quick_push (val);
3718 : :
3719 : 0 : return vec;
3720 : : }
3721 : :
3722 : : /* Return the size nominally occupied by an object of type TYPE
3723 : : when it resides in memory. The value is measured in units of bytes,
3724 : : and its data type is that normally used for type sizes
3725 : : (which is the first type created by make_signed_type or
3726 : : make_unsigned_type). */
3727 : :
3728 : : tree
3729 : 26228683 : size_in_bytes_loc (location_t loc, const_tree type)
3730 : : {
3731 : 26228683 : tree t;
3732 : :
3733 : 26228683 : if (type == error_mark_node)
3734 : 0 : return integer_zero_node;
3735 : :
3736 : 26228683 : type = TYPE_MAIN_VARIANT (type);
3737 : 26228683 : t = TYPE_SIZE_UNIT (type);
3738 : :
3739 : 26228683 : if (t == 0)
3740 : : {
3741 : 56 : lang_hooks.types.incomplete_type_error (loc, NULL_TREE, type);
3742 : 56 : return size_zero_node;
3743 : : }
3744 : :
3745 : : return t;
3746 : : }
3747 : :
3748 : : /* Return the size of TYPE (in bytes) as a wide integer
3749 : : or return -1 if the size can vary or is larger than an integer. */
3750 : :
3751 : : HOST_WIDE_INT
3752 : 498775181 : int_size_in_bytes (const_tree type)
3753 : : {
3754 : 498775181 : tree t;
3755 : :
3756 : 498775181 : if (type == error_mark_node)
3757 : : return 0;
3758 : :
3759 : 498775181 : type = TYPE_MAIN_VARIANT (type);
3760 : 498775181 : t = TYPE_SIZE_UNIT (type);
3761 : :
3762 : 498775181 : if (t && tree_fits_uhwi_p (t))
3763 : 498724293 : return TREE_INT_CST_LOW (t);
3764 : : else
3765 : : return -1;
3766 : : }
3767 : :
3768 : : /* Return the maximum size of TYPE (in bytes) as a wide integer
3769 : : or return -1 if the size can vary or is larger than an integer. */
3770 : :
3771 : : HOST_WIDE_INT
3772 : 9121 : max_int_size_in_bytes (const_tree type)
3773 : : {
3774 : 9121 : HOST_WIDE_INT size = -1;
3775 : 9121 : tree size_tree;
3776 : :
3777 : : /* If this is an array type, check for a possible MAX_SIZE attached. */
3778 : :
3779 : 9121 : if (TREE_CODE (type) == ARRAY_TYPE)
3780 : : {
3781 : 8404 : size_tree = TYPE_ARRAY_MAX_SIZE (type);
3782 : :
3783 : 8404 : if (size_tree && tree_fits_uhwi_p (size_tree))
3784 : 0 : size = tree_to_uhwi (size_tree);
3785 : : }
3786 : :
3787 : : /* If we still haven't been able to get a size, see if the language
3788 : : can compute a maximum size. */
3789 : :
3790 : 0 : if (size == -1)
3791 : : {
3792 : 9121 : size_tree = lang_hooks.types.max_size (type);
3793 : :
3794 : 9121 : if (size_tree && tree_fits_uhwi_p (size_tree))
3795 : 0 : size = tree_to_uhwi (size_tree);
3796 : : }
3797 : :
3798 : 9121 : return size;
3799 : : }
3800 : :
3801 : : /* Return the bit position of FIELD, in bits from the start of the record.
3802 : : This is a tree of type bitsizetype. */
3803 : :
3804 : : tree
3805 : 101503553 : bit_position (const_tree field)
3806 : : {
3807 : 101503553 : return bit_from_pos (DECL_FIELD_OFFSET (field),
3808 : 101503553 : DECL_FIELD_BIT_OFFSET (field));
3809 : : }
3810 : :
3811 : : /* Return the byte position of FIELD, in bytes from the start of the record.
3812 : : This is a tree of type sizetype. */
3813 : :
3814 : : tree
3815 : 103080354 : byte_position (const_tree field)
3816 : : {
3817 : 103080354 : return byte_from_pos (DECL_FIELD_OFFSET (field),
3818 : 103080354 : DECL_FIELD_BIT_OFFSET (field));
3819 : : }
3820 : :
3821 : : /* Likewise, but return as an integer. It must be representable in
3822 : : that way (since it could be a signed value, we don't have the
3823 : : option of returning -1 like int_size_in_byte can. */
3824 : :
3825 : : HOST_WIDE_INT
3826 : 9760033 : int_byte_position (const_tree field)
3827 : : {
3828 : 9760033 : return tree_to_shwi (byte_position (field));
3829 : : }
3830 : :
3831 : : /* Return, as a tree node, the number of elements for TYPE (which is an
3832 : : ARRAY_TYPE) minus one. This counts only elements of the top array. */
3833 : :
3834 : : tree
3835 : 79822752 : array_type_nelts_minus_one (const_tree type)
3836 : : {
3837 : 79822752 : tree index_type, min, max;
3838 : :
3839 : : /* If they did it with unspecified bounds, then we should have already
3840 : : given an error about it before we got here. */
3841 : 79822752 : if (! TYPE_DOMAIN (type))
3842 : 5823253 : return error_mark_node;
3843 : :
3844 : 73999499 : index_type = TYPE_DOMAIN (type);
3845 : 73999499 : min = TYPE_MIN_VALUE (index_type);
3846 : 73999499 : max = TYPE_MAX_VALUE (index_type);
3847 : :
3848 : : /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3849 : 73999499 : if (!max)
3850 : : {
3851 : : /* zero sized arrays are represented from C FE as complete types with
3852 : : NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
3853 : : them as min 0, max -1. */
3854 : 1247764 : if (COMPLETE_TYPE_P (type)
3855 : 3127 : && integer_zerop (TYPE_SIZE (type))
3856 : 1250891 : && integer_zerop (min))
3857 : 3127 : return build_int_cst (TREE_TYPE (min), -1);
3858 : :
3859 : 1244637 : return error_mark_node;
3860 : : }
3861 : :
3862 : 72751735 : return (integer_zerop (min)
3863 : 72751735 : ? max
3864 : 1066969 : : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
3865 : : }
3866 : :
3867 : : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3868 : : (which is an ARRAY_TYPE). This counts only elements of the top
3869 : : array. */
3870 : :
3871 : : tree
3872 : 5224593 : array_type_nelts_top (tree type)
3873 : : {
3874 : 5224593 : return fold_build2_loc (input_location,
3875 : : PLUS_EXPR, sizetype,
3876 : : array_type_nelts_minus_one (type),
3877 : 5224593 : size_one_node);
3878 : : }
3879 : :
3880 : : /* If arg is static -- a reference to an object in static storage -- then
3881 : : return the object. This is not the same as the C meaning of `static'.
3882 : : If arg isn't static, return NULL. */
3883 : :
3884 : : tree
3885 : 1088301793 : staticp (tree arg)
3886 : : {
3887 : 1089206507 : switch (TREE_CODE (arg))
3888 : : {
3889 : : case FUNCTION_DECL:
3890 : : /* Nested functions are static, even though taking their address will
3891 : : involve a trampoline as we unnest the nested function and create
3892 : : the trampoline on the tree level. */
3893 : : return arg;
3894 : :
3895 : 703101227 : case VAR_DECL:
3896 : 565337661 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3897 : 182023430 : && ! DECL_THREAD_LOCAL_P (arg)
3898 : 180227193 : && ! DECL_DLLIMPORT_P (arg)
3899 : 703101227 : ? arg : NULL);
3900 : :
3901 : 577792 : case CONST_DECL:
3902 : 60 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3903 : 577792 : ? arg : NULL);
3904 : :
3905 : 0 : case CONSTRUCTOR:
3906 : 0 : return TREE_STATIC (arg) ? arg : NULL;
3907 : :
3908 : : case LABEL_DECL:
3909 : : case STRING_CST:
3910 : : return arg;
3911 : :
3912 : 661022 : case COMPONENT_REF:
3913 : : /* If the thing being referenced is not a field, then it is
3914 : : something language specific. */
3915 : 661022 : gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
3916 : :
3917 : : /* If we are referencing a bitfield, we can't evaluate an
3918 : : ADDR_EXPR at compile time and so it isn't a constant. */
3919 : 661022 : if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
3920 : : return NULL;
3921 : :
3922 : 661022 : return staticp (TREE_OPERAND (arg, 0));
3923 : :
3924 : : case BIT_FIELD_REF:
3925 : : return NULL;
3926 : :
3927 : 65979 : case INDIRECT_REF:
3928 : 65979 : return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
3929 : :
3930 : 243779 : case ARRAY_REF:
3931 : 243779 : case ARRAY_RANGE_REF:
3932 : 243779 : if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
3933 : 243779 : && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
3934 : 243436 : return staticp (TREE_OPERAND (arg, 0));
3935 : : else
3936 : : return NULL;
3937 : :
3938 : 256 : case REALPART_EXPR:
3939 : 256 : case IMAGPART_EXPR:
3940 : 256 : return staticp (TREE_OPERAND (arg, 0));
3941 : :
3942 : 930 : case COMPOUND_LITERAL_EXPR:
3943 : 930 : return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
3944 : :
3945 : : default:
3946 : : return NULL;
3947 : : }
3948 : : }
3949 : :
3950 : :
3951 : :
3952 : :
3953 : : /* Return whether OP is a DECL whose address is function-invariant. */
3954 : :
3955 : : bool
3956 : 5274420654 : decl_address_invariant_p (const_tree op)
3957 : : {
3958 : : /* The conditions below are slightly less strict than the one in
3959 : : staticp. */
3960 : :
3961 : 5274420654 : switch (TREE_CODE (op))
3962 : : {
3963 : : case PARM_DECL:
3964 : : case RESULT_DECL:
3965 : : case LABEL_DECL:
3966 : : case FUNCTION_DECL:
3967 : : return true;
3968 : :
3969 : 2991463592 : case VAR_DECL:
3970 : 2297555215 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3971 : 2169560509 : || DECL_THREAD_LOCAL_P (op)
3972 : 2169560509 : || DECL_CONTEXT (op) == current_function_decl
3973 : 2999267614 : || decl_function_context (op) == current_function_decl)
3974 : 2983659570 : return true;
3975 : : break;
3976 : :
3977 : 25165746 : case CONST_DECL:
3978 : 0 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3979 : 25165746 : || decl_function_context (op) == current_function_decl)
3980 : 25165746 : return true;
3981 : : break;
3982 : :
3983 : : default:
3984 : : break;
3985 : : }
3986 : :
3987 : : return false;
3988 : : }
3989 : :
3990 : : /* Return whether OP is a DECL whose address is interprocedural-invariant. */
3991 : :
3992 : : bool
3993 : 1752185 : decl_address_ip_invariant_p (const_tree op)
3994 : : {
3995 : : /* The conditions below are slightly less strict than the one in
3996 : : staticp. */
3997 : :
3998 : 1752185 : switch (TREE_CODE (op))
3999 : : {
4000 : : case LABEL_DECL:
4001 : : case FUNCTION_DECL:
4002 : : case STRING_CST:
4003 : : return true;
4004 : :
4005 : 1583284 : case VAR_DECL:
4006 : 1161150 : if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
4007 : 457188 : && !DECL_DLLIMPORT_P (op))
4008 : 2709380 : || DECL_THREAD_LOCAL_P (op))
4009 : 457188 : return true;
4010 : : break;
4011 : :
4012 : 52078 : case CONST_DECL:
4013 : 52078 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
4014 : : return true;
4015 : : break;
4016 : :
4017 : : default:
4018 : : break;
4019 : : }
4020 : :
4021 : : return false;
4022 : : }
4023 : :
4024 : : /* Return true if T is an object with invariant address. */
4025 : :
4026 : : bool
4027 : 20530 : address_invariant_p (tree t)
4028 : : {
4029 : 27149 : while (handled_component_p (t))
4030 : : {
4031 : 7524 : switch (TREE_CODE (t))
4032 : : {
4033 : 1377 : case ARRAY_REF:
4034 : 1377 : case ARRAY_RANGE_REF:
4035 : 1377 : if (!tree_invariant_p (TREE_OPERAND (t, 1))
4036 : 472 : || TREE_OPERAND (t, 2) != NULL_TREE
4037 : 1849 : || TREE_OPERAND (t, 3) != NULL_TREE)
4038 : : return false;
4039 : : break;
4040 : :
4041 : 6000 : case COMPONENT_REF:
4042 : 6000 : if (TREE_OPERAND (t, 2) != NULL_TREE)
4043 : : return false;
4044 : : break;
4045 : :
4046 : : default:
4047 : : break;
4048 : : }
4049 : 6619 : t = TREE_OPERAND (t, 0);
4050 : : }
4051 : :
4052 : 19625 : STRIP_ANY_LOCATION_WRAPPER (t);
4053 : 19625 : return CONSTANT_CLASS_P (t) || decl_address_invariant_p (t);
4054 : : }
4055 : :
4056 : :
4057 : : /* Return true if T is function-invariant (internal function, does
4058 : : not handle arithmetic; that's handled in skip_simple_arithmetic and
4059 : : tree_invariant_p). */
4060 : :
4061 : : static bool
4062 : 14528576 : tree_invariant_p_1 (tree t)
4063 : : {
4064 : 14528576 : if (TREE_CONSTANT (t) || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
4065 : : return true;
4066 : :
4067 : 12568432 : switch (TREE_CODE (t))
4068 : : {
4069 : : case SAVE_EXPR:
4070 : : case TARGET_EXPR:
4071 : : return true;
4072 : :
4073 : 20490 : case ADDR_EXPR:
4074 : 20490 : return address_invariant_p (TREE_OPERAND (t, 0));
4075 : :
4076 : : default:
4077 : : break;
4078 : : }
4079 : :
4080 : : return false;
4081 : : }
4082 : :
4083 : : /* Return true if T is function-invariant. */
4084 : :
4085 : : bool
4086 : 11772212 : tree_invariant_p (tree t)
4087 : : {
4088 : 11772212 : tree inner = skip_simple_arithmetic (t);
4089 : 11772212 : return tree_invariant_p_1 (inner);
4090 : : }
4091 : :
4092 : : /* Wrap a SAVE_EXPR around EXPR, if appropriate.
4093 : : Do this to any expression which may be used in more than one place,
4094 : : but must be evaluated only once.
4095 : :
4096 : : Normally, expand_expr would reevaluate the expression each time.
4097 : : Calling save_expr produces something that is evaluated and recorded
4098 : : the first time expand_expr is called on it. Subsequent calls to
4099 : : expand_expr just reuse the recorded value.
4100 : :
4101 : : The call to expand_expr that generates code that actually computes
4102 : : the value is the first call *at compile time*. Subsequent calls
4103 : : *at compile time* generate code to use the saved value.
4104 : : This produces correct result provided that *at run time* control
4105 : : always flows through the insns made by the first expand_expr
4106 : : before reaching the other places where the save_expr was evaluated.
4107 : : You, the caller of save_expr, must make sure this is so.
4108 : :
4109 : : Constants, and certain read-only nodes, are returned with no
4110 : : SAVE_EXPR because that is safe. Expressions containing placeholders
4111 : : are not touched; see tree.def for an explanation of what these
4112 : : are used for. */
4113 : :
4114 : : tree
4115 : 2756375 : save_expr (tree expr)
4116 : : {
4117 : 2756375 : tree inner;
4118 : :
4119 : : /* If the tree evaluates to a constant, then we don't want to hide that
4120 : : fact (i.e. this allows further folding, and direct checks for constants).
4121 : : However, a read-only object that has side effects cannot be bypassed.
4122 : : Since it is no problem to reevaluate literals, we just return the
4123 : : literal node. */
4124 : 2756375 : inner = skip_simple_arithmetic (expr);
4125 : 2756375 : if (TREE_CODE (inner) == ERROR_MARK)
4126 : : return inner;
4127 : :
4128 : 2756364 : if (tree_invariant_p_1 (inner))
4129 : : return expr;
4130 : :
4131 : : /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
4132 : : it means that the size or offset of some field of an object depends on
4133 : : the value within another field.
4134 : :
4135 : : Note that it must not be the case that EXPR contains both a PLACEHOLDER_EXPR
4136 : : and some variable since it would then need to be both evaluated once and
4137 : : evaluated more than once. Front-ends must assure this case cannot
4138 : : happen by surrounding any such subexpressions in their own SAVE_EXPR
4139 : : and forcing evaluation at the proper time. */
4140 : 2039137 : if (contains_placeholder_p (inner))
4141 : : return expr;
4142 : :
4143 : 2039137 : expr = build1_loc (EXPR_LOCATION (expr), SAVE_EXPR, TREE_TYPE (expr), expr);
4144 : :
4145 : : /* This expression might be placed ahead of a jump to ensure that the
4146 : : value was computed on both sides of the jump. So make sure it isn't
4147 : : eliminated as dead. */
4148 : 2039137 : TREE_SIDE_EFFECTS (expr) = 1;
4149 : 2039137 : return expr;
4150 : : }
4151 : :
4152 : : /* Look inside EXPR into any simple arithmetic operations. Return the
4153 : : outermost non-arithmetic or non-invariant node. */
4154 : :
4155 : : tree
4156 : 14528587 : skip_simple_arithmetic (tree expr)
4157 : : {
4158 : : /* We don't care about whether this can be used as an lvalue in this
4159 : : context. */
4160 : 14538993 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4161 : 10406 : expr = TREE_OPERAND (expr, 0);
4162 : :
4163 : : /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
4164 : : a constant, it will be more efficient to not make another SAVE_EXPR since
4165 : : it will allow better simplification and GCSE will be able to merge the
4166 : : computations if they actually occur. */
4167 : 38551806 : while (true)
4168 : : {
4169 : 38551806 : if (UNARY_CLASS_P (expr))
4170 : 14873885 : expr = TREE_OPERAND (expr, 0);
4171 : 23677921 : else if (BINARY_CLASS_P (expr))
4172 : : {
4173 : : /* Before commutative binary operands are canonicalized,
4174 : : it is quite common to have constants in the first operand.
4175 : : Check for that common case first so that we don't walk
4176 : : large expressions with tree_invariant_p unnecessarily.
4177 : : This can still have terrible compile time complexity,
4178 : : we should limit the depth of the tree_invariant_p and
4179 : : skip_simple_arithmetic recursion. */
4180 : 9214937 : if ((TREE_CONSTANT (TREE_OPERAND (expr, 0))
4181 : 9204748 : || (TREE_READONLY (TREE_OPERAND (expr, 0))
4182 : 9880 : && !TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0))))
4183 : 9224781 : && tree_invariant_p (TREE_OPERAND (expr, 0)))
4184 : 20033 : expr = TREE_OPERAND (expr, 1);
4185 : 9194904 : else if (tree_invariant_p (TREE_OPERAND (expr, 1)))
4186 : 9119823 : expr = TREE_OPERAND (expr, 0);
4187 : 75081 : else if (tree_invariant_p (TREE_OPERAND (expr, 0)))
4188 : 9478 : expr = TREE_OPERAND (expr, 1);
4189 : : else
4190 : : break;
4191 : : }
4192 : : else
4193 : : break;
4194 : : }
4195 : :
4196 : 14528587 : return expr;
4197 : : }
4198 : :
4199 : : /* Look inside EXPR into simple arithmetic operations involving constants.
4200 : : Return the outermost non-arithmetic or non-constant node. */
4201 : :
4202 : : tree
4203 : 0 : skip_simple_constant_arithmetic (tree expr)
4204 : : {
4205 : 0 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4206 : 0 : expr = TREE_OPERAND (expr, 0);
4207 : :
4208 : 0 : while (true)
4209 : : {
4210 : 0 : if (UNARY_CLASS_P (expr))
4211 : 0 : expr = TREE_OPERAND (expr, 0);
4212 : 0 : else if (BINARY_CLASS_P (expr))
4213 : : {
4214 : 0 : if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
4215 : 0 : expr = TREE_OPERAND (expr, 0);
4216 : 0 : else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
4217 : 0 : expr = TREE_OPERAND (expr, 1);
4218 : : else
4219 : : break;
4220 : : }
4221 : : else
4222 : : break;
4223 : : }
4224 : :
4225 : 0 : return expr;
4226 : : }
4227 : :
4228 : : /* Return which tree structure is used by T. */
4229 : :
4230 : : enum tree_node_structure_enum
4231 : 36709014796 : tree_node_structure (const_tree t)
4232 : : {
4233 : 36709014796 : const enum tree_code code = TREE_CODE (t);
4234 : 36709014796 : return tree_node_structure_for_code (code);
4235 : : }
4236 : :
4237 : : /* Set various status flags when building a CALL_EXPR object T. */
4238 : :
4239 : : static void
4240 : 238385007 : process_call_operands (tree t)
4241 : : {
4242 : 238385007 : bool side_effects = TREE_SIDE_EFFECTS (t);
4243 : 238385007 : bool read_only = false;
4244 : 238385007 : int i = call_expr_flags (t);
4245 : :
4246 : : /* Calls have side-effects, except those to const or pure functions. */
4247 : 238385007 : if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
4248 : : side_effects = true;
4249 : : /* Propagate TREE_READONLY of arguments for const functions. */
4250 : 52993744 : if (i & ECF_CONST)
4251 : 51352905 : read_only = true;
4252 : :
4253 : 238385007 : if (!side_effects || read_only)
4254 : 273388099 : for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
4255 : : {
4256 : 220394859 : tree op = TREE_OPERAND (t, i);
4257 : 220394859 : if (op && TREE_SIDE_EFFECTS (op))
4258 : : side_effects = true;
4259 : 220394859 : if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
4260 : : read_only = false;
4261 : : }
4262 : :
4263 : 238385007 : TREE_SIDE_EFFECTS (t) = side_effects;
4264 : 238385007 : TREE_READONLY (t) = read_only;
4265 : 238385007 : }
4266 : :
4267 : : /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
4268 : : size or offset that depends on a field within a record. */
4269 : :
4270 : : bool
4271 : 37881605 : contains_placeholder_p (const_tree exp)
4272 : : {
4273 : 37881605 : enum tree_code code;
4274 : :
4275 : 37881605 : if (!exp)
4276 : : return false;
4277 : :
4278 : 37881605 : code = TREE_CODE (exp);
4279 : 37881605 : if (code == PLACEHOLDER_EXPR)
4280 : : return true;
4281 : :
4282 : 37881605 : switch (TREE_CODE_CLASS (code))
4283 : : {
4284 : 1185087 : case tcc_reference:
4285 : : /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
4286 : : position computations since they will be converted into a
4287 : : WITH_RECORD_EXPR involving the reference, which will assume
4288 : : here will be valid. */
4289 : 1185087 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4290 : :
4291 : 538449 : case tcc_exceptional:
4292 : 538449 : if (code == TREE_LIST)
4293 : 0 : return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
4294 : 0 : || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
4295 : : break;
4296 : :
4297 : 33599099 : case tcc_unary:
4298 : 33599099 : case tcc_binary:
4299 : 33599099 : case tcc_comparison:
4300 : 33599099 : case tcc_expression:
4301 : 33599099 : switch (code)
4302 : : {
4303 : 6262 : case COMPOUND_EXPR:
4304 : : /* Ignoring the first operand isn't quite right, but works best. */
4305 : 6262 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
4306 : :
4307 : 4482 : case COND_EXPR:
4308 : 8964 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4309 : 4482 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
4310 : 8964 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
4311 : :
4312 : : case SAVE_EXPR:
4313 : : /* The save_expr function never wraps anything containing
4314 : : a PLACEHOLDER_EXPR. */
4315 : : return false;
4316 : :
4317 : 24335178 : default:
4318 : 24335178 : break;
4319 : : }
4320 : :
4321 : 24335178 : switch (TREE_CODE_LENGTH (code))
4322 : : {
4323 : 14839293 : case 1:
4324 : 14839293 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4325 : 9478385 : case 2:
4326 : 18955259 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4327 : 18955259 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
4328 : : default:
4329 : : return false;
4330 : : }
4331 : :
4332 : 455081 : case tcc_vl_exp:
4333 : 455081 : switch (code)
4334 : : {
4335 : 455081 : case CALL_EXPR:
4336 : 455081 : {
4337 : 455081 : const_tree arg;
4338 : 455081 : const_call_expr_arg_iterator iter;
4339 : 1502782 : FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
4340 : 592620 : if (CONTAINS_PLACEHOLDER_P (arg))
4341 : : return true;
4342 : : return false;
4343 : : }
4344 : : default:
4345 : : return false;
4346 : : }
4347 : :
4348 : : default:
4349 : : return false;
4350 : : }
4351 : : return false;
4352 : : }
4353 : :
4354 : : /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
4355 : : directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
4356 : : field positions. */
4357 : :
4358 : : static bool
4359 : 798488 : type_contains_placeholder_1 (const_tree type)
4360 : : {
4361 : : /* If the size contains a placeholder or the parent type (component type in
4362 : : the case of arrays) type involves a placeholder, this type does. */
4363 : 1576833 : if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
4364 : 798488 : || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
4365 : 1596976 : || (!POINTER_TYPE_P (type)
4366 : 659452 : && TREE_TYPE (type)
4367 : 108596 : && type_contains_placeholder_p (TREE_TYPE (type))))
4368 : 0 : return true;
4369 : :
4370 : : /* Now do type-specific checks. Note that the last part of the check above
4371 : : greatly limits what we have to do below. */
4372 : 798488 : switch (TREE_CODE (type))
4373 : : {
4374 : : case VOID_TYPE:
4375 : : case OPAQUE_TYPE:
4376 : : case COMPLEX_TYPE:
4377 : : case ENUMERAL_TYPE:
4378 : : case BOOLEAN_TYPE:
4379 : : case POINTER_TYPE:
4380 : : case OFFSET_TYPE:
4381 : : case REFERENCE_TYPE:
4382 : : case METHOD_TYPE:
4383 : : case FUNCTION_TYPE:
4384 : : case VECTOR_TYPE:
4385 : : case NULLPTR_TYPE:
4386 : : return false;
4387 : :
4388 : 173349 : case INTEGER_TYPE:
4389 : 173349 : case BITINT_TYPE:
4390 : 173349 : case REAL_TYPE:
4391 : 173349 : case FIXED_POINT_TYPE:
4392 : : /* Here we just check the bounds. */
4393 : 336947 : return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
4394 : 336947 : || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
4395 : :
4396 : 56424 : case ARRAY_TYPE:
4397 : : /* We have already checked the component type above, so just check
4398 : : the domain type. Flexible array members have a null domain. */
4399 : 112836 : return TYPE_DOMAIN (type) ?
4400 : 56412 : type_contains_placeholder_p (TYPE_DOMAIN (type)) : false;
4401 : :
4402 : 405634 : case RECORD_TYPE:
4403 : 405634 : case UNION_TYPE:
4404 : 405634 : case QUAL_UNION_TYPE:
4405 : 405634 : {
4406 : 405634 : tree field;
4407 : :
4408 : 12114058 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4409 : 11708424 : if (TREE_CODE (field) == FIELD_DECL
4410 : 11708424 : && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
4411 : 938091 : || (TREE_CODE (type) == QUAL_UNION_TYPE
4412 : 0 : && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
4413 : 938091 : || type_contains_placeholder_p (TREE_TYPE (field))))
4414 : 0 : return true;
4415 : :
4416 : : return false;
4417 : : }
4418 : :
4419 : 0 : default:
4420 : 0 : gcc_unreachable ();
4421 : : }
4422 : : }
4423 : :
4424 : : /* Wrapper around above function used to cache its result. */
4425 : :
4426 : : bool
4427 : 3034345 : type_contains_placeholder_p (tree type)
4428 : : {
4429 : 3034345 : bool result;
4430 : :
4431 : : /* If the contains_placeholder_bits field has been initialized,
4432 : : then we know the answer. */
4433 : 3034345 : if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
4434 : 2235857 : return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
4435 : :
4436 : : /* Indicate that we've seen this type node, and the answer is false.
4437 : : This is what we want to return if we run into recursion via fields. */
4438 : 798488 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
4439 : :
4440 : : /* Compute the real value. */
4441 : 798488 : result = type_contains_placeholder_1 (type);
4442 : :
4443 : : /* Store the real value. */
4444 : 798488 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
4445 : :
4446 : 798488 : return result;
4447 : : }
4448 : :
4449 : : /* Push tree EXP onto vector QUEUE if it is not already present. */
4450 : :
4451 : : static void
4452 : 0 : push_without_duplicates (tree exp, vec<tree> *queue)
4453 : : {
4454 : 0 : unsigned int i;
4455 : 0 : tree iter;
4456 : :
4457 : 0 : FOR_EACH_VEC_ELT (*queue, i, iter)
4458 : 0 : if (simple_cst_equal (iter, exp) == 1)
4459 : : break;
4460 : :
4461 : 0 : if (!iter)
4462 : 0 : queue->safe_push (exp);
4463 : 0 : }
4464 : :
4465 : : /* Given a tree EXP, find all occurrences of references to fields
4466 : : in a PLACEHOLDER_EXPR and place them in vector REFS without
4467 : : duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
4468 : : we assume here that EXP contains only arithmetic expressions
4469 : : or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
4470 : : argument list. */
4471 : :
4472 : : void
4473 : 0 : find_placeholder_in_expr (tree exp, vec<tree> *refs)
4474 : : {
4475 : 0 : enum tree_code code = TREE_CODE (exp);
4476 : 0 : tree inner;
4477 : 0 : int i;
4478 : :
4479 : : /* We handle TREE_LIST and COMPONENT_REF separately. */
4480 : 0 : if (code == TREE_LIST)
4481 : : {
4482 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
4483 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
4484 : : }
4485 : 0 : else if (code == COMPONENT_REF)
4486 : : {
4487 : 0 : for (inner = TREE_OPERAND (exp, 0);
4488 : 0 : REFERENCE_CLASS_P (inner);
4489 : 0 : inner = TREE_OPERAND (inner, 0))
4490 : : ;
4491 : :
4492 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
4493 : 0 : push_without_duplicates (exp, refs);
4494 : : else
4495 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
4496 : : }
4497 : : else
4498 : 0 : switch (TREE_CODE_CLASS (code))
4499 : : {
4500 : : case tcc_constant:
4501 : : break;
4502 : :
4503 : 0 : case tcc_declaration:
4504 : : /* Variables allocated to static storage can stay. */
4505 : 0 : if (!TREE_STATIC (exp))
4506 : 0 : push_without_duplicates (exp, refs);
4507 : : break;
4508 : :
4509 : 0 : case tcc_expression:
4510 : : /* This is the pattern built in ada/make_aligning_type. */
4511 : 0 : if (code == ADDR_EXPR
4512 : 0 : && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
4513 : : {
4514 : 0 : push_without_duplicates (exp, refs);
4515 : 0 : break;
4516 : : }
4517 : :
4518 : : /* Fall through. */
4519 : :
4520 : : case tcc_exceptional:
4521 : : case tcc_unary:
4522 : : case tcc_binary:
4523 : : case tcc_comparison:
4524 : : case tcc_reference:
4525 : 0 : for (i = 0; i < TREE_CODE_LENGTH (code); i++)
4526 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4527 : : break;
4528 : :
4529 : : case tcc_vl_exp:
4530 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4531 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4532 : : break;
4533 : :
4534 : 0 : default:
4535 : 0 : gcc_unreachable ();
4536 : : }
4537 : 0 : }
4538 : :
4539 : : /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
4540 : : return a tree with all occurrences of references to F in a
4541 : : PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
4542 : : CONST_DECLs. Note that we assume here that EXP contains only
4543 : : arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
4544 : : occurring only in their argument list. */
4545 : :
4546 : : tree
4547 : 0 : substitute_in_expr (tree exp, tree f, tree r)
4548 : : {
4549 : 0 : enum tree_code code = TREE_CODE (exp);
4550 : 0 : tree op0, op1, op2, op3;
4551 : 0 : tree new_tree;
4552 : :
4553 : : /* We handle TREE_LIST and COMPONENT_REF separately. */
4554 : 0 : if (code == TREE_LIST)
4555 : : {
4556 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
4557 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
4558 : 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4559 : : return exp;
4560 : :
4561 : 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4562 : : }
4563 : 0 : else if (code == COMPONENT_REF)
4564 : : {
4565 : 0 : tree inner;
4566 : :
4567 : : /* If this expression is getting a value from a PLACEHOLDER_EXPR
4568 : : and it is the right field, replace it with R. */
4569 : 0 : for (inner = TREE_OPERAND (exp, 0);
4570 : 0 : REFERENCE_CLASS_P (inner);
4571 : 0 : inner = TREE_OPERAND (inner, 0))
4572 : : ;
4573 : :
4574 : : /* The field. */
4575 : 0 : op1 = TREE_OPERAND (exp, 1);
4576 : :
4577 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
4578 : : return r;
4579 : :
4580 : : /* If this expression hasn't been completed let, leave it alone. */
4581 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
4582 : : return exp;
4583 : :
4584 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4585 : 0 : if (op0 == TREE_OPERAND (exp, 0))
4586 : : return exp;
4587 : :
4588 : 0 : new_tree
4589 : 0 : = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
4590 : : }
4591 : : else
4592 : 0 : switch (TREE_CODE_CLASS (code))
4593 : : {
4594 : : case tcc_constant:
4595 : : return exp;
4596 : :
4597 : 0 : case tcc_declaration:
4598 : 0 : if (exp == f)
4599 : : return r;
4600 : : else
4601 : : return exp;
4602 : :
4603 : 0 : case tcc_expression:
4604 : 0 : if (exp == f)
4605 : : return r;
4606 : :
4607 : : /* Fall through. */
4608 : :
4609 : 0 : case tcc_exceptional:
4610 : 0 : case tcc_unary:
4611 : 0 : case tcc_binary:
4612 : 0 : case tcc_comparison:
4613 : 0 : case tcc_reference:
4614 : 0 : switch (TREE_CODE_LENGTH (code))
4615 : : {
4616 : : case 0:
4617 : : return exp;
4618 : :
4619 : 0 : case 1:
4620 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4621 : 0 : if (op0 == TREE_OPERAND (exp, 0))
4622 : : return exp;
4623 : :
4624 : 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4625 : 0 : break;
4626 : :
4627 : 0 : case 2:
4628 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4629 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4630 : :
4631 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4632 : : return exp;
4633 : :
4634 : 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4635 : 0 : break;
4636 : :
4637 : 0 : case 3:
4638 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4639 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4640 : 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4641 : :
4642 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4643 : 0 : && op2 == TREE_OPERAND (exp, 2))
4644 : : return exp;
4645 : :
4646 : 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4647 : 0 : break;
4648 : :
4649 : 0 : case 4:
4650 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4651 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4652 : 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4653 : 0 : op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
4654 : :
4655 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4656 : 0 : && op2 == TREE_OPERAND (exp, 2)
4657 : 0 : && op3 == TREE_OPERAND (exp, 3))
4658 : : return exp;
4659 : :
4660 : 0 : new_tree
4661 : 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4662 : 0 : break;
4663 : :
4664 : 0 : default:
4665 : 0 : gcc_unreachable ();
4666 : : }
4667 : : break;
4668 : :
4669 : 0 : case tcc_vl_exp:
4670 : 0 : {
4671 : 0 : int i;
4672 : :
4673 : 0 : new_tree = NULL_TREE;
4674 : :
4675 : : /* If we are trying to replace F with a constant or with another
4676 : : instance of one of the arguments of the call, inline back
4677 : : functions which do nothing else than computing a value from
4678 : : the arguments they are passed. This makes it possible to
4679 : : fold partially or entirely the replacement expression. */
4680 : 0 : if (code == CALL_EXPR)
4681 : : {
4682 : 0 : bool maybe_inline = false;
4683 : 0 : if (CONSTANT_CLASS_P (r))
4684 : : maybe_inline = true;
4685 : : else
4686 : 0 : for (i = 3; i < TREE_OPERAND_LENGTH (exp); i++)
4687 : 0 : if (operand_equal_p (TREE_OPERAND (exp, i), r, 0))
4688 : : {
4689 : : maybe_inline = true;
4690 : : break;
4691 : : }
4692 : 0 : if (maybe_inline)
4693 : : {
4694 : 0 : tree t = maybe_inline_call_in_expr (exp);
4695 : 0 : if (t)
4696 : 0 : return SUBSTITUTE_IN_EXPR (t, f, r);
4697 : : }
4698 : : }
4699 : :
4700 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4701 : : {
4702 : 0 : tree op = TREE_OPERAND (exp, i);
4703 : 0 : tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
4704 : 0 : if (new_op != op)
4705 : : {
4706 : 0 : if (!new_tree)
4707 : 0 : new_tree = copy_node (exp);
4708 : 0 : TREE_OPERAND (new_tree, i) = new_op;
4709 : : }
4710 : : }
4711 : :
4712 : 0 : if (new_tree)
4713 : : {
4714 : 0 : new_tree = fold (new_tree);
4715 : 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4716 : 0 : process_call_operands (new_tree);
4717 : : }
4718 : : else
4719 : : return exp;
4720 : : }
4721 : : break;
4722 : :
4723 : 0 : default:
4724 : 0 : gcc_unreachable ();
4725 : : }
4726 : :
4727 : 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4728 : :
4729 : 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4730 : 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4731 : :
4732 : : return new_tree;
4733 : : }
4734 : :
4735 : : /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
4736 : : for it within OBJ, a tree that is an object or a chain of references. */
4737 : :
4738 : : tree
4739 : 210893 : substitute_placeholder_in_expr (tree exp, tree obj)
4740 : : {
4741 : 210893 : enum tree_code code = TREE_CODE (exp);
4742 : 210893 : tree op0, op1, op2, op3;
4743 : 210893 : tree new_tree;
4744 : :
4745 : : /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
4746 : : in the chain of OBJ. */
4747 : 210893 : if (code == PLACEHOLDER_EXPR)
4748 : : {
4749 : 0 : tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
4750 : 0 : tree elt;
4751 : :
4752 : 0 : for (elt = obj; elt != 0;
4753 : 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4754 : 0 : || TREE_CODE (elt) == COND_EXPR)
4755 : 0 : ? TREE_OPERAND (elt, 1)
4756 : 0 : : (REFERENCE_CLASS_P (elt)
4757 : : || UNARY_CLASS_P (elt)
4758 : : || BINARY_CLASS_P (elt)
4759 : : || VL_EXP_CLASS_P (elt)
4760 : : || EXPRESSION_CLASS_P (elt))
4761 : 0 : ? TREE_OPERAND (elt, 0) : 0))
4762 : 0 : if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
4763 : : return elt;
4764 : :
4765 : 0 : for (elt = obj; elt != 0;
4766 : 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4767 : 0 : || TREE_CODE (elt) == COND_EXPR)
4768 : 0 : ? TREE_OPERAND (elt, 1)
4769 : 0 : : (REFERENCE_CLASS_P (elt)
4770 : : || UNARY_CLASS_P (elt)
4771 : : || BINARY_CLASS_P (elt)
4772 : : || VL_EXP_CLASS_P (elt)
4773 : : || EXPRESSION_CLASS_P (elt))
4774 : 0 : ? TREE_OPERAND (elt, 0) : 0))
4775 : 0 : if (POINTER_TYPE_P (TREE_TYPE (elt))
4776 : 0 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
4777 : : == need_type))
4778 : 0 : return fold_build1 (INDIRECT_REF, need_type, elt);
4779 : :
4780 : : /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
4781 : : survives until RTL generation, there will be an error. */
4782 : : return exp;
4783 : : }
4784 : :
4785 : : /* TREE_LIST is special because we need to look at TREE_VALUE
4786 : : and TREE_CHAIN, not TREE_OPERANDS. */
4787 : 210893 : else if (code == TREE_LIST)
4788 : : {
4789 : 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
4790 : 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
4791 : 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4792 : : return exp;
4793 : :
4794 : 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4795 : : }
4796 : : else
4797 : 210893 : switch (TREE_CODE_CLASS (code))
4798 : : {
4799 : : case tcc_constant:
4800 : : case tcc_declaration:
4801 : : return exp;
4802 : :
4803 : 9509 : case tcc_exceptional:
4804 : 9509 : case tcc_unary:
4805 : 9509 : case tcc_binary:
4806 : 9509 : case tcc_comparison:
4807 : 9509 : case tcc_expression:
4808 : 9509 : case tcc_reference:
4809 : 9509 : case tcc_statement:
4810 : 9509 : switch (TREE_CODE_LENGTH (code))
4811 : : {
4812 : : case 0:
4813 : : return exp;
4814 : :
4815 : 7212 : case 1:
4816 : 7212 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4817 : 7212 : if (op0 == TREE_OPERAND (exp, 0))
4818 : : return exp;
4819 : :
4820 : 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4821 : 0 : break;
4822 : :
4823 : 2285 : case 2:
4824 : 2285 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4825 : 2285 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4826 : :
4827 : 2285 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4828 : : return exp;
4829 : :
4830 : 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4831 : 0 : break;
4832 : :
4833 : 12 : case 3:
4834 : 12 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4835 : 12 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4836 : 12 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4837 : :
4838 : 24 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4839 : 24 : && op2 == TREE_OPERAND (exp, 2))
4840 : : return exp;
4841 : :
4842 : 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4843 : 0 : break;
4844 : :
4845 : 0 : case 4:
4846 : 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4847 : 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4848 : 0 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4849 : 0 : op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
4850 : :
4851 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4852 : 0 : && op2 == TREE_OPERAND (exp, 2)
4853 : 0 : && op3 == TREE_OPERAND (exp, 3))
4854 : : return exp;
4855 : :
4856 : 0 : new_tree
4857 : 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4858 : 0 : break;
4859 : :
4860 : 0 : default:
4861 : 0 : gcc_unreachable ();
4862 : : }
4863 : : break;
4864 : :
4865 : : case tcc_vl_exp:
4866 : : {
4867 : : int i;
4868 : :
4869 : : new_tree = NULL_TREE;
4870 : :
4871 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4872 : : {
4873 : 0 : tree op = TREE_OPERAND (exp, i);
4874 : 0 : tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
4875 : 0 : if (new_op != op)
4876 : : {
4877 : 0 : if (!new_tree)
4878 : 0 : new_tree = copy_node (exp);
4879 : 0 : TREE_OPERAND (new_tree, i) = new_op;
4880 : : }
4881 : : }
4882 : :
4883 : 0 : if (new_tree)
4884 : : {
4885 : 0 : new_tree = fold (new_tree);
4886 : 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4887 : 0 : process_call_operands (new_tree);
4888 : : }
4889 : : else
4890 : : return exp;
4891 : : }
4892 : : break;
4893 : :
4894 : 0 : default:
4895 : 0 : gcc_unreachable ();
4896 : : }
4897 : :
4898 : 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4899 : :
4900 : 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4901 : 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4902 : :
4903 : : return new_tree;
4904 : : }
4905 : :
4906 : :
4907 : : /* Subroutine of stabilize_reference; this is called for subtrees of
4908 : : references. Any expression with side-effects must be put in a SAVE_EXPR
4909 : : to ensure that it is only evaluated once.
4910 : :
4911 : : We don't put SAVE_EXPR nodes around everything, because assigning very
4912 : : simple expressions to temporaries causes us to miss good opportunities
4913 : : for optimizations. Among other things, the opportunity to fold in the
4914 : : addition of a constant into an addressing mode often gets lost, e.g.
4915 : : "y[i+1] += x;". In general, we take the approach that we should not make
4916 : : an assignment unless we are forced into it - i.e., that any non-side effect
4917 : : operator should be allowed, and that cse should take care of coalescing
4918 : : multiple utterances of the same expression should that prove fruitful. */
4919 : :
4920 : : static tree
4921 : 588509 : stabilize_reference_1 (tree e)
4922 : : {
4923 : 588509 : tree result;
4924 : 588509 : enum tree_code code = TREE_CODE (e);
4925 : :
4926 : : /* We cannot ignore const expressions because it might be a reference
4927 : : to a const array but whose index contains side-effects. But we can
4928 : : ignore things that are actual constant or that already have been
4929 : : handled by this function. */
4930 : :
4931 : 588509 : if (tree_invariant_p (e))
4932 : : return e;
4933 : :
4934 : 127501 : switch (TREE_CODE_CLASS (code))
4935 : : {
4936 : 0 : case tcc_exceptional:
4937 : : /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
4938 : : have side-effects. */
4939 : 0 : if (code == STATEMENT_LIST)
4940 : 0 : return save_expr (e);
4941 : : /* FALLTHRU */
4942 : 98780 : case tcc_type:
4943 : 98780 : case tcc_declaration:
4944 : 98780 : case tcc_comparison:
4945 : 98780 : case tcc_statement:
4946 : 98780 : case tcc_expression:
4947 : 98780 : case tcc_reference:
4948 : 98780 : case tcc_vl_exp:
4949 : : /* If the expression has side-effects, then encase it in a SAVE_EXPR
4950 : : so that it will only be evaluated once. */
4951 : : /* The reference (r) and comparison (<) classes could be handled as
4952 : : below, but it is generally faster to only evaluate them once. */
4953 : 98780 : if (TREE_SIDE_EFFECTS (e))
4954 : 977 : return save_expr (e);
4955 : : return e;
4956 : :
4957 : : case tcc_constant:
4958 : : /* Constants need no processing. In fact, we should never reach
4959 : : here. */
4960 : : return e;
4961 : :
4962 : 21422 : case tcc_binary:
4963 : : /* Division is slow and tends to be compiled with jumps,
4964 : : especially the division by powers of 2 that is often
4965 : : found inside of an array reference. So do it just once. */
4966 : 21422 : if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
4967 : 19382 : || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
4968 : 19382 : || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
4969 : 19382 : || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
4970 : 2040 : return save_expr (e);
4971 : : /* Recursively stabilize each operand. */
4972 : 19382 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
4973 : 19382 : stabilize_reference_1 (TREE_OPERAND (e, 1)));
4974 : 19382 : break;
4975 : :
4976 : 7299 : case tcc_unary:
4977 : : /* Recursively stabilize each operand. */
4978 : 7299 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
4979 : 7299 : break;
4980 : :
4981 : 0 : default:
4982 : 0 : gcc_unreachable ();
4983 : : }
4984 : :
4985 : 26681 : TREE_TYPE (result) = TREE_TYPE (e);
4986 : 26681 : TREE_READONLY (result) = TREE_READONLY (e);
4987 : 26681 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
4988 : 26681 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
4989 : :
4990 : 26681 : return result;
4991 : : }
4992 : :
4993 : : /* Stabilize a reference so that we can use it any number of times
4994 : : without causing its operands to be evaluated more than once.
4995 : : Returns the stabilized reference. This works by means of save_expr,
4996 : : so see the caveats in the comments about save_expr.
4997 : :
4998 : : Also allows conversion expressions whose operands are references.
4999 : : Any other kind of expression is returned unchanged. */
5000 : :
5001 : : tree
5002 : 4228699 : stabilize_reference (tree ref)
5003 : : {
5004 : 4228699 : tree result;
5005 : 4228699 : enum tree_code code = TREE_CODE (ref);
5006 : :
5007 : 4228699 : switch (code)
5008 : : {
5009 : : case VAR_DECL:
5010 : : case PARM_DECL:
5011 : : case RESULT_DECL:
5012 : : /* No action is needed in this case. */
5013 : : return ref;
5014 : :
5015 : 0 : CASE_CONVERT:
5016 : 0 : case FLOAT_EXPR:
5017 : 0 : case FIX_TRUNC_EXPR:
5018 : 0 : result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
5019 : 0 : break;
5020 : :
5021 : 496289 : case INDIRECT_REF:
5022 : 496289 : result = build_nt (INDIRECT_REF,
5023 : 496289 : stabilize_reference_1 (TREE_OPERAND (ref, 0)));
5024 : 496289 : break;
5025 : :
5026 : 320359 : case COMPONENT_REF:
5027 : 320359 : result = build_nt (COMPONENT_REF,
5028 : 320359 : stabilize_reference (TREE_OPERAND (ref, 0)),
5029 : 320359 : TREE_OPERAND (ref, 1), NULL_TREE);
5030 : 320359 : break;
5031 : :
5032 : 0 : case BIT_FIELD_REF:
5033 : 0 : result = build_nt (BIT_FIELD_REF,
5034 : 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5035 : 0 : TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2));
5036 : 0 : REF_REVERSE_STORAGE_ORDER (result) = REF_REVERSE_STORAGE_ORDER (ref);
5037 : 0 : break;
5038 : :
5039 : 46157 : case ARRAY_REF:
5040 : 92314 : result = build_nt (ARRAY_REF,
5041 : 46157 : stabilize_reference (TREE_OPERAND (ref, 0)),
5042 : 46157 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5043 : 46157 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5044 : 46157 : break;
5045 : :
5046 : 0 : case ARRAY_RANGE_REF:
5047 : 0 : result = build_nt (ARRAY_RANGE_REF,
5048 : 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5049 : 0 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5050 : 0 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5051 : 0 : break;
5052 : :
5053 : 0 : case COMPOUND_EXPR:
5054 : : /* We cannot wrap the first expression in a SAVE_EXPR, as then
5055 : : it wouldn't be ignored. This matters when dealing with
5056 : : volatiles. */
5057 : 0 : return stabilize_reference_1 (ref);
5058 : :
5059 : : /* If arg isn't a kind of lvalue we recognize, make no change.
5060 : : Caller should recognize the error for an invalid lvalue. */
5061 : : default:
5062 : : return ref;
5063 : :
5064 : 0 : case ERROR_MARK:
5065 : 0 : return error_mark_node;
5066 : : }
5067 : :
5068 : 862805 : TREE_TYPE (result) = TREE_TYPE (ref);
5069 : 862805 : TREE_READONLY (result) = TREE_READONLY (ref);
5070 : 862805 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
5071 : 862805 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
5072 : 862805 : protected_set_expr_location (result, EXPR_LOCATION (ref));
5073 : :
5074 : 862805 : return result;
5075 : : }
5076 : :
5077 : : /* Low-level constructors for expressions. */
5078 : :
5079 : : /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
5080 : : and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
5081 : :
5082 : : void
5083 : 1280505685 : recompute_tree_invariant_for_addr_expr (tree t)
5084 : : {
5085 : 1280505685 : tree node;
5086 : 1280505685 : bool tc = true, se = false;
5087 : :
5088 : 1280505685 : gcc_assert (TREE_CODE (t) == ADDR_EXPR);
5089 : :
5090 : : /* We started out assuming this address is both invariant and constant, but
5091 : : does not have side effects. Now go down any handled components and see if
5092 : : any of them involve offsets that are either non-constant or non-invariant.
5093 : : Also check for side-effects.
5094 : :
5095 : : ??? Note that this code makes no attempt to deal with the case where
5096 : : taking the address of something causes a copy due to misalignment. */
5097 : :
5098 : : #define UPDATE_FLAGS(NODE) \
5099 : : do { tree _node = (NODE); \
5100 : : if (_node && !TREE_CONSTANT (_node)) tc = false; \
5101 : : if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
5102 : :
5103 : 1492064906 : for (node = TREE_OPERAND (t, 0); handled_component_p (node);
5104 : 211559221 : node = TREE_OPERAND (node, 0))
5105 : : {
5106 : : /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
5107 : : array reference (probably made temporarily by the G++ front end),
5108 : : so ignore all the operands. */
5109 : 211559221 : if ((TREE_CODE (node) == ARRAY_REF
5110 : 211559221 : || TREE_CODE (node) == ARRAY_RANGE_REF)
5111 : 211559221 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
5112 : : {
5113 : 30591361 : UPDATE_FLAGS (TREE_OPERAND (node, 1));
5114 : 30591361 : if (TREE_OPERAND (node, 2))
5115 : 2315041 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5116 : 30591361 : if (TREE_OPERAND (node, 3))
5117 : 265542 : UPDATE_FLAGS (TREE_OPERAND (node, 3));
5118 : : }
5119 : : /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
5120 : : FIELD_DECL, apparently. The G++ front end can put something else
5121 : : there, at least temporarily. */
5122 : 180967860 : else if (TREE_CODE (node) == COMPONENT_REF
5123 : 180967860 : && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
5124 : : {
5125 : 180084334 : if (TREE_OPERAND (node, 2))
5126 : 16840 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5127 : : }
5128 : : }
5129 : :
5130 : 1280505685 : node = lang_hooks.expr_to_decl (node, &tc, &se);
5131 : :
5132 : : /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
5133 : : the address, since &(*a)->b is a form of addition. If it's a constant, the
5134 : : address is constant too. If it's a decl, its address is constant if the
5135 : : decl is static. Everything else is not constant and, furthermore,
5136 : : taking the address of a volatile variable is not volatile. */
5137 : 1280505685 : if (INDIRECT_REF_P (node)
5138 : 1249175931 : || TREE_CODE (node) == MEM_REF)
5139 : 149461519 : UPDATE_FLAGS (TREE_OPERAND (node, 0));
5140 : 1131044166 : else if (CONSTANT_CLASS_P (node))
5141 : : ;
5142 : 1059072564 : else if (DECL_P (node))
5143 : 1043250927 : tc &= (staticp (node) != NULL_TREE);
5144 : : else
5145 : : {
5146 : 15821637 : tc = false;
5147 : 15821637 : se |= TREE_SIDE_EFFECTS (node);
5148 : : }
5149 : :
5150 : :
5151 : 1280505685 : TREE_CONSTANT (t) = tc;
5152 : 1280505685 : TREE_SIDE_EFFECTS (t) = se;
5153 : : #undef UPDATE_FLAGS
5154 : 1280505685 : }
5155 : :
5156 : : /* Build an expression of code CODE, data type TYPE, and operands as
5157 : : specified. Expressions and reference nodes can be created this way.
5158 : : Constants, decls, types and misc nodes cannot be.
5159 : :
5160 : : We define 5 non-variadic functions, from 0 to 4 arguments. This is
5161 : : enough for all extant tree codes. */
5162 : :
5163 : : tree
5164 : 334430793 : build0 (enum tree_code code, tree tt MEM_STAT_DECL)
5165 : : {
5166 : 334430793 : tree t;
5167 : :
5168 : 334430793 : gcc_assert (TREE_CODE_LENGTH (code) == 0);
5169 : :
5170 : 334430793 : t = make_node (code PASS_MEM_STAT);
5171 : 334430793 : TREE_TYPE (t) = tt;
5172 : :
5173 : 334430793 : return t;
5174 : : }
5175 : :
5176 : : tree
5177 : 3227071458 : build1 (enum tree_code code, tree type, tree node MEM_STAT_DECL)
5178 : : {
5179 : 3227071458 : int length = sizeof (struct tree_exp);
5180 : 3227071458 : tree t;
5181 : :
5182 : 3227071458 : record_node_allocation_statistics (code, length);
5183 : :
5184 : 3227071458 : gcc_assert (TREE_CODE_LENGTH (code) == 1);
5185 : :
5186 : 3227071458 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
5187 : :
5188 : 3227071458 : memset (t, 0, sizeof (struct tree_common));
5189 : :
5190 : 3227071458 : TREE_SET_CODE (t, code);
5191 : :
5192 : 3227071458 : TREE_TYPE (t) = type;
5193 : 3227071458 : SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
5194 : 3227071458 : TREE_OPERAND (t, 0) = node;
5195 : 3227071458 : if (node && !TYPE_P (node))
5196 : : {
5197 : 3227056425 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
5198 : 3227056425 : TREE_READONLY (t) = TREE_READONLY (node);
5199 : : }
5200 : :
5201 : 3227071458 : if (TREE_CODE_CLASS (code) == tcc_statement)
5202 : : {
5203 : 22246897 : if (code != DEBUG_BEGIN_STMT)
5204 : 22246897 : TREE_SIDE_EFFECTS (t) = 1;
5205 : : }
5206 : 3204824561 : else switch (code)
5207 : : {
5208 : 50813 : case VA_ARG_EXPR:
5209 : : /* All of these have side-effects, no matter what their
5210 : : operands are. */
5211 : 50813 : TREE_SIDE_EFFECTS (t) = 1;
5212 : 50813 : TREE_READONLY (t) = 0;
5213 : 50813 : break;
5214 : :
5215 : 512775985 : case INDIRECT_REF:
5216 : : /* Whether a dereference is readonly has nothing to do with whether
5217 : : its operand is readonly. */
5218 : 512775985 : TREE_READONLY (t) = 0;
5219 : 512775985 : break;
5220 : :
5221 : 522872016 : case ADDR_EXPR:
5222 : 522872016 : if (node)
5223 : 522872016 : recompute_tree_invariant_for_addr_expr (t);
5224 : : break;
5225 : :
5226 : 2169125747 : default:
5227 : 849574539 : if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
5228 : 2050730053 : && node && !TYPE_P (node)
5229 : 4219855800 : && TREE_CONSTANT (node))
5230 : 522779479 : TREE_CONSTANT (t) = 1;
5231 : 2169125747 : if (TREE_CODE_CLASS (code) == tcc_reference
5232 : 733663681 : && node && TREE_THIS_VOLATILE (node))
5233 : 2477602 : TREE_THIS_VOLATILE (t) = 1;
5234 : : break;
5235 : : }
5236 : :
5237 : 3227071458 : return t;
5238 : : }
5239 : :
5240 : : #define PROCESS_ARG(N) \
5241 : : do { \
5242 : : TREE_OPERAND (t, N) = arg##N; \
5243 : : if (arg##N &&!TYPE_P (arg##N)) \
5244 : : { \
5245 : : if (TREE_SIDE_EFFECTS (arg##N)) \
5246 : : side_effects = 1; \
5247 : : if (!TREE_READONLY (arg##N) \
5248 : : && !CONSTANT_CLASS_P (arg##N)) \
5249 : : (void) (read_only = 0); \
5250 : : if (!TREE_CONSTANT (arg##N)) \
5251 : : (void) (constant = 0); \
5252 : : } \
5253 : : } while (0)
5254 : :
5255 : : tree
5256 : 1079536121 : build2 (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
5257 : : {
5258 : 1079536121 : bool constant, read_only, side_effects, div_by_zero;
5259 : 1079536121 : tree t;
5260 : :
5261 : 1079536121 : gcc_assert (TREE_CODE_LENGTH (code) == 2);
5262 : :
5263 : 1079536121 : if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
5264 : 182759153 : && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
5265 : : /* When sizetype precision doesn't match that of pointers
5266 : : we need to be able to build explicit extensions or truncations
5267 : : of the offset argument. */
5268 : 1079536121 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
5269 : 0 : gcc_assert (TREE_CODE (arg0) == INTEGER_CST
5270 : : && TREE_CODE (arg1) == INTEGER_CST);
5271 : :
5272 : 1079536121 : if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
5273 : 24778994 : gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
5274 : : && ptrofftype_p (TREE_TYPE (arg1)));
5275 : :
5276 : 1079536121 : t = make_node (code PASS_MEM_STAT);
5277 : 1079536121 : TREE_TYPE (t) = tt;
5278 : :
5279 : : /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
5280 : : result based on those same flags for the arguments. But if the
5281 : : arguments aren't really even `tree' expressions, we shouldn't be trying
5282 : : to do this. */
5283 : :
5284 : : /* Expressions without side effects may be constant if their
5285 : : arguments are as well. */
5286 : 2159072242 : constant = (TREE_CODE_CLASS (code) == tcc_comparison
5287 : 1079536121 : || TREE_CODE_CLASS (code) == tcc_binary);
5288 : 1079536121 : read_only = 1;
5289 : 1079536121 : side_effects = TREE_SIDE_EFFECTS (t);
5290 : :
5291 : 1079536121 : switch (code)
5292 : : {
5293 : 10102672 : case TRUNC_DIV_EXPR:
5294 : 10102672 : case CEIL_DIV_EXPR:
5295 : 10102672 : case FLOOR_DIV_EXPR:
5296 : 10102672 : case ROUND_DIV_EXPR:
5297 : 10102672 : case EXACT_DIV_EXPR:
5298 : 10102672 : case CEIL_MOD_EXPR:
5299 : 10102672 : case FLOOR_MOD_EXPR:
5300 : 10102672 : case ROUND_MOD_EXPR:
5301 : 10102672 : case TRUNC_MOD_EXPR:
5302 : 10102672 : div_by_zero = integer_zerop (arg1);
5303 : 10102672 : break;
5304 : : default:
5305 : : div_by_zero = false;
5306 : : }
5307 : :
5308 : 1174540454 : PROCESS_ARG (0);
5309 : 1518591639 : PROCESS_ARG (1);
5310 : :
5311 : 1079536121 : TREE_SIDE_EFFECTS (t) = side_effects;
5312 : 1079536121 : if (code == MEM_REF)
5313 : : {
5314 : 71284329 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5315 : : {
5316 : 15353598 : tree o = TREE_OPERAND (arg0, 0);
5317 : 15353598 : TREE_READONLY (t) = TREE_READONLY (o);
5318 : 15353598 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5319 : : }
5320 : : }
5321 : : else
5322 : : {
5323 : 1008251792 : TREE_READONLY (t) = read_only;
5324 : : /* Don't mark X / 0 as constant. */
5325 : 1008251792 : TREE_CONSTANT (t) = constant && !div_by_zero;
5326 : 1008251792 : TREE_THIS_VOLATILE (t)
5327 : 1008251792 : = (TREE_CODE_CLASS (code) == tcc_reference
5328 : 1008251792 : && arg0 && TREE_THIS_VOLATILE (arg0));
5329 : : }
5330 : :
5331 : 1079536121 : return t;
5332 : : }
5333 : :
5334 : :
5335 : : tree
5336 : 399717368 : build3 (enum tree_code code, tree tt, tree arg0, tree arg1,
5337 : : tree arg2 MEM_STAT_DECL)
5338 : : {
5339 : 399717368 : bool constant, read_only, side_effects;
5340 : 399717368 : tree t;
5341 : :
5342 : 399717368 : gcc_assert (TREE_CODE_LENGTH (code) == 3);
5343 : 399717368 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5344 : :
5345 : 399717368 : t = make_node (code PASS_MEM_STAT);
5346 : 399717368 : TREE_TYPE (t) = tt;
5347 : :
5348 : 399717368 : read_only = 1;
5349 : :
5350 : : /* As a special exception, if COND_EXPR has NULL branches, we
5351 : : assume that it is a gimple statement and always consider
5352 : : it to have side effects. */
5353 : 399717368 : if (code == COND_EXPR
5354 : 33156461 : && tt == void_type_node
5355 : 21940999 : && arg1 == NULL_TREE
5356 : 21940999 : && arg2 == NULL_TREE)
5357 : : side_effects = true;
5358 : : else
5359 : 399717368 : side_effects = TREE_SIDE_EFFECTS (t);
5360 : :
5361 : 435696976 : PROCESS_ARG (0);
5362 : 411120072 : PROCESS_ARG (1);
5363 : 410319470 : PROCESS_ARG (2);
5364 : :
5365 : 399717368 : if (code == COND_EXPR)
5366 : 33156461 : TREE_READONLY (t) = read_only;
5367 : :
5368 : 399717368 : TREE_SIDE_EFFECTS (t) = side_effects;
5369 : 399717368 : TREE_THIS_VOLATILE (t)
5370 : 399717368 : = (TREE_CODE_CLASS (code) == tcc_reference
5371 : 399717368 : && arg0 && TREE_THIS_VOLATILE (arg0));
5372 : :
5373 : 399717368 : return t;
5374 : : }
5375 : :
5376 : : tree
5377 : 37788790 : build4 (enum tree_code code, tree tt, tree arg0, tree arg1,
5378 : : tree arg2, tree arg3 MEM_STAT_DECL)
5379 : : {
5380 : 37788790 : bool constant, read_only, side_effects;
5381 : 37788790 : tree t;
5382 : :
5383 : 37788790 : gcc_assert (TREE_CODE_LENGTH (code) == 4);
5384 : :
5385 : 37788790 : t = make_node (code PASS_MEM_STAT);
5386 : 37788790 : TREE_TYPE (t) = tt;
5387 : :
5388 : 37788790 : side_effects = TREE_SIDE_EFFECTS (t);
5389 : :
5390 : 37788790 : PROCESS_ARG (0);
5391 : 37788790 : PROCESS_ARG (1);
5392 : 37788790 : PROCESS_ARG (2);
5393 : 37788790 : PROCESS_ARG (3);
5394 : :
5395 : 37788790 : TREE_SIDE_EFFECTS (t) = side_effects;
5396 : 37788790 : TREE_THIS_VOLATILE (t)
5397 : 75577580 : = (TREE_CODE_CLASS (code) == tcc_reference
5398 : 37788790 : && arg0 && TREE_THIS_VOLATILE (arg0));
5399 : :
5400 : 37788790 : return t;
5401 : : }
5402 : :
5403 : : tree
5404 : 1156857 : build5 (enum tree_code code, tree tt, tree arg0, tree arg1,
5405 : : tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
5406 : : {
5407 : 1156857 : bool constant, read_only, side_effects;
5408 : 1156857 : tree t;
5409 : :
5410 : 1156857 : gcc_assert (TREE_CODE_LENGTH (code) == 5);
5411 : :
5412 : 1156857 : t = make_node (code PASS_MEM_STAT);
5413 : 1156857 : TREE_TYPE (t) = tt;
5414 : :
5415 : 1156857 : side_effects = TREE_SIDE_EFFECTS (t);
5416 : :
5417 : 1156857 : PROCESS_ARG (0);
5418 : 1156857 : PROCESS_ARG (1);
5419 : 1156857 : PROCESS_ARG (2);
5420 : 1156857 : PROCESS_ARG (3);
5421 : 1156857 : PROCESS_ARG (4);
5422 : :
5423 : 1156857 : TREE_SIDE_EFFECTS (t) = side_effects;
5424 : 1156857 : if (code == TARGET_MEM_REF)
5425 : : {
5426 : 1150098 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5427 : : {
5428 : 193205 : tree o = TREE_OPERAND (arg0, 0);
5429 : 193205 : TREE_READONLY (t) = TREE_READONLY (o);
5430 : 193205 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5431 : : }
5432 : : }
5433 : : else
5434 : 6759 : TREE_THIS_VOLATILE (t)
5435 : 6759 : = (TREE_CODE_CLASS (code) == tcc_reference
5436 : 6759 : && arg0 && TREE_THIS_VOLATILE (arg0));
5437 : :
5438 : 1156857 : return t;
5439 : : }
5440 : :
5441 : : /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
5442 : : on the pointer PTR. */
5443 : :
5444 : : tree
5445 : 485279 : build_simple_mem_ref_loc (location_t loc, tree ptr)
5446 : : {
5447 : 485279 : poly_int64 offset = 0;
5448 : 485279 : tree ptype = TREE_TYPE (ptr);
5449 : 485279 : tree tem;
5450 : : /* For convenience allow addresses that collapse to a simple base
5451 : : and offset. */
5452 : 485279 : if (TREE_CODE (ptr) == ADDR_EXPR
5453 : 485279 : && (handled_component_p (TREE_OPERAND (ptr, 0))
5454 : 15423 : || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
5455 : : {
5456 : 187 : ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
5457 : 187 : gcc_assert (ptr);
5458 : 187 : if (TREE_CODE (ptr) == MEM_REF)
5459 : : {
5460 : 77 : offset += mem_ref_offset (ptr).force_shwi ();
5461 : 77 : ptr = TREE_OPERAND (ptr, 0);
5462 : : }
5463 : : else
5464 : 110 : ptr = build_fold_addr_expr (ptr);
5465 : 187 : gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
5466 : : }
5467 : 485279 : tem = build2 (MEM_REF, TREE_TYPE (ptype),
5468 : : ptr, build_int_cst (ptype, offset));
5469 : 485279 : SET_EXPR_LOCATION (tem, loc);
5470 : 485279 : return tem;
5471 : : }
5472 : :
5473 : : /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
5474 : :
5475 : : poly_offset_int
5476 : 1203076874 : mem_ref_offset (const_tree t)
5477 : : {
5478 : 1203076874 : return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
5479 : 1203076874 : SIGNED);
5480 : : }
5481 : :
5482 : : /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
5483 : : offsetted by OFFSET units. */
5484 : :
5485 : : tree
5486 : 189693 : build_invariant_address (tree type, tree base, poly_int64 offset)
5487 : : {
5488 : 189693 : tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
5489 : : build_fold_addr_expr (base),
5490 : : build_int_cst (ptr_type_node, offset));
5491 : 189693 : tree addr = build1 (ADDR_EXPR, type, ref);
5492 : 189693 : recompute_tree_invariant_for_addr_expr (addr);
5493 : 189693 : return addr;
5494 : : }
5495 : :
5496 : : /* Similar except don't specify the TREE_TYPE
5497 : : and leave the TREE_SIDE_EFFECTS as 0.
5498 : : It is permissible for arguments to be null,
5499 : : or even garbage if their values do not matter. */
5500 : :
5501 : : tree
5502 : 2099836 : build_nt (enum tree_code code, ...)
5503 : : {
5504 : 2099836 : tree t;
5505 : 2099836 : int length;
5506 : 2099836 : int i;
5507 : 2099836 : va_list p;
5508 : :
5509 : 2099836 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5510 : :
5511 : 2099836 : va_start (p, code);
5512 : :
5513 : 2099836 : t = make_node (code);
5514 : 2099836 : length = TREE_CODE_LENGTH (code);
5515 : :
5516 : 5881712 : for (i = 0; i < length; i++)
5517 : 3781876 : TREE_OPERAND (t, i) = va_arg (p, tree);
5518 : :
5519 : 2099836 : va_end (p);
5520 : 2099836 : return t;
5521 : : }
5522 : :
5523 : : /* Similar to build_nt, but for creating a CALL_EXPR object with a
5524 : : tree vec. */
5525 : :
5526 : : tree
5527 : 0 : build_nt_call_vec (tree fn, vec<tree, va_gc> *args)
5528 : : {
5529 : 0 : tree ret, t;
5530 : 0 : unsigned int ix;
5531 : :
5532 : 0 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
5533 : 0 : CALL_EXPR_FN (ret) = fn;
5534 : 0 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
5535 : 0 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
5536 : 0 : CALL_EXPR_ARG (ret, ix) = t;
5537 : 0 : return ret;
5538 : : }
5539 : :
5540 : : /* Create a DECL_... node of code CODE, name NAME (if non-null)
5541 : : and data type TYPE.
5542 : : We do NOT enter this node in any sort of symbol table.
5543 : :
5544 : : LOC is the location of the decl.
5545 : :
5546 : : layout_decl is used to set up the decl's storage layout.
5547 : : Other slots are initialized to 0 or null pointers. */
5548 : :
5549 : : tree
5550 : 2922361169 : build_decl (location_t loc, enum tree_code code, tree name,
5551 : : tree type MEM_STAT_DECL)
5552 : : {
5553 : 2922361169 : tree t;
5554 : :
5555 : 2922361169 : t = make_node (code PASS_MEM_STAT);
5556 : 2922361169 : DECL_SOURCE_LOCATION (t) = loc;
5557 : :
5558 : : /* if (type == error_mark_node)
5559 : : type = integer_type_node; */
5560 : : /* That is not done, deliberately, so that having error_mark_node
5561 : : as the type can suppress useless errors in the use of this variable. */
5562 : :
5563 : 2922361169 : DECL_NAME (t) = name;
5564 : 2922361169 : TREE_TYPE (t) = type;
5565 : :
5566 : 2922361169 : if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
5567 : 1039505421 : layout_decl (t, 0);
5568 : :
5569 : 2922361169 : return t;
5570 : : }
5571 : :
5572 : : /* Create and return a DEBUG_EXPR_DECL node of the given TYPE. */
5573 : :
5574 : : tree
5575 : 1697142 : build_debug_expr_decl (tree type)
5576 : : {
5577 : 1697142 : tree vexpr = make_node (DEBUG_EXPR_DECL);
5578 : 1697142 : DECL_ARTIFICIAL (vexpr) = 1;
5579 : 1697142 : TREE_TYPE (vexpr) = type;
5580 : 1697142 : SET_DECL_MODE (vexpr, TYPE_MODE (type));
5581 : 1697142 : return vexpr;
5582 : : }
5583 : :
5584 : : /* Builds and returns function declaration with NAME and TYPE. */
5585 : :
5586 : : tree
5587 : 19164 : build_fn_decl (const char *name, tree type)
5588 : : {
5589 : 19164 : tree id = get_identifier (name);
5590 : 19164 : tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
5591 : :
5592 : 19164 : DECL_EXTERNAL (decl) = 1;
5593 : 19164 : TREE_PUBLIC (decl) = 1;
5594 : 19164 : DECL_ARTIFICIAL (decl) = 1;
5595 : 19164 : TREE_NOTHROW (decl) = 1;
5596 : :
5597 : 19164 : return decl;
5598 : : }
5599 : :
5600 : : vec<tree, va_gc> *all_translation_units;
5601 : :
5602 : : /* Builds a new translation-unit decl with name NAME, queues it in the
5603 : : global list of translation-unit decls and returns it. */
5604 : :
5605 : : tree
5606 : 249655 : build_translation_unit_decl (tree name)
5607 : : {
5608 : 249655 : tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
5609 : 249655 : name, NULL_TREE);
5610 : 249655 : TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
5611 : 249655 : vec_safe_push (all_translation_units, tu);
5612 : 249655 : return tu;
5613 : : }
5614 : :
5615 : :
5616 : : /* BLOCK nodes are used to represent the structure of binding contours
5617 : : and declarations, once those contours have been exited and their contents
5618 : : compiled. This information is used for outputting debugging info. */
5619 : :
5620 : : tree
5621 : 696866 : build_block (tree vars, tree subblocks, tree supercontext, tree chain)
5622 : : {
5623 : 696866 : tree block = make_node (BLOCK);
5624 : :
5625 : 696866 : BLOCK_VARS (block) = vars;
5626 : 696866 : BLOCK_SUBBLOCKS (block) = subblocks;
5627 : 696866 : BLOCK_SUPERCONTEXT (block) = supercontext;
5628 : 696866 : BLOCK_CHAIN (block) = chain;
5629 : 696866 : return block;
5630 : : }
5631 : :
5632 : :
5633 : : /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
5634 : :
5635 : : LOC is the location to use in tree T. */
5636 : :
5637 : : void
5638 : 12379350819 : protected_set_expr_location (tree t, location_t loc)
5639 : : {
5640 : 12379350819 : if (CAN_HAVE_LOCATION_P (t))
5641 : 1969788398 : SET_EXPR_LOCATION (t, loc);
5642 : 10345109574 : else if (t && TREE_CODE (t) == STATEMENT_LIST)
5643 : : {
5644 : 22243 : t = expr_single (t);
5645 : 22243 : if (t && CAN_HAVE_LOCATION_P (t))
5646 : 18 : SET_EXPR_LOCATION (t, loc);
5647 : : }
5648 : 12379350819 : }
5649 : :
5650 : : /* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has
5651 : : UNKNOWN_LOCATION. */
5652 : :
5653 : : void
5654 : 21068542 : protected_set_expr_location_if_unset (tree t, location_t loc)
5655 : : {
5656 : 21068542 : t = expr_single (t);
5657 : 21068542 : if (t && !EXPR_HAS_LOCATION (t))
5658 : 15975603 : protected_set_expr_location (t, loc);
5659 : 21068542 : }
5660 : :
5661 : : /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5662 : : of the various TYPE_QUAL values. */
5663 : :
5664 : : static void
5665 : 91946852 : set_type_quals (tree type, int type_quals)
5666 : : {
5667 : 91946852 : TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
5668 : 91946852 : TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
5669 : 91946852 : TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
5670 : 91946852 : TYPE_ATOMIC (type) = (type_quals & TYPE_QUAL_ATOMIC) != 0;
5671 : 91946852 : TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
5672 : 91946852 : }
5673 : :
5674 : : /* Returns true iff CAND and BASE have equivalent language-specific
5675 : : qualifiers. */
5676 : :
5677 : : bool
5678 : 2399245415 : check_lang_type (const_tree cand, const_tree base)
5679 : : {
5680 : 2399245415 : if (lang_hooks.types.type_hash_eq == NULL)
5681 : : return true;
5682 : : /* type_hash_eq currently only applies to these types. */
5683 : 2344392028 : if (TREE_CODE (cand) != FUNCTION_TYPE
5684 : 2344392028 : && TREE_CODE (cand) != METHOD_TYPE)
5685 : : return true;
5686 : 1086248 : return lang_hooks.types.type_hash_eq (cand, base);
5687 : : }
5688 : :
5689 : : /* This function checks to see if TYPE matches the size one of the built-in
5690 : : atomic types, and returns that core atomic type. */
5691 : :
5692 : : static tree
5693 : 8306 : find_atomic_core_type (const_tree type)
5694 : : {
5695 : 8306 : tree base_atomic_type;
5696 : :
5697 : : /* Only handle complete types. */
5698 : 8306 : if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
5699 : : return NULL_TREE;
5700 : :
5701 : 8294 : switch (tree_to_uhwi (TYPE_SIZE (type)))
5702 : : {
5703 : 2448 : case 8:
5704 : 2448 : base_atomic_type = atomicQI_type_node;
5705 : 2448 : break;
5706 : :
5707 : 786 : case 16:
5708 : 786 : base_atomic_type = atomicHI_type_node;
5709 : 786 : break;
5710 : :
5711 : 1001 : case 32:
5712 : 1001 : base_atomic_type = atomicSI_type_node;
5713 : 1001 : break;
5714 : :
5715 : 2630 : case 64:
5716 : 2630 : base_atomic_type = atomicDI_type_node;
5717 : 2630 : break;
5718 : :
5719 : 1309 : case 128:
5720 : 1309 : base_atomic_type = atomicTI_type_node;
5721 : 1309 : break;
5722 : :
5723 : : default:
5724 : : base_atomic_type = NULL_TREE;
5725 : : }
5726 : :
5727 : : return base_atomic_type;
5728 : : }
5729 : :
5730 : : /* Returns true iff unqualified CAND and BASE are equivalent. */
5731 : :
5732 : : bool
5733 : 3843186027 : check_base_type (const_tree cand, const_tree base)
5734 : : {
5735 : 3843186027 : if (TYPE_NAME (cand) != TYPE_NAME (base)
5736 : : /* Apparently this is needed for Objective-C. */
5737 : 3497624686 : || TYPE_CONTEXT (cand) != TYPE_CONTEXT (base)
5738 : 7340810713 : || !attribute_list_equal (TYPE_ATTRIBUTES (cand),
5739 : 3497624686 : TYPE_ATTRIBUTES (base)))
5740 : 345561341 : return false;
5741 : : /* Check alignment. */
5742 : 3497624686 : if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
5743 : 3497624686 : && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
5744 : : return true;
5745 : : /* Atomic types increase minimal alignment. We must to do so as well
5746 : : or we get duplicated canonical types. See PR88686. */
5747 : 10714 : if ((TYPE_QUALS (cand) & TYPE_QUAL_ATOMIC))
5748 : : {
5749 : : /* See if this object can map to a basic atomic type. */
5750 : 1775 : tree atomic_type = find_atomic_core_type (cand);
5751 : 1775 : if (atomic_type && TYPE_ALIGN (atomic_type) == TYPE_ALIGN (cand))
5752 : : return true;
5753 : : }
5754 : : return false;
5755 : : }
5756 : :
5757 : : /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5758 : :
5759 : : bool
5760 : 4064588814 : check_qualified_type (const_tree cand, const_tree base, int type_quals)
5761 : : {
5762 : 4064588814 : return (TYPE_QUALS (cand) == type_quals
5763 : 2742999295 : && check_base_type (cand, base)
5764 : 6462126860 : && check_lang_type (cand, base));
5765 : : }
5766 : :
5767 : : /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5768 : :
5769 : : static bool
5770 : 3400377 : check_aligned_type (const_tree cand, const_tree base, unsigned int align)
5771 : : {
5772 : 3400377 : return (TYPE_QUALS (cand) == TYPE_QUALS (base)
5773 : 2814783 : && TYPE_NAME (cand) == TYPE_NAME (base)
5774 : : /* Apparently this is needed for Objective-C. */
5775 : 2021385 : && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
5776 : : /* Check alignment. */
5777 : 2021385 : && TYPE_ALIGN (cand) == align
5778 : : /* Check this is a user-aligned type as build_aligned_type
5779 : : would create. */
5780 : 953294 : && TYPE_USER_ALIGN (cand)
5781 : 950702 : && attribute_list_equal (TYPE_ATTRIBUTES (cand),
5782 : 950702 : TYPE_ATTRIBUTES (base))
5783 : 4351079 : && check_lang_type (cand, base));
5784 : : }
5785 : :
5786 : : /* Return a version of the TYPE, qualified as indicated by the
5787 : : TYPE_QUALS, if one exists. If no qualified version exists yet,
5788 : : return NULL_TREE. */
5789 : :
5790 : : tree
5791 : 3748122258 : get_qualified_type (tree type, int type_quals)
5792 : : {
5793 : 3748122258 : if (TYPE_QUALS (type) == type_quals)
5794 : : return type;
5795 : :
5796 : 2489539743 : tree mv = TYPE_MAIN_VARIANT (type);
5797 : 2489539743 : if (check_qualified_type (mv, type, type_quals))
5798 : : return mv;
5799 : :
5800 : : /* Search the chain of variants to see if there is already one there just
5801 : : like the one we need to have. If so, use that existing one. We must
5802 : : preserve the TYPE_NAME, since there is code that depends on this. */
5803 : 1667065352 : for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
5804 : 1574987741 : if (check_qualified_type (*tp, type, type_quals))
5805 : : {
5806 : : /* Put the found variant at the head of the variant list so
5807 : : frequently searched variants get found faster. The C++ FE
5808 : : benefits greatly from this. */
5809 : 1036734569 : tree t = *tp;
5810 : 1036734569 : *tp = TYPE_NEXT_VARIANT (t);
5811 : 1036734569 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
5812 : 1036734569 : TYPE_NEXT_VARIANT (mv) = t;
5813 : 1036734569 : return t;
5814 : : }
5815 : :
5816 : : return NULL_TREE;
5817 : : }
5818 : :
5819 : : /* Like get_qualified_type, but creates the type if it does not
5820 : : exist. This function never returns NULL_TREE. */
5821 : :
5822 : : tree
5823 : 3349478235 : build_qualified_type (tree type, int type_quals MEM_STAT_DECL)
5824 : : {
5825 : 3349478235 : tree t;
5826 : :
5827 : : /* See if we already have the appropriate qualified variant. */
5828 : 3349478235 : t = get_qualified_type (type, type_quals);
5829 : :
5830 : : /* If not, build it. */
5831 : 3349478235 : if (!t)
5832 : : {
5833 : 90519897 : t = build_variant_type_copy (type PASS_MEM_STAT);
5834 : 90519897 : set_type_quals (t, type_quals);
5835 : :
5836 : 90519897 : if (((type_quals & TYPE_QUAL_ATOMIC) == TYPE_QUAL_ATOMIC))
5837 : : {
5838 : : /* See if this object can map to a basic atomic type. */
5839 : 6531 : tree atomic_type = find_atomic_core_type (type);
5840 : 6531 : if (atomic_type)
5841 : : {
5842 : : /* Ensure the alignment of this type is compatible with
5843 : : the required alignment of the atomic type. */
5844 : 6399 : if (TYPE_ALIGN (atomic_type) > TYPE_ALIGN (t))
5845 : 94 : SET_TYPE_ALIGN (t, TYPE_ALIGN (atomic_type));
5846 : : }
5847 : : }
5848 : :
5849 : 90519897 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5850 : : /* Propagate structural equality. */
5851 : 4361397 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5852 : 86158500 : else if (TYPE_CANONICAL (type) != type)
5853 : : /* Build the underlying canonical type, since it is different
5854 : : from TYPE. */
5855 : : {
5856 : 28247104 : tree c = build_qualified_type (TYPE_CANONICAL (type), type_quals);
5857 : 28247104 : TYPE_CANONICAL (t) = TYPE_CANONICAL (c);
5858 : : }
5859 : : else
5860 : : /* T is its own canonical type. */
5861 : 57911396 : TYPE_CANONICAL (t) = t;
5862 : :
5863 : : }
5864 : :
5865 : 3349478235 : return t;
5866 : : }
5867 : :
5868 : : /* Create a variant of type T with alignment ALIGN which
5869 : : is measured in bits. */
5870 : :
5871 : : tree
5872 : 1232508 : build_aligned_type (tree type, unsigned int align)
5873 : : {
5874 : 1232508 : tree t;
5875 : :
5876 : 1232508 : if (TYPE_PACKED (type)
5877 : 1232508 : || TYPE_ALIGN (type) == align)
5878 : : return type;
5879 : :
5880 : 3502291 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5881 : 3400377 : if (check_aligned_type (t, type, align))
5882 : : return t;
5883 : :
5884 : 101914 : t = build_variant_type_copy (type);
5885 : 101914 : SET_TYPE_ALIGN (t, align);
5886 : 101914 : TYPE_USER_ALIGN (t) = 1;
5887 : :
5888 : 101914 : return t;
5889 : : }
5890 : :
5891 : : /* Create a new distinct copy of TYPE. The new type is made its own
5892 : : MAIN_VARIANT. If TYPE requires structural equality checks, the
5893 : : resulting type requires structural equality checks; otherwise, its
5894 : : TYPE_CANONICAL points to itself. */
5895 : :
5896 : : tree
5897 : 693635467 : build_distinct_type_copy (tree type MEM_STAT_DECL)
5898 : : {
5899 : 693635467 : tree t = copy_node (type PASS_MEM_STAT);
5900 : :
5901 : 693635467 : TYPE_POINTER_TO (t) = 0;
5902 : 693635467 : TYPE_REFERENCE_TO (t) = 0;
5903 : :
5904 : : /* Set the canonical type either to a new equivalence class, or
5905 : : propagate the need for structural equality checks. */
5906 : 693635467 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5907 : 58422711 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5908 : : else
5909 : 635212756 : TYPE_CANONICAL (t) = t;
5910 : :
5911 : : /* Make it its own variant. */
5912 : 693635467 : TYPE_MAIN_VARIANT (t) = t;
5913 : 693635467 : TYPE_NEXT_VARIANT (t) = 0;
5914 : :
5915 : : /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5916 : : whose TREE_TYPE is not t. This can also happen in the Ada
5917 : : frontend when using subtypes. */
5918 : :
5919 : 693635467 : return t;
5920 : : }
5921 : :
5922 : : /* Create a new variant of TYPE, equivalent but distinct. This is so
5923 : : the caller can modify it. TYPE_CANONICAL for the return type will
5924 : : be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5925 : : are considered equal by the language itself (or that both types
5926 : : require structural equality checks). */
5927 : :
5928 : : tree
5929 : 420695986 : build_variant_type_copy (tree type MEM_STAT_DECL)
5930 : : {
5931 : 420695986 : tree t, m = TYPE_MAIN_VARIANT (type);
5932 : :
5933 : 420695986 : t = build_distinct_type_copy (type PASS_MEM_STAT);
5934 : :
5935 : : /* Since we're building a variant, assume that it is a non-semantic
5936 : : variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5937 : 420695986 : TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
5938 : : /* Type variants have no alias set defined. */
5939 : 420695986 : TYPE_ALIAS_SET (t) = -1;
5940 : :
5941 : : /* Add the new type to the chain of variants of TYPE. */
5942 : 420695986 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
5943 : 420695986 : TYPE_NEXT_VARIANT (m) = t;
5944 : 420695986 : TYPE_MAIN_VARIANT (t) = m;
5945 : :
5946 : 420695986 : return t;
5947 : : }
5948 : :
5949 : : /* Return true if the from tree in both tree maps are equal. */
5950 : :
5951 : : int
5952 : 1896930864 : tree_map_base_eq (const void *va, const void *vb)
5953 : : {
5954 : 1896930864 : const struct tree_map_base *const a = (const struct tree_map_base *) va,
5955 : 1896930864 : *const b = (const struct tree_map_base *) vb;
5956 : 1896930864 : return (a->from == b->from);
5957 : : }
5958 : :
5959 : : /* Hash a from tree in a tree_base_map. */
5960 : :
5961 : : unsigned int
5962 : 0 : tree_map_base_hash (const void *item)
5963 : : {
5964 : 0 : return htab_hash_pointer (((const struct tree_map_base *)item)->from);
5965 : : }
5966 : :
5967 : : /* Return true if this tree map structure is marked for garbage collection
5968 : : purposes. We simply return true if the from tree is marked, so that this
5969 : : structure goes away when the from tree goes away. */
5970 : :
5971 : : bool
5972 : 0 : tree_map_base_marked_p (const void *p)
5973 : : {
5974 : 0 : return ggc_marked_p (((const struct tree_map_base *) p)->from);
5975 : : }
5976 : :
5977 : : /* Hash a from tree in a tree_map. */
5978 : :
5979 : : unsigned int
5980 : 222 : tree_map_hash (const void *item)
5981 : : {
5982 : 222 : return (((const struct tree_map *) item)->hash);
5983 : : }
5984 : :
5985 : : /* Hash a from tree in a tree_decl_map. */
5986 : :
5987 : : unsigned int
5988 : 1301310310 : tree_decl_map_hash (const void *item)
5989 : : {
5990 : 1301310310 : return DECL_UID (((const struct tree_decl_map *) item)->base.from);
5991 : : }
5992 : :
5993 : : /* Return the initialization priority for DECL. */
5994 : :
5995 : : priority_type
5996 : 24255 : decl_init_priority_lookup (tree decl)
5997 : : {
5998 : 24255 : symtab_node *snode = symtab_node::get (decl);
5999 : :
6000 : 24255 : if (!snode)
6001 : : return DEFAULT_INIT_PRIORITY;
6002 : 24255 : return
6003 : 24255 : snode->get_init_priority ();
6004 : : }
6005 : :
6006 : : /* Return the finalization priority for DECL. */
6007 : :
6008 : : priority_type
6009 : 1808 : decl_fini_priority_lookup (tree decl)
6010 : : {
6011 : 1808 : cgraph_node *node = cgraph_node::get (decl);
6012 : :
6013 : 1808 : if (!node)
6014 : : return DEFAULT_INIT_PRIORITY;
6015 : 1808 : return
6016 : 1808 : node->get_fini_priority ();
6017 : : }
6018 : :
6019 : : /* Set the initialization priority for DECL to PRIORITY. */
6020 : :
6021 : : void
6022 : 25771 : decl_init_priority_insert (tree decl, priority_type priority)
6023 : : {
6024 : 25771 : struct symtab_node *snode;
6025 : :
6026 : 25771 : if (priority == DEFAULT_INIT_PRIORITY)
6027 : : {
6028 : 22265 : snode = symtab_node::get (decl);
6029 : 22265 : if (!snode)
6030 : : return;
6031 : : }
6032 : 3506 : else if (VAR_P (decl))
6033 : 45 : snode = varpool_node::get_create (decl);
6034 : : else
6035 : 3461 : snode = cgraph_node::get_create (decl);
6036 : 25053 : snode->set_init_priority (priority);
6037 : : }
6038 : :
6039 : : /* Set the finalization priority for DECL to PRIORITY. */
6040 : :
6041 : : void
6042 : 1667 : decl_fini_priority_insert (tree decl, priority_type priority)
6043 : : {
6044 : 1667 : struct cgraph_node *node;
6045 : :
6046 : 1667 : if (priority == DEFAULT_INIT_PRIORITY)
6047 : : {
6048 : 104 : node = cgraph_node::get (decl);
6049 : 104 : if (!node)
6050 : : return;
6051 : : }
6052 : : else
6053 : 1563 : node = cgraph_node::get_create (decl);
6054 : 1572 : node->set_fini_priority (priority);
6055 : : }
6056 : :
6057 : : /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6058 : :
6059 : : static void
6060 : 0 : print_debug_expr_statistics (void)
6061 : : {
6062 : 0 : fprintf (stderr, "DECL_DEBUG_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6063 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6064 : 0 : (fmt_size_t) debug_expr_for_decl->size (),
6065 : 0 : (fmt_size_t) debug_expr_for_decl->elements (),
6066 : : debug_expr_for_decl->collisions ());
6067 : 0 : }
6068 : :
6069 : : /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6070 : :
6071 : : static void
6072 : 0 : print_value_expr_statistics (void)
6073 : : {
6074 : 0 : fprintf (stderr, "DECL_VALUE_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6075 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6076 : 0 : (fmt_size_t) value_expr_for_decl->size (),
6077 : 0 : (fmt_size_t) value_expr_for_decl->elements (),
6078 : : value_expr_for_decl->collisions ());
6079 : 0 : }
6080 : :
6081 : : /* Lookup a debug expression for FROM, and return it if we find one. */
6082 : :
6083 : : tree
6084 : 457810064 : decl_debug_expr_lookup (tree from)
6085 : : {
6086 : 457810064 : struct tree_decl_map *h, in;
6087 : 457810064 : in.base.from = from;
6088 : :
6089 : 457810064 : h = debug_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6090 : 457810064 : if (h)
6091 : 457810064 : return h->to;
6092 : : return NULL_TREE;
6093 : : }
6094 : :
6095 : : /* Insert a mapping FROM->TO in the debug expression hashtable. */
6096 : :
6097 : : void
6098 : 1401444 : decl_debug_expr_insert (tree from, tree to)
6099 : : {
6100 : 1401444 : struct tree_decl_map *h;
6101 : :
6102 : 1401444 : h = ggc_alloc<tree_decl_map> ();
6103 : 1401444 : h->base.from = from;
6104 : 1401444 : h->to = to;
6105 : 1401444 : *debug_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6106 : 1401444 : }
6107 : :
6108 : : /* Lookup a value expression for FROM, and return it if we find one. */
6109 : :
6110 : : tree
6111 : 12297691 : decl_value_expr_lookup (tree from)
6112 : : {
6113 : 12297691 : struct tree_decl_map *h, in;
6114 : 12297691 : in.base.from = from;
6115 : :
6116 : 12297691 : h = value_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6117 : 12297691 : if (h)
6118 : 12297691 : return h->to;
6119 : : return NULL_TREE;
6120 : : }
6121 : :
6122 : : /* Insert a mapping FROM->TO in the value expression hashtable. */
6123 : :
6124 : : void
6125 : 5264249 : decl_value_expr_insert (tree from, tree to)
6126 : : {
6127 : 5264249 : struct tree_decl_map *h;
6128 : :
6129 : : /* Uses of FROM shouldn't look like they happen at the location of TO. */
6130 : 5264249 : to = protected_set_expr_location_unshare (to, UNKNOWN_LOCATION);
6131 : :
6132 : 5264249 : h = ggc_alloc<tree_decl_map> ();
6133 : 5264249 : h->base.from = from;
6134 : 5264249 : h->to = to;
6135 : 5264249 : *value_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6136 : 5264249 : }
6137 : :
6138 : : /* Lookup a vector of debug arguments for FROM, and return it if we
6139 : : find one. */
6140 : :
6141 : : vec<tree, va_gc> **
6142 : 837417 : decl_debug_args_lookup (tree from)
6143 : : {
6144 : 837417 : struct tree_vec_map *h, in;
6145 : :
6146 : 837417 : if (!DECL_HAS_DEBUG_ARGS_P (from))
6147 : : return NULL;
6148 : 705759 : gcc_checking_assert (debug_args_for_decl != NULL);
6149 : 705759 : in.base.from = from;
6150 : 705759 : h = debug_args_for_decl->find_with_hash (&in, DECL_UID (from));
6151 : 705759 : if (h)
6152 : 702550 : return &h->to;
6153 : : return NULL;
6154 : : }
6155 : :
6156 : : /* Insert a mapping FROM->empty vector of debug arguments in the value
6157 : : expression hashtable. */
6158 : :
6159 : : vec<tree, va_gc> **
6160 : 246979 : decl_debug_args_insert (tree from)
6161 : : {
6162 : 246979 : struct tree_vec_map *h;
6163 : 246979 : tree_vec_map **loc;
6164 : :
6165 : 246979 : if (DECL_HAS_DEBUG_ARGS_P (from))
6166 : 162559 : return decl_debug_args_lookup (from);
6167 : 84420 : if (debug_args_for_decl == NULL)
6168 : 8694 : debug_args_for_decl = hash_table<tree_vec_map_cache_hasher>::create_ggc (64);
6169 : 84420 : h = ggc_alloc<tree_vec_map> ();
6170 : 84420 : h->base.from = from;
6171 : 84420 : h->to = NULL;
6172 : 84420 : loc = debug_args_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT);
6173 : 84420 : *loc = h;
6174 : 84420 : DECL_HAS_DEBUG_ARGS_P (from) = 1;
6175 : 84420 : return &h->to;
6176 : : }
6177 : :
6178 : : /* Hashing of types so that we don't make duplicates.
6179 : : The entry point is `type_hash_canon'. */
6180 : :
6181 : : /* Generate the default hash code for TYPE. This is designed for
6182 : : speed, rather than maximum entropy. */
6183 : :
6184 : : hashval_t
6185 : 1318090187 : type_hash_canon_hash (tree type)
6186 : : {
6187 : 1318090187 : inchash::hash hstate;
6188 : :
6189 : 1318090187 : hstate.add_int (TREE_CODE (type));
6190 : :
6191 : 1318090187 : hstate.add_flag (TYPE_STRUCTURAL_EQUALITY_P (type));
6192 : :
6193 : 1318090187 : if (TREE_TYPE (type))
6194 : 1318068362 : hstate.add_object (TYPE_HASH (TREE_TYPE (type)));
6195 : :
6196 : 1591887838 : for (tree t = TYPE_ATTRIBUTES (type); t; t = TREE_CHAIN (t))
6197 : : /* Just the identifier is adequate to distinguish. */
6198 : 273797651 : hstate.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (t)));
6199 : :
6200 : 1318090187 : switch (TREE_CODE (type))
6201 : : {
6202 : 292167625 : case METHOD_TYPE:
6203 : 292167625 : hstate.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type)));
6204 : : /* FALLTHROUGH. */
6205 : 1139205768 : case FUNCTION_TYPE:
6206 : 4520797828 : for (tree t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
6207 : 3381592060 : if (TREE_VALUE (t) != error_mark_node)
6208 : 3381581517 : hstate.add_object (TYPE_HASH (TREE_VALUE (t)));
6209 : : break;
6210 : :
6211 : 973716 : case OFFSET_TYPE:
6212 : 973716 : hstate.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type)));
6213 : 973716 : break;
6214 : :
6215 : 62512441 : case ARRAY_TYPE:
6216 : 62512441 : {
6217 : 62512441 : if (TYPE_DOMAIN (type))
6218 : 60874498 : hstate.add_object (TYPE_HASH (TYPE_DOMAIN (type)));
6219 : 62512441 : if (!AGGREGATE_TYPE_P (TREE_TYPE (type)))
6220 : : {
6221 : 61166168 : unsigned typeless = TYPE_TYPELESS_STORAGE (type);
6222 : 61166168 : hstate.add_object (typeless);
6223 : : }
6224 : : }
6225 : : break;
6226 : :
6227 : 38062768 : case INTEGER_TYPE:
6228 : 38062768 : {
6229 : 38062768 : tree t = TYPE_MAX_VALUE (type);
6230 : 38062768 : if (!t)
6231 : 541163 : t = TYPE_MIN_VALUE (type);
6232 : 76125537 : for (int i = 0; i < TREE_INT_CST_NUNITS (t); i++)
6233 : 38062769 : hstate.add_object (TREE_INT_CST_ELT (t, i));
6234 : : break;
6235 : : }
6236 : :
6237 : 1 : case BITINT_TYPE:
6238 : 1 : {
6239 : 1 : unsigned prec = TYPE_PRECISION (type);
6240 : 1 : unsigned uns = TYPE_UNSIGNED (type);
6241 : 1 : hstate.add_object (prec);
6242 : 1 : hstate.add_int (uns);
6243 : 1 : break;
6244 : : }
6245 : :
6246 : 11694 : case REAL_TYPE:
6247 : 11694 : case FIXED_POINT_TYPE:
6248 : 11694 : {
6249 : 11694 : unsigned prec = TYPE_PRECISION (type);
6250 : 11694 : hstate.add_object (prec);
6251 : 11694 : break;
6252 : : }
6253 : :
6254 : 71893050 : case VECTOR_TYPE:
6255 : 71893050 : hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type));
6256 : 71893050 : break;
6257 : :
6258 : : case REFERENCE_TYPE:
6259 : 1318090187 : hstate.add_flag (TYPE_REF_IS_RVALUE (type));
6260 : : break;
6261 : :
6262 : : default:
6263 : : break;
6264 : : }
6265 : :
6266 : 1318090187 : return hstate.end ();
6267 : : }
6268 : :
6269 : : /* These are the Hashtable callback functions. */
6270 : :
6271 : : /* Returns true iff the types are equivalent. */
6272 : :
6273 : : bool
6274 : 9253549351 : type_cache_hasher::equal (type_hash *a, type_hash *b)
6275 : : {
6276 : : /* First test the things that are the same for all types. */
6277 : 9253549351 : if (a->hash != b->hash
6278 : 659705833 : || TREE_CODE (a->type) != TREE_CODE (b->type)
6279 : 659697564 : || TREE_TYPE (a->type) != TREE_TYPE (b->type)
6280 : 659697204 : || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
6281 : 659697204 : TYPE_ATTRIBUTES (b->type))
6282 : 9906299880 : || (TREE_CODE (a->type) != COMPLEX_TYPE
6283 : 650694038 : && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
6284 : 8601663031 : return false;
6285 : :
6286 : : /* Be careful about comparing arrays before and after the element type
6287 : : has been completed; don't compare TYPE_ALIGN unless both types are
6288 : : complete. */
6289 : 1301891747 : if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
6290 : 1301891747 : && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
6291 : 650004869 : || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
6292 : 672 : return false;
6293 : :
6294 : 651885648 : if (TYPE_STRUCTURAL_EQUALITY_P (a->type)
6295 : 651885648 : != TYPE_STRUCTURAL_EQUALITY_P (b->type))
6296 : : return false;
6297 : :
6298 : 651882245 : switch (TREE_CODE (a->type))
6299 : : {
6300 : : case VOID_TYPE:
6301 : : case OPAQUE_TYPE:
6302 : : case COMPLEX_TYPE:
6303 : : case POINTER_TYPE:
6304 : : case NULLPTR_TYPE:
6305 : : return true;
6306 : :
6307 : 65685601 : case VECTOR_TYPE:
6308 : 65685601 : return known_eq (TYPE_VECTOR_SUBPARTS (a->type),
6309 : : TYPE_VECTOR_SUBPARTS (b->type));
6310 : :
6311 : 0 : case ENUMERAL_TYPE:
6312 : 0 : if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6313 : 0 : && !(TYPE_VALUES (a->type)
6314 : 0 : && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6315 : 0 : && TYPE_VALUES (b->type)
6316 : 0 : && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
6317 : 0 : && type_list_equal (TYPE_VALUES (a->type),
6318 : 0 : TYPE_VALUES (b->type))))
6319 : 0 : return false;
6320 : :
6321 : : /* fall through */
6322 : :
6323 : 35351929 : case INTEGER_TYPE:
6324 : 35351929 : case REAL_TYPE:
6325 : 35351929 : case BOOLEAN_TYPE:
6326 : 35351929 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6327 : : return false;
6328 : 35345129 : return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
6329 : 786410 : || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
6330 : 786410 : TYPE_MAX_VALUE (b->type)))
6331 : 35732985 : && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
6332 : 523142 : || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
6333 : 523142 : TYPE_MIN_VALUE (b->type))));
6334 : :
6335 : 1546016 : case BITINT_TYPE:
6336 : 1546016 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6337 : : return false;
6338 : 1498254 : return TYPE_UNSIGNED (a->type) == TYPE_UNSIGNED (b->type);
6339 : :
6340 : 0 : case FIXED_POINT_TYPE:
6341 : 0 : return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
6342 : :
6343 : 774467 : case OFFSET_TYPE:
6344 : 774467 : return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
6345 : :
6346 : 84055528 : case METHOD_TYPE:
6347 : 84055528 : if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
6348 : 84055528 : && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6349 : 84006084 : || (TYPE_ARG_TYPES (a->type)
6350 : 84006084 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6351 : 84006084 : && TYPE_ARG_TYPES (b->type)
6352 : 84006084 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6353 : 84006084 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6354 : 84006084 : TYPE_ARG_TYPES (b->type)))))
6355 : : break;
6356 : : return false;
6357 : 52309192 : case ARRAY_TYPE:
6358 : : /* Don't compare TYPE_TYPELESS_STORAGE flag on aggregates,
6359 : : where the flag should be inherited from the element type
6360 : : and can change after ARRAY_TYPEs are created; on non-aggregates
6361 : : compare it and hash it, scalars will never have that flag set
6362 : : and we need to differentiate between arrays created by different
6363 : : front-ends or middle-end created arrays. */
6364 : 52309192 : return (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
6365 : 52309192 : && (AGGREGATE_TYPE_P (TREE_TYPE (a->type))
6366 : 51579924 : || (TYPE_TYPELESS_STORAGE (a->type)
6367 : 51579924 : == TYPE_TYPELESS_STORAGE (b->type))));
6368 : :
6369 : 0 : case RECORD_TYPE:
6370 : 0 : case UNION_TYPE:
6371 : 0 : case QUAL_UNION_TYPE:
6372 : 0 : return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
6373 : 0 : || (TYPE_FIELDS (a->type)
6374 : 0 : && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
6375 : 0 : && TYPE_FIELDS (b->type)
6376 : 0 : && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
6377 : 0 : && type_list_equal (TYPE_FIELDS (a->type),
6378 : 0 : TYPE_FIELDS (b->type))));
6379 : :
6380 : 410102535 : case FUNCTION_TYPE:
6381 : 410102535 : if ((TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6382 : 256591451 : && (TYPE_NO_NAMED_ARGS_STDARG_P (a->type)
6383 : 256591451 : == TYPE_NO_NAMED_ARGS_STDARG_P (b->type)))
6384 : 410406008 : || (TYPE_ARG_TYPES (a->type)
6385 : 153511084 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6386 : 153511084 : && TYPE_ARG_TYPES (b->type)
6387 : 153511069 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6388 : 153511069 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6389 : 153511069 : TYPE_ARG_TYPES (b->type))))
6390 : : break;
6391 : : return false;
6392 : :
6393 : 9 : case REFERENCE_TYPE:
6394 : 9 : return TYPE_REF_IS_RVALUE (a->type) == TYPE_REF_IS_RVALUE (b->type);
6395 : :
6396 : : default:
6397 : : return false;
6398 : : }
6399 : :
6400 : 469033491 : if (lang_hooks.types.type_hash_eq != NULL)
6401 : 291434546 : return lang_hooks.types.type_hash_eq (a->type, b->type);
6402 : :
6403 : : return true;
6404 : : }
6405 : :
6406 : : /* Given TYPE, and HASHCODE its hash code, return the canonical
6407 : : object for an identical type if one already exists.
6408 : : Otherwise, return TYPE, and record it as the canonical object.
6409 : :
6410 : : To use this function, first create a type of the sort you want.
6411 : : Then compute its hash code from the fields of the type that
6412 : : make it different from other similar types.
6413 : : Then call this function and use the value. */
6414 : :
6415 : : tree
6416 : 1320673474 : type_hash_canon (unsigned int hashcode, tree type)
6417 : : {
6418 : 1320673474 : type_hash in;
6419 : 1320673474 : type_hash **loc;
6420 : :
6421 : : /* The hash table only contains main variants, so ensure that's what we're
6422 : : being passed. */
6423 : 1320673474 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
6424 : :
6425 : : /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6426 : : must call that routine before comparing TYPE_ALIGNs. */
6427 : 1320673474 : layout_type (type);
6428 : :
6429 : 1320673474 : in.hash = hashcode;
6430 : 1320673474 : in.type = type;
6431 : :
6432 : 1320673474 : loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT);
6433 : 1320673474 : if (*loc)
6434 : : {
6435 : 626163059 : tree t1 = ((type_hash *) *loc)->type;
6436 : 626163059 : gcc_assert (TYPE_MAIN_VARIANT (t1) == t1
6437 : : && t1 != type);
6438 : 626163059 : if (TYPE_UID (type) + 1 == next_type_uid)
6439 : 621071544 : --next_type_uid;
6440 : : /* Free also min/max values and the cache for integer
6441 : : types. This can't be done in free_node, as LTO frees
6442 : : those on its own. */
6443 : 626163059 : if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE)
6444 : : {
6445 : 36303328 : if (TYPE_MIN_VALUE (type)
6446 : 36303328 : && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
6447 : : {
6448 : : /* Zero is always in TYPE_CACHED_VALUES. */
6449 : 1879243 : if (! TYPE_UNSIGNED (type))
6450 : 1661525 : int_cst_hash_table->remove_elt (TYPE_MIN_VALUE (type));
6451 : 1879243 : ggc_free (TYPE_MIN_VALUE (type));
6452 : : }
6453 : 36303328 : if (TYPE_MAX_VALUE (type)
6454 : 36303328 : && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
6455 : : {
6456 : 1879243 : int_cst_hash_table->remove_elt (TYPE_MAX_VALUE (type));
6457 : 1879243 : ggc_free (TYPE_MAX_VALUE (type));
6458 : : }
6459 : 36303328 : if (TYPE_CACHED_VALUES_P (type))
6460 : 217718 : ggc_free (TYPE_CACHED_VALUES (type));
6461 : : }
6462 : 626163059 : free_node (type);
6463 : 626163059 : return t1;
6464 : : }
6465 : : else
6466 : : {
6467 : 694510415 : struct type_hash *h;
6468 : :
6469 : 694510415 : h = ggc_alloc<type_hash> ();
6470 : 694510415 : h->hash = hashcode;
6471 : 694510415 : h->type = type;
6472 : 694510415 : *loc = h;
6473 : :
6474 : 694510415 : return type;
6475 : : }
6476 : : }
6477 : :
6478 : : static void
6479 : 0 : print_type_hash_statistics (void)
6480 : : {
6481 : 0 : fprintf (stderr, "Type hash: size " HOST_SIZE_T_PRINT_DEC ", "
6482 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6483 : 0 : (fmt_size_t) type_hash_table->size (),
6484 : 0 : (fmt_size_t) type_hash_table->elements (),
6485 : : type_hash_table->collisions ());
6486 : 0 : }
6487 : :
6488 : : /* Given two lists of types
6489 : : (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6490 : : return 1 if the lists contain the same types in the same order.
6491 : : Also, the TREE_PURPOSEs must match. */
6492 : :
6493 : : bool
6494 : 237517677 : type_list_equal (const_tree l1, const_tree l2)
6495 : : {
6496 : 237517677 : const_tree t1, t2;
6497 : :
6498 : 897543820 : for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6499 : 684847118 : if (TREE_VALUE (t1) != TREE_VALUE (t2)
6500 : 684847118 : || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6501 : 24822164 : && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6502 : 1223 : && (TREE_TYPE (TREE_PURPOSE (t1))
6503 : 1223 : == TREE_TYPE (TREE_PURPOSE (t2))))))
6504 : 24820975 : return false;
6505 : :
6506 : 212696702 : return t1 == t2;
6507 : : }
6508 : :
6509 : : /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6510 : : given by TYPE. If the argument list accepts variable arguments,
6511 : : then this function counts only the ordinary arguments. */
6512 : :
6513 : : int
6514 : 78700039 : type_num_arguments (const_tree fntype)
6515 : : {
6516 : 78700039 : int i = 0;
6517 : :
6518 : 306195938 : for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
6519 : : /* If the function does not take a variable number of arguments,
6520 : : the last element in the list will have type `void'. */
6521 : 287649565 : if (VOID_TYPE_P (TREE_VALUE (t)))
6522 : : break;
6523 : : else
6524 : 227495899 : ++i;
6525 : :
6526 : 78700039 : return i;
6527 : : }
6528 : :
6529 : : /* Return the type of the function TYPE's argument ARGNO if known.
6530 : : For vararg function's where ARGNO refers to one of the variadic
6531 : : arguments return null. Otherwise, return a void_type_node for
6532 : : out-of-bounds ARGNO. */
6533 : :
6534 : : tree
6535 : 78180859 : type_argument_type (const_tree fntype, unsigned argno)
6536 : : {
6537 : : /* Treat zero the same as an out-of-bounds argument number. */
6538 : 78180859 : if (!argno)
6539 : 0 : return void_type_node;
6540 : :
6541 : 78180859 : function_args_iterator iter;
6542 : :
6543 : 78180859 : tree argtype;
6544 : 78180859 : unsigned i = 1;
6545 : 168436946 : FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
6546 : : {
6547 : : /* A vararg function's argument list ends in a null. Otherwise,
6548 : : an ordinary function's argument list ends with void. Return
6549 : : null if ARGNO refers to a vararg argument, void_type_node if
6550 : : it's out of bounds, and the formal argument type otherwise. */
6551 : 162873308 : if (!argtype)
6552 : : break;
6553 : :
6554 : 162873308 : if (i == argno || VOID_TYPE_P (argtype))
6555 : : return argtype;
6556 : :
6557 : 90256087 : ++i;
6558 : : }
6559 : :
6560 : : return NULL_TREE;
6561 : : }
6562 : :
6563 : : /* True if integer constants T1 and T2
6564 : : represent the same constant value. */
6565 : :
6566 : : bool
6567 : 1107600151 : tree_int_cst_equal (const_tree t1, const_tree t2)
6568 : : {
6569 : 1107600151 : if (t1 == t2)
6570 : : return true;
6571 : :
6572 : 519710426 : if (t1 == 0 || t2 == 0)
6573 : : return false;
6574 : :
6575 : 519309957 : STRIP_ANY_LOCATION_WRAPPER (t1);
6576 : 519309957 : STRIP_ANY_LOCATION_WRAPPER (t2);
6577 : :
6578 : 519309957 : if (TREE_CODE (t1) == INTEGER_CST
6579 : 515740078 : && TREE_CODE (t2) == INTEGER_CST
6580 : 1035050035 : && wi::to_widest (t1) == wi::to_widest (t2))
6581 : 19045771 : return true;
6582 : :
6583 : : return false;
6584 : : }
6585 : :
6586 : : /* Return true if T is an INTEGER_CST whose numerical value (extended
6587 : : according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
6588 : :
6589 : : bool
6590 : 2046968809 : tree_fits_shwi_p (const_tree t)
6591 : : {
6592 : 2046968809 : return (t != NULL_TREE
6593 : 2046968710 : && TREE_CODE (t) == INTEGER_CST
6594 : 4090543385 : && wi::fits_shwi_p (wi::to_widest (t)));
6595 : : }
6596 : :
6597 : : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6598 : : value (extended according to TYPE_UNSIGNED) fits in a poly_int64. */
6599 : :
6600 : : bool
6601 : 898070301 : tree_fits_poly_int64_p (const_tree t)
6602 : : {
6603 : 898070301 : if (t == NULL_TREE)
6604 : : return false;
6605 : 860203750 : if (POLY_INT_CST_P (t))
6606 : : {
6607 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6608 : : if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t, i))))
6609 : : return false;
6610 : : return true;
6611 : : }
6612 : 860203750 : return (TREE_CODE (t) == INTEGER_CST
6613 : 1720513841 : && wi::fits_shwi_p (wi::to_widest (t)));
6614 : : }
6615 : :
6616 : : /* Return true if T is an INTEGER_CST whose numerical value (extended
6617 : : according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
6618 : :
6619 : : bool
6620 : 3306941081 : tree_fits_uhwi_p (const_tree t)
6621 : : {
6622 : 3306941081 : return (t != NULL_TREE
6623 : 3306504261 : && TREE_CODE (t) == INTEGER_CST
6624 : 6608557114 : && wi::fits_uhwi_p (wi::to_widest (t)));
6625 : : }
6626 : :
6627 : : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6628 : : value (extended according to TYPE_UNSIGNED) fits in a poly_uint64. */
6629 : :
6630 : : bool
6631 : 902098567 : tree_fits_poly_uint64_p (const_tree t)
6632 : : {
6633 : 902098567 : if (t == NULL_TREE)
6634 : : return false;
6635 : 901748846 : if (POLY_INT_CST_P (t))
6636 : : {
6637 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6638 : : if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t, i))))
6639 : : return false;
6640 : : return true;
6641 : : }
6642 : 901748846 : return (TREE_CODE (t) == INTEGER_CST
6643 : 1803499026 : && wi::fits_uhwi_p (wi::to_widest (t)));
6644 : : }
6645 : :
6646 : : /* Return true if T is an INTEGER_CST whose numerical value (extended according
6647 : : to TYPE_UNSIGNED) fits in a sanitize_code_type (uint64_t). */
6648 : :
6649 : : bool
6650 : 90 : tree_fits_sanitize_code_type_p (const_tree t)
6651 : : {
6652 : 90 : if (t == NULL_TREE)
6653 : : return false;
6654 : 90 : return (TREE_CODE (t) == INTEGER_CST
6655 : 180 : && wi::fits_uhwi_p (wi::to_widest (t)));
6656 : : }
6657 : :
6658 : : /* T is an INTEGER_CST whose numerical value (extended according to
6659 : : TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
6660 : : HOST_WIDE_INT. */
6661 : :
6662 : : HOST_WIDE_INT
6663 : 1257352401 : tree_to_shwi (const_tree t)
6664 : : {
6665 : 1257352401 : gcc_assert (tree_fits_shwi_p (t));
6666 : 1257352401 : return TREE_INT_CST_LOW (t);
6667 : : }
6668 : :
6669 : : /* T is an INTEGER_CST whose numerical value (extended according to
6670 : : TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
6671 : : HOST_WIDE_INT. */
6672 : :
6673 : : unsigned HOST_WIDE_INT
6674 : 719067711 : tree_to_uhwi (const_tree t)
6675 : : {
6676 : 719067711 : gcc_assert (tree_fits_uhwi_p (t));
6677 : 719067711 : return TREE_INT_CST_LOW (t);
6678 : : }
6679 : :
6680 : : /* T is an INTEGER_CST whose numerical value (extended according to
6681 : : TYPE_UNSIGNED) fits in a sanitize_code_type. Return that
6682 : : sanitize_code_type. */
6683 : :
6684 : : sanitize_code_type
6685 : 90 : tree_to_sanitize_code_type (const_tree t)
6686 : : {
6687 : 90 : gcc_assert (tree_fits_sanitize_code_type_p (t));
6688 : 90 : return TREE_INT_CST_LOW (t);
6689 : : }
6690 : :
6691 : : /* Return the most significant (sign) bit of T. */
6692 : :
6693 : : int
6694 : 40152874 : tree_int_cst_sign_bit (const_tree t)
6695 : : {
6696 : 40152874 : unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
6697 : :
6698 : 40152874 : return wi::extract_uhwi (wi::to_wide (t), bitno, 1);
6699 : : }
6700 : :
6701 : : /* Return an indication of the sign of the integer constant T.
6702 : : The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6703 : : Note that -1 will never be returned if T's type is unsigned. */
6704 : :
6705 : : int
6706 : 1601470727 : tree_int_cst_sgn (const_tree t)
6707 : : {
6708 : 1601470727 : if (wi::to_wide (t) == 0)
6709 : : return 0;
6710 : 1497566248 : else if (TYPE_UNSIGNED (TREE_TYPE (t)))
6711 : : return 1;
6712 : 64771881 : else if (wi::neg_p (wi::to_wide (t)))
6713 : : return -1;
6714 : : else
6715 : : return 1;
6716 : : }
6717 : :
6718 : : /* Return the minimum number of bits needed to represent VALUE in a
6719 : : signed or unsigned type, UNSIGNEDP says which. */
6720 : :
6721 : : unsigned int
6722 : 3464298 : tree_int_cst_min_precision (tree value, signop sgn)
6723 : : {
6724 : : /* If the value is negative, compute its negative minus 1. The latter
6725 : : adjustment is because the absolute value of the largest negative value
6726 : : is one larger than the largest positive value. This is equivalent to
6727 : : a bit-wise negation, so use that operation instead. */
6728 : :
6729 : 3464298 : if (tree_int_cst_sgn (value) < 0)
6730 : 101194 : value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
6731 : :
6732 : : /* Return the number of bits needed, taking into account the fact
6733 : : that we need one more bit for a signed than unsigned type.
6734 : : If value is 0 or -1, the minimum precision is 1 no matter
6735 : : whether unsignedp is true or false. */
6736 : :
6737 : 3464298 : if (integer_zerop (value))
6738 : : return 1;
6739 : : else
6740 : 4968891 : return tree_floor_log2 (value) + 1 + (sgn == SIGNED ? 1 : 0) ;
6741 : : }
6742 : :
6743 : : /* Return truthvalue of whether T1 is the same tree structure as T2.
6744 : : Return 1 if they are the same.
6745 : : Return 0 if they are understandably different.
6746 : : Return -1 if either contains tree structure not understood by
6747 : : this function. */
6748 : :
6749 : : int
6750 : 178946157 : simple_cst_equal (const_tree t1, const_tree t2)
6751 : : {
6752 : 183028757 : enum tree_code code1, code2;
6753 : 183028757 : int cmp;
6754 : 183028757 : int i;
6755 : :
6756 : 183028757 : if (t1 == t2)
6757 : : return 1;
6758 : 116462024 : if (t1 == 0 || t2 == 0)
6759 : : return 0;
6760 : :
6761 : : /* For location wrappers to be the same, they must be at the same
6762 : : source location (and wrap the same thing). */
6763 : 108273962 : if (location_wrapper_p (t1) && location_wrapper_p (t2))
6764 : : {
6765 : 11145195 : if (EXPR_LOCATION (t1) != EXPR_LOCATION (t2))
6766 : : return 0;
6767 : 493 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6768 : : }
6769 : :
6770 : 97128767 : code1 = TREE_CODE (t1);
6771 : 97128767 : code2 = TREE_CODE (t2);
6772 : :
6773 : 97128767 : if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
6774 : : {
6775 : 4069551 : if (CONVERT_EXPR_CODE_P (code2)
6776 : 4068954 : || code2 == NON_LVALUE_EXPR)
6777 : 597 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6778 : : else
6779 : 4068954 : return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
6780 : : }
6781 : :
6782 : 93059216 : else if (CONVERT_EXPR_CODE_P (code2)
6783 : 93059201 : || code2 == NON_LVALUE_EXPR)
6784 : 118 : return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
6785 : :
6786 : 93059098 : if (code1 != code2)
6787 : : return 0;
6788 : :
6789 : 88436844 : switch (code1)
6790 : : {
6791 : 73690314 : case INTEGER_CST:
6792 : 73690314 : return wi::to_widest (t1) == wi::to_widest (t2);
6793 : :
6794 : 89 : case REAL_CST:
6795 : 89 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
6796 : :
6797 : 0 : case FIXED_CST:
6798 : 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
6799 : :
6800 : 3045024 : case STRING_CST:
6801 : 3045024 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
6802 : 3045024 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
6803 : 3464668 : TREE_STRING_LENGTH (t1)));
6804 : :
6805 : 72 : case CONSTRUCTOR:
6806 : 72 : {
6807 : 72 : unsigned HOST_WIDE_INT idx;
6808 : 72 : vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1);
6809 : 72 : vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);
6810 : :
6811 : 90 : if (vec_safe_length (v1) != vec_safe_length (v2))
6812 : : return false;
6813 : :
6814 : 78 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
6815 : : /* ??? Should we handle also fields here? */
6816 : 9 : if (!simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value))
6817 : : return false;
6818 : : return true;
6819 : : }
6820 : :
6821 : 0 : case SAVE_EXPR:
6822 : 0 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6823 : :
6824 : 213878 : case CALL_EXPR:
6825 : 213878 : cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
6826 : 213878 : if (cmp <= 0)
6827 : : return cmp;
6828 : 87867 : if (call_expr_nargs (t1) != call_expr_nargs (t2))
6829 : : return 0;
6830 : 87867 : {
6831 : 87867 : const_tree arg1, arg2;
6832 : 87867 : const_call_expr_arg_iterator iter1, iter2;
6833 : 175734 : for (arg1 = first_const_call_expr_arg (t1, &iter1),
6834 : 87867 : arg2 = first_const_call_expr_arg (t2, &iter2);
6835 : 87937 : arg1 && arg2;
6836 : 70 : arg1 = next_const_call_expr_arg (&iter1),
6837 : 70 : arg2 = next_const_call_expr_arg (&iter2))
6838 : : {
6839 : 87855 : cmp = simple_cst_equal (arg1, arg2);
6840 : 87855 : if (cmp <= 0)
6841 : : return cmp;
6842 : : }
6843 : 82 : return arg1 == arg2;
6844 : : }
6845 : :
6846 : 12013 : case TARGET_EXPR:
6847 : : /* Special case: if either target is an unallocated VAR_DECL,
6848 : : it means that it's going to be unified with whatever the
6849 : : TARGET_EXPR is really supposed to initialize, so treat it
6850 : : as being equivalent to anything. */
6851 : 12013 : if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
6852 : 12013 : && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
6853 : 12013 : && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
6854 : 12013 : || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
6855 : 0 : && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
6856 : 0 : && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
6857 : : cmp = 1;
6858 : : else
6859 : 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6860 : :
6861 : 0 : if (cmp <= 0)
6862 : : return cmp;
6863 : :
6864 : 12013 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
6865 : :
6866 : 0 : case WITH_CLEANUP_EXPR:
6867 : 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6868 : 0 : if (cmp <= 0)
6869 : : return cmp;
6870 : :
6871 : 0 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
6872 : :
6873 : 425 : case COMPONENT_REF:
6874 : 425 : if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
6875 : 425 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6876 : :
6877 : : return 0;
6878 : :
6879 : : case VAR_DECL:
6880 : : case PARM_DECL:
6881 : : case CONST_DECL:
6882 : : case FUNCTION_DECL:
6883 : : return 0;
6884 : :
6885 : 11412885 : default:
6886 : 11412885 : if (POLY_INT_CST_P (t1))
6887 : : /* A false return means maybe_ne rather than known_ne. */
6888 : : return known_eq (poly_widest_int::from (poly_int_cst_value (t1),
6889 : : TYPE_SIGN (TREE_TYPE (t1))),
6890 : : poly_widest_int::from (poly_int_cst_value (t2),
6891 : : TYPE_SIGN (TREE_TYPE (t2))));
6892 : 11412885 : break;
6893 : : }
6894 : :
6895 : : /* This general rule works for most tree codes. All exceptions should be
6896 : : handled above. If this is a language-specific tree code, we can't
6897 : : trust what might be in the operand, so say we don't know
6898 : : the situation. */
6899 : 11412885 : if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
6900 : : return -1;
6901 : :
6902 : 6618554 : switch (TREE_CODE_CLASS (code1))
6903 : : {
6904 : : case tcc_unary:
6905 : : case tcc_binary:
6906 : : case tcc_comparison:
6907 : : case tcc_expression:
6908 : : case tcc_reference:
6909 : : case tcc_statement:
6910 : : cmp = 1;
6911 : 2105 : for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
6912 : : {
6913 : 1625 : cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
6914 : 1625 : if (cmp <= 0)
6915 : : return cmp;
6916 : : }
6917 : :
6918 : : return cmp;
6919 : :
6920 : : default:
6921 : : return -1;
6922 : : }
6923 : : }
6924 : :
6925 : : /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6926 : : Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6927 : : than U, respectively. */
6928 : :
6929 : : int
6930 : 1322758061 : compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
6931 : : {
6932 : 1322758061 : if (tree_int_cst_sgn (t) < 0)
6933 : : return -1;
6934 : 1322757785 : else if (!tree_fits_uhwi_p (t))
6935 : : return 1;
6936 : 1322757760 : else if (TREE_INT_CST_LOW (t) == u)
6937 : : return 0;
6938 : 1199315056 : else if (TREE_INT_CST_LOW (t) < u)
6939 : : return -1;
6940 : : else
6941 : 12219911 : return 1;
6942 : : }
6943 : :
6944 : : /* Return true if SIZE represents a constant size that is in bounds of
6945 : : what the middle-end and the backend accepts (covering not more than
6946 : : half of the address-space).
6947 : : When PERR is non-null, set *PERR on failure to the description of
6948 : : why SIZE is not valid. */
6949 : :
6950 : : bool
6951 : 54624808 : valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */)
6952 : : {
6953 : 54624808 : if (POLY_INT_CST_P (size))
6954 : : {
6955 : : if (TREE_OVERFLOW (size))
6956 : : return false;
6957 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
6958 : : if (!valid_constant_size_p (POLY_INT_CST_COEFF (size, i)))
6959 : : return false;
6960 : : return true;
6961 : : }
6962 : :
6963 : 54624808 : cst_size_error error;
6964 : 54624808 : if (!perr)
6965 : 49728542 : perr = &error;
6966 : :
6967 : 54624808 : if (TREE_CODE (size) != INTEGER_CST)
6968 : : {
6969 : 3 : *perr = cst_size_not_constant;
6970 : 3 : return false;
6971 : : }
6972 : :
6973 : 54624805 : if (TREE_OVERFLOW_P (size))
6974 : : {
6975 : 60 : *perr = cst_size_overflow;
6976 : 60 : return false;
6977 : : }
6978 : :
6979 : 54624745 : if (tree_int_cst_sgn (size) < 0)
6980 : : {
6981 : 425 : *perr = cst_size_negative;
6982 : 425 : return false;
6983 : : }
6984 : 109248640 : if (!tree_fits_uhwi_p (size)
6985 : 163872960 : || (wi::to_widest (TYPE_MAX_VALUE (sizetype))
6986 : 163872960 : < wi::to_widest (size) * 2))
6987 : : {
6988 : 624 : *perr = cst_size_too_big;
6989 : 624 : return false;
6990 : : }
6991 : :
6992 : : return true;
6993 : : }
6994 : :
6995 : : /* Return the precision of the type, or for a complex or vector type the
6996 : : precision of the type of its elements. */
6997 : :
6998 : : unsigned int
6999 : 7033917033 : element_precision (const_tree type)
7000 : : {
7001 : 7033917033 : if (!TYPE_P (type))
7002 : 6529925 : type = TREE_TYPE (type);
7003 : 7033917033 : enum tree_code code = TREE_CODE (type);
7004 : 7033917033 : if (code == COMPLEX_TYPE || code == VECTOR_TYPE)
7005 : 53488630 : type = TREE_TYPE (type);
7006 : :
7007 : 7033917033 : return TYPE_PRECISION (type);
7008 : : }
7009 : :
7010 : : /* Return true if CODE represents an associative tree code. Otherwise
7011 : : return false. */
7012 : : bool
7013 : 35371467 : associative_tree_code (enum tree_code code)
7014 : : {
7015 : 35371467 : switch (code)
7016 : : {
7017 : : case BIT_IOR_EXPR:
7018 : : case BIT_AND_EXPR:
7019 : : case BIT_XOR_EXPR:
7020 : : case PLUS_EXPR:
7021 : : case MULT_EXPR:
7022 : : case MIN_EXPR:
7023 : : case MAX_EXPR:
7024 : : return true;
7025 : :
7026 : 25046446 : default:
7027 : 25046446 : break;
7028 : : }
7029 : 25046446 : return false;
7030 : : }
7031 : :
7032 : : /* Return true if CODE represents a commutative tree code. Otherwise
7033 : : return false. */
7034 : : bool
7035 : 1648780364 : commutative_tree_code (enum tree_code code)
7036 : : {
7037 : 1648780364 : switch (code)
7038 : : {
7039 : : case PLUS_EXPR:
7040 : : case MULT_EXPR:
7041 : : case MULT_HIGHPART_EXPR:
7042 : : case MIN_EXPR:
7043 : : case MAX_EXPR:
7044 : : case BIT_IOR_EXPR:
7045 : : case BIT_XOR_EXPR:
7046 : : case BIT_AND_EXPR:
7047 : : case NE_EXPR:
7048 : : case EQ_EXPR:
7049 : : case UNORDERED_EXPR:
7050 : : case ORDERED_EXPR:
7051 : : case UNEQ_EXPR:
7052 : : case LTGT_EXPR:
7053 : : case TRUTH_AND_EXPR:
7054 : : case TRUTH_XOR_EXPR:
7055 : : case TRUTH_OR_EXPR:
7056 : : case WIDEN_MULT_EXPR:
7057 : : case VEC_WIDEN_MULT_HI_EXPR:
7058 : : case VEC_WIDEN_MULT_LO_EXPR:
7059 : : case VEC_WIDEN_MULT_EVEN_EXPR:
7060 : : case VEC_WIDEN_MULT_ODD_EXPR:
7061 : : return true;
7062 : :
7063 : 858090197 : default:
7064 : 858090197 : break;
7065 : : }
7066 : 858090197 : return false;
7067 : : }
7068 : :
7069 : : /* Return true if CODE represents a ternary tree code for which the
7070 : : first two operands are commutative. Otherwise return false. */
7071 : : bool
7072 : 76296218 : commutative_ternary_tree_code (enum tree_code code)
7073 : : {
7074 : 76296218 : switch (code)
7075 : : {
7076 : : case WIDEN_MULT_PLUS_EXPR:
7077 : : case WIDEN_MULT_MINUS_EXPR:
7078 : : case DOT_PROD_EXPR:
7079 : : return true;
7080 : :
7081 : 76287987 : default:
7082 : 76287987 : break;
7083 : : }
7084 : 76287987 : return false;
7085 : : }
7086 : :
7087 : : /* Returns true if CODE can overflow. */
7088 : :
7089 : : bool
7090 : 2956 : operation_can_overflow (enum tree_code code)
7091 : : {
7092 : 2956 : switch (code)
7093 : : {
7094 : : case PLUS_EXPR:
7095 : : case MINUS_EXPR:
7096 : : case MULT_EXPR:
7097 : : case LSHIFT_EXPR:
7098 : : /* Can overflow in various ways. */
7099 : : return true;
7100 : : case TRUNC_DIV_EXPR:
7101 : : case EXACT_DIV_EXPR:
7102 : : case FLOOR_DIV_EXPR:
7103 : : case CEIL_DIV_EXPR:
7104 : : /* For INT_MIN / -1. */
7105 : : return true;
7106 : : case NEGATE_EXPR:
7107 : : case ABS_EXPR:
7108 : : /* For -INT_MIN. */
7109 : : return true;
7110 : 144 : default:
7111 : : /* These operators cannot overflow. */
7112 : 144 : return false;
7113 : : }
7114 : : }
7115 : :
7116 : : /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
7117 : : ftrapv doesn't generate trapping insns for CODE. */
7118 : :
7119 : : bool
7120 : 5811355 : operation_no_trapping_overflow (tree type, enum tree_code code)
7121 : : {
7122 : 5811355 : gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type));
7123 : :
7124 : : /* We don't generate instructions that trap on overflow for complex or vector
7125 : : types. */
7126 : 5811355 : if (!INTEGRAL_TYPE_P (type))
7127 : : return true;
7128 : :
7129 : 5811355 : if (!TYPE_OVERFLOW_TRAPS (type))
7130 : : return true;
7131 : :
7132 : 442 : switch (code)
7133 : : {
7134 : : case PLUS_EXPR:
7135 : : case MINUS_EXPR:
7136 : : case MULT_EXPR:
7137 : : case NEGATE_EXPR:
7138 : : case ABS_EXPR:
7139 : : /* These operators can overflow, and -ftrapv generates trapping code for
7140 : : these. */
7141 : : return false;
7142 : : case TRUNC_DIV_EXPR:
7143 : : case EXACT_DIV_EXPR:
7144 : : case FLOOR_DIV_EXPR:
7145 : : case CEIL_DIV_EXPR:
7146 : : case LSHIFT_EXPR:
7147 : : /* These operators can overflow, but -ftrapv does not generate trapping
7148 : : code for these. */
7149 : : return true;
7150 : : default:
7151 : : /* These operators cannot overflow. */
7152 : : return true;
7153 : : }
7154 : : }
7155 : :
7156 : : /* Constructors for pointer, array and function types.
7157 : : (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7158 : : constructed by language-dependent code, not here.) */
7159 : :
7160 : : /* Construct, lay out and return the type of pointers to TO_TYPE with
7161 : : mode MODE. If MODE is VOIDmode, a pointer mode for the address
7162 : : space of TO_TYPE will be picked. If CAN_ALIAS_ALL is TRUE,
7163 : : indicate this type can reference all of memory. If such a type has
7164 : : already been constructed, reuse it. */
7165 : :
7166 : : tree
7167 : 2099852578 : build_pointer_type_for_mode (tree to_type, machine_mode mode,
7168 : : bool can_alias_all)
7169 : : {
7170 : 2099852578 : tree t;
7171 : 2099852578 : bool could_alias = can_alias_all;
7172 : :
7173 : 2099852578 : if (to_type == error_mark_node)
7174 : : return error_mark_node;
7175 : :
7176 : 2099852572 : if (mode == VOIDmode)
7177 : : {
7178 : 1980951709 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7179 : 1980951709 : mode = targetm.addr_space.pointer_mode (as);
7180 : : }
7181 : :
7182 : : /* If the pointed-to type has the may_alias attribute set, force
7183 : : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7184 : 2099852572 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7185 : 4448627 : can_alias_all = true;
7186 : :
7187 : : /* In some cases, languages will have things that aren't a POINTER_TYPE
7188 : : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7189 : : In that case, return that type without regard to the rest of our
7190 : : operands.
7191 : :
7192 : : ??? This is a kludge, but consistent with the way this function has
7193 : : always operated and there doesn't seem to be a good way to avoid this
7194 : : at the moment. */
7195 : 2099852572 : if (TYPE_POINTER_TO (to_type) != 0
7196 : 2099852572 : && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
7197 : 48630 : return TYPE_POINTER_TO (to_type);
7198 : :
7199 : : /* First, if we already have a type for pointers to TO_TYPE and it's
7200 : : the proper mode, use it. */
7201 : 2100384582 : for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
7202 : 1973221217 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7203 : : return t;
7204 : :
7205 : 127163365 : t = make_node (POINTER_TYPE);
7206 : :
7207 : 127163365 : TREE_TYPE (t) = to_type;
7208 : 127163365 : SET_TYPE_MODE (t, mode);
7209 : 127163365 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7210 : 127163365 : TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
7211 : 127163365 : TYPE_POINTER_TO (to_type) = t;
7212 : :
7213 : : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7214 : 127163365 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7215 : 5039879 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7216 : 122123486 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7217 : 37226018 : TYPE_CANONICAL (t)
7218 : 74452036 : = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
7219 : : mode, false);
7220 : :
7221 : : /* Lay out the type. This function has many callers that are concerned
7222 : : with expression-construction, and this simplifies them all. */
7223 : 127163365 : layout_type (t);
7224 : :
7225 : 127163365 : return t;
7226 : : }
7227 : :
7228 : : /* By default build pointers in ptr_mode. */
7229 : :
7230 : : tree
7231 : 1980257118 : build_pointer_type (tree to_type)
7232 : : {
7233 : 1980257118 : return build_pointer_type_for_mode (to_type, VOIDmode, false);
7234 : : }
7235 : :
7236 : : /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7237 : :
7238 : : tree
7239 : 544508268 : build_reference_type_for_mode (tree to_type, machine_mode mode,
7240 : : bool can_alias_all)
7241 : : {
7242 : 544508268 : tree t;
7243 : 544508268 : bool could_alias = can_alias_all;
7244 : :
7245 : 544508268 : if (to_type == error_mark_node)
7246 : : return error_mark_node;
7247 : :
7248 : 544508268 : if (mode == VOIDmode)
7249 : : {
7250 : 449121533 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7251 : 449121533 : mode = targetm.addr_space.pointer_mode (as);
7252 : : }
7253 : :
7254 : : /* If the pointed-to type has the may_alias attribute set, force
7255 : : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7256 : 544508268 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7257 : 717162 : can_alias_all = true;
7258 : :
7259 : : /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7260 : : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7261 : : In that case, return that type without regard to the rest of our
7262 : : operands.
7263 : :
7264 : : ??? This is a kludge, but consistent with the way this function has
7265 : : always operated and there doesn't seem to be a good way to avoid this
7266 : : at the moment. */
7267 : 544508268 : if (TYPE_REFERENCE_TO (to_type) != 0
7268 : 544508268 : && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
7269 : 0 : return TYPE_REFERENCE_TO (to_type);
7270 : :
7271 : : /* First, if we already have a type for pointers to TO_TYPE and it's
7272 : : the proper mode, use it. */
7273 : 544508268 : for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
7274 : 470005083 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7275 : : return t;
7276 : :
7277 : 74503185 : t = make_node (REFERENCE_TYPE);
7278 : :
7279 : 74503185 : TREE_TYPE (t) = to_type;
7280 : 74503185 : SET_TYPE_MODE (t, mode);
7281 : 74503185 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7282 : 74503185 : TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
7283 : 74503185 : TYPE_REFERENCE_TO (to_type) = t;
7284 : :
7285 : : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7286 : 74503185 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7287 : 3563792 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7288 : 70939393 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7289 : 41932541 : TYPE_CANONICAL (t)
7290 : 83865082 : = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
7291 : : mode, false);
7292 : :
7293 : 74503185 : layout_type (t);
7294 : :
7295 : 74503185 : return t;
7296 : : }
7297 : :
7298 : :
7299 : : /* Build the node for the type of references-to-TO_TYPE by default
7300 : : in ptr_mode. */
7301 : :
7302 : : tree
7303 : 21730167 : build_reference_type (tree to_type)
7304 : : {
7305 : 21730167 : return build_reference_type_for_mode (to_type, VOIDmode, false);
7306 : : }
7307 : :
7308 : : #define MAX_INT_CACHED_PREC \
7309 : : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7310 : : static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
7311 : :
7312 : : static void
7313 : 257130 : clear_nonstandard_integer_type_cache (void)
7314 : : {
7315 : 33684030 : for (size_t i = 0 ; i < 2 * MAX_INT_CACHED_PREC + 2 ; i++)
7316 : : {
7317 : 33426900 : nonstandard_integer_type_cache[i] = NULL;
7318 : : }
7319 : 0 : }
7320 : :
7321 : : /* Builds a signed or unsigned integer type of precision PRECISION.
7322 : : Used for C bitfields whose precision does not match that of
7323 : : built-in target types. */
7324 : : tree
7325 : 63460776 : build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
7326 : : int unsignedp)
7327 : : {
7328 : 63460776 : tree itype, ret;
7329 : :
7330 : 63460776 : if (unsignedp)
7331 : 54702676 : unsignedp = MAX_INT_CACHED_PREC + 1;
7332 : :
7333 : 63460776 : if (precision <= MAX_INT_CACHED_PREC)
7334 : : {
7335 : 63035454 : itype = nonstandard_integer_type_cache[precision + unsignedp];
7336 : 63035454 : if (itype)
7337 : : return itype;
7338 : : }
7339 : :
7340 : 1079765 : itype = make_node (INTEGER_TYPE);
7341 : 1079765 : TYPE_PRECISION (itype) = precision;
7342 : :
7343 : 1079765 : if (unsignedp)
7344 : 733157 : fixup_unsigned_type (itype);
7345 : : else
7346 : 346608 : fixup_signed_type (itype);
7347 : :
7348 : 1079765 : inchash::hash hstate;
7349 : 1079765 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7350 : 1079765 : ret = type_hash_canon (hstate.end (), itype);
7351 : 1079765 : if (precision <= MAX_INT_CACHED_PREC)
7352 : 654443 : nonstandard_integer_type_cache[precision + unsignedp] = ret;
7353 : :
7354 : : return ret;
7355 : : }
7356 : :
7357 : : #define MAX_BOOL_CACHED_PREC \
7358 : : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7359 : : static GTY(()) tree nonstandard_boolean_type_cache[MAX_BOOL_CACHED_PREC + 1];
7360 : :
7361 : : /* Builds a boolean type of precision PRECISION.
7362 : : Used for boolean vectors to choose proper vector element size. */
7363 : : tree
7364 : 1953107 : build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision)
7365 : : {
7366 : 1953107 : tree type;
7367 : :
7368 : 1953107 : if (precision <= MAX_BOOL_CACHED_PREC)
7369 : : {
7370 : 1948798 : type = nonstandard_boolean_type_cache[precision];
7371 : 1948798 : if (type)
7372 : : return type;
7373 : : }
7374 : :
7375 : 76977 : type = make_node (BOOLEAN_TYPE);
7376 : 76977 : TYPE_PRECISION (type) = precision;
7377 : 76977 : fixup_signed_type (type);
7378 : :
7379 : 76977 : if (precision <= MAX_INT_CACHED_PREC)
7380 : 72668 : nonstandard_boolean_type_cache[precision] = type;
7381 : :
7382 : : return type;
7383 : : }
7384 : :
7385 : : static GTY(()) vec<tree, va_gc> *bitint_type_cache;
7386 : :
7387 : : /* Builds a signed or unsigned _BitInt(PRECISION) type. */
7388 : : tree
7389 : 1538679 : build_bitint_type (unsigned HOST_WIDE_INT precision, int unsignedp)
7390 : : {
7391 : 1538679 : tree itype, ret;
7392 : :
7393 : 1573610 : gcc_checking_assert (precision >= 1 + !unsignedp);
7394 : :
7395 : 1538679 : if (unsignedp)
7396 : 34931 : unsignedp = MAX_INT_CACHED_PREC + 1;
7397 : :
7398 : 1538679 : if (bitint_type_cache == NULL)
7399 : 499 : vec_safe_grow_cleared (bitint_type_cache, 2 * MAX_INT_CACHED_PREC + 2);
7400 : :
7401 : 1538679 : if (precision <= MAX_INT_CACHED_PREC)
7402 : : {
7403 : 36586 : itype = (*bitint_type_cache)[precision + unsignedp];
7404 : 36586 : if (itype)
7405 : : return itype;
7406 : : }
7407 : :
7408 : 1503522 : itype = make_node (BITINT_TYPE);
7409 : 1503522 : TYPE_PRECISION (itype) = precision;
7410 : :
7411 : 1503522 : if (unsignedp)
7412 : 28431 : fixup_unsigned_type (itype);
7413 : : else
7414 : 1475091 : fixup_signed_type (itype);
7415 : :
7416 : 1503522 : inchash::hash hstate;
7417 : 1503522 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7418 : 1503522 : ret = type_hash_canon (hstate.end (), itype);
7419 : 1503522 : if (precision <= MAX_INT_CACHED_PREC)
7420 : 1429 : (*bitint_type_cache)[precision + unsignedp] = ret;
7421 : :
7422 : : return ret;
7423 : : }
7424 : :
7425 : : /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7426 : : or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7427 : : is true, reuse such a type that has already been constructed. */
7428 : :
7429 : : static tree
7430 : 39027716 : build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
7431 : : {
7432 : 39027716 : tree itype = make_node (INTEGER_TYPE);
7433 : :
7434 : 39027716 : TREE_TYPE (itype) = type;
7435 : :
7436 : 39027716 : TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
7437 : 39027716 : TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
7438 : :
7439 : 39027716 : TYPE_PRECISION (itype) = TYPE_PRECISION (type);
7440 : 39027716 : SET_TYPE_MODE (itype, TYPE_MODE (type));
7441 : 39027716 : TYPE_SIZE (itype) = TYPE_SIZE (type);
7442 : 39027716 : TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
7443 : 39027716 : SET_TYPE_ALIGN (itype, TYPE_ALIGN (type));
7444 : 39027716 : TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
7445 : 39027716 : SET_TYPE_WARN_IF_NOT_ALIGN (itype, TYPE_WARN_IF_NOT_ALIGN (type));
7446 : :
7447 : 39027716 : if (!shared)
7448 : : return itype;
7449 : :
7450 : 39027716 : if ((TYPE_MIN_VALUE (itype)
7451 : 39027716 : && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
7452 : 78054603 : || (TYPE_MAX_VALUE (itype)
7453 : 38485724 : && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
7454 : : {
7455 : : /* Since we cannot reliably merge this type, we need to compare it using
7456 : : structural equality checks. */
7457 : 975177 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
7458 : 975177 : return itype;
7459 : : }
7460 : :
7461 : 38052539 : hashval_t hash = type_hash_canon_hash (itype);
7462 : 38052539 : itype = type_hash_canon (hash, itype);
7463 : :
7464 : 38052539 : return itype;
7465 : : }
7466 : :
7467 : : /* Wrapper around build_range_type_1 with SHARED set to true. */
7468 : :
7469 : : tree
7470 : 39027716 : build_range_type (tree type, tree lowval, tree highval)
7471 : : {
7472 : 39027716 : return build_range_type_1 (type, lowval, highval, true);
7473 : : }
7474 : :
7475 : : /* Wrapper around build_range_type_1 with SHARED set to false. */
7476 : :
7477 : : tree
7478 : 0 : build_nonshared_range_type (tree type, tree lowval, tree highval)
7479 : : {
7480 : 0 : return build_range_type_1 (type, lowval, highval, false);
7481 : : }
7482 : :
7483 : : /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7484 : : MAXVAL should be the maximum value in the domain
7485 : : (one less than the length of the array).
7486 : :
7487 : : The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7488 : : We don't enforce this limit, that is up to caller (e.g. language front end).
7489 : : The limit exists because the result is a signed type and we don't handle
7490 : : sizes that use more than one HOST_WIDE_INT. */
7491 : :
7492 : : tree
7493 : 36320573 : build_index_type (tree maxval)
7494 : : {
7495 : 36320573 : return build_range_type (sizetype, size_zero_node, maxval);
7496 : : }
7497 : :
7498 : : /* Return true if the debug information for TYPE, a subtype, should be emitted
7499 : : as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7500 : : high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7501 : : debug info and doesn't reflect the source code. */
7502 : :
7503 : : bool
7504 : 18 : subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
7505 : : {
7506 : 18 : tree base_type = TREE_TYPE (type), low, high;
7507 : :
7508 : : /* Subrange types have a base type which is an integral type. */
7509 : 18 : if (!INTEGRAL_TYPE_P (base_type))
7510 : : return false;
7511 : :
7512 : : /* Get the real bounds of the subtype. */
7513 : 18 : if (lang_hooks.types.get_subrange_bounds)
7514 : 0 : lang_hooks.types.get_subrange_bounds (type, &low, &high);
7515 : : else
7516 : : {
7517 : 18 : low = TYPE_MIN_VALUE (type);
7518 : 18 : high = TYPE_MAX_VALUE (type);
7519 : : }
7520 : :
7521 : : /* If the type and its base type have the same representation and the same
7522 : : name, then the type is not a subrange but a copy of the base type. */
7523 : 18 : if ((TREE_CODE (base_type) == INTEGER_TYPE
7524 : 18 : || TREE_CODE (base_type) == BOOLEAN_TYPE)
7525 : 18 : && int_size_in_bytes (type) == int_size_in_bytes (base_type)
7526 : 18 : && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
7527 : 0 : && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))
7528 : 18 : && TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (base_type))
7529 : : return false;
7530 : :
7531 : 18 : if (lowval)
7532 : 18 : *lowval = low;
7533 : 18 : if (highval)
7534 : 18 : *highval = high;
7535 : : return true;
7536 : : }
7537 : :
7538 : : /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7539 : : and number of elements specified by the range of values of INDEX_TYPE.
7540 : : If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
7541 : : If SHARED is true, reuse such a type that has already been constructed.
7542 : : If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type. */
7543 : :
7544 : : tree
7545 : 61970737 : build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
7546 : : bool shared, bool set_canonical)
7547 : : {
7548 : 61970737 : tree t;
7549 : :
7550 : 61970737 : if (TREE_CODE (elt_type) == FUNCTION_TYPE)
7551 : : {
7552 : 0 : error ("arrays of functions are not meaningful");
7553 : 0 : elt_type = integer_type_node;
7554 : : }
7555 : :
7556 : 61970737 : t = make_node (ARRAY_TYPE);
7557 : 61970737 : TREE_TYPE (t) = elt_type;
7558 : 61970737 : TYPE_DOMAIN (t) = index_type;
7559 : 61970737 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
7560 : 61970737 : TYPE_TYPELESS_STORAGE (t) = typeless_storage;
7561 : :
7562 : : /* Set TYPE_STRUCTURAL_EQUALITY_P. */
7563 : 61970737 : if (set_canonical
7564 : 61970737 : && (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7565 : 61939626 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7566 : 61684210 : || in_lto_p))
7567 : 358811 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7568 : :
7569 : 61970737 : layout_type (t);
7570 : :
7571 : 61970737 : if (shared)
7572 : : {
7573 : 61970710 : hashval_t hash = type_hash_canon_hash (t);
7574 : 61970710 : tree probe_type = t;
7575 : 61970710 : t = type_hash_canon (hash, t);
7576 : 61970710 : if (t != probe_type)
7577 : : return t;
7578 : : }
7579 : :
7580 : 10123682 : if (TYPE_CANONICAL (t) == t && set_canonical)
7581 : : {
7582 : 9813735 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7583 : 9813735 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7584 : 19627470 : || in_lto_p)
7585 : 0 : gcc_unreachable ();
7586 : 9813735 : else if (TYPE_CANONICAL (elt_type) != elt_type
7587 : 9813735 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
7588 : 100726 : TYPE_CANONICAL (t)
7589 : 292136 : = build_array_type_1 (TYPE_CANONICAL (elt_type),
7590 : : index_type
7591 : 90684 : ? TYPE_CANONICAL (index_type) : NULL_TREE,
7592 : : typeless_storage, shared, set_canonical);
7593 : : }
7594 : :
7595 : : return t;
7596 : : }
7597 : :
7598 : : /* Wrapper around build_array_type_1 with SHARED set to true. */
7599 : :
7600 : : tree
7601 : 61869984 : build_array_type (tree elt_type, tree index_type, bool typeless_storage)
7602 : : {
7603 : 61869984 : return
7604 : 61869984 : build_array_type_1 (elt_type, index_type, typeless_storage, true, true);
7605 : : }
7606 : :
7607 : : /* Wrapper around build_array_type_1 with SHARED set to false. */
7608 : :
7609 : : tree
7610 : 0 : build_nonshared_array_type (tree elt_type, tree index_type)
7611 : : {
7612 : 0 : return build_array_type_1 (elt_type, index_type, false, false, true);
7613 : : }
7614 : :
7615 : : /* Return a representation of ELT_TYPE[NELTS], using indices of type
7616 : : sizetype. */
7617 : :
7618 : : tree
7619 : 1450207 : build_array_type_nelts (tree elt_type, poly_uint64 nelts)
7620 : : {
7621 : 1450207 : return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
7622 : : }
7623 : :
7624 : : /* Computes the canonical argument types from the argument type list
7625 : : ARGTYPES.
7626 : :
7627 : : Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7628 : : on entry to this function, or if any of the ARGTYPES are
7629 : : structural.
7630 : :
7631 : : Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7632 : : true on entry to this function, or if any of the ARGTYPES are
7633 : : non-canonical.
7634 : :
7635 : : Returns a canonical argument list, which may be ARGTYPES when the
7636 : : canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7637 : : true) or would not differ from ARGTYPES. */
7638 : :
7639 : : static tree
7640 : 893745199 : maybe_canonicalize_argtypes (tree argtypes,
7641 : : bool *any_structural_p,
7642 : : bool *any_noncanonical_p)
7643 : : {
7644 : 893745199 : tree arg;
7645 : 893745199 : bool any_noncanonical_argtypes_p = false;
7646 : :
7647 : 3127416315 : for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
7648 : : {
7649 : 2233671116 : if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
7650 : : /* Fail gracefully by stating that the type is structural. */
7651 : 4068 : *any_structural_p = true;
7652 : 2233667048 : else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
7653 : 32942199 : *any_structural_p = true;
7654 : 2200724849 : else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
7655 : 2200724849 : || TREE_PURPOSE (arg))
7656 : : /* If the argument has a default argument, we consider it
7657 : : non-canonical even though the type itself is canonical.
7658 : : That way, different variants of function and method types
7659 : : with default arguments will all point to the variant with
7660 : : no defaults as their canonical type. */
7661 : : any_noncanonical_argtypes_p = true;
7662 : : }
7663 : :
7664 : 893745199 : if (*any_structural_p)
7665 : : return argtypes;
7666 : :
7667 : 806732996 : if (any_noncanonical_argtypes_p)
7668 : : {
7669 : : /* Build the canonical list of argument types. */
7670 : : tree canon_argtypes = NULL_TREE;
7671 : : bool is_void = false;
7672 : :
7673 : 811919608 : for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
7674 : : {
7675 : 624435134 : if (arg == void_list_node)
7676 : : is_void = true;
7677 : : else
7678 : 876340272 : canon_argtypes = tree_cons (NULL_TREE,
7679 : 438170136 : TYPE_CANONICAL (TREE_VALUE (arg)),
7680 : : canon_argtypes);
7681 : : }
7682 : :
7683 : 187484474 : canon_argtypes = nreverse (canon_argtypes);
7684 : 187484474 : if (is_void)
7685 : 186264998 : canon_argtypes = chainon (canon_argtypes, void_list_node);
7686 : :
7687 : : /* There is a non-canonical type. */
7688 : 187484474 : *any_noncanonical_p = true;
7689 : 187484474 : return canon_argtypes;
7690 : : }
7691 : :
7692 : : /* The canonical argument types are the same as ARGTYPES. */
7693 : : return argtypes;
7694 : : }
7695 : :
7696 : : /* Construct, lay out and return
7697 : : the type of functions returning type VALUE_TYPE
7698 : : given arguments of types ARG_TYPES.
7699 : : ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7700 : : are data type nodes for the arguments of the function.
7701 : : NO_NAMED_ARGS_STDARG_P is true if this is a prototyped
7702 : : variable-arguments function with (...) prototype (no named arguments).
7703 : : If such a type has already been constructed, reuse it. */
7704 : :
7705 : : tree
7706 : 602316099 : build_function_type (tree value_type, tree arg_types,
7707 : : bool no_named_args_stdarg_p)
7708 : : {
7709 : 602316099 : tree t;
7710 : 602316099 : inchash::hash hstate;
7711 : 602316099 : bool any_structural_p, any_noncanonical_p;
7712 : 602316099 : tree canon_argtypes;
7713 : :
7714 : 602316099 : gcc_assert (arg_types != error_mark_node);
7715 : :
7716 : 602316099 : if (TREE_CODE (value_type) == FUNCTION_TYPE)
7717 : : {
7718 : 0 : error ("function return type cannot be function");
7719 : 0 : value_type = integer_type_node;
7720 : : }
7721 : :
7722 : : /* Make a node of the sort we want. */
7723 : 602316099 : t = make_node (FUNCTION_TYPE);
7724 : 602316099 : TREE_TYPE (t) = value_type;
7725 : 602316099 : TYPE_ARG_TYPES (t) = arg_types;
7726 : 602316099 : if (no_named_args_stdarg_p)
7727 : : {
7728 : 215858 : gcc_assert (arg_types == NULL_TREE);
7729 : 215858 : TYPE_NO_NAMED_ARGS_STDARG_P (t) = 1;
7730 : : }
7731 : :
7732 : : /* Set up the canonical type. */
7733 : 602316099 : any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
7734 : 602316099 : any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
7735 : 602316099 : canon_argtypes = maybe_canonicalize_argtypes (arg_types,
7736 : : &any_structural_p,
7737 : : &any_noncanonical_p);
7738 : : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7739 : 602316099 : if (any_structural_p)
7740 : 63689341 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7741 : :
7742 : : /* If we already have such a type, use the old one. */
7743 : 602316099 : hashval_t hash = type_hash_canon_hash (t);
7744 : 602316099 : tree probe_type = t;
7745 : 602316099 : t = type_hash_canon (hash, t);
7746 : 602316099 : if (t != probe_type)
7747 : : return t;
7748 : :
7749 : 389856627 : if (any_structural_p)
7750 : 51161031 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7751 : 338695596 : else if (any_noncanonical_p)
7752 : 78404048 : TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
7753 : : canon_argtypes);
7754 : :
7755 : 389856627 : if (!COMPLETE_TYPE_P (t))
7756 : 0 : layout_type (t);
7757 : : return t;
7758 : : }
7759 : :
7760 : : /* Build a function type. The RETURN_TYPE is the type returned by the
7761 : : function. If VAARGS is set, no void_type_node is appended to the
7762 : : list. ARGP must be always be terminated be a NULL_TREE. */
7763 : :
7764 : : static tree
7765 : 14660593 : build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
7766 : : {
7767 : 14660593 : tree t, args, last;
7768 : :
7769 : 14660593 : t = va_arg (argp, tree);
7770 : 62140479 : for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
7771 : 32819293 : args = tree_cons (NULL_TREE, t, args);
7772 : :
7773 : 14660593 : if (vaargs)
7774 : : {
7775 : 824779 : last = args;
7776 : 824779 : if (args != NULL_TREE)
7777 : 696600 : args = nreverse (args);
7778 : 824779 : gcc_assert (last != void_list_node);
7779 : : }
7780 : 13835814 : else if (args == NULL_TREE)
7781 : 1142230 : args = void_list_node;
7782 : : else
7783 : : {
7784 : 12693584 : last = args;
7785 : 12693584 : args = nreverse (args);
7786 : 12693584 : TREE_CHAIN (last) = void_list_node;
7787 : : }
7788 : 14660593 : args = build_function_type (return_type, args, vaargs && args == NULL_TREE);
7789 : :
7790 : 14660593 : return args;
7791 : : }
7792 : :
7793 : : /* Build a function type. The RETURN_TYPE is the type returned by the
7794 : : function. If additional arguments are provided, they are
7795 : : additional argument types. The list of argument types must always
7796 : : be terminated by NULL_TREE. */
7797 : :
7798 : : tree
7799 : 13835814 : build_function_type_list (tree return_type, ...)
7800 : : {
7801 : 13835814 : tree args;
7802 : 13835814 : va_list p;
7803 : :
7804 : 13835814 : va_start (p, return_type);
7805 : 13835814 : args = build_function_type_list_1 (false, return_type, p);
7806 : 13835814 : va_end (p);
7807 : 13835814 : return args;
7808 : : }
7809 : :
7810 : : /* Build a variable argument function type. The RETURN_TYPE is the
7811 : : type returned by the function. If additional arguments are provided,
7812 : : they are additional argument types. The list of argument types must
7813 : : always be terminated by NULL_TREE. */
7814 : :
7815 : : tree
7816 : 824779 : build_varargs_function_type_list (tree return_type, ...)
7817 : : {
7818 : 824779 : tree args;
7819 : 824779 : va_list p;
7820 : :
7821 : 824779 : va_start (p, return_type);
7822 : 824779 : args = build_function_type_list_1 (true, return_type, p);
7823 : 824779 : va_end (p);
7824 : :
7825 : 824779 : return args;
7826 : : }
7827 : :
7828 : : /* Build a function type. RETURN_TYPE is the type returned by the
7829 : : function; VAARGS indicates whether the function takes varargs. The
7830 : : function takes N named arguments, the types of which are provided in
7831 : : ARG_TYPES. */
7832 : :
7833 : : static tree
7834 : 115405075 : build_function_type_array_1 (bool vaargs, tree return_type, int n,
7835 : : tree *arg_types)
7836 : : {
7837 : 115405075 : int i;
7838 : 115405075 : tree t = vaargs ? NULL_TREE : void_list_node;
7839 : :
7840 : 378759236 : for (i = n - 1; i >= 0; i--)
7841 : 263354161 : t = tree_cons (NULL_TREE, arg_types[i], t);
7842 : :
7843 : 115405075 : return build_function_type (return_type, t, vaargs && n == 0);
7844 : : }
7845 : :
7846 : : /* Build a function type. RETURN_TYPE is the type returned by the
7847 : : function. The function takes N named arguments, the types of which
7848 : : are provided in ARG_TYPES. */
7849 : :
7850 : : tree
7851 : 109193089 : build_function_type_array (tree return_type, int n, tree *arg_types)
7852 : : {
7853 : 109193089 : return build_function_type_array_1 (false, return_type, n, arg_types);
7854 : : }
7855 : :
7856 : : /* Build a variable argument function type. RETURN_TYPE is the type
7857 : : returned by the function. The function takes N named arguments, the
7858 : : types of which are provided in ARG_TYPES. */
7859 : :
7860 : : tree
7861 : 6211986 : build_varargs_function_type_array (tree return_type, int n, tree *arg_types)
7862 : : {
7863 : 6211986 : return build_function_type_array_1 (true, return_type, n, arg_types);
7864 : : }
7865 : :
7866 : : /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7867 : : and ARGTYPES (a TREE_LIST) are the return type and arguments types
7868 : : for the method. An implicit additional parameter (of type
7869 : : pointer-to-BASETYPE) is added to the ARGTYPES. */
7870 : :
7871 : : tree
7872 : 291429100 : build_method_type_directly (tree basetype,
7873 : : tree rettype,
7874 : : tree argtypes)
7875 : : {
7876 : 291429100 : tree t;
7877 : 291429100 : tree ptype;
7878 : 291429100 : bool any_structural_p, any_noncanonical_p;
7879 : 291429100 : tree canon_argtypes;
7880 : :
7881 : : /* Make a node of the sort we want. */
7882 : 291429100 : t = make_node (METHOD_TYPE);
7883 : :
7884 : 291429100 : TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7885 : 291429100 : TREE_TYPE (t) = rettype;
7886 : 291429100 : ptype = build_pointer_type (basetype);
7887 : :
7888 : : /* The actual arglist for this function includes a "hidden" argument
7889 : : which is "this". Put it into the list of argument types. */
7890 : 291429100 : argtypes = tree_cons (NULL_TREE, ptype, argtypes);
7891 : 291429100 : TYPE_ARG_TYPES (t) = argtypes;
7892 : :
7893 : : /* Set up the canonical type. */
7894 : 291429100 : any_structural_p
7895 : 291429100 : = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7896 : 291429100 : || TYPE_STRUCTURAL_EQUALITY_P (rettype));
7897 : 291429100 : any_noncanonical_p
7898 : 291429100 : = (TYPE_CANONICAL (basetype) != basetype
7899 : 291429100 : || TYPE_CANONICAL (rettype) != rettype);
7900 : 291429100 : canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
7901 : : &any_structural_p,
7902 : : &any_noncanonical_p);
7903 : :
7904 : : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7905 : 291429100 : if (any_structural_p)
7906 : 23322862 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7907 : :
7908 : : /* If we already have such a type, use the old one. */
7909 : 291429100 : hashval_t hash = type_hash_canon_hash (t);
7910 : 291429100 : tree probe_type = t;
7911 : 291429100 : t = type_hash_canon (hash, t);
7912 : 291429100 : if (t != probe_type)
7913 : : return t;
7914 : :
7915 : 221783159 : if (any_structural_p)
7916 : 19353117 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7917 : 202430042 : else if (any_noncanonical_p)
7918 : 75947531 : TYPE_CANONICAL (t)
7919 : 151895062 : = build_method_type_directly (TYPE_CANONICAL (basetype),
7920 : 75947531 : TYPE_CANONICAL (rettype),
7921 : : canon_argtypes);
7922 : 221783159 : if (!COMPLETE_TYPE_P (t))
7923 : 0 : layout_type (t);
7924 : :
7925 : : return t;
7926 : : }
7927 : :
7928 : : /* Construct, lay out and return the type of methods belonging to class
7929 : : BASETYPE and whose arguments and values are described by TYPE.
7930 : : If that type exists already, reuse it.
7931 : : TYPE must be a FUNCTION_TYPE node. */
7932 : :
7933 : : tree
7934 : 155 : build_method_type (tree basetype, tree type)
7935 : : {
7936 : 155 : gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
7937 : :
7938 : 155 : return build_method_type_directly (basetype,
7939 : 155 : TREE_TYPE (type),
7940 : 155 : TYPE_ARG_TYPES (type));
7941 : : }
7942 : :
7943 : : /* Construct, lay out and return the type of offsets to a value
7944 : : of type TYPE, within an object of type BASETYPE.
7945 : : If a suitable offset type exists already, reuse it. */
7946 : :
7947 : : tree
7948 : 973710 : build_offset_type (tree basetype, tree type)
7949 : : {
7950 : 973710 : tree t;
7951 : :
7952 : : /* Make a node of the sort we want. */
7953 : 973710 : t = make_node (OFFSET_TYPE);
7954 : :
7955 : 973710 : TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7956 : 973710 : TREE_TYPE (t) = type;
7957 : 973710 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7958 : 973710 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7959 : 4 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7960 : :
7961 : : /* If we already have such a type, use the old one. */
7962 : 973710 : hashval_t hash = type_hash_canon_hash (t);
7963 : 973710 : tree probe_type = t;
7964 : 973710 : t = type_hash_canon (hash, t);
7965 : 973710 : if (t != probe_type)
7966 : : return t;
7967 : :
7968 : 199243 : if (!COMPLETE_TYPE_P (t))
7969 : 0 : layout_type (t);
7970 : :
7971 : 199243 : if (TYPE_CANONICAL (t) == t)
7972 : : {
7973 : 199239 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7974 : 199239 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7975 : 0 : gcc_unreachable ();
7976 : 199239 : else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
7977 : 199239 : || TYPE_CANONICAL (type) != type)
7978 : 118921 : TYPE_CANONICAL (t)
7979 : 237842 : = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
7980 : 118921 : TYPE_CANONICAL (type));
7981 : : }
7982 : :
7983 : : return t;
7984 : : }
7985 : :
7986 : : /* Create a complex type whose components are COMPONENT_TYPE.
7987 : :
7988 : : If NAMED is true, the type is given a TYPE_NAME. We do not always
7989 : : do so because this creates a DECL node and thus make the DECL_UIDs
7990 : : dependent on the type canonicalization hashtable, which is GC-ed,
7991 : : so the DECL_UIDs would not be stable wrt garbage collection. */
7992 : :
7993 : : tree
7994 : 5151331 : build_complex_type (tree component_type, bool named)
7995 : : {
7996 : 5151331 : gcc_assert (INTEGRAL_TYPE_P (component_type)
7997 : : || SCALAR_FLOAT_TYPE_P (component_type)
7998 : : || FIXED_POINT_TYPE_P (component_type));
7999 : :
8000 : : /* Make a node of the sort we want. */
8001 : 5151331 : tree probe = make_node (COMPLEX_TYPE);
8002 : :
8003 : 5151331 : TREE_TYPE (probe) = TYPE_MAIN_VARIANT (component_type);
8004 : 5151331 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (probe)))
8005 : 0 : SET_TYPE_STRUCTURAL_EQUALITY (probe);
8006 : :
8007 : : /* If we already have such a type, use the old one. */
8008 : 5151331 : hashval_t hash = type_hash_canon_hash (probe);
8009 : 5151331 : tree t = type_hash_canon (hash, probe);
8010 : :
8011 : 5151331 : if (t == probe)
8012 : : {
8013 : : /* We created a new type. The hash insertion will have laid
8014 : : out the type. We need to check the canonicalization and
8015 : : maybe set the name. */
8016 : 3094840 : gcc_checking_assert (COMPLETE_TYPE_P (t)
8017 : : && !TYPE_NAME (t));
8018 : :
8019 : 3094840 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))
8020 : : ;
8021 : 3094840 : else if (TYPE_CANONICAL (TREE_TYPE (t)) != TREE_TYPE (t))
8022 : 101 : TYPE_CANONICAL (t)
8023 : 202 : = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named);
8024 : :
8025 : : /* We need to create a name, since complex is a fundamental type. */
8026 : 3094840 : if (named)
8027 : : {
8028 : 1141564 : const char *name = NULL;
8029 : :
8030 : 1141564 : if (TREE_TYPE (t) == char_type_node)
8031 : : name = "complex char";
8032 : 1141564 : else if (TREE_TYPE (t) == signed_char_type_node)
8033 : : name = "complex signed char";
8034 : 1141564 : else if (TREE_TYPE (t) == unsigned_char_type_node)
8035 : : name = "complex unsigned char";
8036 : 1141564 : else if (TREE_TYPE (t) == short_integer_type_node)
8037 : : name = "complex short int";
8038 : 1141564 : else if (TREE_TYPE (t) == short_unsigned_type_node)
8039 : : name = "complex short unsigned int";
8040 : 1141564 : else if (TREE_TYPE (t) == integer_type_node)
8041 : : name = "complex int";
8042 : 856173 : else if (TREE_TYPE (t) == unsigned_type_node)
8043 : : name = "complex unsigned int";
8044 : 856173 : else if (TREE_TYPE (t) == long_integer_type_node)
8045 : : name = "complex long int";
8046 : 856173 : else if (TREE_TYPE (t) == long_unsigned_type_node)
8047 : : name = "complex long unsigned int";
8048 : 856173 : else if (TREE_TYPE (t) == long_long_integer_type_node)
8049 : : name = "complex long long int";
8050 : 856173 : else if (TREE_TYPE (t) == long_long_unsigned_type_node)
8051 : : name = "complex long long unsigned int";
8052 : :
8053 : : if (name != NULL)
8054 : 285391 : TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
8055 : : get_identifier (name), t);
8056 : : }
8057 : : }
8058 : :
8059 : 5151331 : return build_qualified_type (t, TYPE_QUALS (component_type));
8060 : : }
8061 : :
8062 : : /* If TYPE is a real or complex floating-point type and the target
8063 : : does not directly support arithmetic on TYPE then return the wider
8064 : : type to be used for arithmetic on TYPE. Otherwise, return
8065 : : NULL_TREE. */
8066 : :
8067 : : tree
8068 : 91429164 : excess_precision_type (tree type)
8069 : : {
8070 : : /* The target can give two different responses to the question of
8071 : : which excess precision mode it would like depending on whether we
8072 : : are in -fexcess-precision=standard or -fexcess-precision=fast. */
8073 : :
8074 : 3294154 : enum excess_precision_type requested_type
8075 : 91429164 : = (flag_excess_precision == EXCESS_PRECISION_FAST
8076 : 91429164 : ? EXCESS_PRECISION_TYPE_FAST
8077 : : : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
8078 : 3294223 : ? EXCESS_PRECISION_TYPE_FLOAT16 : EXCESS_PRECISION_TYPE_STANDARD));
8079 : :
8080 : 91429164 : enum flt_eval_method target_flt_eval_method
8081 : 91429164 : = targetm.c.excess_precision (requested_type);
8082 : :
8083 : : /* The target should not ask for unpredictable float evaluation (though
8084 : : it might advertise that implicitly the evaluation is unpredictable,
8085 : : but we don't care about that here, it will have been reported
8086 : : elsewhere). If it does ask for unpredictable evaluation, we have
8087 : : nothing to do here. */
8088 : 91429164 : gcc_assert (target_flt_eval_method != FLT_EVAL_METHOD_UNPREDICTABLE);
8089 : :
8090 : : /* Nothing to do. The target has asked for all types we know about
8091 : : to be computed with their native precision and range. */
8092 : 91429164 : if (target_flt_eval_method == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
8093 : : return NULL_TREE;
8094 : :
8095 : : /* The target will promote this type in a target-dependent way, so excess
8096 : : precision ought to leave it alone. */
8097 : 90047626 : if (targetm.promoted_type (type) != NULL_TREE)
8098 : : return NULL_TREE;
8099 : :
8100 : 90047626 : machine_mode float16_type_mode = (float16_type_node
8101 : 90047626 : ? TYPE_MODE (float16_type_node)
8102 : 90047626 : : VOIDmode);
8103 : 90047626 : machine_mode bfloat16_type_mode = (bfloat16_type_node
8104 : 90047626 : ? TYPE_MODE (bfloat16_type_node)
8105 : 90047626 : : VOIDmode);
8106 : 90047626 : machine_mode float_type_mode = TYPE_MODE (float_type_node);
8107 : 90047626 : machine_mode double_type_mode = TYPE_MODE (double_type_node);
8108 : :
8109 : 90047626 : switch (TREE_CODE (type))
8110 : : {
8111 : 62750141 : case REAL_TYPE:
8112 : 62750141 : {
8113 : 62750141 : machine_mode type_mode = TYPE_MODE (type);
8114 : 62750141 : switch (target_flt_eval_method)
8115 : : {
8116 : 62737308 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8117 : 62737308 : if (type_mode == float16_type_mode
8118 : 62737308 : || type_mode == bfloat16_type_mode)
8119 : 298586 : return float_type_node;
8120 : : break;
8121 : 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8122 : 0 : if (type_mode == float16_type_mode
8123 : 0 : || type_mode == bfloat16_type_mode
8124 : 0 : || type_mode == float_type_mode)
8125 : 0 : return double_type_node;
8126 : : break;
8127 : 12833 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8128 : 12833 : if (type_mode == float16_type_mode
8129 : 12833 : || type_mode == bfloat16_type_mode
8130 : 12828 : || type_mode == float_type_mode
8131 : 12828 : || type_mode == double_type_mode)
8132 : 12384 : return long_double_type_node;
8133 : : break;
8134 : 0 : default:
8135 : 0 : gcc_unreachable ();
8136 : : }
8137 : : break;
8138 : : }
8139 : 389484 : case COMPLEX_TYPE:
8140 : 389484 : {
8141 : 389484 : if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
8142 : : return NULL_TREE;
8143 : 380004 : machine_mode type_mode = TYPE_MODE (TREE_TYPE (type));
8144 : 380004 : switch (target_flt_eval_method)
8145 : : {
8146 : 379671 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8147 : 379671 : if (type_mode == float16_type_mode
8148 : 379671 : || type_mode == bfloat16_type_mode)
8149 : 271 : return complex_float_type_node;
8150 : : break;
8151 : 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8152 : 0 : if (type_mode == float16_type_mode
8153 : 0 : || type_mode == bfloat16_type_mode
8154 : 0 : || type_mode == float_type_mode)
8155 : 0 : return complex_double_type_node;
8156 : : break;
8157 : 333 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8158 : 333 : if (type_mode == float16_type_mode
8159 : 333 : || type_mode == bfloat16_type_mode
8160 : 333 : || type_mode == float_type_mode
8161 : 333 : || type_mode == double_type_mode)
8162 : 281 : return complex_long_double_type_node;
8163 : : break;
8164 : 0 : default:
8165 : 0 : gcc_unreachable ();
8166 : : }
8167 : : break;
8168 : : }
8169 : : default:
8170 : : break;
8171 : : }
8172 : :
8173 : : return NULL_TREE;
8174 : : }
8175 : :
8176 : : /* Return OP, stripped of any conversions to wider types as much as is safe.
8177 : : Converting the value back to OP's type makes a value equivalent to OP.
8178 : :
8179 : : If FOR_TYPE is nonzero, we return a value which, if converted to
8180 : : type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8181 : :
8182 : : OP must have integer, real or enumeral type. Pointers are not allowed!
8183 : :
8184 : : There are some cases where the obvious value we could return
8185 : : would regenerate to OP if converted to OP's type,
8186 : : but would not extend like OP to wider types.
8187 : : If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8188 : : For example, if OP is (unsigned short)(signed char)-1,
8189 : : we avoid returning (signed char)-1 if FOR_TYPE is int,
8190 : : even though extending that to an unsigned short would regenerate OP,
8191 : : since the result of extending (signed char)-1 to (int)
8192 : : is different from (int) OP. */
8193 : :
8194 : : tree
8195 : 10464103 : get_unwidened (tree op, tree for_type)
8196 : : {
8197 : : /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8198 : 10464103 : tree type = TREE_TYPE (op);
8199 : 10464103 : unsigned final_prec
8200 : 18056746 : = TYPE_PRECISION (for_type != 0 ? for_type : type);
8201 : 10464103 : int uns
8202 : 10464103 : = (for_type != 0 && for_type != type
8203 : 2545457 : && final_prec > TYPE_PRECISION (type)
8204 : 10535239 : && TYPE_UNSIGNED (type));
8205 : 10464103 : tree win = op;
8206 : :
8207 : 10662127 : while (CONVERT_EXPR_P (op))
8208 : : {
8209 : 198053 : int bitschange;
8210 : :
8211 : : /* TYPE_PRECISION on vector types has different meaning
8212 : : (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8213 : : so avoid them here. */
8214 : 198053 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
8215 : : break;
8216 : :
8217 : 198053 : bitschange = TYPE_PRECISION (TREE_TYPE (op))
8218 : 198053 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
8219 : :
8220 : : /* Truncations are many-one so cannot be removed.
8221 : : Unless we are later going to truncate down even farther. */
8222 : 198053 : if (bitschange < 0
8223 : 198053 : && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
8224 : : break;
8225 : :
8226 : : /* See what's inside this conversion. If we decide to strip it,
8227 : : we will set WIN. */
8228 : 198024 : op = TREE_OPERAND (op, 0);
8229 : :
8230 : : /* If we have not stripped any zero-extensions (uns is 0),
8231 : : we can strip any kind of extension.
8232 : : If we have previously stripped a zero-extension,
8233 : : only zero-extensions can safely be stripped.
8234 : : Any extension can be stripped if the bits it would produce
8235 : : are all going to be discarded later by truncating to FOR_TYPE. */
8236 : :
8237 : 198024 : if (bitschange > 0)
8238 : : {
8239 : 107512 : if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
8240 : : win = op;
8241 : : /* TYPE_UNSIGNED says whether this is a zero-extension.
8242 : : Let's avoid computing it if it does not affect WIN
8243 : : and if UNS will not be needed again. */
8244 : 107512 : if ((uns
8245 : 107481 : || CONVERT_EXPR_P (op))
8246 : 108053 : && TYPE_UNSIGNED (TREE_TYPE (op)))
8247 : : {
8248 : : uns = 1;
8249 : : win = op;
8250 : : }
8251 : : }
8252 : : }
8253 : :
8254 : : /* If we finally reach a constant see if it fits in sth smaller and
8255 : : in that case convert it. */
8256 : 10464103 : if (TREE_CODE (win) == INTEGER_CST)
8257 : : {
8258 : 439503 : tree wtype = TREE_TYPE (win);
8259 : 439503 : unsigned prec = wi::min_precision (wi::to_wide (win), TYPE_SIGN (wtype));
8260 : 439503 : if (for_type)
8261 : 434848 : prec = MAX (prec, final_prec);
8262 : 439503 : if (prec < TYPE_PRECISION (wtype))
8263 : : {
8264 : 433182 : tree t = lang_hooks.types.type_for_size (prec, TYPE_UNSIGNED (wtype));
8265 : 433182 : if (t && TYPE_PRECISION (t) < TYPE_PRECISION (wtype))
8266 : 427499 : win = fold_convert (t, win);
8267 : : }
8268 : : }
8269 : :
8270 : 10464103 : return win;
8271 : : }
8272 : :
8273 : : /* Return OP or a simpler expression for a narrower value
8274 : : which can be sign-extended or zero-extended to give back OP.
8275 : : Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8276 : : or 0 if the value should be sign-extended. */
8277 : :
8278 : : tree
8279 : 65744274 : get_narrower (tree op, int *unsignedp_ptr)
8280 : : {
8281 : 65744274 : int uns = 0;
8282 : 65744274 : bool first = true;
8283 : 65744274 : tree win = op;
8284 : 65744274 : bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
8285 : :
8286 : 65744274 : if (TREE_CODE (op) == COMPOUND_EXPR)
8287 : : {
8288 : 86729 : do
8289 : 86729 : op = TREE_OPERAND (op, 1);
8290 : 86729 : while (TREE_CODE (op) == COMPOUND_EXPR);
8291 : 86714 : tree ret = get_narrower (op, unsignedp_ptr);
8292 : 86714 : if (ret == op)
8293 : : return win;
8294 : 4264 : auto_vec <tree, 16> v;
8295 : 4264 : unsigned int i;
8296 : 8535 : for (op = win; TREE_CODE (op) == COMPOUND_EXPR;
8297 : 4271 : op = TREE_OPERAND (op, 1))
8298 : 4271 : v.safe_push (op);
8299 : 12799 : FOR_EACH_VEC_ELT_REVERSE (v, i, op)
8300 : 4271 : ret = build2_loc (EXPR_LOCATION (op), COMPOUND_EXPR,
8301 : 4271 : TREE_TYPE (ret), TREE_OPERAND (op, 0),
8302 : : ret);
8303 : 4264 : return ret;
8304 : 4264 : }
8305 : 78320005 : while (TREE_CODE (op) == NOP_EXPR)
8306 : : {
8307 : 12696514 : int bitschange
8308 : 12696514 : = (TYPE_PRECISION (TREE_TYPE (op))
8309 : 12696514 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
8310 : :
8311 : : /* Truncations are many-one so cannot be removed. */
8312 : 12696514 : if (bitschange < 0)
8313 : : break;
8314 : :
8315 : : /* See what's inside this conversion. If we decide to strip it,
8316 : : we will set WIN. */
8317 : :
8318 : 12662541 : if (bitschange > 0)
8319 : : {
8320 : 3075577 : op = TREE_OPERAND (op, 0);
8321 : : /* An extension: the outermost one can be stripped,
8322 : : but remember whether it is zero or sign extension. */
8323 : 3075577 : if (first)
8324 : 3072388 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8325 : : /* Otherwise, if a sign extension has been stripped,
8326 : : only sign extensions can now be stripped;
8327 : : if a zero extension has been stripped, only zero-extensions. */
8328 : 3189 : else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
8329 : : break;
8330 : : first = false;
8331 : : }
8332 : : else /* bitschange == 0 */
8333 : : {
8334 : : /* A change in nominal type can always be stripped, but we must
8335 : : preserve the unsignedness. */
8336 : 9586964 : if (first)
8337 : 9029997 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8338 : 9586964 : first = false;
8339 : 9586964 : op = TREE_OPERAND (op, 0);
8340 : : /* Keep trying to narrow, but don't assign op to win if it
8341 : : would turn an integral type into something else. */
8342 : 17385399 : if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
8343 : 102786 : continue;
8344 : : }
8345 : :
8346 : 12559659 : win = op;
8347 : : }
8348 : :
8349 : 65657560 : if (TREE_CODE (op) == COMPONENT_REF
8350 : : /* Since type_for_size always gives an integer type. */
8351 : 2364530 : && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
8352 : 2261188 : && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
8353 : : /* Ensure field is laid out already. */
8354 : 2261188 : && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
8355 : 67918745 : && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op, 1))))
8356 : : {
8357 : 2261185 : unsigned HOST_WIDE_INT innerprec
8358 : 2261185 : = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op, 1)));
8359 : 2261185 : int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
8360 : 2261185 : || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
8361 : 2261185 : tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
8362 : :
8363 : : /* We can get this structure field in a narrower type that fits it,
8364 : : but the resulting extension to its nominal type (a fullword type)
8365 : : must satisfy the same conditions as for other extensions.
8366 : :
8367 : : Do this only for fields that are aligned (not bit-fields),
8368 : : because when bit-field insns will be used there is no
8369 : : advantage in doing this. */
8370 : :
8371 : 2261185 : if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
8372 : 0 : && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
8373 : 0 : && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
8374 : 2261185 : && type != 0)
8375 : : {
8376 : 0 : if (first)
8377 : 0 : uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
8378 : 0 : win = fold_convert (type, op);
8379 : : }
8380 : : }
8381 : :
8382 : 65657560 : *unsignedp_ptr = uns;
8383 : 65657560 : return win;
8384 : : }
8385 : :
8386 : : /* Return true if integer constant C has a value that is permissible
8387 : : for TYPE, an integral type. */
8388 : :
8389 : : bool
8390 : 118556898 : int_fits_type_p (const_tree c, const_tree type)
8391 : : {
8392 : 118556898 : tree type_low_bound, type_high_bound;
8393 : 118556898 : bool ok_for_low_bound, ok_for_high_bound;
8394 : 118556898 : signop sgn_c = TYPE_SIGN (TREE_TYPE (c));
8395 : :
8396 : : /* Non-standard boolean types can have arbitrary precision but various
8397 : : transformations assume that they can only take values 0 and +/-1. */
8398 : 118556898 : if (TREE_CODE (type) == BOOLEAN_TYPE)
8399 : 1066593 : return wi::fits_to_boolean_p (wi::to_wide (c), type);
8400 : :
8401 : 117490305 : retry:
8402 : 117502140 : type_low_bound = TYPE_MIN_VALUE (type);
8403 : 117502140 : type_high_bound = TYPE_MAX_VALUE (type);
8404 : :
8405 : : /* If at least one bound of the type is a constant integer, we can check
8406 : : ourselves and maybe make a decision. If no such decision is possible, but
8407 : : this type is a subtype, try checking against that. Otherwise, use
8408 : : fits_to_tree_p, which checks against the precision.
8409 : :
8410 : : Compute the status for each possibly constant bound, and return if we see
8411 : : one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8412 : : for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8413 : : for "constant known to fit". */
8414 : :
8415 : : /* Check if c >= type_low_bound. */
8416 : 117502140 : if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
8417 : : {
8418 : 117502140 : if (tree_int_cst_lt (c, type_low_bound))
8419 : : return false;
8420 : : ok_for_low_bound = true;
8421 : : }
8422 : : else
8423 : : ok_for_low_bound = false;
8424 : :
8425 : : /* Check if c <= type_high_bound. */
8426 : 117255878 : if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
8427 : : {
8428 : 117224391 : if (tree_int_cst_lt (type_high_bound, c))
8429 : : return false;
8430 : : ok_for_high_bound = true;
8431 : : }
8432 : : else
8433 : : ok_for_high_bound = false;
8434 : :
8435 : : /* If the constant fits both bounds, the result is known. */
8436 : 115507367 : if (ok_for_low_bound && ok_for_high_bound)
8437 : : return true;
8438 : :
8439 : : /* Perform some generic filtering which may allow making a decision
8440 : : even if the bounds are not constant. First, negative integers
8441 : : never fit in unsigned types, */
8442 : 31487 : if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (wi::to_wide (c)))
8443 : 0 : return false;
8444 : :
8445 : : /* Second, narrower types always fit in wider ones. */
8446 : 31487 : if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
8447 : : return true;
8448 : :
8449 : : /* Third, unsigned integers with top bit set never fit signed types. */
8450 : 11844 : if (!TYPE_UNSIGNED (type) && sgn_c == UNSIGNED)
8451 : : {
8452 : 14 : int prec = GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (c))) - 1;
8453 : 14 : if (prec < TYPE_PRECISION (TREE_TYPE (c)))
8454 : : {
8455 : : /* When a tree_cst is converted to a wide-int, the precision
8456 : : is taken from the type. However, if the precision of the
8457 : : mode underneath the type is smaller than that, it is
8458 : : possible that the value will not fit. The test below
8459 : : fails if any bit is set between the sign bit of the
8460 : : underlying mode and the top bit of the type. */
8461 : 14 : if (wi::zext (wi::to_wide (c), prec - 1) != wi::to_wide (c))
8462 : : return false;
8463 : : }
8464 : 0 : else if (wi::neg_p (wi::to_wide (c)))
8465 : : return false;
8466 : : }
8467 : :
8468 : : /* If we haven't been able to decide at this point, there nothing more we
8469 : : can check ourselves here. Look at the base type if we have one and it
8470 : : has the same precision. */
8471 : 11835 : if (TREE_CODE (type) == INTEGER_TYPE
8472 : 11835 : && TREE_TYPE (type) != 0
8473 : 23670 : && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
8474 : : {
8475 : 11835 : type = TREE_TYPE (type);
8476 : 11835 : goto retry;
8477 : : }
8478 : :
8479 : : /* Or to fits_to_tree_p, if nothing else. */
8480 : 0 : return wi::fits_to_tree_p (wi::to_wide (c), type);
8481 : : }
8482 : :
8483 : : /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8484 : : bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8485 : : represented (assuming two's-complement arithmetic) within the bit
8486 : : precision of the type are returned instead. */
8487 : :
8488 : : void
8489 : 21159563 : get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
8490 : : {
8491 : 19654515 : if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
8492 : 40814078 : && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
8493 : 19654515 : wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type)), min, TYPE_SIGN (type));
8494 : : else
8495 : : {
8496 : 1505048 : if (TYPE_UNSIGNED (type))
8497 : 1505048 : mpz_set_ui (min, 0);
8498 : : else
8499 : : {
8500 : 0 : wide_int mn = wi::min_value (TYPE_PRECISION (type), SIGNED);
8501 : 0 : wi::to_mpz (mn, min, SIGNED);
8502 : 0 : }
8503 : : }
8504 : :
8505 : 19654515 : if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
8506 : 40814078 : && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
8507 : 19654515 : wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type)), max, TYPE_SIGN (type));
8508 : : else
8509 : : {
8510 : 1505048 : wide_int mn = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
8511 : 1505048 : wi::to_mpz (mn, max, TYPE_SIGN (type));
8512 : 1505048 : }
8513 : 21159563 : }
8514 : :
8515 : : /* Return true if VAR is an automatic variable. */
8516 : :
8517 : : bool
8518 : 377872938 : auto_var_p (const_tree var)
8519 : : {
8520 : 207452168 : return ((((VAR_P (var) && ! DECL_EXTERNAL (var))
8521 : 173775647 : || TREE_CODE (var) == PARM_DECL)
8522 : 269418279 : && ! TREE_STATIC (var))
8523 : 494856427 : || TREE_CODE (var) == RESULT_DECL);
8524 : : }
8525 : :
8526 : : /* Return true if VAR is an automatic variable defined in function FN. */
8527 : :
8528 : : bool
8529 : 1126790861 : auto_var_in_fn_p (const_tree var, const_tree fn)
8530 : : {
8531 : 351671454 : return (DECL_P (var) && DECL_CONTEXT (var) == fn
8532 : 1379496250 : && (auto_var_p (var)
8533 : 4324674 : || TREE_CODE (var) == LABEL_DECL));
8534 : : }
8535 : :
8536 : : /* Subprogram of following function. Called by walk_tree.
8537 : :
8538 : : Return *TP if it is an automatic variable or parameter of the
8539 : : function passed in as DATA. */
8540 : :
8541 : : static tree
8542 : 122727 : find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
8543 : : {
8544 : 122727 : tree fn = (tree) data;
8545 : :
8546 : 122727 : if (TYPE_P (*tp))
8547 : 0 : *walk_subtrees = 0;
8548 : :
8549 : 122727 : else if (DECL_P (*tp)
8550 : 122727 : && auto_var_in_fn_p (*tp, fn))
8551 : 114043 : return *tp;
8552 : :
8553 : : return NULL_TREE;
8554 : : }
8555 : :
8556 : : /* Returns true if T is, contains, or refers to a type with variable
8557 : : size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8558 : : arguments, but not the return type. If FN is nonzero, only return
8559 : : true if a modifier of the type or position of FN is a variable or
8560 : : parameter inside FN.
8561 : :
8562 : : This concept is more general than that of C99 'variably modified types':
8563 : : in C99, a struct type is never variably modified because a VLA may not
8564 : : appear as a structure member. However, in GNU C code like:
8565 : :
8566 : : struct S { int i[f()]; };
8567 : :
8568 : : is valid, and other languages may define similar constructs. */
8569 : :
8570 : : bool
8571 : 1834319282 : variably_modified_type_p (tree type, tree fn)
8572 : : {
8573 : 1834319282 : tree t;
8574 : :
8575 : : /* Test if T is either variable (if FN is zero) or an expression containing
8576 : : a variable in FN. If TYPE isn't gimplified, return true also if
8577 : : gimplify_one_sizepos would gimplify the expression into a local
8578 : : variable. */
8579 : : #define RETURN_TRUE_IF_VAR(T) \
8580 : : do { tree _t = (T); \
8581 : : if (_t != NULL_TREE \
8582 : : && _t != error_mark_node \
8583 : : && !CONSTANT_CLASS_P (_t) \
8584 : : && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8585 : : && (!fn \
8586 : : || (!TYPE_SIZES_GIMPLIFIED (type) \
8587 : : && (TREE_CODE (_t) != VAR_DECL \
8588 : : && !CONTAINS_PLACEHOLDER_P (_t))) \
8589 : : || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8590 : : return true; } while (0)
8591 : :
8592 : 1834319282 : if (type == error_mark_node)
8593 : : return false;
8594 : :
8595 : : /* If TYPE itself has variable size, it is variably modified. */
8596 : 1834070432 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
8597 : 1833946977 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
8598 : :
8599 : 1833946353 : switch (TREE_CODE (type))
8600 : : {
8601 : 509747944 : case POINTER_TYPE:
8602 : 509747944 : case REFERENCE_TYPE:
8603 : 509747944 : case VECTOR_TYPE:
8604 : : /* Ada can have pointer types refering to themselves indirectly. */
8605 : 509747944 : if (TREE_VISITED (type))
8606 : : return false;
8607 : 509747944 : TREE_VISITED (type) = true;
8608 : 509747944 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8609 : : {
8610 : 77878 : TREE_VISITED (type) = false;
8611 : 77878 : return true;
8612 : : }
8613 : 509670066 : TREE_VISITED (type) = false;
8614 : 509670066 : break;
8615 : :
8616 : 89730347 : case FUNCTION_TYPE:
8617 : 89730347 : case METHOD_TYPE:
8618 : : /* If TYPE is a function type, it is variably modified if the
8619 : : return type is variably modified. */
8620 : 89730347 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8621 : : return true;
8622 : : break;
8623 : :
8624 : 440216373 : case INTEGER_TYPE:
8625 : 440216373 : case REAL_TYPE:
8626 : 440216373 : case FIXED_POINT_TYPE:
8627 : 440216373 : case ENUMERAL_TYPE:
8628 : 440216373 : case BOOLEAN_TYPE:
8629 : : /* Scalar types are variably modified if their end points
8630 : : aren't constant. */
8631 : 440216373 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
8632 : 440216373 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
8633 : 440182237 : break;
8634 : :
8635 : 651053775 : case RECORD_TYPE:
8636 : 651053775 : case UNION_TYPE:
8637 : 651053775 : case QUAL_UNION_TYPE:
8638 : : /* We can't see if any of the fields are variably-modified by the
8639 : : definition we normally use, since that would produce infinite
8640 : : recursion via pointers. */
8641 : : /* This is variably modified if some field's type is. */
8642 : 30087076170 : for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
8643 : 29436022395 : if (TREE_CODE (t) == FIELD_DECL)
8644 : : {
8645 : 1000467054 : RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
8646 : 1000467054 : RETURN_TRUE_IF_VAR (DECL_SIZE (t));
8647 : 1000467054 : RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
8648 : :
8649 : : /* If the type is a qualified union, then the DECL_QUALIFIER
8650 : : of fields can also be an expression containing a variable. */
8651 : 1000467054 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
8652 : 0 : RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
8653 : :
8654 : : /* If the field is a qualified union, then it's only a container
8655 : : for what's inside so we look into it. That's necessary in LTO
8656 : : mode because the sizes of the field tested above have been set
8657 : : to PLACEHOLDER_EXPRs by free_lang_data. */
8658 : 1000467054 : if (TREE_CODE (TREE_TYPE (t)) == QUAL_UNION_TYPE
8659 : 1000467054 : && variably_modified_type_p (TREE_TYPE (t), fn))
8660 : : return true;
8661 : : }
8662 : : break;
8663 : :
8664 : 11674110 : case ARRAY_TYPE:
8665 : : /* Do not call ourselves to avoid infinite recursion. This is
8666 : : variably modified if the element type is. */
8667 : 11674110 : RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
8668 : 11670593 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
8669 : 11670575 : break;
8670 : :
8671 : : default:
8672 : : break;
8673 : : }
8674 : :
8675 : : /* The current language may have other cases to check, but in general,
8676 : : all other types are not variably modified. */
8677 : 1833830574 : return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
8678 : :
8679 : : #undef RETURN_TRUE_IF_VAR
8680 : : }
8681 : :
8682 : : /* Given a DECL or TYPE, return the scope in which it was declared, or
8683 : : NULL_TREE if there is no containing scope. */
8684 : :
8685 : : tree
8686 : 2395633426 : get_containing_scope (const_tree t)
8687 : : {
8688 : 2395633426 : return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8689 : : }
8690 : :
8691 : : /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
8692 : :
8693 : : const_tree
8694 : 13306 : get_ultimate_context (const_tree decl)
8695 : : {
8696 : 35822 : while (decl && TREE_CODE (decl) != TRANSLATION_UNIT_DECL)
8697 : : {
8698 : 22516 : if (TREE_CODE (decl) == BLOCK)
8699 : 0 : decl = BLOCK_SUPERCONTEXT (decl);
8700 : : else
8701 : 22516 : decl = get_containing_scope (decl);
8702 : : }
8703 : 13306 : return decl;
8704 : : }
8705 : :
8706 : : /* Return the innermost context enclosing DECL that is
8707 : : a FUNCTION_DECL, or zero if none. */
8708 : :
8709 : : tree
8710 : 1312523899 : decl_function_context (const_tree decl)
8711 : : {
8712 : 1312523899 : tree context;
8713 : :
8714 : 1312523899 : if (TREE_CODE (decl) == ERROR_MARK)
8715 : : return 0;
8716 : :
8717 : : /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8718 : : where we look up the function at runtime. Such functions always take
8719 : : a first argument of type 'pointer to real context'.
8720 : :
8721 : : C++ should really be fixed to use DECL_CONTEXT for the real context,
8722 : : and use something else for the "virtual context". */
8723 : 1312523899 : else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
8724 : 4348762 : context
8725 : 4348762 : = TYPE_MAIN_VARIANT
8726 : : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8727 : : else
8728 : 1308175137 : context = DECL_CONTEXT (decl);
8729 : :
8730 : 2986446655 : while (context && TREE_CODE (context) != FUNCTION_DECL)
8731 : : {
8732 : 1673922756 : if (TREE_CODE (context) == BLOCK)
8733 : 0 : context = BLOCK_SUPERCONTEXT (context);
8734 : : else
8735 : 1673922756 : context = get_containing_scope (context);
8736 : : }
8737 : :
8738 : : return context;
8739 : : }
8740 : :
8741 : : /* Return the innermost context enclosing DECL that is
8742 : : a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8743 : : TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8744 : :
8745 : : tree
8746 : 68892375 : decl_type_context (const_tree decl)
8747 : : {
8748 : 68892375 : tree context = DECL_CONTEXT (decl);
8749 : :
8750 : 71436430 : while (context)
8751 : 65844177 : switch (TREE_CODE (context))
8752 : : {
8753 : : case NAMESPACE_DECL:
8754 : : case TRANSLATION_UNIT_DECL:
8755 : : return NULL_TREE;
8756 : :
8757 : : case RECORD_TYPE:
8758 : : case UNION_TYPE:
8759 : : case QUAL_UNION_TYPE:
8760 : : return context;
8761 : :
8762 : 2544055 : case TYPE_DECL:
8763 : 2544055 : case FUNCTION_DECL:
8764 : 2544055 : context = DECL_CONTEXT (context);
8765 : 2544055 : break;
8766 : :
8767 : 0 : case BLOCK:
8768 : 0 : context = BLOCK_SUPERCONTEXT (context);
8769 : 0 : break;
8770 : :
8771 : 0 : default:
8772 : 0 : gcc_unreachable ();
8773 : : }
8774 : :
8775 : : return NULL_TREE;
8776 : : }
8777 : :
8778 : : /* CALL is a CALL_EXPR. Return the declaration for the function
8779 : : called, or NULL_TREE if the called function cannot be
8780 : : determined. */
8781 : :
8782 : : tree
8783 : 975549395 : get_callee_fndecl (const_tree call)
8784 : : {
8785 : 975549395 : tree addr;
8786 : :
8787 : 975549395 : if (call == error_mark_node)
8788 : : return error_mark_node;
8789 : :
8790 : : /* It's invalid to call this function with anything but a
8791 : : CALL_EXPR. */
8792 : 975549395 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8793 : :
8794 : : /* The first operand to the CALL is the address of the function
8795 : : called. */
8796 : 975549395 : addr = CALL_EXPR_FN (call);
8797 : :
8798 : : /* If there is no function, return early. */
8799 : 975549395 : if (addr == NULL_TREE)
8800 : : return NULL_TREE;
8801 : :
8802 : 974065627 : STRIP_NOPS (addr);
8803 : :
8804 : : /* If this is a readonly function pointer, extract its initial value. */
8805 : 17058288 : if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
8806 : 1742146 : && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
8807 : 974236590 : && DECL_INITIAL (addr))
8808 : 170870 : addr = DECL_INITIAL (addr);
8809 : :
8810 : : /* If the address is just `&f' for some function `f', then we know
8811 : : that `f' is being called. */
8812 : 974065627 : if (TREE_CODE (addr) == ADDR_EXPR
8813 : 974065627 : && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
8814 : 930388770 : return TREE_OPERAND (addr, 0);
8815 : :
8816 : : /* We couldn't figure out what was being called. */
8817 : : return NULL_TREE;
8818 : : }
8819 : :
8820 : : /* Return true when STMTs arguments and return value match those of FNDECL,
8821 : : a decl of a builtin function. */
8822 : :
8823 : : static bool
8824 : 5327297 : tree_builtin_call_types_compatible_p (const_tree call, tree fndecl)
8825 : : {
8826 : 5327297 : gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
8827 : :
8828 : 5327297 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
8829 : 5327297 : if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
8830 : 5327297 : fndecl = decl;
8831 : :
8832 : 5327297 : bool gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
8833 : 5327297 : if (gimple_form
8834 : 12989 : ? !useless_type_conversion_p (TREE_TYPE (call),
8835 : 12989 : TREE_TYPE (TREE_TYPE (fndecl)))
8836 : 5314308 : : (TYPE_MAIN_VARIANT (TREE_TYPE (call))
8837 : 5314308 : != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))))
8838 : : return false;
8839 : :
8840 : 5327081 : tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
8841 : 5327081 : unsigned nargs = call_expr_nargs (call);
8842 : 14159574 : for (unsigned i = 0; i < nargs; ++i, targs = TREE_CHAIN (targs))
8843 : : {
8844 : : /* Variadic args follow. */
8845 : 9788883 : if (!targs)
8846 : : return true;
8847 : 8833150 : tree arg = CALL_EXPR_ARG (call, i);
8848 : 8833150 : tree type = TREE_VALUE (targs);
8849 : 8833150 : if (gimple_form
8850 : 8833150 : ? !useless_type_conversion_p (type, TREE_TYPE (arg))
8851 : 8820161 : : TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (TREE_TYPE (arg)))
8852 : : {
8853 : : /* For pointer arguments be more forgiving, e.g. due to
8854 : : FILE * vs. fileptr_type_node, or say char * vs. const char *
8855 : : differences etc. */
8856 : 1107355 : if (!gimple_form
8857 : 554006 : && POINTER_TYPE_P (type)
8858 : 553454 : && POINTER_TYPE_P (TREE_TYPE (arg))
8859 : 1107355 : && tree_nop_conversion_p (type, TREE_TYPE (arg)))
8860 : 553349 : continue;
8861 : 657 : return false;
8862 : : }
8863 : : }
8864 : 8740735 : if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
8865 : : return false;
8866 : : return true;
8867 : : }
8868 : :
8869 : : /* If CALL_EXPR CALL calls a normal built-in function or an internal function,
8870 : : return the associated function code, otherwise return CFN_LAST. */
8871 : :
8872 : : combined_fn
8873 : 39360116 : get_call_combined_fn (const_tree call)
8874 : : {
8875 : : /* It's invalid to call this function with anything but a CALL_EXPR. */
8876 : 39360116 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8877 : :
8878 : 39360116 : if (!CALL_EXPR_FN (call))
8879 : 65968 : return as_combined_fn (CALL_EXPR_IFN (call));
8880 : :
8881 : 39294148 : tree fndecl = get_callee_fndecl (call);
8882 : 39294148 : if (fndecl
8883 : 39273439 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
8884 : 44621445 : && tree_builtin_call_types_compatible_p (call, fndecl))
8885 : 5326419 : return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
8886 : :
8887 : : return CFN_LAST;
8888 : : }
8889 : :
8890 : : /* Comparator of indices based on tree_node_counts. */
8891 : :
8892 : : static int
8893 : 0 : tree_nodes_cmp (const void *p1, const void *p2)
8894 : : {
8895 : 0 : const unsigned *n1 = (const unsigned *)p1;
8896 : 0 : const unsigned *n2 = (const unsigned *)p2;
8897 : :
8898 : 0 : return tree_node_counts[*n1] - tree_node_counts[*n2];
8899 : : }
8900 : :
8901 : : /* Comparator of indices based on tree_code_counts. */
8902 : :
8903 : : static int
8904 : 0 : tree_codes_cmp (const void *p1, const void *p2)
8905 : : {
8906 : 0 : const unsigned *n1 = (const unsigned *)p1;
8907 : 0 : const unsigned *n2 = (const unsigned *)p2;
8908 : :
8909 : 0 : return tree_code_counts[*n1] - tree_code_counts[*n2];
8910 : : }
8911 : :
8912 : : #define TREE_MEM_USAGE_SPACES 40
8913 : :
8914 : : /* Print debugging information about tree nodes generated during the compile,
8915 : : and any language-specific information. */
8916 : :
8917 : : void
8918 : 0 : dump_tree_statistics (void)
8919 : : {
8920 : 0 : if (GATHER_STATISTICS)
8921 : : {
8922 : : uint64_t total_nodes, total_bytes;
8923 : : fprintf (stderr, "\nKind Nodes Bytes\n");
8924 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8925 : : total_nodes = total_bytes = 0;
8926 : :
8927 : : {
8928 : : auto_vec<unsigned> indices (all_kinds);
8929 : : for (unsigned i = 0; i < all_kinds; i++)
8930 : : indices.quick_push (i);
8931 : : indices.qsort (tree_nodes_cmp);
8932 : :
8933 : : for (unsigned i = 0; i < (int) all_kinds; i++)
8934 : : {
8935 : : unsigned j = indices[i];
8936 : : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n",
8937 : : tree_node_kind_names[j], SIZE_AMOUNT (tree_node_counts[j]),
8938 : : SIZE_AMOUNT (tree_node_sizes[j]));
8939 : : total_nodes += tree_node_counts[j];
8940 : : total_bytes += tree_node_sizes[j];
8941 : : }
8942 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8943 : : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n", "Total",
8944 : : SIZE_AMOUNT (total_nodes), SIZE_AMOUNT (total_bytes));
8945 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8946 : : }
8947 : :
8948 : : {
8949 : : fprintf (stderr, "Code Nodes\n");
8950 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8951 : :
8952 : : auto_vec<unsigned> indices (MAX_TREE_CODES);
8953 : : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8954 : : indices.quick_push (i);
8955 : : indices.qsort (tree_codes_cmp);
8956 : :
8957 : : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8958 : : {
8959 : : unsigned j = indices[i];
8960 : : fprintf (stderr, "%-32s %6" PRIu64 "%c\n",
8961 : : get_tree_code_name ((enum tree_code) j),
8962 : : SIZE_AMOUNT (tree_code_counts[j]));
8963 : : }
8964 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8965 : : fprintf (stderr, "\n");
8966 : : ssanames_print_statistics ();
8967 : : fprintf (stderr, "\n");
8968 : : phinodes_print_statistics ();
8969 : : fprintf (stderr, "\n");
8970 : : }
8971 : : }
8972 : : else
8973 : 0 : fprintf (stderr, "(No per-node statistics)\n");
8974 : :
8975 : 0 : print_type_hash_statistics ();
8976 : 0 : print_debug_expr_statistics ();
8977 : 0 : print_value_expr_statistics ();
8978 : 0 : lang_hooks.print_statistics ();
8979 : 0 : }
8980 : :
8981 : : #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
8982 : :
8983 : : /* Generate a crc32 of the low BYTES bytes of VALUE. */
8984 : :
8985 : : unsigned
8986 : 16941852 : crc32_unsigned_n (unsigned chksum, unsigned value, unsigned bytes)
8987 : : {
8988 : : /* This relies on the raw feedback's top 4 bits being zero. */
8989 : : #define FEEDBACK(X) ((X) * 0x04c11db7)
8990 : : #define SYNDROME(X) (FEEDBACK ((X) & 1) ^ FEEDBACK ((X) & 2) \
8991 : : ^ FEEDBACK ((X) & 4) ^ FEEDBACK ((X) & 8))
8992 : 16941852 : static const unsigned syndromes[16] =
8993 : : {
8994 : : SYNDROME(0x0), SYNDROME(0x1), SYNDROME(0x2), SYNDROME(0x3),
8995 : : SYNDROME(0x4), SYNDROME(0x5), SYNDROME(0x6), SYNDROME(0x7),
8996 : : SYNDROME(0x8), SYNDROME(0x9), SYNDROME(0xa), SYNDROME(0xb),
8997 : : SYNDROME(0xc), SYNDROME(0xd), SYNDROME(0xe), SYNDROME(0xf),
8998 : : };
8999 : : #undef FEEDBACK
9000 : : #undef SYNDROME
9001 : :
9002 : 16941852 : value <<= (32 - bytes * 8);
9003 : 56003592 : for (unsigned ix = bytes * 2; ix--; value <<= 4)
9004 : : {
9005 : 39061740 : unsigned feedback = syndromes[((value ^ chksum) >> 28) & 0xf];
9006 : :
9007 : 39061740 : chksum = (chksum << 4) ^ feedback;
9008 : : }
9009 : :
9010 : 16941852 : return chksum;
9011 : : }
9012 : :
9013 : : /* Generate a crc32 of a string. */
9014 : :
9015 : : unsigned
9016 : 8613 : crc32_string (unsigned chksum, const char *string)
9017 : : {
9018 : 345017 : do
9019 : 345017 : chksum = crc32_byte (chksum, *string);
9020 : 345017 : while (*string++);
9021 : 8613 : return chksum;
9022 : : }
9023 : :
9024 : : /* P is a string that will be used in a symbol. Mask out any characters
9025 : : that are not valid in that context. */
9026 : :
9027 : : void
9028 : 7262 : clean_symbol_name (char *p)
9029 : : {
9030 : 84989 : for (; *p; p++)
9031 : 77727 : if (! (ISALNUM (*p)
9032 : : #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9033 : : || *p == '$'
9034 : : #endif
9035 : : #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9036 : : || *p == '.'
9037 : : #endif
9038 : : ))
9039 : 7190 : *p = '_';
9040 : 7262 : }
9041 : :
9042 : : static GTY(()) unsigned anon_cnt = 0; /* Saved for PCH. */
9043 : :
9044 : : /* Create a unique anonymous identifier. The identifier is still a
9045 : : valid assembly label. */
9046 : :
9047 : : tree
9048 : 2763129 : make_anon_name ()
9049 : : {
9050 : 2763129 : const char *fmt =
9051 : : #if !defined (NO_DOT_IN_LABEL)
9052 : : "."
9053 : : #elif !defined (NO_DOLLAR_IN_LABEL)
9054 : : "$"
9055 : : #else
9056 : : "_"
9057 : : #endif
9058 : : "_anon_%d";
9059 : :
9060 : 2763129 : char buf[24];
9061 : 2763129 : int len = snprintf (buf, sizeof (buf), fmt, anon_cnt++);
9062 : 2763129 : gcc_checking_assert (len < int (sizeof (buf)));
9063 : :
9064 : 2763129 : tree id = get_identifier_with_length (buf, len);
9065 : 2763129 : IDENTIFIER_ANON_P (id) = true;
9066 : :
9067 : 2763129 : return id;
9068 : : }
9069 : :
9070 : : /* Generate a name for a special-purpose function.
9071 : : The generated name may need to be unique across the whole link.
9072 : : Changes to this function may also require corresponding changes to
9073 : : xstrdup_mask_random.
9074 : : TYPE is some string to identify the purpose of this function to the
9075 : : linker or collect2; it must start with an uppercase letter,
9076 : : one of:
9077 : : I - for constructors
9078 : : D - for destructors
9079 : : N - for C++ anonymous namespaces
9080 : : F - for DWARF unwind frame information. */
9081 : :
9082 : : tree
9083 : 5353 : get_file_function_name (const char *type)
9084 : : {
9085 : 5353 : char *buf;
9086 : 5353 : const char *p;
9087 : 5353 : char *q;
9088 : :
9089 : : /* If we already have a name we know to be unique, just use that. */
9090 : 5353 : if (first_global_object_name)
9091 : 5057 : p = q = ASTRDUP (first_global_object_name);
9092 : : /* If the target is handling the constructors/destructors, they
9093 : : will be local to this file and the name is only necessary for
9094 : : debugging purposes.
9095 : : We also assign sub_I and sub_D sufixes to constructors called from
9096 : : the global static constructors. These are always local.
9097 : : OpenMP "declare target" offloaded constructors/destructors use "off_I" and
9098 : : "off_D" for the same purpose. */
9099 : 296 : else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
9100 : 592 : || ((startswith (type, "sub_") || startswith (type, "off_"))
9101 : 296 : && (type[4] == 'I' || type[4] == 'D')))
9102 : : {
9103 : 296 : const char *file = main_input_filename;
9104 : 296 : if (! file)
9105 : 0 : file = LOCATION_FILE (input_location);
9106 : : /* Just use the file's basename, because the full pathname
9107 : : might be quite long. */
9108 : 296 : p = q = ASTRDUP (lbasename (file));
9109 : : }
9110 : : else
9111 : : {
9112 : : /* Otherwise, the name must be unique across the entire link.
9113 : : We don't have anything that we know to be unique to this translation
9114 : : unit, so use what we do have and throw in some randomness. */
9115 : 0 : unsigned len;
9116 : 0 : const char *name = weak_global_object_name;
9117 : 0 : const char *file = main_input_filename;
9118 : :
9119 : 0 : if (! name)
9120 : 0 : name = "";
9121 : 0 : if (! file)
9122 : 0 : file = LOCATION_FILE (input_location);
9123 : :
9124 : 0 : len = strlen (file);
9125 : 0 : q = (char *) alloca (9 + 19 + len + 1);
9126 : 0 : memcpy (q, file, len + 1);
9127 : :
9128 : 0 : snprintf (q + len, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
9129 : : crc32_string (0, name), get_random_seed (false));
9130 : :
9131 : 0 : p = q;
9132 : : }
9133 : :
9134 : 5353 : clean_symbol_name (q);
9135 : 5353 : buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
9136 : : + strlen (type));
9137 : :
9138 : : /* Set up the name of the file-level functions we may need.
9139 : : Use a global object (which is already required to be unique over
9140 : : the program) rather than the file name (which imposes extra
9141 : : constraints). */
9142 : 5353 : sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
9143 : :
9144 : 5353 : return get_identifier (buf);
9145 : : }
9146 : :
9147 : : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9148 : :
9149 : : /* Complain that the tree code of NODE does not match the expected 0
9150 : : terminated list of trailing codes. The trailing code list can be
9151 : : empty, for a more vague error message. FILE, LINE, and FUNCTION
9152 : : are of the caller. */
9153 : :
9154 : : void
9155 : 0 : tree_check_failed (const_tree node, const char *file,
9156 : : int line, const char *function, ...)
9157 : : {
9158 : 0 : va_list args;
9159 : 0 : const char *buffer;
9160 : 0 : unsigned length = 0;
9161 : 0 : enum tree_code code;
9162 : :
9163 : 0 : va_start (args, function);
9164 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9165 : 0 : length += 4 + strlen (get_tree_code_name (code));
9166 : 0 : va_end (args);
9167 : 0 : if (length)
9168 : : {
9169 : 0 : char *tmp;
9170 : 0 : va_start (args, function);
9171 : 0 : length += strlen ("expected ");
9172 : 0 : buffer = tmp = (char *) alloca (length);
9173 : 0 : length = 0;
9174 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9175 : : {
9176 : 0 : const char *prefix = length ? " or " : "expected ";
9177 : :
9178 : 0 : strcpy (tmp + length, prefix);
9179 : 0 : length += strlen (prefix);
9180 : 0 : strcpy (tmp + length, get_tree_code_name (code));
9181 : 0 : length += strlen (get_tree_code_name (code));
9182 : : }
9183 : 0 : va_end (args);
9184 : : }
9185 : : else
9186 : : buffer = "unexpected node";
9187 : :
9188 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9189 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9190 : : function, trim_filename (file), line);
9191 : : }
9192 : :
9193 : : /* Complain that the tree code of NODE does match the expected 0
9194 : : terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9195 : : the caller. */
9196 : :
9197 : : void
9198 : 0 : tree_not_check_failed (const_tree node, const char *file,
9199 : : int line, const char *function, ...)
9200 : : {
9201 : 0 : va_list args;
9202 : 0 : char *buffer;
9203 : 0 : unsigned length = 0;
9204 : 0 : enum tree_code code;
9205 : :
9206 : 0 : va_start (args, function);
9207 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9208 : 0 : length += 4 + strlen (get_tree_code_name (code));
9209 : 0 : va_end (args);
9210 : 0 : va_start (args, function);
9211 : 0 : buffer = (char *) alloca (length);
9212 : 0 : length = 0;
9213 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9214 : : {
9215 : 0 : if (length)
9216 : : {
9217 : 0 : strcpy (buffer + length, " or ");
9218 : 0 : length += 4;
9219 : : }
9220 : 0 : strcpy (buffer + length, get_tree_code_name (code));
9221 : 0 : length += strlen (get_tree_code_name (code));
9222 : : }
9223 : 0 : va_end (args);
9224 : :
9225 : 0 : internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9226 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9227 : : function, trim_filename (file), line);
9228 : : }
9229 : :
9230 : : /* Similar to tree_check_failed, except that we check for a class of tree
9231 : : code, given in CL. */
9232 : :
9233 : : void
9234 : 0 : tree_class_check_failed (const_tree node, const enum tree_code_class cl,
9235 : : const char *file, int line, const char *function)
9236 : : {
9237 : 0 : internal_error
9238 : 0 : ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9239 : 0 : TREE_CODE_CLASS_STRING (cl),
9240 : 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9241 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9242 : : }
9243 : :
9244 : : /* Similar to tree_check_failed, except that instead of specifying a
9245 : : dozen codes, use the knowledge that they're all sequential. */
9246 : :
9247 : : void
9248 : 0 : tree_range_check_failed (const_tree node, const char *file, int line,
9249 : : const char *function, enum tree_code c1,
9250 : : enum tree_code c2)
9251 : : {
9252 : 0 : char *buffer;
9253 : 0 : unsigned length = 0;
9254 : 0 : unsigned int c;
9255 : :
9256 : 0 : for (c = c1; c <= c2; ++c)
9257 : 0 : length += 4 + strlen (get_tree_code_name ((enum tree_code) c));
9258 : :
9259 : 0 : length += strlen ("expected ");
9260 : 0 : buffer = (char *) alloca (length);
9261 : 0 : length = 0;
9262 : :
9263 : 0 : for (c = c1; c <= c2; ++c)
9264 : : {
9265 : 0 : const char *prefix = length ? " or " : "expected ";
9266 : :
9267 : 0 : strcpy (buffer + length, prefix);
9268 : 0 : length += strlen (prefix);
9269 : 0 : strcpy (buffer + length, get_tree_code_name ((enum tree_code) c));
9270 : 0 : length += strlen (get_tree_code_name ((enum tree_code) c));
9271 : : }
9272 : :
9273 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9274 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9275 : : function, trim_filename (file), line);
9276 : : }
9277 : :
9278 : :
9279 : : /* Similar to tree_check_failed, except that we check that a tree does
9280 : : not have the specified code, given in CL. */
9281 : :
9282 : : void
9283 : 0 : tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
9284 : : const char *file, int line, const char *function)
9285 : : {
9286 : 0 : internal_error
9287 : 0 : ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9288 : 0 : TREE_CODE_CLASS_STRING (cl),
9289 : 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9290 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9291 : : }
9292 : :
9293 : :
9294 : : /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9295 : :
9296 : : void
9297 : 0 : omp_clause_check_failed (const_tree node, const char *file, int line,
9298 : : const char *function, enum omp_clause_code code)
9299 : : {
9300 : 0 : internal_error ("tree check: expected %<omp_clause %s%>, have %qs "
9301 : : "in %s, at %s:%d",
9302 : 0 : omp_clause_code_name[code],
9303 : 0 : get_tree_code_name (TREE_CODE (node)),
9304 : : function, trim_filename (file), line);
9305 : : }
9306 : :
9307 : :
9308 : : /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9309 : :
9310 : : void
9311 : 0 : omp_clause_range_check_failed (const_tree node, const char *file, int line,
9312 : : const char *function, enum omp_clause_code c1,
9313 : : enum omp_clause_code c2)
9314 : : {
9315 : 0 : char *buffer;
9316 : 0 : unsigned length = 0;
9317 : 0 : unsigned int c;
9318 : :
9319 : 0 : for (c = c1; c <= c2; ++c)
9320 : 0 : length += 4 + strlen (omp_clause_code_name[c]);
9321 : :
9322 : 0 : length += strlen ("expected ");
9323 : 0 : buffer = (char *) alloca (length);
9324 : 0 : length = 0;
9325 : :
9326 : 0 : for (c = c1; c <= c2; ++c)
9327 : : {
9328 : 0 : const char *prefix = length ? " or " : "expected ";
9329 : :
9330 : 0 : strcpy (buffer + length, prefix);
9331 : 0 : length += strlen (prefix);
9332 : 0 : strcpy (buffer + length, omp_clause_code_name[c]);
9333 : 0 : length += strlen (omp_clause_code_name[c]);
9334 : : }
9335 : :
9336 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9337 : 0 : buffer, omp_clause_code_name[TREE_CODE (node)],
9338 : : function, trim_filename (file), line);
9339 : : }
9340 : :
9341 : :
9342 : : #undef DEFTREESTRUCT
9343 : : #define DEFTREESTRUCT(VAL, NAME) NAME,
9344 : :
9345 : : static const char *ts_enum_names[] = {
9346 : : #include "treestruct.def"
9347 : : };
9348 : : #undef DEFTREESTRUCT
9349 : :
9350 : : #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9351 : :
9352 : : /* Similar to tree_class_check_failed, except that we check for
9353 : : whether CODE contains the tree structure identified by EN. */
9354 : :
9355 : : void
9356 : 0 : tree_contains_struct_check_failed (const_tree node,
9357 : : const enum tree_node_structure_enum en,
9358 : : const char *file, int line,
9359 : : const char *function)
9360 : : {
9361 : 0 : internal_error
9362 : 0 : ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9363 : 0 : TS_ENUM_NAME (en),
9364 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9365 : : }
9366 : :
9367 : :
9368 : : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9369 : : (dynamically sized) vector. */
9370 : :
9371 : : void
9372 : 0 : tree_int_cst_elt_check_failed (int idx, int len, const char *file, int line,
9373 : : const char *function)
9374 : : {
9375 : 0 : internal_error
9376 : 0 : ("tree check: accessed elt %d of %<tree_int_cst%> with %d elts in %s, "
9377 : : "at %s:%d",
9378 : : idx + 1, len, function, trim_filename (file), line);
9379 : : }
9380 : :
9381 : : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9382 : : (dynamically sized) vector. */
9383 : :
9384 : : void
9385 : 0 : tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
9386 : : const char *function)
9387 : : {
9388 : 0 : internal_error
9389 : 0 : ("tree check: accessed elt %d of %<tree_vec%> with %d elts in %s, at %s:%d",
9390 : : idx + 1, len, function, trim_filename (file), line);
9391 : : }
9392 : :
9393 : : /* Similar to above, except that the check is for the bounds of the operand
9394 : : vector of an expression node EXP. */
9395 : :
9396 : : void
9397 : 0 : tree_operand_check_failed (int idx, const_tree exp, const char *file,
9398 : : int line, const char *function)
9399 : : {
9400 : 0 : enum tree_code code = TREE_CODE (exp);
9401 : 0 : internal_error
9402 : 0 : ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9403 : : idx + 1, get_tree_code_name (code), TREE_OPERAND_LENGTH (exp),
9404 : : function, trim_filename (file), line);
9405 : : }
9406 : :
9407 : : /* Similar to above, except that the check is for the number of
9408 : : operands of an OMP_CLAUSE node. */
9409 : :
9410 : : void
9411 : 0 : omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
9412 : : int line, const char *function)
9413 : : {
9414 : 0 : internal_error
9415 : 0 : ("tree check: accessed operand %d of %<omp_clause %s%> with %d operands "
9416 : 0 : "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
9417 : 0 : omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
9418 : : trim_filename (file), line);
9419 : : }
9420 : : #endif /* ENABLE_TREE_CHECKING */
9421 : :
9422 : : /* Create a new vector type node holding NUNITS units of type INNERTYPE,
9423 : : and mapped to the machine mode MODE. Initialize its fields and build
9424 : : the information necessary for debugging output. */
9425 : :
9426 : : static tree
9427 : 71300063 : make_vector_type (tree innertype, poly_int64 nunits, machine_mode mode)
9428 : : {
9429 : 71300063 : tree t;
9430 : 71300063 : tree mv_innertype = TYPE_MAIN_VARIANT (innertype);
9431 : :
9432 : 71300063 : t = make_node (VECTOR_TYPE);
9433 : 71300063 : TREE_TYPE (t) = mv_innertype;
9434 : 71300063 : SET_TYPE_VECTOR_SUBPARTS (t, nunits);
9435 : 71300063 : SET_TYPE_MODE (t, mode);
9436 : :
9437 : 71300063 : if (TYPE_STRUCTURAL_EQUALITY_P (mv_innertype) || in_lto_p)
9438 : 1213465 : SET_TYPE_STRUCTURAL_EQUALITY (t);
9439 : 70086598 : else if ((TYPE_CANONICAL (mv_innertype) != innertype
9440 : 66547316 : || mode != VOIDmode)
9441 : 101102616 : && !VECTOR_BOOLEAN_TYPE_P (t))
9442 : 32662598 : TYPE_CANONICAL (t)
9443 : 65325196 : = make_vector_type (TYPE_CANONICAL (mv_innertype), nunits, VOIDmode);
9444 : :
9445 : 71300063 : layout_type (t);
9446 : :
9447 : 71300063 : hashval_t hash = type_hash_canon_hash (t);
9448 : 71300063 : t = type_hash_canon (hash, t);
9449 : :
9450 : : /* We have built a main variant, based on the main variant of the
9451 : : inner type. Use it to build the variant we return. */
9452 : 142594835 : if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
9453 : 72121053 : && TREE_TYPE (t) != innertype)
9454 : 824988 : return build_type_attribute_qual_variant (t,
9455 : 824988 : TYPE_ATTRIBUTES (innertype),
9456 : 1649976 : TYPE_QUALS (innertype));
9457 : :
9458 : : return t;
9459 : : }
9460 : :
9461 : : static tree
9462 : 3988377 : make_or_reuse_type (unsigned size, int unsignedp)
9463 : : {
9464 : 3988377 : int i;
9465 : :
9466 : 3988377 : if (size == INT_TYPE_SIZE)
9467 : 856173 : return unsignedp ? unsigned_type_node : integer_type_node;
9468 : 3132204 : if (size == CHAR_TYPE_SIZE)
9469 : 570782 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
9470 : 2561422 : if (size == SHORT_TYPE_SIZE)
9471 : 856173 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
9472 : 1741322 : if (size == LONG_TYPE_SIZE)
9473 : 834588 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
9474 : 870661 : if (size == LONG_LONG_TYPE_SIZE)
9475 : 21585 : return (unsignedp ? long_long_unsigned_type_node
9476 : 21585 : : long_long_integer_type_node);
9477 : :
9478 : 863270 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9479 : 849076 : if (size == int_n_data[i].bitsize
9480 : 849076 : && int_n_enabled_p[i])
9481 : 834882 : return (unsignedp ? int_n_trees[i].unsigned_type
9482 : 834882 : : int_n_trees[i].signed_type);
9483 : :
9484 : 14194 : if (unsignedp)
9485 : 7097 : return make_unsigned_type (size);
9486 : : else
9487 : 7097 : return make_signed_type (size);
9488 : : }
9489 : :
9490 : : /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9491 : :
9492 : : static tree
9493 : 5707820 : make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
9494 : : {
9495 : 5707820 : if (satp)
9496 : : {
9497 : 2853910 : if (size == SHORT_FRACT_TYPE_SIZE)
9498 : 570782 : return unsignedp ? sat_unsigned_short_fract_type_node
9499 : 570782 : : sat_short_fract_type_node;
9500 : 2283128 : if (size == FRACT_TYPE_SIZE)
9501 : 570782 : return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
9502 : 1712346 : if (size == LONG_FRACT_TYPE_SIZE)
9503 : 570782 : return unsignedp ? sat_unsigned_long_fract_type_node
9504 : 570782 : : sat_long_fract_type_node;
9505 : 1141564 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9506 : 570782 : return unsignedp ? sat_unsigned_long_long_fract_type_node
9507 : 570782 : : sat_long_long_fract_type_node;
9508 : : }
9509 : : else
9510 : : {
9511 : 2853910 : if (size == SHORT_FRACT_TYPE_SIZE)
9512 : 570782 : return unsignedp ? unsigned_short_fract_type_node
9513 : 570782 : : short_fract_type_node;
9514 : 2283128 : if (size == FRACT_TYPE_SIZE)
9515 : 570782 : return unsignedp ? unsigned_fract_type_node : fract_type_node;
9516 : 1712346 : if (size == LONG_FRACT_TYPE_SIZE)
9517 : 570782 : return unsignedp ? unsigned_long_fract_type_node
9518 : 570782 : : long_fract_type_node;
9519 : 1141564 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9520 : 570782 : return unsignedp ? unsigned_long_long_fract_type_node
9521 : 570782 : : long_long_fract_type_node;
9522 : : }
9523 : :
9524 : 1141564 : return make_fract_type (size, unsignedp, satp);
9525 : : }
9526 : :
9527 : : /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9528 : :
9529 : : static tree
9530 : 4566256 : make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
9531 : : {
9532 : 4566256 : if (satp)
9533 : : {
9534 : 2283128 : if (size == SHORT_ACCUM_TYPE_SIZE)
9535 : 570782 : return unsignedp ? sat_unsigned_short_accum_type_node
9536 : 570782 : : sat_short_accum_type_node;
9537 : 1712346 : if (size == ACCUM_TYPE_SIZE)
9538 : 570782 : return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
9539 : 1141564 : if (size == LONG_ACCUM_TYPE_SIZE)
9540 : 570782 : return unsignedp ? sat_unsigned_long_accum_type_node
9541 : 570782 : : sat_long_accum_type_node;
9542 : 570782 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9543 : 570782 : return unsignedp ? sat_unsigned_long_long_accum_type_node
9544 : 570782 : : sat_long_long_accum_type_node;
9545 : : }
9546 : : else
9547 : : {
9548 : 2283128 : if (size == SHORT_ACCUM_TYPE_SIZE)
9549 : 570782 : return unsignedp ? unsigned_short_accum_type_node
9550 : 570782 : : short_accum_type_node;
9551 : 1712346 : if (size == ACCUM_TYPE_SIZE)
9552 : 570782 : return unsignedp ? unsigned_accum_type_node : accum_type_node;
9553 : 1141564 : if (size == LONG_ACCUM_TYPE_SIZE)
9554 : 570782 : return unsignedp ? unsigned_long_accum_type_node
9555 : 570782 : : long_accum_type_node;
9556 : 570782 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9557 : 570782 : return unsignedp ? unsigned_long_long_accum_type_node
9558 : 570782 : : long_long_accum_type_node;
9559 : : }
9560 : :
9561 : 0 : return make_accum_type (size, unsignedp, satp);
9562 : : }
9563 : :
9564 : :
9565 : : /* Create an atomic variant node for TYPE. This routine is called
9566 : : during initialization of data types to create the 5 basic atomic
9567 : : types. The generic build_variant_type function requires these to
9568 : : already be set up in order to function properly, so cannot be
9569 : : called from there. If ALIGN is non-zero, then ensure alignment is
9570 : : overridden to this value. */
9571 : :
9572 : : static tree
9573 : 1426955 : build_atomic_base (tree type, unsigned int align)
9574 : : {
9575 : 1426955 : tree t;
9576 : :
9577 : : /* Make sure its not already registered. */
9578 : 1426955 : if ((t = get_qualified_type (type, TYPE_QUAL_ATOMIC)))
9579 : : return t;
9580 : :
9581 : 1426955 : t = build_variant_type_copy (type);
9582 : 1426955 : set_type_quals (t, TYPE_QUAL_ATOMIC);
9583 : :
9584 : 1426955 : if (align)
9585 : 0 : SET_TYPE_ALIGN (t, align);
9586 : :
9587 : : return t;
9588 : : }
9589 : :
9590 : : /* Information about the _FloatN and _FloatNx types. This must be in
9591 : : the same order as the corresponding TI_* enum values. */
9592 : : const floatn_type_info floatn_nx_types[NUM_FLOATN_NX_TYPES] =
9593 : : {
9594 : : { 16, false },
9595 : : { 32, false },
9596 : : { 64, false },
9597 : : { 128, false },
9598 : : { 32, true },
9599 : : { 64, true },
9600 : : { 128, true },
9601 : : };
9602 : :
9603 : :
9604 : : /* Create nodes for all integer types (and error_mark_node) using the sizes
9605 : : of C datatypes. SIGNED_CHAR specifies whether char is signed. */
9606 : :
9607 : : void
9608 : 285391 : build_common_tree_nodes (bool signed_char)
9609 : : {
9610 : 285391 : int i;
9611 : :
9612 : 285391 : error_mark_node = make_node (ERROR_MARK);
9613 : 285391 : TREE_TYPE (error_mark_node) = error_mark_node;
9614 : :
9615 : 285391 : initialize_sizetypes ();
9616 : :
9617 : : /* Define both `signed char' and `unsigned char'. */
9618 : 285391 : signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
9619 : 285391 : TYPE_STRING_FLAG (signed_char_type_node) = 1;
9620 : 285391 : unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
9621 : 285391 : TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
9622 : :
9623 : : /* Define `char', which is like either `signed char' or `unsigned char'
9624 : : but not the same as either. */
9625 : 285391 : char_type_node
9626 : 285391 : = (signed_char
9627 : 285391 : ? make_signed_type (CHAR_TYPE_SIZE)
9628 : 56854 : : make_unsigned_type (CHAR_TYPE_SIZE));
9629 : 285391 : TYPE_STRING_FLAG (char_type_node) = 1;
9630 : :
9631 : 285391 : short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
9632 : 285391 : short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
9633 : 285391 : integer_type_node = make_signed_type (INT_TYPE_SIZE);
9634 : 285391 : unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
9635 : 292586 : long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
9636 : 292586 : long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
9637 : 285391 : long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
9638 : 285391 : long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
9639 : :
9640 : 856173 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9641 : : {
9642 : 285391 : int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
9643 : 285391 : int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
9644 : :
9645 : 285391 : if (int_n_enabled_p[i])
9646 : : {
9647 : 278294 : integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type;
9648 : 278294 : integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type;
9649 : : }
9650 : : }
9651 : :
9652 : : /* Define a boolean type. This type only represents boolean values but
9653 : : may be larger than char depending on the value of BOOL_TYPE_SIZE. */
9654 : 285391 : boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
9655 : 285391 : TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
9656 : 285391 : TYPE_PRECISION (boolean_type_node) = 1;
9657 : 285391 : TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
9658 : :
9659 : : /* Define what type to use for size_t. */
9660 : 292586 : if (strcmp (SIZE_TYPE, "unsigned int") == 0)
9661 : 7195 : size_type_node = unsigned_type_node;
9662 : 278196 : else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
9663 : 278196 : size_type_node = long_unsigned_type_node;
9664 : 0 : else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
9665 : 0 : size_type_node = long_long_unsigned_type_node;
9666 : 0 : else if (strcmp (SIZE_TYPE, "short unsigned int") == 0)
9667 : 0 : size_type_node = short_unsigned_type_node;
9668 : : else
9669 : : {
9670 : 0 : int i;
9671 : :
9672 : 0 : size_type_node = NULL_TREE;
9673 : 0 : for (i = 0; i < NUM_INT_N_ENTS; i++)
9674 : 0 : if (int_n_enabled_p[i])
9675 : : {
9676 : 0 : char name[50], altname[50];
9677 : 0 : sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
9678 : 0 : sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize);
9679 : :
9680 : 0 : if (strcmp (name, SIZE_TYPE) == 0
9681 : 0 : || strcmp (altname, SIZE_TYPE) == 0)
9682 : : {
9683 : 0 : size_type_node = int_n_trees[i].unsigned_type;
9684 : : }
9685 : : }
9686 : 0 : if (size_type_node == NULL_TREE)
9687 : 0 : gcc_unreachable ();
9688 : : }
9689 : :
9690 : : /* Define what type to use for ptrdiff_t. */
9691 : 292586 : if (strcmp (PTRDIFF_TYPE, "int") == 0)
9692 : 7195 : ptrdiff_type_node = integer_type_node;
9693 : 278196 : else if (strcmp (PTRDIFF_TYPE, "long int") == 0)
9694 : 278196 : ptrdiff_type_node = long_integer_type_node;
9695 : 0 : else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)
9696 : 0 : ptrdiff_type_node = long_long_integer_type_node;
9697 : 0 : else if (strcmp (PTRDIFF_TYPE, "short int") == 0)
9698 : 0 : ptrdiff_type_node = short_integer_type_node;
9699 : : else
9700 : : {
9701 : 0 : ptrdiff_type_node = NULL_TREE;
9702 : 0 : for (int i = 0; i < NUM_INT_N_ENTS; i++)
9703 : 0 : if (int_n_enabled_p[i])
9704 : : {
9705 : 0 : char name[50], altname[50];
9706 : 0 : sprintf (name, "__int%d", int_n_data[i].bitsize);
9707 : 0 : sprintf (altname, "__int%d__", int_n_data[i].bitsize);
9708 : :
9709 : 0 : if (strcmp (name, PTRDIFF_TYPE) == 0
9710 : 0 : || strcmp (altname, PTRDIFF_TYPE) == 0)
9711 : 0 : ptrdiff_type_node = int_n_trees[i].signed_type;
9712 : : }
9713 : 0 : if (ptrdiff_type_node == NULL_TREE)
9714 : 0 : gcc_unreachable ();
9715 : : }
9716 : :
9717 : : /* Fill in the rest of the sized types. Reuse existing type nodes
9718 : : when possible. */
9719 : 285391 : intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
9720 : 285391 : intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
9721 : 285391 : intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
9722 : 285391 : intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
9723 : 285391 : intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
9724 : :
9725 : 285391 : unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
9726 : 285391 : unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
9727 : 285391 : unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
9728 : 285391 : unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
9729 : 285391 : unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
9730 : :
9731 : : /* Don't call build_qualified type for atomics. That routine does
9732 : : special processing for atomics, and until they are initialized
9733 : : it's better not to make that call.
9734 : :
9735 : : Check to see if there is a target override for atomic types. */
9736 : :
9737 : 285391 : atomicQI_type_node = build_atomic_base (unsigned_intQI_type_node,
9738 : 285391 : targetm.atomic_align_for_mode (QImode));
9739 : 285391 : atomicHI_type_node = build_atomic_base (unsigned_intHI_type_node,
9740 : 285391 : targetm.atomic_align_for_mode (HImode));
9741 : 285391 : atomicSI_type_node = build_atomic_base (unsigned_intSI_type_node,
9742 : 285391 : targetm.atomic_align_for_mode (SImode));
9743 : 285391 : atomicDI_type_node = build_atomic_base (unsigned_intDI_type_node,
9744 : 285391 : targetm.atomic_align_for_mode (DImode));
9745 : 285391 : atomicTI_type_node = build_atomic_base (unsigned_intTI_type_node,
9746 : 285391 : targetm.atomic_align_for_mode (TImode));
9747 : :
9748 : 285391 : access_public_node = get_identifier ("public");
9749 : 285391 : access_protected_node = get_identifier ("protected");
9750 : 285391 : access_private_node = get_identifier ("private");
9751 : :
9752 : : /* Define these next since types below may used them. */
9753 : 285391 : integer_zero_node = build_int_cst (integer_type_node, 0);
9754 : 285391 : integer_one_node = build_int_cst (integer_type_node, 1);
9755 : 285391 : integer_minus_one_node = build_int_cst (integer_type_node, -1);
9756 : :
9757 : 285391 : size_zero_node = size_int (0);
9758 : 285391 : size_one_node = size_int (1);
9759 : 285391 : bitsize_zero_node = bitsize_int (0);
9760 : 285391 : bitsize_one_node = bitsize_int (1);
9761 : 285391 : bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
9762 : :
9763 : 285391 : boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9764 : 285391 : boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9765 : :
9766 : 285391 : void_type_node = make_node (VOID_TYPE);
9767 : 285391 : layout_type (void_type_node);
9768 : :
9769 : : /* We are not going to have real types in C with less than byte alignment,
9770 : : so we might as well not have any types that claim to have it. */
9771 : 285391 : SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT);
9772 : 285391 : TYPE_USER_ALIGN (void_type_node) = 0;
9773 : :
9774 : 285391 : void_node = make_node (VOID_CST);
9775 : 285391 : TREE_TYPE (void_node) = void_type_node;
9776 : :
9777 : 285391 : void_list_node = build_tree_list (NULL_TREE, void_type_node);
9778 : :
9779 : 285391 : null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
9780 : 285391 : layout_type (TREE_TYPE (null_pointer_node));
9781 : :
9782 : 285391 : ptr_type_node = build_pointer_type (void_type_node);
9783 : 285391 : const_ptr_type_node
9784 : 285391 : = build_pointer_type (build_type_variant (void_type_node, 1, 0));
9785 : 1997737 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
9786 : 1712346 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
9787 : :
9788 : 292586 : pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
9789 : :
9790 : 285391 : float_type_node = make_node (REAL_TYPE);
9791 : 285391 : machine_mode float_type_mode
9792 : 285391 : = targetm.c.mode_for_floating_type (TI_FLOAT_TYPE);
9793 : 285391 : SET_TYPE_MODE (float_type_node, float_type_mode);
9794 : 285391 : TYPE_PRECISION (float_type_node)
9795 : 285391 : = GET_MODE_PRECISION (float_type_mode).to_constant ();
9796 : 285391 : layout_type (float_type_node);
9797 : :
9798 : 285391 : double_type_node = make_node (REAL_TYPE);
9799 : 285391 : machine_mode double_type_mode
9800 : 285391 : = targetm.c.mode_for_floating_type (TI_DOUBLE_TYPE);
9801 : 285391 : SET_TYPE_MODE (double_type_node, double_type_mode);
9802 : 285391 : TYPE_PRECISION (double_type_node)
9803 : 285391 : = GET_MODE_PRECISION (double_type_mode).to_constant ();
9804 : 285391 : layout_type (double_type_node);
9805 : :
9806 : 285391 : long_double_type_node = make_node (REAL_TYPE);
9807 : 285391 : machine_mode long_double_type_mode
9808 : 285391 : = targetm.c.mode_for_floating_type (TI_LONG_DOUBLE_TYPE);
9809 : 285391 : SET_TYPE_MODE (long_double_type_node, long_double_type_mode);
9810 : 285391 : TYPE_PRECISION (long_double_type_node)
9811 : 285391 : = GET_MODE_PRECISION (long_double_type_mode).to_constant ();
9812 : 285391 : layout_type (long_double_type_node);
9813 : :
9814 : 2283128 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9815 : : {
9816 : 1997737 : int n = floatn_nx_types[i].n;
9817 : 1997737 : bool extended = floatn_nx_types[i].extended;
9818 : 1997737 : scalar_float_mode mode;
9819 : 1997737 : if (!targetm.floatn_mode (n, extended).exists (&mode))
9820 : 285391 : continue;
9821 : 1712346 : int precision = GET_MODE_PRECISION (mode);
9822 : 1712346 : FLOATN_NX_TYPE_NODE (i) = make_node (REAL_TYPE);
9823 : 1712346 : TYPE_PRECISION (FLOATN_NX_TYPE_NODE (i)) = precision;
9824 : 1712346 : layout_type (FLOATN_NX_TYPE_NODE (i));
9825 : 1712346 : SET_TYPE_MODE (FLOATN_NX_TYPE_NODE (i), mode);
9826 : : }
9827 : 285391 : float128t_type_node = float128_type_node;
9828 : : #ifdef HAVE_BFmode
9829 : 285391 : if (REAL_MODE_FORMAT (BFmode) == &arm_bfloat_half_format
9830 : 285391 : && targetm.scalar_mode_supported_p (BFmode)
9831 : 570782 : && targetm.libgcc_floating_mode_supported_p (BFmode))
9832 : : {
9833 : 285391 : bfloat16_type_node = make_node (REAL_TYPE);
9834 : 285391 : TYPE_PRECISION (bfloat16_type_node) = GET_MODE_PRECISION (BFmode);
9835 : 285391 : layout_type (bfloat16_type_node);
9836 : 285391 : SET_TYPE_MODE (bfloat16_type_node, BFmode);
9837 : : }
9838 : : #endif
9839 : :
9840 : 285391 : float_ptr_type_node = build_pointer_type (float_type_node);
9841 : 285391 : double_ptr_type_node = build_pointer_type (double_type_node);
9842 : 285391 : long_double_ptr_type_node = build_pointer_type (long_double_type_node);
9843 : 285391 : integer_ptr_type_node = build_pointer_type (integer_type_node);
9844 : :
9845 : : /* Fixed size integer types. */
9846 : 285391 : uint16_type_node = make_or_reuse_type (16, 1);
9847 : 285391 : uint32_type_node = make_or_reuse_type (32, 1);
9848 : 285391 : uint64_type_node = make_or_reuse_type (64, 1);
9849 : 285391 : if (targetm.scalar_mode_supported_p (TImode))
9850 : 278294 : uint128_type_node = make_or_reuse_type (128, 1);
9851 : :
9852 : : /* Decimal float types. */
9853 : 285391 : if (targetm.decimal_float_supported_p ())
9854 : : {
9855 : 285391 : dfloat32_type_node = make_node (REAL_TYPE);
9856 : 285391 : TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
9857 : 285391 : SET_TYPE_MODE (dfloat32_type_node, SDmode);
9858 : 285391 : layout_type (dfloat32_type_node);
9859 : :
9860 : 285391 : dfloat64_type_node = make_node (REAL_TYPE);
9861 : 285391 : TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
9862 : 285391 : SET_TYPE_MODE (dfloat64_type_node, DDmode);
9863 : 285391 : layout_type (dfloat64_type_node);
9864 : :
9865 : 285391 : dfloat128_type_node = make_node (REAL_TYPE);
9866 : 285391 : TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
9867 : 285391 : SET_TYPE_MODE (dfloat128_type_node, TDmode);
9868 : 285391 : layout_type (dfloat128_type_node);
9869 : :
9870 : 285391 : dfloat64x_type_node = make_node (REAL_TYPE);
9871 : 285391 : TYPE_PRECISION (dfloat64x_type_node) = DECIMAL128_TYPE_SIZE;
9872 : 285391 : SET_TYPE_MODE (dfloat64x_type_node, TDmode);
9873 : 285391 : layout_type (dfloat64x_type_node);
9874 : : }
9875 : :
9876 : 285391 : complex_integer_type_node = build_complex_type (integer_type_node, true);
9877 : 285391 : complex_float_type_node = build_complex_type (float_type_node, true);
9878 : 285391 : complex_double_type_node = build_complex_type (double_type_node, true);
9879 : 285391 : complex_long_double_type_node = build_complex_type (long_double_type_node,
9880 : : true);
9881 : :
9882 : 2283128 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9883 : : {
9884 : 1997737 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
9885 : 1712346 : COMPLEX_FLOATN_NX_TYPE_NODE (i)
9886 : 1712346 : = build_complex_type (FLOATN_NX_TYPE_NODE (i));
9887 : : }
9888 : :
9889 : : /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9890 : : #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9891 : : sat_ ## KIND ## _type_node = \
9892 : : make_sat_signed_ ## KIND ## _type (SIZE); \
9893 : : sat_unsigned_ ## KIND ## _type_node = \
9894 : : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9895 : : KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9896 : : unsigned_ ## KIND ## _type_node = \
9897 : : make_unsigned_ ## KIND ## _type (SIZE);
9898 : :
9899 : : #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9900 : : sat_ ## WIDTH ## KIND ## _type_node = \
9901 : : make_sat_signed_ ## KIND ## _type (SIZE); \
9902 : : sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9903 : : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9904 : : WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9905 : : unsigned_ ## WIDTH ## KIND ## _type_node = \
9906 : : make_unsigned_ ## KIND ## _type (SIZE);
9907 : :
9908 : : /* Make fixed-point type nodes based on four different widths. */
9909 : : #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9910 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9911 : : MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9912 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9913 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9914 : :
9915 : : /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9916 : : #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9917 : : NAME ## _type_node = \
9918 : : make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9919 : : u ## NAME ## _type_node = \
9920 : : make_or_reuse_unsigned_ ## KIND ## _type \
9921 : : (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9922 : : sat_ ## NAME ## _type_node = \
9923 : : make_or_reuse_sat_signed_ ## KIND ## _type \
9924 : : (GET_MODE_BITSIZE (MODE ## mode)); \
9925 : : sat_u ## NAME ## _type_node = \
9926 : : make_or_reuse_sat_unsigned_ ## KIND ## _type \
9927 : : (GET_MODE_BITSIZE (U ## MODE ## mode));
9928 : :
9929 : : /* Fixed-point type and mode nodes. */
9930 : 285391 : MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
9931 : 285391 : MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
9932 : 285391 : MAKE_FIXED_MODE_NODE (fract, qq, QQ)
9933 : 285391 : MAKE_FIXED_MODE_NODE (fract, hq, HQ)
9934 : 285391 : MAKE_FIXED_MODE_NODE (fract, sq, SQ)
9935 : 285391 : MAKE_FIXED_MODE_NODE (fract, dq, DQ)
9936 : 285391 : MAKE_FIXED_MODE_NODE (fract, tq, TQ)
9937 : 285391 : MAKE_FIXED_MODE_NODE (accum, ha, HA)
9938 : 285391 : MAKE_FIXED_MODE_NODE (accum, sa, SA)
9939 : 285391 : MAKE_FIXED_MODE_NODE (accum, da, DA)
9940 : 285391 : MAKE_FIXED_MODE_NODE (accum, ta, TA)
9941 : :
9942 : 285391 : {
9943 : 285391 : tree t = targetm.build_builtin_va_list ();
9944 : :
9945 : : /* Many back-ends define record types without setting TYPE_NAME.
9946 : : If we copied the record type here, we'd keep the original
9947 : : record type without a name. This breaks name mangling. So,
9948 : : don't copy record types and let c_common_nodes_and_builtins()
9949 : : declare the type to be __builtin_va_list. */
9950 : 285391 : if (TREE_CODE (t) != RECORD_TYPE)
9951 : 285391 : t = build_variant_type_copy (t);
9952 : :
9953 : 285391 : va_list_type_node = t;
9954 : : }
9955 : :
9956 : : /* SCEV analyzer global shared trees. */
9957 : 285391 : chrec_dont_know = make_node (SCEV_NOT_KNOWN);
9958 : 285391 : TREE_TYPE (chrec_dont_know) = void_type_node;
9959 : 285391 : chrec_known = make_node (SCEV_KNOWN);
9960 : 285391 : TREE_TYPE (chrec_known) = void_type_node;
9961 : 285391 : }
9962 : :
9963 : : /* Modify DECL for given flags.
9964 : : TM_PURE attribute is set only on types, so the function will modify
9965 : : DECL's type when ECF_TM_PURE is used. */
9966 : :
9967 : : void
9968 : 30798139 : set_call_expr_flags (tree decl, int flags)
9969 : : {
9970 : 30798139 : if (flags & ECF_NOTHROW)
9971 : 26565851 : TREE_NOTHROW (decl) = 1;
9972 : 30798139 : if (flags & ECF_CONST)
9973 : 12748235 : TREE_READONLY (decl) = 1;
9974 : 30798139 : if (flags & ECF_PURE)
9975 : 1491931 : DECL_PURE_P (decl) = 1;
9976 : 30798139 : if (flags & ECF_LOOPING_CONST_OR_PURE)
9977 : 0 : DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
9978 : 30798139 : if (flags & ECF_NOVOPS)
9979 : 0 : DECL_IS_NOVOPS (decl) = 1;
9980 : 30798139 : if (flags & ECF_NORETURN)
9981 : 1226016 : TREE_THIS_VOLATILE (decl) = 1;
9982 : 30798139 : if (flags & ECF_MALLOC)
9983 : 734280 : DECL_IS_MALLOC (decl) = 1;
9984 : 30798139 : if (flags & ECF_RETURNS_TWICE)
9985 : 0 : DECL_IS_RETURNS_TWICE (decl) = 1;
9986 : 30798139 : if (flags & ECF_LEAF)
9987 : 26408856 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
9988 : 26408856 : NULL, DECL_ATTRIBUTES (decl));
9989 : 30798139 : if (flags & ECF_COLD)
9990 : 649721 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("cold"),
9991 : 649721 : NULL, DECL_ATTRIBUTES (decl));
9992 : 30798139 : if (flags & ECF_RET1)
9993 : 0 : DECL_ATTRIBUTES (decl)
9994 : 0 : = tree_cons (get_identifier ("fn spec"),
9995 : : build_tree_list (NULL_TREE, build_string (2, "1 ")),
9996 : 0 : DECL_ATTRIBUTES (decl));
9997 : 30798139 : if ((flags & ECF_TM_PURE) && flag_tm)
9998 : 544 : apply_tm_attr (decl, get_identifier ("transaction_pure"));
9999 : 30798139 : if ((flags & ECF_XTHROW))
10000 : 410787 : DECL_ATTRIBUTES (decl)
10001 : 821574 : = tree_cons (get_identifier ("expected_throw"),
10002 : 410787 : NULL, DECL_ATTRIBUTES (decl));
10003 : : /* Looping const or pure is implied by noreturn.
10004 : : There is currently no way to declare looping const or looping pure alone. */
10005 : 30798139 : gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE)
10006 : : || ((flags & ECF_NORETURN) && (flags & (ECF_CONST | ECF_PURE))));
10007 : 30798139 : }
10008 : :
10009 : :
10010 : : /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
10011 : :
10012 : : static void
10013 : 9463918 : local_define_builtin (const char *name, tree type, enum built_in_function code,
10014 : : const char *library_name, int ecf_flags)
10015 : : {
10016 : 9463918 : tree decl;
10017 : :
10018 : 9463918 : decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
10019 : : library_name, NULL_TREE);
10020 : 9463918 : set_call_expr_flags (decl, ecf_flags);
10021 : :
10022 : 9463918 : set_builtin_decl (code, decl, true);
10023 : 9463918 : }
10024 : :
10025 : : /* Call this function after instantiating all builtins that the language
10026 : : front end cares about. This will build the rest of the builtins
10027 : : and internal functions that are relied upon by the tree optimizers and
10028 : : the middle-end. */
10029 : :
10030 : : void
10031 : 285375 : build_common_builtin_nodes (void)
10032 : : {
10033 : 285375 : tree tmp, ftype;
10034 : 285375 : int ecf_flags;
10035 : :
10036 : 285375 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_PADDING))
10037 : : {
10038 : 58049 : ftype = build_function_type_list (void_type_node,
10039 : : ptr_type_node,
10040 : : ptr_type_node,
10041 : : NULL_TREE);
10042 : 58049 : local_define_builtin ("__builtin_clear_padding", ftype,
10043 : : BUILT_IN_CLEAR_PADDING,
10044 : : "__builtin_clear_padding",
10045 : : ECF_LEAF | ECF_NOTHROW);
10046 : : }
10047 : :
10048 : 285375 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)
10049 : 231972 : || !builtin_decl_explicit_p (BUILT_IN_TRAP)
10050 : 231972 : || !builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP)
10051 : 512701 : || !builtin_decl_explicit_p (BUILT_IN_ABORT))
10052 : : {
10053 : 58049 : ftype = build_function_type (void_type_node, void_list_node);
10054 : 58049 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE))
10055 : 53403 : local_define_builtin ("__builtin_unreachable", ftype,
10056 : : BUILT_IN_UNREACHABLE,
10057 : : "__builtin_unreachable",
10058 : : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10059 : : | ECF_CONST | ECF_COLD);
10060 : 58049 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP))
10061 : 58049 : local_define_builtin ("__builtin_unreachable trap", ftype,
10062 : : BUILT_IN_UNREACHABLE_TRAP,
10063 : : "__builtin_unreachable trap",
10064 : : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10065 : : | ECF_CONST | ECF_COLD);
10066 : 58049 : if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
10067 : 58049 : local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
10068 : : "abort",
10069 : : ECF_LEAF | ECF_NORETURN | ECF_CONST | ECF_COLD);
10070 : 58049 : if (!builtin_decl_explicit_p (BUILT_IN_TRAP))
10071 : 22600 : local_define_builtin ("__builtin_trap", ftype, BUILT_IN_TRAP,
10072 : : "__builtin_trap",
10073 : : ECF_NORETURN | ECF_NOTHROW | ECF_LEAF | ECF_COLD);
10074 : : }
10075 : :
10076 : 285375 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)
10077 : 285375 : || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10078 : : {
10079 : 58049 : ftype = build_function_type_list (ptr_type_node,
10080 : : ptr_type_node, const_ptr_type_node,
10081 : : size_type_node, NULL_TREE);
10082 : :
10083 : 58049 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY))
10084 : 58049 : local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
10085 : : "memcpy", ECF_NOTHROW | ECF_LEAF);
10086 : 58049 : if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10087 : 53403 : local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
10088 : : "memmove", ECF_NOTHROW | ECF_LEAF);
10089 : : }
10090 : :
10091 : 285375 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP))
10092 : : {
10093 : 53403 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10094 : : const_ptr_type_node, size_type_node,
10095 : : NULL_TREE);
10096 : 53403 : local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
10097 : : "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10098 : : }
10099 : :
10100 : 285375 : if (!builtin_decl_explicit_p (BUILT_IN_MEMSET))
10101 : : {
10102 : 53403 : ftype = build_function_type_list (ptr_type_node,
10103 : : ptr_type_node, integer_type_node,
10104 : : size_type_node, NULL_TREE);
10105 : 53403 : local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
10106 : : "memset", ECF_NOTHROW | ECF_LEAF);
10107 : : }
10108 : :
10109 : : /* If we're checking the stack, `alloca' can throw. */
10110 : 285314 : const int alloca_flags
10111 : 285375 : = ECF_MALLOC | ECF_LEAF | (flag_stack_check ? 0 : ECF_NOTHROW);
10112 : :
10113 : 285375 : if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA))
10114 : : {
10115 : 58049 : ftype = build_function_type_list (ptr_type_node,
10116 : : size_type_node, NULL_TREE);
10117 : 58049 : local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
10118 : : "alloca", alloca_flags);
10119 : : }
10120 : :
10121 : 285375 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10122 : : size_type_node, NULL_TREE);
10123 : 285375 : local_define_builtin ("__builtin_alloca_with_align", ftype,
10124 : : BUILT_IN_ALLOCA_WITH_ALIGN,
10125 : : "__builtin_alloca_with_align",
10126 : : alloca_flags);
10127 : :
10128 : 285375 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10129 : : size_type_node, size_type_node, NULL_TREE);
10130 : 285375 : local_define_builtin ("__builtin_alloca_with_align_and_max", ftype,
10131 : : BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX,
10132 : : "__builtin_alloca_with_align_and_max",
10133 : : alloca_flags);
10134 : :
10135 : 285375 : ftype = build_function_type_list (void_type_node,
10136 : : ptr_type_node, ptr_type_node,
10137 : : ptr_type_node, NULL_TREE);
10138 : 285375 : local_define_builtin ("__builtin_init_trampoline", ftype,
10139 : : BUILT_IN_INIT_TRAMPOLINE,
10140 : : "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
10141 : 285375 : local_define_builtin ("__builtin_init_heap_trampoline", ftype,
10142 : : BUILT_IN_INIT_HEAP_TRAMPOLINE,
10143 : : "__builtin_init_heap_trampoline",
10144 : : ECF_NOTHROW | ECF_LEAF);
10145 : 285375 : local_define_builtin ("__builtin_init_descriptor", ftype,
10146 : : BUILT_IN_INIT_DESCRIPTOR,
10147 : : "__builtin_init_descriptor", ECF_NOTHROW | ECF_LEAF);
10148 : :
10149 : 285375 : ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
10150 : 285375 : local_define_builtin ("__builtin_adjust_trampoline", ftype,
10151 : : BUILT_IN_ADJUST_TRAMPOLINE,
10152 : : "__builtin_adjust_trampoline",
10153 : : ECF_CONST | ECF_NOTHROW);
10154 : 285375 : local_define_builtin ("__builtin_adjust_descriptor", ftype,
10155 : : BUILT_IN_ADJUST_DESCRIPTOR,
10156 : : "__builtin_adjust_descriptor",
10157 : : ECF_CONST | ECF_NOTHROW);
10158 : :
10159 : 285375 : ftype = build_function_type_list (void_type_node,
10160 : : ptr_type_node, ptr_type_node, NULL_TREE);
10161 : 285375 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_CACHE))
10162 : 58049 : local_define_builtin ("__builtin___clear_cache", ftype,
10163 : : BUILT_IN_CLEAR_CACHE,
10164 : : "__clear_cache",
10165 : : ECF_NOTHROW);
10166 : :
10167 : 285375 : local_define_builtin ("__builtin_nonlocal_goto", ftype,
10168 : : BUILT_IN_NONLOCAL_GOTO,
10169 : : "__builtin_nonlocal_goto",
10170 : : ECF_NORETURN | ECF_NOTHROW);
10171 : :
10172 : 285375 : tree ptr_ptr_type_node = build_pointer_type (ptr_type_node);
10173 : :
10174 : 285375 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED))
10175 : : {
10176 : 58049 : ftype = build_function_type_list (void_type_node,
10177 : : ptr_type_node, // void *chain
10178 : : ptr_type_node, // void *func
10179 : : ptr_ptr_type_node, // void **dst
10180 : : NULL_TREE);
10181 : 58049 : local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype,
10182 : : BUILT_IN_GCC_NESTED_PTR_CREATED,
10183 : : "__gcc_nested_func_ptr_created", ECF_NOTHROW);
10184 : : }
10185 : :
10186 : 285375 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED))
10187 : : {
10188 : 58049 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10189 : 58049 : local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype,
10190 : : BUILT_IN_GCC_NESTED_PTR_DELETED,
10191 : : "__gcc_nested_func_ptr_deleted", ECF_NOTHROW);
10192 : : }
10193 : :
10194 : 285375 : ftype = build_function_type_list (void_type_node,
10195 : : ptr_type_node, ptr_type_node, NULL_TREE);
10196 : 285375 : local_define_builtin ("__builtin_setjmp_setup", ftype,
10197 : : BUILT_IN_SETJMP_SETUP,
10198 : : "__builtin_setjmp_setup", ECF_NOTHROW);
10199 : :
10200 : 285375 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10201 : 285375 : local_define_builtin ("__builtin_setjmp_receiver", ftype,
10202 : : BUILT_IN_SETJMP_RECEIVER,
10203 : : "__builtin_setjmp_receiver", ECF_NOTHROW | ECF_LEAF);
10204 : :
10205 : 285375 : ftype = build_function_type_list (ptr_type_node, NULL_TREE);
10206 : 285375 : local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
10207 : : "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
10208 : :
10209 : 285375 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10210 : 285375 : local_define_builtin ("__builtin_stack_restore", ftype,
10211 : : BUILT_IN_STACK_RESTORE,
10212 : : "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
10213 : :
10214 : 285375 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10215 : : const_ptr_type_node, size_type_node,
10216 : : NULL_TREE);
10217 : 285375 : local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ,
10218 : : "__builtin_memcmp_eq",
10219 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10220 : :
10221 : 285375 : local_define_builtin ("__builtin_strncmp_eq", ftype, BUILT_IN_STRNCMP_EQ,
10222 : : "__builtin_strncmp_eq",
10223 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10224 : :
10225 : 285375 : local_define_builtin ("__builtin_strcmp_eq", ftype, BUILT_IN_STRCMP_EQ,
10226 : : "__builtin_strcmp_eq",
10227 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10228 : :
10229 : : /* If there's a possibility that we might use the ARM EABI, build the
10230 : : alternate __cxa_end_cleanup node used to resume from C++. */
10231 : 285375 : if (targetm.arm_eabi_unwinder)
10232 : : {
10233 : 0 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10234 : 0 : local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
10235 : : BUILT_IN_CXA_END_CLEANUP,
10236 : : "__cxa_end_cleanup",
10237 : : ECF_NORETURN | ECF_XTHROW | ECF_LEAF);
10238 : : }
10239 : :
10240 : 285375 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10241 : 570750 : local_define_builtin ("__builtin_unwind_resume", ftype,
10242 : : BUILT_IN_UNWIND_RESUME,
10243 : 285375 : ((targetm_common.except_unwind_info (&global_options)
10244 : : == UI_SJLJ)
10245 : : ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10246 : : ECF_NORETURN | ECF_XTHROW);
10247 : :
10248 : 285375 : if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE)
10249 : : {
10250 : 53403 : ftype = build_function_type_list (ptr_type_node, integer_type_node,
10251 : : NULL_TREE);
10252 : 53403 : local_define_builtin ("__builtin_return_address", ftype,
10253 : : BUILT_IN_RETURN_ADDRESS,
10254 : : "__builtin_return_address",
10255 : : ECF_NOTHROW);
10256 : : }
10257 : :
10258 : 285375 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)
10259 : 285375 : || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10260 : : {
10261 : 58049 : ftype = build_function_type_list (void_type_node, ptr_type_node,
10262 : : ptr_type_node, NULL_TREE);
10263 : 58049 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER))
10264 : 58049 : local_define_builtin ("__cyg_profile_func_enter", ftype,
10265 : : BUILT_IN_PROFILE_FUNC_ENTER,
10266 : : "__cyg_profile_func_enter", 0);
10267 : 58049 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10268 : 58049 : local_define_builtin ("__cyg_profile_func_exit", ftype,
10269 : : BUILT_IN_PROFILE_FUNC_EXIT,
10270 : : "__cyg_profile_func_exit", 0);
10271 : : }
10272 : :
10273 : : /* The exception object and filter values from the runtime. The argument
10274 : : must be zero before exception lowering, i.e. from the front end. After
10275 : : exception lowering, it will be the region number for the exception
10276 : : landing pad. These functions are PURE instead of CONST to prevent
10277 : : them from being hoisted past the exception edge that will initialize
10278 : : its value in the landing pad. */
10279 : 285375 : ftype = build_function_type_list (ptr_type_node,
10280 : : integer_type_node, NULL_TREE);
10281 : 285375 : ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF;
10282 : : /* Only use TM_PURE if we have TM language support. */
10283 : 285375 : if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
10284 : 482 : ecf_flags |= ECF_TM_PURE;
10285 : 285375 : local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
10286 : : "__builtin_eh_pointer", ecf_flags);
10287 : :
10288 : 285375 : tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
10289 : 285375 : ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
10290 : 285375 : local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
10291 : : "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10292 : :
10293 : 285375 : ftype = build_function_type_list (void_type_node,
10294 : : integer_type_node, integer_type_node,
10295 : : NULL_TREE);
10296 : 285375 : local_define_builtin ("__builtin_eh_copy_values", ftype,
10297 : : BUILT_IN_EH_COPY_VALUES,
10298 : : "__builtin_eh_copy_values", ECF_NOTHROW);
10299 : :
10300 : : /* Complex multiplication and division. These are handled as builtins
10301 : : rather than optabs because emit_library_call_value doesn't support
10302 : : complex. Further, we can do slightly better with folding these
10303 : : beasties if the real and complex parts of the arguments are separate. */
10304 : 285375 : {
10305 : 285375 : int mode;
10306 : :
10307 : 1997625 : for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
10308 : : {
10309 : 1712250 : char mode_name_buf[4], *q;
10310 : 1712250 : const char *p;
10311 : 1712250 : enum built_in_function mcode, dcode;
10312 : 1712250 : tree type, inner_type;
10313 : 1712250 : const char *prefix = "__";
10314 : :
10315 : 1712250 : if (targetm.libfunc_gnu_prefix)
10316 : 0 : prefix = "__gnu_";
10317 : :
10318 : 1712250 : type = lang_hooks.types.type_for_mode ((machine_mode) mode, 0);
10319 : 1712250 : if (type == NULL)
10320 : 126406 : continue;
10321 : 1585844 : inner_type = TREE_TYPE (type);
10322 : :
10323 : 1585844 : ftype = build_function_type_list (type, inner_type, inner_type,
10324 : : inner_type, inner_type, NULL_TREE);
10325 : :
10326 : 1585844 : mcode = ((enum built_in_function)
10327 : 1585844 : (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10328 : 1585844 : dcode = ((enum built_in_function)
10329 : 1585844 : (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10330 : :
10331 : 4757532 : for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
10332 : 3171688 : *q = TOLOWER (*p);
10333 : 1585844 : *q = '\0';
10334 : :
10335 : : /* For -ftrapping-math these should throw from a former
10336 : : -fnon-call-exception stmt. */
10337 : 1585844 : built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
10338 : : NULL);
10339 : 1585844 : local_define_builtin (built_in_names[mcode], ftype, mcode,
10340 : : built_in_names[mcode],
10341 : : ECF_CONST | ECF_LEAF);
10342 : :
10343 : 1585844 : built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
10344 : : NULL);
10345 : 1585844 : local_define_builtin (built_in_names[dcode], ftype, dcode,
10346 : : built_in_names[dcode],
10347 : : ECF_CONST | ECF_LEAF);
10348 : : }
10349 : : }
10350 : :
10351 : 285375 : init_internal_fns ();
10352 : 285375 : }
10353 : :
10354 : : /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10355 : : better way.
10356 : :
10357 : : If we requested a pointer to a vector, build up the pointers that
10358 : : we stripped off while looking for the inner type. Similarly for
10359 : : return values from functions.
10360 : :
10361 : : The argument TYPE is the top of the chain, and BOTTOM is the
10362 : : new type which we will point to. */
10363 : :
10364 : : tree
10365 : 0 : reconstruct_complex_type (tree type, tree bottom)
10366 : : {
10367 : 0 : tree inner, outer;
10368 : :
10369 : 0 : if (TREE_CODE (type) == POINTER_TYPE)
10370 : : {
10371 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10372 : 0 : outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
10373 : 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10374 : : }
10375 : : else if (TREE_CODE (type) == REFERENCE_TYPE)
10376 : : {
10377 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10378 : 0 : outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
10379 : 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10380 : : }
10381 : : else if (TREE_CODE (type) == ARRAY_TYPE)
10382 : : {
10383 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10384 : 0 : outer = build_array_type (inner, TYPE_DOMAIN (type));
10385 : : }
10386 : : else if (TREE_CODE (type) == FUNCTION_TYPE)
10387 : : {
10388 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10389 : 0 : outer = build_function_type (inner, TYPE_ARG_TYPES (type),
10390 : 0 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
10391 : : }
10392 : : else if (TREE_CODE (type) == METHOD_TYPE)
10393 : : {
10394 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10395 : : /* The build_method_type_directly() routine prepends 'this' to argument list,
10396 : : so we must compensate by getting rid of it. */
10397 : 0 : outer
10398 : : = build_method_type_directly
10399 : 0 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
10400 : : inner,
10401 : 0 : TREE_CHAIN (TYPE_ARG_TYPES (type)));
10402 : : }
10403 : : else if (TREE_CODE (type) == OFFSET_TYPE)
10404 : : {
10405 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10406 : 0 : outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
10407 : : }
10408 : : else
10409 : : return bottom;
10410 : :
10411 : 0 : return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
10412 : 0 : TYPE_QUALS (type));
10413 : : }
10414 : :
10415 : : /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10416 : : the inner type. */
10417 : : tree
10418 : 33806950 : build_vector_type_for_mode (tree innertype, machine_mode mode)
10419 : : {
10420 : 33806950 : poly_int64 nunits;
10421 : 33806950 : unsigned int bitsize;
10422 : :
10423 : 33806950 : switch (GET_MODE_CLASS (mode))
10424 : : {
10425 : 33805692 : case MODE_VECTOR_BOOL:
10426 : 33805692 : case MODE_VECTOR_INT:
10427 : 33805692 : case MODE_VECTOR_FLOAT:
10428 : 33805692 : case MODE_VECTOR_FRACT:
10429 : 33805692 : case MODE_VECTOR_UFRACT:
10430 : 33805692 : case MODE_VECTOR_ACCUM:
10431 : 33805692 : case MODE_VECTOR_UACCUM:
10432 : 67611384 : nunits = GET_MODE_NUNITS (mode);
10433 : 33805692 : break;
10434 : :
10435 : 1258 : case MODE_INT:
10436 : : /* Check that there are no leftover bits. */
10437 : 1258 : bitsize = GET_MODE_BITSIZE (as_a <scalar_int_mode> (mode));
10438 : 1258 : gcc_assert (bitsize % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
10439 : 1258 : nunits = bitsize / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
10440 : 1258 : break;
10441 : :
10442 : 0 : default:
10443 : 0 : gcc_unreachable ();
10444 : : }
10445 : :
10446 : 33806950 : return make_vector_type (innertype, nunits, mode);
10447 : : }
10448 : :
10449 : : /* Similarly, but takes the inner type and number of units, which must be
10450 : : a power of two. */
10451 : :
10452 : : tree
10453 : 2772089 : build_vector_type (tree innertype, poly_int64 nunits)
10454 : : {
10455 : 2772089 : return make_vector_type (innertype, nunits, VOIDmode);
10456 : : }
10457 : :
10458 : : /* Build a truth vector with NUNITS units, giving it mode MASK_MODE. */
10459 : :
10460 : : tree
10461 : 1952528 : build_truth_vector_type_for_mode (poly_uint64 nunits, machine_mode mask_mode)
10462 : : {
10463 : 1952528 : gcc_assert (mask_mode != BLKmode);
10464 : :
10465 : 1952528 : unsigned HOST_WIDE_INT esize;
10466 : 1952528 : if (VECTOR_MODE_P (mask_mode))
10467 : : {
10468 : 1889642 : poly_uint64 vsize = GET_MODE_PRECISION (mask_mode);
10469 : 1889642 : esize = vector_element_size (vsize, nunits);
10470 : 1889642 : }
10471 : : else
10472 : : esize = 1;
10473 : :
10474 : 1952528 : tree bool_type = build_nonstandard_boolean_type (esize);
10475 : :
10476 : 1952528 : return make_vector_type (bool_type, nunits, mask_mode);
10477 : : }
10478 : :
10479 : : /* Build a vector type that holds one boolean result for each element of
10480 : : vector type VECTYPE. The public interface for this operation is
10481 : : truth_type_for. */
10482 : :
10483 : : static tree
10484 : 1947917 : build_truth_vector_type_for (tree vectype)
10485 : : {
10486 : 1947917 : machine_mode vector_mode = TYPE_MODE (vectype);
10487 : 1947917 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
10488 : :
10489 : 1947917 : machine_mode mask_mode;
10490 : 68797 : if (VECTOR_MODE_P (vector_mode)
10491 : 2016146 : && targetm.vectorize.get_mask_mode (vector_mode).exists (&mask_mode))
10492 : 1947349 : return build_truth_vector_type_for_mode (nunits, mask_mode);
10493 : :
10494 : 568 : poly_uint64 vsize = tree_to_poly_uint64 (TYPE_SIZE (vectype));
10495 : 568 : unsigned HOST_WIDE_INT esize = vector_element_size (vsize, nunits);
10496 : 568 : tree bool_type = build_nonstandard_boolean_type (esize);
10497 : :
10498 : 568 : return make_vector_type (bool_type, nunits, VOIDmode);
10499 : : }
10500 : :
10501 : : /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
10502 : : set. */
10503 : :
10504 : : tree
10505 : 105330 : build_opaque_vector_type (tree innertype, poly_int64 nunits)
10506 : : {
10507 : 105330 : tree t = make_vector_type (innertype, nunits, VOIDmode);
10508 : 105330 : tree cand;
10509 : : /* We always build the non-opaque variant before the opaque one,
10510 : : so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10511 : 105330 : cand = TYPE_NEXT_VARIANT (t);
10512 : 105330 : if (cand
10513 : 94198 : && TYPE_VECTOR_OPAQUE (cand)
10514 : 166660 : && check_qualified_type (cand, t, TYPE_QUALS (t)))
10515 : : return cand;
10516 : : /* Othewise build a variant type and make sure to queue it after
10517 : : the non-opaque type. */
10518 : 44001 : cand = build_distinct_type_copy (t);
10519 : 44001 : TYPE_VECTOR_OPAQUE (cand) = true;
10520 : 44001 : TYPE_CANONICAL (cand) = TYPE_CANONICAL (t);
10521 : 44001 : TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t);
10522 : 44001 : TYPE_NEXT_VARIANT (t) = cand;
10523 : 44001 : TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
10524 : : /* Type variants have no alias set defined. */
10525 : 44001 : TYPE_ALIAS_SET (cand) = -1;
10526 : 44001 : return cand;
10527 : : }
10528 : :
10529 : : /* Return the value of element I of VECTOR_CST T as a wide_int. */
10530 : :
10531 : : static poly_wide_int
10532 : 492233 : vector_cst_int_elt (const_tree t, unsigned int i)
10533 : : {
10534 : : /* First handle elements that are directly encoded. */
10535 : 492233 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10536 : 492233 : if (i < encoded_nelts)
10537 : 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, i));
10538 : :
10539 : : /* Identify the pattern that contains element I and work out the index of
10540 : : the last encoded element for that pattern. */
10541 : 492233 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10542 : 492233 : unsigned int pattern = i % npatterns;
10543 : 492233 : unsigned int count = i / npatterns;
10544 : 492233 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10545 : :
10546 : : /* If there are no steps, the final encoded value is the right one. */
10547 : 492233 : if (!VECTOR_CST_STEPPED_P (t))
10548 : 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, final_i));
10549 : :
10550 : : /* Otherwise work out the value from the last two encoded elements. */
10551 : 492233 : tree v1 = VECTOR_CST_ENCODED_ELT (t, final_i - npatterns);
10552 : 492233 : tree v2 = VECTOR_CST_ENCODED_ELT (t, final_i);
10553 : 492233 : poly_wide_int diff = wi::to_poly_wide (v2) - wi::to_poly_wide (v1);
10554 : 492233 : return wi::to_poly_wide (v2) + (count - 2) * diff;
10555 : 492233 : }
10556 : :
10557 : : /* Return the value of element I of VECTOR_CST T. */
10558 : :
10559 : : tree
10560 : 6003551 : vector_cst_elt (const_tree t, unsigned int i)
10561 : : {
10562 : : /* First handle elements that are directly encoded. */
10563 : 6003551 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10564 : 6003551 : if (i < encoded_nelts)
10565 : 4140693 : return VECTOR_CST_ENCODED_ELT (t, i);
10566 : :
10567 : : /* If there are no steps, the final encoded value is the right one. */
10568 : 1862858 : if (!VECTOR_CST_STEPPED_P (t))
10569 : : {
10570 : : /* Identify the pattern that contains element I and work out the index of
10571 : : the last encoded element for that pattern. */
10572 : 1370625 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10573 : 1370625 : unsigned int pattern = i % npatterns;
10574 : 1370625 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10575 : 1370625 : return VECTOR_CST_ENCODED_ELT (t, final_i);
10576 : : }
10577 : :
10578 : : /* Otherwise work out the value from the last two encoded elements. */
10579 : 492233 : return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t)),
10580 : 984466 : vector_cst_int_elt (t, i));
10581 : : }
10582 : :
10583 : : /* Given an initializer INIT, return TRUE if INIT is zero or some
10584 : : aggregate of zeros. Otherwise return FALSE. If NONZERO is not
10585 : : null, set *NONZERO if and only if INIT is known not to be all
10586 : : zeros. The combination of return value of false and *NONZERO
10587 : : false implies that INIT may but need not be all zeros. Other
10588 : : combinations indicate definitive answers. */
10589 : :
10590 : : bool
10591 : 45022536 : initializer_zerop (const_tree init, bool *nonzero /* = NULL */)
10592 : : {
10593 : 45022536 : bool dummy;
10594 : 45022536 : if (!nonzero)
10595 : 42271015 : nonzero = &dummy;
10596 : :
10597 : : /* Conservatively clear NONZERO and set it only if INIT is definitely
10598 : : not all zero. */
10599 : 45022536 : *nonzero = false;
10600 : :
10601 : 45022536 : STRIP_NOPS (init);
10602 : :
10603 : 45022536 : unsigned HOST_WIDE_INT off = 0;
10604 : :
10605 : 45022536 : switch (TREE_CODE (init))
10606 : : {
10607 : 16800610 : case INTEGER_CST:
10608 : 16800610 : if (integer_zerop (init))
10609 : : return true;
10610 : :
10611 : 10397155 : *nonzero = true;
10612 : 10397155 : return false;
10613 : :
10614 : 529282 : case REAL_CST:
10615 : : /* ??? Note that this is not correct for C4X float formats. There,
10616 : : a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10617 : : negative exponent. */
10618 : 529282 : if (real_zerop (init)
10619 : 617040 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)))
10620 : : return true;
10621 : :
10622 : 444425 : *nonzero = true;
10623 : 444425 : return false;
10624 : :
10625 : 0 : case FIXED_CST:
10626 : 0 : if (fixed_zerop (init))
10627 : : return true;
10628 : :
10629 : 0 : *nonzero = true;
10630 : 0 : return false;
10631 : :
10632 : 17675 : case COMPLEX_CST:
10633 : 17675 : if (integer_zerop (init)
10634 : 17675 : || (real_zerop (init)
10635 : 2958 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
10636 : 2908 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))))
10637 : 3131 : return true;
10638 : :
10639 : 14544 : *nonzero = true;
10640 : 14544 : return false;
10641 : :
10642 : 1117504 : case VECTOR_CST:
10643 : 1117504 : if (VECTOR_CST_NPATTERNS (init) == 1
10644 : 1025304 : && VECTOR_CST_DUPLICATE_P (init)
10645 : 1765392 : && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)))
10646 : : return true;
10647 : :
10648 : 770939 : *nonzero = true;
10649 : 770939 : return false;
10650 : :
10651 : : case RAW_DATA_CST:
10652 : 1581 : for (unsigned int i = 0; i < (unsigned int) RAW_DATA_LENGTH (init); ++i)
10653 : 1581 : if (RAW_DATA_POINTER (init)[i])
10654 : : {
10655 : 1529 : *nonzero = true;
10656 : 1529 : return false;
10657 : : }
10658 : : return true;
10659 : :
10660 : 6137109 : case CONSTRUCTOR:
10661 : 6137109 : {
10662 : 6137109 : if (TREE_CLOBBER_P (init))
10663 : : return false;
10664 : :
10665 : : unsigned HOST_WIDE_INT idx;
10666 : : tree elt;
10667 : :
10668 : 3611899 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
10669 : 2751521 : if (!initializer_zerop (elt, nonzero))
10670 : : return false;
10671 : :
10672 : : return true;
10673 : : }
10674 : :
10675 : 349727 : case MEM_REF:
10676 : 349727 : {
10677 : 349727 : tree arg = TREE_OPERAND (init, 0);
10678 : 349727 : if (TREE_CODE (arg) != ADDR_EXPR)
10679 : : return false;
10680 : 81426 : tree offset = TREE_OPERAND (init, 1);
10681 : 81426 : if (TREE_CODE (offset) != INTEGER_CST
10682 : 81426 : || !tree_fits_uhwi_p (offset))
10683 : : return false;
10684 : 81426 : off = tree_to_uhwi (offset);
10685 : 81426 : if (INT_MAX < off)
10686 : : return false;
10687 : 81422 : arg = TREE_OPERAND (arg, 0);
10688 : 81422 : if (TREE_CODE (arg) != STRING_CST)
10689 : : return false;
10690 : : init = arg;
10691 : : }
10692 : : /* Fall through. */
10693 : :
10694 : : case STRING_CST:
10695 : : {
10696 : : gcc_assert (off <= INT_MAX);
10697 : :
10698 : 161060 : int i = off;
10699 : 161060 : int n = TREE_STRING_LENGTH (init);
10700 : 161060 : if (n <= i)
10701 : : return false;
10702 : :
10703 : : /* We need to loop through all elements to handle cases like
10704 : : "\0" and "\0foobar". */
10705 : 173281 : for (i = 0; i < n; ++i)
10706 : 167585 : if (TREE_STRING_POINTER (init)[i] != '\0')
10707 : : {
10708 : 155331 : *nonzero = true;
10709 : 155331 : return false;
10710 : : }
10711 : :
10712 : : return true;
10713 : : }
10714 : :
10715 : : default:
10716 : : return false;
10717 : : }
10718 : : }
10719 : :
10720 : : /* Return true if EXPR is an initializer expression in which every element
10721 : : is a constant that is numerically equal to 0 or 1. The elements do not
10722 : : need to be equal to each other. */
10723 : :
10724 : : bool
10725 : 126257 : initializer_each_zero_or_onep (const_tree expr)
10726 : : {
10727 : 126257 : STRIP_ANY_LOCATION_WRAPPER (expr);
10728 : :
10729 : 126257 : switch (TREE_CODE (expr))
10730 : : {
10731 : 47195 : case INTEGER_CST:
10732 : 47195 : return integer_zerop (expr) || integer_onep (expr);
10733 : :
10734 : 20735 : case REAL_CST:
10735 : 20735 : return real_zerop (expr) || real_onep (expr);
10736 : :
10737 : 58327 : case VECTOR_CST:
10738 : 58327 : {
10739 : 58327 : unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
10740 : 58327 : if (VECTOR_CST_STEPPED_P (expr)
10741 : 58327 : && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
10742 : : return false;
10743 : :
10744 : 69171 : for (unsigned int i = 0; i < nelts; ++i)
10745 : : {
10746 : 67930 : tree elt = vector_cst_elt (expr, i);
10747 : 67930 : if (!initializer_each_zero_or_onep (elt))
10748 : : return false;
10749 : : }
10750 : :
10751 : : return true;
10752 : : }
10753 : :
10754 : : default:
10755 : : return false;
10756 : : }
10757 : : }
10758 : :
10759 : : /* Check if vector VEC consists of all the equal elements and
10760 : : that the number of elements corresponds to the type of VEC.
10761 : : The function returns first element of the vector
10762 : : or NULL_TREE if the vector is not uniform. */
10763 : : tree
10764 : 2671213 : uniform_vector_p (const_tree vec)
10765 : : {
10766 : 2671213 : tree first, t;
10767 : 2671213 : unsigned HOST_WIDE_INT i, nelts;
10768 : :
10769 : 2671213 : if (vec == NULL_TREE)
10770 : : return NULL_TREE;
10771 : :
10772 : 2671213 : gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
10773 : :
10774 : 2671213 : if (TREE_CODE (vec) == VEC_DUPLICATE_EXPR)
10775 : 0 : return TREE_OPERAND (vec, 0);
10776 : :
10777 : 2671213 : else if (TREE_CODE (vec) == VECTOR_CST)
10778 : : {
10779 : 211811 : if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
10780 : 168451 : return VECTOR_CST_ENCODED_ELT (vec, 0);
10781 : : return NULL_TREE;
10782 : : }
10783 : :
10784 : 2459402 : else if (TREE_CODE (vec) == CONSTRUCTOR
10785 : 2459402 : && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)).is_constant (&nelts))
10786 : : {
10787 : 161380 : first = error_mark_node;
10788 : :
10789 : 529742 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
10790 : : {
10791 : 471618 : if (i == 0)
10792 : : {
10793 : 161380 : first = t;
10794 : 161380 : continue;
10795 : : }
10796 : 310238 : if (!operand_equal_p (first, t, 0))
10797 : : return NULL_TREE;
10798 : : }
10799 : 58124 : if (i != nelts)
10800 : : return NULL_TREE;
10801 : :
10802 : 57932 : if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
10803 : : return uniform_vector_p (first);
10804 : : return first;
10805 : : }
10806 : :
10807 : : return NULL_TREE;
10808 : : }
10809 : :
10810 : : /* If the argument is INTEGER_CST, return it. If the argument is vector
10811 : : with all elements the same INTEGER_CST, return that INTEGER_CST. Otherwise
10812 : : return NULL_TREE.
10813 : : Look through location wrappers. */
10814 : :
10815 : : tree
10816 : 849656704 : uniform_integer_cst_p (tree t)
10817 : : {
10818 : 849656704 : STRIP_ANY_LOCATION_WRAPPER (t);
10819 : :
10820 : 849656704 : if (TREE_CODE (t) == INTEGER_CST)
10821 : : return t;
10822 : :
10823 : 345916769 : if (VECTOR_TYPE_P (TREE_TYPE (t)))
10824 : : {
10825 : 898915 : t = uniform_vector_p (t);
10826 : 898915 : if (t && TREE_CODE (t) == INTEGER_CST)
10827 : : return t;
10828 : : }
10829 : :
10830 : : return NULL_TREE;
10831 : : }
10832 : :
10833 : : /* Checks to see if T is a constant or a constant vector and if each element E
10834 : : adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE. */
10835 : :
10836 : : tree
10837 : 3115430 : bitmask_inv_cst_vector_p (tree t)
10838 : : {
10839 : :
10840 : 3115430 : tree_code code = TREE_CODE (t);
10841 : 3115430 : tree type = TREE_TYPE (t);
10842 : :
10843 : 3115430 : if (!INTEGRAL_TYPE_P (type)
10844 : 3115430 : && !VECTOR_INTEGER_TYPE_P (type))
10845 : : return NULL_TREE;
10846 : :
10847 : 3115430 : unsigned HOST_WIDE_INT nelts = 1;
10848 : 3115430 : tree cst;
10849 : 3115430 : unsigned int idx = 0;
10850 : 3115430 : bool uniform = uniform_integer_cst_p (t);
10851 : 3115430 : tree newtype = unsigned_type_for (type);
10852 : 3115430 : tree_vector_builder builder;
10853 : 3115430 : if (code == INTEGER_CST)
10854 : : cst = t;
10855 : : else
10856 : : {
10857 : 6106 : if (!VECTOR_CST_NELTS (t).is_constant (&nelts))
10858 : : return NULL_TREE;
10859 : :
10860 : 6106 : cst = vector_cst_elt (t, 0);
10861 : 6106 : builder.new_vector (newtype, nelts, 1);
10862 : : }
10863 : :
10864 : 3115430 : tree ty = unsigned_type_for (TREE_TYPE (cst));
10865 : :
10866 : 3115442 : do
10867 : : {
10868 : 3115442 : if (idx > 0)
10869 : 12 : cst = vector_cst_elt (t, idx);
10870 : 3115442 : wide_int icst = wi::to_wide (cst);
10871 : 3115442 : wide_int inv = wi::bit_not (icst);
10872 : 3115442 : icst = wi::add (1, inv);
10873 : 3115442 : if (wi::popcount (icst) != 1)
10874 : : return NULL_TREE;
10875 : :
10876 : 7731 : tree newcst = wide_int_to_tree (ty, inv);
10877 : :
10878 : 7731 : if (uniform)
10879 : 7715 : return build_uniform_cst (newtype, newcst);
10880 : :
10881 : 16 : builder.quick_push (newcst);
10882 : 3115442 : }
10883 : 16 : while (++idx < nelts);
10884 : :
10885 : 4 : return builder.build ();
10886 : 3115430 : }
10887 : :
10888 : : /* If VECTOR_CST T has a single nonzero element, return the index of that
10889 : : element, otherwise return -1. */
10890 : :
10891 : : int
10892 : 177 : single_nonzero_element (const_tree t)
10893 : : {
10894 : 177 : unsigned HOST_WIDE_INT nelts;
10895 : 177 : unsigned int repeat_nelts;
10896 : 177 : if (VECTOR_CST_NELTS (t).is_constant (&nelts))
10897 : 177 : repeat_nelts = nelts;
10898 : : else if (VECTOR_CST_NELTS_PER_PATTERN (t) == 2)
10899 : : {
10900 : : nelts = vector_cst_encoded_nelts (t);
10901 : : repeat_nelts = VECTOR_CST_NPATTERNS (t);
10902 : : }
10903 : : else
10904 : : return -1;
10905 : :
10906 : 177 : int res = -1;
10907 : 561 : for (unsigned int i = 0; i < nelts; ++i)
10908 : : {
10909 : 528 : tree elt = vector_cst_elt (t, i);
10910 : 528 : if (!integer_zerop (elt) && !real_zerop (elt))
10911 : : {
10912 : 321 : if (res >= 0 || i >= repeat_nelts)
10913 : : return -1;
10914 : 177 : res = i;
10915 : : }
10916 : : }
10917 : : return res;
10918 : : }
10919 : :
10920 : : /* Build an empty statement at location LOC. */
10921 : :
10922 : : tree
10923 : 12777902 : build_empty_stmt (location_t loc)
10924 : : {
10925 : 12777902 : tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
10926 : 12777902 : SET_EXPR_LOCATION (t, loc);
10927 : 12777902 : return t;
10928 : : }
10929 : :
10930 : :
10931 : : /* Build an OMP clause with code CODE. LOC is the location of the
10932 : : clause. */
10933 : :
10934 : : tree
10935 : 1708499 : build_omp_clause (location_t loc, enum omp_clause_code code)
10936 : : {
10937 : 1708499 : tree t;
10938 : 1708499 : int size, length;
10939 : :
10940 : 1708499 : length = omp_clause_num_ops[code];
10941 : 1708499 : size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
10942 : :
10943 : 1708499 : record_node_allocation_statistics (OMP_CLAUSE, size);
10944 : :
10945 : 1708499 : t = (tree) ggc_internal_alloc (size);
10946 : 1708499 : memset (t, 0, size);
10947 : 1708499 : TREE_SET_CODE (t, OMP_CLAUSE);
10948 : 1708499 : OMP_CLAUSE_SET_CODE (t, code);
10949 : 1708499 : OMP_CLAUSE_LOCATION (t) = loc;
10950 : :
10951 : 1708499 : return t;
10952 : : }
10953 : :
10954 : : /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10955 : : includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10956 : : Except for the CODE and operand count field, other storage for the
10957 : : object is initialized to zeros. */
10958 : :
10959 : : tree
10960 : 448164121 : build_vl_exp (enum tree_code code, int len MEM_STAT_DECL)
10961 : : {
10962 : 448164121 : tree t;
10963 : 448164121 : int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
10964 : :
10965 : 448164121 : gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
10966 : 448164121 : gcc_assert (len >= 1);
10967 : :
10968 : 448164121 : record_node_allocation_statistics (code, length);
10969 : :
10970 : 448164121 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
10971 : :
10972 : 448164121 : TREE_SET_CODE (t, code);
10973 : :
10974 : : /* Can't use TREE_OPERAND to store the length because if checking is
10975 : : enabled, it will try to check the length before we store it. :-P */
10976 : 448164121 : t->exp.operands[0] = build_int_cst (sizetype, len);
10977 : :
10978 : 448164121 : return t;
10979 : : }
10980 : :
10981 : : /* Helper function for build_call_* functions; build a CALL_EXPR with
10982 : : indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
10983 : : the argument slots. */
10984 : :
10985 : : static tree
10986 : 238385007 : build_call_1 (tree return_type, tree fn, int nargs)
10987 : : {
10988 : 238385007 : tree t;
10989 : :
10990 : 238385007 : t = build_vl_exp (CALL_EXPR, nargs + 3);
10991 : 238385007 : TREE_TYPE (t) = return_type;
10992 : 238385007 : CALL_EXPR_FN (t) = fn;
10993 : 238385007 : CALL_EXPR_STATIC_CHAIN (t) = NULL;
10994 : :
10995 : 238385007 : return t;
10996 : : }
10997 : :
10998 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10999 : : FN and a null static chain slot. NARGS is the number of call arguments
11000 : : which are specified as "..." arguments. */
11001 : :
11002 : : tree
11003 : 152 : build_call_nary (tree return_type, tree fn, int nargs, ...)
11004 : : {
11005 : 152 : tree ret;
11006 : 152 : va_list args;
11007 : 152 : va_start (args, nargs);
11008 : 152 : ret = build_call_valist (return_type, fn, nargs, args);
11009 : 152 : va_end (args);
11010 : 152 : return ret;
11011 : : }
11012 : :
11013 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11014 : : FN and a null static chain slot. NARGS is the number of call arguments
11015 : : which are specified as a va_list ARGS. */
11016 : :
11017 : : tree
11018 : 136525 : build_call_valist (tree return_type, tree fn, int nargs, va_list args)
11019 : : {
11020 : 136525 : tree t;
11021 : 136525 : int i;
11022 : :
11023 : 136525 : t = build_call_1 (return_type, fn, nargs);
11024 : 554351 : for (i = 0; i < nargs; i++)
11025 : 281301 : CALL_EXPR_ARG (t, i) = va_arg (args, tree);
11026 : 136525 : process_call_operands (t);
11027 : 136525 : return t;
11028 : : }
11029 : :
11030 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11031 : : FN and a null static chain slot. NARGS is the number of call arguments
11032 : : which are specified as a tree array ARGS. */
11033 : :
11034 : : tree
11035 : 195556800 : build_call_array_loc (location_t loc, tree return_type, tree fn,
11036 : : int nargs, const tree *args)
11037 : : {
11038 : 195556800 : tree t;
11039 : 195556800 : int i;
11040 : :
11041 : 195556800 : t = build_call_1 (return_type, fn, nargs);
11042 : 673766283 : for (i = 0; i < nargs; i++)
11043 : 282652683 : CALL_EXPR_ARG (t, i) = args[i];
11044 : 195556800 : process_call_operands (t);
11045 : 195556800 : SET_EXPR_LOCATION (t, loc);
11046 : 195556800 : return t;
11047 : : }
11048 : :
11049 : : /* Like build_call_array, but takes a vec. */
11050 : :
11051 : : tree
11052 : 42366000 : build_call_vec (tree return_type, tree fn, const vec<tree, va_gc> *args)
11053 : : {
11054 : 42366000 : tree ret, t;
11055 : 42366000 : unsigned int ix;
11056 : :
11057 : 42366000 : ret = build_call_1 (return_type, fn, vec_safe_length (args));
11058 : 111987325 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
11059 : 27255325 : CALL_EXPR_ARG (ret, ix) = t;
11060 : 42366000 : process_call_operands (ret);
11061 : 42366000 : return ret;
11062 : : }
11063 : :
11064 : : /* Conveniently construct a function call expression. FNDECL names the
11065 : : function to be called and N arguments are passed in the array
11066 : : ARGARRAY. */
11067 : :
11068 : : tree
11069 : 18066209 : build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray)
11070 : : {
11071 : 18066209 : tree fntype = TREE_TYPE (fndecl);
11072 : 18066209 : tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
11073 : :
11074 : 18066209 : return fold_build_call_array_loc (loc, TREE_TYPE (fntype), fn, n, argarray);
11075 : : }
11076 : :
11077 : : /* Conveniently construct a function call expression. FNDECL names the
11078 : : function to be called and the arguments are passed in the vector
11079 : : VEC. */
11080 : :
11081 : : tree
11082 : 20638 : build_call_expr_loc_vec (location_t loc, tree fndecl, vec<tree, va_gc> *vec)
11083 : : {
11084 : 20638 : return build_call_expr_loc_array (loc, fndecl, vec_safe_length (vec),
11085 : 20638 : vec_safe_address (vec));
11086 : : }
11087 : :
11088 : :
11089 : : /* Conveniently construct a function call expression. FNDECL names the
11090 : : function to be called, N is the number of arguments, and the "..."
11091 : : parameters are the argument expressions. */
11092 : :
11093 : : tree
11094 : 16436595 : build_call_expr_loc (location_t loc, tree fndecl, int n, ...)
11095 : : {
11096 : 16436595 : va_list ap;
11097 : 16436595 : tree *argarray = XALLOCAVEC (tree, n);
11098 : 16436595 : int i;
11099 : :
11100 : 16436595 : va_start (ap, n);
11101 : 18866684 : for (i = 0; i < n; i++)
11102 : 2430089 : argarray[i] = va_arg (ap, tree);
11103 : 16436595 : va_end (ap);
11104 : 16436595 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11105 : : }
11106 : :
11107 : : /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
11108 : : varargs macros aren't supported by all bootstrap compilers. */
11109 : :
11110 : : tree
11111 : 1604493 : build_call_expr (tree fndecl, int n, ...)
11112 : : {
11113 : 1604493 : va_list ap;
11114 : 1604493 : tree *argarray = XALLOCAVEC (tree, n);
11115 : 1604493 : int i;
11116 : :
11117 : 1604493 : va_start (ap, n);
11118 : 4715173 : for (i = 0; i < n; i++)
11119 : 3110680 : argarray[i] = va_arg (ap, tree);
11120 : 1604493 : va_end (ap);
11121 : 1604493 : return build_call_expr_loc_array (UNKNOWN_LOCATION, fndecl, n, argarray);
11122 : : }
11123 : :
11124 : : /* Build an internal call to IFN, with arguments ARGS[0:N-1] and with return
11125 : : type TYPE. This is just like CALL_EXPR, except its CALL_EXPR_FN is NULL.
11126 : : It will get gimplified later into an ordinary internal function. */
11127 : :
11128 : : tree
11129 : 325682 : build_call_expr_internal_loc_array (location_t loc, internal_fn ifn,
11130 : : tree type, int n, const tree *args)
11131 : : {
11132 : 325682 : tree t = build_call_1 (type, NULL_TREE, n);
11133 : 1106450 : for (int i = 0; i < n; ++i)
11134 : 780768 : CALL_EXPR_ARG (t, i) = args[i];
11135 : 325682 : SET_EXPR_LOCATION (t, loc);
11136 : 325682 : CALL_EXPR_IFN (t) = ifn;
11137 : 325682 : process_call_operands (t);
11138 : 325682 : return t;
11139 : : }
11140 : :
11141 : : /* Build internal call expression. This is just like CALL_EXPR, except
11142 : : its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
11143 : : internal function. */
11144 : :
11145 : : tree
11146 : 324656 : build_call_expr_internal_loc (location_t loc, enum internal_fn ifn,
11147 : : tree type, int n, ...)
11148 : : {
11149 : 324656 : va_list ap;
11150 : 324656 : tree *argarray = XALLOCAVEC (tree, n);
11151 : 324656 : int i;
11152 : :
11153 : 324656 : va_start (ap, n);
11154 : 1103374 : for (i = 0; i < n; i++)
11155 : 778718 : argarray[i] = va_arg (ap, tree);
11156 : 324656 : va_end (ap);
11157 : 324656 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11158 : : }
11159 : :
11160 : : /* Return a function call to FN, if the target is guaranteed to support it,
11161 : : or null otherwise.
11162 : :
11163 : : N is the number of arguments, passed in the "...", and TYPE is the
11164 : : type of the return value. */
11165 : :
11166 : : tree
11167 : 1825 : maybe_build_call_expr_loc (location_t loc, combined_fn fn, tree type,
11168 : : int n, ...)
11169 : : {
11170 : 1825 : va_list ap;
11171 : 1825 : tree *argarray = XALLOCAVEC (tree, n);
11172 : 1825 : int i;
11173 : :
11174 : 1825 : va_start (ap, n);
11175 : 4743 : for (i = 0; i < n; i++)
11176 : 2918 : argarray[i] = va_arg (ap, tree);
11177 : 1825 : va_end (ap);
11178 : 1825 : if (internal_fn_p (fn))
11179 : : {
11180 : 1024 : internal_fn ifn = as_internal_fn (fn);
11181 : 1024 : if (direct_internal_fn_p (ifn))
11182 : : {
11183 : 1 : tree_pair types = direct_internal_fn_types (ifn, type, argarray);
11184 : 1 : if (!direct_internal_fn_supported_p (ifn, types,
11185 : : OPTIMIZE_FOR_BOTH))
11186 : 1 : return NULL_TREE;
11187 : : }
11188 : 1023 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11189 : : }
11190 : : else
11191 : : {
11192 : 801 : tree fndecl = builtin_decl_implicit (as_builtin_fn (fn));
11193 : 801 : if (!fndecl)
11194 : : return NULL_TREE;
11195 : 693 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11196 : : }
11197 : : }
11198 : :
11199 : : /* Return a function call to the appropriate builtin alloca variant.
11200 : :
11201 : : SIZE is the size to be allocated. ALIGN, if non-zero, is the requested
11202 : : alignment of the allocated area. MAX_SIZE, if non-negative, is an upper
11203 : : bound for SIZE in case it is not a fixed value. */
11204 : :
11205 : : tree
11206 : 8866 : build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size)
11207 : : {
11208 : 8866 : if (max_size >= 0)
11209 : : {
11210 : 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX);
11211 : 0 : return
11212 : 0 : build_call_expr (t, 3, size, size_int (align), size_int (max_size));
11213 : : }
11214 : 8866 : else if (align > 0)
11215 : : {
11216 : 8866 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
11217 : 8866 : return build_call_expr (t, 2, size, size_int (align));
11218 : : }
11219 : : else
11220 : : {
11221 : 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA);
11222 : 0 : return build_call_expr (t, 1, size);
11223 : : }
11224 : : }
11225 : :
11226 : : /* The built-in decl to use to mark code points believed to be unreachable.
11227 : : Typically __builtin_unreachable, but __builtin_trap if
11228 : : -fsanitize=unreachable -fsanitize-trap=unreachable. If only
11229 : : -fsanitize=unreachable, we rely on sanopt to replace calls with the
11230 : : appropriate ubsan function. When building a call directly, use
11231 : : {gimple_},build_builtin_unreachable instead. */
11232 : :
11233 : : tree
11234 : 235758 : builtin_decl_unreachable ()
11235 : : {
11236 : 235758 : enum built_in_function fncode = BUILT_IN_UNREACHABLE;
11237 : :
11238 : 471516 : if (sanitize_flags_p (SANITIZE_UNREACHABLE)
11239 : 235758 : ? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
11240 : 235292 : : flag_unreachable_traps)
11241 : 22 : fncode = BUILT_IN_UNREACHABLE_TRAP;
11242 : : /* For non-trapping sanitize, we will rewrite __builtin_unreachable () later,
11243 : : in the sanopt pass. */
11244 : :
11245 : 235758 : return builtin_decl_explicit (fncode);
11246 : : }
11247 : :
11248 : : /* Build a call to __builtin_unreachable, possibly rewritten by
11249 : : -fsanitize=unreachable. Use this rather than the above when practical. */
11250 : :
11251 : : tree
11252 : 15171731 : build_builtin_unreachable (location_t loc)
11253 : : {
11254 : 15171731 : tree data = NULL_TREE;
11255 : 15171731 : tree fn = sanitize_unreachable_fn (&data, loc);
11256 : 15171731 : return build_call_expr_loc (loc, fn, data != NULL_TREE, data);
11257 : : }
11258 : :
11259 : : /* Create a new constant string literal of type ELTYPE[SIZE] (or LEN
11260 : : if SIZE == -1) and return a tree node representing char* pointer to
11261 : : it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). When STR is nonnull
11262 : : the STRING_CST value is the LEN bytes at STR (the representation
11263 : : of the string, which may be wide). Otherwise it's all zeros. */
11264 : :
11265 : : tree
11266 : 84877 : build_string_literal (unsigned len, const char *str /* = NULL */,
11267 : : tree eltype /* = char_type_node */,
11268 : : unsigned HOST_WIDE_INT size /* = -1 */)
11269 : : {
11270 : 84877 : tree t = build_string (len, str);
11271 : : /* Set the maximum valid index based on the string length or SIZE. */
11272 : 169754 : unsigned HOST_WIDE_INT maxidx
11273 : 84877 : = (size == HOST_WIDE_INT_M1U ? len : size) - 1;
11274 : :
11275 : 84877 : tree index = build_index_type (size_int (maxidx));
11276 : 84877 : eltype = build_type_variant (eltype, 1, 0);
11277 : 84877 : tree type = build_array_type (eltype, index);
11278 : 84877 : TREE_TYPE (t) = type;
11279 : 84877 : TREE_CONSTANT (t) = 1;
11280 : 84877 : TREE_READONLY (t) = 1;
11281 : 84877 : TREE_STATIC (t) = 1;
11282 : :
11283 : 84877 : type = build_pointer_type (eltype);
11284 : 84877 : t = build1 (ADDR_EXPR, type,
11285 : : build4 (ARRAY_REF, eltype,
11286 : : t, integer_zero_node, NULL_TREE, NULL_TREE));
11287 : 84877 : return t;
11288 : : }
11289 : :
11290 : :
11291 : :
11292 : : /* Return true if T (assumed to be a DECL) must be assigned a memory
11293 : : location. */
11294 : :
11295 : : bool
11296 : 1986959961 : needs_to_live_in_memory (const_tree t)
11297 : : {
11298 : 1986959961 : return (TREE_ADDRESSABLE (t)
11299 : 1588367326 : || is_global_var (t)
11300 : 3140916605 : || (TREE_CODE (t) == RESULT_DECL
11301 : 8174391 : && !DECL_BY_REFERENCE (t)
11302 : 5690196 : && aggregate_value_p (t, current_function_decl)));
11303 : : }
11304 : :
11305 : : /* Return value of a constant X and sign-extend it. */
11306 : :
11307 : : HOST_WIDE_INT
11308 : 600996805 : int_cst_value (const_tree x)
11309 : : {
11310 : 600996805 : unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
11311 : 600996805 : unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
11312 : :
11313 : : /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
11314 : 600996805 : gcc_assert (cst_and_fits_in_hwi (x));
11315 : :
11316 : 600996805 : if (bits < HOST_BITS_PER_WIDE_INT)
11317 : : {
11318 : 586627082 : bool negative = ((val >> (bits - 1)) & 1) != 0;
11319 : 586627082 : if (negative)
11320 : 221808 : val |= HOST_WIDE_INT_M1U << (bits - 1) << 1;
11321 : : else
11322 : 586405274 : val &= ~(HOST_WIDE_INT_M1U << (bits - 1) << 1);
11323 : : }
11324 : :
11325 : 600996805 : return val;
11326 : : }
11327 : :
11328 : : /* If TYPE is an integral or pointer type, return an integer type with
11329 : : the same precision which is unsigned iff UNSIGNEDP is true, or itself
11330 : : if TYPE is already an integer type of signedness UNSIGNEDP.
11331 : : If TYPE is a floating-point type, return an integer type with the same
11332 : : bitsize and with the signedness given by UNSIGNEDP; this is useful
11333 : : when doing bit-level operations on a floating-point value. */
11334 : :
11335 : : tree
11336 : 87236390 : signed_or_unsigned_type_for (int unsignedp, tree type)
11337 : : {
11338 : 87236390 : if (ANY_INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) == unsignedp)
11339 : : return type;
11340 : :
11341 : 56383312 : if (TREE_CODE (type) == VECTOR_TYPE)
11342 : : {
11343 : 20701 : tree inner = TREE_TYPE (type);
11344 : 20701 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11345 : 20701 : if (!inner2)
11346 : : return NULL_TREE;
11347 : 20701 : if (inner == inner2)
11348 : : return type;
11349 : 20701 : machine_mode new_mode;
11350 : 41402 : if (VECTOR_MODE_P (TYPE_MODE (type))
11351 : 41333 : && related_int_vector_mode (TYPE_MODE (type)).exists (&new_mode))
11352 : 20632 : return build_vector_type_for_mode (inner2, new_mode);
11353 : 69 : return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
11354 : : }
11355 : :
11356 : : if (TREE_CODE (type) == COMPLEX_TYPE)
11357 : : {
11358 : 24 : tree inner = TREE_TYPE (type);
11359 : 24 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11360 : 24 : if (!inner2)
11361 : : return NULL_TREE;
11362 : 24 : if (inner == inner2)
11363 : : return type;
11364 : 24 : return build_complex_type (inner2);
11365 : : }
11366 : :
11367 : : unsigned int bits;
11368 : : if (INTEGRAL_TYPE_P (type)
11369 : : || POINTER_TYPE_P (type)
11370 : : || TREE_CODE (type) == OFFSET_TYPE)
11371 : 56362493 : bits = TYPE_PRECISION (type);
11372 : : else if (TREE_CODE (type) == REAL_TYPE)
11373 : 188 : bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (type));
11374 : : else
11375 : : return NULL_TREE;
11376 : :
11377 : 56362587 : if (TREE_CODE (type) == BITINT_TYPE && (unsignedp || bits > 1))
11378 : 1685 : return build_bitint_type (bits, unsignedp);
11379 : 56360902 : return build_nonstandard_integer_type (bits, unsignedp);
11380 : : }
11381 : :
11382 : : /* If TYPE is an integral or pointer type, return an integer type with
11383 : : the same precision which is unsigned, or itself if TYPE is already an
11384 : : unsigned integer type. If TYPE is a floating-point type, return an
11385 : : unsigned integer type with the same bitsize as TYPE. */
11386 : :
11387 : : tree
11388 : 77849703 : unsigned_type_for (tree type)
11389 : : {
11390 : 77849703 : return signed_or_unsigned_type_for (1, type);
11391 : : }
11392 : :
11393 : : /* If TYPE is an integral or pointer type, return an integer type with
11394 : : the same precision which is signed, or itself if TYPE is already a
11395 : : signed integer type. If TYPE is a floating-point type, return a
11396 : : signed integer type with the same bitsize as TYPE. */
11397 : :
11398 : : tree
11399 : 9360900 : signed_type_for (tree type)
11400 : : {
11401 : 9360900 : return signed_or_unsigned_type_for (0, type);
11402 : : }
11403 : :
11404 : : /* - For VECTOR_TYPEs:
11405 : : - The truth type must be a VECTOR_BOOLEAN_TYPE.
11406 : : - The number of elements must match (known_eq).
11407 : : - targetm.vectorize.get_mask_mode exists, and exactly
11408 : : the same mode as the truth type.
11409 : : - Otherwise, the truth type must be a BOOLEAN_TYPE
11410 : : or useless_type_conversion_p to BOOLEAN_TYPE. */
11411 : : bool
11412 : 1932 : is_truth_type_for (tree type, tree truth_type)
11413 : : {
11414 : 1932 : machine_mode mask_mode = TYPE_MODE (truth_type);
11415 : 1932 : machine_mode vmode = TYPE_MODE (type);
11416 : 1932 : machine_mode tmask_mode;
11417 : :
11418 : 1932 : if (TREE_CODE (type) == VECTOR_TYPE)
11419 : : {
11420 : 1932 : if (VECTOR_BOOLEAN_TYPE_P (truth_type)
11421 : 1932 : && known_eq (TYPE_VECTOR_SUBPARTS (type),
11422 : : TYPE_VECTOR_SUBPARTS (truth_type))
11423 : 1932 : && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode)
11424 : 3864 : && tmask_mode == mask_mode)
11425 : 1913 : return true;
11426 : :
11427 : 19 : return false;
11428 : : }
11429 : :
11430 : 0 : return useless_type_conversion_p (boolean_type_node, truth_type);
11431 : : }
11432 : :
11433 : : /* If TYPE is a vector type, return a signed integer vector type with the
11434 : : same width and number of subparts. Otherwise return boolean_type_node. */
11435 : :
11436 : : tree
11437 : 3855158 : truth_type_for (tree type)
11438 : : {
11439 : 3855158 : if (TREE_CODE (type) == VECTOR_TYPE)
11440 : : {
11441 : 2016640 : if (VECTOR_BOOLEAN_TYPE_P (type))
11442 : : return type;
11443 : 1947917 : return build_truth_vector_type_for (type);
11444 : : }
11445 : : else
11446 : 1838518 : return boolean_type_node;
11447 : : }
11448 : :
11449 : : /* Returns the largest value obtainable by casting something in INNER type to
11450 : : OUTER type. */
11451 : :
11452 : : tree
11453 : 10635580 : upper_bound_in_type (tree outer, tree inner)
11454 : : {
11455 : 10635580 : unsigned int det = 0;
11456 : 10635580 : unsigned oprec = TYPE_PRECISION (outer);
11457 : 10635580 : unsigned iprec = TYPE_PRECISION (inner);
11458 : 10635580 : unsigned prec;
11459 : :
11460 : : /* Compute a unique number for every combination. */
11461 : 10635580 : det |= (oprec > iprec) ? 4 : 0;
11462 : 10635580 : det |= TYPE_UNSIGNED (outer) ? 2 : 0;
11463 : 10635580 : det |= TYPE_UNSIGNED (inner) ? 1 : 0;
11464 : :
11465 : : /* Determine the exponent to use. */
11466 : 10635580 : switch (det)
11467 : : {
11468 : 7000473 : case 0:
11469 : 7000473 : case 1:
11470 : : /* oprec <= iprec, outer: signed, inner: don't care. */
11471 : 7000473 : prec = oprec - 1;
11472 : 7000473 : break;
11473 : : case 2:
11474 : : case 3:
11475 : : /* oprec <= iprec, outer: unsigned, inner: don't care. */
11476 : : prec = oprec;
11477 : : break;
11478 : 21946 : case 4:
11479 : : /* oprec > iprec, outer: signed, inner: signed. */
11480 : 21946 : prec = iprec - 1;
11481 : 21946 : break;
11482 : : case 5:
11483 : : /* oprec > iprec, outer: signed, inner: unsigned. */
11484 : 10961 : prec = iprec;
11485 : : break;
11486 : : case 6:
11487 : : /* oprec > iprec, outer: unsigned, inner: signed. */
11488 : : prec = oprec;
11489 : : break;
11490 : : case 7:
11491 : : /* oprec > iprec, outer: unsigned, inner: unsigned. */
11492 : 10961 : prec = iprec;
11493 : : break;
11494 : : default:
11495 : : gcc_unreachable ();
11496 : : }
11497 : :
11498 : 10635580 : return wide_int_to_tree (outer,
11499 : 10635580 : wi::mask (prec, false, TYPE_PRECISION (outer)));
11500 : : }
11501 : :
11502 : : /* Returns the smallest value obtainable by casting something in INNER type to
11503 : : OUTER type. */
11504 : :
11505 : : tree
11506 : 8076764 : lower_bound_in_type (tree outer, tree inner)
11507 : : {
11508 : 8076764 : unsigned oprec = TYPE_PRECISION (outer);
11509 : 8076764 : unsigned iprec = TYPE_PRECISION (inner);
11510 : :
11511 : : /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
11512 : : and obtain 0. */
11513 : 8076764 : if (TYPE_UNSIGNED (outer)
11514 : : /* If we are widening something of an unsigned type, OUTER type
11515 : : contains all values of INNER type. In particular, both INNER
11516 : : and OUTER types have zero in common. */
11517 : 8076764 : || (oprec > iprec && TYPE_UNSIGNED (inner)))
11518 : 2167437 : return build_int_cst (outer, 0);
11519 : : else
11520 : : {
11521 : : /* If we are widening a signed type to another signed type, we
11522 : : want to obtain -2^^(iprec-1). If we are keeping the
11523 : : precision or narrowing to a signed type, we want to obtain
11524 : : -2^(oprec-1). */
11525 : 5909327 : unsigned prec = oprec > iprec ? iprec : oprec;
11526 : 5909327 : return wide_int_to_tree (outer,
11527 : 11818654 : wi::mask (prec - 1, true,
11528 : 5909327 : TYPE_PRECISION (outer)));
11529 : : }
11530 : : }
11531 : :
11532 : : /* Return true if two operands that are suitable for PHI nodes are
11533 : : necessarily equal. Specifically, both ARG0 and ARG1 must be either
11534 : : SSA_NAME or invariant. Note that this is strictly an optimization.
11535 : : That is, callers of this function can directly call operand_equal_p
11536 : : and get the same result, only slower. */
11537 : :
11538 : : bool
11539 : 21458937 : operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
11540 : : {
11541 : 21458937 : if (arg0 == arg1)
11542 : : return true;
11543 : 19668640 : if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
11544 : : return false;
11545 : 3767812 : return operand_equal_p (arg0, arg1, 0);
11546 : : }
11547 : :
11548 : : /* Returns number of zeros at the end of binary representation of X. */
11549 : :
11550 : : tree
11551 : 8878471 : num_ending_zeros (const_tree x)
11552 : : {
11553 : 8878471 : return build_int_cst (TREE_TYPE (x), wi::ctz (wi::to_wide (x)));
11554 : : }
11555 : :
11556 : :
11557 : : #define WALK_SUBTREE(NODE) \
11558 : : do \
11559 : : { \
11560 : : result = walk_tree_1 (&(NODE), func, data, pset, lh); \
11561 : : if (result) \
11562 : : return result; \
11563 : : } \
11564 : : while (0)
11565 : :
11566 : : /* This is a subroutine of walk_tree that walks field of TYPE that are to
11567 : : be walked whenever a type is seen in the tree. Rest of operands and return
11568 : : value are as for walk_tree. */
11569 : :
11570 : : static tree
11571 : 3915402761 : walk_type_fields (tree type, walk_tree_fn func, void *data,
11572 : : hash_set<tree> *pset, walk_tree_lh lh)
11573 : : {
11574 : 3915402761 : tree result = NULL_TREE;
11575 : :
11576 : 3915402761 : switch (TREE_CODE (type))
11577 : : {
11578 : 1156868117 : case POINTER_TYPE:
11579 : 1156868117 : case REFERENCE_TYPE:
11580 : 1156868117 : case VECTOR_TYPE:
11581 : : /* We have to worry about mutually recursive pointers. These can't
11582 : : be written in C. They can in Ada. It's pathological, but
11583 : : there's an ACATS test (c38102a) that checks it. Deal with this
11584 : : by checking if we're pointing to another pointer, that one
11585 : : points to another pointer, that one does too, and we have no htab.
11586 : : If so, get a hash table. We check three levels deep to avoid
11587 : : the cost of the hash table if we don't need one. */
11588 : 2285938657 : if (POINTER_TYPE_P (TREE_TYPE (type))
11589 : 27797644 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
11590 : 4859486 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
11591 : 1161690495 : && !pset)
11592 : : {
11593 : 0 : result = walk_tree_without_duplicates (&TREE_TYPE (type),
11594 : : func, data);
11595 : 0 : if (result)
11596 : : return result;
11597 : :
11598 : : break;
11599 : : }
11600 : :
11601 : : /* fall through */
11602 : :
11603 : 1160077647 : case COMPLEX_TYPE:
11604 : 1160077647 : WALK_SUBTREE (TREE_TYPE (type));
11605 : : break;
11606 : :
11607 : 222252803 : case METHOD_TYPE:
11608 : 222252803 : WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
11609 : :
11610 : : /* Fall through. */
11611 : :
11612 : 365375874 : case FUNCTION_TYPE:
11613 : 365375874 : WALK_SUBTREE (TREE_TYPE (type));
11614 : 365375836 : {
11615 : 365375836 : tree arg;
11616 : :
11617 : : /* We never want to walk into default arguments. */
11618 : 1410430375 : for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
11619 : 1045084406 : WALK_SUBTREE (TREE_VALUE (arg));
11620 : : }
11621 : : break;
11622 : :
11623 : 12569903 : case ARRAY_TYPE:
11624 : : /* Don't follow this nodes's type if a pointer for fear that
11625 : : we'll have infinite recursion. If we have a PSET, then we
11626 : : need not fear. */
11627 : 12569903 : if (pset
11628 : 12569903 : || (!POINTER_TYPE_P (TREE_TYPE (type))
11629 : 107000 : && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
11630 : 12568202 : WALK_SUBTREE (TREE_TYPE (type));
11631 : 12567298 : WALK_SUBTREE (TYPE_DOMAIN (type));
11632 : : break;
11633 : :
11634 : 956309 : case OFFSET_TYPE:
11635 : 956309 : WALK_SUBTREE (TREE_TYPE (type));
11636 : 955477 : WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
11637 : : break;
11638 : :
11639 : : default:
11640 : : break;
11641 : : }
11642 : :
11643 : : return NULL_TREE;
11644 : : }
11645 : :
11646 : : /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11647 : : called with the DATA and the address of each sub-tree. If FUNC returns a
11648 : : non-NULL value, the traversal is stopped, and the value returned by FUNC
11649 : : is returned. If PSET is non-NULL it is used to record the nodes visited,
11650 : : and to avoid visiting a node more than once. */
11651 : :
11652 : : tree
11653 : 99199505251 : walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
11654 : : hash_set<tree> *pset, walk_tree_lh lh)
11655 : : {
11656 : : #define WALK_SUBTREE_TAIL(NODE) \
11657 : : do \
11658 : : { \
11659 : : tp = & (NODE); \
11660 : : goto tail_recurse; \
11661 : : } \
11662 : : while (0)
11663 : :
11664 : >12035*10^7 : tail_recurse:
11665 : : /* Skip empty subtrees. */
11666 : >12035*10^7 : if (!*tp)
11667 : : return NULL_TREE;
11668 : :
11669 : : /* Don't walk the same tree twice, if the user has requested
11670 : : that we avoid doing so. */
11671 : 98877308858 : if (pset && pset->add (*tp))
11672 : : return NULL_TREE;
11673 : :
11674 : : /* Call the function. */
11675 : 97684290663 : int walk_subtrees = 1;
11676 : 97684290663 : tree result = (*func) (tp, &walk_subtrees, data);
11677 : :
11678 : : /* If we found something, return it. */
11679 : 97684290663 : if (result)
11680 : : return result;
11681 : :
11682 : 97621173990 : tree t = *tp;
11683 : 97621173990 : tree_code code = TREE_CODE (t);
11684 : :
11685 : : /* Even if we didn't, FUNC may have decided that there was nothing
11686 : : interesting below this point in the tree. */
11687 : 97621173990 : if (!walk_subtrees)
11688 : : {
11689 : : /* But we still need to check our siblings. */
11690 : 64296737325 : if (code == TREE_LIST)
11691 : 85107 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11692 : 64296652218 : else if (code == OMP_CLAUSE)
11693 : 874918 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11694 : : else
11695 : : return NULL_TREE;
11696 : : }
11697 : :
11698 : 33324436665 : if (lh)
11699 : : {
11700 : 16263697050 : result = (*lh) (tp, &walk_subtrees, func, data, pset);
11701 : 16263697050 : if (result || !walk_subtrees)
11702 : 2310420263 : return result;
11703 : : }
11704 : :
11705 : 31014016402 : switch (code)
11706 : : {
11707 : : case ERROR_MARK:
11708 : : case IDENTIFIER_NODE:
11709 : : case INTEGER_CST:
11710 : : case REAL_CST:
11711 : : case FIXED_CST:
11712 : : case STRING_CST:
11713 : : case BLOCK:
11714 : : case PLACEHOLDER_EXPR:
11715 : : case SSA_NAME:
11716 : : case FIELD_DECL:
11717 : : case RESULT_DECL:
11718 : : /* None of these have subtrees other than those already walked
11719 : : above. */
11720 : : break;
11721 : :
11722 : 229316336 : case TREE_LIST:
11723 : 229316336 : WALK_SUBTREE (TREE_VALUE (t));
11724 : 228799214 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11725 : :
11726 : 848621304 : case TREE_VEC:
11727 : 848621304 : {
11728 : 848621304 : int len = TREE_VEC_LENGTH (t);
11729 : :
11730 : 848621304 : if (len == 0)
11731 : : break;
11732 : :
11733 : : /* Walk all elements but the last. */
11734 : 1694646616 : for (int i = 0; i < len - 1; ++i)
11735 : 855451602 : WALK_SUBTREE (TREE_VEC_ELT (t, i));
11736 : :
11737 : : /* Now walk the last one as a tail call. */
11738 : 839195014 : WALK_SUBTREE_TAIL (TREE_VEC_ELT (t, len - 1));
11739 : : }
11740 : :
11741 : 4611609 : case VECTOR_CST:
11742 : 4611609 : {
11743 : 4611609 : unsigned len = vector_cst_encoded_nelts (t);
11744 : 4611609 : if (len == 0)
11745 : : break;
11746 : : /* Walk all elements but the last. */
11747 : 15860649 : for (unsigned i = 0; i < len - 1; ++i)
11748 : 11249184 : WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (t, i));
11749 : : /* Now walk the last one as a tail call. */
11750 : 4611465 : WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (t, len - 1));
11751 : : }
11752 : :
11753 : 534107 : case COMPLEX_CST:
11754 : 534107 : WALK_SUBTREE (TREE_REALPART (t));
11755 : 532541 : WALK_SUBTREE_TAIL (TREE_IMAGPART (t));
11756 : :
11757 : : case CONSTRUCTOR:
11758 : : {
11759 : : unsigned HOST_WIDE_INT idx;
11760 : : constructor_elt *ce;
11761 : :
11762 : 687000015 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce);
11763 : : idx++)
11764 : 219319089 : WALK_SUBTREE (ce->value);
11765 : : }
11766 : : break;
11767 : :
11768 : 3427950 : case SAVE_EXPR:
11769 : 3427950 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, 0));
11770 : :
11771 : 156116655 : case BIND_EXPR:
11772 : 156116655 : {
11773 : 156116655 : tree decl;
11774 : 255784207 : for (decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
11775 : : {
11776 : : /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11777 : : into declarations that are just mentioned, rather than
11778 : : declared; they don't really belong to this part of the tree.
11779 : : And, we can see cycles: the initializer for a declaration
11780 : : can refer to the declaration itself. */
11781 : 99667576 : WALK_SUBTREE (DECL_INITIAL (decl));
11782 : 99667552 : WALK_SUBTREE (DECL_SIZE (decl));
11783 : 99667552 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
11784 : : }
11785 : 156116631 : WALK_SUBTREE_TAIL (BIND_EXPR_BODY (t));
11786 : : }
11787 : :
11788 : 183255382 : case STATEMENT_LIST:
11789 : 183255382 : {
11790 : 183255382 : tree_stmt_iterator i;
11791 : 662754084 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
11792 : 479643186 : WALK_SUBTREE (*tsi_stmt_ptr (i));
11793 : : }
11794 : 183110898 : break;
11795 : :
11796 : 1677879 : case OMP_CLAUSE:
11797 : 1677879 : {
11798 : 1677879 : int len = omp_clause_num_ops[OMP_CLAUSE_CODE (t)];
11799 : : /* Do not walk the iterator operand of OpenMP MAP clauses. */
11800 : 1677879 : if (OMP_CLAUSE_HAS_ITERATORS (t))
11801 : 781 : len--;
11802 : 4740565 : for (int i = 0; i < len; i++)
11803 : 3062686 : WALK_SUBTREE (OMP_CLAUSE_OPERAND (t, i));
11804 : 1677879 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11805 : : }
11806 : :
11807 : 43568418 : case TARGET_EXPR:
11808 : 43568418 : {
11809 : 43568418 : int i, len;
11810 : :
11811 : : /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11812 : : But, we only want to walk once. */
11813 : 43568418 : len = (TREE_OPERAND (t, 3) == TREE_OPERAND (t, 1)) ? 2 : 3;
11814 : 174239535 : for (i = 0; i < len; ++i)
11815 : 130686976 : WALK_SUBTREE (TREE_OPERAND (t, i));
11816 : 43552559 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len));
11817 : : }
11818 : :
11819 : 95277708 : case DECL_EXPR:
11820 : : /* If this is a TYPE_DECL, walk into the fields of the type that it's
11821 : : defining. We only want to walk into these fields of a type in this
11822 : : case and not in the general case of a mere reference to the type.
11823 : :
11824 : : The criterion is as follows: if the field can be an expression, it
11825 : : must be walked only here. This should be in keeping with the fields
11826 : : that are directly gimplified in gimplify_type_sizes in order for the
11827 : : mark/copy-if-shared/unmark machinery of the gimplifier to work with
11828 : : variable-sized types.
11829 : :
11830 : : Note that DECLs get walked as part of processing the BIND_EXPR. */
11831 : 95277708 : if (TREE_CODE (DECL_EXPR_DECL (t)) == TYPE_DECL)
11832 : : {
11833 : : /* Call the function for the decl so e.g. copy_tree_body_r can
11834 : : replace it with the remapped one. */
11835 : 877187 : result = (*func) (&DECL_EXPR_DECL (t), &walk_subtrees, data);
11836 : 877187 : if (result || !walk_subtrees)
11837 : 44356 : return result;
11838 : :
11839 : 832831 : tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (t));
11840 : 832831 : if (TREE_CODE (*type_p) == ERROR_MARK)
11841 : : return NULL_TREE;
11842 : :
11843 : : /* Call the function for the type. See if it returns anything or
11844 : : doesn't want us to continue. If we are to continue, walk both
11845 : : the normal fields and those for the declaration case. */
11846 : 832831 : result = (*func) (type_p, &walk_subtrees, data);
11847 : 832831 : if (result || !walk_subtrees)
11848 : 71385 : return result;
11849 : :
11850 : 761446 : tree type = *type_p;
11851 : :
11852 : : /* But do not walk a pointed-to type since it may itself need to
11853 : : be walked in the declaration case if it isn't anonymous. */
11854 : 761446 : if (!POINTER_TYPE_P (type))
11855 : : {
11856 : 745753 : result = walk_type_fields (type, func, data, pset, lh);
11857 : 745753 : if (result)
11858 : : return result;
11859 : : }
11860 : :
11861 : : /* If this is a record type, also walk the fields. */
11862 : 761446 : if (RECORD_OR_UNION_TYPE_P (type))
11863 : : {
11864 : 288929 : tree field;
11865 : :
11866 : 1181037 : for (field = TYPE_FIELDS (type); field;
11867 : 892108 : field = DECL_CHAIN (field))
11868 : : {
11869 : : /* We'd like to look at the type of the field, but we can
11870 : : easily get infinite recursion. So assume it's pointed
11871 : : to elsewhere in the tree. Also, ignore things that
11872 : : aren't fields. */
11873 : 892108 : if (TREE_CODE (field) != FIELD_DECL)
11874 : 657303 : continue;
11875 : :
11876 : 234805 : WALK_SUBTREE (DECL_FIELD_OFFSET (field));
11877 : 234805 : WALK_SUBTREE (DECL_SIZE (field));
11878 : 234805 : WALK_SUBTREE (DECL_SIZE_UNIT (field));
11879 : 234805 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
11880 : 0 : WALK_SUBTREE (DECL_QUALIFIER (field));
11881 : : }
11882 : : }
11883 : :
11884 : : /* Same for scalar types. */
11885 : 472517 : else if (TREE_CODE (type) == BOOLEAN_TYPE
11886 : : || TREE_CODE (type) == ENUMERAL_TYPE
11887 : 472517 : || TREE_CODE (type) == INTEGER_TYPE
11888 : 472480 : || TREE_CODE (type) == FIXED_POINT_TYPE
11889 : 472480 : || TREE_CODE (type) == REAL_TYPE)
11890 : : {
11891 : 37 : WALK_SUBTREE (TYPE_MIN_VALUE (type));
11892 : 37 : WALK_SUBTREE (TYPE_MAX_VALUE (type));
11893 : : }
11894 : :
11895 : 761446 : WALK_SUBTREE (TYPE_SIZE (type));
11896 : 761446 : WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (type));
11897 : : }
11898 : : /* FALLTHRU */
11899 : :
11900 : 26183756086 : default:
11901 : 26183756086 : if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
11902 : : {
11903 : 20011437250 : int i, len;
11904 : :
11905 : : /* Walk over all the sub-trees of this operand. */
11906 : 20011437250 : len = TREE_OPERAND_LENGTH (t);
11907 : :
11908 : : /* Go through the subtrees. We need to do this in forward order so
11909 : : that the scope of a FOR_EXPR is handled properly. */
11910 : 20011437250 : if (len)
11911 : : {
11912 : 41418762027 : for (i = 0; i < len - 1; ++i)
11913 : 21540936799 : WALK_SUBTREE (TREE_OPERAND (t, i));
11914 : 19877825228 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len - 1));
11915 : : }
11916 : : }
11917 : : /* If this is a type, walk the needed fields in the type. */
11918 : 6172318836 : else if (TYPE_P (t))
11919 : 3914657008 : return walk_type_fields (t, func, data, pset, lh);
11920 : : break;
11921 : : }
11922 : :
11923 : : /* We didn't find what we were looking for. */
11924 : : return NULL_TREE;
11925 : :
11926 : : #undef WALK_SUBTREE_TAIL
11927 : : }
11928 : : #undef WALK_SUBTREE
11929 : :
11930 : : /* Like walk_tree, but does not walk duplicate nodes more than once. */
11931 : :
11932 : : tree
11933 : 2779786611 : walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
11934 : : walk_tree_lh lh)
11935 : : {
11936 : 2779786611 : tree result;
11937 : :
11938 : 2779786611 : hash_set<tree> pset;
11939 : 2779786611 : result = walk_tree_1 (tp, func, data, &pset, lh);
11940 : 2779786611 : return result;
11941 : 2779786611 : }
11942 : :
11943 : :
11944 : : tree
11945 : 910354944 : tree_block (tree t)
11946 : : {
11947 : 910354944 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
11948 : :
11949 : 910354944 : if (IS_EXPR_CODE_CLASS (c))
11950 : 910354944 : return LOCATION_BLOCK (t->exp.locus);
11951 : 0 : gcc_unreachable ();
11952 : : return NULL;
11953 : : }
11954 : :
11955 : : void
11956 : 471715079 : tree_set_block (tree t, tree b)
11957 : : {
11958 : 471715079 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
11959 : :
11960 : 471715079 : if (IS_EXPR_CODE_CLASS (c))
11961 : : {
11962 : 471715079 : t->exp.locus = set_block (t->exp.locus, b);
11963 : : }
11964 : : else
11965 : 0 : gcc_unreachable ();
11966 : 471715079 : }
11967 : :
11968 : : /* Create a nameless artificial label and put it in the current
11969 : : function context. The label has a location of LOC. Returns the
11970 : : newly created label. */
11971 : :
11972 : : tree
11973 : 31226468 : create_artificial_label (location_t loc)
11974 : : {
11975 : 31226468 : tree lab = build_decl (loc,
11976 : : LABEL_DECL, NULL_TREE, void_type_node);
11977 : :
11978 : 31226468 : DECL_ARTIFICIAL (lab) = 1;
11979 : 31226468 : DECL_IGNORED_P (lab) = 1;
11980 : 31226468 : DECL_CONTEXT (lab) = current_function_decl;
11981 : 31226468 : return lab;
11982 : : }
11983 : :
11984 : : /* Given a tree, try to return a useful variable name that we can use
11985 : : to prefix a temporary that is being assigned the value of the tree.
11986 : : I.E. given <temp> = &A, return A. */
11987 : :
11988 : : const char *
11989 : 24843826 : get_name (tree t)
11990 : : {
11991 : 26743377 : tree stripped_decl;
11992 : :
11993 : 26743377 : stripped_decl = t;
11994 : 26743377 : STRIP_NOPS (stripped_decl);
11995 : 26743377 : if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
11996 : 4064021 : return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
11997 : 22679356 : else if (TREE_CODE (stripped_decl) == SSA_NAME)
11998 : : {
11999 : 1281546 : tree name = SSA_NAME_IDENTIFIER (stripped_decl);
12000 : 305362 : if (!name)
12001 : : return NULL;
12002 : 304097 : return IDENTIFIER_POINTER (name);
12003 : : }
12004 : : else
12005 : : {
12006 : 21397810 : switch (TREE_CODE (stripped_decl))
12007 : : {
12008 : 1899551 : case ADDR_EXPR:
12009 : 1899551 : return get_name (TREE_OPERAND (stripped_decl, 0));
12010 : : default:
12011 : : return NULL;
12012 : : }
12013 : : }
12014 : : }
12015 : :
12016 : : /* Return true if TYPE has a variable argument list. */
12017 : :
12018 : : bool
12019 : 211545009 : stdarg_p (const_tree fntype)
12020 : : {
12021 : 211545009 : function_args_iterator args_iter;
12022 : 211545009 : tree n = NULL_TREE, t;
12023 : :
12024 : 211545009 : if (!fntype)
12025 : : return false;
12026 : :
12027 : 211412093 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12028 : : return true;
12029 : :
12030 : 859331250 : FOREACH_FUNCTION_ARGS (fntype, t, args_iter)
12031 : : {
12032 : 648572298 : n = t;
12033 : : }
12034 : :
12035 : 210758952 : return n != NULL_TREE && n != void_type_node;
12036 : : }
12037 : :
12038 : : /* Return true if TYPE has a prototype. */
12039 : :
12040 : : bool
12041 : 711340931 : prototype_p (const_tree fntype)
12042 : : {
12043 : 711340931 : tree t;
12044 : :
12045 : 711340931 : gcc_assert (fntype != NULL_TREE);
12046 : :
12047 : 711340931 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12048 : : return true;
12049 : :
12050 : 710600795 : t = TYPE_ARG_TYPES (fntype);
12051 : 710600795 : return (t != NULL_TREE);
12052 : : }
12053 : :
12054 : : /* If BLOCK is inlined from an __attribute__((__artificial__))
12055 : : routine, return pointer to location from where it has been
12056 : : called. */
12057 : : location_t *
12058 : 181508 : block_nonartificial_location (tree block)
12059 : : {
12060 : 181508 : location_t *ret = NULL;
12061 : :
12062 : 468123 : while (block && TREE_CODE (block) == BLOCK
12063 : 567630 : && BLOCK_ABSTRACT_ORIGIN (block))
12064 : : {
12065 : 180722 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12066 : 180722 : if (TREE_CODE (ao) == FUNCTION_DECL)
12067 : : {
12068 : : /* If AO is an artificial inline, point RET to the
12069 : : call site locus at which it has been inlined and continue
12070 : : the loop, in case AO's caller is also an artificial
12071 : : inline. */
12072 : 77350 : if (DECL_DECLARED_INLINE_P (ao)
12073 : 77350 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
12074 : 1789 : ret = &BLOCK_SOURCE_LOCATION (block);
12075 : : else
12076 : : break;
12077 : : }
12078 : 103372 : else if (TREE_CODE (ao) != BLOCK)
12079 : : break;
12080 : :
12081 : 105161 : block = BLOCK_SUPERCONTEXT (block);
12082 : : }
12083 : 181508 : return ret;
12084 : : }
12085 : :
12086 : :
12087 : : /* If EXP is inlined from an __attribute__((__artificial__))
12088 : : function, return the location of the original call expression. */
12089 : :
12090 : : location_t
12091 : 54 : tree_nonartificial_location (tree exp)
12092 : : {
12093 : 54 : location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
12094 : :
12095 : 54 : if (loc)
12096 : 0 : return *loc;
12097 : : else
12098 : 54 : return EXPR_LOCATION (exp);
12099 : : }
12100 : :
12101 : : /* Return the location into which EXP has been inlined. Analogous
12102 : : to tree_nonartificial_location() above but not limited to artificial
12103 : : functions declared inline. If SYSTEM_HEADER is true, return
12104 : : the macro expansion point of the location if it's in a system header */
12105 : :
12106 : : location_t
12107 : 0 : tree_inlined_location (tree exp, bool system_header /* = true */)
12108 : : {
12109 : 0 : location_t loc = UNKNOWN_LOCATION;
12110 : :
12111 : 0 : tree block = TREE_BLOCK (exp);
12112 : :
12113 : 0 : while (block && TREE_CODE (block) == BLOCK
12114 : 0 : && BLOCK_ABSTRACT_ORIGIN (block))
12115 : : {
12116 : 0 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12117 : 0 : if (TREE_CODE (ao) == FUNCTION_DECL)
12118 : 0 : loc = BLOCK_SOURCE_LOCATION (block);
12119 : 0 : else if (TREE_CODE (ao) != BLOCK)
12120 : : break;
12121 : :
12122 : 0 : block = BLOCK_SUPERCONTEXT (block);
12123 : : }
12124 : :
12125 : 0 : if (loc == UNKNOWN_LOCATION)
12126 : : {
12127 : 0 : loc = EXPR_LOCATION (exp);
12128 : 0 : if (system_header)
12129 : : /* Only consider macro expansion when the block traversal failed
12130 : : to find a location. Otherwise it's not relevant. */
12131 : 0 : return expansion_point_location_if_in_system_header (loc);
12132 : : }
12133 : :
12134 : : return loc;
12135 : : }
12136 : :
12137 : : /* These are the hash table functions for the hash table of OPTIMIZATION_NODE
12138 : : nodes. */
12139 : :
12140 : : /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
12141 : :
12142 : : hashval_t
12143 : 908648179 : cl_option_hasher::hash (tree x)
12144 : : {
12145 : 908648179 : const_tree const t = x;
12146 : :
12147 : 908648179 : if (TREE_CODE (t) == OPTIMIZATION_NODE)
12148 : 96557129 : return cl_optimization_hash (TREE_OPTIMIZATION (t));
12149 : 812091050 : else if (TREE_CODE (t) == TARGET_OPTION_NODE)
12150 : 812091050 : return cl_target_option_hash (TREE_TARGET_OPTION (t));
12151 : : else
12152 : 0 : gcc_unreachable ();
12153 : : }
12154 : :
12155 : : /* Return nonzero if the value represented by *X (an OPTIMIZATION or
12156 : : TARGET_OPTION tree node) is the same as that given by *Y, which is the
12157 : : same. */
12158 : :
12159 : : bool
12160 : 970244492 : cl_option_hasher::equal (tree x, tree y)
12161 : : {
12162 : 970244492 : const_tree const xt = x;
12163 : 970244492 : const_tree const yt = y;
12164 : :
12165 : 970244492 : if (TREE_CODE (xt) != TREE_CODE (yt))
12166 : : return false;
12167 : :
12168 : 549136637 : if (TREE_CODE (xt) == OPTIMIZATION_NODE)
12169 : 95503261 : return cl_optimization_option_eq (TREE_OPTIMIZATION (xt),
12170 : 95503261 : TREE_OPTIMIZATION (yt));
12171 : 453633376 : else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
12172 : 453633376 : return cl_target_option_eq (TREE_TARGET_OPTION (xt),
12173 : 453633376 : TREE_TARGET_OPTION (yt));
12174 : : else
12175 : 0 : gcc_unreachable ();
12176 : : }
12177 : :
12178 : : /* Build an OPTIMIZATION_NODE based on the options in OPTS and OPTS_SET. */
12179 : :
12180 : : tree
12181 : 95785797 : build_optimization_node (struct gcc_options *opts,
12182 : : struct gcc_options *opts_set)
12183 : : {
12184 : 95785797 : tree t;
12185 : :
12186 : : /* Use the cache of optimization nodes. */
12187 : :
12188 : 95785797 : cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
12189 : : opts, opts_set);
12190 : :
12191 : 95785797 : tree *slot = cl_option_hash_table->find_slot (cl_optimization_node, INSERT);
12192 : 95785797 : t = *slot;
12193 : 95785797 : if (!t)
12194 : : {
12195 : : /* Insert this one into the hash table. */
12196 : 287902 : t = cl_optimization_node;
12197 : 287902 : *slot = t;
12198 : :
12199 : : /* Make a new node for next time round. */
12200 : 287902 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
12201 : : }
12202 : :
12203 : 95785797 : return t;
12204 : : }
12205 : :
12206 : : /* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET. */
12207 : :
12208 : : tree
12209 : 74269390 : build_target_option_node (struct gcc_options *opts,
12210 : : struct gcc_options *opts_set)
12211 : : {
12212 : 74269390 : tree t;
12213 : :
12214 : : /* Use the cache of optimization nodes. */
12215 : :
12216 : 74269390 : cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
12217 : : opts, opts_set);
12218 : :
12219 : 74269390 : tree *slot = cl_option_hash_table->find_slot (cl_target_option_node, INSERT);
12220 : 74269390 : t = *slot;
12221 : 74269390 : if (!t)
12222 : : {
12223 : : /* Insert this one into the hash table. */
12224 : 779494 : t = cl_target_option_node;
12225 : 779494 : *slot = t;
12226 : :
12227 : : /* Make a new node for next time round. */
12228 : 779494 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
12229 : : }
12230 : :
12231 : 74269390 : return t;
12232 : : }
12233 : :
12234 : : /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
12235 : : so that they aren't saved during PCH writing. */
12236 : :
12237 : : void
12238 : 435 : prepare_target_option_nodes_for_pch (void)
12239 : : {
12240 : 435 : hash_table<cl_option_hasher>::iterator iter = cl_option_hash_table->begin ();
12241 : 2610 : for (; iter != cl_option_hash_table->end (); ++iter)
12242 : 870 : if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
12243 : 435 : TREE_TARGET_GLOBALS (*iter) = NULL;
12244 : 435 : }
12245 : :
12246 : : /* Determine the "ultimate origin" of a block. */
12247 : :
12248 : : tree
12249 : 228661336 : block_ultimate_origin (const_tree block)
12250 : : {
12251 : 228661336 : tree origin = BLOCK_ABSTRACT_ORIGIN (block);
12252 : :
12253 : 228661336 : if (origin == NULL_TREE)
12254 : : return NULL_TREE;
12255 : : else
12256 : : {
12257 : 284753744 : gcc_checking_assert ((DECL_P (origin)
12258 : : && DECL_ORIGIN (origin) == origin)
12259 : : || BLOCK_ORIGIN (origin) == origin);
12260 : : return origin;
12261 : : }
12262 : : }
12263 : :
12264 : : /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
12265 : : no instruction. */
12266 : :
12267 : : bool
12268 : 1341342309 : tree_nop_conversion_p (const_tree outer_type, const_tree inner_type)
12269 : : {
12270 : : /* Do not strip casts into or out of differing address spaces. */
12271 : 1341342309 : if (POINTER_TYPE_P (outer_type)
12272 : 1341342309 : && TYPE_ADDR_SPACE (TREE_TYPE (outer_type)) != ADDR_SPACE_GENERIC)
12273 : : {
12274 : 570 : if (!POINTER_TYPE_P (inner_type)
12275 : 570 : || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
12276 : 547 : != TYPE_ADDR_SPACE (TREE_TYPE (inner_type))))
12277 : : return false;
12278 : : }
12279 : 1341341739 : else if (POINTER_TYPE_P (inner_type)
12280 : 1341341739 : && TYPE_ADDR_SPACE (TREE_TYPE (inner_type)) != ADDR_SPACE_GENERIC)
12281 : : {
12282 : : /* We already know that outer_type is not a pointer with
12283 : : a non-generic address space. */
12284 : : return false;
12285 : : }
12286 : :
12287 : : /* Use precision rather then machine mode when we can, which gives
12288 : : the correct answer even for submode (bit-field) types. */
12289 : 1341339572 : if ((INTEGRAL_TYPE_P (outer_type)
12290 : 456899776 : || POINTER_TYPE_P (outer_type)
12291 : 73556004 : || TREE_CODE (outer_type) == OFFSET_TYPE)
12292 : 1267794097 : && (INTEGRAL_TYPE_P (inner_type)
12293 : 461955599 : || POINTER_TYPE_P (inner_type)
12294 : 1406432 : || TREE_CODE (inner_type) == OFFSET_TYPE))
12295 : 1266410530 : return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
12296 : :
12297 : : /* Otherwise fall back on comparing machine modes (e.g. for
12298 : : aggregate types, floats). */
12299 : 74929042 : return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
12300 : : }
12301 : :
12302 : : /* Return true iff conversion in EXP generates no instruction. Mark
12303 : : it inline so that we fully inline into the stripping functions even
12304 : : though we have two uses of this function. */
12305 : :
12306 : : static inline bool
12307 : 17768101166 : tree_nop_conversion (const_tree exp)
12308 : : {
12309 : 17768101166 : tree outer_type, inner_type;
12310 : :
12311 : 17768101166 : if (location_wrapper_p (exp))
12312 : : return true;
12313 : 17723704501 : if (!CONVERT_EXPR_P (exp)
12314 : 16922421327 : && TREE_CODE (exp) != NON_LVALUE_EXPR)
12315 : : return false;
12316 : :
12317 : 814183841 : outer_type = TREE_TYPE (exp);
12318 : 814183841 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12319 : 814183841 : if (!inner_type || inner_type == error_mark_node)
12320 : : return false;
12321 : :
12322 : 814183841 : return tree_nop_conversion_p (outer_type, inner_type);
12323 : : }
12324 : :
12325 : : /* Return true iff conversion in EXP generates no instruction. Don't
12326 : : consider conversions changing the signedness. */
12327 : :
12328 : : static bool
12329 : 1790868748 : tree_sign_nop_conversion (const_tree exp)
12330 : : {
12331 : 1790868748 : tree outer_type, inner_type;
12332 : :
12333 : 1790868748 : if (!tree_nop_conversion (exp))
12334 : : return false;
12335 : :
12336 : 134679547 : outer_type = TREE_TYPE (exp);
12337 : 134679547 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12338 : :
12339 : 134679547 : return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
12340 : 134679547 : && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
12341 : : }
12342 : :
12343 : : /* Strip conversions from EXP according to tree_nop_conversion and
12344 : : return the resulting expression. */
12345 : :
12346 : : tree
12347 : 15393779513 : tree_strip_nop_conversions (tree exp)
12348 : : {
12349 : 15977232418 : while (tree_nop_conversion (exp))
12350 : 583452905 : exp = TREE_OPERAND (exp, 0);
12351 : 15393779513 : return exp;
12352 : : }
12353 : :
12354 : : /* Strip conversions from EXP according to tree_sign_nop_conversion
12355 : : and return the resulting expression. */
12356 : :
12357 : : tree
12358 : 1679911784 : tree_strip_sign_nop_conversions (tree exp)
12359 : : {
12360 : 1790868748 : while (tree_sign_nop_conversion (exp))
12361 : 110956964 : exp = TREE_OPERAND (exp, 0);
12362 : 1679911784 : return exp;
12363 : : }
12364 : :
12365 : : /* Avoid any floating point extensions from EXP. */
12366 : : tree
12367 : 84487907 : strip_float_extensions (tree exp)
12368 : : {
12369 : 84629508 : tree sub, expt, subt;
12370 : :
12371 : : /* For floating point constant look up the narrowest type that can hold
12372 : : it properly and handle it like (type)(narrowest_type)constant.
12373 : : This way we can optimize for instance a=a*2.0 where "a" is float
12374 : : but 2.0 is double constant. */
12375 : 84629508 : if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
12376 : : {
12377 : 2581543 : REAL_VALUE_TYPE orig;
12378 : 2581543 : tree type = NULL;
12379 : :
12380 : 2581543 : orig = TREE_REAL_CST (exp);
12381 : 2581543 : if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node)
12382 : 2581543 : && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
12383 : 140563 : type = float_type_node;
12384 : 2440980 : else if (TYPE_PRECISION (TREE_TYPE (exp))
12385 : 2440980 : > TYPE_PRECISION (double_type_node)
12386 : 2440980 : && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
12387 : 35199 : type = double_type_node;
12388 : 2581543 : if (type)
12389 : 175762 : return build_real_truncate (type, orig);
12390 : : }
12391 : :
12392 : 84453746 : if (!CONVERT_EXPR_P (exp))
12393 : : return exp;
12394 : :
12395 : 4094403 : sub = TREE_OPERAND (exp, 0);
12396 : 4094403 : subt = TREE_TYPE (sub);
12397 : 4094403 : expt = TREE_TYPE (exp);
12398 : :
12399 : 4094403 : if (!FLOAT_TYPE_P (subt))
12400 : : return exp;
12401 : :
12402 : 496333 : if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
12403 : : return exp;
12404 : :
12405 : 165809 : if (element_precision (subt) > element_precision (expt))
12406 : : return exp;
12407 : :
12408 : : return strip_float_extensions (sub);
12409 : : }
12410 : :
12411 : : /* Strip out all handled components that produce invariant
12412 : : offsets. */
12413 : :
12414 : : const_tree
12415 : 5862741706 : strip_invariant_refs (const_tree op)
12416 : : {
12417 : 6819564466 : while (handled_component_p (op))
12418 : : {
12419 : 968557311 : switch (TREE_CODE (op))
12420 : : {
12421 : 159913943 : case ARRAY_REF:
12422 : 159913943 : case ARRAY_RANGE_REF:
12423 : 159913943 : if (!is_gimple_constant (TREE_OPERAND (op, 1))
12424 : 149837710 : || TREE_OPERAND (op, 2) != NULL_TREE
12425 : 148311377 : || TREE_OPERAND (op, 3) != NULL_TREE)
12426 : : return NULL;
12427 : : break;
12428 : :
12429 : 808344174 : case COMPONENT_REF:
12430 : 808344174 : if (TREE_OPERAND (op, 2) != NULL_TREE)
12431 : : return NULL;
12432 : : break;
12433 : :
12434 : 956822760 : default:;
12435 : : }
12436 : 956822760 : op = TREE_OPERAND (op, 0);
12437 : : }
12438 : :
12439 : : return op;
12440 : : }
12441 : :
12442 : : /* Strip handled components with zero offset from OP. */
12443 : :
12444 : : tree
12445 : 571933 : strip_zero_offset_components (tree op)
12446 : : {
12447 : 571933 : while (TREE_CODE (op) == COMPONENT_REF
12448 : 443269 : && integer_zerop (DECL_FIELD_OFFSET (TREE_OPERAND (op, 1)))
12449 : 1123236 : && integer_zerop (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (op, 1))))
12450 : 181062 : op = TREE_OPERAND (op, 0);
12451 : 571933 : return op;
12452 : : }
12453 : :
12454 : : static GTY(()) tree gcc_eh_personality_decl;
12455 : :
12456 : : /* Return the GCC personality function decl. */
12457 : :
12458 : : tree
12459 : 395 : lhd_gcc_personality (void)
12460 : : {
12461 : 395 : if (!gcc_eh_personality_decl)
12462 : 153 : gcc_eh_personality_decl = build_personality_function ("gcc");
12463 : 395 : return gcc_eh_personality_decl;
12464 : : }
12465 : :
12466 : : /* TARGET is a call target of GIMPLE call statement
12467 : : (obtained by gimple_call_fn). Return true if it is
12468 : : OBJ_TYPE_REF representing an virtual call of C++ method.
12469 : : (As opposed to OBJ_TYPE_REF representing objc calls
12470 : : through a cast where middle-end devirtualization machinery
12471 : : can't apply.) FOR_DUMP_P is true when being called from
12472 : : the dump routines. */
12473 : :
12474 : : bool
12475 : 27947872 : virtual_method_call_p (const_tree target, bool for_dump_p)
12476 : : {
12477 : 27947872 : if (TREE_CODE (target) != OBJ_TYPE_REF)
12478 : : return false;
12479 : 1200296 : tree t = TREE_TYPE (target);
12480 : 1200296 : gcc_checking_assert (TREE_CODE (t) == POINTER_TYPE);
12481 : 1200296 : t = TREE_TYPE (t);
12482 : 1200296 : if (TREE_CODE (t) == FUNCTION_TYPE)
12483 : : return false;
12484 : 1199208 : gcc_checking_assert (TREE_CODE (t) == METHOD_TYPE);
12485 : : /* If we do not have BINFO associated, it means that type was built
12486 : : without devirtualization enabled. Do not consider this a virtual
12487 : : call. */
12488 : 1199208 : if (!TYPE_BINFO (obj_type_ref_class (target, for_dump_p)))
12489 : : return false;
12490 : : return true;
12491 : : }
12492 : :
12493 : : /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
12494 : :
12495 : : static tree
12496 : 108 : lookup_binfo_at_offset (tree binfo, tree type, HOST_WIDE_INT pos)
12497 : : {
12498 : 108 : unsigned int i;
12499 : 108 : tree base_binfo, b;
12500 : :
12501 : 124 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12502 : 108 : if (pos == tree_to_shwi (BINFO_OFFSET (base_binfo))
12503 : 108 : && types_same_for_odr (TREE_TYPE (base_binfo), type))
12504 : : return base_binfo;
12505 : 70 : else if ((b = lookup_binfo_at_offset (base_binfo, type, pos)) != NULL)
12506 : : return b;
12507 : : return NULL;
12508 : : }
12509 : :
12510 : : /* Try to find a base info of BINFO that would have its field decl at offset
12511 : : OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12512 : : found, return, otherwise return NULL_TREE. */
12513 : :
12514 : : tree
12515 : 370298 : get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
12516 : : {
12517 : 370298 : tree type = BINFO_TYPE (binfo);
12518 : :
12519 : 1029260 : while (true)
12520 : : {
12521 : 699779 : HOST_WIDE_INT pos, size;
12522 : 699779 : tree fld;
12523 : 699779 : int i;
12524 : :
12525 : 699779 : if (types_same_for_odr (type, expected_type))
12526 : 370298 : return binfo;
12527 : 329481 : if (maybe_lt (offset, 0))
12528 : : return NULL_TREE;
12529 : :
12530 : 2011780 : for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
12531 : : {
12532 : 2011780 : if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld))
12533 : 1682096 : continue;
12534 : :
12535 : 329684 : pos = int_bit_position (fld);
12536 : 329684 : size = tree_to_uhwi (DECL_SIZE (fld));
12537 : 2011983 : if (known_in_range_p (offset, pos, size))
12538 : : break;
12539 : : }
12540 : 329481 : if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
12541 : : return NULL_TREE;
12542 : :
12543 : : /* Offset 0 indicates the primary base, whose vtable contents are
12544 : : represented in the binfo for the derived class. */
12545 : 329481 : else if (maybe_ne (offset, 0))
12546 : : {
12547 : 206 : tree found_binfo = NULL, base_binfo;
12548 : : /* Offsets in BINFO are in bytes relative to the whole structure
12549 : : while POS is in bits relative to the containing field. */
12550 : 206 : int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos
12551 : 206 : / BITS_PER_UNIT);
12552 : :
12553 : 392 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12554 : 354 : if (tree_to_shwi (BINFO_OFFSET (base_binfo)) == binfo_offset
12555 : 354 : && types_same_for_odr (TREE_TYPE (base_binfo), TREE_TYPE (fld)))
12556 : : {
12557 : : found_binfo = base_binfo;
12558 : : break;
12559 : : }
12560 : 206 : if (found_binfo)
12561 : : binfo = found_binfo;
12562 : : else
12563 : 38 : binfo = lookup_binfo_at_offset (binfo, TREE_TYPE (fld),
12564 : : binfo_offset);
12565 : : }
12566 : :
12567 : 329481 : type = TREE_TYPE (fld);
12568 : 329481 : offset -= pos;
12569 : 329481 : }
12570 : : }
12571 : :
12572 : : /* PR 84195: Replace control characters in "unescaped" with their
12573 : : escaped equivalents. Allow newlines if -fmessage-length has
12574 : : been set to a non-zero value. This is done here, rather than
12575 : : where the attribute is recorded as the message length can
12576 : : change between these two locations. */
12577 : :
12578 : : void
12579 : 134367 : escaped_string::escape (const char *unescaped)
12580 : : {
12581 : 134367 : char *escaped;
12582 : 134367 : size_t i, new_i, len;
12583 : :
12584 : 134367 : if (m_owned)
12585 : 8 : free (m_str);
12586 : :
12587 : 134367 : m_str = const_cast<char *> (unescaped);
12588 : 134367 : m_owned = false;
12589 : :
12590 : 134367 : if (unescaped == NULL || *unescaped == 0)
12591 : : return;
12592 : :
12593 : 134359 : len = strlen (unescaped);
12594 : 134359 : escaped = NULL;
12595 : 134359 : new_i = 0;
12596 : :
12597 : 3928740 : for (i = 0; i < len; i++)
12598 : : {
12599 : 3794381 : char c = unescaped[i];
12600 : :
12601 : 3794381 : if (!ISCNTRL (c))
12602 : : {
12603 : 3794296 : if (escaped)
12604 : 33 : escaped[new_i++] = c;
12605 : 3794296 : continue;
12606 : : }
12607 : :
12608 : 85 : if (c != '\n' || !pp_is_wrapping_line (global_dc->get_reference_printer ()))
12609 : : {
12610 : 77 : if (escaped == NULL)
12611 : : {
12612 : : /* We only allocate space for a new string if we
12613 : : actually encounter a control character that
12614 : : needs replacing. */
12615 : 19 : escaped = (char *) xmalloc (len * 2 + 1);
12616 : 19 : strncpy (escaped, unescaped, i);
12617 : 19 : new_i = i;
12618 : : }
12619 : :
12620 : 77 : escaped[new_i++] = '\\';
12621 : :
12622 : 77 : switch (c)
12623 : : {
12624 : 8 : case '\a': escaped[new_i++] = 'a'; break;
12625 : 8 : case '\b': escaped[new_i++] = 'b'; break;
12626 : 8 : case '\f': escaped[new_i++] = 'f'; break;
12627 : 15 : case '\n': escaped[new_i++] = 'n'; break;
12628 : 15 : case '\r': escaped[new_i++] = 'r'; break;
12629 : 15 : case '\t': escaped[new_i++] = 't'; break;
12630 : 8 : case '\v': escaped[new_i++] = 'v'; break;
12631 : 0 : default: escaped[new_i++] = '?'; break;
12632 : : }
12633 : : }
12634 : 8 : else if (escaped)
12635 : 4 : escaped[new_i++] = c;
12636 : : }
12637 : :
12638 : 134359 : if (escaped)
12639 : : {
12640 : 19 : escaped[new_i] = 0;
12641 : 19 : m_str = escaped;
12642 : 19 : m_owned = true;
12643 : : }
12644 : : }
12645 : :
12646 : : /* Warn about a use of an identifier which was marked deprecated. Returns
12647 : : whether a warning was given. */
12648 : :
12649 : : bool
12650 : 1312355 : warn_deprecated_use (tree node, tree attr)
12651 : : {
12652 : 1312355 : escaped_string msg;
12653 : :
12654 : 1312355 : if (node == 0 || !warn_deprecated_decl)
12655 : : return false;
12656 : :
12657 : 1307154 : if (!attr)
12658 : : {
12659 : 1193974 : if (DECL_P (node))
12660 : 1193846 : attr = DECL_ATTRIBUTES (node);
12661 : 128 : else if (TYPE_P (node))
12662 : : {
12663 : 128 : tree decl = TYPE_STUB_DECL (node);
12664 : 128 : if (decl)
12665 : 104 : attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
12666 : 24 : else if ((decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node)))
12667 : : != NULL_TREE)
12668 : : {
12669 : 6 : node = TREE_TYPE (decl);
12670 : 6 : attr = TYPE_ATTRIBUTES (node);
12671 : : }
12672 : : }
12673 : : }
12674 : :
12675 : 1193974 : if (attr)
12676 : 134054 : attr = lookup_attribute ("deprecated", attr);
12677 : :
12678 : 134054 : if (attr)
12679 : 134048 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12680 : :
12681 : 1307154 : bool w = false;
12682 : 1307154 : if (DECL_P (node))
12683 : : {
12684 : 1307016 : auto_diagnostic_group d;
12685 : 1307016 : if (msg)
12686 : 133999 : w = warning (OPT_Wdeprecated_declarations,
12687 : : "%qD is deprecated: %s", node, (const char *) msg);
12688 : : else
12689 : 1173017 : w = warning (OPT_Wdeprecated_declarations,
12690 : : "%qD is deprecated", node);
12691 : 1307016 : if (w)
12692 : 786 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12693 : 1307016 : }
12694 : 138 : else if (TYPE_P (node))
12695 : : {
12696 : 138 : tree what = NULL_TREE;
12697 : 138 : tree decl = TYPE_STUB_DECL (node);
12698 : :
12699 : 138 : if (TYPE_NAME (node))
12700 : : {
12701 : 133 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12702 : 10 : what = TYPE_NAME (node);
12703 : 123 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12704 : 123 : && DECL_NAME (TYPE_NAME (node)))
12705 : 123 : what = DECL_NAME (TYPE_NAME (node));
12706 : : }
12707 : :
12708 : 138 : auto_diagnostic_group d;
12709 : 138 : if (what)
12710 : : {
12711 : 133 : if (msg)
12712 : 47 : w = warning (OPT_Wdeprecated_declarations,
12713 : : "%qE is deprecated: %s", what, (const char *) msg);
12714 : : else
12715 : 86 : w = warning (OPT_Wdeprecated_declarations,
12716 : : "%qE is deprecated", what);
12717 : : }
12718 : : else
12719 : : {
12720 : 5 : if (msg)
12721 : 2 : w = warning (OPT_Wdeprecated_declarations,
12722 : : "type is deprecated: %s", (const char *) msg);
12723 : : else
12724 : 3 : w = warning (OPT_Wdeprecated_declarations,
12725 : : "type is deprecated");
12726 : : }
12727 : :
12728 : 138 : if (w && decl)
12729 : 111 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12730 : 138 : }
12731 : :
12732 : : return w;
12733 : 1312355 : }
12734 : :
12735 : : /* Error out with an identifier which was marked 'unavailable'. */
12736 : : void
12737 : 364 : error_unavailable_use (tree node, tree attr)
12738 : : {
12739 : 364 : escaped_string msg;
12740 : :
12741 : 364 : if (node == 0)
12742 : 0 : return;
12743 : :
12744 : 364 : if (!attr)
12745 : : {
12746 : 354 : if (DECL_P (node))
12747 : 294 : attr = DECL_ATTRIBUTES (node);
12748 : 60 : else if (TYPE_P (node))
12749 : : {
12750 : 60 : tree decl = TYPE_STUB_DECL (node);
12751 : 60 : if (decl)
12752 : 51 : attr = lookup_attribute ("unavailable",
12753 : 51 : TYPE_ATTRIBUTES (TREE_TYPE (decl)));
12754 : : }
12755 : : }
12756 : :
12757 : 354 : if (attr)
12758 : 152 : attr = lookup_attribute ("unavailable", attr);
12759 : :
12760 : 152 : if (attr)
12761 : 152 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12762 : :
12763 : 364 : if (DECL_P (node))
12764 : : {
12765 : 294 : auto_diagnostic_group d;
12766 : 294 : if (msg)
12767 : 117 : error ("%qD is unavailable: %s", node, (const char *) msg);
12768 : : else
12769 : 177 : error ("%qD is unavailable", node);
12770 : 294 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12771 : 294 : }
12772 : 70 : else if (TYPE_P (node))
12773 : : {
12774 : 70 : tree what = NULL_TREE;
12775 : 70 : tree decl = TYPE_STUB_DECL (node);
12776 : :
12777 : 70 : if (TYPE_NAME (node))
12778 : : {
12779 : 66 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12780 : 4 : what = TYPE_NAME (node);
12781 : 62 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12782 : 62 : && DECL_NAME (TYPE_NAME (node)))
12783 : 62 : what = DECL_NAME (TYPE_NAME (node));
12784 : : }
12785 : :
12786 : 70 : auto_diagnostic_group d;
12787 : 70 : if (what)
12788 : : {
12789 : 66 : if (msg)
12790 : 33 : error ("%qE is unavailable: %s", what, (const char *) msg);
12791 : : else
12792 : 33 : error ("%qE is unavailable", what);
12793 : : }
12794 : : else
12795 : : {
12796 : 4 : if (msg)
12797 : 2 : error ("type is unavailable: %s", (const char *) msg);
12798 : : else
12799 : 2 : error ("type is unavailable");
12800 : : }
12801 : :
12802 : 70 : if (decl)
12803 : 52 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12804 : 70 : }
12805 : 364 : }
12806 : :
12807 : : /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12808 : : somewhere in it. */
12809 : :
12810 : : bool
12811 : 5738823 : contains_bitfld_component_ref_p (const_tree ref)
12812 : : {
12813 : 11674017 : while (handled_component_p (ref))
12814 : : {
12815 : 5961729 : if (TREE_CODE (ref) == COMPONENT_REF
12816 : 5961729 : && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
12817 : : return true;
12818 : 5935194 : ref = TREE_OPERAND (ref, 0);
12819 : : }
12820 : :
12821 : : return false;
12822 : : }
12823 : :
12824 : : /* Try to determine whether a TRY_CATCH expression can fall through.
12825 : : This is a subroutine of block_may_fallthru. */
12826 : :
12827 : : static bool
12828 : 1 : try_catch_may_fallthru (const_tree stmt)
12829 : : {
12830 : 1 : tree_stmt_iterator i;
12831 : :
12832 : : /* If the TRY block can fall through, the whole TRY_CATCH can
12833 : : fall through. */
12834 : 1 : if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
12835 : : return true;
12836 : :
12837 : 1 : switch (TREE_CODE (TREE_OPERAND (stmt, 1)))
12838 : : {
12839 : 0 : case CATCH_EXPR:
12840 : : /* See below. */
12841 : 0 : return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1)));
12842 : :
12843 : 0 : case EH_FILTER_EXPR:
12844 : : /* See below. */
12845 : 0 : return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1)));
12846 : :
12847 : 0 : case STATEMENT_LIST:
12848 : 0 : break;
12849 : :
12850 : : default:
12851 : : /* See below. */
12852 : : return false;
12853 : : }
12854 : :
12855 : 0 : i = tsi_start (TREE_OPERAND (stmt, 1));
12856 : 0 : switch (TREE_CODE (tsi_stmt (i)))
12857 : : {
12858 : : case CATCH_EXPR:
12859 : : /* We expect to see a sequence of CATCH_EXPR trees, each with a
12860 : : catch expression and a body. The whole TRY_CATCH may fall
12861 : : through iff any of the catch bodies falls through. */
12862 : 0 : for (; !tsi_end_p (i); tsi_next (&i))
12863 : : {
12864 : 0 : if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
12865 : : return true;
12866 : : }
12867 : : return false;
12868 : :
12869 : 0 : case EH_FILTER_EXPR:
12870 : : /* The exception filter expression only matters if there is an
12871 : : exception. If the exception does not match EH_FILTER_TYPES,
12872 : : we will execute EH_FILTER_FAILURE, and we will fall through
12873 : : if that falls through. If the exception does match
12874 : : EH_FILTER_TYPES, the stack unwinder will continue up the
12875 : : stack, so we will not fall through. We don't know whether we
12876 : : will throw an exception which matches EH_FILTER_TYPES or not,
12877 : : so we just ignore EH_FILTER_TYPES and assume that we might
12878 : : throw an exception which doesn't match. */
12879 : 0 : return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
12880 : :
12881 : : default:
12882 : : /* This case represents statements to be executed when an
12883 : : exception occurs. Those statements are implicitly followed
12884 : : by a RESX statement to resume execution after the exception.
12885 : : So in this case the TRY_CATCH never falls through. */
12886 : : return false;
12887 : : }
12888 : : }
12889 : :
12890 : : /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12891 : : need not be 100% accurate; simply be conservative and return true if we
12892 : : don't know. This is used only to avoid stupidly generating extra code.
12893 : : If we're wrong, we'll just delete the extra code later. */
12894 : :
12895 : : bool
12896 : 6451906 : block_may_fallthru (const_tree block)
12897 : : {
12898 : : /* This CONST_CAST is okay because expr_last returns its argument
12899 : : unmodified and we assign it to a const_tree. */
12900 : 7600645 : const_tree stmt = expr_last (CONST_CAST_TREE (block));
12901 : :
12902 : 7600645 : switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
12903 : : {
12904 : : case GOTO_EXPR:
12905 : : case RETURN_EXPR:
12906 : : /* Easy cases. If the last statement of the block implies
12907 : : control transfer, then we can't fall through. */
12908 : : return false;
12909 : :
12910 : 8 : case SWITCH_EXPR:
12911 : : /* If there is a default: label or case labels cover all possible
12912 : : SWITCH_COND values, then the SWITCH_EXPR will transfer control
12913 : : to some case label in all cases and all we care is whether the
12914 : : SWITCH_BODY falls through. */
12915 : 8 : if (SWITCH_ALL_CASES_P (stmt))
12916 : 7 : return block_may_fallthru (SWITCH_BODY (stmt));
12917 : : return true;
12918 : :
12919 : 19810 : case COND_EXPR:
12920 : 19810 : if (block_may_fallthru (COND_EXPR_THEN (stmt)))
12921 : : return true;
12922 : 2798 : return block_may_fallthru (COND_EXPR_ELSE (stmt));
12923 : :
12924 : 578142 : case BIND_EXPR:
12925 : 578142 : return block_may_fallthru (BIND_EXPR_BODY (stmt));
12926 : :
12927 : 1 : case TRY_CATCH_EXPR:
12928 : 1 : return try_catch_may_fallthru (stmt);
12929 : :
12930 : 141 : case TRY_FINALLY_EXPR:
12931 : : /* The finally clause is always executed after the try clause,
12932 : : so if it does not fall through, then the try-finally will not
12933 : : fall through. Otherwise, if the try clause does not fall
12934 : : through, then when the finally clause falls through it will
12935 : : resume execution wherever the try clause was going. So the
12936 : : whole try-finally will only fall through if both the try
12937 : : clause and the finally clause fall through. */
12938 : 141 : return (block_may_fallthru (TREE_OPERAND (stmt, 0))
12939 : 141 : && block_may_fallthru (TREE_OPERAND (stmt, 1)));
12940 : :
12941 : 0 : case EH_ELSE_EXPR:
12942 : 0 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
12943 : :
12944 : 88975 : case MODIFY_EXPR:
12945 : 88975 : if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
12946 : 1554 : stmt = TREE_OPERAND (stmt, 1);
12947 : : else
12948 : : return true;
12949 : : /* FALLTHRU */
12950 : :
12951 : 414711 : case CALL_EXPR:
12952 : : /* Functions that do not return do not fall through. */
12953 : 414711 : return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
12954 : :
12955 : 567782 : case CLEANUP_POINT_EXPR:
12956 : 567782 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
12957 : :
12958 : 10 : case TARGET_EXPR:
12959 : 10 : return block_may_fallthru (TREE_OPERAND (stmt, 1));
12960 : :
12961 : : case ERROR_MARK:
12962 : : return true;
12963 : :
12964 : 4117731 : default:
12965 : 4117731 : return lang_hooks.block_may_fallthru (stmt);
12966 : : }
12967 : : }
12968 : :
12969 : : /* True if we are using EH to handle cleanups. */
12970 : : static bool using_eh_for_cleanups_flag = false;
12971 : :
12972 : : /* This routine is called from front ends to indicate eh should be used for
12973 : : cleanups. */
12974 : : void
12975 : 122163 : using_eh_for_cleanups (void)
12976 : : {
12977 : 122163 : using_eh_for_cleanups_flag = true;
12978 : 122163 : }
12979 : :
12980 : : /* Query whether EH is used for cleanups. */
12981 : : bool
12982 : 1683985 : using_eh_for_cleanups_p (void)
12983 : : {
12984 : 1683985 : return using_eh_for_cleanups_flag;
12985 : : }
12986 : :
12987 : : /* Wrapper for tree_code_name to ensure that tree code is valid */
12988 : : const char *
12989 : 14435475088 : get_tree_code_name (enum tree_code code)
12990 : : {
12991 : 14435475088 : const char *invalid = "<invalid tree code>";
12992 : :
12993 : : /* The tree_code enum promotes to signed, but we could be getting
12994 : : invalid values, so force an unsigned comparison. */
12995 : 14435475088 : if (unsigned (code) >= MAX_TREE_CODES)
12996 : : {
12997 : 0 : if ((unsigned)code == 0xa5a5)
12998 : : return "ggc_freed";
12999 : 0 : return invalid;
13000 : : }
13001 : :
13002 : 14435475088 : return tree_code_name[code];
13003 : : }
13004 : :
13005 : : /* Drops the TREE_OVERFLOW flag from T. */
13006 : :
13007 : : tree
13008 : 35468 : drop_tree_overflow (tree t)
13009 : : {
13010 : 35468 : gcc_checking_assert (TREE_OVERFLOW (t));
13011 : :
13012 : : /* For tree codes with a sharing machinery re-build the result. */
13013 : 35468 : if (poly_int_tree_p (t))
13014 : 35456 : return wide_int_to_tree (TREE_TYPE (t), wi::to_poly_wide (t));
13015 : :
13016 : : /* For VECTOR_CST, remove the overflow bits from the encoded elements
13017 : : and canonicalize the result. */
13018 : 12 : if (TREE_CODE (t) == VECTOR_CST)
13019 : : {
13020 : 0 : tree_vector_builder builder;
13021 : 0 : builder.new_unary_operation (TREE_TYPE (t), t, true);
13022 : 0 : unsigned int count = builder.encoded_nelts ();
13023 : 0 : for (unsigned int i = 0; i < count; ++i)
13024 : : {
13025 : 0 : tree elt = VECTOR_CST_ELT (t, i);
13026 : 0 : if (TREE_OVERFLOW (elt))
13027 : 0 : elt = drop_tree_overflow (elt);
13028 : 0 : builder.quick_push (elt);
13029 : : }
13030 : 0 : return builder.build ();
13031 : 0 : }
13032 : :
13033 : : /* Otherwise, as all tcc_constants are possibly shared, copy the node
13034 : : and drop the flag. */
13035 : 12 : t = copy_node (t);
13036 : 12 : TREE_OVERFLOW (t) = 0;
13037 : :
13038 : : /* For constants that contain nested constants, drop the flag
13039 : : from those as well. */
13040 : 12 : if (TREE_CODE (t) == COMPLEX_CST)
13041 : : {
13042 : 12 : if (TREE_OVERFLOW (TREE_REALPART (t)))
13043 : 12 : TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t));
13044 : 12 : if (TREE_OVERFLOW (TREE_IMAGPART (t)))
13045 : 0 : TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t));
13046 : : }
13047 : :
13048 : : return t;
13049 : : }
13050 : :
13051 : : /* Given a memory reference expression T, return its base address.
13052 : : The base address of a memory reference expression is the main
13053 : : object being referenced. For instance, the base address for
13054 : : 'array[i].fld[j]' is 'array'. You can think of this as stripping
13055 : : away the offset part from a memory address.
13056 : :
13057 : : This function calls handled_component_p to strip away all the inner
13058 : : parts of the memory reference until it reaches the base object. */
13059 : :
13060 : : tree
13061 : 3179346015 : get_base_address (tree t)
13062 : : {
13063 : 3179346015 : if (TREE_CODE (t) == WITH_SIZE_EXPR)
13064 : 971 : t = TREE_OPERAND (t, 0);
13065 : 3940670948 : while (handled_component_p (t))
13066 : 761324933 : t = TREE_OPERAND (t, 0);
13067 : :
13068 : 3179346015 : if ((TREE_CODE (t) == MEM_REF
13069 : 3179346015 : || TREE_CODE (t) == TARGET_MEM_REF)
13070 : 3179346015 : && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
13071 : 156349407 : t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
13072 : :
13073 : 3179346015 : return t;
13074 : : }
13075 : :
13076 : : /* Return a tree of sizetype representing the size, in bytes, of the element
13077 : : of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13078 : :
13079 : : tree
13080 : 785173483 : array_ref_element_size (tree exp)
13081 : : {
13082 : 785173483 : tree aligned_size = TREE_OPERAND (exp, 3);
13083 : 785173483 : tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
13084 : 785173483 : location_t loc = EXPR_LOCATION (exp);
13085 : :
13086 : : /* If a size was specified in the ARRAY_REF, it's the size measured
13087 : : in alignment units of the element type. So multiply by that value. */
13088 : 785173483 : if (aligned_size)
13089 : : {
13090 : : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13091 : : sizetype from another type of the same width and signedness. */
13092 : 376681 : if (TREE_TYPE (aligned_size) != sizetype)
13093 : 2026 : aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
13094 : 376681 : return size_binop_loc (loc, MULT_EXPR, aligned_size,
13095 : 376681 : size_int (TYPE_ALIGN_UNIT (elmt_type)));
13096 : : }
13097 : :
13098 : : /* Otherwise, take the size from that of the element type. Substitute
13099 : : any PLACEHOLDER_EXPR that we have. */
13100 : : else
13101 : 784796802 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
13102 : : }
13103 : :
13104 : : /* Return a tree representing the lower bound of the array mentioned in
13105 : : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13106 : :
13107 : : tree
13108 : 1083079690 : array_ref_low_bound (tree exp)
13109 : : {
13110 : 1083079690 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13111 : :
13112 : : /* If a lower bound is specified in EXP, use it. */
13113 : 1083079690 : if (TREE_OPERAND (exp, 2))
13114 : 1917194 : return TREE_OPERAND (exp, 2);
13115 : :
13116 : : /* Otherwise, if there is a domain type and it has a lower bound, use it,
13117 : : substituting for a PLACEHOLDER_EXPR as needed. */
13118 : 1081162496 : if (domain_type && TYPE_MIN_VALUE (domain_type))
13119 : 1080243576 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
13120 : :
13121 : : /* Otherwise, return a zero of the appropriate type. */
13122 : 918920 : tree idxtype = TREE_TYPE (TREE_OPERAND (exp, 1));
13123 : 918920 : return (idxtype == error_mark_node
13124 : 918920 : ? integer_zero_node : build_int_cst (idxtype, 0));
13125 : : }
13126 : :
13127 : : /* Return a tree representing the upper bound of the array mentioned in
13128 : : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13129 : :
13130 : : tree
13131 : 251831409 : array_ref_up_bound (tree exp)
13132 : : {
13133 : 251831409 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13134 : :
13135 : : /* If there is a domain type and it has an upper bound, use it, substituting
13136 : : for a PLACEHOLDER_EXPR as needed. */
13137 : 251831409 : if (domain_type && TYPE_MAX_VALUE (domain_type))
13138 : 251045256 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
13139 : :
13140 : : /* Otherwise fail. */
13141 : : return NULL_TREE;
13142 : : }
13143 : :
13144 : : /* Returns true if REF is an array reference, a component reference,
13145 : : or a memory reference to an array whose actual size might be larger
13146 : : than its upper bound implies, there are multiple cases:
13147 : : A. a ref to a flexible array member at the end of a structure;
13148 : : B. a ref to an array with a different type against the original decl;
13149 : : for example:
13150 : :
13151 : : short a[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
13152 : : (*((char(*)[16])&a[0]))[i+8]
13153 : :
13154 : : C. a ref to an array that was passed as a parameter;
13155 : : for example:
13156 : :
13157 : : int test (uint8_t *p, uint32_t t[1][1], int n) {
13158 : : for (int i = 0; i < 4; i++, p++)
13159 : : t[i][0] = ...;
13160 : :
13161 : : If non-null, set IS_TRAILING_ARRAY to true if the ref is the above case A.
13162 : : */
13163 : :
13164 : : bool
13165 : 77507940 : array_ref_flexible_size_p (tree ref, bool *is_trailing_array /* = NULL */)
13166 : : {
13167 : : /* The TYPE for this array referece. */
13168 : 77507940 : tree atype = NULL_TREE;
13169 : : /* The FIELD_DECL for the array field in the containing structure. */
13170 : 77507940 : tree afield_decl = NULL_TREE;
13171 : : /* Whether this array is the trailing array of a structure. */
13172 : 77507940 : bool is_trailing_array_tmp = false;
13173 : 77507940 : if (!is_trailing_array)
13174 : 77424708 : is_trailing_array = &is_trailing_array_tmp;
13175 : :
13176 : 77507940 : if (TREE_CODE (ref) == ARRAY_REF
13177 : 77507940 : || TREE_CODE (ref) == ARRAY_RANGE_REF)
13178 : : {
13179 : 77273712 : atype = TREE_TYPE (TREE_OPERAND (ref, 0));
13180 : 77273712 : ref = TREE_OPERAND (ref, 0);
13181 : : }
13182 : 234228 : else if (TREE_CODE (ref) == COMPONENT_REF
13183 : 234228 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE)
13184 : : {
13185 : 170485 : atype = TREE_TYPE (TREE_OPERAND (ref, 1));
13186 : 170485 : afield_decl = TREE_OPERAND (ref, 1);
13187 : : }
13188 : 63743 : else if (TREE_CODE (ref) == MEM_REF)
13189 : : {
13190 : 8301 : tree arg = TREE_OPERAND (ref, 0);
13191 : 8301 : if (TREE_CODE (arg) == ADDR_EXPR)
13192 : 8301 : arg = TREE_OPERAND (arg, 0);
13193 : 8301 : tree argtype = TREE_TYPE (arg);
13194 : 8301 : if (TREE_CODE (argtype) == RECORD_TYPE)
13195 : : {
13196 : 174 : if (tree fld = last_field (argtype))
13197 : : {
13198 : 174 : atype = TREE_TYPE (fld);
13199 : 174 : afield_decl = fld;
13200 : 174 : if (TREE_CODE (atype) != ARRAY_TYPE)
13201 : : return false;
13202 : 174 : if (VAR_P (arg) && DECL_SIZE (fld))
13203 : : return false;
13204 : : }
13205 : : else
13206 : : return false;
13207 : : }
13208 : : else
13209 : : return false;
13210 : : }
13211 : : else
13212 : : return false;
13213 : :
13214 : 77444322 : if (TREE_CODE (ref) == STRING_CST)
13215 : : return false;
13216 : :
13217 : : tree ref_to_array = ref;
13218 : 94080724 : while (handled_component_p (ref))
13219 : : {
13220 : : /* If the reference chain contains a component reference to a
13221 : : non-union type and there follows another field the reference
13222 : : is not at the end of a structure. */
13223 : 19697944 : if (TREE_CODE (ref) == COMPONENT_REF)
13224 : : {
13225 : 18582412 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
13226 : : {
13227 : 17338082 : tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
13228 : 26768247 : while (nextf && TREE_CODE (nextf) != FIELD_DECL)
13229 : 9430165 : nextf = DECL_CHAIN (nextf);
13230 : : if (nextf)
13231 : : return false;
13232 : : }
13233 : : }
13234 : : /* If we have a multi-dimensional array we do not consider
13235 : : a non-innermost dimension as flex array if the whole
13236 : : multi-dimensional array is at struct end.
13237 : : Same for an array of aggregates with a trailing array
13238 : : member. */
13239 : 1115532 : else if (TREE_CODE (ref) == ARRAY_REF)
13240 : : return false;
13241 : 181689 : else if (TREE_CODE (ref) == ARRAY_RANGE_REF)
13242 : : ;
13243 : : /* If we view an underlying object as sth else then what we
13244 : : gathered up to now is what we have to rely on. */
13245 : 181679 : else if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
13246 : : break;
13247 : : else
13248 : 0 : gcc_unreachable ();
13249 : :
13250 : 16637701 : ref = TREE_OPERAND (ref, 0);
13251 : : }
13252 : :
13253 : 74564459 : gcc_assert (!afield_decl
13254 : : || (afield_decl && TREE_CODE (afield_decl) == FIELD_DECL));
13255 : :
13256 : : /* The array now is at struct end. Treat flexible array member as
13257 : : always subject to extend, even into just padding constrained by
13258 : : an underlying decl. */
13259 : 74564459 : if (! TYPE_SIZE (atype)
13260 : 72274043 : || ! TYPE_DOMAIN (atype)
13261 : 146838502 : || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13262 : : {
13263 : 2296013 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13264 : 2377838 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13265 : : }
13266 : :
13267 : : /* If the reference is based on a declared entity, the size of the array
13268 : : is constrained by its given domain. (Do not trust commons PR/69368). */
13269 : 72268446 : ref = get_base_address (ref);
13270 : 72268446 : if (ref
13271 : 72268446 : && DECL_P (ref)
13272 : 62330071 : && !(flag_unconstrained_commons
13273 : 14 : && VAR_P (ref) && DECL_COMMON (ref))
13274 : 62330057 : && DECL_SIZE_UNIT (ref)
13275 : 134598126 : && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
13276 : : {
13277 : : /* If the object itself is the array it is not at struct end. */
13278 : 62329652 : if (DECL_P (ref_to_array))
13279 : : return false;
13280 : :
13281 : : /* Check whether the array domain covers all of the available
13282 : : padding. */
13283 : 15674726 : poly_int64 offset;
13284 : 15674726 : if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
13285 : 15673390 : || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST
13286 : 31325305 : || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST)
13287 : : {
13288 : 24147 : *is_trailing_array
13289 : 24147 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13290 : 24190 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13291 : : }
13292 : 15650579 : if (! get_addr_base_and_unit_offset (ref_to_array, &offset))
13293 : : {
13294 : 2758 : *is_trailing_array
13295 : 2758 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13296 : 2758 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13297 : : }
13298 : :
13299 : : /* If at least one extra element fits it is a flexarray. */
13300 : 15647821 : if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13301 : : - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype)))
13302 : : + 2)
13303 : : * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype))),
13304 : : wi::to_offset (DECL_SIZE_UNIT (ref)) - offset))
13305 : : {
13306 : 584257 : *is_trailing_array
13307 : 584257 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13308 : 596445 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13309 : : }
13310 : :
13311 : : return false;
13312 : : }
13313 : :
13314 : 9938794 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13315 : 9953590 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13316 : : }
13317 : :
13318 : :
13319 : : /* Return a tree representing the offset, in bytes, of the field referenced
13320 : : by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
13321 : :
13322 : : tree
13323 : 2646867495 : component_ref_field_offset (tree exp)
13324 : : {
13325 : 2646867495 : tree aligned_offset = TREE_OPERAND (exp, 2);
13326 : 2646867495 : tree field = TREE_OPERAND (exp, 1);
13327 : 2646867495 : location_t loc = EXPR_LOCATION (exp);
13328 : :
13329 : : /* If an offset was specified in the COMPONENT_REF, it's the offset measured
13330 : : in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
13331 : : value. */
13332 : 2646867495 : if (aligned_offset)
13333 : : {
13334 : : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13335 : : sizetype from another type of the same width and signedness. */
13336 : 11997 : if (TREE_TYPE (aligned_offset) != sizetype)
13337 : 135 : aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
13338 : 11997 : return size_binop_loc (loc, MULT_EXPR, aligned_offset,
13339 : 11997 : size_int (DECL_OFFSET_ALIGN (field)
13340 : : / BITS_PER_UNIT));
13341 : : }
13342 : :
13343 : : /* Otherwise, take the offset from that of the field. Substitute
13344 : : any PLACEHOLDER_EXPR that we have. */
13345 : : else
13346 : 2646855498 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
13347 : : }
13348 : :
13349 : : /* Given the initializer INIT, return the initializer for the field
13350 : : DECL if it exists, otherwise null. Used to obtain the initializer
13351 : : for a flexible array member and determine its size. */
13352 : :
13353 : : static tree
13354 : 1269 : get_initializer_for (tree init, tree decl)
13355 : : {
13356 : 1269 : STRIP_NOPS (init);
13357 : :
13358 : 1269 : tree fld, fld_init;
13359 : 1269 : unsigned HOST_WIDE_INT i;
13360 : 3575 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), i, fld, fld_init)
13361 : : {
13362 : 1928 : if (decl == fld)
13363 : : return fld_init;
13364 : :
13365 : 1037 : if (TREE_CODE (fld) == CONSTRUCTOR)
13366 : : {
13367 : 0 : fld_init = get_initializer_for (fld_init, decl);
13368 : 0 : if (fld_init)
13369 : : return fld_init;
13370 : : }
13371 : : }
13372 : :
13373 : : return NULL_TREE;
13374 : : }
13375 : :
13376 : : /* Determines the special array member type for the array reference REF. */
13377 : : special_array_member
13378 : 255762 : component_ref_sam_type (tree ref)
13379 : : {
13380 : 255762 : special_array_member sam_type = special_array_member::none;
13381 : :
13382 : 255762 : tree member = TREE_OPERAND (ref, 1);
13383 : 255762 : tree memsize = DECL_SIZE_UNIT (member);
13384 : 255762 : if (memsize)
13385 : : {
13386 : 123798 : tree memtype = TREE_TYPE (member);
13387 : 123798 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13388 : 123677 : return sam_type;
13389 : :
13390 : 83232 : bool trailing = false;
13391 : 83232 : (void) array_ref_flexible_size_p (ref, &trailing);
13392 : 83232 : bool zero_elts = integer_zerop (memsize);
13393 : 83232 : if (zero_elts && integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (memtype))))
13394 : : {
13395 : : /* If array element has zero size, verify if it is a flexible
13396 : : array member or zero length array. Clear zero_elts if
13397 : : it has one or more members or is a VLA member. */
13398 : 7 : if (tree dom = TYPE_DOMAIN (memtype))
13399 : 7 : if (tree min = TYPE_MIN_VALUE (dom))
13400 : 7 : if (tree max = TYPE_MAX_VALUE (dom))
13401 : 5 : if (TREE_CODE (min) != INTEGER_CST
13402 : 5 : || TREE_CODE (max) != INTEGER_CST
13403 : 15 : || !((integer_zerop (min) && integer_all_onesp (max))
13404 : 5 : || tree_int_cst_lt (max, min)))
13405 : : zero_elts = false;
13406 : : }
13407 : 83232 : if (!trailing && !zero_elts)
13408 : : /* MEMBER is an interior array with more than one element. */
13409 : : return special_array_member::int_n;
13410 : :
13411 : 23743 : if (zero_elts)
13412 : : {
13413 : 1075 : if (trailing)
13414 : : return special_array_member::trail_0;
13415 : : else
13416 : 463 : return special_array_member::int_0;
13417 : : }
13418 : :
13419 : 23131 : if (!zero_elts)
13420 : 23131 : if (tree dom = TYPE_DOMAIN (memtype))
13421 : 23131 : if (tree min = TYPE_MIN_VALUE (dom))
13422 : 23131 : if (tree max = TYPE_MAX_VALUE (dom))
13423 : 23131 : if (TREE_CODE (min) == INTEGER_CST
13424 : 23131 : && TREE_CODE (max) == INTEGER_CST)
13425 : : {
13426 : 23010 : offset_int minidx = wi::to_offset (min);
13427 : 23010 : offset_int maxidx = wi::to_offset (max);
13428 : 23010 : offset_int neltsm1 = maxidx - minidx;
13429 : 23010 : if (neltsm1 > 0)
13430 : : /* MEMBER is a trailing array with more than
13431 : : one elements. */
13432 : 23010 : return special_array_member::trail_n;
13433 : :
13434 : 1966 : if (neltsm1 == 0)
13435 : : return special_array_member::trail_1;
13436 : : }
13437 : : }
13438 : :
13439 : : return sam_type;
13440 : : }
13441 : :
13442 : : /* Determines the size of the member referenced by the COMPONENT_REF
13443 : : REF, using its initializer expression if necessary in order to
13444 : : determine the size of an initialized flexible array member.
13445 : : If non-null, set *SAM to the type of special array member.
13446 : : Returns the size as sizetype (which might be zero for an object
13447 : : with an uninitialized flexible array member) or null if the size
13448 : : cannot be determined. */
13449 : :
13450 : : tree
13451 : 156809 : component_ref_size (tree ref, special_array_member *sam /* = NULL */)
13452 : : {
13453 : 156809 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
13454 : :
13455 : 156809 : special_array_member sambuf;
13456 : 156809 : if (!sam)
13457 : 101373 : sam = &sambuf;
13458 : 156809 : *sam = component_ref_sam_type (ref);
13459 : :
13460 : : /* The object/argument referenced by the COMPONENT_REF and its type. */
13461 : 156809 : tree arg = TREE_OPERAND (ref, 0);
13462 : 156809 : tree argtype = TREE_TYPE (arg);
13463 : : /* The referenced member. */
13464 : 156809 : tree member = TREE_OPERAND (ref, 1);
13465 : :
13466 : 156809 : tree memsize = DECL_SIZE_UNIT (member);
13467 : 156809 : if (memsize)
13468 : : {
13469 : 89302 : tree memtype = TREE_TYPE (member);
13470 : 89302 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13471 : : /* DECL_SIZE may be less than TYPE_SIZE in C++ when referring
13472 : : to the type of a class with a virtual base which doesn't
13473 : : reflect the size of the virtual's members (see pr97595).
13474 : : If that's the case fail for now and implement something
13475 : : more robust in the future. */
13476 : 40566 : return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype))
13477 : 40566 : ? memsize : NULL_TREE);
13478 : :
13479 : : /* 2-or-more elements arrays are treated as normal arrays by default. */
13480 : 48736 : if (*sam == special_array_member::int_n
13481 : 48736 : || *sam == special_array_member::trail_n)
13482 : : return memsize;
13483 : :
13484 : 1742 : tree afield_decl = TREE_OPERAND (ref, 1);
13485 : 1742 : gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
13486 : : /* If the trailing array is a not a flexible array member, treat it as
13487 : : a normal array. */
13488 : 1742 : if (DECL_NOT_FLEXARRAY (afield_decl)
13489 : 1742 : && *sam != special_array_member::int_0)
13490 : : return memsize;
13491 : :
13492 : 1733 : if (*sam == special_array_member::int_0)
13493 : 270 : memsize = NULL_TREE;
13494 : :
13495 : : /* For a reference to a flexible array member of a union
13496 : : use the size of the union instead of the size of the member. */
13497 : 1733 : if (TREE_CODE (argtype) == UNION_TYPE)
13498 : 277 : memsize = TYPE_SIZE_UNIT (argtype);
13499 : : }
13500 : :
13501 : : /* MEMBER is either a bona fide flexible array member, or a zero-elements
13502 : : array member, or an array of length one treated as such. */
13503 : :
13504 : : /* If the reference is to a declared object and the member a true
13505 : : flexible array, try to determine its size from its initializer. */
13506 : 69240 : poly_int64 baseoff = 0;
13507 : 69240 : tree base = get_addr_base_and_unit_offset (ref, &baseoff);
13508 : 69240 : if (!base || !VAR_P (base))
13509 : : {
13510 : 66025 : if (*sam != special_array_member::int_0)
13511 : : return NULL_TREE;
13512 : :
13513 : 52 : if (TREE_CODE (arg) != COMPONENT_REF)
13514 : : return NULL_TREE;
13515 : :
13516 : : base = arg;
13517 : 6 : while (TREE_CODE (base) == COMPONENT_REF)
13518 : 3 : base = TREE_OPERAND (base, 0);
13519 : 3 : baseoff = tree_to_poly_int64 (byte_position (TREE_OPERAND (ref, 1)));
13520 : : }
13521 : :
13522 : : /* BASE is the declared object of which MEMBER is either a member
13523 : : or that is cast to ARGTYPE (e.g., a char buffer used to store
13524 : : an ARGTYPE object). */
13525 : 3218 : tree basetype = TREE_TYPE (base);
13526 : :
13527 : : /* Determine the base type of the referenced object. If it's
13528 : : the same as ARGTYPE and MEMBER has a known size, return it. */
13529 : 3218 : tree bt = basetype;
13530 : 3218 : if (*sam != special_array_member::int_0)
13531 : 3219 : while (TREE_CODE (bt) == ARRAY_TYPE)
13532 : 222 : bt = TREE_TYPE (bt);
13533 : 3218 : bool typematch = useless_type_conversion_p (argtype, bt);
13534 : 3218 : if (memsize && typematch)
13535 : : return memsize;
13536 : :
13537 : 3128 : memsize = NULL_TREE;
13538 : :
13539 : 3128 : if (typematch)
13540 : : /* MEMBER is a true flexible array member. Compute its size from
13541 : : the initializer of the BASE object if it has one. */
13542 : 2666 : if (tree init = DECL_P (base) ? DECL_INITIAL (base) : NULL_TREE)
13543 : 1302 : if (init != error_mark_node)
13544 : : {
13545 : 1269 : init = get_initializer_for (init, member);
13546 : 1269 : if (init)
13547 : : {
13548 : 891 : memsize = TYPE_SIZE_UNIT (TREE_TYPE (init));
13549 : 891 : if (tree refsize = TYPE_SIZE_UNIT (argtype))
13550 : : {
13551 : : /* Use the larger of the initializer size and the tail
13552 : : padding in the enclosing struct. */
13553 : 891 : poly_int64 rsz = tree_to_poly_int64 (refsize);
13554 : 891 : rsz -= baseoff;
13555 : 891 : if (known_lt (tree_to_poly_int64 (memsize), rsz))
13556 : 56 : memsize = wide_int_to_tree (TREE_TYPE (memsize), rsz);
13557 : : }
13558 : :
13559 : 891 : baseoff = 0;
13560 : : }
13561 : : }
13562 : :
13563 : 891 : if (!memsize)
13564 : : {
13565 : 2237 : if (typematch)
13566 : : {
13567 : 1775 : if (DECL_P (base)
13568 : 1775 : && DECL_EXTERNAL (base)
13569 : 454 : && bt == basetype
13570 : 2223 : && *sam != special_array_member::int_0)
13571 : : /* The size of a flexible array member of an extern struct
13572 : : with no initializer cannot be determined (it's defined
13573 : : in another translation unit and can have an initializer
13574 : : with an arbitrary number of elements). */
13575 : : return NULL_TREE;
13576 : :
13577 : : /* Use the size of the base struct or, for interior zero-length
13578 : : arrays, the size of the enclosing type. */
13579 : 1350 : memsize = TYPE_SIZE_UNIT (bt);
13580 : : }
13581 : 462 : else if (DECL_P (base))
13582 : : /* Use the size of the BASE object (possibly an array of some
13583 : : other type such as char used to store the struct). */
13584 : 459 : memsize = DECL_SIZE_UNIT (base);
13585 : : else
13586 : : return NULL_TREE;
13587 : : }
13588 : :
13589 : : /* If the flexible array member has a known size use the greater
13590 : : of it and the tail padding in the enclosing struct.
13591 : : Otherwise, when the size of the flexible array member is unknown
13592 : : and the referenced object is not a struct, use the size of its
13593 : : type when known. This detects sizes of array buffers when cast
13594 : : to struct types with flexible array members. */
13595 : 1809 : if (memsize)
13596 : : {
13597 : 2675 : if (!tree_fits_poly_int64_p (memsize))
13598 : : return NULL_TREE;
13599 : 2675 : poly_int64 memsz64 = memsize ? tree_to_poly_int64 (memsize) : 0;
13600 : 2675 : if (known_lt (baseoff, memsz64))
13601 : : {
13602 : 1241 : memsz64 -= baseoff;
13603 : 1241 : return wide_int_to_tree (TREE_TYPE (memsize), memsz64);
13604 : : }
13605 : 1434 : return size_zero_node;
13606 : : }
13607 : :
13608 : : /* Return "don't know" for an external non-array object since its
13609 : : flexible array member can be initialized to have any number of
13610 : : elements. Otherwise, return zero because the flexible array
13611 : : member has no elements. */
13612 : 25 : return (DECL_P (base)
13613 : 25 : && DECL_EXTERNAL (base)
13614 : 25 : && (!typematch
13615 : 0 : || TREE_CODE (basetype) != ARRAY_TYPE)
13616 : 25 : ? NULL_TREE : size_zero_node);
13617 : : }
13618 : :
13619 : : /* Return true if the given node CALL is a call to a .ACCESS_WITH_SIZE
13620 : : function. */
13621 : : bool
13622 : 57671601 : is_access_with_size_p (const_tree call)
13623 : : {
13624 : 57671601 : if (TREE_CODE (call) != CALL_EXPR)
13625 : : return false;
13626 : 6994961 : if (CALL_EXPR_IFN (call) == IFN_ACCESS_WITH_SIZE)
13627 : 353 : return true;
13628 : : return false;
13629 : : }
13630 : :
13631 : : /* Get the corresponding reference from the call to a .ACCESS_WITH_SIZE.
13632 : : * i.e the first argument of this call. Return NULL_TREE otherwise. */
13633 : : tree
13634 : 2 : get_ref_from_access_with_size (tree call)
13635 : : {
13636 : 2 : if (is_access_with_size_p (call))
13637 : 2 : return CALL_EXPR_ARG (call, 0);
13638 : : return NULL_TREE;
13639 : : }
13640 : :
13641 : : /* Return the machine mode of T. For vectors, returns the mode of the
13642 : : inner type. The main use case is to feed the result to HONOR_NANS,
13643 : : avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
13644 : :
13645 : : machine_mode
13646 : 5140597604 : element_mode (const_tree t)
13647 : : {
13648 : 5140597604 : if (!TYPE_P (t))
13649 : 203403495 : t = TREE_TYPE (t);
13650 : 5140597604 : if (VECTOR_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
13651 : 1477001500 : t = TREE_TYPE (t);
13652 : 5140597604 : return TYPE_MODE (t);
13653 : : }
13654 : :
13655 : : /* Vector types need to re-check the target flags each time we report
13656 : : the machine mode. We need to do this because attribute target can
13657 : : change the result of vector_mode_supported_p and have_regs_of_mode
13658 : : on a per-function basis. Thus the TYPE_MODE of a VECTOR_TYPE can
13659 : : change on a per-function basis. */
13660 : : /* ??? Possibly a better solution is to run through all the types
13661 : : referenced by a function and re-compute the TYPE_MODE once, rather
13662 : : than make the TYPE_MODE macro call a function. */
13663 : :
13664 : : machine_mode
13665 : 1316658369 : vector_type_mode (const_tree t)
13666 : : {
13667 : 1316658369 : machine_mode mode;
13668 : :
13669 : 1316658369 : gcc_assert (TREE_CODE (t) == VECTOR_TYPE);
13670 : :
13671 : 1316658369 : mode = t->type_common.mode;
13672 : 297923473 : if (VECTOR_MODE_P (mode)
13673 : 1577558894 : && (!targetm.vector_mode_supported_p (mode)
13674 : 1261305395 : || !have_regs_of_mode[mode]))
13675 : : {
13676 : 19236935 : scalar_int_mode innermode;
13677 : :
13678 : : /* For integers, try mapping it to a same-sized scalar mode. */
13679 : 19236935 : if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode))
13680 : : {
13681 : 26908812 : poly_int64 size = (TYPE_VECTOR_SUBPARTS (t)
13682 : 13454406 : * GET_MODE_BITSIZE (innermode));
13683 : 13454406 : scalar_int_mode mode;
13684 : 26775169 : if (int_mode_for_size (size, 0).exists (&mode)
13685 : 13374483 : && have_regs_of_mode[mode])
13686 : 53720 : return mode;
13687 : : }
13688 : :
13689 : 19183215 : return BLKmode;
13690 : : }
13691 : :
13692 : : return mode;
13693 : : }
13694 : :
13695 : : /* Return the size in bits of each element of vector type TYPE. */
13696 : :
13697 : : unsigned int
13698 : 211208 : vector_element_bits (const_tree type)
13699 : : {
13700 : 211208 : gcc_checking_assert (VECTOR_TYPE_P (type));
13701 : 211208 : if (VECTOR_BOOLEAN_TYPE_P (type))
13702 : 1008 : return TYPE_PRECISION (TREE_TYPE (type));
13703 : 210200 : return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
13704 : : }
13705 : :
13706 : : /* Calculate the size in bits of each element of vector type TYPE
13707 : : and return the result as a tree of type bitsizetype. */
13708 : :
13709 : : tree
13710 : 110281 : vector_element_bits_tree (const_tree type)
13711 : : {
13712 : 110281 : gcc_checking_assert (VECTOR_TYPE_P (type));
13713 : 110281 : if (VECTOR_BOOLEAN_TYPE_P (type))
13714 : 596 : return bitsize_int (vector_element_bits (type));
13715 : 109685 : return TYPE_SIZE (TREE_TYPE (type));
13716 : : }
13717 : :
13718 : : /* Verify that basic properties of T match TV and thus T can be a variant of
13719 : : TV. TV should be the more specified variant (i.e. the main variant). */
13720 : :
13721 : : static bool
13722 : 148868654 : verify_type_variant (const_tree t, tree tv)
13723 : : {
13724 : : /* Type variant can differ by:
13725 : :
13726 : : - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
13727 : : ENCODE_QUAL_ADDR_SPACE.
13728 : : - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
13729 : : in this case some values may not be set in the variant types
13730 : : (see TYPE_COMPLETE_P checks).
13731 : : - it is possible to have TYPE_ARTIFICIAL variant of non-artifical type
13732 : : - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
13733 : : - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
13734 : : - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
13735 : : - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
13736 : : this is necessary to make it possible to merge types form different TUs
13737 : : - arrays, pointers and references may have TREE_TYPE that is a variant
13738 : : of TREE_TYPE of their main variants.
13739 : : - aggregates may have new TYPE_FIELDS list that list variants of
13740 : : the main variant TYPE_FIELDS.
13741 : : - vector types may differ by TYPE_VECTOR_OPAQUE
13742 : : */
13743 : :
13744 : : /* Convenience macro for matching individual fields. */
13745 : : #define verify_variant_match(flag) \
13746 : : do { \
13747 : : if (flag (tv) != flag (t)) \
13748 : : { \
13749 : : error ("type variant differs by %s", #flag); \
13750 : : debug_tree (tv); \
13751 : : return false; \
13752 : : } \
13753 : : } while (false)
13754 : :
13755 : : /* tree_base checks. */
13756 : :
13757 : 148868654 : verify_variant_match (TREE_CODE);
13758 : : /* FIXME: Ada builds non-artificial variants of artificial types. */
13759 : : #if 0
13760 : : if (TYPE_ARTIFICIAL (tv))
13761 : : verify_variant_match (TYPE_ARTIFICIAL);
13762 : : #endif
13763 : 148868654 : if (POINTER_TYPE_P (tv))
13764 : 11449908 : verify_variant_match (TYPE_REF_CAN_ALIAS_ALL);
13765 : : /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
13766 : 148868654 : verify_variant_match (TYPE_UNSIGNED);
13767 : 148868654 : verify_variant_match (TYPE_PACKED);
13768 : 148868654 : if (TREE_CODE (t) == REFERENCE_TYPE)
13769 : 3008603 : verify_variant_match (TYPE_REF_IS_RVALUE);
13770 : 148868654 : if (AGGREGATE_TYPE_P (t))
13771 : 63194633 : verify_variant_match (TYPE_REVERSE_STORAGE_ORDER);
13772 : : else
13773 : 85674021 : verify_variant_match (TYPE_SATURATING);
13774 : : /* FIXME: This check trigger during libstdc++ build. */
13775 : : #if 0
13776 : : if (RECORD_OR_UNION_TYPE_P (t) && COMPLETE_TYPE_P (t))
13777 : : verify_variant_match (TYPE_FINAL_P);
13778 : : #endif
13779 : :
13780 : : /* tree_type_common checks. */
13781 : :
13782 : 148868654 : if (COMPLETE_TYPE_P (t))
13783 : : {
13784 : 138322972 : verify_variant_match (TYPE_MODE);
13785 : 138322972 : if (TREE_CODE (TYPE_SIZE (t)) != PLACEHOLDER_EXPR
13786 : 138322972 : && TREE_CODE (TYPE_SIZE (tv)) != PLACEHOLDER_EXPR)
13787 : 138322972 : verify_variant_match (TYPE_SIZE);
13788 : 138322972 : if (TREE_CODE (TYPE_SIZE_UNIT (t)) != PLACEHOLDER_EXPR
13789 : 138322972 : && TREE_CODE (TYPE_SIZE_UNIT (tv)) != PLACEHOLDER_EXPR
13790 : 276645944 : && TYPE_SIZE_UNIT (t) != TYPE_SIZE_UNIT (tv))
13791 : : {
13792 : 0 : gcc_assert (!operand_equal_p (TYPE_SIZE_UNIT (t),
13793 : : TYPE_SIZE_UNIT (tv), 0));
13794 : 0 : error ("type variant has different %<TYPE_SIZE_UNIT%>");
13795 : 0 : debug_tree (tv);
13796 : 0 : error ("type variant%'s %<TYPE_SIZE_UNIT%>");
13797 : 0 : debug_tree (TYPE_SIZE_UNIT (tv));
13798 : 0 : error ("type%'s %<TYPE_SIZE_UNIT%>");
13799 : 0 : debug_tree (TYPE_SIZE_UNIT (t));
13800 : 0 : return false;
13801 : : }
13802 : 138322972 : verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
13803 : : }
13804 : 148868654 : verify_variant_match (TYPE_PRECISION_RAW);
13805 : 148868654 : if (RECORD_OR_UNION_TYPE_P (t))
13806 : 62667324 : verify_variant_match (TYPE_TRANSPARENT_AGGR);
13807 : 86201330 : else if (TREE_CODE (t) == ARRAY_TYPE)
13808 : 527309 : verify_variant_match (TYPE_NONALIASED_COMPONENT);
13809 : : /* During LTO we merge variant lists from diferent translation units
13810 : : that may differ BY TYPE_CONTEXT that in turn may point
13811 : : to TRANSLATION_UNIT_DECL.
13812 : : Ada also builds variants of types with different TYPE_CONTEXT. */
13813 : : #if 0
13814 : : if (!in_lto_p || !TYPE_FILE_SCOPE_P (t))
13815 : : verify_variant_match (TYPE_CONTEXT);
13816 : : #endif
13817 : 148868654 : if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == INTEGER_TYPE)
13818 : 51786990 : verify_variant_match (TYPE_STRING_FLAG);
13819 : 148868654 : if (TREE_CODE (t) == RECORD_TYPE || TREE_CODE (t) == UNION_TYPE)
13820 : 62667324 : verify_variant_match (TYPE_CXX_ODR_P);
13821 : 148868654 : if (TYPE_ALIAS_SET_KNOWN_P (t))
13822 : : {
13823 : 0 : error ("type variant with %<TYPE_ALIAS_SET_KNOWN_P%>");
13824 : 0 : debug_tree (tv);
13825 : 0 : return false;
13826 : : }
13827 : :
13828 : : /* tree_type_non_common checks. */
13829 : :
13830 : : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
13831 : : and dangle the pointer from time to time. */
13832 : 62667324 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_VFIELD (t) != TYPE_VFIELD (tv)
13833 : 148868654 : && (in_lto_p || !TYPE_VFIELD (tv)
13834 : 0 : || TREE_CODE (TYPE_VFIELD (tv)) != TREE_LIST))
13835 : : {
13836 : 0 : error ("type variant has different %<TYPE_VFIELD%>");
13837 : 0 : debug_tree (tv);
13838 : 0 : return false;
13839 : : }
13840 : 2450371 : if ((TREE_CODE (t) == ENUMERAL_TYPE && COMPLETE_TYPE_P (t))
13841 : 146418338 : || TREE_CODE (t) == INTEGER_TYPE
13842 : 95158657 : || TREE_CODE (t) == BOOLEAN_TYPE
13843 : 76301708 : || TREE_CODE (t) == BITINT_TYPE
13844 : 76301560 : || SCALAR_FLOAT_TYPE_P (t)
13845 : 224179942 : || FIXED_POINT_TYPE_P (t))
13846 : : {
13847 : 73557366 : verify_variant_match (TYPE_MAX_VALUE);
13848 : 73557366 : verify_variant_match (TYPE_MIN_VALUE);
13849 : : }
13850 : 148868654 : if (TREE_CODE (t) == METHOD_TYPE)
13851 : 11184 : verify_variant_match (TYPE_METHOD_BASETYPE);
13852 : 148868654 : if (TREE_CODE (t) == OFFSET_TYPE)
13853 : 165 : verify_variant_match (TYPE_OFFSET_BASETYPE);
13854 : 148868654 : if (TREE_CODE (t) == ARRAY_TYPE)
13855 : 527309 : verify_variant_match (TYPE_ARRAY_MAX_SIZE);
13856 : : /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
13857 : : or even type's main variant. This is needed to make bootstrap pass
13858 : : and the bug seems new in GCC 5.
13859 : : C++ FE should be updated to make this consistent and we should check
13860 : : that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
13861 : : is a match with main variant.
13862 : :
13863 : : Also disable the check for Java for now because of parser hack that builds
13864 : : first an dummy BINFO and then sometimes replace it by real BINFO in some
13865 : : of the copies. */
13866 : 62667324 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t) && TYPE_BINFO (tv)
13867 : 51928848 : && TYPE_BINFO (t) != TYPE_BINFO (tv)
13868 : : /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
13869 : : Since there is no cheap way to tell C++/Java type w/o LTO, do checking
13870 : : at LTO time only. */
13871 : 148868654 : && (in_lto_p && odr_type_p (t)))
13872 : : {
13873 : 0 : error ("type variant has different %<TYPE_BINFO%>");
13874 : 0 : debug_tree (tv);
13875 : 0 : error ("type variant%'s %<TYPE_BINFO%>");
13876 : 0 : debug_tree (TYPE_BINFO (tv));
13877 : 0 : error ("type%'s %<TYPE_BINFO%>");
13878 : 0 : debug_tree (TYPE_BINFO (t));
13879 : 0 : return false;
13880 : : }
13881 : :
13882 : : /* Check various uses of TYPE_VALUES_RAW. */
13883 : 148868654 : if (TREE_CODE (t) == ENUMERAL_TYPE
13884 : 148868654 : && TYPE_VALUES (t))
13885 : 2429571 : verify_variant_match (TYPE_VALUES);
13886 : 146439083 : else if (TREE_CODE (t) == ARRAY_TYPE)
13887 : 527309 : verify_variant_match (TYPE_DOMAIN);
13888 : : /* Permit incomplete variants of complete type. While FEs may complete
13889 : : all variants, this does not happen for C++ templates in all cases. */
13890 : 145911774 : else if (RECORD_OR_UNION_TYPE_P (t)
13891 : 62667324 : && COMPLETE_TYPE_P (t)
13892 : 198233055 : && TYPE_FIELDS (t) != TYPE_FIELDS (tv))
13893 : : {
13894 : 3649 : tree f1, f2;
13895 : :
13896 : : /* Fortran builds qualified variants as new records with items of
13897 : : qualified type. Verify that they looks same. */
13898 : 3649 : for (f1 = TYPE_FIELDS (t), f2 = TYPE_FIELDS (tv);
13899 : 11881 : f1 && f2;
13900 : 8232 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
13901 : 8232 : if (TREE_CODE (f1) != FIELD_DECL || TREE_CODE (f2) != FIELD_DECL
13902 : 8232 : || (TYPE_MAIN_VARIANT (TREE_TYPE (f1))
13903 : 8232 : != TYPE_MAIN_VARIANT (TREE_TYPE (f2))
13904 : : /* FIXME: gfc_nonrestricted_type builds all types as variants
13905 : : with exception of pointer types. It deeply copies the type
13906 : : which means that we may end up with a variant type
13907 : : referring non-variant pointer. We may change it to
13908 : : produce types as variants, too, like
13909 : : objc_get_protocol_qualified_type does. */
13910 : 21 : && !POINTER_TYPE_P (TREE_TYPE (f1)))
13911 : 8232 : || DECL_FIELD_OFFSET (f1) != DECL_FIELD_OFFSET (f2)
13912 : 16464 : || DECL_FIELD_BIT_OFFSET (f1) != DECL_FIELD_BIT_OFFSET (f2))
13913 : : break;
13914 : 3649 : if (f1 || f2)
13915 : : {
13916 : 0 : error ("type variant has different %<TYPE_FIELDS%>");
13917 : 0 : debug_tree (tv);
13918 : 0 : error ("first mismatch is field");
13919 : 0 : debug_tree (f1);
13920 : 0 : error ("and field");
13921 : 0 : debug_tree (f2);
13922 : 0 : return false;
13923 : : }
13924 : : }
13925 : 145908125 : else if (FUNC_OR_METHOD_TYPE_P (t))
13926 : 136168 : verify_variant_match (TYPE_ARG_TYPES);
13927 : : /* For C++ the qualified variant of array type is really an array type
13928 : : of qualified TREE_TYPE.
13929 : : objc builds variants of pointer where pointer to type is a variant, too
13930 : : in objc_get_protocol_qualified_type. */
13931 : 148868654 : if (TREE_TYPE (t) != TREE_TYPE (tv)
13932 : 148868654 : && ((TREE_CODE (t) != ARRAY_TYPE
13933 : 0 : && !POINTER_TYPE_P (t))
13934 : 453099 : || TYPE_MAIN_VARIANT (TREE_TYPE (t))
13935 : 453099 : != TYPE_MAIN_VARIANT (TREE_TYPE (tv))))
13936 : : {
13937 : 0 : error ("type variant has different %<TREE_TYPE%>");
13938 : 0 : debug_tree (tv);
13939 : 0 : error ("type variant%'s %<TREE_TYPE%>");
13940 : 0 : debug_tree (TREE_TYPE (tv));
13941 : 0 : error ("type%'s %<TREE_TYPE%>");
13942 : 0 : debug_tree (TREE_TYPE (t));
13943 : 0 : return false;
13944 : : }
13945 : 148868654 : if (type_with_alias_set_p (t)
13946 : 148868654 : && !gimple_canonical_types_compatible_p (t, tv, false))
13947 : : {
13948 : 0 : error ("type is not compatible with its variant");
13949 : 0 : debug_tree (tv);
13950 : 0 : error ("type variant%'s %<TREE_TYPE%>");
13951 : 0 : debug_tree (TREE_TYPE (tv));
13952 : 0 : error ("type%'s %<TREE_TYPE%>");
13953 : 0 : debug_tree (TREE_TYPE (t));
13954 : 0 : return false;
13955 : : }
13956 : : return true;
13957 : : #undef verify_variant_match
13958 : : }
13959 : :
13960 : :
13961 : : /* The TYPE_CANONICAL merging machinery. It should closely resemble
13962 : : the middle-end types_compatible_p function. It needs to avoid
13963 : : claiming types are different for types that should be treated
13964 : : the same with respect to TBAA. Canonical types are also used
13965 : : for IL consistency checks via the useless_type_conversion_p
13966 : : predicate which does not handle all type kinds itself but falls
13967 : : back to pointer-comparison of TYPE_CANONICAL for aggregates
13968 : : for example. */
13969 : :
13970 : : /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
13971 : : type calculation because we need to allow inter-operability between signed
13972 : : and unsigned variants. */
13973 : :
13974 : : bool
13975 : 1665220 : type_with_interoperable_signedness (const_tree type)
13976 : : {
13977 : : /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
13978 : : signed char and unsigned char. Similarly fortran FE builds
13979 : : C_SIZE_T as signed type, while C defines it unsigned. */
13980 : :
13981 : 1665220 : return tree_code_for_canonical_type_merging (TREE_CODE (type))
13982 : : == INTEGER_TYPE
13983 : 1665019 : && (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)
13984 : 449026 : || TYPE_PRECISION (type) == TYPE_PRECISION (size_type_node));
13985 : : }
13986 : :
13987 : : /* Return true iff T1 and T2 are structurally identical for what
13988 : : TBAA is concerned.
13989 : : This function is used both by lto.cc canonical type merging and by the
13990 : : verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
13991 : : that have TYPE_CANONICAL defined and assume them equivalent. This is useful
13992 : : only for LTO because only in these cases TYPE_CANONICAL equivalence
13993 : : correspond to one defined by gimple_canonical_types_compatible_p. */
13994 : :
13995 : : bool
13996 : 319652106 : gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
13997 : : bool trust_type_canonical)
13998 : : {
13999 : : /* Type variants should be same as the main variant. When not doing sanity
14000 : : checking to verify this fact, go to main variants and save some work. */
14001 : 319652106 : if (trust_type_canonical)
14002 : : {
14003 : 890970 : t1 = TYPE_MAIN_VARIANT (t1);
14004 : 890970 : t2 = TYPE_MAIN_VARIANT (t2);
14005 : : }
14006 : :
14007 : : /* Check first for the obvious case of pointer identity. */
14008 : 319652106 : if (t1 == t2)
14009 : : return true;
14010 : :
14011 : : /* Check that we have two types to compare. */
14012 : 266059100 : if (t1 == NULL_TREE || t2 == NULL_TREE)
14013 : : return false;
14014 : :
14015 : : /* We consider complete types always compatible with incomplete type.
14016 : : This does not make sense for canonical type calculation and thus we
14017 : : need to ensure that we are never called on it.
14018 : :
14019 : : FIXME: For more correctness the function probably should have three modes
14020 : : 1) mode assuming that types are complete mathcing their structure
14021 : : 2) mode allowing incomplete types but producing equivalence classes
14022 : : and thus ignoring all info from complete types
14023 : : 3) mode allowing incomplete types to match complete but checking
14024 : : compatibility between complete types.
14025 : :
14026 : : 1 and 2 can be used for canonical type calculation. 3 is the real
14027 : : definition of type compatibility that can be used i.e. for warnings during
14028 : : declaration merging. */
14029 : :
14030 : 266059100 : gcc_assert (!trust_type_canonical
14031 : : || (type_with_alias_set_p (t1) && type_with_alias_set_p (t2)));
14032 : :
14033 : : /* If the types have been previously registered and found equal
14034 : : they still are. */
14035 : :
14036 : 531884554 : if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t2)
14037 : 531079467 : && trust_type_canonical)
14038 : : {
14039 : : /* Do not use TYPE_CANONICAL of pointer types. For LTO streamed types
14040 : : they are always NULL, but they are set to non-NULL for types
14041 : : constructed by build_pointer_type and variants. In this case the
14042 : : TYPE_CANONICAL is more fine grained than the equivalnce we test (where
14043 : : all pointers are considered equal. Be sure to not return false
14044 : : negatives. */
14045 : 164780 : gcc_checking_assert (canonical_type_used_p (t1)
14046 : : && canonical_type_used_p (t2));
14047 : 82390 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
14048 : : }
14049 : :
14050 : : /* For types where we do ODR based TBAA the canonical type is always
14051 : : set correctly, so we know that types are different if their
14052 : : canonical types does not match. */
14053 : 265976710 : if (trust_type_canonical
14054 : 266782297 : && (odr_type_p (t1) && odr_based_tbaa_p (t1))
14055 : 805587 : != (odr_type_p (t2) && odr_based_tbaa_p (t2)))
14056 : : return false;
14057 : :
14058 : : /* Can't be the same type if the types don't have the same code. */
14059 : 265976710 : enum tree_code code = tree_code_for_canonical_type_merging (TREE_CODE (t1));
14060 : 529032766 : if (code != tree_code_for_canonical_type_merging (TREE_CODE (t2)))
14061 : : return false;
14062 : :
14063 : : /* Qualifiers do not matter for canonical type comparison purposes. */
14064 : :
14065 : : /* Void types and nullptr types are always the same. */
14066 : 265976675 : if (VOID_TYPE_P (t1)
14067 : 265937574 : || TREE_CODE (t1) == NULLPTR_TYPE)
14068 : : return true;
14069 : :
14070 : : /* Can't be compatible types if they have different mode. Because of
14071 : : flexible array members, we allow mismatching modes for structures or
14072 : : unions. */
14073 : 265369950 : if (!RECORD_OR_UNION_TYPE_P (t1)
14074 : 265369950 : && TREE_CODE (t1) != ARRAY_TYPE
14075 : 265369950 : && TYPE_MODE (t1) != TYPE_MODE (t2))
14076 : : return false;
14077 : :
14078 : : /* Non-aggregate types can be handled cheaply. */
14079 : 265369950 : if (INTEGRAL_TYPE_P (t1)
14080 : 265369950 : || SCALAR_FLOAT_TYPE_P (t1)
14081 : 144001257 : || FIXED_POINT_TYPE_P (t1)
14082 : 143630979 : || VECTOR_TYPE_P (t1)
14083 : 143606820 : || TREE_CODE (t1) == COMPLEX_TYPE
14084 : 143251123 : || TREE_CODE (t1) == OFFSET_TYPE
14085 : 143250412 : || POINTER_TYPE_P (t1))
14086 : : {
14087 : : /* Can't be the same type if they have different precision. */
14088 : 159023888 : if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
14089 : : return false;
14090 : :
14091 : : /* In some cases the signed and unsigned types are required to be
14092 : : inter-operable. */
14093 : 159023888 : if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)
14094 : 159023888 : && !type_with_interoperable_signedness (t1))
14095 : : return false;
14096 : :
14097 : : /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
14098 : : interoperable with "signed char". Unless all frontends are revisited
14099 : : to agree on these types, we must ignore the flag completely. */
14100 : :
14101 : : /* Fortran standard define C_PTR type that is compatible with every
14102 : : C pointer. For this reason we need to glob all pointers into one.
14103 : : Still pointers in different address spaces are not compatible. */
14104 : 159023888 : if (POINTER_TYPE_P (t1))
14105 : : {
14106 : 36904350 : if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
14107 : 36904350 : != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
14108 : : return false;
14109 : : }
14110 : :
14111 : : /* Tail-recurse to components. */
14112 : 159023888 : if (VECTOR_TYPE_P (t1)
14113 : 159023888 : || TREE_CODE (t1) == COMPLEX_TYPE)
14114 : 379856 : return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
14115 : 379856 : TREE_TYPE (t2),
14116 : 379856 : trust_type_canonical);
14117 : :
14118 : : return true;
14119 : : }
14120 : :
14121 : : /* Do type-specific comparisons. */
14122 : 106346062 : switch (TREE_CODE (t1))
14123 : : {
14124 : 973762 : case ARRAY_TYPE:
14125 : : /* Array types are the same if the element types are the same and
14126 : : minimum and maximum index are the same. */
14127 : 973762 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14128 : : trust_type_canonical)
14129 : 973727 : || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
14130 : 973727 : || TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2)
14131 : 1947489 : || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
14132 : : return false;
14133 : : else
14134 : : {
14135 : 973727 : tree i1 = TYPE_DOMAIN (t1);
14136 : 973727 : tree i2 = TYPE_DOMAIN (t2);
14137 : :
14138 : : /* For an incomplete external array, the type domain can be
14139 : : NULL_TREE. Check this condition also. */
14140 : 973727 : if (i1 == NULL_TREE && i2 == NULL_TREE)
14141 : : return true;
14142 : 870669 : else if (i1 == NULL_TREE || i2 == NULL_TREE)
14143 : : return false;
14144 : : else
14145 : : {
14146 : 870669 : tree min1 = TYPE_MIN_VALUE (i1);
14147 : 870669 : tree min2 = TYPE_MIN_VALUE (i2);
14148 : 870669 : tree max1 = TYPE_MAX_VALUE (i1);
14149 : 870669 : tree max2 = TYPE_MAX_VALUE (i2);
14150 : :
14151 : : /* The minimum/maximum values have to be the same. */
14152 : 870669 : if ((min1 == min2
14153 : 0 : || (min1 && min2
14154 : 0 : && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
14155 : 0 : && TREE_CODE (min2) == PLACEHOLDER_EXPR)
14156 : 0 : || operand_equal_p (min1, min2, 0))))
14157 : 870669 : && (max1 == max2
14158 : 0 : || (max1 && max2
14159 : 0 : && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
14160 : 0 : && TREE_CODE (max2) == PLACEHOLDER_EXPR)
14161 : 0 : || operand_equal_p (max1, max2, 0)))))
14162 : 870669 : return true;
14163 : : else
14164 : 0 : return false;
14165 : : }
14166 : : }
14167 : :
14168 : 6650 : case METHOD_TYPE:
14169 : 6650 : case FUNCTION_TYPE:
14170 : : /* Function types are the same if the return type and arguments types
14171 : : are the same. */
14172 : 6650 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14173 : : trust_type_canonical))
14174 : : return false;
14175 : :
14176 : 6650 : if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)
14177 : 6650 : && (TYPE_NO_NAMED_ARGS_STDARG_P (t1)
14178 : 321 : == TYPE_NO_NAMED_ARGS_STDARG_P (t2)))
14179 : : return true;
14180 : : else
14181 : : {
14182 : 6329 : tree parms1, parms2;
14183 : :
14184 : 6329 : for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
14185 : 27797 : parms1 && parms2;
14186 : 21468 : parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
14187 : : {
14188 : 21468 : if (!gimple_canonical_types_compatible_p
14189 : 21468 : (TREE_VALUE (parms1), TREE_VALUE (parms2),
14190 : : trust_type_canonical))
14191 : : return false;
14192 : : }
14193 : :
14194 : 6329 : if (parms1 || parms2)
14195 : : return false;
14196 : :
14197 : : return true;
14198 : : }
14199 : :
14200 : 105005967 : case RECORD_TYPE:
14201 : 105005967 : case UNION_TYPE:
14202 : 105005967 : case QUAL_UNION_TYPE:
14203 : 105005967 : {
14204 : 105005967 : tree f1, f2;
14205 : :
14206 : : /* Don't try to compare variants of an incomplete type, before
14207 : : TYPE_FIELDS has been copied around. */
14208 : 105005967 : if (!COMPLETE_TYPE_P (t1) && !COMPLETE_TYPE_P (t2))
14209 : : return true;
14210 : :
14211 : :
14212 : 95273060 : if (TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2))
14213 : : return false;
14214 : :
14215 : : /* For aggregate types, all the fields must be the same. */
14216 : 95273060 : for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
14217 : 148421823 : f1 || f2;
14218 : 53148763 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
14219 : : {
14220 : : /* Skip non-fields and zero-sized fields, except zero-sized
14221 : : arrays at the end. */
14222 : 1559001623 : while (f1 && (TREE_CODE (f1) != FIELD_DECL
14223 : 97176556 : || (DECL_SIZE (f1)
14224 : 97161951 : && integer_zerop (DECL_SIZE (f1))
14225 : 44027770 : && (TREE_CHAIN (f1)
14226 : 2902 : || TREE_CODE (TREE_TYPE (f1))
14227 : : != ARRAY_TYPE))))
14228 : 1411635468 : f1 = TREE_CHAIN (f1);
14229 : 1559003102 : while (f2 && (TREE_CODE (f2) != FIELD_DECL
14230 : 97190528 : || (DECL_SIZE (f2)
14231 : 97175903 : && integer_zerop (DECL_SIZE (f2))
14232 : 44029254 : && (TREE_CHAIN (f2)
14233 : 3900 : || TREE_CODE (TREE_TYPE (f2))
14234 : : != ARRAY_TYPE))))
14235 : 1411636947 : f2 = TREE_CHAIN (f2);
14236 : 147366155 : if (!f1 || !f2)
14237 : : break;
14238 : :
14239 : 53148990 : tree t1 = TREE_TYPE (f1);
14240 : 53148990 : tree t2 = TREE_TYPE (f2);
14241 : :
14242 : : /* If the last element are arrays, we only compare the element
14243 : : types. */
14244 : 54194809 : if (TREE_CHAIN (f1) == NULL_TREE && TREE_CODE (t1) == ARRAY_TYPE
14245 : 53215661 : && TREE_CHAIN (f2) == NULL_TREE && TREE_CODE (t2) == ARRAY_TYPE)
14246 : : {
14247 : : /* If both arrays have zero size, this is a match. */
14248 : 119145 : if (DECL_SIZE (f1) && integer_zerop (DECL_SIZE (f1))
14249 : 66870 : && DECL_SIZE (f2) && integer_zerop (DECL_SIZE (f2)))
14250 : : return true;
14251 : :
14252 : 66463 : t1 = TREE_TYPE (t1);
14253 : 66463 : t2 = TREE_TYPE (t2);
14254 : : }
14255 : :
14256 : 53148787 : if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
14257 : 53148782 : || !gimple_compare_field_offset (f1, f2)
14258 : 106297569 : || !gimple_canonical_types_compatible_p
14259 : 53148782 : (t1, t2, trust_type_canonical))
14260 : 24 : return false;
14261 : : }
14262 : :
14263 : : /* If one aggregate has more fields than the other, they
14264 : : are not the same. */
14265 : 95272833 : if (f1 || f2)
14266 : : return false;
14267 : :
14268 : : return true;
14269 : : }
14270 : :
14271 : 359683 : default:
14272 : : /* Consider all types with language specific trees in them mutually
14273 : : compatible. This is executed only from verify_type and false
14274 : : positives can be tolerated. */
14275 : 359683 : gcc_assert (!in_lto_p);
14276 : : return true;
14277 : : }
14278 : : }
14279 : :
14280 : : /* For OPAQUE_TYPE T, it should have only size and alignment information
14281 : : and its mode should be of class MODE_OPAQUE. This function verifies
14282 : : these properties of T match TV which is the main variant of T and TC
14283 : : which is the canonical of T. */
14284 : :
14285 : : static void
14286 : 0 : verify_opaque_type (const_tree t, tree tv, tree tc)
14287 : : {
14288 : 0 : gcc_assert (OPAQUE_TYPE_P (t));
14289 : 0 : gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv));
14290 : 0 : gcc_assert (tc && tc == TYPE_CANONICAL (tc));
14291 : :
14292 : : /* For an opaque type T1, check if some of its properties match
14293 : : the corresponding ones of the other opaque type T2, emit some
14294 : : error messages for those inconsistent ones. */
14295 : 0 : auto check_properties_for_opaque_type = [](const_tree t1, tree t2,
14296 : : const char *kind_msg)
14297 : : {
14298 : 0 : if (!OPAQUE_TYPE_P (t2))
14299 : : {
14300 : 0 : error ("type %s is not an opaque type", kind_msg);
14301 : 0 : debug_tree (t2);
14302 : 0 : return;
14303 : : }
14304 : 0 : if (!OPAQUE_MODE_P (TYPE_MODE (t2)))
14305 : : {
14306 : 0 : error ("type %s is not with opaque mode", kind_msg);
14307 : 0 : debug_tree (t2);
14308 : 0 : return;
14309 : : }
14310 : 0 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
14311 : : {
14312 : 0 : error ("type %s differs by %<TYPE_MODE%>", kind_msg);
14313 : 0 : debug_tree (t2);
14314 : 0 : return;
14315 : : }
14316 : 0 : poly_uint64 t1_size = tree_to_poly_uint64 (TYPE_SIZE (t1));
14317 : 0 : poly_uint64 t2_size = tree_to_poly_uint64 (TYPE_SIZE (t2));
14318 : 0 : if (maybe_ne (t1_size, t2_size))
14319 : : {
14320 : 0 : error ("type %s differs by %<TYPE_SIZE%>", kind_msg);
14321 : 0 : debug_tree (t2);
14322 : 0 : return;
14323 : : }
14324 : 0 : if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2))
14325 : : {
14326 : 0 : error ("type %s differs by %<TYPE_ALIGN%>", kind_msg);
14327 : 0 : debug_tree (t2);
14328 : 0 : return;
14329 : : }
14330 : 0 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
14331 : : {
14332 : 0 : error ("type %s differs by %<TYPE_USER_ALIGN%>", kind_msg);
14333 : 0 : debug_tree (t2);
14334 : 0 : return;
14335 : : }
14336 : : };
14337 : :
14338 : 0 : if (t != tv)
14339 : 0 : check_properties_for_opaque_type (t, tv, "variant");
14340 : :
14341 : 0 : if (t != tc)
14342 : 0 : check_properties_for_opaque_type (t, tc, "canonical");
14343 : 0 : }
14344 : :
14345 : : /* Verify type T. */
14346 : :
14347 : : void
14348 : 737117792 : verify_type (const_tree t)
14349 : : {
14350 : 737117792 : bool error_found = false;
14351 : 737117792 : tree mv = TYPE_MAIN_VARIANT (t);
14352 : 737117792 : tree ct = TYPE_CANONICAL (t);
14353 : :
14354 : 737117792 : if (OPAQUE_TYPE_P (t))
14355 : : {
14356 : 0 : verify_opaque_type (t, mv, ct);
14357 : 0 : return;
14358 : : }
14359 : :
14360 : 737117792 : if (!mv)
14361 : : {
14362 : 0 : error ("main variant is not defined");
14363 : 0 : error_found = true;
14364 : : }
14365 : 737117792 : else if (mv != TYPE_MAIN_VARIANT (mv))
14366 : : {
14367 : 0 : error ("%<TYPE_MAIN_VARIANT%> has different %<TYPE_MAIN_VARIANT%>");
14368 : 0 : debug_tree (mv);
14369 : 0 : error_found = true;
14370 : : }
14371 : 737117792 : else if (t != mv && !verify_type_variant (t, mv))
14372 : : error_found = true;
14373 : :
14374 : 737117792 : if (!ct)
14375 : : ;
14376 : 735121705 : else if (TYPE_CANONICAL (ct) != ct)
14377 : : {
14378 : 0 : error ("%<TYPE_CANONICAL%> has different %<TYPE_CANONICAL%>");
14379 : 0 : debug_tree (ct);
14380 : 0 : error_found = true;
14381 : : }
14382 : : /* Method and function types cannot be used to address memory and thus
14383 : : TYPE_CANONICAL really matters only for determining useless conversions.
14384 : :
14385 : : FIXME: C++ FE produce declarations of builtin functions that are not
14386 : : compatible with main variants. */
14387 : 735121705 : else if (TREE_CODE (t) == FUNCTION_TYPE)
14388 : : ;
14389 : 734511454 : else if (t != ct
14390 : : /* FIXME: gimple_canonical_types_compatible_p cannot compare types
14391 : : with variably sized arrays because their sizes possibly
14392 : : gimplified to different variables. */
14393 : 126034607 : && !variably_modified_type_p (ct, NULL)
14394 : 126030333 : && !gimple_canonical_types_compatible_p (t, ct, false)
14395 : 734523947 : && COMPLETE_TYPE_P (t))
14396 : : {
14397 : 0 : error ("%<TYPE_CANONICAL%> is not compatible");
14398 : 0 : debug_tree (ct);
14399 : 0 : error_found = true;
14400 : : }
14401 : 1325701407 : if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t)
14402 : : /* We allow a mismatch for structure or union because of
14403 : : flexible array members. */
14404 : 586652895 : && !RECORD_OR_UNION_TYPE_P (t)
14405 : 244389280 : && !RECORD_OR_UNION_TYPE_P (TYPE_CANONICAL (t))
14406 : 244389280 : && TREE_CODE (t) != ARRAY_TYPE
14407 : 980130094 : && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
14408 : : {
14409 : 0 : error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");
14410 : 0 : debug_tree (ct);
14411 : 0 : error_found = true;
14412 : : }
14413 : 737117792 : if (TYPE_MAIN_VARIANT (t) == t && ct && TYPE_MAIN_VARIANT (ct) != ct)
14414 : : {
14415 : 0 : error ("%<TYPE_CANONICAL%> of main variant is not main variant");
14416 : 0 : debug_tree (ct);
14417 : 0 : debug_tree (TYPE_MAIN_VARIANT (ct));
14418 : 0 : error_found = true;
14419 : : }
14420 : :
14421 : :
14422 : : /* Check various uses of TYPE_MIN_VALUE_RAW. */
14423 : 737117792 : if (RECORD_OR_UNION_TYPE_P (t))
14424 : : {
14425 : : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
14426 : : and danagle the pointer from time to time. */
14427 : 383356200 : if (TYPE_VFIELD (t)
14428 : 10763128 : && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
14429 : 383356200 : && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
14430 : : {
14431 : 0 : error ("%<TYPE_VFIELD%> is not %<FIELD_DECL%> nor %<TREE_LIST%>");
14432 : 0 : debug_tree (TYPE_VFIELD (t));
14433 : 0 : error_found = true;
14434 : : }
14435 : : }
14436 : 353761592 : else if (TREE_CODE (t) == POINTER_TYPE)
14437 : : {
14438 : 94316960 : if (TYPE_NEXT_PTR_TO (t)
14439 : 94316960 : && TREE_CODE (TYPE_NEXT_PTR_TO (t)) != POINTER_TYPE)
14440 : : {
14441 : 0 : error ("%<TYPE_NEXT_PTR_TO%> is not %<POINTER_TYPE%>");
14442 : 0 : debug_tree (TYPE_NEXT_PTR_TO (t));
14443 : 0 : error_found = true;
14444 : : }
14445 : : }
14446 : 259444632 : else if (TREE_CODE (t) == REFERENCE_TYPE)
14447 : : {
14448 : 43489719 : if (TYPE_NEXT_REF_TO (t)
14449 : 43489719 : && TREE_CODE (TYPE_NEXT_REF_TO (t)) != REFERENCE_TYPE)
14450 : : {
14451 : 0 : error ("%<TYPE_NEXT_REF_TO%> is not %<REFERENCE_TYPE%>");
14452 : 0 : debug_tree (TYPE_NEXT_REF_TO (t));
14453 : 0 : error_found = true;
14454 : : }
14455 : : }
14456 : : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14457 : : || FIXED_POINT_TYPE_P (t))
14458 : : {
14459 : : /* FIXME: The following check should pass:
14460 : : useless_type_conversion_p (const_cast <tree> (t),
14461 : : TREE_TYPE (TYPE_MIN_VALUE (t))
14462 : : but does not for C sizetypes in LTO. */
14463 : : }
14464 : :
14465 : : /* Check various uses of TYPE_MAXVAL_RAW. */
14466 : 737117792 : if (RECORD_OR_UNION_TYPE_P (t))
14467 : : {
14468 : 383356200 : if (!TYPE_BINFO (t))
14469 : : ;
14470 : 358157473 : else if (TREE_CODE (TYPE_BINFO (t)) != TREE_BINFO)
14471 : : {
14472 : 0 : error ("%<TYPE_BINFO%> is not %<TREE_BINFO%>");
14473 : 0 : debug_tree (TYPE_BINFO (t));
14474 : 0 : error_found = true;
14475 : : }
14476 : 358157473 : else if (TREE_TYPE (TYPE_BINFO (t)) != TYPE_MAIN_VARIANT (t))
14477 : : {
14478 : 0 : error ("%<TYPE_BINFO%> type is not %<TYPE_MAIN_VARIANT%>");
14479 : 0 : debug_tree (TREE_TYPE (TYPE_BINFO (t)));
14480 : 0 : error_found = true;
14481 : : }
14482 : : }
14483 : : else if (FUNC_OR_METHOD_TYPE_P (t))
14484 : : {
14485 : 828537 : if (TYPE_METHOD_BASETYPE (t)
14486 : 69197 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != RECORD_TYPE
14487 : 828725 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != UNION_TYPE)
14488 : : {
14489 : 0 : error ("%<TYPE_METHOD_BASETYPE%> is not record nor union");
14490 : 0 : debug_tree (TYPE_METHOD_BASETYPE (t));
14491 : 0 : error_found = true;
14492 : : }
14493 : : }
14494 : : else if (TREE_CODE (t) == OFFSET_TYPE)
14495 : : {
14496 : 35838 : if (TYPE_OFFSET_BASETYPE (t)
14497 : 35838 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != RECORD_TYPE
14498 : 35846 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != UNION_TYPE)
14499 : : {
14500 : 0 : error ("%<TYPE_OFFSET_BASETYPE%> is not record nor union");
14501 : 0 : debug_tree (TYPE_OFFSET_BASETYPE (t));
14502 : 0 : error_found = true;
14503 : : }
14504 : : }
14505 : : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14506 : : || FIXED_POINT_TYPE_P (t))
14507 : : {
14508 : : /* FIXME: The following check should pass:
14509 : : useless_type_conversion_p (const_cast <tree> (t),
14510 : : TREE_TYPE (TYPE_MAX_VALUE (t))
14511 : : but does not for C sizetypes in LTO. */
14512 : : }
14513 : : else if (TREE_CODE (t) == ARRAY_TYPE)
14514 : : {
14515 : 1624828 : if (TYPE_ARRAY_MAX_SIZE (t)
14516 : 1624828 : && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t)) != INTEGER_CST)
14517 : : {
14518 : 0 : error ("%<TYPE_ARRAY_MAX_SIZE%> not %<INTEGER_CST%>");
14519 : 0 : debug_tree (TYPE_ARRAY_MAX_SIZE (t));
14520 : 0 : error_found = true;
14521 : : }
14522 : : }
14523 : 246457701 : else if (TYPE_MAX_VALUE_RAW (t))
14524 : : {
14525 : 0 : error ("%<TYPE_MAX_VALUE_RAW%> non-NULL");
14526 : 0 : debug_tree (TYPE_MAX_VALUE_RAW (t));
14527 : 0 : error_found = true;
14528 : : }
14529 : :
14530 : 737117792 : if (TYPE_LANG_SLOT_1 (t) && in_lto_p)
14531 : : {
14532 : 0 : error ("%<TYPE_LANG_SLOT_1 (binfo)%> field is non-NULL");
14533 : 0 : debug_tree (TYPE_LANG_SLOT_1 (t));
14534 : 0 : error_found = true;
14535 : : }
14536 : :
14537 : : /* Check various uses of TYPE_VALUES_RAW. */
14538 : 737117792 : if (TREE_CODE (t) == ENUMERAL_TYPE)
14539 : 86849866 : for (tree l = TYPE_VALUES (t); l; l = TREE_CHAIN (l))
14540 : : {
14541 : 76068072 : tree value = TREE_VALUE (l);
14542 : 76068072 : tree name = TREE_PURPOSE (l);
14543 : :
14544 : : /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
14545 : : CONST_DECL of ENUMERAL TYPE. */
14546 : 76068072 : if (TREE_CODE (value) != INTEGER_CST && TREE_CODE (value) != CONST_DECL)
14547 : : {
14548 : 0 : error ("enum value is not %<CONST_DECL%> or %<INTEGER_CST%>");
14549 : 0 : debug_tree (value);
14550 : 0 : debug_tree (name);
14551 : 0 : error_found = true;
14552 : : }
14553 : 76068072 : if (TREE_CODE (TREE_TYPE (value)) != INTEGER_TYPE
14554 : 76050210 : && TREE_CODE (TREE_TYPE (value)) != BOOLEAN_TYPE
14555 : 152118279 : && !useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (value)))
14556 : : {
14557 : 0 : error ("enum value type is not %<INTEGER_TYPE%> nor convertible "
14558 : : "to the enum");
14559 : 0 : debug_tree (value);
14560 : 0 : debug_tree (name);
14561 : 0 : error_found = true;
14562 : : }
14563 : 76068072 : if (TREE_CODE (name) != IDENTIFIER_NODE)
14564 : : {
14565 : 0 : error ("enum value name is not %<IDENTIFIER_NODE%>");
14566 : 0 : debug_tree (value);
14567 : 0 : debug_tree (name);
14568 : 0 : error_found = true;
14569 : : }
14570 : : }
14571 : 726335998 : else if (TREE_CODE (t) == ARRAY_TYPE)
14572 : : {
14573 : 1624828 : if (TYPE_DOMAIN (t) && TREE_CODE (TYPE_DOMAIN (t)) != INTEGER_TYPE)
14574 : : {
14575 : 0 : error ("array %<TYPE_DOMAIN%> is not integer type");
14576 : 0 : debug_tree (TYPE_DOMAIN (t));
14577 : 0 : error_found = true;
14578 : : }
14579 : : }
14580 : 724711170 : else if (RECORD_OR_UNION_TYPE_P (t))
14581 : : {
14582 : 383356200 : if (TYPE_FIELDS (t) && !COMPLETE_TYPE_P (t) && in_lto_p)
14583 : : {
14584 : 0 : error ("%<TYPE_FIELDS%> defined in incomplete type");
14585 : 0 : error_found = true;
14586 : : }
14587 : 17506729946 : for (tree fld = TYPE_FIELDS (t); fld; fld = TREE_CHAIN (fld))
14588 : : {
14589 : : /* TODO: verify properties of decls. */
14590 : 17123373746 : if (TREE_CODE (fld) == FIELD_DECL)
14591 : : ;
14592 : : else if (TREE_CODE (fld) == TYPE_DECL)
14593 : : ;
14594 : : else if (TREE_CODE (fld) == CONST_DECL)
14595 : : ;
14596 : : else if (VAR_P (fld))
14597 : : ;
14598 : : else if (TREE_CODE (fld) == TEMPLATE_DECL)
14599 : : ;
14600 : : else if (TREE_CODE (fld) == USING_DECL)
14601 : : ;
14602 : : else if (TREE_CODE (fld) == FUNCTION_DECL)
14603 : : ;
14604 : : else
14605 : : {
14606 : 0 : error ("wrong tree in %<TYPE_FIELDS%> list");
14607 : 0 : debug_tree (fld);
14608 : 0 : error_found = true;
14609 : : }
14610 : : }
14611 : : }
14612 : 341354970 : else if (TREE_CODE (t) == INTEGER_TYPE
14613 : : || TREE_CODE (t) == BOOLEAN_TYPE
14614 : 341354970 : || TREE_CODE (t) == BITINT_TYPE
14615 : 251026959 : || TREE_CODE (t) == OFFSET_TYPE
14616 : 250991121 : || TREE_CODE (t) == REFERENCE_TYPE
14617 : 207501402 : || TREE_CODE (t) == NULLPTR_TYPE
14618 : 207201413 : || TREE_CODE (t) == POINTER_TYPE)
14619 : : {
14620 : 228470517 : if (TYPE_CACHED_VALUES_P (t) != (TYPE_CACHED_VALUES (t) != NULL))
14621 : : {
14622 : 0 : error ("%<TYPE_CACHED_VALUES_P%> is %i while %<TYPE_CACHED_VALUES%> "
14623 : : "is %p",
14624 : 0 : TYPE_CACHED_VALUES_P (t), (void *)TYPE_CACHED_VALUES (t));
14625 : 0 : error_found = true;
14626 : : }
14627 : 228470517 : else if (TYPE_CACHED_VALUES_P (t) && TREE_CODE (TYPE_CACHED_VALUES (t)) != TREE_VEC)
14628 : : {
14629 : 0 : error ("%<TYPE_CACHED_VALUES%> is not %<TREE_VEC%>");
14630 : 0 : debug_tree (TYPE_CACHED_VALUES (t));
14631 : 0 : error_found = true;
14632 : : }
14633 : : /* Verify just enough of cache to ensure that no one copied it to new type.
14634 : : All copying should go by copy_node that should clear it. */
14635 : 228470517 : else if (TYPE_CACHED_VALUES_P (t))
14636 : : {
14637 : : int i;
14638 : 7653145257 : for (i = 0; i < TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t)); i++)
14639 : 7606870364 : if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)
14640 : 7606870364 : && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)) != t)
14641 : : {
14642 : 0 : error ("wrong %<TYPE_CACHED_VALUES%> entry");
14643 : 0 : debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i));
14644 : 0 : error_found = true;
14645 : 0 : break;
14646 : : }
14647 : : }
14648 : : }
14649 : 112884453 : else if (FUNC_OR_METHOD_TYPE_P (t))
14650 : 3120579 : for (tree l = TYPE_ARG_TYPES (t); l; l = TREE_CHAIN (l))
14651 : : {
14652 : : /* C++ FE uses TREE_PURPOSE to store initial values. */
14653 : 2292042 : if (TREE_PURPOSE (l) && in_lto_p)
14654 : : {
14655 : 0 : error ("%<TREE_PURPOSE%> is non-NULL in %<TYPE_ARG_TYPES%> list");
14656 : 0 : debug_tree (l);
14657 : 0 : error_found = true;
14658 : : }
14659 : 2292042 : if (!TYPE_P (TREE_VALUE (l)))
14660 : : {
14661 : 0 : error ("wrong entry in %<TYPE_ARG_TYPES%> list");
14662 : 0 : debug_tree (l);
14663 : 0 : error_found = true;
14664 : : }
14665 : : }
14666 : 223730641 : else if (!is_lang_specific (t) && TYPE_VALUES_RAW (t))
14667 : : {
14668 : 0 : error ("%<TYPE_VALUES_RAW%> field is non-NULL");
14669 : 0 : debug_tree (TYPE_VALUES_RAW (t));
14670 : 0 : error_found = true;
14671 : : }
14672 : 737117792 : if (TREE_CODE (t) != INTEGER_TYPE
14673 : : && TREE_CODE (t) != BOOLEAN_TYPE
14674 : 737117792 : && TREE_CODE (t) != BITINT_TYPE
14675 : : && TREE_CODE (t) != OFFSET_TYPE
14676 : : && TREE_CODE (t) != REFERENCE_TYPE
14677 : : && TREE_CODE (t) != NULLPTR_TYPE
14678 : : && TREE_CODE (t) != POINTER_TYPE
14679 : 508647275 : && TYPE_CACHED_VALUES_P (t))
14680 : : {
14681 : 0 : error ("%<TYPE_CACHED_VALUES_P%> is set while it should not be");
14682 : 0 : error_found = true;
14683 : : }
14684 : :
14685 : : /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
14686 : : TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
14687 : : of a type. */
14688 : 737117792 : if (TREE_CODE (t) == METHOD_TYPE
14689 : 737117792 : && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t)) != TYPE_METHOD_BASETYPE (t))
14690 : : {
14691 : 0 : error ("%<TYPE_METHOD_BASETYPE%> is not main variant");
14692 : 0 : error_found = true;
14693 : : }
14694 : :
14695 : 737117792 : if (error_found)
14696 : : {
14697 : 0 : debug_tree (const_cast <tree> (t));
14698 : 0 : internal_error ("%qs failed", __func__);
14699 : : }
14700 : : }
14701 : :
14702 : :
14703 : : /* Return 1 if ARG interpreted as signed in its precision is known to be
14704 : : always non-negative or 2 if ARG is known to be always negative, or 3 if
14705 : : ARG may be non-negative or negative. STMT if specified is the statement
14706 : : on which it is being tested. */
14707 : :
14708 : : int
14709 : 819260 : get_range_pos_neg (tree arg, gimple *stmt)
14710 : : {
14711 : 819260 : if (arg == error_mark_node || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
14712 : : return 3;
14713 : :
14714 : 819260 : int prec = TYPE_PRECISION (TREE_TYPE (arg));
14715 : 819260 : int cnt = 0;
14716 : 819260 : if (TREE_CODE (arg) == INTEGER_CST)
14717 : : {
14718 : 83738 : wide_int w = wi::sext (wi::to_wide (arg), prec);
14719 : 83738 : if (wi::neg_p (w))
14720 : : return 2;
14721 : : else
14722 : 69326 : return 1;
14723 : 83738 : }
14724 : 734311 : while (CONVERT_EXPR_P (arg)
14725 : 14494 : && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
14726 : 763299 : && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg, 0))) <= prec)
14727 : : {
14728 : 13710 : arg = TREE_OPERAND (arg, 0);
14729 : : /* Narrower value zero extended into wider type
14730 : : will always result in positive values. */
14731 : 13710 : if (TYPE_UNSIGNED (TREE_TYPE (arg))
14732 : 13710 : && TYPE_PRECISION (TREE_TYPE (arg)) < prec)
14733 : : return 1;
14734 : 13283 : prec = TYPE_PRECISION (TREE_TYPE (arg));
14735 : 13283 : if (++cnt > 30)
14736 : : return 3;
14737 : : }
14738 : :
14739 : 735095 : if (TREE_CODE (arg) != SSA_NAME)
14740 : : return 3;
14741 : 728572 : int_range_max r;
14742 : 1471506 : while (!get_range_query (cfun)->range_of_expr (r, arg, stmt)
14743 : 1485868 : || r.undefined_p () || r.varying_p ())
14744 : : {
14745 : 440596 : gimple *g = SSA_NAME_DEF_STMT (arg);
14746 : 440596 : if (is_gimple_assign (g)
14747 : 440596 : && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (g)))
14748 : : {
14749 : 24970 : tree t = gimple_assign_rhs1 (g);
14750 : 49586 : if (INTEGRAL_TYPE_P (TREE_TYPE (t))
14751 : 46948 : && TYPE_PRECISION (TREE_TYPE (t)) <= prec)
14752 : : {
14753 : 14362 : if (TYPE_UNSIGNED (TREE_TYPE (t))
14754 : 14362 : && TYPE_PRECISION (TREE_TYPE (t)) < prec)
14755 : : return 1;
14756 : 14362 : prec = TYPE_PRECISION (TREE_TYPE (t));
14757 : 14362 : arg = t;
14758 : 14362 : if (++cnt > 30)
14759 : : return 3;
14760 : 14362 : continue;
14761 : : }
14762 : : }
14763 : : return 3;
14764 : : }
14765 : 302338 : if (TYPE_UNSIGNED (TREE_TYPE (arg)))
14766 : : {
14767 : : /* For unsigned values, the "positive" range comes
14768 : : below the "negative" range. */
14769 : 132619 : if (!wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14770 : : return 1;
14771 : 37794 : if (wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14772 : : return 2;
14773 : : }
14774 : : else
14775 : : {
14776 : 169719 : if (!wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14777 : : return 1;
14778 : 70602 : if (wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14779 : : return 2;
14780 : : }
14781 : : return 3;
14782 : 728572 : }
14783 : :
14784 : :
14785 : :
14786 : :
14787 : : /* Return true if ARG is marked with the nonnull attribute in the
14788 : : current function signature. */
14789 : :
14790 : : bool
14791 : 26836301 : nonnull_arg_p (const_tree arg)
14792 : : {
14793 : 26836301 : tree t, attrs, fntype;
14794 : 26836301 : unsigned HOST_WIDE_INT arg_num;
14795 : :
14796 : 26836301 : gcc_assert (TREE_CODE (arg) == PARM_DECL
14797 : : && (POINTER_TYPE_P (TREE_TYPE (arg))
14798 : : || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE));
14799 : :
14800 : : /* The static chain decl is always non null. */
14801 : 26836301 : if (arg == cfun->static_chain_decl)
14802 : : return true;
14803 : :
14804 : : /* THIS argument of method is always non-NULL. */
14805 : 26568257 : if (TREE_CODE (TREE_TYPE (cfun->decl)) == METHOD_TYPE
14806 : 10576880 : && arg == DECL_ARGUMENTS (cfun->decl)
14807 : 33193454 : && flag_delete_null_pointer_checks)
14808 : : return true;
14809 : :
14810 : : /* Values passed by reference are always non-NULL. */
14811 : 19945181 : if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
14812 : 19945181 : && flag_delete_null_pointer_checks)
14813 : : return true;
14814 : :
14815 : 13654573 : fntype = TREE_TYPE (cfun->decl);
14816 : 13677517 : for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
14817 : : {
14818 : 537538 : attrs = lookup_attribute ("nonnull", attrs);
14819 : :
14820 : : /* If "nonnull" wasn't specified, we know nothing about the argument. */
14821 : 537538 : if (attrs == NULL_TREE)
14822 : : return false;
14823 : :
14824 : : /* If "nonnull" applies to all the arguments, then ARG is non-null. */
14825 : 113118 : if (TREE_VALUE (attrs) == NULL_TREE)
14826 : : return true;
14827 : :
14828 : : /* Get the position number for ARG in the function signature. */
14829 : 56045 : for (arg_num = 1, t = DECL_ARGUMENTS (cfun->decl);
14830 : 130524 : t;
14831 : 74479 : t = DECL_CHAIN (t), arg_num++)
14832 : : {
14833 : 130524 : if (t == arg)
14834 : : break;
14835 : : }
14836 : :
14837 : 56045 : gcc_assert (t == arg);
14838 : :
14839 : : /* Now see if ARG_NUM is mentioned in the nonnull list. */
14840 : 88679 : for (t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
14841 : : {
14842 : 65735 : if (compare_tree_int (TREE_VALUE (t), arg_num) == 0)
14843 : : return true;
14844 : : }
14845 : : }
14846 : :
14847 : : return false;
14848 : : }
14849 : :
14850 : : /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
14851 : : information. */
14852 : :
14853 : : location_t
14854 : 664450167 : set_block (location_t loc, tree block)
14855 : : {
14856 : 664450167 : location_t pure_loc = get_pure_location (loc);
14857 : 664450167 : source_range src_range = get_range_from_loc (line_table, loc);
14858 : 664450167 : unsigned discriminator = get_discriminator_from_loc (line_table, loc);
14859 : 664450167 : return line_table->get_or_create_combined_loc (pure_loc, src_range, block,
14860 : 664450167 : discriminator);
14861 : : }
14862 : :
14863 : : location_t
14864 : 216409001 : set_source_range (tree expr, location_t start, location_t finish)
14865 : : {
14866 : 216409001 : source_range src_range;
14867 : 216409001 : src_range.m_start = start;
14868 : 216409001 : src_range.m_finish = finish;
14869 : 216409001 : return set_source_range (expr, src_range);
14870 : : }
14871 : :
14872 : : location_t
14873 : 442064594 : set_source_range (tree expr, source_range src_range)
14874 : : {
14875 : 442064594 : if (!EXPR_P (expr))
14876 : : return UNKNOWN_LOCATION;
14877 : :
14878 : 194534833 : location_t expr_location = EXPR_LOCATION (expr);
14879 : 194534833 : location_t pure_loc = get_pure_location (expr_location);
14880 : 194534833 : unsigned discriminator = get_discriminator_from_loc (expr_location);
14881 : 194534833 : location_t adhoc = line_table->get_or_create_combined_loc (pure_loc,
14882 : : src_range,
14883 : : nullptr,
14884 : : discriminator);
14885 : 194534833 : SET_EXPR_LOCATION (expr, adhoc);
14886 : 194534833 : return adhoc;
14887 : : }
14888 : :
14889 : : /* Return EXPR, potentially wrapped with a node expression LOC,
14890 : : if !CAN_HAVE_LOCATION_P (expr).
14891 : :
14892 : : NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
14893 : : VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
14894 : :
14895 : : Wrapper nodes can be identified using location_wrapper_p. */
14896 : :
14897 : : tree
14898 : 1260409776 : maybe_wrap_with_location (tree expr, location_t loc)
14899 : : {
14900 : 1260409776 : if (expr == NULL)
14901 : : return NULL;
14902 : 1260409772 : if (loc == UNKNOWN_LOCATION)
14903 : : return expr;
14904 : 1218248549 : if (CAN_HAVE_LOCATION_P (expr))
14905 : : return expr;
14906 : : /* We should only be adding wrappers for constants and for decls,
14907 : : or for some exceptional tree nodes (e.g. BASELINK in the C++ FE). */
14908 : 736273201 : gcc_assert (CONSTANT_CLASS_P (expr)
14909 : : || DECL_P (expr)
14910 : : || EXCEPTIONAL_CLASS_P (expr));
14911 : :
14912 : : /* For now, don't add wrappers to exceptional tree nodes, to minimize
14913 : : any impact of the wrapper nodes. */
14914 : 736273201 : if (EXCEPTIONAL_CLASS_P (expr) || error_operand_p (expr))
14915 : : return expr;
14916 : :
14917 : : /* Compiler-generated temporary variables don't need a wrapper. */
14918 : 678000186 : if (DECL_P (expr) && DECL_ARTIFICIAL (expr) && DECL_IGNORED_P (expr))
14919 : : return expr;
14920 : :
14921 : : /* If any auto_suppress_location_wrappers are active, don't create
14922 : : wrappers. */
14923 : 677997904 : if (suppress_location_wrappers > 0)
14924 : : return expr;
14925 : :
14926 : 1294048406 : tree_code code
14927 : 159976187 : = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
14928 : 494155237 : || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
14929 : 647024203 : ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
14930 : 647024203 : tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
14931 : : /* Mark this node as being a wrapper. */
14932 : 647024203 : EXPR_LOCATION_WRAPPER_P (wrapper) = 1;
14933 : 647024203 : return wrapper;
14934 : : }
14935 : :
14936 : : int suppress_location_wrappers;
14937 : :
14938 : : /* Return the name of combined function FN, for debugging purposes. */
14939 : :
14940 : : const char *
14941 : 0 : combined_fn_name (combined_fn fn)
14942 : : {
14943 : 0 : if (builtin_fn_p (fn))
14944 : : {
14945 : 0 : tree fndecl = builtin_decl_explicit (as_builtin_fn (fn));
14946 : 0 : return IDENTIFIER_POINTER (DECL_NAME (fndecl));
14947 : : }
14948 : : else
14949 : 0 : return internal_fn_name (as_internal_fn (fn));
14950 : : }
14951 : :
14952 : : /* Return a bitmap with a bit set corresponding to each argument in
14953 : : a function call type FNTYPE declared with attribute nonnull,
14954 : : or null if none of the function's argument are nonnull. The caller
14955 : : must free the bitmap. */
14956 : :
14957 : : bitmap
14958 : 21339281 : get_nonnull_args (const_tree fntype)
14959 : : {
14960 : 21339281 : if (fntype == NULL_TREE)
14961 : : return NULL;
14962 : :
14963 : 20922071 : bitmap argmap = NULL;
14964 : 20922071 : if (TREE_CODE (fntype) == METHOD_TYPE)
14965 : : {
14966 : : /* The this pointer in C++ non-static member functions is
14967 : : implicitly nonnull whether or not it's declared as such. */
14968 : 3060588 : argmap = BITMAP_ALLOC (NULL);
14969 : 3060588 : bitmap_set_bit (argmap, 0);
14970 : : }
14971 : :
14972 : 20922071 : tree attrs = TYPE_ATTRIBUTES (fntype);
14973 : 20922071 : if (!attrs)
14974 : : return argmap;
14975 : :
14976 : : /* A function declaration can specify multiple attribute nonnull,
14977 : : each with zero or more arguments. The loop below creates a bitmap
14978 : : representing a union of all the arguments. An empty (but non-null)
14979 : : bitmap means that all arguments have been declared nonnull. */
14980 : 5740242 : for ( ; attrs; attrs = TREE_CHAIN (attrs))
14981 : : {
14982 : 5635514 : attrs = lookup_attribute ("nonnull", attrs);
14983 : 5635514 : if (!attrs)
14984 : : break;
14985 : :
14986 : 1622904 : if (!argmap)
14987 : 1583088 : argmap = BITMAP_ALLOC (NULL);
14988 : :
14989 : 1622904 : if (!TREE_VALUE (attrs))
14990 : : {
14991 : : /* Clear the bitmap in case a previous attribute nonnull
14992 : : set it and this one overrides it for all arguments. */
14993 : 995020 : bitmap_clear (argmap);
14994 : 995020 : return argmap;
14995 : : }
14996 : :
14997 : : /* Iterate over the indices of the format arguments declared nonnull
14998 : : and set a bit for each. */
14999 : 1649972 : for (tree idx = TREE_VALUE (attrs); idx; idx = TREE_CHAIN (idx))
15000 : : {
15001 : 1022088 : unsigned int val = TREE_INT_CST_LOW (TREE_VALUE (idx)) - 1;
15002 : 1022088 : bitmap_set_bit (argmap, val);
15003 : : }
15004 : : }
15005 : :
15006 : : return argmap;
15007 : : }
15008 : :
15009 : : /* Returns true if TYPE is a type where it and all of its subobjects
15010 : : (recursively) are of structure, union, or array type. */
15011 : :
15012 : : bool
15013 : 1801587938 : is_empty_type (const_tree type)
15014 : : {
15015 : 1801587938 : if (RECORD_OR_UNION_TYPE_P (type))
15016 : : {
15017 : 774057276 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
15018 : 718757528 : if (TREE_CODE (field) == FIELD_DECL
15019 : 396649774 : && !DECL_PADDING_P (field)
15020 : 1115406061 : && !is_empty_type (TREE_TYPE (field)))
15021 : : return false;
15022 : : return true;
15023 : : }
15024 : 1372756958 : else if (TREE_CODE (type) == ARRAY_TYPE)
15025 : 73653845 : return (integer_minus_onep (array_type_nelts_minus_one (type))
15026 : 73610473 : || TYPE_DOMAIN (type) == NULL_TREE
15027 : 141441363 : || is_empty_type (TREE_TYPE (type)));
15028 : : return false;
15029 : : }
15030 : :
15031 : : /* Implement TARGET_EMPTY_RECORD_P. Return true if TYPE is an empty type
15032 : : that shouldn't be passed via stack. */
15033 : :
15034 : : bool
15035 : 1287271388 : default_is_empty_record (const_tree type)
15036 : : {
15037 : 1287271388 : if (!abi_version_at_least (12))
15038 : : return false;
15039 : :
15040 : 1286225967 : if (type == error_mark_node)
15041 : : return false;
15042 : :
15043 : 1286225967 : if (TREE_ADDRESSABLE (type))
15044 : : return false;
15045 : :
15046 : 1286225967 : return is_empty_type (TYPE_MAIN_VARIANT (type));
15047 : : }
15048 : :
15049 : : /* Determine whether TYPE is a structure with a flexible array member,
15050 : : or a union containing such a structure (possibly recursively). */
15051 : :
15052 : : bool
15053 : 73296 : flexible_array_type_p (const_tree type)
15054 : : {
15055 : 73296 : tree x, last;
15056 : 73296 : switch (TREE_CODE (type))
15057 : : {
15058 : 37450 : case RECORD_TYPE:
15059 : 37450 : last = NULL_TREE;
15060 : 171319 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15061 : 133869 : if (TREE_CODE (x) == FIELD_DECL)
15062 : 133869 : last = x;
15063 : 37450 : if (last == NULL_TREE)
15064 : : return false;
15065 : 37442 : if (TREE_CODE (TREE_TYPE (last)) == ARRAY_TYPE
15066 : 473 : && TYPE_SIZE (TREE_TYPE (last)) == NULL_TREE
15067 : 239 : && TYPE_DOMAIN (TREE_TYPE (last)) != NULL_TREE
15068 : 37681 : && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (last))) == NULL_TREE)
15069 : : return true;
15070 : : return false;
15071 : 617 : case UNION_TYPE:
15072 : 1784 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15073 : : {
15074 : 1209 : if (TREE_CODE (x) == FIELD_DECL
15075 : 1209 : && flexible_array_type_p (TREE_TYPE (x)))
15076 : : return true;
15077 : : }
15078 : : return false;
15079 : : default:
15080 : : return false;
15081 : : }
15082 : : }
15083 : :
15084 : : /* Like int_size_in_bytes, but handle empty records specially. */
15085 : :
15086 : : HOST_WIDE_INT
15087 : 371390 : arg_int_size_in_bytes (const_tree type)
15088 : : {
15089 : 371390 : return TYPE_EMPTY_P (type) ? 0 : int_size_in_bytes (type);
15090 : : }
15091 : :
15092 : : /* Like size_in_bytes, but handle empty records specially. */
15093 : :
15094 : : tree
15095 : 5665964 : arg_size_in_bytes (const_tree type)
15096 : : {
15097 : 5665964 : return TYPE_EMPTY_P (type) ? size_zero_node : size_in_bytes (type);
15098 : : }
15099 : :
15100 : : /* Return true if an expression with CODE has to have the same result type as
15101 : : its first operand. */
15102 : :
15103 : : bool
15104 : 0 : expr_type_first_operand_type_p (tree_code code)
15105 : : {
15106 : 0 : switch (code)
15107 : : {
15108 : : case NEGATE_EXPR:
15109 : : case ABS_EXPR:
15110 : : case BIT_NOT_EXPR:
15111 : : case PAREN_EXPR:
15112 : : case CONJ_EXPR:
15113 : :
15114 : : case PLUS_EXPR:
15115 : : case MINUS_EXPR:
15116 : : case MULT_EXPR:
15117 : : case TRUNC_DIV_EXPR:
15118 : : case CEIL_DIV_EXPR:
15119 : : case FLOOR_DIV_EXPR:
15120 : : case ROUND_DIV_EXPR:
15121 : : case TRUNC_MOD_EXPR:
15122 : : case CEIL_MOD_EXPR:
15123 : : case FLOOR_MOD_EXPR:
15124 : : case ROUND_MOD_EXPR:
15125 : : case RDIV_EXPR:
15126 : : case EXACT_DIV_EXPR:
15127 : : case MIN_EXPR:
15128 : : case MAX_EXPR:
15129 : : case BIT_IOR_EXPR:
15130 : : case BIT_XOR_EXPR:
15131 : : case BIT_AND_EXPR:
15132 : :
15133 : : case LSHIFT_EXPR:
15134 : : case RSHIFT_EXPR:
15135 : : case LROTATE_EXPR:
15136 : : case RROTATE_EXPR:
15137 : : return true;
15138 : :
15139 : 0 : default:
15140 : 0 : return false;
15141 : : }
15142 : : }
15143 : :
15144 : : /* Return a typenode for the "standard" C type with a given name. */
15145 : : tree
15146 : 895564 : get_typenode_from_name (const char *name)
15147 : : {
15148 : 895564 : if (name == NULL || *name == '\0')
15149 : : return NULL_TREE;
15150 : :
15151 : 895564 : if (strcmp (name, "char") == 0)
15152 : 0 : return char_type_node;
15153 : 895564 : if (strcmp (name, "unsigned char") == 0)
15154 : 92457 : return unsigned_char_type_node;
15155 : 803107 : if (strcmp (name, "signed char") == 0)
15156 : 92457 : return signed_char_type_node;
15157 : :
15158 : 710650 : if (strcmp (name, "short int") == 0)
15159 : 63151 : return short_integer_type_node;
15160 : 647499 : if (strcmp (name, "short unsigned int") == 0)
15161 : 61638 : return short_unsigned_type_node;
15162 : :
15163 : 585861 : if (strcmp (name, "int") == 0)
15164 : 63973 : return integer_type_node;
15165 : 521888 : if (strcmp (name, "unsigned int") == 0)
15166 : 62452 : return unsigned_type_node;
15167 : :
15168 : 459436 : if (strcmp (name, "long int") == 0)
15169 : 273708 : return long_integer_type_node;
15170 : 185728 : if (strcmp (name, "long unsigned int") == 0)
15171 : 182472 : return long_unsigned_type_node;
15172 : :
15173 : 3256 : if (strcmp (name, "long long int") == 0)
15174 : 1628 : return long_long_integer_type_node;
15175 : 1628 : if (strcmp (name, "long long unsigned int") == 0)
15176 : 1628 : return long_long_unsigned_type_node;
15177 : :
15178 : 0 : gcc_unreachable ();
15179 : : }
15180 : :
15181 : : /* List of pointer types used to declare builtins before we have seen their
15182 : : real declaration.
15183 : :
15184 : : Keep the size up to date in tree.h ! */
15185 : : const builtin_structptr_type builtin_structptr_types[6] =
15186 : : {
15187 : : { fileptr_type_node, ptr_type_node, "FILE" },
15188 : : { const_tm_ptr_type_node, const_ptr_type_node, "tm" },
15189 : : { fenv_t_ptr_type_node, ptr_type_node, "fenv_t" },
15190 : : { const_fenv_t_ptr_type_node, const_ptr_type_node, "fenv_t" },
15191 : : { fexcept_t_ptr_type_node, ptr_type_node, "fexcept_t" },
15192 : : { const_fexcept_t_ptr_type_node, const_ptr_type_node, "fexcept_t" }
15193 : : };
15194 : :
15195 : : /* Return the maximum object size. */
15196 : :
15197 : : tree
15198 : 7191121 : max_object_size (void)
15199 : : {
15200 : : /* To do: Make this a configurable parameter. */
15201 : 7191121 : return TYPE_MAX_VALUE (ptrdiff_type_node);
15202 : : }
15203 : :
15204 : : /* A wrapper around TARGET_VERIFY_TYPE_CONTEXT that makes the silent_p
15205 : : parameter default to false and that weeds out error_mark_node. */
15206 : :
15207 : : bool
15208 : 115953634 : verify_type_context (location_t loc, type_context_kind context,
15209 : : const_tree type, bool silent_p)
15210 : : {
15211 : 115953634 : if (type == error_mark_node)
15212 : : return true;
15213 : :
15214 : 115953542 : gcc_assert (TYPE_P (type));
15215 : 115953542 : return (!targetm.verify_type_context
15216 : 115953542 : || targetm.verify_type_context (loc, context, type, silent_p));
15217 : : }
15218 : :
15219 : : /* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and
15220 : : delete operators. Return false if they may or may not name such
15221 : : a pair and, when nonnull, set *PCERTAIN to true if they certainly
15222 : : do not. */
15223 : :
15224 : : bool
15225 : 61170 : valid_new_delete_pair_p (tree new_asm, tree delete_asm,
15226 : : bool *pcertain /* = NULL */)
15227 : : {
15228 : 61170 : bool certain;
15229 : 61170 : if (!pcertain)
15230 : 49557 : pcertain = &certain;
15231 : :
15232 : 61170 : const char *new_name = IDENTIFIER_POINTER (new_asm);
15233 : 61170 : const char *delete_name = IDENTIFIER_POINTER (delete_asm);
15234 : 61170 : unsigned int new_len = IDENTIFIER_LENGTH (new_asm);
15235 : 61170 : unsigned int delete_len = IDENTIFIER_LENGTH (delete_asm);
15236 : :
15237 : : /* The following failures are due to invalid names so they're not
15238 : : considered certain mismatches. */
15239 : 61170 : *pcertain = false;
15240 : :
15241 : 61170 : if (new_len < 5 || delete_len < 6)
15242 : : return false;
15243 : 61170 : if (new_name[0] == '_')
15244 : 61098 : ++new_name, --new_len;
15245 : 61170 : if (new_name[0] == '_')
15246 : 0 : ++new_name, --new_len;
15247 : 61170 : if (delete_name[0] == '_')
15248 : 61170 : ++delete_name, --delete_len;
15249 : 61170 : if (delete_name[0] == '_')
15250 : 0 : ++delete_name, --delete_len;
15251 : 61170 : if (new_len < 4 || delete_len < 5)
15252 : : return false;
15253 : :
15254 : : /* The following failures are due to names of user-defined operators
15255 : : so they're also not considered certain mismatches. */
15256 : :
15257 : : /* *_len is now just the length after initial underscores. */
15258 : 61170 : if (new_name[0] != 'Z' || new_name[1] != 'n')
15259 : : return false;
15260 : 60503 : if (delete_name[0] != 'Z' || delete_name[1] != 'd')
15261 : : return false;
15262 : :
15263 : : /* The following failures are certain mismatches. */
15264 : 60435 : *pcertain = true;
15265 : :
15266 : : /* _Znw must match _Zdl, _Zna must match _Zda. */
15267 : 60435 : if ((new_name[2] != 'w' || delete_name[2] != 'l')
15268 : 7198 : && (new_name[2] != 'a' || delete_name[2] != 'a'))
15269 : : return false;
15270 : : /* 'j', 'm' and 'y' correspond to size_t. */
15271 : 60321 : if (new_name[3] != 'j' && new_name[3] != 'm' && new_name[3] != 'y')
15272 : : return false;
15273 : 60321 : if (delete_name[3] != 'P' || delete_name[4] != 'v')
15274 : : return false;
15275 : 60321 : if (new_len == 4
15276 : 423 : || (new_len == 18 && !memcmp (new_name + 4, "RKSt9nothrow_t", 14)))
15277 : : {
15278 : : /* _ZnXY or _ZnXYRKSt9nothrow_t matches
15279 : : _ZdXPv, _ZdXPvY and _ZdXPvRKSt9nothrow_t. */
15280 : 60064 : if (delete_len == 5)
15281 : : return true;
15282 : 51057 : if (delete_len == 6 && delete_name[5] == new_name[3])
15283 : : return true;
15284 : 39 : if (delete_len == 19 && !memcmp (delete_name + 5, "RKSt9nothrow_t", 14))
15285 : : return true;
15286 : : }
15287 : 257 : else if ((new_len == 19 && !memcmp (new_name + 4, "St11align_val_t", 15))
15288 : 42 : || (new_len == 33
15289 : 10 : && !memcmp (new_name + 4, "St11align_val_tRKSt9nothrow_t", 29)))
15290 : : {
15291 : : /* _ZnXYSt11align_val_t or _ZnXYSt11align_val_tRKSt9nothrow_t matches
15292 : : _ZdXPvSt11align_val_t or _ZdXPvYSt11align_val_t or
15293 : : _ZdXPvSt11align_val_tRKSt9nothrow_t. */
15294 : 225 : if (delete_len == 20 && !memcmp (delete_name + 5, "St11align_val_t", 15))
15295 : : return true;
15296 : 46 : if (delete_len == 21
15297 : 31 : && delete_name[5] == new_name[3]
15298 : 31 : && !memcmp (delete_name + 6, "St11align_val_t", 15))
15299 : : return true;
15300 : 15 : if (delete_len == 34
15301 : 9 : && !memcmp (delete_name + 5, "St11align_val_tRKSt9nothrow_t", 29))
15302 : : return true;
15303 : : }
15304 : :
15305 : : /* The negative result is conservative. */
15306 : 38 : *pcertain = false;
15307 : 38 : return false;
15308 : : }
15309 : :
15310 : : /* Return the zero-based number corresponding to the argument being
15311 : : deallocated if FNDECL is a deallocation function or an out-of-bounds
15312 : : value if it isn't. */
15313 : :
15314 : : unsigned
15315 : 28598685 : fndecl_dealloc_argno (tree fndecl)
15316 : : {
15317 : : /* A call to operator delete isn't recognized as one to a built-in. */
15318 : 28598685 : if (DECL_IS_OPERATOR_DELETE_P (fndecl))
15319 : : {
15320 : 480085 : if (DECL_IS_REPLACEABLE_OPERATOR (fndecl))
15321 : : return 0;
15322 : :
15323 : : /* Avoid placement delete that's not been inlined. */
15324 : 25679 : tree fname = DECL_ASSEMBLER_NAME (fndecl);
15325 : 25679 : if (id_equal (fname, "_ZdlPvS_") // ordinary form
15326 : 25679 : || id_equal (fname, "_ZdaPvS_")) // array form
15327 : : return UINT_MAX;
15328 : : return 0;
15329 : : }
15330 : :
15331 : : /* TODO: Handle user-defined functions with attribute malloc? Handle
15332 : : known non-built-ins like fopen? */
15333 : 28118600 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
15334 : : {
15335 : 7265093 : switch (DECL_FUNCTION_CODE (fndecl))
15336 : : {
15337 : : case BUILT_IN_FREE:
15338 : : case BUILT_IN_REALLOC:
15339 : : case BUILT_IN_GOMP_FREE:
15340 : : case BUILT_IN_GOMP_REALLOC:
15341 : : return 0;
15342 : : default:
15343 : : break;
15344 : : }
15345 : : return UINT_MAX;
15346 : : }
15347 : :
15348 : 20853507 : tree attrs = DECL_ATTRIBUTES (fndecl);
15349 : 20853507 : if (!attrs)
15350 : : return UINT_MAX;
15351 : :
15352 : 0 : for (tree atfree = attrs;
15353 : 4705212 : (atfree = lookup_attribute ("*dealloc", atfree));
15354 : 0 : atfree = TREE_CHAIN (atfree))
15355 : : {
15356 : 6039 : tree alloc = TREE_VALUE (atfree);
15357 : 6039 : if (!alloc)
15358 : 0 : continue;
15359 : :
15360 : 6039 : tree pos = TREE_CHAIN (alloc);
15361 : 6039 : if (!pos)
15362 : : return 0;
15363 : :
15364 : 3519 : pos = TREE_VALUE (pos);
15365 : 3519 : return TREE_INT_CST_LOW (pos) - 1;
15366 : : }
15367 : :
15368 : : return UINT_MAX;
15369 : : }
15370 : :
15371 : : /* If EXPR refers to a character array or pointer declared attribute
15372 : : nonstring, return a decl for that array or pointer and set *REF
15373 : : to the referenced enclosing object or pointer. Otherwise return
15374 : : null. */
15375 : :
15376 : : tree
15377 : 1397992 : get_attr_nonstring_decl (tree expr, tree *ref)
15378 : : {
15379 : 1403721 : tree decl = expr;
15380 : 1403721 : tree var = NULL_TREE;
15381 : 1403721 : if (TREE_CODE (decl) == SSA_NAME)
15382 : : {
15383 : 836987 : gimple *def = SSA_NAME_DEF_STMT (decl);
15384 : :
15385 : 836987 : if (is_gimple_assign (def))
15386 : : {
15387 : 45362 : tree_code code = gimple_assign_rhs_code (def);
15388 : 45362 : if (code == ADDR_EXPR
15389 : 45362 : || code == COMPONENT_REF
15390 : 30972 : || code == VAR_DECL)
15391 : 19011 : decl = gimple_assign_rhs1 (def);
15392 : : }
15393 : : else
15394 : 791625 : var = SSA_NAME_VAR (decl);
15395 : : }
15396 : :
15397 : 1403721 : if (TREE_CODE (decl) == ADDR_EXPR)
15398 : 26992 : decl = TREE_OPERAND (decl, 0);
15399 : :
15400 : : /* To simplify calling code, store the referenced DECL regardless of
15401 : : the attribute determined below, but avoid storing the SSA_NAME_VAR
15402 : : obtained above (it's not useful for dataflow purposes). */
15403 : 1403721 : if (ref)
15404 : 5446 : *ref = decl;
15405 : :
15406 : : /* Use the SSA_NAME_VAR that was determined above to see if it's
15407 : : declared nonstring. Otherwise drill down into the referenced
15408 : : DECL. */
15409 : 1403721 : if (var)
15410 : : decl = var;
15411 : : else
15412 : : {
15413 : 637543 : while (TREE_CODE (decl) == ARRAY_REF)
15414 : 18858 : decl = TREE_OPERAND (decl, 0);
15415 : 618685 : if (TREE_CODE (decl) == COMPONENT_REF)
15416 : 16284 : decl = TREE_OPERAND (decl, 1);
15417 : 602401 : else if (TREE_CODE (decl) == MEM_REF)
15418 : 5729 : return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref);
15419 : : }
15420 : :
15421 : 1397992 : if (DECL_P (decl) && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl)))
15422 : : return decl;
15423 : :
15424 : : return NULL_TREE;
15425 : : }
15426 : :
15427 : : /* Return length of attribute names string,
15428 : : if arglist chain > 1, -1 otherwise. */
15429 : :
15430 : : int
15431 : 94 : get_target_clone_attr_len (tree arglist)
15432 : : {
15433 : 94 : tree arg;
15434 : 94 : int str_len_sum = 0;
15435 : 94 : int argnum = 0;
15436 : :
15437 : 343 : for (arg = arglist; arg; arg = TREE_CHAIN (arg))
15438 : : {
15439 : 249 : const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
15440 : 249 : size_t len = strlen (str);
15441 : 249 : str_len_sum += len + 1;
15442 : 249 : for (const char *p = strchr (str, TARGET_CLONES_ATTR_SEPARATOR);
15443 : 263 : p;
15444 : 14 : p = strchr (p + 1, TARGET_CLONES_ATTR_SEPARATOR))
15445 : 14 : argnum++;
15446 : 249 : argnum++;
15447 : : }
15448 : 94 : if (argnum <= 1)
15449 : 0 : return -1;
15450 : : return str_len_sum;
15451 : : }
15452 : :
15453 : : /* Returns an auto_vec of string_slices containing the version strings from
15454 : : ARGLIST. DEFAULT_COUNT is incremented for each default version found. */
15455 : :
15456 : : auto_vec<string_slice>
15457 : 108 : get_clone_attr_versions (const tree arglist, int *default_count)
15458 : : {
15459 : 108 : gcc_assert (TREE_CODE (arglist) == TREE_LIST);
15460 : 108 : auto_vec<string_slice> versions;
15461 : :
15462 : 108 : static const char separator_str[] = {TARGET_CLONES_ATTR_SEPARATOR, 0};
15463 : 108 : string_slice separators = string_slice (separator_str);
15464 : :
15465 : 397 : for (tree arg = arglist; arg; arg = TREE_CHAIN (arg))
15466 : : {
15467 : 289 : string_slice str = string_slice (TREE_STRING_POINTER (TREE_VALUE (arg)));
15468 : 881 : while (str.is_valid ())
15469 : : {
15470 : 303 : string_slice attr = string_slice::tokenize (&str, separators);
15471 : 303 : attr = attr.strip ();
15472 : :
15473 : 303 : if (attr == "default" && default_count)
15474 : 0 : (*default_count)++;
15475 : 303 : versions.safe_push (attr);
15476 : : }
15477 : : }
15478 : 108 : return versions;
15479 : : }
15480 : :
15481 : : /* Returns an auto_vec of string_slices containing the version strings from
15482 : : the target_clone attribute from DECL. DEFAULT_COUNT is incremented for each
15483 : : default version found. */
15484 : : auto_vec<string_slice>
15485 : 0 : get_clone_versions (const tree decl, int *default_count)
15486 : : {
15487 : 0 : tree attr = lookup_attribute ("target_clones", DECL_ATTRIBUTES (decl));
15488 : 0 : if (!attr)
15489 : 0 : return auto_vec<string_slice> ();
15490 : 0 : tree arglist = TREE_VALUE (attr);
15491 : 0 : return get_clone_attr_versions (arglist, default_count);
15492 : : }
15493 : :
15494 : : /* If DECL has a target_version attribute, returns a string_slice containing the
15495 : : attribute value. Otherwise, returns string_slice::invalid.
15496 : : Only works for target_version due to target attributes allowing multiple
15497 : : string arguments to specify one target. */
15498 : : string_slice
15499 : 0 : get_target_version (const tree decl)
15500 : : {
15501 : 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15502 : :
15503 : : tree attr = lookup_attribute ("target_version", DECL_ATTRIBUTES (decl));
15504 : :
15505 : : if (!attr)
15506 : : return string_slice::invalid ();
15507 : :
15508 : : return string_slice (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))))
15509 : : .strip ();
15510 : : }
15511 : :
15512 : : void
15513 : 257130 : tree_cc_finalize (void)
15514 : : {
15515 : 257130 : clear_nonstandard_integer_type_cache ();
15516 : 257130 : vec_free (bitint_type_cache);
15517 : 257130 : }
15518 : :
15519 : : void
15520 : 149 : gt_ggc_mx (tree_raw_data *x)
15521 : : {
15522 : 149 : gt_ggc_m_9tree_node (x->typed.type);
15523 : 149 : gt_ggc_m_9tree_node (x->owner);
15524 : 149 : }
15525 : :
15526 : : void
15527 : 12 : gt_pch_nx (tree_raw_data *x)
15528 : : {
15529 : 12 : gt_pch_n_9tree_node (x->typed.type);
15530 : 12 : gt_pch_n_9tree_node (x->owner);
15531 : 12 : }
15532 : :
15533 : : /* For PCH we guarantee that RAW_DATA_CST's RAW_DATA_OWNER is a STRING_CST and
15534 : : RAW_DATA_POINTER points into it. We don't want to save/restore
15535 : : RAW_DATA_POINTER on its own but want to restore it pointing at the same
15536 : : offset of the STRING_CST as before. */
15537 : :
15538 : : void
15539 : 12 : gt_pch_nx (tree_raw_data *x, gt_pointer_operator op, void *cookie)
15540 : : {
15541 : 12 : op (&x->typed.type, NULL, cookie);
15542 : 12 : gcc_checking_assert (x->owner
15543 : : && TREE_CODE (x->owner) == STRING_CST
15544 : : && x->str >= TREE_STRING_POINTER (x->owner)
15545 : : && (x->str + x->length
15546 : : <= (TREE_STRING_POINTER (x->owner)
15547 : : + TREE_STRING_LENGTH (x->owner))));
15548 : 12 : ptrdiff_t off = x->str - (const char *) (x->owner);
15549 : 12 : tree owner = x->owner;
15550 : 12 : op (&x->owner, NULL, cookie);
15551 : 12 : x->owner = owner;
15552 : : /* The above op call relocates x->owner and remembers the address
15553 : : for relocation e.g. if the compiler is position independent.
15554 : : We then restore x->owner back to its previous value and call
15555 : : op again, for x->owner itself this just repeats (uselessly) what
15556 : : the first call did, but as the second argument is now non-NULL
15557 : : and different, it also arranges for &x->str to be noted for the
15558 : : PIE relocation. */
15559 : 12 : op (&x->owner, &x->str, cookie);
15560 : 12 : x->str = (const char *) (x->owner) + off;
15561 : 12 : }
15562 : :
15563 : : #if CHECKING_P
15564 : :
15565 : : namespace selftest {
15566 : :
15567 : : /* Selftests for tree. */
15568 : :
15569 : : /* Verify that integer constants are sane. */
15570 : :
15571 : : static void
15572 : 4 : test_integer_constants ()
15573 : : {
15574 : 4 : ASSERT_TRUE (integer_type_node != NULL);
15575 : 4 : ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
15576 : :
15577 : 4 : tree type = integer_type_node;
15578 : :
15579 : 4 : tree zero = build_zero_cst (type);
15580 : 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
15581 : 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15582 : :
15583 : 4 : tree one = build_int_cst (type, 1);
15584 : 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
15585 : 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15586 : 4 : }
15587 : :
15588 : : /* Verify identifiers. */
15589 : :
15590 : : static void
15591 : 4 : test_identifiers ()
15592 : : {
15593 : 4 : tree identifier = get_identifier ("foo");
15594 : 4 : ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
15595 : 4 : ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
15596 : 4 : }
15597 : :
15598 : : /* Verify LABEL_DECL. */
15599 : :
15600 : : static void
15601 : 4 : test_labels ()
15602 : : {
15603 : 4 : tree identifier = get_identifier ("err");
15604 : 4 : tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
15605 : : identifier, void_type_node);
15606 : 4 : ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
15607 : 4 : ASSERT_FALSE (FORCED_LABEL (label_decl));
15608 : 4 : }
15609 : :
15610 : : /* Return a new VECTOR_CST node whose type is TYPE and whose values
15611 : : are given by VALS. */
15612 : :
15613 : : static tree
15614 : 40 : build_vector (tree type, const vec<tree> &vals MEM_STAT_DECL)
15615 : : {
15616 : 80 : gcc_assert (known_eq (vals.length (), TYPE_VECTOR_SUBPARTS (type)));
15617 : 40 : tree_vector_builder builder (type, vals.length (), 1);
15618 : 40 : builder.splice (vals);
15619 : 40 : return builder.build ();
15620 : 40 : }
15621 : :
15622 : : /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED. */
15623 : :
15624 : : static void
15625 : 40 : check_vector_cst (const vec<tree> &expected, tree actual)
15626 : : {
15627 : 80 : ASSERT_KNOWN_EQ (expected.length (),
15628 : : TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual)));
15629 : 360 : for (unsigned int i = 0; i < expected.length (); ++i)
15630 : 320 : ASSERT_EQ (wi::to_wide (expected[i]),
15631 : : wi::to_wide (vector_cst_elt (actual, i)));
15632 : 40 : }
15633 : :
15634 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
15635 : : and that its elements match EXPECTED. */
15636 : :
15637 : : static void
15638 : 8 : check_vector_cst_duplicate (const vec<tree> &expected, tree actual,
15639 : : unsigned int npatterns)
15640 : : {
15641 : 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15642 : 8 : ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual));
15643 : 8 : ASSERT_EQ (npatterns, vector_cst_encoded_nelts (actual));
15644 : 8 : ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual));
15645 : 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15646 : 8 : check_vector_cst (expected, actual);
15647 : 8 : }
15648 : :
15649 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
15650 : : and NPATTERNS background elements, and that its elements match
15651 : : EXPECTED. */
15652 : :
15653 : : static void
15654 : 8 : check_vector_cst_fill (const vec<tree> &expected, tree actual,
15655 : : unsigned int npatterns)
15656 : : {
15657 : 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15658 : 8 : ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual));
15659 : 8 : ASSERT_EQ (2 * npatterns, vector_cst_encoded_nelts (actual));
15660 : 8 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15661 : 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15662 : 8 : check_vector_cst (expected, actual);
15663 : 8 : }
15664 : :
15665 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
15666 : : and that its elements match EXPECTED. */
15667 : :
15668 : : static void
15669 : 24 : check_vector_cst_stepped (const vec<tree> &expected, tree actual,
15670 : : unsigned int npatterns)
15671 : : {
15672 : 24 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15673 : 24 : ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual));
15674 : 24 : ASSERT_EQ (3 * npatterns, vector_cst_encoded_nelts (actual));
15675 : 24 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15676 : 24 : ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual));
15677 : 24 : check_vector_cst (expected, actual);
15678 : 24 : }
15679 : :
15680 : : /* Test the creation of VECTOR_CSTs. */
15681 : :
15682 : : static void
15683 : 4 : test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO)
15684 : : {
15685 : 4 : auto_vec<tree, 8> elements (8);
15686 : 4 : elements.quick_grow (8);
15687 : 4 : tree element_type = build_nonstandard_integer_type (16, true);
15688 : 4 : tree vector_type = build_vector_type (element_type, 8);
15689 : :
15690 : : /* Test a simple linear series with a base of 0 and a step of 1:
15691 : : { 0, 1, 2, 3, 4, 5, 6, 7 }. */
15692 : 36 : for (unsigned int i = 0; i < 8; ++i)
15693 : 32 : elements[i] = build_int_cst (element_type, i);
15694 : 4 : tree vector = build_vector (vector_type, elements PASS_MEM_STAT);
15695 : 4 : check_vector_cst_stepped (elements, vector, 1);
15696 : :
15697 : : /* Try the same with the first element replaced by 100:
15698 : : { 100, 1, 2, 3, 4, 5, 6, 7 }. */
15699 : 4 : elements[0] = build_int_cst (element_type, 100);
15700 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15701 : 4 : check_vector_cst_stepped (elements, vector, 1);
15702 : :
15703 : : /* Try a series that wraps around.
15704 : : { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }. */
15705 : 32 : for (unsigned int i = 1; i < 8; ++i)
15706 : 28 : elements[i] = build_int_cst (element_type, (65530 + i) & 0xffff);
15707 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15708 : 4 : check_vector_cst_stepped (elements, vector, 1);
15709 : :
15710 : : /* Try a downward series:
15711 : : { 100, 79, 78, 77, 76, 75, 75, 73 }. */
15712 : 32 : for (unsigned int i = 1; i < 8; ++i)
15713 : 28 : elements[i] = build_int_cst (element_type, 80 - i);
15714 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15715 : 4 : check_vector_cst_stepped (elements, vector, 1);
15716 : :
15717 : : /* Try two interleaved series with different bases and steps:
15718 : : { 100, 53, 66, 206, 62, 212, 58, 218 }. */
15719 : 4 : elements[1] = build_int_cst (element_type, 53);
15720 : 16 : for (unsigned int i = 2; i < 8; i += 2)
15721 : : {
15722 : 12 : elements[i] = build_int_cst (element_type, 70 - i * 2);
15723 : 12 : elements[i + 1] = build_int_cst (element_type, 200 + i * 3);
15724 : : }
15725 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15726 : 4 : check_vector_cst_stepped (elements, vector, 2);
15727 : :
15728 : : /* Try a duplicated value:
15729 : : { 100, 100, 100, 100, 100, 100, 100, 100 }. */
15730 : 32 : for (unsigned int i = 1; i < 8; ++i)
15731 : 28 : elements[i] = elements[0];
15732 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15733 : 4 : check_vector_cst_duplicate (elements, vector, 1);
15734 : :
15735 : : /* Try an interleaved duplicated value:
15736 : : { 100, 55, 100, 55, 100, 55, 100, 55 }. */
15737 : 4 : elements[1] = build_int_cst (element_type, 55);
15738 : 28 : for (unsigned int i = 2; i < 8; ++i)
15739 : 24 : elements[i] = elements[i - 2];
15740 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15741 : 4 : check_vector_cst_duplicate (elements, vector, 2);
15742 : :
15743 : : /* Try a duplicated value with 2 exceptions
15744 : : { 41, 97, 100, 55, 100, 55, 100, 55 }. */
15745 : 4 : elements[0] = build_int_cst (element_type, 41);
15746 : 4 : elements[1] = build_int_cst (element_type, 97);
15747 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15748 : 4 : check_vector_cst_fill (elements, vector, 2);
15749 : :
15750 : : /* Try with and without a step
15751 : : { 41, 97, 100, 21, 100, 35, 100, 49 }. */
15752 : 16 : for (unsigned int i = 3; i < 8; i += 2)
15753 : 12 : elements[i] = build_int_cst (element_type, i * 7);
15754 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15755 : 4 : check_vector_cst_stepped (elements, vector, 2);
15756 : :
15757 : : /* Try a fully-general constant:
15758 : : { 41, 97, 100, 21, 100, 9990, 100, 49 }. */
15759 : 4 : elements[5] = build_int_cst (element_type, 9990);
15760 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15761 : 4 : check_vector_cst_fill (elements, vector, 4);
15762 : 4 : }
15763 : :
15764 : : /* Verify that STRIP_NOPS (NODE) is EXPECTED.
15765 : : Helper function for test_location_wrappers, to deal with STRIP_NOPS
15766 : : modifying its argument in-place. */
15767 : :
15768 : : static void
15769 : 12 : check_strip_nops (tree node, tree expected)
15770 : : {
15771 : 12 : STRIP_NOPS (node);
15772 : 12 : ASSERT_EQ (expected, node);
15773 : 12 : }
15774 : :
15775 : : /* Verify location wrappers. */
15776 : :
15777 : : static void
15778 : 4 : test_location_wrappers ()
15779 : : {
15780 : 4 : location_t loc = BUILTINS_LOCATION;
15781 : :
15782 : 4 : ASSERT_EQ (NULL_TREE, maybe_wrap_with_location (NULL_TREE, loc));
15783 : :
15784 : : /* Wrapping a constant. */
15785 : 4 : tree int_cst = build_int_cst (integer_type_node, 42);
15786 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst));
15787 : 4 : ASSERT_FALSE (location_wrapper_p (int_cst));
15788 : :
15789 : 4 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
15790 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
15791 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_cst));
15792 : 4 : ASSERT_EQ (int_cst, tree_strip_any_location_wrapper (wrapped_int_cst));
15793 : :
15794 : : /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION. */
15795 : 4 : ASSERT_EQ (int_cst, maybe_wrap_with_location (int_cst, UNKNOWN_LOCATION));
15796 : :
15797 : : /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P. */
15798 : 4 : tree cast = build1 (NOP_EXPR, char_type_node, int_cst);
15799 : 4 : ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast));
15800 : 4 : ASSERT_EQ (cast, maybe_wrap_with_location (cast, loc));
15801 : :
15802 : : /* Wrapping a STRING_CST. */
15803 : 4 : tree string_cst = build_string (4, "foo");
15804 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst));
15805 : 4 : ASSERT_FALSE (location_wrapper_p (string_cst));
15806 : :
15807 : 4 : tree wrapped_string_cst = maybe_wrap_with_location (string_cst, loc);
15808 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_string_cst));
15809 : 4 : ASSERT_EQ (VIEW_CONVERT_EXPR, TREE_CODE (wrapped_string_cst));
15810 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_string_cst));
15811 : 4 : ASSERT_EQ (string_cst, tree_strip_any_location_wrapper (wrapped_string_cst));
15812 : :
15813 : :
15814 : : /* Wrapping a variable. */
15815 : 4 : tree int_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
15816 : : get_identifier ("some_int_var"),
15817 : : integer_type_node);
15818 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var));
15819 : 4 : ASSERT_FALSE (location_wrapper_p (int_var));
15820 : :
15821 : 4 : tree wrapped_int_var = maybe_wrap_with_location (int_var, loc);
15822 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_var));
15823 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_var));
15824 : 4 : ASSERT_EQ (int_var, tree_strip_any_location_wrapper (wrapped_int_var));
15825 : :
15826 : : /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
15827 : : wrapper. */
15828 : 4 : tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
15829 : 4 : ASSERT_FALSE (location_wrapper_p (r_cast));
15830 : 4 : ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
15831 : :
15832 : : /* Verify that STRIP_NOPS removes wrappers. */
15833 : 4 : check_strip_nops (wrapped_int_cst, int_cst);
15834 : 4 : check_strip_nops (wrapped_string_cst, string_cst);
15835 : 4 : check_strip_nops (wrapped_int_var, int_var);
15836 : 4 : }
15837 : :
15838 : : /* Test various tree predicates. Verify that location wrappers don't
15839 : : affect the results. */
15840 : :
15841 : : static void
15842 : 4 : test_predicates ()
15843 : : {
15844 : : /* Build various constants and wrappers around them. */
15845 : :
15846 : 4 : location_t loc = BUILTINS_LOCATION;
15847 : :
15848 : 4 : tree i_0 = build_int_cst (integer_type_node, 0);
15849 : 4 : tree wr_i_0 = maybe_wrap_with_location (i_0, loc);
15850 : :
15851 : 4 : tree i_1 = build_int_cst (integer_type_node, 1);
15852 : 4 : tree wr_i_1 = maybe_wrap_with_location (i_1, loc);
15853 : :
15854 : 4 : tree i_m1 = build_int_cst (integer_type_node, -1);
15855 : 4 : tree wr_i_m1 = maybe_wrap_with_location (i_m1, loc);
15856 : :
15857 : 4 : tree f_0 = build_real_from_int_cst (float_type_node, i_0);
15858 : 4 : tree wr_f_0 = maybe_wrap_with_location (f_0, loc);
15859 : 4 : tree f_1 = build_real_from_int_cst (float_type_node, i_1);
15860 : 4 : tree wr_f_1 = maybe_wrap_with_location (f_1, loc);
15861 : 4 : tree f_m1 = build_real_from_int_cst (float_type_node, i_m1);
15862 : 4 : tree wr_f_m1 = maybe_wrap_with_location (f_m1, loc);
15863 : :
15864 : 4 : tree c_i_0 = build_complex (NULL_TREE, i_0, i_0);
15865 : 4 : tree c_i_1 = build_complex (NULL_TREE, i_1, i_0);
15866 : 4 : tree c_i_m1 = build_complex (NULL_TREE, i_m1, i_0);
15867 : :
15868 : 4 : tree c_f_0 = build_complex (NULL_TREE, f_0, f_0);
15869 : 4 : tree c_f_1 = build_complex (NULL_TREE, f_1, f_0);
15870 : 4 : tree c_f_m1 = build_complex (NULL_TREE, f_m1, f_0);
15871 : :
15872 : : /* TODO: vector constants. */
15873 : :
15874 : : /* Test integer_onep. */
15875 : 4 : ASSERT_FALSE (integer_onep (i_0));
15876 : 4 : ASSERT_FALSE (integer_onep (wr_i_0));
15877 : 4 : ASSERT_TRUE (integer_onep (i_1));
15878 : 4 : ASSERT_TRUE (integer_onep (wr_i_1));
15879 : 4 : ASSERT_FALSE (integer_onep (i_m1));
15880 : 4 : ASSERT_FALSE (integer_onep (wr_i_m1));
15881 : 4 : ASSERT_FALSE (integer_onep (f_0));
15882 : 4 : ASSERT_FALSE (integer_onep (wr_f_0));
15883 : 4 : ASSERT_FALSE (integer_onep (f_1));
15884 : 4 : ASSERT_FALSE (integer_onep (wr_f_1));
15885 : 4 : ASSERT_FALSE (integer_onep (f_m1));
15886 : 4 : ASSERT_FALSE (integer_onep (wr_f_m1));
15887 : 4 : ASSERT_FALSE (integer_onep (c_i_0));
15888 : 4 : ASSERT_TRUE (integer_onep (c_i_1));
15889 : 4 : ASSERT_FALSE (integer_onep (c_i_m1));
15890 : 4 : ASSERT_FALSE (integer_onep (c_f_0));
15891 : 4 : ASSERT_FALSE (integer_onep (c_f_1));
15892 : 4 : ASSERT_FALSE (integer_onep (c_f_m1));
15893 : :
15894 : : /* Test integer_zerop. */
15895 : 4 : ASSERT_TRUE (integer_zerop (i_0));
15896 : 4 : ASSERT_TRUE (integer_zerop (wr_i_0));
15897 : 4 : ASSERT_FALSE (integer_zerop (i_1));
15898 : 4 : ASSERT_FALSE (integer_zerop (wr_i_1));
15899 : 4 : ASSERT_FALSE (integer_zerop (i_m1));
15900 : 4 : ASSERT_FALSE (integer_zerop (wr_i_m1));
15901 : 4 : ASSERT_FALSE (integer_zerop (f_0));
15902 : 4 : ASSERT_FALSE (integer_zerop (wr_f_0));
15903 : 4 : ASSERT_FALSE (integer_zerop (f_1));
15904 : 4 : ASSERT_FALSE (integer_zerop (wr_f_1));
15905 : 4 : ASSERT_FALSE (integer_zerop (f_m1));
15906 : 4 : ASSERT_FALSE (integer_zerop (wr_f_m1));
15907 : 4 : ASSERT_TRUE (integer_zerop (c_i_0));
15908 : 4 : ASSERT_FALSE (integer_zerop (c_i_1));
15909 : 4 : ASSERT_FALSE (integer_zerop (c_i_m1));
15910 : 4 : ASSERT_FALSE (integer_zerop (c_f_0));
15911 : 4 : ASSERT_FALSE (integer_zerop (c_f_1));
15912 : 4 : ASSERT_FALSE (integer_zerop (c_f_m1));
15913 : :
15914 : : /* Test integer_all_onesp. */
15915 : 4 : ASSERT_FALSE (integer_all_onesp (i_0));
15916 : 4 : ASSERT_FALSE (integer_all_onesp (wr_i_0));
15917 : 4 : ASSERT_FALSE (integer_all_onesp (i_1));
15918 : 4 : ASSERT_FALSE (integer_all_onesp (wr_i_1));
15919 : 4 : ASSERT_TRUE (integer_all_onesp (i_m1));
15920 : 4 : ASSERT_TRUE (integer_all_onesp (wr_i_m1));
15921 : 4 : ASSERT_FALSE (integer_all_onesp (f_0));
15922 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_0));
15923 : 4 : ASSERT_FALSE (integer_all_onesp (f_1));
15924 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_1));
15925 : 4 : ASSERT_FALSE (integer_all_onesp (f_m1));
15926 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_m1));
15927 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_0));
15928 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_1));
15929 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_m1));
15930 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_0));
15931 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_1));
15932 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_m1));
15933 : :
15934 : : /* Test integer_minus_onep. */
15935 : 4 : ASSERT_FALSE (integer_minus_onep (i_0));
15936 : 4 : ASSERT_FALSE (integer_minus_onep (wr_i_0));
15937 : 4 : ASSERT_FALSE (integer_minus_onep (i_1));
15938 : 4 : ASSERT_FALSE (integer_minus_onep (wr_i_1));
15939 : 4 : ASSERT_TRUE (integer_minus_onep (i_m1));
15940 : 4 : ASSERT_TRUE (integer_minus_onep (wr_i_m1));
15941 : 4 : ASSERT_FALSE (integer_minus_onep (f_0));
15942 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_0));
15943 : 4 : ASSERT_FALSE (integer_minus_onep (f_1));
15944 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_1));
15945 : 4 : ASSERT_FALSE (integer_minus_onep (f_m1));
15946 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_m1));
15947 : 4 : ASSERT_FALSE (integer_minus_onep (c_i_0));
15948 : 4 : ASSERT_FALSE (integer_minus_onep (c_i_1));
15949 : 4 : ASSERT_TRUE (integer_minus_onep (c_i_m1));
15950 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_0));
15951 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_1));
15952 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_m1));
15953 : :
15954 : : /* Test integer_each_onep. */
15955 : 4 : ASSERT_FALSE (integer_each_onep (i_0));
15956 : 4 : ASSERT_FALSE (integer_each_onep (wr_i_0));
15957 : 4 : ASSERT_TRUE (integer_each_onep (i_1));
15958 : 4 : ASSERT_TRUE (integer_each_onep (wr_i_1));
15959 : 4 : ASSERT_FALSE (integer_each_onep (i_m1));
15960 : 4 : ASSERT_FALSE (integer_each_onep (wr_i_m1));
15961 : 4 : ASSERT_FALSE (integer_each_onep (f_0));
15962 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_0));
15963 : 4 : ASSERT_FALSE (integer_each_onep (f_1));
15964 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_1));
15965 : 4 : ASSERT_FALSE (integer_each_onep (f_m1));
15966 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_m1));
15967 : 4 : ASSERT_FALSE (integer_each_onep (c_i_0));
15968 : 4 : ASSERT_FALSE (integer_each_onep (c_i_1));
15969 : 4 : ASSERT_FALSE (integer_each_onep (c_i_m1));
15970 : 4 : ASSERT_FALSE (integer_each_onep (c_f_0));
15971 : 4 : ASSERT_FALSE (integer_each_onep (c_f_1));
15972 : 4 : ASSERT_FALSE (integer_each_onep (c_f_m1));
15973 : :
15974 : : /* Test integer_truep. */
15975 : 4 : ASSERT_FALSE (integer_truep (i_0));
15976 : 4 : ASSERT_FALSE (integer_truep (wr_i_0));
15977 : 4 : ASSERT_TRUE (integer_truep (i_1));
15978 : 4 : ASSERT_TRUE (integer_truep (wr_i_1));
15979 : 4 : ASSERT_FALSE (integer_truep (i_m1));
15980 : 4 : ASSERT_FALSE (integer_truep (wr_i_m1));
15981 : 4 : ASSERT_FALSE (integer_truep (f_0));
15982 : 4 : ASSERT_FALSE (integer_truep (wr_f_0));
15983 : 4 : ASSERT_FALSE (integer_truep (f_1));
15984 : 4 : ASSERT_FALSE (integer_truep (wr_f_1));
15985 : 4 : ASSERT_FALSE (integer_truep (f_m1));
15986 : 4 : ASSERT_FALSE (integer_truep (wr_f_m1));
15987 : 4 : ASSERT_FALSE (integer_truep (c_i_0));
15988 : 4 : ASSERT_TRUE (integer_truep (c_i_1));
15989 : 4 : ASSERT_FALSE (integer_truep (c_i_m1));
15990 : 4 : ASSERT_FALSE (integer_truep (c_f_0));
15991 : 4 : ASSERT_FALSE (integer_truep (c_f_1));
15992 : 4 : ASSERT_FALSE (integer_truep (c_f_m1));
15993 : :
15994 : : /* Test integer_nonzerop. */
15995 : 4 : ASSERT_FALSE (integer_nonzerop (i_0));
15996 : 4 : ASSERT_FALSE (integer_nonzerop (wr_i_0));
15997 : 4 : ASSERT_TRUE (integer_nonzerop (i_1));
15998 : 4 : ASSERT_TRUE (integer_nonzerop (wr_i_1));
15999 : 4 : ASSERT_TRUE (integer_nonzerop (i_m1));
16000 : 4 : ASSERT_TRUE (integer_nonzerop (wr_i_m1));
16001 : 4 : ASSERT_FALSE (integer_nonzerop (f_0));
16002 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_0));
16003 : 4 : ASSERT_FALSE (integer_nonzerop (f_1));
16004 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_1));
16005 : 4 : ASSERT_FALSE (integer_nonzerop (f_m1));
16006 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_m1));
16007 : 4 : ASSERT_FALSE (integer_nonzerop (c_i_0));
16008 : 4 : ASSERT_TRUE (integer_nonzerop (c_i_1));
16009 : 4 : ASSERT_TRUE (integer_nonzerop (c_i_m1));
16010 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_0));
16011 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_1));
16012 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_m1));
16013 : :
16014 : : /* Test real_zerop. */
16015 : 4 : ASSERT_FALSE (real_zerop (i_0));
16016 : 4 : ASSERT_FALSE (real_zerop (wr_i_0));
16017 : 4 : ASSERT_FALSE (real_zerop (i_1));
16018 : 4 : ASSERT_FALSE (real_zerop (wr_i_1));
16019 : 4 : ASSERT_FALSE (real_zerop (i_m1));
16020 : 4 : ASSERT_FALSE (real_zerop (wr_i_m1));
16021 : 4 : ASSERT_TRUE (real_zerop (f_0));
16022 : 4 : ASSERT_TRUE (real_zerop (wr_f_0));
16023 : 4 : ASSERT_FALSE (real_zerop (f_1));
16024 : 4 : ASSERT_FALSE (real_zerop (wr_f_1));
16025 : 4 : ASSERT_FALSE (real_zerop (f_m1));
16026 : 4 : ASSERT_FALSE (real_zerop (wr_f_m1));
16027 : 4 : ASSERT_FALSE (real_zerop (c_i_0));
16028 : 4 : ASSERT_FALSE (real_zerop (c_i_1));
16029 : 4 : ASSERT_FALSE (real_zerop (c_i_m1));
16030 : 4 : ASSERT_TRUE (real_zerop (c_f_0));
16031 : 4 : ASSERT_FALSE (real_zerop (c_f_1));
16032 : 4 : ASSERT_FALSE (real_zerop (c_f_m1));
16033 : :
16034 : : /* Test real_onep. */
16035 : 4 : ASSERT_FALSE (real_onep (i_0));
16036 : 4 : ASSERT_FALSE (real_onep (wr_i_0));
16037 : 4 : ASSERT_FALSE (real_onep (i_1));
16038 : 4 : ASSERT_FALSE (real_onep (wr_i_1));
16039 : 4 : ASSERT_FALSE (real_onep (i_m1));
16040 : 4 : ASSERT_FALSE (real_onep (wr_i_m1));
16041 : 4 : ASSERT_FALSE (real_onep (f_0));
16042 : 4 : ASSERT_FALSE (real_onep (wr_f_0));
16043 : 4 : ASSERT_TRUE (real_onep (f_1));
16044 : 4 : ASSERT_TRUE (real_onep (wr_f_1));
16045 : 4 : ASSERT_FALSE (real_onep (f_m1));
16046 : 4 : ASSERT_FALSE (real_onep (wr_f_m1));
16047 : 4 : ASSERT_FALSE (real_onep (c_i_0));
16048 : 4 : ASSERT_FALSE (real_onep (c_i_1));
16049 : 4 : ASSERT_FALSE (real_onep (c_i_m1));
16050 : 4 : ASSERT_FALSE (real_onep (c_f_0));
16051 : 4 : ASSERT_TRUE (real_onep (c_f_1));
16052 : 4 : ASSERT_FALSE (real_onep (c_f_m1));
16053 : :
16054 : : /* Test real_minus_onep. */
16055 : 4 : ASSERT_FALSE (real_minus_onep (i_0));
16056 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_0));
16057 : 4 : ASSERT_FALSE (real_minus_onep (i_1));
16058 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_1));
16059 : 4 : ASSERT_FALSE (real_minus_onep (i_m1));
16060 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_m1));
16061 : 4 : ASSERT_FALSE (real_minus_onep (f_0));
16062 : 4 : ASSERT_FALSE (real_minus_onep (wr_f_0));
16063 : 4 : ASSERT_FALSE (real_minus_onep (f_1));
16064 : 4 : ASSERT_FALSE (real_minus_onep (wr_f_1));
16065 : 4 : ASSERT_TRUE (real_minus_onep (f_m1));
16066 : 4 : ASSERT_TRUE (real_minus_onep (wr_f_m1));
16067 : 4 : ASSERT_FALSE (real_minus_onep (c_i_0));
16068 : 4 : ASSERT_FALSE (real_minus_onep (c_i_1));
16069 : 4 : ASSERT_FALSE (real_minus_onep (c_i_m1));
16070 : 4 : ASSERT_FALSE (real_minus_onep (c_f_0));
16071 : 4 : ASSERT_FALSE (real_minus_onep (c_f_1));
16072 : 4 : ASSERT_TRUE (real_minus_onep (c_f_m1));
16073 : :
16074 : : /* Test zerop. */
16075 : 4 : ASSERT_TRUE (zerop (i_0));
16076 : 4 : ASSERT_TRUE (zerop (wr_i_0));
16077 : 4 : ASSERT_FALSE (zerop (i_1));
16078 : 4 : ASSERT_FALSE (zerop (wr_i_1));
16079 : 4 : ASSERT_FALSE (zerop (i_m1));
16080 : 4 : ASSERT_FALSE (zerop (wr_i_m1));
16081 : 4 : ASSERT_TRUE (zerop (f_0));
16082 : 4 : ASSERT_TRUE (zerop (wr_f_0));
16083 : 4 : ASSERT_FALSE (zerop (f_1));
16084 : 4 : ASSERT_FALSE (zerop (wr_f_1));
16085 : 4 : ASSERT_FALSE (zerop (f_m1));
16086 : 4 : ASSERT_FALSE (zerop (wr_f_m1));
16087 : 4 : ASSERT_TRUE (zerop (c_i_0));
16088 : 4 : ASSERT_FALSE (zerop (c_i_1));
16089 : 4 : ASSERT_FALSE (zerop (c_i_m1));
16090 : 4 : ASSERT_TRUE (zerop (c_f_0));
16091 : 4 : ASSERT_FALSE (zerop (c_f_1));
16092 : 4 : ASSERT_FALSE (zerop (c_f_m1));
16093 : :
16094 : : /* Test tree_expr_nonnegative_p. */
16095 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_0));
16096 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_0));
16097 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_1));
16098 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_1));
16099 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (i_m1));
16100 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_i_m1));
16101 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_0));
16102 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_0));
16103 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_1));
16104 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_1));
16105 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (f_m1));
16106 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_f_m1));
16107 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_0));
16108 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_1));
16109 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_m1));
16110 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_0));
16111 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_1));
16112 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_m1));
16113 : :
16114 : : /* Test tree_expr_nonzero_p. */
16115 : 4 : ASSERT_FALSE (tree_expr_nonzero_p (i_0));
16116 : 4 : ASSERT_FALSE (tree_expr_nonzero_p (wr_i_0));
16117 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_1));
16118 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_1));
16119 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_m1));
16120 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_m1));
16121 : :
16122 : : /* Test integer_valued_real_p. */
16123 : 4 : ASSERT_FALSE (integer_valued_real_p (i_0));
16124 : 4 : ASSERT_TRUE (integer_valued_real_p (f_0));
16125 : 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_0));
16126 : 4 : ASSERT_TRUE (integer_valued_real_p (f_1));
16127 : 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_1));
16128 : :
16129 : : /* Test integer_pow2p. */
16130 : 4 : ASSERT_FALSE (integer_pow2p (i_0));
16131 : 4 : ASSERT_TRUE (integer_pow2p (i_1));
16132 : 4 : ASSERT_TRUE (integer_pow2p (wr_i_1));
16133 : :
16134 : : /* Test uniform_integer_cst_p. */
16135 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_0));
16136 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_0));
16137 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_1));
16138 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_1));
16139 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_m1));
16140 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_m1));
16141 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_0));
16142 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_0));
16143 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_1));
16144 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_1));
16145 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_m1));
16146 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_m1));
16147 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_0));
16148 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_1));
16149 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_m1));
16150 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_0));
16151 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_1));
16152 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_m1));
16153 : 4 : }
16154 : :
16155 : : /* Check that string escaping works correctly. */
16156 : :
16157 : : static void
16158 : 4 : test_escaped_strings (void)
16159 : : {
16160 : 4 : int saved_cutoff;
16161 : 4 : escaped_string msg;
16162 : :
16163 : 4 : msg.escape (NULL);
16164 : : /* ASSERT_STREQ does not accept NULL as a valid test
16165 : : result, so we have to use ASSERT_EQ instead. */
16166 : 4 : ASSERT_EQ (NULL, (const char *) msg);
16167 : :
16168 : 4 : msg.escape ("");
16169 : 4 : ASSERT_STREQ ("", (const char *) msg);
16170 : :
16171 : 4 : msg.escape ("foobar");
16172 : 4 : ASSERT_STREQ ("foobar", (const char *) msg);
16173 : :
16174 : : /* Ensure that we have -fmessage-length set to 0. */
16175 : 4 : pretty_printer *pp = global_dc->get_reference_printer ();
16176 : 4 : saved_cutoff = pp_line_cutoff (pp);
16177 : 4 : pp_line_cutoff (pp) = 0;
16178 : :
16179 : 4 : msg.escape ("foo\nbar");
16180 : 4 : ASSERT_STREQ ("foo\\nbar", (const char *) msg);
16181 : :
16182 : 4 : msg.escape ("\a\b\f\n\r\t\v");
16183 : 4 : ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg);
16184 : :
16185 : : /* Now repeat the tests with -fmessage-length set to 5. */
16186 : 4 : pp_line_cutoff (pp) = 5;
16187 : :
16188 : : /* Note that the newline is not translated into an escape. */
16189 : 4 : msg.escape ("foo\nbar");
16190 : 4 : ASSERT_STREQ ("foo\nbar", (const char *) msg);
16191 : :
16192 : 4 : msg.escape ("\a\b\f\n\r\t\v");
16193 : 4 : ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg);
16194 : :
16195 : : /* Restore the original message length setting. */
16196 : 4 : pp_line_cutoff (pp) = saved_cutoff;
16197 : 4 : }
16198 : :
16199 : : /* Run all of the selftests within this file. */
16200 : :
16201 : : void
16202 : 4 : tree_cc_tests ()
16203 : : {
16204 : 4 : test_integer_constants ();
16205 : 4 : test_identifiers ();
16206 : 4 : test_labels ();
16207 : 4 : test_vector_cst_patterns ();
16208 : 4 : test_location_wrappers ();
16209 : 4 : test_predicates ();
16210 : 4 : test_escaped_strings ();
16211 : 4 : }
16212 : :
16213 : : } // namespace selftest
16214 : :
16215 : : #endif /* CHECKING_P */
16216 : :
16217 : : #include "gt-tree.h"
|