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 7279802505 : 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 1852492727 : keep_cache_entry (type_hash *&t)
165 : {
166 1852492727 : 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 719140 : 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 21978966 : gt_value_expr_mark_2 (tree *tp, int *, void *data)
228 : {
229 21978966 : tree t = *tp;
230 21978966 : if (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t) && !ggc_marked_p (t))
231 : {
232 1039 : tree dve = DECL_VALUE_EXPR (t);
233 1039 : gt_value_expr_mark_data *d = (gt_value_expr_mark_data *) data;
234 1039 : walk_tree_1 (&dve, gt_value_expr_mark_2, data, &d->pset, NULL);
235 1039 : d->to_mark.safe_push (t);
236 : }
237 21978966 : return NULL_TREE;
238 : }
239 :
240 : /* Callback called through traverse_noresize on the
241 : value_expr_for_decl hash table. */
242 :
243 : int
244 9603179 : gt_value_expr_mark_1 (tree_decl_map **e, gt_value_expr_mark_data *data)
245 : {
246 9603179 : if (ggc_marked_p ((*e)->base.from))
247 8078813 : walk_tree_1 (&(*e)->to, gt_value_expr_mark_2, data, &data->pset, NULL);
248 9603179 : 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 719140 : gt_value_expr_mark (hash_table<tree_decl_map_cache_hasher> *h)
263 : {
264 719140 : if (!h)
265 0 : return;
266 :
267 719140 : gt_value_expr_mark_data data;
268 719140 : h->traverse_noresize<gt_value_expr_mark_data *,
269 10322319 : gt_value_expr_mark_1> (&data);
270 2158459 : for (auto v : data.to_mark)
271 1039 : gt_ggc_mx (v);
272 719140 : }
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 : };
404 :
405 : const char * const omp_clause_code_name[] =
406 : {
407 : "error_clause",
408 : "private",
409 : "shared",
410 : "firstprivate",
411 : "lastprivate",
412 : "reduction",
413 : "task_reduction",
414 : "in_reduction",
415 : "copyin",
416 : "copyprivate",
417 : "linear",
418 : "affinity",
419 : "aligned",
420 : "allocate",
421 : "depend",
422 : "nontemporal",
423 : "uniform",
424 : "enter",
425 : "link",
426 : "detach",
427 : "use_device_ptr",
428 : "use_device_addr",
429 : "is_device_ptr",
430 : "inclusive",
431 : "exclusive",
432 : "from",
433 : "to",
434 : "map",
435 : "has_device_addr",
436 : "doacross",
437 : "_mapper_binding_",
438 : "_cache_",
439 : "destroy",
440 : "init",
441 : "use",
442 : "interop",
443 : "gang",
444 : "async",
445 : "wait",
446 : "auto",
447 : "seq",
448 : "_looptemp_",
449 : "_reductemp_",
450 : "_condtemp_",
451 : "_scantemp_",
452 : "if",
453 : "self",
454 : "num_threads",
455 : "schedule",
456 : "nowait",
457 : "ordered",
458 : "default",
459 : "collapse",
460 : "untied",
461 : "final",
462 : "mergeable",
463 : "device",
464 : "dist_schedule",
465 : "inbranch",
466 : "notinbranch",
467 : "num_teams",
468 : "thread_limit",
469 : "proc_bind",
470 : "safelen",
471 : "simdlen",
472 : "device_type",
473 : "for",
474 : "parallel",
475 : "sections",
476 : "taskgroup",
477 : "priority",
478 : "grainsize",
479 : "num_tasks",
480 : "nogroup",
481 : "threads",
482 : "simd",
483 : "hint",
484 : "defaultmap",
485 : "order",
486 : "bind",
487 : "filter",
488 : "indirect",
489 : "partial",
490 : "full",
491 : "sizes",
492 : "_simduid_",
493 : "_simt_",
494 : "independent",
495 : "worker",
496 : "vector",
497 : "num_gangs",
498 : "num_workers",
499 : "vector_length",
500 : "tile",
501 : "if_present",
502 : "finalize",
503 : "nohost",
504 : "novariants",
505 : "nocontext",
506 : "dyn_groupprivate",
507 : "uses_allocators",
508 : };
509 :
510 : /* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric
511 : clause names, but for use in diagnostics etc. would like to use the "user"
512 : clause names. */
513 :
514 : const char *
515 445 : user_omp_clause_code_name (tree clause, bool oacc)
516 : {
517 : /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to
518 : distinguish clauses as seen by the user. See also where front ends do
519 : 'build_omp_clause' with 'OMP_CLAUSE_MAP'. */
520 890 : if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
521 445 : switch (OMP_CLAUSE_MAP_KIND (clause))
522 : {
523 : case GOMP_MAP_FORCE_ALLOC:
524 : case GOMP_MAP_ALLOC: return "create";
525 0 : case GOMP_MAP_FORCE_TO:
526 0 : case GOMP_MAP_TO: return "copyin";
527 0 : case GOMP_MAP_FORCE_FROM:
528 0 : case GOMP_MAP_FROM: return "copyout";
529 361 : case GOMP_MAP_FORCE_TOFROM:
530 361 : case GOMP_MAP_TOFROM: return "copy";
531 0 : case GOMP_MAP_RELEASE: return "delete";
532 0 : case GOMP_MAP_FORCE_PRESENT: return "present";
533 42 : case GOMP_MAP_ATTACH: return "attach";
534 42 : case GOMP_MAP_FORCE_DETACH:
535 42 : case GOMP_MAP_DETACH: return "detach";
536 0 : case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
537 0 : case GOMP_MAP_LINK: return "link";
538 0 : case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
539 : default: break;
540 : }
541 :
542 0 : return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
543 : }
544 :
545 :
546 : /* Return the tree node structure used by tree code CODE. */
547 :
548 : static inline enum tree_node_structure_enum
549 42395848264 : tree_node_structure_for_code (enum tree_code code)
550 : {
551 42395848264 : switch (TREE_CODE_CLASS (code))
552 : {
553 10230487392 : case tcc_declaration:
554 10230487392 : switch (code)
555 : {
556 : case CONST_DECL: return TS_CONST_DECL;
557 : case DEBUG_EXPR_DECL: return TS_DECL_WRTL;
558 : case FIELD_DECL: return TS_FIELD_DECL;
559 : case FUNCTION_DECL: return TS_FUNCTION_DECL;
560 : case LABEL_DECL: return TS_LABEL_DECL;
561 : case PARM_DECL: return TS_PARM_DECL;
562 : case RESULT_DECL: return TS_RESULT_DECL;
563 : case TRANSLATION_UNIT_DECL: return TS_TRANSLATION_UNIT_DECL;
564 : case TYPE_DECL: return TS_TYPE_DECL;
565 : case VAR_DECL: return TS_VAR_DECL;
566 : default: return TS_DECL_NON_COMMON;
567 : }
568 :
569 : case tcc_type: return TS_TYPE_NON_COMMON;
570 :
571 11466192046 : case tcc_binary:
572 11466192046 : case tcc_comparison:
573 11466192046 : case tcc_expression:
574 11466192046 : case tcc_reference:
575 11466192046 : case tcc_statement:
576 11466192046 : case tcc_unary:
577 11466192046 : case tcc_vl_exp: return TS_EXP;
578 :
579 14918805559 : default: /* tcc_constant and tcc_exceptional */
580 14918805559 : break;
581 : }
582 :
583 14918805559 : switch (code)
584 : {
585 : /* tcc_constant cases. */
586 : case COMPLEX_CST: return TS_COMPLEX;
587 285722 : case FIXED_CST: return TS_FIXED_CST;
588 690056437 : case INTEGER_CST: return TS_INT_CST;
589 285722 : case POLY_INT_CST: return TS_POLY_INT_CST;
590 42249550 : case REAL_CST: return TS_REAL_CST;
591 239132106 : case STRING_CST: return TS_STRING;
592 11672078 : case VECTOR_CST: return TS_VECTOR;
593 1005718 : case VOID_CST: return TS_TYPED;
594 285890 : case RAW_DATA_CST: return TS_RAW_DATA_CST;
595 :
596 : /* tcc_exceptional cases. */
597 701403518 : case BLOCK: return TS_BLOCK;
598 139148553 : case CONSTRUCTOR: return TS_CONSTRUCTOR;
599 : case ERROR_MARK: return TS_COMMON;
600 8837654 : case IDENTIFIER_NODE: return TS_IDENTIFIER;
601 836874 : case OMP_CLAUSE: return TS_OMP_CLAUSE;
602 1738121 : case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
603 : case PLACEHOLDER_EXPR: return TS_COMMON;
604 255353136 : case SSA_NAME: return TS_SSA_NAME;
605 777113218 : case STATEMENT_LIST: return TS_STATEMENT_LIST;
606 3671966 : case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
607 276874722 : case TREE_BINFO: return TS_BINFO;
608 9605958042 : case TREE_LIST: return TS_LIST;
609 2161114087 : case TREE_VEC: return TS_VEC;
610 :
611 0 : default:
612 0 : gcc_unreachable ();
613 : }
614 : }
615 :
616 :
617 : /* Initialize tree_contains_struct to describe the hierarchy of tree
618 : nodes. */
619 :
620 : static void
621 285722 : initialize_tree_contains_struct (void)
622 : {
623 285722 : unsigned i;
624 :
625 70287612 : for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
626 : {
627 70001890 : enum tree_code code;
628 70001890 : enum tree_node_structure_enum ts_code;
629 :
630 70001890 : code = (enum tree_code) i;
631 70001890 : ts_code = tree_node_structure_for_code (code);
632 :
633 : /* Mark the TS structure itself. */
634 70001890 : tree_contains_struct[code][ts_code] = 1;
635 :
636 : /* Mark all the structures that TS is derived from. */
637 70001890 : switch (ts_code)
638 : {
639 1142888 : case TS_TYPED:
640 1142888 : case TS_BLOCK:
641 1142888 : case TS_OPTIMIZATION:
642 1142888 : case TS_TARGET_OPTION:
643 1142888 : MARK_TS_BASE (code);
644 1142888 : break;
645 :
646 57715844 : case TS_COMMON:
647 57715844 : case TS_INT_CST:
648 57715844 : case TS_POLY_INT_CST:
649 57715844 : case TS_REAL_CST:
650 57715844 : case TS_FIXED_CST:
651 57715844 : case TS_VECTOR:
652 57715844 : case TS_STRING:
653 57715844 : case TS_RAW_DATA_CST:
654 57715844 : case TS_COMPLEX:
655 57715844 : case TS_SSA_NAME:
656 57715844 : case TS_CONSTRUCTOR:
657 57715844 : case TS_EXP:
658 57715844 : case TS_STATEMENT_LIST:
659 57715844 : MARK_TS_TYPED (code);
660 57715844 : break;
661 :
662 1428610 : case TS_IDENTIFIER:
663 1428610 : case TS_DECL_MINIMAL:
664 1428610 : case TS_TYPE_COMMON:
665 1428610 : case TS_LIST:
666 1428610 : case TS_VEC:
667 1428610 : case TS_BINFO:
668 1428610 : case TS_OMP_CLAUSE:
669 1428610 : MARK_TS_COMMON (code);
670 1428610 : break;
671 :
672 0 : case TS_TYPE_WITH_LANG_SPECIFIC:
673 0 : MARK_TS_TYPE_COMMON (code);
674 0 : break;
675 :
676 6000162 : case TS_TYPE_NON_COMMON:
677 6000162 : MARK_TS_TYPE_WITH_LANG_SPECIFIC (code);
678 6000162 : break;
679 :
680 0 : case TS_DECL_COMMON:
681 0 : MARK_TS_DECL_MINIMAL (code);
682 0 : break;
683 :
684 571444 : case TS_DECL_WRTL:
685 571444 : case TS_CONST_DECL:
686 571444 : MARK_TS_DECL_COMMON (code);
687 571444 : break;
688 :
689 857166 : case TS_DECL_NON_COMMON:
690 857166 : MARK_TS_DECL_WITH_VIS (code);
691 857166 : break;
692 :
693 857166 : case TS_DECL_WITH_VIS:
694 857166 : case TS_PARM_DECL:
695 857166 : case TS_LABEL_DECL:
696 857166 : case TS_RESULT_DECL:
697 857166 : MARK_TS_DECL_WRTL (code);
698 857166 : break;
699 :
700 285722 : case TS_FIELD_DECL:
701 285722 : MARK_TS_DECL_COMMON (code);
702 285722 : break;
703 :
704 285722 : case TS_VAR_DECL:
705 285722 : MARK_TS_DECL_WITH_VIS (code);
706 285722 : break;
707 :
708 571444 : case TS_TYPE_DECL:
709 571444 : case TS_FUNCTION_DECL:
710 571444 : MARK_TS_DECL_NON_COMMON (code);
711 571444 : break;
712 :
713 285722 : case TS_TRANSLATION_UNIT_DECL:
714 285722 : MARK_TS_DECL_COMMON (code);
715 285722 : break;
716 :
717 : default:
718 : gcc_unreachable ();
719 : }
720 : }
721 :
722 : /* Basic consistency checks for attributes used in fold. */
723 285722 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
724 285722 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
725 285722 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
726 285722 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
727 285722 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
728 285722 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
729 285722 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
730 285722 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
731 285722 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
732 285722 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
733 285722 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
734 285722 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
735 285722 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
736 285722 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
737 285722 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
738 285722 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
739 285722 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
740 285722 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
741 285722 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
742 285722 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
743 285722 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
744 285722 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
745 285722 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
746 285722 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
747 285722 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
748 285722 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
749 285722 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
750 285722 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
751 285722 : gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
752 285722 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
753 285722 : gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
754 285722 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
755 285722 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
756 285722 : gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
757 285722 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
758 285722 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
759 285722 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
760 285722 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
761 285722 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_MINIMAL]);
762 285722 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_COMMON]);
763 285722 : }
764 :
765 :
766 : /* Init tree.cc. */
767 :
768 : void
769 285722 : init_ttree (void)
770 : {
771 : /* Initialize the hash table of types. */
772 285722 : type_hash_table
773 285722 : = hash_table<type_cache_hasher>::create_ggc (TYPE_HASH_INITIAL_SIZE);
774 :
775 285722 : debug_expr_for_decl
776 285722 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
777 :
778 285722 : value_expr_for_decl
779 285722 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
780 :
781 285722 : int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024);
782 :
783 285722 : poly_int_cst_hash_table = hash_table<poly_int_cst_hasher>::create_ggc (64);
784 :
785 285722 : int_cst_node = make_int_cst (1, 1);
786 :
787 285722 : cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64);
788 :
789 285722 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
790 285722 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
791 :
792 : /* Initialize the tree_contains_struct array. */
793 285722 : initialize_tree_contains_struct ();
794 285722 : lang_hooks.init_ts ();
795 285722 : }
796 :
797 :
798 : /* Mapping from prefix to label number. */
799 :
800 : struct identifier_hash : ggc_ptr_hash <tree_node>
801 : {
802 38546 : static inline hashval_t hash (tree t)
803 : {
804 38546 : return IDENTIFIER_HASH_VALUE (t);
805 : }
806 : };
807 : struct identifier_count_traits
808 : : simple_hashmap_traits<identifier_hash, long> {};
809 : typedef hash_map<tree, long, identifier_count_traits> internal_label_map;
810 : static GTY(()) internal_label_map *internal_label_nums;
811 :
812 : /* Generates an identifier intended to be used internally with the
813 : given PREFIX. This is intended to be used by the frontend so that
814 : C++ modules can regenerate appropriate (non-clashing) identifiers on
815 : stream-in. */
816 :
817 : tree
818 35974 : generate_internal_label (const char *prefix)
819 : {
820 35974 : tree prefix_id = get_identifier (prefix);
821 35974 : if (!internal_label_nums)
822 2839 : internal_label_nums = internal_label_map::create_ggc();
823 35974 : long &num = internal_label_nums->get_or_insert (prefix_id);
824 :
825 35974 : char tmp[32];
826 35974 : ASM_GENERATE_INTERNAL_LABEL (tmp, prefix, num++);
827 :
828 35974 : tree id = get_identifier (tmp);
829 35974 : IDENTIFIER_INTERNAL_P (id) = true;
830 :
831 : /* Cache the prefix on the identifier so we can retrieve it later. */
832 35974 : TREE_CHAIN (id) = prefix_id;
833 :
834 35974 : return id;
835 : }
836 :
837 : /* Get the PREFIX we created the internal identifier LABEL with. */
838 :
839 : const char *
840 7 : prefix_for_internal_label (tree label)
841 : {
842 7 : gcc_assert (IDENTIFIER_INTERNAL_P (label)
843 : && !IDENTIFIER_TRANSPARENT_ALIAS (label)
844 : && TREE_CHAIN (label)
845 : && TREE_CODE (TREE_CHAIN (label)) == IDENTIFIER_NODE);
846 7 : return IDENTIFIER_POINTER (TREE_CHAIN (label));
847 : }
848 :
849 : /* The name of the object as the assembler will see it (but before any
850 : translations made by ASM_OUTPUT_LABELREF). Often this is the same
851 : as DECL_NAME. It is an IDENTIFIER_NODE. */
852 : tree
853 1754523502 : decl_assembler_name (tree decl)
854 : {
855 1754523502 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
856 178669130 : lang_hooks.set_decl_assembler_name (decl);
857 1754523502 : return DECL_ASSEMBLER_NAME_RAW (decl);
858 : }
859 :
860 : /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
861 : (either of which may be NULL). Inform the FE, if this changes the
862 : name. */
863 :
864 : void
865 938888189 : overwrite_decl_assembler_name (tree decl, tree name)
866 : {
867 938888189 : if (DECL_ASSEMBLER_NAME_RAW (decl) != name)
868 452083201 : lang_hooks.overwrite_decl_assembler_name (decl, name);
869 938888189 : }
870 :
871 : /* Return true if DECL may need an assembler name to be set. */
872 :
873 : static inline bool
874 4982243 : need_assembler_name_p (tree decl)
875 : {
876 : /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
877 : Rule merging. This makes type_odr_p to return true on those types during
878 : LTO and by comparing the mangled name, we can say what types are intended
879 : to be equivalent across compilation unit.
880 :
881 : We do not store names of type_in_anonymous_namespace_p.
882 :
883 : Record, union and enumeration type have linkage that allows use
884 : to check type_in_anonymous_namespace_p. We do not mangle compound types
885 : that always can be compared structurally.
886 :
887 : Similarly for builtin types, we compare properties of their main variant.
888 : A special case are integer types where mangling do make differences
889 : between char/signed char/unsigned char etc. Storing name for these makes
890 : e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
891 : See cp/mangle.cc:write_builtin_type for details. */
892 :
893 4982243 : if (TREE_CODE (decl) == TYPE_DECL)
894 : {
895 155094 : if (DECL_NAME (decl)
896 125874 : && decl == TYPE_NAME (TREE_TYPE (decl))
897 125719 : && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
898 106891 : && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
899 103871 : && ((TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
900 86453 : && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE)
901 17662 : || TYPE_CXX_ODR_P (TREE_TYPE (decl)))
902 102472 : && (type_with_linkage_p (TREE_TYPE (decl))
903 87995 : || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
904 223179 : && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
905 68085 : return !DECL_ASSEMBLER_NAME_SET_P (decl);
906 87009 : return false;
907 : }
908 : /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
909 4827149 : if (!VAR_OR_FUNCTION_DECL_P (decl))
910 : return false;
911 :
912 : /* If DECL already has its assembler name set, it does not need a
913 : new one. */
914 4152627 : if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
915 4152627 : || DECL_ASSEMBLER_NAME_SET_P (decl))
916 : return false;
917 :
918 : /* Abstract decls do not need an assembler name, except they
919 : can be looked up by autofdo. */
920 1609109 : if (DECL_ABSTRACT_P (decl) && !flag_auto_profile)
921 : return false;
922 :
923 : /* For VAR_DECLs, only static, public and external symbols need an
924 : assembler name. */
925 1607850 : if (VAR_P (decl)
926 539323 : && !TREE_STATIC (decl)
927 539001 : && !TREE_PUBLIC (decl)
928 2146851 : && !DECL_EXTERNAL (decl))
929 : return false;
930 :
931 1068849 : if (TREE_CODE (decl) == FUNCTION_DECL)
932 : {
933 : /* Do not set assembler name on builtins. Allow RTL expansion to
934 : decide whether to expand inline or via a regular call. */
935 1068527 : if (fndecl_built_in_p (decl)
936 1068527 : && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
937 : return false;
938 :
939 : /* Functions represented in the callgraph need an assembler name. */
940 1063818 : if (cgraph_node::get (decl) != NULL)
941 : return true;
942 :
943 : /* Unused and not public functions don't need an assembler name. */
944 3278 : if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
945 : return false;
946 : }
947 :
948 : return true;
949 : }
950 :
951 : /* If T needs an assembler name, have one created for it. */
952 :
953 : void
954 4982243 : assign_assembler_name_if_needed (tree t)
955 : {
956 4982243 : if (need_assembler_name_p (t))
957 : {
958 : /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
959 : diagnostics that use input_location to show locus
960 : information. The problem here is that, at this point,
961 : input_location is generally anchored to the end of the file
962 : (since the parser is long gone), so we don't have a good
963 : position to pin it to.
964 :
965 : To alleviate this problem, this uses the location of T's
966 : declaration. Examples of this are
967 : testsuite/g++.dg/template/cond2.C and
968 : testsuite/g++.dg/template/pr35240.C. */
969 1132199 : location_t saved_location = input_location;
970 1132199 : input_location = DECL_SOURCE_LOCATION (t);
971 :
972 1132199 : decl_assembler_name (t);
973 :
974 1132199 : input_location = saved_location;
975 : }
976 4982243 : }
977 :
978 : /* When the target supports COMDAT groups, this indicates which group the
979 : DECL is associated with. This can be either an IDENTIFIER_NODE or a
980 : decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
981 : tree
982 381065762 : decl_comdat_group (const_tree node)
983 : {
984 381065762 : struct symtab_node *snode = symtab_node::get (node);
985 381065762 : if (!snode)
986 : return NULL;
987 364620330 : return snode->get_comdat_group ();
988 : }
989 :
990 : /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
991 : tree
992 11846 : decl_comdat_group_id (const_tree node)
993 : {
994 11846 : struct symtab_node *snode = symtab_node::get (node);
995 11846 : if (!snode)
996 : return NULL;
997 11846 : return snode->get_comdat_group_id ();
998 : }
999 :
1000 : /* When the target supports named section, return its name as IDENTIFIER_NODE
1001 : or NULL if it is in no section. */
1002 : const char *
1003 731420558 : decl_section_name (const_tree node)
1004 : {
1005 731420558 : struct symtab_node *snode = symtab_node::get (node);
1006 731420558 : if (!snode)
1007 : return NULL;
1008 539492249 : return snode->get_section ();
1009 : }
1010 :
1011 : /* Set section name of NODE to VALUE (that is expected to be
1012 : identifier node) */
1013 : void
1014 1798500 : set_decl_section_name (tree node, const char *value)
1015 : {
1016 1798500 : struct symtab_node *snode;
1017 :
1018 1798500 : if (value == NULL)
1019 : {
1020 48 : snode = symtab_node::get (node);
1021 48 : if (!snode)
1022 : return;
1023 : }
1024 1798452 : else if (VAR_P (node))
1025 1553021 : snode = varpool_node::get_create (node);
1026 : else
1027 245431 : snode = cgraph_node::get_create (node);
1028 1798500 : snode->set_section (value);
1029 : }
1030 :
1031 : /* Set section name of NODE to match the section name of OTHER.
1032 :
1033 : set_decl_section_name (decl, other) is equivalent to
1034 : set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more
1035 : efficient. */
1036 : void
1037 17572107 : set_decl_section_name (tree decl, const_tree other)
1038 : {
1039 17572107 : struct symtab_node *other_node = symtab_node::get (other);
1040 17572107 : if (other_node)
1041 : {
1042 17566438 : struct symtab_node *decl_node;
1043 17566438 : if (VAR_P (decl))
1044 23 : decl_node = varpool_node::get_create (decl);
1045 : else
1046 17566415 : decl_node = cgraph_node::get_create (decl);
1047 17566438 : decl_node->set_section (*other_node);
1048 : }
1049 : else
1050 : {
1051 5669 : struct symtab_node *decl_node = symtab_node::get (decl);
1052 5669 : if (!decl_node)
1053 : return;
1054 0 : decl_node->set_section (NULL);
1055 : }
1056 : }
1057 :
1058 : /* Return TLS model of a variable NODE. */
1059 : enum tls_model
1060 272626821 : decl_tls_model (const_tree node)
1061 : {
1062 272626821 : struct varpool_node *snode = varpool_node::get (node);
1063 272626821 : if (!snode)
1064 : return TLS_MODEL_NONE;
1065 223752912 : return snode->tls_model;
1066 : }
1067 :
1068 : /* Set TLS model of variable NODE to MODEL. */
1069 : void
1070 55808 : set_decl_tls_model (tree node, enum tls_model model)
1071 : {
1072 55808 : struct varpool_node *vnode;
1073 :
1074 55808 : if (model == TLS_MODEL_NONE)
1075 : {
1076 5944 : vnode = varpool_node::get (node);
1077 5944 : if (!vnode)
1078 : return;
1079 : }
1080 : else
1081 49864 : vnode = varpool_node::get_create (node);
1082 49864 : vnode->tls_model = model;
1083 : }
1084 :
1085 : /* Compute the number of bytes occupied by a tree with code CODE.
1086 : This function cannot be used for nodes that have variable sizes,
1087 : including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
1088 : size_t
1089 19186925313 : tree_code_size (enum tree_code code)
1090 : {
1091 19186925313 : switch (TREE_CODE_CLASS (code))
1092 : {
1093 4543977827 : case tcc_declaration: /* A decl node */
1094 4543977827 : switch (code)
1095 : {
1096 : case FIELD_DECL: return sizeof (tree_field_decl);
1097 : case PARM_DECL: return sizeof (tree_parm_decl);
1098 296600713 : case VAR_DECL: return sizeof (tree_var_decl);
1099 : case LABEL_DECL: return sizeof (tree_label_decl);
1100 : case RESULT_DECL: return sizeof (tree_result_decl);
1101 29642966 : case CONST_DECL: return sizeof (tree_const_decl);
1102 : case TYPE_DECL: return sizeof (tree_type_decl);
1103 1434961110 : case FUNCTION_DECL: return sizeof (tree_function_decl);
1104 : case DEBUG_EXPR_DECL: return sizeof (tree_decl_with_rtl);
1105 : case TRANSLATION_UNIT_DECL: return sizeof (tree_translation_unit_decl);
1106 : case NAMESPACE_DECL:
1107 : case IMPORTED_DECL:
1108 : case NAMELIST_DECL: return sizeof (tree_decl_non_common);
1109 282346475 : default:
1110 282346475 : gcc_checking_assert (code >= NUM_TREE_CODES);
1111 282346475 : return lang_hooks.tree_size (code);
1112 : }
1113 :
1114 3154329733 : case tcc_type: /* a type node */
1115 3154329733 : switch (code)
1116 : {
1117 : case OFFSET_TYPE:
1118 : case ENUMERAL_TYPE:
1119 : case BOOLEAN_TYPE:
1120 : case INTEGER_TYPE:
1121 : case REAL_TYPE:
1122 : case OPAQUE_TYPE:
1123 : case POINTER_TYPE:
1124 : case REFERENCE_TYPE:
1125 : case NULLPTR_TYPE:
1126 : case FIXED_POINT_TYPE:
1127 : case COMPLEX_TYPE:
1128 : case VECTOR_TYPE:
1129 : case ARRAY_TYPE:
1130 : case RECORD_TYPE:
1131 : case UNION_TYPE:
1132 : case QUAL_UNION_TYPE:
1133 : case VOID_TYPE:
1134 : case FUNCTION_TYPE:
1135 : case METHOD_TYPE:
1136 : case BITINT_TYPE:
1137 : case LANG_TYPE: return sizeof (tree_type_non_common);
1138 758923210 : default:
1139 758923210 : gcc_checking_assert (code >= NUM_TREE_CODES);
1140 758923210 : return lang_hooks.tree_size (code);
1141 : }
1142 :
1143 5504110712 : case tcc_reference: /* a reference */
1144 5504110712 : case tcc_expression: /* an expression */
1145 5504110712 : case tcc_statement: /* an expression with side effects */
1146 5504110712 : case tcc_comparison: /* a comparison expression */
1147 5504110712 : case tcc_unary: /* a unary arithmetic expression */
1148 5504110712 : case tcc_binary: /* a binary arithmetic expression */
1149 5504110712 : return (sizeof (struct tree_exp)
1150 5504110712 : + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
1151 :
1152 42764489 : case tcc_constant: /* a constant */
1153 42764489 : switch (code)
1154 : {
1155 : case VOID_CST: return sizeof (tree_typed);
1156 0 : case INTEGER_CST: gcc_unreachable ();
1157 : case POLY_INT_CST: return sizeof (tree_poly_int_cst);
1158 41923363 : case REAL_CST: return sizeof (tree_real_cst);
1159 : case FIXED_CST: return sizeof (tree_fixed_cst);
1160 : case COMPLEX_CST: return sizeof (tree_complex);
1161 : case RAW_DATA_CST: return sizeof (tree_raw_data);
1162 0 : case VECTOR_CST: gcc_unreachable ();
1163 0 : case STRING_CST: gcc_unreachable ();
1164 61758 : default:
1165 61758 : gcc_checking_assert (code >= NUM_TREE_CODES);
1166 61758 : return lang_hooks.tree_size (code);
1167 : }
1168 :
1169 5941742552 : case tcc_exceptional: /* something random, like an identifier. */
1170 5941742552 : switch (code)
1171 : {
1172 1695418056 : case IDENTIFIER_NODE: return lang_hooks.identifier_size;
1173 : case TREE_LIST: return sizeof (tree_list);
1174 :
1175 : case ERROR_MARK:
1176 : case PLACEHOLDER_EXPR: return sizeof (tree_common);
1177 :
1178 0 : case TREE_VEC: gcc_unreachable ();
1179 0 : case OMP_CLAUSE: gcc_unreachable ();
1180 :
1181 : case SSA_NAME: return sizeof (tree_ssa_name);
1182 :
1183 : case STATEMENT_LIST: return sizeof (tree_statement_list);
1184 315558664 : case BLOCK: return sizeof (struct tree_block);
1185 : case CONSTRUCTOR: return sizeof (tree_constructor);
1186 : case OPTIMIZATION_NODE: return sizeof (tree_optimization_option);
1187 : case TARGET_OPTION_NODE: return sizeof (tree_target_option);
1188 :
1189 1690569348 : default:
1190 1690569348 : gcc_checking_assert (code >= NUM_TREE_CODES);
1191 1690569348 : return lang_hooks.tree_size (code);
1192 : }
1193 :
1194 0 : default:
1195 0 : gcc_unreachable ();
1196 : }
1197 : }
1198 :
1199 : /* Compute the number of bytes occupied by NODE. This routine only
1200 : looks at TREE_CODE, except for those nodes that have variable sizes. */
1201 : size_t
1202 4879826090 : tree_size (const_tree node)
1203 : {
1204 4879826090 : const enum tree_code code = TREE_CODE (node);
1205 4879826090 : switch (code)
1206 : {
1207 527697 : case INTEGER_CST:
1208 527697 : return (sizeof (struct tree_int_cst)
1209 527697 : + (TREE_INT_CST_EXT_NUNITS (node) - 1) * sizeof (HOST_WIDE_INT));
1210 :
1211 0 : case TREE_BINFO:
1212 0 : return (offsetof (struct tree_binfo, base_binfos)
1213 : + vec<tree, va_gc>
1214 0 : ::embedded_size (BINFO_N_BASE_BINFOS (node)));
1215 :
1216 397361804 : case TREE_VEC:
1217 397361804 : return (sizeof (struct tree_vec)
1218 397361804 : + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
1219 :
1220 0 : case VECTOR_CST:
1221 0 : return (sizeof (struct tree_vector)
1222 0 : + (vector_cst_encoded_nelts (node) - 1) * sizeof (tree));
1223 :
1224 21811 : case STRING_CST:
1225 21811 : return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
1226 :
1227 32702 : case OMP_CLAUSE:
1228 32702 : return (sizeof (struct tree_omp_clause)
1229 32702 : + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
1230 32702 : * sizeof (tree));
1231 :
1232 4481882076 : default:
1233 4481882076 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
1234 227835303 : return (sizeof (struct tree_exp)
1235 227835303 : + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
1236 : else
1237 4254046773 : return tree_code_size (code);
1238 : }
1239 : }
1240 :
1241 : /* Return tree node kind based on tree CODE. */
1242 :
1243 : static tree_node_kind
1244 0 : get_stats_node_kind (enum tree_code code)
1245 : {
1246 0 : enum tree_code_class type = TREE_CODE_CLASS (code);
1247 :
1248 0 : switch (type)
1249 : {
1250 : case tcc_declaration: /* A decl node */
1251 : return d_kind;
1252 0 : case tcc_type: /* a type node */
1253 0 : return t_kind;
1254 0 : case tcc_statement: /* an expression with side effects */
1255 0 : return s_kind;
1256 0 : case tcc_reference: /* a reference */
1257 0 : return r_kind;
1258 : case tcc_expression: /* an expression */
1259 : case tcc_comparison: /* a comparison expression */
1260 : case tcc_unary: /* a unary arithmetic expression */
1261 : case tcc_binary: /* a binary arithmetic expression */
1262 : return e_kind;
1263 0 : case tcc_constant: /* a constant */
1264 0 : return c_kind;
1265 0 : case tcc_exceptional: /* something random, like an identifier. */
1266 0 : switch (code)
1267 : {
1268 : case IDENTIFIER_NODE:
1269 : return id_kind;
1270 0 : case TREE_VEC:
1271 0 : return vec_kind;
1272 0 : case TREE_BINFO:
1273 0 : return binfo_kind;
1274 0 : case SSA_NAME:
1275 0 : return ssa_name_kind;
1276 0 : case BLOCK:
1277 0 : return b_kind;
1278 0 : case CONSTRUCTOR:
1279 0 : return constr_kind;
1280 0 : case OMP_CLAUSE:
1281 0 : return omp_clause_kind;
1282 0 : default:
1283 0 : return x_kind;
1284 : }
1285 : break;
1286 : case tcc_vl_exp:
1287 : return e_kind;
1288 0 : default:
1289 0 : gcc_unreachable ();
1290 : }
1291 : }
1292 :
1293 : /* Record interesting allocation statistics for a tree node with CODE
1294 : and LENGTH. */
1295 :
1296 : static void
1297 0 : record_node_allocation_statistics (enum tree_code code, size_t length)
1298 : {
1299 0 : if (!GATHER_STATISTICS)
1300 0 : return;
1301 :
1302 : tree_node_kind kind = get_stats_node_kind (code);
1303 :
1304 : tree_code_counts[(int) code]++;
1305 : tree_node_counts[(int) kind]++;
1306 : tree_node_sizes[(int) kind] += length;
1307 : }
1308 :
1309 : /* Allocate and return a new UID from the DECL_UID namespace. */
1310 :
1311 : int
1312 4537607245 : allocate_decl_uid (void)
1313 : {
1314 4537607245 : return next_decl_uid++;
1315 : }
1316 :
1317 : /* Return a newly allocated node of code CODE. For decl and type
1318 : nodes, some other fields are initialized. The rest of the node is
1319 : initialized to zero. This function cannot be used for TREE_VEC,
1320 : INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
1321 : tree_code_size.
1322 :
1323 : Achoo! I got a code in the node. */
1324 :
1325 : tree
1326 14927369271 : make_node (enum tree_code code MEM_STAT_DECL)
1327 : {
1328 14927369271 : tree t;
1329 14927369271 : enum tree_code_class type = TREE_CODE_CLASS (code);
1330 14927369271 : size_t length = tree_code_size (code);
1331 :
1332 14927369271 : record_node_allocation_statistics (code, length);
1333 :
1334 14927369271 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1335 14927369271 : TREE_SET_CODE (t, code);
1336 :
1337 14927369271 : switch (type)
1338 : {
1339 779644839 : case tcc_statement:
1340 779644839 : if (code != DEBUG_BEGIN_STMT)
1341 423611146 : TREE_SIDE_EFFECTS (t) = 1;
1342 : break;
1343 :
1344 3181188714 : case tcc_declaration:
1345 3181188714 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1346 : {
1347 3181188714 : if (code == FUNCTION_DECL)
1348 : {
1349 1105596417 : SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
1350 1105596417 : SET_DECL_MODE (t, FUNCTION_MODE);
1351 : }
1352 : else
1353 2075592297 : SET_DECL_ALIGN (t, 1);
1354 : }
1355 3181188714 : DECL_SOURCE_LOCATION (t) = input_location;
1356 3181188714 : if (TREE_CODE (t) == DEBUG_EXPR_DECL)
1357 1902684 : DECL_UID (t) = --next_debug_decl_uid;
1358 : else
1359 : {
1360 3179286030 : DECL_UID (t) = allocate_decl_uid ();
1361 3179286030 : SET_DECL_PT_UID (t, -1);
1362 : }
1363 3181188714 : if (TREE_CODE (t) == LABEL_DECL)
1364 42155641 : LABEL_DECL_UID (t) = -1;
1365 :
1366 : break;
1367 :
1368 2337001799 : case tcc_type:
1369 2337001799 : TYPE_UID (t) = next_type_uid++;
1370 2337001799 : SET_TYPE_ALIGN (t, BITS_PER_UNIT);
1371 2337001799 : TYPE_USER_ALIGN (t) = 0;
1372 2337001799 : TYPE_MAIN_VARIANT (t) = t;
1373 2337001799 : TYPE_CANONICAL (t) = t;
1374 :
1375 : /* Default to no attributes for type, but let target change that. */
1376 2337001799 : TYPE_ATTRIBUTES (t) = NULL_TREE;
1377 2337001799 : targetm.set_default_type_attributes (t);
1378 :
1379 : /* We have not yet computed the alias set for this type. */
1380 2337001799 : TYPE_ALIAS_SET (t) = -1;
1381 2337001799 : break;
1382 :
1383 42762769 : case tcc_constant:
1384 42762769 : TREE_CONSTANT (t) = 1;
1385 42762769 : break;
1386 :
1387 1426575670 : case tcc_expression:
1388 1426575670 : switch (code)
1389 : {
1390 319308117 : case INIT_EXPR:
1391 319308117 : case MODIFY_EXPR:
1392 319308117 : case VA_ARG_EXPR:
1393 319308117 : case PREDECREMENT_EXPR:
1394 319308117 : case PREINCREMENT_EXPR:
1395 319308117 : case POSTDECREMENT_EXPR:
1396 319308117 : case POSTINCREMENT_EXPR:
1397 : /* All of these have side-effects, no matter what their
1398 : operands are. */
1399 319308117 : TREE_SIDE_EFFECTS (t) = 1;
1400 319308117 : break;
1401 :
1402 : default:
1403 : break;
1404 : }
1405 : break;
1406 :
1407 5721372814 : case tcc_exceptional:
1408 5721372814 : switch (code)
1409 : {
1410 1078405 : case TARGET_OPTION_NODE:
1411 2156810 : TREE_TARGET_OPTION(t)
1412 1078405 : = ggc_cleared_alloc<struct cl_target_option> ();
1413 1078405 : break;
1414 :
1415 595356 : case OPTIMIZATION_NODE:
1416 1190712 : TREE_OPTIMIZATION (t)
1417 595356 : = ggc_cleared_alloc<struct cl_optimization> ();
1418 595356 : break;
1419 :
1420 : default:
1421 : break;
1422 : }
1423 : break;
1424 :
1425 : default:
1426 : /* Other classes need no special treatment. */
1427 : break;
1428 : }
1429 :
1430 14927369271 : return t;
1431 : }
1432 :
1433 : /* Free tree node. */
1434 :
1435 : void
1436 660314489 : free_node (tree node)
1437 : {
1438 660314489 : enum tree_code code = TREE_CODE (node);
1439 660314489 : if (GATHER_STATISTICS)
1440 : {
1441 : enum tree_node_kind kind = get_stats_node_kind (code);
1442 :
1443 : gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
1444 : gcc_checking_assert (tree_node_counts[(int) kind] != 0);
1445 : gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
1446 :
1447 : tree_code_counts[(int) TREE_CODE (node)]--;
1448 : tree_node_counts[(int) kind]--;
1449 : tree_node_sizes[(int) kind] -= tree_size (node);
1450 : }
1451 660314489 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1452 349 : vec_free (CONSTRUCTOR_ELTS (node));
1453 660314296 : else if (code == BLOCK)
1454 0 : vec_free (BLOCK_NONLOCALIZED_VARS (node));
1455 660314296 : else if (code == TREE_BINFO)
1456 363 : vec_free (BINFO_BASE_ACCESSES (node));
1457 660313933 : else if (code == OPTIMIZATION_NODE)
1458 830 : cl_optimization_option_free (TREE_OPTIMIZATION (node));
1459 660313103 : else if (code == TARGET_OPTION_NODE)
1460 895 : cl_target_option_free (TREE_TARGET_OPTION (node));
1461 660314489 : ggc_free (node);
1462 660314489 : }
1463 :
1464 : /* Return a new node with the same contents as NODE except that its
1465 : TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1466 :
1467 : tree
1468 4797289105 : copy_node (tree node MEM_STAT_DECL)
1469 : {
1470 4797289105 : tree t;
1471 4797289105 : enum tree_code code = TREE_CODE (node);
1472 4797289105 : size_t length;
1473 :
1474 4797289105 : gcc_assert (code != STATEMENT_LIST);
1475 :
1476 4797289105 : length = tree_size (node);
1477 4797289105 : record_node_allocation_statistics (code, length);
1478 4797289105 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
1479 4797289105 : memcpy (t, node, length);
1480 :
1481 4797289105 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
1482 2624170934 : TREE_CHAIN (t) = 0;
1483 4797289105 : TREE_ASM_WRITTEN (t) = 0;
1484 4797289105 : TREE_VISITED (t) = 0;
1485 :
1486 4797289105 : if (TREE_CODE_CLASS (code) == tcc_declaration)
1487 : {
1488 1357279844 : if (code == DEBUG_EXPR_DECL)
1489 0 : DECL_UID (t) = --next_debug_decl_uid;
1490 : else
1491 : {
1492 1357279844 : DECL_UID (t) = allocate_decl_uid ();
1493 1357279844 : if (DECL_PT_UID_SET_P (node))
1494 3482 : SET_DECL_PT_UID (t, DECL_PT_UID (node));
1495 : }
1496 680809353 : if ((TREE_CODE (node) == PARM_DECL || VAR_P (node))
1497 1452408572 : && DECL_HAS_VALUE_EXPR_P (node))
1498 : {
1499 2092380 : SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
1500 2092380 : DECL_HAS_VALUE_EXPR_P (t) = 1;
1501 : }
1502 : /* DECL_DEBUG_EXPR is copied explicitly by callers. */
1503 1357279844 : if (VAR_P (node))
1504 : {
1505 95128728 : DECL_HAS_DEBUG_EXPR_P (t) = 0;
1506 95128728 : t->decl_with_vis.symtab_node = NULL;
1507 : }
1508 1357279844 : if (VAR_P (node) && DECL_HAS_INIT_PRIORITY_P (node))
1509 : {
1510 0 : SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
1511 0 : DECL_HAS_INIT_PRIORITY_P (t) = 1;
1512 : }
1513 1357279844 : if (TREE_CODE (node) == FUNCTION_DECL)
1514 : {
1515 324452335 : DECL_STRUCT_FUNCTION (t) = NULL;
1516 324452335 : t->decl_with_vis.symtab_node = NULL;
1517 : }
1518 : }
1519 3440009261 : else if (TREE_CODE_CLASS (code) == tcc_type)
1520 : {
1521 817327934 : TYPE_UID (t) = next_type_uid++;
1522 : /* The following is so that the debug code for
1523 : the copy is different from the original type.
1524 : The two statements usually duplicate each other
1525 : (because they clear fields of the same union),
1526 : but the optimizer should catch that. */
1527 817327934 : TYPE_SYMTAB_ADDRESS (t) = 0;
1528 817327934 : TYPE_SYMTAB_DIE (t) = 0;
1529 :
1530 : /* Do not copy the values cache. */
1531 817327934 : if (TYPE_CACHED_VALUES_P (t))
1532 : {
1533 19712787 : TYPE_CACHED_VALUES_P (t) = 0;
1534 19712787 : TYPE_CACHED_VALUES (t) = NULL_TREE;
1535 : }
1536 : }
1537 2622681327 : else if (code == TARGET_OPTION_NODE)
1538 : {
1539 0 : TREE_TARGET_OPTION (t) = ggc_alloc<struct cl_target_option>();
1540 0 : memcpy (TREE_TARGET_OPTION (t), TREE_TARGET_OPTION (node),
1541 : sizeof (struct cl_target_option));
1542 : }
1543 2622681327 : else if (code == OPTIMIZATION_NODE)
1544 : {
1545 0 : TREE_OPTIMIZATION (t) = ggc_alloc<struct cl_optimization>();
1546 0 : memcpy (TREE_OPTIMIZATION (t), TREE_OPTIMIZATION (node),
1547 : sizeof (struct cl_optimization));
1548 : }
1549 :
1550 4797289105 : return t;
1551 : }
1552 :
1553 : /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1554 : For example, this can copy a list made of TREE_LIST nodes. */
1555 :
1556 : tree
1557 170723228 : copy_list (tree list)
1558 : {
1559 170723228 : tree head;
1560 170723228 : tree prev, next;
1561 :
1562 170723228 : if (list == 0)
1563 : return 0;
1564 :
1565 165636180 : head = prev = copy_node (list);
1566 165636180 : next = TREE_CHAIN (list);
1567 321491022 : while (next)
1568 : {
1569 155854842 : TREE_CHAIN (prev) = copy_node (next);
1570 155854842 : prev = TREE_CHAIN (prev);
1571 155854842 : next = TREE_CHAIN (next);
1572 : }
1573 : return head;
1574 : }
1575 :
1576 :
1577 : /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1578 : INTEGER_CST with value CST and type TYPE. */
1579 :
1580 : static unsigned int
1581 11471231686 : get_int_cst_ext_nunits (tree type, const wide_int &cst)
1582 : {
1583 11471231686 : gcc_checking_assert (cst.get_precision () == TYPE_PRECISION (type));
1584 : /* We need extra HWIs if CST is an unsigned integer with its
1585 : upper bit set. */
1586 11471231686 : if (TYPE_UNSIGNED (type) && wi::neg_p (cst))
1587 190056477 : return cst.get_precision () / HOST_BITS_PER_WIDE_INT + 1;
1588 11281175209 : return cst.get_len ();
1589 : }
1590 :
1591 : /* Return a new INTEGER_CST with value CST and type TYPE. */
1592 :
1593 : static tree
1594 134189522 : build_new_int_cst (tree type, const wide_int &cst)
1595 : {
1596 134189522 : unsigned int len = cst.get_len ();
1597 134189522 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1598 134189522 : tree nt = make_int_cst (len, ext_len);
1599 :
1600 134189522 : if (len < ext_len)
1601 : {
1602 69186125 : --ext_len;
1603 138372250 : TREE_INT_CST_ELT (nt, ext_len)
1604 69186125 : = zext_hwi (-1, cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1605 93296060 : for (unsigned int i = len; i < ext_len; ++i)
1606 24109935 : TREE_INT_CST_ELT (nt, i) = -1;
1607 : }
1608 65003397 : else if (TYPE_UNSIGNED (type)
1609 65003397 : && cst.get_precision () < len * HOST_BITS_PER_WIDE_INT)
1610 : {
1611 14348288 : len--;
1612 28696576 : TREE_INT_CST_ELT (nt, len)
1613 14348288 : = zext_hwi (cst.elt (len),
1614 14348288 : cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1615 : }
1616 :
1617 257340645 : for (unsigned int i = 0; i < len; i++)
1618 123151123 : TREE_INT_CST_ELT (nt, i) = cst.elt (i);
1619 134189522 : TREE_TYPE (nt) = type;
1620 134189522 : return nt;
1621 : }
1622 :
1623 : /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE. */
1624 :
1625 : static tree
1626 0 : build_new_poly_int_cst (tree type, tree (&coeffs)[NUM_POLY_INT_COEFFS]
1627 : CXX_MEM_STAT_INFO)
1628 : {
1629 0 : size_t length = sizeof (struct tree_poly_int_cst);
1630 0 : record_node_allocation_statistics (POLY_INT_CST, length);
1631 :
1632 0 : tree t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1633 :
1634 0 : TREE_SET_CODE (t, POLY_INT_CST);
1635 0 : TREE_CONSTANT (t) = 1;
1636 0 : TREE_TYPE (t) = type;
1637 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1638 0 : POLY_INT_CST_COEFF (t, i) = coeffs[i];
1639 0 : return t;
1640 : }
1641 :
1642 : /* Create a constant tree that contains CST sign-extended to TYPE. */
1643 :
1644 : tree
1645 7646930411 : build_int_cst (tree type, poly_int64 cst)
1646 : {
1647 : /* Support legacy code. */
1648 7646930411 : if (!type)
1649 2896794499 : type = integer_type_node;
1650 :
1651 7646930411 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1652 : }
1653 :
1654 : /* Create a constant tree that contains CST zero-extended to TYPE. */
1655 :
1656 : tree
1657 9398429 : build_int_cstu (tree type, poly_uint64 cst)
1658 : {
1659 9398429 : return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type)));
1660 : }
1661 :
1662 : /* Create a constant tree that contains CST sign-extended to TYPE. */
1663 :
1664 : tree
1665 28488909 : build_int_cst_type (tree type, poly_int64 cst)
1666 : {
1667 28488909 : gcc_assert (type);
1668 28488909 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1669 : }
1670 :
1671 : /* Constructs tree in type TYPE from with value given by CST. Signedness
1672 : of CST is assumed to be the same as the signedness of TYPE. */
1673 :
1674 : tree
1675 7287762 : double_int_to_tree (tree type, double_int cst)
1676 : {
1677 7287762 : return wide_int_to_tree (type, widest_int::from (cst, TYPE_SIGN (type)));
1678 : }
1679 :
1680 : /* We force the wide_int CST to the range of the type TYPE by sign or
1681 : zero extending it. OVERFLOWABLE indicates if we are interested in
1682 : overflow of the value, when >0 we are only interested in signed
1683 : overflow, for <0 we are interested in any overflow. OVERFLOWED
1684 : indicates whether overflow has already occurred. CONST_OVERFLOWED
1685 : indicates whether constant overflow has already occurred. We force
1686 : T's value to be within range of T's type (by setting to 0 or 1 all
1687 : the bits outside the type's range). We set TREE_OVERFLOWED if,
1688 : OVERFLOWED is nonzero,
1689 : or OVERFLOWABLE is >0 and signed overflow occurs
1690 : or OVERFLOWABLE is <0 and any overflow occurs
1691 : We return a new tree node for the extended wide_int. The node
1692 : is shared if no overflow flags are set. */
1693 :
1694 :
1695 : tree
1696 3080440506 : force_fit_type (tree type, const poly_wide_int_ref &cst,
1697 : int overflowable, bool overflowed)
1698 : {
1699 3080440506 : signop sign = TYPE_SIGN (type);
1700 :
1701 : /* If we need to set overflow flags, return a new unshared node. */
1702 3080440506 : if (overflowed || !wi::fits_to_tree_p (cst, type))
1703 : {
1704 6921380 : if (overflowed
1705 6921380 : || overflowable < 0
1706 5661638 : || (overflowable > 0 && sign == SIGNED))
1707 : {
1708 1316378 : poly_wide_int tmp = poly_wide_int::from (cst, TYPE_PRECISION (type),
1709 1316378 : sign);
1710 1316378 : tree t;
1711 1316378 : if (tmp.is_constant ())
1712 1316378 : t = build_new_int_cst (type, tmp.coeffs[0]);
1713 : else
1714 : {
1715 : tree coeffs[NUM_POLY_INT_COEFFS];
1716 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1717 : {
1718 : coeffs[i] = build_new_int_cst (type, tmp.coeffs[i]);
1719 : TREE_OVERFLOW (coeffs[i]) = 1;
1720 : }
1721 : t = build_new_poly_int_cst (type, coeffs);
1722 : }
1723 1316378 : TREE_OVERFLOW (t) = 1;
1724 1316378 : return t;
1725 1316378 : }
1726 : }
1727 :
1728 : /* Else build a shared node. */
1729 3079124128 : return wide_int_to_tree (type, cst);
1730 : }
1731 :
1732 : /* These are the hash table functions for the hash table of INTEGER_CST
1733 : nodes of a sizetype. */
1734 :
1735 : /* Return the hash code X, an INTEGER_CST. */
1736 :
1737 : hashval_t
1738 3250710436 : int_cst_hasher::hash (tree x)
1739 : {
1740 3250710436 : const_tree const t = x;
1741 3250710436 : hashval_t code = TYPE_UID (TREE_TYPE (t));
1742 3250710436 : int i;
1743 :
1744 6508347471 : for (i = 0; i < TREE_INT_CST_NUNITS (t); i++)
1745 3257637035 : code = iterative_hash_host_wide_int (TREE_INT_CST_ELT(t, i), code);
1746 :
1747 3250710436 : return code;
1748 : }
1749 :
1750 : /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1751 : is the same as that given by *Y, which is the same. */
1752 :
1753 : bool
1754 3210241904 : int_cst_hasher::equal (tree x, tree y)
1755 : {
1756 3210241904 : const_tree const xt = x;
1757 3210241904 : const_tree const yt = y;
1758 :
1759 3210241904 : if (TREE_TYPE (xt) != TREE_TYPE (yt)
1760 940018444 : || TREE_INT_CST_NUNITS (xt) != TREE_INT_CST_NUNITS (yt)
1761 4150209035 : || TREE_INT_CST_EXT_NUNITS (xt) != TREE_INT_CST_EXT_NUNITS (yt))
1762 : return false;
1763 :
1764 1280811783 : for (int i = 0; i < TREE_INT_CST_NUNITS (xt); i++)
1765 906977300 : if (TREE_INT_CST_ELT (xt, i) != TREE_INT_CST_ELT (yt, i))
1766 : return false;
1767 :
1768 : return true;
1769 : }
1770 :
1771 : /* Cache wide_int CST into the TYPE_CACHED_VALUES cache for TYPE.
1772 : SLOT is the slot entry to store it in, and MAX_SLOTS is the maximum
1773 : number of slots that can be cached for the type. */
1774 :
1775 : static inline tree
1776 10802996899 : cache_wide_int_in_type_cache (tree type, const wide_int &cst,
1777 : int slot, int max_slots)
1778 : {
1779 10802996899 : gcc_checking_assert (slot >= 0);
1780 : /* Initialize cache. */
1781 10802996899 : if (!TYPE_CACHED_VALUES_P (type))
1782 : {
1783 19823066 : TYPE_CACHED_VALUES_P (type) = 1;
1784 19823066 : TYPE_CACHED_VALUES (type) = make_tree_vec (max_slots);
1785 : }
1786 10802996899 : tree t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot);
1787 10802996899 : if (!t)
1788 : {
1789 : /* Create a new shared int. */
1790 61509592 : t = build_new_int_cst (type, cst);
1791 61509592 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot) = t;
1792 : }
1793 10802996899 : return t;
1794 : }
1795 :
1796 : /* Create an INT_CST node of TYPE and value CST.
1797 : The returned node is always shared. For small integers we use a
1798 : per-type vector cache, for larger ones we use a single hash table.
1799 : The value is extended from its precision according to the sign of
1800 : the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1801 : the upper bits and ensures that hashing and value equality based
1802 : upon the underlying HOST_WIDE_INTs works without masking. */
1803 :
1804 : static tree
1805 11337042164 : wide_int_to_tree_1 (tree type, const wide_int_ref &pcst)
1806 : {
1807 11337042164 : tree t;
1808 11337042164 : int ix = -1;
1809 11337042164 : int limit = 0;
1810 :
1811 11337042164 : gcc_assert (type);
1812 11337042164 : unsigned int prec = TYPE_PRECISION (type);
1813 11337042164 : signop sgn = TYPE_SIGN (type);
1814 :
1815 : /* Verify that everything is canonical. */
1816 11337042164 : int l = pcst.get_len ();
1817 11337042164 : if (l > 1)
1818 : {
1819 3971443 : if (pcst.elt (l - 1) == 0)
1820 1194429 : gcc_checking_assert (pcst.elt (l - 2) < 0);
1821 3971443 : if (pcst.elt (l - 1) == HOST_WIDE_INT_M1)
1822 8091 : gcc_checking_assert (pcst.elt (l - 2) >= 0);
1823 : }
1824 :
1825 11337042164 : wide_int cst = wide_int::from (pcst, prec, sgn);
1826 11337042164 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1827 :
1828 11337042164 : enum tree_code code = TREE_CODE (type);
1829 11337042164 : if (code == POINTER_TYPE || code == REFERENCE_TYPE)
1830 : {
1831 : /* Cache NULL pointer and zero bounds. */
1832 182549524 : if (cst == 0)
1833 : ix = 0;
1834 : /* Cache upper bounds of pointers. */
1835 44326102 : else if (cst == wi::max_value (prec, sgn))
1836 : ix = 1;
1837 : /* Cache 1 which is used for a non-zero range. */
1838 42220706 : else if (cst == 1)
1839 : ix = 2;
1840 :
1841 : if (ix >= 0)
1842 : {
1843 146558319 : t = cache_wide_int_in_type_cache (type, cst, ix, 3);
1844 : /* Make sure no one is clobbering the shared constant. */
1845 146558319 : gcc_checking_assert (TREE_TYPE (t) == type
1846 : && cst == wi::to_wide (t));
1847 146558319 : return t;
1848 : }
1849 : }
1850 11190483845 : if (ext_len == 1)
1851 : {
1852 : /* We just need to store a single HOST_WIDE_INT. */
1853 11119120293 : HOST_WIDE_INT hwi;
1854 11119120293 : if (TYPE_UNSIGNED (type))
1855 7280679641 : hwi = cst.to_uhwi ();
1856 : else
1857 3838441046 : hwi = cst.to_shwi ();
1858 :
1859 11119120293 : switch (code)
1860 : {
1861 220174 : case NULLPTR_TYPE:
1862 220174 : gcc_assert (hwi == 0);
1863 : /* Fallthru. */
1864 :
1865 : case POINTER_TYPE:
1866 : case REFERENCE_TYPE:
1867 : /* Ignore pointers, as they were already handled above. */
1868 : break;
1869 :
1870 117298829 : case BOOLEAN_TYPE:
1871 : /* Cache false or true. */
1872 117298829 : limit = 2;
1873 117298829 : if (IN_RANGE (hwi, 0, 1))
1874 117118817 : ix = hwi;
1875 : break;
1876 :
1877 10950068835 : case INTEGER_TYPE:
1878 10950068835 : case OFFSET_TYPE:
1879 10950068835 : case BITINT_TYPE:
1880 10950068835 : if (TYPE_SIGN (type) == UNSIGNED)
1881 : {
1882 : /* Cache [0, N). */
1883 7117900594 : limit = param_integer_share_limit;
1884 7117900594 : if (IN_RANGE (hwi, 0, param_integer_share_limit - 1))
1885 6852377083 : ix = hwi;
1886 : }
1887 : else
1888 : {
1889 : /* Cache [-1, N). */
1890 3832168241 : limit = param_integer_share_limit + 1;
1891 3832168241 : if (IN_RANGE (hwi, -1, param_integer_share_limit - 1))
1892 3686942680 : ix = hwi + 1;
1893 : }
1894 : break;
1895 :
1896 : case ENUMERAL_TYPE:
1897 : break;
1898 :
1899 0 : default:
1900 0 : gcc_unreachable ();
1901 : }
1902 :
1903 11119120293 : if (ix >= 0)
1904 : {
1905 10656438580 : t = cache_wide_int_in_type_cache (type, cst, ix, limit);
1906 : /* Make sure no one is clobbering the shared constant. */
1907 21312877160 : gcc_checking_assert (TREE_TYPE (t) == type
1908 : && TREE_INT_CST_NUNITS (t) == 1
1909 : && TREE_INT_CST_EXT_NUNITS (t) == 1
1910 : && TREE_INT_CST_ELT (t, 0) == hwi);
1911 : return t;
1912 : }
1913 : else
1914 : {
1915 : /* Use the cache of larger shared ints, using int_cst_node as
1916 : a temporary. */
1917 :
1918 462681713 : TREE_INT_CST_ELT (int_cst_node, 0) = hwi;
1919 462681713 : TREE_TYPE (int_cst_node) = type;
1920 :
1921 462681713 : tree *slot = int_cst_hash_table->find_slot (int_cst_node, INSERT);
1922 462681713 : t = *slot;
1923 462681713 : if (!t)
1924 : {
1925 : /* Insert this one into the hash table. */
1926 148890644 : t = int_cst_node;
1927 148890644 : *slot = t;
1928 : /* Make a new node for next time round. */
1929 148890644 : int_cst_node = make_int_cst (1, 1);
1930 : }
1931 : }
1932 : }
1933 : else
1934 : {
1935 : /* The value either hashes properly or we drop it on the floor
1936 : for the gc to take care of. There will not be enough of them
1937 : to worry about. */
1938 :
1939 71363552 : tree nt = build_new_int_cst (type, cst);
1940 71363552 : tree *slot = int_cst_hash_table->find_slot (nt, INSERT);
1941 71363552 : t = *slot;
1942 71363552 : if (!t)
1943 : {
1944 : /* Insert this one into the hash table. */
1945 12030198 : t = nt;
1946 12030198 : *slot = t;
1947 : }
1948 : else
1949 59333354 : ggc_free (nt);
1950 : }
1951 :
1952 : return t;
1953 11337042164 : }
1954 :
1955 : hashval_t
1956 0 : poly_int_cst_hasher::hash (tree t)
1957 : {
1958 0 : inchash::hash hstate;
1959 :
1960 0 : hstate.add_int (TYPE_UID (TREE_TYPE (t)));
1961 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1962 0 : hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
1963 :
1964 0 : return hstate.end ();
1965 : }
1966 :
1967 : bool
1968 0 : poly_int_cst_hasher::equal (tree x, const compare_type &y)
1969 : {
1970 0 : if (TREE_TYPE (x) != y.first)
1971 : return false;
1972 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1973 0 : if (wi::to_wide (POLY_INT_CST_COEFF (x, i)) != y.second->coeffs[i])
1974 : return false;
1975 : return true;
1976 : }
1977 :
1978 : /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
1979 : The elements must also have type TYPE. */
1980 :
1981 : tree
1982 0 : build_poly_int_cst (tree type, const poly_wide_int_ref &values)
1983 : {
1984 0 : unsigned int prec = TYPE_PRECISION (type);
1985 0 : gcc_assert (prec <= values.coeffs[0].get_precision ());
1986 0 : poly_wide_int c = poly_wide_int::from (values, prec, SIGNED);
1987 :
1988 0 : inchash::hash h;
1989 0 : h.add_int (TYPE_UID (type));
1990 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1991 0 : h.add_wide_int (c.coeffs[i]);
1992 0 : poly_int_cst_hasher::compare_type comp (type, &c);
1993 0 : tree *slot = poly_int_cst_hash_table->find_slot_with_hash (comp, h.end (),
1994 : INSERT);
1995 0 : if (*slot == NULL_TREE)
1996 : {
1997 : tree coeffs[NUM_POLY_INT_COEFFS];
1998 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1999 0 : coeffs[i] = wide_int_to_tree_1 (type, c.coeffs[i]);
2000 0 : *slot = build_new_poly_int_cst (type, coeffs);
2001 : }
2002 0 : return *slot;
2003 0 : }
2004 :
2005 : /* Create a constant tree with value VALUE in type TYPE. */
2006 :
2007 : tree
2008 11337042164 : wide_int_to_tree (tree type, const poly_wide_int_ref &value)
2009 : {
2010 11337042164 : if (value.is_constant ())
2011 11337042164 : return wide_int_to_tree_1 (type, value.coeffs[0]);
2012 : return build_poly_int_cst (type, value);
2013 : }
2014 :
2015 : /* Insert INTEGER_CST T into a cache of integer constants. And return
2016 : the cached constant (which may or may not be T). If MIGHT_DUPLICATE
2017 : is false, and T falls into the type's 'smaller values' range, there
2018 : cannot be an existing entry. Otherwise, if MIGHT_DUPLICATE is true,
2019 : or the value is large, should an existing entry exist, it is
2020 : returned (rather than inserting T). */
2021 :
2022 : tree
2023 582376 : cache_integer_cst (tree t, bool might_duplicate ATTRIBUTE_UNUSED)
2024 : {
2025 582376 : tree type = TREE_TYPE (t);
2026 582376 : int ix = -1;
2027 582376 : int limit = 0;
2028 582376 : int prec = TYPE_PRECISION (type);
2029 :
2030 582376 : gcc_assert (!TREE_OVERFLOW (t));
2031 :
2032 : /* The caching indices here must match those in
2033 : wide_int_to_type_1. */
2034 582376 : switch (TREE_CODE (type))
2035 : {
2036 0 : case NULLPTR_TYPE:
2037 0 : gcc_checking_assert (integer_zerop (t));
2038 : /* Fallthru. */
2039 :
2040 3963 : case POINTER_TYPE:
2041 3963 : case REFERENCE_TYPE:
2042 3963 : {
2043 3963 : if (integer_zerop (t))
2044 : ix = 0;
2045 1639 : else if (integer_onep (t))
2046 : ix = 2;
2047 :
2048 : if (ix >= 0)
2049 : limit = 3;
2050 : }
2051 : break;
2052 :
2053 10524 : case BOOLEAN_TYPE:
2054 : /* Cache false or true. */
2055 10524 : limit = 2;
2056 10524 : if (wi::ltu_p (wi::to_wide (t), 2))
2057 0 : ix = TREE_INT_CST_ELT (t, 0);
2058 : break;
2059 :
2060 553414 : case INTEGER_TYPE:
2061 553414 : case OFFSET_TYPE:
2062 553414 : case BITINT_TYPE:
2063 553414 : if (TYPE_UNSIGNED (type))
2064 : {
2065 : /* Cache 0..N */
2066 417197 : limit = param_integer_share_limit;
2067 :
2068 : /* This is a little hokie, but if the prec is smaller than
2069 : what is necessary to hold param_integer_share_limit, then the
2070 : obvious test will not get the correct answer. */
2071 417197 : if (prec < HOST_BITS_PER_WIDE_INT)
2072 : {
2073 92630 : if (tree_to_uhwi (t)
2074 92630 : < (unsigned HOST_WIDE_INT) param_integer_share_limit)
2075 12531 : ix = tree_to_uhwi (t);
2076 : }
2077 324567 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2078 246820 : ix = tree_to_uhwi (t);
2079 : }
2080 : else
2081 : {
2082 : /* Cache -1..N */
2083 136217 : limit = param_integer_share_limit + 1;
2084 :
2085 136217 : if (integer_minus_onep (t))
2086 : ix = 0;
2087 135811 : else if (!wi::neg_p (wi::to_wide (t)))
2088 : {
2089 119678 : if (prec < HOST_BITS_PER_WIDE_INT)
2090 : {
2091 114240 : if (tree_to_shwi (t) < param_integer_share_limit)
2092 105759 : ix = tree_to_shwi (t) + 1;
2093 : }
2094 5438 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2095 4291 : ix = tree_to_shwi (t) + 1;
2096 : }
2097 : }
2098 : break;
2099 :
2100 : case ENUMERAL_TYPE:
2101 : /* The slot used by TYPE_CACHED_VALUES is used for the enum
2102 : members. */
2103 : break;
2104 :
2105 0 : default:
2106 0 : gcc_unreachable ();
2107 : }
2108 :
2109 371725 : if (ix >= 0)
2110 : {
2111 : /* Look for it in the type's vector of small shared ints. */
2112 372511 : if (!TYPE_CACHED_VALUES_P (type))
2113 : {
2114 13593 : TYPE_CACHED_VALUES_P (type) = 1;
2115 13593 : TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
2116 : }
2117 :
2118 372511 : if (tree r = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix))
2119 : {
2120 347885 : gcc_checking_assert (might_duplicate);
2121 347885 : t = r;
2122 : }
2123 : else
2124 24626 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
2125 : }
2126 : else
2127 : {
2128 : /* Use the cache of larger shared ints. */
2129 209865 : tree *slot = int_cst_hash_table->find_slot (t, INSERT);
2130 209865 : if (tree r = *slot)
2131 : {
2132 : /* If there is already an entry for the number verify it's the
2133 : same value. */
2134 122283 : gcc_checking_assert (wi::to_wide (tree (r)) == wi::to_wide (t));
2135 : /* And return the cached value. */
2136 122283 : t = r;
2137 : }
2138 : else
2139 : /* Otherwise insert this one into the hash table. */
2140 87582 : *slot = t;
2141 : }
2142 :
2143 582376 : return t;
2144 : }
2145 :
2146 :
2147 : /* Builds an integer constant in TYPE such that lowest BITS bits are ones
2148 : and the rest are zeros. */
2149 :
2150 : tree
2151 9493248 : build_low_bits_mask (tree type, unsigned bits)
2152 : {
2153 9493248 : gcc_assert (bits <= TYPE_PRECISION (type));
2154 :
2155 9493248 : return wide_int_to_tree (type, wi::mask (bits, false,
2156 9493248 : TYPE_PRECISION (type)));
2157 : }
2158 :
2159 : /* Checks that X is integer constant that can be expressed in (unsigned)
2160 : HOST_WIDE_INT without loss of precision. */
2161 :
2162 : bool
2163 962367771 : cst_and_fits_in_hwi (const_tree x)
2164 : {
2165 962367771 : return (TREE_CODE (x) == INTEGER_CST
2166 962367771 : && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
2167 : }
2168 :
2169 : /* Build a newly constructed VECTOR_CST with the given values of
2170 : (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN. */
2171 :
2172 : tree
2173 3271978 : make_vector (unsigned log2_npatterns,
2174 : unsigned int nelts_per_pattern MEM_STAT_DECL)
2175 : {
2176 3271978 : gcc_assert (IN_RANGE (nelts_per_pattern, 1, 3));
2177 3271978 : tree t;
2178 3271978 : unsigned npatterns = 1 << log2_npatterns;
2179 3271978 : unsigned encoded_nelts = npatterns * nelts_per_pattern;
2180 3271978 : unsigned length = (sizeof (struct tree_vector)
2181 : + (encoded_nelts - 1) * sizeof (tree));
2182 :
2183 3271978 : record_node_allocation_statistics (VECTOR_CST, length);
2184 :
2185 3271978 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2186 :
2187 3271978 : TREE_SET_CODE (t, VECTOR_CST);
2188 3271978 : TREE_CONSTANT (t) = 1;
2189 3271978 : VECTOR_CST_LOG2_NPATTERNS (t) = log2_npatterns;
2190 3271978 : VECTOR_CST_NELTS_PER_PATTERN (t) = nelts_per_pattern;
2191 :
2192 3271978 : return t;
2193 : }
2194 :
2195 : /* Return a new VECTOR_CST node whose type is TYPE and whose values
2196 : are extracted from V, a vector of CONSTRUCTOR_ELT. */
2197 :
2198 : tree
2199 674632 : build_vector_from_ctor (tree type, const vec<constructor_elt, va_gc> *v)
2200 : {
2201 674632 : if (vec_safe_length (v) == 0)
2202 1863 : return build_zero_cst (type);
2203 :
2204 672769 : unsigned HOST_WIDE_INT idx, nelts, step = 1;
2205 672769 : tree value;
2206 :
2207 : /* If the vector is a VLA, build a VLA constant vector. */
2208 672769 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts))
2209 : {
2210 : nelts = constant_lower_bound (TYPE_VECTOR_SUBPARTS (type));
2211 : gcc_assert (vec_safe_length (v) <= nelts);
2212 : step = 2;
2213 : }
2214 :
2215 672769 : tree_vector_builder vec (type, nelts, step);
2216 4471858 : FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
2217 : {
2218 3799089 : if (TREE_CODE (value) == VECTOR_CST)
2219 : {
2220 : /* If NELTS is constant then this must be too. */
2221 2268 : unsigned int sub_nelts = VECTOR_CST_NELTS (value).to_constant ();
2222 7276 : for (unsigned i = 0; i < sub_nelts; ++i)
2223 5008 : vec.quick_push (VECTOR_CST_ELT (value, i));
2224 : }
2225 : else
2226 3796821 : vec.quick_push (value);
2227 : }
2228 1906016 : while (vec.length () < nelts * step)
2229 280239 : vec.quick_push (build_zero_cst (TREE_TYPE (type)));
2230 :
2231 672769 : return vec.build ();
2232 672769 : }
2233 :
2234 : /* Build a vector of type VECTYPE where all the elements are SCs. */
2235 : tree
2236 634177 : build_vector_from_val (tree vectype, tree sc)
2237 : {
2238 634177 : unsigned HOST_WIDE_INT i, nunits;
2239 :
2240 634177 : if (sc == error_mark_node)
2241 : return sc;
2242 :
2243 : /* Verify that the vector type is suitable for SC. Note that there
2244 : is some inconsistency in the type-system with respect to restrict
2245 : qualifications of pointers. Vector types always have a main-variant
2246 : element type and the qualification is applied to the vector-type.
2247 : So TREE_TYPE (vector-type) does not return a properly qualified
2248 : vector element-type. */
2249 634177 : gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
2250 : TREE_TYPE (vectype)));
2251 :
2252 634177 : if (CONSTANT_CLASS_P (sc))
2253 : {
2254 604056 : tree_vector_builder v (vectype, 1, 1);
2255 604056 : v.quick_push (sc);
2256 604056 : return v.build ();
2257 604056 : }
2258 30121 : else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
2259 : return fold_build1 (VEC_DUPLICATE_EXPR, vectype, sc);
2260 : else
2261 : {
2262 30121 : vec<constructor_elt, va_gc> *v;
2263 30121 : vec_alloc (v, nunits);
2264 144751 : for (i = 0; i < nunits; ++i)
2265 114630 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
2266 30121 : return build_constructor (vectype, v);
2267 : }
2268 : }
2269 :
2270 : /* If TYPE is not a vector type, just return SC, otherwise return
2271 : build_vector_from_val (TYPE, SC). */
2272 :
2273 : tree
2274 5607980 : build_uniform_cst (tree type, tree sc)
2275 : {
2276 5607980 : if (!VECTOR_TYPE_P (type))
2277 : return sc;
2278 :
2279 257 : return build_vector_from_val (type, sc);
2280 : }
2281 :
2282 : /* Build a vector series of type TYPE in which element I has the value
2283 : BASE + I * STEP. The result is a constant if BASE and STEP are constant
2284 : and a VEC_SERIES_EXPR otherwise. */
2285 :
2286 : tree
2287 18 : build_vec_series (tree type, tree base, tree step)
2288 : {
2289 18 : if (integer_zerop (step))
2290 0 : return build_vector_from_val (type, base);
2291 18 : if (TREE_CODE (base) == INTEGER_CST && TREE_CODE (step) == INTEGER_CST)
2292 : {
2293 18 : tree_vector_builder builder (type, 1, 3);
2294 18 : tree elt1 = wide_int_to_tree (TREE_TYPE (base),
2295 36 : wi::to_wide (base) + wi::to_wide (step));
2296 18 : tree elt2 = wide_int_to_tree (TREE_TYPE (base),
2297 36 : wi::to_wide (elt1) + wi::to_wide (step));
2298 18 : builder.quick_push (base);
2299 18 : builder.quick_push (elt1);
2300 18 : builder.quick_push (elt2);
2301 18 : return builder.build ();
2302 18 : }
2303 0 : return build2 (VEC_SERIES_EXPR, type, base, step);
2304 : }
2305 :
2306 : /* Return a vector with the same number of units and number of bits
2307 : as VEC_TYPE, but in which the elements are a linear series of unsigned
2308 : integers { BASE, BASE + STEP, BASE + STEP * 2, ... }. */
2309 :
2310 : tree
2311 1779 : build_index_vector (tree vec_type, poly_uint64 base, poly_uint64 step)
2312 : {
2313 1779 : tree index_vec_type = vec_type;
2314 1779 : tree index_elt_type = TREE_TYPE (vec_type);
2315 1779 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vec_type);
2316 1779 : if (!INTEGRAL_TYPE_P (index_elt_type) || !TYPE_UNSIGNED (index_elt_type))
2317 : {
2318 4 : index_elt_type = build_nonstandard_integer_type
2319 8 : (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type)), true);
2320 4 : index_vec_type = build_vector_type (index_elt_type, nunits);
2321 : }
2322 :
2323 1779 : tree_vector_builder v (index_vec_type, 1, 3);
2324 7116 : for (unsigned int i = 0; i < 3; ++i)
2325 5337 : v.quick_push (build_int_cstu (index_elt_type, base + i * step));
2326 1779 : return v.build ();
2327 1779 : }
2328 :
2329 : /* Return a VECTOR_CST of type VEC_TYPE in which the first NUM_A
2330 : elements are A and the rest are B. */
2331 :
2332 : tree
2333 0 : build_vector_a_then_b (tree vec_type, unsigned int num_a, tree a, tree b)
2334 : {
2335 0 : gcc_assert (known_le (num_a, TYPE_VECTOR_SUBPARTS (vec_type)));
2336 0 : unsigned int count = constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_type));
2337 : /* Optimize the constant case. */
2338 0 : if ((count & 1) == 0 && TYPE_VECTOR_SUBPARTS (vec_type).is_constant ())
2339 0 : count /= 2;
2340 0 : tree_vector_builder builder (vec_type, count, 2);
2341 0 : for (unsigned int i = 0; i < count * 2; ++i)
2342 0 : builder.quick_push (i < num_a ? a : b);
2343 0 : return builder.build ();
2344 0 : }
2345 :
2346 : /* Something has messed with the elements of CONSTRUCTOR C after it was built;
2347 : calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
2348 :
2349 : void
2350 174547777 : recompute_constructor_flags (tree c)
2351 : {
2352 174547777 : unsigned int i;
2353 174547777 : tree val;
2354 174547777 : bool constant_p = true;
2355 174547777 : bool side_effects_p = false;
2356 174547777 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2357 :
2358 362823508 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2359 : {
2360 : /* Mostly ctors will have elts that don't have side-effects, so
2361 : the usual case is to scan all the elements. Hence a single
2362 : loop for both const and side effects, rather than one loop
2363 : each (with early outs). */
2364 188275731 : if (!TREE_CONSTANT (val))
2365 24626948 : constant_p = false;
2366 188275731 : if (TREE_SIDE_EFFECTS (val))
2367 5130849 : side_effects_p = true;
2368 : }
2369 :
2370 174547777 : TREE_SIDE_EFFECTS (c) = side_effects_p;
2371 174547777 : TREE_CONSTANT (c) = constant_p;
2372 174547777 : }
2373 :
2374 : /* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
2375 : CONSTRUCTOR C. */
2376 :
2377 : void
2378 22978850 : verify_constructor_flags (tree c)
2379 : {
2380 22978850 : unsigned int i;
2381 22978850 : tree val;
2382 22978850 : bool constant_p = TREE_CONSTANT (c);
2383 22978850 : bool side_effects_p = TREE_SIDE_EFFECTS (c);
2384 22978850 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2385 :
2386 174746978 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2387 : {
2388 151768128 : if (constant_p && !TREE_CONSTANT (val))
2389 0 : internal_error ("non-constant element in constant CONSTRUCTOR");
2390 151768128 : if (!side_effects_p && TREE_SIDE_EFFECTS (val))
2391 0 : internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
2392 : }
2393 22978850 : }
2394 :
2395 : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2396 : are in the vec pointed to by VALS. */
2397 : tree
2398 150105178 : build_constructor (tree type, vec<constructor_elt, va_gc> *vals MEM_STAT_DECL)
2399 : {
2400 150105178 : tree c = make_node (CONSTRUCTOR PASS_MEM_STAT);
2401 :
2402 150105178 : TREE_TYPE (c) = type;
2403 150105178 : CONSTRUCTOR_ELTS (c) = vals;
2404 :
2405 150105178 : recompute_constructor_flags (c);
2406 :
2407 150105178 : return c;
2408 : }
2409 :
2410 : /* Build a CONSTRUCTOR node made of a single initializer, with the specified
2411 : INDEX and VALUE. */
2412 : tree
2413 5843 : build_constructor_single (tree type, tree index, tree value)
2414 : {
2415 5843 : vec<constructor_elt, va_gc> *v;
2416 5843 : constructor_elt elt = {index, value};
2417 :
2418 5843 : vec_alloc (v, 1);
2419 5843 : v->quick_push (elt);
2420 :
2421 5843 : return build_constructor (type, v);
2422 : }
2423 :
2424 :
2425 : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2426 : are in a list pointed to by VALS. */
2427 : tree
2428 1005 : build_constructor_from_list (tree type, tree vals)
2429 : {
2430 1005 : tree t;
2431 1005 : vec<constructor_elt, va_gc> *v = NULL;
2432 :
2433 1005 : if (vals)
2434 : {
2435 1005 : vec_alloc (v, list_length (vals));
2436 20820 : for (t = vals; t; t = TREE_CHAIN (t))
2437 19815 : CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
2438 : }
2439 :
2440 1005 : return build_constructor (type, v);
2441 : }
2442 :
2443 : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2444 : are in a vector pointed to by VALS. Note that the TREE_PURPOSE
2445 : fields in the constructor remain null. */
2446 :
2447 : tree
2448 1359 : build_constructor_from_vec (tree type, const vec<tree, va_gc> *vals)
2449 : {
2450 1359 : vec<constructor_elt, va_gc> *v = NULL;
2451 :
2452 73453 : for (tree t : vals)
2453 72094 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
2454 :
2455 1359 : return build_constructor (type, v);
2456 : }
2457 :
2458 : /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
2459 : of elements, provided as index/value pairs. */
2460 :
2461 : tree
2462 39033 : build_constructor_va (tree type, int nelts, ...)
2463 : {
2464 39033 : vec<constructor_elt, va_gc> *v = NULL;
2465 39033 : va_list p;
2466 :
2467 39033 : va_start (p, nelts);
2468 39033 : vec_alloc (v, nelts);
2469 39033 : while (nelts--)
2470 : {
2471 116929 : tree index = va_arg (p, tree);
2472 116929 : tree value = va_arg (p, tree);
2473 272891 : CONSTRUCTOR_APPEND_ELT (v, index, value);
2474 : }
2475 39033 : va_end (p);
2476 39033 : return build_constructor (type, v);
2477 : }
2478 :
2479 : /* Return a node of type TYPE for which TREE_CLOBBER_P is true. */
2480 :
2481 : tree
2482 9828399 : build_clobber (tree type, enum clobber_kind kind)
2483 : {
2484 9828399 : tree clobber = build_constructor (type, NULL);
2485 9828399 : TREE_THIS_VOLATILE (clobber) = true;
2486 9828399 : CLOBBER_KIND (clobber) = kind;
2487 9828399 : return clobber;
2488 : }
2489 :
2490 : /* Return a new FIXED_CST node whose type is TYPE and value is F. */
2491 :
2492 : tree
2493 54 : build_fixed (tree type, FIXED_VALUE_TYPE f)
2494 : {
2495 54 : tree v;
2496 54 : FIXED_VALUE_TYPE *fp;
2497 :
2498 54 : v = make_node (FIXED_CST);
2499 54 : fp = ggc_alloc<fixed_value> ();
2500 54 : memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
2501 :
2502 54 : TREE_TYPE (v) = type;
2503 54 : TREE_FIXED_CST_PTR (v) = fp;
2504 54 : return v;
2505 : }
2506 :
2507 : /* Return a new REAL_CST node whose type is TYPE and value is D. */
2508 :
2509 : tree
2510 41802995 : build_real (tree type, REAL_VALUE_TYPE d)
2511 : {
2512 41802995 : tree v;
2513 41802995 : int overflow = 0;
2514 :
2515 : /* dconst{0,1,2,m1,half} are used in various places in
2516 : the middle-end and optimizers, allow them here
2517 : even for decimal floating point types as an exception
2518 : by converting them to decimal. */
2519 41802995 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))
2520 610216 : && (d.cl == rvc_normal || d.cl == rvc_zero)
2521 42411165 : && !d.decimal)
2522 : {
2523 606 : if (memcmp (&d, &dconst1, sizeof (d)) == 0)
2524 0 : decimal_real_from_string (&d, "1");
2525 606 : else if (memcmp (&d, &dconst2, sizeof (d)) == 0)
2526 22 : decimal_real_from_string (&d, "2");
2527 584 : else if (memcmp (&d, &dconstm1, sizeof (d)) == 0)
2528 90 : decimal_real_from_string (&d, "-1");
2529 494 : else if (memcmp (&d, &dconsthalf, sizeof (d)) == 0)
2530 0 : decimal_real_from_string (&d, "0.5");
2531 494 : else if (memcmp (&d, &dconst0, sizeof (d)) == 0)
2532 : {
2533 : /* Make sure to give zero the minimum quantum exponent for
2534 : the type (which corresponds to all bits zero). */
2535 494 : const struct real_format *fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
2536 494 : char buf[16];
2537 494 : sprintf (buf, "0e%d", fmt->emin - fmt->p);
2538 494 : decimal_real_from_string (&d, buf);
2539 : }
2540 : else
2541 0 : gcc_unreachable ();
2542 : }
2543 :
2544 : /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
2545 : Consider doing it via real_convert now. */
2546 :
2547 41802995 : v = make_node (REAL_CST);
2548 41802995 : TREE_TYPE (v) = type;
2549 41802995 : memcpy (TREE_REAL_CST_PTR (v), &d, sizeof (REAL_VALUE_TYPE));
2550 41802995 : TREE_OVERFLOW (v) = overflow;
2551 41802995 : return v;
2552 : }
2553 :
2554 : /* Like build_real, but first truncate D to the type. */
2555 :
2556 : tree
2557 175275 : build_real_truncate (tree type, REAL_VALUE_TYPE d)
2558 : {
2559 175275 : return build_real (type, real_value_truncate (TYPE_MODE (type), d));
2560 : }
2561 :
2562 : /* Return a new REAL_CST node whose type is TYPE
2563 : and whose value is the integer value of the INTEGER_CST node I. */
2564 :
2565 : REAL_VALUE_TYPE
2566 23721695 : real_value_from_int_cst (const_tree type, const_tree i)
2567 : {
2568 23721695 : REAL_VALUE_TYPE d;
2569 :
2570 : /* Clear all bits of the real value type so that we can later do
2571 : bitwise comparisons to see if two values are the same. */
2572 23721695 : memset (&d, 0, sizeof d);
2573 :
2574 23721695 : real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, wi::to_wide (i),
2575 23721695 : TYPE_SIGN (TREE_TYPE (i)));
2576 23721695 : return d;
2577 : }
2578 :
2579 : /* Given a tree representing an integer constant I, return a tree
2580 : representing the same value as a floating-point constant of type TYPE. */
2581 :
2582 : tree
2583 23087955 : build_real_from_int_cst (tree type, const_tree i)
2584 : {
2585 23087955 : tree v;
2586 23087955 : int overflow = TREE_OVERFLOW (i);
2587 :
2588 23087955 : v = build_real (type, real_value_from_int_cst (type, i));
2589 :
2590 23087955 : TREE_OVERFLOW (v) |= overflow;
2591 23087955 : return v;
2592 : }
2593 :
2594 : /* Return a new REAL_CST node whose type is TYPE
2595 : and whose value is the integer value I which has sign SGN. */
2596 :
2597 : tree
2598 138 : build_real_from_wide (tree type, const wide_int_ref &i, signop sgn)
2599 : {
2600 138 : REAL_VALUE_TYPE d;
2601 :
2602 : /* Clear all bits of the real value type so that we can later do
2603 : bitwise comparisons to see if two values are the same. */
2604 138 : memset (&d, 0, sizeof d);
2605 :
2606 138 : real_from_integer (&d, TYPE_MODE (type), i, sgn);
2607 138 : return build_real (type, d);
2608 : }
2609 :
2610 : /* Return a newly constructed STRING_CST node whose value is the LEN
2611 : characters at STR when STR is nonnull, or all zeros otherwise.
2612 : Note that for a C string literal, LEN should include the trailing NUL.
2613 : The TREE_TYPE is not initialized. */
2614 :
2615 : tree
2616 96230160 : build_string (unsigned len, const char *str /*= NULL */)
2617 : {
2618 : /* Do not waste bytes provided by padding of struct tree_string. */
2619 96230160 : unsigned size = len + offsetof (struct tree_string, str) + 1;
2620 :
2621 96230160 : record_node_allocation_statistics (STRING_CST, size);
2622 :
2623 96230160 : tree s = (tree) ggc_internal_alloc (size);
2624 :
2625 96230160 : memset (s, 0, sizeof (struct tree_typed));
2626 96230160 : TREE_SET_CODE (s, STRING_CST);
2627 96230160 : TREE_CONSTANT (s) = 1;
2628 96230160 : TREE_STRING_LENGTH (s) = len;
2629 96230160 : if (str)
2630 96220993 : memcpy (s->string.str, str, len);
2631 : else
2632 9167 : memset (s->string.str, 0, len);
2633 96230160 : s->string.str[len] = '\0';
2634 :
2635 96230160 : return s;
2636 : }
2637 :
2638 : /* Return a newly constructed COMPLEX_CST node whose value is
2639 : specified by the real and imaginary parts REAL and IMAG.
2640 : Both REAL and IMAG should be constant nodes. TYPE, if specified,
2641 : will be the type of the COMPLEX_CST; otherwise a new type will be made. */
2642 :
2643 : tree
2644 485042 : build_complex (tree type, tree real, tree imag)
2645 : {
2646 485042 : gcc_assert (CONSTANT_CLASS_P (real));
2647 485042 : gcc_assert (CONSTANT_CLASS_P (imag));
2648 :
2649 485042 : tree t = make_node (COMPLEX_CST);
2650 :
2651 485042 : TREE_REALPART (t) = real;
2652 485042 : TREE_IMAGPART (t) = imag;
2653 485042 : TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
2654 485042 : TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
2655 485042 : return t;
2656 : }
2657 :
2658 : /* Build a complex (inf +- 0i), such as for the result of cproj.
2659 : TYPE is the complex tree type of the result. If NEG is true, the
2660 : imaginary zero is negative. */
2661 :
2662 : tree
2663 840 : build_complex_inf (tree type, bool neg)
2664 : {
2665 840 : REAL_VALUE_TYPE rzero = dconst0;
2666 :
2667 840 : rzero.sign = neg;
2668 840 : return build_complex (type, build_real (TREE_TYPE (type), dconstinf),
2669 840 : build_real (TREE_TYPE (type), rzero));
2670 : }
2671 :
2672 : /* Return the constant 1 in type TYPE. If TYPE has several elements, each
2673 : element is set to 1. In particular, this is 1 + i for complex types. */
2674 :
2675 : tree
2676 3779 : build_each_one_cst (tree type)
2677 : {
2678 3779 : if (TREE_CODE (type) == COMPLEX_TYPE)
2679 : {
2680 0 : tree scalar = build_one_cst (TREE_TYPE (type));
2681 0 : return build_complex (type, scalar, scalar);
2682 : }
2683 : else
2684 3779 : return build_one_cst (type);
2685 : }
2686 :
2687 : /* Return a constant of arithmetic type TYPE which is the
2688 : multiplicative identity of the set TYPE. */
2689 :
2690 : tree
2691 9641274 : build_one_cst (tree type)
2692 : {
2693 9641274 : switch (TREE_CODE (type))
2694 : {
2695 9627204 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2696 9627204 : case POINTER_TYPE: case REFERENCE_TYPE:
2697 9627204 : case OFFSET_TYPE: case BITINT_TYPE:
2698 9627204 : return build_int_cst (type, 1);
2699 :
2700 10511 : case REAL_TYPE:
2701 10511 : return build_real (type, dconst1);
2702 :
2703 0 : case FIXED_POINT_TYPE:
2704 : /* We can only generate 1 for accum types. */
2705 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2706 0 : return build_fixed (type, FCONST1 (TYPE_MODE (type)));
2707 :
2708 556 : case VECTOR_TYPE:
2709 556 : {
2710 556 : tree scalar = build_one_cst (TREE_TYPE (type));
2711 :
2712 556 : return build_vector_from_val (type, scalar);
2713 : }
2714 :
2715 3003 : case COMPLEX_TYPE:
2716 6006 : return build_complex (type,
2717 3003 : build_one_cst (TREE_TYPE (type)),
2718 6006 : build_zero_cst (TREE_TYPE (type)));
2719 :
2720 0 : default:
2721 0 : gcc_unreachable ();
2722 : }
2723 : }
2724 :
2725 : /* Return an integer of type TYPE containing all 1's in as much precision as
2726 : it contains, or a complex or vector whose subparts are such integers. */
2727 :
2728 : tree
2729 1697474 : build_all_ones_cst (tree type)
2730 : {
2731 1697474 : if (TREE_CODE (type) == COMPLEX_TYPE)
2732 : {
2733 0 : tree scalar = build_all_ones_cst (TREE_TYPE (type));
2734 0 : return build_complex (type, scalar, scalar);
2735 : }
2736 : else
2737 1697474 : return build_minus_one_cst (type);
2738 : }
2739 :
2740 : /* Return a constant of arithmetic type TYPE which is the
2741 : opposite of the multiplicative identity of the set TYPE. */
2742 :
2743 : tree
2744 2306668 : build_minus_one_cst (tree type)
2745 : {
2746 2306668 : switch (TREE_CODE (type))
2747 : {
2748 2188596 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2749 2188596 : case POINTER_TYPE: case REFERENCE_TYPE:
2750 2188596 : case OFFSET_TYPE: case BITINT_TYPE:
2751 2188596 : return build_int_cst (type, -1);
2752 :
2753 9783 : case REAL_TYPE:
2754 9783 : return build_real (type, dconstm1);
2755 :
2756 0 : case FIXED_POINT_TYPE:
2757 : /* We can only generate 1 for accum types. */
2758 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2759 0 : return build_fixed (type,
2760 : fixed_from_double_int (double_int_minus_one,
2761 0 : SCALAR_TYPE_MODE (type)));
2762 :
2763 108289 : case VECTOR_TYPE:
2764 108289 : {
2765 108289 : tree scalar = build_minus_one_cst (TREE_TYPE (type));
2766 :
2767 108289 : return build_vector_from_val (type, scalar);
2768 : }
2769 :
2770 0 : case COMPLEX_TYPE:
2771 0 : return build_complex (type,
2772 0 : build_minus_one_cst (TREE_TYPE (type)),
2773 0 : build_zero_cst (TREE_TYPE (type)));
2774 :
2775 0 : default:
2776 0 : gcc_unreachable ();
2777 : }
2778 : }
2779 :
2780 : /* Build 0 constant of type TYPE. This is used by constructor folding
2781 : and thus the constant should be represented in memory by
2782 : zero(es). */
2783 :
2784 : tree
2785 90766179 : build_zero_cst (tree type)
2786 : {
2787 90766179 : switch (TREE_CODE (type))
2788 : {
2789 90216696 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2790 90216696 : case POINTER_TYPE: case REFERENCE_TYPE:
2791 90216696 : case OFFSET_TYPE: case NULLPTR_TYPE: case BITINT_TYPE:
2792 90216696 : return build_int_cst (type, 0);
2793 :
2794 201887 : case REAL_TYPE:
2795 201887 : return build_real (type, dconst0);
2796 :
2797 0 : case FIXED_POINT_TYPE:
2798 0 : return build_fixed (type, FCONST0 (TYPE_MODE (type)));
2799 :
2800 158510 : case VECTOR_TYPE:
2801 158510 : {
2802 158510 : tree scalar = build_zero_cst (TREE_TYPE (type));
2803 :
2804 158510 : return build_vector_from_val (type, scalar);
2805 : }
2806 :
2807 3082 : case COMPLEX_TYPE:
2808 3082 : {
2809 3082 : tree zero = build_zero_cst (TREE_TYPE (type));
2810 :
2811 3082 : return build_complex (type, zero, zero);
2812 : }
2813 :
2814 186004 : default:
2815 186004 : if (!AGGREGATE_TYPE_P (type))
2816 1 : return fold_convert (type, integer_zero_node);
2817 186003 : return build_constructor (type, NULL);
2818 : }
2819 : }
2820 :
2821 : /* Build a constant of integer type TYPE, made of VALUE's bits replicated
2822 : every WIDTH bits to fit TYPE's precision. */
2823 :
2824 : tree
2825 14 : build_replicated_int_cst (tree type, unsigned int width, HOST_WIDE_INT value)
2826 : {
2827 14 : int n = ((TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
2828 14 : / HOST_BITS_PER_WIDE_INT);
2829 14 : unsigned HOST_WIDE_INT low, mask;
2830 14 : HOST_WIDE_INT a[WIDE_INT_MAX_INL_ELTS];
2831 14 : int i;
2832 :
2833 14 : gcc_assert (n && n <= WIDE_INT_MAX_INL_ELTS);
2834 :
2835 14 : if (width == HOST_BITS_PER_WIDE_INT)
2836 0 : low = value;
2837 : else
2838 : {
2839 14 : mask = (HOST_WIDE_INT_1U << width) - 1;
2840 14 : low = (unsigned HOST_WIDE_INT) ~0 / mask * (value & mask);
2841 : }
2842 :
2843 28 : for (i = 0; i < n; i++)
2844 14 : a[i] = low;
2845 :
2846 14 : gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
2847 14 : return wide_int_to_tree (type, wide_int::from_array (a, n,
2848 14 : TYPE_PRECISION (type)));
2849 : }
2850 :
2851 : /* If floating-point type TYPE has an IEEE-style sign bit, return an
2852 : unsigned constant in which only the sign bit is set. Return null
2853 : otherwise. */
2854 :
2855 : tree
2856 0 : sign_mask_for (tree type)
2857 : {
2858 : /* Avoid having to choose between a real-only sign and a pair of signs.
2859 : This could be relaxed if the choice becomes obvious later. */
2860 0 : if (TREE_CODE (type) == COMPLEX_TYPE)
2861 : return NULL_TREE;
2862 :
2863 0 : auto eltmode = as_a<scalar_float_mode> (element_mode (type));
2864 0 : auto bits = REAL_MODE_FORMAT (eltmode)->ieee_bits;
2865 0 : if (!bits || !pow2p_hwi (bits))
2866 : return NULL_TREE;
2867 :
2868 0 : tree inttype = unsigned_type_for (type);
2869 0 : if (!inttype)
2870 : return NULL_TREE;
2871 :
2872 0 : auto mask = wi::set_bit_in_zero (bits - 1, bits);
2873 0 : if (VECTOR_TYPE_P (inttype))
2874 : {
2875 0 : tree elt = wide_int_to_tree (TREE_TYPE (inttype), mask);
2876 0 : return build_vector_from_val (inttype, elt);
2877 : }
2878 0 : return wide_int_to_tree (inttype, mask);
2879 0 : }
2880 :
2881 : /* Build a BINFO with LEN language slots. */
2882 :
2883 : tree
2884 113276343 : make_tree_binfo (unsigned base_binfos MEM_STAT_DECL)
2885 : {
2886 113276343 : tree t;
2887 113276343 : size_t length = (offsetof (struct tree_binfo, base_binfos)
2888 113276343 : + vec<tree, va_gc>::embedded_size (base_binfos));
2889 :
2890 113276343 : record_node_allocation_statistics (TREE_BINFO, length);
2891 :
2892 113276343 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
2893 :
2894 113276343 : memset (t, 0, offsetof (struct tree_binfo, base_binfos));
2895 :
2896 113276343 : TREE_SET_CODE (t, TREE_BINFO);
2897 :
2898 113276343 : BINFO_BASE_BINFOS (t)->embedded_init (base_binfos);
2899 :
2900 113276343 : return t;
2901 : }
2902 :
2903 : /* Create a CASE_LABEL_EXPR tree node and return it. */
2904 :
2905 : tree
2906 9548264 : build_case_label (tree low_value, tree high_value, tree label_decl)
2907 : {
2908 9548264 : tree t = make_node (CASE_LABEL_EXPR);
2909 :
2910 9548264 : TREE_TYPE (t) = void_type_node;
2911 9548264 : SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl));
2912 :
2913 9548264 : CASE_LOW (t) = low_value;
2914 9548264 : CASE_HIGH (t) = high_value;
2915 9548264 : CASE_LABEL (t) = label_decl;
2916 9548264 : CASE_CHAIN (t) = NULL_TREE;
2917 :
2918 9548264 : return t;
2919 : }
2920 :
2921 : /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2922 : values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2923 : The latter determines the length of the HOST_WIDE_INT vector. */
2924 :
2925 : tree
2926 284157097 : make_int_cst (int len, int ext_len MEM_STAT_DECL)
2927 : {
2928 284157097 : tree t;
2929 284157097 : int length = ((ext_len - 1) * sizeof (HOST_WIDE_INT)
2930 284157097 : + sizeof (struct tree_int_cst));
2931 :
2932 284157097 : gcc_assert (len);
2933 284157097 : record_node_allocation_statistics (INTEGER_CST, length);
2934 :
2935 284157097 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2936 :
2937 284157097 : TREE_SET_CODE (t, INTEGER_CST);
2938 284157097 : TREE_INT_CST_NUNITS (t) = len;
2939 284157097 : TREE_INT_CST_EXT_NUNITS (t) = ext_len;
2940 284157097 : TREE_CONSTANT (t) = 1;
2941 :
2942 284157097 : return t;
2943 : }
2944 :
2945 : /* Build a newly constructed TREE_VEC node of length LEN. */
2946 :
2947 : tree
2948 3953282297 : make_tree_vec (int len MEM_STAT_DECL)
2949 : {
2950 3953282297 : tree t;
2951 3953282297 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2952 :
2953 3953282297 : record_node_allocation_statistics (TREE_VEC, length);
2954 :
2955 3953282297 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2956 :
2957 3953282297 : TREE_SET_CODE (t, TREE_VEC);
2958 3953282297 : TREE_VEC_LENGTH (t) = len;
2959 :
2960 3953282297 : return t;
2961 : }
2962 :
2963 : /* Grow a TREE_VEC node to new length LEN. */
2964 :
2965 : tree
2966 455619 : grow_tree_vec (tree v, int len MEM_STAT_DECL)
2967 : {
2968 455619 : gcc_assert (TREE_CODE (v) == TREE_VEC);
2969 :
2970 455619 : int oldlen = TREE_VEC_LENGTH (v);
2971 455619 : gcc_assert (len > oldlen);
2972 :
2973 455619 : size_t oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
2974 455619 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2975 :
2976 455619 : record_node_allocation_statistics (TREE_VEC, length - oldlength);
2977 :
2978 455619 : v = (tree) ggc_realloc (v, length PASS_MEM_STAT);
2979 :
2980 455619 : TREE_VEC_LENGTH (v) = len;
2981 :
2982 455619 : return v;
2983 : }
2984 :
2985 : /* Return true if EXPR is the constant zero, whether it is integral, float or
2986 : fixed, and scalar, complex or vector. */
2987 :
2988 : bool
2989 18604017 : zerop (const_tree expr)
2990 : {
2991 18604017 : return (integer_zerop (expr)
2992 13180526 : || real_zerop (expr)
2993 31416131 : || fixed_zerop (expr));
2994 : }
2995 :
2996 : /* Return true if EXPR is the integer constant zero or a complex constant
2997 : of zero, or a location wrapper for such a constant. */
2998 :
2999 : bool
3000 6441110260 : integer_zerop (const_tree expr)
3001 : {
3002 6441110260 : STRIP_ANY_LOCATION_WRAPPER (expr);
3003 :
3004 6441110260 : switch (TREE_CODE (expr))
3005 : {
3006 5322232744 : case INTEGER_CST:
3007 5322232744 : return wi::to_wide (expr) == 0;
3008 1200377 : case COMPLEX_CST:
3009 1200377 : return (integer_zerop (TREE_REALPART (expr))
3010 1222497 : && integer_zerop (TREE_IMAGPART (expr)));
3011 2584785 : case VECTOR_CST:
3012 2584785 : return (VECTOR_CST_NPATTERNS (expr) == 1
3013 2447616 : && VECTOR_CST_DUPLICATE_P (expr)
3014 4627501 : && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
3015 : default:
3016 : return false;
3017 : }
3018 : }
3019 :
3020 : /* Return true if EXPR is the integer constant one or the corresponding
3021 : complex constant, or a location wrapper for such a constant. */
3022 :
3023 : bool
3024 1087085391 : integer_onep (const_tree expr)
3025 : {
3026 1087085391 : STRIP_ANY_LOCATION_WRAPPER (expr);
3027 :
3028 1087085391 : switch (TREE_CODE (expr))
3029 : {
3030 940380291 : case INTEGER_CST:
3031 940380291 : return wi::eq_p (wi::to_widest (expr), 1);
3032 21351 : case COMPLEX_CST:
3033 21351 : return (integer_onep (TREE_REALPART (expr))
3034 21371 : && integer_zerop (TREE_IMAGPART (expr)));
3035 158337 : case VECTOR_CST:
3036 158337 : return (VECTOR_CST_NPATTERNS (expr) == 1
3037 143159 : && VECTOR_CST_DUPLICATE_P (expr)
3038 289387 : && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3039 : default:
3040 : return false;
3041 : }
3042 : }
3043 :
3044 : /* Return true if EXPR is the integer constant one. For complex and vector,
3045 : return true if every piece is the integer constant one.
3046 : Also return true for location wrappers for such a constant. */
3047 :
3048 : bool
3049 783339 : integer_each_onep (const_tree expr)
3050 : {
3051 783339 : STRIP_ANY_LOCATION_WRAPPER (expr);
3052 :
3053 783339 : if (TREE_CODE (expr) == COMPLEX_CST)
3054 34 : return (integer_onep (TREE_REALPART (expr))
3055 48 : && integer_onep (TREE_IMAGPART (expr)));
3056 : else
3057 783305 : return integer_onep (expr);
3058 : }
3059 :
3060 : /* Return true if EXPR is an integer containing all 1's in as much precision
3061 : as it contains, or a complex or vector whose subparts are such integers,
3062 : or a location wrapper for such a constant. */
3063 :
3064 : bool
3065 292782480 : integer_all_onesp (const_tree expr)
3066 : {
3067 292782480 : STRIP_ANY_LOCATION_WRAPPER (expr);
3068 :
3069 292782480 : if (TREE_CODE (expr) == COMPLEX_CST
3070 926 : && integer_all_onesp (TREE_REALPART (expr))
3071 292782520 : && integer_all_onesp (TREE_IMAGPART (expr)))
3072 : return true;
3073 :
3074 292782444 : else if (TREE_CODE (expr) == VECTOR_CST)
3075 480633 : return (VECTOR_CST_NPATTERNS (expr) == 1
3076 438664 : && VECTOR_CST_DUPLICATE_P (expr)
3077 900362 : && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
3078 :
3079 292301811 : else if (TREE_CODE (expr) != INTEGER_CST)
3080 : return false;
3081 :
3082 194570659 : return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED)
3083 389141765 : == wi::to_wide (expr));
3084 : }
3085 :
3086 : /* Return true if EXPR is the integer constant minus one, or a location
3087 : wrapper for such a constant. */
3088 :
3089 : bool
3090 211377060 : integer_minus_onep (const_tree expr)
3091 : {
3092 211377060 : STRIP_ANY_LOCATION_WRAPPER (expr);
3093 :
3094 211377060 : if (TREE_CODE (expr) == COMPLEX_CST)
3095 9058 : return (integer_all_onesp (TREE_REALPART (expr))
3096 9062 : && integer_zerop (TREE_IMAGPART (expr)));
3097 : else
3098 211368002 : return integer_all_onesp (expr);
3099 : }
3100 :
3101 : /* Return true if EXPR is an integer constant that is a power of 2 (i.e., has
3102 : only one bit on), or a location wrapper for such a constant. */
3103 :
3104 : bool
3105 20780296 : integer_pow2p (const_tree expr)
3106 : {
3107 20780296 : STRIP_ANY_LOCATION_WRAPPER (expr);
3108 :
3109 20780296 : if (TREE_CODE (expr) == COMPLEX_CST
3110 543 : && integer_pow2p (TREE_REALPART (expr))
3111 20780523 : && integer_zerop (TREE_IMAGPART (expr)))
3112 : return true;
3113 :
3114 20780143 : if (TREE_CODE (expr) != INTEGER_CST)
3115 : return false;
3116 :
3117 14224716 : return wi::popcount (wi::to_wide (expr)) == 1;
3118 : }
3119 :
3120 : /* Return true if EXPR is an integer constant other than zero or a
3121 : complex constant other than zero, or a location wrapper for such a
3122 : constant. */
3123 :
3124 : bool
3125 166709766 : integer_nonzerop (const_tree expr)
3126 : {
3127 166709766 : STRIP_ANY_LOCATION_WRAPPER (expr);
3128 :
3129 166709766 : return ((TREE_CODE (expr) == INTEGER_CST
3130 83449738 : && wi::to_wide (expr) != 0)
3131 193384785 : || (TREE_CODE (expr) == COMPLEX_CST
3132 244 : && (integer_nonzerop (TREE_REALPART (expr))
3133 184 : || integer_nonzerop (TREE_IMAGPART (expr)))));
3134 : }
3135 :
3136 : /* Return true if EXPR is the integer constant one. For vector,
3137 : return true if every piece is the integer constant minus one
3138 : (representing the value TRUE).
3139 : Also return true for location wrappers for such a constant. */
3140 :
3141 : bool
3142 1128575 : integer_truep (const_tree expr)
3143 : {
3144 1128575 : STRIP_ANY_LOCATION_WRAPPER (expr);
3145 :
3146 1128575 : if (TREE_CODE (expr) == VECTOR_CST)
3147 15069 : return integer_all_onesp (expr);
3148 1113506 : return integer_onep (expr);
3149 : }
3150 :
3151 : /* Return true if EXPR is the fixed-point constant zero, or a location wrapper
3152 : for such a constant. */
3153 :
3154 : bool
3155 30081131 : fixed_zerop (const_tree expr)
3156 : {
3157 30081131 : STRIP_ANY_LOCATION_WRAPPER (expr);
3158 :
3159 30081131 : return (TREE_CODE (expr) == FIXED_CST
3160 30081131 : && TREE_FIXED_CST (expr).data.is_zero ());
3161 : }
3162 :
3163 : /* Return the power of two represented by a tree node known to be a
3164 : power of two. */
3165 :
3166 : int
3167 759198 : tree_log2 (const_tree expr)
3168 : {
3169 759198 : if (TREE_CODE (expr) == COMPLEX_CST)
3170 0 : return tree_log2 (TREE_REALPART (expr));
3171 :
3172 759198 : return wi::exact_log2 (wi::to_wide (expr));
3173 : }
3174 :
3175 : /* Similar, but return the largest integer Y such that 2 ** Y is less
3176 : than or equal to EXPR. */
3177 :
3178 : int
3179 2784359 : tree_floor_log2 (const_tree expr)
3180 : {
3181 2784359 : if (TREE_CODE (expr) == COMPLEX_CST)
3182 0 : return tree_log2 (TREE_REALPART (expr));
3183 :
3184 2784359 : return wi::floor_log2 (wi::to_wide (expr));
3185 : }
3186 :
3187 : /* Return number of known trailing zero bits in EXPR, or, if the value of
3188 : EXPR is known to be zero, the precision of it's type. */
3189 :
3190 : unsigned int
3191 82621958 : tree_ctz (const_tree expr)
3192 : {
3193 165242200 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
3194 82629168 : && !POINTER_TYPE_P (TREE_TYPE (expr)))
3195 : return 0;
3196 :
3197 82621905 : unsigned int ret1, ret2, prec = TYPE_PRECISION (TREE_TYPE (expr));
3198 82621905 : switch (TREE_CODE (expr))
3199 : {
3200 43686296 : case INTEGER_CST:
3201 43686296 : ret1 = wi::ctz (wi::to_wide (expr));
3202 43686296 : return MIN (ret1, prec);
3203 12679787 : case SSA_NAME:
3204 12679787 : ret1 = wi::ctz (get_nonzero_bits (expr));
3205 12679787 : return MIN (ret1, prec);
3206 2086749 : case PLUS_EXPR:
3207 2086749 : case MINUS_EXPR:
3208 2086749 : case BIT_IOR_EXPR:
3209 2086749 : case BIT_XOR_EXPR:
3210 2086749 : case MIN_EXPR:
3211 2086749 : case MAX_EXPR:
3212 2086749 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3213 2086749 : if (ret1 == 0)
3214 : return ret1;
3215 977621 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3216 977621 : return MIN (ret1, ret2);
3217 0 : case POINTER_PLUS_EXPR:
3218 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3219 0 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3220 : /* Second operand is sizetype, which could be in theory
3221 : wider than pointer's precision. Make sure we never
3222 : return more than prec. */
3223 0 : ret2 = MIN (ret2, prec);
3224 0 : return MIN (ret1, ret2);
3225 232 : case BIT_AND_EXPR:
3226 232 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3227 232 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3228 232 : return MAX (ret1, ret2);
3229 11789505 : case MULT_EXPR:
3230 11789505 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3231 11789505 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3232 11789505 : return MIN (ret1 + ret2, prec);
3233 0 : case LSHIFT_EXPR:
3234 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3235 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3236 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3237 : {
3238 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3239 0 : return MIN (ret1 + ret2, prec);
3240 : }
3241 : return ret1;
3242 0 : case RSHIFT_EXPR:
3243 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3244 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3245 : {
3246 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3247 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3248 0 : if (ret1 > ret2)
3249 0 : return ret1 - ret2;
3250 : }
3251 : return 0;
3252 5153 : case TRUNC_DIV_EXPR:
3253 5153 : case CEIL_DIV_EXPR:
3254 5153 : case FLOOR_DIV_EXPR:
3255 5153 : case ROUND_DIV_EXPR:
3256 5153 : case EXACT_DIV_EXPR:
3257 5153 : if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
3258 5153 : && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) == 1)
3259 : {
3260 5153 : int l = tree_log2 (TREE_OPERAND (expr, 1));
3261 5153 : if (l >= 0)
3262 : {
3263 4148 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3264 4148 : ret2 = l;
3265 4148 : if (ret1 > ret2)
3266 0 : return ret1 - ret2;
3267 : }
3268 : }
3269 : return 0;
3270 12354859 : CASE_CONVERT:
3271 12354859 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3272 12354859 : if (ret1 && ret1 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
3273 : ret1 = prec;
3274 12354859 : return MIN (ret1, prec);
3275 0 : case SAVE_EXPR:
3276 0 : return tree_ctz (TREE_OPERAND (expr, 0));
3277 6877 : case COND_EXPR:
3278 6877 : ret1 = tree_ctz (TREE_OPERAND (expr, 1));
3279 6877 : if (ret1 == 0)
3280 : return 0;
3281 163 : ret2 = tree_ctz (TREE_OPERAND (expr, 2));
3282 163 : return MIN (ret1, ret2);
3283 0 : case COMPOUND_EXPR:
3284 0 : return tree_ctz (TREE_OPERAND (expr, 1));
3285 199 : case ADDR_EXPR:
3286 199 : ret1 = get_pointer_alignment (const_cast<tree> (expr));
3287 199 : if (ret1 > BITS_PER_UNIT)
3288 : {
3289 199 : ret1 = ctz_hwi (ret1 / BITS_PER_UNIT);
3290 199 : return MIN (ret1, prec);
3291 : }
3292 : return 0;
3293 : default:
3294 : return 0;
3295 : }
3296 : }
3297 :
3298 : /* Return true if EXPR is the real constant zero. Trailing zeroes matter for
3299 : decimal float constants, so don't return true for them.
3300 : Also return true for location wrappers around such a constant. */
3301 :
3302 : bool
3303 586262320 : real_zerop (const_tree expr)
3304 : {
3305 586262320 : STRIP_ANY_LOCATION_WRAPPER (expr);
3306 :
3307 586262320 : switch (TREE_CODE (expr))
3308 : {
3309 18638966 : case REAL_CST:
3310 18638966 : return real_equal (&TREE_REAL_CST (expr), &dconst0)
3311 18638966 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3312 43898 : case COMPLEX_CST:
3313 43898 : return real_zerop (TREE_REALPART (expr))
3314 56499 : && real_zerop (TREE_IMAGPART (expr));
3315 427563 : case VECTOR_CST:
3316 427563 : {
3317 : /* Don't simply check for a duplicate because the predicate
3318 : accepts both +0.0 and -0.0. */
3319 427563 : unsigned count = vector_cst_encoded_nelts (expr);
3320 453920 : for (unsigned int i = 0; i < count; ++i)
3321 436925 : if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3322 : return false;
3323 : return true;
3324 : }
3325 : default:
3326 : return false;
3327 : }
3328 : }
3329 :
3330 : /* Return true if EXPR is the real constant one in real or complex form.
3331 : Trailing zeroes matter for decimal float constants, so don't return
3332 : true for them.
3333 : Also return true for location wrappers around such a constant. */
3334 :
3335 : bool
3336 120780558 : real_onep (const_tree expr)
3337 : {
3338 120780558 : STRIP_ANY_LOCATION_WRAPPER (expr);
3339 :
3340 120780558 : switch (TREE_CODE (expr))
3341 : {
3342 6938524 : case REAL_CST:
3343 6938524 : return real_equal (&TREE_REAL_CST (expr), &dconst1)
3344 6938524 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3345 12620 : case COMPLEX_CST:
3346 12620 : return real_onep (TREE_REALPART (expr))
3347 16109 : && real_zerop (TREE_IMAGPART (expr));
3348 61036 : case VECTOR_CST:
3349 61036 : return (VECTOR_CST_NPATTERNS (expr) == 1
3350 52483 : && VECTOR_CST_DUPLICATE_P (expr)
3351 104453 : && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3352 : default:
3353 : return false;
3354 : }
3355 : }
3356 :
3357 : /* Return true if EXPR is the real constant minus one. Trailing zeroes
3358 : matter for decimal float constants, so don't return true for them.
3359 : Also return true for location wrappers around such a constant. */
3360 :
3361 : bool
3362 121792584 : real_minus_onep (const_tree expr)
3363 : {
3364 121792584 : STRIP_ANY_LOCATION_WRAPPER (expr);
3365 :
3366 121792584 : switch (TREE_CODE (expr))
3367 : {
3368 6874317 : case REAL_CST:
3369 6874317 : return real_equal (&TREE_REAL_CST (expr), &dconstm1)
3370 6874317 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3371 12600 : case COMPLEX_CST:
3372 12600 : return real_minus_onep (TREE_REALPART (expr))
3373 14972 : && real_zerop (TREE_IMAGPART (expr));
3374 62859 : case VECTOR_CST:
3375 62859 : return (VECTOR_CST_NPATTERNS (expr) == 1
3376 53738 : && VECTOR_CST_DUPLICATE_P (expr)
3377 107376 : && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3378 : default:
3379 : return false;
3380 : }
3381 : }
3382 :
3383 : /* Return true if T could be a floating point zero. */
3384 :
3385 : bool
3386 692634 : real_maybe_zerop (const_tree expr)
3387 : {
3388 692634 : switch (TREE_CODE (expr))
3389 : {
3390 473029 : case REAL_CST:
3391 : /* Can't use real_zerop here, as it always returns false for decimal
3392 : floats. And can't use TREE_REAL_CST (expr).cl == rvc_zero
3393 : either, as decimal zeros are rvc_normal. */
3394 473029 : return real_equal (&TREE_REAL_CST (expr), &dconst0);
3395 0 : case COMPLEX_CST:
3396 0 : return (real_maybe_zerop (TREE_REALPART (expr))
3397 0 : || real_maybe_zerop (TREE_IMAGPART (expr)));
3398 0 : case VECTOR_CST:
3399 0 : {
3400 0 : unsigned count = vector_cst_encoded_nelts (expr);
3401 0 : for (unsigned int i = 0; i < count; ++i)
3402 0 : if (real_maybe_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3403 : return true;
3404 : return false;
3405 : }
3406 : default:
3407 : /* Perhaps for SSA_NAMEs we could query frange. */
3408 : return true;
3409 : }
3410 : }
3411 :
3412 : /* True if EXP is a constant or a cast of a constant. */
3413 :
3414 : bool
3415 5485 : really_constant_p (const_tree exp)
3416 : {
3417 : /* This is not quite the same as STRIP_NOPS. It does more. */
3418 10978 : while (CONVERT_EXPR_P (exp)
3419 11030 : || TREE_CODE (exp) == NON_LVALUE_EXPR)
3420 60 : exp = TREE_OPERAND (exp, 0);
3421 5485 : return TREE_CONSTANT (exp);
3422 : }
3423 :
3424 : /* Return true if T holds a polynomial pointer difference, storing it in
3425 : *VALUE if so. A true return means that T's precision is no greater
3426 : than 64 bits, which is the largest address space we support, so *VALUE
3427 : never loses precision. However, the signedness of the result does
3428 : not necessarily match the signedness of T: sometimes an unsigned type
3429 : like sizetype is used to encode a value that is actually negative. */
3430 :
3431 : bool
3432 11134383 : ptrdiff_tree_p (const_tree t, poly_int64 *value)
3433 : {
3434 11134383 : if (!t)
3435 : return false;
3436 11134383 : if (TREE_CODE (t) == INTEGER_CST)
3437 : {
3438 3144190 : if (!cst_and_fits_in_hwi (t))
3439 : return false;
3440 3143633 : *value = int_cst_value (t);
3441 3143633 : return true;
3442 : }
3443 : if (POLY_INT_CST_P (t))
3444 : {
3445 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3446 : if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t, i)))
3447 : return false;
3448 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3449 : value->coeffs[i] = int_cst_value (POLY_INT_CST_COEFF (t, i));
3450 : return true;
3451 : }
3452 : return false;
3453 : }
3454 :
3455 : poly_int64
3456 463723442 : tree_to_poly_int64 (const_tree t)
3457 : {
3458 463723442 : gcc_assert (tree_fits_poly_int64_p (t));
3459 463723442 : if (POLY_INT_CST_P (t))
3460 : return poly_int_cst_value (t).force_shwi ();
3461 463723442 : return TREE_INT_CST_LOW (t);
3462 : }
3463 :
3464 : poly_uint64
3465 527263787 : tree_to_poly_uint64 (const_tree t)
3466 : {
3467 527263787 : gcc_assert (tree_fits_poly_uint64_p (t));
3468 527263787 : if (POLY_INT_CST_P (t))
3469 : return poly_int_cst_value (t).force_uhwi ();
3470 527263787 : return TREE_INT_CST_LOW (t);
3471 : }
3472 :
3473 : /* Return first list element whose TREE_VALUE is ELEM.
3474 : Return 0 if ELEM is not in LIST. */
3475 :
3476 : tree
3477 8015082 : value_member (tree elem, tree list)
3478 : {
3479 23162716 : while (list)
3480 : {
3481 20147731 : if (elem == TREE_VALUE (list))
3482 : return list;
3483 15147634 : list = TREE_CHAIN (list);
3484 : }
3485 : return NULL_TREE;
3486 : }
3487 :
3488 : /* Return first list element whose TREE_PURPOSE is ELEM.
3489 : Return 0 if ELEM is not in LIST. */
3490 :
3491 : tree
3492 254054838 : purpose_member (const_tree elem, tree list)
3493 : {
3494 567186233 : while (list)
3495 : {
3496 346769311 : if (elem == TREE_PURPOSE (list))
3497 : return list;
3498 313131395 : list = TREE_CHAIN (list);
3499 : }
3500 : return NULL_TREE;
3501 : }
3502 :
3503 : /* Return true if ELEM is in V. */
3504 :
3505 : bool
3506 4987751 : vec_member (const_tree elem, vec<tree, va_gc> *v)
3507 : {
3508 4987751 : unsigned ix;
3509 4987751 : tree t;
3510 7590411 : FOR_EACH_VEC_SAFE_ELT (v, ix, t)
3511 2605052 : if (elem == t)
3512 : return true;
3513 : return false;
3514 : }
3515 :
3516 : /* Returns element number IDX (zero-origin) of chain CHAIN, or
3517 : NULL_TREE. */
3518 :
3519 : tree
3520 27472935 : chain_index (int idx, tree chain)
3521 : {
3522 35334915 : for (; chain && idx > 0; --idx)
3523 7861980 : chain = TREE_CHAIN (chain);
3524 27472935 : return chain;
3525 : }
3526 :
3527 : /* Return true if ELEM is part of the chain CHAIN. */
3528 :
3529 : bool
3530 254711 : chain_member (const_tree elem, const_tree chain)
3531 : {
3532 437304 : while (chain)
3533 : {
3534 435873 : if (elem == chain)
3535 : return true;
3536 182593 : chain = DECL_CHAIN (chain);
3537 : }
3538 :
3539 : return false;
3540 : }
3541 :
3542 : /* Return the length of a chain of nodes chained through TREE_CHAIN.
3543 : We expect a null pointer to mark the end of the chain.
3544 : This is the Lisp primitive `length'. */
3545 :
3546 : int
3547 2148967948 : list_length (const_tree t)
3548 : {
3549 2148967948 : const_tree p = t;
3550 : #ifdef ENABLE_TREE_CHECKING
3551 2148967948 : const_tree q = t;
3552 : #endif
3553 2148967948 : int len = 0;
3554 :
3555 3686709431 : while (p)
3556 : {
3557 1537741483 : p = TREE_CHAIN (p);
3558 : #ifdef ENABLE_TREE_CHECKING
3559 1537741483 : if (len % 2)
3560 509121545 : q = TREE_CHAIN (q);
3561 1537741483 : gcc_assert (p != q);
3562 : #endif
3563 1537741483 : len++;
3564 : }
3565 :
3566 2148967948 : return len;
3567 : }
3568 :
3569 : /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3570 : UNION_TYPE TYPE, or NULL_TREE if none. */
3571 :
3572 : tree
3573 83546 : first_field (const_tree type)
3574 : {
3575 83546 : tree t = TYPE_FIELDS (type);
3576 3312512 : while (t && TREE_CODE (t) != FIELD_DECL)
3577 3228966 : t = TREE_CHAIN (t);
3578 83546 : return t;
3579 : }
3580 :
3581 : /* Returns the last FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3582 : UNION_TYPE TYPE, or NULL_TREE if none. */
3583 :
3584 : tree
3585 2670584 : last_field (const_tree type)
3586 : {
3587 2670584 : tree last = NULL_TREE;
3588 :
3589 58614224 : for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
3590 : {
3591 55943640 : if (TREE_CODE (fld) != FIELD_DECL)
3592 47713167 : continue;
3593 :
3594 : last = fld;
3595 : }
3596 :
3597 2670584 : return last;
3598 : }
3599 :
3600 : /* Concatenate two chains of nodes (chained through TREE_CHAIN)
3601 : by modifying the last node in chain 1 to point to chain 2.
3602 : This is the Lisp primitive `nconc'. */
3603 :
3604 : tree
3605 4044004032 : chainon (tree op1, tree op2)
3606 : {
3607 4044004032 : tree t1;
3608 :
3609 4044004032 : if (!op1)
3610 : return op2;
3611 744928689 : if (!op2)
3612 : return op1;
3613 :
3614 1529617416 : for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
3615 860257764 : continue;
3616 669359652 : TREE_CHAIN (t1) = op2;
3617 :
3618 : #ifdef ENABLE_TREE_CHECKING
3619 669359652 : {
3620 669359652 : tree t2;
3621 1723736055 : for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
3622 1054376403 : gcc_assert (t2 != t1);
3623 : }
3624 : #endif
3625 :
3626 : return op1;
3627 860257764 : }
3628 :
3629 : /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
3630 :
3631 : tree
3632 98575296 : tree_last (tree chain)
3633 : {
3634 98575296 : tree next;
3635 98575296 : if (chain)
3636 181504100 : while ((next = TREE_CHAIN (chain)))
3637 : chain = next;
3638 98575296 : return chain;
3639 : }
3640 :
3641 : /* Reverse the order of elements in the chain T,
3642 : and return the new head of the chain (old last element). */
3643 :
3644 : tree
3645 1593161301 : nreverse (tree t)
3646 : {
3647 1593161301 : tree prev = 0, decl, next;
3648 3988518753 : for (decl = t; decl; decl = next)
3649 : {
3650 : /* We shouldn't be using this function to reverse BLOCK chains; we
3651 : have blocks_nreverse for that. */
3652 2395357452 : gcc_checking_assert (TREE_CODE (decl) != BLOCK);
3653 2395357452 : next = TREE_CHAIN (decl);
3654 2395357452 : TREE_CHAIN (decl) = prev;
3655 2395357452 : prev = decl;
3656 : }
3657 1593161301 : return prev;
3658 : }
3659 :
3660 : /* Return a newly created TREE_LIST node whose
3661 : purpose and value fields are PARM and VALUE. */
3662 :
3663 : tree
3664 1402346113 : build_tree_list (tree parm, tree value MEM_STAT_DECL)
3665 : {
3666 1402346113 : tree t = make_node (TREE_LIST PASS_MEM_STAT);
3667 1402346113 : TREE_PURPOSE (t) = parm;
3668 1402346113 : TREE_VALUE (t) = value;
3669 1402346113 : return t;
3670 : }
3671 :
3672 : /* Build a chain of TREE_LIST nodes from a vector. */
3673 :
3674 : tree
3675 86964548 : build_tree_list_vec (const vec<tree, va_gc> *vec MEM_STAT_DECL)
3676 : {
3677 86964548 : tree ret = NULL_TREE;
3678 86964548 : tree *pp = &ret;
3679 86964548 : unsigned int i;
3680 86964548 : tree t;
3681 182532827 : FOR_EACH_VEC_SAFE_ELT (vec, i, t)
3682 : {
3683 95568279 : *pp = build_tree_list (NULL, t PASS_MEM_STAT);
3684 95568279 : pp = &TREE_CHAIN (*pp);
3685 : }
3686 86964548 : return ret;
3687 : }
3688 :
3689 : /* Return a newly created TREE_LIST node whose
3690 : purpose and value fields are PURPOSE and VALUE
3691 : and whose TREE_CHAIN is CHAIN. */
3692 :
3693 : tree
3694 5524915661 : tree_cons (tree purpose, tree value, tree chain MEM_STAT_DECL)
3695 : {
3696 5524915661 : tree node;
3697 :
3698 5524915661 : node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT);
3699 5524915661 : memset (node, 0, sizeof (struct tree_common));
3700 :
3701 5524915661 : record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
3702 :
3703 5524915661 : TREE_SET_CODE (node, TREE_LIST);
3704 5524915661 : TREE_CHAIN (node) = chain;
3705 5524915661 : TREE_PURPOSE (node) = purpose;
3706 5524915661 : TREE_VALUE (node) = value;
3707 5524915661 : return node;
3708 : }
3709 :
3710 : /* Return the values of the elements of a CONSTRUCTOR as a vector of
3711 : trees. */
3712 :
3713 : vec<tree, va_gc> *
3714 0 : ctor_to_vec (tree ctor)
3715 : {
3716 0 : vec<tree, va_gc> *vec;
3717 0 : vec_alloc (vec, CONSTRUCTOR_NELTS (ctor));
3718 0 : unsigned int ix;
3719 0 : tree val;
3720 :
3721 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
3722 0 : vec->quick_push (val);
3723 :
3724 0 : return vec;
3725 : }
3726 :
3727 : /* Return the size nominally occupied by an object of type TYPE
3728 : when it resides in memory. The value is measured in units of bytes,
3729 : and its data type is that normally used for type sizes
3730 : (which is the first type created by make_signed_type or
3731 : make_unsigned_type). */
3732 :
3733 : tree
3734 31090881 : size_in_bytes_loc (location_t loc, const_tree type)
3735 : {
3736 31090881 : tree t;
3737 :
3738 31090881 : if (type == error_mark_node)
3739 0 : return integer_zero_node;
3740 :
3741 31090881 : type = TYPE_MAIN_VARIANT (type);
3742 31090881 : t = TYPE_SIZE_UNIT (type);
3743 :
3744 31090881 : if (t == 0)
3745 : {
3746 54 : lang_hooks.types.incomplete_type_error (loc, NULL_TREE, type);
3747 54 : return size_zero_node;
3748 : }
3749 :
3750 : return t;
3751 : }
3752 :
3753 : /* Return the size of TYPE (in bytes) as a wide integer
3754 : or return -1 if the size can vary or is larger than an integer. */
3755 :
3756 : HOST_WIDE_INT
3757 518539796 : int_size_in_bytes (const_tree type)
3758 : {
3759 518539796 : tree t;
3760 :
3761 518539796 : if (type == error_mark_node)
3762 : return 0;
3763 :
3764 518539796 : type = TYPE_MAIN_VARIANT (type);
3765 518539796 : t = TYPE_SIZE_UNIT (type);
3766 :
3767 518539796 : if (t && tree_fits_uhwi_p (t))
3768 518487175 : return TREE_INT_CST_LOW (t);
3769 : else
3770 : return -1;
3771 : }
3772 :
3773 : /* Return the maximum size of TYPE (in bytes) as a wide integer
3774 : or return -1 if the size can vary or is larger than an integer. */
3775 :
3776 : HOST_WIDE_INT
3777 9201 : max_int_size_in_bytes (const_tree type)
3778 : {
3779 9201 : HOST_WIDE_INT size = -1;
3780 9201 : tree size_tree;
3781 :
3782 : /* If this is an array type, check for a possible MAX_SIZE attached. */
3783 :
3784 9201 : if (TREE_CODE (type) == ARRAY_TYPE)
3785 : {
3786 8480 : size_tree = TYPE_ARRAY_MAX_SIZE (type);
3787 :
3788 8480 : if (size_tree && tree_fits_uhwi_p (size_tree))
3789 0 : size = tree_to_uhwi (size_tree);
3790 : }
3791 :
3792 : /* If we still haven't been able to get a size, see if the language
3793 : can compute a maximum size. */
3794 :
3795 0 : if (size == -1)
3796 : {
3797 9201 : size_tree = lang_hooks.types.max_size (type);
3798 :
3799 9201 : if (size_tree && tree_fits_uhwi_p (size_tree))
3800 0 : size = tree_to_uhwi (size_tree);
3801 : }
3802 :
3803 9201 : return size;
3804 : }
3805 :
3806 : /* Return the bit position of FIELD, in bits from the start of the record.
3807 : This is a tree of type bitsizetype. */
3808 :
3809 : tree
3810 135971419 : bit_position (const_tree field)
3811 : {
3812 135971419 : return bit_from_pos (DECL_FIELD_OFFSET (field),
3813 135971419 : DECL_FIELD_BIT_OFFSET (field));
3814 : }
3815 :
3816 : /* Return the byte position of FIELD, in bytes from the start of the record.
3817 : This is a tree of type sizetype. */
3818 :
3819 : tree
3820 131585728 : byte_position (const_tree field)
3821 : {
3822 131585728 : return byte_from_pos (DECL_FIELD_OFFSET (field),
3823 131585728 : DECL_FIELD_BIT_OFFSET (field));
3824 : }
3825 :
3826 : /* Likewise, but return as an integer. It must be representable in
3827 : that way (since it could be a signed value, we don't have the
3828 : option of returning -1 like int_size_in_byte can. */
3829 :
3830 : HOST_WIDE_INT
3831 9982136 : int_byte_position (const_tree field)
3832 : {
3833 9982136 : return tree_to_shwi (byte_position (field));
3834 : }
3835 :
3836 : /* Return, as a tree node, the number of elements for TYPE (which is an
3837 : ARRAY_TYPE) minus one. This counts only elements of the top array. */
3838 :
3839 : tree
3840 101619344 : array_type_nelts_minus_one (const_tree type)
3841 : {
3842 101619344 : tree index_type, min, max;
3843 :
3844 : /* If they did it with unspecified bounds, then we should have already
3845 : given an error about it before we got here. */
3846 101619344 : if (! TYPE_DOMAIN (type))
3847 10342739 : return error_mark_node;
3848 :
3849 91276605 : index_type = TYPE_DOMAIN (type);
3850 91276605 : min = TYPE_MIN_VALUE (index_type);
3851 91276605 : max = TYPE_MAX_VALUE (index_type);
3852 :
3853 : /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3854 91276605 : if (!max)
3855 : {
3856 : /* zero sized arrays are represented from C FE as complete types with
3857 : NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
3858 : them as min 0, max -1. */
3859 1264673 : if (COMPLETE_TYPE_P (type)
3860 3135 : && integer_zerop (TYPE_SIZE (type))
3861 1267808 : && integer_zerop (min))
3862 3135 : return build_int_cst (TREE_TYPE (min), -1);
3863 :
3864 1261538 : return error_mark_node;
3865 : }
3866 :
3867 90011932 : return (integer_zerop (min)
3868 90011932 : ? max
3869 1121270 : : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
3870 : }
3871 :
3872 : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3873 : (which is an ARRAY_TYPE). This counts only elements of the top
3874 : array. */
3875 :
3876 : tree
3877 16544485 : array_type_nelts_top (tree type)
3878 : {
3879 16544485 : return fold_build2_loc (input_location,
3880 : PLUS_EXPR, sizetype,
3881 : array_type_nelts_minus_one (type),
3882 16544485 : size_one_node);
3883 : }
3884 :
3885 : /* If arg is static -- a reference to an object in static storage -- then
3886 : return the object. This is not the same as the C meaning of `static'.
3887 : If arg isn't static, return NULL. */
3888 :
3889 : tree
3890 1277585046 : staticp (tree arg)
3891 : {
3892 1279662394 : switch (TREE_CODE (arg))
3893 : {
3894 : case FUNCTION_DECL:
3895 : /* Nested functions are static, even though taking their address will
3896 : involve a trampoline as we unnest the nested function and create
3897 : the trampoline on the tree level. */
3898 : return arg;
3899 :
3900 741634883 : case VAR_DECL:
3901 596708668 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3902 189154158 : && ! DECL_THREAD_LOCAL_P (arg)
3903 187327267 : && ! DECL_DLLIMPORT_P (arg)
3904 741634883 : ? arg : NULL);
3905 :
3906 588058 : case CONST_DECL:
3907 60 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3908 588058 : ? arg : NULL);
3909 :
3910 0 : case CONSTRUCTOR:
3911 0 : return TREE_STATIC (arg) ? arg : NULL;
3912 :
3913 : case LABEL_DECL:
3914 : case STRING_CST:
3915 : return arg;
3916 :
3917 1843484 : case COMPONENT_REF:
3918 : /* If the thing being referenced is not a field, then it is
3919 : something language specific. */
3920 1843484 : gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
3921 :
3922 : /* If we are referencing a bitfield, we can't evaluate an
3923 : ADDR_EXPR at compile time and so it isn't a constant. */
3924 1843484 : if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
3925 : return NULL;
3926 :
3927 1843484 : return staticp (TREE_OPERAND (arg, 0));
3928 :
3929 : case BIT_FIELD_REF:
3930 : return NULL;
3931 :
3932 123709 : case INDIRECT_REF:
3933 123709 : return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
3934 :
3935 233952 : case ARRAY_REF:
3936 233952 : case ARRAY_RANGE_REF:
3937 233952 : if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
3938 233952 : && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
3939 233608 : return staticp (TREE_OPERAND (arg, 0));
3940 : else
3941 : return NULL;
3942 :
3943 256 : case REALPART_EXPR:
3944 256 : case IMAGPART_EXPR:
3945 256 : return staticp (TREE_OPERAND (arg, 0));
3946 :
3947 934 : case COMPOUND_LITERAL_EXPR:
3948 934 : return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
3949 :
3950 : default:
3951 : return NULL;
3952 : }
3953 : }
3954 :
3955 :
3956 :
3957 :
3958 : /* Return whether OP is a DECL whose address is function-invariant. */
3959 :
3960 : bool
3961 5112692608 : decl_address_invariant_p (const_tree op)
3962 : {
3963 : /* The conditions below are slightly less strict than the one in
3964 : staticp. */
3965 :
3966 5112692608 : switch (TREE_CODE (op))
3967 : {
3968 : case PARM_DECL:
3969 : case RESULT_DECL:
3970 : case LABEL_DECL:
3971 : case FUNCTION_DECL:
3972 : return true;
3973 :
3974 2782127222 : case VAR_DECL:
3975 2095433453 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3976 1967995457 : || DECL_THREAD_LOCAL_P (op)
3977 1967995457 : || DECL_CONTEXT (op) == current_function_decl
3978 2789211210 : || decl_function_context (op) == current_function_decl)
3979 2775043234 : return true;
3980 : break;
3981 :
3982 25508334 : case CONST_DECL:
3983 0 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3984 25508334 : || decl_function_context (op) == current_function_decl)
3985 25508334 : return true;
3986 : break;
3987 :
3988 : default:
3989 : break;
3990 : }
3991 :
3992 : return false;
3993 : }
3994 :
3995 : /* Return whether OP is a DECL whose address is interprocedural-invariant. */
3996 :
3997 : bool
3998 1739938 : decl_address_ip_invariant_p (const_tree op)
3999 : {
4000 : /* The conditions below are slightly less strict than the one in
4001 : staticp. */
4002 :
4003 1739938 : symtab_node* node;
4004 1739938 : switch (TREE_CODE (op))
4005 : {
4006 : case LABEL_DECL:
4007 : case STRING_CST:
4008 : return true;
4009 :
4010 89245 : case FUNCTION_DECL:
4011 : /* Disable const propagation of symbols defined in assembly. */
4012 89245 : node = symtab_node::get (op);
4013 89245 : return !node || !node->must_remain_in_tu_name;
4014 :
4015 1551672 : case VAR_DECL:
4016 1551672 : if (TREE_STATIC (op) || DECL_EXTERNAL (op))
4017 : {
4018 : /* Disable const propagation of symbols defined in assembly. */
4019 454860 : node = symtab_node::get (op);
4020 454860 : if (node && node->must_remain_in_tu_name)
4021 : return false;
4022 : }
4023 1131400 : if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
4024 454858 : && !DECL_DLLIMPORT_P (op))
4025 2648482 : || DECL_THREAD_LOCAL_P (op))
4026 454858 : return true;
4027 : break;
4028 :
4029 52576 : case CONST_DECL:
4030 52576 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
4031 : return true;
4032 : break;
4033 :
4034 : default:
4035 : break;
4036 : }
4037 :
4038 : return false;
4039 : }
4040 :
4041 : /* Return true if T is an object with invariant address. */
4042 :
4043 : bool
4044 36721 : address_invariant_p (tree t)
4045 : {
4046 44419 : while (handled_component_p (t))
4047 : {
4048 8691 : switch (TREE_CODE (t))
4049 : {
4050 1468 : case ARRAY_REF:
4051 1468 : case ARRAY_RANGE_REF:
4052 1468 : if (!tree_invariant_p (TREE_OPERAND (t, 1))
4053 475 : || TREE_OPERAND (t, 2) != NULL_TREE
4054 1943 : || TREE_OPERAND (t, 3) != NULL_TREE)
4055 : return false;
4056 : break;
4057 :
4058 7064 : case COMPONENT_REF:
4059 7064 : if (TREE_OPERAND (t, 2) != NULL_TREE)
4060 : return false;
4061 : break;
4062 :
4063 : default:
4064 : break;
4065 : }
4066 7698 : t = TREE_OPERAND (t, 0);
4067 : }
4068 :
4069 35728 : STRIP_ANY_LOCATION_WRAPPER (t);
4070 35728 : return CONSTANT_CLASS_P (t) || decl_address_invariant_p (t);
4071 : }
4072 :
4073 :
4074 : /* Return true if T is function-invariant (internal function, does
4075 : not handle arithmetic; that's handled in skip_simple_arithmetic and
4076 : tree_invariant_p). */
4077 :
4078 : static bool
4079 16165432 : tree_invariant_p_1 (tree t)
4080 : {
4081 16165432 : if (TREE_CONSTANT (t) || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
4082 : return true;
4083 :
4084 13383768 : switch (TREE_CODE (t))
4085 : {
4086 : case SAVE_EXPR:
4087 : case TARGET_EXPR:
4088 : return true;
4089 :
4090 36669 : case ADDR_EXPR:
4091 36669 : return address_invariant_p (TREE_OPERAND (t, 0));
4092 :
4093 : default:
4094 : break;
4095 : }
4096 :
4097 : return false;
4098 : }
4099 :
4100 : /* Return true if T is function-invariant. */
4101 :
4102 : bool
4103 12798979 : tree_invariant_p (tree t)
4104 : {
4105 12798979 : tree inner = skip_simple_arithmetic (t);
4106 12798979 : return tree_invariant_p_1 (inner);
4107 : }
4108 :
4109 : /* Wrap a SAVE_EXPR around EXPR, if appropriate.
4110 : Do this to any expression which may be used in more than one place,
4111 : but must be evaluated only once.
4112 :
4113 : Normally, expand_expr would reevaluate the expression each time.
4114 : Calling save_expr produces something that is evaluated and recorded
4115 : the first time expand_expr is called on it. Subsequent calls to
4116 : expand_expr just reuse the recorded value.
4117 :
4118 : The call to expand_expr that generates code that actually computes
4119 : the value is the first call *at compile time*. Subsequent calls
4120 : *at compile time* generate code to use the saved value.
4121 : This produces correct result provided that *at run time* control
4122 : always flows through the insns made by the first expand_expr
4123 : before reaching the other places where the save_expr was evaluated.
4124 : You, the caller of save_expr, must make sure this is so.
4125 :
4126 : Constants, and certain read-only nodes, are returned with no
4127 : SAVE_EXPR because that is safe. Expressions containing placeholders
4128 : are not touched; see tree.def for an explanation of what these
4129 : are used for. */
4130 :
4131 : tree
4132 3366464 : save_expr (tree expr)
4133 : {
4134 3366464 : tree inner;
4135 :
4136 : /* If the tree evaluates to a constant, then we don't want to hide that
4137 : fact (i.e. this allows further folding, and direct checks for constants).
4138 : However, a read-only object that has side effects cannot be bypassed.
4139 : Since it is no problem to reevaluate literals, we just return the
4140 : literal node. */
4141 3366464 : inner = skip_simple_arithmetic (expr);
4142 3366464 : if (TREE_CODE (inner) == ERROR_MARK)
4143 : return inner;
4144 :
4145 3366453 : if (tree_invariant_p_1 (inner))
4146 : return expr;
4147 :
4148 : /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
4149 : it means that the size or offset of some field of an object depends on
4150 : the value within another field.
4151 :
4152 : Note that it must not be the case that EXPR contains both a PLACEHOLDER_EXPR
4153 : and some variable since it would then need to be both evaluated once and
4154 : evaluated more than once. Front-ends must assure this case cannot
4155 : happen by surrounding any such subexpressions in their own SAVE_EXPR
4156 : and forcing evaluation at the proper time. */
4157 2377333 : if (contains_placeholder_p (inner))
4158 : return expr;
4159 :
4160 2377333 : expr = build1_loc (EXPR_LOCATION (expr), SAVE_EXPR, TREE_TYPE (expr), expr);
4161 :
4162 : /* This expression might be placed ahead of a jump to ensure that the
4163 : value was computed on both sides of the jump. So make sure it isn't
4164 : eliminated as dead. */
4165 2377333 : TREE_SIDE_EFFECTS (expr) = 1;
4166 2377333 : return expr;
4167 : }
4168 :
4169 : /* Look inside EXPR into any simple arithmetic operations. Return the
4170 : outermost non-arithmetic or non-invariant node. */
4171 :
4172 : tree
4173 16165443 : skip_simple_arithmetic (tree expr)
4174 : {
4175 : /* We don't care about whether this can be used as an lvalue in this
4176 : context. */
4177 16181173 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4178 15730 : expr = TREE_OPERAND (expr, 0);
4179 :
4180 : /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
4181 : a constant, it will be more efficient to not make another SAVE_EXPR since
4182 : it will allow better simplification and GCSE will be able to merge the
4183 : computations if they actually occur. */
4184 40814968 : while (true)
4185 : {
4186 40814968 : if (UNARY_CLASS_P (expr))
4187 15490348 : expr = TREE_OPERAND (expr, 0);
4188 25324620 : else if (BINARY_CLASS_P (expr))
4189 : {
4190 : /* Before commutative binary operands are canonicalized,
4191 : it is quite common to have constants in the first operand.
4192 : Check for that common case first so that we don't walk
4193 : large expressions with tree_invariant_p unnecessarily.
4194 : This can still have terrible compile time complexity,
4195 : we should limit the depth of the tree_invariant_p and
4196 : skip_simple_arithmetic recursion. */
4197 9204858 : if ((TREE_CONSTANT (TREE_OPERAND (expr, 0))
4198 9194564 : || (TREE_READONLY (TREE_OPERAND (expr, 0))
4199 10043 : && !TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0))))
4200 9214865 : && tree_invariant_p (TREE_OPERAND (expr, 0)))
4201 20301 : expr = TREE_OPERAND (expr, 1);
4202 9184557 : else if (tree_invariant_p (TREE_OPERAND (expr, 1)))
4203 9129328 : expr = TREE_OPERAND (expr, 0);
4204 55229 : else if (tree_invariant_p (TREE_OPERAND (expr, 0)))
4205 9548 : expr = TREE_OPERAND (expr, 1);
4206 : else
4207 : break;
4208 : }
4209 : else
4210 : break;
4211 : }
4212 :
4213 16165443 : return expr;
4214 : }
4215 :
4216 : /* Look inside EXPR into simple arithmetic operations involving constants.
4217 : Return the outermost non-arithmetic or non-constant node. */
4218 :
4219 : tree
4220 0 : skip_simple_constant_arithmetic (tree expr)
4221 : {
4222 0 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4223 0 : expr = TREE_OPERAND (expr, 0);
4224 :
4225 0 : while (true)
4226 : {
4227 0 : if (UNARY_CLASS_P (expr))
4228 0 : expr = TREE_OPERAND (expr, 0);
4229 0 : else if (BINARY_CLASS_P (expr))
4230 : {
4231 0 : if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
4232 0 : expr = TREE_OPERAND (expr, 0);
4233 0 : else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
4234 0 : expr = TREE_OPERAND (expr, 1);
4235 : else
4236 : break;
4237 : }
4238 : else
4239 : break;
4240 : }
4241 :
4242 0 : return expr;
4243 : }
4244 :
4245 : /* Return which tree structure is used by T. */
4246 :
4247 : enum tree_node_structure_enum
4248 42325846374 : tree_node_structure (const_tree t)
4249 : {
4250 42325846374 : const enum tree_code code = TREE_CODE (t);
4251 42325846374 : return tree_node_structure_for_code (code);
4252 : }
4253 :
4254 : /* Set various status flags when building a CALL_EXPR object T. */
4255 :
4256 : static void
4257 346536473 : process_call_operands (tree t)
4258 : {
4259 346536473 : bool side_effects = TREE_SIDE_EFFECTS (t);
4260 346536473 : bool read_only = false;
4261 346536473 : int i = call_expr_flags (t);
4262 :
4263 : /* Calls have side-effects, except those to const or pure functions. */
4264 346536473 : if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
4265 : side_effects = true;
4266 : /* Propagate TREE_READONLY of arguments for const functions. */
4267 60951051 : if (i & ECF_CONST)
4268 59123749 : read_only = true;
4269 :
4270 346536473 : if (!side_effects || read_only)
4271 301977492 : for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
4272 : {
4273 241026945 : tree op = TREE_OPERAND (t, i);
4274 241026945 : if (op && TREE_SIDE_EFFECTS (op))
4275 : side_effects = true;
4276 241026945 : if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
4277 : read_only = false;
4278 : }
4279 :
4280 346536473 : TREE_SIDE_EFFECTS (t) = side_effects;
4281 346536473 : TREE_READONLY (t) = read_only;
4282 346536473 : }
4283 :
4284 : /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
4285 : size or offset that depends on a field within a record. */
4286 :
4287 : bool
4288 38753697 : contains_placeholder_p (const_tree exp)
4289 : {
4290 38753697 : enum tree_code code;
4291 :
4292 38753697 : if (!exp)
4293 : return false;
4294 :
4295 38753697 : code = TREE_CODE (exp);
4296 38753697 : if (code == PLACEHOLDER_EXPR)
4297 : return true;
4298 :
4299 38753697 : switch (TREE_CODE_CLASS (code))
4300 : {
4301 1202417 : case tcc_reference:
4302 : /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
4303 : position computations since they will be converted into a
4304 : WITH_RECORD_EXPR involving the reference, which will assume
4305 : here will be valid. */
4306 1202417 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4307 :
4308 568227 : case tcc_exceptional:
4309 568227 : if (code == TREE_LIST)
4310 0 : return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
4311 0 : || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
4312 : break;
4313 :
4314 33636280 : case tcc_unary:
4315 33636280 : case tcc_binary:
4316 33636280 : case tcc_comparison:
4317 33636280 : case tcc_expression:
4318 33636280 : switch (code)
4319 : {
4320 6426 : case COMPOUND_EXPR:
4321 : /* Ignoring the first operand isn't quite right, but works best. */
4322 6426 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
4323 :
4324 4503 : case COND_EXPR:
4325 9006 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4326 4503 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
4327 9006 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
4328 :
4329 : case SAVE_EXPR:
4330 : /* The save_expr function never wraps anything containing
4331 : a PLACEHOLDER_EXPR. */
4332 : return false;
4333 :
4334 24508606 : default:
4335 24508606 : break;
4336 : }
4337 :
4338 24508606 : switch (TREE_CODE_LENGTH (code))
4339 : {
4340 14919773 : case 1:
4341 14919773 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4342 9495917 : case 2:
4343 18990295 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4344 18990295 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
4345 : default:
4346 : return false;
4347 : }
4348 :
4349 771693 : case tcc_vl_exp:
4350 771693 : switch (code)
4351 : {
4352 771693 : case CALL_EXPR:
4353 771693 : {
4354 771693 : const_tree arg;
4355 771693 : const_call_expr_arg_iterator iter;
4356 2679902 : FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
4357 1136516 : if (CONTAINS_PLACEHOLDER_P (arg))
4358 : return true;
4359 : return false;
4360 : }
4361 : default:
4362 : return false;
4363 : }
4364 :
4365 : default:
4366 : return false;
4367 : }
4368 : return false;
4369 : }
4370 :
4371 : /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
4372 : directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
4373 : field positions. */
4374 :
4375 : static bool
4376 764111 : type_contains_placeholder_1 (const_tree type)
4377 : {
4378 : /* If the size contains a placeholder or the parent type (component type in
4379 : the case of arrays) type involves a placeholder, this type does. */
4380 1507481 : if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
4381 764111 : || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
4382 1528222 : || (!POINTER_TYPE_P (type)
4383 631981 : && TREE_TYPE (type)
4384 107868 : && type_contains_placeholder_p (TREE_TYPE (type))))
4385 0 : return true;
4386 :
4387 : /* Now do type-specific checks. Note that the last part of the check above
4388 : greatly limits what we have to do below. */
4389 764111 : switch (TREE_CODE (type))
4390 : {
4391 : case VOID_TYPE:
4392 : case OPAQUE_TYPE:
4393 : case COMPLEX_TYPE:
4394 : case ENUMERAL_TYPE:
4395 : case BOOLEAN_TYPE:
4396 : case POINTER_TYPE:
4397 : case OFFSET_TYPE:
4398 : case REFERENCE_TYPE:
4399 : case METHOD_TYPE:
4400 : case FUNCTION_TYPE:
4401 : case VECTOR_TYPE:
4402 : case NULLPTR_TYPE:
4403 : return false;
4404 :
4405 170425 : case INTEGER_TYPE:
4406 170425 : case BITINT_TYPE:
4407 170425 : case REAL_TYPE:
4408 170425 : case FIXED_POINT_TYPE:
4409 : /* Here we just check the bounds. */
4410 331442 : return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
4411 331442 : || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
4412 :
4413 56341 : case ARRAY_TYPE:
4414 : /* We have already checked the component type above, so just check
4415 : the domain type. Flexible array members have a null domain. */
4416 112670 : return TYPE_DOMAIN (type) ?
4417 56329 : type_contains_placeholder_p (TYPE_DOMAIN (type)) : false;
4418 :
4419 381990 : case RECORD_TYPE:
4420 381990 : case UNION_TYPE:
4421 381990 : case QUAL_UNION_TYPE:
4422 381990 : {
4423 381990 : tree field;
4424 :
4425 10997734 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4426 10615744 : if (TREE_CODE (field) == FIELD_DECL
4427 10615744 : && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
4428 894930 : || (TREE_CODE (type) == QUAL_UNION_TYPE
4429 0 : && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
4430 894930 : || type_contains_placeholder_p (TREE_TYPE (field))))
4431 0 : return true;
4432 :
4433 : return false;
4434 : }
4435 :
4436 0 : default:
4437 0 : gcc_unreachable ();
4438 : }
4439 : }
4440 :
4441 : /* Wrapper around above function used to cache its result. */
4442 :
4443 : bool
4444 2949206 : type_contains_placeholder_p (tree type)
4445 : {
4446 2949206 : bool result;
4447 :
4448 : /* If the contains_placeholder_bits field has been initialized,
4449 : then we know the answer. */
4450 2949206 : if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
4451 2185095 : return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
4452 :
4453 : /* Indicate that we've seen this type node, and the answer is false.
4454 : This is what we want to return if we run into recursion via fields. */
4455 764111 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
4456 :
4457 : /* Compute the real value. */
4458 764111 : result = type_contains_placeholder_1 (type);
4459 :
4460 : /* Store the real value. */
4461 764111 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
4462 :
4463 764111 : return result;
4464 : }
4465 :
4466 : /* Push tree EXP onto vector QUEUE if it is not already present. */
4467 :
4468 : static void
4469 0 : push_without_duplicates (tree exp, vec<tree> *queue)
4470 : {
4471 0 : unsigned int i;
4472 0 : tree iter;
4473 :
4474 0 : FOR_EACH_VEC_ELT (*queue, i, iter)
4475 0 : if (simple_cst_equal (iter, exp) == 1)
4476 : break;
4477 :
4478 0 : if (!iter)
4479 0 : queue->safe_push (exp);
4480 0 : }
4481 :
4482 : /* Given a tree EXP, find all occurrences of references to fields
4483 : in a PLACEHOLDER_EXPR and place them in vector REFS without
4484 : duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
4485 : we assume here that EXP contains only arithmetic expressions
4486 : or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
4487 : argument list. */
4488 :
4489 : void
4490 0 : find_placeholder_in_expr (tree exp, vec<tree> *refs)
4491 : {
4492 0 : enum tree_code code = TREE_CODE (exp);
4493 0 : tree inner;
4494 0 : int i;
4495 :
4496 : /* We handle TREE_LIST and COMPONENT_REF separately. */
4497 0 : if (code == TREE_LIST)
4498 : {
4499 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
4500 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
4501 : }
4502 0 : else if (code == COMPONENT_REF)
4503 : {
4504 0 : for (inner = TREE_OPERAND (exp, 0);
4505 0 : REFERENCE_CLASS_P (inner);
4506 0 : inner = TREE_OPERAND (inner, 0))
4507 : ;
4508 :
4509 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
4510 0 : push_without_duplicates (exp, refs);
4511 : else
4512 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
4513 : }
4514 : else
4515 0 : switch (TREE_CODE_CLASS (code))
4516 : {
4517 : case tcc_constant:
4518 : break;
4519 :
4520 0 : case tcc_declaration:
4521 : /* Variables allocated to static storage can stay. */
4522 0 : if (!TREE_STATIC (exp))
4523 0 : push_without_duplicates (exp, refs);
4524 : break;
4525 :
4526 0 : case tcc_expression:
4527 : /* This is the pattern built in ada/make_aligning_type. */
4528 0 : if (code == ADDR_EXPR
4529 0 : && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
4530 : {
4531 0 : push_without_duplicates (exp, refs);
4532 0 : break;
4533 : }
4534 :
4535 : /* Fall through. */
4536 :
4537 : case tcc_exceptional:
4538 : case tcc_unary:
4539 : case tcc_binary:
4540 : case tcc_comparison:
4541 : case tcc_reference:
4542 0 : for (i = 0; i < TREE_CODE_LENGTH (code); i++)
4543 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4544 : break;
4545 :
4546 : case tcc_vl_exp:
4547 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4548 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4549 : break;
4550 :
4551 0 : default:
4552 0 : gcc_unreachable ();
4553 : }
4554 0 : }
4555 :
4556 : /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
4557 : return a tree with all occurrences of references to F in a
4558 : PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
4559 : CONST_DECLs. Note that we assume here that EXP contains only
4560 : arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
4561 : occurring only in their argument list. */
4562 :
4563 : tree
4564 0 : substitute_in_expr (tree exp, tree f, tree r)
4565 : {
4566 0 : enum tree_code code = TREE_CODE (exp);
4567 0 : tree op0, op1, op2, op3;
4568 0 : tree new_tree;
4569 :
4570 : /* We handle TREE_LIST and COMPONENT_REF separately. */
4571 0 : if (code == TREE_LIST)
4572 : {
4573 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
4574 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
4575 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4576 : return exp;
4577 :
4578 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4579 : }
4580 0 : else if (code == COMPONENT_REF)
4581 : {
4582 0 : tree inner;
4583 :
4584 : /* If this expression is getting a value from a PLACEHOLDER_EXPR
4585 : and it is the right field, replace it with R. */
4586 0 : for (inner = TREE_OPERAND (exp, 0);
4587 0 : REFERENCE_CLASS_P (inner);
4588 0 : inner = TREE_OPERAND (inner, 0))
4589 : ;
4590 :
4591 : /* The field. */
4592 0 : op1 = TREE_OPERAND (exp, 1);
4593 :
4594 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
4595 : return r;
4596 :
4597 : /* If this expression hasn't been completed let, leave it alone. */
4598 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
4599 : return exp;
4600 :
4601 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4602 0 : if (op0 == TREE_OPERAND (exp, 0))
4603 : return exp;
4604 :
4605 0 : new_tree
4606 0 : = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
4607 : }
4608 : else
4609 0 : switch (TREE_CODE_CLASS (code))
4610 : {
4611 : case tcc_constant:
4612 : return exp;
4613 :
4614 0 : case tcc_declaration:
4615 0 : if (exp == f)
4616 : return r;
4617 : else
4618 : return exp;
4619 :
4620 0 : case tcc_expression:
4621 0 : if (exp == f)
4622 : return r;
4623 :
4624 : /* Fall through. */
4625 :
4626 0 : case tcc_exceptional:
4627 0 : case tcc_unary:
4628 0 : case tcc_binary:
4629 0 : case tcc_comparison:
4630 0 : case tcc_reference:
4631 0 : switch (TREE_CODE_LENGTH (code))
4632 : {
4633 : case 0:
4634 : return exp;
4635 :
4636 0 : case 1:
4637 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4638 0 : if (op0 == TREE_OPERAND (exp, 0))
4639 : return exp;
4640 :
4641 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4642 0 : break;
4643 :
4644 0 : case 2:
4645 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4646 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4647 :
4648 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4649 : return exp;
4650 :
4651 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4652 0 : break;
4653 :
4654 0 : case 3:
4655 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4656 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4657 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4658 :
4659 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4660 0 : && op2 == TREE_OPERAND (exp, 2))
4661 : return exp;
4662 :
4663 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4664 0 : break;
4665 :
4666 0 : case 4:
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 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4670 0 : op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
4671 :
4672 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4673 0 : && op2 == TREE_OPERAND (exp, 2)
4674 0 : && op3 == TREE_OPERAND (exp, 3))
4675 : return exp;
4676 :
4677 0 : new_tree
4678 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4679 0 : break;
4680 :
4681 0 : default:
4682 0 : gcc_unreachable ();
4683 : }
4684 : break;
4685 :
4686 0 : case tcc_vl_exp:
4687 0 : {
4688 0 : int i;
4689 :
4690 0 : new_tree = NULL_TREE;
4691 :
4692 : /* If we are trying to replace F with a constant or with another
4693 : instance of one of the arguments of the call, inline back
4694 : functions which do nothing else than computing a value from
4695 : the arguments they are passed. This makes it possible to
4696 : fold partially or entirely the replacement expression. */
4697 0 : if (code == CALL_EXPR)
4698 : {
4699 0 : bool maybe_inline = false;
4700 0 : if (CONSTANT_CLASS_P (r))
4701 : maybe_inline = true;
4702 : else
4703 0 : for (i = 3; i < TREE_OPERAND_LENGTH (exp); i++)
4704 0 : if (operand_equal_p (TREE_OPERAND (exp, i), r, 0))
4705 : {
4706 : maybe_inline = true;
4707 : break;
4708 : }
4709 0 : if (maybe_inline)
4710 : {
4711 0 : tree t = maybe_inline_call_in_expr (exp);
4712 0 : if (t)
4713 0 : return SUBSTITUTE_IN_EXPR (t, f, r);
4714 : }
4715 : }
4716 :
4717 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4718 : {
4719 0 : tree op = TREE_OPERAND (exp, i);
4720 0 : tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
4721 0 : if (new_op != op)
4722 : {
4723 0 : if (!new_tree)
4724 0 : new_tree = copy_node (exp);
4725 0 : TREE_OPERAND (new_tree, i) = new_op;
4726 : }
4727 : }
4728 :
4729 0 : if (new_tree)
4730 : {
4731 0 : new_tree = fold (new_tree);
4732 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4733 0 : process_call_operands (new_tree);
4734 : }
4735 : else
4736 : return exp;
4737 : }
4738 : break;
4739 :
4740 0 : default:
4741 0 : gcc_unreachable ();
4742 : }
4743 :
4744 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4745 :
4746 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4747 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4748 :
4749 : return new_tree;
4750 : }
4751 :
4752 : /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
4753 : for it within OBJ, a tree that is an object or a chain of references. */
4754 :
4755 : tree
4756 236557 : substitute_placeholder_in_expr (tree exp, tree obj)
4757 : {
4758 236557 : enum tree_code code = TREE_CODE (exp);
4759 236557 : tree op0, op1, op2, op3;
4760 236557 : tree new_tree;
4761 :
4762 : /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
4763 : in the chain of OBJ. */
4764 236557 : if (code == PLACEHOLDER_EXPR)
4765 : {
4766 0 : tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
4767 0 : tree elt;
4768 :
4769 0 : for (elt = obj; elt != 0;
4770 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4771 0 : || TREE_CODE (elt) == COND_EXPR)
4772 0 : ? TREE_OPERAND (elt, 1)
4773 0 : : (REFERENCE_CLASS_P (elt)
4774 : || UNARY_CLASS_P (elt)
4775 : || BINARY_CLASS_P (elt)
4776 : || VL_EXP_CLASS_P (elt)
4777 : || EXPRESSION_CLASS_P (elt))
4778 0 : ? TREE_OPERAND (elt, 0) : 0))
4779 0 : if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
4780 : return elt;
4781 :
4782 0 : for (elt = obj; elt != 0;
4783 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4784 0 : || TREE_CODE (elt) == COND_EXPR)
4785 0 : ? TREE_OPERAND (elt, 1)
4786 0 : : (REFERENCE_CLASS_P (elt)
4787 : || UNARY_CLASS_P (elt)
4788 : || BINARY_CLASS_P (elt)
4789 : || VL_EXP_CLASS_P (elt)
4790 : || EXPRESSION_CLASS_P (elt))
4791 0 : ? TREE_OPERAND (elt, 0) : 0))
4792 0 : if (POINTER_TYPE_P (TREE_TYPE (elt))
4793 0 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
4794 : == need_type))
4795 0 : return fold_build1 (INDIRECT_REF, need_type, elt);
4796 :
4797 : /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
4798 : survives until RTL generation, there will be an error. */
4799 : return exp;
4800 : }
4801 :
4802 : /* TREE_LIST is special because we need to look at TREE_VALUE
4803 : and TREE_CHAIN, not TREE_OPERANDS. */
4804 236557 : else if (code == TREE_LIST)
4805 : {
4806 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
4807 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
4808 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4809 : return exp;
4810 :
4811 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4812 : }
4813 : else
4814 236557 : switch (TREE_CODE_CLASS (code))
4815 : {
4816 : case tcc_constant:
4817 : case tcc_declaration:
4818 : return exp;
4819 :
4820 9739 : case tcc_exceptional:
4821 9739 : case tcc_unary:
4822 9739 : case tcc_binary:
4823 9739 : case tcc_comparison:
4824 9739 : case tcc_expression:
4825 9739 : case tcc_reference:
4826 9739 : case tcc_statement:
4827 9739 : switch (TREE_CODE_LENGTH (code))
4828 : {
4829 : case 0:
4830 : return exp;
4831 :
4832 7416 : case 1:
4833 7416 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4834 7416 : if (op0 == TREE_OPERAND (exp, 0))
4835 : return exp;
4836 :
4837 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4838 0 : break;
4839 :
4840 2311 : case 2:
4841 2311 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4842 2311 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4843 :
4844 2311 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4845 : return exp;
4846 :
4847 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4848 0 : break;
4849 :
4850 12 : case 3:
4851 12 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4852 12 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4853 12 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4854 :
4855 24 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4856 24 : && op2 == TREE_OPERAND (exp, 2))
4857 : return exp;
4858 :
4859 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4860 0 : break;
4861 :
4862 0 : case 4:
4863 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4864 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4865 0 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4866 0 : op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
4867 :
4868 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4869 0 : && op2 == TREE_OPERAND (exp, 2)
4870 0 : && op3 == TREE_OPERAND (exp, 3))
4871 : return exp;
4872 :
4873 0 : new_tree
4874 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4875 0 : break;
4876 :
4877 0 : default:
4878 0 : gcc_unreachable ();
4879 : }
4880 : break;
4881 :
4882 : case tcc_vl_exp:
4883 : {
4884 : int i;
4885 :
4886 : new_tree = NULL_TREE;
4887 :
4888 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4889 : {
4890 0 : tree op = TREE_OPERAND (exp, i);
4891 0 : tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
4892 0 : if (new_op != op)
4893 : {
4894 0 : if (!new_tree)
4895 0 : new_tree = copy_node (exp);
4896 0 : TREE_OPERAND (new_tree, i) = new_op;
4897 : }
4898 : }
4899 :
4900 0 : if (new_tree)
4901 : {
4902 0 : new_tree = fold (new_tree);
4903 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4904 0 : process_call_operands (new_tree);
4905 : }
4906 : else
4907 : return exp;
4908 : }
4909 : break;
4910 :
4911 0 : default:
4912 0 : gcc_unreachable ();
4913 : }
4914 :
4915 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4916 :
4917 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4918 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4919 :
4920 : return new_tree;
4921 : }
4922 :
4923 :
4924 : /* Subroutine of stabilize_reference; this is called for subtrees of
4925 : references. Any expression with side-effects must be put in a SAVE_EXPR
4926 : to ensure that it is only evaluated once.
4927 :
4928 : We don't put SAVE_EXPR nodes around everything, because assigning very
4929 : simple expressions to temporaries causes us to miss good opportunities
4930 : for optimizations. Among other things, the opportunity to fold in the
4931 : addition of a constant into an addressing mode often gets lost, e.g.
4932 : "y[i+1] += x;". In general, we take the approach that we should not make
4933 : an assignment unless we are forced into it - i.e., that any non-side effect
4934 : operator should be allowed, and that cse should take care of coalescing
4935 : multiple utterances of the same expression should that prove fruitful. */
4936 :
4937 : static tree
4938 1131542 : stabilize_reference_1 (tree e)
4939 : {
4940 1131542 : tree result;
4941 1131542 : enum tree_code code = TREE_CODE (e);
4942 :
4943 : /* We cannot ignore const expressions because it might be a reference
4944 : to a const array but whose index contains side-effects. But we can
4945 : ignore things that are actual constant or that already have been
4946 : handled by this function. */
4947 :
4948 1131542 : if (tree_invariant_p (e))
4949 : return e;
4950 :
4951 125752 : switch (TREE_CODE_CLASS (code))
4952 : {
4953 0 : case tcc_exceptional:
4954 : /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
4955 : have side-effects. */
4956 0 : if (code == STATEMENT_LIST)
4957 0 : return save_expr (e);
4958 : /* FALLTHRU */
4959 96446 : case tcc_type:
4960 96446 : case tcc_declaration:
4961 96446 : case tcc_comparison:
4962 96446 : case tcc_statement:
4963 96446 : case tcc_expression:
4964 96446 : case tcc_reference:
4965 96446 : case tcc_vl_exp:
4966 : /* If the expression has side-effects, then encase it in a SAVE_EXPR
4967 : so that it will only be evaluated once. */
4968 : /* The reference (r) and comparison (<) classes could be handled as
4969 : below, but it is generally faster to only evaluate them once. */
4970 96446 : if (TREE_SIDE_EFFECTS (e))
4971 990 : return save_expr (e);
4972 : return e;
4973 :
4974 : case tcc_constant:
4975 : /* Constants need no processing. In fact, we should never reach
4976 : here. */
4977 : return e;
4978 :
4979 21739 : case tcc_binary:
4980 : /* Division is slow and tends to be compiled with jumps,
4981 : especially the division by powers of 2 that is often
4982 : found inside of an array reference. So do it just once. */
4983 21739 : if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
4984 19699 : || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
4985 19699 : || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
4986 19699 : || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
4987 2040 : return save_expr (e);
4988 : /* Recursively stabilize each operand. */
4989 19699 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
4990 19699 : stabilize_reference_1 (TREE_OPERAND (e, 1)));
4991 19699 : break;
4992 :
4993 7567 : case tcc_unary:
4994 : /* Recursively stabilize each operand. */
4995 7567 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
4996 7567 : break;
4997 :
4998 0 : default:
4999 0 : gcc_unreachable ();
5000 : }
5001 :
5002 27266 : TREE_TYPE (result) = TREE_TYPE (e);
5003 27266 : TREE_READONLY (result) = TREE_READONLY (e);
5004 27266 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
5005 27266 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
5006 :
5007 27266 : return result;
5008 : }
5009 :
5010 : /* Stabilize a reference so that we can use it any number of times
5011 : without causing its operands to be evaluated more than once.
5012 : Returns the stabilized reference. This works by means of save_expr,
5013 : so see the caveats in the comments about save_expr.
5014 :
5015 : Also allows conversion expressions whose operands are references.
5016 : Any other kind of expression is returned unchanged. */
5017 :
5018 : tree
5019 5347125 : stabilize_reference (tree ref)
5020 : {
5021 5347125 : tree result;
5022 5347125 : enum tree_code code = TREE_CODE (ref);
5023 :
5024 5347125 : switch (code)
5025 : {
5026 : case VAR_DECL:
5027 : case PARM_DECL:
5028 : case RESULT_DECL:
5029 : /* No action is needed in this case. */
5030 : return ref;
5031 :
5032 0 : CASE_CONVERT:
5033 0 : case FLOAT_EXPR:
5034 0 : case FIX_TRUNC_EXPR:
5035 0 : result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
5036 0 : break;
5037 :
5038 1037784 : case INDIRECT_REF:
5039 1037784 : result = build_nt (INDIRECT_REF,
5040 1037784 : stabilize_reference_1 (TREE_OPERAND (ref, 0)));
5041 1037784 : break;
5042 :
5043 565193 : case COMPONENT_REF:
5044 565193 : result = build_nt (COMPONENT_REF,
5045 565193 : stabilize_reference (TREE_OPERAND (ref, 0)),
5046 565193 : TREE_OPERAND (ref, 1), NULL_TREE);
5047 565193 : break;
5048 :
5049 0 : case BIT_FIELD_REF:
5050 0 : result = build_nt (BIT_FIELD_REF,
5051 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5052 0 : TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2));
5053 0 : REF_REVERSE_STORAGE_ORDER (result) = REF_REVERSE_STORAGE_ORDER (ref);
5054 0 : break;
5055 :
5056 46793 : case ARRAY_REF:
5057 93586 : result = build_nt (ARRAY_REF,
5058 46793 : stabilize_reference (TREE_OPERAND (ref, 0)),
5059 46793 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5060 46793 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5061 46793 : break;
5062 :
5063 0 : case ARRAY_RANGE_REF:
5064 0 : result = build_nt (ARRAY_RANGE_REF,
5065 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5066 0 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5067 0 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5068 0 : break;
5069 :
5070 0 : case COMPOUND_EXPR:
5071 : /* We cannot wrap the first expression in a SAVE_EXPR, as then
5072 : it wouldn't be ignored. This matters when dealing with
5073 : volatiles. */
5074 0 : return stabilize_reference_1 (ref);
5075 :
5076 : /* If arg isn't a kind of lvalue we recognize, make no change.
5077 : Caller should recognize the error for an invalid lvalue. */
5078 : default:
5079 : return ref;
5080 :
5081 0 : case ERROR_MARK:
5082 0 : return error_mark_node;
5083 : }
5084 :
5085 1649770 : TREE_TYPE (result) = TREE_TYPE (ref);
5086 1649770 : TREE_READONLY (result) = TREE_READONLY (ref);
5087 1649770 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
5088 1649770 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
5089 1649770 : protected_set_expr_location (result, EXPR_LOCATION (ref));
5090 :
5091 1649770 : return result;
5092 : }
5093 :
5094 : /* Low-level constructors for expressions. */
5095 :
5096 : /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
5097 : and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
5098 :
5099 : void
5100 1490667048 : recompute_tree_invariant_for_addr_expr (tree t)
5101 : {
5102 1490667048 : tree node;
5103 1490667048 : bool tc = true, se = false;
5104 :
5105 1490667048 : gcc_assert (TREE_CODE (t) == ADDR_EXPR);
5106 :
5107 : /* We started out assuming this address is both invariant and constant, but
5108 : does not have side effects. Now go down any handled components and see if
5109 : any of them involve offsets that are either non-constant or non-invariant.
5110 : Also check for side-effects.
5111 :
5112 : ??? Note that this code makes no attempt to deal with the case where
5113 : taking the address of something causes a copy due to misalignment. */
5114 :
5115 : #define UPDATE_FLAGS(NODE) \
5116 : do { tree _node = (NODE); \
5117 : if (_node && !TREE_CONSTANT (_node)) tc = false; \
5118 : if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
5119 :
5120 1736836135 : for (node = TREE_OPERAND (t, 0); handled_component_p (node);
5121 246169087 : node = TREE_OPERAND (node, 0))
5122 : {
5123 : /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
5124 : array reference (probably made temporarily by the G++ front end),
5125 : so ignore all the operands. */
5126 246169087 : if ((TREE_CODE (node) == ARRAY_REF
5127 246169087 : || TREE_CODE (node) == ARRAY_RANGE_REF)
5128 246169087 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
5129 : {
5130 32720300 : UPDATE_FLAGS (TREE_OPERAND (node, 1));
5131 32720300 : if (TREE_OPERAND (node, 2))
5132 2189742 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5133 32720300 : if (TREE_OPERAND (node, 3))
5134 273298 : UPDATE_FLAGS (TREE_OPERAND (node, 3));
5135 : }
5136 : /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
5137 : FIELD_DECL, apparently. The G++ front end can put something else
5138 : there, at least temporarily. */
5139 213448787 : else if (TREE_CODE (node) == COMPONENT_REF
5140 213448787 : && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
5141 : {
5142 212273672 : if (TREE_OPERAND (node, 2))
5143 17035 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5144 : }
5145 : }
5146 :
5147 1490667048 : node = lang_hooks.expr_to_decl (node, &tc, &se);
5148 :
5149 : /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
5150 : the address, since &(*a)->b is a form of addition. If it's a constant, the
5151 : address is constant too. If it's a decl, its address is constant if the
5152 : decl is static. Everything else is not constant and, furthermore,
5153 : taking the address of a volatile variable is not volatile. */
5154 1490667048 : if (INDIRECT_REF_P (node)
5155 1443030878 : || TREE_CODE (node) == MEM_REF)
5156 164448405 : UPDATE_FLAGS (TREE_OPERAND (node, 0));
5157 1326218643 : else if (CONSTANT_CLASS_P (node))
5158 : ;
5159 1251700363 : else if (DECL_P (node))
5160 1222484042 : tc &= (staticp (node) != NULL_TREE);
5161 : else
5162 : {
5163 29216321 : tc = false;
5164 29216321 : se |= TREE_SIDE_EFFECTS (node);
5165 : }
5166 :
5167 :
5168 1490667048 : TREE_CONSTANT (t) = tc;
5169 1490667048 : TREE_SIDE_EFFECTS (t) = se;
5170 : #undef UPDATE_FLAGS
5171 1490667048 : }
5172 :
5173 : /* Build an expression of code CODE, data type TYPE, and operands as
5174 : specified. Expressions and reference nodes can be created this way.
5175 : Constants, decls, types and misc nodes cannot be.
5176 :
5177 : We define 5 non-variadic functions, from 0 to 4 arguments. This is
5178 : enough for all extant tree codes. */
5179 :
5180 : tree
5181 382199328 : build0 (enum tree_code code, tree tt MEM_STAT_DECL)
5182 : {
5183 382199328 : tree t;
5184 :
5185 382199328 : gcc_assert (TREE_CODE_LENGTH (code) == 0);
5186 :
5187 382199328 : t = make_node (code PASS_MEM_STAT);
5188 382199328 : TREE_TYPE (t) = tt;
5189 :
5190 382199328 : return t;
5191 : }
5192 :
5193 : tree
5194 4490113813 : build1 (enum tree_code code, tree type, tree node MEM_STAT_DECL)
5195 : {
5196 4490113813 : int length = sizeof (struct tree_exp);
5197 4490113813 : tree t;
5198 :
5199 4490113813 : record_node_allocation_statistics (code, length);
5200 :
5201 4490113813 : gcc_assert (TREE_CODE_LENGTH (code) == 1);
5202 :
5203 4490113813 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
5204 :
5205 4490113813 : memset (t, 0, sizeof (struct tree_common));
5206 :
5207 4490113813 : TREE_SET_CODE (t, code);
5208 :
5209 4490113813 : TREE_TYPE (t) = type;
5210 4490113813 : SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
5211 4490113813 : TREE_OPERAND (t, 0) = node;
5212 4490113813 : if (node && !TYPE_P (node))
5213 : {
5214 4490078559 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
5215 4490078559 : TREE_READONLY (t) = TREE_READONLY (node);
5216 : }
5217 :
5218 4490113813 : if (TREE_CODE_CLASS (code) == tcc_statement)
5219 : {
5220 28273653 : if (code != DEBUG_BEGIN_STMT)
5221 28273653 : TREE_SIDE_EFFECTS (t) = 1;
5222 : }
5223 4461840160 : else switch (code)
5224 : {
5225 50942 : case VA_ARG_EXPR:
5226 : /* All of these have side-effects, no matter what their
5227 : operands are. */
5228 50942 : TREE_SIDE_EFFECTS (t) = 1;
5229 50942 : TREE_READONLY (t) = 0;
5230 50942 : break;
5231 :
5232 723260656 : case INDIRECT_REF:
5233 : /* Whether a dereference is readonly has nothing to do with whether
5234 : its operand is readonly. */
5235 723260656 : TREE_READONLY (t) = 0;
5236 723260656 : break;
5237 :
5238 756878740 : case ADDR_EXPR:
5239 756878740 : if (node)
5240 756878740 : recompute_tree_invariant_for_addr_expr (t);
5241 : break;
5242 :
5243 2981649822 : default:
5244 1056746368 : if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
5245 2811273780 : && node && !TYPE_P (node)
5246 5792923602 : && TREE_CONSTANT (node))
5247 799203132 : TREE_CONSTANT (t) = 1;
5248 2981649822 : if (TREE_CODE_CLASS (code) == tcc_reference
5249 888870761 : && node && TREE_THIS_VOLATILE (node))
5250 2780025 : TREE_THIS_VOLATILE (t) = 1;
5251 : break;
5252 : }
5253 :
5254 4490113813 : return t;
5255 : }
5256 :
5257 : #define PROCESS_ARG(N) \
5258 : do { \
5259 : TREE_OPERAND (t, N) = arg##N; \
5260 : if (arg##N &&!TYPE_P (arg##N)) \
5261 : { \
5262 : if (TREE_SIDE_EFFECTS (arg##N)) \
5263 : side_effects = 1; \
5264 : if (!TREE_READONLY (arg##N) \
5265 : && !CONSTANT_CLASS_P (arg##N)) \
5266 : (void) (read_only = 0); \
5267 : if (!TREE_CONSTANT (arg##N)) \
5268 : (void) (constant = 0); \
5269 : } \
5270 : } while (0)
5271 :
5272 : tree
5273 1337485734 : build2 (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
5274 : {
5275 1337485734 : bool constant, read_only, side_effects, div_by_zero;
5276 1337485734 : tree t;
5277 :
5278 1337485734 : gcc_assert (TREE_CODE_LENGTH (code) == 2);
5279 :
5280 1337485734 : if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
5281 193953839 : && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
5282 : /* When sizetype precision doesn't match that of pointers
5283 : we need to be able to build explicit extensions or truncations
5284 : of the offset argument. */
5285 1337485734 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
5286 0 : gcc_assert (TREE_CODE (arg0) == INTEGER_CST
5287 : && TREE_CODE (arg1) == INTEGER_CST);
5288 :
5289 1337485734 : if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
5290 41721789 : gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
5291 : && ptrofftype_p (TREE_TYPE (arg1)));
5292 :
5293 1337485734 : t = make_node (code PASS_MEM_STAT);
5294 1337485734 : TREE_TYPE (t) = tt;
5295 :
5296 : /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
5297 : result based on those same flags for the arguments. But if the
5298 : arguments aren't really even `tree' expressions, we shouldn't be trying
5299 : to do this. */
5300 :
5301 : /* Expressions without side effects may be constant if their
5302 : arguments are as well. */
5303 2674971468 : constant = (TREE_CODE_CLASS (code) == tcc_comparison
5304 1337485734 : || TREE_CODE_CLASS (code) == tcc_binary);
5305 1337485734 : read_only = 1;
5306 1337485734 : side_effects = TREE_SIDE_EFFECTS (t);
5307 :
5308 1337485734 : switch (code)
5309 : {
5310 15067644 : case TRUNC_DIV_EXPR:
5311 15067644 : case CEIL_DIV_EXPR:
5312 15067644 : case FLOOR_DIV_EXPR:
5313 15067644 : case ROUND_DIV_EXPR:
5314 15067644 : case EXACT_DIV_EXPR:
5315 15067644 : case CEIL_MOD_EXPR:
5316 15067644 : case FLOOR_MOD_EXPR:
5317 15067644 : case ROUND_MOD_EXPR:
5318 15067644 : case TRUNC_MOD_EXPR:
5319 15067644 : div_by_zero = integer_zerop (arg1);
5320 15067644 : break;
5321 : default:
5322 : div_by_zero = false;
5323 : }
5324 :
5325 1464468253 : PROCESS_ARG (0);
5326 1867621055 : PROCESS_ARG (1);
5327 :
5328 1337485734 : TREE_SIDE_EFFECTS (t) = side_effects;
5329 1337485734 : if (code == MEM_REF)
5330 : {
5331 75363004 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5332 : {
5333 18524484 : tree o = TREE_OPERAND (arg0, 0);
5334 18524484 : TREE_READONLY (t) = TREE_READONLY (o);
5335 18524484 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5336 : }
5337 : }
5338 : else
5339 : {
5340 1262122730 : TREE_READONLY (t) = read_only;
5341 : /* Don't mark X / 0 as constant. */
5342 1262122730 : TREE_CONSTANT (t) = constant && !div_by_zero;
5343 1262122730 : TREE_THIS_VOLATILE (t)
5344 1262122730 : = (TREE_CODE_CLASS (code) == tcc_reference
5345 1262122730 : && arg0 && TREE_THIS_VOLATILE (arg0));
5346 : }
5347 :
5348 1337485734 : return t;
5349 : }
5350 :
5351 :
5352 : tree
5353 511740422 : build3 (enum tree_code code, tree tt, tree arg0, tree arg1,
5354 : tree arg2 MEM_STAT_DECL)
5355 : {
5356 511740422 : bool constant, read_only, side_effects;
5357 511740422 : tree t;
5358 :
5359 511740422 : gcc_assert (TREE_CODE_LENGTH (code) == 3);
5360 511740422 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5361 :
5362 511740422 : t = make_node (code PASS_MEM_STAT);
5363 511740422 : TREE_TYPE (t) = tt;
5364 :
5365 511740422 : read_only = 1;
5366 :
5367 : /* As a special exception, if COND_EXPR has NULL branches, we
5368 : assume that it is a gimple statement and always consider
5369 : it to have side effects. */
5370 511740422 : if (code == COND_EXPR
5371 48441556 : && tt == void_type_node
5372 31696092 : && arg1 == NULL_TREE
5373 31696092 : && arg2 == NULL_TREE)
5374 : side_effects = true;
5375 : else
5376 511740422 : side_effects = TREE_SIDE_EFFECTS (t);
5377 :
5378 567451692 : PROCESS_ARG (0);
5379 532859089 : PROCESS_ARG (1);
5380 529639088 : PROCESS_ARG (2);
5381 :
5382 511740422 : if (code == COND_EXPR)
5383 48441556 : TREE_READONLY (t) = read_only;
5384 :
5385 511740422 : TREE_SIDE_EFFECTS (t) = side_effects;
5386 511740422 : TREE_THIS_VOLATILE (t)
5387 511740422 : = (TREE_CODE_CLASS (code) == tcc_reference
5388 511740422 : && arg0 && TREE_THIS_VOLATILE (arg0));
5389 :
5390 511740422 : return t;
5391 : }
5392 :
5393 : tree
5394 66117773 : build4 (enum tree_code code, tree tt, tree arg0, tree arg1,
5395 : tree arg2, tree arg3 MEM_STAT_DECL)
5396 : {
5397 66117773 : bool constant, read_only, side_effects;
5398 66117773 : tree t;
5399 :
5400 66117773 : gcc_assert (TREE_CODE_LENGTH (code) == 4);
5401 :
5402 66117773 : t = make_node (code PASS_MEM_STAT);
5403 66117773 : TREE_TYPE (t) = tt;
5404 :
5405 66117773 : side_effects = TREE_SIDE_EFFECTS (t);
5406 :
5407 66117773 : PROCESS_ARG (0);
5408 66117773 : PROCESS_ARG (1);
5409 66117773 : PROCESS_ARG (2);
5410 66117773 : PROCESS_ARG (3);
5411 :
5412 66117773 : TREE_SIDE_EFFECTS (t) = side_effects;
5413 66117773 : TREE_THIS_VOLATILE (t)
5414 132235546 : = (TREE_CODE_CLASS (code) == tcc_reference
5415 66117773 : && arg0 && TREE_THIS_VOLATILE (arg0));
5416 :
5417 66117773 : return t;
5418 : }
5419 :
5420 : tree
5421 1171482 : build5 (enum tree_code code, tree tt, tree arg0, tree arg1,
5422 : tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
5423 : {
5424 1171482 : bool constant, read_only, side_effects;
5425 1171482 : tree t;
5426 :
5427 1171482 : gcc_assert (TREE_CODE_LENGTH (code) == 5);
5428 :
5429 1171482 : t = make_node (code PASS_MEM_STAT);
5430 1171482 : TREE_TYPE (t) = tt;
5431 :
5432 1171482 : side_effects = TREE_SIDE_EFFECTS (t);
5433 :
5434 1171482 : PROCESS_ARG (0);
5435 1171482 : PROCESS_ARG (1);
5436 1171482 : PROCESS_ARG (2);
5437 1171482 : PROCESS_ARG (3);
5438 1171482 : PROCESS_ARG (4);
5439 :
5440 1171482 : TREE_SIDE_EFFECTS (t) = side_effects;
5441 1171482 : if (code == TARGET_MEM_REF)
5442 : {
5443 1163349 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5444 : {
5445 194063 : tree o = TREE_OPERAND (arg0, 0);
5446 194063 : TREE_READONLY (t) = TREE_READONLY (o);
5447 194063 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5448 : }
5449 : }
5450 : else
5451 8133 : TREE_THIS_VOLATILE (t)
5452 8133 : = (TREE_CODE_CLASS (code) == tcc_reference
5453 8133 : && arg0 && TREE_THIS_VOLATILE (arg0));
5454 :
5455 1171482 : return t;
5456 : }
5457 :
5458 : /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
5459 : on the pointer PTR. */
5460 :
5461 : tree
5462 481226 : build_simple_mem_ref_loc (location_t loc, tree ptr)
5463 : {
5464 481226 : poly_int64 offset = 0;
5465 481226 : tree ptype = TREE_TYPE (ptr);
5466 481226 : tree tem;
5467 : /* For convenience allow addresses that collapse to a simple base
5468 : and offset. */
5469 481226 : if (TREE_CODE (ptr) == ADDR_EXPR
5470 481226 : && (handled_component_p (TREE_OPERAND (ptr, 0))
5471 15536 : || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
5472 : {
5473 150 : ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
5474 150 : gcc_assert (ptr);
5475 150 : if (TREE_CODE (ptr) == MEM_REF)
5476 : {
5477 37 : offset += mem_ref_offset (ptr).force_shwi ();
5478 37 : ptr = TREE_OPERAND (ptr, 0);
5479 : }
5480 : else
5481 113 : ptr = build_fold_addr_expr (ptr);
5482 150 : gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
5483 : }
5484 481226 : tem = build2 (MEM_REF, TREE_TYPE (ptype),
5485 : ptr, build_int_cst (ptype, offset));
5486 481226 : SET_EXPR_LOCATION (tem, loc);
5487 481226 : return tem;
5488 : }
5489 :
5490 : /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
5491 :
5492 : poly_offset_int
5493 1177773484 : mem_ref_offset (const_tree t)
5494 : {
5495 1177773484 : return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
5496 1177773484 : SIGNED);
5497 : }
5498 :
5499 : /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
5500 : offsetted by OFFSET units. */
5501 :
5502 : tree
5503 193942 : build_invariant_address (tree type, tree base, poly_int64 offset)
5504 : {
5505 193942 : tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
5506 : build_fold_addr_expr (base),
5507 : build_int_cst (ptr_type_node, offset));
5508 193942 : tree addr = build1 (ADDR_EXPR, type, ref);
5509 193942 : recompute_tree_invariant_for_addr_expr (addr);
5510 193942 : return addr;
5511 : }
5512 :
5513 : /* Similar except don't specify the TREE_TYPE
5514 : and leave the TREE_SIDE_EFFECTS as 0.
5515 : It is permissible for arguments to be null,
5516 : or even garbage if their values do not matter. */
5517 :
5518 : tree
5519 5727464 : build_nt (enum tree_code code, ...)
5520 : {
5521 5727464 : tree t;
5522 5727464 : int length;
5523 5727464 : int i;
5524 5727464 : va_list p;
5525 :
5526 5727464 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5527 :
5528 5727464 : va_start (p, code);
5529 :
5530 5727464 : t = make_node (code);
5531 5727464 : length = TREE_CODE_LENGTH (code);
5532 :
5533 15492262 : for (i = 0; i < length; i++)
5534 9764798 : TREE_OPERAND (t, i) = va_arg (p, tree);
5535 :
5536 5727464 : va_end (p);
5537 5727464 : return t;
5538 : }
5539 :
5540 : /* Similar to build_nt, but for creating a CALL_EXPR object with a
5541 : tree vec. */
5542 :
5543 : tree
5544 0 : build_nt_call_vec (tree fn, vec<tree, va_gc> *args)
5545 : {
5546 0 : tree ret, t;
5547 0 : unsigned int ix;
5548 :
5549 0 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
5550 0 : CALL_EXPR_FN (ret) = fn;
5551 0 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
5552 0 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
5553 0 : CALL_EXPR_ARG (ret, ix) = t;
5554 0 : return ret;
5555 : }
5556 :
5557 : /* Create a DECL_... node of code CODE, name NAME (if non-null)
5558 : and data type TYPE.
5559 : We do NOT enter this node in any sort of symbol table.
5560 :
5561 : LOC is the location of the decl.
5562 :
5563 : layout_decl is used to set up the decl's storage layout.
5564 : Other slots are initialized to 0 or null pointers. */
5565 :
5566 : tree
5567 3175358373 : build_decl (location_t loc, enum tree_code code, tree name,
5568 : tree type MEM_STAT_DECL)
5569 : {
5570 3175358373 : tree t;
5571 :
5572 3175358373 : t = make_node (code PASS_MEM_STAT);
5573 3175358373 : DECL_SOURCE_LOCATION (t) = loc;
5574 :
5575 : /* if (type == error_mark_node)
5576 : type = integer_type_node; */
5577 : /* That is not done, deliberately, so that having error_mark_node
5578 : as the type can suppress useless errors in the use of this variable. */
5579 :
5580 3175358373 : DECL_NAME (t) = name;
5581 3175358373 : TREE_TYPE (t) = type;
5582 :
5583 3175358373 : if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
5584 1140808243 : layout_decl (t, 0);
5585 :
5586 3175358373 : return t;
5587 : }
5588 :
5589 : /* Create and return a DEBUG_EXPR_DECL node of the given TYPE. */
5590 :
5591 : tree
5592 1616669 : build_debug_expr_decl (tree type)
5593 : {
5594 1616669 : tree vexpr = make_node (DEBUG_EXPR_DECL);
5595 1616669 : DECL_ARTIFICIAL (vexpr) = 1;
5596 1616669 : TREE_TYPE (vexpr) = type;
5597 1616669 : SET_DECL_MODE (vexpr, TYPE_MODE (type));
5598 1616669 : return vexpr;
5599 : }
5600 :
5601 : /* Builds and returns function declaration with NAME and TYPE. */
5602 :
5603 : tree
5604 19875 : build_fn_decl (const char *name, tree type)
5605 : {
5606 19875 : tree id = get_identifier (name);
5607 19875 : tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
5608 :
5609 19875 : DECL_EXTERNAL (decl) = 1;
5610 19875 : TREE_PUBLIC (decl) = 1;
5611 19875 : DECL_ARTIFICIAL (decl) = 1;
5612 19875 : TREE_NOTHROW (decl) = 1;
5613 :
5614 19875 : return decl;
5615 : }
5616 :
5617 : vec<tree, va_gc> *all_translation_units;
5618 :
5619 : /* Builds a new translation-unit decl with name NAME, queues it in the
5620 : global list of translation-unit decls and returns it. */
5621 :
5622 : tree
5623 249573 : build_translation_unit_decl (tree name)
5624 : {
5625 249573 : tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
5626 249573 : name, NULL_TREE);
5627 249573 : TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
5628 249573 : vec_safe_push (all_translation_units, tu);
5629 249573 : return tu;
5630 : }
5631 :
5632 :
5633 : /* BLOCK nodes are used to represent the structure of binding contours
5634 : and declarations, once those contours have been exited and their contents
5635 : compiled. This information is used for outputting debugging info. */
5636 :
5637 : tree
5638 713802 : build_block (tree vars, tree subblocks, tree supercontext, tree chain)
5639 : {
5640 713802 : tree block = make_node (BLOCK);
5641 :
5642 713802 : BLOCK_VARS (block) = vars;
5643 713802 : BLOCK_SUBBLOCKS (block) = subblocks;
5644 713802 : BLOCK_SUPERCONTEXT (block) = supercontext;
5645 713802 : BLOCK_CHAIN (block) = chain;
5646 713802 : return block;
5647 : }
5648 :
5649 :
5650 : /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
5651 :
5652 : LOC is the location to use in tree T. */
5653 :
5654 : void
5655 14133203771 : protected_set_expr_location (tree t, location_t loc)
5656 : {
5657 14133203771 : if (CAN_HAVE_LOCATION_P (t))
5658 2268777577 : SET_EXPR_LOCATION (t, loc);
5659 11755011334 : else if (t && TREE_CODE (t) == STATEMENT_LIST)
5660 : {
5661 22243 : t = expr_single (t);
5662 22243 : if (t && CAN_HAVE_LOCATION_P (t))
5663 18 : SET_EXPR_LOCATION (t, loc);
5664 : }
5665 14133203771 : }
5666 :
5667 : /* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has
5668 : UNKNOWN_LOCATION. */
5669 :
5670 : void
5671 35979804 : protected_set_expr_location_if_unset (tree t, location_t loc)
5672 : {
5673 35979804 : t = expr_single (t);
5674 35979804 : if (t && !EXPR_HAS_LOCATION (t))
5675 24665578 : protected_set_expr_location (t, loc);
5676 35979804 : }
5677 :
5678 : /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5679 : of the various TYPE_QUAL values. */
5680 :
5681 : static void
5682 112051990 : set_type_quals (tree type, int type_quals)
5683 : {
5684 112051990 : TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
5685 112051990 : TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
5686 112051990 : TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
5687 112051990 : TYPE_ATOMIC (type) = (type_quals & TYPE_QUAL_ATOMIC) != 0;
5688 112051990 : TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
5689 112051990 : }
5690 :
5691 : /* Returns true iff CAND and BASE have equivalent language-specific
5692 : qualifiers. */
5693 :
5694 : bool
5695 4208279315 : check_lang_type (const_tree cand, const_tree base)
5696 : {
5697 4208279315 : if (lang_hooks.types.type_hash_eq == NULL)
5698 : return true;
5699 : /* type_hash_eq currently only applies to these types. */
5700 4152287464 : if (TREE_CODE (cand) != FUNCTION_TYPE
5701 4152287464 : && TREE_CODE (cand) != METHOD_TYPE)
5702 : return true;
5703 1578856 : return lang_hooks.types.type_hash_eq (cand, base);
5704 : }
5705 :
5706 : /* This function checks to see if TYPE matches the size one of the built-in
5707 : atomic types, and returns that core atomic type. */
5708 :
5709 : static tree
5710 8862 : find_atomic_core_type (const_tree type)
5711 : {
5712 8862 : tree base_atomic_type;
5713 :
5714 : /* Only handle complete types. */
5715 8862 : if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
5716 : return NULL_TREE;
5717 :
5718 8850 : switch (tree_to_uhwi (TYPE_SIZE (type)))
5719 : {
5720 2703 : case 8:
5721 2703 : base_atomic_type = atomicQI_type_node;
5722 2703 : break;
5723 :
5724 860 : case 16:
5725 860 : base_atomic_type = atomicHI_type_node;
5726 860 : break;
5727 :
5728 1115 : case 32:
5729 1115 : base_atomic_type = atomicSI_type_node;
5730 1115 : break;
5731 :
5732 2742 : case 64:
5733 2742 : base_atomic_type = atomicDI_type_node;
5734 2742 : break;
5735 :
5736 1310 : case 128:
5737 1310 : base_atomic_type = atomicTI_type_node;
5738 1310 : break;
5739 :
5740 : default:
5741 : base_atomic_type = NULL_TREE;
5742 : }
5743 :
5744 : return base_atomic_type;
5745 : }
5746 :
5747 : /* Returns true iff unqualified CAND and BASE are equivalent. */
5748 :
5749 : bool
5750 6220019330 : check_base_type (const_tree cand, const_tree base)
5751 : {
5752 6220019330 : if (TYPE_NAME (cand) != TYPE_NAME (base)
5753 : /* Apparently this is needed for Objective-C. */
5754 5500307355 : || TYPE_CONTEXT (cand) != TYPE_CONTEXT (base)
5755 11720326685 : || !attribute_list_equal (TYPE_ATTRIBUTES (cand),
5756 5500307355 : TYPE_ATTRIBUTES (base)))
5757 719711975 : return false;
5758 : /* Check alignment. */
5759 5500307355 : if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
5760 5500307355 : && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
5761 : return true;
5762 : /* Atomic types increase minimal alignment. We must to do so as well
5763 : or we get duplicated canonical types. See PR88686. */
5764 10818 : if ((TYPE_QUALS (cand) & TYPE_QUAL_ATOMIC))
5765 : {
5766 : /* See if this object can map to a basic atomic type. */
5767 1775 : tree atomic_type = find_atomic_core_type (cand);
5768 1775 : if (atomic_type && TYPE_ALIGN (atomic_type) == TYPE_ALIGN (cand))
5769 : return true;
5770 : }
5771 : return false;
5772 : }
5773 :
5774 : /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5775 :
5776 : bool
5777 6805569942 : check_qualified_type (const_tree cand, const_tree base, int type_quals)
5778 : {
5779 6805569942 : return (TYPE_QUALS (cand) == type_quals
5780 4925941180 : && check_base_type (cand, base)
5781 11012120347 : && check_lang_type (cand, base));
5782 : }
5783 :
5784 : /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5785 :
5786 : static bool
5787 3632065 : check_aligned_type (const_tree cand, const_tree base, unsigned int align)
5788 : {
5789 3632065 : return (TYPE_QUALS (cand) == TYPE_QUALS (base)
5790 2955071 : && TYPE_NAME (cand) == TYPE_NAME (base)
5791 : /* Apparently this is needed for Objective-C. */
5792 2119136 : && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
5793 : /* Check alignment. */
5794 2119136 : && TYPE_ALIGN (cand) == align
5795 : /* Check this is a user-aligned type as build_aligned_type
5796 : would create. */
5797 1002875 : && TYPE_USER_ALIGN (cand)
5798 1000270 : && attribute_list_equal (TYPE_ATTRIBUTES (cand),
5799 1000270 : TYPE_ATTRIBUTES (base))
5800 4632335 : && check_lang_type (cand, base));
5801 : }
5802 :
5803 : /* Return a version of the TYPE, qualified as indicated by the
5804 : TYPE_QUALS, if one exists. If no qualified version exists yet,
5805 : return NULL_TREE. */
5806 :
5807 : tree
5808 5701816354 : get_qualified_type (tree type, int type_quals)
5809 : {
5810 5701816354 : if (TYPE_QUALS (type) == type_quals)
5811 : return type;
5812 :
5813 4318749057 : tree mv = TYPE_MAIN_VARIANT (type);
5814 4318749057 : if (check_qualified_type (mv, type, type_quals))
5815 : return mv;
5816 :
5817 : /* Search the chain of variants to see if there is already one there just
5818 : like the one we need to have. If so, use that existing one. We must
5819 : preserve the TYPE_NAME, since there is code that depends on this. */
5820 2599026460 : for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
5821 2486757992 : if (check_qualified_type (*tp, type, type_quals))
5822 : {
5823 : /* Put the found variant at the head of the variant list so
5824 : frequently searched variants get found faster. The C++ FE
5825 : benefits greatly from this. */
5826 1575312170 : tree t = *tp;
5827 1575312170 : *tp = TYPE_NEXT_VARIANT (t);
5828 1575312170 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
5829 1575312170 : TYPE_NEXT_VARIANT (mv) = t;
5830 1575312170 : return t;
5831 : }
5832 :
5833 : return NULL_TREE;
5834 : }
5835 :
5836 : /* Like get_qualified_type, but creates the type if it does not
5837 : exist. This function never returns NULL_TREE. */
5838 :
5839 : tree
5840 5186766667 : build_qualified_type (tree type, int type_quals MEM_STAT_DECL)
5841 : {
5842 5186766667 : tree t;
5843 :
5844 : /* See if we already have the appropriate qualified variant. */
5845 5186766667 : t = get_qualified_type (type, type_quals);
5846 :
5847 : /* If not, build it. */
5848 5186766667 : if (!t)
5849 : {
5850 110624880 : t = build_variant_type_copy (type PASS_MEM_STAT);
5851 110624880 : set_type_quals (t, type_quals);
5852 :
5853 110624880 : if (((type_quals & TYPE_QUAL_ATOMIC) == TYPE_QUAL_ATOMIC))
5854 : {
5855 : /* See if this object can map to a basic atomic type. */
5856 7087 : tree atomic_type = find_atomic_core_type (type);
5857 7087 : if (atomic_type)
5858 : {
5859 : /* Ensure the alignment of this type is compatible with
5860 : the required alignment of the atomic type. */
5861 6955 : if (TYPE_ALIGN (atomic_type) > TYPE_ALIGN (t))
5862 94 : SET_TYPE_ALIGN (t, TYPE_ALIGN (atomic_type));
5863 : }
5864 : }
5865 :
5866 110624880 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5867 : /* Propagate structural equality. */
5868 5314265 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5869 105310615 : else if (TYPE_CANONICAL (type) != type)
5870 : /* Build the underlying canonical type, since it is different
5871 : from TYPE. */
5872 : {
5873 33649437 : tree c = build_qualified_type (TYPE_CANONICAL (type), type_quals);
5874 33649437 : TYPE_CANONICAL (t) = TYPE_CANONICAL (c);
5875 : }
5876 : else
5877 : /* T is its own canonical type. */
5878 71661178 : TYPE_CANONICAL (t) = t;
5879 :
5880 : }
5881 :
5882 5186766667 : return t;
5883 : }
5884 :
5885 : /* Create a variant of type T with alignment ALIGN which
5886 : is measured in bits. */
5887 :
5888 : tree
5889 1281906 : build_aligned_type (tree type, unsigned int align)
5890 : {
5891 1281906 : tree t;
5892 :
5893 1281906 : if (TYPE_PACKED (type)
5894 1281906 : || TYPE_ALIGN (type) == align)
5895 : return type;
5896 :
5897 3735548 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5898 3632065 : if (check_aligned_type (t, type, align))
5899 : return t;
5900 :
5901 103483 : t = build_variant_type_copy (type);
5902 103483 : SET_TYPE_ALIGN (t, align);
5903 103483 : TYPE_USER_ALIGN (t) = 1;
5904 :
5905 103483 : return t;
5906 : }
5907 :
5908 : /* Create a new distinct copy of TYPE. The new type is made its own
5909 : MAIN_VARIANT. If TYPE requires structural equality checks, the
5910 : resulting type requires structural equality checks; otherwise, its
5911 : TYPE_CANONICAL points to itself. */
5912 :
5913 : tree
5914 801879968 : build_distinct_type_copy (tree type MEM_STAT_DECL)
5915 : {
5916 801879968 : tree t = copy_node (type PASS_MEM_STAT);
5917 :
5918 801879968 : TYPE_POINTER_TO (t) = 0;
5919 801879968 : TYPE_REFERENCE_TO (t) = 0;
5920 :
5921 : /* Set the canonical type either to a new equivalence class, or
5922 : propagate the need for structural equality checks. */
5923 801879968 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5924 65276108 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5925 : else
5926 736603860 : TYPE_CANONICAL (t) = t;
5927 :
5928 : /* Make it its own variant. */
5929 801879968 : TYPE_MAIN_VARIANT (t) = t;
5930 801879968 : TYPE_NEXT_VARIANT (t) = 0;
5931 :
5932 : /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5933 : whose TREE_TYPE is not t. This can also happen in the Ada
5934 : frontend when using subtypes. */
5935 :
5936 801879968 : return t;
5937 : }
5938 :
5939 : /* Create a new variant of TYPE, equivalent but distinct. This is so
5940 : the caller can modify it. TYPE_CANONICAL for the return type will
5941 : be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5942 : are considered equal by the language itself (or that both types
5943 : require structural equality checks). */
5944 :
5945 : tree
5946 521617188 : build_variant_type_copy (tree type MEM_STAT_DECL)
5947 : {
5948 521617188 : tree t, m = TYPE_MAIN_VARIANT (type);
5949 :
5950 521617188 : t = build_distinct_type_copy (type PASS_MEM_STAT);
5951 :
5952 : /* Since we're building a variant, assume that it is a non-semantic
5953 : variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5954 521617188 : TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
5955 : /* Type variants have no alias set defined. */
5956 521617188 : TYPE_ALIAS_SET (t) = -1;
5957 :
5958 : /* Add the new type to the chain of variants of TYPE. */
5959 521617188 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
5960 521617188 : TYPE_NEXT_VARIANT (m) = t;
5961 521617188 : TYPE_MAIN_VARIANT (t) = m;
5962 :
5963 521617188 : return t;
5964 : }
5965 :
5966 : /* Return true if the from tree in both tree maps are equal. */
5967 :
5968 : int
5969 1862126035 : tree_map_base_eq (const void *va, const void *vb)
5970 : {
5971 1862126035 : const struct tree_map_base *const a = (const struct tree_map_base *) va,
5972 1862126035 : *const b = (const struct tree_map_base *) vb;
5973 1862126035 : return (a->from == b->from);
5974 : }
5975 :
5976 : /* Hash a from tree in a tree_base_map. */
5977 :
5978 : unsigned int
5979 0 : tree_map_base_hash (const void *item)
5980 : {
5981 0 : return htab_hash_pointer (((const struct tree_map_base *)item)->from);
5982 : }
5983 :
5984 : /* Return true if this tree map structure is marked for garbage collection
5985 : purposes. We simply return true if the from tree is marked, so that this
5986 : structure goes away when the from tree goes away. */
5987 :
5988 : bool
5989 0 : tree_map_base_marked_p (const void *p)
5990 : {
5991 0 : return ggc_marked_p (((const struct tree_map_base *) p)->from);
5992 : }
5993 :
5994 : /* Hash a from tree in a tree_map. */
5995 :
5996 : unsigned int
5997 210 : tree_map_hash (const void *item)
5998 : {
5999 210 : return (((const struct tree_map *) item)->hash);
6000 : }
6001 :
6002 : /* Hash a from tree in a tree_decl_map. */
6003 :
6004 : unsigned int
6005 1274190401 : tree_decl_map_hash (const void *item)
6006 : {
6007 1274190401 : return DECL_UID (((const struct tree_decl_map *) item)->base.from);
6008 : }
6009 :
6010 : /* Return the initialization priority for DECL. */
6011 :
6012 : priority_type
6013 22299 : decl_init_priority_lookup (tree decl)
6014 : {
6015 22299 : symtab_node *snode = symtab_node::get (decl);
6016 :
6017 22299 : if (!snode)
6018 : return DEFAULT_INIT_PRIORITY;
6019 22299 : return
6020 22299 : snode->get_init_priority ();
6021 : }
6022 :
6023 : /* Return the finalization priority for DECL. */
6024 :
6025 : priority_type
6026 1814 : decl_fini_priority_lookup (tree decl)
6027 : {
6028 1814 : cgraph_node *node = cgraph_node::get (decl);
6029 :
6030 1814 : if (!node)
6031 : return DEFAULT_INIT_PRIORITY;
6032 1814 : return
6033 1814 : node->get_fini_priority ();
6034 : }
6035 :
6036 : /* Set the initialization priority for DECL to PRIORITY. */
6037 :
6038 : void
6039 23824 : decl_init_priority_insert (tree decl, priority_type priority)
6040 : {
6041 23824 : struct symtab_node *snode;
6042 :
6043 23824 : if (priority == DEFAULT_INIT_PRIORITY)
6044 : {
6045 20367 : snode = symtab_node::get (decl);
6046 20367 : if (!snode)
6047 : return;
6048 : }
6049 3457 : else if (VAR_P (decl))
6050 45 : snode = varpool_node::get_create (decl);
6051 : else
6052 3412 : snode = cgraph_node::get_create (decl);
6053 23007 : snode->set_init_priority (priority);
6054 : }
6055 :
6056 : /* Set the finalization priority for DECL to PRIORITY. */
6057 :
6058 : void
6059 1673 : decl_fini_priority_insert (tree decl, priority_type priority)
6060 : {
6061 1673 : struct cgraph_node *node;
6062 :
6063 1673 : if (priority == DEFAULT_INIT_PRIORITY)
6064 : {
6065 104 : node = cgraph_node::get (decl);
6066 104 : if (!node)
6067 : return;
6068 : }
6069 : else
6070 1569 : node = cgraph_node::get_create (decl);
6071 1578 : node->set_fini_priority (priority);
6072 : }
6073 :
6074 : /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6075 :
6076 : static void
6077 0 : print_debug_expr_statistics (void)
6078 : {
6079 0 : fprintf (stderr, "DECL_DEBUG_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6080 : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6081 0 : (fmt_size_t) debug_expr_for_decl->size (),
6082 0 : (fmt_size_t) debug_expr_for_decl->elements (),
6083 : debug_expr_for_decl->collisions ());
6084 0 : }
6085 :
6086 : /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6087 :
6088 : static void
6089 0 : print_value_expr_statistics (void)
6090 : {
6091 0 : fprintf (stderr, "DECL_VALUE_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6092 : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6093 0 : (fmt_size_t) value_expr_for_decl->size (),
6094 0 : (fmt_size_t) value_expr_for_decl->elements (),
6095 : value_expr_for_decl->collisions ());
6096 0 : }
6097 :
6098 : /* Lookup a debug expression for FROM, and return it if we find one. */
6099 :
6100 : tree
6101 424504958 : decl_debug_expr_lookup (tree from)
6102 : {
6103 424504958 : struct tree_decl_map *h, in;
6104 424504958 : in.base.from = from;
6105 :
6106 424504958 : h = debug_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6107 424504958 : if (h)
6108 424504958 : return h->to;
6109 : return NULL_TREE;
6110 : }
6111 :
6112 : /* Insert a mapping FROM->TO in the debug expression hashtable. */
6113 :
6114 : void
6115 1305778 : decl_debug_expr_insert (tree from, tree to)
6116 : {
6117 1305778 : struct tree_decl_map *h;
6118 :
6119 1305778 : h = ggc_alloc<tree_decl_map> ();
6120 1305778 : h->base.from = from;
6121 1305778 : h->to = to;
6122 1305778 : *debug_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6123 1305778 : }
6124 :
6125 : /* Lookup a value expression for FROM, and return it if we find one. */
6126 :
6127 : tree
6128 29273291 : decl_value_expr_lookup (tree from)
6129 : {
6130 29273291 : struct tree_decl_map *h, in;
6131 29273291 : in.base.from = from;
6132 :
6133 29273291 : h = value_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6134 29273291 : if (h)
6135 29273291 : return h->to;
6136 : return NULL_TREE;
6137 : }
6138 :
6139 : /* Insert a mapping FROM->TO in the value expression hashtable. */
6140 :
6141 : void
6142 11688584 : decl_value_expr_insert (tree from, tree to)
6143 : {
6144 11688584 : struct tree_decl_map *h;
6145 :
6146 : /* Uses of FROM shouldn't look like they happen at the location of TO. */
6147 11688584 : to = protected_set_expr_location_unshare (to, UNKNOWN_LOCATION);
6148 :
6149 11688584 : h = ggc_alloc<tree_decl_map> ();
6150 11688584 : h->base.from = from;
6151 11688584 : h->to = to;
6152 11688584 : *value_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6153 11688584 : }
6154 :
6155 : /* Lookup a vector of debug arguments for FROM, and return it if we
6156 : find one. */
6157 :
6158 : vec<tree, va_gc> **
6159 823084 : decl_debug_args_lookup (tree from)
6160 : {
6161 823084 : struct tree_vec_map *h, in;
6162 :
6163 823084 : if (!DECL_HAS_DEBUG_ARGS_P (from))
6164 : return NULL;
6165 692095 : gcc_checking_assert (debug_args_for_decl != NULL);
6166 692095 : in.base.from = from;
6167 692095 : h = debug_args_for_decl->find_with_hash (&in, DECL_UID (from));
6168 692095 : if (h)
6169 688870 : return &h->to;
6170 : return NULL;
6171 : }
6172 :
6173 : /* Insert a mapping FROM->empty vector of debug arguments in the value
6174 : expression hashtable. */
6175 :
6176 : vec<tree, va_gc> **
6177 269585 : decl_debug_args_insert (tree from)
6178 : {
6179 269585 : struct tree_vec_map *h;
6180 269585 : tree_vec_map **loc;
6181 :
6182 269585 : if (DECL_HAS_DEBUG_ARGS_P (from))
6183 190117 : return decl_debug_args_lookup (from);
6184 79468 : if (debug_args_for_decl == NULL)
6185 8424 : debug_args_for_decl = hash_table<tree_vec_map_cache_hasher>::create_ggc (64);
6186 79468 : h = ggc_alloc<tree_vec_map> ();
6187 79468 : h->base.from = from;
6188 79468 : h->to = NULL;
6189 79468 : loc = debug_args_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT);
6190 79468 : *loc = h;
6191 79468 : DECL_HAS_DEBUG_ARGS_P (from) = 1;
6192 79468 : return &h->to;
6193 : }
6194 :
6195 : /* Hashing of types so that we don't make duplicates.
6196 : The entry point is `type_hash_canon'. */
6197 :
6198 : /* Generate the default hash code for TYPE. This is designed for
6199 : speed, rather than maximum entropy. */
6200 :
6201 : hashval_t
6202 1419630514 : type_hash_canon_hash (tree type)
6203 : {
6204 1419630514 : inchash::hash hstate;
6205 :
6206 1419630514 : hstate.add_int (TREE_CODE (type));
6207 :
6208 1419630514 : hstate.add_flag (TYPE_STRUCTURAL_EQUALITY_P (type));
6209 :
6210 1419630514 : if (TREE_TYPE (type))
6211 1419549624 : hstate.add_object (TYPE_HASH (TREE_TYPE (type)));
6212 :
6213 1694612379 : for (tree t = TYPE_ATTRIBUTES (type); t; t = TREE_CHAIN (t))
6214 : /* Just the identifier is adequate to distinguish. */
6215 274981865 : hstate.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (t)));
6216 :
6217 1419630514 : switch (TREE_CODE (type))
6218 : {
6219 342544338 : case METHOD_TYPE:
6220 342544338 : hstate.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type)));
6221 : /* FALLTHROUGH. */
6222 1231114503 : case FUNCTION_TYPE:
6223 4839138829 : for (tree t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
6224 3608024326 : if (TREE_VALUE (t) != error_mark_node)
6225 3608013215 : hstate.add_object (TYPE_HASH (TREE_VALUE (t)));
6226 : break;
6227 :
6228 936600 : case OFFSET_TYPE:
6229 936600 : hstate.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type)));
6230 936600 : break;
6231 :
6232 69527376 : case ARRAY_TYPE:
6233 69527376 : {
6234 69527376 : if (TYPE_DOMAIN (type))
6235 66473825 : hstate.add_object (TYPE_HASH (TYPE_DOMAIN (type)));
6236 69527376 : if (!AGGREGATE_TYPE_P (TREE_TYPE (type)))
6237 : {
6238 67131010 : unsigned typeless = TYPE_TYPELESS_STORAGE (type);
6239 67131010 : hstate.add_object (typeless);
6240 : }
6241 : }
6242 : break;
6243 :
6244 41699638 : case INTEGER_TYPE:
6245 41699638 : {
6246 41699638 : tree t = TYPE_MAX_VALUE (type);
6247 41699638 : if (!t)
6248 548156 : t = TYPE_MIN_VALUE (type);
6249 83399277 : for (int i = 0; i < TREE_INT_CST_NUNITS (t); i++)
6250 41699639 : hstate.add_object (TREE_INT_CST_ELT (t, i));
6251 : break;
6252 : }
6253 :
6254 58771 : case BITINT_TYPE:
6255 58771 : {
6256 58771 : unsigned prec = TYPE_PRECISION (type);
6257 58771 : unsigned uns = TYPE_UNSIGNED (type);
6258 58771 : hstate.add_object (prec);
6259 58771 : hstate.add_int (uns);
6260 58771 : break;
6261 : }
6262 :
6263 11972 : case REAL_TYPE:
6264 11972 : case FIXED_POINT_TYPE:
6265 11972 : {
6266 11972 : unsigned prec = TYPE_PRECISION (type);
6267 11972 : hstate.add_object (prec);
6268 11972 : break;
6269 : }
6270 :
6271 70795000 : case VECTOR_TYPE:
6272 70795000 : hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type));
6273 70795000 : break;
6274 :
6275 : case REFERENCE_TYPE:
6276 1419630514 : hstate.add_flag (TYPE_REF_IS_RVALUE (type));
6277 : break;
6278 :
6279 : default:
6280 : break;
6281 : }
6282 :
6283 1419630514 : return hstate.end ();
6284 : }
6285 :
6286 : /* These are the Hashtable callback functions. */
6287 :
6288 : /* Returns true iff the types are equivalent. */
6289 :
6290 : bool
6291 8664187345 : type_cache_hasher::equal (type_hash *a, type_hash *b)
6292 : {
6293 : /* First test the things that are the same for all types. */
6294 8664187345 : if (a->hash != b->hash
6295 694948997 : || TREE_CODE (a->type) != TREE_CODE (b->type)
6296 694948597 : || TREE_TYPE (a->type) != TREE_TYPE (b->type)
6297 694947933 : || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
6298 694947933 : TYPE_ATTRIBUTES (b->type))
6299 9352176088 : || (TREE_CODE (a->type) != COMPLEX_TYPE
6300 685893114 : && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
6301 7977039072 : return false;
6302 :
6303 : /* Be careful about comparing arrays before and after the element type
6304 : has been completed; don't compare TYPE_ALIGN unless both types are
6305 : complete. */
6306 1371033239 : if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
6307 1371033239 : && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
6308 683884421 : || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
6309 604 : return false;
6310 :
6311 687147669 : if (TYPE_STRUCTURAL_EQUALITY_P (a->type)
6312 687147669 : != TYPE_STRUCTURAL_EQUALITY_P (b->type))
6313 : return false;
6314 :
6315 687144056 : switch (TREE_CODE (a->type))
6316 : {
6317 : case VOID_TYPE:
6318 : case OPAQUE_TYPE:
6319 : case COMPLEX_TYPE:
6320 : case POINTER_TYPE:
6321 : case NULLPTR_TYPE:
6322 : return true;
6323 :
6324 64489474 : case VECTOR_TYPE:
6325 64489474 : return known_eq (TYPE_VECTOR_SUBPARTS (a->type),
6326 : TYPE_VECTOR_SUBPARTS (b->type));
6327 :
6328 0 : case ENUMERAL_TYPE:
6329 0 : if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6330 0 : && !(TYPE_VALUES (a->type)
6331 0 : && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6332 0 : && TYPE_VALUES (b->type)
6333 0 : && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
6334 0 : && type_list_equal (TYPE_VALUES (a->type),
6335 0 : TYPE_VALUES (b->type))))
6336 0 : return false;
6337 :
6338 : /* fall through */
6339 :
6340 38946660 : case INTEGER_TYPE:
6341 38946660 : case REAL_TYPE:
6342 38946660 : case BOOLEAN_TYPE:
6343 38946660 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6344 : return false;
6345 38933240 : return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
6346 727149 : || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
6347 727149 : TYPE_MAX_VALUE (b->type)))
6348 39258346 : && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
6349 477890 : || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
6350 477890 : TYPE_MIN_VALUE (b->type))));
6351 :
6352 53176 : case BITINT_TYPE:
6353 53176 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6354 : return false;
6355 53176 : return TYPE_UNSIGNED (a->type) == TYPE_UNSIGNED (b->type);
6356 :
6357 0 : case FIXED_POINT_TYPE:
6358 0 : return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
6359 :
6360 711572 : case OFFSET_TYPE:
6361 711572 : return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
6362 :
6363 93223988 : case METHOD_TYPE:
6364 93223988 : if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
6365 93223988 : && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6366 93092310 : || (TYPE_ARG_TYPES (a->type)
6367 93092310 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6368 93092310 : && TYPE_ARG_TYPES (b->type)
6369 93092310 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6370 93092310 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6371 93092310 : TYPE_ARG_TYPES (b->type)))))
6372 : break;
6373 : return false;
6374 58691556 : case ARRAY_TYPE:
6375 : /* Don't compare TYPE_TYPELESS_STORAGE flag on aggregates,
6376 : where the flag should be inherited from the element type
6377 : and can change after ARRAY_TYPEs are created; on non-aggregates
6378 : compare it and hash it, scalars will never have that flag set
6379 : and we need to differentiate between arrays created by different
6380 : front-ends or middle-end created arrays. */
6381 58691556 : return (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
6382 58691556 : && (AGGREGATE_TYPE_P (TREE_TYPE (a->type))
6383 56916076 : || (TYPE_TYPELESS_STORAGE (a->type)
6384 56916076 : == TYPE_TYPELESS_STORAGE (b->type))));
6385 :
6386 0 : case RECORD_TYPE:
6387 0 : case UNION_TYPE:
6388 0 : case QUAL_UNION_TYPE:
6389 0 : return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
6390 0 : || (TYPE_FIELDS (a->type)
6391 0 : && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
6392 0 : && TYPE_FIELDS (b->type)
6393 0 : && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
6394 0 : && type_list_equal (TYPE_FIELDS (a->type),
6395 0 : TYPE_FIELDS (b->type))));
6396 :
6397 428931543 : case FUNCTION_TYPE:
6398 428931543 : if ((TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6399 273296488 : && (TYPE_NO_NAMED_ARGS_STDARG_P (a->type)
6400 273296488 : == TYPE_NO_NAMED_ARGS_STDARG_P (b->type)))
6401 429229973 : || (TYPE_ARG_TYPES (a->type)
6402 155635055 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6403 155635055 : && TYPE_ARG_TYPES (b->type)
6404 155635040 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6405 155635040 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6406 155635040 : TYPE_ARG_TYPES (b->type))))
6407 : break;
6408 : return false;
6409 :
6410 9 : case REFERENCE_TYPE:
6411 9 : return TYPE_REF_IS_RVALUE (a->type) == TYPE_REF_IS_RVALUE (b->type);
6412 :
6413 : default:
6414 : return false;
6415 : }
6416 :
6417 495747114 : if (lang_hooks.types.type_hash_eq != NULL)
6418 316575709 : return lang_hooks.types.type_hash_eq (a->type, b->type);
6419 :
6420 : return true;
6421 : }
6422 :
6423 : /* Given TYPE, and HASHCODE its hash code, return the canonical
6424 : object for an identical type if one already exists.
6425 : Otherwise, return TYPE, and record it as the canonical object.
6426 :
6427 : To use this function, first create a type of the sort you want.
6428 : Then compute its hash code from the fields of the type that
6429 : make it different from other similar types.
6430 : Then call this function and use the value. */
6431 :
6432 : tree
6433 1420690427 : type_hash_canon (unsigned int hashcode, tree type)
6434 : {
6435 1420690427 : type_hash in;
6436 1420690427 : type_hash **loc;
6437 :
6438 : /* The hash table only contains main variants, so ensure that's what we're
6439 : being passed. */
6440 1420690427 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
6441 :
6442 : /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6443 : must call that routine before comparing TYPE_ALIGNs. */
6444 1420690427 : layout_type (type);
6445 :
6446 1420690427 : in.hash = hashcode;
6447 1420690427 : in.type = type;
6448 :
6449 1420690427 : loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT);
6450 1420690427 : if (*loc)
6451 : {
6452 660161231 : tree t1 = ((type_hash *) *loc)->type;
6453 660161231 : gcc_assert (TYPE_MAIN_VARIANT (t1) == t1
6454 : && t1 != type);
6455 660161231 : if (TYPE_UID (type) + 1 == next_type_uid)
6456 654988635 : --next_type_uid;
6457 : /* Free also min/max values and the cache for integer
6458 : types. This can't be done in free_node, as LTO frees
6459 : those on its own. */
6460 660161231 : if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE)
6461 : {
6462 38425425 : if (TYPE_MIN_VALUE (type)
6463 38425425 : && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
6464 : {
6465 : /* Zero is always in TYPE_CACHED_VALUES. */
6466 371466 : if (! TYPE_UNSIGNED (type))
6467 216311 : int_cst_hash_table->remove_elt (TYPE_MIN_VALUE (type));
6468 371466 : ggc_free (TYPE_MIN_VALUE (type));
6469 : }
6470 38425425 : if (TYPE_MAX_VALUE (type)
6471 38425425 : && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
6472 : {
6473 371466 : int_cst_hash_table->remove_elt (TYPE_MAX_VALUE (type));
6474 371466 : ggc_free (TYPE_MAX_VALUE (type));
6475 : }
6476 38425425 : if (TYPE_CACHED_VALUES_P (type))
6477 155155 : ggc_free (TYPE_CACHED_VALUES (type));
6478 : }
6479 660161231 : free_node (type);
6480 660161231 : return t1;
6481 : }
6482 : else
6483 : {
6484 760529196 : struct type_hash *h;
6485 :
6486 760529196 : h = ggc_alloc<type_hash> ();
6487 760529196 : h->hash = hashcode;
6488 760529196 : h->type = type;
6489 760529196 : *loc = h;
6490 :
6491 760529196 : return type;
6492 : }
6493 : }
6494 :
6495 : static void
6496 0 : print_type_hash_statistics (void)
6497 : {
6498 0 : fprintf (stderr, "Type hash: size " HOST_SIZE_T_PRINT_DEC ", "
6499 : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6500 0 : (fmt_size_t) type_hash_table->size (),
6501 0 : (fmt_size_t) type_hash_table->elements (),
6502 : type_hash_table->collisions ());
6503 0 : }
6504 :
6505 : /* Given two lists of types
6506 : (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6507 : return 1 if the lists contain the same types in the same order.
6508 : Also, the TREE_PURPOSEs must match. */
6509 :
6510 : bool
6511 248727872 : type_list_equal (const_tree l1, const_tree l2)
6512 : {
6513 248727872 : const_tree t1, t2;
6514 :
6515 933577172 : for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6516 710959210 : if (TREE_VALUE (t1) != TREE_VALUE (t2)
6517 710959210 : || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6518 26111260 : && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6519 1390 : && (TREE_TYPE (TREE_PURPOSE (t1))
6520 1390 : == TREE_TYPE (TREE_PURPOSE (t2))))))
6521 26109910 : return false;
6522 :
6523 222617962 : return t1 == t2;
6524 : }
6525 :
6526 : /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6527 : given by TYPE. If the argument list accepts variable arguments,
6528 : then this function counts only the ordinary arguments. */
6529 :
6530 : int
6531 79218331 : type_num_arguments (const_tree fntype)
6532 : {
6533 79218331 : int i = 0;
6534 :
6535 307734021 : for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
6536 : /* If the function does not take a variable number of arguments,
6537 : the last element in the list will have type `void'. */
6538 289099418 : if (VOID_TYPE_P (TREE_VALUE (t)))
6539 : break;
6540 : else
6541 228515690 : ++i;
6542 :
6543 79218331 : return i;
6544 : }
6545 :
6546 : /* Return the type of the function TYPE's argument ARGNO if known.
6547 : For vararg function's where ARGNO refers to one of the variadic
6548 : arguments return null. Otherwise, return a void_type_node for
6549 : out-of-bounds ARGNO. */
6550 :
6551 : tree
6552 78161527 : type_argument_type (const_tree fntype, unsigned argno)
6553 : {
6554 : /* Treat zero the same as an out-of-bounds argument number. */
6555 78161527 : if (!argno)
6556 0 : return void_type_node;
6557 :
6558 78161527 : function_args_iterator iter;
6559 :
6560 78161527 : tree argtype;
6561 78161527 : unsigned i = 1;
6562 168603907 : FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
6563 : {
6564 : /* A vararg function's argument list ends in a null. Otherwise,
6565 : an ordinary function's argument list ends with void. Return
6566 : null if ARGNO refers to a vararg argument, void_type_node if
6567 : it's out of bounds, and the formal argument type otherwise. */
6568 163012958 : if (!argtype)
6569 : break;
6570 :
6571 163012958 : if (i == argno || VOID_TYPE_P (argtype))
6572 : return argtype;
6573 :
6574 90442380 : ++i;
6575 : }
6576 :
6577 : return NULL_TREE;
6578 : }
6579 :
6580 : /* True if integer constants T1 and T2
6581 : represent the same constant value. */
6582 :
6583 : bool
6584 1310249615 : tree_int_cst_equal (const_tree t1, const_tree t2)
6585 : {
6586 1310249615 : if (t1 == t2)
6587 : return true;
6588 :
6589 652712071 : if (t1 == 0 || t2 == 0)
6590 : return false;
6591 :
6592 652308288 : STRIP_ANY_LOCATION_WRAPPER (t1);
6593 652308288 : STRIP_ANY_LOCATION_WRAPPER (t2);
6594 :
6595 652308288 : if (TREE_CODE (t1) == INTEGER_CST
6596 647740337 : && TREE_CODE (t2) == INTEGER_CST
6597 1300048625 : && wi::to_widest (t1) == wi::to_widest (t2))
6598 20035742 : return true;
6599 :
6600 : return false;
6601 : }
6602 :
6603 : /* Return true if T is an INTEGER_CST whose numerical value (extended
6604 : according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
6605 :
6606 : bool
6607 2596091227 : tree_fits_shwi_p (const_tree t)
6608 : {
6609 2596091227 : return (t != NULL_TREE
6610 2596091136 : && TREE_CODE (t) == INTEGER_CST
6611 5188614512 : && wi::fits_shwi_p (wi::to_widest (t)));
6612 : }
6613 :
6614 : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6615 : value (extended according to TYPE_UNSIGNED) fits in a poly_int64. */
6616 :
6617 : bool
6618 968680665 : tree_fits_poly_int64_p (const_tree t)
6619 : {
6620 968680665 : if (t == NULL_TREE)
6621 : return false;
6622 931711171 : if (POLY_INT_CST_P (t))
6623 : {
6624 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6625 : if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t, i))))
6626 : return false;
6627 : return true;
6628 : }
6629 931711171 : return (TREE_CODE (t) == INTEGER_CST
6630 1863529030 : && wi::fits_shwi_p (wi::to_widest (t)));
6631 : }
6632 :
6633 : /* Return true if T is an INTEGER_CST whose numerical value (extended
6634 : according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
6635 :
6636 : bool
6637 4123547328 : tree_fits_uhwi_p (const_tree t)
6638 : {
6639 4123547328 : return (t != NULL_TREE
6640 4122943213 : && TREE_CODE (t) == INTEGER_CST
6641 8241366299 : && wi::fits_uhwi_p (wi::to_widest (t)));
6642 : }
6643 :
6644 : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6645 : value (extended according to TYPE_UNSIGNED) fits in a poly_uint64. */
6646 :
6647 : bool
6648 1060541080 : tree_fits_poly_uint64_p (const_tree t)
6649 : {
6650 1060541080 : if (t == NULL_TREE)
6651 : return false;
6652 1060183785 : if (POLY_INT_CST_P (t))
6653 : {
6654 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6655 : if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t, i))))
6656 : return false;
6657 : return true;
6658 : }
6659 1060183785 : return (TREE_CODE (t) == INTEGER_CST
6660 2120368965 : && wi::fits_uhwi_p (wi::to_widest (t)));
6661 : }
6662 :
6663 : /* Return true if T is an INTEGER_CST whose numerical value (extended according
6664 : to TYPE_UNSIGNED) fits in a sanitize_code_type (uint64_t). */
6665 :
6666 : bool
6667 90 : tree_fits_sanitize_code_type_p (const_tree t)
6668 : {
6669 90 : if (t == NULL_TREE)
6670 : return false;
6671 90 : return (TREE_CODE (t) == INTEGER_CST
6672 180 : && wi::fits_uhwi_p (wi::to_widest (t)));
6673 : }
6674 :
6675 : /* T is an INTEGER_CST whose numerical value (extended according to
6676 : TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
6677 : HOST_WIDE_INT. */
6678 :
6679 : HOST_WIDE_INT
6680 1443324398 : tree_to_shwi (const_tree t)
6681 : {
6682 1443324398 : gcc_assert (tree_fits_shwi_p (t));
6683 1443324398 : return TREE_INT_CST_LOW (t);
6684 : }
6685 :
6686 : /* T is an INTEGER_CST whose numerical value (extended according to
6687 : TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
6688 : HOST_WIDE_INT. */
6689 :
6690 : unsigned HOST_WIDE_INT
6691 995163612 : tree_to_uhwi (const_tree t)
6692 : {
6693 995163612 : gcc_assert (tree_fits_uhwi_p (t));
6694 995163612 : return TREE_INT_CST_LOW (t);
6695 : }
6696 :
6697 : /* T is an INTEGER_CST whose numerical value (extended according to
6698 : TYPE_UNSIGNED) fits in a sanitize_code_type. Return that
6699 : sanitize_code_type. */
6700 :
6701 : sanitize_code_type
6702 90 : tree_to_sanitize_code_type (const_tree t)
6703 : {
6704 90 : gcc_assert (tree_fits_sanitize_code_type_p (t));
6705 90 : return TREE_INT_CST_LOW (t);
6706 : }
6707 :
6708 : /* Return the most significant (sign) bit of T. */
6709 :
6710 : int
6711 44655406 : tree_int_cst_sign_bit (const_tree t)
6712 : {
6713 44655406 : unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
6714 :
6715 44655406 : return wi::extract_uhwi (wi::to_wide (t), bitno, 1);
6716 : }
6717 :
6718 : /* Return an indication of the sign of the integer constant T.
6719 : The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6720 : Note that -1 will never be returned if T's type is unsigned. */
6721 :
6722 : int
6723 1906377563 : tree_int_cst_sgn (const_tree t)
6724 : {
6725 1906377563 : if (wi::to_wide (t) == 0)
6726 : return 0;
6727 1774559984 : else if (TYPE_UNSIGNED (TREE_TYPE (t)))
6728 : return 1;
6729 77382646 : else if (wi::neg_p (wi::to_wide (t)))
6730 : return -1;
6731 : else
6732 : return 1;
6733 : }
6734 :
6735 : /* Return the minimum number of bits needed to represent VALUE in a
6736 : signed or unsigned type, UNSIGNEDP says which. */
6737 :
6738 : unsigned int
6739 3675021 : tree_int_cst_min_precision (tree value, signop sgn)
6740 : {
6741 : /* If the value is negative, compute its negative minus 1. The latter
6742 : adjustment is because the absolute value of the largest negative value
6743 : is one larger than the largest positive value. This is equivalent to
6744 : a bit-wise negation, so use that operation instead. */
6745 :
6746 3675021 : if (tree_int_cst_sgn (value) < 0)
6747 100375 : value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
6748 :
6749 : /* Return the number of bits needed, taking into account the fact
6750 : that we need one more bit for a signed than unsigned type.
6751 : If value is 0 or -1, the minimum precision is 1 no matter
6752 : whether unsignedp is true or false. */
6753 :
6754 3675021 : if (integer_zerop (value))
6755 : return 1;
6756 : else
6757 5021506 : return tree_floor_log2 (value) + 1 + (sgn == SIGNED ? 1 : 0) ;
6758 : }
6759 :
6760 : /* Return truthvalue of whether T1 is the same tree structure as T2.
6761 : Return 1 if they are the same.
6762 : Return 0 if they are understandably different.
6763 : Return -1 if either contains tree structure not understood by
6764 : this function. */
6765 :
6766 : int
6767 203211538 : simple_cst_equal (const_tree t1, const_tree t2)
6768 : {
6769 206824289 : enum tree_code code1, code2;
6770 206824289 : int cmp;
6771 206824289 : int i;
6772 :
6773 206824289 : if (t1 == t2)
6774 : return 1;
6775 129241129 : if (t1 == 0 || t2 == 0)
6776 : return 0;
6777 :
6778 : /* For location wrappers to be the same, they must be at the same
6779 : source location (and wrap the same thing). */
6780 120998342 : if (location_wrapper_p (t1) && location_wrapper_p (t2))
6781 : {
6782 12392456 : if (EXPR_LOCATION (t1) != EXPR_LOCATION (t2))
6783 : return 0;
6784 654 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6785 : }
6786 :
6787 108605886 : code1 = TREE_CODE (t1);
6788 108605886 : code2 = TREE_CODE (t2);
6789 :
6790 108605886 : if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
6791 : {
6792 3600666 : if (CONVERT_EXPR_CODE_P (code2)
6793 3599961 : || code2 == NON_LVALUE_EXPR)
6794 705 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6795 : else
6796 3599961 : return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
6797 : }
6798 :
6799 105005220 : else if (CONVERT_EXPR_CODE_P (code2)
6800 105005205 : || code2 == NON_LVALUE_EXPR)
6801 113 : return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
6802 :
6803 105005107 : if (code1 != code2)
6804 : return 0;
6805 :
6806 100727069 : switch (code1)
6807 : {
6808 91417802 : case INTEGER_CST:
6809 91417802 : return wi::to_widest (t1) == wi::to_widest (t2);
6810 :
6811 93 : case REAL_CST:
6812 93 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
6813 :
6814 0 : case FIXED_CST:
6815 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
6816 :
6817 3134730 : case STRING_CST:
6818 3134730 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
6819 3134730 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
6820 3584540 : TREE_STRING_LENGTH (t1)));
6821 :
6822 79 : case CONSTRUCTOR:
6823 79 : {
6824 79 : unsigned HOST_WIDE_INT idx;
6825 79 : vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1);
6826 79 : vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);
6827 :
6828 103 : if (vec_safe_length (v1) != vec_safe_length (v2))
6829 : return 0;
6830 :
6831 85 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
6832 : {
6833 12 : if ((*v1)[idx].index
6834 12 : && TREE_CODE ((*v1)[idx].index) == FIELD_DECL)
6835 : {
6836 9 : if ((*v1)[idx].index != (*v2)[idx].index)
6837 : return 0;
6838 : }
6839 : else
6840 : {
6841 3 : cmp = simple_cst_equal ((*v1)[idx].index, (*v2)[idx].index);
6842 3 : if (cmp <= 0)
6843 : return cmp;
6844 : }
6845 12 : cmp = simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value);
6846 12 : if (cmp <= 0)
6847 : return cmp;
6848 : }
6849 : return 1;
6850 : }
6851 :
6852 0 : case SAVE_EXPR:
6853 0 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6854 :
6855 197675 : case CALL_EXPR:
6856 197675 : cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
6857 197675 : if (cmp <= 0)
6858 : return cmp;
6859 81461 : if (call_expr_nargs (t1) != call_expr_nargs (t2))
6860 : return 0;
6861 81461 : {
6862 81461 : const_tree arg1, arg2;
6863 81461 : const_call_expr_arg_iterator iter1, iter2;
6864 162922 : for (arg1 = first_const_call_expr_arg (t1, &iter1),
6865 81461 : arg2 = first_const_call_expr_arg (t2, &iter2);
6866 81491 : arg1 && arg2;
6867 30 : arg1 = next_const_call_expr_arg (&iter1),
6868 30 : arg2 = next_const_call_expr_arg (&iter2))
6869 : {
6870 81447 : cmp = simple_cst_equal (arg1, arg2);
6871 81447 : if (cmp <= 0)
6872 : return cmp;
6873 : }
6874 44 : return arg1 == arg2;
6875 : }
6876 :
6877 11110 : case TARGET_EXPR:
6878 : /* Special case: if either target is an unallocated VAR_DECL,
6879 : it means that it's going to be unified with whatever the
6880 : TARGET_EXPR is really supposed to initialize, so treat it
6881 : as being equivalent to anything. */
6882 11110 : if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
6883 11110 : && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
6884 11110 : && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
6885 11110 : || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
6886 0 : && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
6887 0 : && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
6888 : cmp = 1;
6889 : else
6890 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6891 :
6892 0 : if (cmp <= 0)
6893 : return cmp;
6894 :
6895 11110 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
6896 :
6897 0 : case WITH_CLEANUP_EXPR:
6898 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6899 0 : if (cmp <= 0)
6900 : return cmp;
6901 :
6902 0 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
6903 :
6904 208 : case COMPONENT_REF:
6905 208 : if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
6906 208 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6907 :
6908 : return 0;
6909 :
6910 : case VAR_DECL:
6911 : case PARM_DECL:
6912 : case CONST_DECL:
6913 : case FUNCTION_DECL:
6914 : return 0;
6915 :
6916 5903698 : default:
6917 5903698 : if (POLY_INT_CST_P (t1))
6918 : /* A false return means maybe_ne rather than known_ne. */
6919 : return known_eq (poly_widest_int::from (poly_int_cst_value (t1),
6920 : TYPE_SIGN (TREE_TYPE (t1))),
6921 : poly_widest_int::from (poly_int_cst_value (t2),
6922 : TYPE_SIGN (TREE_TYPE (t2))));
6923 5903698 : break;
6924 : }
6925 :
6926 : /* This general rule works for most tree codes. All exceptions should be
6927 : handled above. If this is a language-specific tree code, we can't
6928 : trust what might be in the operand, so say we don't know
6929 : the situation. */
6930 5903698 : if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
6931 : return -1;
6932 :
6933 823348 : switch (TREE_CODE_CLASS (code1))
6934 : {
6935 : case tcc_unary:
6936 : case tcc_binary:
6937 : case tcc_comparison:
6938 : case tcc_expression:
6939 : case tcc_reference:
6940 : case tcc_statement:
6941 : cmp = 1;
6942 1122 : for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
6943 : {
6944 869 : cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
6945 869 : if (cmp <= 0)
6946 : return cmp;
6947 : }
6948 :
6949 : return cmp;
6950 :
6951 : default:
6952 : return -1;
6953 : }
6954 : }
6955 :
6956 : /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6957 : Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6958 : than U, respectively. */
6959 :
6960 : int
6961 1565099633 : compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
6962 : {
6963 1565099633 : if (tree_int_cst_sgn (t) < 0)
6964 : return -1;
6965 1565099355 : else if (!tree_fits_uhwi_p (t))
6966 : return 1;
6967 1565099330 : else if (TREE_INT_CST_LOW (t) == u)
6968 : return 0;
6969 1403038559 : else if (TREE_INT_CST_LOW (t) < u)
6970 : return -1;
6971 : else
6972 13984226 : return 1;
6973 : }
6974 :
6975 : /* Return true if SIZE represents a constant size that is in bounds of
6976 : what the middle-end and the backend accepts (covering not more than
6977 : half of the address-space).
6978 : When PERR is non-null, set *PERR on failure to the description of
6979 : why SIZE is not valid. */
6980 :
6981 : bool
6982 71867671 : valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */)
6983 : {
6984 71867671 : if (POLY_INT_CST_P (size))
6985 : {
6986 : if (TREE_OVERFLOW (size))
6987 : return false;
6988 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
6989 : if (!valid_constant_size_p (POLY_INT_CST_COEFF (size, i)))
6990 : return false;
6991 : return true;
6992 : }
6993 :
6994 71867671 : cst_size_error error;
6995 71867671 : if (!perr)
6996 65880811 : perr = &error;
6997 :
6998 71867671 : if (TREE_CODE (size) != INTEGER_CST)
6999 : {
7000 3 : *perr = cst_size_not_constant;
7001 3 : return false;
7002 : }
7003 :
7004 71867668 : if (TREE_OVERFLOW_P (size))
7005 : {
7006 60 : *perr = cst_size_overflow;
7007 60 : return false;
7008 : }
7009 :
7010 71867608 : if (tree_int_cst_sgn (size) < 0)
7011 : {
7012 422 : *perr = cst_size_negative;
7013 422 : return false;
7014 : }
7015 143734372 : if (!tree_fits_uhwi_p (size)
7016 215601558 : || (wi::to_widest (TYPE_MAX_VALUE (sizetype))
7017 215601558 : < wi::to_widest (size) * 2))
7018 : {
7019 624 : *perr = cst_size_too_big;
7020 624 : return false;
7021 : }
7022 :
7023 : return true;
7024 : }
7025 :
7026 : /* Return the precision of the type, or for a complex or vector type the
7027 : precision of the type of its elements. */
7028 :
7029 : unsigned int
7030 7514987732 : element_precision (const_tree type)
7031 : {
7032 7514987732 : if (!TYPE_P (type))
7033 6521951 : type = TREE_TYPE (type);
7034 7514987732 : enum tree_code code = TREE_CODE (type);
7035 7514987732 : if (code == COMPLEX_TYPE || code == VECTOR_TYPE)
7036 54021878 : type = TREE_TYPE (type);
7037 :
7038 7514987732 : return TYPE_PRECISION (type);
7039 : }
7040 :
7041 : /* Return true if CODE represents an associative tree code. Otherwise
7042 : return false. */
7043 : bool
7044 34855772 : associative_tree_code (enum tree_code code)
7045 : {
7046 34855772 : switch (code)
7047 : {
7048 : case BIT_IOR_EXPR:
7049 : case BIT_AND_EXPR:
7050 : case BIT_XOR_EXPR:
7051 : case PLUS_EXPR:
7052 : case MULT_EXPR:
7053 : case MIN_EXPR:
7054 : case MAX_EXPR:
7055 : return true;
7056 :
7057 24460643 : default:
7058 24460643 : break;
7059 : }
7060 24460643 : return false;
7061 : }
7062 :
7063 : /* Return true if CODE represents a commutative tree code. Otherwise
7064 : return false. */
7065 : bool
7066 1760332936 : commutative_tree_code (enum tree_code code)
7067 : {
7068 1760332936 : switch (code)
7069 : {
7070 : case PLUS_EXPR:
7071 : case MULT_EXPR:
7072 : case MULT_HIGHPART_EXPR:
7073 : case MIN_EXPR:
7074 : case MAX_EXPR:
7075 : case BIT_IOR_EXPR:
7076 : case BIT_XOR_EXPR:
7077 : case BIT_AND_EXPR:
7078 : case NE_EXPR:
7079 : case EQ_EXPR:
7080 : case UNORDERED_EXPR:
7081 : case ORDERED_EXPR:
7082 : case UNEQ_EXPR:
7083 : case LTGT_EXPR:
7084 : case TRUTH_AND_EXPR:
7085 : case TRUTH_XOR_EXPR:
7086 : case TRUTH_OR_EXPR:
7087 : case WIDEN_MULT_EXPR:
7088 : case VEC_WIDEN_MULT_HI_EXPR:
7089 : case VEC_WIDEN_MULT_LO_EXPR:
7090 : case VEC_WIDEN_MULT_EVEN_EXPR:
7091 : case VEC_WIDEN_MULT_ODD_EXPR:
7092 : return true;
7093 :
7094 929696718 : default:
7095 929696718 : break;
7096 : }
7097 929696718 : return false;
7098 : }
7099 :
7100 : /* Return true if CODE represents a ternary tree code for which the
7101 : first two operands are commutative. Otherwise return false. */
7102 : bool
7103 91769386 : commutative_ternary_tree_code (enum tree_code code)
7104 : {
7105 91769386 : switch (code)
7106 : {
7107 : case WIDEN_MULT_PLUS_EXPR:
7108 : case WIDEN_MULT_MINUS_EXPR:
7109 : case DOT_PROD_EXPR:
7110 : return true;
7111 :
7112 91760681 : default:
7113 91760681 : break;
7114 : }
7115 91760681 : return false;
7116 : }
7117 :
7118 : /* Returns true if CODE can overflow. */
7119 :
7120 : bool
7121 2999 : operation_can_overflow (enum tree_code code)
7122 : {
7123 2999 : switch (code)
7124 : {
7125 : case PLUS_EXPR:
7126 : case MINUS_EXPR:
7127 : case MULT_EXPR:
7128 : case LSHIFT_EXPR:
7129 : /* Can overflow in various ways. */
7130 : return true;
7131 : case TRUNC_DIV_EXPR:
7132 : case EXACT_DIV_EXPR:
7133 : case FLOOR_DIV_EXPR:
7134 : case CEIL_DIV_EXPR:
7135 : /* For INT_MIN / -1. */
7136 : return true;
7137 : case NEGATE_EXPR:
7138 : case ABS_EXPR:
7139 : /* For -INT_MIN. */
7140 : return true;
7141 149 : default:
7142 : /* These operators cannot overflow. */
7143 149 : return false;
7144 : }
7145 : }
7146 :
7147 : /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
7148 : ftrapv doesn't generate trapping insns for CODE. */
7149 :
7150 : bool
7151 5885585 : operation_no_trapping_overflow (tree type, enum tree_code code)
7152 : {
7153 5885585 : gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type));
7154 :
7155 : /* We don't generate instructions that trap on overflow for complex or vector
7156 : types. */
7157 5885585 : if (!INTEGRAL_TYPE_P (type))
7158 : return true;
7159 :
7160 5885585 : if (!TYPE_OVERFLOW_TRAPS (type))
7161 : return true;
7162 :
7163 1358 : switch (code)
7164 : {
7165 : case PLUS_EXPR:
7166 : case MINUS_EXPR:
7167 : case MULT_EXPR:
7168 : case NEGATE_EXPR:
7169 : case ABS_EXPR:
7170 : /* These operators can overflow, and -ftrapv generates trapping code for
7171 : these. */
7172 : return false;
7173 : case TRUNC_DIV_EXPR:
7174 : case EXACT_DIV_EXPR:
7175 : case FLOOR_DIV_EXPR:
7176 : case CEIL_DIV_EXPR:
7177 : case LSHIFT_EXPR:
7178 : /* These operators can overflow, but -ftrapv does not generate trapping
7179 : code for these. */
7180 : return true;
7181 : default:
7182 : /* These operators cannot overflow. */
7183 : return true;
7184 : }
7185 : }
7186 :
7187 : /* Constructors for pointer, array and function types.
7188 : (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7189 : constructed by language-dependent code, not here.) */
7190 :
7191 : /* Construct, lay out and return the type of pointers to TO_TYPE with
7192 : mode MODE. If MODE is VOIDmode, a pointer mode for the address
7193 : space of TO_TYPE will be picked. If CAN_ALIAS_ALL is TRUE,
7194 : indicate this type can reference all of memory. If such a type has
7195 : already been constructed, reuse it. */
7196 :
7197 : tree
7198 3081547635 : build_pointer_type_for_mode (tree to_type, machine_mode mode,
7199 : bool can_alias_all)
7200 : {
7201 3081547635 : tree t;
7202 3081547635 : bool could_alias = can_alias_all;
7203 :
7204 3081547635 : if (to_type == error_mark_node)
7205 : return error_mark_node;
7206 :
7207 3081547629 : if (mode == VOIDmode)
7208 : {
7209 2951914759 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7210 2951914759 : mode = targetm.addr_space.pointer_mode (as);
7211 : }
7212 :
7213 : /* If the pointed-to type has the may_alias attribute set, force
7214 : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7215 3081547629 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7216 4341696 : can_alias_all = true;
7217 :
7218 : /* In some cases, languages will have things that aren't a POINTER_TYPE
7219 : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7220 : In that case, return that type without regard to the rest of our
7221 : operands.
7222 :
7223 : ??? This is a kludge, but consistent with the way this function has
7224 : always operated and there doesn't seem to be a good way to avoid this
7225 : at the moment. */
7226 3081547629 : if (TYPE_POINTER_TO (to_type) != 0
7227 3081547629 : && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
7228 46344 : return TYPE_POINTER_TO (to_type);
7229 :
7230 : /* First, if we already have a type for pointers to TO_TYPE and it's
7231 : the proper mode, use it. */
7232 3082075213 : for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
7233 2922346532 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7234 : return t;
7235 :
7236 159728681 : t = make_node (POINTER_TYPE);
7237 :
7238 159728681 : TREE_TYPE (t) = to_type;
7239 159728681 : SET_TYPE_MODE (t, mode);
7240 159728681 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7241 159728681 : TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
7242 159728681 : TYPE_POINTER_TO (to_type) = t;
7243 :
7244 : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7245 159728681 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7246 5018795 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7247 154709886 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7248 46210641 : TYPE_CANONICAL (t)
7249 92421282 : = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
7250 : mode, false);
7251 :
7252 : /* Lay out the type. This function has many callers that are concerned
7253 : with expression-construction, and this simplifies them all. */
7254 159728681 : layout_type (t);
7255 :
7256 159728681 : return t;
7257 : }
7258 :
7259 : /* By default build pointers in ptr_mode. */
7260 :
7261 : tree
7262 2951225547 : build_pointer_type (tree to_type)
7263 : {
7264 2951225547 : return build_pointer_type_for_mode (to_type, VOIDmode, false);
7265 : }
7266 :
7267 : /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7268 :
7269 : tree
7270 852925443 : build_reference_type_for_mode (tree to_type, machine_mode mode,
7271 : bool can_alias_all)
7272 : {
7273 852925443 : tree t;
7274 852925443 : bool could_alias = can_alias_all;
7275 :
7276 852925443 : if (to_type == error_mark_node)
7277 : return error_mark_node;
7278 :
7279 852925443 : if (mode == VOIDmode)
7280 : {
7281 672836396 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7282 672836396 : mode = targetm.addr_space.pointer_mode (as);
7283 : }
7284 :
7285 : /* If the pointed-to type has the may_alias attribute set, force
7286 : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7287 852925443 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7288 723471 : can_alias_all = true;
7289 :
7290 : /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7291 : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7292 : In that case, return that type without regard to the rest of our
7293 : operands.
7294 :
7295 : ??? This is a kludge, but consistent with the way this function has
7296 : always operated and there doesn't seem to be a good way to avoid this
7297 : at the moment. */
7298 852925443 : if (TYPE_REFERENCE_TO (to_type) != 0
7299 852925443 : && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
7300 0 : return TYPE_REFERENCE_TO (to_type);
7301 :
7302 : /* First, if we already have a type for pointers to TO_TYPE and it's
7303 : the proper mode, use it. */
7304 852925443 : for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
7305 761420108 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7306 : return t;
7307 :
7308 91505335 : t = make_node (REFERENCE_TYPE);
7309 :
7310 91505335 : TREE_TYPE (t) = to_type;
7311 91505335 : SET_TYPE_MODE (t, mode);
7312 91505335 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7313 91505335 : TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
7314 91505335 : TYPE_REFERENCE_TO (to_type) = t;
7315 :
7316 : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7317 91505335 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7318 4847060 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7319 86658275 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7320 50031873 : TYPE_CANONICAL (t)
7321 100063746 : = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
7322 : mode, false);
7323 :
7324 91505335 : layout_type (t);
7325 :
7326 91505335 : return t;
7327 : }
7328 :
7329 :
7330 : /* Build the node for the type of references-to-TO_TYPE by default
7331 : in ptr_mode. */
7332 :
7333 : tree
7334 32771741 : build_reference_type (tree to_type)
7335 : {
7336 32771741 : return build_reference_type_for_mode (to_type, VOIDmode, false);
7337 : }
7338 :
7339 : #define MAX_INT_CACHED_PREC \
7340 : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7341 : static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
7342 :
7343 : static void
7344 256621 : clear_nonstandard_integer_type_cache (void)
7345 : {
7346 33617351 : for (size_t i = 0 ; i < 2 * MAX_INT_CACHED_PREC + 2 ; i++)
7347 : {
7348 33360730 : nonstandard_integer_type_cache[i] = NULL;
7349 : }
7350 0 : }
7351 :
7352 : /* Builds a signed or unsigned integer type of precision PRECISION.
7353 : Used for C bitfields whose precision does not match that of
7354 : built-in target types. */
7355 : tree
7356 62715737 : build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
7357 : int unsignedp)
7358 : {
7359 62715737 : tree itype, ret;
7360 :
7361 62715737 : if (unsignedp)
7362 53905926 : unsignedp = MAX_INT_CACHED_PREC + 1;
7363 :
7364 62715737 : if (precision <= MAX_INT_CACHED_PREC)
7365 : {
7366 62358935 : itype = nonstandard_integer_type_cache[precision + unsignedp];
7367 62358935 : if (itype)
7368 : return itype;
7369 : }
7370 :
7371 1059913 : itype = make_node (INTEGER_TYPE);
7372 1059913 : TYPE_PRECISION (itype) = precision;
7373 :
7374 1059913 : if (unsignedp)
7375 692749 : fixup_unsigned_type (itype);
7376 : else
7377 367164 : fixup_signed_type (itype);
7378 :
7379 1059913 : inchash::hash hstate;
7380 1059913 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7381 1059913 : ret = type_hash_canon (hstate.end (), itype);
7382 1059913 : if (precision <= MAX_INT_CACHED_PREC)
7383 703111 : nonstandard_integer_type_cache[precision + unsignedp] = ret;
7384 :
7385 : return ret;
7386 : }
7387 :
7388 : #define MAX_BOOL_CACHED_PREC \
7389 : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7390 : static GTY(()) tree nonstandard_boolean_type_cache[MAX_BOOL_CACHED_PREC + 1];
7391 :
7392 : /* Builds a boolean type of precision PRECISION.
7393 : Used for boolean vectors to choose proper vector element size. */
7394 : tree
7395 2461584 : build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision)
7396 : {
7397 2461584 : tree type;
7398 :
7399 2461584 : if (precision <= MAX_BOOL_CACHED_PREC)
7400 : {
7401 2457451 : type = nonstandard_boolean_type_cache[precision];
7402 2457451 : if (type)
7403 : return type;
7404 : }
7405 :
7406 79974 : type = make_node (BOOLEAN_TYPE);
7407 79974 : TYPE_PRECISION (type) = precision;
7408 79974 : fixup_signed_type (type);
7409 :
7410 79974 : if (precision <= MAX_INT_CACHED_PREC)
7411 75841 : nonstandard_boolean_type_cache[precision] = type;
7412 :
7413 : return type;
7414 : }
7415 :
7416 : static GTY(()) vec<tree, va_gc> *bitint_type_cache;
7417 :
7418 : /* Builds a signed or unsigned _BitInt(PRECISION) type. */
7419 : tree
7420 72727 : build_bitint_type (unsigned HOST_WIDE_INT precision, int unsignedp)
7421 : {
7422 72727 : tree itype, ret;
7423 :
7424 108701 : gcc_checking_assert (precision >= 1 + !unsignedp);
7425 :
7426 72727 : if (unsignedp)
7427 35974 : unsignedp = MAX_INT_CACHED_PREC + 1;
7428 :
7429 72727 : if (bitint_type_cache == NULL)
7430 522 : vec_safe_grow_cleared (bitint_type_cache, 2 * MAX_INT_CACHED_PREC + 2);
7431 :
7432 72727 : if (precision <= MAX_INT_CACHED_PREC)
7433 : {
7434 15558 : itype = (*bitint_type_cache)[precision + unsignedp];
7435 15558 : if (itype)
7436 : return itype;
7437 : }
7438 :
7439 58770 : itype = make_node (BITINT_TYPE);
7440 58770 : TYPE_PRECISION (itype) = precision;
7441 :
7442 58770 : if (unsignedp)
7443 29428 : fixup_unsigned_type (itype);
7444 : else
7445 29342 : fixup_signed_type (itype);
7446 :
7447 58770 : hashval_t hash = type_hash_canon_hash (itype);
7448 58770 : ret = type_hash_canon (hash, itype);
7449 58770 : if (precision <= MAX_INT_CACHED_PREC)
7450 1601 : (*bitint_type_cache)[precision + unsignedp] = ret;
7451 :
7452 : return ret;
7453 : }
7454 :
7455 : /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7456 : or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7457 : is true, reuse such a type that has already been constructed. */
7458 :
7459 : static tree
7460 42877974 : build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
7461 : {
7462 42877974 : tree itype = make_node (INTEGER_TYPE);
7463 :
7464 42877974 : TREE_TYPE (itype) = type;
7465 :
7466 42877974 : TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
7467 42877974 : TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
7468 :
7469 42877974 : TYPE_PRECISION (itype) = TYPE_PRECISION (type);
7470 42877974 : SET_TYPE_MODE (itype, TYPE_MODE (type));
7471 42877974 : TYPE_SIZE (itype) = TYPE_SIZE (type);
7472 42877974 : TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
7473 42877974 : SET_TYPE_ALIGN (itype, TYPE_ALIGN (type));
7474 42877974 : TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
7475 42877974 : SET_TYPE_WARN_IF_NOT_ALIGN (itype, TYPE_WARN_IF_NOT_ALIGN (type));
7476 :
7477 42877974 : if (!shared)
7478 : return itype;
7479 :
7480 42877974 : if ((TYPE_MIN_VALUE (itype)
7481 42877974 : && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
7482 85755112 : || (TYPE_MAX_VALUE (itype)
7483 42328982 : && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
7484 : {
7485 : /* Since we cannot reliably merge this type, we need to compare it using
7486 : structural equality checks. */
7487 1188582 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
7488 1188582 : return itype;
7489 : }
7490 :
7491 41689392 : hashval_t hash = type_hash_canon_hash (itype);
7492 41689392 : itype = type_hash_canon (hash, itype);
7493 :
7494 41689392 : return itype;
7495 : }
7496 :
7497 : /* Wrapper around build_range_type_1 with SHARED set to true. */
7498 :
7499 : tree
7500 42877974 : build_range_type (tree type, tree lowval, tree highval)
7501 : {
7502 42877974 : return build_range_type_1 (type, lowval, highval, true);
7503 : }
7504 :
7505 : /* Wrapper around build_range_type_1 with SHARED set to false. */
7506 :
7507 : tree
7508 0 : build_nonshared_range_type (tree type, tree lowval, tree highval)
7509 : {
7510 0 : return build_range_type_1 (type, lowval, highval, false);
7511 : }
7512 :
7513 : /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7514 : MAXVAL should be the maximum value in the domain
7515 : (one less than the length of the array).
7516 :
7517 : The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7518 : We don't enforce this limit, that is up to caller (e.g. language front end).
7519 : The limit exists because the result is a signed type and we don't handle
7520 : sizes that use more than one HOST_WIDE_INT. */
7521 :
7522 : tree
7523 39985452 : build_index_type (tree maxval)
7524 : {
7525 39985452 : return build_range_type (sizetype, size_zero_node, maxval);
7526 : }
7527 :
7528 : /* Return true if the debug information for TYPE, a subtype, should be emitted
7529 : as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7530 : high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7531 : debug info and doesn't reflect the source code. */
7532 :
7533 : bool
7534 18 : subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
7535 : {
7536 18 : tree base_type = TREE_TYPE (type), low, high;
7537 :
7538 : /* Subrange types have a base type which is an integral type. */
7539 18 : if (!INTEGRAL_TYPE_P (base_type))
7540 : return false;
7541 :
7542 : /* Get the real bounds of the subtype. */
7543 18 : if (lang_hooks.types.get_subrange_bounds)
7544 0 : lang_hooks.types.get_subrange_bounds (type, &low, &high);
7545 : else
7546 : {
7547 18 : low = TYPE_MIN_VALUE (type);
7548 18 : high = TYPE_MAX_VALUE (type);
7549 : }
7550 :
7551 : /* If the type and its base type have the same representation and the same
7552 : name, then the type is not a subrange but a copy of the base type. */
7553 18 : if ((TREE_CODE (base_type) == INTEGER_TYPE
7554 18 : || TREE_CODE (base_type) == BOOLEAN_TYPE)
7555 18 : && int_size_in_bytes (type) == int_size_in_bytes (base_type)
7556 18 : && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
7557 0 : && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))
7558 18 : && TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (base_type))
7559 : return false;
7560 :
7561 18 : if (lowval)
7562 18 : *lowval = low;
7563 18 : if (highval)
7564 18 : *highval = high;
7565 : return true;
7566 : }
7567 :
7568 : /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7569 : and number of elements specified by the range of values of INDEX_TYPE.
7570 : If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
7571 : If SHARED is true, reuse such a type that has already been constructed.
7572 : If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type. */
7573 :
7574 : tree
7575 68833176 : build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
7576 : bool shared, bool set_canonical)
7577 : {
7578 68833176 : tree t;
7579 :
7580 68833176 : if (TREE_CODE (elt_type) == FUNCTION_TYPE)
7581 : {
7582 0 : error ("arrays of functions are not meaningful");
7583 0 : elt_type = integer_type_node;
7584 : }
7585 :
7586 68833176 : t = make_node (ARRAY_TYPE);
7587 68833176 : TREE_TYPE (t) = elt_type;
7588 68833176 : TYPE_DOMAIN (t) = index_type;
7589 68833176 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
7590 68833176 : TYPE_TYPELESS_STORAGE (t) = typeless_storage;
7591 :
7592 : /* Set TYPE_STRUCTURAL_EQUALITY_P. */
7593 68833176 : if (set_canonical
7594 68833176 : && (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7595 68801640 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7596 68529561 : || in_lto_p))
7597 375883 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7598 :
7599 68833176 : layout_type (t);
7600 :
7601 68833176 : if (shared)
7602 : {
7603 68833147 : hashval_t hash = type_hash_canon_hash (t);
7604 68833147 : tree probe_type = t;
7605 68833147 : t = type_hash_canon (hash, t);
7606 68833147 : if (t != probe_type)
7607 : return t;
7608 : }
7609 :
7610 10707719 : if (TYPE_CANONICAL (t) == t && set_canonical)
7611 : {
7612 10380846 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7613 10380846 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7614 20761692 : || in_lto_p)
7615 0 : gcc_unreachable ();
7616 10380846 : else if (TYPE_CANONICAL (elt_type) != elt_type
7617 10380846 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
7618 103528 : TYPE_CANONICAL (t)
7619 300281 : = build_array_type_1 (TYPE_CANONICAL (elt_type),
7620 : index_type
7621 93225 : ? TYPE_CANONICAL (index_type) : NULL_TREE,
7622 : typeless_storage, shared, set_canonical);
7623 : }
7624 :
7625 : return t;
7626 : }
7627 :
7628 : /* Wrapper around build_array_type_1 with SHARED set to true. */
7629 :
7630 : tree
7631 68729619 : build_array_type (tree elt_type, tree index_type, bool typeless_storage)
7632 : {
7633 68729619 : return
7634 68729619 : build_array_type_1 (elt_type, index_type, typeless_storage, true, true);
7635 : }
7636 :
7637 : /* Wrapper around build_array_type_1 with SHARED set to false. */
7638 :
7639 : tree
7640 0 : build_nonshared_array_type (tree elt_type, tree index_type)
7641 : {
7642 0 : return build_array_type_1 (elt_type, index_type, false, false, true);
7643 : }
7644 :
7645 : /* Return a representation of ELT_TYPE[NELTS], using indices of type
7646 : sizetype. */
7647 :
7648 : tree
7649 1693430 : build_array_type_nelts (tree elt_type, poly_uint64 nelts)
7650 : {
7651 1693430 : return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
7652 : }
7653 :
7654 : /* Computes the canonical argument types from the argument type list
7655 : ARGTYPES.
7656 :
7657 : Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7658 : on entry to this function, or if any of the ARGTYPES are
7659 : structural.
7660 :
7661 : Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7662 : true on entry to this function, or if any of the ARGTYPES are
7663 : non-canonical.
7664 :
7665 : Returns a canonical argument list, which may be ARGTYPES when the
7666 : canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7667 : true) or would not differ from ARGTYPES. */
7668 :
7669 : static tree
7670 984532826 : maybe_canonicalize_argtypes (tree argtypes,
7671 : bool *any_structural_p,
7672 : bool *any_noncanonical_p)
7673 : {
7674 984532826 : tree arg;
7675 984532826 : bool any_noncanonical_argtypes_p = false;
7676 :
7677 3376706433 : for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
7678 : {
7679 2392173607 : if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
7680 : /* Fail gracefully by stating that the type is structural. */
7681 4281 : *any_structural_p = true;
7682 2392169326 : else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
7683 32946364 : *any_structural_p = true;
7684 2359222962 : else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
7685 2359222962 : || TREE_PURPOSE (arg))
7686 : /* If the argument has a default argument, we consider it
7687 : non-canonical even though the type itself is canonical.
7688 : That way, different variants of function and method types
7689 : with default arguments will all point to the variant with
7690 : no defaults as their canonical type. */
7691 : any_noncanonical_argtypes_p = true;
7692 : }
7693 :
7694 984532826 : if (*any_structural_p)
7695 : return argtypes;
7696 :
7697 892100502 : if (any_noncanonical_argtypes_p)
7698 : {
7699 : /* Build the canonical list of argument types. */
7700 : tree canon_argtypes = NULL_TREE;
7701 : bool is_void = false;
7702 :
7703 851608589 : for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
7704 : {
7705 654109374 : if (arg == void_list_node)
7706 : is_void = true;
7707 : else
7708 915171762 : canon_argtypes = tree_cons (NULL_TREE,
7709 457585881 : TYPE_CANONICAL (TREE_VALUE (arg)),
7710 : canon_argtypes);
7711 : }
7712 :
7713 197499215 : canon_argtypes = nreverse (canon_argtypes);
7714 197499215 : if (is_void)
7715 196523493 : canon_argtypes = chainon (canon_argtypes, void_list_node);
7716 :
7717 : /* There is a non-canonical type. */
7718 197499215 : *any_noncanonical_p = true;
7719 197499215 : return canon_argtypes;
7720 : }
7721 :
7722 : /* The canonical argument types are the same as ARGTYPES. */
7723 : return argtypes;
7724 : }
7725 :
7726 : /* Construct, lay out and return
7727 : the type of functions returning type VALUE_TYPE
7728 : given arguments of types ARG_TYPES.
7729 : ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7730 : are data type nodes for the arguments of the function.
7731 : NO_NAMED_ARGS_STDARG_P is true if this is a prototyped
7732 : variable-arguments function with (...) prototype (no named arguments).
7733 : If such a type has already been constructed, reuse it. */
7734 :
7735 : tree
7736 642982973 : build_function_type (tree value_type, tree arg_types,
7737 : bool no_named_args_stdarg_p)
7738 : {
7739 642982973 : tree t;
7740 642982973 : inchash::hash hstate;
7741 642982973 : bool any_structural_p, any_noncanonical_p;
7742 642982973 : tree canon_argtypes;
7743 :
7744 642982973 : gcc_assert (arg_types != error_mark_node);
7745 :
7746 642982973 : if (TREE_CODE (value_type) == FUNCTION_TYPE)
7747 : {
7748 0 : error ("function return type cannot be function");
7749 0 : value_type = integer_type_node;
7750 : }
7751 :
7752 : /* Make a node of the sort we want. */
7753 642982973 : t = make_node (FUNCTION_TYPE);
7754 642982973 : TREE_TYPE (t) = value_type;
7755 642982973 : TYPE_ARG_TYPES (t) = arg_types;
7756 642982973 : if (no_named_args_stdarg_p)
7757 : {
7758 708132 : gcc_assert (arg_types == NULL_TREE);
7759 708132 : TYPE_NO_NAMED_ARGS_STDARG_P (t) = 1;
7760 : }
7761 :
7762 : /* Set up the canonical type. */
7763 642982973 : any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
7764 642982973 : any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
7765 642982973 : canon_argtypes = maybe_canonicalize_argtypes (arg_types,
7766 : &any_structural_p,
7767 : &any_noncanonical_p);
7768 : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7769 642982973 : if (any_structural_p)
7770 67004834 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7771 :
7772 : /* If we already have such a type, use the old one. */
7773 642982973 : hashval_t hash = type_hash_canon_hash (t);
7774 642982973 : tree probe_type = t;
7775 642982973 : t = type_hash_canon (hash, t);
7776 642982973 : if (t != probe_type)
7777 : return t;
7778 :
7779 412284202 : if (any_structural_p)
7780 53161441 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7781 359122761 : else if (any_noncanonical_p)
7782 85507324 : TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
7783 : canon_argtypes,
7784 : no_named_args_stdarg_p);
7785 :
7786 412284202 : if (!COMPLETE_TYPE_P (t))
7787 0 : layout_type (t);
7788 : return t;
7789 : }
7790 :
7791 : /* Build a function type. The RETURN_TYPE is the type returned by the
7792 : function. If VAARGS is set, no void_type_node is appended to the
7793 : list. ARGP must be always be terminated be a NULL_TREE. */
7794 :
7795 : static tree
7796 14886615 : build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
7797 : {
7798 14886615 : tree t, args, last;
7799 :
7800 14886615 : t = va_arg (argp, tree);
7801 63017229 : for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
7802 33243999 : args = tree_cons (NULL_TREE, t, args);
7803 :
7804 14886615 : if (vaargs)
7805 : {
7806 929648 : last = args;
7807 929648 : if (args != NULL_TREE)
7808 800372 : args = nreverse (args);
7809 929648 : gcc_assert (last != void_list_node);
7810 : }
7811 13956967 : else if (args == NULL_TREE)
7812 1146312 : args = void_list_node;
7813 : else
7814 : {
7815 12810655 : last = args;
7816 12810655 : args = nreverse (args);
7817 12810655 : TREE_CHAIN (last) = void_list_node;
7818 : }
7819 14886615 : args = build_function_type (return_type, args, vaargs && args == NULL_TREE);
7820 :
7821 14886615 : return args;
7822 : }
7823 :
7824 : /* Build a function type. The RETURN_TYPE is the type returned by the
7825 : function. If additional arguments are provided, they are
7826 : additional argument types. The list of argument types must always
7827 : be terminated by NULL_TREE. */
7828 :
7829 : tree
7830 13956967 : build_function_type_list (tree return_type, ...)
7831 : {
7832 13956967 : tree args;
7833 13956967 : va_list p;
7834 :
7835 13956967 : va_start (p, return_type);
7836 13956967 : args = build_function_type_list_1 (false, return_type, p);
7837 13956967 : va_end (p);
7838 13956967 : return args;
7839 : }
7840 :
7841 : /* Build a variable argument function type. The RETURN_TYPE is the
7842 : type returned by the function. If additional arguments are provided,
7843 : they are additional argument types. The list of argument types must
7844 : always be terminated by NULL_TREE. */
7845 :
7846 : tree
7847 929648 : build_varargs_function_type_list (tree return_type, ...)
7848 : {
7849 929648 : tree args;
7850 929648 : va_list p;
7851 :
7852 929648 : va_start (p, return_type);
7853 929648 : args = build_function_type_list_1 (true, return_type, p);
7854 929648 : va_end (p);
7855 :
7856 929648 : return args;
7857 : }
7858 :
7859 : /* Build a function type. RETURN_TYPE is the type returned by the
7860 : function; VAARGS indicates whether the function takes varargs. The
7861 : function takes N named arguments, the types of which are provided in
7862 : ARG_TYPES. */
7863 :
7864 : static tree
7865 116145673 : build_function_type_array_1 (bool vaargs, tree return_type, int n,
7866 : tree *arg_types)
7867 : {
7868 116145673 : int i;
7869 116145673 : tree t = vaargs ? NULL_TREE : void_list_node;
7870 :
7871 381255484 : for (i = n - 1; i >= 0; i--)
7872 265109811 : t = tree_cons (NULL_TREE, arg_types[i], t);
7873 :
7874 116145673 : return build_function_type (return_type, t, vaargs && n == 0);
7875 : }
7876 :
7877 : /* Build a function type. RETURN_TYPE is the type returned by the
7878 : function. The function takes N named arguments, the types of which
7879 : are provided in ARG_TYPES. */
7880 :
7881 : tree
7882 109897404 : build_function_type_array (tree return_type, int n, tree *arg_types)
7883 : {
7884 109897404 : return build_function_type_array_1 (false, return_type, n, arg_types);
7885 : }
7886 :
7887 : /* Build a variable argument function type. RETURN_TYPE is the type
7888 : returned by the function. The function takes N named arguments, the
7889 : types of which are provided in ARG_TYPES. */
7890 :
7891 : tree
7892 6248269 : build_varargs_function_type_array (tree return_type, int n, tree *arg_types)
7893 : {
7894 6248269 : return build_function_type_array_1 (true, return_type, n, arg_types);
7895 : }
7896 :
7897 : /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7898 : and ARGTYPES (a TREE_LIST) are the return type and arguments types
7899 : for the method. An implicit additional parameter (of type
7900 : pointer-to-BASETYPE) is added to the ARGTYPES. */
7901 :
7902 : tree
7903 341549853 : build_method_type_directly (tree basetype,
7904 : tree rettype,
7905 : tree argtypes)
7906 : {
7907 341549853 : tree t;
7908 341549853 : tree ptype;
7909 341549853 : bool any_structural_p, any_noncanonical_p;
7910 341549853 : tree canon_argtypes;
7911 :
7912 : /* Make a node of the sort we want. */
7913 341549853 : t = make_node (METHOD_TYPE);
7914 :
7915 341549853 : TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7916 341549853 : TREE_TYPE (t) = rettype;
7917 341549853 : ptype = build_pointer_type (basetype);
7918 :
7919 : /* The actual arglist for this function includes a "hidden" argument
7920 : which is "this". Put it into the list of argument types. */
7921 341549853 : argtypes = tree_cons (NULL_TREE, ptype, argtypes);
7922 341549853 : TYPE_ARG_TYPES (t) = argtypes;
7923 :
7924 : /* Set up the canonical type. */
7925 341549853 : any_structural_p
7926 341549853 : = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7927 341549853 : || TYPE_STRUCTURAL_EQUALITY_P (rettype));
7928 341549853 : any_noncanonical_p
7929 341549853 : = (TYPE_CANONICAL (basetype) != basetype
7930 341549853 : || TYPE_CANONICAL (rettype) != rettype);
7931 341549853 : canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
7932 : &any_structural_p,
7933 : &any_noncanonical_p);
7934 :
7935 : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7936 341549853 : if (any_structural_p)
7937 25427490 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7938 :
7939 : /* If we already have such a type, use the old one. */
7940 341549853 : hashval_t hash = type_hash_canon_hash (t);
7941 341549853 : tree probe_type = t;
7942 341549853 : t = type_hash_canon (hash, t);
7943 341549853 : if (t != probe_type)
7944 : return t;
7945 :
7946 264210815 : if (any_structural_p)
7947 21532258 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7948 242678557 : else if (any_noncanonical_p)
7949 88167044 : TYPE_CANONICAL (t)
7950 176334088 : = build_method_type_directly (TYPE_CANONICAL (basetype),
7951 88167044 : TYPE_CANONICAL (rettype),
7952 : canon_argtypes);
7953 264210815 : if (!COMPLETE_TYPE_P (t))
7954 0 : layout_type (t);
7955 :
7956 : return t;
7957 : }
7958 :
7959 : /* Construct, lay out and return the type of methods belonging to class
7960 : BASETYPE and whose arguments and values are described by TYPE.
7961 : If that type exists already, reuse it.
7962 : TYPE must be a FUNCTION_TYPE node. */
7963 :
7964 : tree
7965 0 : build_method_type (tree basetype, tree type)
7966 : {
7967 0 : gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
7968 :
7969 0 : return build_method_type_directly (basetype,
7970 0 : TREE_TYPE (type),
7971 0 : TYPE_ARG_TYPES (type));
7972 : }
7973 :
7974 : /* Construct, lay out and return the type of offsets to a value
7975 : of type TYPE, within an object of type BASETYPE.
7976 : If a suitable offset type exists already, reuse it. */
7977 :
7978 : tree
7979 936594 : build_offset_type (tree basetype, tree type)
7980 : {
7981 936594 : tree t;
7982 :
7983 : /* Make a node of the sort we want. */
7984 936594 : t = make_node (OFFSET_TYPE);
7985 :
7986 936594 : TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7987 936594 : TREE_TYPE (t) = type;
7988 936594 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7989 936594 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7990 4 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7991 :
7992 : /* If we already have such a type, use the old one. */
7993 936594 : hashval_t hash = type_hash_canon_hash (t);
7994 936594 : tree probe_type = t;
7995 936594 : t = type_hash_canon (hash, t);
7996 936594 : if (t != probe_type)
7997 : return t;
7998 :
7999 225022 : if (!COMPLETE_TYPE_P (t))
8000 0 : layout_type (t);
8001 :
8002 225022 : if (TYPE_CANONICAL (t) == t)
8003 : {
8004 225018 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
8005 225018 : || TYPE_STRUCTURAL_EQUALITY_P (type))
8006 0 : gcc_unreachable ();
8007 225018 : else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
8008 225018 : || TYPE_CANONICAL (type) != type)
8009 128619 : TYPE_CANONICAL (t)
8010 257238 : = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
8011 128619 : TYPE_CANONICAL (type));
8012 : }
8013 :
8014 : return t;
8015 : }
8016 :
8017 : /* Create a complex type whose components are COMPONENT_TYPE.
8018 :
8019 : If NAMED is true, the type is given a TYPE_NAME. We do not always
8020 : do so because this creates a DECL node and thus make the DECL_UIDs
8021 : dependent on the type canonicalization hashtable, which is GC-ed,
8022 : so the DECL_UIDs would not be stable wrt garbage collection. */
8023 :
8024 : tree
8025 5207269 : build_complex_type (tree component_type, bool named)
8026 : {
8027 5207269 : gcc_assert (INTEGRAL_TYPE_P (component_type)
8028 : || SCALAR_FLOAT_TYPE_P (component_type)
8029 : || FIXED_POINT_TYPE_P (component_type));
8030 :
8031 : /* Make a node of the sort we want. */
8032 5207269 : tree probe = make_node (COMPLEX_TYPE);
8033 :
8034 5207269 : TREE_TYPE (probe) = TYPE_MAIN_VARIANT (component_type);
8035 5207269 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (probe)))
8036 0 : SET_TYPE_STRUCTURAL_EQUALITY (probe);
8037 :
8038 : /* If we already have such a type, use the old one. */
8039 5207269 : hashval_t hash = type_hash_canon_hash (probe);
8040 5207269 : tree t = type_hash_canon (hash, probe);
8041 :
8042 5207269 : if (t == probe)
8043 : {
8044 : /* We created a new type. The hash insertion will have laid
8045 : out the type. We need to check the canonicalization and
8046 : maybe set the name. */
8047 3111640 : gcc_checking_assert (COMPLETE_TYPE_P (t)
8048 : && !TYPE_NAME (t));
8049 :
8050 3111640 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))
8051 : ;
8052 3111640 : else if (TYPE_CANONICAL (TREE_TYPE (t)) != TREE_TYPE (t))
8053 101 : TYPE_CANONICAL (t)
8054 202 : = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named);
8055 :
8056 : /* We need to create a name, since complex is a fundamental type. */
8057 3111640 : if (named)
8058 : {
8059 1141688 : const char *name = NULL;
8060 :
8061 1141688 : if (TREE_TYPE (t) == char_type_node)
8062 : name = "complex char";
8063 1141688 : else if (TREE_TYPE (t) == signed_char_type_node)
8064 : name = "complex signed char";
8065 1141688 : else if (TREE_TYPE (t) == unsigned_char_type_node)
8066 : name = "complex unsigned char";
8067 1141688 : else if (TREE_TYPE (t) == short_integer_type_node)
8068 : name = "complex short int";
8069 1141688 : else if (TREE_TYPE (t) == short_unsigned_type_node)
8070 : name = "complex short unsigned int";
8071 1141688 : else if (TREE_TYPE (t) == integer_type_node)
8072 : name = "complex int";
8073 856266 : else if (TREE_TYPE (t) == unsigned_type_node)
8074 : name = "complex unsigned int";
8075 856266 : else if (TREE_TYPE (t) == long_integer_type_node)
8076 : name = "complex long int";
8077 856266 : else if (TREE_TYPE (t) == long_unsigned_type_node)
8078 : name = "complex long unsigned int";
8079 856266 : else if (TREE_TYPE (t) == long_long_integer_type_node)
8080 : name = "complex long long int";
8081 856266 : else if (TREE_TYPE (t) == long_long_unsigned_type_node)
8082 : name = "complex long long unsigned int";
8083 :
8084 : if (name != NULL)
8085 285422 : TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
8086 : get_identifier (name), t);
8087 : }
8088 : }
8089 :
8090 5207269 : return build_qualified_type (t, TYPE_QUALS (component_type));
8091 : }
8092 :
8093 : /* If TYPE is a real or complex floating-point type and the target
8094 : does not directly support arithmetic on TYPE then return the wider
8095 : type to be used for arithmetic on TYPE. Otherwise, return
8096 : NULL_TREE. */
8097 :
8098 : tree
8099 88397142 : excess_precision_type (tree type)
8100 : {
8101 : /* The target can give two different responses to the question of
8102 : which excess precision mode it would like depending on whether we
8103 : are in -fexcess-precision=standard or -fexcess-precision=fast. */
8104 :
8105 3373853 : enum excess_precision_type requested_type
8106 88397142 : = (flag_excess_precision == EXCESS_PRECISION_FAST
8107 88397142 : ? EXCESS_PRECISION_TYPE_FAST
8108 : : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
8109 3373922 : ? EXCESS_PRECISION_TYPE_FLOAT16 : EXCESS_PRECISION_TYPE_STANDARD));
8110 :
8111 88397142 : enum flt_eval_method target_flt_eval_method
8112 88397142 : = targetm.c.excess_precision (requested_type);
8113 :
8114 : /* The target should not ask for unpredictable float evaluation (though
8115 : it might advertise that implicitly the evaluation is unpredictable,
8116 : but we don't care about that here, it will have been reported
8117 : elsewhere). If it does ask for unpredictable evaluation, we have
8118 : nothing to do here. */
8119 88397142 : gcc_assert (target_flt_eval_method != FLT_EVAL_METHOD_UNPREDICTABLE);
8120 :
8121 : /* Nothing to do. The target has asked for all types we know about
8122 : to be computed with their native precision and range. */
8123 88397142 : if (target_flt_eval_method == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
8124 : return NULL_TREE;
8125 :
8126 : /* The target will promote this type in a target-dependent way, so excess
8127 : precision ought to leave it alone. */
8128 86790494 : if (targetm.promoted_type (type) != NULL_TREE)
8129 : return NULL_TREE;
8130 :
8131 86790494 : machine_mode float16_type_mode = (float16_type_node
8132 86790494 : ? TYPE_MODE (float16_type_node)
8133 86790494 : : VOIDmode);
8134 86790494 : machine_mode bfloat16_type_mode = (bfloat16_type_node
8135 86790494 : ? TYPE_MODE (bfloat16_type_node)
8136 86790494 : : VOIDmode);
8137 86790494 : machine_mode float_type_mode = TYPE_MODE (float_type_node);
8138 86790494 : machine_mode double_type_mode = TYPE_MODE (double_type_node);
8139 :
8140 86790494 : switch (TREE_CODE (type))
8141 : {
8142 58454101 : case REAL_TYPE:
8143 58454101 : {
8144 58454101 : machine_mode type_mode = TYPE_MODE (type);
8145 58454101 : switch (target_flt_eval_method)
8146 : {
8147 58441268 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8148 58441268 : if (type_mode == float16_type_mode
8149 58441268 : || type_mode == bfloat16_type_mode)
8150 179295 : return float_type_node;
8151 : break;
8152 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8153 0 : if (type_mode == float16_type_mode
8154 0 : || type_mode == bfloat16_type_mode
8155 0 : || type_mode == float_type_mode)
8156 0 : return double_type_node;
8157 : break;
8158 12833 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8159 12833 : if (type_mode == float16_type_mode
8160 12833 : || type_mode == bfloat16_type_mode
8161 12828 : || type_mode == float_type_mode
8162 12828 : || type_mode == double_type_mode)
8163 12384 : return long_double_type_node;
8164 : break;
8165 0 : default:
8166 0 : gcc_unreachable ();
8167 : }
8168 : break;
8169 : }
8170 370262 : case COMPLEX_TYPE:
8171 370262 : {
8172 370262 : if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
8173 : return NULL_TREE;
8174 360782 : machine_mode type_mode = TYPE_MODE (TREE_TYPE (type));
8175 360782 : switch (target_flt_eval_method)
8176 : {
8177 360449 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8178 360449 : if (type_mode == float16_type_mode
8179 360449 : || type_mode == bfloat16_type_mode)
8180 271 : return complex_float_type_node;
8181 : break;
8182 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8183 0 : if (type_mode == float16_type_mode
8184 0 : || type_mode == bfloat16_type_mode
8185 0 : || type_mode == float_type_mode)
8186 0 : return complex_double_type_node;
8187 : break;
8188 333 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8189 333 : if (type_mode == float16_type_mode
8190 333 : || type_mode == bfloat16_type_mode
8191 333 : || type_mode == float_type_mode
8192 333 : || type_mode == double_type_mode)
8193 281 : return complex_long_double_type_node;
8194 : break;
8195 0 : default:
8196 0 : gcc_unreachable ();
8197 : }
8198 : break;
8199 : }
8200 : default:
8201 : break;
8202 : }
8203 :
8204 : return NULL_TREE;
8205 : }
8206 :
8207 : /* Return OP, stripped of any conversions to wider types as much as is safe.
8208 : Converting the value back to OP's type makes a value equivalent to OP.
8209 :
8210 : If FOR_TYPE is nonzero, we return a value which, if converted to
8211 : type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8212 :
8213 : OP must have integer, real or enumeral type. Pointers are not allowed!
8214 :
8215 : There are some cases where the obvious value we could return
8216 : would regenerate to OP if converted to OP's type,
8217 : but would not extend like OP to wider types.
8218 : If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8219 : For example, if OP is (unsigned short)(signed char)-1,
8220 : we avoid returning (signed char)-1 if FOR_TYPE is int,
8221 : even though extending that to an unsigned short would regenerate OP,
8222 : since the result of extending (signed char)-1 to (int)
8223 : is different from (int) OP. */
8224 :
8225 : tree
8226 11759975 : get_unwidened (tree op, tree for_type)
8227 : {
8228 : /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8229 11759975 : tree type = TREE_TYPE (op);
8230 11759975 : unsigned final_prec
8231 19427609 : = TYPE_PRECISION (for_type != 0 ? for_type : type);
8232 11759975 : int uns
8233 11759975 : = (for_type != 0 && for_type != type
8234 3780460 : && final_prec > TYPE_PRECISION (type)
8235 11986703 : && TYPE_UNSIGNED (type));
8236 11759975 : tree win = op;
8237 :
8238 12103778 : while (CONVERT_EXPR_P (op))
8239 : {
8240 343832 : int bitschange;
8241 :
8242 : /* TYPE_PRECISION on vector types has different meaning
8243 : (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8244 : so avoid them here. */
8245 343832 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
8246 : break;
8247 :
8248 343832 : bitschange = TYPE_PRECISION (TREE_TYPE (op))
8249 343832 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
8250 :
8251 : /* Truncations are many-one so cannot be removed.
8252 : Unless we are later going to truncate down even farther. */
8253 343832 : if (bitschange < 0
8254 343832 : && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
8255 : break;
8256 :
8257 : /* See what's inside this conversion. If we decide to strip it,
8258 : we will set WIN. */
8259 343803 : op = TREE_OPERAND (op, 0);
8260 :
8261 : /* If we have not stripped any zero-extensions (uns is 0),
8262 : we can strip any kind of extension.
8263 : If we have previously stripped a zero-extension,
8264 : only zero-extensions can safely be stripped.
8265 : Any extension can be stripped if the bits it would produce
8266 : are all going to be discarded later by truncating to FOR_TYPE. */
8267 :
8268 343803 : if (bitschange > 0)
8269 : {
8270 194563 : if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
8271 : win = op;
8272 : /* TYPE_UNSIGNED says whether this is a zero-extension.
8273 : Let's avoid computing it if it does not affect WIN
8274 : and if UNS will not be needed again. */
8275 194563 : if ((uns
8276 194532 : || CONVERT_EXPR_P (op))
8277 195098 : && TYPE_UNSIGNED (TREE_TYPE (op)))
8278 : {
8279 : uns = 1;
8280 : win = op;
8281 : }
8282 : }
8283 : }
8284 :
8285 : /* If we finally reach a constant see if it fits in sth smaller and
8286 : in that case convert it. */
8287 11759975 : if (TREE_CODE (win) == INTEGER_CST)
8288 : {
8289 669705 : tree wtype = TREE_TYPE (win);
8290 669705 : unsigned prec = wi::min_precision (wi::to_wide (win), TYPE_SIGN (wtype));
8291 669705 : if (for_type)
8292 658355 : prec = MAX (prec, final_prec);
8293 669705 : if (prec < TYPE_PRECISION (wtype))
8294 : {
8295 666481 : tree t = lang_hooks.types.type_for_size (prec, TYPE_UNSIGNED (wtype));
8296 666481 : if (t && TYPE_PRECISION (t) < TYPE_PRECISION (wtype))
8297 655715 : win = fold_convert (t, win);
8298 : }
8299 : }
8300 :
8301 11759975 : return win;
8302 : }
8303 :
8304 : /* Return OP or a simpler expression for a narrower value
8305 : which can be sign-extended or zero-extended to give back OP.
8306 : Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8307 : or 0 if the value should be sign-extended. */
8308 :
8309 : tree
8310 97399528 : get_narrower (tree op, int *unsignedp_ptr)
8311 : {
8312 97399528 : int uns = 0;
8313 97399528 : bool first = true;
8314 97399528 : tree win = op;
8315 97399528 : bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
8316 :
8317 97399528 : if (TREE_CODE (op) == COMPOUND_EXPR)
8318 : {
8319 87869 : do
8320 87869 : op = TREE_OPERAND (op, 1);
8321 87869 : while (TREE_CODE (op) == COMPOUND_EXPR);
8322 87854 : tree ret = get_narrower (op, unsignedp_ptr);
8323 87854 : if (ret == op)
8324 : return win;
8325 4262 : auto_vec <tree, 16> v;
8326 4262 : unsigned int i;
8327 8531 : for (op = win; TREE_CODE (op) == COMPOUND_EXPR;
8328 4269 : op = TREE_OPERAND (op, 1))
8329 4269 : v.safe_push (op);
8330 12793 : FOR_EACH_VEC_ELT_REVERSE (v, i, op)
8331 4269 : ret = build2_loc (EXPR_LOCATION (op), COMPOUND_EXPR,
8332 4269 : TREE_TYPE (ret), TREE_OPERAND (op, 0),
8333 : ret);
8334 4262 : return ret;
8335 4262 : }
8336 116695316 : while (TREE_CODE (op) == NOP_EXPR)
8337 : {
8338 19415333 : int bitschange
8339 19415333 : = (TYPE_PRECISION (TREE_TYPE (op))
8340 19415333 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
8341 :
8342 : /* Truncations are many-one so cannot be removed. */
8343 19415333 : if (bitschange < 0)
8344 : break;
8345 :
8346 : /* See what's inside this conversion. If we decide to strip it,
8347 : we will set WIN. */
8348 :
8349 19383738 : if (bitschange > 0)
8350 : {
8351 5802559 : op = TREE_OPERAND (op, 0);
8352 : /* An extension: the outermost one can be stripped,
8353 : but remember whether it is zero or sign extension. */
8354 5802559 : if (first)
8355 5792334 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8356 : /* Otherwise, if a sign extension has been stripped,
8357 : only sign extensions can now be stripped;
8358 : if a zero extension has been stripped, only zero-extensions. */
8359 10225 : else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
8360 : break;
8361 : first = false;
8362 : }
8363 : else /* bitschange == 0 */
8364 : {
8365 : /* A change in nominal type can always be stripped, but we must
8366 : preserve the unsignedness. */
8367 13581179 : if (first)
8368 12895475 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8369 13581179 : first = false;
8370 13581179 : op = TREE_OPERAND (op, 0);
8371 : /* Keep trying to narrow, but don't assign op to win if it
8372 : would turn an integral type into something else. */
8373 25465710 : if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
8374 95766 : continue;
8375 : }
8376 :
8377 19287876 : win = op;
8378 : }
8379 :
8380 97311674 : if (TREE_CODE (op) == COMPONENT_REF
8381 : /* Since type_for_size always gives an integer type. */
8382 4498220 : && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
8383 4398065 : && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
8384 : /* Ensure field is laid out already. */
8385 4398065 : && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
8386 101709736 : && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op, 1))))
8387 : {
8388 4398062 : unsigned HOST_WIDE_INT innerprec
8389 4398062 : = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op, 1)));
8390 4398062 : int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
8391 4398062 : || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
8392 4398062 : tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
8393 :
8394 : /* We can get this structure field in a narrower type that fits it,
8395 : but the resulting extension to its nominal type (a fullword type)
8396 : must satisfy the same conditions as for other extensions.
8397 :
8398 : Do this only for fields that are aligned (not bit-fields),
8399 : because when bit-field insns will be used there is no
8400 : advantage in doing this. */
8401 :
8402 4398062 : if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
8403 0 : && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
8404 0 : && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
8405 4398062 : && type != 0)
8406 : {
8407 0 : if (first)
8408 0 : uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
8409 0 : win = fold_convert (type, op);
8410 : }
8411 : }
8412 :
8413 97311674 : *unsignedp_ptr = uns;
8414 97311674 : return win;
8415 : }
8416 :
8417 : /* Return true if integer constant C has a value that is permissible
8418 : for TYPE, an integral type. */
8419 :
8420 : bool
8421 203570115 : int_fits_type_p (const_tree c, const_tree type)
8422 : {
8423 203570115 : tree type_low_bound, type_high_bound;
8424 203570115 : bool ok_for_low_bound, ok_for_high_bound;
8425 203570115 : signop sgn_c = TYPE_SIGN (TREE_TYPE (c));
8426 :
8427 : /* Non-standard boolean types can have arbitrary precision but various
8428 : transformations assume that they can only take values 0 and +/-1. */
8429 203570115 : if (TREE_CODE (type) == BOOLEAN_TYPE)
8430 1310121 : return wi::fits_to_boolean_p (wi::to_wide (c), type);
8431 :
8432 202259994 : retry:
8433 202271841 : type_low_bound = TYPE_MIN_VALUE (type);
8434 202271841 : type_high_bound = TYPE_MAX_VALUE (type);
8435 :
8436 : /* If at least one bound of the type is a constant integer, we can check
8437 : ourselves and maybe make a decision. If no such decision is possible, but
8438 : this type is a subtype, try checking against that. Otherwise, use
8439 : fits_to_tree_p, which checks against the precision.
8440 :
8441 : Compute the status for each possibly constant bound, and return if we see
8442 : one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8443 : for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8444 : for "constant known to fit". */
8445 :
8446 : /* Check if c >= type_low_bound. */
8447 202271841 : if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
8448 : {
8449 202271841 : if (tree_int_cst_lt (c, type_low_bound))
8450 : return false;
8451 : ok_for_low_bound = true;
8452 : }
8453 : else
8454 : ok_for_low_bound = false;
8455 :
8456 : /* Check if c <= type_high_bound. */
8457 202019362 : if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
8458 : {
8459 201987798 : if (tree_int_cst_lt (type_high_bound, c))
8460 : return false;
8461 : ok_for_high_bound = true;
8462 : }
8463 : else
8464 : ok_for_high_bound = false;
8465 :
8466 : /* If the constant fits both bounds, the result is known. */
8467 199853852 : if (ok_for_low_bound && ok_for_high_bound)
8468 : return true;
8469 :
8470 : /* Perform some generic filtering which may allow making a decision
8471 : even if the bounds are not constant. First, negative integers
8472 : never fit in unsigned types, */
8473 31564 : if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (wi::to_wide (c)))
8474 0 : return false;
8475 :
8476 : /* Second, narrower types always fit in wider ones. */
8477 31564 : if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
8478 : return true;
8479 :
8480 : /* Third, unsigned integers with top bit set never fit signed types. */
8481 11856 : if (!TYPE_UNSIGNED (type) && sgn_c == UNSIGNED)
8482 : {
8483 14 : int prec = GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (c))) - 1;
8484 14 : if (prec < TYPE_PRECISION (TREE_TYPE (c)))
8485 : {
8486 : /* When a tree_cst is converted to a wide-int, the precision
8487 : is taken from the type. However, if the precision of the
8488 : mode underneath the type is smaller than that, it is
8489 : possible that the value will not fit. The test below
8490 : fails if any bit is set between the sign bit of the
8491 : underlying mode and the top bit of the type. */
8492 14 : if (wi::zext (wi::to_wide (c), prec - 1) != wi::to_wide (c))
8493 : return false;
8494 : }
8495 0 : else if (wi::neg_p (wi::to_wide (c)))
8496 : return false;
8497 : }
8498 :
8499 : /* If we haven't been able to decide at this point, there nothing more we
8500 : can check ourselves here. Look at the base type if we have one and it
8501 : has the same precision. */
8502 11847 : if (TREE_CODE (type) == INTEGER_TYPE
8503 11847 : && TREE_TYPE (type) != 0
8504 23694 : && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
8505 : {
8506 11847 : type = TREE_TYPE (type);
8507 11847 : goto retry;
8508 : }
8509 :
8510 : /* Or to fits_to_tree_p, if nothing else. */
8511 0 : return wi::fits_to_tree_p (wi::to_wide (c), type);
8512 : }
8513 :
8514 : /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8515 : bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8516 : represented (assuming two's-complement arithmetic) within the bit
8517 : precision of the type are returned instead. */
8518 :
8519 : void
8520 21780234 : get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
8521 : {
8522 20282124 : if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
8523 42062358 : && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
8524 20282124 : wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type)), min, TYPE_SIGN (type));
8525 : else
8526 : {
8527 1498110 : if (TYPE_UNSIGNED (type))
8528 1498110 : mpz_set_ui (min, 0);
8529 : else
8530 : {
8531 0 : wide_int mn = wi::min_value (TYPE_PRECISION (type), SIGNED);
8532 0 : wi::to_mpz (mn, min, SIGNED);
8533 0 : }
8534 : }
8535 :
8536 20282124 : if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
8537 42062358 : && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
8538 20282124 : wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type)), max, TYPE_SIGN (type));
8539 : else
8540 : {
8541 1498110 : wide_int mn = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
8542 1498110 : wi::to_mpz (mn, max, TYPE_SIGN (type));
8543 1498110 : }
8544 21780234 : }
8545 :
8546 : /* Return true if VAR is an automatic variable. */
8547 :
8548 : bool
8549 475147624 : auto_var_p (const_tree var)
8550 : {
8551 250531330 : return ((((VAR_P (var) && ! DECL_EXTERNAL (var))
8552 227955526 : || TREE_CODE (var) == PARM_DECL)
8553 355536213 : && ! TREE_STATIC (var))
8554 603454576 : || TREE_CODE (var) == RESULT_DECL);
8555 : }
8556 :
8557 : /* Return true if VAR is an automatic variable defined in function FN. */
8558 :
8559 : bool
8560 1803434448 : auto_var_in_fn_p (const_tree var, const_tree fn)
8561 : {
8562 495249773 : return (DECL_P (var) && DECL_CONTEXT (var) == fn
8563 2153389836 : && (auto_var_p (var)
8564 4909445 : || TREE_CODE (var) == LABEL_DECL));
8565 : }
8566 :
8567 : /* Subprogram of following function. Called by walk_tree.
8568 :
8569 : Return *TP if it is an automatic variable or parameter of the
8570 : function passed in as DATA. */
8571 :
8572 : static tree
8573 126388 : find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
8574 : {
8575 126388 : tree fn = (tree) data;
8576 :
8577 126388 : if (TYPE_P (*tp))
8578 0 : *walk_subtrees = 0;
8579 :
8580 126388 : else if (DECL_P (*tp)
8581 126388 : && auto_var_in_fn_p (*tp, fn))
8582 117500 : return *tp;
8583 :
8584 : return NULL_TREE;
8585 : }
8586 :
8587 : /* Returns true if T is, contains, or refers to a type with variable
8588 : size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8589 : arguments, but not the return type. If FN is nonzero, only return
8590 : true if a modifier of the type or position of FN is a variable or
8591 : parameter inside FN.
8592 :
8593 : This concept is more general than that of C99 'variably modified types':
8594 : in C99, a struct type is never variably modified because a VLA may not
8595 : appear as a structure member. However, in GNU C code like:
8596 :
8597 : struct S { int i[f()]; };
8598 :
8599 : is valid, and other languages may define similar constructs. */
8600 :
8601 : bool
8602 2586881133 : variably_modified_type_p (tree type, tree fn)
8603 : {
8604 2586881133 : tree t;
8605 :
8606 : /* Test if T is either variable (if FN is zero) or an expression containing
8607 : a variable in FN. If TYPE isn't gimplified, return true also if
8608 : gimplify_one_sizepos would gimplify the expression into a local
8609 : variable. */
8610 : #define RETURN_TRUE_IF_VAR(T) \
8611 : do { tree _t = (T); \
8612 : if (_t != NULL_TREE \
8613 : && _t != error_mark_node \
8614 : && !CONSTANT_CLASS_P (_t) \
8615 : && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8616 : && (!fn \
8617 : || (!TYPE_SIZES_GIMPLIFIED (type) \
8618 : && (TREE_CODE (_t) != VAR_DECL \
8619 : && !CONTAINS_PLACEHOLDER_P (_t))) \
8620 : || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8621 : return true; } while (0)
8622 :
8623 2586881133 : if (type == error_mark_node)
8624 : return false;
8625 :
8626 : /* If TYPE itself has variable size, it is variably modified. */
8627 2586880822 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
8628 2586753455 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
8629 :
8630 2586752831 : switch (TREE_CODE (type))
8631 : {
8632 677682253 : case POINTER_TYPE:
8633 677682253 : case REFERENCE_TYPE:
8634 677682253 : case VECTOR_TYPE:
8635 : /* Ada can have pointer types referring to themselves indirectly. */
8636 677682253 : if (TREE_VISITED (type))
8637 : return false;
8638 677682253 : TREE_VISITED (type) = true;
8639 677682253 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8640 : {
8641 80215 : TREE_VISITED (type) = false;
8642 80215 : return true;
8643 : }
8644 677602038 : TREE_VISITED (type) = false;
8645 677602038 : break;
8646 :
8647 139823023 : case FUNCTION_TYPE:
8648 139823023 : case METHOD_TYPE:
8649 : /* If TYPE is a function type, it is variably modified if the
8650 : return type is variably modified. */
8651 139823023 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8652 : return true;
8653 : break;
8654 :
8655 639444657 : case INTEGER_TYPE:
8656 639444657 : case REAL_TYPE:
8657 639444657 : case FIXED_POINT_TYPE:
8658 639444657 : case ENUMERAL_TYPE:
8659 639444657 : case BOOLEAN_TYPE:
8660 : /* Scalar types are variably modified if their end points
8661 : aren't constant. */
8662 639444657 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
8663 639444657 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
8664 639409417 : break;
8665 :
8666 917235996 : case RECORD_TYPE:
8667 917235996 : case UNION_TYPE:
8668 917235996 : case QUAL_UNION_TYPE:
8669 : /* We can't see if any of the fields are variably-modified by the
8670 : definition we normally use, since that would produce infinite
8671 : recursion via pointers. */
8672 : /* This is variably modified if some field's type is. */
8673 41076910389 : for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
8674 40159674393 : if (TREE_CODE (t) == FIELD_DECL)
8675 : {
8676 1390596052 : RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
8677 1390596052 : RETURN_TRUE_IF_VAR (DECL_SIZE (t));
8678 1390596052 : RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
8679 :
8680 : /* If the type is a qualified union, then the DECL_QUALIFIER
8681 : of fields can also be an expression containing a variable. */
8682 1390596052 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
8683 0 : RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
8684 :
8685 : /* If the field is a qualified union, then it's only a container
8686 : for what's inside so we look into it. That's necessary in LTO
8687 : mode because the sizes of the field tested above have been set
8688 : to PLACEHOLDER_EXPRs by free_lang_data. */
8689 1390596052 : if (TREE_CODE (TREE_TYPE (t)) == QUAL_UNION_TYPE
8690 1390596052 : && variably_modified_type_p (TREE_TYPE (t), fn))
8691 : return true;
8692 : }
8693 : break;
8694 :
8695 14696009 : case ARRAY_TYPE:
8696 : /* Do not call ourselves to avoid infinite recursion. This is
8697 : variably modified if the element type is. */
8698 14696009 : RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
8699 14692437 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
8700 14692411 : break;
8701 :
8702 : default:
8703 : break;
8704 : }
8705 :
8706 : /* The current language may have other cases to check, but in general,
8707 : all other types are not variably modified. */
8708 2586633548 : return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
8709 :
8710 : #undef RETURN_TRUE_IF_VAR
8711 : }
8712 :
8713 : /* Given a DECL or TYPE, return the scope in which it was declared, or
8714 : NULL_TREE if there is no containing scope. */
8715 :
8716 : tree
8717 3345995384 : get_containing_scope (const_tree t)
8718 : {
8719 3345995384 : return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8720 : }
8721 :
8722 : /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
8723 :
8724 : const_tree
8725 13669 : get_ultimate_context (const_tree decl)
8726 : {
8727 36977 : while (decl && TREE_CODE (decl) != TRANSLATION_UNIT_DECL)
8728 : {
8729 23308 : if (TREE_CODE (decl) == BLOCK)
8730 0 : decl = BLOCK_SUPERCONTEXT (decl);
8731 : else
8732 23308 : decl = get_containing_scope (decl);
8733 : }
8734 13669 : return decl;
8735 : }
8736 :
8737 : /* Return the innermost context enclosing DECL that is
8738 : a FUNCTION_DECL, or zero if none. */
8739 :
8740 : tree
8741 1539752672 : decl_function_context (const_tree decl)
8742 : {
8743 1539752672 : tree context;
8744 :
8745 1539752672 : if (TREE_CODE (decl) == ERROR_MARK)
8746 : return 0;
8747 :
8748 : /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8749 : where we look up the function at runtime. Such functions always take
8750 : a first argument of type 'pointer to real context'.
8751 :
8752 : C++ should really be fixed to use DECL_CONTEXT for the real context,
8753 : and use something else for the "virtual context". */
8754 1539752672 : else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
8755 5133848 : context
8756 5133848 : = TYPE_MAIN_VARIANT
8757 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8758 : else
8759 1534618824 : context = DECL_CONTEXT (decl);
8760 :
8761 3826576973 : while (context && TREE_CODE (context) != FUNCTION_DECL)
8762 : {
8763 2286824301 : if (TREE_CODE (context) == BLOCK)
8764 0 : context = BLOCK_SUPERCONTEXT (context);
8765 : else
8766 2286824301 : context = get_containing_scope (context);
8767 : }
8768 :
8769 : return context;
8770 : }
8771 :
8772 : /* Return the innermost context enclosing DECL that is
8773 : a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8774 : TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8775 :
8776 : tree
8777 117885526 : decl_type_context (const_tree decl)
8778 : {
8779 117885526 : tree context = DECL_CONTEXT (decl);
8780 :
8781 123149803 : while (context)
8782 117460154 : switch (TREE_CODE (context))
8783 : {
8784 : case NAMESPACE_DECL:
8785 : case TRANSLATION_UNIT_DECL:
8786 : return NULL_TREE;
8787 :
8788 : case RECORD_TYPE:
8789 : case UNION_TYPE:
8790 : case QUAL_UNION_TYPE:
8791 : return context;
8792 :
8793 5264277 : case TYPE_DECL:
8794 5264277 : case FUNCTION_DECL:
8795 5264277 : context = DECL_CONTEXT (context);
8796 5264277 : break;
8797 :
8798 0 : case BLOCK:
8799 0 : context = BLOCK_SUPERCONTEXT (context);
8800 0 : break;
8801 :
8802 0 : default:
8803 0 : gcc_unreachable ();
8804 : }
8805 :
8806 : return NULL_TREE;
8807 : }
8808 :
8809 : /* CALL is a CALL_EXPR. Return the declaration for the function
8810 : called, or NULL_TREE if the called function cannot be
8811 : determined. */
8812 :
8813 : tree
8814 1484617761 : get_callee_fndecl (const_tree call)
8815 : {
8816 1484617761 : tree addr;
8817 :
8818 1484617761 : if (call == error_mark_node)
8819 : return error_mark_node;
8820 :
8821 : /* It's invalid to call this function with anything but a
8822 : CALL_EXPR. */
8823 1484617761 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8824 :
8825 : /* The first operand to the CALL is the address of the function
8826 : called. */
8827 1484617761 : addr = CALL_EXPR_FN (call);
8828 :
8829 : /* If there is no function, return early. */
8830 1484617761 : if (addr == NULL_TREE)
8831 : return NULL_TREE;
8832 :
8833 1481150283 : STRIP_NOPS (addr);
8834 :
8835 : /* If this is a readonly function pointer, extract its initial value. */
8836 20479123 : if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
8837 2454304 : && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
8838 1481758480 : && DECL_INITIAL (addr))
8839 608144 : addr = DECL_INITIAL (addr);
8840 :
8841 : /* If the address is just `&f' for some function `f', then we know
8842 : that `f' is being called. */
8843 1481150283 : if (TREE_CODE (addr) == ADDR_EXPR
8844 1481150283 : && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
8845 1423203166 : return TREE_OPERAND (addr, 0);
8846 :
8847 : /* We couldn't figure out what was being called. */
8848 : return NULL_TREE;
8849 : }
8850 :
8851 : /* Return true when STMTs arguments and return value match those of FNDECL,
8852 : a decl of a builtin function. */
8853 :
8854 : static bool
8855 6836969 : tree_builtin_call_types_compatible_p (const_tree call, tree fndecl)
8856 : {
8857 6836969 : gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
8858 :
8859 6836969 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
8860 6836969 : if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
8861 6836969 : fndecl = decl;
8862 :
8863 6836969 : bool gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
8864 6836969 : if (gimple_form
8865 13057 : ? !useless_type_conversion_p (TREE_TYPE (call),
8866 13057 : TREE_TYPE (TREE_TYPE (fndecl)))
8867 6823912 : : (TYPE_MAIN_VARIANT (TREE_TYPE (call))
8868 6823912 : != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))))
8869 : return false;
8870 :
8871 6836753 : tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
8872 6836753 : unsigned nargs = call_expr_nargs (call);
8873 16806094 : for (unsigned i = 0; i < nargs; ++i, targs = TREE_CHAIN (targs))
8874 : {
8875 : /* Variadic args follow. */
8876 11859849 : if (!targs)
8877 : return true;
8878 9969998 : tree arg = CALL_EXPR_ARG (call, i);
8879 9969998 : tree type = TREE_VALUE (targs);
8880 9969998 : if (gimple_form
8881 9969998 : ? !useless_type_conversion_p (type, TREE_TYPE (arg))
8882 9956941 : : TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (TREE_TYPE (arg)))
8883 : {
8884 : /* For pointer arguments be more forgiving, e.g. due to
8885 : FILE * vs. fileptr_type_node, or say char * vs. const char *
8886 : differences etc. */
8887 1120287 : if (!gimple_form
8888 560472 : && POINTER_TYPE_P (type)
8889 559920 : && POINTER_TYPE_P (TREE_TYPE (arg))
8890 1120287 : && tree_nop_conversion_p (type, TREE_TYPE (arg)))
8891 559815 : continue;
8892 657 : return false;
8893 : }
8894 : }
8895 9891843 : if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
8896 : return false;
8897 : return true;
8898 : }
8899 :
8900 : /* If CALL_EXPR CALL calls a normal built-in function or an internal function,
8901 : return the associated function code, otherwise return CFN_LAST. */
8902 :
8903 : combined_fn
8904 44998187 : get_call_combined_fn (const_tree call)
8905 : {
8906 : /* It's invalid to call this function with anything but a CALL_EXPR. */
8907 44998187 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8908 :
8909 44998187 : if (!CALL_EXPR_FN (call))
8910 65816 : return as_combined_fn (CALL_EXPR_IFN (call));
8911 :
8912 44932371 : tree fndecl = get_callee_fndecl (call);
8913 44932371 : if (fndecl
8914 44911050 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
8915 51769340 : && tree_builtin_call_types_compatible_p (call, fndecl))
8916 6836091 : return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
8917 :
8918 : return CFN_LAST;
8919 : }
8920 :
8921 : /* Comparator of indices based on tree_node_counts. */
8922 :
8923 : static int
8924 0 : tree_nodes_cmp (const void *p1, const void *p2)
8925 : {
8926 0 : const unsigned *n1 = (const unsigned *)p1;
8927 0 : const unsigned *n2 = (const unsigned *)p2;
8928 :
8929 0 : return tree_node_counts[*n1] - tree_node_counts[*n2];
8930 : }
8931 :
8932 : /* Comparator of indices based on tree_code_counts. */
8933 :
8934 : static int
8935 0 : tree_codes_cmp (const void *p1, const void *p2)
8936 : {
8937 0 : const unsigned *n1 = (const unsigned *)p1;
8938 0 : const unsigned *n2 = (const unsigned *)p2;
8939 :
8940 0 : return tree_code_counts[*n1] - tree_code_counts[*n2];
8941 : }
8942 :
8943 : #define TREE_MEM_USAGE_SPACES 40
8944 :
8945 : /* Print debugging information about tree nodes generated during the compile,
8946 : and any language-specific information. */
8947 :
8948 : void
8949 0 : dump_tree_statistics (void)
8950 : {
8951 0 : if (GATHER_STATISTICS)
8952 : {
8953 : uint64_t total_nodes, total_bytes;
8954 : fprintf (stderr, "\nKind Nodes Bytes\n");
8955 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8956 : total_nodes = total_bytes = 0;
8957 :
8958 : {
8959 : auto_vec<unsigned> indices (all_kinds);
8960 : for (unsigned i = 0; i < all_kinds; i++)
8961 : indices.quick_push (i);
8962 : indices.qsort (tree_nodes_cmp);
8963 :
8964 : for (unsigned i = 0; i < (int) all_kinds; i++)
8965 : {
8966 : unsigned j = indices[i];
8967 : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n",
8968 : tree_node_kind_names[j], SIZE_AMOUNT (tree_node_counts[j]),
8969 : SIZE_AMOUNT (tree_node_sizes[j]));
8970 : total_nodes += tree_node_counts[j];
8971 : total_bytes += tree_node_sizes[j];
8972 : }
8973 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8974 : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n", "Total",
8975 : SIZE_AMOUNT (total_nodes), SIZE_AMOUNT (total_bytes));
8976 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8977 : }
8978 :
8979 : {
8980 : fprintf (stderr, "Code Nodes\n");
8981 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8982 :
8983 : auto_vec<unsigned> indices (MAX_TREE_CODES);
8984 : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8985 : indices.quick_push (i);
8986 : indices.qsort (tree_codes_cmp);
8987 :
8988 : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8989 : {
8990 : unsigned j = indices[i];
8991 : fprintf (stderr, "%-32s %6" PRIu64 "%c\n",
8992 : get_tree_code_name ((enum tree_code) j),
8993 : SIZE_AMOUNT (tree_code_counts[j]));
8994 : }
8995 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8996 : fprintf (stderr, "\n");
8997 : ssanames_print_statistics ();
8998 : fprintf (stderr, "\n");
8999 : phinodes_print_statistics ();
9000 : fprintf (stderr, "\n");
9001 : }
9002 : }
9003 : else
9004 0 : fprintf (stderr, "(No per-node statistics)\n");
9005 :
9006 0 : print_type_hash_statistics ();
9007 0 : print_debug_expr_statistics ();
9008 0 : print_value_expr_statistics ();
9009 0 : lang_hooks.print_statistics ();
9010 0 : }
9011 :
9012 : #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
9013 :
9014 : /* Generate a crc32 of the low BYTES bytes of VALUE. */
9015 :
9016 : unsigned
9017 16638573 : crc32_unsigned_n (unsigned chksum, unsigned value, unsigned bytes)
9018 : {
9019 : /* This relies on the raw feedback's top 4 bits being zero. */
9020 : #define FEEDBACK(X) ((X) * 0x04c11db7)
9021 : #define SYNDROME(X) (FEEDBACK ((X) & 1) ^ FEEDBACK ((X) & 2) \
9022 : ^ FEEDBACK ((X) & 4) ^ FEEDBACK ((X) & 8))
9023 16638573 : static const unsigned syndromes[16] =
9024 : {
9025 : SYNDROME(0x0), SYNDROME(0x1), SYNDROME(0x2), SYNDROME(0x3),
9026 : SYNDROME(0x4), SYNDROME(0x5), SYNDROME(0x6), SYNDROME(0x7),
9027 : SYNDROME(0x8), SYNDROME(0x9), SYNDROME(0xa), SYNDROME(0xb),
9028 : SYNDROME(0xc), SYNDROME(0xd), SYNDROME(0xe), SYNDROME(0xf),
9029 : };
9030 : #undef FEEDBACK
9031 : #undef SYNDROME
9032 :
9033 16638573 : value <<= (32 - bytes * 8);
9034 55367379 : for (unsigned ix = bytes * 2; ix--; value <<= 4)
9035 : {
9036 38728806 : unsigned feedback = syndromes[((value ^ chksum) >> 28) & 0xf];
9037 :
9038 38728806 : chksum = (chksum << 4) ^ feedback;
9039 : }
9040 :
9041 16638573 : return chksum;
9042 : }
9043 :
9044 : /* Generate a crc32 of a string. */
9045 :
9046 : unsigned
9047 8631 : crc32_string (unsigned chksum, const char *string)
9048 : {
9049 344748 : do
9050 344748 : chksum = crc32_byte (chksum, *string);
9051 344748 : while (*string++);
9052 8631 : return chksum;
9053 : }
9054 :
9055 : /* P is a string that will be used in a symbol. Mask out any characters
9056 : that are not valid in that context. */
9057 :
9058 : void
9059 7295 : clean_symbol_name (char *p)
9060 : {
9061 82978 : for (; *p; p++)
9062 75683 : if (! (ISALNUM (*p)
9063 : #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9064 : || *p == '$'
9065 : #endif
9066 : #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9067 : || *p == '.'
9068 : #endif
9069 : ))
9070 6962 : *p = '_';
9071 7295 : }
9072 :
9073 : static GTY(()) unsigned anon_cnt = 0; /* Saved for PCH. */
9074 :
9075 : /* Create a unique anonymous identifier. The identifier is still a
9076 : valid assembly label. */
9077 :
9078 : tree
9079 3599795 : make_anon_name ()
9080 : {
9081 3599795 : const char *fmt =
9082 : #if !defined (NO_DOT_IN_LABEL)
9083 : "."
9084 : #elif !defined (NO_DOLLAR_IN_LABEL)
9085 : "$"
9086 : #else
9087 : "_"
9088 : #endif
9089 : "_anon_%d";
9090 :
9091 3599795 : char buf[24];
9092 3599795 : int len = snprintf (buf, sizeof (buf), fmt, anon_cnt++);
9093 3599795 : gcc_checking_assert (len < int (sizeof (buf)));
9094 :
9095 3599795 : tree id = get_identifier_with_length (buf, len);
9096 3599795 : IDENTIFIER_ANON_P (id) = true;
9097 :
9098 3599795 : return id;
9099 : }
9100 :
9101 : /* Generate a name for a special-purpose function.
9102 : The generated name may need to be unique across the whole link.
9103 : Changes to this function may also require corresponding changes to
9104 : xstrdup_mask_random.
9105 : TYPE is some string to identify the purpose of this function to the
9106 : linker or collect2; it must start with an uppercase letter,
9107 : one of:
9108 : I - for constructors
9109 : D - for destructors
9110 : N - for C++ anonymous namespaces
9111 : F - for DWARF unwind frame information. */
9112 :
9113 : tree
9114 5402 : get_file_function_name (const char *type)
9115 : {
9116 5402 : char *buf;
9117 5402 : const char *p;
9118 5402 : char *q;
9119 :
9120 : /* If we already have a name we know to be unique, just use that. */
9121 5402 : if (first_global_object_name)
9122 5102 : p = q = ASTRDUP (first_global_object_name);
9123 : /* If the target is handling the constructors/destructors, they
9124 : will be local to this file and the name is only necessary for
9125 : debugging purposes.
9126 : We also assign sub_I and sub_D sufixes to constructors called from
9127 : the global static constructors. These are always local.
9128 : OpenMP "declare target" offloaded constructors/destructors use "off_I" and
9129 : "off_D" for the same purpose. */
9130 300 : else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
9131 600 : || ((startswith (type, "sub_") || startswith (type, "off_"))
9132 300 : && (type[4] == 'I' || type[4] == 'D')))
9133 : {
9134 300 : const char *file = main_input_filename;
9135 300 : if (! file)
9136 0 : file = LOCATION_FILE (input_location);
9137 : /* Just use the file's basename, because the full pathname
9138 : might be quite long. */
9139 300 : p = q = ASTRDUP (lbasename (file));
9140 : }
9141 : else
9142 : {
9143 : /* Otherwise, the name must be unique across the entire link.
9144 : We don't have anything that we know to be unique to this translation
9145 : unit, so use what we do have and throw in some randomness. */
9146 0 : unsigned len;
9147 0 : const char *name = weak_global_object_name;
9148 0 : const char *file = main_input_filename;
9149 :
9150 0 : if (! name)
9151 0 : name = "";
9152 0 : if (! file)
9153 0 : file = LOCATION_FILE (input_location);
9154 :
9155 0 : len = strlen (file);
9156 0 : q = (char *) alloca (9 + 19 + len + 1);
9157 0 : memcpy (q, file, len + 1);
9158 :
9159 0 : snprintf (q + len, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
9160 : crc32_string (0, name), get_random_seed (false));
9161 :
9162 0 : p = q;
9163 : }
9164 :
9165 5402 : clean_symbol_name (q);
9166 5402 : buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
9167 : + strlen (type));
9168 :
9169 : /* Set up the name of the file-level functions we may need.
9170 : Use a global object (which is already required to be unique over
9171 : the program) rather than the file name (which imposes extra
9172 : constraints). */
9173 5402 : sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
9174 :
9175 5402 : return get_identifier (buf);
9176 : }
9177 :
9178 : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9179 :
9180 : /* Complain that the tree code of NODE does not match the expected 0
9181 : terminated list of trailing codes. The trailing code list can be
9182 : empty, for a more vague error message. FILE, LINE, and FUNCTION
9183 : are of the caller. */
9184 :
9185 : void
9186 0 : tree_check_failed (const_tree node, const char *file,
9187 : int line, const char *function, ...)
9188 : {
9189 0 : va_list args;
9190 0 : const char *buffer;
9191 0 : unsigned length = 0;
9192 0 : enum tree_code code;
9193 :
9194 0 : va_start (args, function);
9195 0 : while ((code = (enum tree_code) va_arg (args, int)))
9196 0 : length += 4 + strlen (get_tree_code_name (code));
9197 0 : va_end (args);
9198 0 : if (length)
9199 : {
9200 0 : char *tmp;
9201 0 : va_start (args, function);
9202 0 : length += strlen ("expected ");
9203 0 : buffer = tmp = (char *) alloca (length);
9204 0 : length = 0;
9205 0 : while ((code = (enum tree_code) va_arg (args, int)))
9206 : {
9207 0 : const char *prefix = length ? " or " : "expected ";
9208 :
9209 0 : strcpy (tmp + length, prefix);
9210 0 : length += strlen (prefix);
9211 0 : strcpy (tmp + length, get_tree_code_name (code));
9212 0 : length += strlen (get_tree_code_name (code));
9213 : }
9214 0 : va_end (args);
9215 : }
9216 : else
9217 : buffer = "unexpected node";
9218 :
9219 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9220 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9221 : function, trim_filename (file), line);
9222 : }
9223 :
9224 : /* Complain that the tree code of NODE does match the expected 0
9225 : terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9226 : the caller. */
9227 :
9228 : void
9229 0 : tree_not_check_failed (const_tree node, const char *file,
9230 : int line, const char *function, ...)
9231 : {
9232 0 : va_list args;
9233 0 : char *buffer;
9234 0 : unsigned length = 0;
9235 0 : enum tree_code code;
9236 :
9237 0 : va_start (args, function);
9238 0 : while ((code = (enum tree_code) va_arg (args, int)))
9239 0 : length += 4 + strlen (get_tree_code_name (code));
9240 0 : va_end (args);
9241 0 : va_start (args, function);
9242 0 : buffer = (char *) alloca (length);
9243 0 : length = 0;
9244 0 : while ((code = (enum tree_code) va_arg (args, int)))
9245 : {
9246 0 : if (length)
9247 : {
9248 0 : strcpy (buffer + length, " or ");
9249 0 : length += 4;
9250 : }
9251 0 : strcpy (buffer + length, get_tree_code_name (code));
9252 0 : length += strlen (get_tree_code_name (code));
9253 : }
9254 0 : va_end (args);
9255 :
9256 0 : internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9257 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9258 : function, trim_filename (file), line);
9259 : }
9260 :
9261 : /* Similar to tree_check_failed, except that we check for a class of tree
9262 : code, given in CL. */
9263 :
9264 : void
9265 0 : tree_class_check_failed (const_tree node, const enum tree_code_class cl,
9266 : const char *file, int line, const char *function)
9267 : {
9268 0 : internal_error
9269 0 : ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9270 0 : TREE_CODE_CLASS_STRING (cl),
9271 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9272 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9273 : }
9274 :
9275 : /* Similar to tree_check_failed, except that instead of specifying a
9276 : dozen codes, use the knowledge that they're all sequential. */
9277 :
9278 : void
9279 0 : tree_range_check_failed (const_tree node, const char *file, int line,
9280 : const char *function, enum tree_code c1,
9281 : enum tree_code c2)
9282 : {
9283 0 : char *buffer;
9284 0 : unsigned length = 0;
9285 0 : unsigned int c;
9286 :
9287 0 : for (c = c1; c <= c2; ++c)
9288 0 : length += 4 + strlen (get_tree_code_name ((enum tree_code) c));
9289 :
9290 0 : length += strlen ("expected ");
9291 0 : buffer = (char *) alloca (length);
9292 0 : length = 0;
9293 :
9294 0 : for (c = c1; c <= c2; ++c)
9295 : {
9296 0 : const char *prefix = length ? " or " : "expected ";
9297 :
9298 0 : strcpy (buffer + length, prefix);
9299 0 : length += strlen (prefix);
9300 0 : strcpy (buffer + length, get_tree_code_name ((enum tree_code) c));
9301 0 : length += strlen (get_tree_code_name ((enum tree_code) c));
9302 : }
9303 :
9304 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9305 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9306 : function, trim_filename (file), line);
9307 : }
9308 :
9309 :
9310 : /* Similar to tree_check_failed, except that we check that a tree does
9311 : not have the specified code, given in CL. */
9312 :
9313 : void
9314 0 : tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
9315 : const char *file, int line, const char *function)
9316 : {
9317 0 : internal_error
9318 0 : ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9319 0 : TREE_CODE_CLASS_STRING (cl),
9320 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9321 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9322 : }
9323 :
9324 :
9325 : /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9326 :
9327 : void
9328 0 : omp_clause_check_failed (const_tree node, const char *file, int line,
9329 : const char *function, enum omp_clause_code code)
9330 : {
9331 0 : internal_error ("tree check: expected %<omp_clause %s%>, have %qs "
9332 : "in %s, at %s:%d",
9333 0 : omp_clause_code_name[code],
9334 0 : get_tree_code_name (TREE_CODE (node)),
9335 : function, trim_filename (file), line);
9336 : }
9337 :
9338 :
9339 : /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9340 :
9341 : void
9342 0 : omp_clause_range_check_failed (const_tree node, const char *file, int line,
9343 : const char *function, enum omp_clause_code c1,
9344 : enum omp_clause_code c2)
9345 : {
9346 0 : char *buffer;
9347 0 : unsigned length = 0;
9348 0 : unsigned int c;
9349 :
9350 0 : for (c = c1; c <= c2; ++c)
9351 0 : length += 4 + strlen (omp_clause_code_name[c]);
9352 :
9353 0 : length += strlen ("expected ");
9354 0 : buffer = (char *) alloca (length);
9355 0 : length = 0;
9356 :
9357 0 : for (c = c1; c <= c2; ++c)
9358 : {
9359 0 : const char *prefix = length ? " or " : "expected ";
9360 :
9361 0 : strcpy (buffer + length, prefix);
9362 0 : length += strlen (prefix);
9363 0 : strcpy (buffer + length, omp_clause_code_name[c]);
9364 0 : length += strlen (omp_clause_code_name[c]);
9365 : }
9366 :
9367 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9368 0 : buffer, omp_clause_code_name[TREE_CODE (node)],
9369 : function, trim_filename (file), line);
9370 : }
9371 :
9372 :
9373 : #undef DEFTREESTRUCT
9374 : #define DEFTREESTRUCT(VAL, NAME) NAME,
9375 :
9376 : static const char *ts_enum_names[] = {
9377 : #include "treestruct.def"
9378 : };
9379 : #undef DEFTREESTRUCT
9380 :
9381 : #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9382 :
9383 : /* Similar to tree_class_check_failed, except that we check for
9384 : whether CODE contains the tree structure identified by EN. */
9385 :
9386 : void
9387 0 : tree_contains_struct_check_failed (const_tree node,
9388 : const enum tree_node_structure_enum en,
9389 : const char *file, int line,
9390 : const char *function)
9391 : {
9392 0 : internal_error
9393 0 : ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9394 0 : TS_ENUM_NAME (en),
9395 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9396 : }
9397 :
9398 :
9399 : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9400 : (dynamically sized) vector. */
9401 :
9402 : void
9403 0 : tree_int_cst_elt_check_failed (int idx, int len, const char *file, int line,
9404 : const char *function)
9405 : {
9406 0 : internal_error
9407 0 : ("tree check: accessed elt %d of %<tree_int_cst%> with %d elts in %s, "
9408 : "at %s:%d",
9409 : idx + 1, len, function, trim_filename (file), line);
9410 : }
9411 :
9412 : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9413 : (dynamically sized) vector. */
9414 :
9415 : void
9416 0 : tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
9417 : const char *function)
9418 : {
9419 0 : internal_error
9420 0 : ("tree check: accessed elt %d of %<tree_vec%> with %d elts in %s, at %s:%d",
9421 : idx + 1, len, function, trim_filename (file), line);
9422 : }
9423 :
9424 : /* Similar to above, except that the check is for the bounds of the operand
9425 : vector of an expression node EXP. */
9426 :
9427 : void
9428 0 : tree_operand_check_failed (int idx, const_tree exp, const char *file,
9429 : int line, const char *function)
9430 : {
9431 0 : enum tree_code code = TREE_CODE (exp);
9432 0 : internal_error
9433 0 : ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9434 : idx + 1, get_tree_code_name (code), TREE_OPERAND_LENGTH (exp),
9435 : function, trim_filename (file), line);
9436 : }
9437 :
9438 : /* Similar to above, except that the check is for the number of
9439 : operands of an OMP_CLAUSE node. */
9440 :
9441 : void
9442 0 : omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
9443 : int line, const char *function)
9444 : {
9445 0 : internal_error
9446 0 : ("tree check: accessed operand %d of %<omp_clause %s%> with %d operands "
9447 0 : "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
9448 0 : omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
9449 : trim_filename (file), line);
9450 : }
9451 : #endif /* ENABLE_TREE_CHECKING */
9452 :
9453 : /* Create a new vector type node holding NUNITS units of type INNERTYPE,
9454 : and mapped to the machine mode MODE. Initialize its fields and build
9455 : the information necessary for debugging output. */
9456 :
9457 : static tree
9458 70187479 : make_vector_type (tree innertype, poly_int64 nunits, machine_mode mode)
9459 : {
9460 70187479 : tree t;
9461 70187479 : tree mv_innertype = TYPE_MAIN_VARIANT (innertype);
9462 :
9463 70187479 : t = make_node (VECTOR_TYPE);
9464 70187479 : TREE_TYPE (t) = mv_innertype;
9465 70187479 : SET_TYPE_VECTOR_SUBPARTS (t, nunits);
9466 70187479 : SET_TYPE_MODE (t, mode);
9467 :
9468 70187479 : if (TYPE_STRUCTURAL_EQUALITY_P (mv_innertype) || in_lto_p)
9469 1175774 : SET_TYPE_STRUCTURAL_EQUALITY (t);
9470 69011705 : else if ((TYPE_CANONICAL (mv_innertype) != innertype
9471 65540586 : || mode != VOIDmode)
9472 99744750 : && !VECTOR_BOOLEAN_TYPE_P (t))
9473 31816498 : TYPE_CANONICAL (t)
9474 63632996 : = make_vector_type (TYPE_CANONICAL (mv_innertype), nunits, VOIDmode);
9475 :
9476 70187479 : layout_type (t);
9477 :
9478 70187479 : hashval_t hash = type_hash_canon_hash (t);
9479 70187479 : t = type_hash_canon (hash, t);
9480 :
9481 : /* We have built a main variant, based on the main variant of the
9482 : inner type. Use it to build the variant we return. */
9483 140369647 : if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
9484 70970907 : && TREE_TYPE (t) != innertype)
9485 787418 : return build_type_attribute_qual_variant (t,
9486 787418 : TYPE_ATTRIBUTES (innertype),
9487 1574836 : TYPE_QUALS (innertype));
9488 :
9489 : return t;
9490 : }
9491 :
9492 : static tree
9493 3988748 : make_or_reuse_type (unsigned size, int unsignedp)
9494 : {
9495 3988748 : int i;
9496 :
9497 3988748 : if (size == INT_TYPE_SIZE)
9498 856266 : return unsignedp ? unsigned_type_node : integer_type_node;
9499 3132482 : if (size == CHAR_TYPE_SIZE)
9500 570844 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
9501 2561638 : if (size == SHORT_TYPE_SIZE)
9502 856266 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
9503 1741736 : if (size == LONG_TYPE_SIZE)
9504 834504 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
9505 870868 : if (size == LONG_LONG_TYPE_SIZE)
9506 21762 : return (unsignedp ? long_long_unsigned_type_node
9507 21762 : : long_long_integer_type_node);
9508 :
9509 863426 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9510 849106 : if (size == int_n_data[i].bitsize
9511 849106 : && int_n_enabled_p[i])
9512 834786 : return (unsignedp ? int_n_trees[i].unsigned_type
9513 834786 : : int_n_trees[i].signed_type);
9514 :
9515 14320 : if (unsignedp)
9516 7160 : return make_unsigned_type (size);
9517 : else
9518 7160 : return make_signed_type (size);
9519 : }
9520 :
9521 : /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9522 :
9523 : static tree
9524 5708440 : make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
9525 : {
9526 5708440 : if (satp)
9527 : {
9528 2854220 : if (size == SHORT_FRACT_TYPE_SIZE)
9529 570844 : return unsignedp ? sat_unsigned_short_fract_type_node
9530 570844 : : sat_short_fract_type_node;
9531 2283376 : if (size == FRACT_TYPE_SIZE)
9532 570844 : return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
9533 1712532 : if (size == LONG_FRACT_TYPE_SIZE)
9534 570844 : return unsignedp ? sat_unsigned_long_fract_type_node
9535 570844 : : sat_long_fract_type_node;
9536 1141688 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9537 570844 : return unsignedp ? sat_unsigned_long_long_fract_type_node
9538 570844 : : sat_long_long_fract_type_node;
9539 : }
9540 : else
9541 : {
9542 2854220 : if (size == SHORT_FRACT_TYPE_SIZE)
9543 570844 : return unsignedp ? unsigned_short_fract_type_node
9544 570844 : : short_fract_type_node;
9545 2283376 : if (size == FRACT_TYPE_SIZE)
9546 570844 : return unsignedp ? unsigned_fract_type_node : fract_type_node;
9547 1712532 : if (size == LONG_FRACT_TYPE_SIZE)
9548 570844 : return unsignedp ? unsigned_long_fract_type_node
9549 570844 : : long_fract_type_node;
9550 1141688 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9551 570844 : return unsignedp ? unsigned_long_long_fract_type_node
9552 570844 : : long_long_fract_type_node;
9553 : }
9554 :
9555 1141688 : return make_fract_type (size, unsignedp, satp);
9556 : }
9557 :
9558 : /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9559 :
9560 : static tree
9561 4566752 : make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
9562 : {
9563 4566752 : if (satp)
9564 : {
9565 2283376 : if (size == SHORT_ACCUM_TYPE_SIZE)
9566 570844 : return unsignedp ? sat_unsigned_short_accum_type_node
9567 570844 : : sat_short_accum_type_node;
9568 1712532 : if (size == ACCUM_TYPE_SIZE)
9569 570844 : return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
9570 1141688 : if (size == LONG_ACCUM_TYPE_SIZE)
9571 570844 : return unsignedp ? sat_unsigned_long_accum_type_node
9572 570844 : : sat_long_accum_type_node;
9573 570844 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9574 570844 : return unsignedp ? sat_unsigned_long_long_accum_type_node
9575 570844 : : sat_long_long_accum_type_node;
9576 : }
9577 : else
9578 : {
9579 2283376 : if (size == SHORT_ACCUM_TYPE_SIZE)
9580 570844 : return unsignedp ? unsigned_short_accum_type_node
9581 570844 : : short_accum_type_node;
9582 1712532 : if (size == ACCUM_TYPE_SIZE)
9583 570844 : return unsignedp ? unsigned_accum_type_node : accum_type_node;
9584 1141688 : if (size == LONG_ACCUM_TYPE_SIZE)
9585 570844 : return unsignedp ? unsigned_long_accum_type_node
9586 570844 : : long_accum_type_node;
9587 570844 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9588 570844 : return unsignedp ? unsigned_long_long_accum_type_node
9589 570844 : : long_long_accum_type_node;
9590 : }
9591 :
9592 0 : return make_accum_type (size, unsignedp, satp);
9593 : }
9594 :
9595 :
9596 : /* Create an atomic variant node for TYPE. This routine is called
9597 : during initialization of data types to create the 5 basic atomic
9598 : types. The generic build_variant_type function requires these to
9599 : already be set up in order to function properly, so cannot be
9600 : called from there. If ALIGN is non-zero, then ensure alignment is
9601 : overridden to this value. */
9602 :
9603 : static tree
9604 1427110 : build_atomic_base (tree type, unsigned int align)
9605 : {
9606 1427110 : tree t;
9607 :
9608 : /* Make sure its not already registered. */
9609 1427110 : if ((t = get_qualified_type (type, TYPE_QUAL_ATOMIC)))
9610 : return t;
9611 :
9612 1427110 : t = build_variant_type_copy (type);
9613 1427110 : set_type_quals (t, TYPE_QUAL_ATOMIC);
9614 :
9615 1427110 : if (align)
9616 0 : SET_TYPE_ALIGN (t, align);
9617 :
9618 : return t;
9619 : }
9620 :
9621 : /* Information about the _FloatN and _FloatNx types. This must be in
9622 : the same order as the corresponding TI_* enum values. */
9623 : const floatn_type_info floatn_nx_types[NUM_FLOATN_NX_TYPES] =
9624 : {
9625 : { 16, false },
9626 : { 32, false },
9627 : { 64, false },
9628 : { 128, false },
9629 : { 32, true },
9630 : { 64, true },
9631 : { 128, true },
9632 : };
9633 :
9634 :
9635 : /* Create nodes for all integer types (and error_mark_node) using the sizes
9636 : of C datatypes. SIGNED_CHAR specifies whether char is signed. */
9637 :
9638 : void
9639 285422 : build_common_tree_nodes (bool signed_char)
9640 : {
9641 285422 : int i;
9642 :
9643 285422 : error_mark_node = make_node (ERROR_MARK);
9644 285422 : TREE_TYPE (error_mark_node) = error_mark_node;
9645 :
9646 285422 : initialize_sizetypes ();
9647 :
9648 : /* Define both `signed char' and `unsigned char'. */
9649 285422 : signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
9650 285422 : TYPE_STRING_FLAG (signed_char_type_node) = 1;
9651 285422 : unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
9652 285422 : TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
9653 :
9654 : /* Define `char', which is like either `signed char' or `unsigned char'
9655 : but not the same as either. */
9656 285422 : char_type_node
9657 285422 : = (signed_char
9658 285422 : ? make_signed_type (CHAR_TYPE_SIZE)
9659 55587 : : make_unsigned_type (CHAR_TYPE_SIZE));
9660 285422 : TYPE_STRING_FLAG (char_type_node) = 1;
9661 :
9662 285422 : short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
9663 285422 : short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
9664 285422 : integer_type_node = make_signed_type (INT_TYPE_SIZE);
9665 285422 : unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
9666 292676 : long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
9667 292676 : long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
9668 285422 : long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
9669 285422 : long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
9670 :
9671 856266 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9672 : {
9673 285422 : int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
9674 285422 : int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
9675 :
9676 285422 : if (int_n_enabled_p[i])
9677 : {
9678 278262 : integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type;
9679 278262 : integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type;
9680 : }
9681 : }
9682 :
9683 : /* Define a boolean type. This type only represents boolean values but
9684 : may be larger than char depending on the value of BOOL_TYPE_SIZE. */
9685 285422 : boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
9686 285422 : TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
9687 285422 : TYPE_PRECISION (boolean_type_node) = 1;
9688 285422 : TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
9689 :
9690 : /* Define what type to use for size_t. */
9691 292676 : if (strcmp (SIZE_TYPE, "unsigned int") == 0)
9692 7254 : size_type_node = unsigned_type_node;
9693 278168 : else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
9694 278168 : size_type_node = long_unsigned_type_node;
9695 0 : else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
9696 0 : size_type_node = long_long_unsigned_type_node;
9697 0 : else if (strcmp (SIZE_TYPE, "short unsigned int") == 0)
9698 0 : size_type_node = short_unsigned_type_node;
9699 : else
9700 : {
9701 0 : int i;
9702 :
9703 0 : size_type_node = NULL_TREE;
9704 0 : for (i = 0; i < NUM_INT_N_ENTS; i++)
9705 0 : if (int_n_enabled_p[i])
9706 : {
9707 0 : char name[50], altname[50];
9708 0 : sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
9709 0 : sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize);
9710 :
9711 0 : if (strcmp (name, SIZE_TYPE) == 0
9712 0 : || strcmp (altname, SIZE_TYPE) == 0)
9713 : {
9714 0 : size_type_node = int_n_trees[i].unsigned_type;
9715 : }
9716 : }
9717 0 : if (size_type_node == NULL_TREE)
9718 0 : gcc_unreachable ();
9719 : }
9720 :
9721 : /* Define what type to use for ptrdiff_t. */
9722 292676 : if (strcmp (PTRDIFF_TYPE, "int") == 0)
9723 7254 : ptrdiff_type_node = integer_type_node;
9724 278168 : else if (strcmp (PTRDIFF_TYPE, "long int") == 0)
9725 278168 : ptrdiff_type_node = long_integer_type_node;
9726 0 : else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)
9727 0 : ptrdiff_type_node = long_long_integer_type_node;
9728 0 : else if (strcmp (PTRDIFF_TYPE, "short int") == 0)
9729 0 : ptrdiff_type_node = short_integer_type_node;
9730 : else
9731 : {
9732 0 : ptrdiff_type_node = NULL_TREE;
9733 0 : for (int i = 0; i < NUM_INT_N_ENTS; i++)
9734 0 : if (int_n_enabled_p[i])
9735 : {
9736 0 : char name[50], altname[50];
9737 0 : sprintf (name, "__int%d", int_n_data[i].bitsize);
9738 0 : sprintf (altname, "__int%d__", int_n_data[i].bitsize);
9739 :
9740 0 : if (strcmp (name, PTRDIFF_TYPE) == 0
9741 0 : || strcmp (altname, PTRDIFF_TYPE) == 0)
9742 0 : ptrdiff_type_node = int_n_trees[i].signed_type;
9743 : }
9744 0 : if (ptrdiff_type_node == NULL_TREE)
9745 0 : gcc_unreachable ();
9746 : }
9747 :
9748 : /* Fill in the rest of the sized types. Reuse existing type nodes
9749 : when possible. */
9750 285422 : intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
9751 285422 : intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
9752 285422 : intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
9753 285422 : intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
9754 285422 : intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
9755 :
9756 285422 : unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
9757 285422 : unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
9758 285422 : unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
9759 285422 : unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
9760 285422 : unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
9761 :
9762 : /* Don't call build_qualified type for atomics. That routine does
9763 : special processing for atomics, and until they are initialized
9764 : it's better not to make that call.
9765 :
9766 : Check to see if there is a target override for atomic types. */
9767 :
9768 285422 : atomicQI_type_node = build_atomic_base (unsigned_intQI_type_node,
9769 285422 : targetm.atomic_align_for_mode (QImode));
9770 285422 : atomicHI_type_node = build_atomic_base (unsigned_intHI_type_node,
9771 285422 : targetm.atomic_align_for_mode (HImode));
9772 285422 : atomicSI_type_node = build_atomic_base (unsigned_intSI_type_node,
9773 285422 : targetm.atomic_align_for_mode (SImode));
9774 285422 : atomicDI_type_node = build_atomic_base (unsigned_intDI_type_node,
9775 285422 : targetm.atomic_align_for_mode (DImode));
9776 285422 : atomicTI_type_node = build_atomic_base (unsigned_intTI_type_node,
9777 285422 : targetm.atomic_align_for_mode (TImode));
9778 :
9779 285422 : access_public_node = get_identifier ("public");
9780 285422 : access_protected_node = get_identifier ("protected");
9781 285422 : access_private_node = get_identifier ("private");
9782 :
9783 : /* Define these next since types below may used them. */
9784 285422 : integer_zero_node = build_int_cst (integer_type_node, 0);
9785 285422 : integer_one_node = build_int_cst (integer_type_node, 1);
9786 285422 : integer_minus_one_node = build_int_cst (integer_type_node, -1);
9787 :
9788 285422 : size_zero_node = size_int (0);
9789 285422 : size_one_node = size_int (1);
9790 285422 : bitsize_zero_node = bitsize_int (0);
9791 285422 : bitsize_one_node = bitsize_int (1);
9792 285422 : bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
9793 :
9794 285422 : boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9795 285422 : boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9796 :
9797 285422 : void_type_node = make_node (VOID_TYPE);
9798 285422 : layout_type (void_type_node);
9799 :
9800 : /* We are not going to have real types in C with less than byte alignment,
9801 : so we might as well not have any types that claim to have it. */
9802 285422 : SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT);
9803 285422 : TYPE_USER_ALIGN (void_type_node) = 0;
9804 :
9805 285422 : void_node = make_node (VOID_CST);
9806 285422 : TREE_TYPE (void_node) = void_type_node;
9807 :
9808 285422 : void_list_node = build_tree_list (NULL_TREE, void_type_node);
9809 :
9810 285422 : null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
9811 285422 : layout_type (TREE_TYPE (null_pointer_node));
9812 :
9813 285422 : ptr_type_node = build_pointer_type (void_type_node);
9814 285422 : const_ptr_type_node
9815 285422 : = build_pointer_type (build_type_variant (void_type_node, 1, 0));
9816 1997954 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
9817 1712532 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
9818 :
9819 292676 : pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
9820 :
9821 285422 : float_type_node = make_node (REAL_TYPE);
9822 285422 : machine_mode float_type_mode
9823 285422 : = targetm.c.mode_for_floating_type (TI_FLOAT_TYPE);
9824 285422 : SET_TYPE_MODE (float_type_node, float_type_mode);
9825 285422 : TYPE_PRECISION (float_type_node)
9826 285422 : = GET_MODE_PRECISION (float_type_mode).to_constant ();
9827 285422 : layout_type (float_type_node);
9828 :
9829 285422 : double_type_node = make_node (REAL_TYPE);
9830 285422 : machine_mode double_type_mode
9831 285422 : = targetm.c.mode_for_floating_type (TI_DOUBLE_TYPE);
9832 285422 : SET_TYPE_MODE (double_type_node, double_type_mode);
9833 285422 : TYPE_PRECISION (double_type_node)
9834 285422 : = GET_MODE_PRECISION (double_type_mode).to_constant ();
9835 285422 : layout_type (double_type_node);
9836 :
9837 285422 : long_double_type_node = make_node (REAL_TYPE);
9838 285422 : machine_mode long_double_type_mode
9839 285422 : = targetm.c.mode_for_floating_type (TI_LONG_DOUBLE_TYPE);
9840 285422 : SET_TYPE_MODE (long_double_type_node, long_double_type_mode);
9841 285422 : TYPE_PRECISION (long_double_type_node)
9842 285422 : = GET_MODE_PRECISION (long_double_type_mode).to_constant ();
9843 285422 : layout_type (long_double_type_node);
9844 :
9845 2283376 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9846 : {
9847 1997954 : int n = floatn_nx_types[i].n;
9848 1997954 : bool extended = floatn_nx_types[i].extended;
9849 1997954 : scalar_float_mode mode;
9850 1997954 : if (!targetm.floatn_mode (n, extended).exists (&mode))
9851 285422 : continue;
9852 1712532 : int precision = GET_MODE_PRECISION (mode);
9853 1712532 : FLOATN_NX_TYPE_NODE (i) = make_node (REAL_TYPE);
9854 1712532 : TYPE_PRECISION (FLOATN_NX_TYPE_NODE (i)) = precision;
9855 1712532 : layout_type (FLOATN_NX_TYPE_NODE (i));
9856 1712532 : SET_TYPE_MODE (FLOATN_NX_TYPE_NODE (i), mode);
9857 : }
9858 285422 : float128t_type_node = float128_type_node;
9859 : #ifdef HAVE_BFmode
9860 285422 : if (REAL_MODE_FORMAT (BFmode) == &arm_bfloat_half_format
9861 285422 : && targetm.scalar_mode_supported_p (BFmode)
9862 570844 : && targetm.libgcc_floating_mode_supported_p (BFmode))
9863 : {
9864 285422 : bfloat16_type_node = make_node (REAL_TYPE);
9865 285422 : TYPE_PRECISION (bfloat16_type_node) = GET_MODE_PRECISION (BFmode);
9866 285422 : layout_type (bfloat16_type_node);
9867 285422 : SET_TYPE_MODE (bfloat16_type_node, BFmode);
9868 : }
9869 : #endif
9870 :
9871 285422 : float_ptr_type_node = build_pointer_type (float_type_node);
9872 285422 : double_ptr_type_node = build_pointer_type (double_type_node);
9873 285422 : long_double_ptr_type_node = build_pointer_type (long_double_type_node);
9874 285422 : integer_ptr_type_node = build_pointer_type (integer_type_node);
9875 :
9876 : /* Fixed size integer types. */
9877 285422 : uint16_type_node = make_or_reuse_type (16, 1);
9878 285422 : uint32_type_node = make_or_reuse_type (32, 1);
9879 285422 : uint64_type_node = make_or_reuse_type (64, 1);
9880 285422 : if (targetm.scalar_mode_supported_p (TImode))
9881 278262 : uint128_type_node = make_or_reuse_type (128, 1);
9882 :
9883 : /* Decimal float types. */
9884 285422 : if (targetm.decimal_float_supported_p ())
9885 : {
9886 285422 : dfloat32_type_node = make_node (REAL_TYPE);
9887 285422 : TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
9888 285422 : SET_TYPE_MODE (dfloat32_type_node, SDmode);
9889 285422 : layout_type (dfloat32_type_node);
9890 :
9891 285422 : dfloat64_type_node = make_node (REAL_TYPE);
9892 285422 : TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
9893 285422 : SET_TYPE_MODE (dfloat64_type_node, DDmode);
9894 285422 : layout_type (dfloat64_type_node);
9895 :
9896 285422 : dfloat128_type_node = make_node (REAL_TYPE);
9897 285422 : TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
9898 285422 : SET_TYPE_MODE (dfloat128_type_node, TDmode);
9899 285422 : layout_type (dfloat128_type_node);
9900 :
9901 285422 : dfloat64x_type_node = make_node (REAL_TYPE);
9902 285422 : TYPE_PRECISION (dfloat64x_type_node) = DECIMAL128_TYPE_SIZE;
9903 285422 : SET_TYPE_MODE (dfloat64x_type_node, TDmode);
9904 285422 : layout_type (dfloat64x_type_node);
9905 : }
9906 :
9907 285422 : complex_integer_type_node = build_complex_type (integer_type_node, true);
9908 285422 : complex_float_type_node = build_complex_type (float_type_node, true);
9909 285422 : complex_double_type_node = build_complex_type (double_type_node, true);
9910 285422 : complex_long_double_type_node = build_complex_type (long_double_type_node,
9911 : true);
9912 :
9913 2283376 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9914 : {
9915 1997954 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
9916 1712532 : COMPLEX_FLOATN_NX_TYPE_NODE (i)
9917 1712532 : = build_complex_type (FLOATN_NX_TYPE_NODE (i));
9918 : }
9919 :
9920 : /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9921 : #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9922 : sat_ ## KIND ## _type_node = \
9923 : make_sat_signed_ ## KIND ## _type (SIZE); \
9924 : sat_unsigned_ ## KIND ## _type_node = \
9925 : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9926 : KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9927 : unsigned_ ## KIND ## _type_node = \
9928 : make_unsigned_ ## KIND ## _type (SIZE);
9929 :
9930 : #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9931 : sat_ ## WIDTH ## KIND ## _type_node = \
9932 : make_sat_signed_ ## KIND ## _type (SIZE); \
9933 : sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9934 : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9935 : WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9936 : unsigned_ ## WIDTH ## KIND ## _type_node = \
9937 : make_unsigned_ ## KIND ## _type (SIZE);
9938 :
9939 : /* Make fixed-point type nodes based on four different widths. */
9940 : #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9941 : MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9942 : MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9943 : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9944 : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9945 :
9946 : /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9947 : #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9948 : NAME ## _type_node = \
9949 : make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9950 : u ## NAME ## _type_node = \
9951 : make_or_reuse_unsigned_ ## KIND ## _type \
9952 : (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9953 : sat_ ## NAME ## _type_node = \
9954 : make_or_reuse_sat_signed_ ## KIND ## _type \
9955 : (GET_MODE_BITSIZE (MODE ## mode)); \
9956 : sat_u ## NAME ## _type_node = \
9957 : make_or_reuse_sat_unsigned_ ## KIND ## _type \
9958 : (GET_MODE_BITSIZE (U ## MODE ## mode));
9959 :
9960 : /* Fixed-point type and mode nodes. */
9961 285422 : MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
9962 285422 : MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
9963 285422 : MAKE_FIXED_MODE_NODE (fract, qq, QQ)
9964 285422 : MAKE_FIXED_MODE_NODE (fract, hq, HQ)
9965 285422 : MAKE_FIXED_MODE_NODE (fract, sq, SQ)
9966 285422 : MAKE_FIXED_MODE_NODE (fract, dq, DQ)
9967 285422 : MAKE_FIXED_MODE_NODE (fract, tq, TQ)
9968 285422 : MAKE_FIXED_MODE_NODE (accum, ha, HA)
9969 285422 : MAKE_FIXED_MODE_NODE (accum, sa, SA)
9970 285422 : MAKE_FIXED_MODE_NODE (accum, da, DA)
9971 285422 : MAKE_FIXED_MODE_NODE (accum, ta, TA)
9972 :
9973 285422 : {
9974 285422 : tree t = targetm.build_builtin_va_list ();
9975 :
9976 : /* Many back-ends define record types without setting TYPE_NAME.
9977 : If we copied the record type here, we'd keep the original
9978 : record type without a name. This breaks name mangling. So,
9979 : don't copy record types and let c_common_nodes_and_builtins()
9980 : declare the type to be __builtin_va_list. */
9981 285422 : if (TREE_CODE (t) != RECORD_TYPE)
9982 285422 : t = build_variant_type_copy (t);
9983 :
9984 285422 : va_list_type_node = t;
9985 : }
9986 :
9987 : /* SCEV analyzer global shared trees. */
9988 285422 : chrec_dont_know = make_node (SCEV_NOT_KNOWN);
9989 285422 : TREE_TYPE (chrec_dont_know) = void_type_node;
9990 285422 : chrec_known = make_node (SCEV_KNOWN);
9991 285422 : TREE_TYPE (chrec_known) = void_type_node;
9992 285422 : }
9993 :
9994 : /* Modify DECL for given flags.
9995 : TM_PURE attribute is set only on types, so the function will modify
9996 : DECL's type when ECF_TM_PURE is used. */
9997 :
9998 : void
9999 31280808 : set_call_expr_flags (tree decl, int flags)
10000 : {
10001 31280808 : if (flags & ECF_NOTHROW)
10002 27047130 : TREE_NOTHROW (decl) = 1;
10003 31280808 : if (flags & ECF_CONST)
10004 12970353 : TREE_READONLY (decl) = 1;
10005 31280808 : if (flags & ECF_PURE)
10006 1496628 : DECL_PURE_P (decl) = 1;
10007 31280808 : if (flags & ECF_LOOPING_CONST_OR_PURE)
10008 56848 : DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
10009 31280808 : if (flags & ECF_NOVOPS)
10010 0 : DECL_IS_NOVOPS (decl) = 1;
10011 31280808 : if (flags & ECF_NORETURN)
10012 1219386 : TREE_THIS_VOLATILE (decl) = 1;
10013 31280808 : if (flags & ECF_MALLOC)
10014 734263 : DECL_IS_MALLOC (decl) = 1;
10015 31280808 : if (flags & ECF_RETURNS_TWICE)
10016 0 : DECL_IS_RETURNS_TWICE (decl) = 1;
10017 31280808 : if (flags & ECF_LEAF)
10018 26882923 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
10019 26882923 : NULL, DECL_ATTRIBUTES (decl));
10020 31280808 : if (flags & ECF_COLD)
10021 644648 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("cold"),
10022 644648 : NULL, DECL_ATTRIBUTES (decl));
10023 31280808 : if (flags & ECF_RET1)
10024 0 : DECL_ATTRIBUTES (decl)
10025 0 : = tree_cons (get_identifier ("fn spec"),
10026 : build_tree_list (NULL_TREE, build_string (2, "1 ")),
10027 0 : DECL_ATTRIBUTES (decl));
10028 31280808 : if ((flags & ECF_TM_PURE) && flag_tm)
10029 536 : apply_tm_attr (decl, get_identifier ("transaction_pure"));
10030 31280808 : if ((flags & ECF_XTHROW))
10031 409408 : DECL_ATTRIBUTES (decl)
10032 818816 : = tree_cons (get_identifier ("expected_throw"),
10033 409408 : NULL, DECL_ATTRIBUTES (decl));
10034 :
10035 31280808 : if (flags & ECF_CB_1_2)
10036 : {
10037 375468 : tree attr = callback_build_attr (1, 1, 2);
10038 375468 : TREE_CHAIN (attr) = DECL_ATTRIBUTES (decl);
10039 375468 : DECL_ATTRIBUTES (decl) = attr;
10040 : }
10041 :
10042 : /* Looping const or pure is implied by noreturn.
10043 : There is currently no way to declare looping const or looping pure alone. */
10044 31280808 : gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE)
10045 : || (flags & (ECF_CONST | ECF_PURE)));
10046 31280808 : }
10047 :
10048 :
10049 : /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
10050 :
10051 : static void
10052 9506200 : local_define_builtin (const char *name, tree type, enum built_in_function code,
10053 : const char *library_name, int ecf_flags)
10054 : {
10055 9506200 : tree decl;
10056 :
10057 9506200 : decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
10058 : library_name, NULL_TREE);
10059 9506200 : set_call_expr_flags (decl, ecf_flags);
10060 :
10061 9506200 : set_builtin_decl (code, decl, true);
10062 9506200 : }
10063 :
10064 : /* Call this function after instantiating all builtins that the language
10065 : front end cares about. This will build the rest of the builtins
10066 : and internal functions that are relied upon by the tree optimizers and
10067 : the middle-end. */
10068 :
10069 : void
10070 285405 : build_common_builtin_nodes (void)
10071 : {
10072 285405 : tree tmp, ftype;
10073 285405 : int ecf_flags;
10074 :
10075 285405 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_PADDING))
10076 : {
10077 56848 : ftype = build_function_type_list (void_type_node,
10078 : ptr_type_node,
10079 : ptr_type_node,
10080 : NULL_TREE);
10081 56848 : local_define_builtin ("__builtin_clear_padding", ftype,
10082 : BUILT_IN_CLEAR_PADDING,
10083 : "__builtin_clear_padding",
10084 : ECF_LEAF | ECF_NOTHROW);
10085 : }
10086 :
10087 285405 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)
10088 233203 : || !builtin_decl_explicit_p (BUILT_IN_TRAP)
10089 233203 : || !builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP)
10090 228557 : || !builtin_decl_explicit_p (BUILT_IN_OBSERVABLE_CHKPT)
10091 513962 : || !builtin_decl_explicit_p (BUILT_IN_ABORT))
10092 : {
10093 56848 : ftype = build_function_type (void_type_node, void_list_node);
10094 56848 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE))
10095 52202 : local_define_builtin ("__builtin_unreachable", ftype,
10096 : BUILT_IN_UNREACHABLE,
10097 : "__builtin_unreachable",
10098 : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10099 : | ECF_CONST | ECF_COLD);
10100 56848 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP))
10101 56848 : local_define_builtin ("__builtin_unreachable trap", ftype,
10102 : BUILT_IN_UNREACHABLE_TRAP,
10103 : "__builtin_unreachable trap",
10104 : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10105 : | ECF_CONST | ECF_COLD);
10106 56848 : if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
10107 56848 : local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
10108 : "abort",
10109 : ECF_LEAF | ECF_NORETURN | ECF_CONST | ECF_COLD);
10110 56848 : if (!builtin_decl_explicit_p (BUILT_IN_TRAP))
10111 20913 : local_define_builtin ("__builtin_trap", ftype, BUILT_IN_TRAP,
10112 : "__builtin_trap",
10113 : ECF_NORETURN | ECF_NOTHROW | ECF_LEAF | ECF_COLD);
10114 56848 : if (!builtin_decl_explicit_p (BUILT_IN_OBSERVABLE_CHKPT))
10115 56848 : local_define_builtin ("__builtin_observable_checkpoint", ftype,
10116 : BUILT_IN_OBSERVABLE_CHKPT,
10117 : "__builtin_observable_checkpoint",
10118 : ECF_NOTHROW | ECF_LEAF | ECF_CONST
10119 : | ECF_LOOPING_CONST_OR_PURE);
10120 : }
10121 :
10122 285405 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)
10123 285405 : || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10124 : {
10125 56848 : ftype = build_function_type_list (ptr_type_node,
10126 : ptr_type_node, const_ptr_type_node,
10127 : size_type_node, NULL_TREE);
10128 :
10129 56848 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY))
10130 56848 : local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
10131 : "memcpy", ECF_NOTHROW | ECF_LEAF);
10132 56848 : if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10133 52202 : local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
10134 : "memmove", ECF_NOTHROW | ECF_LEAF);
10135 : }
10136 :
10137 285405 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP))
10138 : {
10139 52202 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10140 : const_ptr_type_node, size_type_node,
10141 : NULL_TREE);
10142 52202 : local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
10143 : "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10144 : }
10145 :
10146 285405 : if (!builtin_decl_explicit_p (BUILT_IN_MEMSET))
10147 : {
10148 52202 : ftype = build_function_type_list (ptr_type_node,
10149 : ptr_type_node, integer_type_node,
10150 : size_type_node, NULL_TREE);
10151 52202 : local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
10152 : "memset", ECF_NOTHROW | ECF_LEAF);
10153 : }
10154 :
10155 : /* If we're checking the stack, `alloca' can throw. */
10156 285336 : const int alloca_flags
10157 285405 : = ECF_MALLOC | ECF_LEAF | (flag_stack_check ? 0 : ECF_NOTHROW);
10158 :
10159 285405 : if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA))
10160 : {
10161 56848 : ftype = build_function_type_list (ptr_type_node,
10162 : size_type_node, NULL_TREE);
10163 56848 : local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
10164 : "alloca", alloca_flags);
10165 : }
10166 :
10167 285405 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10168 : size_type_node, NULL_TREE);
10169 285405 : local_define_builtin ("__builtin_alloca_with_align", ftype,
10170 : BUILT_IN_ALLOCA_WITH_ALIGN,
10171 : "__builtin_alloca_with_align",
10172 : alloca_flags);
10173 :
10174 285405 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10175 : size_type_node, size_type_node, NULL_TREE);
10176 285405 : local_define_builtin ("__builtin_alloca_with_align_and_max", ftype,
10177 : BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX,
10178 : "__builtin_alloca_with_align_and_max",
10179 : alloca_flags);
10180 :
10181 285405 : ftype = build_function_type_list (void_type_node,
10182 : ptr_type_node, ptr_type_node,
10183 : ptr_type_node, NULL_TREE);
10184 285405 : local_define_builtin ("__builtin_init_trampoline", ftype,
10185 : BUILT_IN_INIT_TRAMPOLINE,
10186 : "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
10187 285405 : local_define_builtin ("__builtin_init_heap_trampoline", ftype,
10188 : BUILT_IN_INIT_HEAP_TRAMPOLINE,
10189 : "__builtin_init_heap_trampoline",
10190 : ECF_NOTHROW | ECF_LEAF);
10191 285405 : local_define_builtin ("__builtin_init_descriptor", ftype,
10192 : BUILT_IN_INIT_DESCRIPTOR,
10193 : "__builtin_init_descriptor", ECF_NOTHROW | ECF_LEAF);
10194 :
10195 285405 : ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
10196 285405 : local_define_builtin ("__builtin_adjust_trampoline", ftype,
10197 : BUILT_IN_ADJUST_TRAMPOLINE,
10198 : "__builtin_adjust_trampoline",
10199 : ECF_CONST | ECF_NOTHROW);
10200 285405 : local_define_builtin ("__builtin_adjust_descriptor", ftype,
10201 : BUILT_IN_ADJUST_DESCRIPTOR,
10202 : "__builtin_adjust_descriptor",
10203 : ECF_CONST | ECF_NOTHROW);
10204 :
10205 285405 : ftype = build_function_type_list (void_type_node,
10206 : ptr_type_node, ptr_type_node, NULL_TREE);
10207 285405 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_CACHE))
10208 56848 : local_define_builtin ("__builtin___clear_cache", ftype,
10209 : BUILT_IN_CLEAR_CACHE,
10210 : "__clear_cache",
10211 : ECF_NOTHROW);
10212 :
10213 285405 : local_define_builtin ("__builtin_nonlocal_goto", ftype,
10214 : BUILT_IN_NONLOCAL_GOTO,
10215 : "__builtin_nonlocal_goto",
10216 : ECF_NORETURN | ECF_NOTHROW);
10217 :
10218 285405 : tree ptr_ptr_type_node = build_pointer_type (ptr_type_node);
10219 :
10220 285405 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED))
10221 : {
10222 56848 : ftype = build_function_type_list (void_type_node,
10223 : ptr_type_node, // void *chain
10224 : ptr_type_node, // void *func
10225 : ptr_ptr_type_node, // void **dst
10226 : NULL_TREE);
10227 56848 : local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype,
10228 : BUILT_IN_GCC_NESTED_PTR_CREATED,
10229 : "__gcc_nested_func_ptr_created", ECF_NOTHROW);
10230 : }
10231 :
10232 285405 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED))
10233 : {
10234 56848 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10235 56848 : local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype,
10236 : BUILT_IN_GCC_NESTED_PTR_DELETED,
10237 : "__gcc_nested_func_ptr_deleted", ECF_NOTHROW);
10238 : }
10239 :
10240 285405 : ftype = build_function_type_list (void_type_node,
10241 : ptr_type_node, ptr_type_node, NULL_TREE);
10242 285405 : local_define_builtin ("__builtin_setjmp_setup", ftype,
10243 : BUILT_IN_SETJMP_SETUP,
10244 : "__builtin_setjmp_setup", ECF_NOTHROW);
10245 :
10246 285405 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10247 285405 : local_define_builtin ("__builtin_setjmp_receiver", ftype,
10248 : BUILT_IN_SETJMP_RECEIVER,
10249 : "__builtin_setjmp_receiver", ECF_NOTHROW | ECF_LEAF);
10250 :
10251 285405 : ftype = build_function_type_list (ptr_type_node, NULL_TREE);
10252 285405 : local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
10253 : "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
10254 :
10255 285405 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10256 285405 : local_define_builtin ("__builtin_stack_restore", ftype,
10257 : BUILT_IN_STACK_RESTORE,
10258 : "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
10259 :
10260 285405 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10261 : const_ptr_type_node, size_type_node,
10262 : NULL_TREE);
10263 285405 : local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ,
10264 : "__builtin_memcmp_eq",
10265 : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10266 :
10267 285405 : local_define_builtin ("__builtin_strncmp_eq", ftype, BUILT_IN_STRNCMP_EQ,
10268 : "__builtin_strncmp_eq",
10269 : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10270 :
10271 285405 : local_define_builtin ("__builtin_strcmp_eq", ftype, BUILT_IN_STRCMP_EQ,
10272 : "__builtin_strcmp_eq",
10273 : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10274 :
10275 : /* If there's a possibility that we might use the ARM EABI, build the
10276 : alternate __cxa_end_cleanup node used to resume from C++. */
10277 285405 : if (targetm.arm_eabi_unwinder)
10278 : {
10279 0 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10280 0 : local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
10281 : BUILT_IN_CXA_END_CLEANUP,
10282 : "__cxa_end_cleanup",
10283 : ECF_NORETURN | ECF_XTHROW | ECF_LEAF);
10284 : }
10285 :
10286 285405 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10287 570810 : local_define_builtin ("__builtin_unwind_resume", ftype,
10288 : BUILT_IN_UNWIND_RESUME,
10289 285405 : ((targetm_common.except_unwind_info (&global_options)
10290 : == UI_SJLJ)
10291 : ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10292 : ECF_NORETURN | ECF_XTHROW);
10293 :
10294 285405 : if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE)
10295 : {
10296 52202 : ftype = build_function_type_list (ptr_type_node, integer_type_node,
10297 : NULL_TREE);
10298 52202 : local_define_builtin ("__builtin_return_address", ftype,
10299 : BUILT_IN_RETURN_ADDRESS,
10300 : "__builtin_return_address",
10301 : ECF_NOTHROW);
10302 : }
10303 :
10304 285405 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)
10305 285405 : || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10306 : {
10307 56848 : ftype = build_function_type_list (void_type_node, ptr_type_node,
10308 : ptr_type_node, NULL_TREE);
10309 56848 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER))
10310 56848 : local_define_builtin ("__cyg_profile_func_enter", ftype,
10311 : BUILT_IN_PROFILE_FUNC_ENTER,
10312 : "__cyg_profile_func_enter", 0);
10313 56848 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10314 56848 : local_define_builtin ("__cyg_profile_func_exit", ftype,
10315 : BUILT_IN_PROFILE_FUNC_EXIT,
10316 : "__cyg_profile_func_exit", 0);
10317 : }
10318 :
10319 : /* The exception object and filter values from the runtime. The argument
10320 : must be zero before exception lowering, i.e. from the front end. After
10321 : exception lowering, it will be the region number for the exception
10322 : landing pad. These functions are PURE instead of CONST to prevent
10323 : them from being hoisted past the exception edge that will initialize
10324 : its value in the landing pad. */
10325 285405 : ftype = build_function_type_list (ptr_type_node,
10326 : integer_type_node, NULL_TREE);
10327 285405 : ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF;
10328 : /* Only use TM_PURE if we have TM language support. */
10329 285405 : if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
10330 472 : ecf_flags |= ECF_TM_PURE;
10331 285405 : local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
10332 : "__builtin_eh_pointer", ecf_flags);
10333 :
10334 285405 : tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
10335 285405 : ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
10336 285405 : local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
10337 : "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10338 :
10339 285405 : ftype = build_function_type_list (void_type_node,
10340 : integer_type_node, integer_type_node,
10341 : NULL_TREE);
10342 285405 : local_define_builtin ("__builtin_eh_copy_values", ftype,
10343 : BUILT_IN_EH_COPY_VALUES,
10344 : "__builtin_eh_copy_values", ECF_NOTHROW);
10345 :
10346 : /* Complex multiplication and division. These are handled as builtins
10347 : rather than optabs because emit_library_call_value doesn't support
10348 : complex. Further, we can do slightly better with folding these
10349 : beasties if the real and complex parts of the arguments are separate. */
10350 285405 : {
10351 285405 : int mode;
10352 :
10353 1997835 : for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
10354 : {
10355 1712430 : char mode_name_buf[4], *q;
10356 1712430 : const char *p;
10357 1712430 : enum built_in_function mcode, dcode;
10358 1712430 : tree type, inner_type;
10359 1712430 : const char *prefix = "__";
10360 :
10361 1712430 : if (targetm.libfunc_gnu_prefix)
10362 0 : prefix = "__gnu_";
10363 :
10364 1712430 : type = lang_hooks.types.type_for_mode ((machine_mode) mode, 0);
10365 1712430 : if (type == NULL)
10366 124303 : continue;
10367 1588127 : inner_type = TREE_TYPE (type);
10368 :
10369 1588127 : ftype = build_function_type_list (type, inner_type, inner_type,
10370 : inner_type, inner_type, NULL_TREE);
10371 :
10372 1588127 : mcode = ((enum built_in_function)
10373 1588127 : (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10374 1588127 : dcode = ((enum built_in_function)
10375 1588127 : (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10376 :
10377 4764381 : for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
10378 3176254 : *q = TOLOWER (*p);
10379 1588127 : *q = '\0';
10380 :
10381 : /* For -ftrapping-math these should throw from a former
10382 : -fnon-call-exception stmt. */
10383 1588127 : built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
10384 : NULL);
10385 1588127 : local_define_builtin (built_in_names[mcode], ftype, mcode,
10386 : built_in_names[mcode],
10387 : ECF_CONST | ECF_LEAF);
10388 :
10389 1588127 : built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
10390 : NULL);
10391 1588127 : local_define_builtin (built_in_names[dcode], ftype, dcode,
10392 : built_in_names[dcode],
10393 : ECF_CONST | ECF_LEAF);
10394 : }
10395 : }
10396 :
10397 285405 : init_internal_fns ();
10398 285405 : }
10399 :
10400 : /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10401 : better way.
10402 :
10403 : If we requested a pointer to a vector, build up the pointers that
10404 : we stripped off while looking for the inner type. Similarly for
10405 : return values from functions.
10406 :
10407 : The argument TYPE is the top of the chain, and BOTTOM is the
10408 : new type which we will point to. */
10409 :
10410 : tree
10411 0 : reconstruct_complex_type (tree type, tree bottom)
10412 : {
10413 0 : tree inner, outer;
10414 :
10415 0 : if (TREE_CODE (type) == POINTER_TYPE)
10416 : {
10417 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10418 0 : outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
10419 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10420 : }
10421 : else if (TREE_CODE (type) == REFERENCE_TYPE)
10422 : {
10423 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10424 0 : outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
10425 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10426 : }
10427 : else if (TREE_CODE (type) == ARRAY_TYPE)
10428 : {
10429 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10430 0 : outer = build_array_type (inner, TYPE_DOMAIN (type));
10431 : }
10432 : else if (TREE_CODE (type) == FUNCTION_TYPE)
10433 : {
10434 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10435 0 : outer = build_function_type (inner, TYPE_ARG_TYPES (type),
10436 0 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
10437 : }
10438 : else if (TREE_CODE (type) == METHOD_TYPE)
10439 : {
10440 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10441 : /* The build_method_type_directly() routine prepends 'this' to argument list,
10442 : so we must compensate by getting rid of it. */
10443 0 : outer
10444 : = build_method_type_directly
10445 0 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
10446 : inner,
10447 0 : TREE_CHAIN (TYPE_ARG_TYPES (type)));
10448 : }
10449 : else if (TREE_CODE (type) == OFFSET_TYPE)
10450 : {
10451 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10452 0 : outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
10453 : }
10454 : else
10455 : return bottom;
10456 :
10457 0 : return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
10458 0 : TYPE_QUALS (type));
10459 : }
10460 :
10461 : /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10462 : the inner type. */
10463 : tree
10464 32908897 : build_vector_type_for_mode (tree innertype, machine_mode mode)
10465 : {
10466 32908897 : poly_int64 nunits;
10467 32908897 : unsigned int bitsize;
10468 :
10469 32908897 : switch (GET_MODE_CLASS (mode))
10470 : {
10471 32907561 : case MODE_VECTOR_BOOL:
10472 32907561 : case MODE_VECTOR_INT:
10473 32907561 : case MODE_VECTOR_FLOAT:
10474 32907561 : case MODE_VECTOR_FRACT:
10475 32907561 : case MODE_VECTOR_UFRACT:
10476 32907561 : case MODE_VECTOR_ACCUM:
10477 32907561 : case MODE_VECTOR_UACCUM:
10478 65815122 : nunits = GET_MODE_NUNITS (mode);
10479 32907561 : break;
10480 :
10481 1336 : case MODE_INT:
10482 : /* Check that there are no leftover bits. */
10483 1336 : bitsize = GET_MODE_BITSIZE (as_a <scalar_int_mode> (mode));
10484 1336 : gcc_assert (bitsize % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
10485 1336 : nunits = bitsize / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
10486 1336 : break;
10487 :
10488 0 : default:
10489 0 : gcc_unreachable ();
10490 : }
10491 :
10492 32908897 : return make_vector_type (innertype, nunits, mode);
10493 : }
10494 :
10495 : /* Similarly, but takes the inner type and number of units, which must be
10496 : a power of two. */
10497 :
10498 : tree
10499 2892478 : build_vector_type (tree innertype, poly_int64 nunits)
10500 : {
10501 2892478 : return make_vector_type (innertype, nunits, VOIDmode);
10502 : }
10503 :
10504 : /* Build a truth vector with NUNITS units, giving it mode MASK_MODE. */
10505 :
10506 : tree
10507 2461005 : build_truth_vector_type_for_mode (poly_uint64 nunits, machine_mode mask_mode)
10508 : {
10509 2461005 : gcc_assert (mask_mode != BLKmode);
10510 :
10511 2461005 : unsigned HOST_WIDE_INT esize;
10512 2461005 : if (VECTOR_MODE_P (mask_mode))
10513 : {
10514 2348735 : poly_uint64 vsize = GET_MODE_PRECISION (mask_mode);
10515 2348735 : esize = vector_element_size (vsize, nunits);
10516 2348735 : }
10517 : else
10518 : esize = 1;
10519 :
10520 2461005 : tree bool_type = build_nonstandard_boolean_type (esize);
10521 :
10522 2461005 : return make_vector_type (bool_type, nunits, mask_mode);
10523 : }
10524 :
10525 : /* Build a vector type that holds one boolean result for each element of
10526 : vector type VECTYPE. The public interface for this operation is
10527 : truth_type_for. */
10528 :
10529 : static tree
10530 2451835 : build_truth_vector_type_for (tree vectype)
10531 : {
10532 2451835 : machine_mode vector_mode = TYPE_MODE (vectype);
10533 2451835 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
10534 :
10535 2451835 : machine_mode mask_mode;
10536 88884 : if (VECTOR_MODE_P (vector_mode)
10537 2540151 : && targetm.vectorize.get_mask_mode (vector_mode).exists (&mask_mode))
10538 2451267 : return build_truth_vector_type_for_mode (nunits, mask_mode);
10539 :
10540 568 : poly_uint64 vsize = tree_to_poly_uint64 (TYPE_SIZE (vectype));
10541 568 : unsigned HOST_WIDE_INT esize = vector_element_size (vsize, nunits);
10542 568 : tree bool_type = build_nonstandard_boolean_type (esize);
10543 :
10544 568 : return make_vector_type (bool_type, nunits, VOIDmode);
10545 : }
10546 :
10547 : /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
10548 : set. */
10549 :
10550 : tree
10551 108033 : build_opaque_vector_type (tree innertype, poly_int64 nunits)
10552 : {
10553 108033 : tree t = make_vector_type (innertype, nunits, VOIDmode);
10554 108033 : tree cand;
10555 : /* We always build the non-opaque variant before the opaque one,
10556 : so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10557 108033 : cand = TYPE_NEXT_VARIANT (t);
10558 108033 : if (cand
10559 96607 : && TYPE_VECTOR_OPAQUE (cand)
10560 170926 : && check_qualified_type (cand, t, TYPE_QUALS (t)))
10561 : return cand;
10562 : /* Othewise build a variant type and make sure to queue it after
10563 : the non-opaque type. */
10564 45141 : cand = build_distinct_type_copy (t);
10565 45141 : TYPE_VECTOR_OPAQUE (cand) = true;
10566 45141 : TYPE_CANONICAL (cand) = TYPE_CANONICAL (t);
10567 45141 : TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t);
10568 45141 : TYPE_NEXT_VARIANT (t) = cand;
10569 45141 : TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
10570 : /* Type variants have no alias set defined. */
10571 45141 : TYPE_ALIAS_SET (cand) = -1;
10572 45141 : return cand;
10573 : }
10574 :
10575 : /* Return the value of element I of VECTOR_CST T as a wide_int. */
10576 :
10577 : static poly_wide_int
10578 544505 : vector_cst_int_elt (const_tree t, unsigned int i)
10579 : {
10580 : /* First handle elements that are directly encoded. */
10581 544505 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10582 544505 : if (i < encoded_nelts)
10583 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, i));
10584 :
10585 : /* Identify the pattern that contains element I and work out the index of
10586 : the last encoded element for that pattern. */
10587 544505 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10588 544505 : unsigned int pattern = i % npatterns;
10589 544505 : unsigned int count = i / npatterns;
10590 544505 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10591 :
10592 : /* If there are no steps, the final encoded value is the right one. */
10593 544505 : if (!VECTOR_CST_STEPPED_P (t))
10594 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, final_i));
10595 :
10596 : /* Otherwise work out the value from the last two encoded elements. */
10597 544505 : tree v1 = VECTOR_CST_ENCODED_ELT (t, final_i - npatterns);
10598 544505 : tree v2 = VECTOR_CST_ENCODED_ELT (t, final_i);
10599 544505 : poly_wide_int diff = wi::to_poly_wide (v2) - wi::to_poly_wide (v1);
10600 544505 : return wi::to_poly_wide (v2) + (count - 2) * diff;
10601 544505 : }
10602 :
10603 : /* Return the value of element I of VECTOR_CST T. */
10604 :
10605 : tree
10606 6330581 : vector_cst_elt (const_tree t, unsigned int i)
10607 : {
10608 : /* First handle elements that are directly encoded. */
10609 6330581 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10610 6330581 : if (i < encoded_nelts)
10611 4321655 : return VECTOR_CST_ENCODED_ELT (t, i);
10612 :
10613 : /* If there are no steps, the final encoded value is the right one. */
10614 2008926 : if (!VECTOR_CST_STEPPED_P (t))
10615 : {
10616 : /* Identify the pattern that contains element I and work out the index of
10617 : the last encoded element for that pattern. */
10618 1464421 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10619 1464421 : unsigned int pattern = i % npatterns;
10620 1464421 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10621 1464421 : return VECTOR_CST_ENCODED_ELT (t, final_i);
10622 : }
10623 :
10624 : /* Otherwise work out the value from the last two encoded elements. */
10625 544505 : return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t)),
10626 1089010 : vector_cst_int_elt (t, i));
10627 : }
10628 :
10629 : /* Given an initializer INIT, return TRUE if INIT is zero or some
10630 : aggregate of zeros. Otherwise return FALSE. If NONZERO is not
10631 : null, set *NONZERO if and only if INIT is known not to be all
10632 : zeros. The combination of return value of false and *NONZERO
10633 : false implies that INIT may but need not be all zeros. Other
10634 : combinations indicate definitive answers. */
10635 :
10636 : bool
10637 42572628 : initializer_zerop (const_tree init, bool *nonzero /* = NULL */)
10638 : {
10639 42572628 : bool dummy;
10640 42572628 : if (!nonzero)
10641 39828247 : nonzero = &dummy;
10642 :
10643 : /* Conservatively clear NONZERO and set it only if INIT is definitely
10644 : not all zero. */
10645 42572628 : *nonzero = false;
10646 :
10647 42572628 : STRIP_NOPS (init);
10648 :
10649 42572628 : unsigned HOST_WIDE_INT off = 0;
10650 :
10651 42572628 : switch (TREE_CODE (init))
10652 : {
10653 16660070 : case INTEGER_CST:
10654 16660070 : if (integer_zerop (init))
10655 : return true;
10656 :
10657 10460304 : *nonzero = true;
10658 10460304 : return false;
10659 :
10660 551773 : case REAL_CST:
10661 : /* ??? Note that this is not correct for C4X float formats. There,
10662 : a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10663 : negative exponent. */
10664 551773 : if (real_zerop (init)
10665 641934 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)))
10666 : return true;
10667 :
10668 464582 : *nonzero = true;
10669 464582 : return false;
10670 :
10671 0 : case FIXED_CST:
10672 0 : if (fixed_zerop (init))
10673 : return true;
10674 :
10675 0 : *nonzero = true;
10676 0 : return false;
10677 :
10678 17350 : case COMPLEX_CST:
10679 17350 : if (integer_zerop (init)
10680 17350 : || (real_zerop (init)
10681 2957 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
10682 2915 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))))
10683 3143 : return true;
10684 :
10685 14207 : *nonzero = true;
10686 14207 : return false;
10687 :
10688 1117949 : case VECTOR_CST:
10689 1117949 : if (VECTOR_CST_NPATTERNS (init) == 1
10690 1030024 : && VECTOR_CST_DUPLICATE_P (init)
10691 1764661 : && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)))
10692 : return true;
10693 :
10694 778765 : *nonzero = true;
10695 778765 : return false;
10696 :
10697 : case RAW_DATA_CST:
10698 1580 : for (unsigned int i = 0; i < (unsigned int) RAW_DATA_LENGTH (init); ++i)
10699 1580 : if (RAW_DATA_POINTER (init)[i])
10700 : {
10701 1536 : *nonzero = true;
10702 1536 : return false;
10703 : }
10704 : return true;
10705 :
10706 4236429 : case CONSTRUCTOR:
10707 4236429 : {
10708 4236429 : if (TREE_CLOBBER_P (init))
10709 : return false;
10710 :
10711 : unsigned HOST_WIDE_INT idx;
10712 : tree elt;
10713 :
10714 3599409 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
10715 2744381 : if (!initializer_zerop (elt, nonzero))
10716 : return false;
10717 :
10718 : return true;
10719 : }
10720 :
10721 349645 : case MEM_REF:
10722 349645 : {
10723 349645 : tree arg = TREE_OPERAND (init, 0);
10724 349645 : if (TREE_CODE (arg) != ADDR_EXPR)
10725 : return false;
10726 83328 : tree offset = TREE_OPERAND (init, 1);
10727 83328 : if (TREE_CODE (offset) != INTEGER_CST
10728 83328 : || !tree_fits_uhwi_p (offset))
10729 : return false;
10730 83328 : off = tree_to_uhwi (offset);
10731 83328 : if (INT_MAX < off)
10732 : return false;
10733 83324 : arg = TREE_OPERAND (arg, 0);
10734 83324 : if (TREE_CODE (arg) != STRING_CST)
10735 : return false;
10736 : init = arg;
10737 : }
10738 : /* Fall through. */
10739 :
10740 : case STRING_CST:
10741 : {
10742 : gcc_assert (off <= INT_MAX);
10743 :
10744 156488 : int i = off;
10745 156488 : int n = TREE_STRING_LENGTH (init);
10746 156488 : if (n <= i)
10747 : return false;
10748 :
10749 : /* We need to loop through all elements to handle cases like
10750 : "\0" and "\0foobar". */
10751 168691 : for (i = 0; i < n; ++i)
10752 163108 : if (TREE_STRING_POINTER (init)[i] != '\0')
10753 : {
10754 150872 : *nonzero = true;
10755 150872 : return false;
10756 : }
10757 :
10758 : return true;
10759 : }
10760 :
10761 : default:
10762 : return false;
10763 : }
10764 : }
10765 :
10766 : /* Return true if EXPR is an initializer expression in which every element
10767 : is a constant that is numerically equal to 0 or 1. The elements do not
10768 : need to be equal to each other. */
10769 :
10770 : bool
10771 131713 : initializer_each_zero_or_onep (const_tree expr)
10772 : {
10773 131713 : STRIP_ANY_LOCATION_WRAPPER (expr);
10774 :
10775 131713 : switch (TREE_CODE (expr))
10776 : {
10777 48135 : case INTEGER_CST:
10778 48135 : return integer_zerop (expr) || integer_onep (expr);
10779 :
10780 22852 : case REAL_CST:
10781 22852 : return real_zerop (expr) || real_onep (expr);
10782 :
10783 60726 : case VECTOR_CST:
10784 60726 : {
10785 60726 : unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
10786 60726 : if (VECTOR_CST_STEPPED_P (expr)
10787 60726 : && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
10788 : return false;
10789 :
10790 72394 : for (unsigned int i = 0; i < nelts; ++i)
10791 : {
10792 70987 : tree elt = vector_cst_elt (expr, i);
10793 70987 : if (!initializer_each_zero_or_onep (elt))
10794 : return false;
10795 : }
10796 :
10797 : return true;
10798 : }
10799 :
10800 : default:
10801 : return false;
10802 : }
10803 : }
10804 :
10805 : /* Check if vector VEC consists of all the equal elements and
10806 : that the number of elements corresponds to the type of VEC.
10807 : The function returns first element of the vector
10808 : or NULL_TREE if the vector is not uniform. */
10809 : tree
10810 2694742 : uniform_vector_p (const_tree vec)
10811 : {
10812 2694742 : tree first, t;
10813 2694742 : unsigned HOST_WIDE_INT i, nelts;
10814 :
10815 2694742 : if (vec == NULL_TREE)
10816 : return NULL_TREE;
10817 :
10818 2694742 : gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
10819 :
10820 2694742 : if (TREE_CODE (vec) == VEC_DUPLICATE_EXPR)
10821 0 : return TREE_OPERAND (vec, 0);
10822 :
10823 2694742 : else if (TREE_CODE (vec) == VECTOR_CST)
10824 : {
10825 240273 : if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
10826 187925 : return VECTOR_CST_ENCODED_ELT (vec, 0);
10827 : return NULL_TREE;
10828 : }
10829 :
10830 2454469 : else if (TREE_CODE (vec) == CONSTRUCTOR
10831 2454469 : && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)).is_constant (&nelts))
10832 : {
10833 160628 : first = error_mark_node;
10834 :
10835 544476 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
10836 : {
10837 483733 : if (i == 0)
10838 : {
10839 160628 : first = t;
10840 160628 : continue;
10841 : }
10842 323105 : if (!operand_equal_p (first, t, 0))
10843 : return NULL_TREE;
10844 : }
10845 60743 : if (i != nelts)
10846 : return NULL_TREE;
10847 :
10848 60550 : if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
10849 : return uniform_vector_p (first);
10850 : return first;
10851 : }
10852 :
10853 : return NULL_TREE;
10854 : }
10855 :
10856 : /* If OP is a uniform vector return the element it is a splat from. */
10857 :
10858 : tree
10859 268950 : ssa_uniform_vector_p (tree op)
10860 : {
10861 268950 : if (TREE_CODE (op) == VECTOR_CST
10862 : || TREE_CODE (op) == VEC_DUPLICATE_EXPR
10863 : || TREE_CODE (op) == CONSTRUCTOR)
10864 11497 : return uniform_vector_p (op);
10865 : if (TREE_CODE (op) == SSA_NAME)
10866 : {
10867 257453 : gimple *def_stmt = SSA_NAME_DEF_STMT (op);
10868 257453 : if (gimple_assign_single_p (def_stmt))
10869 106953 : return uniform_vector_p (gimple_assign_rhs1 (def_stmt));
10870 : }
10871 : return NULL_TREE;
10872 : }
10873 :
10874 : /* If the argument is INTEGER_CST, return it. If the argument is vector
10875 : with all elements the same INTEGER_CST, return that INTEGER_CST. Otherwise
10876 : return NULL_TREE.
10877 : Look through location wrappers. */
10878 :
10879 : tree
10880 893981198 : uniform_integer_cst_p (tree t)
10881 : {
10882 893981198 : STRIP_ANY_LOCATION_WRAPPER (t);
10883 :
10884 893981198 : if (TREE_CODE (t) == INTEGER_CST)
10885 : return t;
10886 :
10887 361749248 : if (VECTOR_TYPE_P (TREE_TYPE (t)))
10888 : {
10889 931304 : t = uniform_vector_p (t);
10890 931304 : if (t && TREE_CODE (t) == INTEGER_CST)
10891 : return t;
10892 : }
10893 :
10894 : return NULL_TREE;
10895 : }
10896 :
10897 : /* Checks to see if T is a constant or a constant vector and if each element E
10898 : adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE. */
10899 :
10900 : tree
10901 3053516 : bitmask_inv_cst_vector_p (tree t)
10902 : {
10903 :
10904 3053516 : tree_code code = TREE_CODE (t);
10905 3053516 : tree type = TREE_TYPE (t);
10906 :
10907 3053516 : if (!INTEGRAL_TYPE_P (type)
10908 3053516 : && !VECTOR_INTEGER_TYPE_P (type))
10909 : return NULL_TREE;
10910 :
10911 3053516 : unsigned HOST_WIDE_INT nelts = 1;
10912 3053516 : tree cst;
10913 3053516 : unsigned int idx = 0;
10914 3053516 : bool uniform = uniform_integer_cst_p (t);
10915 3053516 : tree newtype = unsigned_type_for (type);
10916 3053516 : tree_vector_builder builder;
10917 3053516 : if (code == INTEGER_CST)
10918 : cst = t;
10919 : else
10920 : {
10921 17509 : if (!VECTOR_CST_NELTS (t).is_constant (&nelts))
10922 : return NULL_TREE;
10923 :
10924 17509 : cst = vector_cst_elt (t, 0);
10925 17509 : builder.new_vector (newtype, nelts, 1);
10926 : }
10927 :
10928 3053516 : tree ty = unsigned_type_for (TREE_TYPE (cst));
10929 :
10930 3053528 : do
10931 : {
10932 3053528 : if (idx > 0)
10933 12 : cst = vector_cst_elt (t, idx);
10934 3053528 : wide_int icst = wi::to_wide (cst);
10935 3053528 : wide_int inv = wi::bit_not (icst);
10936 3053528 : icst = wi::add (1, inv);
10937 3053528 : if (wi::popcount (icst) != 1)
10938 : return NULL_TREE;
10939 :
10940 8027 : tree newcst = wide_int_to_tree (ty, inv);
10941 :
10942 8027 : if (uniform)
10943 8011 : return build_uniform_cst (newtype, newcst);
10944 :
10945 16 : builder.quick_push (newcst);
10946 3053528 : }
10947 16 : while (++idx < nelts);
10948 :
10949 4 : return builder.build ();
10950 3053516 : }
10951 :
10952 : /* If VECTOR_CST T has a single nonzero element, return the index of that
10953 : element, otherwise return -1. */
10954 :
10955 : int
10956 180 : single_nonzero_element (const_tree t)
10957 : {
10958 180 : unsigned HOST_WIDE_INT nelts;
10959 180 : unsigned int repeat_nelts;
10960 180 : if (VECTOR_CST_NELTS (t).is_constant (&nelts))
10961 180 : repeat_nelts = nelts;
10962 : else if (VECTOR_CST_NELTS_PER_PATTERN (t) == 2)
10963 : {
10964 : nelts = vector_cst_encoded_nelts (t);
10965 : repeat_nelts = VECTOR_CST_NPATTERNS (t);
10966 : }
10967 : else
10968 : return -1;
10969 :
10970 180 : int res = -1;
10971 567 : for (unsigned int i = 0; i < nelts; ++i)
10972 : {
10973 531 : tree elt = vector_cst_elt (t, i);
10974 531 : if (!integer_zerop (elt) && !real_zerop (elt))
10975 : {
10976 324 : if (res >= 0 || i >= repeat_nelts)
10977 : return -1;
10978 180 : res = i;
10979 : }
10980 : }
10981 : return res;
10982 : }
10983 :
10984 : /* Build an empty statement at location LOC. */
10985 :
10986 : tree
10987 22235127 : build_empty_stmt (location_t loc)
10988 : {
10989 22235127 : tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
10990 22235127 : SET_EXPR_LOCATION (t, loc);
10991 22235127 : return t;
10992 : }
10993 :
10994 :
10995 : /* Build an OMP clause with code CODE. LOC is the location of the
10996 : clause. */
10997 :
10998 : tree
10999 1731527 : build_omp_clause (location_t loc, enum omp_clause_code code)
11000 : {
11001 1731527 : tree t;
11002 1731527 : int size, length;
11003 :
11004 1731527 : length = omp_clause_num_ops[code];
11005 1731527 : size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
11006 :
11007 1731527 : record_node_allocation_statistics (OMP_CLAUSE, size);
11008 :
11009 1731527 : t = (tree) ggc_internal_alloc (size);
11010 1731527 : memset (t, 0, size);
11011 1731527 : TREE_SET_CODE (t, OMP_CLAUSE);
11012 1731527 : OMP_CLAUSE_SET_CODE (t, code);
11013 1731527 : OMP_CLAUSE_LOCATION (t) = loc;
11014 :
11015 1731527 : return t;
11016 : }
11017 :
11018 : /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
11019 : includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
11020 : Except for the CODE and operand count field, other storage for the
11021 : object is initialized to zeros. */
11022 :
11023 : tree
11024 588101098 : build_vl_exp (enum tree_code code, int len MEM_STAT_DECL)
11025 : {
11026 588101098 : tree t;
11027 588101098 : int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
11028 :
11029 588101098 : gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
11030 588101098 : gcc_assert (len >= 1);
11031 :
11032 588101098 : record_node_allocation_statistics (code, length);
11033 :
11034 588101098 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
11035 :
11036 588101098 : TREE_SET_CODE (t, code);
11037 :
11038 : /* Can't use TREE_OPERAND to store the length because if checking is
11039 : enabled, it will try to check the length before we store it. :-P */
11040 588101098 : t->exp.operands[0] = build_int_cst (sizetype, len);
11041 :
11042 588101098 : return t;
11043 : }
11044 :
11045 : /* Helper function for build_call_* functions; build a CALL_EXPR with
11046 : indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
11047 : the argument slots. */
11048 :
11049 : static tree
11050 346536473 : build_call_1 (tree return_type, tree fn, int nargs)
11051 : {
11052 346536473 : tree t;
11053 :
11054 346536473 : t = build_vl_exp (CALL_EXPR, nargs + 3);
11055 346536473 : TREE_TYPE (t) = return_type;
11056 346536473 : CALL_EXPR_FN (t) = fn;
11057 346536473 : CALL_EXPR_STATIC_CHAIN (t) = NULL;
11058 :
11059 346536473 : return t;
11060 : }
11061 :
11062 : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11063 : FN and a null static chain slot. NARGS is the number of call arguments
11064 : which are specified as a va_list ARGS. */
11065 :
11066 : tree
11067 136084 : build_call_valist (tree return_type, tree fn, int nargs, va_list args)
11068 : {
11069 136084 : tree t;
11070 136084 : int i;
11071 :
11072 136084 : t = build_call_1 (return_type, fn, nargs);
11073 552122 : for (i = 0; i < nargs; i++)
11074 279954 : CALL_EXPR_ARG (t, i) = va_arg (args, tree);
11075 136084 : process_call_operands (t);
11076 136084 : return t;
11077 : }
11078 :
11079 : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11080 : FN and a null static chain slot. ARGS specifies the call arguments. */
11081 :
11082 : tree
11083 204 : build_call (tree return_type, tree fn, std::initializer_list<tree> args)
11084 : {
11085 204 : tree t;
11086 204 : int i;
11087 204 : int nargs = args.size();
11088 :
11089 204 : t = build_call_1 (return_type, fn, nargs);
11090 867 : for (i = 0; i < nargs; i++)
11091 459 : CALL_EXPR_ARG (t, i) = args.begin()[i];
11092 204 : process_call_operands (t);
11093 204 : return t;
11094 : }
11095 :
11096 : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11097 : FN and a null static chain slot. NARGS is the number of call arguments
11098 : which are specified as a tree array ARGS. */
11099 :
11100 : tree
11101 300580470 : build_call_array_loc (location_t loc, tree return_type, tree fn,
11102 : int nargs, const tree *args)
11103 : {
11104 300580470 : tree t;
11105 300580470 : int i;
11106 :
11107 300580470 : t = build_call_1 (return_type, fn, nargs);
11108 988727022 : for (i = 0; i < nargs; i++)
11109 387566082 : CALL_EXPR_ARG (t, i) = args[i];
11110 300580470 : process_call_operands (t);
11111 300580470 : SET_EXPR_LOCATION (t, loc);
11112 300580470 : return t;
11113 : }
11114 :
11115 : /* Like build_call_array, but takes a vec. */
11116 :
11117 : tree
11118 45095796 : build_call_vec (tree return_type, tree fn, const vec<tree, va_gc> *args)
11119 : {
11120 45095796 : tree ret, t;
11121 45095796 : unsigned int ix;
11122 :
11123 45095796 : ret = build_call_1 (return_type, fn, vec_safe_length (args));
11124 124278239 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
11125 34086647 : CALL_EXPR_ARG (ret, ix) = t;
11126 45095796 : process_call_operands (ret);
11127 45095796 : return ret;
11128 : }
11129 :
11130 : /* Conveniently construct a function call expression. FNDECL names the
11131 : function to be called and N arguments are passed in the array
11132 : ARGARRAY. */
11133 :
11134 : tree
11135 24555754 : build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray)
11136 : {
11137 24555754 : tree fntype = TREE_TYPE (fndecl);
11138 24555754 : tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
11139 :
11140 24555754 : return fold_build_call_array_loc (loc, TREE_TYPE (fntype), fn, n, argarray);
11141 : }
11142 :
11143 : /* Conveniently construct a function call expression. FNDECL names the
11144 : function to be called and the arguments are passed in the vector
11145 : VEC. */
11146 :
11147 : tree
11148 20603 : build_call_expr_loc_vec (location_t loc, tree fndecl, vec<tree, va_gc> *vec)
11149 : {
11150 20603 : return build_call_expr_loc_array (loc, fndecl, vec_safe_length (vec),
11151 20603 : vec_safe_address (vec));
11152 : }
11153 :
11154 :
11155 : /* Conveniently construct a function call expression. FNDECL names the
11156 : function to be called, N is the number of arguments, and the "..."
11157 : parameters are the argument expressions. */
11158 :
11159 : tree
11160 22284727 : build_call_expr_loc (location_t loc, tree fndecl, int n, ...)
11161 : {
11162 22284727 : va_list ap;
11163 22284727 : tree *argarray = XALLOCAVEC (tree, n);
11164 22284727 : int i;
11165 :
11166 22284727 : va_start (ap, n);
11167 24886986 : for (i = 0; i < n; i++)
11168 2602259 : argarray[i] = va_arg (ap, tree);
11169 22284727 : va_end (ap);
11170 22284727 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11171 : }
11172 :
11173 : /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
11174 : varargs macros aren't supported by all bootstrap compilers. */
11175 :
11176 : tree
11177 2245941 : build_call_expr (tree fndecl, int n, ...)
11178 : {
11179 2245941 : va_list ap;
11180 2245941 : tree *argarray = XALLOCAVEC (tree, n);
11181 2245941 : int i;
11182 :
11183 2245941 : va_start (ap, n);
11184 6663720 : for (i = 0; i < n; i++)
11185 4417779 : argarray[i] = va_arg (ap, tree);
11186 2245941 : va_end (ap);
11187 2245941 : return build_call_expr_loc_array (UNKNOWN_LOCATION, fndecl, n, argarray);
11188 : }
11189 :
11190 : /* Build an internal call to IFN, with arguments ARGS[0:N-1] and with return
11191 : type TYPE. This is just like CALL_EXPR, except its CALL_EXPR_FN is NULL.
11192 : It will get gimplified later into an ordinary internal function. */
11193 :
11194 : tree
11195 723919 : build_call_expr_internal_loc_array (location_t loc, internal_fn ifn,
11196 : tree type, int n, const tree *args)
11197 : {
11198 723919 : tree t = build_call_1 (type, NULL_TREE, n);
11199 2284656 : for (int i = 0; i < n; ++i)
11200 1560737 : CALL_EXPR_ARG (t, i) = args[i];
11201 723919 : SET_EXPR_LOCATION (t, loc);
11202 723919 : CALL_EXPR_IFN (t) = ifn;
11203 723919 : process_call_operands (t);
11204 723919 : return t;
11205 : }
11206 :
11207 : /* Build internal call expression. This is just like CALL_EXPR, except
11208 : its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
11209 : internal function. */
11210 :
11211 : tree
11212 722835 : build_call_expr_internal_loc (location_t loc, enum internal_fn ifn,
11213 : tree type, int n, ...)
11214 : {
11215 722835 : va_list ap;
11216 722835 : tree *argarray = XALLOCAVEC (tree, n);
11217 722835 : int i;
11218 :
11219 722835 : va_start (ap, n);
11220 2281408 : for (i = 0; i < n; i++)
11221 1558573 : argarray[i] = va_arg (ap, tree);
11222 722835 : va_end (ap);
11223 722835 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11224 : }
11225 :
11226 : /* Return a function call to FN, if the target is guaranteed to support it,
11227 : or null otherwise.
11228 :
11229 : N is the number of arguments, passed in the "...", and TYPE is the
11230 : type of the return value. */
11231 :
11232 : tree
11233 1881 : maybe_build_call_expr_loc (location_t loc, combined_fn fn, tree type,
11234 : int n, ...)
11235 : {
11236 1881 : va_list ap;
11237 1881 : tree *argarray = XALLOCAVEC (tree, n);
11238 1881 : int i;
11239 :
11240 1881 : va_start (ap, n);
11241 4911 : for (i = 0; i < n; i++)
11242 3030 : argarray[i] = va_arg (ap, tree);
11243 1881 : va_end (ap);
11244 1881 : if (internal_fn_p (fn))
11245 : {
11246 1080 : internal_fn ifn = as_internal_fn (fn);
11247 1080 : if (direct_internal_fn_p (ifn))
11248 : {
11249 1 : tree_pair types = direct_internal_fn_types (ifn, type, argarray);
11250 1 : if (!direct_internal_fn_supported_p (ifn, types,
11251 : OPTIMIZE_FOR_BOTH))
11252 1 : return NULL_TREE;
11253 : }
11254 1079 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11255 : }
11256 : else
11257 : {
11258 801 : tree fndecl = builtin_decl_implicit (as_builtin_fn (fn));
11259 801 : if (!fndecl)
11260 : return NULL_TREE;
11261 693 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11262 : }
11263 : }
11264 :
11265 : /* Return a function call to the appropriate builtin alloca variant.
11266 :
11267 : SIZE is the size to be allocated. ALIGN, if non-zero, is the requested
11268 : alignment of the allocated area. MAX_SIZE, if non-negative, is an upper
11269 : bound for SIZE in case it is not a fixed value. */
11270 :
11271 : tree
11272 8944 : build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size)
11273 : {
11274 8944 : if (max_size >= 0)
11275 : {
11276 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX);
11277 0 : return
11278 0 : build_call_expr (t, 3, size, size_int (align), size_int (max_size));
11279 : }
11280 8944 : else if (align > 0)
11281 : {
11282 8944 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
11283 8944 : return build_call_expr (t, 2, size, size_int (align));
11284 : }
11285 : else
11286 : {
11287 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA);
11288 0 : return build_call_expr (t, 1, size);
11289 : }
11290 : }
11291 :
11292 : /* The built-in decl to use to mark code points believed to be unreachable.
11293 : Typically __builtin_unreachable, but __builtin_trap if
11294 : -fsanitize=unreachable -fsanitize-trap=unreachable. If only
11295 : -fsanitize=unreachable, we rely on sanopt to replace calls with the
11296 : appropriate ubsan function. When building a call directly, use
11297 : {gimple_},build_builtin_unreachable instead. */
11298 :
11299 : tree
11300 277204 : builtin_decl_unreachable ()
11301 : {
11302 277204 : enum built_in_function fncode = BUILT_IN_UNREACHABLE;
11303 :
11304 554408 : if (sanitize_flags_p (SANITIZE_UNREACHABLE)
11305 277204 : ? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
11306 276608 : : flag_unreachable_traps)
11307 22 : fncode = BUILT_IN_UNREACHABLE_TRAP;
11308 : /* For non-trapping sanitize, we will rewrite __builtin_unreachable () later,
11309 : in the sanopt pass. */
11310 :
11311 277204 : return builtin_decl_explicit (fncode);
11312 : }
11313 :
11314 : /* Build a call to __builtin_unreachable, possibly rewritten by
11315 : -fsanitize=unreachable. Use this rather than the above when practical. */
11316 :
11317 : tree
11318 20939424 : build_builtin_unreachable (location_t loc)
11319 : {
11320 20939424 : tree data = NULL_TREE;
11321 20939424 : tree fn = sanitize_unreachable_fn (&data, loc);
11322 20939424 : return build_call_expr_loc (loc, fn, data != NULL_TREE, data);
11323 : }
11324 :
11325 : /* Create a new constant string literal of type ELTYPE[SIZE] (or LEN
11326 : if SIZE == -1) and return a tree node representing char* pointer to
11327 : it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). When STR is nonnull
11328 : the STRING_CST value is the LEN bytes at STR (the representation
11329 : of the string, which may be wide). Otherwise it's all zeros. */
11330 :
11331 : tree
11332 196865 : build_string_literal (unsigned len, const char *str /* = NULL */,
11333 : tree eltype /* = char_type_node */,
11334 : unsigned HOST_WIDE_INT size /* = -1 */)
11335 : {
11336 196865 : tree t = build_string (len, str);
11337 : /* Set the maximum valid index based on the string length or SIZE. */
11338 393730 : unsigned HOST_WIDE_INT maxidx
11339 196865 : = (size == HOST_WIDE_INT_M1U ? len : size) - 1;
11340 :
11341 196865 : tree index = build_index_type (size_int (maxidx));
11342 196865 : eltype = build_type_variant (eltype, 1, 0);
11343 196865 : tree type = build_array_type (eltype, index);
11344 196865 : TREE_TYPE (t) = type;
11345 196865 : TREE_CONSTANT (t) = 1;
11346 196865 : TREE_READONLY (t) = 1;
11347 196865 : TREE_STATIC (t) = 1;
11348 :
11349 196865 : type = build_pointer_type (eltype);
11350 196865 : t = build1 (ADDR_EXPR, type,
11351 : build4 (ARRAY_REF, eltype,
11352 : t, integer_zero_node, NULL_TREE, NULL_TREE));
11353 196865 : return t;
11354 : }
11355 :
11356 :
11357 :
11358 : /* Return true if T (assumed to be a DECL) must be assigned a memory
11359 : location. */
11360 :
11361 : bool
11362 1968089084 : needs_to_live_in_memory (const_tree t)
11363 : {
11364 1968089084 : return (TREE_ADDRESSABLE (t)
11365 1592246510 : || is_global_var (t)
11366 3123077665 : || (TREE_CODE (t) == RESULT_DECL
11367 8127249 : && !DECL_BY_REFERENCE (t)
11368 5725463 : && aggregate_value_p (t, current_function_decl)));
11369 : }
11370 :
11371 : /* Return value of a constant X and sign-extend it. */
11372 :
11373 : HOST_WIDE_INT
11374 944656898 : int_cst_value (const_tree x)
11375 : {
11376 944656898 : unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
11377 944656898 : unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
11378 :
11379 : /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
11380 944656898 : gcc_assert (cst_and_fits_in_hwi (x));
11381 :
11382 944656898 : if (bits < HOST_BITS_PER_WIDE_INT)
11383 : {
11384 930045739 : bool negative = ((val >> (bits - 1)) & 1) != 0;
11385 930045739 : if (negative)
11386 218290 : val |= HOST_WIDE_INT_M1U << (bits - 1) << 1;
11387 : else
11388 929827449 : val &= ~(HOST_WIDE_INT_M1U << (bits - 1) << 1);
11389 : }
11390 :
11391 944656898 : return val;
11392 : }
11393 :
11394 : /* If TYPE is an integral or pointer type, return an integer type with
11395 : the same precision which is unsigned iff UNSIGNEDP is true, or itself
11396 : if TYPE is already an integer type of signedness UNSIGNEDP.
11397 : If TYPE is a floating-point type, return an integer type with the same
11398 : bitsize and with the signedness given by UNSIGNEDP; this is useful
11399 : when doing bit-level operations on a floating-point value. */
11400 :
11401 : tree
11402 87426531 : signed_or_unsigned_type_for (int unsignedp, tree type)
11403 : {
11404 87426531 : if (ANY_INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) == unsignedp)
11405 : return type;
11406 :
11407 56251518 : if (TREE_CODE (type) == VECTOR_TYPE)
11408 : {
11409 27781 : tree inner = TREE_TYPE (type);
11410 27781 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11411 27781 : if (!inner2)
11412 : return NULL_TREE;
11413 27781 : if (inner == inner2)
11414 : return type;
11415 27781 : machine_mode new_mode;
11416 55562 : if (VECTOR_MODE_P (TYPE_MODE (type))
11417 55493 : && related_int_vector_mode (TYPE_MODE (type)).exists (&new_mode))
11418 27712 : return build_vector_type_for_mode (inner2, new_mode);
11419 69 : return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
11420 : }
11421 :
11422 : if (TREE_CODE (type) == COMPLEX_TYPE)
11423 : {
11424 24 : tree inner = TREE_TYPE (type);
11425 24 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11426 24 : if (!inner2)
11427 : return NULL_TREE;
11428 24 : if (inner == inner2)
11429 : return type;
11430 24 : return build_complex_type (inner2);
11431 : }
11432 :
11433 : unsigned int bits;
11434 : if (INTEGRAL_TYPE_P (type)
11435 : || POINTER_TYPE_P (type)
11436 : || TREE_CODE (type) == OFFSET_TYPE)
11437 56223619 : bits = TYPE_PRECISION (type);
11438 : else if (TREE_CODE (type) == REAL_TYPE)
11439 188 : bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (type));
11440 : else
11441 : return NULL_TREE;
11442 :
11443 56223713 : if (TREE_CODE (type) == BITINT_TYPE && (unsignedp || bits > 1))
11444 1689 : return build_bitint_type (bits, unsignedp);
11445 56222024 : return build_nonstandard_integer_type (bits, unsignedp);
11446 : }
11447 :
11448 : /* If TYPE is an integral or pointer type, return an integer type with
11449 : the same precision which is unsigned, or itself if TYPE is already an
11450 : unsigned integer type. If TYPE is a floating-point type, return an
11451 : unsigned integer type with the same bitsize as TYPE. */
11452 :
11453 : tree
11454 77929181 : unsigned_type_for (tree type)
11455 : {
11456 77929181 : return signed_or_unsigned_type_for (1, type);
11457 : }
11458 :
11459 : /* If TYPE is an integral or pointer type, return an integer type with
11460 : the same precision which is signed, or itself if TYPE is already a
11461 : signed integer type. If TYPE is a floating-point type, return a
11462 : signed integer type with the same bitsize as TYPE. */
11463 :
11464 : tree
11465 9464207 : signed_type_for (tree type)
11466 : {
11467 9464207 : return signed_or_unsigned_type_for (0, type);
11468 : }
11469 :
11470 : /* - For VECTOR_TYPEs:
11471 : - The truth type must be a VECTOR_BOOLEAN_TYPE.
11472 : - The number of elements must match (known_eq).
11473 : - targetm.vectorize.get_mask_mode exists, and exactly
11474 : the same mode as the truth type.
11475 : - Otherwise, the truth type must be a BOOLEAN_TYPE
11476 : or useless_type_conversion_p to BOOLEAN_TYPE. */
11477 : bool
11478 1460 : is_truth_type_for (tree type, tree truth_type)
11479 : {
11480 1460 : machine_mode mask_mode = TYPE_MODE (truth_type);
11481 1460 : machine_mode vmode = TYPE_MODE (type);
11482 1460 : machine_mode tmask_mode;
11483 :
11484 1460 : if (TREE_CODE (type) == VECTOR_TYPE)
11485 : {
11486 1460 : if (VECTOR_BOOLEAN_TYPE_P (truth_type)
11487 1460 : && known_eq (TYPE_VECTOR_SUBPARTS (type),
11488 : TYPE_VECTOR_SUBPARTS (truth_type))
11489 1460 : && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode)
11490 2920 : && tmask_mode == mask_mode)
11491 1441 : return true;
11492 :
11493 19 : return false;
11494 : }
11495 :
11496 0 : return useless_type_conversion_p (boolean_type_node, truth_type);
11497 : }
11498 :
11499 : /* If TYPE is a vector type, return a signed integer vector type with the
11500 : same width and number of subparts. Otherwise return boolean_type_node. */
11501 :
11502 : tree
11503 4260490 : truth_type_for (tree type)
11504 : {
11505 4260490 : if (TREE_CODE (type) == VECTOR_TYPE)
11506 : {
11507 2518378 : if (VECTOR_BOOLEAN_TYPE_P (type))
11508 : return type;
11509 2451835 : return build_truth_vector_type_for (type);
11510 : }
11511 : else
11512 1742112 : return boolean_type_node;
11513 : }
11514 :
11515 : /* Returns the largest value obtainable by casting something in INNER type to
11516 : OUTER type. */
11517 :
11518 : tree
11519 10979217 : upper_bound_in_type (tree outer, tree inner)
11520 : {
11521 10979217 : unsigned int det = 0;
11522 10979217 : unsigned oprec = TYPE_PRECISION (outer);
11523 10979217 : unsigned iprec = TYPE_PRECISION (inner);
11524 10979217 : unsigned prec;
11525 :
11526 : /* Compute a unique number for every combination. */
11527 10979217 : det |= (oprec > iprec) ? 4 : 0;
11528 10979217 : det |= TYPE_UNSIGNED (outer) ? 2 : 0;
11529 10979217 : det |= TYPE_UNSIGNED (inner) ? 1 : 0;
11530 :
11531 : /* Determine the exponent to use. */
11532 10979217 : switch (det)
11533 : {
11534 7235290 : case 0:
11535 7235290 : case 1:
11536 : /* oprec <= iprec, outer: signed, inner: don't care. */
11537 7235290 : prec = oprec - 1;
11538 7235290 : break;
11539 : case 2:
11540 : case 3:
11541 : /* oprec <= iprec, outer: unsigned, inner: don't care. */
11542 : prec = oprec;
11543 : break;
11544 21561 : case 4:
11545 : /* oprec > iprec, outer: signed, inner: signed. */
11546 21561 : prec = iprec - 1;
11547 21561 : break;
11548 : case 5:
11549 : /* oprec > iprec, outer: signed, inner: unsigned. */
11550 17579 : prec = iprec;
11551 : break;
11552 : case 6:
11553 : /* oprec > iprec, outer: unsigned, inner: signed. */
11554 : prec = oprec;
11555 : break;
11556 : case 7:
11557 : /* oprec > iprec, outer: unsigned, inner: unsigned. */
11558 17579 : prec = iprec;
11559 : break;
11560 : default:
11561 : gcc_unreachable ();
11562 : }
11563 :
11564 10979217 : return wide_int_to_tree (outer,
11565 10979217 : wi::mask (prec, false, TYPE_PRECISION (outer)));
11566 : }
11567 :
11568 : /* Returns the smallest value obtainable by casting something in INNER type to
11569 : OUTER type. */
11570 :
11571 : tree
11572 8379126 : lower_bound_in_type (tree outer, tree inner)
11573 : {
11574 8379126 : unsigned oprec = TYPE_PRECISION (outer);
11575 8379126 : unsigned iprec = TYPE_PRECISION (inner);
11576 :
11577 : /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
11578 : and obtain 0. */
11579 8379126 : if (TYPE_UNSIGNED (outer)
11580 : /* If we are widening something of an unsigned type, OUTER type
11581 : contains all values of INNER type. In particular, both INNER
11582 : and OUTER types have zero in common. */
11583 8379126 : || (oprec > iprec && TYPE_UNSIGNED (inner)))
11584 2283437 : return build_int_cst (outer, 0);
11585 : else
11586 : {
11587 : /* If we are widening a signed type to another signed type, we
11588 : want to obtain -2^^(iprec-1). If we are keeping the
11589 : precision or narrowing to a signed type, we want to obtain
11590 : -2^(oprec-1). */
11591 6095689 : unsigned prec = oprec > iprec ? iprec : oprec;
11592 6095689 : return wide_int_to_tree (outer,
11593 12191378 : wi::mask (prec - 1, true,
11594 6095689 : TYPE_PRECISION (outer)));
11595 : }
11596 : }
11597 :
11598 : /* Return true if two operands that are suitable for PHI nodes are
11599 : necessarily equal. Specifically, both ARG0 and ARG1 must be either
11600 : SSA_NAME or invariant. Note that this is strictly an optimization.
11601 : That is, callers of this function can directly call operand_equal_p
11602 : and get the same result, only slower. */
11603 :
11604 : bool
11605 21348777 : operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
11606 : {
11607 21348777 : if (arg0 == arg1)
11608 : return true;
11609 19603645 : if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
11610 : return false;
11611 3870441 : return operand_equal_p (arg0, arg1, 0);
11612 : }
11613 :
11614 : /* Returns number of zeros at the end of binary representation of X. */
11615 :
11616 : tree
11617 8971881 : num_ending_zeros (const_tree x)
11618 : {
11619 8971881 : return build_int_cst (TREE_TYPE (x), wi::ctz (wi::to_wide (x)));
11620 : }
11621 :
11622 :
11623 : #define WALK_SUBTREE(NODE) \
11624 : do \
11625 : { \
11626 : result = walk_tree_1 (&(NODE), func, data, pset, lh); \
11627 : if (result) \
11628 : return result; \
11629 : } \
11630 : while (0)
11631 :
11632 : /* This is a subroutine of walk_tree that walks field of TYPE that are to
11633 : be walked whenever a type is seen in the tree. Rest of operands and return
11634 : value are as for walk_tree. */
11635 :
11636 : static tree
11637 4797683677 : walk_type_fields (tree type, walk_tree_fn func, void *data,
11638 : hash_set<tree> *pset, walk_tree_lh lh)
11639 : {
11640 4797683677 : tree result = NULL_TREE;
11641 :
11642 4797683677 : switch (TREE_CODE (type))
11643 : {
11644 1456300428 : case POINTER_TYPE:
11645 1456300428 : case REFERENCE_TYPE:
11646 1456300428 : case VECTOR_TYPE:
11647 : /* We have to worry about mutually recursive pointers. These can't
11648 : be written in C. They can in Ada. It's pathological, but
11649 : there's an ACATS test (c38102a) that checks it. Deal with this
11650 : by checking if we're pointing to another pointer, that one
11651 : points to another pointer, that one does too, and we have no htab.
11652 : If so, get a hash table. We check three levels deep to avoid
11653 : the cost of the hash table if we don't need one. */
11654 2868138451 : if (POINTER_TYPE_P (TREE_TYPE (type))
11655 44462472 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
11656 4903393 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
11657 1461122924 : && !pset)
11658 : {
11659 0 : result = walk_tree_without_duplicates (&TREE_TYPE (type),
11660 : func, data);
11661 0 : if (result)
11662 : return result;
11663 :
11664 : break;
11665 : }
11666 :
11667 : /* fall through */
11668 :
11669 1459009564 : case COMPLEX_TYPE:
11670 1459009564 : WALK_SUBTREE (TREE_TYPE (type));
11671 : break;
11672 :
11673 273649720 : case METHOD_TYPE:
11674 273649720 : WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
11675 :
11676 : /* Fall through. */
11677 :
11678 441518074 : case FUNCTION_TYPE:
11679 441518074 : WALK_SUBTREE (TREE_TYPE (type));
11680 441518008 : {
11681 441518008 : tree arg;
11682 :
11683 : /* We never want to walk into default arguments. */
11684 1680015042 : for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
11685 1238526150 : WALK_SUBTREE (TREE_VALUE (arg));
11686 : }
11687 : break;
11688 :
11689 19368011 : case ARRAY_TYPE:
11690 : /* Don't follow this nodes's type if a pointer for fear that
11691 : we'll have infinite recursion. If we have a PSET, then we
11692 : need not fear. */
11693 19368011 : if (pset
11694 19368011 : || (!POINTER_TYPE_P (TREE_TYPE (type))
11695 138224 : && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
11696 19347988 : WALK_SUBTREE (TREE_TYPE (type));
11697 19365271 : WALK_SUBTREE (TYPE_DOMAIN (type));
11698 : break;
11699 :
11700 923934 : case OFFSET_TYPE:
11701 923934 : WALK_SUBTREE (TREE_TYPE (type));
11702 923079 : WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
11703 : break;
11704 :
11705 : default:
11706 : break;
11707 : }
11708 :
11709 : return NULL_TREE;
11710 : }
11711 :
11712 : /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11713 : called with the DATA and the address of each sub-tree. If FUNC returns a
11714 : non-NULL value, the traversal is stopped, and the value returned by FUNC
11715 : is returned. If PSET is non-NULL it is used to record the nodes visited,
11716 : and to avoid visiting a node more than once. */
11717 :
11718 : tree
11719 >10686*10^7 : walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
11720 : hash_set<tree> *pset, walk_tree_lh lh)
11721 : {
11722 : #define WALK_SUBTREE_TAIL(NODE) \
11723 : do \
11724 : { \
11725 : tp = & (NODE); \
11726 : goto tail_recurse; \
11727 : } \
11728 : while (0)
11729 :
11730 >13306*10^7 : tail_recurse:
11731 : /* Skip empty subtrees. */
11732 >13306*10^7 : if (!*tp)
11733 : return NULL_TREE;
11734 :
11735 : /* Don't walk the same tree twice, if the user has requested
11736 : that we avoid doing so. */
11737 >11006*10^7 : if (pset && pset->add (*tp))
11738 : return NULL_TREE;
11739 :
11740 : /* Call the function. */
11741 >10844*10^7 : int walk_subtrees = 1;
11742 >10844*10^7 : tree result = (*func) (tp, &walk_subtrees, data);
11743 :
11744 : /* If we found something, return it. */
11745 >10844*10^7 : if (result)
11746 : return result;
11747 :
11748 >10836*10^7 : tree t = *tp;
11749 >10836*10^7 : tree_code code = TREE_CODE (t);
11750 :
11751 : /* Even if we didn't, FUNC may have decided that there was nothing
11752 : interesting below this point in the tree. */
11753 >10836*10^7 : if (!walk_subtrees)
11754 : {
11755 : /* But we still need to check our siblings. */
11756 65990712926 : if (code == TREE_LIST)
11757 120606 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11758 65990592320 : else if (code == OMP_CLAUSE)
11759 881551 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11760 : else
11761 : return NULL_TREE;
11762 : }
11763 :
11764 42379234926 : if (lh)
11765 : {
11766 25239124722 : result = (*lh) (tp, &walk_subtrees, func, data, pset);
11767 25239124722 : if (result || !walk_subtrees)
11768 2554055183 : return result;
11769 : }
11770 :
11771 39825179743 : switch (code)
11772 : {
11773 : case ERROR_MARK:
11774 : case IDENTIFIER_NODE:
11775 : case INTEGER_CST:
11776 : case REAL_CST:
11777 : case FIXED_CST:
11778 : case STRING_CST:
11779 : case BLOCK:
11780 : case PLACEHOLDER_EXPR:
11781 : case SSA_NAME:
11782 : case FIELD_DECL:
11783 : case RESULT_DECL:
11784 : /* None of these have subtrees other than those already walked
11785 : above. */
11786 : break;
11787 :
11788 291248064 : case TREE_LIST:
11789 291248064 : WALK_SUBTREE (TREE_VALUE (t));
11790 290806660 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11791 :
11792 999864754 : case TREE_VEC:
11793 999864754 : {
11794 999864754 : int len = TREE_VEC_LENGTH (t);
11795 :
11796 999864754 : if (len == 0)
11797 : break;
11798 :
11799 : /* Walk all elements but the last. */
11800 1882978465 : for (int i = 0; i < len - 1; ++i)
11801 892135924 : WALK_SUBTREE (TREE_VEC_ELT (t, i));
11802 :
11803 : /* Now walk the last one as a tail call. */
11804 990842541 : WALK_SUBTREE_TAIL (TREE_VEC_ELT (t, len - 1));
11805 : }
11806 :
11807 4844773 : case VECTOR_CST:
11808 4844773 : {
11809 4844773 : unsigned len = vector_cst_encoded_nelts (t);
11810 4844773 : if (len == 0)
11811 : break;
11812 : /* Walk all elements but the last. */
11813 16872391 : for (unsigned i = 0; i < len - 1; ++i)
11814 12027762 : WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (t, i));
11815 : /* Now walk the last one as a tail call. */
11816 4844629 : WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (t, len - 1));
11817 : }
11818 :
11819 628746 : case COMPLEX_CST:
11820 628746 : WALK_SUBTREE (TREE_REALPART (t));
11821 627180 : WALK_SUBTREE_TAIL (TREE_IMAGPART (t));
11822 :
11823 : case CONSTRUCTOR:
11824 : {
11825 : unsigned HOST_WIDE_INT idx;
11826 : constructor_elt *ce;
11827 :
11828 1009862576 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce);
11829 : idx++)
11830 548741948 : WALK_SUBTREE (ce->value);
11831 : }
11832 : break;
11833 :
11834 5042196 : case SAVE_EXPR:
11835 5042196 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, 0));
11836 :
11837 310779003 : case BIND_EXPR:
11838 310779003 : {
11839 310779003 : tree decl;
11840 519983366 : for (decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
11841 : {
11842 : /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11843 : into declarations that are just mentioned, rather than
11844 : declared; they don't really belong to this part of the tree.
11845 : And, we can see cycles: the initializer for a declaration
11846 : can refer to the declaration itself. */
11847 209204387 : WALK_SUBTREE (DECL_INITIAL (decl));
11848 209204363 : WALK_SUBTREE (DECL_SIZE (decl));
11849 209204363 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
11850 : }
11851 310778979 : WALK_SUBTREE_TAIL (BIND_EXPR_BODY (t));
11852 : }
11853 :
11854 395788822 : case STATEMENT_LIST:
11855 395788822 : {
11856 395788822 : tree_stmt_iterator i;
11857 1457952673 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
11858 1062372386 : WALK_SUBTREE (*tsi_stmt_ptr (i));
11859 : }
11860 395580287 : break;
11861 :
11862 1821075 : case OMP_CLAUSE:
11863 1821075 : {
11864 1821075 : int len = omp_clause_num_ops[OMP_CLAUSE_CODE (t)];
11865 : /* Do not walk the iterator operand of OpenMP MAP clauses. */
11866 1821075 : if (OMP_CLAUSE_HAS_ITERATORS (t))
11867 925 : len--;
11868 5176598 : for (int i = 0; i < len; i++)
11869 3355523 : WALK_SUBTREE (OMP_CLAUSE_OPERAND (t, i));
11870 1821075 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11871 : }
11872 :
11873 105206053 : case TARGET_EXPR:
11874 105206053 : {
11875 105206053 : int i, len;
11876 :
11877 : /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11878 : But, we only want to walk once. */
11879 105206053 : len = (TREE_OPERAND (t, 3) == TREE_OPERAND (t, 1)) ? 2 : 3;
11880 420791506 : for (i = 0; i < len; ++i)
11881 315600478 : WALK_SUBTREE (TREE_OPERAND (t, i));
11882 105191028 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len));
11883 : }
11884 :
11885 197723481 : case DECL_EXPR:
11886 : /* If this is a TYPE_DECL, walk into the fields of the type that it's
11887 : defining. We only want to walk into these fields of a type in this
11888 : case and not in the general case of a mere reference to the type.
11889 :
11890 : The criterion is as follows: if the field can be an expression, it
11891 : must be walked only here. This should be in keeping with the fields
11892 : that are directly gimplified in gimplify_type_sizes in order for the
11893 : mark/copy-if-shared/unmark machinery of the gimplifier to work with
11894 : variable-sized types.
11895 :
11896 : Note that DECLs get walked as part of processing the BIND_EXPR. */
11897 197723481 : if (TREE_CODE (DECL_EXPR_DECL (t)) == TYPE_DECL)
11898 : {
11899 : /* Call the function for the decl so e.g. copy_tree_body_r can
11900 : replace it with the remapped one. */
11901 1515867 : result = (*func) (&DECL_EXPR_DECL (t), &walk_subtrees, data);
11902 1515867 : if (result || !walk_subtrees)
11903 44497 : return result;
11904 :
11905 1471370 : tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (t));
11906 1471370 : if (TREE_CODE (*type_p) == ERROR_MARK)
11907 : return NULL_TREE;
11908 :
11909 : /* Call the function for the type. See if it returns anything or
11910 : doesn't want us to continue. If we are to continue, walk both
11911 : the normal fields and those for the declaration case. */
11912 1471370 : result = (*func) (type_p, &walk_subtrees, data);
11913 1471370 : if (result || !walk_subtrees)
11914 84364 : return result;
11915 :
11916 1387006 : tree type = *type_p;
11917 :
11918 : /* But do not walk a pointed-to type since it may itself need to
11919 : be walked in the declaration case if it isn't anonymous. */
11920 1387006 : if (!POINTER_TYPE_P (type))
11921 : {
11922 1371312 : result = walk_type_fields (type, func, data, pset, lh);
11923 1371312 : if (result)
11924 : return result;
11925 : }
11926 :
11927 : /* If this is a record type, also walk the fields. */
11928 1387006 : if (RECORD_OR_UNION_TYPE_P (type))
11929 : {
11930 396710 : tree field;
11931 :
11932 1832838 : for (field = TYPE_FIELDS (type); field;
11933 1436128 : field = DECL_CHAIN (field))
11934 : {
11935 : /* We'd like to look at the type of the field, but we can
11936 : easily get infinite recursion. So assume it's pointed
11937 : to elsewhere in the tree. Also, ignore things that
11938 : aren't fields. */
11939 1436128 : if (TREE_CODE (field) != FIELD_DECL)
11940 1105930 : continue;
11941 :
11942 330198 : WALK_SUBTREE (DECL_FIELD_OFFSET (field));
11943 330198 : WALK_SUBTREE (DECL_SIZE (field));
11944 330198 : WALK_SUBTREE (DECL_SIZE_UNIT (field));
11945 330198 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
11946 0 : WALK_SUBTREE (DECL_QUALIFIER (field));
11947 : }
11948 : }
11949 :
11950 : /* Same for scalar types. */
11951 990296 : else if (TREE_CODE (type) == BOOLEAN_TYPE
11952 : || TREE_CODE (type) == ENUMERAL_TYPE
11953 990296 : || TREE_CODE (type) == INTEGER_TYPE
11954 990258 : || TREE_CODE (type) == FIXED_POINT_TYPE
11955 990258 : || TREE_CODE (type) == REAL_TYPE)
11956 : {
11957 38 : WALK_SUBTREE (TYPE_MIN_VALUE (type));
11958 38 : WALK_SUBTREE (TYPE_MAX_VALUE (type));
11959 : }
11960 :
11961 1387006 : WALK_SUBTREE (TYPE_SIZE (type));
11962 1387006 : WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (type));
11963 : }
11964 : /* FALLTHRU */
11965 :
11966 32719167028 : default:
11967 32719167028 : if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
11968 : {
11969 24737967351 : int i, len;
11970 :
11971 : /* Walk over all the sub-trees of this operand. */
11972 24737967351 : len = TREE_OPERAND_LENGTH (t);
11973 :
11974 : /* Go through the subtrees. We need to do this in forward order so
11975 : that the scope of a FOR_EXPR is handled properly. */
11976 24737967351 : if (len)
11977 : {
11978 49080045377 : for (i = 0; i < len - 1; ++i)
11979 24598711865 : WALK_SUBTREE (TREE_OPERAND (t, i));
11980 24481333512 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len - 1));
11981 : }
11982 : }
11983 : /* If this is a type, walk the needed fields in the type. */
11984 7981199677 : else if (TYPE_P (t))
11985 4796312365 : return walk_type_fields (t, func, data, pset, lh);
11986 : break;
11987 : }
11988 :
11989 : /* We didn't find what we were looking for. */
11990 : return NULL_TREE;
11991 :
11992 : #undef WALK_SUBTREE_TAIL
11993 : }
11994 : #undef WALK_SUBTREE
11995 :
11996 : /* Like walk_tree, but does not walk duplicate nodes more than once. */
11997 :
11998 : tree
11999 3781498133 : walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
12000 : walk_tree_lh lh)
12001 : {
12002 3781498133 : tree result;
12003 :
12004 3781498133 : hash_set<tree> pset;
12005 3781498133 : result = walk_tree_1 (tp, func, data, &pset, lh);
12006 3781498133 : return result;
12007 3781498133 : }
12008 :
12009 :
12010 : tree
12011 1229195800 : tree_block (tree t)
12012 : {
12013 1229195800 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
12014 :
12015 1229195800 : if (IS_EXPR_CODE_CLASS (c))
12016 1229195800 : return LOCATION_BLOCK (t->exp.locus);
12017 0 : gcc_unreachable ();
12018 : return NULL;
12019 : }
12020 :
12021 : void
12022 814484045 : tree_set_block (tree t, tree b)
12023 : {
12024 814484045 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
12025 :
12026 814484045 : if (IS_EXPR_CODE_CLASS (c))
12027 : {
12028 814484045 : t->exp.locus = set_block (t->exp.locus, b);
12029 : }
12030 : else
12031 0 : gcc_unreachable ();
12032 814484045 : }
12033 :
12034 : /* Create a nameless artificial label and put it in the current
12035 : function context. The label has a location of LOC. Returns the
12036 : newly created label. */
12037 :
12038 : tree
12039 37488493 : create_artificial_label (location_t loc)
12040 : {
12041 37488493 : tree lab = build_decl (loc,
12042 : LABEL_DECL, NULL_TREE, void_type_node);
12043 :
12044 37488493 : DECL_ARTIFICIAL (lab) = 1;
12045 37488493 : DECL_IGNORED_P (lab) = 1;
12046 37488493 : DECL_CONTEXT (lab) = current_function_decl;
12047 37488493 : return lab;
12048 : }
12049 :
12050 : /* Given a tree, try to return a useful variable name that we can use
12051 : to prefix a temporary that is being assigned the value of the tree.
12052 : I.E. given <temp> = &A, return A. */
12053 :
12054 : const char *
12055 24913593 : get_name (tree t)
12056 : {
12057 26762776 : tree stripped_decl;
12058 :
12059 26762776 : stripped_decl = t;
12060 26762776 : STRIP_NOPS (stripped_decl);
12061 26762776 : if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
12062 4061631 : return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
12063 22701145 : else if (TREE_CODE (stripped_decl) == SSA_NAME)
12064 : {
12065 1359253 : tree name = SSA_NAME_IDENTIFIER (stripped_decl);
12066 326075 : if (!name)
12067 : return NULL;
12068 324829 : return IDENTIFIER_POINTER (name);
12069 : }
12070 : else
12071 : {
12072 21341892 : switch (TREE_CODE (stripped_decl))
12073 : {
12074 1849183 : case ADDR_EXPR:
12075 1849183 : return get_name (TREE_OPERAND (stripped_decl, 0));
12076 : default:
12077 : return NULL;
12078 : }
12079 : }
12080 : }
12081 :
12082 : /* Return true if TYPE has a variable argument list. */
12083 :
12084 : bool
12085 233592912 : stdarg_p (const_tree fntype)
12086 : {
12087 233592912 : function_args_iterator args_iter;
12088 233592912 : tree n = NULL_TREE, t;
12089 :
12090 233592912 : if (!fntype)
12091 : return false;
12092 :
12093 233462356 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12094 : return true;
12095 :
12096 944816673 : FOREACH_FUNCTION_ARGS (fntype, t, args_iter)
12097 : {
12098 712005286 : n = t;
12099 : }
12100 :
12101 232811387 : return n != NULL_TREE && n != void_type_node;
12102 : }
12103 :
12104 : /* Return true if TYPE has a prototype. */
12105 :
12106 : bool
12107 698201817 : prototype_p (const_tree fntype)
12108 : {
12109 698201817 : tree t;
12110 :
12111 698201817 : gcc_assert (fntype != NULL_TREE);
12112 :
12113 698201817 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12114 : return true;
12115 :
12116 697464937 : t = TYPE_ARG_TYPES (fntype);
12117 697464937 : return (t != NULL_TREE);
12118 : }
12119 :
12120 : /* If BLOCK is inlined from an __attribute__((__artificial__))
12121 : routine, return pointer to location from where it has been
12122 : called. */
12123 : location_t *
12124 173142 : block_nonartificial_location (tree block)
12125 : {
12126 173142 : location_t *ret = NULL;
12127 :
12128 443353 : while (block && TREE_CODE (block) == BLOCK
12129 534926 : && BLOCK_ABSTRACT_ORIGIN (block))
12130 : {
12131 165826 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12132 165826 : if (TREE_CODE (ao) == FUNCTION_DECL)
12133 : {
12134 : /* If AO is an artificial inline, point RET to the
12135 : call site locus at which it has been inlined and continue
12136 : the loop, in case AO's caller is also an artificial
12137 : inline. */
12138 70518 : if (DECL_DECLARED_INLINE_P (ao)
12139 70518 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
12140 1813 : ret = &BLOCK_SOURCE_LOCATION (block);
12141 : else
12142 : break;
12143 : }
12144 95308 : else if (TREE_CODE (ao) != BLOCK)
12145 : break;
12146 :
12147 97121 : block = BLOCK_SUPERCONTEXT (block);
12148 : }
12149 173142 : return ret;
12150 : }
12151 :
12152 :
12153 : /* If EXP is inlined from an __attribute__((__artificial__))
12154 : function, return the location of the original call expression. */
12155 :
12156 : location_t
12157 52 : tree_nonartificial_location (tree exp)
12158 : {
12159 52 : location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
12160 :
12161 52 : if (loc)
12162 0 : return *loc;
12163 : else
12164 52 : return EXPR_LOCATION (exp);
12165 : }
12166 :
12167 : /* Return the location into which EXP has been inlined. Analogous
12168 : to tree_nonartificial_location() above but not limited to artificial
12169 : functions declared inline. If SYSTEM_HEADER is true, return
12170 : the macro expansion point of the location if it's in a system header */
12171 :
12172 : location_t
12173 0 : tree_inlined_location (tree exp, bool system_header /* = true */)
12174 : {
12175 0 : location_t loc = UNKNOWN_LOCATION;
12176 :
12177 0 : tree block = TREE_BLOCK (exp);
12178 :
12179 0 : while (block && TREE_CODE (block) == BLOCK
12180 0 : && BLOCK_ABSTRACT_ORIGIN (block))
12181 : {
12182 0 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12183 0 : if (TREE_CODE (ao) == FUNCTION_DECL)
12184 0 : loc = BLOCK_SOURCE_LOCATION (block);
12185 0 : else if (TREE_CODE (ao) != BLOCK)
12186 : break;
12187 :
12188 0 : block = BLOCK_SUPERCONTEXT (block);
12189 : }
12190 :
12191 0 : if (loc == UNKNOWN_LOCATION)
12192 : {
12193 0 : loc = EXPR_LOCATION (exp);
12194 0 : if (system_header)
12195 : /* Only consider macro expansion when the block traversal failed
12196 : to find a location. Otherwise it's not relevant. */
12197 0 : return expansion_point_location_if_in_system_header (loc);
12198 : }
12199 :
12200 : return loc;
12201 : }
12202 :
12203 : /* These are the hash table functions for the hash table of OPTIMIZATION_NODE
12204 : nodes. */
12205 :
12206 : /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
12207 :
12208 : hashval_t
12209 868057360 : cl_option_hasher::hash (tree x)
12210 : {
12211 868057360 : const_tree const t = x;
12212 :
12213 868057360 : if (TREE_CODE (t) == OPTIMIZATION_NODE)
12214 102673277 : return cl_optimization_hash (TREE_OPTIMIZATION (t));
12215 765384083 : else if (TREE_CODE (t) == TARGET_OPTION_NODE)
12216 765384083 : return cl_target_option_hash (TREE_TARGET_OPTION (t));
12217 : else
12218 0 : gcc_unreachable ();
12219 : }
12220 :
12221 : /* Return nonzero if the value represented by *X (an OPTIMIZATION or
12222 : TARGET_OPTION tree node) is the same as that given by *Y, which is the
12223 : same. */
12224 :
12225 : bool
12226 938832310 : cl_option_hasher::equal (tree x, tree y)
12227 : {
12228 938832310 : const_tree const xt = x;
12229 938832310 : const_tree const yt = y;
12230 :
12231 938832310 : if (TREE_CODE (xt) != TREE_CODE (yt))
12232 : return false;
12233 :
12234 532984056 : if (TREE_CODE (xt) == OPTIMIZATION_NODE)
12235 96859804 : return cl_optimization_option_eq (TREE_OPTIMIZATION (xt),
12236 96859804 : TREE_OPTIMIZATION (yt));
12237 436124252 : else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
12238 436124252 : return cl_target_option_eq (TREE_TARGET_OPTION (xt),
12239 436124252 : TREE_TARGET_OPTION (yt));
12240 : else
12241 0 : gcc_unreachable ();
12242 : }
12243 :
12244 : /* Build an OPTIMIZATION_NODE based on the options in OPTS and OPTS_SET. */
12245 :
12246 : tree
12247 97142719 : build_optimization_node (struct gcc_options *opts,
12248 : struct gcc_options *opts_set)
12249 : {
12250 97142719 : tree t;
12251 :
12252 : /* Use the cache of optimization nodes. */
12253 :
12254 97142719 : cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
12255 : opts, opts_set);
12256 :
12257 97142719 : tree *slot = cl_option_hash_table->find_slot (cl_optimization_node, INSERT);
12258 97142719 : t = *slot;
12259 97142719 : if (!t)
12260 : {
12261 : /* Insert this one into the hash table. */
12262 287952 : t = cl_optimization_node;
12263 287952 : *slot = t;
12264 :
12265 : /* Make a new node for next time round. */
12266 287952 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
12267 : }
12268 :
12269 97142719 : return t;
12270 : }
12271 :
12272 : /* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET. */
12273 :
12274 : tree
12275 75290490 : build_target_option_node (struct gcc_options *opts,
12276 : struct gcc_options *opts_set)
12277 : {
12278 75290490 : tree t;
12279 :
12280 : /* Use the cache of optimization nodes. */
12281 :
12282 75290490 : cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
12283 : opts, opts_set);
12284 :
12285 75290490 : tree *slot = cl_option_hash_table->find_slot (cl_target_option_node, INSERT);
12286 75290490 : t = *slot;
12287 75290490 : if (!t)
12288 : {
12289 : /* Insert this one into the hash table. */
12290 771435 : t = cl_target_option_node;
12291 771435 : *slot = t;
12292 :
12293 : /* Make a new node for next time round. */
12294 771435 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
12295 : }
12296 :
12297 75290490 : return t;
12298 : }
12299 :
12300 : /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
12301 : so that they aren't saved during PCH writing. */
12302 :
12303 : void
12304 428 : prepare_target_option_nodes_for_pch (void)
12305 : {
12306 428 : hash_table<cl_option_hasher>::iterator iter = cl_option_hash_table->begin ();
12307 2568 : for (; iter != cl_option_hash_table->end (); ++iter)
12308 856 : if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
12309 428 : TREE_TARGET_GLOBALS (*iter) = NULL;
12310 428 : }
12311 :
12312 : /* Determine the "ultimate origin" of a block. */
12313 :
12314 : tree
12315 210060174 : block_ultimate_origin (const_tree block)
12316 : {
12317 210060174 : tree origin = BLOCK_ABSTRACT_ORIGIN (block);
12318 :
12319 210060174 : if (origin == NULL_TREE)
12320 : return NULL_TREE;
12321 : else
12322 : {
12323 250404491 : gcc_checking_assert ((DECL_P (origin)
12324 : && DECL_ORIGIN (origin) == origin)
12325 : || BLOCK_ORIGIN (origin) == origin);
12326 : return origin;
12327 : }
12328 : }
12329 :
12330 : /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
12331 : no instruction. */
12332 :
12333 : bool
12334 1705222449 : tree_nop_conversion_p (const_tree outer_type, const_tree inner_type)
12335 : {
12336 1705222449 : if (!inner_type || inner_type == error_mark_node)
12337 : return false;
12338 :
12339 : /* Do not strip casts into or out of differing address spaces. */
12340 1705186075 : if (POINTER_TYPE_P (outer_type)
12341 1705186075 : && TYPE_ADDR_SPACE (TREE_TYPE (outer_type)) != ADDR_SPACE_GENERIC)
12342 : {
12343 570 : if (!POINTER_TYPE_P (inner_type)
12344 570 : || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
12345 547 : != TYPE_ADDR_SPACE (TREE_TYPE (inner_type))))
12346 : return false;
12347 : }
12348 1705185505 : else if (POINTER_TYPE_P (inner_type)
12349 1705185505 : && TYPE_ADDR_SPACE (TREE_TYPE (inner_type)) != ADDR_SPACE_GENERIC)
12350 : {
12351 : /* We already know that outer_type is not a pointer with
12352 : a non-generic address space. */
12353 : return false;
12354 : }
12355 :
12356 : /* Use precision rather then machine mode when we can, which gives
12357 : the correct answer even for submode (bit-field) types. */
12358 1705183338 : if ((INTEGRAL_TYPE_P (outer_type)
12359 702864393 : || POINTER_TYPE_P (outer_type)
12360 69907624 : || TREE_CODE (outer_type) == OFFSET_TYPE)
12361 1635287000 : && (INTEGRAL_TYPE_P (inner_type)
12362 713707552 : || POINTER_TYPE_P (inner_type)
12363 2665863 : || TREE_CODE (inner_type) == OFFSET_TYPE))
12364 1632644012 : return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
12365 :
12366 : /* Otherwise fall back on comparing machine modes (e.g. for
12367 : aggregate types, floats). */
12368 72539326 : return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
12369 : }
12370 :
12371 : /* Return true iff conversion in EXP generates no instruction. Mark
12372 : it inline so that we fully inline into the stripping functions even
12373 : though we have two uses of this function. */
12374 :
12375 : static inline bool
12376 20894199483 : tree_nop_conversion (const_tree exp)
12377 : {
12378 20894199483 : tree outer_type, inner_type;
12379 :
12380 20894199483 : if (location_wrapper_p (exp))
12381 : return true;
12382 20816746887 : if (!CONVERT_EXPR_P (exp)
12383 19741839729 : && TREE_CODE (exp) != NON_LVALUE_EXPR)
12384 : return false;
12385 :
12386 1095088346 : outer_type = TREE_TYPE (exp);
12387 1095088346 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12388 :
12389 1095088346 : return tree_nop_conversion_p (outer_type, inner_type);
12390 : }
12391 :
12392 : /* Return true iff conversion in EXP generates no instruction. Don't
12393 : consider conversions changing the signedness. */
12394 :
12395 : static bool
12396 2378922148 : tree_sign_nop_conversion (const_tree exp)
12397 : {
12398 2378922148 : tree outer_type, inner_type;
12399 :
12400 2378922148 : if (!tree_nop_conversion (exp))
12401 : return false;
12402 :
12403 225442878 : outer_type = TREE_TYPE (exp);
12404 225442878 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12405 :
12406 225442878 : return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
12407 225442878 : && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
12408 : }
12409 :
12410 : /* Strip conversions from EXP according to tree_nop_conversion and
12411 : return the resulting expression. */
12412 :
12413 : tree
12414 17739134473 : tree_strip_nop_conversions (tree exp)
12415 : {
12416 18515277335 : while (tree_nop_conversion (exp))
12417 776142862 : exp = TREE_OPERAND (exp, 0);
12418 17739134473 : return exp;
12419 : }
12420 :
12421 : /* Strip conversions from EXP according to tree_sign_nop_conversion
12422 : and return the resulting expression. */
12423 :
12424 : tree
12425 2179297721 : tree_strip_sign_nop_conversions (tree exp)
12426 : {
12427 2378922148 : while (tree_sign_nop_conversion (exp))
12428 199624427 : exp = TREE_OPERAND (exp, 0);
12429 2179297721 : return exp;
12430 : }
12431 :
12432 : /* Avoid any floating point extensions from EXP. */
12433 : tree
12434 117563481 : strip_float_extensions (tree exp)
12435 : {
12436 117660277 : tree sub, expt, subt;
12437 :
12438 : /* For floating point constant look up the narrowest type that can hold
12439 : it properly and handle it like (type)(narrowest_type)constant.
12440 : This way we can optimize for instance a=a*2.0 where "a" is float
12441 : but 2.0 is double constant. */
12442 117660277 : if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
12443 : {
12444 3546244 : REAL_VALUE_TYPE orig;
12445 3546244 : tree type = NULL;
12446 :
12447 3546244 : orig = TREE_REAL_CST (exp);
12448 3546244 : if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node)
12449 3546244 : && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
12450 140187 : type = float_type_node;
12451 3406057 : else if (TYPE_PRECISION (TREE_TYPE (exp))
12452 3406057 : > TYPE_PRECISION (double_type_node)
12453 3406057 : && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
12454 34561 : type = double_type_node;
12455 3546244 : if (type)
12456 174748 : return build_real_truncate (type, orig);
12457 : }
12458 :
12459 117485529 : if (!CONVERT_EXPR_P (exp))
12460 : return exp;
12461 :
12462 6433545 : sub = TREE_OPERAND (exp, 0);
12463 6433545 : subt = TREE_TYPE (sub);
12464 6433545 : expt = TREE_TYPE (exp);
12465 :
12466 6433545 : if (!FLOAT_TYPE_P (subt))
12467 : return exp;
12468 :
12469 359467 : if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
12470 : return exp;
12471 :
12472 120187 : if (element_precision (subt) > element_precision (expt))
12473 : return exp;
12474 :
12475 : return strip_float_extensions (sub);
12476 : }
12477 :
12478 : /* Strip out all handled components that produce invariant
12479 : offsets. */
12480 :
12481 : const_tree
12482 5755817236 : strip_invariant_refs (const_tree op)
12483 : {
12484 6689427123 : while (handled_component_p (op))
12485 : {
12486 945587537 : switch (TREE_CODE (op))
12487 : {
12488 183406061 : case ARRAY_REF:
12489 183406061 : case ARRAY_RANGE_REF:
12490 183406061 : if (!is_gimple_constant (TREE_OPERAND (op, 1))
12491 173114253 : || TREE_OPERAND (op, 2) != NULL_TREE
12492 171560450 : || TREE_OPERAND (op, 3) != NULL_TREE)
12493 : return NULL;
12494 : break;
12495 :
12496 761851910 : case COMPONENT_REF:
12497 761851910 : if (TREE_OPERAND (op, 2) != NULL_TREE)
12498 : return NULL;
12499 : break;
12500 :
12501 933609887 : default:;
12502 : }
12503 933609887 : op = TREE_OPERAND (op, 0);
12504 : }
12505 :
12506 : return op;
12507 : }
12508 :
12509 : /* Strip handled components with zero offset from OP. */
12510 :
12511 : tree
12512 561390 : strip_zero_offset_components (tree op)
12513 : {
12514 561390 : while (TREE_CODE (op) == COMPONENT_REF
12515 427563 : && integer_zerop (DECL_FIELD_OFFSET (TREE_OPERAND (op, 1)))
12516 1098868 : && integer_zerop (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (op, 1))))
12517 175307 : op = TREE_OPERAND (op, 0);
12518 561390 : return op;
12519 : }
12520 :
12521 : static GTY(()) tree gcc_eh_personality_decl;
12522 :
12523 : /* Return the GCC personality function decl. */
12524 :
12525 : tree
12526 401 : lhd_gcc_personality (void)
12527 : {
12528 401 : if (!gcc_eh_personality_decl)
12529 155 : gcc_eh_personality_decl = build_personality_function ("gcc");
12530 401 : return gcc_eh_personality_decl;
12531 : }
12532 :
12533 : /* TARGET is a call target of GIMPLE call statement
12534 : (obtained by gimple_call_fn). Return true if it is
12535 : OBJ_TYPE_REF representing an virtual call of C++ method.
12536 : (As opposed to OBJ_TYPE_REF representing objc calls
12537 : through a cast where middle-end devirtualization machinery
12538 : can't apply.) FOR_DUMP_P is true when being called from
12539 : the dump routines. */
12540 :
12541 : bool
12542 27747211 : virtual_method_call_p (const_tree target, bool for_dump_p)
12543 : {
12544 27747211 : if (TREE_CODE (target) != OBJ_TYPE_REF)
12545 : return false;
12546 1295784 : tree t = TREE_TYPE (target);
12547 1295784 : gcc_checking_assert (TREE_CODE (t) == POINTER_TYPE);
12548 1295784 : t = TREE_TYPE (t);
12549 1295784 : if (TREE_CODE (t) == FUNCTION_TYPE)
12550 : return false;
12551 1294696 : gcc_checking_assert (TREE_CODE (t) == METHOD_TYPE);
12552 : /* If we do not have BINFO associated, it means that type was built
12553 : without devirtualization enabled. Do not consider this a virtual
12554 : call. */
12555 1294696 : if (!TYPE_BINFO (obj_type_ref_class (target, for_dump_p)))
12556 : return false;
12557 : return true;
12558 : }
12559 :
12560 : /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
12561 :
12562 : static tree
12563 108 : lookup_binfo_at_offset (tree binfo, tree type, HOST_WIDE_INT pos)
12564 : {
12565 108 : unsigned int i;
12566 108 : tree base_binfo, b;
12567 :
12568 124 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12569 108 : if (pos == tree_to_shwi (BINFO_OFFSET (base_binfo))
12570 108 : && types_same_for_odr (TREE_TYPE (base_binfo), type))
12571 : return base_binfo;
12572 70 : else if ((b = lookup_binfo_at_offset (base_binfo, type, pos)) != NULL)
12573 : return b;
12574 : return NULL;
12575 : }
12576 :
12577 : /* Try to find a base info of BINFO that would have its field decl at offset
12578 : OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12579 : found, return, otherwise return NULL_TREE. */
12580 :
12581 : tree
12582 315111 : get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
12583 : {
12584 315111 : tree type = BINFO_TYPE (binfo);
12585 :
12586 859337 : while (true)
12587 : {
12588 587224 : HOST_WIDE_INT pos, size;
12589 587224 : tree fld;
12590 587224 : int i;
12591 :
12592 587224 : if (types_same_for_odr (type, expected_type))
12593 315111 : return binfo;
12594 272113 : if (maybe_lt (offset, 0))
12595 : return NULL_TREE;
12596 :
12597 1555246 : for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
12598 : {
12599 1555246 : if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld))
12600 1282936 : continue;
12601 :
12602 272310 : pos = int_bit_position (fld);
12603 272310 : size = tree_to_uhwi (DECL_SIZE (fld));
12604 1555443 : if (known_in_range_p (offset, pos, size))
12605 : break;
12606 : }
12607 272113 : if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
12608 : return NULL_TREE;
12609 :
12610 : /* Offset 0 indicates the primary base, whose vtable contents are
12611 : represented in the binfo for the derived class. */
12612 272113 : else if (maybe_ne (offset, 0))
12613 : {
12614 197 : tree found_binfo = NULL, base_binfo;
12615 : /* Offsets in BINFO are in bytes relative to the whole structure
12616 : while POS is in bits relative to the containing field. */
12617 197 : int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos
12618 197 : / BITS_PER_UNIT);
12619 :
12620 377 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12621 339 : if (tree_to_shwi (BINFO_OFFSET (base_binfo)) == binfo_offset
12622 339 : && types_same_for_odr (TREE_TYPE (base_binfo), TREE_TYPE (fld)))
12623 : {
12624 : found_binfo = base_binfo;
12625 : break;
12626 : }
12627 197 : if (found_binfo)
12628 : binfo = found_binfo;
12629 : else
12630 38 : binfo = lookup_binfo_at_offset (binfo, TREE_TYPE (fld),
12631 : binfo_offset);
12632 : }
12633 :
12634 272113 : type = TREE_TYPE (fld);
12635 272113 : offset -= pos;
12636 272113 : }
12637 : }
12638 :
12639 : /* PR 84195: Replace control characters in "unescaped" with their
12640 : escaped equivalents. Allow newlines if -fmessage-length has
12641 : been set to a non-zero value. This is done here, rather than
12642 : where the attribute is recorded as the message length can
12643 : change between these two locations. */
12644 :
12645 : void
12646 127291 : escaped_string::escape (const char *unescaped)
12647 : {
12648 127291 : char *escaped;
12649 127291 : size_t i, new_i, len;
12650 :
12651 127291 : if (m_owned)
12652 8 : free (m_str);
12653 :
12654 127291 : m_str = const_cast<char *> (unescaped);
12655 127291 : m_owned = false;
12656 :
12657 127291 : if (unescaped == NULL || *unescaped == 0)
12658 : return;
12659 :
12660 127283 : len = strlen (unescaped);
12661 127283 : escaped = NULL;
12662 127283 : new_i = 0;
12663 :
12664 3701882 : for (i = 0; i < len; i++)
12665 : {
12666 3574599 : char c = unescaped[i];
12667 :
12668 3574599 : if (!ISCNTRL (c))
12669 : {
12670 3574514 : if (escaped)
12671 33 : escaped[new_i++] = c;
12672 3574514 : continue;
12673 : }
12674 :
12675 85 : if (c != '\n' || !pp_is_wrapping_line (global_dc->get_reference_printer ()))
12676 : {
12677 77 : if (escaped == NULL)
12678 : {
12679 : /* We only allocate space for a new string if we
12680 : actually encounter a control character that
12681 : needs replacing. */
12682 19 : escaped = (char *) xmalloc (len * 2 + 1);
12683 19 : strncpy (escaped, unescaped, i);
12684 19 : new_i = i;
12685 : }
12686 :
12687 77 : escaped[new_i++] = '\\';
12688 :
12689 77 : switch (c)
12690 : {
12691 8 : case '\a': escaped[new_i++] = 'a'; break;
12692 8 : case '\b': escaped[new_i++] = 'b'; break;
12693 8 : case '\f': escaped[new_i++] = 'f'; break;
12694 15 : case '\n': escaped[new_i++] = 'n'; break;
12695 15 : case '\r': escaped[new_i++] = 'r'; break;
12696 15 : case '\t': escaped[new_i++] = 't'; break;
12697 8 : case '\v': escaped[new_i++] = 'v'; break;
12698 0 : default: escaped[new_i++] = '?'; break;
12699 : }
12700 : }
12701 8 : else if (escaped)
12702 4 : escaped[new_i++] = c;
12703 : }
12704 :
12705 127283 : if (escaped)
12706 : {
12707 19 : escaped[new_i] = 0;
12708 19 : m_str = escaped;
12709 19 : m_owned = true;
12710 : }
12711 : }
12712 :
12713 : /* Warn about a use of an identifier which was marked deprecated. Returns
12714 : whether a warning was given. */
12715 :
12716 : bool
12717 1179792 : warn_deprecated_use (tree node, tree attr)
12718 : {
12719 1179792 : escaped_string msg;
12720 :
12721 1179792 : if (node == 0 || !warn_deprecated_decl)
12722 : return false;
12723 :
12724 1172577 : if (!attr)
12725 : {
12726 1065045 : if (DECL_P (node))
12727 1064911 : attr = DECL_ATTRIBUTES (node);
12728 134 : else if (TYPE_P (node))
12729 : {
12730 134 : tree decl = TYPE_STUB_DECL (node);
12731 134 : if (decl)
12732 110 : attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
12733 24 : else if ((decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node)))
12734 : != NULL_TREE)
12735 : {
12736 6 : node = TREE_TYPE (decl);
12737 6 : attr = TYPE_ATTRIBUTES (node);
12738 : }
12739 : }
12740 : }
12741 :
12742 1065045 : if (attr)
12743 126965 : attr = lookup_attribute ("deprecated", attr);
12744 :
12745 126965 : if (attr)
12746 126954 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12747 :
12748 1172577 : bool w = false;
12749 1172577 : if (DECL_P (node))
12750 : {
12751 1172433 : auto_diagnostic_group d;
12752 1172433 : if (msg)
12753 126899 : w = warning (OPT_Wdeprecated_declarations,
12754 : "%qD is deprecated: %s", node, (const char *) msg);
12755 : else
12756 1045534 : w = warning (OPT_Wdeprecated_declarations,
12757 : "%qD is deprecated", node);
12758 1172433 : if (w)
12759 791 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12760 1172433 : }
12761 144 : else if (TYPE_P (node))
12762 : {
12763 144 : tree what = NULL_TREE;
12764 144 : tree decl = TYPE_STUB_DECL (node);
12765 :
12766 144 : if (TYPE_NAME (node))
12767 : {
12768 139 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12769 10 : what = TYPE_NAME (node);
12770 129 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12771 129 : && DECL_NAME (TYPE_NAME (node)))
12772 129 : what = DECL_NAME (TYPE_NAME (node));
12773 : }
12774 :
12775 144 : auto_diagnostic_group d;
12776 144 : if (what)
12777 : {
12778 139 : if (msg)
12779 53 : w = warning (OPT_Wdeprecated_declarations,
12780 : "%qE is deprecated: %s", what, (const char *) msg);
12781 : else
12782 86 : w = warning (OPT_Wdeprecated_declarations,
12783 : "%qE is deprecated", what);
12784 : }
12785 : else
12786 : {
12787 5 : if (msg)
12788 2 : w = warning (OPT_Wdeprecated_declarations,
12789 : "type is deprecated: %s", (const char *) msg);
12790 : else
12791 3 : w = warning (OPT_Wdeprecated_declarations,
12792 : "type is deprecated");
12793 : }
12794 :
12795 144 : if (w && decl)
12796 111 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12797 144 : }
12798 :
12799 : return w;
12800 1179792 : }
12801 :
12802 : /* Error out with an identifier which was marked 'unavailable'. */
12803 : void
12804 376 : error_unavailable_use (tree node, tree attr)
12805 : {
12806 376 : escaped_string msg;
12807 :
12808 376 : if (node == 0)
12809 0 : return;
12810 :
12811 376 : if (!attr)
12812 : {
12813 366 : if (DECL_P (node))
12814 306 : attr = DECL_ATTRIBUTES (node);
12815 60 : else if (TYPE_P (node))
12816 : {
12817 60 : tree decl = TYPE_STUB_DECL (node);
12818 60 : if (decl)
12819 51 : attr = lookup_attribute ("unavailable",
12820 51 : TYPE_ATTRIBUTES (TREE_TYPE (decl)));
12821 : }
12822 : }
12823 :
12824 366 : if (attr)
12825 164 : attr = lookup_attribute ("unavailable", attr);
12826 :
12827 164 : if (attr)
12828 164 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12829 :
12830 376 : if (DECL_P (node))
12831 : {
12832 306 : auto_diagnostic_group d;
12833 306 : if (msg)
12834 129 : error ("%qD is unavailable: %s", node, (const char *) msg);
12835 : else
12836 177 : error ("%qD is unavailable", node);
12837 306 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12838 306 : }
12839 70 : else if (TYPE_P (node))
12840 : {
12841 70 : tree what = NULL_TREE;
12842 70 : tree decl = TYPE_STUB_DECL (node);
12843 :
12844 70 : if (TYPE_NAME (node))
12845 : {
12846 66 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12847 4 : what = TYPE_NAME (node);
12848 62 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12849 62 : && DECL_NAME (TYPE_NAME (node)))
12850 62 : what = DECL_NAME (TYPE_NAME (node));
12851 : }
12852 :
12853 70 : auto_diagnostic_group d;
12854 70 : if (what)
12855 : {
12856 66 : if (msg)
12857 33 : error ("%qE is unavailable: %s", what, (const char *) msg);
12858 : else
12859 33 : error ("%qE is unavailable", what);
12860 : }
12861 : else
12862 : {
12863 4 : if (msg)
12864 2 : error ("type is unavailable: %s", (const char *) msg);
12865 : else
12866 2 : error ("type is unavailable");
12867 : }
12868 :
12869 70 : if (decl)
12870 52 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12871 70 : }
12872 376 : }
12873 :
12874 : /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12875 : somewhere in it. */
12876 :
12877 : bool
12878 5618958 : contains_bitfld_component_ref_p (const_tree ref)
12879 : {
12880 11500614 : while (handled_component_p (ref))
12881 : {
12882 5900582 : if (TREE_CODE (ref) == COMPONENT_REF
12883 5900582 : && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
12884 : return true;
12885 5881656 : ref = TREE_OPERAND (ref, 0);
12886 : }
12887 :
12888 : return false;
12889 : }
12890 :
12891 : /* Try to determine whether a TRY_CATCH expression can fall through.
12892 : This is a subroutine of block_may_fallthru. */
12893 :
12894 : static bool
12895 1 : try_catch_may_fallthru (const_tree stmt)
12896 : {
12897 1 : tree_stmt_iterator i;
12898 :
12899 : /* If the TRY block can fall through, the whole TRY_CATCH can
12900 : fall through. */
12901 1 : if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
12902 : return true;
12903 :
12904 1 : switch (TREE_CODE (TREE_OPERAND (stmt, 1)))
12905 : {
12906 0 : case CATCH_EXPR:
12907 : /* See below. */
12908 0 : return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1)));
12909 :
12910 0 : case EH_FILTER_EXPR:
12911 : /* See below. */
12912 0 : return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1)));
12913 :
12914 0 : case STATEMENT_LIST:
12915 0 : break;
12916 :
12917 : default:
12918 : /* See below. */
12919 : return false;
12920 : }
12921 :
12922 0 : i = tsi_start (TREE_OPERAND (stmt, 1));
12923 0 : switch (TREE_CODE (tsi_stmt (i)))
12924 : {
12925 : case CATCH_EXPR:
12926 : /* We expect to see a sequence of CATCH_EXPR trees, each with a
12927 : catch expression and a body. The whole TRY_CATCH may fall
12928 : through iff any of the catch bodies falls through. */
12929 0 : for (; !tsi_end_p (i); tsi_next (&i))
12930 : {
12931 0 : if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
12932 : return true;
12933 : }
12934 : return false;
12935 :
12936 0 : case EH_FILTER_EXPR:
12937 : /* The exception filter expression only matters if there is an
12938 : exception. If the exception does not match EH_FILTER_TYPES,
12939 : we will execute EH_FILTER_FAILURE, and we will fall through
12940 : if that falls through. If the exception does match
12941 : EH_FILTER_TYPES, the stack unwinder will continue up the
12942 : stack, so we will not fall through. We don't know whether we
12943 : will throw an exception which matches EH_FILTER_TYPES or not,
12944 : so we just ignore EH_FILTER_TYPES and assume that we might
12945 : throw an exception which doesn't match. */
12946 0 : return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
12947 :
12948 : default:
12949 : /* This case represents statements to be executed when an
12950 : exception occurs. Those statements are implicitly followed
12951 : by a RESX statement to resume execution after the exception.
12952 : So in this case the TRY_CATCH never falls through. */
12953 : return false;
12954 : }
12955 : }
12956 :
12957 : /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12958 : need not be 100% accurate; simply be conservative and return true if we
12959 : don't know. This is used only to avoid stupidly generating extra code.
12960 : If we're wrong, we'll just delete the extra code later. */
12961 :
12962 : bool
12963 10938957 : block_may_fallthru (const_tree block)
12964 : {
12965 : /* This CONST_CAST is okay because expr_last returns its argument
12966 : unmodified and we assign it to a const_tree. */
12967 13511070 : const_tree stmt = expr_last (const_cast<tree> (block));
12968 :
12969 13511070 : switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
12970 : {
12971 : case GOTO_EXPR:
12972 : case RETURN_EXPR:
12973 : /* Easy cases. If the last statement of the block implies
12974 : control transfer, then we can't fall through. */
12975 : return false;
12976 :
12977 9 : case SWITCH_EXPR:
12978 : /* If there is a default: label or case labels cover all possible
12979 : SWITCH_COND values, then the SWITCH_EXPR will transfer control
12980 : to some case label in all cases and all we care is whether the
12981 : SWITCH_BODY falls through. */
12982 9 : if (SWITCH_ALL_CASES_P (stmt))
12983 8 : return block_may_fallthru (SWITCH_BODY (stmt));
12984 : return true;
12985 :
12986 20906 : case COND_EXPR:
12987 20906 : if (block_may_fallthru (COND_EXPR_THEN (stmt)))
12988 : return true;
12989 2789 : return block_may_fallthru (COND_EXPR_ELSE (stmt));
12990 :
12991 1210388 : case BIND_EXPR:
12992 1210388 : return block_may_fallthru (BIND_EXPR_BODY (stmt));
12993 :
12994 1 : case TRY_CATCH_EXPR:
12995 1 : return try_catch_may_fallthru (stmt);
12996 :
12997 1233 : case TRY_FINALLY_EXPR:
12998 : /* The finally clause is always executed after the try clause,
12999 : so if it does not fall through, then the try-finally will not
13000 : fall through. Otherwise, if the try clause does not fall
13001 : through, then when the finally clause falls through it will
13002 : resume execution wherever the try clause was going. So the
13003 : whole try-finally will only fall through if both the try
13004 : clause and the finally clause fall through. */
13005 1233 : return (block_may_fallthru (TREE_OPERAND (stmt, 0))
13006 1233 : && block_may_fallthru (TREE_OPERAND (stmt, 1)));
13007 :
13008 0 : case EH_ELSE_EXPR:
13009 0 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
13010 :
13011 91367 : case MODIFY_EXPR:
13012 91367 : if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
13013 1548 : stmt = TREE_OPERAND (stmt, 1);
13014 : else
13015 : return true;
13016 : /* FALLTHRU */
13017 :
13018 444122 : case CALL_EXPR:
13019 : /* Functions that do not return do not fall through. */
13020 444122 : return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
13021 :
13022 1358918 : case CLEANUP_POINT_EXPR:
13023 1358918 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
13024 :
13025 10 : case TARGET_EXPR:
13026 10 : return block_may_fallthru (TREE_OPERAND (stmt, 1));
13027 :
13028 : case ERROR_MARK:
13029 : return true;
13030 :
13031 8241270 : default:
13032 8241270 : return lang_hooks.block_may_fallthru (stmt);
13033 : }
13034 : }
13035 :
13036 : /* True if we are using EH to handle cleanups. */
13037 : static bool using_eh_for_cleanups_flag = false;
13038 :
13039 : /* This routine is called from front ends to indicate eh should be used for
13040 : cleanups. */
13041 : void
13042 120902 : using_eh_for_cleanups (void)
13043 : {
13044 120902 : using_eh_for_cleanups_flag = true;
13045 120902 : }
13046 :
13047 : /* Query whether EH is used for cleanups. */
13048 : bool
13049 1607866 : using_eh_for_cleanups_p (void)
13050 : {
13051 1607866 : return using_eh_for_cleanups_flag;
13052 : }
13053 :
13054 : /* Wrapper for tree_code_name to ensure that tree code is valid */
13055 : const char *
13056 14139736853 : get_tree_code_name (enum tree_code code)
13057 : {
13058 14139736853 : const char *invalid = "<invalid tree code>";
13059 :
13060 : /* The tree_code enum promotes to signed, but we could be getting
13061 : invalid values, so force an unsigned comparison. */
13062 14139736853 : if (unsigned (code) >= MAX_TREE_CODES)
13063 : {
13064 0 : if ((unsigned)code == 0xa5a5)
13065 : return "ggc_freed";
13066 0 : return invalid;
13067 : }
13068 :
13069 14139736853 : return tree_code_name[code];
13070 : }
13071 :
13072 : /* Drops the TREE_OVERFLOW flag from T. */
13073 :
13074 : tree
13075 36589 : drop_tree_overflow (tree t)
13076 : {
13077 36589 : gcc_checking_assert (TREE_OVERFLOW (t));
13078 :
13079 : /* For tree codes with a sharing machinery re-build the result. */
13080 36589 : if (poly_int_tree_p (t))
13081 36577 : return wide_int_to_tree (TREE_TYPE (t), wi::to_poly_wide (t));
13082 :
13083 : /* For VECTOR_CST, remove the overflow bits from the encoded elements
13084 : and canonicalize the result. */
13085 12 : if (TREE_CODE (t) == VECTOR_CST)
13086 : {
13087 0 : tree_vector_builder builder;
13088 0 : builder.new_unary_operation (TREE_TYPE (t), t, true);
13089 0 : unsigned int count = builder.encoded_nelts ();
13090 0 : for (unsigned int i = 0; i < count; ++i)
13091 : {
13092 0 : tree elt = VECTOR_CST_ELT (t, i);
13093 0 : if (TREE_OVERFLOW (elt))
13094 0 : elt = drop_tree_overflow (elt);
13095 0 : builder.quick_push (elt);
13096 : }
13097 0 : return builder.build ();
13098 0 : }
13099 :
13100 : /* Otherwise, as all tcc_constants are possibly shared, copy the node
13101 : and drop the flag. */
13102 12 : t = copy_node (t);
13103 12 : TREE_OVERFLOW (t) = 0;
13104 :
13105 : /* For constants that contain nested constants, drop the flag
13106 : from those as well. */
13107 12 : if (TREE_CODE (t) == COMPLEX_CST)
13108 : {
13109 12 : if (TREE_OVERFLOW (TREE_REALPART (t)))
13110 12 : TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t));
13111 12 : if (TREE_OVERFLOW (TREE_IMAGPART (t)))
13112 0 : TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t));
13113 : }
13114 :
13115 : return t;
13116 : }
13117 :
13118 : /* Given a memory reference expression T, return its base address.
13119 : The base address of a memory reference expression is the main
13120 : object being referenced. For instance, the base address for
13121 : 'array[i].fld[j]' is 'array'. You can think of this as stripping
13122 : away the offset part from a memory address.
13123 :
13124 : This function calls handled_component_p to strip away all the inner
13125 : parts of the memory reference until it reaches the base object. */
13126 :
13127 : tree
13128 3147770437 : get_base_address (tree t)
13129 : {
13130 3147770437 : if (TREE_CODE (t) == WITH_SIZE_EXPR)
13131 899 : t = TREE_OPERAND (t, 0);
13132 3914173366 : while (handled_component_p (t))
13133 766402929 : t = TREE_OPERAND (t, 0);
13134 :
13135 3147770437 : if ((TREE_CODE (t) == MEM_REF
13136 3147770437 : || TREE_CODE (t) == TARGET_MEM_REF)
13137 3147770437 : && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
13138 141109006 : t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
13139 :
13140 3147770437 : return t;
13141 : }
13142 :
13143 : /* Return a tree of sizetype representing the size, in bytes, of the element
13144 : of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13145 :
13146 : tree
13147 787819304 : array_ref_element_size (tree exp)
13148 : {
13149 787819304 : tree aligned_size = TREE_OPERAND (exp, 3);
13150 787819304 : tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
13151 787819304 : location_t loc = EXPR_LOCATION (exp);
13152 :
13153 : /* If a size was specified in the ARRAY_REF, it's the size measured
13154 : in alignment units of the element type. So multiply by that value. */
13155 787819304 : if (aligned_size)
13156 : {
13157 : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13158 : sizetype from another type of the same width and signedness. */
13159 390103 : if (TREE_TYPE (aligned_size) != sizetype)
13160 3157 : aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
13161 390103 : return size_binop_loc (loc, MULT_EXPR, aligned_size,
13162 390103 : size_int (TYPE_ALIGN_UNIT (elmt_type)));
13163 : }
13164 :
13165 : /* Otherwise, take the size from that of the element type. Substitute
13166 : any PLACEHOLDER_EXPR that we have. */
13167 : else
13168 787429201 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
13169 : }
13170 :
13171 : /* Return a tree representing the lower bound of the array mentioned in
13172 : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13173 :
13174 : tree
13175 1087184552 : array_ref_low_bound (tree exp)
13176 : {
13177 1087184552 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13178 :
13179 : /* If a lower bound is specified in EXP, use it. */
13180 1087184552 : if (TREE_OPERAND (exp, 2))
13181 1935359 : return TREE_OPERAND (exp, 2);
13182 :
13183 : /* Otherwise, if there is a domain type and it has a lower bound, use it,
13184 : substituting for a PLACEHOLDER_EXPR as needed. */
13185 1085249193 : if (domain_type && TYPE_MIN_VALUE (domain_type))
13186 1084332167 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
13187 :
13188 : /* Otherwise, return a zero of the appropriate type. */
13189 917026 : tree idxtype = TREE_TYPE (TREE_OPERAND (exp, 1));
13190 917026 : return (idxtype == error_mark_node
13191 917026 : ? integer_zero_node : build_int_cst (idxtype, 0));
13192 : }
13193 :
13194 : /* Return a tree representing the upper bound of the array mentioned in
13195 : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13196 :
13197 : tree
13198 251564027 : array_ref_up_bound (tree exp)
13199 : {
13200 251564027 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13201 :
13202 : /* If there is a domain type and it has an upper bound, use it, substituting
13203 : for a PLACEHOLDER_EXPR as needed. */
13204 251564027 : if (domain_type && TYPE_MAX_VALUE (domain_type))
13205 250751555 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
13206 :
13207 : /* Otherwise fail. */
13208 : return NULL_TREE;
13209 : }
13210 :
13211 : /* Returns true if REF is an array reference, a component reference,
13212 : or a memory reference to an array whose actual size might be larger
13213 : than its upper bound implies, there are multiple cases:
13214 : A. a ref to a flexible array member at the end of a structure;
13215 : B. a ref to an array with a different type against the original decl;
13216 : for example:
13217 :
13218 : short a[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
13219 : (*((char(*)[16])&a[0]))[i+8]
13220 :
13221 : C. a ref to an array that was passed as a parameter;
13222 : for example:
13223 :
13224 : int test (uint8_t *p, uint32_t t[1][1], int n) {
13225 : for (int i = 0; i < 4; i++, p++)
13226 : t[i][0] = ...;
13227 :
13228 : If non-null, set IS_TRAILING_ARRAY to true if the ref is the above case A.
13229 : */
13230 :
13231 : bool
13232 77641478 : array_ref_flexible_size_p (tree ref, bool *is_trailing_array /* = NULL */)
13233 : {
13234 : /* The TYPE for this array referece. */
13235 77641478 : tree atype = NULL_TREE;
13236 : /* The FIELD_DECL for the array field in the containing structure. */
13237 77641478 : tree afield_decl = NULL_TREE;
13238 : /* Whether this array is the trailing array of a structure. */
13239 77641478 : bool is_trailing_array_tmp = false;
13240 77641478 : if (!is_trailing_array)
13241 77559102 : is_trailing_array = &is_trailing_array_tmp;
13242 :
13243 77641478 : if (TREE_CODE (ref) == ARRAY_REF
13244 77641478 : || TREE_CODE (ref) == ARRAY_RANGE_REF)
13245 : {
13246 77401876 : atype = TREE_TYPE (TREE_OPERAND (ref, 0));
13247 77401876 : ref = TREE_OPERAND (ref, 0);
13248 : }
13249 239602 : else if (TREE_CODE (ref) == COMPONENT_REF
13250 239602 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE)
13251 : {
13252 174934 : atype = TREE_TYPE (TREE_OPERAND (ref, 1));
13253 174934 : afield_decl = TREE_OPERAND (ref, 1);
13254 : }
13255 64668 : else if (TREE_CODE (ref) == MEM_REF)
13256 : {
13257 7851 : tree arg = TREE_OPERAND (ref, 0);
13258 7851 : if (TREE_CODE (arg) == ADDR_EXPR)
13259 7851 : arg = TREE_OPERAND (arg, 0);
13260 7851 : tree argtype = TREE_TYPE (arg);
13261 7851 : if (TREE_CODE (argtype) == RECORD_TYPE)
13262 : {
13263 157 : if (tree fld = last_field (argtype))
13264 : {
13265 157 : atype = TREE_TYPE (fld);
13266 157 : afield_decl = fld;
13267 157 : if (TREE_CODE (atype) != ARRAY_TYPE)
13268 : return false;
13269 157 : if (VAR_P (arg) && DECL_SIZE (fld))
13270 : return false;
13271 : }
13272 : else
13273 : return false;
13274 : }
13275 : else
13276 : return false;
13277 : }
13278 : else
13279 : return false;
13280 :
13281 77576923 : if (TREE_CODE (ref) == STRING_CST)
13282 : return false;
13283 :
13284 : tree ref_to_array = ref;
13285 94322249 : while (handled_component_p (ref))
13286 : {
13287 : /* If the reference chain contains a component reference to a
13288 : non-union type and there follows another field the reference
13289 : is not at the end of a structure. */
13290 19930476 : if (TREE_CODE (ref) == COMPONENT_REF)
13291 : {
13292 18774975 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
13293 : {
13294 17521319 : tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
13295 32042238 : while (nextf && TREE_CODE (nextf) != FIELD_DECL)
13296 14520919 : nextf = DECL_CHAIN (nextf);
13297 : if (nextf)
13298 : return false;
13299 : }
13300 : }
13301 : /* If we have a multi-dimensional array we do not consider
13302 : a non-innermost dimension as flex array if the whole
13303 : multi-dimensional array is at struct end.
13304 : Same for an array of aggregates with a trailing array
13305 : member. */
13306 1155501 : else if (TREE_CODE (ref) == ARRAY_REF)
13307 : return false;
13308 186261 : else if (TREE_CODE (ref) == ARRAY_RANGE_REF)
13309 : ;
13310 : /* If we view an underlying object as sth else then what we
13311 : gathered up to now is what we have to rely on. */
13312 186251 : else if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
13313 : break;
13314 : else
13315 0 : gcc_unreachable ();
13316 :
13317 16746465 : ref = TREE_OPERAND (ref, 0);
13318 : }
13319 :
13320 74578024 : gcc_assert (!afield_decl
13321 : || (afield_decl && TREE_CODE (afield_decl) == FIELD_DECL));
13322 :
13323 : /* The array now is at struct end. Treat flexible array member as
13324 : always subject to extend, even into just padding constrained by
13325 : an underlying decl. */
13326 74578024 : if (! TYPE_SIZE (atype)
13327 72029474 : || ! TYPE_DOMAIN (atype)
13328 146607498 : || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13329 : {
13330 2554081 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13331 2640977 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13332 : }
13333 :
13334 : /* If the reference is based on a declared entity, the size of the array
13335 : is constrained by its given domain. (Do not trust commons PR/69368). */
13336 72023943 : ref = get_base_address (ref);
13337 72023943 : if (ref
13338 72023943 : && DECL_P (ref)
13339 62050384 : && !(flag_unconstrained_commons
13340 14 : && VAR_P (ref) && DECL_COMMON (ref))
13341 62050370 : && DECL_SIZE_UNIT (ref)
13342 134073936 : && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
13343 : {
13344 : /* If the object itself is the array it is not at struct end. */
13345 62049965 : if (DECL_P (ref_to_array))
13346 : return false;
13347 :
13348 : /* Check whether the array domain covers all of the available
13349 : padding. */
13350 15640313 : poly_int64 offset;
13351 15640313 : if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
13352 15638953 : || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST
13353 31253914 : || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST)
13354 : {
13355 26712 : *is_trailing_array
13356 26712 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13357 26755 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13358 : }
13359 15613601 : if (! get_addr_base_and_unit_offset (ref_to_array, &offset))
13360 : {
13361 2821 : *is_trailing_array
13362 2821 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13363 2821 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13364 : }
13365 :
13366 : /* If at least one extra element fits it is a flexarray. */
13367 15610780 : if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13368 : - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype)))
13369 : + 2)
13370 : * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype))),
13371 : wi::to_offset (DECL_SIZE_UNIT (ref)) - offset))
13372 : {
13373 583737 : *is_trailing_array
13374 583737 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13375 597092 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13376 : }
13377 :
13378 : return false;
13379 : }
13380 :
13381 9973978 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13382 9988636 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13383 : }
13384 :
13385 :
13386 : /* Return a tree representing the offset, in bytes, of the field referenced
13387 : by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
13388 :
13389 : tree
13390 2694479973 : component_ref_field_offset (tree exp)
13391 : {
13392 2694479973 : tree aligned_offset = TREE_OPERAND (exp, 2);
13393 2694479973 : tree field = TREE_OPERAND (exp, 1);
13394 2694479973 : location_t loc = EXPR_LOCATION (exp);
13395 :
13396 : /* If an offset was specified in the COMPONENT_REF, it's the offset measured
13397 : in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
13398 : value. */
13399 2694479973 : if (aligned_offset)
13400 : {
13401 : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13402 : sizetype from another type of the same width and signedness. */
13403 12016 : if (TREE_TYPE (aligned_offset) != sizetype)
13404 135 : aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
13405 12016 : return size_binop_loc (loc, MULT_EXPR, aligned_offset,
13406 12016 : size_int (DECL_OFFSET_ALIGN (field)
13407 : / BITS_PER_UNIT));
13408 : }
13409 :
13410 : /* Otherwise, take the offset from that of the field. Substitute
13411 : any PLACEHOLDER_EXPR that we have. */
13412 : else
13413 2694467957 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
13414 : }
13415 :
13416 : /* Given the initializer INIT, return the initializer for the field
13417 : DECL if it exists, otherwise null. Used to obtain the initializer
13418 : for a flexible array member and determine its size. */
13419 :
13420 : static tree
13421 1267 : get_initializer_for (tree init, tree decl)
13422 : {
13423 1267 : STRIP_NOPS (init);
13424 :
13425 1267 : tree fld, fld_init;
13426 1267 : unsigned HOST_WIDE_INT i;
13427 3571 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), i, fld, fld_init)
13428 : {
13429 1926 : if (decl == fld)
13430 : return fld_init;
13431 :
13432 1037 : if (TREE_CODE (fld) == CONSTRUCTOR)
13433 : {
13434 0 : fld_init = get_initializer_for (fld_init, decl);
13435 0 : if (fld_init)
13436 : return fld_init;
13437 : }
13438 : }
13439 :
13440 : return NULL_TREE;
13441 : }
13442 :
13443 : /* Determines the special array member type for the array reference REF. */
13444 : special_array_member
13445 253437 : component_ref_sam_type (tree ref)
13446 : {
13447 253437 : special_array_member sam_type = special_array_member::none;
13448 :
13449 253437 : tree member = TREE_OPERAND (ref, 1);
13450 253437 : tree memsize = DECL_SIZE_UNIT (member);
13451 253437 : if (memsize)
13452 : {
13453 121411 : tree memtype = TREE_TYPE (member);
13454 121411 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13455 121289 : return sam_type;
13456 :
13457 82376 : bool trailing = false;
13458 82376 : (void) array_ref_flexible_size_p (ref, &trailing);
13459 82376 : bool zero_elts = integer_zerop (memsize);
13460 82376 : if (zero_elts && integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (memtype))))
13461 : {
13462 : /* If array element has zero size, verify if it is a flexible
13463 : array member or zero length array. Clear zero_elts if
13464 : it has one or more members or is a VLA member. */
13465 6 : if (tree dom = TYPE_DOMAIN (memtype))
13466 6 : if (tree min = TYPE_MIN_VALUE (dom))
13467 6 : if (tree max = TYPE_MAX_VALUE (dom))
13468 4 : if (TREE_CODE (min) != INTEGER_CST
13469 4 : || TREE_CODE (max) != INTEGER_CST
13470 12 : || !((integer_zerop (min) && integer_all_onesp (max))
13471 4 : || tree_int_cst_lt (max, min)))
13472 : zero_elts = false;
13473 : }
13474 82376 : if (!trailing && !zero_elts)
13475 : /* MEMBER is an interior array with more than one element. */
13476 : return special_array_member::int_n;
13477 :
13478 24580 : if (zero_elts)
13479 : {
13480 1074 : if (trailing)
13481 : return special_array_member::trail_0;
13482 : else
13483 463 : return special_array_member::int_0;
13484 : }
13485 :
13486 23969 : if (!zero_elts)
13487 23969 : if (tree dom = TYPE_DOMAIN (memtype))
13488 23969 : if (tree min = TYPE_MIN_VALUE (dom))
13489 23969 : if (tree max = TYPE_MAX_VALUE (dom))
13490 23969 : if (TREE_CODE (min) == INTEGER_CST
13491 23969 : && TREE_CODE (max) == INTEGER_CST)
13492 : {
13493 23847 : offset_int minidx = wi::to_offset (min);
13494 23847 : offset_int maxidx = wi::to_offset (max);
13495 23847 : offset_int neltsm1 = maxidx - minidx;
13496 23847 : if (neltsm1 > 0)
13497 : /* MEMBER is a trailing array with more than
13498 : one elements. */
13499 23847 : return special_array_member::trail_n;
13500 :
13501 2038 : if (neltsm1 == 0)
13502 : return special_array_member::trail_1;
13503 : }
13504 : }
13505 :
13506 : return sam_type;
13507 : }
13508 :
13509 : /* Determines the size of the member referenced by the COMPONENT_REF
13510 : REF, using its initializer expression if necessary in order to
13511 : determine the size of an initialized flexible array member.
13512 : If non-null, set *SAM to the type of special array member.
13513 : Returns the size as sizetype (which might be zero for an object
13514 : with an uninitialized flexible array member) or null if the size
13515 : cannot be determined. */
13516 :
13517 : tree
13518 154351 : component_ref_size (tree ref, special_array_member *sam /* = NULL */)
13519 : {
13520 154351 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
13521 :
13522 154351 : special_array_member sambuf;
13523 154351 : if (!sam)
13524 100270 : sam = &sambuf;
13525 154351 : *sam = component_ref_sam_type (ref);
13526 :
13527 : /* The object/argument referenced by the COMPONENT_REF and its type. */
13528 154351 : tree arg = TREE_OPERAND (ref, 0);
13529 154351 : tree argtype = TREE_TYPE (arg);
13530 : /* The referenced member. */
13531 154351 : tree member = TREE_OPERAND (ref, 1);
13532 :
13533 154351 : tree memsize = DECL_SIZE_UNIT (member);
13534 154351 : if (memsize)
13535 : {
13536 86798 : tree memtype = TREE_TYPE (member);
13537 86798 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13538 : /* DECL_SIZE may be less than TYPE_SIZE in C++ when referring
13539 : to the type of a class with a virtual base which doesn't
13540 : reflect the size of the virtual's members (see pr97595).
13541 : If that's the case fail for now and implement something
13542 : more robust in the future. */
13543 39035 : return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype))
13544 39035 : ? memsize : NULL_TREE);
13545 :
13546 : /* 2-or-more elements arrays are treated as normal arrays by default. */
13547 47763 : if (*sam == special_array_member::int_n
13548 47763 : || *sam == special_array_member::trail_n)
13549 : return memsize;
13550 :
13551 1777 : tree afield_decl = TREE_OPERAND (ref, 1);
13552 1777 : gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
13553 : /* If the trailing array is a not a flexible array member, treat it as
13554 : a normal array. */
13555 1777 : if (DECL_NOT_FLEXARRAY (afield_decl)
13556 1777 : && *sam != special_array_member::int_0)
13557 : return memsize;
13558 :
13559 1768 : if (*sam == special_array_member::int_0)
13560 270 : memsize = NULL_TREE;
13561 :
13562 : /* For a reference to a flexible array member of a union
13563 : use the size of the union instead of the size of the member. */
13564 1768 : if (TREE_CODE (argtype) == UNION_TYPE)
13565 277 : memsize = TYPE_SIZE_UNIT (argtype);
13566 : }
13567 :
13568 : /* MEMBER is either a bona fide flexible array member, or a zero-elements
13569 : array member, or an array of length one treated as such. */
13570 :
13571 : /* If the reference is to a declared object and the member a true
13572 : flexible array, try to determine its size from its initializer. */
13573 69321 : poly_int64 baseoff = 0;
13574 69321 : tree base = get_addr_base_and_unit_offset (ref, &baseoff);
13575 69321 : if (!base || !VAR_P (base))
13576 : {
13577 66039 : if (*sam != special_array_member::int_0)
13578 : return NULL_TREE;
13579 :
13580 52 : if (TREE_CODE (arg) != COMPONENT_REF)
13581 : return NULL_TREE;
13582 :
13583 : base = arg;
13584 6 : while (TREE_CODE (base) == COMPONENT_REF)
13585 3 : base = TREE_OPERAND (base, 0);
13586 3 : baseoff = tree_to_poly_int64 (byte_position (TREE_OPERAND (ref, 1)));
13587 : }
13588 :
13589 : /* BASE is the declared object of which MEMBER is either a member
13590 : or that is cast to ARGTYPE (e.g., a char buffer used to store
13591 : an ARGTYPE object). */
13592 3285 : tree basetype = TREE_TYPE (base);
13593 :
13594 : /* Determine the base type of the referenced object. If it's
13595 : the same as ARGTYPE and MEMBER has a known size, return it. */
13596 3285 : tree bt = basetype;
13597 3285 : if (*sam != special_array_member::int_0)
13598 3286 : while (TREE_CODE (bt) == ARRAY_TYPE)
13599 222 : bt = TREE_TYPE (bt);
13600 3285 : bool typematch = useless_type_conversion_p (argtype, bt);
13601 3285 : if (memsize && typematch)
13602 : return memsize;
13603 :
13604 3195 : memsize = NULL_TREE;
13605 :
13606 3195 : if (typematch)
13607 : /* MEMBER is a true flexible array member. Compute its size from
13608 : the initializer of the BASE object if it has one. */
13609 2697 : if (tree init = DECL_P (base) ? DECL_INITIAL (base) : NULL_TREE)
13610 1300 : if (init != error_mark_node)
13611 : {
13612 1267 : init = get_initializer_for (init, member);
13613 1267 : if (init)
13614 : {
13615 889 : memsize = TYPE_SIZE_UNIT (TREE_TYPE (init));
13616 889 : if (tree refsize = TYPE_SIZE_UNIT (argtype))
13617 : {
13618 : /* Use the larger of the initializer size and the tail
13619 : padding in the enclosing struct. */
13620 889 : poly_int64 rsz = tree_to_poly_int64 (refsize);
13621 889 : rsz -= baseoff;
13622 889 : if (known_lt (tree_to_poly_int64 (memsize), rsz))
13623 56 : memsize = wide_int_to_tree (TREE_TYPE (memsize), rsz);
13624 : }
13625 :
13626 889 : baseoff = 0;
13627 : }
13628 : }
13629 :
13630 889 : if (!memsize)
13631 : {
13632 2306 : if (typematch)
13633 : {
13634 1808 : if (DECL_P (base)
13635 1808 : && DECL_EXTERNAL (base)
13636 454 : && bt == basetype
13637 2256 : && *sam != special_array_member::int_0)
13638 : /* The size of a flexible array member of an extern struct
13639 : with no initializer cannot be determined (it's defined
13640 : in another translation unit and can have an initializer
13641 : with an arbitrary number of elements). */
13642 : return NULL_TREE;
13643 :
13644 : /* Use the size of the base struct or, for interior zero-length
13645 : arrays, the size of the enclosing type. */
13646 1383 : memsize = TYPE_SIZE_UNIT (bt);
13647 : }
13648 498 : else if (DECL_P (base))
13649 : /* Use the size of the BASE object (possibly an array of some
13650 : other type such as char used to store the struct). */
13651 495 : memsize = DECL_SIZE_UNIT (base);
13652 : else
13653 : return NULL_TREE;
13654 : }
13655 :
13656 : /* If the flexible array member has a known size use the greater
13657 : of it and the tail padding in the enclosing struct.
13658 : Otherwise, when the size of the flexible array member is unknown
13659 : and the referenced object is not a struct, use the size of its
13660 : type when known. This detects sizes of array buffers when cast
13661 : to struct types with flexible array members. */
13662 1878 : if (memsize)
13663 : {
13664 2742 : if (!tree_fits_poly_int64_p (memsize))
13665 : return NULL_TREE;
13666 2742 : poly_int64 memsz64 = memsize ? tree_to_poly_int64 (memsize) : 0;
13667 2742 : if (known_lt (baseoff, memsz64))
13668 : {
13669 1275 : memsz64 -= baseoff;
13670 1275 : return wide_int_to_tree (TREE_TYPE (memsize), memsz64);
13671 : }
13672 1467 : return size_zero_node;
13673 : }
13674 :
13675 : /* Return "don't know" for an external non-array object since its
13676 : flexible array member can be initialized to have any number of
13677 : elements. Otherwise, return zero because the flexible array
13678 : member has no elements. */
13679 25 : return (DECL_P (base)
13680 25 : && DECL_EXTERNAL (base)
13681 25 : && (!typematch
13682 0 : || TREE_CODE (basetype) != ARRAY_TYPE)
13683 25 : ? NULL_TREE : size_zero_node);
13684 : }
13685 :
13686 : /* Return true if the given node CALL is a call to a .ACCESS_WITH_SIZE
13687 : function. */
13688 : bool
13689 93524070 : is_access_with_size_p (const_tree call)
13690 : {
13691 93524070 : if (TREE_CODE (call) != CALL_EXPR)
13692 : return false;
13693 41665551 : if (CALL_EXPR_IFN (call) == IFN_ACCESS_WITH_SIZE)
13694 629 : return true;
13695 : return false;
13696 : }
13697 :
13698 : /* Get the corresponding reference from the call to a .ACCESS_WITH_SIZE.
13699 : * i.e the first argument of this call. Return NULL_TREE otherwise. */
13700 : tree
13701 2 : get_ref_from_access_with_size (tree call)
13702 : {
13703 2 : if (is_access_with_size_p (call))
13704 2 : return CALL_EXPR_ARG (call, 0);
13705 : return NULL_TREE;
13706 : }
13707 :
13708 : /* Return the machine mode of T. For vectors, returns the mode of the
13709 : inner type. The main use case is to feed the result to HONOR_NANS,
13710 : avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
13711 :
13712 : machine_mode
13713 6219218438 : element_mode (const_tree t)
13714 : {
13715 6219218438 : if (!TYPE_P (t))
13716 204669684 : t = TREE_TYPE (t);
13717 6219218438 : if (VECTOR_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
13718 1513874515 : t = TREE_TYPE (t);
13719 6219218438 : return TYPE_MODE (t);
13720 : }
13721 :
13722 : /* Vector types need to re-check the target flags each time we report
13723 : the machine mode. We need to do this because attribute target can
13724 : change the result of vector_mode_supported_p and have_regs_of_mode
13725 : on a per-function basis. Thus the TYPE_MODE of a VECTOR_TYPE can
13726 : change on a per-function basis. */
13727 : /* ??? Possibly a better solution is to run through all the types
13728 : referenced by a function and re-compute the TYPE_MODE once, rather
13729 : than make the TYPE_MODE macro call a function. */
13730 :
13731 : machine_mode
13732 1323447428 : vector_type_mode (const_tree t)
13733 : {
13734 1323447428 : machine_mode mode;
13735 :
13736 1323447428 : gcc_assert (TREE_CODE (t) == VECTOR_TYPE);
13737 :
13738 1323447428 : mode = t->type_common.mode;
13739 303909811 : if (VECTOR_MODE_P (mode)
13740 1590258031 : && (!targetm.vector_mode_supported_p (mode)
13741 1264241969 : || !have_regs_of_mode[mode]))
13742 : {
13743 23009478 : scalar_int_mode innermode;
13744 :
13745 : /* For integers, try mapping it to a same-sized scalar mode. */
13746 23009478 : if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode))
13747 : {
13748 34365662 : poly_int64 size = (TYPE_VECTOR_SUBPARTS (t)
13749 17182831 : * GET_MODE_BITSIZE (innermode));
13750 17182831 : scalar_int_mode mode;
13751 31049696 : if (int_mode_for_size (size, 0).exists (&mode)
13752 13920640 : && have_regs_of_mode[mode])
13753 53775 : return mode;
13754 : }
13755 :
13756 22955703 : return BLKmode;
13757 : }
13758 :
13759 : return mode;
13760 : }
13761 :
13762 : /* Return the size in bits of each element of vector type TYPE. */
13763 :
13764 : unsigned int
13765 255258 : vector_element_bits (const_tree type)
13766 : {
13767 255258 : gcc_checking_assert (VECTOR_TYPE_P (type));
13768 255258 : if (VECTOR_BOOLEAN_TYPE_P (type))
13769 1032 : return TYPE_PRECISION (TREE_TYPE (type));
13770 254226 : return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
13771 : }
13772 :
13773 : /* Calculate the size in bits of each element of vector type TYPE
13774 : and return the result as a tree of type bitsizetype. */
13775 :
13776 : tree
13777 110776 : vector_element_bits_tree (const_tree type)
13778 : {
13779 110776 : gcc_checking_assert (VECTOR_TYPE_P (type));
13780 110776 : if (VECTOR_BOOLEAN_TYPE_P (type))
13781 600 : return bitsize_int (vector_element_bits (type));
13782 110176 : return TYPE_SIZE (TREE_TYPE (type));
13783 : }
13784 :
13785 : /* Verify that basic properties of T match TV and thus T can be a variant of
13786 : TV. TV should be the more specified variant (i.e. the main variant). */
13787 :
13788 : static bool
13789 206044640 : verify_type_variant (const_tree t, tree tv)
13790 : {
13791 : /* Type variant can differ by:
13792 :
13793 : - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
13794 : ENCODE_QUAL_ADDR_SPACE.
13795 : - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
13796 : in this case some values may not be set in the variant types
13797 : (see TYPE_COMPLETE_P checks).
13798 : - it is possible to have TYPE_ARTIFICIAL variant of non-artifical type
13799 : - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
13800 : - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
13801 : - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
13802 : - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
13803 : this is necessary to make it possible to merge types form different TUs
13804 : - arrays, pointers and references may have TREE_TYPE that is a variant
13805 : of TREE_TYPE of their main variants.
13806 : - aggregates may have new TYPE_FIELDS list that list variants of
13807 : the main variant TYPE_FIELDS.
13808 : - vector types may differ by TYPE_VECTOR_OPAQUE
13809 : */
13810 :
13811 : /* Convenience macro for matching individual fields. */
13812 : #define verify_variant_match(flag) \
13813 : do { \
13814 : if (flag (tv) != flag (t)) \
13815 : { \
13816 : error ("type variant differs by %s", #flag); \
13817 : debug_tree (tv); \
13818 : return false; \
13819 : } \
13820 : } while (false)
13821 :
13822 : /* tree_base checks. */
13823 :
13824 206044640 : verify_variant_match (TREE_CODE);
13825 : /* FIXME: Ada builds non-artificial variants of artificial types. */
13826 : #if 0
13827 : if (TYPE_ARTIFICIAL (tv))
13828 : verify_variant_match (TYPE_ARTIFICIAL);
13829 : #endif
13830 206044640 : if (POINTER_TYPE_P (tv))
13831 13128858 : verify_variant_match (TYPE_REF_CAN_ALIAS_ALL);
13832 : /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
13833 206044640 : verify_variant_match (TYPE_UNSIGNED);
13834 206044640 : verify_variant_match (TYPE_PACKED);
13835 206044640 : if (TREE_CODE (t) == REFERENCE_TYPE)
13836 3373742 : verify_variant_match (TYPE_REF_IS_RVALUE);
13837 206044640 : if (AGGREGATE_TYPE_P (t))
13838 85134941 : verify_variant_match (TYPE_REVERSE_STORAGE_ORDER);
13839 : else
13840 120909699 : verify_variant_match (TYPE_SATURATING);
13841 : /* FIXME: This check trigger during libstdc++ build. */
13842 : #if 0
13843 : if (RECORD_OR_UNION_TYPE_P (t) && COMPLETE_TYPE_P (t))
13844 : verify_variant_match (TYPE_FINAL_P);
13845 : #endif
13846 :
13847 : /* tree_type_common checks. */
13848 :
13849 206044640 : if (COMPLETE_TYPE_P (t))
13850 : {
13851 194389632 : verify_variant_match (TYPE_MODE);
13852 194389632 : if (TREE_CODE (TYPE_SIZE (t)) != PLACEHOLDER_EXPR
13853 194389632 : && TREE_CODE (TYPE_SIZE (tv)) != PLACEHOLDER_EXPR)
13854 194389632 : verify_variant_match (TYPE_SIZE);
13855 194389632 : if (TREE_CODE (TYPE_SIZE_UNIT (t)) != PLACEHOLDER_EXPR
13856 194389632 : && TREE_CODE (TYPE_SIZE_UNIT (tv)) != PLACEHOLDER_EXPR
13857 388779264 : && TYPE_SIZE_UNIT (t) != TYPE_SIZE_UNIT (tv))
13858 : {
13859 0 : gcc_assert (!operand_equal_p (TYPE_SIZE_UNIT (t),
13860 : TYPE_SIZE_UNIT (tv), 0));
13861 0 : error ("type variant has different %<TYPE_SIZE_UNIT%>");
13862 0 : debug_tree (tv);
13863 0 : error ("type variant%'s %<TYPE_SIZE_UNIT%>");
13864 0 : debug_tree (TYPE_SIZE_UNIT (tv));
13865 0 : error ("type%'s %<TYPE_SIZE_UNIT%>");
13866 0 : debug_tree (TYPE_SIZE_UNIT (t));
13867 0 : return false;
13868 : }
13869 194389632 : verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
13870 : }
13871 206044640 : verify_variant_match (TYPE_PRECISION_RAW);
13872 206044640 : if (RECORD_OR_UNION_TYPE_P (t))
13873 84507076 : verify_variant_match (TYPE_TRANSPARENT_AGGR);
13874 121537564 : else if (TREE_CODE (t) == ARRAY_TYPE)
13875 627865 : verify_variant_match (TYPE_NONALIASED_COMPONENT);
13876 : /* During LTO we merge variant lists from diferent translation units
13877 : that may differ BY TYPE_CONTEXT that in turn may point
13878 : to TRANSLATION_UNIT_DECL.
13879 : Ada also builds variants of types with different TYPE_CONTEXT. */
13880 : #if 0
13881 : if (!in_lto_p || !TYPE_FILE_SCOPE_P (t))
13882 : verify_variant_match (TYPE_CONTEXT);
13883 : #endif
13884 206044640 : if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == INTEGER_TYPE)
13885 60761366 : verify_variant_match (TYPE_STRING_FLAG);
13886 206044640 : if (TREE_CODE (t) == RECORD_TYPE || TREE_CODE (t) == UNION_TYPE)
13887 84507076 : verify_variant_match (TYPE_CXX_ODR_P);
13888 206044640 : if (TYPE_ALIAS_SET_KNOWN_P (t))
13889 : {
13890 0 : error ("type variant with %<TYPE_ALIAS_SET_KNOWN_P%>");
13891 0 : debug_tree (tv);
13892 0 : return false;
13893 : }
13894 :
13895 : /* tree_type_non_common checks. */
13896 :
13897 : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
13898 : and dangle the pointer from time to time. */
13899 84507076 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_VFIELD (t) != TYPE_VFIELD (tv)
13900 206044640 : && (in_lto_p || !TYPE_VFIELD (tv)
13901 0 : || TREE_CODE (TYPE_VFIELD (tv)) != TREE_LIST))
13902 : {
13903 0 : error ("type variant has different %<TYPE_VFIELD%>");
13904 0 : debug_tree (tv);
13905 0 : return false;
13906 : }
13907 3668427 : if ((TREE_CODE (t) == ENUMERAL_TYPE && COMPLETE_TYPE_P (t))
13908 202376270 : || TREE_CODE (t) == INTEGER_TYPE
13909 142242769 : || TREE_CODE (t) == BOOLEAN_TYPE
13910 100746594 : || TREE_CODE (t) == BITINT_TYPE
13911 100746436 : || SCALAR_FLOAT_TYPE_P (t)
13912 305011597 : || FIXED_POINT_TYPE_P (t))
13913 : {
13914 107077683 : verify_variant_match (TYPE_MAX_VALUE);
13915 107077683 : verify_variant_match (TYPE_MIN_VALUE);
13916 : }
13917 206044640 : if (TREE_CODE (t) == METHOD_TYPE)
13918 11075 : verify_variant_match (TYPE_METHOD_BASETYPE);
13919 206044640 : if (TREE_CODE (t) == OFFSET_TYPE)
13920 862 : verify_variant_match (TYPE_OFFSET_BASETYPE);
13921 206044640 : if (TREE_CODE (t) == ARRAY_TYPE)
13922 627865 : verify_variant_match (TYPE_ARRAY_MAX_SIZE);
13923 : /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
13924 : or even type's main variant. This is needed to make bootstrap pass
13925 : and the bug seems new in GCC 5.
13926 : C++ FE should be updated to make this consistent and we should check
13927 : that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
13928 : is a match with main variant.
13929 :
13930 : Also disable the check for Java for now because of parser hack that builds
13931 : first an dummy BINFO and then sometimes replace it by real BINFO in some
13932 : of the copies. */
13933 84507076 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t) && TYPE_BINFO (tv)
13934 72675309 : && TYPE_BINFO (t) != TYPE_BINFO (tv)
13935 : /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
13936 : Since there is no cheap way to tell C++/Java type w/o LTO, do checking
13937 : at LTO time only. */
13938 206044640 : && (in_lto_p && odr_type_p (t)))
13939 : {
13940 0 : error ("type variant has different %<TYPE_BINFO%>");
13941 0 : debug_tree (tv);
13942 0 : error ("type variant%'s %<TYPE_BINFO%>");
13943 0 : debug_tree (TYPE_BINFO (tv));
13944 0 : error ("type%'s %<TYPE_BINFO%>");
13945 0 : debug_tree (TYPE_BINFO (t));
13946 0 : return false;
13947 : }
13948 :
13949 : /* Check various uses of TYPE_VALUES_RAW. */
13950 206044640 : if (TREE_CODE (t) == ENUMERAL_TYPE
13951 206044640 : && TYPE_VALUES (t))
13952 3505443 : verify_variant_match (TYPE_VALUES);
13953 202539197 : else if (TREE_CODE (t) == ARRAY_TYPE)
13954 627865 : verify_variant_match (TYPE_DOMAIN);
13955 : /* Permit incomplete variants of complete type. While FEs may complete
13956 : all variants, this does not happen for C++ templates in all cases. */
13957 201911332 : else if (RECORD_OR_UNION_TYPE_P (t)
13958 84507076 : && COMPLETE_TYPE_P (t)
13959 274984008 : && TYPE_FIELDS (t) != TYPE_FIELDS (tv))
13960 : {
13961 3822 : tree f1, f2;
13962 :
13963 : /* Fortran builds qualified variants as new records with items of
13964 : qualified type. Verify that they looks same. */
13965 3822 : for (f1 = TYPE_FIELDS (t), f2 = TYPE_FIELDS (tv);
13966 12391 : f1 && f2;
13967 8569 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
13968 8569 : if (TREE_CODE (f1) != FIELD_DECL || TREE_CODE (f2) != FIELD_DECL
13969 8569 : || (TYPE_MAIN_VARIANT (TREE_TYPE (f1))
13970 8569 : != TYPE_MAIN_VARIANT (TREE_TYPE (f2))
13971 : /* FIXME: gfc_nonrestricted_type builds all types as variants
13972 : with exception of pointer types. It deeply copies the type
13973 : which means that we may end up with a variant type
13974 : referring non-variant pointer. We may change it to
13975 : produce types as variants, too, like
13976 : objc_get_protocol_qualified_type does. */
13977 21 : && !POINTER_TYPE_P (TREE_TYPE (f1)))
13978 8569 : || DECL_FIELD_OFFSET (f1) != DECL_FIELD_OFFSET (f2)
13979 17138 : || DECL_FIELD_BIT_OFFSET (f1) != DECL_FIELD_BIT_OFFSET (f2))
13980 : break;
13981 3822 : if (f1 || f2)
13982 : {
13983 0 : error ("type variant has different %<TYPE_FIELDS%>");
13984 0 : debug_tree (tv);
13985 0 : error ("first mismatch is field");
13986 0 : debug_tree (f1);
13987 0 : error ("and field");
13988 0 : debug_tree (f2);
13989 0 : return false;
13990 : }
13991 : }
13992 201907510 : else if (FUNC_OR_METHOD_TYPE_P (t))
13993 146353 : verify_variant_match (TYPE_ARG_TYPES);
13994 : /* For C++ the qualified variant of array type is really an array type
13995 : of qualified TREE_TYPE.
13996 : objc builds variants of pointer where pointer to type is a variant, too
13997 : in objc_get_protocol_qualified_type. */
13998 206044640 : if (TREE_TYPE (t) != TREE_TYPE (tv)
13999 206044640 : && ((TREE_CODE (t) != ARRAY_TYPE
14000 0 : && !POINTER_TYPE_P (t))
14001 531446 : || TYPE_MAIN_VARIANT (TREE_TYPE (t))
14002 531446 : != TYPE_MAIN_VARIANT (TREE_TYPE (tv))))
14003 : {
14004 0 : error ("type variant has different %<TREE_TYPE%>");
14005 0 : debug_tree (tv);
14006 0 : error ("type variant%'s %<TREE_TYPE%>");
14007 0 : debug_tree (TREE_TYPE (tv));
14008 0 : error ("type%'s %<TREE_TYPE%>");
14009 0 : debug_tree (TREE_TYPE (t));
14010 0 : return false;
14011 : }
14012 206044640 : if (type_with_alias_set_p (t)
14013 206044640 : && !gimple_canonical_types_compatible_p (t, tv, false))
14014 : {
14015 0 : error ("type is not compatible with its variant");
14016 0 : debug_tree (tv);
14017 0 : error ("type variant%'s %<TREE_TYPE%>");
14018 0 : debug_tree (TREE_TYPE (tv));
14019 0 : error ("type%'s %<TREE_TYPE%>");
14020 0 : debug_tree (TREE_TYPE (t));
14021 0 : return false;
14022 : }
14023 : return true;
14024 : #undef verify_variant_match
14025 : }
14026 :
14027 :
14028 : /* The TYPE_CANONICAL merging machinery. It should closely resemble
14029 : the middle-end types_compatible_p function. It needs to avoid
14030 : claiming types are different for types that should be treated
14031 : the same with respect to TBAA. Canonical types are also used
14032 : for IL consistency checks via the useless_type_conversion_p
14033 : predicate which does not handle all type kinds itself but falls
14034 : back to pointer-comparison of TYPE_CANONICAL for aggregates
14035 : for example. */
14036 :
14037 : /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
14038 : type calculation because we need to allow inter-operability between signed
14039 : and unsigned variants. */
14040 :
14041 : bool
14042 1653885 : type_with_interoperable_signedness (const_tree type)
14043 : {
14044 : /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
14045 : signed char and unsigned char. Similarly fortran FE builds
14046 : C_SIZE_T as signed type, while C defines it unsigned. */
14047 :
14048 1653885 : return tree_code_for_canonical_type_merging (TREE_CODE (type))
14049 : == INTEGER_TYPE
14050 1653684 : && (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)
14051 447179 : || TYPE_PRECISION (type) == TYPE_PRECISION (size_type_node));
14052 : }
14053 :
14054 : /* Return true iff T1 and T2 are structurally identical for what
14055 : TBAA is concerned.
14056 : This function is used both by lto.cc canonical type merging and by the
14057 : verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
14058 : that have TYPE_CANONICAL defined and assume them equivalent. This is useful
14059 : only for LTO because only in these cases TYPE_CANONICAL equivalence
14060 : correspond to one defined by gimple_canonical_types_compatible_p. */
14061 :
14062 : bool
14063 417739692 : gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
14064 : bool trust_type_canonical)
14065 : {
14066 : /* Type variants should be same as the main variant. When not doing sanity
14067 : checking to verify this fact, go to main variants and save some work. */
14068 417739692 : if (trust_type_canonical)
14069 : {
14070 885327 : t1 = TYPE_MAIN_VARIANT (t1);
14071 885327 : t2 = TYPE_MAIN_VARIANT (t2);
14072 : }
14073 :
14074 : /* Check first for the obvious case of pointer identity. */
14075 417739692 : if (t1 == t2)
14076 : return true;
14077 :
14078 : /* Check that we have two types to compare. */
14079 351928791 : if (t1 == NULL_TREE || t2 == NULL_TREE)
14080 : return false;
14081 :
14082 : /* We consider complete types always compatible with incomplete type.
14083 : This does not make sense for canonical type calculation and thus we
14084 : need to ensure that we are never called on it.
14085 :
14086 : FIXME: For more correctness the function probably should have three modes
14087 : 1) mode assuming that types are complete mathcing their structure
14088 : 2) mode allowing incomplete types but producing equivalence classes
14089 : and thus ignoring all info from complete types
14090 : 3) mode allowing incomplete types to match complete but checking
14091 : compatibility between complete types.
14092 :
14093 : 1 and 2 can be used for canonical type calculation. 3 is the real
14094 : definition of type compatibility that can be used i.e. for warnings during
14095 : declaration merging. */
14096 :
14097 351928791 : gcc_assert (!trust_type_canonical
14098 : || (type_with_alias_set_p (t1) && type_with_alias_set_p (t2)));
14099 :
14100 : /* If the types have been previously registered and found equal
14101 : they still are. */
14102 :
14103 703623307 : if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t2)
14104 702823174 : && trust_type_canonical)
14105 : {
14106 : /* Do not use TYPE_CANONICAL of pointer types. For LTO streamed types
14107 : they are always NULL, but they are set to non-NULL for types
14108 : constructed by build_pointer_type and variants. In this case the
14109 : TYPE_CANONICAL is more fine grained than the equivalnce we test (where
14110 : all pointers are considered equal. Be sure to not return false
14111 : negatives. */
14112 163340 : gcc_checking_assert (canonical_type_used_p (t1)
14113 : && canonical_type_used_p (t2));
14114 81670 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
14115 : }
14116 :
14117 : /* For types where we do ODR based TBAA the canonical type is always
14118 : set correctly, so we know that types are different if their
14119 : canonical types does not match. */
14120 351847121 : if (trust_type_canonical
14121 352647773 : && (odr_type_p (t1) && odr_based_tbaa_p (t1))
14122 800652 : != (odr_type_p (t2) && odr_based_tbaa_p (t2)))
14123 : return false;
14124 :
14125 : /* Can't be the same type if the types don't have the same code. */
14126 351847121 : enum tree_code code = tree_code_for_canonical_type_merging (TREE_CODE (t1));
14127 699355410 : if (code != tree_code_for_canonical_type_merging (TREE_CODE (t2)))
14128 : return false;
14129 :
14130 : /* Qualifiers do not matter for canonical type comparison purposes. */
14131 :
14132 : /* Void types and nullptr types are always the same. */
14133 351847086 : if (VOID_TYPE_P (t1)
14134 351801486 : || TREE_CODE (t1) == NULLPTR_TYPE)
14135 : return true;
14136 :
14137 : /* Can't be compatible types if they have different mode. Because of
14138 : flexible array members, we allow mismatching modes for structures or
14139 : unions. */
14140 351176724 : if (!RECORD_OR_UNION_TYPE_P (t1)
14141 351176724 : && TREE_CODE (t1) != ARRAY_TYPE
14142 351176724 : && TYPE_MODE (t1) != TYPE_MODE (t2))
14143 : return false;
14144 :
14145 : /* Non-aggregate types can be handled cheaply. */
14146 351176724 : if (INTEGRAL_TYPE_P (t1)
14147 351176724 : || SCALAR_FLOAT_TYPE_P (t1)
14148 188417339 : || FIXED_POINT_TYPE_P (t1)
14149 188050283 : || VECTOR_TYPE_P (t1)
14150 188025904 : || TREE_CODE (t1) == COMPLEX_TYPE
14151 187689750 : || TREE_CODE (t1) == OFFSET_TYPE
14152 187687802 : || POINTER_TYPE_P (t1))
14153 : {
14154 : /* Can't be the same type if they have different precision. */
14155 206088888 : if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
14156 : return false;
14157 :
14158 : /* In some cases the signed and unsigned types are required to be
14159 : inter-operable. */
14160 206088888 : if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)
14161 206088888 : && !type_with_interoperable_signedness (t1))
14162 : return false;
14163 :
14164 : /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
14165 : interoperable with "signed char". Unless all frontends are revisited
14166 : to agree on these types, we must ignore the flag completely. */
14167 :
14168 : /* Fortran standard define C_PTR type that is compatible with every
14169 : C pointer. For this reason we need to glob all pointers into one.
14170 : Still pointers in different address spaces are not compatible. */
14171 206088888 : if (POINTER_TYPE_P (t1))
14172 : {
14173 42599966 : if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
14174 42599966 : != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
14175 : return false;
14176 : }
14177 :
14178 : /* Tail-recurse to components. */
14179 206088888 : if (VECTOR_TYPE_P (t1)
14180 206088888 : || TREE_CODE (t1) == COMPLEX_TYPE)
14181 360533 : return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
14182 360533 : TREE_TYPE (t2),
14183 360533 : trust_type_canonical);
14184 :
14185 : return true;
14186 : }
14187 :
14188 : /* Do type-specific comparisons. */
14189 145087836 : switch (TREE_CODE (t1))
14190 : {
14191 1120322 : case ARRAY_TYPE:
14192 : /* Array types are the same if the element types are the same and
14193 : minimum and maximum index are the same. */
14194 1120322 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14195 : trust_type_canonical)
14196 1120283 : || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
14197 1120283 : || TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2)
14198 2240605 : || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
14199 : return false;
14200 : else
14201 : {
14202 1120283 : tree i1 = TYPE_DOMAIN (t1);
14203 1120283 : tree i2 = TYPE_DOMAIN (t2);
14204 :
14205 : /* For an incomplete external array, the type domain can be
14206 : NULL_TREE. Check this condition also. */
14207 1120283 : if (i1 == NULL_TREE && i2 == NULL_TREE)
14208 : return true;
14209 1002437 : else if (i1 == NULL_TREE || i2 == NULL_TREE)
14210 : return false;
14211 : else
14212 : {
14213 1002437 : tree min1 = TYPE_MIN_VALUE (i1);
14214 1002437 : tree min2 = TYPE_MIN_VALUE (i2);
14215 1002437 : tree max1 = TYPE_MAX_VALUE (i1);
14216 1002437 : tree max2 = TYPE_MAX_VALUE (i2);
14217 :
14218 : /* The minimum/maximum values have to be the same. */
14219 1002437 : if ((min1 == min2
14220 0 : || (min1 && min2
14221 0 : && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
14222 0 : && TREE_CODE (min2) == PLACEHOLDER_EXPR)
14223 0 : || operand_equal_p (min1, min2, 0))))
14224 1002437 : && (max1 == max2
14225 0 : || (max1 && max2
14226 0 : && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
14227 0 : && TREE_CODE (max2) == PLACEHOLDER_EXPR)
14228 0 : || operand_equal_p (max1, max2, 0)))))
14229 1002437 : return true;
14230 : else
14231 0 : return false;
14232 : }
14233 : }
14234 :
14235 6945 : case METHOD_TYPE:
14236 6945 : case FUNCTION_TYPE:
14237 : /* Function types are the same if the return type and arguments types
14238 : are the same. */
14239 6945 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14240 : trust_type_canonical))
14241 : return false;
14242 :
14243 6945 : if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)
14244 6945 : && (TYPE_NO_NAMED_ARGS_STDARG_P (t1)
14245 320 : == TYPE_NO_NAMED_ARGS_STDARG_P (t2)))
14246 : return true;
14247 : else
14248 : {
14249 6625 : tree parms1, parms2;
14250 :
14251 6625 : for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
14252 29319 : parms1 && parms2;
14253 22694 : parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
14254 : {
14255 22694 : if (!gimple_canonical_types_compatible_p
14256 22694 : (TREE_VALUE (parms1), TREE_VALUE (parms2),
14257 : trust_type_canonical))
14258 : return false;
14259 : }
14260 :
14261 6625 : if (parms1 || parms2)
14262 : return false;
14263 :
14264 : return true;
14265 : }
14266 :
14267 142992558 : case RECORD_TYPE:
14268 142992558 : case UNION_TYPE:
14269 142992558 : case QUAL_UNION_TYPE:
14270 142992558 : {
14271 142992558 : tree f1, f2;
14272 :
14273 : /* Don't try to compare variants of an incomplete type, before
14274 : TYPE_FIELDS has been copied around. */
14275 142992558 : if (!COMPLETE_TYPE_P (t1) && !COMPLETE_TYPE_P (t2))
14276 : return true;
14277 :
14278 :
14279 132287186 : if (TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2))
14280 : return false;
14281 :
14282 : /* For aggregate types, all the fields must be the same. */
14283 132287186 : for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
14284 197628459 : f1 || f2;
14285 65341273 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
14286 : {
14287 : /* Skip non-fields and zero-sized fields, except zero-sized
14288 : arrays at the end. */
14289 1920632547 : while (f1 && (TREE_CODE (f1) != FIELD_DECL
14290 119545508 : || (DECL_SIZE (f1)
14291 119530294 : && integer_zerop (DECL_SIZE (f1))
14292 54204212 : && (TREE_CHAIN (f1)
14293 2870 : || TREE_CODE (TREE_TYPE (f1))
14294 : != ARRAY_TYPE))))
14295 1724041249 : f1 = TREE_CHAIN (f1);
14296 1920634048 : while (f2 && (TREE_CODE (f2) != FIELD_DECL
14297 119559630 : || (DECL_SIZE (f2)
14298 119544308 : && integer_zerop (DECL_SIZE (f2))
14299 54205718 : && (TREE_CHAIN (f2)
14300 3883 : || TREE_CODE (TREE_TYPE (f2))
14301 : != ARRAY_TYPE))))
14302 1724042750 : f2 = TREE_CHAIN (f2);
14303 196591298 : if (!f1 || !f2)
14304 : break;
14305 :
14306 65341500 : tree t1 = TREE_TYPE (f1);
14307 65341500 : tree t2 = TREE_TYPE (f2);
14308 :
14309 : /* If the last element are arrays, we only compare the element
14310 : types. */
14311 66368732 : if (TREE_CHAIN (f1) == NULL_TREE && TREE_CODE (t1) == ARRAY_TYPE
14312 65409977 : && TREE_CHAIN (f2) == NULL_TREE && TREE_CODE (t2) == ARRAY_TYPE)
14313 : {
14314 : /* If both arrays have zero size, this is a match. */
14315 122148 : if (DECL_SIZE (f1) && integer_zerop (DECL_SIZE (f1))
14316 68676 : && DECL_SIZE (f2) && integer_zerop (DECL_SIZE (f2)))
14317 : return true;
14318 :
14319 68269 : t1 = TREE_TYPE (t1);
14320 68269 : t2 = TREE_TYPE (t2);
14321 : }
14322 :
14323 65341297 : if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
14324 65341292 : || !gimple_compare_field_offset (f1, f2)
14325 130682589 : || !gimple_canonical_types_compatible_p
14326 65341292 : (t1, t2, trust_type_canonical))
14327 24 : return false;
14328 : }
14329 :
14330 : /* If one aggregate has more fields than the other, they
14331 : are not the same. */
14332 132286959 : if (f1 || f2)
14333 : return false;
14334 :
14335 : return true;
14336 : }
14337 :
14338 968011 : default:
14339 : /* Consider all types with language specific trees in them mutually
14340 : compatible. This is executed only from verify_type and false
14341 : positives can be tolerated. */
14342 968011 : gcc_assert (!in_lto_p);
14343 : return true;
14344 : }
14345 : }
14346 :
14347 : /* For OPAQUE_TYPE T, it should have only size and alignment information
14348 : and its mode should be of class MODE_OPAQUE. This function verifies
14349 : these properties of T match TV which is the main variant of T and TC
14350 : which is the canonical of T. */
14351 :
14352 : static void
14353 0 : verify_opaque_type (const_tree t, tree tv, tree tc)
14354 : {
14355 0 : gcc_assert (OPAQUE_TYPE_P (t));
14356 0 : gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv));
14357 0 : gcc_assert (tc && tc == TYPE_CANONICAL (tc));
14358 :
14359 : /* For an opaque type T1, check if some of its properties match
14360 : the corresponding ones of the other opaque type T2, emit some
14361 : error messages for those inconsistent ones. */
14362 0 : auto check_properties_for_opaque_type = [](const_tree t1, tree t2,
14363 : const char *kind_msg)
14364 : {
14365 0 : if (!OPAQUE_TYPE_P (t2))
14366 : {
14367 0 : error ("type %s is not an opaque type", kind_msg);
14368 0 : debug_tree (t2);
14369 0 : return;
14370 : }
14371 0 : if (!OPAQUE_MODE_P (TYPE_MODE (t2)))
14372 : {
14373 0 : error ("type %s is not with opaque mode", kind_msg);
14374 0 : debug_tree (t2);
14375 0 : return;
14376 : }
14377 0 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
14378 : {
14379 0 : error ("type %s differs by %<TYPE_MODE%>", kind_msg);
14380 0 : debug_tree (t2);
14381 0 : return;
14382 : }
14383 0 : poly_uint64 t1_size = tree_to_poly_uint64 (TYPE_SIZE (t1));
14384 0 : poly_uint64 t2_size = tree_to_poly_uint64 (TYPE_SIZE (t2));
14385 0 : if (maybe_ne (t1_size, t2_size))
14386 : {
14387 0 : error ("type %s differs by %<TYPE_SIZE%>", kind_msg);
14388 0 : debug_tree (t2);
14389 0 : return;
14390 : }
14391 0 : if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2))
14392 : {
14393 0 : error ("type %s differs by %<TYPE_ALIGN%>", kind_msg);
14394 0 : debug_tree (t2);
14395 0 : return;
14396 : }
14397 0 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
14398 : {
14399 0 : error ("type %s differs by %<TYPE_USER_ALIGN%>", kind_msg);
14400 0 : debug_tree (t2);
14401 0 : return;
14402 : }
14403 : };
14404 :
14405 0 : if (t != tv)
14406 0 : check_properties_for_opaque_type (t, tv, "variant");
14407 :
14408 0 : if (t != tc)
14409 0 : check_properties_for_opaque_type (t, tc, "canonical");
14410 0 : }
14411 :
14412 : /* Verify type T. */
14413 :
14414 : void
14415 937348096 : verify_type (const_tree t)
14416 : {
14417 937348096 : bool error_found = false;
14418 937348096 : tree mv = TYPE_MAIN_VARIANT (t);
14419 937348096 : tree ct = TYPE_CANONICAL (t);
14420 :
14421 937348096 : if (OPAQUE_TYPE_P (t))
14422 : {
14423 0 : verify_opaque_type (t, mv, ct);
14424 0 : return;
14425 : }
14426 :
14427 937348096 : if (!mv)
14428 : {
14429 0 : error ("main variant is not defined");
14430 0 : error_found = true;
14431 : }
14432 937348096 : else if (mv != TYPE_MAIN_VARIANT (mv))
14433 : {
14434 0 : error ("%<TYPE_MAIN_VARIANT%> has different %<TYPE_MAIN_VARIANT%>");
14435 0 : debug_tree (mv);
14436 0 : error_found = true;
14437 : }
14438 937348096 : else if (t != mv && !verify_type_variant (t, mv))
14439 : error_found = true;
14440 :
14441 937348096 : if (!ct)
14442 : ;
14443 935343644 : else if (TYPE_CANONICAL (ct) != ct)
14444 : {
14445 0 : error ("%<TYPE_CANONICAL%> has different %<TYPE_CANONICAL%>");
14446 0 : debug_tree (ct);
14447 0 : error_found = true;
14448 : }
14449 : /* Method and function types cannot be used to address memory and thus
14450 : TYPE_CANONICAL really matters only for determining useless conversions.
14451 :
14452 : FIXME: C++ FE produce declarations of builtin functions that are not
14453 : compatible with main variants. */
14454 935343644 : else if (TREE_CODE (t) == FUNCTION_TYPE)
14455 : ;
14456 934750460 : else if (t != ct
14457 : /* FIXME: gimple_canonical_types_compatible_p cannot compare types
14458 : with variably sized arrays because their sizes possibly
14459 : gimplified to different variables. */
14460 155734797 : && !variably_modified_type_p (ct, NULL)
14461 155730346 : && !gimple_canonical_types_compatible_p (t, ct, false)
14462 934763081 : && COMPLETE_TYPE_P (t))
14463 : {
14464 0 : error ("%<TYPE_CANONICAL%> is not compatible");
14465 0 : debug_tree (ct);
14466 0 : error_found = true;
14467 : }
14468 1698091269 : if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t)
14469 : /* We allow a mismatch for structure or union because of
14470 : flexible array members. */
14471 758806306 : && !RECORD_OR_UNION_TYPE_P (t)
14472 308416101 : && !RECORD_OR_UNION_TYPE_P (TYPE_CANONICAL (t))
14473 308416101 : && TREE_CODE (t) != ARRAY_TYPE
14474 1244271564 : && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
14475 : {
14476 0 : error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");
14477 0 : debug_tree (ct);
14478 0 : error_found = true;
14479 : }
14480 937348096 : if (TYPE_MAIN_VARIANT (t) == t && ct && TYPE_MAIN_VARIANT (ct) != ct)
14481 : {
14482 : /* This can happen when build_type_attribute_variant is called on
14483 : C/C++ arrays of qualified types. volatile int[2] is unqualified
14484 : ARRAY_TYPE with volatile int element type.
14485 : TYPE_CANONICAL (volatile int) is itself and so is
14486 : TYPE_CANONICAL (volatile int[2]). build_type_attribute_qual_variant
14487 : creates a distinct type copy (so TYPE_MAIN_VARIANT is itself) and sets
14488 : its TYPE_CANONICAL to the unqualified ARRAY_TYPE (so volatile int[2]).
14489 : But this is not the TYPE_MAIN_VARIANT, which is int[2]. So, just
14490 : verify that TYPE_MAIN_VARIANT (ct) is already the final type we
14491 : need. */
14492 2 : tree mvc = TYPE_MAIN_VARIANT (ct);
14493 2 : if (TYPE_CANONICAL (mvc) != mvc)
14494 : {
14495 0 : error ("main variant of %<TYPE_CANONICAL%> of main variant is not"
14496 : " its own %<TYPE_CANONICAL%>");
14497 0 : debug_tree (ct);
14498 0 : debug_tree (TYPE_MAIN_VARIANT (ct));
14499 0 : error_found = true;
14500 : }
14501 : }
14502 :
14503 :
14504 : /* Check various uses of TYPE_MIN_VALUE_RAW. */
14505 937348096 : if (RECORD_OR_UNION_TYPE_P (t))
14506 : {
14507 : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
14508 : and danagle the pointer from time to time. */
14509 497901046 : if (TYPE_VFIELD (t)
14510 14352446 : && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
14511 497901046 : && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
14512 : {
14513 0 : error ("%<TYPE_VFIELD%> is not %<FIELD_DECL%> nor %<TREE_LIST%>");
14514 0 : debug_tree (TYPE_VFIELD (t));
14515 0 : error_found = true;
14516 : }
14517 : }
14518 439447050 : else if (TREE_CODE (t) == POINTER_TYPE)
14519 : {
14520 112324450 : if (TYPE_NEXT_PTR_TO (t)
14521 112324450 : && TREE_CODE (TYPE_NEXT_PTR_TO (t)) != POINTER_TYPE)
14522 : {
14523 0 : error ("%<TYPE_NEXT_PTR_TO%> is not %<POINTER_TYPE%>");
14524 0 : debug_tree (TYPE_NEXT_PTR_TO (t));
14525 0 : error_found = true;
14526 : }
14527 : }
14528 327122600 : else if (TREE_CODE (t) == REFERENCE_TYPE)
14529 : {
14530 50423987 : if (TYPE_NEXT_REF_TO (t)
14531 50423987 : && TREE_CODE (TYPE_NEXT_REF_TO (t)) != REFERENCE_TYPE)
14532 : {
14533 0 : error ("%<TYPE_NEXT_REF_TO%> is not %<REFERENCE_TYPE%>");
14534 0 : debug_tree (TYPE_NEXT_REF_TO (t));
14535 0 : error_found = true;
14536 : }
14537 : }
14538 : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14539 : || FIXED_POINT_TYPE_P (t))
14540 : {
14541 : /* FIXME: The following check should pass:
14542 : useless_type_conversion_p (const_cast <tree> (t),
14543 : TREE_TYPE (TYPE_MIN_VALUE (t))
14544 : but does not for C sizetypes in LTO. */
14545 : }
14546 :
14547 : /* Check various uses of TYPE_MAXVAL_RAW. */
14548 937348096 : if (RECORD_OR_UNION_TYPE_P (t))
14549 : {
14550 497901046 : if (!TYPE_BINFO (t))
14551 : ;
14552 469421066 : else if (TREE_CODE (TYPE_BINFO (t)) != TREE_BINFO)
14553 : {
14554 0 : error ("%<TYPE_BINFO%> is not %<TREE_BINFO%>");
14555 0 : debug_tree (TYPE_BINFO (t));
14556 0 : error_found = true;
14557 : }
14558 469421066 : else if (TREE_TYPE (TYPE_BINFO (t)) != TYPE_MAIN_VARIANT (t))
14559 : {
14560 0 : error ("%<TYPE_BINFO%> type is not %<TYPE_MAIN_VARIANT%>");
14561 0 : debug_tree (TREE_TYPE (TYPE_BINFO (t)));
14562 0 : error_found = true;
14563 : }
14564 : }
14565 : else if (FUNC_OR_METHOD_TYPE_P (t))
14566 : {
14567 810008 : if (TYPE_METHOD_BASETYPE (t)
14568 66531 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != RECORD_TYPE
14569 810200 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != UNION_TYPE)
14570 : {
14571 0 : error ("%<TYPE_METHOD_BASETYPE%> is not record nor union");
14572 0 : debug_tree (TYPE_METHOD_BASETYPE (t));
14573 0 : error_found = true;
14574 : }
14575 : }
14576 : else if (TREE_CODE (t) == OFFSET_TYPE)
14577 : {
14578 32855 : if (TYPE_OFFSET_BASETYPE (t)
14579 32855 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != RECORD_TYPE
14580 32863 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != UNION_TYPE)
14581 : {
14582 0 : error ("%<TYPE_OFFSET_BASETYPE%> is not record nor union");
14583 0 : debug_tree (TYPE_OFFSET_BASETYPE (t));
14584 0 : error_found = true;
14585 : }
14586 : }
14587 : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14588 : || FIXED_POINT_TYPE_P (t))
14589 : {
14590 : /* FIXME: The following check should pass:
14591 : useless_type_conversion_p (const_cast <tree> (t),
14592 : TREE_TYPE (TYPE_MAX_VALUE (t))
14593 : but does not for C sizetypes in LTO. */
14594 : }
14595 : else if (TREE_CODE (t) == ARRAY_TYPE)
14596 : {
14597 1776671 : if (TYPE_ARRAY_MAX_SIZE (t)
14598 1776671 : && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t)) != INTEGER_CST)
14599 : {
14600 0 : error ("%<TYPE_ARRAY_MAX_SIZE%> not %<INTEGER_CST%>");
14601 0 : debug_tree (TYPE_ARRAY_MAX_SIZE (t));
14602 0 : error_found = true;
14603 : }
14604 : }
14605 293035455 : else if (TYPE_MAX_VALUE_RAW (t))
14606 : {
14607 0 : error ("%<TYPE_MAX_VALUE_RAW%> non-NULL");
14608 0 : debug_tree (TYPE_MAX_VALUE_RAW (t));
14609 0 : error_found = true;
14610 : }
14611 :
14612 937348096 : if (TYPE_LANG_SLOT_1 (t) && in_lto_p)
14613 : {
14614 0 : error ("%<TYPE_LANG_SLOT_1 (binfo)%> field is non-NULL");
14615 0 : debug_tree (TYPE_LANG_SLOT_1 (t));
14616 0 : error_found = true;
14617 : }
14618 :
14619 : /* Check various uses of TYPE_VALUES_RAW. */
14620 937348096 : if (TREE_CODE (t) == ENUMERAL_TYPE)
14621 102464151 : for (tree l = TYPE_VALUES (t); l; l = TREE_CHAIN (l))
14622 : {
14623 89038877 : tree value = TREE_VALUE (l);
14624 89038877 : tree name = TREE_PURPOSE (l);
14625 :
14626 : /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
14627 : CONST_DECL of ENUMERAL TYPE. */
14628 89038877 : if (TREE_CODE (value) != INTEGER_CST && TREE_CODE (value) != CONST_DECL)
14629 : {
14630 0 : error ("enum value is not %<CONST_DECL%> or %<INTEGER_CST%>");
14631 0 : debug_tree (value);
14632 0 : debug_tree (name);
14633 0 : error_found = true;
14634 : }
14635 89038877 : if (TREE_CODE (TREE_TYPE (value)) != INTEGER_TYPE
14636 89022289 : && TREE_CODE (TREE_TYPE (value)) != BOOLEAN_TYPE
14637 178061163 : && !useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (value)))
14638 : {
14639 0 : error ("enum value type is not %<INTEGER_TYPE%> nor convertible "
14640 : "to the enum");
14641 0 : debug_tree (value);
14642 0 : debug_tree (name);
14643 0 : error_found = true;
14644 : }
14645 89038877 : if (TREE_CODE (name) != IDENTIFIER_NODE)
14646 : {
14647 0 : error ("enum value name is not %<IDENTIFIER_NODE%>");
14648 0 : debug_tree (value);
14649 0 : debug_tree (name);
14650 0 : error_found = true;
14651 : }
14652 : }
14653 923922822 : else if (TREE_CODE (t) == ARRAY_TYPE)
14654 : {
14655 1776671 : if (TYPE_DOMAIN (t) && TREE_CODE (TYPE_DOMAIN (t)) != INTEGER_TYPE)
14656 : {
14657 0 : error ("array %<TYPE_DOMAIN%> is not integer type");
14658 0 : debug_tree (TYPE_DOMAIN (t));
14659 0 : error_found = true;
14660 : }
14661 : }
14662 922146151 : else if (RECORD_OR_UNION_TYPE_P (t))
14663 : {
14664 497901046 : if (TYPE_FIELDS (t) && !COMPLETE_TYPE_P (t) && in_lto_p)
14665 : {
14666 0 : error ("%<TYPE_FIELDS%> defined in incomplete type");
14667 0 : error_found = true;
14668 : }
14669 20069123523 : for (tree fld = TYPE_FIELDS (t); fld; fld = TREE_CHAIN (fld))
14670 : {
14671 : /* TODO: verify properties of decls. */
14672 19571222477 : if (TREE_CODE (fld) == FIELD_DECL)
14673 : ;
14674 : else if (TREE_CODE (fld) == TYPE_DECL)
14675 : ;
14676 : else if (TREE_CODE (fld) == CONST_DECL)
14677 : ;
14678 : else if (VAR_P (fld))
14679 : ;
14680 : else if (TREE_CODE (fld) == TEMPLATE_DECL)
14681 : ;
14682 : else if (TREE_CODE (fld) == USING_DECL)
14683 : ;
14684 : else if (TREE_CODE (fld) == FUNCTION_DECL)
14685 : ;
14686 : else
14687 : {
14688 0 : error ("wrong tree in %<TYPE_FIELDS%> list");
14689 0 : debug_tree (fld);
14690 0 : error_found = true;
14691 : }
14692 : }
14693 : }
14694 424245105 : else if (TREE_CODE (t) == INTEGER_TYPE
14695 : || TREE_CODE (t) == BOOLEAN_TYPE
14696 424245105 : || TREE_CODE (t) == BITINT_TYPE
14697 298842620 : || TREE_CODE (t) == OFFSET_TYPE
14698 298809765 : || TREE_CODE (t) == REFERENCE_TYPE
14699 248385778 : || TREE_CODE (t) == NULLPTR_TYPE
14700 248058257 : || TREE_CODE (t) == POINTER_TYPE)
14701 : {
14702 288511298 : if (TYPE_CACHED_VALUES_P (t) != (TYPE_CACHED_VALUES (t) != NULL))
14703 : {
14704 0 : error ("%<TYPE_CACHED_VALUES_P%> is %i while %<TYPE_CACHED_VALUES%> "
14705 : "is %p",
14706 0 : TYPE_CACHED_VALUES_P (t), (void *)TYPE_CACHED_VALUES (t));
14707 0 : error_found = true;
14708 : }
14709 288511298 : else if (TYPE_CACHED_VALUES_P (t) && TREE_CODE (TYPE_CACHED_VALUES (t)) != TREE_VEC)
14710 : {
14711 0 : error ("%<TYPE_CACHED_VALUES%> is not %<TREE_VEC%>");
14712 0 : debug_tree (TYPE_CACHED_VALUES (t));
14713 0 : error_found = true;
14714 : }
14715 : /* Verify just enough of cache to ensure that no one copied it to new type.
14716 : All copying should go by copy_node that should clear it. */
14717 288511298 : else if (TYPE_CACHED_VALUES_P (t))
14718 : {
14719 : int i;
14720 8442163493 : for (i = 0; i < TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t)); i++)
14721 8368695575 : if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)
14722 8368695575 : && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)) != t)
14723 : {
14724 0 : error ("wrong %<TYPE_CACHED_VALUES%> entry");
14725 0 : debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i));
14726 0 : error_found = true;
14727 0 : break;
14728 : }
14729 : }
14730 : }
14731 135733807 : else if (FUNC_OR_METHOD_TYPE_P (t))
14732 3044194 : for (tree l = TYPE_ARG_TYPES (t); l; l = TREE_CHAIN (l))
14733 : {
14734 : /* C++ FE uses TREE_PURPOSE to store initial values. */
14735 2234186 : if (TREE_PURPOSE (l) && in_lto_p)
14736 : {
14737 0 : error ("%<TREE_PURPOSE%> is non-NULL in %<TYPE_ARG_TYPES%> list");
14738 0 : debug_tree (l);
14739 0 : error_found = true;
14740 : }
14741 2234186 : if (!TYPE_P (TREE_VALUE (l)))
14742 : {
14743 0 : error ("wrong entry in %<TYPE_ARG_TYPES%> list");
14744 0 : debug_tree (l);
14745 0 : error_found = true;
14746 : }
14747 : }
14748 268868281 : else if (!is_lang_specific (t) && TYPE_VALUES_RAW (t))
14749 : {
14750 0 : error ("%<TYPE_VALUES_RAW%> field is non-NULL");
14751 0 : debug_tree (TYPE_VALUES_RAW (t));
14752 0 : error_found = true;
14753 : }
14754 937348096 : if (TREE_CODE (t) != INTEGER_TYPE
14755 : && TREE_CODE (t) != BOOLEAN_TYPE
14756 937348096 : && TREE_CODE (t) != BITINT_TYPE
14757 : && TREE_CODE (t) != OFFSET_TYPE
14758 : && TREE_CODE (t) != REFERENCE_TYPE
14759 : && TREE_CODE (t) != NULLPTR_TYPE
14760 : && TREE_CODE (t) != POINTER_TYPE
14761 648836798 : && TYPE_CACHED_VALUES_P (t))
14762 : {
14763 0 : error ("%<TYPE_CACHED_VALUES_P%> is set while it should not be");
14764 0 : error_found = true;
14765 : }
14766 :
14767 : /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
14768 : TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
14769 : of a type. */
14770 937348096 : if (TREE_CODE (t) == METHOD_TYPE
14771 937348096 : && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t)) != TYPE_METHOD_BASETYPE (t))
14772 : {
14773 0 : error ("%<TYPE_METHOD_BASETYPE%> is not main variant");
14774 0 : error_found = true;
14775 : }
14776 :
14777 937348096 : if (error_found)
14778 : {
14779 0 : debug_tree (const_cast <tree> (t));
14780 0 : internal_error ("%qs failed", __func__);
14781 : }
14782 : }
14783 :
14784 :
14785 : /* Return 1 if ARG interpreted as signed in its precision is known to be
14786 : always non-negative or 2 if ARG is known to be always negative, or 3 if
14787 : ARG may be non-negative or negative. STMT if specified is the statement
14788 : on which it is being tested. */
14789 :
14790 : int
14791 844292 : get_range_pos_neg (tree arg, gimple *stmt)
14792 : {
14793 844292 : if (arg == error_mark_node || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
14794 : return 3;
14795 :
14796 844292 : int prec = TYPE_PRECISION (TREE_TYPE (arg));
14797 844292 : int cnt = 0;
14798 844292 : if (TREE_CODE (arg) == INTEGER_CST)
14799 : {
14800 73225 : wide_int w = wi::sext (wi::to_wide (arg), prec);
14801 73225 : if (wi::neg_p (w))
14802 : return 2;
14803 : else
14804 58780 : return 1;
14805 73225 : }
14806 769854 : while (CONVERT_EXPR_P (arg)
14807 14388 : && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
14808 798630 : && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg, 0))) <= prec)
14809 : {
14810 13604 : arg = TREE_OPERAND (arg, 0);
14811 : /* Narrower value zero extended into wider type
14812 : will always result in positive values. */
14813 13604 : if (TYPE_UNSIGNED (TREE_TYPE (arg))
14814 13604 : && TYPE_PRECISION (TREE_TYPE (arg)) < prec)
14815 : return 1;
14816 13175 : prec = TYPE_PRECISION (TREE_TYPE (arg));
14817 13175 : if (++cnt > 30)
14818 : return 3;
14819 : }
14820 :
14821 770638 : if (TREE_CODE (arg) != SSA_NAME)
14822 : return 3;
14823 764037 : int_range_max r;
14824 1542931 : while (!get_range_query (cfun)->range_of_expr (r, arg, stmt)
14825 1557788 : || r.undefined_p () || r.varying_p ())
14826 : {
14827 495179 : gimple *g = SSA_NAME_DEF_STMT (arg);
14828 495179 : if (is_gimple_assign (g)
14829 495179 : && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (g)))
14830 : {
14831 23976 : tree t = gimple_assign_rhs1 (g);
14832 47599 : if (INTEGRAL_TYPE_P (TREE_TYPE (t))
14833 45027 : && TYPE_PRECISION (TREE_TYPE (t)) <= prec)
14834 : {
14835 14857 : if (TYPE_UNSIGNED (TREE_TYPE (t))
14836 14857 : && TYPE_PRECISION (TREE_TYPE (t)) < prec)
14837 : return 1;
14838 14857 : prec = TYPE_PRECISION (TREE_TYPE (t));
14839 14857 : arg = t;
14840 14857 : if (++cnt > 30)
14841 : return 3;
14842 14857 : continue;
14843 : }
14844 : }
14845 : return 3;
14846 : }
14847 283715 : if (TYPE_UNSIGNED (TREE_TYPE (arg)))
14848 : {
14849 : /* For unsigned values, the "positive" range comes
14850 : below the "negative" range. */
14851 120767 : if (!wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14852 : return 1;
14853 33886 : if (wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14854 : return 2;
14855 : }
14856 : else
14857 : {
14858 162948 : if (!wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14859 : return 1;
14860 69748 : if (wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14861 : return 2;
14862 : }
14863 : return 3;
14864 764037 : }
14865 :
14866 :
14867 :
14868 :
14869 : /* Return true if ARG is marked with the nonnull attribute in the
14870 : current function signature. */
14871 :
14872 : bool
14873 26242402 : nonnull_arg_p (const_tree arg)
14874 : {
14875 26242402 : tree t, attrs, fntype;
14876 26242402 : unsigned HOST_WIDE_INT arg_num;
14877 :
14878 26242402 : gcc_assert (TREE_CODE (arg) == PARM_DECL
14879 : && (POINTER_TYPE_P (TREE_TYPE (arg))
14880 : || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE));
14881 :
14882 : /* The static chain decl is always non null. */
14883 26242402 : if (arg == cfun->static_chain_decl)
14884 : return true;
14885 :
14886 : /* THIS argument of method is always non-NULL. */
14887 25973970 : if (TREE_CODE (TREE_TYPE (cfun->decl)) == METHOD_TYPE
14888 9964073 : && arg == DECL_ARGUMENTS (cfun->decl)
14889 32259971 : && flag_delete_null_pointer_checks)
14890 : return true;
14891 :
14892 : /* Values passed by reference are always non-NULL. */
14893 19690047 : if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
14894 19690047 : && flag_delete_null_pointer_checks)
14895 : return true;
14896 :
14897 13756443 : fntype = TREE_TYPE (cfun->decl);
14898 13779416 : for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
14899 : {
14900 539815 : attrs = lookup_attribute ("nonnull", attrs);
14901 :
14902 : /* If "nonnull" wasn't specified, we know nothing about the argument. */
14903 539815 : if (attrs == NULL_TREE)
14904 : return false;
14905 :
14906 : /* If "nonnull" applies to all the arguments, then ARG is non-null. */
14907 112938 : if (TREE_VALUE (attrs) == NULL_TREE)
14908 : return true;
14909 :
14910 : /* Get the position number for ARG in the function signature. */
14911 56181 : for (arg_num = 1, t = DECL_ARGUMENTS (cfun->decl);
14912 130744 : t;
14913 74563 : t = DECL_CHAIN (t), arg_num++)
14914 : {
14915 130744 : if (t == arg)
14916 : break;
14917 : }
14918 :
14919 56181 : gcc_assert (t == arg);
14920 :
14921 : /* Now see if ARG_NUM is mentioned in the nonnull list. */
14922 88953 : for (t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
14923 : {
14924 65980 : if (compare_tree_int (TREE_VALUE (t), arg_num) == 0)
14925 : return true;
14926 : }
14927 : }
14928 :
14929 : return false;
14930 : }
14931 :
14932 : /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
14933 : information. */
14934 :
14935 : location_t
14936 1004290515 : set_block (location_t loc, tree block)
14937 : {
14938 1004290515 : location_t pure_loc = get_pure_location (loc);
14939 1004290515 : source_range src_range = get_range_from_loc (line_table, loc);
14940 1004290515 : unsigned discriminator = get_discriminator_from_loc (line_table, loc);
14941 1004290515 : return line_table->get_or_create_combined_loc (pure_loc, src_range, block,
14942 1004290515 : discriminator);
14943 : }
14944 :
14945 : location_t
14946 221444335 : set_source_range (tree expr, location_t start, location_t finish)
14947 : {
14948 221444335 : source_range src_range;
14949 221444335 : src_range.m_start = start;
14950 221444335 : src_range.m_finish = finish;
14951 221444335 : return set_source_range (expr, src_range);
14952 : }
14953 :
14954 : location_t
14955 452250996 : set_source_range (tree expr, source_range src_range)
14956 : {
14957 452250996 : if (!EXPR_P (expr))
14958 : return UNKNOWN_LOCATION;
14959 :
14960 199152944 : location_t expr_location = EXPR_LOCATION (expr);
14961 199152944 : location_t pure_loc = get_pure_location (expr_location);
14962 199152944 : unsigned discriminator = get_discriminator_from_loc (expr_location);
14963 199152944 : location_t adhoc = line_table->get_or_create_combined_loc (pure_loc,
14964 : src_range,
14965 : nullptr,
14966 : discriminator);
14967 199152944 : SET_EXPR_LOCATION (expr, adhoc);
14968 199152944 : return adhoc;
14969 : }
14970 :
14971 : /* Return EXPR, potentially wrapped with a node expression LOC,
14972 : if !CAN_HAVE_LOCATION_P (expr).
14973 :
14974 : NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
14975 : VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
14976 :
14977 : Wrapper nodes can be identified using location_wrapper_p. */
14978 :
14979 : tree
14980 1592569358 : maybe_wrap_with_location (tree expr, location_t loc)
14981 : {
14982 1592569358 : if (expr == NULL)
14983 : return NULL;
14984 1592569354 : if (loc == UNKNOWN_LOCATION)
14985 : return expr;
14986 1537655922 : if (CAN_HAVE_LOCATION_P (expr))
14987 : return expr;
14988 : /* We should only be adding wrappers for constants and for decls,
14989 : or for some exceptional tree nodes (e.g. BASELINK in the C++ FE). */
14990 971324971 : gcc_assert (CONSTANT_CLASS_P (expr)
14991 : || DECL_P (expr)
14992 : || EXCEPTIONAL_CLASS_P (expr));
14993 :
14994 : /* For now, don't add wrappers to exceptional tree nodes, to minimize
14995 : any impact of the wrapper nodes. */
14996 971324971 : if (EXCEPTIONAL_CLASS_P (expr) || error_operand_p (expr))
14997 : return expr;
14998 :
14999 : /* Compiler-generated temporary variables don't need a wrapper. */
15000 902949956 : if (DECL_P (expr) && DECL_ARTIFICIAL (expr) && DECL_IGNORED_P (expr))
15001 : return expr;
15002 :
15003 : /* If any auto_suppress_location_wrappers are active, don't create
15004 : wrappers. */
15005 902947599 : if (suppress_location_wrappers > 0)
15006 : return expr;
15007 :
15008 1699668960 : tree_code code
15009 220612326 : = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
15010 638811605 : || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
15011 849834480 : ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
15012 849834480 : tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
15013 : /* Mark this node as being a wrapper. */
15014 849834480 : EXPR_LOCATION_WRAPPER_P (wrapper) = 1;
15015 849834480 : return wrapper;
15016 : }
15017 :
15018 : int suppress_location_wrappers;
15019 :
15020 : /* Return the name of combined function FN, for debugging purposes. */
15021 :
15022 : const char *
15023 0 : combined_fn_name (combined_fn fn)
15024 : {
15025 0 : if (builtin_fn_p (fn))
15026 : {
15027 0 : tree fndecl = builtin_decl_explicit (as_builtin_fn (fn));
15028 0 : return IDENTIFIER_POINTER (DECL_NAME (fndecl));
15029 : }
15030 : else
15031 0 : return internal_fn_name (as_internal_fn (fn));
15032 : }
15033 :
15034 : /* Return a bitmap with a bit set corresponding to each argument in
15035 : a function call type FNTYPE declared with attribute nonnull,
15036 : or null if none of the function's argument are nonnull. The caller
15037 : must free the bitmap. */
15038 :
15039 : bitmap
15040 21508420 : get_nonnull_args (const_tree fntype)
15041 : {
15042 21508420 : if (fntype == NULL_TREE)
15043 : return NULL;
15044 :
15045 20932079 : bitmap argmap = NULL;
15046 20932079 : if (TREE_CODE (fntype) == METHOD_TYPE)
15047 : {
15048 : /* The this pointer in C++ non-static member functions is
15049 : implicitly nonnull whether or not it's declared as such. */
15050 2716801 : argmap = BITMAP_ALLOC (NULL);
15051 2716801 : bitmap_set_bit (argmap, 0);
15052 : }
15053 :
15054 20932079 : tree attrs = TYPE_ATTRIBUTES (fntype);
15055 20932079 : if (!attrs)
15056 : return argmap;
15057 :
15058 : /* A function declaration can specify multiple attribute nonnull,
15059 : each with zero or more arguments. The loop below creates a bitmap
15060 : representing a union of all the arguments. An empty (but non-null)
15061 : bitmap means that all arguments have been declared nonnull. */
15062 5994006 : for ( ; attrs; attrs = TREE_CHAIN (attrs))
15063 : {
15064 5886565 : attrs = lookup_attribute ("nonnull", attrs);
15065 5886565 : if (!attrs)
15066 : break;
15067 :
15068 1605957 : if (!argmap)
15069 1566142 : argmap = BITMAP_ALLOC (NULL);
15070 :
15071 1605957 : if (!TREE_VALUE (attrs))
15072 : {
15073 : /* Clear the bitmap in case a previous attribute nonnull
15074 : set it and this one overrides it for all arguments. */
15075 988863 : bitmap_clear (argmap);
15076 988863 : return argmap;
15077 : }
15078 :
15079 : /* Iterate over the indices of the format arguments declared nonnull
15080 : and set a bit for each. */
15081 1614970 : for (tree idx = TREE_VALUE (attrs); idx; idx = TREE_CHAIN (idx))
15082 : {
15083 997876 : unsigned int val = TREE_INT_CST_LOW (TREE_VALUE (idx)) - 1;
15084 997876 : bitmap_set_bit (argmap, val);
15085 : }
15086 : }
15087 :
15088 : return argmap;
15089 : }
15090 :
15091 : /* Returns true if TYPE is a type where it and all of its subobjects
15092 : (recursively) are of structure, union, or array type. */
15093 :
15094 : bool
15095 1983372490 : is_empty_type (const_tree type)
15096 : {
15097 1983372490 : if (RECORD_OR_UNION_TYPE_P (type))
15098 : {
15099 892116422 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
15100 816408136 : if (TREE_CODE (field) == FIELD_DECL
15101 406518142 : && !DECL_PADDING_P (field)
15102 1222924973 : && !is_empty_type (TREE_TYPE (field)))
15103 : return false;
15104 : return true;
15105 : }
15106 1530299264 : else if (TREE_CODE (type) == ARRAY_TYPE)
15107 84063588 : return (integer_minus_onep (array_type_nelts_minus_one (type))
15108 84019786 : || TYPE_DOMAIN (type) == NULL_TREE
15109 157740754 : || is_empty_type (TREE_TYPE (type)));
15110 : return false;
15111 : }
15112 :
15113 : /* Implement TARGET_EMPTY_RECORD_P. Return true if TYPE is an empty type
15114 : that shouldn't be passed via stack. */
15115 :
15116 : bool
15117 1452388039 : default_is_empty_record (const_tree type)
15118 : {
15119 1452388039 : if (!abi_version_at_least (12))
15120 : return false;
15121 :
15122 1451341062 : if (type == error_mark_node)
15123 : return false;
15124 :
15125 1451341062 : if (TREE_ADDRESSABLE (type))
15126 : return false;
15127 :
15128 1451341062 : return is_empty_type (TYPE_MAIN_VARIANT (type));
15129 : }
15130 :
15131 : /* Determine whether TYPE is a structure with a flexible array member,
15132 : or a union containing such a structure (possibly recursively). */
15133 :
15134 : bool
15135 73577 : flexible_array_type_p (const_tree type)
15136 : {
15137 73577 : tree x, last;
15138 73577 : switch (TREE_CODE (type))
15139 : {
15140 37578 : case RECORD_TYPE:
15141 37578 : last = NULL_TREE;
15142 171670 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15143 134092 : if (TREE_CODE (x) == FIELD_DECL)
15144 134092 : last = x;
15145 37578 : if (last == NULL_TREE)
15146 : return false;
15147 37570 : if (TREE_CODE (TREE_TYPE (last)) == ARRAY_TYPE
15148 518 : && TYPE_SIZE (TREE_TYPE (last)) == NULL_TREE
15149 289 : && TYPE_DOMAIN (TREE_TYPE (last)) != NULL_TREE
15150 37859 : && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (last))) == NULL_TREE)
15151 : return true;
15152 : return false;
15153 617 : case UNION_TYPE:
15154 1784 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15155 : {
15156 1209 : if (TREE_CODE (x) == FIELD_DECL
15157 1209 : && flexible_array_type_p (TREE_TYPE (x)))
15158 : return true;
15159 : }
15160 : return false;
15161 : default:
15162 : return false;
15163 : }
15164 : }
15165 :
15166 : /* Like int_size_in_bytes, but handle empty records specially. */
15167 :
15168 : HOST_WIDE_INT
15169 456939 : arg_int_size_in_bytes (const_tree type)
15170 : {
15171 456939 : return TYPE_EMPTY_P (type) ? 0 : int_size_in_bytes (type);
15172 : }
15173 :
15174 : /* Like size_in_bytes, but handle empty records specially. */
15175 :
15176 : tree
15177 5650403 : arg_size_in_bytes (const_tree type)
15178 : {
15179 5650403 : return TYPE_EMPTY_P (type) ? size_zero_node : size_in_bytes (type);
15180 : }
15181 :
15182 : /* Return true if an expression with CODE has to have the same result type as
15183 : its first operand. */
15184 :
15185 : bool
15186 0 : expr_type_first_operand_type_p (tree_code code)
15187 : {
15188 0 : switch (code)
15189 : {
15190 : case NEGATE_EXPR:
15191 : case ABS_EXPR:
15192 : case BIT_NOT_EXPR:
15193 : case PAREN_EXPR:
15194 : case CONJ_EXPR:
15195 :
15196 : case PLUS_EXPR:
15197 : case MINUS_EXPR:
15198 : case MULT_EXPR:
15199 : case TRUNC_DIV_EXPR:
15200 : case CEIL_DIV_EXPR:
15201 : case FLOOR_DIV_EXPR:
15202 : case ROUND_DIV_EXPR:
15203 : case TRUNC_MOD_EXPR:
15204 : case CEIL_MOD_EXPR:
15205 : case FLOOR_MOD_EXPR:
15206 : case ROUND_MOD_EXPR:
15207 : case RDIV_EXPR:
15208 : case EXACT_DIV_EXPR:
15209 : case MIN_EXPR:
15210 : case MAX_EXPR:
15211 : case BIT_IOR_EXPR:
15212 : case BIT_XOR_EXPR:
15213 : case BIT_AND_EXPR:
15214 :
15215 : case LSHIFT_EXPR:
15216 : case RSHIFT_EXPR:
15217 : case LROTATE_EXPR:
15218 : case RROTATE_EXPR:
15219 : return true;
15220 :
15221 0 : default:
15222 0 : return false;
15223 : }
15224 : }
15225 :
15226 : /* Return a typenode for the "standard" C type with a given name. */
15227 : tree
15228 909690 : get_typenode_from_name (const char *name)
15229 : {
15230 909690 : if (name == NULL || *name == '\0')
15231 : return NULL_TREE;
15232 :
15233 909690 : if (strcmp (name, "char") == 0)
15234 0 : return char_type_node;
15235 909690 : if (strcmp (name, "unsigned char") == 0)
15236 93918 : return unsigned_char_type_node;
15237 815772 : if (strcmp (name, "signed char") == 0)
15238 93918 : return signed_char_type_node;
15239 :
15240 721854 : if (strcmp (name, "short int") == 0)
15241 64128 : return short_integer_type_node;
15242 657726 : if (strcmp (name, "short unsigned int") == 0)
15243 62612 : return short_unsigned_type_node;
15244 :
15245 595114 : if (strcmp (name, "int") == 0)
15246 64947 : return integer_type_node;
15247 530167 : if (strcmp (name, "unsigned int") == 0)
15248 63426 : return unsigned_type_node;
15249 :
15250 466741 : if (strcmp (name, "long int") == 0)
15251 278091 : return long_integer_type_node;
15252 188650 : if (strcmp (name, "long unsigned int") == 0)
15253 185394 : return long_unsigned_type_node;
15254 :
15255 3256 : if (strcmp (name, "long long int") == 0)
15256 1628 : return long_long_integer_type_node;
15257 1628 : if (strcmp (name, "long long unsigned int") == 0)
15258 1628 : return long_long_unsigned_type_node;
15259 :
15260 0 : gcc_unreachable ();
15261 : }
15262 :
15263 : /* List of pointer types used to declare builtins before we have seen their
15264 : real declaration.
15265 :
15266 : Keep the size up to date in tree.h ! */
15267 : const builtin_structptr_type builtin_structptr_types[6] =
15268 : {
15269 : { fileptr_type_node, ptr_type_node, "FILE" },
15270 : { const_tm_ptr_type_node, const_ptr_type_node, "tm" },
15271 : { fenv_t_ptr_type_node, ptr_type_node, "fenv_t" },
15272 : { const_fenv_t_ptr_type_node, const_ptr_type_node, "fenv_t" },
15273 : { fexcept_t_ptr_type_node, ptr_type_node, "fexcept_t" },
15274 : { const_fexcept_t_ptr_type_node, const_ptr_type_node, "fexcept_t" }
15275 : };
15276 :
15277 : /* Return the maximum object size. */
15278 :
15279 : tree
15280 7419946 : max_object_size (void)
15281 : {
15282 : /* To do: Make this a configurable parameter. */
15283 7419946 : return TYPE_MAX_VALUE (ptrdiff_type_node);
15284 : }
15285 :
15286 : /* A wrapper around TARGET_VERIFY_TYPE_CONTEXT that makes the silent_p
15287 : parameter default to false and that weeds out error_mark_node. */
15288 :
15289 : bool
15290 163981156 : verify_type_context (location_t loc, type_context_kind context,
15291 : const_tree type, bool silent_p)
15292 : {
15293 163981156 : if (type == error_mark_node)
15294 : return true;
15295 :
15296 163981061 : gcc_assert (TYPE_P (type));
15297 163981061 : return (!targetm.verify_type_context
15298 163981061 : || targetm.verify_type_context (loc, context, type, silent_p));
15299 : }
15300 :
15301 : /* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and
15302 : delete operators. Return false if they may or may not name such
15303 : a pair and, when nonnull, set *PCERTAIN to true if they certainly
15304 : do not. */
15305 :
15306 : bool
15307 63867 : valid_new_delete_pair_p (tree new_asm, tree delete_asm,
15308 : bool *pcertain /* = NULL */)
15309 : {
15310 63867 : bool certain;
15311 63867 : if (!pcertain)
15312 51935 : pcertain = &certain;
15313 :
15314 63867 : const char *new_name = IDENTIFIER_POINTER (new_asm);
15315 63867 : const char *delete_name = IDENTIFIER_POINTER (delete_asm);
15316 63867 : unsigned int new_len = IDENTIFIER_LENGTH (new_asm);
15317 63867 : unsigned int delete_len = IDENTIFIER_LENGTH (delete_asm);
15318 :
15319 : /* The following failures are due to invalid names so they're not
15320 : considered certain mismatches. */
15321 63867 : *pcertain = false;
15322 :
15323 63867 : if (new_len < 5 || delete_len < 6)
15324 : return false;
15325 63867 : if (new_name[0] == '_')
15326 63795 : ++new_name, --new_len;
15327 63867 : if (new_name[0] == '_')
15328 0 : ++new_name, --new_len;
15329 63867 : if (delete_name[0] == '_')
15330 63867 : ++delete_name, --delete_len;
15331 63867 : if (delete_name[0] == '_')
15332 0 : ++delete_name, --delete_len;
15333 63867 : if (new_len < 4 || delete_len < 5)
15334 : return false;
15335 :
15336 : /* The following failures are due to names of user-defined operators
15337 : so they're also not considered certain mismatches. */
15338 :
15339 : /* *_len is now just the length after initial underscores. */
15340 63867 : if (new_name[0] != 'Z' || new_name[1] != 'n')
15341 : return false;
15342 63194 : if (delete_name[0] != 'Z' || delete_name[1] != 'd')
15343 : return false;
15344 :
15345 : /* The following failures are certain mismatches. */
15346 63122 : *pcertain = true;
15347 :
15348 : /* _Znw must match _Zdl, _Zna must match _Zda. */
15349 63122 : if ((new_name[2] != 'w' || delete_name[2] != 'l')
15350 5007 : && (new_name[2] != 'a' || delete_name[2] != 'a'))
15351 : return false;
15352 63026 : if (new_name[3] == 'I' || delete_name[3] == 'I')
15353 : {
15354 : /* When ::operator new or ::operator delete are function templates,
15355 : return uncertain mismatch, we need demangler in that case. */
15356 6 : *pcertain = false;
15357 6 : return false;
15358 : }
15359 : /* 'j', 'm' and 'y' correspond to size_t. */
15360 63020 : if (new_name[3] != 'j' && new_name[3] != 'm' && new_name[3] != 'y')
15361 : return false;
15362 63020 : if (delete_name[3] != 'P' || delete_name[4] != 'v')
15363 : return false;
15364 63020 : if (new_len == 4
15365 367 : || (new_len == 18 && !memcmp (new_name + 4, "RKSt9nothrow_t", 14)))
15366 : {
15367 : /* _ZnXY or _ZnXYRKSt9nothrow_t matches
15368 : _ZdXPv, _ZdXPvY and _ZdXPvRKSt9nothrow_t. */
15369 62818 : if (delete_len == 5)
15370 : return true;
15371 56266 : if (delete_len == 6 && delete_name[5] == new_name[3])
15372 : return true;
15373 39 : if (delete_len == 19 && !memcmp (delete_name + 5, "RKSt9nothrow_t", 14))
15374 : return true;
15375 : }
15376 202 : else if ((new_len == 19 && !memcmp (new_name + 4, "St11align_val_t", 15))
15377 42 : || (new_len == 33
15378 10 : && !memcmp (new_name + 4, "St11align_val_tRKSt9nothrow_t", 29)))
15379 : {
15380 : /* _ZnXYSt11align_val_t or _ZnXYSt11align_val_tRKSt9nothrow_t matches
15381 : _ZdXPvSt11align_val_t or _ZdXPvYSt11align_val_t or
15382 : _ZdXPvSt11align_val_tRKSt9nothrow_t. */
15383 170 : if (delete_len == 20 && !memcmp (delete_name + 5, "St11align_val_t", 15))
15384 : return true;
15385 54 : if (delete_len == 21
15386 39 : && delete_name[5] == new_name[3]
15387 39 : && !memcmp (delete_name + 6, "St11align_val_t", 15))
15388 : return true;
15389 15 : if (delete_len == 34
15390 9 : && !memcmp (delete_name + 5, "St11align_val_tRKSt9nothrow_t", 29))
15391 : return true;
15392 : }
15393 :
15394 : /* The negative result is conservative. */
15395 38 : *pcertain = false;
15396 38 : return false;
15397 : }
15398 :
15399 : /* Return the zero-based number corresponding to the argument being
15400 : deallocated if FNDECL is a deallocation function or an out-of-bounds
15401 : value if it isn't. */
15402 :
15403 : unsigned
15404 22588435 : fndecl_dealloc_argno (tree fndecl)
15405 : {
15406 : /* A call to operator delete isn't recognized as one to a built-in. */
15407 22588435 : if (DECL_IS_OPERATOR_DELETE_P (fndecl))
15408 : {
15409 344972 : if (DECL_IS_REPLACEABLE_OPERATOR (fndecl))
15410 : return 0;
15411 :
15412 : /* Avoid placement delete that's not been inlined. */
15413 25221 : tree fname = DECL_ASSEMBLER_NAME (fndecl);
15414 25221 : if (id_equal (fname, "_ZdlPvS_") // ordinary form
15415 25221 : || id_equal (fname, "_ZdaPvS_")) // array form
15416 : return UINT_MAX;
15417 : return 0;
15418 : }
15419 :
15420 : /* TODO: Handle user-defined functions with attribute malloc? Handle
15421 : known non-built-ins like fopen? */
15422 22243463 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
15423 : {
15424 5516557 : switch (DECL_FUNCTION_CODE (fndecl))
15425 : {
15426 : case BUILT_IN_FREE:
15427 : case BUILT_IN_REALLOC:
15428 : case BUILT_IN_GOMP_FREE:
15429 : case BUILT_IN_GOMP_REALLOC:
15430 : return 0;
15431 : default:
15432 : break;
15433 : }
15434 : return UINT_MAX;
15435 : }
15436 :
15437 16726906 : tree attrs = DECL_ATTRIBUTES (fndecl);
15438 16726906 : if (!attrs)
15439 : return UINT_MAX;
15440 :
15441 0 : for (tree atfree = attrs;
15442 3830709 : (atfree = lookup_attribute ("*dealloc", atfree));
15443 0 : atfree = TREE_CHAIN (atfree))
15444 : {
15445 4862 : tree alloc = TREE_VALUE (atfree);
15446 4862 : if (!alloc)
15447 0 : continue;
15448 :
15449 4862 : tree pos = TREE_CHAIN (alloc);
15450 4862 : if (!pos)
15451 : return 0;
15452 :
15453 2699 : pos = TREE_VALUE (pos);
15454 2699 : return TREE_INT_CST_LOW (pos) - 1;
15455 : }
15456 :
15457 : return UINT_MAX;
15458 : }
15459 :
15460 : /* If EXPR refers to a character array or pointer declared attribute
15461 : nonstring, return a decl for that array or pointer and set *REF
15462 : to the referenced enclosing object or pointer. Otherwise return
15463 : null. */
15464 :
15465 : tree
15466 1389323 : get_attr_nonstring_decl (tree expr, tree *ref)
15467 : {
15468 1394978 : tree decl = expr;
15469 1394978 : tree var = NULL_TREE;
15470 1394978 : if (TREE_CODE (decl) == SSA_NAME)
15471 : {
15472 834229 : gimple *def = SSA_NAME_DEF_STMT (decl);
15473 :
15474 834229 : if (is_gimple_assign (def))
15475 : {
15476 43069 : tree_code code = gimple_assign_rhs_code (def);
15477 43069 : if (code == ADDR_EXPR
15478 43069 : || code == COMPONENT_REF
15479 29349 : || code == VAR_DECL)
15480 18170 : decl = gimple_assign_rhs1 (def);
15481 : }
15482 : else
15483 791160 : var = SSA_NAME_VAR (decl);
15484 : }
15485 :
15486 1394978 : if (TREE_CODE (decl) == ADDR_EXPR)
15487 25849 : decl = TREE_OPERAND (decl, 0);
15488 :
15489 : /* To simplify calling code, store the referenced DECL regardless of
15490 : the attribute determined below, but avoid storing the SSA_NAME_VAR
15491 : obtained above (it's not useful for dataflow purposes). */
15492 1394978 : if (ref)
15493 5455 : *ref = decl;
15494 :
15495 : /* Use the SSA_NAME_VAR that was determined above to see if it's
15496 : declared nonstring. Otherwise drill down into the referenced
15497 : DECL. */
15498 1394978 : if (var)
15499 : decl = var;
15500 : else
15501 : {
15502 629029 : while (TREE_CODE (decl) == ARRAY_REF)
15503 18452 : decl = TREE_OPERAND (decl, 0);
15504 610577 : if (TREE_CODE (decl) == COMPONENT_REF)
15505 15513 : decl = TREE_OPERAND (decl, 1);
15506 595064 : else if (TREE_CODE (decl) == MEM_REF)
15507 5655 : return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref);
15508 : }
15509 :
15510 1389323 : if (DECL_P (decl) && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl)))
15511 : return decl;
15512 :
15513 : return NULL_TREE;
15514 : }
15515 :
15516 : /* Returns an auto_vec of string_slices containing the version strings from
15517 : ARGLIST. DEFAULT_COUNT is incremented for each default version found.
15518 : If FILTER is true then any invalid versions strings are not included. */
15519 :
15520 : auto_vec<string_slice>
15521 202 : get_clone_attr_versions (const tree arglist,
15522 : int *default_count,
15523 : bool filter)
15524 : {
15525 202 : gcc_assert (TREE_CODE (arglist) == TREE_LIST);
15526 202 : auto_vec<string_slice> versions;
15527 :
15528 202 : static const char separator_str[] = {TARGET_CLONES_ATTR_SEPARATOR, 0};
15529 202 : string_slice separators = string_slice (separator_str);
15530 :
15531 740 : for (tree arg = arglist; arg; arg = TREE_CHAIN (arg))
15532 : {
15533 538 : string_slice str = string_slice (TREE_STRING_POINTER (TREE_VALUE (arg)));
15534 1642 : while (str.is_valid ())
15535 : {
15536 566 : string_slice attr = string_slice::tokenize (&str, separators);
15537 566 : attr = attr.strip ();
15538 :
15539 566 : if (filter && !targetm.check_target_clone_version (attr, NULL))
15540 0 : continue;
15541 :
15542 566 : if (attr == "default" && default_count)
15543 200 : (*default_count)++;
15544 566 : versions.safe_push (attr);
15545 : }
15546 : }
15547 202 : return versions;
15548 : }
15549 :
15550 : /* Returns an auto_vec of string_slices containing the version strings from
15551 : the target_clone attribute from DECL. DEFAULT_COUNT is incremented for each
15552 : default version found. If FILTER is true then any invalid versions strings
15553 : are not included. */
15554 : auto_vec<string_slice>
15555 94 : get_clone_versions (const tree decl, int *default_count, bool filter)
15556 : {
15557 94 : tree attr = lookup_attribute ("target_clones", DECL_ATTRIBUTES (decl));
15558 94 : if (!attr)
15559 0 : return auto_vec<string_slice> ();
15560 94 : tree arglist = TREE_VALUE (attr);
15561 94 : return get_clone_attr_versions (arglist, default_count, filter);
15562 : }
15563 :
15564 : /* If DECL has a target_version attribute, returns a string_slice containing the
15565 : attribute value. Otherwise, returns string_slice::invalid.
15566 : Only works for target_version due to target attributes allowing multiple
15567 : string arguments to specify one target. */
15568 : string_slice
15569 0 : get_target_version (const tree decl)
15570 : {
15571 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15572 :
15573 : tree attr = lookup_attribute ("target_version", DECL_ATTRIBUTES (decl));
15574 :
15575 : if (!attr)
15576 : return string_slice::invalid ();
15577 :
15578 : return string_slice (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))))
15579 : .strip ();
15580 : }
15581 :
15582 : /* Returns true if FN1 and FN2 define disjoint function versions in an FMV
15583 : function set. That is, the two declarations are completely non-overlapping.
15584 : For target_version semantics, that means if one is a target clone and one is
15585 : a target version, the target_version must not be defined by the target_clone,
15586 : and for two target_clones, they must not define any of the same version.
15587 :
15588 : FN1 and FN2 should be function decls. */
15589 :
15590 : bool
15591 29321095 : disjoint_version_decls (tree fn1, tree fn2)
15592 : {
15593 29321095 : if (TREE_CODE (fn1) != FUNCTION_DECL
15594 29319952 : || TREE_CODE (fn2) != FUNCTION_DECL)
15595 : return false;
15596 :
15597 27195866 : if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
15598 : {
15599 27195866 : tree attr1 = lookup_attribute ("target", DECL_ATTRIBUTES (fn1));
15600 27195866 : tree attr2 = lookup_attribute ("target", DECL_ATTRIBUTES (fn2));
15601 :
15602 : /* At least one function decl should have the target attribute
15603 : specified. */
15604 27195866 : if (attr1 == NULL_TREE && attr2 == NULL_TREE)
15605 : return false;
15606 :
15607 : /* Diagnose missing target attribute if one of the decls is already
15608 : multi-versioned. */
15609 18804 : if (attr1 == NULL_TREE || attr2 == NULL_TREE)
15610 : {
15611 360 : if (DECL_FUNCTION_VERSIONED (fn1) || DECL_FUNCTION_VERSIONED (fn2))
15612 : {
15613 114 : if (attr2 != NULL_TREE)
15614 : {
15615 114 : std::swap (fn1, fn2);
15616 114 : attr1 = attr2;
15617 : }
15618 114 : auto_diagnostic_group d;
15619 114 : error_at (DECL_SOURCE_LOCATION (fn2),
15620 : "missing %<target%> attribute for multi-versioned %qD",
15621 : fn2);
15622 114 : inform (DECL_SOURCE_LOCATION (fn1),
15623 : "previous declaration of %qD", fn1);
15624 : /* Prevent diagnosing of the same error multiple times. */
15625 114 : DECL_ATTRIBUTES (fn2)
15626 228 : = tree_cons (get_identifier ("target"),
15627 114 : copy_node (TREE_VALUE (attr1)),
15628 114 : DECL_ATTRIBUTES (fn2));
15629 114 : }
15630 360 : return false;
15631 : }
15632 :
15633 18444 : char *target1 = sorted_attr_string (TREE_VALUE (attr1));
15634 18444 : char *target2 = sorted_attr_string (TREE_VALUE (attr2));
15635 :
15636 : /* The sorted target strings must be different for fn1 and fn2
15637 : to be versions. */
15638 18444 : bool result = strcmp (target1, target2) != 0;
15639 :
15640 18444 : XDELETEVEC (target1);
15641 18444 : XDELETEVEC (target2);
15642 :
15643 18444 : return result;
15644 : }
15645 : else
15646 : {
15647 : /* As this is symmetric, can remove the case where fn2 is target clone
15648 : and fn1 is target version by swapping here. */
15649 : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn2)))
15650 : std::swap (fn1, fn2);
15651 :
15652 : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn1)))
15653 : {
15654 : auto_vec<string_slice> fn1_versions = get_clone_versions (fn1);
15655 : /* fn1 is target_clone. */
15656 : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn2)))
15657 : {
15658 : /* Both are target_clone. */
15659 : auto_vec<string_slice> fn2_versions = get_clone_versions (fn2);
15660 : for (string_slice v1 : fn1_versions)
15661 : {
15662 : for (string_slice v2 : fn2_versions)
15663 : if (targetm.target_option.same_function_versions
15664 : (v1, NULL_TREE, v2, NULL_TREE))
15665 : return false;
15666 : }
15667 : return true;
15668 : }
15669 : else
15670 : {
15671 : string_slice v2 = get_target_version (fn2);
15672 :
15673 : /* target and target_clones is always conflicting for target
15674 : semantics. */
15675 : if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
15676 : return false;
15677 :
15678 : /* Only fn1 is target clone. */
15679 : if (!v2.is_valid ())
15680 : v2 = "default";
15681 : for (string_slice v1 : fn1_versions)
15682 : if (targetm.target_option.same_function_versions
15683 : (v1, NULL_TREE, v2, NULL_TREE))
15684 : return false;
15685 : return true;
15686 : }
15687 : }
15688 : else
15689 : {
15690 : /* Both are target_version. */
15691 : string_slice v1 = get_target_version (fn1);
15692 : string_slice v2 = get_target_version (fn2);
15693 :
15694 : if (!v1.is_valid () && !v2.is_valid ())
15695 : return false;
15696 :
15697 : if (!v1.is_valid ())
15698 : v1 = "default";
15699 : if (!v2.is_valid ())
15700 : v2 = "default";
15701 :
15702 : if (targetm.target_option.same_function_versions (v1, NULL_TREE,
15703 : v2, NULL_TREE))
15704 : return false;
15705 :
15706 : return true;
15707 : }
15708 : }
15709 : }
15710 :
15711 : /* Check if the target_version/target_clones attributes are mergeable
15712 : for two decls, and if so returns false.
15713 : If they aren't mergeable, diagnose this and return true.
15714 : Only works for target_version semantics. */
15715 : bool
15716 0 : diagnose_versioned_decls (tree old_decl, tree new_decl)
15717 : {
15718 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15719 :
15720 : string_slice old_target_attr = get_target_version (old_decl);
15721 : string_slice new_target_attr = get_target_version (new_decl);
15722 :
15723 : tree old_target_clones_attr = lookup_attribute ("target_clones",
15724 : DECL_ATTRIBUTES (old_decl));
15725 : tree new_target_clones_attr = lookup_attribute ("target_clones",
15726 : DECL_ATTRIBUTES (new_decl));
15727 :
15728 : /* If none of these are annotated, then it is mergeable. */
15729 : if (!old_target_attr.is_valid ()
15730 : && !old_target_attr.is_valid ()
15731 : && !old_target_clones_attr
15732 : && !new_target_clones_attr)
15733 : return false;
15734 :
15735 : /* If fn1 is unnanotated and fn2 contains default, then is mergeable. */
15736 : if (!old_target_attr.is_valid ()
15737 : && !old_target_clones_attr
15738 : && is_function_default_version (new_decl))
15739 : return false;
15740 :
15741 : /* If fn2 is unnanotated and fn1 contains default, then is mergeable. */
15742 : if (!new_target_attr.is_valid ()
15743 : && !new_target_clones_attr
15744 : && is_function_default_version (old_decl))
15745 : return false;
15746 :
15747 : /* In the case where both are annotated with target_clones, only mergeable if
15748 : the two sets of target_clones imply the same set of versions. */
15749 : if (old_target_clones_attr && new_target_clones_attr)
15750 : {
15751 : auto_vec<string_slice> old_versions = get_clone_versions (old_decl);
15752 : auto_vec<string_slice> new_versions = get_clone_versions (new_decl);
15753 :
15754 : bool mergeable = true;
15755 :
15756 : if (old_versions.length () != new_versions.length ())
15757 : mergeable = false;
15758 :
15759 : /* Check both inclusion directions. */
15760 : for (auto oldv: old_versions)
15761 : {
15762 : bool matched = false;
15763 : for (auto newv: new_versions)
15764 : if (targetm.target_option.same_function_versions (oldv, old_decl,
15765 : newv, new_decl))
15766 : matched = true;
15767 : if (!matched)
15768 : mergeable = false;
15769 : }
15770 :
15771 : for (auto newv: new_versions)
15772 : {
15773 : bool matched = false;
15774 : for (auto oldv: old_versions)
15775 : if (targetm.target_option.same_function_versions (oldv, old_decl,
15776 : newv, new_decl))
15777 : matched = true;
15778 : if (!matched)
15779 : mergeable = false;
15780 : }
15781 :
15782 : if (!mergeable)
15783 : {
15784 : error_at (DECL_SOURCE_LOCATION (new_decl),
15785 : "%qD conflicts with overlapping %<target_clone%> "
15786 : "declaration",
15787 : new_decl);
15788 : inform (DECL_SOURCE_LOCATION (old_decl),
15789 : "previous declaration of %qD", old_decl);
15790 : return true;
15791 : }
15792 :
15793 : return false;
15794 : }
15795 :
15796 : /* If olddecl is target clones and newdecl is a target_version.
15797 : As they are not distinct this implies newdecl redefines a version of
15798 : olddecl. Not mergeable. */
15799 : if (new_target_clones_attr)
15800 : {
15801 : gcc_assert (old_target_attr.is_valid ());
15802 :
15803 : error_at (DECL_SOURCE_LOCATION (new_decl),
15804 : "%qD conflicts for version %qB",
15805 : new_decl, &old_target_attr);
15806 : inform (DECL_SOURCE_LOCATION (old_decl),
15807 : "previous declaration of %qD",
15808 : old_decl);
15809 : return true;
15810 : }
15811 :
15812 : if (old_target_clones_attr)
15813 : {
15814 : gcc_assert (new_target_attr.is_valid ());
15815 :
15816 : error_at (DECL_SOURCE_LOCATION (new_decl),
15817 : "%qD conflicts with a previous declaration for version %qB",
15818 : new_decl, &new_target_attr);
15819 : inform (DECL_SOURCE_LOCATION (old_decl),
15820 : "previous declaration of %qD",
15821 : old_decl);
15822 : return true;
15823 : }
15824 :
15825 : /* The only remaining case is two target_version annotated decls. */
15826 : return !targetm.target_option.same_function_versions
15827 : (old_target_attr, old_decl, new_target_attr, new_decl);
15828 : }
15829 :
15830 : void
15831 256621 : tree_cc_finalize (void)
15832 : {
15833 256621 : clear_nonstandard_integer_type_cache ();
15834 256621 : vec_free (bitint_type_cache);
15835 256621 : }
15836 :
15837 : void
15838 144 : gt_ggc_mx (tree_raw_data *x)
15839 : {
15840 144 : gt_ggc_m_9tree_node (x->typed.type);
15841 144 : gt_ggc_m_9tree_node (x->owner);
15842 144 : }
15843 :
15844 : void
15845 12 : gt_pch_nx (tree_raw_data *x)
15846 : {
15847 12 : gt_pch_n_9tree_node (x->typed.type);
15848 12 : gt_pch_n_9tree_node (x->owner);
15849 12 : }
15850 :
15851 : /* For PCH we guarantee that RAW_DATA_CST's RAW_DATA_OWNER is a STRING_CST and
15852 : RAW_DATA_POINTER points into it. We don't want to save/restore
15853 : RAW_DATA_POINTER on its own but want to restore it pointing at the same
15854 : offset of the STRING_CST as before. */
15855 :
15856 : void
15857 12 : gt_pch_nx (tree_raw_data *x, gt_pointer_operator op, void *cookie)
15858 : {
15859 12 : op (&x->typed.type, NULL, cookie);
15860 12 : gcc_checking_assert (x->owner
15861 : && TREE_CODE (x->owner) == STRING_CST
15862 : && x->str >= TREE_STRING_POINTER (x->owner)
15863 : && (x->str + x->length
15864 : <= (TREE_STRING_POINTER (x->owner)
15865 : + TREE_STRING_LENGTH (x->owner))));
15866 12 : ptrdiff_t off = x->str - (const char *) (x->owner);
15867 12 : tree owner = x->owner;
15868 12 : op (&x->owner, NULL, cookie);
15869 12 : x->owner = owner;
15870 : /* The above op call relocates x->owner and remembers the address
15871 : for relocation e.g. if the compiler is position independent.
15872 : We then restore x->owner back to its previous value and call
15873 : op again, for x->owner itself this just repeats (uselessly) what
15874 : the first call did, but as the second argument is now non-NULL
15875 : and different, it also arranges for &x->str to be noted for the
15876 : PIE relocation. */
15877 12 : op (&x->owner, &x->str, cookie);
15878 12 : x->str = (const char *) (x->owner) + off;
15879 12 : }
15880 :
15881 : #if CHECKING_P
15882 :
15883 : namespace selftest {
15884 :
15885 : /* Selftests for tree. */
15886 :
15887 : /* Verify that integer constants are sane. */
15888 :
15889 : static void
15890 4 : test_integer_constants ()
15891 : {
15892 4 : ASSERT_TRUE (integer_type_node != NULL);
15893 4 : ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
15894 :
15895 4 : tree type = integer_type_node;
15896 :
15897 4 : tree zero = build_zero_cst (type);
15898 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
15899 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15900 :
15901 4 : tree one = build_int_cst (type, 1);
15902 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
15903 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15904 4 : }
15905 :
15906 : /* Verify identifiers. */
15907 :
15908 : static void
15909 4 : test_identifiers ()
15910 : {
15911 4 : tree identifier = get_identifier ("foo");
15912 4 : ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
15913 4 : ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
15914 4 : }
15915 :
15916 : /* Verify LABEL_DECL. */
15917 :
15918 : static void
15919 4 : test_labels ()
15920 : {
15921 4 : tree identifier = get_identifier ("err");
15922 4 : tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
15923 : identifier, void_type_node);
15924 4 : ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
15925 4 : ASSERT_FALSE (FORCED_LABEL (label_decl));
15926 4 : }
15927 :
15928 : /* Return a new VECTOR_CST node whose type is TYPE and whose values
15929 : are given by VALS. */
15930 :
15931 : static tree
15932 40 : build_vector (tree type, const vec<tree> &vals MEM_STAT_DECL)
15933 : {
15934 80 : gcc_assert (known_eq (vals.length (), TYPE_VECTOR_SUBPARTS (type)));
15935 40 : tree_vector_builder builder (type, vals.length (), 1);
15936 40 : builder.splice (vals);
15937 40 : return builder.build ();
15938 40 : }
15939 :
15940 : /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED. */
15941 :
15942 : static void
15943 40 : check_vector_cst (const vec<tree> &expected, tree actual)
15944 : {
15945 80 : ASSERT_KNOWN_EQ (expected.length (),
15946 : TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual)));
15947 360 : for (unsigned int i = 0; i < expected.length (); ++i)
15948 320 : ASSERT_EQ (wi::to_wide (expected[i]),
15949 : wi::to_wide (vector_cst_elt (actual, i)));
15950 40 : }
15951 :
15952 : /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
15953 : and that its elements match EXPECTED. */
15954 :
15955 : static void
15956 8 : check_vector_cst_duplicate (const vec<tree> &expected, tree actual,
15957 : unsigned int npatterns)
15958 : {
15959 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15960 8 : ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual));
15961 8 : ASSERT_EQ (npatterns, vector_cst_encoded_nelts (actual));
15962 8 : ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual));
15963 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15964 8 : check_vector_cst (expected, actual);
15965 8 : }
15966 :
15967 : /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
15968 : and NPATTERNS background elements, and that its elements match
15969 : EXPECTED. */
15970 :
15971 : static void
15972 8 : check_vector_cst_fill (const vec<tree> &expected, tree actual,
15973 : unsigned int npatterns)
15974 : {
15975 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15976 8 : ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual));
15977 8 : ASSERT_EQ (2 * npatterns, vector_cst_encoded_nelts (actual));
15978 8 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15979 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15980 8 : check_vector_cst (expected, actual);
15981 8 : }
15982 :
15983 : /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
15984 : and that its elements match EXPECTED. */
15985 :
15986 : static void
15987 24 : check_vector_cst_stepped (const vec<tree> &expected, tree actual,
15988 : unsigned int npatterns)
15989 : {
15990 24 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15991 24 : ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual));
15992 24 : ASSERT_EQ (3 * npatterns, vector_cst_encoded_nelts (actual));
15993 24 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15994 24 : ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual));
15995 24 : check_vector_cst (expected, actual);
15996 24 : }
15997 :
15998 : /* Test the creation of VECTOR_CSTs. */
15999 :
16000 : static void
16001 4 : test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO)
16002 : {
16003 4 : auto_vec<tree, 8> elements (8);
16004 4 : elements.quick_grow (8);
16005 4 : tree element_type = build_nonstandard_integer_type (16, true);
16006 4 : tree vector_type = build_vector_type (element_type, 8);
16007 :
16008 : /* Test a simple linear series with a base of 0 and a step of 1:
16009 : { 0, 1, 2, 3, 4, 5, 6, 7 }. */
16010 36 : for (unsigned int i = 0; i < 8; ++i)
16011 32 : elements[i] = build_int_cst (element_type, i);
16012 4 : tree vector = build_vector (vector_type, elements PASS_MEM_STAT);
16013 4 : check_vector_cst_stepped (elements, vector, 1);
16014 :
16015 : /* Try the same with the first element replaced by 100:
16016 : { 100, 1, 2, 3, 4, 5, 6, 7 }. */
16017 4 : elements[0] = build_int_cst (element_type, 100);
16018 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16019 4 : check_vector_cst_stepped (elements, vector, 1);
16020 :
16021 : /* Try a series that wraps around.
16022 : { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }. */
16023 32 : for (unsigned int i = 1; i < 8; ++i)
16024 28 : elements[i] = build_int_cst (element_type, (65530 + i) & 0xffff);
16025 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16026 4 : check_vector_cst_stepped (elements, vector, 1);
16027 :
16028 : /* Try a downward series:
16029 : { 100, 79, 78, 77, 76, 75, 75, 73 }. */
16030 32 : for (unsigned int i = 1; i < 8; ++i)
16031 28 : elements[i] = build_int_cst (element_type, 80 - i);
16032 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16033 4 : check_vector_cst_stepped (elements, vector, 1);
16034 :
16035 : /* Try two interleaved series with different bases and steps:
16036 : { 100, 53, 66, 206, 62, 212, 58, 218 }. */
16037 4 : elements[1] = build_int_cst (element_type, 53);
16038 16 : for (unsigned int i = 2; i < 8; i += 2)
16039 : {
16040 12 : elements[i] = build_int_cst (element_type, 70 - i * 2);
16041 12 : elements[i + 1] = build_int_cst (element_type, 200 + i * 3);
16042 : }
16043 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16044 4 : check_vector_cst_stepped (elements, vector, 2);
16045 :
16046 : /* Try a duplicated value:
16047 : { 100, 100, 100, 100, 100, 100, 100, 100 }. */
16048 32 : for (unsigned int i = 1; i < 8; ++i)
16049 28 : elements[i] = elements[0];
16050 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16051 4 : check_vector_cst_duplicate (elements, vector, 1);
16052 :
16053 : /* Try an interleaved duplicated value:
16054 : { 100, 55, 100, 55, 100, 55, 100, 55 }. */
16055 4 : elements[1] = build_int_cst (element_type, 55);
16056 28 : for (unsigned int i = 2; i < 8; ++i)
16057 24 : elements[i] = elements[i - 2];
16058 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16059 4 : check_vector_cst_duplicate (elements, vector, 2);
16060 :
16061 : /* Try a duplicated value with 2 exceptions
16062 : { 41, 97, 100, 55, 100, 55, 100, 55 }. */
16063 4 : elements[0] = build_int_cst (element_type, 41);
16064 4 : elements[1] = build_int_cst (element_type, 97);
16065 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16066 4 : check_vector_cst_fill (elements, vector, 2);
16067 :
16068 : /* Try with and without a step
16069 : { 41, 97, 100, 21, 100, 35, 100, 49 }. */
16070 16 : for (unsigned int i = 3; i < 8; i += 2)
16071 12 : elements[i] = build_int_cst (element_type, i * 7);
16072 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16073 4 : check_vector_cst_stepped (elements, vector, 2);
16074 :
16075 : /* Try a fully-general constant:
16076 : { 41, 97, 100, 21, 100, 9990, 100, 49 }. */
16077 4 : elements[5] = build_int_cst (element_type, 9990);
16078 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16079 4 : check_vector_cst_fill (elements, vector, 4);
16080 4 : }
16081 :
16082 : /* Verify that STRIP_NOPS (NODE) is EXPECTED.
16083 : Helper function for test_location_wrappers, to deal with STRIP_NOPS
16084 : modifying its argument in-place. */
16085 :
16086 : static void
16087 12 : check_strip_nops (tree node, tree expected)
16088 : {
16089 12 : STRIP_NOPS (node);
16090 12 : ASSERT_EQ (expected, node);
16091 12 : }
16092 :
16093 : /* Verify location wrappers. */
16094 :
16095 : static void
16096 4 : test_location_wrappers ()
16097 : {
16098 4 : location_t loc = BUILTINS_LOCATION;
16099 :
16100 4 : ASSERT_EQ (NULL_TREE, maybe_wrap_with_location (NULL_TREE, loc));
16101 :
16102 : /* Wrapping a constant. */
16103 4 : tree int_cst = build_int_cst (integer_type_node, 42);
16104 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst));
16105 4 : ASSERT_FALSE (location_wrapper_p (int_cst));
16106 :
16107 4 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
16108 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
16109 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_cst));
16110 4 : ASSERT_EQ (int_cst, tree_strip_any_location_wrapper (wrapped_int_cst));
16111 :
16112 : /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION. */
16113 4 : ASSERT_EQ (int_cst, maybe_wrap_with_location (int_cst, UNKNOWN_LOCATION));
16114 :
16115 : /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P. */
16116 4 : tree cast = build1 (NOP_EXPR, char_type_node, int_cst);
16117 4 : ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast));
16118 4 : ASSERT_EQ (cast, maybe_wrap_with_location (cast, loc));
16119 :
16120 : /* Wrapping a STRING_CST. */
16121 4 : tree string_cst = build_string (4, "foo");
16122 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst));
16123 4 : ASSERT_FALSE (location_wrapper_p (string_cst));
16124 :
16125 4 : tree wrapped_string_cst = maybe_wrap_with_location (string_cst, loc);
16126 4 : ASSERT_TRUE (location_wrapper_p (wrapped_string_cst));
16127 4 : ASSERT_EQ (VIEW_CONVERT_EXPR, TREE_CODE (wrapped_string_cst));
16128 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_string_cst));
16129 4 : ASSERT_EQ (string_cst, tree_strip_any_location_wrapper (wrapped_string_cst));
16130 :
16131 :
16132 : /* Wrapping a variable. */
16133 4 : tree int_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
16134 : get_identifier ("some_int_var"),
16135 : integer_type_node);
16136 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var));
16137 4 : ASSERT_FALSE (location_wrapper_p (int_var));
16138 :
16139 4 : tree wrapped_int_var = maybe_wrap_with_location (int_var, loc);
16140 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_var));
16141 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_var));
16142 4 : ASSERT_EQ (int_var, tree_strip_any_location_wrapper (wrapped_int_var));
16143 :
16144 : /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
16145 : wrapper. */
16146 4 : tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
16147 4 : ASSERT_FALSE (location_wrapper_p (r_cast));
16148 4 : ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
16149 :
16150 : /* Verify that STRIP_NOPS removes wrappers. */
16151 4 : check_strip_nops (wrapped_int_cst, int_cst);
16152 4 : check_strip_nops (wrapped_string_cst, string_cst);
16153 4 : check_strip_nops (wrapped_int_var, int_var);
16154 4 : }
16155 :
16156 : /* Test various tree predicates. Verify that location wrappers don't
16157 : affect the results. */
16158 :
16159 : static void
16160 4 : test_predicates ()
16161 : {
16162 : /* Build various constants and wrappers around them. */
16163 :
16164 4 : location_t loc = BUILTINS_LOCATION;
16165 :
16166 4 : tree i_0 = build_int_cst (integer_type_node, 0);
16167 4 : tree wr_i_0 = maybe_wrap_with_location (i_0, loc);
16168 :
16169 4 : tree i_1 = build_int_cst (integer_type_node, 1);
16170 4 : tree wr_i_1 = maybe_wrap_with_location (i_1, loc);
16171 :
16172 4 : tree i_m1 = build_int_cst (integer_type_node, -1);
16173 4 : tree wr_i_m1 = maybe_wrap_with_location (i_m1, loc);
16174 :
16175 4 : tree f_0 = build_real_from_int_cst (float_type_node, i_0);
16176 4 : tree wr_f_0 = maybe_wrap_with_location (f_0, loc);
16177 4 : tree f_1 = build_real_from_int_cst (float_type_node, i_1);
16178 4 : tree wr_f_1 = maybe_wrap_with_location (f_1, loc);
16179 4 : tree f_m1 = build_real_from_int_cst (float_type_node, i_m1);
16180 4 : tree wr_f_m1 = maybe_wrap_with_location (f_m1, loc);
16181 :
16182 4 : tree c_i_0 = build_complex (NULL_TREE, i_0, i_0);
16183 4 : tree c_i_1 = build_complex (NULL_TREE, i_1, i_0);
16184 4 : tree c_i_m1 = build_complex (NULL_TREE, i_m1, i_0);
16185 :
16186 4 : tree c_f_0 = build_complex (NULL_TREE, f_0, f_0);
16187 4 : tree c_f_1 = build_complex (NULL_TREE, f_1, f_0);
16188 4 : tree c_f_m1 = build_complex (NULL_TREE, f_m1, f_0);
16189 :
16190 : /* TODO: vector constants. */
16191 :
16192 : /* Test integer_onep. */
16193 4 : ASSERT_FALSE (integer_onep (i_0));
16194 4 : ASSERT_FALSE (integer_onep (wr_i_0));
16195 4 : ASSERT_TRUE (integer_onep (i_1));
16196 4 : ASSERT_TRUE (integer_onep (wr_i_1));
16197 4 : ASSERT_FALSE (integer_onep (i_m1));
16198 4 : ASSERT_FALSE (integer_onep (wr_i_m1));
16199 4 : ASSERT_FALSE (integer_onep (f_0));
16200 4 : ASSERT_FALSE (integer_onep (wr_f_0));
16201 4 : ASSERT_FALSE (integer_onep (f_1));
16202 4 : ASSERT_FALSE (integer_onep (wr_f_1));
16203 4 : ASSERT_FALSE (integer_onep (f_m1));
16204 4 : ASSERT_FALSE (integer_onep (wr_f_m1));
16205 4 : ASSERT_FALSE (integer_onep (c_i_0));
16206 4 : ASSERT_TRUE (integer_onep (c_i_1));
16207 4 : ASSERT_FALSE (integer_onep (c_i_m1));
16208 4 : ASSERT_FALSE (integer_onep (c_f_0));
16209 4 : ASSERT_FALSE (integer_onep (c_f_1));
16210 4 : ASSERT_FALSE (integer_onep (c_f_m1));
16211 :
16212 : /* Test integer_zerop. */
16213 4 : ASSERT_TRUE (integer_zerop (i_0));
16214 4 : ASSERT_TRUE (integer_zerop (wr_i_0));
16215 4 : ASSERT_FALSE (integer_zerop (i_1));
16216 4 : ASSERT_FALSE (integer_zerop (wr_i_1));
16217 4 : ASSERT_FALSE (integer_zerop (i_m1));
16218 4 : ASSERT_FALSE (integer_zerop (wr_i_m1));
16219 4 : ASSERT_FALSE (integer_zerop (f_0));
16220 4 : ASSERT_FALSE (integer_zerop (wr_f_0));
16221 4 : ASSERT_FALSE (integer_zerop (f_1));
16222 4 : ASSERT_FALSE (integer_zerop (wr_f_1));
16223 4 : ASSERT_FALSE (integer_zerop (f_m1));
16224 4 : ASSERT_FALSE (integer_zerop (wr_f_m1));
16225 4 : ASSERT_TRUE (integer_zerop (c_i_0));
16226 4 : ASSERT_FALSE (integer_zerop (c_i_1));
16227 4 : ASSERT_FALSE (integer_zerop (c_i_m1));
16228 4 : ASSERT_FALSE (integer_zerop (c_f_0));
16229 4 : ASSERT_FALSE (integer_zerop (c_f_1));
16230 4 : ASSERT_FALSE (integer_zerop (c_f_m1));
16231 :
16232 : /* Test integer_all_onesp. */
16233 4 : ASSERT_FALSE (integer_all_onesp (i_0));
16234 4 : ASSERT_FALSE (integer_all_onesp (wr_i_0));
16235 4 : ASSERT_FALSE (integer_all_onesp (i_1));
16236 4 : ASSERT_FALSE (integer_all_onesp (wr_i_1));
16237 4 : ASSERT_TRUE (integer_all_onesp (i_m1));
16238 4 : ASSERT_TRUE (integer_all_onesp (wr_i_m1));
16239 4 : ASSERT_FALSE (integer_all_onesp (f_0));
16240 4 : ASSERT_FALSE (integer_all_onesp (wr_f_0));
16241 4 : ASSERT_FALSE (integer_all_onesp (f_1));
16242 4 : ASSERT_FALSE (integer_all_onesp (wr_f_1));
16243 4 : ASSERT_FALSE (integer_all_onesp (f_m1));
16244 4 : ASSERT_FALSE (integer_all_onesp (wr_f_m1));
16245 4 : ASSERT_FALSE (integer_all_onesp (c_i_0));
16246 4 : ASSERT_FALSE (integer_all_onesp (c_i_1));
16247 4 : ASSERT_FALSE (integer_all_onesp (c_i_m1));
16248 4 : ASSERT_FALSE (integer_all_onesp (c_f_0));
16249 4 : ASSERT_FALSE (integer_all_onesp (c_f_1));
16250 4 : ASSERT_FALSE (integer_all_onesp (c_f_m1));
16251 :
16252 : /* Test integer_minus_onep. */
16253 4 : ASSERT_FALSE (integer_minus_onep (i_0));
16254 4 : ASSERT_FALSE (integer_minus_onep (wr_i_0));
16255 4 : ASSERT_FALSE (integer_minus_onep (i_1));
16256 4 : ASSERT_FALSE (integer_minus_onep (wr_i_1));
16257 4 : ASSERT_TRUE (integer_minus_onep (i_m1));
16258 4 : ASSERT_TRUE (integer_minus_onep (wr_i_m1));
16259 4 : ASSERT_FALSE (integer_minus_onep (f_0));
16260 4 : ASSERT_FALSE (integer_minus_onep (wr_f_0));
16261 4 : ASSERT_FALSE (integer_minus_onep (f_1));
16262 4 : ASSERT_FALSE (integer_minus_onep (wr_f_1));
16263 4 : ASSERT_FALSE (integer_minus_onep (f_m1));
16264 4 : ASSERT_FALSE (integer_minus_onep (wr_f_m1));
16265 4 : ASSERT_FALSE (integer_minus_onep (c_i_0));
16266 4 : ASSERT_FALSE (integer_minus_onep (c_i_1));
16267 4 : ASSERT_TRUE (integer_minus_onep (c_i_m1));
16268 4 : ASSERT_FALSE (integer_minus_onep (c_f_0));
16269 4 : ASSERT_FALSE (integer_minus_onep (c_f_1));
16270 4 : ASSERT_FALSE (integer_minus_onep (c_f_m1));
16271 :
16272 : /* Test integer_each_onep. */
16273 4 : ASSERT_FALSE (integer_each_onep (i_0));
16274 4 : ASSERT_FALSE (integer_each_onep (wr_i_0));
16275 4 : ASSERT_TRUE (integer_each_onep (i_1));
16276 4 : ASSERT_TRUE (integer_each_onep (wr_i_1));
16277 4 : ASSERT_FALSE (integer_each_onep (i_m1));
16278 4 : ASSERT_FALSE (integer_each_onep (wr_i_m1));
16279 4 : ASSERT_FALSE (integer_each_onep (f_0));
16280 4 : ASSERT_FALSE (integer_each_onep (wr_f_0));
16281 4 : ASSERT_FALSE (integer_each_onep (f_1));
16282 4 : ASSERT_FALSE (integer_each_onep (wr_f_1));
16283 4 : ASSERT_FALSE (integer_each_onep (f_m1));
16284 4 : ASSERT_FALSE (integer_each_onep (wr_f_m1));
16285 4 : ASSERT_FALSE (integer_each_onep (c_i_0));
16286 4 : ASSERT_FALSE (integer_each_onep (c_i_1));
16287 4 : ASSERT_FALSE (integer_each_onep (c_i_m1));
16288 4 : ASSERT_FALSE (integer_each_onep (c_f_0));
16289 4 : ASSERT_FALSE (integer_each_onep (c_f_1));
16290 4 : ASSERT_FALSE (integer_each_onep (c_f_m1));
16291 :
16292 : /* Test integer_truep. */
16293 4 : ASSERT_FALSE (integer_truep (i_0));
16294 4 : ASSERT_FALSE (integer_truep (wr_i_0));
16295 4 : ASSERT_TRUE (integer_truep (i_1));
16296 4 : ASSERT_TRUE (integer_truep (wr_i_1));
16297 4 : ASSERT_FALSE (integer_truep (i_m1));
16298 4 : ASSERT_FALSE (integer_truep (wr_i_m1));
16299 4 : ASSERT_FALSE (integer_truep (f_0));
16300 4 : ASSERT_FALSE (integer_truep (wr_f_0));
16301 4 : ASSERT_FALSE (integer_truep (f_1));
16302 4 : ASSERT_FALSE (integer_truep (wr_f_1));
16303 4 : ASSERT_FALSE (integer_truep (f_m1));
16304 4 : ASSERT_FALSE (integer_truep (wr_f_m1));
16305 4 : ASSERT_FALSE (integer_truep (c_i_0));
16306 4 : ASSERT_TRUE (integer_truep (c_i_1));
16307 4 : ASSERT_FALSE (integer_truep (c_i_m1));
16308 4 : ASSERT_FALSE (integer_truep (c_f_0));
16309 4 : ASSERT_FALSE (integer_truep (c_f_1));
16310 4 : ASSERT_FALSE (integer_truep (c_f_m1));
16311 :
16312 : /* Test integer_nonzerop. */
16313 4 : ASSERT_FALSE (integer_nonzerop (i_0));
16314 4 : ASSERT_FALSE (integer_nonzerop (wr_i_0));
16315 4 : ASSERT_TRUE (integer_nonzerop (i_1));
16316 4 : ASSERT_TRUE (integer_nonzerop (wr_i_1));
16317 4 : ASSERT_TRUE (integer_nonzerop (i_m1));
16318 4 : ASSERT_TRUE (integer_nonzerop (wr_i_m1));
16319 4 : ASSERT_FALSE (integer_nonzerop (f_0));
16320 4 : ASSERT_FALSE (integer_nonzerop (wr_f_0));
16321 4 : ASSERT_FALSE (integer_nonzerop (f_1));
16322 4 : ASSERT_FALSE (integer_nonzerop (wr_f_1));
16323 4 : ASSERT_FALSE (integer_nonzerop (f_m1));
16324 4 : ASSERT_FALSE (integer_nonzerop (wr_f_m1));
16325 4 : ASSERT_FALSE (integer_nonzerop (c_i_0));
16326 4 : ASSERT_TRUE (integer_nonzerop (c_i_1));
16327 4 : ASSERT_TRUE (integer_nonzerop (c_i_m1));
16328 4 : ASSERT_FALSE (integer_nonzerop (c_f_0));
16329 4 : ASSERT_FALSE (integer_nonzerop (c_f_1));
16330 4 : ASSERT_FALSE (integer_nonzerop (c_f_m1));
16331 :
16332 : /* Test real_zerop. */
16333 4 : ASSERT_FALSE (real_zerop (i_0));
16334 4 : ASSERT_FALSE (real_zerop (wr_i_0));
16335 4 : ASSERT_FALSE (real_zerop (i_1));
16336 4 : ASSERT_FALSE (real_zerop (wr_i_1));
16337 4 : ASSERT_FALSE (real_zerop (i_m1));
16338 4 : ASSERT_FALSE (real_zerop (wr_i_m1));
16339 4 : ASSERT_TRUE (real_zerop (f_0));
16340 4 : ASSERT_TRUE (real_zerop (wr_f_0));
16341 4 : ASSERT_FALSE (real_zerop (f_1));
16342 4 : ASSERT_FALSE (real_zerop (wr_f_1));
16343 4 : ASSERT_FALSE (real_zerop (f_m1));
16344 4 : ASSERT_FALSE (real_zerop (wr_f_m1));
16345 4 : ASSERT_FALSE (real_zerop (c_i_0));
16346 4 : ASSERT_FALSE (real_zerop (c_i_1));
16347 4 : ASSERT_FALSE (real_zerop (c_i_m1));
16348 4 : ASSERT_TRUE (real_zerop (c_f_0));
16349 4 : ASSERT_FALSE (real_zerop (c_f_1));
16350 4 : ASSERT_FALSE (real_zerop (c_f_m1));
16351 :
16352 : /* Test real_onep. */
16353 4 : ASSERT_FALSE (real_onep (i_0));
16354 4 : ASSERT_FALSE (real_onep (wr_i_0));
16355 4 : ASSERT_FALSE (real_onep (i_1));
16356 4 : ASSERT_FALSE (real_onep (wr_i_1));
16357 4 : ASSERT_FALSE (real_onep (i_m1));
16358 4 : ASSERT_FALSE (real_onep (wr_i_m1));
16359 4 : ASSERT_FALSE (real_onep (f_0));
16360 4 : ASSERT_FALSE (real_onep (wr_f_0));
16361 4 : ASSERT_TRUE (real_onep (f_1));
16362 4 : ASSERT_TRUE (real_onep (wr_f_1));
16363 4 : ASSERT_FALSE (real_onep (f_m1));
16364 4 : ASSERT_FALSE (real_onep (wr_f_m1));
16365 4 : ASSERT_FALSE (real_onep (c_i_0));
16366 4 : ASSERT_FALSE (real_onep (c_i_1));
16367 4 : ASSERT_FALSE (real_onep (c_i_m1));
16368 4 : ASSERT_FALSE (real_onep (c_f_0));
16369 4 : ASSERT_TRUE (real_onep (c_f_1));
16370 4 : ASSERT_FALSE (real_onep (c_f_m1));
16371 :
16372 : /* Test real_minus_onep. */
16373 4 : ASSERT_FALSE (real_minus_onep (i_0));
16374 4 : ASSERT_FALSE (real_minus_onep (wr_i_0));
16375 4 : ASSERT_FALSE (real_minus_onep (i_1));
16376 4 : ASSERT_FALSE (real_minus_onep (wr_i_1));
16377 4 : ASSERT_FALSE (real_minus_onep (i_m1));
16378 4 : ASSERT_FALSE (real_minus_onep (wr_i_m1));
16379 4 : ASSERT_FALSE (real_minus_onep (f_0));
16380 4 : ASSERT_FALSE (real_minus_onep (wr_f_0));
16381 4 : ASSERT_FALSE (real_minus_onep (f_1));
16382 4 : ASSERT_FALSE (real_minus_onep (wr_f_1));
16383 4 : ASSERT_TRUE (real_minus_onep (f_m1));
16384 4 : ASSERT_TRUE (real_minus_onep (wr_f_m1));
16385 4 : ASSERT_FALSE (real_minus_onep (c_i_0));
16386 4 : ASSERT_FALSE (real_minus_onep (c_i_1));
16387 4 : ASSERT_FALSE (real_minus_onep (c_i_m1));
16388 4 : ASSERT_FALSE (real_minus_onep (c_f_0));
16389 4 : ASSERT_FALSE (real_minus_onep (c_f_1));
16390 4 : ASSERT_TRUE (real_minus_onep (c_f_m1));
16391 :
16392 : /* Test zerop. */
16393 4 : ASSERT_TRUE (zerop (i_0));
16394 4 : ASSERT_TRUE (zerop (wr_i_0));
16395 4 : ASSERT_FALSE (zerop (i_1));
16396 4 : ASSERT_FALSE (zerop (wr_i_1));
16397 4 : ASSERT_FALSE (zerop (i_m1));
16398 4 : ASSERT_FALSE (zerop (wr_i_m1));
16399 4 : ASSERT_TRUE (zerop (f_0));
16400 4 : ASSERT_TRUE (zerop (wr_f_0));
16401 4 : ASSERT_FALSE (zerop (f_1));
16402 4 : ASSERT_FALSE (zerop (wr_f_1));
16403 4 : ASSERT_FALSE (zerop (f_m1));
16404 4 : ASSERT_FALSE (zerop (wr_f_m1));
16405 4 : ASSERT_TRUE (zerop (c_i_0));
16406 4 : ASSERT_FALSE (zerop (c_i_1));
16407 4 : ASSERT_FALSE (zerop (c_i_m1));
16408 4 : ASSERT_TRUE (zerop (c_f_0));
16409 4 : ASSERT_FALSE (zerop (c_f_1));
16410 4 : ASSERT_FALSE (zerop (c_f_m1));
16411 :
16412 : /* Test tree_expr_nonnegative_p. */
16413 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_0));
16414 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_0));
16415 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_1));
16416 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_1));
16417 4 : ASSERT_FALSE (tree_expr_nonnegative_p (i_m1));
16418 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_i_m1));
16419 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_0));
16420 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_0));
16421 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_1));
16422 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_1));
16423 4 : ASSERT_FALSE (tree_expr_nonnegative_p (f_m1));
16424 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_f_m1));
16425 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_0));
16426 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_1));
16427 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_m1));
16428 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_0));
16429 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_1));
16430 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_m1));
16431 :
16432 : /* Test tree_expr_nonzero_p. */
16433 4 : ASSERT_FALSE (tree_expr_nonzero_p (i_0));
16434 4 : ASSERT_FALSE (tree_expr_nonzero_p (wr_i_0));
16435 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_1));
16436 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_1));
16437 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_m1));
16438 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_m1));
16439 :
16440 : /* Test integer_valued_real_p. */
16441 4 : ASSERT_FALSE (integer_valued_real_p (i_0));
16442 4 : ASSERT_TRUE (integer_valued_real_p (f_0));
16443 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_0));
16444 4 : ASSERT_TRUE (integer_valued_real_p (f_1));
16445 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_1));
16446 :
16447 : /* Test integer_pow2p. */
16448 4 : ASSERT_FALSE (integer_pow2p (i_0));
16449 4 : ASSERT_TRUE (integer_pow2p (i_1));
16450 4 : ASSERT_TRUE (integer_pow2p (wr_i_1));
16451 :
16452 : /* Test uniform_integer_cst_p. */
16453 4 : ASSERT_TRUE (uniform_integer_cst_p (i_0));
16454 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_0));
16455 4 : ASSERT_TRUE (uniform_integer_cst_p (i_1));
16456 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_1));
16457 4 : ASSERT_TRUE (uniform_integer_cst_p (i_m1));
16458 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_m1));
16459 4 : ASSERT_FALSE (uniform_integer_cst_p (f_0));
16460 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_0));
16461 4 : ASSERT_FALSE (uniform_integer_cst_p (f_1));
16462 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_1));
16463 4 : ASSERT_FALSE (uniform_integer_cst_p (f_m1));
16464 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_m1));
16465 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_0));
16466 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_1));
16467 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_m1));
16468 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_0));
16469 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_1));
16470 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_m1));
16471 4 : }
16472 :
16473 : /* Check that string escaping works correctly. */
16474 :
16475 : static void
16476 4 : test_escaped_strings (void)
16477 : {
16478 4 : int saved_cutoff;
16479 4 : escaped_string msg;
16480 :
16481 4 : msg.escape (NULL);
16482 : /* ASSERT_STREQ does not accept NULL as a valid test
16483 : result, so we have to use ASSERT_EQ instead. */
16484 4 : ASSERT_EQ (NULL, (const char *) msg);
16485 :
16486 4 : msg.escape ("");
16487 4 : ASSERT_STREQ ("", (const char *) msg);
16488 :
16489 4 : msg.escape ("foobar");
16490 4 : ASSERT_STREQ ("foobar", (const char *) msg);
16491 :
16492 : /* Ensure that we have -fmessage-length set to 0. */
16493 4 : pretty_printer *pp = global_dc->get_reference_printer ();
16494 4 : saved_cutoff = pp_line_cutoff (pp);
16495 4 : pp_line_cutoff (pp) = 0;
16496 :
16497 4 : msg.escape ("foo\nbar");
16498 4 : ASSERT_STREQ ("foo\\nbar", (const char *) msg);
16499 :
16500 4 : msg.escape ("\a\b\f\n\r\t\v");
16501 4 : ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg);
16502 :
16503 : /* Now repeat the tests with -fmessage-length set to 5. */
16504 4 : pp_line_cutoff (pp) = 5;
16505 :
16506 : /* Note that the newline is not translated into an escape. */
16507 4 : msg.escape ("foo\nbar");
16508 4 : ASSERT_STREQ ("foo\nbar", (const char *) msg);
16509 :
16510 4 : msg.escape ("\a\b\f\n\r\t\v");
16511 4 : ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg);
16512 :
16513 : /* Restore the original message length setting. */
16514 4 : pp_line_cutoff (pp) = saved_cutoff;
16515 4 : }
16516 :
16517 : /* Run all of the selftests within this file. */
16518 :
16519 : void
16520 4 : tree_cc_tests ()
16521 : {
16522 4 : test_integer_constants ();
16523 4 : test_identifiers ();
16524 4 : test_labels ();
16525 4 : test_vector_cst_patterns ();
16526 4 : test_location_wrappers ();
16527 4 : test_predicates ();
16528 4 : test_escaped_strings ();
16529 4 : }
16530 :
16531 : } // namespace selftest
16532 :
16533 : #endif /* CHECKING_P */
16534 :
16535 : #include "gt-tree.h"
|