Branch data Line data Source code
1 : : /* Language-independent node constructors for parse phase of GNU compiler.
2 : : Copyright (C) 1987-2025 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify it under
7 : : the terms of the GNU General Public License as published by the Free
8 : : Software Foundation; either version 3, or (at your option) any later
9 : : version.
10 : :
11 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : : /* This file contains the low level primitives for operating on tree nodes,
21 : : including allocation, list operations, interning of identifiers,
22 : : construction of data type nodes and statement nodes,
23 : : and construction of type conversion nodes. It also contains
24 : : tables index by tree code that describe how to take apart
25 : : nodes of that code.
26 : :
27 : : It is intended to be language-independent but can occasionally
28 : : calls language-dependent routines. */
29 : :
30 : : #include "config.h"
31 : : #include "system.h"
32 : : #include "coretypes.h"
33 : : #include "backend.h"
34 : : #include "target.h"
35 : : #include "tree.h"
36 : : #include "gimple.h"
37 : : #include "tree-pass.h"
38 : : #include "ssa.h"
39 : : #include "cgraph.h"
40 : : #include "diagnostic.h"
41 : : #include "flags.h"
42 : : #include "alias.h"
43 : : #include "fold-const.h"
44 : : #include "stor-layout.h"
45 : : #include "calls.h"
46 : : #include "attribs.h"
47 : : #include "toplev.h" /* get_random_seed */
48 : : #include "output.h"
49 : : #include "common/common-target.h"
50 : : #include "langhooks.h"
51 : : #include "tree-inline.h"
52 : : #include "tree-iterator.h"
53 : : #include "internal-fn.h"
54 : : #include "gimple-iterator.h"
55 : : #include "gimplify.h"
56 : : #include "tree-dfa.h"
57 : : #include "langhooks-def.h"
58 : : #include "tree-diagnostic.h"
59 : : #include "except.h"
60 : : #include "builtins.h"
61 : : #include "print-tree.h"
62 : : #include "ipa-utils.h"
63 : : #include "selftest.h"
64 : : #include "stringpool.h"
65 : : #include "attribs.h"
66 : : #include "rtl.h"
67 : : #include "regs.h"
68 : : #include "tree-vector-builder.h"
69 : : #include "gimple-fold.h"
70 : : #include "escaped_string.h"
71 : : #include "gimple-range.h"
72 : : #include "gomp-constants.h"
73 : : #include "dfp.h"
74 : : #include "asan.h"
75 : : #include "ubsan.h"
76 : :
77 : : /* Names of tree components.
78 : : Used for printing out the tree and error messages. */
79 : : #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
80 : : #define END_OF_BASE_TREE_CODES "@dummy",
81 : :
82 : : static const char *const tree_code_name[] = {
83 : : #include "all-tree.def"
84 : : };
85 : :
86 : : #undef DEFTREECODE
87 : : #undef END_OF_BASE_TREE_CODES
88 : :
89 : : /* Each tree code class has an associated string representation.
90 : : These must correspond to the tree_code_class entries. */
91 : :
92 : : const char *const tree_code_class_strings[] =
93 : : {
94 : : "exceptional",
95 : : "constant",
96 : : "type",
97 : : "declaration",
98 : : "reference",
99 : : "comparison",
100 : : "unary",
101 : : "binary",
102 : : "statement",
103 : : "vl_exp",
104 : : "expression"
105 : : };
106 : :
107 : : /* obstack.[ch] explicitly declined to prototype this. */
108 : : extern int _obstack_allocated_p (struct obstack *h, void *obj);
109 : :
110 : : /* Statistics-gathering stuff. */
111 : :
112 : : static uint64_t tree_code_counts[MAX_TREE_CODES];
113 : : uint64_t tree_node_counts[(int) all_kinds];
114 : : uint64_t tree_node_sizes[(int) all_kinds];
115 : :
116 : : /* Keep in sync with tree.h:enum tree_node_kind. */
117 : : static const char * const tree_node_kind_names[] = {
118 : : "decls",
119 : : "types",
120 : : "blocks",
121 : : "stmts",
122 : : "refs",
123 : : "exprs",
124 : : "constants",
125 : : "identifiers",
126 : : "vecs",
127 : : "binfos",
128 : : "ssa names",
129 : : "constructors",
130 : : "random kinds",
131 : : "lang_decl kinds",
132 : : "lang_type kinds",
133 : : "omp clauses",
134 : : };
135 : :
136 : : /* Unique id for next decl created. */
137 : : static GTY(()) int next_decl_uid;
138 : : /* Unique id for next type created. */
139 : : static GTY(()) unsigned next_type_uid = 1;
140 : : /* Unique id for next debug decl created. Use negative numbers,
141 : : to catch erroneous uses. */
142 : : static GTY(()) int next_debug_decl_uid;
143 : :
144 : : /* Since we cannot rehash a type after it is in the table, we have to
145 : : keep the hash code. */
146 : :
147 : : struct GTY((for_user)) type_hash {
148 : : unsigned long hash;
149 : : tree type;
150 : : };
151 : :
152 : : /* Initial size of the hash table (rounded to next prime). */
153 : : #define TYPE_HASH_INITIAL_SIZE 1000
154 : :
155 : : struct type_cache_hasher : ggc_cache_ptr_hash<type_hash>
156 : : {
157 : 6701617350 : static hashval_t hash (type_hash *t) { return t->hash; }
158 : : static bool equal (type_hash *a, type_hash *b);
159 : :
160 : : static int
161 : 1670740589 : keep_cache_entry (type_hash *&t)
162 : : {
163 : 1670740589 : return ggc_marked_p (t->type);
164 : : }
165 : : };
166 : :
167 : : /* Now here is the hash table. When recording a type, it is added to
168 : : the slot whose index is the hash code. Note that the hash table is
169 : : used for several kinds of types (function types, array types and
170 : : array index range types, for now). While all these live in the
171 : : same table, they are completely independent, and the hash code is
172 : : computed differently for each of these. */
173 : :
174 : : static GTY ((cache)) hash_table<type_cache_hasher> *type_hash_table;
175 : :
176 : : /* Hash table and temporary node for larger integer const values. */
177 : : static GTY (()) tree int_cst_node;
178 : :
179 : : struct int_cst_hasher : ggc_cache_ptr_hash<tree_node>
180 : : {
181 : : static hashval_t hash (tree t);
182 : : static bool equal (tree x, tree y);
183 : : };
184 : :
185 : : static GTY ((cache)) hash_table<int_cst_hasher> *int_cst_hash_table;
186 : :
187 : : /* Class and variable for making sure that there is a single POLY_INT_CST
188 : : for a given value. */
189 : : struct poly_int_cst_hasher : ggc_cache_ptr_hash<tree_node>
190 : : {
191 : : typedef std::pair<tree, const poly_wide_int *> compare_type;
192 : : static hashval_t hash (tree t);
193 : : static bool equal (tree x, const compare_type &y);
194 : : };
195 : :
196 : : static GTY ((cache)) hash_table<poly_int_cst_hasher> *poly_int_cst_hash_table;
197 : :
198 : : /* Hash table for optimization flags and target option flags. Use the same
199 : : hash table for both sets of options. Nodes for building the current
200 : : optimization and target option nodes. The assumption is most of the time
201 : : the options created will already be in the hash table, so we avoid
202 : : allocating and freeing up a node repeatably. */
203 : : static GTY (()) tree cl_optimization_node;
204 : : static GTY (()) tree cl_target_option_node;
205 : :
206 : : struct cl_option_hasher : ggc_cache_ptr_hash<tree_node>
207 : : {
208 : : static hashval_t hash (tree t);
209 : : static bool equal (tree x, tree y);
210 : : };
211 : :
212 : : static GTY ((cache)) hash_table<cl_option_hasher> *cl_option_hash_table;
213 : :
214 : 699639 : struct gt_value_expr_mark_data {
215 : : hash_set<tree> pset;
216 : : auto_vec<tree, 16> to_mark;
217 : : };
218 : :
219 : : /* Callback called through walk_tree_1 to discover DECL_HAS_VALUE_EXPR_P
220 : : VAR_DECLs which weren't marked yet, in that case marks them and
221 : : walks their DECL_VALUE_EXPR expressions. */
222 : :
223 : : static tree
224 : 12864044 : gt_value_expr_mark_2 (tree *tp, int *, void *data)
225 : : {
226 : 12864044 : tree t = *tp;
227 : 12864044 : if (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t) && !ggc_marked_p (t))
228 : : {
229 : 1022 : tree dve = DECL_VALUE_EXPR (t);
230 : 1022 : gt_value_expr_mark_data *d = (gt_value_expr_mark_data *) data;
231 : 1022 : walk_tree_1 (&dve, gt_value_expr_mark_2, data, &d->pset, NULL);
232 : 1022 : d->to_mark.safe_push (t);
233 : : }
234 : 12864044 : return NULL_TREE;
235 : : }
236 : :
237 : : /* Callback called through traverse_noresize on the
238 : : value_expr_for_decl hash table. */
239 : :
240 : : int
241 : 4916824 : gt_value_expr_mark_1 (tree_decl_map **e, gt_value_expr_mark_data *data)
242 : : {
243 : 4916824 : if (ggc_marked_p ((*e)->base.from))
244 : 4610897 : walk_tree_1 (&(*e)->to, gt_value_expr_mark_2, data, &data->pset, NULL);
245 : 4916824 : return 1;
246 : : }
247 : :
248 : : /* The value_expr_for_decl hash table can have mappings for trees
249 : : which are only referenced from mappings of other trees in the
250 : : same table, see PR118790. Without this routine, gt_cleare_cache
251 : : could clear hash table slot of a tree which isn't marked but
252 : : will be marked when processing later hash table slot of another
253 : : tree which is marked. This function marks with the above
254 : : helpers marks all the not yet marked DECL_HAS_VALUE_EXPR_P
255 : : VAR_DECLs mentioned in DECL_VALUE_EXPR expressions of marked
256 : : trees and in that case also recurses on their DECL_VALUE_EXPR. */
257 : :
258 : : void
259 : 699639 : gt_value_expr_mark (hash_table<tree_decl_map_cache_hasher> *h)
260 : : {
261 : 699639 : if (!h)
262 : 0 : return;
263 : :
264 : 699639 : gt_value_expr_mark_data data;
265 : 699639 : h->traverse_noresize<gt_value_expr_mark_data *,
266 : 5616463 : gt_value_expr_mark_1> (&data);
267 : 2099939 : for (auto v : data.to_mark)
268 : 1022 : gt_ggc_mx (v);
269 : 699639 : }
270 : :
271 : : /* General tree->tree mapping structure for use in hash tables. */
272 : :
273 : :
274 : : static GTY ((cache))
275 : : hash_table<tree_decl_map_cache_hasher> *debug_expr_for_decl;
276 : :
277 : : static GTY ((cache ("gt_value_expr_mark")))
278 : : hash_table<tree_decl_map_cache_hasher> *value_expr_for_decl;
279 : :
280 : : static GTY ((cache))
281 : : hash_table<tree_vec_map_cache_hasher> *debug_args_for_decl;
282 : :
283 : : static void set_type_quals (tree, int);
284 : : static void print_type_hash_statistics (void);
285 : : static void print_debug_expr_statistics (void);
286 : : static void print_value_expr_statistics (void);
287 : :
288 : : tree global_trees[TI_MAX];
289 : : tree integer_types[itk_none];
290 : :
291 : : bool int_n_enabled_p[NUM_INT_N_ENTS];
292 : : struct int_n_trees_t int_n_trees [NUM_INT_N_ENTS];
293 : :
294 : : bool tree_contains_struct[MAX_TREE_CODES][64];
295 : :
296 : : /* Number of operands for each OMP clause. */
297 : : unsigned const char omp_clause_num_ops[] =
298 : : {
299 : : 0, /* OMP_CLAUSE_ERROR */
300 : : 1, /* OMP_CLAUSE_PRIVATE */
301 : : 1, /* OMP_CLAUSE_SHARED */
302 : : 1, /* OMP_CLAUSE_FIRSTPRIVATE */
303 : : 2, /* OMP_CLAUSE_LASTPRIVATE */
304 : : 5, /* OMP_CLAUSE_REDUCTION */
305 : : 5, /* OMP_CLAUSE_TASK_REDUCTION */
306 : : 5, /* OMP_CLAUSE_IN_REDUCTION */
307 : : 1, /* OMP_CLAUSE_COPYIN */
308 : : 1, /* OMP_CLAUSE_COPYPRIVATE */
309 : : 3, /* OMP_CLAUSE_LINEAR */
310 : : 1, /* OMP_CLAUSE_AFFINITY */
311 : : 2, /* OMP_CLAUSE_ALIGNED */
312 : : 3, /* OMP_CLAUSE_ALLOCATE */
313 : : 1, /* OMP_CLAUSE_DEPEND */
314 : : 1, /* OMP_CLAUSE_NONTEMPORAL */
315 : : 1, /* OMP_CLAUSE_UNIFORM */
316 : : 1, /* OMP_CLAUSE_ENTER */
317 : : 1, /* OMP_CLAUSE_LINK */
318 : : 1, /* OMP_CLAUSE_DETACH */
319 : : 1, /* OMP_CLAUSE_USE_DEVICE_PTR */
320 : : 1, /* OMP_CLAUSE_USE_DEVICE_ADDR */
321 : : 1, /* OMP_CLAUSE_IS_DEVICE_PTR */
322 : : 1, /* OMP_CLAUSE_INCLUSIVE */
323 : : 1, /* OMP_CLAUSE_EXCLUSIVE */
324 : : 2, /* OMP_CLAUSE_FROM */
325 : : 2, /* OMP_CLAUSE_TO */
326 : : 2, /* OMP_CLAUSE_MAP */
327 : : 1, /* OMP_CLAUSE_HAS_DEVICE_ADDR */
328 : : 1, /* OMP_CLAUSE_DOACROSS */
329 : : 3, /* OMP_CLAUSE__MAPPER_BINDING_ */
330 : : 2, /* OMP_CLAUSE__CACHE_ */
331 : : 1, /* OMP_CLAUSE_DESTROY */
332 : : 2, /* OMP_CLAUSE_INIT */
333 : : 1, /* OMP_CLAUSE_USE */
334 : : 1, /* OMP_CLAUSE_INTEROP */
335 : : 2, /* OMP_CLAUSE_GANG */
336 : : 1, /* OMP_CLAUSE_ASYNC */
337 : : 1, /* OMP_CLAUSE_WAIT */
338 : : 0, /* OMP_CLAUSE_AUTO */
339 : : 0, /* OMP_CLAUSE_SEQ */
340 : : 1, /* OMP_CLAUSE__LOOPTEMP_ */
341 : : 1, /* OMP_CLAUSE__REDUCTEMP_ */
342 : : 1, /* OMP_CLAUSE__CONDTEMP_ */
343 : : 1, /* OMP_CLAUSE__SCANTEMP_ */
344 : : 1, /* OMP_CLAUSE_IF */
345 : : 1, /* OMP_CLAUSE_SELF */
346 : : 1, /* OMP_CLAUSE_NUM_THREADS */
347 : : 1, /* OMP_CLAUSE_SCHEDULE */
348 : : 0, /* OMP_CLAUSE_NOWAIT */
349 : : 1, /* OMP_CLAUSE_ORDERED */
350 : : 0, /* OMP_CLAUSE_DEFAULT */
351 : : 3, /* OMP_CLAUSE_COLLAPSE */
352 : : 0, /* OMP_CLAUSE_UNTIED */
353 : : 1, /* OMP_CLAUSE_FINAL */
354 : : 0, /* OMP_CLAUSE_MERGEABLE */
355 : : 1, /* OMP_CLAUSE_DEVICE */
356 : : 1, /* OMP_CLAUSE_DIST_SCHEDULE */
357 : : 0, /* OMP_CLAUSE_INBRANCH */
358 : : 0, /* OMP_CLAUSE_NOTINBRANCH */
359 : : 2, /* OMP_CLAUSE_NUM_TEAMS */
360 : : 1, /* OMP_CLAUSE_THREAD_LIMIT */
361 : : 0, /* OMP_CLAUSE_PROC_BIND */
362 : : 1, /* OMP_CLAUSE_SAFELEN */
363 : : 1, /* OMP_CLAUSE_SIMDLEN */
364 : : 0, /* OMP_CLAUSE_DEVICE_TYPE */
365 : : 0, /* OMP_CLAUSE_FOR */
366 : : 0, /* OMP_CLAUSE_PARALLEL */
367 : : 0, /* OMP_CLAUSE_SECTIONS */
368 : : 0, /* OMP_CLAUSE_TASKGROUP */
369 : : 1, /* OMP_CLAUSE_PRIORITY */
370 : : 1, /* OMP_CLAUSE_GRAINSIZE */
371 : : 1, /* OMP_CLAUSE_NUM_TASKS */
372 : : 0, /* OMP_CLAUSE_NOGROUP */
373 : : 0, /* OMP_CLAUSE_THREADS */
374 : : 0, /* OMP_CLAUSE_SIMD */
375 : : 1, /* OMP_CLAUSE_HINT */
376 : : 0, /* OMP_CLAUSE_DEFAULTMAP */
377 : : 0, /* OMP_CLAUSE_ORDER */
378 : : 0, /* OMP_CLAUSE_BIND */
379 : : 1, /* OMP_CLAUSE_FILTER */
380 : : 1, /* OMP_CLAUSE_INDIRECT */
381 : : 1, /* OMP_CLAUSE_PARTIAL */
382 : : 0, /* OMP_CLAUSE_FULL */
383 : : 1, /* OMP_CLAUSE_SIZES */
384 : : 1, /* OMP_CLAUSE__SIMDUID_ */
385 : : 0, /* OMP_CLAUSE__SIMT_ */
386 : : 0, /* OMP_CLAUSE_INDEPENDENT */
387 : : 1, /* OMP_CLAUSE_WORKER */
388 : : 1, /* OMP_CLAUSE_VECTOR */
389 : : 1, /* OMP_CLAUSE_NUM_GANGS */
390 : : 1, /* OMP_CLAUSE_NUM_WORKERS */
391 : : 1, /* OMP_CLAUSE_VECTOR_LENGTH */
392 : : 3, /* OMP_CLAUSE_TILE */
393 : : 0, /* OMP_CLAUSE_IF_PRESENT */
394 : : 0, /* OMP_CLAUSE_FINALIZE */
395 : : 0, /* OMP_CLAUSE_NOHOST */
396 : : 1, /* OMP_CLAUSE_NOVARIANTS */
397 : : 1, /* OMP_CLAUSE_NOCONTEXT */
398 : : };
399 : :
400 : : const char * const omp_clause_code_name[] =
401 : : {
402 : : "error_clause",
403 : : "private",
404 : : "shared",
405 : : "firstprivate",
406 : : "lastprivate",
407 : : "reduction",
408 : : "task_reduction",
409 : : "in_reduction",
410 : : "copyin",
411 : : "copyprivate",
412 : : "linear",
413 : : "affinity",
414 : : "aligned",
415 : : "allocate",
416 : : "depend",
417 : : "nontemporal",
418 : : "uniform",
419 : : "enter",
420 : : "link",
421 : : "detach",
422 : : "use_device_ptr",
423 : : "use_device_addr",
424 : : "is_device_ptr",
425 : : "inclusive",
426 : : "exclusive",
427 : : "from",
428 : : "to",
429 : : "map",
430 : : "has_device_addr",
431 : : "doacross",
432 : : "_mapper_binding_",
433 : : "_cache_",
434 : : "destroy",
435 : : "init",
436 : : "use",
437 : : "interop",
438 : : "gang",
439 : : "async",
440 : : "wait",
441 : : "auto",
442 : : "seq",
443 : : "_looptemp_",
444 : : "_reductemp_",
445 : : "_condtemp_",
446 : : "_scantemp_",
447 : : "if",
448 : : "self",
449 : : "num_threads",
450 : : "schedule",
451 : : "nowait",
452 : : "ordered",
453 : : "default",
454 : : "collapse",
455 : : "untied",
456 : : "final",
457 : : "mergeable",
458 : : "device",
459 : : "dist_schedule",
460 : : "inbranch",
461 : : "notinbranch",
462 : : "num_teams",
463 : : "thread_limit",
464 : : "proc_bind",
465 : : "safelen",
466 : : "simdlen",
467 : : "device_type",
468 : : "for",
469 : : "parallel",
470 : : "sections",
471 : : "taskgroup",
472 : : "priority",
473 : : "grainsize",
474 : : "num_tasks",
475 : : "nogroup",
476 : : "threads",
477 : : "simd",
478 : : "hint",
479 : : "defaultmap",
480 : : "order",
481 : : "bind",
482 : : "filter",
483 : : "indirect",
484 : : "partial",
485 : : "full",
486 : : "sizes",
487 : : "_simduid_",
488 : : "_simt_",
489 : : "independent",
490 : : "worker",
491 : : "vector",
492 : : "num_gangs",
493 : : "num_workers",
494 : : "vector_length",
495 : : "tile",
496 : : "if_present",
497 : : "finalize",
498 : : "nohost",
499 : : "novariants",
500 : : "nocontext",
501 : : };
502 : :
503 : : /* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric
504 : : clause names, but for use in diagnostics etc. would like to use the "user"
505 : : clause names. */
506 : :
507 : : const char *
508 : 465 : user_omp_clause_code_name (tree clause, bool oacc)
509 : : {
510 : : /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to
511 : : distinguish clauses as seen by the user. See also where front ends do
512 : : 'build_omp_clause' with 'OMP_CLAUSE_MAP'. */
513 : 930 : if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
514 : 465 : switch (OMP_CLAUSE_MAP_KIND (clause))
515 : : {
516 : : case GOMP_MAP_FORCE_ALLOC:
517 : : case GOMP_MAP_ALLOC: return "create";
518 : 0 : case GOMP_MAP_FORCE_TO:
519 : 0 : case GOMP_MAP_TO: return "copyin";
520 : 0 : case GOMP_MAP_FORCE_FROM:
521 : 0 : case GOMP_MAP_FROM: return "copyout";
522 : 381 : case GOMP_MAP_FORCE_TOFROM:
523 : 381 : case GOMP_MAP_TOFROM: return "copy";
524 : 0 : case GOMP_MAP_RELEASE: return "delete";
525 : 0 : case GOMP_MAP_FORCE_PRESENT: return "present";
526 : 42 : case GOMP_MAP_ATTACH: return "attach";
527 : 42 : case GOMP_MAP_FORCE_DETACH:
528 : 42 : case GOMP_MAP_DETACH: return "detach";
529 : 0 : case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
530 : 0 : case GOMP_MAP_LINK: return "link";
531 : 0 : case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
532 : : default: break;
533 : : }
534 : :
535 : 0 : return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
536 : : }
537 : :
538 : :
539 : : /* Return the tree node structure used by tree code CODE. */
540 : :
541 : : static inline enum tree_node_structure_enum
542 : 35562939725 : tree_node_structure_for_code (enum tree_code code)
543 : : {
544 : 35562939725 : switch (TREE_CODE_CLASS (code))
545 : : {
546 : 8893684573 : case tcc_declaration:
547 : 8893684573 : switch (code)
548 : : {
549 : : case CONST_DECL: return TS_CONST_DECL;
550 : : case DEBUG_EXPR_DECL: return TS_DECL_WRTL;
551 : : case FIELD_DECL: return TS_FIELD_DECL;
552 : : case FUNCTION_DECL: return TS_FUNCTION_DECL;
553 : : case LABEL_DECL: return TS_LABEL_DECL;
554 : : case PARM_DECL: return TS_PARM_DECL;
555 : : case RESULT_DECL: return TS_RESULT_DECL;
556 : : case TRANSLATION_UNIT_DECL: return TS_TRANSLATION_UNIT_DECL;
557 : : case TYPE_DECL: return TS_TYPE_DECL;
558 : : case VAR_DECL: return TS_VAR_DECL;
559 : : default: return TS_DECL_NON_COMMON;
560 : : }
561 : :
562 : : case tcc_type: return TS_TYPE_NON_COMMON;
563 : :
564 : 8996971243 : case tcc_binary:
565 : 8996971243 : case tcc_comparison:
566 : 8996971243 : case tcc_expression:
567 : 8996971243 : case tcc_reference:
568 : 8996971243 : case tcc_statement:
569 : 8996971243 : case tcc_unary:
570 : 8996971243 : case tcc_vl_exp: return TS_EXP;
571 : :
572 : 12756127299 : default: /* tcc_constant and tcc_exceptional */
573 : 12756127299 : break;
574 : : }
575 : :
576 : 12756127299 : switch (code)
577 : : {
578 : : /* tcc_constant cases. */
579 : : case COMPLEX_CST: return TS_COMPLEX;
580 : 286682 : case FIXED_CST: return TS_FIXED_CST;
581 : 417487735 : case INTEGER_CST: return TS_INT_CST;
582 : 286682 : case POLY_INT_CST: return TS_POLY_INT_CST;
583 : 38714786 : case REAL_CST: return TS_REAL_CST;
584 : 217116687 : case STRING_CST: return TS_STRING;
585 : 11346947 : case VECTOR_CST: return TS_VECTOR;
586 : 987251 : case VOID_CST: return TS_TYPED;
587 : 286853 : case RAW_DATA_CST: return TS_RAW_DATA_CST;
588 : :
589 : : /* tcc_exceptional cases. */
590 : 591923960 : case BLOCK: return TS_BLOCK;
591 : 111840170 : case CONSTRUCTOR: return TS_CONSTRUCTOR;
592 : : case ERROR_MARK: return TS_COMMON;
593 : 8683776 : case IDENTIFIER_NODE: return TS_IDENTIFIER;
594 : 815951 : case OMP_CLAUSE: return TS_OMP_CLAUSE;
595 : 1700075 : case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
596 : : case PLACEHOLDER_EXPR: return TS_COMMON;
597 : 249621662 : case SSA_NAME: return TS_SSA_NAME;
598 : 609503329 : case STATEMENT_LIST: return TS_STATEMENT_LIST;
599 : 3581537 : case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
600 : 229634887 : case TREE_BINFO: return TS_BINFO;
601 : 8548885739 : case TREE_LIST: return TS_LIST;
602 : 1711659391 : case TREE_VEC: return TS_VEC;
603 : :
604 : 0 : default:
605 : 0 : gcc_unreachable ();
606 : : }
607 : : }
608 : :
609 : :
610 : : /* Initialize tree_contains_struct to describe the hierarchy of tree
611 : : nodes. */
612 : :
613 : : static void
614 : 286682 : initialize_tree_contains_struct (void)
615 : : {
616 : 286682 : unsigned i;
617 : :
618 : 70523772 : for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
619 : : {
620 : 70237090 : enum tree_code code;
621 : 70237090 : enum tree_node_structure_enum ts_code;
622 : :
623 : 70237090 : code = (enum tree_code) i;
624 : 70237090 : ts_code = tree_node_structure_for_code (code);
625 : :
626 : : /* Mark the TS structure itself. */
627 : 70237090 : tree_contains_struct[code][ts_code] = 1;
628 : :
629 : : /* Mark all the structures that TS is derived from. */
630 : 70237090 : switch (ts_code)
631 : : {
632 : 1146728 : case TS_TYPED:
633 : 1146728 : case TS_BLOCK:
634 : 1146728 : case TS_OPTIMIZATION:
635 : 1146728 : case TS_TARGET_OPTION:
636 : 1146728 : MARK_TS_BASE (code);
637 : 1146728 : break;
638 : :
639 : 57909764 : case TS_COMMON:
640 : 57909764 : case TS_INT_CST:
641 : 57909764 : case TS_POLY_INT_CST:
642 : 57909764 : case TS_REAL_CST:
643 : 57909764 : case TS_FIXED_CST:
644 : 57909764 : case TS_VECTOR:
645 : 57909764 : case TS_STRING:
646 : 57909764 : case TS_RAW_DATA_CST:
647 : 57909764 : case TS_COMPLEX:
648 : 57909764 : case TS_SSA_NAME:
649 : 57909764 : case TS_CONSTRUCTOR:
650 : 57909764 : case TS_EXP:
651 : 57909764 : case TS_STATEMENT_LIST:
652 : 57909764 : MARK_TS_TYPED (code);
653 : 57909764 : break;
654 : :
655 : 1433410 : case TS_IDENTIFIER:
656 : 1433410 : case TS_DECL_MINIMAL:
657 : 1433410 : case TS_TYPE_COMMON:
658 : 1433410 : case TS_LIST:
659 : 1433410 : case TS_VEC:
660 : 1433410 : case TS_BINFO:
661 : 1433410 : case TS_OMP_CLAUSE:
662 : 1433410 : MARK_TS_COMMON (code);
663 : 1433410 : break;
664 : :
665 : 0 : case TS_TYPE_WITH_LANG_SPECIFIC:
666 : 0 : MARK_TS_TYPE_COMMON (code);
667 : 0 : break;
668 : :
669 : 6020322 : case TS_TYPE_NON_COMMON:
670 : 6020322 : MARK_TS_TYPE_WITH_LANG_SPECIFIC (code);
671 : 6020322 : break;
672 : :
673 : 0 : case TS_DECL_COMMON:
674 : 0 : MARK_TS_DECL_MINIMAL (code);
675 : 0 : break;
676 : :
677 : 573364 : case TS_DECL_WRTL:
678 : 573364 : case TS_CONST_DECL:
679 : 573364 : MARK_TS_DECL_COMMON (code);
680 : 573364 : break;
681 : :
682 : 860046 : case TS_DECL_NON_COMMON:
683 : 860046 : MARK_TS_DECL_WITH_VIS (code);
684 : 860046 : break;
685 : :
686 : 860046 : case TS_DECL_WITH_VIS:
687 : 860046 : case TS_PARM_DECL:
688 : 860046 : case TS_LABEL_DECL:
689 : 860046 : case TS_RESULT_DECL:
690 : 860046 : MARK_TS_DECL_WRTL (code);
691 : 860046 : break;
692 : :
693 : 286682 : case TS_FIELD_DECL:
694 : 286682 : MARK_TS_DECL_COMMON (code);
695 : 286682 : break;
696 : :
697 : 286682 : case TS_VAR_DECL:
698 : 286682 : MARK_TS_DECL_WITH_VIS (code);
699 : 286682 : break;
700 : :
701 : 573364 : case TS_TYPE_DECL:
702 : 573364 : case TS_FUNCTION_DECL:
703 : 573364 : MARK_TS_DECL_NON_COMMON (code);
704 : 573364 : break;
705 : :
706 : 286682 : case TS_TRANSLATION_UNIT_DECL:
707 : 286682 : MARK_TS_DECL_COMMON (code);
708 : 286682 : break;
709 : :
710 : : default:
711 : : gcc_unreachable ();
712 : : }
713 : : }
714 : :
715 : : /* Basic consistency checks for attributes used in fold. */
716 : 286682 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
717 : 286682 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
718 : 286682 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
719 : 286682 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
720 : 286682 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
721 : 286682 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
722 : 286682 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
723 : 286682 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
724 : 286682 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
725 : 286682 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
726 : 286682 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
727 : 286682 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
728 : 286682 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
729 : 286682 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
730 : 286682 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
731 : 286682 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
732 : 286682 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
733 : 286682 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
734 : 286682 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
735 : 286682 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
736 : 286682 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
737 : 286682 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
738 : 286682 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
739 : 286682 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
740 : 286682 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
741 : 286682 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
742 : 286682 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
743 : 286682 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
744 : 286682 : gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
745 : 286682 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
746 : 286682 : gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
747 : 286682 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
748 : 286682 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
749 : 286682 : gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
750 : 286682 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
751 : 286682 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
752 : 286682 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
753 : 286682 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
754 : 286682 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_MINIMAL]);
755 : 286682 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_COMMON]);
756 : 286682 : }
757 : :
758 : :
759 : : /* Init tree.cc. */
760 : :
761 : : void
762 : 286682 : init_ttree (void)
763 : : {
764 : : /* Initialize the hash table of types. */
765 : 286682 : type_hash_table
766 : 286682 : = hash_table<type_cache_hasher>::create_ggc (TYPE_HASH_INITIAL_SIZE);
767 : :
768 : 286682 : debug_expr_for_decl
769 : 286682 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
770 : :
771 : 286682 : value_expr_for_decl
772 : 286682 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
773 : :
774 : 286682 : int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024);
775 : :
776 : 286682 : poly_int_cst_hash_table = hash_table<poly_int_cst_hasher>::create_ggc (64);
777 : :
778 : 286682 : int_cst_node = make_int_cst (1, 1);
779 : :
780 : 286682 : cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64);
781 : :
782 : 286682 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
783 : 286682 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
784 : :
785 : : /* Initialize the tree_contains_struct array. */
786 : 286682 : initialize_tree_contains_struct ();
787 : 286682 : lang_hooks.init_ts ();
788 : 286682 : }
789 : :
790 : :
791 : : /* Mapping from prefix to label number. */
792 : :
793 : : struct identifier_hash : ggc_ptr_hash <tree_node>
794 : : {
795 : 33675 : static inline hashval_t hash (tree t)
796 : : {
797 : 33675 : return IDENTIFIER_HASH_VALUE (t);
798 : : }
799 : : };
800 : : struct identifier_count_traits
801 : : : simple_hashmap_traits<identifier_hash, long> {};
802 : : typedef hash_map<tree, long, identifier_count_traits> internal_label_map;
803 : : static GTY(()) internal_label_map *internal_label_nums;
804 : :
805 : : /* Generates an identifier intended to be used internally with the
806 : : given PREFIX. This is intended to be used by the frontend so that
807 : : C++ modules can regenerate appropriate (non-clashing) identifiers on
808 : : stream-in. */
809 : :
810 : : tree
811 : 33492 : generate_internal_label (const char *prefix)
812 : : {
813 : 33492 : tree prefix_id = get_identifier (prefix);
814 : 33492 : if (!internal_label_nums)
815 : 2644 : internal_label_nums = internal_label_map::create_ggc();
816 : 33492 : long &num = internal_label_nums->get_or_insert (prefix_id);
817 : :
818 : 33492 : char tmp[32];
819 : 33492 : ASM_GENERATE_INTERNAL_LABEL (tmp, prefix, num++);
820 : :
821 : 33492 : tree id = get_identifier (tmp);
822 : 33492 : IDENTIFIER_INTERNAL_P (id) = true;
823 : :
824 : : /* Cache the prefix on the identifier so we can retrieve it later. */
825 : 33492 : TREE_CHAIN (id) = prefix_id;
826 : :
827 : 33492 : return id;
828 : : }
829 : :
830 : : /* Get the PREFIX we created the internal identifier LABEL with. */
831 : :
832 : : const char *
833 : 7 : prefix_for_internal_label (tree label)
834 : : {
835 : 7 : gcc_assert (IDENTIFIER_INTERNAL_P (label)
836 : : && !IDENTIFIER_TRANSPARENT_ALIAS (label)
837 : : && TREE_CHAIN (label)
838 : : && TREE_CODE (TREE_CHAIN (label)) == IDENTIFIER_NODE);
839 : 7 : return IDENTIFIER_POINTER (TREE_CHAIN (label));
840 : : }
841 : :
842 : : /* The name of the object as the assembler will see it (but before any
843 : : translations made by ASM_OUTPUT_LABELREF). Often this is the same
844 : : as DECL_NAME. It is an IDENTIFIER_NODE. */
845 : : tree
846 : 1566848065 : decl_assembler_name (tree decl)
847 : : {
848 : 1566848065 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
849 : 131849088 : lang_hooks.set_decl_assembler_name (decl);
850 : 1566848065 : return DECL_ASSEMBLER_NAME_RAW (decl);
851 : : }
852 : :
853 : : /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
854 : : (either of which may be NULL). Inform the FE, if this changes the
855 : : name. */
856 : :
857 : : void
858 : 760221588 : overwrite_decl_assembler_name (tree decl, tree name)
859 : : {
860 : 760221588 : if (DECL_ASSEMBLER_NAME_RAW (decl) != name)
861 : 404119435 : lang_hooks.overwrite_decl_assembler_name (decl, name);
862 : 760221588 : }
863 : :
864 : : /* Return true if DECL may need an assembler name to be set. */
865 : :
866 : : static inline bool
867 : 12800952 : need_assembler_name_p (tree decl)
868 : : {
869 : : /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
870 : : Rule merging. This makes type_odr_p to return true on those types during
871 : : LTO and by comparing the mangled name, we can say what types are intended
872 : : to be equivalent across compilation unit.
873 : :
874 : : We do not store names of type_in_anonymous_namespace_p.
875 : :
876 : : Record, union and enumeration type have linkage that allows use
877 : : to check type_in_anonymous_namespace_p. We do not mangle compound types
878 : : that always can be compared structurally.
879 : :
880 : : Similarly for builtin types, we compare properties of their main variant.
881 : : A special case are integer types where mangling do make differences
882 : : between char/signed char/unsigned char etc. Storing name for these makes
883 : : e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
884 : : See cp/mangle.cc:write_builtin_type for details. */
885 : :
886 : 12800952 : if (TREE_CODE (decl) == TYPE_DECL)
887 : : {
888 : 390274 : if (DECL_NAME (decl)
889 : 333697 : && decl == TYPE_NAME (TREE_TYPE (decl))
890 : 324796 : && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
891 : 275900 : && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
892 : 272880 : && ((TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
893 : 244152 : && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE)
894 : 29091 : || TYPE_CXX_ODR_P (TREE_TYPE (decl)))
895 : 263447 : && (type_with_linkage_p (TREE_TYPE (decl))
896 : 244905 : || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
897 : 532517 : && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
898 : 142243 : return !DECL_ASSEMBLER_NAME_SET_P (decl);
899 : 248031 : return false;
900 : : }
901 : : /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
902 : 12410678 : if (!VAR_OR_FUNCTION_DECL_P (decl))
903 : : return false;
904 : :
905 : : /* If DECL already has its assembler name set, it does not need a
906 : : new one. */
907 : 11218378 : if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
908 : 11218378 : || DECL_ASSEMBLER_NAME_SET_P (decl))
909 : : return false;
910 : :
911 : : /* Abstract decls do not need an assembler name, except they
912 : : can be looked up by autofdo. */
913 : 6413671 : if (DECL_ABSTRACT_P (decl) && !flag_auto_profile)
914 : : return false;
915 : :
916 : : /* For VAR_DECLs, only static, public and external symbols need an
917 : : assembler name. */
918 : 6410066 : if (VAR_P (decl)
919 : 527579 : && !TREE_STATIC (decl)
920 : 527197 : && !TREE_PUBLIC (decl)
921 : 6936352 : && !DECL_EXTERNAL (decl))
922 : : return false;
923 : :
924 : 5883780 : if (TREE_CODE (decl) == FUNCTION_DECL)
925 : : {
926 : : /* Do not set assembler name on builtins. Allow RTL expansion to
927 : : decide whether to expand inline or via a regular call. */
928 : 5882487 : if (fndecl_built_in_p (decl)
929 : 5882487 : && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
930 : : return false;
931 : :
932 : : /* Functions represented in the callgraph need an assembler name. */
933 : 1352825 : if (cgraph_node::get (decl) != NULL)
934 : : return true;
935 : :
936 : : /* Unused and not public functions don't need an assembler name. */
937 : 239154 : if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
938 : : return false;
939 : : }
940 : :
941 : : return true;
942 : : }
943 : :
944 : : /* If T needs an assembler name, have one created for it. */
945 : :
946 : : void
947 : 12800952 : assign_assembler_name_if_needed (tree t)
948 : : {
949 : 12800952 : if (need_assembler_name_p (t))
950 : : {
951 : : /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
952 : : diagnostics that use input_location to show locus
953 : : information. The problem here is that, at this point,
954 : : input_location is generally anchored to the end of the file
955 : : (since the parser is long gone), so we don't have a good
956 : : position to pin it to.
957 : :
958 : : To alleviate this problem, this uses the location of T's
959 : : declaration. Examples of this are
960 : : testsuite/g++.dg/template/cond2.C and
961 : : testsuite/g++.dg/template/pr35240.C. */
962 : 1494153 : location_t saved_location = input_location;
963 : 1494153 : input_location = DECL_SOURCE_LOCATION (t);
964 : :
965 : 1494153 : decl_assembler_name (t);
966 : :
967 : 1494153 : input_location = saved_location;
968 : : }
969 : 12800952 : }
970 : :
971 : : /* When the target supports COMDAT groups, this indicates which group the
972 : : DECL is associated with. This can be either an IDENTIFIER_NODE or a
973 : : decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
974 : : tree
975 : 360837459 : decl_comdat_group (const_tree node)
976 : : {
977 : 360837459 : struct symtab_node *snode = symtab_node::get (node);
978 : 360837459 : if (!snode)
979 : : return NULL;
980 : 345113569 : return snode->get_comdat_group ();
981 : : }
982 : :
983 : : /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
984 : : tree
985 : 11738 : decl_comdat_group_id (const_tree node)
986 : : {
987 : 11738 : struct symtab_node *snode = symtab_node::get (node);
988 : 11738 : if (!snode)
989 : : return NULL;
990 : 11738 : return snode->get_comdat_group_id ();
991 : : }
992 : :
993 : : /* When the target supports named section, return its name as IDENTIFIER_NODE
994 : : or NULL if it is in no section. */
995 : : const char *
996 : 677275508 : decl_section_name (const_tree node)
997 : : {
998 : 677275508 : struct symtab_node *snode = symtab_node::get (node);
999 : 677275508 : if (!snode)
1000 : : return NULL;
1001 : 533087743 : return snode->get_section ();
1002 : : }
1003 : :
1004 : : /* Set section name of NODE to VALUE (that is expected to be
1005 : : identifier node) */
1006 : : void
1007 : 1796023 : set_decl_section_name (tree node, const char *value)
1008 : : {
1009 : 1796023 : struct symtab_node *snode;
1010 : :
1011 : 1796023 : if (value == NULL)
1012 : : {
1013 : 55 : snode = symtab_node::get (node);
1014 : 55 : if (!snode)
1015 : : return;
1016 : : }
1017 : 1795968 : else if (VAR_P (node))
1018 : 1552394 : snode = varpool_node::get_create (node);
1019 : : else
1020 : 243574 : snode = cgraph_node::get_create (node);
1021 : 1796023 : snode->set_section (value);
1022 : : }
1023 : :
1024 : : /* Set section name of NODE to match the section name of OTHER.
1025 : :
1026 : : set_decl_section_name (decl, other) is equivalent to
1027 : : set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more
1028 : : efficient. */
1029 : : void
1030 : 13658227 : set_decl_section_name (tree decl, const_tree other)
1031 : : {
1032 : 13658227 : struct symtab_node *other_node = symtab_node::get (other);
1033 : 13658227 : if (other_node)
1034 : : {
1035 : 13657881 : struct symtab_node *decl_node;
1036 : 13657881 : if (VAR_P (decl))
1037 : 23 : decl_node = varpool_node::get_create (decl);
1038 : : else
1039 : 13657858 : decl_node = cgraph_node::get_create (decl);
1040 : 13657881 : decl_node->set_section (*other_node);
1041 : : }
1042 : : else
1043 : : {
1044 : 346 : struct symtab_node *decl_node = symtab_node::get (decl);
1045 : 346 : if (!decl_node)
1046 : : return;
1047 : 0 : decl_node->set_section (NULL);
1048 : : }
1049 : : }
1050 : :
1051 : : /* Return TLS model of a variable NODE. */
1052 : : enum tls_model
1053 : 239621183 : decl_tls_model (const_tree node)
1054 : : {
1055 : 239621183 : struct varpool_node *snode = varpool_node::get (node);
1056 : 239621183 : if (!snode)
1057 : : return TLS_MODEL_NONE;
1058 : 202359963 : return snode->tls_model;
1059 : : }
1060 : :
1061 : : /* Set TLS model of variable NODE to MODEL. */
1062 : : void
1063 : 35188 : set_decl_tls_model (tree node, enum tls_model model)
1064 : : {
1065 : 35188 : struct varpool_node *vnode;
1066 : :
1067 : 35188 : if (model == TLS_MODEL_NONE)
1068 : : {
1069 : 5483 : vnode = varpool_node::get (node);
1070 : 5483 : if (!vnode)
1071 : : return;
1072 : : }
1073 : : else
1074 : 29705 : vnode = varpool_node::get_create (node);
1075 : 29705 : vnode->tls_model = model;
1076 : : }
1077 : :
1078 : : /* Compute the number of bytes occupied by a tree with code CODE.
1079 : : This function cannot be used for nodes that have variable sizes,
1080 : : including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
1081 : : size_t
1082 : 15676497929 : tree_code_size (enum tree_code code)
1083 : : {
1084 : 15676497929 : switch (TREE_CODE_CLASS (code))
1085 : : {
1086 : 3874325328 : case tcc_declaration: /* A decl node */
1087 : 3874325328 : switch (code)
1088 : : {
1089 : : case FIELD_DECL: return sizeof (tree_field_decl);
1090 : : case PARM_DECL: return sizeof (tree_parm_decl);
1091 : 214552136 : case VAR_DECL: return sizeof (tree_var_decl);
1092 : : case LABEL_DECL: return sizeof (tree_label_decl);
1093 : : case RESULT_DECL: return sizeof (tree_result_decl);
1094 : 31302325 : case CONST_DECL: return sizeof (tree_const_decl);
1095 : : case TYPE_DECL: return sizeof (tree_type_decl);
1096 : 1336296305 : case FUNCTION_DECL: return sizeof (tree_function_decl);
1097 : : case DEBUG_EXPR_DECL: return sizeof (tree_decl_with_rtl);
1098 : : case TRANSLATION_UNIT_DECL: return sizeof (tree_translation_unit_decl);
1099 : : case NAMESPACE_DECL:
1100 : : case IMPORTED_DECL:
1101 : : case NAMELIST_DECL: return sizeof (tree_decl_non_common);
1102 : 233284348 : default:
1103 : 233284348 : gcc_checking_assert (code >= NUM_TREE_CODES);
1104 : 233284348 : return lang_hooks.tree_size (code);
1105 : : }
1106 : :
1107 : 2671665037 : case tcc_type: /* a type node */
1108 : 2671665037 : switch (code)
1109 : : {
1110 : : case OFFSET_TYPE:
1111 : : case ENUMERAL_TYPE:
1112 : : case BOOLEAN_TYPE:
1113 : : case INTEGER_TYPE:
1114 : : case REAL_TYPE:
1115 : : case OPAQUE_TYPE:
1116 : : case POINTER_TYPE:
1117 : : case REFERENCE_TYPE:
1118 : : case NULLPTR_TYPE:
1119 : : case FIXED_POINT_TYPE:
1120 : : case COMPLEX_TYPE:
1121 : : case VECTOR_TYPE:
1122 : : case ARRAY_TYPE:
1123 : : case RECORD_TYPE:
1124 : : case UNION_TYPE:
1125 : : case QUAL_UNION_TYPE:
1126 : : case VOID_TYPE:
1127 : : case FUNCTION_TYPE:
1128 : : case METHOD_TYPE:
1129 : : case BITINT_TYPE:
1130 : : case LANG_TYPE: return sizeof (tree_type_non_common);
1131 : 624283922 : default:
1132 : 624283922 : gcc_checking_assert (code >= NUM_TREE_CODES);
1133 : 624283922 : return lang_hooks.tree_size (code);
1134 : : }
1135 : :
1136 : 4029496562 : case tcc_reference: /* a reference */
1137 : 4029496562 : case tcc_expression: /* an expression */
1138 : 4029496562 : case tcc_statement: /* an expression with side effects */
1139 : 4029496562 : case tcc_comparison: /* a comparison expression */
1140 : 4029496562 : case tcc_unary: /* a unary arithmetic expression */
1141 : 4029496562 : case tcc_binary: /* a binary arithmetic expression */
1142 : 4029496562 : return (sizeof (struct tree_exp)
1143 : 4029496562 : + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
1144 : :
1145 : 42866305 : case tcc_constant: /* a constant */
1146 : 42866305 : switch (code)
1147 : : {
1148 : : case VOID_CST: return sizeof (tree_typed);
1149 : 0 : case INTEGER_CST: gcc_unreachable ();
1150 : : case POLY_INT_CST: return sizeof (tree_poly_int_cst);
1151 : 42020978 : case REAL_CST: return sizeof (tree_real_cst);
1152 : : case FIXED_CST: return sizeof (tree_fixed_cst);
1153 : : case COMPLEX_CST: return sizeof (tree_complex);
1154 : : case RAW_DATA_CST: return sizeof (tree_raw_data);
1155 : 0 : case VECTOR_CST: gcc_unreachable ();
1156 : 0 : case STRING_CST: gcc_unreachable ();
1157 : 65574 : default:
1158 : 65574 : gcc_checking_assert (code >= NUM_TREE_CODES);
1159 : 65574 : return lang_hooks.tree_size (code);
1160 : : }
1161 : :
1162 : 5058144697 : case tcc_exceptional: /* something random, like an identifier. */
1163 : 5058144697 : switch (code)
1164 : : {
1165 : 1620184235 : case IDENTIFIER_NODE: return lang_hooks.identifier_size;
1166 : : case TREE_LIST: return sizeof (tree_list);
1167 : :
1168 : : case ERROR_MARK:
1169 : : case PLACEHOLDER_EXPR: return sizeof (tree_common);
1170 : :
1171 : 0 : case TREE_VEC: gcc_unreachable ();
1172 : 0 : case OMP_CLAUSE: gcc_unreachable ();
1173 : :
1174 : : case SSA_NAME: return sizeof (tree_ssa_name);
1175 : :
1176 : : case STATEMENT_LIST: return sizeof (tree_statement_list);
1177 : 264924228 : case BLOCK: return sizeof (struct tree_block);
1178 : : case CONSTRUCTOR: return sizeof (tree_constructor);
1179 : : case OPTIMIZATION_NODE: return sizeof (tree_optimization_option);
1180 : : case TARGET_OPTION_NODE: return sizeof (tree_target_option);
1181 : :
1182 : 1311047864 : default:
1183 : 1311047864 : gcc_checking_assert (code >= NUM_TREE_CODES);
1184 : 1311047864 : return lang_hooks.tree_size (code);
1185 : : }
1186 : :
1187 : 0 : default:
1188 : 0 : gcc_unreachable ();
1189 : : }
1190 : : }
1191 : :
1192 : : /* Compute the number of bytes occupied by NODE. This routine only
1193 : : looks at TREE_CODE, except for those nodes that have variable sizes. */
1194 : : size_t
1195 : 3543408446 : tree_size (const_tree node)
1196 : : {
1197 : 3543408446 : const enum tree_code code = TREE_CODE (node);
1198 : 3543408446 : switch (code)
1199 : : {
1200 : 10932115 : case INTEGER_CST:
1201 : 10932115 : return (sizeof (struct tree_int_cst)
1202 : 10932115 : + (TREE_INT_CST_EXT_NUNITS (node) - 1) * sizeof (HOST_WIDE_INT));
1203 : :
1204 : 0 : case TREE_BINFO:
1205 : 0 : return (offsetof (struct tree_binfo, base_binfos)
1206 : : + vec<tree, va_gc>
1207 : 0 : ::embedded_size (BINFO_N_BASE_BINFOS (node)));
1208 : :
1209 : 352110759 : case TREE_VEC:
1210 : 352110759 : return (sizeof (struct tree_vec)
1211 : 352110759 : + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
1212 : :
1213 : 0 : case VECTOR_CST:
1214 : 0 : return (sizeof (struct tree_vector)
1215 : 0 : + (vector_cst_encoded_nelts (node) - 1) * sizeof (tree));
1216 : :
1217 : 22021 : case STRING_CST:
1218 : 22021 : return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
1219 : :
1220 : 32729 : case OMP_CLAUSE:
1221 : 32729 : return (sizeof (struct tree_omp_clause)
1222 : 32729 : + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
1223 : 32729 : * sizeof (tree));
1224 : :
1225 : 3180310822 : default:
1226 : 3180310822 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
1227 : 142084125 : return (sizeof (struct tree_exp)
1228 : 142084125 : + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
1229 : : else
1230 : 3038226697 : return tree_code_size (code);
1231 : : }
1232 : : }
1233 : :
1234 : : /* Return tree node kind based on tree CODE. */
1235 : :
1236 : : static tree_node_kind
1237 : 0 : get_stats_node_kind (enum tree_code code)
1238 : : {
1239 : 0 : enum tree_code_class type = TREE_CODE_CLASS (code);
1240 : :
1241 : 0 : switch (type)
1242 : : {
1243 : : case tcc_declaration: /* A decl node */
1244 : : return d_kind;
1245 : 0 : case tcc_type: /* a type node */
1246 : 0 : return t_kind;
1247 : 0 : case tcc_statement: /* an expression with side effects */
1248 : 0 : return s_kind;
1249 : 0 : case tcc_reference: /* a reference */
1250 : 0 : return r_kind;
1251 : : case tcc_expression: /* an expression */
1252 : : case tcc_comparison: /* a comparison expression */
1253 : : case tcc_unary: /* a unary arithmetic expression */
1254 : : case tcc_binary: /* a binary arithmetic expression */
1255 : : return e_kind;
1256 : 0 : case tcc_constant: /* a constant */
1257 : 0 : return c_kind;
1258 : 0 : case tcc_exceptional: /* something random, like an identifier. */
1259 : 0 : switch (code)
1260 : : {
1261 : : case IDENTIFIER_NODE:
1262 : : return id_kind;
1263 : 0 : case TREE_VEC:
1264 : 0 : return vec_kind;
1265 : 0 : case TREE_BINFO:
1266 : 0 : return binfo_kind;
1267 : 0 : case SSA_NAME:
1268 : 0 : return ssa_name_kind;
1269 : 0 : case BLOCK:
1270 : 0 : return b_kind;
1271 : 0 : case CONSTRUCTOR:
1272 : 0 : return constr_kind;
1273 : 0 : case OMP_CLAUSE:
1274 : 0 : return omp_clause_kind;
1275 : 0 : default:
1276 : 0 : return x_kind;
1277 : : }
1278 : : break;
1279 : : case tcc_vl_exp:
1280 : : return e_kind;
1281 : 0 : default:
1282 : 0 : gcc_unreachable ();
1283 : : }
1284 : : }
1285 : :
1286 : : /* Record interesting allocation statistics for a tree node with CODE
1287 : : and LENGTH. */
1288 : :
1289 : : static void
1290 : 0 : record_node_allocation_statistics (enum tree_code code, size_t length)
1291 : : {
1292 : 0 : if (!GATHER_STATISTICS)
1293 : 0 : return;
1294 : :
1295 : : tree_node_kind kind = get_stats_node_kind (code);
1296 : :
1297 : : tree_code_counts[(int) code]++;
1298 : : tree_node_counts[(int) kind]++;
1299 : : tree_node_sizes[(int) kind] += length;
1300 : : }
1301 : :
1302 : : /* Allocate and return a new UID from the DECL_UID namespace. */
1303 : :
1304 : : int
1305 : 3868333359 : allocate_decl_uid (void)
1306 : : {
1307 : 3868333359 : return next_decl_uid++;
1308 : : }
1309 : :
1310 : : /* Return a newly allocated node of code CODE. For decl and type
1311 : : nodes, some other fields are initialized. The rest of the node is
1312 : : initialized to zero. This function cannot be used for TREE_VEC,
1313 : : INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
1314 : : tree_code_size.
1315 : :
1316 : : Achoo! I got a code in the node. */
1317 : :
1318 : : tree
1319 : 12633205125 : make_node (enum tree_code code MEM_STAT_DECL)
1320 : : {
1321 : 12633205125 : tree t;
1322 : 12633205125 : enum tree_code_class type = TREE_CODE_CLASS (code);
1323 : 12633205125 : size_t length = tree_code_size (code);
1324 : :
1325 : 12633205125 : record_node_allocation_statistics (code, length);
1326 : :
1327 : 12633205125 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1328 : 12633205125 : TREE_SET_CODE (t, code);
1329 : :
1330 : 12633205125 : switch (type)
1331 : : {
1332 : 625030144 : case tcc_statement:
1333 : 625030144 : if (code != DEBUG_BEGIN_STMT)
1334 : 326529801 : TREE_SIDE_EFFECTS (t) = 1;
1335 : : break;
1336 : :
1337 : 2855325094 : case tcc_declaration:
1338 : 2855325094 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1339 : : {
1340 : 2855325094 : if (code == FUNCTION_DECL)
1341 : : {
1342 : 1075685687 : SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
1343 : 1075685687 : SET_DECL_MODE (t, FUNCTION_MODE);
1344 : : }
1345 : : else
1346 : 1779639407 : SET_DECL_ALIGN (t, 1);
1347 : : }
1348 : 2855325094 : DECL_SOURCE_LOCATION (t) = input_location;
1349 : 2855325094 : if (TREE_CODE (t) == DEBUG_EXPR_DECL)
1350 : 1889867 : DECL_UID (t) = --next_debug_decl_uid;
1351 : : else
1352 : : {
1353 : 2853435227 : DECL_UID (t) = allocate_decl_uid ();
1354 : 2853435227 : SET_DECL_PT_UID (t, -1);
1355 : : }
1356 : 2855325094 : if (TREE_CODE (t) == LABEL_DECL)
1357 : 33113299 : LABEL_DECL_UID (t) = -1;
1358 : :
1359 : : break;
1360 : :
1361 : 1982367674 : case tcc_type:
1362 : 1982367674 : TYPE_UID (t) = next_type_uid++;
1363 : 1982367674 : SET_TYPE_ALIGN (t, BITS_PER_UNIT);
1364 : 1982367674 : TYPE_USER_ALIGN (t) = 0;
1365 : 1982367674 : TYPE_MAIN_VARIANT (t) = t;
1366 : 1982367674 : TYPE_CANONICAL (t) = t;
1367 : :
1368 : : /* Default to no attributes for type, but let target change that. */
1369 : 1982367674 : TYPE_ATTRIBUTES (t) = NULL_TREE;
1370 : 1982367674 : targetm.set_default_type_attributes (t);
1371 : :
1372 : : /* We have not yet computed the alias set for this type. */
1373 : 1982367674 : TYPE_ALIAS_SET (t) = -1;
1374 : 1982367674 : break;
1375 : :
1376 : 42865121 : case tcc_constant:
1377 : 42865121 : TREE_CONSTANT (t) = 1;
1378 : 42865121 : break;
1379 : :
1380 : 1064408065 : case tcc_expression:
1381 : 1064408065 : switch (code)
1382 : : {
1383 : 252109711 : case INIT_EXPR:
1384 : 252109711 : case MODIFY_EXPR:
1385 : 252109711 : case VA_ARG_EXPR:
1386 : 252109711 : case PREDECREMENT_EXPR:
1387 : 252109711 : case PREINCREMENT_EXPR:
1388 : 252109711 : case POSTDECREMENT_EXPR:
1389 : 252109711 : case POSTINCREMENT_EXPR:
1390 : : /* All of these have side-effects, no matter what their
1391 : : operands are. */
1392 : 252109711 : TREE_SIDE_EFFECTS (t) = 1;
1393 : 252109711 : break;
1394 : :
1395 : : default:
1396 : : break;
1397 : : }
1398 : : break;
1399 : :
1400 : 4861940737 : case tcc_exceptional:
1401 : 4861940737 : switch (code)
1402 : : {
1403 : 1089919 : case TARGET_OPTION_NODE:
1404 : 2179838 : TREE_TARGET_OPTION(t)
1405 : 1089919 : = ggc_cleared_alloc<struct cl_target_option> ();
1406 : 1089919 : break;
1407 : :
1408 : 598787 : case OPTIMIZATION_NODE:
1409 : 1197574 : TREE_OPTIMIZATION (t)
1410 : 598787 : = ggc_cleared_alloc<struct cl_optimization> ();
1411 : 598787 : break;
1412 : :
1413 : : default:
1414 : : break;
1415 : : }
1416 : : break;
1417 : :
1418 : : default:
1419 : : /* Other classes need no special treatment. */
1420 : : break;
1421 : : }
1422 : :
1423 : 12633205125 : return t;
1424 : : }
1425 : :
1426 : : /* Free tree node. */
1427 : :
1428 : : void
1429 : 609172797 : free_node (tree node)
1430 : : {
1431 : 609172797 : enum tree_code code = TREE_CODE (node);
1432 : 609172797 : if (GATHER_STATISTICS)
1433 : : {
1434 : : enum tree_node_kind kind = get_stats_node_kind (code);
1435 : :
1436 : : gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
1437 : : gcc_checking_assert (tree_node_counts[(int) kind] != 0);
1438 : : gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
1439 : :
1440 : : tree_code_counts[(int) TREE_CODE (node)]--;
1441 : : tree_node_counts[(int) kind]--;
1442 : : tree_node_sizes[(int) kind] -= tree_size (node);
1443 : : }
1444 : 609172797 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1445 : 349 : vec_free (CONSTRUCTOR_ELTS (node));
1446 : 609172604 : else if (code == BLOCK)
1447 : 0 : vec_free (BLOCK_NONLOCALIZED_VARS (node));
1448 : 609172604 : else if (code == TREE_BINFO)
1449 : 363 : vec_free (BINFO_BASE_ACCESSES (node));
1450 : 609172241 : else if (code == OPTIMIZATION_NODE)
1451 : 808 : cl_optimization_option_free (TREE_OPTIMIZATION (node));
1452 : 609171433 : else if (code == TARGET_OPTION_NODE)
1453 : 873 : cl_target_option_free (TREE_TARGET_OPTION (node));
1454 : 609172797 : ggc_free (node);
1455 : 609172797 : }
1456 : :
1457 : : /* Return a new node with the same contents as NODE except that its
1458 : : TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1459 : :
1460 : : tree
1461 : 3462789003 : copy_node (tree node MEM_STAT_DECL)
1462 : : {
1463 : 3462789003 : tree t;
1464 : 3462789003 : enum tree_code code = TREE_CODE (node);
1465 : 3462789003 : size_t length;
1466 : :
1467 : 3462789003 : gcc_assert (code != STATEMENT_LIST);
1468 : :
1469 : 3462789003 : length = tree_size (node);
1470 : 3462789003 : record_node_allocation_statistics (code, length);
1471 : 3462789003 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
1472 : 3462789003 : memcpy (t, node, length);
1473 : :
1474 : 3462789003 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
1475 : 2108165678 : TREE_CHAIN (t) = 0;
1476 : 3462789003 : TREE_ASM_WRITTEN (t) = 0;
1477 : 3462789003 : TREE_VISITED (t) = 0;
1478 : :
1479 : 3462789003 : if (TREE_CODE_CLASS (code) == tcc_declaration)
1480 : : {
1481 : 1013934127 : if (code == DEBUG_EXPR_DECL)
1482 : 0 : DECL_UID (t) = --next_debug_decl_uid;
1483 : : else
1484 : : {
1485 : 1013934127 : DECL_UID (t) = allocate_decl_uid ();
1486 : 1013934127 : if (DECL_PT_UID_SET_P (node))
1487 : 3519 : SET_DECL_PT_UID (t, DECL_PT_UID (node));
1488 : : }
1489 : 498404727 : if ((TREE_CODE (node) == PARM_DECL || VAR_P (node))
1490 : 1072722453 : && DECL_HAS_VALUE_EXPR_P (node))
1491 : : {
1492 : 832182 : SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
1493 : 832182 : DECL_HAS_VALUE_EXPR_P (t) = 1;
1494 : : }
1495 : : /* DECL_DEBUG_EXPR is copied explicitly by callers. */
1496 : 1013934127 : if (VAR_P (node))
1497 : : {
1498 : 58788326 : DECL_HAS_DEBUG_EXPR_P (t) = 0;
1499 : 58788326 : t->decl_with_vis.symtab_node = NULL;
1500 : : }
1501 : 1013934127 : if (VAR_P (node) && DECL_HAS_INIT_PRIORITY_P (node))
1502 : : {
1503 : 0 : SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
1504 : 0 : DECL_HAS_INIT_PRIORITY_P (t) = 1;
1505 : : }
1506 : 1013934127 : if (TREE_CODE (node) == FUNCTION_DECL)
1507 : : {
1508 : 256017789 : DECL_STRUCT_FUNCTION (t) = NULL;
1509 : 256017789 : t->decl_with_vis.symtab_node = NULL;
1510 : : }
1511 : : }
1512 : 2448854876 : else if (TREE_CODE_CLASS (code) == tcc_type)
1513 : : {
1514 : 689297363 : TYPE_UID (t) = next_type_uid++;
1515 : : /* The following is so that the debug code for
1516 : : the copy is different from the original type.
1517 : : The two statements usually duplicate each other
1518 : : (because they clear fields of the same union),
1519 : : but the optimizer should catch that. */
1520 : 689297363 : TYPE_SYMTAB_ADDRESS (t) = 0;
1521 : 689297363 : TYPE_SYMTAB_DIE (t) = 0;
1522 : :
1523 : : /* Do not copy the values cache. */
1524 : 689297363 : if (TYPE_CACHED_VALUES_P (t))
1525 : : {
1526 : 17260204 : TYPE_CACHED_VALUES_P (t) = 0;
1527 : 17260204 : TYPE_CACHED_VALUES (t) = NULL_TREE;
1528 : : }
1529 : : }
1530 : 1759557513 : else if (code == TARGET_OPTION_NODE)
1531 : : {
1532 : 0 : TREE_TARGET_OPTION (t) = ggc_alloc<struct cl_target_option>();
1533 : 0 : memcpy (TREE_TARGET_OPTION (t), TREE_TARGET_OPTION (node),
1534 : : sizeof (struct cl_target_option));
1535 : : }
1536 : 1759557513 : else if (code == OPTIMIZATION_NODE)
1537 : : {
1538 : 0 : TREE_OPTIMIZATION (t) = ggc_alloc<struct cl_optimization>();
1539 : 0 : memcpy (TREE_OPTIMIZATION (t), TREE_OPTIMIZATION (node),
1540 : : sizeof (struct cl_optimization));
1541 : : }
1542 : :
1543 : 3462789003 : return t;
1544 : : }
1545 : :
1546 : : /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1547 : : For example, this can copy a list made of TREE_LIST nodes. */
1548 : :
1549 : : tree
1550 : 135511627 : copy_list (tree list)
1551 : : {
1552 : 135511627 : tree head;
1553 : 135511627 : tree prev, next;
1554 : :
1555 : 135511627 : if (list == 0)
1556 : : return 0;
1557 : :
1558 : 130473940 : head = prev = copy_node (list);
1559 : 130473940 : next = TREE_CHAIN (list);
1560 : 258236639 : while (next)
1561 : : {
1562 : 127762699 : TREE_CHAIN (prev) = copy_node (next);
1563 : 127762699 : prev = TREE_CHAIN (prev);
1564 : 127762699 : next = TREE_CHAIN (next);
1565 : : }
1566 : : return head;
1567 : : }
1568 : :
1569 : :
1570 : : /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1571 : : INTEGER_CST with value CST and type TYPE. */
1572 : :
1573 : : static unsigned int
1574 : 8915899495 : get_int_cst_ext_nunits (tree type, const wide_int &cst)
1575 : : {
1576 : 8915899495 : gcc_checking_assert (cst.get_precision () == TYPE_PRECISION (type));
1577 : : /* We need extra HWIs if CST is an unsigned integer with its
1578 : : upper bit set. */
1579 : 8915899495 : if (TYPE_UNSIGNED (type) && wi::neg_p (cst))
1580 : 164835215 : return cst.get_precision () / HOST_BITS_PER_WIDE_INT + 1;
1581 : 8751064280 : return cst.get_len ();
1582 : : }
1583 : :
1584 : : /* Return a new INTEGER_CST with value CST and type TYPE. */
1585 : :
1586 : : static tree
1587 : 121313117 : build_new_int_cst (tree type, const wide_int &cst)
1588 : : {
1589 : 121313117 : unsigned int len = cst.get_len ();
1590 : 121313117 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1591 : 121313117 : tree nt = make_int_cst (len, ext_len);
1592 : :
1593 : 121313117 : if (len < ext_len)
1594 : : {
1595 : 59941326 : --ext_len;
1596 : 119882652 : TREE_INT_CST_ELT (nt, ext_len)
1597 : 59941326 : = zext_hwi (-1, cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1598 : 78142623 : for (unsigned int i = len; i < ext_len; ++i)
1599 : 18201297 : TREE_INT_CST_ELT (nt, i) = -1;
1600 : : }
1601 : 61371791 : else if (TYPE_UNSIGNED (type)
1602 : 61371791 : && cst.get_precision () < len * HOST_BITS_PER_WIDE_INT)
1603 : : {
1604 : 12635291 : len--;
1605 : 25270582 : TREE_INT_CST_ELT (nt, len)
1606 : 12635291 : = zext_hwi (cst.elt (len),
1607 : 12635291 : cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1608 : : }
1609 : :
1610 : 251578777 : for (unsigned int i = 0; i < len; i++)
1611 : 130265660 : TREE_INT_CST_ELT (nt, i) = cst.elt (i);
1612 : 121313117 : TREE_TYPE (nt) = type;
1613 : 121313117 : return nt;
1614 : : }
1615 : :
1616 : : /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE. */
1617 : :
1618 : : static tree
1619 : 0 : build_new_poly_int_cst (tree type, tree (&coeffs)[NUM_POLY_INT_COEFFS]
1620 : : CXX_MEM_STAT_INFO)
1621 : : {
1622 : 0 : size_t length = sizeof (struct tree_poly_int_cst);
1623 : 0 : record_node_allocation_statistics (POLY_INT_CST, length);
1624 : :
1625 : 0 : tree t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1626 : :
1627 : 0 : TREE_SET_CODE (t, POLY_INT_CST);
1628 : 0 : TREE_CONSTANT (t) = 1;
1629 : 0 : TREE_TYPE (t) = type;
1630 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1631 : 0 : POLY_INT_CST_COEFF (t, i) = coeffs[i];
1632 : 0 : return t;
1633 : : }
1634 : :
1635 : : /* Create a constant tree that contains CST sign-extended to TYPE. */
1636 : :
1637 : : tree
1638 : 5936256497 : build_int_cst (tree type, poly_int64 cst)
1639 : : {
1640 : : /* Support legacy code. */
1641 : 5936256497 : if (!type)
1642 : 1905084317 : type = integer_type_node;
1643 : :
1644 : 5936256497 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1645 : : }
1646 : :
1647 : : /* Create a constant tree that contains CST zero-extended to TYPE. */
1648 : :
1649 : : tree
1650 : 9221450 : build_int_cstu (tree type, poly_uint64 cst)
1651 : : {
1652 : 9221450 : return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type)));
1653 : : }
1654 : :
1655 : : /* Create a constant tree that contains CST sign-extended to TYPE. */
1656 : :
1657 : : tree
1658 : 24906472 : build_int_cst_type (tree type, poly_int64 cst)
1659 : : {
1660 : 24906472 : gcc_assert (type);
1661 : 24906472 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1662 : : }
1663 : :
1664 : : /* Constructs tree in type TYPE from with value given by CST. Signedness
1665 : : of CST is assumed to be the same as the signedness of TYPE. */
1666 : :
1667 : : tree
1668 : 7287023 : double_int_to_tree (tree type, double_int cst)
1669 : : {
1670 : 7287023 : return wide_int_to_tree (type, widest_int::from (cst, TYPE_SIGN (type)));
1671 : : }
1672 : :
1673 : : /* We force the wide_int CST to the range of the type TYPE by sign or
1674 : : zero extending it. OVERFLOWABLE indicates if we are interested in
1675 : : overflow of the value, when >0 we are only interested in signed
1676 : : overflow, for <0 we are interested in any overflow. OVERFLOWED
1677 : : indicates whether overflow has already occurred. CONST_OVERFLOWED
1678 : : indicates whether constant overflow has already occurred. We force
1679 : : T's value to be within range of T's type (by setting to 0 or 1 all
1680 : : the bits outside the type's range). We set TREE_OVERFLOWED if,
1681 : : OVERFLOWED is nonzero,
1682 : : or OVERFLOWABLE is >0 and signed overflow occurs
1683 : : or OVERFLOWABLE is <0 and any overflow occurs
1684 : : We return a new tree node for the extended wide_int. The node
1685 : : is shared if no overflow flags are set. */
1686 : :
1687 : :
1688 : : tree
1689 : 2308855445 : force_fit_type (tree type, const poly_wide_int_ref &cst,
1690 : : int overflowable, bool overflowed)
1691 : : {
1692 : 2308855445 : signop sign = TYPE_SIGN (type);
1693 : :
1694 : : /* If we need to set overflow flags, return a new unshared node. */
1695 : 2308855445 : if (overflowed || !wi::fits_to_tree_p (cst, type))
1696 : : {
1697 : 6592133 : if (overflowed
1698 : 6592133 : || overflowable < 0
1699 : 5355766 : || (overflowable > 0 && sign == SIGNED))
1700 : : {
1701 : 1282814 : poly_wide_int tmp = poly_wide_int::from (cst, TYPE_PRECISION (type),
1702 : 1282814 : sign);
1703 : 1282814 : tree t;
1704 : 1282814 : if (tmp.is_constant ())
1705 : 1282814 : t = build_new_int_cst (type, tmp.coeffs[0]);
1706 : : else
1707 : : {
1708 : : tree coeffs[NUM_POLY_INT_COEFFS];
1709 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1710 : : {
1711 : : coeffs[i] = build_new_int_cst (type, tmp.coeffs[i]);
1712 : : TREE_OVERFLOW (coeffs[i]) = 1;
1713 : : }
1714 : : t = build_new_poly_int_cst (type, coeffs);
1715 : : }
1716 : 1282814 : TREE_OVERFLOW (t) = 1;
1717 : 1282814 : return t;
1718 : 1282814 : }
1719 : : }
1720 : :
1721 : : /* Else build a shared node. */
1722 : 2307572631 : return wide_int_to_tree (type, cst);
1723 : : }
1724 : :
1725 : : /* These are the hash table functions for the hash table of INTEGER_CST
1726 : : nodes of a sizetype. */
1727 : :
1728 : : /* Return the hash code X, an INTEGER_CST. */
1729 : :
1730 : : hashval_t
1731 : 1686960842 : int_cst_hasher::hash (tree x)
1732 : : {
1733 : 1686960842 : const_tree const t = x;
1734 : 1686960842 : hashval_t code = TYPE_UID (TREE_TYPE (t));
1735 : 1686960842 : int i;
1736 : :
1737 : 3431903686 : for (i = 0; i < TREE_INT_CST_NUNITS (t); i++)
1738 : 1744942844 : code = iterative_hash_host_wide_int (TREE_INT_CST_ELT(t, i), code);
1739 : :
1740 : 1686960842 : return code;
1741 : : }
1742 : :
1743 : : /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1744 : : is the same as that given by *Y, which is the same. */
1745 : :
1746 : : bool
1747 : 1692482479 : int_cst_hasher::equal (tree x, tree y)
1748 : : {
1749 : 1692482479 : const_tree const xt = x;
1750 : 1692482479 : const_tree const yt = y;
1751 : :
1752 : 1692482479 : if (TREE_TYPE (xt) != TREE_TYPE (yt)
1753 : 584529163 : || TREE_INT_CST_NUNITS (xt) != TREE_INT_CST_NUNITS (yt)
1754 : 2276957156 : || TREE_INT_CST_EXT_NUNITS (xt) != TREE_INT_CST_EXT_NUNITS (yt))
1755 : : return false;
1756 : :
1757 : 861458384 : for (int i = 0; i < TREE_INT_CST_NUNITS (xt); i++)
1758 : 555701019 : if (TREE_INT_CST_ELT (xt, i) != TREE_INT_CST_ELT (yt, i))
1759 : : return false;
1760 : :
1761 : : return true;
1762 : : }
1763 : :
1764 : : /* Cache wide_int CST into the TYPE_CACHED_VALUES cache for TYPE.
1765 : : SLOT is the slot entry to store it in, and MAX_SLOTS is the maximum
1766 : : number of slots that can be cached for the type. */
1767 : :
1768 : : static inline tree
1769 : 8416800619 : cache_wide_int_in_type_cache (tree type, const wide_int &cst,
1770 : : int slot, int max_slots)
1771 : : {
1772 : 8416800619 : gcc_checking_assert (slot >= 0);
1773 : : /* Initialize cache. */
1774 : 8416800619 : if (!TYPE_CACHED_VALUES_P (type))
1775 : : {
1776 : 17324915 : TYPE_CACHED_VALUES_P (type) = 1;
1777 : 17324915 : TYPE_CACHED_VALUES (type) = make_tree_vec (max_slots);
1778 : : }
1779 : 8416800619 : tree t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot);
1780 : 8416800619 : if (!t)
1781 : : {
1782 : : /* Create a new shared int. */
1783 : 55058115 : t = build_new_int_cst (type, cst);
1784 : 55058115 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot) = t;
1785 : : }
1786 : 8416800619 : return t;
1787 : : }
1788 : :
1789 : : /* Create an INT_CST node of TYPE and value CST.
1790 : : The returned node is always shared. For small integers we use a
1791 : : per-type vector cache, for larger ones we use a single hash table.
1792 : : The value is extended from its precision according to the sign of
1793 : : the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1794 : : the upper bits and ensures that hashing and value equality based
1795 : : upon the underlying HOST_WIDE_INTs works without masking. */
1796 : :
1797 : : static tree
1798 : 8794586378 : wide_int_to_tree_1 (tree type, const wide_int_ref &pcst)
1799 : : {
1800 : 8794586378 : tree t;
1801 : 8794586378 : int ix = -1;
1802 : 8794586378 : int limit = 0;
1803 : :
1804 : 8794586378 : gcc_assert (type);
1805 : 8794586378 : unsigned int prec = TYPE_PRECISION (type);
1806 : 8794586378 : signop sgn = TYPE_SIGN (type);
1807 : :
1808 : : /* Verify that everything is canonical. */
1809 : 8794586378 : int l = pcst.get_len ();
1810 : 8794586378 : if (l > 1)
1811 : : {
1812 : 6671202 : if (pcst.elt (l - 1) == 0)
1813 : 1072736 : gcc_checking_assert (pcst.elt (l - 2) < 0);
1814 : 6671202 : if (pcst.elt (l - 1) == HOST_WIDE_INT_M1)
1815 : 11776 : gcc_checking_assert (pcst.elt (l - 2) >= 0);
1816 : : }
1817 : :
1818 : 8794586378 : wide_int cst = wide_int::from (pcst, prec, sgn);
1819 : 8794586378 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1820 : :
1821 : 8794586378 : enum tree_code code = TREE_CODE (type);
1822 : 8794586378 : if (code == POINTER_TYPE || code == REFERENCE_TYPE)
1823 : : {
1824 : : /* Cache NULL pointer and zero bounds. */
1825 : 166672716 : if (cst == 0)
1826 : : ix = 0;
1827 : : /* Cache upper bounds of pointers. */
1828 : 32113137 : else if (cst == wi::max_value (prec, sgn))
1829 : : ix = 1;
1830 : : /* Cache 1 which is used for a non-zero range. */
1831 : 30061260 : else if (cst == 1)
1832 : : ix = 2;
1833 : :
1834 : : if (ix >= 0)
1835 : : {
1836 : 140502678 : t = cache_wide_int_in_type_cache (type, cst, ix, 3);
1837 : : /* Make sure no one is clobbering the shared constant. */
1838 : 140502678 : gcc_checking_assert (TREE_TYPE (t) == type
1839 : : && cst == wi::to_wide (t));
1840 : 140502678 : return t;
1841 : : }
1842 : : }
1843 : 8654083700 : if (ext_len == 1)
1844 : : {
1845 : : /* We just need to store a single HOST_WIDE_INT. */
1846 : 8589111512 : HOST_WIDE_INT hwi;
1847 : 8589111512 : if (TYPE_UNSIGNED (type))
1848 : 5869912220 : hwi = cst.to_uhwi ();
1849 : : else
1850 : 2719199663 : hwi = cst.to_shwi ();
1851 : :
1852 : 8589111512 : switch (code)
1853 : : {
1854 : 206684 : case NULLPTR_TYPE:
1855 : 206684 : gcc_assert (hwi == 0);
1856 : : /* Fallthru. */
1857 : :
1858 : : case POINTER_TYPE:
1859 : : case REFERENCE_TYPE:
1860 : : /* Ignore pointers, as they were already handled above. */
1861 : : break;
1862 : :
1863 : 105435035 : case BOOLEAN_TYPE:
1864 : : /* Cache false or true. */
1865 : 105435035 : limit = 2;
1866 : 105435035 : if (IN_RANGE (hwi, 0, 1))
1867 : 105280982 : ix = hwi;
1868 : : break;
1869 : :
1870 : 8453712145 : case INTEGER_TYPE:
1871 : 8453712145 : case OFFSET_TYPE:
1872 : 8453712145 : case BITINT_TYPE:
1873 : 8453712145 : if (TYPE_SIGN (type) == UNSIGNED)
1874 : : {
1875 : : /* Cache [0, N). */
1876 : 5737818902 : limit = param_integer_share_limit;
1877 : 5737818902 : if (IN_RANGE (hwi, 0, param_integer_share_limit - 1))
1878 : 5557995764 : ix = hwi;
1879 : : }
1880 : : else
1881 : : {
1882 : : /* Cache [-1, N). */
1883 : 2715893243 : limit = param_integer_share_limit + 1;
1884 : 2715893243 : if (IN_RANGE (hwi, -1, param_integer_share_limit - 1))
1885 : 2613021195 : ix = hwi + 1;
1886 : : }
1887 : : break;
1888 : :
1889 : : case ENUMERAL_TYPE:
1890 : : break;
1891 : :
1892 : 0 : default:
1893 : 0 : gcc_unreachable ();
1894 : : }
1895 : :
1896 : 8589111512 : if (ix >= 0)
1897 : : {
1898 : 8276297941 : t = cache_wide_int_in_type_cache (type, cst, ix, limit);
1899 : : /* Make sure no one is clobbering the shared constant. */
1900 : 16552595882 : gcc_checking_assert (TREE_TYPE (t) == type
1901 : : && TREE_INT_CST_NUNITS (t) == 1
1902 : : && TREE_INT_CST_EXT_NUNITS (t) == 1
1903 : : && TREE_INT_CST_ELT (t, 0) == hwi);
1904 : : return t;
1905 : : }
1906 : : else
1907 : : {
1908 : : /* Use the cache of larger shared ints, using int_cst_node as
1909 : : a temporary. */
1910 : :
1911 : 312813571 : TREE_INT_CST_ELT (int_cst_node, 0) = hwi;
1912 : 312813571 : TREE_TYPE (int_cst_node) = type;
1913 : :
1914 : 312813571 : tree *slot = int_cst_hash_table->find_slot (int_cst_node, INSERT);
1915 : 312813571 : t = *slot;
1916 : 312813571 : if (!t)
1917 : : {
1918 : : /* Insert this one into the hash table. */
1919 : 62173092 : t = int_cst_node;
1920 : 62173092 : *slot = t;
1921 : : /* Make a new node for next time round. */
1922 : 62173092 : int_cst_node = make_int_cst (1, 1);
1923 : : }
1924 : : }
1925 : : }
1926 : : else
1927 : : {
1928 : : /* The value either hashes properly or we drop it on the floor
1929 : : for the gc to take care of. There will not be enough of them
1930 : : to worry about. */
1931 : :
1932 : 64972188 : tree nt = build_new_int_cst (type, cst);
1933 : 64972188 : tree *slot = int_cst_hash_table->find_slot (nt, INSERT);
1934 : 64972188 : t = *slot;
1935 : 64972188 : if (!t)
1936 : : {
1937 : : /* Insert this one into the hash table. */
1938 : 13483218 : t = nt;
1939 : 13483218 : *slot = t;
1940 : : }
1941 : : else
1942 : 51488970 : ggc_free (nt);
1943 : : }
1944 : :
1945 : : return t;
1946 : 8794586378 : }
1947 : :
1948 : : hashval_t
1949 : 0 : poly_int_cst_hasher::hash (tree t)
1950 : : {
1951 : 0 : inchash::hash hstate;
1952 : :
1953 : 0 : hstate.add_int (TYPE_UID (TREE_TYPE (t)));
1954 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1955 : 0 : hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
1956 : :
1957 : 0 : return hstate.end ();
1958 : : }
1959 : :
1960 : : bool
1961 : 0 : poly_int_cst_hasher::equal (tree x, const compare_type &y)
1962 : : {
1963 : 0 : if (TREE_TYPE (x) != y.first)
1964 : : return false;
1965 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1966 : 0 : if (wi::to_wide (POLY_INT_CST_COEFF (x, i)) != y.second->coeffs[i])
1967 : : return false;
1968 : : return true;
1969 : : }
1970 : :
1971 : : /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
1972 : : The elements must also have type TYPE. */
1973 : :
1974 : : tree
1975 : 0 : build_poly_int_cst (tree type, const poly_wide_int_ref &values)
1976 : : {
1977 : 0 : unsigned int prec = TYPE_PRECISION (type);
1978 : 0 : gcc_assert (prec <= values.coeffs[0].get_precision ());
1979 : 0 : poly_wide_int c = poly_wide_int::from (values, prec, SIGNED);
1980 : :
1981 : 0 : inchash::hash h;
1982 : 0 : h.add_int (TYPE_UID (type));
1983 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1984 : 0 : h.add_wide_int (c.coeffs[i]);
1985 : 0 : poly_int_cst_hasher::compare_type comp (type, &c);
1986 : 0 : tree *slot = poly_int_cst_hash_table->find_slot_with_hash (comp, h.end (),
1987 : : INSERT);
1988 : 0 : if (*slot == NULL_TREE)
1989 : : {
1990 : : tree coeffs[NUM_POLY_INT_COEFFS];
1991 : 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1992 : 0 : coeffs[i] = wide_int_to_tree_1 (type, c.coeffs[i]);
1993 : 0 : *slot = build_new_poly_int_cst (type, coeffs);
1994 : : }
1995 : 0 : return *slot;
1996 : 0 : }
1997 : :
1998 : : /* Create a constant tree with value VALUE in type TYPE. */
1999 : :
2000 : : tree
2001 : 8794586378 : wide_int_to_tree (tree type, const poly_wide_int_ref &value)
2002 : : {
2003 : 8794586378 : if (value.is_constant ())
2004 : 8794586378 : return wide_int_to_tree_1 (type, value.coeffs[0]);
2005 : : return build_poly_int_cst (type, value);
2006 : : }
2007 : :
2008 : : /* Insert INTEGER_CST T into a cache of integer constants. And return
2009 : : the cached constant (which may or may not be T). If MIGHT_DUPLICATE
2010 : : is false, and T falls into the type's 'smaller values' range, there
2011 : : cannot be an existing entry. Otherwise, if MIGHT_DUPLICATE is true,
2012 : : or the value is large, should an existing entry exist, it is
2013 : : returned (rather than inserting T). */
2014 : :
2015 : : tree
2016 : 491159 : cache_integer_cst (tree t, bool might_duplicate ATTRIBUTE_UNUSED)
2017 : : {
2018 : 491159 : tree type = TREE_TYPE (t);
2019 : 491159 : int ix = -1;
2020 : 491159 : int limit = 0;
2021 : 491159 : int prec = TYPE_PRECISION (type);
2022 : :
2023 : 491159 : gcc_assert (!TREE_OVERFLOW (t));
2024 : :
2025 : : /* The caching indices here must match those in
2026 : : wide_int_to_type_1. */
2027 : 491159 : switch (TREE_CODE (type))
2028 : : {
2029 : 0 : case NULLPTR_TYPE:
2030 : 0 : gcc_checking_assert (integer_zerop (t));
2031 : : /* Fallthru. */
2032 : :
2033 : 3163 : case POINTER_TYPE:
2034 : 3163 : case REFERENCE_TYPE:
2035 : 3163 : {
2036 : 3163 : if (integer_zerop (t))
2037 : : ix = 0;
2038 : 1332 : else if (integer_onep (t))
2039 : : ix = 2;
2040 : :
2041 : : if (ix >= 0)
2042 : : limit = 3;
2043 : : }
2044 : : break;
2045 : :
2046 : 9896 : case BOOLEAN_TYPE:
2047 : : /* Cache false or true. */
2048 : 9896 : limit = 2;
2049 : 9896 : if (wi::ltu_p (wi::to_wide (t), 2))
2050 : 0 : ix = TREE_INT_CST_ELT (t, 0);
2051 : : break;
2052 : :
2053 : 466421 : case INTEGER_TYPE:
2054 : 466421 : case OFFSET_TYPE:
2055 : 466421 : case BITINT_TYPE:
2056 : 466421 : if (TYPE_UNSIGNED (type))
2057 : : {
2058 : : /* Cache 0..N */
2059 : 347326 : limit = param_integer_share_limit;
2060 : :
2061 : : /* This is a little hokie, but if the prec is smaller than
2062 : : what is necessary to hold param_integer_share_limit, then the
2063 : : obvious test will not get the correct answer. */
2064 : 347326 : if (prec < HOST_BITS_PER_WIDE_INT)
2065 : : {
2066 : 72076 : if (tree_to_uhwi (t)
2067 : 72076 : < (unsigned HOST_WIDE_INT) param_integer_share_limit)
2068 : 10581 : ix = tree_to_uhwi (t);
2069 : : }
2070 : 275250 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2071 : 213271 : ix = tree_to_uhwi (t);
2072 : : }
2073 : : else
2074 : : {
2075 : : /* Cache -1..N */
2076 : 119095 : limit = param_integer_share_limit + 1;
2077 : :
2078 : 119095 : if (integer_minus_onep (t))
2079 : : ix = 0;
2080 : 118756 : else if (!wi::neg_p (wi::to_wide (t)))
2081 : : {
2082 : 104059 : if (prec < HOST_BITS_PER_WIDE_INT)
2083 : : {
2084 : 99845 : if (tree_to_shwi (t) < param_integer_share_limit)
2085 : 92323 : ix = tree_to_shwi (t) + 1;
2086 : : }
2087 : 4214 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2088 : 3416 : ix = tree_to_shwi (t) + 1;
2089 : : }
2090 : : }
2091 : : break;
2092 : :
2093 : : case ENUMERAL_TYPE:
2094 : : /* The slot used by TYPE_CACHED_VALUES is used for the enum
2095 : : members. */
2096 : : break;
2097 : :
2098 : 0 : default:
2099 : 0 : gcc_unreachable ();
2100 : : }
2101 : :
2102 : 321422 : if (ix >= 0)
2103 : : {
2104 : : /* Look for it in the type's vector of small shared ints. */
2105 : 322040 : if (!TYPE_CACHED_VALUES_P (type))
2106 : : {
2107 : 12253 : TYPE_CACHED_VALUES_P (type) = 1;
2108 : 12253 : TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
2109 : : }
2110 : :
2111 : 322040 : if (tree r = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix))
2112 : : {
2113 : 301128 : gcc_checking_assert (might_duplicate);
2114 : 301128 : t = r;
2115 : : }
2116 : : else
2117 : 20912 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
2118 : : }
2119 : : else
2120 : : {
2121 : : /* Use the cache of larger shared ints. */
2122 : 169119 : tree *slot = int_cst_hash_table->find_slot (t, INSERT);
2123 : 169119 : if (tree r = *slot)
2124 : : {
2125 : : /* If there is already an entry for the number verify it's the
2126 : : same value. */
2127 : 100475 : gcc_checking_assert (wi::to_wide (tree (r)) == wi::to_wide (t));
2128 : : /* And return the cached value. */
2129 : 100475 : t = r;
2130 : : }
2131 : : else
2132 : : /* Otherwise insert this one into the hash table. */
2133 : 68644 : *slot = t;
2134 : : }
2135 : :
2136 : 491159 : return t;
2137 : : }
2138 : :
2139 : :
2140 : : /* Builds an integer constant in TYPE such that lowest BITS bits are ones
2141 : : and the rest are zeros. */
2142 : :
2143 : : tree
2144 : 9144019 : build_low_bits_mask (tree type, unsigned bits)
2145 : : {
2146 : 9144019 : gcc_assert (bits <= TYPE_PRECISION (type));
2147 : :
2148 : 9144019 : return wide_int_to_tree (type, wi::mask (bits, false,
2149 : 9144019 : TYPE_PRECISION (type)));
2150 : : }
2151 : :
2152 : : /* Checks that X is integer constant that can be expressed in (unsigned)
2153 : : HOST_WIDE_INT without loss of precision. */
2154 : :
2155 : : bool
2156 : 587109225 : cst_and_fits_in_hwi (const_tree x)
2157 : : {
2158 : 587109225 : return (TREE_CODE (x) == INTEGER_CST
2159 : 587109225 : && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
2160 : : }
2161 : :
2162 : : /* Build a newly constructed VECTOR_CST with the given values of
2163 : : (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN. */
2164 : :
2165 : : tree
2166 : 3203024 : make_vector (unsigned log2_npatterns,
2167 : : unsigned int nelts_per_pattern MEM_STAT_DECL)
2168 : : {
2169 : 3203024 : gcc_assert (IN_RANGE (nelts_per_pattern, 1, 3));
2170 : 3203024 : tree t;
2171 : 3203024 : unsigned npatterns = 1 << log2_npatterns;
2172 : 3203024 : unsigned encoded_nelts = npatterns * nelts_per_pattern;
2173 : 3203024 : unsigned length = (sizeof (struct tree_vector)
2174 : : + (encoded_nelts - 1) * sizeof (tree));
2175 : :
2176 : 3203024 : record_node_allocation_statistics (VECTOR_CST, length);
2177 : :
2178 : 3203024 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2179 : :
2180 : 3203024 : TREE_SET_CODE (t, VECTOR_CST);
2181 : 3203024 : TREE_CONSTANT (t) = 1;
2182 : 3203024 : VECTOR_CST_LOG2_NPATTERNS (t) = log2_npatterns;
2183 : 3203024 : VECTOR_CST_NELTS_PER_PATTERN (t) = nelts_per_pattern;
2184 : :
2185 : 3203024 : return t;
2186 : : }
2187 : :
2188 : : /* Return a new VECTOR_CST node whose type is TYPE and whose values
2189 : : are extracted from V, a vector of CONSTRUCTOR_ELT. */
2190 : :
2191 : : tree
2192 : 656522 : build_vector_from_ctor (tree type, const vec<constructor_elt, va_gc> *v)
2193 : : {
2194 : 656522 : if (vec_safe_length (v) == 0)
2195 : 684 : return build_zero_cst (type);
2196 : :
2197 : 655838 : unsigned HOST_WIDE_INT idx, nelts, step = 1;
2198 : 655838 : tree value;
2199 : :
2200 : : /* If the vector is a VLA, build a VLA constant vector. */
2201 : 655838 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts))
2202 : : {
2203 : : nelts = constant_lower_bound (TYPE_VECTOR_SUBPARTS (type));
2204 : : gcc_assert (vec_safe_length (v) <= nelts);
2205 : : step = 2;
2206 : : }
2207 : :
2208 : 655838 : tree_vector_builder vec (type, nelts, step);
2209 : 4361343 : FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
2210 : : {
2211 : 3705505 : if (TREE_CODE (value) == VECTOR_CST)
2212 : : {
2213 : : /* If NELTS is constant then this must be too. */
2214 : 360 : unsigned int sub_nelts = VECTOR_CST_NELTS (value).to_constant ();
2215 : 1400 : for (unsigned i = 0; i < sub_nelts; ++i)
2216 : 1040 : vec.quick_push (VECTOR_CST_ELT (value, i));
2217 : : }
2218 : : else
2219 : 3705145 : vec.quick_push (value);
2220 : : }
2221 : 1853916 : while (vec.length () < nelts * step)
2222 : 271120 : vec.quick_push (build_zero_cst (TREE_TYPE (type)));
2223 : :
2224 : 655838 : return vec.build ();
2225 : 655838 : }
2226 : :
2227 : : /* Build a vector of type VECTYPE where all the elements are SCs. */
2228 : : tree
2229 : 668139 : build_vector_from_val (tree vectype, tree sc)
2230 : : {
2231 : 668139 : unsigned HOST_WIDE_INT i, nunits;
2232 : :
2233 : 668139 : if (sc == error_mark_node)
2234 : : return sc;
2235 : :
2236 : : /* Verify that the vector type is suitable for SC. Note that there
2237 : : is some inconsistency in the type-system with respect to restrict
2238 : : qualifications of pointers. Vector types always have a main-variant
2239 : : element type and the qualification is applied to the vector-type.
2240 : : So TREE_TYPE (vector-type) does not return a properly qualified
2241 : : vector element-type. */
2242 : 668139 : gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
2243 : : TREE_TYPE (vectype)));
2244 : :
2245 : 668139 : if (CONSTANT_CLASS_P (sc))
2246 : : {
2247 : 640022 : tree_vector_builder v (vectype, 1, 1);
2248 : 640022 : v.quick_push (sc);
2249 : 640022 : return v.build ();
2250 : 640022 : }
2251 : 28117 : else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
2252 : : return fold_build1 (VEC_DUPLICATE_EXPR, vectype, sc);
2253 : : else
2254 : : {
2255 : 28117 : vec<constructor_elt, va_gc> *v;
2256 : 28117 : vec_alloc (v, nunits);
2257 : 129516 : for (i = 0; i < nunits; ++i)
2258 : 101399 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
2259 : 28117 : return build_constructor (vectype, v);
2260 : : }
2261 : : }
2262 : :
2263 : : /* If TYPE is not a vector type, just return SC, otherwise return
2264 : : build_vector_from_val (TYPE, SC). */
2265 : :
2266 : : tree
2267 : 5000609 : build_uniform_cst (tree type, tree sc)
2268 : : {
2269 : 5000609 : if (!VECTOR_TYPE_P (type))
2270 : : return sc;
2271 : :
2272 : 241 : return build_vector_from_val (type, sc);
2273 : : }
2274 : :
2275 : : /* Build a vector series of type TYPE in which element I has the value
2276 : : BASE + I * STEP. The result is a constant if BASE and STEP are constant
2277 : : and a VEC_SERIES_EXPR otherwise. */
2278 : :
2279 : : tree
2280 : 18 : build_vec_series (tree type, tree base, tree step)
2281 : : {
2282 : 18 : if (integer_zerop (step))
2283 : 0 : return build_vector_from_val (type, base);
2284 : 18 : if (TREE_CODE (base) == INTEGER_CST && TREE_CODE (step) == INTEGER_CST)
2285 : : {
2286 : 18 : tree_vector_builder builder (type, 1, 3);
2287 : 18 : tree elt1 = wide_int_to_tree (TREE_TYPE (base),
2288 : 36 : wi::to_wide (base) + wi::to_wide (step));
2289 : 18 : tree elt2 = wide_int_to_tree (TREE_TYPE (base),
2290 : 36 : wi::to_wide (elt1) + wi::to_wide (step));
2291 : 18 : builder.quick_push (base);
2292 : 18 : builder.quick_push (elt1);
2293 : 18 : builder.quick_push (elt2);
2294 : 18 : return builder.build ();
2295 : 18 : }
2296 : 0 : return build2 (VEC_SERIES_EXPR, type, base, step);
2297 : : }
2298 : :
2299 : : /* Return a vector with the same number of units and number of bits
2300 : : as VEC_TYPE, but in which the elements are a linear series of unsigned
2301 : : integers { BASE, BASE + STEP, BASE + STEP * 2, ... }. */
2302 : :
2303 : : tree
2304 : 1776 : build_index_vector (tree vec_type, poly_uint64 base, poly_uint64 step)
2305 : : {
2306 : 1776 : tree index_vec_type = vec_type;
2307 : 1776 : tree index_elt_type = TREE_TYPE (vec_type);
2308 : 1776 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vec_type);
2309 : 1776 : if (!INTEGRAL_TYPE_P (index_elt_type) || !TYPE_UNSIGNED (index_elt_type))
2310 : : {
2311 : 4 : index_elt_type = build_nonstandard_integer_type
2312 : 8 : (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type)), true);
2313 : 4 : index_vec_type = build_vector_type (index_elt_type, nunits);
2314 : : }
2315 : :
2316 : 1776 : tree_vector_builder v (index_vec_type, 1, 3);
2317 : 7104 : for (unsigned int i = 0; i < 3; ++i)
2318 : 5328 : v.quick_push (build_int_cstu (index_elt_type, base + i * step));
2319 : 1776 : return v.build ();
2320 : 1776 : }
2321 : :
2322 : : /* Return a VECTOR_CST of type VEC_TYPE in which the first NUM_A
2323 : : elements are A and the rest are B. */
2324 : :
2325 : : tree
2326 : 0 : build_vector_a_then_b (tree vec_type, unsigned int num_a, tree a, tree b)
2327 : : {
2328 : 0 : gcc_assert (known_le (num_a, TYPE_VECTOR_SUBPARTS (vec_type)));
2329 : 0 : unsigned int count = constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_type));
2330 : : /* Optimize the constant case. */
2331 : 0 : if ((count & 1) == 0 && TYPE_VECTOR_SUBPARTS (vec_type).is_constant ())
2332 : 0 : count /= 2;
2333 : 0 : tree_vector_builder builder (vec_type, count, 2);
2334 : 0 : for (unsigned int i = 0; i < count * 2; ++i)
2335 : 0 : builder.quick_push (i < num_a ? a : b);
2336 : 0 : return builder.build ();
2337 : 0 : }
2338 : :
2339 : : /* Something has messed with the elements of CONSTRUCTOR C after it was built;
2340 : : calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
2341 : :
2342 : : void
2343 : 86310725 : recompute_constructor_flags (tree c)
2344 : : {
2345 : 86310725 : unsigned int i;
2346 : 86310725 : tree val;
2347 : 86310725 : bool constant_p = true;
2348 : 86310725 : bool side_effects_p = false;
2349 : 86310725 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2350 : :
2351 : 190083555 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2352 : : {
2353 : : /* Mostly ctors will have elts that don't have side-effects, so
2354 : : the usual case is to scan all the elements. Hence a single
2355 : : loop for both const and side effects, rather than one loop
2356 : : each (with early outs). */
2357 : 103772830 : if (!TREE_CONSTANT (val))
2358 : 15127917 : constant_p = false;
2359 : 103772830 : if (TREE_SIDE_EFFECTS (val))
2360 : 3014285 : side_effects_p = true;
2361 : : }
2362 : :
2363 : 86310725 : TREE_SIDE_EFFECTS (c) = side_effects_p;
2364 : 86310725 : TREE_CONSTANT (c) = constant_p;
2365 : 86310725 : }
2366 : :
2367 : : /* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
2368 : : CONSTRUCTOR C. */
2369 : :
2370 : : void
2371 : 11521959 : verify_constructor_flags (tree c)
2372 : : {
2373 : 11521959 : unsigned int i;
2374 : 11521959 : tree val;
2375 : 11521959 : bool constant_p = TREE_CONSTANT (c);
2376 : 11521959 : bool side_effects_p = TREE_SIDE_EFFECTS (c);
2377 : 11521959 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2378 : :
2379 : 59946092 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2380 : : {
2381 : 48424133 : if (constant_p && !TREE_CONSTANT (val))
2382 : 0 : internal_error ("non-constant element in constant CONSTRUCTOR");
2383 : 48424133 : if (!side_effects_p && TREE_SIDE_EFFECTS (val))
2384 : 0 : internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
2385 : : }
2386 : 11521959 : }
2387 : :
2388 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2389 : : are in the vec pointed to by VALS. */
2390 : : tree
2391 : 71645539 : build_constructor (tree type, vec<constructor_elt, va_gc> *vals MEM_STAT_DECL)
2392 : : {
2393 : 71645539 : tree c = make_node (CONSTRUCTOR PASS_MEM_STAT);
2394 : :
2395 : 71645539 : TREE_TYPE (c) = type;
2396 : 71645539 : CONSTRUCTOR_ELTS (c) = vals;
2397 : :
2398 : 71645539 : recompute_constructor_flags (c);
2399 : :
2400 : 71645539 : return c;
2401 : : }
2402 : :
2403 : : /* Build a CONSTRUCTOR node made of a single initializer, with the specified
2404 : : INDEX and VALUE. */
2405 : : tree
2406 : 3698 : build_constructor_single (tree type, tree index, tree value)
2407 : : {
2408 : 3698 : vec<constructor_elt, va_gc> *v;
2409 : 3698 : constructor_elt elt = {index, value};
2410 : :
2411 : 3698 : vec_alloc (v, 1);
2412 : 3698 : v->quick_push (elt);
2413 : :
2414 : 3698 : return build_constructor (type, v);
2415 : : }
2416 : :
2417 : :
2418 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2419 : : are in a list pointed to by VALS. */
2420 : : tree
2421 : 5621 : build_constructor_from_list (tree type, tree vals)
2422 : : {
2423 : 5621 : tree t;
2424 : 5621 : vec<constructor_elt, va_gc> *v = NULL;
2425 : :
2426 : 5621 : if (vals)
2427 : : {
2428 : 5621 : vec_alloc (v, list_length (vals));
2429 : 54548 : for (t = vals; t; t = TREE_CHAIN (t))
2430 : 48927 : CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
2431 : : }
2432 : :
2433 : 5621 : return build_constructor (type, v);
2434 : : }
2435 : :
2436 : : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2437 : : are in a vector pointed to by VALS. Note that the TREE_PURPOSE
2438 : : fields in the constructor remain null. */
2439 : :
2440 : : tree
2441 : 1368 : build_constructor_from_vec (tree type, const vec<tree, va_gc> *vals)
2442 : : {
2443 : 1368 : vec<constructor_elt, va_gc> *v = NULL;
2444 : :
2445 : 72399 : for (tree t : vals)
2446 : 71031 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
2447 : :
2448 : 1368 : return build_constructor (type, v);
2449 : : }
2450 : :
2451 : : /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
2452 : : of elements, provided as index/value pairs. */
2453 : :
2454 : : tree
2455 : 38176 : build_constructor_va (tree type, int nelts, ...)
2456 : : {
2457 : 38176 : vec<constructor_elt, va_gc> *v = NULL;
2458 : 38176 : va_list p;
2459 : :
2460 : 38176 : va_start (p, nelts);
2461 : 38176 : vec_alloc (v, nelts);
2462 : 38176 : while (nelts--)
2463 : : {
2464 : 114723 : tree index = va_arg (p, tree);
2465 : 114723 : tree value = va_arg (p, tree);
2466 : 267622 : CONSTRUCTOR_APPEND_ELT (v, index, value);
2467 : : }
2468 : 38176 : va_end (p);
2469 : 38176 : return build_constructor (type, v);
2470 : : }
2471 : :
2472 : : /* Return a node of type TYPE for which TREE_CLOBBER_P is true. */
2473 : :
2474 : : tree
2475 : 11569768 : build_clobber (tree type, enum clobber_kind kind)
2476 : : {
2477 : 11569768 : tree clobber = build_constructor (type, NULL);
2478 : 11569768 : TREE_THIS_VOLATILE (clobber) = true;
2479 : 11569768 : CLOBBER_KIND (clobber) = kind;
2480 : 11569768 : return clobber;
2481 : : }
2482 : :
2483 : : /* Return a new FIXED_CST node whose type is TYPE and value is F. */
2484 : :
2485 : : tree
2486 : 54 : build_fixed (tree type, FIXED_VALUE_TYPE f)
2487 : : {
2488 : 54 : tree v;
2489 : 54 : FIXED_VALUE_TYPE *fp;
2490 : :
2491 : 54 : v = make_node (FIXED_CST);
2492 : 54 : fp = ggc_alloc<fixed_value> ();
2493 : 54 : memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
2494 : :
2495 : 54 : TREE_TYPE (v) = type;
2496 : 54 : TREE_FIXED_CST_PTR (v) = fp;
2497 : 54 : return v;
2498 : : }
2499 : :
2500 : : /* Return a new REAL_CST node whose type is TYPE and value is D. */
2501 : :
2502 : : tree
2503 : 41903919 : build_real (tree type, REAL_VALUE_TYPE d)
2504 : : {
2505 : 41903919 : tree v;
2506 : 41903919 : int overflow = 0;
2507 : :
2508 : : /* dconst{0,1,2,m1,half} are used in various places in
2509 : : the middle-end and optimizers, allow them here
2510 : : even for decimal floating point types as an exception
2511 : : by converting them to decimal. */
2512 : 41903919 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))
2513 : 610441 : && (d.cl == rvc_normal || d.cl == rvc_zero)
2514 : 42512314 : && !d.decimal)
2515 : : {
2516 : 715 : if (memcmp (&d, &dconst1, sizeof (d)) == 0)
2517 : 0 : decimal_real_from_string (&d, "1");
2518 : 715 : else if (memcmp (&d, &dconst2, sizeof (d)) == 0)
2519 : 22 : decimal_real_from_string (&d, "2");
2520 : 693 : else if (memcmp (&d, &dconstm1, sizeof (d)) == 0)
2521 : 90 : decimal_real_from_string (&d, "-1");
2522 : 603 : else if (memcmp (&d, &dconsthalf, sizeof (d)) == 0)
2523 : 0 : decimal_real_from_string (&d, "0.5");
2524 : 603 : else if (memcmp (&d, &dconst0, sizeof (d)) == 0)
2525 : : {
2526 : : /* Make sure to give zero the minimum quantum exponent for
2527 : : the type (which corresponds to all bits zero). */
2528 : 603 : const struct real_format *fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
2529 : 603 : char buf[16];
2530 : 603 : sprintf (buf, "0e%d", fmt->emin - fmt->p);
2531 : 603 : decimal_real_from_string (&d, buf);
2532 : : }
2533 : : else
2534 : 0 : gcc_unreachable ();
2535 : : }
2536 : :
2537 : : /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
2538 : : Consider doing it via real_convert now. */
2539 : :
2540 : 41903919 : v = make_node (REAL_CST);
2541 : 41903919 : TREE_TYPE (v) = type;
2542 : 41903919 : memcpy (TREE_REAL_CST_PTR (v), &d, sizeof (REAL_VALUE_TYPE));
2543 : 41903919 : TREE_OVERFLOW (v) = overflow;
2544 : 41903919 : return v;
2545 : : }
2546 : :
2547 : : /* Like build_real, but first truncate D to the type. */
2548 : :
2549 : : tree
2550 : 176289 : build_real_truncate (tree type, REAL_VALUE_TYPE d)
2551 : : {
2552 : 176289 : return build_real (type, real_value_truncate (TYPE_MODE (type), d));
2553 : : }
2554 : :
2555 : : /* Return a new REAL_CST node whose type is TYPE
2556 : : and whose value is the integer value of the INTEGER_CST node I. */
2557 : :
2558 : : REAL_VALUE_TYPE
2559 : 24506023 : real_value_from_int_cst (const_tree type, const_tree i)
2560 : : {
2561 : 24506023 : REAL_VALUE_TYPE d;
2562 : :
2563 : : /* Clear all bits of the real value type so that we can later do
2564 : : bitwise comparisons to see if two values are the same. */
2565 : 24506023 : memset (&d, 0, sizeof d);
2566 : :
2567 : 24506023 : real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, wi::to_wide (i),
2568 : 24506023 : TYPE_SIGN (TREE_TYPE (i)));
2569 : 24506023 : return d;
2570 : : }
2571 : :
2572 : : /* Given a tree representing an integer constant I, return a tree
2573 : : representing the same value as a floating-point constant of type TYPE. */
2574 : :
2575 : : tree
2576 : 23930521 : build_real_from_int_cst (tree type, const_tree i)
2577 : : {
2578 : 23930521 : tree v;
2579 : 23930521 : int overflow = TREE_OVERFLOW (i);
2580 : :
2581 : 23930521 : v = build_real (type, real_value_from_int_cst (type, i));
2582 : :
2583 : 23930521 : TREE_OVERFLOW (v) |= overflow;
2584 : 23930521 : return v;
2585 : : }
2586 : :
2587 : : /* Return a new REAL_CST node whose type is TYPE
2588 : : and whose value is the integer value I which has sign SGN. */
2589 : :
2590 : : tree
2591 : 129 : build_real_from_wide (tree type, const wide_int_ref &i, signop sgn)
2592 : : {
2593 : 129 : REAL_VALUE_TYPE d;
2594 : :
2595 : : /* Clear all bits of the real value type so that we can later do
2596 : : bitwise comparisons to see if two values are the same. */
2597 : 129 : memset (&d, 0, sizeof d);
2598 : :
2599 : 129 : real_from_integer (&d, TYPE_MODE (type), i, sgn);
2600 : 129 : return build_real (type, d);
2601 : : }
2602 : :
2603 : : /* Return a newly constructed STRING_CST node whose value is the LEN
2604 : : characters at STR when STR is nonnull, or all zeros otherwise.
2605 : : Note that for a C string literal, LEN should include the trailing NUL.
2606 : : The TREE_TYPE is not initialized. */
2607 : :
2608 : : tree
2609 : 90096574 : build_string (unsigned len, const char *str /*= NULL */)
2610 : : {
2611 : : /* Do not waste bytes provided by padding of struct tree_string. */
2612 : 90096574 : unsigned size = len + offsetof (struct tree_string, str) + 1;
2613 : :
2614 : 90096574 : record_node_allocation_statistics (STRING_CST, size);
2615 : :
2616 : 90096574 : tree s = (tree) ggc_internal_alloc (size);
2617 : :
2618 : 90096574 : memset (s, 0, sizeof (struct tree_typed));
2619 : 90096574 : TREE_SET_CODE (s, STRING_CST);
2620 : 90096574 : TREE_CONSTANT (s) = 1;
2621 : 90096574 : TREE_STRING_LENGTH (s) = len;
2622 : 90096574 : if (str)
2623 : 90087397 : memcpy (s->string.str, str, len);
2624 : : else
2625 : 9177 : memset (s->string.str, 0, len);
2626 : 90096574 : s->string.str[len] = '\0';
2627 : :
2628 : 90096574 : return s;
2629 : : }
2630 : :
2631 : : /* Return a newly constructed COMPLEX_CST node whose value is
2632 : : specified by the real and imaginary parts REAL and IMAG.
2633 : : Both REAL and IMAG should be constant nodes. TYPE, if specified,
2634 : : will be the type of the COMPLEX_CST; otherwise a new type will be made. */
2635 : :
2636 : : tree
2637 : 484947 : build_complex (tree type, tree real, tree imag)
2638 : : {
2639 : 484947 : gcc_assert (CONSTANT_CLASS_P (real));
2640 : 484947 : gcc_assert (CONSTANT_CLASS_P (imag));
2641 : :
2642 : 484947 : tree t = make_node (COMPLEX_CST);
2643 : :
2644 : 484947 : TREE_REALPART (t) = real;
2645 : 484947 : TREE_IMAGPART (t) = imag;
2646 : 484947 : TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
2647 : 484947 : TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
2648 : 484947 : return t;
2649 : : }
2650 : :
2651 : : /* Build a complex (inf +- 0i), such as for the result of cproj.
2652 : : TYPE is the complex tree type of the result. If NEG is true, the
2653 : : imaginary zero is negative. */
2654 : :
2655 : : tree
2656 : 840 : build_complex_inf (tree type, bool neg)
2657 : : {
2658 : 840 : REAL_VALUE_TYPE rzero = dconst0;
2659 : :
2660 : 840 : rzero.sign = neg;
2661 : 840 : return build_complex (type, build_real (TREE_TYPE (type), dconstinf),
2662 : 840 : build_real (TREE_TYPE (type), rzero));
2663 : : }
2664 : :
2665 : : /* Return the constant 1 in type TYPE. If TYPE has several elements, each
2666 : : element is set to 1. In particular, this is 1 + i for complex types. */
2667 : :
2668 : : tree
2669 : 4108 : build_each_one_cst (tree type)
2670 : : {
2671 : 4108 : if (TREE_CODE (type) == COMPLEX_TYPE)
2672 : : {
2673 : 0 : tree scalar = build_one_cst (TREE_TYPE (type));
2674 : 0 : return build_complex (type, scalar, scalar);
2675 : : }
2676 : : else
2677 : 4108 : return build_one_cst (type);
2678 : : }
2679 : :
2680 : : /* Return a constant of arithmetic type TYPE which is the
2681 : : multiplicative identity of the set TYPE. */
2682 : :
2683 : : tree
2684 : 9327595 : build_one_cst (tree type)
2685 : : {
2686 : 9327595 : switch (TREE_CODE (type))
2687 : : {
2688 : 9313768 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2689 : 9313768 : case POINTER_TYPE: case REFERENCE_TYPE:
2690 : 9313768 : case OFFSET_TYPE: case BITINT_TYPE:
2691 : 9313768 : return build_int_cst (type, 1);
2692 : :
2693 : 10485 : case REAL_TYPE:
2694 : 10485 : return build_real (type, dconst1);
2695 : :
2696 : 0 : case FIXED_POINT_TYPE:
2697 : : /* We can only generate 1 for accum types. */
2698 : 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2699 : 0 : return build_fixed (type, FCONST1 (TYPE_MODE (type)));
2700 : :
2701 : 339 : case VECTOR_TYPE:
2702 : 339 : {
2703 : 339 : tree scalar = build_one_cst (TREE_TYPE (type));
2704 : :
2705 : 339 : return build_vector_from_val (type, scalar);
2706 : : }
2707 : :
2708 : 3003 : case COMPLEX_TYPE:
2709 : 6006 : return build_complex (type,
2710 : 3003 : build_one_cst (TREE_TYPE (type)),
2711 : 6006 : build_zero_cst (TREE_TYPE (type)));
2712 : :
2713 : 0 : default:
2714 : 0 : gcc_unreachable ();
2715 : : }
2716 : : }
2717 : :
2718 : : /* Return an integer of type TYPE containing all 1's in as much precision as
2719 : : it contains, or a complex or vector whose subparts are such integers. */
2720 : :
2721 : : tree
2722 : 1800409 : build_all_ones_cst (tree type)
2723 : : {
2724 : 1800409 : if (TREE_CODE (type) == COMPLEX_TYPE)
2725 : : {
2726 : 0 : tree scalar = build_all_ones_cst (TREE_TYPE (type));
2727 : 0 : return build_complex (type, scalar, scalar);
2728 : : }
2729 : : else
2730 : 1800409 : return build_minus_one_cst (type);
2731 : : }
2732 : :
2733 : : /* Return a constant of arithmetic type TYPE which is the
2734 : : opposite of the multiplicative identity of the set TYPE. */
2735 : :
2736 : : tree
2737 : 2389720 : build_minus_one_cst (tree type)
2738 : : {
2739 : 2389720 : switch (TREE_CODE (type))
2740 : : {
2741 : 2274355 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2742 : 2274355 : case POINTER_TYPE: case REFERENCE_TYPE:
2743 : 2274355 : case OFFSET_TYPE: case BITINT_TYPE:
2744 : 2274355 : return build_int_cst (type, -1);
2745 : :
2746 : 9786 : case REAL_TYPE:
2747 : 9786 : return build_real (type, dconstm1);
2748 : :
2749 : 0 : case FIXED_POINT_TYPE:
2750 : : /* We can only generate 1 for accum types. */
2751 : 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2752 : 0 : return build_fixed (type,
2753 : : fixed_from_double_int (double_int_minus_one,
2754 : 0 : SCALAR_TYPE_MODE (type)));
2755 : :
2756 : 105579 : case VECTOR_TYPE:
2757 : 105579 : {
2758 : 105579 : tree scalar = build_minus_one_cst (TREE_TYPE (type));
2759 : :
2760 : 105579 : return build_vector_from_val (type, scalar);
2761 : : }
2762 : :
2763 : 0 : case COMPLEX_TYPE:
2764 : 0 : return build_complex (type,
2765 : 0 : build_minus_one_cst (TREE_TYPE (type)),
2766 : 0 : build_zero_cst (TREE_TYPE (type)));
2767 : :
2768 : 0 : default:
2769 : 0 : gcc_unreachable ();
2770 : : }
2771 : : }
2772 : :
2773 : : /* Build 0 constant of type TYPE. This is used by constructor folding
2774 : : and thus the constant should be represented in memory by
2775 : : zero(es). */
2776 : :
2777 : : tree
2778 : 78441703 : build_zero_cst (tree type)
2779 : : {
2780 : 78441703 : switch (TREE_CODE (type))
2781 : : {
2782 : 77820844 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2783 : 77820844 : case POINTER_TYPE: case REFERENCE_TYPE:
2784 : 77820844 : case OFFSET_TYPE: case NULLPTR_TYPE: case BITINT_TYPE:
2785 : 77820844 : return build_int_cst (type, 0);
2786 : :
2787 : 221992 : case REAL_TYPE:
2788 : 221992 : return build_real (type, dconst0);
2789 : :
2790 : 0 : case FIXED_POINT_TYPE:
2791 : 0 : return build_fixed (type, FCONST0 (TYPE_MODE (type)));
2792 : :
2793 : 209213 : case VECTOR_TYPE:
2794 : 209213 : {
2795 : 209213 : tree scalar = build_zero_cst (TREE_TYPE (type));
2796 : :
2797 : 209213 : return build_vector_from_val (type, scalar);
2798 : : }
2799 : :
2800 : 3534 : case COMPLEX_TYPE:
2801 : 3534 : {
2802 : 3534 : tree zero = build_zero_cst (TREE_TYPE (type));
2803 : :
2804 : 3534 : return build_complex (type, zero, zero);
2805 : : }
2806 : :
2807 : 186120 : default:
2808 : 186120 : if (!AGGREGATE_TYPE_P (type))
2809 : 1 : return fold_convert (type, integer_zero_node);
2810 : 186119 : return build_constructor (type, NULL);
2811 : : }
2812 : : }
2813 : :
2814 : : /* Build a constant of integer type TYPE, made of VALUE's bits replicated
2815 : : every WIDTH bits to fit TYPE's precision. */
2816 : :
2817 : : tree
2818 : 14 : build_replicated_int_cst (tree type, unsigned int width, HOST_WIDE_INT value)
2819 : : {
2820 : 14 : int n = ((TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
2821 : 14 : / HOST_BITS_PER_WIDE_INT);
2822 : 14 : unsigned HOST_WIDE_INT low, mask;
2823 : 14 : HOST_WIDE_INT a[WIDE_INT_MAX_INL_ELTS];
2824 : 14 : int i;
2825 : :
2826 : 14 : gcc_assert (n && n <= WIDE_INT_MAX_INL_ELTS);
2827 : :
2828 : 14 : if (width == HOST_BITS_PER_WIDE_INT)
2829 : 0 : low = value;
2830 : : else
2831 : : {
2832 : 14 : mask = (HOST_WIDE_INT_1U << width) - 1;
2833 : 14 : low = (unsigned HOST_WIDE_INT) ~0 / mask * (value & mask);
2834 : : }
2835 : :
2836 : 28 : for (i = 0; i < n; i++)
2837 : 14 : a[i] = low;
2838 : :
2839 : 14 : gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
2840 : 14 : return wide_int_to_tree (type, wide_int::from_array (a, n,
2841 : 14 : TYPE_PRECISION (type)));
2842 : : }
2843 : :
2844 : : /* If floating-point type TYPE has an IEEE-style sign bit, return an
2845 : : unsigned constant in which only the sign bit is set. Return null
2846 : : otherwise. */
2847 : :
2848 : : tree
2849 : 0 : sign_mask_for (tree type)
2850 : : {
2851 : : /* Avoid having to choose between a real-only sign and a pair of signs.
2852 : : This could be relaxed if the choice becomes obvious later. */
2853 : 0 : if (TREE_CODE (type) == COMPLEX_TYPE)
2854 : : return NULL_TREE;
2855 : :
2856 : 0 : auto eltmode = as_a<scalar_float_mode> (element_mode (type));
2857 : 0 : auto bits = REAL_MODE_FORMAT (eltmode)->ieee_bits;
2858 : 0 : if (!bits || !pow2p_hwi (bits))
2859 : : return NULL_TREE;
2860 : :
2861 : 0 : tree inttype = unsigned_type_for (type);
2862 : 0 : if (!inttype)
2863 : : return NULL_TREE;
2864 : :
2865 : 0 : auto mask = wi::set_bit_in_zero (bits - 1, bits);
2866 : 0 : if (VECTOR_TYPE_P (inttype))
2867 : : {
2868 : 0 : tree elt = wide_int_to_tree (TREE_TYPE (inttype), mask);
2869 : 0 : return build_vector_from_val (inttype, elt);
2870 : : }
2871 : 0 : return wide_int_to_tree (inttype, mask);
2872 : 0 : }
2873 : :
2874 : : /* Build a BINFO with LEN language slots. */
2875 : :
2876 : : tree
2877 : 86087632 : make_tree_binfo (unsigned base_binfos MEM_STAT_DECL)
2878 : : {
2879 : 86087632 : tree t;
2880 : 86087632 : size_t length = (offsetof (struct tree_binfo, base_binfos)
2881 : 86087632 : + vec<tree, va_gc>::embedded_size (base_binfos));
2882 : :
2883 : 86087632 : record_node_allocation_statistics (TREE_BINFO, length);
2884 : :
2885 : 86087632 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
2886 : :
2887 : 86087632 : memset (t, 0, offsetof (struct tree_binfo, base_binfos));
2888 : :
2889 : 86087632 : TREE_SET_CODE (t, TREE_BINFO);
2890 : :
2891 : 86087632 : BINFO_BASE_BINFOS (t)->embedded_init (base_binfos);
2892 : :
2893 : 86087632 : return t;
2894 : : }
2895 : :
2896 : : /* Create a CASE_LABEL_EXPR tree node and return it. */
2897 : :
2898 : : tree
2899 : 4688589 : build_case_label (tree low_value, tree high_value, tree label_decl)
2900 : : {
2901 : 4688589 : tree t = make_node (CASE_LABEL_EXPR);
2902 : :
2903 : 4688589 : TREE_TYPE (t) = void_type_node;
2904 : 4688589 : SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl));
2905 : :
2906 : 4688589 : CASE_LOW (t) = low_value;
2907 : 4688589 : CASE_HIGH (t) = high_value;
2908 : 4688589 : CASE_LABEL (t) = label_decl;
2909 : 4688589 : CASE_CHAIN (t) = NULL_TREE;
2910 : :
2911 : 4688589 : return t;
2912 : : }
2913 : :
2914 : : /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2915 : : values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2916 : : The latter determines the length of the HOST_WIDE_INT vector. */
2917 : :
2918 : : tree
2919 : 184471305 : make_int_cst (int len, int ext_len MEM_STAT_DECL)
2920 : : {
2921 : 184471305 : tree t;
2922 : 184471305 : int length = ((ext_len - 1) * sizeof (HOST_WIDE_INT)
2923 : 184471305 : + sizeof (struct tree_int_cst));
2924 : :
2925 : 184471305 : gcc_assert (len);
2926 : 184471305 : record_node_allocation_statistics (INTEGER_CST, length);
2927 : :
2928 : 184471305 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2929 : :
2930 : 184471305 : TREE_SET_CODE (t, INTEGER_CST);
2931 : 184471305 : TREE_INT_CST_NUNITS (t) = len;
2932 : 184471305 : TREE_INT_CST_EXT_NUNITS (t) = ext_len;
2933 : 184471305 : TREE_CONSTANT (t) = 1;
2934 : :
2935 : 184471305 : return t;
2936 : : }
2937 : :
2938 : : /* Build a newly constructed TREE_VEC node of length LEN. */
2939 : :
2940 : : tree
2941 : 2358137312 : make_tree_vec (int len MEM_STAT_DECL)
2942 : : {
2943 : 2358137312 : tree t;
2944 : 2358137312 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2945 : :
2946 : 2358137312 : record_node_allocation_statistics (TREE_VEC, length);
2947 : :
2948 : 2358137312 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2949 : :
2950 : 2358137312 : TREE_SET_CODE (t, TREE_VEC);
2951 : 2358137312 : TREE_VEC_LENGTH (t) = len;
2952 : :
2953 : 2358137312 : return t;
2954 : : }
2955 : :
2956 : : /* Grow a TREE_VEC node to new length LEN. */
2957 : :
2958 : : tree
2959 : 136368 : grow_tree_vec (tree v, int len MEM_STAT_DECL)
2960 : : {
2961 : 136368 : gcc_assert (TREE_CODE (v) == TREE_VEC);
2962 : :
2963 : 136368 : int oldlen = TREE_VEC_LENGTH (v);
2964 : 136368 : gcc_assert (len > oldlen);
2965 : :
2966 : 136368 : size_t oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
2967 : 136368 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2968 : :
2969 : 136368 : record_node_allocation_statistics (TREE_VEC, length - oldlength);
2970 : :
2971 : 136368 : v = (tree) ggc_realloc (v, length PASS_MEM_STAT);
2972 : :
2973 : 136368 : TREE_VEC_LENGTH (v) = len;
2974 : :
2975 : 136368 : return v;
2976 : : }
2977 : :
2978 : : /* Return true if EXPR is the constant zero, whether it is integral, float or
2979 : : fixed, and scalar, complex or vector. */
2980 : :
2981 : : bool
2982 : 15833765 : zerop (const_tree expr)
2983 : : {
2984 : 15833765 : return (integer_zerop (expr)
2985 : 10705582 : || real_zerop (expr)
2986 : 26136894 : || fixed_zerop (expr));
2987 : : }
2988 : :
2989 : : /* Return true if EXPR is the integer constant zero or a complex constant
2990 : : of zero, or a location wrapper for such a constant. */
2991 : :
2992 : : bool
2993 : 5329245289 : integer_zerop (const_tree expr)
2994 : : {
2995 : 5329245289 : STRIP_ANY_LOCATION_WRAPPER (expr);
2996 : :
2997 : 5329245289 : switch (TREE_CODE (expr))
2998 : : {
2999 : 4471498352 : case INTEGER_CST:
3000 : 4471498352 : return wi::to_wide (expr) == 0;
3001 : 1195249 : case COMPLEX_CST:
3002 : 1195249 : return (integer_zerop (TREE_REALPART (expr))
3003 : 1217145 : && integer_zerop (TREE_IMAGPART (expr)));
3004 : 1990717 : case VECTOR_CST:
3005 : 1990717 : return (VECTOR_CST_NPATTERNS (expr) == 1
3006 : 1919366 : && VECTOR_CST_DUPLICATE_P (expr)
3007 : 3696393 : && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
3008 : : default:
3009 : : return false;
3010 : : }
3011 : : }
3012 : :
3013 : : /* Return true if EXPR is the integer constant one or the corresponding
3014 : : complex constant, or a location wrapper for such a constant. */
3015 : :
3016 : : bool
3017 : 890718543 : integer_onep (const_tree expr)
3018 : : {
3019 : 890718543 : STRIP_ANY_LOCATION_WRAPPER (expr);
3020 : :
3021 : 890718543 : switch (TREE_CODE (expr))
3022 : : {
3023 : 759281828 : case INTEGER_CST:
3024 : 759281828 : return wi::eq_p (wi::to_widest (expr), 1);
3025 : 21346 : case COMPLEX_CST:
3026 : 21346 : return (integer_onep (TREE_REALPART (expr))
3027 : 21366 : && integer_zerop (TREE_IMAGPART (expr)));
3028 : 132131 : case VECTOR_CST:
3029 : 132131 : return (VECTOR_CST_NPATTERNS (expr) == 1
3030 : 117342 : && VECTOR_CST_DUPLICATE_P (expr)
3031 : 238503 : && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3032 : : default:
3033 : : return false;
3034 : : }
3035 : : }
3036 : :
3037 : : /* Return true if EXPR is the integer constant one. For complex and vector,
3038 : : return true if every piece is the integer constant one.
3039 : : Also return true for location wrappers for such a constant. */
3040 : :
3041 : : bool
3042 : 728057 : integer_each_onep (const_tree expr)
3043 : : {
3044 : 728057 : STRIP_ANY_LOCATION_WRAPPER (expr);
3045 : :
3046 : 728057 : if (TREE_CODE (expr) == COMPLEX_CST)
3047 : 34 : return (integer_onep (TREE_REALPART (expr))
3048 : 48 : && integer_onep (TREE_IMAGPART (expr)));
3049 : : else
3050 : 728023 : return integer_onep (expr);
3051 : : }
3052 : :
3053 : : /* Return true if EXPR is an integer containing all 1's in as much precision
3054 : : as it contains, or a complex or vector whose subparts are such integers,
3055 : : or a location wrapper for such a constant. */
3056 : :
3057 : : bool
3058 : 265638731 : integer_all_onesp (const_tree expr)
3059 : : {
3060 : 265638731 : STRIP_ANY_LOCATION_WRAPPER (expr);
3061 : :
3062 : 265638731 : if (TREE_CODE (expr) == COMPLEX_CST
3063 : 926 : && integer_all_onesp (TREE_REALPART (expr))
3064 : 265638771 : && integer_all_onesp (TREE_IMAGPART (expr)))
3065 : : return true;
3066 : :
3067 : 265638695 : else if (TREE_CODE (expr) == VECTOR_CST)
3068 : 417426 : return (VECTOR_CST_NPATTERNS (expr) == 1
3069 : 402440 : && VECTOR_CST_DUPLICATE_P (expr)
3070 : 803704 : && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
3071 : :
3072 : 265221269 : else if (TREE_CODE (expr) != INTEGER_CST)
3073 : : return false;
3074 : :
3075 : 174473407 : return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED)
3076 : 348947250 : == wi::to_wide (expr));
3077 : : }
3078 : :
3079 : : /* Return true if EXPR is the integer constant minus one, or a location
3080 : : wrapper for such a constant. */
3081 : :
3082 : : bool
3083 : 192692704 : integer_minus_onep (const_tree expr)
3084 : : {
3085 : 192692704 : STRIP_ANY_LOCATION_WRAPPER (expr);
3086 : :
3087 : 192692704 : if (TREE_CODE (expr) == COMPLEX_CST)
3088 : 9060 : return (integer_all_onesp (TREE_REALPART (expr))
3089 : 9064 : && integer_zerop (TREE_IMAGPART (expr)));
3090 : : else
3091 : 192683644 : return integer_all_onesp (expr);
3092 : : }
3093 : :
3094 : : /* Return true if EXPR is an integer constant that is a power of 2 (i.e., has
3095 : : only one bit on), or a location wrapper for such a constant. */
3096 : :
3097 : : bool
3098 : 20674831 : integer_pow2p (const_tree expr)
3099 : : {
3100 : 20674831 : STRIP_ANY_LOCATION_WRAPPER (expr);
3101 : :
3102 : 20674831 : if (TREE_CODE (expr) == COMPLEX_CST
3103 : 543 : && integer_pow2p (TREE_REALPART (expr))
3104 : 20675058 : && integer_zerop (TREE_IMAGPART (expr)))
3105 : : return true;
3106 : :
3107 : 20674678 : if (TREE_CODE (expr) != INTEGER_CST)
3108 : : return false;
3109 : :
3110 : 14305280 : return wi::popcount (wi::to_wide (expr)) == 1;
3111 : : }
3112 : :
3113 : : /* Return true if EXPR is an integer constant other than zero or a
3114 : : complex constant other than zero, or a location wrapper for such a
3115 : : constant. */
3116 : :
3117 : : bool
3118 : 133569206 : integer_nonzerop (const_tree expr)
3119 : : {
3120 : 133569206 : STRIP_ANY_LOCATION_WRAPPER (expr);
3121 : :
3122 : 133569206 : return ((TREE_CODE (expr) == INTEGER_CST
3123 : 62187680 : && wi::to_wide (expr) != 0)
3124 : 146865965 : || (TREE_CODE (expr) == COMPLEX_CST
3125 : 242 : && (integer_nonzerop (TREE_REALPART (expr))
3126 : 182 : || integer_nonzerop (TREE_IMAGPART (expr)))));
3127 : : }
3128 : :
3129 : : /* Return true if EXPR is the integer constant one. For vector,
3130 : : return true if every piece is the integer constant minus one
3131 : : (representing the value TRUE).
3132 : : Also return true for location wrappers for such a constant. */
3133 : :
3134 : : bool
3135 : 1107054 : integer_truep (const_tree expr)
3136 : : {
3137 : 1107054 : STRIP_ANY_LOCATION_WRAPPER (expr);
3138 : :
3139 : 1107054 : if (TREE_CODE (expr) == VECTOR_CST)
3140 : 12259 : return integer_all_onesp (expr);
3141 : 1094795 : return integer_onep (expr);
3142 : : }
3143 : :
3144 : : /* Return true if EXPR is the fixed-point constant zero, or a location wrapper
3145 : : for such a constant. */
3146 : :
3147 : : bool
3148 : 23808655 : fixed_zerop (const_tree expr)
3149 : : {
3150 : 23808655 : STRIP_ANY_LOCATION_WRAPPER (expr);
3151 : :
3152 : 23808655 : return (TREE_CODE (expr) == FIXED_CST
3153 : 23808655 : && TREE_FIXED_CST (expr).data.is_zero ());
3154 : : }
3155 : :
3156 : : /* Return the power of two represented by a tree node known to be a
3157 : : power of two. */
3158 : :
3159 : : int
3160 : 686967 : tree_log2 (const_tree expr)
3161 : : {
3162 : 686967 : if (TREE_CODE (expr) == COMPLEX_CST)
3163 : 0 : return tree_log2 (TREE_REALPART (expr));
3164 : :
3165 : 686967 : return wi::exact_log2 (wi::to_wide (expr));
3166 : : }
3167 : :
3168 : : /* Similar, but return the largest integer Y such that 2 ** Y is less
3169 : : than or equal to EXPR. */
3170 : :
3171 : : int
3172 : 2591042 : tree_floor_log2 (const_tree expr)
3173 : : {
3174 : 2591042 : if (TREE_CODE (expr) == COMPLEX_CST)
3175 : 0 : return tree_log2 (TREE_REALPART (expr));
3176 : :
3177 : 2591042 : return wi::floor_log2 (wi::to_wide (expr));
3178 : : }
3179 : :
3180 : : /* Return number of known trailing zero bits in EXPR, or, if the value of
3181 : : EXPR is known to be zero, the precision of it's type. */
3182 : :
3183 : : unsigned int
3184 : 82238632 : tree_ctz (const_tree expr)
3185 : : {
3186 : 164475641 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
3187 : 82246056 : && !POINTER_TYPE_P (TREE_TYPE (expr)))
3188 : : return 0;
3189 : :
3190 : 82238616 : unsigned int ret1, ret2, prec = TYPE_PRECISION (TREE_TYPE (expr));
3191 : 82238616 : switch (TREE_CODE (expr))
3192 : : {
3193 : 43440886 : case INTEGER_CST:
3194 : 43440886 : ret1 = wi::ctz (wi::to_wide (expr));
3195 : 43440886 : return MIN (ret1, prec);
3196 : 12636938 : case SSA_NAME:
3197 : 12636938 : ret1 = wi::ctz (get_nonzero_bits (expr));
3198 : 12636938 : return MIN (ret1, prec);
3199 : 2003457 : case PLUS_EXPR:
3200 : 2003457 : case MINUS_EXPR:
3201 : 2003457 : case BIT_IOR_EXPR:
3202 : 2003457 : case BIT_XOR_EXPR:
3203 : 2003457 : case MIN_EXPR:
3204 : 2003457 : case MAX_EXPR:
3205 : 2003457 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3206 : 2003457 : if (ret1 == 0)
3207 : : return ret1;
3208 : 918074 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3209 : 918074 : return MIN (ret1, ret2);
3210 : 0 : case POINTER_PLUS_EXPR:
3211 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3212 : 0 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3213 : : /* Second operand is sizetype, which could be in theory
3214 : : wider than pointer's precision. Make sure we never
3215 : : return more than prec. */
3216 : 0 : ret2 = MIN (ret2, prec);
3217 : 0 : return MIN (ret1, ret2);
3218 : 273 : case BIT_AND_EXPR:
3219 : 273 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3220 : 273 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3221 : 273 : return MAX (ret1, ret2);
3222 : 11802856 : case MULT_EXPR:
3223 : 11802856 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3224 : 11802856 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3225 : 11802856 : return MIN (ret1 + ret2, prec);
3226 : 0 : case LSHIFT_EXPR:
3227 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3228 : 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3229 : 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3230 : : {
3231 : 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3232 : 0 : return MIN (ret1 + ret2, prec);
3233 : : }
3234 : : return ret1;
3235 : 0 : case RSHIFT_EXPR:
3236 : 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3237 : 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3238 : : {
3239 : 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3240 : 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3241 : 0 : if (ret1 > ret2)
3242 : 0 : return ret1 - ret2;
3243 : : }
3244 : : return 0;
3245 : 5684 : case TRUNC_DIV_EXPR:
3246 : 5684 : case CEIL_DIV_EXPR:
3247 : 5684 : case FLOOR_DIV_EXPR:
3248 : 5684 : case ROUND_DIV_EXPR:
3249 : 5684 : case EXACT_DIV_EXPR:
3250 : 5684 : if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
3251 : 5684 : && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) == 1)
3252 : : {
3253 : 5684 : int l = tree_log2 (TREE_OPERAND (expr, 1));
3254 : 5684 : if (l >= 0)
3255 : : {
3256 : 4545 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3257 : 4545 : ret2 = l;
3258 : 4545 : if (ret1 > ret2)
3259 : 0 : return ret1 - ret2;
3260 : : }
3261 : : }
3262 : : return 0;
3263 : 12325015 : CASE_CONVERT:
3264 : 12325015 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3265 : 12325015 : if (ret1 && ret1 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
3266 : : ret1 = prec;
3267 : 12325015 : return MIN (ret1, prec);
3268 : 0 : case SAVE_EXPR:
3269 : 0 : return tree_ctz (TREE_OPERAND (expr, 0));
3270 : 9620 : case COND_EXPR:
3271 : 9620 : ret1 = tree_ctz (TREE_OPERAND (expr, 1));
3272 : 9620 : if (ret1 == 0)
3273 : : return 0;
3274 : 186 : ret2 = tree_ctz (TREE_OPERAND (expr, 2));
3275 : 186 : return MIN (ret1, ret2);
3276 : 0 : case COMPOUND_EXPR:
3277 : 0 : return tree_ctz (TREE_OPERAND (expr, 1));
3278 : 187 : case ADDR_EXPR:
3279 : 187 : ret1 = get_pointer_alignment (CONST_CAST_TREE (expr));
3280 : 187 : if (ret1 > BITS_PER_UNIT)
3281 : : {
3282 : 187 : ret1 = ctz_hwi (ret1 / BITS_PER_UNIT);
3283 : 187 : return MIN (ret1, prec);
3284 : : }
3285 : : return 0;
3286 : : default:
3287 : : return 0;
3288 : : }
3289 : : }
3290 : :
3291 : : /* Return true if EXPR is the real constant zero. Trailing zeroes matter for
3292 : : decimal float constants, so don't return true for them.
3293 : : Also return true for location wrappers around such a constant. */
3294 : :
3295 : : bool
3296 : 555087853 : real_zerop (const_tree expr)
3297 : : {
3298 : 555087853 : STRIP_ANY_LOCATION_WRAPPER (expr);
3299 : :
3300 : 555087853 : switch (TREE_CODE (expr))
3301 : : {
3302 : 19391350 : case REAL_CST:
3303 : 19391350 : return real_equal (&TREE_REAL_CST (expr), &dconst0)
3304 : 19391350 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3305 : 44615 : case COMPLEX_CST:
3306 : 44615 : return real_zerop (TREE_REALPART (expr))
3307 : 57657 : && real_zerop (TREE_IMAGPART (expr));
3308 : 428475 : case VECTOR_CST:
3309 : 428475 : {
3310 : : /* Don't simply check for a duplicate because the predicate
3311 : : accepts both +0.0 and -0.0. */
3312 : 428475 : unsigned count = vector_cst_encoded_nelts (expr);
3313 : 453634 : for (unsigned int i = 0; i < count; ++i)
3314 : 437759 : if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3315 : : return false;
3316 : : return true;
3317 : : }
3318 : : default:
3319 : : return false;
3320 : : }
3321 : : }
3322 : :
3323 : : /* Return true if EXPR is the real constant one in real or complex form.
3324 : : Trailing zeroes matter for decimal float constants, so don't return
3325 : : true for them.
3326 : : Also return true for location wrappers around such a constant. */
3327 : :
3328 : : bool
3329 : 115235427 : real_onep (const_tree expr)
3330 : : {
3331 : 115235427 : STRIP_ANY_LOCATION_WRAPPER (expr);
3332 : :
3333 : 115235427 : switch (TREE_CODE (expr))
3334 : : {
3335 : 7303688 : case REAL_CST:
3336 : 7303688 : return real_equal (&TREE_REAL_CST (expr), &dconst1)
3337 : 7303688 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3338 : 12593 : case COMPLEX_CST:
3339 : 12593 : return real_onep (TREE_REALPART (expr))
3340 : 16082 : && real_zerop (TREE_IMAGPART (expr));
3341 : 56985 : case VECTOR_CST:
3342 : 56985 : return (VECTOR_CST_NPATTERNS (expr) == 1
3343 : 48821 : && VECTOR_CST_DUPLICATE_P (expr)
3344 : 97103 : && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3345 : : default:
3346 : : return false;
3347 : : }
3348 : : }
3349 : :
3350 : : /* Return true if EXPR is the real constant minus one. Trailing zeroes
3351 : : matter for decimal float constants, so don't return true for them.
3352 : : Also return true for location wrappers around such a constant. */
3353 : :
3354 : : bool
3355 : 116219044 : real_minus_onep (const_tree expr)
3356 : : {
3357 : 116219044 : STRIP_ANY_LOCATION_WRAPPER (expr);
3358 : :
3359 : 116219044 : switch (TREE_CODE (expr))
3360 : : {
3361 : 7241828 : case REAL_CST:
3362 : 7241828 : return real_equal (&TREE_REAL_CST (expr), &dconstm1)
3363 : 7241828 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3364 : 12573 : case COMPLEX_CST:
3365 : 12573 : return real_minus_onep (TREE_REALPART (expr))
3366 : 14945 : && real_zerop (TREE_IMAGPART (expr));
3367 : 58668 : case VECTOR_CST:
3368 : 58668 : return (VECTOR_CST_NPATTERNS (expr) == 1
3369 : 49936 : && VECTOR_CST_DUPLICATE_P (expr)
3370 : 99750 : && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3371 : : default:
3372 : : return false;
3373 : : }
3374 : : }
3375 : :
3376 : : /* Return true if T could be a floating point zero. */
3377 : :
3378 : : bool
3379 : 686434 : real_maybe_zerop (const_tree expr)
3380 : : {
3381 : 686434 : switch (TREE_CODE (expr))
3382 : : {
3383 : 470721 : case REAL_CST:
3384 : : /* Can't use real_zerop here, as it always returns false for decimal
3385 : : floats. And can't use TREE_REAL_CST (expr).cl == rvc_zero
3386 : : either, as decimal zeros are rvc_normal. */
3387 : 470721 : return real_equal (&TREE_REAL_CST (expr), &dconst0);
3388 : 0 : case COMPLEX_CST:
3389 : 0 : return (real_maybe_zerop (TREE_REALPART (expr))
3390 : 0 : || real_maybe_zerop (TREE_IMAGPART (expr)));
3391 : 0 : case VECTOR_CST:
3392 : 0 : {
3393 : 0 : unsigned count = vector_cst_encoded_nelts (expr);
3394 : 0 : for (unsigned int i = 0; i < count; ++i)
3395 : 0 : if (real_maybe_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3396 : : return true;
3397 : : return false;
3398 : : }
3399 : : default:
3400 : : /* Perhaps for SSA_NAMEs we could query frange. */
3401 : : return true;
3402 : : }
3403 : : }
3404 : :
3405 : : /* True if EXP is a constant or a cast of a constant. */
3406 : :
3407 : : bool
3408 : 3481 : really_constant_p (const_tree exp)
3409 : : {
3410 : : /* This is not quite the same as STRIP_NOPS. It does more. */
3411 : 6970 : while (CONVERT_EXPR_P (exp)
3412 : 7022 : || TREE_CODE (exp) == NON_LVALUE_EXPR)
3413 : 60 : exp = TREE_OPERAND (exp, 0);
3414 : 3481 : return TREE_CONSTANT (exp);
3415 : : }
3416 : :
3417 : : /* Return true if T holds a polynomial pointer difference, storing it in
3418 : : *VALUE if so. A true return means that T's precision is no greater
3419 : : than 64 bits, which is the largest address space we support, so *VALUE
3420 : : never loses precision. However, the signedness of the result does
3421 : : not necessarily match the signedness of T: sometimes an unsigned type
3422 : : like sizetype is used to encode a value that is actually negative. */
3423 : :
3424 : : bool
3425 : 10652437 : ptrdiff_tree_p (const_tree t, poly_int64 *value)
3426 : : {
3427 : 10652437 : if (!t)
3428 : : return false;
3429 : 10652437 : if (TREE_CODE (t) == INTEGER_CST)
3430 : : {
3431 : 2966172 : if (!cst_and_fits_in_hwi (t))
3432 : : return false;
3433 : 2965414 : *value = int_cst_value (t);
3434 : 2965414 : return true;
3435 : : }
3436 : : if (POLY_INT_CST_P (t))
3437 : : {
3438 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3439 : : if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t, i)))
3440 : : return false;
3441 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3442 : : value->coeffs[i] = int_cst_value (POLY_INT_CST_COEFF (t, i));
3443 : : return true;
3444 : : }
3445 : : return false;
3446 : : }
3447 : :
3448 : : poly_int64
3449 : 420950115 : tree_to_poly_int64 (const_tree t)
3450 : : {
3451 : 420950115 : gcc_assert (tree_fits_poly_int64_p (t));
3452 : 420950115 : if (POLY_INT_CST_P (t))
3453 : : return poly_int_cst_value (t).force_shwi ();
3454 : 420950115 : return TREE_INT_CST_LOW (t);
3455 : : }
3456 : :
3457 : : poly_uint64
3458 : 438677604 : tree_to_poly_uint64 (const_tree t)
3459 : : {
3460 : 438677604 : gcc_assert (tree_fits_poly_uint64_p (t));
3461 : 438677604 : if (POLY_INT_CST_P (t))
3462 : : return poly_int_cst_value (t).force_uhwi ();
3463 : 438677604 : return TREE_INT_CST_LOW (t);
3464 : : }
3465 : :
3466 : : /* Return first list element whose TREE_VALUE is ELEM.
3467 : : Return 0 if ELEM is not in LIST. */
3468 : :
3469 : : tree
3470 : 7642266 : value_member (tree elem, tree list)
3471 : : {
3472 : 22381921 : while (list)
3473 : : {
3474 : 19467987 : if (elem == TREE_VALUE (list))
3475 : : return list;
3476 : 14739655 : list = TREE_CHAIN (list);
3477 : : }
3478 : : return NULL_TREE;
3479 : : }
3480 : :
3481 : : /* Return first list element whose TREE_PURPOSE is ELEM.
3482 : : Return 0 if ELEM is not in LIST. */
3483 : :
3484 : : tree
3485 : 134346574 : purpose_member (const_tree elem, tree list)
3486 : : {
3487 : 308805652 : while (list)
3488 : : {
3489 : 188153724 : if (elem == TREE_PURPOSE (list))
3490 : : return list;
3491 : 174459078 : list = TREE_CHAIN (list);
3492 : : }
3493 : : return NULL_TREE;
3494 : : }
3495 : :
3496 : : /* Return true if ELEM is in V. */
3497 : :
3498 : : bool
3499 : 1857289 : vec_member (const_tree elem, vec<tree, va_gc> *v)
3500 : : {
3501 : 1857289 : unsigned ix;
3502 : 1857289 : tree t;
3503 : 3430225 : FOR_EACH_VEC_SAFE_ELT (v, ix, t)
3504 : 1574878 : if (elem == t)
3505 : : return true;
3506 : : return false;
3507 : : }
3508 : :
3509 : : /* Returns element number IDX (zero-origin) of chain CHAIN, or
3510 : : NULL_TREE. */
3511 : :
3512 : : tree
3513 : 17549198 : chain_index (int idx, tree chain)
3514 : : {
3515 : 22451894 : for (; chain && idx > 0; --idx)
3516 : 4902696 : chain = TREE_CHAIN (chain);
3517 : 17549198 : return chain;
3518 : : }
3519 : :
3520 : : /* Return true if ELEM is part of the chain CHAIN. */
3521 : :
3522 : : bool
3523 : 177736 : chain_member (const_tree elem, const_tree chain)
3524 : : {
3525 : 345549 : while (chain)
3526 : : {
3527 : 344266 : if (elem == chain)
3528 : : return true;
3529 : 167813 : chain = DECL_CHAIN (chain);
3530 : : }
3531 : :
3532 : : return false;
3533 : : }
3534 : :
3535 : : /* Return the length of a chain of nodes chained through TREE_CHAIN.
3536 : : We expect a null pointer to mark the end of the chain.
3537 : : This is the Lisp primitive `length'. */
3538 : :
3539 : : int
3540 : 1893893105 : list_length (const_tree t)
3541 : : {
3542 : 1893893105 : const_tree p = t;
3543 : : #ifdef ENABLE_TREE_CHECKING
3544 : 1893893105 : const_tree q = t;
3545 : : #endif
3546 : 1893893105 : int len = 0;
3547 : :
3548 : 2981800998 : while (p)
3549 : : {
3550 : 1087907893 : p = TREE_CHAIN (p);
3551 : : #ifdef ENABLE_TREE_CHECKING
3552 : 1087907893 : if (len % 2)
3553 : 351009727 : q = TREE_CHAIN (q);
3554 : 1087907893 : gcc_assert (p != q);
3555 : : #endif
3556 : 1087907893 : len++;
3557 : : }
3558 : :
3559 : 1893893105 : return len;
3560 : : }
3561 : :
3562 : : /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3563 : : UNION_TYPE TYPE, or NULL_TREE if none. */
3564 : :
3565 : : tree
3566 : 38116 : first_field (const_tree type)
3567 : : {
3568 : 38116 : tree t = TYPE_FIELDS (type);
3569 : 2753316 : while (t && TREE_CODE (t) != FIELD_DECL)
3570 : 2715200 : t = TREE_CHAIN (t);
3571 : 38116 : return t;
3572 : : }
3573 : :
3574 : : /* Returns the last FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3575 : : UNION_TYPE TYPE, or NULL_TREE if none. */
3576 : :
3577 : : tree
3578 : 2690978 : last_field (const_tree type)
3579 : : {
3580 : 2690978 : tree last = NULL_TREE;
3581 : :
3582 : 55114460 : for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
3583 : : {
3584 : 52423482 : if (TREE_CODE (fld) != FIELD_DECL)
3585 : 43999169 : continue;
3586 : :
3587 : : last = fld;
3588 : : }
3589 : :
3590 : 2690978 : return last;
3591 : : }
3592 : :
3593 : : /* Concatenate two chains of nodes (chained through TREE_CHAIN)
3594 : : by modifying the last node in chain 1 to point to chain 2.
3595 : : This is the Lisp primitive `nconc'. */
3596 : :
3597 : : tree
3598 : 3837838124 : chainon (tree op1, tree op2)
3599 : : {
3600 : 3837838124 : tree t1;
3601 : :
3602 : 3837838124 : if (!op1)
3603 : : return op2;
3604 : 683447705 : if (!op2)
3605 : : return op1;
3606 : :
3607 : 1446123708 : for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
3608 : 833657406 : continue;
3609 : 612466302 : TREE_CHAIN (t1) = op2;
3610 : :
3611 : : #ifdef ENABLE_TREE_CHECKING
3612 : 612466302 : {
3613 : 612466302 : tree t2;
3614 : 1607936354 : for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
3615 : 995470052 : gcc_assert (t2 != t1);
3616 : : }
3617 : : #endif
3618 : :
3619 : : return op1;
3620 : 833657406 : }
3621 : :
3622 : : /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
3623 : :
3624 : : tree
3625 : 88952428 : tree_last (tree chain)
3626 : : {
3627 : 88952428 : tree next;
3628 : 88952428 : if (chain)
3629 : 167780249 : while ((next = TREE_CHAIN (chain)))
3630 : : chain = next;
3631 : 88952428 : return chain;
3632 : : }
3633 : :
3634 : : /* Reverse the order of elements in the chain T,
3635 : : and return the new head of the chain (old last element). */
3636 : :
3637 : : tree
3638 : 1281520036 : nreverse (tree t)
3639 : : {
3640 : 1281520036 : tree prev = 0, decl, next;
3641 : 3306076492 : for (decl = t; decl; decl = next)
3642 : : {
3643 : : /* We shouldn't be using this function to reverse BLOCK chains; we
3644 : : have blocks_nreverse for that. */
3645 : 2024556456 : gcc_checking_assert (TREE_CODE (decl) != BLOCK);
3646 : 2024556456 : next = TREE_CHAIN (decl);
3647 : 2024556456 : TREE_CHAIN (decl) = prev;
3648 : 2024556456 : prev = decl;
3649 : : }
3650 : 1281520036 : return prev;
3651 : : }
3652 : :
3653 : : /* Return a newly created TREE_LIST node whose
3654 : : purpose and value fields are PARM and VALUE. */
3655 : :
3656 : : tree
3657 : 1200638944 : build_tree_list (tree parm, tree value MEM_STAT_DECL)
3658 : : {
3659 : 1200638944 : tree t = make_node (TREE_LIST PASS_MEM_STAT);
3660 : 1200638944 : TREE_PURPOSE (t) = parm;
3661 : 1200638944 : TREE_VALUE (t) = value;
3662 : 1200638944 : return t;
3663 : : }
3664 : :
3665 : : /* Build a chain of TREE_LIST nodes from a vector. */
3666 : :
3667 : : tree
3668 : 80822788 : build_tree_list_vec (const vec<tree, va_gc> *vec MEM_STAT_DECL)
3669 : : {
3670 : 80822788 : tree ret = NULL_TREE;
3671 : 80822788 : tree *pp = &ret;
3672 : 80822788 : unsigned int i;
3673 : 80822788 : tree t;
3674 : 170796717 : FOR_EACH_VEC_SAFE_ELT (vec, i, t)
3675 : : {
3676 : 89973929 : *pp = build_tree_list (NULL, t PASS_MEM_STAT);
3677 : 89973929 : pp = &TREE_CHAIN (*pp);
3678 : : }
3679 : 80822788 : return ret;
3680 : : }
3681 : :
3682 : : /* Return a newly created TREE_LIST node whose
3683 : : purpose and value fields are PURPOSE and VALUE
3684 : : and whose TREE_CHAIN is CHAIN. */
3685 : :
3686 : : tree
3687 : 4863076852 : tree_cons (tree purpose, tree value, tree chain MEM_STAT_DECL)
3688 : : {
3689 : 4863076852 : tree node;
3690 : :
3691 : 4863076852 : node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT);
3692 : 4863076852 : memset (node, 0, sizeof (struct tree_common));
3693 : :
3694 : 4863076852 : record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
3695 : :
3696 : 4863076852 : TREE_SET_CODE (node, TREE_LIST);
3697 : 4863076852 : TREE_CHAIN (node) = chain;
3698 : 4863076852 : TREE_PURPOSE (node) = purpose;
3699 : 4863076852 : TREE_VALUE (node) = value;
3700 : 4863076852 : return node;
3701 : : }
3702 : :
3703 : : /* Return the values of the elements of a CONSTRUCTOR as a vector of
3704 : : trees. */
3705 : :
3706 : : vec<tree, va_gc> *
3707 : 0 : ctor_to_vec (tree ctor)
3708 : : {
3709 : 0 : vec<tree, va_gc> *vec;
3710 : 0 : vec_alloc (vec, CONSTRUCTOR_NELTS (ctor));
3711 : 0 : unsigned int ix;
3712 : 0 : tree val;
3713 : :
3714 : 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
3715 : 0 : vec->quick_push (val);
3716 : :
3717 : 0 : return vec;
3718 : : }
3719 : :
3720 : : /* Return the size nominally occupied by an object of type TYPE
3721 : : when it resides in memory. The value is measured in units of bytes,
3722 : : and its data type is that normally used for type sizes
3723 : : (which is the first type created by make_signed_type or
3724 : : make_unsigned_type). */
3725 : :
3726 : : tree
3727 : 25623393 : size_in_bytes_loc (location_t loc, const_tree type)
3728 : : {
3729 : 25623393 : tree t;
3730 : :
3731 : 25623393 : if (type == error_mark_node)
3732 : 0 : return integer_zero_node;
3733 : :
3734 : 25623393 : type = TYPE_MAIN_VARIANT (type);
3735 : 25623393 : t = TYPE_SIZE_UNIT (type);
3736 : :
3737 : 25623393 : if (t == 0)
3738 : : {
3739 : 56 : lang_hooks.types.incomplete_type_error (loc, NULL_TREE, type);
3740 : 56 : return size_zero_node;
3741 : : }
3742 : :
3743 : : return t;
3744 : : }
3745 : :
3746 : : /* Return the size of TYPE (in bytes) as a wide integer
3747 : : or return -1 if the size can vary or is larger than an integer. */
3748 : :
3749 : : HOST_WIDE_INT
3750 : 488436939 : int_size_in_bytes (const_tree type)
3751 : : {
3752 : 488436939 : tree t;
3753 : :
3754 : 488436939 : if (type == error_mark_node)
3755 : : return 0;
3756 : :
3757 : 488436939 : type = TYPE_MAIN_VARIANT (type);
3758 : 488436939 : t = TYPE_SIZE_UNIT (type);
3759 : :
3760 : 488436939 : if (t && tree_fits_uhwi_p (t))
3761 : 488386985 : return TREE_INT_CST_LOW (t);
3762 : : else
3763 : : return -1;
3764 : : }
3765 : :
3766 : : /* Return the maximum size of TYPE (in bytes) as a wide integer
3767 : : or return -1 if the size can vary or is larger than an integer. */
3768 : :
3769 : : HOST_WIDE_INT
3770 : 9093 : max_int_size_in_bytes (const_tree type)
3771 : : {
3772 : 9093 : HOST_WIDE_INT size = -1;
3773 : 9093 : tree size_tree;
3774 : :
3775 : : /* If this is an array type, check for a possible MAX_SIZE attached. */
3776 : :
3777 : 9093 : if (TREE_CODE (type) == ARRAY_TYPE)
3778 : : {
3779 : 8376 : size_tree = TYPE_ARRAY_MAX_SIZE (type);
3780 : :
3781 : 8376 : if (size_tree && tree_fits_uhwi_p (size_tree))
3782 : 0 : size = tree_to_uhwi (size_tree);
3783 : : }
3784 : :
3785 : : /* If we still haven't been able to get a size, see if the language
3786 : : can compute a maximum size. */
3787 : :
3788 : 0 : if (size == -1)
3789 : : {
3790 : 9093 : size_tree = lang_hooks.types.max_size (type);
3791 : :
3792 : 9093 : if (size_tree && tree_fits_uhwi_p (size_tree))
3793 : 0 : size = tree_to_uhwi (size_tree);
3794 : : }
3795 : :
3796 : 9093 : return size;
3797 : : }
3798 : :
3799 : : /* Return the bit position of FIELD, in bits from the start of the record.
3800 : : This is a tree of type bitsizetype. */
3801 : :
3802 : : tree
3803 : 94097818 : bit_position (const_tree field)
3804 : : {
3805 : 94097818 : return bit_from_pos (DECL_FIELD_OFFSET (field),
3806 : 94097818 : DECL_FIELD_BIT_OFFSET (field));
3807 : : }
3808 : :
3809 : : /* Return the byte position of FIELD, in bytes from the start of the record.
3810 : : This is a tree of type sizetype. */
3811 : :
3812 : : tree
3813 : 99354173 : byte_position (const_tree field)
3814 : : {
3815 : 99354173 : return byte_from_pos (DECL_FIELD_OFFSET (field),
3816 : 99354173 : DECL_FIELD_BIT_OFFSET (field));
3817 : : }
3818 : :
3819 : : /* Likewise, but return as an integer. It must be representable in
3820 : : that way (since it could be a signed value, we don't have the
3821 : : option of returning -1 like int_size_in_byte can. */
3822 : :
3823 : : HOST_WIDE_INT
3824 : 9750084 : int_byte_position (const_tree field)
3825 : : {
3826 : 9750084 : return tree_to_shwi (byte_position (field));
3827 : : }
3828 : :
3829 : : /* Return, as a tree node, the number of elements for TYPE (which is an
3830 : : ARRAY_TYPE) minus one. This counts only elements of the top array. */
3831 : :
3832 : : tree
3833 : 77152319 : array_type_nelts_minus_one (const_tree type)
3834 : : {
3835 : 77152319 : tree index_type, min, max;
3836 : :
3837 : : /* If they did it with unspecified bounds, then we should have already
3838 : : given an error about it before we got here. */
3839 : 77152319 : if (! TYPE_DOMAIN (type))
3840 : 5629746 : return error_mark_node;
3841 : :
3842 : 71522573 : index_type = TYPE_DOMAIN (type);
3843 : 71522573 : min = TYPE_MIN_VALUE (index_type);
3844 : 71522573 : max = TYPE_MAX_VALUE (index_type);
3845 : :
3846 : : /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3847 : 71522573 : if (!max)
3848 : : {
3849 : : /* zero sized arrays are represented from C FE as complete types with
3850 : : NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
3851 : : them as min 0, max -1. */
3852 : 1245914 : if (COMPLETE_TYPE_P (type)
3853 : 3128 : && integer_zerop (TYPE_SIZE (type))
3854 : 1249042 : && integer_zerop (min))
3855 : 3128 : return build_int_cst (TREE_TYPE (min), -1);
3856 : :
3857 : 1242786 : return error_mark_node;
3858 : : }
3859 : :
3860 : 70276659 : return (integer_zerop (min)
3861 : 70276659 : ? max
3862 : 1051969 : : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
3863 : : }
3864 : :
3865 : : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3866 : : (which is an ARRAY_TYPE). This counts only elements of the top
3867 : : array. */
3868 : :
3869 : : tree
3870 : 5261196 : array_type_nelts_top (tree type)
3871 : : {
3872 : 5261196 : return fold_build2_loc (input_location,
3873 : : PLUS_EXPR, sizetype,
3874 : : array_type_nelts_minus_one (type),
3875 : 5261196 : size_one_node);
3876 : : }
3877 : :
3878 : : /* If arg is static -- a reference to an object in static storage -- then
3879 : : return the object. This is not the same as the C meaning of `static'.
3880 : : If arg isn't static, return NULL. */
3881 : :
3882 : : tree
3883 : 1045490271 : staticp (tree arg)
3884 : : {
3885 : 1046371854 : switch (TREE_CODE (arg))
3886 : : {
3887 : : case FUNCTION_DECL:
3888 : : /* Nested functions are static, even though taking their address will
3889 : : involve a trampoline as we unnest the nested function and create
3890 : : the trampoline on the tree level. */
3891 : : return arg;
3892 : :
3893 : 672699107 : case VAR_DECL:
3894 : 539899472 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3895 : 176942255 : && ! DECL_THREAD_LOCAL_P (arg)
3896 : 175156627 : && ! DECL_DLLIMPORT_P (arg)
3897 : 672699107 : ? arg : NULL);
3898 : :
3899 : 577579 : case CONST_DECL:
3900 : 62 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3901 : 577579 : ? arg : NULL);
3902 : :
3903 : 0 : case CONSTRUCTOR:
3904 : 0 : return TREE_STATIC (arg) ? arg : NULL;
3905 : :
3906 : : case LABEL_DECL:
3907 : : case STRING_CST:
3908 : : return arg;
3909 : :
3910 : 639283 : case COMPONENT_REF:
3911 : : /* If the thing being referenced is not a field, then it is
3912 : : something language specific. */
3913 : 639283 : gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
3914 : :
3915 : : /* If we are referencing a bitfield, we can't evaluate an
3916 : : ADDR_EXPR at compile time and so it isn't a constant. */
3917 : 639283 : if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
3918 : : return NULL;
3919 : :
3920 : 639283 : return staticp (TREE_OPERAND (arg, 0));
3921 : :
3922 : : case BIT_FIELD_REF:
3923 : : return NULL;
3924 : :
3925 : 63673 : case INDIRECT_REF:
3926 : 63673 : return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
3927 : :
3928 : 242643 : case ARRAY_REF:
3929 : 242643 : case ARRAY_RANGE_REF:
3930 : 242643 : if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
3931 : 242643 : && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
3932 : 242300 : return staticp (TREE_OPERAND (arg, 0));
3933 : : else
3934 : : return NULL;
3935 : :
3936 : 930 : case COMPOUND_LITERAL_EXPR:
3937 : 930 : return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
3938 : :
3939 : : default:
3940 : : return NULL;
3941 : : }
3942 : : }
3943 : :
3944 : :
3945 : :
3946 : :
3947 : : /* Return whether OP is a DECL whose address is function-invariant. */
3948 : :
3949 : : bool
3950 : 5101852992 : decl_address_invariant_p (const_tree op)
3951 : : {
3952 : : /* The conditions below are slightly less strict than the one in
3953 : : staticp. */
3954 : :
3955 : 5101852992 : switch (TREE_CODE (op))
3956 : : {
3957 : : case PARM_DECL:
3958 : : case RESULT_DECL:
3959 : : case LABEL_DECL:
3960 : : case FUNCTION_DECL:
3961 : : return true;
3962 : :
3963 : 2875599472 : case VAR_DECL:
3964 : 2186812162 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3965 : 2061158560 : || DECL_THREAD_LOCAL_P (op)
3966 : 2061158560 : || DECL_CONTEXT (op) == current_function_decl
3967 : 2882838603 : || decl_function_context (op) == current_function_decl)
3968 : 2868360341 : return true;
3969 : : break;
3970 : :
3971 : 25150989 : case CONST_DECL:
3972 : 0 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
3973 : 25150989 : || decl_function_context (op) == current_function_decl)
3974 : 25150989 : return true;
3975 : : break;
3976 : :
3977 : : default:
3978 : : break;
3979 : : }
3980 : :
3981 : : return false;
3982 : : }
3983 : :
3984 : : /* Return whether OP is a DECL whose address is interprocedural-invariant. */
3985 : :
3986 : : bool
3987 : 1715567 : decl_address_ip_invariant_p (const_tree op)
3988 : : {
3989 : : /* The conditions below are slightly less strict than the one in
3990 : : staticp. */
3991 : :
3992 : 1715567 : switch (TREE_CODE (op))
3993 : : {
3994 : : case LABEL_DECL:
3995 : : case FUNCTION_DECL:
3996 : : case STRING_CST:
3997 : : return true;
3998 : :
3999 : 1548388 : case VAR_DECL:
4000 : 1111481 : if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
4001 : 470408 : && !DECL_DLLIMPORT_P (op))
4002 : 2626368 : || DECL_THREAD_LOCAL_P (op))
4003 : 470408 : return true;
4004 : : break;
4005 : :
4006 : 52053 : case CONST_DECL:
4007 : 52053 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
4008 : : return true;
4009 : : break;
4010 : :
4011 : : default:
4012 : : break;
4013 : : }
4014 : :
4015 : : return false;
4016 : : }
4017 : :
4018 : : /* Return true if T is an object with invariant address. */
4019 : :
4020 : : bool
4021 : 20344 : address_invariant_p (tree t)
4022 : : {
4023 : 26944 : while (handled_component_p (t))
4024 : : {
4025 : 7505 : switch (TREE_CODE (t))
4026 : : {
4027 : 1377 : case ARRAY_REF:
4028 : 1377 : case ARRAY_RANGE_REF:
4029 : 1377 : if (!tree_invariant_p (TREE_OPERAND (t, 1))
4030 : 472 : || TREE_OPERAND (t, 2) != NULL_TREE
4031 : 1849 : || TREE_OPERAND (t, 3) != NULL_TREE)
4032 : : return false;
4033 : : break;
4034 : :
4035 : 5993 : case COMPONENT_REF:
4036 : 5993 : if (TREE_OPERAND (t, 2) != NULL_TREE)
4037 : : return false;
4038 : : break;
4039 : :
4040 : : default:
4041 : : break;
4042 : : }
4043 : 6600 : t = TREE_OPERAND (t, 0);
4044 : : }
4045 : :
4046 : 19439 : STRIP_ANY_LOCATION_WRAPPER (t);
4047 : 19439 : return CONSTANT_CLASS_P (t) || decl_address_invariant_p (t);
4048 : : }
4049 : :
4050 : :
4051 : : /* Return true if T is function-invariant (internal function, does
4052 : : not handle arithmetic; that's handled in skip_simple_arithmetic and
4053 : : tree_invariant_p). */
4054 : :
4055 : : static bool
4056 : 14355220 : tree_invariant_p_1 (tree t)
4057 : : {
4058 : 14355220 : if (TREE_CONSTANT (t) || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
4059 : : return true;
4060 : :
4061 : 12479963 : switch (TREE_CODE (t))
4062 : : {
4063 : : case SAVE_EXPR:
4064 : : case TARGET_EXPR:
4065 : : return true;
4066 : :
4067 : 20320 : case ADDR_EXPR:
4068 : 20320 : return address_invariant_p (TREE_OPERAND (t, 0));
4069 : :
4070 : : default:
4071 : : break;
4072 : : }
4073 : :
4074 : : return false;
4075 : : }
4076 : :
4077 : : /* Return true if T is function-invariant. */
4078 : :
4079 : : bool
4080 : 11669373 : tree_invariant_p (tree t)
4081 : : {
4082 : 11669373 : tree inner = skip_simple_arithmetic (t);
4083 : 11669373 : return tree_invariant_p_1 (inner);
4084 : : }
4085 : :
4086 : : /* Wrap a SAVE_EXPR around EXPR, if appropriate.
4087 : : Do this to any expression which may be used in more than one place,
4088 : : but must be evaluated only once.
4089 : :
4090 : : Normally, expand_expr would reevaluate the expression each time.
4091 : : Calling save_expr produces something that is evaluated and recorded
4092 : : the first time expand_expr is called on it. Subsequent calls to
4093 : : expand_expr just reuse the recorded value.
4094 : :
4095 : : The call to expand_expr that generates code that actually computes
4096 : : the value is the first call *at compile time*. Subsequent calls
4097 : : *at compile time* generate code to use the saved value.
4098 : : This produces correct result provided that *at run time* control
4099 : : always flows through the insns made by the first expand_expr
4100 : : before reaching the other places where the save_expr was evaluated.
4101 : : You, the caller of save_expr, must make sure this is so.
4102 : :
4103 : : Constants, and certain read-only nodes, are returned with no
4104 : : SAVE_EXPR because that is safe. Expressions containing placeholders
4105 : : are not touched; see tree.def for an explanation of what these
4106 : : are used for. */
4107 : :
4108 : : tree
4109 : 2685858 : save_expr (tree expr)
4110 : : {
4111 : 2685858 : tree inner;
4112 : :
4113 : : /* If the tree evaluates to a constant, then we don't want to hide that
4114 : : fact (i.e. this allows further folding, and direct checks for constants).
4115 : : However, a read-only object that has side effects cannot be bypassed.
4116 : : Since it is no problem to reevaluate literals, we just return the
4117 : : literal node. */
4118 : 2685858 : inner = skip_simple_arithmetic (expr);
4119 : 2685858 : if (TREE_CODE (inner) == ERROR_MARK)
4120 : : return inner;
4121 : :
4122 : 2685847 : if (tree_invariant_p_1 (inner))
4123 : : return expr;
4124 : :
4125 : : /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
4126 : : it means that the size or offset of some field of an object depends on
4127 : : the value within another field.
4128 : :
4129 : : Note that it must not be the case that EXPR contains both a PLACEHOLDER_EXPR
4130 : : and some variable since it would then need to be both evaluated once and
4131 : : evaluated more than once. Front-ends must assure this case cannot
4132 : : happen by surrounding any such subexpressions in their own SAVE_EXPR
4133 : : and forcing evaluation at the proper time. */
4134 : 1985669 : if (contains_placeholder_p (inner))
4135 : : return expr;
4136 : :
4137 : 1985669 : expr = build1_loc (EXPR_LOCATION (expr), SAVE_EXPR, TREE_TYPE (expr), expr);
4138 : :
4139 : : /* This expression might be placed ahead of a jump to ensure that the
4140 : : value was computed on both sides of the jump. So make sure it isn't
4141 : : eliminated as dead. */
4142 : 1985669 : TREE_SIDE_EFFECTS (expr) = 1;
4143 : 1985669 : return expr;
4144 : : }
4145 : :
4146 : : /* Look inside EXPR into any simple arithmetic operations. Return the
4147 : : outermost non-arithmetic or non-invariant node. */
4148 : :
4149 : : tree
4150 : 14355231 : skip_simple_arithmetic (tree expr)
4151 : : {
4152 : : /* We don't care about whether this can be used as an lvalue in this
4153 : : context. */
4154 : 14365596 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4155 : 10365 : expr = TREE_OPERAND (expr, 0);
4156 : :
4157 : : /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
4158 : : a constant, it will be more efficient to not make another SAVE_EXPR since
4159 : : it will allow better simplification and GCSE will be able to merge the
4160 : : computations if they actually occur. */
4161 : 38269227 : while (true)
4162 : : {
4163 : 38269227 : if (UNARY_CLASS_P (expr))
4164 : 14770621 : expr = TREE_OPERAND (expr, 0);
4165 : 23498606 : else if (BINARY_CLASS_P (expr))
4166 : : {
4167 : : /* Before commutative binary operands are canonicalized,
4168 : : it is quite common to have constants in the first operand.
4169 : : Check for that common case first so that we don't walk
4170 : : large expressions with tree_invariant_p unnecessarily.
4171 : : This can still have terrible compile time complexity,
4172 : : we should limit the depth of the tree_invariant_p and
4173 : : skip_simple_arithmetic recursion. */
4174 : 9207089 : if ((TREE_CONSTANT (TREE_OPERAND (expr, 0))
4175 : 9197025 : || (TREE_READONLY (TREE_OPERAND (expr, 0))
4176 : 9625 : && !TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0))))
4177 : 9216678 : && tree_invariant_p (TREE_OPERAND (expr, 0)))
4178 : 19653 : expr = TREE_OPERAND (expr, 1);
4179 : 9187436 : else if (tree_invariant_p (TREE_OPERAND (expr, 1)))
4180 : 9114508 : expr = TREE_OPERAND (expr, 0);
4181 : 72928 : else if (tree_invariant_p (TREE_OPERAND (expr, 0)))
4182 : 9214 : expr = TREE_OPERAND (expr, 1);
4183 : : else
4184 : : break;
4185 : : }
4186 : : else
4187 : : break;
4188 : : }
4189 : :
4190 : 14355231 : return expr;
4191 : : }
4192 : :
4193 : : /* Look inside EXPR into simple arithmetic operations involving constants.
4194 : : Return the outermost non-arithmetic or non-constant node. */
4195 : :
4196 : : tree
4197 : 0 : skip_simple_constant_arithmetic (tree expr)
4198 : : {
4199 : 0 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4200 : 0 : expr = TREE_OPERAND (expr, 0);
4201 : :
4202 : 0 : while (true)
4203 : : {
4204 : 0 : if (UNARY_CLASS_P (expr))
4205 : 0 : expr = TREE_OPERAND (expr, 0);
4206 : 0 : else if (BINARY_CLASS_P (expr))
4207 : : {
4208 : 0 : if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
4209 : 0 : expr = TREE_OPERAND (expr, 0);
4210 : 0 : else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
4211 : 0 : expr = TREE_OPERAND (expr, 1);
4212 : : else
4213 : : break;
4214 : : }
4215 : : else
4216 : : break;
4217 : : }
4218 : :
4219 : 0 : return expr;
4220 : : }
4221 : :
4222 : : /* Return which tree structure is used by T. */
4223 : :
4224 : : enum tree_node_structure_enum
4225 : 35492702635 : tree_node_structure (const_tree t)
4226 : : {
4227 : 35492702635 : const enum tree_code code = TREE_CODE (t);
4228 : 35492702635 : return tree_node_structure_for_code (code);
4229 : : }
4230 : :
4231 : : /* Set various status flags when building a CALL_EXPR object T. */
4232 : :
4233 : : static void
4234 : 230124124 : process_call_operands (tree t)
4235 : : {
4236 : 230124124 : bool side_effects = TREE_SIDE_EFFECTS (t);
4237 : 230124124 : bool read_only = false;
4238 : 230124124 : int i = call_expr_flags (t);
4239 : :
4240 : : /* Calls have side-effects, except those to const or pure functions. */
4241 : 230124124 : if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
4242 : : side_effects = true;
4243 : : /* Propagate TREE_READONLY of arguments for const functions. */
4244 : 52138460 : if (i & ECF_CONST)
4245 : 50536480 : read_only = true;
4246 : :
4247 : 230124124 : if (!side_effects || read_only)
4248 : 270602601 : for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
4249 : : {
4250 : 218464645 : tree op = TREE_OPERAND (t, i);
4251 : 218464645 : if (op && TREE_SIDE_EFFECTS (op))
4252 : : side_effects = true;
4253 : 218464645 : if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
4254 : : read_only = false;
4255 : : }
4256 : :
4257 : 230124124 : TREE_SIDE_EFFECTS (t) = side_effects;
4258 : 230124124 : TREE_READONLY (t) = read_only;
4259 : 230124124 : }
4260 : :
4261 : : /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
4262 : : size or offset that depends on a field within a record. */
4263 : :
4264 : : bool
4265 : 37676906 : contains_placeholder_p (const_tree exp)
4266 : : {
4267 : 37676906 : enum tree_code code;
4268 : :
4269 : 37676906 : if (!exp)
4270 : : return false;
4271 : :
4272 : 37676906 : code = TREE_CODE (exp);
4273 : 37676906 : if (code == PLACEHOLDER_EXPR)
4274 : : return true;
4275 : :
4276 : 37676906 : switch (TREE_CODE_CLASS (code))
4277 : : {
4278 : 1154604 : case tcc_reference:
4279 : : /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
4280 : : position computations since they will be converted into a
4281 : : WITH_RECORD_EXPR involving the reference, which will assume
4282 : : here will be valid. */
4283 : 1154604 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4284 : :
4285 : 509104 : case tcc_exceptional:
4286 : 509104 : if (code == TREE_LIST)
4287 : 0 : return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
4288 : 0 : || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
4289 : : break;
4290 : :
4291 : 33511745 : case tcc_unary:
4292 : 33511745 : case tcc_binary:
4293 : 33511745 : case tcc_comparison:
4294 : 33511745 : case tcc_expression:
4295 : 33511745 : switch (code)
4296 : : {
4297 : 5197 : case COMPOUND_EXPR:
4298 : : /* Ignoring the first operand isn't quite right, but works best. */
4299 : 5197 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
4300 : :
4301 : 2975 : case COND_EXPR:
4302 : 5950 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4303 : 2975 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
4304 : 5950 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
4305 : :
4306 : : case SAVE_EXPR:
4307 : : /* The save_expr function never wraps anything containing
4308 : : a PLACEHOLDER_EXPR. */
4309 : : return false;
4310 : :
4311 : 24263526 : default:
4312 : 24263526 : break;
4313 : : }
4314 : :
4315 : 24263526 : switch (TREE_CODE_LENGTH (code))
4316 : : {
4317 : 14791063 : case 1:
4318 : 14791063 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4319 : 9455745 : case 2:
4320 : 18910341 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4321 : 18910341 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
4322 : : default:
4323 : : return false;
4324 : : }
4325 : :
4326 : 440837 : case tcc_vl_exp:
4327 : 440837 : switch (code)
4328 : : {
4329 : 440837 : case CALL_EXPR:
4330 : 440837 : {
4331 : 440837 : const_tree arg;
4332 : 440837 : const_call_expr_arg_iterator iter;
4333 : 1457132 : FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
4334 : 575458 : if (CONTAINS_PLACEHOLDER_P (arg))
4335 : : return true;
4336 : : return false;
4337 : : }
4338 : : default:
4339 : : return false;
4340 : : }
4341 : :
4342 : : default:
4343 : : return false;
4344 : : }
4345 : : return false;
4346 : : }
4347 : :
4348 : : /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
4349 : : directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
4350 : : field positions. */
4351 : :
4352 : : static bool
4353 : 756933 : type_contains_placeholder_1 (const_tree type)
4354 : : {
4355 : : /* If the size contains a placeholder or the parent type (component type in
4356 : : the case of arrays) type involves a placeholder, this type does. */
4357 : 1493813 : if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
4358 : 756933 : || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
4359 : 1513866 : || (!POINTER_TYPE_P (type)
4360 : 625166 : && TREE_TYPE (type)
4361 : 104768 : && type_contains_placeholder_p (TREE_TYPE (type))))
4362 : 0 : return true;
4363 : :
4364 : : /* Now do type-specific checks. Note that the last part of the check above
4365 : : greatly limits what we have to do below. */
4366 : 756933 : switch (TREE_CODE (type))
4367 : : {
4368 : : case VOID_TYPE:
4369 : : case OPAQUE_TYPE:
4370 : : case COMPLEX_TYPE:
4371 : : case ENUMERAL_TYPE:
4372 : : case BOOLEAN_TYPE:
4373 : : case POINTER_TYPE:
4374 : : case OFFSET_TYPE:
4375 : : case REFERENCE_TYPE:
4376 : : case METHOD_TYPE:
4377 : : case FUNCTION_TYPE:
4378 : : case VECTOR_TYPE:
4379 : : case NULLPTR_TYPE:
4380 : : return false;
4381 : :
4382 : 161567 : case INTEGER_TYPE:
4383 : 161567 : case BITINT_TYPE:
4384 : 161567 : case REAL_TYPE:
4385 : 161567 : case FIXED_POINT_TYPE:
4386 : : /* Here we just check the bounds. */
4387 : 313498 : return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
4388 : 313498 : || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
4389 : :
4390 : 54688 : case ARRAY_TYPE:
4391 : : /* We have already checked the component type above, so just check
4392 : : the domain type. Flexible array members have a null domain. */
4393 : 109364 : return TYPE_DOMAIN (type) ?
4394 : 54676 : type_contains_placeholder_p (TYPE_DOMAIN (type)) : false;
4395 : :
4396 : 385730 : case RECORD_TYPE:
4397 : 385730 : case UNION_TYPE:
4398 : 385730 : case QUAL_UNION_TYPE:
4399 : 385730 : {
4400 : 385730 : tree field;
4401 : :
4402 : 11542757 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4403 : 11157027 : if (TREE_CODE (field) == FIELD_DECL
4404 : 11157027 : && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
4405 : 891333 : || (TREE_CODE (type) == QUAL_UNION_TYPE
4406 : 0 : && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
4407 : 891333 : || type_contains_placeholder_p (TREE_TYPE (field))))
4408 : 0 : return true;
4409 : :
4410 : : return false;
4411 : : }
4412 : :
4413 : 0 : default:
4414 : 0 : gcc_unreachable ();
4415 : : }
4416 : : }
4417 : :
4418 : : /* Wrapper around above function used to cache its result. */
4419 : :
4420 : : bool
4421 : 2961733 : type_contains_placeholder_p (tree type)
4422 : : {
4423 : 2961733 : bool result;
4424 : :
4425 : : /* If the contains_placeholder_bits field has been initialized,
4426 : : then we know the answer. */
4427 : 2961733 : if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
4428 : 2204800 : return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
4429 : :
4430 : : /* Indicate that we've seen this type node, and the answer is false.
4431 : : This is what we want to return if we run into recursion via fields. */
4432 : 756933 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
4433 : :
4434 : : /* Compute the real value. */
4435 : 756933 : result = type_contains_placeholder_1 (type);
4436 : :
4437 : : /* Store the real value. */
4438 : 756933 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
4439 : :
4440 : 756933 : return result;
4441 : : }
4442 : :
4443 : : /* Push tree EXP onto vector QUEUE if it is not already present. */
4444 : :
4445 : : static void
4446 : 0 : push_without_duplicates (tree exp, vec<tree> *queue)
4447 : : {
4448 : 0 : unsigned int i;
4449 : 0 : tree iter;
4450 : :
4451 : 0 : FOR_EACH_VEC_ELT (*queue, i, iter)
4452 : 0 : if (simple_cst_equal (iter, exp) == 1)
4453 : : break;
4454 : :
4455 : 0 : if (!iter)
4456 : 0 : queue->safe_push (exp);
4457 : 0 : }
4458 : :
4459 : : /* Given a tree EXP, find all occurrences of references to fields
4460 : : in a PLACEHOLDER_EXPR and place them in vector REFS without
4461 : : duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
4462 : : we assume here that EXP contains only arithmetic expressions
4463 : : or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
4464 : : argument list. */
4465 : :
4466 : : void
4467 : 0 : find_placeholder_in_expr (tree exp, vec<tree> *refs)
4468 : : {
4469 : 0 : enum tree_code code = TREE_CODE (exp);
4470 : 0 : tree inner;
4471 : 0 : int i;
4472 : :
4473 : : /* We handle TREE_LIST and COMPONENT_REF separately. */
4474 : 0 : if (code == TREE_LIST)
4475 : : {
4476 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
4477 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
4478 : : }
4479 : 0 : else if (code == COMPONENT_REF)
4480 : : {
4481 : 0 : for (inner = TREE_OPERAND (exp, 0);
4482 : 0 : REFERENCE_CLASS_P (inner);
4483 : 0 : inner = TREE_OPERAND (inner, 0))
4484 : : ;
4485 : :
4486 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
4487 : 0 : push_without_duplicates (exp, refs);
4488 : : else
4489 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
4490 : : }
4491 : : else
4492 : 0 : switch (TREE_CODE_CLASS (code))
4493 : : {
4494 : : case tcc_constant:
4495 : : break;
4496 : :
4497 : 0 : case tcc_declaration:
4498 : : /* Variables allocated to static storage can stay. */
4499 : 0 : if (!TREE_STATIC (exp))
4500 : 0 : push_without_duplicates (exp, refs);
4501 : : break;
4502 : :
4503 : 0 : case tcc_expression:
4504 : : /* This is the pattern built in ada/make_aligning_type. */
4505 : 0 : if (code == ADDR_EXPR
4506 : 0 : && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
4507 : : {
4508 : 0 : push_without_duplicates (exp, refs);
4509 : 0 : break;
4510 : : }
4511 : :
4512 : : /* Fall through. */
4513 : :
4514 : : case tcc_exceptional:
4515 : : case tcc_unary:
4516 : : case tcc_binary:
4517 : : case tcc_comparison:
4518 : : case tcc_reference:
4519 : 0 : for (i = 0; i < TREE_CODE_LENGTH (code); i++)
4520 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4521 : : break;
4522 : :
4523 : : case tcc_vl_exp:
4524 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4525 : 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4526 : : break;
4527 : :
4528 : 0 : default:
4529 : 0 : gcc_unreachable ();
4530 : : }
4531 : 0 : }
4532 : :
4533 : : /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
4534 : : return a tree with all occurrences of references to F in a
4535 : : PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
4536 : : CONST_DECLs. Note that we assume here that EXP contains only
4537 : : arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
4538 : : occurring only in their argument list. */
4539 : :
4540 : : tree
4541 : 0 : substitute_in_expr (tree exp, tree f, tree r)
4542 : : {
4543 : 0 : enum tree_code code = TREE_CODE (exp);
4544 : 0 : tree op0, op1, op2, op3;
4545 : 0 : tree new_tree;
4546 : :
4547 : : /* We handle TREE_LIST and COMPONENT_REF separately. */
4548 : 0 : if (code == TREE_LIST)
4549 : : {
4550 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
4551 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
4552 : 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4553 : : return exp;
4554 : :
4555 : 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4556 : : }
4557 : 0 : else if (code == COMPONENT_REF)
4558 : : {
4559 : 0 : tree inner;
4560 : :
4561 : : /* If this expression is getting a value from a PLACEHOLDER_EXPR
4562 : : and it is the right field, replace it with R. */
4563 : 0 : for (inner = TREE_OPERAND (exp, 0);
4564 : 0 : REFERENCE_CLASS_P (inner);
4565 : 0 : inner = TREE_OPERAND (inner, 0))
4566 : : ;
4567 : :
4568 : : /* The field. */
4569 : 0 : op1 = TREE_OPERAND (exp, 1);
4570 : :
4571 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
4572 : : return r;
4573 : :
4574 : : /* If this expression hasn't been completed let, leave it alone. */
4575 : 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
4576 : : return exp;
4577 : :
4578 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4579 : 0 : if (op0 == TREE_OPERAND (exp, 0))
4580 : : return exp;
4581 : :
4582 : 0 : new_tree
4583 : 0 : = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
4584 : : }
4585 : : else
4586 : 0 : switch (TREE_CODE_CLASS (code))
4587 : : {
4588 : : case tcc_constant:
4589 : : return exp;
4590 : :
4591 : 0 : case tcc_declaration:
4592 : 0 : if (exp == f)
4593 : : return r;
4594 : : else
4595 : : return exp;
4596 : :
4597 : 0 : case tcc_expression:
4598 : 0 : if (exp == f)
4599 : : return r;
4600 : :
4601 : : /* Fall through. */
4602 : :
4603 : 0 : case tcc_exceptional:
4604 : 0 : case tcc_unary:
4605 : 0 : case tcc_binary:
4606 : 0 : case tcc_comparison:
4607 : 0 : case tcc_reference:
4608 : 0 : switch (TREE_CODE_LENGTH (code))
4609 : : {
4610 : : case 0:
4611 : : return exp;
4612 : :
4613 : 0 : case 1:
4614 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4615 : 0 : if (op0 == TREE_OPERAND (exp, 0))
4616 : : return exp;
4617 : :
4618 : 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4619 : 0 : break;
4620 : :
4621 : 0 : case 2:
4622 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4623 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4624 : :
4625 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4626 : : return exp;
4627 : :
4628 : 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4629 : 0 : break;
4630 : :
4631 : 0 : case 3:
4632 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4633 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4634 : 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4635 : :
4636 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4637 : 0 : && op2 == TREE_OPERAND (exp, 2))
4638 : : return exp;
4639 : :
4640 : 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4641 : 0 : break;
4642 : :
4643 : 0 : case 4:
4644 : 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4645 : 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4646 : 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4647 : 0 : op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
4648 : :
4649 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4650 : 0 : && op2 == TREE_OPERAND (exp, 2)
4651 : 0 : && op3 == TREE_OPERAND (exp, 3))
4652 : : return exp;
4653 : :
4654 : 0 : new_tree
4655 : 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4656 : 0 : break;
4657 : :
4658 : 0 : default:
4659 : 0 : gcc_unreachable ();
4660 : : }
4661 : : break;
4662 : :
4663 : 0 : case tcc_vl_exp:
4664 : 0 : {
4665 : 0 : int i;
4666 : :
4667 : 0 : new_tree = NULL_TREE;
4668 : :
4669 : : /* If we are trying to replace F with a constant or with another
4670 : : instance of one of the arguments of the call, inline back
4671 : : functions which do nothing else than computing a value from
4672 : : the arguments they are passed. This makes it possible to
4673 : : fold partially or entirely the replacement expression. */
4674 : 0 : if (code == CALL_EXPR)
4675 : : {
4676 : 0 : bool maybe_inline = false;
4677 : 0 : if (CONSTANT_CLASS_P (r))
4678 : : maybe_inline = true;
4679 : : else
4680 : 0 : for (i = 3; i < TREE_OPERAND_LENGTH (exp); i++)
4681 : 0 : if (operand_equal_p (TREE_OPERAND (exp, i), r, 0))
4682 : : {
4683 : : maybe_inline = true;
4684 : : break;
4685 : : }
4686 : 0 : if (maybe_inline)
4687 : : {
4688 : 0 : tree t = maybe_inline_call_in_expr (exp);
4689 : 0 : if (t)
4690 : 0 : return SUBSTITUTE_IN_EXPR (t, f, r);
4691 : : }
4692 : : }
4693 : :
4694 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4695 : : {
4696 : 0 : tree op = TREE_OPERAND (exp, i);
4697 : 0 : tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
4698 : 0 : if (new_op != op)
4699 : : {
4700 : 0 : if (!new_tree)
4701 : 0 : new_tree = copy_node (exp);
4702 : 0 : TREE_OPERAND (new_tree, i) = new_op;
4703 : : }
4704 : : }
4705 : :
4706 : 0 : if (new_tree)
4707 : : {
4708 : 0 : new_tree = fold (new_tree);
4709 : 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4710 : 0 : process_call_operands (new_tree);
4711 : : }
4712 : : else
4713 : : return exp;
4714 : : }
4715 : : break;
4716 : :
4717 : 0 : default:
4718 : 0 : gcc_unreachable ();
4719 : : }
4720 : :
4721 : 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4722 : :
4723 : 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4724 : 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4725 : :
4726 : : return new_tree;
4727 : : }
4728 : :
4729 : : /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
4730 : : for it within OBJ, a tree that is an object or a chain of references. */
4731 : :
4732 : : tree
4733 : 210337 : substitute_placeholder_in_expr (tree exp, tree obj)
4734 : : {
4735 : 210337 : enum tree_code code = TREE_CODE (exp);
4736 : 210337 : tree op0, op1, op2, op3;
4737 : 210337 : tree new_tree;
4738 : :
4739 : : /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
4740 : : in the chain of OBJ. */
4741 : 210337 : if (code == PLACEHOLDER_EXPR)
4742 : : {
4743 : 0 : tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
4744 : 0 : tree elt;
4745 : :
4746 : 0 : for (elt = obj; elt != 0;
4747 : 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4748 : 0 : || TREE_CODE (elt) == COND_EXPR)
4749 : 0 : ? TREE_OPERAND (elt, 1)
4750 : 0 : : (REFERENCE_CLASS_P (elt)
4751 : : || UNARY_CLASS_P (elt)
4752 : : || BINARY_CLASS_P (elt)
4753 : : || VL_EXP_CLASS_P (elt)
4754 : : || EXPRESSION_CLASS_P (elt))
4755 : 0 : ? TREE_OPERAND (elt, 0) : 0))
4756 : 0 : if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
4757 : : return elt;
4758 : :
4759 : 0 : for (elt = obj; elt != 0;
4760 : 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4761 : 0 : || TREE_CODE (elt) == COND_EXPR)
4762 : 0 : ? TREE_OPERAND (elt, 1)
4763 : 0 : : (REFERENCE_CLASS_P (elt)
4764 : : || UNARY_CLASS_P (elt)
4765 : : || BINARY_CLASS_P (elt)
4766 : : || VL_EXP_CLASS_P (elt)
4767 : : || EXPRESSION_CLASS_P (elt))
4768 : 0 : ? TREE_OPERAND (elt, 0) : 0))
4769 : 0 : if (POINTER_TYPE_P (TREE_TYPE (elt))
4770 : 0 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
4771 : : == need_type))
4772 : 0 : return fold_build1 (INDIRECT_REF, need_type, elt);
4773 : :
4774 : : /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
4775 : : survives until RTL generation, there will be an error. */
4776 : : return exp;
4777 : : }
4778 : :
4779 : : /* TREE_LIST is special because we need to look at TREE_VALUE
4780 : : and TREE_CHAIN, not TREE_OPERANDS. */
4781 : 210337 : else if (code == TREE_LIST)
4782 : : {
4783 : 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
4784 : 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
4785 : 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4786 : : return exp;
4787 : :
4788 : 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4789 : : }
4790 : : else
4791 : 210337 : switch (TREE_CODE_CLASS (code))
4792 : : {
4793 : : case tcc_constant:
4794 : : case tcc_declaration:
4795 : : return exp;
4796 : :
4797 : 9437 : case tcc_exceptional:
4798 : 9437 : case tcc_unary:
4799 : 9437 : case tcc_binary:
4800 : 9437 : case tcc_comparison:
4801 : 9437 : case tcc_expression:
4802 : 9437 : case tcc_reference:
4803 : 9437 : case tcc_statement:
4804 : 9437 : switch (TREE_CODE_LENGTH (code))
4805 : : {
4806 : : case 0:
4807 : : return exp;
4808 : :
4809 : 7185 : case 1:
4810 : 7185 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4811 : 7185 : if (op0 == TREE_OPERAND (exp, 0))
4812 : : return exp;
4813 : :
4814 : 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4815 : 0 : break;
4816 : :
4817 : 2240 : case 2:
4818 : 2240 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4819 : 2240 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4820 : :
4821 : 2240 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4822 : : return exp;
4823 : :
4824 : 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4825 : 0 : break;
4826 : :
4827 : 12 : case 3:
4828 : 12 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4829 : 12 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4830 : 12 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4831 : :
4832 : 24 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4833 : 24 : && op2 == TREE_OPERAND (exp, 2))
4834 : : return exp;
4835 : :
4836 : 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4837 : 0 : break;
4838 : :
4839 : 0 : case 4:
4840 : 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4841 : 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4842 : 0 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4843 : 0 : op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
4844 : :
4845 : 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4846 : 0 : && op2 == TREE_OPERAND (exp, 2)
4847 : 0 : && op3 == TREE_OPERAND (exp, 3))
4848 : : return exp;
4849 : :
4850 : 0 : new_tree
4851 : 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4852 : 0 : break;
4853 : :
4854 : 0 : default:
4855 : 0 : gcc_unreachable ();
4856 : : }
4857 : : break;
4858 : :
4859 : : case tcc_vl_exp:
4860 : : {
4861 : : int i;
4862 : :
4863 : : new_tree = NULL_TREE;
4864 : :
4865 : 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4866 : : {
4867 : 0 : tree op = TREE_OPERAND (exp, i);
4868 : 0 : tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
4869 : 0 : if (new_op != op)
4870 : : {
4871 : 0 : if (!new_tree)
4872 : 0 : new_tree = copy_node (exp);
4873 : 0 : TREE_OPERAND (new_tree, i) = new_op;
4874 : : }
4875 : : }
4876 : :
4877 : 0 : if (new_tree)
4878 : : {
4879 : 0 : new_tree = fold (new_tree);
4880 : 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4881 : 0 : process_call_operands (new_tree);
4882 : : }
4883 : : else
4884 : : return exp;
4885 : : }
4886 : : break;
4887 : :
4888 : 0 : default:
4889 : 0 : gcc_unreachable ();
4890 : : }
4891 : :
4892 : 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4893 : :
4894 : 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4895 : 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4896 : :
4897 : : return new_tree;
4898 : : }
4899 : :
4900 : :
4901 : : /* Subroutine of stabilize_reference; this is called for subtrees of
4902 : : references. Any expression with side-effects must be put in a SAVE_EXPR
4903 : : to ensure that it is only evaluated once.
4904 : :
4905 : : We don't put SAVE_EXPR nodes around everything, because assigning very
4906 : : simple expressions to temporaries causes us to miss good opportunities
4907 : : for optimizations. Among other things, the opportunity to fold in the
4908 : : addition of a constant into an addressing mode often gets lost, e.g.
4909 : : "y[i+1] += x;". In general, we take the approach that we should not make
4910 : : an assignment unless we are forced into it - i.e., that any non-side effect
4911 : : operator should be allowed, and that cse should take care of coalescing
4912 : : multiple utterances of the same expression should that prove fruitful. */
4913 : :
4914 : : static tree
4915 : 547528 : stabilize_reference_1 (tree e)
4916 : : {
4917 : 547528 : tree result;
4918 : 547528 : enum tree_code code = TREE_CODE (e);
4919 : :
4920 : : /* We cannot ignore const expressions because it might be a reference
4921 : : to a const array but whose index contains side-effects. But we can
4922 : : ignore things that are actual constant or that already have been
4923 : : handled by this function. */
4924 : :
4925 : 547528 : if (tree_invariant_p (e))
4926 : : return e;
4927 : :
4928 : 146742 : switch (TREE_CODE_CLASS (code))
4929 : : {
4930 : 0 : case tcc_exceptional:
4931 : : /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
4932 : : have side-effects. */
4933 : 0 : if (code == STATEMENT_LIST)
4934 : 0 : return save_expr (e);
4935 : : /* FALLTHRU */
4936 : 118491 : case tcc_type:
4937 : 118491 : case tcc_declaration:
4938 : 118491 : case tcc_comparison:
4939 : 118491 : case tcc_statement:
4940 : 118491 : case tcc_expression:
4941 : 118491 : case tcc_reference:
4942 : 118491 : case tcc_vl_exp:
4943 : : /* If the expression has side-effects, then encase it in a SAVE_EXPR
4944 : : so that it will only be evaluated once. */
4945 : : /* The reference (r) and comparison (<) classes could be handled as
4946 : : below, but it is generally faster to only evaluate them once. */
4947 : 118491 : if (TREE_SIDE_EFFECTS (e))
4948 : 975 : return save_expr (e);
4949 : : return e;
4950 : :
4951 : : case tcc_constant:
4952 : : /* Constants need no processing. In fact, we should never reach
4953 : : here. */
4954 : : return e;
4955 : :
4956 : 21186 : case tcc_binary:
4957 : : /* Division is slow and tends to be compiled with jumps,
4958 : : especially the division by powers of 2 that is often
4959 : : found inside of an array reference. So do it just once. */
4960 : 21186 : if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
4961 : 19146 : || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
4962 : 19146 : || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
4963 : 19146 : || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
4964 : 2040 : return save_expr (e);
4965 : : /* Recursively stabilize each operand. */
4966 : 19146 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
4967 : 19146 : stabilize_reference_1 (TREE_OPERAND (e, 1)));
4968 : 19146 : break;
4969 : :
4970 : 7065 : case tcc_unary:
4971 : : /* Recursively stabilize each operand. */
4972 : 7065 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
4973 : 7065 : break;
4974 : :
4975 : 0 : default:
4976 : 0 : gcc_unreachable ();
4977 : : }
4978 : :
4979 : 26211 : TREE_TYPE (result) = TREE_TYPE (e);
4980 : 26211 : TREE_READONLY (result) = TREE_READONLY (e);
4981 : 26211 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
4982 : 26211 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
4983 : :
4984 : 26211 : return result;
4985 : : }
4986 : :
4987 : : /* Stabilize a reference so that we can use it any number of times
4988 : : without causing its operands to be evaluated more than once.
4989 : : Returns the stabilized reference. This works by means of save_expr,
4990 : : so see the caveats in the comments about save_expr.
4991 : :
4992 : : Also allows conversion expressions whose operands are references.
4993 : : Any other kind of expression is returned unchanged. */
4994 : :
4995 : : tree
4996 : 4032118 : stabilize_reference (tree ref)
4997 : : {
4998 : 4032118 : tree result;
4999 : 4032118 : enum tree_code code = TREE_CODE (ref);
5000 : :
5001 : 4032118 : switch (code)
5002 : : {
5003 : : case VAR_DECL:
5004 : : case PARM_DECL:
5005 : : case RESULT_DECL:
5006 : : /* No action is needed in this case. */
5007 : : return ref;
5008 : :
5009 : 0 : CASE_CONVERT:
5010 : 0 : case FLOAT_EXPR:
5011 : 0 : case FIX_TRUNC_EXPR:
5012 : 0 : result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
5013 : 0 : break;
5014 : :
5015 : 456016 : case INDIRECT_REF:
5016 : 456016 : result = build_nt (INDIRECT_REF,
5017 : 456016 : stabilize_reference_1 (TREE_OPERAND (ref, 0)));
5018 : 456016 : break;
5019 : :
5020 : 308150 : case COMPONENT_REF:
5021 : 308150 : result = build_nt (COMPONENT_REF,
5022 : 308150 : stabilize_reference (TREE_OPERAND (ref, 0)),
5023 : 308150 : TREE_OPERAND (ref, 1), NULL_TREE);
5024 : 308150 : break;
5025 : :
5026 : 0 : case BIT_FIELD_REF:
5027 : 0 : result = build_nt (BIT_FIELD_REF,
5028 : 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5029 : 0 : TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2));
5030 : 0 : REF_REVERSE_STORAGE_ORDER (result) = REF_REVERSE_STORAGE_ORDER (ref);
5031 : 0 : break;
5032 : :
5033 : 46155 : case ARRAY_REF:
5034 : 92310 : result = build_nt (ARRAY_REF,
5035 : 46155 : stabilize_reference (TREE_OPERAND (ref, 0)),
5036 : 46155 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5037 : 46155 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5038 : 46155 : break;
5039 : :
5040 : 0 : case ARRAY_RANGE_REF:
5041 : 0 : result = build_nt (ARRAY_RANGE_REF,
5042 : 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5043 : 0 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5044 : 0 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5045 : 0 : break;
5046 : :
5047 : 0 : case COMPOUND_EXPR:
5048 : : /* We cannot wrap the first expression in a SAVE_EXPR, as then
5049 : : it wouldn't be ignored. This matters when dealing with
5050 : : volatiles. */
5051 : 0 : return stabilize_reference_1 (ref);
5052 : :
5053 : : /* If arg isn't a kind of lvalue we recognize, make no change.
5054 : : Caller should recognize the error for an invalid lvalue. */
5055 : : default:
5056 : : return ref;
5057 : :
5058 : 0 : case ERROR_MARK:
5059 : 0 : return error_mark_node;
5060 : : }
5061 : :
5062 : 810321 : TREE_TYPE (result) = TREE_TYPE (ref);
5063 : 810321 : TREE_READONLY (result) = TREE_READONLY (ref);
5064 : 810321 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
5065 : 810321 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
5066 : 810321 : protected_set_expr_location (result, EXPR_LOCATION (ref));
5067 : :
5068 : 810321 : return result;
5069 : : }
5070 : :
5071 : : /* Low-level constructors for expressions. */
5072 : :
5073 : : /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
5074 : : and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
5075 : :
5076 : : void
5077 : 1231044949 : recompute_tree_invariant_for_addr_expr (tree t)
5078 : : {
5079 : 1231044949 : tree node;
5080 : 1231044949 : bool tc = true, se = false;
5081 : :
5082 : 1231044949 : gcc_assert (TREE_CODE (t) == ADDR_EXPR);
5083 : :
5084 : : /* We started out assuming this address is both invariant and constant, but
5085 : : does not have side effects. Now go down any handled components and see if
5086 : : any of them involve offsets that are either non-constant or non-invariant.
5087 : : Also check for side-effects.
5088 : :
5089 : : ??? Note that this code makes no attempt to deal with the case where
5090 : : taking the address of something causes a copy due to misalignment. */
5091 : :
5092 : : #define UPDATE_FLAGS(NODE) \
5093 : : do { tree _node = (NODE); \
5094 : : if (_node && !TREE_CONSTANT (_node)) tc = false; \
5095 : : if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
5096 : :
5097 : 1431689894 : for (node = TREE_OPERAND (t, 0); handled_component_p (node);
5098 : 200644945 : node = TREE_OPERAND (node, 0))
5099 : : {
5100 : : /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
5101 : : array reference (probably made temporarily by the G++ front end),
5102 : : so ignore all the operands. */
5103 : 200644945 : if ((TREE_CODE (node) == ARRAY_REF
5104 : 200644945 : || TREE_CODE (node) == ARRAY_RANGE_REF)
5105 : 200644945 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
5106 : : {
5107 : 29872162 : UPDATE_FLAGS (TREE_OPERAND (node, 1));
5108 : 29872162 : if (TREE_OPERAND (node, 2))
5109 : 2015108 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5110 : 29872162 : if (TREE_OPERAND (node, 3))
5111 : 265811 : UPDATE_FLAGS (TREE_OPERAND (node, 3));
5112 : : }
5113 : : /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
5114 : : FIELD_DECL, apparently. The G++ front end can put something else
5115 : : there, at least temporarily. */
5116 : 170772783 : else if (TREE_CODE (node) == COMPONENT_REF
5117 : 170772783 : && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
5118 : : {
5119 : 169959916 : if (TREE_OPERAND (node, 2))
5120 : 16542 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5121 : : }
5122 : : }
5123 : :
5124 : 1231044949 : node = lang_hooks.expr_to_decl (node, &tc, &se);
5125 : :
5126 : : /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
5127 : : the address, since &(*a)->b is a form of addition. If it's a constant, the
5128 : : address is constant too. If it's a decl, its address is constant if the
5129 : : decl is static. Everything else is not constant and, furthermore,
5130 : : taking the address of a volatile variable is not volatile. */
5131 : 1231044949 : if (INDIRECT_REF_P (node)
5132 : 1200775192 : || TREE_CODE (node) == MEM_REF)
5133 : 142863286 : UPDATE_FLAGS (TREE_OPERAND (node, 0));
5134 : 1088181663 : else if (CONSTANT_CLASS_P (node))
5135 : : ;
5136 : 1017345286 : else if (DECL_P (node))
5137 : 1002163069 : tc &= (staticp (node) != NULL_TREE);
5138 : : else
5139 : : {
5140 : 15182217 : tc = false;
5141 : 15182217 : se |= TREE_SIDE_EFFECTS (node);
5142 : : }
5143 : :
5144 : :
5145 : 1231044949 : TREE_CONSTANT (t) = tc;
5146 : 1231044949 : TREE_SIDE_EFFECTS (t) = se;
5147 : : #undef UPDATE_FLAGS
5148 : 1231044949 : }
5149 : :
5150 : : /* Build an expression of code CODE, data type TYPE, and operands as
5151 : : specified. Expressions and reference nodes can be created this way.
5152 : : Constants, decls, types and misc nodes cannot be.
5153 : :
5154 : : We define 5 non-variadic functions, from 0 to 4 arguments. This is
5155 : : enough for all extant tree codes. */
5156 : :
5157 : : tree
5158 : 322657724 : build0 (enum tree_code code, tree tt MEM_STAT_DECL)
5159 : : {
5160 : 322657724 : tree t;
5161 : :
5162 : 322657724 : gcc_assert (TREE_CODE_LENGTH (code) == 0);
5163 : :
5164 : 322657724 : t = make_node (code PASS_MEM_STAT);
5165 : 322657724 : TREE_TYPE (t) = tt;
5166 : :
5167 : 322657724 : return t;
5168 : : }
5169 : :
5170 : : tree
5171 : 3111162621 : build1 (enum tree_code code, tree type, tree node MEM_STAT_DECL)
5172 : : {
5173 : 3111162621 : int length = sizeof (struct tree_exp);
5174 : 3111162621 : tree t;
5175 : :
5176 : 3111162621 : record_node_allocation_statistics (code, length);
5177 : :
5178 : 3111162621 : gcc_assert (TREE_CODE_LENGTH (code) == 1);
5179 : :
5180 : 3111162621 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
5181 : :
5182 : 3111162621 : memset (t, 0, sizeof (struct tree_common));
5183 : :
5184 : 3111162621 : TREE_SET_CODE (t, code);
5185 : :
5186 : 3111162621 : TREE_TYPE (t) = type;
5187 : 3111162621 : SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
5188 : 3111162621 : TREE_OPERAND (t, 0) = node;
5189 : 3111162621 : if (node && !TYPE_P (node))
5190 : : {
5191 : 3111147599 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
5192 : 3111147599 : TREE_READONLY (t) = TREE_READONLY (node);
5193 : : }
5194 : :
5195 : 3111162621 : if (TREE_CODE_CLASS (code) == tcc_statement)
5196 : : {
5197 : 21819165 : if (code != DEBUG_BEGIN_STMT)
5198 : 21819165 : TREE_SIDE_EFFECTS (t) = 1;
5199 : : }
5200 : 3089343456 : else switch (code)
5201 : : {
5202 : 50794 : case VA_ARG_EXPR:
5203 : : /* All of these have side-effects, no matter what their
5204 : : operands are. */
5205 : 50794 : TREE_SIDE_EFFECTS (t) = 1;
5206 : 50794 : TREE_READONLY (t) = 0;
5207 : 50794 : break;
5208 : :
5209 : 491290659 : case INDIRECT_REF:
5210 : : /* Whether a dereference is readonly has nothing to do with whether
5211 : : its operand is readonly. */
5212 : 491290659 : TREE_READONLY (t) = 0;
5213 : 491290659 : break;
5214 : :
5215 : 503475530 : case ADDR_EXPR:
5216 : 503475530 : if (node)
5217 : 503475530 : recompute_tree_invariant_for_addr_expr (t);
5218 : : break;
5219 : :
5220 : 2094526473 : default:
5221 : 824777954 : if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
5222 : 1979728486 : && node && !TYPE_P (node)
5223 : 4074254959 : && TREE_CONSTANT (node))
5224 : 500453610 : TREE_CONSTANT (t) = 1;
5225 : 2094526473 : if (TREE_CODE_CLASS (code) == tcc_reference
5226 : 712412819 : && node && TREE_THIS_VOLATILE (node))
5227 : 2336325 : TREE_THIS_VOLATILE (t) = 1;
5228 : : break;
5229 : : }
5230 : :
5231 : 3111162621 : return t;
5232 : : }
5233 : :
5234 : : #define PROCESS_ARG(N) \
5235 : : do { \
5236 : : TREE_OPERAND (t, N) = arg##N; \
5237 : : if (arg##N &&!TYPE_P (arg##N)) \
5238 : : { \
5239 : : if (TREE_SIDE_EFFECTS (arg##N)) \
5240 : : side_effects = 1; \
5241 : : if (!TREE_READONLY (arg##N) \
5242 : : && !CONSTANT_CLASS_P (arg##N)) \
5243 : : (void) (read_only = 0); \
5244 : : if (!TREE_CONSTANT (arg##N)) \
5245 : : (void) (constant = 0); \
5246 : : } \
5247 : : } while (0)
5248 : :
5249 : : tree
5250 : 1044302979 : build2 (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
5251 : : {
5252 : 1044302979 : bool constant, read_only, side_effects, div_by_zero;
5253 : 1044302979 : tree t;
5254 : :
5255 : 1044302979 : gcc_assert (TREE_CODE_LENGTH (code) == 2);
5256 : :
5257 : 1044302979 : if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
5258 : 179657115 : && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
5259 : : /* When sizetype precision doesn't match that of pointers
5260 : : we need to be able to build explicit extensions or truncations
5261 : : of the offset argument. */
5262 : 1044302979 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
5263 : 0 : gcc_assert (TREE_CODE (arg0) == INTEGER_CST
5264 : : && TREE_CODE (arg1) == INTEGER_CST);
5265 : :
5266 : 1044302979 : if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
5267 : 23217413 : gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
5268 : : && ptrofftype_p (TREE_TYPE (arg1)));
5269 : :
5270 : 1044302979 : t = make_node (code PASS_MEM_STAT);
5271 : 1044302979 : TREE_TYPE (t) = tt;
5272 : :
5273 : : /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
5274 : : result based on those same flags for the arguments. But if the
5275 : : arguments aren't really even `tree' expressions, we shouldn't be trying
5276 : : to do this. */
5277 : :
5278 : : /* Expressions without side effects may be constant if their
5279 : : arguments are as well. */
5280 : 2088605958 : constant = (TREE_CODE_CLASS (code) == tcc_comparison
5281 : 1044302979 : || TREE_CODE_CLASS (code) == tcc_binary);
5282 : 1044302979 : read_only = 1;
5283 : 1044302979 : side_effects = TREE_SIDE_EFFECTS (t);
5284 : :
5285 : 1044302979 : switch (code)
5286 : : {
5287 : 9819615 : case TRUNC_DIV_EXPR:
5288 : 9819615 : case CEIL_DIV_EXPR:
5289 : 9819615 : case FLOOR_DIV_EXPR:
5290 : 9819615 : case ROUND_DIV_EXPR:
5291 : 9819615 : case EXACT_DIV_EXPR:
5292 : 9819615 : case CEIL_MOD_EXPR:
5293 : 9819615 : case FLOOR_MOD_EXPR:
5294 : 9819615 : case ROUND_MOD_EXPR:
5295 : 9819615 : case TRUNC_MOD_EXPR:
5296 : 9819615 : div_by_zero = integer_zerop (arg1);
5297 : 9819615 : break;
5298 : : default:
5299 : : div_by_zero = false;
5300 : : }
5301 : :
5302 : 1136223209 : PROCESS_ARG (0);
5303 : 1469988059 : PROCESS_ARG (1);
5304 : :
5305 : 1044302979 : TREE_SIDE_EFFECTS (t) = side_effects;
5306 : 1044302979 : if (code == MEM_REF)
5307 : : {
5308 : 68499109 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5309 : : {
5310 : 14570382 : tree o = TREE_OPERAND (arg0, 0);
5311 : 14570382 : TREE_READONLY (t) = TREE_READONLY (o);
5312 : 14570382 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5313 : : }
5314 : : }
5315 : : else
5316 : : {
5317 : 975803870 : TREE_READONLY (t) = read_only;
5318 : : /* Don't mark X / 0 as constant. */
5319 : 975803870 : TREE_CONSTANT (t) = constant && !div_by_zero;
5320 : 975803870 : TREE_THIS_VOLATILE (t)
5321 : 975803870 : = (TREE_CODE_CLASS (code) == tcc_reference
5322 : 975803870 : && arg0 && TREE_THIS_VOLATILE (arg0));
5323 : : }
5324 : :
5325 : 1044302979 : return t;
5326 : : }
5327 : :
5328 : :
5329 : : tree
5330 : 385215722 : build3 (enum tree_code code, tree tt, tree arg0, tree arg1,
5331 : : tree arg2 MEM_STAT_DECL)
5332 : : {
5333 : 385215722 : bool constant, read_only, side_effects;
5334 : 385215722 : tree t;
5335 : :
5336 : 385215722 : gcc_assert (TREE_CODE_LENGTH (code) == 3);
5337 : 385215722 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5338 : :
5339 : 385215722 : t = make_node (code PASS_MEM_STAT);
5340 : 385215722 : TREE_TYPE (t) = tt;
5341 : :
5342 : 385215722 : read_only = 1;
5343 : :
5344 : : /* As a special exception, if COND_EXPR has NULL branches, we
5345 : : assume that it is a gimple statement and always consider
5346 : : it to have side effects. */
5347 : 385215722 : if (code == COND_EXPR
5348 : 31745399 : && tt == void_type_node
5349 : 21191777 : && arg1 == NULL_TREE
5350 : 21191777 : && arg2 == NULL_TREE)
5351 : : side_effects = true;
5352 : : else
5353 : 385215722 : side_effects = TREE_SIDE_EFFECTS (t);
5354 : :
5355 : 419554239 : PROCESS_ARG (0);
5356 : 395426122 : PROCESS_ARG (1);
5357 : 395255731 : PROCESS_ARG (2);
5358 : :
5359 : 385215722 : if (code == COND_EXPR)
5360 : 31745399 : TREE_READONLY (t) = read_only;
5361 : :
5362 : 385215722 : TREE_SIDE_EFFECTS (t) = side_effects;
5363 : 385215722 : TREE_THIS_VOLATILE (t)
5364 : 385215722 : = (TREE_CODE_CLASS (code) == tcc_reference
5365 : 385215722 : && arg0 && TREE_THIS_VOLATILE (arg0));
5366 : :
5367 : 385215722 : return t;
5368 : : }
5369 : :
5370 : : tree
5371 : 36180005 : build4 (enum tree_code code, tree tt, tree arg0, tree arg1,
5372 : : tree arg2, tree arg3 MEM_STAT_DECL)
5373 : : {
5374 : 36180005 : bool constant, read_only, side_effects;
5375 : 36180005 : tree t;
5376 : :
5377 : 36180005 : gcc_assert (TREE_CODE_LENGTH (code) == 4);
5378 : :
5379 : 36180005 : t = make_node (code PASS_MEM_STAT);
5380 : 36180005 : TREE_TYPE (t) = tt;
5381 : :
5382 : 36180005 : side_effects = TREE_SIDE_EFFECTS (t);
5383 : :
5384 : 36180005 : PROCESS_ARG (0);
5385 : 36180005 : PROCESS_ARG (1);
5386 : 36180005 : PROCESS_ARG (2);
5387 : 36180005 : PROCESS_ARG (3);
5388 : :
5389 : 36180005 : TREE_SIDE_EFFECTS (t) = side_effects;
5390 : 36180005 : TREE_THIS_VOLATILE (t)
5391 : 72360010 : = (TREE_CODE_CLASS (code) == tcc_reference
5392 : 36180005 : && arg0 && TREE_THIS_VOLATILE (arg0));
5393 : :
5394 : 36180005 : return t;
5395 : : }
5396 : :
5397 : : tree
5398 : 1149253 : build5 (enum tree_code code, tree tt, tree arg0, tree arg1,
5399 : : tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
5400 : : {
5401 : 1149253 : bool constant, read_only, side_effects;
5402 : 1149253 : tree t;
5403 : :
5404 : 1149253 : gcc_assert (TREE_CODE_LENGTH (code) == 5);
5405 : :
5406 : 1149253 : t = make_node (code PASS_MEM_STAT);
5407 : 1149253 : TREE_TYPE (t) = tt;
5408 : :
5409 : 1149253 : side_effects = TREE_SIDE_EFFECTS (t);
5410 : :
5411 : 1149253 : PROCESS_ARG (0);
5412 : 1149253 : PROCESS_ARG (1);
5413 : 1149253 : PROCESS_ARG (2);
5414 : 1149253 : PROCESS_ARG (3);
5415 : 1149253 : PROCESS_ARG (4);
5416 : :
5417 : 1149253 : TREE_SIDE_EFFECTS (t) = side_effects;
5418 : 1149253 : if (code == TARGET_MEM_REF)
5419 : : {
5420 : 1142568 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5421 : : {
5422 : 194921 : tree o = TREE_OPERAND (arg0, 0);
5423 : 194921 : TREE_READONLY (t) = TREE_READONLY (o);
5424 : 194921 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5425 : : }
5426 : : }
5427 : : else
5428 : 6685 : TREE_THIS_VOLATILE (t)
5429 : 6685 : = (TREE_CODE_CLASS (code) == tcc_reference
5430 : 6685 : && arg0 && TREE_THIS_VOLATILE (arg0));
5431 : :
5432 : 1149253 : return t;
5433 : : }
5434 : :
5435 : : /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
5436 : : on the pointer PTR. */
5437 : :
5438 : : tree
5439 : 481660 : build_simple_mem_ref_loc (location_t loc, tree ptr)
5440 : : {
5441 : 481660 : poly_int64 offset = 0;
5442 : 481660 : tree ptype = TREE_TYPE (ptr);
5443 : 481660 : tree tem;
5444 : : /* For convenience allow addresses that collapse to a simple base
5445 : : and offset. */
5446 : 481660 : if (TREE_CODE (ptr) == ADDR_EXPR
5447 : 481660 : && (handled_component_p (TREE_OPERAND (ptr, 0))
5448 : 15406 : || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
5449 : : {
5450 : 187 : ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
5451 : 187 : gcc_assert (ptr);
5452 : 187 : if (TREE_CODE (ptr) == MEM_REF)
5453 : : {
5454 : 77 : offset += mem_ref_offset (ptr).force_shwi ();
5455 : 77 : ptr = TREE_OPERAND (ptr, 0);
5456 : : }
5457 : : else
5458 : 110 : ptr = build_fold_addr_expr (ptr);
5459 : 187 : gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
5460 : : }
5461 : 481660 : tem = build2 (MEM_REF, TREE_TYPE (ptype),
5462 : : ptr, build_int_cst (ptype, offset));
5463 : 481660 : SET_EXPR_LOCATION (tem, loc);
5464 : 481660 : return tem;
5465 : : }
5466 : :
5467 : : /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
5468 : :
5469 : : poly_offset_int
5470 : 1165138825 : mem_ref_offset (const_tree t)
5471 : : {
5472 : 1165138825 : return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
5473 : 1165138825 : SIGNED);
5474 : : }
5475 : :
5476 : : /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
5477 : : offsetted by OFFSET units. */
5478 : :
5479 : : tree
5480 : 189018 : build_invariant_address (tree type, tree base, poly_int64 offset)
5481 : : {
5482 : 189018 : tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
5483 : : build_fold_addr_expr (base),
5484 : : build_int_cst (ptr_type_node, offset));
5485 : 189018 : tree addr = build1 (ADDR_EXPR, type, ref);
5486 : 189018 : recompute_tree_invariant_for_addr_expr (addr);
5487 : 189018 : return addr;
5488 : : }
5489 : :
5490 : : /* Similar except don't specify the TREE_TYPE
5491 : : and leave the TREE_SIDE_EFFECTS as 0.
5492 : : It is permissible for arguments to be null,
5493 : : or even garbage if their values do not matter. */
5494 : :
5495 : : tree
5496 : 1962638 : build_nt (enum tree_code code, ...)
5497 : : {
5498 : 1962638 : tree t;
5499 : 1962638 : int length;
5500 : 1962638 : int i;
5501 : 1962638 : va_list p;
5502 : :
5503 : 1962638 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5504 : :
5505 : 1962638 : va_start (p, code);
5506 : :
5507 : 1962638 : t = make_node (code);
5508 : 1962638 : length = TREE_CODE_LENGTH (code);
5509 : :
5510 : 5530372 : for (i = 0; i < length; i++)
5511 : 3567734 : TREE_OPERAND (t, i) = va_arg (p, tree);
5512 : :
5513 : 1962638 : va_end (p);
5514 : 1962638 : return t;
5515 : : }
5516 : :
5517 : : /* Similar to build_nt, but for creating a CALL_EXPR object with a
5518 : : tree vec. */
5519 : :
5520 : : tree
5521 : 0 : build_nt_call_vec (tree fn, vec<tree, va_gc> *args)
5522 : : {
5523 : 0 : tree ret, t;
5524 : 0 : unsigned int ix;
5525 : :
5526 : 0 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
5527 : 0 : CALL_EXPR_FN (ret) = fn;
5528 : 0 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
5529 : 0 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
5530 : 0 : CALL_EXPR_ARG (ret, ix) = t;
5531 : 0 : return ret;
5532 : : }
5533 : :
5534 : : /* Create a DECL_... node of code CODE, name NAME (if non-null)
5535 : : and data type TYPE.
5536 : : We do NOT enter this node in any sort of symbol table.
5537 : :
5538 : : LOC is the location of the decl.
5539 : :
5540 : : layout_decl is used to set up the decl's storage layout.
5541 : : Other slots are initialized to 0 or null pointers. */
5542 : :
5543 : : tree
5544 : 2850292832 : build_decl (location_t loc, enum tree_code code, tree name,
5545 : : tree type MEM_STAT_DECL)
5546 : : {
5547 : 2850292832 : tree t;
5548 : :
5549 : 2850292832 : t = make_node (code PASS_MEM_STAT);
5550 : 2850292832 : DECL_SOURCE_LOCATION (t) = loc;
5551 : :
5552 : : /* if (type == error_mark_node)
5553 : : type = integer_type_node; */
5554 : : /* That is not done, deliberately, so that having error_mark_node
5555 : : as the type can suppress useless errors in the use of this variable. */
5556 : :
5557 : 2850292832 : DECL_NAME (t) = name;
5558 : 2850292832 : TREE_TYPE (t) = type;
5559 : :
5560 : 2850292832 : if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
5561 : 1000814140 : layout_decl (t, 0);
5562 : :
5563 : 2850292832 : return t;
5564 : : }
5565 : :
5566 : : /* Create and return a DEBUG_EXPR_DECL node of the given TYPE. */
5567 : :
5568 : : tree
5569 : 1589947 : build_debug_expr_decl (tree type)
5570 : : {
5571 : 1589947 : tree vexpr = make_node (DEBUG_EXPR_DECL);
5572 : 1589947 : DECL_ARTIFICIAL (vexpr) = 1;
5573 : 1589947 : TREE_TYPE (vexpr) = type;
5574 : 1589947 : SET_DECL_MODE (vexpr, TYPE_MODE (type));
5575 : 1589947 : return vexpr;
5576 : : }
5577 : :
5578 : : /* Builds and returns function declaration with NAME and TYPE. */
5579 : :
5580 : : tree
5581 : 19033 : build_fn_decl (const char *name, tree type)
5582 : : {
5583 : 19033 : tree id = get_identifier (name);
5584 : 19033 : tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
5585 : :
5586 : 19033 : DECL_EXTERNAL (decl) = 1;
5587 : 19033 : TREE_PUBLIC (decl) = 1;
5588 : 19033 : DECL_ARTIFICIAL (decl) = 1;
5589 : 19033 : TREE_NOTHROW (decl) = 1;
5590 : :
5591 : 19033 : return decl;
5592 : : }
5593 : :
5594 : : vec<tree, va_gc> *all_translation_units;
5595 : :
5596 : : /* Builds a new translation-unit decl with name NAME, queues it in the
5597 : : global list of translation-unit decls and returns it. */
5598 : :
5599 : : tree
5600 : 248982 : build_translation_unit_decl (tree name)
5601 : : {
5602 : 248982 : tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
5603 : 248982 : name, NULL_TREE);
5604 : 248982 : TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
5605 : 248982 : vec_safe_push (all_translation_units, tu);
5606 : 248982 : return tu;
5607 : : }
5608 : :
5609 : :
5610 : : /* BLOCK nodes are used to represent the structure of binding contours
5611 : : and declarations, once those contours have been exited and their contents
5612 : : compiled. This information is used for outputting debugging info. */
5613 : :
5614 : : tree
5615 : 692712 : build_block (tree vars, tree subblocks, tree supercontext, tree chain)
5616 : : {
5617 : 692712 : tree block = make_node (BLOCK);
5618 : :
5619 : 692712 : BLOCK_VARS (block) = vars;
5620 : 692712 : BLOCK_SUBBLOCKS (block) = subblocks;
5621 : 692712 : BLOCK_SUPERCONTEXT (block) = supercontext;
5622 : 692712 : BLOCK_CHAIN (block) = chain;
5623 : 692712 : return block;
5624 : : }
5625 : :
5626 : :
5627 : : /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
5628 : :
5629 : : LOC is the location to use in tree T. */
5630 : :
5631 : : void
5632 : 11954899798 : protected_set_expr_location (tree t, location_t loc)
5633 : : {
5634 : 11954899798 : if (CAN_HAVE_LOCATION_P (t))
5635 : 1906238304 : SET_EXPR_LOCATION (t, loc);
5636 : 9987320192 : else if (t && TREE_CODE (t) == STATEMENT_LIST)
5637 : : {
5638 : 22243 : t = expr_single (t);
5639 : 22243 : if (t && CAN_HAVE_LOCATION_P (t))
5640 : 18 : SET_EXPR_LOCATION (t, loc);
5641 : : }
5642 : 11954899798 : }
5643 : :
5644 : : /* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has
5645 : : UNKNOWN_LOCATION. */
5646 : :
5647 : : void
5648 : 20858070 : protected_set_expr_location_if_unset (tree t, location_t loc)
5649 : : {
5650 : 20858070 : t = expr_single (t);
5651 : 20858070 : if (t && !EXPR_HAS_LOCATION (t))
5652 : 15619333 : protected_set_expr_location (t, loc);
5653 : 20858070 : }
5654 : :
5655 : : /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5656 : : of the various TYPE_QUAL values. */
5657 : :
5658 : : static void
5659 : 89108213 : set_type_quals (tree type, int type_quals)
5660 : : {
5661 : 89108213 : TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
5662 : 89108213 : TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
5663 : 89108213 : TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
5664 : 89108213 : TYPE_ATOMIC (type) = (type_quals & TYPE_QUAL_ATOMIC) != 0;
5665 : 89108213 : TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
5666 : 89108213 : }
5667 : :
5668 : : /* Returns true iff CAND and BASE have equivalent language-specific
5669 : : qualifiers. */
5670 : :
5671 : : bool
5672 : 2306813623 : check_lang_type (const_tree cand, const_tree base)
5673 : : {
5674 : 2306813623 : if (lang_hooks.types.type_hash_eq == NULL)
5675 : : return true;
5676 : : /* type_hash_eq currently only applies to these types. */
5677 : 2252041805 : if (TREE_CODE (cand) != FUNCTION_TYPE
5678 : 2252041805 : && TREE_CODE (cand) != METHOD_TYPE)
5679 : : return true;
5680 : 1052326 : return lang_hooks.types.type_hash_eq (cand, base);
5681 : : }
5682 : :
5683 : : /* This function checks to see if TYPE matches the size one of the built-in
5684 : : atomic types, and returns that core atomic type. */
5685 : :
5686 : : static tree
5687 : 8283 : find_atomic_core_type (const_tree type)
5688 : : {
5689 : 8283 : tree base_atomic_type;
5690 : :
5691 : : /* Only handle complete types. */
5692 : 8283 : if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
5693 : : return NULL_TREE;
5694 : :
5695 : 8278 : switch (tree_to_uhwi (TYPE_SIZE (type)))
5696 : : {
5697 : 2446 : case 8:
5698 : 2446 : base_atomic_type = atomicQI_type_node;
5699 : 2446 : break;
5700 : :
5701 : 786 : case 16:
5702 : 786 : base_atomic_type = atomicHI_type_node;
5703 : 786 : break;
5704 : :
5705 : 987 : case 32:
5706 : 987 : base_atomic_type = atomicSI_type_node;
5707 : 987 : break;
5708 : :
5709 : 2630 : case 64:
5710 : 2630 : base_atomic_type = atomicDI_type_node;
5711 : 2630 : break;
5712 : :
5713 : 1309 : case 128:
5714 : 1309 : base_atomic_type = atomicTI_type_node;
5715 : 1309 : break;
5716 : :
5717 : : default:
5718 : : base_atomic_type = NULL_TREE;
5719 : : }
5720 : :
5721 : : return base_atomic_type;
5722 : : }
5723 : :
5724 : : /* Returns true iff unqualified CAND and BASE are equivalent. */
5725 : :
5726 : : bool
5727 : 3685138457 : check_base_type (const_tree cand, const_tree base)
5728 : : {
5729 : 3685138457 : if (TYPE_NAME (cand) != TYPE_NAME (base)
5730 : : /* Apparently this is needed for Objective-C. */
5731 : 3357634586 : || TYPE_CONTEXT (cand) != TYPE_CONTEXT (base)
5732 : 7042773043 : || !attribute_list_equal (TYPE_ATTRIBUTES (cand),
5733 : 3357634586 : TYPE_ATTRIBUTES (base)))
5734 : 327503871 : return false;
5735 : : /* Check alignment. */
5736 : 3357634586 : if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
5737 : 3357634586 : && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
5738 : : return true;
5739 : : /* Atomic types increase minimal alignment. We must to do so as well
5740 : : or we get duplicated canonical types. See PR88686. */
5741 : 11038 : if ((TYPE_QUALS (cand) & TYPE_QUAL_ATOMIC))
5742 : : {
5743 : : /* See if this object can map to a basic atomic type. */
5744 : 1775 : tree atomic_type = find_atomic_core_type (cand);
5745 : 1775 : if (atomic_type && TYPE_ALIGN (atomic_type) == TYPE_ALIGN (cand))
5746 : : return true;
5747 : : }
5748 : : return false;
5749 : : }
5750 : :
5751 : : /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5752 : :
5753 : : bool
5754 : 3895951673 : check_qualified_type (const_tree cand, const_tree base, int type_quals)
5755 : : {
5756 : 3895951673 : return (TYPE_QUALS (cand) == type_quals
5757 : 2632590891 : && check_base_type (cand, base)
5758 : 6201132946 : && check_lang_type (cand, base));
5759 : : }
5760 : :
5761 : : /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5762 : :
5763 : : static bool
5764 : 3221084 : check_aligned_type (const_tree cand, const_tree base, unsigned int align)
5765 : : {
5766 : 3221084 : return (TYPE_QUALS (cand) == TYPE_QUALS (base)
5767 : 2671119 : && TYPE_NAME (cand) == TYPE_NAME (base)
5768 : : /* Apparently this is needed for Objective-C. */
5769 : 1897258 : && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
5770 : : /* Check alignment. */
5771 : 1897258 : && TYPE_ALIGN (cand) == align
5772 : : /* Check this is a user-aligned type as build_aligned_type
5773 : : would create. */
5774 : 898887 : && TYPE_USER_ALIGN (cand)
5775 : 895675 : && attribute_list_equal (TYPE_ATTRIBUTES (cand),
5776 : 895675 : TYPE_ATTRIBUTES (base))
5777 : 4116759 : && check_lang_type (cand, base));
5778 : : }
5779 : :
5780 : : /* Return a version of the TYPE, qualified as indicated by the
5781 : : TYPE_QUALS, if one exists. If no qualified version exists yet,
5782 : : return NULL_TREE. */
5783 : :
5784 : : tree
5785 : 3637704742 : get_qualified_type (tree type, int type_quals)
5786 : : {
5787 : 3637704742 : if (TYPE_QUALS (type) == type_quals)
5788 : : return type;
5789 : :
5790 : 2394340956 : tree mv = TYPE_MAIN_VARIANT (type);
5791 : 2394340956 : if (check_qualified_type (mv, type, type_quals))
5792 : : return mv;
5793 : :
5794 : : /* Search the chain of variants to see if there is already one there just
5795 : : like the one we need to have. If so, use that existing one. We must
5796 : : preserve the TYPE_NAME, since there is code that depends on this. */
5797 : 1590784339 : for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
5798 : 1501549564 : if (check_qualified_type (*tp, type, type_quals))
5799 : : {
5800 : : /* Put the found variant at the head of the variant list so
5801 : : frequently searched variants get found faster. The C++ FE
5802 : : benefits greatly from this. */
5803 : 998992510 : tree t = *tp;
5804 : 998992510 : *tp = TYPE_NEXT_VARIANT (t);
5805 : 998992510 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
5806 : 998992510 : TYPE_NEXT_VARIANT (mv) = t;
5807 : 998992510 : return t;
5808 : : }
5809 : :
5810 : : return NULL_TREE;
5811 : : }
5812 : :
5813 : : /* Like get_qualified_type, but creates the type if it does not
5814 : : exist. This function never returns NULL_TREE. */
5815 : :
5816 : : tree
5817 : 3254345848 : build_qualified_type (tree type, int type_quals MEM_STAT_DECL)
5818 : : {
5819 : 3254345848 : tree t;
5820 : :
5821 : : /* See if we already have the appropriate qualified variant. */
5822 : 3254345848 : t = get_qualified_type (type, type_quals);
5823 : :
5824 : : /* If not, build it. */
5825 : 3254345848 : if (!t)
5826 : : {
5827 : 87676293 : t = build_variant_type_copy (type PASS_MEM_STAT);
5828 : 87676293 : set_type_quals (t, type_quals);
5829 : :
5830 : 87676293 : if (((type_quals & TYPE_QUAL_ATOMIC) == TYPE_QUAL_ATOMIC))
5831 : : {
5832 : : /* See if this object can map to a basic atomic type. */
5833 : 6508 : tree atomic_type = find_atomic_core_type (type);
5834 : 6508 : if (atomic_type)
5835 : : {
5836 : : /* Ensure the alignment of this type is compatible with
5837 : : the required alignment of the atomic type. */
5838 : 6383 : if (TYPE_ALIGN (atomic_type) > TYPE_ALIGN (t))
5839 : 94 : SET_TYPE_ALIGN (t, TYPE_ALIGN (atomic_type));
5840 : : }
5841 : : }
5842 : :
5843 : 87676293 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5844 : : /* Propagate structural equality. */
5845 : 4262763 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5846 : 83413530 : else if (TYPE_CANONICAL (type) != type)
5847 : : /* Build the underlying canonical type, since it is different
5848 : : from TYPE. */
5849 : : {
5850 : 27176122 : tree c = build_qualified_type (TYPE_CANONICAL (type), type_quals);
5851 : 27176122 : TYPE_CANONICAL (t) = TYPE_CANONICAL (c);
5852 : : }
5853 : : else
5854 : : /* T is its own canonical type. */
5855 : 56237408 : TYPE_CANONICAL (t) = t;
5856 : :
5857 : : }
5858 : :
5859 : 3254345848 : return t;
5860 : : }
5861 : :
5862 : : /* Create a variant of type T with alignment ALIGN which
5863 : : is measured in bits. */
5864 : :
5865 : : tree
5866 : 1172644 : build_aligned_type (tree type, unsigned int align)
5867 : : {
5868 : 1172644 : tree t;
5869 : :
5870 : 1172644 : if (TYPE_PACKED (type)
5871 : 1172644 : || TYPE_ALIGN (type) == align)
5872 : : return type;
5873 : :
5874 : 3318698 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5875 : 3221084 : if (check_aligned_type (t, type, align))
5876 : : return t;
5877 : :
5878 : 97614 : t = build_variant_type_copy (type);
5879 : 97614 : SET_TYPE_ALIGN (t, align);
5880 : 97614 : TYPE_USER_ALIGN (t) = 1;
5881 : :
5882 : 97614 : return t;
5883 : : }
5884 : :
5885 : : /* Create a new distinct copy of TYPE. The new type is made its own
5886 : : MAIN_VARIANT. If TYPE requires structural equality checks, the
5887 : : resulting type requires structural equality checks; otherwise, its
5888 : : TYPE_CANONICAL points to itself. */
5889 : :
5890 : : tree
5891 : 676704287 : build_distinct_type_copy (tree type MEM_STAT_DECL)
5892 : : {
5893 : 676704287 : tree t = copy_node (type PASS_MEM_STAT);
5894 : :
5895 : 676704287 : TYPE_POINTER_TO (t) = 0;
5896 : 676704287 : TYPE_REFERENCE_TO (t) = 0;
5897 : :
5898 : : /* Set the canonical type either to a new equivalence class, or
5899 : : propagate the need for structural equality checks. */
5900 : 676704287 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5901 : 56718387 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5902 : : else
5903 : 619985900 : TYPE_CANONICAL (t) = t;
5904 : :
5905 : : /* Make it its own variant. */
5906 : 676704287 : TYPE_MAIN_VARIANT (t) = t;
5907 : 676704287 : TYPE_NEXT_VARIANT (t) = 0;
5908 : :
5909 : : /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5910 : : whose TREE_TYPE is not t. This can also happen in the Ada
5911 : : frontend when using subtypes. */
5912 : :
5913 : 676704287 : return t;
5914 : : }
5915 : :
5916 : : /* Create a new variant of TYPE, equivalent but distinct. This is so
5917 : : the caller can modify it. TYPE_CANONICAL for the return type will
5918 : : be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5919 : : are considered equal by the language itself (or that both types
5920 : : require structural equality checks). */
5921 : :
5922 : : tree
5923 : 404443149 : build_variant_type_copy (tree type MEM_STAT_DECL)
5924 : : {
5925 : 404443149 : tree t, m = TYPE_MAIN_VARIANT (type);
5926 : :
5927 : 404443149 : t = build_distinct_type_copy (type PASS_MEM_STAT);
5928 : :
5929 : : /* Since we're building a variant, assume that it is a non-semantic
5930 : : variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5931 : 404443149 : TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
5932 : : /* Type variants have no alias set defined. */
5933 : 404443149 : TYPE_ALIAS_SET (t) = -1;
5934 : :
5935 : : /* Add the new type to the chain of variants of TYPE. */
5936 : 404443149 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
5937 : 404443149 : TYPE_NEXT_VARIANT (m) = t;
5938 : 404443149 : TYPE_MAIN_VARIANT (t) = m;
5939 : :
5940 : 404443149 : return t;
5941 : : }
5942 : :
5943 : : /* Return true if the from tree in both tree maps are equal. */
5944 : :
5945 : : int
5946 : 1765158395 : tree_map_base_eq (const void *va, const void *vb)
5947 : : {
5948 : 1765158395 : const struct tree_map_base *const a = (const struct tree_map_base *) va,
5949 : 1765158395 : *const b = (const struct tree_map_base *) vb;
5950 : 1765158395 : return (a->from == b->from);
5951 : : }
5952 : :
5953 : : /* Hash a from tree in a tree_base_map. */
5954 : :
5955 : : unsigned int
5956 : 0 : tree_map_base_hash (const void *item)
5957 : : {
5958 : 0 : return htab_hash_pointer (((const struct tree_map_base *)item)->from);
5959 : : }
5960 : :
5961 : : /* Return true if this tree map structure is marked for garbage collection
5962 : : purposes. We simply return true if the from tree is marked, so that this
5963 : : structure goes away when the from tree goes away. */
5964 : :
5965 : : bool
5966 : 0 : tree_map_base_marked_p (const void *p)
5967 : : {
5968 : 0 : return ggc_marked_p (((const struct tree_map_base *) p)->from);
5969 : : }
5970 : :
5971 : : /* Hash a from tree in a tree_map. */
5972 : :
5973 : : unsigned int
5974 : 242 : tree_map_hash (const void *item)
5975 : : {
5976 : 242 : return (((const struct tree_map *) item)->hash);
5977 : : }
5978 : :
5979 : : /* Hash a from tree in a tree_decl_map. */
5980 : :
5981 : : unsigned int
5982 : 1202403197 : tree_decl_map_hash (const void *item)
5983 : : {
5984 : 1202403197 : return DECL_UID (((const struct tree_decl_map *) item)->base.from);
5985 : : }
5986 : :
5987 : : /* Return the initialization priority for DECL. */
5988 : :
5989 : : priority_type
5990 : 23490 : decl_init_priority_lookup (tree decl)
5991 : : {
5992 : 23490 : symtab_node *snode = symtab_node::get (decl);
5993 : :
5994 : 23490 : if (!snode)
5995 : : return DEFAULT_INIT_PRIORITY;
5996 : 23490 : return
5997 : 23490 : snode->get_init_priority ();
5998 : : }
5999 : :
6000 : : /* Return the finalization priority for DECL. */
6001 : :
6002 : : priority_type
6003 : 1803 : decl_fini_priority_lookup (tree decl)
6004 : : {
6005 : 1803 : cgraph_node *node = cgraph_node::get (decl);
6006 : :
6007 : 1803 : if (!node)
6008 : : return DEFAULT_INIT_PRIORITY;
6009 : 1803 : return
6010 : 1803 : node->get_fini_priority ();
6011 : : }
6012 : :
6013 : : /* Set the initialization priority for DECL to PRIORITY. */
6014 : :
6015 : : void
6016 : 24926 : decl_init_priority_insert (tree decl, priority_type priority)
6017 : : {
6018 : 24926 : struct symtab_node *snode;
6019 : :
6020 : 24926 : if (priority == DEFAULT_INIT_PRIORITY)
6021 : : {
6022 : 21297 : snode = symtab_node::get (decl);
6023 : 21297 : if (!snode)
6024 : : return;
6025 : : }
6026 : 3629 : else if (VAR_P (decl))
6027 : 45 : snode = varpool_node::get_create (decl);
6028 : : else
6029 : 3584 : snode = cgraph_node::get_create (decl);
6030 : 24208 : snode->set_init_priority (priority);
6031 : : }
6032 : :
6033 : : /* Set the finalization priority for DECL to PRIORITY. */
6034 : :
6035 : : void
6036 : 1662 : decl_fini_priority_insert (tree decl, priority_type priority)
6037 : : {
6038 : 1662 : struct cgraph_node *node;
6039 : :
6040 : 1662 : if (priority == DEFAULT_INIT_PRIORITY)
6041 : : {
6042 : 104 : node = cgraph_node::get (decl);
6043 : 104 : if (!node)
6044 : : return;
6045 : : }
6046 : : else
6047 : 1558 : node = cgraph_node::get_create (decl);
6048 : 1567 : node->set_fini_priority (priority);
6049 : : }
6050 : :
6051 : : /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6052 : :
6053 : : static void
6054 : 0 : print_debug_expr_statistics (void)
6055 : : {
6056 : 0 : fprintf (stderr, "DECL_DEBUG_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6057 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6058 : 0 : (fmt_size_t) debug_expr_for_decl->size (),
6059 : 0 : (fmt_size_t) debug_expr_for_decl->elements (),
6060 : : debug_expr_for_decl->collisions ());
6061 : 0 : }
6062 : :
6063 : : /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6064 : :
6065 : : static void
6066 : 0 : print_value_expr_statistics (void)
6067 : : {
6068 : 0 : fprintf (stderr, "DECL_VALUE_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6069 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6070 : 0 : (fmt_size_t) value_expr_for_decl->size (),
6071 : 0 : (fmt_size_t) value_expr_for_decl->elements (),
6072 : : value_expr_for_decl->collisions ());
6073 : 0 : }
6074 : :
6075 : : /* Lookup a debug expression for FROM, and return it if we find one. */
6076 : :
6077 : : tree
6078 : 435213975 : decl_debug_expr_lookup (tree from)
6079 : : {
6080 : 435213975 : struct tree_decl_map *h, in;
6081 : 435213975 : in.base.from = from;
6082 : :
6083 : 435213975 : h = debug_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6084 : 435213975 : if (h)
6085 : 435213975 : return h->to;
6086 : : return NULL_TREE;
6087 : : }
6088 : :
6089 : : /* Insert a mapping FROM->TO in the debug expression hashtable. */
6090 : :
6091 : : void
6092 : 1308589 : decl_debug_expr_insert (tree from, tree to)
6093 : : {
6094 : 1308589 : struct tree_decl_map *h;
6095 : :
6096 : 1308589 : h = ggc_alloc<tree_decl_map> ();
6097 : 1308589 : h->base.from = from;
6098 : 1308589 : h->to = to;
6099 : 1308589 : *debug_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6100 : 1308589 : }
6101 : :
6102 : : /* Lookup a value expression for FROM, and return it if we find one. */
6103 : :
6104 : : tree
6105 : 11420568 : decl_value_expr_lookup (tree from)
6106 : : {
6107 : 11420568 : struct tree_decl_map *h, in;
6108 : 11420568 : in.base.from = from;
6109 : :
6110 : 11420568 : h = value_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6111 : 11420568 : if (h)
6112 : 11420568 : return h->to;
6113 : : return NULL_TREE;
6114 : : }
6115 : :
6116 : : /* Insert a mapping FROM->TO in the value expression hashtable. */
6117 : :
6118 : : void
6119 : 4212299 : decl_value_expr_insert (tree from, tree to)
6120 : : {
6121 : 4212299 : struct tree_decl_map *h;
6122 : :
6123 : : /* Uses of FROM shouldn't look like they happen at the location of TO. */
6124 : 4212299 : to = protected_set_expr_location_unshare (to, UNKNOWN_LOCATION);
6125 : :
6126 : 4212299 : h = ggc_alloc<tree_decl_map> ();
6127 : 4212299 : h->base.from = from;
6128 : 4212299 : h->to = to;
6129 : 4212299 : *value_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6130 : 4212299 : }
6131 : :
6132 : : /* Lookup a vector of debug arguments for FROM, and return it if we
6133 : : find one. */
6134 : :
6135 : : vec<tree, va_gc> **
6136 : 790194 : decl_debug_args_lookup (tree from)
6137 : : {
6138 : 790194 : struct tree_vec_map *h, in;
6139 : :
6140 : 790194 : if (!DECL_HAS_DEBUG_ARGS_P (from))
6141 : : return NULL;
6142 : 658898 : gcc_checking_assert (debug_args_for_decl != NULL);
6143 : 658898 : in.base.from = from;
6144 : 658898 : h = debug_args_for_decl->find_with_hash (&in, DECL_UID (from));
6145 : 658898 : if (h)
6146 : 655744 : return &h->to;
6147 : : return NULL;
6148 : : }
6149 : :
6150 : : /* Insert a mapping FROM->empty vector of debug arguments in the value
6151 : : expression hashtable. */
6152 : :
6153 : : vec<tree, va_gc> **
6154 : 233263 : decl_debug_args_insert (tree from)
6155 : : {
6156 : 233263 : struct tree_vec_map *h;
6157 : 233263 : tree_vec_map **loc;
6158 : :
6159 : 233263 : if (DECL_HAS_DEBUG_ARGS_P (from))
6160 : 153665 : return decl_debug_args_lookup (from);
6161 : 79598 : if (debug_args_for_decl == NULL)
6162 : 8269 : debug_args_for_decl = hash_table<tree_vec_map_cache_hasher>::create_ggc (64);
6163 : 79598 : h = ggc_alloc<tree_vec_map> ();
6164 : 79598 : h->base.from = from;
6165 : 79598 : h->to = NULL;
6166 : 79598 : loc = debug_args_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT);
6167 : 79598 : *loc = h;
6168 : 79598 : DECL_HAS_DEBUG_ARGS_P (from) = 1;
6169 : 79598 : return &h->to;
6170 : : }
6171 : :
6172 : : /* Hashing of types so that we don't make duplicates.
6173 : : The entry point is `type_hash_canon'. */
6174 : :
6175 : : /* Generate the default hash code for TYPE. This is designed for
6176 : : speed, rather than maximum entropy. */
6177 : :
6178 : : hashval_t
6179 : 1287198615 : type_hash_canon_hash (tree type)
6180 : : {
6181 : 1287198615 : inchash::hash hstate;
6182 : :
6183 : 1287198615 : hstate.add_int (TREE_CODE (type));
6184 : :
6185 : 1287198615 : hstate.add_flag (TYPE_STRUCTURAL_EQUALITY_P (type));
6186 : :
6187 : 1287198615 : if (TREE_TYPE (type))
6188 : 1287176790 : hstate.add_object (TYPE_HASH (TREE_TYPE (type)));
6189 : :
6190 : 1561219994 : for (tree t = TYPE_ATTRIBUTES (type); t; t = TREE_CHAIN (t))
6191 : : /* Just the identifier is adequate to distinguish. */
6192 : 274021379 : hstate.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (t)));
6193 : :
6194 : 1287198615 : switch (TREE_CODE (type))
6195 : : {
6196 : 282055698 : case METHOD_TYPE:
6197 : 282055698 : hstate.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type)));
6198 : : /* FALLTHROUGH. */
6199 : 1113990295 : case FUNCTION_TYPE:
6200 : 4428878368 : for (tree t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
6201 : 3314888073 : if (TREE_VALUE (t) != error_mark_node)
6202 : 3314884202 : hstate.add_object (TYPE_HASH (TREE_VALUE (t)));
6203 : : break;
6204 : :
6205 : 947828 : case OFFSET_TYPE:
6206 : 947828 : hstate.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type)));
6207 : 947828 : break;
6208 : :
6209 : 60108146 : case ARRAY_TYPE:
6210 : 60108146 : {
6211 : 60108146 : if (TYPE_DOMAIN (type))
6212 : 58521603 : hstate.add_object (TYPE_HASH (TYPE_DOMAIN (type)));
6213 : 60108146 : if (!AGGREGATE_TYPE_P (TREE_TYPE (type)))
6214 : : {
6215 : 58785736 : unsigned typeless = TYPE_TYPELESS_STORAGE (type);
6216 : 58785736 : hstate.add_object (typeless);
6217 : : }
6218 : : }
6219 : : break;
6220 : :
6221 : 36414825 : case INTEGER_TYPE:
6222 : 36414825 : {
6223 : 36414825 : tree t = TYPE_MAX_VALUE (type);
6224 : 36414825 : if (!t)
6225 : 540218 : t = TYPE_MIN_VALUE (type);
6226 : 72829651 : for (int i = 0; i < TREE_INT_CST_NUNITS (t); i++)
6227 : 36414826 : hstate.add_object (TREE_INT_CST_ELT (t, i));
6228 : : break;
6229 : : }
6230 : :
6231 : 1 : case BITINT_TYPE:
6232 : 1 : {
6233 : 1 : unsigned prec = TYPE_PRECISION (type);
6234 : 1 : unsigned uns = TYPE_UNSIGNED (type);
6235 : 1 : hstate.add_object (prec);
6236 : 1 : hstate.add_int (uns);
6237 : 1 : break;
6238 : : }
6239 : :
6240 : 11694 : case REAL_TYPE:
6241 : 11694 : case FIXED_POINT_TYPE:
6242 : 11694 : {
6243 : 11694 : unsigned prec = TYPE_PRECISION (type);
6244 : 11694 : hstate.add_object (prec);
6245 : 11694 : break;
6246 : : }
6247 : :
6248 : 70293311 : case VECTOR_TYPE:
6249 : 70293311 : hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type));
6250 : 70293311 : break;
6251 : :
6252 : : case REFERENCE_TYPE:
6253 : 1287198615 : hstate.add_flag (TYPE_REF_IS_RVALUE (type));
6254 : : break;
6255 : :
6256 : : default:
6257 : : break;
6258 : : }
6259 : :
6260 : 1287198615 : return hstate.end ();
6261 : : }
6262 : :
6263 : : /* These are the Hashtable callback functions. */
6264 : :
6265 : : /* Returns true iff the types are equivalent. */
6266 : :
6267 : : bool
6268 : 7885228352 : type_cache_hasher::equal (type_hash *a, type_hash *b)
6269 : : {
6270 : : /* First test the things that are the same for all types. */
6271 : 7885228352 : if (a->hash != b->hash
6272 : 641720223 : || TREE_CODE (a->type) != TREE_CODE (b->type)
6273 : 641713072 : || TREE_TYPE (a->type) != TREE_TYPE (b->type)
6274 : 641712307 : || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
6275 : 641712307 : TYPE_ATTRIBUTES (b->type))
6276 : 8519998902 : || (TREE_CODE (a->type) != COMPLEX_TYPE
6277 : 632724199 : && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
6278 : 7251329311 : return false;
6279 : :
6280 : : /* Be careful about comparing arrays before and after the element type
6281 : : has been completed; don't compare TYPE_ALIGN unless both types are
6282 : : complete. */
6283 : 1265962818 : if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
6284 : 1265962818 : && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
6285 : 632063221 : || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
6286 : 669 : return false;
6287 : :
6288 : 633898372 : if (TYPE_STRUCTURAL_EQUALITY_P (a->type)
6289 : 633898372 : != TYPE_STRUCTURAL_EQUALITY_P (b->type))
6290 : : return false;
6291 : :
6292 : 633894976 : switch (TREE_CODE (a->type))
6293 : : {
6294 : : case VOID_TYPE:
6295 : : case OPAQUE_TYPE:
6296 : : case COMPLEX_TYPE:
6297 : : case POINTER_TYPE:
6298 : : case NULLPTR_TYPE:
6299 : : return true;
6300 : :
6301 : 64077856 : case VECTOR_TYPE:
6302 : 64077856 : return known_eq (TYPE_VECTOR_SUBPARTS (a->type),
6303 : : TYPE_VECTOR_SUBPARTS (b->type));
6304 : :
6305 : 0 : case ENUMERAL_TYPE:
6306 : 0 : if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6307 : 0 : && !(TYPE_VALUES (a->type)
6308 : 0 : && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6309 : 0 : && TYPE_VALUES (b->type)
6310 : 0 : && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
6311 : 0 : && type_list_equal (TYPE_VALUES (a->type),
6312 : 0 : TYPE_VALUES (b->type))))
6313 : 0 : return false;
6314 : :
6315 : : /* fall through */
6316 : :
6317 : 33878859 : case INTEGER_TYPE:
6318 : 33878859 : case REAL_TYPE:
6319 : 33878859 : case BOOLEAN_TYPE:
6320 : 33878859 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6321 : : return false;
6322 : 33872158 : return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
6323 : 798750 : || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
6324 : 798750 : TYPE_MAX_VALUE (b->type)))
6325 : 34256089 : && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
6326 : 504672 : || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
6327 : 504672 : TYPE_MIN_VALUE (b->type))));
6328 : :
6329 : 1535424 : case BITINT_TYPE:
6330 : 1535424 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6331 : : return false;
6332 : 1488721 : return TYPE_UNSIGNED (a->type) == TYPE_UNSIGNED (b->type);
6333 : :
6334 : 0 : case FIXED_POINT_TYPE:
6335 : 0 : return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
6336 : :
6337 : 753997 : case OFFSET_TYPE:
6338 : 753997 : return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
6339 : :
6340 : 81309923 : case METHOD_TYPE:
6341 : 81309923 : if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
6342 : 81309923 : && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6343 : 81261905 : || (TYPE_ARG_TYPES (a->type)
6344 : 81261905 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6345 : 81261905 : && TYPE_ARG_TYPES (b->type)
6346 : 81261905 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6347 : 81261905 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6348 : 81261905 : TYPE_ARG_TYPES (b->type)))))
6349 : : break;
6350 : : return false;
6351 : 50184321 : case ARRAY_TYPE:
6352 : : /* Don't compare TYPE_TYPELESS_STORAGE flag on aggregates,
6353 : : where the flag should be inherited from the element type
6354 : : and can change after ARRAY_TYPEs are created; on non-aggregates
6355 : : compare it and hash it, scalars will never have that flag set
6356 : : and we need to differentiate between arrays created by different
6357 : : front-ends or middle-end created arrays. */
6358 : 50184321 : return (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
6359 : 50184321 : && (AGGREGATE_TYPE_P (TREE_TYPE (a->type))
6360 : 49474236 : || (TYPE_TYPELESS_STORAGE (a->type)
6361 : 49474236 : == TYPE_TYPELESS_STORAGE (b->type))));
6362 : :
6363 : 0 : case RECORD_TYPE:
6364 : 0 : case UNION_TYPE:
6365 : 0 : case QUAL_UNION_TYPE:
6366 : 0 : return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
6367 : 0 : || (TYPE_FIELDS (a->type)
6368 : 0 : && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
6369 : 0 : && TYPE_FIELDS (b->type)
6370 : 0 : && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
6371 : 0 : && type_list_equal (TYPE_FIELDS (a->type),
6372 : 0 : TYPE_FIELDS (b->type))));
6373 : :
6374 : 400107757 : case FUNCTION_TYPE:
6375 : 400107757 : if ((TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6376 : 253226504 : && (TYPE_NO_NAMED_ARGS_STDARG_P (a->type)
6377 : 253226504 : == TYPE_NO_NAMED_ARGS_STDARG_P (b->type)))
6378 : 400420548 : || (TYPE_ARG_TYPES (a->type)
6379 : 146881253 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6380 : 146881253 : && TYPE_ARG_TYPES (b->type)
6381 : 146881253 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6382 : 146881253 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6383 : 146881253 : TYPE_ARG_TYPES (b->type))))
6384 : : break;
6385 : : return false;
6386 : :
6387 : 9 : case REFERENCE_TYPE:
6388 : 9 : return TYPE_REF_IS_RVALUE (a->type) == TYPE_REF_IS_RVALUE (b->type);
6389 : :
6390 : : default:
6391 : : return false;
6392 : : }
6393 : :
6394 : 457131443 : if (lang_hooks.types.type_hash_eq != NULL)
6395 : 279514406 : return lang_hooks.types.type_hash_eq (a->type, b->type);
6396 : :
6397 : : return true;
6398 : : }
6399 : :
6400 : : /* Given TYPE, and HASHCODE its hash code, return the canonical
6401 : : object for an identical type if one already exists.
6402 : : Otherwise, return TYPE, and record it as the canonical object.
6403 : :
6404 : : To use this function, first create a type of the sort you want.
6405 : : Then compute its hash code from the fields of the type that
6406 : : make it different from other similar types.
6407 : : Then call this function and use the value. */
6408 : :
6409 : : tree
6410 : 1289766678 : type_hash_canon (unsigned int hashcode, tree type)
6411 : : {
6412 : 1289766678 : type_hash in;
6413 : 1289766678 : type_hash **loc;
6414 : :
6415 : : /* The hash table only contains main variants, so ensure that's what we're
6416 : : being passed. */
6417 : 1289766678 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
6418 : :
6419 : : /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6420 : : must call that routine before comparing TYPE_ALIGNs. */
6421 : 1289766678 : layout_type (type);
6422 : :
6423 : 1289766678 : in.hash = hashcode;
6424 : 1289766678 : in.type = type;
6425 : :
6426 : 1289766678 : loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT);
6427 : 1289766678 : if (*loc)
6428 : : {
6429 : 609018755 : tree t1 = ((type_hash *) *loc)->type;
6430 : 609018755 : gcc_assert (TYPE_MAIN_VARIANT (t1) == t1
6431 : : && t1 != type);
6432 : 609018755 : if (TYPE_UID (type) + 1 == next_type_uid)
6433 : 603953783 : --next_type_uid;
6434 : : /* Free also min/max values and the cache for integer
6435 : : types. This can't be done in free_node, as LTO frees
6436 : : those on its own. */
6437 : 609018755 : if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE)
6438 : : {
6439 : 34824296 : if (TYPE_MIN_VALUE (type)
6440 : 34824296 : && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
6441 : : {
6442 : : /* Zero is always in TYPE_CACHED_VALUES. */
6443 : 1871073 : if (! TYPE_UNSIGNED (type))
6444 : 1656368 : int_cst_hash_table->remove_elt (TYPE_MIN_VALUE (type));
6445 : 1871073 : ggc_free (TYPE_MIN_VALUE (type));
6446 : : }
6447 : 34824296 : if (TYPE_MAX_VALUE (type)
6448 : 34824296 : && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
6449 : : {
6450 : 1871073 : int_cst_hash_table->remove_elt (TYPE_MAX_VALUE (type));
6451 : 1871073 : ggc_free (TYPE_MAX_VALUE (type));
6452 : : }
6453 : 34824296 : if (TYPE_CACHED_VALUES_P (type))
6454 : 214705 : ggc_free (TYPE_CACHED_VALUES (type));
6455 : : }
6456 : 609018755 : free_node (type);
6457 : 609018755 : return t1;
6458 : : }
6459 : : else
6460 : : {
6461 : 680747923 : struct type_hash *h;
6462 : :
6463 : 680747923 : h = ggc_alloc<type_hash> ();
6464 : 680747923 : h->hash = hashcode;
6465 : 680747923 : h->type = type;
6466 : 680747923 : *loc = h;
6467 : :
6468 : 680747923 : return type;
6469 : : }
6470 : : }
6471 : :
6472 : : static void
6473 : 0 : print_type_hash_statistics (void)
6474 : : {
6475 : 0 : fprintf (stderr, "Type hash: size " HOST_SIZE_T_PRINT_DEC ", "
6476 : : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6477 : 0 : (fmt_size_t) type_hash_table->size (),
6478 : 0 : (fmt_size_t) type_hash_table->elements (),
6479 : : type_hash_table->collisions ());
6480 : 0 : }
6481 : :
6482 : : /* Given two lists of types
6483 : : (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6484 : : return 1 if the lists contain the same types in the same order.
6485 : : Also, the TREE_PURPOSEs must match. */
6486 : :
6487 : : bool
6488 : 228143681 : type_list_equal (const_tree l1, const_tree l2)
6489 : : {
6490 : 228143681 : const_tree t1, t2;
6491 : :
6492 : 863306663 : for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6493 : 659136383 : if (TREE_VALUE (t1) != TREE_VALUE (t2)
6494 : 659136383 : || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6495 : 23974645 : && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6496 : 1275 : && (TREE_TYPE (TREE_PURPOSE (t1))
6497 : 1275 : == TREE_TYPE (TREE_PURPOSE (t2))))))
6498 : 23973401 : return false;
6499 : :
6500 : 204170280 : return t1 == t2;
6501 : : }
6502 : :
6503 : : /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6504 : : given by TYPE. If the argument list accepts variable arguments,
6505 : : then this function counts only the ordinary arguments. */
6506 : :
6507 : : int
6508 : 78395535 : type_num_arguments (const_tree fntype)
6509 : : {
6510 : 78395535 : int i = 0;
6511 : :
6512 : 305241226 : for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
6513 : : /* If the function does not take a variable number of arguments,
6514 : : the last element in the list will have type `void'. */
6515 : 286694213 : if (VOID_TYPE_P (TREE_VALUE (t)))
6516 : : break;
6517 : : else
6518 : 226845691 : ++i;
6519 : :
6520 : 78395535 : return i;
6521 : : }
6522 : :
6523 : : /* Return the type of the function TYPE's argument ARGNO if known.
6524 : : For vararg function's where ARGNO refers to one of the variadic
6525 : : arguments return null. Otherwise, return a void_type_node for
6526 : : out-of-bounds ARGNO. */
6527 : :
6528 : : tree
6529 : 77912563 : type_argument_type (const_tree fntype, unsigned argno)
6530 : : {
6531 : : /* Treat zero the same as an out-of-bounds argument number. */
6532 : 77912563 : if (!argno)
6533 : 0 : return void_type_node;
6534 : :
6535 : 77912563 : function_args_iterator iter;
6536 : :
6537 : 77912563 : tree argtype;
6538 : 77912563 : unsigned i = 1;
6539 : 168027182 : FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
6540 : : {
6541 : : /* A vararg function's argument list ends in a null. Otherwise,
6542 : : an ordinary function's argument list ends with void. Return
6543 : : null if ARGNO refers to a vararg argument, void_type_node if
6544 : : it's out of bounds, and the formal argument type otherwise. */
6545 : 162463727 : if (!argtype)
6546 : : break;
6547 : :
6548 : 162463727 : if (i == argno || VOID_TYPE_P (argtype))
6549 : : return argtype;
6550 : :
6551 : 90114619 : ++i;
6552 : : }
6553 : :
6554 : : return NULL_TREE;
6555 : : }
6556 : :
6557 : : /* True if integer constants T1 and T2
6558 : : represent the same constant value. */
6559 : :
6560 : : bool
6561 : 1068781723 : tree_int_cst_equal (const_tree t1, const_tree t2)
6562 : : {
6563 : 1068781723 : if (t1 == t2)
6564 : : return true;
6565 : :
6566 : 498049112 : if (t1 == 0 || t2 == 0)
6567 : : return false;
6568 : :
6569 : 497632233 : STRIP_ANY_LOCATION_WRAPPER (t1);
6570 : 497632233 : STRIP_ANY_LOCATION_WRAPPER (t2);
6571 : :
6572 : 497632233 : if (TREE_CODE (t1) == INTEGER_CST
6573 : 494071818 : && TREE_CODE (t2) == INTEGER_CST
6574 : 991704051 : && wi::to_widest (t1) == wi::to_widest (t2))
6575 : 18436823 : return true;
6576 : :
6577 : : return false;
6578 : : }
6579 : :
6580 : : /* Return true if T is an INTEGER_CST whose numerical value (extended
6581 : : according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
6582 : :
6583 : : bool
6584 : 1974334196 : tree_fits_shwi_p (const_tree t)
6585 : : {
6586 : 1974334196 : return (t != NULL_TREE
6587 : 1974334097 : && TREE_CODE (t) == INTEGER_CST
6588 : 3945324911 : && wi::fits_shwi_p (wi::to_widest (t)));
6589 : : }
6590 : :
6591 : : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6592 : : value (extended according to TYPE_UNSIGNED) fits in a poly_int64. */
6593 : :
6594 : : bool
6595 : 885107182 : tree_fits_poly_int64_p (const_tree t)
6596 : : {
6597 : 885107182 : if (t == NULL_TREE)
6598 : : return false;
6599 : 845656730 : if (POLY_INT_CST_P (t))
6600 : : {
6601 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6602 : : if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t, i))))
6603 : : return false;
6604 : : return true;
6605 : : }
6606 : 845656730 : return (TREE_CODE (t) == INTEGER_CST
6607 : 1691418120 : && wi::fits_shwi_p (wi::to_widest (t)));
6608 : : }
6609 : :
6610 : : /* Return true if T is an INTEGER_CST whose numerical value (extended
6611 : : according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
6612 : :
6613 : : bool
6614 : 3213298414 : tree_fits_uhwi_p (const_tree t)
6615 : : {
6616 : 3213298414 : return (t != NULL_TREE
6617 : 3212864944 : && TREE_CODE (t) == INTEGER_CST
6618 : 6421585869 : && wi::fits_uhwi_p (wi::to_widest (t)));
6619 : : }
6620 : :
6621 : : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6622 : : value (extended according to TYPE_UNSIGNED) fits in a poly_uint64. */
6623 : :
6624 : : bool
6625 : 871289223 : tree_fits_poly_uint64_p (const_tree t)
6626 : : {
6627 : 871289223 : if (t == NULL_TREE)
6628 : : return false;
6629 : 870939973 : if (POLY_INT_CST_P (t))
6630 : : {
6631 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6632 : : if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t, i))))
6633 : : return false;
6634 : : return true;
6635 : : }
6636 : 870939973 : return (TREE_CODE (t) == INTEGER_CST
6637 : 1741881280 : && wi::fits_uhwi_p (wi::to_widest (t)));
6638 : : }
6639 : :
6640 : : /* T is an INTEGER_CST whose numerical value (extended according to
6641 : : TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
6642 : : HOST_WIDE_INT. */
6643 : :
6644 : : HOST_WIDE_INT
6645 : 1219466249 : tree_to_shwi (const_tree t)
6646 : : {
6647 : 1219466249 : gcc_assert (tree_fits_shwi_p (t));
6648 : 1219466249 : return TREE_INT_CST_LOW (t);
6649 : : }
6650 : :
6651 : : /* T is an INTEGER_CST whose numerical value (extended according to
6652 : : TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
6653 : : HOST_WIDE_INT. */
6654 : :
6655 : : unsigned HOST_WIDE_INT
6656 : 699255681 : tree_to_uhwi (const_tree t)
6657 : : {
6658 : 699255681 : gcc_assert (tree_fits_uhwi_p (t));
6659 : 699255681 : return TREE_INT_CST_LOW (t);
6660 : : }
6661 : :
6662 : : /* Return the most significant (sign) bit of T. */
6663 : :
6664 : : int
6665 : 39574796 : tree_int_cst_sign_bit (const_tree t)
6666 : : {
6667 : 39574796 : unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
6668 : :
6669 : 39574796 : return wi::extract_uhwi (wi::to_wide (t), bitno, 1);
6670 : : }
6671 : :
6672 : : /* Return an indication of the sign of the integer constant T.
6673 : : The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6674 : : Note that -1 will never be returned if T's type is unsigned. */
6675 : :
6676 : : int
6677 : 1549338133 : tree_int_cst_sgn (const_tree t)
6678 : : {
6679 : 1549338133 : if (wi::to_wide (t) == 0)
6680 : : return 0;
6681 : 1448988898 : else if (TYPE_UNSIGNED (TREE_TYPE (t)))
6682 : : return 1;
6683 : 63725646 : else if (wi::neg_p (wi::to_wide (t)))
6684 : : return -1;
6685 : : else
6686 : : return 1;
6687 : : }
6688 : :
6689 : : /* Return the minimum number of bits needed to represent VALUE in a
6690 : : signed or unsigned type, UNSIGNEDP says which. */
6691 : :
6692 : : unsigned int
6693 : 3299014 : tree_int_cst_min_precision (tree value, signop sgn)
6694 : : {
6695 : : /* If the value is negative, compute its negative minus 1. The latter
6696 : : adjustment is because the absolute value of the largest negative value
6697 : : is one larger than the largest positive value. This is equivalent to
6698 : : a bit-wise negation, so use that operation instead. */
6699 : :
6700 : 3299014 : if (tree_int_cst_sgn (value) < 0)
6701 : 97135 : value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
6702 : :
6703 : : /* Return the number of bits needed, taking into account the fact
6704 : : that we need one more bit for a signed than unsigned type.
6705 : : If value is 0 or -1, the minimum precision is 1 no matter
6706 : : whether unsignedp is true or false. */
6707 : :
6708 : 3299014 : if (integer_zerop (value))
6709 : : return 1;
6710 : : else
6711 : 4720676 : return tree_floor_log2 (value) + 1 + (sgn == SIGNED ? 1 : 0) ;
6712 : : }
6713 : :
6714 : : /* Return truthvalue of whether T1 is the same tree structure as T2.
6715 : : Return 1 if they are the same.
6716 : : Return 0 if they are understandably different.
6717 : : Return -1 if either contains tree structure not understood by
6718 : : this function. */
6719 : :
6720 : : int
6721 : 172622928 : simple_cst_equal (const_tree t1, const_tree t2)
6722 : : {
6723 : 176510187 : enum tree_code code1, code2;
6724 : 176510187 : int cmp;
6725 : 176510187 : int i;
6726 : :
6727 : 176510187 : if (t1 == t2)
6728 : : return 1;
6729 : 112569849 : if (t1 == 0 || t2 == 0)
6730 : : return 0;
6731 : :
6732 : : /* For location wrappers to be the same, they must be at the same
6733 : : source location (and wrap the same thing). */
6734 : 104507977 : if (location_wrapper_p (t1) && location_wrapper_p (t2))
6735 : : {
6736 : 10761367 : if (EXPR_LOCATION (t1) != EXPR_LOCATION (t2))
6737 : : return 0;
6738 : 558 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6739 : : }
6740 : :
6741 : 93746610 : code1 = TREE_CODE (t1);
6742 : 93746610 : code2 = TREE_CODE (t2);
6743 : :
6744 : 93746610 : if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
6745 : : {
6746 : 3874350 : if (CONVERT_EXPR_CODE_P (code2)
6747 : 3873672 : || code2 == NON_LVALUE_EXPR)
6748 : 678 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6749 : : else
6750 : 3873672 : return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
6751 : : }
6752 : :
6753 : 89872260 : else if (CONVERT_EXPR_CODE_P (code2)
6754 : 89872245 : || code2 == NON_LVALUE_EXPR)
6755 : 116 : return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
6756 : :
6757 : 89872144 : if (code1 != code2)
6758 : : return 0;
6759 : :
6760 : 85460345 : switch (code1)
6761 : : {
6762 : 70936583 : case INTEGER_CST:
6763 : 70936583 : return wi::to_widest (t1) == wi::to_widest (t2);
6764 : :
6765 : 87 : case REAL_CST:
6766 : 87 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
6767 : :
6768 : 0 : case FIXED_CST:
6769 : 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
6770 : :
6771 : 3020246 : case STRING_CST:
6772 : 3020246 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
6773 : 3020246 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
6774 : 3436003 : TREE_STRING_LENGTH (t1)));
6775 : :
6776 : 64 : case CONSTRUCTOR:
6777 : 64 : {
6778 : 64 : unsigned HOST_WIDE_INT idx;
6779 : 64 : vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1);
6780 : 64 : vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);
6781 : :
6782 : 82 : if (vec_safe_length (v1) != vec_safe_length (v2))
6783 : : return false;
6784 : :
6785 : 70 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
6786 : : /* ??? Should we handle also fields here? */
6787 : 9 : if (!simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value))
6788 : : return false;
6789 : : return true;
6790 : : }
6791 : :
6792 : 0 : case SAVE_EXPR:
6793 : 0 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6794 : :
6795 : 206556 : case CALL_EXPR:
6796 : 206556 : cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
6797 : 206556 : if (cmp <= 0)
6798 : : return cmp;
6799 : 84610 : if (call_expr_nargs (t1) != call_expr_nargs (t2))
6800 : : return 0;
6801 : 84610 : {
6802 : 84610 : const_tree arg1, arg2;
6803 : 84610 : const_call_expr_arg_iterator iter1, iter2;
6804 : 169220 : for (arg1 = first_const_call_expr_arg (t1, &iter1),
6805 : 84610 : arg2 = first_const_call_expr_arg (t2, &iter2);
6806 : 84680 : arg1 && arg2;
6807 : 70 : arg1 = next_const_call_expr_arg (&iter1),
6808 : 70 : arg2 = next_const_call_expr_arg (&iter2))
6809 : : {
6810 : 84598 : cmp = simple_cst_equal (arg1, arg2);
6811 : 84598 : if (cmp <= 0)
6812 : : return cmp;
6813 : : }
6814 : 82 : return arg1 == arg2;
6815 : : }
6816 : :
6817 : 11810 : case TARGET_EXPR:
6818 : : /* Special case: if either target is an unallocated VAR_DECL,
6819 : : it means that it's going to be unified with whatever the
6820 : : TARGET_EXPR is really supposed to initialize, so treat it
6821 : : as being equivalent to anything. */
6822 : 11810 : if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
6823 : 11810 : && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
6824 : 11810 : && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
6825 : 11810 : || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
6826 : 0 : && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
6827 : 0 : && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
6828 : : cmp = 1;
6829 : : else
6830 : 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6831 : :
6832 : 0 : if (cmp <= 0)
6833 : : return cmp;
6834 : :
6835 : 11810 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
6836 : :
6837 : 0 : case WITH_CLEANUP_EXPR:
6838 : 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6839 : 0 : if (cmp <= 0)
6840 : : return cmp;
6841 : :
6842 : 0 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
6843 : :
6844 : 425 : case COMPONENT_REF:
6845 : 425 : if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
6846 : 425 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6847 : :
6848 : : return 0;
6849 : :
6850 : : case VAR_DECL:
6851 : : case PARM_DECL:
6852 : : case CONST_DECL:
6853 : : case FUNCTION_DECL:
6854 : : return 0;
6855 : :
6856 : 11223700 : default:
6857 : 11223700 : if (POLY_INT_CST_P (t1))
6858 : : /* A false return means maybe_ne rather than known_ne. */
6859 : : return known_eq (poly_widest_int::from (poly_int_cst_value (t1),
6860 : : TYPE_SIGN (TREE_TYPE (t1))),
6861 : : poly_widest_int::from (poly_int_cst_value (t2),
6862 : : TYPE_SIGN (TREE_TYPE (t2))));
6863 : 11223700 : break;
6864 : : }
6865 : :
6866 : : /* This general rule works for most tree codes. All exceptions should be
6867 : : handled above. If this is a language-specific tree code, we can't
6868 : : trust what might be in the operand, so say we don't know
6869 : : the situation. */
6870 : 11223700 : if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
6871 : : return -1;
6872 : :
6873 : 6597892 : switch (TREE_CODE_CLASS (code1))
6874 : : {
6875 : : case tcc_unary:
6876 : : case tcc_binary:
6877 : : case tcc_comparison:
6878 : : case tcc_expression:
6879 : : case tcc_reference:
6880 : : case tcc_statement:
6881 : : cmp = 1;
6882 : 2105 : for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
6883 : : {
6884 : 1625 : cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
6885 : 1625 : if (cmp <= 0)
6886 : : return cmp;
6887 : : }
6888 : :
6889 : : return cmp;
6890 : :
6891 : : default:
6892 : : return -1;
6893 : : }
6894 : : }
6895 : :
6896 : : /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6897 : : Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6898 : : than U, respectively. */
6899 : :
6900 : : int
6901 : 1278439067 : compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
6902 : : {
6903 : 1278439067 : if (tree_int_cst_sgn (t) < 0)
6904 : : return -1;
6905 : 1278438791 : else if (!tree_fits_uhwi_p (t))
6906 : : return 1;
6907 : 1278438766 : else if (TREE_INT_CST_LOW (t) == u)
6908 : : return 0;
6909 : 1160319794 : else if (TREE_INT_CST_LOW (t) < u)
6910 : : return -1;
6911 : : else
6912 : 12017818 : return 1;
6913 : : }
6914 : :
6915 : : /* Return true if SIZE represents a constant size that is in bounds of
6916 : : what the middle-end and the backend accepts (covering not more than
6917 : : half of the address-space).
6918 : : When PERR is non-null, set *PERR on failure to the description of
6919 : : why SIZE is not valid. */
6920 : :
6921 : : bool
6922 : 52406326 : valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */)
6923 : : {
6924 : 52406326 : if (POLY_INT_CST_P (size))
6925 : : {
6926 : : if (TREE_OVERFLOW (size))
6927 : : return false;
6928 : : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
6929 : : if (!valid_constant_size_p (POLY_INT_CST_COEFF (size, i)))
6930 : : return false;
6931 : : return true;
6932 : : }
6933 : :
6934 : 52406326 : cst_size_error error;
6935 : 52406326 : if (!perr)
6936 : 47645582 : perr = &error;
6937 : :
6938 : 52406326 : if (TREE_CODE (size) != INTEGER_CST)
6939 : : {
6940 : 3 : *perr = cst_size_not_constant;
6941 : 3 : return false;
6942 : : }
6943 : :
6944 : 52406323 : if (TREE_OVERFLOW_P (size))
6945 : : {
6946 : 60 : *perr = cst_size_overflow;
6947 : 60 : return false;
6948 : : }
6949 : :
6950 : 52406263 : if (tree_int_cst_sgn (size) < 0)
6951 : : {
6952 : 426 : *perr = cst_size_negative;
6953 : 426 : return false;
6954 : : }
6955 : 104811674 : if (!tree_fits_uhwi_p (size)
6956 : 157217511 : || (wi::to_widest (TYPE_MAX_VALUE (sizetype))
6957 : 157217511 : < wi::to_widest (size) * 2))
6958 : : {
6959 : 624 : *perr = cst_size_too_big;
6960 : 624 : return false;
6961 : : }
6962 : :
6963 : : return true;
6964 : : }
6965 : :
6966 : : /* Return the precision of the type, or for a complex or vector type the
6967 : : precision of the type of its elements. */
6968 : :
6969 : : unsigned int
6970 : 6896715866 : element_precision (const_tree type)
6971 : : {
6972 : 6896715866 : if (!TYPE_P (type))
6973 : 6533142 : type = TREE_TYPE (type);
6974 : 6896715866 : enum tree_code code = TREE_CODE (type);
6975 : 6896715866 : if (code == COMPLEX_TYPE || code == VECTOR_TYPE)
6976 : 53054863 : type = TREE_TYPE (type);
6977 : :
6978 : 6896715866 : return TYPE_PRECISION (type);
6979 : : }
6980 : :
6981 : : /* Return true if CODE represents an associative tree code. Otherwise
6982 : : return false. */
6983 : : bool
6984 : 34746071 : associative_tree_code (enum tree_code code)
6985 : : {
6986 : 34746071 : switch (code)
6987 : : {
6988 : : case BIT_IOR_EXPR:
6989 : : case BIT_AND_EXPR:
6990 : : case BIT_XOR_EXPR:
6991 : : case PLUS_EXPR:
6992 : : case MULT_EXPR:
6993 : : case MIN_EXPR:
6994 : : case MAX_EXPR:
6995 : : return true;
6996 : :
6997 : 24607465 : default:
6998 : 24607465 : break;
6999 : : }
7000 : 24607465 : return false;
7001 : : }
7002 : :
7003 : : /* Return true if CODE represents a commutative tree code. Otherwise
7004 : : return false. */
7005 : : bool
7006 : 1614106646 : commutative_tree_code (enum tree_code code)
7007 : : {
7008 : 1614106646 : switch (code)
7009 : : {
7010 : : case PLUS_EXPR:
7011 : : case MULT_EXPR:
7012 : : case MULT_HIGHPART_EXPR:
7013 : : case MIN_EXPR:
7014 : : case MAX_EXPR:
7015 : : case BIT_IOR_EXPR:
7016 : : case BIT_XOR_EXPR:
7017 : : case BIT_AND_EXPR:
7018 : : case NE_EXPR:
7019 : : case EQ_EXPR:
7020 : : case UNORDERED_EXPR:
7021 : : case ORDERED_EXPR:
7022 : : case UNEQ_EXPR:
7023 : : case LTGT_EXPR:
7024 : : case TRUTH_AND_EXPR:
7025 : : case TRUTH_XOR_EXPR:
7026 : : case TRUTH_OR_EXPR:
7027 : : case WIDEN_MULT_EXPR:
7028 : : case VEC_WIDEN_MULT_HI_EXPR:
7029 : : case VEC_WIDEN_MULT_LO_EXPR:
7030 : : case VEC_WIDEN_MULT_EVEN_EXPR:
7031 : : case VEC_WIDEN_MULT_ODD_EXPR:
7032 : : return true;
7033 : :
7034 : 836270416 : default:
7035 : 836270416 : break;
7036 : : }
7037 : 836270416 : return false;
7038 : : }
7039 : :
7040 : : /* Return true if CODE represents a ternary tree code for which the
7041 : : first two operands are commutative. Otherwise return false. */
7042 : : bool
7043 : 74125572 : commutative_ternary_tree_code (enum tree_code code)
7044 : : {
7045 : 74125572 : switch (code)
7046 : : {
7047 : : case WIDEN_MULT_PLUS_EXPR:
7048 : : case WIDEN_MULT_MINUS_EXPR:
7049 : : case DOT_PROD_EXPR:
7050 : : return true;
7051 : :
7052 : 74120067 : default:
7053 : 74120067 : break;
7054 : : }
7055 : 74120067 : return false;
7056 : : }
7057 : :
7058 : : /* Returns true if CODE can overflow. */
7059 : :
7060 : : bool
7061 : 2956 : operation_can_overflow (enum tree_code code)
7062 : : {
7063 : 2956 : switch (code)
7064 : : {
7065 : : case PLUS_EXPR:
7066 : : case MINUS_EXPR:
7067 : : case MULT_EXPR:
7068 : : case LSHIFT_EXPR:
7069 : : /* Can overflow in various ways. */
7070 : : return true;
7071 : : case TRUNC_DIV_EXPR:
7072 : : case EXACT_DIV_EXPR:
7073 : : case FLOOR_DIV_EXPR:
7074 : : case CEIL_DIV_EXPR:
7075 : : /* For INT_MIN / -1. */
7076 : : return true;
7077 : : case NEGATE_EXPR:
7078 : : case ABS_EXPR:
7079 : : /* For -INT_MIN. */
7080 : : return true;
7081 : 141 : default:
7082 : : /* These operators cannot overflow. */
7083 : 141 : return false;
7084 : : }
7085 : : }
7086 : :
7087 : : /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
7088 : : ftrapv doesn't generate trapping insns for CODE. */
7089 : :
7090 : : bool
7091 : 5731379 : operation_no_trapping_overflow (tree type, enum tree_code code)
7092 : : {
7093 : 5731379 : gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type));
7094 : :
7095 : : /* We don't generate instructions that trap on overflow for complex or vector
7096 : : types. */
7097 : 5731379 : if (!INTEGRAL_TYPE_P (type))
7098 : : return true;
7099 : :
7100 : 5731379 : if (!TYPE_OVERFLOW_TRAPS (type))
7101 : : return true;
7102 : :
7103 : 439 : switch (code)
7104 : : {
7105 : : case PLUS_EXPR:
7106 : : case MINUS_EXPR:
7107 : : case MULT_EXPR:
7108 : : case NEGATE_EXPR:
7109 : : case ABS_EXPR:
7110 : : /* These operators can overflow, and -ftrapv generates trapping code for
7111 : : these. */
7112 : : return false;
7113 : : case TRUNC_DIV_EXPR:
7114 : : case EXACT_DIV_EXPR:
7115 : : case FLOOR_DIV_EXPR:
7116 : : case CEIL_DIV_EXPR:
7117 : : case LSHIFT_EXPR:
7118 : : /* These operators can overflow, but -ftrapv does not generate trapping
7119 : : code for these. */
7120 : : return true;
7121 : : default:
7122 : : /* These operators cannot overflow. */
7123 : : return true;
7124 : : }
7125 : : }
7126 : :
7127 : : /* Constructors for pointer, array and function types.
7128 : : (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7129 : : constructed by language-dependent code, not here.) */
7130 : :
7131 : : /* Construct, lay out and return the type of pointers to TO_TYPE with
7132 : : mode MODE. If MODE is VOIDmode, a pointer mode for the address
7133 : : space of TO_TYPE will be picked. If CAN_ALIAS_ALL is TRUE,
7134 : : indicate this type can reference all of memory. If such a type has
7135 : : already been constructed, reuse it. */
7136 : :
7137 : : tree
7138 : 2024804312 : build_pointer_type_for_mode (tree to_type, machine_mode mode,
7139 : : bool can_alias_all)
7140 : : {
7141 : 2024804312 : tree t;
7142 : 2024804312 : bool could_alias = can_alias_all;
7143 : :
7144 : 2024804312 : if (to_type == error_mark_node)
7145 : : return error_mark_node;
7146 : :
7147 : 2024804306 : if (mode == VOIDmode)
7148 : : {
7149 : 1907421749 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7150 : 1907421749 : mode = targetm.addr_space.pointer_mode (as);
7151 : : }
7152 : :
7153 : : /* If the pointed-to type has the may_alias attribute set, force
7154 : : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7155 : 2024804306 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7156 : 4321230 : can_alias_all = true;
7157 : :
7158 : : /* In some cases, languages will have things that aren't a POINTER_TYPE
7159 : : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7160 : : In that case, return that type without regard to the rest of our
7161 : : operands.
7162 : :
7163 : : ??? This is a kludge, but consistent with the way this function has
7164 : : always operated and there doesn't seem to be a good way to avoid this
7165 : : at the moment. */
7166 : 2024804306 : if (TYPE_POINTER_TO (to_type) != 0
7167 : 2024804306 : && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
7168 : 41427 : return TYPE_POINTER_TO (to_type);
7169 : :
7170 : : /* First, if we already have a type for pointers to TO_TYPE and it's
7171 : : the proper mode, use it. */
7172 : 2025313930 : for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
7173 : 1901951517 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7174 : : return t;
7175 : :
7176 : 123362413 : t = make_node (POINTER_TYPE);
7177 : :
7178 : 123362413 : TREE_TYPE (t) = to_type;
7179 : 123362413 : SET_TYPE_MODE (t, mode);
7180 : 123362413 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7181 : 123362413 : TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
7182 : 123362413 : TYPE_POINTER_TO (to_type) = t;
7183 : :
7184 : : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7185 : 123362413 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7186 : 5068450 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7187 : 118293963 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7188 : 36050801 : TYPE_CANONICAL (t)
7189 : 72101602 : = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
7190 : : mode, false);
7191 : :
7192 : : /* Lay out the type. This function has many callers that are concerned
7193 : : with expression-construction, and this simplifies them all. */
7194 : 123362413 : layout_type (t);
7195 : :
7196 : 123362413 : return t;
7197 : : }
7198 : :
7199 : : /* By default build pointers in ptr_mode. */
7200 : :
7201 : : tree
7202 : 1906740872 : build_pointer_type (tree to_type)
7203 : : {
7204 : 1906740872 : return build_pointer_type_for_mode (to_type, VOIDmode, false);
7205 : : }
7206 : :
7207 : : /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7208 : :
7209 : : tree
7210 : 514773187 : build_reference_type_for_mode (tree to_type, machine_mode mode,
7211 : : bool can_alias_all)
7212 : : {
7213 : 514773187 : tree t;
7214 : 514773187 : bool could_alias = can_alias_all;
7215 : :
7216 : 514773187 : if (to_type == error_mark_node)
7217 : : return error_mark_node;
7218 : :
7219 : 514773187 : if (mode == VOIDmode)
7220 : : {
7221 : 425657367 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7222 : 425657367 : mode = targetm.addr_space.pointer_mode (as);
7223 : : }
7224 : :
7225 : : /* If the pointed-to type has the may_alias attribute set, force
7226 : : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7227 : 514773187 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7228 : 681880 : can_alias_all = true;
7229 : :
7230 : : /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7231 : : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7232 : : In that case, return that type without regard to the rest of our
7233 : : operands.
7234 : :
7235 : : ??? This is a kludge, but consistent with the way this function has
7236 : : always operated and there doesn't seem to be a good way to avoid this
7237 : : at the moment. */
7238 : 514773187 : if (TYPE_REFERENCE_TO (to_type) != 0
7239 : 514773187 : && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
7240 : 0 : return TYPE_REFERENCE_TO (to_type);
7241 : :
7242 : : /* First, if we already have a type for pointers to TO_TYPE and it's
7243 : : the proper mode, use it. */
7244 : 514773187 : for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
7245 : 443040214 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7246 : : return t;
7247 : :
7248 : 71732973 : t = make_node (REFERENCE_TYPE);
7249 : :
7250 : 71732973 : TREE_TYPE (t) = to_type;
7251 : 71732973 : SET_TYPE_MODE (t, mode);
7252 : 71732973 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7253 : 71732973 : TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
7254 : 71732973 : TYPE_REFERENCE_TO (to_type) = t;
7255 : :
7256 : : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7257 : 71732973 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7258 : 3430190 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7259 : 68302783 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7260 : 40232950 : TYPE_CANONICAL (t)
7261 : 80465900 : = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
7262 : : mode, false);
7263 : :
7264 : 71732973 : layout_type (t);
7265 : :
7266 : 71732973 : return t;
7267 : : }
7268 : :
7269 : :
7270 : : /* Build the node for the type of references-to-TO_TYPE by default
7271 : : in ptr_mode. */
7272 : :
7273 : : tree
7274 : 20806239 : build_reference_type (tree to_type)
7275 : : {
7276 : 20806239 : return build_reference_type_for_mode (to_type, VOIDmode, false);
7277 : : }
7278 : :
7279 : : #define MAX_INT_CACHED_PREC \
7280 : : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7281 : : static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
7282 : :
7283 : : static void
7284 : 257941 : clear_nonstandard_integer_type_cache (void)
7285 : : {
7286 : 33790271 : for (size_t i = 0 ; i < 2 * MAX_INT_CACHED_PREC + 2 ; i++)
7287 : : {
7288 : 33532330 : nonstandard_integer_type_cache[i] = NULL;
7289 : : }
7290 : 0 : }
7291 : :
7292 : : /* Builds a signed or unsigned integer type of precision PRECISION.
7293 : : Used for C bitfields whose precision does not match that of
7294 : : built-in target types. */
7295 : : tree
7296 : 62620478 : build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
7297 : : int unsignedp)
7298 : : {
7299 : 62620478 : tree itype, ret;
7300 : :
7301 : 62620478 : if (unsignedp)
7302 : 54068411 : unsignedp = MAX_INT_CACHED_PREC + 1;
7303 : :
7304 : 62620478 : if (precision <= MAX_INT_CACHED_PREC)
7305 : : {
7306 : 62195039 : itype = nonstandard_integer_type_cache[precision + unsignedp];
7307 : 62195039 : if (itype)
7308 : : return itype;
7309 : : }
7310 : :
7311 : 1074209 : itype = make_node (INTEGER_TYPE);
7312 : 1074209 : TYPE_PRECISION (itype) = precision;
7313 : :
7314 : 1074209 : if (unsignedp)
7315 : 726332 : fixup_unsigned_type (itype);
7316 : : else
7317 : 347877 : fixup_signed_type (itype);
7318 : :
7319 : 1074209 : inchash::hash hstate;
7320 : 1074209 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7321 : 1074209 : ret = type_hash_canon (hstate.end (), itype);
7322 : 1074209 : if (precision <= MAX_INT_CACHED_PREC)
7323 : 648770 : nonstandard_integer_type_cache[precision + unsignedp] = ret;
7324 : :
7325 : : return ret;
7326 : : }
7327 : :
7328 : : #define MAX_BOOL_CACHED_PREC \
7329 : : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7330 : : static GTY(()) tree nonstandard_boolean_type_cache[MAX_BOOL_CACHED_PREC + 1];
7331 : :
7332 : : /* Builds a boolean type of precision PRECISION.
7333 : : Used for boolean vectors to choose proper vector element size. */
7334 : : tree
7335 : 1907156 : build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision)
7336 : : {
7337 : 1907156 : tree type;
7338 : :
7339 : 1907156 : if (precision <= MAX_BOOL_CACHED_PREC)
7340 : : {
7341 : 1902925 : type = nonstandard_boolean_type_cache[precision];
7342 : 1902925 : if (type)
7343 : : return type;
7344 : : }
7345 : :
7346 : 74684 : type = make_node (BOOLEAN_TYPE);
7347 : 74684 : TYPE_PRECISION (type) = precision;
7348 : 74684 : fixup_signed_type (type);
7349 : :
7350 : 74684 : if (precision <= MAX_INT_CACHED_PREC)
7351 : 70453 : nonstandard_boolean_type_cache[precision] = type;
7352 : :
7353 : : return type;
7354 : : }
7355 : :
7356 : : static GTY(()) vec<tree, va_gc> *bitint_type_cache;
7357 : :
7358 : : /* Builds a signed or unsigned _BitInt(PRECISION) type. */
7359 : : tree
7360 : 1528287 : build_bitint_type (unsigned HOST_WIDE_INT precision, int unsignedp)
7361 : : {
7362 : 1528287 : tree itype, ret;
7363 : :
7364 : 1562973 : gcc_checking_assert (precision >= 1 + !unsignedp);
7365 : :
7366 : 1528287 : if (unsignedp)
7367 : 34686 : unsignedp = MAX_INT_CACHED_PREC + 1;
7368 : :
7369 : 1528287 : if (bitint_type_cache == NULL)
7370 : 466 : vec_safe_grow_cleared (bitint_type_cache, 2 * MAX_INT_CACHED_PREC + 2);
7371 : :
7372 : 1528287 : if (precision <= MAX_INT_CACHED_PREC)
7373 : : {
7374 : 35799 : itype = (*bitint_type_cache)[precision + unsignedp];
7375 : 35799 : if (itype)
7376 : : return itype;
7377 : : }
7378 : :
7379 : 1493854 : itype = make_node (BITINT_TYPE);
7380 : 1493854 : TYPE_PRECISION (itype) = precision;
7381 : :
7382 : 1493854 : if (unsignedp)
7383 : 28364 : fixup_unsigned_type (itype);
7384 : : else
7385 : 1465490 : fixup_signed_type (itype);
7386 : :
7387 : 1493854 : inchash::hash hstate;
7388 : 1493854 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7389 : 1493854 : ret = type_hash_canon (hstate.end (), itype);
7390 : 1493854 : if (precision <= MAX_INT_CACHED_PREC)
7391 : 1366 : (*bitint_type_cache)[precision + unsignedp] = ret;
7392 : :
7393 : : return ret;
7394 : : }
7395 : :
7396 : : /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7397 : : or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7398 : : is true, reuse such a type that has already been constructed. */
7399 : :
7400 : : static tree
7401 : 37321679 : build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
7402 : : {
7403 : 37321679 : tree itype = make_node (INTEGER_TYPE);
7404 : :
7405 : 37321679 : TREE_TYPE (itype) = type;
7406 : :
7407 : 37321679 : TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
7408 : 37321679 : TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
7409 : :
7410 : 37321679 : TYPE_PRECISION (itype) = TYPE_PRECISION (type);
7411 : 37321679 : SET_TYPE_MODE (itype, TYPE_MODE (type));
7412 : 37321679 : TYPE_SIZE (itype) = TYPE_SIZE (type);
7413 : 37321679 : TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
7414 : 37321679 : SET_TYPE_ALIGN (itype, TYPE_ALIGN (type));
7415 : 37321679 : TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
7416 : 37321679 : SET_TYPE_WARN_IF_NOT_ALIGN (itype, TYPE_WARN_IF_NOT_ALIGN (type));
7417 : :
7418 : 37321679 : if (!shared)
7419 : : return itype;
7420 : :
7421 : 37321679 : if ((TYPE_MIN_VALUE (itype)
7422 : 37321679 : && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
7423 : 74642544 : || (TYPE_MAX_VALUE (itype)
7424 : 36780647 : && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
7425 : : {
7426 : : /* Since we cannot reliably merge this type, we need to compare it using
7427 : : structural equality checks. */
7428 : 917083 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
7429 : 917083 : return itype;
7430 : : }
7431 : :
7432 : 36404596 : hashval_t hash = type_hash_canon_hash (itype);
7433 : 36404596 : itype = type_hash_canon (hash, itype);
7434 : :
7435 : 36404596 : return itype;
7436 : : }
7437 : :
7438 : : /* Wrapper around build_range_type_1 with SHARED set to true. */
7439 : :
7440 : : tree
7441 : 37321679 : build_range_type (tree type, tree lowval, tree highval)
7442 : : {
7443 : 37321679 : return build_range_type_1 (type, lowval, highval, true);
7444 : : }
7445 : :
7446 : : /* Wrapper around build_range_type_1 with SHARED set to false. */
7447 : :
7448 : : tree
7449 : 0 : build_nonshared_range_type (tree type, tree lowval, tree highval)
7450 : : {
7451 : 0 : return build_range_type_1 (type, lowval, highval, false);
7452 : : }
7453 : :
7454 : : /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7455 : : MAXVAL should be the maximum value in the domain
7456 : : (one less than the length of the array).
7457 : :
7458 : : The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7459 : : We don't enforce this limit, that is up to caller (e.g. language front end).
7460 : : The limit exists because the result is a signed type and we don't handle
7461 : : sizes that use more than one HOST_WIDE_INT. */
7462 : :
7463 : : tree
7464 : 34911302 : build_index_type (tree maxval)
7465 : : {
7466 : 34911302 : return build_range_type (sizetype, size_zero_node, maxval);
7467 : : }
7468 : :
7469 : : /* Return true if the debug information for TYPE, a subtype, should be emitted
7470 : : as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7471 : : high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7472 : : debug info and doesn't reflect the source code. */
7473 : :
7474 : : bool
7475 : 18 : subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
7476 : : {
7477 : 18 : tree base_type = TREE_TYPE (type), low, high;
7478 : :
7479 : : /* Subrange types have a base type which is an integral type. */
7480 : 18 : if (!INTEGRAL_TYPE_P (base_type))
7481 : : return false;
7482 : :
7483 : : /* Get the real bounds of the subtype. */
7484 : 18 : if (lang_hooks.types.get_subrange_bounds)
7485 : 0 : lang_hooks.types.get_subrange_bounds (type, &low, &high);
7486 : : else
7487 : : {
7488 : 18 : low = TYPE_MIN_VALUE (type);
7489 : 18 : high = TYPE_MAX_VALUE (type);
7490 : : }
7491 : :
7492 : : /* If the type and its base type have the same representation and the same
7493 : : name, then the type is not a subrange but a copy of the base type. */
7494 : 18 : if ((TREE_CODE (base_type) == INTEGER_TYPE
7495 : 18 : || TREE_CODE (base_type) == BOOLEAN_TYPE)
7496 : 18 : && int_size_in_bytes (type) == int_size_in_bytes (base_type)
7497 : 18 : && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
7498 : 0 : && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))
7499 : 18 : && TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (base_type))
7500 : : return false;
7501 : :
7502 : 18 : if (lowval)
7503 : 18 : *lowval = low;
7504 : 18 : if (highval)
7505 : 18 : *highval = high;
7506 : : return true;
7507 : : }
7508 : :
7509 : : /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7510 : : and number of elements specified by the range of values of INDEX_TYPE.
7511 : : If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
7512 : : If SHARED is true, reuse such a type that has already been constructed.
7513 : : If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type. */
7514 : :
7515 : : tree
7516 : 59591013 : build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
7517 : : bool shared, bool set_canonical)
7518 : : {
7519 : 59591013 : tree t;
7520 : :
7521 : 59591013 : if (TREE_CODE (elt_type) == FUNCTION_TYPE)
7522 : : {
7523 : 0 : error ("arrays of functions are not meaningful");
7524 : 0 : elt_type = integer_type_node;
7525 : : }
7526 : :
7527 : 59591013 : t = make_node (ARRAY_TYPE);
7528 : 59591013 : TREE_TYPE (t) = elt_type;
7529 : 59591013 : TYPE_DOMAIN (t) = index_type;
7530 : 59591013 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
7531 : 59591013 : TYPE_TYPELESS_STORAGE (t) = typeless_storage;
7532 : :
7533 : : /* Set TYPE_STRUCTURAL_EQUALITY_P. */
7534 : 59591013 : if (set_canonical
7535 : 59591013 : && (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7536 : 59560043 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7537 : 59315710 : || in_lto_p))
7538 : 349283 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7539 : :
7540 : 59591013 : layout_type (t);
7541 : :
7542 : 59591013 : if (shared)
7543 : : {
7544 : 59590986 : hashval_t hash = type_hash_canon_hash (t);
7545 : 59590986 : tree probe_type = t;
7546 : 59590986 : t = type_hash_canon (hash, t);
7547 : 59590986 : if (t != probe_type)
7548 : : return t;
7549 : : }
7550 : :
7551 : 9846071 : if (TYPE_CANONICAL (t) == t && set_canonical)
7552 : : {
7553 : 9545912 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7554 : 9545912 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7555 : 19091824 : || in_lto_p)
7556 : 0 : gcc_unreachable ();
7557 : 9545912 : else if (TYPE_CANONICAL (elt_type) != elt_type
7558 : 9545912 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
7559 : 100168 : TYPE_CANONICAL (t)
7560 : 290432 : = build_array_type_1 (TYPE_CANONICAL (elt_type),
7561 : : index_type
7562 : 90096 : ? TYPE_CANONICAL (index_type) : NULL_TREE,
7563 : : typeless_storage, shared, set_canonical);
7564 : : }
7565 : :
7566 : : return t;
7567 : : }
7568 : :
7569 : : /* Wrapper around build_array_type_1 with SHARED set to true. */
7570 : :
7571 : : tree
7572 : 59490818 : build_array_type (tree elt_type, tree index_type, bool typeless_storage)
7573 : : {
7574 : 59490818 : return
7575 : 59490818 : build_array_type_1 (elt_type, index_type, typeless_storage, true, true);
7576 : : }
7577 : :
7578 : : /* Wrapper around build_array_type_1 with SHARED set to false. */
7579 : :
7580 : : tree
7581 : 0 : build_nonshared_array_type (tree elt_type, tree index_type)
7582 : : {
7583 : 0 : return build_array_type_1 (elt_type, index_type, false, false, true);
7584 : : }
7585 : :
7586 : : /* Return a representation of ELT_TYPE[NELTS], using indices of type
7587 : : sizetype. */
7588 : :
7589 : : tree
7590 : 1422411 : build_array_type_nelts (tree elt_type, poly_uint64 nelts)
7591 : : {
7592 : 1422411 : return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
7593 : : }
7594 : :
7595 : : /* Computes the canonical argument types from the argument type list
7596 : : ARGTYPES.
7597 : :
7598 : : Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7599 : : on entry to this function, or if any of the ARGTYPES are
7600 : : structural.
7601 : :
7602 : : Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7603 : : true on entry to this function, or if any of the ARGTYPES are
7604 : : non-canonical.
7605 : :
7606 : : Returns a canonical argument list, which may be ARGTYPES when the
7607 : : canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7608 : : true) or would not differ from ARGTYPES. */
7609 : :
7610 : : static tree
7611 : 868275919 : maybe_canonicalize_argtypes (tree argtypes,
7612 : : bool *any_structural_p,
7613 : : bool *any_noncanonical_p)
7614 : : {
7615 : 868275919 : tree arg;
7616 : 868275919 : bool any_noncanonical_argtypes_p = false;
7617 : :
7618 : 3042845407 : for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
7619 : : {
7620 : 2174569488 : if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
7621 : : /* Fail gracefully by stating that the type is structural. */
7622 : 3861 : *any_structural_p = true;
7623 : 2174565627 : else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
7624 : 32871372 : *any_structural_p = true;
7625 : 2141694255 : else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
7626 : 2141694255 : || TREE_PURPOSE (arg))
7627 : : /* If the argument has a default argument, we consider it
7628 : : non-canonical even though the type itself is canonical.
7629 : : That way, different variants of function and method types
7630 : : with default arguments will all point to the variant with
7631 : : no defaults as their canonical type. */
7632 : : any_noncanonical_argtypes_p = true;
7633 : : }
7634 : :
7635 : 868275919 : if (*any_structural_p)
7636 : : return argtypes;
7637 : :
7638 : 781422217 : if (any_noncanonical_argtypes_p)
7639 : : {
7640 : : /* Build the canonical list of argument types. */
7641 : : tree canon_argtypes = NULL_TREE;
7642 : : bool is_void = false;
7643 : :
7644 : 790266157 : for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
7645 : : {
7646 : 607923250 : if (arg == void_list_node)
7647 : : is_void = true;
7648 : : else
7649 : 853564782 : canon_argtypes = tree_cons (NULL_TREE,
7650 : 426782391 : TYPE_CANONICAL (TREE_VALUE (arg)),
7651 : : canon_argtypes);
7652 : : }
7653 : :
7654 : 182342907 : canon_argtypes = nreverse (canon_argtypes);
7655 : 182342907 : if (is_void)
7656 : 181140859 : canon_argtypes = chainon (canon_argtypes, void_list_node);
7657 : :
7658 : : /* There is a non-canonical type. */
7659 : 182342907 : *any_noncanonical_p = true;
7660 : 182342907 : return canon_argtypes;
7661 : : }
7662 : :
7663 : : /* The canonical argument types are the same as ARGTYPES. */
7664 : : return argtypes;
7665 : : }
7666 : :
7667 : : /* Construct, lay out and return
7668 : : the type of functions returning type VALUE_TYPE
7669 : : given arguments of types ARG_TYPES.
7670 : : ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7671 : : are data type nodes for the arguments of the function.
7672 : : NO_NAMED_ARGS_STDARG_P is true if this is a prototyped
7673 : : variable-arguments function with (...) prototype (no named arguments).
7674 : : If such a type has already been constructed, reuse it. */
7675 : :
7676 : : tree
7677 : 586929151 : build_function_type (tree value_type, tree arg_types,
7678 : : bool no_named_args_stdarg_p)
7679 : : {
7680 : 586929151 : tree t;
7681 : 586929151 : inchash::hash hstate;
7682 : 586929151 : bool any_structural_p, any_noncanonical_p;
7683 : 586929151 : tree canon_argtypes;
7684 : :
7685 : 586929151 : gcc_assert (arg_types != error_mark_node);
7686 : :
7687 : 586929151 : if (TREE_CODE (value_type) == FUNCTION_TYPE)
7688 : : {
7689 : 0 : error ("function return type cannot be function");
7690 : 0 : value_type = integer_type_node;
7691 : : }
7692 : :
7693 : : /* Make a node of the sort we want. */
7694 : 586929151 : t = make_node (FUNCTION_TYPE);
7695 : 586929151 : TREE_TYPE (t) = value_type;
7696 : 586929151 : TYPE_ARG_TYPES (t) = arg_types;
7697 : 586929151 : if (no_named_args_stdarg_p)
7698 : : {
7699 : 219362 : gcc_assert (arg_types == NULL_TREE);
7700 : 219362 : TYPE_NO_NAMED_ARGS_STDARG_P (t) = 1;
7701 : : }
7702 : :
7703 : : /* Set up the canonical type. */
7704 : 586929151 : any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
7705 : 586929151 : any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
7706 : 586929151 : canon_argtypes = maybe_canonicalize_argtypes (arg_types,
7707 : : &any_structural_p,
7708 : : &any_noncanonical_p);
7709 : : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7710 : 586929151 : if (any_structural_p)
7711 : 64283536 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7712 : :
7713 : : /* If we already have such a type, use the old one. */
7714 : 586929151 : hashval_t hash = type_hash_canon_hash (t);
7715 : 586929151 : tree probe_type = t;
7716 : 586929151 : t = type_hash_canon (hash, t);
7717 : 586929151 : if (t != probe_type)
7718 : : return t;
7719 : :
7720 : 384663336 : if (any_structural_p)
7721 : 52141066 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7722 : 332522270 : else if (any_noncanonical_p)
7723 : 75629134 : TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
7724 : : canon_argtypes);
7725 : :
7726 : 384663336 : if (!COMPLETE_TYPE_P (t))
7727 : 0 : layout_type (t);
7728 : : return t;
7729 : : }
7730 : :
7731 : : /* Build a function type. The RETURN_TYPE is the type returned by the
7732 : : function. If VAARGS is set, no void_type_node is appended to the
7733 : : list. ARGP must be always be terminated be a NULL_TREE. */
7734 : :
7735 : : static tree
7736 : 14599343 : build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
7737 : : {
7738 : 14599343 : tree t, args, last;
7739 : :
7740 : 14599343 : t = va_arg (argp, tree);
7741 : 61891061 : for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
7742 : 32692375 : args = tree_cons (NULL_TREE, t, args);
7743 : :
7744 : 14599343 : if (vaargs)
7745 : : {
7746 : 823719 : last = args;
7747 : 823719 : if (args != NULL_TREE)
7748 : 697360 : args = nreverse (args);
7749 : 823719 : gcc_assert (last != void_list_node);
7750 : : }
7751 : 13775624 : else if (args == NULL_TREE)
7752 : 1132957 : args = void_list_node;
7753 : : else
7754 : : {
7755 : 12642667 : last = args;
7756 : 12642667 : args = nreverse (args);
7757 : 12642667 : TREE_CHAIN (last) = void_list_node;
7758 : : }
7759 : 14599343 : args = build_function_type (return_type, args, vaargs && args == NULL_TREE);
7760 : :
7761 : 14599343 : return args;
7762 : : }
7763 : :
7764 : : /* Build a function type. The RETURN_TYPE is the type returned by the
7765 : : function. If additional arguments are provided, they are
7766 : : additional argument types. The list of argument types must always
7767 : : be terminated by NULL_TREE. */
7768 : :
7769 : : tree
7770 : 13775624 : build_function_type_list (tree return_type, ...)
7771 : : {
7772 : 13775624 : tree args;
7773 : 13775624 : va_list p;
7774 : :
7775 : 13775624 : va_start (p, return_type);
7776 : 13775624 : args = build_function_type_list_1 (false, return_type, p);
7777 : 13775624 : va_end (p);
7778 : 13775624 : return args;
7779 : : }
7780 : :
7781 : : /* Build a variable argument function type. The RETURN_TYPE is the
7782 : : type returned by the function. If additional arguments are provided,
7783 : : they are additional argument types. The list of argument types must
7784 : : always be terminated by NULL_TREE. */
7785 : :
7786 : : tree
7787 : 823719 : build_varargs_function_type_list (tree return_type, ...)
7788 : : {
7789 : 823719 : tree args;
7790 : 823719 : va_list p;
7791 : :
7792 : 823719 : va_start (p, return_type);
7793 : 823719 : args = build_function_type_list_1 (true, return_type, p);
7794 : 823719 : va_end (p);
7795 : :
7796 : 823719 : return args;
7797 : : }
7798 : :
7799 : : /* Build a function type. RETURN_TYPE is the type returned by the
7800 : : function; VAARGS indicates whether the function takes varargs. The
7801 : : function takes N named arguments, the types of which are provided in
7802 : : ARG_TYPES. */
7803 : :
7804 : : static tree
7805 : 115699587 : build_function_type_array_1 (bool vaargs, tree return_type, int n,
7806 : : tree *arg_types)
7807 : : {
7808 : 115699587 : int i;
7809 : 115699587 : tree t = vaargs ? NULL_TREE : void_list_node;
7810 : :
7811 : 379196784 : for (i = n - 1; i >= 0; i--)
7812 : 263497197 : t = tree_cons (NULL_TREE, arg_types[i], t);
7813 : :
7814 : 115699587 : return build_function_type (return_type, t, vaargs && n == 0);
7815 : : }
7816 : :
7817 : : /* Build a function type. RETURN_TYPE is the type returned by the
7818 : : function. The function takes N named arguments, the types of which
7819 : : are provided in ARG_TYPES. */
7820 : :
7821 : : tree
7822 : 109453107 : build_function_type_array (tree return_type, int n, tree *arg_types)
7823 : : {
7824 : 109453107 : return build_function_type_array_1 (false, return_type, n, arg_types);
7825 : : }
7826 : :
7827 : : /* Build a variable argument function type. RETURN_TYPE is the type
7828 : : returned by the function. The function takes N named arguments, the
7829 : : types of which are provided in ARG_TYPES. */
7830 : :
7831 : : tree
7832 : 6246480 : build_varargs_function_type_array (tree return_type, int n, tree *arg_types)
7833 : : {
7834 : 6246480 : return build_function_type_array_1 (true, return_type, n, arg_types);
7835 : : }
7836 : :
7837 : : /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7838 : : and ARGTYPES (a TREE_LIST) are the return type and arguments types
7839 : : for the method. An implicit additional parameter (of type
7840 : : pointer-to-BASETYPE) is added to the ARGTYPES. */
7841 : :
7842 : : tree
7843 : 281346768 : build_method_type_directly (tree basetype,
7844 : : tree rettype,
7845 : : tree argtypes)
7846 : : {
7847 : 281346768 : tree t;
7848 : 281346768 : tree ptype;
7849 : 281346768 : bool any_structural_p, any_noncanonical_p;
7850 : 281346768 : tree canon_argtypes;
7851 : :
7852 : : /* Make a node of the sort we want. */
7853 : 281346768 : t = make_node (METHOD_TYPE);
7854 : :
7855 : 281346768 : TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7856 : 281346768 : TREE_TYPE (t) = rettype;
7857 : 281346768 : ptype = build_pointer_type (basetype);
7858 : :
7859 : : /* The actual arglist for this function includes a "hidden" argument
7860 : : which is "this". Put it into the list of argument types. */
7861 : 281346768 : argtypes = tree_cons (NULL_TREE, ptype, argtypes);
7862 : 281346768 : TYPE_ARG_TYPES (t) = argtypes;
7863 : :
7864 : : /* Set up the canonical type. */
7865 : 281346768 : any_structural_p
7866 : 281346768 : = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7867 : 281346768 : || TYPE_STRUCTURAL_EQUALITY_P (rettype));
7868 : 281346768 : any_noncanonical_p
7869 : 281346768 : = (TYPE_CANONICAL (basetype) != basetype
7870 : 281346768 : || TYPE_CANONICAL (rettype) != rettype);
7871 : 281346768 : canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
7872 : : &any_structural_p,
7873 : : &any_noncanonical_p);
7874 : :
7875 : : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7876 : 281346768 : if (any_structural_p)
7877 : 22570166 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7878 : :
7879 : : /* If we already have such a type, use the old one. */
7880 : 281346768 : hashval_t hash = type_hash_canon_hash (t);
7881 : 281346768 : tree probe_type = t;
7882 : 281346768 : t = type_hash_canon (hash, t);
7883 : 281346768 : if (t != probe_type)
7884 : : return t;
7885 : :
7886 : 213945912 : if (any_structural_p)
7887 : 18721739 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7888 : 195224173 : else if (any_noncanonical_p)
7889 : 73076755 : TYPE_CANONICAL (t)
7890 : 146153510 : = build_method_type_directly (TYPE_CANONICAL (basetype),
7891 : 73076755 : TYPE_CANONICAL (rettype),
7892 : : canon_argtypes);
7893 : 213945912 : if (!COMPLETE_TYPE_P (t))
7894 : 0 : layout_type (t);
7895 : :
7896 : : return t;
7897 : : }
7898 : :
7899 : : /* Construct, lay out and return the type of methods belonging to class
7900 : : BASETYPE and whose arguments and values are described by TYPE.
7901 : : If that type exists already, reuse it.
7902 : : TYPE must be a FUNCTION_TYPE node. */
7903 : :
7904 : : tree
7905 : 155 : build_method_type (tree basetype, tree type)
7906 : : {
7907 : 155 : gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
7908 : :
7909 : 155 : return build_method_type_directly (basetype,
7910 : 155 : TREE_TYPE (type),
7911 : 155 : TYPE_ARG_TYPES (type));
7912 : : }
7913 : :
7914 : : /* Construct, lay out and return the type of offsets to a value
7915 : : of type TYPE, within an object of type BASETYPE.
7916 : : If a suitable offset type exists already, reuse it. */
7917 : :
7918 : : tree
7919 : 947822 : build_offset_type (tree basetype, tree type)
7920 : : {
7921 : 947822 : tree t;
7922 : :
7923 : : /* Make a node of the sort we want. */
7924 : 947822 : t = make_node (OFFSET_TYPE);
7925 : :
7926 : 947822 : TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7927 : 947822 : TREE_TYPE (t) = type;
7928 : 947822 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7929 : 947822 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7930 : 4 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7931 : :
7932 : : /* If we already have such a type, use the old one. */
7933 : 947822 : hashval_t hash = type_hash_canon_hash (t);
7934 : 947822 : tree probe_type = t;
7935 : 947822 : t = type_hash_canon (hash, t);
7936 : 947822 : if (t != probe_type)
7937 : : return t;
7938 : :
7939 : 193825 : if (!COMPLETE_TYPE_P (t))
7940 : 0 : layout_type (t);
7941 : :
7942 : 193825 : if (TYPE_CANONICAL (t) == t)
7943 : : {
7944 : 193821 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7945 : 193821 : || TYPE_STRUCTURAL_EQUALITY_P (type))
7946 : 0 : gcc_unreachable ();
7947 : 193821 : else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
7948 : 193821 : || TYPE_CANONICAL (type) != type)
7949 : 115410 : TYPE_CANONICAL (t)
7950 : 230820 : = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
7951 : 115410 : TYPE_CANONICAL (type));
7952 : : }
7953 : :
7954 : : return t;
7955 : : }
7956 : :
7957 : : /* Create a complex type whose components are COMPONENT_TYPE.
7958 : :
7959 : : If NAMED is true, the type is given a TYPE_NAME. We do not always
7960 : : do so because this creates a DECL node and thus make the DECL_UIDs
7961 : : dependent on the type canonicalization hashtable, which is GC-ed,
7962 : : so the DECL_UIDs would not be stable wrt garbage collection. */
7963 : :
7964 : : tree
7965 : 5152092 : build_complex_type (tree component_type, bool named)
7966 : : {
7967 : 5152092 : gcc_assert (INTEGRAL_TYPE_P (component_type)
7968 : : || SCALAR_FLOAT_TYPE_P (component_type)
7969 : : || FIXED_POINT_TYPE_P (component_type));
7970 : :
7971 : : /* Make a node of the sort we want. */
7972 : 5152092 : tree probe = make_node (COMPLEX_TYPE);
7973 : :
7974 : 5152092 : TREE_TYPE (probe) = TYPE_MAIN_VARIANT (component_type);
7975 : 5152092 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (probe)))
7976 : 0 : SET_TYPE_STRUCTURAL_EQUALITY (probe);
7977 : :
7978 : : /* If we already have such a type, use the old one. */
7979 : 5152092 : hashval_t hash = type_hash_canon_hash (probe);
7980 : 5152092 : tree t = type_hash_canon (hash, probe);
7981 : :
7982 : 5152092 : if (t == probe)
7983 : : {
7984 : : /* We created a new type. The hash insertion will have laid
7985 : : out the type. We need to check the canonicalization and
7986 : : maybe set the name. */
7987 : 3105741 : gcc_checking_assert (COMPLETE_TYPE_P (t)
7988 : : && !TYPE_NAME (t));
7989 : :
7990 : 3105741 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))
7991 : : ;
7992 : 3105741 : else if (TYPE_CANONICAL (TREE_TYPE (t)) != TREE_TYPE (t))
7993 : 99 : TYPE_CANONICAL (t)
7994 : 198 : = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named);
7995 : :
7996 : : /* We need to create a name, since complex is a fundamental type. */
7997 : 3105741 : if (named)
7998 : : {
7999 : 1145536 : const char *name = NULL;
8000 : :
8001 : 1145536 : if (TREE_TYPE (t) == char_type_node)
8002 : : name = "complex char";
8003 : 1145536 : else if (TREE_TYPE (t) == signed_char_type_node)
8004 : : name = "complex signed char";
8005 : 1145536 : else if (TREE_TYPE (t) == unsigned_char_type_node)
8006 : : name = "complex unsigned char";
8007 : 1145536 : else if (TREE_TYPE (t) == short_integer_type_node)
8008 : : name = "complex short int";
8009 : 1145536 : else if (TREE_TYPE (t) == short_unsigned_type_node)
8010 : : name = "complex short unsigned int";
8011 : 1145536 : else if (TREE_TYPE (t) == integer_type_node)
8012 : : name = "complex int";
8013 : 859152 : else if (TREE_TYPE (t) == unsigned_type_node)
8014 : : name = "complex unsigned int";
8015 : 859152 : else if (TREE_TYPE (t) == long_integer_type_node)
8016 : : name = "complex long int";
8017 : 859152 : else if (TREE_TYPE (t) == long_unsigned_type_node)
8018 : : name = "complex long unsigned int";
8019 : 859152 : else if (TREE_TYPE (t) == long_long_integer_type_node)
8020 : : name = "complex long long int";
8021 : 859152 : else if (TREE_TYPE (t) == long_long_unsigned_type_node)
8022 : : name = "complex long long unsigned int";
8023 : :
8024 : : if (name != NULL)
8025 : 286384 : TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
8026 : : get_identifier (name), t);
8027 : : }
8028 : : }
8029 : :
8030 : 5152092 : return build_qualified_type (t, TYPE_QUALS (component_type));
8031 : : }
8032 : :
8033 : : /* If TYPE is a real or complex floating-point type and the target
8034 : : does not directly support arithmetic on TYPE then return the wider
8035 : : type to be used for arithmetic on TYPE. Otherwise, return
8036 : : NULL_TREE. */
8037 : :
8038 : : tree
8039 : 90140112 : excess_precision_type (tree type)
8040 : : {
8041 : : /* The target can give two different responses to the question of
8042 : : which excess precision mode it would like depending on whether we
8043 : : are in -fexcess-precision=standard or -fexcess-precision=fast. */
8044 : :
8045 : 3269566 : enum excess_precision_type requested_type
8046 : 90140112 : = (flag_excess_precision == EXCESS_PRECISION_FAST
8047 : 90140112 : ? EXCESS_PRECISION_TYPE_FAST
8048 : : : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
8049 : 3269635 : ? EXCESS_PRECISION_TYPE_FLOAT16 : EXCESS_PRECISION_TYPE_STANDARD));
8050 : :
8051 : 90140112 : enum flt_eval_method target_flt_eval_method
8052 : 90140112 : = targetm.c.excess_precision (requested_type);
8053 : :
8054 : : /* The target should not ask for unpredictable float evaluation (though
8055 : : it might advertise that implicitly the evaluation is unpredictable,
8056 : : but we don't care about that here, it will have been reported
8057 : : elsewhere). If it does ask for unpredictable evaluation, we have
8058 : : nothing to do here. */
8059 : 90140112 : gcc_assert (target_flt_eval_method != FLT_EVAL_METHOD_UNPREDICTABLE);
8060 : :
8061 : : /* Nothing to do. The target has asked for all types we know about
8062 : : to be computed with their native precision and range. */
8063 : 90140112 : if (target_flt_eval_method == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
8064 : : return NULL_TREE;
8065 : :
8066 : : /* The target will promote this type in a target-dependent way, so excess
8067 : : precision ought to leave it alone. */
8068 : 88756318 : if (targetm.promoted_type (type) != NULL_TREE)
8069 : : return NULL_TREE;
8070 : :
8071 : 88756318 : machine_mode float16_type_mode = (float16_type_node
8072 : 88756318 : ? TYPE_MODE (float16_type_node)
8073 : 88756318 : : VOIDmode);
8074 : 88756318 : machine_mode bfloat16_type_mode = (bfloat16_type_node
8075 : 88756318 : ? TYPE_MODE (bfloat16_type_node)
8076 : 88756318 : : VOIDmode);
8077 : 88756318 : machine_mode float_type_mode = TYPE_MODE (float_type_node);
8078 : 88756318 : machine_mode double_type_mode = TYPE_MODE (double_type_node);
8079 : :
8080 : 88756318 : switch (TREE_CODE (type))
8081 : : {
8082 : 61471246 : case REAL_TYPE:
8083 : 61471246 : {
8084 : 61471246 : machine_mode type_mode = TYPE_MODE (type);
8085 : 61471246 : switch (target_flt_eval_method)
8086 : : {
8087 : 61458413 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8088 : 61458413 : if (type_mode == float16_type_mode
8089 : 61458413 : || type_mode == bfloat16_type_mode)
8090 : 283143 : return float_type_node;
8091 : : break;
8092 : 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8093 : 0 : if (type_mode == float16_type_mode
8094 : 0 : || type_mode == bfloat16_type_mode
8095 : 0 : || type_mode == float_type_mode)
8096 : 0 : return double_type_node;
8097 : : break;
8098 : 12833 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8099 : 12833 : if (type_mode == float16_type_mode
8100 : 12833 : || type_mode == bfloat16_type_mode
8101 : 12828 : || type_mode == float_type_mode
8102 : 12828 : || type_mode == double_type_mode)
8103 : 12384 : return long_double_type_node;
8104 : : break;
8105 : 0 : default:
8106 : 0 : gcc_unreachable ();
8107 : : }
8108 : : break;
8109 : : }
8110 : 384542 : case COMPLEX_TYPE:
8111 : 384542 : {
8112 : 384542 : if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
8113 : : return NULL_TREE;
8114 : 375062 : machine_mode type_mode = TYPE_MODE (TREE_TYPE (type));
8115 : 375062 : switch (target_flt_eval_method)
8116 : : {
8117 : 374729 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8118 : 374729 : if (type_mode == float16_type_mode
8119 : 374729 : || type_mode == bfloat16_type_mode)
8120 : 271 : return complex_float_type_node;
8121 : : break;
8122 : 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8123 : 0 : if (type_mode == float16_type_mode
8124 : 0 : || type_mode == bfloat16_type_mode
8125 : 0 : || type_mode == float_type_mode)
8126 : 0 : return complex_double_type_node;
8127 : : break;
8128 : 333 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8129 : 333 : if (type_mode == float16_type_mode
8130 : 333 : || type_mode == bfloat16_type_mode
8131 : 333 : || type_mode == float_type_mode
8132 : 333 : || type_mode == double_type_mode)
8133 : 281 : return complex_long_double_type_node;
8134 : : break;
8135 : 0 : default:
8136 : 0 : gcc_unreachable ();
8137 : : }
8138 : : break;
8139 : : }
8140 : : default:
8141 : : break;
8142 : : }
8143 : :
8144 : : return NULL_TREE;
8145 : : }
8146 : :
8147 : : /* Return OP, stripped of any conversions to wider types as much as is safe.
8148 : : Converting the value back to OP's type makes a value equivalent to OP.
8149 : :
8150 : : If FOR_TYPE is nonzero, we return a value which, if converted to
8151 : : type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8152 : :
8153 : : OP must have integer, real or enumeral type. Pointers are not allowed!
8154 : :
8155 : : There are some cases where the obvious value we could return
8156 : : would regenerate to OP if converted to OP's type,
8157 : : but would not extend like OP to wider types.
8158 : : If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8159 : : For example, if OP is (unsigned short)(signed char)-1,
8160 : : we avoid returning (signed char)-1 if FOR_TYPE is int,
8161 : : even though extending that to an unsigned short would regenerate OP,
8162 : : since the result of extending (signed char)-1 to (int)
8163 : : is different from (int) OP. */
8164 : :
8165 : : tree
8166 : 10436607 : get_unwidened (tree op, tree for_type)
8167 : : {
8168 : : /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8169 : 10436607 : tree type = TREE_TYPE (op);
8170 : 10436607 : unsigned final_prec
8171 : 18010863 : = TYPE_PRECISION (for_type != 0 ? for_type : type);
8172 : 10436607 : int uns
8173 : 10436607 : = (for_type != 0 && for_type != type
8174 : 2550198 : && final_prec > TYPE_PRECISION (type)
8175 : 10503361 : && TYPE_UNSIGNED (type));
8176 : 10436607 : tree win = op;
8177 : :
8178 : 10648981 : while (CONVERT_EXPR_P (op))
8179 : : {
8180 : 212403 : int bitschange;
8181 : :
8182 : : /* TYPE_PRECISION on vector types has different meaning
8183 : : (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8184 : : so avoid them here. */
8185 : 212403 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
8186 : : break;
8187 : :
8188 : 212403 : bitschange = TYPE_PRECISION (TREE_TYPE (op))
8189 : 212403 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
8190 : :
8191 : : /* Truncations are many-one so cannot be removed.
8192 : : Unless we are later going to truncate down even farther. */
8193 : 212403 : if (bitschange < 0
8194 : 212403 : && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
8195 : : break;
8196 : :
8197 : : /* See what's inside this conversion. If we decide to strip it,
8198 : : we will set WIN. */
8199 : 212374 : op = TREE_OPERAND (op, 0);
8200 : :
8201 : : /* If we have not stripped any zero-extensions (uns is 0),
8202 : : we can strip any kind of extension.
8203 : : If we have previously stripped a zero-extension,
8204 : : only zero-extensions can safely be stripped.
8205 : : Any extension can be stripped if the bits it would produce
8206 : : are all going to be discarded later by truncating to FOR_TYPE. */
8207 : :
8208 : 212374 : if (bitschange > 0)
8209 : : {
8210 : 124307 : if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
8211 : : win = op;
8212 : : /* TYPE_UNSIGNED says whether this is a zero-extension.
8213 : : Let's avoid computing it if it does not affect WIN
8214 : : and if UNS will not be needed again. */
8215 : 124307 : if ((uns
8216 : 124276 : || CONVERT_EXPR_P (op))
8217 : 124848 : && TYPE_UNSIGNED (TREE_TYPE (op)))
8218 : : {
8219 : : uns = 1;
8220 : : win = op;
8221 : : }
8222 : : }
8223 : : }
8224 : :
8225 : : /* If we finally reach a constant see if it fits in sth smaller and
8226 : : in that case convert it. */
8227 : 10436607 : if (TREE_CODE (win) == INTEGER_CST)
8228 : : {
8229 : 450200 : tree wtype = TREE_TYPE (win);
8230 : 450200 : unsigned prec = wi::min_precision (wi::to_wide (win), TYPE_SIGN (wtype));
8231 : 450200 : if (for_type)
8232 : 445614 : prec = MAX (prec, final_prec);
8233 : 450200 : if (prec < TYPE_PRECISION (wtype))
8234 : : {
8235 : 444193 : tree t = lang_hooks.types.type_for_size (prec, TYPE_UNSIGNED (wtype));
8236 : 444193 : if (t && TYPE_PRECISION (t) < TYPE_PRECISION (wtype))
8237 : 438708 : win = fold_convert (t, win);
8238 : : }
8239 : : }
8240 : :
8241 : 10436607 : return win;
8242 : : }
8243 : :
8244 : : /* Return OP or a simpler expression for a narrower value
8245 : : which can be sign-extended or zero-extended to give back OP.
8246 : : Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8247 : : or 0 if the value should be sign-extended. */
8248 : :
8249 : : tree
8250 : 64327519 : get_narrower (tree op, int *unsignedp_ptr)
8251 : : {
8252 : 64327519 : int uns = 0;
8253 : 64327519 : bool first = true;
8254 : 64327519 : tree win = op;
8255 : 64327519 : bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
8256 : :
8257 : 64327519 : if (TREE_CODE (op) == COMPOUND_EXPR)
8258 : : {
8259 : 81612 : do
8260 : 81612 : op = TREE_OPERAND (op, 1);
8261 : 81612 : while (TREE_CODE (op) == COMPOUND_EXPR);
8262 : 81597 : tree ret = get_narrower (op, unsignedp_ptr);
8263 : 81597 : if (ret == op)
8264 : : return win;
8265 : 4264 : auto_vec <tree, 16> v;
8266 : 4264 : unsigned int i;
8267 : 8535 : for (op = win; TREE_CODE (op) == COMPOUND_EXPR;
8268 : 4271 : op = TREE_OPERAND (op, 1))
8269 : 4271 : v.safe_push (op);
8270 : 12799 : FOR_EACH_VEC_ELT_REVERSE (v, i, op)
8271 : 4271 : ret = build2_loc (EXPR_LOCATION (op), COMPOUND_EXPR,
8272 : 4271 : TREE_TYPE (ret), TREE_OPERAND (op, 0),
8273 : : ret);
8274 : 4264 : return ret;
8275 : 4264 : }
8276 : 76666995 : while (TREE_CODE (op) == NOP_EXPR)
8277 : : {
8278 : 12454493 : int bitschange
8279 : 12454493 : = (TYPE_PRECISION (TREE_TYPE (op))
8280 : 12454493 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
8281 : :
8282 : : /* Truncations are many-one so cannot be removed. */
8283 : 12454493 : if (bitschange < 0)
8284 : : break;
8285 : :
8286 : : /* See what's inside this conversion. If we decide to strip it,
8287 : : we will set WIN. */
8288 : :
8289 : 12421169 : if (bitschange > 0)
8290 : : {
8291 : 3013828 : op = TREE_OPERAND (op, 0);
8292 : : /* An extension: the outermost one can be stripped,
8293 : : but remember whether it is zero or sign extension. */
8294 : 3013828 : if (first)
8295 : 3010873 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8296 : : /* Otherwise, if a sign extension has been stripped,
8297 : : only sign extensions can now be stripped;
8298 : : if a zero extension has been stripped, only zero-extensions. */
8299 : 2955 : else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
8300 : : break;
8301 : : first = false;
8302 : : }
8303 : : else /* bitschange == 0 */
8304 : : {
8305 : : /* A change in nominal type can always be stripped, but we must
8306 : : preserve the unsignedness. */
8307 : 9407341 : if (first)
8308 : 8869988 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8309 : 9407341 : first = false;
8310 : 9407341 : op = TREE_OPERAND (op, 0);
8311 : : /* Keep trying to narrow, but don't assign op to win if it
8312 : : would turn an integral type into something else. */
8313 : 17059910 : if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
8314 : 100942 : continue;
8315 : : }
8316 : :
8317 : 12320131 : win = op;
8318 : : }
8319 : :
8320 : 64245922 : if (TREE_CODE (op) == COMPONENT_REF
8321 : : /* Since type_for_size always gives an integer type. */
8322 : 2331467 : && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
8323 : 2228964 : && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
8324 : : /* Ensure field is laid out already. */
8325 : 2228964 : && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
8326 : 66474883 : && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op, 1))))
8327 : : {
8328 : 2228961 : unsigned HOST_WIDE_INT innerprec
8329 : 2228961 : = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op, 1)));
8330 : 2228961 : int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
8331 : 2228961 : || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
8332 : 2228961 : tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
8333 : :
8334 : : /* We can get this structure field in a narrower type that fits it,
8335 : : but the resulting extension to its nominal type (a fullword type)
8336 : : must satisfy the same conditions as for other extensions.
8337 : :
8338 : : Do this only for fields that are aligned (not bit-fields),
8339 : : because when bit-field insns will be used there is no
8340 : : advantage in doing this. */
8341 : :
8342 : 2228961 : if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
8343 : 0 : && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
8344 : 0 : && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
8345 : 2228961 : && type != 0)
8346 : : {
8347 : 0 : if (first)
8348 : 0 : uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
8349 : 0 : win = fold_convert (type, op);
8350 : : }
8351 : : }
8352 : :
8353 : 64245922 : *unsignedp_ptr = uns;
8354 : 64245922 : return win;
8355 : : }
8356 : :
8357 : : /* Return true if integer constant C has a value that is permissible
8358 : : for TYPE, an integral type. */
8359 : :
8360 : : bool
8361 : 116242456 : int_fits_type_p (const_tree c, const_tree type)
8362 : : {
8363 : 116242456 : tree type_low_bound, type_high_bound;
8364 : 116242456 : bool ok_for_low_bound, ok_for_high_bound;
8365 : 116242456 : signop sgn_c = TYPE_SIGN (TREE_TYPE (c));
8366 : :
8367 : : /* Non-standard boolean types can have arbitrary precision but various
8368 : : transformations assume that they can only take values 0 and +/-1. */
8369 : 116242456 : if (TREE_CODE (type) == BOOLEAN_TYPE)
8370 : 1038920 : return wi::fits_to_boolean_p (wi::to_wide (c), type);
8371 : :
8372 : 115203536 : retry:
8373 : 115215371 : type_low_bound = TYPE_MIN_VALUE (type);
8374 : 115215371 : type_high_bound = TYPE_MAX_VALUE (type);
8375 : :
8376 : : /* If at least one bound of the type is a constant integer, we can check
8377 : : ourselves and maybe make a decision. If no such decision is possible, but
8378 : : this type is a subtype, try checking against that. Otherwise, use
8379 : : fits_to_tree_p, which checks against the precision.
8380 : :
8381 : : Compute the status for each possibly constant bound, and return if we see
8382 : : one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8383 : : for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8384 : : for "constant known to fit". */
8385 : :
8386 : : /* Check if c >= type_low_bound. */
8387 : 115215371 : if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
8388 : : {
8389 : 115215371 : if (tree_int_cst_lt (c, type_low_bound))
8390 : : return false;
8391 : : ok_for_low_bound = true;
8392 : : }
8393 : : else
8394 : : ok_for_low_bound = false;
8395 : :
8396 : : /* Check if c <= type_high_bound. */
8397 : 114974693 : if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
8398 : : {
8399 : 114943226 : if (tree_int_cst_lt (type_high_bound, c))
8400 : : return false;
8401 : : ok_for_high_bound = true;
8402 : : }
8403 : : else
8404 : : ok_for_high_bound = false;
8405 : :
8406 : : /* If the constant fits both bounds, the result is known. */
8407 : 113265180 : if (ok_for_low_bound && ok_for_high_bound)
8408 : : return true;
8409 : :
8410 : : /* Perform some generic filtering which may allow making a decision
8411 : : even if the bounds are not constant. First, negative integers
8412 : : never fit in unsigned types, */
8413 : 31467 : if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (wi::to_wide (c)))
8414 : 0 : return false;
8415 : :
8416 : : /* Second, narrower types always fit in wider ones. */
8417 : 31467 : if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
8418 : : return true;
8419 : :
8420 : : /* Third, unsigned integers with top bit set never fit signed types. */
8421 : 11844 : if (!TYPE_UNSIGNED (type) && sgn_c == UNSIGNED)
8422 : : {
8423 : 14 : int prec = GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (c))) - 1;
8424 : 14 : if (prec < TYPE_PRECISION (TREE_TYPE (c)))
8425 : : {
8426 : : /* When a tree_cst is converted to a wide-int, the precision
8427 : : is taken from the type. However, if the precision of the
8428 : : mode underneath the type is smaller than that, it is
8429 : : possible that the value will not fit. The test below
8430 : : fails if any bit is set between the sign bit of the
8431 : : underlying mode and the top bit of the type. */
8432 : 14 : if (wi::zext (wi::to_wide (c), prec - 1) != wi::to_wide (c))
8433 : : return false;
8434 : : }
8435 : 0 : else if (wi::neg_p (wi::to_wide (c)))
8436 : : return false;
8437 : : }
8438 : :
8439 : : /* If we haven't been able to decide at this point, there nothing more we
8440 : : can check ourselves here. Look at the base type if we have one and it
8441 : : has the same precision. */
8442 : 11835 : if (TREE_CODE (type) == INTEGER_TYPE
8443 : 11835 : && TREE_TYPE (type) != 0
8444 : 23670 : && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
8445 : : {
8446 : 11835 : type = TREE_TYPE (type);
8447 : 11835 : goto retry;
8448 : : }
8449 : :
8450 : : /* Or to fits_to_tree_p, if nothing else. */
8451 : 0 : return wi::fits_to_tree_p (wi::to_wide (c), type);
8452 : : }
8453 : :
8454 : : /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8455 : : bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8456 : : represented (assuming two's-complement arithmetic) within the bit
8457 : : precision of the type are returned instead. */
8458 : :
8459 : : void
8460 : 20830065 : get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
8461 : : {
8462 : 19398875 : if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
8463 : 40228940 : && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
8464 : 19398875 : wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type)), min, TYPE_SIGN (type));
8465 : : else
8466 : : {
8467 : 1431190 : if (TYPE_UNSIGNED (type))
8468 : 1431190 : mpz_set_ui (min, 0);
8469 : : else
8470 : : {
8471 : 0 : wide_int mn = wi::min_value (TYPE_PRECISION (type), SIGNED);
8472 : 0 : wi::to_mpz (mn, min, SIGNED);
8473 : 0 : }
8474 : : }
8475 : :
8476 : 19398875 : if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
8477 : 40228940 : && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
8478 : 19398875 : wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type)), max, TYPE_SIGN (type));
8479 : : else
8480 : : {
8481 : 1431190 : wide_int mn = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
8482 : 1431190 : wi::to_mpz (mn, max, TYPE_SIGN (type));
8483 : 1431190 : }
8484 : 20830065 : }
8485 : :
8486 : : /* Return true if VAR is an automatic variable. */
8487 : :
8488 : : bool
8489 : 365451573 : auto_var_p (const_tree var)
8490 : : {
8491 : 199676374 : return ((((VAR_P (var) && ! DECL_EXTERNAL (var))
8492 : 169114592 : || TREE_CODE (var) == PARM_DECL)
8493 : 259382928 : && ! TREE_STATIC (var))
8494 : 479845632 : || TREE_CODE (var) == RESULT_DECL);
8495 : : }
8496 : :
8497 : : /* Return true if VAR is an automatic variable defined in function FN. */
8498 : :
8499 : : bool
8500 : 1076548034 : auto_var_in_fn_p (const_tree var, const_tree fn)
8501 : : {
8502 : 337035477 : return (DECL_P (var) && DECL_CONTEXT (var) == fn
8503 : 1319131894 : && (auto_var_p (var)
8504 : 4211203 : || TREE_CODE (var) == LABEL_DECL));
8505 : : }
8506 : :
8507 : : /* Subprogram of following function. Called by walk_tree.
8508 : :
8509 : : Return *TP if it is an automatic variable or parameter of the
8510 : : function passed in as DATA. */
8511 : :
8512 : : static tree
8513 : 120744 : find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
8514 : : {
8515 : 120744 : tree fn = (tree) data;
8516 : :
8517 : 120744 : if (TYPE_P (*tp))
8518 : 0 : *walk_subtrees = 0;
8519 : :
8520 : 120744 : else if (DECL_P (*tp)
8521 : 120744 : && auto_var_in_fn_p (*tp, fn))
8522 : 112084 : return *tp;
8523 : :
8524 : : return NULL_TREE;
8525 : : }
8526 : :
8527 : : /* Returns true if T is, contains, or refers to a type with variable
8528 : : size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8529 : : arguments, but not the return type. If FN is nonzero, only return
8530 : : true if a modifier of the type or position of FN is a variable or
8531 : : parameter inside FN.
8532 : :
8533 : : This concept is more general than that of C99 'variably modified types':
8534 : : in C99, a struct type is never variably modified because a VLA may not
8535 : : appear as a structure member. However, in GNU C code like:
8536 : :
8537 : : struct S { int i[f()]; };
8538 : :
8539 : : is valid, and other languages may define similar constructs. */
8540 : :
8541 : : bool
8542 : 1751282126 : variably_modified_type_p (tree type, tree fn)
8543 : : {
8544 : 1751282126 : tree t;
8545 : :
8546 : : /* Test if T is either variable (if FN is zero) or an expression containing
8547 : : a variable in FN. If TYPE isn't gimplified, return true also if
8548 : : gimplify_one_sizepos would gimplify the expression into a local
8549 : : variable. */
8550 : : #define RETURN_TRUE_IF_VAR(T) \
8551 : : do { tree _t = (T); \
8552 : : if (_t != NULL_TREE \
8553 : : && _t != error_mark_node \
8554 : : && !CONSTANT_CLASS_P (_t) \
8555 : : && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8556 : : && (!fn \
8557 : : || (!TYPE_SIZES_GIMPLIFIED (type) \
8558 : : && (TREE_CODE (_t) != VAR_DECL \
8559 : : && !CONTAINS_PLACEHOLDER_P (_t))) \
8560 : : || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8561 : : return true; } while (0)
8562 : :
8563 : 1751282126 : if (type == error_mark_node)
8564 : : return false;
8565 : :
8566 : : /* If TYPE itself has variable size, it is variably modified. */
8567 : 1751045077 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
8568 : 1750923193 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
8569 : :
8570 : 1750922569 : switch (TREE_CODE (type))
8571 : : {
8572 : 490122458 : case POINTER_TYPE:
8573 : 490122458 : case REFERENCE_TYPE:
8574 : 490122458 : case VECTOR_TYPE:
8575 : : /* Ada can have pointer types refering to themselves indirectly. */
8576 : 490122458 : if (TREE_VISITED (type))
8577 : : return false;
8578 : 490122458 : TREE_VISITED (type) = true;
8579 : 490122458 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8580 : : {
8581 : 76968 : TREE_VISITED (type) = false;
8582 : 76968 : return true;
8583 : : }
8584 : 490045490 : TREE_VISITED (type) = false;
8585 : 490045490 : break;
8586 : :
8587 : 85589087 : case FUNCTION_TYPE:
8588 : 85589087 : case METHOD_TYPE:
8589 : : /* If TYPE is a function type, it is variably modified if the
8590 : : return type is variably modified. */
8591 : 85589087 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8592 : : return true;
8593 : : break;
8594 : :
8595 : 417120791 : case INTEGER_TYPE:
8596 : 417120791 : case REAL_TYPE:
8597 : 417120791 : case FIXED_POINT_TYPE:
8598 : 417120791 : case ENUMERAL_TYPE:
8599 : 417120791 : case BOOLEAN_TYPE:
8600 : : /* Scalar types are variably modified if their end points
8601 : : aren't constant. */
8602 : 417120791 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
8603 : 417120791 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
8604 : 417087119 : break;
8605 : :
8606 : 621838489 : case RECORD_TYPE:
8607 : 621838489 : case UNION_TYPE:
8608 : 621838489 : case QUAL_UNION_TYPE:
8609 : : /* We can't see if any of the fields are variably-modified by the
8610 : : definition we normally use, since that would produce infinite
8611 : : recursion via pointers. */
8612 : : /* This is variably modified if some field's type is. */
8613 : 28702085528 : for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
8614 : 28080247039 : if (TREE_CODE (t) == FIELD_DECL)
8615 : : {
8616 : 952641923 : RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
8617 : 952641923 : RETURN_TRUE_IF_VAR (DECL_SIZE (t));
8618 : 952641923 : RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
8619 : :
8620 : : /* If the type is a qualified union, then the DECL_QUALIFIER
8621 : : of fields can also be an expression containing a variable. */
8622 : 952641923 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
8623 : 0 : RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
8624 : :
8625 : : /* If the field is a qualified union, then it's only a container
8626 : : for what's inside so we look into it. That's necessary in LTO
8627 : : mode because the sizes of the field tested above have been set
8628 : : to PLACEHOLDER_EXPRs by free_lang_data. */
8629 : 952641923 : if (TREE_CODE (TREE_TYPE (t)) == QUAL_UNION_TYPE
8630 : 952641923 : && variably_modified_type_p (TREE_TYPE (t), fn))
8631 : : return true;
8632 : : }
8633 : : break;
8634 : :
8635 : 11146766 : case ARRAY_TYPE:
8636 : : /* Do not call ourselves to avoid infinite recursion. This is
8637 : : variably modified if the element type is. */
8638 : 11146766 : RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
8639 : 11143245 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
8640 : 11143227 : break;
8641 : :
8642 : : default:
8643 : : break;
8644 : : }
8645 : :
8646 : : /* The current language may have other cases to check, but in general,
8647 : : all other types are not variably modified. */
8648 : 1750808160 : return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
8649 : :
8650 : : #undef RETURN_TRUE_IF_VAR
8651 : : }
8652 : :
8653 : : /* Given a DECL or TYPE, return the scope in which it was declared, or
8654 : : NULL_TREE if there is no containing scope. */
8655 : :
8656 : : tree
8657 : 2302609385 : get_containing_scope (const_tree t)
8658 : : {
8659 : 2302609385 : return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8660 : : }
8661 : :
8662 : : /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
8663 : :
8664 : : const_tree
8665 : 13271 : get_ultimate_context (const_tree decl)
8666 : : {
8667 : 35775 : while (decl && TREE_CODE (decl) != TRANSLATION_UNIT_DECL)
8668 : : {
8669 : 22504 : if (TREE_CODE (decl) == BLOCK)
8670 : 0 : decl = BLOCK_SUPERCONTEXT (decl);
8671 : : else
8672 : 22504 : decl = get_containing_scope (decl);
8673 : : }
8674 : 13271 : return decl;
8675 : : }
8676 : :
8677 : : /* Return the innermost context enclosing DECL that is
8678 : : a FUNCTION_DECL, or zero if none. */
8679 : :
8680 : : tree
8681 : 1261606432 : decl_function_context (const_tree decl)
8682 : : {
8683 : 1261606432 : tree context;
8684 : :
8685 : 1261606432 : if (TREE_CODE (decl) == ERROR_MARK)
8686 : : return 0;
8687 : :
8688 : : /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8689 : : where we look up the function at runtime. Such functions always take
8690 : : a first argument of type 'pointer to real context'.
8691 : :
8692 : : C++ should really be fixed to use DECL_CONTEXT for the real context,
8693 : : and use something else for the "virtual context". */
8694 : 1261606432 : else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
8695 : 4116921 : context
8696 : 4116921 : = TYPE_MAIN_VARIANT
8697 : : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8698 : : else
8699 : 1257489511 : context = DECL_CONTEXT (decl);
8700 : :
8701 : 2864184408 : while (context && TREE_CODE (context) != FUNCTION_DECL)
8702 : : {
8703 : 1602577976 : if (TREE_CODE (context) == BLOCK)
8704 : 0 : context = BLOCK_SUPERCONTEXT (context);
8705 : : else
8706 : 1602577976 : context = get_containing_scope (context);
8707 : : }
8708 : :
8709 : : return context;
8710 : : }
8711 : :
8712 : : /* Return the innermost context enclosing DECL that is
8713 : : a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8714 : : TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8715 : :
8716 : : tree
8717 : 52285425 : decl_type_context (const_tree decl)
8718 : : {
8719 : 52285425 : tree context = DECL_CONTEXT (decl);
8720 : :
8721 : 54740611 : while (context)
8722 : 49148982 : switch (TREE_CODE (context))
8723 : : {
8724 : : case NAMESPACE_DECL:
8725 : : case TRANSLATION_UNIT_DECL:
8726 : : return NULL_TREE;
8727 : :
8728 : : case RECORD_TYPE:
8729 : : case UNION_TYPE:
8730 : : case QUAL_UNION_TYPE:
8731 : : return context;
8732 : :
8733 : 2455186 : case TYPE_DECL:
8734 : 2455186 : case FUNCTION_DECL:
8735 : 2455186 : context = DECL_CONTEXT (context);
8736 : 2455186 : break;
8737 : :
8738 : 0 : case BLOCK:
8739 : 0 : context = BLOCK_SUPERCONTEXT (context);
8740 : 0 : break;
8741 : :
8742 : 0 : default:
8743 : 0 : gcc_unreachable ();
8744 : : }
8745 : :
8746 : : return NULL_TREE;
8747 : : }
8748 : :
8749 : : /* CALL is a CALL_EXPR. Return the declaration for the function
8750 : : called, or NULL_TREE if the called function cannot be
8751 : : determined. */
8752 : :
8753 : : tree
8754 : 943184404 : get_callee_fndecl (const_tree call)
8755 : : {
8756 : 943184404 : tree addr;
8757 : :
8758 : 943184404 : if (call == error_mark_node)
8759 : : return error_mark_node;
8760 : :
8761 : : /* It's invalid to call this function with anything but a
8762 : : CALL_EXPR. */
8763 : 943184404 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8764 : :
8765 : : /* The first operand to the CALL is the address of the function
8766 : : called. */
8767 : 943184404 : addr = CALL_EXPR_FN (call);
8768 : :
8769 : : /* If there is no function, return early. */
8770 : 943184404 : if (addr == NULL_TREE)
8771 : : return NULL_TREE;
8772 : :
8773 : 941713604 : STRIP_NOPS (addr);
8774 : :
8775 : : /* If this is a readonly function pointer, extract its initial value. */
8776 : 16411332 : if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
8777 : 1682511 : && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
8778 : 941880238 : && DECL_INITIAL (addr))
8779 : 166543 : addr = DECL_INITIAL (addr);
8780 : :
8781 : : /* If the address is just `&f' for some function `f', then we know
8782 : : that `f' is being called. */
8783 : 941713604 : if (TREE_CODE (addr) == ADDR_EXPR
8784 : 941713604 : && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
8785 : 900902608 : return TREE_OPERAND (addr, 0);
8786 : :
8787 : : /* We couldn't figure out what was being called. */
8788 : : return NULL_TREE;
8789 : : }
8790 : :
8791 : : /* Return true when STMTs arguments and return value match those of FNDECL,
8792 : : a decl of a builtin function. */
8793 : :
8794 : : static bool
8795 : 5202223 : tree_builtin_call_types_compatible_p (const_tree call, tree fndecl)
8796 : : {
8797 : 5202223 : gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
8798 : :
8799 : 5202223 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
8800 : 5202223 : if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
8801 : 5202223 : fndecl = decl;
8802 : :
8803 : 5202223 : bool gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
8804 : 5202223 : if (gimple_form
8805 : 12989 : ? !useless_type_conversion_p (TREE_TYPE (call),
8806 : 12989 : TREE_TYPE (TREE_TYPE (fndecl)))
8807 : 5189234 : : (TYPE_MAIN_VARIANT (TREE_TYPE (call))
8808 : 5189234 : != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))))
8809 : : return false;
8810 : :
8811 : 5202007 : tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
8812 : 5202007 : unsigned nargs = call_expr_nargs (call);
8813 : 13851071 : for (unsigned i = 0; i < nargs; ++i, targs = TREE_CHAIN (targs))
8814 : : {
8815 : : /* Variadic args follow. */
8816 : 9575454 : if (!targs)
8817 : : return true;
8818 : 8649721 : tree arg = CALL_EXPR_ARG (call, i);
8819 : 8649721 : tree type = TREE_VALUE (targs);
8820 : 8649721 : if (gimple_form
8821 : 8649721 : ? !useless_type_conversion_p (type, TREE_TYPE (arg))
8822 : 8636732 : : TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (TREE_TYPE (arg)))
8823 : : {
8824 : : /* For pointer arguments be more forgiving, e.g. due to
8825 : : FILE * vs. fileptr_type_node, or say char * vs. const char *
8826 : : differences etc. */
8827 : 1105853 : if (!gimple_form
8828 : 553255 : && POINTER_TYPE_P (type)
8829 : 552703 : && POINTER_TYPE_P (TREE_TYPE (arg))
8830 : 1105853 : && tree_nop_conversion_p (type, TREE_TYPE (arg)))
8831 : 552598 : continue;
8832 : 657 : return false;
8833 : : }
8834 : : }
8835 : 8550587 : if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
8836 : : return false;
8837 : : return true;
8838 : : }
8839 : :
8840 : : /* If CALL_EXPR CALL calls a normal built-in function or an internal function,
8841 : : return the associated function code, otherwise return CFN_LAST. */
8842 : :
8843 : : combined_fn
8844 : 38278781 : get_call_combined_fn (const_tree call)
8845 : : {
8846 : : /* It's invalid to call this function with anything but a CALL_EXPR. */
8847 : 38278781 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8848 : :
8849 : 38278781 : if (!CALL_EXPR_FN (call))
8850 : 65968 : return as_combined_fn (CALL_EXPR_IFN (call));
8851 : :
8852 : 38212813 : tree fndecl = get_callee_fndecl (call);
8853 : 38212813 : if (fndecl
8854 : 38192273 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
8855 : 43415036 : && tree_builtin_call_types_compatible_p (call, fndecl))
8856 : 5201345 : return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
8857 : :
8858 : : return CFN_LAST;
8859 : : }
8860 : :
8861 : : /* Comparator of indices based on tree_node_counts. */
8862 : :
8863 : : static int
8864 : 0 : tree_nodes_cmp (const void *p1, const void *p2)
8865 : : {
8866 : 0 : const unsigned *n1 = (const unsigned *)p1;
8867 : 0 : const unsigned *n2 = (const unsigned *)p2;
8868 : :
8869 : 0 : return tree_node_counts[*n1] - tree_node_counts[*n2];
8870 : : }
8871 : :
8872 : : /* Comparator of indices based on tree_code_counts. */
8873 : :
8874 : : static int
8875 : 0 : tree_codes_cmp (const void *p1, const void *p2)
8876 : : {
8877 : 0 : const unsigned *n1 = (const unsigned *)p1;
8878 : 0 : const unsigned *n2 = (const unsigned *)p2;
8879 : :
8880 : 0 : return tree_code_counts[*n1] - tree_code_counts[*n2];
8881 : : }
8882 : :
8883 : : #define TREE_MEM_USAGE_SPACES 40
8884 : :
8885 : : /* Print debugging information about tree nodes generated during the compile,
8886 : : and any language-specific information. */
8887 : :
8888 : : void
8889 : 0 : dump_tree_statistics (void)
8890 : : {
8891 : 0 : if (GATHER_STATISTICS)
8892 : : {
8893 : : uint64_t total_nodes, total_bytes;
8894 : : fprintf (stderr, "\nKind Nodes Bytes\n");
8895 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8896 : : total_nodes = total_bytes = 0;
8897 : :
8898 : : {
8899 : : auto_vec<unsigned> indices (all_kinds);
8900 : : for (unsigned i = 0; i < all_kinds; i++)
8901 : : indices.quick_push (i);
8902 : : indices.qsort (tree_nodes_cmp);
8903 : :
8904 : : for (unsigned i = 0; i < (int) all_kinds; i++)
8905 : : {
8906 : : unsigned j = indices[i];
8907 : : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n",
8908 : : tree_node_kind_names[j], SIZE_AMOUNT (tree_node_counts[j]),
8909 : : SIZE_AMOUNT (tree_node_sizes[j]));
8910 : : total_nodes += tree_node_counts[j];
8911 : : total_bytes += tree_node_sizes[j];
8912 : : }
8913 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8914 : : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n", "Total",
8915 : : SIZE_AMOUNT (total_nodes), SIZE_AMOUNT (total_bytes));
8916 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8917 : : }
8918 : :
8919 : : {
8920 : : fprintf (stderr, "Code Nodes\n");
8921 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8922 : :
8923 : : auto_vec<unsigned> indices (MAX_TREE_CODES);
8924 : : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8925 : : indices.quick_push (i);
8926 : : indices.qsort (tree_codes_cmp);
8927 : :
8928 : : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
8929 : : {
8930 : : unsigned j = indices[i];
8931 : : fprintf (stderr, "%-32s %6" PRIu64 "%c\n",
8932 : : get_tree_code_name ((enum tree_code) j),
8933 : : SIZE_AMOUNT (tree_code_counts[j]));
8934 : : }
8935 : : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8936 : : fprintf (stderr, "\n");
8937 : : ssanames_print_statistics ();
8938 : : fprintf (stderr, "\n");
8939 : : phinodes_print_statistics ();
8940 : : fprintf (stderr, "\n");
8941 : : }
8942 : : }
8943 : : else
8944 : 0 : fprintf (stderr, "(No per-node statistics)\n");
8945 : :
8946 : 0 : print_type_hash_statistics ();
8947 : 0 : print_debug_expr_statistics ();
8948 : 0 : print_value_expr_statistics ();
8949 : 0 : lang_hooks.print_statistics ();
8950 : 0 : }
8951 : :
8952 : : #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
8953 : :
8954 : : /* Generate a crc32 of the low BYTES bytes of VALUE. */
8955 : :
8956 : : unsigned
8957 : 16487153 : crc32_unsigned_n (unsigned chksum, unsigned value, unsigned bytes)
8958 : : {
8959 : : /* This relies on the raw feedback's top 4 bits being zero. */
8960 : : #define FEEDBACK(X) ((X) * 0x04c11db7)
8961 : : #define SYNDROME(X) (FEEDBACK ((X) & 1) ^ FEEDBACK ((X) & 2) \
8962 : : ^ FEEDBACK ((X) & 4) ^ FEEDBACK ((X) & 8))
8963 : 16487153 : static const unsigned syndromes[16] =
8964 : : {
8965 : : SYNDROME(0x0), SYNDROME(0x1), SYNDROME(0x2), SYNDROME(0x3),
8966 : : SYNDROME(0x4), SYNDROME(0x5), SYNDROME(0x6), SYNDROME(0x7),
8967 : : SYNDROME(0x8), SYNDROME(0x9), SYNDROME(0xa), SYNDROME(0xb),
8968 : : SYNDROME(0xc), SYNDROME(0xd), SYNDROME(0xe), SYNDROME(0xf),
8969 : : };
8970 : : #undef FEEDBACK
8971 : : #undef SYNDROME
8972 : :
8973 : 16487153 : value <<= (32 - bytes * 8);
8974 : 54463455 : for (unsigned ix = bytes * 2; ix--; value <<= 4)
8975 : : {
8976 : 37976302 : unsigned feedback = syndromes[((value ^ chksum) >> 28) & 0xf];
8977 : :
8978 : 37976302 : chksum = (chksum << 4) ^ feedback;
8979 : : }
8980 : :
8981 : 16487153 : return chksum;
8982 : : }
8983 : :
8984 : : /* Generate a crc32 of a string. */
8985 : :
8986 : : unsigned
8987 : 8600 : crc32_string (unsigned chksum, const char *string)
8988 : : {
8989 : 344615 : do
8990 : 344615 : chksum = crc32_byte (chksum, *string);
8991 : 344615 : while (*string++);
8992 : 8600 : return chksum;
8993 : : }
8994 : :
8995 : : /* P is a string that will be used in a symbol. Mask out any characters
8996 : : that are not valid in that context. */
8997 : :
8998 : : void
8999 : 7184 : clean_symbol_name (char *p)
9000 : : {
9001 : 81219 : for (; *p; p++)
9002 : 74035 : if (! (ISALNUM (*p)
9003 : : #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9004 : : || *p == '$'
9005 : : #endif
9006 : : #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9007 : : || *p == '.'
9008 : : #endif
9009 : : ))
9010 : 6695 : *p = '_';
9011 : 7184 : }
9012 : :
9013 : : static GTY(()) unsigned anon_cnt = 0; /* Saved for PCH. */
9014 : :
9015 : : /* Create a unique anonymous identifier. The identifier is still a
9016 : : valid assembly label. */
9017 : :
9018 : : tree
9019 : 2614149 : make_anon_name ()
9020 : : {
9021 : 2614149 : const char *fmt =
9022 : : #if !defined (NO_DOT_IN_LABEL)
9023 : : "."
9024 : : #elif !defined (NO_DOLLAR_IN_LABEL)
9025 : : "$"
9026 : : #else
9027 : : "_"
9028 : : #endif
9029 : : "_anon_%d";
9030 : :
9031 : 2614149 : char buf[24];
9032 : 2614149 : int len = snprintf (buf, sizeof (buf), fmt, anon_cnt++);
9033 : 2614149 : gcc_checking_assert (len < int (sizeof (buf)));
9034 : :
9035 : 2614149 : tree id = get_identifier_with_length (buf, len);
9036 : 2614149 : IDENTIFIER_ANON_P (id) = true;
9037 : :
9038 : 2614149 : return id;
9039 : : }
9040 : :
9041 : : /* Generate a name for a special-purpose function.
9042 : : The generated name may need to be unique across the whole link.
9043 : : Changes to this function may also require corresponding changes to
9044 : : xstrdup_mask_random.
9045 : : TYPE is some string to identify the purpose of this function to the
9046 : : linker or collect2; it must start with an uppercase letter,
9047 : : one of:
9048 : : I - for constructors
9049 : : D - for destructors
9050 : : N - for C++ anonymous namespaces
9051 : : F - for DWARF unwind frame information. */
9052 : :
9053 : : tree
9054 : 5255 : get_file_function_name (const char *type)
9055 : : {
9056 : 5255 : char *buf;
9057 : 5255 : const char *p;
9058 : 5255 : char *q;
9059 : :
9060 : : /* If we already have a name we know to be unique, just use that. */
9061 : 5255 : if (first_global_object_name)
9062 : 4965 : p = q = ASTRDUP (first_global_object_name);
9063 : : /* If the target is handling the constructors/destructors, they
9064 : : will be local to this file and the name is only necessary for
9065 : : debugging purposes.
9066 : : We also assign sub_I and sub_D sufixes to constructors called from
9067 : : the global static constructors. These are always local.
9068 : : OpenMP "declare target" offloaded constructors/destructors use "off_I" and
9069 : : "off_D" for the same purpose. */
9070 : 290 : else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
9071 : 580 : || ((startswith (type, "sub_") || startswith (type, "off_"))
9072 : 290 : && (type[4] == 'I' || type[4] == 'D')))
9073 : : {
9074 : 290 : const char *file = main_input_filename;
9075 : 290 : if (! file)
9076 : 0 : file = LOCATION_FILE (input_location);
9077 : : /* Just use the file's basename, because the full pathname
9078 : : might be quite long. */
9079 : 290 : p = q = ASTRDUP (lbasename (file));
9080 : : }
9081 : : else
9082 : : {
9083 : : /* Otherwise, the name must be unique across the entire link.
9084 : : We don't have anything that we know to be unique to this translation
9085 : : unit, so use what we do have and throw in some randomness. */
9086 : 0 : unsigned len;
9087 : 0 : const char *name = weak_global_object_name;
9088 : 0 : const char *file = main_input_filename;
9089 : :
9090 : 0 : if (! name)
9091 : 0 : name = "";
9092 : 0 : if (! file)
9093 : 0 : file = LOCATION_FILE (input_location);
9094 : :
9095 : 0 : len = strlen (file);
9096 : 0 : q = (char *) alloca (9 + 19 + len + 1);
9097 : 0 : memcpy (q, file, len + 1);
9098 : :
9099 : 0 : snprintf (q + len, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
9100 : : crc32_string (0, name), get_random_seed (false));
9101 : :
9102 : 0 : p = q;
9103 : : }
9104 : :
9105 : 5255 : clean_symbol_name (q);
9106 : 5255 : buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
9107 : : + strlen (type));
9108 : :
9109 : : /* Set up the name of the file-level functions we may need.
9110 : : Use a global object (which is already required to be unique over
9111 : : the program) rather than the file name (which imposes extra
9112 : : constraints). */
9113 : 5255 : sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
9114 : :
9115 : 5255 : return get_identifier (buf);
9116 : : }
9117 : :
9118 : : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9119 : :
9120 : : /* Complain that the tree code of NODE does not match the expected 0
9121 : : terminated list of trailing codes. The trailing code list can be
9122 : : empty, for a more vague error message. FILE, LINE, and FUNCTION
9123 : : are of the caller. */
9124 : :
9125 : : void
9126 : 0 : tree_check_failed (const_tree node, const char *file,
9127 : : int line, const char *function, ...)
9128 : : {
9129 : 0 : va_list args;
9130 : 0 : const char *buffer;
9131 : 0 : unsigned length = 0;
9132 : 0 : enum tree_code code;
9133 : :
9134 : 0 : va_start (args, function);
9135 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9136 : 0 : length += 4 + strlen (get_tree_code_name (code));
9137 : 0 : va_end (args);
9138 : 0 : if (length)
9139 : : {
9140 : 0 : char *tmp;
9141 : 0 : va_start (args, function);
9142 : 0 : length += strlen ("expected ");
9143 : 0 : buffer = tmp = (char *) alloca (length);
9144 : 0 : length = 0;
9145 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9146 : : {
9147 : 0 : const char *prefix = length ? " or " : "expected ";
9148 : :
9149 : 0 : strcpy (tmp + length, prefix);
9150 : 0 : length += strlen (prefix);
9151 : 0 : strcpy (tmp + length, get_tree_code_name (code));
9152 : 0 : length += strlen (get_tree_code_name (code));
9153 : : }
9154 : 0 : va_end (args);
9155 : : }
9156 : : else
9157 : : buffer = "unexpected node";
9158 : :
9159 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9160 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9161 : : function, trim_filename (file), line);
9162 : : }
9163 : :
9164 : : /* Complain that the tree code of NODE does match the expected 0
9165 : : terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9166 : : the caller. */
9167 : :
9168 : : void
9169 : 0 : tree_not_check_failed (const_tree node, const char *file,
9170 : : int line, const char *function, ...)
9171 : : {
9172 : 0 : va_list args;
9173 : 0 : char *buffer;
9174 : 0 : unsigned length = 0;
9175 : 0 : enum tree_code code;
9176 : :
9177 : 0 : va_start (args, function);
9178 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9179 : 0 : length += 4 + strlen (get_tree_code_name (code));
9180 : 0 : va_end (args);
9181 : 0 : va_start (args, function);
9182 : 0 : buffer = (char *) alloca (length);
9183 : 0 : length = 0;
9184 : 0 : while ((code = (enum tree_code) va_arg (args, int)))
9185 : : {
9186 : 0 : if (length)
9187 : : {
9188 : 0 : strcpy (buffer + length, " or ");
9189 : 0 : length += 4;
9190 : : }
9191 : 0 : strcpy (buffer + length, get_tree_code_name (code));
9192 : 0 : length += strlen (get_tree_code_name (code));
9193 : : }
9194 : 0 : va_end (args);
9195 : :
9196 : 0 : internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9197 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9198 : : function, trim_filename (file), line);
9199 : : }
9200 : :
9201 : : /* Similar to tree_check_failed, except that we check for a class of tree
9202 : : code, given in CL. */
9203 : :
9204 : : void
9205 : 0 : tree_class_check_failed (const_tree node, const enum tree_code_class cl,
9206 : : const char *file, int line, const char *function)
9207 : : {
9208 : 0 : internal_error
9209 : 0 : ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9210 : 0 : TREE_CODE_CLASS_STRING (cl),
9211 : 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9212 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9213 : : }
9214 : :
9215 : : /* Similar to tree_check_failed, except that instead of specifying a
9216 : : dozen codes, use the knowledge that they're all sequential. */
9217 : :
9218 : : void
9219 : 0 : tree_range_check_failed (const_tree node, const char *file, int line,
9220 : : const char *function, enum tree_code c1,
9221 : : enum tree_code c2)
9222 : : {
9223 : 0 : char *buffer;
9224 : 0 : unsigned length = 0;
9225 : 0 : unsigned int c;
9226 : :
9227 : 0 : for (c = c1; c <= c2; ++c)
9228 : 0 : length += 4 + strlen (get_tree_code_name ((enum tree_code) c));
9229 : :
9230 : 0 : length += strlen ("expected ");
9231 : 0 : buffer = (char *) alloca (length);
9232 : 0 : length = 0;
9233 : :
9234 : 0 : for (c = c1; c <= c2; ++c)
9235 : : {
9236 : 0 : const char *prefix = length ? " or " : "expected ";
9237 : :
9238 : 0 : strcpy (buffer + length, prefix);
9239 : 0 : length += strlen (prefix);
9240 : 0 : strcpy (buffer + length, get_tree_code_name ((enum tree_code) c));
9241 : 0 : length += strlen (get_tree_code_name ((enum tree_code) c));
9242 : : }
9243 : :
9244 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9245 : 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9246 : : function, trim_filename (file), line);
9247 : : }
9248 : :
9249 : :
9250 : : /* Similar to tree_check_failed, except that we check that a tree does
9251 : : not have the specified code, given in CL. */
9252 : :
9253 : : void
9254 : 0 : tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
9255 : : const char *file, int line, const char *function)
9256 : : {
9257 : 0 : internal_error
9258 : 0 : ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9259 : 0 : TREE_CODE_CLASS_STRING (cl),
9260 : 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9261 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9262 : : }
9263 : :
9264 : :
9265 : : /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9266 : :
9267 : : void
9268 : 0 : omp_clause_check_failed (const_tree node, const char *file, int line,
9269 : : const char *function, enum omp_clause_code code)
9270 : : {
9271 : 0 : internal_error ("tree check: expected %<omp_clause %s%>, have %qs "
9272 : : "in %s, at %s:%d",
9273 : 0 : omp_clause_code_name[code],
9274 : 0 : get_tree_code_name (TREE_CODE (node)),
9275 : : function, trim_filename (file), line);
9276 : : }
9277 : :
9278 : :
9279 : : /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9280 : :
9281 : : void
9282 : 0 : omp_clause_range_check_failed (const_tree node, const char *file, int line,
9283 : : const char *function, enum omp_clause_code c1,
9284 : : enum omp_clause_code c2)
9285 : : {
9286 : 0 : char *buffer;
9287 : 0 : unsigned length = 0;
9288 : 0 : unsigned int c;
9289 : :
9290 : 0 : for (c = c1; c <= c2; ++c)
9291 : 0 : length += 4 + strlen (omp_clause_code_name[c]);
9292 : :
9293 : 0 : length += strlen ("expected ");
9294 : 0 : buffer = (char *) alloca (length);
9295 : 0 : length = 0;
9296 : :
9297 : 0 : for (c = c1; c <= c2; ++c)
9298 : : {
9299 : 0 : const char *prefix = length ? " or " : "expected ";
9300 : :
9301 : 0 : strcpy (buffer + length, prefix);
9302 : 0 : length += strlen (prefix);
9303 : 0 : strcpy (buffer + length, omp_clause_code_name[c]);
9304 : 0 : length += strlen (omp_clause_code_name[c]);
9305 : : }
9306 : :
9307 : 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9308 : 0 : buffer, omp_clause_code_name[TREE_CODE (node)],
9309 : : function, trim_filename (file), line);
9310 : : }
9311 : :
9312 : :
9313 : : #undef DEFTREESTRUCT
9314 : : #define DEFTREESTRUCT(VAL, NAME) NAME,
9315 : :
9316 : : static const char *ts_enum_names[] = {
9317 : : #include "treestruct.def"
9318 : : };
9319 : : #undef DEFTREESTRUCT
9320 : :
9321 : : #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9322 : :
9323 : : /* Similar to tree_class_check_failed, except that we check for
9324 : : whether CODE contains the tree structure identified by EN. */
9325 : :
9326 : : void
9327 : 0 : tree_contains_struct_check_failed (const_tree node,
9328 : : const enum tree_node_structure_enum en,
9329 : : const char *file, int line,
9330 : : const char *function)
9331 : : {
9332 : 0 : internal_error
9333 : 0 : ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9334 : 0 : TS_ENUM_NAME (en),
9335 : 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9336 : : }
9337 : :
9338 : :
9339 : : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9340 : : (dynamically sized) vector. */
9341 : :
9342 : : void
9343 : 0 : tree_int_cst_elt_check_failed (int idx, int len, const char *file, int line,
9344 : : const char *function)
9345 : : {
9346 : 0 : internal_error
9347 : 0 : ("tree check: accessed elt %d of %<tree_int_cst%> with %d elts in %s, "
9348 : : "at %s:%d",
9349 : : idx + 1, len, function, trim_filename (file), line);
9350 : : }
9351 : :
9352 : : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9353 : : (dynamically sized) vector. */
9354 : :
9355 : : void
9356 : 0 : tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
9357 : : const char *function)
9358 : : {
9359 : 0 : internal_error
9360 : 0 : ("tree check: accessed elt %d of %<tree_vec%> with %d elts in %s, at %s:%d",
9361 : : idx + 1, len, function, trim_filename (file), line);
9362 : : }
9363 : :
9364 : : /* Similar to above, except that the check is for the bounds of the operand
9365 : : vector of an expression node EXP. */
9366 : :
9367 : : void
9368 : 0 : tree_operand_check_failed (int idx, const_tree exp, const char *file,
9369 : : int line, const char *function)
9370 : : {
9371 : 0 : enum tree_code code = TREE_CODE (exp);
9372 : 0 : internal_error
9373 : 0 : ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9374 : : idx + 1, get_tree_code_name (code), TREE_OPERAND_LENGTH (exp),
9375 : : function, trim_filename (file), line);
9376 : : }
9377 : :
9378 : : /* Similar to above, except that the check is for the number of
9379 : : operands of an OMP_CLAUSE node. */
9380 : :
9381 : : void
9382 : 0 : omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
9383 : : int line, const char *function)
9384 : : {
9385 : 0 : internal_error
9386 : 0 : ("tree check: accessed operand %d of %<omp_clause %s%> with %d operands "
9387 : 0 : "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
9388 : 0 : omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
9389 : : trim_filename (file), line);
9390 : : }
9391 : : #endif /* ENABLE_TREE_CHECKING */
9392 : :
9393 : : /* Create a new vector type node holding NUNITS units of type INNERTYPE,
9394 : : and mapped to the machine mode MODE. Initialize its fields and build
9395 : : the information necessary for debugging output. */
9396 : :
9397 : : static tree
9398 : 69700396 : make_vector_type (tree innertype, poly_int64 nunits, machine_mode mode)
9399 : : {
9400 : 69700396 : tree t;
9401 : 69700396 : tree mv_innertype = TYPE_MAIN_VARIANT (innertype);
9402 : :
9403 : 69700396 : t = make_node (VECTOR_TYPE);
9404 : 69700396 : TREE_TYPE (t) = mv_innertype;
9405 : 69700396 : SET_TYPE_VECTOR_SUBPARTS (t, nunits);
9406 : 69700396 : SET_TYPE_MODE (t, mode);
9407 : :
9408 : 69700396 : if (TYPE_STRUCTURAL_EQUALITY_P (mv_innertype) || in_lto_p)
9409 : 1243202 : SET_TYPE_STRUCTURAL_EQUALITY (t);
9410 : 68457194 : else if ((TYPE_CANONICAL (mv_innertype) != innertype
9411 : 65044840 : || mode != VOIDmode)
9412 : 98762883 : && !VECTOR_BOOLEAN_TYPE_P (t))
9413 : 31870791 : TYPE_CANONICAL (t)
9414 : 63741582 : = make_vector_type (TYPE_CANONICAL (mv_innertype), nunits, VOIDmode);
9415 : :
9416 : 69700396 : layout_type (t);
9417 : :
9418 : 69700396 : hashval_t hash = type_hash_canon_hash (t);
9419 : 69700396 : t = type_hash_canon (hash, t);
9420 : :
9421 : : /* We have built a main variant, based on the main variant of the
9422 : : inner type. Use it to build the variant we return. */
9423 : 139395674 : if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
9424 : 70487810 : && TREE_TYPE (t) != innertype)
9425 : 791341 : return build_type_attribute_qual_variant (t,
9426 : 791341 : TYPE_ATTRIBUTES (innertype),
9427 : 1582682 : TYPE_QUALS (innertype));
9428 : :
9429 : : return t;
9430 : : }
9431 : :
9432 : : static tree
9433 : 4002291 : make_or_reuse_type (unsigned size, int unsignedp)
9434 : : {
9435 : 4002291 : int i;
9436 : :
9437 : 4002291 : if (size == INT_TYPE_SIZE)
9438 : 859152 : return unsignedp ? unsigned_type_node : integer_type_node;
9439 : 3143139 : if (size == CHAR_TYPE_SIZE)
9440 : 572768 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
9441 : 2570371 : if (size == SHORT_TYPE_SIZE)
9442 : 859152 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
9443 : 1747238 : if (size == LONG_TYPE_SIZE)
9444 : 837600 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
9445 : 873619 : if (size == LONG_LONG_TYPE_SIZE)
9446 : 21552 : return (unsignedp ? long_long_unsigned_type_node
9447 : 21552 : : long_long_integer_type_node);
9448 : :
9449 : 866237 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9450 : 852067 : if (size == int_n_data[i].bitsize
9451 : 852067 : && int_n_enabled_p[i])
9452 : 837897 : return (unsignedp ? int_n_trees[i].unsigned_type
9453 : 837897 : : int_n_trees[i].signed_type);
9454 : :
9455 : 14170 : if (unsignedp)
9456 : 7085 : return make_unsigned_type (size);
9457 : : else
9458 : 7085 : return make_signed_type (size);
9459 : : }
9460 : :
9461 : : /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9462 : :
9463 : : static tree
9464 : 5727680 : make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
9465 : : {
9466 : 5727680 : if (satp)
9467 : : {
9468 : 2863840 : if (size == SHORT_FRACT_TYPE_SIZE)
9469 : 572768 : return unsignedp ? sat_unsigned_short_fract_type_node
9470 : 572768 : : sat_short_fract_type_node;
9471 : 2291072 : if (size == FRACT_TYPE_SIZE)
9472 : 572768 : return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
9473 : 1718304 : if (size == LONG_FRACT_TYPE_SIZE)
9474 : 572768 : return unsignedp ? sat_unsigned_long_fract_type_node
9475 : 572768 : : sat_long_fract_type_node;
9476 : 1145536 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9477 : 572768 : return unsignedp ? sat_unsigned_long_long_fract_type_node
9478 : 572768 : : sat_long_long_fract_type_node;
9479 : : }
9480 : : else
9481 : : {
9482 : 2863840 : if (size == SHORT_FRACT_TYPE_SIZE)
9483 : 572768 : return unsignedp ? unsigned_short_fract_type_node
9484 : 572768 : : short_fract_type_node;
9485 : 2291072 : if (size == FRACT_TYPE_SIZE)
9486 : 572768 : return unsignedp ? unsigned_fract_type_node : fract_type_node;
9487 : 1718304 : if (size == LONG_FRACT_TYPE_SIZE)
9488 : 572768 : return unsignedp ? unsigned_long_fract_type_node
9489 : 572768 : : long_fract_type_node;
9490 : 1145536 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9491 : 572768 : return unsignedp ? unsigned_long_long_fract_type_node
9492 : 572768 : : long_long_fract_type_node;
9493 : : }
9494 : :
9495 : 1145536 : return make_fract_type (size, unsignedp, satp);
9496 : : }
9497 : :
9498 : : /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9499 : :
9500 : : static tree
9501 : 4582144 : make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
9502 : : {
9503 : 4582144 : if (satp)
9504 : : {
9505 : 2291072 : if (size == SHORT_ACCUM_TYPE_SIZE)
9506 : 572768 : return unsignedp ? sat_unsigned_short_accum_type_node
9507 : 572768 : : sat_short_accum_type_node;
9508 : 1718304 : if (size == ACCUM_TYPE_SIZE)
9509 : 572768 : return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
9510 : 1145536 : if (size == LONG_ACCUM_TYPE_SIZE)
9511 : 572768 : return unsignedp ? sat_unsigned_long_accum_type_node
9512 : 572768 : : sat_long_accum_type_node;
9513 : 572768 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9514 : 572768 : return unsignedp ? sat_unsigned_long_long_accum_type_node
9515 : 572768 : : sat_long_long_accum_type_node;
9516 : : }
9517 : : else
9518 : : {
9519 : 2291072 : if (size == SHORT_ACCUM_TYPE_SIZE)
9520 : 572768 : return unsignedp ? unsigned_short_accum_type_node
9521 : 572768 : : short_accum_type_node;
9522 : 1718304 : if (size == ACCUM_TYPE_SIZE)
9523 : 572768 : return unsignedp ? unsigned_accum_type_node : accum_type_node;
9524 : 1145536 : if (size == LONG_ACCUM_TYPE_SIZE)
9525 : 572768 : return unsignedp ? unsigned_long_accum_type_node
9526 : 572768 : : long_accum_type_node;
9527 : 572768 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9528 : 572768 : return unsignedp ? unsigned_long_long_accum_type_node
9529 : 572768 : : long_long_accum_type_node;
9530 : : }
9531 : :
9532 : 0 : return make_accum_type (size, unsignedp, satp);
9533 : : }
9534 : :
9535 : :
9536 : : /* Create an atomic variant node for TYPE. This routine is called
9537 : : during initialization of data types to create the 5 basic atomic
9538 : : types. The generic build_variant_type function requires these to
9539 : : already be set up in order to function properly, so cannot be
9540 : : called from there. If ALIGN is non-zero, then ensure alignment is
9541 : : overridden to this value. */
9542 : :
9543 : : static tree
9544 : 1431920 : build_atomic_base (tree type, unsigned int align)
9545 : : {
9546 : 1431920 : tree t;
9547 : :
9548 : : /* Make sure its not already registered. */
9549 : 1431920 : if ((t = get_qualified_type (type, TYPE_QUAL_ATOMIC)))
9550 : : return t;
9551 : :
9552 : 1431920 : t = build_variant_type_copy (type);
9553 : 1431920 : set_type_quals (t, TYPE_QUAL_ATOMIC);
9554 : :
9555 : 1431920 : if (align)
9556 : 0 : SET_TYPE_ALIGN (t, align);
9557 : :
9558 : : return t;
9559 : : }
9560 : :
9561 : : /* Information about the _FloatN and _FloatNx types. This must be in
9562 : : the same order as the corresponding TI_* enum values. */
9563 : : const floatn_type_info floatn_nx_types[NUM_FLOATN_NX_TYPES] =
9564 : : {
9565 : : { 16, false },
9566 : : { 32, false },
9567 : : { 64, false },
9568 : : { 128, false },
9569 : : { 32, true },
9570 : : { 64, true },
9571 : : { 128, true },
9572 : : };
9573 : :
9574 : :
9575 : : /* Create nodes for all integer types (and error_mark_node) using the sizes
9576 : : of C datatypes. SIGNED_CHAR specifies whether char is signed. */
9577 : :
9578 : : void
9579 : 286384 : build_common_tree_nodes (bool signed_char)
9580 : : {
9581 : 286384 : int i;
9582 : :
9583 : 286384 : error_mark_node = make_node (ERROR_MARK);
9584 : 286384 : TREE_TYPE (error_mark_node) = error_mark_node;
9585 : :
9586 : 286384 : initialize_sizetypes ();
9587 : :
9588 : : /* Define both `signed char' and `unsigned char'. */
9589 : 286384 : signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
9590 : 286384 : TYPE_STRING_FLAG (signed_char_type_node) = 1;
9591 : 286384 : unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
9592 : 286384 : TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
9593 : :
9594 : : /* Define `char', which is like either `signed char' or `unsigned char'
9595 : : but not the same as either. */
9596 : 286384 : char_type_node
9597 : 286384 : = (signed_char
9598 : 286384 : ? make_signed_type (CHAR_TYPE_SIZE)
9599 : 56617 : : make_unsigned_type (CHAR_TYPE_SIZE));
9600 : 286384 : TYPE_STRING_FLAG (char_type_node) = 1;
9601 : :
9602 : 286384 : short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
9603 : 286384 : short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
9604 : 286384 : integer_type_node = make_signed_type (INT_TYPE_SIZE);
9605 : 286384 : unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
9606 : 293568 : long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
9607 : 293568 : long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
9608 : 286384 : long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
9609 : 286384 : long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
9610 : :
9611 : 859152 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9612 : : {
9613 : 286384 : int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
9614 : 286384 : int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
9615 : :
9616 : 286384 : if (int_n_enabled_p[i])
9617 : : {
9618 : 279299 : integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type;
9619 : 279299 : integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type;
9620 : : }
9621 : : }
9622 : :
9623 : : /* Define a boolean type. This type only represents boolean values but
9624 : : may be larger than char depending on the value of BOOL_TYPE_SIZE. */
9625 : 286384 : boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
9626 : 286384 : TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
9627 : 286384 : TYPE_PRECISION (boolean_type_node) = 1;
9628 : 286384 : TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
9629 : :
9630 : : /* Define what type to use for size_t. */
9631 : 293568 : if (strcmp (SIZE_TYPE, "unsigned int") == 0)
9632 : 7184 : size_type_node = unsigned_type_node;
9633 : 279200 : else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
9634 : 279200 : size_type_node = long_unsigned_type_node;
9635 : 0 : else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
9636 : 0 : size_type_node = long_long_unsigned_type_node;
9637 : 0 : else if (strcmp (SIZE_TYPE, "short unsigned int") == 0)
9638 : 0 : size_type_node = short_unsigned_type_node;
9639 : : else
9640 : : {
9641 : 0 : int i;
9642 : :
9643 : 0 : size_type_node = NULL_TREE;
9644 : 0 : for (i = 0; i < NUM_INT_N_ENTS; i++)
9645 : 0 : if (int_n_enabled_p[i])
9646 : : {
9647 : 0 : char name[50], altname[50];
9648 : 0 : sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
9649 : 0 : sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize);
9650 : :
9651 : 0 : if (strcmp (name, SIZE_TYPE) == 0
9652 : 0 : || strcmp (altname, SIZE_TYPE) == 0)
9653 : : {
9654 : 0 : size_type_node = int_n_trees[i].unsigned_type;
9655 : : }
9656 : : }
9657 : 0 : if (size_type_node == NULL_TREE)
9658 : 0 : gcc_unreachable ();
9659 : : }
9660 : :
9661 : : /* Define what type to use for ptrdiff_t. */
9662 : 293568 : if (strcmp (PTRDIFF_TYPE, "int") == 0)
9663 : 7184 : ptrdiff_type_node = integer_type_node;
9664 : 279200 : else if (strcmp (PTRDIFF_TYPE, "long int") == 0)
9665 : 279200 : ptrdiff_type_node = long_integer_type_node;
9666 : 0 : else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)
9667 : 0 : ptrdiff_type_node = long_long_integer_type_node;
9668 : 0 : else if (strcmp (PTRDIFF_TYPE, "short int") == 0)
9669 : 0 : ptrdiff_type_node = short_integer_type_node;
9670 : : else
9671 : : {
9672 : 0 : ptrdiff_type_node = NULL_TREE;
9673 : 0 : for (int i = 0; i < NUM_INT_N_ENTS; i++)
9674 : 0 : if (int_n_enabled_p[i])
9675 : : {
9676 : 0 : char name[50], altname[50];
9677 : 0 : sprintf (name, "__int%d", int_n_data[i].bitsize);
9678 : 0 : sprintf (altname, "__int%d__", int_n_data[i].bitsize);
9679 : :
9680 : 0 : if (strcmp (name, PTRDIFF_TYPE) == 0
9681 : 0 : || strcmp (altname, PTRDIFF_TYPE) == 0)
9682 : 0 : ptrdiff_type_node = int_n_trees[i].signed_type;
9683 : : }
9684 : 0 : if (ptrdiff_type_node == NULL_TREE)
9685 : 0 : gcc_unreachable ();
9686 : : }
9687 : :
9688 : : /* Fill in the rest of the sized types. Reuse existing type nodes
9689 : : when possible. */
9690 : 286384 : intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
9691 : 286384 : intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
9692 : 286384 : intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
9693 : 286384 : intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
9694 : 286384 : intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
9695 : :
9696 : 286384 : unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
9697 : 286384 : unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
9698 : 286384 : unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
9699 : 286384 : unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
9700 : 286384 : unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
9701 : :
9702 : : /* Don't call build_qualified type for atomics. That routine does
9703 : : special processing for atomics, and until they are initialized
9704 : : it's better not to make that call.
9705 : :
9706 : : Check to see if there is a target override for atomic types. */
9707 : :
9708 : 286384 : atomicQI_type_node = build_atomic_base (unsigned_intQI_type_node,
9709 : 286384 : targetm.atomic_align_for_mode (QImode));
9710 : 286384 : atomicHI_type_node = build_atomic_base (unsigned_intHI_type_node,
9711 : 286384 : targetm.atomic_align_for_mode (HImode));
9712 : 286384 : atomicSI_type_node = build_atomic_base (unsigned_intSI_type_node,
9713 : 286384 : targetm.atomic_align_for_mode (SImode));
9714 : 286384 : atomicDI_type_node = build_atomic_base (unsigned_intDI_type_node,
9715 : 286384 : targetm.atomic_align_for_mode (DImode));
9716 : 286384 : atomicTI_type_node = build_atomic_base (unsigned_intTI_type_node,
9717 : 286384 : targetm.atomic_align_for_mode (TImode));
9718 : :
9719 : 286384 : access_public_node = get_identifier ("public");
9720 : 286384 : access_protected_node = get_identifier ("protected");
9721 : 286384 : access_private_node = get_identifier ("private");
9722 : :
9723 : : /* Define these next since types below may used them. */
9724 : 286384 : integer_zero_node = build_int_cst (integer_type_node, 0);
9725 : 286384 : integer_one_node = build_int_cst (integer_type_node, 1);
9726 : 286384 : integer_minus_one_node = build_int_cst (integer_type_node, -1);
9727 : :
9728 : 286384 : size_zero_node = size_int (0);
9729 : 286384 : size_one_node = size_int (1);
9730 : 286384 : bitsize_zero_node = bitsize_int (0);
9731 : 286384 : bitsize_one_node = bitsize_int (1);
9732 : 286384 : bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
9733 : :
9734 : 286384 : boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9735 : 286384 : boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9736 : :
9737 : 286384 : void_type_node = make_node (VOID_TYPE);
9738 : 286384 : layout_type (void_type_node);
9739 : :
9740 : : /* We are not going to have real types in C with less than byte alignment,
9741 : : so we might as well not have any types that claim to have it. */
9742 : 286384 : SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT);
9743 : 286384 : TYPE_USER_ALIGN (void_type_node) = 0;
9744 : :
9745 : 286384 : void_node = make_node (VOID_CST);
9746 : 286384 : TREE_TYPE (void_node) = void_type_node;
9747 : :
9748 : 286384 : void_list_node = build_tree_list (NULL_TREE, void_type_node);
9749 : :
9750 : 286384 : null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
9751 : 286384 : layout_type (TREE_TYPE (null_pointer_node));
9752 : :
9753 : 286384 : ptr_type_node = build_pointer_type (void_type_node);
9754 : 286384 : const_ptr_type_node
9755 : 286384 : = build_pointer_type (build_type_variant (void_type_node, 1, 0));
9756 : 2004688 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
9757 : 1718304 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
9758 : :
9759 : 293568 : pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
9760 : :
9761 : 286384 : float_type_node = make_node (REAL_TYPE);
9762 : 286384 : machine_mode float_type_mode
9763 : 286384 : = targetm.c.mode_for_floating_type (TI_FLOAT_TYPE);
9764 : 286384 : SET_TYPE_MODE (float_type_node, float_type_mode);
9765 : 286384 : TYPE_PRECISION (float_type_node)
9766 : 286384 : = GET_MODE_PRECISION (float_type_mode).to_constant ();
9767 : 286384 : layout_type (float_type_node);
9768 : :
9769 : 286384 : double_type_node = make_node (REAL_TYPE);
9770 : 286384 : machine_mode double_type_mode
9771 : 286384 : = targetm.c.mode_for_floating_type (TI_DOUBLE_TYPE);
9772 : 286384 : SET_TYPE_MODE (double_type_node, double_type_mode);
9773 : 286384 : TYPE_PRECISION (double_type_node)
9774 : 286384 : = GET_MODE_PRECISION (double_type_mode).to_constant ();
9775 : 286384 : layout_type (double_type_node);
9776 : :
9777 : 286384 : long_double_type_node = make_node (REAL_TYPE);
9778 : 286384 : machine_mode long_double_type_mode
9779 : 286384 : = targetm.c.mode_for_floating_type (TI_LONG_DOUBLE_TYPE);
9780 : 286384 : SET_TYPE_MODE (long_double_type_node, long_double_type_mode);
9781 : 286384 : TYPE_PRECISION (long_double_type_node)
9782 : 286384 : = GET_MODE_PRECISION (long_double_type_mode).to_constant ();
9783 : 286384 : layout_type (long_double_type_node);
9784 : :
9785 : 2291072 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9786 : : {
9787 : 2004688 : int n = floatn_nx_types[i].n;
9788 : 2004688 : bool extended = floatn_nx_types[i].extended;
9789 : 2004688 : scalar_float_mode mode;
9790 : 2004688 : if (!targetm.floatn_mode (n, extended).exists (&mode))
9791 : 286384 : continue;
9792 : 1718304 : int precision = GET_MODE_PRECISION (mode);
9793 : 1718304 : FLOATN_NX_TYPE_NODE (i) = make_node (REAL_TYPE);
9794 : 1718304 : TYPE_PRECISION (FLOATN_NX_TYPE_NODE (i)) = precision;
9795 : 1718304 : layout_type (FLOATN_NX_TYPE_NODE (i));
9796 : 1718304 : SET_TYPE_MODE (FLOATN_NX_TYPE_NODE (i), mode);
9797 : : }
9798 : 286384 : float128t_type_node = float128_type_node;
9799 : : #ifdef HAVE_BFmode
9800 : 286384 : if (REAL_MODE_FORMAT (BFmode) == &arm_bfloat_half_format
9801 : 286384 : && targetm.scalar_mode_supported_p (BFmode)
9802 : 572768 : && targetm.libgcc_floating_mode_supported_p (BFmode))
9803 : : {
9804 : 286384 : bfloat16_type_node = make_node (REAL_TYPE);
9805 : 286384 : TYPE_PRECISION (bfloat16_type_node) = GET_MODE_PRECISION (BFmode);
9806 : 286384 : layout_type (bfloat16_type_node);
9807 : 286384 : SET_TYPE_MODE (bfloat16_type_node, BFmode);
9808 : : }
9809 : : #endif
9810 : :
9811 : 286384 : float_ptr_type_node = build_pointer_type (float_type_node);
9812 : 286384 : double_ptr_type_node = build_pointer_type (double_type_node);
9813 : 286384 : long_double_ptr_type_node = build_pointer_type (long_double_type_node);
9814 : 286384 : integer_ptr_type_node = build_pointer_type (integer_type_node);
9815 : :
9816 : : /* Fixed size integer types. */
9817 : 286384 : uint16_type_node = make_or_reuse_type (16, 1);
9818 : 286384 : uint32_type_node = make_or_reuse_type (32, 1);
9819 : 286384 : uint64_type_node = make_or_reuse_type (64, 1);
9820 : 286384 : if (targetm.scalar_mode_supported_p (TImode))
9821 : 279299 : uint128_type_node = make_or_reuse_type (128, 1);
9822 : :
9823 : : /* Decimal float types. */
9824 : 286384 : if (targetm.decimal_float_supported_p ())
9825 : : {
9826 : 286384 : dfloat32_type_node = make_node (REAL_TYPE);
9827 : 286384 : TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
9828 : 286384 : SET_TYPE_MODE (dfloat32_type_node, SDmode);
9829 : 286384 : layout_type (dfloat32_type_node);
9830 : :
9831 : 286384 : dfloat64_type_node = make_node (REAL_TYPE);
9832 : 286384 : TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
9833 : 286384 : SET_TYPE_MODE (dfloat64_type_node, DDmode);
9834 : 286384 : layout_type (dfloat64_type_node);
9835 : :
9836 : 286384 : dfloat128_type_node = make_node (REAL_TYPE);
9837 : 286384 : TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
9838 : 286384 : SET_TYPE_MODE (dfloat128_type_node, TDmode);
9839 : 286384 : layout_type (dfloat128_type_node);
9840 : :
9841 : 286384 : dfloat64x_type_node = make_node (REAL_TYPE);
9842 : 286384 : TYPE_PRECISION (dfloat64x_type_node) = DECIMAL128_TYPE_SIZE;
9843 : 286384 : SET_TYPE_MODE (dfloat64x_type_node, TDmode);
9844 : 286384 : layout_type (dfloat64x_type_node);
9845 : : }
9846 : :
9847 : 286384 : complex_integer_type_node = build_complex_type (integer_type_node, true);
9848 : 286384 : complex_float_type_node = build_complex_type (float_type_node, true);
9849 : 286384 : complex_double_type_node = build_complex_type (double_type_node, true);
9850 : 286384 : complex_long_double_type_node = build_complex_type (long_double_type_node,
9851 : : true);
9852 : :
9853 : 2291072 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9854 : : {
9855 : 2004688 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
9856 : 1718304 : COMPLEX_FLOATN_NX_TYPE_NODE (i)
9857 : 1718304 : = build_complex_type (FLOATN_NX_TYPE_NODE (i));
9858 : : }
9859 : :
9860 : : /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9861 : : #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9862 : : sat_ ## KIND ## _type_node = \
9863 : : make_sat_signed_ ## KIND ## _type (SIZE); \
9864 : : sat_unsigned_ ## KIND ## _type_node = \
9865 : : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9866 : : KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9867 : : unsigned_ ## KIND ## _type_node = \
9868 : : make_unsigned_ ## KIND ## _type (SIZE);
9869 : :
9870 : : #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9871 : : sat_ ## WIDTH ## KIND ## _type_node = \
9872 : : make_sat_signed_ ## KIND ## _type (SIZE); \
9873 : : sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9874 : : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9875 : : WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9876 : : unsigned_ ## WIDTH ## KIND ## _type_node = \
9877 : : make_unsigned_ ## KIND ## _type (SIZE);
9878 : :
9879 : : /* Make fixed-point type nodes based on four different widths. */
9880 : : #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9881 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9882 : : MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9883 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9884 : : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9885 : :
9886 : : /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9887 : : #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9888 : : NAME ## _type_node = \
9889 : : make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9890 : : u ## NAME ## _type_node = \
9891 : : make_or_reuse_unsigned_ ## KIND ## _type \
9892 : : (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9893 : : sat_ ## NAME ## _type_node = \
9894 : : make_or_reuse_sat_signed_ ## KIND ## _type \
9895 : : (GET_MODE_BITSIZE (MODE ## mode)); \
9896 : : sat_u ## NAME ## _type_node = \
9897 : : make_or_reuse_sat_unsigned_ ## KIND ## _type \
9898 : : (GET_MODE_BITSIZE (U ## MODE ## mode));
9899 : :
9900 : : /* Fixed-point type and mode nodes. */
9901 : 286384 : MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
9902 : 286384 : MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
9903 : 286384 : MAKE_FIXED_MODE_NODE (fract, qq, QQ)
9904 : 286384 : MAKE_FIXED_MODE_NODE (fract, hq, HQ)
9905 : 286384 : MAKE_FIXED_MODE_NODE (fract, sq, SQ)
9906 : 286384 : MAKE_FIXED_MODE_NODE (fract, dq, DQ)
9907 : 286384 : MAKE_FIXED_MODE_NODE (fract, tq, TQ)
9908 : 286384 : MAKE_FIXED_MODE_NODE (accum, ha, HA)
9909 : 286384 : MAKE_FIXED_MODE_NODE (accum, sa, SA)
9910 : 286384 : MAKE_FIXED_MODE_NODE (accum, da, DA)
9911 : 286384 : MAKE_FIXED_MODE_NODE (accum, ta, TA)
9912 : :
9913 : 286384 : {
9914 : 286384 : tree t = targetm.build_builtin_va_list ();
9915 : :
9916 : : /* Many back-ends define record types without setting TYPE_NAME.
9917 : : If we copied the record type here, we'd keep the original
9918 : : record type without a name. This breaks name mangling. So,
9919 : : don't copy record types and let c_common_nodes_and_builtins()
9920 : : declare the type to be __builtin_va_list. */
9921 : 286384 : if (TREE_CODE (t) != RECORD_TYPE)
9922 : 286384 : t = build_variant_type_copy (t);
9923 : :
9924 : 286384 : va_list_type_node = t;
9925 : : }
9926 : :
9927 : : /* SCEV analyzer global shared trees. */
9928 : 286384 : chrec_dont_know = make_node (SCEV_NOT_KNOWN);
9929 : 286384 : TREE_TYPE (chrec_dont_know) = void_type_node;
9930 : 286384 : chrec_known = make_node (SCEV_KNOWN);
9931 : 286384 : TREE_TYPE (chrec_known) = void_type_node;
9932 : 286384 : }
9933 : :
9934 : : /* Modify DECL for given flags.
9935 : : TM_PURE attribute is set only on types, so the function will modify
9936 : : DECL's type when ECF_TM_PURE is used. */
9937 : :
9938 : : void
9939 : 30610969 : set_call_expr_flags (tree decl, int flags)
9940 : : {
9941 : 30610969 : if (flags & ECF_NOTHROW)
9942 : 26377706 : TREE_NOTHROW (decl) = 1;
9943 : 30610969 : if (flags & ECF_CONST)
9944 : 12676349 : TREE_READONLY (decl) = 1;
9945 : 30610969 : if (flags & ECF_PURE)
9946 : 1496507 : DECL_PURE_P (decl) = 1;
9947 : 30610969 : if (flags & ECF_LOOPING_CONST_OR_PURE)
9948 : 0 : DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
9949 : 30610969 : if (flags & ECF_NOVOPS)
9950 : 0 : DECL_IS_NOVOPS (decl) = 1;
9951 : 30610969 : if (flags & ECF_NORETURN)
9952 : 1218716 : TREE_THIS_VOLATILE (decl) = 1;
9953 : 30610969 : if (flags & ECF_MALLOC)
9954 : 734977 : DECL_IS_MALLOC (decl) = 1;
9955 : 30610969 : if (flags & ECF_RETURNS_TWICE)
9956 : 0 : DECL_IS_RETURNS_TWICE (decl) = 1;
9957 : 30610969 : if (flags & ECF_LEAF)
9958 : 26250786 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
9959 : 26250786 : NULL, DECL_ATTRIBUTES (decl));
9960 : 30610969 : if (flags & ECF_COLD)
9961 : 640947 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("cold"),
9962 : 640947 : NULL, DECL_ATTRIBUTES (decl));
9963 : 30610969 : if (flags & ECF_RET1)
9964 : 0 : DECL_ATTRIBUTES (decl)
9965 : 0 : = tree_cons (get_identifier ("fn spec"),
9966 : : build_tree_list (NULL_TREE, build_string (2, "1 ")),
9967 : 0 : DECL_ATTRIBUTES (decl));
9968 : 30610969 : if ((flags & ECF_TM_PURE) && flag_tm)
9969 : 574 : apply_tm_attr (decl, get_identifier ("transaction_pure"));
9970 : 30610969 : if ((flags & ECF_XTHROW))
9971 : 409208 : DECL_ATTRIBUTES (decl)
9972 : 818416 : = tree_cons (get_identifier ("expected_throw"),
9973 : 409208 : NULL, DECL_ATTRIBUTES (decl));
9974 : : /* Looping const or pure is implied by noreturn.
9975 : : There is currently no way to declare looping const or looping pure alone. */
9976 : 30610969 : gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE)
9977 : : || ((flags & ECF_NORETURN) && (flags & (ECF_CONST | ECF_PURE))));
9978 : 30610969 : }
9979 : :
9980 : :
9981 : : /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
9982 : :
9983 : : static void
9984 : 9490553 : local_define_builtin (const char *name, tree type, enum built_in_function code,
9985 : : const char *library_name, int ecf_flags)
9986 : : {
9987 : 9490553 : tree decl;
9988 : :
9989 : 9490553 : decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
9990 : : library_name, NULL_TREE);
9991 : 9490553 : set_call_expr_flags (decl, ecf_flags);
9992 : :
9993 : 9490553 : set_builtin_decl (code, decl, true);
9994 : 9490553 : }
9995 : :
9996 : : /* Call this function after instantiating all builtins that the language
9997 : : front end cares about. This will build the rest of the builtins
9998 : : and internal functions that are relied upon by the tree optimizers and
9999 : : the middle-end. */
10000 : :
10001 : : void
10002 : 286368 : build_common_builtin_nodes (void)
10003 : : {
10004 : 286368 : tree tmp, ftype;
10005 : 286368 : int ecf_flags;
10006 : :
10007 : 286368 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_PADDING))
10008 : : {
10009 : 57802 : ftype = build_function_type_list (void_type_node,
10010 : : ptr_type_node,
10011 : : ptr_type_node,
10012 : : NULL_TREE);
10013 : 57802 : local_define_builtin ("__builtin_clear_padding", ftype,
10014 : : BUILT_IN_CLEAR_PADDING,
10015 : : "__builtin_clear_padding",
10016 : : ECF_LEAF | ECF_NOTHROW);
10017 : : }
10018 : :
10019 : 286368 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)
10020 : 233210 : || !builtin_decl_explicit_p (BUILT_IN_TRAP)
10021 : 233210 : || !builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP)
10022 : 514934 : || !builtin_decl_explicit_p (BUILT_IN_ABORT))
10023 : : {
10024 : 57802 : ftype = build_function_type (void_type_node, void_list_node);
10025 : 57802 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE))
10026 : 53158 : local_define_builtin ("__builtin_unreachable", ftype,
10027 : : BUILT_IN_UNREACHABLE,
10028 : : "__builtin_unreachable",
10029 : : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10030 : : | ECF_CONST | ECF_COLD);
10031 : 57802 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP))
10032 : 57802 : local_define_builtin ("__builtin_unreachable trap", ftype,
10033 : : BUILT_IN_UNREACHABLE_TRAP,
10034 : : "__builtin_unreachable trap",
10035 : : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10036 : : | ECF_CONST | ECF_COLD);
10037 : 57802 : if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
10038 : 57802 : local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
10039 : : "abort",
10040 : : ECF_LEAF | ECF_NORETURN | ECF_CONST | ECF_COLD);
10041 : 57802 : if (!builtin_decl_explicit_p (BUILT_IN_TRAP))
10042 : 22569 : local_define_builtin ("__builtin_trap", ftype, BUILT_IN_TRAP,
10043 : : "__builtin_trap",
10044 : : ECF_NORETURN | ECF_NOTHROW | ECF_LEAF | ECF_COLD);
10045 : : }
10046 : :
10047 : 286368 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)
10048 : 286368 : || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10049 : : {
10050 : 57802 : ftype = build_function_type_list (ptr_type_node,
10051 : : ptr_type_node, const_ptr_type_node,
10052 : : size_type_node, NULL_TREE);
10053 : :
10054 : 57802 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY))
10055 : 57802 : local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
10056 : : "memcpy", ECF_NOTHROW | ECF_LEAF);
10057 : 57802 : if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10058 : 53158 : local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
10059 : : "memmove", ECF_NOTHROW | ECF_LEAF);
10060 : : }
10061 : :
10062 : 286368 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP))
10063 : : {
10064 : 53158 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10065 : : const_ptr_type_node, size_type_node,
10066 : : NULL_TREE);
10067 : 53158 : local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
10068 : : "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10069 : : }
10070 : :
10071 : 286368 : if (!builtin_decl_explicit_p (BUILT_IN_MEMSET))
10072 : : {
10073 : 53158 : ftype = build_function_type_list (ptr_type_node,
10074 : : ptr_type_node, integer_type_node,
10075 : : size_type_node, NULL_TREE);
10076 : 53158 : local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
10077 : : "memset", ECF_NOTHROW | ECF_LEAF);
10078 : : }
10079 : :
10080 : : /* If we're checking the stack, `alloca' can throw. */
10081 : 286308 : const int alloca_flags
10082 : 286368 : = ECF_MALLOC | ECF_LEAF | (flag_stack_check ? 0 : ECF_NOTHROW);
10083 : :
10084 : 286368 : if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA))
10085 : : {
10086 : 57802 : ftype = build_function_type_list (ptr_type_node,
10087 : : size_type_node, NULL_TREE);
10088 : 57802 : local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
10089 : : "alloca", alloca_flags);
10090 : : }
10091 : :
10092 : 286368 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10093 : : size_type_node, NULL_TREE);
10094 : 286368 : local_define_builtin ("__builtin_alloca_with_align", ftype,
10095 : : BUILT_IN_ALLOCA_WITH_ALIGN,
10096 : : "__builtin_alloca_with_align",
10097 : : alloca_flags);
10098 : :
10099 : 286368 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10100 : : size_type_node, size_type_node, NULL_TREE);
10101 : 286368 : local_define_builtin ("__builtin_alloca_with_align_and_max", ftype,
10102 : : BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX,
10103 : : "__builtin_alloca_with_align_and_max",
10104 : : alloca_flags);
10105 : :
10106 : 286368 : ftype = build_function_type_list (void_type_node,
10107 : : ptr_type_node, ptr_type_node,
10108 : : ptr_type_node, NULL_TREE);
10109 : 286368 : local_define_builtin ("__builtin_init_trampoline", ftype,
10110 : : BUILT_IN_INIT_TRAMPOLINE,
10111 : : "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
10112 : 286368 : local_define_builtin ("__builtin_init_heap_trampoline", ftype,
10113 : : BUILT_IN_INIT_HEAP_TRAMPOLINE,
10114 : : "__builtin_init_heap_trampoline",
10115 : : ECF_NOTHROW | ECF_LEAF);
10116 : 286368 : local_define_builtin ("__builtin_init_descriptor", ftype,
10117 : : BUILT_IN_INIT_DESCRIPTOR,
10118 : : "__builtin_init_descriptor", ECF_NOTHROW | ECF_LEAF);
10119 : :
10120 : 286368 : ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
10121 : 286368 : local_define_builtin ("__builtin_adjust_trampoline", ftype,
10122 : : BUILT_IN_ADJUST_TRAMPOLINE,
10123 : : "__builtin_adjust_trampoline",
10124 : : ECF_CONST | ECF_NOTHROW);
10125 : 286368 : local_define_builtin ("__builtin_adjust_descriptor", ftype,
10126 : : BUILT_IN_ADJUST_DESCRIPTOR,
10127 : : "__builtin_adjust_descriptor",
10128 : : ECF_CONST | ECF_NOTHROW);
10129 : :
10130 : 286368 : ftype = build_function_type_list (void_type_node,
10131 : : ptr_type_node, ptr_type_node, NULL_TREE);
10132 : 286368 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_CACHE))
10133 : 57802 : local_define_builtin ("__builtin___clear_cache", ftype,
10134 : : BUILT_IN_CLEAR_CACHE,
10135 : : "__clear_cache",
10136 : : ECF_NOTHROW);
10137 : :
10138 : 286368 : local_define_builtin ("__builtin_nonlocal_goto", ftype,
10139 : : BUILT_IN_NONLOCAL_GOTO,
10140 : : "__builtin_nonlocal_goto",
10141 : : ECF_NORETURN | ECF_NOTHROW);
10142 : :
10143 : 286368 : tree ptr_ptr_type_node = build_pointer_type (ptr_type_node);
10144 : :
10145 : 286368 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED))
10146 : : {
10147 : 57802 : ftype = build_function_type_list (void_type_node,
10148 : : ptr_type_node, // void *chain
10149 : : ptr_type_node, // void *func
10150 : : ptr_ptr_type_node, // void **dst
10151 : : NULL_TREE);
10152 : 57802 : local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype,
10153 : : BUILT_IN_GCC_NESTED_PTR_CREATED,
10154 : : "__gcc_nested_func_ptr_created", ECF_NOTHROW);
10155 : : }
10156 : :
10157 : 286368 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED))
10158 : : {
10159 : 57802 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10160 : 57802 : local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype,
10161 : : BUILT_IN_GCC_NESTED_PTR_DELETED,
10162 : : "__gcc_nested_func_ptr_deleted", ECF_NOTHROW);
10163 : : }
10164 : :
10165 : 286368 : ftype = build_function_type_list (void_type_node,
10166 : : ptr_type_node, ptr_type_node, NULL_TREE);
10167 : 286368 : local_define_builtin ("__builtin_setjmp_setup", ftype,
10168 : : BUILT_IN_SETJMP_SETUP,
10169 : : "__builtin_setjmp_setup", ECF_NOTHROW);
10170 : :
10171 : 286368 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10172 : 286368 : local_define_builtin ("__builtin_setjmp_receiver", ftype,
10173 : : BUILT_IN_SETJMP_RECEIVER,
10174 : : "__builtin_setjmp_receiver", ECF_NOTHROW | ECF_LEAF);
10175 : :
10176 : 286368 : ftype = build_function_type_list (ptr_type_node, NULL_TREE);
10177 : 286368 : local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
10178 : : "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
10179 : :
10180 : 286368 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10181 : 286368 : local_define_builtin ("__builtin_stack_restore", ftype,
10182 : : BUILT_IN_STACK_RESTORE,
10183 : : "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
10184 : :
10185 : 286368 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10186 : : const_ptr_type_node, size_type_node,
10187 : : NULL_TREE);
10188 : 286368 : local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ,
10189 : : "__builtin_memcmp_eq",
10190 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10191 : :
10192 : 286368 : local_define_builtin ("__builtin_strncmp_eq", ftype, BUILT_IN_STRNCMP_EQ,
10193 : : "__builtin_strncmp_eq",
10194 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10195 : :
10196 : 286368 : local_define_builtin ("__builtin_strcmp_eq", ftype, BUILT_IN_STRCMP_EQ,
10197 : : "__builtin_strcmp_eq",
10198 : : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10199 : :
10200 : : /* If there's a possibility that we might use the ARM EABI, build the
10201 : : alternate __cxa_end_cleanup node used to resume from C++. */
10202 : 286368 : if (targetm.arm_eabi_unwinder)
10203 : : {
10204 : 0 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10205 : 0 : local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
10206 : : BUILT_IN_CXA_END_CLEANUP,
10207 : : "__cxa_end_cleanup",
10208 : : ECF_NORETURN | ECF_XTHROW | ECF_LEAF);
10209 : : }
10210 : :
10211 : 286368 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10212 : 572736 : local_define_builtin ("__builtin_unwind_resume", ftype,
10213 : : BUILT_IN_UNWIND_RESUME,
10214 : 286368 : ((targetm_common.except_unwind_info (&global_options)
10215 : : == UI_SJLJ)
10216 : : ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10217 : : ECF_NORETURN | ECF_XTHROW);
10218 : :
10219 : 286368 : if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE)
10220 : : {
10221 : 53158 : ftype = build_function_type_list (ptr_type_node, integer_type_node,
10222 : : NULL_TREE);
10223 : 53158 : local_define_builtin ("__builtin_return_address", ftype,
10224 : : BUILT_IN_RETURN_ADDRESS,
10225 : : "__builtin_return_address",
10226 : : ECF_NOTHROW);
10227 : : }
10228 : :
10229 : 286368 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)
10230 : 286368 : || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10231 : : {
10232 : 57802 : ftype = build_function_type_list (void_type_node, ptr_type_node,
10233 : : ptr_type_node, NULL_TREE);
10234 : 57802 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER))
10235 : 57802 : local_define_builtin ("__cyg_profile_func_enter", ftype,
10236 : : BUILT_IN_PROFILE_FUNC_ENTER,
10237 : : "__cyg_profile_func_enter", 0);
10238 : 57802 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10239 : 57802 : local_define_builtin ("__cyg_profile_func_exit", ftype,
10240 : : BUILT_IN_PROFILE_FUNC_EXIT,
10241 : : "__cyg_profile_func_exit", 0);
10242 : : }
10243 : :
10244 : : /* The exception object and filter values from the runtime. The argument
10245 : : must be zero before exception lowering, i.e. from the front end. After
10246 : : exception lowering, it will be the region number for the exception
10247 : : landing pad. These functions are PURE instead of CONST to prevent
10248 : : them from being hoisted past the exception edge that will initialize
10249 : : its value in the landing pad. */
10250 : 286368 : ftype = build_function_type_list (ptr_type_node,
10251 : : integer_type_node, NULL_TREE);
10252 : 286368 : ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF;
10253 : : /* Only use TM_PURE if we have TM language support. */
10254 : 286368 : if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
10255 : 512 : ecf_flags |= ECF_TM_PURE;
10256 : 286368 : local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
10257 : : "__builtin_eh_pointer", ecf_flags);
10258 : :
10259 : 286368 : tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
10260 : 286368 : ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
10261 : 286368 : local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
10262 : : "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10263 : :
10264 : 286368 : ftype = build_function_type_list (void_type_node,
10265 : : integer_type_node, integer_type_node,
10266 : : NULL_TREE);
10267 : 286368 : local_define_builtin ("__builtin_eh_copy_values", ftype,
10268 : : BUILT_IN_EH_COPY_VALUES,
10269 : : "__builtin_eh_copy_values", ECF_NOTHROW);
10270 : :
10271 : : /* Complex multiplication and division. These are handled as builtins
10272 : : rather than optabs because emit_library_call_value doesn't support
10273 : : complex. Further, we can do slightly better with folding these
10274 : : beasties if the real and complex parts of the arguments are separate. */
10275 : 286368 : {
10276 : 286368 : int mode;
10277 : :
10278 : 2004576 : for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
10279 : : {
10280 : 1718208 : char mode_name_buf[4], *q;
10281 : 1718208 : const char *p;
10282 : 1718208 : enum built_in_function mcode, dcode;
10283 : 1718208 : tree type, inner_type;
10284 : 1718208 : const char *prefix = "__";
10285 : :
10286 : 1718208 : if (targetm.libfunc_gnu_prefix)
10287 : 0 : prefix = "__gnu_";
10288 : :
10289 : 1718208 : type = lang_hooks.types.type_for_mode ((machine_mode) mode, 0);
10290 : 1718208 : if (type == NULL)
10291 : 126617 : continue;
10292 : 1591591 : inner_type = TREE_TYPE (type);
10293 : :
10294 : 1591591 : ftype = build_function_type_list (type, inner_type, inner_type,
10295 : : inner_type, inner_type, NULL_TREE);
10296 : :
10297 : 1591591 : mcode = ((enum built_in_function)
10298 : 1591591 : (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10299 : 1591591 : dcode = ((enum built_in_function)
10300 : 1591591 : (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10301 : :
10302 : 4774773 : for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
10303 : 3183182 : *q = TOLOWER (*p);
10304 : 1591591 : *q = '\0';
10305 : :
10306 : : /* For -ftrapping-math these should throw from a former
10307 : : -fnon-call-exception stmt. */
10308 : 1591591 : built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
10309 : : NULL);
10310 : 1591591 : local_define_builtin (built_in_names[mcode], ftype, mcode,
10311 : : built_in_names[mcode],
10312 : : ECF_CONST | ECF_LEAF);
10313 : :
10314 : 1591591 : built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
10315 : : NULL);
10316 : 1591591 : local_define_builtin (built_in_names[dcode], ftype, dcode,
10317 : : built_in_names[dcode],
10318 : : ECF_CONST | ECF_LEAF);
10319 : : }
10320 : : }
10321 : :
10322 : 286368 : init_internal_fns ();
10323 : 286368 : }
10324 : :
10325 : : /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10326 : : better way.
10327 : :
10328 : : If we requested a pointer to a vector, build up the pointers that
10329 : : we stripped off while looking for the inner type. Similarly for
10330 : : return values from functions.
10331 : :
10332 : : The argument TYPE is the top of the chain, and BOTTOM is the
10333 : : new type which we will point to. */
10334 : :
10335 : : tree
10336 : 0 : reconstruct_complex_type (tree type, tree bottom)
10337 : : {
10338 : 0 : tree inner, outer;
10339 : :
10340 : 0 : if (TREE_CODE (type) == POINTER_TYPE)
10341 : : {
10342 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10343 : 0 : outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
10344 : 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10345 : : }
10346 : : else if (TREE_CODE (type) == REFERENCE_TYPE)
10347 : : {
10348 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10349 : 0 : outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
10350 : 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10351 : : }
10352 : : else if (TREE_CODE (type) == ARRAY_TYPE)
10353 : : {
10354 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10355 : 0 : outer = build_array_type (inner, TYPE_DOMAIN (type));
10356 : : }
10357 : : else if (TREE_CODE (type) == FUNCTION_TYPE)
10358 : : {
10359 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10360 : 0 : outer = build_function_type (inner, TYPE_ARG_TYPES (type),
10361 : 0 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
10362 : : }
10363 : : else if (TREE_CODE (type) == METHOD_TYPE)
10364 : : {
10365 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10366 : : /* The build_method_type_directly() routine prepends 'this' to argument list,
10367 : : so we must compensate by getting rid of it. */
10368 : 0 : outer
10369 : : = build_method_type_directly
10370 : 0 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
10371 : : inner,
10372 : 0 : TREE_CHAIN (TYPE_ARG_TYPES (type)));
10373 : : }
10374 : : else if (TREE_CODE (type) == OFFSET_TYPE)
10375 : : {
10376 : 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10377 : 0 : outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
10378 : : }
10379 : : else
10380 : : return bottom;
10381 : :
10382 : 0 : return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
10383 : 0 : TYPE_QUALS (type));
10384 : : }
10385 : :
10386 : : /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10387 : : the inner type. */
10388 : : tree
10389 : 33045289 : build_vector_type_for_mode (tree innertype, machine_mode mode)
10390 : : {
10391 : 33045289 : poly_int64 nunits;
10392 : 33045289 : unsigned int bitsize;
10393 : :
10394 : 33045289 : switch (GET_MODE_CLASS (mode))
10395 : : {
10396 : 33044034 : case MODE_VECTOR_BOOL:
10397 : 33044034 : case MODE_VECTOR_INT:
10398 : 33044034 : case MODE_VECTOR_FLOAT:
10399 : 33044034 : case MODE_VECTOR_FRACT:
10400 : 33044034 : case MODE_VECTOR_UFRACT:
10401 : 33044034 : case MODE_VECTOR_ACCUM:
10402 : 33044034 : case MODE_VECTOR_UACCUM:
10403 : 66088068 : nunits = GET_MODE_NUNITS (mode);
10404 : 33044034 : break;
10405 : :
10406 : 1255 : case MODE_INT:
10407 : : /* Check that there are no leftover bits. */
10408 : 1255 : bitsize = GET_MODE_BITSIZE (as_a <scalar_int_mode> (mode));
10409 : 1255 : gcc_assert (bitsize % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
10410 : 1255 : nunits = bitsize / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
10411 : 1255 : break;
10412 : :
10413 : 0 : default:
10414 : 0 : gcc_unreachable ();
10415 : : }
10416 : :
10417 : 33045289 : return make_vector_type (innertype, nunits, mode);
10418 : : }
10419 : :
10420 : : /* Similarly, but takes the inner type and number of units, which must be
10421 : : a power of two. */
10422 : :
10423 : : tree
10424 : 2771848 : build_vector_type (tree innertype, poly_int64 nunits)
10425 : : {
10426 : 2771848 : return make_vector_type (innertype, nunits, VOIDmode);
10427 : : }
10428 : :
10429 : : /* Build a truth vector with NUNITS units, giving it mode MASK_MODE. */
10430 : :
10431 : : tree
10432 : 1906584 : build_truth_vector_type_for_mode (poly_uint64 nunits, machine_mode mask_mode)
10433 : : {
10434 : 1906584 : gcc_assert (mask_mode != BLKmode);
10435 : :
10436 : 1906584 : unsigned HOST_WIDE_INT esize;
10437 : 1906584 : if (VECTOR_MODE_P (mask_mode))
10438 : : {
10439 : 1847331 : poly_uint64 vsize = GET_MODE_PRECISION (mask_mode);
10440 : 1847331 : esize = vector_element_size (vsize, nunits);
10441 : 1847331 : }
10442 : : else
10443 : : esize = 1;
10444 : :
10445 : 1906584 : tree bool_type = build_nonstandard_boolean_type (esize);
10446 : :
10447 : 1906584 : return make_vector_type (bool_type, nunits, mask_mode);
10448 : : }
10449 : :
10450 : : /* Build a vector type that holds one boolean result for each element of
10451 : : vector type VECTYPE. The public interface for this operation is
10452 : : truth_type_for. */
10453 : :
10454 : : static tree
10455 : 1900884 : build_truth_vector_type_for (tree vectype)
10456 : : {
10457 : 1900884 : machine_mode vector_mode = TYPE_MODE (vectype);
10458 : 1900884 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
10459 : :
10460 : 1900884 : machine_mode mask_mode;
10461 : 68845 : if (VECTOR_MODE_P (vector_mode)
10462 : 1969168 : && targetm.vectorize.get_mask_mode (vector_mode).exists (&mask_mode))
10463 : 1900323 : return build_truth_vector_type_for_mode (nunits, mask_mode);
10464 : :
10465 : 561 : poly_uint64 vsize = tree_to_poly_uint64 (TYPE_SIZE (vectype));
10466 : 561 : unsigned HOST_WIDE_INT esize = vector_element_size (vsize, nunits);
10467 : 561 : tree bool_type = build_nonstandard_boolean_type (esize);
10468 : :
10469 : 561 : return make_vector_type (bool_type, nunits, VOIDmode);
10470 : : }
10471 : :
10472 : : /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
10473 : : set. */
10474 : :
10475 : : tree
10476 : 105323 : build_opaque_vector_type (tree innertype, poly_int64 nunits)
10477 : : {
10478 : 105323 : tree t = make_vector_type (innertype, nunits, VOIDmode);
10479 : 105323 : tree cand;
10480 : : /* We always build the non-opaque variant before the opaque one,
10481 : : so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10482 : 105323 : cand = TYPE_NEXT_VARIANT (t);
10483 : 105323 : if (cand
10484 : 94021 : && TYPE_VECTOR_OPAQUE (cand)
10485 : 166476 : && check_qualified_type (cand, t, TYPE_QUALS (t)))
10486 : : return cand;
10487 : : /* Othewise build a variant type and make sure to queue it after
10488 : : the non-opaque type. */
10489 : 44171 : cand = build_distinct_type_copy (t);
10490 : 44171 : TYPE_VECTOR_OPAQUE (cand) = true;
10491 : 44171 : TYPE_CANONICAL (cand) = TYPE_CANONICAL (t);
10492 : 44171 : TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t);
10493 : 44171 : TYPE_NEXT_VARIANT (t) = cand;
10494 : 44171 : TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
10495 : : /* Type variants have no alias set defined. */
10496 : 44171 : TYPE_ALIAS_SET (cand) = -1;
10497 : 44171 : return cand;
10498 : : }
10499 : :
10500 : : /* Return the value of element I of VECTOR_CST T as a wide_int. */
10501 : :
10502 : : static poly_wide_int
10503 : 483201 : vector_cst_int_elt (const_tree t, unsigned int i)
10504 : : {
10505 : : /* First handle elements that are directly encoded. */
10506 : 483201 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10507 : 483201 : if (i < encoded_nelts)
10508 : 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, i));
10509 : :
10510 : : /* Identify the pattern that contains element I and work out the index of
10511 : : the last encoded element for that pattern. */
10512 : 483201 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10513 : 483201 : unsigned int pattern = i % npatterns;
10514 : 483201 : unsigned int count = i / npatterns;
10515 : 483201 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10516 : :
10517 : : /* If there are no steps, the final encoded value is the right one. */
10518 : 483201 : if (!VECTOR_CST_STEPPED_P (t))
10519 : 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, final_i));
10520 : :
10521 : : /* Otherwise work out the value from the last two encoded elements. */
10522 : 483201 : tree v1 = VECTOR_CST_ENCODED_ELT (t, final_i - npatterns);
10523 : 483201 : tree v2 = VECTOR_CST_ENCODED_ELT (t, final_i);
10524 : 483201 : poly_wide_int diff = wi::to_poly_wide (v2) - wi::to_poly_wide (v1);
10525 : 483201 : return wi::to_poly_wide (v2) + (count - 2) * diff;
10526 : 483201 : }
10527 : :
10528 : : /* Return the value of element I of VECTOR_CST T. */
10529 : :
10530 : : tree
10531 : 5819995 : vector_cst_elt (const_tree t, unsigned int i)
10532 : : {
10533 : : /* First handle elements that are directly encoded. */
10534 : 5819995 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10535 : 5819995 : if (i < encoded_nelts)
10536 : 4085751 : return VECTOR_CST_ENCODED_ELT (t, i);
10537 : :
10538 : : /* If there are no steps, the final encoded value is the right one. */
10539 : 1734244 : if (!VECTOR_CST_STEPPED_P (t))
10540 : : {
10541 : : /* Identify the pattern that contains element I and work out the index of
10542 : : the last encoded element for that pattern. */
10543 : 1251043 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10544 : 1251043 : unsigned int pattern = i % npatterns;
10545 : 1251043 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10546 : 1251043 : return VECTOR_CST_ENCODED_ELT (t, final_i);
10547 : : }
10548 : :
10549 : : /* Otherwise work out the value from the last two encoded elements. */
10550 : 483201 : return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t)),
10551 : 966402 : vector_cst_int_elt (t, i));
10552 : : }
10553 : :
10554 : : /* Given an initializer INIT, return TRUE if INIT is zero or some
10555 : : aggregate of zeros. Otherwise return FALSE. If NONZERO is not
10556 : : null, set *NONZERO if and only if INIT is known not to be all
10557 : : zeros. The combination of return value of false and *NONZERO
10558 : : false implies that INIT may but need not be all zeros. Other
10559 : : combinations indicate definitive answers. */
10560 : :
10561 : : bool
10562 : 44071748 : initializer_zerop (const_tree init, bool *nonzero /* = NULL */)
10563 : : {
10564 : 44071748 : bool dummy;
10565 : 44071748 : if (!nonzero)
10566 : 41328603 : nonzero = &dummy;
10567 : :
10568 : : /* Conservatively clear NONZERO and set it only if INIT is definitely
10569 : : not all zero. */
10570 : 44071748 : *nonzero = false;
10571 : :
10572 : 44071748 : STRIP_NOPS (init);
10573 : :
10574 : 44071748 : unsigned HOST_WIDE_INT off = 0;
10575 : :
10576 : 44071748 : switch (TREE_CODE (init))
10577 : : {
10578 : 16428152 : case INTEGER_CST:
10579 : 16428152 : if (integer_zerop (init))
10580 : : return true;
10581 : :
10582 : 10283999 : *nonzero = true;
10583 : 10283999 : return false;
10584 : :
10585 : 528700 : case REAL_CST:
10586 : : /* ??? Note that this is not correct for C4X float formats. There,
10587 : : a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10588 : : negative exponent. */
10589 : 528700 : if (real_zerop (init)
10590 : 615397 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)))
10591 : : return true;
10592 : :
10593 : 444906 : *nonzero = true;
10594 : 444906 : return false;
10595 : :
10596 : 0 : case FIXED_CST:
10597 : 0 : if (fixed_zerop (init))
10598 : : return true;
10599 : :
10600 : 0 : *nonzero = true;
10601 : 0 : return false;
10602 : :
10603 : 17662 : case COMPLEX_CST:
10604 : 17662 : if (integer_zerop (init)
10605 : 17662 : || (real_zerop (init)
10606 : 2948 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
10607 : 2898 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))))
10608 : 3120 : return true;
10609 : :
10610 : 14542 : *nonzero = true;
10611 : 14542 : return false;
10612 : :
10613 : 1106085 : case VECTOR_CST:
10614 : 1106085 : if (VECTOR_CST_NPATTERNS (init) == 1
10615 : 1014238 : && VECTOR_CST_DUPLICATE_P (init)
10616 : 1744925 : && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)))
10617 : : return true;
10618 : :
10619 : 765247 : *nonzero = true;
10620 : 765247 : return false;
10621 : :
10622 : : case RAW_DATA_CST:
10623 : 1569 : for (unsigned int i = 0; i < (unsigned int) RAW_DATA_LENGTH (init); ++i)
10624 : 1569 : if (RAW_DATA_POINTER (init)[i])
10625 : : {
10626 : 1519 : *nonzero = true;
10627 : 1519 : return false;
10628 : : }
10629 : : return true;
10630 : :
10631 : 5805908 : case CONSTRUCTOR:
10632 : 5805908 : {
10633 : 5805908 : if (TREE_CLOBBER_P (init))
10634 : : return false;
10635 : :
10636 : : unsigned HOST_WIDE_INT idx;
10637 : : tree elt;
10638 : :
10639 : 3571663 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
10640 : 2743145 : if (!initializer_zerop (elt, nonzero))
10641 : : return false;
10642 : :
10643 : : return true;
10644 : : }
10645 : :
10646 : 430784 : case MEM_REF:
10647 : 430784 : {
10648 : 430784 : tree arg = TREE_OPERAND (init, 0);
10649 : 430784 : if (TREE_CODE (arg) != ADDR_EXPR)
10650 : : return false;
10651 : 78554 : tree offset = TREE_OPERAND (init, 1);
10652 : 78554 : if (TREE_CODE (offset) != INTEGER_CST
10653 : 78554 : || !tree_fits_uhwi_p (offset))
10654 : : return false;
10655 : 78554 : off = tree_to_uhwi (offset);
10656 : 78554 : if (INT_MAX < off)
10657 : : return false;
10658 : 78550 : arg = TREE_OPERAND (arg, 0);
10659 : 78550 : if (TREE_CODE (arg) != STRING_CST)
10660 : : return false;
10661 : : init = arg;
10662 : : }
10663 : : /* Fall through. */
10664 : :
10665 : : case STRING_CST:
10666 : : {
10667 : : gcc_assert (off <= INT_MAX);
10668 : :
10669 : 159827 : int i = off;
10670 : 159827 : int n = TREE_STRING_LENGTH (init);
10671 : 159827 : if (n <= i)
10672 : : return false;
10673 : :
10674 : : /* We need to loop through all elements to handle cases like
10675 : : "\0" and "\0foobar". */
10676 : 172110 : for (i = 0; i < n; ++i)
10677 : 166459 : if (TREE_STRING_POINTER (init)[i] != '\0')
10678 : : {
10679 : 154143 : *nonzero = true;
10680 : 154143 : return false;
10681 : : }
10682 : :
10683 : : return true;
10684 : : }
10685 : :
10686 : : default:
10687 : : return false;
10688 : : }
10689 : : }
10690 : :
10691 : : /* Return true if EXPR is an initializer expression in which every element
10692 : : is a constant that is numerically equal to 0 or 1. The elements do not
10693 : : need to be equal to each other. */
10694 : :
10695 : : bool
10696 : 122675 : initializer_each_zero_or_onep (const_tree expr)
10697 : : {
10698 : 122675 : STRIP_ANY_LOCATION_WRAPPER (expr);
10699 : :
10700 : 122675 : switch (TREE_CODE (expr))
10701 : : {
10702 : 46614 : case INTEGER_CST:
10703 : 46614 : return integer_zerop (expr) || integer_onep (expr);
10704 : :
10705 : 19489 : case REAL_CST:
10706 : 19489 : return real_zerop (expr) || real_onep (expr);
10707 : :
10708 : 56572 : case VECTOR_CST:
10709 : 56572 : {
10710 : 56572 : unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
10711 : 56572 : if (VECTOR_CST_STEPPED_P (expr)
10712 : 56572 : && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
10713 : : return false;
10714 : :
10715 : 67328 : for (unsigned int i = 0; i < nelts; ++i)
10716 : : {
10717 : 66103 : tree elt = vector_cst_elt (expr, i);
10718 : 66103 : if (!initializer_each_zero_or_onep (elt))
10719 : : return false;
10720 : : }
10721 : :
10722 : : return true;
10723 : : }
10724 : :
10725 : : default:
10726 : : return false;
10727 : : }
10728 : : }
10729 : :
10730 : : /* Check if vector VEC consists of all the equal elements and
10731 : : that the number of elements corresponds to the type of VEC.
10732 : : The function returns first element of the vector
10733 : : or NULL_TREE if the vector is not uniform. */
10734 : : tree
10735 : 2572594 : uniform_vector_p (const_tree vec)
10736 : : {
10737 : 2572594 : tree first, t;
10738 : 2572594 : unsigned HOST_WIDE_INT i, nelts;
10739 : :
10740 : 2572594 : if (vec == NULL_TREE)
10741 : : return NULL_TREE;
10742 : :
10743 : 2572594 : gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
10744 : :
10745 : 2572594 : if (TREE_CODE (vec) == VEC_DUPLICATE_EXPR)
10746 : 0 : return TREE_OPERAND (vec, 0);
10747 : :
10748 : 2572594 : else if (TREE_CODE (vec) == VECTOR_CST)
10749 : : {
10750 : 207057 : if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
10751 : 165544 : return VECTOR_CST_ENCODED_ELT (vec, 0);
10752 : : return NULL_TREE;
10753 : : }
10754 : :
10755 : 2365537 : else if (TREE_CODE (vec) == CONSTRUCTOR
10756 : 2365537 : && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)).is_constant (&nelts))
10757 : : {
10758 : 158282 : first = error_mark_node;
10759 : :
10760 : 519194 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
10761 : : {
10762 : 461793 : if (i == 0)
10763 : : {
10764 : 158282 : first = t;
10765 : 158282 : continue;
10766 : : }
10767 : 303511 : if (!operand_equal_p (first, t, 0))
10768 : : return NULL_TREE;
10769 : : }
10770 : 57401 : if (i != nelts)
10771 : : return NULL_TREE;
10772 : :
10773 : 57209 : if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
10774 : : return uniform_vector_p (first);
10775 : : return first;
10776 : : }
10777 : :
10778 : : return NULL_TREE;
10779 : : }
10780 : :
10781 : : /* If the argument is INTEGER_CST, return it. If the argument is vector
10782 : : with all elements the same INTEGER_CST, return that INTEGER_CST. Otherwise
10783 : : return NULL_TREE.
10784 : : Look through location wrappers. */
10785 : :
10786 : : tree
10787 : 828439234 : uniform_integer_cst_p (tree t)
10788 : : {
10789 : 828439234 : STRIP_ANY_LOCATION_WRAPPER (t);
10790 : :
10791 : 828439234 : if (TREE_CODE (t) == INTEGER_CST)
10792 : : return t;
10793 : :
10794 : 338817767 : if (VECTOR_TYPE_P (TREE_TYPE (t)))
10795 : : {
10796 : 889131 : t = uniform_vector_p (t);
10797 : 889131 : if (t && TREE_CODE (t) == INTEGER_CST)
10798 : : return t;
10799 : : }
10800 : :
10801 : : return NULL_TREE;
10802 : : }
10803 : :
10804 : : /* Checks to see if T is a constant or a constant vector and if each element E
10805 : : adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE. */
10806 : :
10807 : : tree
10808 : 3084355 : bitmask_inv_cst_vector_p (tree t)
10809 : : {
10810 : :
10811 : 3084355 : tree_code code = TREE_CODE (t);
10812 : 3084355 : tree type = TREE_TYPE (t);
10813 : :
10814 : 3084355 : if (!INTEGRAL_TYPE_P (type)
10815 : 3084355 : && !VECTOR_INTEGER_TYPE_P (type))
10816 : : return NULL_TREE;
10817 : :
10818 : 3084355 : unsigned HOST_WIDE_INT nelts = 1;
10819 : 3084355 : tree cst;
10820 : 3084355 : unsigned int idx = 0;
10821 : 3084355 : bool uniform = uniform_integer_cst_p (t);
10822 : 3084355 : tree newtype = unsigned_type_for (type);
10823 : 3084355 : tree_vector_builder builder;
10824 : 3084355 : if (code == INTEGER_CST)
10825 : : cst = t;
10826 : : else
10827 : : {
10828 : 6024 : if (!VECTOR_CST_NELTS (t).is_constant (&nelts))
10829 : : return NULL_TREE;
10830 : :
10831 : 6024 : cst = vector_cst_elt (t, 0);
10832 : 6024 : builder.new_vector (newtype, nelts, 1);
10833 : : }
10834 : :
10835 : 3084355 : tree ty = unsigned_type_for (TREE_TYPE (cst));
10836 : :
10837 : 3084367 : do
10838 : : {
10839 : 3084367 : if (idx > 0)
10840 : 12 : cst = vector_cst_elt (t, idx);
10841 : 3084367 : wide_int icst = wi::to_wide (cst);
10842 : 3084367 : wide_int inv = wi::bit_not (icst);
10843 : 3084367 : icst = wi::add (1, inv);
10844 : 3084367 : if (wi::popcount (icst) != 1)
10845 : : return NULL_TREE;
10846 : :
10847 : 22422 : tree newcst = wide_int_to_tree (ty, inv);
10848 : :
10849 : 22422 : if (uniform)
10850 : 22406 : return build_uniform_cst (newtype, newcst);
10851 : :
10852 : 16 : builder.quick_push (newcst);
10853 : 3084367 : }
10854 : 16 : while (++idx < nelts);
10855 : :
10856 : 4 : return builder.build ();
10857 : 3084355 : }
10858 : :
10859 : : /* If VECTOR_CST T has a single nonzero element, return the index of that
10860 : : element, otherwise return -1. */
10861 : :
10862 : : int
10863 : 177 : single_nonzero_element (const_tree t)
10864 : : {
10865 : 177 : unsigned HOST_WIDE_INT nelts;
10866 : 177 : unsigned int repeat_nelts;
10867 : 177 : if (VECTOR_CST_NELTS (t).is_constant (&nelts))
10868 : 177 : repeat_nelts = nelts;
10869 : : else if (VECTOR_CST_NELTS_PER_PATTERN (t) == 2)
10870 : : {
10871 : : nelts = vector_cst_encoded_nelts (t);
10872 : : repeat_nelts = VECTOR_CST_NPATTERNS (t);
10873 : : }
10874 : : else
10875 : : return -1;
10876 : :
10877 : 177 : int res = -1;
10878 : 561 : for (unsigned int i = 0; i < nelts; ++i)
10879 : : {
10880 : 528 : tree elt = vector_cst_elt (t, i);
10881 : 528 : if (!integer_zerop (elt) && !real_zerop (elt))
10882 : : {
10883 : 321 : if (res >= 0 || i >= repeat_nelts)
10884 : : return -1;
10885 : 177 : res = i;
10886 : : }
10887 : : }
10888 : : return res;
10889 : : }
10890 : :
10891 : : /* Build an empty statement at location LOC. */
10892 : :
10893 : : tree
10894 : 12521859 : build_empty_stmt (location_t loc)
10895 : : {
10896 : 12521859 : tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
10897 : 12521859 : SET_EXPR_LOCATION (t, loc);
10898 : 12521859 : return t;
10899 : : }
10900 : :
10901 : :
10902 : : /* Build an OMP clause with code CODE. LOC is the location of the
10903 : : clause. */
10904 : :
10905 : : tree
10906 : 1700005 : build_omp_clause (location_t loc, enum omp_clause_code code)
10907 : : {
10908 : 1700005 : tree t;
10909 : 1700005 : int size, length;
10910 : :
10911 : 1700005 : length = omp_clause_num_ops[code];
10912 : 1700005 : size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
10913 : :
10914 : 1700005 : record_node_allocation_statistics (OMP_CLAUSE, size);
10915 : :
10916 : 1700005 : t = (tree) ggc_internal_alloc (size);
10917 : 1700005 : memset (t, 0, size);
10918 : 1700005 : TREE_SET_CODE (t, OMP_CLAUSE);
10919 : 1700005 : OMP_CLAUSE_SET_CODE (t, code);
10920 : 1700005 : OMP_CLAUSE_LOCATION (t) = loc;
10921 : :
10922 : 1700005 : return t;
10923 : : }
10924 : :
10925 : : /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10926 : : includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10927 : : Except for the CODE and operand count field, other storage for the
10928 : : object is initialized to zeros. */
10929 : :
10930 : : tree
10931 : 432510407 : build_vl_exp (enum tree_code code, int len MEM_STAT_DECL)
10932 : : {
10933 : 432510407 : tree t;
10934 : 432510407 : int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
10935 : :
10936 : 432510407 : gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
10937 : 432510407 : gcc_assert (len >= 1);
10938 : :
10939 : 432510407 : record_node_allocation_statistics (code, length);
10940 : :
10941 : 432510407 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
10942 : :
10943 : 432510407 : TREE_SET_CODE (t, code);
10944 : :
10945 : : /* Can't use TREE_OPERAND to store the length because if checking is
10946 : : enabled, it will try to check the length before we store it. :-P */
10947 : 432510407 : t->exp.operands[0] = build_int_cst (sizetype, len);
10948 : :
10949 : 432510407 : return t;
10950 : : }
10951 : :
10952 : : /* Helper function for build_call_* functions; build a CALL_EXPR with
10953 : : indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
10954 : : the argument slots. */
10955 : :
10956 : : static tree
10957 : 230124124 : build_call_1 (tree return_type, tree fn, int nargs)
10958 : : {
10959 : 230124124 : tree t;
10960 : :
10961 : 230124124 : t = build_vl_exp (CALL_EXPR, nargs + 3);
10962 : 230124124 : TREE_TYPE (t) = return_type;
10963 : 230124124 : CALL_EXPR_FN (t) = fn;
10964 : 230124124 : CALL_EXPR_STATIC_CHAIN (t) = NULL;
10965 : :
10966 : 230124124 : return t;
10967 : : }
10968 : :
10969 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10970 : : FN and a null static chain slot. NARGS is the number of call arguments
10971 : : which are specified as "..." arguments. */
10972 : :
10973 : : tree
10974 : 151 : build_call_nary (tree return_type, tree fn, int nargs, ...)
10975 : : {
10976 : 151 : tree ret;
10977 : 151 : va_list args;
10978 : 151 : va_start (args, nargs);
10979 : 151 : ret = build_call_valist (return_type, fn, nargs, args);
10980 : 151 : va_end (args);
10981 : 151 : return ret;
10982 : : }
10983 : :
10984 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10985 : : FN and a null static chain slot. NARGS is the number of call arguments
10986 : : which are specified as a va_list ARGS. */
10987 : :
10988 : : tree
10989 : 136423 : build_call_valist (tree return_type, tree fn, int nargs, va_list args)
10990 : : {
10991 : 136423 : tree t;
10992 : 136423 : int i;
10993 : :
10994 : 136423 : t = build_call_1 (return_type, fn, nargs);
10995 : 553843 : for (i = 0; i < nargs; i++)
10996 : 280997 : CALL_EXPR_ARG (t, i) = va_arg (args, tree);
10997 : 136423 : process_call_operands (t);
10998 : 136423 : return t;
10999 : : }
11000 : :
11001 : : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11002 : : FN and a null static chain slot. NARGS is the number of call arguments
11003 : : which are specified as a tree array ARGS. */
11004 : :
11005 : : tree
11006 : 188795692 : build_call_array_loc (location_t loc, tree return_type, tree fn,
11007 : : int nargs, const tree *args)
11008 : : {
11009 : 188795692 : tree t;
11010 : 188795692 : int i;
11011 : :
11012 : 188795692 : t = build_call_1 (return_type, fn, nargs);
11013 : 654427850 : for (i = 0; i < nargs; i++)
11014 : 276836466 : CALL_EXPR_ARG (t, i) = args[i];
11015 : 188795692 : process_call_operands (t);
11016 : 188795692 : SET_EXPR_LOCATION (t, loc);
11017 : 188795692 : return t;
11018 : : }
11019 : :
11020 : : /* Like build_call_array, but takes a vec. */
11021 : :
11022 : : tree
11023 : 40870112 : build_call_vec (tree return_type, tree fn, const vec<tree, va_gc> *args)
11024 : : {
11025 : 40870112 : tree ret, t;
11026 : 40870112 : unsigned int ix;
11027 : :
11028 : 40870112 : ret = build_call_1 (return_type, fn, vec_safe_length (args));
11029 : 108159579 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
11030 : 26419355 : CALL_EXPR_ARG (ret, ix) = t;
11031 : 40870112 : process_call_operands (ret);
11032 : 40870112 : return ret;
11033 : : }
11034 : :
11035 : : /* Conveniently construct a function call expression. FNDECL names the
11036 : : function to be called and N arguments are passed in the array
11037 : : ARGARRAY. */
11038 : :
11039 : : tree
11040 : 17398179 : build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray)
11041 : : {
11042 : 17398179 : tree fntype = TREE_TYPE (fndecl);
11043 : 17398179 : tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
11044 : :
11045 : 17398179 : return fold_build_call_array_loc (loc, TREE_TYPE (fntype), fn, n, argarray);
11046 : : }
11047 : :
11048 : : /* Conveniently construct a function call expression. FNDECL names the
11049 : : function to be called and the arguments are passed in the vector
11050 : : VEC. */
11051 : :
11052 : : tree
11053 : 20634 : build_call_expr_loc_vec (location_t loc, tree fndecl, vec<tree, va_gc> *vec)
11054 : : {
11055 : 20634 : return build_call_expr_loc_array (loc, fndecl, vec_safe_length (vec),
11056 : 20634 : vec_safe_address (vec));
11057 : : }
11058 : :
11059 : :
11060 : : /* Conveniently construct a function call expression. FNDECL names the
11061 : : function to be called, N is the number of arguments, and the "..."
11062 : : parameters are the argument expressions. */
11063 : :
11064 : : tree
11065 : 15808183 : build_call_expr_loc (location_t loc, tree fndecl, int n, ...)
11066 : : {
11067 : 15808183 : va_list ap;
11068 : 15808183 : tree *argarray = XALLOCAVEC (tree, n);
11069 : 15808183 : int i;
11070 : :
11071 : 15808183 : va_start (ap, n);
11072 : 18211753 : for (i = 0; i < n; i++)
11073 : 2403570 : argarray[i] = va_arg (ap, tree);
11074 : 15808183 : va_end (ap);
11075 : 15808183 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11076 : : }
11077 : :
11078 : : /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
11079 : : varargs macros aren't supported by all bootstrap compilers. */
11080 : :
11081 : : tree
11082 : 1564879 : build_call_expr (tree fndecl, int n, ...)
11083 : : {
11084 : 1564879 : va_list ap;
11085 : 1564879 : tree *argarray = XALLOCAVEC (tree, n);
11086 : 1564879 : int i;
11087 : :
11088 : 1564879 : va_start (ap, n);
11089 : 4592495 : for (i = 0; i < n; i++)
11090 : 3027616 : argarray[i] = va_arg (ap, tree);
11091 : 1564879 : va_end (ap);
11092 : 1564879 : return build_call_expr_loc_array (UNKNOWN_LOCATION, fndecl, n, argarray);
11093 : : }
11094 : :
11095 : : /* Build an internal call to IFN, with arguments ARGS[0:N-1] and with return
11096 : : type TYPE. This is just like CALL_EXPR, except its CALL_EXPR_FN is NULL.
11097 : : It will get gimplified later into an ordinary internal function. */
11098 : :
11099 : : tree
11100 : 321897 : build_call_expr_internal_loc_array (location_t loc, internal_fn ifn,
11101 : : tree type, int n, const tree *args)
11102 : : {
11103 : 321897 : tree t = build_call_1 (type, NULL_TREE, n);
11104 : 1097657 : for (int i = 0; i < n; ++i)
11105 : 775760 : CALL_EXPR_ARG (t, i) = args[i];
11106 : 321897 : SET_EXPR_LOCATION (t, loc);
11107 : 321897 : CALL_EXPR_IFN (t) = ifn;
11108 : 321897 : process_call_operands (t);
11109 : 321897 : return t;
11110 : : }
11111 : :
11112 : : /* Build internal call expression. This is just like CALL_EXPR, except
11113 : : its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
11114 : : internal function. */
11115 : :
11116 : : tree
11117 : 320871 : build_call_expr_internal_loc (location_t loc, enum internal_fn ifn,
11118 : : tree type, int n, ...)
11119 : : {
11120 : 320871 : va_list ap;
11121 : 320871 : tree *argarray = XALLOCAVEC (tree, n);
11122 : 320871 : int i;
11123 : :
11124 : 320871 : va_start (ap, n);
11125 : 1094581 : for (i = 0; i < n; i++)
11126 : 773710 : argarray[i] = va_arg (ap, tree);
11127 : 320871 : va_end (ap);
11128 : 320871 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11129 : : }
11130 : :
11131 : : /* Return a function call to FN, if the target is guaranteed to support it,
11132 : : or null otherwise.
11133 : :
11134 : : N is the number of arguments, passed in the "...", and TYPE is the
11135 : : type of the return value. */
11136 : :
11137 : : tree
11138 : 1825 : maybe_build_call_expr_loc (location_t loc, combined_fn fn, tree type,
11139 : : int n, ...)
11140 : : {
11141 : 1825 : va_list ap;
11142 : 1825 : tree *argarray = XALLOCAVEC (tree, n);
11143 : 1825 : int i;
11144 : :
11145 : 1825 : va_start (ap, n);
11146 : 4743 : for (i = 0; i < n; i++)
11147 : 2918 : argarray[i] = va_arg (ap, tree);
11148 : 1825 : va_end (ap);
11149 : 1825 : if (internal_fn_p (fn))
11150 : : {
11151 : 1024 : internal_fn ifn = as_internal_fn (fn);
11152 : 1024 : if (direct_internal_fn_p (ifn))
11153 : : {
11154 : 1 : tree_pair types = direct_internal_fn_types (ifn, type, argarray);
11155 : 1 : if (!direct_internal_fn_supported_p (ifn, types,
11156 : : OPTIMIZE_FOR_BOTH))
11157 : 1 : return NULL_TREE;
11158 : : }
11159 : 1023 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11160 : : }
11161 : : else
11162 : : {
11163 : 801 : tree fndecl = builtin_decl_implicit (as_builtin_fn (fn));
11164 : 801 : if (!fndecl)
11165 : : return NULL_TREE;
11166 : 693 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11167 : : }
11168 : : }
11169 : :
11170 : : /* Return a function call to the appropriate builtin alloca variant.
11171 : :
11172 : : SIZE is the size to be allocated. ALIGN, if non-zero, is the requested
11173 : : alignment of the allocated area. MAX_SIZE, if non-negative, is an upper
11174 : : bound for SIZE in case it is not a fixed value. */
11175 : :
11176 : : tree
11177 : 8838 : build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size)
11178 : : {
11179 : 8838 : if (max_size >= 0)
11180 : : {
11181 : 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX);
11182 : 0 : return
11183 : 0 : build_call_expr (t, 3, size, size_int (align), size_int (max_size));
11184 : : }
11185 : 8838 : else if (align > 0)
11186 : : {
11187 : 8838 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
11188 : 8838 : return build_call_expr (t, 2, size, size_int (align));
11189 : : }
11190 : : else
11191 : : {
11192 : 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA);
11193 : 0 : return build_call_expr (t, 1, size);
11194 : : }
11195 : : }
11196 : :
11197 : : /* The built-in decl to use to mark code points believed to be unreachable.
11198 : : Typically __builtin_unreachable, but __builtin_trap if
11199 : : -fsanitize=unreachable -fsanitize-trap=unreachable. If only
11200 : : -fsanitize=unreachable, we rely on sanopt to replace calls with the
11201 : : appropriate ubsan function. When building a call directly, use
11202 : : {gimple_},build_builtin_unreachable instead. */
11203 : :
11204 : : tree
11205 : 226037 : builtin_decl_unreachable ()
11206 : : {
11207 : 226037 : enum built_in_function fncode = BUILT_IN_UNREACHABLE;
11208 : :
11209 : 452074 : if (sanitize_flags_p (SANITIZE_UNREACHABLE)
11210 : 226037 : ? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
11211 : 225571 : : flag_unreachable_traps)
11212 : 22 : fncode = BUILT_IN_UNREACHABLE_TRAP;
11213 : : /* For non-trapping sanitize, we will rewrite __builtin_unreachable () later,
11214 : : in the sanopt pass. */
11215 : :
11216 : 226037 : return builtin_decl_explicit (fncode);
11217 : : }
11218 : :
11219 : : /* Build a call to __builtin_unreachable, possibly rewritten by
11220 : : -fsanitize=unreachable. Use this rather than the above when practical. */
11221 : :
11222 : : tree
11223 : 14565609 : build_builtin_unreachable (location_t loc)
11224 : : {
11225 : 14565609 : tree data = NULL_TREE;
11226 : 14565609 : tree fn = sanitize_unreachable_fn (&data, loc);
11227 : 14565609 : return build_call_expr_loc (loc, fn, data != NULL_TREE, data);
11228 : : }
11229 : :
11230 : : /* Create a new constant string literal of type ELTYPE[SIZE] (or LEN
11231 : : if SIZE == -1) and return a tree node representing char* pointer to
11232 : : it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). When STR is nonnull
11233 : : the STRING_CST value is the LEN bytes at STR (the representation
11234 : : of the string, which may be wide). Otherwise it's all zeros. */
11235 : :
11236 : : tree
11237 : 86573 : build_string_literal (unsigned len, const char *str /* = NULL */,
11238 : : tree eltype /* = char_type_node */,
11239 : : unsigned HOST_WIDE_INT size /* = -1 */)
11240 : : {
11241 : 86573 : tree t = build_string (len, str);
11242 : : /* Set the maximum valid index based on the string length or SIZE. */
11243 : 173146 : unsigned HOST_WIDE_INT maxidx
11244 : 86573 : = (size == HOST_WIDE_INT_M1U ? len : size) - 1;
11245 : :
11246 : 86573 : tree index = build_index_type (size_int (maxidx));
11247 : 86573 : eltype = build_type_variant (eltype, 1, 0);
11248 : 86573 : tree type = build_array_type (eltype, index);
11249 : 86573 : TREE_TYPE (t) = type;
11250 : 86573 : TREE_CONSTANT (t) = 1;
11251 : 86573 : TREE_READONLY (t) = 1;
11252 : 86573 : TREE_STATIC (t) = 1;
11253 : :
11254 : 86573 : type = build_pointer_type (eltype);
11255 : 86573 : t = build1 (ADDR_EXPR, type,
11256 : : build4 (ARRAY_REF, eltype,
11257 : : t, integer_zero_node, NULL_TREE, NULL_TREE));
11258 : 86573 : return t;
11259 : : }
11260 : :
11261 : :
11262 : :
11263 : : /* Return true if T (assumed to be a DECL) must be assigned a memory
11264 : : location. */
11265 : :
11266 : : bool
11267 : 1949988645 : needs_to_live_in_memory (const_tree t)
11268 : : {
11269 : 1949988645 : return (TREE_ADDRESSABLE (t)
11270 : 1563586758 : || is_global_var (t)
11271 : 3084706049 : || (TREE_CODE (t) == RESULT_DECL
11272 : 8006886 : && !DECL_BY_REFERENCE (t)
11273 : 5609238 : && aggregate_value_p (t, current_function_decl)));
11274 : : }
11275 : :
11276 : : /* Return value of a constant X and sign-extend it. */
11277 : :
11278 : : HOST_WIDE_INT
11279 : 569935912 : int_cst_value (const_tree x)
11280 : : {
11281 : 569935912 : unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
11282 : 569935912 : unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
11283 : :
11284 : : /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
11285 : 569935912 : gcc_assert (cst_and_fits_in_hwi (x));
11286 : :
11287 : 569935912 : if (bits < HOST_BITS_PER_WIDE_INT)
11288 : : {
11289 : 555821356 : bool negative = ((val >> (bits - 1)) & 1) != 0;
11290 : 555821356 : if (negative)
11291 : 215680 : val |= HOST_WIDE_INT_M1U << (bits - 1) << 1;
11292 : : else
11293 : 555605676 : val &= ~(HOST_WIDE_INT_M1U << (bits - 1) << 1);
11294 : : }
11295 : :
11296 : 569935912 : return val;
11297 : : }
11298 : :
11299 : : /* If TYPE is an integral or pointer type, return an integer type with
11300 : : the same precision which is unsigned iff UNSIGNEDP is true, or itself
11301 : : if TYPE is already an integer type of signedness UNSIGNEDP.
11302 : : If TYPE is a floating-point type, return an integer type with the same
11303 : : bitsize and with the signedness given by UNSIGNEDP; this is useful
11304 : : when doing bit-level operations on a floating-point value. */
11305 : :
11306 : : tree
11307 : 86100077 : signed_or_unsigned_type_for (int unsignedp, tree type)
11308 : : {
11309 : 86100077 : if (ANY_INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) == unsignedp)
11310 : : return type;
11311 : :
11312 : 55654239 : if (TREE_CODE (type) == VECTOR_TYPE)
11313 : : {
11314 : 18445 : tree inner = TREE_TYPE (type);
11315 : 18445 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11316 : 18445 : if (!inner2)
11317 : : return NULL_TREE;
11318 : 18445 : if (inner == inner2)
11319 : : return type;
11320 : 18445 : machine_mode new_mode;
11321 : 36890 : if (VECTOR_MODE_P (TYPE_MODE (type))
11322 : 36821 : && related_int_vector_mode (TYPE_MODE (type)).exists (&new_mode))
11323 : 18376 : return build_vector_type_for_mode (inner2, new_mode);
11324 : 69 : return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
11325 : : }
11326 : :
11327 : : if (TREE_CODE (type) == COMPLEX_TYPE)
11328 : : {
11329 : 24 : tree inner = TREE_TYPE (type);
11330 : 24 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11331 : 24 : if (!inner2)
11332 : : return NULL_TREE;
11333 : 24 : if (inner == inner2)
11334 : : return type;
11335 : 24 : return build_complex_type (inner2);
11336 : : }
11337 : :
11338 : : unsigned int bits;
11339 : : if (INTEGRAL_TYPE_P (type)
11340 : : || POINTER_TYPE_P (type)
11341 : : || TREE_CODE (type) == OFFSET_TYPE)
11342 : 55635676 : bits = TYPE_PRECISION (type);
11343 : : else if (TREE_CODE (type) == REAL_TYPE)
11344 : 188 : bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (type));
11345 : : else
11346 : : return NULL_TREE;
11347 : :
11348 : 55635770 : if (TREE_CODE (type) == BITINT_TYPE && (unsignedp || bits > 1))
11349 : 1488 : return build_bitint_type (bits, unsignedp);
11350 : 55634282 : return build_nonstandard_integer_type (bits, unsignedp);
11351 : : }
11352 : :
11353 : : /* If TYPE is an integral or pointer type, return an integer type with
11354 : : the same precision which is unsigned, or itself if TYPE is already an
11355 : : unsigned integer type. If TYPE is a floating-point type, return an
11356 : : unsigned integer type with the same bitsize as TYPE. */
11357 : :
11358 : : tree
11359 : 76901139 : unsigned_type_for (tree type)
11360 : : {
11361 : 76901139 : return signed_or_unsigned_type_for (1, type);
11362 : : }
11363 : :
11364 : : /* If TYPE is an integral or pointer type, return an integer type with
11365 : : the same precision which is signed, or itself if TYPE is already a
11366 : : signed integer type. If TYPE is a floating-point type, return a
11367 : : signed integer type with the same bitsize as TYPE. */
11368 : :
11369 : : tree
11370 : 9175434 : signed_type_for (tree type)
11371 : : {
11372 : 9175434 : return signed_or_unsigned_type_for (0, type);
11373 : : }
11374 : :
11375 : : /* - For VECTOR_TYPEs:
11376 : : - The truth type must be a VECTOR_BOOLEAN_TYPE.
11377 : : - The number of elements must match (known_eq).
11378 : : - targetm.vectorize.get_mask_mode exists, and exactly
11379 : : the same mode as the truth type.
11380 : : - Otherwise, the truth type must be a BOOLEAN_TYPE
11381 : : or useless_type_conversion_p to BOOLEAN_TYPE. */
11382 : : bool
11383 : 1924 : is_truth_type_for (tree type, tree truth_type)
11384 : : {
11385 : 1924 : machine_mode mask_mode = TYPE_MODE (truth_type);
11386 : 1924 : machine_mode vmode = TYPE_MODE (type);
11387 : 1924 : machine_mode tmask_mode;
11388 : :
11389 : 1924 : if (TREE_CODE (type) == VECTOR_TYPE)
11390 : : {
11391 : 1924 : if (VECTOR_BOOLEAN_TYPE_P (truth_type)
11392 : 1924 : && known_eq (TYPE_VECTOR_SUBPARTS (type),
11393 : : TYPE_VECTOR_SUBPARTS (truth_type))
11394 : 1924 : && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode)
11395 : 3848 : && tmask_mode == mask_mode)
11396 : 1905 : return true;
11397 : :
11398 : 19 : return false;
11399 : : }
11400 : :
11401 : 0 : return useless_type_conversion_p (boolean_type_node, truth_type);
11402 : : }
11403 : :
11404 : : /* If TYPE is a vector type, return a signed integer vector type with the
11405 : : same width and number of subparts. Otherwise return boolean_type_node. */
11406 : :
11407 : : tree
11408 : 3866605 : truth_type_for (tree type)
11409 : : {
11410 : 3866605 : if (TREE_CODE (type) == VECTOR_TYPE)
11411 : : {
11412 : 1972479 : if (VECTOR_BOOLEAN_TYPE_P (type))
11413 : : return type;
11414 : 1900884 : return build_truth_vector_type_for (type);
11415 : : }
11416 : : else
11417 : 1894126 : return boolean_type_node;
11418 : : }
11419 : :
11420 : : /* Returns the largest value obtainable by casting something in INNER type to
11421 : : OUTER type. */
11422 : :
11423 : : tree
11424 : 10529738 : upper_bound_in_type (tree outer, tree inner)
11425 : : {
11426 : 10529738 : unsigned int det = 0;
11427 : 10529738 : unsigned oprec = TYPE_PRECISION (outer);
11428 : 10529738 : unsigned iprec = TYPE_PRECISION (inner);
11429 : 10529738 : unsigned prec;
11430 : :
11431 : : /* Compute a unique number for every combination. */
11432 : 10529738 : det |= (oprec > iprec) ? 4 : 0;
11433 : 10529738 : det |= TYPE_UNSIGNED (outer) ? 2 : 0;
11434 : 10529738 : det |= TYPE_UNSIGNED (inner) ? 1 : 0;
11435 : :
11436 : : /* Determine the exponent to use. */
11437 : 10529738 : switch (det)
11438 : : {
11439 : 6960252 : case 0:
11440 : 6960252 : case 1:
11441 : : /* oprec <= iprec, outer: signed, inner: don't care. */
11442 : 6960252 : prec = oprec - 1;
11443 : 6960252 : break;
11444 : : case 2:
11445 : : case 3:
11446 : : /* oprec <= iprec, outer: unsigned, inner: don't care. */
11447 : : prec = oprec;
11448 : : break;
11449 : 21566 : case 4:
11450 : : /* oprec > iprec, outer: signed, inner: signed. */
11451 : 21566 : prec = iprec - 1;
11452 : 21566 : break;
11453 : : case 5:
11454 : : /* oprec > iprec, outer: signed, inner: unsigned. */
11455 : 8629 : prec = iprec;
11456 : : break;
11457 : : case 6:
11458 : : /* oprec > iprec, outer: unsigned, inner: signed. */
11459 : : prec = oprec;
11460 : : break;
11461 : : case 7:
11462 : : /* oprec > iprec, outer: unsigned, inner: unsigned. */
11463 : 8629 : prec = iprec;
11464 : : break;
11465 : : default:
11466 : : gcc_unreachable ();
11467 : : }
11468 : :
11469 : 10529738 : return wide_int_to_tree (outer,
11470 : 10529738 : wi::mask (prec, false, TYPE_PRECISION (outer)));
11471 : : }
11472 : :
11473 : : /* Returns the smallest value obtainable by casting something in INNER type to
11474 : : OUTER type. */
11475 : :
11476 : : tree
11477 : 8014904 : lower_bound_in_type (tree outer, tree inner)
11478 : : {
11479 : 8014904 : unsigned oprec = TYPE_PRECISION (outer);
11480 : 8014904 : unsigned iprec = TYPE_PRECISION (inner);
11481 : :
11482 : : /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
11483 : : and obtain 0. */
11484 : 8014904 : if (TYPE_UNSIGNED (outer)
11485 : : /* If we are widening something of an unsigned type, OUTER type
11486 : : contains all values of INNER type. In particular, both INNER
11487 : : and OUTER types have zero in common. */
11488 : 8014904 : || (oprec > iprec && TYPE_UNSIGNED (inner)))
11489 : 2123047 : return build_int_cst (outer, 0);
11490 : : else
11491 : : {
11492 : : /* If we are widening a signed type to another signed type, we
11493 : : want to obtain -2^^(iprec-1). If we are keeping the
11494 : : precision or narrowing to a signed type, we want to obtain
11495 : : -2^(oprec-1). */
11496 : 5891857 : unsigned prec = oprec > iprec ? iprec : oprec;
11497 : 5891857 : return wide_int_to_tree (outer,
11498 : 11783714 : wi::mask (prec - 1, true,
11499 : 5891857 : TYPE_PRECISION (outer)));
11500 : : }
11501 : : }
11502 : :
11503 : : /* Return true if two operands that are suitable for PHI nodes are
11504 : : necessarily equal. Specifically, both ARG0 and ARG1 must be either
11505 : : SSA_NAME or invariant. Note that this is strictly an optimization.
11506 : : That is, callers of this function can directly call operand_equal_p
11507 : : and get the same result, only slower. */
11508 : :
11509 : : bool
11510 : 20959753 : operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
11511 : : {
11512 : 20959753 : if (arg0 == arg1)
11513 : : return true;
11514 : 19195526 : if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
11515 : : return false;
11516 : 3644907 : return operand_equal_p (arg0, arg1, 0);
11517 : : }
11518 : :
11519 : : /* Returns number of zeros at the end of binary representation of X. */
11520 : :
11521 : : tree
11522 : 8775688 : num_ending_zeros (const_tree x)
11523 : : {
11524 : 8775688 : return build_int_cst (TREE_TYPE (x), wi::ctz (wi::to_wide (x)));
11525 : : }
11526 : :
11527 : :
11528 : : #define WALK_SUBTREE(NODE) \
11529 : : do \
11530 : : { \
11531 : : result = walk_tree_1 (&(NODE), func, data, pset, lh); \
11532 : : if (result) \
11533 : : return result; \
11534 : : } \
11535 : : while (0)
11536 : :
11537 : : /* This is a subroutine of walk_tree that walks field of TYPE that are to
11538 : : be walked whenever a type is seen in the tree. Rest of operands and return
11539 : : value are as for walk_tree. */
11540 : :
11541 : : static tree
11542 : 3758972172 : walk_type_fields (tree type, walk_tree_fn func, void *data,
11543 : : hash_set<tree> *pset, walk_tree_lh lh)
11544 : : {
11545 : 3758972172 : tree result = NULL_TREE;
11546 : :
11547 : 3758972172 : switch (TREE_CODE (type))
11548 : : {
11549 : 1108733926 : case POINTER_TYPE:
11550 : 1108733926 : case REFERENCE_TYPE:
11551 : 1108733926 : case VECTOR_TYPE:
11552 : : /* We have to worry about mutually recursive pointers. These can't
11553 : : be written in C. They can in Ada. It's pathological, but
11554 : : there's an ACATS test (c38102a) that checks it. Deal with this
11555 : : by checking if we're pointing to another pointer, that one
11556 : : points to another pointer, that one does too, and we have no htab.
11557 : : If so, get a hash table. We check three levels deep to avoid
11558 : : the cost of the hash table if we don't need one. */
11559 : 2192134487 : if (POINTER_TYPE_P (TREE_TYPE (type))
11560 : 25333432 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
11561 : 4851696 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
11562 : 1113556304 : && !pset)
11563 : : {
11564 : 0 : result = walk_tree_without_duplicates (&TREE_TYPE (type),
11565 : : func, data);
11566 : 0 : if (result)
11567 : : return result;
11568 : :
11569 : : break;
11570 : : }
11571 : :
11572 : : /* fall through */
11573 : :
11574 : 1111867712 : case COMPLEX_TYPE:
11575 : 1111867712 : WALK_SUBTREE (TREE_TYPE (type));
11576 : : break;
11577 : :
11578 : 215153886 : case METHOD_TYPE:
11579 : 215153886 : WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
11580 : :
11581 : : /* Fall through. */
11582 : :
11583 : 351153515 : case FUNCTION_TYPE:
11584 : 351153515 : WALK_SUBTREE (TREE_TYPE (type));
11585 : 351153477 : {
11586 : 351153477 : tree arg;
11587 : :
11588 : : /* We never want to walk into default arguments. */
11589 : 1357493361 : for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
11590 : 1006369133 : WALK_SUBTREE (TREE_VALUE (arg));
11591 : : }
11592 : : break;
11593 : :
11594 : 12103188 : case ARRAY_TYPE:
11595 : : /* Don't follow this nodes's type if a pointer for fear that
11596 : : we'll have infinite recursion. If we have a PSET, then we
11597 : : need not fear. */
11598 : 12103188 : if (pset
11599 : 12103188 : || (!POINTER_TYPE_P (TREE_TYPE (type))
11600 : 106188 : && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
11601 : 12101489 : WALK_SUBTREE (TREE_TYPE (type));
11602 : 12100644 : WALK_SUBTREE (TYPE_DOMAIN (type));
11603 : : break;
11604 : :
11605 : 926923 : case OFFSET_TYPE:
11606 : 926923 : WALK_SUBTREE (TREE_TYPE (type));
11607 : 926091 : WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
11608 : : break;
11609 : :
11610 : : default:
11611 : : break;
11612 : : }
11613 : :
11614 : : return NULL_TREE;
11615 : : }
11616 : :
11617 : : /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11618 : : called with the DATA and the address of each sub-tree. If FUNC returns a
11619 : : non-NULL value, the traversal is stopped, and the value returned by FUNC
11620 : : is returned. If PSET is non-NULL it is used to record the nodes visited,
11621 : : and to avoid visiting a node more than once. */
11622 : :
11623 : : tree
11624 : 95949712851 : walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
11625 : : hash_set<tree> *pset, walk_tree_lh lh)
11626 : : {
11627 : : #define WALK_SUBTREE_TAIL(NODE) \
11628 : : do \
11629 : : { \
11630 : : tp = & (NODE); \
11631 : : goto tail_recurse; \
11632 : : } \
11633 : : while (0)
11634 : :
11635 : >11646*10^7 : tail_recurse:
11636 : : /* Skip empty subtrees. */
11637 : >11646*10^7 : if (!*tp)
11638 : : return NULL_TREE;
11639 : :
11640 : : /* Don't walk the same tree twice, if the user has requested
11641 : : that we avoid doing so. */
11642 : 95676857762 : if (pset && pset->add (*tp))
11643 : : return NULL_TREE;
11644 : :
11645 : : /* Call the function. */
11646 : 94517684801 : int walk_subtrees = 1;
11647 : 94517684801 : tree result = (*func) (tp, &walk_subtrees, data);
11648 : :
11649 : : /* If we found something, return it. */
11650 : 94517684801 : if (result)
11651 : : return result;
11652 : :
11653 : 94458132267 : tree t = *tp;
11654 : 94458132267 : tree_code code = TREE_CODE (t);
11655 : :
11656 : : /* Even if we didn't, FUNC may have decided that there was nothing
11657 : : interesting below this point in the tree. */
11658 : 94458132267 : if (!walk_subtrees)
11659 : : {
11660 : : /* But we still need to check our siblings. */
11661 : 62219164450 : if (code == TREE_LIST)
11662 : 94626 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11663 : 62219069824 : else if (code == OMP_CLAUSE)
11664 : 874170 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11665 : : else
11666 : : return NULL_TREE;
11667 : : }
11668 : :
11669 : 32238967817 : if (lh)
11670 : : {
11671 : 15666126644 : result = (*lh) (tp, &walk_subtrees, func, data, pset);
11672 : 15666126644 : if (result || !walk_subtrees)
11673 : 2224823784 : return result;
11674 : : }
11675 : :
11676 : 30014144033 : switch (code)
11677 : : {
11678 : : case ERROR_MARK:
11679 : : case IDENTIFIER_NODE:
11680 : : case INTEGER_CST:
11681 : : case REAL_CST:
11682 : : case FIXED_CST:
11683 : : case STRING_CST:
11684 : : case BLOCK:
11685 : : case PLACEHOLDER_EXPR:
11686 : : case SSA_NAME:
11687 : : case FIELD_DECL:
11688 : : case RESULT_DECL:
11689 : : /* None of these have subtrees other than those already walked
11690 : : above. */
11691 : : break;
11692 : :
11693 : 239501919 : case TREE_LIST:
11694 : 239501919 : WALK_SUBTREE (TREE_VALUE (t));
11695 : 239002282 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11696 : :
11697 : 818544534 : case TREE_VEC:
11698 : 818544534 : {
11699 : 818544534 : int len = TREE_VEC_LENGTH (t);
11700 : :
11701 : 818544534 : if (len == 0)
11702 : : break;
11703 : :
11704 : : /* Walk all elements but the last. */
11705 : 1654598998 : for (int i = 0; i < len - 1; ++i)
11706 : 845114018 : WALK_SUBTREE (TREE_VEC_ELT (t, i));
11707 : :
11708 : : /* Now walk the last one as a tail call. */
11709 : 809484980 : WALK_SUBTREE_TAIL (TREE_VEC_ELT (t, len - 1));
11710 : : }
11711 : :
11712 : 4577809 : case VECTOR_CST:
11713 : 4577809 : {
11714 : 4577809 : unsigned len = vector_cst_encoded_nelts (t);
11715 : 4577809 : if (len == 0)
11716 : : break;
11717 : : /* Walk all elements but the last. */
11718 : 15786454 : for (unsigned i = 0; i < len - 1; ++i)
11719 : 11208789 : WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (t, i));
11720 : : /* Now walk the last one as a tail call. */
11721 : 4577665 : WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (t, len - 1));
11722 : : }
11723 : :
11724 : 533457 : case COMPLEX_CST:
11725 : 533457 : WALK_SUBTREE (TREE_REALPART (t));
11726 : 531891 : WALK_SUBTREE_TAIL (TREE_IMAGPART (t));
11727 : :
11728 : : case CONSTRUCTOR:
11729 : : {
11730 : : unsigned HOST_WIDE_INT idx;
11731 : : constructor_elt *ce;
11732 : :
11733 : 660947287 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce);
11734 : : idx++)
11735 : 211559197 : WALK_SUBTREE (ce->value);
11736 : : }
11737 : : break;
11738 : :
11739 : 3344835 : case SAVE_EXPR:
11740 : 3344835 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, 0));
11741 : :
11742 : 151624115 : case BIND_EXPR:
11743 : 151624115 : {
11744 : 151624115 : tree decl;
11745 : 248630330 : for (decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
11746 : : {
11747 : : /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11748 : : into declarations that are just mentioned, rather than
11749 : : declared; they don't really belong to this part of the tree.
11750 : : And, we can see cycles: the initializer for a declaration
11751 : : can refer to the declaration itself. */
11752 : 97006239 : WALK_SUBTREE (DECL_INITIAL (decl));
11753 : 97006215 : WALK_SUBTREE (DECL_SIZE (decl));
11754 : 97006215 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
11755 : : }
11756 : 151624091 : WALK_SUBTREE_TAIL (BIND_EXPR_BODY (t));
11757 : : }
11758 : :
11759 : 177974936 : case STATEMENT_LIST:
11760 : 177974936 : {
11761 : 177974936 : tree_stmt_iterator i;
11762 : 643717824 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
11763 : 465876292 : WALK_SUBTREE (*tsi_stmt_ptr (i));
11764 : : }
11765 : 177841532 : break;
11766 : :
11767 : 1676298 : case OMP_CLAUSE:
11768 : 1676298 : {
11769 : 1676298 : int len = omp_clause_num_ops[OMP_CLAUSE_CODE (t)];
11770 : 4388937 : for (int i = 0; i < len; i++)
11771 : 2712639 : WALK_SUBTREE (OMP_CLAUSE_OPERAND (t, i));
11772 : 1676298 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11773 : : }
11774 : :
11775 : 41825661 : case TARGET_EXPR:
11776 : 41825661 : {
11777 : 41825661 : int i, len;
11778 : :
11779 : : /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11780 : : But, we only want to walk once. */
11781 : 41825661 : len = (TREE_OPERAND (t, 3) == TREE_OPERAND (t, 1)) ? 2 : 3;
11782 : 167271565 : for (i = 0; i < len; ++i)
11783 : 125460231 : WALK_SUBTREE (TREE_OPERAND (t, i));
11784 : 41811334 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len));
11785 : : }
11786 : :
11787 : 92522652 : case DECL_EXPR:
11788 : : /* If this is a TYPE_DECL, walk into the fields of the type that it's
11789 : : defining. We only want to walk into these fields of a type in this
11790 : : case and not in the general case of a mere reference to the type.
11791 : :
11792 : : The criterion is as follows: if the field can be an expression, it
11793 : : must be walked only here. This should be in keeping with the fields
11794 : : that are directly gimplified in gimplify_type_sizes in order for the
11795 : : mark/copy-if-shared/unmark machinery of the gimplifier to work with
11796 : : variable-sized types.
11797 : :
11798 : : Note that DECLs get walked as part of processing the BIND_EXPR. */
11799 : 92522652 : if (TREE_CODE (DECL_EXPR_DECL (t)) == TYPE_DECL)
11800 : : {
11801 : : /* Call the function for the decl so e.g. copy_tree_body_r can
11802 : : replace it with the remapped one. */
11803 : 854918 : result = (*func) (&DECL_EXPR_DECL (t), &walk_subtrees, data);
11804 : 854918 : if (result || !walk_subtrees)
11805 : 49563 : return result;
11806 : :
11807 : 805355 : tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (t));
11808 : 805355 : if (TREE_CODE (*type_p) == ERROR_MARK)
11809 : : return NULL_TREE;
11810 : :
11811 : : /* Call the function for the type. See if it returns anything or
11812 : : doesn't want us to continue. If we are to continue, walk both
11813 : : the normal fields and those for the declaration case. */
11814 : 805355 : result = (*func) (type_p, &walk_subtrees, data);
11815 : 805355 : if (result || !walk_subtrees)
11816 : 69600 : return result;
11817 : :
11818 : 735755 : tree type = *type_p;
11819 : :
11820 : : /* But do not walk a pointed-to type since it may itself need to
11821 : : be walked in the declaration case if it isn't anonymous. */
11822 : 735755 : if (!POINTER_TYPE_P (type))
11823 : : {
11824 : 720062 : result = walk_type_fields (type, func, data, pset, lh);
11825 : 720062 : if (result)
11826 : : return result;
11827 : : }
11828 : :
11829 : : /* If this is a record type, also walk the fields. */
11830 : 735755 : if (RECORD_OR_UNION_TYPE_P (type))
11831 : : {
11832 : 273761 : tree field;
11833 : :
11834 : 1104564 : for (field = TYPE_FIELDS (type); field;
11835 : 830803 : field = DECL_CHAIN (field))
11836 : : {
11837 : : /* We'd like to look at the type of the field, but we can
11838 : : easily get infinite recursion. So assume it's pointed
11839 : : to elsewhere in the tree. Also, ignore things that
11840 : : aren't fields. */
11841 : 830803 : if (TREE_CODE (field) != FIELD_DECL)
11842 : 611930 : continue;
11843 : :
11844 : 218873 : WALK_SUBTREE (DECL_FIELD_OFFSET (field));
11845 : 218873 : WALK_SUBTREE (DECL_SIZE (field));
11846 : 218873 : WALK_SUBTREE (DECL_SIZE_UNIT (field));
11847 : 218873 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
11848 : 0 : WALK_SUBTREE (DECL_QUALIFIER (field));
11849 : : }
11850 : : }
11851 : :
11852 : : /* Same for scalar types. */
11853 : 461994 : else if (TREE_CODE (type) == BOOLEAN_TYPE
11854 : : || TREE_CODE (type) == ENUMERAL_TYPE
11855 : 461994 : || TREE_CODE (type) == INTEGER_TYPE
11856 : 461957 : || TREE_CODE (type) == FIXED_POINT_TYPE
11857 : 461957 : || TREE_CODE (type) == REAL_TYPE)
11858 : : {
11859 : 37 : WALK_SUBTREE (TYPE_MIN_VALUE (type));
11860 : 37 : WALK_SUBTREE (TYPE_MAX_VALUE (type));
11861 : : }
11862 : :
11863 : 735755 : WALK_SUBTREE (TYPE_SIZE (type));
11864 : 735755 : WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (type));
11865 : : }
11866 : : /* FALLTHRU */
11867 : :
11868 : 25326062293 : default:
11869 : 25326062293 : if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
11870 : : {
11871 : 19391153134 : int i, len;
11872 : :
11873 : : /* Walk over all the sub-trees of this operand. */
11874 : 19391153134 : len = TREE_OPERAND_LENGTH (t);
11875 : :
11876 : : /* Go through the subtrees. We need to do this in forward order so
11877 : : that the scope of a FOR_EXPR is handled properly. */
11878 : 19391153134 : if (len)
11879 : : {
11880 : 40222601623 : for (i = 0; i < len - 1; ++i)
11881 : 20961106249 : WALK_SUBTREE (TREE_OPERAND (t, i));
11882 : 19261495374 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len - 1));
11883 : : }
11884 : : }
11885 : : /* If this is a type, walk the needed fields in the type. */
11886 : 5934909159 : else if (TYPE_P (t))
11887 : 3758252110 : return walk_type_fields (t, func, data, pset, lh);
11888 : : break;
11889 : : }
11890 : :
11891 : : /* We didn't find what we were looking for. */
11892 : : return NULL_TREE;
11893 : :
11894 : : #undef WALK_SUBTREE_TAIL
11895 : : }
11896 : : #undef WALK_SUBTREE
11897 : :
11898 : : /* Like walk_tree, but does not walk duplicate nodes more than once. */
11899 : :
11900 : : tree
11901 : 2662300924 : walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
11902 : : walk_tree_lh lh)
11903 : : {
11904 : 2662300924 : tree result;
11905 : :
11906 : 2662300924 : hash_set<tree> pset;
11907 : 2662300924 : result = walk_tree_1 (tp, func, data, &pset, lh);
11908 : 2662300924 : return result;
11909 : 2662300924 : }
11910 : :
11911 : :
11912 : : tree
11913 : 874839501 : tree_block (tree t)
11914 : : {
11915 : 874839501 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
11916 : :
11917 : 874839501 : if (IS_EXPR_CODE_CLASS (c))
11918 : 874839501 : return LOCATION_BLOCK (t->exp.locus);
11919 : 0 : gcc_unreachable ();
11920 : : return NULL;
11921 : : }
11922 : :
11923 : : void
11924 : 451864419 : tree_set_block (tree t, tree b)
11925 : : {
11926 : 451864419 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
11927 : :
11928 : 451864419 : if (IS_EXPR_CODE_CLASS (c))
11929 : : {
11930 : 451864419 : t->exp.locus = set_block (t->exp.locus, b);
11931 : : }
11932 : : else
11933 : 0 : gcc_unreachable ();
11934 : 451864419 : }
11935 : :
11936 : : /* Create a nameless artificial label and put it in the current
11937 : : function context. The label has a location of LOC. Returns the
11938 : : newly created label. */
11939 : :
11940 : : tree
11941 : 30717785 : create_artificial_label (location_t loc)
11942 : : {
11943 : 30717785 : tree lab = build_decl (loc,
11944 : : LABEL_DECL, NULL_TREE, void_type_node);
11945 : :
11946 : 30717785 : DECL_ARTIFICIAL (lab) = 1;
11947 : 30717785 : DECL_IGNORED_P (lab) = 1;
11948 : 30717785 : DECL_CONTEXT (lab) = current_function_decl;
11949 : 30717785 : return lab;
11950 : : }
11951 : :
11952 : : /* Given a tree, try to return a useful variable name that we can use
11953 : : to prefix a temporary that is being assigned the value of the tree.
11954 : : I.E. given <temp> = &A, return A. */
11955 : :
11956 : : const char *
11957 : 24582111 : get_name (tree t)
11958 : : {
11959 : 26451225 : tree stripped_decl;
11960 : :
11961 : 26451225 : stripped_decl = t;
11962 : 26451225 : STRIP_NOPS (stripped_decl);
11963 : 26451225 : if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
11964 : 4044432 : return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
11965 : 22406793 : else if (TREE_CODE (stripped_decl) == SSA_NAME)
11966 : : {
11967 : 1251947 : tree name = SSA_NAME_IDENTIFIER (stripped_decl);
11968 : 295725 : if (!name)
11969 : : return NULL;
11970 : 294334 : return IDENTIFIER_POINTER (name);
11971 : : }
11972 : : else
11973 : : {
11974 : 21154846 : switch (TREE_CODE (stripped_decl))
11975 : : {
11976 : 1869114 : case ADDR_EXPR:
11977 : 1869114 : return get_name (TREE_OPERAND (stripped_decl, 0));
11978 : : default:
11979 : : return NULL;
11980 : : }
11981 : : }
11982 : : }
11983 : :
11984 : : /* Return true if TYPE has a variable argument list. */
11985 : :
11986 : : bool
11987 : 206066590 : stdarg_p (const_tree fntype)
11988 : : {
11989 : 206066590 : function_args_iterator args_iter;
11990 : 206066590 : tree n = NULL_TREE, t;
11991 : :
11992 : 206066590 : if (!fntype)
11993 : : return false;
11994 : :
11995 : 205933520 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
11996 : : return true;
11997 : :
11998 : 838274354 : FOREACH_FUNCTION_ARGS (fntype, t, args_iter)
11999 : : {
12000 : 633001056 : n = t;
12001 : : }
12002 : :
12003 : 205273298 : return n != NULL_TREE && n != void_type_node;
12004 : : }
12005 : :
12006 : : /* Return true if TYPE has a prototype. */
12007 : :
12008 : : bool
12009 : 707378967 : prototype_p (const_tree fntype)
12010 : : {
12011 : 707378967 : tree t;
12012 : :
12013 : 707378967 : gcc_assert (fntype != NULL_TREE);
12014 : :
12015 : 707378967 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12016 : : return true;
12017 : :
12018 : 706631318 : t = TYPE_ARG_TYPES (fntype);
12019 : 706631318 : return (t != NULL_TREE);
12020 : : }
12021 : :
12022 : : /* If BLOCK is inlined from an __attribute__((__artificial__))
12023 : : routine, return pointer to location from where it has been
12024 : : called. */
12025 : : location_t *
12026 : 167367 : block_nonartificial_location (tree block)
12027 : : {
12028 : 167367 : location_t *ret = NULL;
12029 : :
12030 : 432983 : while (block && TREE_CODE (block) == BLOCK
12031 : 526165 : && BLOCK_ABSTRACT_ORIGIN (block))
12032 : : {
12033 : 167302 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12034 : 167302 : if (TREE_CODE (ao) == FUNCTION_DECL)
12035 : : {
12036 : : /* If AO is an artificial inline, point RET to the
12037 : : call site locus at which it has been inlined and continue
12038 : : the loop, in case AO's caller is also an artificial
12039 : : inline. */
12040 : 70745 : if (DECL_DECLARED_INLINE_P (ao)
12041 : 70745 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
12042 : 1789 : ret = &BLOCK_SOURCE_LOCATION (block);
12043 : : else
12044 : : break;
12045 : : }
12046 : 96557 : else if (TREE_CODE (ao) != BLOCK)
12047 : : break;
12048 : :
12049 : 98346 : block = BLOCK_SUPERCONTEXT (block);
12050 : : }
12051 : 167367 : return ret;
12052 : : }
12053 : :
12054 : :
12055 : : /* If EXP is inlined from an __attribute__((__artificial__))
12056 : : function, return the location of the original call expression. */
12057 : :
12058 : : location_t
12059 : 97 : tree_nonartificial_location (tree exp)
12060 : : {
12061 : 97 : location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
12062 : :
12063 : 97 : if (loc)
12064 : 0 : return *loc;
12065 : : else
12066 : 97 : return EXPR_LOCATION (exp);
12067 : : }
12068 : :
12069 : : /* Return the location into which EXP has been inlined. Analogous
12070 : : to tree_nonartificial_location() above but not limited to artificial
12071 : : functions declared inline. If SYSTEM_HEADER is true, return
12072 : : the macro expansion point of the location if it's in a system header */
12073 : :
12074 : : location_t
12075 : 0 : tree_inlined_location (tree exp, bool system_header /* = true */)
12076 : : {
12077 : 0 : location_t loc = UNKNOWN_LOCATION;
12078 : :
12079 : 0 : tree block = TREE_BLOCK (exp);
12080 : :
12081 : 0 : while (block && TREE_CODE (block) == BLOCK
12082 : 0 : && BLOCK_ABSTRACT_ORIGIN (block))
12083 : : {
12084 : 0 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12085 : 0 : if (TREE_CODE (ao) == FUNCTION_DECL)
12086 : 0 : loc = BLOCK_SOURCE_LOCATION (block);
12087 : 0 : else if (TREE_CODE (ao) != BLOCK)
12088 : : break;
12089 : :
12090 : 0 : block = BLOCK_SUPERCONTEXT (block);
12091 : : }
12092 : :
12093 : 0 : if (loc == UNKNOWN_LOCATION)
12094 : : {
12095 : 0 : loc = EXPR_LOCATION (exp);
12096 : 0 : if (system_header)
12097 : : /* Only consider macro expansion when the block traversal failed
12098 : : to find a location. Otherwise it's not relevant. */
12099 : 0 : return expansion_point_location_if_in_system_header (loc);
12100 : : }
12101 : :
12102 : : return loc;
12103 : : }
12104 : :
12105 : : /* These are the hash table functions for the hash table of OPTIMIZATION_NODE
12106 : : nodes. */
12107 : :
12108 : : /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
12109 : :
12110 : : hashval_t
12111 : 823705891 : cl_option_hasher::hash (tree x)
12112 : : {
12113 : 823705891 : const_tree const t = x;
12114 : :
12115 : 823705891 : if (TREE_CODE (t) == OPTIMIZATION_NODE)
12116 : 96254227 : return cl_optimization_hash (TREE_OPTIMIZATION (t));
12117 : 727451664 : else if (TREE_CODE (t) == TARGET_OPTION_NODE)
12118 : 727451664 : return cl_target_option_hash (TREE_TARGET_OPTION (t));
12119 : : else
12120 : 0 : gcc_unreachable ();
12121 : : }
12122 : :
12123 : : /* Return nonzero if the value represented by *X (an OPTIMIZATION or
12124 : : TARGET_OPTION tree node) is the same as that given by *Y, which is the
12125 : : same. */
12126 : :
12127 : : bool
12128 : 891977732 : cl_option_hasher::equal (tree x, tree y)
12129 : : {
12130 : 891977732 : const_tree const xt = x;
12131 : 891977732 : const_tree const yt = y;
12132 : :
12133 : 891977732 : if (TREE_CODE (xt) != TREE_CODE (yt))
12134 : : return false;
12135 : :
12136 : 517186525 : if (TREE_CODE (xt) == OPTIMIZATION_NODE)
12137 : 95479366 : return cl_optimization_option_eq (TREE_OPTIMIZATION (xt),
12138 : 95479366 : TREE_OPTIMIZATION (yt));
12139 : 421707159 : else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
12140 : 421707159 : return cl_target_option_eq (TREE_TARGET_OPTION (xt),
12141 : 421707159 : TREE_TARGET_OPTION (yt));
12142 : : else
12143 : 0 : gcc_unreachable ();
12144 : : }
12145 : :
12146 : : /* Build an OPTIMIZATION_NODE based on the options in OPTS and OPTS_SET. */
12147 : :
12148 : : tree
12149 : 95768007 : build_optimization_node (struct gcc_options *opts,
12150 : : struct gcc_options *opts_set)
12151 : : {
12152 : 95768007 : tree t;
12153 : :
12154 : : /* Use the cache of optimization nodes. */
12155 : :
12156 : 95768007 : cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
12157 : : opts, opts_set);
12158 : :
12159 : 95768007 : tree *slot = cl_option_hash_table->find_slot (cl_optimization_node, INSERT);
12160 : 95768007 : t = *slot;
12161 : 95768007 : if (!t)
12162 : : {
12163 : : /* Insert this one into the hash table. */
12164 : 288866 : t = cl_optimization_node;
12165 : 288866 : *slot = t;
12166 : :
12167 : : /* Make a new node for next time round. */
12168 : 288866 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
12169 : : }
12170 : :
12171 : 95768007 : return t;
12172 : : }
12173 : :
12174 : : /* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET. */
12175 : :
12176 : : tree
12177 : 74235880 : build_target_option_node (struct gcc_options *opts,
12178 : : struct gcc_options *opts_set)
12179 : : {
12180 : 74235880 : tree t;
12181 : :
12182 : : /* Use the cache of optimization nodes. */
12183 : :
12184 : 74235880 : cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
12185 : : opts, opts_set);
12186 : :
12187 : 74235880 : tree *slot = cl_option_hash_table->find_slot (cl_target_option_node, INSERT);
12188 : 74235880 : t = *slot;
12189 : 74235880 : if (!t)
12190 : : {
12191 : : /* Insert this one into the hash table. */
12192 : 780432 : t = cl_target_option_node;
12193 : 780432 : *slot = t;
12194 : :
12195 : : /* Make a new node for next time round. */
12196 : 780432 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
12197 : : }
12198 : :
12199 : 74235880 : return t;
12200 : : }
12201 : :
12202 : : /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
12203 : : so that they aren't saved during PCH writing. */
12204 : :
12205 : : void
12206 : 465 : prepare_target_option_nodes_for_pch (void)
12207 : : {
12208 : 465 : hash_table<cl_option_hasher>::iterator iter = cl_option_hash_table->begin ();
12209 : 2790 : for (; iter != cl_option_hash_table->end (); ++iter)
12210 : 930 : if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
12211 : 465 : TREE_TARGET_GLOBALS (*iter) = NULL;
12212 : 465 : }
12213 : :
12214 : : /* Determine the "ultimate origin" of a block. */
12215 : :
12216 : : tree
12217 : 218053859 : block_ultimate_origin (const_tree block)
12218 : : {
12219 : 218053859 : tree origin = BLOCK_ABSTRACT_ORIGIN (block);
12220 : :
12221 : 218053859 : if (origin == NULL_TREE)
12222 : : return NULL_TREE;
12223 : : else
12224 : : {
12225 : 266160451 : gcc_checking_assert ((DECL_P (origin)
12226 : : && DECL_ORIGIN (origin) == origin)
12227 : : || BLOCK_ORIGIN (origin) == origin);
12228 : : return origin;
12229 : : }
12230 : : }
12231 : :
12232 : : /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
12233 : : no instruction. */
12234 : :
12235 : : bool
12236 : 1300445839 : tree_nop_conversion_p (const_tree outer_type, const_tree inner_type)
12237 : : {
12238 : : /* Do not strip casts into or out of differing address spaces. */
12239 : 1300445839 : if (POINTER_TYPE_P (outer_type)
12240 : 1300445839 : && TYPE_ADDR_SPACE (TREE_TYPE (outer_type)) != ADDR_SPACE_GENERIC)
12241 : : {
12242 : 639 : if (!POINTER_TYPE_P (inner_type)
12243 : 639 : || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
12244 : 558 : != TYPE_ADDR_SPACE (TREE_TYPE (inner_type))))
12245 : : return false;
12246 : : }
12247 : 1300445200 : else if (POINTER_TYPE_P (inner_type)
12248 : 1300445200 : && TYPE_ADDR_SPACE (TREE_TYPE (inner_type)) != ADDR_SPACE_GENERIC)
12249 : : {
12250 : : /* We already know that outer_type is not a pointer with
12251 : : a non-generic address space. */
12252 : : return false;
12253 : : }
12254 : :
12255 : : /* Use precision rather then machine mode when we can, which gives
12256 : : the correct answer even for submode (bit-field) types. */
12257 : 1300442903 : if ((INTEGRAL_TYPE_P (outer_type)
12258 : 431653770 : || POINTER_TYPE_P (outer_type)
12259 : 71858088 : || TREE_CODE (outer_type) == OFFSET_TYPE)
12260 : 1228595294 : && (INTEGRAL_TYPE_P (inner_type)
12261 : 436436120 : || POINTER_TYPE_P (inner_type)
12262 : 1041527 : || TREE_CODE (inner_type) == OFFSET_TYPE))
12263 : 1227576640 : return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
12264 : :
12265 : : /* Otherwise fall back on comparing machine modes (e.g. for
12266 : : aggregate types, floats). */
12267 : 72866263 : return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
12268 : : }
12269 : :
12270 : : /* Return true iff conversion in EXP generates no instruction. Mark
12271 : : it inline so that we fully inline into the stripping functions even
12272 : : though we have two uses of this function. */
12273 : :
12274 : : static inline bool
12275 : 17466685659 : tree_nop_conversion (const_tree exp)
12276 : : {
12277 : 17466685659 : tree outer_type, inner_type;
12278 : :
12279 : 17466685659 : if (location_wrapper_p (exp))
12280 : : return true;
12281 : 17424549168 : if (!CONVERT_EXPR_P (exp)
12282 : 16651352747 : && TREE_CODE (exp) != NON_LVALUE_EXPR)
12283 : : return false;
12284 : :
12285 : 785861207 : outer_type = TREE_TYPE (exp);
12286 : 785861207 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12287 : 785861207 : if (!inner_type || inner_type == error_mark_node)
12288 : : return false;
12289 : :
12290 : 785861207 : return tree_nop_conversion_p (outer_type, inner_type);
12291 : : }
12292 : :
12293 : : /* Return true iff conversion in EXP generates no instruction. Don't
12294 : : consider conversions changing the signedness. */
12295 : :
12296 : : static bool
12297 : 1738694824 : tree_sign_nop_conversion (const_tree exp)
12298 : : {
12299 : 1738694824 : tree outer_type, inner_type;
12300 : :
12301 : 1738694824 : if (!tree_nop_conversion (exp))
12302 : : return false;
12303 : :
12304 : 128184187 : outer_type = TREE_TYPE (exp);
12305 : 128184187 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12306 : :
12307 : 128184187 : return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
12308 : 128184187 : && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
12309 : : }
12310 : :
12311 : : /* Strip conversions from EXP according to tree_nop_conversion and
12312 : : return the resulting expression. */
12313 : :
12314 : : tree
12315 : 15167097206 : tree_strip_nop_conversions (tree exp)
12316 : : {
12317 : 15727990835 : while (tree_nop_conversion (exp))
12318 : 560893629 : exp = TREE_OPERAND (exp, 0);
12319 : 15167097206 : return exp;
12320 : : }
12321 : :
12322 : : /* Strip conversions from EXP according to tree_sign_nop_conversion
12323 : : and return the resulting expression. */
12324 : :
12325 : : tree
12326 : 1633574101 : tree_strip_sign_nop_conversions (tree exp)
12327 : : {
12328 : 1738694824 : while (tree_sign_nop_conversion (exp))
12329 : 105120723 : exp = TREE_OPERAND (exp, 0);
12330 : 1633574101 : return exp;
12331 : : }
12332 : :
12333 : : /* Avoid any floating point extensions from EXP. */
12334 : : tree
12335 : 82122873 : strip_float_extensions (tree exp)
12336 : : {
12337 : 82260294 : tree sub, expt, subt;
12338 : :
12339 : : /* For floating point constant look up the narrowest type that can hold
12340 : : it properly and handle it like (type)(narrowest_type)constant.
12341 : : This way we can optimize for instance a=a*2.0 where "a" is float
12342 : : but 2.0 is double constant. */
12343 : 82260294 : if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
12344 : : {
12345 : 2523109 : REAL_VALUE_TYPE orig;
12346 : 2523109 : tree type = NULL;
12347 : :
12348 : 2523109 : orig = TREE_REAL_CST (exp);
12349 : 2523109 : if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node)
12350 : 2523109 : && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
12351 : 140563 : type = float_type_node;
12352 : 2382546 : else if (TYPE_PRECISION (TREE_TYPE (exp))
12353 : 2382546 : > TYPE_PRECISION (double_type_node)
12354 : 2382546 : && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
12355 : 35199 : type = double_type_node;
12356 : 2523109 : if (type)
12357 : 175762 : return build_real_truncate (type, orig);
12358 : : }
12359 : :
12360 : 82084532 : if (!CONVERT_EXPR_P (exp))
12361 : : return exp;
12362 : :
12363 : 3936704 : sub = TREE_OPERAND (exp, 0);
12364 : 3936704 : subt = TREE_TYPE (sub);
12365 : 3936704 : expt = TREE_TYPE (exp);
12366 : :
12367 : 3936704 : if (!FLOAT_TYPE_P (subt))
12368 : : return exp;
12369 : :
12370 : 483181 : if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
12371 : : return exp;
12372 : :
12373 : 161425 : if (element_precision (subt) > element_precision (expt))
12374 : : return exp;
12375 : :
12376 : : return strip_float_extensions (sub);
12377 : : }
12378 : :
12379 : : /* Strip out all handled components that produce invariant
12380 : : offsets. */
12381 : :
12382 : : const_tree
12383 : 5678306375 : strip_invariant_refs (const_tree op)
12384 : : {
12385 : 6589325661 : while (handled_component_p (op))
12386 : : {
12387 : 921921857 : switch (TREE_CODE (op))
12388 : : {
12389 : 159336633 : case ARRAY_REF:
12390 : 159336633 : case ARRAY_RANGE_REF:
12391 : 159336633 : if (!is_gimple_constant (TREE_OPERAND (op, 1))
12392 : 149890730 : || TREE_OPERAND (op, 2) != NULL_TREE
12393 : 148566259 : || TREE_OPERAND (op, 3) != NULL_TREE)
12394 : : return NULL;
12395 : : break;
12396 : :
12397 : 762391022 : case COMPONENT_REF:
12398 : 762391022 : if (TREE_OPERAND (op, 2) != NULL_TREE)
12399 : : return NULL;
12400 : : break;
12401 : :
12402 : 911019286 : default:;
12403 : : }
12404 : 911019286 : op = TREE_OPERAND (op, 0);
12405 : : }
12406 : :
12407 : : return op;
12408 : : }
12409 : :
12410 : : /* Strip handled components with zero offset from OP. */
12411 : :
12412 : : tree
12413 : 561748 : strip_zero_offset_components (tree op)
12414 : : {
12415 : 561748 : while (TREE_CODE (op) == COMPONENT_REF
12416 : 436793 : && integer_zerop (DECL_FIELD_OFFSET (TREE_OPERAND (op, 1)))
12417 : 1108295 : && integer_zerop (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (op, 1))))
12418 : 179775 : op = TREE_OPERAND (op, 0);
12419 : 561748 : return op;
12420 : : }
12421 : :
12422 : : static GTY(()) tree gcc_eh_personality_decl;
12423 : :
12424 : : /* Return the GCC personality function decl. */
12425 : :
12426 : : tree
12427 : 395 : lhd_gcc_personality (void)
12428 : : {
12429 : 395 : if (!gcc_eh_personality_decl)
12430 : 153 : gcc_eh_personality_decl = build_personality_function ("gcc");
12431 : 395 : return gcc_eh_personality_decl;
12432 : : }
12433 : :
12434 : : /* TARGET is a call target of GIMPLE call statement
12435 : : (obtained by gimple_call_fn). Return true if it is
12436 : : OBJ_TYPE_REF representing an virtual call of C++ method.
12437 : : (As opposed to OBJ_TYPE_REF representing objc calls
12438 : : through a cast where middle-end devirtualization machinery
12439 : : can't apply.) FOR_DUMP_P is true when being called from
12440 : : the dump routines. */
12441 : :
12442 : : bool
12443 : 27254626 : virtual_method_call_p (const_tree target, bool for_dump_p)
12444 : : {
12445 : 27254626 : if (TREE_CODE (target) != OBJ_TYPE_REF)
12446 : : return false;
12447 : 1128835 : tree t = TREE_TYPE (target);
12448 : 1128835 : gcc_checking_assert (TREE_CODE (t) == POINTER_TYPE);
12449 : 1128835 : t = TREE_TYPE (t);
12450 : 1128835 : if (TREE_CODE (t) == FUNCTION_TYPE)
12451 : : return false;
12452 : 1127727 : gcc_checking_assert (TREE_CODE (t) == METHOD_TYPE);
12453 : : /* If we do not have BINFO associated, it means that type was built
12454 : : without devirtualization enabled. Do not consider this a virtual
12455 : : call. */
12456 : 1127727 : if (!TYPE_BINFO (obj_type_ref_class (target, for_dump_p)))
12457 : : return false;
12458 : : return true;
12459 : : }
12460 : :
12461 : : /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
12462 : :
12463 : : static tree
12464 : 75 : lookup_binfo_at_offset (tree binfo, tree type, HOST_WIDE_INT pos)
12465 : : {
12466 : 75 : unsigned int i;
12467 : 75 : tree base_binfo, b;
12468 : :
12469 : 84 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12470 : 75 : if (pos == tree_to_shwi (BINFO_OFFSET (base_binfo))
12471 : 75 : && types_same_for_odr (TREE_TYPE (base_binfo), type))
12472 : : return base_binfo;
12473 : 50 : else if ((b = lookup_binfo_at_offset (base_binfo, type, pos)) != NULL)
12474 : : return b;
12475 : : return NULL;
12476 : : }
12477 : :
12478 : : /* Try to find a base info of BINFO that would have its field decl at offset
12479 : : OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12480 : : found, return, otherwise return NULL_TREE. */
12481 : :
12482 : : tree
12483 : 366160 : get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
12484 : : {
12485 : 366160 : tree type = BINFO_TYPE (binfo);
12486 : :
12487 : 1021404 : while (true)
12488 : : {
12489 : 693782 : HOST_WIDE_INT pos, size;
12490 : 693782 : tree fld;
12491 : 693782 : int i;
12492 : :
12493 : 693782 : if (types_same_for_odr (type, expected_type))
12494 : 366160 : return binfo;
12495 : 327622 : if (maybe_lt (offset, 0))
12496 : : return NULL_TREE;
12497 : :
12498 : 2013347 : for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
12499 : : {
12500 : 2013347 : if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld))
12501 : 1685549 : continue;
12502 : :
12503 : 327798 : pos = int_bit_position (fld);
12504 : 327798 : size = tree_to_uhwi (DECL_SIZE (fld));
12505 : 2013523 : if (known_in_range_p (offset, pos, size))
12506 : : break;
12507 : : }
12508 : 327622 : if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
12509 : : return NULL_TREE;
12510 : :
12511 : : /* Offset 0 indicates the primary base, whose vtable contents are
12512 : : represented in the binfo for the derived class. */
12513 : 327622 : else if (maybe_ne (offset, 0))
12514 : : {
12515 : 187 : tree found_binfo = NULL, base_binfo;
12516 : : /* Offsets in BINFO are in bytes relative to the whole structure
12517 : : while POS is in bits relative to the containing field. */
12518 : 187 : int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos
12519 : 187 : / BITS_PER_UNIT);
12520 : :
12521 : 353 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12522 : 328 : if (tree_to_shwi (BINFO_OFFSET (base_binfo)) == binfo_offset
12523 : 328 : && types_same_for_odr (TREE_TYPE (base_binfo), TREE_TYPE (fld)))
12524 : : {
12525 : : found_binfo = base_binfo;
12526 : : break;
12527 : : }
12528 : 187 : if (found_binfo)
12529 : : binfo = found_binfo;
12530 : : else
12531 : 25 : binfo = lookup_binfo_at_offset (binfo, TREE_TYPE (fld),
12532 : : binfo_offset);
12533 : : }
12534 : :
12535 : 327622 : type = TREE_TYPE (fld);
12536 : 327622 : offset -= pos;
12537 : 327622 : }
12538 : : }
12539 : :
12540 : : /* PR 84195: Replace control characters in "unescaped" with their
12541 : : escaped equivalents. Allow newlines if -fmessage-length has
12542 : : been set to a non-zero value. This is done here, rather than
12543 : : where the attribute is recorded as the message length can
12544 : : change between these two locations. */
12545 : :
12546 : : void
12547 : 130169 : escaped_string::escape (const char *unescaped)
12548 : : {
12549 : 130169 : char *escaped;
12550 : 130169 : size_t i, new_i, len;
12551 : :
12552 : 130169 : if (m_owned)
12553 : 8 : free (m_str);
12554 : :
12555 : 130169 : m_str = const_cast<char *> (unescaped);
12556 : 130169 : m_owned = false;
12557 : :
12558 : 130169 : if (unescaped == NULL || *unescaped == 0)
12559 : : return;
12560 : :
12561 : 130161 : len = strlen (unescaped);
12562 : 130161 : escaped = NULL;
12563 : 130161 : new_i = 0;
12564 : :
12565 : 3809509 : for (i = 0; i < len; i++)
12566 : : {
12567 : 3679348 : char c = unescaped[i];
12568 : :
12569 : 3679348 : if (!ISCNTRL (c))
12570 : : {
12571 : 3679263 : if (escaped)
12572 : 33 : escaped[new_i++] = c;
12573 : 3679263 : continue;
12574 : : }
12575 : :
12576 : 85 : if (c != '\n' || !pp_is_wrapping_line (global_dc->get_reference_printer ()))
12577 : : {
12578 : 77 : if (escaped == NULL)
12579 : : {
12580 : : /* We only allocate space for a new string if we
12581 : : actually encounter a control character that
12582 : : needs replacing. */
12583 : 19 : escaped = (char *) xmalloc (len * 2 + 1);
12584 : 19 : strncpy (escaped, unescaped, i);
12585 : 19 : new_i = i;
12586 : : }
12587 : :
12588 : 77 : escaped[new_i++] = '\\';
12589 : :
12590 : 77 : switch (c)
12591 : : {
12592 : 8 : case '\a': escaped[new_i++] = 'a'; break;
12593 : 8 : case '\b': escaped[new_i++] = 'b'; break;
12594 : 8 : case '\f': escaped[new_i++] = 'f'; break;
12595 : 15 : case '\n': escaped[new_i++] = 'n'; break;
12596 : 15 : case '\r': escaped[new_i++] = 'r'; break;
12597 : 15 : case '\t': escaped[new_i++] = 't'; break;
12598 : 8 : case '\v': escaped[new_i++] = 'v'; break;
12599 : 0 : default: escaped[new_i++] = '?'; break;
12600 : : }
12601 : : }
12602 : 8 : else if (escaped)
12603 : 4 : escaped[new_i++] = c;
12604 : : }
12605 : :
12606 : 130161 : if (escaped)
12607 : : {
12608 : 19 : escaped[new_i] = 0;
12609 : 19 : m_str = escaped;
12610 : 19 : m_owned = true;
12611 : : }
12612 : : }
12613 : :
12614 : : /* Warn about a use of an identifier which was marked deprecated. Returns
12615 : : whether a warning was given. */
12616 : :
12617 : : bool
12618 : 1258198 : warn_deprecated_use (tree node, tree attr)
12619 : : {
12620 : 1258198 : escaped_string msg;
12621 : :
12622 : 1258198 : if (node == 0 || !warn_deprecated_decl)
12623 : : return false;
12624 : :
12625 : 1253015 : if (!attr)
12626 : : {
12627 : 1143417 : if (DECL_P (node))
12628 : 1143289 : attr = DECL_ATTRIBUTES (node);
12629 : 128 : else if (TYPE_P (node))
12630 : : {
12631 : 128 : tree decl = TYPE_STUB_DECL (node);
12632 : 128 : if (decl)
12633 : 104 : attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
12634 : 24 : else if ((decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node)))
12635 : : != NULL_TREE)
12636 : : {
12637 : 6 : node = TREE_TYPE (decl);
12638 : 6 : attr = TYPE_ATTRIBUTES (node);
12639 : : }
12640 : : }
12641 : : }
12642 : :
12643 : 1143417 : if (attr)
12644 : 129858 : attr = lookup_attribute ("deprecated", attr);
12645 : :
12646 : 129858 : if (attr)
12647 : 129849 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12648 : :
12649 : 1253015 : bool w = false;
12650 : 1253015 : if (DECL_P (node))
12651 : : {
12652 : 1252877 : auto_diagnostic_group d;
12653 : 1252877 : if (msg)
12654 : 129800 : w = warning (OPT_Wdeprecated_declarations,
12655 : : "%qD is deprecated: %s", node, (const char *) msg);
12656 : : else
12657 : 1123077 : w = warning (OPT_Wdeprecated_declarations,
12658 : : "%qD is deprecated", node);
12659 : 1252877 : if (w)
12660 : 781 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12661 : 1252877 : }
12662 : 138 : else if (TYPE_P (node))
12663 : : {
12664 : 138 : tree what = NULL_TREE;
12665 : 138 : tree decl = TYPE_STUB_DECL (node);
12666 : :
12667 : 138 : if (TYPE_NAME (node))
12668 : : {
12669 : 133 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12670 : 10 : what = TYPE_NAME (node);
12671 : 123 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12672 : 123 : && DECL_NAME (TYPE_NAME (node)))
12673 : 123 : what = DECL_NAME (TYPE_NAME (node));
12674 : : }
12675 : :
12676 : 138 : auto_diagnostic_group d;
12677 : 138 : if (what)
12678 : : {
12679 : 133 : if (msg)
12680 : 47 : w = warning (OPT_Wdeprecated_declarations,
12681 : : "%qE is deprecated: %s", what, (const char *) msg);
12682 : : else
12683 : 86 : w = warning (OPT_Wdeprecated_declarations,
12684 : : "%qE is deprecated", what);
12685 : : }
12686 : : else
12687 : : {
12688 : 5 : if (msg)
12689 : 2 : w = warning (OPT_Wdeprecated_declarations,
12690 : : "type is deprecated: %s", (const char *) msg);
12691 : : else
12692 : 3 : w = warning (OPT_Wdeprecated_declarations,
12693 : : "type is deprecated");
12694 : : }
12695 : :
12696 : 138 : if (w && decl)
12697 : 111 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12698 : 138 : }
12699 : :
12700 : : return w;
12701 : 1258198 : }
12702 : :
12703 : : /* Error out with an identifier which was marked 'unavailable'. */
12704 : : void
12705 : 364 : error_unavailable_use (tree node, tree attr)
12706 : : {
12707 : 364 : escaped_string msg;
12708 : :
12709 : 364 : if (node == 0)
12710 : 0 : return;
12711 : :
12712 : 364 : if (!attr)
12713 : : {
12714 : 354 : if (DECL_P (node))
12715 : 294 : attr = DECL_ATTRIBUTES (node);
12716 : 60 : else if (TYPE_P (node))
12717 : : {
12718 : 60 : tree decl = TYPE_STUB_DECL (node);
12719 : 60 : if (decl)
12720 : 51 : attr = lookup_attribute ("unavailable",
12721 : 51 : TYPE_ATTRIBUTES (TREE_TYPE (decl)));
12722 : : }
12723 : : }
12724 : :
12725 : 354 : if (attr)
12726 : 152 : attr = lookup_attribute ("unavailable", attr);
12727 : :
12728 : 152 : if (attr)
12729 : 152 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12730 : :
12731 : 364 : if (DECL_P (node))
12732 : : {
12733 : 294 : auto_diagnostic_group d;
12734 : 294 : if (msg)
12735 : 117 : error ("%qD is unavailable: %s", node, (const char *) msg);
12736 : : else
12737 : 177 : error ("%qD is unavailable", node);
12738 : 294 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12739 : 294 : }
12740 : 70 : else if (TYPE_P (node))
12741 : : {
12742 : 70 : tree what = NULL_TREE;
12743 : 70 : tree decl = TYPE_STUB_DECL (node);
12744 : :
12745 : 70 : if (TYPE_NAME (node))
12746 : : {
12747 : 66 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12748 : 4 : what = TYPE_NAME (node);
12749 : 62 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12750 : 62 : && DECL_NAME (TYPE_NAME (node)))
12751 : 62 : what = DECL_NAME (TYPE_NAME (node));
12752 : : }
12753 : :
12754 : 70 : auto_diagnostic_group d;
12755 : 70 : if (what)
12756 : : {
12757 : 66 : if (msg)
12758 : 33 : error ("%qE is unavailable: %s", what, (const char *) msg);
12759 : : else
12760 : 33 : error ("%qE is unavailable", what);
12761 : : }
12762 : : else
12763 : : {
12764 : 4 : if (msg)
12765 : 2 : error ("type is unavailable: %s", (const char *) msg);
12766 : : else
12767 : 2 : error ("type is unavailable");
12768 : : }
12769 : :
12770 : 70 : if (decl)
12771 : 52 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12772 : 70 : }
12773 : 364 : }
12774 : :
12775 : : /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12776 : : somewhere in it. */
12777 : :
12778 : : bool
12779 : 5600404 : contains_bitfld_component_ref_p (const_tree ref)
12780 : : {
12781 : 11425930 : while (handled_component_p (ref))
12782 : : {
12783 : 5853775 : if (TREE_CODE (ref) == COMPONENT_REF
12784 : 5853775 : && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
12785 : : return true;
12786 : 5825526 : ref = TREE_OPERAND (ref, 0);
12787 : : }
12788 : :
12789 : : return false;
12790 : : }
12791 : :
12792 : : /* Try to determine whether a TRY_CATCH expression can fall through.
12793 : : This is a subroutine of block_may_fallthru. */
12794 : :
12795 : : static bool
12796 : 1 : try_catch_may_fallthru (const_tree stmt)
12797 : : {
12798 : 1 : tree_stmt_iterator i;
12799 : :
12800 : : /* If the TRY block can fall through, the whole TRY_CATCH can
12801 : : fall through. */
12802 : 1 : if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
12803 : : return true;
12804 : :
12805 : 1 : switch (TREE_CODE (TREE_OPERAND (stmt, 1)))
12806 : : {
12807 : 0 : case CATCH_EXPR:
12808 : : /* See below. */
12809 : 0 : return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1)));
12810 : :
12811 : 0 : case EH_FILTER_EXPR:
12812 : : /* See below. */
12813 : 0 : return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1)));
12814 : :
12815 : 0 : case STATEMENT_LIST:
12816 : 0 : break;
12817 : :
12818 : : default:
12819 : : /* See below. */
12820 : : return false;
12821 : : }
12822 : :
12823 : 0 : i = tsi_start (TREE_OPERAND (stmt, 1));
12824 : 0 : switch (TREE_CODE (tsi_stmt (i)))
12825 : : {
12826 : : case CATCH_EXPR:
12827 : : /* We expect to see a sequence of CATCH_EXPR trees, each with a
12828 : : catch expression and a body. The whole TRY_CATCH may fall
12829 : : through iff any of the catch bodies falls through. */
12830 : 0 : for (; !tsi_end_p (i); tsi_next (&i))
12831 : : {
12832 : 0 : if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
12833 : : return true;
12834 : : }
12835 : : return false;
12836 : :
12837 : 0 : case EH_FILTER_EXPR:
12838 : : /* The exception filter expression only matters if there is an
12839 : : exception. If the exception does not match EH_FILTER_TYPES,
12840 : : we will execute EH_FILTER_FAILURE, and we will fall through
12841 : : if that falls through. If the exception does match
12842 : : EH_FILTER_TYPES, the stack unwinder will continue up the
12843 : : stack, so we will not fall through. We don't know whether we
12844 : : will throw an exception which matches EH_FILTER_TYPES or not,
12845 : : so we just ignore EH_FILTER_TYPES and assume that we might
12846 : : throw an exception which doesn't match. */
12847 : 0 : return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
12848 : :
12849 : : default:
12850 : : /* This case represents statements to be executed when an
12851 : : exception occurs. Those statements are implicitly followed
12852 : : by a RESX statement to resume execution after the exception.
12853 : : So in this case the TRY_CATCH never falls through. */
12854 : : return false;
12855 : : }
12856 : : }
12857 : :
12858 : : /* Try to determine if we can fall out of the bottom of BLOCK. This guess
12859 : : need not be 100% accurate; simply be conservative and return true if we
12860 : : don't know. This is used only to avoid stupidly generating extra code.
12861 : : If we're wrong, we'll just delete the extra code later. */
12862 : :
12863 : : bool
12864 : 6214718 : block_may_fallthru (const_tree block)
12865 : : {
12866 : : /* This CONST_CAST is okay because expr_last returns its argument
12867 : : unmodified and we assign it to a const_tree. */
12868 : 7312548 : const_tree stmt = expr_last (CONST_CAST_TREE (block));
12869 : :
12870 : 7312548 : switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
12871 : : {
12872 : : case GOTO_EXPR:
12873 : : case RETURN_EXPR:
12874 : : /* Easy cases. If the last statement of the block implies
12875 : : control transfer, then we can't fall through. */
12876 : : return false;
12877 : :
12878 : 8 : case SWITCH_EXPR:
12879 : : /* If there is a default: label or case labels cover all possible
12880 : : SWITCH_COND values, then the SWITCH_EXPR will transfer control
12881 : : to some case label in all cases and all we care is whether the
12882 : : SWITCH_BODY falls through. */
12883 : 8 : if (SWITCH_ALL_CASES_P (stmt))
12884 : 7 : return block_may_fallthru (SWITCH_BODY (stmt));
12885 : : return true;
12886 : :
12887 : 19796 : case COND_EXPR:
12888 : 19796 : if (block_may_fallthru (COND_EXPR_THEN (stmt)))
12889 : : return true;
12890 : 2793 : return block_may_fallthru (COND_EXPR_ELSE (stmt));
12891 : :
12892 : 535682 : case BIND_EXPR:
12893 : 535682 : return block_may_fallthru (BIND_EXPR_BODY (stmt));
12894 : :
12895 : 1 : case TRY_CATCH_EXPR:
12896 : 1 : return try_catch_may_fallthru (stmt);
12897 : :
12898 : 141 : case TRY_FINALLY_EXPR:
12899 : : /* The finally clause is always executed after the try clause,
12900 : : so if it does not fall through, then the try-finally will not
12901 : : fall through. Otherwise, if the try clause does not fall
12902 : : through, then when the finally clause falls through it will
12903 : : resume execution wherever the try clause was going. So the
12904 : : whole try-finally will only fall through if both the try
12905 : : clause and the finally clause fall through. */
12906 : 141 : return (block_may_fallthru (TREE_OPERAND (stmt, 0))
12907 : 141 : && block_may_fallthru (TREE_OPERAND (stmt, 1)));
12908 : :
12909 : 0 : case EH_ELSE_EXPR:
12910 : 0 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
12911 : :
12912 : 88419 : case MODIFY_EXPR:
12913 : 88419 : if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
12914 : 1540 : stmt = TREE_OPERAND (stmt, 1);
12915 : : else
12916 : : return true;
12917 : : /* FALLTHRU */
12918 : :
12919 : 407761 : case CALL_EXPR:
12920 : : /* Functions that do not return do not fall through. */
12921 : 407761 : return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
12922 : :
12923 : 559338 : case CLEANUP_POINT_EXPR:
12924 : 559338 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
12925 : :
12926 : 10 : case TARGET_EXPR:
12927 : 10 : return block_may_fallthru (TREE_OPERAND (stmt, 1));
12928 : :
12929 : : case ERROR_MARK:
12930 : : return true;
12931 : :
12932 : 3971083 : default:
12933 : 3971083 : return lang_hooks.block_may_fallthru (stmt);
12934 : : }
12935 : : }
12936 : :
12937 : : /* True if we are using EH to handle cleanups. */
12938 : : static bool using_eh_for_cleanups_flag = false;
12939 : :
12940 : : /* This routine is called from front ends to indicate eh should be used for
12941 : : cleanups. */
12942 : : void
12943 : 120527 : using_eh_for_cleanups (void)
12944 : : {
12945 : 120527 : using_eh_for_cleanups_flag = true;
12946 : 120527 : }
12947 : :
12948 : : /* Query whether EH is used for cleanups. */
12949 : : bool
12950 : 1625543 : using_eh_for_cleanups_p (void)
12951 : : {
12952 : 1625543 : return using_eh_for_cleanups_flag;
12953 : : }
12954 : :
12955 : : /* Wrapper for tree_code_name to ensure that tree code is valid */
12956 : : const char *
12957 : 14168607457 : get_tree_code_name (enum tree_code code)
12958 : : {
12959 : 14168607457 : const char *invalid = "<invalid tree code>";
12960 : :
12961 : : /* The tree_code enum promotes to signed, but we could be getting
12962 : : invalid values, so force an unsigned comparison. */
12963 : 14168607457 : if (unsigned (code) >= MAX_TREE_CODES)
12964 : : {
12965 : 0 : if ((unsigned)code == 0xa5a5)
12966 : : return "ggc_freed";
12967 : 0 : return invalid;
12968 : : }
12969 : :
12970 : 14168607457 : return tree_code_name[code];
12971 : : }
12972 : :
12973 : : /* Drops the TREE_OVERFLOW flag from T. */
12974 : :
12975 : : tree
12976 : 38085 : drop_tree_overflow (tree t)
12977 : : {
12978 : 38085 : gcc_checking_assert (TREE_OVERFLOW (t));
12979 : :
12980 : : /* For tree codes with a sharing machinery re-build the result. */
12981 : 38085 : if (poly_int_tree_p (t))
12982 : 38073 : return wide_int_to_tree (TREE_TYPE (t), wi::to_poly_wide (t));
12983 : :
12984 : : /* For VECTOR_CST, remove the overflow bits from the encoded elements
12985 : : and canonicalize the result. */
12986 : 12 : if (TREE_CODE (t) == VECTOR_CST)
12987 : : {
12988 : 0 : tree_vector_builder builder;
12989 : 0 : builder.new_unary_operation (TREE_TYPE (t), t, true);
12990 : 0 : unsigned int count = builder.encoded_nelts ();
12991 : 0 : for (unsigned int i = 0; i < count; ++i)
12992 : : {
12993 : 0 : tree elt = VECTOR_CST_ELT (t, i);
12994 : 0 : if (TREE_OVERFLOW (elt))
12995 : 0 : elt = drop_tree_overflow (elt);
12996 : 0 : builder.quick_push (elt);
12997 : : }
12998 : 0 : return builder.build ();
12999 : 0 : }
13000 : :
13001 : : /* Otherwise, as all tcc_constants are possibly shared, copy the node
13002 : : and drop the flag. */
13003 : 12 : t = copy_node (t);
13004 : 12 : TREE_OVERFLOW (t) = 0;
13005 : :
13006 : : /* For constants that contain nested constants, drop the flag
13007 : : from those as well. */
13008 : 12 : if (TREE_CODE (t) == COMPLEX_CST)
13009 : : {
13010 : 12 : if (TREE_OVERFLOW (TREE_REALPART (t)))
13011 : 12 : TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t));
13012 : 12 : if (TREE_OVERFLOW (TREE_IMAGPART (t)))
13013 : 0 : TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t));
13014 : : }
13015 : :
13016 : : return t;
13017 : : }
13018 : :
13019 : : /* Given a memory reference expression T, return its base address.
13020 : : The base address of a memory reference expression is the main
13021 : : object being referenced. For instance, the base address for
13022 : : 'array[i].fld[j]' is 'array'. You can think of this as stripping
13023 : : away the offset part from a memory address.
13024 : :
13025 : : This function calls handled_component_p to strip away all the inner
13026 : : parts of the memory reference until it reaches the base object. */
13027 : :
13028 : : tree
13029 : 3108162192 : get_base_address (tree t)
13030 : : {
13031 : 3108162192 : if (TREE_CODE (t) == WITH_SIZE_EXPR)
13032 : 971 : t = TREE_OPERAND (t, 0);
13033 : 3847683095 : while (handled_component_p (t))
13034 : 739520903 : t = TREE_OPERAND (t, 0);
13035 : :
13036 : 3108162192 : if ((TREE_CODE (t) == MEM_REF
13037 : 3108162192 : || TREE_CODE (t) == TARGET_MEM_REF)
13038 : 3108162192 : && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
13039 : 149424314 : t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
13040 : :
13041 : 3108162192 : return t;
13042 : : }
13043 : :
13044 : : /* Return a tree of sizetype representing the size, in bytes, of the element
13045 : : of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13046 : :
13047 : : tree
13048 : 757551004 : array_ref_element_size (tree exp)
13049 : : {
13050 : 757551004 : tree aligned_size = TREE_OPERAND (exp, 3);
13051 : 757551004 : tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
13052 : 757551004 : location_t loc = EXPR_LOCATION (exp);
13053 : :
13054 : : /* If a size was specified in the ARRAY_REF, it's the size measured
13055 : : in alignment units of the element type. So multiply by that value. */
13056 : 757551004 : if (aligned_size)
13057 : : {
13058 : : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13059 : : sizetype from another type of the same width and signedness. */
13060 : 375519 : if (TREE_TYPE (aligned_size) != sizetype)
13061 : 2026 : aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
13062 : 375519 : return size_binop_loc (loc, MULT_EXPR, aligned_size,
13063 : 375519 : size_int (TYPE_ALIGN_UNIT (elmt_type)));
13064 : : }
13065 : :
13066 : : /* Otherwise, take the size from that of the element type. Substitute
13067 : : any PLACEHOLDER_EXPR that we have. */
13068 : : else
13069 : 757175485 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
13070 : : }
13071 : :
13072 : : /* Return a tree representing the lower bound of the array mentioned in
13073 : : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13074 : :
13075 : : tree
13076 : 1055689333 : array_ref_low_bound (tree exp)
13077 : : {
13078 : 1055689333 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13079 : :
13080 : : /* If a lower bound is specified in EXP, use it. */
13081 : 1055689333 : if (TREE_OPERAND (exp, 2))
13082 : 1108332 : return TREE_OPERAND (exp, 2);
13083 : :
13084 : : /* Otherwise, if there is a domain type and it has a lower bound, use it,
13085 : : substituting for a PLACEHOLDER_EXPR as needed. */
13086 : 1054581001 : if (domain_type && TYPE_MIN_VALUE (domain_type))
13087 : 1053684534 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
13088 : :
13089 : : /* Otherwise, return a zero of the appropriate type. */
13090 : 896467 : tree idxtype = TREE_TYPE (TREE_OPERAND (exp, 1));
13091 : 896467 : return (idxtype == error_mark_node
13092 : 896467 : ? integer_zero_node : build_int_cst (idxtype, 0));
13093 : : }
13094 : :
13095 : : /* Return a tree representing the upper bound of the array mentioned in
13096 : : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13097 : :
13098 : : tree
13099 : 252384106 : array_ref_up_bound (tree exp)
13100 : : {
13101 : 252384106 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13102 : :
13103 : : /* If there is a domain type and it has an upper bound, use it, substituting
13104 : : for a PLACEHOLDER_EXPR as needed. */
13105 : 252384106 : if (domain_type && TYPE_MAX_VALUE (domain_type))
13106 : 251589976 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
13107 : :
13108 : : /* Otherwise fail. */
13109 : : return NULL_TREE;
13110 : : }
13111 : :
13112 : : /* Returns true if REF is an array reference, a component reference,
13113 : : or a memory reference to an array whose actual size might be larger
13114 : : than its upper bound implies, there are multiple cases:
13115 : : A. a ref to a flexible array member at the end of a structure;
13116 : : B. a ref to an array with a different type against the original decl;
13117 : : for example:
13118 : :
13119 : : short a[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
13120 : : (*((char(*)[16])&a[0]))[i+8]
13121 : :
13122 : : C. a ref to an array that was passed as a parameter;
13123 : : for example:
13124 : :
13125 : : int test (uint8_t *p, uint32_t t[1][1], int n) {
13126 : : for (int i = 0; i < 4; i++, p++)
13127 : : t[i][0] = ...;
13128 : :
13129 : : If non-null, set IS_TRAILING_ARRAY to true if the ref is the above case A.
13130 : : */
13131 : :
13132 : : bool
13133 : 72759071 : array_ref_flexible_size_p (tree ref, bool *is_trailing_array /* = NULL */)
13134 : : {
13135 : : /* The TYPE for this array referece. */
13136 : 72759071 : tree atype = NULL_TREE;
13137 : : /* The FIELD_DECL for the array field in the containing structure. */
13138 : 72759071 : tree afield_decl = NULL_TREE;
13139 : : /* Whether this array is the trailing array of a structure. */
13140 : 72759071 : bool is_trailing_array_tmp = false;
13141 : 72759071 : if (!is_trailing_array)
13142 : 72679869 : is_trailing_array = &is_trailing_array_tmp;
13143 : :
13144 : 72759071 : if (TREE_CODE (ref) == ARRAY_REF
13145 : 72759071 : || TREE_CODE (ref) == ARRAY_RANGE_REF)
13146 : : {
13147 : 72531825 : atype = TREE_TYPE (TREE_OPERAND (ref, 0));
13148 : 72531825 : ref = TREE_OPERAND (ref, 0);
13149 : : }
13150 : 227246 : else if (TREE_CODE (ref) == COMPONENT_REF
13151 : 227246 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE)
13152 : : {
13153 : 163944 : atype = TREE_TYPE (TREE_OPERAND (ref, 1));
13154 : 163944 : afield_decl = TREE_OPERAND (ref, 1);
13155 : : }
13156 : 63302 : else if (TREE_CODE (ref) == MEM_REF)
13157 : : {
13158 : 8298 : tree arg = TREE_OPERAND (ref, 0);
13159 : 8298 : if (TREE_CODE (arg) == ADDR_EXPR)
13160 : 8298 : arg = TREE_OPERAND (arg, 0);
13161 : 8298 : tree argtype = TREE_TYPE (arg);
13162 : 8298 : if (TREE_CODE (argtype) == RECORD_TYPE)
13163 : : {
13164 : 174 : if (tree fld = last_field (argtype))
13165 : : {
13166 : 174 : atype = TREE_TYPE (fld);
13167 : 174 : afield_decl = fld;
13168 : 174 : if (TREE_CODE (atype) != ARRAY_TYPE)
13169 : : return false;
13170 : 174 : if (VAR_P (arg) && DECL_SIZE (fld))
13171 : : return false;
13172 : : }
13173 : : else
13174 : : return false;
13175 : : }
13176 : : else
13177 : : return false;
13178 : : }
13179 : : else
13180 : : return false;
13181 : :
13182 : 72695894 : if (TREE_CODE (ref) == STRING_CST)
13183 : : return false;
13184 : :
13185 : : tree ref_to_array = ref;
13186 : 89335142 : while (handled_component_p (ref))
13187 : : {
13188 : : /* If the reference chain contains a component reference to a
13189 : : non-union type and there follows another field the reference
13190 : : is not at the end of a structure. */
13191 : 19577064 : if (TREE_CODE (ref) == COMPONENT_REF)
13192 : : {
13193 : 18464337 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
13194 : : {
13195 : 17231677 : tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
13196 : 25290619 : while (nextf && TREE_CODE (nextf) != FIELD_DECL)
13197 : 8058942 : nextf = DECL_CHAIN (nextf);
13198 : : if (nextf)
13199 : : return false;
13200 : : }
13201 : : }
13202 : : /* If we have a multi-dimensional array we do not consider
13203 : : a non-innermost dimension as flex array if the whole
13204 : : multi-dimensional array is at struct end.
13205 : : Same for an array of aggregates with a trailing array
13206 : : member. */
13207 : 1112727 : else if (TREE_CODE (ref) == ARRAY_REF)
13208 : : return false;
13209 : 179211 : else if (TREE_CODE (ref) == ARRAY_RANGE_REF)
13210 : : ;
13211 : : /* If we view an underlying object as sth else then what we
13212 : : gathered up to now is what we have to rely on. */
13213 : 179201 : else if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
13214 : : break;
13215 : : else
13216 : 0 : gcc_unreachable ();
13217 : :
13218 : 16640535 : ref = TREE_OPERAND (ref, 0);
13219 : : }
13220 : :
13221 : 69937279 : gcc_assert (!afield_decl
13222 : : || (afield_decl && TREE_CODE (afield_decl) == FIELD_DECL));
13223 : :
13224 : : /* The array now is at struct end. Treat flexible array member as
13225 : : always subject to extend, even into just padding constrained by
13226 : : an underlying decl. */
13227 : 69937279 : if (! TYPE_SIZE (atype)
13228 : 67624762 : || ! TYPE_DOMAIN (atype)
13229 : 137562041 : || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13230 : : {
13231 : 2318107 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13232 : 2397451 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13233 : : }
13234 : :
13235 : : /* If the reference is based on a declared entity, the size of the array
13236 : : is constrained by its given domain. (Do not trust commons PR/69368). */
13237 : 67619172 : ref = get_base_address (ref);
13238 : 67619172 : if (ref
13239 : 67619172 : && DECL_P (ref)
13240 : 57655623 : && !(flag_unconstrained_commons
13241 : 14 : && VAR_P (ref) && DECL_COMMON (ref))
13242 : 57655609 : && DECL_SIZE_UNIT (ref)
13243 : 125274404 : && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
13244 : : {
13245 : : /* If the object itself is the array it is not at struct end. */
13246 : 57655204 : if (DECL_P (ref_to_array))
13247 : : return false;
13248 : :
13249 : : /* Check whether the array domain covers all of the available
13250 : : padding. */
13251 : 15504219 : poly_int64 offset;
13252 : 15504219 : if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
13253 : 15502883 : || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST
13254 : 30984314 : || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST)
13255 : : {
13256 : 24124 : *is_trailing_array
13257 : 24124 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13258 : 24167 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13259 : : }
13260 : 15480095 : if (! get_addr_base_and_unit_offset (ref_to_array, &offset))
13261 : : {
13262 : 2630 : *is_trailing_array
13263 : 2630 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13264 : 2630 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13265 : : }
13266 : :
13267 : : /* If at least one extra element fits it is a flexarray. */
13268 : 15477465 : if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13269 : : - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype)))
13270 : : + 2)
13271 : : * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype))),
13272 : : wi::to_offset (DECL_SIZE_UNIT (ref)) - offset))
13273 : : {
13274 : 366475 : *is_trailing_array
13275 : 366475 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13276 : 378620 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13277 : : }
13278 : :
13279 : : return false;
13280 : : }
13281 : :
13282 : 9963968 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13283 : 9978526 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13284 : : }
13285 : :
13286 : :
13287 : : /* Return a tree representing the offset, in bytes, of the field referenced
13288 : : by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
13289 : :
13290 : : tree
13291 : 2596480066 : component_ref_field_offset (tree exp)
13292 : : {
13293 : 2596480066 : tree aligned_offset = TREE_OPERAND (exp, 2);
13294 : 2596480066 : tree field = TREE_OPERAND (exp, 1);
13295 : 2596480066 : location_t loc = EXPR_LOCATION (exp);
13296 : :
13297 : : /* If an offset was specified in the COMPONENT_REF, it's the offset measured
13298 : : in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
13299 : : value. */
13300 : 2596480066 : if (aligned_offset)
13301 : : {
13302 : : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13303 : : sizetype from another type of the same width and signedness. */
13304 : 11862 : if (TREE_TYPE (aligned_offset) != sizetype)
13305 : 122 : aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
13306 : 11862 : return size_binop_loc (loc, MULT_EXPR, aligned_offset,
13307 : 11862 : size_int (DECL_OFFSET_ALIGN (field)
13308 : : / BITS_PER_UNIT));
13309 : : }
13310 : :
13311 : : /* Otherwise, take the offset from that of the field. Substitute
13312 : : any PLACEHOLDER_EXPR that we have. */
13313 : : else
13314 : 2596468204 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
13315 : : }
13316 : :
13317 : : /* Given the initializer INIT, return the initializer for the field
13318 : : DECL if it exists, otherwise null. Used to obtain the initializer
13319 : : for a flexible array member and determine its size. */
13320 : :
13321 : : static tree
13322 : 1268 : get_initializer_for (tree init, tree decl)
13323 : : {
13324 : 1268 : STRIP_NOPS (init);
13325 : :
13326 : 1268 : tree fld, fld_init;
13327 : 1268 : unsigned HOST_WIDE_INT i;
13328 : 3572 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), i, fld, fld_init)
13329 : : {
13330 : 1927 : if (decl == fld)
13331 : : return fld_init;
13332 : :
13333 : 1036 : if (TREE_CODE (fld) == CONSTRUCTOR)
13334 : : {
13335 : 0 : fld_init = get_initializer_for (fld_init, decl);
13336 : 0 : if (fld_init)
13337 : : return fld_init;
13338 : : }
13339 : : }
13340 : :
13341 : : return NULL_TREE;
13342 : : }
13343 : :
13344 : : /* Determines the special array member type for the array reference REF. */
13345 : : special_array_member
13346 : 252225 : component_ref_sam_type (tree ref)
13347 : : {
13348 : 252225 : special_array_member sam_type = special_array_member::none;
13349 : :
13350 : 252225 : tree member = TREE_OPERAND (ref, 1);
13351 : 252225 : tree memsize = DECL_SIZE_UNIT (member);
13352 : 252225 : if (memsize)
13353 : : {
13354 : 120278 : tree memtype = TREE_TYPE (member);
13355 : 120278 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13356 : 120157 : return sam_type;
13357 : :
13358 : 79202 : bool trailing = false;
13359 : 79202 : (void) array_ref_flexible_size_p (ref, &trailing);
13360 : 79202 : bool zero_elts = integer_zerop (memsize);
13361 : 79202 : if (zero_elts && integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (memtype))))
13362 : : {
13363 : : /* If array element has zero size, verify if it is a flexible
13364 : : array member or zero length array. Clear zero_elts if
13365 : : it has one or more members or is a VLA member. */
13366 : 7 : if (tree dom = TYPE_DOMAIN (memtype))
13367 : 7 : if (tree min = TYPE_MIN_VALUE (dom))
13368 : 7 : if (tree max = TYPE_MAX_VALUE (dom))
13369 : 5 : if (TREE_CODE (min) != INTEGER_CST
13370 : 5 : || TREE_CODE (max) != INTEGER_CST
13371 : 15 : || !((integer_zerop (min) && integer_all_onesp (max))
13372 : 5 : || tree_int_cst_lt (max, min)))
13373 : : zero_elts = false;
13374 : : }
13375 : 79202 : if (!trailing && !zero_elts)
13376 : : /* MEMBER is an interior array with more than one element. */
13377 : : return special_array_member::int_n;
13378 : :
13379 : 23490 : if (zero_elts)
13380 : : {
13381 : 1075 : if (trailing)
13382 : : return special_array_member::trail_0;
13383 : : else
13384 : 463 : return special_array_member::int_0;
13385 : : }
13386 : :
13387 : 22878 : if (!zero_elts)
13388 : 22878 : if (tree dom = TYPE_DOMAIN (memtype))
13389 : 22878 : if (tree min = TYPE_MIN_VALUE (dom))
13390 : 22878 : if (tree max = TYPE_MAX_VALUE (dom))
13391 : 22878 : if (TREE_CODE (min) == INTEGER_CST
13392 : 22878 : && TREE_CODE (max) == INTEGER_CST)
13393 : : {
13394 : 22757 : offset_int minidx = wi::to_offset (min);
13395 : 22757 : offset_int maxidx = wi::to_offset (max);
13396 : 22757 : offset_int neltsm1 = maxidx - minidx;
13397 : 22757 : if (neltsm1 > 0)
13398 : : /* MEMBER is a trailing array with more than
13399 : : one elements. */
13400 : 22757 : return special_array_member::trail_n;
13401 : :
13402 : 1966 : if (neltsm1 == 0)
13403 : : return special_array_member::trail_1;
13404 : : }
13405 : : }
13406 : :
13407 : : return sam_type;
13408 : : }
13409 : :
13410 : : /* Determines the size of the member referenced by the COMPONENT_REF
13411 : : REF, using its initializer expression if necessary in order to
13412 : : determine the size of an initialized flexible array member.
13413 : : If non-null, set *SAM to the type of special array member.
13414 : : Returns the size as sizetype (which might be zero for an object
13415 : : with an uninitialized flexible array member) or null if the size
13416 : : cannot be determined. */
13417 : :
13418 : : tree
13419 : 153298 : component_ref_size (tree ref, special_array_member *sam /* = NULL */)
13420 : : {
13421 : 153298 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
13422 : :
13423 : 153298 : special_array_member sambuf;
13424 : 153298 : if (!sam)
13425 : 97548 : sam = &sambuf;
13426 : 153298 : *sam = component_ref_sam_type (ref);
13427 : :
13428 : : /* The object/argument referenced by the COMPONENT_REF and its type. */
13429 : 153298 : tree arg = TREE_OPERAND (ref, 0);
13430 : 153298 : tree argtype = TREE_TYPE (arg);
13431 : : /* The referenced member. */
13432 : 153298 : tree member = TREE_OPERAND (ref, 1);
13433 : :
13434 : 153298 : tree memsize = DECL_SIZE_UNIT (member);
13435 : 153298 : if (memsize)
13436 : : {
13437 : 85808 : tree memtype = TREE_TYPE (member);
13438 : 85808 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13439 : : /* DECL_SIZE may be less than TYPE_SIZE in C++ when referring
13440 : : to the type of a class with a virtual base which doesn't
13441 : : reflect the size of the virtual's members (see pr97595).
13442 : : If that's the case fail for now and implement something
13443 : : more robust in the future. */
13444 : 41076 : return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype))
13445 : 41076 : ? memsize : NULL_TREE);
13446 : :
13447 : : /* 2-or-more elements arrays are treated as normal arrays by default. */
13448 : 44732 : if (*sam == special_array_member::int_n
13449 : 44732 : || *sam == special_array_member::trail_n)
13450 : : return memsize;
13451 : :
13452 : 1742 : tree afield_decl = TREE_OPERAND (ref, 1);
13453 : 1742 : gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
13454 : : /* If the trailing array is a not a flexible array member, treat it as
13455 : : a normal array. */
13456 : 1742 : if (DECL_NOT_FLEXARRAY (afield_decl)
13457 : 1742 : && *sam != special_array_member::int_0)
13458 : : return memsize;
13459 : :
13460 : 1733 : if (*sam == special_array_member::int_0)
13461 : 270 : memsize = NULL_TREE;
13462 : :
13463 : : /* For a reference to a flexible array member of a union
13464 : : use the size of the union instead of the size of the member. */
13465 : 1733 : if (TREE_CODE (argtype) == UNION_TYPE)
13466 : 277 : memsize = TYPE_SIZE_UNIT (argtype);
13467 : : }
13468 : :
13469 : : /* MEMBER is either a bona fide flexible array member, or a zero-elements
13470 : : array member, or an array of length one treated as such. */
13471 : :
13472 : : /* If the reference is to a declared object and the member a true
13473 : : flexible array, try to determine its size from its initializer. */
13474 : 69223 : poly_int64 baseoff = 0;
13475 : 69223 : tree base = get_addr_base_and_unit_offset (ref, &baseoff);
13476 : 69223 : if (!base || !VAR_P (base))
13477 : : {
13478 : 66025 : if (*sam != special_array_member::int_0)
13479 : : return NULL_TREE;
13480 : :
13481 : 52 : if (TREE_CODE (arg) != COMPONENT_REF)
13482 : : return NULL_TREE;
13483 : :
13484 : : base = arg;
13485 : 6 : while (TREE_CODE (base) == COMPONENT_REF)
13486 : 3 : base = TREE_OPERAND (base, 0);
13487 : 3 : baseoff = tree_to_poly_int64 (byte_position (TREE_OPERAND (ref, 1)));
13488 : : }
13489 : :
13490 : : /* BASE is the declared object of which MEMBER is either a member
13491 : : or that is cast to ARGTYPE (e.g., a char buffer used to store
13492 : : an ARGTYPE object). */
13493 : 3201 : tree basetype = TREE_TYPE (base);
13494 : :
13495 : : /* Determine the base type of the referenced object. If it's
13496 : : the same as ARGTYPE and MEMBER has a known size, return it. */
13497 : 3201 : tree bt = basetype;
13498 : 3201 : if (*sam != special_array_member::int_0)
13499 : 3202 : while (TREE_CODE (bt) == ARRAY_TYPE)
13500 : 222 : bt = TREE_TYPE (bt);
13501 : 3201 : bool typematch = useless_type_conversion_p (argtype, bt);
13502 : 3201 : if (memsize && typematch)
13503 : : return memsize;
13504 : :
13505 : 3111 : memsize = NULL_TREE;
13506 : :
13507 : 3111 : if (typematch)
13508 : : /* MEMBER is a true flexible array member. Compute its size from
13509 : : the initializer of the BASE object if it has one. */
13510 : 2649 : if (tree init = DECL_P (base) ? DECL_INITIAL (base) : NULL_TREE)
13511 : 1301 : if (init != error_mark_node)
13512 : : {
13513 : 1268 : init = get_initializer_for (init, member);
13514 : 1268 : if (init)
13515 : : {
13516 : 891 : memsize = TYPE_SIZE_UNIT (TREE_TYPE (init));
13517 : 891 : if (tree refsize = TYPE_SIZE_UNIT (argtype))
13518 : : {
13519 : : /* Use the larger of the initializer size and the tail
13520 : : padding in the enclosing struct. */
13521 : 891 : poly_int64 rsz = tree_to_poly_int64 (refsize);
13522 : 891 : rsz -= baseoff;
13523 : 891 : if (known_lt (tree_to_poly_int64 (memsize), rsz))
13524 : 56 : memsize = wide_int_to_tree (TREE_TYPE (memsize), rsz);
13525 : : }
13526 : :
13527 : 891 : baseoff = 0;
13528 : : }
13529 : : }
13530 : :
13531 : 891 : if (!memsize)
13532 : : {
13533 : 2220 : if (typematch)
13534 : : {
13535 : 1758 : if (DECL_P (base)
13536 : 1758 : && DECL_EXTERNAL (base)
13537 : 454 : && bt == basetype
13538 : 2206 : && *sam != special_array_member::int_0)
13539 : : /* The size of a flexible array member of an extern struct
13540 : : with no initializer cannot be determined (it's defined
13541 : : in another translation unit and can have an initializer
13542 : : with an arbitrary number of elements). */
13543 : : return NULL_TREE;
13544 : :
13545 : : /* Use the size of the base struct or, for interior zero-length
13546 : : arrays, the size of the enclosing type. */
13547 : 1333 : memsize = TYPE_SIZE_UNIT (bt);
13548 : : }
13549 : 462 : else if (DECL_P (base))
13550 : : /* Use the size of the BASE object (possibly an array of some
13551 : : other type such as char used to store the struct). */
13552 : 459 : memsize = DECL_SIZE_UNIT (base);
13553 : : else
13554 : : return NULL_TREE;
13555 : : }
13556 : :
13557 : : /* If the flexible array member has a known size use the greater
13558 : : of it and the tail padding in the enclosing struct.
13559 : : Otherwise, when the size of the flexible array member is unknown
13560 : : and the referenced object is not a struct, use the size of its
13561 : : type when known. This detects sizes of array buffers when cast
13562 : : to struct types with flexible array members. */
13563 : 1792 : if (memsize)
13564 : : {
13565 : 2658 : if (!tree_fits_poly_int64_p (memsize))
13566 : : return NULL_TREE;
13567 : 2658 : poly_int64 memsz64 = memsize ? tree_to_poly_int64 (memsize) : 0;
13568 : 2658 : if (known_lt (baseoff, memsz64))
13569 : : {
13570 : 1241 : memsz64 -= baseoff;
13571 : 1241 : return wide_int_to_tree (TREE_TYPE (memsize), memsz64);
13572 : : }
13573 : 1417 : return size_zero_node;
13574 : : }
13575 : :
13576 : : /* Return "don't know" for an external non-array object since its
13577 : : flexible array member can be initialized to have any number of
13578 : : elements. Otherwise, return zero because the flexible array
13579 : : member has no elements. */
13580 : 25 : return (DECL_P (base)
13581 : 25 : && DECL_EXTERNAL (base)
13582 : 25 : && (!typematch
13583 : 0 : || TREE_CODE (basetype) != ARRAY_TYPE)
13584 : 25 : ? NULL_TREE : size_zero_node);
13585 : : }
13586 : :
13587 : : /* Return true if the given node CALL is a call to a .ACCESS_WITH_SIZE
13588 : : function. */
13589 : : bool
13590 : 57655987 : is_access_with_size_p (const_tree call)
13591 : : {
13592 : 57655987 : if (TREE_CODE (call) != CALL_EXPR)
13593 : : return false;
13594 : 6994946 : if (CALL_EXPR_IFN (call) == IFN_ACCESS_WITH_SIZE)
13595 : 355 : return true;
13596 : : return false;
13597 : : }
13598 : :
13599 : : /* Get the corresponding reference from the call to a .ACCESS_WITH_SIZE.
13600 : : * i.e the first argument of this call. Return NULL_TREE otherwise. */
13601 : : tree
13602 : 2 : get_ref_from_access_with_size (tree call)
13603 : : {
13604 : 2 : if (is_access_with_size_p (call))
13605 : 2 : return CALL_EXPR_ARG (call, 0);
13606 : : return NULL_TREE;
13607 : : }
13608 : :
13609 : : /* Return the machine mode of T. For vectors, returns the mode of the
13610 : : inner type. The main use case is to feed the result to HONOR_NANS,
13611 : : avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
13612 : :
13613 : : machine_mode
13614 : 5075471972 : element_mode (const_tree t)
13615 : : {
13616 : 5075471972 : if (!TYPE_P (t))
13617 : 199341215 : t = TREE_TYPE (t);
13618 : 5075471972 : if (VECTOR_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
13619 : 1476759820 : t = TREE_TYPE (t);
13620 : 5075471972 : return TYPE_MODE (t);
13621 : : }
13622 : :
13623 : : /* Vector types need to re-check the target flags each time we report
13624 : : the machine mode. We need to do this because attribute target can
13625 : : change the result of vector_mode_supported_p and have_regs_of_mode
13626 : : on a per-function basis. Thus the TYPE_MODE of a VECTOR_TYPE can
13627 : : change on a per-function basis. */
13628 : : /* ??? Possibly a better solution is to run through all the types
13629 : : referenced by a function and re-compute the TYPE_MODE once, rather
13630 : : than make the TYPE_MODE macro call a function. */
13631 : :
13632 : : machine_mode
13633 : 1307466248 : vector_type_mode (const_tree t)
13634 : : {
13635 : 1307466248 : machine_mode mode;
13636 : :
13637 : 1307466248 : gcc_assert (TREE_CODE (t) == VECTOR_TYPE);
13638 : :
13639 : 1307466248 : mode = t->type_common.mode;
13640 : 296208075 : if (VECTOR_MODE_P (mode)
13641 : 1567446303 : && (!targetm.vector_mode_supported_p (mode)
13642 : 1252891868 : || !have_regs_of_mode[mode]))
13643 : : {
13644 : 19176413 : scalar_int_mode innermode;
13645 : :
13646 : : /* For integers, try mapping it to a same-sized scalar mode. */
13647 : 19176413 : if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode))
13648 : : {
13649 : 26789484 : poly_int64 size = (TYPE_VECTOR_SUBPARTS (t)
13650 : 13394742 : * GET_MODE_BITSIZE (innermode));
13651 : 13394742 : scalar_int_mode mode;
13652 : 26654081 : if (int_mode_for_size (size, 0).exists (&mode)
13653 : 13312917 : && have_regs_of_mode[mode])
13654 : 53578 : return mode;
13655 : : }
13656 : :
13657 : 19122835 : return BLKmode;
13658 : : }
13659 : :
13660 : : return mode;
13661 : : }
13662 : :
13663 : : /* Return the size in bits of each element of vector type TYPE. */
13664 : :
13665 : : unsigned int
13666 : 202937 : vector_element_bits (const_tree type)
13667 : : {
13668 : 202937 : gcc_checking_assert (VECTOR_TYPE_P (type));
13669 : 202937 : if (VECTOR_BOOLEAN_TYPE_P (type))
13670 : 974 : return TYPE_PRECISION (TREE_TYPE (type));
13671 : 201963 : return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
13672 : : }
13673 : :
13674 : : /* Calculate the size in bits of each element of vector type TYPE
13675 : : and return the result as a tree of type bitsizetype. */
13676 : :
13677 : : tree
13678 : 111075 : vector_element_bits_tree (const_tree type)
13679 : : {
13680 : 111075 : gcc_checking_assert (VECTOR_TYPE_P (type));
13681 : 111075 : if (VECTOR_BOOLEAN_TYPE_P (type))
13682 : 600 : return bitsize_int (vector_element_bits (type));
13683 : 110475 : return TYPE_SIZE (TREE_TYPE (type));
13684 : : }
13685 : :
13686 : : /* Verify that basic properties of T match TV and thus T can be a variant of
13687 : : TV. TV should be the more specified variant (i.e. the main variant). */
13688 : :
13689 : : static bool
13690 : 142212394 : verify_type_variant (const_tree t, tree tv)
13691 : : {
13692 : : /* Type variant can differ by:
13693 : :
13694 : : - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
13695 : : ENCODE_QUAL_ADDR_SPACE.
13696 : : - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
13697 : : in this case some values may not be set in the variant types
13698 : : (see TYPE_COMPLETE_P checks).
13699 : : - it is possible to have TYPE_ARTIFICIAL variant of non-artifical type
13700 : : - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
13701 : : - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
13702 : : - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
13703 : : - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
13704 : : this is necessary to make it possible to merge types form different TUs
13705 : : - arrays, pointers and references may have TREE_TYPE that is a variant
13706 : : of TREE_TYPE of their main variants.
13707 : : - aggregates may have new TYPE_FIELDS list that list variants of
13708 : : the main variant TYPE_FIELDS.
13709 : : - vector types may differ by TYPE_VECTOR_OPAQUE
13710 : : */
13711 : :
13712 : : /* Convenience macro for matching individual fields. */
13713 : : #define verify_variant_match(flag) \
13714 : : do { \
13715 : : if (flag (tv) != flag (t)) \
13716 : : { \
13717 : : error ("type variant differs by %s", #flag); \
13718 : : debug_tree (tv); \
13719 : : return false; \
13720 : : } \
13721 : : } while (false)
13722 : :
13723 : : /* tree_base checks. */
13724 : :
13725 : 142212394 : verify_variant_match (TREE_CODE);
13726 : : /* FIXME: Ada builds non-artificial variants of artificial types. */
13727 : : #if 0
13728 : : if (TYPE_ARTIFICIAL (tv))
13729 : : verify_variant_match (TYPE_ARTIFICIAL);
13730 : : #endif
13731 : 142212394 : if (POINTER_TYPE_P (tv))
13732 : 11021572 : verify_variant_match (TYPE_REF_CAN_ALIAS_ALL);
13733 : : /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
13734 : 142212394 : verify_variant_match (TYPE_UNSIGNED);
13735 : 142212394 : verify_variant_match (TYPE_PACKED);
13736 : 142212394 : if (TREE_CODE (t) == REFERENCE_TYPE)
13737 : 2807825 : verify_variant_match (TYPE_REF_IS_RVALUE);
13738 : 142212394 : if (AGGREGATE_TYPE_P (t))
13739 : 60589587 : verify_variant_match (TYPE_REVERSE_STORAGE_ORDER);
13740 : : else
13741 : 81622807 : verify_variant_match (TYPE_SATURATING);
13742 : : /* FIXME: This check trigger during libstdc++ build. */
13743 : : #if 0
13744 : : if (RECORD_OR_UNION_TYPE_P (t) && COMPLETE_TYPE_P (t))
13745 : : verify_variant_match (TYPE_FINAL_P);
13746 : : #endif
13747 : :
13748 : : /* tree_type_common checks. */
13749 : :
13750 : 142212394 : if (COMPLETE_TYPE_P (t))
13751 : : {
13752 : 131977858 : verify_variant_match (TYPE_MODE);
13753 : 131977858 : if (TREE_CODE (TYPE_SIZE (t)) != PLACEHOLDER_EXPR
13754 : 131977858 : && TREE_CODE (TYPE_SIZE (tv)) != PLACEHOLDER_EXPR)
13755 : 131977858 : verify_variant_match (TYPE_SIZE);
13756 : 131977858 : if (TREE_CODE (TYPE_SIZE_UNIT (t)) != PLACEHOLDER_EXPR
13757 : 131977858 : && TREE_CODE (TYPE_SIZE_UNIT (tv)) != PLACEHOLDER_EXPR
13758 : 263955716 : && TYPE_SIZE_UNIT (t) != TYPE_SIZE_UNIT (tv))
13759 : : {
13760 : 0 : gcc_assert (!operand_equal_p (TYPE_SIZE_UNIT (t),
13761 : : TYPE_SIZE_UNIT (tv), 0));
13762 : 0 : error ("type variant has different %<TYPE_SIZE_UNIT%>");
13763 : 0 : debug_tree (tv);
13764 : 0 : error ("type variant%'s %<TYPE_SIZE_UNIT%>");
13765 : 0 : debug_tree (TYPE_SIZE_UNIT (tv));
13766 : 0 : error ("type%'s %<TYPE_SIZE_UNIT%>");
13767 : 0 : debug_tree (TYPE_SIZE_UNIT (t));
13768 : 0 : return false;
13769 : : }
13770 : 131977858 : verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
13771 : : }
13772 : 142212394 : verify_variant_match (TYPE_PRECISION_RAW);
13773 : 142212394 : if (RECORD_OR_UNION_TYPE_P (t))
13774 : 60085136 : verify_variant_match (TYPE_TRANSPARENT_AGGR);
13775 : 82127258 : else if (TREE_CODE (t) == ARRAY_TYPE)
13776 : 504451 : verify_variant_match (TYPE_NONALIASED_COMPONENT);
13777 : : /* During LTO we merge variant lists from diferent translation units
13778 : : that may differ BY TYPE_CONTEXT that in turn may point
13779 : : to TRANSLATION_UNIT_DECL.
13780 : : Ada also builds variants of types with different TYPE_CONTEXT. */
13781 : : #if 0
13782 : : if (!in_lto_p || !TYPE_FILE_SCOPE_P (t))
13783 : : verify_variant_match (TYPE_CONTEXT);
13784 : : #endif
13785 : 142212394 : if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == INTEGER_TYPE)
13786 : 50068540 : verify_variant_match (TYPE_STRING_FLAG);
13787 : 142212394 : if (TREE_CODE (t) == RECORD_TYPE || TREE_CODE (t) == UNION_TYPE)
13788 : 60085136 : verify_variant_match (TYPE_CXX_ODR_P);
13789 : 142212394 : if (TYPE_ALIAS_SET_KNOWN_P (t))
13790 : : {
13791 : 0 : error ("type variant with %<TYPE_ALIAS_SET_KNOWN_P%>");
13792 : 0 : debug_tree (tv);
13793 : 0 : return false;
13794 : : }
13795 : :
13796 : : /* tree_type_non_common checks. */
13797 : :
13798 : : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
13799 : : and dangle the pointer from time to time. */
13800 : 60085136 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_VFIELD (t) != TYPE_VFIELD (tv)
13801 : 142212394 : && (in_lto_p || !TYPE_VFIELD (tv)
13802 : 0 : || TREE_CODE (TYPE_VFIELD (tv)) != TREE_LIST))
13803 : : {
13804 : 0 : error ("type variant has different %<TYPE_VFIELD%>");
13805 : 0 : debug_tree (tv);
13806 : 0 : return false;
13807 : : }
13808 : 2349137 : if ((TREE_CODE (t) == ENUMERAL_TYPE && COMPLETE_TYPE_P (t))
13809 : 139863310 : || TREE_CODE (t) == INTEGER_TYPE
13810 : 90299221 : || TREE_CODE (t) == BOOLEAN_TYPE
13811 : 73296090 : || TREE_CODE (t) == BITINT_TYPE
13812 : 73295955 : || SCALAR_FLOAT_TYPE_P (t)
13813 : 214547368 : || FIXED_POINT_TYPE_P (t))
13814 : : {
13815 : 69877420 : verify_variant_match (TYPE_MAX_VALUE);
13816 : 69877420 : verify_variant_match (TYPE_MIN_VALUE);
13817 : : }
13818 : 142212394 : if (TREE_CODE (t) == METHOD_TYPE)
13819 : 18863 : verify_variant_match (TYPE_METHOD_BASETYPE);
13820 : 142212394 : if (TREE_CODE (t) == OFFSET_TYPE)
13821 : 159 : verify_variant_match (TYPE_OFFSET_BASETYPE);
13822 : 142212394 : if (TREE_CODE (t) == ARRAY_TYPE)
13823 : 504451 : verify_variant_match (TYPE_ARRAY_MAX_SIZE);
13824 : : /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
13825 : : or even type's main variant. This is needed to make bootstrap pass
13826 : : and the bug seems new in GCC 5.
13827 : : C++ FE should be updated to make this consistent and we should check
13828 : : that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
13829 : : is a match with main variant.
13830 : :
13831 : : Also disable the check for Java for now because of parser hack that builds
13832 : : first an dummy BINFO and then sometimes replace it by real BINFO in some
13833 : : of the copies. */
13834 : 60085136 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t) && TYPE_BINFO (tv)
13835 : 49652738 : && TYPE_BINFO (t) != TYPE_BINFO (tv)
13836 : : /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
13837 : : Since there is no cheap way to tell C++/Java type w/o LTO, do checking
13838 : : at LTO time only. */
13839 : 142212394 : && (in_lto_p && odr_type_p (t)))
13840 : : {
13841 : 0 : error ("type variant has different %<TYPE_BINFO%>");
13842 : 0 : debug_tree (tv);
13843 : 0 : error ("type variant%'s %<TYPE_BINFO%>");
13844 : 0 : debug_tree (TYPE_BINFO (tv));
13845 : 0 : error ("type%'s %<TYPE_BINFO%>");
13846 : 0 : debug_tree (TYPE_BINFO (t));
13847 : 0 : return false;
13848 : : }
13849 : :
13850 : : /* Check various uses of TYPE_VALUES_RAW. */
13851 : 142212394 : if (TREE_CODE (t) == ENUMERAL_TYPE
13852 : 142212394 : && TYPE_VALUES (t))
13853 : 2329089 : verify_variant_match (TYPE_VALUES);
13854 : 139883305 : else if (TREE_CODE (t) == ARRAY_TYPE)
13855 : 504451 : verify_variant_match (TYPE_DOMAIN);
13856 : : /* Permit incomplete variants of complete type. While FEs may complete
13857 : : all variants, this does not happen for C++ templates in all cases. */
13858 : 139378854 : else if (RECORD_OR_UNION_TYPE_P (t)
13859 : 60085136 : && COMPLETE_TYPE_P (t)
13860 : 189447381 : && TYPE_FIELDS (t) != TYPE_FIELDS (tv))
13861 : : {
13862 : 3327 : tree f1, f2;
13863 : :
13864 : : /* Fortran builds qualified variants as new records with items of
13865 : : qualified type. Verify that they looks same. */
13866 : 3327 : for (f1 = TYPE_FIELDS (t), f2 = TYPE_FIELDS (tv);
13867 : 10919 : f1 && f2;
13868 : 7592 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
13869 : 7592 : if (TREE_CODE (f1) != FIELD_DECL || TREE_CODE (f2) != FIELD_DECL
13870 : 7592 : || (TYPE_MAIN_VARIANT (TREE_TYPE (f1))
13871 : 7592 : != TYPE_MAIN_VARIANT (TREE_TYPE (f2))
13872 : : /* FIXME: gfc_nonrestricted_type builds all types as variants
13873 : : with exception of pointer types. It deeply copies the type
13874 : : which means that we may end up with a variant type
13875 : : referring non-variant pointer. We may change it to
13876 : : produce types as variants, too, like
13877 : : objc_get_protocol_qualified_type does. */
13878 : 21 : && !POINTER_TYPE_P (TREE_TYPE (f1)))
13879 : 7592 : || DECL_FIELD_OFFSET (f1) != DECL_FIELD_OFFSET (f2)
13880 : 15184 : || DECL_FIELD_BIT_OFFSET (f1) != DECL_FIELD_BIT_OFFSET (f2))
13881 : : break;
13882 : 3327 : if (f1 || f2)
13883 : : {
13884 : 0 : error ("type variant has different %<TYPE_FIELDS%>");
13885 : 0 : debug_tree (tv);
13886 : 0 : error ("first mismatch is field");
13887 : 0 : debug_tree (f1);
13888 : 0 : error ("and field");
13889 : 0 : debug_tree (f2);
13890 : 0 : return false;
13891 : : }
13892 : : }
13893 : 139375527 : else if (FUNC_OR_METHOD_TYPE_P (t))
13894 : 178161 : verify_variant_match (TYPE_ARG_TYPES);
13895 : : /* For C++ the qualified variant of array type is really an array type
13896 : : of qualified TREE_TYPE.
13897 : : objc builds variants of pointer where pointer to type is a variant, too
13898 : : in objc_get_protocol_qualified_type. */
13899 : 142212394 : if (TREE_TYPE (t) != TREE_TYPE (tv)
13900 : 142212394 : && ((TREE_CODE (t) != ARRAY_TYPE
13901 : 0 : && !POINTER_TYPE_P (t))
13902 : 431715 : || TYPE_MAIN_VARIANT (TREE_TYPE (t))
13903 : 431715 : != TYPE_MAIN_VARIANT (TREE_TYPE (tv))))
13904 : : {
13905 : 0 : error ("type variant has different %<TREE_TYPE%>");
13906 : 0 : debug_tree (tv);
13907 : 0 : error ("type variant%'s %<TREE_TYPE%>");
13908 : 0 : debug_tree (TREE_TYPE (tv));
13909 : 0 : error ("type%'s %<TREE_TYPE%>");
13910 : 0 : debug_tree (TREE_TYPE (t));
13911 : 0 : return false;
13912 : : }
13913 : 142212394 : if (type_with_alias_set_p (t)
13914 : 142212394 : && !gimple_canonical_types_compatible_p (t, tv, false))
13915 : : {
13916 : 0 : error ("type is not compatible with its variant");
13917 : 0 : debug_tree (tv);
13918 : 0 : error ("type variant%'s %<TREE_TYPE%>");
13919 : 0 : debug_tree (TREE_TYPE (tv));
13920 : 0 : error ("type%'s %<TREE_TYPE%>");
13921 : 0 : debug_tree (TREE_TYPE (t));
13922 : 0 : return false;
13923 : : }
13924 : : return true;
13925 : : #undef verify_variant_match
13926 : : }
13927 : :
13928 : :
13929 : : /* The TYPE_CANONICAL merging machinery. It should closely resemble
13930 : : the middle-end types_compatible_p function. It needs to avoid
13931 : : claiming types are different for types that should be treated
13932 : : the same with respect to TBAA. Canonical types are also used
13933 : : for IL consistency checks via the useless_type_conversion_p
13934 : : predicate which does not handle all type kinds itself but falls
13935 : : back to pointer-comparison of TYPE_CANONICAL for aggregates
13936 : : for example. */
13937 : :
13938 : : /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
13939 : : type calculation because we need to allow inter-operability between signed
13940 : : and unsigned variants. */
13941 : :
13942 : : bool
13943 : 1770199 : type_with_interoperable_signedness (const_tree type)
13944 : : {
13945 : : /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
13946 : : signed char and unsigned char. Similarly fortran FE builds
13947 : : C_SIZE_T as signed type, while C defines it unsigned. */
13948 : :
13949 : 1770199 : return tree_code_for_canonical_type_merging (TREE_CODE (type))
13950 : : == INTEGER_TYPE
13951 : 1769998 : && (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)
13952 : 474794 : || TYPE_PRECISION (type) == TYPE_PRECISION (size_type_node));
13953 : : }
13954 : :
13955 : : /* Return true iff T1 and T2 are structurally identical for what
13956 : : TBAA is concerned.
13957 : : This function is used both by lto.cc canonical type merging and by the
13958 : : verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
13959 : : that have TYPE_CANONICAL defined and assume them equivalent. This is useful
13960 : : only for LTO because only in these cases TYPE_CANONICAL equivalence
13961 : : correspond to one defined by gimple_canonical_types_compatible_p. */
13962 : :
13963 : : bool
13964 : 306738585 : gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
13965 : : bool trust_type_canonical)
13966 : : {
13967 : : /* Type variants should be same as the main variant. When not doing sanity
13968 : : checking to verify this fact, go to main variants and save some work. */
13969 : 306738585 : if (trust_type_canonical)
13970 : : {
13971 : 947433 : t1 = TYPE_MAIN_VARIANT (t1);
13972 : 947433 : t2 = TYPE_MAIN_VARIANT (t2);
13973 : : }
13974 : :
13975 : : /* Check first for the obvious case of pointer identity. */
13976 : 306738585 : if (t1 == t2)
13977 : : return true;
13978 : :
13979 : : /* Check that we have two types to compare. */
13980 : 254945008 : if (t1 == NULL_TREE || t2 == NULL_TREE)
13981 : : return false;
13982 : :
13983 : : /* We consider complete types always compatible with incomplete type.
13984 : : This does not make sense for canonical type calculation and thus we
13985 : : need to ensure that we are never called on it.
13986 : :
13987 : : FIXME: For more correctness the function probably should have three modes
13988 : : 1) mode assuming that types are complete mathcing their structure
13989 : : 2) mode allowing incomplete types but producing equivalence classes
13990 : : and thus ignoring all info from complete types
13991 : : 3) mode allowing incomplete types to match complete but checking
13992 : : compatibility between complete types.
13993 : :
13994 : : 1 and 2 can be used for canonical type calculation. 3 is the real
13995 : : definition of type compatibility that can be used i.e. for warnings during
13996 : : declaration merging. */
13997 : :
13998 : 254945008 : gcc_assert (!trust_type_canonical
13999 : : || (type_with_alias_set_p (t1) && type_with_alias_set_p (t2)));
14000 : :
14001 : : /* If the types have been previously registered and found equal
14002 : : they still are. */
14003 : :
14004 : 509657897 : if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t2)
14005 : 508801927 : && trust_type_canonical)
14006 : : {
14007 : : /* Do not use TYPE_CANONICAL of pointer types. For LTO streamed types
14008 : : they are always NULL, but they are set to non-NULL for types
14009 : : constructed by build_pointer_type and variants. In this case the
14010 : : TYPE_CANONICAL is more fine grained than the equivalnce we test (where
14011 : : all pointers are considered equal. Be sure to not return false
14012 : : negatives. */
14013 : 175976 : gcc_checking_assert (canonical_type_used_p (t1)
14014 : : && canonical_type_used_p (t2));
14015 : 87988 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
14016 : : }
14017 : :
14018 : : /* For types where we do ODR based TBAA the canonical type is always
14019 : : set correctly, so we know that types are different if their
14020 : : canonical types does not match. */
14021 : 254857020 : if (trust_type_canonical
14022 : 255713490 : && (odr_type_p (t1) && odr_based_tbaa_p (t1))
14023 : 856470 : != (odr_type_p (t2) && odr_based_tbaa_p (t2)))
14024 : : return false;
14025 : :
14026 : : /* Can't be the same type if the types don't have the same code. */
14027 : 254857020 : enum tree_code code = tree_code_for_canonical_type_merging (TREE_CODE (t1));
14028 : 506908714 : if (code != tree_code_for_canonical_type_merging (TREE_CODE (t2)))
14029 : : return false;
14030 : :
14031 : : /* Qualifiers do not matter for canonical type comparison purposes. */
14032 : :
14033 : : /* Void types and nullptr types are always the same. */
14034 : 254856985 : if (VOID_TYPE_P (t1)
14035 : 254817681 : || TREE_CODE (t1) == NULLPTR_TYPE)
14036 : : return true;
14037 : :
14038 : : /* Can't be compatible types if they have different mode. Because of
14039 : : flexible array members, we allow mismatching modes for structures or
14040 : : unions. */
14041 : 254264112 : if (!RECORD_OR_UNION_TYPE_P (t1)
14042 : 254264112 : && TREE_CODE (t1) != ARRAY_TYPE
14043 : 254264112 : && TYPE_MODE (t1) != TYPE_MODE (t2))
14044 : : return false;
14045 : :
14046 : : /* Non-aggregate types can be handled cheaply. */
14047 : 254264112 : if (INTEGRAL_TYPE_P (t1)
14048 : 254264112 : || SCALAR_FLOAT_TYPE_P (t1)
14049 : 138135455 : || FIXED_POINT_TYPE_P (t1)
14050 : 137739977 : || VECTOR_TYPE_P (t1)
14051 : 137714169 : || TREE_CODE (t1) == COMPLEX_TYPE
14052 : 137357744 : || TREE_CODE (t1) == OFFSET_TYPE
14053 : 137357044 : || POINTER_TYPE_P (t1))
14054 : : {
14055 : : /* Can't be the same type if they have different precision. */
14056 : 152509576 : if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
14057 : : return false;
14058 : :
14059 : : /* In some cases the signed and unsigned types are required to be
14060 : : inter-operable. */
14061 : 152509576 : if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)
14062 : 152509576 : && !type_with_interoperable_signedness (t1))
14063 : : return false;
14064 : :
14065 : : /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
14066 : : interoperable with "signed char". Unless all frontends are revisited
14067 : : to agree on these types, we must ignore the flag completely. */
14068 : :
14069 : : /* Fortran standard define C_PTR type that is compatible with every
14070 : : C pointer. For this reason we need to glob all pointers into one.
14071 : : Still pointers in different address spaces are not compatible. */
14072 : 152509576 : if (POINTER_TYPE_P (t1))
14073 : : {
14074 : 35602508 : if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
14075 : 35602508 : != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
14076 : : return false;
14077 : : }
14078 : :
14079 : : /* Tail-recurse to components. */
14080 : 152509576 : if (VECTOR_TYPE_P (t1)
14081 : 152509576 : || TREE_CODE (t1) == COMPLEX_TYPE)
14082 : 382233 : return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
14083 : 382233 : TREE_TYPE (t2),
14084 : 382233 : trust_type_canonical);
14085 : :
14086 : : return true;
14087 : : }
14088 : :
14089 : : /* Do type-specific comparisons. */
14090 : 101754536 : switch (TREE_CODE (t1))
14091 : : {
14092 : 939195 : case ARRAY_TYPE:
14093 : : /* Array types are the same if the element types are the same and
14094 : : minimum and maximum index are the same. */
14095 : 939195 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14096 : : trust_type_canonical)
14097 : 939160 : || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
14098 : 939160 : || TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2)
14099 : 1878355 : || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
14100 : : return false;
14101 : : else
14102 : : {
14103 : 939160 : tree i1 = TYPE_DOMAIN (t1);
14104 : 939160 : tree i2 = TYPE_DOMAIN (t2);
14105 : :
14106 : : /* For an incomplete external array, the type domain can be
14107 : : NULL_TREE. Check this condition also. */
14108 : 939160 : if (i1 == NULL_TREE && i2 == NULL_TREE)
14109 : : return true;
14110 : 841161 : else if (i1 == NULL_TREE || i2 == NULL_TREE)
14111 : : return false;
14112 : : else
14113 : : {
14114 : 841161 : tree min1 = TYPE_MIN_VALUE (i1);
14115 : 841161 : tree min2 = TYPE_MIN_VALUE (i2);
14116 : 841161 : tree max1 = TYPE_MAX_VALUE (i1);
14117 : 841161 : tree max2 = TYPE_MAX_VALUE (i2);
14118 : :
14119 : : /* The minimum/maximum values have to be the same. */
14120 : 841161 : if ((min1 == min2
14121 : 0 : || (min1 && min2
14122 : 0 : && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
14123 : 0 : && TREE_CODE (min2) == PLACEHOLDER_EXPR)
14124 : 0 : || operand_equal_p (min1, min2, 0))))
14125 : 841161 : && (max1 == max2
14126 : 0 : || (max1 && max2
14127 : 0 : && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
14128 : 0 : && TREE_CODE (max2) == PLACEHOLDER_EXPR)
14129 : 0 : || operand_equal_p (max1, max2, 0)))))
14130 : 841161 : return true;
14131 : : else
14132 : 0 : return false;
14133 : : }
14134 : : }
14135 : :
14136 : 14783 : case METHOD_TYPE:
14137 : 14783 : case FUNCTION_TYPE:
14138 : : /* Function types are the same if the return type and arguments types
14139 : : are the same. */
14140 : 14783 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14141 : : trust_type_canonical))
14142 : : return false;
14143 : :
14144 : 14783 : if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)
14145 : 14783 : && (TYPE_NO_NAMED_ARGS_STDARG_P (t1)
14146 : 539 : == TYPE_NO_NAMED_ARGS_STDARG_P (t2)))
14147 : : return true;
14148 : : else
14149 : : {
14150 : 14244 : tree parms1, parms2;
14151 : :
14152 : 14244 : for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
14153 : 61181 : parms1 && parms2;
14154 : 46937 : parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
14155 : : {
14156 : 46937 : if (!gimple_canonical_types_compatible_p
14157 : 46937 : (TREE_VALUE (parms1), TREE_VALUE (parms2),
14158 : : trust_type_canonical))
14159 : : return false;
14160 : : }
14161 : :
14162 : 14244 : if (parms1 || parms2)
14163 : : return false;
14164 : :
14165 : : return true;
14166 : : }
14167 : :
14168 : 100451370 : case RECORD_TYPE:
14169 : 100451370 : case UNION_TYPE:
14170 : 100451370 : case QUAL_UNION_TYPE:
14171 : 100451370 : {
14172 : 100451370 : tree f1, f2;
14173 : :
14174 : : /* Don't try to compare variants of an incomplete type, before
14175 : : TYPE_FIELDS has been copied around. */
14176 : 100451370 : if (!COMPLETE_TYPE_P (t1) && !COMPLETE_TYPE_P (t2))
14177 : : return true;
14178 : :
14179 : :
14180 : 91048737 : if (TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2))
14181 : : return false;
14182 : :
14183 : : /* For aggregate types, all the fields must be the same. */
14184 : 91048737 : for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
14185 : 142380631 : f1 || f2;
14186 : 51331894 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
14187 : : {
14188 : : /* Skip non-fields and zero-sized fields, except zero-sized
14189 : : arrays at the end. */
14190 : 1503877321 : while (f1 && (TREE_CODE (f1) != FIELD_DECL
14191 : 93377548 : || (DECL_SIZE (f1)
14192 : 93362933 : && integer_zerop (DECL_SIZE (f1))
14193 : 42045631 : && (TREE_CHAIN (f1)
14194 : 4239 : || TREE_CODE (TREE_TYPE (f1))
14195 : : != ARRAY_TYPE))))
14196 : 1362577653 : f1 = TREE_CHAIN (f1);
14197 : 1503879063 : while (f2 && (TREE_CODE (f2) != FIELD_DECL
14198 : 93429144 : || (DECL_SIZE (f2)
14199 : 93414509 : && integer_zerop (DECL_SIZE (f2))
14200 : 42047378 : && (TREE_CHAIN (f2)
14201 : 5434 : || TREE_CODE (TREE_TYPE (f2))
14202 : : != ARRAY_TYPE))))
14203 : 1362579395 : f2 = TREE_CHAIN (f2);
14204 : 141299668 : if (!f1 || !f2)
14205 : : break;
14206 : :
14207 : 51332121 : tree t1 = TREE_TYPE (f1);
14208 : 51332121 : tree t2 = TREE_TYPE (f2);
14209 : :
14210 : : /* If the last element are arrays, we only compare the element
14211 : : types. */
14212 : 52398778 : if (TREE_CHAIN (f1) == NULL_TREE && TREE_CODE (t1) == ARRAY_TYPE
14213 : 51408946 : && TREE_CHAIN (f2) == NULL_TREE && TREE_CODE (t2) == ARRAY_TYPE)
14214 : : {
14215 : : /* If both arrays have zero size, this is a match. */
14216 : 139443 : if (DECL_SIZE (f1) && integer_zerop (DECL_SIZE (f1))
14217 : 77024 : && DECL_SIZE (f2) && integer_zerop (DECL_SIZE (f2)))
14218 : : return true;
14219 : :
14220 : 76617 : t1 = TREE_TYPE (t1);
14221 : 76617 : t2 = TREE_TYPE (t2);
14222 : : }
14223 : :
14224 : 51331918 : if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
14225 : 51331913 : || !gimple_compare_field_offset (f1, f2)
14226 : 102663831 : || !gimple_canonical_types_compatible_p
14227 : 51331913 : (t1, t2, trust_type_canonical))
14228 : 24 : return false;
14229 : : }
14230 : :
14231 : : /* If one aggregate has more fields than the other, they
14232 : : are not the same. */
14233 : 91048510 : if (f1 || f2)
14234 : : return false;
14235 : :
14236 : : return true;
14237 : : }
14238 : :
14239 : 349188 : default:
14240 : : /* Consider all types with language specific trees in them mutually
14241 : : compatible. This is executed only from verify_type and false
14242 : : positives can be tolerated. */
14243 : 349188 : gcc_assert (!in_lto_p);
14244 : : return true;
14245 : : }
14246 : : }
14247 : :
14248 : : /* For OPAQUE_TYPE T, it should have only size and alignment information
14249 : : and its mode should be of class MODE_OPAQUE. This function verifies
14250 : : these properties of T match TV which is the main variant of T and TC
14251 : : which is the canonical of T. */
14252 : :
14253 : : static void
14254 : 0 : verify_opaque_type (const_tree t, tree tv, tree tc)
14255 : : {
14256 : 0 : gcc_assert (OPAQUE_TYPE_P (t));
14257 : 0 : gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv));
14258 : 0 : gcc_assert (tc && tc == TYPE_CANONICAL (tc));
14259 : :
14260 : : /* For an opaque type T1, check if some of its properties match
14261 : : the corresponding ones of the other opaque type T2, emit some
14262 : : error messages for those inconsistent ones. */
14263 : 0 : auto check_properties_for_opaque_type = [](const_tree t1, tree t2,
14264 : : const char *kind_msg)
14265 : : {
14266 : 0 : if (!OPAQUE_TYPE_P (t2))
14267 : : {
14268 : 0 : error ("type %s is not an opaque type", kind_msg);
14269 : 0 : debug_tree (t2);
14270 : 0 : return;
14271 : : }
14272 : 0 : if (!OPAQUE_MODE_P (TYPE_MODE (t2)))
14273 : : {
14274 : 0 : error ("type %s is not with opaque mode", kind_msg);
14275 : 0 : debug_tree (t2);
14276 : 0 : return;
14277 : : }
14278 : 0 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
14279 : : {
14280 : 0 : error ("type %s differs by %<TYPE_MODE%>", kind_msg);
14281 : 0 : debug_tree (t2);
14282 : 0 : return;
14283 : : }
14284 : 0 : poly_uint64 t1_size = tree_to_poly_uint64 (TYPE_SIZE (t1));
14285 : 0 : poly_uint64 t2_size = tree_to_poly_uint64 (TYPE_SIZE (t2));
14286 : 0 : if (maybe_ne (t1_size, t2_size))
14287 : : {
14288 : 0 : error ("type %s differs by %<TYPE_SIZE%>", kind_msg);
14289 : 0 : debug_tree (t2);
14290 : 0 : return;
14291 : : }
14292 : 0 : if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2))
14293 : : {
14294 : 0 : error ("type %s differs by %<TYPE_ALIGN%>", kind_msg);
14295 : 0 : debug_tree (t2);
14296 : 0 : return;
14297 : : }
14298 : 0 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
14299 : : {
14300 : 0 : error ("type %s differs by %<TYPE_USER_ALIGN%>", kind_msg);
14301 : 0 : debug_tree (t2);
14302 : 0 : return;
14303 : : }
14304 : : };
14305 : :
14306 : 0 : if (t != tv)
14307 : 0 : check_properties_for_opaque_type (t, tv, "variant");
14308 : :
14309 : 0 : if (t != tc)
14310 : 0 : check_properties_for_opaque_type (t, tc, "canonical");
14311 : 0 : }
14312 : :
14313 : : /* Verify type T. */
14314 : :
14315 : : void
14316 : 712112741 : verify_type (const_tree t)
14317 : : {
14318 : 712112741 : bool error_found = false;
14319 : 712112741 : tree mv = TYPE_MAIN_VARIANT (t);
14320 : 712112741 : tree ct = TYPE_CANONICAL (t);
14321 : :
14322 : 712112741 : if (OPAQUE_TYPE_P (t))
14323 : : {
14324 : 0 : verify_opaque_type (t, mv, ct);
14325 : 0 : return;
14326 : : }
14327 : :
14328 : 712112741 : if (!mv)
14329 : : {
14330 : 0 : error ("main variant is not defined");
14331 : 0 : error_found = true;
14332 : : }
14333 : 712112741 : else if (mv != TYPE_MAIN_VARIANT (mv))
14334 : : {
14335 : 0 : error ("%<TYPE_MAIN_VARIANT%> has different %<TYPE_MAIN_VARIANT%>");
14336 : 0 : debug_tree (mv);
14337 : 0 : error_found = true;
14338 : : }
14339 : 712112741 : else if (t != mv && !verify_type_variant (t, mv))
14340 : : error_found = true;
14341 : :
14342 : 712112741 : if (!ct)
14343 : : ;
14344 : 710118101 : else if (TYPE_CANONICAL (ct) != ct)
14345 : : {
14346 : 0 : error ("%<TYPE_CANONICAL%> has different %<TYPE_CANONICAL%>");
14347 : 0 : debug_tree (ct);
14348 : 0 : error_found = true;
14349 : : }
14350 : : /* Method and function types cannot be used to address memory and thus
14351 : : TYPE_CANONICAL really matters only for determining useless conversions.
14352 : :
14353 : : FIXME: C++ FE produce declarations of builtin functions that are not
14354 : : compatible with main variants. */
14355 : 710118101 : else if (TREE_CODE (t) == FUNCTION_TYPE)
14356 : : ;
14357 : 707289509 : else if (t != ct
14358 : : /* FIXME: gimple_canonical_types_compatible_p cannot compare types
14359 : : with variably sized arrays because their sizes possibly
14360 : : gimplified to different variables. */
14361 : 121277829 : && !variably_modified_type_p (ct, NULL)
14362 : 121273554 : && !gimple_canonical_types_compatible_p (t, ct, false)
14363 : 707339363 : && COMPLETE_TYPE_P (t))
14364 : : {
14365 : 0 : error ("%<TYPE_CANONICAL%> is not compatible");
14366 : 0 : debug_tree (ct);
14367 : 0 : error_found = true;
14368 : : }
14369 : 1280819505 : if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t)
14370 : : /* We allow a mismatch for structure or union because of
14371 : : flexible array members. */
14372 : 566778025 : && !RECORD_OR_UNION_TYPE_P (t)
14373 : 237952084 : && !RECORD_OR_UNION_TYPE_P (TYPE_CANONICAL (t))
14374 : 237952084 : && TREE_CODE (t) != ARRAY_TYPE
14375 : 948717128 : && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
14376 : : {
14377 : 0 : error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");
14378 : 0 : debug_tree (ct);
14379 : 0 : error_found = true;
14380 : : }
14381 : 712112741 : if (TYPE_MAIN_VARIANT (t) == t && ct && TYPE_MAIN_VARIANT (ct) != ct)
14382 : : {
14383 : 0 : error ("%<TYPE_CANONICAL%> of main variant is not main variant");
14384 : 0 : debug_tree (ct);
14385 : 0 : debug_tree (TYPE_MAIN_VARIANT (ct));
14386 : 0 : error_found = true;
14387 : : }
14388 : :
14389 : :
14390 : : /* Check various uses of TYPE_MIN_VALUE_RAW. */
14391 : 712112741 : if (RECORD_OR_UNION_TYPE_P (t))
14392 : : {
14393 : : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
14394 : : and danagle the pointer from time to time. */
14395 : 368282909 : if (TYPE_VFIELD (t)
14396 : 10204016 : && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
14397 : 368282909 : && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
14398 : : {
14399 : 0 : error ("%<TYPE_VFIELD%> is not %<FIELD_DECL%> nor %<TREE_LIST%>");
14400 : 0 : debug_tree (TYPE_VFIELD (t));
14401 : 0 : error_found = true;
14402 : : }
14403 : : }
14404 : 343829832 : else if (TREE_CODE (t) == POINTER_TYPE)
14405 : : {
14406 : 91598125 : if (TYPE_NEXT_PTR_TO (t)
14407 : 91598125 : && TREE_CODE (TYPE_NEXT_PTR_TO (t)) != POINTER_TYPE)
14408 : : {
14409 : 0 : error ("%<TYPE_NEXT_PTR_TO%> is not %<POINTER_TYPE%>");
14410 : 0 : debug_tree (TYPE_NEXT_PTR_TO (t));
14411 : 0 : error_found = true;
14412 : : }
14413 : : }
14414 : 252231707 : else if (TREE_CODE (t) == REFERENCE_TYPE)
14415 : : {
14416 : 42041789 : if (TYPE_NEXT_REF_TO (t)
14417 : 42041789 : && TREE_CODE (TYPE_NEXT_REF_TO (t)) != REFERENCE_TYPE)
14418 : : {
14419 : 0 : error ("%<TYPE_NEXT_REF_TO%> is not %<REFERENCE_TYPE%>");
14420 : 0 : debug_tree (TYPE_NEXT_REF_TO (t));
14421 : 0 : error_found = true;
14422 : : }
14423 : : }
14424 : : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14425 : : || FIXED_POINT_TYPE_P (t))
14426 : : {
14427 : : /* FIXME: The following check should pass:
14428 : : useless_type_conversion_p (const_cast <tree> (t),
14429 : : TREE_TYPE (TYPE_MIN_VALUE (t))
14430 : : but does not for C sizetypes in LTO. */
14431 : : }
14432 : :
14433 : : /* Check various uses of TYPE_MAXVAL_RAW. */
14434 : 712112741 : if (RECORD_OR_UNION_TYPE_P (t))
14435 : : {
14436 : 368282909 : if (!TYPE_BINFO (t))
14437 : : ;
14438 : 343809467 : else if (TREE_CODE (TYPE_BINFO (t)) != TREE_BINFO)
14439 : : {
14440 : 0 : error ("%<TYPE_BINFO%> is not %<TREE_BINFO%>");
14441 : 0 : debug_tree (TYPE_BINFO (t));
14442 : 0 : error_found = true;
14443 : : }
14444 : 343809467 : else if (TREE_TYPE (TYPE_BINFO (t)) != TYPE_MAIN_VARIANT (t))
14445 : : {
14446 : 0 : error ("%<TYPE_BINFO%> type is not %<TYPE_MAIN_VARIANT%>");
14447 : 0 : debug_tree (TREE_TYPE (TYPE_BINFO (t)));
14448 : 0 : error_found = true;
14449 : : }
14450 : : }
14451 : : else if (FUNC_OR_METHOD_TYPE_P (t))
14452 : : {
14453 : 3073832 : if (TYPE_METHOD_BASETYPE (t)
14454 : 95759 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != RECORD_TYPE
14455 : 3074050 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != UNION_TYPE)
14456 : : {
14457 : 0 : error ("%<TYPE_METHOD_BASETYPE%> is not record nor union");
14458 : 0 : debug_tree (TYPE_METHOD_BASETYPE (t));
14459 : 0 : error_found = true;
14460 : : }
14461 : : }
14462 : : else if (TREE_CODE (t) == OFFSET_TYPE)
14463 : : {
14464 : 35190 : if (TYPE_OFFSET_BASETYPE (t)
14465 : 35190 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != RECORD_TYPE
14466 : 35198 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != UNION_TYPE)
14467 : : {
14468 : 0 : error ("%<TYPE_OFFSET_BASETYPE%> is not record nor union");
14469 : 0 : debug_tree (TYPE_OFFSET_BASETYPE (t));
14470 : 0 : error_found = true;
14471 : : }
14472 : : }
14473 : : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14474 : : || FIXED_POINT_TYPE_P (t))
14475 : : {
14476 : : /* FIXME: The following check should pass:
14477 : : useless_type_conversion_p (const_cast <tree> (t),
14478 : : TREE_TYPE (TYPE_MAX_VALUE (t))
14479 : : but does not for C sizetypes in LTO. */
14480 : : }
14481 : : else if (TREE_CODE (t) == ARRAY_TYPE)
14482 : : {
14483 : 1589878 : if (TYPE_ARRAY_MAX_SIZE (t)
14484 : 1589878 : && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t)) != INTEGER_CST)
14485 : : {
14486 : 0 : error ("%<TYPE_ARRAY_MAX_SIZE%> not %<INTEGER_CST%>");
14487 : 0 : debug_tree (TYPE_ARRAY_MAX_SIZE (t));
14488 : 0 : error_found = true;
14489 : : }
14490 : : }
14491 : 238817128 : else if (TYPE_MAX_VALUE_RAW (t))
14492 : : {
14493 : 0 : error ("%<TYPE_MAX_VALUE_RAW%> non-NULL");
14494 : 0 : debug_tree (TYPE_MAX_VALUE_RAW (t));
14495 : 0 : error_found = true;
14496 : : }
14497 : :
14498 : 712112741 : if (TYPE_LANG_SLOT_1 (t) && in_lto_p)
14499 : : {
14500 : 0 : error ("%<TYPE_LANG_SLOT_1 (binfo)%> field is non-NULL");
14501 : 0 : debug_tree (TYPE_LANG_SLOT_1 (t));
14502 : 0 : error_found = true;
14503 : : }
14504 : :
14505 : : /* Check various uses of TYPE_VALUES_RAW. */
14506 : 712112741 : if (TREE_CODE (t) == ENUMERAL_TYPE)
14507 : 84476212 : for (tree l = TYPE_VALUES (t); l; l = TREE_CHAIN (l))
14508 : : {
14509 : 74022634 : tree value = TREE_VALUE (l);
14510 : 74022634 : tree name = TREE_PURPOSE (l);
14511 : :
14512 : : /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
14513 : : CONST_DECL of ENUMERAL TYPE. */
14514 : 74022634 : if (TREE_CODE (value) != INTEGER_CST && TREE_CODE (value) != CONST_DECL)
14515 : : {
14516 : 0 : error ("enum value is not %<CONST_DECL%> or %<INTEGER_CST%>");
14517 : 0 : debug_tree (value);
14518 : 0 : debug_tree (name);
14519 : 0 : error_found = true;
14520 : : }
14521 : 74022634 : if (TREE_CODE (TREE_TYPE (value)) != INTEGER_TYPE
14522 : 74005368 : && TREE_CODE (TREE_TYPE (value)) != BOOLEAN_TYPE
14523 : 148027999 : && !useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (value)))
14524 : : {
14525 : 0 : error ("enum value type is not %<INTEGER_TYPE%> nor convertible "
14526 : : "to the enum");
14527 : 0 : debug_tree (value);
14528 : 0 : debug_tree (name);
14529 : 0 : error_found = true;
14530 : : }
14531 : 74022634 : if (TREE_CODE (name) != IDENTIFIER_NODE)
14532 : : {
14533 : 0 : error ("enum value name is not %<IDENTIFIER_NODE%>");
14534 : 0 : debug_tree (value);
14535 : 0 : debug_tree (name);
14536 : 0 : error_found = true;
14537 : : }
14538 : : }
14539 : 701659163 : else if (TREE_CODE (t) == ARRAY_TYPE)
14540 : : {
14541 : 1589878 : if (TYPE_DOMAIN (t) && TREE_CODE (TYPE_DOMAIN (t)) != INTEGER_TYPE)
14542 : : {
14543 : 0 : error ("array %<TYPE_DOMAIN%> is not integer type");
14544 : 0 : debug_tree (TYPE_DOMAIN (t));
14545 : 0 : error_found = true;
14546 : : }
14547 : : }
14548 : 700069285 : else if (RECORD_OR_UNION_TYPE_P (t))
14549 : : {
14550 : 368282909 : if (TYPE_FIELDS (t) && !COMPLETE_TYPE_P (t) && in_lto_p)
14551 : : {
14552 : 0 : error ("%<TYPE_FIELDS%> defined in incomplete type");
14553 : 0 : error_found = true;
14554 : : }
14555 : 16843300605 : for (tree fld = TYPE_FIELDS (t); fld; fld = TREE_CHAIN (fld))
14556 : : {
14557 : : /* TODO: verify properties of decls. */
14558 : 16475017696 : if (TREE_CODE (fld) == FIELD_DECL)
14559 : : ;
14560 : : else if (TREE_CODE (fld) == TYPE_DECL)
14561 : : ;
14562 : : else if (TREE_CODE (fld) == CONST_DECL)
14563 : : ;
14564 : : else if (VAR_P (fld))
14565 : : ;
14566 : : else if (TREE_CODE (fld) == TEMPLATE_DECL)
14567 : : ;
14568 : : else if (TREE_CODE (fld) == USING_DECL)
14569 : : ;
14570 : : else if (TREE_CODE (fld) == FUNCTION_DECL)
14571 : : ;
14572 : : else
14573 : : {
14574 : 0 : error ("wrong tree in %<TYPE_FIELDS%> list");
14575 : 0 : debug_tree (fld);
14576 : 0 : error_found = true;
14577 : : }
14578 : : }
14579 : : }
14580 : 331786376 : else if (TREE_CODE (t) == INTEGER_TYPE
14581 : : || TREE_CODE (t) == BOOLEAN_TYPE
14582 : 331786376 : || TREE_CODE (t) == BITINT_TYPE
14583 : 245589638 : || TREE_CODE (t) == OFFSET_TYPE
14584 : 245554448 : || TREE_CODE (t) == REFERENCE_TYPE
14585 : 203512659 : || TREE_CODE (t) == NULLPTR_TYPE
14586 : 203220223 : || TREE_CODE (t) == POINTER_TYPE)
14587 : : {
14588 : 220164278 : if (TYPE_CACHED_VALUES_P (t) != (TYPE_CACHED_VALUES (t) != NULL))
14589 : : {
14590 : 0 : error ("%<TYPE_CACHED_VALUES_P%> is %i while %<TYPE_CACHED_VALUES%> "
14591 : : "is %p",
14592 : 0 : TYPE_CACHED_VALUES_P (t), (void *)TYPE_CACHED_VALUES (t));
14593 : 0 : error_found = true;
14594 : : }
14595 : 220164278 : else if (TYPE_CACHED_VALUES_P (t) && TREE_CODE (TYPE_CACHED_VALUES (t)) != TREE_VEC)
14596 : : {
14597 : 0 : error ("%<TYPE_CACHED_VALUES%> is not %<TREE_VEC%>");
14598 : 0 : debug_tree (TYPE_CACHED_VALUES (t));
14599 : 0 : error_found = true;
14600 : : }
14601 : : /* Verify just enough of cache to ensure that no one copied it to new type.
14602 : : All copying should go by copy_node that should clear it. */
14603 : 220164278 : else if (TYPE_CACHED_VALUES_P (t))
14604 : : {
14605 : : int i;
14606 : 7675262299 : for (i = 0; i < TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t)); i++)
14607 : 7628975952 : if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)
14608 : 7628975952 : && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)) != t)
14609 : : {
14610 : 0 : error ("wrong %<TYPE_CACHED_VALUES%> entry");
14611 : 0 : debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i));
14612 : 0 : error_found = true;
14613 : 0 : break;
14614 : : }
14615 : : }
14616 : : }
14617 : 111622098 : else if (FUNC_OR_METHOD_TYPE_P (t))
14618 : 12371596 : for (tree l = TYPE_ARG_TYPES (t); l; l = TREE_CHAIN (l))
14619 : : {
14620 : : /* C++ FE uses TREE_PURPOSE to store initial values. */
14621 : 9297764 : if (TREE_PURPOSE (l) && in_lto_p)
14622 : : {
14623 : 0 : error ("%<TREE_PURPOSE%> is non-NULL in %<TYPE_ARG_TYPES%> list");
14624 : 0 : debug_tree (l);
14625 : 0 : error_found = true;
14626 : : }
14627 : 9297764 : if (!TYPE_P (TREE_VALUE (l)))
14628 : : {
14629 : 0 : error ("wrong entry in %<TYPE_ARG_TYPES%> list");
14630 : 0 : debug_tree (l);
14631 : 0 : error_found = true;
14632 : : }
14633 : : }
14634 : 216726616 : else if (!is_lang_specific (t) && TYPE_VALUES_RAW (t))
14635 : : {
14636 : 0 : error ("%<TYPE_VALUES_RAW%> field is non-NULL");
14637 : 0 : debug_tree (TYPE_VALUES_RAW (t));
14638 : 0 : error_found = true;
14639 : : }
14640 : 712112741 : if (TREE_CODE (t) != INTEGER_TYPE
14641 : : && TREE_CODE (t) != BOOLEAN_TYPE
14642 : 712112741 : && TREE_CODE (t) != BITINT_TYPE
14643 : : && TREE_CODE (t) != OFFSET_TYPE
14644 : : && TREE_CODE (t) != REFERENCE_TYPE
14645 : : && TREE_CODE (t) != NULLPTR_TYPE
14646 : : && TREE_CODE (t) != POINTER_TYPE
14647 : 491948463 : && TYPE_CACHED_VALUES_P (t))
14648 : : {
14649 : 0 : error ("%<TYPE_CACHED_VALUES_P%> is set while it should not be");
14650 : 0 : error_found = true;
14651 : : }
14652 : :
14653 : : /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
14654 : : TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
14655 : : of a type. */
14656 : 712112741 : if (TREE_CODE (t) == METHOD_TYPE
14657 : 712112741 : && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t)) != TYPE_METHOD_BASETYPE (t))
14658 : : {
14659 : 0 : error ("%<TYPE_METHOD_BASETYPE%> is not main variant");
14660 : 0 : error_found = true;
14661 : : }
14662 : :
14663 : 712112741 : if (error_found)
14664 : : {
14665 : 0 : debug_tree (const_cast <tree> (t));
14666 : 0 : internal_error ("%qs failed", __func__);
14667 : : }
14668 : : }
14669 : :
14670 : :
14671 : : /* Return 1 if ARG interpreted as signed in its precision is known to be
14672 : : always non-negative or 2 if ARG is known to be always negative, or 3 if
14673 : : ARG may be non-negative or negative. STMT if specified is the statement
14674 : : on which it is being tested. */
14675 : :
14676 : : int
14677 : 806555 : get_range_pos_neg (tree arg, gimple *stmt)
14678 : : {
14679 : 806555 : if (arg == error_mark_node)
14680 : : return 3;
14681 : :
14682 : 806555 : int prec = TYPE_PRECISION (TREE_TYPE (arg));
14683 : 806555 : int cnt = 0;
14684 : 806555 : if (TREE_CODE (arg) == INTEGER_CST)
14685 : : {
14686 : 79232 : wide_int w = wi::sext (wi::to_wide (arg), prec);
14687 : 79232 : if (wi::neg_p (w))
14688 : : return 2;
14689 : : else
14690 : 64895 : return 1;
14691 : 79232 : }
14692 : 726112 : while (CONVERT_EXPR_P (arg)
14693 : 14494 : && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
14694 : 755100 : && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg, 0))) <= prec)
14695 : : {
14696 : 13710 : arg = TREE_OPERAND (arg, 0);
14697 : : /* Narrower value zero extended into wider type
14698 : : will always result in positive values. */
14699 : 13710 : if (TYPE_UNSIGNED (TREE_TYPE (arg))
14700 : 13710 : && TYPE_PRECISION (TREE_TYPE (arg)) < prec)
14701 : : return 1;
14702 : 13283 : prec = TYPE_PRECISION (TREE_TYPE (arg));
14703 : 13283 : if (++cnt > 30)
14704 : : return 3;
14705 : : }
14706 : :
14707 : 726896 : if (TREE_CODE (arg) != SSA_NAME)
14708 : : return 3;
14709 : 720525 : int_range_max r;
14710 : 1455352 : while (!get_range_query (cfun)->range_of_expr (r, arg, stmt)
14711 : 1469654 : || r.undefined_p () || r.varying_p ())
14712 : : {
14713 : 439112 : gimple *g = SSA_NAME_DEF_STMT (arg);
14714 : 439112 : if (is_gimple_assign (g)
14715 : 439112 : && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (g)))
14716 : : {
14717 : 24823 : tree t = gimple_assign_rhs1 (g);
14718 : 49292 : if (INTEGRAL_TYPE_P (TREE_TYPE (t))
14719 : 46654 : && TYPE_PRECISION (TREE_TYPE (t)) <= prec)
14720 : : {
14721 : 14302 : if (TYPE_UNSIGNED (TREE_TYPE (t))
14722 : 14302 : && TYPE_PRECISION (TREE_TYPE (t)) < prec)
14723 : : return 1;
14724 : 14302 : prec = TYPE_PRECISION (TREE_TYPE (t));
14725 : 14302 : arg = t;
14726 : 14302 : if (++cnt > 30)
14727 : : return 3;
14728 : 14302 : continue;
14729 : : }
14730 : : }
14731 : : return 3;
14732 : : }
14733 : 295715 : if (TYPE_UNSIGNED (TREE_TYPE (arg)))
14734 : : {
14735 : : /* For unsigned values, the "positive" range comes
14736 : : below the "negative" range. */
14737 : 132350 : if (!wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14738 : : return 1;
14739 : 38310 : if (wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14740 : : return 2;
14741 : : }
14742 : : else
14743 : : {
14744 : 163365 : if (!wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
14745 : : return 1;
14746 : 69429 : if (wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
14747 : : return 2;
14748 : : }
14749 : : return 3;
14750 : 720525 : }
14751 : :
14752 : :
14753 : :
14754 : :
14755 : : /* Return true if ARG is marked with the nonnull attribute in the
14756 : : current function signature. */
14757 : :
14758 : : bool
14759 : 26046077 : nonnull_arg_p (const_tree arg)
14760 : : {
14761 : 26046077 : tree t, attrs, fntype;
14762 : 26046077 : unsigned HOST_WIDE_INT arg_num;
14763 : :
14764 : 26046077 : gcc_assert (TREE_CODE (arg) == PARM_DECL
14765 : : && (POINTER_TYPE_P (TREE_TYPE (arg))
14766 : : || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE));
14767 : :
14768 : : /* The static chain decl is always non null. */
14769 : 26046077 : if (arg == cfun->static_chain_decl)
14770 : : return true;
14771 : :
14772 : : /* THIS argument of method is always non-NULL. */
14773 : 25778005 : if (TREE_CODE (TREE_TYPE (cfun->decl)) == METHOD_TYPE
14774 : 10123593 : && arg == DECL_ARGUMENTS (cfun->decl)
14775 : 32091395 : && flag_delete_null_pointer_checks)
14776 : : return true;
14777 : :
14778 : : /* Values passed by reference are always non-NULL. */
14779 : 19466736 : if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
14780 : 19466736 : && flag_delete_null_pointer_checks)
14781 : : return true;
14782 : :
14783 : 13358305 : fntype = TREE_TYPE (cfun->decl);
14784 : 13381249 : for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
14785 : : {
14786 : 534997 : attrs = lookup_attribute ("nonnull", attrs);
14787 : :
14788 : : /* If "nonnull" wasn't specified, we know nothing about the argument. */
14789 : 534997 : if (attrs == NULL_TREE)
14790 : : return false;
14791 : :
14792 : : /* If "nonnull" applies to all the arguments, then ARG is non-null. */
14793 : 110763 : if (TREE_VALUE (attrs) == NULL_TREE)
14794 : : return true;
14795 : :
14796 : : /* Get the position number for ARG in the function signature. */
14797 : 55652 : for (arg_num = 1, t = DECL_ARGUMENTS (cfun->decl);
14798 : 130174 : t;
14799 : 74522 : t = DECL_CHAIN (t), arg_num++)
14800 : : {
14801 : 130174 : if (t == arg)
14802 : : break;
14803 : : }
14804 : :
14805 : 55652 : gcc_assert (t == arg);
14806 : :
14807 : : /* Now see if ARG_NUM is mentioned in the nonnull list. */
14808 : 88330 : for (t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
14809 : : {
14810 : 65386 : if (compare_tree_int (TREE_VALUE (t), arg_num) == 0)
14811 : : return true;
14812 : : }
14813 : : }
14814 : :
14815 : : return false;
14816 : : }
14817 : :
14818 : : /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
14819 : : information. */
14820 : :
14821 : : location_t
14822 : 645332010 : set_block (location_t loc, tree block)
14823 : : {
14824 : 645332010 : location_t pure_loc = get_pure_location (loc);
14825 : 645332010 : source_range src_range = get_range_from_loc (line_table, loc);
14826 : 645332010 : unsigned discriminator = get_discriminator_from_loc (line_table, loc);
14827 : 645332010 : return line_table->get_or_create_combined_loc (pure_loc, src_range, block,
14828 : 645332010 : discriminator);
14829 : : }
14830 : :
14831 : : location_t
14832 : 216359638 : set_source_range (tree expr, location_t start, location_t finish)
14833 : : {
14834 : 216359638 : source_range src_range;
14835 : 216359638 : src_range.m_start = start;
14836 : 216359638 : src_range.m_finish = finish;
14837 : 216359638 : return set_source_range (expr, src_range);
14838 : : }
14839 : :
14840 : : location_t
14841 : 441977951 : set_source_range (tree expr, source_range src_range)
14842 : : {
14843 : 441977951 : if (!EXPR_P (expr))
14844 : : return UNKNOWN_LOCATION;
14845 : :
14846 : 194490939 : location_t expr_location = EXPR_LOCATION (expr);
14847 : 194490939 : location_t pure_loc = get_pure_location (expr_location);
14848 : 194490939 : unsigned discriminator = get_discriminator_from_loc (expr_location);
14849 : 194490939 : location_t adhoc = line_table->get_or_create_combined_loc (pure_loc,
14850 : : src_range,
14851 : : nullptr,
14852 : : discriminator);
14853 : 194490939 : SET_EXPR_LOCATION (expr, adhoc);
14854 : 194490939 : return adhoc;
14855 : : }
14856 : :
14857 : : /* Return EXPR, potentially wrapped with a node expression LOC,
14858 : : if !CAN_HAVE_LOCATION_P (expr).
14859 : :
14860 : : NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
14861 : : VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
14862 : :
14863 : : Wrapper nodes can be identified using location_wrapper_p. */
14864 : :
14865 : : tree
14866 : 1214923292 : maybe_wrap_with_location (tree expr, location_t loc)
14867 : : {
14868 : 1214923292 : if (expr == NULL)
14869 : : return NULL;
14870 : 1214923288 : if (loc == UNKNOWN_LOCATION)
14871 : : return expr;
14872 : 1175095268 : if (CAN_HAVE_LOCATION_P (expr))
14873 : : return expr;
14874 : : /* We should only be adding wrappers for constants and for decls,
14875 : : or for some exceptional tree nodes (e.g. BASELINK in the C++ FE). */
14876 : 709728621 : gcc_assert (CONSTANT_CLASS_P (expr)
14877 : : || DECL_P (expr)
14878 : : || EXCEPTIONAL_CLASS_P (expr));
14879 : :
14880 : : /* For now, don't add wrappers to exceptional tree nodes, to minimize
14881 : : any impact of the wrapper nodes. */
14882 : 709728621 : if (EXCEPTIONAL_CLASS_P (expr) || error_operand_p (expr))
14883 : : return expr;
14884 : :
14885 : : /* Compiler-generated temporary variables don't need a wrapper. */
14886 : 653425319 : if (DECL_P (expr) && DECL_ARTIFICIAL (expr) && DECL_IGNORED_P (expr))
14887 : : return expr;
14888 : :
14889 : : /* If any auto_suppress_location_wrappers are active, don't create
14890 : : wrappers. */
14891 : 653423062 : if (suppress_location_wrappers > 0)
14892 : : return expr;
14893 : :
14894 : 1246850498 : tree_code code
14895 : 153388133 : = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
14896 : 476800039 : || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
14897 : 623425249 : ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
14898 : 623425249 : tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
14899 : : /* Mark this node as being a wrapper. */
14900 : 623425249 : EXPR_LOCATION_WRAPPER_P (wrapper) = 1;
14901 : 623425249 : return wrapper;
14902 : : }
14903 : :
14904 : : int suppress_location_wrappers;
14905 : :
14906 : : /* Return the name of combined function FN, for debugging purposes. */
14907 : :
14908 : : const char *
14909 : 0 : combined_fn_name (combined_fn fn)
14910 : : {
14911 : 0 : if (builtin_fn_p (fn))
14912 : : {
14913 : 0 : tree fndecl = builtin_decl_explicit (as_builtin_fn (fn));
14914 : 0 : return IDENTIFIER_POINTER (DECL_NAME (fndecl));
14915 : : }
14916 : : else
14917 : 0 : return internal_fn_name (as_internal_fn (fn));
14918 : : }
14919 : :
14920 : : /* Return a bitmap with a bit set corresponding to each argument in
14921 : : a function call type FNTYPE declared with attribute nonnull,
14922 : : or null if none of the function's argument are nonnull. The caller
14923 : : must free the bitmap. */
14924 : :
14925 : : bitmap
14926 : 20787441 : get_nonnull_args (const_tree fntype)
14927 : : {
14928 : 20787441 : if (fntype == NULL_TREE)
14929 : : return NULL;
14930 : :
14931 : 20375342 : bitmap argmap = NULL;
14932 : 20375342 : if (TREE_CODE (fntype) == METHOD_TYPE)
14933 : : {
14934 : : /* The this pointer in C++ non-static member functions is
14935 : : implicitly nonnull whether or not it's declared as such. */
14936 : 2790568 : argmap = BITMAP_ALLOC (NULL);
14937 : 2790568 : bitmap_set_bit (argmap, 0);
14938 : : }
14939 : :
14940 : 20375342 : tree attrs = TYPE_ATTRIBUTES (fntype);
14941 : 20375342 : if (!attrs)
14942 : : return argmap;
14943 : :
14944 : : /* A function declaration can specify multiple attribute nonnull,
14945 : : each with zero or more arguments. The loop below creates a bitmap
14946 : : representing a union of all the arguments. An empty (but non-null)
14947 : : bitmap means that all arguments have been declared nonnull. */
14948 : 5600932 : for ( ; attrs; attrs = TREE_CHAIN (attrs))
14949 : : {
14950 : 5502308 : attrs = lookup_attribute ("nonnull", attrs);
14951 : 5502308 : if (!attrs)
14952 : : break;
14953 : :
14954 : 1600906 : if (!argmap)
14955 : 1561153 : argmap = BITMAP_ALLOC (NULL);
14956 : :
14957 : 1600906 : if (!TREE_VALUE (attrs))
14958 : : {
14959 : : /* Clear the bitmap in case a previous attribute nonnull
14960 : : set it and this one overrides it for all arguments. */
14961 : 980374 : bitmap_clear (argmap);
14962 : 980374 : return argmap;
14963 : : }
14964 : :
14965 : : /* Iterate over the indices of the format arguments declared nonnull
14966 : : and set a bit for each. */
14967 : 1634539 : for (tree idx = TREE_VALUE (attrs); idx; idx = TREE_CHAIN (idx))
14968 : : {
14969 : 1014007 : unsigned int val = TREE_INT_CST_LOW (TREE_VALUE (idx)) - 1;
14970 : 1014007 : bitmap_set_bit (argmap, val);
14971 : : }
14972 : : }
14973 : :
14974 : : return argmap;
14975 : : }
14976 : :
14977 : : /* Returns true if TYPE is a type where it and all of its subobjects
14978 : : (recursively) are of structure, union, or array type. */
14979 : :
14980 : : bool
14981 : 1757991417 : is_empty_type (const_tree type)
14982 : : {
14983 : 1757991417 : if (RECORD_OR_UNION_TYPE_P (type))
14984 : : {
14985 : 755459165 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
14986 : 703064130 : if (TREE_CODE (field) == FIELD_DECL
14987 : 394681379 : && !DECL_PADDING_P (field)
14988 : 1097744273 : && !is_empty_type (TREE_TYPE (field)))
14989 : : return false;
14990 : : return true;
14991 : : }
14992 : 1332952107 : else if (TREE_CODE (type) == ARRAY_TYPE)
14993 : 70936383 : return (integer_minus_onep (array_type_nelts_minus_one (type))
14994 : 70893113 : || TYPE_DOMAIN (type) == NULL_TREE
14995 : 136200048 : || is_empty_type (TREE_TYPE (type)));
14996 : : return false;
14997 : : }
14998 : :
14999 : : /* Implement TARGET_EMPTY_RECORD_P. Return true if TYPE is an empty type
15000 : : that shouldn't be passed via stack. */
15001 : :
15002 : : bool
15003 : 1249092260 : default_is_empty_record (const_tree type)
15004 : : {
15005 : 1249092260 : if (!abi_version_at_least (12))
15006 : : return false;
15007 : :
15008 : 1248046994 : if (type == error_mark_node)
15009 : : return false;
15010 : :
15011 : 1248046994 : if (TREE_ADDRESSABLE (type))
15012 : : return false;
15013 : :
15014 : 1248046994 : return is_empty_type (TYPE_MAIN_VARIANT (type));
15015 : : }
15016 : :
15017 : : /* Determine whether TYPE is a structure with a flexible array member,
15018 : : or a union containing such a structure (possibly recursively). */
15019 : :
15020 : : bool
15021 : 72534 : flexible_array_type_p (const_tree type)
15022 : : {
15023 : 72534 : tree x, last;
15024 : 72534 : switch (TREE_CODE (type))
15025 : : {
15026 : 37389 : case RECORD_TYPE:
15027 : 37389 : last = NULL_TREE;
15028 : 171096 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15029 : 133707 : if (TREE_CODE (x) == FIELD_DECL)
15030 : 133707 : last = x;
15031 : 37389 : if (last == NULL_TREE)
15032 : : return false;
15033 : 37382 : if (TREE_CODE (TREE_TYPE (last)) == ARRAY_TYPE
15034 : 473 : && TYPE_SIZE (TREE_TYPE (last)) == NULL_TREE
15035 : 239 : && TYPE_DOMAIN (TREE_TYPE (last)) != NULL_TREE
15036 : 37621 : && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (last))) == NULL_TREE)
15037 : : return true;
15038 : : return false;
15039 : 616 : case UNION_TYPE:
15040 : 1782 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15041 : : {
15042 : 1208 : if (TREE_CODE (x) == FIELD_DECL
15043 : 1208 : && flexible_array_type_p (TREE_TYPE (x)))
15044 : : return true;
15045 : : }
15046 : : return false;
15047 : : default:
15048 : : return false;
15049 : : }
15050 : : }
15051 : :
15052 : : /* Like int_size_in_bytes, but handle empty records specially. */
15053 : :
15054 : : HOST_WIDE_INT
15055 : 371608 : arg_int_size_in_bytes (const_tree type)
15056 : : {
15057 : 371608 : return TYPE_EMPTY_P (type) ? 0 : int_size_in_bytes (type);
15058 : : }
15059 : :
15060 : : /* Like size_in_bytes, but handle empty records specially. */
15061 : :
15062 : : tree
15063 : 5618039 : arg_size_in_bytes (const_tree type)
15064 : : {
15065 : 5618039 : return TYPE_EMPTY_P (type) ? size_zero_node : size_in_bytes (type);
15066 : : }
15067 : :
15068 : : /* Return true if an expression with CODE has to have the same result type as
15069 : : its first operand. */
15070 : :
15071 : : bool
15072 : 0 : expr_type_first_operand_type_p (tree_code code)
15073 : : {
15074 : 0 : switch (code)
15075 : : {
15076 : : case NEGATE_EXPR:
15077 : : case ABS_EXPR:
15078 : : case BIT_NOT_EXPR:
15079 : : case PAREN_EXPR:
15080 : : case CONJ_EXPR:
15081 : :
15082 : : case PLUS_EXPR:
15083 : : case MINUS_EXPR:
15084 : : case MULT_EXPR:
15085 : : case TRUNC_DIV_EXPR:
15086 : : case CEIL_DIV_EXPR:
15087 : : case FLOOR_DIV_EXPR:
15088 : : case ROUND_DIV_EXPR:
15089 : : case TRUNC_MOD_EXPR:
15090 : : case CEIL_MOD_EXPR:
15091 : : case FLOOR_MOD_EXPR:
15092 : : case ROUND_MOD_EXPR:
15093 : : case RDIV_EXPR:
15094 : : case EXACT_DIV_EXPR:
15095 : : case MIN_EXPR:
15096 : : case MAX_EXPR:
15097 : : case BIT_IOR_EXPR:
15098 : : case BIT_XOR_EXPR:
15099 : : case BIT_AND_EXPR:
15100 : :
15101 : : case LSHIFT_EXPR:
15102 : : case RSHIFT_EXPR:
15103 : : case LROTATE_EXPR:
15104 : : case RROTATE_EXPR:
15105 : : return true;
15106 : :
15107 : 0 : default:
15108 : 0 : return false;
15109 : : }
15110 : : }
15111 : :
15112 : : /* Return a typenode for the "standard" C type with a given name. */
15113 : : tree
15114 : 889358 : get_typenode_from_name (const char *name)
15115 : : {
15116 : 889358 : if (name == NULL || *name == '\0')
15117 : : return NULL_TREE;
15118 : :
15119 : 889358 : if (strcmp (name, "char") == 0)
15120 : 0 : return char_type_node;
15121 : 889358 : if (strcmp (name, "unsigned char") == 0)
15122 : 91815 : return unsigned_char_type_node;
15123 : 797543 : if (strcmp (name, "signed char") == 0)
15124 : 91815 : return signed_char_type_node;
15125 : :
15126 : 705728 : if (strcmp (name, "short int") == 0)
15127 : 62723 : return short_integer_type_node;
15128 : 643005 : if (strcmp (name, "short unsigned int") == 0)
15129 : 61210 : return short_unsigned_type_node;
15130 : :
15131 : 581795 : if (strcmp (name, "int") == 0)
15132 : 63545 : return integer_type_node;
15133 : 518250 : if (strcmp (name, "unsigned int") == 0)
15134 : 62024 : return unsigned_type_node;
15135 : :
15136 : 456226 : if (strcmp (name, "long int") == 0)
15137 : 271782 : return long_integer_type_node;
15138 : 184444 : if (strcmp (name, "long unsigned int") == 0)
15139 : 181188 : return long_unsigned_type_node;
15140 : :
15141 : 3256 : if (strcmp (name, "long long int") == 0)
15142 : 1628 : return long_long_integer_type_node;
15143 : 1628 : if (strcmp (name, "long long unsigned int") == 0)
15144 : 1628 : return long_long_unsigned_type_node;
15145 : :
15146 : 0 : gcc_unreachable ();
15147 : : }
15148 : :
15149 : : /* List of pointer types used to declare builtins before we have seen their
15150 : : real declaration.
15151 : :
15152 : : Keep the size up to date in tree.h ! */
15153 : : const builtin_structptr_type builtin_structptr_types[6] =
15154 : : {
15155 : : { fileptr_type_node, ptr_type_node, "FILE" },
15156 : : { const_tm_ptr_type_node, const_ptr_type_node, "tm" },
15157 : : { fenv_t_ptr_type_node, ptr_type_node, "fenv_t" },
15158 : : { const_fenv_t_ptr_type_node, const_ptr_type_node, "fenv_t" },
15159 : : { fexcept_t_ptr_type_node, ptr_type_node, "fexcept_t" },
15160 : : { const_fexcept_t_ptr_type_node, const_ptr_type_node, "fexcept_t" }
15161 : : };
15162 : :
15163 : : /* Return the maximum object size. */
15164 : :
15165 : : tree
15166 : 7089706 : max_object_size (void)
15167 : : {
15168 : : /* To do: Make this a configurable parameter. */
15169 : 7089706 : return TYPE_MAX_VALUE (ptrdiff_type_node);
15170 : : }
15171 : :
15172 : : /* A wrapper around TARGET_VERIFY_TYPE_CONTEXT that makes the silent_p
15173 : : parameter default to false and that weeds out error_mark_node. */
15174 : :
15175 : : bool
15176 : 110182400 : verify_type_context (location_t loc, type_context_kind context,
15177 : : const_tree type, bool silent_p)
15178 : : {
15179 : 110182400 : if (type == error_mark_node)
15180 : : return true;
15181 : :
15182 : 110182308 : gcc_assert (TYPE_P (type));
15183 : 110182308 : return (!targetm.verify_type_context
15184 : 110182308 : || targetm.verify_type_context (loc, context, type, silent_p));
15185 : : }
15186 : :
15187 : : /* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and
15188 : : delete operators. Return false if they may or may not name such
15189 : : a pair and, when nonnull, set *PCERTAIN to true if they certainly
15190 : : do not. */
15191 : :
15192 : : bool
15193 : 59257 : valid_new_delete_pair_p (tree new_asm, tree delete_asm,
15194 : : bool *pcertain /* = NULL */)
15195 : : {
15196 : 59257 : bool certain;
15197 : 59257 : if (!pcertain)
15198 : 47879 : pcertain = &certain;
15199 : :
15200 : 59257 : const char *new_name = IDENTIFIER_POINTER (new_asm);
15201 : 59257 : const char *delete_name = IDENTIFIER_POINTER (delete_asm);
15202 : 59257 : unsigned int new_len = IDENTIFIER_LENGTH (new_asm);
15203 : 59257 : unsigned int delete_len = IDENTIFIER_LENGTH (delete_asm);
15204 : :
15205 : : /* The following failures are due to invalid names so they're not
15206 : : considered certain mismatches. */
15207 : 59257 : *pcertain = false;
15208 : :
15209 : 59257 : if (new_len < 5 || delete_len < 6)
15210 : : return false;
15211 : 59257 : if (new_name[0] == '_')
15212 : 59191 : ++new_name, --new_len;
15213 : 59257 : if (new_name[0] == '_')
15214 : 0 : ++new_name, --new_len;
15215 : 59257 : if (delete_name[0] == '_')
15216 : 59257 : ++delete_name, --delete_len;
15217 : 59257 : if (delete_name[0] == '_')
15218 : 0 : ++delete_name, --delete_len;
15219 : 59257 : if (new_len < 4 || delete_len < 5)
15220 : : return false;
15221 : :
15222 : : /* The following failures are due to names of user-defined operators
15223 : : so they're also not considered certain mismatches. */
15224 : :
15225 : : /* *_len is now just the length after initial underscores. */
15226 : 59257 : if (new_name[0] != 'Z' || new_name[1] != 'n')
15227 : : return false;
15228 : 58613 : if (delete_name[0] != 'Z' || delete_name[1] != 'd')
15229 : : return false;
15230 : :
15231 : : /* The following failures are certain mismatches. */
15232 : 58545 : *pcertain = true;
15233 : :
15234 : : /* _Znw must match _Zdl, _Zna must match _Zda. */
15235 : 58545 : if ((new_name[2] != 'w' || delete_name[2] != 'l')
15236 : 7343 : && (new_name[2] != 'a' || delete_name[2] != 'a'))
15237 : : return false;
15238 : : /* 'j', 'm' and 'y' correspond to size_t. */
15239 : 58431 : if (new_name[3] != 'j' && new_name[3] != 'm' && new_name[3] != 'y')
15240 : : return false;
15241 : 58431 : if (delete_name[3] != 'P' || delete_name[4] != 'v')
15242 : : return false;
15243 : 58431 : if (new_len == 4
15244 : 411 : || (new_len == 18 && !memcmp (new_name + 4, "RKSt9nothrow_t", 14)))
15245 : : {
15246 : : /* _ZnXY or _ZnXYRKSt9nothrow_t matches
15247 : : _ZdXPv, _ZdXPvY and _ZdXPvRKSt9nothrow_t. */
15248 : 58174 : if (delete_len == 5)
15249 : : return true;
15250 : 49027 : if (delete_len == 6 && delete_name[5] == new_name[3])
15251 : : return true;
15252 : 33 : if (delete_len == 19 && !memcmp (delete_name + 5, "RKSt9nothrow_t", 14))
15253 : : return true;
15254 : : }
15255 : 257 : else if ((new_len == 19 && !memcmp (new_name + 4, "St11align_val_t", 15))
15256 : 42 : || (new_len == 33
15257 : 10 : && !memcmp (new_name + 4, "St11align_val_tRKSt9nothrow_t", 29)))
15258 : : {
15259 : : /* _ZnXYSt11align_val_t or _ZnXYSt11align_val_tRKSt9nothrow_t matches
15260 : : _ZdXPvSt11align_val_t or _ZdXPvYSt11align_val_t or
15261 : : _ZdXPvSt11align_val_tRKSt9nothrow_t. */
15262 : 225 : if (delete_len == 20 && !memcmp (delete_name + 5, "St11align_val_t", 15))
15263 : : return true;
15264 : 46 : if (delete_len == 21
15265 : 31 : && delete_name[5] == new_name[3]
15266 : 31 : && !memcmp (delete_name + 6, "St11align_val_t", 15))
15267 : : return true;
15268 : 15 : if (delete_len == 34
15269 : 9 : && !memcmp (delete_name + 5, "St11align_val_tRKSt9nothrow_t", 29))
15270 : : return true;
15271 : : }
15272 : :
15273 : : /* The negative result is conservative. */
15274 : 38 : *pcertain = false;
15275 : 38 : return false;
15276 : : }
15277 : :
15278 : : /* Return the zero-based number corresponding to the argument being
15279 : : deallocated if FNDECL is a deallocation function or an out-of-bounds
15280 : : value if it isn't. */
15281 : :
15282 : : unsigned
15283 : 27886059 : fndecl_dealloc_argno (tree fndecl)
15284 : : {
15285 : : /* A call to operator delete isn't recognized as one to a built-in. */
15286 : 27886059 : if (DECL_IS_OPERATOR_DELETE_P (fndecl))
15287 : : {
15288 : 440396 : if (DECL_IS_REPLACEABLE_OPERATOR (fndecl))
15289 : : return 0;
15290 : :
15291 : : /* Avoid placement delete that's not been inlined. */
15292 : 24628 : tree fname = DECL_ASSEMBLER_NAME (fndecl);
15293 : 24628 : if (id_equal (fname, "_ZdlPvS_") // ordinary form
15294 : 24628 : || id_equal (fname, "_ZdaPvS_")) // array form
15295 : : return UINT_MAX;
15296 : : return 0;
15297 : : }
15298 : :
15299 : : /* TODO: Handle user-defined functions with attribute malloc? Handle
15300 : : known non-built-ins like fopen? */
15301 : 27445663 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
15302 : : {
15303 : 7129530 : switch (DECL_FUNCTION_CODE (fndecl))
15304 : : {
15305 : : case BUILT_IN_FREE:
15306 : : case BUILT_IN_REALLOC:
15307 : : case BUILT_IN_GOMP_FREE:
15308 : : case BUILT_IN_GOMP_REALLOC:
15309 : : return 0;
15310 : : default:
15311 : : break;
15312 : : }
15313 : : return UINT_MAX;
15314 : : }
15315 : :
15316 : 20316133 : tree attrs = DECL_ATTRIBUTES (fndecl);
15317 : 20316133 : if (!attrs)
15318 : : return UINT_MAX;
15319 : :
15320 : 0 : for (tree atfree = attrs;
15321 : 4586568 : (atfree = lookup_attribute ("*dealloc", atfree));
15322 : 0 : atfree = TREE_CHAIN (atfree))
15323 : : {
15324 : 6045 : tree alloc = TREE_VALUE (atfree);
15325 : 6045 : if (!alloc)
15326 : 0 : continue;
15327 : :
15328 : 6045 : tree pos = TREE_CHAIN (alloc);
15329 : 6045 : if (!pos)
15330 : : return 0;
15331 : :
15332 : 3525 : pos = TREE_VALUE (pos);
15333 : 3525 : return TREE_INT_CST_LOW (pos) - 1;
15334 : : }
15335 : :
15336 : : return UINT_MAX;
15337 : : }
15338 : :
15339 : : /* If EXPR refers to a character array or pointer declared attribute
15340 : : nonstring, return a decl for that array or pointer and set *REF
15341 : : to the referenced enclosing object or pointer. Otherwise return
15342 : : null. */
15343 : :
15344 : : tree
15345 : 1394710 : get_attr_nonstring_decl (tree expr, tree *ref)
15346 : : {
15347 : 1400439 : tree decl = expr;
15348 : 1400439 : tree var = NULL_TREE;
15349 : 1400439 : if (TREE_CODE (decl) == SSA_NAME)
15350 : : {
15351 : 835454 : gimple *def = SSA_NAME_DEF_STMT (decl);
15352 : :
15353 : 835454 : if (is_gimple_assign (def))
15354 : : {
15355 : 44753 : tree_code code = gimple_assign_rhs_code (def);
15356 : 44753 : if (code == ADDR_EXPR
15357 : 44753 : || code == COMPONENT_REF
15358 : 30483 : || code == VAR_DECL)
15359 : 19104 : decl = gimple_assign_rhs1 (def);
15360 : : }
15361 : : else
15362 : 790701 : var = SSA_NAME_VAR (decl);
15363 : : }
15364 : :
15365 : 1400439 : if (TREE_CODE (decl) == ADDR_EXPR)
15366 : 26994 : decl = TREE_OPERAND (decl, 0);
15367 : :
15368 : : /* To simplify calling code, store the referenced DECL regardless of
15369 : : the attribute determined below, but avoid storing the SSA_NAME_VAR
15370 : : obtained above (it's not useful for dataflow purposes). */
15371 : 1400439 : if (ref)
15372 : 5444 : *ref = decl;
15373 : :
15374 : : /* Use the SSA_NAME_VAR that was determined above to see if it's
15375 : : declared nonstring. Otherwise drill down into the referenced
15376 : : DECL. */
15377 : 1400439 : if (var)
15378 : : decl = var;
15379 : : else
15380 : : {
15381 : 635553 : while (TREE_CODE (decl) == ARRAY_REF)
15382 : 18762 : decl = TREE_OPERAND (decl, 0);
15383 : 616791 : if (TREE_CODE (decl) == COMPONENT_REF)
15384 : 16164 : decl = TREE_OPERAND (decl, 1);
15385 : 600627 : else if (TREE_CODE (decl) == MEM_REF)
15386 : 5729 : return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref);
15387 : : }
15388 : :
15389 : 1394710 : if (DECL_P (decl) && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl)))
15390 : : return decl;
15391 : :
15392 : : return NULL_TREE;
15393 : : }
15394 : :
15395 : : /* Return length of attribute names string,
15396 : : if arglist chain > 1, -1 otherwise. */
15397 : :
15398 : : int
15399 : 202 : get_target_clone_attr_len (tree arglist)
15400 : : {
15401 : 202 : tree arg;
15402 : 202 : int str_len_sum = 0;
15403 : 202 : int argnum = 0;
15404 : :
15405 : 740 : for (arg = arglist; arg; arg = TREE_CHAIN (arg))
15406 : : {
15407 : 538 : const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
15408 : 538 : size_t len = strlen (str);
15409 : 538 : str_len_sum += len + 1;
15410 : 538 : for (const char *p = strchr (str, TARGET_CLONES_ATTR_SEPARATOR);
15411 : 566 : p;
15412 : 28 : p = strchr (p + 1, TARGET_CLONES_ATTR_SEPARATOR))
15413 : 28 : argnum++;
15414 : 538 : argnum++;
15415 : : }
15416 : 202 : if (argnum <= 1)
15417 : 1 : return -1;
15418 : : return str_len_sum;
15419 : : }
15420 : :
15421 : : void
15422 : 257941 : tree_cc_finalize (void)
15423 : : {
15424 : 257941 : clear_nonstandard_integer_type_cache ();
15425 : 257941 : vec_free (bitint_type_cache);
15426 : 257941 : }
15427 : :
15428 : : void
15429 : 147 : gt_ggc_mx (tree_raw_data *x)
15430 : : {
15431 : 147 : gt_ggc_m_9tree_node (x->typed.type);
15432 : 147 : gt_ggc_m_9tree_node (x->owner);
15433 : 147 : }
15434 : :
15435 : : void
15436 : 12 : gt_pch_nx (tree_raw_data *x)
15437 : : {
15438 : 12 : gt_pch_n_9tree_node (x->typed.type);
15439 : 12 : gt_pch_n_9tree_node (x->owner);
15440 : 12 : }
15441 : :
15442 : : /* For PCH we guarantee that RAW_DATA_CST's RAW_DATA_OWNER is a STRING_CST and
15443 : : RAW_DATA_POINTER points into it. We don't want to save/restore
15444 : : RAW_DATA_POINTER on its own but want to restore it pointing at the same
15445 : : offset of the STRING_CST as before. */
15446 : :
15447 : : void
15448 : 12 : gt_pch_nx (tree_raw_data *x, gt_pointer_operator op, void *cookie)
15449 : : {
15450 : 12 : op (&x->typed.type, NULL, cookie);
15451 : 12 : gcc_checking_assert (x->owner
15452 : : && TREE_CODE (x->owner) == STRING_CST
15453 : : && x->str >= TREE_STRING_POINTER (x->owner)
15454 : : && (x->str + x->length
15455 : : <= (TREE_STRING_POINTER (x->owner)
15456 : : + TREE_STRING_LENGTH (x->owner))));
15457 : 12 : ptrdiff_t off = x->str - (const char *) (x->owner);
15458 : 12 : tree owner = x->owner;
15459 : 12 : op (&x->owner, NULL, cookie);
15460 : 12 : x->owner = owner;
15461 : : /* The above op call relocates x->owner and remembers the address
15462 : : for relocation e.g. if the compiler is position independent.
15463 : : We then restore x->owner back to its previous value and call
15464 : : op again, for x->owner itself this just repeats (uselessly) what
15465 : : the first call did, but as the second argument is now non-NULL
15466 : : and different, it also arranges for &x->str to be noted for the
15467 : : PIE relocation. */
15468 : 12 : op (&x->owner, &x->str, cookie);
15469 : 12 : x->str = (const char *) (x->owner) + off;
15470 : 12 : }
15471 : :
15472 : : #if CHECKING_P
15473 : :
15474 : : namespace selftest {
15475 : :
15476 : : /* Selftests for tree. */
15477 : :
15478 : : /* Verify that integer constants are sane. */
15479 : :
15480 : : static void
15481 : 4 : test_integer_constants ()
15482 : : {
15483 : 4 : ASSERT_TRUE (integer_type_node != NULL);
15484 : 4 : ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
15485 : :
15486 : 4 : tree type = integer_type_node;
15487 : :
15488 : 4 : tree zero = build_zero_cst (type);
15489 : 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
15490 : 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15491 : :
15492 : 4 : tree one = build_int_cst (type, 1);
15493 : 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
15494 : 4 : ASSERT_EQ (type, TREE_TYPE (zero));
15495 : 4 : }
15496 : :
15497 : : /* Verify identifiers. */
15498 : :
15499 : : static void
15500 : 4 : test_identifiers ()
15501 : : {
15502 : 4 : tree identifier = get_identifier ("foo");
15503 : 4 : ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
15504 : 4 : ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
15505 : 4 : }
15506 : :
15507 : : /* Verify LABEL_DECL. */
15508 : :
15509 : : static void
15510 : 4 : test_labels ()
15511 : : {
15512 : 4 : tree identifier = get_identifier ("err");
15513 : 4 : tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
15514 : : identifier, void_type_node);
15515 : 4 : ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
15516 : 4 : ASSERT_FALSE (FORCED_LABEL (label_decl));
15517 : 4 : }
15518 : :
15519 : : /* Return a new VECTOR_CST node whose type is TYPE and whose values
15520 : : are given by VALS. */
15521 : :
15522 : : static tree
15523 : 40 : build_vector (tree type, const vec<tree> &vals MEM_STAT_DECL)
15524 : : {
15525 : 80 : gcc_assert (known_eq (vals.length (), TYPE_VECTOR_SUBPARTS (type)));
15526 : 40 : tree_vector_builder builder (type, vals.length (), 1);
15527 : 40 : builder.splice (vals);
15528 : 40 : return builder.build ();
15529 : 40 : }
15530 : :
15531 : : /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED. */
15532 : :
15533 : : static void
15534 : 40 : check_vector_cst (const vec<tree> &expected, tree actual)
15535 : : {
15536 : 80 : ASSERT_KNOWN_EQ (expected.length (),
15537 : : TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual)));
15538 : 360 : for (unsigned int i = 0; i < expected.length (); ++i)
15539 : 320 : ASSERT_EQ (wi::to_wide (expected[i]),
15540 : : wi::to_wide (vector_cst_elt (actual, i)));
15541 : 40 : }
15542 : :
15543 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
15544 : : and that its elements match EXPECTED. */
15545 : :
15546 : : static void
15547 : 8 : check_vector_cst_duplicate (const vec<tree> &expected, tree actual,
15548 : : unsigned int npatterns)
15549 : : {
15550 : 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15551 : 8 : ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual));
15552 : 8 : ASSERT_EQ (npatterns, vector_cst_encoded_nelts (actual));
15553 : 8 : ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual));
15554 : 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15555 : 8 : check_vector_cst (expected, actual);
15556 : 8 : }
15557 : :
15558 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
15559 : : and NPATTERNS background elements, and that its elements match
15560 : : EXPECTED. */
15561 : :
15562 : : static void
15563 : 8 : check_vector_cst_fill (const vec<tree> &expected, tree actual,
15564 : : unsigned int npatterns)
15565 : : {
15566 : 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15567 : 8 : ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual));
15568 : 8 : ASSERT_EQ (2 * npatterns, vector_cst_encoded_nelts (actual));
15569 : 8 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15570 : 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
15571 : 8 : check_vector_cst (expected, actual);
15572 : 8 : }
15573 : :
15574 : : /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
15575 : : and that its elements match EXPECTED. */
15576 : :
15577 : : static void
15578 : 24 : check_vector_cst_stepped (const vec<tree> &expected, tree actual,
15579 : : unsigned int npatterns)
15580 : : {
15581 : 24 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
15582 : 24 : ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual));
15583 : 24 : ASSERT_EQ (3 * npatterns, vector_cst_encoded_nelts (actual));
15584 : 24 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
15585 : 24 : ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual));
15586 : 24 : check_vector_cst (expected, actual);
15587 : 24 : }
15588 : :
15589 : : /* Test the creation of VECTOR_CSTs. */
15590 : :
15591 : : static void
15592 : 4 : test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO)
15593 : : {
15594 : 4 : auto_vec<tree, 8> elements (8);
15595 : 4 : elements.quick_grow (8);
15596 : 4 : tree element_type = build_nonstandard_integer_type (16, true);
15597 : 4 : tree vector_type = build_vector_type (element_type, 8);
15598 : :
15599 : : /* Test a simple linear series with a base of 0 and a step of 1:
15600 : : { 0, 1, 2, 3, 4, 5, 6, 7 }. */
15601 : 36 : for (unsigned int i = 0; i < 8; ++i)
15602 : 32 : elements[i] = build_int_cst (element_type, i);
15603 : 4 : tree vector = build_vector (vector_type, elements PASS_MEM_STAT);
15604 : 4 : check_vector_cst_stepped (elements, vector, 1);
15605 : :
15606 : : /* Try the same with the first element replaced by 100:
15607 : : { 100, 1, 2, 3, 4, 5, 6, 7 }. */
15608 : 4 : elements[0] = build_int_cst (element_type, 100);
15609 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15610 : 4 : check_vector_cst_stepped (elements, vector, 1);
15611 : :
15612 : : /* Try a series that wraps around.
15613 : : { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }. */
15614 : 32 : for (unsigned int i = 1; i < 8; ++i)
15615 : 28 : elements[i] = build_int_cst (element_type, (65530 + i) & 0xffff);
15616 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15617 : 4 : check_vector_cst_stepped (elements, vector, 1);
15618 : :
15619 : : /* Try a downward series:
15620 : : { 100, 79, 78, 77, 76, 75, 75, 73 }. */
15621 : 32 : for (unsigned int i = 1; i < 8; ++i)
15622 : 28 : elements[i] = build_int_cst (element_type, 80 - i);
15623 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15624 : 4 : check_vector_cst_stepped (elements, vector, 1);
15625 : :
15626 : : /* Try two interleaved series with different bases and steps:
15627 : : { 100, 53, 66, 206, 62, 212, 58, 218 }. */
15628 : 4 : elements[1] = build_int_cst (element_type, 53);
15629 : 16 : for (unsigned int i = 2; i < 8; i += 2)
15630 : : {
15631 : 12 : elements[i] = build_int_cst (element_type, 70 - i * 2);
15632 : 12 : elements[i + 1] = build_int_cst (element_type, 200 + i * 3);
15633 : : }
15634 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15635 : 4 : check_vector_cst_stepped (elements, vector, 2);
15636 : :
15637 : : /* Try a duplicated value:
15638 : : { 100, 100, 100, 100, 100, 100, 100, 100 }. */
15639 : 32 : for (unsigned int i = 1; i < 8; ++i)
15640 : 28 : elements[i] = elements[0];
15641 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15642 : 4 : check_vector_cst_duplicate (elements, vector, 1);
15643 : :
15644 : : /* Try an interleaved duplicated value:
15645 : : { 100, 55, 100, 55, 100, 55, 100, 55 }. */
15646 : 4 : elements[1] = build_int_cst (element_type, 55);
15647 : 28 : for (unsigned int i = 2; i < 8; ++i)
15648 : 24 : elements[i] = elements[i - 2];
15649 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15650 : 4 : check_vector_cst_duplicate (elements, vector, 2);
15651 : :
15652 : : /* Try a duplicated value with 2 exceptions
15653 : : { 41, 97, 100, 55, 100, 55, 100, 55 }. */
15654 : 4 : elements[0] = build_int_cst (element_type, 41);
15655 : 4 : elements[1] = build_int_cst (element_type, 97);
15656 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15657 : 4 : check_vector_cst_fill (elements, vector, 2);
15658 : :
15659 : : /* Try with and without a step
15660 : : { 41, 97, 100, 21, 100, 35, 100, 49 }. */
15661 : 16 : for (unsigned int i = 3; i < 8; i += 2)
15662 : 12 : elements[i] = build_int_cst (element_type, i * 7);
15663 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15664 : 4 : check_vector_cst_stepped (elements, vector, 2);
15665 : :
15666 : : /* Try a fully-general constant:
15667 : : { 41, 97, 100, 21, 100, 9990, 100, 49 }. */
15668 : 4 : elements[5] = build_int_cst (element_type, 9990);
15669 : 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
15670 : 4 : check_vector_cst_fill (elements, vector, 4);
15671 : 4 : }
15672 : :
15673 : : /* Verify that STRIP_NOPS (NODE) is EXPECTED.
15674 : : Helper function for test_location_wrappers, to deal with STRIP_NOPS
15675 : : modifying its argument in-place. */
15676 : :
15677 : : static void
15678 : 12 : check_strip_nops (tree node, tree expected)
15679 : : {
15680 : 12 : STRIP_NOPS (node);
15681 : 12 : ASSERT_EQ (expected, node);
15682 : 12 : }
15683 : :
15684 : : /* Verify location wrappers. */
15685 : :
15686 : : static void
15687 : 4 : test_location_wrappers ()
15688 : : {
15689 : 4 : location_t loc = BUILTINS_LOCATION;
15690 : :
15691 : 4 : ASSERT_EQ (NULL_TREE, maybe_wrap_with_location (NULL_TREE, loc));
15692 : :
15693 : : /* Wrapping a constant. */
15694 : 4 : tree int_cst = build_int_cst (integer_type_node, 42);
15695 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst));
15696 : 4 : ASSERT_FALSE (location_wrapper_p (int_cst));
15697 : :
15698 : 4 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
15699 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
15700 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_cst));
15701 : 4 : ASSERT_EQ (int_cst, tree_strip_any_location_wrapper (wrapped_int_cst));
15702 : :
15703 : : /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION. */
15704 : 4 : ASSERT_EQ (int_cst, maybe_wrap_with_location (int_cst, UNKNOWN_LOCATION));
15705 : :
15706 : : /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P. */
15707 : 4 : tree cast = build1 (NOP_EXPR, char_type_node, int_cst);
15708 : 4 : ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast));
15709 : 4 : ASSERT_EQ (cast, maybe_wrap_with_location (cast, loc));
15710 : :
15711 : : /* Wrapping a STRING_CST. */
15712 : 4 : tree string_cst = build_string (4, "foo");
15713 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst));
15714 : 4 : ASSERT_FALSE (location_wrapper_p (string_cst));
15715 : :
15716 : 4 : tree wrapped_string_cst = maybe_wrap_with_location (string_cst, loc);
15717 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_string_cst));
15718 : 4 : ASSERT_EQ (VIEW_CONVERT_EXPR, TREE_CODE (wrapped_string_cst));
15719 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_string_cst));
15720 : 4 : ASSERT_EQ (string_cst, tree_strip_any_location_wrapper (wrapped_string_cst));
15721 : :
15722 : :
15723 : : /* Wrapping a variable. */
15724 : 4 : tree int_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
15725 : : get_identifier ("some_int_var"),
15726 : : integer_type_node);
15727 : 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var));
15728 : 4 : ASSERT_FALSE (location_wrapper_p (int_var));
15729 : :
15730 : 4 : tree wrapped_int_var = maybe_wrap_with_location (int_var, loc);
15731 : 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_var));
15732 : 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_var));
15733 : 4 : ASSERT_EQ (int_var, tree_strip_any_location_wrapper (wrapped_int_var));
15734 : :
15735 : : /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
15736 : : wrapper. */
15737 : 4 : tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
15738 : 4 : ASSERT_FALSE (location_wrapper_p (r_cast));
15739 : 4 : ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
15740 : :
15741 : : /* Verify that STRIP_NOPS removes wrappers. */
15742 : 4 : check_strip_nops (wrapped_int_cst, int_cst);
15743 : 4 : check_strip_nops (wrapped_string_cst, string_cst);
15744 : 4 : check_strip_nops (wrapped_int_var, int_var);
15745 : 4 : }
15746 : :
15747 : : /* Test various tree predicates. Verify that location wrappers don't
15748 : : affect the results. */
15749 : :
15750 : : static void
15751 : 4 : test_predicates ()
15752 : : {
15753 : : /* Build various constants and wrappers around them. */
15754 : :
15755 : 4 : location_t loc = BUILTINS_LOCATION;
15756 : :
15757 : 4 : tree i_0 = build_int_cst (integer_type_node, 0);
15758 : 4 : tree wr_i_0 = maybe_wrap_with_location (i_0, loc);
15759 : :
15760 : 4 : tree i_1 = build_int_cst (integer_type_node, 1);
15761 : 4 : tree wr_i_1 = maybe_wrap_with_location (i_1, loc);
15762 : :
15763 : 4 : tree i_m1 = build_int_cst (integer_type_node, -1);
15764 : 4 : tree wr_i_m1 = maybe_wrap_with_location (i_m1, loc);
15765 : :
15766 : 4 : tree f_0 = build_real_from_int_cst (float_type_node, i_0);
15767 : 4 : tree wr_f_0 = maybe_wrap_with_location (f_0, loc);
15768 : 4 : tree f_1 = build_real_from_int_cst (float_type_node, i_1);
15769 : 4 : tree wr_f_1 = maybe_wrap_with_location (f_1, loc);
15770 : 4 : tree f_m1 = build_real_from_int_cst (float_type_node, i_m1);
15771 : 4 : tree wr_f_m1 = maybe_wrap_with_location (f_m1, loc);
15772 : :
15773 : 4 : tree c_i_0 = build_complex (NULL_TREE, i_0, i_0);
15774 : 4 : tree c_i_1 = build_complex (NULL_TREE, i_1, i_0);
15775 : 4 : tree c_i_m1 = build_complex (NULL_TREE, i_m1, i_0);
15776 : :
15777 : 4 : tree c_f_0 = build_complex (NULL_TREE, f_0, f_0);
15778 : 4 : tree c_f_1 = build_complex (NULL_TREE, f_1, f_0);
15779 : 4 : tree c_f_m1 = build_complex (NULL_TREE, f_m1, f_0);
15780 : :
15781 : : /* TODO: vector constants. */
15782 : :
15783 : : /* Test integer_onep. */
15784 : 4 : ASSERT_FALSE (integer_onep (i_0));
15785 : 4 : ASSERT_FALSE (integer_onep (wr_i_0));
15786 : 4 : ASSERT_TRUE (integer_onep (i_1));
15787 : 4 : ASSERT_TRUE (integer_onep (wr_i_1));
15788 : 4 : ASSERT_FALSE (integer_onep (i_m1));
15789 : 4 : ASSERT_FALSE (integer_onep (wr_i_m1));
15790 : 4 : ASSERT_FALSE (integer_onep (f_0));
15791 : 4 : ASSERT_FALSE (integer_onep (wr_f_0));
15792 : 4 : ASSERT_FALSE (integer_onep (f_1));
15793 : 4 : ASSERT_FALSE (integer_onep (wr_f_1));
15794 : 4 : ASSERT_FALSE (integer_onep (f_m1));
15795 : 4 : ASSERT_FALSE (integer_onep (wr_f_m1));
15796 : 4 : ASSERT_FALSE (integer_onep (c_i_0));
15797 : 4 : ASSERT_TRUE (integer_onep (c_i_1));
15798 : 4 : ASSERT_FALSE (integer_onep (c_i_m1));
15799 : 4 : ASSERT_FALSE (integer_onep (c_f_0));
15800 : 4 : ASSERT_FALSE (integer_onep (c_f_1));
15801 : 4 : ASSERT_FALSE (integer_onep (c_f_m1));
15802 : :
15803 : : /* Test integer_zerop. */
15804 : 4 : ASSERT_TRUE (integer_zerop (i_0));
15805 : 4 : ASSERT_TRUE (integer_zerop (wr_i_0));
15806 : 4 : ASSERT_FALSE (integer_zerop (i_1));
15807 : 4 : ASSERT_FALSE (integer_zerop (wr_i_1));
15808 : 4 : ASSERT_FALSE (integer_zerop (i_m1));
15809 : 4 : ASSERT_FALSE (integer_zerop (wr_i_m1));
15810 : 4 : ASSERT_FALSE (integer_zerop (f_0));
15811 : 4 : ASSERT_FALSE (integer_zerop (wr_f_0));
15812 : 4 : ASSERT_FALSE (integer_zerop (f_1));
15813 : 4 : ASSERT_FALSE (integer_zerop (wr_f_1));
15814 : 4 : ASSERT_FALSE (integer_zerop (f_m1));
15815 : 4 : ASSERT_FALSE (integer_zerop (wr_f_m1));
15816 : 4 : ASSERT_TRUE (integer_zerop (c_i_0));
15817 : 4 : ASSERT_FALSE (integer_zerop (c_i_1));
15818 : 4 : ASSERT_FALSE (integer_zerop (c_i_m1));
15819 : 4 : ASSERT_FALSE (integer_zerop (c_f_0));
15820 : 4 : ASSERT_FALSE (integer_zerop (c_f_1));
15821 : 4 : ASSERT_FALSE (integer_zerop (c_f_m1));
15822 : :
15823 : : /* Test integer_all_onesp. */
15824 : 4 : ASSERT_FALSE (integer_all_onesp (i_0));
15825 : 4 : ASSERT_FALSE (integer_all_onesp (wr_i_0));
15826 : 4 : ASSERT_FALSE (integer_all_onesp (i_1));
15827 : 4 : ASSERT_FALSE (integer_all_onesp (wr_i_1));
15828 : 4 : ASSERT_TRUE (integer_all_onesp (i_m1));
15829 : 4 : ASSERT_TRUE (integer_all_onesp (wr_i_m1));
15830 : 4 : ASSERT_FALSE (integer_all_onesp (f_0));
15831 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_0));
15832 : 4 : ASSERT_FALSE (integer_all_onesp (f_1));
15833 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_1));
15834 : 4 : ASSERT_FALSE (integer_all_onesp (f_m1));
15835 : 4 : ASSERT_FALSE (integer_all_onesp (wr_f_m1));
15836 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_0));
15837 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_1));
15838 : 4 : ASSERT_FALSE (integer_all_onesp (c_i_m1));
15839 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_0));
15840 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_1));
15841 : 4 : ASSERT_FALSE (integer_all_onesp (c_f_m1));
15842 : :
15843 : : /* Test integer_minus_onep. */
15844 : 4 : ASSERT_FALSE (integer_minus_onep (i_0));
15845 : 4 : ASSERT_FALSE (integer_minus_onep (wr_i_0));
15846 : 4 : ASSERT_FALSE (integer_minus_onep (i_1));
15847 : 4 : ASSERT_FALSE (integer_minus_onep (wr_i_1));
15848 : 4 : ASSERT_TRUE (integer_minus_onep (i_m1));
15849 : 4 : ASSERT_TRUE (integer_minus_onep (wr_i_m1));
15850 : 4 : ASSERT_FALSE (integer_minus_onep (f_0));
15851 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_0));
15852 : 4 : ASSERT_FALSE (integer_minus_onep (f_1));
15853 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_1));
15854 : 4 : ASSERT_FALSE (integer_minus_onep (f_m1));
15855 : 4 : ASSERT_FALSE (integer_minus_onep (wr_f_m1));
15856 : 4 : ASSERT_FALSE (integer_minus_onep (c_i_0));
15857 : 4 : ASSERT_FALSE (integer_minus_onep (c_i_1));
15858 : 4 : ASSERT_TRUE (integer_minus_onep (c_i_m1));
15859 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_0));
15860 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_1));
15861 : 4 : ASSERT_FALSE (integer_minus_onep (c_f_m1));
15862 : :
15863 : : /* Test integer_each_onep. */
15864 : 4 : ASSERT_FALSE (integer_each_onep (i_0));
15865 : 4 : ASSERT_FALSE (integer_each_onep (wr_i_0));
15866 : 4 : ASSERT_TRUE (integer_each_onep (i_1));
15867 : 4 : ASSERT_TRUE (integer_each_onep (wr_i_1));
15868 : 4 : ASSERT_FALSE (integer_each_onep (i_m1));
15869 : 4 : ASSERT_FALSE (integer_each_onep (wr_i_m1));
15870 : 4 : ASSERT_FALSE (integer_each_onep (f_0));
15871 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_0));
15872 : 4 : ASSERT_FALSE (integer_each_onep (f_1));
15873 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_1));
15874 : 4 : ASSERT_FALSE (integer_each_onep (f_m1));
15875 : 4 : ASSERT_FALSE (integer_each_onep (wr_f_m1));
15876 : 4 : ASSERT_FALSE (integer_each_onep (c_i_0));
15877 : 4 : ASSERT_FALSE (integer_each_onep (c_i_1));
15878 : 4 : ASSERT_FALSE (integer_each_onep (c_i_m1));
15879 : 4 : ASSERT_FALSE (integer_each_onep (c_f_0));
15880 : 4 : ASSERT_FALSE (integer_each_onep (c_f_1));
15881 : 4 : ASSERT_FALSE (integer_each_onep (c_f_m1));
15882 : :
15883 : : /* Test integer_truep. */
15884 : 4 : ASSERT_FALSE (integer_truep (i_0));
15885 : 4 : ASSERT_FALSE (integer_truep (wr_i_0));
15886 : 4 : ASSERT_TRUE (integer_truep (i_1));
15887 : 4 : ASSERT_TRUE (integer_truep (wr_i_1));
15888 : 4 : ASSERT_FALSE (integer_truep (i_m1));
15889 : 4 : ASSERT_FALSE (integer_truep (wr_i_m1));
15890 : 4 : ASSERT_FALSE (integer_truep (f_0));
15891 : 4 : ASSERT_FALSE (integer_truep (wr_f_0));
15892 : 4 : ASSERT_FALSE (integer_truep (f_1));
15893 : 4 : ASSERT_FALSE (integer_truep (wr_f_1));
15894 : 4 : ASSERT_FALSE (integer_truep (f_m1));
15895 : 4 : ASSERT_FALSE (integer_truep (wr_f_m1));
15896 : 4 : ASSERT_FALSE (integer_truep (c_i_0));
15897 : 4 : ASSERT_TRUE (integer_truep (c_i_1));
15898 : 4 : ASSERT_FALSE (integer_truep (c_i_m1));
15899 : 4 : ASSERT_FALSE (integer_truep (c_f_0));
15900 : 4 : ASSERT_FALSE (integer_truep (c_f_1));
15901 : 4 : ASSERT_FALSE (integer_truep (c_f_m1));
15902 : :
15903 : : /* Test integer_nonzerop. */
15904 : 4 : ASSERT_FALSE (integer_nonzerop (i_0));
15905 : 4 : ASSERT_FALSE (integer_nonzerop (wr_i_0));
15906 : 4 : ASSERT_TRUE (integer_nonzerop (i_1));
15907 : 4 : ASSERT_TRUE (integer_nonzerop (wr_i_1));
15908 : 4 : ASSERT_TRUE (integer_nonzerop (i_m1));
15909 : 4 : ASSERT_TRUE (integer_nonzerop (wr_i_m1));
15910 : 4 : ASSERT_FALSE (integer_nonzerop (f_0));
15911 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_0));
15912 : 4 : ASSERT_FALSE (integer_nonzerop (f_1));
15913 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_1));
15914 : 4 : ASSERT_FALSE (integer_nonzerop (f_m1));
15915 : 4 : ASSERT_FALSE (integer_nonzerop (wr_f_m1));
15916 : 4 : ASSERT_FALSE (integer_nonzerop (c_i_0));
15917 : 4 : ASSERT_TRUE (integer_nonzerop (c_i_1));
15918 : 4 : ASSERT_TRUE (integer_nonzerop (c_i_m1));
15919 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_0));
15920 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_1));
15921 : 4 : ASSERT_FALSE (integer_nonzerop (c_f_m1));
15922 : :
15923 : : /* Test real_zerop. */
15924 : 4 : ASSERT_FALSE (real_zerop (i_0));
15925 : 4 : ASSERT_FALSE (real_zerop (wr_i_0));
15926 : 4 : ASSERT_FALSE (real_zerop (i_1));
15927 : 4 : ASSERT_FALSE (real_zerop (wr_i_1));
15928 : 4 : ASSERT_FALSE (real_zerop (i_m1));
15929 : 4 : ASSERT_FALSE (real_zerop (wr_i_m1));
15930 : 4 : ASSERT_TRUE (real_zerop (f_0));
15931 : 4 : ASSERT_TRUE (real_zerop (wr_f_0));
15932 : 4 : ASSERT_FALSE (real_zerop (f_1));
15933 : 4 : ASSERT_FALSE (real_zerop (wr_f_1));
15934 : 4 : ASSERT_FALSE (real_zerop (f_m1));
15935 : 4 : ASSERT_FALSE (real_zerop (wr_f_m1));
15936 : 4 : ASSERT_FALSE (real_zerop (c_i_0));
15937 : 4 : ASSERT_FALSE (real_zerop (c_i_1));
15938 : 4 : ASSERT_FALSE (real_zerop (c_i_m1));
15939 : 4 : ASSERT_TRUE (real_zerop (c_f_0));
15940 : 4 : ASSERT_FALSE (real_zerop (c_f_1));
15941 : 4 : ASSERT_FALSE (real_zerop (c_f_m1));
15942 : :
15943 : : /* Test real_onep. */
15944 : 4 : ASSERT_FALSE (real_onep (i_0));
15945 : 4 : ASSERT_FALSE (real_onep (wr_i_0));
15946 : 4 : ASSERT_FALSE (real_onep (i_1));
15947 : 4 : ASSERT_FALSE (real_onep (wr_i_1));
15948 : 4 : ASSERT_FALSE (real_onep (i_m1));
15949 : 4 : ASSERT_FALSE (real_onep (wr_i_m1));
15950 : 4 : ASSERT_FALSE (real_onep (f_0));
15951 : 4 : ASSERT_FALSE (real_onep (wr_f_0));
15952 : 4 : ASSERT_TRUE (real_onep (f_1));
15953 : 4 : ASSERT_TRUE (real_onep (wr_f_1));
15954 : 4 : ASSERT_FALSE (real_onep (f_m1));
15955 : 4 : ASSERT_FALSE (real_onep (wr_f_m1));
15956 : 4 : ASSERT_FALSE (real_onep (c_i_0));
15957 : 4 : ASSERT_FALSE (real_onep (c_i_1));
15958 : 4 : ASSERT_FALSE (real_onep (c_i_m1));
15959 : 4 : ASSERT_FALSE (real_onep (c_f_0));
15960 : 4 : ASSERT_TRUE (real_onep (c_f_1));
15961 : 4 : ASSERT_FALSE (real_onep (c_f_m1));
15962 : :
15963 : : /* Test real_minus_onep. */
15964 : 4 : ASSERT_FALSE (real_minus_onep (i_0));
15965 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_0));
15966 : 4 : ASSERT_FALSE (real_minus_onep (i_1));
15967 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_1));
15968 : 4 : ASSERT_FALSE (real_minus_onep (i_m1));
15969 : 4 : ASSERT_FALSE (real_minus_onep (wr_i_m1));
15970 : 4 : ASSERT_FALSE (real_minus_onep (f_0));
15971 : 4 : ASSERT_FALSE (real_minus_onep (wr_f_0));
15972 : 4 : ASSERT_FALSE (real_minus_onep (f_1));
15973 : 4 : ASSERT_FALSE (real_minus_onep (wr_f_1));
15974 : 4 : ASSERT_TRUE (real_minus_onep (f_m1));
15975 : 4 : ASSERT_TRUE (real_minus_onep (wr_f_m1));
15976 : 4 : ASSERT_FALSE (real_minus_onep (c_i_0));
15977 : 4 : ASSERT_FALSE (real_minus_onep (c_i_1));
15978 : 4 : ASSERT_FALSE (real_minus_onep (c_i_m1));
15979 : 4 : ASSERT_FALSE (real_minus_onep (c_f_0));
15980 : 4 : ASSERT_FALSE (real_minus_onep (c_f_1));
15981 : 4 : ASSERT_TRUE (real_minus_onep (c_f_m1));
15982 : :
15983 : : /* Test zerop. */
15984 : 4 : ASSERT_TRUE (zerop (i_0));
15985 : 4 : ASSERT_TRUE (zerop (wr_i_0));
15986 : 4 : ASSERT_FALSE (zerop (i_1));
15987 : 4 : ASSERT_FALSE (zerop (wr_i_1));
15988 : 4 : ASSERT_FALSE (zerop (i_m1));
15989 : 4 : ASSERT_FALSE (zerop (wr_i_m1));
15990 : 4 : ASSERT_TRUE (zerop (f_0));
15991 : 4 : ASSERT_TRUE (zerop (wr_f_0));
15992 : 4 : ASSERT_FALSE (zerop (f_1));
15993 : 4 : ASSERT_FALSE (zerop (wr_f_1));
15994 : 4 : ASSERT_FALSE (zerop (f_m1));
15995 : 4 : ASSERT_FALSE (zerop (wr_f_m1));
15996 : 4 : ASSERT_TRUE (zerop (c_i_0));
15997 : 4 : ASSERT_FALSE (zerop (c_i_1));
15998 : 4 : ASSERT_FALSE (zerop (c_i_m1));
15999 : 4 : ASSERT_TRUE (zerop (c_f_0));
16000 : 4 : ASSERT_FALSE (zerop (c_f_1));
16001 : 4 : ASSERT_FALSE (zerop (c_f_m1));
16002 : :
16003 : : /* Test tree_expr_nonnegative_p. */
16004 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_0));
16005 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_0));
16006 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_1));
16007 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_1));
16008 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (i_m1));
16009 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_i_m1));
16010 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_0));
16011 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_0));
16012 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_1));
16013 : 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_1));
16014 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (f_m1));
16015 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_f_m1));
16016 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_0));
16017 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_1));
16018 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_m1));
16019 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_0));
16020 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_1));
16021 : 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_m1));
16022 : :
16023 : : /* Test tree_expr_nonzero_p. */
16024 : 4 : ASSERT_FALSE (tree_expr_nonzero_p (i_0));
16025 : 4 : ASSERT_FALSE (tree_expr_nonzero_p (wr_i_0));
16026 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_1));
16027 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_1));
16028 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_m1));
16029 : 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_m1));
16030 : :
16031 : : /* Test integer_valued_real_p. */
16032 : 4 : ASSERT_FALSE (integer_valued_real_p (i_0));
16033 : 4 : ASSERT_TRUE (integer_valued_real_p (f_0));
16034 : 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_0));
16035 : 4 : ASSERT_TRUE (integer_valued_real_p (f_1));
16036 : 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_1));
16037 : :
16038 : : /* Test integer_pow2p. */
16039 : 4 : ASSERT_FALSE (integer_pow2p (i_0));
16040 : 4 : ASSERT_TRUE (integer_pow2p (i_1));
16041 : 4 : ASSERT_TRUE (integer_pow2p (wr_i_1));
16042 : :
16043 : : /* Test uniform_integer_cst_p. */
16044 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_0));
16045 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_0));
16046 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_1));
16047 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_1));
16048 : 4 : ASSERT_TRUE (uniform_integer_cst_p (i_m1));
16049 : 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_m1));
16050 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_0));
16051 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_0));
16052 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_1));
16053 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_1));
16054 : 4 : ASSERT_FALSE (uniform_integer_cst_p (f_m1));
16055 : 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_m1));
16056 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_0));
16057 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_1));
16058 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_m1));
16059 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_0));
16060 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_1));
16061 : 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_m1));
16062 : 4 : }
16063 : :
16064 : : /* Check that string escaping works correctly. */
16065 : :
16066 : : static void
16067 : 4 : test_escaped_strings (void)
16068 : : {
16069 : 4 : int saved_cutoff;
16070 : 4 : escaped_string msg;
16071 : :
16072 : 4 : msg.escape (NULL);
16073 : : /* ASSERT_STREQ does not accept NULL as a valid test
16074 : : result, so we have to use ASSERT_EQ instead. */
16075 : 4 : ASSERT_EQ (NULL, (const char *) msg);
16076 : :
16077 : 4 : msg.escape ("");
16078 : 4 : ASSERT_STREQ ("", (const char *) msg);
16079 : :
16080 : 4 : msg.escape ("foobar");
16081 : 4 : ASSERT_STREQ ("foobar", (const char *) msg);
16082 : :
16083 : : /* Ensure that we have -fmessage-length set to 0. */
16084 : 4 : pretty_printer *pp = global_dc->get_reference_printer ();
16085 : 4 : saved_cutoff = pp_line_cutoff (pp);
16086 : 4 : pp_line_cutoff (pp) = 0;
16087 : :
16088 : 4 : msg.escape ("foo\nbar");
16089 : 4 : ASSERT_STREQ ("foo\\nbar", (const char *) msg);
16090 : :
16091 : 4 : msg.escape ("\a\b\f\n\r\t\v");
16092 : 4 : ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg);
16093 : :
16094 : : /* Now repeat the tests with -fmessage-length set to 5. */
16095 : 4 : pp_line_cutoff (pp) = 5;
16096 : :
16097 : : /* Note that the newline is not translated into an escape. */
16098 : 4 : msg.escape ("foo\nbar");
16099 : 4 : ASSERT_STREQ ("foo\nbar", (const char *) msg);
16100 : :
16101 : 4 : msg.escape ("\a\b\f\n\r\t\v");
16102 : 4 : ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg);
16103 : :
16104 : : /* Restore the original message length setting. */
16105 : 4 : pp_line_cutoff (pp) = saved_cutoff;
16106 : 4 : }
16107 : :
16108 : : /* Run all of the selftests within this file. */
16109 : :
16110 : : void
16111 : 4 : tree_cc_tests ()
16112 : : {
16113 : 4 : test_integer_constants ();
16114 : 4 : test_identifiers ();
16115 : 4 : test_labels ();
16116 : 4 : test_vector_cst_patterns ();
16117 : 4 : test_location_wrappers ();
16118 : 4 : test_predicates ();
16119 : 4 : test_escaped_strings ();
16120 : 4 : }
16121 : :
16122 : : } // namespace selftest
16123 : :
16124 : : #endif /* CHECKING_P */
16125 : :
16126 : : #include "gt-tree.h"
|