Line data Source code
1 : /* Language-independent node constructors for parse phase of GNU compiler.
2 : Copyright (C) 1987-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
6 : GCC is free software; you can redistribute it and/or modify it under
7 : the terms of the GNU General Public License as published by the Free
8 : Software Foundation; either version 3, or (at your option) any later
9 : version.
10 :
11 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with GCC; see the file COPYING3. If not see
18 : <http://www.gnu.org/licenses/>. */
19 :
20 : /* This file contains the low level primitives for operating on tree nodes,
21 : including allocation, list operations, interning of identifiers,
22 : construction of data type nodes and statement nodes,
23 : and construction of type conversion nodes. It also contains
24 : tables index by tree code that describe how to take apart
25 : nodes of that code.
26 :
27 : It is intended to be language-independent but can occasionally
28 : calls language-dependent routines. */
29 :
30 : #include "config.h"
31 : #include "system.h"
32 : #include "coretypes.h"
33 : #include "backend.h"
34 : #include "target.h"
35 : #include "memmodel.h"
36 : #include "tm_p.h"
37 : #include "tree.h"
38 : #include "gimple.h"
39 : #include "tree-pass.h"
40 : #include "ssa.h"
41 : #include "cgraph.h"
42 : #include "diagnostic.h"
43 : #include "flags.h"
44 : #include "alias.h"
45 : #include "fold-const.h"
46 : #include "stor-layout.h"
47 : #include "calls.h"
48 : #include "attribs.h"
49 : #include "toplev.h" /* get_random_seed */
50 : #include "output.h"
51 : #include "common/common-target.h"
52 : #include "langhooks.h"
53 : #include "tree-inline.h"
54 : #include "tree-iterator.h"
55 : #include "internal-fn.h"
56 : #include "gimple-iterator.h"
57 : #include "gimplify.h"
58 : #include "tree-dfa.h"
59 : #include "langhooks-def.h"
60 : #include "tree-diagnostic.h"
61 : #include "except.h"
62 : #include "builtins.h"
63 : #include "print-tree.h"
64 : #include "ipa-utils.h"
65 : #include "selftest.h"
66 : #include "stringpool.h"
67 : #include "rtl.h"
68 : #include "regs.h"
69 : #include "tree-vector-builder.h"
70 : #include "gimple-fold.h"
71 : #include "escaped_string.h"
72 : #include "gimple-range.h"
73 : #include "gomp-constants.h"
74 : #include "dfp.h"
75 : #include "asan.h"
76 : #include "ubsan.h"
77 : #include "attr-callback.h"
78 :
79 : /* Names of tree components.
80 : Used for printing out the tree and error messages. */
81 : #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
82 : #define END_OF_BASE_TREE_CODES "@dummy",
83 :
84 : static const char *const tree_code_name[] = {
85 : #include "all-tree.def"
86 : };
87 :
88 : #undef DEFTREECODE
89 : #undef END_OF_BASE_TREE_CODES
90 :
91 : /* Each tree code class has an associated string representation.
92 : These must correspond to the tree_code_class entries. */
93 :
94 : const char *const tree_code_class_strings[] =
95 : {
96 : "exceptional",
97 : "constant",
98 : "type",
99 : "declaration",
100 : "reference",
101 : "comparison",
102 : "unary",
103 : "binary",
104 : "statement",
105 : "vl_exp",
106 : "expression"
107 : };
108 :
109 : /* obstack.[ch] explicitly declined to prototype this. */
110 : extern int _obstack_allocated_p (struct obstack *h, void *obj);
111 :
112 : /* Statistics-gathering stuff. */
113 :
114 : static uint64_t tree_code_counts[MAX_TREE_CODES];
115 : uint64_t tree_node_counts[(int) all_kinds];
116 : uint64_t tree_node_sizes[(int) all_kinds];
117 :
118 : /* Keep in sync with tree.h:enum tree_node_kind. */
119 : static const char * const tree_node_kind_names[] = {
120 : "decls",
121 : "types",
122 : "blocks",
123 : "stmts",
124 : "refs",
125 : "exprs",
126 : "constants",
127 : "identifiers",
128 : "vecs",
129 : "binfos",
130 : "ssa names",
131 : "constructors",
132 : "random kinds",
133 : "lang_decl kinds",
134 : "lang_type kinds",
135 : "omp clauses",
136 : };
137 :
138 : /* Unique id for next decl created. */
139 : static GTY(()) int next_decl_uid;
140 : /* Unique id for next type created. */
141 : static GTY(()) unsigned next_type_uid = 1;
142 : /* Unique id for next debug decl created. Use negative numbers,
143 : to catch erroneous uses. */
144 : static GTY(()) int next_debug_decl_uid;
145 :
146 : /* Since we cannot rehash a type after it is in the table, we have to
147 : keep the hash code. */
148 :
149 : struct GTY((for_user)) type_hash {
150 : unsigned long hash;
151 : tree type;
152 : };
153 :
154 : /* Initial size of the hash table (rounded to next prime). */
155 : #define TYPE_HASH_INITIAL_SIZE 1000
156 :
157 : struct type_cache_hasher : ggc_cache_ptr_hash<type_hash>
158 : {
159 8911465798 : static hashval_t hash (type_hash *t) { return t->hash; }
160 : static bool equal (type_hash *a, type_hash *b);
161 :
162 : static int
163 2067752959 : keep_cache_entry (type_hash *&t)
164 : {
165 2067752959 : return ggc_marked_p (t->type);
166 : }
167 : };
168 :
169 : /* Now here is the hash table. When recording a type, it is added to
170 : the slot whose index is the hash code. Note that the hash table is
171 : used for several kinds of types (function types, array types and
172 : array index range types, for now). While all these live in the
173 : same table, they are completely independent, and the hash code is
174 : computed differently for each of these. */
175 :
176 : static GTY ((cache)) hash_table<type_cache_hasher> *type_hash_table;
177 :
178 : /* Hash table and temporary node for larger integer const values. */
179 : static GTY (()) tree int_cst_node;
180 :
181 : struct int_cst_hasher : ggc_cache_ptr_hash<tree_node>
182 : {
183 : static hashval_t hash (tree t);
184 : static bool equal (tree x, tree y);
185 : };
186 :
187 : static GTY ((cache)) hash_table<int_cst_hasher> *int_cst_hash_table;
188 :
189 : /* Class and variable for making sure that there is a single POLY_INT_CST
190 : for a given value. */
191 : struct poly_int_cst_hasher : ggc_cache_ptr_hash<tree_node>
192 : {
193 : typedef std::pair<tree, const poly_wide_int *> compare_type;
194 : static hashval_t hash (tree t);
195 : static bool equal (tree x, const compare_type &y);
196 : };
197 :
198 : static GTY ((cache)) hash_table<poly_int_cst_hasher> *poly_int_cst_hash_table;
199 :
200 : /* Hash table for optimization flags and target option flags. Use the same
201 : hash table for both sets of options. Nodes for building the current
202 : optimization and target option nodes. The assumption is most of the time
203 : the options created will already be in the hash table, so we avoid
204 : allocating and freeing up a node repeatably. */
205 : static GTY (()) tree cl_optimization_node;
206 : static GTY (()) tree cl_target_option_node;
207 :
208 : struct cl_option_hasher : ggc_cache_ptr_hash<tree_node>
209 : {
210 : static hashval_t hash (tree t);
211 : static bool equal (tree x, tree y);
212 : };
213 :
214 : static GTY ((cache)) hash_table<cl_option_hasher> *cl_option_hash_table;
215 :
216 874596 : struct gt_value_expr_mark_data {
217 : hash_set<tree> pset;
218 : auto_vec<tree, 16> to_mark;
219 : };
220 :
221 : /* Callback called through walk_tree_1 to discover DECL_HAS_VALUE_EXPR_P
222 : VAR_DECLs which weren't marked yet, in that case marks them and
223 : walks their DECL_VALUE_EXPR expressions. */
224 :
225 : static tree
226 24355804 : gt_value_expr_mark_2 (tree *tp, int *, void *data)
227 : {
228 24355804 : tree t = *tp;
229 24355804 : if (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t) && !ggc_marked_p (t))
230 : {
231 1095 : tree dve = DECL_VALUE_EXPR (t);
232 1095 : gt_value_expr_mark_data *d = (gt_value_expr_mark_data *) data;
233 1095 : walk_tree_1 (&dve, gt_value_expr_mark_2, data, &d->pset, NULL);
234 1095 : d->to_mark.safe_push (t);
235 : }
236 24355804 : return NULL_TREE;
237 : }
238 :
239 : /* Callback called through traverse_noresize on the
240 : value_expr_for_decl hash table. */
241 :
242 : int
243 10332292 : gt_value_expr_mark_1 (tree_decl_map **e, gt_value_expr_mark_data *data)
244 : {
245 10332292 : if (ggc_marked_p ((*e)->base.from))
246 9022505 : walk_tree_1 (&(*e)->to, gt_value_expr_mark_2, data, &data->pset, NULL);
247 10332292 : return 1;
248 : }
249 :
250 : /* The value_expr_for_decl hash table can have mappings for trees
251 : which are only referenced from mappings of other trees in the
252 : same table, see PR118790. Without this routine, gt_cleare_cache
253 : could clear hash table slot of a tree which isn't marked but
254 : will be marked when processing later hash table slot of another
255 : tree which is marked. This function marks with the above
256 : helpers marks all the not yet marked DECL_HAS_VALUE_EXPR_P
257 : VAR_DECLs mentioned in DECL_VALUE_EXPR expressions of marked
258 : trees and in that case also recurses on their DECL_VALUE_EXPR. */
259 :
260 : void
261 874596 : gt_value_expr_mark (hash_table<tree_decl_map_cache_hasher> *h)
262 : {
263 874596 : if (!h)
264 0 : return;
265 :
266 874596 : gt_value_expr_mark_data data;
267 874596 : h->traverse_noresize<gt_value_expr_mark_data *,
268 11206888 : gt_value_expr_mark_1> (&data);
269 2624883 : for (auto v : data.to_mark)
270 1095 : gt_ggc_mx (v);
271 874596 : }
272 :
273 : /* General tree->tree mapping structure for use in hash tables. */
274 :
275 :
276 : static GTY ((cache))
277 : hash_table<tree_decl_map_cache_hasher> *debug_expr_for_decl;
278 :
279 : static GTY ((cache ("gt_value_expr_mark")))
280 : hash_table<tree_decl_map_cache_hasher> *value_expr_for_decl;
281 :
282 : static GTY ((cache))
283 : hash_table<tree_vec_map_cache_hasher> *debug_args_for_decl;
284 :
285 : static void set_type_quals (tree, int);
286 : static void print_type_hash_statistics (void);
287 : static void print_debug_expr_statistics (void);
288 : static void print_value_expr_statistics (void);
289 :
290 : tree global_trees[TI_MAX];
291 : tree integer_types[itk_none];
292 :
293 : bool int_n_enabled_p[NUM_INT_N_ENTS];
294 : struct int_n_trees_t int_n_trees [NUM_INT_N_ENTS];
295 :
296 : bool tree_contains_struct[MAX_TREE_CODES][64];
297 :
298 : /* Number of operands for each OMP clause. */
299 : unsigned const char omp_clause_num_ops[] =
300 : {
301 : 0, /* OMP_CLAUSE_ERROR */
302 : 1, /* OMP_CLAUSE_PRIVATE */
303 : 1, /* OMP_CLAUSE_SHARED */
304 : 1, /* OMP_CLAUSE_FIRSTPRIVATE */
305 : 2, /* OMP_CLAUSE_LASTPRIVATE */
306 : 5, /* OMP_CLAUSE_REDUCTION */
307 : 5, /* OMP_CLAUSE_TASK_REDUCTION */
308 : 5, /* OMP_CLAUSE_IN_REDUCTION */
309 : 1, /* OMP_CLAUSE_COPYIN */
310 : 1, /* OMP_CLAUSE_COPYPRIVATE */
311 : 3, /* OMP_CLAUSE_LINEAR */
312 : 1, /* OMP_CLAUSE_AFFINITY */
313 : 2, /* OMP_CLAUSE_ALIGNED */
314 : 3, /* OMP_CLAUSE_ALLOCATE */
315 : 1, /* OMP_CLAUSE_DEPEND */
316 : 1, /* OMP_CLAUSE_NONTEMPORAL */
317 : 1, /* OMP_CLAUSE_UNIFORM */
318 : 1, /* OMP_CLAUSE_ENTER */
319 : 1, /* OMP_CLAUSE_LINK */
320 : 1, /* OMP_CLAUSE_LOCAL */
321 : 1, /* OMP_CLAUSE_DETACH */
322 : 1, /* OMP_CLAUSE_USE_DEVICE_PTR */
323 : 1, /* OMP_CLAUSE_USE_DEVICE_ADDR */
324 : 1, /* OMP_CLAUSE_IS_DEVICE_PTR */
325 : 1, /* OMP_CLAUSE_INCLUSIVE */
326 : 1, /* OMP_CLAUSE_EXCLUSIVE */
327 : 3, /* OMP_CLAUSE_FROM */
328 : 3, /* OMP_CLAUSE_TO */
329 : 3, /* OMP_CLAUSE_MAP (update walk_tree_1 if this is changed) */
330 : 1, /* OMP_CLAUSE_HAS_DEVICE_ADDR */
331 : 1, /* OMP_CLAUSE_DOACROSS */
332 : 3, /* OMP_CLAUSE__MAPPER_BINDING_ */
333 : 2, /* OMP_CLAUSE__CACHE_ */
334 : 1, /* OMP_CLAUSE_DESTROY */
335 : 2, /* OMP_CLAUSE_INIT */
336 : 1, /* OMP_CLAUSE_USE */
337 : 1, /* OMP_CLAUSE_INTEROP */
338 : 2, /* OMP_CLAUSE_GANG */
339 : 1, /* OMP_CLAUSE_ASYNC */
340 : 1, /* OMP_CLAUSE_WAIT */
341 : 0, /* OMP_CLAUSE_AUTO */
342 : 0, /* OMP_CLAUSE_SEQ */
343 : 1, /* OMP_CLAUSE__LOOPTEMP_ */
344 : 1, /* OMP_CLAUSE__REDUCTEMP_ */
345 : 1, /* OMP_CLAUSE__CONDTEMP_ */
346 : 1, /* OMP_CLAUSE__SCANTEMP_ */
347 : 1, /* OMP_CLAUSE_IF */
348 : 1, /* OMP_CLAUSE_SELF */
349 : 1, /* OMP_CLAUSE_NUM_THREADS */
350 : 1, /* OMP_CLAUSE_SCHEDULE */
351 : 0, /* OMP_CLAUSE_NOWAIT */
352 : 1, /* OMP_CLAUSE_ORDERED */
353 : 0, /* OMP_CLAUSE_DEFAULT */
354 : 3, /* OMP_CLAUSE_COLLAPSE */
355 : 0, /* OMP_CLAUSE_UNTIED */
356 : 1, /* OMP_CLAUSE_FINAL */
357 : 0, /* OMP_CLAUSE_MERGEABLE */
358 : 1, /* OMP_CLAUSE_DEVICE */
359 : 1, /* OMP_CLAUSE_DIST_SCHEDULE */
360 : 0, /* OMP_CLAUSE_INBRANCH */
361 : 0, /* OMP_CLAUSE_NOTINBRANCH */
362 : 2, /* OMP_CLAUSE_NUM_TEAMS */
363 : 1, /* OMP_CLAUSE_THREAD_LIMIT */
364 : 0, /* OMP_CLAUSE_PROC_BIND */
365 : 1, /* OMP_CLAUSE_SAFELEN */
366 : 3, /* OMP_CLAUSE_SIMDLEN */
367 : 0, /* OMP_CLAUSE_DEVICE_TYPE */
368 : 0, /* OMP_CLAUSE_FOR */
369 : 0, /* OMP_CLAUSE_PARALLEL */
370 : 0, /* OMP_CLAUSE_SECTIONS */
371 : 0, /* OMP_CLAUSE_TASKGROUP */
372 : 1, /* OMP_CLAUSE_PRIORITY */
373 : 1, /* OMP_CLAUSE_GRAINSIZE */
374 : 1, /* OMP_CLAUSE_NUM_TASKS */
375 : 0, /* OMP_CLAUSE_NOGROUP */
376 : 0, /* OMP_CLAUSE_THREADS */
377 : 0, /* OMP_CLAUSE_SIMD */
378 : 1, /* OMP_CLAUSE_HINT */
379 : 0, /* OMP_CLAUSE_DEFAULTMAP */
380 : 0, /* OMP_CLAUSE_ORDER */
381 : 0, /* OMP_CLAUSE_BIND */
382 : 1, /* OMP_CLAUSE_FILTER */
383 : 1, /* OMP_CLAUSE_INDIRECT */
384 : 1, /* OMP_CLAUSE_PARTIAL */
385 : 0, /* OMP_CLAUSE_FULL */
386 : 1, /* OMP_CLAUSE_SIZES */
387 : 1, /* OMP_CLAUSE__SIMDUID_ */
388 : 0, /* OMP_CLAUSE__SIMT_ */
389 : 0, /* OMP_CLAUSE_INDEPENDENT */
390 : 1, /* OMP_CLAUSE_WORKER */
391 : 1, /* OMP_CLAUSE_VECTOR */
392 : 1, /* OMP_CLAUSE_NUM_GANGS */
393 : 1, /* OMP_CLAUSE_NUM_WORKERS */
394 : 1, /* OMP_CLAUSE_VECTOR_LENGTH */
395 : 3, /* OMP_CLAUSE_TILE */
396 : 0, /* OMP_CLAUSE_IF_PRESENT */
397 : 0, /* OMP_CLAUSE_FINALIZE */
398 : 0, /* OMP_CLAUSE_NOHOST */
399 : 1, /* OMP_CLAUSE_NOVARIANTS */
400 : 1, /* OMP_CLAUSE_NOCONTEXT */
401 : 1, /* OMP_CLAUSE_DYN_GROUPPRIVATE */
402 : 3, /* OMP_CLAUSE_USES_ALLOCATORS */
403 : 2, /* OMP_CLAUSE_MESSAGE */
404 : };
405 :
406 : const char * const omp_clause_code_name[] =
407 : {
408 : "error_clause",
409 : "private",
410 : "shared",
411 : "firstprivate",
412 : "lastprivate",
413 : "reduction",
414 : "task_reduction",
415 : "in_reduction",
416 : "copyin",
417 : "copyprivate",
418 : "linear",
419 : "affinity",
420 : "aligned",
421 : "allocate",
422 : "depend",
423 : "nontemporal",
424 : "uniform",
425 : "enter",
426 : "link",
427 : "local",
428 : "detach",
429 : "use_device_ptr",
430 : "use_device_addr",
431 : "is_device_ptr",
432 : "inclusive",
433 : "exclusive",
434 : "from",
435 : "to",
436 : "map",
437 : "has_device_addr",
438 : "doacross",
439 : "_mapper_binding_",
440 : "_cache_",
441 : "destroy",
442 : "init",
443 : "use",
444 : "interop",
445 : "gang",
446 : "async",
447 : "wait",
448 : "auto",
449 : "seq",
450 : "_looptemp_",
451 : "_reductemp_",
452 : "_condtemp_",
453 : "_scantemp_",
454 : "if",
455 : "self",
456 : "num_threads",
457 : "schedule",
458 : "nowait",
459 : "ordered",
460 : "default",
461 : "collapse",
462 : "untied",
463 : "final",
464 : "mergeable",
465 : "device",
466 : "dist_schedule",
467 : "inbranch",
468 : "notinbranch",
469 : "num_teams",
470 : "thread_limit",
471 : "proc_bind",
472 : "safelen",
473 : "simdlen",
474 : "device_type",
475 : "for",
476 : "parallel",
477 : "sections",
478 : "taskgroup",
479 : "priority",
480 : "grainsize",
481 : "num_tasks",
482 : "nogroup",
483 : "threads",
484 : "simd",
485 : "hint",
486 : "defaultmap",
487 : "order",
488 : "bind",
489 : "filter",
490 : "indirect",
491 : "partial",
492 : "full",
493 : "sizes",
494 : "_simduid_",
495 : "_simt_",
496 : "independent",
497 : "worker",
498 : "vector",
499 : "num_gangs",
500 : "num_workers",
501 : "vector_length",
502 : "tile",
503 : "if_present",
504 : "finalize",
505 : "nohost",
506 : "novariants",
507 : "nocontext",
508 : "dyn_groupprivate",
509 : "uses_allocators",
510 : "message"
511 : };
512 :
513 : /* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric
514 : clause names, but for use in diagnostics etc. would like to use the "user"
515 : clause names. */
516 :
517 : const char *
518 445 : user_omp_clause_code_name (tree clause, bool oacc)
519 : {
520 : /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to
521 : distinguish clauses as seen by the user. See also where front ends do
522 : 'build_omp_clause' with 'OMP_CLAUSE_MAP'. */
523 890 : if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
524 445 : switch (OMP_CLAUSE_MAP_KIND (clause))
525 : {
526 : case GOMP_MAP_FORCE_ALLOC:
527 : case GOMP_MAP_ALLOC: return "create";
528 0 : case GOMP_MAP_FORCE_TO:
529 0 : case GOMP_MAP_TO: return "copyin";
530 0 : case GOMP_MAP_FORCE_FROM:
531 0 : case GOMP_MAP_FROM: return "copyout";
532 361 : case GOMP_MAP_FORCE_TOFROM:
533 361 : case GOMP_MAP_TOFROM: return "copy";
534 0 : case GOMP_MAP_RELEASE: return "delete";
535 0 : case GOMP_MAP_FORCE_PRESENT: return "present";
536 42 : case GOMP_MAP_ATTACH: return "attach";
537 42 : case GOMP_MAP_FORCE_DETACH:
538 42 : case GOMP_MAP_DETACH: return "detach";
539 0 : case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
540 0 : case GOMP_MAP_LINK: return "link";
541 0 : case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
542 : default: break;
543 : }
544 :
545 0 : return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
546 : }
547 :
548 :
549 : /* Return the tree node structure used by tree code CODE. */
550 :
551 : static inline enum tree_node_structure_enum
552 44920826935 : tree_node_structure_for_code (enum tree_code code)
553 : {
554 44920826935 : switch (TREE_CODE_CLASS (code))
555 : {
556 11092521175 : case tcc_declaration:
557 11092521175 : switch (code)
558 : {
559 : case CONST_DECL: return TS_CONST_DECL;
560 : case DEBUG_EXPR_DECL: return TS_DECL_WRTL;
561 : case FIELD_DECL: return TS_FIELD_DECL;
562 : case FUNCTION_DECL: return TS_FUNCTION_DECL;
563 : case LABEL_DECL: return TS_LABEL_DECL;
564 : case PARM_DECL: return TS_PARM_DECL;
565 : case RESULT_DECL: return TS_RESULT_DECL;
566 : case TRANSLATION_UNIT_DECL: return TS_TRANSLATION_UNIT_DECL;
567 : case TYPE_DECL: return TS_TYPE_DECL;
568 : case VAR_DECL: return TS_VAR_DECL;
569 : default: return TS_DECL_NON_COMMON;
570 : }
571 :
572 : case tcc_type: return TS_TYPE_NON_COMMON;
573 :
574 11707526927 : case tcc_binary:
575 11707526927 : case tcc_comparison:
576 11707526927 : case tcc_expression:
577 11707526927 : case tcc_reference:
578 11707526927 : case tcc_statement:
579 11707526927 : case tcc_unary:
580 11707526927 : case tcc_vl_exp: return TS_EXP;
581 :
582 16015037166 : default: /* tcc_constant and tcc_exceptional */
583 16015037166 : break;
584 : }
585 :
586 16015037166 : switch (code)
587 : {
588 : /* tcc_constant cases. */
589 : case COMPLEX_CST: return TS_COMPLEX;
590 294536 : case FIXED_CST: return TS_FIXED_CST;
591 779183140 : case INTEGER_CST: return TS_INT_CST;
592 294536 : case POLY_INT_CST: return TS_POLY_INT_CST;
593 49779316 : case REAL_CST: return TS_REAL_CST;
594 261173388 : case STRING_CST: return TS_STRING;
595 13863080 : case VECTOR_CST: return TS_VECTOR;
596 1169990 : case VOID_CST: return TS_TYPED;
597 294791 : case RAW_DATA_CST: return TS_RAW_DATA_CST;
598 :
599 : /* tcc_exceptional cases. */
600 741383439 : case BLOCK: return TS_BLOCK;
601 143553295 : case CONSTRUCTOR: return TS_CONSTRUCTOR;
602 : case ERROR_MARK: return TS_COMMON;
603 9063217 : case IDENTIFIER_NODE: return TS_IDENTIFIER;
604 871674 : case OMP_CLAUSE: return TS_OMP_CLAUSE;
605 2057912 : case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
606 : case PLACEHOLDER_EXPR: return TS_COMMON;
607 335968166 : case SSA_NAME: return TS_SSA_NAME;
608 814367326 : case STATEMENT_LIST: return TS_STATEMENT_LIST;
609 4006470 : case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
610 278080641 : case TREE_BINFO: return TS_BINFO;
611 10337488377 : case TREE_LIST: return TS_LIST;
612 2240176352 : case TREE_VEC: return TS_VEC;
613 :
614 0 : default:
615 0 : gcc_unreachable ();
616 : }
617 : }
618 :
619 :
620 : /* Initialize tree_contains_struct to describe the hierarchy of tree
621 : nodes. */
622 :
623 : static void
624 294536 : initialize_tree_contains_struct (void)
625 : {
626 294536 : unsigned i;
627 :
628 72455856 : for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
629 : {
630 72161320 : enum tree_code code;
631 72161320 : enum tree_node_structure_enum ts_code;
632 :
633 72161320 : code = (enum tree_code) i;
634 72161320 : ts_code = tree_node_structure_for_code (code);
635 :
636 : /* Mark the TS structure itself. */
637 72161320 : tree_contains_struct[code][ts_code] = 1;
638 :
639 : /* Mark all the structures that TS is derived from. */
640 72161320 : switch (ts_code)
641 : {
642 1178144 : case TS_TYPED:
643 1178144 : case TS_BLOCK:
644 1178144 : case TS_OPTIMIZATION:
645 1178144 : case TS_TARGET_OPTION:
646 1178144 : MARK_TS_BASE (code);
647 1178144 : break;
648 :
649 59496272 : case TS_COMMON:
650 59496272 : case TS_INT_CST:
651 59496272 : case TS_POLY_INT_CST:
652 59496272 : case TS_REAL_CST:
653 59496272 : case TS_FIXED_CST:
654 59496272 : case TS_VECTOR:
655 59496272 : case TS_STRING:
656 59496272 : case TS_RAW_DATA_CST:
657 59496272 : case TS_COMPLEX:
658 59496272 : case TS_SSA_NAME:
659 59496272 : case TS_CONSTRUCTOR:
660 59496272 : case TS_EXP:
661 59496272 : case TS_STATEMENT_LIST:
662 59496272 : MARK_TS_TYPED (code);
663 59496272 : break;
664 :
665 1472680 : case TS_IDENTIFIER:
666 1472680 : case TS_DECL_MINIMAL:
667 1472680 : case TS_TYPE_COMMON:
668 1472680 : case TS_LIST:
669 1472680 : case TS_VEC:
670 1472680 : case TS_BINFO:
671 1472680 : case TS_OMP_CLAUSE:
672 1472680 : MARK_TS_COMMON (code);
673 1472680 : break;
674 :
675 : case TS_TYPE_WITH_LANG_SPECIFIC:
676 : MARK_TS_TYPE_COMMON (code);
677 : break;
678 :
679 6185256 : case TS_TYPE_NON_COMMON:
680 6185256 : MARK_TS_TYPE_WITH_LANG_SPECIFIC (code);
681 6185256 : break;
682 :
683 : case TS_DECL_COMMON:
684 : MARK_TS_DECL_MINIMAL (code);
685 : break;
686 :
687 589072 : case TS_DECL_WRTL:
688 589072 : case TS_CONST_DECL:
689 589072 : MARK_TS_DECL_COMMON (code);
690 589072 : break;
691 :
692 883608 : case TS_DECL_NON_COMMON:
693 883608 : MARK_TS_DECL_WITH_VIS (code);
694 883608 : break;
695 :
696 883608 : case TS_DECL_WITH_VIS:
697 883608 : case TS_PARM_DECL:
698 883608 : case TS_LABEL_DECL:
699 883608 : case TS_RESULT_DECL:
700 883608 : MARK_TS_DECL_WRTL (code);
701 883608 : break;
702 :
703 294536 : case TS_FIELD_DECL:
704 294536 : MARK_TS_DECL_COMMON (code);
705 294536 : break;
706 :
707 294536 : case TS_VAR_DECL:
708 294536 : MARK_TS_DECL_WITH_VIS (code);
709 294536 : break;
710 :
711 589072 : case TS_TYPE_DECL:
712 589072 : case TS_FUNCTION_DECL:
713 589072 : MARK_TS_DECL_NON_COMMON (code);
714 589072 : break;
715 :
716 294536 : case TS_TRANSLATION_UNIT_DECL:
717 294536 : MARK_TS_DECL_COMMON (code);
718 294536 : break;
719 :
720 : default:
721 : gcc_unreachable ();
722 : }
723 : }
724 :
725 : /* Basic consistency checks for attributes used in fold. */
726 294536 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
727 294536 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
728 294536 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
729 294536 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
730 294536 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
731 294536 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
732 294536 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
733 294536 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
734 294536 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
735 294536 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
736 294536 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
737 294536 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
738 294536 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
739 294536 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
740 294536 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
741 294536 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
742 294536 : gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
743 294536 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
744 294536 : gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
745 294536 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
746 294536 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
747 294536 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
748 294536 : gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
749 294536 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
750 294536 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
751 294536 : gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
752 294536 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
753 294536 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
754 294536 : gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
755 294536 : gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
756 294536 : gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
757 294536 : gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
758 294536 : gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
759 294536 : gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
760 294536 : gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
761 294536 : gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
762 294536 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
763 294536 : gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
764 294536 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_MINIMAL]);
765 294536 : gcc_assert (tree_contains_struct[NAMELIST_DECL][TS_DECL_COMMON]);
766 294536 : }
767 :
768 :
769 : /* Init tree.cc. */
770 :
771 : void
772 294536 : init_ttree (void)
773 : {
774 : /* Initialize the hash table of types. */
775 294536 : type_hash_table
776 294536 : = hash_table<type_cache_hasher>::create_ggc (TYPE_HASH_INITIAL_SIZE);
777 :
778 294536 : debug_expr_for_decl
779 294536 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
780 :
781 294536 : value_expr_for_decl
782 294536 : = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
783 :
784 294536 : int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024);
785 :
786 294536 : poly_int_cst_hash_table = hash_table<poly_int_cst_hasher>::create_ggc (64);
787 :
788 294536 : int_cst_node = make_int_cst (1, 1);
789 :
790 294536 : cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64);
791 :
792 294536 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
793 294536 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
794 :
795 : /* Initialize the tree_contains_struct array. */
796 294536 : initialize_tree_contains_struct ();
797 294536 : lang_hooks.init_ts ();
798 294536 : }
799 :
800 :
801 : /* Mapping from prefix to label number. */
802 :
803 : struct identifier_hash : ggc_ptr_hash <tree_node>
804 : {
805 55714 : static inline hashval_t hash (tree t)
806 : {
807 55714 : return IDENTIFIER_HASH_VALUE (t);
808 : }
809 : };
810 : struct identifier_count_traits
811 : : simple_hashmap_traits<identifier_hash, long> {};
812 : typedef hash_map<tree, long, identifier_count_traits> internal_label_map;
813 : static GTY(()) internal_label_map *internal_label_nums;
814 :
815 : /* Generates an identifier intended to be used internally with the
816 : given PREFIX. This is intended to be used by the frontend so that
817 : C++ modules can regenerate appropriate (non-clashing) identifiers on
818 : stream-in. */
819 :
820 : tree
821 44415 : generate_internal_label (const char *prefix)
822 : {
823 44415 : tree prefix_id = get_identifier (prefix);
824 44415 : if (!internal_label_nums)
825 3093 : internal_label_nums = internal_label_map::create_ggc();
826 44415 : long &num = internal_label_nums->get_or_insert (prefix_id);
827 :
828 44415 : char tmp[32];
829 44415 : ASM_GENERATE_INTERNAL_LABEL (tmp, prefix, num++);
830 :
831 44415 : tree id = get_identifier (tmp);
832 44415 : IDENTIFIER_INTERNAL_P (id) = true;
833 :
834 : /* Cache the prefix on the identifier so we can retrieve it later. */
835 44415 : TREE_CHAIN (id) = prefix_id;
836 :
837 44415 : return id;
838 : }
839 :
840 : /* Get the PREFIX we created the internal identifier LABEL with. */
841 :
842 : const char *
843 7 : prefix_for_internal_label (tree label)
844 : {
845 7 : gcc_assert (IDENTIFIER_INTERNAL_P (label)
846 : && !IDENTIFIER_TRANSPARENT_ALIAS (label)
847 : && TREE_CHAIN (label)
848 : && TREE_CODE (TREE_CHAIN (label)) == IDENTIFIER_NODE);
849 7 : return IDENTIFIER_POINTER (TREE_CHAIN (label));
850 : }
851 :
852 : /* The name of the object as the assembler will see it (but before any
853 : translations made by ASM_OUTPUT_LABELREF). Often this is the same
854 : as DECL_NAME. It is an IDENTIFIER_NODE. */
855 : tree
856 1771810375 : decl_assembler_name (tree decl)
857 : {
858 1771810375 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
859 174403589 : lang_hooks.set_decl_assembler_name (decl);
860 1771810375 : return DECL_ASSEMBLER_NAME_RAW (decl);
861 : }
862 :
863 : /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
864 : (either of which may be NULL). Inform the FE, if this changes the
865 : name. */
866 :
867 : void
868 932381120 : overwrite_decl_assembler_name (tree decl, tree name)
869 : {
870 932381120 : if (DECL_ASSEMBLER_NAME_RAW (decl) != name)
871 460194672 : lang_hooks.overwrite_decl_assembler_name (decl, name);
872 932381120 : }
873 :
874 : /* Return true if DECL may need an assembler name to be set. */
875 :
876 : static inline bool
877 5207920 : need_assembler_name_p (tree decl)
878 : {
879 : /* We use DECL_ASSEMBLER_NAME to hold mangled type names for One Definition
880 : Rule merging. This makes type_odr_p to return true on those types during
881 : LTO and by comparing the mangled name, we can say what types are intended
882 : to be equivalent across compilation unit.
883 :
884 : We do not store names of type_in_anonymous_namespace_p.
885 :
886 : Record, union and enumeration type have linkage that allows use
887 : to check type_in_anonymous_namespace_p. We do not mangle compound types
888 : that always can be compared structurally.
889 :
890 : Similarly for builtin types, we compare properties of their main variant.
891 : A special case are integer types where mangling do make differences
892 : between char/signed char/unsigned char etc. Storing name for these makes
893 : e.g. -fno-signed-char/-fsigned-char mismatches to be handled well.
894 : See cp/mangle.cc:write_builtin_type for details. */
895 :
896 5207920 : if (TREE_CODE (decl) == TYPE_DECL)
897 : {
898 158986 : if (DECL_NAME (decl)
899 129544 : && decl == TYPE_NAME (TREE_TYPE (decl))
900 129389 : && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == TREE_TYPE (decl)
901 109690 : && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
902 106670 : && ((TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
903 88646 : && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE)
904 18282 : || TYPE_CXX_ODR_P (TREE_TYPE (decl)))
905 105269 : && (type_with_linkage_p (TREE_TYPE (decl))
906 90263 : || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)
907 229133 : && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
908 70147 : return !DECL_ASSEMBLER_NAME_SET_P (decl);
909 : return false;
910 : }
911 : /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
912 5048934 : if (!VAR_OR_FUNCTION_DECL_P (decl))
913 : return false;
914 :
915 : /* If DECL already has its assembler name set, it does not need a
916 : new one. */
917 4350456 : if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
918 4350456 : || DECL_ASSEMBLER_NAME_SET_P (decl))
919 : return false;
920 :
921 : /* Abstract decls do not need an assembler name, except they
922 : can be looked up by autofdo. */
923 1737684 : if (DECL_ABSTRACT_P (decl) && !flag_auto_profile)
924 : return false;
925 :
926 : /* For VAR_DECLs, only static, public and external symbols need an
927 : assembler name. */
928 1736305 : if (VAR_P (decl)
929 547229 : && !TREE_STATIC (decl)
930 546904 : && !TREE_PUBLIC (decl)
931 2283209 : && !DECL_EXTERNAL (decl))
932 : return false;
933 :
934 1189401 : if (TREE_CODE (decl) == FUNCTION_DECL)
935 : {
936 : /* Do not set assembler name on builtins. Allow RTL expansion to
937 : decide whether to expand inline or via a regular call. */
938 1189076 : if (fndecl_built_in_p (decl)
939 1189076 : && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
940 : return false;
941 :
942 : /* Functions represented in the callgraph need an assembler name. */
943 1184361 : if (cgraph_node::get (decl) != NULL)
944 : return true;
945 :
946 : /* Unused and not public functions don't need an assembler name. */
947 3377 : if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
948 3 : return false;
949 : }
950 :
951 : return true;
952 : }
953 :
954 : /* If T needs an assembler name, have one created for it. */
955 :
956 : void
957 5207920 : assign_assembler_name_if_needed (tree t)
958 : {
959 5207920 : if (need_assembler_name_p (t))
960 : {
961 : /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
962 : diagnostics that use input_location to show locus
963 : information. The problem here is that, at this point,
964 : input_location is generally anchored to the end of the file
965 : (since the parser is long gone), so we don't have a good
966 : position to pin it to.
967 :
968 : To alleviate this problem, this uses the location of T's
969 : declaration. Examples of this are
970 : testsuite/g++.dg/template/cond2.C and
971 : testsuite/g++.dg/template/pr35240.C. */
972 1254807 : location_t saved_location = input_location;
973 1254807 : input_location = DECL_SOURCE_LOCATION (t);
974 :
975 1254807 : decl_assembler_name (t);
976 :
977 1254807 : input_location = saved_location;
978 : }
979 5207920 : }
980 :
981 : /* When the target supports COMDAT groups, this indicates which group the
982 : DECL is associated with. This can be either an IDENTIFIER_NODE or a
983 : decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
984 : tree
985 399022616 : decl_comdat_group (const_tree node)
986 : {
987 399022616 : struct symtab_node *snode = symtab_node::get (node);
988 399022616 : if (!snode)
989 : return NULL;
990 381362272 : return snode->get_comdat_group ();
991 : }
992 :
993 : /* Likewise, but make sure it's been reduced to an IDENTIFIER_NODE. */
994 : tree
995 12105 : decl_comdat_group_id (const_tree node)
996 : {
997 12105 : struct symtab_node *snode = symtab_node::get (node);
998 12105 : if (!snode)
999 : return NULL;
1000 12105 : return snode->get_comdat_group_id ();
1001 : }
1002 :
1003 : /* When the target supports named section, return its name as IDENTIFIER_NODE
1004 : or NULL if it is in no section. */
1005 : const char *
1006 765715727 : decl_section_name (const_tree node)
1007 : {
1008 765715727 : struct symtab_node *snode = symtab_node::get (node);
1009 765715727 : if (!snode)
1010 : return NULL;
1011 576745800 : return snode->get_section ();
1012 : }
1013 :
1014 : /* Set section name of NODE to VALUE (that is expected to be
1015 : identifier node) */
1016 : void
1017 1835824 : set_decl_section_name (tree node, const char *value)
1018 : {
1019 1835824 : struct symtab_node *snode;
1020 :
1021 1835824 : if (value == NULL)
1022 : {
1023 219 : snode = symtab_node::get (node);
1024 219 : if (!snode)
1025 : return;
1026 : }
1027 1835605 : else if (VAR_P (node))
1028 1571694 : snode = varpool_node::get_create (node);
1029 : else
1030 263911 : snode = cgraph_node::get_create (node);
1031 1835824 : snode->set_section (value);
1032 : }
1033 :
1034 : /* Set section name of NODE to match the section name of OTHER.
1035 :
1036 : set_decl_section_name (decl, other) is equivalent to
1037 : set_decl_section_name (decl, DECL_SECTION_NAME (other)), but possibly more
1038 : efficient. */
1039 : void
1040 16817922 : set_decl_section_name (tree decl, const_tree other)
1041 : {
1042 16817922 : struct symtab_node *other_node = symtab_node::get (other);
1043 16817922 : if (other_node)
1044 : {
1045 16816481 : struct symtab_node *decl_node;
1046 16816481 : if (VAR_P (decl))
1047 23 : decl_node = varpool_node::get_create (decl);
1048 : else
1049 16816458 : decl_node = cgraph_node::get_create (decl);
1050 16816481 : decl_node->set_section (*other_node);
1051 : }
1052 : else
1053 : {
1054 1441 : struct symtab_node *decl_node = symtab_node::get (decl);
1055 1441 : if (!decl_node)
1056 : return;
1057 0 : decl_node->set_section (NULL);
1058 : }
1059 : }
1060 :
1061 : /* Return TLS model of a variable NODE. */
1062 : enum tls_model
1063 283929620 : decl_tls_model (const_tree node)
1064 : {
1065 283929620 : struct varpool_node *snode = varpool_node::get (node);
1066 283929620 : if (!snode)
1067 : return TLS_MODEL_NONE;
1068 234023870 : return snode->tls_model;
1069 : }
1070 :
1071 : /* Set TLS model of variable NODE to MODEL. */
1072 : void
1073 58029 : set_decl_tls_model (tree node, enum tls_model model)
1074 : {
1075 58029 : struct varpool_node *vnode;
1076 :
1077 58029 : if (model == TLS_MODEL_NONE)
1078 : {
1079 6285 : vnode = varpool_node::get (node);
1080 6285 : if (!vnode)
1081 : return;
1082 : }
1083 : else
1084 51744 : vnode = varpool_node::get_create (node);
1085 51744 : vnode->tls_model = model;
1086 : }
1087 :
1088 : /* Compute the number of bytes occupied by a tree with code CODE.
1089 : This function cannot be used for nodes that have variable sizes,
1090 : including TREE_VEC, INTEGER_CST, STRING_CST, and CALL_EXPR. */
1091 : size_t
1092 19475723685 : tree_code_size (enum tree_code code)
1093 : {
1094 19475723685 : switch (TREE_CODE_CLASS (code))
1095 : {
1096 4683017815 : case tcc_declaration: /* A decl node */
1097 4683017815 : switch (code)
1098 : {
1099 : case FIELD_DECL: return sizeof (tree_field_decl);
1100 : case PARM_DECL: return sizeof (tree_parm_decl);
1101 287258301 : case VAR_DECL: return sizeof (tree_var_decl);
1102 : case LABEL_DECL: return sizeof (tree_label_decl);
1103 : case RESULT_DECL: return sizeof (tree_result_decl);
1104 31727151 : case CONST_DECL: return sizeof (tree_const_decl);
1105 : case TYPE_DECL: return sizeof (tree_type_decl);
1106 1504185562 : case FUNCTION_DECL: return sizeof (tree_function_decl);
1107 : case DEBUG_EXPR_DECL: return sizeof (tree_decl_with_rtl);
1108 : case TRANSLATION_UNIT_DECL: return sizeof (tree_translation_unit_decl);
1109 : case NAMESPACE_DECL:
1110 : case IMPORTED_DECL:
1111 : case NAMELIST_DECL: return sizeof (tree_decl_non_common);
1112 303717999 : default:
1113 303717999 : gcc_checking_assert (code >= NUM_TREE_CODES);
1114 303717999 : return lang_hooks.tree_size (code);
1115 : }
1116 :
1117 3238035048 : case tcc_type: /* a type node */
1118 3238035048 : switch (code)
1119 : {
1120 : case OFFSET_TYPE:
1121 : case ENUMERAL_TYPE:
1122 : case BOOLEAN_TYPE:
1123 : case INTEGER_TYPE:
1124 : case REAL_TYPE:
1125 : case OPAQUE_TYPE:
1126 : case POINTER_TYPE:
1127 : case REFERENCE_TYPE:
1128 : case NULLPTR_TYPE:
1129 : case FIXED_POINT_TYPE:
1130 : case COMPLEX_TYPE:
1131 : case VECTOR_TYPE:
1132 : case ARRAY_TYPE:
1133 : case RECORD_TYPE:
1134 : case UNION_TYPE:
1135 : case QUAL_UNION_TYPE:
1136 : case VOID_TYPE:
1137 : case FUNCTION_TYPE:
1138 : case METHOD_TYPE:
1139 : case BITINT_TYPE:
1140 : case LANG_TYPE: return sizeof (tree_type_non_common);
1141 775144323 : default:
1142 775144323 : gcc_checking_assert (code >= NUM_TREE_CODES);
1143 775144323 : return lang_hooks.tree_size (code);
1144 : }
1145 :
1146 5345011843 : case tcc_reference: /* a reference */
1147 5345011843 : case tcc_expression: /* an expression */
1148 5345011843 : case tcc_statement: /* an expression with side effects */
1149 5345011843 : case tcc_comparison: /* a comparison expression */
1150 5345011843 : case tcc_unary: /* a unary arithmetic expression */
1151 5345011843 : case tcc_binary: /* a binary arithmetic expression */
1152 5345011843 : return (sizeof (struct tree_exp)
1153 5345011843 : + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
1154 :
1155 44777576 : case tcc_constant: /* a constant */
1156 44777576 : switch (code)
1157 : {
1158 : case VOID_CST: return sizeof (tree_typed);
1159 0 : case INTEGER_CST: gcc_unreachable ();
1160 : case POLY_INT_CST: return sizeof (tree_poly_int_cst);
1161 43921437 : case REAL_CST: return sizeof (tree_real_cst);
1162 : case FIXED_CST: return sizeof (tree_fixed_cst);
1163 : case COMPLEX_CST: return sizeof (tree_complex);
1164 : case RAW_DATA_CST: return sizeof (tree_raw_data);
1165 0 : case VECTOR_CST: gcc_unreachable ();
1166 0 : case STRING_CST: gcc_unreachable ();
1167 64901 : default:
1168 64901 : gcc_checking_assert (code >= NUM_TREE_CODES);
1169 64901 : return lang_hooks.tree_size (code);
1170 : }
1171 :
1172 6164881403 : case tcc_exceptional: /* something random, like an identifier. */
1173 6164881403 : switch (code)
1174 : {
1175 1789326014 : case IDENTIFIER_NODE: return lang_hooks.identifier_size;
1176 : case TREE_LIST: return sizeof (tree_list);
1177 :
1178 : case ERROR_MARK:
1179 : case PLACEHOLDER_EXPR: return sizeof (tree_common);
1180 :
1181 0 : case TREE_VEC: gcc_unreachable ();
1182 0 : case OMP_CLAUSE: gcc_unreachable ();
1183 :
1184 : case SSA_NAME: return sizeof (tree_ssa_name);
1185 :
1186 : case STATEMENT_LIST: return sizeof (tree_statement_list);
1187 322156153 : case BLOCK: return sizeof (struct tree_block);
1188 : case CONSTRUCTOR: return sizeof (tree_constructor);
1189 : case OPTIMIZATION_NODE: return sizeof (tree_optimization_option);
1190 : case TARGET_OPTION_NODE: return sizeof (tree_target_option);
1191 :
1192 1701722252 : default:
1193 1701722252 : gcc_checking_assert (code >= NUM_TREE_CODES);
1194 1701722252 : return lang_hooks.tree_size (code);
1195 : }
1196 :
1197 0 : default:
1198 0 : gcc_unreachable ();
1199 : }
1200 : }
1201 :
1202 : /* Compute the number of bytes occupied by NODE. This routine only
1203 : looks at TREE_CODE, except for those nodes that have variable sizes. */
1204 : size_t
1205 4713707542 : tree_size (const_tree node)
1206 : {
1207 4713707542 : const enum tree_code code = TREE_CODE (node);
1208 4713707542 : switch (code)
1209 : {
1210 539521 : case INTEGER_CST:
1211 539521 : return (sizeof (struct tree_int_cst)
1212 539521 : + (TREE_INT_CST_EXT_NUNITS (node) - 1) * sizeof (HOST_WIDE_INT));
1213 :
1214 0 : case TREE_BINFO:
1215 0 : return (offsetof (struct tree_binfo, base_binfos)
1216 : + vec<tree, va_gc>
1217 0 : ::embedded_size (BINFO_N_BASE_BINFOS (node)));
1218 :
1219 432286627 : case TREE_VEC:
1220 432286627 : return (sizeof (struct tree_vec)
1221 432286627 : + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
1222 :
1223 0 : case VECTOR_CST:
1224 0 : return (sizeof (struct tree_vector)
1225 0 : + (vector_cst_encoded_nelts (node) - 1) * sizeof (tree));
1226 :
1227 23848 : case STRING_CST:
1228 23848 : return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
1229 :
1230 33866 : case OMP_CLAUSE:
1231 33866 : return (sizeof (struct tree_omp_clause)
1232 33866 : + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
1233 33866 : * sizeof (tree));
1234 :
1235 4280823680 : default:
1236 4280823680 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
1237 198671551 : return (sizeof (struct tree_exp)
1238 198671551 : + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
1239 : else
1240 4082152129 : return tree_code_size (code);
1241 : }
1242 : }
1243 :
1244 : /* Return tree node kind based on tree CODE. */
1245 :
1246 : static tree_node_kind
1247 0 : get_stats_node_kind (enum tree_code code)
1248 : {
1249 0 : enum tree_code_class type = TREE_CODE_CLASS (code);
1250 :
1251 0 : switch (type)
1252 : {
1253 : case tcc_declaration: /* A decl node */
1254 : return d_kind;
1255 0 : case tcc_type: /* a type node */
1256 0 : return t_kind;
1257 0 : case tcc_statement: /* an expression with side effects */
1258 0 : return s_kind;
1259 0 : case tcc_reference: /* a reference */
1260 0 : return r_kind;
1261 : case tcc_expression: /* an expression */
1262 : case tcc_comparison: /* a comparison expression */
1263 : case tcc_unary: /* a unary arithmetic expression */
1264 : case tcc_binary: /* a binary arithmetic expression */
1265 : return e_kind;
1266 0 : case tcc_constant: /* a constant */
1267 0 : return c_kind;
1268 0 : case tcc_exceptional: /* something random, like an identifier. */
1269 0 : switch (code)
1270 : {
1271 : case IDENTIFIER_NODE:
1272 : return id_kind;
1273 0 : case TREE_VEC:
1274 0 : return vec_kind;
1275 0 : case TREE_BINFO:
1276 0 : return binfo_kind;
1277 0 : case SSA_NAME:
1278 0 : return ssa_name_kind;
1279 0 : case BLOCK:
1280 0 : return b_kind;
1281 0 : case CONSTRUCTOR:
1282 0 : return constr_kind;
1283 0 : case OMP_CLAUSE:
1284 0 : return omp_clause_kind;
1285 0 : default:
1286 0 : return x_kind;
1287 : }
1288 : break;
1289 : case tcc_vl_exp:
1290 : return e_kind;
1291 0 : default:
1292 0 : gcc_unreachable ();
1293 : }
1294 : }
1295 :
1296 : /* Record interesting allocation statistics for a tree node with CODE
1297 : and LENGTH. */
1298 :
1299 : static void
1300 0 : record_node_allocation_statistics (enum tree_code code, size_t length)
1301 : {
1302 0 : if (!GATHER_STATISTICS)
1303 0 : return;
1304 :
1305 : tree_node_kind kind = get_stats_node_kind (code);
1306 :
1307 : tree_code_counts[(int) code]++;
1308 : tree_node_counts[(int) kind]++;
1309 : tree_node_sizes[(int) kind] += length;
1310 : }
1311 :
1312 : /* Allocate and return a new UID from the DECL_UID namespace. */
1313 :
1314 : int
1315 4676233664 : allocate_decl_uid (void)
1316 : {
1317 4676233664 : return next_decl_uid++;
1318 : }
1319 :
1320 : /* Return a newly allocated node of code CODE. For decl and type
1321 : nodes, some other fields are initialized. The rest of the node is
1322 : initialized to zero. This function cannot be used for TREE_VEC,
1323 : INTEGER_CST or OMP_CLAUSE nodes, which is enforced by asserts in
1324 : tree_code_size.
1325 :
1326 : Achoo! I got a code in the node. */
1327 :
1328 : tree
1329 15387750359 : make_node (enum tree_code code MEM_STAT_DECL)
1330 : {
1331 15387750359 : tree t;
1332 15387750359 : enum tree_code_class type = TREE_CODE_CLASS (code);
1333 15387750359 : size_t length = tree_code_size (code);
1334 :
1335 15387750359 : record_node_allocation_statistics (code, length);
1336 :
1337 15387750359 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1338 15387750359 : TREE_SET_CODE (t, code);
1339 :
1340 15387750359 : switch (type)
1341 : {
1342 799617223 : case tcc_statement:
1343 799617223 : if (code != DEBUG_BEGIN_STMT)
1344 419910611 : TREE_SIDE_EFFECTS (t) = 1;
1345 : break;
1346 :
1347 3337387451 : case tcc_declaration:
1348 3337387451 : if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1349 : {
1350 3337387451 : if (code == FUNCTION_DECL)
1351 : {
1352 1175489763 : SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
1353 1175489763 : SET_DECL_MODE (t, FUNCTION_MODE);
1354 : }
1355 : else
1356 2161897688 : SET_DECL_ALIGN (t, 1);
1357 : }
1358 3337387451 : DECL_SOURCE_LOCATION (t) = input_location;
1359 3337387451 : if (TREE_CODE (t) == DEBUG_EXPR_DECL)
1360 2070486 : DECL_UID (t) = --next_debug_decl_uid;
1361 : else
1362 : {
1363 3335316965 : DECL_UID (t) = allocate_decl_uid ();
1364 3335316965 : SET_DECL_PT_UID (t, -1);
1365 : }
1366 3337387451 : if (TREE_CODE (t) == LABEL_DECL)
1367 38426810 : LABEL_DECL_UID (t) = -1;
1368 :
1369 : break;
1370 :
1371 2401962947 : case tcc_type:
1372 2401962947 : TYPE_UID (t) = next_type_uid++;
1373 2401962947 : SET_TYPE_ALIGN (t, BITS_PER_UNIT);
1374 2401962947 : TYPE_USER_ALIGN (t) = 0;
1375 2401962947 : TYPE_MAIN_VARIANT (t) = t;
1376 2401962947 : TYPE_CANONICAL (t) = t;
1377 :
1378 : /* Default to no attributes for type, but let target change that. */
1379 2401962947 : TYPE_ATTRIBUTES (t) = NULL_TREE;
1380 2401962947 : targetm.set_default_type_attributes (t);
1381 :
1382 : /* We have not yet computed the alias set for this type. */
1383 2401962947 : TYPE_ALIAS_SET (t) = -1;
1384 2401962947 : break;
1385 :
1386 44775715 : case tcc_constant:
1387 44775715 : TREE_CONSTANT (t) = 1;
1388 44775715 : break;
1389 :
1390 1389621948 : case tcc_expression:
1391 1389621948 : switch (code)
1392 : {
1393 299238257 : case INIT_EXPR:
1394 299238257 : case MODIFY_EXPR:
1395 299238257 : case VA_ARG_EXPR:
1396 299238257 : case PREDECREMENT_EXPR:
1397 299238257 : case PREINCREMENT_EXPR:
1398 299238257 : case POSTDECREMENT_EXPR:
1399 299238257 : case POSTINCREMENT_EXPR:
1400 : /* All of these have side-effects, no matter what their
1401 : operands are. */
1402 299238257 : TREE_SIDE_EFFECTS (t) = 1;
1403 299238257 : break;
1404 :
1405 : default:
1406 : break;
1407 : }
1408 : break;
1409 :
1410 5935999076 : case tcc_exceptional:
1411 5935999076 : switch (code)
1412 : {
1413 1104525 : case TARGET_OPTION_NODE:
1414 2209050 : TREE_TARGET_OPTION(t)
1415 1104525 : = ggc_cleared_alloc<struct cl_target_option> ();
1416 1104525 : break;
1417 :
1418 613336 : case OPTIMIZATION_NODE:
1419 1226672 : TREE_OPTIMIZATION (t)
1420 613336 : = ggc_cleared_alloc<struct cl_optimization> ();
1421 613336 : break;
1422 :
1423 : default:
1424 : break;
1425 : }
1426 : break;
1427 :
1428 : default:
1429 : /* Other classes need no special treatment. */
1430 : break;
1431 : }
1432 :
1433 15387750359 : return t;
1434 : }
1435 :
1436 : /* Free tree node. */
1437 :
1438 : void
1439 687733604 : free_node (tree node)
1440 : {
1441 687733604 : enum tree_code code = TREE_CODE (node);
1442 687733604 : if (GATHER_STATISTICS)
1443 : {
1444 : enum tree_node_kind kind = get_stats_node_kind (code);
1445 :
1446 : gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
1447 : gcc_checking_assert (tree_node_counts[(int) kind] != 0);
1448 : gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
1449 :
1450 : tree_code_counts[(int) TREE_CODE (node)]--;
1451 : tree_node_counts[(int) kind]--;
1452 : tree_node_sizes[(int) kind] -= tree_size (node);
1453 : }
1454 687733604 : if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1455 349 : vec_free (CONSTRUCTOR_ELTS (node));
1456 687733411 : else if (code == BLOCK)
1457 0 : vec_free (BLOCK_NONLOCALIZED_VARS (node));
1458 687733411 : else if (code == TREE_BINFO)
1459 369 : vec_free (BINFO_BASE_ACCESSES (node));
1460 687733042 : else if (code == OPTIMIZATION_NODE)
1461 867 : cl_optimization_option_free (TREE_OPTIMIZATION (node));
1462 687732175 : else if (code == TARGET_OPTION_NODE)
1463 932 : cl_target_option_free (TREE_TARGET_OPTION (node));
1464 687733604 : ggc_free (node);
1465 687733604 : }
1466 :
1467 : /* Return a new node with the same contents as NODE except that its
1468 : TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
1469 :
1470 : tree
1471 4626789714 : copy_node (tree node MEM_STAT_DECL)
1472 : {
1473 4626789714 : tree t;
1474 4626789714 : enum tree_code code = TREE_CODE (node);
1475 4626789714 : size_t length;
1476 :
1477 4626789714 : gcc_assert (code != STATEMENT_LIST);
1478 :
1479 4626789714 : length = tree_size (node);
1480 4626789714 : record_node_allocation_statistics (code, length);
1481 4626789714 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
1482 4626789714 : memcpy (t, node, length);
1483 :
1484 4626789714 : if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
1485 2659318303 : TREE_CHAIN (t) = 0;
1486 4626789714 : TREE_ASM_WRITTEN (t) = 0;
1487 4626789714 : TREE_VISITED (t) = 0;
1488 :
1489 4626789714 : if (TREE_CODE_CLASS (code) == tcc_declaration)
1490 : {
1491 1339809167 : if (code == DEBUG_EXPR_DECL)
1492 0 : DECL_UID (t) = --next_debug_decl_uid;
1493 : else
1494 : {
1495 1339809167 : DECL_UID (t) = allocate_decl_uid ();
1496 1339809167 : if (DECL_PT_UID_SET_P (node))
1497 3534 : SET_DECL_PT_UID (t, DECL_PT_UID (node));
1498 : }
1499 667908423 : if ((TREE_CODE (node) == PARM_DECL || VAR_P (node))
1500 1429563857 : && DECL_HAS_VALUE_EXPR_P (node))
1501 : {
1502 1278731 : SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
1503 1278731 : DECL_HAS_VALUE_EXPR_P (t) = 1;
1504 : }
1505 : /* DECL_DEBUG_EXPR is copied explicitly by callers. */
1506 1339809167 : if (VAR_P (node))
1507 : {
1508 89754690 : DECL_HAS_DEBUG_EXPR_P (t) = 0;
1509 89754690 : t->decl_with_vis.symtab_node = NULL;
1510 : }
1511 1339809167 : if (VAR_P (node) && DECL_HAS_INIT_PRIORITY_P (node))
1512 : {
1513 0 : SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
1514 0 : DECL_HAS_INIT_PRIORITY_P (t) = 1;
1515 : }
1516 1339809167 : if (TREE_CODE (node) == FUNCTION_DECL)
1517 : {
1518 323518295 : DECL_STRUCT_FUNCTION (t) = NULL;
1519 323518295 : t->decl_with_vis.symtab_node = NULL;
1520 : }
1521 : }
1522 3286980547 : else if (TREE_CODE_CLASS (code) == tcc_type)
1523 : {
1524 836072101 : TYPE_UID (t) = next_type_uid++;
1525 : /* The following is so that the debug code for
1526 : the copy is different from the original type.
1527 : The two statements usually duplicate each other
1528 : (because they clear fields of the same union),
1529 : but the optimizer should catch that. */
1530 836072101 : TYPE_SYMTAB_ADDRESS (t) = 0;
1531 836072101 : TYPE_SYMTAB_DIE (t) = 0;
1532 :
1533 : /* Do not copy the values cache. */
1534 836072101 : if (TYPE_CACHED_VALUES_P (t))
1535 : {
1536 20237028 : TYPE_CACHED_VALUES_P (t) = 0;
1537 20237028 : TYPE_CACHED_VALUES (t) = NULL_TREE;
1538 : }
1539 : }
1540 2450908446 : else if (code == TARGET_OPTION_NODE)
1541 : {
1542 0 : TREE_TARGET_OPTION (t) = ggc_alloc<struct cl_target_option>();
1543 0 : memcpy (TREE_TARGET_OPTION (t), TREE_TARGET_OPTION (node),
1544 : sizeof (struct cl_target_option));
1545 : }
1546 2450908446 : else if (code == OPTIMIZATION_NODE)
1547 : {
1548 0 : TREE_OPTIMIZATION (t) = ggc_alloc<struct cl_optimization>();
1549 0 : memcpy (TREE_OPTIMIZATION (t), TREE_OPTIMIZATION (node),
1550 : sizeof (struct cl_optimization));
1551 : }
1552 :
1553 4626789714 : return t;
1554 : }
1555 :
1556 : /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1557 : For example, this can copy a list made of TREE_LIST nodes. */
1558 :
1559 : tree
1560 170559651 : copy_list (tree list)
1561 : {
1562 170559651 : tree head;
1563 170559651 : tree prev, next;
1564 :
1565 170559651 : if (list == 0)
1566 : return 0;
1567 :
1568 165265110 : head = prev = copy_node (list);
1569 165265110 : next = TREE_CHAIN (list);
1570 324832603 : while (next)
1571 : {
1572 159567493 : TREE_CHAIN (prev) = copy_node (next);
1573 159567493 : prev = TREE_CHAIN (prev);
1574 159567493 : next = TREE_CHAIN (next);
1575 : }
1576 : return head;
1577 : }
1578 :
1579 :
1580 : /* Return the value that TREE_INT_CST_EXT_NUNITS should have for an
1581 : INTEGER_CST with value CST and type TYPE. */
1582 :
1583 : static unsigned int
1584 11283662512 : get_int_cst_ext_nunits (tree type, const wide_int &cst)
1585 : {
1586 11283662512 : gcc_checking_assert (cst.get_precision () == TYPE_PRECISION (type));
1587 : /* We need extra HWIs if CST is an unsigned integer with its
1588 : upper bit set. */
1589 11283662512 : if (TYPE_UNSIGNED (type) && wi::neg_p (cst))
1590 190069167 : return cst.get_precision () / HOST_BITS_PER_WIDE_INT + 1;
1591 11093593345 : return cst.get_len ();
1592 : }
1593 :
1594 : /* Return a new INTEGER_CST with value CST and type TYPE. */
1595 :
1596 : static tree
1597 137365540 : build_new_int_cst (tree type, const wide_int &cst)
1598 : {
1599 137365540 : unsigned int len = cst.get_len ();
1600 137365540 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1601 137365540 : tree nt = make_int_cst (len, ext_len);
1602 :
1603 137365540 : if (len < ext_len)
1604 : {
1605 70718900 : --ext_len;
1606 141437800 : TREE_INT_CST_ELT (nt, ext_len)
1607 70718900 : = zext_hwi (-1, cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1608 94224009 : for (unsigned int i = len; i < ext_len; ++i)
1609 23505109 : TREE_INT_CST_ELT (nt, i) = -1;
1610 : }
1611 66646640 : else if (TYPE_UNSIGNED (type)
1612 66646640 : && cst.get_precision () < len * HOST_BITS_PER_WIDE_INT)
1613 : {
1614 14378344 : len--;
1615 28756688 : TREE_INT_CST_ELT (nt, len)
1616 14378344 : = zext_hwi (cst.elt (len),
1617 14378344 : cst.get_precision () % HOST_BITS_PER_WIDE_INT);
1618 : }
1619 :
1620 263875764 : for (unsigned int i = 0; i < len; i++)
1621 126510224 : TREE_INT_CST_ELT (nt, i) = cst.elt (i);
1622 137365540 : TREE_TYPE (nt) = type;
1623 137365540 : return nt;
1624 : }
1625 :
1626 : /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE. */
1627 :
1628 : static tree
1629 0 : build_new_poly_int_cst (tree type, tree (&coeffs)[NUM_POLY_INT_COEFFS]
1630 : CXX_MEM_STAT_INFO)
1631 : {
1632 0 : size_t length = sizeof (struct tree_poly_int_cst);
1633 0 : record_node_allocation_statistics (POLY_INT_CST, length);
1634 :
1635 0 : tree t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1636 :
1637 0 : TREE_SET_CODE (t, POLY_INT_CST);
1638 0 : TREE_CONSTANT (t) = 1;
1639 0 : TREE_TYPE (t) = type;
1640 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1641 0 : POLY_INT_CST_COEFF (t, i) = coeffs[i];
1642 0 : return t;
1643 : }
1644 :
1645 : /* Create a constant tree that contains CST sign-extended to TYPE. */
1646 :
1647 : tree
1648 7436372748 : build_int_cst (tree type, poly_int64 cst)
1649 : {
1650 : /* Support legacy code. */
1651 7436372748 : if (!type)
1652 48 : type = integer_type_node;
1653 :
1654 7436372748 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1655 : }
1656 :
1657 : /* Create a constant tree that contains CST zero-extended to TYPE. */
1658 :
1659 : tree
1660 9972957 : build_int_cstu (tree type, poly_uint64 cst)
1661 : {
1662 9972957 : return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type)));
1663 : }
1664 :
1665 : /* Create a constant tree that contains CST sign-extended to TYPE. */
1666 :
1667 : tree
1668 27838751 : build_int_cst_type (tree type, poly_int64 cst)
1669 : {
1670 27838751 : gcc_assert (type);
1671 27838751 : return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1672 : }
1673 :
1674 : /* Constructs tree in type TYPE from with value given by CST. Signedness
1675 : of CST is assumed to be the same as the signedness of TYPE. */
1676 :
1677 : tree
1678 7298166 : double_int_to_tree (tree type, double_int cst)
1679 : {
1680 7298166 : return wide_int_to_tree (type, widest_int::from (cst, TYPE_SIGN (type)));
1681 : }
1682 :
1683 : /* We force the wide_int CST to the range of the type TYPE by sign or
1684 : zero extending it. OVERFLOWABLE indicates if we are interested in
1685 : overflow of the value, when >0 we are only interested in signed
1686 : overflow, for <0 we are interested in any overflow. OVERFLOWED
1687 : indicates whether overflow has already occurred. CONST_OVERFLOWED
1688 : indicates whether constant overflow has already occurred. We force
1689 : T's value to be within range of T's type (by setting to 0 or 1 all
1690 : the bits outside the type's range). We set TREE_OVERFLOWED if,
1691 : OVERFLOWED is nonzero,
1692 : or OVERFLOWABLE is >0 and signed overflow occurs
1693 : or OVERFLOWABLE is <0 and any overflow occurs
1694 : We return a new tree node for the extended wide_int. The node
1695 : is shared if no overflow flags are set. */
1696 :
1697 :
1698 : tree
1699 3071193645 : force_fit_type (tree type, const poly_wide_int_ref &cst,
1700 : int overflowable, bool overflowed)
1701 : {
1702 3071193645 : signop sign = TYPE_SIGN (type);
1703 :
1704 : /* If we need to set overflow flags, return a new unshared node. */
1705 3071193645 : if (overflowed || !wi::fits_to_tree_p (cst, type))
1706 : {
1707 7195852 : if (overflowed
1708 7195852 : || overflowable < 0
1709 5952200 : || (overflowable > 0 && sign == SIGNED))
1710 : {
1711 1325457 : poly_wide_int tmp = poly_wide_int::from (cst, TYPE_PRECISION (type),
1712 1325457 : sign);
1713 1325457 : tree t;
1714 1325457 : if (tmp.is_constant ())
1715 1325457 : t = build_new_int_cst (type, tmp.coeffs[0]);
1716 : else
1717 : {
1718 : tree coeffs[NUM_POLY_INT_COEFFS];
1719 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1720 : {
1721 : coeffs[i] = build_new_int_cst (type, tmp.coeffs[i]);
1722 : TREE_OVERFLOW (coeffs[i]) = 1;
1723 : }
1724 : t = build_new_poly_int_cst (type, coeffs);
1725 : }
1726 1325457 : TREE_OVERFLOW (t) = 1;
1727 1325457 : return t;
1728 1325457 : }
1729 : }
1730 :
1731 : /* Else build a shared node. */
1732 3069868188 : return wide_int_to_tree (type, cst);
1733 : }
1734 :
1735 : /* These are the hash table functions for the hash table of INTEGER_CST
1736 : nodes of a sizetype. */
1737 :
1738 : /* Return the hash code X, an INTEGER_CST. */
1739 :
1740 : hashval_t
1741 2979135932 : int_cst_hasher::hash (tree x)
1742 : {
1743 2979135932 : const_tree const t = x;
1744 2979135932 : hashval_t code = TYPE_UID (TREE_TYPE (t));
1745 2979135932 : int i;
1746 :
1747 5963879753 : for (i = 0; i < TREE_INT_CST_NUNITS (t); i++)
1748 2984743821 : code = iterative_hash_host_wide_int (TREE_INT_CST_ELT(t, i), code);
1749 :
1750 2979135932 : return code;
1751 : }
1752 :
1753 : /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1754 : is the same as that given by *Y, which is the same. */
1755 :
1756 : bool
1757 2921709530 : int_cst_hasher::equal (tree x, tree y)
1758 : {
1759 2921709530 : const_tree const xt = x;
1760 2921709530 : const_tree const yt = y;
1761 :
1762 2921709530 : if (TREE_TYPE (xt) != TREE_TYPE (yt)
1763 966197872 : || TREE_INT_CST_NUNITS (xt) != TREE_INT_CST_NUNITS (yt)
1764 3887858270 : || TREE_INT_CST_EXT_NUNITS (xt) != TREE_INT_CST_EXT_NUNITS (yt))
1765 : return false;
1766 :
1767 1324073048 : for (int i = 0; i < TREE_INT_CST_NUNITS (xt); i++)
1768 929643991 : if (TREE_INT_CST_ELT (xt, i) != TREE_INT_CST_ELT (yt, i))
1769 : return false;
1770 :
1771 : return true;
1772 : }
1773 :
1774 : /* Cache wide_int CST into the TYPE_CACHED_VALUES cache for TYPE.
1775 : SLOT is the slot entry to store it in, and MAX_SLOTS is the maximum
1776 : number of slots that can be cached for the type. */
1777 :
1778 : static inline tree
1779 10582689404 : cache_wide_int_in_type_cache (tree type, const wide_int &cst,
1780 : int slot, int max_slots)
1781 : {
1782 10582689404 : gcc_checking_assert (slot >= 0);
1783 : /* Initialize cache. */
1784 10582689404 : if (!TYPE_CACHED_VALUES_P (type))
1785 : {
1786 20668055 : TYPE_CACHED_VALUES_P (type) = 1;
1787 20668055 : TYPE_CACHED_VALUES (type) = make_tree_vec (max_slots);
1788 : }
1789 10582689404 : tree t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot);
1790 10582689404 : if (!t)
1791 : {
1792 : /* Create a new shared int. */
1793 63010884 : t = build_new_int_cst (type, cst);
1794 63010884 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), slot) = t;
1795 : }
1796 10582689404 : return t;
1797 : }
1798 :
1799 : /* Create an INT_CST node of TYPE and value CST.
1800 : The returned node is always shared. For small integers we use a
1801 : per-type vector cache, for larger ones we use a single hash table.
1802 : The value is extended from its precision according to the sign of
1803 : the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1804 : the upper bits and ensures that hashing and value equality based
1805 : upon the underlying HOST_WIDE_INTs works without masking. */
1806 :
1807 : static tree
1808 11146296972 : wide_int_to_tree_1 (tree type, const wide_int_ref &pcst)
1809 : {
1810 11146296972 : tree t;
1811 11146296972 : int ix = -1;
1812 11146296972 : int limit = 0;
1813 :
1814 11146296972 : gcc_assert (type);
1815 11146296972 : unsigned int prec = TYPE_PRECISION (type);
1816 11146296972 : signop sgn = TYPE_SIGN (type);
1817 :
1818 : /* Verify that everything is canonical. */
1819 11146296972 : int l = pcst.get_len ();
1820 11146296972 : if (l > 1)
1821 : {
1822 3998490 : if (pcst.elt (l - 1) == 0)
1823 1126826 : gcc_checking_assert (pcst.elt (l - 2) < 0);
1824 3998490 : if (pcst.elt (l - 1) == HOST_WIDE_INT_M1)
1825 11545 : gcc_checking_assert (pcst.elt (l - 2) >= 0);
1826 : }
1827 :
1828 11146296972 : wide_int cst = wide_int::from (pcst, prec, sgn);
1829 11146296972 : unsigned int ext_len = get_int_cst_ext_nunits (type, cst);
1830 :
1831 11146296972 : enum tree_code code = TREE_CODE (type);
1832 11146296972 : if (code == POINTER_TYPE || code == REFERENCE_TYPE)
1833 : {
1834 : /* Cache NULL pointer and zero bounds. */
1835 194721716 : if (cst == 0)
1836 : ix = 0;
1837 : /* Cache upper bounds of pointers. */
1838 51656906 : else if (cst == wi::max_value (prec, sgn))
1839 : ix = 1;
1840 : /* Cache 1 which is used for a non-zero range. */
1841 49528265 : else if (cst == 1)
1842 : ix = 2;
1843 :
1844 : if (ix >= 0)
1845 : {
1846 151066318 : t = cache_wide_int_in_type_cache (type, cst, ix, 3);
1847 : /* Make sure no one is clobbering the shared constant. */
1848 151066318 : gcc_checking_assert (TREE_TYPE (t) == type
1849 : && cst == wi::to_wide (t));
1850 151066318 : return t;
1851 : }
1852 : }
1853 10995230654 : if (ext_len == 1)
1854 : {
1855 : /* We just need to store a single HOST_WIDE_INT. */
1856 10922201455 : HOST_WIDE_INT hwi;
1857 10922201455 : if (TYPE_UNSIGNED (type))
1858 7347088746 : hwi = cst.to_uhwi ();
1859 : else
1860 3575178848 : hwi = cst.to_shwi ();
1861 :
1862 10922201455 : switch (code)
1863 : {
1864 : /* This could represent the C++ std::meta::info type. */
1865 228878 : case LANG_TYPE:
1866 228878 : case NULLPTR_TYPE:
1867 228878 : gcc_assert (hwi == 0);
1868 : /* Fallthru. */
1869 :
1870 : case POINTER_TYPE:
1871 : case REFERENCE_TYPE:
1872 : /* Ignore pointers, as they were already handled above. */
1873 : break;
1874 :
1875 123692627 : case BOOLEAN_TYPE:
1876 : /* Cache false or true. */
1877 123692627 : limit = 2;
1878 123692627 : if (IN_RANGE (hwi, 0, 1))
1879 123485080 : ix = hwi;
1880 : break;
1881 :
1882 10739385743 : case INTEGER_TYPE:
1883 10739385743 : case OFFSET_TYPE:
1884 10739385743 : case BITINT_TYPE:
1885 10739385743 : if (TYPE_SIGN (type) == UNSIGNED)
1886 : {
1887 : /* Cache [0, N). */
1888 7170602238 : limit = param_integer_share_limit;
1889 7170602238 : if (IN_RANGE (hwi, 0, param_integer_share_limit - 1))
1890 6889592147 : ix = hwi;
1891 : }
1892 : else
1893 : {
1894 : /* Cache [-1, N). */
1895 3568783505 : limit = param_integer_share_limit + 1;
1896 3568783505 : if (IN_RANGE (hwi, -1, param_integer_share_limit - 1))
1897 3418545859 : ix = hwi + 1;
1898 : }
1899 : break;
1900 :
1901 : case ENUMERAL_TYPE:
1902 : break;
1903 :
1904 0 : default:
1905 0 : gcc_unreachable ();
1906 : }
1907 :
1908 10922201455 : if (ix >= 0)
1909 : {
1910 10431623086 : t = cache_wide_int_in_type_cache (type, cst, ix, limit);
1911 : /* Make sure no one is clobbering the shared constant. */
1912 20863246172 : gcc_checking_assert (TREE_TYPE (t) == type
1913 : && TREE_INT_CST_NUNITS (t) == 1
1914 : && TREE_INT_CST_EXT_NUNITS (t) == 1
1915 : && TREE_INT_CST_ELT (t, 0) == hwi);
1916 : return t;
1917 : }
1918 : else
1919 : {
1920 : /* Use the cache of larger shared ints, using int_cst_node as
1921 : a temporary. */
1922 :
1923 490578369 : TREE_INT_CST_ELT (int_cst_node, 0) = hwi;
1924 490578369 : TREE_TYPE (int_cst_node) = type;
1925 :
1926 490578369 : tree *slot = int_cst_hash_table->find_slot (int_cst_node, INSERT);
1927 490578369 : t = *slot;
1928 490578369 : if (!t)
1929 : {
1930 : /* Insert this one into the hash table. */
1931 157055743 : t = int_cst_node;
1932 157055743 : *slot = t;
1933 : /* Make a new node for next time round. */
1934 157055743 : int_cst_node = make_int_cst (1, 1);
1935 : }
1936 : }
1937 : }
1938 : else
1939 : {
1940 : /* The value either hashes properly or we drop it on the floor
1941 : for the gc to take care of. There will not be enough of them
1942 : to worry about. */
1943 :
1944 73029199 : tree nt = build_new_int_cst (type, cst);
1945 73029199 : tree *slot = int_cst_hash_table->find_slot (nt, INSERT);
1946 73029199 : t = *slot;
1947 73029199 : if (!t)
1948 : {
1949 : /* Insert this one into the hash table. */
1950 12859410 : t = nt;
1951 12859410 : *slot = t;
1952 : }
1953 : else
1954 60169789 : ggc_free (nt);
1955 : }
1956 :
1957 : return t;
1958 11146296972 : }
1959 :
1960 : hashval_t
1961 0 : poly_int_cst_hasher::hash (tree t)
1962 : {
1963 0 : inchash::hash hstate;
1964 :
1965 0 : hstate.add_int (TYPE_UID (TREE_TYPE (t)));
1966 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1967 0 : hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
1968 :
1969 0 : return hstate.end ();
1970 : }
1971 :
1972 : bool
1973 0 : poly_int_cst_hasher::equal (tree x, const compare_type &y)
1974 : {
1975 0 : if (TREE_TYPE (x) != y.first)
1976 : return false;
1977 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1978 0 : if (wi::to_wide (POLY_INT_CST_COEFF (x, i)) != y.second->coeffs[i])
1979 : return false;
1980 : return true;
1981 : }
1982 :
1983 : /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
1984 : The elements must also have type TYPE. */
1985 :
1986 : tree
1987 0 : build_poly_int_cst (tree type, const poly_wide_int_ref &values)
1988 : {
1989 0 : unsigned int prec = TYPE_PRECISION (type);
1990 0 : gcc_assert (prec <= values.coeffs[0].get_precision ());
1991 0 : poly_wide_int c = poly_wide_int::from (values, prec, SIGNED);
1992 :
1993 0 : inchash::hash h;
1994 0 : h.add_int (TYPE_UID (type));
1995 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1996 0 : h.add_wide_int (c.coeffs[i]);
1997 0 : poly_int_cst_hasher::compare_type comp (type, &c);
1998 0 : tree *slot = poly_int_cst_hash_table->find_slot_with_hash (comp, h.end (),
1999 : INSERT);
2000 0 : if (*slot == NULL_TREE)
2001 : {
2002 : tree coeffs[NUM_POLY_INT_COEFFS];
2003 0 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
2004 0 : coeffs[i] = wide_int_to_tree_1 (type, c.coeffs[i]);
2005 0 : *slot = build_new_poly_int_cst (type, coeffs);
2006 : }
2007 0 : return *slot;
2008 0 : }
2009 :
2010 : /* Create a constant tree with value VALUE in type TYPE. */
2011 :
2012 : tree
2013 11146296972 : wide_int_to_tree (tree type, const poly_wide_int_ref &value)
2014 : {
2015 11146296972 : if (value.is_constant ())
2016 11146296972 : return wide_int_to_tree_1 (type, value.coeffs[0]);
2017 : return build_poly_int_cst (type, value);
2018 : }
2019 :
2020 : /* Insert INTEGER_CST T into a cache of integer constants. And return
2021 : the cached constant (which may or may not be T). If MIGHT_DUPLICATE
2022 : is false, and T falls into the type's 'smaller values' range, there
2023 : cannot be an existing entry. Otherwise, if MIGHT_DUPLICATE is true,
2024 : or the value is large, should an existing entry exist, it is
2025 : returned (rather than inserting T). */
2026 :
2027 : tree
2028 642265 : cache_integer_cst (tree t, bool might_duplicate ATTRIBUTE_UNUSED)
2029 : {
2030 642265 : tree type = TREE_TYPE (t);
2031 642265 : int ix = -1;
2032 642265 : int limit = 0;
2033 642265 : int prec = TYPE_PRECISION (type);
2034 :
2035 642265 : gcc_assert (!TREE_OVERFLOW (t));
2036 :
2037 : /* The caching indices here must match those in
2038 : wide_int_to_type_1. */
2039 642265 : switch (TREE_CODE (type))
2040 : {
2041 : /* This could represent the C++ std::meta::info type. */
2042 2 : case LANG_TYPE:
2043 2 : case NULLPTR_TYPE:
2044 2 : gcc_checking_assert (integer_zerop (t));
2045 : /* Fallthru. */
2046 :
2047 4997 : case POINTER_TYPE:
2048 4997 : case REFERENCE_TYPE:
2049 4997 : {
2050 4997 : if (integer_zerop (t))
2051 : ix = 0;
2052 1981 : else if (integer_onep (t))
2053 : ix = 2;
2054 :
2055 : if (ix >= 0)
2056 : limit = 3;
2057 : }
2058 : break;
2059 :
2060 10985 : case BOOLEAN_TYPE:
2061 : /* Cache false or true. */
2062 10985 : limit = 2;
2063 10985 : if (wi::ltu_p (wi::to_wide (t), 2))
2064 0 : ix = TREE_INT_CST_ELT (t, 0);
2065 : break;
2066 :
2067 611185 : case INTEGER_TYPE:
2068 611185 : case OFFSET_TYPE:
2069 611185 : case BITINT_TYPE:
2070 611185 : if (TYPE_UNSIGNED (type))
2071 : {
2072 : /* Cache 0..N */
2073 454139 : limit = param_integer_share_limit;
2074 :
2075 : /* This is a little hokie, but if the prec is smaller than
2076 : what is necessary to hold param_integer_share_limit, then the
2077 : obvious test will not get the correct answer. */
2078 454139 : if (prec < HOST_BITS_PER_WIDE_INT)
2079 : {
2080 96294 : if (tree_to_uhwi (t)
2081 96294 : < (unsigned HOST_WIDE_INT) param_integer_share_limit)
2082 16667 : ix = tree_to_uhwi (t);
2083 : }
2084 357845 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2085 279065 : ix = tree_to_uhwi (t);
2086 : }
2087 : else
2088 : {
2089 : /* Cache -1..N */
2090 157046 : limit = param_integer_share_limit + 1;
2091 :
2092 157046 : if (integer_minus_onep (t))
2093 : ix = 0;
2094 156586 : else if (!wi::neg_p (wi::to_wide (t)))
2095 : {
2096 138834 : if (prec < HOST_BITS_PER_WIDE_INT)
2097 : {
2098 132137 : if (tree_to_shwi (t) < param_integer_share_limit)
2099 123049 : ix = tree_to_shwi (t) + 1;
2100 : }
2101 6697 : else if (wi::ltu_p (wi::to_wide (t), param_integer_share_limit))
2102 5450 : ix = tree_to_shwi (t) + 1;
2103 : }
2104 : }
2105 : break;
2106 :
2107 : case ENUMERAL_TYPE:
2108 : /* The slot used by TYPE_CACHED_VALUES is used for the enum
2109 : members. */
2110 : break;
2111 :
2112 0 : default:
2113 0 : gcc_unreachable ();
2114 : }
2115 :
2116 427247 : if (ix >= 0)
2117 : {
2118 : /* Look for it in the type's vector of small shared ints. */
2119 428232 : if (!TYPE_CACHED_VALUES_P (type))
2120 : {
2121 14577 : TYPE_CACHED_VALUES_P (type) = 1;
2122 14577 : TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
2123 : }
2124 :
2125 428232 : if (tree r = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix))
2126 : {
2127 402321 : gcc_checking_assert (might_duplicate);
2128 402321 : t = r;
2129 : }
2130 : else
2131 25911 : TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
2132 : }
2133 : else
2134 : {
2135 : /* Use the cache of larger shared ints. */
2136 214033 : tree *slot = int_cst_hash_table->find_slot (t, INSERT);
2137 214033 : if (tree r = *slot)
2138 : {
2139 : /* If there is already an entry for the number verify it's the
2140 : same value. */
2141 126101 : gcc_checking_assert (wi::to_wide (tree (r)) == wi::to_wide (t));
2142 : /* And return the cached value. */
2143 126101 : t = r;
2144 : }
2145 : else
2146 : /* Otherwise insert this one into the hash table. */
2147 87932 : *slot = t;
2148 : }
2149 :
2150 642265 : return t;
2151 : }
2152 :
2153 :
2154 : /* Builds an integer constant in TYPE such that lowest BITS bits are ones
2155 : and the rest are zeros. */
2156 :
2157 : tree
2158 10177191 : build_low_bits_mask (tree type, unsigned bits)
2159 : {
2160 10177191 : gcc_assert (bits <= TYPE_PRECISION (type));
2161 :
2162 10177191 : return wide_int_to_tree (type, wi::mask (bits, false,
2163 10177191 : TYPE_PRECISION (type)));
2164 : }
2165 :
2166 : /* Checks that X is integer constant that can be expressed in (unsigned)
2167 : HOST_WIDE_INT without loss of precision. */
2168 :
2169 : bool
2170 801392903 : cst_and_fits_in_hwi (const_tree x)
2171 : {
2172 801392903 : return (TREE_CODE (x) == INTEGER_CST
2173 801392903 : && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
2174 : }
2175 :
2176 : /* Build a newly constructed VECTOR_CST with the given values of
2177 : (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN. */
2178 :
2179 : tree
2180 3489114 : make_vector (unsigned log2_npatterns,
2181 : unsigned int nelts_per_pattern MEM_STAT_DECL)
2182 : {
2183 3489114 : gcc_assert (IN_RANGE (nelts_per_pattern, 1, 3));
2184 3489114 : tree t;
2185 3489114 : unsigned npatterns = 1 << log2_npatterns;
2186 3489114 : unsigned encoded_nelts = npatterns * nelts_per_pattern;
2187 3489114 : unsigned length = (sizeof (struct tree_vector)
2188 : + (encoded_nelts - 1) * sizeof (tree));
2189 :
2190 3489114 : record_node_allocation_statistics (VECTOR_CST, length);
2191 :
2192 3489114 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2193 :
2194 3489114 : TREE_SET_CODE (t, VECTOR_CST);
2195 3489114 : TREE_CONSTANT (t) = 1;
2196 3489114 : VECTOR_CST_LOG2_NPATTERNS (t) = log2_npatterns;
2197 3489114 : VECTOR_CST_NELTS_PER_PATTERN (t) = nelts_per_pattern;
2198 :
2199 3489114 : return t;
2200 : }
2201 :
2202 : /* Return a new VECTOR_CST node whose type is TYPE and whose values
2203 : are extracted from V, a vector of CONSTRUCTOR_ELT. */
2204 :
2205 : tree
2206 690166 : build_vector_from_ctor (tree type, const vec<constructor_elt, va_gc> *v)
2207 : {
2208 690166 : if (vec_safe_length (v) == 0)
2209 2052 : return build_zero_cst (type);
2210 :
2211 688114 : unsigned HOST_WIDE_INT idx, npatterns, nelts_per_pattern;
2212 688114 : tree value;
2213 :
2214 : /* If the vector is a VLA, build a VLA constant vector. */
2215 688114 : npatterns = constant_lower_bound (TYPE_VECTOR_SUBPARTS (type));
2216 688114 : nelts_per_pattern = TYPE_VECTOR_SUBPARTS (type).is_constant () ? 1 : 2;
2217 688114 : gcc_assert (vec_safe_length (v) <= npatterns);
2218 :
2219 688114 : tree_vector_builder vec (type, npatterns, nelts_per_pattern);
2220 5246487 : FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
2221 : {
2222 3870259 : if (TREE_CODE (value) == VECTOR_CST)
2223 : {
2224 : /* If NPATTERNS is constant then this must be too. */
2225 4908 : unsigned int sub_nelts = VECTOR_CST_NELTS (value).to_constant ();
2226 19972 : for (unsigned i = 0; i < sub_nelts; ++i)
2227 15064 : vec.quick_push (VECTOR_CST_ELT (value, i));
2228 : }
2229 : else
2230 3865351 : vec.quick_push (value);
2231 : }
2232 1946896 : while (vec.length () < npatterns * nelts_per_pattern)
2233 285334 : vec.quick_push (build_zero_cst (TREE_TYPE (type)));
2234 :
2235 688114 : return vec.build ();
2236 688114 : }
2237 :
2238 : /* Build a vector of type VECTYPE where all the elements are SCs. */
2239 : tree
2240 667745 : build_vector_from_val (tree vectype, tree sc)
2241 : {
2242 667745 : unsigned HOST_WIDE_INT i, nunits;
2243 :
2244 667745 : if (sc == error_mark_node)
2245 : return sc;
2246 :
2247 : /* Verify that the vector type is suitable for SC. Note that there
2248 : is some inconsistency in the type-system with respect to restrict
2249 : qualifications of pointers. Vector types always have a main-variant
2250 : element type and the qualification is applied to the vector-type.
2251 : So TREE_TYPE (vector-type) does not return a properly qualified
2252 : vector element-type. */
2253 667745 : gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
2254 : TREE_TYPE (vectype)));
2255 :
2256 667745 : if (CONSTANT_CLASS_P (sc))
2257 : {
2258 636370 : tree_vector_builder v (vectype, 1, 1);
2259 636370 : v.quick_push (sc);
2260 636370 : return v.build ();
2261 636370 : }
2262 31375 : else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
2263 : return fold_build1 (VEC_DUPLICATE_EXPR, vectype, sc);
2264 : else
2265 : {
2266 31375 : vec<constructor_elt, va_gc> *v;
2267 31375 : vec_alloc (v, nunits);
2268 181786 : for (i = 0; i < nunits; ++i)
2269 119036 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
2270 31375 : return build_constructor (vectype, v);
2271 : }
2272 : }
2273 :
2274 : /* If TYPE is not a vector type, just return SC, otherwise return
2275 : build_vector_from_val (TYPE, SC). */
2276 :
2277 : tree
2278 5583182 : build_uniform_cst (tree type, tree sc)
2279 : {
2280 5583182 : if (!VECTOR_TYPE_P (type))
2281 : return sc;
2282 :
2283 372 : return build_vector_from_val (type, sc);
2284 : }
2285 :
2286 : /* Build a vector series of type TYPE in which element I has the value
2287 : BASE + I * STEP. The result is a constant if BASE and STEP are constant
2288 : and a VEC_SERIES_EXPR otherwise. */
2289 :
2290 : tree
2291 21 : build_vec_series (tree type, tree base, tree step)
2292 : {
2293 21 : if (integer_zerop (step))
2294 0 : return build_vector_from_val (type, base);
2295 21 : if (TREE_CODE (base) == INTEGER_CST && TREE_CODE (step) == INTEGER_CST)
2296 : {
2297 21 : tree_vector_builder builder (type, 1, 3);
2298 21 : tree elt1 = wide_int_to_tree (TREE_TYPE (base),
2299 42 : wi::to_wide (base) + wi::to_wide (step));
2300 21 : tree elt2 = wide_int_to_tree (TREE_TYPE (base),
2301 42 : wi::to_wide (elt1) + wi::to_wide (step));
2302 21 : builder.quick_push (base);
2303 21 : builder.quick_push (elt1);
2304 21 : builder.quick_push (elt2);
2305 21 : return builder.build ();
2306 21 : }
2307 0 : return build2 (VEC_SERIES_EXPR, type, base, step);
2308 : }
2309 :
2310 : /* Return a vector with the same number of units and number of bits
2311 : as VEC_TYPE, but in which the elements are a linear series of unsigned
2312 : integers { BASE, BASE + STEP, BASE + STEP * 2, ... }. */
2313 :
2314 : tree
2315 1810 : build_index_vector (tree vec_type, poly_uint64 base, poly_uint64 step)
2316 : {
2317 1810 : tree index_vec_type = vec_type;
2318 1810 : tree index_elt_type = TREE_TYPE (vec_type);
2319 1810 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vec_type);
2320 1810 : if (!INTEGRAL_TYPE_P (index_elt_type) || !TYPE_UNSIGNED (index_elt_type))
2321 : {
2322 4 : index_elt_type = build_nonstandard_integer_type
2323 8 : (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type)), true);
2324 4 : index_vec_type = build_vector_type (index_elt_type, nunits);
2325 : }
2326 :
2327 1810 : tree_vector_builder v (index_vec_type, 1, 3);
2328 9050 : for (unsigned int i = 0; i < 3; ++i)
2329 5430 : v.quick_push (build_int_cstu (index_elt_type, base + i * step));
2330 1810 : return v.build ();
2331 1810 : }
2332 :
2333 : /* Return a VECTOR_CST of type VEC_TYPE in which the first NUM_A
2334 : elements are A and the rest are B. */
2335 :
2336 : tree
2337 0 : build_vector_a_then_b (tree vec_type, unsigned int num_a, tree a, tree b)
2338 : {
2339 0 : gcc_assert (known_le (num_a, TYPE_VECTOR_SUBPARTS (vec_type)));
2340 0 : unsigned int count = constant_lower_bound (TYPE_VECTOR_SUBPARTS (vec_type));
2341 : /* Optimize the constant case. */
2342 0 : if ((count & 1) == 0 && TYPE_VECTOR_SUBPARTS (vec_type).is_constant ())
2343 0 : count /= 2;
2344 0 : tree_vector_builder builder (vec_type, count, 2);
2345 0 : for (unsigned int i = 0; i < count * 2; ++i)
2346 0 : builder.quick_push (i < num_a ? a : b);
2347 0 : return builder.build ();
2348 0 : }
2349 :
2350 : /* Something has messed with the elements of CONSTRUCTOR C after it was built;
2351 : calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
2352 :
2353 : void
2354 168793420 : recompute_constructor_flags (tree c)
2355 : {
2356 168793420 : unsigned int i;
2357 168793420 : tree val;
2358 168793420 : bool constant_p = true;
2359 168793420 : bool side_effects_p = false;
2360 168793420 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2361 :
2362 351667274 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2363 : {
2364 : /* Mostly ctors will have elts that don't have side-effects, so
2365 : the usual case is to scan all the elements. Hence a single
2366 : loop for both const and side effects, rather than one loop
2367 : each (with early outs). */
2368 182873854 : if (!TREE_CONSTANT (val))
2369 22753142 : constant_p = false;
2370 182873854 : if (TREE_SIDE_EFFECTS (val))
2371 4708130 : side_effects_p = true;
2372 : }
2373 :
2374 168793420 : TREE_SIDE_EFFECTS (c) = side_effects_p;
2375 168793420 : TREE_CONSTANT (c) = constant_p;
2376 168793420 : }
2377 :
2378 : /* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
2379 : CONSTRUCTOR C. */
2380 :
2381 : void
2382 20050742 : verify_constructor_flags (tree c)
2383 : {
2384 20050742 : unsigned int i;
2385 20050742 : tree val;
2386 20050742 : bool constant_p = TREE_CONSTANT (c);
2387 20050742 : bool side_effects_p = TREE_SIDE_EFFECTS (c);
2388 20050742 : vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
2389 :
2390 176534513 : FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
2391 : {
2392 156483771 : if (constant_p && !TREE_CONSTANT (val))
2393 0 : internal_error ("non-constant element in constant CONSTRUCTOR");
2394 156483771 : if (!side_effects_p && TREE_SIDE_EFFECTS (val))
2395 0 : internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
2396 : }
2397 20050742 : }
2398 :
2399 : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2400 : are in the vec pointed to by VALS. */
2401 : tree
2402 143883099 : build_constructor (tree type, vec<constructor_elt, va_gc> *vals MEM_STAT_DECL)
2403 : {
2404 143883099 : tree c = make_node (CONSTRUCTOR PASS_MEM_STAT);
2405 :
2406 143883099 : TREE_TYPE (c) = type;
2407 143883099 : CONSTRUCTOR_ELTS (c) = vals;
2408 :
2409 143883099 : recompute_constructor_flags (c);
2410 :
2411 143883099 : return c;
2412 : }
2413 :
2414 : /* Build a CONSTRUCTOR node made of a single initializer, with the specified
2415 : INDEX and VALUE. */
2416 : tree
2417 7067 : build_constructor_single (tree type, tree index, tree value)
2418 : {
2419 7067 : vec<constructor_elt, va_gc> *v;
2420 7067 : constructor_elt elt = {index, value};
2421 :
2422 7067 : vec_alloc (v, 1);
2423 7067 : v->quick_push (elt);
2424 :
2425 7067 : return build_constructor (type, v);
2426 : }
2427 :
2428 :
2429 : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2430 : are in a list pointed to by VALS. */
2431 : tree
2432 1013 : build_constructor_from_list (tree type, tree vals)
2433 : {
2434 1013 : tree t;
2435 1013 : vec<constructor_elt, va_gc> *v = NULL;
2436 :
2437 1013 : if (vals)
2438 : {
2439 1013 : vec_alloc (v, list_length (vals));
2440 21849 : for (t = vals; t; t = TREE_CHAIN (t))
2441 19823 : CONSTRUCTOR_APPEND_ELT (v, TREE_PURPOSE (t), TREE_VALUE (t));
2442 : }
2443 :
2444 1013 : return build_constructor (type, v);
2445 : }
2446 :
2447 : /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
2448 : are in a vector pointed to by VALS. Note that the TREE_PURPOSE
2449 : fields in the constructor remain null. */
2450 :
2451 : tree
2452 1617 : build_constructor_from_vec (tree type, const vec<tree, va_gc> *vals)
2453 : {
2454 1617 : vec<constructor_elt, va_gc> *v = NULL;
2455 :
2456 75520 : for (tree t : vals)
2457 73903 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t);
2458 :
2459 1617 : return build_constructor (type, v);
2460 : }
2461 :
2462 : /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
2463 : of elements, provided as index/value pairs. */
2464 :
2465 : tree
2466 39904 : build_constructor_va (tree type, int nelts, ...)
2467 : {
2468 39904 : vec<constructor_elt, va_gc> *v = NULL;
2469 39904 : va_list p;
2470 :
2471 39904 : va_start (p, nelts);
2472 39904 : vec_alloc (v, nelts);
2473 39904 : while (nelts--)
2474 : {
2475 121290 : tree index = va_arg (p, tree);
2476 121290 : tree value = va_arg (p, tree);
2477 282484 : CONSTRUCTOR_APPEND_ELT (v, index, value);
2478 : }
2479 39904 : va_end (p);
2480 39904 : return build_constructor (type, v);
2481 : }
2482 :
2483 : /* Return a node of type TYPE for which TREE_CLOBBER_P is true. */
2484 :
2485 : tree
2486 10197899 : build_clobber (tree type, enum clobber_kind kind)
2487 : {
2488 10197899 : tree clobber = build_constructor (type, NULL);
2489 10197899 : TREE_THIS_VOLATILE (clobber) = true;
2490 10197899 : CLOBBER_KIND (clobber) = kind;
2491 10197899 : return clobber;
2492 : }
2493 :
2494 : /* Return a new FIXED_CST node whose type is TYPE and value is F. */
2495 :
2496 : tree
2497 54 : build_fixed (tree type, FIXED_VALUE_TYPE f)
2498 : {
2499 54 : tree v;
2500 54 : FIXED_VALUE_TYPE *fp;
2501 :
2502 54 : v = make_node (FIXED_CST);
2503 54 : fp = ggc_alloc<fixed_value> ();
2504 54 : memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
2505 :
2506 54 : TREE_TYPE (v) = type;
2507 54 : TREE_FIXED_CST_PTR (v) = fp;
2508 54 : return v;
2509 : }
2510 :
2511 : /* Return a new REAL_CST node whose type is TYPE and value is D. */
2512 :
2513 : tree
2514 43798553 : build_real (tree type, REAL_VALUE_TYPE d)
2515 : {
2516 43798553 : tree v;
2517 43798553 : int overflow = 0;
2518 :
2519 : /* dconst{0,1,2,m1,half} are used in various places in
2520 : the middle-end and optimizers, allow them here
2521 : even for decimal floating point types as an exception
2522 : by converting them to decimal. */
2523 43798553 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))
2524 610641 : && (d.cl == rvc_normal || d.cl == rvc_zero)
2525 44406996 : && !d.decimal)
2526 : {
2527 610 : if (memcmp (&d, &dconst1, sizeof (d)) == 0)
2528 0 : decimal_real_from_string (&d, "1");
2529 610 : else if (memcmp (&d, &dconst2, sizeof (d)) == 0)
2530 22 : decimal_real_from_string (&d, "2");
2531 588 : else if (memcmp (&d, &dconstm1, sizeof (d)) == 0)
2532 90 : decimal_real_from_string (&d, "-1");
2533 498 : else if (memcmp (&d, &dconsthalf, sizeof (d)) == 0)
2534 0 : decimal_real_from_string (&d, "0.5");
2535 498 : else if (memcmp (&d, &dconst0, sizeof (d)) == 0)
2536 : {
2537 : /* Make sure to give zero the minimum quantum exponent for
2538 : the type (which corresponds to all bits zero). */
2539 498 : const struct real_format *fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
2540 498 : char buf[16];
2541 498 : sprintf (buf, "0e%d", fmt->emin - fmt->p);
2542 498 : decimal_real_from_string (&d, buf);
2543 : }
2544 : else
2545 0 : gcc_unreachable ();
2546 : }
2547 :
2548 : /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
2549 : Consider doing it via real_convert now. */
2550 :
2551 43798553 : v = make_node (REAL_CST);
2552 43798553 : TREE_TYPE (v) = type;
2553 43798553 : memcpy (TREE_REAL_CST_PTR (v), &d, sizeof (REAL_VALUE_TYPE));
2554 43798553 : TREE_OVERFLOW (v) = overflow;
2555 43798553 : return v;
2556 : }
2557 :
2558 : /* Like build_real, but first truncate D to the type. */
2559 :
2560 : tree
2561 176686 : build_real_truncate (tree type, REAL_VALUE_TYPE d)
2562 : {
2563 176686 : return build_real (type, real_value_truncate (TYPE_MODE (type), d));
2564 : }
2565 :
2566 : /* Return a new REAL_CST node whose type is TYPE
2567 : and whose value is the integer value of the INTEGER_CST node I. */
2568 :
2569 : REAL_VALUE_TYPE
2570 24997667 : real_value_from_int_cst (const_tree type, const_tree i)
2571 : {
2572 24997667 : REAL_VALUE_TYPE d;
2573 :
2574 : /* Clear all bits of the real value type so that we can later do
2575 : bitwise comparisons to see if two values are the same. */
2576 24997667 : memset (&d, 0, sizeof d);
2577 :
2578 24997667 : real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, wi::to_wide (i),
2579 24997667 : TYPE_SIGN (TREE_TYPE (i)));
2580 24997667 : return d;
2581 : }
2582 :
2583 : /* Given a tree representing an integer constant I, return a tree
2584 : representing the same value as a floating-point constant of type TYPE. */
2585 :
2586 : tree
2587 24326422 : build_real_from_int_cst (tree type, const_tree i)
2588 : {
2589 24326422 : tree v;
2590 24326422 : int overflow = TREE_OVERFLOW (i);
2591 :
2592 24326422 : v = build_real (type, real_value_from_int_cst (type, i));
2593 :
2594 24326422 : TREE_OVERFLOW (v) |= overflow;
2595 24326422 : return v;
2596 : }
2597 :
2598 : /* Return a new REAL_CST node whose type is TYPE
2599 : and whose value is the integer value I which has sign SGN. */
2600 :
2601 : tree
2602 138 : build_real_from_wide (tree type, const wide_int_ref &i, signop sgn)
2603 : {
2604 138 : REAL_VALUE_TYPE d;
2605 :
2606 : /* Clear all bits of the real value type so that we can later do
2607 : bitwise comparisons to see if two values are the same. */
2608 138 : memset (&d, 0, sizeof d);
2609 :
2610 138 : real_from_integer (&d, TYPE_MODE (type), i, sgn);
2611 138 : return build_real (type, d);
2612 : }
2613 :
2614 : /* Return a newly constructed STRING_CST node whose value is the LEN
2615 : characters at STR when STR is nonnull, or all zeros otherwise.
2616 : Note that for a C string literal, LEN should include the trailing NUL.
2617 : The TREE_TYPE is not initialized. */
2618 :
2619 : tree
2620 101697204 : build_string (unsigned len, const char *str /*= NULL */)
2621 : {
2622 : /* Do not waste bytes provided by padding of struct tree_string. */
2623 101697204 : unsigned size = len + offsetof (struct tree_string, str) + 1;
2624 :
2625 101697204 : record_node_allocation_statistics (STRING_CST, size);
2626 :
2627 101697204 : tree s = (tree) ggc_internal_alloc (size);
2628 :
2629 101697204 : memset (s, 0, sizeof (struct tree_typed));
2630 101697204 : TREE_SET_CODE (s, STRING_CST);
2631 101697204 : TREE_CONSTANT (s) = 1;
2632 101697204 : TREE_STRING_LENGTH (s) = len;
2633 101697204 : if (str)
2634 101688037 : memcpy (s->string.str, str, len);
2635 : else
2636 9167 : memset (s->string.str, 0, len);
2637 101697204 : s->string.str[len] = '\0';
2638 :
2639 101697204 : return s;
2640 : }
2641 :
2642 : /* Return a newly constructed COMPLEX_CST node whose value is
2643 : specified by the real and imaginary parts REAL and IMAG.
2644 : Both REAL and IMAG should be constant nodes. TYPE, if specified,
2645 : will be the type of the COMPLEX_CST; otherwise a new type will be made. */
2646 :
2647 : tree
2648 488030 : build_complex (tree type, tree real, tree imag)
2649 : {
2650 488030 : gcc_assert (CONSTANT_CLASS_P (real));
2651 488030 : gcc_assert (CONSTANT_CLASS_P (imag));
2652 :
2653 488030 : tree t = make_node (COMPLEX_CST);
2654 :
2655 488030 : TREE_REALPART (t) = real;
2656 488030 : TREE_IMAGPART (t) = imag;
2657 488030 : TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
2658 488030 : TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
2659 488030 : return t;
2660 : }
2661 :
2662 : /* Build a complex (inf +- 0i), such as for the result of cproj.
2663 : TYPE is the complex tree type of the result. If NEG is true, the
2664 : imaginary zero is negative. */
2665 :
2666 : tree
2667 840 : build_complex_inf (tree type, bool neg)
2668 : {
2669 840 : REAL_VALUE_TYPE rzero = dconst0;
2670 :
2671 840 : rzero.sign = neg;
2672 840 : return build_complex (type, build_real (TREE_TYPE (type), dconstinf),
2673 840 : build_real (TREE_TYPE (type), rzero));
2674 : }
2675 :
2676 : /* Return the constant 1 in type TYPE. If TYPE has several elements, each
2677 : element is set to 1. In particular, this is 1 + i for complex types. */
2678 :
2679 : tree
2680 3766 : build_each_one_cst (tree type)
2681 : {
2682 3766 : if (TREE_CODE (type) == COMPLEX_TYPE)
2683 : {
2684 0 : tree scalar = build_one_cst (TREE_TYPE (type));
2685 0 : return build_complex (type, scalar, scalar);
2686 : }
2687 : else
2688 3766 : return build_one_cst (type);
2689 : }
2690 :
2691 : /* Return a constant of arithmetic type TYPE which is the
2692 : multiplicative identity of the set TYPE. */
2693 :
2694 : tree
2695 10077235 : build_one_cst (tree type)
2696 : {
2697 10077235 : switch (TREE_CODE (type))
2698 : {
2699 10062920 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2700 10062920 : case POINTER_TYPE: case REFERENCE_TYPE:
2701 10062920 : case OFFSET_TYPE: case BITINT_TYPE:
2702 10062920 : return build_int_cst (type, 1);
2703 :
2704 10707 : case REAL_TYPE:
2705 10707 : return build_real (type, dconst1);
2706 :
2707 0 : case FIXED_POINT_TYPE:
2708 : /* We can only generate 1 for accum types. */
2709 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2710 0 : return build_fixed (type, FCONST1 (TYPE_MODE (type)));
2711 :
2712 589 : case VECTOR_TYPE:
2713 589 : {
2714 589 : tree scalar = build_one_cst (TREE_TYPE (type));
2715 :
2716 589 : return build_vector_from_val (type, scalar);
2717 : }
2718 :
2719 3019 : case COMPLEX_TYPE:
2720 6038 : return build_complex (type,
2721 3019 : build_one_cst (TREE_TYPE (type)),
2722 6038 : build_zero_cst (TREE_TYPE (type)));
2723 :
2724 0 : default:
2725 0 : gcc_unreachable ();
2726 : }
2727 : }
2728 :
2729 : /* Return an integer of type TYPE containing all 1's in as much precision as
2730 : it contains, or a complex or vector whose subparts are such integers. */
2731 :
2732 : tree
2733 1723046 : build_all_ones_cst (tree type)
2734 : {
2735 1723046 : if (TREE_CODE (type) == COMPLEX_TYPE)
2736 : {
2737 0 : tree scalar = build_all_ones_cst (TREE_TYPE (type));
2738 0 : return build_complex (type, scalar, scalar);
2739 : }
2740 : else
2741 1723046 : return build_minus_one_cst (type);
2742 : }
2743 :
2744 : /* Return a constant of arithmetic type TYPE which is the
2745 : opposite of the multiplicative identity of the set TYPE. */
2746 :
2747 : tree
2748 3136748 : build_minus_one_cst (tree type)
2749 : {
2750 3136748 : switch (TREE_CODE (type))
2751 : {
2752 3011744 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2753 3011744 : case POINTER_TYPE: case REFERENCE_TYPE:
2754 3011744 : case OFFSET_TYPE: case BITINT_TYPE:
2755 3011744 : return build_int_cst (type, -1);
2756 :
2757 14828 : case REAL_TYPE:
2758 14828 : return build_real (type, dconstm1);
2759 :
2760 0 : case FIXED_POINT_TYPE:
2761 : /* We can only generate 1 for accum types. */
2762 0 : gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
2763 0 : return build_fixed (type,
2764 : fixed_from_double_int (double_int_minus_one,
2765 0 : SCALAR_TYPE_MODE (type)));
2766 :
2767 110176 : case VECTOR_TYPE:
2768 110176 : {
2769 110176 : tree scalar = build_minus_one_cst (TREE_TYPE (type));
2770 :
2771 110176 : return build_vector_from_val (type, scalar);
2772 : }
2773 :
2774 0 : case COMPLEX_TYPE:
2775 0 : return build_complex (type,
2776 0 : build_minus_one_cst (TREE_TYPE (type)),
2777 0 : build_zero_cst (TREE_TYPE (type)));
2778 :
2779 0 : default:
2780 0 : gcc_unreachable ();
2781 : }
2782 : }
2783 :
2784 : /* Build 0 constant of type TYPE. This is used by constructor folding
2785 : and thus the constant should be represented in memory by
2786 : zero(es). */
2787 :
2788 : tree
2789 98917477 : build_zero_cst (tree type)
2790 : {
2791 98917477 : switch (TREE_CODE (type))
2792 : {
2793 98324903 : case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
2794 98324903 : case POINTER_TYPE: case REFERENCE_TYPE:
2795 98324903 : case OFFSET_TYPE: case NULLPTR_TYPE: case BITINT_TYPE:
2796 98324903 : return build_int_cst (type, 0);
2797 :
2798 226487 : case REAL_TYPE:
2799 226487 : return build_real (type, dconst0);
2800 :
2801 0 : case FIXED_POINT_TYPE:
2802 0 : return build_fixed (type, FCONST0 (TYPE_MODE (type)));
2803 :
2804 177760 : case VECTOR_TYPE:
2805 177760 : {
2806 177760 : tree scalar = build_zero_cst (TREE_TYPE (type));
2807 :
2808 177760 : return build_vector_from_val (type, scalar);
2809 : }
2810 :
2811 2083 : case COMPLEX_TYPE:
2812 2083 : {
2813 2083 : tree zero = build_zero_cst (TREE_TYPE (type));
2814 :
2815 2083 : return build_complex (type, zero, zero);
2816 : }
2817 :
2818 186244 : default:
2819 186244 : if (!AGGREGATE_TYPE_P (type))
2820 1 : return fold_convert (type, integer_zero_node);
2821 186243 : return build_constructor (type, NULL);
2822 : }
2823 : }
2824 :
2825 : /* Build a constant of integer type TYPE, made of VALUE's bits replicated
2826 : every WIDTH bits to fit TYPE's precision. */
2827 :
2828 : tree
2829 14 : build_replicated_int_cst (tree type, unsigned int width, HOST_WIDE_INT value)
2830 : {
2831 14 : int n = ((TYPE_PRECISION (type) + HOST_BITS_PER_WIDE_INT - 1)
2832 14 : / HOST_BITS_PER_WIDE_INT);
2833 14 : unsigned HOST_WIDE_INT low, mask;
2834 14 : HOST_WIDE_INT a[WIDE_INT_MAX_INL_ELTS];
2835 14 : int i;
2836 :
2837 14 : gcc_assert (n && n <= WIDE_INT_MAX_INL_ELTS);
2838 :
2839 14 : if (width == HOST_BITS_PER_WIDE_INT)
2840 0 : low = value;
2841 : else
2842 : {
2843 14 : mask = (HOST_WIDE_INT_1U << width) - 1;
2844 14 : low = (unsigned HOST_WIDE_INT) ~0 / mask * (value & mask);
2845 : }
2846 :
2847 28 : for (i = 0; i < n; i++)
2848 14 : a[i] = low;
2849 :
2850 14 : gcc_assert (TYPE_PRECISION (type) <= MAX_BITSIZE_MODE_ANY_INT);
2851 14 : return wide_int_to_tree (type, wide_int::from_array (a, n,
2852 14 : TYPE_PRECISION (type)));
2853 : }
2854 :
2855 : /* If floating-point type TYPE has an IEEE-style sign bit, return an
2856 : unsigned constant in which only the sign bit is set. Return null
2857 : otherwise. */
2858 :
2859 : tree
2860 0 : sign_mask_for (tree type)
2861 : {
2862 : /* Avoid having to choose between a real-only sign and a pair of signs.
2863 : This could be relaxed if the choice becomes obvious later. */
2864 0 : if (TREE_CODE (type) == COMPLEX_TYPE)
2865 : return NULL_TREE;
2866 :
2867 0 : auto eltmode = as_a<scalar_float_mode> (element_mode (type));
2868 0 : auto bits = REAL_MODE_FORMAT (eltmode)->ieee_bits;
2869 0 : if (!bits || !pow2p_hwi (bits))
2870 : return NULL_TREE;
2871 :
2872 0 : tree inttype = unsigned_type_for (type);
2873 0 : if (!inttype)
2874 : return NULL_TREE;
2875 :
2876 0 : auto mask = wi::set_bit_in_zero (bits - 1, bits);
2877 0 : if (VECTOR_TYPE_P (inttype))
2878 : {
2879 0 : tree elt = wide_int_to_tree (TREE_TYPE (inttype), mask);
2880 0 : return build_vector_from_val (inttype, elt);
2881 : }
2882 0 : return wide_int_to_tree (inttype, mask);
2883 0 : }
2884 :
2885 : /* Build a BINFO with LEN language slots. */
2886 :
2887 : tree
2888 112912130 : make_tree_binfo (unsigned base_binfos MEM_STAT_DECL)
2889 : {
2890 112912130 : tree t;
2891 112912130 : size_t length = (offsetof (struct tree_binfo, base_binfos)
2892 112912130 : + vec<tree, va_gc>::embedded_size (base_binfos));
2893 :
2894 112912130 : record_node_allocation_statistics (TREE_BINFO, length);
2895 :
2896 112912130 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
2897 :
2898 112912130 : memset (t, 0, offsetof (struct tree_binfo, base_binfos));
2899 :
2900 112912130 : TREE_SET_CODE (t, TREE_BINFO);
2901 :
2902 112912130 : BINFO_BASE_BINFOS (t)->embedded_init (base_binfos);
2903 :
2904 112912130 : return t;
2905 : }
2906 :
2907 : /* Create a CASE_LABEL_EXPR tree node and return it. */
2908 :
2909 : tree
2910 7182093 : build_case_label (tree low_value, tree high_value, tree label_decl)
2911 : {
2912 7182093 : tree t = make_node (CASE_LABEL_EXPR);
2913 :
2914 7182093 : TREE_TYPE (t) = void_type_node;
2915 7182093 : SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl));
2916 :
2917 7182093 : CASE_LOW (t) = low_value;
2918 7182093 : CASE_HIGH (t) = high_value;
2919 7182093 : CASE_LABEL (t) = label_decl;
2920 7182093 : CASE_CHAIN (t) = NULL_TREE;
2921 :
2922 7182093 : return t;
2923 : }
2924 :
2925 : /* Build a newly constructed INTEGER_CST node. LEN and EXT_LEN are the
2926 : values of TREE_INT_CST_NUNITS and TREE_INT_CST_EXT_NUNITS respectively.
2927 : The latter determines the length of the HOST_WIDE_INT vector. */
2928 :
2929 : tree
2930 295573303 : make_int_cst (int len, int ext_len MEM_STAT_DECL)
2931 : {
2932 295573303 : tree t;
2933 295573303 : int length = ((ext_len - 1) * sizeof (HOST_WIDE_INT)
2934 295573303 : + sizeof (struct tree_int_cst));
2935 :
2936 295573303 : gcc_assert (len);
2937 295573303 : record_node_allocation_statistics (INTEGER_CST, length);
2938 :
2939 295573303 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2940 :
2941 295573303 : TREE_SET_CODE (t, INTEGER_CST);
2942 295573303 : TREE_INT_CST_NUNITS (t) = len;
2943 295573303 : TREE_INT_CST_EXT_NUNITS (t) = ext_len;
2944 295573303 : TREE_CONSTANT (t) = 1;
2945 :
2946 295573303 : return t;
2947 : }
2948 :
2949 : /* Build a newly constructed TREE_VEC node of length LEN. */
2950 :
2951 : tree
2952 3407629749 : make_tree_vec (int len MEM_STAT_DECL)
2953 : {
2954 3407629749 : tree t;
2955 3407629749 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2956 :
2957 3407629749 : record_node_allocation_statistics (TREE_VEC, length);
2958 :
2959 3407629749 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2960 :
2961 3407629749 : TREE_SET_CODE (t, TREE_VEC);
2962 3407629749 : TREE_VEC_LENGTH (t) = len;
2963 :
2964 3407629749 : return t;
2965 : }
2966 :
2967 : /* Grow a TREE_VEC node to new length LEN. */
2968 :
2969 : tree
2970 541966 : grow_tree_vec (tree v, int len MEM_STAT_DECL)
2971 : {
2972 541966 : gcc_assert (TREE_CODE (v) == TREE_VEC);
2973 :
2974 541966 : int oldlen = TREE_VEC_LENGTH (v);
2975 541966 : gcc_assert (len > oldlen);
2976 :
2977 541966 : size_t oldlength = (oldlen - 1) * sizeof (tree) + sizeof (struct tree_vec);
2978 541966 : size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
2979 :
2980 541966 : record_node_allocation_statistics (TREE_VEC, length - oldlength);
2981 :
2982 541966 : v = (tree) ggc_realloc (v, length PASS_MEM_STAT);
2983 :
2984 541966 : TREE_VEC_LENGTH (v) = len;
2985 :
2986 541966 : return v;
2987 : }
2988 :
2989 : /* Return true if EXPR is the constant zero, whether it is integral, float or
2990 : fixed, and scalar, complex or vector. */
2991 :
2992 : bool
2993 18098043 : zerop (const_tree expr)
2994 : {
2995 18098043 : return (integer_zerop (expr)
2996 12531614 : || real_zerop (expr)
2997 30231661 : || fixed_zerop (expr));
2998 : }
2999 :
3000 : /* Return true if EXPR is the integer constant zero or a complex constant
3001 : of zero, or a location wrapper for such a constant. */
3002 :
3003 : bool
3004 7103834673 : integer_zerop (const_tree expr)
3005 : {
3006 7103834673 : STRIP_ANY_LOCATION_WRAPPER (expr);
3007 :
3008 7103834673 : switch (TREE_CODE (expr))
3009 : {
3010 5591763301 : case INTEGER_CST:
3011 5591763301 : return wi::to_wide (expr) == 0;
3012 1200884 : case COMPLEX_CST:
3013 1200884 : return (integer_zerop (TREE_REALPART (expr))
3014 1223474 : && integer_zerop (TREE_IMAGPART (expr)));
3015 3114988 : case VECTOR_CST:
3016 3114988 : return (VECTOR_CST_NPATTERNS (expr) == 1
3017 2941950 : && VECTOR_CST_DUPLICATE_P (expr)
3018 5593774 : && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
3019 : default:
3020 : return false;
3021 : }
3022 : }
3023 :
3024 : /* Return true if EXPR is the integer constant one or the corresponding
3025 : complex constant, or a location wrapper for such a constant. */
3026 :
3027 : bool
3028 1100650336 : integer_onep (const_tree expr)
3029 : {
3030 1100650336 : STRIP_ANY_LOCATION_WRAPPER (expr);
3031 :
3032 1100650336 : switch (TREE_CODE (expr))
3033 : {
3034 953307469 : case INTEGER_CST:
3035 953307469 : return wi::eq_p (wi::to_widest (expr), 1);
3036 21757 : case COMPLEX_CST:
3037 21757 : return (integer_onep (TREE_REALPART (expr))
3038 21809 : && integer_zerop (TREE_IMAGPART (expr)));
3039 203570 : case VECTOR_CST:
3040 203570 : return (VECTOR_CST_NPATTERNS (expr) == 1
3041 182165 : && VECTOR_CST_DUPLICATE_P (expr)
3042 361962 : && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3043 : default:
3044 : return false;
3045 : }
3046 : }
3047 :
3048 : /* Return true if EXPR is the integer constant one. For complex and vector,
3049 : return true if every piece is the integer constant one.
3050 : Also return true for location wrappers for such a constant. */
3051 :
3052 : bool
3053 773138 : integer_each_onep (const_tree expr)
3054 : {
3055 773138 : STRIP_ANY_LOCATION_WRAPPER (expr);
3056 :
3057 773138 : if (TREE_CODE (expr) == COMPLEX_CST)
3058 34 : return (integer_onep (TREE_REALPART (expr))
3059 48 : && integer_onep (TREE_IMAGPART (expr)));
3060 : else
3061 773104 : return integer_onep (expr);
3062 : }
3063 :
3064 : /* Return true if EXPR is an integer containing all 1's in as much precision
3065 : as it contains, or a complex or vector whose subparts are such integers,
3066 : or a location wrapper for such a constant. */
3067 :
3068 : bool
3069 300055271 : integer_all_onesp (const_tree expr)
3070 : {
3071 300055271 : STRIP_ANY_LOCATION_WRAPPER (expr);
3072 :
3073 300055271 : if (TREE_CODE (expr) == COMPLEX_CST
3074 937 : && integer_all_onesp (TREE_REALPART (expr))
3075 300055311 : && integer_all_onesp (TREE_IMAGPART (expr)))
3076 : return true;
3077 :
3078 300055235 : else if (TREE_CODE (expr) == VECTOR_CST)
3079 634585 : return (VECTOR_CST_NPATTERNS (expr) == 1
3080 581578 : && VECTOR_CST_DUPLICATE_P (expr)
3081 1191274 : && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
3082 :
3083 299420650 : else if (TREE_CODE (expr) != INTEGER_CST)
3084 : return false;
3085 :
3086 198772376 : return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED)
3087 397610848 : == wi::to_wide (expr));
3088 : }
3089 :
3090 : /* Return true if EXPR is the integer constant minus one, or a location
3091 : wrapper for such a constant. */
3092 :
3093 : bool
3094 219336008 : integer_minus_onep (const_tree expr)
3095 : {
3096 219336008 : STRIP_ANY_LOCATION_WRAPPER (expr);
3097 :
3098 219336008 : if (TREE_CODE (expr) == COMPLEX_CST)
3099 9421 : return (integer_all_onesp (TREE_REALPART (expr))
3100 9425 : && integer_zerop (TREE_IMAGPART (expr)));
3101 : else
3102 219326587 : return integer_all_onesp (expr);
3103 : }
3104 :
3105 : /* Return true if EXPR is an integer constant that is a power of 2 (i.e., has
3106 : only one bit on), or a location wrapper for such a constant. */
3107 :
3108 : bool
3109 22560577 : integer_pow2p (const_tree expr)
3110 : {
3111 22560577 : STRIP_ANY_LOCATION_WRAPPER (expr);
3112 :
3113 22560577 : if (TREE_CODE (expr) == COMPLEX_CST
3114 567 : && integer_pow2p (TREE_REALPART (expr))
3115 22560818 : && integer_zerop (TREE_IMAGPART (expr)))
3116 : return true;
3117 :
3118 22560410 : if (TREE_CODE (expr) != INTEGER_CST)
3119 : return false;
3120 :
3121 14168523 : return wi::popcount (wi::to_wide (expr)) == 1;
3122 : }
3123 :
3124 : /* Return true if EXPR is an integer constant other than zero or a
3125 : complex constant other than zero, or a location wrapper for such a
3126 : constant. */
3127 :
3128 : bool
3129 164676912 : integer_nonzerop (const_tree expr)
3130 : {
3131 164676912 : STRIP_ANY_LOCATION_WRAPPER (expr);
3132 :
3133 164676912 : return ((TREE_CODE (expr) == INTEGER_CST
3134 86290475 : && wi::to_wide (expr) != 0)
3135 193958163 : || (TREE_CODE (expr) == COMPLEX_CST
3136 244 : && (integer_nonzerop (TREE_REALPART (expr))
3137 184 : || integer_nonzerop (TREE_IMAGPART (expr)))));
3138 : }
3139 :
3140 : /* Return true if EXPR is the integer constant one. For vector,
3141 : return true if every piece is the integer constant minus one
3142 : (representing the value TRUE).
3143 : Also return true for location wrappers for such a constant. */
3144 :
3145 : bool
3146 1174968 : integer_truep (const_tree expr)
3147 : {
3148 1174968 : STRIP_ANY_LOCATION_WRAPPER (expr);
3149 :
3150 1174968 : if (TREE_CODE (expr) == VECTOR_CST)
3151 14805 : return integer_all_onesp (expr);
3152 1160163 : return integer_onep (expr);
3153 : }
3154 :
3155 : /* Return true if EXPR is the fixed-point constant zero, or a location wrapper
3156 : for such a constant. */
3157 :
3158 : bool
3159 29650804 : fixed_zerop (const_tree expr)
3160 : {
3161 29650804 : STRIP_ANY_LOCATION_WRAPPER (expr);
3162 :
3163 29650804 : return (TREE_CODE (expr) == FIXED_CST
3164 29650804 : && TREE_FIXED_CST (expr).data.is_zero ());
3165 : }
3166 :
3167 : /* Return the power of two represented by a tree node known to be a
3168 : power of two. */
3169 :
3170 : int
3171 790392 : tree_log2 (const_tree expr)
3172 : {
3173 790392 : if (TREE_CODE (expr) == COMPLEX_CST)
3174 0 : return tree_log2 (TREE_REALPART (expr));
3175 :
3176 790392 : return wi::exact_log2 (wi::to_wide (expr));
3177 : }
3178 :
3179 : /* Similar, but return the largest integer Y such that 2 ** Y is less
3180 : than or equal to EXPR. */
3181 :
3182 : int
3183 2994913 : tree_floor_log2 (const_tree expr)
3184 : {
3185 2994913 : if (TREE_CODE (expr) == COMPLEX_CST)
3186 0 : return tree_log2 (TREE_REALPART (expr));
3187 :
3188 2994913 : return wi::floor_log2 (wi::to_wide (expr));
3189 : }
3190 :
3191 : /* Return number of known trailing zero bits in EXPR, or, if the value of
3192 : EXPR is known to be zero, the precision of it's type. */
3193 :
3194 : unsigned int
3195 84484102 : tree_ctz (const_tree expr)
3196 : {
3197 168966494 : if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
3198 84492153 : && !POINTER_TYPE_P (TREE_TYPE (expr)))
3199 : return 0;
3200 :
3201 84484041 : unsigned int ret1, ret2, prec = TYPE_PRECISION (TREE_TYPE (expr));
3202 84484041 : switch (TREE_CODE (expr))
3203 : {
3204 45103777 : case INTEGER_CST:
3205 45103777 : ret1 = wi::ctz (wi::to_wide (expr));
3206 45103777 : return MIN (ret1, prec);
3207 12851578 : case SSA_NAME:
3208 12851578 : ret1 = wi::ctz (get_nonzero_bits (expr));
3209 12851578 : return MIN (ret1, prec);
3210 2086630 : case PLUS_EXPR:
3211 2086630 : case MINUS_EXPR:
3212 2086630 : case BIT_IOR_EXPR:
3213 2086630 : case BIT_XOR_EXPR:
3214 2086630 : case MIN_EXPR:
3215 2086630 : case MAX_EXPR:
3216 2086630 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3217 2086630 : if (ret1 == 0)
3218 : return ret1;
3219 954297 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3220 954297 : return MIN (ret1, ret2);
3221 0 : case POINTER_PLUS_EXPR:
3222 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3223 0 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3224 : /* Second operand is sizetype, which could be in theory
3225 : wider than pointer's precision. Make sure we never
3226 : return more than prec. */
3227 0 : ret2 = MIN (ret2, prec);
3228 0 : return MIN (ret1, ret2);
3229 234 : case BIT_AND_EXPR:
3230 234 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3231 234 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3232 234 : return MAX (ret1, ret2);
3233 11908355 : case MULT_EXPR:
3234 11908355 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3235 11908355 : ret2 = tree_ctz (TREE_OPERAND (expr, 1));
3236 11908355 : return MIN (ret1 + ret2, prec);
3237 0 : case LSHIFT_EXPR:
3238 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3239 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3240 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3241 : {
3242 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3243 0 : return MIN (ret1 + ret2, prec);
3244 : }
3245 : return ret1;
3246 0 : case RSHIFT_EXPR:
3247 0 : if (tree_fits_uhwi_p (TREE_OPERAND (expr, 1))
3248 0 : && (tree_to_uhwi (TREE_OPERAND (expr, 1)) < prec))
3249 : {
3250 0 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3251 0 : ret2 = tree_to_uhwi (TREE_OPERAND (expr, 1));
3252 0 : if (ret1 > ret2)
3253 0 : return ret1 - ret2;
3254 : }
3255 : return 0;
3256 6096 : case TRUNC_DIV_EXPR:
3257 6096 : case CEIL_DIV_EXPR:
3258 6096 : case FLOOR_DIV_EXPR:
3259 6096 : case ROUND_DIV_EXPR:
3260 6096 : case EXACT_DIV_EXPR:
3261 6096 : if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
3262 6096 : && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) == 1)
3263 : {
3264 6096 : int l = tree_log2 (TREE_OPERAND (expr, 1));
3265 6096 : if (l >= 0)
3266 : {
3267 5008 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3268 5008 : ret2 = l;
3269 5008 : if (ret1 > ret2)
3270 0 : return ret1 - ret2;
3271 : }
3272 : }
3273 : return 0;
3274 12504266 : CASE_CONVERT:
3275 12504266 : ret1 = tree_ctz (TREE_OPERAND (expr, 0));
3276 12504266 : if (ret1 && ret1 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
3277 : ret1 = prec;
3278 12504266 : return MIN (ret1, prec);
3279 0 : case SAVE_EXPR:
3280 0 : return tree_ctz (TREE_OPERAND (expr, 0));
3281 12524 : case COND_EXPR:
3282 12524 : ret1 = tree_ctz (TREE_OPERAND (expr, 1));
3283 12524 : if (ret1 == 0)
3284 : return 0;
3285 205 : ret2 = tree_ctz (TREE_OPERAND (expr, 2));
3286 205 : return MIN (ret1, ret2);
3287 0 : case COMPOUND_EXPR:
3288 0 : return tree_ctz (TREE_OPERAND (expr, 1));
3289 196 : case ADDR_EXPR:
3290 196 : ret1 = get_pointer_alignment (const_cast<tree> (expr));
3291 196 : if (ret1 > BITS_PER_UNIT)
3292 : {
3293 196 : ret1 = ctz_hwi (ret1 / BITS_PER_UNIT);
3294 196 : return MIN (ret1, prec);
3295 : }
3296 : return 0;
3297 : default:
3298 : return 0;
3299 : }
3300 : }
3301 :
3302 : /* Return true if EXPR is the real constant zero. Trailing zeroes matter for
3303 : decimal float constants, so don't return true for them.
3304 : Also return true for location wrappers around such a constant. */
3305 :
3306 : bool
3307 592911396 : real_zerop (const_tree expr)
3308 : {
3309 592911396 : STRIP_ANY_LOCATION_WRAPPER (expr);
3310 :
3311 592911396 : switch (TREE_CODE (expr))
3312 : {
3313 19483853 : case REAL_CST:
3314 19483853 : return real_equal (&TREE_REAL_CST (expr), &dconst0)
3315 19483853 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3316 45421 : case COMPLEX_CST:
3317 45421 : return real_zerop (TREE_REALPART (expr))
3318 58481 : && real_zerop (TREE_IMAGPART (expr));
3319 487486 : case VECTOR_CST:
3320 487486 : {
3321 : /* Don't simply check for a duplicate because the predicate
3322 : accepts both +0.0 and -0.0. */
3323 487486 : unsigned count = vector_cst_encoded_nelts (expr);
3324 1009854 : for (unsigned int i = 0; i < count; ++i)
3325 498542 : if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3326 : return false;
3327 : return true;
3328 : }
3329 : default:
3330 : return false;
3331 : }
3332 : }
3333 :
3334 : /* Return true if EXPR is the real constant negative zero. */
3335 :
3336 : bool
3337 6 : real_negzerop (const_tree expr)
3338 : {
3339 6 : STRIP_ANY_LOCATION_WRAPPER (expr);
3340 :
3341 6 : if (TREE_CODE (expr) == VECTOR_CST)
3342 : {
3343 0 : expr = uniform_vector_p (expr);
3344 0 : if (!expr)
3345 : return false;
3346 : }
3347 :
3348 6 : if (TREE_CODE (expr) == COMPLEX_CST)
3349 2 : return real_negzerop (TREE_REALPART (expr))
3350 4 : && real_negzerop (TREE_IMAGPART (expr));
3351 :
3352 4 : return TREE_CODE (expr) == REAL_CST
3353 4 : && REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (expr))
3354 8 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3355 : }
3356 :
3357 : /* Return true if EXPR is the real constant one in real or complex form.
3358 : Trailing zeroes matter for decimal float constants, so don't return
3359 : true for them.
3360 : Also return true for location wrappers around such a constant. */
3361 :
3362 : bool
3363 122221636 : real_onep (const_tree expr)
3364 : {
3365 122221636 : STRIP_ANY_LOCATION_WRAPPER (expr);
3366 :
3367 122221636 : switch (TREE_CODE (expr))
3368 : {
3369 7279061 : case REAL_CST:
3370 7279061 : return real_equal (&TREE_REAL_CST (expr), &dconst1)
3371 7279061 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3372 12972 : case COMPLEX_CST:
3373 12972 : return real_onep (TREE_REALPART (expr))
3374 16581 : && real_zerop (TREE_IMAGPART (expr));
3375 67164 : case VECTOR_CST:
3376 67164 : return (VECTOR_CST_NPATTERNS (expr) == 1
3377 58003 : && VECTOR_CST_DUPLICATE_P (expr)
3378 114604 : && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3379 : default:
3380 : return false;
3381 : }
3382 : }
3383 :
3384 : /* Return true if EXPR is the real constant minus one. Trailing zeroes
3385 : matter for decimal float constants, so don't return true for them.
3386 : Also return true for location wrappers around such a constant. */
3387 :
3388 : bool
3389 123263725 : real_minus_onep (const_tree expr)
3390 : {
3391 123263725 : STRIP_ANY_LOCATION_WRAPPER (expr);
3392 :
3393 123263725 : switch (TREE_CODE (expr))
3394 : {
3395 7212406 : case REAL_CST:
3396 7212406 : return real_equal (&TREE_REAL_CST (expr), &dconstm1)
3397 7212406 : && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
3398 12952 : case COMPLEX_CST:
3399 12952 : return real_minus_onep (TREE_REALPART (expr))
3400 15324 : && real_zerop (TREE_IMAGPART (expr));
3401 69811 : case VECTOR_CST:
3402 69811 : return (VECTOR_CST_NPATTERNS (expr) == 1
3403 60051 : && VECTOR_CST_DUPLICATE_P (expr)
3404 119118 : && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
3405 : default:
3406 : return false;
3407 : }
3408 : }
3409 :
3410 : /* Return true if T could be a floating point zero. */
3411 :
3412 : bool
3413 712300 : real_maybe_zerop (const_tree expr)
3414 : {
3415 712300 : switch (TREE_CODE (expr))
3416 : {
3417 486058 : case REAL_CST:
3418 : /* Can't use real_zerop here, as it always returns false for decimal
3419 : floats. And can't use TREE_REAL_CST (expr).cl == rvc_zero
3420 : either, as decimal zeros are rvc_normal. */
3421 486058 : return real_equal (&TREE_REAL_CST (expr), &dconst0);
3422 0 : case COMPLEX_CST:
3423 0 : return (real_maybe_zerop (TREE_REALPART (expr))
3424 0 : || real_maybe_zerop (TREE_IMAGPART (expr)));
3425 0 : case VECTOR_CST:
3426 0 : {
3427 0 : unsigned count = vector_cst_encoded_nelts (expr);
3428 0 : for (unsigned int i = 0; i < count; ++i)
3429 0 : if (real_maybe_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
3430 : return true;
3431 : return false;
3432 : }
3433 : default:
3434 : /* Perhaps for SSA_NAMEs we could query frange. */
3435 : return true;
3436 : }
3437 : }
3438 :
3439 : /* True if EXP is a constant or a cast of a constant. */
3440 :
3441 : bool
3442 6192 : really_constant_p (const_tree exp)
3443 : {
3444 : /* This is not quite the same as STRIP_NOPS. It does more. */
3445 12392 : while (CONVERT_EXPR_P (exp)
3446 12444 : || TREE_CODE (exp) == NON_LVALUE_EXPR)
3447 60 : exp = TREE_OPERAND (exp, 0);
3448 6192 : return TREE_CONSTANT (exp);
3449 : }
3450 :
3451 : /* Return true if T holds a polynomial pointer difference, storing it in
3452 : *VALUE if so. A true return means that T's precision is no greater
3453 : than 64 bits, which is the largest address space we support, so *VALUE
3454 : never loses precision. However, the signedness of the result does
3455 : not necessarily match the signedness of T: sometimes an unsigned type
3456 : like sizetype is used to encode a value that is actually negative. */
3457 :
3458 : bool
3459 11512091 : ptrdiff_tree_p (const_tree t, poly_int64 *value)
3460 : {
3461 11512091 : if (!t)
3462 : return false;
3463 11512091 : if (TREE_CODE (t) == INTEGER_CST)
3464 : {
3465 3351403 : if (!cst_and_fits_in_hwi (t))
3466 : return false;
3467 3350886 : *value = int_cst_value (t);
3468 3350886 : return true;
3469 : }
3470 : if (POLY_INT_CST_P (t))
3471 : {
3472 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3473 : if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t, i)))
3474 : return false;
3475 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
3476 : value->coeffs[i] = int_cst_value (POLY_INT_CST_COEFF (t, i));
3477 : return true;
3478 : }
3479 : return false;
3480 : }
3481 :
3482 : poly_int64
3483 490522094 : tree_to_poly_int64 (const_tree t)
3484 : {
3485 490522094 : gcc_assert (tree_fits_poly_int64_p (t));
3486 490522094 : if (POLY_INT_CST_P (t))
3487 : return poly_int_cst_value (t).force_shwi ();
3488 490522094 : return TREE_INT_CST_LOW (t);
3489 : }
3490 :
3491 : poly_uint64
3492 552466267 : tree_to_poly_uint64 (const_tree t)
3493 : {
3494 552466267 : gcc_assert (tree_fits_poly_uint64_p (t));
3495 552466267 : if (POLY_INT_CST_P (t))
3496 : return poly_int_cst_value (t).force_uhwi ();
3497 552466267 : return TREE_INT_CST_LOW (t);
3498 : }
3499 :
3500 : /* Return first list element whose TREE_VALUE is ELEM.
3501 : Return 0 if ELEM is not in LIST. */
3502 :
3503 : tree
3504 8267437 : value_member (tree elem, tree list)
3505 : {
3506 24059849 : while (list)
3507 : {
3508 20895294 : if (elem == TREE_VALUE (list))
3509 : return list;
3510 15792412 : list = TREE_CHAIN (list);
3511 : }
3512 : return NULL_TREE;
3513 : }
3514 :
3515 : /* Return first list element whose TREE_PURPOSE is ELEM.
3516 : Return 0 if ELEM is not in LIST. */
3517 :
3518 : tree
3519 208844562 : purpose_member (const_tree elem, tree list)
3520 : {
3521 549653192 : while (list)
3522 : {
3523 373989937 : if (elem == TREE_PURPOSE (list))
3524 : return list;
3525 340808630 : list = TREE_CHAIN (list);
3526 : }
3527 : return NULL_TREE;
3528 : }
3529 :
3530 : /* Return true if ELEM is in V. */
3531 :
3532 : bool
3533 5404323 : vec_member (const_tree elem, vec<tree, va_gc> *v)
3534 : {
3535 5404323 : unsigned ix;
3536 5404323 : tree t;
3537 8150111 : FOR_EACH_VEC_SAFE_ELT (v, ix, t)
3538 2754063 : if (elem == t)
3539 : return true;
3540 : return false;
3541 : }
3542 :
3543 : /* Returns element number IDX (zero-origin) of chain CHAIN, or
3544 : NULL_TREE. */
3545 :
3546 : tree
3547 23181378 : chain_index (int idx, tree chain)
3548 : {
3549 29749902 : for (; chain && idx > 0; --idx)
3550 6568524 : chain = TREE_CHAIN (chain);
3551 23181378 : return chain;
3552 : }
3553 :
3554 : /* Return true if ELEM is part of the chain CHAIN. */
3555 :
3556 : bool
3557 235858 : chain_member (const_tree elem, const_tree chain)
3558 : {
3559 435699 : while (chain)
3560 : {
3561 434214 : if (elem == chain)
3562 : return true;
3563 199841 : chain = DECL_CHAIN (chain);
3564 : }
3565 :
3566 : return false;
3567 : }
3568 :
3569 : /* Return the length of a chain of nodes chained through TREE_CHAIN.
3570 : We expect a null pointer to mark the end of the chain.
3571 : This is the Lisp primitive `length'. */
3572 :
3573 : int
3574 2172998672 : list_length (const_tree t)
3575 : {
3576 2172998672 : const_tree p = t;
3577 : #ifdef ENABLE_TREE_CHECKING
3578 2172998672 : const_tree q = t;
3579 : #endif
3580 2172998672 : int len = 0;
3581 :
3582 3630884148 : while (p)
3583 : {
3584 1457885476 : p = TREE_CHAIN (p);
3585 : #ifdef ENABLE_TREE_CHECKING
3586 1457885476 : if (len % 2)
3587 475355571 : q = TREE_CHAIN (q);
3588 1457885476 : gcc_assert (p != q);
3589 : #endif
3590 1457885476 : len++;
3591 : }
3592 :
3593 2172998672 : return len;
3594 : }
3595 :
3596 : /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3597 : UNION_TYPE TYPE, or NULL_TREE if none. */
3598 :
3599 : tree
3600 160326 : first_field (const_tree type)
3601 : {
3602 160326 : tree t = TYPE_FIELDS (type);
3603 4321536 : while (t && TREE_CODE (t) != FIELD_DECL)
3604 4161210 : t = TREE_CHAIN (t);
3605 160326 : return t;
3606 : }
3607 :
3608 : /* Returns the last FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
3609 : UNION_TYPE TYPE, or NULL_TREE if none. */
3610 :
3611 : tree
3612 2859978 : last_field (const_tree type)
3613 : {
3614 2859978 : tree last = NULL_TREE;
3615 :
3616 67286292 : for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
3617 : {
3618 64426314 : if (TREE_CODE (fld) != FIELD_DECL)
3619 55816743 : continue;
3620 :
3621 : last = fld;
3622 : }
3623 :
3624 2859978 : return last;
3625 : }
3626 :
3627 : /* Concatenate two chains of nodes (chained through TREE_CHAIN)
3628 : by modifying the last node in chain 1 to point to chain 2.
3629 : This is the Lisp primitive `nconc'. */
3630 :
3631 : tree
3632 4237793453 : chainon (tree op1, tree op2)
3633 : {
3634 4237793453 : tree t1;
3635 :
3636 4237793453 : if (!op1)
3637 : return op2;
3638 788197088 : if (!op2)
3639 : return op1;
3640 :
3641 1624705161 : for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
3642 915988525 : continue;
3643 708716636 : TREE_CHAIN (t1) = op2;
3644 :
3645 : #ifdef ENABLE_TREE_CHECKING
3646 708716636 : {
3647 708716636 : tree t2;
3648 1803040181 : for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
3649 1094323545 : gcc_assert (t2 != t1);
3650 : }
3651 : #endif
3652 :
3653 : return op1;
3654 915988525 : }
3655 :
3656 : /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
3657 :
3658 : tree
3659 107324628 : tree_last (tree chain)
3660 : {
3661 107324628 : tree next;
3662 107324628 : if (chain)
3663 196241239 : while ((next = TREE_CHAIN (chain)))
3664 : chain = next;
3665 107324628 : return chain;
3666 : }
3667 :
3668 : /* Reverse the order of elements in the chain T,
3669 : and return the new head of the chain (old last element). */
3670 :
3671 : tree
3672 1609712204 : nreverse (tree t)
3673 : {
3674 1609712204 : tree prev = 0, decl, next;
3675 4064332518 : for (decl = t; decl; decl = next)
3676 : {
3677 : /* We shouldn't be using this function to reverse BLOCK chains; we
3678 : have blocks_nreverse for that. */
3679 2454620314 : gcc_checking_assert (TREE_CODE (decl) != BLOCK);
3680 2454620314 : next = TREE_CHAIN (decl);
3681 2454620314 : TREE_CHAIN (decl) = prev;
3682 2454620314 : prev = decl;
3683 : }
3684 1609712204 : return prev;
3685 : }
3686 :
3687 : /* Return a newly created TREE_LIST node whose
3688 : purpose and value fields are PARM and VALUE. */
3689 :
3690 : tree
3691 1493003091 : build_tree_list (tree parm, tree value MEM_STAT_DECL)
3692 : {
3693 1493003091 : tree t = make_node (TREE_LIST PASS_MEM_STAT);
3694 1493003091 : TREE_PURPOSE (t) = parm;
3695 1493003091 : TREE_VALUE (t) = value;
3696 1493003091 : return t;
3697 : }
3698 :
3699 : /* Build a chain of TREE_LIST nodes from a vector. */
3700 :
3701 : tree
3702 94203738 : build_tree_list_vec (const vec<tree, va_gc> *vec MEM_STAT_DECL)
3703 : {
3704 94203738 : tree ret = NULL_TREE;
3705 94203738 : tree *pp = &ret;
3706 94203738 : unsigned int i;
3707 94203738 : tree t;
3708 197743481 : FOR_EACH_VEC_SAFE_ELT (vec, i, t)
3709 : {
3710 103539743 : *pp = build_tree_list (NULL, t PASS_MEM_STAT);
3711 103539743 : pp = &TREE_CHAIN (*pp);
3712 : }
3713 94203738 : return ret;
3714 : }
3715 :
3716 : /* Return a newly created TREE_LIST node whose
3717 : purpose and value fields are PURPOSE and VALUE
3718 : and whose TREE_CHAIN is CHAIN. */
3719 :
3720 : tree
3721 5716548836 : tree_cons (tree purpose, tree value, tree chain MEM_STAT_DECL)
3722 : {
3723 5716548836 : tree node;
3724 :
3725 5716548836 : node = ggc_alloc_tree_node_stat (sizeof (struct tree_list) PASS_MEM_STAT);
3726 5716548836 : memset (node, 0, sizeof (struct tree_common));
3727 :
3728 5716548836 : record_node_allocation_statistics (TREE_LIST, sizeof (struct tree_list));
3729 :
3730 5716548836 : TREE_SET_CODE (node, TREE_LIST);
3731 5716548836 : TREE_CHAIN (node) = chain;
3732 5716548836 : TREE_PURPOSE (node) = purpose;
3733 5716548836 : TREE_VALUE (node) = value;
3734 5716548836 : return node;
3735 : }
3736 :
3737 : /* Return the values of the elements of a CONSTRUCTOR as a vector of
3738 : trees. */
3739 :
3740 : vec<tree, va_gc> *
3741 0 : ctor_to_vec (tree ctor)
3742 : {
3743 0 : vec<tree, va_gc> *vec;
3744 0 : vec_alloc (vec, CONSTRUCTOR_NELTS (ctor));
3745 0 : unsigned int ix;
3746 0 : tree val;
3747 :
3748 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
3749 0 : vec->quick_push (val);
3750 :
3751 0 : return vec;
3752 : }
3753 :
3754 : /* Return the size nominally occupied by an object of type TYPE
3755 : when it resides in memory. The value is measured in units of bytes,
3756 : and its data type is that normally used for type sizes
3757 : (which is the first type created by make_signed_type or
3758 : make_unsigned_type). */
3759 :
3760 : tree
3761 29204697 : size_in_bytes_loc (location_t loc, const_tree type)
3762 : {
3763 29204697 : tree t;
3764 :
3765 29204697 : if (type == error_mark_node)
3766 0 : return integer_zero_node;
3767 :
3768 29204697 : type = TYPE_MAIN_VARIANT (type);
3769 29204697 : t = TYPE_SIZE_UNIT (type);
3770 :
3771 29204697 : if (t == 0)
3772 : {
3773 65 : lang_hooks.types.incomplete_type_error (loc, NULL_TREE, type);
3774 65 : return size_zero_node;
3775 : }
3776 :
3777 : return t;
3778 : }
3779 :
3780 : /* Return the size of TYPE (in bytes) as a wide integer
3781 : or return -1 if the size can vary or is larger than an integer. */
3782 :
3783 : HOST_WIDE_INT
3784 518257377 : int_size_in_bytes (const_tree type)
3785 : {
3786 518257377 : tree t;
3787 :
3788 518257377 : if (type == error_mark_node)
3789 : return 0;
3790 :
3791 518257377 : type = TYPE_MAIN_VARIANT (type);
3792 518257377 : t = TYPE_SIZE_UNIT (type);
3793 :
3794 518257377 : if (t && tree_fits_uhwi_p (t))
3795 518203430 : return TREE_INT_CST_LOW (t);
3796 : else
3797 : return -1;
3798 : }
3799 :
3800 : /* Return the maximum size of TYPE (in bytes) as a wide integer
3801 : or return -1 if the size can vary or is larger than an integer. */
3802 :
3803 : HOST_WIDE_INT
3804 9286 : max_int_size_in_bytes (const_tree type)
3805 : {
3806 9286 : HOST_WIDE_INT size = -1;
3807 9286 : tree size_tree;
3808 :
3809 : /* If this is an array type, check for a possible MAX_SIZE attached. */
3810 :
3811 9286 : if (TREE_CODE (type) == ARRAY_TYPE)
3812 : {
3813 8553 : size_tree = TYPE_ARRAY_MAX_SIZE (type);
3814 :
3815 8553 : if (size_tree && tree_fits_uhwi_p (size_tree))
3816 0 : size = tree_to_uhwi (size_tree);
3817 : }
3818 :
3819 : /* If we still haven't been able to get a size, see if the language
3820 : can compute a maximum size. */
3821 :
3822 0 : if (size == -1)
3823 : {
3824 9286 : size_tree = lang_hooks.types.max_size (type);
3825 :
3826 9286 : if (size_tree && tree_fits_uhwi_p (size_tree))
3827 0 : size = tree_to_uhwi (size_tree);
3828 : }
3829 :
3830 9286 : return size;
3831 : }
3832 :
3833 : /* Return the bit position of FIELD, in bits from the start of the record.
3834 : This is a tree of type bitsizetype. */
3835 :
3836 : tree
3837 148101070 : bit_position (const_tree field)
3838 : {
3839 148101070 : return bit_from_pos (DECL_FIELD_OFFSET (field),
3840 148101070 : DECL_FIELD_BIT_OFFSET (field));
3841 : }
3842 :
3843 : /* Return the byte position of FIELD, in bytes from the start of the record.
3844 : This is a tree of type sizetype. */
3845 :
3846 : tree
3847 121814592 : byte_position (const_tree field)
3848 : {
3849 121814592 : return byte_from_pos (DECL_FIELD_OFFSET (field),
3850 121814592 : DECL_FIELD_BIT_OFFSET (field));
3851 : }
3852 :
3853 : /* Likewise, but return as an integer. It must be representable in
3854 : that way (since it could be a signed value, we don't have the
3855 : option of returning -1 like int_size_in_byte can. */
3856 :
3857 : HOST_WIDE_INT
3858 10121335 : int_byte_position (const_tree field)
3859 : {
3860 10121335 : return tree_to_shwi (byte_position (field));
3861 : }
3862 :
3863 : /* Return, as a tree node, the number of elements for TYPE (which is an
3864 : ARRAY_TYPE) minus one. This counts only elements of the top array. */
3865 :
3866 : tree
3867 115732714 : array_type_nelts_minus_one (const_tree type)
3868 : {
3869 115732714 : tree index_type, min, max;
3870 :
3871 : /* If they did it with unspecified bounds, then we should have already
3872 : given an error about it before we got here. */
3873 115732714 : if (! TYPE_DOMAIN (type))
3874 10285638 : return error_mark_node;
3875 :
3876 105447076 : index_type = TYPE_DOMAIN (type);
3877 105447076 : min = TYPE_MIN_VALUE (index_type);
3878 105447076 : max = TYPE_MAX_VALUE (index_type);
3879 :
3880 : /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
3881 105447076 : if (!max)
3882 : {
3883 : /* zero sized arrays are represented from C FE as complete types with
3884 : NULL TYPE_MAX_VALUE and zero TYPE_SIZE, while C++ FE represents
3885 : them as min 0, max -1. */
3886 1286991 : if (COMPLETE_TYPE_P (type)
3887 3145 : && integer_zerop (TYPE_SIZE (type))
3888 1290136 : && integer_zerop (min))
3889 3145 : return build_int_cst (TREE_TYPE (min), -1);
3890 :
3891 1283846 : return error_mark_node;
3892 : }
3893 :
3894 104160085 : return (integer_zerop (min)
3895 104160085 : ? max
3896 1178120 : : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
3897 : }
3898 :
3899 : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3900 : (which is an ARRAY_TYPE). This counts only elements of the top
3901 : array. */
3902 :
3903 : tree
3904 25191110 : array_type_nelts_top (tree type)
3905 : {
3906 25191110 : return fold_build2_loc (input_location,
3907 : PLUS_EXPR, sizetype,
3908 : array_type_nelts_minus_one (type),
3909 25191110 : size_one_node);
3910 : }
3911 :
3912 : /* If arg is static -- a reference to an object in static storage -- then
3913 : return the object. This is not the same as the C meaning of `static'.
3914 : If arg isn't static, return NULL. */
3915 :
3916 : tree
3917 1240496596 : staticp (tree arg)
3918 : {
3919 1241577390 : switch (TREE_CODE (arg))
3920 : {
3921 : case FUNCTION_DECL:
3922 : /* Nested functions are static, even though taking their address will
3923 : involve a trampoline as we unnest the nested function and create
3924 : the trampoline on the tree level. */
3925 : return arg;
3926 :
3927 747858205 : case VAR_DECL:
3928 591483729 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3929 202114904 : && ! DECL_THREAD_LOCAL_P (arg)
3930 200253870 : && ! DECL_DLLIMPORT_P (arg)
3931 747858205 : ? arg : NULL);
3932 :
3933 698899 : case CONST_DECL:
3934 44 : return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
3935 698899 : ? arg : NULL);
3936 :
3937 0 : case CONSTRUCTOR:
3938 0 : return TREE_STATIC (arg) ? arg : NULL;
3939 :
3940 : case LABEL_DECL:
3941 : case STRING_CST:
3942 : return arg;
3943 :
3944 826559 : case COMPONENT_REF:
3945 : /* If the thing being referenced is not a field, then it is
3946 : something language specific. */
3947 826559 : gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
3948 :
3949 : /* If we are referencing a bitfield, we can't evaluate an
3950 : ADDR_EXPR at compile time and so it isn't a constant. */
3951 826559 : if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
3952 : return NULL;
3953 :
3954 826559 : return staticp (TREE_OPERAND (arg, 0));
3955 :
3956 : case BIT_FIELD_REF:
3957 : return NULL;
3958 :
3959 35408 : case INDIRECT_REF:
3960 35408 : return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
3961 :
3962 254123 : case ARRAY_REF:
3963 254123 : case ARRAY_RANGE_REF:
3964 254123 : if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
3965 254123 : && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
3966 253779 : return staticp (TREE_OPERAND (arg, 0));
3967 : else
3968 : return NULL;
3969 :
3970 456 : case REALPART_EXPR:
3971 456 : case IMAGPART_EXPR:
3972 456 : return staticp (TREE_OPERAND (arg, 0));
3973 :
3974 934 : case COMPOUND_LITERAL_EXPR:
3975 934 : return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
3976 :
3977 : default:
3978 : return NULL;
3979 : }
3980 : }
3981 :
3982 :
3983 :
3984 :
3985 : /* Return whether OP is a DECL whose address is function-invariant. */
3986 :
3987 : bool
3988 5446632036 : decl_address_invariant_p (const_tree op)
3989 : {
3990 : /* The conditions below are slightly less strict than the one in
3991 : staticp. */
3992 :
3993 5446632036 : switch (TREE_CODE (op))
3994 : {
3995 : case PARM_DECL:
3996 : case RESULT_DECL:
3997 : case LABEL_DECL:
3998 : case FUNCTION_DECL:
3999 : return true;
4000 :
4001 3007494497 : case VAR_DECL:
4002 2296877149 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
4003 2152996969 : || DECL_THREAD_LOCAL_P (op)
4004 2152996969 : || DECL_CONTEXT (op) == current_function_decl
4005 3015709981 : || decl_function_context (op) == current_function_decl)
4006 : return true;
4007 : break;
4008 :
4009 26073577 : case CONST_DECL:
4010 0 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
4011 26073577 : || decl_function_context (op) == current_function_decl)
4012 : return true;
4013 : break;
4014 :
4015 : default:
4016 : break;
4017 : }
4018 :
4019 : return false;
4020 : }
4021 :
4022 : /* Return whether OP is a DECL whose address is interprocedural-invariant. */
4023 :
4024 : bool
4025 1895945 : decl_address_ip_invariant_p (const_tree op)
4026 : {
4027 : /* The conditions below are slightly less strict than the one in
4028 : staticp. */
4029 :
4030 1895945 : symtab_node* node;
4031 1895945 : switch (TREE_CODE (op))
4032 : {
4033 : case LABEL_DECL:
4034 : case STRING_CST:
4035 : return true;
4036 :
4037 91333 : case FUNCTION_DECL:
4038 : /* Disable const propagation of symbols defined in assembly. */
4039 91333 : node = symtab_node::get (op);
4040 91333 : return !node || !node->must_remain_in_tu_name;
4041 :
4042 1699244 : case VAR_DECL:
4043 1699244 : if (TREE_STATIC (op) || DECL_EXTERNAL (op))
4044 : {
4045 : /* Disable const propagation of symbols defined in assembly. */
4046 493955 : node = symtab_node::get (op);
4047 493955 : if (node && node->must_remain_in_tu_name)
4048 : return false;
4049 : }
4050 1255602 : if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
4051 493953 : && !DECL_DLLIMPORT_P (op))
4052 2904531 : || DECL_THREAD_LOCAL_P (op))
4053 : return true;
4054 : break;
4055 :
4056 53643 : case CONST_DECL:
4057 53643 : if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
4058 : return true;
4059 : break;
4060 :
4061 : default:
4062 : break;
4063 : }
4064 :
4065 : return false;
4066 : }
4067 :
4068 : /* Return true if T is an object with invariant address. */
4069 :
4070 : bool
4071 45664 : address_invariant_p (tree t)
4072 : {
4073 53636 : while (handled_component_p (t))
4074 : {
4075 8971 : switch (TREE_CODE (t))
4076 : {
4077 1481 : case ARRAY_REF:
4078 1481 : case ARRAY_RANGE_REF:
4079 1481 : if (!tree_invariant_p (TREE_OPERAND (t, 1))
4080 482 : || TREE_OPERAND (t, 2) != NULL_TREE
4081 1963 : || TREE_OPERAND (t, 3) != NULL_TREE)
4082 : return false;
4083 : break;
4084 :
4085 7331 : case COMPONENT_REF:
4086 7331 : if (TREE_OPERAND (t, 2) != NULL_TREE)
4087 : return false;
4088 : break;
4089 :
4090 : default:
4091 : break;
4092 : }
4093 7972 : t = TREE_OPERAND (t, 0);
4094 : }
4095 :
4096 44665 : STRIP_ANY_LOCATION_WRAPPER (t);
4097 44665 : return CONSTANT_CLASS_P (t) || decl_address_invariant_p (t);
4098 : }
4099 :
4100 :
4101 : /* Return true if T is function-invariant (internal function, does
4102 : not handle arithmetic; that's handled in skip_simple_arithmetic and
4103 : tree_invariant_p). */
4104 :
4105 : static bool
4106 16174209 : tree_invariant_p_1 (tree t)
4107 : {
4108 16174209 : if (TREE_CONSTANT (t) || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
4109 : return true;
4110 :
4111 13522088 : switch (TREE_CODE (t))
4112 : {
4113 : case SAVE_EXPR:
4114 : case TARGET_EXPR:
4115 : return true;
4116 :
4117 45612 : case ADDR_EXPR:
4118 45612 : return address_invariant_p (TREE_OPERAND (t, 0));
4119 :
4120 : default:
4121 : break;
4122 : }
4123 :
4124 : return false;
4125 : }
4126 :
4127 : /* Return true if T is function-invariant. */
4128 :
4129 : bool
4130 12661084 : tree_invariant_p (tree t)
4131 : {
4132 12661084 : tree inner = skip_simple_arithmetic (t);
4133 12661084 : return tree_invariant_p_1 (inner);
4134 : }
4135 :
4136 : /* Wrap a SAVE_EXPR around EXPR, if appropriate.
4137 : Do this to any expression which may be used in more than one place,
4138 : but must be evaluated only once.
4139 :
4140 : Normally, expand_expr would reevaluate the expression each time.
4141 : Calling save_expr produces something that is evaluated and recorded
4142 : the first time expand_expr is called on it. Subsequent calls to
4143 : expand_expr just reuse the recorded value.
4144 :
4145 : The call to expand_expr that generates code that actually computes
4146 : the value is the first call *at compile time*. Subsequent calls
4147 : *at compile time* generate code to use the saved value.
4148 : This produces correct result provided that *at run time* control
4149 : always flows through the insns made by the first expand_expr
4150 : before reaching the other places where the save_expr was evaluated.
4151 : You, the caller of save_expr, must make sure this is so.
4152 :
4153 : Constants, and certain read-only nodes, are returned with no
4154 : SAVE_EXPR because that is safe. Expressions containing placeholders
4155 : are not touched; see tree.def for an explanation of what these
4156 : are used for. */
4157 :
4158 : tree
4159 3513136 : save_expr (tree expr)
4160 : {
4161 3513136 : tree inner;
4162 :
4163 : /* If the tree evaluates to a constant, then we don't want to hide that
4164 : fact (i.e. this allows further folding, and direct checks for constants).
4165 : However, a read-only object that has side effects cannot be bypassed.
4166 : Since it is no problem to reevaluate literals, we just return the
4167 : literal node. */
4168 3513136 : inner = skip_simple_arithmetic (expr);
4169 3513136 : if (TREE_CODE (inner) == ERROR_MARK)
4170 : return inner;
4171 :
4172 3513125 : if (tree_invariant_p_1 (inner))
4173 : return expr;
4174 :
4175 : /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
4176 : it means that the size or offset of some field of an object depends on
4177 : the value within another field.
4178 :
4179 : Note that it must not be the case that EXPR contains both a PLACEHOLDER_EXPR
4180 : and some variable since it would then need to be both evaluated once and
4181 : evaluated more than once. Front-ends must assure this case cannot
4182 : happen by surrounding any such subexpressions in their own SAVE_EXPR
4183 : and forcing evaluation at the proper time. */
4184 2455410 : if (contains_placeholder_p (inner))
4185 : return expr;
4186 :
4187 2455410 : expr = build1_loc (EXPR_LOCATION (expr), SAVE_EXPR, TREE_TYPE (expr), expr);
4188 :
4189 : /* This expression might be placed ahead of a jump to ensure that the
4190 : value was computed on both sides of the jump. So make sure it isn't
4191 : eliminated as dead. */
4192 2455410 : TREE_SIDE_EFFECTS (expr) = 1;
4193 2455410 : return expr;
4194 : }
4195 :
4196 : /* Look inside EXPR into any simple arithmetic operations. Return the
4197 : outermost non-arithmetic or non-invariant node. */
4198 :
4199 : tree
4200 16174220 : skip_simple_arithmetic (tree expr)
4201 : {
4202 : /* We don't care about whether this can be used as an lvalue in this
4203 : context. */
4204 16189989 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4205 15769 : expr = TREE_OPERAND (expr, 0);
4206 :
4207 : /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
4208 : a constant, it will be more efficient to not make another SAVE_EXPR since
4209 : it will allow better simplification and GCSE will be able to merge the
4210 : computations if they actually occur. */
4211 40691904 : while (true)
4212 : {
4213 40691904 : if (UNARY_CLASS_P (expr))
4214 15341572 : expr = TREE_OPERAND (expr, 0);
4215 25350332 : else if (BINARY_CLASS_P (expr))
4216 : {
4217 : /* Before commutative binary operands are canonicalized,
4218 : it is quite common to have constants in the first operand.
4219 : Check for that common case first so that we don't walk
4220 : large expressions with tree_invariant_p unnecessarily.
4221 : This can still have terrible compile time complexity,
4222 : we should limit the depth of the tree_invariant_p and
4223 : skip_simple_arithmetic recursion. */
4224 9230515 : if ((TREE_CONSTANT (TREE_OPERAND (expr, 0))
4225 9220167 : || (TREE_READONLY (TREE_OPERAND (expr, 0))
4226 10471 : && !TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0))))
4227 9240950 : && tree_invariant_p (TREE_OPERAND (expr, 0)))
4228 20783 : expr = TREE_OPERAND (expr, 1);
4229 9209732 : else if (tree_invariant_p (TREE_OPERAND (expr, 1)))
4230 9145462 : expr = TREE_OPERAND (expr, 0);
4231 64270 : else if (tree_invariant_p (TREE_OPERAND (expr, 0)))
4232 9867 : expr = TREE_OPERAND (expr, 1);
4233 : else
4234 : break;
4235 : }
4236 : else
4237 : break;
4238 : }
4239 :
4240 16174220 : return expr;
4241 : }
4242 :
4243 : /* Look inside EXPR into simple arithmetic operations involving constants.
4244 : Return the outermost non-arithmetic or non-constant node. */
4245 :
4246 : tree
4247 0 : skip_simple_constant_arithmetic (tree expr)
4248 : {
4249 0 : while (TREE_CODE (expr) == NON_LVALUE_EXPR)
4250 0 : expr = TREE_OPERAND (expr, 0);
4251 :
4252 0 : while (true)
4253 : {
4254 0 : if (UNARY_CLASS_P (expr))
4255 0 : expr = TREE_OPERAND (expr, 0);
4256 0 : else if (BINARY_CLASS_P (expr))
4257 : {
4258 0 : if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
4259 0 : expr = TREE_OPERAND (expr, 0);
4260 0 : else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
4261 0 : expr = TREE_OPERAND (expr, 1);
4262 : else
4263 : break;
4264 : }
4265 : else
4266 : break;
4267 : }
4268 :
4269 0 : return expr;
4270 : }
4271 :
4272 : /* Return which tree structure is used by T. */
4273 :
4274 : enum tree_node_structure_enum
4275 44848665615 : tree_node_structure (const_tree t)
4276 : {
4277 44848665615 : const enum tree_code code = TREE_CODE (t);
4278 44848665615 : return tree_node_structure_for_code (code);
4279 : }
4280 :
4281 : /* Set various status flags when building a CALL_EXPR object T. */
4282 :
4283 : static void
4284 296745354 : process_call_operands (tree t)
4285 : {
4286 296745354 : bool side_effects = TREE_SIDE_EFFECTS (t);
4287 296745354 : bool read_only = false;
4288 296745354 : int i = call_expr_flags (t);
4289 :
4290 : /* Calls have side-effects, except those to const or pure functions. */
4291 296745354 : if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
4292 : side_effects = true;
4293 : /* Propagate TREE_READONLY of arguments for const functions. */
4294 61708643 : if (i & ECF_CONST)
4295 60073987 : read_only = true;
4296 :
4297 296745354 : if (!side_effects || read_only)
4298 308122887 : for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
4299 : {
4300 246426727 : tree op = TREE_OPERAND (t, i);
4301 246426727 : if (op && TREE_SIDE_EFFECTS (op))
4302 : side_effects = true;
4303 246426727 : if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
4304 : read_only = false;
4305 : }
4306 :
4307 296745354 : TREE_SIDE_EFFECTS (t) = side_effects;
4308 296745354 : TREE_READONLY (t) = read_only;
4309 296745354 : }
4310 :
4311 : /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
4312 : size or offset that depends on a field within a record. */
4313 :
4314 : bool
4315 39073915 : contains_placeholder_p (const_tree exp)
4316 : {
4317 39073915 : enum tree_code code;
4318 :
4319 39073915 : if (!exp)
4320 : return false;
4321 :
4322 39073915 : code = TREE_CODE (exp);
4323 39073915 : if (code == PLACEHOLDER_EXPR)
4324 : return true;
4325 :
4326 39073915 : switch (TREE_CODE_CLASS (code))
4327 : {
4328 1190014 : case tcc_reference:
4329 : /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
4330 : position computations since they will be converted into a
4331 : WITH_RECORD_EXPR involving the reference, which will assume
4332 : here will be valid. */
4333 1190014 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4334 :
4335 593335 : case tcc_exceptional:
4336 593335 : if (code == TREE_LIST)
4337 0 : return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
4338 0 : || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
4339 : break;
4340 :
4341 33846696 : case tcc_unary:
4342 33846696 : case tcc_binary:
4343 33846696 : case tcc_comparison:
4344 33846696 : case tcc_expression:
4345 33846696 : switch (code)
4346 : {
4347 7316 : case COMPOUND_EXPR:
4348 : /* Ignoring the first operand isn't quite right, but works best. */
4349 7316 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
4350 :
4351 4660 : case COND_EXPR:
4352 9320 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4353 4660 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
4354 9320 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
4355 :
4356 : case SAVE_EXPR:
4357 : /* The save_expr function never wraps anything containing
4358 : a PLACEHOLDER_EXPR. */
4359 : return false;
4360 :
4361 24657693 : default:
4362 24657693 : break;
4363 : }
4364 :
4365 24657693 : switch (TREE_CODE_LENGTH (code))
4366 : {
4367 15034427 : case 1:
4368 15034427 : return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
4369 9525020 : case 2:
4370 19048498 : return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
4371 19048498 : || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
4372 : default:
4373 : return false;
4374 : }
4375 :
4376 820814 : case tcc_vl_exp:
4377 820814 : switch (code)
4378 : {
4379 820814 : case CALL_EXPR:
4380 820814 : {
4381 820814 : const_tree arg;
4382 820814 : const_call_expr_arg_iterator iter;
4383 2856521 : FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
4384 1214893 : if (CONTAINS_PLACEHOLDER_P (arg))
4385 : return true;
4386 : return false;
4387 : }
4388 : default:
4389 : return false;
4390 : }
4391 :
4392 : default:
4393 : return false;
4394 : }
4395 : return false;
4396 : }
4397 :
4398 : /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
4399 : directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
4400 : field positions. */
4401 :
4402 : static bool
4403 819673 : type_contains_placeholder_1 (const_tree type)
4404 : {
4405 : /* If the size contains a placeholder or the parent type (component type in
4406 : the case of arrays) type involves a placeholder, this type does. */
4407 1617857 : if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
4408 819673 : || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
4409 1639346 : || (!POINTER_TYPE_P (type)
4410 679399 : && TREE_TYPE (type)
4411 118057 : && type_contains_placeholder_p (TREE_TYPE (type))))
4412 : return true;
4413 :
4414 : /* Now do type-specific checks. Note that the last part of the check above
4415 : greatly limits what we have to do below. */
4416 819673 : switch (TREE_CODE (type))
4417 : {
4418 : case VOID_TYPE:
4419 : case OPAQUE_TYPE:
4420 : case COMPLEX_TYPE:
4421 : case ENUMERAL_TYPE:
4422 : case BOOLEAN_TYPE:
4423 : case POINTER_TYPE:
4424 : case OFFSET_TYPE:
4425 : case REFERENCE_TYPE:
4426 : case METHOD_TYPE:
4427 : case FUNCTION_TYPE:
4428 : case VECTOR_TYPE:
4429 : case NULLPTR_TYPE:
4430 : return false;
4431 :
4432 184368 : case INTEGER_TYPE:
4433 184368 : case BITINT_TYPE:
4434 184368 : case REAL_TYPE:
4435 184368 : case FIXED_POINT_TYPE:
4436 : /* Here we just check the bounds. */
4437 358830 : return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
4438 358830 : || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
4439 :
4440 58744 : case ARRAY_TYPE:
4441 : /* We have already checked the component type above, so just check
4442 : the domain type. Flexible array members have a null domain. */
4443 117476 : return TYPE_DOMAIN (type) ?
4444 58732 : type_contains_placeholder_p (TYPE_DOMAIN (type)) : false;
4445 :
4446 411505 : case RECORD_TYPE:
4447 411505 : case UNION_TYPE:
4448 411505 : case QUAL_UNION_TYPE:
4449 411505 : {
4450 411505 : tree field;
4451 :
4452 12118507 : for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4453 11707002 : if (TREE_CODE (field) == FIELD_DECL
4454 11707002 : && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
4455 958004 : || (TREE_CODE (type) == QUAL_UNION_TYPE
4456 0 : && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
4457 958004 : || type_contains_placeholder_p (TREE_TYPE (field))))
4458 : return true;
4459 :
4460 : return false;
4461 : }
4462 :
4463 0 : default:
4464 0 : gcc_unreachable ();
4465 : }
4466 : }
4467 :
4468 : /* Wrapper around above function used to cache its result. */
4469 :
4470 : bool
4471 3020300 : type_contains_placeholder_p (tree type)
4472 : {
4473 3020300 : bool result;
4474 :
4475 : /* If the contains_placeholder_bits field has been initialized,
4476 : then we know the answer. */
4477 3020300 : if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
4478 2200627 : return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
4479 :
4480 : /* Indicate that we've seen this type node, and the answer is false.
4481 : This is what we want to return if we run into recursion via fields. */
4482 819673 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
4483 :
4484 : /* Compute the real value. */
4485 819673 : result = type_contains_placeholder_1 (type);
4486 :
4487 : /* Store the real value. */
4488 819673 : TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
4489 :
4490 819673 : return result;
4491 : }
4492 :
4493 : /* Push tree EXP onto vector QUEUE if it is not already present. */
4494 :
4495 : static void
4496 0 : push_without_duplicates (tree exp, vec<tree> *queue)
4497 : {
4498 0 : unsigned int i;
4499 0 : tree iter;
4500 :
4501 0 : FOR_EACH_VEC_ELT (*queue, i, iter)
4502 0 : if (simple_cst_equal (iter, exp) == 1)
4503 : break;
4504 :
4505 0 : if (!iter)
4506 0 : queue->safe_push (exp);
4507 0 : }
4508 :
4509 : /* Given a tree EXP, find all occurrences of references to fields
4510 : in a PLACEHOLDER_EXPR and place them in vector REFS without
4511 : duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
4512 : we assume here that EXP contains only arithmetic expressions
4513 : or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
4514 : argument list. */
4515 :
4516 : void
4517 0 : find_placeholder_in_expr (tree exp, vec<tree> *refs)
4518 : {
4519 0 : enum tree_code code = TREE_CODE (exp);
4520 0 : tree inner;
4521 0 : int i;
4522 :
4523 : /* We handle TREE_LIST and COMPONENT_REF separately. */
4524 0 : if (code == TREE_LIST)
4525 : {
4526 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
4527 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
4528 : }
4529 0 : else if (code == COMPONENT_REF)
4530 : {
4531 0 : for (inner = TREE_OPERAND (exp, 0);
4532 0 : REFERENCE_CLASS_P (inner);
4533 0 : inner = TREE_OPERAND (inner, 0))
4534 : ;
4535 :
4536 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
4537 0 : push_without_duplicates (exp, refs);
4538 : else
4539 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
4540 : }
4541 : else
4542 0 : switch (TREE_CODE_CLASS (code))
4543 : {
4544 : case tcc_constant:
4545 : break;
4546 :
4547 0 : case tcc_declaration:
4548 : /* Variables allocated to static storage can stay. */
4549 0 : if (!TREE_STATIC (exp))
4550 0 : push_without_duplicates (exp, refs);
4551 : break;
4552 :
4553 0 : case tcc_expression:
4554 : /* This is the pattern built in ada/make_aligning_type. */
4555 0 : if (code == ADDR_EXPR
4556 0 : && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
4557 : {
4558 0 : push_without_duplicates (exp, refs);
4559 0 : break;
4560 : }
4561 :
4562 : /* Fall through. */
4563 :
4564 : case tcc_exceptional:
4565 : case tcc_unary:
4566 : case tcc_binary:
4567 : case tcc_comparison:
4568 : case tcc_reference:
4569 0 : for (i = 0; i < TREE_CODE_LENGTH (code); i++)
4570 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4571 : break;
4572 :
4573 : case tcc_vl_exp:
4574 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4575 0 : FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
4576 : break;
4577 :
4578 0 : default:
4579 0 : gcc_unreachable ();
4580 : }
4581 0 : }
4582 :
4583 : /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
4584 : return a tree with all occurrences of references to F in a
4585 : PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
4586 : CONST_DECLs. Note that we assume here that EXP contains only
4587 : arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
4588 : occurring only in their argument list. */
4589 :
4590 : tree
4591 0 : substitute_in_expr (tree exp, tree f, tree r)
4592 : {
4593 0 : enum tree_code code = TREE_CODE (exp);
4594 0 : tree op0, op1, op2, op3;
4595 0 : tree new_tree;
4596 :
4597 : /* We handle TREE_LIST and COMPONENT_REF separately. */
4598 0 : if (code == TREE_LIST)
4599 : {
4600 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
4601 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
4602 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4603 : return exp;
4604 :
4605 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4606 : }
4607 0 : else if (code == COMPONENT_REF)
4608 : {
4609 0 : tree inner;
4610 :
4611 : /* If this expression is getting a value from a PLACEHOLDER_EXPR
4612 : and it is the right field, replace it with R. */
4613 0 : for (inner = TREE_OPERAND (exp, 0);
4614 0 : REFERENCE_CLASS_P (inner);
4615 0 : inner = TREE_OPERAND (inner, 0))
4616 : ;
4617 :
4618 : /* The field. */
4619 0 : op1 = TREE_OPERAND (exp, 1);
4620 :
4621 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
4622 : return r;
4623 :
4624 : /* If this expression hasn't been completed let, leave it alone. */
4625 0 : if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
4626 : return exp;
4627 :
4628 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4629 0 : if (op0 == TREE_OPERAND (exp, 0))
4630 : return exp;
4631 :
4632 0 : new_tree
4633 0 : = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
4634 : }
4635 : else
4636 0 : switch (TREE_CODE_CLASS (code))
4637 : {
4638 : case tcc_constant:
4639 : return exp;
4640 :
4641 0 : case tcc_declaration:
4642 0 : if (exp == f)
4643 : return r;
4644 : else
4645 0 : return exp;
4646 :
4647 0 : case tcc_expression:
4648 0 : if (exp == f)
4649 : return r;
4650 :
4651 : /* Fall through. */
4652 :
4653 0 : case tcc_exceptional:
4654 0 : case tcc_unary:
4655 0 : case tcc_binary:
4656 0 : case tcc_comparison:
4657 0 : case tcc_reference:
4658 0 : switch (TREE_CODE_LENGTH (code))
4659 : {
4660 : case 0:
4661 : return exp;
4662 :
4663 0 : case 1:
4664 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4665 0 : if (op0 == TREE_OPERAND (exp, 0))
4666 : return exp;
4667 :
4668 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4669 0 : break;
4670 :
4671 0 : case 2:
4672 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4673 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4674 :
4675 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4676 : return exp;
4677 :
4678 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4679 0 : break;
4680 :
4681 0 : case 3:
4682 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4683 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4684 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4685 :
4686 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4687 0 : && op2 == TREE_OPERAND (exp, 2))
4688 : return exp;
4689 :
4690 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4691 0 : break;
4692 :
4693 0 : case 4:
4694 0 : op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
4695 0 : op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
4696 0 : op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
4697 0 : op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
4698 :
4699 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4700 0 : && op2 == TREE_OPERAND (exp, 2)
4701 0 : && op3 == TREE_OPERAND (exp, 3))
4702 : return exp;
4703 :
4704 0 : new_tree
4705 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4706 0 : break;
4707 :
4708 0 : default:
4709 0 : gcc_unreachable ();
4710 : }
4711 : break;
4712 :
4713 0 : case tcc_vl_exp:
4714 0 : {
4715 0 : int i;
4716 :
4717 0 : new_tree = NULL_TREE;
4718 :
4719 : /* If we are trying to replace F with a constant or with another
4720 : instance of one of the arguments of the call, inline back
4721 : functions which do nothing else than computing a value from
4722 : the arguments they are passed. This makes it possible to
4723 : fold partially or entirely the replacement expression. */
4724 0 : if (code == CALL_EXPR)
4725 : {
4726 0 : bool maybe_inline = false;
4727 0 : if (CONSTANT_CLASS_P (r))
4728 : maybe_inline = true;
4729 : else
4730 0 : for (i = 3; i < TREE_OPERAND_LENGTH (exp); i++)
4731 0 : if (operand_equal_p (TREE_OPERAND (exp, i), r, 0))
4732 : {
4733 : maybe_inline = true;
4734 : break;
4735 : }
4736 0 : if (maybe_inline)
4737 : {
4738 0 : tree t = maybe_inline_call_in_expr (exp);
4739 0 : if (t)
4740 0 : return SUBSTITUTE_IN_EXPR (t, f, r);
4741 : }
4742 : }
4743 :
4744 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4745 : {
4746 0 : tree op = TREE_OPERAND (exp, i);
4747 0 : tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
4748 0 : if (new_op != op)
4749 : {
4750 0 : if (!new_tree)
4751 0 : new_tree = copy_node (exp);
4752 0 : TREE_OPERAND (new_tree, i) = new_op;
4753 : }
4754 : }
4755 :
4756 0 : if (new_tree)
4757 : {
4758 0 : new_tree = fold (new_tree);
4759 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4760 0 : process_call_operands (new_tree);
4761 : }
4762 : else
4763 : return exp;
4764 : }
4765 : break;
4766 :
4767 0 : default:
4768 0 : gcc_unreachable ();
4769 : }
4770 :
4771 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4772 :
4773 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4774 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4775 :
4776 : return new_tree;
4777 : }
4778 :
4779 : /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
4780 : for it within OBJ, a tree that is an object or a chain of references. */
4781 :
4782 : tree
4783 249418 : substitute_placeholder_in_expr (tree exp, tree obj)
4784 : {
4785 249418 : enum tree_code code = TREE_CODE (exp);
4786 249418 : tree op0, op1, op2, op3;
4787 249418 : tree new_tree;
4788 :
4789 : /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
4790 : in the chain of OBJ. */
4791 249418 : if (code == PLACEHOLDER_EXPR)
4792 : {
4793 0 : tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
4794 0 : tree elt;
4795 :
4796 0 : for (elt = obj; elt != 0;
4797 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4798 0 : || TREE_CODE (elt) == COND_EXPR)
4799 0 : ? TREE_OPERAND (elt, 1)
4800 0 : : (REFERENCE_CLASS_P (elt)
4801 : || UNARY_CLASS_P (elt)
4802 : || BINARY_CLASS_P (elt)
4803 : || VL_EXP_CLASS_P (elt)
4804 : || EXPRESSION_CLASS_P (elt))
4805 0 : ? TREE_OPERAND (elt, 0) : 0))
4806 0 : if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
4807 : return elt;
4808 :
4809 0 : for (elt = obj; elt != 0;
4810 0 : elt = ((TREE_CODE (elt) == COMPOUND_EXPR
4811 0 : || TREE_CODE (elt) == COND_EXPR)
4812 0 : ? TREE_OPERAND (elt, 1)
4813 0 : : (REFERENCE_CLASS_P (elt)
4814 : || UNARY_CLASS_P (elt)
4815 : || BINARY_CLASS_P (elt)
4816 : || VL_EXP_CLASS_P (elt)
4817 : || EXPRESSION_CLASS_P (elt))
4818 0 : ? TREE_OPERAND (elt, 0) : 0))
4819 0 : if (POINTER_TYPE_P (TREE_TYPE (elt))
4820 0 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
4821 : == need_type))
4822 0 : return fold_build1 (INDIRECT_REF, need_type, elt);
4823 :
4824 : /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
4825 : survives until RTL generation, there will be an error. */
4826 : return exp;
4827 : }
4828 :
4829 : /* TREE_LIST is special because we need to look at TREE_VALUE
4830 : and TREE_CHAIN, not TREE_OPERANDS. */
4831 249418 : else if (code == TREE_LIST)
4832 : {
4833 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
4834 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
4835 0 : if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
4836 : return exp;
4837 :
4838 0 : return tree_cons (TREE_PURPOSE (exp), op1, op0);
4839 : }
4840 : else
4841 249418 : switch (TREE_CODE_CLASS (code))
4842 : {
4843 : case tcc_constant:
4844 : case tcc_declaration:
4845 : return exp;
4846 :
4847 10171 : case tcc_exceptional:
4848 10171 : case tcc_unary:
4849 10171 : case tcc_binary:
4850 10171 : case tcc_comparison:
4851 10171 : case tcc_expression:
4852 10171 : case tcc_reference:
4853 10171 : case tcc_statement:
4854 10171 : switch (TREE_CODE_LENGTH (code))
4855 : {
4856 : case 0:
4857 : return exp;
4858 :
4859 7776 : case 1:
4860 7776 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4861 7776 : if (op0 == TREE_OPERAND (exp, 0))
4862 : return exp;
4863 :
4864 0 : new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
4865 0 : break;
4866 :
4867 2383 : case 2:
4868 2383 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4869 2383 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4870 :
4871 2383 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
4872 : return exp;
4873 :
4874 0 : new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
4875 0 : break;
4876 :
4877 12 : case 3:
4878 12 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4879 12 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4880 12 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4881 :
4882 24 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4883 24 : && op2 == TREE_OPERAND (exp, 2))
4884 : return exp;
4885 :
4886 0 : new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
4887 0 : break;
4888 :
4889 0 : case 4:
4890 0 : op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
4891 0 : op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
4892 0 : op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
4893 0 : op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
4894 :
4895 0 : if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
4896 0 : && op2 == TREE_OPERAND (exp, 2)
4897 0 : && op3 == TREE_OPERAND (exp, 3))
4898 : return exp;
4899 :
4900 0 : new_tree
4901 0 : = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
4902 0 : break;
4903 :
4904 0 : default:
4905 0 : gcc_unreachable ();
4906 : }
4907 : break;
4908 :
4909 : case tcc_vl_exp:
4910 : {
4911 : int i;
4912 :
4913 : new_tree = NULL_TREE;
4914 :
4915 0 : for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
4916 : {
4917 0 : tree op = TREE_OPERAND (exp, i);
4918 0 : tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
4919 0 : if (new_op != op)
4920 : {
4921 0 : if (!new_tree)
4922 0 : new_tree = copy_node (exp);
4923 0 : TREE_OPERAND (new_tree, i) = new_op;
4924 : }
4925 : }
4926 :
4927 0 : if (new_tree)
4928 : {
4929 0 : new_tree = fold (new_tree);
4930 0 : if (TREE_CODE (new_tree) == CALL_EXPR)
4931 0 : process_call_operands (new_tree);
4932 : }
4933 : else
4934 : return exp;
4935 : }
4936 : break;
4937 :
4938 0 : default:
4939 0 : gcc_unreachable ();
4940 : }
4941 :
4942 0 : TREE_READONLY (new_tree) |= TREE_READONLY (exp);
4943 :
4944 0 : if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF)
4945 0 : TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp);
4946 :
4947 : return new_tree;
4948 : }
4949 :
4950 :
4951 : /* Subroutine of stabilize_reference; this is called for subtrees of
4952 : references. Any expression with side-effects must be put in a SAVE_EXPR
4953 : to ensure that it is only evaluated once.
4954 :
4955 : We don't put SAVE_EXPR nodes around everything, because assigning very
4956 : simple expressions to temporaries causes us to miss good opportunities
4957 : for optimizations. Among other things, the opportunity to fold in the
4958 : addition of a constant into an addressing mode often gets lost, e.g.
4959 : "y[i+1] += x;". In general, we take the approach that we should not make
4960 : an assignment unless we are forced into it - i.e., that any non-side effect
4961 : operator should be allowed, and that cse should take care of coalescing
4962 : multiple utterances of the same expression should that prove fruitful. */
4963 :
4964 : static tree
4965 914039 : stabilize_reference_1 (tree e)
4966 : {
4967 914039 : tree result;
4968 914039 : enum tree_code code = TREE_CODE (e);
4969 :
4970 : /* We cannot ignore const expressions because it might be a reference
4971 : to a const array but whose index contains side-effects. But we can
4972 : ignore things that are actual constant or that already have been
4973 : handled by this function. */
4974 :
4975 914039 : if (tree_invariant_p (e))
4976 : return e;
4977 :
4978 135274 : switch (TREE_CODE_CLASS (code))
4979 : {
4980 0 : case tcc_exceptional:
4981 : /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
4982 : have side-effects. */
4983 0 : if (code == STATEMENT_LIST)
4984 0 : return save_expr (e);
4985 : /* FALLTHRU */
4986 105416 : case tcc_type:
4987 105416 : case tcc_declaration:
4988 105416 : case tcc_comparison:
4989 105416 : case tcc_statement:
4990 105416 : case tcc_expression:
4991 105416 : case tcc_reference:
4992 105416 : case tcc_vl_exp:
4993 : /* If the expression has side-effects, then encase it in a SAVE_EXPR
4994 : so that it will only be evaluated once. */
4995 : /* The reference (r) and comparison (<) classes could be handled as
4996 : below, but it is generally faster to only evaluate them once. */
4997 105416 : if (TREE_SIDE_EFFECTS (e))
4998 1004 : return save_expr (e);
4999 : return e;
5000 :
5001 : case tcc_constant:
5002 : /* Constants need no processing. In fact, we should never reach
5003 : here. */
5004 : return e;
5005 :
5006 22043 : case tcc_binary:
5007 : /* Division is slow and tends to be compiled with jumps,
5008 : especially the division by powers of 2 that is often
5009 : found inside of an array reference. So do it just once. */
5010 22043 : if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
5011 20003 : || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
5012 20003 : || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
5013 20003 : || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
5014 2040 : return save_expr (e);
5015 : /* Recursively stabilize each operand. */
5016 20003 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
5017 20003 : stabilize_reference_1 (TREE_OPERAND (e, 1)));
5018 20003 : break;
5019 :
5020 7815 : case tcc_unary:
5021 : /* Recursively stabilize each operand. */
5022 7815 : result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
5023 7815 : break;
5024 :
5025 0 : default:
5026 0 : gcc_unreachable ();
5027 : }
5028 :
5029 27818 : TREE_TYPE (result) = TREE_TYPE (e);
5030 27818 : TREE_READONLY (result) = TREE_READONLY (e);
5031 27818 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
5032 27818 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
5033 :
5034 27818 : return result;
5035 : }
5036 :
5037 : /* Stabilize a reference so that we can use it any number of times
5038 : without causing its operands to be evaluated more than once.
5039 : Returns the stabilized reference. This works by means of save_expr,
5040 : so see the caveats in the comments about save_expr.
5041 :
5042 : Also allows conversion expressions whose operands are references.
5043 : Any other kind of expression is returned unchanged. */
5044 :
5045 : tree
5046 4946297 : stabilize_reference (tree ref)
5047 : {
5048 4946297 : tree result;
5049 4946297 : enum tree_code code = TREE_CODE (ref);
5050 :
5051 4946297 : switch (code)
5052 : {
5053 : case VAR_DECL:
5054 : case PARM_DECL:
5055 : case RESULT_DECL:
5056 : /* No action is needed in this case. */
5057 : return ref;
5058 :
5059 0 : CASE_CONVERT:
5060 0 : case FLOAT_EXPR:
5061 0 : case FIX_TRUNC_EXPR:
5062 0 : result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
5063 0 : break;
5064 :
5065 819181 : case INDIRECT_REF:
5066 819181 : result = build_nt (INDIRECT_REF,
5067 819181 : stabilize_reference_1 (TREE_OPERAND (ref, 0)));
5068 819181 : break;
5069 :
5070 474426 : case COMPONENT_REF:
5071 474426 : result = build_nt (COMPONENT_REF,
5072 474426 : stabilize_reference (TREE_OPERAND (ref, 0)),
5073 474426 : TREE_OPERAND (ref, 1), NULL_TREE);
5074 474426 : break;
5075 :
5076 0 : case BIT_FIELD_REF:
5077 0 : result = build_nt (BIT_FIELD_REF,
5078 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5079 0 : TREE_OPERAND (ref, 1), TREE_OPERAND (ref, 2));
5080 0 : REF_REVERSE_STORAGE_ORDER (result) = REF_REVERSE_STORAGE_ORDER (ref);
5081 0 : break;
5082 :
5083 47037 : case ARRAY_REF:
5084 94074 : result = build_nt (ARRAY_REF,
5085 47037 : stabilize_reference (TREE_OPERAND (ref, 0)),
5086 47037 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5087 47037 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5088 47037 : break;
5089 :
5090 0 : case ARRAY_RANGE_REF:
5091 0 : result = build_nt (ARRAY_RANGE_REF,
5092 0 : stabilize_reference (TREE_OPERAND (ref, 0)),
5093 0 : stabilize_reference_1 (TREE_OPERAND (ref, 1)),
5094 0 : TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
5095 0 : break;
5096 :
5097 0 : case COMPOUND_EXPR:
5098 : /* We cannot wrap the first expression in a SAVE_EXPR, as then
5099 : it wouldn't be ignored. This matters when dealing with
5100 : volatiles. */
5101 0 : return stabilize_reference_1 (ref);
5102 :
5103 : /* If arg isn't a kind of lvalue we recognize, make no change.
5104 : Caller should recognize the error for an invalid lvalue. */
5105 : default:
5106 : return ref;
5107 :
5108 0 : case ERROR_MARK:
5109 0 : return error_mark_node;
5110 : }
5111 :
5112 1340644 : TREE_TYPE (result) = TREE_TYPE (ref);
5113 1340644 : TREE_READONLY (result) = TREE_READONLY (ref);
5114 1340644 : TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
5115 1340644 : TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
5116 1340644 : protected_set_expr_location (result, EXPR_LOCATION (ref));
5117 :
5118 1340644 : return result;
5119 : }
5120 :
5121 : /* Low-level constructors for expressions. */
5122 :
5123 : /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
5124 : and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
5125 :
5126 : void
5127 1462338067 : recompute_tree_invariant_for_addr_expr (tree t)
5128 : {
5129 1462338067 : tree node;
5130 1462338067 : bool tc = true, se = false;
5131 :
5132 1462338067 : gcc_assert (TREE_CODE (t) == ADDR_EXPR);
5133 :
5134 : /* We started out assuming this address is both invariant and constant, but
5135 : does not have side effects. Now go down any handled components and see if
5136 : any of them involve offsets that are either non-constant or non-invariant.
5137 : Also check for side-effects.
5138 :
5139 : ??? Note that this code makes no attempt to deal with the case where
5140 : taking the address of something causes a copy due to misalignment. */
5141 :
5142 : #define UPDATE_FLAGS(NODE) \
5143 : do { tree _node = (NODE); \
5144 : if (_node && !TREE_CONSTANT (_node)) tc = false; \
5145 : if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
5146 :
5147 1715725747 : for (node = TREE_OPERAND (t, 0); handled_component_p (node);
5148 253387680 : node = TREE_OPERAND (node, 0))
5149 : {
5150 : /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
5151 : array reference (probably made temporarily by the G++ front end),
5152 : so ignore all the operands. */
5153 253387680 : if ((TREE_CODE (node) == ARRAY_REF
5154 253387680 : || TREE_CODE (node) == ARRAY_RANGE_REF)
5155 253387680 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
5156 : {
5157 34596637 : UPDATE_FLAGS (TREE_OPERAND (node, 1));
5158 34596637 : if (TREE_OPERAND (node, 2))
5159 2221897 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5160 34596637 : if (TREE_OPERAND (node, 3))
5161 309669 : UPDATE_FLAGS (TREE_OPERAND (node, 3));
5162 : }
5163 : /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
5164 : FIELD_DECL, apparently. The G++ front end can put something else
5165 : there, at least temporarily. */
5166 218791043 : else if (TREE_CODE (node) == COMPONENT_REF
5167 218791043 : && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
5168 : {
5169 217559684 : if (TREE_OPERAND (node, 2))
5170 17038 : UPDATE_FLAGS (TREE_OPERAND (node, 2));
5171 : }
5172 : }
5173 :
5174 1462338067 : node = lang_hooks.expr_to_decl (node, &tc, &se);
5175 :
5176 : /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
5177 : the address, since &(*a)->b is a form of addition. If it's a constant, the
5178 : address is constant too. If it's a decl, its address is constant if the
5179 : decl is static. Everything else is not constant and, furthermore,
5180 : taking the address of a volatile variable is not volatile. */
5181 1462338067 : if (INDIRECT_REF_P (node)
5182 1422465453 : || TREE_CODE (node) == MEM_REF)
5183 168654319 : UPDATE_FLAGS (TREE_OPERAND (node, 0));
5184 1293683748 : else if (CONSTANT_CLASS_P (node))
5185 : ;
5186 1211750882 : else if (DECL_P (node))
5187 1186869481 : tc &= (staticp (node) != NULL_TREE);
5188 : else
5189 : {
5190 24881401 : tc = false;
5191 24881401 : se |= TREE_SIDE_EFFECTS (node);
5192 : }
5193 :
5194 :
5195 1462338067 : TREE_CONSTANT (t) = tc;
5196 1462338067 : TREE_SIDE_EFFECTS (t) = se;
5197 : #undef UPDATE_FLAGS
5198 1462338067 : }
5199 :
5200 : /* Build an expression of code CODE, data type TYPE, and operands as
5201 : specified. Expressions and reference nodes can be created this way.
5202 : Constants, decls, types and misc nodes cannot be.
5203 :
5204 : We define 5 non-variadic functions, from 0 to 4 arguments. This is
5205 : enough for all extant tree codes. */
5206 :
5207 : tree
5208 407235970 : build0 (enum tree_code code, tree tt MEM_STAT_DECL)
5209 : {
5210 407235970 : tree t;
5211 :
5212 407235970 : gcc_assert (TREE_CODE_LENGTH (code) == 0);
5213 :
5214 407235970 : t = make_node (code PASS_MEM_STAT);
5215 407235970 : TREE_TYPE (t) = tt;
5216 :
5217 407235970 : return t;
5218 : }
5219 :
5220 : tree
5221 4184373208 : build1 (enum tree_code code, tree type, tree node MEM_STAT_DECL)
5222 : {
5223 4184373208 : int length = sizeof (struct tree_exp);
5224 4184373208 : tree t;
5225 :
5226 4184373208 : record_node_allocation_statistics (code, length);
5227 :
5228 4184373208 : gcc_assert (TREE_CODE_LENGTH (code) == 1);
5229 :
5230 4184373208 : t = ggc_alloc_tree_node_stat (length PASS_MEM_STAT);
5231 :
5232 4184373208 : memset (t, 0, sizeof (struct tree_common));
5233 :
5234 4184373208 : TREE_SET_CODE (t, code);
5235 :
5236 4184373208 : TREE_TYPE (t) = type;
5237 4184373208 : SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
5238 4184373208 : TREE_OPERAND (t, 0) = node;
5239 4184373208 : if (node && !TYPE_P (node))
5240 : {
5241 4184310359 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
5242 4184310359 : TREE_READONLY (t) = TREE_READONLY (node);
5243 : }
5244 :
5245 4184373208 : if (TREE_CODE_CLASS (code) == tcc_statement)
5246 : {
5247 24616309 : if (code != DEBUG_BEGIN_STMT)
5248 24616309 : TREE_SIDE_EFFECTS (t) = 1;
5249 : }
5250 4159756899 : else switch (code)
5251 : {
5252 51200 : case VA_ARG_EXPR:
5253 : /* All of these have side-effects, no matter what their
5254 : operands are. */
5255 51200 : TREE_SIDE_EFFECTS (t) = 1;
5256 51200 : TREE_READONLY (t) = 0;
5257 51200 : break;
5258 :
5259 651613620 : case INDIRECT_REF:
5260 : /* Whether a dereference is readonly has nothing to do with whether
5261 : its operand is readonly. */
5262 651613620 : TREE_READONLY (t) = 0;
5263 651613620 : break;
5264 :
5265 695950785 : case ADDR_EXPR:
5266 695950785 : if (node)
5267 695950785 : recompute_tree_invariant_for_addr_expr (t);
5268 : break;
5269 :
5270 2812141294 : default:
5271 1038058119 : if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
5272 2660499780 : && node && !TYPE_P (node)
5273 5472641074 : && TREE_CONSTANT (node))
5274 735600540 : TREE_CONSTANT (t) = 1;
5275 2812141294 : if (TREE_CODE_CLASS (code) == tcc_reference
5276 889207999 : && node && TREE_THIS_VOLATILE (node))
5277 3059374 : TREE_THIS_VOLATILE (t) = 1;
5278 : break;
5279 : }
5280 :
5281 4184373208 : return t;
5282 : }
5283 :
5284 : #define PROCESS_ARG(N) \
5285 : do { \
5286 : TREE_OPERAND (t, N) = arg##N; \
5287 : if (arg##N &&!TYPE_P (arg##N)) \
5288 : { \
5289 : if (TREE_SIDE_EFFECTS (arg##N)) \
5290 : side_effects = 1; \
5291 : if (!TREE_READONLY (arg##N) \
5292 : && !CONSTANT_CLASS_P (arg##N)) \
5293 : (void) (read_only = 0); \
5294 : if (!TREE_CONSTANT (arg##N)) \
5295 : (void) (constant = 0); \
5296 : } \
5297 : } while (0)
5298 :
5299 : tree
5300 1333626548 : build2 (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
5301 : {
5302 1333626548 : bool constant, read_only, side_effects, div_by_zero;
5303 1333626548 : tree t;
5304 :
5305 1333626548 : gcc_assert (TREE_CODE_LENGTH (code) == 2);
5306 :
5307 1333626548 : if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
5308 196711733 : && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
5309 : /* When sizetype precision doesn't match that of pointers
5310 : we need to be able to build explicit extensions or truncations
5311 : of the offset argument. */
5312 1333626548 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
5313 0 : gcc_assert (TREE_CODE (arg0) == INTEGER_CST
5314 : && TREE_CODE (arg1) == INTEGER_CST);
5315 :
5316 1333626548 : if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
5317 63120143 : gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
5318 : && ptrofftype_p (TREE_TYPE (arg1)));
5319 :
5320 1333626548 : t = make_node (code PASS_MEM_STAT);
5321 1333626548 : TREE_TYPE (t) = tt;
5322 :
5323 : /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
5324 : result based on those same flags for the arguments. But if the
5325 : arguments aren't really even `tree' expressions, we shouldn't be trying
5326 : to do this. */
5327 :
5328 : /* Expressions without side effects may be constant if their
5329 : arguments are as well. */
5330 2667253096 : constant = (TREE_CODE_CLASS (code) == tcc_comparison
5331 1333626548 : || TREE_CODE_CLASS (code) == tcc_binary);
5332 1333626548 : read_only = 1;
5333 1333626548 : side_effects = TREE_SIDE_EFFECTS (t);
5334 :
5335 1333626548 : switch (code)
5336 : {
5337 14817356 : case TRUNC_DIV_EXPR:
5338 14817356 : case CEIL_DIV_EXPR:
5339 14817356 : case FLOOR_DIV_EXPR:
5340 14817356 : case ROUND_DIV_EXPR:
5341 14817356 : case EXACT_DIV_EXPR:
5342 14817356 : case CEIL_MOD_EXPR:
5343 14817356 : case FLOOR_MOD_EXPR:
5344 14817356 : case ROUND_MOD_EXPR:
5345 14817356 : case TRUNC_MOD_EXPR:
5346 14817356 : div_by_zero = integer_zerop (arg1);
5347 14817356 : break;
5348 : default:
5349 : div_by_zero = false;
5350 : }
5351 :
5352 1475679735 : PROCESS_ARG (0);
5353 1879753005 : PROCESS_ARG (1);
5354 :
5355 1333626548 : TREE_SIDE_EFFECTS (t) = side_effects;
5356 1333626548 : if (code == MEM_REF)
5357 : {
5358 84115118 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5359 : {
5360 23706461 : tree o = TREE_OPERAND (arg0, 0);
5361 23706461 : TREE_READONLY (t) = TREE_READONLY (o);
5362 23706461 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5363 : }
5364 : }
5365 : else
5366 : {
5367 1249511430 : TREE_READONLY (t) = read_only;
5368 : /* Don't mark X / 0 as constant. */
5369 1249511430 : TREE_CONSTANT (t) = constant && !div_by_zero;
5370 1249511430 : TREE_THIS_VOLATILE (t)
5371 1249511430 : = (TREE_CODE_CLASS (code) == tcc_reference
5372 1249511430 : && arg0 && TREE_THIS_VOLATILE (arg0));
5373 : }
5374 :
5375 1333626548 : return t;
5376 : }
5377 :
5378 :
5379 : tree
5380 492231146 : build3 (enum tree_code code, tree tt, tree arg0, tree arg1,
5381 : tree arg2 MEM_STAT_DECL)
5382 : {
5383 492231146 : bool constant, read_only, side_effects;
5384 492231146 : tree t;
5385 :
5386 492231146 : gcc_assert (TREE_CODE_LENGTH (code) == 3);
5387 492231146 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5388 :
5389 492231146 : t = make_node (code PASS_MEM_STAT);
5390 492231146 : TREE_TYPE (t) = tt;
5391 :
5392 492231146 : read_only = 1;
5393 :
5394 : /* As a special exception, if COND_EXPR has NULL branches, we
5395 : assume that it is a gimple statement and always consider
5396 : it to have side effects. */
5397 492231146 : if (code == COND_EXPR
5398 41397632 : && tt == void_type_node
5399 25888553 : && arg1 == NULL_TREE
5400 25888553 : && arg2 == NULL_TREE)
5401 : side_effects = true;
5402 : else
5403 492231146 : side_effects = TREE_SIDE_EFFECTS (t);
5404 :
5405 492231146 : PROCESS_ARG (0);
5406 492231146 : PROCESS_ARG (1);
5407 492231146 : PROCESS_ARG (2);
5408 :
5409 492231146 : if (code == COND_EXPR)
5410 41397632 : TREE_READONLY (t) = read_only;
5411 :
5412 492231146 : TREE_SIDE_EFFECTS (t) = side_effects;
5413 492231146 : TREE_THIS_VOLATILE (t)
5414 492231146 : = (TREE_CODE_CLASS (code) == tcc_reference
5415 492231146 : && arg0 && TREE_THIS_VOLATILE (arg0));
5416 :
5417 492231146 : return t;
5418 : }
5419 :
5420 : tree
5421 59831207 : build4 (enum tree_code code, tree tt, tree arg0, tree arg1,
5422 : tree arg2, tree arg3 MEM_STAT_DECL)
5423 : {
5424 59831207 : bool constant, read_only, side_effects;
5425 59831207 : tree t;
5426 :
5427 59831207 : gcc_assert (TREE_CODE_LENGTH (code) == 4);
5428 :
5429 59831207 : t = make_node (code PASS_MEM_STAT);
5430 59831207 : TREE_TYPE (t) = tt;
5431 :
5432 59831207 : side_effects = TREE_SIDE_EFFECTS (t);
5433 :
5434 59831207 : PROCESS_ARG (0);
5435 59831207 : PROCESS_ARG (1);
5436 59831207 : PROCESS_ARG (2);
5437 59831207 : PROCESS_ARG (3);
5438 :
5439 59831207 : TREE_SIDE_EFFECTS (t) = side_effects;
5440 59831207 : TREE_THIS_VOLATILE (t)
5441 119662414 : = (TREE_CODE_CLASS (code) == tcc_reference
5442 59831207 : && arg0 && TREE_THIS_VOLATILE (arg0));
5443 :
5444 59831207 : return t;
5445 : }
5446 :
5447 : tree
5448 1177649 : build5 (enum tree_code code, tree tt, tree arg0, tree arg1,
5449 : tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
5450 : {
5451 1177649 : bool constant, read_only, side_effects;
5452 1177649 : tree t;
5453 :
5454 1177649 : gcc_assert (TREE_CODE_LENGTH (code) == 5);
5455 :
5456 1177649 : t = make_node (code PASS_MEM_STAT);
5457 1177649 : TREE_TYPE (t) = tt;
5458 :
5459 1177649 : side_effects = TREE_SIDE_EFFECTS (t);
5460 :
5461 1177649 : PROCESS_ARG (0);
5462 1177649 : PROCESS_ARG (1);
5463 1177649 : PROCESS_ARG (2);
5464 1177649 : PROCESS_ARG (3);
5465 1177649 : PROCESS_ARG (4);
5466 :
5467 1177649 : TREE_SIDE_EFFECTS (t) = side_effects;
5468 1177649 : if (code == TARGET_MEM_REF)
5469 : {
5470 1168756 : if (arg0 && TREE_CODE (arg0) == ADDR_EXPR)
5471 : {
5472 182696 : tree o = TREE_OPERAND (arg0, 0);
5473 182696 : TREE_READONLY (t) = TREE_READONLY (o);
5474 182696 : TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (o);
5475 : }
5476 : }
5477 : else
5478 8893 : TREE_THIS_VOLATILE (t)
5479 8893 : = (TREE_CODE_CLASS (code) == tcc_reference
5480 8893 : && arg0 && TREE_THIS_VOLATILE (arg0));
5481 :
5482 1177649 : return t;
5483 : }
5484 :
5485 : /* Build a simple MEM_REF tree with the semantics of a plain INDIRECT_REF
5486 : on the pointer PTR. */
5487 :
5488 : tree
5489 486127 : build_simple_mem_ref_loc (location_t loc, tree ptr)
5490 : {
5491 486127 : poly_int64 offset = 0;
5492 486127 : tree ptype = TREE_TYPE (ptr);
5493 486127 : tree tem;
5494 : /* For convenience allow addresses that collapse to a simple base
5495 : and offset. */
5496 486127 : if (TREE_CODE (ptr) == ADDR_EXPR
5497 486127 : && (handled_component_p (TREE_OPERAND (ptr, 0))
5498 15619 : || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
5499 : {
5500 147 : ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
5501 147 : gcc_assert (ptr);
5502 147 : if (TREE_CODE (ptr) == MEM_REF)
5503 : {
5504 37 : offset += mem_ref_offset (ptr).force_shwi ();
5505 37 : ptr = TREE_OPERAND (ptr, 0);
5506 : }
5507 : else
5508 110 : ptr = build_fold_addr_expr (ptr);
5509 147 : gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
5510 : }
5511 486127 : tem = build2 (MEM_REF, TREE_TYPE (ptype),
5512 : ptr, build_int_cst (ptype, offset));
5513 486127 : SET_EXPR_LOCATION (tem, loc);
5514 486127 : return tem;
5515 : }
5516 :
5517 : /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
5518 :
5519 : poly_offset_int
5520 1242088385 : mem_ref_offset (const_tree t)
5521 : {
5522 1242088385 : return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
5523 1242088385 : SIGNED);
5524 : }
5525 :
5526 : /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
5527 : offsetted by OFFSET units. */
5528 :
5529 : tree
5530 201022 : build_invariant_address (tree type, tree base, poly_int64 offset)
5531 : {
5532 201022 : tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
5533 : build_fold_addr_expr (base),
5534 : build_int_cst (ptr_type_node, offset));
5535 201022 : tree addr = build1 (ADDR_EXPR, type, ref);
5536 201022 : recompute_tree_invariant_for_addr_expr (addr);
5537 201022 : return addr;
5538 : }
5539 :
5540 : /* Similar except don't specify the TREE_TYPE
5541 : and leave the TREE_SIDE_EFFECTS as 0.
5542 : It is permissible for arguments to be null,
5543 : or even garbage if their values do not matter. */
5544 :
5545 : tree
5546 5895112 : build_nt (enum tree_code code, ...)
5547 : {
5548 5895112 : tree t;
5549 5895112 : int length;
5550 5895112 : int i;
5551 5895112 : va_list p;
5552 :
5553 5895112 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
5554 :
5555 5895112 : va_start (p, code);
5556 :
5557 5895112 : t = make_node (code);
5558 5895112 : length = TREE_CODE_LENGTH (code);
5559 :
5560 17469023 : for (i = 0; i < length; i++)
5561 11573911 : TREE_OPERAND (t, i) = va_arg (p, tree);
5562 :
5563 5895112 : va_end (p);
5564 5895112 : return t;
5565 : }
5566 :
5567 : /* Similar to build_nt, but for creating a CALL_EXPR object with a
5568 : tree vec. */
5569 :
5570 : tree
5571 0 : build_nt_call_vec (tree fn, vec<tree, va_gc> *args)
5572 : {
5573 0 : tree ret, t;
5574 0 : unsigned int ix;
5575 :
5576 0 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
5577 0 : CALL_EXPR_FN (ret) = fn;
5578 0 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
5579 0 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
5580 0 : CALL_EXPR_ARG (ret, ix) = t;
5581 0 : return ret;
5582 : }
5583 :
5584 : /* Create a DECL_... node of code CODE, name NAME (if non-null)
5585 : and data type TYPE.
5586 : We do NOT enter this node in any sort of symbol table.
5587 :
5588 : LOC is the location of the decl.
5589 :
5590 : layout_decl is used to set up the decl's storage layout.
5591 : Other slots are initialized to 0 or null pointers. */
5592 :
5593 : tree
5594 3331040659 : build_decl (location_t loc, enum tree_code code, tree name,
5595 : tree type MEM_STAT_DECL)
5596 : {
5597 3331040659 : tree t;
5598 :
5599 3331040659 : t = make_node (code PASS_MEM_STAT);
5600 3331040659 : DECL_SOURCE_LOCATION (t) = loc;
5601 :
5602 : /* if (type == error_mark_node)
5603 : type = integer_type_node; */
5604 : /* That is not done, deliberately, so that having error_mark_node
5605 : as the type can suppress useless errors in the use of this variable. */
5606 :
5607 3331040659 : DECL_NAME (t) = name;
5608 3331040659 : TREE_TYPE (t) = type;
5609 :
5610 3331040659 : if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
5611 1181233820 : layout_decl (t, 0);
5612 :
5613 3331040659 : return t;
5614 : }
5615 :
5616 : /* Create and return a DEBUG_EXPR_DECL node of the given TYPE. */
5617 :
5618 : tree
5619 1764509 : build_debug_expr_decl (tree type)
5620 : {
5621 1764509 : tree vexpr = make_node (DEBUG_EXPR_DECL);
5622 1764509 : DECL_ARTIFICIAL (vexpr) = 1;
5623 1764509 : TREE_TYPE (vexpr) = type;
5624 1764509 : SET_DECL_MODE (vexpr, TYPE_MODE (type));
5625 1764509 : return vexpr;
5626 : }
5627 :
5628 : /* Builds and returns function declaration with NAME and TYPE. */
5629 :
5630 : tree
5631 21460 : build_fn_decl (const char *name, tree type)
5632 : {
5633 21460 : tree id = get_identifier (name);
5634 21460 : tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
5635 :
5636 21460 : DECL_EXTERNAL (decl) = 1;
5637 21460 : TREE_PUBLIC (decl) = 1;
5638 21460 : DECL_ARTIFICIAL (decl) = 1;
5639 21460 : TREE_NOTHROW (decl) = 1;
5640 :
5641 21460 : return decl;
5642 : }
5643 :
5644 : vec<tree, va_gc> *all_translation_units;
5645 :
5646 : /* Builds a new translation-unit decl with name NAME, queues it in the
5647 : global list of translation-unit decls and returns it. */
5648 :
5649 : tree
5650 257206 : build_translation_unit_decl (tree name)
5651 : {
5652 257206 : tree tu = build_decl (UNKNOWN_LOCATION, TRANSLATION_UNIT_DECL,
5653 257206 : name, NULL_TREE);
5654 257206 : TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
5655 257206 : vec_safe_push (all_translation_units, tu);
5656 257206 : return tu;
5657 : }
5658 :
5659 :
5660 : /* BLOCK nodes are used to represent the structure of binding contours
5661 : and declarations, once those contours have been exited and their contents
5662 : compiled. This information is used for outputting debugging info. */
5663 :
5664 : tree
5665 740365 : build_block (tree vars, tree subblocks, tree supercontext, tree chain)
5666 : {
5667 740365 : tree block = make_node (BLOCK);
5668 :
5669 740365 : BLOCK_VARS (block) = vars;
5670 740365 : BLOCK_SUBBLOCKS (block) = subblocks;
5671 740365 : BLOCK_SUPERCONTEXT (block) = supercontext;
5672 740365 : BLOCK_CHAIN (block) = chain;
5673 740365 : return block;
5674 : }
5675 :
5676 :
5677 : /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
5678 :
5679 : LOC is the location to use in tree T. */
5680 :
5681 : void
5682 15175022737 : protected_set_expr_location (tree t, location_t loc)
5683 : {
5684 15175022737 : if (CAN_HAVE_LOCATION_P (t))
5685 2403155224 : SET_EXPR_LOCATION (t, loc);
5686 12680648279 : else if (t && TREE_CODE (t) == STATEMENT_LIST)
5687 : {
5688 22265 : t = expr_single (t);
5689 22265 : if (t && CAN_HAVE_LOCATION_P (t))
5690 18 : SET_EXPR_LOCATION (t, loc);
5691 : }
5692 15175022737 : }
5693 :
5694 : /* Like PROTECTED_SET_EXPR_LOCATION, but only do that if T has
5695 : UNKNOWN_LOCATION. */
5696 :
5697 : void
5698 26579540 : protected_set_expr_location_if_unset (tree t, location_t loc)
5699 : {
5700 26579540 : t = expr_single (t);
5701 26579540 : if (t && !EXPR_HAS_LOCATION (t))
5702 17471195 : protected_set_expr_location (t, loc);
5703 26579540 : }
5704 :
5705 : /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5706 : of the various TYPE_QUAL values. */
5707 :
5708 : static void
5709 115426736 : set_type_quals (tree type, int type_quals)
5710 : {
5711 115426736 : TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
5712 115426736 : TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
5713 115426736 : TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
5714 115426736 : TYPE_ATOMIC (type) = (type_quals & TYPE_QUAL_ATOMIC) != 0;
5715 115426736 : TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
5716 115426736 : }
5717 :
5718 : /* Returns true iff CAND and BASE have equivalent language-specific
5719 : qualifiers. */
5720 :
5721 : bool
5722 3309697446 : check_lang_type (const_tree cand, const_tree base)
5723 : {
5724 3309697446 : if (lang_hooks.types.type_hash_eq == NULL)
5725 : return true;
5726 : /* type_hash_eq currently only applies to these types. */
5727 3251828424 : if (TREE_CODE (cand) != FUNCTION_TYPE
5728 3251828424 : && TREE_CODE (cand) != METHOD_TYPE)
5729 : return true;
5730 1191323 : return lang_hooks.types.type_hash_eq (cand, base);
5731 : }
5732 :
5733 : /* This function checks to see if TYPE matches the size one of the built-in
5734 : atomic types, and returns that core atomic type. */
5735 :
5736 : static tree
5737 8918 : find_atomic_core_type (const_tree type)
5738 : {
5739 8918 : tree base_atomic_type;
5740 :
5741 : /* Only handle complete types. */
5742 8918 : if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
5743 : return NULL_TREE;
5744 :
5745 8906 : switch (tree_to_uhwi (TYPE_SIZE (type)))
5746 : {
5747 2710 : case 8:
5748 2710 : base_atomic_type = atomicQI_type_node;
5749 2710 : break;
5750 :
5751 862 : case 16:
5752 862 : base_atomic_type = atomicHI_type_node;
5753 862 : break;
5754 :
5755 1117 : case 32:
5756 1117 : base_atomic_type = atomicSI_type_node;
5757 1117 : break;
5758 :
5759 2749 : case 64:
5760 2749 : base_atomic_type = atomicDI_type_node;
5761 2749 : break;
5762 :
5763 1348 : case 128:
5764 1348 : base_atomic_type = atomicTI_type_node;
5765 1348 : break;
5766 :
5767 : default:
5768 : base_atomic_type = NULL_TREE;
5769 : }
5770 :
5771 : return base_atomic_type;
5772 : }
5773 :
5774 : /* Returns true iff unqualified CAND and BASE are equivalent. */
5775 :
5776 : bool
5777 5251683105 : check_base_type (const_tree cand, const_tree base)
5778 : {
5779 5251683105 : if (TYPE_NAME (cand) != TYPE_NAME (base)
5780 : /* Apparently this is needed for Objective-C. */
5781 4624869412 : || TYPE_CONTEXT (cand) != TYPE_CONTEXT (base)
5782 9876552516 : || !attribute_list_equal (TYPE_ATTRIBUTES (cand),
5783 4624869411 : TYPE_ATTRIBUTES (base)))
5784 : return false;
5785 : /* Check alignment. */
5786 4624869411 : if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
5787 4624869411 : && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
5788 : return true;
5789 : /* Atomic types increase minimal alignment. We must to do so as well
5790 : or we get duplicated canonical types. See PR88686. */
5791 11284 : if ((TYPE_QUALS (cand) & TYPE_QUAL_ATOMIC))
5792 : {
5793 : /* See if this object can map to a basic atomic type. */
5794 1775 : tree atomic_type = find_atomic_core_type (cand);
5795 1775 : if (atomic_type && TYPE_ALIGN (atomic_type) == TYPE_ALIGN (cand))
5796 1775 : return true;
5797 : }
5798 : return false;
5799 : }
5800 :
5801 : /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
5802 :
5803 : bool
5804 5632937666 : check_qualified_type (const_tree cand, const_tree base, int type_quals)
5805 : {
5806 5632937666 : return (TYPE_QUALS (cand) == type_quals
5807 3934300592 : && check_base_type (cand, base)
5808 8940779218 : && check_lang_type (cand, base));
5809 : }
5810 :
5811 : /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5812 :
5813 : static bool
5814 3870326 : check_aligned_type (const_tree cand, const_tree base, unsigned int align)
5815 : {
5816 3870326 : return (TYPE_QUALS (cand) == TYPE_QUALS (base)
5817 3142515 : && TYPE_NAME (cand) == TYPE_NAME (base)
5818 : /* Apparently this is needed for Objective-C. */
5819 2224277 : && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
5820 : /* Check alignment. */
5821 2224277 : && TYPE_ALIGN (cand) == align
5822 : /* Check this is a user-aligned type as build_aligned_type
5823 : would create. */
5824 1053614 : && TYPE_USER_ALIGN (cand)
5825 1050774 : && attribute_list_equal (TYPE_ATTRIBUTES (cand),
5826 1050774 : TYPE_ATTRIBUTES (base))
5827 4921100 : && check_lang_type (cand, base));
5828 : }
5829 :
5830 : /* Return a version of the TYPE, qualified as indicated by the
5831 : TYPE_QUALS, if one exists. If no qualified version exists yet,
5832 : return NULL_TREE. */
5833 :
5834 : tree
5835 4827609942 : get_qualified_type (tree type, int type_quals)
5836 : {
5837 4827609942 : if (TYPE_QUALS (type) == type_quals)
5838 : return type;
5839 :
5840 3423423320 : tree mv = TYPE_MAIN_VARIANT (type);
5841 3423423320 : if (check_qualified_type (mv, type, type_quals))
5842 : return mv;
5843 :
5844 : /* Search the chain of variants to see if there is already one there just
5845 : like the one we need to have. If so, use that existing one. We must
5846 : preserve the TYPE_NAME, since there is code that depends on this. */
5847 2325106722 : for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
5848 2209450544 : if (check_qualified_type (*tp, type, type_quals))
5849 : {
5850 : /* Put the found variant at the head of the variant list so
5851 : frequently searched variants get found faster. The C++ FE
5852 : benefits greatly from this. */
5853 1387645380 : tree t = *tp;
5854 1387645380 : *tp = TYPE_NEXT_VARIANT (t);
5855 1387645380 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
5856 1387645380 : TYPE_NEXT_VARIANT (mv) = t;
5857 1387645380 : return t;
5858 : }
5859 :
5860 : return NULL_TREE;
5861 : }
5862 :
5863 : /* Like get_qualified_type, but creates the type if it does not
5864 : exist. This function never returns NULL_TREE. */
5865 :
5866 : tree
5867 4321649217 : build_qualified_type (tree type, int type_quals MEM_STAT_DECL)
5868 : {
5869 4321649217 : tree t;
5870 :
5871 : /* See if we already have the appropriate qualified variant. */
5872 4321649217 : t = get_qualified_type (type, type_quals);
5873 :
5874 : /* If not, build it. */
5875 4321649217 : if (!t)
5876 : {
5877 113955536 : t = build_variant_type_copy (type PASS_MEM_STAT);
5878 113955536 : set_type_quals (t, type_quals);
5879 :
5880 113955536 : if (((type_quals & TYPE_QUAL_ATOMIC) == TYPE_QUAL_ATOMIC))
5881 : {
5882 : /* See if this object can map to a basic atomic type. */
5883 7143 : tree atomic_type = find_atomic_core_type (type);
5884 7143 : if (atomic_type)
5885 : {
5886 : /* Ensure the alignment of this type is compatible with
5887 : the required alignment of the atomic type. */
5888 7011 : if (TYPE_ALIGN (atomic_type) > TYPE_ALIGN (t))
5889 98 : SET_TYPE_ALIGN (t, TYPE_ALIGN (atomic_type));
5890 : }
5891 : }
5892 :
5893 113955536 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5894 : /* Propagate structural equality. */
5895 5792259 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5896 108163277 : else if (TYPE_CANONICAL (type) != type)
5897 : /* Build the underlying canonical type, since it is different
5898 : from TYPE. */
5899 : {
5900 35368264 : tree c = build_qualified_type (TYPE_CANONICAL (type), type_quals);
5901 35368264 : TYPE_CANONICAL (t) = TYPE_CANONICAL (c);
5902 : }
5903 : else
5904 : /* T is its own canonical type. */
5905 72795013 : TYPE_CANONICAL (t) = t;
5906 :
5907 : }
5908 :
5909 4321649217 : return t;
5910 : }
5911 :
5912 : /* Create a variant of type T with alignment ALIGN which
5913 : is measured in bits. */
5914 :
5915 : tree
5916 1344598 : build_aligned_type (tree type, unsigned int align)
5917 : {
5918 1344598 : tree t;
5919 :
5920 1344598 : if (TYPE_PACKED (type)
5921 1344598 : || TYPE_ALIGN (type) == align)
5922 : return type;
5923 :
5924 3979651 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
5925 3870326 : if (check_aligned_type (t, type, align))
5926 : return t;
5927 :
5928 109325 : t = build_variant_type_copy (type);
5929 109325 : SET_TYPE_ALIGN (t, align);
5930 109325 : TYPE_USER_ALIGN (t) = 1;
5931 :
5932 109325 : return t;
5933 : }
5934 :
5935 : /* Create a new distinct copy of TYPE. The new type is made its own
5936 : MAIN_VARIANT. If TYPE requires structural equality checks, the
5937 : resulting type requires structural equality checks; otherwise, its
5938 : TYPE_CANONICAL points to itself. */
5939 :
5940 : tree
5941 820697997 : build_distinct_type_copy (tree type MEM_STAT_DECL)
5942 : {
5943 820697997 : tree t = copy_node (type PASS_MEM_STAT);
5944 :
5945 820697997 : TYPE_POINTER_TO (t) = 0;
5946 820697997 : TYPE_REFERENCE_TO (t) = 0;
5947 :
5948 : /* Set the canonical type either to a new equivalence class, or
5949 : propagate the need for structural equality checks. */
5950 820697997 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
5951 69363232 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5952 : else
5953 751334765 : TYPE_CANONICAL (t) = t;
5954 :
5955 : /* Make it its own variant. */
5956 820697997 : TYPE_MAIN_VARIANT (t) = t;
5957 820697997 : TYPE_NEXT_VARIANT (t) = 0;
5958 :
5959 : /* Note that it is now possible for TYPE_MIN_VALUE to be a value
5960 : whose TREE_TYPE is not t. This can also happen in the Ada
5961 : frontend when using subtypes. */
5962 :
5963 820697997 : return t;
5964 : }
5965 :
5966 : /* Create a new variant of TYPE, equivalent but distinct. This is so
5967 : the caller can modify it. TYPE_CANONICAL for the return type will
5968 : be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
5969 : are considered equal by the language itself (or that both types
5970 : require structural equality checks). */
5971 :
5972 : tree
5973 529988953 : build_variant_type_copy (tree type MEM_STAT_DECL)
5974 : {
5975 529988953 : tree t, m = TYPE_MAIN_VARIANT (type);
5976 :
5977 529988953 : t = build_distinct_type_copy (type PASS_MEM_STAT);
5978 :
5979 : /* Since we're building a variant, assume that it is a non-semantic
5980 : variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
5981 529988953 : TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
5982 : /* Type variants have no alias set defined. */
5983 529988953 : TYPE_ALIAS_SET (t) = -1;
5984 :
5985 : /* Add the new type to the chain of variants of TYPE. */
5986 529988953 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
5987 529988953 : TYPE_NEXT_VARIANT (m) = t;
5988 529988953 : TYPE_MAIN_VARIANT (t) = m;
5989 :
5990 529988953 : return t;
5991 : }
5992 :
5993 : /* Return true if the from tree in both tree maps are equal. */
5994 :
5995 : int
5996 1912665206 : tree_map_base_eq (const void *va, const void *vb)
5997 : {
5998 1912665206 : const struct tree_map_base *const a = (const struct tree_map_base *) va,
5999 1912665206 : *const b = (const struct tree_map_base *) vb;
6000 1912665206 : return (a->from == b->from);
6001 : }
6002 :
6003 : /* Hash a from tree in a tree_base_map. */
6004 :
6005 : unsigned int
6006 0 : tree_map_base_hash (const void *item)
6007 : {
6008 0 : return htab_hash_pointer (((const struct tree_map_base *)item)->from);
6009 : }
6010 :
6011 : /* Return true if this tree map structure is marked for garbage collection
6012 : purposes. We simply return true if the from tree is marked, so that this
6013 : structure goes away when the from tree goes away. */
6014 :
6015 : bool
6016 0 : tree_map_base_marked_p (const void *p)
6017 : {
6018 0 : return ggc_marked_p (((const struct tree_map_base *) p)->from);
6019 : }
6020 :
6021 : /* Hash a from tree in a tree_map. */
6022 :
6023 : unsigned int
6024 254 : tree_map_hash (const void *item)
6025 : {
6026 254 : return (((const struct tree_map *) item)->hash);
6027 : }
6028 :
6029 : /* Hash a from tree in a tree_decl_map. */
6030 :
6031 : unsigned int
6032 1300927694 : tree_decl_map_hash (const void *item)
6033 : {
6034 1300927694 : return DECL_UID (((const struct tree_decl_map *) item)->base.from);
6035 : }
6036 :
6037 : /* Return the initialization priority for DECL. */
6038 :
6039 : priority_type
6040 23092 : decl_init_priority_lookup (tree decl)
6041 : {
6042 23092 : symtab_node *snode = symtab_node::get (decl);
6043 :
6044 23092 : if (!snode)
6045 : return DEFAULT_INIT_PRIORITY;
6046 23092 : return
6047 23092 : snode->get_init_priority ();
6048 : }
6049 :
6050 : /* Return the finalization priority for DECL. */
6051 :
6052 : priority_type
6053 1880 : decl_fini_priority_lookup (tree decl)
6054 : {
6055 1880 : cgraph_node *node = cgraph_node::get (decl);
6056 :
6057 1880 : if (!node)
6058 : return DEFAULT_INIT_PRIORITY;
6059 1880 : return
6060 1880 : node->get_fini_priority ();
6061 : }
6062 :
6063 : /* Set the initialization priority for DECL to PRIORITY. */
6064 :
6065 : void
6066 24691 : decl_init_priority_insert (tree decl, priority_type priority)
6067 : {
6068 24691 : struct symtab_node *snode;
6069 :
6070 24691 : if (priority == DEFAULT_INIT_PRIORITY)
6071 : {
6072 21141 : snode = symtab_node::get (decl);
6073 21141 : if (!snode)
6074 : return;
6075 : }
6076 3550 : else if (VAR_P (decl))
6077 45 : snode = varpool_node::get_create (decl);
6078 : else
6079 3505 : snode = cgraph_node::get_create (decl);
6080 23836 : snode->set_init_priority (priority);
6081 : }
6082 :
6083 : /* Set the finalization priority for DECL to PRIORITY. */
6084 :
6085 : void
6086 1740 : decl_fini_priority_insert (tree decl, priority_type priority)
6087 : {
6088 1740 : struct cgraph_node *node;
6089 :
6090 1740 : if (priority == DEFAULT_INIT_PRIORITY)
6091 : {
6092 105 : node = cgraph_node::get (decl);
6093 105 : if (!node)
6094 : return;
6095 : }
6096 : else
6097 1635 : node = cgraph_node::get_create (decl);
6098 1645 : node->set_fini_priority (priority);
6099 : }
6100 :
6101 : /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6102 :
6103 : static void
6104 0 : print_debug_expr_statistics (void)
6105 : {
6106 0 : fprintf (stderr, "DECL_DEBUG_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6107 : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6108 0 : (fmt_size_t) debug_expr_for_decl->size (),
6109 0 : (fmt_size_t) debug_expr_for_decl->elements (),
6110 : debug_expr_for_decl->collisions ());
6111 0 : }
6112 :
6113 : /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6114 :
6115 : static void
6116 0 : print_value_expr_statistics (void)
6117 : {
6118 0 : fprintf (stderr, "DECL_VALUE_EXPR hash: size " HOST_SIZE_T_PRINT_DEC ", "
6119 : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6120 0 : (fmt_size_t) value_expr_for_decl->size (),
6121 0 : (fmt_size_t) value_expr_for_decl->elements (),
6122 : value_expr_for_decl->collisions ());
6123 0 : }
6124 :
6125 : /* Lookup a debug expression for FROM, and return it if we find one. */
6126 :
6127 : tree
6128 451826209 : decl_debug_expr_lookup (tree from)
6129 : {
6130 451826209 : struct tree_decl_map *h, in;
6131 451826209 : in.base.from = from;
6132 :
6133 451826209 : h = debug_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6134 451826209 : if (h)
6135 451826209 : return h->to;
6136 : return NULL_TREE;
6137 : }
6138 :
6139 : /* Insert a mapping FROM->TO in the debug expression hashtable. */
6140 :
6141 : void
6142 1428001 : decl_debug_expr_insert (tree from, tree to)
6143 : {
6144 1428001 : struct tree_decl_map *h;
6145 :
6146 1428001 : h = ggc_alloc<tree_decl_map> ();
6147 1428001 : h->base.from = from;
6148 1428001 : h->to = to;
6149 1428001 : *debug_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6150 1428001 : }
6151 :
6152 : /* Lookup a value expression for FROM, and return it if we find one. */
6153 :
6154 : tree
6155 24355965 : decl_value_expr_lookup (tree from)
6156 : {
6157 24355965 : struct tree_decl_map *h, in;
6158 24355965 : in.base.from = from;
6159 :
6160 24355965 : h = value_expr_for_decl->find_with_hash (&in, DECL_UID (from));
6161 24355965 : if (h)
6162 24355965 : return h->to;
6163 : return NULL_TREE;
6164 : }
6165 :
6166 : /* Insert a mapping FROM->TO in the value expression hashtable. */
6167 :
6168 : void
6169 8999002 : decl_value_expr_insert (tree from, tree to)
6170 : {
6171 8999002 : struct tree_decl_map *h;
6172 :
6173 : /* Uses of FROM shouldn't look like they happen at the location of TO. */
6174 8999002 : to = protected_set_expr_location_unshare (to, UNKNOWN_LOCATION);
6175 :
6176 8999002 : h = ggc_alloc<tree_decl_map> ();
6177 8999002 : h->base.from = from;
6178 8999002 : h->to = to;
6179 8999002 : *value_expr_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT) = h;
6180 8999002 : }
6181 :
6182 : /* Lookup a vector of debug arguments for FROM, and return it if we
6183 : find one. */
6184 :
6185 : vec<tree, va_gc> **
6186 1000992 : decl_debug_args_lookup (tree from)
6187 : {
6188 1000992 : struct tree_vec_map *h, in;
6189 :
6190 1000992 : if (!DECL_HAS_DEBUG_ARGS_P (from))
6191 : return NULL;
6192 857849 : gcc_checking_assert (debug_args_for_decl != NULL);
6193 857849 : in.base.from = from;
6194 857849 : h = debug_args_for_decl->find_with_hash (&in, DECL_UID (from));
6195 857849 : if (h)
6196 853851 : return &h->to;
6197 : return NULL;
6198 : }
6199 :
6200 : /* Insert a mapping FROM->empty vector of debug arguments in the value
6201 : expression hashtable. */
6202 :
6203 : vec<tree, va_gc> **
6204 317616 : decl_debug_args_insert (tree from)
6205 : {
6206 317616 : struct tree_vec_map *h;
6207 317616 : tree_vec_map **loc;
6208 :
6209 317616 : if (DECL_HAS_DEBUG_ARGS_P (from))
6210 222326 : return decl_debug_args_lookup (from);
6211 95290 : if (debug_args_for_decl == NULL)
6212 8688 : debug_args_for_decl = hash_table<tree_vec_map_cache_hasher>::create_ggc (64);
6213 95290 : h = ggc_alloc<tree_vec_map> ();
6214 95290 : h->base.from = from;
6215 95290 : h->to = NULL;
6216 95290 : loc = debug_args_for_decl->find_slot_with_hash (h, DECL_UID (from), INSERT);
6217 95290 : *loc = h;
6218 95290 : DECL_HAS_DEBUG_ARGS_P (from) = 1;
6219 95290 : return &h->to;
6220 : }
6221 :
6222 : /* Hashing of types so that we don't make duplicates.
6223 : The entry point is `type_hash_canon'. */
6224 :
6225 : /* Generate the default hash code for TYPE. This is designed for
6226 : speed, rather than maximum entropy. */
6227 :
6228 : hashval_t
6229 1480744503 : type_hash_canon_hash (tree type)
6230 : {
6231 1480744503 : inchash::hash hstate;
6232 :
6233 1480744503 : hstate.add_int (TREE_CODE (type));
6234 :
6235 1480744503 : hstate.add_flag (TYPE_STRUCTURAL_EQUALITY_P (type));
6236 :
6237 1480744503 : if (TREE_TYPE (type))
6238 1480660537 : hstate.add_object (TYPE_HASH (TREE_TYPE (type)));
6239 :
6240 1766364446 : for (tree t = TYPE_ATTRIBUTES (type); t; t = TREE_CHAIN (t))
6241 : /* Just the identifier is adequate to distinguish. */
6242 285619943 : hstate.add_object (IDENTIFIER_HASH_VALUE (get_attribute_name (t)));
6243 :
6244 1480744503 : switch (TREE_CODE (type))
6245 : {
6246 348730409 : case METHOD_TYPE:
6247 348730409 : hstate.add_object (TYPE_HASH (TYPE_METHOD_BASETYPE (type)));
6248 : /* FALLTHROUGH. */
6249 1281806058 : case FUNCTION_TYPE:
6250 5056572269 : for (tree t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
6251 3774766211 : if (TREE_VALUE (t) != error_mark_node)
6252 3774724764 : hstate.add_object (TYPE_HASH (TREE_VALUE (t)));
6253 : break;
6254 :
6255 1000228 : case OFFSET_TYPE:
6256 1000228 : hstate.add_object (TYPE_HASH (TYPE_OFFSET_BASETYPE (type)));
6257 1000228 : break;
6258 :
6259 74813532 : case ARRAY_TYPE:
6260 74813532 : {
6261 74813532 : if (TYPE_DOMAIN (type))
6262 71766602 : hstate.add_object (TYPE_HASH (TYPE_DOMAIN (type)));
6263 74813532 : if (!AGGREGATE_TYPE_P (TREE_TYPE (type)))
6264 : {
6265 72291889 : unsigned typeless = TYPE_TYPELESS_STORAGE (type);
6266 72291889 : hstate.add_object (typeless);
6267 : }
6268 : }
6269 : break;
6270 :
6271 44317388 : case INTEGER_TYPE:
6272 44317388 : {
6273 44317388 : tree t = TYPE_MAX_VALUE (type);
6274 44317388 : if (!t)
6275 558565 : t = TYPE_MIN_VALUE (type);
6276 88634777 : for (int i = 0; i < TREE_INT_CST_NUNITS (t); i++)
6277 44317389 : hstate.add_object (TREE_INT_CST_ELT (t, i));
6278 : break;
6279 : }
6280 :
6281 61497 : case BITINT_TYPE:
6282 61497 : {
6283 61497 : unsigned prec = TYPE_PRECISION (type);
6284 61497 : unsigned uns = TYPE_UNSIGNED (type);
6285 61497 : hstate.add_object (prec);
6286 61497 : hstate.add_int (uns);
6287 61497 : break;
6288 : }
6289 :
6290 12082 : case REAL_TYPE:
6291 12082 : case FIXED_POINT_TYPE:
6292 12082 : {
6293 12082 : unsigned prec = TYPE_PRECISION (type);
6294 12082 : hstate.add_object (prec);
6295 12082 : break;
6296 : }
6297 :
6298 72978970 : case VECTOR_TYPE:
6299 72978970 : hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type));
6300 72978970 : break;
6301 :
6302 : case REFERENCE_TYPE:
6303 1480744503 : hstate.add_flag (TYPE_REF_IS_RVALUE (type));
6304 : break;
6305 :
6306 : default:
6307 : break;
6308 : }
6309 :
6310 1480744503 : return hstate.end ();
6311 : }
6312 :
6313 : /* These are the Hashtable callback functions. */
6314 :
6315 : /* Returns true iff the types are equivalent. */
6316 :
6317 : bool
6318 10343302435 : type_cache_hasher::equal (type_hash *a, type_hash *b)
6319 : {
6320 : /* First test the things that are the same for all types. */
6321 10343302435 : if (a->hash != b->hash
6322 724990877 : || TREE_CODE (a->type) != TREE_CODE (b->type)
6323 724990077 : || TREE_TYPE (a->type) != TREE_TYPE (b->type)
6324 724981069 : || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
6325 724981069 : TYPE_ATTRIBUTES (b->type))
6326 11061031716 : || (TREE_CODE (a->type) != COMPLEX_TYPE
6327 715471258 : && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
6328 : return false;
6329 :
6330 : /* Be careful about comparing arrays before and after the element type
6331 : has been completed; don't compare TYPE_ALIGN unless both types are
6332 : complete. */
6333 1430394628 : if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type)
6334 1430394628 : && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
6335 713569602 : || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
6336 : return false;
6337 :
6338 716823829 : if (TYPE_STRUCTURAL_EQUALITY_P (a->type)
6339 716823829 : != TYPE_STRUCTURAL_EQUALITY_P (b->type))
6340 : return false;
6341 :
6342 716814004 : switch (TREE_CODE (a->type))
6343 : {
6344 : case VOID_TYPE:
6345 : case OPAQUE_TYPE:
6346 : case COMPLEX_TYPE:
6347 : case POINTER_TYPE:
6348 : case NULLPTR_TYPE:
6349 : return true;
6350 :
6351 66293431 : case VECTOR_TYPE:
6352 66293431 : return known_eq (TYPE_VECTOR_SUBPARTS (a->type),
6353 : TYPE_VECTOR_SUBPARTS (b->type));
6354 :
6355 0 : case ENUMERAL_TYPE:
6356 0 : if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6357 0 : && !(TYPE_VALUES (a->type)
6358 0 : && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6359 0 : && TYPE_VALUES (b->type)
6360 0 : && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
6361 0 : && type_list_equal (TYPE_VALUES (a->type),
6362 0 : TYPE_VALUES (b->type))))
6363 : return false;
6364 :
6365 : /* fall through */
6366 :
6367 41286124 : case INTEGER_TYPE:
6368 41286124 : case REAL_TYPE:
6369 41286124 : case BOOLEAN_TYPE:
6370 41286124 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6371 : return false;
6372 41272179 : return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
6373 749115 : || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
6374 749115 : TYPE_MAX_VALUE (b->type)))
6375 41606387 : && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
6376 493523 : || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
6377 493523 : TYPE_MIN_VALUE (b->type))));
6378 :
6379 54626 : case BITINT_TYPE:
6380 54626 : if (TYPE_PRECISION (a->type) != TYPE_PRECISION (b->type))
6381 : return false;
6382 54626 : return TYPE_UNSIGNED (a->type) == TYPE_UNSIGNED (b->type);
6383 :
6384 0 : case FIXED_POINT_TYPE:
6385 0 : return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
6386 :
6387 757686 : case OFFSET_TYPE:
6388 757686 : return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
6389 :
6390 96920775 : case METHOD_TYPE:
6391 96920775 : if (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
6392 96920775 : && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6393 96767952 : || (TYPE_ARG_TYPES (a->type)
6394 96767952 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6395 96767952 : && TYPE_ARG_TYPES (b->type)
6396 96767952 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6397 96767952 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6398 96767952 : TYPE_ARG_TYPES (b->type)))))
6399 : break;
6400 : return false;
6401 63291624 : case ARRAY_TYPE:
6402 : /* Don't compare TYPE_TYPELESS_STORAGE flag on aggregates,
6403 : where the flag should be inherited from the element type
6404 : and can change after ARRAY_TYPEs are created; on non-aggregates
6405 : compare it and hash it, scalars will never have that flag set
6406 : and we need to differentiate between arrays created by different
6407 : front-ends or middle-end created arrays. */
6408 63291624 : return (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
6409 63291624 : && (AGGREGATE_TYPE_P (TREE_TYPE (a->type))
6410 61419010 : || (TYPE_TYPELESS_STORAGE (a->type)
6411 61419010 : == TYPE_TYPELESS_STORAGE (b->type))));
6412 :
6413 0 : case RECORD_TYPE:
6414 0 : case UNION_TYPE:
6415 0 : case QUAL_UNION_TYPE:
6416 0 : return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
6417 0 : || (TYPE_FIELDS (a->type)
6418 0 : && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
6419 0 : && TYPE_FIELDS (b->type)
6420 0 : && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
6421 0 : && type_list_equal (TYPE_FIELDS (a->type),
6422 0 : TYPE_FIELDS (b->type))));
6423 :
6424 445951257 : case FUNCTION_TYPE:
6425 445951257 : if ((TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
6426 281716714 : && (TYPE_NO_NAMED_ARGS_STDARG_P (a->type)
6427 281716714 : == TYPE_NO_NAMED_ARGS_STDARG_P (b->type)))
6428 446396422 : || (TYPE_ARG_TYPES (a->type)
6429 164234543 : && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
6430 164234543 : && TYPE_ARG_TYPES (b->type)
6431 164234528 : && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
6432 164234528 : && type_list_equal (TYPE_ARG_TYPES (a->type),
6433 164234528 : TYPE_ARG_TYPES (b->type))))
6434 : break;
6435 : return false;
6436 :
6437 9 : case REFERENCE_TYPE:
6438 9 : return TYPE_REF_IS_RVALUE (a->type) == TYPE_REF_IS_RVALUE (b->type);
6439 :
6440 : default:
6441 : return false;
6442 : }
6443 :
6444 514229481 : if (lang_hooks.types.type_hash_eq != NULL)
6445 328588094 : return lang_hooks.types.type_hash_eq (a->type, b->type);
6446 :
6447 : return true;
6448 : }
6449 :
6450 : /* Given TYPE, and HASHCODE its hash code, return the canonical
6451 : object for an identical type if one already exists.
6452 : Otherwise, return TYPE, and record it as the canonical object.
6453 :
6454 : To use this function, first create a type of the sort you want.
6455 : Then compute its hash code from the fields of the type that
6456 : make it different from other similar types.
6457 : Then call this function and use the value. */
6458 :
6459 : tree
6460 1481844316 : type_hash_canon (unsigned int hashcode, tree type)
6461 : {
6462 1481844316 : type_hash in;
6463 1481844316 : type_hash **loc;
6464 :
6465 : /* The hash table only contains main variants, so ensure that's what we're
6466 : being passed. */
6467 1481844316 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
6468 :
6469 : /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6470 : must call that routine before comparing TYPE_ALIGNs. */
6471 1481844316 : layout_type (type);
6472 :
6473 1481844316 : in.hash = hashcode;
6474 1481844316 : in.type = type;
6475 :
6476 1481844316 : loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT);
6477 1481844316 : if (*loc)
6478 : {
6479 687576928 : tree t1 = ((type_hash *) *loc)->type;
6480 687576928 : gcc_assert (TYPE_MAIN_VARIANT (t1) == t1
6481 : && t1 != type);
6482 687576928 : if (TYPE_UID (type) + 1 == next_type_uid)
6483 682055441 : --next_type_uid;
6484 : /* Free also min/max values and the cache for integer
6485 : types. This can't be done in free_node, as LTO frees
6486 : those on its own. */
6487 687576928 : if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE)
6488 : {
6489 40746222 : if (TYPE_MIN_VALUE (type)
6490 40746222 : && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
6491 : {
6492 : /* Zero is always in TYPE_CACHED_VALUES. */
6493 381821 : if (! TYPE_UNSIGNED (type))
6494 228720 : int_cst_hash_table->remove_elt (TYPE_MIN_VALUE (type));
6495 381821 : ggc_free (TYPE_MIN_VALUE (type));
6496 : }
6497 40746222 : if (TYPE_MAX_VALUE (type)
6498 40746222 : && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
6499 : {
6500 381821 : int_cst_hash_table->remove_elt (TYPE_MAX_VALUE (type));
6501 381821 : ggc_free (TYPE_MAX_VALUE (type));
6502 : }
6503 40746222 : if (TYPE_CACHED_VALUES_P (type))
6504 153101 : ggc_free (TYPE_CACHED_VALUES (type));
6505 : }
6506 687576928 : free_node (type);
6507 687576928 : return t1;
6508 : }
6509 : else
6510 : {
6511 794267388 : struct type_hash *h;
6512 :
6513 794267388 : h = ggc_alloc<type_hash> ();
6514 794267388 : h->hash = hashcode;
6515 794267388 : h->type = type;
6516 794267388 : *loc = h;
6517 :
6518 794267388 : return type;
6519 : }
6520 : }
6521 :
6522 : static void
6523 0 : print_type_hash_statistics (void)
6524 : {
6525 0 : fprintf (stderr, "Type hash: size " HOST_SIZE_T_PRINT_DEC ", "
6526 : HOST_SIZE_T_PRINT_DEC " elements, %f collisions\n",
6527 0 : (fmt_size_t) type_hash_table->size (),
6528 0 : (fmt_size_t) type_hash_table->elements (),
6529 : type_hash_table->collisions ());
6530 0 : }
6531 :
6532 : /* Given two lists of types
6533 : (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6534 : return 1 if the lists contain the same types in the same order.
6535 : Also, the TREE_PURPOSEs must match. */
6536 :
6537 : bool
6538 261003016 : type_list_equal (const_tree l1, const_tree l2)
6539 : {
6540 261003016 : const_tree t1, t2;
6541 :
6542 980789228 : for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6543 747983500 : if (TREE_VALUE (t1) != TREE_VALUE (t2)
6544 747983500 : || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6545 28199364 : && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6546 2109 : && (TREE_TYPE (TREE_PURPOSE (t1))
6547 2109 : == TREE_TYPE (TREE_PURPOSE (t2))))))
6548 : return false;
6549 :
6550 232805728 : return t1 == t2;
6551 : }
6552 :
6553 : /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6554 : given by TYPE. If the argument list accepts variable arguments,
6555 : then this function counts only the ordinary arguments. */
6556 :
6557 : int
6558 82249307 : type_num_arguments (const_tree fntype)
6559 : {
6560 82249307 : int i = 0;
6561 :
6562 320107208 : for (tree t = TYPE_ARG_TYPES (fntype); t; t = TREE_CHAIN (t))
6563 : /* If the function does not take a variable number of arguments,
6564 : the last element in the list will have type `void'. */
6565 300906975 : if (VOID_TYPE_P (TREE_VALUE (t)))
6566 : break;
6567 : else
6568 237857901 : ++i;
6569 :
6570 82249307 : return i;
6571 : }
6572 :
6573 : /* Return the type of the function TYPE's argument ARGNO if known.
6574 : For vararg function's where ARGNO refers to one of the variadic
6575 : arguments return null. Otherwise, return a void_type_node for
6576 : out-of-bounds ARGNO. */
6577 :
6578 : tree
6579 81164090 : type_argument_type (const_tree fntype, unsigned argno)
6580 : {
6581 : /* Treat zero the same as an out-of-bounds argument number. */
6582 81164090 : if (!argno)
6583 0 : return void_type_node;
6584 :
6585 81164090 : function_args_iterator iter;
6586 :
6587 81164090 : tree argtype;
6588 81164090 : unsigned i = 1;
6589 174673517 : FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
6590 : {
6591 : /* A vararg function's argument list ends in a null. Otherwise,
6592 : an ordinary function's argument list ends with void. Return
6593 : null if ARGNO refers to a vararg argument, void_type_node if
6594 : it's out of bounds, and the formal argument type otherwise. */
6595 168911964 : if (!argtype)
6596 : break;
6597 :
6598 168911964 : if (i == argno || VOID_TYPE_P (argtype))
6599 : return argtype;
6600 :
6601 93509427 : ++i;
6602 : }
6603 :
6604 : return NULL_TREE;
6605 : }
6606 :
6607 : /* True if integer constants T1 and T2
6608 : represent the same constant value. */
6609 :
6610 : bool
6611 1342947369 : tree_int_cst_equal (const_tree t1, const_tree t2)
6612 : {
6613 1342947369 : if (t1 == t2)
6614 : return true;
6615 :
6616 680373329 : if (t1 == 0 || t2 == 0)
6617 : return false;
6618 :
6619 679956926 : STRIP_ANY_LOCATION_WRAPPER (t1);
6620 679956926 : STRIP_ANY_LOCATION_WRAPPER (t2);
6621 :
6622 679956926 : if (TREE_CODE (t1) == INTEGER_CST
6623 675792067 : && TREE_CODE (t2) == INTEGER_CST
6624 1355748993 : && wi::to_widest (t1) == wi::to_widest (t2))
6625 20798297 : return true;
6626 :
6627 : return false;
6628 : }
6629 :
6630 : /* Return true if T is an INTEGER_CST whose numerical value (extended
6631 : according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
6632 :
6633 : bool
6634 2422647028 : tree_fits_shwi_p (const_tree t)
6635 : {
6636 2422647028 : return (t != NULL_TREE
6637 2422646937 : && TREE_CODE (t) == INTEGER_CST
6638 4842564046 : && wi::fits_shwi_p (wi::to_widest (t)));
6639 : }
6640 :
6641 : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6642 : value (extended according to TYPE_UNSIGNED) fits in a poly_int64. */
6643 :
6644 : bool
6645 1023791884 : tree_fits_poly_int64_p (const_tree t)
6646 : {
6647 1023791884 : if (t == NULL_TREE)
6648 : return false;
6649 985634789 : if (POLY_INT_CST_P (t))
6650 : {
6651 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6652 : if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t, i))))
6653 : return false;
6654 : return true;
6655 : }
6656 985634789 : return (TREE_CODE (t) == INTEGER_CST
6657 1971375337 : && wi::fits_shwi_p (wi::to_widest (t)));
6658 : }
6659 :
6660 : /* Return true if T is an INTEGER_CST whose numerical value (extended
6661 : according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
6662 :
6663 : bool
6664 4228875499 : tree_fits_uhwi_p (const_tree t)
6665 : {
6666 4228875499 : return (t != NULL_TREE
6667 4228238791 : && TREE_CODE (t) == INTEGER_CST
6668 8451689392 : && wi::fits_uhwi_p (wi::to_widest (t)));
6669 : }
6670 :
6671 : /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6672 : value (extended according to TYPE_UNSIGNED) fits in a poly_uint64. */
6673 :
6674 : bool
6675 1097692432 : tree_fits_poly_uint64_p (const_tree t)
6676 : {
6677 1097692432 : if (t == NULL_TREE)
6678 : return false;
6679 1097331496 : if (POLY_INT_CST_P (t))
6680 : {
6681 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6682 : if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t, i))))
6683 : return false;
6684 : return true;
6685 : }
6686 1097331496 : return (TREE_CODE (t) == INTEGER_CST
6687 2194664403 : && wi::fits_uhwi_p (wi::to_widest (t)));
6688 : }
6689 :
6690 : /* Return true if T is an INTEGER_CST whose numerical value (extended according
6691 : to TYPE_UNSIGNED) fits in a sanitize_code_type (uint64_t). */
6692 :
6693 : bool
6694 90 : tree_fits_sanitize_code_type_p (const_tree t)
6695 : {
6696 90 : if (t == NULL_TREE)
6697 : return false;
6698 90 : return (TREE_CODE (t) == INTEGER_CST
6699 180 : && wi::fits_uhwi_p (wi::to_widest (t)));
6700 : }
6701 :
6702 : /* T is an INTEGER_CST whose numerical value (extended according to
6703 : TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
6704 : HOST_WIDE_INT. */
6705 :
6706 : HOST_WIDE_INT
6707 1431909711 : tree_to_shwi (const_tree t)
6708 : {
6709 1431909711 : gcc_assert (tree_fits_shwi_p (t));
6710 1431909711 : return TREE_INT_CST_LOW (t);
6711 : }
6712 :
6713 : /* T is an INTEGER_CST whose numerical value (extended according to
6714 : TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
6715 : HOST_WIDE_INT. */
6716 :
6717 : unsigned HOST_WIDE_INT
6718 1048990317 : tree_to_uhwi (const_tree t)
6719 : {
6720 1048990317 : gcc_assert (tree_fits_uhwi_p (t));
6721 1048990317 : return TREE_INT_CST_LOW (t);
6722 : }
6723 :
6724 : /* T is an INTEGER_CST whose numerical value (extended according to
6725 : TYPE_UNSIGNED) fits in a sanitize_code_type. Return that
6726 : sanitize_code_type. */
6727 :
6728 : sanitize_code_type
6729 90 : tree_to_sanitize_code_type (const_tree t)
6730 : {
6731 90 : gcc_assert (tree_fits_sanitize_code_type_p (t));
6732 90 : return TREE_INT_CST_LOW (t);
6733 : }
6734 :
6735 : /* Return the most significant (sign) bit of T. */
6736 :
6737 : int
6738 45982216 : tree_int_cst_sign_bit (const_tree t)
6739 : {
6740 45982216 : unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
6741 :
6742 45982216 : return wi::extract_uhwi (wi::to_wide (t), bitno, 1);
6743 : }
6744 :
6745 : /* Return an indication of the sign of the integer constant T.
6746 : The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6747 : Note that -1 will never be returned if T's type is unsigned. */
6748 :
6749 : int
6750 1923208007 : tree_int_cst_sgn (const_tree t)
6751 : {
6752 1923208007 : if (wi::to_wide (t) == 0)
6753 : return 0;
6754 1788108003 : else if (TYPE_UNSIGNED (TREE_TYPE (t)))
6755 : return 1;
6756 85049609 : else if (wi::neg_p (wi::to_wide (t)))
6757 : return -1;
6758 : else
6759 81362072 : return 1;
6760 : }
6761 :
6762 : /* Return the minimum number of bits needed to represent VALUE in a
6763 : signed or unsigned type, UNSIGNEDP says which. */
6764 :
6765 : unsigned int
6766 3768047 : tree_int_cst_min_precision (tree value, signop sgn)
6767 : {
6768 : /* If the value is negative, compute its negative minus 1. The latter
6769 : adjustment is because the absolute value of the largest negative value
6770 : is one larger than the largest positive value. This is equivalent to
6771 : a bit-wise negation, so use that operation instead. */
6772 :
6773 3768047 : if (tree_int_cst_sgn (value) < 0)
6774 107637 : value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
6775 :
6776 : /* Return the number of bits needed, taking into account the fact
6777 : that we need one more bit for a signed than unsigned type.
6778 : If value is 0 or -1, the minimum precision is 1 no matter
6779 : whether unsignedp is true or false. */
6780 :
6781 3768047 : if (integer_zerop (value))
6782 : return 1;
6783 : else
6784 5412787 : return tree_floor_log2 (value) + 1 + (sgn == SIGNED ? 1 : 0) ;
6785 : }
6786 :
6787 : /* Return truthvalue of whether T1 is the same tree structure as T2.
6788 : Return 1 if they are the same.
6789 : Return 0 if they are understandably different.
6790 : Return -1 if either contains tree structure not understood by
6791 : this function. */
6792 :
6793 : int
6794 209831971 : simple_cst_equal (const_tree t1, const_tree t2)
6795 : {
6796 213634235 : enum tree_code code1, code2;
6797 213634235 : int cmp;
6798 213634235 : int i;
6799 :
6800 213634235 : if (t1 == t2)
6801 : return 1;
6802 136712036 : if (t1 == 0 || t2 == 0)
6803 : return 0;
6804 :
6805 : /* For location wrappers to be the same, they must be at the same
6806 : source location (and wrap the same thing). */
6807 127839113 : if (location_wrapper_p (t1) && location_wrapper_p (t2))
6808 : {
6809 13497564 : if (EXPR_LOCATION (t1) != EXPR_LOCATION (t2))
6810 : return 0;
6811 962 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6812 : }
6813 :
6814 114341549 : code1 = TREE_CODE (t1);
6815 114341549 : code2 = TREE_CODE (t2);
6816 :
6817 114341549 : if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
6818 : {
6819 3789297 : if (CONVERT_EXPR_CODE_P (code2)
6820 3788579 : || code2 == NON_LVALUE_EXPR)
6821 718 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6822 : else
6823 3788579 : return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
6824 : }
6825 :
6826 110552252 : else if (CONVERT_EXPR_CODE_P (code2)
6827 110552237 : || code2 == NON_LVALUE_EXPR)
6828 113 : return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
6829 :
6830 110552139 : if (code1 != code2)
6831 : return 0;
6832 :
6833 106042018 : switch (code1)
6834 : {
6835 96091130 : case INTEGER_CST:
6836 96091130 : return wi::to_widest (t1) == wi::to_widest (t2);
6837 :
6838 99 : case REAL_CST:
6839 99 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
6840 :
6841 0 : case FIXED_CST:
6842 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
6843 :
6844 3270770 : case STRING_CST:
6845 3270770 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
6846 3270770 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
6847 3755980 : TREE_STRING_LENGTH (t1)));
6848 :
6849 477 : case CONSTRUCTOR:
6850 477 : {
6851 477 : unsigned HOST_WIDE_INT idx;
6852 477 : vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (t1);
6853 477 : vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);
6854 :
6855 501 : if (vec_safe_length (v1) != vec_safe_length (v2))
6856 : return 0;
6857 :
6858 483 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
6859 : {
6860 12 : if ((*v1)[idx].index
6861 12 : && TREE_CODE ((*v1)[idx].index) == FIELD_DECL)
6862 : {
6863 9 : if ((*v1)[idx].index != (*v2)[idx].index)
6864 : return 0;
6865 : }
6866 : else
6867 : {
6868 3 : cmp = simple_cst_equal ((*v1)[idx].index, (*v2)[idx].index);
6869 3 : if (cmp <= 0)
6870 : return cmp;
6871 : }
6872 12 : cmp = simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value);
6873 12 : if (cmp <= 0)
6874 : return cmp;
6875 : }
6876 : return 1;
6877 : }
6878 :
6879 0 : case SAVE_EXPR:
6880 0 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6881 :
6882 208724 : case CALL_EXPR:
6883 208724 : cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
6884 208724 : if (cmp <= 0)
6885 : return cmp;
6886 86171 : if (call_expr_nargs (t1) != call_expr_nargs (t2))
6887 : return 0;
6888 86171 : {
6889 86171 : const_tree arg1, arg2;
6890 86171 : const_call_expr_arg_iterator iter1, iter2;
6891 172342 : for (arg1 = first_const_call_expr_arg (t1, &iter1),
6892 86171 : arg2 = first_const_call_expr_arg (t2, &iter2);
6893 86202 : arg1 && arg2;
6894 31 : arg1 = next_const_call_expr_arg (&iter1),
6895 31 : arg2 = next_const_call_expr_arg (&iter2))
6896 : {
6897 86145 : cmp = simple_cst_equal (arg1, arg2);
6898 86145 : if (cmp <= 0)
6899 : return cmp;
6900 : }
6901 57 : return arg1 == arg2;
6902 : }
6903 :
6904 11684 : case TARGET_EXPR:
6905 : /* Special case: if either target is an unallocated VAR_DECL,
6906 : it means that it's going to be unified with whatever the
6907 : TARGET_EXPR is really supposed to initialize, so treat it
6908 : as being equivalent to anything. */
6909 11684 : if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
6910 11684 : && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
6911 11684 : && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
6912 11684 : || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
6913 0 : && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
6914 0 : && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
6915 : cmp = 1;
6916 : else
6917 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6918 :
6919 0 : if (cmp <= 0)
6920 : return cmp;
6921 :
6922 11684 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
6923 :
6924 0 : case WITH_CLEANUP_EXPR:
6925 0 : cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6926 0 : if (cmp <= 0)
6927 : return cmp;
6928 :
6929 0 : return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
6930 :
6931 208 : case COMPONENT_REF:
6932 208 : if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
6933 208 : return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
6934 :
6935 : return 0;
6936 :
6937 : case VAR_DECL:
6938 : case PARM_DECL:
6939 : case CONST_DECL:
6940 : case FUNCTION_DECL:
6941 : return 0;
6942 :
6943 6394280 : default:
6944 6394280 : if (POLY_INT_CST_P (t1))
6945 : /* A false return means maybe_ne rather than known_ne. */
6946 : return known_eq (poly_widest_int::from (poly_int_cst_value (t1),
6947 : TYPE_SIGN (TREE_TYPE (t1))),
6948 : poly_widest_int::from (poly_int_cst_value (t2),
6949 : TYPE_SIGN (TREE_TYPE (t2))));
6950 6394280 : break;
6951 : }
6952 :
6953 : /* This general rule works for most tree codes. All exceptions should be
6954 : handled above. If this is a language-specific tree code, we can't
6955 : trust what might be in the operand, so say we don't know
6956 : the situation. */
6957 6394280 : if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
6958 : return -1;
6959 :
6960 882350 : switch (TREE_CODE_CLASS (code1))
6961 : {
6962 : case tcc_unary:
6963 : case tcc_binary:
6964 : case tcc_comparison:
6965 : case tcc_expression:
6966 : case tcc_reference:
6967 : case tcc_statement:
6968 : cmp = 1;
6969 1121 : for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
6970 : {
6971 858 : cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
6972 858 : if (cmp <= 0)
6973 : return cmp;
6974 : }
6975 :
6976 : return cmp;
6977 :
6978 : default:
6979 : return -1;
6980 : }
6981 : }
6982 :
6983 : /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
6984 : Return -1, 0, or 1 if the value of T is less than, equal to, or greater
6985 : than U, respectively. */
6986 :
6987 : int
6988 1569403924 : compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
6989 : {
6990 1569403924 : if (tree_int_cst_sgn (t) < 0)
6991 : return -1;
6992 1569403645 : else if (!tree_fits_uhwi_p (t))
6993 : return 1;
6994 1569403616 : else if (TREE_INT_CST_LOW (t) == u)
6995 : return 0;
6996 1397373545 : else if (TREE_INT_CST_LOW (t) < u)
6997 : return -1;
6998 : else
6999 13965405 : return 1;
7000 : }
7001 :
7002 : /* Return true if SIZE represents a constant size that is in bounds of
7003 : what the middle-end and the backend accepts (covering not more than
7004 : half of the address-space).
7005 : When PERR is non-null, set *PERR on failure to the description of
7006 : why SIZE is not valid. */
7007 :
7008 : bool
7009 69861436 : valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */)
7010 : {
7011 69861436 : if (POLY_INT_CST_P (size))
7012 : {
7013 : if (TREE_OVERFLOW (size))
7014 : return false;
7015 : for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
7016 : if (!valid_constant_size_p (POLY_INT_CST_COEFF (size, i)))
7017 : return false;
7018 : return true;
7019 : }
7020 :
7021 69861436 : cst_size_error error;
7022 69861436 : if (!perr)
7023 64056764 : perr = &error;
7024 :
7025 69861436 : if (TREE_CODE (size) != INTEGER_CST)
7026 : {
7027 3 : *perr = cst_size_not_constant;
7028 3 : return false;
7029 : }
7030 :
7031 69861433 : if (TREE_OVERFLOW_P (size))
7032 : {
7033 60 : *perr = cst_size_overflow;
7034 60 : return false;
7035 : }
7036 :
7037 69861373 : if (tree_int_cst_sgn (size) < 0)
7038 : {
7039 429 : *perr = cst_size_negative;
7040 429 : return false;
7041 : }
7042 139721888 : if (!tree_fits_uhwi_p (size)
7043 139721888 : || (wi::to_widest (TYPE_MAX_VALUE (sizetype))
7044 139721888 : < wi::to_widest (size) * 2))
7045 : {
7046 624 : *perr = cst_size_too_big;
7047 624 : return false;
7048 : }
7049 :
7050 : return true;
7051 : }
7052 :
7053 : /* Return the precision of the type, or for a complex or vector type the
7054 : precision of the type of its elements. */
7055 :
7056 : unsigned int
7057 7697670400 : element_precision (const_tree type)
7058 : {
7059 7697670400 : if (!TYPE_P (type))
7060 6404331 : type = TREE_TYPE (type);
7061 7697670400 : enum tree_code code = TREE_CODE (type);
7062 7697670400 : if (code == COMPLEX_TYPE || code == VECTOR_TYPE)
7063 57731429 : type = TREE_TYPE (type);
7064 :
7065 7697670400 : return TYPE_PRECISION (type);
7066 : }
7067 :
7068 : /* Return true if CODE represents an associative tree code. Otherwise
7069 : return false. */
7070 : bool
7071 37331043 : associative_tree_code (enum tree_code code)
7072 : {
7073 37331043 : switch (code)
7074 : {
7075 : case BIT_IOR_EXPR:
7076 : case BIT_AND_EXPR:
7077 : case BIT_XOR_EXPR:
7078 : case PLUS_EXPR:
7079 : case MULT_EXPR:
7080 : case MIN_EXPR:
7081 : case MAX_EXPR:
7082 : return true;
7083 :
7084 26248031 : default:
7085 26248031 : break;
7086 : }
7087 26248031 : return false;
7088 : }
7089 :
7090 : /* Return true if CODE represents a commutative tree code. Otherwise
7091 : return false. */
7092 : bool
7093 1787541706 : commutative_tree_code (enum tree_code code)
7094 : {
7095 1787541706 : switch (code)
7096 : {
7097 : case PLUS_EXPR:
7098 : case MULT_EXPR:
7099 : case MULT_HIGHPART_EXPR:
7100 : case MIN_EXPR:
7101 : case MAX_EXPR:
7102 : case BIT_IOR_EXPR:
7103 : case BIT_XOR_EXPR:
7104 : case BIT_AND_EXPR:
7105 : case NE_EXPR:
7106 : case EQ_EXPR:
7107 : case UNORDERED_EXPR:
7108 : case ORDERED_EXPR:
7109 : case UNEQ_EXPR:
7110 : case LTGT_EXPR:
7111 : case TRUTH_AND_EXPR:
7112 : case TRUTH_XOR_EXPR:
7113 : case TRUTH_OR_EXPR:
7114 : case WIDEN_MULT_EXPR:
7115 : case VEC_WIDEN_MULT_HI_EXPR:
7116 : case VEC_WIDEN_MULT_LO_EXPR:
7117 : case VEC_WIDEN_MULT_EVEN_EXPR:
7118 : case VEC_WIDEN_MULT_ODD_EXPR:
7119 : return true;
7120 :
7121 956160610 : default:
7122 956160610 : break;
7123 : }
7124 956160610 : return false;
7125 : }
7126 :
7127 : /* Return true if CODE represents a ternary tree code for which the
7128 : first two operands are commutative. Otherwise return false. */
7129 : bool
7130 99251131 : commutative_ternary_tree_code (enum tree_code code)
7131 : {
7132 99251131 : switch (code)
7133 : {
7134 : case WIDEN_MULT_PLUS_EXPR:
7135 : case WIDEN_MULT_MINUS_EXPR:
7136 : case DOT_PROD_EXPR:
7137 : return true;
7138 :
7139 99241280 : default:
7140 99241280 : break;
7141 : }
7142 99241280 : return false;
7143 : }
7144 :
7145 : /* Returns true if CODE can overflow. */
7146 :
7147 : bool
7148 618 : operation_can_overflow (enum tree_code code)
7149 : {
7150 618 : switch (code)
7151 : {
7152 : case PLUS_EXPR:
7153 : case MINUS_EXPR:
7154 : case MULT_EXPR:
7155 : case LSHIFT_EXPR:
7156 : /* Can overflow in various ways. */
7157 : return true;
7158 : case TRUNC_DIV_EXPR:
7159 : case EXACT_DIV_EXPR:
7160 : case FLOOR_DIV_EXPR:
7161 : case CEIL_DIV_EXPR:
7162 : /* For INT_MIN / -1. */
7163 : return true;
7164 : case NEGATE_EXPR:
7165 : case ABS_EXPR:
7166 : /* For -INT_MIN. */
7167 : return true;
7168 164 : default:
7169 : /* These operators cannot overflow. */
7170 164 : return false;
7171 : }
7172 : }
7173 :
7174 : /* Returns true if CODE operating on operands of type TYPE doesn't overflow, or
7175 : ftrapv doesn't generate trapping insns for CODE. */
7176 :
7177 : bool
7178 262148 : operation_no_trapping_overflow (tree type, enum tree_code code)
7179 : {
7180 262148 : gcc_checking_assert (ANY_INTEGRAL_TYPE_P (type));
7181 :
7182 : /* We don't generate instructions that trap on overflow for complex or vector
7183 : types. */
7184 262148 : if (!INTEGRAL_TYPE_P (type))
7185 : return true;
7186 :
7187 262148 : if (!TYPE_OVERFLOW_TRAPS (type))
7188 : return true;
7189 :
7190 262 : switch (code)
7191 : {
7192 : case PLUS_EXPR:
7193 : case MINUS_EXPR:
7194 : case MULT_EXPR:
7195 : case NEGATE_EXPR:
7196 : case ABS_EXPR:
7197 : /* These operators can overflow, and -ftrapv generates trapping code for
7198 : these. */
7199 : return false;
7200 : case TRUNC_DIV_EXPR:
7201 : case EXACT_DIV_EXPR:
7202 : case FLOOR_DIV_EXPR:
7203 : case CEIL_DIV_EXPR:
7204 : case LSHIFT_EXPR:
7205 : /* These operators can overflow, but -ftrapv does not generate trapping
7206 : code for these. */
7207 : return true;
7208 : default:
7209 : /* These operators cannot overflow. */
7210 : return true;
7211 : }
7212 : }
7213 :
7214 : /* Constructors for pointer, array and function types.
7215 : (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7216 : constructed by language-dependent code, not here.) */
7217 :
7218 : /* Construct, lay out and return the type of pointers to TO_TYPE with
7219 : mode MODE. If MODE is VOIDmode, a pointer mode for the address
7220 : space of TO_TYPE will be picked. If CAN_ALIAS_ALL is TRUE,
7221 : indicate this type can reference all of memory. If such a type has
7222 : already been constructed, reuse it. */
7223 :
7224 : tree
7225 2682866350 : build_pointer_type_for_mode (tree to_type, machine_mode mode,
7226 : bool can_alias_all)
7227 : {
7228 2682866350 : tree t;
7229 2682866350 : bool could_alias = can_alias_all;
7230 :
7231 2682866350 : if (to_type == error_mark_node)
7232 : return error_mark_node;
7233 :
7234 2682866344 : if (mode == VOIDmode)
7235 : {
7236 2551440050 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7237 2551440050 : mode = targetm.addr_space.pointer_mode (as);
7238 : }
7239 :
7240 : /* If the pointed-to type has the may_alias attribute set, force
7241 : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7242 2682866344 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7243 4517015 : can_alias_all = true;
7244 :
7245 : /* In some cases, languages will have things that aren't a POINTER_TYPE
7246 : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7247 : In that case, return that type without regard to the rest of our
7248 : operands.
7249 :
7250 : ??? This is a kludge, but consistent with the way this function has
7251 : always operated and there doesn't seem to be a good way to avoid this
7252 : at the moment. */
7253 2682866344 : if (TYPE_POINTER_TO (to_type) != 0
7254 2682866344 : && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
7255 167685 : return TYPE_POINTER_TO (to_type);
7256 :
7257 : /* First, if we already have a type for pointers to TO_TYPE and it's
7258 : the proper mode, use it. */
7259 2683433982 : for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
7260 2527601930 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7261 : return t;
7262 :
7263 155832052 : t = make_node (POINTER_TYPE);
7264 :
7265 155832052 : TREE_TYPE (t) = to_type;
7266 155832052 : SET_TYPE_MODE (t, mode);
7267 155832052 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7268 155832052 : TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
7269 155832052 : TYPE_POINTER_TO (to_type) = t;
7270 :
7271 : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7272 155832052 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7273 5377819 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7274 150454233 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7275 44903462 : TYPE_CANONICAL (t)
7276 89806924 : = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
7277 : mode, false);
7278 :
7279 : /* Lay out the type. This function has many callers that are concerned
7280 : with expression-construction, and this simplifies them all. */
7281 155832052 : layout_type (t);
7282 :
7283 155832052 : return t;
7284 : }
7285 :
7286 : /* By default build pointers in ptr_mode. */
7287 :
7288 : tree
7289 2550740679 : build_pointer_type (tree to_type)
7290 : {
7291 2550740679 : return build_pointer_type_for_mode (to_type, VOIDmode, false);
7292 : }
7293 :
7294 : /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7295 :
7296 : tree
7297 745153641 : build_reference_type_for_mode (tree to_type, machine_mode mode,
7298 : bool can_alias_all)
7299 : {
7300 745153641 : tree t;
7301 745153641 : bool could_alias = can_alias_all;
7302 :
7303 745153641 : if (to_type == error_mark_node)
7304 : return error_mark_node;
7305 :
7306 745153641 : if (mode == VOIDmode)
7307 : {
7308 588344882 : addr_space_t as = TYPE_ADDR_SPACE (to_type);
7309 588344882 : mode = targetm.addr_space.pointer_mode (as);
7310 : }
7311 :
7312 : /* If the pointed-to type has the may_alias attribute set, force
7313 : a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7314 745153641 : if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
7315 758694 : can_alias_all = true;
7316 :
7317 : /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7318 : (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7319 : In that case, return that type without regard to the rest of our
7320 : operands.
7321 :
7322 : ??? This is a kludge, but consistent with the way this function has
7323 : always operated and there doesn't seem to be a good way to avoid this
7324 : at the moment. */
7325 745153641 : if (TYPE_REFERENCE_TO (to_type) != 0
7326 745153641 : && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
7327 0 : return TYPE_REFERENCE_TO (to_type);
7328 :
7329 : /* First, if we already have a type for pointers to TO_TYPE and it's
7330 : the proper mode, use it. */
7331 745153641 : for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
7332 650518869 : if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
7333 : return t;
7334 :
7335 94634772 : t = make_node (REFERENCE_TYPE);
7336 :
7337 94634772 : TREE_TYPE (t) = to_type;
7338 94634772 : SET_TYPE_MODE (t, mode);
7339 94634772 : TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
7340 94634772 : TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
7341 94634772 : TYPE_REFERENCE_TO (to_type) = t;
7342 :
7343 : /* During LTO we do not set TYPE_CANONICAL of pointers and references. */
7344 94634772 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type) || in_lto_p)
7345 5123096 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7346 89511676 : else if (TYPE_CANONICAL (to_type) != to_type || could_alias)
7347 53100763 : TYPE_CANONICAL (t)
7348 106201526 : = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
7349 : mode, false);
7350 :
7351 94634772 : layout_type (t);
7352 :
7353 94634772 : return t;
7354 : }
7355 :
7356 :
7357 : /* Build the node for the type of references-to-TO_TYPE by default
7358 : in ptr_mode. */
7359 :
7360 : tree
7361 27293578 : build_reference_type (tree to_type)
7362 : {
7363 27293578 : return build_reference_type_for_mode (to_type, VOIDmode, false);
7364 : }
7365 :
7366 : #define MAX_INT_CACHED_PREC \
7367 : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7368 : static GTY(()) tree nonstandard_integer_type_cache[2 * MAX_INT_CACHED_PREC + 2];
7369 :
7370 : static void
7371 264460 : clear_nonstandard_integer_type_cache (void)
7372 : {
7373 34644260 : for (size_t i = 0 ; i < 2 * MAX_INT_CACHED_PREC + 2 ; i++)
7374 : {
7375 34379800 : nonstandard_integer_type_cache[i] = NULL;
7376 : }
7377 0 : }
7378 :
7379 : /* Builds a signed or unsigned integer type of precision PRECISION.
7380 : Used for C bitfields whose precision does not match that of
7381 : built-in target types. */
7382 : tree
7383 64108458 : build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
7384 : int unsignedp)
7385 : {
7386 64108458 : tree itype, ret;
7387 :
7388 64108458 : if (unsignedp)
7389 55211090 : unsignedp = MAX_INT_CACHED_PREC + 1;
7390 :
7391 64108458 : if (precision <= MAX_INT_CACHED_PREC)
7392 : {
7393 63740603 : itype = nonstandard_integer_type_cache[precision + unsignedp];
7394 63740603 : if (itype)
7395 : return itype;
7396 : }
7397 :
7398 1099813 : itype = make_node (INTEGER_TYPE);
7399 1099813 : TYPE_PRECISION (itype) = precision;
7400 :
7401 1099813 : if (unsignedp)
7402 715726 : fixup_unsigned_type (itype);
7403 : else
7404 384087 : fixup_signed_type (itype);
7405 :
7406 1099813 : inchash::hash hstate;
7407 1099813 : inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7408 1099813 : ret = type_hash_canon (hstate.end (), itype);
7409 1099813 : if (precision <= MAX_INT_CACHED_PREC)
7410 731958 : nonstandard_integer_type_cache[precision + unsignedp] = ret;
7411 :
7412 : return ret;
7413 : }
7414 :
7415 : #define MAX_BOOL_CACHED_PREC \
7416 : (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7417 : static GTY(()) tree nonstandard_boolean_type_cache[MAX_BOOL_CACHED_PREC + 1];
7418 :
7419 : /* Builds a boolean type of precision PRECISION.
7420 : Used for boolean vectors to choose proper vector element size. */
7421 : tree
7422 2759923 : build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision)
7423 : {
7424 2759923 : tree type;
7425 :
7426 2759923 : if (precision <= MAX_BOOL_CACHED_PREC)
7427 : {
7428 2755862 : type = nonstandard_boolean_type_cache[precision];
7429 2755862 : if (type)
7430 : return type;
7431 : }
7432 :
7433 84648 : type = make_node (BOOLEAN_TYPE);
7434 84648 : TYPE_PRECISION (type) = precision;
7435 84648 : fixup_signed_type (type);
7436 :
7437 84648 : if (precision <= MAX_INT_CACHED_PREC)
7438 80587 : nonstandard_boolean_type_cache[precision] = type;
7439 :
7440 : return type;
7441 : }
7442 :
7443 : static GTY(()) vec<tree, va_gc> *bitint_type_cache;
7444 :
7445 : /* Builds a signed or unsigned _BitInt(PRECISION) type. */
7446 : tree
7447 77328 : build_bitint_type (unsigned HOST_WIDE_INT precision, int unsignedp)
7448 : {
7449 77328 : tree itype, ret;
7450 :
7451 77328 : gcc_checking_assert (precision >= 1);
7452 :
7453 77328 : if (unsignedp)
7454 38289 : unsignedp = MAX_INT_CACHED_PREC + 1;
7455 :
7456 77328 : if (bitint_type_cache == NULL)
7457 766 : vec_safe_grow_cleared (bitint_type_cache, 2 * MAX_INT_CACHED_PREC + 2);
7458 :
7459 77328 : if (precision <= MAX_INT_CACHED_PREC)
7460 : {
7461 17911 : itype = (*bitint_type_cache)[precision + unsignedp];
7462 17911 : if (itype)
7463 : return itype;
7464 : }
7465 :
7466 61496 : itype = make_node (BITINT_TYPE);
7467 61496 : TYPE_PRECISION (itype) = precision;
7468 :
7469 61496 : if (unsignedp)
7470 30798 : fixup_unsigned_type (itype);
7471 : else
7472 30698 : fixup_signed_type (itype);
7473 :
7474 61496 : hashval_t hash = type_hash_canon_hash (itype);
7475 61496 : ret = type_hash_canon (hash, itype);
7476 61496 : if (precision <= MAX_INT_CACHED_PREC)
7477 2079 : (*bitint_type_cache)[precision + unsignedp] = ret;
7478 :
7479 : return ret;
7480 : }
7481 :
7482 : /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7483 : or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7484 : is true, reuse such a type that has already been constructed. */
7485 :
7486 : static tree
7487 45549925 : build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
7488 : {
7489 45549925 : tree itype = make_node (INTEGER_TYPE);
7490 :
7491 45549925 : TREE_TYPE (itype) = type;
7492 :
7493 45549925 : TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
7494 45549925 : TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
7495 :
7496 45549925 : TYPE_PRECISION (itype) = TYPE_PRECISION (type);
7497 45549925 : SET_TYPE_MODE (itype, TYPE_MODE (type));
7498 45549925 : TYPE_SIZE (itype) = TYPE_SIZE (type);
7499 45549925 : TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
7500 45549925 : SET_TYPE_ALIGN (itype, TYPE_ALIGN (type));
7501 45549925 : TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
7502 45549925 : SET_TYPE_WARN_IF_NOT_ALIGN (itype, TYPE_WARN_IF_NOT_ALIGN (type));
7503 :
7504 45549925 : if (!shared)
7505 : return itype;
7506 :
7507 45549925 : if ((TYPE_MIN_VALUE (itype)
7508 45549925 : && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
7509 91099010 : || (TYPE_MAX_VALUE (itype)
7510 44990520 : && TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST))
7511 : {
7512 : /* Since we cannot reliably merge this type, we need to compare it using
7513 : structural equality checks. */
7514 1243023 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
7515 1243023 : return itype;
7516 : }
7517 :
7518 44306902 : hashval_t hash = type_hash_canon_hash (itype);
7519 44306902 : itype = type_hash_canon (hash, itype);
7520 :
7521 44306902 : return itype;
7522 : }
7523 :
7524 : /* Wrapper around build_range_type_1 with SHARED set to true. */
7525 :
7526 : tree
7527 45549925 : build_range_type (tree type, tree lowval, tree highval)
7528 : {
7529 45549925 : return build_range_type_1 (type, lowval, highval, true);
7530 : }
7531 :
7532 : /* Wrapper around build_range_type_1 with SHARED set to false. */
7533 :
7534 : tree
7535 0 : build_nonshared_range_type (tree type, tree lowval, tree highval)
7536 : {
7537 0 : return build_range_type_1 (type, lowval, highval, false);
7538 : }
7539 :
7540 : /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7541 : MAXVAL should be the maximum value in the domain
7542 : (one less than the length of the array).
7543 :
7544 : The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7545 : We don't enforce this limit, that is up to caller (e.g. language front end).
7546 : The limit exists because the result is a signed type and we don't handle
7547 : sizes that use more than one HOST_WIDE_INT. */
7548 :
7549 : tree
7550 42586060 : build_index_type (tree maxval)
7551 : {
7552 42586060 : return build_range_type (sizetype, size_zero_node, maxval);
7553 : }
7554 :
7555 : /* Return true if the debug information for TYPE, a subtype, should be emitted
7556 : as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7557 : high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7558 : debug info and doesn't reflect the source code. */
7559 :
7560 : bool
7561 18 : subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
7562 : {
7563 18 : tree base_type = TREE_TYPE (type), low, high;
7564 :
7565 : /* Subrange types have a base type which is an integral type. */
7566 18 : if (!INTEGRAL_TYPE_P (base_type))
7567 : return false;
7568 :
7569 : /* Get the real bounds of the subtype. */
7570 18 : if (lang_hooks.types.get_subrange_bounds)
7571 0 : lang_hooks.types.get_subrange_bounds (type, &low, &high);
7572 : else
7573 : {
7574 18 : low = TYPE_MIN_VALUE (type);
7575 18 : high = TYPE_MAX_VALUE (type);
7576 : }
7577 :
7578 : /* If the type and its base type have the same representation and the same
7579 : name, then the type is not a subrange but a copy of the base type. */
7580 18 : if ((TREE_CODE (base_type) == INTEGER_TYPE
7581 18 : || TREE_CODE (base_type) == BOOLEAN_TYPE)
7582 18 : && int_size_in_bytes (type) == int_size_in_bytes (base_type)
7583 18 : && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
7584 0 : && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))
7585 18 : && TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (base_type))
7586 : return false;
7587 :
7588 18 : if (lowval)
7589 18 : *lowval = low;
7590 18 : if (highval)
7591 18 : *highval = high;
7592 : return true;
7593 : }
7594 :
7595 : /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7596 : and number of elements specified by the range of values of INDEX_TYPE.
7597 : If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
7598 : If SHARED is true, reuse such a type that has already been constructed.
7599 : If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type. */
7600 :
7601 : tree
7602 74166932 : build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
7603 : bool shared, bool set_canonical)
7604 : {
7605 74166932 : tree t;
7606 :
7607 74166932 : if (TREE_CODE (elt_type) == FUNCTION_TYPE)
7608 : {
7609 0 : error ("arrays of functions are not meaningful");
7610 0 : elt_type = integer_type_node;
7611 : }
7612 :
7613 74166932 : t = make_node (ARRAY_TYPE);
7614 74166932 : TREE_TYPE (t) = elt_type;
7615 74166932 : TYPE_DOMAIN (t) = index_type;
7616 74166932 : TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
7617 74166932 : TYPE_TYPELESS_STORAGE (t) = typeless_storage;
7618 :
7619 : /* Set TYPE_STRUCTURAL_EQUALITY_P. */
7620 74166932 : if (set_canonical
7621 74166932 : && (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7622 74127604 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7623 73833429 : || in_lto_p))
7624 406191 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7625 :
7626 74166932 : layout_type (t);
7627 :
7628 74166932 : if (shared)
7629 : {
7630 74166903 : hashval_t hash = type_hash_canon_hash (t);
7631 74166903 : tree probe_type = t;
7632 74166903 : t = type_hash_canon (hash, t);
7633 74166903 : if (t != probe_type)
7634 : return t;
7635 : }
7636 :
7637 11384816 : if (TYPE_CANONICAL (t) == t && set_canonical)
7638 : {
7639 11027726 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
7640 11027726 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
7641 22055452 : || in_lto_p)
7642 0 : gcc_unreachable ();
7643 11027726 : else if (TYPE_CANONICAL (elt_type) != elt_type
7644 11027726 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
7645 106798 : TYPE_CANONICAL (t)
7646 309925 : = build_array_type_1 (TYPE_CANONICAL (elt_type),
7647 : index_type
7648 96329 : ? TYPE_CANONICAL (index_type) : NULL_TREE,
7649 : typeless_storage, shared, set_canonical);
7650 : }
7651 :
7652 : return t;
7653 : }
7654 :
7655 : /* Wrapper around build_array_type_1 with SHARED set to true. */
7656 :
7657 : tree
7658 74060105 : build_array_type (tree elt_type, tree index_type, bool typeless_storage)
7659 : {
7660 74060105 : return
7661 74060105 : build_array_type_1 (elt_type, index_type, typeless_storage, true, true);
7662 : }
7663 :
7664 : /* Wrapper around build_array_type_1 with SHARED set to false. */
7665 :
7666 : tree
7667 0 : build_nonshared_array_type (tree elt_type, tree index_type)
7668 : {
7669 0 : return build_array_type_1 (elt_type, index_type, false, false, true);
7670 : }
7671 :
7672 : /* Return a representation of ELT_TYPE[NELTS], using indices of type
7673 : sizetype. */
7674 :
7675 : tree
7676 1713548 : build_array_type_nelts (tree elt_type, poly_uint64 nelts)
7677 : {
7678 1713548 : return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
7679 : }
7680 :
7681 : /* Computes the canonical argument types from the argument type list
7682 : ARGTYPES.
7683 :
7684 : Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7685 : on entry to this function, or if any of the ARGTYPES are
7686 : structural.
7687 :
7688 : Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7689 : true on entry to this function, or if any of the ARGTYPES are
7690 : non-canonical.
7691 :
7692 : Returns a canonical argument list, which may be ARGTYPES when the
7693 : canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7694 : true) or would not differ from ARGTYPES. */
7695 :
7696 : static tree
7697 1025674066 : maybe_canonicalize_argtypes (tree argtypes,
7698 : bool *any_structural_p,
7699 : bool *any_noncanonical_p)
7700 : {
7701 1025674066 : tree arg;
7702 1025674066 : bool any_noncanonical_argtypes_p = false;
7703 :
7704 3542964656 : for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
7705 : {
7706 2517290590 : if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
7707 : /* Fail gracefully by stating that the type is structural. */
7708 15657 : *any_structural_p = true;
7709 2517274933 : else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
7710 35321647 : *any_structural_p = true;
7711 2481953286 : else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
7712 2481953286 : || TREE_PURPOSE (arg))
7713 : /* If the argument has a default argument, we consider it
7714 : non-canonical even though the type itself is canonical.
7715 : That way, different variants of function and method types
7716 : with default arguments will all point to the variant with
7717 : no defaults as their canonical type. */
7718 : any_noncanonical_argtypes_p = true;
7719 : }
7720 :
7721 1025674066 : if (*any_structural_p)
7722 : return argtypes;
7723 :
7724 928616156 : if (any_noncanonical_argtypes_p)
7725 : {
7726 : /* Build the canonical list of argument types. */
7727 : tree canon_argtypes = NULL_TREE;
7728 : bool is_void = false;
7729 :
7730 905674491 : for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
7731 : {
7732 695032452 : if (arg == void_list_node)
7733 : is_void = true;
7734 : else
7735 970824842 : canon_argtypes = tree_cons (NULL_TREE,
7736 485412421 : TYPE_CANONICAL (TREE_VALUE (arg)),
7737 : canon_argtypes);
7738 : }
7739 :
7740 210642039 : canon_argtypes = nreverse (canon_argtypes);
7741 210642039 : if (is_void)
7742 209620031 : canon_argtypes = chainon (canon_argtypes, void_list_node);
7743 :
7744 : /* There is a non-canonical type. */
7745 210642039 : *any_noncanonical_p = true;
7746 210642039 : return canon_argtypes;
7747 : }
7748 :
7749 : /* The canonical argument types are the same as ARGTYPES. */
7750 : return argtypes;
7751 : }
7752 :
7753 : /* Construct, lay out and return
7754 : the type of functions returning type VALUE_TYPE
7755 : given arguments of types ARG_TYPES.
7756 : ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7757 : are data type nodes for the arguments of the function.
7758 : NO_NAMED_ARGS_STDARG_P is true if this is a prototyped
7759 : variable-arguments function with (...) prototype (no named arguments).
7760 : If such a type has already been constructed, reuse it. */
7761 :
7762 : tree
7763 678023681 : build_function_type (tree value_type, tree arg_types,
7764 : bool no_named_args_stdarg_p)
7765 : {
7766 678023681 : tree t;
7767 678023681 : inchash::hash hstate;
7768 678023681 : bool any_structural_p, any_noncanonical_p;
7769 678023681 : tree canon_argtypes;
7770 :
7771 678023681 : gcc_assert (arg_types != error_mark_node);
7772 :
7773 678023681 : if (TREE_CODE (value_type) == FUNCTION_TYPE)
7774 : {
7775 0 : error ("function return type cannot be function");
7776 0 : value_type = integer_type_node;
7777 : }
7778 :
7779 : /* Make a node of the sort we want. */
7780 678023681 : t = make_node (FUNCTION_TYPE);
7781 678023681 : TREE_TYPE (t) = value_type;
7782 678023681 : TYPE_ARG_TYPES (t) = arg_types;
7783 678023681 : if (no_named_args_stdarg_p)
7784 : {
7785 1195831 : gcc_assert (arg_types == NULL_TREE);
7786 1195831 : TYPE_NO_NAMED_ARGS_STDARG_P (t) = 1;
7787 : }
7788 :
7789 : /* Set up the canonical type. */
7790 678023681 : any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
7791 678023681 : any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
7792 678023681 : canon_argtypes = maybe_canonicalize_argtypes (arg_types,
7793 : &any_structural_p,
7794 : &any_noncanonical_p);
7795 : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7796 678023681 : if (any_structural_p)
7797 70040212 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7798 :
7799 : /* If we already have such a type, use the old one. */
7800 678023681 : hashval_t hash = type_hash_canon_hash (t);
7801 678023681 : tree probe_type = t;
7802 678023681 : t = type_hash_canon (hash, t);
7803 678023681 : if (t != probe_type)
7804 : return t;
7805 :
7806 438035177 : if (any_structural_p)
7807 56274900 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7808 381760277 : else if (any_noncanonical_p)
7809 90237774 : TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
7810 : canon_argtypes,
7811 : no_named_args_stdarg_p);
7812 :
7813 438035177 : if (!COMPLETE_TYPE_P (t))
7814 0 : layout_type (t);
7815 : return t;
7816 : }
7817 :
7818 : /* Build a function type. The RETURN_TYPE is the type returned by the
7819 : function. If VAARGS is set, no void_type_node is appended to the
7820 : list. ARGP must be always be terminated be a NULL_TREE. */
7821 :
7822 : static tree
7823 15674403 : build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
7824 : {
7825 15674403 : tree t, args, last;
7826 :
7827 15674403 : t = va_arg (argp, tree);
7828 65890380 : for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
7829 34541574 : args = tree_cons (NULL_TREE, t, args);
7830 :
7831 15674403 : if (vaargs)
7832 : {
7833 1074479 : last = args;
7834 1074479 : if (args != NULL_TREE)
7835 837672 : args = nreverse (args);
7836 1074479 : gcc_assert (last != void_list_node);
7837 : }
7838 14599924 : else if (args == NULL_TREE)
7839 1243496 : args = void_list_node;
7840 : else
7841 : {
7842 13356428 : last = args;
7843 13356428 : args = nreverse (args);
7844 13356428 : TREE_CHAIN (last) = void_list_node;
7845 : }
7846 15674403 : args = build_function_type (return_type, args, vaargs && args == NULL_TREE);
7847 :
7848 15674403 : return args;
7849 : }
7850 :
7851 : /* Build a function type. The RETURN_TYPE is the type returned by the
7852 : function. If additional arguments are provided, they are
7853 : additional argument types. The list of argument types must always
7854 : be terminated by NULL_TREE. */
7855 :
7856 : tree
7857 14599924 : build_function_type_list (tree return_type, ...)
7858 : {
7859 14599924 : tree args;
7860 14599924 : va_list p;
7861 :
7862 14599924 : va_start (p, return_type);
7863 14599924 : args = build_function_type_list_1 (false, return_type, p);
7864 14599924 : va_end (p);
7865 14599924 : return args;
7866 : }
7867 :
7868 : /* Build a variable argument function type. The RETURN_TYPE is the
7869 : type returned by the function. If additional arguments are provided,
7870 : they are additional argument types. The list of argument types must
7871 : always be terminated by NULL_TREE. */
7872 :
7873 : tree
7874 1074479 : build_varargs_function_type_list (tree return_type, ...)
7875 : {
7876 1074479 : tree args;
7877 1074479 : va_list p;
7878 :
7879 1074479 : va_start (p, return_type);
7880 1074479 : args = build_function_type_list_1 (true, return_type, p);
7881 1074479 : va_end (p);
7882 :
7883 1074479 : return args;
7884 : }
7885 :
7886 : /* Build a function type. RETURN_TYPE is the type returned by the
7887 : function; VAARGS indicates whether the function takes varargs. The
7888 : function takes N named arguments, the types of which are provided in
7889 : ARG_TYPES. */
7890 :
7891 : static tree
7892 122589916 : build_function_type_array_1 (bool vaargs, tree return_type, int n,
7893 : tree *arg_types)
7894 : {
7895 122589916 : int i;
7896 122589916 : tree t = vaargs ? NULL_TREE : void_list_node;
7897 :
7898 401043115 : for (i = n - 1; i >= 0; i--)
7899 278453199 : t = tree_cons (NULL_TREE, arg_types[i], t);
7900 :
7901 122589916 : return build_function_type (return_type, t, vaargs && n == 0);
7902 : }
7903 :
7904 : /* Build a function type. RETURN_TYPE is the type returned by the
7905 : function. The function takes N named arguments, the types of which
7906 : are provided in ARG_TYPES. */
7907 :
7908 : tree
7909 116048019 : build_function_type_array (tree return_type, int n, tree *arg_types)
7910 : {
7911 116048019 : return build_function_type_array_1 (false, return_type, n, arg_types);
7912 : }
7913 :
7914 : /* Build a variable argument function type. RETURN_TYPE is the type
7915 : returned by the function. The function takes N named arguments, the
7916 : types of which are provided in ARG_TYPES. */
7917 :
7918 : tree
7919 6541897 : build_varargs_function_type_array (tree return_type, int n, tree *arg_types)
7920 : {
7921 6541897 : return build_function_type_array_1 (true, return_type, n, arg_types);
7922 : }
7923 :
7924 : /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
7925 : and ARGTYPES (a TREE_LIST) are the return type and arguments types
7926 : for the method. An implicit additional parameter (of type
7927 : pointer-to-BASETYPE) is added to the ARGTYPES. */
7928 :
7929 : tree
7930 347650385 : build_method_type_directly (tree basetype,
7931 : tree rettype,
7932 : tree argtypes)
7933 : {
7934 347650385 : tree t;
7935 347650385 : tree ptype;
7936 347650385 : bool any_structural_p, any_noncanonical_p;
7937 347650385 : tree canon_argtypes;
7938 :
7939 : /* Make a node of the sort we want. */
7940 347650385 : t = make_node (METHOD_TYPE);
7941 :
7942 347650385 : TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
7943 347650385 : TREE_TYPE (t) = rettype;
7944 347650385 : ptype = build_pointer_type (basetype);
7945 :
7946 : /* The actual arglist for this function includes a "hidden" argument
7947 : which is "this". Put it into the list of argument types. */
7948 347650385 : argtypes = tree_cons (NULL_TREE, ptype, argtypes);
7949 347650385 : TYPE_ARG_TYPES (t) = argtypes;
7950 :
7951 : /* Set up the canonical type. */
7952 347650385 : any_structural_p
7953 347650385 : = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
7954 347650385 : || TYPE_STRUCTURAL_EQUALITY_P (rettype));
7955 347650385 : any_noncanonical_p
7956 347650385 : = (TYPE_CANONICAL (basetype) != basetype
7957 347650385 : || TYPE_CANONICAL (rettype) != rettype);
7958 347650385 : canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
7959 : &any_structural_p,
7960 : &any_noncanonical_p);
7961 :
7962 : /* Set TYPE_STRUCTURAL_EQUALITY_P early. */
7963 347650385 : if (any_structural_p)
7964 27017698 : SET_TYPE_STRUCTURAL_EQUALITY (t);
7965 :
7966 : /* If we already have such a type, use the old one. */
7967 347650385 : hashval_t hash = type_hash_canon_hash (t);
7968 347650385 : tree probe_type = t;
7969 347650385 : t = type_hash_canon (hash, t);
7970 347650385 : if (t != probe_type)
7971 : return t;
7972 :
7973 268010952 : if (any_structural_p)
7974 22809304 : gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
7975 245201648 : else if (any_noncanonical_p)
7976 90211336 : TYPE_CANONICAL (t)
7977 180422672 : = build_method_type_directly (TYPE_CANONICAL (basetype),
7978 90211336 : TYPE_CANONICAL (rettype),
7979 : canon_argtypes);
7980 268010952 : if (!COMPLETE_TYPE_P (t))
7981 0 : layout_type (t);
7982 :
7983 : return t;
7984 : }
7985 :
7986 : /* Construct, lay out and return the type of methods belonging to class
7987 : BASETYPE and whose arguments and values are described by TYPE.
7988 : If that type exists already, reuse it.
7989 : TYPE must be a FUNCTION_TYPE node. */
7990 :
7991 : tree
7992 0 : build_method_type (tree basetype, tree type)
7993 : {
7994 0 : gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
7995 :
7996 0 : return build_method_type_directly (basetype,
7997 0 : TREE_TYPE (type),
7998 0 : TYPE_ARG_TYPES (type));
7999 : }
8000 :
8001 : /* Construct, lay out and return the type of offsets to a value
8002 : of type TYPE, within an object of type BASETYPE.
8003 : If a suitable offset type exists already, reuse it. */
8004 :
8005 : tree
8006 1000222 : build_offset_type (tree basetype, tree type)
8007 : {
8008 1000222 : tree t;
8009 :
8010 : /* Make a node of the sort we want. */
8011 1000222 : t = make_node (OFFSET_TYPE);
8012 :
8013 1000222 : TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
8014 1000222 : TREE_TYPE (t) = type;
8015 1000222 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
8016 1000222 : || TYPE_STRUCTURAL_EQUALITY_P (type))
8017 4 : SET_TYPE_STRUCTURAL_EQUALITY (t);
8018 :
8019 : /* If we already have such a type, use the old one. */
8020 1000222 : hashval_t hash = type_hash_canon_hash (t);
8021 1000222 : tree probe_type = t;
8022 1000222 : t = type_hash_canon (hash, t);
8023 1000222 : if (t != probe_type)
8024 : return t;
8025 :
8026 242536 : if (!COMPLETE_TYPE_P (t))
8027 0 : layout_type (t);
8028 :
8029 242536 : if (TYPE_CANONICAL (t) == t)
8030 : {
8031 242532 : if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
8032 242532 : || TYPE_STRUCTURAL_EQUALITY_P (type))
8033 0 : gcc_unreachable ();
8034 242532 : else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
8035 242532 : || TYPE_CANONICAL (type) != type)
8036 139056 : TYPE_CANONICAL (t)
8037 278112 : = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
8038 139056 : TYPE_CANONICAL (type));
8039 : }
8040 :
8041 : return t;
8042 : }
8043 :
8044 : /* Create a complex type whose components are COMPONENT_TYPE.
8045 :
8046 : If NAMED is true, the type is given a TYPE_NAME. We do not always
8047 : do so because this creates a DECL node and thus make the DECL_UIDs
8048 : dependent on the type canonicalization hashtable, which is GC-ed,
8049 : so the DECL_UIDs would not be stable wrt garbage collection. */
8050 :
8051 : tree
8052 5466528 : build_complex_type (tree component_type, bool named)
8053 : {
8054 5466528 : gcc_assert (INTEGRAL_TYPE_P (component_type)
8055 : || SCALAR_FLOAT_TYPE_P (component_type)
8056 : || FIXED_POINT_TYPE_P (component_type));
8057 :
8058 : /* Make a node of the sort we want. */
8059 5466528 : tree probe = make_node (COMPLEX_TYPE);
8060 :
8061 5466528 : TREE_TYPE (probe) = TYPE_MAIN_VARIANT (component_type);
8062 5466528 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (probe)))
8063 0 : SET_TYPE_STRUCTURAL_EQUALITY (probe);
8064 :
8065 : /* If we already have such a type, use the old one. */
8066 5466528 : hashval_t hash = type_hash_canon_hash (probe);
8067 5466528 : tree t = type_hash_canon (hash, probe);
8068 :
8069 5466528 : if (t == probe)
8070 : {
8071 : /* We created a new type. The hash insertion will have laid
8072 : out the type. We need to check the canonicalization and
8073 : maybe set the name. */
8074 3208505 : gcc_checking_assert (COMPLETE_TYPE_P (t)
8075 : && !TYPE_NAME (t));
8076 :
8077 3208505 : if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))
8078 : ;
8079 3208505 : else if (TYPE_CANONICAL (TREE_TYPE (t)) != TREE_TYPE (t))
8080 105 : TYPE_CANONICAL (t)
8081 210 : = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named);
8082 :
8083 : /* We need to create a name, since complex is a fundamental type. */
8084 3208505 : if (named)
8085 : {
8086 1176960 : const char *name = NULL;
8087 :
8088 1176960 : if (TREE_TYPE (t) == char_type_node)
8089 : name = "complex char";
8090 1176960 : else if (TREE_TYPE (t) == signed_char_type_node)
8091 : name = "complex signed char";
8092 1176960 : else if (TREE_TYPE (t) == unsigned_char_type_node)
8093 : name = "complex unsigned char";
8094 1176960 : else if (TREE_TYPE (t) == short_integer_type_node)
8095 : name = "complex short int";
8096 1176960 : else if (TREE_TYPE (t) == short_unsigned_type_node)
8097 : name = "complex short unsigned int";
8098 1176960 : else if (TREE_TYPE (t) == integer_type_node)
8099 : name = "complex int";
8100 882720 : else if (TREE_TYPE (t) == unsigned_type_node)
8101 : name = "complex unsigned int";
8102 882720 : else if (TREE_TYPE (t) == long_integer_type_node)
8103 : name = "complex long int";
8104 882720 : else if (TREE_TYPE (t) == long_unsigned_type_node)
8105 : name = "complex long unsigned int";
8106 882720 : else if (TREE_TYPE (t) == long_long_integer_type_node)
8107 : name = "complex long long int";
8108 882720 : else if (TREE_TYPE (t) == long_long_unsigned_type_node)
8109 : name = "complex long long unsigned int";
8110 :
8111 : if (name != NULL)
8112 294240 : TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
8113 : get_identifier (name), t);
8114 : }
8115 : }
8116 :
8117 5466528 : return build_qualified_type (t, TYPE_QUALS (component_type));
8118 : }
8119 :
8120 : /* If TYPE is a real or complex floating-point type and the target
8121 : does not directly support arithmetic on TYPE then return the wider
8122 : type to be used for arithmetic on TYPE. Otherwise, return
8123 : NULL_TREE. */
8124 :
8125 : tree
8126 91342375 : excess_precision_type (tree type)
8127 : {
8128 : /* The target can give two different responses to the question of
8129 : which excess precision mode it would like depending on whether we
8130 : are in -fexcess-precision=standard or -fexcess-precision=fast. */
8131 :
8132 3557561 : enum excess_precision_type requested_type
8133 91342375 : = (flag_excess_precision == EXCESS_PRECISION_FAST
8134 91342375 : ? EXCESS_PRECISION_TYPE_FAST
8135 : : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
8136 3558287 : ? EXCESS_PRECISION_TYPE_FLOAT16 : EXCESS_PRECISION_TYPE_STANDARD));
8137 :
8138 91342375 : enum flt_eval_method target_flt_eval_method
8139 91342375 : = targetm.c.excess_precision (requested_type);
8140 :
8141 : /* The target should not ask for unpredictable float evaluation (though
8142 : it might advertise that implicitly the evaluation is unpredictable,
8143 : but we don't care about that here, it will have been reported
8144 : elsewhere). If it does ask for unpredictable evaluation, we have
8145 : nothing to do here. */
8146 91342375 : gcc_assert (target_flt_eval_method != FLT_EVAL_METHOD_UNPREDICTABLE);
8147 :
8148 : /* Nothing to do. The target has asked for all types we know about
8149 : to be computed with their native precision and range. */
8150 91342375 : if (target_flt_eval_method == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
8151 : return NULL_TREE;
8152 :
8153 : /* The target will promote this type in a target-dependent way, so excess
8154 : precision ought to leave it alone. */
8155 89708057 : if (targetm.promoted_type (type) != NULL_TREE)
8156 : return NULL_TREE;
8157 :
8158 89708057 : machine_mode float16_type_mode = (float16_type_node
8159 89708057 : ? TYPE_MODE (float16_type_node)
8160 89708057 : : VOIDmode);
8161 89708057 : machine_mode bfloat16_type_mode = (bfloat16_type_node
8162 89708057 : ? TYPE_MODE (bfloat16_type_node)
8163 89708057 : : VOIDmode);
8164 89708057 : machine_mode float_type_mode = TYPE_MODE (float_type_node);
8165 89708057 : machine_mode double_type_mode = TYPE_MODE (double_type_node);
8166 :
8167 89708057 : switch (TREE_CODE (type))
8168 : {
8169 61119271 : case REAL_TYPE:
8170 61119271 : {
8171 61119271 : machine_mode type_mode = TYPE_MODE (type);
8172 61119271 : switch (target_flt_eval_method)
8173 : {
8174 61106438 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8175 61106438 : if (type_mode == float16_type_mode
8176 61106438 : || type_mode == bfloat16_type_mode)
8177 283512 : return float_type_node;
8178 : break;
8179 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8180 0 : if (type_mode == float16_type_mode
8181 0 : || type_mode == bfloat16_type_mode
8182 0 : || type_mode == float_type_mode)
8183 0 : return double_type_node;
8184 : break;
8185 12833 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8186 12833 : if (type_mode == float16_type_mode
8187 12833 : || type_mode == bfloat16_type_mode
8188 12828 : || type_mode == float_type_mode
8189 12828 : || type_mode == double_type_mode)
8190 12384 : return long_double_type_node;
8191 : break;
8192 0 : default:
8193 0 : gcc_unreachable ();
8194 : }
8195 : break;
8196 : }
8197 381182 : case COMPLEX_TYPE:
8198 381182 : {
8199 381182 : if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
8200 : return NULL_TREE;
8201 371659 : machine_mode type_mode = TYPE_MODE (TREE_TYPE (type));
8202 371659 : switch (target_flt_eval_method)
8203 : {
8204 371326 : case FLT_EVAL_METHOD_PROMOTE_TO_FLOAT:
8205 371326 : if (type_mode == float16_type_mode
8206 371326 : || type_mode == bfloat16_type_mode)
8207 281 : return complex_float_type_node;
8208 : break;
8209 0 : case FLT_EVAL_METHOD_PROMOTE_TO_DOUBLE:
8210 0 : if (type_mode == float16_type_mode
8211 0 : || type_mode == bfloat16_type_mode
8212 0 : || type_mode == float_type_mode)
8213 0 : return complex_double_type_node;
8214 : break;
8215 333 : case FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE:
8216 333 : if (type_mode == float16_type_mode
8217 333 : || type_mode == bfloat16_type_mode
8218 333 : || type_mode == float_type_mode
8219 333 : || type_mode == double_type_mode)
8220 281 : return complex_long_double_type_node;
8221 : break;
8222 0 : default:
8223 0 : gcc_unreachable ();
8224 : }
8225 : break;
8226 : }
8227 : default:
8228 : break;
8229 : }
8230 :
8231 : return NULL_TREE;
8232 : }
8233 :
8234 : /* Return OP, stripped of any conversions to wider types as much as is safe.
8235 : Converting the value back to OP's type makes a value equivalent to OP.
8236 :
8237 : If FOR_TYPE is nonzero, we return a value which, if converted to
8238 : type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8239 :
8240 : OP must have integer, real or enumeral type. Pointers are not allowed!
8241 :
8242 : There are some cases where the obvious value we could return
8243 : would regenerate to OP if converted to OP's type,
8244 : but would not extend like OP to wider types.
8245 : If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8246 : For example, if OP is (unsigned short)(signed char)-1,
8247 : we avoid returning (signed char)-1 if FOR_TYPE is int,
8248 : even though extending that to an unsigned short would regenerate OP,
8249 : since the result of extending (signed char)-1 to (int)
8250 : is different from (int) OP. */
8251 :
8252 : tree
8253 11798286 : get_unwidened (tree op, tree for_type)
8254 : {
8255 : /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8256 11798286 : tree type = TREE_TYPE (op);
8257 11798286 : unsigned final_prec
8258 19679129 : = TYPE_PRECISION (for_type != 0 ? for_type : type);
8259 11798286 : int uns
8260 11798286 : = (for_type != 0 && for_type != type
8261 3504265 : && final_prec > TYPE_PRECISION (type)
8262 12047941 : && TYPE_UNSIGNED (type));
8263 11798286 : tree win = op;
8264 :
8265 12172675 : while (CONVERT_EXPR_P (op))
8266 : {
8267 374482 : int bitschange;
8268 :
8269 : /* TYPE_PRECISION on vector types has different meaning
8270 : (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8271 : so avoid them here. */
8272 374482 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
8273 : break;
8274 :
8275 374482 : bitschange = TYPE_PRECISION (TREE_TYPE (op))
8276 374482 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
8277 :
8278 : /* Truncations are many-one so cannot be removed.
8279 : Unless we are later going to truncate down even farther. */
8280 374482 : if (bitschange < 0
8281 374482 : && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
8282 : break;
8283 :
8284 : /* See what's inside this conversion. If we decide to strip it,
8285 : we will set WIN. */
8286 374389 : op = TREE_OPERAND (op, 0);
8287 :
8288 : /* If we have not stripped any zero-extensions (uns is 0),
8289 : we can strip any kind of extension.
8290 : If we have previously stripped a zero-extension,
8291 : only zero-extensions can safely be stripped.
8292 : Any extension can be stripped if the bits it would produce
8293 : are all going to be discarded later by truncating to FOR_TYPE. */
8294 :
8295 374389 : if (bitschange > 0)
8296 : {
8297 229999 : if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
8298 : win = op;
8299 : /* TYPE_UNSIGNED says whether this is a zero-extension.
8300 : Let's avoid computing it if it does not affect WIN
8301 : and if UNS will not be needed again. */
8302 229999 : if ((uns
8303 229968 : || CONVERT_EXPR_P (op))
8304 230721 : && TYPE_UNSIGNED (TREE_TYPE (op)))
8305 : {
8306 : uns = 1;
8307 : win = op;
8308 : }
8309 : }
8310 : }
8311 :
8312 : /* If we finally reach a constant see if it fits in sth smaller and
8313 : in that case convert it. */
8314 11798286 : if (TREE_CODE (win) == INTEGER_CST)
8315 : {
8316 577136 : tree wtype = TREE_TYPE (win);
8317 577136 : unsigned prec = wi::min_precision (wi::to_wide (win), TYPE_SIGN (wtype));
8318 577136 : if (for_type)
8319 565282 : prec = MAX (prec, final_prec);
8320 577136 : if (prec < TYPE_PRECISION (wtype))
8321 : {
8322 572591 : tree t = lang_hooks.types.type_for_size (prec, TYPE_UNSIGNED (wtype));
8323 572591 : if (t && TYPE_PRECISION (t) < TYPE_PRECISION (wtype))
8324 560707 : win = fold_convert (t, win);
8325 : }
8326 : }
8327 :
8328 11798286 : return win;
8329 : }
8330 :
8331 : /* Return OP or a simpler expression for a narrower value
8332 : which can be sign-extended or zero-extended to give back OP.
8333 : Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8334 : or 0 if the value should be sign-extended. */
8335 :
8336 : tree
8337 86290711 : get_narrower (tree op, int *unsignedp_ptr)
8338 : {
8339 86290711 : int uns = 0;
8340 86290711 : bool first = true;
8341 86290711 : tree win = op;
8342 86290711 : bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
8343 :
8344 86290711 : if (TREE_CODE (op) == COMPOUND_EXPR)
8345 : {
8346 90964 : do
8347 90964 : op = TREE_OPERAND (op, 1);
8348 90964 : while (TREE_CODE (op) == COMPOUND_EXPR);
8349 90949 : tree ret = get_narrower (op, unsignedp_ptr);
8350 90949 : if (ret == op)
8351 : return win;
8352 4262 : auto_vec <tree, 16> v;
8353 4262 : unsigned int i;
8354 8531 : for (op = win; TREE_CODE (op) == COMPOUND_EXPR;
8355 4269 : op = TREE_OPERAND (op, 1))
8356 4269 : v.safe_push (op);
8357 17055 : FOR_EACH_VEC_ELT_REVERSE (v, i, op)
8358 4269 : ret = build2_loc (EXPR_LOCATION (op), COMPOUND_EXPR,
8359 4269 : TREE_TYPE (ret), TREE_OPERAND (op, 0),
8360 : ret);
8361 4262 : return ret;
8362 4262 : }
8363 102779843 : while (TREE_CODE (op) == NOP_EXPR)
8364 : {
8365 16613401 : int bitschange
8366 16613401 : = (TYPE_PRECISION (TREE_TYPE (op))
8367 16613401 : - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
8368 :
8369 : /* Truncations are many-one so cannot be removed. */
8370 16613401 : if (bitschange < 0)
8371 : break;
8372 :
8373 : /* See what's inside this conversion. If we decide to strip it,
8374 : we will set WIN. */
8375 :
8376 16580177 : if (bitschange > 0)
8377 : {
8378 3920589 : op = TREE_OPERAND (op, 0);
8379 : /* An extension: the outermost one can be stripped,
8380 : but remember whether it is zero or sign extension. */
8381 3920589 : if (first)
8382 3909578 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8383 : /* Otherwise, if a sign extension has been stripped,
8384 : only sign extensions can now be stripped;
8385 : if a zero extension has been stripped, only zero-extensions. */
8386 11011 : else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
8387 : break;
8388 : first = false;
8389 : }
8390 : else /* bitschange == 0 */
8391 : {
8392 : /* A change in nominal type can always be stripped, but we must
8393 : preserve the unsignedness. */
8394 12659588 : if (first)
8395 12054906 : uns = TYPE_UNSIGNED (TREE_TYPE (op));
8396 12659588 : first = false;
8397 12659588 : op = TREE_OPERAND (op, 0);
8398 : /* Keep trying to narrow, but don't assign op to win if it
8399 : would turn an integral type into something else. */
8400 23540033 : if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
8401 100026 : continue;
8402 : }
8403 :
8404 16480055 : win = op;
8405 : }
8406 :
8407 86199762 : if (TREE_CODE (op) == COMPONENT_REF
8408 : /* Since type_for_size always gives an integer type. */
8409 3024922 : && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
8410 2921652 : && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
8411 : /* Ensure field is laid out already. */
8412 2921652 : && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
8413 89121411 : && tree_fits_uhwi_p (DECL_SIZE (TREE_OPERAND (op, 1))))
8414 : {
8415 2921649 : unsigned HOST_WIDE_INT innerprec
8416 2921649 : = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (op, 1)));
8417 2921649 : int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
8418 2921649 : || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
8419 2921649 : tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
8420 :
8421 : /* We can get this structure field in a narrower type that fits it,
8422 : but the resulting extension to its nominal type (a fullword type)
8423 : must satisfy the same conditions as for other extensions.
8424 :
8425 : Do this only for fields that are aligned (not bit-fields),
8426 : because when bit-field insns will be used there is no
8427 : advantage in doing this. */
8428 :
8429 2921649 : if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
8430 0 : && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
8431 0 : && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
8432 2921649 : && type != 0)
8433 : {
8434 0 : if (first)
8435 0 : uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
8436 0 : win = fold_convert (type, op);
8437 : }
8438 : }
8439 :
8440 86199762 : *unsignedp_ptr = uns;
8441 86199762 : return win;
8442 : }
8443 :
8444 : /* Return true if integer constant C has a value that is permissible
8445 : for TYPE, an integral type. */
8446 :
8447 : bool
8448 199961899 : int_fits_type_p (const_tree c, const_tree type)
8449 : {
8450 199961899 : tree type_low_bound, type_high_bound;
8451 199961899 : bool ok_for_low_bound, ok_for_high_bound;
8452 199961899 : signop sgn_c = TYPE_SIGN (TREE_TYPE (c));
8453 :
8454 : /* Non-standard boolean types can have arbitrary precision but various
8455 : transformations assume that they can only take values 0 and +/-1. */
8456 199961899 : if (TREE_CODE (type) == BOOLEAN_TYPE)
8457 1287405 : return wi::fits_to_boolean_p (wi::to_wide (c), type);
8458 :
8459 198674494 : retry:
8460 198686341 : type_low_bound = TYPE_MIN_VALUE (type);
8461 198686341 : type_high_bound = TYPE_MAX_VALUE (type);
8462 :
8463 : /* If at least one bound of the type is a constant integer, we can check
8464 : ourselves and maybe make a decision. If no such decision is possible, but
8465 : this type is a subtype, try checking against that. Otherwise, use
8466 : fits_to_tree_p, which checks against the precision.
8467 :
8468 : Compute the status for each possibly constant bound, and return if we see
8469 : one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8470 : for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8471 : for "constant known to fit". */
8472 :
8473 : /* Check if c >= type_low_bound. */
8474 198686341 : if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
8475 : {
8476 198686341 : if (tree_int_cst_lt (c, type_low_bound))
8477 : return false;
8478 : ok_for_low_bound = true;
8479 : }
8480 : else
8481 : ok_for_low_bound = false;
8482 :
8483 : /* Check if c <= type_high_bound. */
8484 198431311 : if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
8485 : {
8486 198399719 : if (tree_int_cst_lt (type_high_bound, c))
8487 : return false;
8488 : ok_for_high_bound = true;
8489 : }
8490 : else
8491 : ok_for_high_bound = false;
8492 :
8493 : /* If the constant fits both bounds, the result is known. */
8494 196477077 : if (ok_for_low_bound && ok_for_high_bound)
8495 : return true;
8496 :
8497 : /* Perform some generic filtering which may allow making a decision
8498 : even if the bounds are not constant. First, negative integers
8499 : never fit in unsigned types, */
8500 31592 : if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (wi::to_wide (c)))
8501 0 : return false;
8502 :
8503 : /* Second, narrower types always fit in wider ones. */
8504 31592 : if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
8505 : return true;
8506 :
8507 : /* Third, unsigned integers with top bit set never fit signed types. */
8508 11856 : if (!TYPE_UNSIGNED (type) && sgn_c == UNSIGNED)
8509 : {
8510 14 : int prec = GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (c))) - 1;
8511 14 : if (prec < TYPE_PRECISION (TREE_TYPE (c)))
8512 : {
8513 : /* When a tree_cst is converted to a wide-int, the precision
8514 : is taken from the type. However, if the precision of the
8515 : mode underneath the type is smaller than that, it is
8516 : possible that the value will not fit. The test below
8517 : fails if any bit is set between the sign bit of the
8518 : underlying mode and the top bit of the type. */
8519 14 : if (wi::zext (wi::to_wide (c), prec - 1) != wi::to_wide (c))
8520 : return false;
8521 : }
8522 0 : else if (wi::neg_p (wi::to_wide (c)))
8523 : return false;
8524 : }
8525 :
8526 : /* If we haven't been able to decide at this point, there nothing more we
8527 : can check ourselves here. Look at the base type if we have one and it
8528 : has the same precision. */
8529 11847 : if (TREE_CODE (type) == INTEGER_TYPE
8530 11847 : && TREE_TYPE (type) != 0
8531 23694 : && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
8532 : {
8533 11847 : type = TREE_TYPE (type);
8534 11847 : goto retry;
8535 : }
8536 :
8537 : /* Or to fits_to_tree_p, if nothing else. */
8538 0 : return wi::fits_to_tree_p (wi::to_wide (c), type);
8539 : }
8540 :
8541 : /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8542 : bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8543 : represented (assuming two's-complement arithmetic) within the bit
8544 : precision of the type are returned instead. */
8545 :
8546 : void
8547 23315132 : get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
8548 : {
8549 21767519 : if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
8550 45082651 : && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
8551 21767519 : wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type)), min, TYPE_SIGN (type));
8552 : else
8553 : {
8554 1547613 : if (TYPE_UNSIGNED (type))
8555 1547613 : mpz_set_ui (min, 0);
8556 : else
8557 : {
8558 0 : wide_int mn = wi::min_value (TYPE_PRECISION (type), SIGNED);
8559 0 : wi::to_mpz (mn, min, SIGNED);
8560 0 : }
8561 : }
8562 :
8563 21767519 : if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
8564 45082651 : && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
8565 21767519 : wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type)), max, TYPE_SIGN (type));
8566 : else
8567 : {
8568 1547613 : wide_int mn = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
8569 1547613 : wi::to_mpz (mn, max, TYPE_SIGN (type));
8570 1547613 : }
8571 23315132 : }
8572 :
8573 : /* Return true if VAR is an automatic variable. */
8574 :
8575 : bool
8576 1249400459 : auto_var_p (const_tree var)
8577 : {
8578 1030658774 : return ((((VAR_P (var) && ! DECL_EXTERNAL (var))
8579 224287978 : || TREE_CODE (var) == PARM_DECL)
8580 1126002265 : && ! TREE_STATIC (var))
8581 1399802866 : || TREE_CODE (var) == RESULT_DECL);
8582 : }
8583 :
8584 : /* Return true if VAR is an automatic variable defined in function FN. */
8585 :
8586 : bool
8587 1873117293 : auto_var_in_fn_p (const_tree var, const_tree fn)
8588 : {
8589 632302058 : return (DECL_P (var) && DECL_CONTEXT (var) == fn
8590 2281485270 : && (auto_var_p (var)
8591 6436949 : || TREE_CODE (var) == LABEL_DECL));
8592 : }
8593 :
8594 : /* Subprogram of following function. Called by walk_tree.
8595 :
8596 : Return *TP if it is an automatic variable or parameter of the
8597 : function passed in as DATA. */
8598 :
8599 : static tree
8600 127080 : find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
8601 : {
8602 127080 : tree fn = (tree) data;
8603 :
8604 127080 : if (TYPE_P (*tp))
8605 0 : *walk_subtrees = 0;
8606 :
8607 127080 : else if (DECL_P (*tp)
8608 127080 : && auto_var_in_fn_p (*tp, fn))
8609 118508 : return *tp;
8610 :
8611 : return NULL_TREE;
8612 : }
8613 :
8614 : /* Returns true if T is, contains, or refers to a type with variable
8615 : size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8616 : arguments, but not the return type. If FN is nonzero, only return
8617 : true if a modifier of the type or position of FN is a variable or
8618 : parameter inside FN.
8619 :
8620 : This concept is more general than that of C99 'variably modified types':
8621 : in C99, a struct type is never variably modified because a VLA may not
8622 : appear as a structure member. However, in GNU C code like:
8623 :
8624 : struct S { int i[f()]; };
8625 :
8626 : is valid, and other languages may define similar constructs. */
8627 :
8628 : bool
8629 2485917732 : variably_modified_type_p (tree type, tree fn)
8630 : {
8631 2485917732 : tree t;
8632 :
8633 : /* Test if T is either variable (if FN is zero) or an expression containing
8634 : a variable in FN. If TYPE isn't gimplified, return true also if
8635 : gimplify_one_sizepos would gimplify the expression into a local
8636 : variable. */
8637 : #define RETURN_TRUE_IF_VAR(T) \
8638 : do { tree _t = (T); \
8639 : if (_t != NULL_TREE \
8640 : && _t != error_mark_node \
8641 : && !CONSTANT_CLASS_P (_t) \
8642 : && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8643 : && (!fn \
8644 : || (!TYPE_SIZES_GIMPLIFIED (type) \
8645 : && (TREE_CODE (_t) != VAR_DECL \
8646 : && !CONTAINS_PLACEHOLDER_P (_t))) \
8647 : || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8648 : return true; } while (0)
8649 :
8650 2485917732 : if (type == error_mark_node)
8651 : return false;
8652 :
8653 : /* If TYPE itself has variable size, it is variably modified. */
8654 2485917348 : RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
8655 2485775537 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
8656 :
8657 2485774913 : switch (TREE_CODE (type))
8658 : {
8659 664786575 : case POINTER_TYPE:
8660 664786575 : case REFERENCE_TYPE:
8661 664786575 : case VECTOR_TYPE:
8662 : /* Ada can have pointer types referring to themselves indirectly. */
8663 664786575 : if (TREE_VISITED (type))
8664 : return false;
8665 664786575 : TREE_VISITED (type) = true;
8666 664786575 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8667 : {
8668 81487 : TREE_VISITED (type) = false;
8669 81487 : return true;
8670 : }
8671 664705088 : TREE_VISITED (type) = false;
8672 664705088 : break;
8673 :
8674 141374323 : case FUNCTION_TYPE:
8675 141374323 : case METHOD_TYPE:
8676 : /* If TYPE is a function type, it is variably modified if the
8677 : return type is variably modified. */
8678 141374323 : if (variably_modified_type_p (TREE_TYPE (type), fn))
8679 : return true;
8680 : break;
8681 :
8682 613822999 : case INTEGER_TYPE:
8683 613822999 : case REAL_TYPE:
8684 613822999 : case FIXED_POINT_TYPE:
8685 613822999 : case ENUMERAL_TYPE:
8686 613822999 : case BOOLEAN_TYPE:
8687 : /* Scalar types are variably modified if their end points
8688 : aren't constant. */
8689 613822999 : RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
8690 613822999 : RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
8691 613786817 : break;
8692 :
8693 864678602 : case RECORD_TYPE:
8694 864678602 : case UNION_TYPE:
8695 864678602 : case QUAL_UNION_TYPE:
8696 : /* We can't see if any of the fields are variably-modified by the
8697 : definition we normally use, since that would produce infinite
8698 : recursion via pointers. */
8699 : /* This is variably modified if some field's type is. */
8700 40178966869 : for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
8701 39314288267 : if (TREE_CODE (t) == FIELD_DECL)
8702 : {
8703 1262887549 : RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
8704 1262887549 : RETURN_TRUE_IF_VAR (DECL_SIZE (t));
8705 1262887549 : RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
8706 :
8707 : /* If the type is a qualified union, then the DECL_QUALIFIER
8708 : of fields can also be an expression containing a variable. */
8709 1262887549 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
8710 0 : RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
8711 :
8712 : /* If the field is a qualified union, then it's only a container
8713 : for what's inside so we look into it. That's necessary in LTO
8714 : mode because the sizes of the field tested above have been set
8715 : to PLACEHOLDER_EXPRs by free_lang_data. */
8716 1262887549 : if (TREE_CODE (TREE_TYPE (t)) == QUAL_UNION_TYPE
8717 1262887549 : && variably_modified_type_p (TREE_TYPE (t), fn))
8718 : return true;
8719 : }
8720 : break;
8721 :
8722 14791374 : case ARRAY_TYPE:
8723 : /* Do not call ourselves to avoid infinite recursion. This is
8724 : variably modified if the element type is. */
8725 14791374 : RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
8726 14787884 : RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
8727 14787858 : break;
8728 :
8729 : default:
8730 : break;
8731 : }
8732 :
8733 : /* The current language may have other cases to check, but in general,
8734 : all other types are not variably modified. */
8735 2485653498 : return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
8736 :
8737 : #undef RETURN_TRUE_IF_VAR
8738 : }
8739 :
8740 : /* Given a DECL or TYPE, return the scope in which it was declared, or
8741 : NULL_TREE if there is no containing scope. */
8742 :
8743 : tree
8744 3029481396 : get_containing_scope (const_tree t)
8745 : {
8746 3029481396 : return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8747 : }
8748 :
8749 : /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
8750 :
8751 : const_tree
8752 14482 : get_ultimate_context (const_tree decl)
8753 : {
8754 39749 : while (decl && TREE_CODE (decl) != TRANSLATION_UNIT_DECL)
8755 : {
8756 25267 : if (TREE_CODE (decl) == BLOCK)
8757 0 : decl = BLOCK_SUPERCONTEXT (decl);
8758 : else
8759 25267 : decl = get_containing_scope (decl);
8760 : }
8761 14482 : return decl;
8762 : }
8763 :
8764 : /* Return the innermost context enclosing DECL that is
8765 : a FUNCTION_DECL, or zero if none. */
8766 :
8767 : tree
8768 1527109599 : decl_function_context (const_tree decl)
8769 : {
8770 1527109599 : tree context;
8771 :
8772 1527109599 : if (TREE_CODE (decl) == ERROR_MARK)
8773 : return 0;
8774 :
8775 : /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8776 : where we look up the function at runtime. Such functions always take
8777 : a first argument of type 'pointer to real context'.
8778 :
8779 : C++ should really be fixed to use DECL_CONTEXT for the real context,
8780 : and use something else for the "virtual context". */
8781 1527109599 : else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
8782 4926858 : context
8783 4926858 : = TYPE_MAIN_VARIANT
8784 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8785 : else
8786 1522182741 : context = DECL_CONTEXT (decl);
8787 :
8788 3700083104 : while (context && TREE_CODE (context) != FUNCTION_DECL)
8789 : {
8790 2172973505 : if (TREE_CODE (context) == BLOCK)
8791 0 : context = BLOCK_SUPERCONTEXT (context);
8792 : else
8793 2172973505 : context = get_containing_scope (context);
8794 : }
8795 :
8796 : return context;
8797 : }
8798 :
8799 : /* Return the innermost context enclosing DECL that is
8800 : a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8801 : TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8802 :
8803 : tree
8804 99494293 : decl_type_context (const_tree decl)
8805 : {
8806 99494293 : tree context = DECL_CONTEXT (decl);
8807 :
8808 102662137 : while (context)
8809 96919552 : switch (TREE_CODE (context))
8810 : {
8811 : case NAMESPACE_DECL:
8812 : case TRANSLATION_UNIT_DECL:
8813 : return NULL_TREE;
8814 :
8815 : case RECORD_TYPE:
8816 : case UNION_TYPE:
8817 : case QUAL_UNION_TYPE:
8818 : return context;
8819 :
8820 3167844 : case TYPE_DECL:
8821 3167844 : case FUNCTION_DECL:
8822 3167844 : context = DECL_CONTEXT (context);
8823 3167844 : break;
8824 :
8825 0 : case BLOCK:
8826 0 : context = BLOCK_SUPERCONTEXT (context);
8827 0 : break;
8828 :
8829 0 : default:
8830 0 : gcc_unreachable ();
8831 : }
8832 :
8833 : return NULL_TREE;
8834 : }
8835 :
8836 : /* CALL is a CALL_EXPR. Return the declaration for the function
8837 : called, or NULL_TREE if the called function cannot be
8838 : determined. */
8839 :
8840 : tree
8841 1268506405 : get_callee_fndecl (const_tree call)
8842 : {
8843 1268506405 : tree addr;
8844 :
8845 1268506405 : if (call == error_mark_node)
8846 : return error_mark_node;
8847 :
8848 : /* It's invalid to call this function with anything but a
8849 : CALL_EXPR. */
8850 1268506405 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8851 :
8852 : /* The first operand to the CALL is the address of the function
8853 : called. */
8854 1268506405 : addr = CALL_EXPR_FN (call);
8855 :
8856 : /* If there is no function, return early. */
8857 1268506405 : if (addr == NULL_TREE)
8858 : return NULL_TREE;
8859 :
8860 1265760351 : STRIP_NOPS (addr);
8861 :
8862 : /* If this is a readonly function pointer, extract its initial value. */
8863 21384584 : if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
8864 2536802 : && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
8865 1266432495 : && DECL_INITIAL (addr))
8866 672089 : addr = DECL_INITIAL (addr);
8867 :
8868 : /* If the address is just `&f' for some function `f', then we know
8869 : that `f' is being called. */
8870 1265760351 : if (TREE_CODE (addr) == ADDR_EXPR
8871 1265760351 : && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
8872 1210543781 : return TREE_OPERAND (addr, 0);
8873 :
8874 : /* We couldn't figure out what was being called. */
8875 : return NULL_TREE;
8876 : }
8877 :
8878 : /* Return true when STMTs arguments and return value match those of FNDECL,
8879 : a decl of a builtin function. */
8880 :
8881 : static bool
8882 6516246 : tree_builtin_call_types_compatible_p (const_tree call, tree fndecl)
8883 : {
8884 6516246 : gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
8885 :
8886 6516246 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
8887 6516246 : if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
8888 6516246 : fndecl = decl;
8889 :
8890 6516246 : bool gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
8891 6516246 : if (gimple_form
8892 17880 : ? !useless_type_conversion_p (TREE_TYPE (call),
8893 17880 : TREE_TYPE (TREE_TYPE (fndecl)))
8894 6498366 : : (TYPE_MAIN_VARIANT (TREE_TYPE (call))
8895 6498366 : != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))))
8896 : return false;
8897 :
8898 6516030 : tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
8899 6516030 : unsigned nargs = call_expr_nargs (call);
8900 16431995 : for (unsigned i = 0; i < nargs; ++i, targs = TREE_CHAIN (targs))
8901 : {
8902 : /* Variadic args follow. */
8903 11482045 : if (!targs)
8904 : return true;
8905 9916622 : tree arg = CALL_EXPR_ARG (call, i);
8906 9916622 : tree type = TREE_VALUE (targs);
8907 9916622 : if (gimple_form
8908 9916622 : ? !useless_type_conversion_p (type, TREE_TYPE (arg))
8909 9898742 : : TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (TREE_TYPE (arg)))
8910 : {
8911 : /* For pointer arguments be more forgiving, e.g. due to
8912 : FILE * vs. fileptr_type_node, or say char * vs. const char *
8913 : differences etc. */
8914 1131873 : if (!gimple_form
8915 566265 : && POINTER_TYPE_P (type)
8916 565713 : && POINTER_TYPE_P (TREE_TYPE (arg))
8917 1131873 : && tree_nop_conversion_p (type, TREE_TYPE (arg)))
8918 565608 : continue;
8919 : return false;
8920 : }
8921 : }
8922 9899253 : if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
8923 5 : return false;
8924 : return true;
8925 : }
8926 :
8927 : /* If CALL_EXPR CALL calls a normal built-in function or an internal function,
8928 : return the associated function code, otherwise return CFN_LAST. */
8929 :
8930 : combined_fn
8931 42599298 : get_call_combined_fn (const_tree call)
8932 : {
8933 : /* It's invalid to call this function with anything but a CALL_EXPR. */
8934 42599298 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
8935 :
8936 42599298 : if (!CALL_EXPR_FN (call))
8937 67011 : return as_combined_fn (CALL_EXPR_IFN (call));
8938 :
8939 42532287 : tree fndecl = get_callee_fndecl (call);
8940 42532287 : if (fndecl
8941 42509558 : && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
8942 49048533 : && tree_builtin_call_types_compatible_p (call, fndecl))
8943 6515368 : return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
8944 :
8945 : return CFN_LAST;
8946 : }
8947 :
8948 : /* Comparator of indices based on tree_node_counts. */
8949 :
8950 : static int
8951 0 : tree_nodes_cmp (const void *p1, const void *p2)
8952 : {
8953 0 : const unsigned *n1 = (const unsigned *)p1;
8954 0 : const unsigned *n2 = (const unsigned *)p2;
8955 :
8956 0 : return tree_node_counts[*n1] - tree_node_counts[*n2];
8957 : }
8958 :
8959 : /* Comparator of indices based on tree_code_counts. */
8960 :
8961 : static int
8962 0 : tree_codes_cmp (const void *p1, const void *p2)
8963 : {
8964 0 : const unsigned *n1 = (const unsigned *)p1;
8965 0 : const unsigned *n2 = (const unsigned *)p2;
8966 :
8967 0 : return tree_code_counts[*n1] - tree_code_counts[*n2];
8968 : }
8969 :
8970 : #define TREE_MEM_USAGE_SPACES 40
8971 :
8972 : /* Print debugging information about tree nodes generated during the compile,
8973 : and any language-specific information. */
8974 :
8975 : void
8976 0 : dump_tree_statistics (void)
8977 : {
8978 0 : if (GATHER_STATISTICS)
8979 : {
8980 : uint64_t total_nodes, total_bytes;
8981 : fprintf (stderr, "\nKind Nodes Bytes\n");
8982 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8983 : total_nodes = total_bytes = 0;
8984 :
8985 : {
8986 : auto_vec<unsigned> indices (all_kinds);
8987 : for (unsigned i = 0; i < all_kinds; i++)
8988 : indices.quick_push (i);
8989 : indices.qsort (tree_nodes_cmp);
8990 :
8991 : for (unsigned i = 0; i < (int) all_kinds; i++)
8992 : {
8993 : unsigned j = indices[i];
8994 : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n",
8995 : tree_node_kind_names[j], SIZE_AMOUNT (tree_node_counts[j]),
8996 : SIZE_AMOUNT (tree_node_sizes[j]));
8997 : total_nodes += tree_node_counts[j];
8998 : total_bytes += tree_node_sizes[j];
8999 : }
9000 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
9001 : fprintf (stderr, "%-20s %6" PRIu64 "%c %9" PRIu64 "%c\n", "Total",
9002 : SIZE_AMOUNT (total_nodes), SIZE_AMOUNT (total_bytes));
9003 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
9004 : }
9005 :
9006 : {
9007 : fprintf (stderr, "Code Nodes\n");
9008 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
9009 :
9010 : auto_vec<unsigned> indices (MAX_TREE_CODES);
9011 : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
9012 : indices.quick_push (i);
9013 : indices.qsort (tree_codes_cmp);
9014 :
9015 : for (unsigned i = 0; i < MAX_TREE_CODES; i++)
9016 : {
9017 : unsigned j = indices[i];
9018 : fprintf (stderr, "%-32s %6" PRIu64 "%c\n",
9019 : get_tree_code_name ((enum tree_code) j),
9020 : SIZE_AMOUNT (tree_code_counts[j]));
9021 : }
9022 : mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
9023 : fprintf (stderr, "\n");
9024 : ssanames_print_statistics ();
9025 : fprintf (stderr, "\n");
9026 : phinodes_print_statistics ();
9027 : fprintf (stderr, "\n");
9028 : }
9029 : }
9030 : else
9031 0 : fprintf (stderr, "(No per-node statistics)\n");
9032 :
9033 0 : print_type_hash_statistics ();
9034 0 : print_debug_expr_statistics ();
9035 0 : print_value_expr_statistics ();
9036 0 : lang_hooks.print_statistics ();
9037 0 : }
9038 :
9039 : #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
9040 :
9041 : /* Generate a crc32 of the low BYTES bytes of VALUE. */
9042 :
9043 : unsigned
9044 17583055 : crc32_unsigned_n (unsigned chksum, unsigned value, unsigned bytes)
9045 : {
9046 : /* This relies on the raw feedback's top 4 bits being zero. */
9047 : #define FEEDBACK(X) ((X) * 0x04c11db7)
9048 : #define SYNDROME(X) (FEEDBACK ((X) & 1) ^ FEEDBACK ((X) & 2) \
9049 : ^ FEEDBACK ((X) & 4) ^ FEEDBACK ((X) & 8))
9050 17583055 : static const unsigned syndromes[16] =
9051 : {
9052 : SYNDROME(0x0), SYNDROME(0x1), SYNDROME(0x2), SYNDROME(0x3),
9053 : SYNDROME(0x4), SYNDROME(0x5), SYNDROME(0x6), SYNDROME(0x7),
9054 : SYNDROME(0x8), SYNDROME(0x9), SYNDROME(0xa), SYNDROME(0xb),
9055 : SYNDROME(0xc), SYNDROME(0xd), SYNDROME(0xe), SYNDROME(0xf),
9056 : };
9057 : #undef FEEDBACK
9058 : #undef SYNDROME
9059 :
9060 17583055 : value <<= (32 - bytes * 8);
9061 58581681 : for (unsigned ix = bytes * 2; ix--; value <<= 4)
9062 : {
9063 40998626 : unsigned feedback = syndromes[((value ^ chksum) >> 28) & 0xf];
9064 :
9065 40998626 : chksum = (chksum << 4) ^ feedback;
9066 : }
9067 :
9068 17583055 : return chksum;
9069 : }
9070 :
9071 : /* Generate a crc32 of a string. */
9072 :
9073 : unsigned
9074 10120 : crc32_string (unsigned chksum, const char *string)
9075 : {
9076 405161 : do
9077 405161 : chksum = crc32_byte (chksum, *string);
9078 405161 : while (*string++);
9079 10120 : return chksum;
9080 : }
9081 :
9082 : /* P is a string that will be used in a symbol. Mask out any characters
9083 : that are not valid in that context. */
9084 :
9085 : void
9086 7582 : clean_symbol_name (char *p)
9087 : {
9088 87494 : for (; *p; p++)
9089 79912 : if (! (ISALNUM (*p)
9090 : #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9091 : || *p == '$'
9092 : #endif
9093 : #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9094 : || *p == '.'
9095 : #endif
9096 : ))
9097 7415 : *p = '_';
9098 7582 : }
9099 :
9100 : static GTY(()) unsigned anon_cnt = 0; /* Saved for PCH. */
9101 :
9102 : /* Create a unique anonymous identifier. The identifier is still a
9103 : valid assembly label. */
9104 :
9105 : tree
9106 3672252 : make_anon_name ()
9107 : {
9108 3672252 : const char *fmt =
9109 : #if !defined (NO_DOT_IN_LABEL)
9110 : "."
9111 : #elif !defined (NO_DOLLAR_IN_LABEL)
9112 : "$"
9113 : #else
9114 : "_"
9115 : #endif
9116 : "_anon_%d";
9117 :
9118 3672252 : char buf[24];
9119 3672252 : int len = snprintf (buf, sizeof (buf), fmt, anon_cnt++);
9120 3672252 : gcc_checking_assert (len < int (sizeof (buf)));
9121 :
9122 3672252 : tree id = get_identifier_with_length (buf, len);
9123 3672252 : IDENTIFIER_ANON_P (id) = true;
9124 :
9125 3672252 : return id;
9126 : }
9127 :
9128 : /* Generate a name for a special-purpose function.
9129 : The generated name may need to be unique across the whole link.
9130 : Changes to this function may also require corresponding changes to
9131 : xstrdup_mask_random.
9132 : TYPE is some string to identify the purpose of this function to the
9133 : linker or collect2; it must start with an uppercase letter,
9134 : one of:
9135 : I - for constructors
9136 : D - for destructors
9137 : N - for C++ anonymous namespaces
9138 : F - for DWARF unwind frame information. */
9139 :
9140 : tree
9141 5672 : get_file_function_name (const char *type)
9142 : {
9143 5672 : char *buf;
9144 5672 : const char *p;
9145 5672 : char *q;
9146 :
9147 : /* If we already have a name we know to be unique, just use that. */
9148 5672 : if (first_global_object_name)
9149 5373 : p = q = ASTRDUP (first_global_object_name);
9150 : /* If the target is handling the constructors/destructors, they
9151 : will be local to this file and the name is only necessary for
9152 : debugging purposes.
9153 : We also assign sub_I and sub_D suffixes to constructors called from
9154 : the global static constructors. These are always local.
9155 : OpenMP "declare target" offloaded constructors/destructors use "off_I" and
9156 : "off_D" for the same purpose. */
9157 299 : else if (((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
9158 598 : || ((startswith (type, "sub_") || startswith (type, "off_"))
9159 299 : && (type[4] == 'I' || type[4] == 'D')))
9160 : {
9161 299 : const char *file = main_input_filename;
9162 299 : if (! file)
9163 0 : file = LOCATION_FILE (input_location);
9164 : /* Just use the file's basename, because the full pathname
9165 : might be quite long. */
9166 299 : p = q = ASTRDUP (lbasename (file));
9167 : }
9168 : else
9169 : {
9170 : /* Otherwise, the name must be unique across the entire link.
9171 : We don't have anything that we know to be unique to this translation
9172 : unit, so use what we do have and throw in some randomness. */
9173 0 : unsigned len;
9174 0 : const char *name = weak_global_object_name;
9175 0 : const char *file = main_input_filename;
9176 :
9177 0 : if (! name)
9178 0 : name = "";
9179 0 : if (! file)
9180 0 : file = LOCATION_FILE (input_location);
9181 :
9182 0 : len = strlen (file);
9183 0 : q = (char *) alloca (9 + 19 + len + 1);
9184 0 : memcpy (q, file, len + 1);
9185 :
9186 0 : snprintf (q + len, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
9187 : crc32_string (0, name), get_random_seed (false));
9188 :
9189 0 : p = q;
9190 : }
9191 :
9192 5672 : clean_symbol_name (q);
9193 5672 : buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
9194 : + strlen (type));
9195 :
9196 : /* Set up the name of the file-level functions we may need.
9197 : Use a global object (which is already required to be unique over
9198 : the program) rather than the file name (which imposes extra
9199 : constraints). */
9200 5672 : sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
9201 :
9202 5672 : return get_identifier (buf);
9203 : }
9204 :
9205 : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9206 :
9207 : /* Complain that the tree code of NODE does not match the expected 0
9208 : terminated list of trailing codes. The trailing code list can be
9209 : empty, for a more vague error message. FILE, LINE, and FUNCTION
9210 : are of the caller. */
9211 :
9212 : void
9213 0 : tree_check_failed (const_tree node, const char *file,
9214 : int line, const char *function, ...)
9215 : {
9216 0 : va_list args;
9217 0 : const char *buffer;
9218 0 : unsigned length = 0;
9219 0 : enum tree_code code;
9220 :
9221 0 : va_start (args, function);
9222 0 : while ((code = (enum tree_code) va_arg (args, int)))
9223 0 : length += 4 + strlen (get_tree_code_name (code));
9224 0 : va_end (args);
9225 0 : if (length)
9226 : {
9227 0 : char *tmp;
9228 0 : va_start (args, function);
9229 0 : length += strlen ("expected ");
9230 0 : buffer = tmp = (char *) alloca (length);
9231 0 : length = 0;
9232 0 : while ((code = (enum tree_code) va_arg (args, int)))
9233 : {
9234 0 : const char *prefix = length ? " or " : "expected ";
9235 :
9236 0 : strcpy (tmp + length, prefix);
9237 0 : length += strlen (prefix);
9238 0 : strcpy (tmp + length, get_tree_code_name (code));
9239 0 : length += strlen (get_tree_code_name (code));
9240 : }
9241 0 : va_end (args);
9242 : }
9243 : else
9244 : buffer = "unexpected node";
9245 :
9246 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9247 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9248 : function, trim_filename (file), line);
9249 : }
9250 :
9251 : /* Complain that the tree code of NODE does match the expected 0
9252 : terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9253 : the caller. */
9254 :
9255 : void
9256 0 : tree_not_check_failed (const_tree node, const char *file,
9257 : int line, const char *function, ...)
9258 : {
9259 0 : va_list args;
9260 0 : char *buffer;
9261 0 : unsigned length = 0;
9262 0 : enum tree_code code;
9263 :
9264 0 : va_start (args, function);
9265 0 : while ((code = (enum tree_code) va_arg (args, int)))
9266 0 : length += 4 + strlen (get_tree_code_name (code));
9267 0 : va_end (args);
9268 0 : va_start (args, function);
9269 0 : buffer = (char *) alloca (length);
9270 0 : length = 0;
9271 0 : while ((code = (enum tree_code) va_arg (args, int)))
9272 : {
9273 0 : if (length)
9274 : {
9275 0 : strcpy (buffer + length, " or ");
9276 0 : length += 4;
9277 : }
9278 0 : strcpy (buffer + length, get_tree_code_name (code));
9279 0 : length += strlen (get_tree_code_name (code));
9280 : }
9281 0 : va_end (args);
9282 :
9283 0 : internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9284 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9285 : function, trim_filename (file), line);
9286 : }
9287 :
9288 : /* Similar to tree_check_failed, except that we check for a class of tree
9289 : code, given in CL. */
9290 :
9291 : void
9292 0 : tree_class_check_failed (const_tree node, const enum tree_code_class cl,
9293 : const char *file, int line, const char *function)
9294 : {
9295 0 : internal_error
9296 0 : ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9297 0 : TREE_CODE_CLASS_STRING (cl),
9298 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9299 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9300 : }
9301 :
9302 : /* Similar to tree_check_failed, except that instead of specifying a
9303 : dozen codes, use the knowledge that they're all sequential. */
9304 :
9305 : void
9306 0 : tree_range_check_failed (const_tree node, const char *file, int line,
9307 : const char *function, enum tree_code c1,
9308 : enum tree_code c2)
9309 : {
9310 0 : char *buffer;
9311 0 : unsigned length = 0;
9312 0 : unsigned int c;
9313 :
9314 0 : for (c = c1; c <= c2; ++c)
9315 0 : length += 4 + strlen (get_tree_code_name ((enum tree_code) c));
9316 :
9317 0 : length += strlen ("expected ");
9318 0 : buffer = (char *) alloca (length);
9319 0 : length = 0;
9320 :
9321 0 : for (c = c1; c <= c2; ++c)
9322 : {
9323 0 : const char *prefix = length ? " or " : "expected ";
9324 :
9325 0 : strcpy (buffer + length, prefix);
9326 0 : length += strlen (prefix);
9327 0 : strcpy (buffer + length, get_tree_code_name ((enum tree_code) c));
9328 0 : length += strlen (get_tree_code_name ((enum tree_code) c));
9329 : }
9330 :
9331 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9332 0 : buffer, get_tree_code_name (TREE_CODE (node)),
9333 : function, trim_filename (file), line);
9334 : }
9335 :
9336 :
9337 : /* Similar to tree_check_failed, except that we check that a tree does
9338 : not have the specified code, given in CL. */
9339 :
9340 : void
9341 0 : tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
9342 : const char *file, int line, const char *function)
9343 : {
9344 0 : internal_error
9345 0 : ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9346 0 : TREE_CODE_CLASS_STRING (cl),
9347 0 : TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
9348 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9349 : }
9350 :
9351 :
9352 : /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9353 :
9354 : void
9355 0 : omp_clause_check_failed (const_tree node, const char *file, int line,
9356 : const char *function, enum omp_clause_code code)
9357 : {
9358 0 : internal_error ("tree check: expected %<omp_clause %s%>, have %qs "
9359 : "in %s, at %s:%d",
9360 0 : omp_clause_code_name[code],
9361 0 : get_tree_code_name (TREE_CODE (node)),
9362 : function, trim_filename (file), line);
9363 : }
9364 :
9365 :
9366 : /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9367 :
9368 : void
9369 0 : omp_clause_range_check_failed (const_tree node, const char *file, int line,
9370 : const char *function, enum omp_clause_code c1,
9371 : enum omp_clause_code c2)
9372 : {
9373 0 : char *buffer;
9374 0 : unsigned length = 0;
9375 0 : unsigned int c;
9376 :
9377 0 : for (c = c1; c <= c2; ++c)
9378 0 : length += 4 + strlen (omp_clause_code_name[c]);
9379 :
9380 0 : length += strlen ("expected ");
9381 0 : buffer = (char *) alloca (length);
9382 0 : length = 0;
9383 :
9384 0 : for (c = c1; c <= c2; ++c)
9385 : {
9386 0 : const char *prefix = length ? " or " : "expected ";
9387 :
9388 0 : strcpy (buffer + length, prefix);
9389 0 : length += strlen (prefix);
9390 0 : strcpy (buffer + length, omp_clause_code_name[c]);
9391 0 : length += strlen (omp_clause_code_name[c]);
9392 : }
9393 :
9394 0 : internal_error ("tree check: %s, have %s in %s, at %s:%d",
9395 0 : buffer, omp_clause_code_name[TREE_CODE (node)],
9396 : function, trim_filename (file), line);
9397 : }
9398 :
9399 :
9400 : #undef DEFTREESTRUCT
9401 : #define DEFTREESTRUCT(VAL, NAME) NAME,
9402 :
9403 : static const char *ts_enum_names[] = {
9404 : #include "treestruct.def"
9405 : };
9406 : #undef DEFTREESTRUCT
9407 :
9408 : #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9409 :
9410 : /* Similar to tree_class_check_failed, except that we check for
9411 : whether CODE contains the tree structure identified by EN. */
9412 :
9413 : void
9414 0 : tree_contains_struct_check_failed (const_tree node,
9415 : const enum tree_node_structure_enum en,
9416 : const char *file, int line,
9417 : const char *function)
9418 : {
9419 0 : internal_error
9420 0 : ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9421 0 : TS_ENUM_NAME (en),
9422 0 : get_tree_code_name (TREE_CODE (node)), function, trim_filename (file), line);
9423 : }
9424 :
9425 :
9426 : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9427 : (dynamically sized) vector. */
9428 :
9429 : void
9430 0 : tree_int_cst_elt_check_failed (int idx, int len, const char *file, int line,
9431 : const char *function)
9432 : {
9433 0 : internal_error
9434 0 : ("tree check: accessed elt %d of %<tree_int_cst%> with %d elts in %s, "
9435 : "at %s:%d",
9436 : idx + 1, len, function, trim_filename (file), line);
9437 : }
9438 :
9439 : /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9440 : (dynamically sized) vector. */
9441 :
9442 : void
9443 0 : tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
9444 : const char *function)
9445 : {
9446 0 : internal_error
9447 0 : ("tree check: accessed elt %d of %<tree_vec%> with %d elts in %s, at %s:%d",
9448 : idx + 1, len, function, trim_filename (file), line);
9449 : }
9450 :
9451 : /* Similar to above, except that the check is for the bounds of the operand
9452 : vector of an expression node EXP. */
9453 :
9454 : void
9455 0 : tree_operand_check_failed (int idx, const_tree exp, const char *file,
9456 : int line, const char *function)
9457 : {
9458 0 : enum tree_code code = TREE_CODE (exp);
9459 0 : internal_error
9460 0 : ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9461 : idx + 1, get_tree_code_name (code), TREE_OPERAND_LENGTH (exp),
9462 : function, trim_filename (file), line);
9463 : }
9464 :
9465 : /* Similar to above, except that the check is for the number of
9466 : operands of an OMP_CLAUSE node. */
9467 :
9468 : void
9469 0 : omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
9470 : int line, const char *function)
9471 : {
9472 0 : internal_error
9473 0 : ("tree check: accessed operand %d of %<omp_clause %s%> with %d operands "
9474 0 : "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
9475 0 : omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
9476 : trim_filename (file), line);
9477 : }
9478 : #endif /* ENABLE_TREE_CHECKING */
9479 :
9480 : /* Create a new vector type node holding NUNITS units of type INNERTYPE,
9481 : and mapped to the machine mode MODE. Initialize its fields and build
9482 : the information necessary for debugging output. */
9483 :
9484 : static tree
9485 72366630 : make_vector_type (tree innertype, poly_int64 nunits, machine_mode mode)
9486 : {
9487 72366630 : tree t;
9488 72366630 : tree mv_innertype = TYPE_MAIN_VARIANT (innertype);
9489 :
9490 72366630 : t = make_node (VECTOR_TYPE);
9491 72366630 : TREE_TYPE (t) = mv_innertype;
9492 72366630 : SET_TYPE_VECTOR_SUBPARTS (t, nunits);
9493 72366630 : SET_TYPE_MODE (t, mode);
9494 :
9495 72366630 : if (TYPE_STRUCTURAL_EQUALITY_P (mv_innertype) || in_lto_p)
9496 1176172 : SET_TYPE_STRUCTURAL_EQUALITY (t);
9497 71190458 : else if ((TYPE_CANONICAL (mv_innertype) != innertype
9498 67439843 : || mode != VOIDmode)
9499 102861195 : && !VECTOR_BOOLEAN_TYPE_P (t))
9500 32738730 : TYPE_CANONICAL (t)
9501 65477460 : = make_vector_type (TYPE_CANONICAL (mv_innertype), nunits, VOIDmode);
9502 :
9503 72366630 : layout_type (t);
9504 :
9505 72366630 : hashval_t hash = type_hash_canon_hash (t);
9506 72366630 : t = type_hash_canon (hash, t);
9507 :
9508 : /* We have built a main variant, based on the main variant of the
9509 : inner type. Use it to build the variant we return. */
9510 144727613 : if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
9511 73272575 : && TREE_TYPE (t) != innertype)
9512 910278 : return build_type_attribute_qual_variant (t,
9513 910278 : TYPE_ATTRIBUTES (innertype),
9514 1820556 : TYPE_QUALS (innertype));
9515 :
9516 : return t;
9517 : }
9518 :
9519 : static tree
9520 4112217 : make_or_reuse_type (unsigned size, int unsignedp)
9521 : {
9522 4112217 : int i;
9523 :
9524 4112217 : if (size == INT_TYPE_SIZE)
9525 882720 : return unsignedp ? unsigned_type_node : integer_type_node;
9526 3229497 : if (size == CHAR_TYPE_SIZE)
9527 588480 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
9528 2641017 : if (size == SHORT_TYPE_SIZE)
9529 882720 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
9530 1794576 : if (size == LONG_TYPE_SIZE)
9531 861009 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
9532 897288 : if (size == LONG_LONG_TYPE_SIZE)
9533 21711 : return (unsignedp ? long_long_unsigned_type_node
9534 21711 : : long_long_integer_type_node);
9535 :
9536 889863 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9537 875577 : if (size == int_n_data[i].bitsize
9538 875577 : && int_n_enabled_p[i])
9539 861291 : return (unsignedp ? int_n_trees[i].unsigned_type
9540 861291 : : int_n_trees[i].signed_type);
9541 :
9542 14286 : if (unsignedp)
9543 7143 : return make_unsigned_type (size);
9544 : else
9545 7143 : return make_signed_type (size);
9546 : }
9547 :
9548 : /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9549 :
9550 : static tree
9551 5884800 : make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
9552 : {
9553 5884800 : if (satp)
9554 : {
9555 2942400 : if (size == SHORT_FRACT_TYPE_SIZE)
9556 588480 : return unsignedp ? sat_unsigned_short_fract_type_node
9557 588480 : : sat_short_fract_type_node;
9558 2353920 : if (size == FRACT_TYPE_SIZE)
9559 588480 : return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
9560 1765440 : if (size == LONG_FRACT_TYPE_SIZE)
9561 588480 : return unsignedp ? sat_unsigned_long_fract_type_node
9562 588480 : : sat_long_fract_type_node;
9563 1176960 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9564 588480 : return unsignedp ? sat_unsigned_long_long_fract_type_node
9565 588480 : : sat_long_long_fract_type_node;
9566 : }
9567 : else
9568 : {
9569 2942400 : if (size == SHORT_FRACT_TYPE_SIZE)
9570 588480 : return unsignedp ? unsigned_short_fract_type_node
9571 588480 : : short_fract_type_node;
9572 2353920 : if (size == FRACT_TYPE_SIZE)
9573 588480 : return unsignedp ? unsigned_fract_type_node : fract_type_node;
9574 1765440 : if (size == LONG_FRACT_TYPE_SIZE)
9575 588480 : return unsignedp ? unsigned_long_fract_type_node
9576 588480 : : long_fract_type_node;
9577 1176960 : if (size == LONG_LONG_FRACT_TYPE_SIZE)
9578 588480 : return unsignedp ? unsigned_long_long_fract_type_node
9579 588480 : : long_long_fract_type_node;
9580 : }
9581 :
9582 1176960 : return make_fract_type (size, unsignedp, satp);
9583 : }
9584 :
9585 : /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9586 :
9587 : static tree
9588 4707840 : make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
9589 : {
9590 4707840 : if (satp)
9591 : {
9592 2353920 : if (size == SHORT_ACCUM_TYPE_SIZE)
9593 588480 : return unsignedp ? sat_unsigned_short_accum_type_node
9594 588480 : : sat_short_accum_type_node;
9595 1765440 : if (size == ACCUM_TYPE_SIZE)
9596 588480 : return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
9597 1176960 : if (size == LONG_ACCUM_TYPE_SIZE)
9598 588480 : return unsignedp ? sat_unsigned_long_accum_type_node
9599 588480 : : sat_long_accum_type_node;
9600 588480 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9601 588480 : return unsignedp ? sat_unsigned_long_long_accum_type_node
9602 588480 : : sat_long_long_accum_type_node;
9603 : }
9604 : else
9605 : {
9606 2353920 : if (size == SHORT_ACCUM_TYPE_SIZE)
9607 588480 : return unsignedp ? unsigned_short_accum_type_node
9608 588480 : : short_accum_type_node;
9609 1765440 : if (size == ACCUM_TYPE_SIZE)
9610 588480 : return unsignedp ? unsigned_accum_type_node : accum_type_node;
9611 1176960 : if (size == LONG_ACCUM_TYPE_SIZE)
9612 588480 : return unsignedp ? unsigned_long_accum_type_node
9613 588480 : : long_accum_type_node;
9614 588480 : if (size == LONG_LONG_ACCUM_TYPE_SIZE)
9615 588480 : return unsignedp ? unsigned_long_long_accum_type_node
9616 588480 : : long_long_accum_type_node;
9617 : }
9618 :
9619 0 : return make_accum_type (size, unsignedp, satp);
9620 : }
9621 :
9622 :
9623 : /* Create an atomic variant node for TYPE. This routine is called
9624 : during initialization of data types to create the 5 basic atomic
9625 : types. The generic build_variant_type function requires these to
9626 : already be set up in order to function properly, so cannot be
9627 : called from there. If ALIGN is non-zero, then ensure alignment is
9628 : overridden to this value. */
9629 :
9630 : static tree
9631 1471200 : build_atomic_base (tree type, unsigned int align)
9632 : {
9633 1471200 : tree t;
9634 :
9635 : /* Make sure its not already registered. */
9636 1471200 : if ((t = get_qualified_type (type, TYPE_QUAL_ATOMIC)))
9637 : return t;
9638 :
9639 1471200 : t = build_variant_type_copy (type);
9640 1471200 : set_type_quals (t, TYPE_QUAL_ATOMIC);
9641 :
9642 1471200 : if (align)
9643 0 : SET_TYPE_ALIGN (t, align);
9644 :
9645 : return t;
9646 : }
9647 :
9648 : /* Return unsigned integer tree node for TYPE. */
9649 :
9650 : tree
9651 294280 : unsigned_integer_tree_node_for_type (const char *type)
9652 : {
9653 294280 : tree type_node;
9654 :
9655 294280 : if (strcmp (type, "unsigned int") == 0)
9656 7237 : type_node = unsigned_type_node;
9657 287043 : else if (strcmp (type, "long unsigned int") == 0)
9658 287043 : type_node = long_unsigned_type_node;
9659 0 : else if (strcmp (type, "long long unsigned int") == 0)
9660 0 : type_node = long_long_unsigned_type_node;
9661 0 : else if (strcmp (type, "short unsigned int") == 0)
9662 0 : type_node = short_unsigned_type_node;
9663 : else
9664 : {
9665 : int i;
9666 :
9667 : type_node = nullptr;
9668 0 : for (i = 0; i < NUM_INT_N_ENTS; i++)
9669 0 : if (int_n_enabled_p[i])
9670 : {
9671 0 : char name[50], altname[50];
9672 0 : sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
9673 0 : sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize);
9674 :
9675 0 : if (strcmp (name, type) == 0
9676 0 : || strcmp (altname, type) == 0)
9677 : {
9678 0 : type_node = int_n_trees[i].unsigned_type;
9679 : }
9680 : }
9681 0 : if (type_node == nullptr)
9682 0 : gcc_unreachable ();
9683 : }
9684 :
9685 294280 : return type_node;
9686 : }
9687 :
9688 : /* Information about the _FloatN and _FloatNx types. This must be in
9689 : the same order as the corresponding TI_* enum values. */
9690 : const floatn_type_info floatn_nx_types[NUM_FLOATN_NX_TYPES] =
9691 : {
9692 : { 16, false },
9693 : { 32, false },
9694 : { 64, false },
9695 : { 128, false },
9696 : { 32, true },
9697 : { 64, true },
9698 : { 128, true },
9699 : };
9700 :
9701 :
9702 : /* Create nodes for all integer types (and error_mark_node) using the sizes
9703 : of C datatypes. SIGNED_CHAR specifies whether char is signed. */
9704 :
9705 : void
9706 294240 : build_common_tree_nodes (bool signed_char)
9707 : {
9708 294240 : int i;
9709 :
9710 294240 : error_mark_node = make_node (ERROR_MARK);
9711 294240 : TREE_TYPE (error_mark_node) = error_mark_node;
9712 :
9713 294240 : initialize_sizetypes ();
9714 :
9715 : /* Define both `signed char' and `unsigned char'. */
9716 294240 : signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
9717 294240 : TYPE_STRING_FLAG (signed_char_type_node) = 1;
9718 294240 : unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
9719 294240 : TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
9720 :
9721 : /* Define `char', which is like either `signed char' or `unsigned char'
9722 : but not the same as either. */
9723 294240 : char_type_node
9724 294240 : = (signed_char
9725 294240 : ? make_signed_type (CHAR_TYPE_SIZE)
9726 57756 : : make_unsigned_type (CHAR_TYPE_SIZE));
9727 294240 : TYPE_STRING_FLAG (char_type_node) = 1;
9728 :
9729 294240 : short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
9730 294240 : short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
9731 294240 : integer_type_node = make_signed_type (INT_TYPE_SIZE);
9732 294240 : unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
9733 301477 : long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
9734 301477 : long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
9735 294240 : long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
9736 294240 : long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
9737 :
9738 588480 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
9739 : {
9740 294240 : int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
9741 294240 : int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
9742 :
9743 294240 : if (int_n_enabled_p[i])
9744 : {
9745 287097 : integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type;
9746 287097 : integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type;
9747 : }
9748 : }
9749 :
9750 : /* Define a boolean type. This type only represents boolean values but
9751 : may be larger than char depending on the value of BOOL_TYPE_SIZE. */
9752 294240 : boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
9753 294240 : TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
9754 294240 : TYPE_PRECISION (boolean_type_node) = 1;
9755 294240 : TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
9756 :
9757 : /* Define what type to use for size_t. */
9758 301477 : size_type_node = unsigned_integer_tree_node_for_type (SIZE_TYPE);
9759 :
9760 : /* Define what type to use for ptrdiff_t. */
9761 301477 : if (strcmp (PTRDIFF_TYPE, "int") == 0)
9762 7237 : ptrdiff_type_node = integer_type_node;
9763 287003 : else if (strcmp (PTRDIFF_TYPE, "long int") == 0)
9764 287003 : ptrdiff_type_node = long_integer_type_node;
9765 0 : else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)
9766 0 : ptrdiff_type_node = long_long_integer_type_node;
9767 0 : else if (strcmp (PTRDIFF_TYPE, "short int") == 0)
9768 0 : ptrdiff_type_node = short_integer_type_node;
9769 : else
9770 : {
9771 0 : ptrdiff_type_node = NULL_TREE;
9772 0 : for (int i = 0; i < NUM_INT_N_ENTS; i++)
9773 0 : if (int_n_enabled_p[i])
9774 : {
9775 0 : char name[50], altname[50];
9776 0 : sprintf (name, "__int%d", int_n_data[i].bitsize);
9777 0 : sprintf (altname, "__int%d__", int_n_data[i].bitsize);
9778 :
9779 0 : if (strcmp (name, PTRDIFF_TYPE) == 0
9780 0 : || strcmp (altname, PTRDIFF_TYPE) == 0)
9781 0 : ptrdiff_type_node = int_n_trees[i].signed_type;
9782 : }
9783 0 : if (ptrdiff_type_node == NULL_TREE)
9784 0 : gcc_unreachable ();
9785 : }
9786 :
9787 : /* Fill in the rest of the sized types. Reuse existing type nodes
9788 : when possible. */
9789 294240 : intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
9790 294240 : intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
9791 294240 : intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
9792 294240 : intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
9793 294240 : intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
9794 :
9795 294240 : unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
9796 294240 : unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
9797 294240 : unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
9798 294240 : unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
9799 294240 : unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
9800 :
9801 : /* Don't call build_qualified type for atomics. That routine does
9802 : special processing for atomics, and until they are initialized
9803 : it's better not to make that call.
9804 :
9805 : Check to see if there is a target override for atomic types. */
9806 :
9807 294240 : atomicQI_type_node = build_atomic_base (unsigned_intQI_type_node,
9808 294240 : targetm.atomic_align_for_mode (QImode));
9809 294240 : atomicHI_type_node = build_atomic_base (unsigned_intHI_type_node,
9810 294240 : targetm.atomic_align_for_mode (HImode));
9811 294240 : atomicSI_type_node = build_atomic_base (unsigned_intSI_type_node,
9812 294240 : targetm.atomic_align_for_mode (SImode));
9813 294240 : atomicDI_type_node = build_atomic_base (unsigned_intDI_type_node,
9814 294240 : targetm.atomic_align_for_mode (DImode));
9815 294240 : atomicTI_type_node = build_atomic_base (unsigned_intTI_type_node,
9816 294240 : targetm.atomic_align_for_mode (TImode));
9817 :
9818 294240 : access_public_node = get_identifier ("public");
9819 294240 : access_protected_node = get_identifier ("protected");
9820 294240 : access_private_node = get_identifier ("private");
9821 :
9822 : /* Define these next since types below may used them. */
9823 294240 : integer_zero_node = build_int_cst (integer_type_node, 0);
9824 294240 : integer_one_node = build_int_cst (integer_type_node, 1);
9825 294240 : integer_minus_one_node = build_int_cst (integer_type_node, -1);
9826 :
9827 294240 : size_zero_node = size_int (0);
9828 294240 : size_one_node = size_int (1);
9829 294240 : bitsize_zero_node = bitsize_int (0);
9830 294240 : bitsize_one_node = bitsize_int (1);
9831 294240 : bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
9832 :
9833 294240 : boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9834 294240 : boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9835 :
9836 294240 : void_type_node = make_node (VOID_TYPE);
9837 294240 : layout_type (void_type_node);
9838 :
9839 : /* We are not going to have real types in C with less than byte alignment,
9840 : so we might as well not have any types that claim to have it. */
9841 294240 : SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT);
9842 294240 : TYPE_USER_ALIGN (void_type_node) = 0;
9843 :
9844 294240 : void_node = make_node (VOID_CST);
9845 294240 : TREE_TYPE (void_node) = void_type_node;
9846 :
9847 294240 : void_list_node = build_tree_list (NULL_TREE, void_type_node);
9848 :
9849 294240 : null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
9850 294240 : layout_type (TREE_TYPE (null_pointer_node));
9851 :
9852 294240 : ptr_type_node = build_pointer_type (void_type_node);
9853 294240 : const_ptr_type_node
9854 294240 : = build_pointer_type (build_type_variant (void_type_node, 1, 0));
9855 2059680 : for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
9856 1765440 : builtin_structptr_types[i].node = builtin_structptr_types[i].base;
9857 :
9858 301477 : pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
9859 :
9860 294240 : float_type_node = make_node (REAL_TYPE);
9861 294240 : machine_mode float_type_mode
9862 294240 : = targetm.c.mode_for_floating_type (TI_FLOAT_TYPE);
9863 294240 : SET_TYPE_MODE (float_type_node, float_type_mode);
9864 294240 : TYPE_PRECISION (float_type_node)
9865 294240 : = GET_MODE_PRECISION (float_type_mode).to_constant ();
9866 294240 : layout_type (float_type_node);
9867 :
9868 294240 : double_type_node = make_node (REAL_TYPE);
9869 294240 : machine_mode double_type_mode
9870 294240 : = targetm.c.mode_for_floating_type (TI_DOUBLE_TYPE);
9871 294240 : SET_TYPE_MODE (double_type_node, double_type_mode);
9872 294240 : TYPE_PRECISION (double_type_node)
9873 294240 : = GET_MODE_PRECISION (double_type_mode).to_constant ();
9874 294240 : layout_type (double_type_node);
9875 :
9876 294240 : long_double_type_node = make_node (REAL_TYPE);
9877 294240 : machine_mode long_double_type_mode
9878 294240 : = targetm.c.mode_for_floating_type (TI_LONG_DOUBLE_TYPE);
9879 294240 : SET_TYPE_MODE (long_double_type_node, long_double_type_mode);
9880 294240 : TYPE_PRECISION (long_double_type_node)
9881 294240 : = GET_MODE_PRECISION (long_double_type_mode).to_constant ();
9882 294240 : layout_type (long_double_type_node);
9883 :
9884 2648160 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9885 : {
9886 2059680 : int n = floatn_nx_types[i].n;
9887 2059680 : bool extended = floatn_nx_types[i].extended;
9888 2059680 : scalar_float_mode mode;
9889 2059680 : if (!targetm.floatn_mode (n, extended).exists (&mode))
9890 294240 : continue;
9891 1765440 : int precision = GET_MODE_PRECISION (mode);
9892 1765440 : FLOATN_NX_TYPE_NODE (i) = make_node (REAL_TYPE);
9893 1765440 : TYPE_PRECISION (FLOATN_NX_TYPE_NODE (i)) = precision;
9894 1765440 : layout_type (FLOATN_NX_TYPE_NODE (i));
9895 1765440 : SET_TYPE_MODE (FLOATN_NX_TYPE_NODE (i), mode);
9896 : }
9897 294240 : float128t_type_node = float128_type_node;
9898 : #ifdef HAVE_BFmode
9899 294240 : if (REAL_MODE_FORMAT (BFmode) == &arm_bfloat_half_format
9900 294240 : && targetm.scalar_mode_supported_p (BFmode)
9901 588480 : && targetm.libgcc_floating_mode_supported_p (BFmode))
9902 : {
9903 294240 : bfloat16_type_node = make_node (REAL_TYPE);
9904 294240 : TYPE_PRECISION (bfloat16_type_node) = GET_MODE_PRECISION (BFmode);
9905 294240 : layout_type (bfloat16_type_node);
9906 294240 : SET_TYPE_MODE (bfloat16_type_node, BFmode);
9907 : }
9908 : #endif
9909 :
9910 294240 : float_ptr_type_node = build_pointer_type (float_type_node);
9911 294240 : double_ptr_type_node = build_pointer_type (double_type_node);
9912 294240 : long_double_ptr_type_node = build_pointer_type (long_double_type_node);
9913 294240 : integer_ptr_type_node = build_pointer_type (integer_type_node);
9914 :
9915 : /* Fixed size integer types. */
9916 294240 : uint16_type_node = make_or_reuse_type (16, 1);
9917 294240 : uint32_type_node = make_or_reuse_type (32, 1);
9918 294240 : uint64_type_node = make_or_reuse_type (64, 1);
9919 294240 : if (targetm.scalar_mode_supported_p (TImode))
9920 287097 : uint128_type_node = make_or_reuse_type (128, 1);
9921 :
9922 : /* Decimal float types. */
9923 294240 : if (targetm.decimal_float_supported_p ())
9924 : {
9925 294240 : dfloat32_type_node = make_node (REAL_TYPE);
9926 294240 : TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
9927 294240 : SET_TYPE_MODE (dfloat32_type_node, SDmode);
9928 294240 : layout_type (dfloat32_type_node);
9929 :
9930 294240 : dfloat64_type_node = make_node (REAL_TYPE);
9931 294240 : TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
9932 294240 : SET_TYPE_MODE (dfloat64_type_node, DDmode);
9933 294240 : layout_type (dfloat64_type_node);
9934 :
9935 294240 : dfloat128_type_node = make_node (REAL_TYPE);
9936 294240 : TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
9937 294240 : SET_TYPE_MODE (dfloat128_type_node, TDmode);
9938 294240 : layout_type (dfloat128_type_node);
9939 :
9940 294240 : dfloat64x_type_node = make_node (REAL_TYPE);
9941 294240 : TYPE_PRECISION (dfloat64x_type_node) = DECIMAL128_TYPE_SIZE;
9942 294240 : SET_TYPE_MODE (dfloat64x_type_node, TDmode);
9943 294240 : layout_type (dfloat64x_type_node);
9944 : }
9945 :
9946 294240 : complex_integer_type_node = build_complex_type (integer_type_node, true);
9947 294240 : complex_float_type_node = build_complex_type (float_type_node, true);
9948 294240 : complex_double_type_node = build_complex_type (double_type_node, true);
9949 294240 : complex_long_double_type_node = build_complex_type (long_double_type_node,
9950 : true);
9951 :
9952 2353920 : for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
9953 : {
9954 2059680 : if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
9955 1765440 : COMPLEX_FLOATN_NX_TYPE_NODE (i)
9956 1765440 : = build_complex_type (FLOATN_NX_TYPE_NODE (i));
9957 : }
9958 :
9959 : /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9960 : #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9961 : sat_ ## KIND ## _type_node = \
9962 : make_sat_signed_ ## KIND ## _type (SIZE); \
9963 : sat_unsigned_ ## KIND ## _type_node = \
9964 : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9965 : KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9966 : unsigned_ ## KIND ## _type_node = \
9967 : make_unsigned_ ## KIND ## _type (SIZE);
9968 :
9969 : #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9970 : sat_ ## WIDTH ## KIND ## _type_node = \
9971 : make_sat_signed_ ## KIND ## _type (SIZE); \
9972 : sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9973 : make_sat_unsigned_ ## KIND ## _type (SIZE); \
9974 : WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9975 : unsigned_ ## WIDTH ## KIND ## _type_node = \
9976 : make_unsigned_ ## KIND ## _type (SIZE);
9977 :
9978 : /* Make fixed-point type nodes based on four different widths. */
9979 : #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9980 : MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9981 : MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9982 : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9983 : MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9984 :
9985 : /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9986 : #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9987 : NAME ## _type_node = \
9988 : make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9989 : u ## NAME ## _type_node = \
9990 : make_or_reuse_unsigned_ ## KIND ## _type \
9991 : (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9992 : sat_ ## NAME ## _type_node = \
9993 : make_or_reuse_sat_signed_ ## KIND ## _type \
9994 : (GET_MODE_BITSIZE (MODE ## mode)); \
9995 : sat_u ## NAME ## _type_node = \
9996 : make_or_reuse_sat_unsigned_ ## KIND ## _type \
9997 : (GET_MODE_BITSIZE (U ## MODE ## mode));
9998 :
9999 : /* Fixed-point type and mode nodes. */
10000 294240 : MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
10001 294240 : MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
10002 294240 : MAKE_FIXED_MODE_NODE (fract, qq, QQ)
10003 294240 : MAKE_FIXED_MODE_NODE (fract, hq, HQ)
10004 294240 : MAKE_FIXED_MODE_NODE (fract, sq, SQ)
10005 294240 : MAKE_FIXED_MODE_NODE (fract, dq, DQ)
10006 294240 : MAKE_FIXED_MODE_NODE (fract, tq, TQ)
10007 294240 : MAKE_FIXED_MODE_NODE (accum, ha, HA)
10008 294240 : MAKE_FIXED_MODE_NODE (accum, sa, SA)
10009 294240 : MAKE_FIXED_MODE_NODE (accum, da, DA)
10010 294240 : MAKE_FIXED_MODE_NODE (accum, ta, TA)
10011 :
10012 294240 : {
10013 294240 : tree t = targetm.build_builtin_va_list ();
10014 :
10015 : /* Many back-ends define record types without setting TYPE_NAME.
10016 : If we copied the record type here, we'd keep the original
10017 : record type without a name. This breaks name mangling. So,
10018 : don't copy record types and let c_common_nodes_and_builtins()
10019 : declare the type to be __builtin_va_list. */
10020 294240 : if (TREE_CODE (t) != RECORD_TYPE)
10021 294240 : t = build_variant_type_copy (t);
10022 :
10023 294240 : va_list_type_node = t;
10024 : }
10025 :
10026 : /* SCEV analyzer global shared trees. */
10027 294240 : chrec_dont_know = make_node (SCEV_NOT_KNOWN);
10028 294240 : TREE_TYPE (chrec_dont_know) = void_type_node;
10029 294240 : chrec_known = make_node (SCEV_KNOWN);
10030 294240 : TREE_TYPE (chrec_known) = void_type_node;
10031 294240 : }
10032 :
10033 : /* Modify DECL for given flags.
10034 : TM_PURE attribute is set only on types, so the function will modify
10035 : DECL's type when ECF_TM_PURE is used. */
10036 :
10037 : void
10038 33167616 : set_call_expr_flags (tree decl, int flags)
10039 : {
10040 33167616 : if (flags & ECF_NOTHROW)
10041 28807853 : TREE_NOTHROW (decl) = 1;
10042 33167616 : if (flags & ECF_CONST)
10043 13601429 : TREE_READONLY (decl) = 1;
10044 33167616 : if (flags & ECF_PURE)
10045 1589275 : DECL_PURE_P (decl) = 1;
10046 33167616 : if (flags & ECF_LOOPING_CONST_OR_PURE)
10047 53901 : DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
10048 33167616 : if (flags & ECF_NOVOPS)
10049 0 : DECL_IS_NOVOPS (decl) = 1;
10050 33167616 : if (flags & ECF_NORETURN)
10051 1246782 : TREE_THIS_VOLATILE (decl) = 1;
10052 33167616 : if (flags & ECF_MALLOC)
10053 753594 : DECL_IS_MALLOC (decl) = 1;
10054 33167616 : if (flags & ECF_RETURNS_TWICE)
10055 0 : DECL_IS_RETURNS_TWICE (decl) = 1;
10056 33167616 : if (flags & ECF_LEAF)
10057 28621852 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("leaf"),
10058 28621852 : NULL, DECL_ATTRIBUTES (decl));
10059 33167616 : if (flags & ECF_COLD)
10060 654300 : DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("cold"),
10061 654300 : NULL, DECL_ATTRIBUTES (decl));
10062 33167616 : if (flags & ECF_RET1)
10063 0 : DECL_ATTRIBUTES (decl)
10064 0 : = tree_cons (get_identifier ("fn spec"),
10065 : build_tree_list (NULL_TREE, build_string (2, "1 ")),
10066 0 : DECL_ATTRIBUTES (decl));
10067 33167616 : if ((flags & ECF_TM_PURE) && flag_tm)
10068 537 : apply_tm_attr (decl, get_identifier ("transaction_pure"));
10069 33167616 : if ((flags & ECF_XTHROW))
10070 424934 : DECL_ATTRIBUTES (decl)
10071 849868 : = tree_cons (get_identifier ("expected_throw"),
10072 424934 : NULL, DECL_ATTRIBUTES (decl));
10073 :
10074 33167616 : if (flags & ECF_CB_1_2)
10075 : {
10076 389256 : tree attr = callback_build_attr (1, 1, 2);
10077 389256 : TREE_CHAIN (attr) = DECL_ATTRIBUTES (decl);
10078 389256 : DECL_ATTRIBUTES (decl) = attr;
10079 : }
10080 :
10081 : /* Looping const or pure is implied by noreturn.
10082 : There is currently no way to declare looping const or looping pure alone. */
10083 33167616 : gcc_assert (!(flags & ECF_LOOPING_CONST_OR_PURE)
10084 : || (flags & (ECF_CONST | ECF_PURE)));
10085 33167616 : }
10086 :
10087 :
10088 : /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
10089 :
10090 : static void
10091 9723508 : local_define_builtin (const char *name, tree type, enum built_in_function code,
10092 : const char *library_name, int ecf_flags)
10093 : {
10094 9723508 : tree decl;
10095 :
10096 9723508 : decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
10097 : library_name, NULL_TREE);
10098 9723508 : set_call_expr_flags (decl, ecf_flags);
10099 :
10100 9723508 : set_builtin_decl (code, decl, true);
10101 9723508 : }
10102 :
10103 : /* Call this function after instantiating all builtins that the language
10104 : front end cares about. This will build the rest of the builtins
10105 : and internal functions that are relied upon by the tree optimizers and
10106 : the middle-end. */
10107 :
10108 : void
10109 294223 : build_common_builtin_nodes (void)
10110 : {
10111 294223 : tree tmp, ftype;
10112 294223 : int ecf_flags;
10113 :
10114 294223 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_PADDING))
10115 : {
10116 59057 : ftype = build_function_type_list (void_type_node,
10117 : ptr_type_node,
10118 : ptr_type_node,
10119 : NULL_TREE);
10120 59057 : local_define_builtin ("__builtin_clear_padding", ftype,
10121 : BUILT_IN_CLEAR_PADDING,
10122 : "__builtin_clear_padding",
10123 : ECF_LEAF | ECF_NOTHROW);
10124 : }
10125 :
10126 294223 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE)
10127 244968 : || !builtin_decl_explicit_p (BUILT_IN_TRAP)
10128 244968 : || !builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP)
10129 240322 : || !builtin_decl_explicit_p (BUILT_IN_OBSERVABLE_CHKPT)
10130 534545 : || !builtin_decl_explicit_p (BUILT_IN_ABORT))
10131 : {
10132 53901 : ftype = build_function_type (void_type_node, void_list_node);
10133 53901 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE))
10134 49255 : local_define_builtin ("__builtin_unreachable", ftype,
10135 : BUILT_IN_UNREACHABLE,
10136 : "__builtin_unreachable",
10137 : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10138 : | ECF_CONST | ECF_COLD);
10139 53901 : if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE_TRAP))
10140 53901 : local_define_builtin ("__builtin_unreachable trap", ftype,
10141 : BUILT_IN_UNREACHABLE_TRAP,
10142 : "__builtin_unreachable trap",
10143 : ECF_NOTHROW | ECF_LEAF | ECF_NORETURN
10144 : | ECF_CONST | ECF_COLD);
10145 53901 : if (!builtin_decl_explicit_p (BUILT_IN_ABORT))
10146 53901 : local_define_builtin ("__builtin_abort", ftype, BUILT_IN_ABORT,
10147 : "abort",
10148 : ECF_LEAF | ECF_NORETURN | ECF_CONST | ECF_COLD);
10149 53901 : if (!builtin_decl_explicit_p (BUILT_IN_TRAP))
10150 16817 : local_define_builtin ("__builtin_trap", ftype, BUILT_IN_TRAP,
10151 : "__builtin_trap",
10152 : ECF_NORETURN | ECF_NOTHROW | ECF_LEAF | ECF_COLD);
10153 53901 : if (!builtin_decl_explicit_p (BUILT_IN_OBSERVABLE_CHKPT))
10154 53901 : local_define_builtin ("__builtin_observable_checkpoint", ftype,
10155 : BUILT_IN_OBSERVABLE_CHKPT,
10156 : "__builtin_observable_checkpoint",
10157 : ECF_NOTHROW | ECF_LEAF | ECF_CONST
10158 : | ECF_LOOPING_CONST_OR_PURE);
10159 : }
10160 :
10161 294223 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY)
10162 294223 : || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10163 : {
10164 53901 : ftype = build_function_type_list (ptr_type_node,
10165 : ptr_type_node, const_ptr_type_node,
10166 : size_type_node, NULL_TREE);
10167 :
10168 53901 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY))
10169 53901 : local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
10170 : "memcpy", ECF_NOTHROW | ECF_LEAF);
10171 53901 : if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE))
10172 49255 : local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
10173 : "memmove", ECF_NOTHROW | ECF_LEAF);
10174 : }
10175 :
10176 294223 : if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP))
10177 : {
10178 49255 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10179 : const_ptr_type_node, size_type_node,
10180 : NULL_TREE);
10181 49255 : local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
10182 : "memcmp", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10183 : }
10184 :
10185 294223 : if (!builtin_decl_explicit_p (BUILT_IN_MEMSET))
10186 : {
10187 49255 : ftype = build_function_type_list (ptr_type_node,
10188 : ptr_type_node, integer_type_node,
10189 : size_type_node, NULL_TREE);
10190 49255 : local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
10191 : "memset", ECF_NOTHROW | ECF_LEAF);
10192 : }
10193 :
10194 : /* If we're checking the stack, `alloca' can throw. */
10195 294156 : const int alloca_flags
10196 294223 : = ECF_MALLOC | ECF_LEAF | (flag_stack_check ? 0 : ECF_NOTHROW);
10197 :
10198 294223 : if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA))
10199 : {
10200 53901 : ftype = build_function_type_list (ptr_type_node,
10201 : size_type_node, NULL_TREE);
10202 53901 : local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
10203 : "alloca", alloca_flags);
10204 : }
10205 :
10206 294223 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10207 : size_type_node, NULL_TREE);
10208 294223 : local_define_builtin ("__builtin_alloca_with_align", ftype,
10209 : BUILT_IN_ALLOCA_WITH_ALIGN,
10210 : "__builtin_alloca_with_align",
10211 : alloca_flags);
10212 :
10213 294223 : ftype = build_function_type_list (ptr_type_node, size_type_node,
10214 : size_type_node, size_type_node, NULL_TREE);
10215 294223 : local_define_builtin ("__builtin_alloca_with_align_and_max", ftype,
10216 : BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX,
10217 : "__builtin_alloca_with_align_and_max",
10218 : alloca_flags);
10219 :
10220 294223 : ftype = build_function_type_list (void_type_node,
10221 : ptr_type_node, ptr_type_node,
10222 : ptr_type_node, NULL_TREE);
10223 294223 : local_define_builtin ("__builtin_init_trampoline", ftype,
10224 : BUILT_IN_INIT_TRAMPOLINE,
10225 : "__builtin_init_trampoline", ECF_NOTHROW | ECF_LEAF);
10226 294223 : local_define_builtin ("__builtin_init_heap_trampoline", ftype,
10227 : BUILT_IN_INIT_HEAP_TRAMPOLINE,
10228 : "__builtin_init_heap_trampoline",
10229 : ECF_NOTHROW | ECF_LEAF);
10230 294223 : local_define_builtin ("__builtin_init_descriptor", ftype,
10231 : BUILT_IN_INIT_DESCRIPTOR,
10232 : "__builtin_init_descriptor", ECF_NOTHROW | ECF_LEAF);
10233 :
10234 294223 : ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
10235 294223 : local_define_builtin ("__builtin_adjust_trampoline", ftype,
10236 : BUILT_IN_ADJUST_TRAMPOLINE,
10237 : "__builtin_adjust_trampoline",
10238 : ECF_CONST | ECF_NOTHROW);
10239 294223 : local_define_builtin ("__builtin_adjust_descriptor", ftype,
10240 : BUILT_IN_ADJUST_DESCRIPTOR,
10241 : "__builtin_adjust_descriptor",
10242 : ECF_CONST | ECF_NOTHROW);
10243 :
10244 294223 : ftype = build_function_type_list (void_type_node,
10245 : ptr_type_node, ptr_type_node, NULL_TREE);
10246 294223 : if (!builtin_decl_explicit_p (BUILT_IN_CLEAR_CACHE))
10247 53901 : local_define_builtin ("__builtin___clear_cache", ftype,
10248 : BUILT_IN_CLEAR_CACHE,
10249 : "__clear_cache",
10250 : ECF_NOTHROW);
10251 :
10252 294223 : local_define_builtin ("__builtin_nonlocal_goto", ftype,
10253 : BUILT_IN_NONLOCAL_GOTO,
10254 : "__builtin_nonlocal_goto",
10255 : ECF_NORETURN | ECF_NOTHROW);
10256 :
10257 294223 : tree ptr_ptr_type_node = build_pointer_type (ptr_type_node);
10258 :
10259 294223 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_CREATED))
10260 : {
10261 53901 : ftype = build_function_type_list (void_type_node,
10262 : ptr_type_node, // void *chain
10263 : ptr_type_node, // void *func
10264 : ptr_ptr_type_node, // void **dst
10265 : NULL_TREE);
10266 53901 : local_define_builtin ("__builtin___gcc_nested_func_ptr_created", ftype,
10267 : BUILT_IN_GCC_NESTED_PTR_CREATED,
10268 : "__gcc_nested_func_ptr_created", ECF_NOTHROW);
10269 : }
10270 :
10271 294223 : if (!builtin_decl_explicit_p (BUILT_IN_GCC_NESTED_PTR_DELETED))
10272 : {
10273 53901 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10274 53901 : local_define_builtin ("__builtin___gcc_nested_func_ptr_deleted", ftype,
10275 : BUILT_IN_GCC_NESTED_PTR_DELETED,
10276 : "__gcc_nested_func_ptr_deleted", ECF_NOTHROW);
10277 : }
10278 :
10279 294223 : ftype = build_function_type_list (void_type_node,
10280 : ptr_type_node, ptr_type_node, NULL_TREE);
10281 294223 : local_define_builtin ("__builtin_setjmp_setup", ftype,
10282 : BUILT_IN_SETJMP_SETUP,
10283 : "__builtin_setjmp_setup", ECF_NOTHROW);
10284 :
10285 294223 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10286 294223 : local_define_builtin ("__builtin_setjmp_receiver", ftype,
10287 : BUILT_IN_SETJMP_RECEIVER,
10288 : "__builtin_setjmp_receiver", ECF_NOTHROW | ECF_LEAF);
10289 :
10290 294223 : ftype = build_function_type_list (ptr_type_node, NULL_TREE);
10291 294223 : local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
10292 : "__builtin_stack_save", ECF_NOTHROW | ECF_LEAF);
10293 :
10294 294223 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10295 294223 : local_define_builtin ("__builtin_stack_restore", ftype,
10296 : BUILT_IN_STACK_RESTORE,
10297 : "__builtin_stack_restore", ECF_NOTHROW | ECF_LEAF);
10298 :
10299 294223 : ftype = build_function_type_list (integer_type_node, const_ptr_type_node,
10300 : const_ptr_type_node, size_type_node,
10301 : NULL_TREE);
10302 294223 : local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ,
10303 : "__builtin_memcmp_eq",
10304 : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10305 :
10306 294223 : local_define_builtin ("__builtin_strncmp_eq", ftype, BUILT_IN_STRNCMP_EQ,
10307 : "__builtin_strncmp_eq",
10308 : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10309 :
10310 294223 : local_define_builtin ("__builtin_strcmp_eq", ftype, BUILT_IN_STRCMP_EQ,
10311 : "__builtin_strcmp_eq",
10312 : ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10313 :
10314 : /* If there's a possibility that we might use the ARM EABI, build the
10315 : alternate __cxa_end_cleanup node used to resume from C++. */
10316 294223 : if (targetm.arm_eabi_unwinder)
10317 : {
10318 0 : ftype = build_function_type_list (void_type_node, NULL_TREE);
10319 0 : local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
10320 : BUILT_IN_CXA_END_CLEANUP,
10321 : "__cxa_end_cleanup",
10322 : ECF_NORETURN | ECF_XTHROW | ECF_LEAF);
10323 : }
10324 :
10325 294223 : ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
10326 588446 : local_define_builtin ("__builtin_unwind_resume", ftype,
10327 : BUILT_IN_UNWIND_RESUME,
10328 294223 : ((targetm_common.except_unwind_info (&global_options)
10329 : == UI_SJLJ)
10330 : ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
10331 : ECF_NORETURN | ECF_XTHROW);
10332 :
10333 294223 : if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS) == NULL_TREE)
10334 : {
10335 49255 : ftype = build_function_type_list (ptr_type_node, integer_type_node,
10336 : NULL_TREE);
10337 49255 : local_define_builtin ("__builtin_return_address", ftype,
10338 : BUILT_IN_RETURN_ADDRESS,
10339 : "__builtin_return_address",
10340 : ECF_NOTHROW);
10341 : }
10342 :
10343 294223 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER)
10344 294223 : || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10345 : {
10346 53901 : ftype = build_function_type_list (void_type_node, ptr_type_node,
10347 : ptr_type_node, NULL_TREE);
10348 53901 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER))
10349 53901 : local_define_builtin ("__cyg_profile_func_enter", ftype,
10350 : BUILT_IN_PROFILE_FUNC_ENTER,
10351 : "__cyg_profile_func_enter", 0);
10352 53901 : if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT))
10353 53901 : local_define_builtin ("__cyg_profile_func_exit", ftype,
10354 : BUILT_IN_PROFILE_FUNC_EXIT,
10355 : "__cyg_profile_func_exit", 0);
10356 : }
10357 :
10358 : /* The exception object and filter values from the runtime. The argument
10359 : must be zero before exception lowering, i.e. from the front end. After
10360 : exception lowering, it will be the region number for the exception
10361 : landing pad. These functions are PURE instead of CONST to prevent
10362 : them from being hoisted past the exception edge that will initialize
10363 : its value in the landing pad. */
10364 294223 : ftype = build_function_type_list (ptr_type_node,
10365 : integer_type_node, NULL_TREE);
10366 294223 : ecf_flags = ECF_PURE | ECF_NOTHROW | ECF_LEAF;
10367 : /* Only use TM_PURE if we have TM language support. */
10368 294223 : if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
10369 473 : ecf_flags |= ECF_TM_PURE;
10370 294223 : local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
10371 : "__builtin_eh_pointer", ecf_flags);
10372 :
10373 294223 : tmp = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
10374 294223 : ftype = build_function_type_list (tmp, integer_type_node, NULL_TREE);
10375 294223 : local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
10376 : "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10377 :
10378 294223 : ftype = build_function_type_list (void_type_node,
10379 : integer_type_node, integer_type_node,
10380 : NULL_TREE);
10381 294223 : local_define_builtin ("__builtin_eh_copy_values", ftype,
10382 : BUILT_IN_EH_COPY_VALUES,
10383 : "__builtin_eh_copy_values", ECF_NOTHROW);
10384 :
10385 : /* Complex multiplication and division. These are handled as builtins
10386 : rather than optabs because emit_library_call_value doesn't support
10387 : complex. Further, we can do slightly better with folding these
10388 : beasties if the real and complex parts of the arguments are separate. */
10389 294223 : {
10390 294223 : int mode;
10391 :
10392 2353784 : for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
10393 : {
10394 1765338 : char mode_name_buf[4], *q;
10395 1765338 : const char *p;
10396 1765338 : enum built_in_function mcode, dcode;
10397 1765338 : tree type, inner_type;
10398 1765338 : const char *prefix = "__";
10399 :
10400 1765338 : if (targetm.libfunc_gnu_prefix)
10401 0 : prefix = "__gnu_";
10402 :
10403 1765338 : type = lang_hooks.types.type_for_mode ((machine_mode) mode, 0);
10404 1765338 : if (type == NULL)
10405 129282 : continue;
10406 1636056 : inner_type = TREE_TYPE (type);
10407 :
10408 1636056 : ftype = build_function_type_list (type, inner_type, inner_type,
10409 : inner_type, inner_type, NULL_TREE);
10410 :
10411 1636056 : mcode = ((enum built_in_function)
10412 1636056 : (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10413 1636056 : dcode = ((enum built_in_function)
10414 1636056 : (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
10415 :
10416 4908168 : for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
10417 3272112 : *q = TOLOWER (*p);
10418 1636056 : *q = '\0';
10419 :
10420 : /* For -ftrapping-math these should throw from a former
10421 : -fnon-call-exception stmt. */
10422 1636056 : built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
10423 : NULL);
10424 1636056 : local_define_builtin (built_in_names[mcode], ftype, mcode,
10425 : built_in_names[mcode],
10426 : ECF_CONST | ECF_LEAF);
10427 :
10428 1636056 : built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
10429 : NULL);
10430 1636056 : local_define_builtin (built_in_names[dcode], ftype, dcode,
10431 : built_in_names[dcode],
10432 : ECF_CONST | ECF_LEAF);
10433 : }
10434 : }
10435 :
10436 294223 : init_internal_fns ();
10437 294223 : }
10438 :
10439 : /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10440 : better way.
10441 :
10442 : If we requested a pointer to a vector, build up the pointers that
10443 : we stripped off while looking for the inner type. Similarly for
10444 : return values from functions.
10445 :
10446 : The argument TYPE is the top of the chain, and BOTTOM is the
10447 : new type which we will point to. */
10448 :
10449 : tree
10450 0 : reconstruct_complex_type (tree type, tree bottom)
10451 : {
10452 0 : tree inner, outer;
10453 :
10454 0 : if (TREE_CODE (type) == POINTER_TYPE)
10455 : {
10456 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10457 0 : outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
10458 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10459 : }
10460 : else if (TREE_CODE (type) == REFERENCE_TYPE)
10461 : {
10462 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10463 0 : outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
10464 0 : TYPE_REF_CAN_ALIAS_ALL (type));
10465 : }
10466 : else if (TREE_CODE (type) == ARRAY_TYPE)
10467 : {
10468 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10469 0 : outer = build_array_type (inner, TYPE_DOMAIN (type));
10470 : }
10471 : else if (TREE_CODE (type) == FUNCTION_TYPE)
10472 : {
10473 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10474 0 : outer = build_function_type (inner, TYPE_ARG_TYPES (type),
10475 0 : TYPE_NO_NAMED_ARGS_STDARG_P (type));
10476 : }
10477 : else if (TREE_CODE (type) == METHOD_TYPE)
10478 : {
10479 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10480 : /* The build_method_type_directly() routine prepends 'this' to argument list,
10481 : so we must compensate by getting rid of it. */
10482 0 : outer
10483 : = build_method_type_directly
10484 0 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
10485 : inner,
10486 0 : TREE_CHAIN (TYPE_ARG_TYPES (type)));
10487 : }
10488 : else if (TREE_CODE (type) == OFFSET_TYPE)
10489 : {
10490 0 : inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
10491 0 : outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
10492 : }
10493 : else
10494 : return bottom;
10495 :
10496 0 : return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
10497 0 : TYPE_QUALS (type));
10498 : }
10499 :
10500 : /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10501 : the inner type. */
10502 : tree
10503 33826922 : build_vector_type_for_mode (tree innertype, machine_mode mode)
10504 : {
10505 33826922 : poly_int64 nunits;
10506 33826922 : unsigned int bitsize;
10507 :
10508 33826922 : switch (GET_MODE_CLASS (mode))
10509 : {
10510 33825532 : case MODE_VECTOR_BOOL:
10511 33825532 : case MODE_VECTOR_INT:
10512 33825532 : case MODE_VECTOR_FLOAT:
10513 33825532 : case MODE_VECTOR_FRACT:
10514 33825532 : case MODE_VECTOR_UFRACT:
10515 33825532 : case MODE_VECTOR_ACCUM:
10516 33825532 : case MODE_VECTOR_UACCUM:
10517 67651064 : nunits = GET_MODE_NUNITS (mode);
10518 33825532 : break;
10519 :
10520 1390 : case MODE_INT:
10521 : /* Check that there are no leftover bits. */
10522 1390 : bitsize = GET_MODE_BITSIZE (as_a <scalar_int_mode> (mode));
10523 1390 : gcc_assert (bitsize % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
10524 1390 : nunits = bitsize / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
10525 1390 : break;
10526 :
10527 0 : default:
10528 0 : gcc_unreachable ();
10529 : }
10530 :
10531 33826922 : return make_vector_type (innertype, nunits, mode);
10532 : }
10533 :
10534 : /* Similarly, but takes the inner type and number of units, which must be
10535 : a power of two. */
10536 :
10537 : tree
10538 2930730 : build_vector_type (tree innertype, poly_int64 nunits)
10539 : {
10540 2930730 : return make_vector_type (innertype, nunits, VOIDmode);
10541 : }
10542 :
10543 : /* Build a truth vector with NUNITS units, giving it mode MASK_MODE. */
10544 :
10545 : tree
10546 2759289 : build_truth_vector_type_for_mode (poly_uint64 nunits, machine_mode mask_mode)
10547 : {
10548 2759289 : gcc_assert (mask_mode != BLKmode);
10549 :
10550 2759289 : unsigned HOST_WIDE_INT esize;
10551 2759289 : if (VECTOR_MODE_P (mask_mode))
10552 : {
10553 2621348 : poly_uint64 vsize = GET_MODE_PRECISION (mask_mode);
10554 2621348 : esize = vector_element_size (vsize, nunits);
10555 2621348 : }
10556 : else
10557 : esize = 1;
10558 :
10559 2759289 : tree bool_type = build_nonstandard_boolean_type (esize);
10560 :
10561 2759289 : return make_vector_type (bool_type, nunits, mask_mode);
10562 : }
10563 :
10564 : /* Build a vector type that holds one boolean result for each element of
10565 : vector type VECTYPE. The public interface for this operation is
10566 : truth_type_for. */
10567 :
10568 : static tree
10569 2748090 : build_truth_vector_type_for (tree vectype)
10570 : {
10571 2748090 : machine_mode vector_mode = TYPE_MODE (vectype);
10572 2748090 : poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
10573 :
10574 2748090 : machine_mode mask_mode;
10575 104593 : if (VECTOR_MODE_P (vector_mode)
10576 2852062 : && targetm.vectorize.get_mask_mode (vector_mode).exists (&mask_mode))
10577 2747469 : return build_truth_vector_type_for_mode (nunits, mask_mode);
10578 :
10579 621 : poly_uint64 vsize = tree_to_poly_uint64 (TYPE_SIZE (vectype));
10580 621 : unsigned HOST_WIDE_INT esize = vector_element_size (vsize, nunits);
10581 621 : tree bool_type = build_nonstandard_boolean_type (esize);
10582 :
10583 621 : return make_vector_type (bool_type, nunits, VOIDmode);
10584 : }
10585 :
10586 : /* Like build_vector_type, but builds a variant type with TYPE_VECTOR_OPAQUE
10587 : set. */
10588 :
10589 : tree
10590 110338 : build_opaque_vector_type (tree innertype, poly_int64 nunits)
10591 : {
10592 110338 : tree t = make_vector_type (innertype, nunits, VOIDmode);
10593 110338 : tree cand;
10594 : /* We always build the non-opaque variant before the opaque one,
10595 : so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10596 110338 : cand = TYPE_NEXT_VARIANT (t);
10597 110338 : if (cand
10598 98608 : && TYPE_VECTOR_OPAQUE (cand)
10599 174140 : && check_qualified_type (cand, t, TYPE_QUALS (t)))
10600 : return cand;
10601 : /* Otherwise build a variant type and make sure to queue it after
10602 : the non-opaque type. */
10603 46537 : cand = build_distinct_type_copy (t);
10604 46537 : TYPE_VECTOR_OPAQUE (cand) = true;
10605 46537 : TYPE_CANONICAL (cand) = TYPE_CANONICAL (t);
10606 46537 : TYPE_NEXT_VARIANT (cand) = TYPE_NEXT_VARIANT (t);
10607 46537 : TYPE_NEXT_VARIANT (t) = cand;
10608 46537 : TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
10609 : /* Type variants have no alias set defined. */
10610 46537 : TYPE_ALIAS_SET (cand) = -1;
10611 46537 : return cand;
10612 : }
10613 :
10614 : /* Return the value of element I of VECTOR_CST T as a wide_int. */
10615 :
10616 : static poly_wide_int
10617 543991 : vector_cst_int_elt (const_tree t, unsigned int i)
10618 : {
10619 : /* First handle elements that are directly encoded. */
10620 543991 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10621 543991 : if (i < encoded_nelts)
10622 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, i));
10623 :
10624 : /* Identify the pattern that contains element I and work out the index of
10625 : the last encoded element for that pattern. */
10626 543991 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10627 543991 : unsigned int pattern = i % npatterns;
10628 543991 : unsigned int count = i / npatterns;
10629 543991 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10630 :
10631 : /* If there are no steps, the final encoded value is the right one. */
10632 543991 : if (!VECTOR_CST_STEPPED_P (t))
10633 0 : return wi::to_poly_wide (VECTOR_CST_ENCODED_ELT (t, final_i));
10634 :
10635 : /* Otherwise work out the value from the last two encoded elements. */
10636 543991 : tree v1 = VECTOR_CST_ENCODED_ELT (t, final_i - npatterns);
10637 543991 : tree v2 = VECTOR_CST_ENCODED_ELT (t, final_i);
10638 543991 : poly_wide_int diff = wi::to_poly_wide (v2) - wi::to_poly_wide (v1);
10639 543991 : return wi::to_poly_wide (v2) + (count - 2) * diff;
10640 543991 : }
10641 :
10642 : /* Return the value of element I of VECTOR_CST T. */
10643 :
10644 : tree
10645 8289442 : vector_cst_elt (const_tree t, unsigned int i)
10646 : {
10647 : /* First handle elements that are directly encoded. */
10648 8289442 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10649 8289442 : if (i < encoded_nelts)
10650 5342903 : return VECTOR_CST_ENCODED_ELT (t, i);
10651 :
10652 : /* If there are no steps, the final encoded value is the right one. */
10653 2946539 : if (!VECTOR_CST_STEPPED_P (t))
10654 : {
10655 : /* Identify the pattern that contains element I and work out the index of
10656 : the last encoded element for that pattern. */
10657 2402548 : unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10658 2402548 : unsigned int pattern = i % npatterns;
10659 2402548 : unsigned int final_i = encoded_nelts - npatterns + pattern;
10660 2402548 : return VECTOR_CST_ENCODED_ELT (t, final_i);
10661 : }
10662 :
10663 : /* Otherwise work out the value from the last two encoded elements. */
10664 543991 : return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t)),
10665 1087982 : vector_cst_int_elt (t, i));
10666 : }
10667 :
10668 : /* Given an initializer INIT, return TRUE if INIT is zero or some
10669 : aggregate of zeros. Otherwise return FALSE. If NONZERO is not
10670 : null, set *NONZERO if and only if INIT is known not to be all
10671 : zeros. The combination of return value of false and *NONZERO
10672 : false implies that INIT may but need not be all zeros. Other
10673 : combinations indicate definitive answers. */
10674 :
10675 : bool
10676 45224247 : initializer_zerop (const_tree init, bool *nonzero /* = NULL */)
10677 : {
10678 45224247 : bool dummy;
10679 45224247 : if (!nonzero)
10680 42435929 : nonzero = &dummy;
10681 :
10682 : /* Conservatively clear NONZERO and set it only if INIT is definitely
10683 : not all zero. */
10684 45224247 : *nonzero = false;
10685 :
10686 45224247 : STRIP_NOPS (init);
10687 :
10688 45224247 : unsigned HOST_WIDE_INT off = 0;
10689 :
10690 45224247 : switch (TREE_CODE (init))
10691 : {
10692 17383800 : case INTEGER_CST:
10693 17383800 : if (integer_zerop (init))
10694 : return true;
10695 :
10696 11039551 : *nonzero = true;
10697 11039551 : return false;
10698 :
10699 584412 : case REAL_CST:
10700 : /* ??? Note that this is not correct for C4X float formats. There,
10701 : a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10702 : negative exponent. */
10703 584412 : if (real_zerop (init)
10704 683968 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)))
10705 : return true;
10706 :
10707 488050 : *nonzero = true;
10708 488050 : return false;
10709 :
10710 0 : case FIXED_CST:
10711 0 : if (fixed_zerop (init))
10712 : return true;
10713 :
10714 0 : *nonzero = true;
10715 0 : return false;
10716 :
10717 18329 : case COMPLEX_CST:
10718 18329 : if (integer_zerop (init)
10719 18329 : || (real_zerop (init)
10720 3250 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
10721 3170 : && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))))
10722 : return true;
10723 :
10724 14977 : *nonzero = true;
10725 14977 : return false;
10726 :
10727 1190664 : case VECTOR_CST:
10728 1190664 : if (VECTOR_CST_NPATTERNS (init) == 1
10729 1095348 : && VECTOR_CST_DUPLICATE_P (init)
10730 1874318 : && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)))
10731 : return true;
10732 :
10733 834498 : *nonzero = true;
10734 834498 : return false;
10735 :
10736 : case RAW_DATA_CST:
10737 1959 : for (unsigned int i = 0; i < (unsigned int) RAW_DATA_LENGTH (init); ++i)
10738 1959 : if (RAW_DATA_POINTER (init)[i])
10739 : {
10740 1914 : *nonzero = true;
10741 1914 : return false;
10742 : }
10743 : return true;
10744 :
10745 4404050 : case CONSTRUCTOR:
10746 4404050 : {
10747 4404050 : if (TREE_CLOBBER_P (init))
10748 : return false;
10749 :
10750 : unsigned HOST_WIDE_INT idx;
10751 : tree elt;
10752 :
10753 3685238 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
10754 2788318 : if (!initializer_zerop (elt, nonzero))
10755 : return false;
10756 :
10757 : return true;
10758 : }
10759 :
10760 374418 : case MEM_REF:
10761 374418 : {
10762 374418 : tree arg = TREE_OPERAND (init, 0);
10763 374418 : if (TREE_CODE (arg) != ADDR_EXPR)
10764 : return false;
10765 93535 : tree offset = TREE_OPERAND (init, 1);
10766 93535 : if (TREE_CODE (offset) != INTEGER_CST
10767 93535 : || !tree_fits_uhwi_p (offset))
10768 : return false;
10769 93535 : off = tree_to_uhwi (offset);
10770 93535 : if (INT_MAX < off)
10771 : return false;
10772 93531 : arg = TREE_OPERAND (arg, 0);
10773 93531 : if (TREE_CODE (arg) != STRING_CST)
10774 : return false;
10775 : init = arg;
10776 : }
10777 : /* Fall through. */
10778 :
10779 : case STRING_CST:
10780 : {
10781 : gcc_assert (off <= INT_MAX);
10782 :
10783 165037 : int i = off;
10784 165037 : int n = TREE_STRING_LENGTH (init);
10785 165037 : if (n <= i)
10786 : return false;
10787 :
10788 : /* We need to loop through all elements to handle cases like
10789 : "\0" and "\0foobar". */
10790 176930 : for (i = 0; i < n; ++i)
10791 171604 : if (TREE_STRING_POINTER (init)[i] != '\0')
10792 : {
10793 159678 : *nonzero = true;
10794 159678 : return false;
10795 : }
10796 :
10797 : return true;
10798 : }
10799 :
10800 : default:
10801 : return false;
10802 : }
10803 : }
10804 :
10805 : /* Return true if EXPR is an initializer expression in which every element
10806 : is a constant that is numerically equal to 0 or 1. The elements do not
10807 : need to be equal to each other. */
10808 :
10809 : bool
10810 145025 : initializer_each_zero_or_onep (const_tree expr)
10811 : {
10812 145025 : STRIP_ANY_LOCATION_WRAPPER (expr);
10813 :
10814 145025 : switch (TREE_CODE (expr))
10815 : {
10816 53413 : case INTEGER_CST:
10817 53413 : return integer_zerop (expr) || integer_onep (expr);
10818 :
10819 24809 : case REAL_CST:
10820 24809 : return real_zerop (expr) || real_onep (expr);
10821 :
10822 66803 : case VECTOR_CST:
10823 66803 : {
10824 66803 : unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
10825 66803 : if (VECTOR_CST_STEPPED_P (expr)
10826 66803 : && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
10827 : return false;
10828 :
10829 80683 : for (unsigned int i = 0; i < nelts; ++i)
10830 : {
10831 78222 : tree elt = vector_cst_elt (expr, i);
10832 78222 : if (!initializer_each_zero_or_onep (elt))
10833 : return false;
10834 : }
10835 :
10836 : return true;
10837 : }
10838 :
10839 : default:
10840 : return false;
10841 : }
10842 : }
10843 :
10844 : /* Check if vector VEC consists of all the equal elements and
10845 : that the number of elements corresponds to the type of VEC.
10846 : The function returns first element of the vector
10847 : or NULL_TREE if the vector is not uniform. */
10848 : tree
10849 3333132 : uniform_vector_p (const_tree vec)
10850 : {
10851 3333132 : tree first, t;
10852 3333132 : unsigned HOST_WIDE_INT i, nelts;
10853 :
10854 3333132 : if (vec == NULL_TREE)
10855 : return NULL_TREE;
10856 :
10857 3333132 : gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
10858 :
10859 3333132 : if (TREE_CODE (vec) == VEC_DUPLICATE_EXPR)
10860 0 : return TREE_OPERAND (vec, 0);
10861 :
10862 3333132 : else if (TREE_CODE (vec) == VECTOR_CST)
10863 : {
10864 425255 : if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
10865 358686 : return VECTOR_CST_ENCODED_ELT (vec, 0);
10866 : return NULL_TREE;
10867 : }
10868 :
10869 2907877 : else if (TREE_CODE (vec) == CONSTRUCTOR
10870 2907877 : && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)).is_constant (&nelts))
10871 : {
10872 180448 : first = error_mark_node;
10873 :
10874 592084 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
10875 : {
10876 528500 : if (i == 0)
10877 : {
10878 180448 : first = t;
10879 180448 : continue;
10880 : }
10881 348052 : if (!operand_equal_p (first, t, 0))
10882 : return NULL_TREE;
10883 : }
10884 63584 : if (i != nelts)
10885 : return NULL_TREE;
10886 :
10887 63288 : if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
10888 0 : return uniform_vector_p (first);
10889 : return first;
10890 : }
10891 :
10892 : return NULL_TREE;
10893 : }
10894 :
10895 : /* If OP is a uniform vector return the element it is a splat from. */
10896 :
10897 : tree
10898 293253 : ssa_uniform_vector_p (tree op)
10899 : {
10900 293253 : if (TREE_CODE (op) == VECTOR_CST
10901 : || TREE_CODE (op) == VEC_DUPLICATE_EXPR
10902 : || TREE_CODE (op) == CONSTRUCTOR)
10903 12216 : return uniform_vector_p (op);
10904 : if (TREE_CODE (op) == SSA_NAME)
10905 : {
10906 281037 : gimple *def_stmt = SSA_NAME_DEF_STMT (op);
10907 281037 : if (gimple_assign_single_p (def_stmt))
10908 115468 : return uniform_vector_p (gimple_assign_rhs1 (def_stmt));
10909 : /* A VEC_DUPLICATE_EXPR is a unary assignment, so it is not covered
10910 : by the gimple_assign_single_p case above. */
10911 165569 : if (is_gimple_assign (def_stmt)
10912 165569 : && gimple_assign_rhs_code (def_stmt) == VEC_DUPLICATE_EXPR)
10913 0 : return gimple_assign_rhs1 (def_stmt);
10914 : }
10915 : return NULL_TREE;
10916 : }
10917 :
10918 : /* If the argument is INTEGER_CST, return it. If the argument is vector
10919 : with all elements the same INTEGER_CST, return that INTEGER_CST. Otherwise
10920 : return NULL_TREE.
10921 : Look through location wrappers. */
10922 :
10923 : tree
10924 892280969 : uniform_integer_cst_p (tree t)
10925 : {
10926 892280969 : STRIP_ANY_LOCATION_WRAPPER (t);
10927 :
10928 892280969 : if (TREE_CODE (t) == INTEGER_CST)
10929 : return t;
10930 :
10931 357269144 : if (VECTOR_TYPE_P (TREE_TYPE (t)))
10932 : {
10933 1417720 : t = uniform_vector_p (t);
10934 1417720 : if (t && TREE_CODE (t) == INTEGER_CST)
10935 301519 : return t;
10936 : }
10937 :
10938 : return NULL_TREE;
10939 : }
10940 :
10941 : /* Return true if ELT1 and ELT2 are INTEGER_CSTs and if ELT1 - ELT2 is
10942 : consistent with the uniform difference recorded in DIFF. */
10943 :
10944 : static bool
10945 307 : record_uniform_integer_difference (const_tree elt1, const_tree elt2,
10946 : widest_int *diff, bool *diff_p)
10947 : {
10948 307 : STRIP_ANY_LOCATION_WRAPPER (elt1);
10949 307 : STRIP_ANY_LOCATION_WRAPPER (elt2);
10950 :
10951 307 : if (TREE_CODE (elt1) != INTEGER_CST
10952 106 : || TREE_CODE (elt2) != INTEGER_CST)
10953 : return false;
10954 :
10955 106 : widest_int elt_diff = wi::to_widest (elt1) - wi::to_widest (elt2);
10956 106 : if (!*diff_p)
10957 : {
10958 106 : *diff = elt_diff;
10959 106 : *diff_p = true;
10960 106 : return true;
10961 : }
10962 :
10963 0 : return *diff == elt_diff;
10964 307 : }
10965 :
10966 : /* Return the uniform difference between two INTEGER_CSTs or corresponding
10967 : elements of two VECTOR_CSTs or NULL_TREE if no such difference exists. */
10968 :
10969 : tree
10970 307 : uniform_vector_difference_p (const_tree t1, const_tree t2)
10971 : {
10972 307 : STRIP_ANY_LOCATION_WRAPPER (t1);
10973 307 : STRIP_ANY_LOCATION_WRAPPER (t2);
10974 :
10975 307 : if (TREE_CODE (t1) == INTEGER_CST
10976 0 : && TREE_CODE (t2) == INTEGER_CST)
10977 : {
10978 0 : widest_int diff = wi::to_widest (t1) - wi::to_widest (t2);
10979 0 : if (!wi::fits_shwi_p (diff))
10980 : return NULL_TREE;
10981 0 : return build_int_cst (long_long_integer_type_node, diff.to_shwi ());
10982 0 : }
10983 :
10984 307 : if (TREE_CODE (t1) != VECTOR_CST
10985 307 : || TREE_CODE (t2) != VECTOR_CST
10986 614 : || !known_eq (VECTOR_CST_NELTS (t1), VECTOR_CST_NELTS (t2)))
10987 : return NULL_TREE;
10988 :
10989 307 : widest_int diff;
10990 307 : bool diff_p = false;
10991 :
10992 307 : if (VECTOR_CST_LOG2_NPATTERNS (t1) == VECTOR_CST_LOG2_NPATTERNS (t2)
10993 307 : && (VECTOR_CST_NELTS_PER_PATTERN (t1)
10994 307 : == VECTOR_CST_NELTS_PER_PATTERN (t2)))
10995 : {
10996 307 : unsigned int encoded_nelts = vector_cst_encoded_nelts (t1);
10997 307 : gcc_assert (encoded_nelts == vector_cst_encoded_nelts (t2));
10998 :
10999 413 : for (unsigned int i = 0; i < encoded_nelts; ++i)
11000 614 : if (!record_uniform_integer_difference (VECTOR_CST_ENCODED_ELT (t1, i),
11001 307 : VECTOR_CST_ENCODED_ELT (t2, i),
11002 : &diff, &diff_p))
11003 : return NULL_TREE;
11004 : }
11005 : else
11006 : {
11007 0 : unsigned HOST_WIDE_INT nelts;
11008 0 : if (!VECTOR_CST_NELTS (t1).is_constant (&nelts))
11009 307 : return NULL_TREE;
11010 :
11011 0 : for (unsigned HOST_WIDE_INT i = 0; i < nelts; ++i)
11012 0 : if (!record_uniform_integer_difference (vector_cst_elt (t1, i),
11013 0 : vector_cst_elt (t2, i),
11014 : &diff, &diff_p))
11015 : return NULL_TREE;
11016 : }
11017 :
11018 106 : if (!diff_p || !wi::fits_shwi_p (diff))
11019 : return NULL_TREE;
11020 :
11021 106 : return build_int_cst (long_long_integer_type_node, diff.to_shwi ());
11022 307 : }
11023 :
11024 : /* Checks to see if T is a constant or a constant vector and if each element E
11025 : adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE. */
11026 :
11027 : tree
11028 3077212 : bitmask_inv_cst_vector_p (tree t)
11029 : {
11030 :
11031 3077212 : tree_code code = TREE_CODE (t);
11032 3077212 : tree type = TREE_TYPE (t);
11033 :
11034 3077212 : if (!INTEGRAL_TYPE_P (type)
11035 3077212 : && !VECTOR_INTEGER_TYPE_P (type))
11036 : return NULL_TREE;
11037 :
11038 3077184 : unsigned HOST_WIDE_INT nelts = 1;
11039 3077184 : tree cst;
11040 3077184 : unsigned int idx = 0;
11041 3077184 : bool uniform = uniform_integer_cst_p (t);
11042 3077184 : tree newtype = unsigned_type_for (type);
11043 3077184 : tree_vector_builder builder;
11044 3077184 : if (code == INTEGER_CST)
11045 : cst = t;
11046 : else
11047 : {
11048 17835 : if (!VECTOR_CST_NELTS (t).is_constant (&nelts))
11049 : return NULL_TREE;
11050 :
11051 17835 : cst = vector_cst_elt (t, 0);
11052 17835 : builder.new_vector (newtype, nelts, 1);
11053 : }
11054 :
11055 3077184 : tree ty = unsigned_type_for (TREE_TYPE (cst));
11056 :
11057 3077196 : do
11058 : {
11059 3077196 : if (idx > 0)
11060 12 : cst = vector_cst_elt (t, idx);
11061 3077196 : wide_int icst = wi::to_wide (cst);
11062 3077196 : wide_int inv = wi::bit_not (icst);
11063 3077196 : icst = wi::add (1, inv);
11064 3077196 : if (wi::popcount (icst) != 1)
11065 : return NULL_TREE;
11066 :
11067 15979 : tree newcst = wide_int_to_tree (ty, inv);
11068 :
11069 15979 : if (uniform)
11070 15963 : return build_uniform_cst (newtype, newcst);
11071 :
11072 16 : builder.quick_push (newcst);
11073 3077196 : }
11074 16 : while (++idx < nelts);
11075 :
11076 4 : return builder.build ();
11077 3077184 : }
11078 :
11079 : /* If VECTOR_CST T has a single nonzero element, return the index of that
11080 : element, otherwise return -1. */
11081 :
11082 : int
11083 177 : single_nonzero_element (const_tree t)
11084 : {
11085 177 : unsigned HOST_WIDE_INT nelts;
11086 177 : unsigned int repeat_nelts;
11087 177 : if (VECTOR_CST_NELTS (t).is_constant (&nelts))
11088 177 : repeat_nelts = nelts;
11089 : else if (VECTOR_CST_NELTS_PER_PATTERN (t) == 2)
11090 : {
11091 : nelts = vector_cst_encoded_nelts (t);
11092 : repeat_nelts = VECTOR_CST_NPATTERNS (t);
11093 : }
11094 : else
11095 : return -1;
11096 :
11097 177 : int res = -1;
11098 561 : for (unsigned int i = 0; i < nelts; ++i)
11099 : {
11100 528 : tree elt = vector_cst_elt (t, i);
11101 528 : if (!integer_zerop (elt) && !real_zerop (elt))
11102 : {
11103 321 : if (res >= 0 || i >= repeat_nelts)
11104 : return -1;
11105 177 : res = i;
11106 : }
11107 : }
11108 : return res;
11109 : }
11110 :
11111 : /* Build an empty statement at location LOC. */
11112 :
11113 : tree
11114 16278107 : build_empty_stmt (location_t loc)
11115 : {
11116 16278107 : tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
11117 16278107 : SET_EXPR_LOCATION (t, loc);
11118 16278107 : return t;
11119 : }
11120 :
11121 :
11122 : /* Build an OMP clause with code CODE. LOC is the location of the
11123 : clause. */
11124 :
11125 : tree
11126 1782315 : build_omp_clause (location_t loc, enum omp_clause_code code)
11127 : {
11128 1782315 : tree t;
11129 1782315 : int size, length;
11130 :
11131 1782315 : length = omp_clause_num_ops[code];
11132 1782315 : size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
11133 :
11134 1782315 : record_node_allocation_statistics (OMP_CLAUSE, size);
11135 :
11136 1782315 : t = (tree) ggc_internal_alloc (size);
11137 1782315 : memset (t, 0, size);
11138 1782315 : TREE_SET_CODE (t, OMP_CLAUSE);
11139 1782315 : OMP_CLAUSE_SET_CODE (t, code);
11140 1782315 : OMP_CLAUSE_LOCATION (t) = loc;
11141 :
11142 1782315 : return t;
11143 : }
11144 :
11145 : /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
11146 : includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
11147 : Except for the CODE and operand count field, other storage for the
11148 : object is initialized to zeros. */
11149 :
11150 : tree
11151 553390127 : build_vl_exp (enum tree_code code, int len MEM_STAT_DECL)
11152 : {
11153 553390127 : tree t;
11154 553390127 : int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
11155 :
11156 553390127 : gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
11157 553390127 : gcc_assert (len >= 1);
11158 :
11159 553390127 : record_node_allocation_statistics (code, length);
11160 :
11161 553390127 : t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
11162 :
11163 553390127 : TREE_SET_CODE (t, code);
11164 :
11165 : /* Can't use TREE_OPERAND to store the length because if checking is
11166 : enabled, it will try to check the length before we store it. :-P */
11167 553390127 : t->exp.operands[0] = build_int_cst (sizetype, len);
11168 :
11169 553390127 : return t;
11170 : }
11171 :
11172 : /* Helper function for build_call_* functions; build a CALL_EXPR with
11173 : indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
11174 : the argument slots. */
11175 :
11176 : static tree
11177 296745354 : build_call_1 (tree return_type, tree fn, int nargs)
11178 : {
11179 296745354 : tree t;
11180 :
11181 296745354 : t = build_vl_exp (CALL_EXPR, nargs + 3);
11182 296745354 : TREE_TYPE (t) = return_type;
11183 296745354 : CALL_EXPR_FN (t) = fn;
11184 296745354 : CALL_EXPR_STATIC_CHAIN (t) = NULL;
11185 :
11186 296745354 : return t;
11187 : }
11188 :
11189 : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11190 : FN and a null static chain slot. NARGS is the number of call arguments
11191 : which are specified as a va_list ARGS. */
11192 :
11193 : tree
11194 136167 : build_call_valist (tree return_type, tree fn, int nargs, va_list args)
11195 : {
11196 136167 : tree t;
11197 136167 : int i;
11198 :
11199 136167 : t = build_call_1 (return_type, fn, nargs);
11200 552528 : for (i = 0; i < nargs; i++)
11201 280194 : CALL_EXPR_ARG (t, i) = va_arg (args, tree);
11202 136167 : process_call_operands (t);
11203 136167 : return t;
11204 : }
11205 :
11206 : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11207 : FN and a null static chain slot. ARGS specifies the call arguments. */
11208 :
11209 : tree
11210 272 : build_call (tree return_type, tree fn, std::initializer_list<tree> args)
11211 : {
11212 272 : tree t;
11213 272 : int i;
11214 272 : int nargs = args.size();
11215 :
11216 272 : t = build_call_1 (return_type, fn, nargs);
11217 1036 : for (i = 0; i < nargs; i++)
11218 492 : CALL_EXPR_ARG (t, i) = args.begin()[i];
11219 272 : process_call_operands (t);
11220 272 : return t;
11221 : }
11222 :
11223 : /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
11224 : FN and a null static chain slot. NARGS is the number of call arguments
11225 : which are specified as a tree array ARGS. */
11226 :
11227 : tree
11228 248417574 : build_call_array_loc (location_t loc, tree return_type, tree fn,
11229 : int nargs, const tree *args)
11230 : {
11231 248417574 : tree t;
11232 248417574 : int i;
11233 :
11234 248417574 : t = build_call_1 (return_type, fn, nargs);
11235 831030596 : for (i = 0; i < nargs; i++)
11236 334195448 : CALL_EXPR_ARG (t, i) = args[i];
11237 248417574 : process_call_operands (t);
11238 248417574 : SET_EXPR_LOCATION (t, loc);
11239 248417574 : return t;
11240 : }
11241 :
11242 : /* Like build_call_array, but takes a vec. */
11243 :
11244 : tree
11245 47373007 : build_call_vec (tree return_type, tree fn, const vec<tree, va_gc> *args)
11246 : {
11247 47373007 : tree ret, t;
11248 47373007 : unsigned int ix;
11249 :
11250 47373007 : ret = build_call_1 (return_type, fn, vec_safe_length (args));
11251 130543817 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
11252 35797803 : CALL_EXPR_ARG (ret, ix) = t;
11253 47373007 : process_call_operands (ret);
11254 47373007 : return ret;
11255 : }
11256 :
11257 : /* Conveniently construct a function call expression. FNDECL names the
11258 : function to be called and N arguments are passed in the array
11259 : ARGARRAY. */
11260 :
11261 : tree
11262 24301264 : build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray)
11263 : {
11264 24301264 : tree fntype = TREE_TYPE (fndecl);
11265 24301264 : tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
11266 :
11267 24301264 : return fold_build_call_array_loc (loc, TREE_TYPE (fntype), fn, n, argarray);
11268 : }
11269 :
11270 : /* Conveniently construct a function call expression. FNDECL names the
11271 : function to be called and the arguments are passed in the vector
11272 : VEC. */
11273 :
11274 : tree
11275 20908 : build_call_expr_loc_vec (location_t loc, tree fndecl, vec<tree, va_gc> *vec)
11276 : {
11277 20908 : return build_call_expr_loc_array (loc, fndecl, vec_safe_length (vec),
11278 20908 : vec_safe_address (vec));
11279 : }
11280 :
11281 :
11282 : /* Conveniently construct a function call expression. FNDECL names the
11283 : function to be called, N is the number of arguments, and the "..."
11284 : parameters are the argument expressions. */
11285 :
11286 : tree
11287 22194478 : build_call_expr_loc (location_t loc, tree fndecl, int n, ...)
11288 : {
11289 22194478 : va_list ap;
11290 22194478 : tree *argarray = XALLOCAVEC (tree, n);
11291 22194478 : int i;
11292 :
11293 22194478 : va_start (ap, n);
11294 25127241 : for (i = 0; i < n; i++)
11295 2932763 : argarray[i] = va_arg (ap, tree);
11296 22194478 : va_end (ap);
11297 22194478 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11298 : }
11299 :
11300 : /* Like build_call_expr_loc (UNKNOWN_LOCATION, ...). Duplicated because
11301 : varargs macros aren't supported by all bootstrap compilers. */
11302 :
11303 : tree
11304 2081383 : build_call_expr (tree fndecl, int n, ...)
11305 : {
11306 2081383 : va_list ap;
11307 2081383 : tree *argarray = XALLOCAVEC (tree, n);
11308 2081383 : int i;
11309 :
11310 2081383 : va_start (ap, n);
11311 6240299 : for (i = 0; i < n; i++)
11312 4158916 : argarray[i] = va_arg (ap, tree);
11313 2081383 : va_end (ap);
11314 2081383 : return build_call_expr_loc_array (UNKNOWN_LOCATION, fndecl, n, argarray);
11315 : }
11316 :
11317 : /* Build an internal call to IFN, with arguments ARGS[0:N-1] and with return
11318 : type TYPE. This is just like CALL_EXPR, except its CALL_EXPR_FN is NULL.
11319 : It will get gimplified later into an ordinary internal function. */
11320 :
11321 : tree
11322 818334 : build_call_expr_internal_loc_array (location_t loc, internal_fn ifn,
11323 : tree type, int n, const tree *args)
11324 : {
11325 818334 : tree t = build_call_1 (type, NULL_TREE, n);
11326 3403820 : for (int i = 0; i < n; ++i)
11327 1767152 : CALL_EXPR_ARG (t, i) = args[i];
11328 818334 : SET_EXPR_LOCATION (t, loc);
11329 818334 : CALL_EXPR_IFN (t) = ifn;
11330 818334 : process_call_operands (t);
11331 818334 : return t;
11332 : }
11333 :
11334 : /* Build internal call expression. This is just like CALL_EXPR, except
11335 : its CALL_EXPR_FN is NULL. It will get gimplified later into ordinary
11336 : internal function. */
11337 :
11338 : tree
11339 817159 : build_call_expr_internal_loc (location_t loc, enum internal_fn ifn,
11340 : tree type, int n, ...)
11341 : {
11342 817159 : va_list ap;
11343 817159 : tree *argarray = XALLOCAVEC (tree, n);
11344 817159 : int i;
11345 :
11346 817159 : va_start (ap, n);
11347 2581947 : for (i = 0; i < n; i++)
11348 1764788 : argarray[i] = va_arg (ap, tree);
11349 817159 : va_end (ap);
11350 817159 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11351 : }
11352 :
11353 : /* Return a function call to FN, if the target is guaranteed to support it,
11354 : or null otherwise.
11355 :
11356 : N is the number of arguments, passed in the "...", and TYPE is the
11357 : type of the return value. */
11358 :
11359 : tree
11360 1968 : maybe_build_call_expr_loc (location_t loc, combined_fn fn, tree type,
11361 : int n, ...)
11362 : {
11363 1968 : va_list ap;
11364 1968 : tree *argarray = XALLOCAVEC (tree, n);
11365 1968 : int i;
11366 :
11367 1968 : va_start (ap, n);
11368 5165 : for (i = 0; i < n; i++)
11369 3197 : argarray[i] = va_arg (ap, tree);
11370 1968 : va_end (ap);
11371 1968 : if (internal_fn_p (fn))
11372 : {
11373 1160 : internal_fn ifn = as_internal_fn (fn);
11374 1160 : if (direct_internal_fn_p (ifn))
11375 : {
11376 3 : tree_pair types = direct_internal_fn_types (ifn, type, argarray);
11377 3 : if (!direct_internal_fn_supported_p (ifn, types,
11378 : OPTIMIZE_FOR_BOTH))
11379 1 : return NULL_TREE;
11380 : }
11381 1159 : return build_call_expr_internal_loc_array (loc, ifn, type, n, argarray);
11382 : }
11383 : else
11384 : {
11385 808 : tree fndecl = builtin_decl_implicit (as_builtin_fn (fn));
11386 808 : if (!fndecl)
11387 : return NULL_TREE;
11388 700 : return build_call_expr_loc_array (loc, fndecl, n, argarray);
11389 : }
11390 : }
11391 :
11392 : /* Return a function call to the appropriate builtin alloca variant.
11393 :
11394 : SIZE is the size to be allocated. ALIGN, if non-zero, is the requested
11395 : alignment of the allocated area. MAX_SIZE, if non-negative, is an upper
11396 : bound for SIZE in case it is not a fixed value. */
11397 :
11398 : tree
11399 9029 : build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size)
11400 : {
11401 9029 : if (max_size >= 0)
11402 : {
11403 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX);
11404 0 : return
11405 0 : build_call_expr (t, 3, size, size_int (align), size_int (max_size));
11406 : }
11407 9029 : else if (align > 0)
11408 : {
11409 9029 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
11410 9029 : return build_call_expr (t, 2, size, size_int (align));
11411 : }
11412 : else
11413 : {
11414 0 : tree t = builtin_decl_explicit (BUILT_IN_ALLOCA);
11415 0 : return build_call_expr (t, 1, size);
11416 : }
11417 : }
11418 :
11419 : /* The built-in decl to use to mark code points believed to be unreachable.
11420 : Typically __builtin_unreachable, but __builtin_trap if
11421 : -fsanitize=unreachable -fsanitize-trap=unreachable. If only
11422 : -fsanitize=unreachable, we rely on sanopt to replace calls with the
11423 : appropriate ubsan function. When building a call directly, use
11424 : {gimple_},build_builtin_unreachable instead. */
11425 :
11426 : tree
11427 365834 : builtin_decl_unreachable ()
11428 : {
11429 365834 : enum built_in_function fncode = BUILT_IN_UNREACHABLE;
11430 :
11431 731668 : if (sanitize_flags_p (SANITIZE_UNREACHABLE)
11432 365834 : ? (flag_sanitize_trap & SANITIZE_UNREACHABLE)
11433 365236 : : flag_unreachable_traps)
11434 22 : fncode = BUILT_IN_UNREACHABLE_TRAP;
11435 : /* For non-trapping sanitize, we will rewrite __builtin_unreachable () later,
11436 : in the sanopt pass. */
11437 :
11438 365834 : return builtin_decl_explicit (fncode);
11439 : }
11440 :
11441 : /* Build a call to __builtin_unreachable, possibly rewritten by
11442 : -fsanitize=unreachable. Use this rather than the above when practical. */
11443 :
11444 : tree
11445 20670299 : build_builtin_unreachable (location_t loc)
11446 : {
11447 20670299 : tree data = NULL_TREE;
11448 20670299 : tree fn = sanitize_unreachable_fn (&data, loc);
11449 20670299 : return build_call_expr_loc (loc, fn, data != NULL_TREE, data);
11450 : }
11451 :
11452 : /* Create a new constant string literal of type ELTYPE[SIZE] (or LEN
11453 : if SIZE == -1) and return a tree node representing char* pointer to
11454 : it as an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). When STR is nonnull
11455 : the STRING_CST value is the LEN bytes at STR (the representation
11456 : of the string, which may be wide). Otherwise it's all zeros. */
11457 :
11458 : tree
11459 268700 : build_string_literal (unsigned len, const char *str /* = NULL */,
11460 : tree eltype /* = char_type_node */,
11461 : unsigned HOST_WIDE_INT size /* = -1 */)
11462 : {
11463 268700 : tree t = build_string (len, str);
11464 : /* Set the maximum valid index based on the string length or SIZE. */
11465 537400 : unsigned HOST_WIDE_INT maxidx
11466 268700 : = (size == HOST_WIDE_INT_M1U ? len : size) - 1;
11467 :
11468 268700 : tree index = build_index_type (size_int (maxidx));
11469 268700 : eltype = build_type_variant (eltype, 1, 0);
11470 268700 : tree type = build_array_type (eltype, index);
11471 268700 : TREE_TYPE (t) = type;
11472 268700 : TREE_CONSTANT (t) = 1;
11473 268700 : TREE_READONLY (t) = 1;
11474 268700 : TREE_STATIC (t) = 1;
11475 :
11476 268700 : type = build_pointer_type (eltype);
11477 268700 : t = build1 (ADDR_EXPR, type,
11478 : build4 (ARRAY_REF, eltype,
11479 : t, integer_zero_node, NULL_TREE, NULL_TREE));
11480 268700 : return t;
11481 : }
11482 :
11483 :
11484 :
11485 : /* Return true if T (assumed to be a DECL) must be assigned a memory
11486 : location. */
11487 :
11488 : bool
11489 2027778814 : needs_to_live_in_memory (const_tree t)
11490 : {
11491 2027778814 : return (TREE_ADDRESSABLE (t)
11492 1648589479 : || is_global_var (t)
11493 3223249886 : || (TREE_CODE (t) == RESULT_DECL
11494 8492362 : && !DECL_BY_REFERENCE (t)
11495 5894618 : && aggregate_value_p (t, current_function_decl)));
11496 : }
11497 :
11498 : /* Return value of a constant X and sign-extend it. */
11499 :
11500 : HOST_WIDE_INT
11501 783443181 : int_cst_value (const_tree x)
11502 : {
11503 783443181 : unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
11504 783443181 : unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
11505 :
11506 : /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
11507 783443181 : gcc_assert (cst_and_fits_in_hwi (x));
11508 :
11509 783443181 : if (bits < HOST_BITS_PER_WIDE_INT)
11510 : {
11511 768591182 : bool negative = ((val >> (bits - 1)) & 1) != 0;
11512 768591182 : if (negative)
11513 210666 : val |= HOST_WIDE_INT_M1U << (bits - 1) << 1;
11514 : else
11515 768380516 : val &= ~(HOST_WIDE_INT_M1U << (bits - 1) << 1);
11516 : }
11517 :
11518 783443181 : return val;
11519 : }
11520 :
11521 : /* If TYPE is an integral or pointer type, return an integer type with
11522 : the same precision which is unsigned iff UNSIGNEDP is true, or itself
11523 : if TYPE is already an integer type of signedness UNSIGNEDP.
11524 : If TYPE is a floating-point type, return an integer type with the same
11525 : bitsize and with the signedness given by UNSIGNEDP; this is useful
11526 : when doing bit-level operations on a floating-point value. */
11527 :
11528 : tree
11529 89839256 : signed_or_unsigned_type_for (int unsignedp, tree type)
11530 : {
11531 89839256 : if (ANY_INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) == unsignedp)
11532 : return type;
11533 :
11534 57549438 : if (TREE_CODE (type) == VECTOR_TYPE)
11535 : {
11536 27492 : tree inner = TREE_TYPE (type);
11537 27492 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11538 27492 : if (!inner2)
11539 : return NULL_TREE;
11540 27492 : if (inner == inner2)
11541 : return type;
11542 27492 : machine_mode new_mode;
11543 54984 : if (VECTOR_MODE_P (TYPE_MODE (type))
11544 54900 : && related_int_vector_mode (TYPE_MODE (type)).exists (&new_mode))
11545 27408 : return build_vector_type_for_mode (inner2, new_mode);
11546 84 : return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
11547 : }
11548 :
11549 : if (TREE_CODE (type) == COMPLEX_TYPE)
11550 : {
11551 24 : tree inner = TREE_TYPE (type);
11552 24 : tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11553 24 : if (!inner2)
11554 : return NULL_TREE;
11555 24 : if (inner == inner2)
11556 : return type;
11557 24 : return build_complex_type (inner2);
11558 : }
11559 :
11560 : unsigned int bits;
11561 : if (INTEGRAL_TYPE_P (type)
11562 : || POINTER_TYPE_P (type)
11563 : || TREE_CODE (type) == OFFSET_TYPE)
11564 57521828 : bits = TYPE_PRECISION (type);
11565 : else if (TREE_CODE (type) == REAL_TYPE)
11566 188 : bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (type));
11567 : else
11568 : return NULL_TREE;
11569 :
11570 57521922 : if (TREE_CODE (type) == BITINT_TYPE)
11571 2676 : return build_bitint_type (bits, unsignedp);
11572 57519246 : return build_nonstandard_integer_type (bits, unsignedp);
11573 : }
11574 :
11575 : /* If TYPE is an integral or pointer type, return an integer type with
11576 : the same precision which is unsigned, or itself if TYPE is already an
11577 : unsigned integer type. If TYPE is a floating-point type, return an
11578 : unsigned integer type with the same bitsize as TYPE. */
11579 :
11580 : tree
11581 79652580 : unsigned_type_for (tree type)
11582 : {
11583 79652580 : return signed_or_unsigned_type_for (1, type);
11584 : }
11585 :
11586 : /* If TYPE is an integral or pointer type, return an integer type with
11587 : the same precision which is signed, or itself if TYPE is already a
11588 : signed integer type. If TYPE is a floating-point type, return a
11589 : signed integer type with the same bitsize as TYPE. */
11590 :
11591 : tree
11592 9985229 : signed_type_for (tree type)
11593 : {
11594 9985229 : return signed_or_unsigned_type_for (0, type);
11595 : }
11596 :
11597 : /* - For VECTOR_TYPEs:
11598 : - The truth type must be a VECTOR_BOOLEAN_TYPE.
11599 : - The number of elements must match (known_eq).
11600 : - targetm.vectorize.get_mask_mode exists, and exactly
11601 : the same mode as the truth type.
11602 : - Otherwise, the truth type must be a BOOLEAN_TYPE
11603 : or useless_type_conversion_p to BOOLEAN_TYPE. */
11604 : bool
11605 1374 : is_truth_type_for (tree type, tree truth_type)
11606 : {
11607 1374 : machine_mode mask_mode = TYPE_MODE (truth_type);
11608 1374 : machine_mode vmode = TYPE_MODE (type);
11609 1374 : machine_mode tmask_mode;
11610 :
11611 1374 : if (TREE_CODE (type) == VECTOR_TYPE)
11612 : {
11613 1374 : if (VECTOR_BOOLEAN_TYPE_P (truth_type)
11614 1374 : && known_eq (TYPE_VECTOR_SUBPARTS (type),
11615 : TYPE_VECTOR_SUBPARTS (truth_type))
11616 1374 : && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode)
11617 2748 : && tmask_mode == mask_mode)
11618 1355 : return true;
11619 :
11620 19 : return false;
11621 : }
11622 :
11623 0 : return useless_type_conversion_p (boolean_type_node, truth_type);
11624 : }
11625 :
11626 : /* If TYPE is a vector type, return a signed integer vector type with the
11627 : same width and number of subparts. Otherwise return boolean_type_node. */
11628 :
11629 : tree
11630 3930616 : truth_type_for (tree type)
11631 : {
11632 3930616 : if (TREE_CODE (type) == VECTOR_TYPE)
11633 : {
11634 2807081 : if (VECTOR_BOOLEAN_TYPE_P (type))
11635 : return type;
11636 2748090 : return build_truth_vector_type_for (type);
11637 : }
11638 : else
11639 1123535 : return boolean_type_node;
11640 : }
11641 :
11642 : /* Returns the largest value obtainable by casting something in INNER type to
11643 : OUTER type. */
11644 :
11645 : tree
11646 11119530 : upper_bound_in_type (tree outer, tree inner)
11647 : {
11648 11119530 : unsigned int det = 0;
11649 11119530 : unsigned oprec = TYPE_PRECISION (outer);
11650 11119530 : unsigned iprec = TYPE_PRECISION (inner);
11651 11119530 : unsigned prec;
11652 :
11653 : /* Compute a unique number for every combination. */
11654 11119530 : det |= (oprec > iprec) ? 4 : 0;
11655 11119530 : det |= TYPE_UNSIGNED (outer) ? 2 : 0;
11656 11119530 : det |= TYPE_UNSIGNED (inner) ? 1 : 0;
11657 :
11658 : /* Determine the exponent to use. */
11659 11119530 : switch (det)
11660 : {
11661 7450526 : case 0:
11662 7450526 : case 1:
11663 : /* oprec <= iprec, outer: signed, inner: don't care. */
11664 7450526 : prec = oprec - 1;
11665 7450526 : break;
11666 : case 2:
11667 : case 3:
11668 : /* oprec <= iprec, outer: unsigned, inner: don't care. */
11669 : prec = oprec;
11670 : break;
11671 22348 : case 4:
11672 : /* oprec > iprec, outer: signed, inner: signed. */
11673 22348 : prec = iprec - 1;
11674 22348 : break;
11675 : case 5:
11676 : /* oprec > iprec, outer: signed, inner: unsigned. */
11677 9445 : prec = iprec;
11678 : break;
11679 : case 6:
11680 : /* oprec > iprec, outer: unsigned, inner: signed. */
11681 : prec = oprec;
11682 : break;
11683 : case 7:
11684 : /* oprec > iprec, outer: unsigned, inner: unsigned. */
11685 9445 : prec = iprec;
11686 : break;
11687 : default:
11688 : gcc_unreachable ();
11689 : }
11690 :
11691 11119530 : return wide_int_to_tree (outer,
11692 11119530 : wi::mask (prec, false, TYPE_PRECISION (outer)));
11693 : }
11694 :
11695 : /* Returns the smallest value obtainable by casting something in INNER type to
11696 : OUTER type. */
11697 :
11698 : tree
11699 8507253 : lower_bound_in_type (tree outer, tree inner)
11700 : {
11701 8507253 : unsigned oprec = TYPE_PRECISION (outer);
11702 8507253 : unsigned iprec = TYPE_PRECISION (inner);
11703 :
11704 : /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
11705 : and obtain 0. */
11706 8507253 : if (TYPE_UNSIGNED (outer)
11707 : /* If we are widening something of an unsigned type, OUTER type
11708 : contains all values of INNER type. In particular, both INNER
11709 : and OUTER types have zero in common. */
11710 8507253 : || (oprec > iprec && TYPE_UNSIGNED (inner)))
11711 2271327 : return build_int_cst (outer, 0);
11712 : else
11713 : {
11714 : /* If we are widening a signed type to another signed type, we
11715 : want to obtain -2^^(iprec-1). If we are keeping the
11716 : precision or narrowing to a signed type, we want to obtain
11717 : -2^(oprec-1). */
11718 6235926 : unsigned prec = oprec > iprec ? iprec : oprec;
11719 6235926 : return wide_int_to_tree (outer,
11720 12471852 : wi::mask (prec - 1, true,
11721 6235926 : TYPE_PRECISION (outer)));
11722 : }
11723 : }
11724 :
11725 : /* Return true if two operands that are suitable for PHI nodes are
11726 : necessarily equal. Specifically, both ARG0 and ARG1 must be either
11727 : SSA_NAME or invariant. Note that this is strictly an optimization.
11728 : That is, callers of this function can directly call operand_equal_p
11729 : and get the same result, only slower. */
11730 :
11731 : bool
11732 22278377 : operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
11733 : {
11734 22278377 : if (arg0 == arg1)
11735 : return true;
11736 20485087 : if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
11737 : return false;
11738 4413573 : return operand_equal_p (arg0, arg1, 0);
11739 : }
11740 :
11741 : /* Returns number of zeros at the end of binary representation of X. */
11742 :
11743 : tree
11744 9348827 : num_ending_zeros (const_tree x)
11745 : {
11746 9348827 : return build_int_cst (TREE_TYPE (x), wi::ctz (wi::to_wide (x)));
11747 : }
11748 :
11749 :
11750 : #define WALK_SUBTREE(NODE) \
11751 : do \
11752 : { \
11753 : result = walk_tree_1 (&(NODE), func, data, pset, lh); \
11754 : if (result) \
11755 : return result; \
11756 : } \
11757 : while (0)
11758 :
11759 : /* This is a subroutine of walk_tree that walks field of TYPE that are to
11760 : be walked whenever a type is seen in the tree. Rest of operands and return
11761 : value are as for walk_tree. */
11762 :
11763 : static tree
11764 5284446906 : walk_type_fields (tree type, walk_tree_fn func, void *data,
11765 : hash_set<tree> *pset, walk_tree_lh lh)
11766 : {
11767 5284446906 : tree result = NULL_TREE;
11768 :
11769 5284446906 : switch (TREE_CODE (type))
11770 : {
11771 1537449225 : case POINTER_TYPE:
11772 1537449225 : case REFERENCE_TYPE:
11773 1537449225 : case VECTOR_TYPE:
11774 : /* We have to worry about mutually recursive pointers. These can't
11775 : be written in C. They can in Ada. It's pathological, but
11776 : there's an ACATS test (c38102a) that checks it. Deal with this
11777 : by checking if we're pointing to another pointer, that one
11778 : points to another pointer, that one does too, and we have no htab.
11779 : If so, get a hash table. We check three levels deep to avoid
11780 : the cost of the hash table if we don't need one. */
11781 3024299258 : if (POINTER_TYPE_P (TREE_TYPE (type))
11782 50599261 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
11783 7329922 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
11784 1544677507 : && !pset)
11785 : {
11786 0 : result = walk_tree_without_duplicates (&TREE_TYPE (type),
11787 : func, data);
11788 0 : if (result)
11789 : return result;
11790 :
11791 : break;
11792 : }
11793 :
11794 : /* fall through */
11795 :
11796 1540430476 : case COMPLEX_TYPE:
11797 1540430476 : WALK_SUBTREE (TREE_TYPE (type));
11798 : break;
11799 :
11800 268937898 : case METHOD_TYPE:
11801 268937898 : WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
11802 :
11803 : /* Fall through. */
11804 :
11805 439294090 : case FUNCTION_TYPE:
11806 439294090 : WALK_SUBTREE (TREE_TYPE (type));
11807 439294048 : {
11808 439294048 : tree arg;
11809 :
11810 : /* We never want to walk into default arguments. */
11811 1684421190 : for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
11812 1245156007 : WALK_SUBTREE (TREE_VALUE (arg));
11813 : }
11814 : break;
11815 :
11816 17204841 : case ARRAY_TYPE:
11817 : /* Don't follow this nodes's type if a pointer for fear that
11818 : we'll have infinite recursion. If we have a PSET, then we
11819 : need not fear. */
11820 17204841 : if (pset
11821 17204841 : || (!POINTER_TYPE_P (TREE_TYPE (type))
11822 162492 : && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
11823 17183907 : WALK_SUBTREE (TREE_TYPE (type));
11824 17202218 : WALK_SUBTREE (TYPE_DOMAIN (type));
11825 : break;
11826 :
11827 1143416 : case OFFSET_TYPE:
11828 1143416 : WALK_SUBTREE (TREE_TYPE (type));
11829 1142530 : WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
11830 : break;
11831 :
11832 : default:
11833 : break;
11834 : }
11835 :
11836 : return NULL_TREE;
11837 : }
11838 :
11839 : /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
11840 : called with the DATA and the address of each sub-tree. If FUNC returns a
11841 : non-NULL value, the traversal is stopped, and the value returned by FUNC
11842 : is returned. If PSET is non-NULL it is used to record the nodes visited,
11843 : and to avoid visiting a node more than once. */
11844 :
11845 : tree
11846 >11276*10^7 : walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
11847 : hash_set<tree> *pset, walk_tree_lh lh)
11848 : {
11849 : #define WALK_SUBTREE_TAIL(NODE) \
11850 : do \
11851 : { \
11852 : tp = & (NODE); \
11853 : goto tail_recurse; \
11854 : } \
11855 : while (0)
11856 :
11857 26393299078 : tail_recurse:
11858 : /* Skip empty subtrees. */
11859 >13915*10^7 : if (!*tp)
11860 : return NULL_TREE;
11861 :
11862 : /* Don't walk the same tree twice, if the user has requested
11863 : that we avoid doing so. */
11864 >11503*10^7 : if (pset && pset->add (*tp))
11865 : return NULL_TREE;
11866 :
11867 : /* Call the function. */
11868 >11324*10^7 : int walk_subtrees = 1;
11869 >11324*10^7 : tree result = (*func) (tp, &walk_subtrees, data);
11870 :
11871 : /* If we found something, return it. */
11872 >11324*10^7 : if (result)
11873 : return result;
11874 :
11875 >11316*10^7 : tree t = *tp;
11876 >11316*10^7 : tree_code code = TREE_CODE (t);
11877 :
11878 : /* Even if we didn't, FUNC may have decided that there was nothing
11879 : interesting below this point in the tree. */
11880 >11316*10^7 : if (!walk_subtrees)
11881 : {
11882 : /* But we still need to check our siblings. */
11883 69457293812 : if (code == TREE_LIST)
11884 118191 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11885 69457175621 : else if (code == OMP_CLAUSE)
11886 890549 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11887 : else
11888 : return NULL_TREE;
11889 : }
11890 :
11891 43708210097 : if (lh)
11892 : {
11893 25660541600 : result = (*lh) (tp, &walk_subtrees, func, data, pset);
11894 25660541600 : if (result || !walk_subtrees)
11895 : return result;
11896 : }
11897 :
11898 40739765889 : switch (code)
11899 : {
11900 : case ERROR_MARK:
11901 : case IDENTIFIER_NODE:
11902 : case INTEGER_CST:
11903 : case REAL_CST:
11904 : case FIXED_CST:
11905 : case STRING_CST:
11906 : case BLOCK:
11907 : case PLACEHOLDER_EXPR:
11908 : case SSA_NAME:
11909 : case FIELD_DECL:
11910 : case RESULT_DECL:
11911 : /* None of these have subtrees other than those already walked
11912 : above. */
11913 : break;
11914 :
11915 290560865 : case TREE_LIST:
11916 290560865 : WALK_SUBTREE (TREE_VALUE (t));
11917 290066296 : WALK_SUBTREE_TAIL (TREE_CHAIN (t));
11918 :
11919 1359689185 : case TREE_VEC:
11920 1359689185 : {
11921 1359689185 : int len = TREE_VEC_LENGTH (t);
11922 :
11923 1359689185 : if (len == 0)
11924 : break;
11925 :
11926 : /* Walk all elements but the last. */
11927 2495619735 : for (int i = 0; i < len - 1; ++i)
11928 1145799578 : WALK_SUBTREE (TREE_VEC_ELT (t, i));
11929 :
11930 : /* Now walk the last one as a tail call. */
11931 1349820157 : WALK_SUBTREE_TAIL (TREE_VEC_ELT (t, len - 1));
11932 : }
11933 :
11934 5607827 : case VECTOR_CST:
11935 5607827 : {
11936 5607827 : unsigned len = vector_cst_encoded_nelts (t);
11937 5607827 : if (len == 0)
11938 : break;
11939 : /* Walk all elements but the last. */
11940 18472040 : for (unsigned i = 0; i < len - 1; ++i)
11941 12864381 : WALK_SUBTREE (VECTOR_CST_ENCODED_ELT (t, i));
11942 : /* Now walk the last one as a tail call. */
11943 5607659 : WALK_SUBTREE_TAIL (VECTOR_CST_ENCODED_ELT (t, len - 1));
11944 : }
11945 :
11946 641132 : case COMPLEX_CST:
11947 641132 : WALK_SUBTREE (TREE_REALPART (t));
11948 639566 : WALK_SUBTREE_TAIL (TREE_IMAGPART (t));
11949 :
11950 : case CONSTRUCTOR:
11951 : {
11952 : unsigned HOST_WIDE_INT idx;
11953 : constructor_elt *ce;
11954 :
11955 981394645 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce);
11956 : idx++)
11957 503381010 : WALK_SUBTREE (ce->value);
11958 : }
11959 : break;
11960 :
11961 4862778 : case SAVE_EXPR:
11962 4862778 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, 0));
11963 :
11964 273712774 : case BIND_EXPR:
11965 273712774 : {
11966 273712774 : tree decl;
11967 441787398 : for (decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl))
11968 : {
11969 : /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
11970 : into declarations that are just mentioned, rather than
11971 : declared; they don't really belong to this part of the tree.
11972 : And, we can see cycles: the initializer for a declaration
11973 : can refer to the declaration itself. */
11974 168074648 : WALK_SUBTREE (DECL_INITIAL (decl));
11975 168074624 : WALK_SUBTREE (DECL_SIZE (decl));
11976 168074624 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
11977 : }
11978 273712750 : WALK_SUBTREE_TAIL (BIND_EXPR_BODY (t));
11979 : }
11980 :
11981 368095043 : case STATEMENT_LIST:
11982 368095043 : {
11983 368095043 : tree_stmt_iterator i;
11984 1324765811 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
11985 956865608 : WALK_SUBTREE (*tsi_stmt_ptr (i));
11986 : }
11987 367900203 : break;
11988 :
11989 1844907 : case OMP_CLAUSE:
11990 1844907 : {
11991 1844907 : int len = omp_clause_num_ops[OMP_CLAUSE_CODE (t)];
11992 : /* Do not walk the iterator operand of OpenMP MAP clauses. */
11993 1844907 : if (OMP_CLAUSE_HAS_ITERATORS (t))
11994 1638 : len--;
11995 5268615 : for (int i = 0; i < len; i++)
11996 3423708 : WALK_SUBTREE (OMP_CLAUSE_OPERAND (t, i));
11997 1844907 : WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (t));
11998 : }
11999 :
12000 82275267 : case TARGET_EXPR:
12001 82275267 : {
12002 82275267 : int i, len;
12003 :
12004 : /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
12005 : But, we only want to walk once. */
12006 82275267 : len = (TREE_OPERAND (t, 3) == TREE_OPERAND (t, 1)) ? 2 : 3;
12007 329065731 : for (i = 0; i < len; ++i)
12008 246808081 : WALK_SUBTREE (TREE_OPERAND (t, i));
12009 82257650 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len));
12010 : }
12011 :
12012 164836255 : case DECL_EXPR:
12013 : /* If this is a TYPE_DECL, walk into the fields of the type that it's
12014 : defining. We only want to walk into these fields of a type in this
12015 : case and not in the general case of a mere reference to the type.
12016 :
12017 : The criterion is as follows: if the field can be an expression, it
12018 : must be walked only here. This should be in keeping with the fields
12019 : that are directly gimplified in gimplify_type_sizes in order for the
12020 : mark/copy-if-shared/unmark machinery of the gimplifier to work with
12021 : variable-sized types.
12022 :
12023 : Note that DECLs get walked as part of processing the BIND_EXPR. */
12024 164836255 : if (TREE_CODE (DECL_EXPR_DECL (t)) == TYPE_DECL)
12025 : {
12026 : /* Call the function for the decl so e.g. copy_tree_body_r can
12027 : replace it with the remapped one. */
12028 1791036 : result = (*func) (&DECL_EXPR_DECL (t), &walk_subtrees, data);
12029 1791036 : if (result || !walk_subtrees)
12030 : return result;
12031 :
12032 1745552 : tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (t));
12033 1745552 : if (TREE_CODE (*type_p) == ERROR_MARK)
12034 : return NULL_TREE;
12035 :
12036 : /* Call the function for the type. See if it returns anything or
12037 : doesn't want us to continue. If we are to continue, walk both
12038 : the normal fields and those for the declaration case. */
12039 1745552 : result = (*func) (type_p, &walk_subtrees, data);
12040 1745552 : if (result || !walk_subtrees)
12041 : return result;
12042 :
12043 1650470 : tree type = *type_p;
12044 :
12045 : /* But do not walk a pointed-to type since it may itself need to
12046 : be walked in the declaration case if it isn't anonymous. */
12047 1650470 : if (!POINTER_TYPE_P (type))
12048 : {
12049 1634763 : result = walk_type_fields (type, func, data, pset, lh);
12050 1634763 : if (result)
12051 : return result;
12052 : }
12053 :
12054 : /* If this is a record type, also walk the fields. */
12055 1650470 : if (RECORD_OR_UNION_TYPE_P (type))
12056 : {
12057 506852 : tree field;
12058 :
12059 2387026 : for (field = TYPE_FIELDS (type); field;
12060 1880174 : field = DECL_CHAIN (field))
12061 : {
12062 : /* We'd like to look at the type of the field, but we can
12063 : easily get infinite recursion. So assume it's pointed
12064 : to elsewhere in the tree. Also, ignore things that
12065 : aren't fields. */
12066 1880174 : if (TREE_CODE (field) != FIELD_DECL)
12067 1404963 : continue;
12068 :
12069 475211 : WALK_SUBTREE (DECL_FIELD_OFFSET (field));
12070 475211 : WALK_SUBTREE (DECL_SIZE (field));
12071 475211 : WALK_SUBTREE (DECL_SIZE_UNIT (field));
12072 475211 : if (TREE_CODE (type) == QUAL_UNION_TYPE)
12073 0 : WALK_SUBTREE (DECL_QUALIFIER (field));
12074 : }
12075 : }
12076 :
12077 : /* Same for scalar types. */
12078 : else if (TREE_CODE (type) == BOOLEAN_TYPE
12079 : || TREE_CODE (type) == ENUMERAL_TYPE
12080 : || TREE_CODE (type) == INTEGER_TYPE
12081 : || TREE_CODE (type) == FIXED_POINT_TYPE
12082 : || TREE_CODE (type) == REAL_TYPE)
12083 : {
12084 38353 : WALK_SUBTREE (TYPE_MIN_VALUE (type));
12085 38353 : WALK_SUBTREE (TYPE_MAX_VALUE (type));
12086 : }
12087 :
12088 1650470 : WALK_SUBTREE (TYPE_SIZE (type));
12089 1650470 : WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (type));
12090 : }
12091 : /* FALLTHRU */
12092 :
12093 33182027007 : default:
12094 33182027007 : if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
12095 : {
12096 24657674398 : int i, len;
12097 :
12098 : /* Walk over all the sub-trees of this operand. */
12099 24657674398 : len = TREE_OPERAND_LENGTH (t);
12100 :
12101 : /* Go through the subtrees. We need to do this in forward order so
12102 : that the scope of a FOR_EXPR is handled properly. */
12103 24657674398 : if (len)
12104 : {
12105 49389217245 : for (i = 0; i < len - 1; ++i)
12106 25007389140 : WALK_SUBTREE (TREE_OPERAND (t, i));
12107 24381828105 : WALK_SUBTREE_TAIL (TREE_OPERAND (t, len - 1));
12108 : }
12109 : }
12110 : /* If this is a type, walk the needed fields in the type. */
12111 8524352609 : else if (TYPE_P (t))
12112 5282812143 : return walk_type_fields (t, func, data, pset, lh);
12113 : break;
12114 : }
12115 :
12116 : /* We didn't find what we were looking for. */
12117 : return NULL_TREE;
12118 :
12119 : #undef WALK_SUBTREE_TAIL
12120 : }
12121 : #undef WALK_SUBTREE
12122 :
12123 : /* Like walk_tree, but does not walk duplicate nodes more than once. */
12124 :
12125 : tree
12126 3945312572 : walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
12127 : walk_tree_lh lh)
12128 : {
12129 3945312572 : tree result;
12130 :
12131 3945312572 : hash_set<tree> pset;
12132 3945312572 : result = walk_tree_1 (tp, func, data, &pset, lh);
12133 3945312572 : return result;
12134 3945312572 : }
12135 :
12136 :
12137 : tree
12138 1215129315 : tree_block (tree t)
12139 : {
12140 1215129315 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
12141 :
12142 1215129315 : if (IS_EXPR_CODE_CLASS (c))
12143 1215129315 : return LOCATION_BLOCK (t->exp.locus);
12144 0 : gcc_unreachable ();
12145 : return NULL;
12146 : }
12147 :
12148 : void
12149 759317726 : tree_set_block (tree t, tree b)
12150 : {
12151 759317726 : const enum tree_code_class c = TREE_CODE_CLASS (TREE_CODE (t));
12152 :
12153 759317726 : if (IS_EXPR_CODE_CLASS (c))
12154 : {
12155 759317726 : t->exp.locus = set_block (t->exp.locus, b);
12156 : }
12157 : else
12158 0 : gcc_unreachable ();
12159 759317726 : }
12160 :
12161 : /* Create a nameless artificial label and put it in the current
12162 : function context. The label has a location of LOC. Returns the
12163 : newly created label. */
12164 :
12165 : tree
12166 33373943 : create_artificial_label (location_t loc)
12167 : {
12168 33373943 : tree lab = build_decl (loc,
12169 : LABEL_DECL, NULL_TREE, void_type_node);
12170 :
12171 33373943 : DECL_ARTIFICIAL (lab) = 1;
12172 33373943 : DECL_IGNORED_P (lab) = 1;
12173 33373943 : DECL_CONTEXT (lab) = current_function_decl;
12174 33373943 : return lab;
12175 : }
12176 :
12177 : /* Given a tree, try to return a useful variable name that we can use
12178 : to prefix a temporary that is being assigned the value of the tree.
12179 : I.E. given <temp> = &A, return A. */
12180 :
12181 : const char *
12182 25524805 : get_name (tree t)
12183 : {
12184 27435467 : tree stripped_decl;
12185 :
12186 27435467 : stripped_decl = t;
12187 27435467 : STRIP_NOPS (stripped_decl);
12188 27435467 : if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
12189 4082511 : return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
12190 23352956 : else if (TREE_CODE (stripped_decl) == SSA_NAME)
12191 : {
12192 1382179 : tree name = SSA_NAME_IDENTIFIER (stripped_decl);
12193 326309 : if (!name)
12194 : return NULL;
12195 325053 : return IDENTIFIER_POINTER (name);
12196 : }
12197 : else
12198 : {
12199 21970777 : switch (TREE_CODE (stripped_decl))
12200 : {
12201 1910662 : case ADDR_EXPR:
12202 1910662 : return get_name (TREE_OPERAND (stripped_decl, 0));
12203 : default:
12204 : return NULL;
12205 : }
12206 : }
12207 : }
12208 :
12209 : /* Return true if TYPE has a variable argument list. */
12210 :
12211 : bool
12212 239882035 : stdarg_p (const_tree fntype)
12213 : {
12214 239882035 : function_args_iterator args_iter;
12215 239882035 : tree n = NULL_TREE, t;
12216 :
12217 239882035 : if (!fntype)
12218 : return false;
12219 :
12220 239744646 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12221 : return true;
12222 :
12223 971360751 : FOREACH_FUNCTION_ARGS (fntype, t, args_iter)
12224 : {
12225 732377492 : n = t;
12226 : }
12227 :
12228 238983259 : return n != NULL_TREE && n != void_type_node;
12229 : }
12230 :
12231 : /* Return true if TYPE has a prototype. */
12232 :
12233 : bool
12234 733157565 : prototype_p (const_tree fntype)
12235 : {
12236 733157565 : tree t;
12237 :
12238 733157565 : gcc_assert (fntype != NULL_TREE);
12239 :
12240 733157565 : if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
12241 : return true;
12242 :
12243 732294263 : t = TYPE_ARG_TYPES (fntype);
12244 732294263 : return (t != NULL_TREE);
12245 : }
12246 :
12247 : /* If BLOCK is inlined from an __attribute__((__artificial__))
12248 : routine, return pointer to location from where it has been
12249 : called. */
12250 : location_t *
12251 175281 : block_nonartificial_location (tree block)
12252 : {
12253 175281 : location_t *ret = NULL;
12254 :
12255 450124 : while (block && TREE_CODE (block) == BLOCK
12256 544525 : && BLOCK_ABSTRACT_ORIGIN (block))
12257 : {
12258 172099 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12259 172099 : if (TREE_CODE (ao) == FUNCTION_DECL)
12260 : {
12261 : /* If AO is an artificial inline, point RET to the
12262 : call site locus at which it has been inlined and continue
12263 : the loop, in case AO's caller is also an artificial
12264 : inline. */
12265 74292 : if (DECL_DECLARED_INLINE_P (ao)
12266 74292 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
12267 1801 : ret = &BLOCK_SOURCE_LOCATION (block);
12268 : else
12269 : break;
12270 : }
12271 97807 : else if (TREE_CODE (ao) != BLOCK)
12272 : break;
12273 :
12274 99608 : block = BLOCK_SUPERCONTEXT (block);
12275 : }
12276 175281 : return ret;
12277 : }
12278 :
12279 :
12280 : /* If EXP is inlined from an __attribute__((__artificial__))
12281 : function, return the location of the original call expression. */
12282 :
12283 : location_t
12284 46 : tree_nonartificial_location (tree exp)
12285 : {
12286 46 : location_t *loc = block_nonartificial_location (TREE_BLOCK (exp));
12287 :
12288 46 : if (loc)
12289 0 : return *loc;
12290 : else
12291 46 : return EXPR_LOCATION (exp);
12292 : }
12293 :
12294 : /* Return the location into which EXP has been inlined. Analogous
12295 : to tree_nonartificial_location() above but not limited to artificial
12296 : functions declared inline. If SYSTEM_HEADER is true, return
12297 : the macro expansion point of the location if it's in a system header */
12298 :
12299 : location_t
12300 0 : tree_inlined_location (tree exp, bool system_header /* = true */)
12301 : {
12302 0 : location_t loc = UNKNOWN_LOCATION;
12303 :
12304 0 : tree block = TREE_BLOCK (exp);
12305 :
12306 0 : while (block && TREE_CODE (block) == BLOCK
12307 0 : && BLOCK_ABSTRACT_ORIGIN (block))
12308 : {
12309 0 : tree ao = BLOCK_ABSTRACT_ORIGIN (block);
12310 0 : if (TREE_CODE (ao) == FUNCTION_DECL)
12311 0 : loc = BLOCK_SOURCE_LOCATION (block);
12312 0 : else if (TREE_CODE (ao) != BLOCK)
12313 : break;
12314 :
12315 0 : block = BLOCK_SUPERCONTEXT (block);
12316 : }
12317 :
12318 0 : if (loc == UNKNOWN_LOCATION)
12319 : {
12320 0 : loc = EXPR_LOCATION (exp);
12321 0 : if (system_header)
12322 : /* Only consider macro expansion when the block traversal failed
12323 : to find a location. Otherwise it's not relevant. */
12324 0 : return expansion_point_location_if_in_system_header (loc);
12325 : }
12326 :
12327 : return loc;
12328 : }
12329 :
12330 : /* These are the hash table functions for the hash table of OPTIMIZATION_NODE
12331 : nodes. */
12332 :
12333 : /* Return the hash code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
12334 :
12335 : hashval_t
12336 982598839 : cl_option_hasher::hash (tree x)
12337 : {
12338 982598839 : const_tree const t = x;
12339 :
12340 982598839 : if (TREE_CODE (t) == OPTIMIZATION_NODE)
12341 102166713 : return cl_optimization_hash (TREE_OPTIMIZATION (t));
12342 880432126 : else if (TREE_CODE (t) == TARGET_OPTION_NODE)
12343 880432126 : return cl_target_option_hash (TREE_TARGET_OPTION (t));
12344 : else
12345 0 : gcc_unreachable ();
12346 : }
12347 :
12348 : /* Return nonzero if the value represented by *X (an OPTIMIZATION or
12349 : TARGET_OPTION tree node) is the same as that given by *Y, which is the
12350 : same. */
12351 :
12352 : bool
12353 1032797725 : cl_option_hasher::equal (tree x, tree y)
12354 : {
12355 1032797725 : const_tree const xt = x;
12356 1032797725 : const_tree const yt = y;
12357 :
12358 1032797725 : if (TREE_CODE (xt) != TREE_CODE (yt))
12359 : return false;
12360 :
12361 575574336 : if (TREE_CODE (xt) == OPTIMIZATION_NODE)
12362 101262787 : return cl_optimization_option_eq (TREE_OPTIMIZATION (xt),
12363 101262787 : TREE_OPTIMIZATION (yt));
12364 474311549 : else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
12365 474311549 : return cl_target_option_eq (TREE_TARGET_OPTION (xt),
12366 474311549 : TREE_TARGET_OPTION (yt));
12367 : else
12368 0 : gcc_unreachable ();
12369 : }
12370 :
12371 : /* Build an OPTIMIZATION_NODE based on the options in OPTS and OPTS_SET. */
12372 :
12373 : tree
12374 101549755 : build_optimization_node (struct gcc_options *opts,
12375 : struct gcc_options *opts_set)
12376 : {
12377 101549755 : tree t;
12378 :
12379 : /* Use the cache of optimization nodes. */
12380 :
12381 101549755 : cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node),
12382 : opts, opts_set);
12383 :
12384 101549755 : tree *slot = cl_option_hash_table->find_slot (cl_optimization_node, INSERT);
12385 101549755 : t = *slot;
12386 101549755 : if (!t)
12387 : {
12388 : /* Insert this one into the hash table. */
12389 296813 : t = cl_optimization_node;
12390 296813 : *slot = t;
12391 :
12392 : /* Make a new node for next time round. */
12393 296813 : cl_optimization_node = make_node (OPTIMIZATION_NODE);
12394 : }
12395 :
12396 101549755 : return t;
12397 : }
12398 :
12399 : /* Build a TARGET_OPTION_NODE based on the options in OPTS and OPTS_SET. */
12400 :
12401 : tree
12402 78608831 : build_target_option_node (struct gcc_options *opts,
12403 : struct gcc_options *opts_set)
12404 : {
12405 78608831 : tree t;
12406 :
12407 : /* Use the cache of optimization nodes. */
12408 :
12409 78608831 : cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node),
12410 : opts, opts_set);
12411 :
12412 78608831 : tree *slot = cl_option_hash_table->find_slot (cl_target_option_node, INSERT);
12413 78608831 : t = *slot;
12414 78608831 : if (!t)
12415 : {
12416 : /* Insert this one into the hash table. */
12417 788443 : t = cl_target_option_node;
12418 788443 : *slot = t;
12419 :
12420 : /* Make a new node for next time round. */
12421 788443 : cl_target_option_node = make_node (TARGET_OPTION_NODE);
12422 : }
12423 :
12424 78608831 : return t;
12425 : }
12426 :
12427 : /* Clear TREE_TARGET_GLOBALS of all TARGET_OPTION_NODE trees,
12428 : so that they aren't saved during PCH writing. */
12429 :
12430 : void
12431 429 : prepare_target_option_nodes_for_pch (void)
12432 : {
12433 429 : hash_table<cl_option_hasher>::iterator iter = cl_option_hash_table->begin ();
12434 1716 : for (; iter != cl_option_hash_table->end (); ++iter)
12435 858 : if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
12436 429 : TREE_TARGET_GLOBALS (*iter) = NULL;
12437 429 : }
12438 :
12439 : /* Determine the "ultimate origin" of a block. */
12440 :
12441 : tree
12442 233538850 : block_ultimate_origin (const_tree block)
12443 : {
12444 233538850 : tree origin = BLOCK_ABSTRACT_ORIGIN (block);
12445 :
12446 233538850 : if (origin == NULL_TREE)
12447 : return NULL_TREE;
12448 : else
12449 : {
12450 290647610 : gcc_checking_assert ((DECL_P (origin)
12451 : && DECL_ORIGIN (origin) == origin)
12452 : || BLOCK_ORIGIN (origin) == origin);
12453 : return origin;
12454 : }
12455 : }
12456 :
12457 : /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
12458 : no instruction. */
12459 :
12460 : bool
12461 1756865428 : tree_nop_conversion_p (const_tree outer_type, const_tree inner_type)
12462 : {
12463 1756865428 : if (!inner_type || inner_type == error_mark_node)
12464 : return false;
12465 :
12466 : /* Do not strip casts into or out of differing address spaces. */
12467 1756827218 : if (POINTER_TYPE_P (outer_type)
12468 1756827218 : && TYPE_ADDR_SPACE (TREE_TYPE (outer_type)) != ADDR_SPACE_GENERIC)
12469 : {
12470 565 : if (!POINTER_TYPE_P (inner_type)
12471 565 : || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
12472 544 : != TYPE_ADDR_SPACE (TREE_TYPE (inner_type))))
12473 : return false;
12474 : }
12475 1756826653 : else if (POINTER_TYPE_P (inner_type)
12476 1756826653 : && TYPE_ADDR_SPACE (TREE_TYPE (inner_type)) != ADDR_SPACE_GENERIC)
12477 : {
12478 : /* We already know that outer_type is not a pointer with
12479 : a non-generic address space. */
12480 : return false;
12481 : }
12482 :
12483 : /* Use precision rather then machine mode when we can, which gives
12484 : the correct answer even for submode (bit-field) types. */
12485 1756824650 : if ((INTEGRAL_TYPE_P (outer_type)
12486 786688471 : || POINTER_TYPE_P (outer_type)
12487 74377060 : || TREE_CODE (outer_type) == OFFSET_TYPE)
12488 1682459135 : && (INTEGRAL_TYPE_P (inner_type)
12489 806426473 : || POINTER_TYPE_P (inner_type)
12490 1992087 : || TREE_CODE (inner_type) == OFFSET_TYPE))
12491 1680491212 : return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
12492 :
12493 76333438 : if (TYPE_MODE (outer_type) == BLKmode
12494 76333438 : && TYPE_MODE (inner_type) == BLKmode)
12495 : {
12496 7945 : if (VECTOR_TYPE_P (outer_type)
12497 5324 : && VECTOR_TYPE_P (inner_type)
12498 5324 : && known_eq (TYPE_VECTOR_SUBPARTS (outer_type),
12499 : TYPE_VECTOR_SUBPARTS (inner_type))
12500 18593 : && (TYPE_MODE (TREE_TYPE (outer_type))
12501 5324 : == TYPE_MODE (TREE_TYPE (inner_type))))
12502 5324 : return true;
12503 2621 : return false;
12504 : }
12505 :
12506 : /* Otherwise fall back on comparing machine modes (e.g. for
12507 : aggregate types, floats). */
12508 76325493 : return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
12509 : }
12510 :
12511 : /* Return true iff a view conversion from vector type INNER_TYPE to vector
12512 : type OUTER_TYPE has the same number of elements and does not change the
12513 : representation of an element. */
12514 :
12515 : bool
12516 6870363 : vector_nop_conversion_p (const_tree outer_type, const_tree inner_type)
12517 : {
12518 6870363 : return (VECTOR_TYPE_P (outer_type)
12519 3556889 : && VECTOR_TYPE_P (inner_type)
12520 3530277 : && known_eq (TYPE_VECTOR_SUBPARTS (outer_type),
12521 : TYPE_VECTOR_SUBPARTS (inner_type))
12522 9341226 : && tree_nop_conversion_p (TREE_TYPE (outer_type),
12523 2470863 : TREE_TYPE (inner_type)));
12524 : }
12525 :
12526 : /* Return true iff conversion in EXP generates no instruction. Mark
12527 : it inline so that we fully inline into the stripping functions even
12528 : though we have two uses of this function. */
12529 :
12530 : static inline bool
12531 21020238575 : tree_nop_conversion (const_tree exp)
12532 : {
12533 21020238575 : tree outer_type, inner_type;
12534 :
12535 21020238575 : if (location_wrapper_p (exp))
12536 : return true;
12537 20951869425 : if (!CONVERT_EXPR_P (exp)
12538 19855738322 : && TREE_CODE (exp) != NON_LVALUE_EXPR)
12539 : return false;
12540 :
12541 1112688832 : outer_type = TREE_TYPE (exp);
12542 1112688832 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12543 :
12544 1112688832 : return tree_nop_conversion_p (outer_type, inner_type);
12545 : }
12546 :
12547 : /* Return true iff conversion in EXP generates no instruction. Don't
12548 : consider conversions changing the signedness. */
12549 :
12550 : static bool
12551 2413861132 : tree_sign_nop_conversion (const_tree exp)
12552 : {
12553 2413861132 : tree outer_type, inner_type;
12554 :
12555 2413861132 : if (!tree_nop_conversion (exp))
12556 : return false;
12557 :
12558 241208404 : outer_type = TREE_TYPE (exp);
12559 241208404 : inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
12560 :
12561 241208404 : return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
12562 241208404 : && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
12563 : }
12564 :
12565 : /* Strip conversions from EXP according to tree_nop_conversion and
12566 : return the resulting expression. */
12567 :
12568 : tree
12569 17814445908 : tree_strip_nop_conversions (tree exp)
12570 : {
12571 18606377443 : while (tree_nop_conversion (exp))
12572 791931535 : exp = TREE_OPERAND (exp, 0);
12573 17814445908 : return exp;
12574 : }
12575 :
12576 : /* Strip conversions from EXP according to tree_sign_nop_conversion
12577 : and return the resulting expression. */
12578 :
12579 : tree
12580 2199534863 : tree_strip_sign_nop_conversions (tree exp)
12581 : {
12582 2413861132 : while (tree_sign_nop_conversion (exp))
12583 214326269 : exp = TREE_OPERAND (exp, 0);
12584 2199534863 : return exp;
12585 : }
12586 :
12587 : /* Avoid any floating point extensions from EXP. */
12588 : tree
12589 101508174 : strip_float_extensions (tree exp)
12590 : {
12591 101628407 : tree sub, expt, subt;
12592 :
12593 : /* For floating point constant look up the narrowest type that can hold
12594 : it properly and handle it like (type)(narrowest_type)constant.
12595 : This way we can optimize for instance a=a*2.0 where "a" is float
12596 : but 2.0 is double constant. */
12597 101628407 : if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
12598 : {
12599 3278747 : REAL_VALUE_TYPE orig;
12600 3278747 : tree type = NULL;
12601 :
12602 3278747 : orig = TREE_REAL_CST (exp);
12603 3278747 : if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node)
12604 3278747 : && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
12605 141588 : type = float_type_node;
12606 3137159 : else if (TYPE_PRECISION (TREE_TYPE (exp))
12607 3137159 : > TYPE_PRECISION (double_type_node)
12608 3137159 : && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
12609 34571 : type = double_type_node;
12610 3278747 : if (type)
12611 176159 : return build_real_truncate (type, orig);
12612 : }
12613 :
12614 101452248 : if (!CONVERT_EXPR_P (exp))
12615 : return exp;
12616 :
12617 5627518 : sub = TREE_OPERAND (exp, 0);
12618 5627518 : subt = TREE_TYPE (sub);
12619 5627518 : expt = TREE_TYPE (exp);
12620 :
12621 5627518 : if (!FLOAT_TYPE_P (subt))
12622 : return exp;
12623 :
12624 432904 : if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
12625 : return exp;
12626 :
12627 144666 : if (element_precision (subt) > element_precision (expt))
12628 : return exp;
12629 :
12630 : return strip_float_extensions (sub);
12631 : }
12632 :
12633 : /* Strip out all handled components that produce invariant
12634 : offsets. */
12635 :
12636 : const_tree
12637 6154376304 : strip_invariant_refs (const_tree op)
12638 : {
12639 7192732587 : while (handled_component_p (op))
12640 : {
12641 1050712347 : switch (TREE_CODE (op))
12642 : {
12643 198629597 : case ARRAY_REF:
12644 198629597 : case ARRAY_RANGE_REF:
12645 198629597 : if (!is_gimple_constant (TREE_OPERAND (op, 1))
12646 188017314 : || TREE_OPERAND (op, 2) != NULL_TREE
12647 186456232 : || TREE_OPERAND (op, 3) != NULL_TREE)
12648 : return NULL;
12649 : break;
12650 :
12651 850662475 : case COMPONENT_REF:
12652 850662475 : if (TREE_OPERAND (op, 2) != NULL_TREE)
12653 : return NULL;
12654 : break;
12655 :
12656 1038356283 : default:;
12657 : }
12658 1038356283 : op = TREE_OPERAND (op, 0);
12659 : }
12660 :
12661 : return op;
12662 : }
12663 :
12664 : /* Strip handled components with zero offset from OP. */
12665 :
12666 : tree
12667 559275 : strip_zero_offset_components (tree op)
12668 : {
12669 559275 : while (TREE_CODE (op) == COMPONENT_REF
12670 427474 : && integer_zerop (DECL_FIELD_OFFSET (TREE_OPERAND (op, 1)))
12671 1096008 : && integer_zerop (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (op, 1))))
12672 175227 : op = TREE_OPERAND (op, 0);
12673 559275 : return op;
12674 : }
12675 :
12676 : static GTY(()) tree gcc_eh_personality_decl;
12677 :
12678 : /* Return the GCC personality function decl. */
12679 :
12680 : tree
12681 407 : lhd_gcc_personality (void)
12682 : {
12683 407 : if (!gcc_eh_personality_decl)
12684 163 : gcc_eh_personality_decl = build_personality_function ("gcc");
12685 407 : return gcc_eh_personality_decl;
12686 : }
12687 :
12688 : /* TARGET is a call target of GIMPLE call statement
12689 : (obtained by gimple_call_fn). Return true if it is
12690 : OBJ_TYPE_REF representing an virtual call of C++ method.
12691 : (As opposed to OBJ_TYPE_REF representing objc calls
12692 : through a cast where middle-end devirtualization machinery
12693 : can't apply.) FOR_DUMP_P is true when being called from
12694 : the dump routines. */
12695 :
12696 : bool
12697 29116899 : virtual_method_call_p (const_tree target, bool for_dump_p)
12698 : {
12699 29116899 : if (TREE_CODE (target) != OBJ_TYPE_REF)
12700 : return false;
12701 1341870 : tree t = TREE_TYPE (target);
12702 1341870 : gcc_checking_assert (TREE_CODE (t) == POINTER_TYPE);
12703 1341870 : t = TREE_TYPE (t);
12704 1341870 : if (TREE_CODE (t) == FUNCTION_TYPE)
12705 : return false;
12706 1340586 : gcc_checking_assert (TREE_CODE (t) == METHOD_TYPE);
12707 : /* If we do not have BINFO associated, it means that type was built
12708 : without devirtualization enabled. Do not consider this a virtual
12709 : call. */
12710 1340586 : if (!TYPE_BINFO (obj_type_ref_class (target, for_dump_p)))
12711 0 : return false;
12712 : return true;
12713 : }
12714 :
12715 : /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */
12716 :
12717 : static tree
12718 108 : lookup_binfo_at_offset (tree binfo, tree type, HOST_WIDE_INT pos)
12719 : {
12720 108 : unsigned int i;
12721 108 : tree base_binfo, b;
12722 :
12723 124 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12724 108 : if (pos == tree_to_shwi (BINFO_OFFSET (base_binfo))
12725 108 : && types_same_for_odr (TREE_TYPE (base_binfo), type))
12726 : return base_binfo;
12727 70 : else if ((b = lookup_binfo_at_offset (base_binfo, type, pos)) != NULL)
12728 : return b;
12729 : return NULL;
12730 : }
12731 :
12732 : /* Try to find a base info of BINFO that would have its field decl at offset
12733 : OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12734 : found, return, otherwise return NULL_TREE. */
12735 :
12736 : tree
12737 283777 : get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
12738 : {
12739 283777 : tree type = BINFO_TYPE (binfo);
12740 :
12741 767117 : while (true)
12742 : {
12743 525447 : HOST_WIDE_INT pos, size;
12744 525447 : tree fld;
12745 525447 : int i;
12746 :
12747 525447 : if (types_same_for_odr (type, expected_type))
12748 283777 : return binfo;
12749 241670 : if (maybe_lt (offset, 0))
12750 : return NULL_TREE;
12751 :
12752 1203524 : for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
12753 : {
12754 1203524 : if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld))
12755 961657 : continue;
12756 :
12757 241867 : pos = int_bit_position (fld);
12758 241867 : size = tree_to_uhwi (DECL_SIZE (fld));
12759 1203721 : if (known_in_range_p (offset, pos, size))
12760 : break;
12761 : }
12762 241670 : if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
12763 : return NULL_TREE;
12764 :
12765 : /* Offset 0 indicates the primary base, whose vtable contents are
12766 : represented in the binfo for the derived class. */
12767 241670 : else if (maybe_ne (offset, 0))
12768 : {
12769 197 : tree found_binfo = NULL, base_binfo;
12770 : /* Offsets in BINFO are in bytes relative to the whole structure
12771 : while POS is in bits relative to the containing field. */
12772 197 : int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos
12773 197 : / BITS_PER_UNIT);
12774 :
12775 377 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
12776 339 : if (tree_to_shwi (BINFO_OFFSET (base_binfo)) == binfo_offset
12777 339 : && types_same_for_odr (TREE_TYPE (base_binfo), TREE_TYPE (fld)))
12778 : {
12779 : found_binfo = base_binfo;
12780 : break;
12781 : }
12782 197 : if (found_binfo)
12783 : binfo = found_binfo;
12784 : else
12785 38 : binfo = lookup_binfo_at_offset (binfo, TREE_TYPE (fld),
12786 : binfo_offset);
12787 : }
12788 :
12789 241670 : type = TREE_TYPE (fld);
12790 241670 : offset -= pos;
12791 241670 : }
12792 : }
12793 :
12794 : /* PR 84195: Replace control characters in "unescaped" with their
12795 : escaped equivalents. Allow newlines if -fmessage-length has
12796 : been set to a non-zero value. This is done here, rather than
12797 : where the attribute is recorded as the message length can
12798 : change between these two locations. */
12799 :
12800 : void
12801 136428 : escaped_string::escape (const char *unescaped)
12802 : {
12803 136428 : char *escaped;
12804 136428 : size_t i, new_i, len;
12805 :
12806 136428 : if (m_owned)
12807 8 : free (m_str);
12808 :
12809 136428 : m_str = const_cast<char *> (unescaped);
12810 136428 : m_owned = false;
12811 :
12812 136428 : if (unescaped == NULL || *unescaped == 0)
12813 : return;
12814 :
12815 136420 : len = strlen (unescaped);
12816 136420 : escaped = NULL;
12817 136420 : new_i = 0;
12818 :
12819 3953273 : for (i = 0; i < len; i++)
12820 : {
12821 3816853 : char c = unescaped[i];
12822 :
12823 3816853 : if (!ISCNTRL (c))
12824 : {
12825 3816768 : if (escaped)
12826 33 : escaped[new_i++] = c;
12827 3816768 : continue;
12828 : }
12829 :
12830 85 : if (c != '\n' || !pp_is_wrapping_line (global_dc->get_reference_printer ()))
12831 : {
12832 77 : if (escaped == NULL)
12833 : {
12834 : /* We only allocate space for a new string if we
12835 : actually encounter a control character that
12836 : needs replacing. */
12837 19 : escaped = (char *) xmalloc (len * 2 + 1);
12838 19 : strncpy (escaped, unescaped, i);
12839 19 : new_i = i;
12840 : }
12841 :
12842 77 : escaped[new_i++] = '\\';
12843 :
12844 77 : switch (c)
12845 : {
12846 8 : case '\a': escaped[new_i++] = 'a'; break;
12847 8 : case '\b': escaped[new_i++] = 'b'; break;
12848 8 : case '\f': escaped[new_i++] = 'f'; break;
12849 15 : case '\n': escaped[new_i++] = 'n'; break;
12850 15 : case '\r': escaped[new_i++] = 'r'; break;
12851 15 : case '\t': escaped[new_i++] = 't'; break;
12852 8 : case '\v': escaped[new_i++] = 'v'; break;
12853 0 : default: escaped[new_i++] = '?'; break;
12854 : }
12855 : }
12856 8 : else if (escaped)
12857 4 : escaped[new_i++] = c;
12858 : }
12859 :
12860 136420 : if (escaped)
12861 : {
12862 19 : escaped[new_i] = 0;
12863 19 : m_str = escaped;
12864 19 : m_owned = true;
12865 : }
12866 : }
12867 :
12868 : /* Warn about a use of an identifier which was marked deprecated. Returns
12869 : whether a warning was given. */
12870 :
12871 : bool
12872 1420713 : warn_deprecated_use (tree node, tree attr)
12873 : {
12874 1420713 : escaped_string msg;
12875 :
12876 1420713 : if (node == 0 || !warn_deprecated_decl)
12877 : return false;
12878 :
12879 1413474 : if (!attr)
12880 : {
12881 1298027 : if (DECL_P (node))
12882 1297857 : attr = DECL_ATTRIBUTES (node);
12883 170 : else if (TYPE_P (node))
12884 : {
12885 170 : tree decl = TYPE_STUB_DECL (node);
12886 170 : if (decl)
12887 146 : attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
12888 24 : else if ((decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (node)))
12889 : != NULL_TREE)
12890 : {
12891 6 : node = TREE_TYPE (decl);
12892 6 : attr = TYPE_ATTRIBUTES (node);
12893 : }
12894 : }
12895 : }
12896 :
12897 1298027 : if (attr)
12898 135954 : attr = lookup_attribute ("deprecated", attr);
12899 :
12900 135954 : if (attr)
12901 135943 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12902 :
12903 1413474 : bool w = false;
12904 1413474 : if (DECL_P (node))
12905 : {
12906 1413294 : auto_diagnostic_group d;
12907 1413294 : if (msg)
12908 135852 : w = warning (OPT_Wdeprecated_declarations,
12909 : "%qD is deprecated: %s", node, (const char *) msg);
12910 : else
12911 1277442 : w = warning (OPT_Wdeprecated_declarations,
12912 : "%qD is deprecated", node);
12913 1413294 : if (w)
12914 800 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12915 1413294 : }
12916 180 : else if (TYPE_P (node))
12917 : {
12918 180 : tree what = NULL_TREE;
12919 180 : tree decl = TYPE_STUB_DECL (node);
12920 :
12921 180 : if (TYPE_NAME (node))
12922 : {
12923 175 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
12924 10 : what = TYPE_NAME (node);
12925 165 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12926 165 : && DECL_NAME (TYPE_NAME (node)))
12927 165 : what = DECL_NAME (TYPE_NAME (node));
12928 : }
12929 :
12930 180 : auto_diagnostic_group d;
12931 180 : if (what)
12932 : {
12933 175 : if (msg)
12934 89 : w = warning (OPT_Wdeprecated_declarations,
12935 : "%qE is deprecated: %s", what, (const char *) msg);
12936 : else
12937 86 : w = warning (OPT_Wdeprecated_declarations,
12938 : "%qE is deprecated", what);
12939 : }
12940 : else
12941 : {
12942 5 : if (msg)
12943 2 : w = warning (OPT_Wdeprecated_declarations,
12944 : "type is deprecated: %s", (const char *) msg);
12945 : else
12946 3 : w = warning (OPT_Wdeprecated_declarations,
12947 : "type is deprecated");
12948 : }
12949 :
12950 180 : if (w && decl)
12951 111 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
12952 180 : }
12953 :
12954 : return w;
12955 1420713 : }
12956 :
12957 : /* Error out with an identifier which was marked 'unavailable'. */
12958 : void
12959 376 : error_unavailable_use (tree node, tree attr)
12960 : {
12961 376 : escaped_string msg;
12962 :
12963 376 : if (node == 0)
12964 0 : return;
12965 :
12966 376 : if (!attr)
12967 : {
12968 366 : if (DECL_P (node))
12969 306 : attr = DECL_ATTRIBUTES (node);
12970 60 : else if (TYPE_P (node))
12971 : {
12972 60 : tree decl = TYPE_STUB_DECL (node);
12973 60 : if (decl)
12974 51 : attr = lookup_attribute ("unavailable",
12975 51 : TYPE_ATTRIBUTES (TREE_TYPE (decl)));
12976 : }
12977 : }
12978 :
12979 366 : if (attr)
12980 164 : attr = lookup_attribute ("unavailable", attr);
12981 :
12982 164 : if (attr)
12983 164 : msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12984 :
12985 376 : if (DECL_P (node))
12986 : {
12987 306 : auto_diagnostic_group d;
12988 306 : if (msg)
12989 129 : error ("%qD is unavailable: %s", node, (const char *) msg);
12990 : else
12991 177 : error ("%qD is unavailable", node);
12992 306 : inform (DECL_SOURCE_LOCATION (node), "declared here");
12993 306 : }
12994 70 : else if (TYPE_P (node))
12995 : {
12996 70 : tree what = NULL_TREE;
12997 70 : tree decl = TYPE_STUB_DECL (node);
12998 :
12999 70 : if (TYPE_NAME (node))
13000 : {
13001 66 : if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
13002 4 : what = TYPE_NAME (node);
13003 62 : else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
13004 62 : && DECL_NAME (TYPE_NAME (node)))
13005 62 : what = DECL_NAME (TYPE_NAME (node));
13006 : }
13007 :
13008 70 : auto_diagnostic_group d;
13009 70 : if (what)
13010 : {
13011 66 : if (msg)
13012 33 : error ("%qE is unavailable: %s", what, (const char *) msg);
13013 : else
13014 33 : error ("%qE is unavailable", what);
13015 : }
13016 : else
13017 : {
13018 4 : if (msg)
13019 2 : error ("type is unavailable: %s", (const char *) msg);
13020 : else
13021 2 : error ("type is unavailable");
13022 : }
13023 :
13024 70 : if (decl)
13025 52 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
13026 70 : }
13027 376 : }
13028 :
13029 : /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
13030 : somewhere in it. */
13031 :
13032 : bool
13033 5907941 : contains_bitfld_component_ref_p (const_tree ref)
13034 : {
13035 12090385 : while (handled_component_p (ref))
13036 : {
13037 6199792 : if (TREE_CODE (ref) == COMPONENT_REF
13038 6199792 : && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
13039 : return true;
13040 6182444 : ref = TREE_OPERAND (ref, 0);
13041 : }
13042 :
13043 : return false;
13044 : }
13045 :
13046 : /* Try to determine whether a TRY_CATCH expression can fall through.
13047 : This is a subroutine of block_may_fallthru. */
13048 :
13049 : static bool
13050 1 : try_catch_may_fallthru (const_tree stmt)
13051 : {
13052 1 : tree_stmt_iterator i;
13053 :
13054 : /* If the TRY block can fall through, the whole TRY_CATCH can
13055 : fall through. */
13056 1 : if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
13057 : return true;
13058 :
13059 1 : switch (TREE_CODE (TREE_OPERAND (stmt, 1)))
13060 : {
13061 0 : case CATCH_EXPR:
13062 : /* See below. */
13063 0 : return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1)));
13064 :
13065 0 : case EH_FILTER_EXPR:
13066 : /* See below. */
13067 0 : return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1)));
13068 :
13069 0 : case STATEMENT_LIST:
13070 0 : break;
13071 :
13072 : default:
13073 : /* See below. */
13074 : return false;
13075 : }
13076 :
13077 0 : i = tsi_start (TREE_OPERAND (stmt, 1));
13078 0 : switch (TREE_CODE (tsi_stmt (i)))
13079 : {
13080 : case CATCH_EXPR:
13081 : /* We expect to see a sequence of CATCH_EXPR trees, each with a
13082 : catch expression and a body. The whole TRY_CATCH may fall
13083 : through iff any of the catch bodies falls through. */
13084 0 : for (; !tsi_end_p (i); tsi_next (&i))
13085 : {
13086 0 : if (block_may_fallthru (CATCH_BODY (tsi_stmt (i))))
13087 : return true;
13088 : }
13089 : return false;
13090 :
13091 0 : case EH_FILTER_EXPR:
13092 : /* The exception filter expression only matters if there is an
13093 : exception. If the exception does not match EH_FILTER_TYPES,
13094 : we will execute EH_FILTER_FAILURE, and we will fall through
13095 : if that falls through. If the exception does match
13096 : EH_FILTER_TYPES, the stack unwinder will continue up the
13097 : stack, so we will not fall through. We don't know whether we
13098 : will throw an exception which matches EH_FILTER_TYPES or not,
13099 : so we just ignore EH_FILTER_TYPES and assume that we might
13100 : throw an exception which doesn't match. */
13101 0 : return block_may_fallthru (EH_FILTER_FAILURE (tsi_stmt (i)));
13102 :
13103 : default:
13104 : /* This case represents statements to be executed when an
13105 : exception occurs. Those statements are implicitly followed
13106 : by a RESX statement to resume execution after the exception.
13107 : So in this case the TRY_CATCH never falls through. */
13108 : return false;
13109 : }
13110 : }
13111 :
13112 : /* Try to determine if we can fall out of the bottom of BLOCK. This guess
13113 : need not be 100% accurate; simply be conservative and return true if we
13114 : don't know. This is used only to avoid stupidly generating extra code.
13115 : If we're wrong, we'll just delete the extra code later. */
13116 :
13117 : bool
13118 9431558 : block_may_fallthru (const_tree block)
13119 : {
13120 : /* This CONST_CAST is okay because expr_last returns its argument
13121 : unmodified and we assign it to a const_tree. */
13122 10897610 : const_tree stmt = expr_last (const_cast<tree> (block));
13123 :
13124 10897610 : switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
13125 : {
13126 : case GOTO_EXPR:
13127 : case RETURN_EXPR:
13128 : /* Easy cases. If the last statement of the block implies
13129 : control transfer, then we can't fall through. */
13130 : return false;
13131 :
13132 12 : case SWITCH_EXPR:
13133 : /* If there is a default: label or case labels cover all possible
13134 : SWITCH_COND values, then the SWITCH_EXPR will transfer control
13135 : to some case label in all cases and all we care is whether the
13136 : SWITCH_BODY falls through. */
13137 12 : if (SWITCH_ALL_CASES_P (stmt))
13138 11 : return block_may_fallthru (SWITCH_BODY (stmt));
13139 : return true;
13140 :
13141 22078 : case COND_EXPR:
13142 22078 : if (block_may_fallthru (COND_EXPR_THEN (stmt)))
13143 : return true;
13144 2821 : return block_may_fallthru (COND_EXPR_ELSE (stmt));
13145 :
13146 910467 : case BIND_EXPR:
13147 910467 : return block_may_fallthru (BIND_EXPR_BODY (stmt));
13148 :
13149 1 : case TRY_CATCH_EXPR:
13150 1 : return try_catch_may_fallthru (stmt);
13151 :
13152 2104 : case TRY_FINALLY_EXPR:
13153 : /* The finally clause is always executed after the try clause,
13154 : so if it does not fall through, then the try-finally will not
13155 : fall through. Otherwise, if the try clause does not fall
13156 : through, then when the finally clause falls through it will
13157 : resume execution wherever the try clause was going. So the
13158 : whole try-finally will only fall through if both the try
13159 : clause and the finally clause fall through. */
13160 2104 : return (block_may_fallthru (TREE_OPERAND (stmt, 0))
13161 2104 : && block_may_fallthru (TREE_OPERAND (stmt, 1)));
13162 :
13163 0 : case EH_ELSE_EXPR:
13164 0 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
13165 :
13166 92015 : case MODIFY_EXPR:
13167 92015 : if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
13168 1587 : stmt = TREE_OPERAND (stmt, 1);
13169 : else
13170 : return true;
13171 : /* FALLTHRU */
13172 :
13173 325207 : case CALL_EXPR:
13174 : /* Functions that do not return do not fall through. */
13175 325207 : return (call_expr_flags (stmt) & ECF_NORETURN) == 0;
13176 :
13177 552743 : case CLEANUP_POINT_EXPR:
13178 552743 : return block_may_fallthru (TREE_OPERAND (stmt, 0));
13179 :
13180 10 : case TARGET_EXPR:
13181 10 : return block_may_fallthru (TREE_OPERAND (stmt, 1));
13182 :
13183 : case ERROR_MARK:
13184 : return true;
13185 :
13186 6700083 : default:
13187 6700083 : return lang_hooks.block_may_fallthru (stmt);
13188 : }
13189 : }
13190 :
13191 : /* True if we are using EH to handle cleanups. */
13192 : static bool using_eh_for_cleanups_flag = false;
13193 :
13194 : /* This routine is called from front ends to indicate eh should be used for
13195 : cleanups. */
13196 : void
13197 126380 : using_eh_for_cleanups (void)
13198 : {
13199 126380 : using_eh_for_cleanups_flag = true;
13200 126380 : }
13201 :
13202 : /* Query whether EH is used for cleanups. */
13203 : bool
13204 1768067 : using_eh_for_cleanups_p (void)
13205 : {
13206 1768067 : return using_eh_for_cleanups_flag;
13207 : }
13208 :
13209 : /* Wrapper for tree_code_name to ensure that tree code is valid */
13210 : const char *
13211 14802041906 : get_tree_code_name (enum tree_code code)
13212 : {
13213 14802041906 : const char *invalid = "<invalid tree code>";
13214 :
13215 : /* The tree_code enum promotes to signed, but we could be getting
13216 : invalid values, so force an unsigned comparison. */
13217 14802041906 : if (unsigned (code) >= MAX_TREE_CODES)
13218 : {
13219 0 : if ((unsigned)code == 0xa5a5)
13220 : return "ggc_freed";
13221 0 : return invalid;
13222 : }
13223 :
13224 14802041906 : return tree_code_name[code];
13225 : }
13226 :
13227 : /* Drops the TREE_OVERFLOW flag from T. */
13228 :
13229 : tree
13230 36857 : drop_tree_overflow (tree t)
13231 : {
13232 36857 : gcc_checking_assert (TREE_OVERFLOW (t));
13233 :
13234 : /* For tree codes with a sharing machinery re-build the result. */
13235 36857 : if (poly_int_tree_p (t))
13236 36845 : return wide_int_to_tree (TREE_TYPE (t), wi::to_poly_wide (t));
13237 :
13238 : /* For VECTOR_CST, remove the overflow bits from the encoded elements
13239 : and canonicalize the result. */
13240 12 : if (TREE_CODE (t) == VECTOR_CST)
13241 : {
13242 0 : tree_vector_builder builder;
13243 0 : builder.new_unary_operation (TREE_TYPE (t), t, true);
13244 0 : unsigned int count = builder.encoded_nelts ();
13245 0 : for (unsigned int i = 0; i < count; ++i)
13246 : {
13247 0 : tree elt = VECTOR_CST_ELT (t, i);
13248 0 : if (TREE_OVERFLOW (elt))
13249 0 : elt = drop_tree_overflow (elt);
13250 0 : builder.quick_push (elt);
13251 : }
13252 0 : return builder.build ();
13253 0 : }
13254 :
13255 : /* Otherwise, as all tcc_constants are possibly shared, copy the node
13256 : and drop the flag. */
13257 12 : t = copy_node (t);
13258 12 : TREE_OVERFLOW (t) = 0;
13259 :
13260 : /* For constants that contain nested constants, drop the flag
13261 : from those as well. */
13262 12 : if (TREE_CODE (t) == COMPLEX_CST)
13263 : {
13264 12 : if (TREE_OVERFLOW (TREE_REALPART (t)))
13265 12 : TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t));
13266 12 : if (TREE_OVERFLOW (TREE_IMAGPART (t)))
13267 0 : TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t));
13268 : }
13269 :
13270 : return t;
13271 : }
13272 :
13273 : /* Given a memory reference expression T, return its base address.
13274 : The base address of a memory reference expression is the main
13275 : object being referenced. For instance, the base address for
13276 : 'array[i].fld[j]' is 'array'. You can think of this as stripping
13277 : away the offset part from a memory address.
13278 :
13279 : This function calls handled_component_p to strip away all the inner
13280 : parts of the memory reference until it reaches the base object. */
13281 :
13282 : tree
13283 3322528837 : get_base_address (tree t)
13284 : {
13285 3322528837 : if (TREE_CODE (t) == WITH_SIZE_EXPR)
13286 899 : t = TREE_OPERAND (t, 0);
13287 4140555086 : while (handled_component_p (t))
13288 818026249 : t = TREE_OPERAND (t, 0);
13289 :
13290 3322528837 : if ((TREE_CODE (t) == MEM_REF
13291 3322528837 : || TREE_CODE (t) == TARGET_MEM_REF)
13292 3322528837 : && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
13293 151973490 : t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
13294 :
13295 3322528837 : return t;
13296 : }
13297 :
13298 : /* Return a tree of sizetype representing the size, in bytes, of the element
13299 : of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13300 :
13301 : tree
13302 799040531 : array_ref_element_size (tree exp)
13303 : {
13304 799040531 : tree aligned_size = TREE_OPERAND (exp, 3);
13305 799040531 : tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
13306 799040531 : location_t loc = EXPR_LOCATION (exp);
13307 :
13308 : /* If a size was specified in the ARRAY_REF, it's the size measured
13309 : in alignment units of the element type. So multiply by that value. */
13310 799040531 : if (aligned_size)
13311 : {
13312 : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13313 : sizetype from another type of the same width and signedness. */
13314 339960 : if (TREE_TYPE (aligned_size) != sizetype)
13315 5016 : aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
13316 339960 : return size_binop_loc (loc, MULT_EXPR, aligned_size,
13317 339960 : size_int (TYPE_ALIGN_UNIT (elmt_type)));
13318 : }
13319 :
13320 : /* Otherwise, take the size from that of the element type. Substitute
13321 : any PLACEHOLDER_EXPR that we have. */
13322 : else
13323 798700571 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
13324 : }
13325 :
13326 : /* Return a tree representing the lower bound of the array mentioned in
13327 : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13328 :
13329 : tree
13330 1102080336 : array_ref_low_bound (tree exp)
13331 : {
13332 1102080336 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13333 :
13334 : /* If a lower bound is specified in EXP, use it. */
13335 1102080336 : if (TREE_OPERAND (exp, 2))
13336 1974330 : return TREE_OPERAND (exp, 2);
13337 :
13338 : /* Otherwise, if there is a domain type and it has a lower bound, use it,
13339 : substituting for a PLACEHOLDER_EXPR as needed. */
13340 1100106006 : if (domain_type && TYPE_MIN_VALUE (domain_type))
13341 1099183201 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
13342 :
13343 : /* Otherwise, return a zero of the appropriate type. */
13344 922805 : tree idxtype = TREE_TYPE (TREE_OPERAND (exp, 1));
13345 922805 : return (idxtype == error_mark_node
13346 922805 : ? integer_zero_node : build_int_cst (idxtype, 0));
13347 : }
13348 :
13349 : /* Return a tree representing the upper bound of the array mentioned in
13350 : EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
13351 :
13352 : tree
13353 252865050 : array_ref_up_bound (tree exp)
13354 : {
13355 252865050 : tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
13356 :
13357 : /* If there is a domain type and it has an upper bound, use it, substituting
13358 : for a PLACEHOLDER_EXPR as needed. */
13359 252865050 : if (domain_type && TYPE_MAX_VALUE (domain_type))
13360 252072138 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
13361 :
13362 : /* Otherwise fail. */
13363 : return NULL_TREE;
13364 : }
13365 :
13366 : /* Returns true if REF is an array reference, a component reference,
13367 : or a memory reference to an array whose actual size might be larger
13368 : than its upper bound implies, there are multiple cases:
13369 : A. a ref to a flexible array member at the end of a structure;
13370 : B. a ref to an array with a different type against the original decl;
13371 : for example:
13372 :
13373 : short a[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
13374 : (*((char(*)[16])&a[0]))[i+8]
13375 :
13376 : C. a ref to an array that was passed as a parameter;
13377 : for example:
13378 :
13379 : int test (uint8_t *p, uint32_t t[1][1], int n) {
13380 : for (int i = 0; i < 4; i++, p++)
13381 : t[i][0] = ...;
13382 :
13383 : If non-null, set IS_TRAILING_ARRAY to true if the ref is the above case A.
13384 : */
13385 :
13386 : bool
13387 76140937 : array_ref_flexible_size_p (tree ref, bool *is_trailing_array /* = NULL */)
13388 : {
13389 : /* The TYPE for this array reference. */
13390 76140937 : tree atype = NULL_TREE;
13391 : /* The FIELD_DECL for the array field in the containing structure. */
13392 76140937 : tree afield_decl = NULL_TREE;
13393 : /* Whether this array is the trailing array of a structure. */
13394 76140937 : bool is_trailing_array_tmp = false;
13395 76140937 : if (!is_trailing_array)
13396 76056885 : is_trailing_array = &is_trailing_array_tmp;
13397 :
13398 76140937 : if (TREE_CODE (ref) == ARRAY_REF
13399 76140937 : || TREE_CODE (ref) == ARRAY_RANGE_REF)
13400 : {
13401 75896484 : atype = TREE_TYPE (TREE_OPERAND (ref, 0));
13402 75896484 : ref = TREE_OPERAND (ref, 0);
13403 : }
13404 244453 : else if (TREE_CODE (ref) == COMPONENT_REF
13405 244453 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE)
13406 : {
13407 172930 : atype = TREE_TYPE (TREE_OPERAND (ref, 1));
13408 172930 : afield_decl = TREE_OPERAND (ref, 1);
13409 : }
13410 71523 : else if (TREE_CODE (ref) == MEM_REF)
13411 : {
13412 7645 : tree arg = TREE_OPERAND (ref, 0);
13413 7645 : if (TREE_CODE (arg) == ADDR_EXPR)
13414 7645 : arg = TREE_OPERAND (arg, 0);
13415 7645 : tree argtype = TREE_TYPE (arg);
13416 7645 : if (TREE_CODE (argtype) == RECORD_TYPE)
13417 : {
13418 157 : if (tree fld = last_field (argtype))
13419 : {
13420 157 : atype = TREE_TYPE (fld);
13421 157 : afield_decl = fld;
13422 157 : if (TREE_CODE (atype) != ARRAY_TYPE)
13423 : return false;
13424 157 : if (VAR_P (arg) && DECL_SIZE (fld))
13425 : return false;
13426 : }
13427 : else
13428 : return false;
13429 : }
13430 : else
13431 : return false;
13432 : }
13433 : else
13434 : return false;
13435 :
13436 76069527 : if (TREE_CODE (ref) == STRING_CST)
13437 : return false;
13438 :
13439 : tree ref_to_array = ref;
13440 93380871 : while (handled_component_p (ref))
13441 : {
13442 : /* If the reference chain contains a component reference to a
13443 : non-union type and there follows another field the reference
13444 : is not at the end of a structure. */
13445 20477680 : if (TREE_CODE (ref) == COMPONENT_REF)
13446 : {
13447 19348492 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
13448 : {
13449 18081864 : tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
13450 42345803 : while (nextf && TREE_CODE (nextf) != FIELD_DECL)
13451 24263939 : nextf = DECL_CHAIN (nextf);
13452 : if (nextf)
13453 : return false;
13454 : }
13455 : }
13456 : /* If we have a multi-dimensional array we do not consider
13457 : a non-innermost dimension as flex array if the whole
13458 : multi-dimensional array is at struct end.
13459 : Same for an array of aggregates with a trailing array
13460 : member. */
13461 1129188 : else if (TREE_CODE (ref) == ARRAY_REF)
13462 : return false;
13463 190628 : else if (TREE_CODE (ref) == ARRAY_RANGE_REF)
13464 : ;
13465 : /* If we view an underlying object as sth else then what we
13466 : gathered up to now is what we have to rely on. */
13467 190612 : else if (TREE_CODE (ref) == VIEW_CONVERT_EXPR)
13468 : break;
13469 : else
13470 0 : gcc_unreachable ();
13471 :
13472 17312580 : ref = TREE_OPERAND (ref, 0);
13473 : }
13474 :
13475 73093803 : gcc_assert (!afield_decl
13476 : || (afield_decl && TREE_CODE (afield_decl) == FIELD_DECL));
13477 :
13478 : /* The array now is at struct end. Treat flexible array member as
13479 : always subject to extend, even into just padding constrained by
13480 : an underlying decl. */
13481 73093803 : if (! TYPE_SIZE (atype)
13482 70526835 : || ! TYPE_DOMAIN (atype)
13483 143620638 : || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13484 : {
13485 2572360 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13486 2572360 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13487 : }
13488 :
13489 : /* If the reference is based on a declared entity, the size of the array
13490 : is constrained by its given domain. (Do not trust commons PR/69368). */
13491 70521443 : ref = get_base_address (ref);
13492 70521443 : if (ref
13493 70521443 : && DECL_P (ref)
13494 60137333 : && !(flag_unconstrained_commons
13495 14 : && VAR_P (ref) && DECL_COMMON (ref))
13496 60137319 : && DECL_SIZE_UNIT (ref)
13497 130658385 : && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
13498 : {
13499 : /* If the object itself is the array it is not at struct end. */
13500 60136914 : if (DECL_P (ref_to_array))
13501 : return false;
13502 :
13503 : /* Check whether the array domain covers all of the available
13504 : padding. */
13505 15779413 : poly_int64 offset;
13506 15779413 : if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
13507 15778053 : || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST
13508 31534989 : || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST)
13509 : {
13510 23837 : *is_trailing_array
13511 23837 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13512 23837 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13513 : }
13514 15755576 : if (! get_addr_base_and_unit_offset (ref_to_array, &offset))
13515 : {
13516 2847 : *is_trailing_array
13517 2847 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13518 2847 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13519 : }
13520 :
13521 : /* If at least one extra element fits it is a flexarray. */
13522 15752729 : if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13523 : - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype)))
13524 : + 2)
13525 : * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype))),
13526 : wi::to_offset (DECL_SIZE_UNIT (ref)) - offset))
13527 : {
13528 394374 : *is_trailing_array
13529 394374 : = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13530 394374 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13531 : }
13532 :
13533 : return false;
13534 : }
13535 :
13536 10384529 : *is_trailing_array = afield_decl && TREE_CODE (afield_decl) == FIELD_DECL;
13537 10384529 : return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
13538 : }
13539 :
13540 :
13541 : /* Return a tree representing the offset, in bytes, of the field referenced
13542 : by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
13543 :
13544 : tree
13545 2802088588 : component_ref_field_offset (tree exp)
13546 : {
13547 2802088588 : tree aligned_offset = TREE_OPERAND (exp, 2);
13548 2802088588 : tree field = TREE_OPERAND (exp, 1);
13549 2802088588 : location_t loc = EXPR_LOCATION (exp);
13550 :
13551 : /* If an offset was specified in the COMPONENT_REF, it's the offset measured
13552 : in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
13553 : value. */
13554 2802088588 : if (aligned_offset)
13555 : {
13556 : /* ??? tree_ssa_useless_type_conversion will eliminate casts to
13557 : sizetype from another type of the same width and signedness. */
13558 11913 : if (TREE_TYPE (aligned_offset) != sizetype)
13559 133 : aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
13560 11913 : return size_binop_loc (loc, MULT_EXPR, aligned_offset,
13561 11913 : size_int (DECL_OFFSET_ALIGN (field)
13562 : / BITS_PER_UNIT));
13563 : }
13564 :
13565 : /* Otherwise, take the offset from that of the field. Substitute
13566 : any PLACEHOLDER_EXPR that we have. */
13567 : else
13568 2802076675 : return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
13569 : }
13570 :
13571 : /* Given the initializer INIT, return the initializer for the field
13572 : DECL if it exists, otherwise null. Used to obtain the initializer
13573 : for a flexible array member and determine its size. */
13574 :
13575 : static tree
13576 1267 : get_initializer_for (tree init, tree decl)
13577 : {
13578 1267 : STRIP_NOPS (init);
13579 :
13580 1267 : tree fld, fld_init;
13581 1267 : unsigned HOST_WIDE_INT i;
13582 3571 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), i, fld, fld_init)
13583 : {
13584 1926 : if (decl == fld)
13585 : return fld_init;
13586 :
13587 1037 : if (TREE_CODE (fld) == CONSTRUCTOR)
13588 : {
13589 0 : fld_init = get_initializer_for (fld_init, decl);
13590 0 : if (fld_init)
13591 : return fld_init;
13592 : }
13593 : }
13594 :
13595 : return NULL_TREE;
13596 : }
13597 :
13598 : /* Determines the special array member type for the array reference REF. */
13599 : special_array_member
13600 257732 : component_ref_sam_type (tree ref)
13601 : {
13602 257732 : special_array_member sam_type = special_array_member::none;
13603 :
13604 257732 : tree member = TREE_OPERAND (ref, 1);
13605 257732 : tree memsize = DECL_SIZE_UNIT (member);
13606 257732 : if (memsize)
13607 : {
13608 125638 : tree memtype = TREE_TYPE (member);
13609 125638 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13610 125516 : return sam_type;
13611 :
13612 84052 : bool trailing = false;
13613 84052 : (void) array_ref_flexible_size_p (ref, &trailing);
13614 84052 : bool zero_elts = integer_zerop (memsize);
13615 84052 : if (zero_elts && integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (memtype))))
13616 : {
13617 : /* If array element has zero size, verify if it is a flexible
13618 : array member or zero length array. Clear zero_elts if
13619 : it has one or more members or is a VLA member. */
13620 6 : if (tree dom = TYPE_DOMAIN (memtype))
13621 6 : if (tree min = TYPE_MIN_VALUE (dom))
13622 6 : if (tree max = TYPE_MAX_VALUE (dom))
13623 4 : if (TREE_CODE (min) != INTEGER_CST
13624 4 : || TREE_CODE (max) != INTEGER_CST
13625 12 : || !((integer_zerop (min) && integer_all_onesp (max))
13626 4 : || tree_int_cst_lt (max, min)))
13627 : zero_elts = false;
13628 : }
13629 84052 : if (!trailing && !zero_elts)
13630 : /* MEMBER is an interior array with more than one element. */
13631 : return special_array_member::int_n;
13632 :
13633 23532 : if (zero_elts)
13634 : {
13635 1074 : if (trailing)
13636 : return special_array_member::trail_0;
13637 : else
13638 463 : return special_array_member::int_0;
13639 : }
13640 :
13641 22921 : if (!zero_elts)
13642 22921 : if (tree dom = TYPE_DOMAIN (memtype))
13643 22921 : if (tree min = TYPE_MIN_VALUE (dom))
13644 22921 : if (tree max = TYPE_MAX_VALUE (dom))
13645 22921 : if (TREE_CODE (min) == INTEGER_CST
13646 22921 : && TREE_CODE (max) == INTEGER_CST)
13647 : {
13648 22799 : offset_int minidx = wi::to_offset (min);
13649 22799 : offset_int maxidx = wi::to_offset (max);
13650 22799 : offset_int neltsm1 = maxidx - minidx;
13651 22799 : if (neltsm1 > 0)
13652 : /* MEMBER is a trailing array with more than
13653 : one elements. */
13654 22799 : return special_array_member::trail_n;
13655 :
13656 2182 : if (neltsm1 == 0)
13657 : return special_array_member::trail_1;
13658 : }
13659 : }
13660 :
13661 : return sam_type;
13662 : }
13663 :
13664 : /* Determines the size of the member referenced by the COMPONENT_REF
13665 : REF, using its initializer expression if necessary in order to
13666 : determine the size of an initialized flexible array member.
13667 : If non-null, set *SAM to the type of special array member.
13668 : Returns the size as sizetype (which might be zero for an object
13669 : with an uninitialized flexible array member) or null if the size
13670 : cannot be determined. */
13671 :
13672 : tree
13673 158377 : component_ref_size (tree ref, special_array_member *sam /* = NULL */)
13674 : {
13675 158377 : gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
13676 :
13677 158377 : special_array_member sambuf;
13678 158377 : if (!sam)
13679 101522 : sam = &sambuf;
13680 158377 : *sam = component_ref_sam_type (ref);
13681 :
13682 : /* The object/argument referenced by the COMPONENT_REF and its type. */
13683 158377 : tree arg = TREE_OPERAND (ref, 0);
13684 158377 : tree argtype = TREE_TYPE (arg);
13685 : /* The referenced member. */
13686 158377 : tree member = TREE_OPERAND (ref, 1);
13687 :
13688 158377 : tree memsize = DECL_SIZE_UNIT (member);
13689 158377 : if (memsize)
13690 : {
13691 90790 : tree memtype = TREE_TYPE (member);
13692 90790 : if (TREE_CODE (memtype) != ARRAY_TYPE)
13693 : /* DECL_SIZE may be less than TYPE_SIZE in C++ when referring
13694 : to the type of a class with a virtual base which doesn't
13695 : reflect the size of the virtual's members (see pr97595).
13696 : If that's the case fail for now and implement something
13697 : more robust in the future. */
13698 41586 : return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype))
13699 41586 : ? memsize : NULL_TREE);
13700 :
13701 : /* 2-or-more elements arrays are treated as normal arrays by default. */
13702 49204 : if (*sam == special_array_member::int_n
13703 49204 : || *sam == special_array_member::trail_n)
13704 : return memsize;
13705 :
13706 1849 : tree afield_decl = TREE_OPERAND (ref, 1);
13707 1849 : gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
13708 : /* If the trailing array is a not a flexible array member, treat it as
13709 : a normal array. */
13710 1849 : if (DECL_NOT_FLEXARRAY (afield_decl)
13711 1849 : && *sam != special_array_member::int_0)
13712 : return memsize;
13713 :
13714 1840 : if (*sam == special_array_member::int_0)
13715 270 : memsize = NULL_TREE;
13716 :
13717 : /* For a reference to a flexible array member of a union
13718 : use the size of the union instead of the size of the member. */
13719 1840 : if (TREE_CODE (argtype) == UNION_TYPE)
13720 277 : memsize = TYPE_SIZE_UNIT (argtype);
13721 : }
13722 :
13723 : /* MEMBER is either a bona fide flexible array member, or a zero-elements
13724 : array member, or an array of length one treated as such. */
13725 :
13726 : /* If the reference is to a declared object and the member a true
13727 : flexible array, try to determine its size from its initializer. */
13728 69427 : poly_int64 baseoff = 0;
13729 69427 : tree base = get_addr_base_and_unit_offset (ref, &baseoff);
13730 69427 : if (!base || !VAR_P (base))
13731 : {
13732 66079 : if (*sam != special_array_member::int_0)
13733 : return NULL_TREE;
13734 :
13735 52 : if (TREE_CODE (arg) != COMPONENT_REF)
13736 : return NULL_TREE;
13737 :
13738 : base = arg;
13739 6 : while (TREE_CODE (base) == COMPONENT_REF)
13740 3 : base = TREE_OPERAND (base, 0);
13741 3 : baseoff = tree_to_poly_int64 (byte_position (TREE_OPERAND (ref, 1)));
13742 : }
13743 :
13744 : /* BASE is the declared object of which MEMBER is either a member
13745 : or that is cast to ARGTYPE (e.g., a char buffer used to store
13746 : an ARGTYPE object). */
13747 3351 : tree basetype = TREE_TYPE (base);
13748 :
13749 : /* Determine the base type of the referenced object. If it's
13750 : the same as ARGTYPE and MEMBER has a known size, return it. */
13751 3351 : tree bt = basetype;
13752 3351 : if (*sam != special_array_member::int_0)
13753 3352 : while (TREE_CODE (bt) == ARRAY_TYPE)
13754 222 : bt = TREE_TYPE (bt);
13755 3351 : bool typematch = useless_type_conversion_p (argtype, bt);
13756 3351 : if (memsize && typematch)
13757 : return memsize;
13758 :
13759 3261 : memsize = NULL_TREE;
13760 :
13761 3261 : if (typematch)
13762 : /* MEMBER is a true flexible array member. Compute its size from
13763 : the initializer of the BASE object if it has one. */
13764 2697 : if (tree init = DECL_P (base) ? DECL_INITIAL (base) : NULL_TREE)
13765 1300 : if (init != error_mark_node)
13766 : {
13767 1267 : init = get_initializer_for (init, member);
13768 1267 : if (init)
13769 : {
13770 889 : memsize = TYPE_SIZE_UNIT (TREE_TYPE (init));
13771 889 : if (tree refsize = TYPE_SIZE_UNIT (argtype))
13772 : {
13773 : /* Use the larger of the initializer size and the tail
13774 : padding in the enclosing struct. */
13775 889 : poly_int64 rsz = tree_to_poly_int64 (refsize);
13776 889 : rsz -= baseoff;
13777 889 : if (known_lt (tree_to_poly_int64 (memsize), rsz))
13778 56 : memsize = wide_int_to_tree (TREE_TYPE (memsize), rsz);
13779 : }
13780 :
13781 889 : baseoff = 0;
13782 : }
13783 : }
13784 :
13785 889 : if (!memsize)
13786 : {
13787 2372 : if (typematch)
13788 : {
13789 1808 : if (DECL_P (base)
13790 1808 : && DECL_EXTERNAL (base)
13791 454 : && bt == basetype
13792 2256 : && *sam != special_array_member::int_0)
13793 : /* The size of a flexible array member of an extern struct
13794 : with no initializer cannot be determined (it's defined
13795 : in another translation unit and can have an initializer
13796 : with an arbitrary number of elements). */
13797 : return NULL_TREE;
13798 :
13799 : /* Use the size of the base struct or, for interior zero-length
13800 : arrays, the size of the enclosing type. */
13801 1383 : memsize = TYPE_SIZE_UNIT (bt);
13802 : }
13803 564 : else if (DECL_P (base))
13804 : /* Use the size of the BASE object (possibly an array of some
13805 : other type such as char used to store the struct). */
13806 561 : memsize = DECL_SIZE_UNIT (base);
13807 : else
13808 : return NULL_TREE;
13809 : }
13810 :
13811 : /* If the flexible array member has a known size use the greater
13812 : of it and the tail padding in the enclosing struct.
13813 : Otherwise, when the size of the flexible array member is unknown
13814 : and the referenced object is not a struct, use the size of its
13815 : type when known. This detects sizes of array buffers when cast
13816 : to struct types with flexible array members. */
13817 1944 : if (memsize)
13818 : {
13819 2808 : if (!tree_fits_poly_int64_p (memsize))
13820 : return NULL_TREE;
13821 2808 : poly_int64 memsz64 = memsize ? tree_to_poly_int64 (memsize) : 0;
13822 2808 : if (known_lt (baseoff, memsz64))
13823 : {
13824 1341 : memsz64 -= baseoff;
13825 1341 : return wide_int_to_tree (TREE_TYPE (memsize), memsz64);
13826 : }
13827 1467 : return size_zero_node;
13828 : }
13829 :
13830 : /* Return "don't know" for an external non-array object since its
13831 : flexible array member can be initialized to have any number of
13832 : elements. Otherwise, return zero because the flexible array
13833 : member has no elements. */
13834 25 : return (DECL_P (base)
13835 25 : && DECL_EXTERNAL (base)
13836 25 : && (!typematch
13837 0 : || TREE_CODE (basetype) != ARRAY_TYPE)
13838 25 : ? NULL_TREE : size_zero_node);
13839 : }
13840 :
13841 : /* Return true if the given node CALL is a call to a .ACCESS_WITH_SIZE
13842 : function. */
13843 : bool
13844 168575025 : is_access_with_size_p (const_tree call)
13845 : {
13846 168575025 : if (TREE_CODE (call) != CALL_EXPR)
13847 : return false;
13848 43731683 : if (CALL_EXPR_IFN (call) == IFN_ACCESS_WITH_SIZE)
13849 1073 : return true;
13850 : return false;
13851 : }
13852 :
13853 : /* Get the corresponding reference from the call to a .ACCESS_WITH_SIZE.
13854 : * i.e the first argument of this call. Return NULL_TREE otherwise. */
13855 : tree
13856 3 : get_ref_from_access_with_size (tree call)
13857 : {
13858 3 : if (is_access_with_size_p (call))
13859 3 : return CALL_EXPR_ARG (call, 0);
13860 : return NULL_TREE;
13861 : }
13862 :
13863 : /* Return the machine mode of T. For vectors, returns the mode of the
13864 : inner type. The main use case is to feed the result to HONOR_NANS,
13865 : avoiding the BLKmode that a direct TYPE_MODE (T) might return. */
13866 :
13867 : machine_mode
13868 5992356271 : element_mode (const_tree t)
13869 : {
13870 5992356271 : if (!TYPE_P (t))
13871 208744162 : t = TREE_TYPE (t);
13872 5992356271 : if (VECTOR_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
13873 1565382440 : t = TREE_TYPE (t);
13874 5992356271 : return TYPE_MODE (t);
13875 : }
13876 :
13877 : /* Vector types need to re-check the target flags each time we report
13878 : the machine mode. We need to do this because attribute target can
13879 : change the result of vector_mode_supported_p and have_regs_of_mode
13880 : on a per-function basis. Thus the TYPE_MODE of a VECTOR_TYPE can
13881 : change on a per-function basis. */
13882 : /* ??? Possibly a better solution is to run through all the types
13883 : referenced by a function and re-compute the TYPE_MODE once, rather
13884 : than make the TYPE_MODE macro call a function. */
13885 :
13886 : machine_mode
13887 1379650480 : vector_type_mode (const_tree t)
13888 : {
13889 1379650480 : machine_mode mode;
13890 :
13891 1379650480 : gcc_assert (TREE_CODE (t) == VECTOR_TYPE);
13892 :
13893 1379650480 : mode = t->type_common.mode;
13894 319485226 : if (VECTOR_MODE_P (mode)
13895 1660647190 : && (!targetm.vector_mode_supported_p (mode)
13896 1317209682 : || !have_regs_of_mode[mode]))
13897 : {
13898 24917194 : scalar_int_mode innermode;
13899 :
13900 : /* For integers, try mapping it to a same-sized scalar mode. */
13901 24917194 : if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode))
13902 : {
13903 36923626 : poly_int64 size = (TYPE_VECTOR_SUBPARTS (t)
13904 18461813 : * GET_MODE_BITSIZE (innermode));
13905 18461813 : scalar_int_mode mode;
13906 33363246 : if (int_mode_for_size (size, 0).exists (&mode)
13907 15098475 : && have_regs_of_mode[mode])
13908 197042 : return mode;
13909 : }
13910 :
13911 : return BLKmode;
13912 : }
13913 :
13914 : return mode;
13915 : }
13916 :
13917 : /* Return the size in bits of each element of vector type TYPE. */
13918 :
13919 : unsigned int
13920 253752 : vector_element_bits (const_tree type)
13921 : {
13922 253752 : gcc_checking_assert (VECTOR_TYPE_P (type));
13923 253752 : if (VECTOR_BOOLEAN_TYPE_P (type))
13924 1282 : return TYPE_PRECISION (TREE_TYPE (type));
13925 252470 : return tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)));
13926 : }
13927 :
13928 : /* Calculate the size in bits of each element of vector type TYPE
13929 : and return the result as a tree of type bitsizetype. */
13930 :
13931 : tree
13932 93467 : vector_element_bits_tree (const_tree type)
13933 : {
13934 93467 : gcc_checking_assert (VECTOR_TYPE_P (type));
13935 93467 : if (VECTOR_BOOLEAN_TYPE_P (type))
13936 647 : return bitsize_int (vector_element_bits (type));
13937 92820 : return TYPE_SIZE (TREE_TYPE (type));
13938 : }
13939 :
13940 : /* Verify that basic properties of T match TV and thus T can be a variant of
13941 : TV. TV should be the more specified variant (i.e. the main variant). */
13942 :
13943 : static bool
13944 200042846 : verify_type_variant (const_tree t, tree tv)
13945 : {
13946 : /* Type variant can differ by:
13947 :
13948 : - TYPE_QUALS: TYPE_READONLY, TYPE_VOLATILE, TYPE_ATOMIC, TYPE_RESTRICT,
13949 : ENCODE_QUAL_ADDR_SPACE.
13950 : - main variant may be TYPE_COMPLETE_P and variant types !TYPE_COMPLETE_P
13951 : in this case some values may not be set in the variant types
13952 : (see TYPE_COMPLETE_P checks).
13953 : - it is possible to have TYPE_ARTIFICIAL variant of non-artificial type
13954 : - by TYPE_NAME and attributes (i.e. when variant originate by typedef)
13955 : - TYPE_CANONICAL (TYPE_ALIAS_SET is the same among variants)
13956 : - by the alignment: TYPE_ALIGN and TYPE_USER_ALIGN
13957 : - during LTO by TYPE_CONTEXT if type is TYPE_FILE_SCOPE_P
13958 : this is necessary to make it possible to merge types form different TUs
13959 : - arrays, pointers and references may have TREE_TYPE that is a variant
13960 : of TREE_TYPE of their main variants.
13961 : - aggregates may have new TYPE_FIELDS list that list variants of
13962 : the main variant TYPE_FIELDS.
13963 : - vector types may differ by TYPE_VECTOR_OPAQUE
13964 : */
13965 :
13966 : /* Convenience macro for matching individual fields. */
13967 : #define verify_variant_match(flag) \
13968 : do { \
13969 : if (flag (tv) != flag (t)) \
13970 : { \
13971 : error ("type variant differs by %s", #flag); \
13972 : debug_tree (tv); \
13973 : return false; \
13974 : } \
13975 : } while (false)
13976 :
13977 : /* tree_base checks. */
13978 :
13979 200042846 : verify_variant_match (TREE_CODE);
13980 : /* FIXME: Ada builds non-artificial variants of artificial types. */
13981 : #if 0
13982 : if (TYPE_ARTIFICIAL (tv))
13983 : verify_variant_match (TYPE_ARTIFICIAL);
13984 : #endif
13985 200042846 : if (POINTER_TYPE_P (tv))
13986 13096998 : verify_variant_match (TYPE_REF_CAN_ALIAS_ALL);
13987 : /* FIXME: TYPE_SIZES_GIMPLIFIED may differs for Ada build. */
13988 200042846 : verify_variant_match (TYPE_UNSIGNED);
13989 200042846 : verify_variant_match (TYPE_PACKED);
13990 200042846 : if (TREE_CODE (t) == REFERENCE_TYPE)
13991 3195807 : verify_variant_match (TYPE_REF_IS_RVALUE);
13992 200042846 : if (AGGREGATE_TYPE_P (t))
13993 82368310 : verify_variant_match (TYPE_REVERSE_STORAGE_ORDER);
13994 : else
13995 117674536 : verify_variant_match (TYPE_SATURATING);
13996 : /* FIXME: This check trigger during libstdc++ build. */
13997 : #if 0
13998 : if (RECORD_OR_UNION_TYPE_P (t) && COMPLETE_TYPE_P (t))
13999 : verify_variant_match (TYPE_FINAL_P);
14000 : #endif
14001 :
14002 : /* tree_type_common checks. */
14003 :
14004 200042846 : if (COMPLETE_TYPE_P (t))
14005 : {
14006 188067399 : verify_variant_match (TYPE_MODE);
14007 188067399 : if (TREE_CODE (TYPE_SIZE (t)) != PLACEHOLDER_EXPR
14008 188067399 : && TREE_CODE (TYPE_SIZE (tv)) != PLACEHOLDER_EXPR)
14009 188067399 : verify_variant_match (TYPE_SIZE);
14010 188067399 : if (TREE_CODE (TYPE_SIZE_UNIT (t)) != PLACEHOLDER_EXPR
14011 188067399 : && TREE_CODE (TYPE_SIZE_UNIT (tv)) != PLACEHOLDER_EXPR
14012 376134798 : && TYPE_SIZE_UNIT (t) != TYPE_SIZE_UNIT (tv))
14013 : {
14014 0 : gcc_assert (!operand_equal_p (TYPE_SIZE_UNIT (t),
14015 : TYPE_SIZE_UNIT (tv), 0));
14016 0 : error ("type variant has different %<TYPE_SIZE_UNIT%>");
14017 0 : debug_tree (tv);
14018 0 : error ("type variant%'s %<TYPE_SIZE_UNIT%>");
14019 0 : debug_tree (TYPE_SIZE_UNIT (tv));
14020 0 : error ("type%'s %<TYPE_SIZE_UNIT%>");
14021 0 : debug_tree (TYPE_SIZE_UNIT (t));
14022 0 : return false;
14023 : }
14024 188067399 : verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
14025 : }
14026 200042846 : verify_variant_match (TYPE_PRECISION_RAW);
14027 200042846 : if (RECORD_OR_UNION_TYPE_P (t))
14028 81741894 : verify_variant_match (TYPE_TRANSPARENT_AGGR);
14029 118300952 : else if (TREE_CODE (t) == ARRAY_TYPE)
14030 626416 : verify_variant_match (TYPE_NONALIASED_COMPONENT);
14031 : /* During LTO we merge variant lists from different translation units
14032 : that may differ BY TYPE_CONTEXT that in turn may point
14033 : to TRANSLATION_UNIT_DECL.
14034 : Ada also builds variants of types with different TYPE_CONTEXT. */
14035 : #if 0
14036 : if (!in_lto_p || !TYPE_FILE_SCOPE_P (t))
14037 : verify_variant_match (TYPE_CONTEXT);
14038 : #endif
14039 200042846 : if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == INTEGER_TYPE)
14040 63846732 : verify_variant_match (TYPE_STRING_FLAG);
14041 200042846 : if (TREE_CODE (t) == RECORD_TYPE || TREE_CODE (t) == UNION_TYPE)
14042 81741894 : verify_variant_match (TYPE_CXX_ODR_P);
14043 200042846 : if (TYPE_ALIAS_SET_KNOWN_P (t))
14044 : {
14045 0 : error ("type variant with %<TYPE_ALIAS_SET_KNOWN_P%>");
14046 0 : debug_tree (tv);
14047 0 : return false;
14048 : }
14049 :
14050 : /* tree_type_non_common checks. */
14051 :
14052 : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
14053 : and dangle the pointer from time to time. */
14054 81741894 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_VFIELD (t) != TYPE_VFIELD (tv)
14055 200042846 : && (in_lto_p || !TYPE_VFIELD (tv)
14056 0 : || TREE_CODE (TYPE_VFIELD (tv)) != TREE_LIST))
14057 : {
14058 0 : error ("type variant has different %<TYPE_VFIELD%>");
14059 0 : debug_tree (tv);
14060 0 : return false;
14061 : }
14062 3569404 : if ((TREE_CODE (t) == ENUMERAL_TYPE && COMPLETE_TYPE_P (t))
14063 196473499 : || TREE_CODE (t) == INTEGER_TYPE
14064 133253183 : || TREE_CODE (t) == BOOLEAN_TYPE
14065 98206817 : || TREE_CODE (t) == BITINT_TYPE
14066 98206507 : || SCALAR_FLOAT_TYPE_P (t)
14067 296263245 : || FIXED_POINT_TYPE_P (t))
14068 : {
14069 103822447 : verify_variant_match (TYPE_MAX_VALUE);
14070 103822447 : verify_variant_match (TYPE_MIN_VALUE);
14071 : }
14072 200042846 : if (TREE_CODE (t) == METHOD_TYPE)
14073 11978 : verify_variant_match (TYPE_METHOD_BASETYPE);
14074 200042846 : if (TREE_CODE (t) == OFFSET_TYPE)
14075 1607 : verify_variant_match (TYPE_OFFSET_BASETYPE);
14076 200042846 : if (TREE_CODE (t) == ARRAY_TYPE)
14077 626416 : verify_variant_match (TYPE_ARRAY_MAX_SIZE);
14078 : /* FIXME: Be lax and allow TYPE_BINFO to be missing in variant types
14079 : or even type's main variant. This is needed to make bootstrap pass
14080 : and the bug seems new in GCC 5.
14081 : C++ FE should be updated to make this consistent and we should check
14082 : that TYPE_BINFO is always NULL for !COMPLETE_TYPE_P and otherwise there
14083 : is a match with main variant.
14084 :
14085 : Also disable the check for Java for now because of parser hack that builds
14086 : first an dummy BINFO and then sometimes replace it by real BINFO in some
14087 : of the copies. */
14088 81741894 : if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t) && TYPE_BINFO (tv)
14089 69595405 : && TYPE_BINFO (t) != TYPE_BINFO (tv)
14090 : /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
14091 : Since there is no cheap way to tell C++/Java type w/o LTO, do checking
14092 : at LTO time only. */
14093 200042846 : && (in_lto_p && odr_type_p (t)))
14094 : {
14095 0 : error ("type variant has different %<TYPE_BINFO%>");
14096 0 : debug_tree (tv);
14097 0 : error ("type variant%'s %<TYPE_BINFO%>");
14098 0 : debug_tree (TYPE_BINFO (tv));
14099 0 : error ("type%'s %<TYPE_BINFO%>");
14100 0 : debug_tree (TYPE_BINFO (t));
14101 0 : return false;
14102 : }
14103 :
14104 : /* Check various uses of TYPE_VALUES_RAW. */
14105 200042846 : if (TREE_CODE (t) == ENUMERAL_TYPE
14106 200042846 : && TYPE_VALUES (t))
14107 3398545 : verify_variant_match (TYPE_VALUES);
14108 196644301 : else if (TREE_CODE (t) == ARRAY_TYPE)
14109 626416 : verify_variant_match (TYPE_DOMAIN);
14110 : /* Permit incomplete variants of complete type. While FEs may complete
14111 : all variants, this does not happen for C++ templates in all cases. */
14112 196017885 : else if (RECORD_OR_UNION_TYPE_P (t)
14113 81741894 : && COMPLETE_TYPE_P (t)
14114 265992895 : && TYPE_FIELDS (t) != TYPE_FIELDS (tv))
14115 : {
14116 4168 : tree f1, f2;
14117 :
14118 : /* Fortran builds qualified variants as new records with items of
14119 : qualified type. Verify that they looks same. */
14120 4168 : for (f1 = TYPE_FIELDS (t), f2 = TYPE_FIELDS (tv);
14121 13320 : f1 && f2;
14122 9152 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
14123 9152 : if (TREE_CODE (f1) != FIELD_DECL || TREE_CODE (f2) != FIELD_DECL
14124 9152 : || (TYPE_MAIN_VARIANT (TREE_TYPE (f1))
14125 9152 : != TYPE_MAIN_VARIANT (TREE_TYPE (f2))
14126 : /* FIXME: gfc_nonrestricted_type builds all types as variants
14127 : with exception of pointer types. It deeply copies the type
14128 : which means that we may end up with a variant type
14129 : referring non-variant pointer. We may change it to
14130 : produce types as variants, too, like
14131 : objc_get_protocol_qualified_type does. */
14132 69 : && !POINTER_TYPE_P (TREE_TYPE (f1)))
14133 9152 : || DECL_FIELD_OFFSET (f1) != DECL_FIELD_OFFSET (f2)
14134 18304 : || DECL_FIELD_BIT_OFFSET (f1) != DECL_FIELD_BIT_OFFSET (f2))
14135 : break;
14136 4168 : if (f1 || f2)
14137 : {
14138 0 : error ("type variant has different %<TYPE_FIELDS%>");
14139 0 : debug_tree (tv);
14140 0 : error ("first mismatch is field");
14141 0 : debug_tree (f1);
14142 0 : error ("and field");
14143 0 : debug_tree (f2);
14144 0 : return false;
14145 : }
14146 : }
14147 196013717 : else if (FUNC_OR_METHOD_TYPE_P (t))
14148 152809 : verify_variant_match (TYPE_ARG_TYPES);
14149 : /* For C++ the qualified variant of array type is really an array type
14150 : of qualified TREE_TYPE.
14151 : objc builds variants of pointer where pointer to type is a variant, too
14152 : in objc_get_protocol_qualified_type. */
14153 200042846 : if (TREE_TYPE (t) != TREE_TYPE (tv)
14154 200042846 : && ((TREE_CODE (t) != ARRAY_TYPE
14155 0 : && !POINTER_TYPE_P (t))
14156 540638 : || TYPE_MAIN_VARIANT (TREE_TYPE (t))
14157 540638 : != TYPE_MAIN_VARIANT (TREE_TYPE (tv))))
14158 : {
14159 0 : error ("type variant has different %<TREE_TYPE%>");
14160 0 : debug_tree (tv);
14161 0 : error ("type variant%'s %<TREE_TYPE%>");
14162 0 : debug_tree (TREE_TYPE (tv));
14163 0 : error ("type%'s %<TREE_TYPE%>");
14164 0 : debug_tree (TREE_TYPE (t));
14165 0 : return false;
14166 : }
14167 200042846 : if (type_with_alias_set_p (t)
14168 200042846 : && !gimple_canonical_types_compatible_p (t, tv, false))
14169 : {
14170 0 : error ("type is not compatible with its variant");
14171 0 : debug_tree (tv);
14172 0 : error ("type variant%'s %<TREE_TYPE%>");
14173 0 : debug_tree (TREE_TYPE (tv));
14174 0 : error ("type%'s %<TREE_TYPE%>");
14175 0 : debug_tree (TREE_TYPE (t));
14176 0 : return false;
14177 : }
14178 : return true;
14179 : #undef verify_variant_match
14180 : }
14181 :
14182 :
14183 : /* The TYPE_CANONICAL merging machinery. It should closely resemble
14184 : the middle-end types_compatible_p function. It needs to avoid
14185 : claiming types are different for types that should be treated
14186 : the same with respect to TBAA. Canonical types are also used
14187 : for IL consistency checks via the useless_type_conversion_p
14188 : predicate which does not handle all type kinds itself but falls
14189 : back to pointer-comparison of TYPE_CANONICAL for aggregates
14190 : for example. */
14191 :
14192 : /* Return true if TYPE_UNSIGNED of TYPE should be ignored for canonical
14193 : type calculation because we need to allow inter-operability between signed
14194 : and unsigned variants. */
14195 :
14196 : bool
14197 1676460 : type_with_interoperable_signedness (const_tree type)
14198 : {
14199 : /* Fortran standard require C_SIGNED_CHAR to be interoperable with both
14200 : signed char and unsigned char. Similarly fortran FE builds
14201 : C_SIZE_T as signed type, while C defines it unsigned. */
14202 :
14203 1676460 : return tree_code_for_canonical_type_merging (TREE_CODE (type))
14204 : == INTEGER_TYPE
14205 1676256 : && (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)
14206 453520 : || TYPE_PRECISION (type) == TYPE_PRECISION (size_type_node));
14207 : }
14208 :
14209 : /* Return true iff T1 and T2 are structurally identical for what
14210 : TBAA is concerned.
14211 : This function is used both by lto.cc canonical type merging and by the
14212 : verifier. If TRUST_TYPE_CANONICAL we do not look into structure of types
14213 : that have TYPE_CANONICAL defined and assume them equivalent. This is useful
14214 : only for LTO because only in these cases TYPE_CANONICAL equivalence
14215 : correspond to one defined by gimple_canonical_types_compatible_p. */
14216 :
14217 : bool
14218 409366950 : gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
14219 : bool trust_type_canonical)
14220 : {
14221 : /* Type variants should be same as the main variant. When not doing sanity
14222 : checking to verify this fact, go to main variants and save some work. */
14223 409765391 : if (trust_type_canonical)
14224 : {
14225 897306 : t1 = TYPE_MAIN_VARIANT (t1);
14226 897306 : t2 = TYPE_MAIN_VARIANT (t2);
14227 : }
14228 :
14229 : /* Check first for the obvious case of pointer identity. */
14230 409765391 : if (t1 == t2)
14231 : return true;
14232 :
14233 : /* Check that we have two types to compare. */
14234 346568686 : if (t1 == NULL_TREE || t2 == NULL_TREE)
14235 : return false;
14236 :
14237 : /* We consider complete types always compatible with incomplete type.
14238 : This does not make sense for canonical type calculation and thus we
14239 : need to ensure that we are never called on it.
14240 :
14241 : FIXME: For more correctness the function probably should have three modes
14242 : 1) mode assuming that types are complete matching their structure
14243 : 2) mode allowing incomplete types but producing equivalence classes
14244 : and thus ignoring all info from complete types
14245 : 3) mode allowing incomplete types to match complete but checking
14246 : compatibility between complete types.
14247 :
14248 : 1 and 2 can be used for canonical type calculation. 3 is the real
14249 : definition of type compatibility that can be used i.e. for warnings during
14250 : declaration merging. */
14251 :
14252 346568686 : gcc_assert (!trust_type_canonical
14253 : || (type_with_alias_set_p (t1) && type_with_alias_set_p (t2)));
14254 :
14255 : /* If the types have been previously registered and found equal
14256 : they still are. */
14257 :
14258 692840688 : if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t2)
14259 691893536 : && trust_type_canonical)
14260 : {
14261 : /* Do not use TYPE_CANONICAL of pointer types. For LTO streamed types
14262 : they are always NULL, but they are set to non-NULL for types
14263 : constructed by build_pointer_type and variants. In this case the
14264 : TYPE_CANONICAL is more fine grained than the equivalnce we test (where
14265 : all pointers are considered equal. Be sure to not return false
14266 : negatives. */
14267 165416 : gcc_checking_assert (canonical_type_used_p (t1)
14268 : && canonical_type_used_p (t2));
14269 82708 : return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
14270 : }
14271 :
14272 : /* For types where we do ODR based TBAA the canonical type is always
14273 : set correctly, so we know that types are different if their
14274 : canonical types does not match. */
14275 346485978 : if (trust_type_canonical
14276 347297515 : && (odr_type_p (t1) && odr_based_tbaa_p (t1))
14277 811537 : != (odr_type_p (t2) && odr_based_tbaa_p (t2)))
14278 : return false;
14279 :
14280 : /* Can't be the same type if the types don't have the same code. */
14281 346485978 : enum tree_code code = tree_code_for_canonical_type_merging (TREE_CODE (t1));
14282 688694230 : if (code != tree_code_for_canonical_type_merging (TREE_CODE (t2)))
14283 : return false;
14284 :
14285 : /* Qualifiers do not matter for canonical type comparison purposes. */
14286 :
14287 : /* Void types and nullptr types are always the same. */
14288 346485943 : if (VOID_TYPE_P (t1)
14289 346437206 : || TREE_CODE (t1) == NULLPTR_TYPE)
14290 : return true;
14291 :
14292 : /* Can't be compatible types if they have different mode. Because of
14293 : flexible array members, we allow mismatching modes for structures or
14294 : unions. */
14295 345772049 : if (!RECORD_OR_UNION_TYPE_P (t1)
14296 345772049 : && TREE_CODE (t1) != ARRAY_TYPE
14297 345772049 : && TYPE_MODE (t1) != TYPE_MODE (t2))
14298 : return false;
14299 :
14300 : /* Non-aggregate types can be handled cheaply. */
14301 345772049 : if (INTEGRAL_TYPE_P (t1)
14302 345772049 : || SCALAR_FLOAT_TYPE_P (t1)
14303 183259189 : || FIXED_POINT_TYPE_P (t1)
14304 182887507 : || VECTOR_TYPE_P (t1)
14305 182837096 : || TREE_CODE (t1) == COMPLEX_TYPE
14306 182489066 : || TREE_CODE (t1) == OFFSET_TYPE
14307 182485830 : || POINTER_TYPE_P (t1))
14308 : {
14309 : /* Can't be the same type if they have different precision. */
14310 206880804 : if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
14311 : return false;
14312 :
14313 : /* In some cases the signed and unsigned types are required to be
14314 : inter-operable. */
14315 206880804 : if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)
14316 206880804 : && !type_with_interoperable_signedness (t1))
14317 : return false;
14318 :
14319 : /* Fortran's C_SIGNED_CHAR is !TYPE_STRING_FLAG but needs to be
14320 : interoperable with "signed char". Unless all frontends are revisited
14321 : to agree on these types, we must ignore the flag completely. */
14322 :
14323 : /* Fortran standard define C_PTR type that is compatible with every
14324 : C pointer. For this reason we need to glob all pointers into one.
14325 : Still pointers in different address spaces are not compatible. */
14326 206880804 : if (POINTER_TYPE_P (t1))
14327 : {
14328 43594585 : if (TYPE_ADDR_SPACE (TREE_TYPE (t1))
14329 43594585 : != TYPE_ADDR_SPACE (TREE_TYPE (t2)))
14330 : return false;
14331 : }
14332 :
14333 : /* Tail-recurse to components. */
14334 206880804 : if (VECTOR_TYPE_P (t1)
14335 206880804 : || TREE_CODE (t1) == COMPLEX_TYPE)
14336 1195323 : return gimple_canonical_types_compatible_p (TREE_TYPE (t1),
14337 398441 : TREE_TYPE (t2),
14338 398441 : trust_type_canonical);
14339 :
14340 : return true;
14341 : }
14342 :
14343 : /* Do type-specific comparisons. */
14344 138891245 : switch (TREE_CODE (t1))
14345 : {
14346 1127324 : case ARRAY_TYPE:
14347 : /* Array types are the same if the element types are the same and
14348 : minimum and maximum index are the same. */
14349 1127324 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14350 : trust_type_canonical)
14351 1127285 : || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
14352 1127285 : || TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2)
14353 2254609 : || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
14354 : return false;
14355 : else
14356 : {
14357 1127285 : tree i1 = TYPE_DOMAIN (t1);
14358 1127285 : tree i2 = TYPE_DOMAIN (t2);
14359 :
14360 : /* For an incomplete external array, the type domain can be
14361 : NULL_TREE. Check this condition also. */
14362 1127285 : if (i1 == NULL_TREE && i2 == NULL_TREE)
14363 : return true;
14364 1027143 : else if (i1 == NULL_TREE || i2 == NULL_TREE)
14365 : return false;
14366 : else
14367 : {
14368 1027143 : tree min1 = TYPE_MIN_VALUE (i1);
14369 1027143 : tree min2 = TYPE_MIN_VALUE (i2);
14370 1027143 : tree max1 = TYPE_MAX_VALUE (i1);
14371 1027143 : tree max2 = TYPE_MAX_VALUE (i2);
14372 :
14373 : /* The minimum/maximum values have to be the same. */
14374 1027143 : if ((min1 == min2
14375 0 : || (min1 && min2
14376 0 : && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
14377 0 : && TREE_CODE (min2) == PLACEHOLDER_EXPR)
14378 0 : || operand_equal_p (min1, min2, 0))))
14379 1027143 : && (max1 == max2
14380 0 : || (max1 && max2
14381 0 : && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
14382 0 : && TREE_CODE (max2) == PLACEHOLDER_EXPR)
14383 0 : || operand_equal_p (max1, max2, 0)))))
14384 1027143 : return true;
14385 : else
14386 : return false;
14387 : }
14388 : }
14389 :
14390 7232 : case METHOD_TYPE:
14391 7232 : case FUNCTION_TYPE:
14392 : /* Function types are the same if the return type and arguments types
14393 : are the same. */
14394 7232 : if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2),
14395 : trust_type_canonical))
14396 : return false;
14397 :
14398 7232 : if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)
14399 7232 : && (TYPE_NO_NAMED_ARGS_STDARG_P (t1)
14400 340 : == TYPE_NO_NAMED_ARGS_STDARG_P (t2)))
14401 : return true;
14402 : else
14403 : {
14404 6892 : tree parms1, parms2;
14405 :
14406 6892 : for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
14407 30653 : parms1 && parms2;
14408 23761 : parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
14409 : {
14410 47522 : if (!gimple_canonical_types_compatible_p
14411 23761 : (TREE_VALUE (parms1), TREE_VALUE (parms2),
14412 : trust_type_canonical))
14413 : return false;
14414 : }
14415 :
14416 6892 : if (parms1 || parms2)
14417 : return false;
14418 :
14419 6892 : return true;
14420 : }
14421 :
14422 137409428 : case RECORD_TYPE:
14423 137409428 : case UNION_TYPE:
14424 137409428 : case QUAL_UNION_TYPE:
14425 137409428 : {
14426 137409428 : tree f1, f2;
14427 :
14428 : /* Don't try to compare variants of an incomplete type, before
14429 : TYPE_FIELDS has been copied around. */
14430 137409428 : if (!COMPLETE_TYPE_P (t1) && !COMPLETE_TYPE_P (t2))
14431 : return true;
14432 :
14433 :
14434 126343729 : if (TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2))
14435 : return false;
14436 :
14437 : /* For aggregate types, all the fields must be the same. */
14438 126343729 : for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
14439 189248860 : f1 || f2;
14440 62905131 : f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
14441 : {
14442 : /* Skip non-fields and zero-sized fields, except zero-sized
14443 : arrays at the end. */
14444 1906277757 : while (f1 && (TREE_CODE (f1) != FIELD_DECL
14445 115380230 : || (DECL_SIZE (f1)
14446 115362890 : && integer_zerop (DECL_SIZE (f1))
14447 52475076 : && (TREE_CHAIN (f1)
14448 3657 : || TREE_CODE (TREE_TYPE (f1))
14449 : != ARRAY_TYPE))))
14450 1718158289 : f1 = TREE_CHAIN (f1);
14451 1906279375 : while (f2 && (TREE_CODE (f2) != FIELD_DECL
14452 115395486 : || (DECL_SIZE (f2)
14453 115378038 : && integer_zerop (DECL_SIZE (f2))
14454 52476701 : && (TREE_CHAIN (f2)
14455 4766 : || TREE_CODE (TREE_TYPE (f2))
14456 : != ARRAY_TYPE))))
14457 1718159907 : f2 = TREE_CHAIN (f2);
14458 188119468 : if (!f1 || !f2)
14459 : break;
14460 :
14461 62905926 : tree t1 = TREE_TYPE (f1);
14462 62905926 : tree t2 = TREE_TYPE (f2);
14463 :
14464 : /* If the last element are arrays, we only compare the element
14465 : types. */
14466 64025688 : if (TREE_CHAIN (f1) == NULL_TREE && TREE_CODE (t1) == ARRAY_TYPE
14467 62993204 : && TREE_CHAIN (f2) == NULL_TREE && TREE_CODE (t2) == ARRAY_TYPE)
14468 : {
14469 : /* If both arrays have zero size, this is a match. */
14470 157624 : if (DECL_SIZE (f1) && integer_zerop (DECL_SIZE (f1))
14471 88045 : && DECL_SIZE (f2) && integer_zerop (DECL_SIZE (f2)))
14472 : return true;
14473 :
14474 86502 : t1 = TREE_TYPE (t1);
14475 86502 : t2 = TREE_TYPE (t2);
14476 : }
14477 :
14478 62905155 : if (DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
14479 62905150 : || !gimple_compare_field_offset (f1, f2)
14480 125810305 : || !gimple_canonical_types_compatible_p
14481 62905150 : (t1, t2, trust_type_canonical))
14482 : return false;
14483 : }
14484 :
14485 : /* If one aggregate has more fields than the other, they
14486 : are not the same. */
14487 126342934 : if (f1 || f2)
14488 13638 : return false;
14489 :
14490 : return true;
14491 : }
14492 :
14493 347261 : default:
14494 : /* Consider all types with language specific trees in them mutually
14495 : compatible. This is executed only from verify_type and false
14496 : positives can be tolerated. */
14497 347261 : gcc_assert (!in_lto_p);
14498 : return true;
14499 : }
14500 : }
14501 :
14502 : /* For OPAQUE_TYPE T, it should have only size and alignment information
14503 : and its mode should be of class MODE_OPAQUE. This function verifies
14504 : these properties of T match TV which is the main variant of T and TC
14505 : which is the canonical of T. */
14506 :
14507 : static void
14508 0 : verify_opaque_type (const_tree t, tree tv, tree tc)
14509 : {
14510 0 : gcc_assert (OPAQUE_TYPE_P (t));
14511 0 : gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv));
14512 0 : gcc_assert (tc && tc == TYPE_CANONICAL (tc));
14513 :
14514 : /* For an opaque type T1, check if some of its properties match
14515 : the corresponding ones of the other opaque type T2, emit some
14516 : error messages for those inconsistent ones. */
14517 0 : auto check_properties_for_opaque_type = [](const_tree t1, tree t2,
14518 : const char *kind_msg)
14519 : {
14520 0 : if (!OPAQUE_TYPE_P (t2))
14521 : {
14522 0 : error ("type %s is not an opaque type", kind_msg);
14523 0 : debug_tree (t2);
14524 0 : return;
14525 : }
14526 0 : if (!OPAQUE_MODE_P (TYPE_MODE (t2)))
14527 : {
14528 0 : error ("type %s is not with opaque mode", kind_msg);
14529 0 : debug_tree (t2);
14530 0 : return;
14531 : }
14532 0 : if (TYPE_MODE (t1) != TYPE_MODE (t2))
14533 : {
14534 0 : error ("type %s differs by %<TYPE_MODE%>", kind_msg);
14535 0 : debug_tree (t2);
14536 0 : return;
14537 : }
14538 0 : poly_uint64 t1_size = tree_to_poly_uint64 (TYPE_SIZE (t1));
14539 0 : poly_uint64 t2_size = tree_to_poly_uint64 (TYPE_SIZE (t2));
14540 0 : if (maybe_ne (t1_size, t2_size))
14541 : {
14542 0 : error ("type %s differs by %<TYPE_SIZE%>", kind_msg);
14543 0 : debug_tree (t2);
14544 0 : return;
14545 : }
14546 0 : if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2))
14547 : {
14548 0 : error ("type %s differs by %<TYPE_ALIGN%>", kind_msg);
14549 0 : debug_tree (t2);
14550 0 : return;
14551 : }
14552 0 : if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
14553 : {
14554 0 : error ("type %s differs by %<TYPE_USER_ALIGN%>", kind_msg);
14555 0 : debug_tree (t2);
14556 0 : return;
14557 : }
14558 : };
14559 :
14560 0 : if (t != tv)
14561 0 : check_properties_for_opaque_type (t, tv, "variant");
14562 :
14563 0 : if (t != tc)
14564 0 : check_properties_for_opaque_type (t, tc, "canonical");
14565 0 : }
14566 :
14567 : /* Verify type T. */
14568 :
14569 : void
14570 924894453 : verify_type (const_tree t)
14571 : {
14572 924894453 : bool error_found = false;
14573 924894453 : tree mv = TYPE_MAIN_VARIANT (t);
14574 924894453 : tree ct = TYPE_CANONICAL (t);
14575 :
14576 924894453 : if (OPAQUE_TYPE_P (t))
14577 : {
14578 0 : verify_opaque_type (t, mv, ct);
14579 0 : return;
14580 : }
14581 :
14582 924894453 : if (!mv)
14583 : {
14584 0 : error ("main variant is not defined");
14585 0 : error_found = true;
14586 : }
14587 924894453 : else if (mv != TYPE_MAIN_VARIANT (mv))
14588 : {
14589 0 : error ("%<TYPE_MAIN_VARIANT%> has different %<TYPE_MAIN_VARIANT%>");
14590 0 : debug_tree (mv);
14591 0 : error_found = true;
14592 : }
14593 924894453 : else if (t != mv && !verify_type_variant (t, mv))
14594 : error_found = true;
14595 :
14596 924894453 : if (!ct)
14597 : ;
14598 922859454 : else if (TYPE_CANONICAL (ct) != ct)
14599 : {
14600 0 : error ("%<TYPE_CANONICAL%> has different %<TYPE_CANONICAL%>");
14601 0 : debug_tree (ct);
14602 0 : error_found = true;
14603 : }
14604 : /* Method and function types cannot be used to address memory and thus
14605 : TYPE_CANONICAL really matters only for determining useless conversions.
14606 :
14607 : FIXME: C++ FE produce declarations of builtin functions that are not
14608 : compatible with main variants. */
14609 922859454 : else if (TREE_CODE (t) == FUNCTION_TYPE)
14610 : ;
14611 922220858 : else if (t != ct
14612 : /* FIXME: gimple_canonical_types_compatible_p cannot compare types
14613 : with variably sized arrays because their sizes possibly
14614 : gimplified to different variables. */
14615 156486120 : && !variably_modified_type_p (ct, NULL)
14616 156481481 : && !gimple_canonical_types_compatible_p (t, ct, false)
14617 922234496 : && COMPLETE_TYPE_P (t))
14618 : {
14619 0 : error ("%<TYPE_CANONICAL%> is not compatible");
14620 0 : debug_tree (ct);
14621 0 : error_found = true;
14622 : }
14623 1671976132 : if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t)
14624 : /* We allow a mismatch for structure or union because of
14625 : flexible array members. */
14626 745117303 : && !RECORD_OR_UNION_TYPE_P (t)
14627 307351200 : && !RECORD_OR_UNION_TYPE_P (TYPE_CANONICAL (t))
14628 307351200 : && TREE_CODE (t) != ARRAY_TYPE
14629 1230726898 : && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
14630 : {
14631 0 : error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");
14632 0 : debug_tree (ct);
14633 0 : error_found = true;
14634 : }
14635 924894453 : if (TYPE_MAIN_VARIANT (t) == t && ct && TYPE_MAIN_VARIANT (ct) != ct)
14636 : {
14637 : /* This can happen when build_type_attribute_variant is called on
14638 : C/C++ arrays of qualified types. volatile int[2] is unqualified
14639 : ARRAY_TYPE with volatile int element type.
14640 : TYPE_CANONICAL (volatile int) is itself and so is
14641 : TYPE_CANONICAL (volatile int[2]). build_type_attribute_qual_variant
14642 : creates a distinct type copy (so TYPE_MAIN_VARIANT is itself) and sets
14643 : its TYPE_CANONICAL to the unqualified ARRAY_TYPE (so volatile int[2]).
14644 : But this is not the TYPE_MAIN_VARIANT, which is int[2]. So, just
14645 : verify that TYPE_MAIN_VARIANT (ct) is already the final type we
14646 : need. */
14647 2 : tree mvc = TYPE_MAIN_VARIANT (ct);
14648 2 : if (TYPE_CANONICAL (mvc) != mvc)
14649 : {
14650 0 : error ("main variant of %<TYPE_CANONICAL%> of main variant is not"
14651 : " its own %<TYPE_CANONICAL%>");
14652 0 : debug_tree (ct);
14653 0 : debug_tree (TYPE_MAIN_VARIANT (ct));
14654 0 : error_found = true;
14655 : }
14656 : }
14657 :
14658 :
14659 : /* Check various uses of TYPE_MIN_VALUE_RAW. */
14660 924894453 : if (RECORD_OR_UNION_TYPE_P (t))
14661 : {
14662 : /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
14663 : and danagle the pointer from time to time. */
14664 486441967 : if (TYPE_VFIELD (t)
14665 12450999 : && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
14666 486441967 : && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
14667 : {
14668 0 : error ("%<TYPE_VFIELD%> is not %<FIELD_DECL%> nor %<TREE_LIST%>");
14669 0 : debug_tree (TYPE_VFIELD (t));
14670 0 : error_found = true;
14671 : }
14672 : }
14673 438452486 : else if (TREE_CODE (t) == POINTER_TYPE)
14674 : {
14675 112670362 : if (TYPE_NEXT_PTR_TO (t)
14676 112670362 : && TREE_CODE (TYPE_NEXT_PTR_TO (t)) != POINTER_TYPE)
14677 : {
14678 0 : error ("%<TYPE_NEXT_PTR_TO%> is not %<POINTER_TYPE%>");
14679 0 : debug_tree (TYPE_NEXT_PTR_TO (t));
14680 0 : error_found = true;
14681 : }
14682 : }
14683 325782124 : else if (TREE_CODE (t) == REFERENCE_TYPE)
14684 : {
14685 51425602 : if (TYPE_NEXT_REF_TO (t)
14686 51425602 : && TREE_CODE (TYPE_NEXT_REF_TO (t)) != REFERENCE_TYPE)
14687 : {
14688 0 : error ("%<TYPE_NEXT_REF_TO%> is not %<REFERENCE_TYPE%>");
14689 0 : debug_tree (TYPE_NEXT_REF_TO (t));
14690 0 : error_found = true;
14691 : }
14692 : }
14693 : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14694 : || FIXED_POINT_TYPE_P (t))
14695 : {
14696 : /* FIXME: The following check should pass:
14697 : useless_type_conversion_p (const_cast <tree> (t),
14698 : TREE_TYPE (TYPE_MIN_VALUE (t))
14699 : but does not for C sizetypes in LTO. */
14700 : }
14701 :
14702 : /* Check various uses of TYPE_MAXVAL_RAW. */
14703 924894453 : if (RECORD_OR_UNION_TYPE_P (t))
14704 : {
14705 486441967 : if (!TYPE_BINFO (t))
14706 : ;
14707 457481702 : else if (TREE_CODE (TYPE_BINFO (t)) != TREE_BINFO)
14708 : {
14709 0 : error ("%<TYPE_BINFO%> is not %<TREE_BINFO%>");
14710 0 : debug_tree (TYPE_BINFO (t));
14711 0 : error_found = true;
14712 : }
14713 457481702 : else if (TREE_TYPE (TYPE_BINFO (t)) != TYPE_MAIN_VARIANT (t))
14714 : {
14715 0 : error ("%<TYPE_BINFO%> type is not %<TYPE_MAIN_VARIANT%>");
14716 0 : debug_tree (TREE_TYPE (TYPE_BINFO (t)));
14717 0 : error_found = true;
14718 : }
14719 : }
14720 : else if (FUNC_OR_METHOD_TYPE_P (t))
14721 : {
14722 862003 : if (TYPE_METHOD_BASETYPE (t)
14723 70466 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != RECORD_TYPE
14724 862201 : && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != UNION_TYPE)
14725 : {
14726 0 : error ("%<TYPE_METHOD_BASETYPE%> is not record nor union");
14727 0 : debug_tree (TYPE_METHOD_BASETYPE (t));
14728 0 : error_found = true;
14729 : }
14730 : }
14731 : else if (TREE_CODE (t) == OFFSET_TYPE)
14732 : {
14733 35500 : if (TYPE_OFFSET_BASETYPE (t)
14734 35500 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != RECORD_TYPE
14735 35508 : && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != UNION_TYPE)
14736 : {
14737 0 : error ("%<TYPE_OFFSET_BASETYPE%> is not record nor union");
14738 0 : debug_tree (TYPE_OFFSET_BASETYPE (t));
14739 0 : error_found = true;
14740 : }
14741 : }
14742 : else if (INTEGRAL_TYPE_P (t) || SCALAR_FLOAT_TYPE_P (t)
14743 : || FIXED_POINT_TYPE_P (t))
14744 : {
14745 : /* FIXME: The following check should pass:
14746 : useless_type_conversion_p (const_cast <tree> (t),
14747 : TREE_TYPE (TYPE_MAX_VALUE (t))
14748 : but does not for C sizetypes in LTO. */
14749 : }
14750 : else if (TREE_CODE (t) == ARRAY_TYPE)
14751 : {
14752 1793094 : if (TYPE_ARRAY_MAX_SIZE (t)
14753 1793094 : && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t)) != INTEGER_CST)
14754 : {
14755 0 : error ("%<TYPE_ARRAY_MAX_SIZE%> not %<INTEGER_CST%>");
14756 0 : debug_tree (TYPE_ARRAY_MAX_SIZE (t));
14757 0 : error_found = true;
14758 : }
14759 : }
14760 294494613 : else if (TYPE_MAX_VALUE_RAW (t))
14761 : {
14762 0 : error ("%<TYPE_MAX_VALUE_RAW%> non-NULL");
14763 0 : debug_tree (TYPE_MAX_VALUE_RAW (t));
14764 0 : error_found = true;
14765 : }
14766 :
14767 924894453 : if (TYPE_LANG_SLOT_1 (t) && in_lto_p)
14768 : {
14769 0 : error ("%<TYPE_LANG_SLOT_1 (binfo)%> field is non-NULL");
14770 0 : debug_tree (TYPE_LANG_SLOT_1 (t));
14771 0 : error_found = true;
14772 : }
14773 :
14774 : /* Check various uses of TYPE_VALUES_RAW. */
14775 924894453 : if (TREE_CODE (t) == ENUMERAL_TYPE)
14776 104069523 : for (tree l = TYPE_VALUES (t); l; l = TREE_CHAIN (l))
14777 : {
14778 90445314 : tree value = TREE_VALUE (l);
14779 90445314 : tree name = TREE_PURPOSE (l);
14780 :
14781 : /* C FE porduce INTEGER_CST of INTEGER_TYPE, while C++ FE uses
14782 : CONST_DECL of ENUMERAL TYPE. */
14783 90445314 : if (TREE_CODE (value) != INTEGER_CST && TREE_CODE (value) != CONST_DECL)
14784 : {
14785 0 : error ("enum value is not %<CONST_DECL%> or %<INTEGER_CST%>");
14786 0 : debug_tree (value);
14787 0 : debug_tree (name);
14788 0 : error_found = true;
14789 : }
14790 90445314 : if (TREE_CODE (TREE_TYPE (value)) != INTEGER_TYPE
14791 90428544 : && TREE_CODE (TREE_TYPE (value)) != BOOLEAN_TYPE
14792 180873855 : && !useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (value)))
14793 : {
14794 0 : error ("enum value type is not %<INTEGER_TYPE%> nor convertible "
14795 : "to the enum");
14796 0 : debug_tree (value);
14797 0 : debug_tree (name);
14798 0 : error_found = true;
14799 : }
14800 90445314 : if (TREE_CODE (name) != IDENTIFIER_NODE)
14801 : {
14802 0 : error ("enum value name is not %<IDENTIFIER_NODE%>");
14803 0 : debug_tree (value);
14804 0 : debug_tree (name);
14805 0 : error_found = true;
14806 : }
14807 : }
14808 911270244 : else if (TREE_CODE (t) == ARRAY_TYPE)
14809 : {
14810 1793094 : if (TYPE_DOMAIN (t) && TREE_CODE (TYPE_DOMAIN (t)) != INTEGER_TYPE)
14811 : {
14812 0 : error ("array %<TYPE_DOMAIN%> is not integer type");
14813 0 : debug_tree (TYPE_DOMAIN (t));
14814 0 : error_found = true;
14815 : }
14816 : }
14817 909477150 : else if (RECORD_OR_UNION_TYPE_P (t))
14818 : {
14819 486441967 : if (TYPE_FIELDS (t) && !COMPLETE_TYPE_P (t) && in_lto_p)
14820 : {
14821 0 : error ("%<TYPE_FIELDS%> defined in incomplete type");
14822 0 : error_found = true;
14823 : }
14824 21045568269 : for (tree fld = TYPE_FIELDS (t); fld; fld = TREE_CHAIN (fld))
14825 : {
14826 : /* TODO: verify properties of decls. */
14827 20559126302 : if (TREE_CODE (fld) == FIELD_DECL)
14828 : ;
14829 : else if (TREE_CODE (fld) == TYPE_DECL)
14830 : ;
14831 : else if (TREE_CODE (fld) == CONST_DECL)
14832 : ;
14833 : else if (VAR_P (fld))
14834 : ;
14835 : else if (TREE_CODE (fld) == TEMPLATE_DECL)
14836 : ;
14837 : else if (TREE_CODE (fld) == USING_DECL)
14838 : ;
14839 : else if (TREE_CODE (fld) == FUNCTION_DECL)
14840 : ;
14841 : else
14842 : {
14843 0 : error ("wrong tree in %<TYPE_FIELDS%> list");
14844 0 : debug_tree (fld);
14845 0 : error_found = true;
14846 : }
14847 : }
14848 : }
14849 423035183 : else if (TREE_CODE (t) == INTEGER_TYPE
14850 : || TREE_CODE (t) == BOOLEAN_TYPE
14851 423035183 : || TREE_CODE (t) == BITINT_TYPE
14852 300774975 : || TREE_CODE (t) == OFFSET_TYPE
14853 300739475 : || TREE_CODE (t) == REFERENCE_TYPE
14854 249313873 : || TREE_CODE (t) == NULLPTR_TYPE
14855 248965359 : || TREE_CODE (t) == POINTER_TYPE)
14856 : {
14857 286740186 : if (TYPE_CACHED_VALUES_P (t) != (TYPE_CACHED_VALUES (t) != NULL))
14858 : {
14859 0 : error ("%<TYPE_CACHED_VALUES_P%> is %i while %<TYPE_CACHED_VALUES%> "
14860 : "is %p",
14861 0 : TYPE_CACHED_VALUES_P (t), (void *)TYPE_CACHED_VALUES (t));
14862 0 : error_found = true;
14863 : }
14864 286740186 : else if (TYPE_CACHED_VALUES_P (t) && TREE_CODE (TYPE_CACHED_VALUES (t)) != TREE_VEC)
14865 : {
14866 0 : error ("%<TYPE_CACHED_VALUES%> is not %<TREE_VEC%>");
14867 0 : debug_tree (TYPE_CACHED_VALUES (t));
14868 0 : error_found = true;
14869 : }
14870 : /* Verify just enough of cache to ensure that no one copied it to new type.
14871 : All copying should go by copy_node that should clear it. */
14872 286740186 : else if (TYPE_CACHED_VALUES_P (t))
14873 : {
14874 : int i;
14875 8533598187 : for (i = 0; i < TREE_VEC_LENGTH (TYPE_CACHED_VALUES (t)); i++)
14876 8466740228 : if (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)
14877 8466740228 : && TREE_TYPE (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i)) != t)
14878 : {
14879 0 : error ("wrong %<TYPE_CACHED_VALUES%> entry");
14880 0 : debug_tree (TREE_VEC_ELT (TYPE_CACHED_VALUES (t), i));
14881 0 : error_found = true;
14882 0 : break;
14883 : }
14884 : }
14885 : }
14886 136294997 : else if (FUNC_OR_METHOD_TYPE_P (t))
14887 3257608 : for (tree l = TYPE_ARG_TYPES (t); l; l = TREE_CHAIN (l))
14888 : {
14889 : /* C++ FE uses TREE_PURPOSE to store initial values. */
14890 2395605 : if (TREE_PURPOSE (l) && in_lto_p)
14891 : {
14892 0 : error ("%<TREE_PURPOSE%> is non-NULL in %<TYPE_ARG_TYPES%> list");
14893 0 : debug_tree (l);
14894 0 : error_found = true;
14895 : }
14896 2395605 : if (!TYPE_P (TREE_VALUE (l)))
14897 : {
14898 0 : error ("wrong entry in %<TYPE_ARG_TYPES%> list");
14899 0 : debug_tree (l);
14900 0 : error_found = true;
14901 : }
14902 : }
14903 270488413 : else if (!is_lang_specific (t) && TYPE_VALUES_RAW (t))
14904 : {
14905 0 : error ("%<TYPE_VALUES_RAW%> field is non-NULL");
14906 0 : debug_tree (TYPE_VALUES_RAW (t));
14907 0 : error_found = true;
14908 : }
14909 924894453 : if (TREE_CODE (t) != INTEGER_TYPE
14910 : && TREE_CODE (t) != BOOLEAN_TYPE
14911 924894453 : && TREE_CODE (t) != BITINT_TYPE
14912 : && TREE_CODE (t) != OFFSET_TYPE
14913 : && TREE_CODE (t) != REFERENCE_TYPE
14914 : && TREE_CODE (t) != NULLPTR_TYPE
14915 : && TREE_CODE (t) != POINTER_TYPE
14916 638154267 : && TYPE_CACHED_VALUES_P (t))
14917 : {
14918 0 : error ("%<TYPE_CACHED_VALUES_P%> is set while it should not be");
14919 0 : error_found = true;
14920 : }
14921 :
14922 : /* ipa-devirt makes an assumption that TYPE_METHOD_BASETYPE is always
14923 : TYPE_MAIN_VARIANT and it would be odd to add methods only to variatns
14924 : of a type. */
14925 924894453 : if (TREE_CODE (t) == METHOD_TYPE
14926 924894453 : && TYPE_MAIN_VARIANT (TYPE_METHOD_BASETYPE (t)) != TYPE_METHOD_BASETYPE (t))
14927 : {
14928 0 : error ("%<TYPE_METHOD_BASETYPE%> is not main variant");
14929 0 : error_found = true;
14930 : }
14931 :
14932 924894453 : if (error_found)
14933 : {
14934 0 : debug_tree (const_cast <tree> (t));
14935 0 : internal_error ("%qs failed", __func__);
14936 : }
14937 : }
14938 :
14939 :
14940 : /* Return 1 if ARG interpreted as signed in its precision is known to be
14941 : always non-negative or 2 if ARG is known to be always negative, or 3 if
14942 : ARG may be non-negative or negative. STMT if specified is the statement
14943 : on which it is being tested. */
14944 :
14945 : int
14946 875277 : get_range_pos_neg (tree arg, gimple *stmt)
14947 : {
14948 875277 : if (arg == error_mark_node || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
14949 : return 3;
14950 :
14951 875277 : int prec = TYPE_PRECISION (TREE_TYPE (arg));
14952 875277 : int cnt = 0;
14953 875277 : if (TREE_CODE (arg) == INTEGER_CST)
14954 : {
14955 69571 : wide_int w = wi::sext (wi::to_wide (arg), prec);
14956 69571 : if (wi::neg_p (w))
14957 : return 2;
14958 : else
14959 55131 : return 1;
14960 69571 : }
14961 804054 : while (CONVERT_EXPR_P (arg)
14962 15350 : && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
14963 834754 : && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg, 0))) <= prec)
14964 : {
14965 14706 : arg = TREE_OPERAND (arg, 0);
14966 : /* Narrower value zero extended into wider type
14967 : will always result in positive values. */
14968 14706 : if (TYPE_UNSIGNED (TREE_TYPE (arg))
14969 14706 : && TYPE_PRECISION (TREE_TYPE (arg)) < prec)
14970 : return 1;
14971 13698 : prec = TYPE_PRECISION (TREE_TYPE (arg));
14972 13698 : if (++cnt > 30)
14973 : return 3;
14974 : }
14975 :
14976 804698 : if (TREE_CODE (arg) != SSA_NAME)
14977 : return 3;
14978 798424 : int_range_max r;
14979 1614157 : while (!get_range_query (cfun)->range_of_expr (r, arg, stmt)
14980 1631466 : || r.undefined_p () || r.varying_p ())
14981 : {
14982 537939 : gimple *g = SSA_NAME_DEF_STMT (arg);
14983 537939 : if (is_gimple_assign (g)
14984 537939 : && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (g)))
14985 : {
14986 29375 : tree t = gimple_assign_rhs1 (g);
14987 58423 : if (INTEGRAL_TYPE_P (TREE_TYPE (t))
14988 55737 : && TYPE_PRECISION (TREE_TYPE (t)) <= prec)
14989 : {
14990 19710 : if (TYPE_UNSIGNED (TREE_TYPE (t))
14991 19710 : && TYPE_PRECISION (TREE_TYPE (t)) < prec)
14992 : return 1;
14993 17309 : prec = TYPE_PRECISION (TREE_TYPE (t));
14994 17309 : arg = t;
14995 17309 : if (++cnt > 30)
14996 : return 3;
14997 17309 : continue;
14998 : }
14999 : }
15000 : return 3;
15001 : }
15002 277794 : if (TYPE_UNSIGNED (TREE_TYPE (arg)))
15003 : {
15004 : /* For unsigned values, the "positive" range comes
15005 : below the "negative" range. */
15006 113457 : if (!wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
15007 : return 1;
15008 32167 : if (wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
15009 822 : return 2;
15010 : }
15011 : else
15012 : {
15013 164337 : if (!wi::neg_p (wi::sext (r.lower_bound (), prec), SIGNED))
15014 : return 1;
15015 66139 : if (wi::neg_p (wi::sext (r.upper_bound (), prec), SIGNED))
15016 1199 : return 2;
15017 : }
15018 : return 3;
15019 798424 : }
15020 :
15021 :
15022 :
15023 :
15024 : /* Return true if ARG is marked with the nonnull attribute in the
15025 : current function signature. */
15026 :
15027 : bool
15028 29860744 : nonnull_arg_p (const_tree arg)
15029 : {
15030 29860744 : tree t, attrs, fntype;
15031 29860744 : unsigned HOST_WIDE_INT arg_num;
15032 :
15033 29860744 : gcc_assert (TREE_CODE (arg) == PARM_DECL
15034 : && (POINTER_TYPE_P (TREE_TYPE (arg))
15035 : || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE));
15036 :
15037 : /* The static chain decl is always non null. */
15038 29860744 : if (arg == cfun->static_chain_decl)
15039 : return true;
15040 :
15041 : /* THIS argument of method is always non-NULL. */
15042 29591640 : if (TREE_CODE (TREE_TYPE (cfun->decl)) == METHOD_TYPE
15043 12128561 : && arg == DECL_ARGUMENTS (cfun->decl)
15044 37460437 : && flag_delete_null_pointer_checks)
15045 : return true;
15046 :
15047 : /* Values passed by reference are always non-NULL. */
15048 21725298 : if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
15049 21725298 : && flag_delete_null_pointer_checks)
15050 : return true;
15051 :
15052 14194679 : fntype = TREE_TYPE (cfun->decl);
15053 14218577 : for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
15054 : {
15055 570127 : attrs = lookup_attribute ("nonnull", attrs);
15056 :
15057 : /* If "nonnull" wasn't specified, we know nothing about the argument. */
15058 570127 : if (attrs == NULL_TREE)
15059 : return false;
15060 :
15061 : /* If "nonnull" applies to all the arguments, then ARG is non-null. */
15062 116203 : if (TREE_VALUE (attrs) == NULL_TREE)
15063 : return true;
15064 :
15065 : /* Get the position number for ARG in the function signature. */
15066 57524 : for (arg_num = 1, t = DECL_ARGUMENTS (cfun->decl);
15067 131909 : t;
15068 74385 : t = DECL_CHAIN (t), arg_num++)
15069 : {
15070 131909 : if (t == arg)
15071 : break;
15072 : }
15073 :
15074 57524 : gcc_assert (t == arg);
15075 :
15076 : /* Now see if ARG_NUM is mentioned in the nonnull list. */
15077 91077 : for (t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
15078 : {
15079 67179 : if (compare_tree_int (TREE_VALUE (t), arg_num) == 0)
15080 : return true;
15081 : }
15082 : }
15083 :
15084 : return false;
15085 : }
15086 :
15087 : /* Combine LOC and BLOCK to a combined adhoc loc, retaining any range
15088 : information. */
15089 :
15090 : location_t
15091 964260905 : set_block (location_t loc, tree block)
15092 : {
15093 964260905 : location_t pure_loc = get_pure_location (loc);
15094 964260905 : source_range src_range = get_range_from_loc (line_table, loc);
15095 964260905 : unsigned discriminator = get_discriminator_from_loc (line_table, loc);
15096 964260905 : return line_table->get_or_create_combined_loc (pure_loc, src_range, block,
15097 964260905 : discriminator);
15098 : }
15099 :
15100 : location_t
15101 228418994 : set_source_range (tree expr, location_t start, location_t finish)
15102 : {
15103 228418994 : source_range src_range;
15104 228418994 : src_range.m_start = start;
15105 228418994 : src_range.m_finish = finish;
15106 228418994 : return set_source_range (expr, src_range);
15107 : }
15108 :
15109 : location_t
15110 465134625 : set_source_range (tree expr, source_range src_range)
15111 : {
15112 465134625 : if (!EXPR_P (expr))
15113 : return UNKNOWN_LOCATION;
15114 :
15115 205456832 : location_t expr_location = EXPR_LOCATION (expr);
15116 205456832 : location_t pure_loc = get_pure_location (expr_location);
15117 205456832 : unsigned discriminator = get_discriminator_from_loc (expr_location);
15118 205456832 : location_t adhoc = line_table->get_or_create_combined_loc (pure_loc,
15119 : src_range,
15120 : nullptr,
15121 : discriminator);
15122 205456832 : SET_EXPR_LOCATION (expr, adhoc);
15123 205456832 : return adhoc;
15124 : }
15125 :
15126 : /* Return EXPR, potentially wrapped with a node expression LOC,
15127 : if !CAN_HAVE_LOCATION_P (expr).
15128 :
15129 : NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
15130 : VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
15131 :
15132 : Wrapper nodes can be identified using location_wrapper_p. */
15133 :
15134 : tree
15135 1624390237 : maybe_wrap_with_location (tree expr, location_t loc)
15136 : {
15137 1624390237 : if (expr == NULL)
15138 : return NULL;
15139 1624390233 : if (loc == UNKNOWN_LOCATION)
15140 : return expr;
15141 1569056345 : if (CAN_HAVE_LOCATION_P (expr))
15142 : return expr;
15143 : /* We should only be adding wrappers for constants and for decls,
15144 : or for some exceptional tree nodes (e.g. BASELINK in the C++ FE). */
15145 960172425 : gcc_assert (CONSTANT_CLASS_P (expr)
15146 : || DECL_P (expr)
15147 : || EXCEPTIONAL_CLASS_P (expr));
15148 :
15149 : /* For now, don't add wrappers to exceptional tree nodes, to minimize
15150 : any impact of the wrapper nodes. */
15151 960172425 : if (EXCEPTIONAL_CLASS_P (expr) || error_operand_p (expr))
15152 : return expr;
15153 :
15154 : /* Compiler-generated temporary variables don't need a wrapper. */
15155 885205376 : if (DECL_P (expr) && DECL_ARTIFICIAL (expr) && DECL_IGNORED_P (expr))
15156 : return expr;
15157 :
15158 : /* If any auto_suppress_location_wrappers are active, don't create
15159 : wrappers. */
15160 885202878 : if (suppress_location_wrappers > 0)
15161 : return expr;
15162 :
15163 1655087818 : tree_code code
15164 217026973 : = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
15165 619504972 : || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
15166 827543909 : ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
15167 827543909 : tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
15168 : /* Mark this node as being a wrapper. */
15169 827543909 : EXPR_LOCATION_WRAPPER_P (wrapper) = 1;
15170 827543909 : return wrapper;
15171 : }
15172 :
15173 : int suppress_location_wrappers;
15174 :
15175 : /* Return the name of combined function FN, for debugging purposes. */
15176 :
15177 : const char *
15178 0 : combined_fn_name (combined_fn fn)
15179 : {
15180 0 : if (builtin_fn_p (fn))
15181 : {
15182 0 : tree fndecl = builtin_decl_explicit (as_builtin_fn (fn));
15183 0 : return IDENTIFIER_POINTER (DECL_NAME (fndecl));
15184 : }
15185 : else
15186 0 : return internal_fn_name (as_internal_fn (fn));
15187 : }
15188 :
15189 : /* Return a bitmap with a bit set corresponding to each argument in
15190 : a function call type FNTYPE declared with attribute nonnull,
15191 : or null if none of the function's argument are nonnull. The caller
15192 : must free the bitmap. */
15193 :
15194 : bitmap
15195 22388326 : get_nonnull_args (const_tree fntype)
15196 : {
15197 22388326 : if (fntype == NULL_TREE)
15198 : return NULL;
15199 :
15200 21728387 : bitmap argmap = NULL;
15201 21728387 : if (TREE_CODE (fntype) == METHOD_TYPE)
15202 : {
15203 : /* The this pointer in C++ non-static member functions is
15204 : implicitly nonnull whether or not it's declared as such. */
15205 2997816 : argmap = BITMAP_ALLOC (NULL);
15206 2997816 : bitmap_set_bit (argmap, 0);
15207 : }
15208 :
15209 21728387 : tree attrs = TYPE_ATTRIBUTES (fntype);
15210 21728387 : if (!attrs)
15211 : return argmap;
15212 :
15213 : /* A function declaration can specify multiple attribute nonnull,
15214 : each with zero or more arguments. The loop below creates a bitmap
15215 : representing a union of all the arguments. An empty (but non-null)
15216 : bitmap means that all arguments have been declared nonnull. */
15217 6075301 : for ( ; attrs; attrs = TREE_CHAIN (attrs))
15218 : {
15219 5964293 : attrs = lookup_attribute ("nonnull", attrs);
15220 5964293 : if (!attrs)
15221 : break;
15222 :
15223 1433592 : if (!argmap)
15224 1395291 : argmap = BITMAP_ALLOC (NULL);
15225 :
15226 1433592 : if (!TREE_VALUE (attrs))
15227 : {
15228 : /* Clear the bitmap in case a previous attribute nonnull
15229 : set it and this one overrides it for all arguments. */
15230 786322 : bitmap_clear (argmap);
15231 786322 : return argmap;
15232 : }
15233 :
15234 : /* Iterate over the indices of the format arguments declared nonnull
15235 : and set a bit for each. */
15236 1696857 : for (tree idx = TREE_VALUE (attrs); idx; idx = TREE_CHAIN (idx))
15237 : {
15238 1049587 : unsigned int val = TREE_INT_CST_LOW (TREE_VALUE (idx)) - 1;
15239 1049587 : bitmap_set_bit (argmap, val);
15240 : }
15241 : }
15242 :
15243 : return argmap;
15244 : }
15245 :
15246 : /* Returns true if TYPE is a type where it and all of its subobjects
15247 : (recursively) are of structure, union, or array type. */
15248 :
15249 : bool
15250 2037443636 : is_empty_type (const_tree type)
15251 : {
15252 2037443636 : if (RECORD_OR_UNION_TYPE_P (type))
15253 : {
15254 894883838 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
15255 821503940 : if (TREE_CODE (field) == FIELD_DECL
15256 405760169 : && !DECL_PADDING_P (field)
15257 1227262759 : && !is_empty_type (TREE_TYPE (field)))
15258 : return false;
15259 : return true;
15260 : }
15261 1586871728 : else if (TREE_CODE (type) == ARRAY_TYPE)
15262 89534544 : return (integer_minus_onep (array_type_nelts_minus_one (type))
15263 89490338 : || TYPE_DOMAIN (type) == NULL_TREE
15264 168739366 : || is_empty_type (TREE_TYPE (type)));
15265 : return false;
15266 : }
15267 :
15268 : /* Implement TARGET_EMPTY_RECORD_P. Return true if TYPE is an empty type
15269 : that shouldn't be passed via stack. */
15270 :
15271 : bool
15272 1500012931 : default_is_empty_record (const_tree type)
15273 : {
15274 1500012931 : if (!abi_version_at_least (12))
15275 : return false;
15276 :
15277 1498949989 : if (type == error_mark_node)
15278 : return false;
15279 :
15280 1498949989 : if (TREE_ADDRESSABLE (type))
15281 : return false;
15282 :
15283 1498949989 : return is_empty_type (TYPE_MAIN_VARIANT (type));
15284 : }
15285 :
15286 :
15287 : /* Determine whether TYPE is an ISO C99 flexible array member type "[]". */
15288 :
15289 : bool
15290 11836417 : flexible_array_member_type_p (const_tree type)
15291 : {
15292 11836417 : if (TREE_CODE (type) == ARRAY_TYPE
15293 4945740 : && TYPE_SIZE (type) == NULL_TREE
15294 649287 : && TYPE_DOMAIN (type) != NULL_TREE
15295 12395823 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
15296 559406 : return true;
15297 :
15298 : return false;
15299 : }
15300 :
15301 :
15302 : /* Determine whether TYPE is a structure with a flexible array member,
15303 : or a union containing such a structure (possibly recursively). */
15304 :
15305 : bool
15306 72579 : flexible_array_type_p (const_tree type)
15307 : {
15308 72579 : tree x, last;
15309 72579 : switch (TREE_CODE (type))
15310 : {
15311 38277 : case RECORD_TYPE:
15312 38277 : last = NULL_TREE;
15313 174119 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15314 135842 : if (TREE_CODE (x) == FIELD_DECL)
15315 135842 : last = x;
15316 38277 : if (last == NULL_TREE)
15317 : return false;
15318 38269 : return flexible_array_member_type_p (TREE_TYPE (last));
15319 579 : case UNION_TYPE:
15320 1668 : for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
15321 : {
15322 1131 : if (TREE_CODE (x) == FIELD_DECL
15323 1131 : && flexible_array_type_p (TREE_TYPE (x)))
15324 : return true;
15325 : }
15326 : return false;
15327 : default:
15328 : return false;
15329 : }
15330 : }
15331 :
15332 : /* Like int_size_in_bytes, but handle empty records specially. */
15333 :
15334 : HOST_WIDE_INT
15335 464864 : arg_int_size_in_bytes (const_tree type)
15336 : {
15337 464864 : return TYPE_EMPTY_P (type) ? 0 : int_size_in_bytes (type);
15338 : }
15339 :
15340 : /* Like size_in_bytes, but handle empty records specially. */
15341 :
15342 : tree
15343 5732603 : arg_size_in_bytes (const_tree type)
15344 : {
15345 5732603 : return TYPE_EMPTY_P (type) ? size_zero_node : size_in_bytes (type);
15346 : }
15347 :
15348 : /* Return true if an expression with CODE has to have the same result type as
15349 : its first operand. */
15350 :
15351 : bool
15352 0 : expr_type_first_operand_type_p (tree_code code)
15353 : {
15354 0 : switch (code)
15355 : {
15356 : case NEGATE_EXPR:
15357 : case ABS_EXPR:
15358 : case BIT_NOT_EXPR:
15359 : case PAREN_EXPR:
15360 : case CONJ_EXPR:
15361 :
15362 : case PLUS_EXPR:
15363 : case MINUS_EXPR:
15364 : case MULT_EXPR:
15365 : case TRUNC_DIV_EXPR:
15366 : case CEIL_DIV_EXPR:
15367 : case FLOOR_DIV_EXPR:
15368 : case ROUND_DIV_EXPR:
15369 : case TRUNC_MOD_EXPR:
15370 : case CEIL_MOD_EXPR:
15371 : case FLOOR_MOD_EXPR:
15372 : case ROUND_MOD_EXPR:
15373 : case RDIV_EXPR:
15374 : case EXACT_DIV_EXPR:
15375 : case MIN_EXPR:
15376 : case MAX_EXPR:
15377 : case BIT_IOR_EXPR:
15378 : case BIT_XOR_EXPR:
15379 : case BIT_AND_EXPR:
15380 :
15381 : case LSHIFT_EXPR:
15382 : case RSHIFT_EXPR:
15383 : case LROTATE_EXPR:
15384 : case RROTATE_EXPR:
15385 : return true;
15386 :
15387 0 : default:
15388 0 : return false;
15389 : }
15390 : }
15391 :
15392 : /* Return a typenode for the "standard" C type with a given name. */
15393 : tree
15394 943012 : get_typenode_from_name (const char *name)
15395 : {
15396 943012 : if (name == NULL || *name == '\0')
15397 : return NULL_TREE;
15398 :
15399 943012 : if (strcmp (name, "char") == 0)
15400 0 : return char_type_node;
15401 943012 : if (strcmp (name, "unsigned char") == 0)
15402 97365 : return unsigned_char_type_node;
15403 845647 : if (strcmp (name, "signed char") == 0)
15404 97365 : return signed_char_type_node;
15405 :
15406 748282 : if (strcmp (name, "short int") == 0)
15407 66427 : return short_integer_type_node;
15408 681855 : if (strcmp (name, "short unsigned int") == 0)
15409 64910 : return short_unsigned_type_node;
15410 :
15411 616945 : if (strcmp (name, "int") == 0)
15412 67255 : return integer_type_node;
15413 549690 : if (strcmp (name, "unsigned int") == 0)
15414 65728 : return unsigned_type_node;
15415 :
15416 483962 : if (strcmp (name, "long int") == 0)
15417 288414 : return long_integer_type_node;
15418 195548 : if (strcmp (name, "long unsigned int") == 0)
15419 192276 : return long_unsigned_type_node;
15420 :
15421 3272 : if (strcmp (name, "long long int") == 0)
15422 1636 : return long_long_integer_type_node;
15423 1636 : if (strcmp (name, "long long unsigned int") == 0)
15424 1636 : return long_long_unsigned_type_node;
15425 :
15426 0 : gcc_unreachable ();
15427 : }
15428 :
15429 : /* List of pointer types used to declare builtins before we have seen their
15430 : real declaration.
15431 :
15432 : Keep the size up to date in tree.h ! */
15433 : const builtin_structptr_type builtin_structptr_types[6] =
15434 : {
15435 : { fileptr_type_node, ptr_type_node, "FILE" },
15436 : { const_tm_ptr_type_node, const_ptr_type_node, "tm" },
15437 : { fenv_t_ptr_type_node, ptr_type_node, "fenv_t" },
15438 : { const_fenv_t_ptr_type_node, const_ptr_type_node, "fenv_t" },
15439 : { fexcept_t_ptr_type_node, ptr_type_node, "fexcept_t" },
15440 : { const_fexcept_t_ptr_type_node, const_ptr_type_node, "fexcept_t" }
15441 : };
15442 :
15443 : /* Return the maximum object size. */
15444 :
15445 : tree
15446 7680633 : max_object_size (void)
15447 : {
15448 : /* To do: Make this a configurable parameter. */
15449 7680633 : return TYPE_MAX_VALUE (ptrdiff_type_node);
15450 : }
15451 :
15452 : /* A wrapper around TARGET_VERIFY_TYPE_CONTEXT that makes the silent_p
15453 : parameter default to false and that weeds out error_mark_node. */
15454 :
15455 : bool
15456 157414614 : verify_type_context (location_t loc, type_context_kind context,
15457 : const_tree type, bool silent_p)
15458 : {
15459 157414614 : if (type == error_mark_node)
15460 : return true;
15461 :
15462 157414518 : gcc_assert (TYPE_P (type));
15463 157414518 : return (!targetm.verify_type_context
15464 157414518 : || targetm.verify_type_context (loc, context, type, silent_p));
15465 : }
15466 :
15467 : /* Callback of walk_tree telling whether the current tree pointed by TP is the
15468 : one provided as DATA. */
15469 :
15470 : static tree
15471 4739 : find_tree_1 (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, void *data)
15472 : {
15473 4739 : if (*tp == data)
15474 : return (tree) data;
15475 : else
15476 4667 : return NULL;
15477 : }
15478 :
15479 : /* Return whether SEARCH is a subtree of TOP. */
15480 :
15481 : bool
15482 3863 : find_tree (tree top, tree search)
15483 : {
15484 3863 : return walk_tree_without_duplicates (&top, find_tree_1, search) != 0;
15485 : }
15486 :
15487 : /* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and
15488 : delete operators. Return false if they may or may not name such
15489 : a pair and, when nonnull, set *PCERTAIN to true if they certainly
15490 : do not. */
15491 :
15492 : bool
15493 70563 : valid_new_delete_pair_p (tree new_asm, tree delete_asm,
15494 : bool *pcertain /* = NULL */)
15495 : {
15496 70563 : bool certain;
15497 70563 : if (!pcertain)
15498 57522 : pcertain = &certain;
15499 :
15500 70563 : const char *new_name = IDENTIFIER_POINTER (new_asm);
15501 70563 : const char *delete_name = IDENTIFIER_POINTER (delete_asm);
15502 70563 : unsigned int new_len = IDENTIFIER_LENGTH (new_asm);
15503 70563 : unsigned int delete_len = IDENTIFIER_LENGTH (delete_asm);
15504 :
15505 : /* The following failures are due to invalid names so they're not
15506 : considered certain mismatches. */
15507 70563 : *pcertain = false;
15508 :
15509 70563 : if (new_len < 5 || delete_len < 6)
15510 : return false;
15511 70563 : if (new_name[0] == '_')
15512 70491 : ++new_name, --new_len;
15513 70563 : if (new_name[0] == '_')
15514 0 : ++new_name, --new_len;
15515 70563 : if (delete_name[0] == '_')
15516 70563 : ++delete_name, --delete_len;
15517 70563 : if (delete_name[0] == '_')
15518 0 : ++delete_name, --delete_len;
15519 70563 : if (new_len < 4 || delete_len < 5)
15520 : return false;
15521 :
15522 : /* The following failures are due to names of user-defined operators
15523 : so they're also not considered certain mismatches. */
15524 :
15525 : /* *_len is now just the length after initial underscores. */
15526 70563 : if (new_name[0] != 'Z' || new_name[1] != 'n')
15527 : return false;
15528 69878 : if (delete_name[0] != 'Z' || delete_name[1] != 'd')
15529 : return false;
15530 :
15531 : /* The following failures are certain mismatches. */
15532 69802 : *pcertain = true;
15533 :
15534 : /* _Znw must match _Zdl, _Zna must match _Zda. */
15535 69802 : if ((new_name[2] != 'w' || delete_name[2] != 'l')
15536 5069 : && (new_name[2] != 'a' || delete_name[2] != 'a'))
15537 : return false;
15538 69706 : if (new_name[3] == 'I' || delete_name[3] == 'I')
15539 : {
15540 : /* When ::operator new or ::operator delete are function templates,
15541 : return uncertain mismatch, we need demangler in that case. */
15542 24 : *pcertain = false;
15543 24 : return false;
15544 : }
15545 : /* 'j', 'm' and 'y' correspond to size_t. */
15546 69682 : if (new_name[3] != 'j' && new_name[3] != 'm' && new_name[3] != 'y')
15547 : return false;
15548 69682 : if (delete_name[3] != 'P' || delete_name[4] != 'v')
15549 : return false;
15550 69682 : if (new_len == 4
15551 472 : || (new_len == 18 && !memcmp (new_name + 4, "RKSt9nothrow_t", 14)))
15552 : {
15553 : /* _ZnXY or _ZnXYRKSt9nothrow_t matches
15554 : _ZdXPv, _ZdXPvY and _ZdXPvRKSt9nothrow_t. */
15555 69378 : if (delete_len == 5)
15556 : return true;
15557 62746 : if (delete_len == 6 && delete_name[5] == new_name[3])
15558 : return true;
15559 39 : if (delete_len == 19 && !memcmp (delete_name + 5, "RKSt9nothrow_t", 14))
15560 : return true;
15561 : }
15562 304 : else if ((new_len == 19 && !memcmp (new_name + 4, "St11align_val_t", 15))
15563 54 : || (new_len == 33
15564 10 : && !memcmp (new_name + 4, "St11align_val_tRKSt9nothrow_t", 29)))
15565 : {
15566 : /* _ZnXYSt11align_val_t or _ZnXYSt11align_val_tRKSt9nothrow_t matches
15567 : _ZdXPvSt11align_val_t or _ZdXPvYSt11align_val_t or
15568 : _ZdXPvSt11align_val_tRKSt9nothrow_t. */
15569 260 : if (delete_len == 20 && !memcmp (delete_name + 5, "St11align_val_t", 15))
15570 : return true;
15571 144 : if (delete_len == 21
15572 129 : && delete_name[5] == new_name[3]
15573 129 : && !memcmp (delete_name + 6, "St11align_val_t", 15))
15574 : return true;
15575 15 : if (delete_len == 34
15576 9 : && !memcmp (delete_name + 5, "St11align_val_tRKSt9nothrow_t", 29))
15577 : return true;
15578 : }
15579 :
15580 : /* The negative result is conservative. */
15581 50 : *pcertain = false;
15582 50 : return false;
15583 : }
15584 :
15585 : /* Return the zero-based number corresponding to the argument being
15586 : deallocated if FNDECL is a deallocation function or an out-of-bounds
15587 : value if it isn't. */
15588 :
15589 : unsigned
15590 23679222 : fndecl_dealloc_argno (tree fndecl)
15591 : {
15592 : /* A call to operator delete isn't recognized as one to a built-in. */
15593 23679222 : if (DECL_IS_OPERATOR_DELETE_P (fndecl))
15594 : {
15595 368901 : if (DECL_IS_REPLACEABLE_OPERATOR (fndecl))
15596 : return 0;
15597 :
15598 : /* Avoid placement delete that's not been inlined. */
15599 27282 : tree fname = DECL_ASSEMBLER_NAME (fndecl);
15600 27282 : if (id_equal (fname, "_ZdlPvS_") // ordinary form
15601 27282 : || id_equal (fname, "_ZdaPvS_")) // array form
15602 24528 : return UINT_MAX;
15603 : return 0;
15604 : }
15605 :
15606 : /* TODO: Handle user-defined functions with attribute malloc? Handle
15607 : known non-built-ins like fopen? */
15608 23310321 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
15609 : {
15610 5681423 : switch (DECL_FUNCTION_CODE (fndecl))
15611 : {
15612 : case BUILT_IN_FREE:
15613 : case BUILT_IN_REALLOC:
15614 : case BUILT_IN_GOMP_FREE:
15615 : case BUILT_IN_GOMP_REALLOC:
15616 : return 0;
15617 5454952 : default:
15618 5454952 : break;
15619 : }
15620 5454952 : return UINT_MAX;
15621 : }
15622 :
15623 17628898 : tree attrs = DECL_ATTRIBUTES (fndecl);
15624 17628898 : if (!attrs)
15625 : return UINT_MAX;
15626 :
15627 0 : for (tree atfree = attrs;
15628 4076160 : (atfree = lookup_attribute ("*dealloc", atfree));
15629 0 : atfree = TREE_CHAIN (atfree))
15630 : {
15631 4950 : tree alloc = TREE_VALUE (atfree);
15632 4950 : if (!alloc)
15633 0 : continue;
15634 :
15635 4950 : tree pos = TREE_CHAIN (alloc);
15636 4950 : if (!pos)
15637 : return 0;
15638 :
15639 2763 : pos = TREE_VALUE (pos);
15640 2763 : return TREE_INT_CST_LOW (pos) - 1;
15641 : }
15642 :
15643 : return UINT_MAX;
15644 : }
15645 :
15646 : /* If EXPR refers to a character array or pointer declared attribute
15647 : nonstring, return a decl for that array or pointer and set *REF
15648 : to the referenced enclosing object or pointer. Otherwise return
15649 : null. */
15650 :
15651 : tree
15652 1400817 : get_attr_nonstring_decl (tree expr, tree *ref)
15653 : {
15654 1406525 : tree decl = expr;
15655 1406525 : tree var = NULL_TREE;
15656 1406525 : if (TREE_CODE (decl) == SSA_NAME)
15657 : {
15658 836374 : gimple *def = SSA_NAME_DEF_STMT (decl);
15659 :
15660 836374 : if (is_gimple_assign (def))
15661 : {
15662 44508 : tree_code code = gimple_assign_rhs_code (def);
15663 44508 : if (code == ADDR_EXPR
15664 44508 : || code == COMPONENT_REF
15665 29532 : || code == VAR_DECL)
15666 19471 : decl = gimple_assign_rhs1 (def);
15667 : }
15668 : else
15669 791866 : var = SSA_NAME_VAR (decl);
15670 : }
15671 :
15672 1406525 : if (TREE_CODE (decl) == ADDR_EXPR)
15673 25968 : decl = TREE_OPERAND (decl, 0);
15674 :
15675 : /* To simplify calling code, store the referenced DECL regardless of
15676 : the attribute determined below, but avoid storing the SSA_NAME_VAR
15677 : obtained above (it's not useful for dataflow purposes). */
15678 1406525 : if (ref)
15679 5463 : *ref = decl;
15680 :
15681 : /* Use the SSA_NAME_VAR that was determined above to see if it's
15682 : declared nonstring. Otherwise drill down into the referenced
15683 : DECL. */
15684 1406525 : if (var)
15685 : decl = var;
15686 : else
15687 : {
15688 639617 : while (TREE_CODE (decl) == ARRAY_REF)
15689 18655 : decl = TREE_OPERAND (decl, 0);
15690 620962 : if (TREE_CODE (decl) == COMPONENT_REF)
15691 16749 : decl = TREE_OPERAND (decl, 1);
15692 604213 : else if (TREE_CODE (decl) == MEM_REF)
15693 5708 : return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref);
15694 : }
15695 :
15696 1400817 : if (DECL_P (decl) && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl)))
15697 7921 : return decl;
15698 :
15699 : return NULL_TREE;
15700 : }
15701 :
15702 : /* Returns an auto_vec of string_slices containing the version strings from
15703 : ARGLIST. DEFAULT_COUNT is incremented for each default version found.
15704 : If FILTER is true then any invalid versions strings are not included. */
15705 :
15706 : auto_vec<string_slice>
15707 212 : get_clone_attr_versions (const tree arglist,
15708 : int *default_count,
15709 : bool filter)
15710 : {
15711 212 : gcc_assert (TREE_CODE (arglist) == TREE_LIST);
15712 212 : auto_vec<string_slice> versions;
15713 :
15714 212 : static const char separator_str[] = {TARGET_CLONES_ATTR_SEPARATOR, 0};
15715 212 : string_slice separators = string_slice (separator_str);
15716 :
15717 776 : for (tree arg = arglist; arg; arg = TREE_CHAIN (arg))
15718 : {
15719 564 : string_slice str = string_slice (TREE_STRING_POINTER (TREE_VALUE (arg)));
15720 1720 : while (str.is_valid ())
15721 : {
15722 592 : string_slice attr = string_slice::tokenize (&str, separators);
15723 592 : attr = attr.strip ();
15724 :
15725 592 : if (filter && !targetm.check_target_clone_version (attr, NULL))
15726 0 : continue;
15727 :
15728 592 : if (attr == "default" && default_count)
15729 210 : (*default_count)++;
15730 592 : versions.safe_push (attr);
15731 : }
15732 : }
15733 212 : return versions;
15734 : }
15735 :
15736 : /* Returns an auto_vec of string_slices containing the version strings from
15737 : the target_clone attribute from DECL. DEFAULT_COUNT is incremented for each
15738 : default version found. If FILTER is true then any invalid versions strings
15739 : are not included. */
15740 : auto_vec<string_slice>
15741 99 : get_clone_versions (const tree decl, int *default_count, bool filter)
15742 : {
15743 99 : tree attr = lookup_attribute ("target_clones", DECL_ATTRIBUTES (decl));
15744 99 : if (!attr)
15745 0 : return auto_vec<string_slice> ();
15746 99 : tree arglist = TREE_VALUE (attr);
15747 99 : return get_clone_attr_versions (arglist, default_count, filter);
15748 : }
15749 :
15750 : /* If DECL has a target_version attribute, returns a string_slice containing the
15751 : attribute value. Otherwise, returns string_slice::invalid.
15752 : Only works for target_version due to target attributes allowing multiple
15753 : string arguments to specify one target. */
15754 : string_slice
15755 0 : get_target_version (const tree decl)
15756 : {
15757 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15758 :
15759 : tree attr = lookup_attribute ("target_version", DECL_ATTRIBUTES (decl));
15760 :
15761 : if (!attr)
15762 : return string_slice::invalid ();
15763 :
15764 : return string_slice (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))))
15765 : .strip ();
15766 : }
15767 :
15768 : /* Returns true if FN1 and FN2 define disjoint function versions in an FMV
15769 : function set. That is, the two declarations are completely non-overlapping.
15770 : For target_version semantics, that means if one is a target clone and one is
15771 : a target version, the target_version must not be defined by the target_clone,
15772 : and for two target_clones, they must not define any of the same version.
15773 :
15774 : FN1 and FN2 should be function decls. */
15775 :
15776 : bool
15777 31383562 : disjoint_version_decls (tree fn1, tree fn2)
15778 : {
15779 31383562 : if (TREE_CODE (fn1) != FUNCTION_DECL
15780 31382318 : || TREE_CODE (fn2) != FUNCTION_DECL)
15781 : return false;
15782 :
15783 29040862 : if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
15784 : {
15785 29040862 : tree attr1 = lookup_attribute ("target", DECL_ATTRIBUTES (fn1));
15786 29040862 : tree attr2 = lookup_attribute ("target", DECL_ATTRIBUTES (fn2));
15787 :
15788 : /* At least one function decl should have the target attribute
15789 : specified. */
15790 29040862 : if (attr1 == NULL_TREE && attr2 == NULL_TREE)
15791 : return false;
15792 :
15793 : /* Diagnose missing target attribute if one of the decls is already
15794 : multi-versioned. */
15795 18867 : if (attr1 == NULL_TREE || attr2 == NULL_TREE)
15796 : {
15797 363 : if (DECL_FUNCTION_VERSIONED (fn1) || DECL_FUNCTION_VERSIONED (fn2))
15798 : {
15799 114 : if (attr2 != NULL_TREE)
15800 : {
15801 114 : std::swap (fn1, fn2);
15802 114 : attr1 = attr2;
15803 : }
15804 114 : auto_diagnostic_group d;
15805 114 : error_at (DECL_SOURCE_LOCATION (fn2),
15806 : "missing %<target%> attribute for multi-versioned %qD",
15807 : fn2);
15808 114 : inform (DECL_SOURCE_LOCATION (fn1),
15809 : "previous declaration of %qD", fn1);
15810 : /* Prevent diagnosing of the same error multiple times. */
15811 114 : DECL_ATTRIBUTES (fn2)
15812 228 : = tree_cons (get_identifier ("target"),
15813 114 : copy_node (TREE_VALUE (attr1)),
15814 114 : DECL_ATTRIBUTES (fn2));
15815 114 : }
15816 : return false;
15817 : }
15818 :
15819 18504 : char *target1 = sorted_attr_string (TREE_VALUE (attr1));
15820 18504 : char *target2 = sorted_attr_string (TREE_VALUE (attr2));
15821 :
15822 : /* The sorted target strings must be different for fn1 and fn2
15823 : to be versions. */
15824 18504 : bool result = strcmp (target1, target2) != 0;
15825 :
15826 18504 : XDELETEVEC (target1);
15827 18504 : XDELETEVEC (target2);
15828 :
15829 18504 : return result;
15830 : }
15831 : else
15832 : {
15833 : /* As this is symmetric, can remove the case where fn2 is target clone
15834 : and fn1 is target version by swapping here. */
15835 : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn2)))
15836 : std::swap (fn1, fn2);
15837 :
15838 : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn1)))
15839 : {
15840 : auto_vec<string_slice> fn1_versions = get_clone_versions (fn1);
15841 : /* fn1 is target_clone. */
15842 : if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (fn2)))
15843 : {
15844 : /* Both are target_clone. */
15845 : auto_vec<string_slice> fn2_versions = get_clone_versions (fn2);
15846 : for (string_slice v1 : fn1_versions)
15847 : {
15848 : for (string_slice v2 : fn2_versions)
15849 : if (targetm.target_option.same_function_versions
15850 : (v1, NULL_TREE, v2, NULL_TREE))
15851 : return false;
15852 : }
15853 : return true;
15854 : }
15855 : else
15856 : {
15857 : string_slice v2 = get_target_version (fn2);
15858 :
15859 : /* target and target_clones is always conflicting for target
15860 : semantics. */
15861 : if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
15862 : return false;
15863 :
15864 : /* Only fn1 is target clone. */
15865 : if (!v2.is_valid ())
15866 : v2 = "default";
15867 : for (string_slice v1 : fn1_versions)
15868 : if (targetm.target_option.same_function_versions
15869 : (v1, NULL_TREE, v2, NULL_TREE))
15870 : return false;
15871 : return true;
15872 : }
15873 : }
15874 : else
15875 : {
15876 : /* Both are target_version. */
15877 : string_slice v1 = get_target_version (fn1);
15878 : string_slice v2 = get_target_version (fn2);
15879 :
15880 : if (!v1.is_valid () && !v2.is_valid ())
15881 : return false;
15882 :
15883 : if (!v1.is_valid ())
15884 : v1 = "default";
15885 : if (!v2.is_valid ())
15886 : v2 = "default";
15887 :
15888 : if (targetm.target_option.same_function_versions (v1, NULL_TREE,
15889 : v2, NULL_TREE))
15890 : return false;
15891 :
15892 : return true;
15893 : }
15894 : }
15895 : }
15896 :
15897 : /* Check if the target_version/target_clones attributes are mergeable
15898 : for two decls, and if so returns false.
15899 : If they aren't mergeable, diagnose this and return true.
15900 : Only works for target_version semantics. */
15901 : bool
15902 0 : diagnose_versioned_decls (tree old_decl, tree new_decl)
15903 : {
15904 0 : gcc_assert (!TARGET_HAS_FMV_TARGET_ATTRIBUTE);
15905 :
15906 : string_slice old_target_attr = get_target_version (old_decl);
15907 : string_slice new_target_attr = get_target_version (new_decl);
15908 :
15909 : tree old_target_clones_attr = lookup_attribute ("target_clones",
15910 : DECL_ATTRIBUTES (old_decl));
15911 : tree new_target_clones_attr = lookup_attribute ("target_clones",
15912 : DECL_ATTRIBUTES (new_decl));
15913 :
15914 : /* If none of these are annotated, then it is mergeable. */
15915 : if (!old_target_attr.is_valid ()
15916 : && !old_target_attr.is_valid ()
15917 : && !old_target_clones_attr
15918 : && !new_target_clones_attr)
15919 : return false;
15920 :
15921 : /* If fn1 is unnanotated and fn2 contains default, then is mergeable. */
15922 : if (!old_target_attr.is_valid ()
15923 : && !old_target_clones_attr
15924 : && is_function_default_version (new_decl))
15925 : return false;
15926 :
15927 : /* If fn2 is unnanotated and fn1 contains default, then is mergeable. */
15928 : if (!new_target_attr.is_valid ()
15929 : && !new_target_clones_attr
15930 : && is_function_default_version (old_decl))
15931 : return false;
15932 :
15933 : /* In the case where both are annotated with target_clones, only mergeable if
15934 : the two sets of target_clones imply the same set of versions. */
15935 : if (old_target_clones_attr && new_target_clones_attr)
15936 : {
15937 : auto_vec<string_slice> old_versions = get_clone_versions (old_decl);
15938 : auto_vec<string_slice> new_versions = get_clone_versions (new_decl);
15939 :
15940 : bool mergeable = true;
15941 :
15942 : if (old_versions.length () != new_versions.length ())
15943 : mergeable = false;
15944 :
15945 : /* Check both inclusion directions. */
15946 : for (auto oldv: old_versions)
15947 : {
15948 : bool matched = false;
15949 : for (auto newv: new_versions)
15950 : if (targetm.target_option.same_function_versions (oldv, old_decl,
15951 : newv, new_decl))
15952 : matched = true;
15953 : if (!matched)
15954 : mergeable = false;
15955 : }
15956 :
15957 : for (auto newv: new_versions)
15958 : {
15959 : bool matched = false;
15960 : for (auto oldv: old_versions)
15961 : if (targetm.target_option.same_function_versions (oldv, old_decl,
15962 : newv, new_decl))
15963 : matched = true;
15964 : if (!matched)
15965 : mergeable = false;
15966 : }
15967 :
15968 : if (!mergeable)
15969 : {
15970 : error_at (DECL_SOURCE_LOCATION (new_decl),
15971 : "%qD conflicts with overlapping %<target_clone%> "
15972 : "declaration",
15973 : new_decl);
15974 : inform (DECL_SOURCE_LOCATION (old_decl),
15975 : "previous declaration of %qD", old_decl);
15976 : return true;
15977 : }
15978 :
15979 : return false;
15980 : }
15981 :
15982 : /* If olddecl is target clones and newdecl is a target_version.
15983 : As they are not distinct this implies newdecl redefines a version of
15984 : olddecl. Not mergeable. */
15985 : if (new_target_clones_attr)
15986 : {
15987 : gcc_assert (old_target_attr.is_valid ());
15988 :
15989 : error_at (DECL_SOURCE_LOCATION (new_decl),
15990 : "%qD conflicts for version %qB",
15991 : new_decl, &old_target_attr);
15992 : inform (DECL_SOURCE_LOCATION (old_decl),
15993 : "previous declaration of %qD",
15994 : old_decl);
15995 : return true;
15996 : }
15997 :
15998 : if (old_target_clones_attr)
15999 : {
16000 : gcc_assert (new_target_attr.is_valid ());
16001 :
16002 : error_at (DECL_SOURCE_LOCATION (new_decl),
16003 : "%qD conflicts with a previous declaration for version %qB",
16004 : new_decl, &new_target_attr);
16005 : inform (DECL_SOURCE_LOCATION (old_decl),
16006 : "previous declaration of %qD",
16007 : old_decl);
16008 : return true;
16009 : }
16010 :
16011 : /* The only remaining case is two target_version annotated decls. */
16012 : return !targetm.target_option.same_function_versions
16013 : (old_target_attr, old_decl, new_target_attr, new_decl);
16014 : }
16015 :
16016 :
16017 : /* This page contains routines to unshare tree nodes, i.e. to duplicate tree
16018 : nodes that are referenced more than once in GENERIC functions. This is
16019 : necessary because gimplification (translation into GIMPLE) is performed
16020 : by modifying tree nodes in-place, so gimplification of a shared node in a
16021 : first context could generate an invalid GIMPLE form in a second context.
16022 :
16023 : This is achieved with a simple mark/copy/unmark algorithm that walks the
16024 : GENERIC representation top-down, marks nodes with TREE_VISITED the first
16025 : time it encounters them, duplicates them if they already have TREE_VISITED
16026 : set, and finally removes the TREE_VISITED marks it has set.
16027 :
16028 : The algorithm works only at the function level, i.e. it generates a GENERIC
16029 : representation of a function with no nodes shared within the function when
16030 : passed a GENERIC function (except for nodes that are allowed to be shared).
16031 :
16032 : At the global level, it is also necessary to unshare tree nodes that are
16033 : referenced in more than one function, for the same aforementioned reason.
16034 : This requires some cooperation from the front-end. There are 2 strategies:
16035 :
16036 : 1. Manual unsharing. The front-end needs to call unshare_expr on every
16037 : expression that might end up being shared across functions.
16038 :
16039 : 2. Deep unsharing. This is an extension of regular unsharing. Instead
16040 : of calling unshare_expr on expressions that might be shared across
16041 : functions, the front-end pre-marks them with TREE_VISITED. This will
16042 : ensure that they are unshared on the first reference within functions
16043 : when the regular unsharing algorithm runs. The counterpart is that
16044 : this algorithm must look deeper than for manual unsharing, which is
16045 : specified by LANG_HOOKS_DEEP_UNSHARING.
16046 :
16047 : If there are only few specific cases of node sharing across functions, it is
16048 : probably easier for a front-end to unshare the expressions manually. On the
16049 : contrary, if the expressions generated at the global level are as widespread
16050 : as expressions generated within functions, deep unsharing is very likely the
16051 : way to go. */
16052 :
16053 : /* Similar to copy_tree_r but do not copy SAVE_EXPR or TARGET_EXPR nodes.
16054 : These nodes model computations that must be done once. If we were to
16055 : unshare something like SAVE_EXPR(i++), the gimplification process would
16056 : create wrong code. However, if DATA is non-null, it must hold a pointer
16057 : set that is used to unshare the subtrees of these nodes. */
16058 :
16059 : static tree
16060 2861855774 : mostly_copy_tree_r (tree *tp, int *walk_subtrees, void *data)
16061 : {
16062 2861855774 : tree t = *tp;
16063 2861855774 : enum tree_code code = TREE_CODE (t);
16064 :
16065 : /* Do not copy SAVE_EXPR, TARGET_EXPR or BIND_EXPR nodes themselves, but
16066 : copy their subtrees if we can make sure to do it only once. */
16067 2861855774 : if (code == SAVE_EXPR || code == TARGET_EXPR || code == BIND_EXPR)
16068 : {
16069 11771131 : if (data && !((hash_set<tree> *)data)->add (t))
16070 : ;
16071 : else
16072 11771131 : *walk_subtrees = 0;
16073 : }
16074 :
16075 : /* Stop at types, decls, constants like copy_tree_r. */
16076 2850084643 : else if (TREE_CODE_CLASS (code) == tcc_type
16077 : || TREE_CODE_CLASS (code) == tcc_declaration
16078 2850084643 : || TREE_CODE_CLASS (code) == tcc_constant)
16079 1762360237 : *walk_subtrees = 0;
16080 :
16081 : /* Cope with the statement expression extension. */
16082 1087724406 : else if (code == STATEMENT_LIST)
16083 : ;
16084 :
16085 : /* Leave the bulk of the work to copy_tree_r itself. */
16086 : else
16087 1087674762 : copy_tree_r (tp, walk_subtrees, NULL);
16088 :
16089 2861855774 : return NULL_TREE;
16090 : }
16091 :
16092 : /* Callback for walk_tree to unshare most of the shared trees rooted at *TP.
16093 : If *TP has been visited already, then *TP is deeply copied by calling
16094 : mostly_copy_tree_r. DATA is passed to mostly_copy_tree_r unmodified. */
16095 :
16096 : static tree
16097 289189650 : copy_if_shared_r (tree *tp, int *walk_subtrees, void *data)
16098 : {
16099 289189650 : tree t = *tp;
16100 289189650 : enum tree_code code = TREE_CODE (t);
16101 :
16102 : /* Skip types, decls, and constants. But we do want to look at their
16103 : types and the bounds of types. Mark them as visited so we properly
16104 : unmark their subtrees on the unmark pass. If we've already seen them,
16105 : don't look down further. */
16106 289189650 : if (TREE_CODE_CLASS (code) == tcc_type
16107 : || TREE_CODE_CLASS (code) == tcc_declaration
16108 289189650 : || TREE_CODE_CLASS (code) == tcc_constant)
16109 : {
16110 137263315 : if (TREE_VISITED (t))
16111 83934485 : *walk_subtrees = 0;
16112 : else
16113 53328830 : TREE_VISITED (t) = 1;
16114 : }
16115 :
16116 : /* If this node has been visited already, unshare it and don't look
16117 : any deeper. */
16118 151926335 : else if (TREE_VISITED (t))
16119 : {
16120 1807307 : walk_tree (tp, mostly_copy_tree_r, data, NULL);
16121 1807307 : *walk_subtrees = 0;
16122 : }
16123 :
16124 : /* Otherwise, mark the node as visited and keep looking. */
16125 : else
16126 150119028 : TREE_VISITED (t) = 1;
16127 :
16128 289189650 : return NULL_TREE;
16129 : }
16130 :
16131 : /* Unshare most of the shared trees rooted at *TP. DATA is passed to the
16132 : copy_if_shared_r callback unmodified. */
16133 :
16134 : void
16135 9227679 : copy_if_shared (tree *tp, void *data)
16136 : {
16137 9227679 : walk_tree (tp, copy_if_shared_r, data, NULL);
16138 9227679 : }
16139 :
16140 : /* Unconditionally make an unshared copy of EXPR. This is used when using
16141 : stored expressions which span multiple functions, such as BINFO_VTABLE,
16142 : as the normal unsharing process can't tell that they're shared. */
16143 :
16144 : tree
16145 1598062758 : unshare_expr (tree expr)
16146 : {
16147 1598062758 : walk_tree (&expr, mostly_copy_tree_r, NULL, NULL);
16148 1598062758 : return expr;
16149 : }
16150 :
16151 : /* Worker for unshare_expr_without_location. */
16152 :
16153 : static tree
16154 15730882 : prune_expr_location (tree *tp, int *walk_subtrees, void *)
16155 : {
16156 15730882 : if (EXPR_P (*tp))
16157 7894402 : SET_EXPR_LOCATION (*tp, UNKNOWN_LOCATION);
16158 : else
16159 7836480 : *walk_subtrees = 0;
16160 15730882 : return NULL_TREE;
16161 : }
16162 :
16163 : /* Similar to unshare_expr but also prune all expression locations
16164 : from EXPR. */
16165 :
16166 : tree
16167 24965061 : unshare_expr_without_location (tree expr)
16168 : {
16169 24965061 : walk_tree (&expr, mostly_copy_tree_r, NULL, NULL);
16170 24965061 : if (EXPR_P (expr))
16171 5395585 : walk_tree (&expr, prune_expr_location, NULL, NULL);
16172 24965061 : return expr;
16173 : }
16174 :
16175 : void
16176 264460 : tree_cc_finalize (void)
16177 : {
16178 264460 : clear_nonstandard_integer_type_cache ();
16179 264460 : vec_free (bitint_type_cache);
16180 264460 : }
16181 :
16182 : void
16183 231 : gt_ggc_mx (tree_raw_data *x)
16184 : {
16185 231 : gt_ggc_m_9tree_node (x->typed.type);
16186 231 : gt_ggc_m_9tree_node (x->owner);
16187 231 : }
16188 :
16189 : void
16190 12 : gt_pch_nx (tree_raw_data *x)
16191 : {
16192 12 : gt_pch_n_9tree_node (x->typed.type);
16193 12 : gt_pch_n_9tree_node (x->owner);
16194 12 : }
16195 :
16196 : /* For PCH we guarantee that RAW_DATA_CST's RAW_DATA_OWNER is a STRING_CST and
16197 : RAW_DATA_POINTER points into it. We don't want to save/restore
16198 : RAW_DATA_POINTER on its own but want to restore it pointing at the same
16199 : offset of the STRING_CST as before. */
16200 :
16201 : void
16202 12 : gt_pch_nx (tree_raw_data *x, gt_pointer_operator op, void *cookie)
16203 : {
16204 12 : op (&x->typed.type, NULL, cookie);
16205 12 : gcc_checking_assert (x->owner
16206 : && TREE_CODE (x->owner) == STRING_CST
16207 : && x->str >= TREE_STRING_POINTER (x->owner)
16208 : && (x->str + x->length
16209 : <= (TREE_STRING_POINTER (x->owner)
16210 : + TREE_STRING_LENGTH (x->owner))));
16211 12 : ptrdiff_t off = x->str - (const char *) (x->owner);
16212 12 : tree owner = x->owner;
16213 12 : op (&x->owner, NULL, cookie);
16214 12 : x->owner = owner;
16215 : /* The above op call relocates x->owner and remembers the address
16216 : for relocation e.g. if the compiler is position independent.
16217 : We then restore x->owner back to its previous value and call
16218 : op again, for x->owner itself this just repeats (uselessly) what
16219 : the first call did, but as the second argument is now non-NULL
16220 : and different, it also arranges for &x->str to be noted for the
16221 : PIE relocation. */
16222 12 : op (&x->owner, &x->str, cookie);
16223 12 : x->str = (const char *) (x->owner) + off;
16224 12 : }
16225 :
16226 : #if CHECKING_P
16227 :
16228 : namespace selftest {
16229 :
16230 : /* Selftests for tree. */
16231 :
16232 : /* Verify that integer constants are sane. */
16233 :
16234 : static void
16235 4 : test_integer_constants ()
16236 : {
16237 4 : ASSERT_TRUE (integer_type_node != NULL);
16238 4 : ASSERT_TRUE (build_int_cst (integer_type_node, 0) != NULL);
16239 :
16240 4 : tree type = integer_type_node;
16241 :
16242 4 : tree zero = build_zero_cst (type);
16243 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (zero));
16244 4 : ASSERT_EQ (type, TREE_TYPE (zero));
16245 :
16246 4 : tree one = build_int_cst (type, 1);
16247 4 : ASSERT_EQ (INTEGER_CST, TREE_CODE (one));
16248 4 : ASSERT_EQ (type, TREE_TYPE (zero));
16249 4 : }
16250 :
16251 : /* Verify identifiers. */
16252 :
16253 : static void
16254 4 : test_identifiers ()
16255 : {
16256 4 : tree identifier = get_identifier ("foo");
16257 4 : ASSERT_EQ (3, IDENTIFIER_LENGTH (identifier));
16258 4 : ASSERT_STREQ ("foo", IDENTIFIER_POINTER (identifier));
16259 4 : }
16260 :
16261 : /* Verify LABEL_DECL. */
16262 :
16263 : static void
16264 4 : test_labels ()
16265 : {
16266 4 : tree identifier = get_identifier ("err");
16267 4 : tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL,
16268 : identifier, void_type_node);
16269 4 : ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
16270 4 : ASSERT_FALSE (FORCED_LABEL (label_decl));
16271 4 : }
16272 :
16273 : /* Return a new VECTOR_CST node whose type is TYPE and whose values
16274 : are given by VALS. */
16275 :
16276 : static tree
16277 40 : build_vector (tree type, const vec<tree> &vals MEM_STAT_DECL)
16278 : {
16279 80 : gcc_assert (known_eq (vals.length (), TYPE_VECTOR_SUBPARTS (type)));
16280 40 : tree_vector_builder builder (type, vals.length (), 1);
16281 40 : builder.splice (vals);
16282 40 : return builder.build ();
16283 40 : }
16284 :
16285 : /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED. */
16286 :
16287 : static void
16288 40 : check_vector_cst (const vec<tree> &expected, tree actual)
16289 : {
16290 80 : ASSERT_KNOWN_EQ (expected.length (),
16291 : TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual)));
16292 360 : for (unsigned int i = 0; i < expected.length (); ++i)
16293 320 : ASSERT_EQ (wi::to_wide (expected[i]),
16294 : wi::to_wide (vector_cst_elt (actual, i)));
16295 40 : }
16296 :
16297 : /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
16298 : and that its elements match EXPECTED. */
16299 :
16300 : static void
16301 8 : check_vector_cst_duplicate (const vec<tree> &expected, tree actual,
16302 : unsigned int npatterns)
16303 : {
16304 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
16305 8 : ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual));
16306 8 : ASSERT_EQ (npatterns, vector_cst_encoded_nelts (actual));
16307 8 : ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual));
16308 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
16309 8 : check_vector_cst (expected, actual);
16310 8 : }
16311 :
16312 : /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
16313 : and NPATTERNS background elements, and that its elements match
16314 : EXPECTED. */
16315 :
16316 : static void
16317 8 : check_vector_cst_fill (const vec<tree> &expected, tree actual,
16318 : unsigned int npatterns)
16319 : {
16320 8 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
16321 8 : ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual));
16322 8 : ASSERT_EQ (2 * npatterns, vector_cst_encoded_nelts (actual));
16323 8 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
16324 8 : ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
16325 8 : check_vector_cst (expected, actual);
16326 8 : }
16327 :
16328 : /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
16329 : and that its elements match EXPECTED. */
16330 :
16331 : static void
16332 24 : check_vector_cst_stepped (const vec<tree> &expected, tree actual,
16333 : unsigned int npatterns)
16334 : {
16335 24 : ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
16336 24 : ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual));
16337 24 : ASSERT_EQ (3 * npatterns, vector_cst_encoded_nelts (actual));
16338 24 : ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
16339 24 : ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual));
16340 24 : check_vector_cst (expected, actual);
16341 24 : }
16342 :
16343 : /* Test the creation of VECTOR_CSTs. */
16344 :
16345 : static void
16346 4 : test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO)
16347 : {
16348 4 : auto_vec<tree, 8> elements (8);
16349 4 : elements.quick_grow (8);
16350 4 : tree element_type = build_nonstandard_integer_type (16, true);
16351 4 : tree vector_type = build_vector_type (element_type, 8);
16352 :
16353 : /* Test a simple linear series with a base of 0 and a step of 1:
16354 : { 0, 1, 2, 3, 4, 5, 6, 7 }. */
16355 36 : for (unsigned int i = 0; i < 8; ++i)
16356 32 : elements[i] = build_int_cst (element_type, i);
16357 4 : tree vector = build_vector (vector_type, elements PASS_MEM_STAT);
16358 4 : check_vector_cst_stepped (elements, vector, 1);
16359 :
16360 : /* Try the same with the first element replaced by 100:
16361 : { 100, 1, 2, 3, 4, 5, 6, 7 }. */
16362 4 : elements[0] = build_int_cst (element_type, 100);
16363 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16364 4 : check_vector_cst_stepped (elements, vector, 1);
16365 :
16366 : /* Try a series that wraps around.
16367 : { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }. */
16368 36 : for (unsigned int i = 1; i < 8; ++i)
16369 28 : elements[i] = build_int_cst (element_type, (65530 + i) & 0xffff);
16370 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16371 4 : check_vector_cst_stepped (elements, vector, 1);
16372 :
16373 : /* Try a downward series:
16374 : { 100, 79, 78, 77, 76, 75, 75, 73 }. */
16375 36 : for (unsigned int i = 1; i < 8; ++i)
16376 28 : elements[i] = build_int_cst (element_type, 80 - i);
16377 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16378 4 : check_vector_cst_stepped (elements, vector, 1);
16379 :
16380 : /* Try two interleaved series with different bases and steps:
16381 : { 100, 53, 66, 206, 62, 212, 58, 218 }. */
16382 4 : elements[1] = build_int_cst (element_type, 53);
16383 16 : for (unsigned int i = 2; i < 8; i += 2)
16384 : {
16385 12 : elements[i] = build_int_cst (element_type, 70 - i * 2);
16386 12 : elements[i + 1] = build_int_cst (element_type, 200 + i * 3);
16387 : }
16388 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16389 4 : check_vector_cst_stepped (elements, vector, 2);
16390 :
16391 : /* Try a duplicated value:
16392 : { 100, 100, 100, 100, 100, 100, 100, 100 }. */
16393 36 : for (unsigned int i = 1; i < 8; ++i)
16394 28 : elements[i] = elements[0];
16395 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16396 4 : check_vector_cst_duplicate (elements, vector, 1);
16397 :
16398 : /* Try an interleaved duplicated value:
16399 : { 100, 55, 100, 55, 100, 55, 100, 55 }. */
16400 4 : elements[1] = build_int_cst (element_type, 55);
16401 28 : for (unsigned int i = 2; i < 8; ++i)
16402 24 : elements[i] = elements[i - 2];
16403 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16404 4 : check_vector_cst_duplicate (elements, vector, 2);
16405 :
16406 : /* Try a duplicated value with 2 exceptions
16407 : { 41, 97, 100, 55, 100, 55, 100, 55 }. */
16408 4 : elements[0] = build_int_cst (element_type, 41);
16409 4 : elements[1] = build_int_cst (element_type, 97);
16410 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16411 4 : check_vector_cst_fill (elements, vector, 2);
16412 :
16413 : /* Try with and without a step
16414 : { 41, 97, 100, 21, 100, 35, 100, 49 }. */
16415 20 : for (unsigned int i = 3; i < 8; i += 2)
16416 12 : elements[i] = build_int_cst (element_type, i * 7);
16417 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16418 4 : check_vector_cst_stepped (elements, vector, 2);
16419 :
16420 : /* Try a fully-general constant:
16421 : { 41, 97, 100, 21, 100, 9990, 100, 49 }. */
16422 4 : elements[5] = build_int_cst (element_type, 9990);
16423 4 : vector = build_vector (vector_type, elements PASS_MEM_STAT);
16424 4 : check_vector_cst_fill (elements, vector, 4);
16425 4 : }
16426 :
16427 : /* Verify that STRIP_NOPS (NODE) is EXPECTED.
16428 : Helper function for test_location_wrappers, to deal with STRIP_NOPS
16429 : modifying its argument in-place. */
16430 :
16431 : static void
16432 12 : check_strip_nops (tree node, tree expected)
16433 : {
16434 12 : STRIP_NOPS (node);
16435 12 : ASSERT_EQ (expected, node);
16436 12 : }
16437 :
16438 : /* Verify location wrappers. */
16439 :
16440 : static void
16441 4 : test_location_wrappers ()
16442 : {
16443 4 : location_t loc = BUILTINS_LOCATION;
16444 :
16445 4 : ASSERT_EQ (NULL_TREE, maybe_wrap_with_location (NULL_TREE, loc));
16446 :
16447 : /* Wrapping a constant. */
16448 4 : tree int_cst = build_int_cst (integer_type_node, 42);
16449 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst));
16450 4 : ASSERT_FALSE (location_wrapper_p (int_cst));
16451 :
16452 4 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
16453 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
16454 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_cst));
16455 4 : ASSERT_EQ (int_cst, tree_strip_any_location_wrapper (wrapped_int_cst));
16456 :
16457 : /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION. */
16458 4 : ASSERT_EQ (int_cst, maybe_wrap_with_location (int_cst, UNKNOWN_LOCATION));
16459 :
16460 : /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P. */
16461 4 : tree cast = build1 (NOP_EXPR, char_type_node, int_cst);
16462 4 : ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast));
16463 4 : ASSERT_EQ (cast, maybe_wrap_with_location (cast, loc));
16464 :
16465 : /* Wrapping a STRING_CST. */
16466 4 : tree string_cst = build_string (4, "foo");
16467 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst));
16468 4 : ASSERT_FALSE (location_wrapper_p (string_cst));
16469 :
16470 4 : tree wrapped_string_cst = maybe_wrap_with_location (string_cst, loc);
16471 4 : ASSERT_TRUE (location_wrapper_p (wrapped_string_cst));
16472 4 : ASSERT_EQ (VIEW_CONVERT_EXPR, TREE_CODE (wrapped_string_cst));
16473 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_string_cst));
16474 4 : ASSERT_EQ (string_cst, tree_strip_any_location_wrapper (wrapped_string_cst));
16475 :
16476 :
16477 : /* Wrapping a variable. */
16478 4 : tree int_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
16479 : get_identifier ("some_int_var"),
16480 : integer_type_node);
16481 4 : ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var));
16482 4 : ASSERT_FALSE (location_wrapper_p (int_var));
16483 :
16484 4 : tree wrapped_int_var = maybe_wrap_with_location (int_var, loc);
16485 4 : ASSERT_TRUE (location_wrapper_p (wrapped_int_var));
16486 4 : ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_var));
16487 4 : ASSERT_EQ (int_var, tree_strip_any_location_wrapper (wrapped_int_var));
16488 :
16489 : /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
16490 : wrapper. */
16491 4 : tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
16492 4 : ASSERT_FALSE (location_wrapper_p (r_cast));
16493 4 : ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
16494 :
16495 : /* Verify that STRIP_NOPS removes wrappers. */
16496 4 : check_strip_nops (wrapped_int_cst, int_cst);
16497 4 : check_strip_nops (wrapped_string_cst, string_cst);
16498 4 : check_strip_nops (wrapped_int_var, int_var);
16499 4 : }
16500 :
16501 : /* Test various tree predicates. Verify that location wrappers don't
16502 : affect the results. */
16503 :
16504 : static void
16505 4 : test_predicates ()
16506 : {
16507 : /* Build various constants and wrappers around them. */
16508 :
16509 4 : location_t loc = BUILTINS_LOCATION;
16510 :
16511 4 : tree i_0 = build_int_cst (integer_type_node, 0);
16512 4 : tree wr_i_0 = maybe_wrap_with_location (i_0, loc);
16513 :
16514 4 : tree i_1 = build_int_cst (integer_type_node, 1);
16515 4 : tree wr_i_1 = maybe_wrap_with_location (i_1, loc);
16516 :
16517 4 : tree i_m1 = build_int_cst (integer_type_node, -1);
16518 4 : tree wr_i_m1 = maybe_wrap_with_location (i_m1, loc);
16519 :
16520 4 : tree f_0 = build_real_from_int_cst (float_type_node, i_0);
16521 4 : tree wr_f_0 = maybe_wrap_with_location (f_0, loc);
16522 4 : tree f_1 = build_real_from_int_cst (float_type_node, i_1);
16523 4 : tree wr_f_1 = maybe_wrap_with_location (f_1, loc);
16524 4 : tree f_m1 = build_real_from_int_cst (float_type_node, i_m1);
16525 4 : tree wr_f_m1 = maybe_wrap_with_location (f_m1, loc);
16526 :
16527 4 : tree c_i_0 = build_complex (NULL_TREE, i_0, i_0);
16528 4 : tree c_i_1 = build_complex (NULL_TREE, i_1, i_0);
16529 4 : tree c_i_m1 = build_complex (NULL_TREE, i_m1, i_0);
16530 :
16531 4 : tree c_f_0 = build_complex (NULL_TREE, f_0, f_0);
16532 4 : tree c_f_1 = build_complex (NULL_TREE, f_1, f_0);
16533 4 : tree c_f_m1 = build_complex (NULL_TREE, f_m1, f_0);
16534 :
16535 : /* TODO: vector constants. */
16536 :
16537 : /* Test integer_onep. */
16538 4 : ASSERT_FALSE (integer_onep (i_0));
16539 4 : ASSERT_FALSE (integer_onep (wr_i_0));
16540 4 : ASSERT_TRUE (integer_onep (i_1));
16541 4 : ASSERT_TRUE (integer_onep (wr_i_1));
16542 4 : ASSERT_FALSE (integer_onep (i_m1));
16543 4 : ASSERT_FALSE (integer_onep (wr_i_m1));
16544 4 : ASSERT_FALSE (integer_onep (f_0));
16545 4 : ASSERT_FALSE (integer_onep (wr_f_0));
16546 4 : ASSERT_FALSE (integer_onep (f_1));
16547 4 : ASSERT_FALSE (integer_onep (wr_f_1));
16548 4 : ASSERT_FALSE (integer_onep (f_m1));
16549 4 : ASSERT_FALSE (integer_onep (wr_f_m1));
16550 4 : ASSERT_FALSE (integer_onep (c_i_0));
16551 4 : ASSERT_TRUE (integer_onep (c_i_1));
16552 4 : ASSERT_FALSE (integer_onep (c_i_m1));
16553 4 : ASSERT_FALSE (integer_onep (c_f_0));
16554 4 : ASSERT_FALSE (integer_onep (c_f_1));
16555 4 : ASSERT_FALSE (integer_onep (c_f_m1));
16556 :
16557 : /* Test integer_zerop. */
16558 4 : ASSERT_TRUE (integer_zerop (i_0));
16559 4 : ASSERT_TRUE (integer_zerop (wr_i_0));
16560 4 : ASSERT_FALSE (integer_zerop (i_1));
16561 4 : ASSERT_FALSE (integer_zerop (wr_i_1));
16562 4 : ASSERT_FALSE (integer_zerop (i_m1));
16563 4 : ASSERT_FALSE (integer_zerop (wr_i_m1));
16564 4 : ASSERT_FALSE (integer_zerop (f_0));
16565 4 : ASSERT_FALSE (integer_zerop (wr_f_0));
16566 4 : ASSERT_FALSE (integer_zerop (f_1));
16567 4 : ASSERT_FALSE (integer_zerop (wr_f_1));
16568 4 : ASSERT_FALSE (integer_zerop (f_m1));
16569 4 : ASSERT_FALSE (integer_zerop (wr_f_m1));
16570 4 : ASSERT_TRUE (integer_zerop (c_i_0));
16571 4 : ASSERT_FALSE (integer_zerop (c_i_1));
16572 4 : ASSERT_FALSE (integer_zerop (c_i_m1));
16573 4 : ASSERT_FALSE (integer_zerop (c_f_0));
16574 4 : ASSERT_FALSE (integer_zerop (c_f_1));
16575 4 : ASSERT_FALSE (integer_zerop (c_f_m1));
16576 :
16577 : /* Test integer_all_onesp. */
16578 4 : ASSERT_FALSE (integer_all_onesp (i_0));
16579 4 : ASSERT_FALSE (integer_all_onesp (wr_i_0));
16580 4 : ASSERT_FALSE (integer_all_onesp (i_1));
16581 4 : ASSERT_FALSE (integer_all_onesp (wr_i_1));
16582 4 : ASSERT_TRUE (integer_all_onesp (i_m1));
16583 4 : ASSERT_TRUE (integer_all_onesp (wr_i_m1));
16584 4 : ASSERT_FALSE (integer_all_onesp (f_0));
16585 4 : ASSERT_FALSE (integer_all_onesp (wr_f_0));
16586 4 : ASSERT_FALSE (integer_all_onesp (f_1));
16587 4 : ASSERT_FALSE (integer_all_onesp (wr_f_1));
16588 4 : ASSERT_FALSE (integer_all_onesp (f_m1));
16589 4 : ASSERT_FALSE (integer_all_onesp (wr_f_m1));
16590 4 : ASSERT_FALSE (integer_all_onesp (c_i_0));
16591 4 : ASSERT_FALSE (integer_all_onesp (c_i_1));
16592 4 : ASSERT_FALSE (integer_all_onesp (c_i_m1));
16593 4 : ASSERT_FALSE (integer_all_onesp (c_f_0));
16594 4 : ASSERT_FALSE (integer_all_onesp (c_f_1));
16595 4 : ASSERT_FALSE (integer_all_onesp (c_f_m1));
16596 :
16597 : /* Test integer_minus_onep. */
16598 4 : ASSERT_FALSE (integer_minus_onep (i_0));
16599 4 : ASSERT_FALSE (integer_minus_onep (wr_i_0));
16600 4 : ASSERT_FALSE (integer_minus_onep (i_1));
16601 4 : ASSERT_FALSE (integer_minus_onep (wr_i_1));
16602 4 : ASSERT_TRUE (integer_minus_onep (i_m1));
16603 4 : ASSERT_TRUE (integer_minus_onep (wr_i_m1));
16604 4 : ASSERT_FALSE (integer_minus_onep (f_0));
16605 4 : ASSERT_FALSE (integer_minus_onep (wr_f_0));
16606 4 : ASSERT_FALSE (integer_minus_onep (f_1));
16607 4 : ASSERT_FALSE (integer_minus_onep (wr_f_1));
16608 4 : ASSERT_FALSE (integer_minus_onep (f_m1));
16609 4 : ASSERT_FALSE (integer_minus_onep (wr_f_m1));
16610 4 : ASSERT_FALSE (integer_minus_onep (c_i_0));
16611 4 : ASSERT_FALSE (integer_minus_onep (c_i_1));
16612 4 : ASSERT_TRUE (integer_minus_onep (c_i_m1));
16613 4 : ASSERT_FALSE (integer_minus_onep (c_f_0));
16614 4 : ASSERT_FALSE (integer_minus_onep (c_f_1));
16615 4 : ASSERT_FALSE (integer_minus_onep (c_f_m1));
16616 :
16617 : /* Test integer_each_onep. */
16618 4 : ASSERT_FALSE (integer_each_onep (i_0));
16619 4 : ASSERT_FALSE (integer_each_onep (wr_i_0));
16620 4 : ASSERT_TRUE (integer_each_onep (i_1));
16621 4 : ASSERT_TRUE (integer_each_onep (wr_i_1));
16622 4 : ASSERT_FALSE (integer_each_onep (i_m1));
16623 4 : ASSERT_FALSE (integer_each_onep (wr_i_m1));
16624 4 : ASSERT_FALSE (integer_each_onep (f_0));
16625 4 : ASSERT_FALSE (integer_each_onep (wr_f_0));
16626 4 : ASSERT_FALSE (integer_each_onep (f_1));
16627 4 : ASSERT_FALSE (integer_each_onep (wr_f_1));
16628 4 : ASSERT_FALSE (integer_each_onep (f_m1));
16629 4 : ASSERT_FALSE (integer_each_onep (wr_f_m1));
16630 4 : ASSERT_FALSE (integer_each_onep (c_i_0));
16631 4 : ASSERT_FALSE (integer_each_onep (c_i_1));
16632 4 : ASSERT_FALSE (integer_each_onep (c_i_m1));
16633 4 : ASSERT_FALSE (integer_each_onep (c_f_0));
16634 4 : ASSERT_FALSE (integer_each_onep (c_f_1));
16635 4 : ASSERT_FALSE (integer_each_onep (c_f_m1));
16636 :
16637 : /* Test integer_truep. */
16638 4 : ASSERT_FALSE (integer_truep (i_0));
16639 4 : ASSERT_FALSE (integer_truep (wr_i_0));
16640 4 : ASSERT_TRUE (integer_truep (i_1));
16641 4 : ASSERT_TRUE (integer_truep (wr_i_1));
16642 4 : ASSERT_FALSE (integer_truep (i_m1));
16643 4 : ASSERT_FALSE (integer_truep (wr_i_m1));
16644 4 : ASSERT_FALSE (integer_truep (f_0));
16645 4 : ASSERT_FALSE (integer_truep (wr_f_0));
16646 4 : ASSERT_FALSE (integer_truep (f_1));
16647 4 : ASSERT_FALSE (integer_truep (wr_f_1));
16648 4 : ASSERT_FALSE (integer_truep (f_m1));
16649 4 : ASSERT_FALSE (integer_truep (wr_f_m1));
16650 4 : ASSERT_FALSE (integer_truep (c_i_0));
16651 4 : ASSERT_TRUE (integer_truep (c_i_1));
16652 4 : ASSERT_FALSE (integer_truep (c_i_m1));
16653 4 : ASSERT_FALSE (integer_truep (c_f_0));
16654 4 : ASSERT_FALSE (integer_truep (c_f_1));
16655 4 : ASSERT_FALSE (integer_truep (c_f_m1));
16656 :
16657 : /* Test integer_nonzerop. */
16658 4 : ASSERT_FALSE (integer_nonzerop (i_0));
16659 4 : ASSERT_FALSE (integer_nonzerop (wr_i_0));
16660 4 : ASSERT_TRUE (integer_nonzerop (i_1));
16661 4 : ASSERT_TRUE (integer_nonzerop (wr_i_1));
16662 4 : ASSERT_TRUE (integer_nonzerop (i_m1));
16663 4 : ASSERT_TRUE (integer_nonzerop (wr_i_m1));
16664 4 : ASSERT_FALSE (integer_nonzerop (f_0));
16665 4 : ASSERT_FALSE (integer_nonzerop (wr_f_0));
16666 4 : ASSERT_FALSE (integer_nonzerop (f_1));
16667 4 : ASSERT_FALSE (integer_nonzerop (wr_f_1));
16668 4 : ASSERT_FALSE (integer_nonzerop (f_m1));
16669 4 : ASSERT_FALSE (integer_nonzerop (wr_f_m1));
16670 4 : ASSERT_FALSE (integer_nonzerop (c_i_0));
16671 4 : ASSERT_TRUE (integer_nonzerop (c_i_1));
16672 4 : ASSERT_TRUE (integer_nonzerop (c_i_m1));
16673 4 : ASSERT_FALSE (integer_nonzerop (c_f_0));
16674 4 : ASSERT_FALSE (integer_nonzerop (c_f_1));
16675 4 : ASSERT_FALSE (integer_nonzerop (c_f_m1));
16676 :
16677 : /* Test real_zerop. */
16678 4 : ASSERT_FALSE (real_zerop (i_0));
16679 4 : ASSERT_FALSE (real_zerop (wr_i_0));
16680 4 : ASSERT_FALSE (real_zerop (i_1));
16681 4 : ASSERT_FALSE (real_zerop (wr_i_1));
16682 4 : ASSERT_FALSE (real_zerop (i_m1));
16683 4 : ASSERT_FALSE (real_zerop (wr_i_m1));
16684 4 : ASSERT_TRUE (real_zerop (f_0));
16685 4 : ASSERT_TRUE (real_zerop (wr_f_0));
16686 4 : ASSERT_FALSE (real_zerop (f_1));
16687 4 : ASSERT_FALSE (real_zerop (wr_f_1));
16688 4 : ASSERT_FALSE (real_zerop (f_m1));
16689 4 : ASSERT_FALSE (real_zerop (wr_f_m1));
16690 4 : ASSERT_FALSE (real_zerop (c_i_0));
16691 4 : ASSERT_FALSE (real_zerop (c_i_1));
16692 4 : ASSERT_FALSE (real_zerop (c_i_m1));
16693 4 : ASSERT_TRUE (real_zerop (c_f_0));
16694 4 : ASSERT_FALSE (real_zerop (c_f_1));
16695 4 : ASSERT_FALSE (real_zerop (c_f_m1));
16696 :
16697 : /* Test real_onep. */
16698 4 : ASSERT_FALSE (real_onep (i_0));
16699 4 : ASSERT_FALSE (real_onep (wr_i_0));
16700 4 : ASSERT_FALSE (real_onep (i_1));
16701 4 : ASSERT_FALSE (real_onep (wr_i_1));
16702 4 : ASSERT_FALSE (real_onep (i_m1));
16703 4 : ASSERT_FALSE (real_onep (wr_i_m1));
16704 4 : ASSERT_FALSE (real_onep (f_0));
16705 4 : ASSERT_FALSE (real_onep (wr_f_0));
16706 4 : ASSERT_TRUE (real_onep (f_1));
16707 4 : ASSERT_TRUE (real_onep (wr_f_1));
16708 4 : ASSERT_FALSE (real_onep (f_m1));
16709 4 : ASSERT_FALSE (real_onep (wr_f_m1));
16710 4 : ASSERT_FALSE (real_onep (c_i_0));
16711 4 : ASSERT_FALSE (real_onep (c_i_1));
16712 4 : ASSERT_FALSE (real_onep (c_i_m1));
16713 4 : ASSERT_FALSE (real_onep (c_f_0));
16714 4 : ASSERT_TRUE (real_onep (c_f_1));
16715 4 : ASSERT_FALSE (real_onep (c_f_m1));
16716 :
16717 : /* Test real_minus_onep. */
16718 4 : ASSERT_FALSE (real_minus_onep (i_0));
16719 4 : ASSERT_FALSE (real_minus_onep (wr_i_0));
16720 4 : ASSERT_FALSE (real_minus_onep (i_1));
16721 4 : ASSERT_FALSE (real_minus_onep (wr_i_1));
16722 4 : ASSERT_FALSE (real_minus_onep (i_m1));
16723 4 : ASSERT_FALSE (real_minus_onep (wr_i_m1));
16724 4 : ASSERT_FALSE (real_minus_onep (f_0));
16725 4 : ASSERT_FALSE (real_minus_onep (wr_f_0));
16726 4 : ASSERT_FALSE (real_minus_onep (f_1));
16727 4 : ASSERT_FALSE (real_minus_onep (wr_f_1));
16728 4 : ASSERT_TRUE (real_minus_onep (f_m1));
16729 4 : ASSERT_TRUE (real_minus_onep (wr_f_m1));
16730 4 : ASSERT_FALSE (real_minus_onep (c_i_0));
16731 4 : ASSERT_FALSE (real_minus_onep (c_i_1));
16732 4 : ASSERT_FALSE (real_minus_onep (c_i_m1));
16733 4 : ASSERT_FALSE (real_minus_onep (c_f_0));
16734 4 : ASSERT_FALSE (real_minus_onep (c_f_1));
16735 4 : ASSERT_TRUE (real_minus_onep (c_f_m1));
16736 :
16737 : /* Test zerop. */
16738 4 : ASSERT_TRUE (zerop (i_0));
16739 4 : ASSERT_TRUE (zerop (wr_i_0));
16740 4 : ASSERT_FALSE (zerop (i_1));
16741 4 : ASSERT_FALSE (zerop (wr_i_1));
16742 4 : ASSERT_FALSE (zerop (i_m1));
16743 4 : ASSERT_FALSE (zerop (wr_i_m1));
16744 4 : ASSERT_TRUE (zerop (f_0));
16745 4 : ASSERT_TRUE (zerop (wr_f_0));
16746 4 : ASSERT_FALSE (zerop (f_1));
16747 4 : ASSERT_FALSE (zerop (wr_f_1));
16748 4 : ASSERT_FALSE (zerop (f_m1));
16749 4 : ASSERT_FALSE (zerop (wr_f_m1));
16750 4 : ASSERT_TRUE (zerop (c_i_0));
16751 4 : ASSERT_FALSE (zerop (c_i_1));
16752 4 : ASSERT_FALSE (zerop (c_i_m1));
16753 4 : ASSERT_TRUE (zerop (c_f_0));
16754 4 : ASSERT_FALSE (zerop (c_f_1));
16755 4 : ASSERT_FALSE (zerop (c_f_m1));
16756 :
16757 : /* Test tree_expr_nonnegative_p. */
16758 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_0));
16759 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_0));
16760 4 : ASSERT_TRUE (tree_expr_nonnegative_p (i_1));
16761 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_i_1));
16762 4 : ASSERT_FALSE (tree_expr_nonnegative_p (i_m1));
16763 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_i_m1));
16764 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_0));
16765 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_0));
16766 4 : ASSERT_TRUE (tree_expr_nonnegative_p (f_1));
16767 4 : ASSERT_TRUE (tree_expr_nonnegative_p (wr_f_1));
16768 4 : ASSERT_FALSE (tree_expr_nonnegative_p (f_m1));
16769 4 : ASSERT_FALSE (tree_expr_nonnegative_p (wr_f_m1));
16770 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_0));
16771 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_1));
16772 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_i_m1));
16773 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_0));
16774 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_1));
16775 4 : ASSERT_FALSE (tree_expr_nonnegative_p (c_f_m1));
16776 :
16777 : /* Test tree_expr_nonzero_p. */
16778 4 : ASSERT_FALSE (tree_expr_nonzero_p (i_0));
16779 4 : ASSERT_FALSE (tree_expr_nonzero_p (wr_i_0));
16780 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_1));
16781 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_1));
16782 4 : ASSERT_TRUE (tree_expr_nonzero_p (i_m1));
16783 4 : ASSERT_TRUE (tree_expr_nonzero_p (wr_i_m1));
16784 :
16785 : /* Test integer_valued_real_p. */
16786 4 : ASSERT_FALSE (integer_valued_real_p (i_0));
16787 4 : ASSERT_TRUE (integer_valued_real_p (f_0));
16788 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_0));
16789 4 : ASSERT_TRUE (integer_valued_real_p (f_1));
16790 4 : ASSERT_TRUE (integer_valued_real_p (wr_f_1));
16791 :
16792 : /* Test integer_pow2p. */
16793 4 : ASSERT_FALSE (integer_pow2p (i_0));
16794 4 : ASSERT_TRUE (integer_pow2p (i_1));
16795 4 : ASSERT_TRUE (integer_pow2p (wr_i_1));
16796 :
16797 : /* Test uniform_integer_cst_p. */
16798 4 : ASSERT_TRUE (uniform_integer_cst_p (i_0));
16799 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_0));
16800 4 : ASSERT_TRUE (uniform_integer_cst_p (i_1));
16801 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_1));
16802 4 : ASSERT_TRUE (uniform_integer_cst_p (i_m1));
16803 4 : ASSERT_TRUE (uniform_integer_cst_p (wr_i_m1));
16804 4 : ASSERT_FALSE (uniform_integer_cst_p (f_0));
16805 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_0));
16806 4 : ASSERT_FALSE (uniform_integer_cst_p (f_1));
16807 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_1));
16808 4 : ASSERT_FALSE (uniform_integer_cst_p (f_m1));
16809 4 : ASSERT_FALSE (uniform_integer_cst_p (wr_f_m1));
16810 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_0));
16811 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_1));
16812 4 : ASSERT_FALSE (uniform_integer_cst_p (c_i_m1));
16813 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_0));
16814 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_1));
16815 4 : ASSERT_FALSE (uniform_integer_cst_p (c_f_m1));
16816 4 : }
16817 :
16818 : /* Check that string escaping works correctly. */
16819 :
16820 : static void
16821 4 : test_escaped_strings (void)
16822 : {
16823 4 : int saved_cutoff;
16824 4 : escaped_string msg;
16825 :
16826 4 : msg.escape (NULL);
16827 : /* ASSERT_STREQ does not accept NULL as a valid test
16828 : result, so we have to use ASSERT_EQ instead. */
16829 4 : ASSERT_EQ (NULL, (const char *) msg);
16830 :
16831 4 : msg.escape ("");
16832 4 : ASSERT_STREQ ("", (const char *) msg);
16833 :
16834 4 : msg.escape ("foobar");
16835 4 : ASSERT_STREQ ("foobar", (const char *) msg);
16836 :
16837 : /* Ensure that we have -fmessage-length set to 0. */
16838 4 : pretty_printer *pp = global_dc->get_reference_printer ();
16839 4 : saved_cutoff = pp_line_cutoff (pp);
16840 4 : pp_line_cutoff (pp) = 0;
16841 :
16842 4 : msg.escape ("foo\nbar");
16843 4 : ASSERT_STREQ ("foo\\nbar", (const char *) msg);
16844 :
16845 4 : msg.escape ("\a\b\f\n\r\t\v");
16846 4 : ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg);
16847 :
16848 : /* Now repeat the tests with -fmessage-length set to 5. */
16849 4 : pp_line_cutoff (pp) = 5;
16850 :
16851 : /* Note that the newline is not translated into an escape. */
16852 4 : msg.escape ("foo\nbar");
16853 4 : ASSERT_STREQ ("foo\nbar", (const char *) msg);
16854 :
16855 4 : msg.escape ("\a\b\f\n\r\t\v");
16856 4 : ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg);
16857 :
16858 : /* Restore the original message length setting. */
16859 4 : pp_line_cutoff (pp) = saved_cutoff;
16860 4 : }
16861 :
16862 : /* Run all of the selftests within this file. */
16863 :
16864 : void
16865 4 : tree_cc_tests ()
16866 : {
16867 4 : test_integer_constants ();
16868 4 : test_identifiers ();
16869 4 : test_labels ();
16870 4 : test_vector_cst_patterns ();
16871 4 : test_location_wrappers ();
16872 4 : test_predicates ();
16873 4 : test_escaped_strings ();
16874 4 : }
16875 :
16876 : } // namespace selftest
16877 :
16878 : #endif /* CHECKING_P */
16879 :
16880 : #include "gt-tree.h"
|