Line data Source code
1 : /* Language-independent node constructors for parse phase of GNU compiler.
2 : Copyright (C) 1987-2026 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 : #include "attr-callback.h"
79 :
80 : /* Names of tree components.
81 : Used for printing out the tree and error messages. */
82 : #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
83 : #define END_OF_BASE_TREE_CODES "@dummy",
84 :
85 : static const char *const tree_code_name[] = {
86 : #include "all-tree.def"
87 : };
88 :
89 : #undef DEFTREECODE
90 : #undef END_OF_BASE_TREE_CODES
91 :
92 : /* Each tree code class has an associated string representation.
93 : These must correspond to the tree_code_class entries. */
94 :
95 : const char *const tree_code_class_strings[] =
96 : {
97 : "exceptional",
98 : "constant",
99 : "type",
100 : "declaration",
101 : "reference",
102 : "comparison",
103 : "unary",
104 : "binary",
105 : "statement",
106 : "vl_exp",
107 : "expression"
108 : };
109 :
110 : /* obstack.[ch] explicitly declined to prototype this. */
111 : extern int _obstack_allocated_p (struct obstack *h, void *obj);
112 :
113 : /* Statistics-gathering stuff. */
114 :
115 : static uint64_t tree_code_counts[MAX_TREE_CODES];
116 : uint64_t tree_node_counts[(int) all_kinds];
117 : uint64_t tree_node_sizes[(int) all_kinds];
118 :
119 : /* Keep in sync with tree.h:enum tree_node_kind. */
120 : static const char * const tree_node_kind_names[] = {
121 : "decls",
122 : "types",
123 : "blocks",
124 : "stmts",
125 : "refs",
126 : "exprs",
127 : "constants",
128 : "identifiers",
129 : "vecs",
130 : "binfos",
131 : "ssa names",
132 : "constructors",
133 : "random kinds",
134 : "lang_decl kinds",
135 : "lang_type kinds",
136 : "omp clauses",
137 : };
138 :
139 : /* Unique id for next decl created. */
140 : static GTY(()) int next_decl_uid;
141 : /* Unique id for next type created. */
142 : static GTY(()) unsigned next_type_uid = 1;
143 : /* Unique id for next debug decl created. Use negative numbers,
144 : to catch erroneous uses. */
145 : static GTY(()) int next_debug_decl_uid;
146 :
147 : /* Since we cannot rehash a type after it is in the table, we have to
148 : keep the hash code. */
149 :
150 : struct GTY((for_user)) type_hash {
151 : unsigned long hash;
152 : tree type;
153 : };
154 :
155 : /* Initial size of the hash table (rounded to next prime). */
156 : #define TYPE_HASH_INITIAL_SIZE 1000
157 :
158 : struct type_cache_hasher : ggc_cache_ptr_hash<type_hash>
159 : {
160 8363187812 : static hashval_t hash (type_hash *t) { return t->hash; }
161 : static bool equal (type_hash *a, type_hash *b);
162 :
163 : static int
164 2052011487 : keep_cache_entry (type_hash *&t)
165 : {
166 2052011487 : return ggc_marked_p (t->type);
167 : }
168 : };
169 :
170 : /* Now here is the hash table. When recording a type, it is added to
171 : the slot whose index is the hash code. Note that the hash table is
172 : used for several kinds of types (function types, array types and
173 : array index range types, for now). While all these live in the
174 : same table, they are completely independent, and the hash code is
175 : computed differently for each of these. */
176 :
177 : static GTY ((cache)) hash_table<type_cache_hasher> *type_hash_table;
178 :
179 : /* Hash table and temporary node for larger integer const values. */
180 : static GTY (()) tree int_cst_node;
181 :
182 : struct int_cst_hasher : ggc_cache_ptr_hash<tree_node>
183 : {
184 : static hashval_t hash (tree t);
185 : static bool equal (tree x, tree y);
186 : };
187 :
188 : static GTY ((cache)) hash_table<int_cst_hasher> *int_cst_hash_table;
189 :
190 : /* Class and variable for making sure that there is a single POLY_INT_CST
191 : for a given value. */
192 : struct poly_int_cst_hasher : ggc_cache_ptr_hash<tree_node>
193 : {
194 : typedef std::pair<tree, const poly_wide_int *> compare_type;
195 : static hashval_t hash (tree t);
196 : static bool equal (tree x, const compare_type &y);
197 : };
198 :
199 : static GTY ((cache)) hash_table<poly_int_cst_hasher> *poly_int_cst_hash_table;
200 :
201 : /* Hash table for optimization flags and target option flags. Use the same
202 : hash table for both sets of options. Nodes for building the current
203 : optimization and target option nodes. The assumption is most of the time
204 : the options created will already be in the hash table, so we avoid
205 : allocating and freeing up a node repeatably. */
206 : static GTY (()) tree cl_optimization_node;
207 : static GTY (()) tree cl_target_option_node;
208 :
209 : struct cl_option_hasher : ggc_cache_ptr_hash<tree_node>
210 : {
211 : static hashval_t hash (tree t);
212 : static bool equal (tree x, tree y);
213 : };
214 :
215 : static GTY ((cache)) hash_table<cl_option_hasher> *cl_option_hash_table;
216 :
217 872086 : struct gt_value_expr_mark_data {
218 : hash_set<tree> pset;
219 : auto_vec<tree, 16> to_mark;
220 : };
221 :
222 : /* Callback called through walk_tree_1 to discover DECL_HAS_VALUE_EXPR_P
223 : VAR_DECLs which weren't marked yet, in that case marks them and
224 : walks their DECL_VALUE_EXPR expressions. */
225 :
226 : static tree
227 23724681 : gt_value_expr_mark_2 (tree *tp, int *, void *data)
228 : {
229 23724681 : tree t = *tp;
230 23724681 : if (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t) && !ggc_marked_p (t))
231 : {
232 1095 : tree dve = DECL_VALUE_EXPR (t);
233 1095 : gt_value_expr_mark_data *d = (gt_value_expr_mark_data *) data;
234 1095 : walk_tree_1 (&dve, gt_value_expr_mark_2, data, &d->pset, NULL);
235 1095 : d->to_mark.safe_push (t);
236 : }
237 23724681 : return NULL_TREE;
238 : }
239 :
240 : /* Callback called through traverse_noresize on the
241 : value_expr_for_decl hash table. */
242 :
243 : int
244 10086210 : gt_value_expr_mark_1 (tree_decl_map **e, gt_value_expr_mark_data *data)
245 : {
246 10086210 : if (ggc_marked_p ((*e)->base.from))
247 8793368 : walk_tree_1 (&(*e)->to, gt_value_expr_mark_2, data, &data->pset, NULL);
248 10086210 : return 1;
249 : }
250 :
251 : /* The value_expr_for_decl hash table can have mappings for trees
252 : which are only referenced from mappings of other trees in the
253 : same table, see PR118790. Without this routine, gt_cleare_cache
254 : could clear hash table slot of a tree which isn't marked but
255 : will be marked when processing later hash table slot of another
256 : tree which is marked. This function marks with the above
257 : helpers marks all the not yet marked DECL_HAS_VALUE_EXPR_P
258 : VAR_DECLs mentioned in DECL_VALUE_EXPR expressions of marked
259 : trees and in that case also recurses on their DECL_VALUE_EXPR. */
260 :
261 : void
262 872086 : gt_value_expr_mark (hash_table<tree_decl_map_cache_hasher> *h)
263 : {
264 872086 : if (!h)
265 0 : return;
266 :
267 872086 : gt_value_expr_mark_data data;
268 872086 : h->traverse_noresize<gt_value_expr_mark_data *,
269 10958296 : gt_value_expr_mark_1> (&data);
270 2617353 : for (auto v : data.to_mark)
271 1095 : gt_ggc_mx (v);
272 872086 : }
273 :
274 : /* General tree->tree mapping structure for use in hash tables. */
275 :
276 :
277 : static GTY ((cache))
278 : hash_table<tree_decl_map_cache_hasher> *debug_expr_for_decl;
279 :
280 : static GTY ((cache ("gt_value_expr_mark")))
281 : hash_table<tree_decl_map_cache_hasher> *value_expr_for_decl;
282 :
283 : static GTY ((cache))
284 : hash_table<tree_vec_map_cache_hasher> *debug_args_for_decl;
285 :
286 : static void set_type_quals (tree, int);
287 : static void print_type_hash_statistics (void);
288 : static void print_debug_expr_statistics (void);
289 : static void print_value_expr_statistics (void);
290 :
291 : tree global_trees[TI_MAX];
292 : tree integer_types[itk_none];
293 :
294 : bool int_n_enabled_p[NUM_INT_N_ENTS];
295 : struct int_n_trees_t int_n_trees [NUM_INT_N_ENTS];
296 :
297 : bool tree_contains_struct[MAX_TREE_CODES][64];
298 :
299 : /* Number of operands for each OMP clause. */
300 : unsigned const char omp_clause_num_ops[] =
301 : {
302 : 0, /* OMP_CLAUSE_ERROR */
303 : 1, /* OMP_CLAUSE_PRIVATE */
304 : 1, /* OMP_CLAUSE_SHARED */
305 : 1, /* OMP_CLAUSE_FIRSTPRIVATE */
306 : 2, /* OMP_CLAUSE_LASTPRIVATE */
307 : 5, /* OMP_CLAUSE_REDUCTION */
308 : 5, /* OMP_CLAUSE_TASK_REDUCTION */
309 : 5, /* OMP_CLAUSE_IN_REDUCTION */
310 : 1, /* OMP_CLAUSE_COPYIN */
311 : 1, /* OMP_CLAUSE_COPYPRIVATE */
312 : 3, /* OMP_CLAUSE_LINEAR */
313 : 1, /* OMP_CLAUSE_AFFINITY */
314 : 2, /* OMP_CLAUSE_ALIGNED */
315 : 3, /* OMP_CLAUSE_ALLOCATE */
316 : 1, /* OMP_CLAUSE_DEPEND */
317 : 1, /* OMP_CLAUSE_NONTEMPORAL */
318 : 1, /* OMP_CLAUSE_UNIFORM */
319 : 1, /* OMP_CLAUSE_ENTER */
320 : 1, /* OMP_CLAUSE_LINK */
321 : 1, /* OMP_CLAUSE_DETACH */
322 : 1, /* OMP_CLAUSE_USE_DEVICE_PTR */
323 : 1, /* OMP_CLAUSE_USE_DEVICE_ADDR */
324 : 1, /* OMP_CLAUSE_IS_DEVICE_PTR */
325 : 1, /* OMP_CLAUSE_INCLUSIVE */
326 : 1, /* OMP_CLAUSE_EXCLUSIVE */
327 : 3, /* OMP_CLAUSE_FROM */
328 : 3, /* OMP_CLAUSE_TO */
329 : 3, /* OMP_CLAUSE_MAP (update walk_tree_1 if this is changed) */
330 : 1, /* OMP_CLAUSE_HAS_DEVICE_ADDR */
331 : 1, /* OMP_CLAUSE_DOACROSS */
332 : 3, /* OMP_CLAUSE__MAPPER_BINDING_ */
333 : 2, /* OMP_CLAUSE__CACHE_ */
334 : 1, /* OMP_CLAUSE_DESTROY */
335 : 2, /* OMP_CLAUSE_INIT */
336 : 1, /* OMP_CLAUSE_USE */
337 : 1, /* OMP_CLAUSE_INTEROP */
338 : 2, /* OMP_CLAUSE_GANG */
339 : 1, /* OMP_CLAUSE_ASYNC */
340 : 1, /* OMP_CLAUSE_WAIT */
341 : 0, /* OMP_CLAUSE_AUTO */
342 : 0, /* OMP_CLAUSE_SEQ */
343 : 1, /* OMP_CLAUSE__LOOPTEMP_ */
344 : 1, /* OMP_CLAUSE__REDUCTEMP_ */
345 : 1, /* OMP_CLAUSE__CONDTEMP_ */
346 : 1, /* OMP_CLAUSE__SCANTEMP_ */
347 : 1, /* OMP_CLAUSE_IF */
348 : 1, /* OMP_CLAUSE_SELF */
349 : 1, /* OMP_CLAUSE_NUM_THREADS */
350 : 1, /* OMP_CLAUSE_SCHEDULE */
351 : 0, /* OMP_CLAUSE_NOWAIT */
352 : 1, /* OMP_CLAUSE_ORDERED */
353 : 0, /* OMP_CLAUSE_DEFAULT */
354 : 3, /* OMP_CLAUSE_COLLAPSE */
355 : 0, /* OMP_CLAUSE_UNTIED */
356 : 1, /* OMP_CLAUSE_FINAL */
357 : 0, /* OMP_CLAUSE_MERGEABLE */
358 : 1, /* OMP_CLAUSE_DEVICE */
359 : 1, /* OMP_CLAUSE_DIST_SCHEDULE */
360 : 0, /* OMP_CLAUSE_INBRANCH */
361 : 0, /* OMP_CLAUSE_NOTINBRANCH */
362 : 2, /* OMP_CLAUSE_NUM_TEAMS */
363 : 1, /* OMP_CLAUSE_THREAD_LIMIT */
364 : 0, /* OMP_CLAUSE_PROC_BIND */
365 : 1, /* OMP_CLAUSE_SAFELEN */
366 : 1, /* OMP_CLAUSE_SIMDLEN */
367 : 0, /* OMP_CLAUSE_DEVICE_TYPE */
368 : 0, /* OMP_CLAUSE_FOR */
369 : 0, /* OMP_CLAUSE_PARALLEL */
370 : 0, /* OMP_CLAUSE_SECTIONS */
371 : 0, /* OMP_CLAUSE_TASKGROUP */
372 : 1, /* OMP_CLAUSE_PRIORITY */
373 : 1, /* OMP_CLAUSE_GRAINSIZE */
374 : 1, /* OMP_CLAUSE_NUM_TASKS */
375 : 0, /* OMP_CLAUSE_NOGROUP */
376 : 0, /* OMP_CLAUSE_THREADS */
377 : 0, /* OMP_CLAUSE_SIMD */
378 : 1, /* OMP_CLAUSE_HINT */
379 : 0, /* OMP_CLAUSE_DEFAULTMAP */
380 : 0, /* OMP_CLAUSE_ORDER */
381 : 0, /* OMP_CLAUSE_BIND */
382 : 1, /* OMP_CLAUSE_FILTER */
383 : 1, /* OMP_CLAUSE_INDIRECT */
384 : 1, /* OMP_CLAUSE_PARTIAL */
385 : 0, /* OMP_CLAUSE_FULL */
386 : 1, /* OMP_CLAUSE_SIZES */
387 : 1, /* OMP_CLAUSE__SIMDUID_ */
388 : 0, /* OMP_CLAUSE__SIMT_ */
389 : 0, /* OMP_CLAUSE_INDEPENDENT */
390 : 1, /* OMP_CLAUSE_WORKER */
391 : 1, /* OMP_CLAUSE_VECTOR */
392 : 1, /* OMP_CLAUSE_NUM_GANGS */
393 : 1, /* OMP_CLAUSE_NUM_WORKERS */
394 : 1, /* OMP_CLAUSE_VECTOR_LENGTH */
395 : 3, /* OMP_CLAUSE_TILE */
396 : 0, /* OMP_CLAUSE_IF_PRESENT */
397 : 0, /* OMP_CLAUSE_FINALIZE */
398 : 0, /* OMP_CLAUSE_NOHOST */
399 : 1, /* OMP_CLAUSE_NOVARIANTS */
400 : 1, /* OMP_CLAUSE_NOCONTEXT */
401 : 1, /* OMP_CLAUSE_DYN_GROUPPRIVATE */
402 : 3, /* OMP_CLAUSE_USES_ALLOCATORS */
403 : 2, /* OMP_CLAUSE_MESSAGE */
404 : };
405 :
406 : const char * const omp_clause_code_name[] =
407 : {
408 : "error_clause",
409 : "private",
410 : "shared",
411 : "firstprivate",
412 : "lastprivate",
413 : "reduction",
414 : "task_reduction",
415 : "in_reduction",
416 : "copyin",
417 : "copyprivate",
418 : "linear",
419 : "affinity",
420 : "aligned",
421 : "allocate",
422 : "depend",
423 : "nontemporal",
424 : "uniform",
425 : "enter",
426 : "link",
427 : "detach",
428 : "use_device_ptr",
429 : "use_device_addr",
430 : "is_device_ptr",
431 : "inclusive",
432 : "exclusive",
433 : "from",
434 : "to",
435 : "map",
436 : "has_device_addr",
437 : "doacross",
438 : "_mapper_binding_",
439 : "_cache_",
440 : "destroy",
441 : "init",
442 : "use",
443 : "interop",
444 : "gang",
445 : "async",
446 : "wait",
447 : "auto",
448 : "seq",
449 : "_looptemp_",
450 : "_reductemp_",
451 : "_condtemp_",
452 : "_scantemp_",
453 : "if",
454 : "self",
455 : "num_threads",
456 : "schedule",
457 : "nowait",
458 : "ordered",
459 : "default",
460 : "collapse",
461 : "untied",
462 : "final",
463 : "mergeable",
464 : "device",
465 : "dist_schedule",
466 : "inbranch",
467 : "notinbranch",
468 : "num_teams",
469 : "thread_limit",
470 : "proc_bind",
471 : "safelen",
472 : "simdlen",
473 : "device_type",
474 : "for",
475 : "parallel",
476 : "sections",
477 : "taskgroup",
478 : "priority",
479 : "grainsize",
480 : "num_tasks",
481 : "nogroup",
482 : "threads",
483 : "simd",
484 : "hint",
485 : "defaultmap",
486 : "order",
487 : "bind",
488 : "filter",
489 : "indirect",
490 : "partial",
491 : "full",
492 : "sizes",
493 : "_simduid_",
494 : "_simt_",
495 : "independent",
496 : "worker",
497 : "vector",
498 : "num_gangs",
499 : "num_workers",
500 : "vector_length",
501 : "tile",
502 : "if_present",
503 : "finalize",
504 : "nohost",
505 : "novariants",
506 : "nocontext",
507 : "dyn_groupprivate",
508 : "uses_allocators",
509 : "message"
510 : };
511 :
512 : /* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric
513 : clause names, but for use in diagnostics etc. would like to use the "user"
514 : clause names. */
515 :
516 : const char *
517 445 : user_omp_clause_code_name (tree clause, bool oacc)
518 : {
519 : /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to
520 : distinguish clauses as seen by the user. See also where front ends do
521 : 'build_omp_clause' with 'OMP_CLAUSE_MAP'. */
522 890 : if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
523 445 : switch (OMP_CLAUSE_MAP_KIND (clause))
524 : {
525 : case GOMP_MAP_FORCE_ALLOC:
526 : case GOMP_MAP_ALLOC: return "create";
527 0 : case GOMP_MAP_FORCE_TO:
528 0 : case GOMP_MAP_TO: return "copyin";
529 0 : case GOMP_MAP_FORCE_FROM:
530 0 : case GOMP_MAP_FROM: return "copyout";
531 361 : case GOMP_MAP_FORCE_TOFROM:
532 361 : case GOMP_MAP_TOFROM: return "copy";
533 0 : case GOMP_MAP_RELEASE: return "delete";
534 0 : case GOMP_MAP_FORCE_PRESENT: return "present";
535 42 : case GOMP_MAP_ATTACH: return "attach";
536 42 : case GOMP_MAP_FORCE_DETACH:
537 42 : case GOMP_MAP_DETACH: return "detach";
538 0 : case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
539 0 : case GOMP_MAP_LINK: return "link";
540 0 : case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
541 : default: break;
542 : }
543 :
544 0 : return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
545 : }
546 :
547 :
548 : /* Return the tree node structure used by tree code CODE. */
549 :
550 : static inline enum tree_node_structure_enum
551 44584277036 : tree_node_structure_for_code (enum tree_code code)
552 : {
553 44584277036 : switch (TREE_CODE_CLASS (code))
554 : {
555 11019235461 : case tcc_declaration:
556 11019235461 : switch (code)
557 : {
558 : case CONST_DECL: return TS_CONST_DECL;
559 : case DEBUG_EXPR_DECL: return TS_DECL_WRTL;
560 : case FIELD_DECL: return TS_FIELD_DECL;
561 : case FUNCTION_DECL: return TS_FUNCTION_DECL;
562 : case LABEL_DECL: return TS_LABEL_DECL;
563 : case PARM_DECL: return TS_PARM_DECL;
564 : case RESULT_DECL: return TS_RESULT_DECL;
565 : case TRANSLATION_UNIT_DECL: return TS_TRANSLATION_UNIT_DECL;
566 : case TYPE_DECL: return TS_TYPE_DECL;
567 : case VAR_DECL: return TS_VAR_DECL;
568 : default: return TS_DECL_NON_COMMON;
569 : }
570 :
571 : case tcc_type: return TS_TYPE_NON_COMMON;
572 :
573 11614239988 : case tcc_binary:
574 11614239988 : case tcc_comparison:
575 11614239988 : case tcc_expression:
576 11614239988 : case tcc_reference:
577 11614239988 : case tcc_statement:
578 11614239988 : case tcc_unary:
579 11614239988 : case tcc_vl_exp: return TS_EXP;
580 :
581 15895451494 : default: /* tcc_constant and tcc_exceptional */
582 15895451494 : break;
583 : }
584 :
585 15895451494 : switch (code)
586 : {
587 : /* tcc_constant cases. */
588 : case COMPLEX_CST: return TS_COMPLEX;
589 294196 : case FIXED_CST: return TS_FIXED_CST;
590 775540344 : case INTEGER_CST: return TS_INT_CST;
591 294196 : case POLY_INT_CST: return TS_POLY_INT_CST;
592 49576665 : case REAL_CST: return TS_REAL_CST;
593 259468206 : case STRING_CST: return TS_STRING;
594 13852930 : case VECTOR_CST: return TS_VECTOR;
595 1167132 : case VOID_CST: return TS_TYPED;
596 294456 : case RAW_DATA_CST: return TS_RAW_DATA_CST;
597 :
598 : /* tcc_exceptional cases. */
599 735229215 : case BLOCK: return TS_BLOCK;
600 142737045 : case CONSTRUCTOR: return TS_CONSTRUCTOR;
601 : case ERROR_MARK: return TS_COMMON;
602 8932543 : case IDENTIFIER_NODE: return TS_IDENTIFIER;
603 866804 : case OMP_CLAUSE: return TS_OMP_CLAUSE;
604 2052481 : case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
605 : case PLACEHOLDER_EXPR: return TS_COMMON;
606 334669909 : case SSA_NAME: return TS_SSA_NAME;
607 808694485 : case STATEMENT_LIST: return TS_STATEMENT_LIST;
608 4000622 : case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
609 275213238 : case TREE_BINFO: return TS_BINFO;
610 10262274482 : case TREE_LIST: return TS_LIST;
611 2218329733 : case TREE_VEC: return TS_VEC;
612 :
613 0 : default:
614 0 : gcc_unreachable ();
615 : }
616 : }
617 :
618 :
619 : /* Initialize tree_contains_struct to describe the hierarchy of tree
620 : nodes. */
621 :
622 : static void
623 294196 : initialize_tree_contains_struct (void)
624 : {
625 294196 : unsigned i;
626 :
627 72372216 : for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
628 : {
629 72078020 : enum tree_code code;
630 72078020 : enum tree_node_structure_enum ts_code;
631 :
632 72078020 : code = (enum tree_code) i;
633 72078020 : ts_code = tree_node_structure_for_code (code);
634 :
635 : /* Mark the TS structure itself. */
636 72078020 : tree_contains_struct[code][ts_code] = 1;
637 :
638 : /* Mark all the structures that TS is derived from. */
639 72078020 : switch (ts_code)
640 : {
641 1176784 : case TS_TYPED:
642 1176784 : case TS_BLOCK:
643 1176784 : case TS_OPTIMIZATION:
644 1176784 : case TS_TARGET_OPTION:
645 1176784 : MARK_TS_BASE (code);
646 1176784 : break;
647 :
648 59427592 : case TS_COMMON:
649 59427592 : case TS_INT_CST:
650 59427592 : case TS_POLY_INT_CST:
651 59427592 : case TS_REAL_CST:
652 59427592 : case TS_FIXED_CST:
653 59427592 : case TS_VECTOR:
654 59427592 : case TS_STRING:
655 59427592 : case TS_RAW_DATA_CST:
656 59427592 : case TS_COMPLEX:
657 59427592 : case TS_SSA_NAME:
658 59427592 : case TS_CONSTRUCTOR:
659 59427592 : case TS_EXP:
660 59427592 : case TS_STATEMENT_LIST:
661 59427592 : MARK_TS_TYPED (code);
662 59427592 : break;
663 :
664 1470980 : case TS_IDENTIFIER:
665 1470980 : case TS_DECL_MINIMAL:
666 1470980 : case TS_TYPE_COMMON:
667 1470980 : case TS_LIST:
668 1470980 : case TS_VEC:
669 1470980 : case TS_BINFO:
670 1470980 : case TS_OMP_CLAUSE:
671 1470980 : MARK_TS_COMMON (code);
672 1470980 : break;
673 :
674 : case TS_TYPE_WITH_LANG_SPECIFIC:
675 : MARK_TS_TYPE_COMMON (code);
676 : break;
677 :
678 6178116 : case TS_TYPE_NON_COMMON:
679 6178116 : MARK_TS_TYPE_WITH_LANG_SPECIFIC (code);
680 6178116 : break;
681 :
682 : case TS_DECL_COMMON:
683 : MARK_TS_DECL_MINIMAL (code);
684 : break;
685 :
686 588392 : case TS_DECL_WRTL:
687 588392 : case TS_CONST_DECL:
688 588392 : MARK_TS_DECL_COMMON (code);
689 588392 : break;
690 :
691 882588 : case TS_DECL_NON_COMMON:
692 882588 : MARK_TS_DECL_WITH_VIS (code);
693 882588 : break;
694 :
695 882588 : case TS_DECL_WITH_VIS:
696 882588 : case TS_PARM_DECL:
697 882588 : case TS_LABEL_DECL:
698 882588 : case TS_RESULT_DECL:
699 882588 : MARK_TS_DECL_WRTL (code);
700 882588 : break;
701 :
702 294196 : case TS_FIELD_DECL:
703 294196 : MARK_TS_DECL_COMMON (code);
704 294196 : break;
705 :
706 294196 : case TS_VAR_DECL:
707 294196 : MARK_TS_DECL_WITH_VIS (code);
708 294196 : break;
709 :
710 588392 : case TS_TYPE_DECL:
711 588392 : case TS_FUNCTION_DECL:
712 588392 : MARK_TS_DECL_NON_COMMON (code);
713 588392 : break;
714 :
715 294196 : case TS_TRANSLATION_UNIT_DECL:
716 294196 : MARK_TS_DECL_COMMON (code);
717 294196 : break;
718 :
719 : default:
720 : gcc_unreachable ();
721 : }
722 : }
723 :
724 : /* Basic consistency checks for attributes used in fold. */
725 294196 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
726 294196 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
727 294196 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
728 294196 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
729 294196 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
730 294196 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
731 294196 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
732 294196 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
733 294196 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
734 294196 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
735 294196 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
736 294196 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
737 294196 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
738 294196 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
739 294196 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
740 294196 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
741 294196 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
742 294196 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
743 294196 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
744 294196 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
745 294196 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
746 294196 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
747 294196 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
748 294196 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
749 294196 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
750 294196 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
751 294196 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
752 294196 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
753 294196 : gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
754 294196 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
755 294196 : gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
756 294196 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
757 294196 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
758 294196 : gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
759 294196 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
760 294196 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
761 294196 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
762 294196 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
763 294196 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_MINIMAL]);
764 294196 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_COMMON]);
765 294196 : }
766 :
767 :
768 : /* Init tree.cc. */
769 :
770 : void
771 294196 : init_ttree (void)
772 : {
773 : /* Initialize the hash table of types. */
774 294196 : type_hash_table
775 294196 : = hash_table<type_cache_hasher>::create_ggc (TYPE_HASH_INITIAL_SIZE);
776 :
777 294196 : debug_expr_for_decl
778 294196 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
779 :
780 294196 : value_expr_for_decl
781 294196 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
782 :
783 294196 : int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024);
784 :
785 294196 : poly_int_cst_hash_table = hash_table<poly_int_cst_hasher>::create_ggc (64);
786 :
787 294196 : int_cst_node = make_int_cst (1, 1);
788 :
789 294196 : cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64);
790 :
791 294196 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
792 294196 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
793 :
794 : /* Initialize the tree_contains_struct array. */
795 294196 : initialize_tree_contains_struct ();
796 294196 : lang_hooks.init_ts ();
797 294196 : }
798 :
799 :
800 : /* Mapping from prefix to label number. */
801 :
802 : struct identifier_hash : ggc_ptr_hash <tree_node>
803 : {
804 55275 : static inline hashval_t hash (tree t)
805 : {
806 55275 : return IDENTIFIER_HASH_VALUE (t);
807 : }
808 : };
809 : struct identifier_count_traits
810 : : simple_hashmap_traits<identifier_hash, long> {};
811 : typedef hash_map<tree, long, identifier_count_traits> internal_label_map;
812 : static GTY(()) internal_label_map *internal_label_nums;
813 :
814 : /* Generates an identifier intended to be used internally with the
815 : given PREFIX. This is intended to be used by the frontend so that
816 : C++ modules can regenerate appropriate (non-clashing) identifiers on
817 : stream-in. */
818 :
819 : tree
820 44236 : generate_internal_label (const char *prefix)
821 : {
822 44236 : tree prefix_id = get_identifier (prefix);
823 44236 : if (!internal_label_nums)
824 3072 : internal_label_nums = internal_label_map::create_ggc();
825 44236 : long &num = internal_label_nums->get_or_insert (prefix_id);
826 :
827 44236 : char tmp[32];
828 44236 : ASM_GENERATE_INTERNAL_LABEL (tmp, prefix, num++);
829 :
830 44236 : tree id = get_identifier (tmp);
831 44236 : IDENTIFIER_INTERNAL_P (id) = true;
832 :
833 : /* Cache the prefix on the identifier so we can retrieve it later. */
834 44236 : TREE_CHAIN (id) = prefix_id;
835 :
836 44236 : return id;
837 : }
838 :
839 : /* Get the PREFIX we created the internal identifier LABEL with. */
840 :
841 : const char *
842 7 : prefix_for_internal_label (tree label)
843 : {
844 7 : gcc_assert (IDENTIFIER_INTERNAL_P (label)
845 : && !IDENTIFIER_TRANSPARENT_ALIAS (label)
846 : && TREE_CHAIN (label)
847 : && TREE_CODE (TREE_CHAIN (label)) == IDENTIFIER_NODE);
848 7 : return IDENTIFIER_POINTER (TREE_CHAIN (label));
849 : }
850 :
851 : /* The name of the object as the assembler will see it (but before any
852 : translations made by ASM_OUTPUT_LABELREF). Often this is the same
853 : as DECL_NAME. It is an IDENTIFIER_NODE. */
854 : tree
855 1763948305 : decl_assembler_name (tree decl)
856 : {
857 1763948305 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
858 173729589 : lang_hooks.set_decl_assembler_name (decl);
859 1763948305 : return DECL_ASSEMBLER_NAME_RAW (decl);
860 : }
861 :
862 : /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
863 : (either of which may be NULL). Inform the FE, if this changes the
864 : name. */
865 :
866 : void
867 924073556 : overwrite_decl_assembler_name (tree decl, tree name)
868 : {
869 924073556 : if (DECL_ASSEMBLER_NAME_RAW (decl) != name)
870 454639268 : lang_hooks.overwrite_decl_assembler_name (decl, name);
871 924073556 : }
872 :
873 : /* Return true if DECL may need an assembler name to be set. */
874 :
875 : static inline bool
876 5174981 : need_assembler_name_p (tree decl)
877 : {
878 : /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
879 : Rule merging. This makes type_odr_p to return true on those types during
880 : LTO and by comparing the mangled name, we can say what types are intended
881 : to be equivalent across compilation unit.
882 :
883 : We do not store names of type_in_anonymous_namespace_p.
884 :
885 : Record, union and enumeration type have linkage that allows use
886 : to check type_in_anonymous_namespace_p. We do not mangle compound types
887 : that always can be compared structurally.
888 :
889 : Similarly for builtin types, we compare properties of their main variant.
890 : A special case are integer types where mangling do make differences
891 : between char/signed char/unsigned char etc. Storing name for these makes
892 : e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
893 : See cp/mangle.cc:write_builtin_type for details. */
894 :
895 5174981 : if (TREE_CODE (decl) == TYPE_DECL)
896 : {
897 157881 : if (DECL_NAME (decl)
898 128481 : && decl == TYPE_NAME (TREE_TYPE (decl))
899 128326 : && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
900 108993 : && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
901 105973 : && ((TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
902 88104 : && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE)
903 18127 : || TYPE_CXX_ODR_P (TREE_TYPE (decl)))
904 104572 : && (type_with_linkage_p (TREE_TYPE (decl))
905 89719 : || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
906 227452 : && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
907 69571 : return !DECL_ASSEMBLER_NAME_SET_P (decl);
908 : return false;
909 : }
910 : /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
911 5017100 : if (!VAR_OR_FUNCTION_DECL_P (decl))
912 : return false;
913 :
914 : /* If DECL already has its assembler name set, it does not need a
915 : new one. */
916 4323762 : if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
917 4323762 : || DECL_ASSEMBLER_NAME_SET_P (decl))
918 : return false;
919 :
920 : /* Abstract decls do not need an assembler name, except they
921 : can be looked up by autofdo. */
922 1736633 : if (DECL_ABSTRACT_P (decl) && !flag_auto_profile)
923 : return false;
924 :
925 : /* For VAR_DECLs, only static, public and external symbols need an
926 : assembler name. */
927 1735252 : if (VAR_P (decl)
928 543890 : && !TREE_STATIC (decl)
929 543565 : && !TREE_PUBLIC (decl)
930 2278817 : && !DECL_EXTERNAL (decl))
931 : return false;
932 :
933 1191687 : if (TREE_CODE (decl) == FUNCTION_DECL)
934 : {
935 : /* Do not set assembler name on builtins. Allow RTL expansion to
936 : decide whether to expand inline or via a regular call. */
937 1191362 : if (fndecl_built_in_p (decl)
938 1191362 : && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
939 : return false;
940 :
941 : /* Functions represented in the callgraph need an assembler name. */
942 1186647 : if (cgraph_node::get (decl) != NULL)
943 : return true;
944 :
945 : /* Unused and not public functions don't need an assembler name. */
946 3377 : if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
947 3 : return false;
948 : }
949 :
950 : return true;
951 : }
952 :
953 : /* If T needs an assembler name, have one created for it. */
954 :
955 : void
956 5174981 : assign_assembler_name_if_needed (tree t)
957 : {
958 5174981 : if (need_assembler_name_p (t))
959 : {
960 : /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
961 : diagnostics that use input_location to show locus
962 : information. The problem here is that, at this point,
963 : input_location is generally anchored to the end of the file
964 : (since the parser is long gone), so we don't have a good
965 : position to pin it to.
966 :
967 : To alleviate this problem, this uses the location of T's
968 : declaration. Examples of this are
969 : testsuite/g++.dg/template/cond2.C and
970 : testsuite/g++.dg/template/pr35240.C. */
971 1256517 : location_t saved_location = input_location;
972 1256517 : input_location = DECL_SOURCE_LOCATION (t);
973 :
974 1256517 : decl_assembler_name (t);
975 :
976 1256517 : input_location = saved_location;
977 : }
978 5174981 : }
979 :
980 : /* When the target supports COMDAT groups, this indicates which group the
981 : DECL is associated with. This can be either an IDENTIFIER_NODE or a
982 : decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
983 : tree
984 395781678 : decl_comdat_group (const_tree node)
985 : {
986 395781678 : struct symtab_node *snode = symtab_node::get (node);
987 395781678 : if (!snode)
988 : return NULL;
989 378358990 : return snode->get_comdat_group ();
990 : }
991 :
992 : /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
993 : tree
994 11921 : decl_comdat_group_id (const_tree node)
995 : {
996 11921 : struct symtab_node *snode = symtab_node::get (node);
997 11921 : if (!snode)
998 : return NULL;
999 11921 : return snode->get_comdat_group_id ();
1000 : }
1001 :
1002 : /* When the target supports named section, return its name as IDENTIFIER_NODE
1003 : or NULL if it is in no section. */
1004 : const char *
1005 757369102 : decl_section_name (const_tree node)
1006 : {
1007 757369102 : struct symtab_node *snode = symtab_node::get (node);
1008 757369102 : if (!snode)
1009 : return NULL;
1010 569489062 : return snode->get_section ();
1011 : }
1012 :
1013 : /* Set section name of NODE to VALUE (that is expected to be
1014 : identifier node) */
1015 : void
1016 1829520 : set_decl_section_name (tree node, const char *value)
1017 : {
1018 1829520 : struct symtab_node *snode;
1019 :
1020 1829520 : if (value == NULL)
1021 : {
1022 211 : snode = symtab_node::get (node);
1023 211 : if (!snode)
1024 : return;
1025 : }
1026 1829309 : else if (VAR_P (node))
1027 1569495 : snode = varpool_node::get_create (node);
1028 : else
1029 259814 : snode = cgraph_node::get_create (node);
1030 1829520 : snode->set_section (value);
1031 : }
1032 :
1033 : /* Set section name of NODE to match the section name of OTHER.
1034 :
1035 : set_decl_section_name (decl, other) is equivalent to
1036 : set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more
1037 : efficient. */
1038 : void
1039 16721184 : set_decl_section_name (tree decl, const_tree other)
1040 : {
1041 16721184 : struct symtab_node *other_node = symtab_node::get (other);
1042 16721184 : if (other_node)
1043 : {
1044 16705316 : struct symtab_node *decl_node;
1045 16705316 : if (VAR_P (decl))
1046 23 : decl_node = varpool_node::get_create (decl);
1047 : else
1048 16705293 : decl_node = cgraph_node::get_create (decl);
1049 16705316 : decl_node->set_section (*other_node);
1050 : }
1051 : else
1052 : {
1053 15868 : struct symtab_node *decl_node = symtab_node::get (decl);
1054 15868 : if (!decl_node)
1055 : return;
1056 0 : decl_node->set_section (NULL);
1057 : }
1058 : }
1059 :
1060 : /* Return TLS model of a variable NODE. */
1061 : enum tls_model
1062 281905568 : decl_tls_model (const_tree node)
1063 : {
1064 281905568 : struct varpool_node *snode = varpool_node::get (node);
1065 281905568 : if (!snode)
1066 : return TLS_MODEL_NONE;
1067 232298455 : return snode->tls_model;
1068 : }
1069 :
1070 : /* Set TLS model of variable NODE to MODEL. */
1071 : void
1072 57688 : set_decl_tls_model (tree node, enum tls_model model)
1073 : {
1074 57688 : struct varpool_node *vnode;
1075 :
1076 57688 : if (model == TLS_MODEL_NONE)
1077 : {
1078 6127 : vnode = varpool_node::get (node);
1079 6127 : if (!vnode)
1080 : return;
1081 : }
1082 : else
1083 51561 : vnode = varpool_node::get_create (node);
1084 51561 : vnode->tls_model = model;
1085 : }
1086 :
1087 : /* Compute the number of bytes occupied by a tree with code CODE.
1088 : This function cannot be used for nodes that have variable sizes,
1089 : including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
1090 : size_t
1091 19283688006 : tree_code_size (enum tree_code code)
1092 : {
1093 19283688006 : switch (TREE_CODE_CLASS (code))
1094 : {
1095 4628027740 : case tcc_declaration: /* A decl node */
1096 4628027740 : switch (code)
1097 : {
1098 : case FIELD_DECL: return sizeof (tree_field_decl);
1099 : case PARM_DECL: return sizeof (tree_parm_decl);
1100 284964588 : case VAR_DECL: return sizeof (tree_var_decl);
1101 : case LABEL_DECL: return sizeof (tree_label_decl);
1102 : case RESULT_DECL: return sizeof (tree_result_decl);
1103 31395117 : case CONST_DECL: return sizeof (tree_const_decl);
1104 : case TYPE_DECL: return sizeof (tree_type_decl);
1105 1469670621 : case FUNCTION_DECL: return sizeof (tree_function_decl);
1106 : case DEBUG_EXPR_DECL: return sizeof (tree_decl_with_rtl);
1107 : case TRANSLATION_UNIT_DECL: return sizeof (tree_translation_unit_decl);
1108 : case NAMESPACE_DECL:
1109 : case IMPORTED_DECL:
1110 : case NAMELIST_DECL: return sizeof (tree_decl_non_common);
1111 301415097 : default:
1112 301415097 : gcc_checking_assert (code >= NUM_TREE_CODES);
1113 301415097 : return lang_hooks.tree_size (code);
1114 : }
1115 :
1116 3210941008 : case tcc_type: /* a type node */
1117 3210941008 : switch (code)
1118 : {
1119 : case OFFSET_TYPE:
1120 : case ENUMERAL_TYPE:
1121 : case BOOLEAN_TYPE:
1122 : case INTEGER_TYPE:
1123 : case REAL_TYPE:
1124 : case OPAQUE_TYPE:
1125 : case POINTER_TYPE:
1126 : case REFERENCE_TYPE:
1127 : case NULLPTR_TYPE:
1128 : case FIXED_POINT_TYPE:
1129 : case COMPLEX_TYPE:
1130 : case VECTOR_TYPE:
1131 : case ARRAY_TYPE:
1132 : case RECORD_TYPE:
1133 : case UNION_TYPE:
1134 : case QUAL_UNION_TYPE:
1135 : case VOID_TYPE:
1136 : case FUNCTION_TYPE:
1137 : case METHOD_TYPE:
1138 : case BITINT_TYPE:
1139 : case LANG_TYPE: return sizeof (tree_type_non_common);
1140 768410881 : default:
1141 768410881 : gcc_checking_assert (code >= NUM_TREE_CODES);
1142 768410881 : return lang_hooks.tree_size (code);
1143 : }
1144 :
1145 5308767165 : case tcc_reference: /* a reference */
1146 5308767165 : case tcc_expression: /* an expression */
1147 5308767165 : case tcc_statement: /* an expression with side effects */
1148 5308767165 : case tcc_comparison: /* a comparison expression */
1149 5308767165 : case tcc_unary: /* a unary arithmetic expression */
1150 5308767165 : case tcc_binary: /* a binary arithmetic expression */
1151 5308767165 : return (sizeof (struct tree_exp)
1152 5308767165 : + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
1153 :
1154 44608782 : case tcc_constant: /* a constant */
1155 44608782 : switch (code)
1156 : {
1157 : case VOID_CST: return sizeof (tree_typed);
1158 0 : case INTEGER_CST: gcc_unreachable ();
1159 : case POLY_INT_CST: return sizeof (tree_poly_int_cst);
1160 43753490 : case REAL_CST: return sizeof (tree_real_cst);
1161 : case FIXED_CST: return sizeof (tree_fixed_cst);
1162 : case COMPLEX_CST: return sizeof (tree_complex);
1163 : case RAW_DATA_CST: return sizeof (tree_raw_data);
1164 0 : case VECTOR_CST: gcc_unreachable ();
1165 0 : case STRING_CST: gcc_unreachable ();
1166 64661 : default:
1167 64661 : gcc_checking_assert (code >= NUM_TREE_CODES);
1168 64661 : return lang_hooks.tree_size (code);
1169 : }
1170 :
1171 6091343311 : case tcc_exceptional: /* something random, like an identifier. */
1172 6091343311 : switch (code)
1173 : {
1174 1749415879 : case IDENTIFIER_NODE: return lang_hooks.identifier_size;
1175 : case TREE_LIST: return sizeof (tree_list);
1176 :
1177 : case ERROR_MARK:
1178 : case PLACEHOLDER_EXPR: return sizeof (tree_common);
1179 :
1180 0 : case TREE_VEC: gcc_unreachable ();
1181 0 : case OMP_CLAUSE: gcc_unreachable ();
1182 :
1183 : case SSA_NAME: return sizeof (tree_ssa_name);
1184 :
1185 : case STATEMENT_LIST: return sizeof (tree_statement_list);
1186 319290485 : case BLOCK: return sizeof (struct tree_block);
1187 : case CONSTRUCTOR: return sizeof (tree_constructor);
1188 : case OPTIMIZATION_NODE: return sizeof (tree_optimization_option);
1189 : case TARGET_OPTION_NODE: return sizeof (tree_target_option);
1190 :
1191 1688491213 : default:
1192 1688491213 : gcc_checking_assert (code >= NUM_TREE_CODES);
1193 1688491213 : return lang_hooks.tree_size (code);
1194 : }
1195 :
1196 0 : default:
1197 0 : gcc_unreachable ();
1198 : }
1199 : }
1200 :
1201 : /* Compute the number of bytes occupied by NODE. This routine only
1202 : looks at TREE_CODE, except for those nodes that have variable sizes. */
1203 : size_t
1204 4685388174 : tree_size (const_tree node)
1205 : {
1206 4685388174 : const enum tree_code code = TREE_CODE (node);
1207 4685388174 : switch (code)
1208 : {
1209 541447 : case INTEGER_CST:
1210 541447 : return (sizeof (struct tree_int_cst)
1211 541447 : + (TREE_INT_CST_EXT_NUNITS (node) - 1) * sizeof (HOST_WIDE_INT));
1212 :
1213 0 : case TREE_BINFO:
1214 0 : return (offsetof (struct tree_binfo, base_binfos)
1215 : + vec<tree, va_gc>
1216 0 : ::embedded_size (BINFO_N_BASE_BINFOS (node)));
1217 :
1218 428366788 : case TREE_VEC:
1219 428366788 : return (sizeof (struct tree_vec)
1220 428366788 : + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
1221 :
1222 0 : case VECTOR_CST:
1223 0 : return (sizeof (struct tree_vector)
1224 0 : + (vector_cst_encoded_nelts (node) - 1) * sizeof (tree));
1225 :
1226 23748 : case STRING_CST:
1227 23748 : return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
1228 :
1229 33813 : case OMP_CLAUSE:
1230 33813 : return (sizeof (struct tree_omp_clause)
1231 33813 : + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
1232 33813 : * sizeof (tree));
1233 :
1234 4256422378 : default:
1235 4256422378 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
1236 197681841 : return (sizeof (struct tree_exp)
1237 197681841 : + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
1238 : else
1239 4058740537 : return tree_code_size (code);
1240 : }
1241 : }
1242 :
1243 : /* Return tree node kind based on tree CODE. */
1244 :
1245 : static tree_node_kind
1246 0 : get_stats_node_kind (enum tree_code code)
1247 : {
1248 0 : enum tree_code_class type = TREE_CODE_CLASS (code);
1249 :
1250 0 : switch (type)
1251 : {
1252 : case tcc_declaration: /* A decl node */
1253 : return d_kind;
1254 0 : case tcc_type: /* a type node */
1255 0 : return t_kind;
1256 0 : case tcc_statement: /* an expression with side effects */
1257 0 : return s_kind;
1258 0 : case tcc_reference: /* a reference */
1259 0 : return r_kind;
1260 : case tcc_expression: /* an expression */
1261 : case tcc_comparison: /* a comparison expression */
1262 : case tcc_unary: /* a unary arithmetic expression */
1263 : case tcc_binary: /* a binary arithmetic expression */
1264 : return e_kind;
1265 0 : case tcc_constant: /* a constant */
1266 0 : return c_kind;
1267 0 : case tcc_exceptional: /* something random, like an identifier. */
1268 0 : switch (code)
1269 : {
1270 : case IDENTIFIER_NODE:
1271 : return id_kind;
1272 0 : case TREE_VEC:
1273 0 : return vec_kind;
1274 0 : case TREE_BINFO:
1275 0 : return binfo_kind;
1276 0 : case SSA_NAME:
1277 0 : return ssa_name_kind;
1278 0 : case BLOCK:
1279 0 : return b_kind;
1280 0 : case CONSTRUCTOR:
1281 0 : return constr_kind;
1282 0 : case OMP_CLAUSE:
1283 0 : return omp_clause_kind;
1284 0 : default:
1285 0 : return x_kind;
1286 : }
1287 : break;
1288 : case tcc_vl_exp:
1289 : return e_kind;
1290 0 : default:
1291 0 : gcc_unreachable ();
1292 : }
1293 : }
1294 :
1295 : /* Record interesting allocation statistics for a tree node with CODE
1296 : and LENGTH. */
1297 :
1298 : static void
1299 0 : record_node_allocation_statistics (enum tree_code code, size_t length)
1300 : {
1301 0 : if (!GATHER_STATISTICS)
1302 0 : return;
1303 :
1304 : tree_node_kind kind = get_stats_node_kind (code);
1305 :
1306 : tree_code_counts[(int) code]++;
1307 : tree_node_counts[(int) kind]++;
1308 : tree_node_sizes[(int) kind] += length;
1309 : }
1310 :
1311 : /* Allocate and return a new UID from the DECL_UID namespace. */
1312 :
1313 : int
1314 4621313674 : allocate_decl_uid (void)
1315 : {
1316 4621313674 : return next_decl_uid++;
1317 : }
1318 :
1319 : /* Return a newly allocated node of code CODE. For decl and type
1320 : nodes, some other fields are initialized. The rest of the node is
1321 : initialized to zero. This function cannot be used for TREE_VEC,
1322 : INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
1323 : tree_code_size.
1324 :
1325 : Achoo! I got a code in the node. */
1326 :
1327 : tree
1328 15219191662 : make_node (enum tree_code code MEM_STAT_DECL)
1329 : {
1330 15219191662 : tree t;
1331 15219191662 : enum tree_code_class type = TREE_CODE_CLASS (code);
1332 15219191662 : size_t length = tree_code_size (code);
1333 :
1334 15219191662 : record_node_allocation_statistics (code, length);
1335 :
1336 15219191662 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1337 15219191662 : TREE_SET_CODE (t, code);
1338 :
1339 15219191662 : switch (type)
1340 : {
1341 792640927 : case tcc_statement:
1342 792640927 : if (code != DEBUG_BEGIN_STMT)
1343 416350480 : TREE_SIDE_EFFECTS (t) = 1;
1344 : break;
1345 :
1346 3290414649 : case tcc_declaration:
1347 3290414649 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1348 : {
1349 3290414649 : if (code == FUNCTION_DECL)
1350 : {
1351 1142834690 : SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
1352 1142834690 : SET_DECL_MODE (t, FUNCTION_MODE);
1353 : }
1354 : else
1355 2147579959 : SET_DECL_ALIGN (t, 1);
1356 : }
1357 3290414649 : DECL_SOURCE_LOCATION (t) = input_location;
1358 3290414649 : if (TREE_CODE (t) == DEBUG_EXPR_DECL)
1359 2047376 : DECL_UID (t) = --next_debug_decl_uid;
1360 : else
1361 : {
1362 3288367273 : DECL_UID (t) = allocate_decl_uid ();
1363 3288367273 : SET_DECL_PT_UID (t, -1);
1364 : }
1365 3290414649 : if (TREE_CODE (t) == LABEL_DECL)
1366 38051345 : LABEL_DECL_UID (t) = -1;
1367 :
1368 : break;
1369 :
1370 2381790015 : case tcc_type:
1371 2381790015 : TYPE_UID (t) = next_type_uid++;
1372 2381790015 : SET_TYPE_ALIGN (t, BITS_PER_UNIT);
1373 2381790015 : TYPE_USER_ALIGN (t) = 0;
1374 2381790015 : TYPE_MAIN_VARIANT (t) = t;
1375 2381790015 : TYPE_CANONICAL (t) = t;
1376 :
1377 : /* Default to no attributes for type, but let target change that. */
1378 2381790015 : TYPE_ATTRIBUTES (t) = NULL_TREE;
1379 2381790015 : targetm.set_default_type_attributes (t);
1380 :
1381 : /* We have not yet computed the alias set for this type. */
1382 2381790015 : TYPE_ALIAS_SET (t) = -1;
1383 2381790015 : break;
1384 :
1385 44606913 : case tcc_constant:
1386 44606913 : TREE_CONSTANT (t) = 1;
1387 44606913 : break;
1388 :
1389 1379581663 : case tcc_expression:
1390 1379581663 : switch (code)
1391 : {
1392 297793483 : case INIT_EXPR:
1393 297793483 : case MODIFY_EXPR:
1394 297793483 : case VA_ARG_EXPR:
1395 297793483 : case PREDECREMENT_EXPR:
1396 297793483 : case PREINCREMENT_EXPR:
1397 297793483 : case POSTDECREMENT_EXPR:
1398 297793483 : case POSTINCREMENT_EXPR:
1399 : /* All of these have side-effects, no matter what their
1400 : operands are. */
1401 297793483 : TREE_SIDE_EFFECTS (t) = 1;
1402 297793483 : break;
1403 :
1404 : default:
1405 : break;
1406 : }
1407 : break;
1408 :
1409 5864147425 : case tcc_exceptional:
1410 5864147425 : switch (code)
1411 : {
1412 1098183 : case TARGET_OPTION_NODE:
1413 2196366 : TREE_TARGET_OPTION(t)
1414 1098183 : = ggc_cleared_alloc<struct cl_target_option> ();
1415 1098183 : break;
1416 :
1417 612637 : case OPTIMIZATION_NODE:
1418 1225274 : TREE_OPTIMIZATION (t)
1419 612637 : = ggc_cleared_alloc<struct cl_optimization> ();
1420 612637 : break;
1421 :
1422 : default:
1423 : break;
1424 : }
1425 : break;
1426 :
1427 : default:
1428 : /* Other classes need no special treatment. */
1429 : break;
1430 : }
1431 :
1432 15219191662 : return t;
1433 : }
1434 :
1435 : /* Free tree node. */
1436 :
1437 : void
1438 686538702 : free_node (tree node)
1439 : {
1440 686538702 : enum tree_code code = TREE_CODE (node);
1441 686538702 : if (GATHER_STATISTICS)
1442 : {
1443 : enum tree_node_kind kind = get_stats_node_kind (code);
1444 :
1445 : gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
1446 : gcc_checking_assert (tree_node_counts[(int) kind] != 0);
1447 : gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
1448 :
1449 : tree_code_counts[(int) TREE_CODE (node)]--;
1450 : tree_node_counts[(int) kind]--;
1451 : tree_node_sizes[(int) kind] -= tree_size (node);
1452 : }
1453 686538702 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1454 349 : vec_free (CONSTRUCTOR_ELTS (node));
1455 686538509 : else if (code == BLOCK)
1456 0 : vec_free (BLOCK_NONLOCALIZED_VARS (node));
1457 686538509 : else if (code == TREE_BINFO)
1458 369 : vec_free (BINFO_BASE_ACCESSES (node));
1459 686538140 : else if (code == OPTIMIZATION_NODE)
1460 861 : cl_optimization_option_free (TREE_OPTIMIZATION (node));
1461 686537279 : else if (code == TARGET_OPTION_NODE)
1462 926 : cl_target_option_free (TREE_TARGET_OPTION (node));
1463 686538702 : ggc_free (node);
1464 686538702 : }
1465 :
1466 : /* Return a new node with the same contents as NODE except that its
1467 : TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1468 :
1469 : tree
1470 4599287704 : copy_node (tree node MEM_STAT_DECL)
1471 : {
1472 4599287704 : tree t;
1473 4599287704 : enum tree_code code = TREE_CODE (node);
1474 4599287704 : size_t length;
1475 :
1476 4599287704 : gcc_assert (code != STATEMENT_LIST);
1477 :
1478 4599287704 : length = tree_size (node);
1479 4599287704 : record_node_allocation_statistics (code, length);
1480 4599287704 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
1481 4599287704 : memcpy (t, node, length);
1482 :
1483 4599287704 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
1484 2640282650 : TREE_CHAIN (t) = 0;
1485 4599287704 : TREE_ASM_WRITTEN (t) = 0;
1486 4599287704 : TREE_VISITED (t) = 0;
1487 :
1488 4599287704 : if (TREE_CODE_CLASS (code) == tcc_declaration)
1489 : {
1490 1331857284 : if (code == DEBUG_EXPR_DECL)
1491 0 : DECL_UID (t) = --next_debug_decl_uid;
1492 : else
1493 : {
1494 1331857284 : DECL_UID (t) = allocate_decl_uid ();
1495 1331857284 : if (DECL_PT_UID_SET_P (node))
1496 3494 : SET_DECL_PT_UID (t, DECL_PT_UID (node));
1497 : }
1498 663515855 : if ((TREE_CODE (node) == PARM_DECL || VAR_P (node))
1499 1420669594 : && DECL_HAS_VALUE_EXPR_P (node))
1500 : {
1501 1272275 : SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
1502 1272275 : DECL_HAS_VALUE_EXPR_P (t) = 1;
1503 : }
1504 : /* DECL_DEBUG_EXPR is copied explicitly by callers. */
1505 1331857284 : if (VAR_P (node))
1506 : {
1507 88812310 : DECL_HAS_DEBUG_EXPR_P (t) = 0;
1508 88812310 : t->decl_with_vis.symtab_node = NULL;
1509 : }
1510 1331857284 : if (VAR_P (node) && DECL_HAS_INIT_PRIORITY_P (node))
1511 : {
1512 0 : SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
1513 0 : DECL_HAS_INIT_PRIORITY_P (t) = 1;
1514 : }
1515 1331857284 : if (TREE_CODE (node) == FUNCTION_DECL)
1516 : {
1517 321719832 : DECL_STRUCT_FUNCTION (t) = NULL;
1518 321719832 : t->decl_with_vis.symtab_node = NULL;
1519 : }
1520 : }
1521 3267430420 : else if (TREE_CODE_CLASS (code) == tcc_type)
1522 : {
1523 829150993 : TYPE_UID (t) = next_type_uid++;
1524 : /* The following is so that the debug code for
1525 : the copy is different from the original type.
1526 : The two statements usually duplicate each other
1527 : (because they clear fields of the same union),
1528 : but the optimizer should catch that. */
1529 829150993 : TYPE_SYMTAB_ADDRESS (t) = 0;
1530 829150993 : TYPE_SYMTAB_DIE (t) = 0;
1531 :
1532 : /* Do not copy the values cache. */
1533 829150993 : if (TYPE_CACHED_VALUES_P (t))
1534 : {
1535 20163422 : TYPE_CACHED_VALUES_P (t) = 0;
1536 20163422 : TYPE_CACHED_VALUES (t) = NULL_TREE;
1537 : }
1538 : }
1539 2438279427 : else if (code == TARGET_OPTION_NODE)
1540 : {
1541 0 : TREE_TARGET_OPTION (t) = ggc_alloc<struct cl_target_option>();
1542 0 : memcpy (TREE_TARGET_OPTION (t), TREE_TARGET_OPTION (node),
1543 : sizeof (struct cl_target_option));
1544 : }
1545 2438279427 : else if (code == OPTIMIZATION_NODE)
1546 : {
1547 0 : TREE_OPTIMIZATION (t) = ggc_alloc<struct cl_optimization>();
1548 0 : memcpy (TREE_OPTIMIZATION (t), TREE_OPTIMIZATION (node),
1549 : sizeof (struct cl_optimization));
1550 : }
1551 :
1552 4599287704 : return t;
1553 : }
1554 :
1555 : /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1556 : For example, this can copy a list made of TREE_LIST nodes. */
1557 :
1558 : tree
1559 169713174 : copy_list (tree list)
1560 : {
1561 169713174 : tree head;
1562 169713174 : tree prev, next;
1563 :
1564 169713174 : if (list == 0)
1565 : return 0;
1566 :
1567 164427656 : head = prev = copy_node (list);
1568 164427656 : next = TREE_CHAIN (list);
1569 322975124 : while (next)
1570 : {
1571 158547468 : TREE_CHAIN (prev) = copy_node (next);
1572 158547468 : prev = TREE_CHAIN (prev);
1573 158547468 : next = TREE_CHAIN (next);
1574 : }
1575 : return head;
1576 : }
1577 :
1578 :
1579 : /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1580 : INTEGER_CST with value CST and type TYPE. */
1581 :
1582 : static unsigned int
1583 11196283728 : get_int_cst_ext_nunits (tree type, const wide_int &cst)
1584 : {
1585 11196283728 : gcc_checking_assert (cst.get_precision () == TYPE_PRECISION (type));
1586 : /* We need extra HWIs if CST is an unsigned integer with its
1587 : upper bit set. */
1588 11196283728 : if (TYPE_UNSIGNED (type) && wi::neg_p (cst))
1589 188229056 : return cst.get_precision () / HOST_BITS_PER_WIDE_INT + 1;
1590 11008054672 : return cst.get_len ();
1591 : }
1592 :
1593 : /* Return a new INTEGER_CST with value CST and type TYPE. */
1594 :
1595 : static tree
1596 136310771 : build_new_int_cst (tree type, const wide_int &cst)
1597 : {
1598 136310771 : unsigned int len = cst.get_len ();
1599 136310771 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1600 136310771 : tree nt = make_int_cst (len, ext_len);
1601 :
1602 136310771 : if (len < ext_len)
1603 : {
1604 69913793 : --ext_len;
1605 139827586 : TREE_INT_CST_ELT (nt, ext_len)
1606 69913793 : = zext_hwi (-1, cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1607 93278407 : for (unsigned int i = len; i < ext_len; ++i)
1608 23364614 : TREE_INT_CST_ELT (nt, i) = -1;
1609 : }
1610 66396978 : else if (TYPE_UNSIGNED (type)
1611 66396978 : && cst.get_precision () < len * HOST_BITS_PER_WIDE_INT)
1612 : {
1613 14364998 : len--;
1614 28729996 : TREE_INT_CST_ELT (nt, len)
1615 14364998 : = zext_hwi (cst.elt (len),
1616 14364998 : cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1617 : }
1618 :
1619 261741437 : for (unsigned int i = 0; i < len; i++)
1620 125430666 : TREE_INT_CST_ELT (nt, i) = cst.elt (i);
1621 136310771 : TREE_TYPE (nt) = type;
1622 136310771 : return nt;
1623 : }
1624 :
1625 : /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE. */
1626 :
1627 : static tree
1628 0 : build_new_poly_int_cst (tree type, tree (&coeffs)[NUM_POLY_INT_COEFFS]
1629 : CXX_MEM_STAT_INFO)
1630 : {
1631 0 : size_t length = sizeof (struct tree_poly_int_cst);
1632 0 : record_node_allocation_statistics (POLY_INT_CST, length);
1633 :
1634 0 : tree t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1635 :
1636 0 : TREE_SET_CODE (t, POLY_INT_CST);
1637 0 : TREE_CONSTANT (t) = 1;
1638 0 : TREE_TYPE (t) = type;
1639 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1640 0 : POLY_INT_CST_COEFF (t, i) = coeffs[i];
1641 0 : return t;
1642 : }
1643 :
1644 : /* Create a constant tree that contains CST sign-extended to TYPE. */
1645 :
1646 : tree
1647 7368517853 : build_int_cst (tree type, poly_int64 cst)
1648 : {
1649 : /* Support legacy code. */
1650 7368517853 : if (!type)
1651 2577796638 : type = integer_type_node;
1652 :
1653 7368517853 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1654 : }
1655 :
1656 : /* Create a constant tree that contains CST zero-extended to TYPE. */
1657 :
1658 : tree
1659 9895484 : build_int_cstu (tree type, poly_uint64 cst)
1660 : {
1661 9895484 : return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type)));
1662 : }
1663 :
1664 : /* Create a constant tree that contains CST sign-extended to TYPE. */
1665 :
1666 : tree
1667 27712040 : build_int_cst_type (tree type, poly_int64 cst)
1668 : {
1669 27712040 : gcc_assert (type);
1670 27712040 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1671 : }
1672 :
1673 : /* Constructs tree in type TYPE from with value given by CST. Signedness
1674 : of CST is assumed to be the same as the signedness of TYPE. */
1675 :
1676 : tree
1677 7298173 : double_int_to_tree (tree type, double_int cst)
1678 : {
1679 7298173 : return wide_int_to_tree (type, widest_int::from (cst, TYPE_SIGN (type)));
1680 : }
1681 :
1682 : /* We force the wide_int CST to the range of the type TYPE by sign or
1683 : zero extending it. OVERFLOWABLE indicates if we are interested in
1684 : overflow of the value, when >0 we are only interested in signed
1685 : overflow, for <0 we are interested in any overflow. OVERFLOWED
1686 : indicates whether overflow has already occurred. CONST_OVERFLOWED
1687 : indicates whether constant overflow has already occurred. We force
1688 : T's value to be within range of T's type (by setting to 0 or 1 all
1689 : the bits outside the type's range). We set TREE_OVERFLOWED if,
1690 : OVERFLOWED is nonzero,
1691 : or OVERFLOWABLE is >0 and signed overflow occurs
1692 : or OVERFLOWABLE is <0 and any overflow occurs
1693 : We return a new tree node for the extended wide_int. The node
1694 : is shared if no overflow flags are set. */
1695 :
1696 :
1697 : tree
1698 3057127465 : force_fit_type (tree type, const poly_wide_int_ref &cst,
1699 : int overflowable, bool overflowed)
1700 : {
1701 3057127465 : signop sign = TYPE_SIGN (type);
1702 :
1703 : /* If we need to set overflow flags, return a new unshared node. */
1704 3057127465 : if (overflowed || !wi::fits_to_tree_p (cst, type))
1705 : {
1706 7171660 : if (overflowed
1707 7171660 : || overflowable < 0
1708 5945693 : || (overflowable > 0 && sign == SIGNED))
1709 : {
1710 1307177 : poly_wide_int tmp = poly_wide_int::from (cst, TYPE_PRECISION (type),
1711 1307177 : sign);
1712 1307177 : tree t;
1713 1307177 : if (tmp.is_constant ())
1714 1307177 : t = build_new_int_cst (type, tmp.coeffs[0]);
1715 : else
1716 : {
1717 : tree coeffs[NUM_POLY_INT_COEFFS];
1718 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1719 : {
1720 : coeffs[i] = build_new_int_cst (type, tmp.coeffs[i]);
1721 : TREE_OVERFLOW (coeffs[i]) = 1;
1722 : }
1723 : t = build_new_poly_int_cst (type, coeffs);
1724 : }
1725 1307177 : TREE_OVERFLOW (t) = 1;
1726 1307177 : return t;
1727 1307177 : }
1728 : }
1729 :
1730 : /* Else build a shared node. */
1731 3055820288 : return wide_int_to_tree (type, cst);
1732 : }
1733 :
1734 : /* These are the hash table functions for the hash table of INTEGER_CST
1735 : nodes of a sizetype. */
1736 :
1737 : /* Return the hash code X, an INTEGER_CST. */
1738 :
1739 : hashval_t
1740 3274829530 : int_cst_hasher::hash (tree x)
1741 : {
1742 3274829530 : const_tree const t = x;
1743 3274829530 : hashval_t code = TYPE_UID (TREE_TYPE (t));
1744 3274829530 : int i;
1745 :
1746 6556482188 : for (i = 0; i < TREE_INT_CST_NUNITS (t); i++)
1747 3281652658 : code = iterative_hash_host_wide_int (TREE_INT_CST_ELT(t, i), code);
1748 :
1749 3274829530 : return code;
1750 : }
1751 :
1752 : /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1753 : is the same as that given by *Y, which is the same. */
1754 :
1755 : bool
1756 3234619845 : int_cst_hasher::equal (tree x, tree y)
1757 : {
1758 3234619845 : const_tree const xt = x;
1759 3234619845 : const_tree const yt = y;
1760 :
1761 3234619845 : if (TREE_TYPE (xt) != TREE_TYPE (yt)
1762 996174551 : || TREE_INT_CST_NUNITS (xt) != TREE_INT_CST_NUNITS (yt)
1763 4230738067 : || TREE_INT_CST_EXT_NUNITS (xt) != TREE_INT_CST_EXT_NUNITS (yt))
1764 : return false;
1765 :
1766 1352628700 : for (int i = 0; i < TREE_INT_CST_NUNITS (xt); i++)
1767 960542009 : if (TREE_INT_CST_ELT (xt, i) != TREE_INT_CST_ELT (yt, i))
1768 : return false;
1769 :
1770 : return true;
1771 : }
1772 :
1773 : /* Cache wide_int CST into the TYPE_CACHED_VALUES cache for TYPE.
1774 : SLOT is the slot entry to store it in, and MAX_SLOTS is the maximum
1775 : number of slots that can be cached for the type. */
1776 :
1777 : static inline tree
1778 10499817612 : cache_wide_int_in_type_cache (tree type, const wide_int &cst,
1779 : int slot, int max_slots)
1780 : {
1781 10499817612 : gcc_checking_assert (slot >= 0);
1782 : /* Initialize cache. */
1783 10499817612 : if (!TYPE_CACHED_VALUES_P (type))
1784 : {
1785 20563769 : TYPE_CACHED_VALUES_P (type) = 1;
1786 20563769 : TYPE_CACHED_VALUES (type) = make_tree_vec (max_slots);
1787 : }
1788 10499817612 : tree t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot);
1789 10499817612 : if (!t)
1790 : {
1791 : /* Create a new shared int. */
1792 62787651 : t = build_new_int_cst (type, cst);
1793 62787651 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot) = t;
1794 : }
1795 10499817612 : return t;
1796 : }
1797 :
1798 : /* Create an INT_CST node of TYPE and value CST.
1799 : The returned node is always shared. For small integers we use a
1800 : per-type vector cache, for larger ones we use a single hash table.
1801 : The value is extended from its precision according to the sign of
1802 : the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1803 : the upper bits and ensures that hashing and value equality based
1804 : upon the underlying HOST_WIDE_INTs works without masking. */
1805 :
1806 : static tree
1807 11059972957 : wide_int_to_tree_1 (tree type, const wide_int_ref &pcst)
1808 : {
1809 11059972957 : tree t;
1810 11059972957 : int ix = -1;
1811 11059972957 : int limit = 0;
1812 :
1813 11059972957 : gcc_assert (type);
1814 11059972957 : unsigned int prec = TYPE_PRECISION (type);
1815 11059972957 : signop sgn = TYPE_SIGN (type);
1816 :
1817 : /* Verify that everything is canonical. */
1818 11059972957 : int l = pcst.get_len ();
1819 11059972957 : if (l > 1)
1820 : {
1821 4046825 : if (pcst.elt (l - 1) == 0)
1822 1189985 : gcc_checking_assert (pcst.elt (l - 2) < 0);
1823 4046825 : if (pcst.elt (l - 1) == HOST_WIDE_INT_M1)
1824 11307 : gcc_checking_assert (pcst.elt (l - 2) >= 0);
1825 : }
1826 :
1827 11059972957 : wide_int cst = wide_int::from (pcst, prec, sgn);
1828 11059972957 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1829 :
1830 11059972957 : enum tree_code code = TREE_CODE (type);
1831 11059972957 : if (code == POINTER_TYPE || code == REFERENCE_TYPE)
1832 : {
1833 : /* Cache NULL pointer and zero bounds. */
1834 192958263 : if (cst == 0)
1835 : ix = 0;
1836 : /* Cache upper bounds of pointers. */
1837 50916232 : else if (cst == wi::max_value (prec, sgn))
1838 : ix = 1;
1839 : /* Cache 1 which is used for a non-zero range. */
1840 48802937 : else if (cst == 1)
1841 : ix = 2;
1842 :
1843 : if (ix >= 0)
1844 : {
1845 149995075 : t = cache_wide_int_in_type_cache (type, cst, ix, 3);
1846 : /* Make sure no one is clobbering the shared constant. */
1847 149995075 : gcc_checking_assert (TREE_TYPE (t) == type
1848 : && cst == wi::to_wide (t));
1849 149995075 : return t;
1850 : }
1851 : }
1852 10909977882 : if (ext_len == 1)
1853 : {
1854 : /* We just need to store a single HOST_WIDE_INT. */
1855 10837761939 : HOST_WIDE_INT hwi;
1856 10837761939 : if (TYPE_UNSIGNED (type))
1857 7290825869 : hwi = cst.to_uhwi ();
1858 : else
1859 3547002205 : hwi = cst.to_shwi ();
1860 :
1861 10837761939 : switch (code)
1862 : {
1863 226625 : case NULLPTR_TYPE:
1864 226625 : gcc_assert (hwi == 0);
1865 : /* Fallthru. */
1866 :
1867 : case POINTER_TYPE:
1868 : case REFERENCE_TYPE:
1869 : /* Ignore pointers, as they were already handled above. */
1870 : break;
1871 :
1872 115578218 : case BOOLEAN_TYPE:
1873 : /* Cache false or true. */
1874 115578218 : limit = 2;
1875 115578218 : if (IN_RANGE (hwi, 0, 1))
1876 115371699 : ix = hwi;
1877 : break;
1878 :
1879 10663945677 : case INTEGER_TYPE:
1880 10663945677 : case OFFSET_TYPE:
1881 10663945677 : case BITINT_TYPE:
1882 10663945677 : if (TYPE_SIGN (type) == UNSIGNED)
1883 : {
1884 : /* Cache [0, N). */
1885 7123299070 : limit = param_integer_share_limit;
1886 7123299070 : if (IN_RANGE (hwi, 0, param_integer_share_limit - 1))
1887 6843465581 : ix = hwi;
1888 : }
1889 : else
1890 : {
1891 : /* Cache [-1, N). */
1892 3540646607 : limit = param_integer_share_limit + 1;
1893 3540646607 : if (IN_RANGE (hwi, -1, param_integer_share_limit - 1))
1894 3390985257 : ix = hwi + 1;
1895 : }
1896 : break;
1897 :
1898 : case ENUMERAL_TYPE:
1899 : break;
1900 :
1901 0 : default:
1902 0 : gcc_unreachable ();
1903 : }
1904 :
1905 10837761939 : if (ix >= 0)
1906 : {
1907 10349822537 : t = cache_wide_int_in_type_cache (type, cst, ix, limit);
1908 : /* Make sure no one is clobbering the shared constant. */
1909 20699645074 : gcc_checking_assert (TREE_TYPE (t) == type
1910 : && TREE_INT_CST_NUNITS (t) == 1
1911 : && TREE_INT_CST_EXT_NUNITS (t) == 1
1912 : && TREE_INT_CST_ELT (t, 0) == hwi);
1913 : return t;
1914 : }
1915 : else
1916 : {
1917 : /* Use the cache of larger shared ints, using int_cst_node as
1918 : a temporary. */
1919 :
1920 487939402 : TREE_INT_CST_ELT (int_cst_node, 0) = hwi;
1921 487939402 : TREE_TYPE (int_cst_node) = type;
1922 :
1923 487939402 : tree *slot = int_cst_hash_table->find_slot (int_cst_node, INSERT);
1924 487939402 : t = *slot;
1925 487939402 : if (!t)
1926 : {
1927 : /* Insert this one into the hash table. */
1928 156048181 : t = int_cst_node;
1929 156048181 : *slot = t;
1930 : /* Make a new node for next time round. */
1931 156048181 : int_cst_node = make_int_cst (1, 1);
1932 : }
1933 : }
1934 : }
1935 : else
1936 : {
1937 : /* The value either hashes properly or we drop it on the floor
1938 : for the gc to take care of. There will not be enough of them
1939 : to worry about. */
1940 :
1941 72215943 : tree nt = build_new_int_cst (type, cst);
1942 72215943 : tree *slot = int_cst_hash_table->find_slot (nt, INSERT);
1943 72215943 : t = *slot;
1944 72215943 : if (!t)
1945 : {
1946 : /* Insert this one into the hash table. */
1947 12744217 : t = nt;
1948 12744217 : *slot = t;
1949 : }
1950 : else
1951 59471726 : ggc_free (nt);
1952 : }
1953 :
1954 : return t;
1955 11059972957 : }
1956 :
1957 : hashval_t
1958 0 : poly_int_cst_hasher::hash (tree t)
1959 : {
1960 0 : inchash::hash hstate;
1961 :
1962 0 : hstate.add_int (TYPE_UID (TREE_TYPE (t)));
1963 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1964 0 : hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
1965 :
1966 0 : return hstate.end ();
1967 : }
1968 :
1969 : bool
1970 0 : poly_int_cst_hasher::equal (tree x, const compare_type &y)
1971 : {
1972 0 : if (TREE_TYPE (x) != y.first)
1973 : return false;
1974 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1975 0 : if (wi::to_wide (POLY_INT_CST_COEFF (x, i)) != y.second->coeffs[i])
1976 : return false;
1977 : return true;
1978 : }
1979 :
1980 : /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
1981 : The elements must also have type TYPE. */
1982 :
1983 : tree
1984 0 : build_poly_int_cst (tree type, const poly_wide_int_ref &values)
1985 : {
1986 0 : unsigned int prec = TYPE_PRECISION (type);
1987 0 : gcc_assert (prec <= values.coeffs[0].get_precision ());
1988 0 : poly_wide_int c = poly_wide_int::from (values, prec, SIGNED);
1989 :
1990 0 : inchash::hash h;
1991 0 : h.add_int (TYPE_UID (type));
1992 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1993 0 : h.add_wide_int (c.coeffs[i]);
1994 0 : poly_int_cst_hasher::compare_type comp (type, &c);
1995 0 : tree *slot = poly_int_cst_hash_table->find_slot_with_hash (comp, h.end (),
1996 : INSERT);
1997 0 : if (*slot == NULL_TREE)
1998 : {
1999 : tree coeffs[NUM_POLY_INT_COEFFS];
2000 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
2001 0 : coeffs[i] = wide_int_to_tree_1 (type, c.coeffs[i]);
2002 0 : *slot = build_new_poly_int_cst (type, coeffs);
2003 : }
2004 0 : return *slot;
2005 0 : }
2006 :
2007 : /* Create a constant tree with value VALUE in type TYPE. */
2008 :
2009 : tree
2010 11059972957 : wide_int_to_tree (tree type, const poly_wide_int_ref &value)
2011 : {
2012 11059972957 : if (value.is_constant ())
2013 11059972957 : return wide_int_to_tree_1 (type, value.coeffs[0]);
2014 : return build_poly_int_cst (type, value);
2015 : }
2016 :
2017 : /* Insert INTEGER_CST T into a cache of integer constants. And return
2018 : the cached constant (which may or may not be T). If MIGHT_DUPLICATE
2019 : is false, and T falls into the type's 'smaller values' range, there
2020 : cannot be an existing entry. Otherwise, if MIGHT_DUPLICATE is true,
2021 : or the value is large, should an existing entry exist, it is
2022 : returned (rather than inserting T). */
2023 :
2024 : tree
2025 638178 : cache_integer_cst (tree t, bool might_duplicate ATTRIBUTE_UNUSED)
2026 : {
2027 638178 : tree type = TREE_TYPE (t);
2028 638178 : int ix = -1;
2029 638178 : int limit = 0;
2030 638178 : int prec = TYPE_PRECISION (type);
2031 :
2032 638178 : gcc_assert (!TREE_OVERFLOW (t));
2033 :
2034 : /* The caching indices here must match those in
2035 : wide_int_to_type_1. */
2036 638178 : switch (TREE_CODE (type))
2037 : {
2038 0 : case NULLPTR_TYPE:
2039 0 : gcc_checking_assert (integer_zerop (t));
2040 : /* Fallthru. */
2041 :
2042 4880 : case POINTER_TYPE:
2043 4880 : case REFERENCE_TYPE:
2044 4880 : {
2045 4880 : if (integer_zerop (t))
2046 : ix = 0;
2047 1878 : else if (integer_onep (t))
2048 : ix = 2;
2049 :
2050 : if (ix >= 0)
2051 : limit = 3;
2052 : }
2053 : break;
2054 :
2055 10762 : case BOOLEAN_TYPE:
2056 : /* Cache false or true. */
2057 10762 : limit = 2;
2058 10762 : if (wi::ltu_p (wi::to_wide (t), 2))
2059 0 : ix = TREE_INT_CST_ELT (t, 0);
2060 : break;
2061 :
2062 607054 : case INTEGER_TYPE:
2063 607054 : case OFFSET_TYPE:
2064 607054 : case BITINT_TYPE:
2065 607054 : if (TYPE_UNSIGNED (type))
2066 : {
2067 : /* Cache 0..N */
2068 453233 : limit = param_integer_share_limit;
2069 :
2070 : /* This is a little hokie, but if the prec is smaller than
2071 : what is necessary to hold param_integer_share_limit, then the
2072 : obvious test will not get the correct answer. */
2073 453233 : if (prec < HOST_BITS_PER_WIDE_INT)
2074 : {
2075 96414 : if (tree_to_uhwi (t)
2076 96414 : < (unsigned HOST_WIDE_INT) param_integer_share_limit)
2077 15852 : ix = tree_to_uhwi (t);
2078 : }
2079 356819 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2080 276840 : ix = tree_to_uhwi (t);
2081 : }
2082 : else
2083 : {
2084 : /* Cache -1..N */
2085 153821 : limit = param_integer_share_limit + 1;
2086 :
2087 153821 : if (integer_minus_onep (t))
2088 : ix = 0;
2089 153351 : else if (!wi::neg_p (wi::to_wide (t)))
2090 : {
2091 136175 : if (prec < HOST_BITS_PER_WIDE_INT)
2092 : {
2093 129466 : if (tree_to_shwi (t) < param_integer_share_limit)
2094 120346 : ix = tree_to_shwi (t) + 1;
2095 : }
2096 6709 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2097 5419 : ix = tree_to_shwi (t) + 1;
2098 : }
2099 : }
2100 : break;
2101 :
2102 : case ENUMERAL_TYPE:
2103 : /* The slot used by TYPE_CACHED_VALUES is used for the enum
2104 : members. */
2105 : break;
2106 :
2107 0 : default:
2108 0 : gcc_unreachable ();
2109 : }
2110 :
2111 421459 : if (ix >= 0)
2112 : {
2113 : /* Look for it in the type's vector of small shared ints. */
2114 422377 : if (!TYPE_CACHED_VALUES_P (type))
2115 : {
2116 14389 : TYPE_CACHED_VALUES_P (type) = 1;
2117 14389 : TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
2118 : }
2119 :
2120 422377 : if (tree r = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix))
2121 : {
2122 395760 : gcc_checking_assert (might_duplicate);
2123 395760 : t = r;
2124 : }
2125 : else
2126 26617 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
2127 : }
2128 : else
2129 : {
2130 : /* Use the cache of larger shared ints. */
2131 215801 : tree *slot = int_cst_hash_table->find_slot (t, INSERT);
2132 215801 : if (tree r = *slot)
2133 : {
2134 : /* If there is already an entry for the number verify it's the
2135 : same value. */
2136 125677 : gcc_checking_assert (wi::to_wide (tree (r)) == wi::to_wide (t));
2137 : /* And return the cached value. */
2138 125677 : t = r;
2139 : }
2140 : else
2141 : /* Otherwise insert this one into the hash table. */
2142 90124 : *slot = t;
2143 : }
2144 :
2145 638178 : return t;
2146 : }
2147 :
2148 :
2149 : /* Builds an integer constant in TYPE such that lowest BITS bits are ones
2150 : and the rest are zeros. */
2151 :
2152 : tree
2153 9732212 : build_low_bits_mask (tree type, unsigned bits)
2154 : {
2155 9732212 : gcc_assert (bits <= TYPE_PRECISION (type));
2156 :
2157 9732212 : return wide_int_to_tree (type, wi::mask (bits, false,
2158 9732212 : TYPE_PRECISION (type)));
2159 : }
2160 :
2161 : /* Checks that X is integer constant that can be expressed in (unsigned)
2162 : HOST_WIDE_INT without loss of precision. */
2163 :
2164 : bool
2165 794421138 : cst_and_fits_in_hwi (const_tree x)
2166 : {
2167 794421138 : return (TREE_CODE (x) == INTEGER_CST
2168 794421138 : && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
2169 : }
2170 :
2171 : /* Build a newly constructed VECTOR_CST with the given values of
2172 : (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN. */
2173 :
2174 : tree
2175 3465580 : make_vector (unsigned log2_npatterns,
2176 : unsigned int nelts_per_pattern MEM_STAT_DECL)
2177 : {
2178 3465580 : gcc_assert (IN_RANGE (nelts_per_pattern, 1, 3));
2179 3465580 : tree t;
2180 3465580 : unsigned npatterns = 1 << log2_npatterns;
2181 3465580 : unsigned encoded_nelts = npatterns * nelts_per_pattern;
2182 3465580 : unsigned length = (sizeof (struct tree_vector)
2183 : + (encoded_nelts - 1) * sizeof (tree));
2184 :
2185 3465580 : record_node_allocation_statistics (VECTOR_CST, length);
2186 :
2187 3465580 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2188 :
2189 3465580 : TREE_SET_CODE (t, VECTOR_CST);
2190 3465580 : TREE_CONSTANT (t) = 1;
2191 3465580 : VECTOR_CST_LOG2_NPATTERNS (t) = log2_npatterns;
2192 3465580 : VECTOR_CST_NELTS_PER_PATTERN (t) = nelts_per_pattern;
2193 :
2194 3465580 : return t;
2195 : }
2196 :
2197 : /* Return a new VECTOR_CST node whose type is TYPE and whose values
2198 : are extracted from V, a vector of CONSTRUCTOR_ELT. */
2199 :
2200 : tree
2201 689549 : build_vector_from_ctor (tree type, const vec<constructor_elt, va_gc> *v)
2202 : {
2203 689549 : if (vec_safe_length (v) == 0)
2204 2052 : return build_zero_cst (type);
2205 :
2206 687497 : unsigned HOST_WIDE_INT idx, npatterns, nelts_per_pattern;
2207 687497 : tree value;
2208 :
2209 : /* If the vector is a VLA, build a VLA constant vector. */
2210 687497 : npatterns = constant_lower_bound (TYPE_VECTOR_SUBPARTS (type));
2211 687497 : nelts_per_pattern = TYPE_VECTOR_SUBPARTS (type).is_constant () ? 1 : 2;
2212 687497 : gcc_assert (vec_safe_length (v) <= npatterns);
2213 :
2214 687497 : tree_vector_builder vec (type, npatterns, nelts_per_pattern);
2215 5242086 : FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
2216 : {
2217 3867092 : if (TREE_CODE (value) == VECTOR_CST)
2218 : {
2219 : /* If NPATTERNS is constant then this must be too. */
2220 4908 : unsigned int sub_nelts = VECTOR_CST_NELTS (value).to_constant ();
2221 19972 : for (unsigned i = 0; i < sub_nelts; ++i)
2222 15064 : vec.quick_push (VECTOR_CST_ELT (value, i));
2223 : }
2224 : else
2225 3862184 : vec.quick_push (value);
2226 : }
2227 1944366 : while (vec.length () < npatterns * nelts_per_pattern)
2228 284686 : vec.quick_push (build_zero_cst (TREE_TYPE (type)));
2229 :
2230 687497 : return vec.build ();
2231 687497 : }
2232 :
2233 : /* Build a vector of type VECTYPE where all the elements are SCs. */
2234 : tree
2235 663947 : build_vector_from_val (tree vectype, tree sc)
2236 : {
2237 663947 : unsigned HOST_WIDE_INT i, nunits;
2238 :
2239 663947 : if (sc == error_mark_node)
2240 : return sc;
2241 :
2242 : /* Verify that the vector type is suitable for SC. Note that there
2243 : is some inconsistency in the type-system with respect to restrict
2244 : qualifications of pointers. Vector types always have a main-variant
2245 : element type and the qualification is applied to the vector-type.
2246 : So TREE_TYPE (vector-type) does not return a properly qualified
2247 : vector element-type. */
2248 663947 : gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
2249 : TREE_TYPE (vectype)));
2250 :
2251 663947 : if (CONSTANT_CLASS_P (sc))
2252 : {
2253 632356 : tree_vector_builder v (vectype, 1, 1);
2254 632356 : v.quick_push (sc);
2255 632356 : return v.build ();
2256 632356 : }
2257 31591 : else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
2258 : return fold_build1 (VEC_DUPLICATE_EXPR, vectype, sc);
2259 : else
2260 : {
2261 31591 : vec<constructor_elt, va_gc> *v;
2262 31591 : vec_alloc (v, nunits);
2263 182483 : for (i = 0; i < nunits; ++i)
2264 119301 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
2265 31591 : return build_constructor (vectype, v);
2266 : }
2267 : }
2268 :
2269 : /* If TYPE is not a vector type, just return SC, otherwise return
2270 : build_vector_from_val (TYPE, SC). */
2271 :
2272 : tree
2273 5528929 : build_uniform_cst (tree type, tree sc)
2274 : {
2275 5528929 : if (!VECTOR_TYPE_P (type))
2276 : return sc;
2277 :
2278 370 : return build_vector_from_val (type, sc);
2279 : }
2280 :
2281 : /* Build a vector series of type TYPE in which element I has the value
2282 : BASE + I * STEP. The result is a constant if BASE and STEP are constant
2283 : and a VEC_SERIES_EXPR otherwise. */
2284 :
2285 : tree
2286 18 : build_vec_series (tree type, tree base, tree step)
2287 : {
2288 18 : if (integer_zerop (step))
2289 0 : return build_vector_from_val (type, base);
2290 18 : if (TREE_CODE (base) == INTEGER_CST && TREE_CODE (step) == INTEGER_CST)
2291 : {
2292 18 : tree_vector_builder builder (type, 1, 3);
2293 18 : tree elt1 = wide_int_to_tree (TREE_TYPE (base),
2294 36 : wi::to_wide (base) + wi::to_wide (step));
2295 18 : tree elt2 = wide_int_to_tree (TREE_TYPE (base),
2296 36 : wi::to_wide (elt1) + wi::to_wide (step));
2297 18 : builder.quick_push (base);
2298 18 : builder.quick_push (elt1);
2299 18 : builder.quick_push (elt2);
2300 18 : return builder.build ();
2301 18 : }
2302 0 : return build2 (VEC_SERIES_EXPR, type, base, step);
2303 : }
2304 :
2305 : /* Return a vector with the same number of units and number of bits
2306 : as VEC_TYPE, but in which the elements are a linear series of unsigned
2307 : integers { BASE, BASE + STEP, BASE + STEP * 2, ... }. */
2308 :
2309 : tree
2310 1797 : build_index_vector (tree vec_type, poly_uint64 base, poly_uint64 step)
2311 : {
2312 1797 : tree index_vec_type = vec_type;
2313 1797 : tree index_elt_type = TREE_TYPE (vec_type);
2314 1797 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vec_type);
2315 1797 : if (!INTEGRAL_TYPE_P (index_elt_type) || !TYPE_UNSIGNED (index_elt_type))
2316 : {
2317 4 : index_elt_type = build_nonstandard_integer_type
2318 8 : (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type)), true);
2319 4 : index_vec_type = build_vector_type (index_elt_type, nunits);
2320 : }
2321 :
2322 1797 : tree_vector_builder v (index_vec_type, 1, 3);
2323 8985 : for (unsigned int i = 0; i < 3; ++i)
2324 5391 : v.quick_push (build_int_cstu (index_elt_type, base + i * step));
2325 1797 : return v.build ();
2326 1797 : }
2327 :
2328 : /* Return a VECTOR_CST of type VEC_TYPE in which the first NUM_A
2329 : elements are A and the rest are B. */
2330 :
2331 : tree
2332 0 : build_vector_a_then_b (tree vec_type, unsigned int num_a, tree a, tree b)
2333 : {
2334 0 : gcc_assert (known_le (num_a, TYPE_VECTOR_SUBPARTS (vec_type)));
2335 0 : unsigned int count = constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_type));
2336 : /* Optimize the constant case. */
2337 0 : if ((count & 1) == 0 && TYPE_VECTOR_SUBPARTS (vec_type).is_constant ())
2338 0 : count /= 2;
2339 0 : tree_vector_builder builder (vec_type, count, 2);
2340 0 : for (unsigned int i = 0; i < count * 2; ++i)
2341 0 : builder.quick_push (i < num_a ? a : b);
2342 0 : return builder.build ();
2343 0 : }
2344 :
2345 : /* Something has messed with the elements of CONSTRUCTOR C after it was built;
2346 : calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
2347 :
2348 : void
2349 167630274 : recompute_constructor_flags (tree c)
2350 : {
2351 167630274 : unsigned int i;
2352 167630274 : tree val;
2353 167630274 : bool constant_p = true;
2354 167630274 : bool side_effects_p = false;
2355 167630274 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2356 :
2357 349232127 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2358 : {
2359 : /* Mostly ctors will have elts that don't have side-effects, so
2360 : the usual case is to scan all the elements. Hence a single
2361 : loop for both const and side effects, rather than one loop
2362 : each (with early outs). */
2363 181601853 : if (!TREE_CONSTANT (val))
2364 22632191 : constant_p = false;
2365 181601853 : if (TREE_SIDE_EFFECTS (val))
2366 4683997 : side_effects_p = true;
2367 : }
2368 :
2369 167630274 : TREE_SIDE_EFFECTS (c) = side_effects_p;
2370 167630274 : TREE_CONSTANT (c) = constant_p;
2371 167630274 : }
2372 :
2373 : /* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
2374 : CONSTRUCTOR C. */
2375 :
2376 : void
2377 19897025 : verify_constructor_flags (tree c)
2378 : {
2379 19897025 : unsigned int i;
2380 19897025 : tree val;
2381 19897025 : bool constant_p = TREE_CONSTANT (c);
2382 19897025 : bool side_effects_p = TREE_SIDE_EFFECTS (c);
2383 19897025 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2384 :
2385 174435675 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2386 : {
2387 154538650 : if (constant_p && !TREE_CONSTANT (val))
2388 0 : internal_error ("non-constant element in constant CONSTRUCTOR");
2389 154538650 : if (!side_effects_p && TREE_SIDE_EFFECTS (val))
2390 0 : internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
2391 : }
2392 19897025 : }
2393 :
2394 : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2395 : are in the vec pointed to by VALS. */
2396 : tree
2397 142938429 : build_constructor (tree type, vec<constructor_elt, va_gc> *vals MEM_STAT_DECL)
2398 : {
2399 142938429 : tree c = make_node (CONSTRUCTOR PASS_MEM_STAT);
2400 :
2401 142938429 : TREE_TYPE (c) = type;
2402 142938429 : CONSTRUCTOR_ELTS (c) = vals;
2403 :
2404 142938429 : recompute_constructor_flags (c);
2405 :
2406 142938429 : return c;
2407 : }
2408 :
2409 : /* Build a CONSTRUCTOR node made of a single initializer, with the specified
2410 : INDEX and VALUE. */
2411 : tree
2412 7015 : build_constructor_single (tree type, tree index, tree value)
2413 : {
2414 7015 : vec<constructor_elt, va_gc> *v;
2415 7015 : constructor_elt elt = {index, value};
2416 :
2417 7015 : vec_alloc (v, 1);
2418 7015 : v->quick_push (elt);
2419 :
2420 7015 : return build_constructor (type, v);
2421 : }
2422 :
2423 :
2424 : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2425 : are in a list pointed to by VALS. */
2426 : tree
2427 1013 : build_constructor_from_list (tree type, tree vals)
2428 : {
2429 1013 : tree t;
2430 1013 : vec<constructor_elt, va_gc> *v = NULL;
2431 :
2432 1013 : if (vals)
2433 : {
2434 1013 : vec_alloc (v, list_length (vals));
2435 21849 : for (t = vals; t; t = TREE_CHAIN (t))
2436 19823 : CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
2437 : }
2438 :
2439 1013 : return build_constructor (type, v);
2440 : }
2441 :
2442 : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2443 : are in a vector pointed to by VALS. Note that the TREE_PURPOSE
2444 : fields in the constructor remain null. */
2445 :
2446 : tree
2447 1610 : build_constructor_from_vec (tree type, const vec<tree, va_gc> *vals)
2448 : {
2449 1610 : vec<constructor_elt, va_gc> *v = NULL;
2450 :
2451 73721 : for (tree t : vals)
2452 72111 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
2453 :
2454 1610 : return build_constructor (type, v);
2455 : }
2456 :
2457 : /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
2458 : of elements, provided as index/value pairs. */
2459 :
2460 : tree
2461 39817 : build_constructor_va (tree type, int nelts, ...)
2462 : {
2463 39817 : vec<constructor_elt, va_gc> *v = NULL;
2464 39817 : va_list p;
2465 :
2466 39817 : va_start (p, nelts);
2467 39817 : vec_alloc (v, nelts);
2468 39817 : while (nelts--)
2469 : {
2470 120711 : tree index = va_arg (p, tree);
2471 120711 : tree value = va_arg (p, tree);
2472 281239 : CONSTRUCTOR_APPEND_ELT (v, index, value);
2473 : }
2474 39817 : va_end (p);
2475 39817 : return build_constructor (type, v);
2476 : }
2477 :
2478 : /* Return a node of type TYPE for which TREE_CLOBBER_P is true. */
2479 :
2480 : tree
2481 10137458 : build_clobber (tree type, enum clobber_kind kind)
2482 : {
2483 10137458 : tree clobber = build_constructor (type, NULL);
2484 10137458 : TREE_THIS_VOLATILE (clobber) = true;
2485 10137458 : CLOBBER_KIND (clobber) = kind;
2486 10137458 : return clobber;
2487 : }
2488 :
2489 : /* Return a new FIXED_CST node whose type is TYPE and value is F. */
2490 :
2491 : tree
2492 54 : build_fixed (tree type, FIXED_VALUE_TYPE f)
2493 : {
2494 54 : tree v;
2495 54 : FIXED_VALUE_TYPE *fp;
2496 :
2497 54 : v = make_node (FIXED_CST);
2498 54 : fp = ggc_alloc<fixed_value> ();
2499 54 : memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
2500 :
2501 54 : TREE_TYPE (v) = type;
2502 54 : TREE_FIXED_CST_PTR (v) = fp;
2503 54 : return v;
2504 : }
2505 :
2506 : /* Return a new REAL_CST node whose type is TYPE and value is D. */
2507 :
2508 : tree
2509 43631907 : build_real (tree type, REAL_VALUE_TYPE d)
2510 : {
2511 43631907 : tree v;
2512 43631907 : int overflow = 0;
2513 :
2514 : /* dconst{0,1,2,m1,half} are used in various places in
2515 : the middle-end and optimizers, allow them here
2516 : even for decimal floating point types as an exception
2517 : by converting them to decimal. */
2518 43631907 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))
2519 610457 : && (d.cl == rvc_normal || d.cl == rvc_zero)
2520 44240166 : && !d.decimal)
2521 : {
2522 610 : if (memcmp (&d, &dconst1, sizeof (d)) == 0)
2523 0 : decimal_real_from_string (&d, "1");
2524 610 : else if (memcmp (&d, &dconst2, sizeof (d)) == 0)
2525 22 : decimal_real_from_string (&d, "2");
2526 588 : else if (memcmp (&d, &dconstm1, sizeof (d)) == 0)
2527 90 : decimal_real_from_string (&d, "-1");
2528 498 : else if (memcmp (&d, &dconsthalf, sizeof (d)) == 0)
2529 0 : decimal_real_from_string (&d, "0.5");
2530 498 : else if (memcmp (&d, &dconst0, sizeof (d)) == 0)
2531 : {
2532 : /* Make sure to give zero the minimum quantum exponent for
2533 : the type (which corresponds to all bits zero). */
2534 498 : const struct real_format *fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
2535 498 : char buf[16];
2536 498 : sprintf (buf, "0e%d", fmt->emin - fmt->p);
2537 498 : decimal_real_from_string (&d, buf);
2538 : }
2539 : else
2540 0 : gcc_unreachable ();
2541 : }
2542 :
2543 : /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
2544 : Consider doing it via real_convert now. */
2545 :
2546 43631907 : v = make_node (REAL_CST);
2547 43631907 : TREE_TYPE (v) = type;
2548 43631907 : memcpy (TREE_REAL_CST_PTR (v), &d, sizeof (REAL_VALUE_TYPE));
2549 43631907 : TREE_OVERFLOW (v) = overflow;
2550 43631907 : return v;
2551 : }
2552 :
2553 : /* Like build_real, but first truncate D to the type. */
2554 :
2555 : tree
2556 175945 : build_real_truncate (tree type, REAL_VALUE_TYPE d)
2557 : {
2558 175945 : return build_real (type, real_value_truncate (TYPE_MODE (type), d));
2559 : }
2560 :
2561 : /* Return a new REAL_CST node whose type is TYPE
2562 : and whose value is the integer value of the INTEGER_CST node I. */
2563 :
2564 : REAL_VALUE_TYPE
2565 24854774 : real_value_from_int_cst (const_tree type, const_tree i)
2566 : {
2567 24854774 : REAL_VALUE_TYPE d;
2568 :
2569 : /* Clear all bits of the real value type so that we can later do
2570 : bitwise comparisons to see if two values are the same. */
2571 24854774 : memset (&d, 0, sizeof d);
2572 :
2573 24854774 : real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, wi::to_wide (i),
2574 24854774 : TYPE_SIGN (TREE_TYPE (i)));
2575 24854774 : return d;
2576 : }
2577 :
2578 : /* Given a tree representing an integer constant I, return a tree
2579 : representing the same value as a floating-point constant of type TYPE. */
2580 :
2581 : tree
2582 24228923 : build_real_from_int_cst (tree type, const_tree i)
2583 : {
2584 24228923 : tree v;
2585 24228923 : int overflow = TREE_OVERFLOW (i);
2586 :
2587 24228923 : v = build_real (type, real_value_from_int_cst (type, i));
2588 :
2589 24228923 : TREE_OVERFLOW (v) |= overflow;
2590 24228923 : return v;
2591 : }
2592 :
2593 : /* Return a new REAL_CST node whose type is TYPE
2594 : and whose value is the integer value I which has sign SGN. */
2595 :
2596 : tree
2597 138 : build_real_from_wide (tree type, const wide_int_ref &i, signop sgn)
2598 : {
2599 138 : REAL_VALUE_TYPE d;
2600 :
2601 : /* Clear all bits of the real value type so that we can later do
2602 : bitwise comparisons to see if two values are the same. */
2603 138 : memset (&d, 0, sizeof d);
2604 :
2605 138 : real_from_integer (&d, TYPE_MODE (type), i, sgn);
2606 138 : return build_real (type, d);
2607 : }
2608 :
2609 : /* Return a newly constructed STRING_CST node whose value is the LEN
2610 : characters at STR when STR is nonnull, or all zeros otherwise.
2611 : Note that for a C string literal, LEN should include the trailing NUL.
2612 : The TREE_TYPE is not initialized. */
2613 :
2614 : tree
2615 101245744 : build_string (unsigned len, const char *str /*= NULL */)
2616 : {
2617 : /* Do not waste bytes provided by padding of struct tree_string. */
2618 101245744 : unsigned size = len + offsetof (struct tree_string, str) + 1;
2619 :
2620 101245744 : record_node_allocation_statistics (STRING_CST, size);
2621 :
2622 101245744 : tree s = (tree) ggc_internal_alloc (size);
2623 :
2624 101245744 : memset (s, 0, sizeof (struct tree_typed));
2625 101245744 : TREE_SET_CODE (s, STRING_CST);
2626 101245744 : TREE_CONSTANT (s) = 1;
2627 101245744 : TREE_STRING_LENGTH (s) = len;
2628 101245744 : if (str)
2629 101236577 : memcpy (s->string.str, str, len);
2630 : else
2631 9167 : memset (s->string.str, 0, len);
2632 101245744 : s->string.str[len] = '\0';
2633 :
2634 101245744 : return s;
2635 : }
2636 :
2637 : /* Return a newly constructed COMPLEX_CST node whose value is
2638 : specified by the real and imaginary parts REAL and IMAG.
2639 : Both REAL and IMAG should be constant nodes. TYPE, if specified,
2640 : will be the type of the COMPLEX_CST; otherwise a new type will be made. */
2641 :
2642 : tree
2643 487756 : build_complex (tree type, tree real, tree imag)
2644 : {
2645 487756 : gcc_assert (CONSTANT_CLASS_P (real));
2646 487756 : gcc_assert (CONSTANT_CLASS_P (imag));
2647 :
2648 487756 : tree t = make_node (COMPLEX_CST);
2649 :
2650 487756 : TREE_REALPART (t) = real;
2651 487756 : TREE_IMAGPART (t) = imag;
2652 487756 : TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
2653 487756 : TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
2654 487756 : return t;
2655 : }
2656 :
2657 : /* Build a complex (inf +- 0i), such as for the result of cproj.
2658 : TYPE is the complex tree type of the result. If NEG is true, the
2659 : imaginary zero is negative. */
2660 :
2661 : tree
2662 840 : build_complex_inf (tree type, bool neg)
2663 : {
2664 840 : REAL_VALUE_TYPE rzero = dconst0;
2665 :
2666 840 : rzero.sign = neg;
2667 840 : return build_complex (type, build_real (TREE_TYPE (type), dconstinf),
2668 840 : build_real (TREE_TYPE (type), rzero));
2669 : }
2670 :
2671 : /* Return the constant 1 in type TYPE. If TYPE has several elements, each
2672 : element is set to 1. In particular, this is 1 + i for complex types. */
2673 :
2674 : tree
2675 3823 : build_each_one_cst (tree type)
2676 : {
2677 3823 : if (TREE_CODE (type) == COMPLEX_TYPE)
2678 : {
2679 0 : tree scalar = build_one_cst (TREE_TYPE (type));
2680 0 : return build_complex (type, scalar, scalar);
2681 : }
2682 : else
2683 3823 : return build_one_cst (type);
2684 : }
2685 :
2686 : /* Return a constant of arithmetic type TYPE which is the
2687 : multiplicative identity of the set TYPE. */
2688 :
2689 : tree
2690 10236333 : build_one_cst (tree type)
2691 : {
2692 10236333 : switch (TREE_CODE (type))
2693 : {
2694 10222036 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2695 10222036 : case POINTER_TYPE: case REFERENCE_TYPE:
2696 10222036 : case OFFSET_TYPE: case BITINT_TYPE:
2697 10222036 : return build_int_cst (type, 1);
2698 :
2699 10687 : case REAL_TYPE:
2700 10687 : return build_real (type, dconst1);
2701 :
2702 0 : case FIXED_POINT_TYPE:
2703 : /* We can only generate 1 for accum types. */
2704 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2705 0 : return build_fixed (type, FCONST1 (TYPE_MODE (type)));
2706 :
2707 591 : case VECTOR_TYPE:
2708 591 : {
2709 591 : tree scalar = build_one_cst (TREE_TYPE (type));
2710 :
2711 591 : return build_vector_from_val (type, scalar);
2712 : }
2713 :
2714 3019 : case COMPLEX_TYPE:
2715 6038 : return build_complex (type,
2716 3019 : build_one_cst (TREE_TYPE (type)),
2717 6038 : build_zero_cst (TREE_TYPE (type)));
2718 :
2719 0 : default:
2720 0 : gcc_unreachable ();
2721 : }
2722 : }
2723 :
2724 : /* Return an integer of type TYPE containing all 1's in as much precision as
2725 : it contains, or a complex or vector whose subparts are such integers. */
2726 :
2727 : tree
2728 1720606 : build_all_ones_cst (tree type)
2729 : {
2730 1720606 : if (TREE_CODE (type) == COMPLEX_TYPE)
2731 : {
2732 0 : tree scalar = build_all_ones_cst (TREE_TYPE (type));
2733 0 : return build_complex (type, scalar, scalar);
2734 : }
2735 : else
2736 1720606 : return build_minus_one_cst (type);
2737 : }
2738 :
2739 : /* Return a constant of arithmetic type TYPE which is the
2740 : opposite of the multiplicative identity of the set TYPE. */
2741 :
2742 : tree
2743 3133550 : build_minus_one_cst (tree type)
2744 : {
2745 3133550 : switch (TREE_CODE (type))
2746 : {
2747 3008686 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2748 3008686 : case POINTER_TYPE: case REFERENCE_TYPE:
2749 3008686 : case OFFSET_TYPE: case BITINT_TYPE:
2750 3008686 : return build_int_cst (type, -1);
2751 :
2752 14776 : case REAL_TYPE:
2753 14776 : return build_real (type, dconstm1);
2754 :
2755 0 : case FIXED_POINT_TYPE:
2756 : /* We can only generate 1 for accum types. */
2757 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2758 0 : return build_fixed (type,
2759 : fixed_from_double_int (double_int_minus_one,
2760 0 : SCALAR_TYPE_MODE (type)));
2761 :
2762 110088 : case VECTOR_TYPE:
2763 110088 : {
2764 110088 : tree scalar = build_minus_one_cst (TREE_TYPE (type));
2765 :
2766 110088 : return build_vector_from_val (type, scalar);
2767 : }
2768 :
2769 0 : case COMPLEX_TYPE:
2770 0 : return build_complex (type,
2771 0 : build_minus_one_cst (TREE_TYPE (type)),
2772 0 : build_zero_cst (TREE_TYPE (type)));
2773 :
2774 0 : default:
2775 0 : gcc_unreachable ();
2776 : }
2777 : }
2778 :
2779 : /* Build 0 constant of type TYPE. This is used by constructor folding
2780 : and thus the constant should be represented in memory by
2781 : zero(es). */
2782 :
2783 : tree
2784 90234262 : build_zero_cst (tree type)
2785 : {
2786 90234262 : switch (TREE_CODE (type))
2787 : {
2788 89645226 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2789 89645226 : case POINTER_TYPE: case REFERENCE_TYPE:
2790 89645226 : case OFFSET_TYPE: case NULLPTR_TYPE: case BITINT_TYPE:
2791 89645226 : return build_int_cst (type, 0);
2792 :
2793 222963 : case REAL_TYPE:
2794 222963 : return build_real (type, dconst0);
2795 :
2796 0 : case FIXED_POINT_TYPE:
2797 0 : return build_fixed (type, FCONST0 (TYPE_MODE (type)));
2798 :
2799 177750 : case VECTOR_TYPE:
2800 177750 : {
2801 177750 : tree scalar = build_zero_cst (TREE_TYPE (type));
2802 :
2803 177750 : return build_vector_from_val (type, scalar);
2804 : }
2805 :
2806 2083 : case COMPLEX_TYPE:
2807 2083 : {
2808 2083 : tree zero = build_zero_cst (TREE_TYPE (type));
2809 :
2810 2083 : return build_complex (type, zero, zero);
2811 : }
2812 :
2813 186240 : default:
2814 186240 : if (!AGGREGATE_TYPE_P (type))
2815 1 : return fold_convert (type, integer_zero_node);
2816 186239 : return build_constructor (type, NULL);
2817 : }
2818 : }
2819 :
2820 : /* Build a constant of integer type TYPE, made of VALUE's bits replicated
2821 : every WIDTH bits to fit TYPE's precision. */
2822 :
2823 : tree
2824 14 : build_replicated_int_cst (tree type, unsigned int width, HOST_WIDE_INT value)
2825 : {
2826 14 : int n = ((TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
2827 14 : / HOST_BITS_PER_WIDE_INT);
2828 14 : unsigned HOST_WIDE_INT low, mask;
2829 14 : HOST_WIDE_INT a[WIDE_INT_MAX_INL_ELTS];
2830 14 : int i;
2831 :
2832 14 : gcc_assert (n && n <= WIDE_INT_MAX_INL_ELTS);
2833 :
2834 14 : if (width == HOST_BITS_PER_WIDE_INT)
2835 0 : low = value;
2836 : else
2837 : {
2838 14 : mask = (HOST_WIDE_INT_1U << width) - 1;
2839 14 : low = (unsigned HOST_WIDE_INT) ~0 / mask * (value & mask);
2840 : }
2841 :
2842 28 : for (i = 0; i < n; i++)
2843 14 : a[i] = low;
2844 :
2845 14 : gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
2846 14 : return wide_int_to_tree (type, wide_int::from_array (a, n,
2847 14 : TYPE_PRECISION (type)));
2848 : }
2849 :
2850 : /* If floating-point type TYPE has an IEEE-style sign bit, return an
2851 : unsigned constant in which only the sign bit is set. Return null
2852 : otherwise. */
2853 :
2854 : tree
2855 0 : sign_mask_for (tree type)
2856 : {
2857 : /* Avoid having to choose between a real-only sign and a pair of signs.
2858 : This could be relaxed if the choice becomes obvious later. */
2859 0 : if (TREE_CODE (type) == COMPLEX_TYPE)
2860 : return NULL_TREE;
2861 :
2862 0 : auto eltmode = as_a<scalar_float_mode> (element_mode (type));
2863 0 : auto bits = REAL_MODE_FORMAT (eltmode)->ieee_bits;
2864 0 : if (!bits || !pow2p_hwi (bits))
2865 : return NULL_TREE;
2866 :
2867 0 : tree inttype = unsigned_type_for (type);
2868 0 : if (!inttype)
2869 : return NULL_TREE;
2870 :
2871 0 : auto mask = wi::set_bit_in_zero (bits - 1, bits);
2872 0 : if (VECTOR_TYPE_P (inttype))
2873 : {
2874 0 : tree elt = wide_int_to_tree (TREE_TYPE (inttype), mask);
2875 0 : return build_vector_from_val (inttype, elt);
2876 : }
2877 0 : return wide_int_to_tree (inttype, mask);
2878 0 : }
2879 :
2880 : /* Build a BINFO with LEN language slots. */
2881 :
2882 : tree
2883 112263132 : make_tree_binfo (unsigned base_binfos MEM_STAT_DECL)
2884 : {
2885 112263132 : tree t;
2886 112263132 : size_t length = (offsetof (struct tree_binfo, base_binfos)
2887 112263132 : + vec<tree, va_gc>::embedded_size (base_binfos));
2888 :
2889 112263132 : record_node_allocation_statistics (TREE_BINFO, length);
2890 :
2891 112263132 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
2892 :
2893 112263132 : memset (t, 0, offsetof (struct tree_binfo, base_binfos));
2894 :
2895 112263132 : TREE_SET_CODE (t, TREE_BINFO);
2896 :
2897 112263132 : BINFO_BASE_BINFOS (t)->embedded_init (base_binfos);
2898 :
2899 112263132 : return t;
2900 : }
2901 :
2902 : /* Create a CASE_LABEL_EXPR tree node and return it. */
2903 :
2904 : tree
2905 7028843 : build_case_label (tree low_value, tree high_value, tree label_decl)
2906 : {
2907 7028843 : tree t = make_node (CASE_LABEL_EXPR);
2908 :
2909 7028843 : TREE_TYPE (t) = void_type_node;
2910 7028843 : SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl));
2911 :
2912 7028843 : CASE_LOW (t) = low_value;
2913 7028843 : CASE_HIGH (t) = high_value;
2914 7028843 : CASE_LABEL (t) = label_decl;
2915 7028843 : CASE_CHAIN (t) = NULL_TREE;
2916 :
2917 7028843 : return t;
2918 : }
2919 :
2920 : /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2921 : values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2922 : The latter determines the length of the HOST_WIDE_INT vector. */
2923 :
2924 : tree
2925 293505283 : make_int_cst (int len, int ext_len MEM_STAT_DECL)
2926 : {
2927 293505283 : tree t;
2928 293505283 : int length = ((ext_len - 1) * sizeof (HOST_WIDE_INT)
2929 293505283 : + sizeof (struct tree_int_cst));
2930 :
2931 293505283 : gcc_assert (len);
2932 293505283 : record_node_allocation_statistics (INTEGER_CST, length);
2933 :
2934 293505283 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2935 :
2936 293505283 : TREE_SET_CODE (t, INTEGER_CST);
2937 293505283 : TREE_INT_CST_NUNITS (t) = len;
2938 293505283 : TREE_INT_CST_EXT_NUNITS (t) = ext_len;
2939 293505283 : TREE_CONSTANT (t) = 1;
2940 :
2941 293505283 : return t;
2942 : }
2943 :
2944 : /* Build a newly constructed TREE_VEC node of length LEN. */
2945 :
2946 : tree
2947 3365080296 : make_tree_vec (int len MEM_STAT_DECL)
2948 : {
2949 3365080296 : tree t;
2950 3365080296 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2951 :
2952 3365080296 : record_node_allocation_statistics (TREE_VEC, length);
2953 :
2954 3365080296 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2955 :
2956 3365080296 : TREE_SET_CODE (t, TREE_VEC);
2957 3365080296 : TREE_VEC_LENGTH (t) = len;
2958 :
2959 3365080296 : return t;
2960 : }
2961 :
2962 : /* Grow a TREE_VEC node to new length LEN. */
2963 :
2964 : tree
2965 519852 : grow_tree_vec (tree v, int len MEM_STAT_DECL)
2966 : {
2967 519852 : gcc_assert (TREE_CODE (v) == TREE_VEC);
2968 :
2969 519852 : int oldlen = TREE_VEC_LENGTH (v);
2970 519852 : gcc_assert (len > oldlen);
2971 :
2972 519852 : size_t oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
2973 519852 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2974 :
2975 519852 : record_node_allocation_statistics (TREE_VEC, length - oldlength);
2976 :
2977 519852 : v = (tree) ggc_realloc (v, length PASS_MEM_STAT);
2978 :
2979 519852 : TREE_VEC_LENGTH (v) = len;
2980 :
2981 519852 : return v;
2982 : }
2983 :
2984 : /* Return true if EXPR is the constant zero, whether it is integral, float or
2985 : fixed, and scalar, complex or vector. */
2986 :
2987 : bool
2988 18045814 : zerop (const_tree expr)
2989 : {
2990 18045814 : return (integer_zerop (expr)
2991 12491762 : || real_zerop (expr)
2992 30141248 : || fixed_zerop (expr));
2993 : }
2994 :
2995 : /* Return true if EXPR is the integer constant zero or a complex constant
2996 : of zero, or a location wrapper for such a constant. */
2997 :
2998 : bool
2999 6700639315 : integer_zerop (const_tree expr)
3000 : {
3001 6700639315 : STRIP_ANY_LOCATION_WRAPPER (expr);
3002 :
3003 6700639315 : switch (TREE_CODE (expr))
3004 : {
3005 5454882355 : case INTEGER_CST:
3006 5454882355 : return wi::to_wide (expr) == 0;
3007 1200518 : case COMPLEX_CST:
3008 1200518 : return (integer_zerop (TREE_REALPART (expr))
3009 1223058 : && integer_zerop (TREE_IMAGPART (expr)));
3010 3059015 : case VECTOR_CST:
3011 3059015 : return (VECTOR_CST_NPATTERNS (expr) == 1
3012 2889743 : && VECTOR_CST_DUPLICATE_P (expr)
3013 5497491 : && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
3014 : default:
3015 : return false;
3016 : }
3017 : }
3018 :
3019 : /* Return true if EXPR is the integer constant one or the corresponding
3020 : complex constant, or a location wrapper for such a constant. */
3021 :
3022 : bool
3023 1095205635 : integer_onep (const_tree expr)
3024 : {
3025 1095205635 : STRIP_ANY_LOCATION_WRAPPER (expr);
3026 :
3027 1095205635 : switch (TREE_CODE (expr))
3028 : {
3029 948897072 : case INTEGER_CST:
3030 948897072 : return wi::eq_p (wi::to_widest (expr), 1);
3031 21901 : case COMPLEX_CST:
3032 21901 : return (integer_onep (TREE_REALPART (expr))
3033 21925 : && integer_zerop (TREE_IMAGPART (expr)));
3034 192156 : case VECTOR_CST:
3035 192156 : return (VECTOR_CST_NPATTERNS (expr) == 1
3036 170790 : && VECTOR_CST_DUPLICATE_P (expr)
3037 339286 : && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3038 : default:
3039 : return false;
3040 : }
3041 : }
3042 :
3043 : /* Return true if EXPR is the integer constant one. For complex and vector,
3044 : return true if every piece is the integer constant one.
3045 : Also return true for location wrappers for such a constant. */
3046 :
3047 : bool
3048 774391 : integer_each_onep (const_tree expr)
3049 : {
3050 774391 : STRIP_ANY_LOCATION_WRAPPER (expr);
3051 :
3052 774391 : if (TREE_CODE (expr) == COMPLEX_CST)
3053 34 : return (integer_onep (TREE_REALPART (expr))
3054 48 : && integer_onep (TREE_IMAGPART (expr)));
3055 : else
3056 774357 : return integer_onep (expr);
3057 : }
3058 :
3059 : /* Return true if EXPR is an integer containing all 1's in as much precision
3060 : as it contains, or a complex or vector whose subparts are such integers,
3061 : or a location wrapper for such a constant. */
3062 :
3063 : bool
3064 299834957 : integer_all_onesp (const_tree expr)
3065 : {
3066 299834957 : STRIP_ANY_LOCATION_WRAPPER (expr);
3067 :
3068 299834957 : if (TREE_CODE (expr) == COMPLEX_CST
3069 952 : && integer_all_onesp (TREE_REALPART (expr))
3070 299834997 : && integer_all_onesp (TREE_IMAGPART (expr)))
3071 : return true;
3072 :
3073 299834921 : else if (TREE_CODE (expr) == VECTOR_CST)
3074 626664 : return (VECTOR_CST_NPATTERNS (expr) == 1
3075 573536 : && VECTOR_CST_DUPLICATE_P (expr)
3076 1175598 : && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
3077 :
3078 299208257 : else if (TREE_CODE (expr) != INTEGER_CST)
3079 : return false;
3080 :
3081 198366363 : return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED)
3082 396798822 : == wi::to_wide (expr));
3083 : }
3084 :
3085 : /* Return true if EXPR is the integer constant minus one, or a location
3086 : wrapper for such a constant. */
3087 :
3088 : bool
3089 218968063 : integer_minus_onep (const_tree expr)
3090 : {
3091 218968063 : STRIP_ANY_LOCATION_WRAPPER (expr);
3092 :
3093 218968063 : if (TREE_CODE (expr) == COMPLEX_CST)
3094 9421 : return (integer_all_onesp (TREE_REALPART (expr))
3095 9425 : && integer_zerop (TREE_IMAGPART (expr)));
3096 : else
3097 218958642 : return integer_all_onesp (expr);
3098 : }
3099 :
3100 : /* Return true if EXPR is an integer constant that is a power of 2 (i.e., has
3101 : only one bit on), or a location wrapper for such a constant. */
3102 :
3103 : bool
3104 22334388 : integer_pow2p (const_tree expr)
3105 : {
3106 22334388 : STRIP_ANY_LOCATION_WRAPPER (expr);
3107 :
3108 22334388 : if (TREE_CODE (expr) == COMPLEX_CST
3109 553 : && integer_pow2p (TREE_REALPART (expr))
3110 22334615 : && integer_zerop (TREE_IMAGPART (expr)))
3111 : return true;
3112 :
3113 22334235 : if (TREE_CODE (expr) != INTEGER_CST)
3114 : return false;
3115 :
3116 13985422 : return wi::popcount (wi::to_wide (expr)) == 1;
3117 : }
3118 :
3119 : /* Return true if EXPR is an integer constant other than zero or a
3120 : complex constant other than zero, or a location wrapper for such a
3121 : constant. */
3122 :
3123 : bool
3124 155139985 : integer_nonzerop (const_tree expr)
3125 : {
3126 155139985 : STRIP_ANY_LOCATION_WRAPPER (expr);
3127 :
3128 155139985 : return ((TREE_CODE (expr) == INTEGER_CST
3129 77006937 : && wi::to_wide (expr) != 0)
3130 175650993 : || (TREE_CODE (expr) == COMPLEX_CST
3131 244 : && (integer_nonzerop (TREE_REALPART (expr))
3132 184 : || integer_nonzerop (TREE_IMAGPART (expr)))));
3133 : }
3134 :
3135 : /* Return true if EXPR is the integer constant one. For vector,
3136 : return true if every piece is the integer constant minus one
3137 : (representing the value TRUE).
3138 : Also return true for location wrappers for such a constant. */
3139 :
3140 : bool
3141 1198472 : integer_truep (const_tree expr)
3142 : {
3143 1198472 : STRIP_ANY_LOCATION_WRAPPER (expr);
3144 :
3145 1198472 : if (TREE_CODE (expr) == VECTOR_CST)
3146 14916 : return integer_all_onesp (expr);
3147 1183556 : return integer_onep (expr);
3148 : }
3149 :
3150 : /* Return true if EXPR is the fixed-point constant zero, or a location wrapper
3151 : for such a constant. */
3152 :
3153 : bool
3154 29578132 : fixed_zerop (const_tree expr)
3155 : {
3156 29578132 : STRIP_ANY_LOCATION_WRAPPER (expr);
3157 :
3158 29578132 : return (TREE_CODE (expr) == FIXED_CST
3159 29578132 : && TREE_FIXED_CST (expr).data.is_zero ());
3160 : }
3161 :
3162 : /* Return the power of two represented by a tree node known to be a
3163 : power of two. */
3164 :
3165 : int
3166 788316 : tree_log2 (const_tree expr)
3167 : {
3168 788316 : if (TREE_CODE (expr) == COMPLEX_CST)
3169 0 : return tree_log2 (TREE_REALPART (expr));
3170 :
3171 788316 : return wi::exact_log2 (wi::to_wide (expr));
3172 : }
3173 :
3174 : /* Similar, but return the largest integer Y such that 2 ** Y is less
3175 : than or equal to EXPR. */
3176 :
3177 : int
3178 2978883 : tree_floor_log2 (const_tree expr)
3179 : {
3180 2978883 : if (TREE_CODE (expr) == COMPLEX_CST)
3181 0 : return tree_log2 (TREE_REALPART (expr));
3182 :
3183 2978883 : return wi::floor_log2 (wi::to_wide (expr));
3184 : }
3185 :
3186 : /* Return number of known trailing zero bits in EXPR, or, if the value of
3187 : EXPR is known to be zero, the precision of it's type. */
3188 :
3189 : unsigned int
3190 84211779 : tree_ctz (const_tree expr)
3191 : {
3192 168421837 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
3193 84219945 : && !POINTER_TYPE_P (TREE_TYPE (expr)))
3194 : return 0;
3195 :
3196 84211718 : unsigned int ret1, ret2, prec = TYPE_PRECISION (TREE_TYPE (expr));
3197 84211718 : switch (TREE_CODE (expr))
3198 : {
3199 44829632 : case INTEGER_CST:
3200 44829632 : ret1 = wi::ctz (wi::to_wide (expr));
3201 44829632 : return MIN (ret1, prec);
3202 12850379 : case SSA_NAME:
3203 12850379 : ret1 = wi::ctz (get_nonzero_bits (expr));
3204 12850379 : return MIN (ret1, prec);
3205 2085632 : case PLUS_EXPR:
3206 2085632 : case MINUS_EXPR:
3207 2085632 : case BIT_IOR_EXPR:
3208 2085632 : case BIT_XOR_EXPR:
3209 2085632 : case MIN_EXPR:
3210 2085632 : case MAX_EXPR:
3211 2085632 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3212 2085632 : if (ret1 == 0)
3213 : return ret1;
3214 961277 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3215 961277 : return MIN (ret1, ret2);
3216 0 : case POINTER_PLUS_EXPR:
3217 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3218 0 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3219 : /* Second operand is sizetype, which could be in theory
3220 : wider than pointer's precision. Make sure we never
3221 : return more than prec. */
3222 0 : ret2 = MIN (ret2, prec);
3223 0 : return MIN (ret1, ret2);
3224 234 : case BIT_AND_EXPR:
3225 234 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3226 234 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3227 234 : return MAX (ret1, ret2);
3228 11914941 : case MULT_EXPR:
3229 11914941 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3230 11914941 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3231 11914941 : return MIN (ret1 + ret2, prec);
3232 0 : case LSHIFT_EXPR:
3233 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3234 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3235 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3236 : {
3237 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3238 0 : return MIN (ret1 + ret2, prec);
3239 : }
3240 : return ret1;
3241 0 : case RSHIFT_EXPR:
3242 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3243 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3244 : {
3245 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3246 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3247 0 : if (ret1 > ret2)
3248 0 : return ret1 - ret2;
3249 : }
3250 : return 0;
3251 6079 : case TRUNC_DIV_EXPR:
3252 6079 : case CEIL_DIV_EXPR:
3253 6079 : case FLOOR_DIV_EXPR:
3254 6079 : case ROUND_DIV_EXPR:
3255 6079 : case EXACT_DIV_EXPR:
3256 6079 : if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
3257 6079 : && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) == 1)
3258 : {
3259 6079 : int l = tree_log2 (TREE_OPERAND (expr, 1));
3260 6079 : if (l >= 0)
3261 : {
3262 5003 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3263 5003 : ret2 = l;
3264 5003 : if (ret1 > ret2)
3265 0 : return ret1 - ret2;
3266 : }
3267 : }
3268 : return 0;
3269 12501636 : CASE_CONVERT:
3270 12501636 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3271 12501636 : if (ret1 && ret1 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
3272 : ret1 = prec;
3273 12501636 : return MIN (ret1, prec);
3274 0 : case SAVE_EXPR:
3275 0 : return tree_ctz (TREE_OPERAND (expr, 0));
3276 12590 : case COND_EXPR:
3277 12590 : ret1 = tree_ctz (TREE_OPERAND (expr, 1));
3278 12590 : if (ret1 == 0)
3279 : return 0;
3280 205 : ret2 = tree_ctz (TREE_OPERAND (expr, 2));
3281 205 : return MIN (ret1, ret2);
3282 0 : case COMPOUND_EXPR:
3283 0 : return tree_ctz (TREE_OPERAND (expr, 1));
3284 204 : case ADDR_EXPR:
3285 204 : ret1 = get_pointer_alignment (const_cast<tree> (expr));
3286 204 : if (ret1 > BITS_PER_UNIT)
3287 : {
3288 204 : ret1 = ctz_hwi (ret1 / BITS_PER_UNIT);
3289 204 : return MIN (ret1, prec);
3290 : }
3291 : return 0;
3292 : default:
3293 : return 0;
3294 : }
3295 : }
3296 :
3297 : /* Return true if EXPR is the real constant zero. Trailing zeroes matter for
3298 : decimal float constants, so don't return true for them.
3299 : Also return true for location wrappers around such a constant. */
3300 :
3301 : bool
3302 592275528 : real_zerop (const_tree expr)
3303 : {
3304 592275528 : STRIP_ANY_LOCATION_WRAPPER (expr);
3305 :
3306 592275528 : switch (TREE_CODE (expr))
3307 : {
3308 19405847 : case REAL_CST:
3309 19405847 : return real_equal (&TREE_REAL_CST (expr), &dconst0)
3310 19405847 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3311 45276 : case COMPLEX_CST:
3312 45276 : return real_zerop (TREE_REALPART (expr))
3313 58215 : && real_zerop (TREE_IMAGPART (expr));
3314 471598 : case VECTOR_CST:
3315 471598 : {
3316 : /* Don't simply check for a duplicate because the predicate
3317 : accepts both +0.0 and -0.0. */
3318 471598 : unsigned count = vector_cst_encoded_nelts (expr);
3319 977960 : for (unsigned int i = 0; i < count; ++i)
3320 482664 : if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3321 : return false;
3322 : return true;
3323 : }
3324 : default:
3325 : return false;
3326 : }
3327 : }
3328 :
3329 : /* Return true if EXPR is the real constant negative zero. */
3330 :
3331 : bool
3332 6 : real_negzerop (const_tree expr)
3333 : {
3334 6 : STRIP_ANY_LOCATION_WRAPPER (expr);
3335 :
3336 6 : if (TREE_CODE (expr) == VECTOR_CST)
3337 : {
3338 0 : expr = uniform_vector_p (expr);
3339 0 : if (!expr)
3340 : return false;
3341 : }
3342 :
3343 6 : if (TREE_CODE (expr) == COMPLEX_CST)
3344 2 : return real_negzerop (TREE_REALPART (expr))
3345 4 : && real_negzerop (TREE_IMAGPART (expr));
3346 :
3347 4 : return TREE_CODE (expr) == REAL_CST
3348 4 : && REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (expr))
3349 8 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3350 : }
3351 :
3352 : /* Return true if EXPR is the real constant one in real or complex form.
3353 : Trailing zeroes matter for decimal float constants, so don't return
3354 : true for them.
3355 : Also return true for location wrappers around such a constant. */
3356 :
3357 : bool
3358 122407670 : real_onep (const_tree expr)
3359 : {
3360 122407670 : STRIP_ANY_LOCATION_WRAPPER (expr);
3361 :
3362 122407670 : switch (TREE_CODE (expr))
3363 : {
3364 7229537 : case REAL_CST:
3365 7229537 : return real_equal (&TREE_REAL_CST (expr), &dconst1)
3366 7229537 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3367 12972 : case COMPLEX_CST:
3368 12972 : return real_onep (TREE_REALPART (expr))
3369 16581 : && real_zerop (TREE_IMAGPART (expr));
3370 61130 : case VECTOR_CST:
3371 61130 : return (VECTOR_CST_NPATTERNS (expr) == 1
3372 51864 : && VECTOR_CST_DUPLICATE_P (expr)
3373 102559 : && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3374 : default:
3375 : return false;
3376 : }
3377 : }
3378 :
3379 : /* Return true if EXPR is the real constant minus one. Trailing zeroes
3380 : matter for decimal float constants, so don't return true for them.
3381 : Also return true for location wrappers around such a constant. */
3382 :
3383 : bool
3384 123437377 : real_minus_onep (const_tree expr)
3385 : {
3386 123437377 : STRIP_ANY_LOCATION_WRAPPER (expr);
3387 :
3388 123437377 : switch (TREE_CODE (expr))
3389 : {
3390 7162891 : case REAL_CST:
3391 7162891 : return real_equal (&TREE_REAL_CST (expr), &dconstm1)
3392 7162891 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3393 12952 : case COMPLEX_CST:
3394 12952 : return real_minus_onep (TREE_REALPART (expr))
3395 15324 : && real_zerop (TREE_IMAGPART (expr));
3396 62739 : case VECTOR_CST:
3397 62739 : return (VECTOR_CST_NPATTERNS (expr) == 1
3398 52873 : && VECTOR_CST_DUPLICATE_P (expr)
3399 104992 : && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3400 : default:
3401 : return false;
3402 : }
3403 : }
3404 :
3405 : /* Return true if T could be a floating point zero. */
3406 :
3407 : bool
3408 704193 : real_maybe_zerop (const_tree expr)
3409 : {
3410 704193 : switch (TREE_CODE (expr))
3411 : {
3412 484297 : case REAL_CST:
3413 : /* Can't use real_zerop here, as it always returns false for decimal
3414 : floats. And can't use TREE_REAL_CST (expr).cl == rvc_zero
3415 : either, as decimal zeros are rvc_normal. */
3416 484297 : return real_equal (&TREE_REAL_CST (expr), &dconst0);
3417 0 : case COMPLEX_CST:
3418 0 : return (real_maybe_zerop (TREE_REALPART (expr))
3419 0 : || real_maybe_zerop (TREE_IMAGPART (expr)));
3420 0 : case VECTOR_CST:
3421 0 : {
3422 0 : unsigned count = vector_cst_encoded_nelts (expr);
3423 0 : for (unsigned int i = 0; i < count; ++i)
3424 0 : if (real_maybe_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3425 : return true;
3426 : return false;
3427 : }
3428 : default:
3429 : /* Perhaps for SSA_NAMEs we could query frange. */
3430 : return true;
3431 : }
3432 : }
3433 :
3434 : /* True if EXP is a constant or a cast of a constant. */
3435 :
3436 : bool
3437 6113 : really_constant_p (const_tree exp)
3438 : {
3439 : /* This is not quite the same as STRIP_NOPS. It does more. */
3440 12234 : while (CONVERT_EXPR_P (exp)
3441 12286 : || TREE_CODE (exp) == NON_LVALUE_EXPR)
3442 60 : exp = TREE_OPERAND (exp, 0);
3443 6113 : return TREE_CONSTANT (exp);
3444 : }
3445 :
3446 : /* Return true if T holds a polynomial pointer difference, storing it in
3447 : *VALUE if so. A true return means that T's precision is no greater
3448 : than 64 bits, which is the largest address space we support, so *VALUE
3449 : never loses precision. However, the signedness of the result does
3450 : not necessarily match the signedness of T: sometimes an unsigned type
3451 : like sizetype is used to encode a value that is actually negative. */
3452 :
3453 : bool
3454 11398445 : ptrdiff_tree_p (const_tree t, poly_int64 *value)
3455 : {
3456 11398445 : if (!t)
3457 : return false;
3458 11398445 : if (TREE_CODE (t) == INTEGER_CST)
3459 : {
3460 3300346 : if (!cst_and_fits_in_hwi (t))
3461 : return false;
3462 3299775 : *value = int_cst_value (t);
3463 3299775 : return true;
3464 : }
3465 : if (POLY_INT_CST_P (t))
3466 : {
3467 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3468 : if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t, i)))
3469 : return false;
3470 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3471 : value->coeffs[i] = int_cst_value (POLY_INT_CST_COEFF (t, i));
3472 : return true;
3473 : }
3474 : return false;
3475 : }
3476 :
3477 : poly_int64
3478 487020029 : tree_to_poly_int64 (const_tree t)
3479 : {
3480 487020029 : gcc_assert (tree_fits_poly_int64_p (t));
3481 487020029 : if (POLY_INT_CST_P (t))
3482 : return poly_int_cst_value (t).force_shwi ();
3483 487020029 : return TREE_INT_CST_LOW (t);
3484 : }
3485 :
3486 : poly_uint64
3487 551464927 : tree_to_poly_uint64 (const_tree t)
3488 : {
3489 551464927 : gcc_assert (tree_fits_poly_uint64_p (t));
3490 551464927 : if (POLY_INT_CST_P (t))
3491 : return poly_int_cst_value (t).force_uhwi ();
3492 551464927 : return TREE_INT_CST_LOW (t);
3493 : }
3494 :
3495 : /* Return first list element whose TREE_VALUE is ELEM.
3496 : Return 0 if ELEM is not in LIST. */
3497 :
3498 : tree
3499 8241689 : value_member (tree elem, tree list)
3500 : {
3501 23988534 : while (list)
3502 : {
3503 20833120 : if (elem == TREE_VALUE (list))
3504 : return list;
3505 15746845 : list = TREE_CHAIN (list);
3506 : }
3507 : return NULL_TREE;
3508 : }
3509 :
3510 : /* Return first list element whose TREE_PURPOSE is ELEM.
3511 : Return 0 if ELEM is not in LIST. */
3512 :
3513 : tree
3514 206525806 : purpose_member (const_tree elem, tree list)
3515 : {
3516 544528292 : while (list)
3517 : {
3518 370186582 : if (elem == TREE_PURPOSE (list))
3519 : return list;
3520 338002486 : list = TREE_CHAIN (list);
3521 : }
3522 : return NULL_TREE;
3523 : }
3524 :
3525 : /* Return true if ELEM is in V. */
3526 :
3527 : bool
3528 5368892 : vec_member (const_tree elem, vec<tree, va_gc> *v)
3529 : {
3530 5368892 : unsigned ix;
3531 5368892 : tree t;
3532 8108464 : FOR_EACH_VEC_SAFE_ELT (v, ix, t)
3533 2747826 : if (elem == t)
3534 : return true;
3535 : return false;
3536 : }
3537 :
3538 : /* Returns element number IDX (zero-origin) of chain CHAIN, or
3539 : NULL_TREE. */
3540 :
3541 : tree
3542 23056112 : chain_index (int idx, tree chain)
3543 : {
3544 29576223 : for (; chain && idx > 0; --idx)
3545 6520111 : chain = TREE_CHAIN (chain);
3546 23056112 : return chain;
3547 : }
3548 :
3549 : /* Return true if ELEM is part of the chain CHAIN. */
3550 :
3551 : bool
3552 234857 : chain_member (const_tree elem, const_tree chain)
3553 : {
3554 434047 : while (chain)
3555 : {
3556 432560 : if (elem == chain)
3557 : return true;
3558 199190 : chain = DECL_CHAIN (chain);
3559 : }
3560 :
3561 : return false;
3562 : }
3563 :
3564 : /* Return the length of a chain of nodes chained through TREE_CHAIN.
3565 : We expect a null pointer to mark the end of the chain.
3566 : This is the Lisp primitive `length'. */
3567 :
3568 : int
3569 2147567434 : list_length (const_tree t)
3570 : {
3571 2147567434 : const_tree p = t;
3572 : #ifdef ENABLE_TREE_CHECKING
3573 2147567434 : const_tree q = t;
3574 : #endif
3575 2147567434 : int len = 0;
3576 :
3577 3593525015 : while (p)
3578 : {
3579 1445957581 : p = TREE_CHAIN (p);
3580 : #ifdef ENABLE_TREE_CHECKING
3581 1445957581 : if (len % 2)
3582 471611187 : q = TREE_CHAIN (q);
3583 1445957581 : gcc_assert (p != q);
3584 : #endif
3585 1445957581 : len++;
3586 : }
3587 :
3588 2147567434 : return len;
3589 : }
3590 :
3591 : /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3592 : UNION_TYPE TYPE, or NULL_TREE if none. */
3593 :
3594 : tree
3595 160547 : first_field (const_tree type)
3596 : {
3597 160547 : tree t = TYPE_FIELDS (type);
3598 4351997 : while (t && TREE_CODE (t) != FIELD_DECL)
3599 4191450 : t = TREE_CHAIN (t);
3600 160547 : return t;
3601 : }
3602 :
3603 : /* Returns the last FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3604 : UNION_TYPE TYPE, or NULL_TREE if none. */
3605 :
3606 : tree
3607 2838202 : last_field (const_tree type)
3608 : {
3609 2838202 : tree last = NULL_TREE;
3610 :
3611 66337694 : for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
3612 : {
3613 63499492 : if (TREE_CODE (fld) != FIELD_DECL)
3614 54956266 : continue;
3615 :
3616 : last = fld;
3617 : }
3618 :
3619 2838202 : return last;
3620 : }
3621 :
3622 : /* Concatenate two chains of nodes (chained through TREE_CHAIN)
3623 : by modifying the last node in chain 1 to point to chain 2.
3624 : This is the Lisp primitive `nconc'. */
3625 :
3626 : tree
3627 4201591509 : chainon (tree op1, tree op2)
3628 : {
3629 4201591509 : tree t1;
3630 :
3631 4201591509 : if (!op1)
3632 : return op2;
3633 784087462 : if (!op2)
3634 : return op1;
3635 :
3636 1615251280 : for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
3637 910417718 : continue;
3638 704833562 : TREE_CHAIN (t1) = op2;
3639 :
3640 : #ifdef ENABLE_TREE_CHECKING
3641 704833562 : {
3642 704833562 : tree t2;
3643 1795585586 : for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
3644 1090752024 : gcc_assert (t2 != t1);
3645 : }
3646 : #endif
3647 :
3648 : return op1;
3649 910417718 : }
3650 :
3651 : /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
3652 :
3653 : tree
3654 106400623 : tree_last (tree chain)
3655 : {
3656 106400623 : tree next;
3657 106400623 : if (chain)
3658 194712761 : while ((next = TREE_CHAIN (chain)))
3659 : chain = next;
3660 106400623 : return chain;
3661 : }
3662 :
3663 : /* Reverse the order of elements in the chain T,
3664 : and return the new head of the chain (old last element). */
3665 :
3666 : tree
3667 1597927498 : nreverse (tree t)
3668 : {
3669 1597927498 : tree prev = 0, decl, next;
3670 4034945682 : for (decl = t; decl; decl = next)
3671 : {
3672 : /* We shouldn't be using this function to reverse BLOCK chains; we
3673 : have blocks_nreverse for that. */
3674 2437018184 : gcc_checking_assert (TREE_CODE (decl) != BLOCK);
3675 2437018184 : next = TREE_CHAIN (decl);
3676 2437018184 : TREE_CHAIN (decl) = prev;
3677 2437018184 : prev = decl;
3678 : }
3679 1597927498 : return prev;
3680 : }
3681 :
3682 : /* Return a newly created TREE_LIST node whose
3683 : purpose and value fields are PARM and VALUE. */
3684 :
3685 : tree
3686 1482022443 : build_tree_list (tree parm, tree value MEM_STAT_DECL)
3687 : {
3688 1482022443 : tree t = make_node (TREE_LIST PASS_MEM_STAT);
3689 1482022443 : TREE_PURPOSE (t) = parm;
3690 1482022443 : TREE_VALUE (t) = value;
3691 1482022443 : return t;
3692 : }
3693 :
3694 : /* Build a chain of TREE_LIST nodes from a vector. */
3695 :
3696 : tree
3697 93449185 : build_tree_list_vec (const vec<tree, va_gc> *vec MEM_STAT_DECL)
3698 : {
3699 93449185 : tree ret = NULL_TREE;
3700 93449185 : tree *pp = &ret;
3701 93449185 : unsigned int i;
3702 93449185 : tree t;
3703 196215523 : FOR_EACH_VEC_SAFE_ELT (vec, i, t)
3704 : {
3705 102766338 : *pp = build_tree_list (NULL, t PASS_MEM_STAT);
3706 102766338 : pp = &TREE_CHAIN (*pp);
3707 : }
3708 93449185 : return ret;
3709 : }
3710 :
3711 : /* Return a newly created TREE_LIST node whose
3712 : purpose and value fields are PURPOSE and VALUE
3713 : and whose TREE_CHAIN is CHAIN. */
3714 :
3715 : tree
3716 5648869889 : tree_cons (tree purpose, tree value, tree chain MEM_STAT_DECL)
3717 : {
3718 5648869889 : tree node;
3719 :
3720 5648869889 : node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT);
3721 5648869889 : memset (node, 0, sizeof (struct tree_common));
3722 :
3723 5648869889 : record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
3724 :
3725 5648869889 : TREE_SET_CODE (node, TREE_LIST);
3726 5648869889 : TREE_CHAIN (node) = chain;
3727 5648869889 : TREE_PURPOSE (node) = purpose;
3728 5648869889 : TREE_VALUE (node) = value;
3729 5648869889 : return node;
3730 : }
3731 :
3732 : /* Return the values of the elements of a CONSTRUCTOR as a vector of
3733 : trees. */
3734 :
3735 : vec<tree, va_gc> *
3736 0 : ctor_to_vec (tree ctor)
3737 : {
3738 0 : vec<tree, va_gc> *vec;
3739 0 : vec_alloc (vec, CONSTRUCTOR_NELTS (ctor));
3740 0 : unsigned int ix;
3741 0 : tree val;
3742 :
3743 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
3744 0 : vec->quick_push (val);
3745 :
3746 0 : return vec;
3747 : }
3748 :
3749 : /* Return the size nominally occupied by an object of type TYPE
3750 : when it resides in memory. The value is measured in units of bytes,
3751 : and its data type is that normally used for type sizes
3752 : (which is the first type created by make_signed_type or
3753 : make_unsigned_type). */
3754 :
3755 : tree
3756 29087976 : size_in_bytes_loc (location_t loc, const_tree type)
3757 : {
3758 29087976 : tree t;
3759 :
3760 29087976 : if (type == error_mark_node)
3761 0 : return integer_zero_node;
3762 :
3763 29087976 : type = TYPE_MAIN_VARIANT (type);
3764 29087976 : t = TYPE_SIZE_UNIT (type);
3765 :
3766 29087976 : if (t == 0)
3767 : {
3768 65 : lang_hooks.types.incomplete_type_error (loc, NULL_TREE, type);
3769 65 : return size_zero_node;
3770 : }
3771 :
3772 : return t;
3773 : }
3774 :
3775 : /* Return the size of TYPE (in bytes) as a wide integer
3776 : or return -1 if the size can vary or is larger than an integer. */
3777 :
3778 : HOST_WIDE_INT
3779 532783873 : int_size_in_bytes (const_tree type)
3780 : {
3781 532783873 : tree t;
3782 :
3783 532783873 : if (type == error_mark_node)
3784 : return 0;
3785 :
3786 532783873 : type = TYPE_MAIN_VARIANT (type);
3787 532783873 : t = TYPE_SIZE_UNIT (type);
3788 :
3789 532783873 : if (t && tree_fits_uhwi_p (t))
3790 532730399 : return TREE_INT_CST_LOW (t);
3791 : else
3792 : return -1;
3793 : }
3794 :
3795 : /* Return the maximum size of TYPE (in bytes) as a wide integer
3796 : or return -1 if the size can vary or is larger than an integer. */
3797 :
3798 : HOST_WIDE_INT
3799 9223 : max_int_size_in_bytes (const_tree type)
3800 : {
3801 9223 : HOST_WIDE_INT size = -1;
3802 9223 : tree size_tree;
3803 :
3804 : /* If this is an array type, check for a possible MAX_SIZE attached. */
3805 :
3806 9223 : if (TREE_CODE (type) == ARRAY_TYPE)
3807 : {
3808 8490 : size_tree = TYPE_ARRAY_MAX_SIZE (type);
3809 :
3810 8490 : if (size_tree && tree_fits_uhwi_p (size_tree))
3811 0 : size = tree_to_uhwi (size_tree);
3812 : }
3813 :
3814 : /* If we still haven't been able to get a size, see if the language
3815 : can compute a maximum size. */
3816 :
3817 0 : if (size == -1)
3818 : {
3819 9223 : size_tree = lang_hooks.types.max_size (type);
3820 :
3821 9223 : if (size_tree && tree_fits_uhwi_p (size_tree))
3822 0 : size = tree_to_uhwi (size_tree);
3823 : }
3824 :
3825 9223 : return size;
3826 : }
3827 :
3828 : /* Return the bit position of FIELD, in bits from the start of the record.
3829 : This is a tree of type bitsizetype. */
3830 :
3831 : tree
3832 147703323 : bit_position (const_tree field)
3833 : {
3834 147703323 : return bit_from_pos (DECL_FIELD_OFFSET (field),
3835 147703323 : DECL_FIELD_BIT_OFFSET (field));
3836 : }
3837 :
3838 : /* Return the byte position of FIELD, in bytes from the start of the record.
3839 : This is a tree of type sizetype. */
3840 :
3841 : tree
3842 121109267 : byte_position (const_tree field)
3843 : {
3844 121109267 : return byte_from_pos (DECL_FIELD_OFFSET (field),
3845 121109267 : DECL_FIELD_BIT_OFFSET (field));
3846 : }
3847 :
3848 : /* Likewise, but return as an integer. It must be representable in
3849 : that way (since it could be a signed value, we don't have the
3850 : option of returning -1 like int_size_in_byte can. */
3851 :
3852 : HOST_WIDE_INT
3853 10119816 : int_byte_position (const_tree field)
3854 : {
3855 10119816 : return tree_to_shwi (byte_position (field));
3856 : }
3857 :
3858 : /* Return, as a tree node, the number of elements for TYPE (which is an
3859 : ARRAY_TYPE) minus one. This counts only elements of the top array. */
3860 :
3861 : tree
3862 114816269 : array_type_nelts_minus_one (const_tree type)
3863 : {
3864 114816269 : tree index_type, min, max;
3865 :
3866 : /* If they did it with unspecified bounds, then we should have already
3867 : given an error about it before we got here. */
3868 114816269 : if (! TYPE_DOMAIN (type))
3869 10204419 : return error_mark_node;
3870 :
3871 104611850 : index_type = TYPE_DOMAIN (type);
3872 104611850 : min = TYPE_MIN_VALUE (index_type);
3873 104611850 : max = TYPE_MAX_VALUE (index_type);
3874 :
3875 : /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3876 104611850 : if (!max)
3877 : {
3878 : /* zero sized arrays are represented from C FE as complete types with
3879 : NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
3880 : them as min 0, max -1. */
3881 1281612 : if (COMPLETE_TYPE_P (type)
3882 3145 : && integer_zerop (TYPE_SIZE (type))
3883 1284757 : && integer_zerop (min))
3884 3145 : return build_int_cst (TREE_TYPE (min), -1);
3885 :
3886 1278467 : return error_mark_node;
3887 : }
3888 :
3889 103330238 : return (integer_zerop (min)
3890 103330238 : ? max
3891 1159554 : : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
3892 : }
3893 :
3894 : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3895 : (which is an ARRAY_TYPE). This counts only elements of the top
3896 : array. */
3897 :
3898 : tree
3899 24859190 : array_type_nelts_top (tree type)
3900 : {
3901 24859190 : return fold_build2_loc (input_location,
3902 : PLUS_EXPR, sizetype,
3903 : array_type_nelts_minus_one (type),
3904 24859190 : size_one_node);
3905 : }
3906 :
3907 : /* If arg is static -- a reference to an object in static storage -- then
3908 : return the object. This is not the same as the C meaning of `static'.
3909 : If arg isn't static, return NULL. */
3910 :
3911 : tree
3912 1230784078 : staticp (tree arg)
3913 : {
3914 1231855999 : switch (TREE_CODE (arg))
3915 : {
3916 : case FUNCTION_DECL:
3917 : /* Nested functions are static, even though taking their address will
3918 : involve a trampoline as we unnest the nested function and create
3919 : the trampoline on the tree level. */
3920 : return arg;
3921 :
3922 741268992 : case VAR_DECL:
3923 586497624 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3924 200320828 : && ! DECL_THREAD_LOCAL_P (arg)
3925 198459713 : && ! DECL_DLLIMPORT_P (arg)
3926 741268992 : ? arg : NULL);
3927 :
3928 702645 : case CONST_DECL:
3929 44 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3930 702645 : ? arg : NULL);
3931 :
3932 0 : case CONSTRUCTOR:
3933 0 : return TREE_STATIC (arg) ? arg : NULL;
3934 :
3935 : case LABEL_DECL:
3936 : case STRING_CST:
3937 : return arg;
3938 :
3939 819303 : case COMPONENT_REF:
3940 : /* If the thing being referenced is not a field, then it is
3941 : something language specific. */
3942 819303 : gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
3943 :
3944 : /* If we are referencing a bitfield, we can't evaluate an
3945 : ADDR_EXPR at compile time and so it isn't a constant. */
3946 819303 : if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
3947 : return NULL;
3948 :
3949 819303 : return staticp (TREE_OPERAND (arg, 0));
3950 :
3951 : case BIT_FIELD_REF:
3952 : return NULL;
3953 :
3954 35314 : case INDIRECT_REF:
3955 35314 : return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
3956 :
3957 252524 : case ARRAY_REF:
3958 252524 : case ARRAY_RANGE_REF:
3959 252524 : if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
3960 252524 : && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
3961 252180 : return staticp (TREE_OPERAND (arg, 0));
3962 : else
3963 : return NULL;
3964 :
3965 438 : case REALPART_EXPR:
3966 438 : case IMAGPART_EXPR:
3967 438 : return staticp (TREE_OPERAND (arg, 0));
3968 :
3969 934 : case COMPOUND_LITERAL_EXPR:
3970 934 : return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
3971 :
3972 : default:
3973 : return NULL;
3974 : }
3975 : }
3976 :
3977 :
3978 :
3979 :
3980 : /* Return whether OP is a DECL whose address is function-invariant. */
3981 :
3982 : bool
3983 5360782744 : decl_address_invariant_p (const_tree op)
3984 : {
3985 : /* The conditions below are slightly less strict than the one in
3986 : staticp. */
3987 :
3988 5360782744 : switch (TREE_CODE (op))
3989 : {
3990 : case PARM_DECL:
3991 : case RESULT_DECL:
3992 : case LABEL_DECL:
3993 : case FUNCTION_DECL:
3994 : return true;
3995 :
3996 2956425657 : case VAR_DECL:
3997 2251369536 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3998 2115315148 : || DECL_THREAD_LOCAL_P (op)
3999 2115315148 : || DECL_CONTEXT (op) == current_function_decl
4000 2964362625 : || decl_function_context (op) == current_function_decl)
4001 : return true;
4002 : break;
4003 :
4004 25937046 : case CONST_DECL:
4005 0 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
4006 25937046 : || decl_function_context (op) == current_function_decl)
4007 : return true;
4008 : break;
4009 :
4010 : default:
4011 : break;
4012 : }
4013 :
4014 : return false;
4015 : }
4016 :
4017 : /* Return whether OP is a DECL whose address is interprocedural-invariant. */
4018 :
4019 : bool
4020 1852561 : decl_address_ip_invariant_p (const_tree op)
4021 : {
4022 : /* The conditions below are slightly less strict than the one in
4023 : staticp. */
4024 :
4025 1852561 : symtab_node* node;
4026 1852561 : switch (TREE_CODE (op))
4027 : {
4028 : case LABEL_DECL:
4029 : case STRING_CST:
4030 : return true;
4031 :
4032 91197 : case FUNCTION_DECL:
4033 : /* Disable const propagation of symbols defined in assembly. */
4034 91197 : node = symtab_node::get (op);
4035 91197 : return !node || !node->must_remain_in_tu_name;
4036 :
4037 1656412 : case VAR_DECL:
4038 1656412 : if (TREE_STATIC (op) || DECL_EXTERNAL (op))
4039 : {
4040 : /* Disable const propagation of symbols defined in assembly. */
4041 481127 : node = symtab_node::get (op);
4042 481127 : if (node && node->must_remain_in_tu_name)
4043 : return false;
4044 : }
4045 1215238 : if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
4046 481125 : && !DECL_DLLIMPORT_P (op))
4047 2831695 : || DECL_THREAD_LOCAL_P (op))
4048 : return true;
4049 : break;
4050 :
4051 53336 : case CONST_DECL:
4052 53336 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
4053 : return true;
4054 : break;
4055 :
4056 : default:
4057 : break;
4058 : }
4059 :
4060 : return false;
4061 : }
4062 :
4063 : /* Return true if T is an object with invariant address. */
4064 :
4065 : bool
4066 45940 : address_invariant_p (tree t)
4067 : {
4068 53884 : while (handled_component_p (t))
4069 : {
4070 8937 : switch (TREE_CODE (t))
4071 : {
4072 1473 : case ARRAY_REF:
4073 1473 : case ARRAY_RANGE_REF:
4074 1473 : if (!tree_invariant_p (TREE_OPERAND (t, 1))
4075 480 : || TREE_OPERAND (t, 2) != NULL_TREE
4076 1953 : || TREE_OPERAND (t, 3) != NULL_TREE)
4077 : return false;
4078 : break;
4079 :
4080 7305 : case COMPONENT_REF:
4081 7305 : if (TREE_OPERAND (t, 2) != NULL_TREE)
4082 : return false;
4083 : break;
4084 :
4085 : default:
4086 : break;
4087 : }
4088 7944 : t = TREE_OPERAND (t, 0);
4089 : }
4090 :
4091 44947 : STRIP_ANY_LOCATION_WRAPPER (t);
4092 44947 : return CONSTANT_CLASS_P (t) || decl_address_invariant_p (t);
4093 : }
4094 :
4095 :
4096 : /* Return true if T is function-invariant (internal function, does
4097 : not handle arithmetic; that's handled in skip_simple_arithmetic and
4098 : tree_invariant_p). */
4099 :
4100 : static bool
4101 16118868 : tree_invariant_p_1 (tree t)
4102 : {
4103 16118868 : if (TREE_CONSTANT (t) || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
4104 : return true;
4105 :
4106 13483331 : switch (TREE_CODE (t))
4107 : {
4108 : case SAVE_EXPR:
4109 : case TARGET_EXPR:
4110 : return true;
4111 :
4112 45888 : case ADDR_EXPR:
4113 45888 : return address_invariant_p (TREE_OPERAND (t, 0));
4114 :
4115 : default:
4116 : break;
4117 : }
4118 :
4119 : return false;
4120 : }
4121 :
4122 : /* Return true if T is function-invariant. */
4123 :
4124 : bool
4125 12637634 : tree_invariant_p (tree t)
4126 : {
4127 12637634 : tree inner = skip_simple_arithmetic (t);
4128 12637634 : return tree_invariant_p_1 (inner);
4129 : }
4130 :
4131 : /* Wrap a SAVE_EXPR around EXPR, if appropriate.
4132 : Do this to any expression which may be used in more than one place,
4133 : but must be evaluated only once.
4134 :
4135 : Normally, expand_expr would reevaluate the expression each time.
4136 : Calling save_expr produces something that is evaluated and recorded
4137 : the first time expand_expr is called on it. Subsequent calls to
4138 : expand_expr just reuse the recorded value.
4139 :
4140 : The call to expand_expr that generates code that actually computes
4141 : the value is the first call *at compile time*. Subsequent calls
4142 : *at compile time* generate code to use the saved value.
4143 : This produces correct result provided that *at run time* control
4144 : always flows through the insns made by the first expand_expr
4145 : before reaching the other places where the save_expr was evaluated.
4146 : You, the caller of save_expr, must make sure this is so.
4147 :
4148 : Constants, and certain read-only nodes, are returned with no
4149 : SAVE_EXPR because that is safe. Expressions containing placeholders
4150 : are not touched; see tree.def for an explanation of what these
4151 : are used for. */
4152 :
4153 : tree
4154 3481245 : save_expr (tree expr)
4155 : {
4156 3481245 : tree inner;
4157 :
4158 : /* If the tree evaluates to a constant, then we don't want to hide that
4159 : fact (i.e. this allows further folding, and direct checks for constants).
4160 : However, a read-only object that has side effects cannot be bypassed.
4161 : Since it is no problem to reevaluate literals, we just return the
4162 : literal node. */
4163 3481245 : inner = skip_simple_arithmetic (expr);
4164 3481245 : if (TREE_CODE (inner) == ERROR_MARK)
4165 : return inner;
4166 :
4167 3481234 : if (tree_invariant_p_1 (inner))
4168 : return expr;
4169 :
4170 : /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
4171 : it means that the size or offset of some field of an object depends on
4172 : the value within another field.
4173 :
4174 : Note that it must not be the case that EXPR contains both a PLACEHOLDER_EXPR
4175 : and some variable since it would then need to be both evaluated once and
4176 : evaluated more than once. Front-ends must assure this case cannot
4177 : happen by surrounding any such subexpressions in their own SAVE_EXPR
4178 : and forcing evaluation at the proper time. */
4179 2429008 : if (contains_placeholder_p (inner))
4180 : return expr;
4181 :
4182 2429008 : expr = build1_loc (EXPR_LOCATION (expr), SAVE_EXPR, TREE_TYPE (expr), expr);
4183 :
4184 : /* This expression might be placed ahead of a jump to ensure that the
4185 : value was computed on both sides of the jump. So make sure it isn't
4186 : eliminated as dead. */
4187 2429008 : TREE_SIDE_EFFECTS (expr) = 1;
4188 2429008 : return expr;
4189 : }
4190 :
4191 : /* Look inside EXPR into any simple arithmetic operations. Return the
4192 : outermost non-arithmetic or non-invariant node. */
4193 :
4194 : tree
4195 16118879 : skip_simple_arithmetic (tree expr)
4196 : {
4197 : /* We don't care about whether this can be used as an lvalue in this
4198 : context. */
4199 16134590 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4200 15711 : expr = TREE_OPERAND (expr, 0);
4201 :
4202 : /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
4203 : a constant, it will be more efficient to not make another SAVE_EXPR since
4204 : it will allow better simplification and GCSE will be able to merge the
4205 : computations if they actually occur. */
4206 40573291 : while (true)
4207 : {
4208 40573291 : if (UNARY_CLASS_P (expr))
4209 15288985 : expr = TREE_OPERAND (expr, 0);
4210 25284306 : else if (BINARY_CLASS_P (expr))
4211 : {
4212 : /* Before commutative binary operands are canonicalized,
4213 : it is quite common to have constants in the first operand.
4214 : Check for that common case first so that we don't walk
4215 : large expressions with tree_invariant_p unnecessarily.
4216 : This can still have terrible compile time complexity,
4217 : we should limit the depth of the tree_invariant_p and
4218 : skip_simple_arithmetic recursion. */
4219 9219472 : if ((TREE_CONSTANT (TREE_OPERAND (expr, 0))
4220 9209124 : || (TREE_READONLY (TREE_OPERAND (expr, 0))
4221 10130 : && !TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0))))
4222 9229566 : && tree_invariant_p (TREE_OPERAND (expr, 0)))
4223 20442 : expr = TREE_OPERAND (expr, 1);
4224 9199030 : else if (tree_invariant_p (TREE_OPERAND (expr, 1)))
4225 9135205 : expr = TREE_OPERAND (expr, 0);
4226 63825 : else if (tree_invariant_p (TREE_OPERAND (expr, 0)))
4227 9780 : expr = TREE_OPERAND (expr, 1);
4228 : else
4229 : break;
4230 : }
4231 : else
4232 : break;
4233 : }
4234 :
4235 16118879 : return expr;
4236 : }
4237 :
4238 : /* Look inside EXPR into simple arithmetic operations involving constants.
4239 : Return the outermost non-arithmetic or non-constant node. */
4240 :
4241 : tree
4242 0 : skip_simple_constant_arithmetic (tree expr)
4243 : {
4244 0 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4245 0 : expr = TREE_OPERAND (expr, 0);
4246 :
4247 0 : while (true)
4248 : {
4249 0 : if (UNARY_CLASS_P (expr))
4250 0 : expr = TREE_OPERAND (expr, 0);
4251 0 : else if (BINARY_CLASS_P (expr))
4252 : {
4253 0 : if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
4254 0 : expr = TREE_OPERAND (expr, 0);
4255 0 : else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
4256 0 : expr = TREE_OPERAND (expr, 1);
4257 : else
4258 : break;
4259 : }
4260 : else
4261 : break;
4262 : }
4263 :
4264 0 : return expr;
4265 : }
4266 :
4267 : /* Return which tree structure is used by T. */
4268 :
4269 : enum tree_node_structure_enum
4270 44512199016 : tree_node_structure (const_tree t)
4271 : {
4272 44512199016 : const enum tree_code code = TREE_CODE (t);
4273 44512199016 : return tree_node_structure_for_code (code);
4274 : }
4275 :
4276 : /* Set various status flags when building a CALL_EXPR object T. */
4277 :
4278 : static void
4279 295000911 : process_call_operands (tree t)
4280 : {
4281 295000911 : bool side_effects = TREE_SIDE_EFFECTS (t);
4282 295000911 : bool read_only = false;
4283 295000911 : int i = call_expr_flags (t);
4284 :
4285 : /* Calls have side-effects, except those to const or pure functions. */
4286 295000911 : if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
4287 : side_effects = true;
4288 : /* Propagate TREE_READONLY of arguments for const functions. */
4289 61517742 : if (i & ECF_CONST)
4290 59899451 : read_only = true;
4291 :
4292 295000911 : if (!side_effects || read_only)
4293 307443022 : for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
4294 : {
4295 245925784 : tree op = TREE_OPERAND (t, i);
4296 245925784 : if (op && TREE_SIDE_EFFECTS (op))
4297 : side_effects = true;
4298 245925784 : if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
4299 : read_only = false;
4300 : }
4301 :
4302 295000911 : TREE_SIDE_EFFECTS (t) = side_effects;
4303 295000911 : TREE_READONLY (t) = read_only;
4304 295000911 : }
4305 :
4306 : /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
4307 : size or offset that depends on a field within a record. */
4308 :
4309 : bool
4310 38930562 : contains_placeholder_p (const_tree exp)
4311 : {
4312 38930562 : enum tree_code code;
4313 :
4314 38930562 : if (!exp)
4315 : return false;
4316 :
4317 38930562 : code = TREE_CODE (exp);
4318 38930562 : if (code == PLACEHOLDER_EXPR)
4319 : return true;
4320 :
4321 38930562 : switch (TREE_CODE_CLASS (code))
4322 : {
4323 1179209 : case tcc_reference:
4324 : /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
4325 : position computations since they will be converted into a
4326 : WITH_RECORD_EXPR involving the reference, which will assume
4327 : here will be valid. */
4328 1179209 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4329 :
4330 586398 : case tcc_exceptional:
4331 586398 : if (code == TREE_LIST)
4332 0 : return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
4333 0 : || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
4334 : break;
4335 :
4336 33770553 : case tcc_unary:
4337 33770553 : case tcc_binary:
4338 33770553 : case tcc_comparison:
4339 33770553 : case tcc_expression:
4340 33770553 : switch (code)
4341 : {
4342 7287 : case COMPOUND_EXPR:
4343 : /* Ignoring the first operand isn't quite right, but works best. */
4344 7287 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
4345 :
4346 4531 : case COND_EXPR:
4347 9062 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4348 4531 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
4349 9062 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
4350 :
4351 : case SAVE_EXPR:
4352 : /* The save_expr function never wraps anything containing
4353 : a PLACEHOLDER_EXPR. */
4354 : return false;
4355 :
4356 24585841 : default:
4357 24585841 : break;
4358 : }
4359 :
4360 24585841 : switch (TREE_CODE_LENGTH (code))
4361 : {
4362 14979240 : case 1:
4363 14979240 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4364 9508691 : case 2:
4365 19015841 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4366 19015841 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
4367 : default:
4368 : return false;
4369 : }
4370 :
4371 816512 : case tcc_vl_exp:
4372 816512 : switch (code)
4373 : {
4374 816512 : case CALL_EXPR:
4375 816512 : {
4376 816512 : const_tree arg;
4377 816512 : const_call_expr_arg_iterator iter;
4378 2841451 : FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
4379 1208427 : if (CONTAINS_PLACEHOLDER_P (arg))
4380 : return true;
4381 : return false;
4382 : }
4383 : default:
4384 : return false;
4385 : }
4386 :
4387 : default:
4388 : return false;
4389 : }
4390 : return false;
4391 : }
4392 :
4393 : /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
4394 : directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
4395 : field positions. */
4396 :
4397 : static bool
4398 812059 : type_contains_placeholder_1 (const_tree type)
4399 : {
4400 : /* If the size contains a placeholder or the parent type (component type in
4401 : the case of arrays) type involves a placeholder, this type does. */
4402 1602857 : if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
4403 812059 : || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
4404 1624118 : || (!POINTER_TYPE_P (type)
4405 672903 : && TREE_TYPE (type)
4406 116798 : && type_contains_placeholder_p (TREE_TYPE (type))))
4407 : return true;
4408 :
4409 : /* Now do type-specific checks. Note that the last part of the check above
4410 : greatly limits what we have to do below. */
4411 812059 : switch (TREE_CODE (type))
4412 : {
4413 : case VOID_TYPE:
4414 : case OPAQUE_TYPE:
4415 : case COMPLEX_TYPE:
4416 : case ENUMERAL_TYPE:
4417 : case BOOLEAN_TYPE:
4418 : case POINTER_TYPE:
4419 : case OFFSET_TYPE:
4420 : case REFERENCE_TYPE:
4421 : case METHOD_TYPE:
4422 : case FUNCTION_TYPE:
4423 : case VECTOR_TYPE:
4424 : case NULLPTR_TYPE:
4425 : return false;
4426 :
4427 182309 : case INTEGER_TYPE:
4428 182309 : case BITINT_TYPE:
4429 182309 : case REAL_TYPE:
4430 182309 : case FIXED_POINT_TYPE:
4431 : /* Here we just check the bounds. */
4432 354834 : return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
4433 354834 : || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
4434 :
4435 58172 : case ARRAY_TYPE:
4436 : /* We have already checked the component type above, so just check
4437 : the domain type. Flexible array members have a null domain. */
4438 116332 : return TYPE_DOMAIN (type) ?
4439 58160 : type_contains_placeholder_p (TYPE_DOMAIN (type)) : false;
4440 :
4441 407938 : case RECORD_TYPE:
4442 407938 : case UNION_TYPE:
4443 407938 : case QUAL_UNION_TYPE:
4444 407938 : {
4445 407938 : tree field;
4446 :
4447 11983955 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4448 11576017 : if (TREE_CODE (field) == FIELD_DECL
4449 11576017 : && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
4450 950124 : || (TREE_CODE (type) == QUAL_UNION_TYPE
4451 0 : && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
4452 950124 : || type_contains_placeholder_p (TREE_TYPE (field))))
4453 : return true;
4454 :
4455 : return false;
4456 : }
4457 :
4458 0 : default:
4459 0 : gcc_unreachable ();
4460 : }
4461 : }
4462 :
4463 : /* Wrapper around above function used to cache its result. */
4464 :
4465 : bool
4466 3011288 : type_contains_placeholder_p (tree type)
4467 : {
4468 3011288 : bool result;
4469 :
4470 : /* If the contains_placeholder_bits field has been initialized,
4471 : then we know the answer. */
4472 3011288 : if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
4473 2199229 : return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
4474 :
4475 : /* Indicate that we've seen this type node, and the answer is false.
4476 : This is what we want to return if we run into recursion via fields. */
4477 812059 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
4478 :
4479 : /* Compute the real value. */
4480 812059 : result = type_contains_placeholder_1 (type);
4481 :
4482 : /* Store the real value. */
4483 812059 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
4484 :
4485 812059 : return result;
4486 : }
4487 :
4488 : /* Push tree EXP onto vector QUEUE if it is not already present. */
4489 :
4490 : static void
4491 0 : push_without_duplicates (tree exp, vec<tree> *queue)
4492 : {
4493 0 : unsigned int i;
4494 0 : tree iter;
4495 :
4496 0 : FOR_EACH_VEC_ELT (*queue, i, iter)
4497 0 : if (simple_cst_equal (iter, exp) == 1)
4498 : break;
4499 :
4500 0 : if (!iter)
4501 0 : queue->safe_push (exp);
4502 0 : }
4503 :
4504 : /* Given a tree EXP, find all occurrences of references to fields
4505 : in a PLACEHOLDER_EXPR and place them in vector REFS without
4506 : duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
4507 : we assume here that EXP contains only arithmetic expressions
4508 : or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
4509 : argument list. */
4510 :
4511 : void
4512 0 : find_placeholder_in_expr (tree exp, vec<tree> *refs)
4513 : {
4514 0 : enum tree_code code = TREE_CODE (exp);
4515 0 : tree inner;
4516 0 : int i;
4517 :
4518 : /* We handle TREE_LIST and COMPONENT_REF separately. */
4519 0 : if (code == TREE_LIST)
4520 : {
4521 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
4522 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
4523 : }
4524 0 : else if (code == COMPONENT_REF)
4525 : {
4526 0 : for (inner = TREE_OPERAND (exp, 0);
4527 0 : REFERENCE_CLASS_P (inner);
4528 0 : inner = TREE_OPERAND (inner, 0))
4529 : ;
4530 :
4531 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
4532 0 : push_without_duplicates (exp, refs);
4533 : else
4534 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
4535 : }
4536 : else
4537 0 : switch (TREE_CODE_CLASS (code))
4538 : {
4539 : case tcc_constant:
4540 : break;
4541 :
4542 0 : case tcc_declaration:
4543 : /* Variables allocated to static storage can stay. */
4544 0 : if (!TREE_STATIC (exp))
4545 0 : push_without_duplicates (exp, refs);
4546 : break;
4547 :
4548 0 : case tcc_expression:
4549 : /* This is the pattern built in ada/make_aligning_type. */
4550 0 : if (code == ADDR_EXPR
4551 0 : && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
4552 : {
4553 0 : push_without_duplicates (exp, refs);
4554 0 : break;
4555 : }
4556 :
4557 : /* Fall through. */
4558 :
4559 : case tcc_exceptional:
4560 : case tcc_unary:
4561 : case tcc_binary:
4562 : case tcc_comparison:
4563 : case tcc_reference:
4564 0 : for (i = 0; i < TREE_CODE_LENGTH (code); i++)
4565 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4566 : break;
4567 :
4568 : case tcc_vl_exp:
4569 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4570 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4571 : break;
4572 :
4573 0 : default:
4574 0 : gcc_unreachable ();
4575 : }
4576 0 : }
4577 :
4578 : /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
4579 : return a tree with all occurrences of references to F in a
4580 : PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
4581 : CONST_DECLs. Note that we assume here that EXP contains only
4582 : arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
4583 : occurring only in their argument list. */
4584 :
4585 : tree
4586 0 : substitute_in_expr (tree exp, tree f, tree r)
4587 : {
4588 0 : enum tree_code code = TREE_CODE (exp);
4589 0 : tree op0, op1, op2, op3;
4590 0 : tree new_tree;
4591 :
4592 : /* We handle TREE_LIST and COMPONENT_REF separately. */
4593 0 : if (code == TREE_LIST)
4594 : {
4595 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
4596 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
4597 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4598 : return exp;
4599 :
4600 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4601 : }
4602 0 : else if (code == COMPONENT_REF)
4603 : {
4604 0 : tree inner;
4605 :
4606 : /* If this expression is getting a value from a PLACEHOLDER_EXPR
4607 : and it is the right field, replace it with R. */
4608 0 : for (inner = TREE_OPERAND (exp, 0);
4609 0 : REFERENCE_CLASS_P (inner);
4610 0 : inner = TREE_OPERAND (inner, 0))
4611 : ;
4612 :
4613 : /* The field. */
4614 0 : op1 = TREE_OPERAND (exp, 1);
4615 :
4616 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
4617 : return r;
4618 :
4619 : /* If this expression hasn't been completed let, leave it alone. */
4620 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
4621 : return exp;
4622 :
4623 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4624 0 : if (op0 == TREE_OPERAND (exp, 0))
4625 : return exp;
4626 :
4627 0 : new_tree
4628 0 : = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
4629 : }
4630 : else
4631 0 : switch (TREE_CODE_CLASS (code))
4632 : {
4633 : case tcc_constant:
4634 : return exp;
4635 :
4636 0 : case tcc_declaration:
4637 0 : if (exp == f)
4638 : return r;
4639 : else
4640 0 : return exp;
4641 :
4642 0 : case tcc_expression:
4643 0 : if (exp == f)
4644 : return r;
4645 :
4646 : /* Fall through. */
4647 :
4648 0 : case tcc_exceptional:
4649 0 : case tcc_unary:
4650 0 : case tcc_binary:
4651 0 : case tcc_comparison:
4652 0 : case tcc_reference:
4653 0 : switch (TREE_CODE_LENGTH (code))
4654 : {
4655 : case 0:
4656 : return exp;
4657 :
4658 0 : case 1:
4659 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4660 0 : if (op0 == TREE_OPERAND (exp, 0))
4661 : return exp;
4662 :
4663 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4664 0 : break;
4665 :
4666 0 : case 2:
4667 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4668 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4669 :
4670 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4671 : return exp;
4672 :
4673 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4674 0 : break;
4675 :
4676 0 : case 3:
4677 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4678 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4679 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4680 :
4681 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4682 0 : && op2 == TREE_OPERAND (exp, 2))
4683 : return exp;
4684 :
4685 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4686 0 : break;
4687 :
4688 0 : case 4:
4689 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4690 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4691 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4692 0 : op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
4693 :
4694 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4695 0 : && op2 == TREE_OPERAND (exp, 2)
4696 0 : && op3 == TREE_OPERAND (exp, 3))
4697 : return exp;
4698 :
4699 0 : new_tree
4700 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4701 0 : break;
4702 :
4703 0 : default:
4704 0 : gcc_unreachable ();
4705 : }
4706 : break;
4707 :
4708 0 : case tcc_vl_exp:
4709 0 : {
4710 0 : int i;
4711 :
4712 0 : new_tree = NULL_TREE;
4713 :
4714 : /* If we are trying to replace F with a constant or with another
4715 : instance of one of the arguments of the call, inline back
4716 : functions which do nothing else than computing a value from
4717 : the arguments they are passed. This makes it possible to
4718 : fold partially or entirely the replacement expression. */
4719 0 : if (code == CALL_EXPR)
4720 : {
4721 0 : bool maybe_inline = false;
4722 0 : if (CONSTANT_CLASS_P (r))
4723 : maybe_inline = true;
4724 : else
4725 0 : for (i = 3; i < TREE_OPERAND_LENGTH (exp); i++)
4726 0 : if (operand_equal_p (TREE_OPERAND (exp, i), r, 0))
4727 : {
4728 : maybe_inline = true;
4729 : break;
4730 : }
4731 0 : if (maybe_inline)
4732 : {
4733 0 : tree t = maybe_inline_call_in_expr (exp);
4734 0 : if (t)
4735 0 : return SUBSTITUTE_IN_EXPR (t, f, r);
4736 : }
4737 : }
4738 :
4739 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4740 : {
4741 0 : tree op = TREE_OPERAND (exp, i);
4742 0 : tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
4743 0 : if (new_op != op)
4744 : {
4745 0 : if (!new_tree)
4746 0 : new_tree = copy_node (exp);
4747 0 : TREE_OPERAND (new_tree, i) = new_op;
4748 : }
4749 : }
4750 :
4751 0 : if (new_tree)
4752 : {
4753 0 : new_tree = fold (new_tree);
4754 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4755 0 : process_call_operands (new_tree);
4756 : }
4757 : else
4758 : return exp;
4759 : }
4760 : break;
4761 :
4762 0 : default:
4763 0 : gcc_unreachable ();
4764 : }
4765 :
4766 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4767 :
4768 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4769 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4770 :
4771 : return new_tree;
4772 : }
4773 :
4774 : /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
4775 : for it within OBJ, a tree that is an object or a chain of references. */
4776 :
4777 : tree
4778 248477 : substitute_placeholder_in_expr (tree exp, tree obj)
4779 : {
4780 248477 : enum tree_code code = TREE_CODE (exp);
4781 248477 : tree op0, op1, op2, op3;
4782 248477 : tree new_tree;
4783 :
4784 : /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
4785 : in the chain of OBJ. */
4786 248477 : if (code == PLACEHOLDER_EXPR)
4787 : {
4788 0 : tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
4789 0 : tree elt;
4790 :
4791 0 : for (elt = obj; elt != 0;
4792 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4793 0 : || TREE_CODE (elt) == COND_EXPR)
4794 0 : ? TREE_OPERAND (elt, 1)
4795 0 : : (REFERENCE_CLASS_P (elt)
4796 : || UNARY_CLASS_P (elt)
4797 : || BINARY_CLASS_P (elt)
4798 : || VL_EXP_CLASS_P (elt)
4799 : || EXPRESSION_CLASS_P (elt))
4800 0 : ? TREE_OPERAND (elt, 0) : 0))
4801 0 : if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
4802 : return elt;
4803 :
4804 0 : for (elt = obj; elt != 0;
4805 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4806 0 : || TREE_CODE (elt) == COND_EXPR)
4807 0 : ? TREE_OPERAND (elt, 1)
4808 0 : : (REFERENCE_CLASS_P (elt)
4809 : || UNARY_CLASS_P (elt)
4810 : || BINARY_CLASS_P (elt)
4811 : || VL_EXP_CLASS_P (elt)
4812 : || EXPRESSION_CLASS_P (elt))
4813 0 : ? TREE_OPERAND (elt, 0) : 0))
4814 0 : if (POINTER_TYPE_P (TREE_TYPE (elt))
4815 0 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
4816 : == need_type))
4817 0 : return fold_build1 (INDIRECT_REF, need_type, elt);
4818 :
4819 : /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
4820 : survives until RTL generation, there will be an error. */
4821 : return exp;
4822 : }
4823 :
4824 : /* TREE_LIST is special because we need to look at TREE_VALUE
4825 : and TREE_CHAIN, not TREE_OPERANDS. */
4826 248477 : else if (code == TREE_LIST)
4827 : {
4828 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
4829 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
4830 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4831 : return exp;
4832 :
4833 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4834 : }
4835 : else
4836 248477 : switch (TREE_CODE_CLASS (code))
4837 : {
4838 : case tcc_constant:
4839 : case tcc_declaration:
4840 : return exp;
4841 :
4842 10069 : case tcc_exceptional:
4843 10069 : case tcc_unary:
4844 10069 : case tcc_binary:
4845 10069 : case tcc_comparison:
4846 10069 : case tcc_expression:
4847 10069 : case tcc_reference:
4848 10069 : case tcc_statement:
4849 10069 : switch (TREE_CODE_LENGTH (code))
4850 : {
4851 : case 0:
4852 : return exp;
4853 :
4854 7674 : case 1:
4855 7674 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4856 7674 : if (op0 == TREE_OPERAND (exp, 0))
4857 : return exp;
4858 :
4859 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4860 0 : break;
4861 :
4862 2383 : case 2:
4863 2383 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4864 2383 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4865 :
4866 2383 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4867 : return exp;
4868 :
4869 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4870 0 : break;
4871 :
4872 12 : case 3:
4873 12 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4874 12 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4875 12 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4876 :
4877 24 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4878 24 : && op2 == TREE_OPERAND (exp, 2))
4879 : return exp;
4880 :
4881 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4882 0 : break;
4883 :
4884 0 : case 4:
4885 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4886 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4887 0 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4888 0 : op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
4889 :
4890 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4891 0 : && op2 == TREE_OPERAND (exp, 2)
4892 0 : && op3 == TREE_OPERAND (exp, 3))
4893 : return exp;
4894 :
4895 0 : new_tree
4896 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4897 0 : break;
4898 :
4899 0 : default:
4900 0 : gcc_unreachable ();
4901 : }
4902 : break;
4903 :
4904 : case tcc_vl_exp:
4905 : {
4906 : int i;
4907 :
4908 : new_tree = NULL_TREE;
4909 :
4910 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4911 : {
4912 0 : tree op = TREE_OPERAND (exp, i);
4913 0 : tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
4914 0 : if (new_op != op)
4915 : {
4916 0 : if (!new_tree)
4917 0 : new_tree = copy_node (exp);
4918 0 : TREE_OPERAND (new_tree, i) = new_op;
4919 : }
4920 : }
4921 :
4922 0 : if (new_tree)
4923 : {
4924 0 : new_tree = fold (new_tree);
4925 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4926 0 : process_call_operands (new_tree);
4927 : }
4928 : else
4929 : return exp;
4930 : }
4931 : break;
4932 :
4933 0 : default:
4934 0 : gcc_unreachable ();
4935 : }
4936 :
4937 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4938 :
4939 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4940 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4941 :
4942 : return new_tree;
4943 : }
4944 :
4945 :
4946 : /* Subroutine of stabilize_reference; this is called for subtrees of
4947 : references. Any expression with side-effects must be put in a SAVE_EXPR
4948 : to ensure that it is only evaluated once.
4949 :
4950 : We don't put SAVE_EXPR nodes around everything, because assigning very
4951 : simple expressions to temporaries causes us to miss good opportunities
4952 : for optimizations. Among other things, the opportunity to fold in the
4953 : addition of a constant into an addressing mode often gets lost, e.g.
4954 : "y[i+1] += x;". In general, we take the approach that we should not make
4955 : an assignment unless we are forced into it - i.e., that any non-side effect
4956 : operator should be allowed, and that cse should take care of coalescing
4957 : multiple utterances of the same expression should that prove fruitful. */
4958 :
4959 : static tree
4960 910027 : stabilize_reference_1 (tree e)
4961 : {
4962 910027 : tree result;
4963 910027 : enum tree_code code = TREE_CODE (e);
4964 :
4965 : /* We cannot ignore const expressions because it might be a reference
4966 : to a const array but whose index contains side-effects. But we can
4967 : ignore things that are actual constant or that already have been
4968 : handled by this function. */
4969 :
4970 910027 : if (tree_invariant_p (e))
4971 : return e;
4972 :
4973 134733 : switch (TREE_CODE_CLASS (code))
4974 : {
4975 0 : case tcc_exceptional:
4976 : /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
4977 : have side-effects. */
4978 0 : if (code == STATEMENT_LIST)
4979 0 : return save_expr (e);
4980 : /* FALLTHRU */
4981 104973 : case tcc_type:
4982 104973 : case tcc_declaration:
4983 104973 : case tcc_comparison:
4984 104973 : case tcc_statement:
4985 104973 : case tcc_expression:
4986 104973 : case tcc_reference:
4987 104973 : case tcc_vl_exp:
4988 : /* If the expression has side-effects, then encase it in a SAVE_EXPR
4989 : so that it will only be evaluated once. */
4990 : /* The reference (r) and comparison (<) classes could be handled as
4991 : below, but it is generally faster to only evaluate them once. */
4992 104973 : if (TREE_SIDE_EFFECTS (e))
4993 998 : return save_expr (e);
4994 : return e;
4995 :
4996 : case tcc_constant:
4997 : /* Constants need no processing. In fact, we should never reach
4998 : here. */
4999 : return e;
5000 :
5001 22004 : case tcc_binary:
5002 : /* Division is slow and tends to be compiled with jumps,
5003 : especially the division by powers of 2 that is often
5004 : found inside of an array reference. So do it just once. */
5005 22004 : if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
5006 19964 : || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
5007 19964 : || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
5008 19964 : || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
5009 2040 : return save_expr (e);
5010 : /* Recursively stabilize each operand. */
5011 19964 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
5012 19964 : stabilize_reference_1 (TREE_OPERAND (e, 1)));
5013 19964 : break;
5014 :
5015 7756 : case tcc_unary:
5016 : /* Recursively stabilize each operand. */
5017 7756 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
5018 7756 : break;
5019 :
5020 0 : default:
5021 0 : gcc_unreachable ();
5022 : }
5023 :
5024 27720 : TREE_TYPE (result) = TREE_TYPE (e);
5025 27720 : TREE_READONLY (result) = TREE_READONLY (e);
5026 27720 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
5027 27720 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
5028 :
5029 27720 : return result;
5030 : }
5031 :
5032 : /* Stabilize a reference so that we can use it any number of times
5033 : without causing its operands to be evaluated more than once.
5034 : Returns the stabilized reference. This works by means of save_expr,
5035 : so see the caveats in the comments about save_expr.
5036 :
5037 : Also allows conversion expressions whose operands are references.
5038 : Any other kind of expression is returned unchanged. */
5039 :
5040 : tree
5041 4924887 : stabilize_reference (tree ref)
5042 : {
5043 4924887 : tree result;
5044 4924887 : enum tree_code code = TREE_CODE (ref);
5045 :
5046 4924887 : switch (code)
5047 : {
5048 : case VAR_DECL:
5049 : case PARM_DECL:
5050 : case RESULT_DECL:
5051 : /* No action is needed in this case. */
5052 : return ref;
5053 :
5054 0 : CASE_CONVERT:
5055 0 : case FLOAT_EXPR:
5056 0 : case FIX_TRUNC_EXPR:
5057 0 : result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
5058 0 : break;
5059 :
5060 815334 : case INDIRECT_REF:
5061 815334 : result = build_nt (INDIRECT_REF,
5062 815334 : stabilize_reference_1 (TREE_OPERAND (ref, 0)));
5063 815334 : break;
5064 :
5065 472412 : case COMPONENT_REF:
5066 472412 : result = build_nt (COMPONENT_REF,
5067 472412 : stabilize_reference (TREE_OPERAND (ref, 0)),
5068 472412 : TREE_OPERAND (ref, 1), NULL_TREE);
5069 472412 : break;
5070 :
5071 0 : case BIT_FIELD_REF:
5072 0 : result = build_nt (BIT_FIELD_REF,
5073 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5074 0 : TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2));
5075 0 : REF_REVERSE_STORAGE_ORDER (result) = REF_REVERSE_STORAGE_ORDER (ref);
5076 0 : break;
5077 :
5078 47009 : case ARRAY_REF:
5079 94018 : result = build_nt (ARRAY_REF,
5080 47009 : stabilize_reference (TREE_OPERAND (ref, 0)),
5081 47009 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5082 47009 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5083 47009 : break;
5084 :
5085 0 : case ARRAY_RANGE_REF:
5086 0 : result = build_nt (ARRAY_RANGE_REF,
5087 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5088 0 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5089 0 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5090 0 : break;
5091 :
5092 0 : case COMPOUND_EXPR:
5093 : /* We cannot wrap the first expression in a SAVE_EXPR, as then
5094 : it wouldn't be ignored. This matters when dealing with
5095 : volatiles. */
5096 0 : return stabilize_reference_1 (ref);
5097 :
5098 : /* If arg isn't a kind of lvalue we recognize, make no change.
5099 : Caller should recognize the error for an invalid lvalue. */
5100 : default:
5101 : return ref;
5102 :
5103 0 : case ERROR_MARK:
5104 0 : return error_mark_node;
5105 : }
5106 :
5107 1334755 : TREE_TYPE (result) = TREE_TYPE (ref);
5108 1334755 : TREE_READONLY (result) = TREE_READONLY (ref);
5109 1334755 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
5110 1334755 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
5111 1334755 : protected_set_expr_location (result, EXPR_LOCATION (ref));
5112 :
5113 1334755 : return result;
5114 : }
5115 :
5116 : /* Low-level constructors for expressions. */
5117 :
5118 : /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
5119 : and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
5120 :
5121 : void
5122 1450076818 : recompute_tree_invariant_for_addr_expr (tree t)
5123 : {
5124 1450076818 : tree node;
5125 1450076818 : bool tc = true, se = false;
5126 :
5127 1450076818 : gcc_assert (TREE_CODE (t) == ADDR_EXPR);
5128 :
5129 : /* We started out assuming this address is both invariant and constant, but
5130 : does not have side effects. Now go down any handled components and see if
5131 : any of them involve offsets that are either non-constant or non-invariant.
5132 : Also check for side-effects.
5133 :
5134 : ??? Note that this code makes no attempt to deal with the case where
5135 : taking the address of something causes a copy due to misalignment. */
5136 :
5137 : #define UPDATE_FLAGS(NODE) \
5138 : do { tree _node = (NODE); \
5139 : if (_node && !TREE_CONSTANT (_node)) tc = false; \
5140 : if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
5141 :
5142 1700043948 : for (node = TREE_OPERAND (t, 0); handled_component_p (node);
5143 249967130 : node = TREE_OPERAND (node, 0))
5144 : {
5145 : /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
5146 : array reference (probably made temporarily by the G++ front end),
5147 : so ignore all the operands. */
5148 249967130 : if ((TREE_CODE (node) == ARRAY_REF
5149 249967130 : || TREE_CODE (node) == ARRAY_RANGE_REF)
5150 249967130 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
5151 : {
5152 34656777 : UPDATE_FLAGS (TREE_OPERAND (node, 1));
5153 34656777 : if (TREE_OPERAND (node, 2))
5154 2353061 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5155 34656777 : if (TREE_OPERAND (node, 3))
5156 299986 : UPDATE_FLAGS (TREE_OPERAND (node, 3));
5157 : }
5158 : /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
5159 : FIELD_DECL, apparently. The G++ front end can put something else
5160 : there, at least temporarily. */
5161 215310353 : else if (TREE_CODE (node) == COMPONENT_REF
5162 215310353 : && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
5163 : {
5164 214084020 : if (TREE_OPERAND (node, 2))
5165 17035 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5166 : }
5167 : }
5168 :
5169 1450076818 : node = lang_hooks.expr_to_decl (node, &tc, &se);
5170 :
5171 : /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
5172 : the address, since &(*a)->b is a form of addition. If it's a constant, the
5173 : address is constant too. If it's a decl, its address is constant if the
5174 : decl is static. Everything else is not constant and, furthermore,
5175 : taking the address of a volatile variable is not volatile. */
5176 1450076818 : if (INDIRECT_REF_P (node)
5177 1410413857 : || TREE_CODE (node) == MEM_REF)
5178 165530215 : UPDATE_FLAGS (TREE_OPERAND (node, 0));
5179 1284546603 : else if (CONSTANT_CLASS_P (node))
5180 : ;
5181 1202261648 : else if (DECL_P (node))
5182 1177537052 : tc &= (staticp (node) != NULL_TREE);
5183 : else
5184 : {
5185 24724596 : tc = false;
5186 24724596 : se |= TREE_SIDE_EFFECTS (node);
5187 : }
5188 :
5189 :
5190 1450076818 : TREE_CONSTANT (t) = tc;
5191 1450076818 : TREE_SIDE_EFFECTS (t) = se;
5192 : #undef UPDATE_FLAGS
5193 1450076818 : }
5194 :
5195 : /* Build an expression of code CODE, data type TYPE, and operands as
5196 : specified. Expressions and reference nodes can be created this way.
5197 : Constants, decls, types and misc nodes cannot be.
5198 :
5199 : We define 5 non-variadic functions, from 0 to 4 arguments. This is
5200 : enough for all extant tree codes. */
5201 :
5202 : tree
5203 403606382 : build0 (enum tree_code code, tree tt MEM_STAT_DECL)
5204 : {
5205 403606382 : tree t;
5206 :
5207 403606382 : gcc_assert (TREE_CODE_LENGTH (code) == 0);
5208 :
5209 403606382 : t = make_node (code PASS_MEM_STAT);
5210 403606382 : TREE_TYPE (t) = tt;
5211 :
5212 403606382 : return t;
5213 : }
5214 :
5215 : tree
5216 4144247113 : build1 (enum tree_code code, tree type, tree node MEM_STAT_DECL)
5217 : {
5218 4144247113 : int length = sizeof (struct tree_exp);
5219 4144247113 : tree t;
5220 :
5221 4144247113 : record_node_allocation_statistics (code, length);
5222 :
5223 4144247113 : gcc_assert (TREE_CODE_LENGTH (code) == 1);
5224 :
5225 4144247113 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
5226 :
5227 4144247113 : memset (t, 0, sizeof (struct tree_common));
5228 :
5229 4144247113 : TREE_SET_CODE (t, code);
5230 :
5231 4144247113 : TREE_TYPE (t) = type;
5232 4144247113 : SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
5233 4144247113 : TREE_OPERAND (t, 0) = node;
5234 4144247113 : if (node && !TYPE_P (node))
5235 : {
5236 4144182476 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
5237 4144182476 : TREE_READONLY (t) = TREE_READONLY (node);
5238 : }
5239 :
5240 4144247113 : if (TREE_CODE_CLASS (code) == tcc_statement)
5241 : {
5242 24515794 : if (code != DEBUG_BEGIN_STMT)
5243 24515794 : TREE_SIDE_EFFECTS (t) = 1;
5244 : }
5245 4119731319 : else switch (code)
5246 : {
5247 51188 : case VA_ARG_EXPR:
5248 : /* All of these have side-effects, no matter what their
5249 : operands are. */
5250 51188 : TREE_SIDE_EFFECTS (t) = 1;
5251 51188 : TREE_READONLY (t) = 0;
5252 51188 : break;
5253 :
5254 645794595 : case INDIRECT_REF:
5255 : /* Whether a dereference is readonly has nothing to do with whether
5256 : its operand is readonly. */
5257 645794595 : TREE_READONLY (t) = 0;
5258 645794595 : break;
5259 :
5260 690604842 : case ADDR_EXPR:
5261 690604842 : if (node)
5262 690604842 : recompute_tree_invariant_for_addr_expr (t);
5263 : break;
5264 :
5265 2783280694 : default:
5266 1030302385 : if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
5267 2632587790 : && node && !TYPE_P (node)
5268 5415868484 : && TREE_CONSTANT (node))
5269 725774701 : TREE_CONSTANT (t) = 1;
5270 2783280694 : if (TREE_CODE_CLASS (code) == tcc_reference
5271 882388333 : && node && TREE_THIS_VOLATILE (node))
5272 3017818 : TREE_THIS_VOLATILE (t) = 1;
5273 : break;
5274 : }
5275 :
5276 4144247113 : return t;
5277 : }
5278 :
5279 : #define PROCESS_ARG(N) \
5280 : do { \
5281 : TREE_OPERAND (t, N) = arg##N; \
5282 : if (arg##N &&!TYPE_P (arg##N)) \
5283 : { \
5284 : if (TREE_SIDE_EFFECTS (arg##N)) \
5285 : side_effects = 1; \
5286 : if (!TREE_READONLY (arg##N) \
5287 : && !CONSTANT_CLASS_P (arg##N)) \
5288 : (void) (read_only = 0); \
5289 : if (!TREE_CONSTANT (arg##N)) \
5290 : (void) (constant = 0); \
5291 : } \
5292 : } while (0)
5293 :
5294 : tree
5295 1325026096 : build2 (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
5296 : {
5297 1325026096 : bool constant, read_only, side_effects, div_by_zero;
5298 1325026096 : tree t;
5299 :
5300 1325026096 : gcc_assert (TREE_CODE_LENGTH (code) == 2);
5301 :
5302 1325026096 : if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
5303 196348505 : && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
5304 : /* When sizetype precision doesn't match that of pointers
5305 : we need to be able to build explicit extensions or truncations
5306 : of the offset argument. */
5307 1325026096 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
5308 0 : gcc_assert (TREE_CODE (arg0) == INTEGER_CST
5309 : && TREE_CODE (arg1) == INTEGER_CST);
5310 :
5311 1325026096 : if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
5312 61663471 : gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
5313 : && ptrofftype_p (TREE_TYPE (arg1)));
5314 :
5315 1325026096 : t = make_node (code PASS_MEM_STAT);
5316 1325026096 : TREE_TYPE (t) = tt;
5317 :
5318 : /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
5319 : result based on those same flags for the arguments. But if the
5320 : arguments aren't really even `tree' expressions, we shouldn't be trying
5321 : to do this. */
5322 :
5323 : /* Expressions without side effects may be constant if their
5324 : arguments are as well. */
5325 2650052192 : constant = (TREE_CODE_CLASS (code) == tcc_comparison
5326 1325026096 : || TREE_CODE_CLASS (code) == tcc_binary);
5327 1325026096 : read_only = 1;
5328 1325026096 : side_effects = TREE_SIDE_EFFECTS (t);
5329 :
5330 1325026096 : switch (code)
5331 : {
5332 14722578 : case TRUNC_DIV_EXPR:
5333 14722578 : case CEIL_DIV_EXPR:
5334 14722578 : case FLOOR_DIV_EXPR:
5335 14722578 : case ROUND_DIV_EXPR:
5336 14722578 : case EXACT_DIV_EXPR:
5337 14722578 : case CEIL_MOD_EXPR:
5338 14722578 : case FLOOR_MOD_EXPR:
5339 14722578 : case ROUND_MOD_EXPR:
5340 14722578 : case TRUNC_MOD_EXPR:
5341 14722578 : div_by_zero = integer_zerop (arg1);
5342 14722578 : break;
5343 : default:
5344 : div_by_zero = false;
5345 : }
5346 :
5347 1464950573 : PROCESS_ARG (0);
5348 1866703895 : PROCESS_ARG (1);
5349 :
5350 1325026096 : TREE_SIDE_EFFECTS (t) = side_effects;
5351 1325026096 : if (code == MEM_REF)
5352 : {
5353 82650032 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5354 : {
5355 23225691 : tree o = TREE_OPERAND (arg0, 0);
5356 23225691 : TREE_READONLY (t) = TREE_READONLY (o);
5357 23225691 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5358 : }
5359 : }
5360 : else
5361 : {
5362 1242376064 : TREE_READONLY (t) = read_only;
5363 : /* Don't mark X / 0 as constant. */
5364 1242376064 : TREE_CONSTANT (t) = constant && !div_by_zero;
5365 1242376064 : TREE_THIS_VOLATILE (t)
5366 1242376064 : = (TREE_CODE_CLASS (code) == tcc_reference
5367 1242376064 : && arg0 && TREE_THIS_VOLATILE (arg0));
5368 : }
5369 :
5370 1325026096 : return t;
5371 : }
5372 :
5373 :
5374 : tree
5375 488477286 : build3 (enum tree_code code, tree tt, tree arg0, tree arg1,
5376 : tree arg2 MEM_STAT_DECL)
5377 : {
5378 488477286 : bool constant, read_only, side_effects;
5379 488477286 : tree t;
5380 :
5381 488477286 : gcc_assert (TREE_CODE_LENGTH (code) == 3);
5382 488477286 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5383 :
5384 488477286 : t = make_node (code PASS_MEM_STAT);
5385 488477286 : TREE_TYPE (t) = tt;
5386 :
5387 488477286 : read_only = 1;
5388 :
5389 : /* As a special exception, if COND_EXPR has NULL branches, we
5390 : assume that it is a gimple statement and always consider
5391 : it to have side effects. */
5392 488477286 : if (code == COND_EXPR
5393 41135157 : && tt == void_type_node
5394 25753121 : && arg1 == NULL_TREE
5395 25753121 : && arg2 == NULL_TREE)
5396 : side_effects = true;
5397 : else
5398 488477286 : side_effects = TREE_SIDE_EFFECTS (t);
5399 :
5400 488477286 : PROCESS_ARG (0);
5401 488477286 : PROCESS_ARG (1);
5402 488477286 : PROCESS_ARG (2);
5403 :
5404 488477286 : if (code == COND_EXPR)
5405 41135157 : TREE_READONLY (t) = read_only;
5406 :
5407 488477286 : TREE_SIDE_EFFECTS (t) = side_effects;
5408 488477286 : TREE_THIS_VOLATILE (t)
5409 488477286 : = (TREE_CODE_CLASS (code) == tcc_reference
5410 488477286 : && arg0 && TREE_THIS_VOLATILE (arg0));
5411 :
5412 488477286 : return t;
5413 : }
5414 :
5415 : tree
5416 59394491 : build4 (enum tree_code code, tree tt, tree arg0, tree arg1,
5417 : tree arg2, tree arg3 MEM_STAT_DECL)
5418 : {
5419 59394491 : bool constant, read_only, side_effects;
5420 59394491 : tree t;
5421 :
5422 59394491 : gcc_assert (TREE_CODE_LENGTH (code) == 4);
5423 :
5424 59394491 : t = make_node (code PASS_MEM_STAT);
5425 59394491 : TREE_TYPE (t) = tt;
5426 :
5427 59394491 : side_effects = TREE_SIDE_EFFECTS (t);
5428 :
5429 59394491 : PROCESS_ARG (0);
5430 59394491 : PROCESS_ARG (1);
5431 59394491 : PROCESS_ARG (2);
5432 59394491 : PROCESS_ARG (3);
5433 :
5434 59394491 : TREE_SIDE_EFFECTS (t) = side_effects;
5435 59394491 : TREE_THIS_VOLATILE (t)
5436 118788982 : = (TREE_CODE_CLASS (code) == tcc_reference
5437 59394491 : && arg0 && TREE_THIS_VOLATILE (arg0));
5438 :
5439 59394491 : return t;
5440 : }
5441 :
5442 : tree
5443 1183843 : build5 (enum tree_code code, tree tt, tree arg0, tree arg1,
5444 : tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
5445 : {
5446 1183843 : bool constant, read_only, side_effects;
5447 1183843 : tree t;
5448 :
5449 1183843 : gcc_assert (TREE_CODE_LENGTH (code) == 5);
5450 :
5451 1183843 : t = make_node (code PASS_MEM_STAT);
5452 1183843 : TREE_TYPE (t) = tt;
5453 :
5454 1183843 : side_effects = TREE_SIDE_EFFECTS (t);
5455 :
5456 1183843 : PROCESS_ARG (0);
5457 1183843 : PROCESS_ARG (1);
5458 1183843 : PROCESS_ARG (2);
5459 1183843 : PROCESS_ARG (3);
5460 1183843 : PROCESS_ARG (4);
5461 :
5462 1183843 : TREE_SIDE_EFFECTS (t) = side_effects;
5463 1183843 : if (code == TARGET_MEM_REF)
5464 : {
5465 1175187 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5466 : {
5467 190964 : tree o = TREE_OPERAND (arg0, 0);
5468 190964 : TREE_READONLY (t) = TREE_READONLY (o);
5469 190964 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5470 : }
5471 : }
5472 : else
5473 8656 : TREE_THIS_VOLATILE (t)
5474 8656 : = (TREE_CODE_CLASS (code) == tcc_reference
5475 8656 : && arg0 && TREE_THIS_VOLATILE (arg0));
5476 :
5477 1183843 : return t;
5478 : }
5479 :
5480 : /* Build a simple MEM_REF tree with the semantics of a plain INDIRECT_REF
5481 : on the pointer PTR. */
5482 :
5483 : tree
5484 484815 : build_simple_mem_ref_loc (location_t loc, tree ptr)
5485 : {
5486 484815 : poly_int64 offset = 0;
5487 484815 : tree ptype = TREE_TYPE (ptr);
5488 484815 : tree tem;
5489 : /* For convenience allow addresses that collapse to a simple base
5490 : and offset. */
5491 484815 : if (TREE_CODE (ptr) == ADDR_EXPR
5492 484815 : && (handled_component_p (TREE_OPERAND (ptr, 0))
5493 15629 : || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
5494 : {
5495 147 : ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
5496 147 : gcc_assert (ptr);
5497 147 : if (TREE_CODE (ptr) == MEM_REF)
5498 : {
5499 37 : offset += mem_ref_offset (ptr).force_shwi ();
5500 37 : ptr = TREE_OPERAND (ptr, 0);
5501 : }
5502 : else
5503 110 : ptr = build_fold_addr_expr (ptr);
5504 147 : gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
5505 : }
5506 484815 : tem = build2 (MEM_REF, TREE_TYPE (ptype),
5507 : ptr, build_int_cst (ptype, offset));
5508 484815 : SET_EXPR_LOCATION (tem, loc);
5509 484815 : return tem;
5510 : }
5511 :
5512 : /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
5513 :
5514 : poly_offset_int
5515 1234728124 : mem_ref_offset (const_tree t)
5516 : {
5517 1234728124 : return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
5518 1234728124 : SIGNED);
5519 : }
5520 :
5521 : /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
5522 : offsetted by OFFSET units. */
5523 :
5524 : tree
5525 199619 : build_invariant_address (tree type, tree base, poly_int64 offset)
5526 : {
5527 199619 : tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
5528 : build_fold_addr_expr (base),
5529 : build_int_cst (ptr_type_node, offset));
5530 199619 : tree addr = build1 (ADDR_EXPR, type, ref);
5531 199619 : recompute_tree_invariant_for_addr_expr (addr);
5532 199619 : return addr;
5533 : }
5534 :
5535 : /* Similar except don't specify the TREE_TYPE
5536 : and leave the TREE_SIDE_EFFECTS as 0.
5537 : It is permissible for arguments to be null,
5538 : or even garbage if their values do not matter. */
5539 :
5540 : tree
5541 5867612 : build_nt (enum tree_code code, ...)
5542 : {
5543 5867612 : tree t;
5544 5867612 : int length;
5545 5867612 : int i;
5546 5867612 : va_list p;
5547 :
5548 5867612 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5549 :
5550 5867612 : va_start (p, code);
5551 :
5552 5867612 : t = make_node (code);
5553 5867612 : length = TREE_CODE_LENGTH (code);
5554 :
5555 15834769 : for (i = 0; i < length; i++)
5556 9967157 : TREE_OPERAND (t, i) = va_arg (p, tree);
5557 :
5558 5867612 : va_end (p);
5559 5867612 : return t;
5560 : }
5561 :
5562 : /* Similar to build_nt, but for creating a CALL_EXPR object with a
5563 : tree vec. */
5564 :
5565 : tree
5566 0 : build_nt_call_vec (tree fn, vec<tree, va_gc> *args)
5567 : {
5568 0 : tree ret, t;
5569 0 : unsigned int ix;
5570 :
5571 0 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
5572 0 : CALL_EXPR_FN (ret) = fn;
5573 0 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
5574 0 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
5575 0 : CALL_EXPR_ARG (ret, ix) = t;
5576 0 : return ret;
5577 : }
5578 :
5579 : /* Create a DECL_... node of code CODE, name NAME (if non-null)
5580 : and data type TYPE.
5581 : We do NOT enter this node in any sort of symbol table.
5582 :
5583 : LOC is the location of the decl.
5584 :
5585 : layout_decl is used to set up the decl's storage layout.
5586 : Other slots are initialized to 0 or null pointers. */
5587 :
5588 : tree
5589 3284078338 : build_decl (location_t loc, enum tree_code code, tree name,
5590 : tree type MEM_STAT_DECL)
5591 : {
5592 3284078338 : tree t;
5593 :
5594 3284078338 : t = make_node (code PASS_MEM_STAT);
5595 3284078338 : DECL_SOURCE_LOCATION (t) = loc;
5596 :
5597 : /* if (type == error_mark_node)
5598 : type = integer_type_node; */
5599 : /* That is not done, deliberately, so that having error_mark_node
5600 : as the type can suppress useless errors in the use of this variable. */
5601 :
5602 3284078338 : DECL_NAME (t) = name;
5603 3284078338 : TREE_TYPE (t) = type;
5604 :
5605 3284078338 : if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
5606 1174096204 : layout_decl (t, 0);
5607 :
5608 3284078338 : return t;
5609 : }
5610 :
5611 : /* Create and return a DEBUG_EXPR_DECL node of the given TYPE. */
5612 :
5613 : tree
5614 1737768 : build_debug_expr_decl (tree type)
5615 : {
5616 1737768 : tree vexpr = make_node (DEBUG_EXPR_DECL);
5617 1737768 : DECL_ARTIFICIAL (vexpr) = 1;
5618 1737768 : TREE_TYPE (vexpr) = type;
5619 1737768 : SET_DECL_MODE (vexpr, TYPE_MODE (type));
5620 1737768 : return vexpr;
5621 : }
5622 :
5623 : /* Builds and returns function declaration with NAME and TYPE. */
5624 :
5625 : tree
5626 21431 : build_fn_decl (const char *name, tree type)
5627 : {
5628 21431 : tree id = get_identifier (name);
5629 21431 : tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
5630 :
5631 21431 : DECL_EXTERNAL (decl) = 1;
5632 21431 : TREE_PUBLIC (decl) = 1;
5633 21431 : DECL_ARTIFICIAL (decl) = 1;
5634 21431 : TREE_NOTHROW (decl) = 1;
5635 :
5636 21431 : return decl;
5637 : }
5638 :
5639 : vec<tree, va_gc> *all_translation_units;
5640 :
5641 : /* Builds a new translation-unit decl with name NAME, queues it in the
5642 : global list of translation-unit decls and returns it. */
5643 :
5644 : tree
5645 257012 : build_translation_unit_decl (tree name)
5646 : {
5647 257012 : tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
5648 257012 : name, NULL_TREE);
5649 257012 : TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
5650 257012 : vec_safe_push (all_translation_units, tu);
5651 257012 : return tu;
5652 : }
5653 :
5654 :
5655 : /* BLOCK nodes are used to represent the structure of binding contours
5656 : and declarations, once those contours have been exited and their contents
5657 : compiled. This information is used for outputting debugging info. */
5658 :
5659 : tree
5660 734050 : build_block (tree vars, tree subblocks, tree supercontext, tree chain)
5661 : {
5662 734050 : tree block = make_node (BLOCK);
5663 :
5664 734050 : BLOCK_VARS (block) = vars;
5665 734050 : BLOCK_SUBBLOCKS (block) = subblocks;
5666 734050 : BLOCK_SUPERCONTEXT (block) = supercontext;
5667 734050 : BLOCK_CHAIN (block) = chain;
5668 734050 : return block;
5669 : }
5670 :
5671 :
5672 : /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
5673 :
5674 : LOC is the location to use in tree T. */
5675 :
5676 : void
5677 15051460914 : protected_set_expr_location (tree t, location_t loc)
5678 : {
5679 15051460914 : if (CAN_HAVE_LOCATION_P (t))
5680 2386284581 : SET_EXPR_LOCATION (t, loc);
5681 12574459705 : else if (t && TREE_CODE (t) == STATEMENT_LIST)
5682 : {
5683 22243 : t = expr_single (t);
5684 22243 : if (t && CAN_HAVE_LOCATION_P (t))
5685 18 : SET_EXPR_LOCATION (t, loc);
5686 : }
5687 15051460914 : }
5688 :
5689 : /* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has
5690 : UNKNOWN_LOCATION. */
5691 :
5692 : void
5693 26423619 : protected_set_expr_location_if_unset (tree t, location_t loc)
5694 : {
5695 26423619 : t = expr_single (t);
5696 26423619 : if (t && !EXPR_HAS_LOCATION (t))
5697 18866503 : protected_set_expr_location (t, loc);
5698 26423619 : }
5699 :
5700 : /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5701 : of the various TYPE_QUAL values. */
5702 :
5703 : static void
5704 114579912 : set_type_quals (tree type, int type_quals)
5705 : {
5706 114579912 : TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
5707 114579912 : TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
5708 114579912 : TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
5709 114579912 : TYPE_ATOMIC (type) = (type_quals & TYPE_QUAL_ATOMIC) != 0;
5710 114579912 : TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
5711 114579912 : }
5712 :
5713 : /* Returns true iff CAND and BASE have equivalent language-specific
5714 : qualifiers. */
5715 :
5716 : bool
5717 3264678558 : check_lang_type (const_tree cand, const_tree base)
5718 : {
5719 3264678558 : if (lang_hooks.types.type_hash_eq == NULL)
5720 : return true;
5721 : /* type_hash_eq currently only applies to these types. */
5722 3207060819 : if (TREE_CODE (cand) != FUNCTION_TYPE
5723 3207060819 : && TREE_CODE (cand) != METHOD_TYPE)
5724 : return true;
5725 1186114 : return lang_hooks.types.type_hash_eq (cand, base);
5726 : }
5727 :
5728 : /* This function checks to see if TYPE matches the size one of the built-in
5729 : atomic types, and returns that core atomic type. */
5730 :
5731 : static tree
5732 8918 : find_atomic_core_type (const_tree type)
5733 : {
5734 8918 : tree base_atomic_type;
5735 :
5736 : /* Only handle complete types. */
5737 8918 : if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
5738 : return NULL_TREE;
5739 :
5740 8906 : switch (tree_to_uhwi (TYPE_SIZE (type)))
5741 : {
5742 2710 : case 8:
5743 2710 : base_atomic_type = atomicQI_type_node;
5744 2710 : break;
5745 :
5746 862 : case 16:
5747 862 : base_atomic_type = atomicHI_type_node;
5748 862 : break;
5749 :
5750 1117 : case 32:
5751 1117 : base_atomic_type = atomicSI_type_node;
5752 1117 : break;
5753 :
5754 2749 : case 64:
5755 2749 : base_atomic_type = atomicDI_type_node;
5756 2749 : break;
5757 :
5758 1348 : case 128:
5759 1348 : base_atomic_type = atomicTI_type_node;
5760 1348 : break;
5761 :
5762 : default:
5763 : base_atomic_type = NULL_TREE;
5764 : }
5765 :
5766 : return base_atomic_type;
5767 : }
5768 :
5769 : /* Returns true iff unqualified CAND and BASE are equivalent. */
5770 :
5771 : bool
5772 5198124098 : check_base_type (const_tree cand, const_tree base)
5773 : {
5774 5198124098 : if (TYPE_NAME (cand) != TYPE_NAME (base)
5775 : /* Apparently this is needed for Objective-C. */
5776 4581501652 : || TYPE_CONTEXT (cand) != TYPE_CONTEXT (base)
5777 9779625749 : || !attribute_list_equal (TYPE_ATTRIBUTES (cand),
5778 4581501651 : TYPE_ATTRIBUTES (base)))
5779 : return false;
5780 : /* Check alignment. */
5781 4581501651 : if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
5782 4581501651 : && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
5783 : return true;
5784 : /* Atomic types increase minimal alignment. We must to do so as well
5785 : or we get duplicated canonical types. See PR88686. */
5786 11298 : if ((TYPE_QUALS (cand) & TYPE_QUAL_ATOMIC))
5787 : {
5788 : /* See if this object can map to a basic atomic type. */
5789 1775 : tree atomic_type = find_atomic_core_type (cand);
5790 1775 : if (atomic_type && TYPE_ALIGN (atomic_type) == TYPE_ALIGN (cand))
5791 1775 : return true;
5792 : }
5793 : return false;
5794 : }
5795 :
5796 : /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5797 :
5798 : bool
5799 5566737954 : check_qualified_type (const_tree cand, const_tree base, int type_quals)
5800 : {
5801 5566737954 : return (TYPE_QUALS (cand) == type_quals
5802 3879087337 : && check_base_type (cand, base)
5803 8829556473 : && check_lang_type (cand, base));
5804 : }
5805 :
5806 : /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5807 :
5808 : static bool
5809 3877130 : check_aligned_type (const_tree cand, const_tree base, unsigned int align)
5810 : {
5811 3877130 : return (TYPE_QUALS (cand) == TYPE_QUALS (base)
5812 3141811 : && TYPE_NAME (cand) == TYPE_NAME (base)
5813 : /* Apparently this is needed for Objective-C. */
5814 2238028 : && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
5815 : /* Check alignment. */
5816 2238028 : && TYPE_ALIGN (cand) == align
5817 : /* Check this is a user-aligned type as build_aligned_type
5818 : would create. */
5819 1059820 : && TYPE_USER_ALIGN (cand)
5820 1056959 : && attribute_list_equal (TYPE_ATTRIBUTES (cand),
5821 1056959 : TYPE_ATTRIBUTES (base))
5822 4934089 : && check_lang_type (cand, base));
5823 : }
5824 :
5825 : /* Return a version of the TYPE, qualified as indicated by the
5826 : TYPE_QUALS, if one exists. If no qualified version exists yet,
5827 : return NULL_TREE. */
5828 :
5829 : tree
5830 4772662893 : get_qualified_type (tree type, int type_quals)
5831 : {
5832 4772662893 : if (TYPE_QUALS (type) == type_quals)
5833 : return type;
5834 :
5835 3377552754 : tree mv = TYPE_MAIN_VARIANT (type);
5836 3377552754 : if (check_qualified_type (mv, type, type_quals))
5837 : return mv;
5838 :
5839 : /* Search the chain of variants to see if there is already one there just
5840 : like the one we need to have. If so, use that existing one. We must
5841 : preserve the TYPE_NAME, since there is code that depends on this. */
5842 2303929921 : for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
5843 2189121449 : if (check_qualified_type (*tp, type, type_quals))
5844 : {
5845 : /* Put the found variant at the head of the variant list so
5846 : frequently searched variants get found faster. The C++ FE
5847 : benefits greatly from this. */
5848 1374999150 : tree t = *tp;
5849 1374999150 : *tp = TYPE_NEXT_VARIANT (t);
5850 1374999150 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
5851 1374999150 : TYPE_NEXT_VARIANT (mv) = t;
5852 1374999150 : return t;
5853 : }
5854 :
5855 : return NULL_TREE;
5856 : }
5857 :
5858 : /* Like get_qualified_type, but creates the type if it does not
5859 : exist. This function never returns NULL_TREE. */
5860 :
5861 : tree
5862 4268567151 : build_qualified_type (tree type, int type_quals MEM_STAT_DECL)
5863 : {
5864 4268567151 : tree t;
5865 :
5866 : /* See if we already have the appropriate qualified variant. */
5867 4268567151 : t = get_qualified_type (type, type_quals);
5868 :
5869 : /* If not, build it. */
5870 4268567151 : if (!t)
5871 : {
5872 113110442 : t = build_variant_type_copy (type PASS_MEM_STAT);
5873 113110442 : set_type_quals (t, type_quals);
5874 :
5875 113110442 : if (((type_quals & TYPE_QUAL_ATOMIC) == TYPE_QUAL_ATOMIC))
5876 : {
5877 : /* See if this object can map to a basic atomic type. */
5878 7143 : tree atomic_type = find_atomic_core_type (type);
5879 7143 : if (atomic_type)
5880 : {
5881 : /* Ensure the alignment of this type is compatible with
5882 : the required alignment of the atomic type. */
5883 7011 : if (TYPE_ALIGN (atomic_type) > TYPE_ALIGN (t))
5884 98 : SET_TYPE_ALIGN (t, TYPE_ALIGN (atomic_type));
5885 : }
5886 : }
5887 :
5888 113110442 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5889 : /* Propagate structural equality. */
5890 5730485 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5891 107379957 : else if (TYPE_CANONICAL (type) != type)
5892 : /* Build the underlying canonical type, since it is different
5893 : from TYPE. */
5894 : {
5895 35104925 : tree c = build_qualified_type (TYPE_CANONICAL (type), type_quals);
5896 35104925 : TYPE_CANONICAL (t) = TYPE_CANONICAL (c);
5897 : }
5898 : else
5899 : /* T is its own canonical type. */
5900 72275032 : TYPE_CANONICAL (t) = t;
5901 :
5902 : }
5903 :
5904 4268567151 : return t;
5905 : }
5906 :
5907 : /* Create a variant of type T with alignment ALIGN which
5908 : is measured in bits. */
5909 :
5910 : tree
5911 1349255 : build_aligned_type (tree type, unsigned int align)
5912 : {
5913 1349255 : tree t;
5914 :
5915 1349255 : if (TYPE_PACKED (type)
5916 1349255 : || TYPE_ALIGN (type) == align)
5917 : return type;
5918 :
5919 3986254 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5920 3877130 : if (check_aligned_type (t, type, align))
5921 : return t;
5922 :
5923 109124 : t = build_variant_type_copy (type);
5924 109124 : SET_TYPE_ALIGN (t, align);
5925 109124 : TYPE_USER_ALIGN (t) = 1;
5926 :
5927 109124 : return t;
5928 : }
5929 :
5930 : /* Create a new distinct copy of TYPE. The new type is made its own
5931 : MAIN_VARIANT. If TYPE requires structural equality checks, the
5932 : resulting type requires structural equality checks; otherwise, its
5933 : TYPE_CANONICAL points to itself. */
5934 :
5935 : tree
5936 813884432 : build_distinct_type_copy (tree type MEM_STAT_DECL)
5937 : {
5938 813884432 : tree t = copy_node (type PASS_MEM_STAT);
5939 :
5940 813884432 : TYPE_POINTER_TO (t) = 0;
5941 813884432 : TYPE_REFERENCE_TO (t) = 0;
5942 :
5943 : /* Set the canonical type either to a new equivalence class, or
5944 : propagate the need for structural equality checks. */
5945 813884432 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5946 68617574 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5947 : else
5948 745266858 : TYPE_CANONICAL (t) = t;
5949 :
5950 : /* Make it its own variant. */
5951 813884432 : TYPE_MAIN_VARIANT (t) = t;
5952 813884432 : TYPE_NEXT_VARIANT (t) = 0;
5953 :
5954 : /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5955 : whose TREE_TYPE is not t. This can also happen in the Ada
5956 : frontend when using subtypes. */
5957 :
5958 813884432 : return t;
5959 : }
5960 :
5961 : /* Create a new variant of TYPE, equivalent but distinct. This is so
5962 : the caller can modify it. TYPE_CANONICAL for the return type will
5963 : be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5964 : are considered equal by the language itself (or that both types
5965 : require structural equality checks). */
5966 :
5967 : tree
5968 526529273 : build_variant_type_copy (tree type MEM_STAT_DECL)
5969 : {
5970 526529273 : tree t, m = TYPE_MAIN_VARIANT (type);
5971 :
5972 526529273 : t = build_distinct_type_copy (type PASS_MEM_STAT);
5973 :
5974 : /* Since we're building a variant, assume that it is a non-semantic
5975 : variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5976 526529273 : TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
5977 : /* Type variants have no alias set defined. */
5978 526529273 : TYPE_ALIAS_SET (t) = -1;
5979 :
5980 : /* Add the new type to the chain of variants of TYPE. */
5981 526529273 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
5982 526529273 : TYPE_NEXT_VARIANT (m) = t;
5983 526529273 : TYPE_MAIN_VARIANT (t) = m;
5984 :
5985 526529273 : return t;
5986 : }
5987 :
5988 : /* Return true if the from tree in both tree maps are equal. */
5989 :
5990 : int
5991 1903950564 : tree_map_base_eq (const void *va, const void *vb)
5992 : {
5993 1903950564 : const struct tree_map_base *const a = (const struct tree_map_base *) va,
5994 1903950564 : *const b = (const struct tree_map_base *) vb;
5995 1903950564 : return (a->from == b->from);
5996 : }
5997 :
5998 : /* Hash a from tree in a tree_base_map. */
5999 :
6000 : unsigned int
6001 0 : tree_map_base_hash (const void *item)
6002 : {
6003 0 : return htab_hash_pointer (((const struct tree_map_base *)item)->from);
6004 : }
6005 :
6006 : /* Return true if this tree map structure is marked for garbage collection
6007 : purposes. We simply return true if the from tree is marked, so that this
6008 : structure goes away when the from tree goes away. */
6009 :
6010 : bool
6011 0 : tree_map_base_marked_p (const void *p)
6012 : {
6013 0 : return ggc_marked_p (((const struct tree_map_base *) p)->from);
6014 : }
6015 :
6016 : /* Hash a from tree in a tree_map. */
6017 :
6018 : unsigned int
6019 182 : tree_map_hash (const void *item)
6020 : {
6021 182 : return (((const struct tree_map *) item)->hash);
6022 : }
6023 :
6024 : /* Hash a from tree in a tree_decl_map. */
6025 :
6026 : unsigned int
6027 1298511772 : tree_decl_map_hash (const void *item)
6028 : {
6029 1298511772 : return DECL_UID (((const struct tree_decl_map *) item)->base.from);
6030 : }
6031 :
6032 : /* Return the initialization priority for DECL. */
6033 :
6034 : priority_type
6035 24455 : decl_init_priority_lookup (tree decl)
6036 : {
6037 24455 : symtab_node *snode = symtab_node::get (decl);
6038 :
6039 24455 : if (!snode)
6040 : return DEFAULT_INIT_PRIORITY;
6041 24455 : return
6042 24455 : snode->get_init_priority ();
6043 : }
6044 :
6045 : /* Return the finalization priority for DECL. */
6046 :
6047 : priority_type
6048 1879 : decl_fini_priority_lookup (tree decl)
6049 : {
6050 1879 : cgraph_node *node = cgraph_node::get (decl);
6051 :
6052 1879 : if (!node)
6053 : return DEFAULT_INIT_PRIORITY;
6054 1879 : return
6055 1879 : node->get_fini_priority ();
6056 : }
6057 :
6058 : /* Set the initialization priority for DECL to PRIORITY. */
6059 :
6060 : void
6061 26052 : decl_init_priority_insert (tree decl, priority_type priority)
6062 : {
6063 26052 : struct symtab_node *snode;
6064 :
6065 26052 : if (priority == DEFAULT_INIT_PRIORITY)
6066 : {
6067 22524 : snode = symtab_node::get (decl);
6068 22524 : if (!snode)
6069 : return;
6070 : }
6071 3528 : else if (VAR_P (decl))
6072 45 : snode = varpool_node::get_create (decl);
6073 : else
6074 3483 : snode = cgraph_node::get_create (decl);
6075 25227 : snode->set_init_priority (priority);
6076 : }
6077 :
6078 : /* Set the finalization priority for DECL to PRIORITY. */
6079 :
6080 : void
6081 1740 : decl_fini_priority_insert (tree decl, priority_type priority)
6082 : {
6083 1740 : struct cgraph_node *node;
6084 :
6085 1740 : if (priority == DEFAULT_INIT_PRIORITY)
6086 : {
6087 105 : node = cgraph_node::get (decl);
6088 105 : if (!node)
6089 : return;
6090 : }
6091 : else
6092 1635 : node = cgraph_node::get_create (decl);
6093 1645 : node->set_fini_priority (priority);
6094 : }
6095 :
6096 : /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6097 :
6098 : static void
6099 0 : print_debug_expr_statistics (void)
6100 : {
6101 0 : fprintf (stderr, "DECL_DEBUG_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6102 : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6103 0 : (fmt_size_t) debug_expr_for_decl->size (),
6104 0 : (fmt_size_t) debug_expr_for_decl->elements (),
6105 : debug_expr_for_decl->collisions ());
6106 0 : }
6107 :
6108 : /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6109 :
6110 : static void
6111 0 : print_value_expr_statistics (void)
6112 : {
6113 0 : fprintf (stderr, "DECL_VALUE_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6114 : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6115 0 : (fmt_size_t) value_expr_for_decl->size (),
6116 0 : (fmt_size_t) value_expr_for_decl->elements (),
6117 : value_expr_for_decl->collisions ());
6118 0 : }
6119 :
6120 : /* Lookup a debug expression for FROM, and return it if we find one. */
6121 :
6122 : tree
6123 449375631 : decl_debug_expr_lookup (tree from)
6124 : {
6125 449375631 : struct tree_decl_map *h, in;
6126 449375631 : in.base.from = from;
6127 :
6128 449375631 : h = debug_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6129 449375631 : if (h)
6130 449375631 : return h->to;
6131 : return NULL_TREE;
6132 : }
6133 :
6134 : /* Insert a mapping FROM->TO in the debug expression hashtable. */
6135 :
6136 : void
6137 1425765 : decl_debug_expr_insert (tree from, tree to)
6138 : {
6139 1425765 : struct tree_decl_map *h;
6140 :
6141 1425765 : h = ggc_alloc<tree_decl_map> ();
6142 1425765 : h->base.from = from;
6143 1425765 : h->to = to;
6144 1425765 : *debug_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6145 1425765 : }
6146 :
6147 : /* Lookup a value expression for FROM, and return it if we find one. */
6148 :
6149 : tree
6150 24298637 : decl_value_expr_lookup (tree from)
6151 : {
6152 24298637 : struct tree_decl_map *h, in;
6153 24298637 : in.base.from = from;
6154 :
6155 24298637 : h = value_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6156 24298637 : if (h)
6157 24298637 : return h->to;
6158 : return NULL_TREE;
6159 : }
6160 :
6161 : /* Insert a mapping FROM->TO in the value expression hashtable. */
6162 :
6163 : void
6164 8921108 : decl_value_expr_insert (tree from, tree to)
6165 : {
6166 8921108 : struct tree_decl_map *h;
6167 :
6168 : /* Uses of FROM shouldn't look like they happen at the location of TO. */
6169 8921108 : to = protected_set_expr_location_unshare (to, UNKNOWN_LOCATION);
6170 :
6171 8921108 : h = ggc_alloc<tree_decl_map> ();
6172 8921108 : h->base.from = from;
6173 8921108 : h->to = to;
6174 8921108 : *value_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6175 8921108 : }
6176 :
6177 : /* Lookup a vector of debug arguments for FROM, and return it if we
6178 : find one. */
6179 :
6180 : vec<tree, va_gc> **
6181 966926 : decl_debug_args_lookup (tree from)
6182 : {
6183 966926 : struct tree_vec_map *h, in;
6184 :
6185 966926 : if (!DECL_HAS_DEBUG_ARGS_P (from))
6186 : return NULL;
6187 825061 : gcc_checking_assert (debug_args_for_decl != NULL);
6188 825061 : in.base.from = from;
6189 825061 : h = debug_args_for_decl->find_with_hash (&in, DECL_UID (from));
6190 825061 : if (h)
6191 821138 : return &h->to;
6192 : return NULL;
6193 : }
6194 :
6195 : /* Insert a mapping FROM->empty vector of debug arguments in the value
6196 : expression hashtable. */
6197 :
6198 : vec<tree, va_gc> **
6199 307773 : decl_debug_args_insert (tree from)
6200 : {
6201 307773 : struct tree_vec_map *h;
6202 307773 : tree_vec_map **loc;
6203 :
6204 307773 : if (DECL_HAS_DEBUG_ARGS_P (from))
6205 213572 : return decl_debug_args_lookup (from);
6206 94201 : if (debug_args_for_decl == NULL)
6207 8514 : debug_args_for_decl = hash_table<tree_vec_map_cache_hasher>::create_ggc (64);
6208 94201 : h = ggc_alloc<tree_vec_map> ();
6209 94201 : h->base.from = from;
6210 94201 : h->to = NULL;
6211 94201 : loc = debug_args_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT);
6212 94201 : *loc = h;
6213 94201 : DECL_HAS_DEBUG_ARGS_P (from) = 1;
6214 94201 : return &h->to;
6215 : }
6216 :
6217 : /* Hashing of types so that we don't make duplicates.
6218 : The entry point is `type_hash_canon'. */
6219 :
6220 : /* Generate the default hash code for TYPE. This is designed for
6221 : speed, rather than maximum entropy. */
6222 :
6223 : hashval_t
6224 1466626679 : type_hash_canon_hash (tree type)
6225 : {
6226 1466626679 : inchash::hash hstate;
6227 :
6228 1466626679 : hstate.add_int (TREE_CODE (type));
6229 :
6230 1466626679 : hstate.add_flag (TYPE_STRUCTURAL_EQUALITY_P (type));
6231 :
6232 1466626679 : if (TREE_TYPE (type))
6233 1466543188 : hstate.add_object (TYPE_HASH (TREE_TYPE (type)));
6234 :
6235 1748913631 : for (tree t = TYPE_ATTRIBUTES (type); t; t = TREE_CHAIN (t))
6236 : /* Just the identifier is adequate to distinguish. */
6237 282286952 : hstate.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (t)));
6238 :
6239 1466626679 : switch (TREE_CODE (type))
6240 : {
6241 347001845 : case METHOD_TYPE:
6242 347001845 : hstate.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type)));
6243 : /* FALLTHROUGH. */
6244 1265518247 : case FUNCTION_TYPE:
6245 4987959795 : for (tree t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
6246 3722441548 : if (TREE_VALUE (t) != error_mark_node)
6247 3722428981 : hstate.add_object (TYPE_HASH (TREE_VALUE (t)));
6248 : break;
6249 :
6250 995482 : case OFFSET_TYPE:
6251 995482 : hstate.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type)));
6252 995482 : break;
6253 :
6254 74315570 : case ARRAY_TYPE:
6255 74315570 : {
6256 74315570 : if (TYPE_DOMAIN (type))
6257 71294074 : hstate.add_object (TYPE_HASH (TYPE_DOMAIN (type)));
6258 74315570 : if (!AGGREGATE_TYPE_P (TREE_TYPE (type)))
6259 : {
6260 71804262 : unsigned typeless = TYPE_TYPELESS_STORAGE (type);
6261 71804262 : hstate.add_object (typeless);
6262 : }
6263 : }
6264 : break;
6265 :
6266 44103357 : case INTEGER_TYPE:
6267 44103357 : {
6268 44103357 : tree t = TYPE_MAX_VALUE (type);
6269 44103357 : if (!t)
6270 556492 : t = TYPE_MIN_VALUE (type);
6271 88206715 : for (int i = 0; i < TREE_INT_CST_NUNITS (t); i++)
6272 44103358 : hstate.add_object (TREE_INT_CST_ELT (t, i));
6273 : break;
6274 : }
6275 :
6276 61030 : case BITINT_TYPE:
6277 61030 : {
6278 61030 : unsigned prec = TYPE_PRECISION (type);
6279 61030 : unsigned uns = TYPE_UNSIGNED (type);
6280 61030 : hstate.add_object (prec);
6281 61030 : hstate.add_int (uns);
6282 61030 : break;
6283 : }
6284 :
6285 12074 : case REAL_TYPE:
6286 12074 : case FIXED_POINT_TYPE:
6287 12074 : {
6288 12074 : unsigned prec = TYPE_PRECISION (type);
6289 12074 : hstate.add_object (prec);
6290 12074 : break;
6291 : }
6292 :
6293 75904326 : case VECTOR_TYPE:
6294 75904326 : hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type));
6295 75904326 : break;
6296 :
6297 : case REFERENCE_TYPE:
6298 1466626679 : hstate.add_flag (TYPE_REF_IS_RVALUE (type));
6299 : break;
6300 :
6301 : default:
6302 : break;
6303 : }
6304 :
6305 1466626679 : return hstate.end ();
6306 : }
6307 :
6308 : /* These are the Hashtable callback functions. */
6309 :
6310 : /* Returns true iff the types are equivalent. */
6311 :
6312 : bool
6313 9789726410 : type_cache_hasher::equal (type_hash *a, type_hash *b)
6314 : {
6315 : /* First test the things that are the same for all types. */
6316 9789726410 : if (a->hash != b->hash
6317 723381445 : || TREE_CODE (a->type) != TREE_CODE (b->type)
6318 723380928 : || TREE_TYPE (a->type) != TREE_TYPE (b->type)
6319 723380520 : || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
6320 723380520 : TYPE_ATTRIBUTES (b->type))
6321 10505928039 : || (TREE_CODE (a->type) != COMPLEX_TYPE
6322 713976521 : && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
6323 : return false;
6324 :
6325 : /* Be careful about comparing arrays before and after the element type
6326 : has been completed; don't compare TYPE_ALIGN unless both types are
6327 : complete. */
6328 1427374515 : if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
6329 1427374515 : && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
6330 712072113 : || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
6331 : return false;
6332 :
6333 715301261 : if (TYPE_STRUCTURAL_EQUALITY_P (a->type)
6334 715301261 : != TYPE_STRUCTURAL_EQUALITY_P (b->type))
6335 : return false;
6336 :
6337 715297457 : switch (TREE_CODE (a->type))
6338 : {
6339 : case VOID_TYPE:
6340 : case OPAQUE_TYPE:
6341 : case COMPLEX_TYPE:
6342 : case POINTER_TYPE:
6343 : case NULLPTR_TYPE:
6344 : return true;
6345 :
6346 69414262 : case VECTOR_TYPE:
6347 69414262 : return known_eq (TYPE_VECTOR_SUBPARTS (a->type),
6348 : TYPE_VECTOR_SUBPARTS (b->type));
6349 :
6350 0 : case ENUMERAL_TYPE:
6351 0 : if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6352 0 : && !(TYPE_VALUES (a->type)
6353 0 : && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6354 0 : && TYPE_VALUES (b->type)
6355 0 : && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
6356 0 : && type_list_equal (TYPE_VALUES (a->type),
6357 0 : TYPE_VALUES (b->type))))
6358 : return false;
6359 :
6360 : /* fall through */
6361 :
6362 41068591 : case INTEGER_TYPE:
6363 41068591 : case REAL_TYPE:
6364 41068591 : case BOOLEAN_TYPE:
6365 41068591 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6366 : return false;
6367 41054730 : return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
6368 743370 : || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
6369 743370 : TYPE_MAX_VALUE (b->type)))
6370 41382688 : && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
6371 488665 : || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
6372 488665 : TYPE_MIN_VALUE (b->type))));
6373 :
6374 54423 : case BITINT_TYPE:
6375 54423 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6376 : return false;
6377 54423 : return TYPE_UNSIGNED (a->type) == TYPE_UNSIGNED (b->type);
6378 :
6379 0 : case FIXED_POINT_TYPE:
6380 0 : return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
6381 :
6382 754181 : case OFFSET_TYPE:
6383 754181 : return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
6384 :
6385 96474643 : case METHOD_TYPE:
6386 96474643 : if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
6387 96474643 : && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6388 96322617 : || (TYPE_ARG_TYPES (a->type)
6389 96322617 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6390 96322617 : && TYPE_ARG_TYPES (b->type)
6391 96322617 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6392 96322617 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6393 96322617 : TYPE_ARG_TYPES (b->type)))))
6394 : break;
6395 : return false;
6396 62847000 : case ARRAY_TYPE:
6397 : /* Don't compare TYPE_TYPELESS_STORAGE flag on aggregates,
6398 : where the flag should be inherited from the element type
6399 : and can change after ARRAY_TYPEs are created; on non-aggregates
6400 : compare it and hash it, scalars will never have that flag set
6401 : and we need to differentiate between arrays created by different
6402 : front-ends or middle-end created arrays. */
6403 62847000 : return (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
6404 62847000 : && (AGGREGATE_TYPE_P (TREE_TYPE (a->type))
6405 60982206 : || (TYPE_TYPELESS_STORAGE (a->type)
6406 60982206 : == TYPE_TYPELESS_STORAGE (b->type))));
6407 :
6408 0 : case RECORD_TYPE:
6409 0 : case UNION_TYPE:
6410 0 : case QUAL_UNION_TYPE:
6411 0 : return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
6412 0 : || (TYPE_FIELDS (a->type)
6413 0 : && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
6414 0 : && TYPE_FIELDS (b->type)
6415 0 : && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
6416 0 : && type_list_equal (TYPE_FIELDS (a->type),
6417 0 : TYPE_FIELDS (b->type))));
6418 :
6419 442458791 : case FUNCTION_TYPE:
6420 442458791 : if ((TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6421 278641040 : && (TYPE_NO_NAMED_ARGS_STDARG_P (a->type)
6422 278641040 : == TYPE_NO_NAMED_ARGS_STDARG_P (b->type)))
6423 442761205 : || (TYPE_ARG_TYPES (a->type)
6424 163817751 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6425 163817751 : && TYPE_ARG_TYPES (b->type)
6426 163817736 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6427 163817736 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6428 163817736 : TYPE_ARG_TYPES (b->type))))
6429 : break;
6430 : return false;
6431 :
6432 9 : case REFERENCE_TYPE:
6433 9 : return TYPE_REF_IS_RVALUE (a->type) == TYPE_REF_IS_RVALUE (b->type);
6434 :
6435 : default:
6436 : return false;
6437 : }
6438 :
6439 510615800 : if (lang_hooks.types.type_hash_eq != NULL)
6440 326731778 : return lang_hooks.types.type_hash_eq (a->type, b->type);
6441 :
6442 : return true;
6443 : }
6444 :
6445 : /* Given TYPE, and HASHCODE its hash code, return the canonical
6446 : object for an identical type if one already exists.
6447 : Otherwise, return TYPE, and record it as the canonical object.
6448 :
6449 : To use this function, first create a type of the sort you want.
6450 : Then compute its hash code from the fields of the type that
6451 : make it different from other similar types.
6452 : Then call this function and use the value. */
6453 :
6454 : tree
6455 1467713419 : type_hash_canon (unsigned int hashcode, tree type)
6456 : {
6457 1467713419 : type_hash in;
6458 1467713419 : type_hash **loc;
6459 :
6460 : /* The hash table only contains main variants, so ensure that's what we're
6461 : being passed. */
6462 1467713419 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
6463 :
6464 : /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6465 : must call that routine before comparing TYPE_ALIGNs. */
6466 1467713419 : layout_type (type);
6467 :
6468 1467713419 : in.hash = hashcode;
6469 1467713419 : in.type = type;
6470 :
6471 1467713419 : loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT);
6472 1467713419 : if (*loc)
6473 : {
6474 686383497 : tree t1 = ((type_hash *) *loc)->type;
6475 686383497 : gcc_assert (TYPE_MAIN_VARIANT (t1) == t1
6476 : && t1 != type);
6477 686383497 : if (TYPE_UID (type) + 1 == next_type_uid)
6478 681054455 : --next_type_uid;
6479 : /* Free also min/max values and the cache for integer
6480 : types. This can't be done in free_node, as LTO frees
6481 : those on its own. */
6482 686383497 : if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE)
6483 : {
6484 40526685 : if (TYPE_MIN_VALUE (type)
6485 40526685 : && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
6486 : {
6487 : /* Zero is always in TYPE_CACHED_VALUES. */
6488 375380 : if (! TYPE_UNSIGNED (type))
6489 222687 : int_cst_hash_table->remove_elt (TYPE_MIN_VALUE (type));
6490 375380 : ggc_free (TYPE_MIN_VALUE (type));
6491 : }
6492 40526685 : if (TYPE_MAX_VALUE (type)
6493 40526685 : && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
6494 : {
6495 375380 : int_cst_hash_table->remove_elt (TYPE_MAX_VALUE (type));
6496 375380 : ggc_free (TYPE_MAX_VALUE (type));
6497 : }
6498 40526685 : if (TYPE_CACHED_VALUES_P (type))
6499 152693 : ggc_free (TYPE_CACHED_VALUES (type));
6500 : }
6501 686383497 : free_node (type);
6502 686383497 : return t1;
6503 : }
6504 : else
6505 : {
6506 781329922 : struct type_hash *h;
6507 :
6508 781329922 : h = ggc_alloc<type_hash> ();
6509 781329922 : h->hash = hashcode;
6510 781329922 : h->type = type;
6511 781329922 : *loc = h;
6512 :
6513 781329922 : return type;
6514 : }
6515 : }
6516 :
6517 : static void
6518 0 : print_type_hash_statistics (void)
6519 : {
6520 0 : fprintf (stderr, "Type hash: size " HOST_SIZE_T_PRINT_DEC ", "
6521 : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6522 0 : (fmt_size_t) type_hash_table->size (),
6523 0 : (fmt_size_t) type_hash_table->elements (),
6524 : type_hash_table->collisions ());
6525 0 : }
6526 :
6527 : /* Given two lists of types
6528 : (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6529 : return 1 if the lists contain the same types in the same order.
6530 : Also, the TREE_PURPOSEs must match. */
6531 :
6532 : bool
6533 260140892 : type_list_equal (const_tree l1, const_tree l2)
6534 : {
6535 260140892 : const_tree t1, t2;
6536 :
6537 978072431 : for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6538 745946694 : if (TREE_VALUE (t1) != TREE_VALUE (t2)
6539 745946694 : || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6540 28017009 : && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6541 1887 : && (TREE_TYPE (TREE_PURPOSE (t1))
6542 1887 : == TREE_TYPE (TREE_PURPOSE (t2))))))
6543 : return false;
6544 :
6545 232125737 : return t1 == t2;
6546 : }
6547 :
6548 : /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6549 : given by TYPE. If the argument list accepts variable arguments,
6550 : then this function counts only the ordinary arguments. */
6551 :
6552 : int
6553 81811852 : type_num_arguments (const_tree fntype)
6554 : {
6555 81811852 : int i = 0;
6556 :
6557 318385309 : for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
6558 : /* If the function does not take a variable number of arguments,
6559 : the last element in the list will have type `void'. */
6560 299296017 : if (VOID_TYPE_P (TREE_VALUE (t)))
6561 : break;
6562 : else
6563 236573457 : ++i;
6564 :
6565 81811852 : return i;
6566 : }
6567 :
6568 : /* Return the type of the function TYPE's argument ARGNO if known.
6569 : For vararg function's where ARGNO refers to one of the variadic
6570 : arguments return null. Otherwise, return a void_type_node for
6571 : out-of-bounds ARGNO. */
6572 :
6573 : tree
6574 80732543 : type_argument_type (const_tree fntype, unsigned argno)
6575 : {
6576 : /* Treat zero the same as an out-of-bounds argument number. */
6577 80732543 : if (!argno)
6578 0 : return void_type_node;
6579 :
6580 80732543 : function_args_iterator iter;
6581 :
6582 80732543 : tree argtype;
6583 80732543 : unsigned i = 1;
6584 173726447 : FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
6585 : {
6586 : /* A vararg function's argument list ends in a null. Otherwise,
6587 : an ordinary function's argument list ends with void. Return
6588 : null if ARGNO refers to a vararg argument, void_type_node if
6589 : it's out of bounds, and the formal argument type otherwise. */
6590 167997700 : if (!argtype)
6591 : break;
6592 :
6593 167997700 : if (i == argno || VOID_TYPE_P (argtype))
6594 : return argtype;
6595 :
6596 92993904 : ++i;
6597 : }
6598 :
6599 : return NULL_TREE;
6600 : }
6601 :
6602 : /* True if integer constants T1 and T2
6603 : represent the same constant value. */
6604 :
6605 : bool
6606 1335850826 : tree_int_cst_equal (const_tree t1, const_tree t2)
6607 : {
6608 1335850826 : if (t1 == t2)
6609 : return true;
6610 :
6611 675910478 : if (t1 == 0 || t2 == 0)
6612 : return false;
6613 :
6614 675493372 : STRIP_ANY_LOCATION_WRAPPER (t1);
6615 675493372 : STRIP_ANY_LOCATION_WRAPPER (t2);
6616 :
6617 675493372 : if (TREE_CODE (t1) == INTEGER_CST
6618 671344117 : && TREE_CODE (t2) == INTEGER_CST
6619 1346837489 : && wi::to_widest (t1) == wi::to_widest (t2))
6620 20527496 : return true;
6621 :
6622 : return false;
6623 : }
6624 :
6625 : /* Return true if T is an INTEGER_CST whose numerical value (extended
6626 : according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
6627 :
6628 : bool
6629 2400561847 : tree_fits_shwi_p (const_tree t)
6630 : {
6631 2400561847 : return (t != NULL_TREE
6632 2400561756 : && TREE_CODE (t) == INTEGER_CST
6633 4798430809 : && wi::fits_shwi_p (wi::to_widest (t)));
6634 : }
6635 :
6636 : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6637 : value (extended according to TYPE_UNSIGNED) fits in a poly_int64. */
6638 :
6639 : bool
6640 1016792822 : tree_fits_poly_int64_p (const_tree t)
6641 : {
6642 1016792822 : if (t == NULL_TREE)
6643 : return false;
6644 978593127 : if (POLY_INT_CST_P (t))
6645 : {
6646 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6647 : if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t, i))))
6648 : return false;
6649 : return true;
6650 : }
6651 978593127 : return (TREE_CODE (t) == INTEGER_CST
6652 1957292550 : && wi::fits_shwi_p (wi::to_widest (t)));
6653 : }
6654 :
6655 : /* Return true if T is an INTEGER_CST whose numerical value (extended
6656 : according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
6657 :
6658 : bool
6659 4200321454 : tree_fits_uhwi_p (const_tree t)
6660 : {
6661 4200321454 : return (t != NULL_TREE
6662 4199709001 : && TREE_CODE (t) == INTEGER_CST
6663 8394678714 : && wi::fits_uhwi_p (wi::to_widest (t)));
6664 : }
6665 :
6666 : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6667 : value (extended according to TYPE_UNSIGNED) fits in a poly_uint64. */
6668 :
6669 : bool
6670 1095433999 : tree_fits_poly_uint64_p (const_tree t)
6671 : {
6672 1095433999 : if (t == NULL_TREE)
6673 : return false;
6674 1095074357 : if (POLY_INT_CST_P (t))
6675 : {
6676 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6677 : if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t, i))))
6678 : return false;
6679 : return true;
6680 : }
6681 1095074357 : return (TREE_CODE (t) == INTEGER_CST
6682 2190150125 : && wi::fits_uhwi_p (wi::to_widest (t)));
6683 : }
6684 :
6685 : /* Return true if T is an INTEGER_CST whose numerical value (extended according
6686 : to TYPE_UNSIGNED) fits in a sanitize_code_type (uint64_t). */
6687 :
6688 : bool
6689 90 : tree_fits_sanitize_code_type_p (const_tree t)
6690 : {
6691 90 : if (t == NULL_TREE)
6692 : return false;
6693 90 : return (TREE_CODE (t) == INTEGER_CST
6694 180 : && wi::fits_uhwi_p (wi::to_widest (t)));
6695 : }
6696 :
6697 : /* T is an INTEGER_CST whose numerical value (extended according to
6698 : TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
6699 : HOST_WIDE_INT. */
6700 :
6701 : HOST_WIDE_INT
6702 1421129682 : tree_to_shwi (const_tree t)
6703 : {
6704 1421129682 : gcc_assert (tree_fits_shwi_p (t));
6705 1421129682 : return TREE_INT_CST_LOW (t);
6706 : }
6707 :
6708 : /* T is an INTEGER_CST whose numerical value (extended according to
6709 : TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
6710 : HOST_WIDE_INT. */
6711 :
6712 : unsigned HOST_WIDE_INT
6713 1029295087 : tree_to_uhwi (const_tree t)
6714 : {
6715 1029295087 : gcc_assert (tree_fits_uhwi_p (t));
6716 1029295087 : return TREE_INT_CST_LOW (t);
6717 : }
6718 :
6719 : /* T is an INTEGER_CST whose numerical value (extended according to
6720 : TYPE_UNSIGNED) fits in a sanitize_code_type. Return that
6721 : sanitize_code_type. */
6722 :
6723 : sanitize_code_type
6724 90 : tree_to_sanitize_code_type (const_tree t)
6725 : {
6726 90 : gcc_assert (tree_fits_sanitize_code_type_p (t));
6727 90 : return TREE_INT_CST_LOW (t);
6728 : }
6729 :
6730 : /* Return the most significant (sign) bit of T. */
6731 :
6732 : int
6733 46157976 : tree_int_cst_sign_bit (const_tree t)
6734 : {
6735 46157976 : unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
6736 :
6737 46157976 : return wi::extract_uhwi (wi::to_wide (t), bitno, 1);
6738 : }
6739 :
6740 : /* Return an indication of the sign of the integer constant T.
6741 : The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6742 : Note that -1 will never be returned if T's type is unsigned. */
6743 :
6744 : int
6745 1913627440 : tree_int_cst_sgn (const_tree t)
6746 : {
6747 1913627440 : if (wi::to_wide (t) == 0)
6748 : return 0;
6749 1778705652 : else if (TYPE_UNSIGNED (TREE_TYPE (t)))
6750 : return 1;
6751 84811878 : else if (wi::neg_p (wi::to_wide (t)))
6752 : return -1;
6753 : else
6754 81152098 : return 1;
6755 : }
6756 :
6757 : /* Return the minimum number of bits needed to represent VALUE in a
6758 : signed or unsigned type, UNSIGNEDP says which. */
6759 :
6760 : unsigned int
6761 3751080 : tree_int_cst_min_precision (tree value, signop sgn)
6762 : {
6763 : /* If the value is negative, compute its negative minus 1. The latter
6764 : adjustment is because the absolute value of the largest negative value
6765 : is one larger than the largest positive value. This is equivalent to
6766 : a bit-wise negation, so use that operation instead. */
6767 :
6768 3751080 : if (tree_int_cst_sgn (value) < 0)
6769 107168 : value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
6770 :
6771 : /* Return the number of bits needed, taking into account the fact
6772 : that we need one more bit for a signed than unsigned type.
6773 : If value is 0 or -1, the minimum precision is 1 no matter
6774 : whether unsignedp is true or false. */
6775 :
6776 3751080 : if (integer_zerop (value))
6777 : return 1;
6778 : else
6779 5389489 : return tree_floor_log2 (value) + 1 + (sgn == SIGNED ? 1 : 0) ;
6780 : }
6781 :
6782 : /* Return truthvalue of whether T1 is the same tree structure as T2.
6783 : Return 1 if they are the same.
6784 : Return 0 if they are understandably different.
6785 : Return -1 if either contains tree structure not understood by
6786 : this function. */
6787 :
6788 : int
6789 209197162 : simple_cst_equal (const_tree t1, const_tree t2)
6790 : {
6791 213001592 : enum tree_code code1, code2;
6792 213001592 : int cmp;
6793 213001592 : int i;
6794 :
6795 213001592 : if (t1 == t2)
6796 : return 1;
6797 136441347 : if (t1 == 0 || t2 == 0)
6798 : return 0;
6799 :
6800 : /* For location wrappers to be the same, they must be at the same
6801 : source location (and wrap the same thing). */
6802 127717784 : if (location_wrapper_p (t1) && location_wrapper_p (t2))
6803 : {
6804 13448432 : if (EXPR_LOCATION (t1) != EXPR_LOCATION (t2))
6805 : return 0;
6806 738 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6807 : }
6808 :
6809 114269352 : code1 = TREE_CODE (t1);
6810 114269352 : code2 = TREE_CODE (t2);
6811 :
6812 114269352 : if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
6813 : {
6814 3791715 : if (CONVERT_EXPR_CODE_P (code2)
6815 3791001 : || code2 == NON_LVALUE_EXPR)
6816 714 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6817 : else
6818 3791001 : return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
6819 : }
6820 :
6821 110477637 : else if (CONVERT_EXPR_CODE_P (code2)
6822 110477622 : || code2 == NON_LVALUE_EXPR)
6823 113 : return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
6824 :
6825 110477524 : if (code1 != code2)
6826 : return 0;
6827 :
6828 105978569 : switch (code1)
6829 : {
6830 96083725 : case INTEGER_CST:
6831 96083725 : return wi::to_widest (t1) == wi::to_widest (t2);
6832 :
6833 93 : case REAL_CST:
6834 93 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
6835 :
6836 0 : case FIXED_CST:
6837 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
6838 :
6839 3238068 : case STRING_CST:
6840 3238068 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
6841 3238068 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
6842 3718730 : TREE_STRING_LENGTH (t1)));
6843 :
6844 479 : case CONSTRUCTOR:
6845 479 : {
6846 479 : unsigned HOST_WIDE_INT idx;
6847 479 : vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1);
6848 479 : vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);
6849 :
6850 503 : if (vec_safe_length (v1) != vec_safe_length (v2))
6851 : return 0;
6852 :
6853 485 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
6854 : {
6855 12 : if ((*v1)[idx].index
6856 12 : && TREE_CODE ((*v1)[idx].index) == FIELD_DECL)
6857 : {
6858 9 : if ((*v1)[idx].index != (*v2)[idx].index)
6859 : return 0;
6860 : }
6861 : else
6862 : {
6863 3 : cmp = simple_cst_equal ((*v1)[idx].index, (*v2)[idx].index);
6864 3 : if (cmp <= 0)
6865 : return cmp;
6866 : }
6867 12 : cmp = simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value);
6868 12 : if (cmp <= 0)
6869 : return cmp;
6870 : }
6871 : return 1;
6872 : }
6873 :
6874 0 : case SAVE_EXPR:
6875 0 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6876 :
6877 208102 : case CALL_EXPR:
6878 208102 : cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
6879 208102 : if (cmp <= 0)
6880 : return cmp;
6881 85931 : if (call_expr_nargs (t1) != call_expr_nargs (t2))
6882 : return 0;
6883 85931 : {
6884 85931 : const_tree arg1, arg2;
6885 85931 : const_call_expr_arg_iterator iter1, iter2;
6886 171862 : for (arg1 = first_const_call_expr_arg (t1, &iter1),
6887 85931 : arg2 = first_const_call_expr_arg (t2, &iter2);
6888 85965 : arg1 && arg2;
6889 34 : arg1 = next_const_call_expr_arg (&iter1),
6890 34 : arg2 = next_const_call_expr_arg (&iter2))
6891 : {
6892 85905 : cmp = simple_cst_equal (arg1, arg2);
6893 85905 : if (cmp <= 0)
6894 : return cmp;
6895 : }
6896 60 : return arg1 == arg2;
6897 : }
6898 :
6899 11656 : case TARGET_EXPR:
6900 : /* Special case: if either target is an unallocated VAR_DECL,
6901 : it means that it's going to be unified with whatever the
6902 : TARGET_EXPR is really supposed to initialize, so treat it
6903 : as being equivalent to anything. */
6904 11656 : if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
6905 11656 : && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
6906 11656 : && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
6907 11656 : || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
6908 0 : && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
6909 0 : && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
6910 : cmp = 1;
6911 : else
6912 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6913 :
6914 0 : if (cmp <= 0)
6915 : return cmp;
6916 :
6917 11656 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
6918 :
6919 0 : case WITH_CLEANUP_EXPR:
6920 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6921 0 : if (cmp <= 0)
6922 : return cmp;
6923 :
6924 0 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
6925 :
6926 208 : case COMPONENT_REF:
6927 208 : if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
6928 208 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6929 :
6930 : return 0;
6931 :
6932 : case VAR_DECL:
6933 : case PARM_DECL:
6934 : case CONST_DECL:
6935 : case FUNCTION_DECL:
6936 : return 0;
6937 :
6938 6371650 : default:
6939 6371650 : if (POLY_INT_CST_P (t1))
6940 : /* A false return means maybe_ne rather than known_ne. */
6941 : return known_eq (poly_widest_int::from (poly_int_cst_value (t1),
6942 : TYPE_SIGN (TREE_TYPE (t1))),
6943 : poly_widest_int::from (poly_int_cst_value (t2),
6944 : TYPE_SIGN (TREE_TYPE (t2))));
6945 6371650 : break;
6946 : }
6947 :
6948 : /* This general rule works for most tree codes. All exceptions should be
6949 : handled above. If this is a language-specific tree code, we can't
6950 : trust what might be in the operand, so say we don't know
6951 : the situation. */
6952 6371650 : if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
6953 : return -1;
6954 :
6955 880778 : switch (TREE_CODE_CLASS (code1))
6956 : {
6957 : case tcc_unary:
6958 : case tcc_binary:
6959 : case tcc_comparison:
6960 : case tcc_expression:
6961 : case tcc_reference:
6962 : case tcc_statement:
6963 : cmp = 1;
6964 1172 : for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
6965 : {
6966 903 : cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
6967 903 : if (cmp <= 0)
6968 : return cmp;
6969 : }
6970 :
6971 : return cmp;
6972 :
6973 : default:
6974 : return -1;
6975 : }
6976 : }
6977 :
6978 : /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6979 : Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6980 : than U, respectively. */
6981 :
6982 : int
6983 1560728582 : compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
6984 : {
6985 1560728582 : if (tree_int_cst_sgn (t) < 0)
6986 : return -1;
6987 1560728301 : else if (!tree_fits_uhwi_p (t))
6988 : return 1;
6989 1560728276 : else if (TREE_INT_CST_LOW (t) == u)
6990 : return 0;
6991 1389934580 : else if (TREE_INT_CST_LOW (t) < u)
6992 : return -1;
6993 : else
6994 13927058 : return 1;
6995 : }
6996 :
6997 : /* Return true if SIZE represents a constant size that is in bounds of
6998 : what the middle-end and the backend accepts (covering not more than
6999 : half of the address-space).
7000 : When PERR is non-null, set *PERR on failure to the description of
7001 : why SIZE is not valid. */
7002 :
7003 : bool
7004 69472633 : valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */)
7005 : {
7006 69472633 : if (POLY_INT_CST_P (size))
7007 : {
7008 : if (TREE_OVERFLOW (size))
7009 : return false;
7010 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
7011 : if (!valid_constant_size_p (POLY_INT_CST_COEFF (size, i)))
7012 : return false;
7013 : return true;
7014 : }
7015 :
7016 69472633 : cst_size_error error;
7017 69472633 : if (!perr)
7018 63695520 : perr = &error;
7019 :
7020 69472633 : if (TREE_CODE (size) != INTEGER_CST)
7021 : {
7022 3 : *perr = cst_size_not_constant;
7023 3 : return false;
7024 : }
7025 :
7026 69472630 : if (TREE_OVERFLOW_P (size))
7027 : {
7028 60 : *perr = cst_size_overflow;
7029 60 : return false;
7030 : }
7031 :
7032 69472570 : if (tree_int_cst_sgn (size) < 0)
7033 : {
7034 413 : *perr = cst_size_negative;
7035 413 : return false;
7036 : }
7037 138944314 : if (!tree_fits_uhwi_p (size)
7038 138944314 : || (wi::to_widest (TYPE_MAX_VALUE (sizetype))
7039 138944314 : < wi::to_widest (size) * 2))
7040 : {
7041 624 : *perr = cst_size_too_big;
7042 624 : return false;
7043 : }
7044 :
7045 : return true;
7046 : }
7047 :
7048 : /* Return the precision of the type, or for a complex or vector type the
7049 : precision of the type of its elements. */
7050 :
7051 : unsigned int
7052 7697443253 : element_precision (const_tree type)
7053 : {
7054 7697443253 : if (!TYPE_P (type))
7055 6274175 : type = TREE_TYPE (type);
7056 7697443253 : enum tree_code code = TREE_CODE (type);
7057 7697443253 : if (code == COMPLEX_TYPE || code == VECTOR_TYPE)
7058 57710723 : type = TREE_TYPE (type);
7059 :
7060 7697443253 : return TYPE_PRECISION (type);
7061 : }
7062 :
7063 : /* Return true if CODE represents an associative tree code. Otherwise
7064 : return false. */
7065 : bool
7066 36710834 : associative_tree_code (enum tree_code code)
7067 : {
7068 36710834 : switch (code)
7069 : {
7070 : case BIT_IOR_EXPR:
7071 : case BIT_AND_EXPR:
7072 : case BIT_XOR_EXPR:
7073 : case PLUS_EXPR:
7074 : case MULT_EXPR:
7075 : case MIN_EXPR:
7076 : case MAX_EXPR:
7077 : return true;
7078 :
7079 25834636 : default:
7080 25834636 : break;
7081 : }
7082 25834636 : return false;
7083 : }
7084 :
7085 : /* Return true if CODE represents a commutative tree code. Otherwise
7086 : return false. */
7087 : bool
7088 1808061186 : commutative_tree_code (enum tree_code code)
7089 : {
7090 1808061186 : switch (code)
7091 : {
7092 : case PLUS_EXPR:
7093 : case MULT_EXPR:
7094 : case MULT_HIGHPART_EXPR:
7095 : case MIN_EXPR:
7096 : case MAX_EXPR:
7097 : case BIT_IOR_EXPR:
7098 : case BIT_XOR_EXPR:
7099 : case BIT_AND_EXPR:
7100 : case NE_EXPR:
7101 : case EQ_EXPR:
7102 : case UNORDERED_EXPR:
7103 : case ORDERED_EXPR:
7104 : case UNEQ_EXPR:
7105 : case LTGT_EXPR:
7106 : case TRUTH_AND_EXPR:
7107 : case TRUTH_XOR_EXPR:
7108 : case TRUTH_OR_EXPR:
7109 : case WIDEN_MULT_EXPR:
7110 : case VEC_WIDEN_MULT_HI_EXPR:
7111 : case VEC_WIDEN_MULT_LO_EXPR:
7112 : case VEC_WIDEN_MULT_EVEN_EXPR:
7113 : case VEC_WIDEN_MULT_ODD_EXPR:
7114 : return true;
7115 :
7116 970603541 : default:
7117 970603541 : break;
7118 : }
7119 970603541 : return false;
7120 : }
7121 :
7122 : /* Return true if CODE represents a ternary tree code for which the
7123 : first two operands are commutative. Otherwise return false. */
7124 : bool
7125 98959934 : commutative_ternary_tree_code (enum tree_code code)
7126 : {
7127 98959934 : switch (code)
7128 : {
7129 : case WIDEN_MULT_PLUS_EXPR:
7130 : case WIDEN_MULT_MINUS_EXPR:
7131 : case DOT_PROD_EXPR:
7132 : return true;
7133 :
7134 98950386 : default:
7135 98950386 : break;
7136 : }
7137 98950386 : return false;
7138 : }
7139 :
7140 : /* Returns true if CODE can overflow. */
7141 :
7142 : bool
7143 3667 : operation_can_overflow (enum tree_code code)
7144 : {
7145 3667 : switch (code)
7146 : {
7147 : case PLUS_EXPR:
7148 : case MINUS_EXPR:
7149 : case MULT_EXPR:
7150 : case LSHIFT_EXPR:
7151 : /* Can overflow in various ways. */
7152 : return true;
7153 : case TRUNC_DIV_EXPR:
7154 : case EXACT_DIV_EXPR:
7155 : case FLOOR_DIV_EXPR:
7156 : case CEIL_DIV_EXPR:
7157 : /* For INT_MIN / -1. */
7158 : return true;
7159 : case NEGATE_EXPR:
7160 : case ABS_EXPR:
7161 : /* For -INT_MIN. */
7162 : return true;
7163 571 : default:
7164 : /* These operators cannot overflow. */
7165 571 : return false;
7166 : }
7167 : }
7168 :
7169 : /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
7170 : ftrapv doesn't generate trapping insns for CODE. */
7171 :
7172 : bool
7173 259668 : operation_no_trapping_overflow (tree type, enum tree_code code)
7174 : {
7175 259668 : gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type));
7176 :
7177 : /* We don't generate instructions that trap on overflow for complex or vector
7178 : types. */
7179 259668 : if (!INTEGRAL_TYPE_P (type))
7180 : return true;
7181 :
7182 259668 : if (!TYPE_OVERFLOW_TRAPS (type))
7183 : return true;
7184 :
7185 264 : switch (code)
7186 : {
7187 : case PLUS_EXPR:
7188 : case MINUS_EXPR:
7189 : case MULT_EXPR:
7190 : case NEGATE_EXPR:
7191 : case ABS_EXPR:
7192 : /* These operators can overflow, and -ftrapv generates trapping code for
7193 : these. */
7194 : return false;
7195 : case TRUNC_DIV_EXPR:
7196 : case EXACT_DIV_EXPR:
7197 : case FLOOR_DIV_EXPR:
7198 : case CEIL_DIV_EXPR:
7199 : case LSHIFT_EXPR:
7200 : /* These operators can overflow, but -ftrapv does not generate trapping
7201 : code for these. */
7202 : return true;
7203 : default:
7204 : /* These operators cannot overflow. */
7205 : return true;
7206 : }
7207 : }
7208 :
7209 : /* Constructors for pointer, array and function types.
7210 : (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7211 : constructed by language-dependent code, not here.) */
7212 :
7213 : /* Construct, lay out and return the type of pointers to TO_TYPE with
7214 : mode MODE. If MODE is VOIDmode, a pointer mode for the address
7215 : space of TO_TYPE will be picked. If CAN_ALIAS_ALL is TRUE,
7216 : indicate this type can reference all of memory. If such a type has
7217 : already been constructed, reuse it. */
7218 :
7219 : tree
7220 2658630637 : build_pointer_type_for_mode (tree to_type, machine_mode mode,
7221 : bool can_alias_all)
7222 : {
7223 2658630637 : tree t;
7224 2658630637 : bool could_alias = can_alias_all;
7225 :
7226 2658630637 : if (to_type == error_mark_node)
7227 : return error_mark_node;
7228 :
7229 2658630631 : if (mode == VOIDmode)
7230 : {
7231 2527848857 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7232 2527848857 : mode = targetm.addr_space.pointer_mode (as);
7233 : }
7234 :
7235 : /* If the pointed-to type has the may_alias attribute set, force
7236 : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7237 2658630631 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7238 4503567 : can_alias_all = true;
7239 :
7240 : /* In some cases, languages will have things that aren't a POINTER_TYPE
7241 : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7242 : In that case, return that type without regard to the rest of our
7243 : operands.
7244 :
7245 : ??? This is a kludge, but consistent with the way this function has
7246 : always operated and there doesn't seem to be a good way to avoid this
7247 : at the moment. */
7248 2658630631 : if (TYPE_POINTER_TO (to_type) != 0
7249 2658630631 : && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
7250 50191 : return TYPE_POINTER_TO (to_type);
7251 :
7252 : /* First, if we already have a type for pointers to TO_TYPE and it's
7253 : the proper mode, use it. */
7254 2659312867 : for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
7255 2504691884 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7256 : return t;
7257 :
7258 154620983 : t = make_node (POINTER_TYPE);
7259 :
7260 154620983 : TREE_TYPE (t) = to_type;
7261 154620983 : SET_TYPE_MODE (t, mode);
7262 154620983 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7263 154620983 : TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
7264 154620983 : TYPE_POINTER_TO (to_type) = t;
7265 :
7266 : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7267 154620983 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7268 5360705 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7269 149260278 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7270 44678390 : TYPE_CANONICAL (t)
7271 89356780 : = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
7272 : mode, false);
7273 :
7274 : /* Lay out the type. This function has many callers that are concerned
7275 : with expression-construction, and this simplifies them all. */
7276 154620983 : layout_type (t);
7277 :
7278 154620983 : return t;
7279 : }
7280 :
7281 : /* By default build pointers in ptr_mode. */
7282 :
7283 : tree
7284 2527130958 : build_pointer_type (tree to_type)
7285 : {
7286 2527130958 : return build_pointer_type_for_mode (to_type, VOIDmode, false);
7287 : }
7288 :
7289 : /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7290 :
7291 : tree
7292 739902943 : build_reference_type_for_mode (tree to_type, machine_mode mode,
7293 : bool can_alias_all)
7294 : {
7295 739902943 : tree t;
7296 739902943 : bool could_alias = can_alias_all;
7297 :
7298 739902943 : if (to_type == error_mark_node)
7299 : return error_mark_node;
7300 :
7301 739902943 : if (mode == VOIDmode)
7302 : {
7303 584941040 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7304 584941040 : mode = targetm.addr_space.pointer_mode (as);
7305 : }
7306 :
7307 : /* If the pointed-to type has the may_alias attribute set, force
7308 : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7309 739902943 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7310 756020 : can_alias_all = true;
7311 :
7312 : /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7313 : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7314 : In that case, return that type without regard to the rest of our
7315 : operands.
7316 :
7317 : ??? This is a kludge, but consistent with the way this function has
7318 : always operated and there doesn't seem to be a good way to avoid this
7319 : at the moment. */
7320 739902943 : if (TYPE_REFERENCE_TO (to_type) != 0
7321 739902943 : && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
7322 0 : return TYPE_REFERENCE_TO (to_type);
7323 :
7324 : /* First, if we already have a type for pointers to TO_TYPE and it's
7325 : the proper mode, use it. */
7326 739902943 : for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
7327 645952793 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7328 : return t;
7329 :
7330 93950150 : t = make_node (REFERENCE_TYPE);
7331 :
7332 93950150 : TREE_TYPE (t) = to_type;
7333 93950150 : SET_TYPE_MODE (t, mode);
7334 93950150 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7335 93950150 : TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
7336 93950150 : TYPE_REFERENCE_TO (to_type) = t;
7337 :
7338 : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7339 93950150 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7340 5098716 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7341 88851434 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7342 52615943 : TYPE_CANONICAL (t)
7343 105231886 : = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
7344 : mode, false);
7345 :
7346 93950150 : layout_type (t);
7347 :
7348 93950150 : return t;
7349 : }
7350 :
7351 :
7352 : /* Build the node for the type of references-to-TO_TYPE by default
7353 : in ptr_mode. */
7354 :
7355 : tree
7356 27733322 : build_reference_type (tree to_type)
7357 : {
7358 27733322 : return build_reference_type_for_mode (to_type, VOIDmode, false);
7359 : }
7360 :
7361 : #define MAX_INT_CACHED_PREC \
7362 : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7363 : static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
7364 :
7365 : static void
7366 264319 : clear_nonstandard_integer_type_cache (void)
7367 : {
7368 34625789 : for (size_t i = 0 ; i < 2 * MAX_INT_CACHED_PREC + 2 ; i++)
7369 : {
7370 34361470 : nonstandard_integer_type_cache[i] = NULL;
7371 : }
7372 0 : }
7373 :
7374 : /* Builds a signed or unsigned integer type of precision PRECISION.
7375 : Used for C bitfields whose precision does not match that of
7376 : built-in target types. */
7377 : tree
7378 64245357 : build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
7379 : int unsignedp)
7380 : {
7381 64245357 : tree itype, ret;
7382 :
7383 64245357 : if (unsignedp)
7384 55352899 : unsignedp = MAX_INT_CACHED_PREC + 1;
7385 :
7386 64245357 : if (precision <= MAX_INT_CACHED_PREC)
7387 : {
7388 63882480 : itype = nonstandard_integer_type_cache[precision + unsignedp];
7389 63882480 : if (itype)
7390 : return itype;
7391 : }
7392 :
7393 1086740 : itype = make_node (INTEGER_TYPE);
7394 1086740 : TYPE_PRECISION (itype) = precision;
7395 :
7396 1086740 : if (unsignedp)
7397 713036 : fixup_unsigned_type (itype);
7398 : else
7399 373704 : fixup_signed_type (itype);
7400 :
7401 1086740 : inchash::hash hstate;
7402 1086740 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7403 1086740 : ret = type_hash_canon (hstate.end (), itype);
7404 1086740 : if (precision <= MAX_INT_CACHED_PREC)
7405 723863 : nonstandard_integer_type_cache[precision + unsignedp] = ret;
7406 :
7407 : return ret;
7408 : }
7409 :
7410 : #define MAX_BOOL_CACHED_PREC \
7411 : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7412 : static GTY(()) tree nonstandard_boolean_type_cache[MAX_BOOL_CACHED_PREC + 1];
7413 :
7414 : /* Builds a boolean type of precision PRECISION.
7415 : Used for boolean vectors to choose proper vector element size. */
7416 : tree
7417 2776459 : build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision)
7418 : {
7419 2776459 : tree type;
7420 :
7421 2776459 : if (precision <= MAX_BOOL_CACHED_PREC)
7422 : {
7423 2772409 : type = nonstandard_boolean_type_cache[precision];
7424 2772409 : if (type)
7425 : return type;
7426 : }
7427 :
7428 84152 : type = make_node (BOOLEAN_TYPE);
7429 84152 : TYPE_PRECISION (type) = precision;
7430 84152 : fixup_signed_type (type);
7431 :
7432 84152 : if (precision <= MAX_INT_CACHED_PREC)
7433 80102 : nonstandard_boolean_type_cache[precision] = type;
7434 :
7435 : return type;
7436 : }
7437 :
7438 : static GTY(()) vec<tree, va_gc> *bitint_type_cache;
7439 :
7440 : /* Builds a signed or unsigned _BitInt(PRECISION) type. */
7441 : tree
7442 76248 : build_bitint_type (unsigned HOST_WIDE_INT precision, int unsignedp)
7443 : {
7444 76248 : tree itype, ret;
7445 :
7446 76248 : gcc_checking_assert (precision >= 1);
7447 :
7448 76248 : if (unsignedp)
7449 37488 : unsignedp = MAX_INT_CACHED_PREC + 1;
7450 :
7451 76248 : if (bitint_type_cache == NULL)
7452 689 : vec_safe_grow_cleared (bitint_type_cache, 2 * MAX_INT_CACHED_PREC + 2);
7453 :
7454 76248 : if (precision <= MAX_INT_CACHED_PREC)
7455 : {
7456 17148 : itype = (*bitint_type_cache)[precision + unsignedp];
7457 17148 : if (itype)
7458 : return itype;
7459 : }
7460 :
7461 61029 : itype = make_node (BITINT_TYPE);
7462 61029 : TYPE_PRECISION (itype) = precision;
7463 :
7464 61029 : if (unsignedp)
7465 30542 : fixup_unsigned_type (itype);
7466 : else
7467 30487 : fixup_signed_type (itype);
7468 :
7469 61029 : hashval_t hash = type_hash_canon_hash (itype);
7470 61029 : ret = type_hash_canon (hash, itype);
7471 61029 : if (precision <= MAX_INT_CACHED_PREC)
7472 1929 : (*bitint_type_cache)[precision + unsignedp] = ret;
7473 :
7474 : return ret;
7475 : }
7476 :
7477 : /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7478 : or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7479 : is true, reuse such a type that has already been constructed. */
7480 :
7481 : static tree
7482 45306701 : build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
7483 : {
7484 45306701 : tree itype = make_node (INTEGER_TYPE);
7485 :
7486 45306701 : TREE_TYPE (itype) = type;
7487 :
7488 45306701 : TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
7489 45306701 : TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
7490 :
7491 45306701 : TYPE_PRECISION (itype) = TYPE_PRECISION (type);
7492 45306701 : SET_TYPE_MODE (itype, TYPE_MODE (type));
7493 45306701 : TYPE_SIZE (itype) = TYPE_SIZE (type);
7494 45306701 : TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
7495 45306701 : SET_TYPE_ALIGN (itype, TYPE_ALIGN (type));
7496 45306701 : TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
7497 45306701 : SET_TYPE_WARN_IF_NOT_ALIGN (itype, TYPE_WARN_IF_NOT_ALIGN (type));
7498 :
7499 45306701 : if (!shared)
7500 : return itype;
7501 :
7502 45306701 : if ((TYPE_MIN_VALUE (itype)
7503 45306701 : && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
7504 90612565 : || (TYPE_MAX_VALUE (itype)
7505 44749372 : && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
7506 : {
7507 : /* Since we cannot reliably merge this type, we need to compare it using
7508 : structural equality checks. */
7509 1213830 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
7510 1213830 : return itype;
7511 : }
7512 :
7513 44092871 : hashval_t hash = type_hash_canon_hash (itype);
7514 44092871 : itype = type_hash_canon (hash, itype);
7515 :
7516 44092871 : return itype;
7517 : }
7518 :
7519 : /* Wrapper around build_range_type_1 with SHARED set to true. */
7520 :
7521 : tree
7522 45306701 : build_range_type (tree type, tree lowval, tree highval)
7523 : {
7524 45306701 : return build_range_type_1 (type, lowval, highval, true);
7525 : }
7526 :
7527 : /* Wrapper around build_range_type_1 with SHARED set to false. */
7528 :
7529 : tree
7530 0 : build_nonshared_range_type (tree type, tree lowval, tree highval)
7531 : {
7532 0 : return build_range_type_1 (type, lowval, highval, false);
7533 : }
7534 :
7535 : /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7536 : MAXVAL should be the maximum value in the domain
7537 : (one less than the length of the array).
7538 :
7539 : The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7540 : We don't enforce this limit, that is up to caller (e.g. language front end).
7541 : The limit exists because the result is a signed type and we don't handle
7542 : sizes that use more than one HOST_WIDE_INT. */
7543 :
7544 : tree
7545 42344340 : build_index_type (tree maxval)
7546 : {
7547 42344340 : return build_range_type (sizetype, size_zero_node, maxval);
7548 : }
7549 :
7550 : /* Return true if the debug information for TYPE, a subtype, should be emitted
7551 : as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7552 : high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7553 : debug info and doesn't reflect the source code. */
7554 :
7555 : bool
7556 18 : subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
7557 : {
7558 18 : tree base_type = TREE_TYPE (type), low, high;
7559 :
7560 : /* Subrange types have a base type which is an integral type. */
7561 18 : if (!INTEGRAL_TYPE_P (base_type))
7562 : return false;
7563 :
7564 : /* Get the real bounds of the subtype. */
7565 18 : if (lang_hooks.types.get_subrange_bounds)
7566 0 : lang_hooks.types.get_subrange_bounds (type, &low, &high);
7567 : else
7568 : {
7569 18 : low = TYPE_MIN_VALUE (type);
7570 18 : high = TYPE_MAX_VALUE (type);
7571 : }
7572 :
7573 : /* If the type and its base type have the same representation and the same
7574 : name, then the type is not a subrange but a copy of the base type. */
7575 18 : if ((TREE_CODE (base_type) == INTEGER_TYPE
7576 18 : || TREE_CODE (base_type) == BOOLEAN_TYPE)
7577 18 : && int_size_in_bytes (type) == int_size_in_bytes (base_type)
7578 18 : && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
7579 0 : && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))
7580 18 : && TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (base_type))
7581 : return false;
7582 :
7583 18 : if (lowval)
7584 18 : *lowval = low;
7585 18 : if (highval)
7586 18 : *highval = high;
7587 : return true;
7588 : }
7589 :
7590 : /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7591 : and number of elements specified by the range of values of INDEX_TYPE.
7592 : If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
7593 : If SHARED is true, reuse such a type that has already been constructed.
7594 : If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type. */
7595 :
7596 : tree
7597 73672060 : build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
7598 : bool shared, bool set_canonical)
7599 : {
7600 73672060 : tree t;
7601 :
7602 73672060 : if (TREE_CODE (elt_type) == FUNCTION_TYPE)
7603 : {
7604 0 : error ("arrays of functions are not meaningful");
7605 0 : elt_type = integer_type_node;
7606 : }
7607 :
7608 73672060 : t = make_node (ARRAY_TYPE);
7609 73672060 : TREE_TYPE (t) = elt_type;
7610 73672060 : TYPE_DOMAIN (t) = index_type;
7611 73672060 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
7612 73672060 : TYPE_TYPELESS_STORAGE (t) = typeless_storage;
7613 :
7614 : /* Set TYPE_STRUCTURAL_EQUALITY_P. */
7615 73672060 : if (set_canonical
7616 73672060 : && (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7617 73632855 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7618 73350614 : || in_lto_p))
7619 394115 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7620 :
7621 73672060 : layout_type (t);
7622 :
7623 73672060 : if (shared)
7624 : {
7625 73672031 : hashval_t hash = type_hash_canon_hash (t);
7626 73672031 : tree probe_type = t;
7627 73672031 : t = type_hash_canon (hash, t);
7628 73672031 : if (t != probe_type)
7629 : return t;
7630 : }
7631 :
7632 11333022 : if (TYPE_CANONICAL (t) == t && set_canonical)
7633 : {
7634 10988087 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7635 10988087 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7636 21976174 : || in_lto_p)
7637 0 : gcc_unreachable ();
7638 10988087 : else if (TYPE_CANONICAL (elt_type) != elt_type
7639 10988087 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
7640 106450 : TYPE_CANONICAL (t)
7641 308872 : = build_array_type_1 (TYPE_CANONICAL (elt_type),
7642 : index_type
7643 95972 : ? TYPE_CANONICAL (index_type) : NULL_TREE,
7644 : typeless_storage, shared, set_canonical);
7645 : }
7646 :
7647 : return t;
7648 : }
7649 :
7650 : /* Wrapper around build_array_type_1 with SHARED set to true. */
7651 :
7652 : tree
7653 73565581 : build_array_type (tree elt_type, tree index_type, bool typeless_storage)
7654 : {
7655 73565581 : return
7656 73565581 : build_array_type_1 (elt_type, index_type, typeless_storage, true, true);
7657 : }
7658 :
7659 : /* Wrapper around build_array_type_1 with SHARED set to false. */
7660 :
7661 : tree
7662 0 : build_nonshared_array_type (tree elt_type, tree index_type)
7663 : {
7664 0 : return build_array_type_1 (elt_type, index_type, false, false, true);
7665 : }
7666 :
7667 : /* Return a representation of ELT_TYPE[NELTS], using indices of type
7668 : sizetype. */
7669 :
7670 : tree
7671 1710674 : build_array_type_nelts (tree elt_type, poly_uint64 nelts)
7672 : {
7673 1710674 : return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
7674 : }
7675 :
7676 : /* Computes the canonical argument types from the argument type list
7677 : ARGTYPES.
7678 :
7679 : Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7680 : on entry to this function, or if any of the ARGTYPES are
7681 : structural.
7682 :
7683 : Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7684 : true on entry to this function, or if any of the ARGTYPES are
7685 : non-canonical.
7686 :
7687 : Returns a canonical argument list, which may be ARGTYPES when the
7688 : canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7689 : true) or would not differ from ARGTYPES. */
7690 :
7691 : static tree
7692 1012557723 : maybe_canonicalize_argtypes (tree argtypes,
7693 : bool *any_structural_p,
7694 : bool *any_noncanonical_p)
7695 : {
7696 1012557723 : tree arg;
7697 1012557723 : bool any_noncanonical_argtypes_p = false;
7698 :
7699 3488711373 : for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
7700 : {
7701 2476153650 : if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
7702 : /* Fail gracefully by stating that the type is structural. */
7703 4827 : *any_structural_p = true;
7704 2476148823 : else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
7705 34859669 : *any_structural_p = true;
7706 2441289154 : else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
7707 2441289154 : || TREE_PURPOSE (arg))
7708 : /* If the argument has a default argument, we consider it
7709 : non-canonical even though the type itself is canonical.
7710 : That way, different variants of function and method types
7711 : with default arguments will all point to the variant with
7712 : no defaults as their canonical type. */
7713 : any_noncanonical_argtypes_p = true;
7714 : }
7715 :
7716 1012557723 : if (*any_structural_p)
7717 : return argtypes;
7718 :
7719 916359009 : if (any_noncanonical_argtypes_p)
7720 : {
7721 : /* Build the canonical list of argument types. */
7722 : tree canon_argtypes = NULL_TREE;
7723 : bool is_void = false;
7724 :
7725 901790312 : for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
7726 : {
7727 692107907 : if (arg == void_list_node)
7728 : is_void = true;
7729 : else
7730 966868524 : canon_argtypes = tree_cons (NULL_TREE,
7731 483434262 : TYPE_CANONICAL (TREE_VALUE (arg)),
7732 : canon_argtypes);
7733 : }
7734 :
7735 209682405 : canon_argtypes = nreverse (canon_argtypes);
7736 209682405 : if (is_void)
7737 208673645 : canon_argtypes = chainon (canon_argtypes, void_list_node);
7738 :
7739 : /* There is a non-canonical type. */
7740 209682405 : *any_noncanonical_p = true;
7741 209682405 : return canon_argtypes;
7742 : }
7743 :
7744 : /* The canonical argument types are the same as ARGTYPES. */
7745 : return argtypes;
7746 : }
7747 :
7748 : /* Construct, lay out and return
7749 : the type of functions returning type VALUE_TYPE
7750 : given arguments of types ARG_TYPES.
7751 : ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7752 : are data type nodes for the arguments of the function.
7753 : NO_NAMED_ARGS_STDARG_P is true if this is a prototyped
7754 : variable-arguments function with (...) prototype (no named arguments).
7755 : If such a type has already been constructed, reuse it. */
7756 :
7757 : tree
7758 666631854 : build_function_type (tree value_type, tree arg_types,
7759 : bool no_named_args_stdarg_p)
7760 : {
7761 666631854 : tree t;
7762 666631854 : inchash::hash hstate;
7763 666631854 : bool any_structural_p, any_noncanonical_p;
7764 666631854 : tree canon_argtypes;
7765 :
7766 666631854 : gcc_assert (arg_types != error_mark_node);
7767 :
7768 666631854 : if (TREE_CODE (value_type) == FUNCTION_TYPE)
7769 : {
7770 0 : error ("function return type cannot be function");
7771 0 : value_type = integer_type_node;
7772 : }
7773 :
7774 : /* Make a node of the sort we want. */
7775 666631854 : t = make_node (FUNCTION_TYPE);
7776 666631854 : TREE_TYPE (t) = value_type;
7777 666631854 : TYPE_ARG_TYPES (t) = arg_types;
7778 666631854 : if (no_named_args_stdarg_p)
7779 : {
7780 1055832 : gcc_assert (arg_types == NULL_TREE);
7781 1055832 : TYPE_NO_NAMED_ARGS_STDARG_P (t) = 1;
7782 : }
7783 :
7784 : /* Set up the canonical type. */
7785 666631854 : any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
7786 666631854 : any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
7787 666631854 : canon_argtypes = maybe_canonicalize_argtypes (arg_types,
7788 : &any_structural_p,
7789 : &any_noncanonical_p);
7790 : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7791 666631854 : if (any_structural_p)
7792 69457374 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7793 :
7794 : /* If we already have such a type, use the old one. */
7795 666631854 : hashval_t hash = type_hash_canon_hash (t);
7796 666631854 : tree probe_type = t;
7797 666631854 : t = type_hash_canon (hash, t);
7798 666631854 : if (t != probe_type)
7799 : return t;
7800 :
7801 427551782 : if (any_structural_p)
7802 55804053 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7803 371747729 : else if (any_noncanonical_p)
7804 89616846 : TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
7805 : canon_argtypes,
7806 : no_named_args_stdarg_p);
7807 :
7808 427551782 : if (!COMPLETE_TYPE_P (t))
7809 0 : layout_type (t);
7810 : return t;
7811 : }
7812 :
7813 : /* Build a function type. The RETURN_TYPE is the type returned by the
7814 : function. If VAARGS is set, no void_type_node is appended to the
7815 : list. ARGP must be always be terminated be a NULL_TREE. */
7816 :
7817 : static tree
7818 15490602 : build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
7819 : {
7820 15490602 : tree t, args, last;
7821 :
7822 15490602 : t = va_arg (argp, tree);
7823 65347689 : for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
7824 34366485 : args = tree_cons (NULL_TREE, t, args);
7825 :
7826 15490602 : if (vaargs)
7827 : {
7828 954172 : last = args;
7829 954172 : if (args != NULL_TREE)
7830 820784 : args = nreverse (args);
7831 954172 : gcc_assert (last != void_list_node);
7832 : }
7833 14536430 : else if (args == NULL_TREE)
7834 1240938 : args = void_list_node;
7835 : else
7836 : {
7837 13295492 : last = args;
7838 13295492 : args = nreverse (args);
7839 13295492 : TREE_CHAIN (last) = void_list_node;
7840 : }
7841 15490602 : args = build_function_type (return_type, args, vaargs && args == NULL_TREE);
7842 :
7843 15490602 : return args;
7844 : }
7845 :
7846 : /* Build a function type. The RETURN_TYPE is the type returned by the
7847 : function. If additional arguments are provided, they are
7848 : additional argument types. The list of argument types must always
7849 : be terminated by NULL_TREE. */
7850 :
7851 : tree
7852 14536430 : build_function_type_list (tree return_type, ...)
7853 : {
7854 14536430 : tree args;
7855 14536430 : va_list p;
7856 :
7857 14536430 : va_start (p, return_type);
7858 14536430 : args = build_function_type_list_1 (false, return_type, p);
7859 14536430 : va_end (p);
7860 14536430 : return args;
7861 : }
7862 :
7863 : /* Build a variable argument function type. The RETURN_TYPE is the
7864 : type returned by the function. If additional arguments are provided,
7865 : they are additional argument types. The list of argument types must
7866 : always be terminated by NULL_TREE. */
7867 :
7868 : tree
7869 954172 : build_varargs_function_type_list (tree return_type, ...)
7870 : {
7871 954172 : tree args;
7872 954172 : va_list p;
7873 :
7874 954172 : va_start (p, return_type);
7875 954172 : args = build_function_type_list_1 (true, return_type, p);
7876 954172 : va_end (p);
7877 :
7878 954172 : return args;
7879 : }
7880 :
7881 : /* Build a function type. RETURN_TYPE is the type returned by the
7882 : function; VAARGS indicates whether the function takes varargs. The
7883 : function takes N named arguments, the types of which are provided in
7884 : ARG_TYPES. */
7885 :
7886 : static tree
7887 120128266 : build_function_type_array_1 (bool vaargs, tree return_type, int n,
7888 : tree *arg_types)
7889 : {
7890 120128266 : int i;
7891 120128266 : tree t = vaargs ? NULL_TREE : void_list_node;
7892 :
7893 393055952 : for (i = n - 1; i >= 0; i--)
7894 272927686 : t = tree_cons (NULL_TREE, arg_types[i], t);
7895 :
7896 120128266 : return build_function_type (return_type, t, vaargs && n == 0);
7897 : }
7898 :
7899 : /* Build a function type. RETURN_TYPE is the type returned by the
7900 : function. The function takes N named arguments, the types of which
7901 : are provided in ARG_TYPES. */
7902 :
7903 : tree
7904 113729468 : build_function_type_array (tree return_type, int n, tree *arg_types)
7905 : {
7906 113729468 : return build_function_type_array_1 (false, return_type, n, arg_types);
7907 : }
7908 :
7909 : /* Build a variable argument function type. RETURN_TYPE is the type
7910 : returned by the function. The function takes N named arguments, the
7911 : types of which are provided in ARG_TYPES. */
7912 :
7913 : tree
7914 6398798 : build_varargs_function_type_array (tree return_type, int n, tree *arg_types)
7915 : {
7916 6398798 : return build_function_type_array_1 (true, return_type, n, arg_types);
7917 : }
7918 :
7919 : /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7920 : and ARGTYPES (a TREE_LIST) are the return type and arguments types
7921 : for the method. An implicit additional parameter (of type
7922 : pointer-to-BASETYPE) is added to the ARGTYPES. */
7923 :
7924 : tree
7925 345925869 : build_method_type_directly (tree basetype,
7926 : tree rettype,
7927 : tree argtypes)
7928 : {
7929 345925869 : tree t;
7930 345925869 : tree ptype;
7931 345925869 : bool any_structural_p, any_noncanonical_p;
7932 345925869 : tree canon_argtypes;
7933 :
7934 : /* Make a node of the sort we want. */
7935 345925869 : t = make_node (METHOD_TYPE);
7936 :
7937 345925869 : TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7938 345925869 : TREE_TYPE (t) = rettype;
7939 345925869 : ptype = build_pointer_type (basetype);
7940 :
7941 : /* The actual arglist for this function includes a "hidden" argument
7942 : which is "this". Put it into the list of argument types. */
7943 345925869 : argtypes = tree_cons (NULL_TREE, ptype, argtypes);
7944 345925869 : TYPE_ARG_TYPES (t) = argtypes;
7945 :
7946 : /* Set up the canonical type. */
7947 345925869 : any_structural_p
7948 345925869 : = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7949 345925869 : || TYPE_STRUCTURAL_EQUALITY_P (rettype));
7950 345925869 : any_noncanonical_p
7951 345925869 : = (TYPE_CANONICAL (basetype) != basetype
7952 345925869 : || TYPE_CANONICAL (rettype) != rettype);
7953 345925869 : canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
7954 : &any_structural_p,
7955 : &any_noncanonical_p);
7956 :
7957 : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7958 345925869 : if (any_structural_p)
7959 26741340 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7960 :
7961 : /* If we already have such a type, use the old one. */
7962 345925869 : hashval_t hash = type_hash_canon_hash (t);
7963 345925869 : tree probe_type = t;
7964 345925869 : t = type_hash_canon (hash, t);
7965 345925869 : if (t != probe_type)
7966 : return t;
7967 :
7968 266684410 : if (any_structural_p)
7969 22568083 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7970 244116327 : else if (any_noncanonical_p)
7971 89859045 : TYPE_CANONICAL (t)
7972 179718090 : = build_method_type_directly (TYPE_CANONICAL (basetype),
7973 89859045 : TYPE_CANONICAL (rettype),
7974 : canon_argtypes);
7975 266684410 : if (!COMPLETE_TYPE_P (t))
7976 0 : layout_type (t);
7977 :
7978 : return t;
7979 : }
7980 :
7981 : /* Construct, lay out and return the type of methods belonging to class
7982 : BASETYPE and whose arguments and values are described by TYPE.
7983 : If that type exists already, reuse it.
7984 : TYPE must be a FUNCTION_TYPE node. */
7985 :
7986 : tree
7987 0 : build_method_type (tree basetype, tree type)
7988 : {
7989 0 : gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
7990 :
7991 0 : return build_method_type_directly (basetype,
7992 0 : TREE_TYPE (type),
7993 0 : TYPE_ARG_TYPES (type));
7994 : }
7995 :
7996 : /* Construct, lay out and return the type of offsets to a value
7997 : of type TYPE, within an object of type BASETYPE.
7998 : If a suitable offset type exists already, reuse it. */
7999 :
8000 : tree
8001 995476 : build_offset_type (tree basetype, tree type)
8002 : {
8003 995476 : tree t;
8004 :
8005 : /* Make a node of the sort we want. */
8006 995476 : t = make_node (OFFSET_TYPE);
8007 :
8008 995476 : TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
8009 995476 : TREE_TYPE (t) = type;
8010 995476 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
8011 995476 : || TYPE_STRUCTURAL_EQUALITY_P (type))
8012 4 : SET_TYPE_STRUCTURAL_EQUALITY (t);
8013 :
8014 : /* If we already have such a type, use the old one. */
8015 995476 : hashval_t hash = type_hash_canon_hash (t);
8016 995476 : tree probe_type = t;
8017 995476 : t = type_hash_canon (hash, t);
8018 995476 : if (t != probe_type)
8019 : return t;
8020 :
8021 241295 : if (!COMPLETE_TYPE_P (t))
8022 0 : layout_type (t);
8023 :
8024 241295 : if (TYPE_CANONICAL (t) == t)
8025 : {
8026 241291 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
8027 241291 : || TYPE_STRUCTURAL_EQUALITY_P (type))
8028 0 : gcc_unreachable ();
8029 241291 : else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
8030 241291 : || TYPE_CANONICAL (type) != type)
8031 138311 : TYPE_CANONICAL (t)
8032 276622 : = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
8033 138311 : TYPE_CANONICAL (type));
8034 : }
8035 :
8036 : return t;
8037 : }
8038 :
8039 : /* Create a complex type whose components are COMPONENT_TYPE.
8040 :
8041 : If NAMED is true, the type is given a TYPE_NAME. We do not always
8042 : do so because this creates a DECL node and thus make the DECL_UIDs
8043 : dependent on the type canonicalization hashtable, which is GC-ed,
8044 : so the DECL_UIDs would not be stable wrt garbage collection. */
8045 :
8046 : tree
8047 5428738 : build_complex_type (tree component_type, bool named)
8048 : {
8049 5428738 : gcc_assert (INTEGRAL_TYPE_P (component_type)
8050 : || SCALAR_FLOAT_TYPE_P (component_type)
8051 : || FIXED_POINT_TYPE_P (component_type));
8052 :
8053 : /* Make a node of the sort we want. */
8054 5428738 : tree probe = make_node (COMPLEX_TYPE);
8055 :
8056 5428738 : TREE_TYPE (probe) = TYPE_MAIN_VARIANT (component_type);
8057 5428738 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (probe)))
8058 0 : SET_TYPE_STRUCTURAL_EQUALITY (probe);
8059 :
8060 : /* If we already have such a type, use the old one. */
8061 5428738 : hashval_t hash = type_hash_canon_hash (probe);
8062 5428738 : tree t = type_hash_canon (hash, probe);
8063 :
8064 5428738 : if (t == probe)
8065 : {
8066 : /* We created a new type. The hash insertion will have laid
8067 : out the type. We need to check the canonicalization and
8068 : maybe set the name. */
8069 3203630 : gcc_checking_assert (COMPLETE_TYPE_P (t)
8070 : && !TYPE_NAME (t));
8071 :
8072 3203630 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))
8073 : ;
8074 3203630 : else if (TYPE_CANONICAL (TREE_TYPE (t)) != TREE_TYPE (t))
8075 105 : TYPE_CANONICAL (t)
8076 210 : = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named);
8077 :
8078 : /* We need to create a name, since complex is a fundamental type. */
8079 3203630 : if (named)
8080 : {
8081 1175576 : const char *name = NULL;
8082 :
8083 1175576 : if (TREE_TYPE (t) == char_type_node)
8084 : name = "complex char";
8085 1175576 : else if (TREE_TYPE (t) == signed_char_type_node)
8086 : name = "complex signed char";
8087 1175576 : else if (TREE_TYPE (t) == unsigned_char_type_node)
8088 : name = "complex unsigned char";
8089 1175576 : else if (TREE_TYPE (t) == short_integer_type_node)
8090 : name = "complex short int";
8091 1175576 : else if (TREE_TYPE (t) == short_unsigned_type_node)
8092 : name = "complex short unsigned int";
8093 1175576 : else if (TREE_TYPE (t) == integer_type_node)
8094 : name = "complex int";
8095 881682 : else if (TREE_TYPE (t) == unsigned_type_node)
8096 : name = "complex unsigned int";
8097 881682 : else if (TREE_TYPE (t) == long_integer_type_node)
8098 : name = "complex long int";
8099 881682 : else if (TREE_TYPE (t) == long_unsigned_type_node)
8100 : name = "complex long unsigned int";
8101 881682 : else if (TREE_TYPE (t) == long_long_integer_type_node)
8102 : name = "complex long long int";
8103 881682 : else if (TREE_TYPE (t) == long_long_unsigned_type_node)
8104 : name = "complex long long unsigned int";
8105 :
8106 : if (name != NULL)
8107 293894 : TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
8108 : get_identifier (name), t);
8109 : }
8110 : }
8111 :
8112 5428738 : return build_qualified_type (t, TYPE_QUALS (component_type));
8113 : }
8114 :
8115 : /* If TYPE is a real or complex floating-point type and the target
8116 : does not directly support arithmetic on TYPE then return the wider
8117 : type to be used for arithmetic on TYPE. Otherwise, return
8118 : NULL_TREE. */
8119 :
8120 : tree
8121 90967874 : excess_precision_type (tree type)
8122 : {
8123 : /* The target can give two different responses to the question of
8124 : which excess precision mode it would like depending on whether we
8125 : are in -fexcess-precision=standard or -fexcess-precision=fast. */
8126 :
8127 3542737 : enum excess_precision_type requested_type
8128 90967874 : = (flag_excess_precision == EXCESS_PRECISION_FAST
8129 90967874 : ? EXCESS_PRECISION_TYPE_FAST
8130 : : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
8131 3543463 : ? EXCESS_PRECISION_TYPE_FLOAT16 : EXCESS_PRECISION_TYPE_STANDARD));
8132 :
8133 90967874 : enum flt_eval_method target_flt_eval_method
8134 90967874 : = targetm.c.excess_precision (requested_type);
8135 :
8136 : /* The target should not ask for unpredictable float evaluation (though
8137 : it might advertise that implicitly the evaluation is unpredictable,
8138 : but we don't care about that here, it will have been reported
8139 : elsewhere). If it does ask for unpredictable evaluation, we have
8140 : nothing to do here. */
8141 90967874 : gcc_assert (target_flt_eval_method != FLT_EVAL_METHOD_UNPREDICTABLE);
8142 :
8143 : /* Nothing to do. The target has asked for all types we know about
8144 : to be computed with their native precision and range. */
8145 90967874 : if (target_flt_eval_method == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
8146 : return NULL_TREE;
8147 :
8148 : /* The target will promote this type in a target-dependent way, so excess
8149 : precision ought to leave it alone. */
8150 89336214 : if (targetm.promoted_type (type) != NULL_TREE)
8151 : return NULL_TREE;
8152 :
8153 89336214 : machine_mode float16_type_mode = (float16_type_node
8154 89336214 : ? TYPE_MODE (float16_type_node)
8155 89336214 : : VOIDmode);
8156 89336214 : machine_mode bfloat16_type_mode = (bfloat16_type_node
8157 89336214 : ? TYPE_MODE (bfloat16_type_node)
8158 89336214 : : VOIDmode);
8159 89336214 : machine_mode float_type_mode = TYPE_MODE (float_type_node);
8160 89336214 : machine_mode double_type_mode = TYPE_MODE (double_type_node);
8161 :
8162 89336214 : switch (TREE_CODE (type))
8163 : {
8164 60868129 : case REAL_TYPE:
8165 60868129 : {
8166 60868129 : machine_mode type_mode = TYPE_MODE (type);
8167 60868129 : switch (target_flt_eval_method)
8168 : {
8169 60855296 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8170 60855296 : if (type_mode == float16_type_mode
8171 60855296 : || type_mode == bfloat16_type_mode)
8172 279721 : return float_type_node;
8173 : break;
8174 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8175 0 : if (type_mode == float16_type_mode
8176 0 : || type_mode == bfloat16_type_mode
8177 0 : || type_mode == float_type_mode)
8178 0 : return double_type_node;
8179 : break;
8180 12833 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8181 12833 : if (type_mode == float16_type_mode
8182 12833 : || type_mode == bfloat16_type_mode
8183 12828 : || type_mode == float_type_mode
8184 12828 : || type_mode == double_type_mode)
8185 12384 : return long_double_type_node;
8186 : break;
8187 0 : default:
8188 0 : gcc_unreachable ();
8189 : }
8190 : break;
8191 : }
8192 380359 : case COMPLEX_TYPE:
8193 380359 : {
8194 380359 : if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
8195 : return NULL_TREE;
8196 370843 : machine_mode type_mode = TYPE_MODE (TREE_TYPE (type));
8197 370843 : switch (target_flt_eval_method)
8198 : {
8199 370510 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8200 370510 : if (type_mode == float16_type_mode
8201 370510 : || type_mode == bfloat16_type_mode)
8202 281 : return complex_float_type_node;
8203 : break;
8204 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8205 0 : if (type_mode == float16_type_mode
8206 0 : || type_mode == bfloat16_type_mode
8207 0 : || type_mode == float_type_mode)
8208 0 : return complex_double_type_node;
8209 : break;
8210 333 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8211 333 : if (type_mode == float16_type_mode
8212 333 : || type_mode == bfloat16_type_mode
8213 333 : || type_mode == float_type_mode
8214 333 : || type_mode == double_type_mode)
8215 281 : return complex_long_double_type_node;
8216 : break;
8217 0 : default:
8218 0 : gcc_unreachable ();
8219 : }
8220 : break;
8221 : }
8222 : default:
8223 : break;
8224 : }
8225 :
8226 : return NULL_TREE;
8227 : }
8228 :
8229 : /* Return OP, stripped of any conversions to wider types as much as is safe.
8230 : Converting the value back to OP's type makes a value equivalent to OP.
8231 :
8232 : If FOR_TYPE is nonzero, we return a value which, if converted to
8233 : type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8234 :
8235 : OP must have integer, real or enumeral type. Pointers are not allowed!
8236 :
8237 : There are some cases where the obvious value we could return
8238 : would regenerate to OP if converted to OP's type,
8239 : but would not extend like OP to wider types.
8240 : If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8241 : For example, if OP is (unsigned short)(signed char)-1,
8242 : we avoid returning (signed char)-1 if FOR_TYPE is int,
8243 : even though extending that to an unsigned short would regenerate OP,
8244 : since the result of extending (signed char)-1 to (int)
8245 : is different from (int) OP. */
8246 :
8247 : tree
8248 11669615 : get_unwidened (tree op, tree for_type)
8249 : {
8250 : /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8251 11669615 : tree type = TREE_TYPE (op);
8252 11669615 : unsigned final_prec
8253 19529758 : = TYPE_PRECISION (for_type != 0 ? for_type : type);
8254 11669615 : int uns
8255 11669615 : = (for_type != 0 && for_type != type
8256 3398181 : && final_prec > TYPE_PRECISION (type)
8257 11919696 : && TYPE_UNSIGNED (type));
8258 11669615 : tree win = op;
8259 :
8260 12042127 : while (CONVERT_EXPR_P (op))
8261 : {
8262 372605 : int bitschange;
8263 :
8264 : /* TYPE_PRECISION on vector types has different meaning
8265 : (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8266 : so avoid them here. */
8267 372605 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
8268 : break;
8269 :
8270 372605 : bitschange = TYPE_PRECISION (TREE_TYPE (op))
8271 372605 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
8272 :
8273 : /* Truncations are many-one so cannot be removed.
8274 : Unless we are later going to truncate down even farther. */
8275 372605 : if (bitschange < 0
8276 372605 : && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
8277 : break;
8278 :
8279 : /* See what's inside this conversion. If we decide to strip it,
8280 : we will set WIN. */
8281 372512 : op = TREE_OPERAND (op, 0);
8282 :
8283 : /* If we have not stripped any zero-extensions (uns is 0),
8284 : we can strip any kind of extension.
8285 : If we have previously stripped a zero-extension,
8286 : only zero-extensions can safely be stripped.
8287 : Any extension can be stripped if the bits it would produce
8288 : are all going to be discarded later by truncating to FOR_TYPE. */
8289 :
8290 372512 : if (bitschange > 0)
8291 : {
8292 228779 : if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
8293 : win = op;
8294 : /* TYPE_UNSIGNED says whether this is a zero-extension.
8295 : Let's avoid computing it if it does not affect WIN
8296 : and if UNS will not be needed again. */
8297 228779 : if ((uns
8298 228748 : || CONVERT_EXPR_P (op))
8299 229480 : && TYPE_UNSIGNED (TREE_TYPE (op)))
8300 : {
8301 : uns = 1;
8302 : win = op;
8303 : }
8304 : }
8305 : }
8306 :
8307 : /* If we finally reach a constant see if it fits in sth smaller and
8308 : in that case convert it. */
8309 11669615 : if (TREE_CODE (win) == INTEGER_CST)
8310 : {
8311 574220 : tree wtype = TREE_TYPE (win);
8312 574220 : unsigned prec = wi::min_precision (wi::to_wide (win), TYPE_SIGN (wtype));
8313 574220 : if (for_type)
8314 562407 : prec = MAX (prec, final_prec);
8315 574220 : if (prec < TYPE_PRECISION (wtype))
8316 : {
8317 569719 : tree t = lang_hooks.types.type_for_size (prec, TYPE_UNSIGNED (wtype));
8318 569719 : if (t && TYPE_PRECISION (t) < TYPE_PRECISION (wtype))
8319 557912 : win = fold_convert (t, win);
8320 : }
8321 : }
8322 :
8323 11669615 : return win;
8324 : }
8325 :
8326 : /* Return OP or a simpler expression for a narrower value
8327 : which can be sign-extended or zero-extended to give back OP.
8328 : Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8329 : or 0 if the value should be sign-extended. */
8330 :
8331 : tree
8332 85994812 : get_narrower (tree op, int *unsignedp_ptr)
8333 : {
8334 85994812 : int uns = 0;
8335 85994812 : bool first = true;
8336 85994812 : tree win = op;
8337 85994812 : bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
8338 :
8339 85994812 : if (TREE_CODE (op) == COMPOUND_EXPR)
8340 : {
8341 90899 : do
8342 90899 : op = TREE_OPERAND (op, 1);
8343 90899 : while (TREE_CODE (op) == COMPOUND_EXPR);
8344 90884 : tree ret = get_narrower (op, unsignedp_ptr);
8345 90884 : if (ret == op)
8346 : return win;
8347 4262 : auto_vec <tree, 16> v;
8348 4262 : unsigned int i;
8349 8531 : for (op = win; TREE_CODE (op) == COMPOUND_EXPR;
8350 4269 : op = TREE_OPERAND (op, 1))
8351 4269 : v.safe_push (op);
8352 17055 : FOR_EACH_VEC_ELT_REVERSE (v, i, op)
8353 4269 : ret = build2_loc (EXPR_LOCATION (op), COMPOUND_EXPR,
8354 4269 : TREE_TYPE (ret), TREE_OPERAND (op, 0),
8355 : ret);
8356 4262 : return ret;
8357 4262 : }
8358 102410289 : while (TREE_CODE (op) == NOP_EXPR)
8359 : {
8360 16539565 : int bitschange
8361 16539565 : = (TYPE_PRECISION (TREE_TYPE (op))
8362 16539565 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
8363 :
8364 : /* Truncations are many-one so cannot be removed. */
8365 16539565 : if (bitschange < 0)
8366 : break;
8367 :
8368 : /* See what's inside this conversion. If we decide to strip it,
8369 : we will set WIN. */
8370 :
8371 16506457 : if (bitschange > 0)
8372 : {
8373 3903051 : op = TREE_OPERAND (op, 0);
8374 : /* An extension: the outermost one can be stripped,
8375 : but remember whether it is zero or sign extension. */
8376 3903051 : if (first)
8377 3892084 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8378 : /* Otherwise, if a sign extension has been stripped,
8379 : only sign extensions can now be stripped;
8380 : if a zero extension has been stripped, only zero-extensions. */
8381 10967 : else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
8382 : break;
8383 : first = false;
8384 : }
8385 : else /* bitschange == 0 */
8386 : {
8387 : /* A change in nominal type can always be stripped, but we must
8388 : preserve the unsignedness. */
8389 12603406 : if (first)
8390 12000936 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8391 12603406 : first = false;
8392 12603406 : op = TREE_OPERAND (op, 0);
8393 : /* Keep trying to narrow, but don't assign op to win if it
8394 : would turn an integral type into something else. */
8395 23435047 : if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
8396 99709 : continue;
8397 : }
8398 :
8399 16406652 : win = op;
8400 : }
8401 :
8402 85903928 : if (TREE_CODE (op) == COMPONENT_REF
8403 : /* Since type_for_size always gives an integer type. */
8404 3010952 : && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
8405 2908436 : && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
8406 : /* Ensure field is laid out already. */
8407 2908436 : && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
8408 88812361 : && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op, 1))))
8409 : {
8410 2908433 : unsigned HOST_WIDE_INT innerprec
8411 2908433 : = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op, 1)));
8412 2908433 : int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
8413 2908433 : || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
8414 2908433 : tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
8415 :
8416 : /* We can get this structure field in a narrower type that fits it,
8417 : but the resulting extension to its nominal type (a fullword type)
8418 : must satisfy the same conditions as for other extensions.
8419 :
8420 : Do this only for fields that are aligned (not bit-fields),
8421 : because when bit-field insns will be used there is no
8422 : advantage in doing this. */
8423 :
8424 2908433 : if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
8425 0 : && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
8426 0 : && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
8427 2908433 : && type != 0)
8428 : {
8429 0 : if (first)
8430 0 : uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
8431 0 : win = fold_convert (type, op);
8432 : }
8433 : }
8434 :
8435 85903928 : *unsignedp_ptr = uns;
8436 85903928 : return win;
8437 : }
8438 :
8439 : /* Return true if integer constant C has a value that is permissible
8440 : for TYPE, an integral type. */
8441 :
8442 : bool
8443 198819821 : int_fits_type_p (const_tree c, const_tree type)
8444 : {
8445 198819821 : tree type_low_bound, type_high_bound;
8446 198819821 : bool ok_for_low_bound, ok_for_high_bound;
8447 198819821 : signop sgn_c = TYPE_SIGN (TREE_TYPE (c));
8448 :
8449 : /* Non-standard boolean types can have arbitrary precision but various
8450 : transformations assume that they can only take values 0 and +/-1. */
8451 198819821 : if (TREE_CODE (type) == BOOLEAN_TYPE)
8452 1291801 : return wi::fits_to_boolean_p (wi::to_wide (c), type);
8453 :
8454 197528020 : retry:
8455 197539867 : type_low_bound = TYPE_MIN_VALUE (type);
8456 197539867 : type_high_bound = TYPE_MAX_VALUE (type);
8457 :
8458 : /* If at least one bound of the type is a constant integer, we can check
8459 : ourselves and maybe make a decision. If no such decision is possible, but
8460 : this type is a subtype, try checking against that. Otherwise, use
8461 : fits_to_tree_p, which checks against the precision.
8462 :
8463 : Compute the status for each possibly constant bound, and return if we see
8464 : one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8465 : for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8466 : for "constant known to fit". */
8467 :
8468 : /* Check if c >= type_low_bound. */
8469 197539867 : if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
8470 : {
8471 197539867 : if (tree_int_cst_lt (c, type_low_bound))
8472 : return false;
8473 : ok_for_low_bound = true;
8474 : }
8475 : else
8476 : ok_for_low_bound = false;
8477 :
8478 : /* Check if c <= type_high_bound. */
8479 197284311 : if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
8480 : {
8481 197252739 : if (tree_int_cst_lt (type_high_bound, c))
8482 : return false;
8483 : ok_for_high_bound = true;
8484 : }
8485 : else
8486 : ok_for_high_bound = false;
8487 :
8488 : /* If the constant fits both bounds, the result is known. */
8489 195323465 : if (ok_for_low_bound && ok_for_high_bound)
8490 : return true;
8491 :
8492 : /* Perform some generic filtering which may allow making a decision
8493 : even if the bounds are not constant. First, negative integers
8494 : never fit in unsigned types, */
8495 31572 : if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (wi::to_wide (c)))
8496 0 : return false;
8497 :
8498 : /* Second, narrower types always fit in wider ones. */
8499 31572 : if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
8500 : return true;
8501 :
8502 : /* Third, unsigned integers with top bit set never fit signed types. */
8503 11856 : if (!TYPE_UNSIGNED (type) && sgn_c == UNSIGNED)
8504 : {
8505 14 : int prec = GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (c))) - 1;
8506 14 : if (prec < TYPE_PRECISION (TREE_TYPE (c)))
8507 : {
8508 : /* When a tree_cst is converted to a wide-int, the precision
8509 : is taken from the type. However, if the precision of the
8510 : mode underneath the type is smaller than that, it is
8511 : possible that the value will not fit. The test below
8512 : fails if any bit is set between the sign bit of the
8513 : underlying mode and the top bit of the type. */
8514 14 : if (wi::zext (wi::to_wide (c), prec - 1) != wi::to_wide (c))
8515 : return false;
8516 : }
8517 0 : else if (wi::neg_p (wi::to_wide (c)))
8518 : return false;
8519 : }
8520 :
8521 : /* If we haven't been able to decide at this point, there nothing more we
8522 : can check ourselves here. Look at the base type if we have one and it
8523 : has the same precision. */
8524 11847 : if (TREE_CODE (type) == INTEGER_TYPE
8525 11847 : && TREE_TYPE (type) != 0
8526 23694 : && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
8527 : {
8528 11847 : type = TREE_TYPE (type);
8529 11847 : goto retry;
8530 : }
8531 :
8532 : /* Or to fits_to_tree_p, if nothing else. */
8533 0 : return wi::fits_to_tree_p (wi::to_wide (c), type);
8534 : }
8535 :
8536 : /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8537 : bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8538 : represented (assuming two's-complement arithmetic) within the bit
8539 : precision of the type are returned instead. */
8540 :
8541 : void
8542 23179070 : get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
8543 : {
8544 21651243 : if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
8545 44830313 : && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
8546 21651243 : wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type)), min, TYPE_SIGN (type));
8547 : else
8548 : {
8549 1527827 : if (TYPE_UNSIGNED (type))
8550 1527827 : mpz_set_ui (min, 0);
8551 : else
8552 : {
8553 0 : wide_int mn = wi::min_value (TYPE_PRECISION (type), SIGNED);
8554 0 : wi::to_mpz (mn, min, SIGNED);
8555 0 : }
8556 : }
8557 :
8558 21651243 : if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
8559 44830313 : && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
8560 21651243 : wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type)), max, TYPE_SIGN (type));
8561 : else
8562 : {
8563 1527827 : wide_int mn = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
8564 1527827 : wi::to_mpz (mn, max, TYPE_SIGN (type));
8565 1527827 : }
8566 23179070 : }
8567 :
8568 : /* Return true if VAR is an automatic variable. */
8569 :
8570 : bool
8571 537118635 : auto_var_p (const_tree var)
8572 : {
8573 319535568 : return ((((VAR_P (var) && ! DECL_EXTERNAL (var))
8574 220961847 : || TREE_CODE (var) == PARM_DECL)
8575 416621764 : && ! TREE_STATIC (var))
8576 667931524 : || TREE_CODE (var) == RESULT_DECL);
8577 : }
8578 :
8579 : /* Return true if VAR is an automatic variable defined in function FN. */
8580 :
8581 : bool
8582 1865737591 : auto_var_in_fn_p (const_tree var, const_tree fn)
8583 : {
8584 632726153 : return (DECL_P (var) && DECL_CONTEXT (var) == fn
8585 2273195837 : && (auto_var_p (var)
8586 6332695 : || TREE_CODE (var) == LABEL_DECL));
8587 : }
8588 :
8589 : /* Subprogram of following function. Called by walk_tree.
8590 :
8591 : Return *TP if it is an automatic variable or parameter of the
8592 : function passed in as DATA. */
8593 :
8594 : static tree
8595 128919 : find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
8596 : {
8597 128919 : tree fn = (tree) data;
8598 :
8599 128919 : if (TYPE_P (*tp))
8600 0 : *walk_subtrees = 0;
8601 :
8602 128919 : else if (DECL_P (*tp)
8603 128919 : && auto_var_in_fn_p (*tp, fn))
8604 120512 : return *tp;
8605 :
8606 : return NULL_TREE;
8607 : }
8608 :
8609 : /* Returns true if T is, contains, or refers to a type with variable
8610 : size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8611 : arguments, but not the return type. If FN is nonzero, only return
8612 : true if a modifier of the type or position of FN is a variable or
8613 : parameter inside FN.
8614 :
8615 : This concept is more general than that of C99 'variably modified types':
8616 : in C99, a struct type is never variably modified because a VLA may not
8617 : appear as a structure member. However, in GNU C code like:
8618 :
8619 : struct S { int i[f()]; };
8620 :
8621 : is valid, and other languages may define similar constructs. */
8622 :
8623 : bool
8624 2465937916 : variably_modified_type_p (tree type, tree fn)
8625 : {
8626 2465937916 : tree t;
8627 :
8628 : /* Test if T is either variable (if FN is zero) or an expression containing
8629 : a variable in FN. If TYPE isn't gimplified, return true also if
8630 : gimplify_one_sizepos would gimplify the expression into a local
8631 : variable. */
8632 : #define RETURN_TRUE_IF_VAR(T) \
8633 : do { tree _t = (T); \
8634 : if (_t != NULL_TREE \
8635 : && _t != error_mark_node \
8636 : && !CONSTANT_CLASS_P (_t) \
8637 : && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8638 : && (!fn \
8639 : || (!TYPE_SIZES_GIMPLIFIED (type) \
8640 : && (TREE_CODE (_t) != VAR_DECL \
8641 : && !CONTAINS_PLACEHOLDER_P (_t))) \
8642 : || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8643 : return true; } while (0)
8644 :
8645 2465937916 : if (type == error_mark_node)
8646 : return false;
8647 :
8648 : /* If TYPE itself has variable size, it is variably modified. */
8649 2465937542 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
8650 2465795632 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
8651 :
8652 2465795008 : switch (TREE_CODE (type))
8653 : {
8654 660903804 : case POINTER_TYPE:
8655 660903804 : case REFERENCE_TYPE:
8656 660903804 : case VECTOR_TYPE:
8657 : /* Ada can have pointer types referring to themselves indirectly. */
8658 660903804 : if (TREE_VISITED (type))
8659 : return false;
8660 660903804 : TREE_VISITED (type) = true;
8661 660903804 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8662 : {
8663 81927 : TREE_VISITED (type) = false;
8664 81927 : return true;
8665 : }
8666 660821877 : TREE_VISITED (type) = false;
8667 660821877 : break;
8668 :
8669 140542885 : case FUNCTION_TYPE:
8670 140542885 : case METHOD_TYPE:
8671 : /* If TYPE is a function type, it is variably modified if the
8672 : return type is variably modified. */
8673 140542885 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8674 : return true;
8675 : break;
8676 :
8677 607596741 : case INTEGER_TYPE:
8678 607596741 : case REAL_TYPE:
8679 607596741 : case FIXED_POINT_TYPE:
8680 607596741 : case ENUMERAL_TYPE:
8681 607596741 : case BOOLEAN_TYPE:
8682 : /* Scalar types are variably modified if their end points
8683 : aren't constant. */
8684 607596741 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
8685 607596741 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
8686 607560970 : break;
8687 :
8688 857515256 : case RECORD_TYPE:
8689 857515256 : case UNION_TYPE:
8690 857515256 : case QUAL_UNION_TYPE:
8691 : /* We can't see if any of the fields are variably-modified by the
8692 : definition we normally use, since that would produce infinite
8693 : recursion via pointers. */
8694 : /* This is variably modified if some field's type is. */
8695 39836817192 : for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
8696 38979301936 : if (TREE_CODE (t) == FIELD_DECL)
8697 : {
8698 1253650457 : RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
8699 1253650457 : RETURN_TRUE_IF_VAR (DECL_SIZE (t));
8700 1253650457 : RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
8701 :
8702 : /* If the type is a qualified union, then the DECL_QUALIFIER
8703 : of fields can also be an expression containing a variable. */
8704 1253650457 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
8705 0 : RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
8706 :
8707 : /* If the field is a qualified union, then it's only a container
8708 : for what's inside so we look into it. That's necessary in LTO
8709 : mode because the sizes of the field tested above have been set
8710 : to PLACEHOLDER_EXPRs by free_lang_data. */
8711 1253650457 : if (TREE_CODE (TREE_TYPE (t)) == QUAL_UNION_TYPE
8712 1253650457 : && variably_modified_type_p (TREE_TYPE (t), fn))
8713 : return true;
8714 : }
8715 : break;
8716 :
8717 14669173 : case ARRAY_TYPE:
8718 : /* Do not call ourselves to avoid infinite recursion. This is
8719 : variably modified if the element type is. */
8720 14669173 : RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
8721 14665659 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
8722 14665633 : break;
8723 :
8724 : default:
8725 : break;
8726 : }
8727 :
8728 : /* The current language may have other cases to check, but in general,
8729 : all other types are not variably modified. */
8730 2465673540 : return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
8731 :
8732 : #undef RETURN_TRUE_IF_VAR
8733 : }
8734 :
8735 : /* Given a DECL or TYPE, return the scope in which it was declared, or
8736 : NULL_TREE if there is no containing scope. */
8737 :
8738 : tree
8739 3088696466 : get_containing_scope (const_tree t)
8740 : {
8741 3088696466 : return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8742 : }
8743 :
8744 : /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
8745 :
8746 : const_tree
8747 14451 : get_ultimate_context (const_tree decl)
8748 : {
8749 39654 : while (decl && TREE_CODE (decl) != TRANSLATION_UNIT_DECL)
8750 : {
8751 25203 : if (TREE_CODE (decl) == BLOCK)
8752 0 : decl = BLOCK_SUPERCONTEXT (decl);
8753 : else
8754 25203 : decl = get_containing_scope (decl);
8755 : }
8756 14451 : return decl;
8757 : }
8758 :
8759 : /* Return the innermost context enclosing DECL that is
8760 : a FUNCTION_DECL, or zero if none. */
8761 :
8762 : tree
8763 1547914100 : decl_function_context (const_tree decl)
8764 : {
8765 1547914100 : tree context;
8766 :
8767 1547914100 : if (TREE_CODE (decl) == ERROR_MARK)
8768 : return 0;
8769 :
8770 : /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8771 : where we look up the function at runtime. Such functions always take
8772 : a first argument of type 'pointer to real context'.
8773 :
8774 : C++ should really be fixed to use DECL_CONTEXT for the real context,
8775 : and use something else for the "virtual context". */
8776 1547914100 : else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
8777 4895582 : context
8778 4895582 : = TYPE_MAIN_VARIANT
8779 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8780 : else
8781 1543018518 : context = DECL_CONTEXT (decl);
8782 :
8783 3787144249 : while (context && TREE_CODE (context) != FUNCTION_DECL)
8784 : {
8785 2239230149 : if (TREE_CODE (context) == BLOCK)
8786 0 : context = BLOCK_SUPERCONTEXT (context);
8787 : else
8788 2239230149 : context = get_containing_scope (context);
8789 : }
8790 :
8791 : return context;
8792 : }
8793 :
8794 : /* Return the innermost context enclosing DECL that is
8795 : a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8796 : TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8797 :
8798 : tree
8799 98944101 : decl_type_context (const_tree decl)
8800 : {
8801 98944101 : tree context = DECL_CONTEXT (decl);
8802 :
8803 102082521 : while (context)
8804 96348578 : switch (TREE_CODE (context))
8805 : {
8806 : case NAMESPACE_DECL:
8807 : case TRANSLATION_UNIT_DECL:
8808 : return NULL_TREE;
8809 :
8810 : case RECORD_TYPE:
8811 : case UNION_TYPE:
8812 : case QUAL_UNION_TYPE:
8813 : return context;
8814 :
8815 3138420 : case TYPE_DECL:
8816 3138420 : case FUNCTION_DECL:
8817 3138420 : context = DECL_CONTEXT (context);
8818 3138420 : break;
8819 :
8820 0 : case BLOCK:
8821 0 : context = BLOCK_SUPERCONTEXT (context);
8822 0 : break;
8823 :
8824 0 : default:
8825 0 : gcc_unreachable ();
8826 : }
8827 :
8828 : return NULL_TREE;
8829 : }
8830 :
8831 : /* CALL is a CALL_EXPR. Return the declaration for the function
8832 : called, or NULL_TREE if the called function cannot be
8833 : determined. */
8834 :
8835 : tree
8836 1260480389 : get_callee_fndecl (const_tree call)
8837 : {
8838 1260480389 : tree addr;
8839 :
8840 1260480389 : if (call == error_mark_node)
8841 : return error_mark_node;
8842 :
8843 : /* It's invalid to call this function with anything but a
8844 : CALL_EXPR. */
8845 1260480389 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8846 :
8847 : /* The first operand to the CALL is the address of the function
8848 : called. */
8849 1260480389 : addr = CALL_EXPR_FN (call);
8850 :
8851 : /* If there is no function, return early. */
8852 1260480389 : if (addr == NULL_TREE)
8853 : return NULL_TREE;
8854 :
8855 1257748013 : STRIP_NOPS (addr);
8856 :
8857 : /* If this is a readonly function pointer, extract its initial value. */
8858 21207261 : if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
8859 2528744 : && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
8860 1258417255 : && DECL_INITIAL (addr))
8861 669187 : addr = DECL_INITIAL (addr);
8862 :
8863 : /* If the address is just `&f' for some function `f', then we know
8864 : that `f' is being called. */
8865 1257748013 : if (TREE_CODE (addr) == ADDR_EXPR
8866 1257748013 : && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
8867 1202872482 : return TREE_OPERAND (addr, 0);
8868 :
8869 : /* We couldn't figure out what was being called. */
8870 : return NULL_TREE;
8871 : }
8872 :
8873 : /* Return true when STMTs arguments and return value match those of FNDECL,
8874 : a decl of a builtin function. */
8875 :
8876 : static bool
8877 6459683 : tree_builtin_call_types_compatible_p (const_tree call, tree fndecl)
8878 : {
8879 6459683 : gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
8880 :
8881 6459683 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
8882 6459683 : if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
8883 6459683 : fndecl = decl;
8884 :
8885 6459683 : bool gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
8886 6459683 : if (gimple_form
8887 15269 : ? !useless_type_conversion_p (TREE_TYPE (call),
8888 15269 : TREE_TYPE (TREE_TYPE (fndecl)))
8889 6444414 : : (TYPE_MAIN_VARIANT (TREE_TYPE (call))
8890 6444414 : != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))))
8891 : return false;
8892 :
8893 6459467 : tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
8894 6459467 : unsigned nargs = call_expr_nargs (call);
8895 16302108 : for (unsigned i = 0; i < nargs; ++i, targs = TREE_CHAIN (targs))
8896 : {
8897 : /* Variadic args follow. */
8898 11401777 : if (!targs)
8899 : return true;
8900 9843298 : tree arg = CALL_EXPR_ARG (call, i);
8901 9843298 : tree type = TREE_VALUE (targs);
8902 9843298 : if (gimple_form
8903 9843298 : ? !useless_type_conversion_p (type, TREE_TYPE (arg))
8904 9828029 : : TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (TREE_TYPE (arg)))
8905 : {
8906 : /* For pointer arguments be more forgiving, e.g. due to
8907 : FILE * vs. fileptr_type_node, or say char * vs. const char *
8908 : differences etc. */
8909 1128999 : if (!gimple_form
8910 564828 : && POINTER_TYPE_P (type)
8911 564276 : && POINTER_TYPE_P (TREE_TYPE (arg))
8912 1128999 : && tree_nop_conversion_p (type, TREE_TYPE (arg)))
8913 564171 : continue;
8914 : return false;
8915 : }
8916 : }
8917 9800015 : if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
8918 5 : return false;
8919 : return true;
8920 : }
8921 :
8922 : /* If CALL_EXPR CALL calls a normal built-in function or an internal function,
8923 : return the associated function code, otherwise return CFN_LAST. */
8924 :
8925 : combined_fn
8926 42376838 : get_call_combined_fn (const_tree call)
8927 : {
8928 : /* It's invalid to call this function with anything but a CALL_EXPR. */
8929 42376838 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8930 :
8931 42376838 : if (!CALL_EXPR_FN (call))
8932 66325 : return as_combined_fn (CALL_EXPR_IFN (call));
8933 :
8934 42310513 : tree fndecl = get_callee_fndecl (call);
8935 42310513 : if (fndecl
8936 42288267 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
8937 48770196 : && tree_builtin_call_types_compatible_p (call, fndecl))
8938 6458805 : return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
8939 :
8940 : return CFN_LAST;
8941 : }
8942 :
8943 : /* Comparator of indices based on tree_node_counts. */
8944 :
8945 : static int
8946 0 : tree_nodes_cmp (const void *p1, const void *p2)
8947 : {
8948 0 : const unsigned *n1 = (const unsigned *)p1;
8949 0 : const unsigned *n2 = (const unsigned *)p2;
8950 :
8951 0 : return tree_node_counts[*n1] - tree_node_counts[*n2];
8952 : }
8953 :
8954 : /* Comparator of indices based on tree_code_counts. */
8955 :
8956 : static int
8957 0 : tree_codes_cmp (const void *p1, const void *p2)
8958 : {
8959 0 : const unsigned *n1 = (const unsigned *)p1;
8960 0 : const unsigned *n2 = (const unsigned *)p2;
8961 :
8962 0 : return tree_code_counts[*n1] - tree_code_counts[*n2];
8963 : }
8964 :
8965 : #define TREE_MEM_USAGE_SPACES 40
8966 :
8967 : /* Print debugging information about tree nodes generated during the compile,
8968 : and any language-specific information. */
8969 :
8970 : void
8971 0 : dump_tree_statistics (void)
8972 : {
8973 0 : if (GATHER_STATISTICS)
8974 : {
8975 : uint64_t total_nodes, total_bytes;
8976 : fprintf (stderr, "\nKind Nodes Bytes\n");
8977 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8978 : total_nodes = total_bytes = 0;
8979 :
8980 : {
8981 : auto_vec<unsigned> indices (all_kinds);
8982 : for (unsigned i = 0; i < all_kinds; i++)
8983 : indices.quick_push (i);
8984 : indices.qsort (tree_nodes_cmp);
8985 :
8986 : for (unsigned i = 0; i < (int) all_kinds; i++)
8987 : {
8988 : unsigned j = indices[i];
8989 : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n",
8990 : tree_node_kind_names[j], SIZE_AMOUNT (tree_node_counts[j]),
8991 : SIZE_AMOUNT (tree_node_sizes[j]));
8992 : total_nodes += tree_node_counts[j];
8993 : total_bytes += tree_node_sizes[j];
8994 : }
8995 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8996 : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n", "Total",
8997 : SIZE_AMOUNT (total_nodes), SIZE_AMOUNT (total_bytes));
8998 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8999 : }
9000 :
9001 : {
9002 : fprintf (stderr, "Code Nodes\n");
9003 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
9004 :
9005 : auto_vec<unsigned> indices (MAX_TREE_CODES);
9006 : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
9007 : indices.quick_push (i);
9008 : indices.qsort (tree_codes_cmp);
9009 :
9010 : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
9011 : {
9012 : unsigned j = indices[i];
9013 : fprintf (stderr, "%-32s %6" PRIu64 "%c\n",
9014 : get_tree_code_name ((enum tree_code) j),
9015 : SIZE_AMOUNT (tree_code_counts[j]));
9016 : }
9017 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
9018 : fprintf (stderr, "\n");
9019 : ssanames_print_statistics ();
9020 : fprintf (stderr, "\n");
9021 : phinodes_print_statistics ();
9022 : fprintf (stderr, "\n");
9023 : }
9024 : }
9025 : else
9026 0 : fprintf (stderr, "(No per-node statistics)\n");
9027 :
9028 0 : print_type_hash_statistics ();
9029 0 : print_debug_expr_statistics ();
9030 0 : print_value_expr_statistics ();
9031 0 : lang_hooks.print_statistics ();
9032 0 : }
9033 :
9034 : #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
9035 :
9036 : /* Generate a crc32 of the low BYTES bytes of VALUE. */
9037 :
9038 : unsigned
9039 17347675 : crc32_unsigned_n (unsigned chksum, unsigned value, unsigned bytes)
9040 : {
9041 : /* This relies on the raw feedback's top 4 bits being zero. */
9042 : #define FEEDBACK(X) ((X) * 0x04c11db7)
9043 : #define SYNDROME(X) (FEEDBACK ((X) & 1) ^ FEEDBACK ((X) & 2) \
9044 : ^ FEEDBACK ((X) & 4) ^ FEEDBACK ((X) & 8))
9045 17347675 : static const unsigned syndromes[16] =
9046 : {
9047 : SYNDROME(0x0), SYNDROME(0x1), SYNDROME(0x2), SYNDROME(0x3),
9048 : SYNDROME(0x4), SYNDROME(0x5), SYNDROME(0x6), SYNDROME(0x7),
9049 : SYNDROME(0x8), SYNDROME(0x9), SYNDROME(0xa), SYNDROME(0xb),
9050 : SYNDROME(0xc), SYNDROME(0xd), SYNDROME(0xe), SYNDROME(0xf),
9051 : };
9052 : #undef FEEDBACK
9053 : #undef SYNDROME
9054 :
9055 17347675 : value <<= (32 - bytes * 8);
9056 57785625 : for (unsigned ix = bytes * 2; ix--; value <<= 4)
9057 : {
9058 40437950 : unsigned feedback = syndromes[((value ^ chksum) >> 28) & 0xf];
9059 :
9060 40437950 : chksum = (chksum << 4) ^ feedback;
9061 : }
9062 :
9063 17347675 : return chksum;
9064 : }
9065 :
9066 : /* Generate a crc32 of a string. */
9067 :
9068 : unsigned
9069 10083 : crc32_string (unsigned chksum, const char *string)
9070 : {
9071 403560 : do
9072 403560 : chksum = crc32_byte (chksum, *string);
9073 403560 : while (*string++);
9074 10083 : return chksum;
9075 : }
9076 :
9077 : /* P is a string that will be used in a symbol. Mask out any characters
9078 : that are not valid in that context. */
9079 :
9080 : void
9081 7542 : clean_symbol_name (char *p)
9082 : {
9083 86666 : for (; *p; p++)
9084 79124 : if (! (ISALNUM (*p)
9085 : #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9086 : || *p == '$'
9087 : #endif
9088 : #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9089 : || *p == '.'
9090 : #endif
9091 : ))
9092 7325 : *p = '_';
9093 7542 : }
9094 :
9095 : static GTY(()) unsigned anon_cnt = 0; /* Saved for PCH. */
9096 :
9097 : /* Create a unique anonymous identifier. The identifier is still a
9098 : valid assembly label. */
9099 :
9100 : tree
9101 3641820 : make_anon_name ()
9102 : {
9103 3641820 : const char *fmt =
9104 : #if !defined (NO_DOT_IN_LABEL)
9105 : "."
9106 : #elif !defined (NO_DOLLAR_IN_LABEL)
9107 : "$"
9108 : #else
9109 : "_"
9110 : #endif
9111 : "_anon_%d";
9112 :
9113 3641820 : char buf[24];
9114 3641820 : int len = snprintf (buf, sizeof (buf), fmt, anon_cnt++);
9115 3641820 : gcc_checking_assert (len < int (sizeof (buf)));
9116 :
9117 3641820 : tree id = get_identifier_with_length (buf, len);
9118 3641820 : IDENTIFIER_ANON_P (id) = true;
9119 :
9120 3641820 : return id;
9121 : }
9122 :
9123 : /* Generate a name for a special-purpose function.
9124 : The generated name may need to be unique across the whole link.
9125 : Changes to this function may also require corresponding changes to
9126 : xstrdup_mask_random.
9127 : TYPE is some string to identify the purpose of this function to the
9128 : linker or collect2; it must start with an uppercase letter,
9129 : one of:
9130 : I - for constructors
9131 : D - for destructors
9132 : N - for C++ anonymous namespaces
9133 : F - for DWARF unwind frame information. */
9134 :
9135 : tree
9136 5632 : get_file_function_name (const char *type)
9137 : {
9138 5632 : char *buf;
9139 5632 : const char *p;
9140 5632 : char *q;
9141 :
9142 : /* If we already have a name we know to be unique, just use that. */
9143 5632 : if (first_global_object_name)
9144 5333 : p = q = ASTRDUP (first_global_object_name);
9145 : /* If the target is handling the constructors/destructors, they
9146 : will be local to this file and the name is only necessary for
9147 : debugging purposes.
9148 : We also assign sub_I and sub_D suffixes to constructors called from
9149 : the global static constructors. These are always local.
9150 : OpenMP "declare target" offloaded constructors/destructors use "off_I" and
9151 : "off_D" for the same purpose. */
9152 299 : else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
9153 598 : || ((startswith (type, "sub_") || startswith (type, "off_"))
9154 299 : && (type[4] == 'I' || type[4] == 'D')))
9155 : {
9156 299 : const char *file = main_input_filename;
9157 299 : if (! file)
9158 0 : file = LOCATION_FILE (input_location);
9159 : /* Just use the file's basename, because the full pathname
9160 : might be quite long. */
9161 299 : p = q = ASTRDUP (lbasename (file));
9162 : }
9163 : else
9164 : {
9165 : /* Otherwise, the name must be unique across the entire link.
9166 : We don't have anything that we know to be unique to this translation
9167 : unit, so use what we do have and throw in some randomness. */
9168 0 : unsigned len;
9169 0 : const char *name = weak_global_object_name;
9170 0 : const char *file = main_input_filename;
9171 :
9172 0 : if (! name)
9173 0 : name = "";
9174 0 : if (! file)
9175 0 : file = LOCATION_FILE (input_location);
9176 :
9177 0 : len = strlen (file);
9178 0 : q = (char *) alloca (9 + 19 + len + 1);
9179 0 : memcpy (q, file, len + 1);
9180 :
9181 0 : snprintf (q + len, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
9182 : crc32_string (0, name), get_random_seed (false));
9183 :
9184 0 : p = q;
9185 : }
9186 :
9187 5632 : clean_symbol_name (q);
9188 5632 : buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
9189 : + strlen (type));
9190 :
9191 : /* Set up the name of the file-level functions we may need.
9192 : Use a global object (which is already required to be unique over
9193 : the program) rather than the file name (which imposes extra
9194 : constraints). */
9195 5632 : sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
9196 :
9197 5632 : return get_identifier (buf);
9198 : }
9199 :
9200 : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9201 :
9202 : /* Complain that the tree code of NODE does not match the expected 0
9203 : terminated list of trailing codes. The trailing code list can be
9204 : empty, for a more vague error message. FILE, LINE, and FUNCTION
9205 : are of the caller. */
9206 :
9207 : void
9208 0 : tree_check_failed (const_tree node, const char *file,
9209 : int line, const char *function, ...)
9210 : {
9211 0 : va_list args;
9212 0 : const char *buffer;
9213 0 : unsigned length = 0;
9214 0 : enum tree_code code;
9215 :
9216 0 : va_start (args, function);
9217 0 : while ((code = (enum tree_code) va_arg (args, int)))
9218 0 : length += 4 + strlen (get_tree_code_name (code));
9219 0 : va_end (args);
9220 0 : if (length)
9221 : {
9222 0 : char *tmp;
9223 0 : va_start (args, function);
9224 0 : length += strlen ("expected ");
9225 0 : buffer = tmp = (char *) alloca (length);
9226 0 : length = 0;
9227 0 : while ((code = (enum tree_code) va_arg (args, int)))
9228 : {
9229 0 : const char *prefix = length ? " or " : "expected ";
9230 :
9231 0 : strcpy (tmp + length, prefix);
9232 0 : length += strlen (prefix);
9233 0 : strcpy (tmp + length, get_tree_code_name (code));
9234 0 : length += strlen (get_tree_code_name (code));
9235 : }
9236 0 : va_end (args);
9237 : }
9238 : else
9239 : buffer = "unexpected node";
9240 :
9241 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9242 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9243 : function, trim_filename (file), line);
9244 : }
9245 :
9246 : /* Complain that the tree code of NODE does match the expected 0
9247 : terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9248 : the caller. */
9249 :
9250 : void
9251 0 : tree_not_check_failed (const_tree node, const char *file,
9252 : int line, const char *function, ...)
9253 : {
9254 0 : va_list args;
9255 0 : char *buffer;
9256 0 : unsigned length = 0;
9257 0 : enum tree_code code;
9258 :
9259 0 : va_start (args, function);
9260 0 : while ((code = (enum tree_code) va_arg (args, int)))
9261 0 : length += 4 + strlen (get_tree_code_name (code));
9262 0 : va_end (args);
9263 0 : va_start (args, function);
9264 0 : buffer = (char *) alloca (length);
9265 0 : length = 0;
9266 0 : while ((code = (enum tree_code) va_arg (args, int)))
9267 : {
9268 0 : if (length)
9269 : {
9270 0 : strcpy (buffer + length, " or ");
9271 0 : length += 4;
9272 : }
9273 0 : strcpy (buffer + length, get_tree_code_name (code));
9274 0 : length += strlen (get_tree_code_name (code));
9275 : }
9276 0 : va_end (args);
9277 :
9278 0 : internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9279 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9280 : function, trim_filename (file), line);
9281 : }
9282 :
9283 : /* Similar to tree_check_failed, except that we check for a class of tree
9284 : code, given in CL. */
9285 :
9286 : void
9287 0 : tree_class_check_failed (const_tree node, const enum tree_code_class cl,
9288 : const char *file, int line, const char *function)
9289 : {
9290 0 : internal_error
9291 0 : ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9292 0 : TREE_CODE_CLASS_STRING (cl),
9293 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9294 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9295 : }
9296 :
9297 : /* Similar to tree_check_failed, except that instead of specifying a
9298 : dozen codes, use the knowledge that they're all sequential. */
9299 :
9300 : void
9301 0 : tree_range_check_failed (const_tree node, const char *file, int line,
9302 : const char *function, enum tree_code c1,
9303 : enum tree_code c2)
9304 : {
9305 0 : char *buffer;
9306 0 : unsigned length = 0;
9307 0 : unsigned int c;
9308 :
9309 0 : for (c = c1; c <= c2; ++c)
9310 0 : length += 4 + strlen (get_tree_code_name ((enum tree_code) c));
9311 :
9312 0 : length += strlen ("expected ");
9313 0 : buffer = (char *) alloca (length);
9314 0 : length = 0;
9315 :
9316 0 : for (c = c1; c <= c2; ++c)
9317 : {
9318 0 : const char *prefix = length ? " or " : "expected ";
9319 :
9320 0 : strcpy (buffer + length, prefix);
9321 0 : length += strlen (prefix);
9322 0 : strcpy (buffer + length, get_tree_code_name ((enum tree_code) c));
9323 0 : length += strlen (get_tree_code_name ((enum tree_code) c));
9324 : }
9325 :
9326 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9327 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9328 : function, trim_filename (file), line);
9329 : }
9330 :
9331 :
9332 : /* Similar to tree_check_failed, except that we check that a tree does
9333 : not have the specified code, given in CL. */
9334 :
9335 : void
9336 0 : tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
9337 : const char *file, int line, const char *function)
9338 : {
9339 0 : internal_error
9340 0 : ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9341 0 : TREE_CODE_CLASS_STRING (cl),
9342 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9343 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9344 : }
9345 :
9346 :
9347 : /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9348 :
9349 : void
9350 0 : omp_clause_check_failed (const_tree node, const char *file, int line,
9351 : const char *function, enum omp_clause_code code)
9352 : {
9353 0 : internal_error ("tree check: expected %<omp_clause %s%>, have %qs "
9354 : "in %s, at %s:%d",
9355 0 : omp_clause_code_name[code],
9356 0 : get_tree_code_name (TREE_CODE (node)),
9357 : function, trim_filename (file), line);
9358 : }
9359 :
9360 :
9361 : /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9362 :
9363 : void
9364 0 : omp_clause_range_check_failed (const_tree node, const char *file, int line,
9365 : const char *function, enum omp_clause_code c1,
9366 : enum omp_clause_code c2)
9367 : {
9368 0 : char *buffer;
9369 0 : unsigned length = 0;
9370 0 : unsigned int c;
9371 :
9372 0 : for (c = c1; c <= c2; ++c)
9373 0 : length += 4 + strlen (omp_clause_code_name[c]);
9374 :
9375 0 : length += strlen ("expected ");
9376 0 : buffer = (char *) alloca (length);
9377 0 : length = 0;
9378 :
9379 0 : for (c = c1; c <= c2; ++c)
9380 : {
9381 0 : const char *prefix = length ? " or " : "expected ";
9382 :
9383 0 : strcpy (buffer + length, prefix);
9384 0 : length += strlen (prefix);
9385 0 : strcpy (buffer + length, omp_clause_code_name[c]);
9386 0 : length += strlen (omp_clause_code_name[c]);
9387 : }
9388 :
9389 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9390 0 : buffer, omp_clause_code_name[TREE_CODE (node)],
9391 : function, trim_filename (file), line);
9392 : }
9393 :
9394 :
9395 : #undef DEFTREESTRUCT
9396 : #define DEFTREESTRUCT(VAL, NAME) NAME,
9397 :
9398 : static const char *ts_enum_names[] = {
9399 : #include "treestruct.def"
9400 : };
9401 : #undef DEFTREESTRUCT
9402 :
9403 : #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9404 :
9405 : /* Similar to tree_class_check_failed, except that we check for
9406 : whether CODE contains the tree structure identified by EN. */
9407 :
9408 : void
9409 0 : tree_contains_struct_check_failed (const_tree node,
9410 : const enum tree_node_structure_enum en,
9411 : const char *file, int line,
9412 : const char *function)
9413 : {
9414 0 : internal_error
9415 0 : ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9416 0 : TS_ENUM_NAME (en),
9417 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9418 : }
9419 :
9420 :
9421 : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9422 : (dynamically sized) vector. */
9423 :
9424 : void
9425 0 : tree_int_cst_elt_check_failed (int idx, int len, const char *file, int line,
9426 : const char *function)
9427 : {
9428 0 : internal_error
9429 0 : ("tree check: accessed elt %d of %<tree_int_cst%> with %d elts in %s, "
9430 : "at %s:%d",
9431 : idx + 1, len, function, trim_filename (file), line);
9432 : }
9433 :
9434 : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9435 : (dynamically sized) vector. */
9436 :
9437 : void
9438 0 : tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
9439 : const char *function)
9440 : {
9441 0 : internal_error
9442 0 : ("tree check: accessed elt %d of %<tree_vec%> with %d elts in %s, at %s:%d",
9443 : idx + 1, len, function, trim_filename (file), line);
9444 : }
9445 :
9446 : /* Similar to above, except that the check is for the bounds of the operand
9447 : vector of an expression node EXP. */
9448 :
9449 : void
9450 0 : tree_operand_check_failed (int idx, const_tree exp, const char *file,
9451 : int line, const char *function)
9452 : {
9453 0 : enum tree_code code = TREE_CODE (exp);
9454 0 : internal_error
9455 0 : ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9456 : idx + 1, get_tree_code_name (code), TREE_OPERAND_LENGTH (exp),
9457 : function, trim_filename (file), line);
9458 : }
9459 :
9460 : /* Similar to above, except that the check is for the number of
9461 : operands of an OMP_CLAUSE node. */
9462 :
9463 : void
9464 0 : omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
9465 : int line, const char *function)
9466 : {
9467 0 : internal_error
9468 0 : ("tree check: accessed operand %d of %<omp_clause %s%> with %d operands "
9469 0 : "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
9470 0 : omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
9471 : trim_filename (file), line);
9472 : }
9473 : #endif /* ENABLE_TREE_CHECKING */
9474 :
9475 : /* Create a new vector type node holding NUNITS units of type INNERTYPE,
9476 : and mapped to the machine mode MODE. Initialize its fields and build
9477 : the information necessary for debugging output. */
9478 :
9479 : static tree
9480 75292471 : make_vector_type (tree innertype, poly_int64 nunits, machine_mode mode)
9481 : {
9482 75292471 : tree t;
9483 75292471 : tree mv_innertype = TYPE_MAIN_VARIANT (innertype);
9484 :
9485 75292471 : t = make_node (VECTOR_TYPE);
9486 75292471 : TREE_TYPE (t) = mv_innertype;
9487 75292471 : SET_TYPE_VECTOR_SUBPARTS (t, nunits);
9488 75292471 : SET_TYPE_MODE (t, mode);
9489 :
9490 75292471 : if (TYPE_STRUCTURAL_EQUALITY_P (mv_innertype) || in_lto_p)
9491 1215143 : SET_TYPE_STRUCTURAL_EQUALITY (t);
9492 74077328 : else if ((TYPE_CANONICAL (mv_innertype) != innertype
9493 70332197 : || mode != VOIDmode)
9494 107205991 : && !VECTOR_BOOLEAN_TYPE_P (t))
9495 34174617 : TYPE_CANONICAL (t)
9496 68349234 : = make_vector_type (TYPE_CANONICAL (mv_innertype), nunits, VOIDmode);
9497 :
9498 75292471 : layout_type (t);
9499 :
9500 75292471 : hashval_t hash = type_hash_canon_hash (t);
9501 75292471 : t = type_hash_canon (hash, t);
9502 :
9503 : /* We have built a main variant, based on the main variant of the
9504 : inner type. Use it to build the variant we return. */
9505 150579166 : if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
9506 76143125 : && TREE_TYPE (t) != innertype)
9507 854987 : return build_type_attribute_qual_variant (t,
9508 854987 : TYPE_ATTRIBUTES (innertype),
9509 1709974 : TYPE_QUALS (innertype));
9510 :
9511 : return t;
9512 : }
9513 :
9514 : static tree
9515 4107354 : make_or_reuse_type (unsigned size, int unsignedp)
9516 : {
9517 4107354 : int i;
9518 :
9519 4107354 : if (size == INT_TYPE_SIZE)
9520 881682 : return unsignedp ? unsigned_type_node : integer_type_node;
9521 3225672 : if (size == CHAR_TYPE_SIZE)
9522 587788 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
9523 2637884 : if (size == SHORT_TYPE_SIZE)
9524 881682 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
9525 1792582 : if (size == LONG_TYPE_SIZE)
9526 859911 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
9527 896291 : if (size == LONG_LONG_TYPE_SIZE)
9528 21771 : return (unsignedp ? long_long_unsigned_type_node
9529 21771 : : long_long_integer_type_node);
9530 :
9531 888844 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9532 874520 : if (size == int_n_data[i].bitsize
9533 874520 : && int_n_enabled_p[i])
9534 860196 : return (unsignedp ? int_n_trees[i].unsigned_type
9535 860196 : : int_n_trees[i].signed_type);
9536 :
9537 14324 : if (unsignedp)
9538 7162 : return make_unsigned_type (size);
9539 : else
9540 7162 : return make_signed_type (size);
9541 : }
9542 :
9543 : /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9544 :
9545 : static tree
9546 5877880 : make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
9547 : {
9548 5877880 : if (satp)
9549 : {
9550 2938940 : if (size == SHORT_FRACT_TYPE_SIZE)
9551 587788 : return unsignedp ? sat_unsigned_short_fract_type_node
9552 587788 : : sat_short_fract_type_node;
9553 2351152 : if (size == FRACT_TYPE_SIZE)
9554 587788 : return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
9555 1763364 : if (size == LONG_FRACT_TYPE_SIZE)
9556 587788 : return unsignedp ? sat_unsigned_long_fract_type_node
9557 587788 : : sat_long_fract_type_node;
9558 1175576 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9559 587788 : return unsignedp ? sat_unsigned_long_long_fract_type_node
9560 587788 : : sat_long_long_fract_type_node;
9561 : }
9562 : else
9563 : {
9564 2938940 : if (size == SHORT_FRACT_TYPE_SIZE)
9565 587788 : return unsignedp ? unsigned_short_fract_type_node
9566 587788 : : short_fract_type_node;
9567 2351152 : if (size == FRACT_TYPE_SIZE)
9568 587788 : return unsignedp ? unsigned_fract_type_node : fract_type_node;
9569 1763364 : if (size == LONG_FRACT_TYPE_SIZE)
9570 587788 : return unsignedp ? unsigned_long_fract_type_node
9571 587788 : : long_fract_type_node;
9572 1175576 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9573 587788 : return unsignedp ? unsigned_long_long_fract_type_node
9574 587788 : : long_long_fract_type_node;
9575 : }
9576 :
9577 1175576 : return make_fract_type (size, unsignedp, satp);
9578 : }
9579 :
9580 : /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9581 :
9582 : static tree
9583 4702304 : make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
9584 : {
9585 4702304 : if (satp)
9586 : {
9587 2351152 : if (size == SHORT_ACCUM_TYPE_SIZE)
9588 587788 : return unsignedp ? sat_unsigned_short_accum_type_node
9589 587788 : : sat_short_accum_type_node;
9590 1763364 : if (size == ACCUM_TYPE_SIZE)
9591 587788 : return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
9592 1175576 : if (size == LONG_ACCUM_TYPE_SIZE)
9593 587788 : return unsignedp ? sat_unsigned_long_accum_type_node
9594 587788 : : sat_long_accum_type_node;
9595 587788 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9596 587788 : return unsignedp ? sat_unsigned_long_long_accum_type_node
9597 587788 : : sat_long_long_accum_type_node;
9598 : }
9599 : else
9600 : {
9601 2351152 : if (size == SHORT_ACCUM_TYPE_SIZE)
9602 587788 : return unsignedp ? unsigned_short_accum_type_node
9603 587788 : : short_accum_type_node;
9604 1763364 : if (size == ACCUM_TYPE_SIZE)
9605 587788 : return unsignedp ? unsigned_accum_type_node : accum_type_node;
9606 1175576 : if (size == LONG_ACCUM_TYPE_SIZE)
9607 587788 : return unsignedp ? unsigned_long_accum_type_node
9608 587788 : : long_accum_type_node;
9609 587788 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9610 587788 : return unsignedp ? unsigned_long_long_accum_type_node
9611 587788 : : long_long_accum_type_node;
9612 : }
9613 :
9614 0 : return make_accum_type (size, unsignedp, satp);
9615 : }
9616 :
9617 :
9618 : /* Create an atomic variant node for TYPE. This routine is called
9619 : during initialization of data types to create the 5 basic atomic
9620 : types. The generic build_variant_type function requires these to
9621 : already be set up in order to function properly, so cannot be
9622 : called from there. If ALIGN is non-zero, then ensure alignment is
9623 : overridden to this value. */
9624 :
9625 : static tree
9626 1469470 : build_atomic_base (tree type, unsigned int align)
9627 : {
9628 1469470 : tree t;
9629 :
9630 : /* Make sure its not already registered. */
9631 1469470 : if ((t = get_qualified_type (type, TYPE_QUAL_ATOMIC)))
9632 : return t;
9633 :
9634 1469470 : t = build_variant_type_copy (type);
9635 1469470 : set_type_quals (t, TYPE_QUAL_ATOMIC);
9636 :
9637 1469470 : if (align)
9638 0 : SET_TYPE_ALIGN (t, align);
9639 :
9640 : return t;
9641 : }
9642 :
9643 : /* Return unsigned integer tree node for TYPE. */
9644 :
9645 : tree
9646 293934 : unsigned_integer_tree_node_for_type (const char *type)
9647 : {
9648 293934 : tree type_node;
9649 :
9650 293934 : if (strcmp (type, "unsigned int") == 0)
9651 7257 : type_node = unsigned_type_node;
9652 286677 : else if (strcmp (type, "long unsigned int") == 0)
9653 286677 : type_node = long_unsigned_type_node;
9654 0 : else if (strcmp (type, "long long unsigned int") == 0)
9655 0 : type_node = long_long_unsigned_type_node;
9656 0 : else if (strcmp (type, "short unsigned int") == 0)
9657 0 : type_node = short_unsigned_type_node;
9658 : else
9659 : {
9660 : int i;
9661 :
9662 : type_node = nullptr;
9663 0 : for (i = 0; i < NUM_INT_N_ENTS; i++)
9664 0 : if (int_n_enabled_p[i])
9665 : {
9666 0 : char name[50], altname[50];
9667 0 : sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
9668 0 : sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize);
9669 :
9670 0 : if (strcmp (name, type) == 0
9671 0 : || strcmp (altname, type) == 0)
9672 : {
9673 0 : type_node = int_n_trees[i].unsigned_type;
9674 : }
9675 : }
9676 0 : if (type_node == nullptr)
9677 0 : gcc_unreachable ();
9678 : }
9679 :
9680 293934 : return type_node;
9681 : }
9682 :
9683 : /* Information about the _FloatN and _FloatNx types. This must be in
9684 : the same order as the corresponding TI_* enum values. */
9685 : const floatn_type_info floatn_nx_types[NUM_FLOATN_NX_TYPES] =
9686 : {
9687 : { 16, false },
9688 : { 32, false },
9689 : { 64, false },
9690 : { 128, false },
9691 : { 32, true },
9692 : { 64, true },
9693 : { 128, true },
9694 : };
9695 :
9696 :
9697 : /* Create nodes for all integer types (and error_mark_node) using the sizes
9698 : of C datatypes. SIGNED_CHAR specifies whether char is signed. */
9699 :
9700 : void
9701 293894 : build_common_tree_nodes (bool signed_char)
9702 : {
9703 293894 : int i;
9704 :
9705 293894 : error_mark_node = make_node (ERROR_MARK);
9706 293894 : TREE_TYPE (error_mark_node) = error_mark_node;
9707 :
9708 293894 : initialize_sizetypes ();
9709 :
9710 : /* Define both `signed char' and `unsigned char'. */
9711 293894 : signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
9712 293894 : TYPE_STRING_FLAG (signed_char_type_node) = 1;
9713 293894 : unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
9714 293894 : TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
9715 :
9716 : /* Define `char', which is like either `signed char' or `unsigned char'
9717 : but not the same as either. */
9718 293894 : char_type_node
9719 293894 : = (signed_char
9720 293894 : ? make_signed_type (CHAR_TYPE_SIZE)
9721 58665 : : make_unsigned_type (CHAR_TYPE_SIZE));
9722 293894 : TYPE_STRING_FLAG (char_type_node) = 1;
9723 :
9724 293894 : short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
9725 293894 : short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
9726 293894 : integer_type_node = make_signed_type (INT_TYPE_SIZE);
9727 293894 : unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
9728 301151 : long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
9729 301151 : long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
9730 293894 : long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
9731 293894 : long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
9732 :
9733 587788 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9734 : {
9735 293894 : int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
9736 293894 : int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
9737 :
9738 293894 : if (int_n_enabled_p[i])
9739 : {
9740 286732 : integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type;
9741 286732 : integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type;
9742 : }
9743 : }
9744 :
9745 : /* Define a boolean type. This type only represents boolean values but
9746 : may be larger than char depending on the value of BOOL_TYPE_SIZE. */
9747 293894 : boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
9748 293894 : TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
9749 293894 : TYPE_PRECISION (boolean_type_node) = 1;
9750 293894 : TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
9751 :
9752 : /* Define what type to use for size_t. */
9753 301151 : size_type_node = unsigned_integer_tree_node_for_type (SIZE_TYPE);
9754 :
9755 : /* Define what type to use for ptrdiff_t. */
9756 301151 : if (strcmp (PTRDIFF_TYPE, "int") == 0)
9757 7257 : ptrdiff_type_node = integer_type_node;
9758 286637 : else if (strcmp (PTRDIFF_TYPE, "long int") == 0)
9759 286637 : ptrdiff_type_node = long_integer_type_node;
9760 0 : else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)
9761 0 : ptrdiff_type_node = long_long_integer_type_node;
9762 0 : else if (strcmp (PTRDIFF_TYPE, "short int") == 0)
9763 0 : ptrdiff_type_node = short_integer_type_node;
9764 : else
9765 : {
9766 0 : ptrdiff_type_node = NULL_TREE;
9767 0 : for (int i = 0; i < NUM_INT_N_ENTS; i++)
9768 0 : if (int_n_enabled_p[i])
9769 : {
9770 0 : char name[50], altname[50];
9771 0 : sprintf (name, "__int%d", int_n_data[i].bitsize);
9772 0 : sprintf (altname, "__int%d__", int_n_data[i].bitsize);
9773 :
9774 0 : if (strcmp (name, PTRDIFF_TYPE) == 0
9775 0 : || strcmp (altname, PTRDIFF_TYPE) == 0)
9776 0 : ptrdiff_type_node = int_n_trees[i].signed_type;
9777 : }
9778 0 : if (ptrdiff_type_node == NULL_TREE)
9779 0 : gcc_unreachable ();
9780 : }
9781 :
9782 : /* Fill in the rest of the sized types. Reuse existing type nodes
9783 : when possible. */
9784 293894 : intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
9785 293894 : intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
9786 293894 : intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
9787 293894 : intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
9788 293894 : intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
9789 :
9790 293894 : unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
9791 293894 : unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
9792 293894 : unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
9793 293894 : unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
9794 293894 : unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
9795 :
9796 : /* Don't call build_qualified type for atomics. That routine does
9797 : special processing for atomics, and until they are initialized
9798 : it's better not to make that call.
9799 :
9800 : Check to see if there is a target override for atomic types. */
9801 :
9802 293894 : atomicQI_type_node = build_atomic_base (unsigned_intQI_type_node,
9803 293894 : targetm.atomic_align_for_mode (QImode));
9804 293894 : atomicHI_type_node = build_atomic_base (unsigned_intHI_type_node,
9805 293894 : targetm.atomic_align_for_mode (HImode));
9806 293894 : atomicSI_type_node = build_atomic_base (unsigned_intSI_type_node,
9807 293894 : targetm.atomic_align_for_mode (SImode));
9808 293894 : atomicDI_type_node = build_atomic_base (unsigned_intDI_type_node,
9809 293894 : targetm.atomic_align_for_mode (DImode));
9810 293894 : atomicTI_type_node = build_atomic_base (unsigned_intTI_type_node,
9811 293894 : targetm.atomic_align_for_mode (TImode));
9812 :
9813 293894 : access_public_node = get_identifier ("public");
9814 293894 : access_protected_node = get_identifier ("protected");
9815 293894 : access_private_node = get_identifier ("private");
9816 :
9817 : /* Define these next since types below may used them. */
9818 293894 : integer_zero_node = build_int_cst (integer_type_node, 0);
9819 293894 : integer_one_node = build_int_cst (integer_type_node, 1);
9820 293894 : integer_minus_one_node = build_int_cst (integer_type_node, -1);
9821 :
9822 293894 : size_zero_node = size_int (0);
9823 293894 : size_one_node = size_int (1);
9824 293894 : bitsize_zero_node = bitsize_int (0);
9825 293894 : bitsize_one_node = bitsize_int (1);
9826 293894 : bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
9827 :
9828 293894 : boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9829 293894 : boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9830 :
9831 293894 : void_type_node = make_node (VOID_TYPE);
9832 293894 : layout_type (void_type_node);
9833 :
9834 : /* We are not going to have real types in C with less than byte alignment,
9835 : so we might as well not have any types that claim to have it. */
9836 293894 : SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT);
9837 293894 : TYPE_USER_ALIGN (void_type_node) = 0;
9838 :
9839 293894 : void_node = make_node (VOID_CST);
9840 293894 : TREE_TYPE (void_node) = void_type_node;
9841 :
9842 293894 : void_list_node = build_tree_list (NULL_TREE, void_type_node);
9843 :
9844 293894 : null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
9845 293894 : layout_type (TREE_TYPE (null_pointer_node));
9846 :
9847 293894 : ptr_type_node = build_pointer_type (void_type_node);
9848 293894 : const_ptr_type_node
9849 293894 : = build_pointer_type (build_type_variant (void_type_node, 1, 0));
9850 2057258 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
9851 1763364 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
9852 :
9853 301151 : pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
9854 :
9855 293894 : float_type_node = make_node (REAL_TYPE);
9856 293894 : machine_mode float_type_mode
9857 293894 : = targetm.c.mode_for_floating_type (TI_FLOAT_TYPE);
9858 293894 : SET_TYPE_MODE (float_type_node, float_type_mode);
9859 293894 : TYPE_PRECISION (float_type_node)
9860 293894 : = GET_MODE_PRECISION (float_type_mode).to_constant ();
9861 293894 : layout_type (float_type_node);
9862 :
9863 293894 : double_type_node = make_node (REAL_TYPE);
9864 293894 : machine_mode double_type_mode
9865 293894 : = targetm.c.mode_for_floating_type (TI_DOUBLE_TYPE);
9866 293894 : SET_TYPE_MODE (double_type_node, double_type_mode);
9867 293894 : TYPE_PRECISION (double_type_node)
9868 293894 : = GET_MODE_PRECISION (double_type_mode).to_constant ();
9869 293894 : layout_type (double_type_node);
9870 :
9871 293894 : long_double_type_node = make_node (REAL_TYPE);
9872 293894 : machine_mode long_double_type_mode
9873 293894 : = targetm.c.mode_for_floating_type (TI_LONG_DOUBLE_TYPE);
9874 293894 : SET_TYPE_MODE (long_double_type_node, long_double_type_mode);
9875 293894 : TYPE_PRECISION (long_double_type_node)
9876 293894 : = GET_MODE_PRECISION (long_double_type_mode).to_constant ();
9877 293894 : layout_type (long_double_type_node);
9878 :
9879 2645046 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9880 : {
9881 2057258 : int n = floatn_nx_types[i].n;
9882 2057258 : bool extended = floatn_nx_types[i].extended;
9883 2057258 : scalar_float_mode mode;
9884 2057258 : if (!targetm.floatn_mode (n, extended).exists (&mode))
9885 293894 : continue;
9886 1763364 : int precision = GET_MODE_PRECISION (mode);
9887 1763364 : FLOATN_NX_TYPE_NODE (i) = make_node (REAL_TYPE);
9888 1763364 : TYPE_PRECISION (FLOATN_NX_TYPE_NODE (i)) = precision;
9889 1763364 : layout_type (FLOATN_NX_TYPE_NODE (i));
9890 1763364 : SET_TYPE_MODE (FLOATN_NX_TYPE_NODE (i), mode);
9891 : }
9892 293894 : float128t_type_node = float128_type_node;
9893 : #ifdef HAVE_BFmode
9894 293894 : if (REAL_MODE_FORMAT (BFmode) == &arm_bfloat_half_format
9895 293894 : && targetm.scalar_mode_supported_p (BFmode)
9896 587788 : && targetm.libgcc_floating_mode_supported_p (BFmode))
9897 : {
9898 293894 : bfloat16_type_node = make_node (REAL_TYPE);
9899 293894 : TYPE_PRECISION (bfloat16_type_node) = GET_MODE_PRECISION (BFmode);
9900 293894 : layout_type (bfloat16_type_node);
9901 293894 : SET_TYPE_MODE (bfloat16_type_node, BFmode);
9902 : }
9903 : #endif
9904 :
9905 293894 : float_ptr_type_node = build_pointer_type (float_type_node);
9906 293894 : double_ptr_type_node = build_pointer_type (double_type_node);
9907 293894 : long_double_ptr_type_node = build_pointer_type (long_double_type_node);
9908 293894 : integer_ptr_type_node = build_pointer_type (integer_type_node);
9909 :
9910 : /* Fixed size integer types. */
9911 293894 : uint16_type_node = make_or_reuse_type (16, 1);
9912 293894 : uint32_type_node = make_or_reuse_type (32, 1);
9913 293894 : uint64_type_node = make_or_reuse_type (64, 1);
9914 293894 : if (targetm.scalar_mode_supported_p (TImode))
9915 286732 : uint128_type_node = make_or_reuse_type (128, 1);
9916 :
9917 : /* Decimal float types. */
9918 293894 : if (targetm.decimal_float_supported_p ())
9919 : {
9920 293894 : dfloat32_type_node = make_node (REAL_TYPE);
9921 293894 : TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
9922 293894 : SET_TYPE_MODE (dfloat32_type_node, SDmode);
9923 293894 : layout_type (dfloat32_type_node);
9924 :
9925 293894 : dfloat64_type_node = make_node (REAL_TYPE);
9926 293894 : TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
9927 293894 : SET_TYPE_MODE (dfloat64_type_node, DDmode);
9928 293894 : layout_type (dfloat64_type_node);
9929 :
9930 293894 : dfloat128_type_node = make_node (REAL_TYPE);
9931 293894 : TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
9932 293894 : SET_TYPE_MODE (dfloat128_type_node, TDmode);
9933 293894 : layout_type (dfloat128_type_node);
9934 :
9935 293894 : dfloat64x_type_node = make_node (REAL_TYPE);
9936 293894 : TYPE_PRECISION (dfloat64x_type_node) = DECIMAL128_TYPE_SIZE;
9937 293894 : SET_TYPE_MODE (dfloat64x_type_node, TDmode);
9938 293894 : layout_type (dfloat64x_type_node);
9939 : }
9940 :
9941 293894 : complex_integer_type_node = build_complex_type (integer_type_node, true);
9942 293894 : complex_float_type_node = build_complex_type (float_type_node, true);
9943 293894 : complex_double_type_node = build_complex_type (double_type_node, true);
9944 293894 : complex_long_double_type_node = build_complex_type (long_double_type_node,
9945 : true);
9946 :
9947 2351152 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9948 : {
9949 2057258 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
9950 1763364 : COMPLEX_FLOATN_NX_TYPE_NODE (i)
9951 1763364 : = build_complex_type (FLOATN_NX_TYPE_NODE (i));
9952 : }
9953 :
9954 : /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9955 : #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9956 : sat_ ## KIND ## _type_node = \
9957 : make_sat_signed_ ## KIND ## _type (SIZE); \
9958 : sat_unsigned_ ## KIND ## _type_node = \
9959 : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9960 : KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9961 : unsigned_ ## KIND ## _type_node = \
9962 : make_unsigned_ ## KIND ## _type (SIZE);
9963 :
9964 : #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9965 : sat_ ## WIDTH ## KIND ## _type_node = \
9966 : make_sat_signed_ ## KIND ## _type (SIZE); \
9967 : sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9968 : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9969 : WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9970 : unsigned_ ## WIDTH ## KIND ## _type_node = \
9971 : make_unsigned_ ## KIND ## _type (SIZE);
9972 :
9973 : /* Make fixed-point type nodes based on four different widths. */
9974 : #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9975 : MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9976 : MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9977 : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9978 : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9979 :
9980 : /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9981 : #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9982 : NAME ## _type_node = \
9983 : make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9984 : u ## NAME ## _type_node = \
9985 : make_or_reuse_unsigned_ ## KIND ## _type \
9986 : (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9987 : sat_ ## NAME ## _type_node = \
9988 : make_or_reuse_sat_signed_ ## KIND ## _type \
9989 : (GET_MODE_BITSIZE (MODE ## mode)); \
9990 : sat_u ## NAME ## _type_node = \
9991 : make_or_reuse_sat_unsigned_ ## KIND ## _type \
9992 : (GET_MODE_BITSIZE (U ## MODE ## mode));
9993 :
9994 : /* Fixed-point type and mode nodes. */
9995 293894 : MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
9996 293894 : MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
9997 293894 : MAKE_FIXED_MODE_NODE (fract, qq, QQ)
9998 293894 : MAKE_FIXED_MODE_NODE (fract, hq, HQ)
9999 293894 : MAKE_FIXED_MODE_NODE (fract, sq, SQ)
10000 293894 : MAKE_FIXED_MODE_NODE (fract, dq, DQ)
10001 293894 : MAKE_FIXED_MODE_NODE (fract, tq, TQ)
10002 293894 : MAKE_FIXED_MODE_NODE (accum, ha, HA)
10003 293894 : MAKE_FIXED_MODE_NODE (accum, sa, SA)
10004 293894 : MAKE_FIXED_MODE_NODE (accum, da, DA)
10005 293894 : MAKE_FIXED_MODE_NODE (accum, ta, TA)
10006 :
10007 293894 : {
10008 293894 : tree t = targetm.build_builtin_va_list ();
10009 :
10010 : /* Many back-ends define record types without setting TYPE_NAME.
10011 : If we copied the record type here, we'd keep the original
10012 : record type without a name. This breaks name mangling. So,
10013 : don't copy record types and let c_common_nodes_and_builtins()
10014 : declare the type to be __builtin_va_list. */
10015 293894 : if (TREE_CODE (t) != RECORD_TYPE)
10016 293894 : t = build_variant_type_copy (t);
10017 :
10018 293894 : va_list_type_node = t;
10019 : }
10020 :
10021 : /* SCEV analyzer global shared trees. */
10022 293894 : chrec_dont_know = make_node (SCEV_NOT_KNOWN);
10023 293894 : TREE_TYPE (chrec_dont_know) = void_type_node;
10024 293894 : chrec_known = make_node (SCEV_KNOWN);
10025 293894 : TREE_TYPE (chrec_known) = void_type_node;
10026 293894 : }
10027 :
10028 : /* Modify DECL for given flags.
10029 : TM_PURE attribute is set only on types, so the function will modify
10030 : DECL's type when ECF_TM_PURE is used. */
10031 :
10032 : void
10033 32840281 : set_call_expr_flags (tree decl, int flags)
10034 : {
10035 32840281 : if (flags & ECF_NOTHROW)
10036 28477397 : TREE_NOTHROW (decl) = 1;
10037 32840281 : if (flags & ECF_CONST)
10038 13560242 : TREE_READONLY (decl) = 1;
10039 32840281 : if (flags & ECF_PURE)
10040 1592941 : DECL_PURE_P (decl) = 1;
10041 32840281 : if (flags & ECF_LOOPING_CONST_OR_PURE)
10042 59966 : DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
10043 32840281 : if (flags & ECF_NOVOPS)
10044 0 : DECL_IS_NOVOPS (decl) = 1;
10045 32840281 : if (flags & ECF_NORETURN)
10046 1267030 : TREE_THIS_VOLATILE (decl) = 1;
10047 32840281 : if (flags & ECF_MALLOC)
10048 757805 : DECL_IS_MALLOC (decl) = 1;
10049 32840281 : if (flags & ECF_RETURNS_TWICE)
10050 0 : DECL_IS_RETURNS_TWICE (decl) = 1;
10051 32840281 : if (flags & ECF_LEAF)
10052 28288494 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
10053 28288494 : NULL, DECL_ATTRIBUTES (decl));
10054 32840281 : if (flags & ECF_COLD)
10055 673694 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("cold"),
10056 673694 : NULL, DECL_ATTRIBUTES (decl));
10057 32840281 : if (flags & ECF_RET1)
10058 0 : DECL_ATTRIBUTES (decl)
10059 0 : = tree_cons (get_identifier ("fn spec"),
10060 : build_tree_list (NULL_TREE, build_string (2, "1 ")),
10061 0 : DECL_ATTRIBUTES (decl));
10062 32840281 : if ((flags & ECF_TM_PURE) && flag_tm)
10063 533 : apply_tm_attr (decl, get_identifier ("transaction_pure"));
10064 32840281 : if ((flags & ECF_XTHROW))
10065 423265 : DECL_ATTRIBUTES (decl)
10066 846530 : = tree_cons (get_identifier ("expected_throw"),
10067 423265 : NULL, DECL_ATTRIBUTES (decl));
10068 :
10069 32840281 : if (flags & ECF_CB_1_2)
10070 : {
10071 384948 : tree attr = callback_build_attr (1, 1, 2);
10072 384948 : TREE_CHAIN (attr) = DECL_ATTRIBUTES (decl);
10073 384948 : DECL_ATTRIBUTES (decl) = attr;
10074 : }
10075 :
10076 : /* Looping const or pure is implied by noreturn.
10077 : There is currently no way to declare looping const or looping pure alone. */
10078 32840281 : gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE)
10079 : || (flags & (ECF_CONST | ECF_PURE)));
10080 32840281 : }
10081 :
10082 :
10083 : /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
10084 :
10085 : static void
10086 9807800 : local_define_builtin (const char *name, tree type, enum built_in_function code,
10087 : const char *library_name, int ecf_flags)
10088 : {
10089 9807800 : tree decl;
10090 :
10091 9807800 : decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
10092 : library_name, NULL_TREE);
10093 9807800 : set_call_expr_flags (decl, ecf_flags);
10094 :
10095 9807800 : set_builtin_decl (code, decl, true);
10096 9807800 : }
10097 :
10098 : /* Call this function after instantiating all builtins that the language
10099 : front end cares about. This will build the rest of the builtins
10100 : and internal functions that are relied upon by the tree optimizers and
10101 : the middle-end. */
10102 :
10103 : void
10104 293877 : build_common_builtin_nodes (void)
10105 : {
10106 293877 : tree tmp, ftype;
10107 293877 : int ecf_flags;
10108 :
10109 293877 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_PADDING))
10110 : {
10111 59966 : ftype = build_function_type_list (void_type_node,
10112 : ptr_type_node,
10113 : ptr_type_node,
10114 : NULL_TREE);
10115 59966 : local_define_builtin ("__builtin_clear_padding", ftype,
10116 : BUILT_IN_CLEAR_PADDING,
10117 : "__builtin_clear_padding",
10118 : ECF_LEAF | ECF_NOTHROW);
10119 : }
10120 :
10121 293877 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)
10122 238557 : || !builtin_decl_explicit_p (BUILT_IN_TRAP)
10123 238557 : || !builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP)
10124 233911 : || !builtin_decl_explicit_p (BUILT_IN_OBSERVABLE_CHKPT)
10125 527788 : || !builtin_decl_explicit_p (BUILT_IN_ABORT))
10126 : {
10127 59966 : ftype = build_function_type (void_type_node, void_list_node);
10128 59966 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE))
10129 55320 : local_define_builtin ("__builtin_unreachable", ftype,
10130 : BUILT_IN_UNREACHABLE,
10131 : "__builtin_unreachable",
10132 : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10133 : | ECF_CONST | ECF_COLD);
10134 59966 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP))
10135 59966 : local_define_builtin ("__builtin_unreachable trap", ftype,
10136 : BUILT_IN_UNREACHABLE_TRAP,
10137 : "__builtin_unreachable trap",
10138 : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10139 : | ECF_CONST | ECF_COLD);
10140 59966 : if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
10141 59966 : local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
10142 : "abort",
10143 : ECF_LEAF | ECF_NORETURN | ECF_CONST | ECF_COLD);
10144 59966 : if (!builtin_decl_explicit_p (BUILT_IN_TRAP))
10145 23241 : local_define_builtin ("__builtin_trap", ftype, BUILT_IN_TRAP,
10146 : "__builtin_trap",
10147 : ECF_NORETURN | ECF_NOTHROW | ECF_LEAF | ECF_COLD);
10148 59966 : if (!builtin_decl_explicit_p (BUILT_IN_OBSERVABLE_CHKPT))
10149 59966 : local_define_builtin ("__builtin_observable_checkpoint", ftype,
10150 : BUILT_IN_OBSERVABLE_CHKPT,
10151 : "__builtin_observable_checkpoint",
10152 : ECF_NOTHROW | ECF_LEAF | ECF_CONST
10153 : | ECF_LOOPING_CONST_OR_PURE);
10154 : }
10155 :
10156 293877 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)
10157 293877 : || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10158 : {
10159 59966 : ftype = build_function_type_list (ptr_type_node,
10160 : ptr_type_node, const_ptr_type_node,
10161 : size_type_node, NULL_TREE);
10162 :
10163 59966 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY))
10164 59966 : local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
10165 : "memcpy", ECF_NOTHROW | ECF_LEAF);
10166 59966 : if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10167 55320 : local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
10168 : "memmove", ECF_NOTHROW | ECF_LEAF);
10169 : }
10170 :
10171 293877 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP))
10172 : {
10173 55320 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10174 : const_ptr_type_node, size_type_node,
10175 : NULL_TREE);
10176 55320 : local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
10177 : "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10178 : }
10179 :
10180 293877 : if (!builtin_decl_explicit_p (BUILT_IN_MEMSET))
10181 : {
10182 55320 : ftype = build_function_type_list (ptr_type_node,
10183 : ptr_type_node, integer_type_node,
10184 : size_type_node, NULL_TREE);
10185 55320 : local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
10186 : "memset", ECF_NOTHROW | ECF_LEAF);
10187 : }
10188 :
10189 : /* If we're checking the stack, `alloca' can throw. */
10190 293809 : const int alloca_flags
10191 293877 : = ECF_MALLOC | ECF_LEAF | (flag_stack_check ? 0 : ECF_NOTHROW);
10192 :
10193 293877 : if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA))
10194 : {
10195 59966 : ftype = build_function_type_list (ptr_type_node,
10196 : size_type_node, NULL_TREE);
10197 59966 : local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
10198 : "alloca", alloca_flags);
10199 : }
10200 :
10201 293877 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10202 : size_type_node, NULL_TREE);
10203 293877 : local_define_builtin ("__builtin_alloca_with_align", ftype,
10204 : BUILT_IN_ALLOCA_WITH_ALIGN,
10205 : "__builtin_alloca_with_align",
10206 : alloca_flags);
10207 :
10208 293877 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10209 : size_type_node, size_type_node, NULL_TREE);
10210 293877 : local_define_builtin ("__builtin_alloca_with_align_and_max", ftype,
10211 : BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX,
10212 : "__builtin_alloca_with_align_and_max",
10213 : alloca_flags);
10214 :
10215 293877 : ftype = build_function_type_list (void_type_node,
10216 : ptr_type_node, ptr_type_node,
10217 : ptr_type_node, NULL_TREE);
10218 293877 : local_define_builtin ("__builtin_init_trampoline", ftype,
10219 : BUILT_IN_INIT_TRAMPOLINE,
10220 : "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
10221 293877 : local_define_builtin ("__builtin_init_heap_trampoline", ftype,
10222 : BUILT_IN_INIT_HEAP_TRAMPOLINE,
10223 : "__builtin_init_heap_trampoline",
10224 : ECF_NOTHROW | ECF_LEAF);
10225 293877 : local_define_builtin ("__builtin_init_descriptor", ftype,
10226 : BUILT_IN_INIT_DESCRIPTOR,
10227 : "__builtin_init_descriptor", ECF_NOTHROW | ECF_LEAF);
10228 :
10229 293877 : ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
10230 293877 : local_define_builtin ("__builtin_adjust_trampoline", ftype,
10231 : BUILT_IN_ADJUST_TRAMPOLINE,
10232 : "__builtin_adjust_trampoline",
10233 : ECF_CONST | ECF_NOTHROW);
10234 293877 : local_define_builtin ("__builtin_adjust_descriptor", ftype,
10235 : BUILT_IN_ADJUST_DESCRIPTOR,
10236 : "__builtin_adjust_descriptor",
10237 : ECF_CONST | ECF_NOTHROW);
10238 :
10239 293877 : ftype = build_function_type_list (void_type_node,
10240 : ptr_type_node, ptr_type_node, NULL_TREE);
10241 293877 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_CACHE))
10242 59966 : local_define_builtin ("__builtin___clear_cache", ftype,
10243 : BUILT_IN_CLEAR_CACHE,
10244 : "__clear_cache",
10245 : ECF_NOTHROW);
10246 :
10247 293877 : local_define_builtin ("__builtin_nonlocal_goto", ftype,
10248 : BUILT_IN_NONLOCAL_GOTO,
10249 : "__builtin_nonlocal_goto",
10250 : ECF_NORETURN | ECF_NOTHROW);
10251 :
10252 293877 : tree ptr_ptr_type_node = build_pointer_type (ptr_type_node);
10253 :
10254 293877 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED))
10255 : {
10256 59966 : ftype = build_function_type_list (void_type_node,
10257 : ptr_type_node, // void *chain
10258 : ptr_type_node, // void *func
10259 : ptr_ptr_type_node, // void **dst
10260 : NULL_TREE);
10261 59966 : local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype,
10262 : BUILT_IN_GCC_NESTED_PTR_CREATED,
10263 : "__gcc_nested_func_ptr_created", ECF_NOTHROW);
10264 : }
10265 :
10266 293877 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED))
10267 : {
10268 59966 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10269 59966 : local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype,
10270 : BUILT_IN_GCC_NESTED_PTR_DELETED,
10271 : "__gcc_nested_func_ptr_deleted", ECF_NOTHROW);
10272 : }
10273 :
10274 293877 : ftype = build_function_type_list (void_type_node,
10275 : ptr_type_node, ptr_type_node, NULL_TREE);
10276 293877 : local_define_builtin ("__builtin_setjmp_setup", ftype,
10277 : BUILT_IN_SETJMP_SETUP,
10278 : "__builtin_setjmp_setup", ECF_NOTHROW);
10279 :
10280 293877 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10281 293877 : local_define_builtin ("__builtin_setjmp_receiver", ftype,
10282 : BUILT_IN_SETJMP_RECEIVER,
10283 : "__builtin_setjmp_receiver", ECF_NOTHROW | ECF_LEAF);
10284 :
10285 293877 : ftype = build_function_type_list (ptr_type_node, NULL_TREE);
10286 293877 : local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
10287 : "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
10288 :
10289 293877 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10290 293877 : local_define_builtin ("__builtin_stack_restore", ftype,
10291 : BUILT_IN_STACK_RESTORE,
10292 : "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
10293 :
10294 293877 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10295 : const_ptr_type_node, size_type_node,
10296 : NULL_TREE);
10297 293877 : local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ,
10298 : "__builtin_memcmp_eq",
10299 : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10300 :
10301 293877 : local_define_builtin ("__builtin_strncmp_eq", ftype, BUILT_IN_STRNCMP_EQ,
10302 : "__builtin_strncmp_eq",
10303 : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10304 :
10305 293877 : local_define_builtin ("__builtin_strcmp_eq", ftype, BUILT_IN_STRCMP_EQ,
10306 : "__builtin_strcmp_eq",
10307 : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10308 :
10309 : /* If there's a possibility that we might use the ARM EABI, build the
10310 : alternate __cxa_end_cleanup node used to resume from C++. */
10311 293877 : if (targetm.arm_eabi_unwinder)
10312 : {
10313 0 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10314 0 : local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
10315 : BUILT_IN_CXA_END_CLEANUP,
10316 : "__cxa_end_cleanup",
10317 : ECF_NORETURN | ECF_XTHROW | ECF_LEAF);
10318 : }
10319 :
10320 293877 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10321 587754 : local_define_builtin ("__builtin_unwind_resume", ftype,
10322 : BUILT_IN_UNWIND_RESUME,
10323 293877 : ((targetm_common.except_unwind_info (&global_options)
10324 : == UI_SJLJ)
10325 : ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10326 : ECF_NORETURN | ECF_XTHROW);
10327 :
10328 293877 : if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE)
10329 : {
10330 55320 : ftype = build_function_type_list (ptr_type_node, integer_type_node,
10331 : NULL_TREE);
10332 55320 : local_define_builtin ("__builtin_return_address", ftype,
10333 : BUILT_IN_RETURN_ADDRESS,
10334 : "__builtin_return_address",
10335 : ECF_NOTHROW);
10336 : }
10337 :
10338 293877 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)
10339 293877 : || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10340 : {
10341 59966 : ftype = build_function_type_list (void_type_node, ptr_type_node,
10342 : ptr_type_node, NULL_TREE);
10343 59966 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER))
10344 59966 : local_define_builtin ("__cyg_profile_func_enter", ftype,
10345 : BUILT_IN_PROFILE_FUNC_ENTER,
10346 : "__cyg_profile_func_enter", 0);
10347 59966 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10348 59966 : local_define_builtin ("__cyg_profile_func_exit", ftype,
10349 : BUILT_IN_PROFILE_FUNC_EXIT,
10350 : "__cyg_profile_func_exit", 0);
10351 : }
10352 :
10353 : /* The exception object and filter values from the runtime. The argument
10354 : must be zero before exception lowering, i.e. from the front end. After
10355 : exception lowering, it will be the region number for the exception
10356 : landing pad. These functions are PURE instead of CONST to prevent
10357 : them from being hoisted past the exception edge that will initialize
10358 : its value in the landing pad. */
10359 293877 : ftype = build_function_type_list (ptr_type_node,
10360 : integer_type_node, NULL_TREE);
10361 293877 : ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF;
10362 : /* Only use TM_PURE if we have TM language support. */
10363 293877 : if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
10364 469 : ecf_flags |= ECF_TM_PURE;
10365 293877 : local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
10366 : "__builtin_eh_pointer", ecf_flags);
10367 :
10368 293877 : tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
10369 293877 : ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
10370 293877 : local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
10371 : "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10372 :
10373 293877 : ftype = build_function_type_list (void_type_node,
10374 : integer_type_node, integer_type_node,
10375 : NULL_TREE);
10376 293877 : local_define_builtin ("__builtin_eh_copy_values", ftype,
10377 : BUILT_IN_EH_COPY_VALUES,
10378 : "__builtin_eh_copy_values", ECF_NOTHROW);
10379 :
10380 : /* Complex multiplication and division. These are handled as builtins
10381 : rather than optabs because emit_library_call_value doesn't support
10382 : complex. Further, we can do slightly better with folding these
10383 : beasties if the real and complex parts of the arguments are separate. */
10384 293877 : {
10385 293877 : int mode;
10386 :
10387 2351016 : for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
10388 : {
10389 1763262 : char mode_name_buf[4], *q;
10390 1763262 : const char *p;
10391 1763262 : enum built_in_function mcode, dcode;
10392 1763262 : tree type, inner_type;
10393 1763262 : const char *prefix = "__";
10394 :
10395 1763262 : if (targetm.libfunc_gnu_prefix)
10396 0 : prefix = "__gnu_";
10397 :
10398 1763262 : type = lang_hooks.types.type_for_mode ((machine_mode) mode, 0);
10399 1763262 : if (type == NULL)
10400 130927 : continue;
10401 1632335 : inner_type = TREE_TYPE (type);
10402 :
10403 1632335 : ftype = build_function_type_list (type, inner_type, inner_type,
10404 : inner_type, inner_type, NULL_TREE);
10405 :
10406 1632335 : mcode = ((enum built_in_function)
10407 1632335 : (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10408 1632335 : dcode = ((enum built_in_function)
10409 1632335 : (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10410 :
10411 4897005 : for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
10412 3264670 : *q = TOLOWER (*p);
10413 1632335 : *q = '\0';
10414 :
10415 : /* For -ftrapping-math these should throw from a former
10416 : -fnon-call-exception stmt. */
10417 1632335 : built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
10418 : NULL);
10419 1632335 : local_define_builtin (built_in_names[mcode], ftype, mcode,
10420 : built_in_names[mcode],
10421 : ECF_CONST | ECF_LEAF);
10422 :
10423 1632335 : built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
10424 : NULL);
10425 1632335 : local_define_builtin (built_in_names[dcode], ftype, dcode,
10426 : built_in_names[dcode],
10427 : ECF_CONST | ECF_LEAF);
10428 : }
10429 : }
10430 :
10431 293877 : init_internal_fns ();
10432 293877 : }
10433 :
10434 : /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10435 : better way.
10436 :
10437 : If we requested a pointer to a vector, build up the pointers that
10438 : we stripped off while looking for the inner type. Similarly for
10439 : return values from functions.
10440 :
10441 : The argument TYPE is the top of the chain, and BOTTOM is the
10442 : new type which we will point to. */
10443 :
10444 : tree
10445 0 : reconstruct_complex_type (tree type, tree bottom)
10446 : {
10447 0 : tree inner, outer;
10448 :
10449 0 : if (TREE_CODE (type) == POINTER_TYPE)
10450 : {
10451 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10452 0 : outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
10453 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10454 : }
10455 : else if (TREE_CODE (type) == REFERENCE_TYPE)
10456 : {
10457 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10458 0 : outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
10459 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10460 : }
10461 : else if (TREE_CODE (type) == ARRAY_TYPE)
10462 : {
10463 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10464 0 : outer = build_array_type (inner, TYPE_DOMAIN (type));
10465 : }
10466 : else if (TREE_CODE (type) == FUNCTION_TYPE)
10467 : {
10468 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10469 0 : outer = build_function_type (inner, TYPE_ARG_TYPES (type),
10470 0 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
10471 : }
10472 : else if (TREE_CODE (type) == METHOD_TYPE)
10473 : {
10474 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10475 : /* The build_method_type_directly() routine prepends 'this' to argument list,
10476 : so we must compensate by getting rid of it. */
10477 0 : outer
10478 : = build_method_type_directly
10479 0 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
10480 : inner,
10481 0 : TREE_CHAIN (TYPE_ARG_TYPES (type)));
10482 : }
10483 : else if (TREE_CODE (type) == OFFSET_TYPE)
10484 : {
10485 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10486 0 : outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
10487 : }
10488 : else
10489 : return bottom;
10490 :
10491 0 : return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
10492 0 : TYPE_QUALS (type));
10493 : }
10494 :
10495 : /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10496 : the inner type. */
10497 : tree
10498 35301865 : build_vector_type_for_mode (tree innertype, machine_mode mode)
10499 : {
10500 35301865 : poly_int64 nunits;
10501 35301865 : unsigned int bitsize;
10502 :
10503 35301865 : switch (GET_MODE_CLASS (mode))
10504 : {
10505 35300455 : case MODE_VECTOR_BOOL:
10506 35300455 : case MODE_VECTOR_INT:
10507 35300455 : case MODE_VECTOR_FLOAT:
10508 35300455 : case MODE_VECTOR_FRACT:
10509 35300455 : case MODE_VECTOR_UFRACT:
10510 35300455 : case MODE_VECTOR_ACCUM:
10511 35300455 : case MODE_VECTOR_UACCUM:
10512 70600910 : nunits = GET_MODE_NUNITS (mode);
10513 35300455 : break;
10514 :
10515 1410 : case MODE_INT:
10516 : /* Check that there are no leftover bits. */
10517 1410 : bitsize = GET_MODE_BITSIZE (as_a <scalar_int_mode> (mode));
10518 1410 : gcc_assert (bitsize % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
10519 1410 : nunits = bitsize / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
10520 1410 : break;
10521 :
10522 0 : default:
10523 0 : gcc_unreachable ();
10524 : }
10525 :
10526 35301865 : return make_vector_type (innertype, nunits, mode);
10527 : }
10528 :
10529 : /* Similarly, but takes the inner type and number of units, which must be
10530 : a power of two. */
10531 :
10532 : tree
10533 2929291 : build_vector_type (tree innertype, poly_int64 nunits)
10534 : {
10535 2929291 : return make_vector_type (innertype, nunits, VOIDmode);
10536 : }
10537 :
10538 : /* Build a truth vector with NUNITS units, giving it mode MASK_MODE. */
10539 :
10540 : tree
10541 2775827 : build_truth_vector_type_for_mode (poly_uint64 nunits, machine_mode mask_mode)
10542 : {
10543 2775827 : gcc_assert (mask_mode != BLKmode);
10544 :
10545 2775827 : unsigned HOST_WIDE_INT esize;
10546 2775827 : if (VECTOR_MODE_P (mask_mode))
10547 : {
10548 2637063 : poly_uint64 vsize = GET_MODE_PRECISION (mask_mode);
10549 2637063 : esize = vector_element_size (vsize, nunits);
10550 2637063 : }
10551 : else
10552 : esize = 1;
10553 :
10554 2775827 : tree bool_type = build_nonstandard_boolean_type (esize);
10555 :
10556 2775827 : return make_vector_type (bool_type, nunits, mask_mode);
10557 : }
10558 :
10559 : /* Build a vector type that holds one boolean result for each element of
10560 : vector type VECTYPE. The public interface for this operation is
10561 : truth_type_for. */
10562 :
10563 : static tree
10564 2764779 : build_truth_vector_type_for (tree vectype)
10565 : {
10566 2764779 : machine_mode vector_mode = TYPE_MODE (vectype);
10567 2764779 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
10568 :
10569 2764779 : machine_mode mask_mode;
10570 103954 : if (VECTOR_MODE_P (vector_mode)
10571 2868112 : && targetm.vectorize.get_mask_mode (vector_mode).exists (&mask_mode))
10572 2764158 : return build_truth_vector_type_for_mode (nunits, mask_mode);
10573 :
10574 621 : poly_uint64 vsize = tree_to_poly_uint64 (TYPE_SIZE (vectype));
10575 621 : unsigned HOST_WIDE_INT esize = vector_element_size (vsize, nunits);
10576 621 : tree bool_type = build_nonstandard_boolean_type (esize);
10577 :
10578 621 : return make_vector_type (bool_type, nunits, VOIDmode);
10579 : }
10580 :
10581 : /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
10582 : set. */
10583 :
10584 : tree
10585 110250 : build_opaque_vector_type (tree innertype, poly_int64 nunits)
10586 : {
10587 110250 : tree t = make_vector_type (innertype, nunits, VOIDmode);
10588 110250 : tree cand;
10589 : /* We always build the non-opaque variant before the opaque one,
10590 : so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10591 110250 : cand = TYPE_NEXT_VARIANT (t);
10592 110250 : if (cand
10593 98531 : && TYPE_VECTOR_OPAQUE (cand)
10594 174001 : && check_qualified_type (cand, t, TYPE_QUALS (t)))
10595 : return cand;
10596 : /* Otherwise build a variant type and make sure to queue it after
10597 : the non-opaque type. */
10598 46500 : cand = build_distinct_type_copy (t);
10599 46500 : TYPE_VECTOR_OPAQUE (cand) = true;
10600 46500 : TYPE_CANONICAL (cand) = TYPE_CANONICAL (t);
10601 46500 : TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t);
10602 46500 : TYPE_NEXT_VARIANT (t) = cand;
10603 46500 : TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
10604 : /* Type variants have no alias set defined. */
10605 46500 : TYPE_ALIAS_SET (cand) = -1;
10606 46500 : return cand;
10607 : }
10608 :
10609 : /* Return the value of element I of VECTOR_CST T as a wide_int. */
10610 :
10611 : static poly_wide_int
10612 539505 : vector_cst_int_elt (const_tree t, unsigned int i)
10613 : {
10614 : /* First handle elements that are directly encoded. */
10615 539505 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10616 539505 : if (i < encoded_nelts)
10617 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, i));
10618 :
10619 : /* Identify the pattern that contains element I and work out the index of
10620 : the last encoded element for that pattern. */
10621 539505 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10622 539505 : unsigned int pattern = i % npatterns;
10623 539505 : unsigned int count = i / npatterns;
10624 539505 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10625 :
10626 : /* If there are no steps, the final encoded value is the right one. */
10627 539505 : if (!VECTOR_CST_STEPPED_P (t))
10628 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, final_i));
10629 :
10630 : /* Otherwise work out the value from the last two encoded elements. */
10631 539505 : tree v1 = VECTOR_CST_ENCODED_ELT (t, final_i - npatterns);
10632 539505 : tree v2 = VECTOR_CST_ENCODED_ELT (t, final_i);
10633 539505 : poly_wide_int diff = wi::to_poly_wide (v2) - wi::to_poly_wide (v1);
10634 539505 : return wi::to_poly_wide (v2) + (count - 2) * diff;
10635 539505 : }
10636 :
10637 : /* Return the value of element I of VECTOR_CST T. */
10638 :
10639 : tree
10640 8181230 : vector_cst_elt (const_tree t, unsigned int i)
10641 : {
10642 : /* First handle elements that are directly encoded. */
10643 8181230 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10644 8181230 : if (i < encoded_nelts)
10645 5266645 : return VECTOR_CST_ENCODED_ELT (t, i);
10646 :
10647 : /* If there are no steps, the final encoded value is the right one. */
10648 2914585 : if (!VECTOR_CST_STEPPED_P (t))
10649 : {
10650 : /* Identify the pattern that contains element I and work out the index of
10651 : the last encoded element for that pattern. */
10652 2375080 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10653 2375080 : unsigned int pattern = i % npatterns;
10654 2375080 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10655 2375080 : return VECTOR_CST_ENCODED_ELT (t, final_i);
10656 : }
10657 :
10658 : /* Otherwise work out the value from the last two encoded elements. */
10659 539505 : return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t)),
10660 1079010 : vector_cst_int_elt (t, i));
10661 : }
10662 :
10663 : /* Given an initializer INIT, return TRUE if INIT is zero or some
10664 : aggregate of zeros. Otherwise return FALSE. If NONZERO is not
10665 : null, set *NONZERO if and only if INIT is known not to be all
10666 : zeros. The combination of return value of false and *NONZERO
10667 : false implies that INIT may but need not be all zeros. Other
10668 : combinations indicate definitive answers. */
10669 :
10670 : bool
10671 44926504 : initializer_zerop (const_tree init, bool *nonzero /* = NULL */)
10672 : {
10673 44926504 : bool dummy;
10674 44926504 : if (!nonzero)
10675 42146220 : nonzero = &dummy;
10676 :
10677 : /* Conservatively clear NONZERO and set it only if INIT is definitely
10678 : not all zero. */
10679 44926504 : *nonzero = false;
10680 :
10681 44926504 : STRIP_NOPS (init);
10682 :
10683 44926504 : unsigned HOST_WIDE_INT off = 0;
10684 :
10685 44926504 : switch (TREE_CODE (init))
10686 : {
10687 17315003 : case INTEGER_CST:
10688 17315003 : if (integer_zerop (init))
10689 : return true;
10690 :
10691 10970196 : *nonzero = true;
10692 10970196 : return false;
10693 :
10694 575489 : case REAL_CST:
10695 : /* ??? Note that this is not correct for C4X float formats. There,
10696 : a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10697 : negative exponent. */
10698 575489 : if (real_zerop (init)
10699 672480 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)))
10700 : return true;
10701 :
10702 481668 : *nonzero = true;
10703 481668 : return false;
10704 :
10705 0 : case FIXED_CST:
10706 0 : if (fixed_zerop (init))
10707 : return true;
10708 :
10709 0 : *nonzero = true;
10710 0 : return false;
10711 :
10712 18300 : case COMPLEX_CST:
10713 18300 : if (integer_zerop (init)
10714 18300 : || (real_zerop (init)
10715 3249 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
10716 3169 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))))
10717 : return true;
10718 :
10719 14953 : *nonzero = true;
10720 14953 : return false;
10721 :
10722 1181589 : case VECTOR_CST:
10723 1181589 : if (VECTOR_CST_NPATTERNS (init) == 1
10724 1086726 : && VECTOR_CST_DUPLICATE_P (init)
10725 1861608 : && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)))
10726 : return true;
10727 :
10728 822892 : *nonzero = true;
10729 822892 : return false;
10730 :
10731 : case RAW_DATA_CST:
10732 1969 : for (unsigned int i = 0; i < (unsigned int) RAW_DATA_LENGTH (init); ++i)
10733 1969 : if (RAW_DATA_POINTER (init)[i])
10734 : {
10735 1919 : *nonzero = true;
10736 1919 : return false;
10737 : }
10738 : return true;
10739 :
10740 4360539 : case CONSTRUCTOR:
10741 4360539 : {
10742 4360539 : if (TREE_CLOBBER_P (init))
10743 : return false;
10744 :
10745 : unsigned HOST_WIDE_INT idx;
10746 : tree elt;
10747 :
10748 3665039 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
10749 2780284 : if (!initializer_zerop (elt, nonzero))
10750 : return false;
10751 :
10752 : return true;
10753 : }
10754 :
10755 371780 : case MEM_REF:
10756 371780 : {
10757 371780 : tree arg = TREE_OPERAND (init, 0);
10758 371780 : if (TREE_CODE (arg) != ADDR_EXPR)
10759 : return false;
10760 92997 : tree offset = TREE_OPERAND (init, 1);
10761 92997 : if (TREE_CODE (offset) != INTEGER_CST
10762 92997 : || !tree_fits_uhwi_p (offset))
10763 : return false;
10764 92997 : off = tree_to_uhwi (offset);
10765 92997 : if (INT_MAX < off)
10766 : return false;
10767 92993 : arg = TREE_OPERAND (arg, 0);
10768 92993 : if (TREE_CODE (arg) != STRING_CST)
10769 : return false;
10770 : init = arg;
10771 : }
10772 : /* Fall through. */
10773 :
10774 : case STRING_CST:
10775 : {
10776 : gcc_assert (off <= INT_MAX);
10777 :
10778 156535 : int i = off;
10779 156535 : int n = TREE_STRING_LENGTH (init);
10780 156535 : if (n <= i)
10781 : return false;
10782 :
10783 : /* We need to loop through all elements to handle cases like
10784 : "\0" and "\0foobar". */
10785 168687 : for (i = 0; i < n; ++i)
10786 163165 : if (TREE_STRING_POINTER (init)[i] != '\0')
10787 : {
10788 150980 : *nonzero = true;
10789 150980 : return false;
10790 : }
10791 :
10792 : return true;
10793 : }
10794 :
10795 : default:
10796 : return false;
10797 : }
10798 : }
10799 :
10800 : /* Return true if EXPR is an initializer expression in which every element
10801 : is a constant that is numerically equal to 0 or 1. The elements do not
10802 : need to be equal to each other. */
10803 :
10804 : bool
10805 132934 : initializer_each_zero_or_onep (const_tree expr)
10806 : {
10807 132934 : STRIP_ANY_LOCATION_WRAPPER (expr);
10808 :
10809 132934 : switch (TREE_CODE (expr))
10810 : {
10811 46853 : case INTEGER_CST:
10812 46853 : return integer_zerop (expr) || integer_onep (expr);
10813 :
10814 25272 : case REAL_CST:
10815 25272 : return real_zerop (expr) || real_onep (expr);
10816 :
10817 60809 : case VECTOR_CST:
10818 60809 : {
10819 60809 : unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
10820 60809 : if (VECTOR_CST_STEPPED_P (expr)
10821 60809 : && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
10822 : return false;
10823 :
10824 74530 : for (unsigned int i = 0; i < nelts; ++i)
10825 : {
10826 72125 : tree elt = vector_cst_elt (expr, i);
10827 72125 : if (!initializer_each_zero_or_onep (elt))
10828 : return false;
10829 : }
10830 :
10831 : return true;
10832 : }
10833 :
10834 : default:
10835 : return false;
10836 : }
10837 : }
10838 :
10839 : /* Check if vector VEC consists of all the equal elements and
10840 : that the number of elements corresponds to the type of VEC.
10841 : The function returns first element of the vector
10842 : or NULL_TREE if the vector is not uniform. */
10843 : tree
10844 3291635 : uniform_vector_p (const_tree vec)
10845 : {
10846 3291635 : tree first, t;
10847 3291635 : unsigned HOST_WIDE_INT i, nelts;
10848 :
10849 3291635 : if (vec == NULL_TREE)
10850 : return NULL_TREE;
10851 :
10852 3291635 : gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
10853 :
10854 3291635 : if (TREE_CODE (vec) == VEC_DUPLICATE_EXPR)
10855 0 : return TREE_OPERAND (vec, 0);
10856 :
10857 3291635 : else if (TREE_CODE (vec) == VECTOR_CST)
10858 : {
10859 402893 : if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
10860 337321 : return VECTOR_CST_ENCODED_ELT (vec, 0);
10861 : return NULL_TREE;
10862 : }
10863 :
10864 2888742 : else if (TREE_CODE (vec) == CONSTRUCTOR
10865 2888742 : && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)).is_constant (&nelts))
10866 : {
10867 177931 : first = error_mark_node;
10868 :
10869 583371 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
10870 : {
10871 520801 : if (i == 0)
10872 : {
10873 177931 : first = t;
10874 177931 : continue;
10875 : }
10876 342870 : if (!operand_equal_p (first, t, 0))
10877 : return NULL_TREE;
10878 : }
10879 62570 : if (i != nelts)
10880 : return NULL_TREE;
10881 :
10882 62274 : if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
10883 0 : return uniform_vector_p (first);
10884 : return first;
10885 : }
10886 :
10887 : return NULL_TREE;
10888 : }
10889 :
10890 : /* If OP is a uniform vector return the element it is a splat from. */
10891 :
10892 : tree
10893 288554 : ssa_uniform_vector_p (tree op)
10894 : {
10895 288554 : if (TREE_CODE (op) == VECTOR_CST
10896 : || TREE_CODE (op) == VEC_DUPLICATE_EXPR
10897 : || TREE_CODE (op) == CONSTRUCTOR)
10898 12087 : return uniform_vector_p (op);
10899 : if (TREE_CODE (op) == SSA_NAME)
10900 : {
10901 276467 : gimple *def_stmt = SSA_NAME_DEF_STMT (op);
10902 276467 : if (gimple_assign_single_p (def_stmt))
10903 117481 : return uniform_vector_p (gimple_assign_rhs1 (def_stmt));
10904 : /* A VEC_DUPLICATE_EXPR is a unary assignment, so it is not covered
10905 : by the gimple_assign_single_p case above. */
10906 158986 : if (is_gimple_assign (def_stmt)
10907 158986 : && gimple_assign_rhs_code (def_stmt) == VEC_DUPLICATE_EXPR)
10908 0 : return gimple_assign_rhs1 (def_stmt);
10909 : }
10910 : return NULL_TREE;
10911 : }
10912 :
10913 : /* If the argument is INTEGER_CST, return it. If the argument is vector
10914 : with all elements the same INTEGER_CST, return that INTEGER_CST. Otherwise
10915 : return NULL_TREE.
10916 : Look through location wrappers. */
10917 :
10918 : tree
10919 898068341 : uniform_integer_cst_p (tree t)
10920 : {
10921 898068341 : STRIP_ANY_LOCATION_WRAPPER (t);
10922 :
10923 898068341 : if (TREE_CODE (t) == INTEGER_CST)
10924 : return t;
10925 :
10926 361549554 : if (VECTOR_TYPE_P (TREE_TYPE (t)))
10927 : {
10928 1400081 : t = uniform_vector_p (t);
10929 1400081 : if (t && TREE_CODE (t) == INTEGER_CST)
10930 284435 : return t;
10931 : }
10932 :
10933 : return NULL_TREE;
10934 : }
10935 :
10936 : /* Return true if ELT1 and ELT2 are INTEGER_CSTs and if ELT1 - ELT2 is
10937 : consistent with the uniform difference recorded in DIFF. */
10938 :
10939 : static bool
10940 295 : record_uniform_integer_difference (const_tree elt1, const_tree elt2,
10941 : widest_int *diff, bool *diff_p)
10942 : {
10943 295 : STRIP_ANY_LOCATION_WRAPPER (elt1);
10944 295 : STRIP_ANY_LOCATION_WRAPPER (elt2);
10945 :
10946 295 : if (TREE_CODE (elt1) != INTEGER_CST
10947 94 : || TREE_CODE (elt2) != INTEGER_CST)
10948 : return false;
10949 :
10950 94 : widest_int elt_diff = wi::to_widest (elt1) - wi::to_widest (elt2);
10951 94 : if (!*diff_p)
10952 : {
10953 94 : *diff = elt_diff;
10954 94 : *diff_p = true;
10955 94 : return true;
10956 : }
10957 :
10958 0 : return *diff == elt_diff;
10959 295 : }
10960 :
10961 : /* Return the uniform difference between two INTEGER_CSTs or corresponding
10962 : elements of two VECTOR_CSTs or NULL_TREE if no such difference exists. */
10963 :
10964 : tree
10965 295 : uniform_vector_difference_p (const_tree t1, const_tree t2)
10966 : {
10967 295 : STRIP_ANY_LOCATION_WRAPPER (t1);
10968 295 : STRIP_ANY_LOCATION_WRAPPER (t2);
10969 :
10970 295 : if (TREE_CODE (t1) == INTEGER_CST
10971 0 : && TREE_CODE (t2) == INTEGER_CST)
10972 : {
10973 0 : widest_int diff = wi::to_widest (t1) - wi::to_widest (t2);
10974 0 : if (!wi::fits_shwi_p (diff))
10975 : return NULL_TREE;
10976 0 : return build_int_cst (long_long_integer_type_node, diff.to_shwi ());
10977 0 : }
10978 :
10979 295 : if (TREE_CODE (t1) != VECTOR_CST
10980 295 : || TREE_CODE (t2) != VECTOR_CST
10981 590 : || !known_eq (VECTOR_CST_NELTS (t1), VECTOR_CST_NELTS (t2)))
10982 : return NULL_TREE;
10983 :
10984 295 : widest_int diff;
10985 295 : bool diff_p = false;
10986 :
10987 295 : if (VECTOR_CST_LOG2_NPATTERNS (t1) == VECTOR_CST_LOG2_NPATTERNS (t2)
10988 295 : && (VECTOR_CST_NELTS_PER_PATTERN (t1)
10989 295 : == VECTOR_CST_NELTS_PER_PATTERN (t2)))
10990 : {
10991 295 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t1);
10992 295 : gcc_assert (encoded_nelts == vector_cst_encoded_nelts (t2));
10993 :
10994 389 : for (unsigned int i = 0; i < encoded_nelts; ++i)
10995 590 : if (!record_uniform_integer_difference (VECTOR_CST_ENCODED_ELT (t1, i),
10996 295 : VECTOR_CST_ENCODED_ELT (t2, i),
10997 : &diff, &diff_p))
10998 : return NULL_TREE;
10999 : }
11000 : else
11001 : {
11002 0 : unsigned HOST_WIDE_INT nelts;
11003 0 : if (!VECTOR_CST_NELTS (t1).is_constant (&nelts))
11004 295 : return NULL_TREE;
11005 :
11006 0 : for (unsigned HOST_WIDE_INT i = 0; i < nelts; ++i)
11007 0 : if (!record_uniform_integer_difference (vector_cst_elt (t1, i),
11008 0 : vector_cst_elt (t2, i),
11009 : &diff, &diff_p))
11010 : return NULL_TREE;
11011 : }
11012 :
11013 94 : if (!diff_p || !wi::fits_shwi_p (diff))
11014 : return NULL_TREE;
11015 :
11016 94 : return build_int_cst (long_long_integer_type_node, diff.to_shwi ());
11017 295 : }
11018 :
11019 : /* Checks to see if T is a constant or a constant vector and if each element E
11020 : adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE. */
11021 :
11022 : tree
11023 3020509 : bitmask_inv_cst_vector_p (tree t)
11024 : {
11025 :
11026 3020509 : tree_code code = TREE_CODE (t);
11027 3020509 : tree type = TREE_TYPE (t);
11028 :
11029 3020509 : if (!INTEGRAL_TYPE_P (type)
11030 3020509 : && !VECTOR_INTEGER_TYPE_P (type))
11031 : return NULL_TREE;
11032 :
11033 3020481 : unsigned HOST_WIDE_INT nelts = 1;
11034 3020481 : tree cst;
11035 3020481 : unsigned int idx = 0;
11036 3020481 : bool uniform = uniform_integer_cst_p (t);
11037 3020481 : tree newtype = unsigned_type_for (type);
11038 3020481 : tree_vector_builder builder;
11039 3020481 : if (code == INTEGER_CST)
11040 : cst = t;
11041 : else
11042 : {
11043 17641 : if (!VECTOR_CST_NELTS (t).is_constant (&nelts))
11044 : return NULL_TREE;
11045 :
11046 17641 : cst = vector_cst_elt (t, 0);
11047 17641 : builder.new_vector (newtype, nelts, 1);
11048 : }
11049 :
11050 3020481 : tree ty = unsigned_type_for (TREE_TYPE (cst));
11051 :
11052 3020493 : do
11053 : {
11054 3020493 : if (idx > 0)
11055 12 : cst = vector_cst_elt (t, idx);
11056 3020493 : wide_int icst = wi::to_wide (cst);
11057 3020493 : wide_int inv = wi::bit_not (icst);
11058 3020493 : icst = wi::add (1, inv);
11059 3020493 : if (wi::popcount (icst) != 1)
11060 : return NULL_TREE;
11061 :
11062 16005 : tree newcst = wide_int_to_tree (ty, inv);
11063 :
11064 16005 : if (uniform)
11065 15989 : return build_uniform_cst (newtype, newcst);
11066 :
11067 16 : builder.quick_push (newcst);
11068 3020493 : }
11069 16 : while (++idx < nelts);
11070 :
11071 4 : return builder.build ();
11072 3020481 : }
11073 :
11074 : /* If VECTOR_CST T has a single nonzero element, return the index of that
11075 : element, otherwise return -1. */
11076 :
11077 : int
11078 179 : single_nonzero_element (const_tree t)
11079 : {
11080 179 : unsigned HOST_WIDE_INT nelts;
11081 179 : unsigned int repeat_nelts;
11082 179 : if (VECTOR_CST_NELTS (t).is_constant (&nelts))
11083 179 : repeat_nelts = nelts;
11084 : else if (VECTOR_CST_NELTS_PER_PATTERN (t) == 2)
11085 : {
11086 : nelts = vector_cst_encoded_nelts (t);
11087 : repeat_nelts = VECTOR_CST_NPATTERNS (t);
11088 : }
11089 : else
11090 : return -1;
11091 :
11092 179 : int res = -1;
11093 565 : for (unsigned int i = 0; i < nelts; ++i)
11094 : {
11095 530 : tree elt = vector_cst_elt (t, i);
11096 530 : if (!integer_zerop (elt) && !real_zerop (elt))
11097 : {
11098 323 : if (res >= 0 || i >= repeat_nelts)
11099 : return -1;
11100 179 : res = i;
11101 : }
11102 : }
11103 : return res;
11104 : }
11105 :
11106 : /* Build an empty statement at location LOC. */
11107 :
11108 : tree
11109 16172959 : build_empty_stmt (location_t loc)
11110 : {
11111 16172959 : tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
11112 16172959 : SET_EXPR_LOCATION (t, loc);
11113 16172959 : return t;
11114 : }
11115 :
11116 :
11117 : /* Build an OMP clause with code CODE. LOC is the location of the
11118 : clause. */
11119 :
11120 : tree
11121 1768246 : build_omp_clause (location_t loc, enum omp_clause_code code)
11122 : {
11123 1768246 : tree t;
11124 1768246 : int size, length;
11125 :
11126 1768246 : length = omp_clause_num_ops[code];
11127 1768246 : size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
11128 :
11129 1768246 : record_node_allocation_statistics (OMP_CLAUSE, size);
11130 :
11131 1768246 : t = (tree) ggc_internal_alloc (size);
11132 1768246 : memset (t, 0, size);
11133 1768246 : TREE_SET_CODE (t, OMP_CLAUSE);
11134 1768246 : OMP_CLAUSE_SET_CODE (t, code);
11135 1768246 : OMP_CLAUSE_LOCATION (t) = loc;
11136 :
11137 1768246 : return t;
11138 : }
11139 :
11140 : /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
11141 : includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
11142 : Except for the CODE and operand count field, other storage for the
11143 : object is initialized to zeros. */
11144 :
11145 : tree
11146 549676967 : build_vl_exp (enum tree_code code, int len MEM_STAT_DECL)
11147 : {
11148 549676967 : tree t;
11149 549676967 : int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
11150 :
11151 549676967 : gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
11152 549676967 : gcc_assert (len >= 1);
11153 :
11154 549676967 : record_node_allocation_statistics (code, length);
11155 :
11156 549676967 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
11157 :
11158 549676967 : TREE_SET_CODE (t, code);
11159 :
11160 : /* Can't use TREE_OPERAND to store the length because if checking is
11161 : enabled, it will try to check the length before we store it. :-P */
11162 549676967 : t->exp.operands[0] = build_int_cst (sizetype, len);
11163 :
11164 549676967 : return t;
11165 : }
11166 :
11167 : /* Helper function for build_call_* functions; build a CALL_EXPR with
11168 : indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
11169 : the argument slots. */
11170 :
11171 : static tree
11172 295000911 : build_call_1 (tree return_type, tree fn, int nargs)
11173 : {
11174 295000911 : tree t;
11175 :
11176 295000911 : t = build_vl_exp (CALL_EXPR, nargs + 3);
11177 295000911 : TREE_TYPE (t) = return_type;
11178 295000911 : CALL_EXPR_FN (t) = fn;
11179 295000911 : CALL_EXPR_STATIC_CHAIN (t) = NULL;
11180 :
11181 295000911 : return t;
11182 : }
11183 :
11184 : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11185 : FN and a null static chain slot. NARGS is the number of call arguments
11186 : which are specified as a va_list ARGS. */
11187 :
11188 : tree
11189 136057 : build_call_valist (tree return_type, tree fn, int nargs, va_list args)
11190 : {
11191 136057 : tree t;
11192 136057 : int i;
11193 :
11194 136057 : t = build_call_1 (return_type, fn, nargs);
11195 551971 : for (i = 0; i < nargs; i++)
11196 279857 : CALL_EXPR_ARG (t, i) = va_arg (args, tree);
11197 136057 : process_call_operands (t);
11198 136057 : return t;
11199 : }
11200 :
11201 : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11202 : FN and a null static chain slot. ARGS specifies the call arguments. */
11203 :
11204 : tree
11205 266 : build_call (tree return_type, tree fn, std::initializer_list<tree> args)
11206 : {
11207 266 : tree t;
11208 266 : int i;
11209 266 : int nargs = args.size();
11210 :
11211 266 : t = build_call_1 (return_type, fn, nargs);
11212 1024 : for (i = 0; i < nargs; i++)
11213 492 : CALL_EXPR_ARG (t, i) = args.begin()[i];
11214 266 : process_call_operands (t);
11215 266 : return t;
11216 : }
11217 :
11218 : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11219 : FN and a null static chain slot. NARGS is the number of call arguments
11220 : which are specified as a tree array ARGS. */
11221 :
11222 : tree
11223 247029059 : build_call_array_loc (location_t loc, tree return_type, tree fn,
11224 : int nargs, const tree *args)
11225 : {
11226 247029059 : tree t;
11227 247029059 : int i;
11228 :
11229 247029059 : t = build_call_1 (return_type, fn, nargs);
11230 826609320 : for (i = 0; i < nargs; i++)
11231 332551202 : CALL_EXPR_ARG (t, i) = args[i];
11232 247029059 : process_call_operands (t);
11233 247029059 : SET_EXPR_LOCATION (t, loc);
11234 247029059 : return t;
11235 : }
11236 :
11237 : /* Like build_call_array, but takes a vec. */
11238 :
11239 : tree
11240 47021301 : build_call_vec (tree return_type, tree fn, const vec<tree, va_gc> *args)
11241 : {
11242 47021301 : tree ret, t;
11243 47021301 : unsigned int ix;
11244 :
11245 47021301 : ret = build_call_1 (return_type, fn, vec_safe_length (args));
11246 129651050 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
11247 35608448 : CALL_EXPR_ARG (ret, ix) = t;
11248 47021301 : process_call_operands (ret);
11249 47021301 : return ret;
11250 : }
11251 :
11252 : /* Conveniently construct a function call expression. FNDECL names the
11253 : function to be called and N arguments are passed in the array
11254 : ARGARRAY. */
11255 :
11256 : tree
11257 24169414 : build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray)
11258 : {
11259 24169414 : tree fntype = TREE_TYPE (fndecl);
11260 24169414 : tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
11261 :
11262 24169414 : return fold_build_call_array_loc (loc, TREE_TYPE (fntype), fn, n, argarray);
11263 : }
11264 :
11265 : /* Conveniently construct a function call expression. FNDECL names the
11266 : function to be called and the arguments are passed in the vector
11267 : VEC. */
11268 :
11269 : tree
11270 20908 : build_call_expr_loc_vec (location_t loc, tree fndecl, vec<tree, va_gc> *vec)
11271 : {
11272 20908 : return build_call_expr_loc_array (loc, fndecl, vec_safe_length (vec),
11273 20908 : vec_safe_address (vec));
11274 : }
11275 :
11276 :
11277 : /* Conveniently construct a function call expression. FNDECL names the
11278 : function to be called, N is the number of arguments, and the "..."
11279 : parameters are the argument expressions. */
11280 :
11281 : tree
11282 22073538 : build_call_expr_loc (location_t loc, tree fndecl, int n, ...)
11283 : {
11284 22073538 : va_list ap;
11285 22073538 : tree *argarray = XALLOCAVEC (tree, n);
11286 22073538 : int i;
11287 :
11288 22073538 : va_start (ap, n);
11289 24978476 : for (i = 0; i < n; i++)
11290 2904938 : argarray[i] = va_arg (ap, tree);
11291 22073538 : va_end (ap);
11292 22073538 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11293 : }
11294 :
11295 : /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
11296 : varargs macros aren't supported by all bootstrap compilers. */
11297 :
11298 : tree
11299 2070478 : build_call_expr (tree fndecl, int n, ...)
11300 : {
11301 2070478 : va_list ap;
11302 2070478 : tree *argarray = XALLOCAVEC (tree, n);
11303 2070478 : int i;
11304 :
11305 2070478 : va_start (ap, n);
11306 6207483 : for (i = 0; i < n; i++)
11307 4137005 : argarray[i] = va_arg (ap, tree);
11308 2070478 : va_end (ap);
11309 2070478 : return build_call_expr_loc_array (UNKNOWN_LOCATION, fndecl, n, argarray);
11310 : }
11311 :
11312 : /* Build an internal call to IFN, with arguments ARGS[0:N-1] and with return
11313 : type TYPE. This is just like CALL_EXPR, except its CALL_EXPR_FN is NULL.
11314 : It will get gimplified later into an ordinary internal function. */
11315 :
11316 : tree
11317 814228 : build_call_expr_internal_loc_array (location_t loc, internal_fn ifn,
11318 : tree type, int n, const tree *args)
11319 : {
11320 814228 : tree t = build_call_1 (type, NULL_TREE, n);
11321 3387919 : for (int i = 0; i < n; ++i)
11322 1759463 : CALL_EXPR_ARG (t, i) = args[i];
11323 814228 : SET_EXPR_LOCATION (t, loc);
11324 814228 : CALL_EXPR_IFN (t) = ifn;
11325 814228 : process_call_operands (t);
11326 814228 : return t;
11327 : }
11328 :
11329 : /* Build internal call expression. This is just like CALL_EXPR, except
11330 : its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
11331 : internal function. */
11332 :
11333 : tree
11334 813054 : build_call_expr_internal_loc (location_t loc, enum internal_fn ifn,
11335 : tree type, int n, ...)
11336 : {
11337 813054 : va_list ap;
11338 813054 : tree *argarray = XALLOCAVEC (tree, n);
11339 813054 : int i;
11340 :
11341 813054 : va_start (ap, n);
11342 2570157 : for (i = 0; i < n; i++)
11343 1757103 : argarray[i] = va_arg (ap, tree);
11344 813054 : va_end (ap);
11345 813054 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11346 : }
11347 :
11348 : /* Return a function call to FN, if the target is guaranteed to support it,
11349 : or null otherwise.
11350 :
11351 : N is the number of arguments, passed in the "...", and TYPE is the
11352 : type of the return value. */
11353 :
11354 : tree
11355 1968 : maybe_build_call_expr_loc (location_t loc, combined_fn fn, tree type,
11356 : int n, ...)
11357 : {
11358 1968 : va_list ap;
11359 1968 : tree *argarray = XALLOCAVEC (tree, n);
11360 1968 : int i;
11361 :
11362 1968 : va_start (ap, n);
11363 5165 : for (i = 0; i < n; i++)
11364 3197 : argarray[i] = va_arg (ap, tree);
11365 1968 : va_end (ap);
11366 1968 : if (internal_fn_p (fn))
11367 : {
11368 1160 : internal_fn ifn = as_internal_fn (fn);
11369 1160 : if (direct_internal_fn_p (ifn))
11370 : {
11371 3 : tree_pair types = direct_internal_fn_types (ifn, type, argarray);
11372 3 : if (!direct_internal_fn_supported_p (ifn, types,
11373 : OPTIMIZE_FOR_BOTH))
11374 1 : return NULL_TREE;
11375 : }
11376 1159 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11377 : }
11378 : else
11379 : {
11380 808 : tree fndecl = builtin_decl_implicit (as_builtin_fn (fn));
11381 808 : if (!fndecl)
11382 : return NULL_TREE;
11383 700 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11384 : }
11385 : }
11386 :
11387 : /* Return a function call to the appropriate builtin alloca variant.
11388 :
11389 : SIZE is the size to be allocated. ALIGN, if non-zero, is the requested
11390 : alignment of the allocated area. MAX_SIZE, if non-negative, is an upper
11391 : bound for SIZE in case it is not a fixed value. */
11392 :
11393 : tree
11394 8966 : build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size)
11395 : {
11396 8966 : if (max_size >= 0)
11397 : {
11398 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX);
11399 0 : return
11400 0 : build_call_expr (t, 3, size, size_int (align), size_int (max_size));
11401 : }
11402 8966 : else if (align > 0)
11403 : {
11404 8966 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
11405 8966 : return build_call_expr (t, 2, size, size_int (align));
11406 : }
11407 : else
11408 : {
11409 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA);
11410 0 : return build_call_expr (t, 1, size);
11411 : }
11412 : }
11413 :
11414 : /* The built-in decl to use to mark code points believed to be unreachable.
11415 : Typically __builtin_unreachable, but __builtin_trap if
11416 : -fsanitize=unreachable -fsanitize-trap=unreachable. If only
11417 : -fsanitize=unreachable, we rely on sanopt to replace calls with the
11418 : appropriate ubsan function. When building a call directly, use
11419 : {gimple_},build_builtin_unreachable instead. */
11420 :
11421 : tree
11422 356308 : builtin_decl_unreachable ()
11423 : {
11424 356308 : enum built_in_function fncode = BUILT_IN_UNREACHABLE;
11425 :
11426 712616 : if (sanitize_flags_p (SANITIZE_UNREACHABLE)
11427 356308 : ? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
11428 355712 : : flag_unreachable_traps)
11429 22 : fncode = BUILT_IN_UNREACHABLE_TRAP;
11430 : /* For non-trapping sanitize, we will rewrite __builtin_unreachable () later,
11431 : in the sanopt pass. */
11432 :
11433 356308 : return builtin_decl_explicit (fncode);
11434 : }
11435 :
11436 : /* Build a call to __builtin_unreachable, possibly rewritten by
11437 : -fsanitize=unreachable. Use this rather than the above when practical. */
11438 :
11439 : tree
11440 20563293 : build_builtin_unreachable (location_t loc)
11441 : {
11442 20563293 : tree data = NULL_TREE;
11443 20563293 : tree fn = sanitize_unreachable_fn (&data, loc);
11444 20563293 : return build_call_expr_loc (loc, fn, data != NULL_TREE, data);
11445 : }
11446 :
11447 : /* Create a new constant string literal of type ELTYPE[SIZE] (or LEN
11448 : if SIZE == -1) and return a tree node representing char* pointer to
11449 : it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). When STR is nonnull
11450 : the STRING_CST value is the LEN bytes at STR (the representation
11451 : of the string, which may be wide). Otherwise it's all zeros. */
11452 :
11453 : tree
11454 267510 : build_string_literal (unsigned len, const char *str /* = NULL */,
11455 : tree eltype /* = char_type_node */,
11456 : unsigned HOST_WIDE_INT size /* = -1 */)
11457 : {
11458 267510 : tree t = build_string (len, str);
11459 : /* Set the maximum valid index based on the string length or SIZE. */
11460 535020 : unsigned HOST_WIDE_INT maxidx
11461 267510 : = (size == HOST_WIDE_INT_M1U ? len : size) - 1;
11462 :
11463 267510 : tree index = build_index_type (size_int (maxidx));
11464 267510 : eltype = build_type_variant (eltype, 1, 0);
11465 267510 : tree type = build_array_type (eltype, index);
11466 267510 : TREE_TYPE (t) = type;
11467 267510 : TREE_CONSTANT (t) = 1;
11468 267510 : TREE_READONLY (t) = 1;
11469 267510 : TREE_STATIC (t) = 1;
11470 :
11471 267510 : type = build_pointer_type (eltype);
11472 267510 : t = build1 (ADDR_EXPR, type,
11473 : build4 (ARRAY_REF, eltype,
11474 : t, integer_zero_node, NULL_TREE, NULL_TREE));
11475 267510 : return t;
11476 : }
11477 :
11478 :
11479 :
11480 : /* Return true if T (assumed to be a DECL) must be assigned a memory
11481 : location. */
11482 :
11483 : bool
11484 2018319173 : needs_to_live_in_memory (const_tree t)
11485 : {
11486 2018319173 : return (TREE_ADDRESSABLE (t)
11487 1640956852 : || is_global_var (t)
11488 3206677380 : || (TREE_CODE (t) == RESULT_DECL
11489 8438946 : && !DECL_BY_REFERENCE (t)
11490 5899051 : && aggregate_value_p (t, current_function_decl)));
11491 : }
11492 :
11493 : /* Return value of a constant X and sign-extend it. */
11494 :
11495 : HOST_WIDE_INT
11496 776360994 : int_cst_value (const_tree x)
11497 : {
11498 776360994 : unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
11499 776360994 : unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
11500 :
11501 : /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
11502 776360994 : gcc_assert (cst_and_fits_in_hwi (x));
11503 :
11504 776360994 : if (bits < HOST_BITS_PER_WIDE_INT)
11505 : {
11506 761564253 : bool negative = ((val >> (bits - 1)) & 1) != 0;
11507 761564253 : if (negative)
11508 222654 : val |= HOST_WIDE_INT_M1U << (bits - 1) << 1;
11509 : else
11510 761341599 : val &= ~(HOST_WIDE_INT_M1U << (bits - 1) << 1);
11511 : }
11512 :
11513 776360994 : return val;
11514 : }
11515 :
11516 : /* If TYPE is an integral or pointer type, return an integer type with
11517 : the same precision which is unsigned iff UNSIGNEDP is true, or itself
11518 : if TYPE is already an integer type of signedness UNSIGNEDP.
11519 : If TYPE is a floating-point type, return an integer type with the same
11520 : bitsize and with the signedness given by UNSIGNEDP; this is useful
11521 : when doing bit-level operations on a floating-point value. */
11522 :
11523 : tree
11524 89100552 : signed_or_unsigned_type_for (int unsignedp, tree type)
11525 : {
11526 89100552 : if (ANY_INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) == unsignedp)
11527 : return type;
11528 :
11529 57339839 : if (TREE_CODE (type) == VECTOR_TYPE)
11530 : {
11531 28926 : tree inner = TREE_TYPE (type);
11532 28926 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11533 28926 : if (!inner2)
11534 : return NULL_TREE;
11535 28926 : if (inner == inner2)
11536 : return type;
11537 28926 : machine_mode new_mode;
11538 57852 : if (VECTOR_MODE_P (TYPE_MODE (type))
11539 57768 : && related_int_vector_mode (TYPE_MODE (type)).exists (&new_mode))
11540 28842 : return build_vector_type_for_mode (inner2, new_mode);
11541 84 : return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
11542 : }
11543 :
11544 : if (TREE_CODE (type) == COMPLEX_TYPE)
11545 : {
11546 24 : tree inner = TREE_TYPE (type);
11547 24 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11548 24 : if (!inner2)
11549 : return NULL_TREE;
11550 24 : if (inner == inner2)
11551 : return type;
11552 24 : return build_complex_type (inner2);
11553 : }
11554 :
11555 : unsigned int bits;
11556 : if (INTEGRAL_TYPE_P (type)
11557 : || POINTER_TYPE_P (type)
11558 : || TREE_CODE (type) == OFFSET_TYPE)
11559 57310795 : bits = TYPE_PRECISION (type);
11560 : else if (TREE_CODE (type) == REAL_TYPE)
11561 188 : bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (type));
11562 : else
11563 : return NULL_TREE;
11564 :
11565 57310889 : if (TREE_CODE (type) == BITINT_TYPE)
11566 2091 : return build_bitint_type (bits, unsignedp);
11567 57308798 : return build_nonstandard_integer_type (bits, unsignedp);
11568 : }
11569 :
11570 : /* If TYPE is an integral or pointer type, return an integer type with
11571 : the same precision which is unsigned, or itself if TYPE is already an
11572 : unsigned integer type. If TYPE is a floating-point type, return an
11573 : unsigned integer type with the same bitsize as TYPE. */
11574 :
11575 : tree
11576 79049995 : unsigned_type_for (tree type)
11577 : {
11578 79049995 : return signed_or_unsigned_type_for (1, type);
11579 : }
11580 :
11581 : /* If TYPE is an integral or pointer type, return an integer type with
11582 : the same precision which is signed, or itself if TYPE is already a
11583 : signed integer type. If TYPE is a floating-point type, return a
11584 : signed integer type with the same bitsize as TYPE. */
11585 :
11586 : tree
11587 10016243 : signed_type_for (tree type)
11588 : {
11589 10016243 : return signed_or_unsigned_type_for (0, type);
11590 : }
11591 :
11592 : /* - For VECTOR_TYPEs:
11593 : - The truth type must be a VECTOR_BOOLEAN_TYPE.
11594 : - The number of elements must match (known_eq).
11595 : - targetm.vectorize.get_mask_mode exists, and exactly
11596 : the same mode as the truth type.
11597 : - Otherwise, the truth type must be a BOOLEAN_TYPE
11598 : or useless_type_conversion_p to BOOLEAN_TYPE. */
11599 : bool
11600 1422 : is_truth_type_for (tree type, tree truth_type)
11601 : {
11602 1422 : machine_mode mask_mode = TYPE_MODE (truth_type);
11603 1422 : machine_mode vmode = TYPE_MODE (type);
11604 1422 : machine_mode tmask_mode;
11605 :
11606 1422 : if (TREE_CODE (type) == VECTOR_TYPE)
11607 : {
11608 1422 : if (VECTOR_BOOLEAN_TYPE_P (truth_type)
11609 1422 : && known_eq (TYPE_VECTOR_SUBPARTS (type),
11610 : TYPE_VECTOR_SUBPARTS (truth_type))
11611 1422 : && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode)
11612 2844 : && tmask_mode == mask_mode)
11613 1403 : return true;
11614 :
11615 19 : return false;
11616 : }
11617 :
11618 0 : return useless_type_conversion_p (boolean_type_node, truth_type);
11619 : }
11620 :
11621 : /* If TYPE is a vector type, return a signed integer vector type with the
11622 : same width and number of subparts. Otherwise return boolean_type_node. */
11623 :
11624 : tree
11625 5307105 : truth_type_for (tree type)
11626 : {
11627 5307105 : if (TREE_CODE (type) == VECTOR_TYPE)
11628 : {
11629 2822089 : if (VECTOR_BOOLEAN_TYPE_P (type))
11630 : return type;
11631 2764779 : return build_truth_vector_type_for (type);
11632 : }
11633 : else
11634 2485016 : return boolean_type_node;
11635 : }
11636 :
11637 : /* Returns the largest value obtainable by casting something in INNER type to
11638 : OUTER type. */
11639 :
11640 : tree
11641 11108445 : upper_bound_in_type (tree outer, tree inner)
11642 : {
11643 11108445 : unsigned int det = 0;
11644 11108445 : unsigned oprec = TYPE_PRECISION (outer);
11645 11108445 : unsigned iprec = TYPE_PRECISION (inner);
11646 11108445 : unsigned prec;
11647 :
11648 : /* Compute a unique number for every combination. */
11649 11108445 : det |= (oprec > iprec) ? 4 : 0;
11650 11108445 : det |= TYPE_UNSIGNED (outer) ? 2 : 0;
11651 11108445 : det |= TYPE_UNSIGNED (inner) ? 1 : 0;
11652 :
11653 : /* Determine the exponent to use. */
11654 11108445 : switch (det)
11655 : {
11656 7476402 : case 0:
11657 7476402 : case 1:
11658 : /* oprec <= iprec, outer: signed, inner: don't care. */
11659 7476402 : prec = oprec - 1;
11660 7476402 : break;
11661 : case 2:
11662 : case 3:
11663 : /* oprec <= iprec, outer: unsigned, inner: don't care. */
11664 : prec = oprec;
11665 : break;
11666 23106 : case 4:
11667 : /* oprec > iprec, outer: signed, inner: signed. */
11668 23106 : prec = iprec - 1;
11669 23106 : break;
11670 : case 5:
11671 : /* oprec > iprec, outer: signed, inner: unsigned. */
11672 9737 : prec = iprec;
11673 : break;
11674 : case 6:
11675 : /* oprec > iprec, outer: unsigned, inner: signed. */
11676 : prec = oprec;
11677 : break;
11678 : case 7:
11679 : /* oprec > iprec, outer: unsigned, inner: unsigned. */
11680 9737 : prec = iprec;
11681 : break;
11682 : default:
11683 : gcc_unreachable ();
11684 : }
11685 :
11686 11108445 : return wide_int_to_tree (outer,
11687 11108445 : wi::mask (prec, false, TYPE_PRECISION (outer)));
11688 : }
11689 :
11690 : /* Returns the smallest value obtainable by casting something in INNER type to
11691 : OUTER type. */
11692 :
11693 : tree
11694 8454940 : lower_bound_in_type (tree outer, tree inner)
11695 : {
11696 8454940 : unsigned oprec = TYPE_PRECISION (outer);
11697 8454940 : unsigned iprec = TYPE_PRECISION (inner);
11698 :
11699 : /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
11700 : and obtain 0. */
11701 8454940 : if (TYPE_UNSIGNED (outer)
11702 : /* If we are widening something of an unsigned type, OUTER type
11703 : contains all values of INNER type. In particular, both INNER
11704 : and OUTER types have zero in common. */
11705 8454940 : || (oprec > iprec && TYPE_UNSIGNED (inner)))
11706 2250524 : return build_int_cst (outer, 0);
11707 : else
11708 : {
11709 : /* If we are widening a signed type to another signed type, we
11710 : want to obtain -2^^(iprec-1). If we are keeping the
11711 : precision or narrowing to a signed type, we want to obtain
11712 : -2^(oprec-1). */
11713 6204416 : unsigned prec = oprec > iprec ? iprec : oprec;
11714 6204416 : return wide_int_to_tree (outer,
11715 12408832 : wi::mask (prec - 1, true,
11716 6204416 : TYPE_PRECISION (outer)));
11717 : }
11718 : }
11719 :
11720 : /* Return true if two operands that are suitable for PHI nodes are
11721 : necessarily equal. Specifically, both ARG0 and ARG1 must be either
11722 : SSA_NAME or invariant. Note that this is strictly an optimization.
11723 : That is, callers of this function can directly call operand_equal_p
11724 : and get the same result, only slower. */
11725 :
11726 : bool
11727 22188777 : operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
11728 : {
11729 22188777 : if (arg0 == arg1)
11730 : return true;
11731 20430297 : if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
11732 : return false;
11733 4375592 : return operand_equal_p (arg0, arg1, 0);
11734 : }
11735 :
11736 : /* Returns number of zeros at the end of binary representation of X. */
11737 :
11738 : tree
11739 9268849 : num_ending_zeros (const_tree x)
11740 : {
11741 9268849 : return build_int_cst (TREE_TYPE (x), wi::ctz (wi::to_wide (x)));
11742 : }
11743 :
11744 :
11745 : #define WALK_SUBTREE(NODE) \
11746 : do \
11747 : { \
11748 : result = walk_tree_1 (&(NODE), func, data, pset, lh); \
11749 : if (result) \
11750 : return result; \
11751 : } \
11752 : while (0)
11753 :
11754 : /* This is a subroutine of walk_tree that walks field of TYPE that are to
11755 : be walked whenever a type is seen in the tree. Rest of operands and return
11756 : value are as for walk_tree. */
11757 :
11758 : static tree
11759 5249209211 : walk_type_fields (tree type, walk_tree_fn func, void *data,
11760 : hash_set<tree> *pset, walk_tree_lh lh)
11761 : {
11762 5249209211 : tree result = NULL_TREE;
11763 :
11764 5249209211 : switch (TREE_CODE (type))
11765 : {
11766 1526850412 : case POINTER_TYPE:
11767 1526850412 : case REFERENCE_TYPE:
11768 1526850412 : case VECTOR_TYPE:
11769 : /* We have to worry about mutually recursive pointers. These can't
11770 : be written in C. They can in Ada. It's pathological, but
11771 : there's an ACATS test (c38102a) that checks it. Deal with this
11772 : by checking if we're pointing to another pointer, that one
11773 : points to another pointer, that one does too, and we have no htab.
11774 : If so, get a hash table. We check three levels deep to avoid
11775 : the cost of the hash table if we don't need one. */
11776 3003523366 : if (POINTER_TYPE_P (TREE_TYPE (type))
11777 50177525 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
11778 7329671 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
11779 1534078694 : && !pset)
11780 : {
11781 0 : result = walk_tree_without_duplicates (&TREE_TYPE (type),
11782 : func, data);
11783 0 : if (result)
11784 : return result;
11785 :
11786 : break;
11787 : }
11788 :
11789 : /* fall through */
11790 :
11791 1529817618 : case COMPLEX_TYPE:
11792 1529817618 : WALK_SUBTREE (TREE_TYPE (type));
11793 : break;
11794 :
11795 267505551 : case METHOD_TYPE:
11796 267505551 : WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
11797 :
11798 : /* Fall through. */
11799 :
11800 436766513 : case FUNCTION_TYPE:
11801 436766513 : WALK_SUBTREE (TREE_TYPE (type));
11802 436766471 : {
11803 436766471 : tree arg;
11804 :
11805 : /* We never want to walk into default arguments. */
11806 1674717191 : for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
11807 1237979481 : WALK_SUBTREE (TREE_VALUE (arg));
11808 : }
11809 : break;
11810 :
11811 17086475 : case ARRAY_TYPE:
11812 : /* Don't follow this nodes's type if a pointer for fear that
11813 : we'll have infinite recursion. If we have a PSET, then we
11814 : need not fear. */
11815 17086475 : if (pset
11816 17086475 : || (!POINTER_TYPE_P (TREE_TYPE (type))
11817 163647 : && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
11818 17065609 : WALK_SUBTREE (TREE_TYPE (type));
11819 17083852 : WALK_SUBTREE (TYPE_DOMAIN (type));
11820 : break;
11821 :
11822 1137771 : case OFFSET_TYPE:
11823 1137771 : WALK_SUBTREE (TREE_TYPE (type));
11824 1136907 : WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
11825 : break;
11826 :
11827 : default:
11828 : break;
11829 : }
11830 :
11831 : return NULL_TREE;
11832 : }
11833 :
11834 : /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11835 : called with the DATA and the address of each sub-tree. If FUNC returns a
11836 : non-NULL value, the traversal is stopped, and the value returned by FUNC
11837 : is returned. If PSET is non-NULL it is used to record the nodes visited,
11838 : and to avoid visiting a node more than once. */
11839 :
11840 : tree
11841 >11144*10^7 : walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
11842 : hash_set<tree> *pset, walk_tree_lh lh)
11843 : {
11844 : #define WALK_SUBTREE_TAIL(NODE) \
11845 : do \
11846 : { \
11847 : tp = & (NODE); \
11848 : goto tail_recurse; \
11849 : } \
11850 : while (0)
11851 :
11852 26135574211 : tail_recurse:
11853 : /* Skip empty subtrees. */
11854 >13757*10^7 : if (!*tp)
11855 : return NULL_TREE;
11856 :
11857 : /* Don't walk the same tree twice, if the user has requested
11858 : that we avoid doing so. */
11859 >11376*10^7 : if (pset && pset->add (*tp))
11860 : return NULL_TREE;
11861 :
11862 : /* Call the function. */
11863 >11198*10^7 : int walk_subtrees = 1;
11864 >11198*10^7 : tree result = (*func) (tp, &walk_subtrees, data);
11865 :
11866 : /* If we found something, return it. */
11867 >11198*10^7 : if (result)
11868 : return result;
11869 :
11870 >11190*10^7 : tree t = *tp;
11871 >11190*10^7 : tree_code code = TREE_CODE (t);
11872 :
11873 : /* Even if we didn't, FUNC may have decided that there was nothing
11874 : interesting below this point in the tree. */
11875 >11190*10^7 : if (!walk_subtrees)
11876 : {
11877 : /* But we still need to check our siblings. */
11878 68588625529 : if (code == TREE_LIST)
11879 107445 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11880 68588518084 : else if (code == OMP_CLAUSE)
11881 891321 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11882 : else
11883 : return NULL_TREE;
11884 : }
11885 :
11886 43318287050 : if (lh)
11887 : {
11888 25504226176 : result = (*lh) (tp, &walk_subtrees, func, data, pset);
11889 25504226176 : if (result || !walk_subtrees)
11890 : return result;
11891 : }
11892 :
11893 40373575490 : switch (code)
11894 : {
11895 : case ERROR_MARK:
11896 : case IDENTIFIER_NODE:
11897 : case INTEGER_CST:
11898 : case REAL_CST:
11899 : case FIXED_CST:
11900 : case STRING_CST:
11901 : case BLOCK:
11902 : case PLACEHOLDER_EXPR:
11903 : case SSA_NAME:
11904 : case FIELD_DECL:
11905 : case RESULT_DECL:
11906 : /* None of these have subtrees other than those already walked
11907 : above. */
11908 : break;
11909 :
11910 286665810 : case TREE_LIST:
11911 286665810 : WALK_SUBTREE (TREE_VALUE (t));
11912 286174462 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11913 :
11914 1348385999 : case TREE_VEC:
11915 1348385999 : {
11916 1348385999 : int len = TREE_VEC_LENGTH (t);
11917 :
11918 1348385999 : if (len == 0)
11919 : break;
11920 :
11921 : /* Walk all elements but the last. */
11922 2475317270 : for (int i = 0; i < len - 1; ++i)
11923 1136704407 : WALK_SUBTREE (TREE_VEC_ELT (t, i));
11924 :
11925 : /* Now walk the last one as a tail call. */
11926 1338612863 : WALK_SUBTREE_TAIL (TREE_VEC_ELT (t, len - 1));
11927 : }
11928 :
11929 5589131 : case VECTOR_CST:
11930 5589131 : {
11931 5589131 : unsigned len = vector_cst_encoded_nelts (t);
11932 5589131 : if (len == 0)
11933 : break;
11934 : /* Walk all elements but the last. */
11935 18431258 : for (unsigned i = 0; i < len - 1; ++i)
11936 12842295 : WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (t, i));
11937 : /* Now walk the last one as a tail call. */
11938 5588963 : WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (t, len - 1));
11939 : }
11940 :
11941 640640 : case COMPLEX_CST:
11942 640640 : WALK_SUBTREE (TREE_REALPART (t));
11943 639074 : WALK_SUBTREE_TAIL (TREE_IMAGPART (t));
11944 :
11945 : case CONSTRUCTOR:
11946 : {
11947 : unsigned HOST_WIDE_INT idx;
11948 : constructor_elt *ce;
11949 :
11950 967215201 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce);
11951 : idx++)
11952 497271053 : WALK_SUBTREE (ce->value);
11953 : }
11954 : break;
11955 :
11956 4859380 : case SAVE_EXPR:
11957 4859380 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, 0));
11958 :
11959 271754953 : case BIND_EXPR:
11960 271754953 : {
11961 271754953 : tree decl;
11962 439089679 : for (decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
11963 : {
11964 : /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11965 : into declarations that are just mentioned, rather than
11966 : declared; they don't really belong to this part of the tree.
11967 : And, we can see cycles: the initializer for a declaration
11968 : can refer to the declaration itself. */
11969 167334750 : WALK_SUBTREE (DECL_INITIAL (decl));
11970 167334726 : WALK_SUBTREE (DECL_SIZE (decl));
11971 167334726 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
11972 : }
11973 271754929 : WALK_SUBTREE_TAIL (BIND_EXPR_BODY (t));
11974 : }
11975 :
11976 366542010 : case STATEMENT_LIST:
11977 366542010 : {
11978 366542010 : tree_stmt_iterator i;
11979 1318696396 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
11980 952347875 : WALK_SUBTREE (*tsi_stmt_ptr (i));
11981 : }
11982 366348521 : break;
11983 :
11984 1845475 : case OMP_CLAUSE:
11985 1845475 : {
11986 1845475 : int len = omp_clause_num_ops[OMP_CLAUSE_CODE (t)];
11987 : /* Do not walk the iterator operand of OpenMP MAP clauses. */
11988 1845475 : if (OMP_CLAUSE_HAS_ITERATORS (t))
11989 1578 : len--;
11990 5260497 : for (int i = 0; i < len; i++)
11991 3415022 : WALK_SUBTREE (OMP_CLAUSE_OPERAND (t, i));
11992 1845475 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11993 : }
11994 :
11995 82375604 : case TARGET_EXPR:
11996 82375604 : {
11997 82375604 : int i, len;
11998 :
11999 : /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
12000 : But, we only want to walk once. */
12001 82375604 : len = (TREE_OPERAND (t, 3) == TREE_OPERAND (t, 1)) ? 2 : 3;
12002 329467290 : for (i = 0; i < len; ++i)
12003 247109197 : WALK_SUBTREE (TREE_OPERAND (t, i));
12004 82358093 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len));
12005 : }
12006 :
12007 164132840 : case DECL_EXPR:
12008 : /* If this is a TYPE_DECL, walk into the fields of the type that it's
12009 : defining. We only want to walk into these fields of a type in this
12010 : case and not in the general case of a mere reference to the type.
12011 :
12012 : The criterion is as follows: if the field can be an expression, it
12013 : must be walked only here. This should be in keeping with the fields
12014 : that are directly gimplified in gimplify_type_sizes in order for the
12015 : mark/copy-if-shared/unmark machinery of the gimplifier to work with
12016 : variable-sized types.
12017 :
12018 : Note that DECLs get walked as part of processing the BIND_EXPR. */
12019 164132840 : if (TREE_CODE (DECL_EXPR_DECL (t)) == TYPE_DECL)
12020 : {
12021 : /* Call the function for the decl so e.g. copy_tree_body_r can
12022 : replace it with the remapped one. */
12023 1774267 : result = (*func) (&DECL_EXPR_DECL (t), &walk_subtrees, data);
12024 1774267 : if (result || !walk_subtrees)
12025 : return result;
12026 :
12027 1728827 : tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (t));
12028 1728827 : if (TREE_CODE (*type_p) == ERROR_MARK)
12029 : return NULL_TREE;
12030 :
12031 : /* Call the function for the type. See if it returns anything or
12032 : doesn't want us to continue. If we are to continue, walk both
12033 : the normal fields and those for the declaration case. */
12034 1728827 : result = (*func) (type_p, &walk_subtrees, data);
12035 1728827 : if (result || !walk_subtrees)
12036 : return result;
12037 :
12038 1634176 : tree type = *type_p;
12039 :
12040 : /* But do not walk a pointed-to type since it may itself need to
12041 : be walked in the declaration case if it isn't anonymous. */
12042 1634176 : if (!POINTER_TYPE_P (type))
12043 : {
12044 1618469 : result = walk_type_fields (type, func, data, pset, lh);
12045 1618469 : if (result)
12046 : return result;
12047 : }
12048 :
12049 : /* If this is a record type, also walk the fields. */
12050 1634176 : if (RECORD_OR_UNION_TYPE_P (type))
12051 : {
12052 494483 : tree field;
12053 :
12054 2314443 : for (field = TYPE_FIELDS (type); field;
12055 1819960 : field = DECL_CHAIN (field))
12056 : {
12057 : /* We'd like to look at the type of the field, but we can
12058 : easily get infinite recursion. So assume it's pointed
12059 : to elsewhere in the tree. Also, ignore things that
12060 : aren't fields. */
12061 1819960 : if (TREE_CODE (field) != FIELD_DECL)
12062 1367692 : continue;
12063 :
12064 452268 : WALK_SUBTREE (DECL_FIELD_OFFSET (field));
12065 452268 : WALK_SUBTREE (DECL_SIZE (field));
12066 452268 : WALK_SUBTREE (DECL_SIZE_UNIT (field));
12067 452268 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
12068 0 : WALK_SUBTREE (DECL_QUALIFIER (field));
12069 : }
12070 : }
12071 :
12072 : /* Same for scalar types. */
12073 : else if (TREE_CODE (type) == BOOLEAN_TYPE
12074 : || TREE_CODE (type) == ENUMERAL_TYPE
12075 : || TREE_CODE (type) == INTEGER_TYPE
12076 : || TREE_CODE (type) == FIXED_POINT_TYPE
12077 : || TREE_CODE (type) == REAL_TYPE)
12078 : {
12079 38213 : WALK_SUBTREE (TYPE_MIN_VALUE (type));
12080 38213 : WALK_SUBTREE (TYPE_MAX_VALUE (type));
12081 : }
12082 :
12083 1634176 : WALK_SUBTREE (TYPE_SIZE (type));
12084 1634176 : WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (type));
12085 : }
12086 : /* FALLTHRU */
12087 :
12088 32883405544 : default:
12089 32883405544 : if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
12090 : {
12091 24415441208 : int i, len;
12092 :
12093 : /* Walk over all the sub-trees of this operand. */
12094 24415441208 : len = TREE_OPERAND_LENGTH (t);
12095 :
12096 : /* Go through the subtrees. We need to do this in forward order so
12097 : that the scope of a FOR_EXPR is handled properly. */
12098 24415441208 : if (len)
12099 : {
12100 48901866803 : for (i = 0; i < len - 1; ++i)
12101 24760758773 : WALK_SUBTREE (TREE_OPERAND (t, i));
12102 24141108030 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len - 1));
12103 : }
12104 : }
12105 : /* If this is a type, walk the needed fields in the type. */
12106 8467964336 : else if (TYPE_P (t))
12107 5247590742 : return walk_type_fields (t, func, data, pset, lh);
12108 : break;
12109 : }
12110 :
12111 : /* We didn't find what we were looking for. */
12112 : return NULL_TREE;
12113 :
12114 : #undef WALK_SUBTREE_TAIL
12115 : }
12116 : #undef WALK_SUBTREE
12117 :
12118 : /* Like walk_tree, but does not walk duplicate nodes more than once. */
12119 :
12120 : tree
12121 3908607702 : walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
12122 : walk_tree_lh lh)
12123 : {
12124 3908607702 : tree result;
12125 :
12126 3908607702 : hash_set<tree> pset;
12127 3908607702 : result = walk_tree_1 (tp, func, data, &pset, lh);
12128 3908607702 : return result;
12129 3908607702 : }
12130 :
12131 :
12132 : tree
12133 1202429926 : tree_block (tree t)
12134 : {
12135 1202429926 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
12136 :
12137 1202429926 : if (IS_EXPR_CODE_CLASS (c))
12138 1202429926 : return LOCATION_BLOCK (t->exp.locus);
12139 0 : gcc_unreachable ();
12140 : return NULL;
12141 : }
12142 :
12143 : void
12144 755096272 : tree_set_block (tree t, tree b)
12145 : {
12146 755096272 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
12147 :
12148 755096272 : if (IS_EXPR_CODE_CLASS (c))
12149 : {
12150 755096272 : t->exp.locus = set_block (t->exp.locus, b);
12151 : }
12152 : else
12153 0 : gcc_unreachable ();
12154 755096272 : }
12155 :
12156 : /* Create a nameless artificial label and put it in the current
12157 : function context. The label has a location of LOC. Returns the
12158 : newly created label. */
12159 :
12160 : tree
12161 33135010 : create_artificial_label (location_t loc)
12162 : {
12163 33135010 : tree lab = build_decl (loc,
12164 : LABEL_DECL, NULL_TREE, void_type_node);
12165 :
12166 33135010 : DECL_ARTIFICIAL (lab) = 1;
12167 33135010 : DECL_IGNORED_P (lab) = 1;
12168 33135010 : DECL_CONTEXT (lab) = current_function_decl;
12169 33135010 : return lab;
12170 : }
12171 :
12172 : /* Given a tree, try to return a useful variable name that we can use
12173 : to prefix a temporary that is being assigned the value of the tree.
12174 : I.E. given <temp> = &A, return A. */
12175 :
12176 : const char *
12177 25441062 : get_name (tree t)
12178 : {
12179 27349482 : tree stripped_decl;
12180 :
12181 27349482 : stripped_decl = t;
12182 27349482 : STRIP_NOPS (stripped_decl);
12183 27349482 : if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
12184 4093647 : return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
12185 23255835 : else if (TREE_CODE (stripped_decl) == SSA_NAME)
12186 : {
12187 1392437 : tree name = SSA_NAME_IDENTIFIER (stripped_decl);
12188 340028 : if (!name)
12189 : return NULL;
12190 338469 : return IDENTIFIER_POINTER (name);
12191 : }
12192 : else
12193 : {
12194 21863398 : switch (TREE_CODE (stripped_decl))
12195 : {
12196 1908420 : case ADDR_EXPR:
12197 1908420 : return get_name (TREE_OPERAND (stripped_decl, 0));
12198 : default:
12199 : return NULL;
12200 : }
12201 : }
12202 : }
12203 :
12204 : /* Return true if TYPE has a variable argument list. */
12205 :
12206 : bool
12207 238059081 : stdarg_p (const_tree fntype)
12208 : {
12209 238059081 : function_args_iterator args_iter;
12210 238059081 : tree n = NULL_TREE, t;
12211 :
12212 238059081 : if (!fntype)
12213 : return false;
12214 :
12215 237921856 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12216 : return true;
12217 :
12218 964207174 : FOREACH_FUNCTION_ARGS (fntype, t, args_iter)
12219 : {
12220 726949377 : n = t;
12221 : }
12222 :
12223 237257797 : return n != NULL_TREE && n != void_type_node;
12224 : }
12225 :
12226 : /* Return true if TYPE has a prototype. */
12227 :
12228 : bool
12229 729421640 : prototype_p (const_tree fntype)
12230 : {
12231 729421640 : tree t;
12232 :
12233 729421640 : gcc_assert (fntype != NULL_TREE);
12234 :
12235 729421640 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12236 : return true;
12237 :
12238 728670082 : t = TYPE_ARG_TYPES (fntype);
12239 728670082 : return (t != NULL_TREE);
12240 : }
12241 :
12242 : /* If BLOCK is inlined from an __attribute__((__artificial__))
12243 : routine, return pointer to location from where it has been
12244 : called. */
12245 : location_t *
12246 174258 : block_nonartificial_location (tree block)
12247 : {
12248 174258 : location_t *ret = NULL;
12249 :
12250 446272 : while (block && TREE_CODE (block) == BLOCK
12251 538808 : && BLOCK_ABSTRACT_ORIGIN (block))
12252 : {
12253 168526 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12254 168526 : if (TREE_CODE (ao) == FUNCTION_DECL)
12255 : {
12256 : /* If AO is an artificial inline, point RET to the
12257 : call site locus at which it has been inlined and continue
12258 : the loop, in case AO's caller is also an artificial
12259 : inline. */
12260 72537 : if (DECL_DECLARED_INLINE_P (ao)
12261 72537 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
12262 1813 : ret = &BLOCK_SOURCE_LOCATION (block);
12263 : else
12264 : break;
12265 : }
12266 95989 : else if (TREE_CODE (ao) != BLOCK)
12267 : break;
12268 :
12269 97802 : block = BLOCK_SUPERCONTEXT (block);
12270 : }
12271 174258 : return ret;
12272 : }
12273 :
12274 :
12275 : /* If EXP is inlined from an __attribute__((__artificial__))
12276 : function, return the location of the original call expression. */
12277 :
12278 : location_t
12279 46 : tree_nonartificial_location (tree exp)
12280 : {
12281 46 : location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
12282 :
12283 46 : if (loc)
12284 0 : return *loc;
12285 : else
12286 46 : return EXPR_LOCATION (exp);
12287 : }
12288 :
12289 : /* Return the location into which EXP has been inlined. Analogous
12290 : to tree_nonartificial_location() above but not limited to artificial
12291 : functions declared inline. If SYSTEM_HEADER is true, return
12292 : the macro expansion point of the location if it's in a system header */
12293 :
12294 : location_t
12295 0 : tree_inlined_location (tree exp, bool system_header /* = true */)
12296 : {
12297 0 : location_t loc = UNKNOWN_LOCATION;
12298 :
12299 0 : tree block = TREE_BLOCK (exp);
12300 :
12301 0 : while (block && TREE_CODE (block) == BLOCK
12302 0 : && BLOCK_ABSTRACT_ORIGIN (block))
12303 : {
12304 0 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12305 0 : if (TREE_CODE (ao) == FUNCTION_DECL)
12306 0 : loc = BLOCK_SOURCE_LOCATION (block);
12307 0 : else if (TREE_CODE (ao) != BLOCK)
12308 : break;
12309 :
12310 0 : block = BLOCK_SUPERCONTEXT (block);
12311 : }
12312 :
12313 0 : if (loc == UNKNOWN_LOCATION)
12314 : {
12315 0 : loc = EXPR_LOCATION (exp);
12316 0 : if (system_header)
12317 : /* Only consider macro expansion when the block traversal failed
12318 : to find a location. Otherwise it's not relevant. */
12319 0 : return expansion_point_location_if_in_system_header (loc);
12320 : }
12321 :
12322 : return loc;
12323 : }
12324 :
12325 : /* These are the hash table functions for the hash table of OPTIMIZATION_NODE
12326 : nodes. */
12327 :
12328 : /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
12329 :
12330 : hashval_t
12331 845240304 : cl_option_hasher::hash (tree x)
12332 : {
12333 845240304 : const_tree const t = x;
12334 :
12335 845240304 : if (TREE_CODE (t) == OPTIMIZATION_NODE)
12336 102305162 : return cl_optimization_hash (TREE_OPTIMIZATION (t));
12337 742935142 : else if (TREE_CODE (t) == TARGET_OPTION_NODE)
12338 742935142 : return cl_target_option_hash (TREE_TARGET_OPTION (t));
12339 : else
12340 0 : gcc_unreachable ();
12341 : }
12342 :
12343 : /* Return nonzero if the value represented by *X (an OPTIMIZATION or
12344 : TARGET_OPTION tree node) is the same as that given by *Y, which is the
12345 : same. */
12346 :
12347 : bool
12348 891229828 : cl_option_hasher::equal (tree x, tree y)
12349 : {
12350 891229828 : const_tree const xt = x;
12351 891229828 : const_tree const yt = y;
12352 :
12353 891229828 : if (TREE_CODE (xt) != TREE_CODE (yt))
12354 : return false;
12355 :
12356 510172105 : if (TREE_CODE (xt) == OPTIMIZATION_NODE)
12357 100685932 : return cl_optimization_option_eq (TREE_OPTIMIZATION (xt),
12358 100685932 : TREE_OPTIMIZATION (yt));
12359 409486173 : else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
12360 409486173 : return cl_target_option_eq (TREE_TARGET_OPTION (xt),
12361 409486173 : TREE_TARGET_OPTION (yt));
12362 : else
12363 0 : gcc_unreachable ();
12364 : }
12365 :
12366 : /* Build an OPTIMIZATION_NODE based on the options in OPTS and OPTS_SET. */
12367 :
12368 : tree
12369 100979918 : build_optimization_node (struct gcc_options *opts,
12370 : struct gcc_options *opts_set)
12371 : {
12372 100979918 : tree t;
12373 :
12374 : /* Use the cache of optimization nodes. */
12375 :
12376 100979918 : cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
12377 : opts, opts_set);
12378 :
12379 100979918 : tree *slot = cl_option_hash_table->find_slot (cl_optimization_node, INSERT);
12380 100979918 : t = *slot;
12381 100979918 : if (!t)
12382 : {
12383 : /* Insert this one into the hash table. */
12384 296459 : t = cl_optimization_node;
12385 296459 : *slot = t;
12386 :
12387 : /* Make a new node for next time round. */
12388 296459 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
12389 : }
12390 :
12391 100979918 : return t;
12392 : }
12393 :
12394 : /* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET. */
12395 :
12396 : tree
12397 78164306 : build_target_option_node (struct gcc_options *opts,
12398 : struct gcc_options *opts_set)
12399 : {
12400 78164306 : tree t;
12401 :
12402 : /* Use the cache of optimization nodes. */
12403 :
12404 78164306 : cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
12405 : opts, opts_set);
12406 :
12407 78164306 : tree *slot = cl_option_hash_table->find_slot (cl_target_option_node, INSERT);
12408 78164306 : t = *slot;
12409 78164306 : if (!t)
12410 : {
12411 : /* Insert this one into the hash table. */
12412 782442 : t = cl_target_option_node;
12413 782442 : *slot = t;
12414 :
12415 : /* Make a new node for next time round. */
12416 782442 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
12417 : }
12418 :
12419 78164306 : return t;
12420 : }
12421 :
12422 : /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
12423 : so that they aren't saved during PCH writing. */
12424 :
12425 : void
12426 425 : prepare_target_option_nodes_for_pch (void)
12427 : {
12428 425 : hash_table<cl_option_hasher>::iterator iter = cl_option_hash_table->begin ();
12429 1700 : for (; iter != cl_option_hash_table->end (); ++iter)
12430 850 : if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
12431 425 : TREE_TARGET_GLOBALS (*iter) = NULL;
12432 425 : }
12433 :
12434 : /* Determine the "ultimate origin" of a block. */
12435 :
12436 : tree
12437 228636827 : block_ultimate_origin (const_tree block)
12438 : {
12439 228636827 : tree origin = BLOCK_ABSTRACT_ORIGIN (block);
12440 :
12441 228636827 : if (origin == NULL_TREE)
12442 : return NULL_TREE;
12443 : else
12444 : {
12445 282921223 : gcc_checking_assert ((DECL_P (origin)
12446 : && DECL_ORIGIN (origin) == origin)
12447 : || BLOCK_ORIGIN (origin) == origin);
12448 : return origin;
12449 : }
12450 : }
12451 :
12452 : /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
12453 : no instruction. */
12454 :
12455 : bool
12456 1768954359 : tree_nop_conversion_p (const_tree outer_type, const_tree inner_type)
12457 : {
12458 1768954359 : if (!inner_type || inner_type == error_mark_node)
12459 : return false;
12460 :
12461 : /* Do not strip casts into or out of differing address spaces. */
12462 1768916293 : if (POINTER_TYPE_P (outer_type)
12463 1768916293 : && TYPE_ADDR_SPACE (TREE_TYPE (outer_type)) != ADDR_SPACE_GENERIC)
12464 : {
12465 574 : if (!POINTER_TYPE_P (inner_type)
12466 574 : || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
12467 551 : != TYPE_ADDR_SPACE (TREE_TYPE (inner_type))))
12468 : return false;
12469 : }
12470 1768915719 : else if (POINTER_TYPE_P (inner_type)
12471 1768915719 : && TYPE_ADDR_SPACE (TREE_TYPE (inner_type)) != ADDR_SPACE_GENERIC)
12472 : {
12473 : /* We already know that outer_type is not a pointer with
12474 : a non-generic address space. */
12475 : return false;
12476 : }
12477 :
12478 : /* Use precision rather then machine mode when we can, which gives
12479 : the correct answer even for submode (bit-field) types. */
12480 1768913431 : if ((INTEGRAL_TYPE_P (outer_type)
12481 770052099 : || POINTER_TYPE_P (outer_type)
12482 74147690 : || TREE_CODE (outer_type) == OFFSET_TYPE)
12483 1694777474 : && (INTEGRAL_TYPE_P (inner_type)
12484 789511328 : || POINTER_TYPE_P (inner_type)
12485 1942741 : || TREE_CODE (inner_type) == OFFSET_TYPE))
12486 1692859690 : return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
12487 :
12488 76053741 : if (TYPE_MODE (outer_type) == BLKmode
12489 76053741 : && TYPE_MODE (inner_type) == BLKmode)
12490 : {
12491 7934 : if (VECTOR_TYPE_P (outer_type)
12492 5324 : && VECTOR_TYPE_P (inner_type)
12493 5324 : && known_eq (TYPE_VECTOR_SUBPARTS (outer_type),
12494 : TYPE_VECTOR_SUBPARTS (inner_type))
12495 18582 : && (TYPE_MODE (TREE_TYPE (outer_type))
12496 5324 : == TYPE_MODE (TREE_TYPE (inner_type))))
12497 5324 : return true;
12498 2610 : return false;
12499 : }
12500 :
12501 : /* Otherwise fall back on comparing machine modes (e.g. for
12502 : aggregate types, floats). */
12503 76045807 : return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
12504 : }
12505 :
12506 : /* Return true iff a view conversion from vector type INNER_TYPE to vector
12507 : type OUTER_TYPE has the same number of elements and does not change the
12508 : representation of an element. */
12509 :
12510 : bool
12511 6900044 : vector_nop_conversion_p (const_tree outer_type, const_tree inner_type)
12512 : {
12513 6900044 : return (VECTOR_TYPE_P (outer_type)
12514 3595719 : && VECTOR_TYPE_P (inner_type)
12515 3566573 : && known_eq (TYPE_VECTOR_SUBPARTS (outer_type),
12516 : TYPE_VECTOR_SUBPARTS (inner_type))
12517 9410701 : && tree_nop_conversion_p (TREE_TYPE (outer_type),
12518 2510657 : TREE_TYPE (inner_type)));
12519 : }
12520 :
12521 : /* Return true iff conversion in EXP generates no instruction. Mark
12522 : it inline so that we fully inline into the stripping functions even
12523 : though we have two uses of this function. */
12524 :
12525 : static inline bool
12526 20923271570 : tree_nop_conversion (const_tree exp)
12527 : {
12528 20923271570 : tree outer_type, inner_type;
12529 :
12530 20923271570 : if (location_wrapper_p (exp))
12531 : return true;
12532 20855471967 : if (!CONVERT_EXPR_P (exp)
12533 19756502408 : && TREE_CODE (exp) != NON_LVALUE_EXPR)
12534 : return false;
12535 :
12536 1115405784 : outer_type = TREE_TYPE (exp);
12537 1115405784 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12538 :
12539 1115405784 : return tree_nop_conversion_p (outer_type, inner_type);
12540 : }
12541 :
12542 : /* Return true iff conversion in EXP generates no instruction. Don't
12543 : consider conversions changing the signedness. */
12544 :
12545 : static bool
12546 2394517626 : tree_sign_nop_conversion (const_tree exp)
12547 : {
12548 2394517626 : tree outer_type, inner_type;
12549 :
12550 2394517626 : if (!tree_nop_conversion (exp))
12551 : return false;
12552 :
12553 237356781 : outer_type = TREE_TYPE (exp);
12554 237356781 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12555 :
12556 237356781 : return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
12557 237356781 : && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
12558 : }
12559 :
12560 : /* Strip conversions from EXP according to tree_nop_conversion and
12561 : return the resulting expression. */
12562 :
12563 : tree
12564 17741380160 : tree_strip_nop_conversions (tree exp)
12565 : {
12566 18528753944 : while (tree_nop_conversion (exp))
12567 787373784 : exp = TREE_OPERAND (exp, 0);
12568 17741380160 : return exp;
12569 : }
12570 :
12571 : /* Strip conversions from EXP according to tree_sign_nop_conversion
12572 : and return the resulting expression. */
12573 :
12574 : tree
12575 2183996462 : tree_strip_sign_nop_conversions (tree exp)
12576 : {
12577 2394517626 : while (tree_sign_nop_conversion (exp))
12578 210521164 : exp = TREE_OPERAND (exp, 0);
12579 2183996462 : return exp;
12580 : }
12581 :
12582 : /* Avoid any floating point extensions from EXP. */
12583 : tree
12584 101058904 : strip_float_extensions (tree exp)
12585 : {
12586 101178197 : tree sub, expt, subt;
12587 :
12588 : /* For floating point constant look up the narrowest type that can hold
12589 : it properly and handle it like (type)(narrowest_type)constant.
12590 : This way we can optimize for instance a=a*2.0 where "a" is float
12591 : but 2.0 is double constant. */
12592 101178197 : if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
12593 : {
12594 3259103 : REAL_VALUE_TYPE orig;
12595 3259103 : tree type = NULL;
12596 :
12597 3259103 : orig = TREE_REAL_CST (exp);
12598 3259103 : if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node)
12599 3259103 : && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
12600 140842 : type = float_type_node;
12601 3118261 : else if (TYPE_PRECISION (TREE_TYPE (exp))
12602 3118261 : > TYPE_PRECISION (double_type_node)
12603 3118261 : && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
12604 34576 : type = double_type_node;
12605 3259103 : if (type)
12606 175418 : return build_real_truncate (type, orig);
12607 : }
12608 :
12609 101002779 : if (!CONVERT_EXPR_P (exp))
12610 : return exp;
12611 :
12612 5602045 : sub = TREE_OPERAND (exp, 0);
12613 5602045 : subt = TREE_TYPE (sub);
12614 5602045 : expt = TREE_TYPE (exp);
12615 :
12616 5602045 : if (!FLOAT_TYPE_P (subt))
12617 : return exp;
12618 :
12619 429961 : if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
12620 : return exp;
12621 :
12622 143685 : if (element_precision (subt) > element_precision (expt))
12623 : return exp;
12624 :
12625 : return strip_float_extensions (sub);
12626 : }
12627 :
12628 : /* Strip out all handled components that produce invariant
12629 : offsets. */
12630 :
12631 : const_tree
12632 6055243994 : strip_invariant_refs (const_tree op)
12633 : {
12634 7071441391 : while (handled_component_p (op))
12635 : {
12636 1028629151 : switch (TREE_CODE (op))
12637 : {
12638 198061214 : case ARRAY_REF:
12639 198061214 : case ARRAY_RANGE_REF:
12640 198061214 : if (!is_gimple_constant (TREE_OPERAND (op, 1))
12641 187375673 : || TREE_OPERAND (op, 2) != NULL_TREE
12642 185802533 : || TREE_OPERAND (op, 3) != NULL_TREE)
12643 : return NULL;
12644 : break;
12645 :
12646 829145013 : case COMPONENT_REF:
12647 829145013 : if (TREE_OPERAND (op, 2) != NULL_TREE)
12648 : return NULL;
12649 : break;
12650 :
12651 1016197397 : default:;
12652 : }
12653 1016197397 : op = TREE_OPERAND (op, 0);
12654 : }
12655 :
12656 : return op;
12657 : }
12658 :
12659 : /* Strip handled components with zero offset from OP. */
12660 :
12661 : tree
12662 581250 : strip_zero_offset_components (tree op)
12663 : {
12664 581250 : while (TREE_CODE (op) == COMPONENT_REF
12665 437604 : && integer_zerop (DECL_FIELD_OFFSET (TREE_OPERAND (op, 1)))
12666 1131702 : && integer_zerop (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (op, 1))))
12667 181080 : op = TREE_OPERAND (op, 0);
12668 581250 : return op;
12669 : }
12670 :
12671 : static GTY(()) tree gcc_eh_personality_decl;
12672 :
12673 : /* Return the GCC personality function decl. */
12674 :
12675 : tree
12676 407 : lhd_gcc_personality (void)
12677 : {
12678 407 : if (!gcc_eh_personality_decl)
12679 161 : gcc_eh_personality_decl = build_personality_function ("gcc");
12680 407 : return gcc_eh_personality_decl;
12681 : }
12682 :
12683 : /* TARGET is a call target of GIMPLE call statement
12684 : (obtained by gimple_call_fn). Return true if it is
12685 : OBJ_TYPE_REF representing an virtual call of C++ method.
12686 : (As opposed to OBJ_TYPE_REF representing objc calls
12687 : through a cast where middle-end devirtualization machinery
12688 : can't apply.) FOR_DUMP_P is true when being called from
12689 : the dump routines. */
12690 :
12691 : bool
12692 28640367 : virtual_method_call_p (const_tree target, bool for_dump_p)
12693 : {
12694 28640367 : if (TREE_CODE (target) != OBJ_TYPE_REF)
12695 : return false;
12696 1307908 : tree t = TREE_TYPE (target);
12697 1307908 : gcc_checking_assert (TREE_CODE (t) == POINTER_TYPE);
12698 1307908 : t = TREE_TYPE (t);
12699 1307908 : if (TREE_CODE (t) == FUNCTION_TYPE)
12700 : return false;
12701 1306636 : gcc_checking_assert (TREE_CODE (t) == METHOD_TYPE);
12702 : /* If we do not have BINFO associated, it means that type was built
12703 : without devirtualization enabled. Do not consider this a virtual
12704 : call. */
12705 1306636 : if (!TYPE_BINFO (obj_type_ref_class (target, for_dump_p)))
12706 0 : return false;
12707 : return true;
12708 : }
12709 :
12710 : /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
12711 :
12712 : static tree
12713 108 : lookup_binfo_at_offset (tree binfo, tree type, HOST_WIDE_INT pos)
12714 : {
12715 108 : unsigned int i;
12716 108 : tree base_binfo, b;
12717 :
12718 124 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12719 108 : if (pos == tree_to_shwi (BINFO_OFFSET (base_binfo))
12720 108 : && types_same_for_odr (TREE_TYPE (base_binfo), type))
12721 : return base_binfo;
12722 70 : else if ((b = lookup_binfo_at_offset (base_binfo, type, pos)) != NULL)
12723 : return b;
12724 : return NULL;
12725 : }
12726 :
12727 : /* Try to find a base info of BINFO that would have its field decl at offset
12728 : OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12729 : found, return, otherwise return NULL_TREE. */
12730 :
12731 : tree
12732 276158 : get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
12733 : {
12734 276158 : tree type = BINFO_TYPE (binfo);
12735 :
12736 737276 : while (true)
12737 : {
12738 506717 : HOST_WIDE_INT pos, size;
12739 506717 : tree fld;
12740 506717 : int i;
12741 :
12742 506717 : if (types_same_for_odr (type, expected_type))
12743 276158 : return binfo;
12744 230559 : if (maybe_lt (offset, 0))
12745 : return NULL_TREE;
12746 :
12747 1164245 : for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
12748 : {
12749 1164245 : if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld))
12750 933489 : continue;
12751 :
12752 230756 : pos = int_bit_position (fld);
12753 230756 : size = tree_to_uhwi (DECL_SIZE (fld));
12754 1164442 : if (known_in_range_p (offset, pos, size))
12755 : break;
12756 : }
12757 230559 : if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
12758 : return NULL_TREE;
12759 :
12760 : /* Offset 0 indicates the primary base, whose vtable contents are
12761 : represented in the binfo for the derived class. */
12762 230559 : else if (maybe_ne (offset, 0))
12763 : {
12764 197 : tree found_binfo = NULL, base_binfo;
12765 : /* Offsets in BINFO are in bytes relative to the whole structure
12766 : while POS is in bits relative to the containing field. */
12767 197 : int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos
12768 197 : / BITS_PER_UNIT);
12769 :
12770 377 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12771 339 : if (tree_to_shwi (BINFO_OFFSET (base_binfo)) == binfo_offset
12772 339 : && types_same_for_odr (TREE_TYPE (base_binfo), TREE_TYPE (fld)))
12773 : {
12774 : found_binfo = base_binfo;
12775 : break;
12776 : }
12777 197 : if (found_binfo)
12778 : binfo = found_binfo;
12779 : else
12780 38 : binfo = lookup_binfo_at_offset (binfo, TREE_TYPE (fld),
12781 : binfo_offset);
12782 : }
12783 :
12784 230559 : type = TREE_TYPE (fld);
12785 230559 : offset -= pos;
12786 230559 : }
12787 : }
12788 :
12789 : /* PR 84195: Replace control characters in "unescaped" with their
12790 : escaped equivalents. Allow newlines if -fmessage-length has
12791 : been set to a non-zero value. This is done here, rather than
12792 : where the attribute is recorded as the message length can
12793 : change between these two locations. */
12794 :
12795 : void
12796 135941 : escaped_string::escape (const char *unescaped)
12797 : {
12798 135941 : char *escaped;
12799 135941 : size_t i, new_i, len;
12800 :
12801 135941 : if (m_owned)
12802 8 : free (m_str);
12803 :
12804 135941 : m_str = const_cast<char *> (unescaped);
12805 135941 : m_owned = false;
12806 :
12807 135941 : if (unescaped == NULL || *unescaped == 0)
12808 : return;
12809 :
12810 135933 : len = strlen (unescaped);
12811 135933 : escaped = NULL;
12812 135933 : new_i = 0;
12813 :
12814 3942767 : for (i = 0; i < len; i++)
12815 : {
12816 3806834 : char c = unescaped[i];
12817 :
12818 3806834 : if (!ISCNTRL (c))
12819 : {
12820 3806749 : if (escaped)
12821 33 : escaped[new_i++] = c;
12822 3806749 : continue;
12823 : }
12824 :
12825 85 : if (c != '\n' || !pp_is_wrapping_line (global_dc->get_reference_printer ()))
12826 : {
12827 77 : if (escaped == NULL)
12828 : {
12829 : /* We only allocate space for a new string if we
12830 : actually encounter a control character that
12831 : needs replacing. */
12832 19 : escaped = (char *) xmalloc (len * 2 + 1);
12833 19 : strncpy (escaped, unescaped, i);
12834 19 : new_i = i;
12835 : }
12836 :
12837 77 : escaped[new_i++] = '\\';
12838 :
12839 77 : switch (c)
12840 : {
12841 8 : case '\a': escaped[new_i++] = 'a'; break;
12842 8 : case '\b': escaped[new_i++] = 'b'; break;
12843 8 : case '\f': escaped[new_i++] = 'f'; break;
12844 15 : case '\n': escaped[new_i++] = 'n'; break;
12845 15 : case '\r': escaped[new_i++] = 'r'; break;
12846 15 : case '\t': escaped[new_i++] = 't'; break;
12847 8 : case '\v': escaped[new_i++] = 'v'; break;
12848 0 : default: escaped[new_i++] = '?'; break;
12849 : }
12850 : }
12851 8 : else if (escaped)
12852 4 : escaped[new_i++] = c;
12853 : }
12854 :
12855 135933 : if (escaped)
12856 : {
12857 19 : escaped[new_i] = 0;
12858 19 : m_str = escaped;
12859 19 : m_owned = true;
12860 : }
12861 : }
12862 :
12863 : /* Warn about a use of an identifier which was marked deprecated. Returns
12864 : whether a warning was given. */
12865 :
12866 : bool
12867 1412842 : warn_deprecated_use (tree node, tree attr)
12868 : {
12869 1412842 : escaped_string msg;
12870 :
12871 1412842 : if (node == 0 || !warn_deprecated_decl)
12872 : return false;
12873 :
12874 1405603 : if (!attr)
12875 : {
12876 1290637 : if (DECL_P (node))
12877 1290467 : attr = DECL_ATTRIBUTES (node);
12878 170 : else if (TYPE_P (node))
12879 : {
12880 170 : tree decl = TYPE_STUB_DECL (node);
12881 170 : if (decl)
12882 146 : attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
12883 24 : else if ((decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node)))
12884 : != NULL_TREE)
12885 : {
12886 6 : node = TREE_TYPE (decl);
12887 6 : attr = TYPE_ATTRIBUTES (node);
12888 : }
12889 : }
12890 : }
12891 :
12892 1290637 : if (attr)
12893 135467 : attr = lookup_attribute ("deprecated", attr);
12894 :
12895 135467 : if (attr)
12896 135456 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12897 :
12898 1405603 : bool w = false;
12899 1405603 : if (DECL_P (node))
12900 : {
12901 1405423 : auto_diagnostic_group d;
12902 1405423 : if (msg)
12903 135365 : w = warning (OPT_Wdeprecated_declarations,
12904 : "%qD is deprecated: %s", node, (const char *) msg);
12905 : else
12906 1270058 : w = warning (OPT_Wdeprecated_declarations,
12907 : "%qD is deprecated", node);
12908 1405423 : if (w)
12909 800 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12910 1405423 : }
12911 180 : else if (TYPE_P (node))
12912 : {
12913 180 : tree what = NULL_TREE;
12914 180 : tree decl = TYPE_STUB_DECL (node);
12915 :
12916 180 : if (TYPE_NAME (node))
12917 : {
12918 175 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12919 10 : what = TYPE_NAME (node);
12920 165 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12921 165 : && DECL_NAME (TYPE_NAME (node)))
12922 165 : what = DECL_NAME (TYPE_NAME (node));
12923 : }
12924 :
12925 180 : auto_diagnostic_group d;
12926 180 : if (what)
12927 : {
12928 175 : if (msg)
12929 89 : w = warning (OPT_Wdeprecated_declarations,
12930 : "%qE is deprecated: %s", what, (const char *) msg);
12931 : else
12932 86 : w = warning (OPT_Wdeprecated_declarations,
12933 : "%qE is deprecated", what);
12934 : }
12935 : else
12936 : {
12937 5 : if (msg)
12938 2 : w = warning (OPT_Wdeprecated_declarations,
12939 : "type is deprecated: %s", (const char *) msg);
12940 : else
12941 3 : w = warning (OPT_Wdeprecated_declarations,
12942 : "type is deprecated");
12943 : }
12944 :
12945 180 : if (w && decl)
12946 111 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12947 180 : }
12948 :
12949 : return w;
12950 1412842 : }
12951 :
12952 : /* Error out with an identifier which was marked 'unavailable'. */
12953 : void
12954 376 : error_unavailable_use (tree node, tree attr)
12955 : {
12956 376 : escaped_string msg;
12957 :
12958 376 : if (node == 0)
12959 0 : return;
12960 :
12961 376 : if (!attr)
12962 : {
12963 366 : if (DECL_P (node))
12964 306 : attr = DECL_ATTRIBUTES (node);
12965 60 : else if (TYPE_P (node))
12966 : {
12967 60 : tree decl = TYPE_STUB_DECL (node);
12968 60 : if (decl)
12969 51 : attr = lookup_attribute ("unavailable",
12970 51 : TYPE_ATTRIBUTES (TREE_TYPE (decl)));
12971 : }
12972 : }
12973 :
12974 366 : if (attr)
12975 164 : attr = lookup_attribute ("unavailable", attr);
12976 :
12977 164 : if (attr)
12978 164 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12979 :
12980 376 : if (DECL_P (node))
12981 : {
12982 306 : auto_diagnostic_group d;
12983 306 : if (msg)
12984 129 : error ("%qD is unavailable: %s", node, (const char *) msg);
12985 : else
12986 177 : error ("%qD is unavailable", node);
12987 306 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12988 306 : }
12989 70 : else if (TYPE_P (node))
12990 : {
12991 70 : tree what = NULL_TREE;
12992 70 : tree decl = TYPE_STUB_DECL (node);
12993 :
12994 70 : if (TYPE_NAME (node))
12995 : {
12996 66 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12997 4 : what = TYPE_NAME (node);
12998 62 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12999 62 : && DECL_NAME (TYPE_NAME (node)))
13000 62 : what = DECL_NAME (TYPE_NAME (node));
13001 : }
13002 :
13003 70 : auto_diagnostic_group d;
13004 70 : if (what)
13005 : {
13006 66 : if (msg)
13007 33 : error ("%qE is unavailable: %s", what, (const char *) msg);
13008 : else
13009 33 : error ("%qE is unavailable", what);
13010 : }
13011 : else
13012 : {
13013 4 : if (msg)
13014 2 : error ("type is unavailable: %s", (const char *) msg);
13015 : else
13016 2 : error ("type is unavailable");
13017 : }
13018 :
13019 70 : if (decl)
13020 52 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
13021 70 : }
13022 376 : }
13023 :
13024 : /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
13025 : somewhere in it. */
13026 :
13027 : bool
13028 5848169 : contains_bitfld_component_ref_p (const_tree ref)
13029 : {
13030 11966440 : while (handled_component_p (ref))
13031 : {
13032 6135339 : if (TREE_CODE (ref) == COMPONENT_REF
13033 6135339 : && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
13034 : return true;
13035 6118271 : ref = TREE_OPERAND (ref, 0);
13036 : }
13037 :
13038 : return false;
13039 : }
13040 :
13041 : /* Try to determine whether a TRY_CATCH expression can fall through.
13042 : This is a subroutine of block_may_fallthru. */
13043 :
13044 : static bool
13045 1 : try_catch_may_fallthru (const_tree stmt)
13046 : {
13047 1 : tree_stmt_iterator i;
13048 :
13049 : /* If the TRY block can fall through, the whole TRY_CATCH can
13050 : fall through. */
13051 1 : if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
13052 : return true;
13053 :
13054 1 : switch (TREE_CODE (TREE_OPERAND (stmt, 1)))
13055 : {
13056 0 : case CATCH_EXPR:
13057 : /* See below. */
13058 0 : return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1)));
13059 :
13060 0 : case EH_FILTER_EXPR:
13061 : /* See below. */
13062 0 : return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1)));
13063 :
13064 0 : case STATEMENT_LIST:
13065 0 : break;
13066 :
13067 : default:
13068 : /* See below. */
13069 : return false;
13070 : }
13071 :
13072 0 : i = tsi_start (TREE_OPERAND (stmt, 1));
13073 0 : switch (TREE_CODE (tsi_stmt (i)))
13074 : {
13075 : case CATCH_EXPR:
13076 : /* We expect to see a sequence of CATCH_EXPR trees, each with a
13077 : catch expression and a body. The whole TRY_CATCH may fall
13078 : through iff any of the catch bodies falls through. */
13079 0 : for (; !tsi_end_p (i); tsi_next (&i))
13080 : {
13081 0 : if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
13082 : return true;
13083 : }
13084 : return false;
13085 :
13086 0 : case EH_FILTER_EXPR:
13087 : /* The exception filter expression only matters if there is an
13088 : exception. If the exception does not match EH_FILTER_TYPES,
13089 : we will execute EH_FILTER_FAILURE, and we will fall through
13090 : if that falls through. If the exception does match
13091 : EH_FILTER_TYPES, the stack unwinder will continue up the
13092 : stack, so we will not fall through. We don't know whether we
13093 : will throw an exception which matches EH_FILTER_TYPES or not,
13094 : so we just ignore EH_FILTER_TYPES and assume that we might
13095 : throw an exception which doesn't match. */
13096 0 : return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
13097 :
13098 : default:
13099 : /* This case represents statements to be executed when an
13100 : exception occurs. Those statements are implicitly followed
13101 : by a RESX statement to resume execution after the exception.
13102 : So in this case the TRY_CATCH never falls through. */
13103 : return false;
13104 : }
13105 : }
13106 :
13107 : /* Try to determine if we can fall out of the bottom of BLOCK. This guess
13108 : need not be 100% accurate; simply be conservative and return true if we
13109 : don't know. This is used only to avoid stupidly generating extra code.
13110 : If we're wrong, we'll just delete the extra code later. */
13111 :
13112 : bool
13113 9368403 : block_may_fallthru (const_tree block)
13114 : {
13115 : /* This CONST_CAST is okay because expr_last returns its argument
13116 : unmodified and we assign it to a const_tree. */
13117 10822851 : const_tree stmt = expr_last (const_cast<tree> (block));
13118 :
13119 10822851 : switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
13120 : {
13121 : case GOTO_EXPR:
13122 : case RETURN_EXPR:
13123 : /* Easy cases. If the last statement of the block implies
13124 : control transfer, then we can't fall through. */
13125 : return false;
13126 :
13127 12 : case SWITCH_EXPR:
13128 : /* If there is a default: label or case labels cover all possible
13129 : SWITCH_COND values, then the SWITCH_EXPR will transfer control
13130 : to some case label in all cases and all we care is whether the
13131 : SWITCH_BODY falls through. */
13132 12 : if (SWITCH_ALL_CASES_P (stmt))
13133 11 : return block_may_fallthru (SWITCH_BODY (stmt));
13134 : return true;
13135 :
13136 21930 : case COND_EXPR:
13137 21930 : if (block_may_fallthru (COND_EXPR_THEN (stmt)))
13138 : return true;
13139 2823 : return block_may_fallthru (COND_EXPR_ELSE (stmt));
13140 :
13141 905043 : case BIND_EXPR:
13142 905043 : return block_may_fallthru (BIND_EXPR_BODY (stmt));
13143 :
13144 1 : case TRY_CATCH_EXPR:
13145 1 : return try_catch_may_fallthru (stmt);
13146 :
13147 2078 : case TRY_FINALLY_EXPR:
13148 : /* The finally clause is always executed after the try clause,
13149 : so if it does not fall through, then the try-finally will not
13150 : fall through. Otherwise, if the try clause does not fall
13151 : through, then when the finally clause falls through it will
13152 : resume execution wherever the try clause was going. So the
13153 : whole try-finally will only fall through if both the try
13154 : clause and the finally clause fall through. */
13155 2078 : return (block_may_fallthru (TREE_OPERAND (stmt, 0))
13156 2078 : && block_may_fallthru (TREE_OPERAND (stmt, 1)));
13157 :
13158 0 : case EH_ELSE_EXPR:
13159 0 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
13160 :
13161 91930 : case MODIFY_EXPR:
13162 91930 : if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
13163 1597 : stmt = TREE_OPERAND (stmt, 1);
13164 : else
13165 : return true;
13166 : /* FALLTHRU */
13167 :
13168 446029 : case CALL_EXPR:
13169 : /* Functions that do not return do not fall through. */
13170 446029 : return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
13171 :
13172 546561 : case CLEANUP_POINT_EXPR:
13173 546561 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
13174 :
13175 10 : case TARGET_EXPR:
13176 10 : return block_may_fallthru (TREE_OPERAND (stmt, 1));
13177 :
13178 : case ERROR_MARK:
13179 : return true;
13180 :
13181 6546938 : default:
13182 6546938 : return lang_hooks.block_may_fallthru (stmt);
13183 : }
13184 : }
13185 :
13186 : /* True if we are using EH to handle cleanups. */
13187 : static bool using_eh_for_cleanups_flag = false;
13188 :
13189 : /* This routine is called from front ends to indicate eh should be used for
13190 : cleanups. */
13191 : void
13192 126499 : using_eh_for_cleanups (void)
13193 : {
13194 126499 : using_eh_for_cleanups_flag = true;
13195 126499 : }
13196 :
13197 : /* Query whether EH is used for cleanups. */
13198 : bool
13199 1739365 : using_eh_for_cleanups_p (void)
13200 : {
13201 1739365 : return using_eh_for_cleanups_flag;
13202 : }
13203 :
13204 : /* Wrapper for tree_code_name to ensure that tree code is valid */
13205 : const char *
13206 14675292675 : get_tree_code_name (enum tree_code code)
13207 : {
13208 14675292675 : const char *invalid = "<invalid tree code>";
13209 :
13210 : /* The tree_code enum promotes to signed, but we could be getting
13211 : invalid values, so force an unsigned comparison. */
13212 14675292675 : if (unsigned (code) >= MAX_TREE_CODES)
13213 : {
13214 0 : if ((unsigned)code == 0xa5a5)
13215 : return "ggc_freed";
13216 0 : return invalid;
13217 : }
13218 :
13219 14675292675 : return tree_code_name[code];
13220 : }
13221 :
13222 : /* Drops the TREE_OVERFLOW flag from T. */
13223 :
13224 : tree
13225 35939 : drop_tree_overflow (tree t)
13226 : {
13227 35939 : gcc_checking_assert (TREE_OVERFLOW (t));
13228 :
13229 : /* For tree codes with a sharing machinery re-build the result. */
13230 35939 : if (poly_int_tree_p (t))
13231 35927 : return wide_int_to_tree (TREE_TYPE (t), wi::to_poly_wide (t));
13232 :
13233 : /* For VECTOR_CST, remove the overflow bits from the encoded elements
13234 : and canonicalize the result. */
13235 12 : if (TREE_CODE (t) == VECTOR_CST)
13236 : {
13237 0 : tree_vector_builder builder;
13238 0 : builder.new_unary_operation (TREE_TYPE (t), t, true);
13239 0 : unsigned int count = builder.encoded_nelts ();
13240 0 : for (unsigned int i = 0; i < count; ++i)
13241 : {
13242 0 : tree elt = VECTOR_CST_ELT (t, i);
13243 0 : if (TREE_OVERFLOW (elt))
13244 0 : elt = drop_tree_overflow (elt);
13245 0 : builder.quick_push (elt);
13246 : }
13247 0 : return builder.build ();
13248 0 : }
13249 :
13250 : /* Otherwise, as all tcc_constants are possibly shared, copy the node
13251 : and drop the flag. */
13252 12 : t = copy_node (t);
13253 12 : TREE_OVERFLOW (t) = 0;
13254 :
13255 : /* For constants that contain nested constants, drop the flag
13256 : from those as well. */
13257 12 : if (TREE_CODE (t) == COMPLEX_CST)
13258 : {
13259 12 : if (TREE_OVERFLOW (TREE_REALPART (t)))
13260 12 : TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t));
13261 12 : if (TREE_OVERFLOW (TREE_IMAGPART (t)))
13262 0 : TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t));
13263 : }
13264 :
13265 : return t;
13266 : }
13267 :
13268 : /* Given a memory reference expression T, return its base address.
13269 : The base address of a memory reference expression is the main
13270 : object being referenced. For instance, the base address for
13271 : 'array[i].fld[j]' is 'array'. You can think of this as stripping
13272 : away the offset part from a memory address.
13273 :
13274 : This function calls handled_component_p to strip away all the inner
13275 : parts of the memory reference until it reaches the base object. */
13276 :
13277 : tree
13278 3279471283 : get_base_address (tree t)
13279 : {
13280 3279471283 : if (TREE_CODE (t) == WITH_SIZE_EXPR)
13281 899 : t = TREE_OPERAND (t, 0);
13282 4087061665 : while (handled_component_p (t))
13283 807590382 : t = TREE_OPERAND (t, 0);
13284 :
13285 3279471283 : if ((TREE_CODE (t) == MEM_REF
13286 3279471283 : || TREE_CODE (t) == TARGET_MEM_REF)
13287 3279471283 : && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
13288 149874800 : t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
13289 :
13290 3279471283 : return t;
13291 : }
13292 :
13293 : /* Return a tree of sizetype representing the size, in bytes, of the element
13294 : of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13295 :
13296 : tree
13297 796462554 : array_ref_element_size (tree exp)
13298 : {
13299 796462554 : tree aligned_size = TREE_OPERAND (exp, 3);
13300 796462554 : tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
13301 796462554 : location_t loc = EXPR_LOCATION (exp);
13302 :
13303 : /* If a size was specified in the ARRAY_REF, it's the size measured
13304 : in alignment units of the element type. So multiply by that value. */
13305 796462554 : if (aligned_size)
13306 : {
13307 : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13308 : sizetype from another type of the same width and signedness. */
13309 394164 : if (TREE_TYPE (aligned_size) != sizetype)
13310 3725 : aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
13311 394164 : return size_binop_loc (loc, MULT_EXPR, aligned_size,
13312 394164 : size_int (TYPE_ALIGN_UNIT (elmt_type)));
13313 : }
13314 :
13315 : /* Otherwise, take the size from that of the element type. Substitute
13316 : any PLACEHOLDER_EXPR that we have. */
13317 : else
13318 796068390 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
13319 : }
13320 :
13321 : /* Return a tree representing the lower bound of the array mentioned in
13322 : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13323 :
13324 : tree
13325 1098591387 : array_ref_low_bound (tree exp)
13326 : {
13327 1098591387 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13328 :
13329 : /* If a lower bound is specified in EXP, use it. */
13330 1098591387 : if (TREE_OPERAND (exp, 2))
13331 1968005 : return TREE_OPERAND (exp, 2);
13332 :
13333 : /* Otherwise, if there is a domain type and it has a lower bound, use it,
13334 : substituting for a PLACEHOLDER_EXPR as needed. */
13335 1096623382 : if (domain_type && TYPE_MIN_VALUE (domain_type))
13336 1095694572 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
13337 :
13338 : /* Otherwise, return a zero of the appropriate type. */
13339 928810 : tree idxtype = TREE_TYPE (TREE_OPERAND (exp, 1));
13340 928810 : return (idxtype == error_mark_node
13341 928810 : ? integer_zero_node : build_int_cst (idxtype, 0));
13342 : }
13343 :
13344 : /* Return a tree representing the upper bound of the array mentioned in
13345 : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13346 :
13347 : tree
13348 252009627 : array_ref_up_bound (tree exp)
13349 : {
13350 252009627 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13351 :
13352 : /* If there is a domain type and it has an upper bound, use it, substituting
13353 : for a PLACEHOLDER_EXPR as needed. */
13354 252009627 : if (domain_type && TYPE_MAX_VALUE (domain_type))
13355 251216409 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
13356 :
13357 : /* Otherwise fail. */
13358 : return NULL_TREE;
13359 : }
13360 :
13361 : /* Returns true if REF is an array reference, a component reference,
13362 : or a memory reference to an array whose actual size might be larger
13363 : than its upper bound implies, there are multiple cases:
13364 : A. a ref to a flexible array member at the end of a structure;
13365 : B. a ref to an array with a different type against the original decl;
13366 : for example:
13367 :
13368 : short a[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
13369 : (*((char(*)[16])&a[0]))[i+8]
13370 :
13371 : C. a ref to an array that was passed as a parameter;
13372 : for example:
13373 :
13374 : int test (uint8_t *p, uint32_t t[1][1], int n) {
13375 : for (int i = 0; i < 4; i++, p++)
13376 : t[i][0] = ...;
13377 :
13378 : If non-null, set IS_TRAILING_ARRAY to true if the ref is the above case A.
13379 : */
13380 :
13381 : bool
13382 75514825 : array_ref_flexible_size_p (tree ref, bool *is_trailing_array /* = NULL */)
13383 : {
13384 : /* The TYPE for this array reference. */
13385 75514825 : tree atype = NULL_TREE;
13386 : /* The FIELD_DECL for the array field in the containing structure. */
13387 75514825 : tree afield_decl = NULL_TREE;
13388 : /* Whether this array is the trailing array of a structure. */
13389 75514825 : bool is_trailing_array_tmp = false;
13390 75514825 : if (!is_trailing_array)
13391 75431761 : is_trailing_array = &is_trailing_array_tmp;
13392 :
13393 75514825 : if (TREE_CODE (ref) == ARRAY_REF
13394 75514825 : || TREE_CODE (ref) == ARRAY_RANGE_REF)
13395 : {
13396 75272044 : atype = TREE_TYPE (TREE_OPERAND (ref, 0));
13397 75272044 : ref = TREE_OPERAND (ref, 0);
13398 : }
13399 242781 : else if (TREE_CODE (ref) == COMPONENT_REF
13400 242781 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE)
13401 : {
13402 171569 : atype = TREE_TYPE (TREE_OPERAND (ref, 1));
13403 171569 : afield_decl = TREE_OPERAND (ref, 1);
13404 : }
13405 71212 : else if (TREE_CODE (ref) == MEM_REF)
13406 : {
13407 7629 : tree arg = TREE_OPERAND (ref, 0);
13408 7629 : if (TREE_CODE (arg) == ADDR_EXPR)
13409 7629 : arg = TREE_OPERAND (arg, 0);
13410 7629 : tree argtype = TREE_TYPE (arg);
13411 7629 : if (TREE_CODE (argtype) == RECORD_TYPE)
13412 : {
13413 157 : if (tree fld = last_field (argtype))
13414 : {
13415 157 : atype = TREE_TYPE (fld);
13416 157 : afield_decl = fld;
13417 157 : if (TREE_CODE (atype) != ARRAY_TYPE)
13418 : return false;
13419 157 : if (VAR_P (arg) && DECL_SIZE (fld))
13420 : return false;
13421 : }
13422 : else
13423 : return false;
13424 : }
13425 : else
13426 : return false;
13427 : }
13428 : else
13429 : return false;
13430 :
13431 75443726 : if (TREE_CODE (ref) == STRING_CST)
13432 : return false;
13433 :
13434 : tree ref_to_array = ref;
13435 92817577 : while (handled_component_p (ref))
13436 : {
13437 : /* If the reference chain contains a component reference to a
13438 : non-union type and there follows another field the reference
13439 : is not at the end of a structure. */
13440 20535913 : if (TREE_CODE (ref) == COMPONENT_REF)
13441 : {
13442 19391055 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
13443 : {
13444 18135988 : tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
13445 45148974 : while (nextf && TREE_CODE (nextf) != FIELD_DECL)
13446 27012986 : nextf = DECL_CHAIN (nextf);
13447 : if (nextf)
13448 : return false;
13449 : }
13450 : }
13451 : /* If we have a multi-dimensional array we do not consider
13452 : a non-innermost dimension as flex array if the whole
13453 : multi-dimensional array is at struct end.
13454 : Same for an array of aggregates with a trailing array
13455 : member. */
13456 1144858 : else if (TREE_CODE (ref) == ARRAY_REF)
13457 : return false;
13458 198195 : else if (TREE_CODE (ref) == ARRAY_RANGE_REF)
13459 : ;
13460 : /* If we view an underlying object as sth else then what we
13461 : gathered up to now is what we have to rely on. */
13462 198179 : else if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
13463 : break;
13464 : else
13465 0 : gcc_unreachable ();
13466 :
13467 17375089 : ref = TREE_OPERAND (ref, 0);
13468 : }
13469 :
13470 72479843 : gcc_assert (!afield_decl
13471 : || (afield_decl && TREE_CODE (afield_decl) == FIELD_DECL));
13472 :
13473 : /* The array now is at struct end. Treat flexible array member as
13474 : always subject to extend, even into just padding constrained by
13475 : an underlying decl. */
13476 72479843 : if (! TYPE_SIZE (atype)
13477 69922094 : || ! TYPE_DOMAIN (atype)
13478 142401937 : || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13479 : {
13480 2563185 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13481 2563185 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13482 : }
13483 :
13484 : /* If the reference is based on a declared entity, the size of the array
13485 : is constrained by its given domain. (Do not trust commons PR/69368). */
13486 69916658 : ref = get_base_address (ref);
13487 69916658 : if (ref
13488 69916658 : && DECL_P (ref)
13489 59552321 : && !(flag_unconstrained_commons
13490 14 : && VAR_P (ref) && DECL_COMMON (ref))
13491 59552307 : && DECL_SIZE_UNIT (ref)
13492 129468588 : && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
13493 : {
13494 : /* If the object itself is the array it is not at struct end. */
13495 59551902 : if (DECL_P (ref_to_array))
13496 : return false;
13497 :
13498 : /* Check whether the array domain covers all of the available
13499 : padding. */
13500 15809988 : poly_int64 offset;
13501 15809988 : if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
13502 15808628 : || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST
13503 31596252 : || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST)
13504 : {
13505 23724 : *is_trailing_array
13506 23724 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13507 23724 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13508 : }
13509 15786264 : if (! get_addr_base_and_unit_offset (ref_to_array, &offset))
13510 : {
13511 2835 : *is_trailing_array
13512 2835 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13513 2835 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13514 : }
13515 :
13516 : /* If at least one extra element fits it is a flexarray. */
13517 15783429 : if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13518 : - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype)))
13519 : + 2)
13520 : * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype))),
13521 : wi::to_offset (DECL_SIZE_UNIT (ref)) - offset))
13522 : {
13523 395042 : *is_trailing_array
13524 395042 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13525 395042 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13526 : }
13527 :
13528 : return false;
13529 : }
13530 :
13531 10364756 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13532 10364756 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13533 : }
13534 :
13535 :
13536 : /* Return a tree representing the offset, in bytes, of the field referenced
13537 : by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
13538 :
13539 : tree
13540 2786001504 : component_ref_field_offset (tree exp)
13541 : {
13542 2786001504 : tree aligned_offset = TREE_OPERAND (exp, 2);
13543 2786001504 : tree field = TREE_OPERAND (exp, 1);
13544 2786001504 : location_t loc = EXPR_LOCATION (exp);
13545 :
13546 : /* If an offset was specified in the COMPONENT_REF, it's the offset measured
13547 : in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
13548 : value. */
13549 2786001504 : if (aligned_offset)
13550 : {
13551 : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13552 : sizetype from another type of the same width and signedness. */
13553 11911 : if (TREE_TYPE (aligned_offset) != sizetype)
13554 133 : aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
13555 11911 : return size_binop_loc (loc, MULT_EXPR, aligned_offset,
13556 11911 : size_int (DECL_OFFSET_ALIGN (field)
13557 : / BITS_PER_UNIT));
13558 : }
13559 :
13560 : /* Otherwise, take the offset from that of the field. Substitute
13561 : any PLACEHOLDER_EXPR that we have. */
13562 : else
13563 2785989593 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
13564 : }
13565 :
13566 : /* Given the initializer INIT, return the initializer for the field
13567 : DECL if it exists, otherwise null. Used to obtain the initializer
13568 : for a flexible array member and determine its size. */
13569 :
13570 : static tree
13571 1267 : get_initializer_for (tree init, tree decl)
13572 : {
13573 1267 : STRIP_NOPS (init);
13574 :
13575 1267 : tree fld, fld_init;
13576 1267 : unsigned HOST_WIDE_INT i;
13577 3571 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), i, fld, fld_init)
13578 : {
13579 1926 : if (decl == fld)
13580 : return fld_init;
13581 :
13582 1037 : if (TREE_CODE (fld) == CONSTRUCTOR)
13583 : {
13584 0 : fld_init = get_initializer_for (fld_init, decl);
13585 0 : if (fld_init)
13586 : return fld_init;
13587 : }
13588 : }
13589 :
13590 : return NULL_TREE;
13591 : }
13592 :
13593 : /* Determines the special array member type for the array reference REF. */
13594 : special_array_member
13595 256591 : component_ref_sam_type (tree ref)
13596 : {
13597 256591 : special_array_member sam_type = special_array_member::none;
13598 :
13599 256591 : tree member = TREE_OPERAND (ref, 1);
13600 256591 : tree memsize = DECL_SIZE_UNIT (member);
13601 256591 : if (memsize)
13602 : {
13603 124501 : tree memtype = TREE_TYPE (member);
13604 124501 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13605 124379 : return sam_type;
13606 :
13607 83064 : bool trailing = false;
13608 83064 : (void) array_ref_flexible_size_p (ref, &trailing);
13609 83064 : bool zero_elts = integer_zerop (memsize);
13610 83064 : if (zero_elts && integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (memtype))))
13611 : {
13612 : /* If array element has zero size, verify if it is a flexible
13613 : array member or zero length array. Clear zero_elts if
13614 : it has one or more members or is a VLA member. */
13615 6 : if (tree dom = TYPE_DOMAIN (memtype))
13616 6 : if (tree min = TYPE_MIN_VALUE (dom))
13617 6 : if (tree max = TYPE_MAX_VALUE (dom))
13618 4 : if (TREE_CODE (min) != INTEGER_CST
13619 4 : || TREE_CODE (max) != INTEGER_CST
13620 12 : || !((integer_zerop (min) && integer_all_onesp (max))
13621 4 : || tree_int_cst_lt (max, min)))
13622 : zero_elts = false;
13623 : }
13624 83064 : if (!trailing && !zero_elts)
13625 : /* MEMBER is an interior array with more than one element. */
13626 : return special_array_member::int_n;
13627 :
13628 23222 : if (zero_elts)
13629 : {
13630 1074 : if (trailing)
13631 : return special_array_member::trail_0;
13632 : else
13633 463 : return special_array_member::int_0;
13634 : }
13635 :
13636 22611 : if (!zero_elts)
13637 22611 : if (tree dom = TYPE_DOMAIN (memtype))
13638 22611 : if (tree min = TYPE_MIN_VALUE (dom))
13639 22611 : if (tree max = TYPE_MAX_VALUE (dom))
13640 22611 : if (TREE_CODE (min) == INTEGER_CST
13641 22611 : && TREE_CODE (max) == INTEGER_CST)
13642 : {
13643 22489 : offset_int minidx = wi::to_offset (min);
13644 22489 : offset_int maxidx = wi::to_offset (max);
13645 22489 : offset_int neltsm1 = maxidx - minidx;
13646 22489 : if (neltsm1 > 0)
13647 : /* MEMBER is a trailing array with more than
13648 : one elements. */
13649 22489 : return special_array_member::trail_n;
13650 :
13651 2182 : if (neltsm1 == 0)
13652 : return special_array_member::trail_1;
13653 : }
13654 : }
13655 :
13656 : return sam_type;
13657 : }
13658 :
13659 : /* Determines the size of the member referenced by the COMPONENT_REF
13660 : REF, using its initializer expression if necessary in order to
13661 : determine the size of an initialized flexible array member.
13662 : If non-null, set *SAM to the type of special array member.
13663 : Returns the size as sizetype (which might be zero for an object
13664 : with an uninitialized flexible array member) or null if the size
13665 : cannot be determined. */
13666 :
13667 : tree
13668 157241 : component_ref_size (tree ref, special_array_member *sam /* = NULL */)
13669 : {
13670 157241 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
13671 :
13672 157241 : special_array_member sambuf;
13673 157241 : if (!sam)
13674 100938 : sam = &sambuf;
13675 157241 : *sam = component_ref_sam_type (ref);
13676 :
13677 : /* The object/argument referenced by the COMPONENT_REF and its type. */
13678 157241 : tree arg = TREE_OPERAND (ref, 0);
13679 157241 : tree argtype = TREE_TYPE (arg);
13680 : /* The referenced member. */
13681 157241 : tree member = TREE_OPERAND (ref, 1);
13682 :
13683 157241 : tree memsize = DECL_SIZE_UNIT (member);
13684 157241 : if (memsize)
13685 : {
13686 89656 : tree memtype = TREE_TYPE (member);
13687 89656 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13688 : /* DECL_SIZE may be less than TYPE_SIZE in C++ when referring
13689 : to the type of a class with a virtual base which doesn't
13690 : reflect the size of the virtual's members (see pr97595).
13691 : If that's the case fail for now and implement something
13692 : more robust in the future. */
13693 41437 : return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype))
13694 41437 : ? memsize : NULL_TREE);
13695 :
13696 : /* 2-or-more elements arrays are treated as normal arrays by default. */
13697 48219 : if (*sam == special_array_member::int_n
13698 48219 : || *sam == special_array_member::trail_n)
13699 : return memsize;
13700 :
13701 1849 : tree afield_decl = TREE_OPERAND (ref, 1);
13702 1849 : gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
13703 : /* If the trailing array is a not a flexible array member, treat it as
13704 : a normal array. */
13705 1849 : if (DECL_NOT_FLEXARRAY (afield_decl)
13706 1849 : && *sam != special_array_member::int_0)
13707 : return memsize;
13708 :
13709 1840 : if (*sam == special_array_member::int_0)
13710 270 : memsize = NULL_TREE;
13711 :
13712 : /* For a reference to a flexible array member of a union
13713 : use the size of the union instead of the size of the member. */
13714 1840 : if (TREE_CODE (argtype) == UNION_TYPE)
13715 277 : memsize = TYPE_SIZE_UNIT (argtype);
13716 : }
13717 :
13718 : /* MEMBER is either a bona fide flexible array member, or a zero-elements
13719 : array member, or an array of length one treated as such. */
13720 :
13721 : /* If the reference is to a declared object and the member a true
13722 : flexible array, try to determine its size from its initializer. */
13723 69425 : poly_int64 baseoff = 0;
13724 69425 : tree base = get_addr_base_and_unit_offset (ref, &baseoff);
13725 69425 : if (!base || !VAR_P (base))
13726 : {
13727 66077 : if (*sam != special_array_member::int_0)
13728 : return NULL_TREE;
13729 :
13730 52 : if (TREE_CODE (arg) != COMPONENT_REF)
13731 : return NULL_TREE;
13732 :
13733 : base = arg;
13734 6 : while (TREE_CODE (base) == COMPONENT_REF)
13735 3 : base = TREE_OPERAND (base, 0);
13736 3 : baseoff = tree_to_poly_int64 (byte_position (TREE_OPERAND (ref, 1)));
13737 : }
13738 :
13739 : /* BASE is the declared object of which MEMBER is either a member
13740 : or that is cast to ARGTYPE (e.g., a char buffer used to store
13741 : an ARGTYPE object). */
13742 3351 : tree basetype = TREE_TYPE (base);
13743 :
13744 : /* Determine the base type of the referenced object. If it's
13745 : the same as ARGTYPE and MEMBER has a known size, return it. */
13746 3351 : tree bt = basetype;
13747 3351 : if (*sam != special_array_member::int_0)
13748 3352 : while (TREE_CODE (bt) == ARRAY_TYPE)
13749 222 : bt = TREE_TYPE (bt);
13750 3351 : bool typematch = useless_type_conversion_p (argtype, bt);
13751 3351 : if (memsize && typematch)
13752 : return memsize;
13753 :
13754 3261 : memsize = NULL_TREE;
13755 :
13756 3261 : if (typematch)
13757 : /* MEMBER is a true flexible array member. Compute its size from
13758 : the initializer of the BASE object if it has one. */
13759 2697 : if (tree init = DECL_P (base) ? DECL_INITIAL (base) : NULL_TREE)
13760 1300 : if (init != error_mark_node)
13761 : {
13762 1267 : init = get_initializer_for (init, member);
13763 1267 : if (init)
13764 : {
13765 889 : memsize = TYPE_SIZE_UNIT (TREE_TYPE (init));
13766 889 : if (tree refsize = TYPE_SIZE_UNIT (argtype))
13767 : {
13768 : /* Use the larger of the initializer size and the tail
13769 : padding in the enclosing struct. */
13770 889 : poly_int64 rsz = tree_to_poly_int64 (refsize);
13771 889 : rsz -= baseoff;
13772 889 : if (known_lt (tree_to_poly_int64 (memsize), rsz))
13773 56 : memsize = wide_int_to_tree (TREE_TYPE (memsize), rsz);
13774 : }
13775 :
13776 889 : baseoff = 0;
13777 : }
13778 : }
13779 :
13780 889 : if (!memsize)
13781 : {
13782 2372 : if (typematch)
13783 : {
13784 1808 : if (DECL_P (base)
13785 1808 : && DECL_EXTERNAL (base)
13786 454 : && bt == basetype
13787 2256 : && *sam != special_array_member::int_0)
13788 : /* The size of a flexible array member of an extern struct
13789 : with no initializer cannot be determined (it's defined
13790 : in another translation unit and can have an initializer
13791 : with an arbitrary number of elements). */
13792 : return NULL_TREE;
13793 :
13794 : /* Use the size of the base struct or, for interior zero-length
13795 : arrays, the size of the enclosing type. */
13796 1383 : memsize = TYPE_SIZE_UNIT (bt);
13797 : }
13798 564 : else if (DECL_P (base))
13799 : /* Use the size of the BASE object (possibly an array of some
13800 : other type such as char used to store the struct). */
13801 561 : memsize = DECL_SIZE_UNIT (base);
13802 : else
13803 : return NULL_TREE;
13804 : }
13805 :
13806 : /* If the flexible array member has a known size use the greater
13807 : of it and the tail padding in the enclosing struct.
13808 : Otherwise, when the size of the flexible array member is unknown
13809 : and the referenced object is not a struct, use the size of its
13810 : type when known. This detects sizes of array buffers when cast
13811 : to struct types with flexible array members. */
13812 1944 : if (memsize)
13813 : {
13814 2808 : if (!tree_fits_poly_int64_p (memsize))
13815 : return NULL_TREE;
13816 2808 : poly_int64 memsz64 = memsize ? tree_to_poly_int64 (memsize) : 0;
13817 2808 : if (known_lt (baseoff, memsz64))
13818 : {
13819 1341 : memsz64 -= baseoff;
13820 1341 : return wide_int_to_tree (TREE_TYPE (memsize), memsz64);
13821 : }
13822 1467 : return size_zero_node;
13823 : }
13824 :
13825 : /* Return "don't know" for an external non-array object since its
13826 : flexible array member can be initialized to have any number of
13827 : elements. Otherwise, return zero because the flexible array
13828 : member has no elements. */
13829 25 : return (DECL_P (base)
13830 25 : && DECL_EXTERNAL (base)
13831 25 : && (!typematch
13832 0 : || TREE_CODE (basetype) != ARRAY_TYPE)
13833 25 : ? NULL_TREE : size_zero_node);
13834 : }
13835 :
13836 : /* Return true if the given node CALL is a call to a .ACCESS_WITH_SIZE
13837 : function. */
13838 : bool
13839 168159837 : is_access_with_size_p (const_tree call)
13840 : {
13841 168159837 : if (TREE_CODE (call) != CALL_EXPR)
13842 : return false;
13843 43658510 : if (CALL_EXPR_IFN (call) == IFN_ACCESS_WITH_SIZE)
13844 1073 : return true;
13845 : return false;
13846 : }
13847 :
13848 : /* Get the corresponding reference from the call to a .ACCESS_WITH_SIZE.
13849 : * i.e the first argument of this call. Return NULL_TREE otherwise. */
13850 : tree
13851 3 : get_ref_from_access_with_size (tree call)
13852 : {
13853 3 : if (is_access_with_size_p (call))
13854 3 : return CALL_EXPR_ARG (call, 0);
13855 : return NULL_TREE;
13856 : }
13857 :
13858 : /* Return the machine mode of T. For vectors, returns the mode of the
13859 : inner type. The main use case is to feed the result to HONOR_NANS,
13860 : avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
13861 :
13862 : machine_mode
13863 5953243733 : element_mode (const_tree t)
13864 : {
13865 5953243733 : if (!TYPE_P (t))
13866 208667153 : t = TREE_TYPE (t);
13867 5953243733 : if (VECTOR_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
13868 1561831806 : t = TREE_TYPE (t);
13869 5953243733 : return TYPE_MODE (t);
13870 : }
13871 :
13872 : /* Vector types need to re-check the target flags each time we report
13873 : the machine mode. We need to do this because attribute target can
13874 : change the result of vector_mode_supported_p and have_regs_of_mode
13875 : on a per-function basis. Thus the TYPE_MODE of a VECTOR_TYPE can
13876 : change on a per-function basis. */
13877 : /* ??? Possibly a better solution is to run through all the types
13878 : referenced by a function and re-compute the TYPE_MODE once, rather
13879 : than make the TYPE_MODE macro call a function. */
13880 :
13881 : machine_mode
13882 1410935965 : vector_type_mode (const_tree t)
13883 : {
13884 1410935965 : machine_mode mode;
13885 :
13886 1410935965 : gcc_assert (TREE_CODE (t) == VECTOR_TYPE);
13887 :
13888 1410935965 : mode = t->type_common.mode;
13889 319741638 : if (VECTOR_MODE_P (mode)
13890 1690771366 : && (!targetm.vector_mode_supported_p (mode)
13891 1348152779 : || !have_regs_of_mode[mode]))
13892 : {
13893 23839168 : scalar_int_mode innermode;
13894 :
13895 : /* For integers, try mapping it to a same-sized scalar mode. */
13896 23839168 : if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode))
13897 : {
13898 35648544 : poly_int64 size = (TYPE_VECTOR_SUBPARTS (t)
13899 17824272 : * GET_MODE_BITSIZE (innermode));
13900 17824272 : scalar_int_mode mode;
13901 32137379 : if (int_mode_for_size (size, 0).exists (&mode)
13902 14474589 : && have_regs_of_mode[mode])
13903 161482 : return mode;
13904 : }
13905 :
13906 : return BLKmode;
13907 : }
13908 :
13909 : return mode;
13910 : }
13911 :
13912 : /* Return the size in bits of each element of vector type TYPE. */
13913 :
13914 : unsigned int
13915 252327 : vector_element_bits (const_tree type)
13916 : {
13917 252327 : gcc_checking_assert (VECTOR_TYPE_P (type));
13918 252327 : if (VECTOR_BOOLEAN_TYPE_P (type))
13919 1316 : return TYPE_PRECISION (TREE_TYPE (type));
13920 251011 : return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
13921 : }
13922 :
13923 : /* Calculate the size in bits of each element of vector type TYPE
13924 : and return the result as a tree of type bitsizetype. */
13925 :
13926 : tree
13927 121814 : vector_element_bits_tree (const_tree type)
13928 : {
13929 121814 : gcc_checking_assert (VECTOR_TYPE_P (type));
13930 121814 : if (VECTOR_BOOLEAN_TYPE_P (type))
13931 681 : return bitsize_int (vector_element_bits (type));
13932 121133 : return TYPE_SIZE (TREE_TYPE (type));
13933 : }
13934 :
13935 : /* Verify that basic properties of T match TV and thus T can be a variant of
13936 : TV. TV should be the more specified variant (i.e. the main variant). */
13937 :
13938 : static bool
13939 199294707 : verify_type_variant (const_tree t, tree tv)
13940 : {
13941 : /* Type variant can differ by:
13942 :
13943 : - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
13944 : ENCODE_QUAL_ADDR_SPACE.
13945 : - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
13946 : in this case some values may not be set in the variant types
13947 : (see TYPE_COMPLETE_P checks).
13948 : - it is possible to have TYPE_ARTIFICIAL variant of non-artificial type
13949 : - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
13950 : - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
13951 : - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
13952 : - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
13953 : this is necessary to make it possible to merge types form different TUs
13954 : - arrays, pointers and references may have TREE_TYPE that is a variant
13955 : of TREE_TYPE of their main variants.
13956 : - aggregates may have new TYPE_FIELDS list that list variants of
13957 : the main variant TYPE_FIELDS.
13958 : - vector types may differ by TYPE_VECTOR_OPAQUE
13959 : */
13960 :
13961 : /* Convenience macro for matching individual fields. */
13962 : #define verify_variant_match(flag) \
13963 : do { \
13964 : if (flag (tv) != flag (t)) \
13965 : { \
13966 : error ("type variant differs by %s", #flag); \
13967 : debug_tree (tv); \
13968 : return false; \
13969 : } \
13970 : } while (false)
13971 :
13972 : /* tree_base checks. */
13973 :
13974 199294707 : verify_variant_match (TREE_CODE);
13975 : /* FIXME: Ada builds non-artificial variants of artificial types. */
13976 : #if 0
13977 : if (TYPE_ARTIFICIAL (tv))
13978 : verify_variant_match (TYPE_ARTIFICIAL);
13979 : #endif
13980 199294707 : if (POINTER_TYPE_P (tv))
13981 13007701 : verify_variant_match (TYPE_REF_CAN_ALIAS_ALL);
13982 : /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
13983 199294707 : verify_variant_match (TYPE_UNSIGNED);
13984 199294707 : verify_variant_match (TYPE_PACKED);
13985 199294707 : if (TREE_CODE (t) == REFERENCE_TYPE)
13986 3169249 : verify_variant_match (TYPE_REF_IS_RVALUE);
13987 199294707 : if (AGGREGATE_TYPE_P (t))
13988 82015732 : verify_variant_match (TYPE_REVERSE_STORAGE_ORDER);
13989 : else
13990 117278975 : verify_variant_match (TYPE_SATURATING);
13991 : /* FIXME: This check trigger during libstdc++ build. */
13992 : #if 0
13993 : if (RECORD_OR_UNION_TYPE_P (t) && COMPLETE_TYPE_P (t))
13994 : verify_variant_match (TYPE_FINAL_P);
13995 : #endif
13996 :
13997 : /* tree_type_common checks. */
13998 :
13999 199294707 : if (COMPLETE_TYPE_P (t))
14000 : {
14001 187362461 : verify_variant_match (TYPE_MODE);
14002 187362461 : if (TREE_CODE (TYPE_SIZE (t)) != PLACEHOLDER_EXPR
14003 187362461 : && TREE_CODE (TYPE_SIZE (tv)) != PLACEHOLDER_EXPR)
14004 187362461 : verify_variant_match (TYPE_SIZE);
14005 187362461 : if (TREE_CODE (TYPE_SIZE_UNIT (t)) != PLACEHOLDER_EXPR
14006 187362461 : && TREE_CODE (TYPE_SIZE_UNIT (tv)) != PLACEHOLDER_EXPR
14007 374724922 : && TYPE_SIZE_UNIT (t) != TYPE_SIZE_UNIT (tv))
14008 : {
14009 0 : gcc_assert (!operand_equal_p (TYPE_SIZE_UNIT (t),
14010 : TYPE_SIZE_UNIT (tv), 0));
14011 0 : error ("type variant has different %<TYPE_SIZE_UNIT%>");
14012 0 : debug_tree (tv);
14013 0 : error ("type variant%'s %<TYPE_SIZE_UNIT%>");
14014 0 : debug_tree (TYPE_SIZE_UNIT (tv));
14015 0 : error ("type%'s %<TYPE_SIZE_UNIT%>");
14016 0 : debug_tree (TYPE_SIZE_UNIT (t));
14017 0 : return false;
14018 : }
14019 187362461 : verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
14020 : }
14021 199294707 : verify_variant_match (TYPE_PRECISION_RAW);
14022 199294707 : if (RECORD_OR_UNION_TYPE_P (t))
14023 81392769 : verify_variant_match (TYPE_TRANSPARENT_AGGR);
14024 117901938 : else if (TREE_CODE (t) == ARRAY_TYPE)
14025 622963 : verify_variant_match (TYPE_NONALIASED_COMPONENT);
14026 : /* During LTO we merge variant lists from different translation units
14027 : that may differ BY TYPE_CONTEXT that in turn may point
14028 : to TRANSLATION_UNIT_DECL.
14029 : Ada also builds variants of types with different TYPE_CONTEXT. */
14030 : #if 0
14031 : if (!in_lto_p || !TYPE_FILE_SCOPE_P (t))
14032 : verify_variant_match (TYPE_CONTEXT);
14033 : #endif
14034 199294707 : if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == INTEGER_TYPE)
14035 63756570 : verify_variant_match (TYPE_STRING_FLAG);
14036 199294707 : if (TREE_CODE (t) == RECORD_TYPE || TREE_CODE (t) == UNION_TYPE)
14037 81392769 : verify_variant_match (TYPE_CXX_ODR_P);
14038 199294707 : if (TYPE_ALIAS_SET_KNOWN_P (t))
14039 : {
14040 0 : error ("type variant with %<TYPE_ALIAS_SET_KNOWN_P%>");
14041 0 : debug_tree (tv);
14042 0 : return false;
14043 : }
14044 :
14045 : /* tree_type_non_common checks. */
14046 :
14047 : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
14048 : and dangle the pointer from time to time. */
14049 81392769 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_VFIELD (t) != TYPE_VFIELD (tv)
14050 199294707 : && (in_lto_p || !TYPE_VFIELD (tv)
14051 0 : || TREE_CODE (TYPE_VFIELD (tv)) != TREE_LIST))
14052 : {
14053 0 : error ("type variant has different %<TYPE_VFIELD%>");
14054 0 : debug_tree (tv);
14055 0 : return false;
14056 : }
14057 3554712 : if ((TREE_CODE (t) == ENUMERAL_TYPE && COMPLETE_TYPE_P (t))
14058 195740052 : || TREE_CODE (t) == INTEGER_TYPE
14059 132606445 : || TREE_CODE (t) == BOOLEAN_TYPE
14060 97751705 : || TREE_CODE (t) == BITINT_TYPE
14061 97751445 : || SCALAR_FLOAT_TYPE_P (t)
14062 295070212 : || FIXED_POINT_TYPE_P (t))
14063 : {
14064 103519202 : verify_variant_match (TYPE_MAX_VALUE);
14065 103519202 : verify_variant_match (TYPE_MIN_VALUE);
14066 : }
14067 199294707 : if (TREE_CODE (t) == METHOD_TYPE)
14068 11716 : verify_variant_match (TYPE_METHOD_BASETYPE);
14069 199294707 : if (TREE_CODE (t) == OFFSET_TYPE)
14070 1607 : verify_variant_match (TYPE_OFFSET_BASETYPE);
14071 199294707 : if (TREE_CODE (t) == ARRAY_TYPE)
14072 622963 : verify_variant_match (TYPE_ARRAY_MAX_SIZE);
14073 : /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
14074 : or even type's main variant. This is needed to make bootstrap pass
14075 : and the bug seems new in GCC 5.
14076 : C++ FE should be updated to make this consistent and we should check
14077 : that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
14078 : is a match with main variant.
14079 :
14080 : Also disable the check for Java for now because of parser hack that builds
14081 : first an dummy BINFO and then sometimes replace it by real BINFO in some
14082 : of the copies. */
14083 81392769 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t) && TYPE_BINFO (tv)
14084 69289361 : && TYPE_BINFO (t) != TYPE_BINFO (tv)
14085 : /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
14086 : Since there is no cheap way to tell C++/Java type w/o LTO, do checking
14087 : at LTO time only. */
14088 199294707 : && (in_lto_p && odr_type_p (t)))
14089 : {
14090 0 : error ("type variant has different %<TYPE_BINFO%>");
14091 0 : debug_tree (tv);
14092 0 : error ("type variant%'s %<TYPE_BINFO%>");
14093 0 : debug_tree (TYPE_BINFO (tv));
14094 0 : error ("type%'s %<TYPE_BINFO%>");
14095 0 : debug_tree (TYPE_BINFO (t));
14096 0 : return false;
14097 : }
14098 :
14099 : /* Check various uses of TYPE_VALUES_RAW. */
14100 199294707 : if (TREE_CODE (t) == ENUMERAL_TYPE
14101 199294707 : && TYPE_VALUES (t))
14102 3384447 : verify_variant_match (TYPE_VALUES);
14103 195910260 : else if (TREE_CODE (t) == ARRAY_TYPE)
14104 622963 : verify_variant_match (TYPE_DOMAIN);
14105 : /* Permit incomplete variants of complete type. While FEs may complete
14106 : all variants, this does not happen for C++ templates in all cases. */
14107 195287297 : else if (RECORD_OR_UNION_TYPE_P (t)
14108 81392769 : && COMPLETE_TYPE_P (t)
14109 264955929 : && TYPE_FIELDS (t) != TYPE_FIELDS (tv))
14110 : {
14111 4102 : tree f1, f2;
14112 :
14113 : /* Fortran builds qualified variants as new records with items of
14114 : qualified type. Verify that they looks same. */
14115 4102 : for (f1 = TYPE_FIELDS (t), f2 = TYPE_FIELDS (tv);
14116 13115 : f1 && f2;
14117 9013 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
14118 9013 : if (TREE_CODE (f1) != FIELD_DECL || TREE_CODE (f2) != FIELD_DECL
14119 9013 : || (TYPE_MAIN_VARIANT (TREE_TYPE (f1))
14120 9013 : != TYPE_MAIN_VARIANT (TREE_TYPE (f2))
14121 : /* FIXME: gfc_nonrestricted_type builds all types as variants
14122 : with exception of pointer types. It deeply copies the type
14123 : which means that we may end up with a variant type
14124 : referring non-variant pointer. We may change it to
14125 : produce types as variants, too, like
14126 : objc_get_protocol_qualified_type does. */
14127 29 : && !POINTER_TYPE_P (TREE_TYPE (f1)))
14128 9013 : || DECL_FIELD_OFFSET (f1) != DECL_FIELD_OFFSET (f2)
14129 18026 : || DECL_FIELD_BIT_OFFSET (f1) != DECL_FIELD_BIT_OFFSET (f2))
14130 : break;
14131 4102 : if (f1 || f2)
14132 : {
14133 0 : error ("type variant has different %<TYPE_FIELDS%>");
14134 0 : debug_tree (tv);
14135 0 : error ("first mismatch is field");
14136 0 : debug_tree (f1);
14137 0 : error ("and field");
14138 0 : debug_tree (f2);
14139 0 : return false;
14140 : }
14141 : }
14142 195283195 : else if (FUNC_OR_METHOD_TYPE_P (t))
14143 151874 : verify_variant_match (TYPE_ARG_TYPES);
14144 : /* For C++ the qualified variant of array type is really an array type
14145 : of qualified TREE_TYPE.
14146 : objc builds variants of pointer where pointer to type is a variant, too
14147 : in objc_get_protocol_qualified_type. */
14148 199294707 : if (TREE_TYPE (t) != TREE_TYPE (tv)
14149 199294707 : && ((TREE_CODE (t) != ARRAY_TYPE
14150 0 : && !POINTER_TYPE_P (t))
14151 537451 : || TYPE_MAIN_VARIANT (TREE_TYPE (t))
14152 537451 : != TYPE_MAIN_VARIANT (TREE_TYPE (tv))))
14153 : {
14154 0 : error ("type variant has different %<TREE_TYPE%>");
14155 0 : debug_tree (tv);
14156 0 : error ("type variant%'s %<TREE_TYPE%>");
14157 0 : debug_tree (TREE_TYPE (tv));
14158 0 : error ("type%'s %<TREE_TYPE%>");
14159 0 : debug_tree (TREE_TYPE (t));
14160 0 : return false;
14161 : }
14162 199294707 : if (type_with_alias_set_p (t)
14163 199294707 : && !gimple_canonical_types_compatible_p (t, tv, false))
14164 : {
14165 0 : error ("type is not compatible with its variant");
14166 0 : debug_tree (tv);
14167 0 : error ("type variant%'s %<TREE_TYPE%>");
14168 0 : debug_tree (TREE_TYPE (tv));
14169 0 : error ("type%'s %<TREE_TYPE%>");
14170 0 : debug_tree (TREE_TYPE (t));
14171 0 : return false;
14172 : }
14173 : return true;
14174 : #undef verify_variant_match
14175 : }
14176 :
14177 :
14178 : /* The TYPE_CANONICAL merging machinery. It should closely resemble
14179 : the middle-end types_compatible_p function. It needs to avoid
14180 : claiming types are different for types that should be treated
14181 : the same with respect to TBAA. Canonical types are also used
14182 : for IL consistency checks via the useless_type_conversion_p
14183 : predicate which does not handle all type kinds itself but falls
14184 : back to pointer-comparison of TYPE_CANONICAL for aggregates
14185 : for example. */
14186 :
14187 : /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
14188 : type calculation because we need to allow inter-operability between signed
14189 : and unsigned variants. */
14190 :
14191 : bool
14192 1675512 : type_with_interoperable_signedness (const_tree type)
14193 : {
14194 : /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
14195 : signed char and unsigned char. Similarly fortran FE builds
14196 : C_SIZE_T as signed type, while C defines it unsigned. */
14197 :
14198 1675512 : return tree_code_for_canonical_type_merging (TREE_CODE (type))
14199 : == INTEGER_TYPE
14200 1675308 : && (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)
14201 452821 : || TYPE_PRECISION (type) == TYPE_PRECISION (size_type_node));
14202 : }
14203 :
14204 : /* Return true iff T1 and T2 are structurally identical for what
14205 : TBAA is concerned.
14206 : This function is used both by lto.cc canonical type merging and by the
14207 : verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
14208 : that have TYPE_CANONICAL defined and assume them equivalent. This is useful
14209 : only for LTO because only in these cases TYPE_CANONICAL equivalence
14210 : correspond to one defined by gimple_canonical_types_compatible_p. */
14211 :
14212 : bool
14213 407770712 : gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
14214 : bool trust_type_canonical)
14215 : {
14216 : /* Type variants should be same as the main variant. When not doing sanity
14217 : checking to verify this fact, go to main variants and save some work. */
14218 408168107 : if (trust_type_canonical)
14219 : {
14220 896910 : t1 = TYPE_MAIN_VARIANT (t1);
14221 896910 : t2 = TYPE_MAIN_VARIANT (t2);
14222 : }
14223 :
14224 : /* Check first for the obvious case of pointer identity. */
14225 408168107 : if (t1 == t2)
14226 : return true;
14227 :
14228 : /* Check that we have two types to compare. */
14229 345246498 : if (t1 == NULL_TREE || t2 == NULL_TREE)
14230 : return false;
14231 :
14232 : /* We consider complete types always compatible with incomplete type.
14233 : This does not make sense for canonical type calculation and thus we
14234 : need to ensure that we are never called on it.
14235 :
14236 : FIXME: For more correctness the function probably should have three modes
14237 : 1) mode assuming that types are complete matching their structure
14238 : 2) mode allowing incomplete types but producing equivalence classes
14239 : and thus ignoring all info from complete types
14240 : 3) mode allowing incomplete types to match complete but checking
14241 : compatibility between complete types.
14242 :
14243 : 1 and 2 can be used for canonical type calculation. 3 is the real
14244 : definition of type compatibility that can be used i.e. for warnings during
14245 : declaration merging. */
14246 :
14247 345246498 : gcc_assert (!trust_type_canonical
14248 : || (type_with_alias_set_p (t1) && type_with_alias_set_p (t2)));
14249 :
14250 : /* If the types have been previously registered and found equal
14251 : they still are. */
14252 :
14253 690196829 : if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t2)
14254 689249595 : && trust_type_canonical)
14255 : {
14256 : /* Do not use TYPE_CANONICAL of pointer types. For LTO streamed types
14257 : they are always NULL, but they are set to non-NULL for types
14258 : constructed by build_pointer_type and variants. In this case the
14259 : TYPE_CANONICAL is more fine grained than the equivalnce we test (where
14260 : all pointers are considered equal. Be sure to not return false
14261 : negatives. */
14262 165448 : gcc_checking_assert (canonical_type_used_p (t1)
14263 : && canonical_type_used_p (t2));
14264 82724 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
14265 : }
14266 :
14267 : /* For types where we do ODR based TBAA the canonical type is always
14268 : set correctly, so we know that types are different if their
14269 : canonical types does not match. */
14270 345163774 : if (trust_type_canonical
14271 345974919 : && (odr_type_p (t1) && odr_based_tbaa_p (t1))
14272 811145 : != (odr_type_p (t2) && odr_based_tbaa_p (t2)))
14273 : return false;
14274 :
14275 : /* Can't be the same type if the types don't have the same code. */
14276 345163774 : enum tree_code code = tree_code_for_canonical_type_merging (TREE_CODE (t1));
14277 686071078 : if (code != tree_code_for_canonical_type_merging (TREE_CODE (t2)))
14278 : return false;
14279 :
14280 : /* Qualifiers do not matter for canonical type comparison purposes. */
14281 :
14282 : /* Void types and nullptr types are always the same. */
14283 345163739 : if (VOID_TYPE_P (t1)
14284 345115117 : || TREE_CODE (t1) == NULLPTR_TYPE)
14285 : return true;
14286 :
14287 : /* Can't be compatible types if they have different mode. Because of
14288 : flexible array members, we allow mismatching modes for structures or
14289 : unions. */
14290 344452534 : if (!RECORD_OR_UNION_TYPE_P (t1)
14291 344452534 : && TREE_CODE (t1) != ARRAY_TYPE
14292 344452534 : && TYPE_MODE (t1) != TYPE_MODE (t2))
14293 : return false;
14294 :
14295 : /* Non-aggregate types can be handled cheaply. */
14296 344452534 : if (INTEGRAL_TYPE_P (t1)
14297 344452534 : || SCALAR_FLOAT_TYPE_P (t1)
14298 182405415 : || FIXED_POINT_TYPE_P (t1)
14299 182033643 : || VECTOR_TYPE_P (t1)
14300 181983458 : || TREE_CODE (t1) == COMPLEX_TYPE
14301 181636248 : || TREE_CODE (t1) == OFFSET_TYPE
14302 181633012 : || POINTER_TYPE_P (t1))
14303 : {
14304 : /* Can't be the same type if they have different precision. */
14305 206193689 : if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
14306 : return false;
14307 :
14308 : /* In some cases the signed and unsigned types are required to be
14309 : inter-operable. */
14310 206193689 : if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)
14311 206193689 : && !type_with_interoperable_signedness (t1))
14312 : return false;
14313 :
14314 : /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
14315 : interoperable with "signed char". Unless all frontends are revisited
14316 : to agree on these types, we must ignore the flag completely. */
14317 :
14318 : /* Fortran standard define C_PTR type that is compatible with every
14319 : C pointer. For this reason we need to glob all pointers into one.
14320 : Still pointers in different address spaces are not compatible. */
14321 206193689 : if (POINTER_TYPE_P (t1))
14322 : {
14323 43374167 : if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
14324 43374167 : != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
14325 : return false;
14326 : }
14327 :
14328 : /* Tail-recurse to components. */
14329 206193689 : if (VECTOR_TYPE_P (t1)
14330 206193689 : || TREE_CODE (t1) == COMPLEX_TYPE)
14331 1192185 : return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
14332 397395 : TREE_TYPE (t2),
14333 397395 : trust_type_canonical);
14334 :
14335 : return true;
14336 : }
14337 :
14338 : /* Do type-specific comparisons. */
14339 138258845 : switch (TREE_CODE (t1))
14340 : {
14341 1122727 : case ARRAY_TYPE:
14342 : /* Array types are the same if the element types are the same and
14343 : minimum and maximum index are the same. */
14344 1122727 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14345 : trust_type_canonical)
14346 1122688 : || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
14347 1122688 : || TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2)
14348 2245415 : || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
14349 : return false;
14350 : else
14351 : {
14352 1122688 : tree i1 = TYPE_DOMAIN (t1);
14353 1122688 : tree i2 = TYPE_DOMAIN (t2);
14354 :
14355 : /* For an incomplete external array, the type domain can be
14356 : NULL_TREE. Check this condition also. */
14357 1122688 : if (i1 == NULL_TREE && i2 == NULL_TREE)
14358 : return true;
14359 1022778 : else if (i1 == NULL_TREE || i2 == NULL_TREE)
14360 : return false;
14361 : else
14362 : {
14363 1022778 : tree min1 = TYPE_MIN_VALUE (i1);
14364 1022778 : tree min2 = TYPE_MIN_VALUE (i2);
14365 1022778 : tree max1 = TYPE_MAX_VALUE (i1);
14366 1022778 : tree max2 = TYPE_MAX_VALUE (i2);
14367 :
14368 : /* The minimum/maximum values have to be the same. */
14369 1022778 : if ((min1 == min2
14370 0 : || (min1 && min2
14371 0 : && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
14372 0 : && TREE_CODE (min2) == PLACEHOLDER_EXPR)
14373 0 : || operand_equal_p (min1, min2, 0))))
14374 1022778 : && (max1 == max2
14375 0 : || (max1 && max2
14376 0 : && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
14377 0 : && TREE_CODE (max2) == PLACEHOLDER_EXPR)
14378 0 : || operand_equal_p (max1, max2, 0)))))
14379 1022778 : return true;
14380 : else
14381 : return false;
14382 : }
14383 : }
14384 :
14385 7044 : case METHOD_TYPE:
14386 7044 : case FUNCTION_TYPE:
14387 : /* Function types are the same if the return type and arguments types
14388 : are the same. */
14389 7044 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14390 : trust_type_canonical))
14391 : return false;
14392 :
14393 7044 : if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)
14394 7044 : && (TYPE_NO_NAMED_ARGS_STDARG_P (t1)
14395 322 : == TYPE_NO_NAMED_ARGS_STDARG_P (t2)))
14396 : return true;
14397 : else
14398 : {
14399 6722 : tree parms1, parms2;
14400 :
14401 6722 : for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
14402 29955 : parms1 && parms2;
14403 23233 : parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
14404 : {
14405 46466 : if (!gimple_canonical_types_compatible_p
14406 23233 : (TREE_VALUE (parms1), TREE_VALUE (parms2),
14407 : trust_type_canonical))
14408 : return false;
14409 : }
14410 :
14411 6722 : if (parms1 || parms2)
14412 : return false;
14413 :
14414 6722 : return true;
14415 : }
14416 :
14417 136784140 : case RECORD_TYPE:
14418 136784140 : case UNION_TYPE:
14419 136784140 : case QUAL_UNION_TYPE:
14420 136784140 : {
14421 136784140 : tree f1, f2;
14422 :
14423 : /* Don't try to compare variants of an incomplete type, before
14424 : TYPE_FIELDS has been copied around. */
14425 136784140 : if (!COMPLETE_TYPE_P (t1) && !COMPLETE_TYPE_P (t2))
14426 : return true;
14427 :
14428 :
14429 125758637 : if (TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2))
14430 : return false;
14431 :
14432 : /* For aggregate types, all the fields must be the same. */
14433 125758637 : for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
14434 188391152 : f1 || f2;
14435 62632515 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
14436 : {
14437 : /* Skip non-fields and zero-sized fields, except zero-sized
14438 : arrays at the end. */
14439 1895405069 : while (f1 && (TREE_CODE (f1) != FIELD_DECL
14440 114873862 : || (DECL_SIZE (f1)
14441 114856524 : && integer_zerop (DECL_SIZE (f1))
14442 52241324 : && (TREE_CHAIN (f1)
14443 3495 : || TREE_CODE (TREE_TYPE (f1))
14444 : != ARRAY_TYPE))))
14445 1708141327 : f1 = TREE_CHAIN (f1);
14446 1895406631 : while (f2 && (TREE_CODE (f2) != FIELD_DECL
14447 114888950 : || (DECL_SIZE (f2)
14448 114871504 : && integer_zerop (DECL_SIZE (f2))
14449 52242893 : && (TREE_CHAIN (f2)
14450 4556 : || TREE_CODE (TREE_TYPE (f2))
14451 : != ARRAY_TYPE))))
14452 1708142889 : f2 = TREE_CHAIN (f2);
14453 187263742 : if (!f1 || !f2)
14454 : break;
14455 :
14456 62633310 : tree t1 = TREE_TYPE (f1);
14457 62633310 : tree t2 = TREE_TYPE (f2);
14458 :
14459 : /* If the last element are arrays, we only compare the element
14460 : types. */
14461 63751183 : if (TREE_CHAIN (f1) == NULL_TREE && TREE_CODE (t1) == ARRAY_TYPE
14462 62720541 : && TREE_CHAIN (f2) == NULL_TREE && TREE_CODE (t2) == ARRAY_TYPE)
14463 : {
14464 : /* If both arrays have zero size, this is a match. */
14465 157532 : if (DECL_SIZE (f1) && integer_zerop (DECL_SIZE (f1))
14466 87998 : && DECL_SIZE (f2) && integer_zerop (DECL_SIZE (f2)))
14467 : return true;
14468 :
14469 86455 : t1 = TREE_TYPE (t1);
14470 86455 : t2 = TREE_TYPE (t2);
14471 : }
14472 :
14473 62632539 : if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
14474 62632534 : || !gimple_compare_field_offset (f1, f2)
14475 125265073 : || !gimple_canonical_types_compatible_p
14476 62632534 : (t1, t2, trust_type_canonical))
14477 : return false;
14478 : }
14479 :
14480 : /* If one aggregate has more fields than the other, they
14481 : are not the same. */
14482 125757842 : if (f1 || f2)
14483 13526 : return false;
14484 :
14485 : return true;
14486 : }
14487 :
14488 344934 : default:
14489 : /* Consider all types with language specific trees in them mutually
14490 : compatible. This is executed only from verify_type and false
14491 : positives can be tolerated. */
14492 344934 : gcc_assert (!in_lto_p);
14493 : return true;
14494 : }
14495 : }
14496 :
14497 : /* For OPAQUE_TYPE T, it should have only size and alignment information
14498 : and its mode should be of class MODE_OPAQUE. This function verifies
14499 : these properties of T match TV which is the main variant of T and TC
14500 : which is the canonical of T. */
14501 :
14502 : static void
14503 0 : verify_opaque_type (const_tree t, tree tv, tree tc)
14504 : {
14505 0 : gcc_assert (OPAQUE_TYPE_P (t));
14506 0 : gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv));
14507 0 : gcc_assert (tc && tc == TYPE_CANONICAL (tc));
14508 :
14509 : /* For an opaque type T1, check if some of its properties match
14510 : the corresponding ones of the other opaque type T2, emit some
14511 : error messages for those inconsistent ones. */
14512 0 : auto check_properties_for_opaque_type = [](const_tree t1, tree t2,
14513 : const char *kind_msg)
14514 : {
14515 0 : if (!OPAQUE_TYPE_P (t2))
14516 : {
14517 0 : error ("type %s is not an opaque type", kind_msg);
14518 0 : debug_tree (t2);
14519 0 : return;
14520 : }
14521 0 : if (!OPAQUE_MODE_P (TYPE_MODE (t2)))
14522 : {
14523 0 : error ("type %s is not with opaque mode", kind_msg);
14524 0 : debug_tree (t2);
14525 0 : return;
14526 : }
14527 0 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
14528 : {
14529 0 : error ("type %s differs by %<TYPE_MODE%>", kind_msg);
14530 0 : debug_tree (t2);
14531 0 : return;
14532 : }
14533 0 : poly_uint64 t1_size = tree_to_poly_uint64 (TYPE_SIZE (t1));
14534 0 : poly_uint64 t2_size = tree_to_poly_uint64 (TYPE_SIZE (t2));
14535 0 : if (maybe_ne (t1_size, t2_size))
14536 : {
14537 0 : error ("type %s differs by %<TYPE_SIZE%>", kind_msg);
14538 0 : debug_tree (t2);
14539 0 : return;
14540 : }
14541 0 : if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2))
14542 : {
14543 0 : error ("type %s differs by %<TYPE_ALIGN%>", kind_msg);
14544 0 : debug_tree (t2);
14545 0 : return;
14546 : }
14547 0 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
14548 : {
14549 0 : error ("type %s differs by %<TYPE_USER_ALIGN%>", kind_msg);
14550 0 : debug_tree (t2);
14551 0 : return;
14552 : }
14553 : };
14554 :
14555 0 : if (t != tv)
14556 0 : check_properties_for_opaque_type (t, tv, "variant");
14557 :
14558 0 : if (t != tc)
14559 0 : check_properties_for_opaque_type (t, tc, "canonical");
14560 0 : }
14561 :
14562 : /* Verify type T. */
14563 :
14564 : void
14565 921460958 : verify_type (const_tree t)
14566 : {
14567 921460958 : bool error_found = false;
14568 921460958 : tree mv = TYPE_MAIN_VARIANT (t);
14569 921460958 : tree ct = TYPE_CANONICAL (t);
14570 :
14571 921460958 : if (OPAQUE_TYPE_P (t))
14572 : {
14573 0 : verify_opaque_type (t, mv, ct);
14574 0 : return;
14575 : }
14576 :
14577 921460958 : if (!mv)
14578 : {
14579 0 : error ("main variant is not defined");
14580 0 : error_found = true;
14581 : }
14582 921460958 : else if (mv != TYPE_MAIN_VARIANT (mv))
14583 : {
14584 0 : error ("%<TYPE_MAIN_VARIANT%> has different %<TYPE_MAIN_VARIANT%>");
14585 0 : debug_tree (mv);
14586 0 : error_found = true;
14587 : }
14588 921460958 : else if (t != mv && !verify_type_variant (t, mv))
14589 : error_found = true;
14590 :
14591 921460958 : if (!ct)
14592 : ;
14593 919429069 : else if (TYPE_CANONICAL (ct) != ct)
14594 : {
14595 0 : error ("%<TYPE_CANONICAL%> has different %<TYPE_CANONICAL%>");
14596 0 : debug_tree (ct);
14597 0 : error_found = true;
14598 : }
14599 : /* Method and function types cannot be used to address memory and thus
14600 : TYPE_CANONICAL really matters only for determining useless conversions.
14601 :
14602 : FIXME: C++ FE produce declarations of builtin functions that are not
14603 : compatible with main variants. */
14604 919429069 : else if (TREE_CODE (t) == FUNCTION_TYPE)
14605 : ;
14606 918793005 : else if (t != ct
14607 : /* FIXME: gimple_canonical_types_compatible_p cannot compare types
14608 : with variably sized arrays because their sizes possibly
14609 : gimplified to different variables. */
14610 155872419 : && !variably_modified_type_p (ct, NULL)
14611 155867799 : && !gimple_canonical_types_compatible_p (t, ct, false)
14612 918806531 : && COMPLETE_TYPE_P (t))
14613 : {
14614 0 : error ("%<TYPE_CANONICAL%> is not compatible");
14615 0 : debug_tree (ct);
14616 0 : error_found = true;
14617 : }
14618 1665777204 : if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t)
14619 : /* We allow a mismatch for structure or union because of
14620 : flexible array members. */
14621 742355130 : && !RECORD_OR_UNION_TYPE_P (t)
14622 306263323 : && !RECORD_OR_UNION_TYPE_P (TYPE_CANONICAL (t))
14623 306263323 : && TREE_CODE (t) != ARRAY_TYPE
14624 1226213201 : && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
14625 : {
14626 0 : error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");
14627 0 : debug_tree (ct);
14628 0 : error_found = true;
14629 : }
14630 921460958 : if (TYPE_MAIN_VARIANT (t) == t && ct && TYPE_MAIN_VARIANT (ct) != ct)
14631 : {
14632 : /* This can happen when build_type_attribute_variant is called on
14633 : C/C++ arrays of qualified types. volatile int[2] is unqualified
14634 : ARRAY_TYPE with volatile int element type.
14635 : TYPE_CANONICAL (volatile int) is itself and so is
14636 : TYPE_CANONICAL (volatile int[2]). build_type_attribute_qual_variant
14637 : creates a distinct type copy (so TYPE_MAIN_VARIANT is itself) and sets
14638 : its TYPE_CANONICAL to the unqualified ARRAY_TYPE (so volatile int[2]).
14639 : But this is not the TYPE_MAIN_VARIANT, which is int[2]. So, just
14640 : verify that TYPE_MAIN_VARIANT (ct) is already the final type we
14641 : need. */
14642 2 : tree mvc = TYPE_MAIN_VARIANT (ct);
14643 2 : if (TYPE_CANONICAL (mvc) != mvc)
14644 : {
14645 0 : error ("main variant of %<TYPE_CANONICAL%> of main variant is not"
14646 : " its own %<TYPE_CANONICAL%>");
14647 0 : debug_tree (ct);
14648 0 : debug_tree (TYPE_MAIN_VARIANT (ct));
14649 0 : error_found = true;
14650 : }
14651 : }
14652 :
14653 :
14654 : /* Check various uses of TYPE_MIN_VALUE_RAW. */
14655 921460958 : if (RECORD_OR_UNION_TYPE_P (t))
14656 : {
14657 : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
14658 : and danagle the pointer from time to time. */
14659 484552541 : if (TYPE_VFIELD (t)
14660 12367791 : && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
14661 484552541 : && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
14662 : {
14663 0 : error ("%<TYPE_VFIELD%> is not %<FIELD_DECL%> nor %<TREE_LIST%>");
14664 0 : debug_tree (TYPE_VFIELD (t));
14665 0 : error_found = true;
14666 : }
14667 : }
14668 436908417 : else if (TREE_CODE (t) == POINTER_TYPE)
14669 : {
14670 112265126 : if (TYPE_NEXT_PTR_TO (t)
14671 112265126 : && TREE_CODE (TYPE_NEXT_PTR_TO (t)) != POINTER_TYPE)
14672 : {
14673 0 : error ("%<TYPE_NEXT_PTR_TO%> is not %<POINTER_TYPE%>");
14674 0 : debug_tree (TYPE_NEXT_PTR_TO (t));
14675 0 : error_found = true;
14676 : }
14677 : }
14678 324643291 : else if (TREE_CODE (t) == REFERENCE_TYPE)
14679 : {
14680 51208454 : if (TYPE_NEXT_REF_TO (t)
14681 51208454 : && TREE_CODE (TYPE_NEXT_REF_TO (t)) != REFERENCE_TYPE)
14682 : {
14683 0 : error ("%<TYPE_NEXT_REF_TO%> is not %<REFERENCE_TYPE%>");
14684 0 : debug_tree (TYPE_NEXT_REF_TO (t));
14685 0 : error_found = true;
14686 : }
14687 : }
14688 : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14689 : || FIXED_POINT_TYPE_P (t))
14690 : {
14691 : /* FIXME: The following check should pass:
14692 : useless_type_conversion_p (const_cast <tree> (t),
14693 : TREE_TYPE (TYPE_MIN_VALUE (t))
14694 : but does not for C sizetypes in LTO. */
14695 : }
14696 :
14697 : /* Check various uses of TYPE_MAXVAL_RAW. */
14698 921460958 : if (RECORD_OR_UNION_TYPE_P (t))
14699 : {
14700 484552541 : if (!TYPE_BINFO (t))
14701 : ;
14702 455740024 : else if (TREE_CODE (TYPE_BINFO (t)) != TREE_BINFO)
14703 : {
14704 0 : error ("%<TYPE_BINFO%> is not %<TREE_BINFO%>");
14705 0 : debug_tree (TYPE_BINFO (t));
14706 0 : error_found = true;
14707 : }
14708 455740024 : else if (TREE_TYPE (TYPE_BINFO (t)) != TYPE_MAIN_VARIANT (t))
14709 : {
14710 0 : error ("%<TYPE_BINFO%> type is not %<TYPE_MAIN_VARIANT%>");
14711 0 : debug_tree (TREE_TYPE (TYPE_BINFO (t)));
14712 0 : error_found = true;
14713 : }
14714 : }
14715 : else if (FUNC_OR_METHOD_TYPE_P (t))
14716 : {
14717 858004 : if (TYPE_METHOD_BASETYPE (t)
14718 69666 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != RECORD_TYPE
14719 858202 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != UNION_TYPE)
14720 : {
14721 0 : error ("%<TYPE_METHOD_BASETYPE%> is not record nor union");
14722 0 : debug_tree (TYPE_METHOD_BASETYPE (t));
14723 0 : error_found = true;
14724 : }
14725 : }
14726 : else if (TREE_CODE (t) == OFFSET_TYPE)
14727 : {
14728 35380 : if (TYPE_OFFSET_BASETYPE (t)
14729 35380 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != RECORD_TYPE
14730 35388 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != UNION_TYPE)
14731 : {
14732 0 : error ("%<TYPE_OFFSET_BASETYPE%> is not record nor union");
14733 0 : debug_tree (TYPE_OFFSET_BASETYPE (t));
14734 0 : error_found = true;
14735 : }
14736 : }
14737 : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14738 : || FIXED_POINT_TYPE_P (t))
14739 : {
14740 : /* FIXME: The following check should pass:
14741 : useless_type_conversion_p (const_cast <tree> (t),
14742 : TREE_TYPE (TYPE_MAX_VALUE (t))
14743 : but does not for C sizetypes in LTO. */
14744 : }
14745 : else if (TREE_CODE (t) == ARRAY_TYPE)
14746 : {
14747 1785239 : if (TYPE_ARRAY_MAX_SIZE (t)
14748 1785239 : && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t)) != INTEGER_CST)
14749 : {
14750 0 : error ("%<TYPE_ARRAY_MAX_SIZE%> not %<INTEGER_CST%>");
14751 0 : debug_tree (TYPE_ARRAY_MAX_SIZE (t));
14752 0 : error_found = true;
14753 : }
14754 : }
14755 293417481 : else if (TYPE_MAX_VALUE_RAW (t))
14756 : {
14757 0 : error ("%<TYPE_MAX_VALUE_RAW%> non-NULL");
14758 0 : debug_tree (TYPE_MAX_VALUE_RAW (t));
14759 0 : error_found = true;
14760 : }
14761 :
14762 921460958 : if (TYPE_LANG_SLOT_1 (t) && in_lto_p)
14763 : {
14764 0 : error ("%<TYPE_LANG_SLOT_1 (binfo)%> field is non-NULL");
14765 0 : debug_tree (TYPE_LANG_SLOT_1 (t));
14766 0 : error_found = true;
14767 : }
14768 :
14769 : /* Check various uses of TYPE_VALUES_RAW. */
14770 921460958 : if (TREE_CODE (t) == ENUMERAL_TYPE)
14771 103486288 : for (tree l = TYPE_VALUES (t); l; l = TREE_CHAIN (l))
14772 : {
14773 89935882 : tree value = TREE_VALUE (l);
14774 89935882 : tree name = TREE_PURPOSE (l);
14775 :
14776 : /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
14777 : CONST_DECL of ENUMERAL TYPE. */
14778 89935882 : if (TREE_CODE (value) != INTEGER_CST && TREE_CODE (value) != CONST_DECL)
14779 : {
14780 0 : error ("enum value is not %<CONST_DECL%> or %<INTEGER_CST%>");
14781 0 : debug_tree (value);
14782 0 : debug_tree (name);
14783 0 : error_found = true;
14784 : }
14785 89935882 : if (TREE_CODE (TREE_TYPE (value)) != INTEGER_TYPE
14786 89918202 : && TREE_CODE (TREE_TYPE (value)) != BOOLEAN_TYPE
14787 179854081 : && !useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (value)))
14788 : {
14789 0 : error ("enum value type is not %<INTEGER_TYPE%> nor convertible "
14790 : "to the enum");
14791 0 : debug_tree (value);
14792 0 : debug_tree (name);
14793 0 : error_found = true;
14794 : }
14795 89935882 : if (TREE_CODE (name) != IDENTIFIER_NODE)
14796 : {
14797 0 : error ("enum value name is not %<IDENTIFIER_NODE%>");
14798 0 : debug_tree (value);
14799 0 : debug_tree (name);
14800 0 : error_found = true;
14801 : }
14802 : }
14803 907910552 : else if (TREE_CODE (t) == ARRAY_TYPE)
14804 : {
14805 1785239 : if (TYPE_DOMAIN (t) && TREE_CODE (TYPE_DOMAIN (t)) != INTEGER_TYPE)
14806 : {
14807 0 : error ("array %<TYPE_DOMAIN%> is not integer type");
14808 0 : debug_tree (TYPE_DOMAIN (t));
14809 0 : error_found = true;
14810 : }
14811 : }
14812 906125313 : else if (RECORD_OR_UNION_TYPE_P (t))
14813 : {
14814 484552541 : if (TYPE_FIELDS (t) && !COMPLETE_TYPE_P (t) && in_lto_p)
14815 : {
14816 0 : error ("%<TYPE_FIELDS%> defined in incomplete type");
14817 0 : error_found = true;
14818 : }
14819 20960599523 : for (tree fld = TYPE_FIELDS (t); fld; fld = TREE_CHAIN (fld))
14820 : {
14821 : /* TODO: verify properties of decls. */
14822 20476046982 : if (TREE_CODE (fld) == FIELD_DECL)
14823 : ;
14824 : else if (TREE_CODE (fld) == TYPE_DECL)
14825 : ;
14826 : else if (TREE_CODE (fld) == CONST_DECL)
14827 : ;
14828 : else if (VAR_P (fld))
14829 : ;
14830 : else if (TREE_CODE (fld) == TEMPLATE_DECL)
14831 : ;
14832 : else if (TREE_CODE (fld) == USING_DECL)
14833 : ;
14834 : else if (TREE_CODE (fld) == FUNCTION_DECL)
14835 : ;
14836 : else
14837 : {
14838 0 : error ("wrong tree in %<TYPE_FIELDS%> list");
14839 0 : debug_tree (fld);
14840 0 : error_found = true;
14841 : }
14842 : }
14843 : }
14844 421572772 : else if (TREE_CODE (t) == INTEGER_TYPE
14845 : || TREE_CODE (t) == BOOLEAN_TYPE
14846 421572772 : || TREE_CODE (t) == BITINT_TYPE
14847 299665629 : || TREE_CODE (t) == OFFSET_TYPE
14848 299630249 : || TREE_CODE (t) == REFERENCE_TYPE
14849 248421795 : || TREE_CODE (t) == NULLPTR_TYPE
14850 248074585 : || TREE_CODE (t) == POINTER_TYPE)
14851 : {
14852 285763313 : if (TYPE_CACHED_VALUES_P (t) != (TYPE_CACHED_VALUES (t) != NULL))
14853 : {
14854 0 : error ("%<TYPE_CACHED_VALUES_P%> is %i while %<TYPE_CACHED_VALUES%> "
14855 : "is %p",
14856 0 : TYPE_CACHED_VALUES_P (t), (void *)TYPE_CACHED_VALUES (t));
14857 0 : error_found = true;
14858 : }
14859 285763313 : else if (TYPE_CACHED_VALUES_P (t) && TREE_CODE (TYPE_CACHED_VALUES (t)) != TREE_VEC)
14860 : {
14861 0 : error ("%<TYPE_CACHED_VALUES%> is not %<TREE_VEC%>");
14862 0 : debug_tree (TYPE_CACHED_VALUES (t));
14863 0 : error_found = true;
14864 : }
14865 : /* Verify just enough of cache to ensure that no one copied it to new type.
14866 : All copying should go by copy_node that should clear it. */
14867 285763313 : else if (TYPE_CACHED_VALUES_P (t))
14868 : {
14869 : int i;
14870 8523749567 : for (i = 0; i < TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t)); i++)
14871 8457139247 : if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)
14872 8457139247 : && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)) != t)
14873 : {
14874 0 : error ("wrong %<TYPE_CACHED_VALUES%> entry");
14875 0 : debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i));
14876 0 : error_found = true;
14877 0 : break;
14878 : }
14879 : }
14880 : }
14881 135809459 : else if (FUNC_OR_METHOD_TYPE_P (t))
14882 3243522 : for (tree l = TYPE_ARG_TYPES (t); l; l = TREE_CHAIN (l))
14883 : {
14884 : /* C++ FE uses TREE_PURPOSE to store initial values. */
14885 2385518 : if (TREE_PURPOSE (l) && in_lto_p)
14886 : {
14887 0 : error ("%<TREE_PURPOSE%> is non-NULL in %<TYPE_ARG_TYPES%> list");
14888 0 : debug_tree (l);
14889 0 : error_found = true;
14890 : }
14891 2385518 : if (!TYPE_P (TREE_VALUE (l)))
14892 : {
14893 0 : error ("wrong entry in %<TYPE_ARG_TYPES%> list");
14894 0 : debug_tree (l);
14895 0 : error_found = true;
14896 : }
14897 : }
14898 269527860 : else if (!is_lang_specific (t) && TYPE_VALUES_RAW (t))
14899 : {
14900 0 : error ("%<TYPE_VALUES_RAW%> field is non-NULL");
14901 0 : debug_tree (TYPE_VALUES_RAW (t));
14902 0 : error_found = true;
14903 : }
14904 921460958 : if (TREE_CODE (t) != INTEGER_TYPE
14905 : && TREE_CODE (t) != BOOLEAN_TYPE
14906 921460958 : && TREE_CODE (t) != BITINT_TYPE
14907 : && TREE_CODE (t) != OFFSET_TYPE
14908 : && TREE_CODE (t) != REFERENCE_TYPE
14909 : && TREE_CODE (t) != NULLPTR_TYPE
14910 : && TREE_CODE (t) != POINTER_TYPE
14911 635697645 : && TYPE_CACHED_VALUES_P (t))
14912 : {
14913 0 : error ("%<TYPE_CACHED_VALUES_P%> is set while it should not be");
14914 0 : error_found = true;
14915 : }
14916 :
14917 : /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
14918 : TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
14919 : of a type. */
14920 921460958 : if (TREE_CODE (t) == METHOD_TYPE
14921 921460958 : && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t)) != TYPE_METHOD_BASETYPE (t))
14922 : {
14923 0 : error ("%<TYPE_METHOD_BASETYPE%> is not main variant");
14924 0 : error_found = true;
14925 : }
14926 :
14927 921460958 : if (error_found)
14928 : {
14929 0 : debug_tree (const_cast <tree> (t));
14930 0 : internal_error ("%qs failed", __func__);
14931 : }
14932 : }
14933 :
14934 :
14935 : /* Return 1 if ARG interpreted as signed in its precision is known to be
14936 : always non-negative or 2 if ARG is known to be always negative, or 3 if
14937 : ARG may be non-negative or negative. STMT if specified is the statement
14938 : on which it is being tested. */
14939 :
14940 : int
14941 872089 : get_range_pos_neg (tree arg, gimple *stmt)
14942 : {
14943 872089 : if (arg == error_mark_node || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
14944 : return 3;
14945 :
14946 872089 : int prec = TYPE_PRECISION (TREE_TYPE (arg));
14947 872089 : int cnt = 0;
14948 872089 : if (TREE_CODE (arg) == INTEGER_CST)
14949 : {
14950 69970 : wide_int w = wi::sext (wi::to_wide (arg), prec);
14951 69970 : if (wi::neg_p (w))
14952 : return 2;
14953 : else
14954 55509 : return 1;
14955 69970 : }
14956 800854 : while (CONVERT_EXPR_P (arg)
14957 14745 : && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
14958 830344 : && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg, 0))) <= prec)
14959 : {
14960 14101 : arg = TREE_OPERAND (arg, 0);
14961 : /* Narrower value zero extended into wider type
14962 : will always result in positive values. */
14963 14101 : if (TYPE_UNSIGNED (TREE_TYPE (arg))
14964 14101 : && TYPE_PRECISION (TREE_TYPE (arg)) < prec)
14965 : return 1;
14966 13480 : prec = TYPE_PRECISION (TREE_TYPE (arg));
14967 13480 : if (++cnt > 30)
14968 : return 3;
14969 : }
14970 :
14971 801498 : if (TREE_CODE (arg) != SSA_NAME)
14972 : return 3;
14973 795281 : int_range_max r;
14974 1607919 : while (!get_range_query (cfun)->range_of_expr (r, arg, stmt)
14975 1625276 : || r.undefined_p () || r.varying_p ())
14976 : {
14977 535470 : gimple *g = SSA_NAME_DEF_STMT (arg);
14978 535470 : if (is_gimple_assign (g)
14979 535470 : && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (g)))
14980 : {
14981 29377 : tree t = gimple_assign_rhs1 (g);
14982 58427 : if (INTEGRAL_TYPE_P (TREE_TYPE (t))
14983 55741 : && TYPE_PRECISION (TREE_TYPE (t)) <= prec)
14984 : {
14985 19754 : if (TYPE_UNSIGNED (TREE_TYPE (t))
14986 19754 : && TYPE_PRECISION (TREE_TYPE (t)) < prec)
14987 : return 1;
14988 17357 : prec = TYPE_PRECISION (TREE_TYPE (t));
14989 17357 : arg = t;
14990 17357 : if (++cnt > 30)
14991 : return 3;
14992 17357 : continue;
14993 : }
14994 : }
14995 : return 3;
14996 : }
14997 277168 : if (TYPE_UNSIGNED (TREE_TYPE (arg)))
14998 : {
14999 : /* For unsigned values, the "positive" range comes
15000 : below the "negative" range. */
15001 114434 : if (!wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
15002 : return 1;
15003 32645 : if (wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
15004 837 : return 2;
15005 : }
15006 : else
15007 : {
15008 162734 : if (!wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
15009 : return 1;
15010 65464 : if (wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
15011 1191 : return 2;
15012 : }
15013 : return 3;
15014 795281 : }
15015 :
15016 :
15017 :
15018 :
15019 : /* Return true if ARG is marked with the nonnull attribute in the
15020 : current function signature. */
15021 :
15022 : bool
15023 27617671 : nonnull_arg_p (const_tree arg)
15024 : {
15025 27617671 : tree t, attrs, fntype;
15026 27617671 : unsigned HOST_WIDE_INT arg_num;
15027 :
15028 27617671 : gcc_assert (TREE_CODE (arg) == PARM_DECL
15029 : && (POINTER_TYPE_P (TREE_TYPE (arg))
15030 : || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE));
15031 :
15032 : /* The static chain decl is always non null. */
15033 27617671 : if (arg == cfun->static_chain_decl)
15034 : return true;
15035 :
15036 : /* THIS argument of method is always non-NULL. */
15037 27348621 : if (TREE_CODE (TREE_TYPE (cfun->decl)) == METHOD_TYPE
15038 10622287 : && arg == DECL_ARGUMENTS (cfun->decl)
15039 33997413 : && flag_delete_null_pointer_checks)
15040 : return true;
15041 :
15042 : /* Values passed by reference are always non-NULL. */
15043 20701939 : if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
15044 20701939 : && flag_delete_null_pointer_checks)
15045 : return true;
15046 :
15047 14140398 : fntype = TREE_TYPE (cfun->decl);
15048 14164388 : for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
15049 : {
15050 568263 : attrs = lookup_attribute ("nonnull", attrs);
15051 :
15052 : /* If "nonnull" wasn't specified, we know nothing about the argument. */
15053 568263 : if (attrs == NULL_TREE)
15054 : return false;
15055 :
15056 : /* If "nonnull" applies to all the arguments, then ARG is non-null. */
15057 116376 : if (TREE_VALUE (attrs) == NULL_TREE)
15058 : return true;
15059 :
15060 : /* Get the position number for ARG in the function signature. */
15061 57645 : for (arg_num = 1, t = DECL_ARGUMENTS (cfun->decl);
15062 132171 : t;
15063 74526 : t = DECL_CHAIN (t), arg_num++)
15064 : {
15065 132171 : if (t == arg)
15066 : break;
15067 : }
15068 :
15069 57645 : gcc_assert (t == arg);
15070 :
15071 : /* Now see if ARG_NUM is mentioned in the nonnull list. */
15072 91360 : for (t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
15073 : {
15074 67370 : if (compare_tree_int (TREE_VALUE (t), arg_num) == 0)
15075 : return true;
15076 : }
15077 : }
15078 :
15079 : return false;
15080 : }
15081 :
15082 : /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
15083 : information. */
15084 :
15085 : location_t
15086 957236193 : set_block (location_t loc, tree block)
15087 : {
15088 957236193 : location_t pure_loc = get_pure_location (loc);
15089 957236193 : source_range src_range = get_range_from_loc (line_table, loc);
15090 957236193 : unsigned discriminator = get_discriminator_from_loc (line_table, loc);
15091 957236193 : return line_table->get_or_create_combined_loc (pure_loc, src_range, block,
15092 957236193 : discriminator);
15093 : }
15094 :
15095 : location_t
15096 227919290 : set_source_range (tree expr, location_t start, location_t finish)
15097 : {
15098 227919290 : source_range src_range;
15099 227919290 : src_range.m_start = start;
15100 227919290 : src_range.m_finish = finish;
15101 227919290 : return set_source_range (expr, src_range);
15102 : }
15103 :
15104 : location_t
15105 464006226 : set_source_range (tree expr, source_range src_range)
15106 : {
15107 464006226 : if (!EXPR_P (expr))
15108 : return UNKNOWN_LOCATION;
15109 :
15110 204980855 : location_t expr_location = EXPR_LOCATION (expr);
15111 204980855 : location_t pure_loc = get_pure_location (expr_location);
15112 204980855 : unsigned discriminator = get_discriminator_from_loc (expr_location);
15113 204980855 : location_t adhoc = line_table->get_or_create_combined_loc (pure_loc,
15114 : src_range,
15115 : nullptr,
15116 : discriminator);
15117 204980855 : SET_EXPR_LOCATION (expr, adhoc);
15118 204980855 : return adhoc;
15119 : }
15120 :
15121 : /* Return EXPR, potentially wrapped with a node expression LOC,
15122 : if !CAN_HAVE_LOCATION_P (expr).
15123 :
15124 : NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
15125 : VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
15126 :
15127 : Wrapper nodes can be identified using location_wrapper_p. */
15128 :
15129 : tree
15130 1611649189 : maybe_wrap_with_location (tree expr, location_t loc)
15131 : {
15132 1611649189 : if (expr == NULL)
15133 : return NULL;
15134 1611649185 : if (loc == UNKNOWN_LOCATION)
15135 : return expr;
15136 1556978765 : if (CAN_HAVE_LOCATION_P (expr))
15137 : return expr;
15138 : /* We should only be adding wrappers for constants and for decls,
15139 : or for some exceptional tree nodes (e.g. BASELINK in the C++ FE). */
15140 952237933 : gcc_assert (CONSTANT_CLASS_P (expr)
15141 : || DECL_P (expr)
15142 : || EXCEPTIONAL_CLASS_P (expr));
15143 :
15144 : /* For now, don't add wrappers to exceptional tree nodes, to minimize
15145 : any impact of the wrapper nodes. */
15146 952237933 : if (EXCEPTIONAL_CLASS_P (expr) || error_operand_p (expr))
15147 : return expr;
15148 :
15149 : /* Compiler-generated temporary variables don't need a wrapper. */
15150 877782879 : if (DECL_P (expr) && DECL_ARTIFICIAL (expr) && DECL_IGNORED_P (expr))
15151 : return expr;
15152 :
15153 : /* If any auto_suppress_location_wrappers are active, don't create
15154 : wrappers. */
15155 877780363 : if (suppress_location_wrappers > 0)
15156 : return expr;
15157 :
15158 1641184790 : tree_code code
15159 215348576 : = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
15160 614142150 : || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
15161 820592395 : ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
15162 820592395 : tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
15163 : /* Mark this node as being a wrapper. */
15164 820592395 : EXPR_LOCATION_WRAPPER_P (wrapper) = 1;
15165 820592395 : return wrapper;
15166 : }
15167 :
15168 : int suppress_location_wrappers;
15169 :
15170 : /* Return the name of combined function FN, for debugging purposes. */
15171 :
15172 : const char *
15173 0 : combined_fn_name (combined_fn fn)
15174 : {
15175 0 : if (builtin_fn_p (fn))
15176 : {
15177 0 : tree fndecl = builtin_decl_explicit (as_builtin_fn (fn));
15178 0 : return IDENTIFIER_POINTER (DECL_NAME (fndecl));
15179 : }
15180 : else
15181 0 : return internal_fn_name (as_internal_fn (fn));
15182 : }
15183 :
15184 : /* Return a bitmap with a bit set corresponding to each argument in
15185 : a function call type FNTYPE declared with attribute nonnull,
15186 : or null if none of the function's argument are nonnull. The caller
15187 : must free the bitmap. */
15188 :
15189 : bitmap
15190 22046714 : get_nonnull_args (const_tree fntype)
15191 : {
15192 22046714 : if (fntype == NULL_TREE)
15193 : return NULL;
15194 :
15195 21384056 : bitmap argmap = NULL;
15196 21384056 : if (TREE_CODE (fntype) == METHOD_TYPE)
15197 : {
15198 : /* The this pointer in C++ non-static member functions is
15199 : implicitly nonnull whether or not it's declared as such. */
15200 2870704 : argmap = BITMAP_ALLOC (NULL);
15201 2870704 : bitmap_set_bit (argmap, 0);
15202 : }
15203 :
15204 21384056 : tree attrs = TYPE_ATTRIBUTES (fntype);
15205 21384056 : if (!attrs)
15206 : return argmap;
15207 :
15208 : /* A function declaration can specify multiple attribute nonnull,
15209 : each with zero or more arguments. The loop below creates a bitmap
15210 : representing a union of all the arguments. An empty (but non-null)
15211 : bitmap means that all arguments have been declared nonnull. */
15212 6015728 : for ( ; attrs; attrs = TREE_CHAIN (attrs))
15213 : {
15214 5905296 : attrs = lookup_attribute ("nonnull", attrs);
15215 5905296 : if (!attrs)
15216 : break;
15217 :
15218 1428342 : if (!argmap)
15219 1390064 : argmap = BITMAP_ALLOC (NULL);
15220 :
15221 1428342 : if (!TREE_VALUE (attrs))
15222 : {
15223 : /* Clear the bitmap in case a previous attribute nonnull
15224 : set it and this one overrides it for all arguments. */
15225 782737 : bitmap_clear (argmap);
15226 782737 : return argmap;
15227 : }
15228 :
15229 : /* Iterate over the indices of the format arguments declared nonnull
15230 : and set a bit for each. */
15231 1692862 : for (tree idx = TREE_VALUE (attrs); idx; idx = TREE_CHAIN (idx))
15232 : {
15233 1047257 : unsigned int val = TREE_INT_CST_LOW (TREE_VALUE (idx)) - 1;
15234 1047257 : bitmap_set_bit (argmap, val);
15235 : }
15236 : }
15237 :
15238 : return argmap;
15239 : }
15240 :
15241 : /* Returns true if TYPE is a type where it and all of its subobjects
15242 : (recursively) are of structure, union, or array type. */
15243 :
15244 : bool
15245 2022700112 : is_empty_type (const_tree type)
15246 : {
15247 2022700112 : if (RECORD_OR_UNION_TYPE_P (type))
15248 : {
15249 892169934 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
15250 819173798 : if (TREE_CODE (field) == FIELD_DECL
15251 405522849 : && !DECL_PADDING_P (field)
15252 1224695297 : && !is_empty_type (TREE_TYPE (field)))
15253 : return false;
15254 : return true;
15255 : }
15256 1572630676 : else if (TREE_CODE (type) == ARRAY_TYPE)
15257 88952481 : return (integer_minus_onep (array_type_nelts_minus_one (type))
15258 88908485 : || TYPE_DOMAIN (type) == NULL_TREE
15259 167656669 : || is_empty_type (TREE_TYPE (type)));
15260 : return false;
15261 : }
15262 :
15263 : /* Implement TARGET_EMPTY_RECORD_P. Return true if TYPE is an empty type
15264 : that shouldn't be passed via stack. */
15265 :
15266 : bool
15267 1486197993 : default_is_empty_record (const_tree type)
15268 : {
15269 1486197993 : if (!abi_version_at_least (12))
15270 : return false;
15271 :
15272 1485137576 : if (type == error_mark_node)
15273 : return false;
15274 :
15275 1485137576 : if (TREE_ADDRESSABLE (type))
15276 : return false;
15277 :
15278 1485137576 : return is_empty_type (TYPE_MAIN_VARIANT (type));
15279 : }
15280 :
15281 :
15282 : /* Determine whether TYPE is an ISO C99 flexible array member type "[]". */
15283 :
15284 : bool
15285 11824949 : flexible_array_member_type_p (const_tree type)
15286 : {
15287 11824949 : if (TREE_CODE (type) == ARRAY_TYPE
15288 4940892 : && TYPE_SIZE (type) == NULL_TREE
15289 649219 : && TYPE_DOMAIN (type) != NULL_TREE
15290 12384082 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
15291 559133 : return true;
15292 :
15293 : return false;
15294 : }
15295 :
15296 :
15297 : /* Determine whether TYPE is a structure with a flexible array member,
15298 : or a union containing such a structure (possibly recursively). */
15299 :
15300 : bool
15301 72528 : flexible_array_type_p (const_tree type)
15302 : {
15303 72528 : tree x, last;
15304 72528 : switch (TREE_CODE (type))
15305 : {
15306 38228 : case RECORD_TYPE:
15307 38228 : last = NULL_TREE;
15308 174602 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15309 136374 : if (TREE_CODE (x) == FIELD_DECL)
15310 136374 : last = x;
15311 38228 : if (last == NULL_TREE)
15312 : return false;
15313 38220 : return flexible_array_member_type_p (TREE_TYPE (last));
15314 579 : case UNION_TYPE:
15315 1668 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15316 : {
15317 1131 : if (TREE_CODE (x) == FIELD_DECL
15318 1131 : && flexible_array_type_p (TREE_TYPE (x)))
15319 : return true;
15320 : }
15321 : return false;
15322 : default:
15323 : return false;
15324 : }
15325 : }
15326 :
15327 : /* Like int_size_in_bytes, but handle empty records specially. */
15328 :
15329 : HOST_WIDE_INT
15330 464003 : arg_int_size_in_bytes (const_tree type)
15331 : {
15332 464003 : return TYPE_EMPTY_P (type) ? 0 : int_size_in_bytes (type);
15333 : }
15334 :
15335 : /* Like size_in_bytes, but handle empty records specially. */
15336 :
15337 : tree
15338 5728915 : arg_size_in_bytes (const_tree type)
15339 : {
15340 5728915 : return TYPE_EMPTY_P (type) ? size_zero_node : size_in_bytes (type);
15341 : }
15342 :
15343 : /* Return true if an expression with CODE has to have the same result type as
15344 : its first operand. */
15345 :
15346 : bool
15347 0 : expr_type_first_operand_type_p (tree_code code)
15348 : {
15349 0 : switch (code)
15350 : {
15351 : case NEGATE_EXPR:
15352 : case ABS_EXPR:
15353 : case BIT_NOT_EXPR:
15354 : case PAREN_EXPR:
15355 : case CONJ_EXPR:
15356 :
15357 : case PLUS_EXPR:
15358 : case MINUS_EXPR:
15359 : case MULT_EXPR:
15360 : case TRUNC_DIV_EXPR:
15361 : case CEIL_DIV_EXPR:
15362 : case FLOOR_DIV_EXPR:
15363 : case ROUND_DIV_EXPR:
15364 : case TRUNC_MOD_EXPR:
15365 : case CEIL_MOD_EXPR:
15366 : case FLOOR_MOD_EXPR:
15367 : case ROUND_MOD_EXPR:
15368 : case RDIV_EXPR:
15369 : case EXACT_DIV_EXPR:
15370 : case MIN_EXPR:
15371 : case MAX_EXPR:
15372 : case BIT_IOR_EXPR:
15373 : case BIT_XOR_EXPR:
15374 : case BIT_AND_EXPR:
15375 :
15376 : case LSHIFT_EXPR:
15377 : case RSHIFT_EXPR:
15378 : case LROTATE_EXPR:
15379 : case RROTATE_EXPR:
15380 : return true;
15381 :
15382 0 : default:
15383 0 : return false;
15384 : }
15385 : }
15386 :
15387 : /* Return a typenode for the "standard" C type with a given name. */
15388 : tree
15389 932601 : get_typenode_from_name (const char *name)
15390 : {
15391 932601 : if (name == NULL || *name == '\0')
15392 : return NULL_TREE;
15393 :
15394 932601 : if (strcmp (name, "char") == 0)
15395 0 : return char_type_node;
15396 932601 : if (strcmp (name, "unsigned char") == 0)
15397 96288 : return unsigned_char_type_node;
15398 836313 : if (strcmp (name, "signed char") == 0)
15399 96288 : return signed_char_type_node;
15400 :
15401 740025 : if (strcmp (name, "short int") == 0)
15402 65709 : return short_integer_type_node;
15403 674316 : if (strcmp (name, "short unsigned int") == 0)
15404 64192 : return short_unsigned_type_node;
15405 :
15406 610124 : if (strcmp (name, "int") == 0)
15407 66537 : return integer_type_node;
15408 543587 : if (strcmp (name, "unsigned int") == 0)
15409 65010 : return unsigned_type_node;
15410 :
15411 478577 : if (strcmp (name, "long int") == 0)
15412 285183 : return long_integer_type_node;
15413 193394 : if (strcmp (name, "long unsigned int") == 0)
15414 190122 : return long_unsigned_type_node;
15415 :
15416 3272 : if (strcmp (name, "long long int") == 0)
15417 1636 : return long_long_integer_type_node;
15418 1636 : if (strcmp (name, "long long unsigned int") == 0)
15419 1636 : return long_long_unsigned_type_node;
15420 :
15421 0 : gcc_unreachable ();
15422 : }
15423 :
15424 : /* List of pointer types used to declare builtins before we have seen their
15425 : real declaration.
15426 :
15427 : Keep the size up to date in tree.h ! */
15428 : const builtin_structptr_type builtin_structptr_types[6] =
15429 : {
15430 : { fileptr_type_node, ptr_type_node, "FILE" },
15431 : { const_tm_ptr_type_node, const_ptr_type_node, "tm" },
15432 : { fenv_t_ptr_type_node, ptr_type_node, "fenv_t" },
15433 : { const_fenv_t_ptr_type_node, const_ptr_type_node, "fenv_t" },
15434 : { fexcept_t_ptr_type_node, ptr_type_node, "fexcept_t" },
15435 : { const_fexcept_t_ptr_type_node, const_ptr_type_node, "fexcept_t" }
15436 : };
15437 :
15438 : /* Return the maximum object size. */
15439 :
15440 : tree
15441 7609186 : max_object_size (void)
15442 : {
15443 : /* To do: Make this a configurable parameter. */
15444 7609186 : return TYPE_MAX_VALUE (ptrdiff_type_node);
15445 : }
15446 :
15447 : /* A wrapper around TARGET_VERIFY_TYPE_CONTEXT that makes the silent_p
15448 : parameter default to false and that weeds out error_mark_node. */
15449 :
15450 : bool
15451 156655815 : verify_type_context (location_t loc, type_context_kind context,
15452 : const_tree type, bool silent_p)
15453 : {
15454 156655815 : if (type == error_mark_node)
15455 : return true;
15456 :
15457 156655719 : gcc_assert (TYPE_P (type));
15458 156655719 : return (!targetm.verify_type_context
15459 156655719 : || targetm.verify_type_context (loc, context, type, silent_p));
15460 : }
15461 :
15462 : /* Callback of walk_tree telling whether the current tree pointed by TP is the
15463 : one provided as DATA. */
15464 :
15465 : static tree
15466 4739 : find_tree_1 (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, void *data)
15467 : {
15468 4739 : if (*tp == data)
15469 : return (tree) data;
15470 : else
15471 4667 : return NULL;
15472 : }
15473 :
15474 : /* Return whether SEARCH is a subtree of TOP. */
15475 :
15476 : bool
15477 3797 : find_tree (tree top, tree search)
15478 : {
15479 3797 : return walk_tree_without_duplicates (&top, find_tree_1, search) != 0;
15480 : }
15481 :
15482 : /* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and
15483 : delete operators. Return false if they may or may not name such
15484 : a pair and, when nonnull, set *PCERTAIN to true if they certainly
15485 : do not. */
15486 :
15487 : bool
15488 67151 : valid_new_delete_pair_p (tree new_asm, tree delete_asm,
15489 : bool *pcertain /* = NULL */)
15490 : {
15491 67151 : bool certain;
15492 67151 : if (!pcertain)
15493 54629 : pcertain = &certain;
15494 :
15495 67151 : const char *new_name = IDENTIFIER_POINTER (new_asm);
15496 67151 : const char *delete_name = IDENTIFIER_POINTER (delete_asm);
15497 67151 : unsigned int new_len = IDENTIFIER_LENGTH (new_asm);
15498 67151 : unsigned int delete_len = IDENTIFIER_LENGTH (delete_asm);
15499 :
15500 : /* The following failures are due to invalid names so they're not
15501 : considered certain mismatches. */
15502 67151 : *pcertain = false;
15503 :
15504 67151 : if (new_len < 5 || delete_len < 6)
15505 : return false;
15506 67151 : if (new_name[0] == '_')
15507 67079 : ++new_name, --new_len;
15508 67151 : if (new_name[0] == '_')
15509 0 : ++new_name, --new_len;
15510 67151 : if (delete_name[0] == '_')
15511 67151 : ++delete_name, --delete_len;
15512 67151 : if (delete_name[0] == '_')
15513 0 : ++delete_name, --delete_len;
15514 67151 : if (new_len < 4 || delete_len < 5)
15515 : return false;
15516 :
15517 : /* The following failures are due to names of user-defined operators
15518 : so they're also not considered certain mismatches. */
15519 :
15520 : /* *_len is now just the length after initial underscores. */
15521 67151 : if (new_name[0] != 'Z' || new_name[1] != 'n')
15522 : return false;
15523 66478 : if (delete_name[0] != 'Z' || delete_name[1] != 'd')
15524 : return false;
15525 :
15526 : /* The following failures are certain mismatches. */
15527 66402 : *pcertain = true;
15528 :
15529 : /* _Znw must match _Zdl, _Zna must match _Zda. */
15530 66402 : if ((new_name[2] != 'w' || delete_name[2] != 'l')
15531 5060 : && (new_name[2] != 'a' || delete_name[2] != 'a'))
15532 : return false;
15533 66306 : if (new_name[3] == 'I' || delete_name[3] == 'I')
15534 : {
15535 : /* When ::operator new or ::operator delete are function templates,
15536 : return uncertain mismatch, we need demangler in that case. */
15537 6 : *pcertain = false;
15538 6 : return false;
15539 : }
15540 : /* 'j', 'm' and 'y' correspond to size_t. */
15541 66300 : if (new_name[3] != 'j' && new_name[3] != 'm' && new_name[3] != 'y')
15542 : return false;
15543 66300 : if (delete_name[3] != 'P' || delete_name[4] != 'v')
15544 : return false;
15545 66300 : if (new_len == 4
15546 370 : || (new_len == 18 && !memcmp (new_name + 4, "RKSt9nothrow_t", 14)))
15547 : {
15548 : /* _ZnXY or _ZnXYRKSt9nothrow_t matches
15549 : _ZdXPv, _ZdXPvY and _ZdXPvRKSt9nothrow_t. */
15550 66098 : if (delete_len == 5)
15551 : return true;
15552 59491 : if (delete_len == 6 && delete_name[5] == new_name[3])
15553 : return true;
15554 39 : if (delete_len == 19 && !memcmp (delete_name + 5, "RKSt9nothrow_t", 14))
15555 : return true;
15556 : }
15557 202 : else if ((new_len == 19 && !memcmp (new_name + 4, "St11align_val_t", 15))
15558 42 : || (new_len == 33
15559 10 : && !memcmp (new_name + 4, "St11align_val_tRKSt9nothrow_t", 29)))
15560 : {
15561 : /* _ZnXYSt11align_val_t or _ZnXYSt11align_val_tRKSt9nothrow_t matches
15562 : _ZdXPvSt11align_val_t or _ZdXPvYSt11align_val_t or
15563 : _ZdXPvSt11align_val_tRKSt9nothrow_t. */
15564 170 : if (delete_len == 20 && !memcmp (delete_name + 5, "St11align_val_t", 15))
15565 : return true;
15566 54 : if (delete_len == 21
15567 39 : && delete_name[5] == new_name[3]
15568 39 : && !memcmp (delete_name + 6, "St11align_val_t", 15))
15569 : return true;
15570 15 : if (delete_len == 34
15571 9 : && !memcmp (delete_name + 5, "St11align_val_tRKSt9nothrow_t", 29))
15572 : return true;
15573 : }
15574 :
15575 : /* The negative result is conservative. */
15576 38 : *pcertain = false;
15577 38 : return false;
15578 : }
15579 :
15580 : /* Return the zero-based number corresponding to the argument being
15581 : deallocated if FNDECL is a deallocation function or an out-of-bounds
15582 : value if it isn't. */
15583 :
15584 : unsigned
15585 23390245 : fndecl_dealloc_argno (tree fndecl)
15586 : {
15587 : /* A call to operator delete isn't recognized as one to a built-in. */
15588 23390245 : if (DECL_IS_OPERATOR_DELETE_P (fndecl))
15589 : {
15590 358673 : if (DECL_IS_REPLACEABLE_OPERATOR (fndecl))
15591 : return 0;
15592 :
15593 : /* Avoid placement delete that's not been inlined. */
15594 26760 : tree fname = DECL_ASSEMBLER_NAME (fndecl);
15595 26760 : if (id_equal (fname, "_ZdlPvS_") // ordinary form
15596 26760 : || id_equal (fname, "_ZdaPvS_")) // array form
15597 24132 : return UINT_MAX;
15598 : return 0;
15599 : }
15600 :
15601 : /* TODO: Handle user-defined functions with attribute malloc? Handle
15602 : known non-built-ins like fopen? */
15603 23031572 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
15604 : {
15605 5635186 : switch (DECL_FUNCTION_CODE (fndecl))
15606 : {
15607 : case BUILT_IN_FREE:
15608 : case BUILT_IN_REALLOC:
15609 : case BUILT_IN_GOMP_FREE:
15610 : case BUILT_IN_GOMP_REALLOC:
15611 : return 0;
15612 5410047 : default:
15613 5410047 : break;
15614 : }
15615 5410047 : return UINT_MAX;
15616 : }
15617 :
15618 17396386 : tree attrs = DECL_ATTRIBUTES (fndecl);
15619 17396386 : if (!attrs)
15620 : return UINT_MAX;
15621 :
15622 0 : for (tree atfree = attrs;
15623 4012185 : (atfree = lookup_attribute ("*dealloc", atfree));
15624 0 : atfree = TREE_CHAIN (atfree))
15625 : {
15626 4950 : tree alloc = TREE_VALUE (atfree);
15627 4950 : if (!alloc)
15628 0 : continue;
15629 :
15630 4950 : tree pos = TREE_CHAIN (alloc);
15631 4950 : if (!pos)
15632 : return 0;
15633 :
15634 2763 : pos = TREE_VALUE (pos);
15635 2763 : return TREE_INT_CST_LOW (pos) - 1;
15636 : }
15637 :
15638 : return UINT_MAX;
15639 : }
15640 :
15641 : /* If EXPR refers to a character array or pointer declared attribute
15642 : nonstring, return a decl for that array or pointer and set *REF
15643 : to the referenced enclosing object or pointer. Otherwise return
15644 : null. */
15645 :
15646 : tree
15647 1400369 : get_attr_nonstring_decl (tree expr, tree *ref)
15648 : {
15649 1406071 : tree decl = expr;
15650 1406071 : tree var = NULL_TREE;
15651 1406071 : if (TREE_CODE (decl) == SSA_NAME)
15652 : {
15653 836235 : gimple *def = SSA_NAME_DEF_STMT (decl);
15654 :
15655 836235 : if (is_gimple_assign (def))
15656 : {
15657 44352 : tree_code code = gimple_assign_rhs_code (def);
15658 44352 : if (code == ADDR_EXPR
15659 44352 : || code == COMPONENT_REF
15660 29456 : || code == VAR_DECL)
15661 19359 : decl = gimple_assign_rhs1 (def);
15662 : }
15663 : else
15664 791883 : var = SSA_NAME_VAR (decl);
15665 : }
15666 :
15667 1406071 : if (TREE_CODE (decl) == ADDR_EXPR)
15668 25980 : decl = TREE_OPERAND (decl, 0);
15669 :
15670 : /* To simplify calling code, store the referenced DECL regardless of
15671 : the attribute determined below, but avoid storing the SSA_NAME_VAR
15672 : obtained above (it's not useful for dataflow purposes). */
15673 1406071 : if (ref)
15674 5463 : *ref = decl;
15675 :
15676 : /* Use the SSA_NAME_VAR that was determined above to see if it's
15677 : declared nonstring. Otherwise drill down into the referenced
15678 : DECL. */
15679 1406071 : if (var)
15680 : decl = var;
15681 : else
15682 : {
15683 639213 : while (TREE_CODE (decl) == ARRAY_REF)
15684 18685 : decl = TREE_OPERAND (decl, 0);
15685 620528 : if (TREE_CODE (decl) == COMPONENT_REF)
15686 16745 : decl = TREE_OPERAND (decl, 1);
15687 603783 : else if (TREE_CODE (decl) == MEM_REF)
15688 5702 : return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref);
15689 : }
15690 :
15691 1400369 : if (DECL_P (decl) && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl)))
15692 7921 : return decl;
15693 :
15694 : return NULL_TREE;
15695 : }
15696 :
15697 : /* Returns an auto_vec of string_slices containing the version strings from
15698 : ARGLIST. DEFAULT_COUNT is incremented for each default version found.
15699 : If FILTER is true then any invalid versions strings are not included. */
15700 :
15701 : auto_vec<string_slice>
15702 208 : get_clone_attr_versions (const tree arglist,
15703 : int *default_count,
15704 : bool filter)
15705 : {
15706 208 : gcc_assert (TREE_CODE (arglist) == TREE_LIST);
15707 208 : auto_vec<string_slice> versions;
15708 :
15709 208 : static const char separator_str[] = {TARGET_CLONES_ATTR_SEPARATOR, 0};
15710 208 : string_slice separators = string_slice (separator_str);
15711 :
15712 764 : for (tree arg = arglist; arg; arg = TREE_CHAIN (arg))
15713 : {
15714 556 : string_slice str = string_slice (TREE_STRING_POINTER (TREE_VALUE (arg)));
15715 1696 : while (str.is_valid ())
15716 : {
15717 584 : string_slice attr = string_slice::tokenize (&str, separators);
15718 584 : attr = attr.strip ();
15719 :
15720 584 : if (filter && !targetm.check_target_clone_version (attr, NULL))
15721 0 : continue;
15722 :
15723 584 : if (attr == "default" && default_count)
15724 206 : (*default_count)++;
15725 584 : versions.safe_push (attr);
15726 : }
15727 : }
15728 208 : return versions;
15729 : }
15730 :
15731 : /* Returns an auto_vec of string_slices containing the version strings from
15732 : the target_clone attribute from DECL. DEFAULT_COUNT is incremented for each
15733 : default version found. If FILTER is true then any invalid versions strings
15734 : are not included. */
15735 : auto_vec<string_slice>
15736 97 : get_clone_versions (const tree decl, int *default_count, bool filter)
15737 : {
15738 97 : tree attr = lookup_attribute ("target_clones", DECL_ATTRIBUTES (decl));
15739 97 : if (!attr)
15740 0 : return auto_vec<string_slice> ();
15741 97 : tree arglist = TREE_VALUE (attr);
15742 97 : return get_clone_attr_versions (arglist, default_count, filter);
15743 : }
15744 :
15745 : /* If DECL has a target_version attribute, returns a string_slice containing the
15746 : attribute value. Otherwise, returns string_slice::invalid.
15747 : Only works for target_version due to target attributes allowing multiple
15748 : string arguments to specify one target. */
15749 : string_slice
15750 0 : get_target_version (const tree decl)
15751 : {
15752 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15753 :
15754 : tree attr = lookup_attribute ("target_version", DECL_ATTRIBUTES (decl));
15755 :
15756 : if (!attr)
15757 : return string_slice::invalid ();
15758 :
15759 : return string_slice (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))))
15760 : .strip ();
15761 : }
15762 :
15763 : /* Returns true if FN1 and FN2 define disjoint function versions in an FMV
15764 : function set. That is, the two declarations are completely non-overlapping.
15765 : For target_version semantics, that means if one is a target clone and one is
15766 : a target version, the target_version must not be defined by the target_clone,
15767 : and for two target_clones, they must not define any of the same version.
15768 :
15769 : FN1 and FN2 should be function decls. */
15770 :
15771 : bool
15772 31217091 : disjoint_version_decls (tree fn1, tree fn2)
15773 : {
15774 31217091 : if (TREE_CODE (fn1) != FUNCTION_DECL
15775 31215859 : || TREE_CODE (fn2) != FUNCTION_DECL)
15776 : return false;
15777 :
15778 28948841 : if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
15779 : {
15780 28948841 : tree attr1 = lookup_attribute ("target", DECL_ATTRIBUTES (fn1));
15781 28948841 : tree attr2 = lookup_attribute ("target", DECL_ATTRIBUTES (fn2));
15782 :
15783 : /* At least one function decl should have the target attribute
15784 : specified. */
15785 28948841 : if (attr1 == NULL_TREE && attr2 == NULL_TREE)
15786 : return false;
15787 :
15788 : /* Diagnose missing target attribute if one of the decls is already
15789 : multi-versioned. */
15790 18867 : if (attr1 == NULL_TREE || attr2 == NULL_TREE)
15791 : {
15792 363 : if (DECL_FUNCTION_VERSIONED (fn1) || DECL_FUNCTION_VERSIONED (fn2))
15793 : {
15794 114 : if (attr2 != NULL_TREE)
15795 : {
15796 114 : std::swap (fn1, fn2);
15797 114 : attr1 = attr2;
15798 : }
15799 114 : auto_diagnostic_group d;
15800 114 : error_at (DECL_SOURCE_LOCATION (fn2),
15801 : "missing %<target%> attribute for multi-versioned %qD",
15802 : fn2);
15803 114 : inform (DECL_SOURCE_LOCATION (fn1),
15804 : "previous declaration of %qD", fn1);
15805 : /* Prevent diagnosing of the same error multiple times. */
15806 114 : DECL_ATTRIBUTES (fn2)
15807 228 : = tree_cons (get_identifier ("target"),
15808 114 : copy_node (TREE_VALUE (attr1)),
15809 114 : DECL_ATTRIBUTES (fn2));
15810 114 : }
15811 : return false;
15812 : }
15813 :
15814 18504 : char *target1 = sorted_attr_string (TREE_VALUE (attr1));
15815 18504 : char *target2 = sorted_attr_string (TREE_VALUE (attr2));
15816 :
15817 : /* The sorted target strings must be different for fn1 and fn2
15818 : to be versions. */
15819 18504 : bool result = strcmp (target1, target2) != 0;
15820 :
15821 18504 : XDELETEVEC (target1);
15822 18504 : XDELETEVEC (target2);
15823 :
15824 18504 : return result;
15825 : }
15826 : else
15827 : {
15828 : /* As this is symmetric, can remove the case where fn2 is target clone
15829 : and fn1 is target version by swapping here. */
15830 : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn2)))
15831 : std::swap (fn1, fn2);
15832 :
15833 : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn1)))
15834 : {
15835 : auto_vec<string_slice> fn1_versions = get_clone_versions (fn1);
15836 : /* fn1 is target_clone. */
15837 : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn2)))
15838 : {
15839 : /* Both are target_clone. */
15840 : auto_vec<string_slice> fn2_versions = get_clone_versions (fn2);
15841 : for (string_slice v1 : fn1_versions)
15842 : {
15843 : for (string_slice v2 : fn2_versions)
15844 : if (targetm.target_option.same_function_versions
15845 : (v1, NULL_TREE, v2, NULL_TREE))
15846 : return false;
15847 : }
15848 : return true;
15849 : }
15850 : else
15851 : {
15852 : string_slice v2 = get_target_version (fn2);
15853 :
15854 : /* target and target_clones is always conflicting for target
15855 : semantics. */
15856 : if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
15857 : return false;
15858 :
15859 : /* Only fn1 is target clone. */
15860 : if (!v2.is_valid ())
15861 : v2 = "default";
15862 : for (string_slice v1 : fn1_versions)
15863 : if (targetm.target_option.same_function_versions
15864 : (v1, NULL_TREE, v2, NULL_TREE))
15865 : return false;
15866 : return true;
15867 : }
15868 : }
15869 : else
15870 : {
15871 : /* Both are target_version. */
15872 : string_slice v1 = get_target_version (fn1);
15873 : string_slice v2 = get_target_version (fn2);
15874 :
15875 : if (!v1.is_valid () && !v2.is_valid ())
15876 : return false;
15877 :
15878 : if (!v1.is_valid ())
15879 : v1 = "default";
15880 : if (!v2.is_valid ())
15881 : v2 = "default";
15882 :
15883 : if (targetm.target_option.same_function_versions (v1, NULL_TREE,
15884 : v2, NULL_TREE))
15885 : return false;
15886 :
15887 : return true;
15888 : }
15889 : }
15890 : }
15891 :
15892 : /* Check if the target_version/target_clones attributes are mergeable
15893 : for two decls, and if so returns false.
15894 : If they aren't mergeable, diagnose this and return true.
15895 : Only works for target_version semantics. */
15896 : bool
15897 0 : diagnose_versioned_decls (tree old_decl, tree new_decl)
15898 : {
15899 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15900 :
15901 : string_slice old_target_attr = get_target_version (old_decl);
15902 : string_slice new_target_attr = get_target_version (new_decl);
15903 :
15904 : tree old_target_clones_attr = lookup_attribute ("target_clones",
15905 : DECL_ATTRIBUTES (old_decl));
15906 : tree new_target_clones_attr = lookup_attribute ("target_clones",
15907 : DECL_ATTRIBUTES (new_decl));
15908 :
15909 : /* If none of these are annotated, then it is mergeable. */
15910 : if (!old_target_attr.is_valid ()
15911 : && !old_target_attr.is_valid ()
15912 : && !old_target_clones_attr
15913 : && !new_target_clones_attr)
15914 : return false;
15915 :
15916 : /* If fn1 is unnanotated and fn2 contains default, then is mergeable. */
15917 : if (!old_target_attr.is_valid ()
15918 : && !old_target_clones_attr
15919 : && is_function_default_version (new_decl))
15920 : return false;
15921 :
15922 : /* If fn2 is unnanotated and fn1 contains default, then is mergeable. */
15923 : if (!new_target_attr.is_valid ()
15924 : && !new_target_clones_attr
15925 : && is_function_default_version (old_decl))
15926 : return false;
15927 :
15928 : /* In the case where both are annotated with target_clones, only mergeable if
15929 : the two sets of target_clones imply the same set of versions. */
15930 : if (old_target_clones_attr && new_target_clones_attr)
15931 : {
15932 : auto_vec<string_slice> old_versions = get_clone_versions (old_decl);
15933 : auto_vec<string_slice> new_versions = get_clone_versions (new_decl);
15934 :
15935 : bool mergeable = true;
15936 :
15937 : if (old_versions.length () != new_versions.length ())
15938 : mergeable = false;
15939 :
15940 : /* Check both inclusion directions. */
15941 : for (auto oldv: old_versions)
15942 : {
15943 : bool matched = false;
15944 : for (auto newv: new_versions)
15945 : if (targetm.target_option.same_function_versions (oldv, old_decl,
15946 : newv, new_decl))
15947 : matched = true;
15948 : if (!matched)
15949 : mergeable = false;
15950 : }
15951 :
15952 : for (auto newv: new_versions)
15953 : {
15954 : bool matched = false;
15955 : for (auto oldv: old_versions)
15956 : if (targetm.target_option.same_function_versions (oldv, old_decl,
15957 : newv, new_decl))
15958 : matched = true;
15959 : if (!matched)
15960 : mergeable = false;
15961 : }
15962 :
15963 : if (!mergeable)
15964 : {
15965 : error_at (DECL_SOURCE_LOCATION (new_decl),
15966 : "%qD conflicts with overlapping %<target_clone%> "
15967 : "declaration",
15968 : new_decl);
15969 : inform (DECL_SOURCE_LOCATION (old_decl),
15970 : "previous declaration of %qD", old_decl);
15971 : return true;
15972 : }
15973 :
15974 : return false;
15975 : }
15976 :
15977 : /* If olddecl is target clones and newdecl is a target_version.
15978 : As they are not distinct this implies newdecl redefines a version of
15979 : olddecl. Not mergeable. */
15980 : if (new_target_clones_attr)
15981 : {
15982 : gcc_assert (old_target_attr.is_valid ());
15983 :
15984 : error_at (DECL_SOURCE_LOCATION (new_decl),
15985 : "%qD conflicts for version %qB",
15986 : new_decl, &old_target_attr);
15987 : inform (DECL_SOURCE_LOCATION (old_decl),
15988 : "previous declaration of %qD",
15989 : old_decl);
15990 : return true;
15991 : }
15992 :
15993 : if (old_target_clones_attr)
15994 : {
15995 : gcc_assert (new_target_attr.is_valid ());
15996 :
15997 : error_at (DECL_SOURCE_LOCATION (new_decl),
15998 : "%qD conflicts with a previous declaration for version %qB",
15999 : new_decl, &new_target_attr);
16000 : inform (DECL_SOURCE_LOCATION (old_decl),
16001 : "previous declaration of %qD",
16002 : old_decl);
16003 : return true;
16004 : }
16005 :
16006 : /* The only remaining case is two target_version annotated decls. */
16007 : return !targetm.target_option.same_function_versions
16008 : (old_target_attr, old_decl, new_target_attr, new_decl);
16009 : }
16010 :
16011 :
16012 : /* This page contains routines to unshare tree nodes, i.e. to duplicate tree
16013 : nodes that are referenced more than once in GENERIC functions. This is
16014 : necessary because gimplification (translation into GIMPLE) is performed
16015 : by modifying tree nodes in-place, so gimplification of a shared node in a
16016 : first context could generate an invalid GIMPLE form in a second context.
16017 :
16018 : This is achieved with a simple mark/copy/unmark algorithm that walks the
16019 : GENERIC representation top-down, marks nodes with TREE_VISITED the first
16020 : time it encounters them, duplicates them if they already have TREE_VISITED
16021 : set, and finally removes the TREE_VISITED marks it has set.
16022 :
16023 : The algorithm works only at the function level, i.e. it generates a GENERIC
16024 : representation of a function with no nodes shared within the function when
16025 : passed a GENERIC function (except for nodes that are allowed to be shared).
16026 :
16027 : At the global level, it is also necessary to unshare tree nodes that are
16028 : referenced in more than one function, for the same aforementioned reason.
16029 : This requires some cooperation from the front-end. There are 2 strategies:
16030 :
16031 : 1. Manual unsharing. The front-end needs to call unshare_expr on every
16032 : expression that might end up being shared across functions.
16033 :
16034 : 2. Deep unsharing. This is an extension of regular unsharing. Instead
16035 : of calling unshare_expr on expressions that might be shared across
16036 : functions, the front-end pre-marks them with TREE_VISITED. This will
16037 : ensure that they are unshared on the first reference within functions
16038 : when the regular unsharing algorithm runs. The counterpart is that
16039 : this algorithm must look deeper than for manual unsharing, which is
16040 : specified by LANG_HOOKS_DEEP_UNSHARING.
16041 :
16042 : If there are only few specific cases of node sharing across functions, it is
16043 : probably easier for a front-end to unshare the expressions manually. On the
16044 : contrary, if the expressions generated at the global level are as widespread
16045 : as expressions generated within functions, deep unsharing is very likely the
16046 : way to go. */
16047 :
16048 : /* Similar to copy_tree_r but do not copy SAVE_EXPR or TARGET_EXPR nodes.
16049 : These nodes model computations that must be done once. If we were to
16050 : unshare something like SAVE_EXPR(i++), the gimplification process would
16051 : create wrong code. However, if DATA is non-null, it must hold a pointer
16052 : set that is used to unshare the subtrees of these nodes. */
16053 :
16054 : static tree
16055 2837324360 : mostly_copy_tree_r (tree *tp, int *walk_subtrees, void *data)
16056 : {
16057 2837324360 : tree t = *tp;
16058 2837324360 : enum tree_code code = TREE_CODE (t);
16059 :
16060 : /* Do not copy SAVE_EXPR, TARGET_EXPR or BIND_EXPR nodes themselves, but
16061 : copy their subtrees if we can make sure to do it only once. */
16062 2837324360 : if (code == SAVE_EXPR || code == TARGET_EXPR || code == BIND_EXPR)
16063 : {
16064 11703786 : if (data && !((hash_set<tree> *)data)->add (t))
16065 : ;
16066 : else
16067 11703786 : *walk_subtrees = 0;
16068 : }
16069 :
16070 : /* Stop at types, decls, constants like copy_tree_r. */
16071 2825620574 : else if (TREE_CODE_CLASS (code) == tcc_type
16072 : || TREE_CODE_CLASS (code) == tcc_declaration
16073 2825620574 : || TREE_CODE_CLASS (code) == tcc_constant)
16074 1748003676 : *walk_subtrees = 0;
16075 :
16076 : /* Cope with the statement expression extension. */
16077 1077616898 : else if (code == STATEMENT_LIST)
16078 : ;
16079 :
16080 : /* Leave the bulk of the work to copy_tree_r itself. */
16081 : else
16082 1077567254 : copy_tree_r (tp, walk_subtrees, NULL);
16083 :
16084 2837324360 : return NULL_TREE;
16085 : }
16086 :
16087 : /* Callback for walk_tree to unshare most of the shared trees rooted at *TP.
16088 : If *TP has been visited already, then *TP is deeply copied by calling
16089 : mostly_copy_tree_r. DATA is passed to mostly_copy_tree_r unmodified. */
16090 :
16091 : static tree
16092 286959247 : copy_if_shared_r (tree *tp, int *walk_subtrees, void *data)
16093 : {
16094 286959247 : tree t = *tp;
16095 286959247 : enum tree_code code = TREE_CODE (t);
16096 :
16097 : /* Skip types, decls, and constants. But we do want to look at their
16098 : types and the bounds of types. Mark them as visited so we properly
16099 : unmark their subtrees on the unmark pass. If we've already seen them,
16100 : don't look down further. */
16101 286959247 : if (TREE_CODE_CLASS (code) == tcc_type
16102 : || TREE_CODE_CLASS (code) == tcc_declaration
16103 286959247 : || TREE_CODE_CLASS (code) == tcc_constant)
16104 : {
16105 136376365 : if (TREE_VISITED (t))
16106 83432546 : *walk_subtrees = 0;
16107 : else
16108 52943819 : TREE_VISITED (t) = 1;
16109 : }
16110 :
16111 : /* If this node has been visited already, unshare it and don't look
16112 : any deeper. */
16113 150582882 : else if (TREE_VISITED (t))
16114 : {
16115 1774221 : walk_tree (tp, mostly_copy_tree_r, data, NULL);
16116 1774221 : *walk_subtrees = 0;
16117 : }
16118 :
16119 : /* Otherwise, mark the node as visited and keep looking. */
16120 : else
16121 148808661 : TREE_VISITED (t) = 1;
16122 :
16123 286959247 : return NULL_TREE;
16124 : }
16125 :
16126 : /* Unshare most of the shared trees rooted at *TP. DATA is passed to the
16127 : copy_if_shared_r callback unmodified. */
16128 :
16129 : void
16130 9163812 : copy_if_shared (tree *tp, void *data)
16131 : {
16132 9163812 : walk_tree (tp, copy_if_shared_r, data, NULL);
16133 9163812 : }
16134 :
16135 : /* Unconditionally make an unshared copy of EXPR. This is used when using
16136 : stored expressions which span multiple functions, such as BINFO_VTABLE,
16137 : as the normal unsharing process can't tell that they're shared. */
16138 :
16139 : tree
16140 1583342413 : unshare_expr (tree expr)
16141 : {
16142 1583342413 : walk_tree (&expr, mostly_copy_tree_r, NULL, NULL);
16143 1583342413 : return expr;
16144 : }
16145 :
16146 : /* Worker for unshare_expr_without_location. */
16147 :
16148 : static tree
16149 15528101 : prune_expr_location (tree *tp, int *walk_subtrees, void *)
16150 : {
16151 15528101 : if (EXPR_P (*tp))
16152 7787439 : SET_EXPR_LOCATION (*tp, UNKNOWN_LOCATION);
16153 : else
16154 7740662 : *walk_subtrees = 0;
16155 15528101 : return NULL_TREE;
16156 : }
16157 :
16158 : /* Similar to unshare_expr but also prune all expression locations
16159 : from EXPR. */
16160 :
16161 : tree
16162 24625747 : unshare_expr_without_location (tree expr)
16163 : {
16164 24625747 : walk_tree (&expr, mostly_copy_tree_r, NULL, NULL);
16165 24625747 : if (EXPR_P (expr))
16166 5311395 : walk_tree (&expr, prune_expr_location, NULL, NULL);
16167 24625747 : return expr;
16168 : }
16169 :
16170 : void
16171 264319 : tree_cc_finalize (void)
16172 : {
16173 264319 : clear_nonstandard_integer_type_cache ();
16174 264319 : vec_free (bitint_type_cache);
16175 264319 : }
16176 :
16177 : void
16178 236 : gt_ggc_mx (tree_raw_data *x)
16179 : {
16180 236 : gt_ggc_m_9tree_node (x->typed.type);
16181 236 : gt_ggc_m_9tree_node (x->owner);
16182 236 : }
16183 :
16184 : void
16185 12 : gt_pch_nx (tree_raw_data *x)
16186 : {
16187 12 : gt_pch_n_9tree_node (x->typed.type);
16188 12 : gt_pch_n_9tree_node (x->owner);
16189 12 : }
16190 :
16191 : /* For PCH we guarantee that RAW_DATA_CST's RAW_DATA_OWNER is a STRING_CST and
16192 : RAW_DATA_POINTER points into it. We don't want to save/restore
16193 : RAW_DATA_POINTER on its own but want to restore it pointing at the same
16194 : offset of the STRING_CST as before. */
16195 :
16196 : void
16197 12 : gt_pch_nx (tree_raw_data *x, gt_pointer_operator op, void *cookie)
16198 : {
16199 12 : op (&x->typed.type, NULL, cookie);
16200 12 : gcc_checking_assert (x->owner
16201 : && TREE_CODE (x->owner) == STRING_CST
16202 : && x->str >= TREE_STRING_POINTER (x->owner)
16203 : && (x->str + x->length
16204 : <= (TREE_STRING_POINTER (x->owner)
16205 : + TREE_STRING_LENGTH (x->owner))));
16206 12 : ptrdiff_t off = x->str - (const char *) (x->owner);
16207 12 : tree owner = x->owner;
16208 12 : op (&x->owner, NULL, cookie);
16209 12 : x->owner = owner;
16210 : /* The above op call relocates x->owner and remembers the address
16211 : for relocation e.g. if the compiler is position independent.
16212 : We then restore x->owner back to its previous value and call
16213 : op again, for x->owner itself this just repeats (uselessly) what
16214 : the first call did, but as the second argument is now non-NULL
16215 : and different, it also arranges for &x->str to be noted for the
16216 : PIE relocation. */
16217 12 : op (&x->owner, &x->str, cookie);
16218 12 : x->str = (const char *) (x->owner) + off;
16219 12 : }
16220 :
16221 : #if CHECKING_P
16222 :
16223 : namespace selftest {
16224 :
16225 : /* Selftests for tree. */
16226 :
16227 : /* Verify that integer constants are sane. */
16228 :
16229 : static void
16230 4 : test_integer_constants ()
16231 : {
16232 4 : ASSERT_TRUE (integer_type_node != NULL);
16233 4 : ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
16234 :
16235 4 : tree type = integer_type_node;
16236 :
16237 4 : tree zero = build_zero_cst (type);
16238 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
16239 4 : ASSERT_EQ (type, TREE_TYPE (zero));
16240 :
16241 4 : tree one = build_int_cst (type, 1);
16242 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
16243 4 : ASSERT_EQ (type, TREE_TYPE (zero));
16244 4 : }
16245 :
16246 : /* Verify identifiers. */
16247 :
16248 : static void
16249 4 : test_identifiers ()
16250 : {
16251 4 : tree identifier = get_identifier ("foo");
16252 4 : ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
16253 4 : ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
16254 4 : }
16255 :
16256 : /* Verify LABEL_DECL. */
16257 :
16258 : static void
16259 4 : test_labels ()
16260 : {
16261 4 : tree identifier = get_identifier ("err");
16262 4 : tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
16263 : identifier, void_type_node);
16264 4 : ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
16265 4 : ASSERT_FALSE (FORCED_LABEL (label_decl));
16266 4 : }
16267 :
16268 : /* Return a new VECTOR_CST node whose type is TYPE and whose values
16269 : are given by VALS. */
16270 :
16271 : static tree
16272 40 : build_vector (tree type, const vec<tree> &vals MEM_STAT_DECL)
16273 : {
16274 80 : gcc_assert (known_eq (vals.length (), TYPE_VECTOR_SUBPARTS (type)));
16275 40 : tree_vector_builder builder (type, vals.length (), 1);
16276 40 : builder.splice (vals);
16277 40 : return builder.build ();
16278 40 : }
16279 :
16280 : /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED. */
16281 :
16282 : static void
16283 40 : check_vector_cst (const vec<tree> &expected, tree actual)
16284 : {
16285 80 : ASSERT_KNOWN_EQ (expected.length (),
16286 : TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual)));
16287 360 : for (unsigned int i = 0; i < expected.length (); ++i)
16288 320 : ASSERT_EQ (wi::to_wide (expected[i]),
16289 : wi::to_wide (vector_cst_elt (actual, i)));
16290 40 : }
16291 :
16292 : /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
16293 : and that its elements match EXPECTED. */
16294 :
16295 : static void
16296 8 : check_vector_cst_duplicate (const vec<tree> &expected, tree actual,
16297 : unsigned int npatterns)
16298 : {
16299 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
16300 8 : ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual));
16301 8 : ASSERT_EQ (npatterns, vector_cst_encoded_nelts (actual));
16302 8 : ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual));
16303 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
16304 8 : check_vector_cst (expected, actual);
16305 8 : }
16306 :
16307 : /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
16308 : and NPATTERNS background elements, and that its elements match
16309 : EXPECTED. */
16310 :
16311 : static void
16312 8 : check_vector_cst_fill (const vec<tree> &expected, tree actual,
16313 : unsigned int npatterns)
16314 : {
16315 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
16316 8 : ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual));
16317 8 : ASSERT_EQ (2 * npatterns, vector_cst_encoded_nelts (actual));
16318 8 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
16319 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
16320 8 : check_vector_cst (expected, actual);
16321 8 : }
16322 :
16323 : /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
16324 : and that its elements match EXPECTED. */
16325 :
16326 : static void
16327 24 : check_vector_cst_stepped (const vec<tree> &expected, tree actual,
16328 : unsigned int npatterns)
16329 : {
16330 24 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
16331 24 : ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual));
16332 24 : ASSERT_EQ (3 * npatterns, vector_cst_encoded_nelts (actual));
16333 24 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
16334 24 : ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual));
16335 24 : check_vector_cst (expected, actual);
16336 24 : }
16337 :
16338 : /* Test the creation of VECTOR_CSTs. */
16339 :
16340 : static void
16341 4 : test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO)
16342 : {
16343 4 : auto_vec<tree, 8> elements (8);
16344 4 : elements.quick_grow (8);
16345 4 : tree element_type = build_nonstandard_integer_type (16, true);
16346 4 : tree vector_type = build_vector_type (element_type, 8);
16347 :
16348 : /* Test a simple linear series with a base of 0 and a step of 1:
16349 : { 0, 1, 2, 3, 4, 5, 6, 7 }. */
16350 36 : for (unsigned int i = 0; i < 8; ++i)
16351 32 : elements[i] = build_int_cst (element_type, i);
16352 4 : tree vector = build_vector (vector_type, elements PASS_MEM_STAT);
16353 4 : check_vector_cst_stepped (elements, vector, 1);
16354 :
16355 : /* Try the same with the first element replaced by 100:
16356 : { 100, 1, 2, 3, 4, 5, 6, 7 }. */
16357 4 : elements[0] = build_int_cst (element_type, 100);
16358 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16359 4 : check_vector_cst_stepped (elements, vector, 1);
16360 :
16361 : /* Try a series that wraps around.
16362 : { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }. */
16363 36 : for (unsigned int i = 1; i < 8; ++i)
16364 28 : elements[i] = build_int_cst (element_type, (65530 + i) & 0xffff);
16365 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16366 4 : check_vector_cst_stepped (elements, vector, 1);
16367 :
16368 : /* Try a downward series:
16369 : { 100, 79, 78, 77, 76, 75, 75, 73 }. */
16370 36 : for (unsigned int i = 1; i < 8; ++i)
16371 28 : elements[i] = build_int_cst (element_type, 80 - i);
16372 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16373 4 : check_vector_cst_stepped (elements, vector, 1);
16374 :
16375 : /* Try two interleaved series with different bases and steps:
16376 : { 100, 53, 66, 206, 62, 212, 58, 218 }. */
16377 4 : elements[1] = build_int_cst (element_type, 53);
16378 16 : for (unsigned int i = 2; i < 8; i += 2)
16379 : {
16380 12 : elements[i] = build_int_cst (element_type, 70 - i * 2);
16381 12 : elements[i + 1] = build_int_cst (element_type, 200 + i * 3);
16382 : }
16383 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16384 4 : check_vector_cst_stepped (elements, vector, 2);
16385 :
16386 : /* Try a duplicated value:
16387 : { 100, 100, 100, 100, 100, 100, 100, 100 }. */
16388 36 : for (unsigned int i = 1; i < 8; ++i)
16389 28 : elements[i] = elements[0];
16390 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16391 4 : check_vector_cst_duplicate (elements, vector, 1);
16392 :
16393 : /* Try an interleaved duplicated value:
16394 : { 100, 55, 100, 55, 100, 55, 100, 55 }. */
16395 4 : elements[1] = build_int_cst (element_type, 55);
16396 28 : for (unsigned int i = 2; i < 8; ++i)
16397 24 : elements[i] = elements[i - 2];
16398 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16399 4 : check_vector_cst_duplicate (elements, vector, 2);
16400 :
16401 : /* Try a duplicated value with 2 exceptions
16402 : { 41, 97, 100, 55, 100, 55, 100, 55 }. */
16403 4 : elements[0] = build_int_cst (element_type, 41);
16404 4 : elements[1] = build_int_cst (element_type, 97);
16405 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16406 4 : check_vector_cst_fill (elements, vector, 2);
16407 :
16408 : /* Try with and without a step
16409 : { 41, 97, 100, 21, 100, 35, 100, 49 }. */
16410 20 : for (unsigned int i = 3; i < 8; i += 2)
16411 12 : elements[i] = build_int_cst (element_type, i * 7);
16412 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16413 4 : check_vector_cst_stepped (elements, vector, 2);
16414 :
16415 : /* Try a fully-general constant:
16416 : { 41, 97, 100, 21, 100, 9990, 100, 49 }. */
16417 4 : elements[5] = build_int_cst (element_type, 9990);
16418 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16419 4 : check_vector_cst_fill (elements, vector, 4);
16420 4 : }
16421 :
16422 : /* Verify that STRIP_NOPS (NODE) is EXPECTED.
16423 : Helper function for test_location_wrappers, to deal with STRIP_NOPS
16424 : modifying its argument in-place. */
16425 :
16426 : static void
16427 12 : check_strip_nops (tree node, tree expected)
16428 : {
16429 12 : STRIP_NOPS (node);
16430 12 : ASSERT_EQ (expected, node);
16431 12 : }
16432 :
16433 : /* Verify location wrappers. */
16434 :
16435 : static void
16436 4 : test_location_wrappers ()
16437 : {
16438 4 : location_t loc = BUILTINS_LOCATION;
16439 :
16440 4 : ASSERT_EQ (NULL_TREE, maybe_wrap_with_location (NULL_TREE, loc));
16441 :
16442 : /* Wrapping a constant. */
16443 4 : tree int_cst = build_int_cst (integer_type_node, 42);
16444 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst));
16445 4 : ASSERT_FALSE (location_wrapper_p (int_cst));
16446 :
16447 4 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
16448 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
16449 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_cst));
16450 4 : ASSERT_EQ (int_cst, tree_strip_any_location_wrapper (wrapped_int_cst));
16451 :
16452 : /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION. */
16453 4 : ASSERT_EQ (int_cst, maybe_wrap_with_location (int_cst, UNKNOWN_LOCATION));
16454 :
16455 : /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P. */
16456 4 : tree cast = build1 (NOP_EXPR, char_type_node, int_cst);
16457 4 : ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast));
16458 4 : ASSERT_EQ (cast, maybe_wrap_with_location (cast, loc));
16459 :
16460 : /* Wrapping a STRING_CST. */
16461 4 : tree string_cst = build_string (4, "foo");
16462 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst));
16463 4 : ASSERT_FALSE (location_wrapper_p (string_cst));
16464 :
16465 4 : tree wrapped_string_cst = maybe_wrap_with_location (string_cst, loc);
16466 4 : ASSERT_TRUE (location_wrapper_p (wrapped_string_cst));
16467 4 : ASSERT_EQ (VIEW_CONVERT_EXPR, TREE_CODE (wrapped_string_cst));
16468 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_string_cst));
16469 4 : ASSERT_EQ (string_cst, tree_strip_any_location_wrapper (wrapped_string_cst));
16470 :
16471 :
16472 : /* Wrapping a variable. */
16473 4 : tree int_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
16474 : get_identifier ("some_int_var"),
16475 : integer_type_node);
16476 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var));
16477 4 : ASSERT_FALSE (location_wrapper_p (int_var));
16478 :
16479 4 : tree wrapped_int_var = maybe_wrap_with_location (int_var, loc);
16480 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_var));
16481 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_var));
16482 4 : ASSERT_EQ (int_var, tree_strip_any_location_wrapper (wrapped_int_var));
16483 :
16484 : /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
16485 : wrapper. */
16486 4 : tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
16487 4 : ASSERT_FALSE (location_wrapper_p (r_cast));
16488 4 : ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
16489 :
16490 : /* Verify that STRIP_NOPS removes wrappers. */
16491 4 : check_strip_nops (wrapped_int_cst, int_cst);
16492 4 : check_strip_nops (wrapped_string_cst, string_cst);
16493 4 : check_strip_nops (wrapped_int_var, int_var);
16494 4 : }
16495 :
16496 : /* Test various tree predicates. Verify that location wrappers don't
16497 : affect the results. */
16498 :
16499 : static void
16500 4 : test_predicates ()
16501 : {
16502 : /* Build various constants and wrappers around them. */
16503 :
16504 4 : location_t loc = BUILTINS_LOCATION;
16505 :
16506 4 : tree i_0 = build_int_cst (integer_type_node, 0);
16507 4 : tree wr_i_0 = maybe_wrap_with_location (i_0, loc);
16508 :
16509 4 : tree i_1 = build_int_cst (integer_type_node, 1);
16510 4 : tree wr_i_1 = maybe_wrap_with_location (i_1, loc);
16511 :
16512 4 : tree i_m1 = build_int_cst (integer_type_node, -1);
16513 4 : tree wr_i_m1 = maybe_wrap_with_location (i_m1, loc);
16514 :
16515 4 : tree f_0 = build_real_from_int_cst (float_type_node, i_0);
16516 4 : tree wr_f_0 = maybe_wrap_with_location (f_0, loc);
16517 4 : tree f_1 = build_real_from_int_cst (float_type_node, i_1);
16518 4 : tree wr_f_1 = maybe_wrap_with_location (f_1, loc);
16519 4 : tree f_m1 = build_real_from_int_cst (float_type_node, i_m1);
16520 4 : tree wr_f_m1 = maybe_wrap_with_location (f_m1, loc);
16521 :
16522 4 : tree c_i_0 = build_complex (NULL_TREE, i_0, i_0);
16523 4 : tree c_i_1 = build_complex (NULL_TREE, i_1, i_0);
16524 4 : tree c_i_m1 = build_complex (NULL_TREE, i_m1, i_0);
16525 :
16526 4 : tree c_f_0 = build_complex (NULL_TREE, f_0, f_0);
16527 4 : tree c_f_1 = build_complex (NULL_TREE, f_1, f_0);
16528 4 : tree c_f_m1 = build_complex (NULL_TREE, f_m1, f_0);
16529 :
16530 : /* TODO: vector constants. */
16531 :
16532 : /* Test integer_onep. */
16533 4 : ASSERT_FALSE (integer_onep (i_0));
16534 4 : ASSERT_FALSE (integer_onep (wr_i_0));
16535 4 : ASSERT_TRUE (integer_onep (i_1));
16536 4 : ASSERT_TRUE (integer_onep (wr_i_1));
16537 4 : ASSERT_FALSE (integer_onep (i_m1));
16538 4 : ASSERT_FALSE (integer_onep (wr_i_m1));
16539 4 : ASSERT_FALSE (integer_onep (f_0));
16540 4 : ASSERT_FALSE (integer_onep (wr_f_0));
16541 4 : ASSERT_FALSE (integer_onep (f_1));
16542 4 : ASSERT_FALSE (integer_onep (wr_f_1));
16543 4 : ASSERT_FALSE (integer_onep (f_m1));
16544 4 : ASSERT_FALSE (integer_onep (wr_f_m1));
16545 4 : ASSERT_FALSE (integer_onep (c_i_0));
16546 4 : ASSERT_TRUE (integer_onep (c_i_1));
16547 4 : ASSERT_FALSE (integer_onep (c_i_m1));
16548 4 : ASSERT_FALSE (integer_onep (c_f_0));
16549 4 : ASSERT_FALSE (integer_onep (c_f_1));
16550 4 : ASSERT_FALSE (integer_onep (c_f_m1));
16551 :
16552 : /* Test integer_zerop. */
16553 4 : ASSERT_TRUE (integer_zerop (i_0));
16554 4 : ASSERT_TRUE (integer_zerop (wr_i_0));
16555 4 : ASSERT_FALSE (integer_zerop (i_1));
16556 4 : ASSERT_FALSE (integer_zerop (wr_i_1));
16557 4 : ASSERT_FALSE (integer_zerop (i_m1));
16558 4 : ASSERT_FALSE (integer_zerop (wr_i_m1));
16559 4 : ASSERT_FALSE (integer_zerop (f_0));
16560 4 : ASSERT_FALSE (integer_zerop (wr_f_0));
16561 4 : ASSERT_FALSE (integer_zerop (f_1));
16562 4 : ASSERT_FALSE (integer_zerop (wr_f_1));
16563 4 : ASSERT_FALSE (integer_zerop (f_m1));
16564 4 : ASSERT_FALSE (integer_zerop (wr_f_m1));
16565 4 : ASSERT_TRUE (integer_zerop (c_i_0));
16566 4 : ASSERT_FALSE (integer_zerop (c_i_1));
16567 4 : ASSERT_FALSE (integer_zerop (c_i_m1));
16568 4 : ASSERT_FALSE (integer_zerop (c_f_0));
16569 4 : ASSERT_FALSE (integer_zerop (c_f_1));
16570 4 : ASSERT_FALSE (integer_zerop (c_f_m1));
16571 :
16572 : /* Test integer_all_onesp. */
16573 4 : ASSERT_FALSE (integer_all_onesp (i_0));
16574 4 : ASSERT_FALSE (integer_all_onesp (wr_i_0));
16575 4 : ASSERT_FALSE (integer_all_onesp (i_1));
16576 4 : ASSERT_FALSE (integer_all_onesp (wr_i_1));
16577 4 : ASSERT_TRUE (integer_all_onesp (i_m1));
16578 4 : ASSERT_TRUE (integer_all_onesp (wr_i_m1));
16579 4 : ASSERT_FALSE (integer_all_onesp (f_0));
16580 4 : ASSERT_FALSE (integer_all_onesp (wr_f_0));
16581 4 : ASSERT_FALSE (integer_all_onesp (f_1));
16582 4 : ASSERT_FALSE (integer_all_onesp (wr_f_1));
16583 4 : ASSERT_FALSE (integer_all_onesp (f_m1));
16584 4 : ASSERT_FALSE (integer_all_onesp (wr_f_m1));
16585 4 : ASSERT_FALSE (integer_all_onesp (c_i_0));
16586 4 : ASSERT_FALSE (integer_all_onesp (c_i_1));
16587 4 : ASSERT_FALSE (integer_all_onesp (c_i_m1));
16588 4 : ASSERT_FALSE (integer_all_onesp (c_f_0));
16589 4 : ASSERT_FALSE (integer_all_onesp (c_f_1));
16590 4 : ASSERT_FALSE (integer_all_onesp (c_f_m1));
16591 :
16592 : /* Test integer_minus_onep. */
16593 4 : ASSERT_FALSE (integer_minus_onep (i_0));
16594 4 : ASSERT_FALSE (integer_minus_onep (wr_i_0));
16595 4 : ASSERT_FALSE (integer_minus_onep (i_1));
16596 4 : ASSERT_FALSE (integer_minus_onep (wr_i_1));
16597 4 : ASSERT_TRUE (integer_minus_onep (i_m1));
16598 4 : ASSERT_TRUE (integer_minus_onep (wr_i_m1));
16599 4 : ASSERT_FALSE (integer_minus_onep (f_0));
16600 4 : ASSERT_FALSE (integer_minus_onep (wr_f_0));
16601 4 : ASSERT_FALSE (integer_minus_onep (f_1));
16602 4 : ASSERT_FALSE (integer_minus_onep (wr_f_1));
16603 4 : ASSERT_FALSE (integer_minus_onep (f_m1));
16604 4 : ASSERT_FALSE (integer_minus_onep (wr_f_m1));
16605 4 : ASSERT_FALSE (integer_minus_onep (c_i_0));
16606 4 : ASSERT_FALSE (integer_minus_onep (c_i_1));
16607 4 : ASSERT_TRUE (integer_minus_onep (c_i_m1));
16608 4 : ASSERT_FALSE (integer_minus_onep (c_f_0));
16609 4 : ASSERT_FALSE (integer_minus_onep (c_f_1));
16610 4 : ASSERT_FALSE (integer_minus_onep (c_f_m1));
16611 :
16612 : /* Test integer_each_onep. */
16613 4 : ASSERT_FALSE (integer_each_onep (i_0));
16614 4 : ASSERT_FALSE (integer_each_onep (wr_i_0));
16615 4 : ASSERT_TRUE (integer_each_onep (i_1));
16616 4 : ASSERT_TRUE (integer_each_onep (wr_i_1));
16617 4 : ASSERT_FALSE (integer_each_onep (i_m1));
16618 4 : ASSERT_FALSE (integer_each_onep (wr_i_m1));
16619 4 : ASSERT_FALSE (integer_each_onep (f_0));
16620 4 : ASSERT_FALSE (integer_each_onep (wr_f_0));
16621 4 : ASSERT_FALSE (integer_each_onep (f_1));
16622 4 : ASSERT_FALSE (integer_each_onep (wr_f_1));
16623 4 : ASSERT_FALSE (integer_each_onep (f_m1));
16624 4 : ASSERT_FALSE (integer_each_onep (wr_f_m1));
16625 4 : ASSERT_FALSE (integer_each_onep (c_i_0));
16626 4 : ASSERT_FALSE (integer_each_onep (c_i_1));
16627 4 : ASSERT_FALSE (integer_each_onep (c_i_m1));
16628 4 : ASSERT_FALSE (integer_each_onep (c_f_0));
16629 4 : ASSERT_FALSE (integer_each_onep (c_f_1));
16630 4 : ASSERT_FALSE (integer_each_onep (c_f_m1));
16631 :
16632 : /* Test integer_truep. */
16633 4 : ASSERT_FALSE (integer_truep (i_0));
16634 4 : ASSERT_FALSE (integer_truep (wr_i_0));
16635 4 : ASSERT_TRUE (integer_truep (i_1));
16636 4 : ASSERT_TRUE (integer_truep (wr_i_1));
16637 4 : ASSERT_FALSE (integer_truep (i_m1));
16638 4 : ASSERT_FALSE (integer_truep (wr_i_m1));
16639 4 : ASSERT_FALSE (integer_truep (f_0));
16640 4 : ASSERT_FALSE (integer_truep (wr_f_0));
16641 4 : ASSERT_FALSE (integer_truep (f_1));
16642 4 : ASSERT_FALSE (integer_truep (wr_f_1));
16643 4 : ASSERT_FALSE (integer_truep (f_m1));
16644 4 : ASSERT_FALSE (integer_truep (wr_f_m1));
16645 4 : ASSERT_FALSE (integer_truep (c_i_0));
16646 4 : ASSERT_TRUE (integer_truep (c_i_1));
16647 4 : ASSERT_FALSE (integer_truep (c_i_m1));
16648 4 : ASSERT_FALSE (integer_truep (c_f_0));
16649 4 : ASSERT_FALSE (integer_truep (c_f_1));
16650 4 : ASSERT_FALSE (integer_truep (c_f_m1));
16651 :
16652 : /* Test integer_nonzerop. */
16653 4 : ASSERT_FALSE (integer_nonzerop (i_0));
16654 4 : ASSERT_FALSE (integer_nonzerop (wr_i_0));
16655 4 : ASSERT_TRUE (integer_nonzerop (i_1));
16656 4 : ASSERT_TRUE (integer_nonzerop (wr_i_1));
16657 4 : ASSERT_TRUE (integer_nonzerop (i_m1));
16658 4 : ASSERT_TRUE (integer_nonzerop (wr_i_m1));
16659 4 : ASSERT_FALSE (integer_nonzerop (f_0));
16660 4 : ASSERT_FALSE (integer_nonzerop (wr_f_0));
16661 4 : ASSERT_FALSE (integer_nonzerop (f_1));
16662 4 : ASSERT_FALSE (integer_nonzerop (wr_f_1));
16663 4 : ASSERT_FALSE (integer_nonzerop (f_m1));
16664 4 : ASSERT_FALSE (integer_nonzerop (wr_f_m1));
16665 4 : ASSERT_FALSE (integer_nonzerop (c_i_0));
16666 4 : ASSERT_TRUE (integer_nonzerop (c_i_1));
16667 4 : ASSERT_TRUE (integer_nonzerop (c_i_m1));
16668 4 : ASSERT_FALSE (integer_nonzerop (c_f_0));
16669 4 : ASSERT_FALSE (integer_nonzerop (c_f_1));
16670 4 : ASSERT_FALSE (integer_nonzerop (c_f_m1));
16671 :
16672 : /* Test real_zerop. */
16673 4 : ASSERT_FALSE (real_zerop (i_0));
16674 4 : ASSERT_FALSE (real_zerop (wr_i_0));
16675 4 : ASSERT_FALSE (real_zerop (i_1));
16676 4 : ASSERT_FALSE (real_zerop (wr_i_1));
16677 4 : ASSERT_FALSE (real_zerop (i_m1));
16678 4 : ASSERT_FALSE (real_zerop (wr_i_m1));
16679 4 : ASSERT_TRUE (real_zerop (f_0));
16680 4 : ASSERT_TRUE (real_zerop (wr_f_0));
16681 4 : ASSERT_FALSE (real_zerop (f_1));
16682 4 : ASSERT_FALSE (real_zerop (wr_f_1));
16683 4 : ASSERT_FALSE (real_zerop (f_m1));
16684 4 : ASSERT_FALSE (real_zerop (wr_f_m1));
16685 4 : ASSERT_FALSE (real_zerop (c_i_0));
16686 4 : ASSERT_FALSE (real_zerop (c_i_1));
16687 4 : ASSERT_FALSE (real_zerop (c_i_m1));
16688 4 : ASSERT_TRUE (real_zerop (c_f_0));
16689 4 : ASSERT_FALSE (real_zerop (c_f_1));
16690 4 : ASSERT_FALSE (real_zerop (c_f_m1));
16691 :
16692 : /* Test real_onep. */
16693 4 : ASSERT_FALSE (real_onep (i_0));
16694 4 : ASSERT_FALSE (real_onep (wr_i_0));
16695 4 : ASSERT_FALSE (real_onep (i_1));
16696 4 : ASSERT_FALSE (real_onep (wr_i_1));
16697 4 : ASSERT_FALSE (real_onep (i_m1));
16698 4 : ASSERT_FALSE (real_onep (wr_i_m1));
16699 4 : ASSERT_FALSE (real_onep (f_0));
16700 4 : ASSERT_FALSE (real_onep (wr_f_0));
16701 4 : ASSERT_TRUE (real_onep (f_1));
16702 4 : ASSERT_TRUE (real_onep (wr_f_1));
16703 4 : ASSERT_FALSE (real_onep (f_m1));
16704 4 : ASSERT_FALSE (real_onep (wr_f_m1));
16705 4 : ASSERT_FALSE (real_onep (c_i_0));
16706 4 : ASSERT_FALSE (real_onep (c_i_1));
16707 4 : ASSERT_FALSE (real_onep (c_i_m1));
16708 4 : ASSERT_FALSE (real_onep (c_f_0));
16709 4 : ASSERT_TRUE (real_onep (c_f_1));
16710 4 : ASSERT_FALSE (real_onep (c_f_m1));
16711 :
16712 : /* Test real_minus_onep. */
16713 4 : ASSERT_FALSE (real_minus_onep (i_0));
16714 4 : ASSERT_FALSE (real_minus_onep (wr_i_0));
16715 4 : ASSERT_FALSE (real_minus_onep (i_1));
16716 4 : ASSERT_FALSE (real_minus_onep (wr_i_1));
16717 4 : ASSERT_FALSE (real_minus_onep (i_m1));
16718 4 : ASSERT_FALSE (real_minus_onep (wr_i_m1));
16719 4 : ASSERT_FALSE (real_minus_onep (f_0));
16720 4 : ASSERT_FALSE (real_minus_onep (wr_f_0));
16721 4 : ASSERT_FALSE (real_minus_onep (f_1));
16722 4 : ASSERT_FALSE (real_minus_onep (wr_f_1));
16723 4 : ASSERT_TRUE (real_minus_onep (f_m1));
16724 4 : ASSERT_TRUE (real_minus_onep (wr_f_m1));
16725 4 : ASSERT_FALSE (real_minus_onep (c_i_0));
16726 4 : ASSERT_FALSE (real_minus_onep (c_i_1));
16727 4 : ASSERT_FALSE (real_minus_onep (c_i_m1));
16728 4 : ASSERT_FALSE (real_minus_onep (c_f_0));
16729 4 : ASSERT_FALSE (real_minus_onep (c_f_1));
16730 4 : ASSERT_TRUE (real_minus_onep (c_f_m1));
16731 :
16732 : /* Test zerop. */
16733 4 : ASSERT_TRUE (zerop (i_0));
16734 4 : ASSERT_TRUE (zerop (wr_i_0));
16735 4 : ASSERT_FALSE (zerop (i_1));
16736 4 : ASSERT_FALSE (zerop (wr_i_1));
16737 4 : ASSERT_FALSE (zerop (i_m1));
16738 4 : ASSERT_FALSE (zerop (wr_i_m1));
16739 4 : ASSERT_TRUE (zerop (f_0));
16740 4 : ASSERT_TRUE (zerop (wr_f_0));
16741 4 : ASSERT_FALSE (zerop (f_1));
16742 4 : ASSERT_FALSE (zerop (wr_f_1));
16743 4 : ASSERT_FALSE (zerop (f_m1));
16744 4 : ASSERT_FALSE (zerop (wr_f_m1));
16745 4 : ASSERT_TRUE (zerop (c_i_0));
16746 4 : ASSERT_FALSE (zerop (c_i_1));
16747 4 : ASSERT_FALSE (zerop (c_i_m1));
16748 4 : ASSERT_TRUE (zerop (c_f_0));
16749 4 : ASSERT_FALSE (zerop (c_f_1));
16750 4 : ASSERT_FALSE (zerop (c_f_m1));
16751 :
16752 : /* Test tree_expr_nonnegative_p. */
16753 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_0));
16754 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_0));
16755 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_1));
16756 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_1));
16757 4 : ASSERT_FALSE (tree_expr_nonnegative_p (i_m1));
16758 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_i_m1));
16759 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_0));
16760 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_0));
16761 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_1));
16762 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_1));
16763 4 : ASSERT_FALSE (tree_expr_nonnegative_p (f_m1));
16764 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_f_m1));
16765 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_0));
16766 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_1));
16767 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_m1));
16768 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_0));
16769 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_1));
16770 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_m1));
16771 :
16772 : /* Test tree_expr_nonzero_p. */
16773 4 : ASSERT_FALSE (tree_expr_nonzero_p (i_0));
16774 4 : ASSERT_FALSE (tree_expr_nonzero_p (wr_i_0));
16775 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_1));
16776 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_1));
16777 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_m1));
16778 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_m1));
16779 :
16780 : /* Test integer_valued_real_p. */
16781 4 : ASSERT_FALSE (integer_valued_real_p (i_0));
16782 4 : ASSERT_TRUE (integer_valued_real_p (f_0));
16783 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_0));
16784 4 : ASSERT_TRUE (integer_valued_real_p (f_1));
16785 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_1));
16786 :
16787 : /* Test integer_pow2p. */
16788 4 : ASSERT_FALSE (integer_pow2p (i_0));
16789 4 : ASSERT_TRUE (integer_pow2p (i_1));
16790 4 : ASSERT_TRUE (integer_pow2p (wr_i_1));
16791 :
16792 : /* Test uniform_integer_cst_p. */
16793 4 : ASSERT_TRUE (uniform_integer_cst_p (i_0));
16794 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_0));
16795 4 : ASSERT_TRUE (uniform_integer_cst_p (i_1));
16796 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_1));
16797 4 : ASSERT_TRUE (uniform_integer_cst_p (i_m1));
16798 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_m1));
16799 4 : ASSERT_FALSE (uniform_integer_cst_p (f_0));
16800 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_0));
16801 4 : ASSERT_FALSE (uniform_integer_cst_p (f_1));
16802 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_1));
16803 4 : ASSERT_FALSE (uniform_integer_cst_p (f_m1));
16804 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_m1));
16805 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_0));
16806 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_1));
16807 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_m1));
16808 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_0));
16809 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_1));
16810 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_m1));
16811 4 : }
16812 :
16813 : /* Check that string escaping works correctly. */
16814 :
16815 : static void
16816 4 : test_escaped_strings (void)
16817 : {
16818 4 : int saved_cutoff;
16819 4 : escaped_string msg;
16820 :
16821 4 : msg.escape (NULL);
16822 : /* ASSERT_STREQ does not accept NULL as a valid test
16823 : result, so we have to use ASSERT_EQ instead. */
16824 4 : ASSERT_EQ (NULL, (const char *) msg);
16825 :
16826 4 : msg.escape ("");
16827 4 : ASSERT_STREQ ("", (const char *) msg);
16828 :
16829 4 : msg.escape ("foobar");
16830 4 : ASSERT_STREQ ("foobar", (const char *) msg);
16831 :
16832 : /* Ensure that we have -fmessage-length set to 0. */
16833 4 : pretty_printer *pp = global_dc->get_reference_printer ();
16834 4 : saved_cutoff = pp_line_cutoff (pp);
16835 4 : pp_line_cutoff (pp) = 0;
16836 :
16837 4 : msg.escape ("foo\nbar");
16838 4 : ASSERT_STREQ ("foo\\nbar", (const char *) msg);
16839 :
16840 4 : msg.escape ("\a\b\f\n\r\t\v");
16841 4 : ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg);
16842 :
16843 : /* Now repeat the tests with -fmessage-length set to 5. */
16844 4 : pp_line_cutoff (pp) = 5;
16845 :
16846 : /* Note that the newline is not translated into an escape. */
16847 4 : msg.escape ("foo\nbar");
16848 4 : ASSERT_STREQ ("foo\nbar", (const char *) msg);
16849 :
16850 4 : msg.escape ("\a\b\f\n\r\t\v");
16851 4 : ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg);
16852 :
16853 : /* Restore the original message length setting. */
16854 4 : pp_line_cutoff (pp) = saved_cutoff;
16855 4 : }
16856 :
16857 : /* Run all of the selftests within this file. */
16858 :
16859 : void
16860 4 : tree_cc_tests ()
16861 : {
16862 4 : test_integer_constants ();
16863 4 : test_identifiers ();
16864 4 : test_labels ();
16865 4 : test_vector_cst_patterns ();
16866 4 : test_location_wrappers ();
16867 4 : test_predicates ();
16868 4 : test_escaped_strings ();
16869 4 : }
16870 :
16871 : } // namespace selftest
16872 :
16873 : #endif /* CHECKING_P */
16874 :
16875 : #include "gt-tree.h"
|