]>
Commit | Line | Data |
---|---|---|
10a9d4cf | 1 | /* Language-independent node constructors for parse phase of GNU compiler. |
b278476e | 2 | Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
9c85a98a | 3 | 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
63bf54cf | 4 | Free Software Foundation, Inc. |
10a9d4cf | 5 | |
f12b58b3 | 6 | This file is part of GCC. |
10a9d4cf | 7 | |
f12b58b3 | 8 | GCC is free software; you can redistribute it and/or modify it under |
9 | the terms of the GNU General Public License as published by the Free | |
8c4c00c1 | 10 | Software Foundation; either version 3, or (at your option) any later |
f12b58b3 | 11 | version. |
10a9d4cf | 12 | |
f12b58b3 | 13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
10a9d4cf | 17 | |
18 | You should have received a copy of the GNU General Public License | |
8c4c00c1 | 19 | along with GCC; see the file COPYING3. If not see |
20 | <http://www.gnu.org/licenses/>. */ | |
10a9d4cf | 21 | |
10a9d4cf | 22 | /* This file contains the low level primitives for operating on tree nodes, |
23 | including allocation, list operations, interning of identifiers, | |
24 | construction of data type nodes and statement nodes, | |
25 | and construction of type conversion nodes. It also contains | |
26 | tables index by tree code that describe how to take apart | |
27 | nodes of that code. | |
28 | ||
29 | It is intended to be language-independent, but occasionally | |
92192583 | 30 | calls language-dependent routines defined (for C) in typecheck.c. */ |
10a9d4cf | 31 | |
32 | #include "config.h" | |
405711de | 33 | #include "system.h" |
805e22b2 | 34 | #include "coretypes.h" |
35 | #include "tm.h" | |
10a9d4cf | 36 | #include "flags.h" |
10a9d4cf | 37 | #include "tree.h" |
ef258422 | 38 | #include "real.h" |
7953c610 | 39 | #include "tm_p.h" |
9c237f94 | 40 | #include "function.h" |
10a9d4cf | 41 | #include "obstack.h" |
12874aaf | 42 | #include "toplev.h" |
a7b0c170 | 43 | #include "ggc.h" |
f2d83427 | 44 | #include "hashtab.h" |
e772a198 | 45 | #include "output.h" |
a767736d | 46 | #include "target.h" |
b7fced5e | 47 | #include "langhooks.h" |
4ee9c684 | 48 | #include "tree-iterator.h" |
49 | #include "basic-block.h" | |
50 | #include "tree-flow.h" | |
00b76131 | 51 | #include "params.h" |
98f8a662 | 52 | #include "pointer-set.h" |
06f0b99c | 53 | #include "fixed-value.h" |
ad87de1e | 54 | |
e014fc6a | 55 | /* Tree code classes. */ |
56 | ||
57 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, | |
58 | #define END_OF_BASE_TREE_CODES tcc_exceptional, | |
59 | ||
60 | const enum tree_code_class tree_code_type[] = { | |
61 | #include "all-tree.def" | |
62 | }; | |
63 | ||
64 | #undef DEFTREECODE | |
65 | #undef END_OF_BASE_TREE_CODES | |
66 | ||
67 | /* Table indexed by tree code giving number of expression | |
68 | operands beyond the fixed part of the node structure. | |
69 | Not used for types or decls. */ | |
70 | ||
71 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, | |
72 | #define END_OF_BASE_TREE_CODES 0, | |
73 | ||
74 | const unsigned char tree_code_length[] = { | |
75 | #include "all-tree.def" | |
76 | }; | |
77 | ||
78 | #undef DEFTREECODE | |
79 | #undef END_OF_BASE_TREE_CODES | |
80 | ||
81 | /* Names of tree components. | |
82 | Used for printing out the tree and error messages. */ | |
83 | #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME, | |
84 | #define END_OF_BASE_TREE_CODES "@dummy", | |
85 | ||
86 | const char *const tree_code_name[] = { | |
87 | #include "all-tree.def" | |
88 | }; | |
89 | ||
90 | #undef DEFTREECODE | |
91 | #undef END_OF_BASE_TREE_CODES | |
92 | ||
ce45a448 | 93 | /* Each tree code class has an associated string representation. |
94 | These must correspond to the tree_code_class entries. */ | |
95 | ||
a93de1ee | 96 | const char *const tree_code_class_strings[] = |
97 | { | |
98 | "exceptional", | |
99 | "constant", | |
100 | "type", | |
101 | "declaration", | |
102 | "reference", | |
103 | "comparison", | |
104 | "unary", | |
105 | "binary", | |
106 | "statement", | |
c2f47e15 | 107 | "vl_exp", |
75a70cf9 | 108 | "expression" |
a93de1ee | 109 | }; |
ce45a448 | 110 | |
9bfff6cb | 111 | /* obstack.[ch] explicitly declined to prototype this. */ |
60b8c5b3 | 112 | extern int _obstack_allocated_p (struct obstack *h, void *obj); |
10a9d4cf | 113 | |
6d7f57b2 | 114 | #ifdef GATHER_STATISTICS |
10a9d4cf | 115 | /* Statistics-gathering stuff. */ |
1bb37c35 | 116 | |
9bfff6cb | 117 | int tree_node_counts[(int) all_kinds]; |
118 | int tree_node_sizes[(int) all_kinds]; | |
1bb37c35 | 119 | |
b4b174c3 | 120 | /* Keep in sync with tree.h:enum tree_node_kind. */ |
43182305 | 121 | static const char * const tree_node_kind_names[] = { |
1bb37c35 | 122 | "decls", |
123 | "types", | |
124 | "blocks", | |
125 | "stmts", | |
126 | "refs", | |
127 | "exprs", | |
128 | "constants", | |
129 | "identifiers", | |
1bb37c35 | 130 | "perm_tree_lists", |
131 | "temp_tree_lists", | |
132 | "vecs", | |
3cb98335 | 133 | "binfos", |
4ee9c684 | 134 | "ssa names", |
c75b4594 | 135 | "constructors", |
1bb37c35 | 136 | "random kinds", |
137 | "lang_decl kinds", | |
55d6e7cd | 138 | "lang_type kinds", |
35cc02b5 | 139 | "omp clauses", |
1bb37c35 | 140 | }; |
6d7f57b2 | 141 | #endif /* GATHER_STATISTICS */ |
10a9d4cf | 142 | |
6053ec2b | 143 | /* Unique id for next decl created. */ |
f61c5461 | 144 | static GTY(()) int next_decl_uid; |
5beefc7b | 145 | /* Unique id for next type created. */ |
f61c5461 | 146 | static GTY(()) int next_type_uid = 1; |
6053ec2b | 147 | |
f2d83427 | 148 | /* Since we cannot rehash a type after it is in the table, we have to |
149 | keep the hash code. */ | |
a7b0c170 | 150 | |
1f3233d1 | 151 | struct type_hash GTY(()) |
a7b0c170 | 152 | { |
f2d83427 | 153 | unsigned long hash; |
154 | tree type; | |
a7b0c170 | 155 | }; |
156 | ||
9bfff6cb | 157 | /* Initial size of the hash table (rounded to next prime). */ |
f2d83427 | 158 | #define TYPE_HASH_INITIAL_SIZE 1000 |
a7b0c170 | 159 | |
f2d83427 | 160 | /* Now here is the hash table. When recording a type, it is added to |
161 | the slot whose index is the hash code. Note that the hash table is | |
162 | used for several kinds of types (function types, array types and | |
163 | array index range types, for now). While all these live in the | |
164 | same table, they are completely independent, and the hash code is | |
165 | computed differently for each of these. */ | |
166 | ||
1f3233d1 | 167 | static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash))) |
168 | htab_t type_hash_table; | |
a7b0c170 | 169 | |
743771b6 | 170 | /* Hash table and temporary node for larger integer const values. */ |
171 | static GTY (()) tree int_cst_node; | |
172 | static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node))) | |
173 | htab_t int_cst_hash_table; | |
174 | ||
46f8e3b0 | 175 | /* Hash table for optimization flags and target option flags. Use the same |
176 | hash table for both sets of options. Nodes for building the current | |
177 | optimization and target option nodes. The assumption is most of the time | |
178 | the options created will already be in the hash table, so we avoid | |
179 | allocating and freeing up a node repeatably. */ | |
180 | static GTY (()) tree cl_optimization_node; | |
181 | static GTY (()) tree cl_target_option_node; | |
182 | static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node))) | |
183 | htab_t cl_option_hash_table; | |
184 | ||
8bc1e6ff | 185 | /* General tree->tree mapping structure for use in hash tables. */ |
186 | ||
8bc1e6ff | 187 | |
188 | static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) | |
189 | htab_t debug_expr_for_decl; | |
190 | ||
75fa4f82 | 191 | static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) |
192 | htab_t value_expr_for_decl; | |
193 | ||
9af7fd5b | 194 | static GTY ((if_marked ("tree_priority_map_marked_p"), |
195 | param_is (struct tree_priority_map))) | |
5ded8c6f | 196 | htab_t init_priority_for_decl; |
197 | ||
83b34c62 | 198 | static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) |
199 | htab_t restrict_base_for_decl; | |
200 | ||
60b8c5b3 | 201 | static void set_type_quals (tree, int); |
60b8c5b3 | 202 | static int type_hash_eq (const void *, const void *); |
203 | static hashval_t type_hash_hash (const void *); | |
743771b6 | 204 | static hashval_t int_cst_hash_hash (const void *); |
205 | static int int_cst_hash_eq (const void *, const void *); | |
46f8e3b0 | 206 | static hashval_t cl_option_hash_hash (const void *); |
207 | static int cl_option_hash_eq (const void *, const void *); | |
60b8c5b3 | 208 | static void print_type_hash_statistics (void); |
8bc1e6ff | 209 | static void print_debug_expr_statistics (void); |
75fa4f82 | 210 | static void print_value_expr_statistics (void); |
60b8c5b3 | 211 | static int type_hash_marked_p (const void *); |
720082dc | 212 | static unsigned int type_hash_list (const_tree, hashval_t); |
213 | static unsigned int attribute_hash_list (const_tree, hashval_t); | |
5f9979a2 | 214 | |
775e7cc0 | 215 | tree global_trees[TI_MAX]; |
b06898ca | 216 | tree integer_types[itk_none]; |
8bc1e6ff | 217 | |
5ca99950 | 218 | unsigned char tree_contains_struct[MAX_TREE_CODES][64]; |
55d6e7cd | 219 | |
220 | /* Number of operands for each OpenMP clause. */ | |
221 | unsigned const char omp_clause_num_ops[] = | |
222 | { | |
223 | 0, /* OMP_CLAUSE_ERROR */ | |
224 | 1, /* OMP_CLAUSE_PRIVATE */ | |
225 | 1, /* OMP_CLAUSE_SHARED */ | |
226 | 1, /* OMP_CLAUSE_FIRSTPRIVATE */ | |
fd6481cf | 227 | 2, /* OMP_CLAUSE_LASTPRIVATE */ |
55d6e7cd | 228 | 4, /* OMP_CLAUSE_REDUCTION */ |
229 | 1, /* OMP_CLAUSE_COPYIN */ | |
230 | 1, /* OMP_CLAUSE_COPYPRIVATE */ | |
231 | 1, /* OMP_CLAUSE_IF */ | |
232 | 1, /* OMP_CLAUSE_NUM_THREADS */ | |
233 | 1, /* OMP_CLAUSE_SCHEDULE */ | |
234 | 0, /* OMP_CLAUSE_NOWAIT */ | |
235 | 0, /* OMP_CLAUSE_ORDERED */ | |
fd6481cf | 236 | 0, /* OMP_CLAUSE_DEFAULT */ |
237 | 3, /* OMP_CLAUSE_COLLAPSE */ | |
238 | 0 /* OMP_CLAUSE_UNTIED */ | |
55d6e7cd | 239 | }; |
240 | ||
241 | const char * const omp_clause_code_name[] = | |
242 | { | |
243 | "error_clause", | |
244 | "private", | |
245 | "shared", | |
246 | "firstprivate", | |
247 | "lastprivate", | |
248 | "reduction", | |
249 | "copyin", | |
250 | "copyprivate", | |
251 | "if", | |
252 | "num_threads", | |
253 | "schedule", | |
254 | "nowait", | |
255 | "ordered", | |
fd6481cf | 256 | "default", |
257 | "collapse", | |
258 | "untied" | |
55d6e7cd | 259 | }; |
775e7cc0 | 260 | \f |
92192583 | 261 | /* Init tree.c. */ |
10a9d4cf | 262 | |
263 | void | |
60b8c5b3 | 264 | init_ttree (void) |
10a9d4cf | 265 | { |
083a2b5e | 266 | /* Initialize the hash table of types. */ |
573aba85 | 267 | type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash, |
268 | type_hash_eq, 0); | |
8bc1e6ff | 269 | |
270 | debug_expr_for_decl = htab_create_ggc (512, tree_map_hash, | |
271 | tree_map_eq, 0); | |
272 | ||
75fa4f82 | 273 | value_expr_for_decl = htab_create_ggc (512, tree_map_hash, |
274 | tree_map_eq, 0); | |
9af7fd5b | 275 | init_priority_for_decl = htab_create_ggc (512, tree_priority_map_hash, |
276 | tree_priority_map_eq, 0); | |
83b34c62 | 277 | restrict_base_for_decl = htab_create_ggc (256, tree_map_hash, |
278 | tree_map_eq, 0); | |
75fa4f82 | 279 | |
743771b6 | 280 | int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash, |
281 | int_cst_hash_eq, NULL); | |
8bc1e6ff | 282 | |
743771b6 | 283 | int_cst_node = make_node (INTEGER_CST); |
8bc1e6ff | 284 | |
46f8e3b0 | 285 | cl_option_hash_table = htab_create_ggc (64, cl_option_hash_hash, |
286 | cl_option_hash_eq, NULL); | |
287 | ||
288 | cl_optimization_node = make_node (OPTIMIZATION_NODE); | |
289 | cl_target_option_node = make_node (TARGET_OPTION_NODE); | |
290 | ||
5ded8c6f | 291 | tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON] = 1; |
292 | tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_NON_COMMON] = 1; | |
293 | tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON] = 1; | |
294 | ||
295 | ||
296 | tree_contains_struct[CONST_DECL][TS_DECL_COMMON] = 1; | |
297 | tree_contains_struct[VAR_DECL][TS_DECL_COMMON] = 1; | |
298 | tree_contains_struct[PARM_DECL][TS_DECL_COMMON] = 1; | |
299 | tree_contains_struct[RESULT_DECL][TS_DECL_COMMON] = 1; | |
300 | tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON] = 1; | |
301 | tree_contains_struct[TYPE_DECL][TS_DECL_COMMON] = 1; | |
302 | tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON] = 1; | |
303 | tree_contains_struct[LABEL_DECL][TS_DECL_COMMON] = 1; | |
304 | tree_contains_struct[FIELD_DECL][TS_DECL_COMMON] = 1; | |
305 | ||
306 | ||
307 | tree_contains_struct[CONST_DECL][TS_DECL_WRTL] = 1; | |
308 | tree_contains_struct[VAR_DECL][TS_DECL_WRTL] = 1; | |
309 | tree_contains_struct[PARM_DECL][TS_DECL_WRTL] = 1; | |
310 | tree_contains_struct[RESULT_DECL][TS_DECL_WRTL] = 1; | |
311 | tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL] = 1; | |
312 | tree_contains_struct[LABEL_DECL][TS_DECL_WRTL] = 1; | |
313 | ||
314 | tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL] = 1; | |
315 | tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL] = 1; | |
316 | tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL] = 1; | |
317 | tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL] = 1; | |
318 | tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL] = 1; | |
319 | tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL] = 1; | |
320 | tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL] = 1; | |
321 | tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL] = 1; | |
322 | tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL] = 1; | |
0b3f639d | 323 | |
5ded8c6f | 324 | tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS] = 1; |
325 | tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS] = 1; | |
326 | tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS] = 1; | |
327 | tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_WITH_VIS] = 1; | |
328 | ||
329 | tree_contains_struct[VAR_DECL][TS_VAR_DECL] = 1; | |
330 | tree_contains_struct[FIELD_DECL][TS_FIELD_DECL] = 1; | |
331 | tree_contains_struct[PARM_DECL][TS_PARM_DECL] = 1; | |
332 | tree_contains_struct[LABEL_DECL][TS_LABEL_DECL] = 1; | |
333 | tree_contains_struct[RESULT_DECL][TS_RESULT_DECL] = 1; | |
334 | tree_contains_struct[CONST_DECL][TS_CONST_DECL] = 1; | |
335 | tree_contains_struct[TYPE_DECL][TS_TYPE_DECL] = 1; | |
336 | tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL] = 1; | |
5d8a39b7 | 337 | tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL] = 1; |
338 | tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON] = 1; | |
5ded8c6f | 339 | |
340 | lang_hooks.init_ts (); | |
10a9d4cf | 341 | } |
342 | ||
10a9d4cf | 343 | \f |
d1f6c8f2 | 344 | /* The name of the object as the assembler will see it (but before any |
345 | translations made by ASM_OUTPUT_LABELREF). Often this is the same | |
346 | as DECL_NAME. It is an IDENTIFIER_NODE. */ | |
347 | tree | |
60b8c5b3 | 348 | decl_assembler_name (tree decl) |
d1f6c8f2 | 349 | { |
350 | if (!DECL_ASSEMBLER_NAME_SET_P (decl)) | |
dc24ddbd | 351 | lang_hooks.set_decl_assembler_name (decl); |
5ded8c6f | 352 | return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name; |
d1f6c8f2 | 353 | } |
354 | ||
1d416bd7 | 355 | /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */ |
356 | ||
357 | bool | |
28485874 | 358 | decl_assembler_name_equal (tree decl, const_tree asmname) |
1d416bd7 | 359 | { |
360 | tree decl_asmname = DECL_ASSEMBLER_NAME (decl); | |
ac2722c5 | 361 | const char *decl_str; |
362 | const char *asmname_str; | |
363 | bool test = false; | |
1d416bd7 | 364 | |
365 | if (decl_asmname == asmname) | |
366 | return true; | |
367 | ||
ac2722c5 | 368 | decl_str = IDENTIFIER_POINTER (decl_asmname); |
369 | asmname_str = IDENTIFIER_POINTER (asmname); | |
370 | ||
371 | ||
1d416bd7 | 372 | /* If the target assembler name was set by the user, things are trickier. |
373 | We have a leading '*' to begin with. After that, it's arguable what | |
374 | is the correct thing to do with -fleading-underscore. Arguably, we've | |
375 | historically been doing the wrong thing in assemble_alias by always | |
376 | printing the leading underscore. Since we're not changing that, make | |
377 | sure user_label_prefix follows the '*' before matching. */ | |
ac2722c5 | 378 | if (decl_str[0] == '*') |
1d416bd7 | 379 | { |
1d416bd7 | 380 | size_t ulp_len = strlen (user_label_prefix); |
381 | ||
ac2722c5 | 382 | decl_str ++; |
383 | ||
1d416bd7 | 384 | if (ulp_len == 0) |
ac2722c5 | 385 | test = true; |
1d416bd7 | 386 | else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0) |
ac2722c5 | 387 | decl_str += ulp_len, test=true; |
1d416bd7 | 388 | else |
ac2722c5 | 389 | decl_str --; |
390 | } | |
391 | if (asmname_str[0] == '*') | |
392 | { | |
393 | size_t ulp_len = strlen (user_label_prefix); | |
394 | ||
395 | asmname_str ++; | |
1d416bd7 | 396 | |
ac2722c5 | 397 | if (ulp_len == 0) |
398 | test = true; | |
399 | else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0) | |
400 | asmname_str += ulp_len, test=true; | |
401 | else | |
402 | asmname_str --; | |
1d416bd7 | 403 | } |
404 | ||
ac2722c5 | 405 | if (!test) |
406 | return false; | |
407 | return strcmp (decl_str, asmname_str) == 0; | |
1d416bd7 | 408 | } |
409 | ||
28485874 | 410 | /* Hash asmnames ignoring the user specified marks. */ |
411 | ||
412 | hashval_t | |
413 | decl_assembler_name_hash (const_tree asmname) | |
414 | { | |
415 | if (IDENTIFIER_POINTER (asmname)[0] == '*') | |
416 | { | |
417 | const char *decl_str = IDENTIFIER_POINTER (asmname) + 1; | |
418 | size_t ulp_len = strlen (user_label_prefix); | |
419 | ||
420 | if (ulp_len == 0) | |
421 | ; | |
422 | else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0) | |
423 | decl_str += ulp_len; | |
424 | ||
425 | return htab_hash_string (decl_str); | |
426 | } | |
427 | ||
428 | return htab_hash_string (IDENTIFIER_POINTER (asmname)); | |
429 | } | |
430 | ||
d5406300 | 431 | /* Compute the number of bytes occupied by a tree with code CODE. |
c2f47e15 | 432 | This function cannot be used for nodes that have variable sizes, |
75a70cf9 | 433 | including TREE_VEC, STRING_CST, and CALL_EXPR. */ |
6663ac46 | 434 | size_t |
51d121a0 | 435 | tree_code_size (enum tree_code code) |
6663ac46 | 436 | { |
6663ac46 | 437 | switch (TREE_CODE_CLASS (code)) |
438 | { | |
ce45a448 | 439 | case tcc_declaration: /* A decl node */ |
5ded8c6f | 440 | { |
441 | switch (code) | |
442 | { | |
443 | case FIELD_DECL: | |
444 | return sizeof (struct tree_field_decl); | |
445 | case PARM_DECL: | |
446 | return sizeof (struct tree_parm_decl); | |
447 | case VAR_DECL: | |
448 | return sizeof (struct tree_var_decl); | |
449 | case LABEL_DECL: | |
450 | return sizeof (struct tree_label_decl); | |
451 | case RESULT_DECL: | |
452 | return sizeof (struct tree_result_decl); | |
453 | case CONST_DECL: | |
454 | return sizeof (struct tree_const_decl); | |
455 | case TYPE_DECL: | |
456 | return sizeof (struct tree_type_decl); | |
457 | case FUNCTION_DECL: | |
458 | return sizeof (struct tree_function_decl); | |
459 | default: | |
460 | return sizeof (struct tree_decl_non_common); | |
461 | } | |
462 | } | |
6663ac46 | 463 | |
ce45a448 | 464 | case tcc_type: /* a type node */ |
6663ac46 | 465 | return sizeof (struct tree_type); |
466 | ||
ce45a448 | 467 | case tcc_reference: /* a reference */ |
468 | case tcc_expression: /* an expression */ | |
469 | case tcc_statement: /* an expression with side effects */ | |
470 | case tcc_comparison: /* a comparison expression */ | |
471 | case tcc_unary: /* a unary arithmetic expression */ | |
472 | case tcc_binary: /* a binary arithmetic expression */ | |
6663ac46 | 473 | return (sizeof (struct tree_exp) |
c2f47e15 | 474 | + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree)); |
6663ac46 | 475 | |
ce45a448 | 476 | case tcc_constant: /* a constant */ |
295e387a | 477 | switch (code) |
478 | { | |
479 | case INTEGER_CST: return sizeof (struct tree_int_cst); | |
480 | case REAL_CST: return sizeof (struct tree_real_cst); | |
06f0b99c | 481 | case FIXED_CST: return sizeof (struct tree_fixed_cst); |
295e387a | 482 | case COMPLEX_CST: return sizeof (struct tree_complex); |
483 | case VECTOR_CST: return sizeof (struct tree_vector); | |
d5406300 | 484 | case STRING_CST: gcc_unreachable (); |
295e387a | 485 | default: |
dc24ddbd | 486 | return lang_hooks.tree_size (code); |
295e387a | 487 | } |
6663ac46 | 488 | |
ce45a448 | 489 | case tcc_exceptional: /* something random, like an identifier. */ |
295e387a | 490 | switch (code) |
491 | { | |
492 | case IDENTIFIER_NODE: return lang_hooks.identifier_size; | |
493 | case TREE_LIST: return sizeof (struct tree_list); | |
295e387a | 494 | |
495 | case ERROR_MARK: | |
496 | case PLACEHOLDER_EXPR: return sizeof (struct tree_common); | |
497 | ||
d5406300 | 498 | case TREE_VEC: |
75a70cf9 | 499 | case OMP_CLAUSE: gcc_unreachable (); |
4ee9c684 | 500 | |
4ee9c684 | 501 | case SSA_NAME: return sizeof (struct tree_ssa_name); |
4ee9c684 | 502 | |
503 | case STATEMENT_LIST: return sizeof (struct tree_statement_list); | |
1acf0298 | 504 | case BLOCK: return sizeof (struct tree_block); |
c75b4594 | 505 | case CONSTRUCTOR: return sizeof (struct tree_constructor); |
46f8e3b0 | 506 | case OPTIMIZATION_NODE: return sizeof (struct tree_optimization_option); |
507 | case TARGET_OPTION_NODE: return sizeof (struct tree_target_option); | |
4ee9c684 | 508 | |
295e387a | 509 | default: |
dc24ddbd | 510 | return lang_hooks.tree_size (code); |
295e387a | 511 | } |
6663ac46 | 512 | |
513 | default: | |
8c0963c4 | 514 | gcc_unreachable (); |
6663ac46 | 515 | } |
516 | } | |
517 | ||
51d121a0 | 518 | /* Compute the number of bytes occupied by NODE. This routine only |
c2f47e15 | 519 | looks at TREE_CODE, except for those nodes that have variable sizes. */ |
51d121a0 | 520 | size_t |
720082dc | 521 | tree_size (const_tree node) |
51d121a0 | 522 | { |
720082dc | 523 | const enum tree_code code = TREE_CODE (node); |
51d121a0 | 524 | switch (code) |
525 | { | |
1e612ca4 | 526 | case TREE_BINFO: |
527 | return (offsetof (struct tree_binfo, base_binfos) | |
528 | + VEC_embedded_size (tree, BINFO_N_BASE_BINFOS (node))); | |
51d121a0 | 529 | |
530 | case TREE_VEC: | |
531 | return (sizeof (struct tree_vec) | |
c2f47e15 | 532 | + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree)); |
51d121a0 | 533 | |
d5406300 | 534 | case STRING_CST: |
4043066e | 535 | return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1; |
d5406300 | 536 | |
55d6e7cd | 537 | case OMP_CLAUSE: |
538 | return (sizeof (struct tree_omp_clause) | |
539 | + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1) | |
540 | * sizeof (tree)); | |
541 | ||
51d121a0 | 542 | default: |
c2f47e15 | 543 | if (TREE_CODE_CLASS (code) == tcc_vl_exp) |
544 | return (sizeof (struct tree_exp) | |
545 | + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree)); | |
546 | else | |
547 | return tree_code_size (code); | |
51d121a0 | 548 | } |
549 | } | |
550 | ||
551 | /* Return a newly allocated node of code CODE. For decl and type | |
552 | nodes, some other fields are initialized. The rest of the node is | |
75a70cf9 | 553 | initialized to zero. This function cannot be used for TREE_VEC or |
554 | OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size. | |
10a9d4cf | 555 | |
556 | Achoo! I got a code in the node. */ | |
557 | ||
558 | tree | |
674b05f5 | 559 | make_node_stat (enum tree_code code MEM_STAT_DECL) |
10a9d4cf | 560 | { |
19cb6b50 | 561 | tree t; |
ce45a448 | 562 | enum tree_code_class type = TREE_CODE_CLASS (code); |
51d121a0 | 563 | size_t length = tree_code_size (code); |
07e64d6e | 564 | #ifdef GATHER_STATISTICS |
19cb6b50 | 565 | tree_node_kind kind; |
709c2f34 | 566 | |
10a9d4cf | 567 | switch (type) |
568 | { | |
ce45a448 | 569 | case tcc_declaration: /* A decl node */ |
10a9d4cf | 570 | kind = d_kind; |
10a9d4cf | 571 | break; |
572 | ||
ce45a448 | 573 | case tcc_type: /* a type node */ |
10a9d4cf | 574 | kind = t_kind; |
10a9d4cf | 575 | break; |
576 | ||
ce45a448 | 577 | case tcc_statement: /* an expression with side effects */ |
10a9d4cf | 578 | kind = s_kind; |
6663ac46 | 579 | break; |
580 | ||
ce45a448 | 581 | case tcc_reference: /* a reference */ |
10a9d4cf | 582 | kind = r_kind; |
6663ac46 | 583 | break; |
584 | ||
ce45a448 | 585 | case tcc_expression: /* an expression */ |
586 | case tcc_comparison: /* a comparison expression */ | |
587 | case tcc_unary: /* a unary arithmetic expression */ | |
588 | case tcc_binary: /* a binary arithmetic expression */ | |
10a9d4cf | 589 | kind = e_kind; |
10a9d4cf | 590 | break; |
591 | ||
ce45a448 | 592 | case tcc_constant: /* a constant */ |
10a9d4cf | 593 | kind = c_kind; |
56ad1c9b | 594 | break; |
10a9d4cf | 595 | |
ce45a448 | 596 | case tcc_exceptional: /* something random, like an identifier. */ |
83e38fdd | 597 | switch (code) |
598 | { | |
599 | case IDENTIFIER_NODE: | |
600 | kind = id_kind; | |
601 | break; | |
602 | ||
c75b4594 | 603 | case TREE_VEC: |
83e38fdd | 604 | kind = vec_kind; |
605 | break; | |
606 | ||
607 | case TREE_BINFO: | |
608 | kind = binfo_kind; | |
609 | break; | |
610 | ||
83e38fdd | 611 | case SSA_NAME: |
612 | kind = ssa_name_kind; | |
613 | break; | |
614 | ||
615 | case BLOCK: | |
616 | kind = b_kind; | |
617 | break; | |
618 | ||
c75b4594 | 619 | case CONSTRUCTOR: |
620 | kind = constr_kind; | |
621 | break; | |
622 | ||
83e38fdd | 623 | default: |
624 | kind = x_kind; | |
625 | break; | |
626 | } | |
49ca1fcd | 627 | break; |
83e38fdd | 628 | |
629 | default: | |
630 | gcc_unreachable (); | |
10a9d4cf | 631 | } |
632 | ||
9bfff6cb | 633 | tree_node_counts[(int) kind]++; |
634 | tree_node_sizes[(int) kind] += length; | |
10a9d4cf | 635 | #endif |
636 | ||
1bb42c87 | 637 | if (code == IDENTIFIER_NODE) |
45ba1503 | 638 | t = (tree) ggc_alloc_zone_pass_stat (length, &tree_id_zone); |
1bb42c87 | 639 | else |
45ba1503 | 640 | t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); |
6663ac46 | 641 | |
b9a7cc69 | 642 | memset (t, 0, length); |
6663ac46 | 643 | |
10a9d4cf | 644 | TREE_SET_CODE (t, code); |
10a9d4cf | 645 | |
646 | switch (type) | |
647 | { | |
ce45a448 | 648 | case tcc_statement: |
10a9d4cf | 649 | TREE_SIDE_EFFECTS (t) = 1; |
10a9d4cf | 650 | break; |
651 | ||
ce45a448 | 652 | case tcc_declaration: |
437f5d6b | 653 | if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON)) |
654 | { | |
6c96b31e | 655 | if (code == FUNCTION_DECL) |
656 | { | |
657 | DECL_ALIGN (t) = FUNCTION_BOUNDARY; | |
658 | DECL_MODE (t) = FUNCTION_MODE; | |
659 | } | |
660 | else | |
437f5d6b | 661 | DECL_ALIGN (t) = 1; |
437f5d6b | 662 | /* We have not yet computed the alias set for this declaration. */ |
663 | DECL_POINTER_ALIAS_SET (t) = -1; | |
664 | } | |
346064d9 | 665 | DECL_SOURCE_LOCATION (t) = input_location; |
ae0686dd | 666 | DECL_UID (t) = next_decl_uid++; |
94733307 | 667 | |
10a9d4cf | 668 | break; |
669 | ||
ce45a448 | 670 | case tcc_type: |
5beefc7b | 671 | TYPE_UID (t) = next_type_uid++; |
d1b5d503 | 672 | TYPE_ALIGN (t) = BITS_PER_UNIT; |
aca14577 | 673 | TYPE_USER_ALIGN (t) = 0; |
10a9d4cf | 674 | TYPE_MAIN_VARIANT (t) = t; |
6753bca0 | 675 | TYPE_CANONICAL (t) = t; |
94733307 | 676 | |
677 | /* Default to no attributes for type, but let target change that. */ | |
9dd95dae | 678 | TYPE_ATTRIBUTES (t) = NULL_TREE; |
883b2e73 | 679 | targetm.set_default_type_attributes (t); |
94733307 | 680 | |
681 | /* We have not yet computed the alias set for this type. */ | |
b5ba9f3a | 682 | TYPE_ALIAS_SET (t) = -1; |
10a9d4cf | 683 | break; |
684 | ||
ce45a448 | 685 | case tcc_constant: |
10a9d4cf | 686 | TREE_CONSTANT (t) = 1; |
687 | break; | |
e5b44228 | 688 | |
ce45a448 | 689 | case tcc_expression: |
e5b44228 | 690 | switch (code) |
691 | { | |
692 | case INIT_EXPR: | |
693 | case MODIFY_EXPR: | |
694 | case VA_ARG_EXPR: | |
e5b44228 | 695 | case PREDECREMENT_EXPR: |
696 | case PREINCREMENT_EXPR: | |
697 | case POSTDECREMENT_EXPR: | |
698 | case POSTINCREMENT_EXPR: | |
699 | /* All of these have side-effects, no matter what their | |
700 | operands are. */ | |
701 | TREE_SIDE_EFFECTS (t) = 1; | |
702 | break; | |
9bfff6cb | 703 | |
e5b44228 | 704 | default: |
705 | break; | |
706 | } | |
707 | break; | |
ce45a448 | 708 | |
709 | default: | |
710 | /* Other classes need no special treatment. */ | |
711 | break; | |
10a9d4cf | 712 | } |
713 | ||
714 | return t; | |
715 | } | |
716 | \f | |
fa6f5153 | 717 | /* Return a new node with the same contents as NODE except that its |
6ba31ca8 | 718 | TREE_CHAIN is zero and it has a fresh uid. */ |
10a9d4cf | 719 | |
720 | tree | |
674b05f5 | 721 | copy_node_stat (tree node MEM_STAT_DECL) |
10a9d4cf | 722 | { |
19cb6b50 | 723 | tree t; |
724 | enum tree_code code = TREE_CODE (node); | |
725 | size_t length; | |
10a9d4cf | 726 | |
8c0963c4 | 727 | gcc_assert (code != STATEMENT_LIST); |
4ee9c684 | 728 | |
6663ac46 | 729 | length = tree_size (node); |
45ba1503 | 730 | t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); |
86f9e2d8 | 731 | memcpy (t, node, length); |
10a9d4cf | 732 | |
75a70cf9 | 733 | TREE_CHAIN (t) = 0; |
d40095a0 | 734 | TREE_ASM_WRITTEN (t) = 0; |
4ee9c684 | 735 | TREE_VISITED (t) = 0; |
35cc02b5 | 736 | t->base.ann = 0; |
10a9d4cf | 737 | |
ce45a448 | 738 | if (TREE_CODE_CLASS (code) == tcc_declaration) |
75fa4f82 | 739 | { |
740 | DECL_UID (t) = next_decl_uid++; | |
741 | if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL) | |
742 | && DECL_HAS_VALUE_EXPR_P (node)) | |
743 | { | |
744 | SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node)); | |
745 | DECL_HAS_VALUE_EXPR_P (t) = 1; | |
746 | } | |
5ded8c6f | 747 | if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node)) |
748 | { | |
749 | SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node)); | |
750 | DECL_HAS_INIT_PRIORITY_P (t) = 1; | |
751 | } | |
83b34c62 | 752 | if (TREE_CODE (node) == VAR_DECL && DECL_BASED_ON_RESTRICT_P (node)) |
753 | { | |
754 | SET_DECL_RESTRICT_BASE (t, DECL_GET_RESTRICT_BASE (node)); | |
755 | DECL_BASED_ON_RESTRICT_P (t) = 1; | |
756 | } | |
75fa4f82 | 757 | } |
ce45a448 | 758 | else if (TREE_CODE_CLASS (code) == tcc_type) |
0b56cc51 | 759 | { |
760 | TYPE_UID (t) = next_type_uid++; | |
29cabea4 | 761 | /* The following is so that the debug code for |
762 | the copy is different from the original type. | |
763 | The two statements usually duplicate each other | |
764 | (because they clear fields of the same union), | |
a92771b8 | 765 | but the optimizer should catch that. */ |
29cabea4 | 766 | TYPE_SYMTAB_POINTER (t) = 0; |
767 | TYPE_SYMTAB_ADDRESS (t) = 0; | |
1561d3cd | 768 | |
769 | /* Do not copy the values cache. */ | |
770 | if (TYPE_CACHED_VALUES_P(t)) | |
771 | { | |
772 | TYPE_CACHED_VALUES_P (t) = 0; | |
773 | TYPE_CACHED_VALUES (t) = NULL_TREE; | |
774 | } | |
0b56cc51 | 775 | } |
5beefc7b | 776 | |
10a9d4cf | 777 | return t; |
778 | } | |
779 | ||
780 | /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field. | |
781 | For example, this can copy a list made of TREE_LIST nodes. */ | |
782 | ||
783 | tree | |
60b8c5b3 | 784 | copy_list (tree list) |
10a9d4cf | 785 | { |
786 | tree head; | |
19cb6b50 | 787 | tree prev, next; |
10a9d4cf | 788 | |
789 | if (list == 0) | |
790 | return 0; | |
791 | ||
792 | head = prev = copy_node (list); | |
793 | next = TREE_CHAIN (list); | |
794 | while (next) | |
795 | { | |
796 | TREE_CHAIN (prev) = copy_node (next); | |
797 | prev = TREE_CHAIN (prev); | |
798 | next = TREE_CHAIN (next); | |
799 | } | |
800 | return head; | |
801 | } | |
6efd403b | 802 | |
10a9d4cf | 803 | \f |
7016c612 | 804 | /* Create an INT_CST node with a LOW value sign extended. */ |
805 | ||
9d0db5ea | 806 | tree |
807 | build_int_cst (tree type, HOST_WIDE_INT low) | |
7016c612 | 808 | { |
167a3fa5 | 809 | /* Support legacy code. */ |
810 | if (!type) | |
811 | type = integer_type_node; | |
812 | ||
95a4a2f1 | 813 | return build_int_cst_wide (type, low, low < 0 ? -1 : 0); |
7016c612 | 814 | } |
815 | ||
816 | /* Create an INT_CST node with a LOW value zero extended. */ | |
817 | ||
9d0db5ea | 818 | tree |
819 | build_int_cstu (tree type, unsigned HOST_WIDE_INT low) | |
7016c612 | 820 | { |
821 | return build_int_cst_wide (type, low, 0); | |
822 | } | |
823 | ||
b7584afd | 824 | /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended |
825 | if it is negative. This function is similar to build_int_cst, but | |
826 | the extra bits outside of the type precision are cleared. Constants | |
827 | with these extra bits may confuse the fold so that it detects overflows | |
828 | even in cases when they do not occur, and in general should be avoided. | |
829 | We cannot however make this a default behavior of build_int_cst without | |
830 | more intrusive changes, since there are parts of gcc that rely on the extra | |
831 | precision of the integer constants. */ | |
dec41e98 | 832 | |
833 | tree | |
834 | build_int_cst_type (tree type, HOST_WIDE_INT low) | |
835 | { | |
ca9b061d | 836 | unsigned HOST_WIDE_INT low1; |
837 | HOST_WIDE_INT hi; | |
dec41e98 | 838 | |
ca9b061d | 839 | gcc_assert (type); |
b7584afd | 840 | |
ca9b061d | 841 | fit_double_type (low, low < 0 ? -1 : 0, &low1, &hi, type); |
dec41e98 | 842 | |
ca9b061d | 843 | return build_int_cst_wide (type, low1, hi); |
dec41e98 | 844 | } |
845 | ||
697bbc3f | 846 | /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated |
847 | and sign extended according to the value range of TYPE. */ | |
848 | ||
849 | tree | |
850 | build_int_cst_wide_type (tree type, | |
851 | unsigned HOST_WIDE_INT low, HOST_WIDE_INT high) | |
852 | { | |
853 | fit_double_type (low, high, &low, &high, type); | |
854 | return build_int_cst_wide (type, low, high); | |
855 | } | |
856 | ||
743771b6 | 857 | /* These are the hash table functions for the hash table of INTEGER_CST |
858 | nodes of a sizetype. */ | |
859 | ||
860 | /* Return the hash code code X, an INTEGER_CST. */ | |
861 | ||
862 | static hashval_t | |
863 | int_cst_hash_hash (const void *x) | |
864 | { | |
aae87fc3 | 865 | const_tree const t = (const_tree) x; |
743771b6 | 866 | |
867 | return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t) | |
868 | ^ htab_hash_pointer (TREE_TYPE (t))); | |
869 | } | |
870 | ||
871 | /* Return nonzero if the value represented by *X (an INTEGER_CST tree node) | |
872 | is the same as that given by *Y, which is the same. */ | |
873 | ||
874 | static int | |
875 | int_cst_hash_eq (const void *x, const void *y) | |
876 | { | |
aae87fc3 | 877 | const_tree const xt = (const_tree) x; |
878 | const_tree const yt = (const_tree) y; | |
743771b6 | 879 | |
880 | return (TREE_TYPE (xt) == TREE_TYPE (yt) | |
881 | && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt) | |
882 | && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt)); | |
883 | } | |
884 | ||
697bbc3f | 885 | /* Create an INT_CST node of TYPE and value HI:LOW. |
886 | The returned node is always shared. For small integers we use a | |
887 | per-type vector cache, for larger ones we use a single hash table. */ | |
10a9d4cf | 888 | |
889 | tree | |
7016c612 | 890 | build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi) |
10a9d4cf | 891 | { |
7c446c95 | 892 | tree t; |
00b76131 | 893 | int ix = -1; |
894 | int limit = 0; | |
7c446c95 | 895 | |
167a3fa5 | 896 | gcc_assert (type); |
ac13e8d9 | 897 | |
00b76131 | 898 | switch (TREE_CODE (type)) |
899 | { | |
900 | case POINTER_TYPE: | |
901 | case REFERENCE_TYPE: | |
902 | /* Cache NULL pointer. */ | |
903 | if (!hi && !low) | |
904 | { | |
905 | limit = 1; | |
906 | ix = 0; | |
907 | } | |
908 | break; | |
ac13e8d9 | 909 | |
00b76131 | 910 | case BOOLEAN_TYPE: |
911 | /* Cache false or true. */ | |
912 | limit = 2; | |
913 | if (!hi && low < 2) | |
914 | ix = low; | |
915 | break; | |
ac13e8d9 | 916 | |
00b76131 | 917 | case INTEGER_TYPE: |
00b76131 | 918 | case OFFSET_TYPE: |
919 | if (TYPE_UNSIGNED (type)) | |
920 | { | |
921 | /* Cache 0..N */ | |
922 | limit = INTEGER_SHARE_LIMIT; | |
923 | if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT) | |
924 | ix = low; | |
925 | } | |
926 | else | |
927 | { | |
928 | /* Cache -1..N */ | |
929 | limit = INTEGER_SHARE_LIMIT + 1; | |
930 | if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT) | |
931 | ix = low + 1; | |
932 | else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1) | |
933 | ix = 0; | |
934 | } | |
935 | break; | |
aae57ecf | 936 | |
937 | case ENUMERAL_TYPE: | |
00b76131 | 938 | break; |
aae57ecf | 939 | |
940 | default: | |
941 | gcc_unreachable (); | |
00b76131 | 942 | } |
ac13e8d9 | 943 | |
00b76131 | 944 | if (ix >= 0) |
945 | { | |
743771b6 | 946 | /* Look for it in the type's vector of small shared ints. */ |
00b76131 | 947 | if (!TYPE_CACHED_VALUES_P (type)) |
948 | { | |
949 | TYPE_CACHED_VALUES_P (type) = 1; | |
950 | TYPE_CACHED_VALUES (type) = make_tree_vec (limit); | |
951 | } | |
ac13e8d9 | 952 | |
00b76131 | 953 | t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix); |
954 | if (t) | |
955 | { | |
956 | /* Make sure no one is clobbering the shared constant. */ | |
8c0963c4 | 957 | gcc_assert (TREE_TYPE (t) == type); |
958 | gcc_assert (TREE_INT_CST_LOW (t) == low); | |
959 | gcc_assert (TREE_INT_CST_HIGH (t) == hi); | |
743771b6 | 960 | } |
961 | else | |
962 | { | |
963 | /* Create a new shared int. */ | |
964 | t = make_node (INTEGER_CST); | |
965 | ||
966 | TREE_INT_CST_LOW (t) = low; | |
967 | TREE_INT_CST_HIGH (t) = hi; | |
968 | TREE_TYPE (t) = type; | |
969 | ||
970 | TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t; | |
00b76131 | 971 | } |
972 | } | |
743771b6 | 973 | else |
974 | { | |
975 | /* Use the cache of larger shared ints. */ | |
976 | void **slot; | |
ac13e8d9 | 977 | |
743771b6 | 978 | TREE_INT_CST_LOW (int_cst_node) = low; |
979 | TREE_INT_CST_HIGH (int_cst_node) = hi; | |
980 | TREE_TYPE (int_cst_node) = type; | |
00b76131 | 981 | |
743771b6 | 982 | slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT); |
45ba1503 | 983 | t = (tree) *slot; |
743771b6 | 984 | if (!t) |
985 | { | |
986 | /* Insert this one into the hash table. */ | |
987 | t = int_cst_node; | |
988 | *slot = t; | |
989 | /* Make a new node for next time round. */ | |
990 | int_cst_node = make_node (INTEGER_CST); | |
991 | } | |
992 | } | |
ac13e8d9 | 993 | |
10a9d4cf | 994 | return t; |
995 | } | |
996 | ||
dede8dcc | 997 | /* Builds an integer constant in TYPE such that lowest BITS bits are ones |
998 | and the rest are zeros. */ | |
999 | ||
1000 | tree | |
1001 | build_low_bits_mask (tree type, unsigned bits) | |
1002 | { | |
1003 | unsigned HOST_WIDE_INT low; | |
1004 | HOST_WIDE_INT high; | |
1005 | unsigned HOST_WIDE_INT all_ones = ~(unsigned HOST_WIDE_INT) 0; | |
1006 | ||
1007 | gcc_assert (bits <= TYPE_PRECISION (type)); | |
1008 | ||
1009 | if (bits == TYPE_PRECISION (type) | |
1010 | && !TYPE_UNSIGNED (type)) | |
1011 | { | |
1012 | /* Sign extended all-ones mask. */ | |
1013 | low = all_ones; | |
1014 | high = -1; | |
1015 | } | |
1016 | else if (bits <= HOST_BITS_PER_WIDE_INT) | |
1017 | { | |
1018 | low = all_ones >> (HOST_BITS_PER_WIDE_INT - bits); | |
1019 | high = 0; | |
1020 | } | |
1021 | else | |
1022 | { | |
1023 | bits -= HOST_BITS_PER_WIDE_INT; | |
1024 | low = all_ones; | |
1025 | high = all_ones >> (HOST_BITS_PER_WIDE_INT - bits); | |
1026 | } | |
1027 | ||
1028 | return build_int_cst_wide (type, low, high); | |
1029 | } | |
1030 | ||
dec41e98 | 1031 | /* Checks that X is integer constant that can be expressed in (unsigned) |
1032 | HOST_WIDE_INT without loss of precision. */ | |
1033 | ||
1034 | bool | |
720082dc | 1035 | cst_and_fits_in_hwi (const_tree x) |
dec41e98 | 1036 | { |
1037 | if (TREE_CODE (x) != INTEGER_CST) | |
1038 | return false; | |
1039 | ||
1040 | if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT) | |
1041 | return false; | |
1042 | ||
1043 | return (TREE_INT_CST_HIGH (x) == 0 | |
1044 | || TREE_INT_CST_HIGH (x) == -1); | |
1045 | } | |
1046 | ||
886cfd4f | 1047 | /* Return a new VECTOR_CST node whose type is TYPE and whose values |
5206b159 | 1048 | are in a list pointed to by VALS. */ |
886cfd4f | 1049 | |
1050 | tree | |
60b8c5b3 | 1051 | build_vector (tree type, tree vals) |
886cfd4f | 1052 | { |
1053 | tree v = make_node (VECTOR_CST); | |
f96bd2bf | 1054 | int over = 0; |
886cfd4f | 1055 | tree link; |
1056 | ||
1057 | TREE_VECTOR_CST_ELTS (v) = vals; | |
1058 | TREE_TYPE (v) = type; | |
1059 | ||
1060 | /* Iterate through elements and check for overflow. */ | |
1061 | for (link = vals; link; link = TREE_CHAIN (link)) | |
1062 | { | |
1063 | tree value = TREE_VALUE (link); | |
1064 | ||
96d5c2e2 | 1065 | /* Don't crash if we get an address constant. */ |
1066 | if (!CONSTANT_CLASS_P (value)) | |
1067 | continue; | |
1068 | ||
f96bd2bf | 1069 | over |= TREE_OVERFLOW (value); |
886cfd4f | 1070 | } |
709c2f34 | 1071 | |
f96bd2bf | 1072 | TREE_OVERFLOW (v) = over; |
886cfd4f | 1073 | return v; |
1074 | } | |
1075 | ||
c75b4594 | 1076 | /* Return a new VECTOR_CST node whose type is TYPE and whose values |
1077 | are extracted from V, a vector of CONSTRUCTOR_ELT. */ | |
1078 | ||
1079 | tree | |
1080 | build_vector_from_ctor (tree type, VEC(constructor_elt,gc) *v) | |
1081 | { | |
1082 | tree list = NULL_TREE; | |
1083 | unsigned HOST_WIDE_INT idx; | |
1084 | tree value; | |
1085 | ||
1086 | FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value) | |
1087 | list = tree_cons (NULL_TREE, value, list); | |
1088 | return build_vector (type, nreverse (list)); | |
1089 | } | |
1090 | ||
46518bf2 | 1091 | /* Return a new CONSTRUCTOR node whose type is TYPE and whose values |
5206b159 | 1092 | are in the VEC pointed to by VALS. */ |
46518bf2 | 1093 | tree |
c75b4594 | 1094 | build_constructor (tree type, VEC(constructor_elt,gc) *vals) |
46518bf2 | 1095 | { |
1096 | tree c = make_node (CONSTRUCTOR); | |
1097 | TREE_TYPE (c) = type; | |
1098 | CONSTRUCTOR_ELTS (c) = vals; | |
c75b4594 | 1099 | return c; |
1100 | } | |
1101 | ||
1102 | /* Build a CONSTRUCTOR node made of a single initializer, with the specified | |
1103 | INDEX and VALUE. */ | |
1104 | tree | |
1105 | build_constructor_single (tree type, tree index, tree value) | |
1106 | { | |
1107 | VEC(constructor_elt,gc) *v; | |
1108 | constructor_elt *elt; | |
9fd22806 | 1109 | tree t; |
c75b4594 | 1110 | |
1111 | v = VEC_alloc (constructor_elt, gc, 1); | |
1112 | elt = VEC_quick_push (constructor_elt, v, NULL); | |
1113 | elt->index = index; | |
1114 | elt->value = value; | |
1115 | ||
9fd22806 | 1116 | t = build_constructor (type, v); |
1117 | TREE_CONSTANT (t) = TREE_CONSTANT (value); | |
1118 | return t; | |
c75b4594 | 1119 | } |
1120 | ||
1121 | ||
1122 | /* Return a new CONSTRUCTOR node whose type is TYPE and whose values | |
1123 | are in a list pointed to by VALS. */ | |
1124 | tree | |
1125 | build_constructor_from_list (tree type, tree vals) | |
1126 | { | |
9fd22806 | 1127 | tree t, val; |
c75b4594 | 1128 | VEC(constructor_elt,gc) *v = NULL; |
9fd22806 | 1129 | bool constant_p = true; |
46518bf2 | 1130 | |
46518bf2 | 1131 | if (vals) |
1132 | { | |
c75b4594 | 1133 | v = VEC_alloc (constructor_elt, gc, list_length (vals)); |
1134 | for (t = vals; t; t = TREE_CHAIN (t)) | |
1135 | { | |
1136 | constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL); | |
9fd22806 | 1137 | val = TREE_VALUE (t); |
c75b4594 | 1138 | elt->index = TREE_PURPOSE (t); |
9fd22806 | 1139 | elt->value = val; |
1140 | if (!TREE_CONSTANT (val)) | |
1141 | constant_p = false; | |
c75b4594 | 1142 | } |
46518bf2 | 1143 | } |
46518bf2 | 1144 | |
9fd22806 | 1145 | t = build_constructor (type, v); |
1146 | TREE_CONSTANT (t) = constant_p; | |
1147 | return t; | |
46518bf2 | 1148 | } |
1149 | ||
06f0b99c | 1150 | /* Return a new FIXED_CST node whose type is TYPE and value is F. */ |
1151 | ||
1152 | tree | |
1153 | build_fixed (tree type, FIXED_VALUE_TYPE f) | |
1154 | { | |
1155 | tree v; | |
1156 | FIXED_VALUE_TYPE *fp; | |
1157 | ||
1158 | v = make_node (FIXED_CST); | |
45ba1503 | 1159 | fp = GGC_NEW (FIXED_VALUE_TYPE); |
06f0b99c | 1160 | memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE)); |
1161 | ||
1162 | TREE_TYPE (v) = type; | |
1163 | TREE_FIXED_CST_PTR (v) = fp; | |
1164 | return v; | |
1165 | } | |
c75b4594 | 1166 | |
10a9d4cf | 1167 | /* Return a new REAL_CST node whose type is TYPE and value is D. */ |
1168 | ||
1169 | tree | |
60b8c5b3 | 1170 | build_real (tree type, REAL_VALUE_TYPE d) |
10a9d4cf | 1171 | { |
1172 | tree v; | |
ef258422 | 1173 | REAL_VALUE_TYPE *dp; |
e31c27ad | 1174 | int overflow = 0; |
10a9d4cf | 1175 | |
aa870c1b | 1176 | /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE. |
1177 | Consider doing it via real_convert now. */ | |
10a9d4cf | 1178 | |
1179 | v = make_node (REAL_CST); | |
45ba1503 | 1180 | dp = GGC_NEW (REAL_VALUE_TYPE); |
ef258422 | 1181 | memcpy (dp, &d, sizeof (REAL_VALUE_TYPE)); |
6c34d0c2 | 1182 | |
10a9d4cf | 1183 | TREE_TYPE (v) = type; |
ef258422 | 1184 | TREE_REAL_CST_PTR (v) = dp; |
f96bd2bf | 1185 | TREE_OVERFLOW (v) = overflow; |
10a9d4cf | 1186 | return v; |
1187 | } | |
1188 | ||
1189 | /* Return a new REAL_CST node whose type is TYPE | |
1190 | and whose value is the integer value of the INTEGER_CST node I. */ | |
1191 | ||
10a9d4cf | 1192 | REAL_VALUE_TYPE |
720082dc | 1193 | real_value_from_int_cst (const_tree type, const_tree i) |
10a9d4cf | 1194 | { |
1195 | REAL_VALUE_TYPE d; | |
04eb37c0 | 1196 | |
a3a81d87 | 1197 | /* Clear all bits of the real value type so that we can later do |
1198 | bitwise comparisons to see if two values are the same. */ | |
f0af5a88 | 1199 | memset (&d, 0, sizeof d); |
a3a81d87 | 1200 | |
67c65562 | 1201 | real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, |
1202 | TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i), | |
78a8ed03 | 1203 | TYPE_UNSIGNED (TREE_TYPE (i))); |
10a9d4cf | 1204 | return d; |
1205 | } | |
1206 | ||
083a2b5e | 1207 | /* Given a tree representing an integer constant I, return a tree |
536f5fb1 | 1208 | representing the same value as a floating-point constant of type TYPE. */ |
10a9d4cf | 1209 | |
1210 | tree | |
720082dc | 1211 | build_real_from_int_cst (tree type, const_tree i) |
10a9d4cf | 1212 | { |
1213 | tree v; | |
1aa16793 | 1214 | int overflow = TREE_OVERFLOW (i); |
10a9d4cf | 1215 | |
ef258422 | 1216 | v = build_real (type, real_value_from_int_cst (type, i)); |
10a9d4cf | 1217 | |
ef258422 | 1218 | TREE_OVERFLOW (v) |= overflow; |
10a9d4cf | 1219 | return v; |
1220 | } | |
1221 | ||
10a9d4cf | 1222 | /* Return a newly constructed STRING_CST node whose value is |
1223 | the LEN characters at STR. | |
1224 | The TREE_TYPE is not initialized. */ | |
1225 | ||
1226 | tree | |
60b8c5b3 | 1227 | build_string (int len, const char *str) |
10a9d4cf | 1228 | { |
d5406300 | 1229 | tree s; |
1230 | size_t length; | |
65c79db3 | 1231 | |
1232 | /* Do not waste bytes provided by padding of struct tree_string. */ | |
1233 | length = len + offsetof (struct tree_string, str) + 1; | |
d5406300 | 1234 | |
1235 | #ifdef GATHER_STATISTICS | |
1236 | tree_node_counts[(int) c_kind]++; | |
1237 | tree_node_sizes[(int) c_kind] += length; | |
1238 | #endif | |
1239 | ||
1240 | s = ggc_alloc_tree (length); | |
083a2b5e | 1241 | |
d5406300 | 1242 | memset (s, 0, sizeof (struct tree_common)); |
1243 | TREE_SET_CODE (s, STRING_CST); | |
152994e1 | 1244 | TREE_CONSTANT (s) = 1; |
10a9d4cf | 1245 | TREE_STRING_LENGTH (s) = len; |
e47a6f81 | 1246 | memcpy (s->string.str, str, len); |
1247 | s->string.str[len] = '\0'; | |
083a2b5e | 1248 | |
10a9d4cf | 1249 | return s; |
1250 | } | |
1251 | ||
1252 | /* Return a newly constructed COMPLEX_CST node whose value is | |
1253 | specified by the real and imaginary parts REAL and IMAG. | |
13079119 | 1254 | Both REAL and IMAG should be constant nodes. TYPE, if specified, |
1255 | will be the type of the COMPLEX_CST; otherwise a new type will be made. */ | |
10a9d4cf | 1256 | |
1257 | tree | |
60b8c5b3 | 1258 | build_complex (tree type, tree real, tree imag) |
10a9d4cf | 1259 | { |
19cb6b50 | 1260 | tree t = make_node (COMPLEX_CST); |
1aa16793 | 1261 | |
10a9d4cf | 1262 | TREE_REALPART (t) = real; |
1263 | TREE_IMAGPART (t) = imag; | |
13079119 | 1264 | TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real)); |
1aa16793 | 1265 | TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag); |
10a9d4cf | 1266 | return t; |
1267 | } | |
1268 | ||
ba56cb50 | 1269 | /* Return a constant of arithmetic type TYPE which is the |
a3a710ae | 1270 | multiplicative identity of the set TYPE. */ |
ba56cb50 | 1271 | |
1272 | tree | |
1273 | build_one_cst (tree type) | |
1274 | { | |
1275 | switch (TREE_CODE (type)) | |
1276 | { | |
1277 | case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: | |
1278 | case POINTER_TYPE: case REFERENCE_TYPE: | |
1279 | case OFFSET_TYPE: | |
1280 | return build_int_cst (type, 1); | |
1281 | ||
1282 | case REAL_TYPE: | |
1283 | return build_real (type, dconst1); | |
1284 | ||
06f0b99c | 1285 | case FIXED_POINT_TYPE: |
1286 | /* We can only generate 1 for accum types. */ | |
1287 | gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type))); | |
1288 | return build_fixed (type, FCONST1(TYPE_MODE (type))); | |
1289 | ||
ba56cb50 | 1290 | case VECTOR_TYPE: |
1291 | { | |
1292 | tree scalar, cst; | |
1293 | int i; | |
1294 | ||
1295 | scalar = build_one_cst (TREE_TYPE (type)); | |
1296 | ||
1297 | /* Create 'vect_cst_ = {cst,cst,...,cst}' */ | |
1298 | cst = NULL_TREE; | |
1299 | for (i = TYPE_VECTOR_SUBPARTS (type); --i >= 0; ) | |
1300 | cst = tree_cons (NULL_TREE, scalar, cst); | |
1301 | ||
1302 | return build_vector (type, cst); | |
1303 | } | |
1304 | ||
1305 | case COMPLEX_TYPE: | |
1306 | return build_complex (type, | |
1307 | build_one_cst (TREE_TYPE (type)), | |
1308 | fold_convert (TREE_TYPE (type), integer_zero_node)); | |
1309 | ||
1310 | default: | |
1311 | gcc_unreachable (); | |
1312 | } | |
1313 | } | |
1314 | ||
3cb98335 | 1315 | /* Build a BINFO with LEN language slots. */ |
1316 | ||
1317 | tree | |
f6cc6a08 | 1318 | make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL) |
3cb98335 | 1319 | { |
1320 | tree t; | |
f6cc6a08 | 1321 | size_t length = (offsetof (struct tree_binfo, base_binfos) |
1322 | + VEC_embedded_size (tree, base_binfos)); | |
b27ac6b5 | 1323 | |
3cb98335 | 1324 | #ifdef GATHER_STATISTICS |
1325 | tree_node_counts[(int) binfo_kind]++; | |
1326 | tree_node_sizes[(int) binfo_kind] += length; | |
1327 | #endif | |
1328 | ||
45ba1503 | 1329 | t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); |
3cb98335 | 1330 | |
f6cc6a08 | 1331 | memset (t, 0, offsetof (struct tree_binfo, base_binfos)); |
3cb98335 | 1332 | |
1333 | TREE_SET_CODE (t, TREE_BINFO); | |
b27ac6b5 | 1334 | |
f6cc6a08 | 1335 | VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos); |
3cb98335 | 1336 | |
1337 | return t; | |
1338 | } | |
1339 | ||
1340 | ||
10a9d4cf | 1341 | /* Build a newly constructed TREE_VEC node of length LEN. */ |
a92771b8 | 1342 | |
10a9d4cf | 1343 | tree |
674b05f5 | 1344 | make_tree_vec_stat (int len MEM_STAT_DECL) |
10a9d4cf | 1345 | { |
19cb6b50 | 1346 | tree t; |
709c2f34 | 1347 | int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec); |
10a9d4cf | 1348 | |
1349 | #ifdef GATHER_STATISTICS | |
709c2f34 | 1350 | tree_node_counts[(int) vec_kind]++; |
1351 | tree_node_sizes[(int) vec_kind] += length; | |
10a9d4cf | 1352 | #endif |
1353 | ||
45ba1503 | 1354 | t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); |
ad31d6ab | 1355 | |
b9a7cc69 | 1356 | memset (t, 0, length); |
674b05f5 | 1357 | |
10a9d4cf | 1358 | TREE_SET_CODE (t, TREE_VEC); |
1359 | TREE_VEC_LENGTH (t) = len; | |
10a9d4cf | 1360 | |
1361 | return t; | |
1362 | } | |
1363 | \f | |
c29fe334 | 1364 | /* Return 1 if EXPR is the integer constant zero or a complex constant |
1365 | of zero. */ | |
10a9d4cf | 1366 | |
1367 | int | |
720082dc | 1368 | integer_zerop (const_tree expr) |
10a9d4cf | 1369 | { |
84bf2ad1 | 1370 | STRIP_NOPS (expr); |
10a9d4cf | 1371 | |
c29fe334 | 1372 | return ((TREE_CODE (expr) == INTEGER_CST |
1373 | && TREE_INT_CST_LOW (expr) == 0 | |
1374 | && TREE_INT_CST_HIGH (expr) == 0) | |
1375 | || (TREE_CODE (expr) == COMPLEX_CST | |
1376 | && integer_zerop (TREE_REALPART (expr)) | |
1377 | && integer_zerop (TREE_IMAGPART (expr)))); | |
10a9d4cf | 1378 | } |
1379 | ||
c29fe334 | 1380 | /* Return 1 if EXPR is the integer constant one or the corresponding |
1381 | complex constant. */ | |
10a9d4cf | 1382 | |
1383 | int | |
720082dc | 1384 | integer_onep (const_tree expr) |
10a9d4cf | 1385 | { |
84bf2ad1 | 1386 | STRIP_NOPS (expr); |
10a9d4cf | 1387 | |
c29fe334 | 1388 | return ((TREE_CODE (expr) == INTEGER_CST |
1389 | && TREE_INT_CST_LOW (expr) == 1 | |
1390 | && TREE_INT_CST_HIGH (expr) == 0) | |
1391 | || (TREE_CODE (expr) == COMPLEX_CST | |
1392 | && integer_onep (TREE_REALPART (expr)) | |
1393 | && integer_zerop (TREE_IMAGPART (expr)))); | |
10a9d4cf | 1394 | } |
1395 | ||
c29fe334 | 1396 | /* Return 1 if EXPR is an integer containing all 1's in as much precision as |
1397 | it contains. Likewise for the corresponding complex constant. */ | |
10a9d4cf | 1398 | |
1399 | int | |
720082dc | 1400 | integer_all_onesp (const_tree expr) |
10a9d4cf | 1401 | { |
19cb6b50 | 1402 | int prec; |
1403 | int uns; | |
10a9d4cf | 1404 | |
84bf2ad1 | 1405 | STRIP_NOPS (expr); |
10a9d4cf | 1406 | |
c29fe334 | 1407 | if (TREE_CODE (expr) == COMPLEX_CST |
1408 | && integer_all_onesp (TREE_REALPART (expr)) | |
1409 | && integer_zerop (TREE_IMAGPART (expr))) | |
1410 | return 1; | |
1411 | ||
ff674908 | 1412 | else if (TREE_CODE (expr) != INTEGER_CST) |
10a9d4cf | 1413 | return 0; |
1414 | ||
78a8ed03 | 1415 | uns = TYPE_UNSIGNED (TREE_TYPE (expr)); |
0c3502bc | 1416 | if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0 |
1417 | && TREE_INT_CST_HIGH (expr) == -1) | |
1418 | return 1; | |
10a9d4cf | 1419 | if (!uns) |
0c3502bc | 1420 | return 0; |
10a9d4cf | 1421 | |
94fa8241 | 1422 | /* Note that using TYPE_PRECISION here is wrong. We care about the |
1423 | actual bits, not the (arbitrary) range of the type. */ | |
1424 | prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr))); | |
89e66659 | 1425 | if (prec >= HOST_BITS_PER_WIDE_INT) |
10a9d4cf | 1426 | { |
a0c2c45b | 1427 | HOST_WIDE_INT high_value; |
1428 | int shift_amount; | |
10a9d4cf | 1429 | |
89e66659 | 1430 | shift_amount = prec - HOST_BITS_PER_WIDE_INT; |
10a9d4cf | 1431 | |
8c0963c4 | 1432 | /* Can not handle precisions greater than twice the host int size. */ |
1433 | gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT); | |
1434 | if (shift_amount == HOST_BITS_PER_WIDE_INT) | |
10a9d4cf | 1435 | /* Shifting by the host word size is undefined according to the ANSI |
1436 | standard, so we must handle this as a special case. */ | |
1437 | high_value = -1; | |
1438 | else | |
89e66659 | 1439 | high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1; |
10a9d4cf | 1440 | |
9bfff6cb | 1441 | return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0 |
a0c2c45b | 1442 | && TREE_INT_CST_HIGH (expr) == high_value); |
10a9d4cf | 1443 | } |
1444 | else | |
a0c2c45b | 1445 | return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1; |
10a9d4cf | 1446 | } |
1447 | ||
1448 | /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only | |
1449 | one bit on). */ | |
1450 | ||
1451 | int | |
720082dc | 1452 | integer_pow2p (const_tree expr) |
10a9d4cf | 1453 | { |
ca641ef1 | 1454 | int prec; |
89e66659 | 1455 | HOST_WIDE_INT high, low; |
10a9d4cf | 1456 | |
84bf2ad1 | 1457 | STRIP_NOPS (expr); |
10a9d4cf | 1458 | |
c29fe334 | 1459 | if (TREE_CODE (expr) == COMPLEX_CST |
1460 | && integer_pow2p (TREE_REALPART (expr)) | |
1461 | && integer_zerop (TREE_IMAGPART (expr))) | |
1462 | return 1; | |
1463 | ||
ff674908 | 1464 | if (TREE_CODE (expr) != INTEGER_CST) |
10a9d4cf | 1465 | return 0; |
1466 | ||
997d68fe | 1467 | prec = (POINTER_TYPE_P (TREE_TYPE (expr)) |
ca641ef1 | 1468 | ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr))); |
10a9d4cf | 1469 | high = TREE_INT_CST_HIGH (expr); |
1470 | low = TREE_INT_CST_LOW (expr); | |
1471 | ||
ca641ef1 | 1472 | /* First clear all bits that are beyond the type's precision in case |
1473 | we've been sign extended. */ | |
1474 | ||
1475 | if (prec == 2 * HOST_BITS_PER_WIDE_INT) | |
1476 | ; | |
1477 | else if (prec > HOST_BITS_PER_WIDE_INT) | |
1478 | high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); | |
1479 | else | |
1480 | { | |
1481 | high = 0; | |
1482 | if (prec < HOST_BITS_PER_WIDE_INT) | |
1483 | low &= ~((HOST_WIDE_INT) (-1) << prec); | |
1484 | } | |
1485 | ||
10a9d4cf | 1486 | if (high == 0 && low == 0) |
1487 | return 0; | |
1488 | ||
1489 | return ((high == 0 && (low & (low - 1)) == 0) | |
1490 | || (low == 0 && (high & (high - 1)) == 0)); | |
1491 | } | |
1492 | ||
805e22b2 | 1493 | /* Return 1 if EXPR is an integer constant other than zero or a |
1494 | complex constant other than zero. */ | |
1495 | ||
1496 | int | |
720082dc | 1497 | integer_nonzerop (const_tree expr) |
805e22b2 | 1498 | { |
1499 | STRIP_NOPS (expr); | |
1500 | ||
1501 | return ((TREE_CODE (expr) == INTEGER_CST | |
805e22b2 | 1502 | && (TREE_INT_CST_LOW (expr) != 0 |
1503 | || TREE_INT_CST_HIGH (expr) != 0)) | |
1504 | || (TREE_CODE (expr) == COMPLEX_CST | |
1505 | && (integer_nonzerop (TREE_REALPART (expr)) | |
1506 | || integer_nonzerop (TREE_IMAGPART (expr))))); | |
1507 | } | |
1508 | ||
06f0b99c | 1509 | /* Return 1 if EXPR is the fixed-point constant zero. */ |
1510 | ||
1511 | int | |
4dc2a232 | 1512 | fixed_zerop (const_tree expr) |
06f0b99c | 1513 | { |
1514 | return (TREE_CODE (expr) == FIXED_CST | |
1515 | && double_int_zero_p (TREE_FIXED_CST (expr).data)); | |
1516 | } | |
1517 | ||
ca641ef1 | 1518 | /* Return the power of two represented by a tree node known to be a |
1519 | power of two. */ | |
1520 | ||
1521 | int | |
720082dc | 1522 | tree_log2 (const_tree expr) |
ca641ef1 | 1523 | { |
1524 | int prec; | |
1525 | HOST_WIDE_INT high, low; | |
1526 | ||
1527 | STRIP_NOPS (expr); | |
1528 | ||
1529 | if (TREE_CODE (expr) == COMPLEX_CST) | |
1530 | return tree_log2 (TREE_REALPART (expr)); | |
1531 | ||
997d68fe | 1532 | prec = (POINTER_TYPE_P (TREE_TYPE (expr)) |
ca641ef1 | 1533 | ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr))); |
1534 | ||
1535 | high = TREE_INT_CST_HIGH (expr); | |
1536 | low = TREE_INT_CST_LOW (expr); | |
1537 | ||
1538 | /* First clear all bits that are beyond the type's precision in case | |
1539 | we've been sign extended. */ | |
1540 | ||
1541 | if (prec == 2 * HOST_BITS_PER_WIDE_INT) | |
1542 | ; | |
1543 | else if (prec > HOST_BITS_PER_WIDE_INT) | |
1544 | high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); | |
1545 | else | |
1546 | { | |
1547 | high = 0; | |
1548 | if (prec < HOST_BITS_PER_WIDE_INT) | |
1549 | low &= ~((HOST_WIDE_INT) (-1) << prec); | |
1550 | } | |
1551 | ||
1552 | return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high) | |
9bfff6cb | 1553 | : exact_log2 (low)); |
ca641ef1 | 1554 | } |
1555 | ||
a0c2c45b | 1556 | /* Similar, but return the largest integer Y such that 2 ** Y is less |
1557 | than or equal to EXPR. */ | |
1558 | ||
1559 | int | |
720082dc | 1560 | tree_floor_log2 (const_tree expr) |
a0c2c45b | 1561 | { |
1562 | int prec; | |
1563 | HOST_WIDE_INT high, low; | |
1564 | ||
1565 | STRIP_NOPS (expr); | |
1566 | ||
1567 | if (TREE_CODE (expr) == COMPLEX_CST) | |
1568 | return tree_log2 (TREE_REALPART (expr)); | |
1569 | ||
1570 | prec = (POINTER_TYPE_P (TREE_TYPE (expr)) | |
1571 | ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr))); | |
1572 | ||
1573 | high = TREE_INT_CST_HIGH (expr); | |
1574 | low = TREE_INT_CST_LOW (expr); | |
1575 | ||
1576 | /* First clear all bits that are beyond the type's precision in case | |
1577 | we've been sign extended. Ignore if type's precision hasn't been set | |
1578 | since what we are doing is setting it. */ | |
1579 | ||
1580 | if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0) | |
1581 | ; | |
1582 | else if (prec > HOST_BITS_PER_WIDE_INT) | |
1583 | high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); | |
1584 | else | |
1585 | { | |
1586 | high = 0; | |
1587 | if (prec < HOST_BITS_PER_WIDE_INT) | |
1588 | low &= ~((HOST_WIDE_INT) (-1) << prec); | |
1589 | } | |
1590 | ||
1591 | return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high) | |
1592 | : floor_log2 (low)); | |
1593 | } | |
1594 | ||
10a9d4cf | 1595 | /* Return 1 if EXPR is the real constant zero. */ |
1596 | ||
1597 | int | |
720082dc | 1598 | real_zerop (const_tree expr) |
10a9d4cf | 1599 | { |
84bf2ad1 | 1600 | STRIP_NOPS (expr); |
10a9d4cf | 1601 | |
c29fe334 | 1602 | return ((TREE_CODE (expr) == REAL_CST |
1603 | && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0)) | |
1604 | || (TREE_CODE (expr) == COMPLEX_CST | |
1605 | && real_zerop (TREE_REALPART (expr)) | |
1606 | && real_zerop (TREE_IMAGPART (expr)))); | |
10a9d4cf | 1607 | } |
1608 | ||
c29fe334 | 1609 | /* Return 1 if EXPR is the real constant one in real or complex form. */ |
10a9d4cf | 1610 | |
1611 | int | |
720082dc | 1612 | real_onep (const_tree expr) |
10a9d4cf | 1613 | { |
84bf2ad1 | 1614 | STRIP_NOPS (expr); |
10a9d4cf | 1615 | |
c29fe334 | 1616 | return ((TREE_CODE (expr) == REAL_CST |
1617 | && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1)) | |
1618 | || (TREE_CODE (expr) == COMPLEX_CST | |
1619 | && real_onep (TREE_REALPART (expr)) | |
1620 | && real_zerop (TREE_IMAGPART (expr)))); | |
10a9d4cf | 1621 | } |
1622 | ||
1623 | /* Return 1 if EXPR is the real constant two. */ | |
1624 | ||
1625 | int | |
720082dc | 1626 | real_twop (const_tree expr) |
10a9d4cf | 1627 | { |
84bf2ad1 | 1628 | STRIP_NOPS (expr); |
10a9d4cf | 1629 | |
c29fe334 | 1630 | return ((TREE_CODE (expr) == REAL_CST |
1631 | && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2)) | |
1632 | || (TREE_CODE (expr) == COMPLEX_CST | |
1633 | && real_twop (TREE_REALPART (expr)) | |
1634 | && real_zerop (TREE_IMAGPART (expr)))); | |
10a9d4cf | 1635 | } |
1636 | ||
19fe5401 | 1637 | /* Return 1 if EXPR is the real constant minus one. */ |
1638 | ||
1639 | int | |
720082dc | 1640 | real_minus_onep (const_tree expr) |
19fe5401 | 1641 | { |
1642 | STRIP_NOPS (expr); | |
1643 | ||
1644 | return ((TREE_CODE (expr) == REAL_CST | |
19fe5401 | 1645 | && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1)) |
1646 | || (TREE_CODE (expr) == COMPLEX_CST | |
1647 | && real_minus_onep (TREE_REALPART (expr)) | |
1648 | && real_zerop (TREE_IMAGPART (expr)))); | |
1649 | } | |
1650 | ||
10a9d4cf | 1651 | /* Nonzero if EXP is a constant or a cast of a constant. */ |
9bfff6cb | 1652 | |
10a9d4cf | 1653 | int |
720082dc | 1654 | really_constant_p (const_tree exp) |
10a9d4cf | 1655 | { |
84bf2ad1 | 1656 | /* This is not quite the same as STRIP_NOPS. It does more. */ |
72dd6141 | 1657 | while (CONVERT_EXPR_P (exp) |
10a9d4cf | 1658 | || TREE_CODE (exp) == NON_LVALUE_EXPR) |
1659 | exp = TREE_OPERAND (exp, 0); | |
1660 | return TREE_CONSTANT (exp); | |
1661 | } | |
1662 | \f | |
1663 | /* Return first list element whose TREE_VALUE is ELEM. | |
edee2468 | 1664 | Return 0 if ELEM is not in LIST. */ |
10a9d4cf | 1665 | |
1666 | tree | |
60b8c5b3 | 1667 | value_member (tree elem, tree list) |
10a9d4cf | 1668 | { |
1669 | while (list) | |
1670 | { | |
1671 | if (elem == TREE_VALUE (list)) | |
1672 | return list; | |
1673 | list = TREE_CHAIN (list); | |
1674 | } | |
1675 | return NULL_TREE; | |
1676 | } | |
1677 | ||
1678 | /* Return first list element whose TREE_PURPOSE is ELEM. | |
edee2468 | 1679 | Return 0 if ELEM is not in LIST. */ |
10a9d4cf | 1680 | |
1681 | tree | |
720082dc | 1682 | purpose_member (const_tree elem, tree list) |
10a9d4cf | 1683 | { |
1684 | while (list) | |
1685 | { | |
1686 | if (elem == TREE_PURPOSE (list)) | |
1687 | return list; | |
1688 | list = TREE_CHAIN (list); | |
10a9d4cf | 1689 | } |
1690 | return NULL_TREE; | |
1691 | } | |
1692 | ||
a92771b8 | 1693 | /* Return nonzero if ELEM is part of the chain CHAIN. */ |
10a9d4cf | 1694 | |
1695 | int | |
720082dc | 1696 | chain_member (const_tree elem, const_tree chain) |
10a9d4cf | 1697 | { |
1698 | while (chain) | |
1699 | { | |
1700 | if (elem == chain) | |
1701 | return 1; | |
1702 | chain = TREE_CHAIN (chain); | |
1703 | } | |
1704 | ||
1705 | return 0; | |
1706 | } | |
1707 | ||
1708 | /* Return the length of a chain of nodes chained through TREE_CHAIN. | |
1709 | We expect a null pointer to mark the end of the chain. | |
1710 | This is the Lisp primitive `length'. */ | |
1711 | ||
1712 | int | |
720082dc | 1713 | list_length (const_tree t) |
10a9d4cf | 1714 | { |
720082dc | 1715 | const_tree p = t; |
393b349a | 1716 | #ifdef ENABLE_TREE_CHECKING |
720082dc | 1717 | const_tree q = t; |
393b349a | 1718 | #endif |
19cb6b50 | 1719 | int len = 0; |
10a9d4cf | 1720 | |
393b349a | 1721 | while (p) |
1722 | { | |
1723 | p = TREE_CHAIN (p); | |
1724 | #ifdef ENABLE_TREE_CHECKING | |
1725 | if (len % 2) | |
1726 | q = TREE_CHAIN (q); | |
8c0963c4 | 1727 | gcc_assert (p != q); |
393b349a | 1728 | #endif |
1729 | len++; | |
1730 | } | |
10a9d4cf | 1731 | |
1732 | return len; | |
1733 | } | |
1734 | ||
efd3939c | 1735 | /* Returns the number of FIELD_DECLs in TYPE. */ |
1736 | ||
1737 | int | |
720082dc | 1738 | fields_length (const_tree type) |
efd3939c | 1739 | { |
1740 | tree t = TYPE_FIELDS (type); | |
1741 | int count = 0; | |
1742 | ||
1743 | for (; t; t = TREE_CHAIN (t)) | |
1744 | if (TREE_CODE (t) == FIELD_DECL) | |
1745 | ++count; | |
1746 | ||
1747 | return count; | |
1748 | } | |
1749 | ||
10a9d4cf | 1750 | /* Concatenate two chains of nodes (chained through TREE_CHAIN) |
1751 | by modifying the last node in chain 1 to point to chain 2. | |
1752 | This is the Lisp primitive `nconc'. */ | |
1753 | ||
1754 | tree | |
60b8c5b3 | 1755 | chainon (tree op1, tree op2) |
10a9d4cf | 1756 | { |
4d2aa485 | 1757 | tree t1; |
10a9d4cf | 1758 | |
4d2aa485 | 1759 | if (!op1) |
1760 | return op2; | |
1761 | if (!op2) | |
1762 | return op1; | |
1763 | ||
1764 | for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1)) | |
1765 | continue; | |
1766 | TREE_CHAIN (t1) = op2; | |
cb764359 | 1767 | |
0c4e40c5 | 1768 | #ifdef ENABLE_TREE_CHECKING |
4d2aa485 | 1769 | { |
1770 | tree t2; | |
1771 | for (t2 = op2; t2; t2 = TREE_CHAIN (t2)) | |
8c0963c4 | 1772 | gcc_assert (t2 != t1); |
4d2aa485 | 1773 | } |
5fd99be7 | 1774 | #endif |
4d2aa485 | 1775 | |
1776 | return op1; | |
10a9d4cf | 1777 | } |
1778 | ||
1779 | /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */ | |
1780 | ||
1781 | tree | |
60b8c5b3 | 1782 | tree_last (tree chain) |
10a9d4cf | 1783 | { |
19cb6b50 | 1784 | tree next; |
10a9d4cf | 1785 | if (chain) |
07e64d6e | 1786 | while ((next = TREE_CHAIN (chain))) |
10a9d4cf | 1787 | chain = next; |
1788 | return chain; | |
1789 | } | |
1790 | ||
a7bc9181 | 1791 | /* Return the node in a chain of nodes whose value is x, NULL if not found. */ |
1792 | ||
1793 | tree | |
1794 | tree_find_value (tree chain, tree x) | |
1795 | { | |
1796 | tree list; | |
1797 | for (list = chain; list; list = TREE_CHAIN (list)) | |
1798 | if (TREE_VALUE (list) == x) | |
1799 | return list; | |
1800 | return NULL; | |
1801 | } | |
1802 | ||
10a9d4cf | 1803 | /* Reverse the order of elements in the chain T, |
1804 | and return the new head of the chain (old last element). */ | |
1805 | ||
1806 | tree | |
60b8c5b3 | 1807 | nreverse (tree t) |
10a9d4cf | 1808 | { |
19cb6b50 | 1809 | tree prev = 0, decl, next; |
10a9d4cf | 1810 | for (decl = t; decl; decl = next) |
1811 | { | |
1812 | next = TREE_CHAIN (decl); | |
1813 | TREE_CHAIN (decl) = prev; | |
1814 | prev = decl; | |
1815 | } | |
1816 | return prev; | |
1817 | } | |
10a9d4cf | 1818 | \f |
1819 | /* Return a newly created TREE_LIST node whose | |
1820 | purpose and value fields are PARM and VALUE. */ | |
1821 | ||
1822 | tree | |
674b05f5 | 1823 | build_tree_list_stat (tree parm, tree value MEM_STAT_DECL) |
10a9d4cf | 1824 | { |
674b05f5 | 1825 | tree t = make_node_stat (TREE_LIST PASS_MEM_STAT); |
10a9d4cf | 1826 | TREE_PURPOSE (t) = parm; |
1827 | TREE_VALUE (t) = value; | |
1828 | return t; | |
1829 | } | |
1830 | ||
10a9d4cf | 1831 | /* Return a newly created TREE_LIST node whose |
52b078bc | 1832 | purpose and value fields are PURPOSE and VALUE |
10a9d4cf | 1833 | and whose TREE_CHAIN is CHAIN. */ |
1834 | ||
1835 | tree | |
674b05f5 | 1836 | tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL) |
10a9d4cf | 1837 | { |
19cb6b50 | 1838 | tree node; |
1bfd55c5 | 1839 | |
45ba1503 | 1840 | node = (tree) ggc_alloc_zone_pass_stat (sizeof (struct tree_list), &tree_zone); |
791ceafe | 1841 | |
1842 | memset (node, 0, sizeof (struct tree_common)); | |
1bfd55c5 | 1843 | |
10a9d4cf | 1844 | #ifdef GATHER_STATISTICS |
eff5f036 | 1845 | tree_node_counts[(int) x_kind]++; |
1846 | tree_node_sizes[(int) x_kind] += sizeof (struct tree_list); | |
10a9d4cf | 1847 | #endif |
1848 | ||
10a9d4cf | 1849 | TREE_SET_CODE (node, TREE_LIST); |
10a9d4cf | 1850 | TREE_CHAIN (node) = chain; |
1851 | TREE_PURPOSE (node) = purpose; | |
1852 | TREE_VALUE (node) = value; | |
1853 | return node; | |
1854 | } | |
1855 | ||
f82f1250 | 1856 | /* Return the elements of a CONSTRUCTOR as a TREE_LIST. */ |
1857 | ||
1858 | tree | |
1859 | ctor_to_list (tree ctor) | |
1860 | { | |
1861 | tree list = NULL_TREE; | |
1862 | tree *p = &list; | |
1863 | unsigned ix; | |
b26a4c3c | 1864 | tree purpose, val; |
f82f1250 | 1865 | |
b26a4c3c | 1866 | FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), ix, purpose, val) |
f82f1250 | 1867 | { |
b26a4c3c | 1868 | *p = build_tree_list (purpose, val); |
f82f1250 | 1869 | p = &TREE_CHAIN (*p); |
1870 | } | |
1871 | ||
1872 | return list; | |
1873 | } | |
10a9d4cf | 1874 | \f |
1875 | /* Return the size nominally occupied by an object of type TYPE | |
1876 | when it resides in memory. The value is measured in units of bytes, | |
1877 | and its data type is that normally used for type sizes | |
1878 | (which is the first type created by make_signed_type or | |
1879 | make_unsigned_type). */ | |
1880 | ||
1881 | tree | |
f8fd23c0 | 1882 | size_in_bytes (const_tree type) |
10a9d4cf | 1883 | { |
a7478f11 | 1884 | tree t; |
1885 | ||
10a9d4cf | 1886 | if (type == error_mark_node) |
1887 | return integer_zero_node; | |
cec6c892 | 1888 | |
10a9d4cf | 1889 | type = TYPE_MAIN_VARIANT (type); |
cec6c892 | 1890 | t = TYPE_SIZE_UNIT (type); |
083a2b5e | 1891 | |
cec6c892 | 1892 | if (t == 0) |
10a9d4cf | 1893 | { |
dc24ddbd | 1894 | lang_hooks.types.incomplete_type_error (NULL_TREE, type); |
786414ee | 1895 | return size_zero_node; |
10a9d4cf | 1896 | } |
083a2b5e | 1897 | |
a7478f11 | 1898 | return t; |
10a9d4cf | 1899 | } |
1900 | ||
997d68fe | 1901 | /* Return the size of TYPE (in bytes) as a wide integer |
1902 | or return -1 if the size can vary or is larger than an integer. */ | |
10a9d4cf | 1903 | |
997d68fe | 1904 | HOST_WIDE_INT |
720082dc | 1905 | int_size_in_bytes (const_tree type) |
10a9d4cf | 1906 | { |
997d68fe | 1907 | tree t; |
1908 | ||
10a9d4cf | 1909 | if (type == error_mark_node) |
1910 | return 0; | |
997d68fe | 1911 | |
10a9d4cf | 1912 | type = TYPE_MAIN_VARIANT (type); |
cec6c892 | 1913 | t = TYPE_SIZE_UNIT (type); |
1914 | if (t == 0 | |
1915 | || TREE_CODE (t) != INTEGER_CST | |
5d844ba2 | 1916 | || TREE_INT_CST_HIGH (t) != 0 |
1917 | /* If the result would appear negative, it's too big to represent. */ | |
1918 | || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0) | |
10a9d4cf | 1919 | return -1; |
997d68fe | 1920 | |
1921 | return TREE_INT_CST_LOW (t); | |
10a9d4cf | 1922 | } |
150edb07 | 1923 | |
1924 | /* Return the maximum size of TYPE (in bytes) as a wide integer | |
1925 | or return -1 if the size can vary or is larger than an integer. */ | |
1926 | ||
1927 | HOST_WIDE_INT | |
f8fd23c0 | 1928 | max_int_size_in_bytes (const_tree type) |
150edb07 | 1929 | { |
1930 | HOST_WIDE_INT size = -1; | |
1931 | tree size_tree; | |
1932 | ||
1933 | /* If this is an array type, check for a possible MAX_SIZE attached. */ | |
1934 | ||
1935 | if (TREE_CODE (type) == ARRAY_TYPE) | |
1936 | { | |
1937 | size_tree = TYPE_ARRAY_MAX_SIZE (type); | |
1938 | ||
1939 | if (size_tree && host_integerp (size_tree, 1)) | |
1940 | size = tree_low_cst (size_tree, 1); | |
1941 | } | |
1942 | ||
1943 | /* If we still haven't been able to get a size, see if the language | |
1944 | can compute a maximum size. */ | |
1945 | ||
1946 | if (size == -1) | |
1947 | { | |
1948 | size_tree = lang_hooks.types.max_size (type); | |
1949 | ||
1950 | if (size_tree && host_integerp (size_tree, 1)) | |
1951 | size = tree_low_cst (size_tree, 1); | |
1952 | } | |
1953 | ||
1954 | return size; | |
1955 | } | |
5d844ba2 | 1956 | \f |
1957 | /* Return the bit position of FIELD, in bits from the start of the record. | |
1958 | This is a tree of type bitsizetype. */ | |
1959 | ||
1960 | tree | |
720082dc | 1961 | bit_position (const_tree field) |
5d844ba2 | 1962 | { |
6d731e4d | 1963 | return bit_from_pos (DECL_FIELD_OFFSET (field), |
1964 | DECL_FIELD_BIT_OFFSET (field)); | |
5d844ba2 | 1965 | } |
fe352cf1 | 1966 | |
1fa3a8f6 | 1967 | /* Likewise, but return as an integer. It must be representable in |
1968 | that way (since it could be a signed value, we don't have the | |
1969 | option of returning -1 like int_size_in_byte can. */ | |
5d844ba2 | 1970 | |
1971 | HOST_WIDE_INT | |
720082dc | 1972 | int_bit_position (const_tree field) |
5d844ba2 | 1973 | { |
1974 | return tree_low_cst (bit_position (field), 0); | |
1975 | } | |
1976 | \f | |
02e7a332 | 1977 | /* Return the byte position of FIELD, in bytes from the start of the record. |
1978 | This is a tree of type sizetype. */ | |
1979 | ||
1980 | tree | |
720082dc | 1981 | byte_position (const_tree field) |
02e7a332 | 1982 | { |
6d731e4d | 1983 | return byte_from_pos (DECL_FIELD_OFFSET (field), |
1984 | DECL_FIELD_BIT_OFFSET (field)); | |
02e7a332 | 1985 | } |
1986 | ||
1fa3a8f6 | 1987 | /* Likewise, but return as an integer. It must be representable in |
1988 | that way (since it could be a signed value, we don't have the | |
1989 | option of returning -1 like int_size_in_byte can. */ | |
02e7a332 | 1990 | |
1991 | HOST_WIDE_INT | |
720082dc | 1992 | int_byte_position (const_tree field) |
02e7a332 | 1993 | { |
1994 | return tree_low_cst (byte_position (field), 0); | |
1995 | } | |
1996 | \f | |
5d844ba2 | 1997 | /* Return the strictest alignment, in bits, that T is known to have. */ |
fe352cf1 | 1998 | |
1999 | unsigned int | |
720082dc | 2000 | expr_align (const_tree t) |
fe352cf1 | 2001 | { |
2002 | unsigned int align0, align1; | |
2003 | ||
2004 | switch (TREE_CODE (t)) | |
2005 | { | |
72dd6141 | 2006 | CASE_CONVERT: case NON_LVALUE_EXPR: |
fe352cf1 | 2007 | /* If we have conversions, we know that the alignment of the |
2008 | object must meet each of the alignments of the types. */ | |
2009 | align0 = expr_align (TREE_OPERAND (t, 0)); | |
2010 | align1 = TYPE_ALIGN (TREE_TYPE (t)); | |
2011 | return MAX (align0, align1); | |
2012 | ||
41076ef6 | 2013 | case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR: |
fe352cf1 | 2014 | case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR: |
b27ac6b5 | 2015 | case CLEANUP_POINT_EXPR: |
fe352cf1 | 2016 | /* These don't change the alignment of an object. */ |
2017 | return expr_align (TREE_OPERAND (t, 0)); | |
2018 | ||
2019 | case COND_EXPR: | |
2020 | /* The best we can do is say that the alignment is the least aligned | |
2021 | of the two arms. */ | |
2022 | align0 = expr_align (TREE_OPERAND (t, 1)); | |
2023 | align1 = expr_align (TREE_OPERAND (t, 2)); | |
2024 | return MIN (align0, align1); | |
2025 | ||
6c96b31e | 2026 | /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set |
2027 | meaningfully, it's always 1. */ | |
b278476e | 2028 | case LABEL_DECL: case CONST_DECL: |
fe352cf1 | 2029 | case VAR_DECL: case PARM_DECL: case RESULT_DECL: |
b278476e | 2030 | case FUNCTION_DECL: |
6c96b31e | 2031 | gcc_assert (DECL_ALIGN (t) != 0); |
2032 | return DECL_ALIGN (t); | |
b278476e | 2033 | |
fe352cf1 | 2034 | default: |
2035 | break; | |
2036 | } | |
2037 | ||
2038 | /* Otherwise take the alignment from that of the type. */ | |
2039 | return TYPE_ALIGN (TREE_TYPE (t)); | |
2040 | } | |
5dbb3364 | 2041 | \f |
2042 | /* Return, as a tree node, the number of elements for TYPE (which is an | |
73e36ac1 | 2043 | ARRAY_TYPE) minus one. This counts only elements of the top array. */ |
10a9d4cf | 2044 | |
2045 | tree | |
720082dc | 2046 | array_type_nelts (const_tree type) |
10a9d4cf | 2047 | { |
b88376f1 | 2048 | tree index_type, min, max; |
2049 | ||
2050 | /* If they did it with unspecified bounds, then we should have already | |
2051 | given an error about it before we got here. */ | |
2052 | if (! TYPE_DOMAIN (type)) | |
2053 | return error_mark_node; | |
2054 | ||
2055 | index_type = TYPE_DOMAIN (type); | |
2056 | min = TYPE_MIN_VALUE (index_type); | |
2057 | max = TYPE_MAX_VALUE (index_type); | |
1e06f4a9 | 2058 | |
1e06f4a9 | 2059 | return (integer_zerop (min) |
2060 | ? max | |
49d00087 | 2061 | : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min)); |
10a9d4cf | 2062 | } |
2063 | \f | |
5e1a75c5 | 2064 | /* If arg is static -- a reference to an object in static storage -- then |
2065 | return the object. This is not the same as the C meaning of `static'. | |
2066 | If arg isn't static, return NULL. */ | |
10a9d4cf | 2067 | |
82e3f297 | 2068 | tree |
60b8c5b3 | 2069 | staticp (tree arg) |
10a9d4cf | 2070 | { |
2071 | switch (TREE_CODE (arg)) | |
2072 | { | |
10a9d4cf | 2073 | case FUNCTION_DECL: |
dedb9173 | 2074 | /* Nested functions are static, even though taking their address will |
2075 | involve a trampoline as we unnest the nested function and create | |
2076 | the trampoline on the tree level. */ | |
2077 | return arg; | |
c6f5e832 | 2078 | |
17239360 | 2079 | case VAR_DECL: |
2a6f0f81 | 2080 | return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg)) |
1b53eb20 | 2081 | && ! DECL_THREAD_LOCAL_P (arg) |
6c1e551f | 2082 | && ! DECL_DLLIMPORT_P (arg) |
82e3f297 | 2083 | ? arg : NULL); |
10a9d4cf | 2084 | |
6e030094 | 2085 | case CONST_DECL: |
2086 | return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg)) | |
2087 | ? arg : NULL); | |
2088 | ||
9b7a6be1 | 2089 | case CONSTRUCTOR: |
82e3f297 | 2090 | return TREE_STATIC (arg) ? arg : NULL; |
9b7a6be1 | 2091 | |
38d0709d | 2092 | case LABEL_DECL: |
10a9d4cf | 2093 | case STRING_CST: |
82e3f297 | 2094 | return arg; |
10a9d4cf | 2095 | |
4ee9c684 | 2096 | case COMPONENT_REF: |
cf484390 | 2097 | /* If the thing being referenced is not a field, then it is |
2098 | something language specific. */ | |
862f468c | 2099 | gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL); |
4ee9c684 | 2100 | |
8aa7b9d6 | 2101 | /* If we are referencing a bitfield, we can't evaluate an |
2102 | ADDR_EXPR at compile time and so it isn't a constant. */ | |
4ee9c684 | 2103 | if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1))) |
82e3f297 | 2104 | return NULL; |
4ee9c684 | 2105 | |
2106 | return staticp (TREE_OPERAND (arg, 0)); | |
8aa7b9d6 | 2107 | |
10a9d4cf | 2108 | case BIT_FIELD_REF: |
82e3f297 | 2109 | return NULL; |
10a9d4cf | 2110 | |
b056d812 | 2111 | case MISALIGNED_INDIRECT_REF: |
2112 | case ALIGN_INDIRECT_REF: | |
10a9d4cf | 2113 | case INDIRECT_REF: |
82e3f297 | 2114 | return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL; |
10a9d4cf | 2115 | |
2116 | case ARRAY_REF: | |
ba04d9d5 | 2117 | case ARRAY_RANGE_REF: |
10a9d4cf | 2118 | if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST |
2119 | && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST) | |
2120 | return staticp (TREE_OPERAND (arg, 0)); | |
4ee9c684 | 2121 | else |
862f468c | 2122 | return NULL; |
2123 | ||
2124 | case COMPOUND_LITERAL_EXPR: | |
2125 | return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL; | |
10a9d4cf | 2126 | |
0dbd1c74 | 2127 | default: |
862f468c | 2128 | return NULL; |
0dbd1c74 | 2129 | } |
10a9d4cf | 2130 | } |
c7d4e749 | 2131 | |
10a9d4cf | 2132 | \f |
c7d4e749 | 2133 | |
2134 | ||
2135 | /* Return whether OP is a DECL whose address is function-invariant. */ | |
2136 | ||
2137 | bool | |
2138 | decl_address_invariant_p (const_tree op) | |
2139 | { | |
2140 | /* The conditions below are slightly less strict than the one in | |
2141 | staticp. */ | |
2142 | ||
2143 | switch (TREE_CODE (op)) | |
2144 | { | |
2145 | case PARM_DECL: | |
2146 | case RESULT_DECL: | |
2147 | case LABEL_DECL: | |
2148 | case FUNCTION_DECL: | |
2149 | return true; | |
2150 | ||
2151 | case VAR_DECL: | |
2152 | if (((TREE_STATIC (op) || DECL_EXTERNAL (op)) | |
2153 | && !DECL_DLLIMPORT_P (op)) | |
2154 | || DECL_THREAD_LOCAL_P (op) | |
2155 | || DECL_CONTEXT (op) == current_function_decl | |
2156 | || decl_function_context (op) == current_function_decl) | |
2157 | return true; | |
2158 | break; | |
2159 | ||
2160 | case CONST_DECL: | |
2161 | if ((TREE_STATIC (op) || DECL_EXTERNAL (op)) | |
2162 | || decl_function_context (op) == current_function_decl) | |
2163 | return true; | |
2164 | break; | |
2165 | ||
2166 | default: | |
2167 | break; | |
2168 | } | |
2169 | ||
2170 | return false; | |
2171 | } | |
2172 | ||
b9c94ed7 | 2173 | /* Return whether OP is a DECL whose address is interprocedural-invariant. */ |
2174 | ||
2175 | bool | |
2176 | decl_address_ip_invariant_p (const_tree op) | |
2177 | { | |
2178 | /* The conditions below are slightly less strict than the one in | |
2179 | staticp. */ | |
2180 | ||
2181 | switch (TREE_CODE (op)) | |
2182 | { | |
2183 | case LABEL_DECL: | |
2184 | case FUNCTION_DECL: | |
2185 | case STRING_CST: | |
2186 | return true; | |
2187 | ||
2188 | case VAR_DECL: | |
2189 | if (((TREE_STATIC (op) || DECL_EXTERNAL (op)) | |
2190 | && !DECL_DLLIMPORT_P (op)) | |
2191 | || DECL_THREAD_LOCAL_P (op)) | |
2192 | return true; | |
2193 | break; | |
2194 | ||
2195 | case CONST_DECL: | |
2196 | if ((TREE_STATIC (op) || DECL_EXTERNAL (op))) | |
2197 | return true; | |
2198 | break; | |
2199 | ||
2200 | default: | |
2201 | break; | |
2202 | } | |
2203 | ||
2204 | return false; | |
2205 | } | |
2206 | ||
c7d4e749 | 2207 | |
2208 | /* Return true if T is function-invariant (internal function, does | |
2209 | not handle arithmetic; that's handled in skip_simple_arithmetic and | |
2210 | tree_invariant_p). */ | |
2211 | ||
2212 | static bool tree_invariant_p (tree t); | |
2213 | ||
2214 | static bool | |
2215 | tree_invariant_p_1 (tree t) | |
2216 | { | |
2217 | tree op; | |
2218 | ||
2219 | if (TREE_CONSTANT (t) | |
2220 | || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t))) | |
2221 | return true; | |
2222 | ||
2223 | switch (TREE_CODE (t)) | |
2224 | { | |
2225 | case SAVE_EXPR: | |
2226 | return true; | |
2227 | ||
2228 | case ADDR_EXPR: | |
2229 | op = TREE_OPERAND (t, 0); | |
2230 | while (handled_component_p (op)) | |
2231 | { | |
2232 | switch (TREE_CODE (op)) | |
2233 | { | |
2234 | case ARRAY_REF: | |
2235 | case ARRAY_RANGE_REF: | |
2236 | if (!tree_invariant_p (TREE_OPERAND (op, 1)) | |
2237 | || TREE_OPERAND (op, 2) != NULL_TREE | |
2238 | || TREE_OPERAND (op, 3) != NULL_TREE) | |
2239 | return false; | |
2240 | break; | |
2241 | ||
2242 | case COMPONENT_REF: | |
2243 | if (TREE_OPERAND (op, 2) != NULL_TREE) | |
2244 | return false; | |
2245 | break; | |
2246 | ||
2247 | default:; | |
2248 | } | |
2249 | op = TREE_OPERAND (op, 0); | |
2250 | } | |
2251 | ||
2252 | return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op); | |
2253 | ||
2254 | default: | |
2255 | break; | |
2256 | } | |
2257 | ||
2258 | return false; | |
2259 | } | |
2260 | ||
2261 | /* Return true if T is function-invariant. */ | |
2262 | ||
2263 | static bool | |
2264 | tree_invariant_p (tree t) | |
2265 | { | |
2266 | tree inner = skip_simple_arithmetic (t); | |
2267 | return tree_invariant_p_1 (inner); | |
2268 | } | |
2269 | ||
e696cc2a | 2270 | /* Wrap a SAVE_EXPR around EXPR, if appropriate. |
2271 | Do this to any expression which may be used in more than one place, | |
2272 | but must be evaluated only once. | |
2273 | ||
2274 | Normally, expand_expr would reevaluate the expression each time. | |
2275 | Calling save_expr produces something that is evaluated and recorded | |
2276 | the first time expand_expr is called on it. Subsequent calls to | |
2277 | expand_expr just reuse the recorded value. | |
2278 | ||
2279 | The call to expand_expr that generates code that actually computes | |
2280 | the value is the first call *at compile time*. Subsequent calls | |
2281 | *at compile time* generate code to use the saved value. | |
2282 | This produces correct result provided that *at run time* control | |
2283 | always flows through the insns made by the first expand_expr | |
2284 | before reaching the other places where the save_expr was evaluated. | |
2285 | You, the caller of save_expr, must make sure this is so. | |
2286 | ||
2287 | Constants, and certain read-only nodes, are returned with no | |
2288 | SAVE_EXPR because that is safe. Expressions containing placeholders | |
2fdc5285 | 2289 | are not touched; see tree.def for an explanation of what these |
2290 | are used for. */ | |
10a9d4cf | 2291 | |
2292 | tree | |
60b8c5b3 | 2293 | save_expr (tree expr) |
10a9d4cf | 2294 | { |
ce3fb06e | 2295 | tree t = fold (expr); |
d30525e2 | 2296 | tree inner; |
2297 | ||
10a9d4cf | 2298 | /* If the tree evaluates to a constant, then we don't want to hide that |
2299 | fact (i.e. this allows further folding, and direct checks for constants). | |
8a7a0a5a | 2300 | However, a read-only object that has side effects cannot be bypassed. |
9bfff6cb | 2301 | Since it is no problem to reevaluate literals, we just return the |
a92771b8 | 2302 | literal node. */ |
d30525e2 | 2303 | inner = skip_simple_arithmetic (t); |
c7d4e749 | 2304 | if (TREE_CODE (inner) == ERROR_MARK) |
2305 | return inner; | |
4ee9c684 | 2306 | |
c7d4e749 | 2307 | if (tree_invariant_p_1 (inner)) |
10a9d4cf | 2308 | return t; |
2309 | ||
414bee42 | 2310 | /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since |
2387fcfe | 2311 | it means that the size or offset of some field of an object depends on |
2312 | the value within another field. | |
2313 | ||
2314 | Note that it must not be the case that T contains both a PLACEHOLDER_EXPR | |
2315 | and some variable since it would then need to be both evaluated once and | |
2316 | evaluated more than once. Front-ends must assure this case cannot | |
2317 | happen by surrounding any such subexpressions in their own SAVE_EXPR | |
2318 | and forcing evaluation at the proper time. */ | |
414bee42 | 2319 | if (contains_placeholder_p (inner)) |
2387fcfe | 2320 | return t; |
2321 | ||
67c155cb | 2322 | t = build1 (SAVE_EXPR, TREE_TYPE (expr), t); |
10a9d4cf | 2323 | |
2324 | /* This expression might be placed ahead of a jump to ensure that the | |
2325 | value was computed on both sides of the jump. So make sure it isn't | |
2326 | eliminated as dead. */ | |
2327 | TREE_SIDE_EFFECTS (t) = 1; | |
2328 | return t; | |
2329 | } | |
0e676ec9 | 2330 | |
414bee42 | 2331 | /* Look inside EXPR and into any simple arithmetic operations. Return |
2332 | the innermost non-arithmetic node. */ | |
2333 | ||
2334 | tree | |
60b8c5b3 | 2335 | skip_simple_arithmetic (tree expr) |
414bee42 | 2336 | { |
2337 | tree inner; | |
60b8c5b3 | 2338 | |
414bee42 | 2339 | /* We don't care about whether this can be used as an lvalue in this |
2340 | context. */ | |
2341 | while (TREE_CODE (expr) == NON_LVALUE_EXPR) | |
2342 | expr = TREE_OPERAND (expr, 0); | |
2343 | ||
2344 | /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and | |
2345 | a constant, it will be more efficient to not make another SAVE_EXPR since | |
2346 | it will allow better simplification and GCSE will be able to merge the | |
2347 | computations if they actually occur. */ | |
2348 | inner = expr; | |
2349 | while (1) | |
2350 | { | |
ce45a448 | 2351 | if (UNARY_CLASS_P (inner)) |
414bee42 | 2352 | inner = TREE_OPERAND (inner, 0); |
ce45a448 | 2353 | else if (BINARY_CLASS_P (inner)) |
414bee42 | 2354 | { |
c7d4e749 | 2355 | if (tree_invariant_p (TREE_OPERAND (inner, 1))) |
414bee42 | 2356 | inner = TREE_OPERAND (inner, 0); |
c7d4e749 | 2357 | else if (tree_invariant_p (TREE_OPERAND (inner, 0))) |
414bee42 | 2358 | inner = TREE_OPERAND (inner, 1); |
2359 | else | |
2360 | break; | |
2361 | } | |
2362 | else | |
2363 | break; | |
2364 | } | |
2365 | ||
2366 | return inner; | |
2367 | } | |
2368 | ||
1f3233d1 | 2369 | /* Return which tree structure is used by T. */ |
2370 | ||
2371 | enum tree_node_structure_enum | |
720082dc | 2372 | tree_node_structure (const_tree t) |
1f3233d1 | 2373 | { |
720082dc | 2374 | const enum tree_code code = TREE_CODE (t); |
60b8c5b3 | 2375 | |
1f3233d1 | 2376 | switch (TREE_CODE_CLASS (code)) |
5ded8c6f | 2377 | { |
ce45a448 | 2378 | case tcc_declaration: |
5ded8c6f | 2379 | { |
2380 | switch (code) | |
2381 | { | |
2382 | case FIELD_DECL: | |
2383 | return TS_FIELD_DECL; | |
2384 | case PARM_DECL: | |
2385 | return TS_PARM_DECL; | |
2386 | case VAR_DECL: | |
2387 | return TS_VAR_DECL; | |
2388 | case LABEL_DECL: | |
2389 | return TS_LABEL_DECL; | |
2390 | case RESULT_DECL: | |
2391 | return TS_RESULT_DECL; | |
2392 | case CONST_DECL: | |
2393 | return TS_CONST_DECL; | |
2394 | case TYPE_DECL: | |
2395 | return TS_TYPE_DECL; | |
2396 | case FUNCTION_DECL: | |
2397 | return TS_FUNCTION_DECL; | |
2398 | default: | |
2399 | return TS_DECL_NON_COMMON; | |
2400 | } | |
2401 | } | |
ce45a448 | 2402 | case tcc_type: |
2403 | return TS_TYPE; | |
2404 | case tcc_reference: | |
2405 | case tcc_comparison: | |
2406 | case tcc_unary: | |
2407 | case tcc_binary: | |
2408 | case tcc_expression: | |
2409 | case tcc_statement: | |
c2f47e15 | 2410 | case tcc_vl_exp: |
1f3233d1 | 2411 | return TS_EXP; |
ce45a448 | 2412 | default: /* tcc_constant and tcc_exceptional */ |
1f3233d1 | 2413 | break; |
2414 | } | |
2415 | switch (code) | |
2416 | { | |
ce45a448 | 2417 | /* tcc_constant cases. */ |
1f3233d1 | 2418 | case INTEGER_CST: return TS_INT_CST; |
2419 | case REAL_CST: return TS_REAL_CST; | |
06f0b99c | 2420 | case FIXED_CST: return TS_FIXED_CST; |
1f3233d1 | 2421 | case COMPLEX_CST: return TS_COMPLEX; |
2422 | case VECTOR_CST: return TS_VECTOR; | |
2423 | case STRING_CST: return TS_STRING; | |
ce45a448 | 2424 | /* tcc_exceptional cases. */ |
1f3233d1 | 2425 | case ERROR_MARK: return TS_COMMON; |
2426 | case IDENTIFIER_NODE: return TS_IDENTIFIER; | |
2427 | case TREE_LIST: return TS_LIST; | |
2428 | case TREE_VEC: return TS_VEC; | |
4ee9c684 | 2429 | case SSA_NAME: return TS_SSA_NAME; |
1f3233d1 | 2430 | case PLACEHOLDER_EXPR: return TS_COMMON; |
4ee9c684 | 2431 | case STATEMENT_LIST: return TS_STATEMENT_LIST; |
1acf0298 | 2432 | case BLOCK: return TS_BLOCK; |
c75b4594 | 2433 | case CONSTRUCTOR: return TS_CONSTRUCTOR; |
3cb98335 | 2434 | case TREE_BINFO: return TS_BINFO; |
55d6e7cd | 2435 | case OMP_CLAUSE: return TS_OMP_CLAUSE; |
46f8e3b0 | 2436 | case OPTIMIZATION_NODE: return TS_OPTIMIZATION; |
2437 | case TARGET_OPTION_NODE: return TS_TARGET_OPTION; | |
1f3233d1 | 2438 | |
2439 | default: | |
8c0963c4 | 2440 | gcc_unreachable (); |
1f3233d1 | 2441 | } |
2442 | } | |
2387fcfe | 2443 | \f |
2444 | /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size | |
9b1025bc | 2445 | or offset that depends on a field within a record. */ |
2387fcfe | 2446 | |
ce3fb06e | 2447 | bool |
b7bf20db | 2448 | contains_placeholder_p (const_tree exp) |
2387fcfe | 2449 | { |
19cb6b50 | 2450 | enum tree_code code; |
2387fcfe | 2451 | |
e41f0d80 | 2452 | if (!exp) |
2453 | return 0; | |
2454 | ||
e41f0d80 | 2455 | code = TREE_CODE (exp); |
55f9d7dc | 2456 | if (code == PLACEHOLDER_EXPR) |
7b3cf6ac | 2457 | return 1; |
f1875696 | 2458 | |
2387fcfe | 2459 | switch (TREE_CODE_CLASS (code)) |
2460 | { | |
ce45a448 | 2461 | case tcc_reference: |
7b3cf6ac | 2462 | /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit |
2463 | position computations since they will be converted into a | |
2464 | WITH_RECORD_EXPR involving the reference, which will assume | |
2465 | here will be valid. */ | |
ce3fb06e | 2466 | return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0)); |
2387fcfe | 2467 | |
ce45a448 | 2468 | case tcc_exceptional: |
0dbd1c74 | 2469 | if (code == TREE_LIST) |
ce3fb06e | 2470 | return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp)) |
2471 | || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp))); | |
0dbd1c74 | 2472 | break; |
9bfff6cb | 2473 | |
ce45a448 | 2474 | case tcc_unary: |
2475 | case tcc_binary: | |
2476 | case tcc_comparison: | |
2477 | case tcc_expression: | |
9b1025bc | 2478 | switch (code) |
2479 | { | |
2480 | case COMPOUND_EXPR: | |
9bfff6cb | 2481 | /* Ignoring the first operand isn't quite right, but works best. */ |
ce3fb06e | 2482 | return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)); |
9b1025bc | 2483 | |
9b1025bc | 2484 | case COND_EXPR: |
ce3fb06e | 2485 | return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0)) |
2486 | || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)) | |
2487 | || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2))); | |
9b1025bc | 2488 | |
9f85d7ea | 2489 | case SAVE_EXPR: |
2490 | /* The save_expr function never wraps anything containing | |
2491 | a PLACEHOLDER_EXPR. */ | |
2492 | return 0; | |
2493 | ||
0dbd1c74 | 2494 | default: |
2495 | break; | |
9b1025bc | 2496 | } |
2497 | ||
651396d6 | 2498 | switch (TREE_CODE_LENGTH (code)) |
2387fcfe | 2499 | { |
2500 | case 1: | |
ce3fb06e | 2501 | return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0)); |
2387fcfe | 2502 | case 2: |
ce3fb06e | 2503 | return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0)) |
2504 | || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))); | |
0dbd1c74 | 2505 | default: |
2506 | return 0; | |
2387fcfe | 2507 | } |
2387fcfe | 2508 | |
c2f47e15 | 2509 | case tcc_vl_exp: |
2510 | switch (code) | |
2511 | { | |
2512 | case CALL_EXPR: | |
2513 | { | |
b7bf20db | 2514 | const_tree arg; |
2515 | const_call_expr_arg_iterator iter; | |
2516 | FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp) | |
c2f47e15 | 2517 | if (CONTAINS_PLACEHOLDER_P (arg)) |
2518 | return 1; | |
2519 | return 0; | |
2520 | } | |
2521 | default: | |
2522 | return 0; | |
2523 | } | |
2524 | ||
0dbd1c74 | 2525 | default: |
2526 | return 0; | |
2527 | } | |
a43854ee | 2528 | return 0; |
2387fcfe | 2529 | } |
bc280274 | 2530 | |
2bd342e5 | 2531 | /* Return true if any part of the computation of TYPE involves a |
2532 | PLACEHOLDER_EXPR. This includes size, bounds, qualifiers | |
2533 | (for QUAL_UNION_TYPE) and field positions. */ | |
ce3fb06e | 2534 | |
2bd342e5 | 2535 | static bool |
720082dc | 2536 | type_contains_placeholder_1 (const_tree type) |
ce3fb06e | 2537 | { |
2538 | /* If the size contains a placeholder or the parent type (component type in | |
2539 | the case of arrays) type involves a placeholder, this type does. */ | |
2540 | if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type)) | |
2541 | || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type)) | |
2542 | || (TREE_TYPE (type) != 0 | |
2543 | && type_contains_placeholder_p (TREE_TYPE (type)))) | |
2bd342e5 | 2544 | return true; |
ce3fb06e | 2545 | |
2546 | /* Now do type-specific checks. Note that the last part of the check above | |
2547 | greatly limits what we have to do below. */ | |
2548 | switch (TREE_CODE (type)) | |
2549 | { | |
2550 | case VOID_TYPE: | |
2551 | case COMPLEX_TYPE: | |
ce3fb06e | 2552 | case ENUMERAL_TYPE: |
2553 | case BOOLEAN_TYPE: | |
ce3fb06e | 2554 | case POINTER_TYPE: |
2555 | case OFFSET_TYPE: | |
2556 | case REFERENCE_TYPE: | |
2557 | case METHOD_TYPE: | |
ce3fb06e | 2558 | case FUNCTION_TYPE: |
17febea8 | 2559 | case VECTOR_TYPE: |
2bd342e5 | 2560 | return false; |
ce3fb06e | 2561 | |
2562 | case INTEGER_TYPE: | |
2563 | case REAL_TYPE: | |
06f0b99c | 2564 | case FIXED_POINT_TYPE: |
ce3fb06e | 2565 | /* Here we just check the bounds. */ |
2566 | return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type)) | |
2567 | || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type))); | |
2568 | ||
2569 | case ARRAY_TYPE: | |
ce3fb06e | 2570 | /* We're already checked the component type (TREE_TYPE), so just check |
2571 | the index type. */ | |
2572 | return type_contains_placeholder_p (TYPE_DOMAIN (type)); | |
2573 | ||
2574 | case RECORD_TYPE: | |
2575 | case UNION_TYPE: | |
2576 | case QUAL_UNION_TYPE: | |
2577 | { | |
ce3fb06e | 2578 | tree field; |
ce3fb06e | 2579 | |
2580 | for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) | |
2581 | if (TREE_CODE (field) == FIELD_DECL | |
2582 | && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field)) | |
2583 | || (TREE_CODE (type) == QUAL_UNION_TYPE | |
2584 | && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field))) | |
2585 | || type_contains_placeholder_p (TREE_TYPE (field)))) | |
2bd342e5 | 2586 | return true; |
2587 | ||
2588 | return false; | |
ce3fb06e | 2589 | } |
2590 | ||
2591 | default: | |
8c0963c4 | 2592 | gcc_unreachable (); |
ce3fb06e | 2593 | } |
2594 | } | |
2bd342e5 | 2595 | |
2596 | bool | |
2597 | type_contains_placeholder_p (tree type) | |
2598 | { | |
2599 | bool result; | |
2600 | ||
2601 | /* If the contains_placeholder_bits field has been initialized, | |
2602 | then we know the answer. */ | |
2603 | if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0) | |
2604 | return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1; | |
2605 | ||
2606 | /* Indicate that we've seen this type node, and the answer is false. | |
2607 | This is what we want to return if we run into recursion via fields. */ | |
2608 | TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1; | |
2609 | ||
2610 | /* Compute the real value. */ | |
2611 | result = type_contains_placeholder_1 (type); | |
2612 | ||
2613 | /* Store the real value. */ | |
2614 | TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1; | |
2615 | ||
2616 | return result; | |
2617 | } | |
2387fcfe | 2618 | \f |
2619 | /* Given a tree EXP, a FIELD_DECL F, and a replacement value R, | |
2620 | return a tree with all occurrences of references to F in a | |
2621 | PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP | |
0dbd1c74 | 2622 | contains only arithmetic expressions or a CALL_EXPR with a |
2623 | PLACEHOLDER_EXPR occurring only in its arglist. */ | |
2387fcfe | 2624 | |
2625 | tree | |
60b8c5b3 | 2626 | substitute_in_expr (tree exp, tree f, tree r) |
2387fcfe | 2627 | { |
2628 | enum tree_code code = TREE_CODE (exp); | |
38071326 | 2629 | tree op0, op1, op2, op3; |
f4e36c33 | 2630 | tree new_tree, inner; |
2387fcfe | 2631 | |
50d1f269 | 2632 | /* We handle TREE_LIST and COMPONENT_REF separately. */ |
2633 | if (code == TREE_LIST) | |
2387fcfe | 2634 | { |
55f9d7dc | 2635 | op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r); |
2636 | op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r); | |
50d1f269 | 2637 | if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp)) |
2387fcfe | 2638 | return exp; |
0dbd1c74 | 2639 | |
50d1f269 | 2640 | return tree_cons (TREE_PURPOSE (exp), op1, op0); |
2641 | } | |
2642 | else if (code == COMPONENT_REF) | |
2643 | { | |
2644 | /* If this expression is getting a value from a PLACEHOLDER_EXPR | |
2645 | and it is the right field, replace it with R. */ | |
2646 | for (inner = TREE_OPERAND (exp, 0); | |
ce45a448 | 2647 | REFERENCE_CLASS_P (inner); |
50d1f269 | 2648 | inner = TREE_OPERAND (inner, 0)) |
2649 | ; | |
2650 | if (TREE_CODE (inner) == PLACEHOLDER_EXPR | |
2651 | && TREE_OPERAND (exp, 1) == f) | |
2652 | return r; | |
2653 | ||
b55f9493 | 2654 | /* If this expression hasn't been completed let, leave it alone. */ |
50d1f269 | 2655 | if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0) |
2656 | return exp; | |
2657 | ||
55f9d7dc | 2658 | op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r); |
50d1f269 | 2659 | if (op0 == TREE_OPERAND (exp, 0)) |
2660 | return exp; | |
2661 | ||
f4e36c33 | 2662 | new_tree = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), |
49d00087 | 2663 | op0, TREE_OPERAND (exp, 1), NULL_TREE); |
50d1f269 | 2664 | } |
2665 | else | |
2666 | switch (TREE_CODE_CLASS (code)) | |
2667 | { | |
ce45a448 | 2668 | case tcc_constant: |
2669 | case tcc_declaration: | |
50d1f269 | 2670 | return exp; |
2387fcfe | 2671 | |
ce45a448 | 2672 | case tcc_exceptional: |
2673 | case tcc_unary: | |
2674 | case tcc_binary: | |
2675 | case tcc_comparison: | |
2676 | case tcc_expression: | |
2677 | case tcc_reference: | |
651396d6 | 2678 | switch (TREE_CODE_LENGTH (code)) |
50d1f269 | 2679 | { |
2680 | case 0: | |
a93ec305 | 2681 | return exp; |
9bfff6cb | 2682 | |
50d1f269 | 2683 | case 1: |
55f9d7dc | 2684 | op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r); |
50d1f269 | 2685 | if (op0 == TREE_OPERAND (exp, 0)) |
2686 | return exp; | |
49393347 | 2687 | |
f4e36c33 | 2688 | new_tree = fold_build1 (code, TREE_TYPE (exp), op0); |
50d1f269 | 2689 | break; |
2387fcfe | 2690 | |
50d1f269 | 2691 | case 2: |
55f9d7dc | 2692 | op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r); |
2693 | op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r); | |
b4c3eba3 | 2694 | |
50d1f269 | 2695 | if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)) |
2696 | return exp; | |
a93ec305 | 2697 | |
f4e36c33 | 2698 | new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1); |
50d1f269 | 2699 | break; |
2387fcfe | 2700 | |
50d1f269 | 2701 | case 3: |
55f9d7dc | 2702 | op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r); |
2703 | op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r); | |
2704 | op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r); | |
2d4694be | 2705 | |
50d1f269 | 2706 | if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) |
2707 | && op2 == TREE_OPERAND (exp, 2)) | |
2708 | return exp; | |
0dbd1c74 | 2709 | |
f4e36c33 | 2710 | new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2); |
50d1f269 | 2711 | break; |
0dbd1c74 | 2712 | |
38071326 | 2713 | case 4: |
2714 | op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r); | |
2715 | op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r); | |
2716 | op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r); | |
2717 | op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r); | |
2718 | ||
2719 | if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) | |
2720 | && op2 == TREE_OPERAND (exp, 2) | |
2721 | && op3 == TREE_OPERAND (exp, 3)) | |
2722 | return exp; | |
2723 | ||
f4e36c33 | 2724 | new_tree = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3)); |
38071326 | 2725 | break; |
2726 | ||
50d1f269 | 2727 | default: |
8c0963c4 | 2728 | gcc_unreachable (); |
50d1f269 | 2729 | } |
2730 | break; | |
2387fcfe | 2731 | |
c2f47e15 | 2732 | case tcc_vl_exp: |
2733 | { | |
2734 | tree copy = NULL_TREE; | |
2735 | int i; | |
a13ff590 | 2736 | |
2737 | for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++) | |
c2f47e15 | 2738 | { |
2739 | tree op = TREE_OPERAND (exp, i); | |
7c952a13 | 2740 | tree new_op = SUBSTITUTE_IN_EXPR (op, f, r); |
2741 | if (new_op != op) | |
c2f47e15 | 2742 | { |
7c952a13 | 2743 | if (!copy) |
2744 | copy = copy_node (exp); | |
2745 | TREE_OPERAND (copy, i) = new_op; | |
c2f47e15 | 2746 | } |
2747 | } | |
7c952a13 | 2748 | |
c2f47e15 | 2749 | if (copy) |
f4e36c33 | 2750 | new_tree = fold (copy); |
c2f47e15 | 2751 | else |
2752 | return exp; | |
2753 | } | |
a13ff590 | 2754 | break; |
c2f47e15 | 2755 | |
50d1f269 | 2756 | default: |
8c0963c4 | 2757 | gcc_unreachable (); |
50d1f269 | 2758 | } |
2387fcfe | 2759 | |
f4e36c33 | 2760 | TREE_READONLY (new_tree) = TREE_READONLY (exp); |
2761 | return new_tree; | |
2387fcfe | 2762 | } |
55f9d7dc | 2763 | |
2764 | /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement | |
2765 | for it within OBJ, a tree that is an object or a chain of references. */ | |
2766 | ||
2767 | tree | |
2768 | substitute_placeholder_in_expr (tree exp, tree obj) | |
2769 | { | |
2770 | enum tree_code code = TREE_CODE (exp); | |
f0ac718c | 2771 | tree op0, op1, op2, op3; |
55f9d7dc | 2772 | |
2773 | /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type | |
2774 | in the chain of OBJ. */ | |
2775 | if (code == PLACEHOLDER_EXPR) | |
2776 | { | |
2777 | tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp)); | |
2778 | tree elt; | |
2779 | ||
2780 | for (elt = obj; elt != 0; | |
2781 | elt = ((TREE_CODE (elt) == COMPOUND_EXPR | |
2782 | || TREE_CODE (elt) == COND_EXPR) | |
2783 | ? TREE_OPERAND (elt, 1) | |
ce45a448 | 2784 | : (REFERENCE_CLASS_P (elt) |
2785 | || UNARY_CLASS_P (elt) | |
2786 | || BINARY_CLASS_P (elt) | |
c2f47e15 | 2787 | || VL_EXP_CLASS_P (elt) |
ce45a448 | 2788 | || EXPRESSION_CLASS_P (elt)) |
55f9d7dc | 2789 | ? TREE_OPERAND (elt, 0) : 0)) |
2790 | if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type) | |
2791 | return elt; | |
2792 | ||
2793 | for (elt = obj; elt != 0; | |
2794 | elt = ((TREE_CODE (elt) == COMPOUND_EXPR | |
2795 | || TREE_CODE (elt) == COND_EXPR) | |
2796 | ? TREE_OPERAND (elt, 1) | |
ce45a448 | 2797 | : (REFERENCE_CLASS_P (elt) |
2798 | || UNARY_CLASS_P (elt) | |
2799 | || BINARY_CLASS_P (elt) | |
c2f47e15 | 2800 | || VL_EXP_CLASS_P (elt) |
ce45a448 | 2801 | || EXPRESSION_CLASS_P (elt)) |
55f9d7dc | 2802 | ? TREE_OPERAND (elt, 0) : 0)) |
2803 | if (POINTER_TYPE_P (TREE_TYPE (elt)) | |
2804 | && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt))) | |
2805 | == need_type)) | |
49d00087 | 2806 | return fold_build1 (INDIRECT_REF, need_type, elt); |
55f9d7dc | 2807 | |
2808 | /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it | |
2809 | survives until RTL generation, there will be an error. */ | |
2810 | return exp; | |
2811 | } | |
2812 | ||
2813 | /* TREE_LIST is special because we need to look at TREE_VALUE | |
2814 | and TREE_CHAIN, not TREE_OPERANDS. */ | |
2815 | else if (code == TREE_LIST) | |
2816 | { | |
2817 | op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj); | |
2818 | op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj); | |
2819 | if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp)) | |
2820 | return exp; | |
2821 | ||
2822 | return tree_cons (TREE_PURPOSE (exp), op1, op0); | |
2823 | } | |
2824 | else | |
2825 | switch (TREE_CODE_CLASS (code)) | |
2826 | { | |
ce45a448 | 2827 | case tcc_constant: |
2828 | case tcc_declaration: | |
55f9d7dc | 2829 | return exp; |
2830 | ||
ce45a448 | 2831 | case tcc_exceptional: |
2832 | case tcc_unary: | |
2833 | case tcc_binary: | |
2834 | case tcc_comparison: | |
2835 | case tcc_expression: | |
2836 | case tcc_reference: | |
2837 | case tcc_statement: | |
651396d6 | 2838 | switch (TREE_CODE_LENGTH (code)) |
55f9d7dc | 2839 | { |
2840 | case 0: | |
2841 | return exp; | |
2842 | ||
2843 | case 1: | |
2844 | op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); | |
2845 | if (op0 == TREE_OPERAND (exp, 0)) | |
2846 | return exp; | |
2847 | else | |
49d00087 | 2848 | return fold_build1 (code, TREE_TYPE (exp), op0); |
55f9d7dc | 2849 | |
2850 | case 2: | |
2851 | op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); | |
2852 | op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); | |
2853 | ||
2854 | if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)) | |
2855 | return exp; | |
2856 | else | |
49d00087 | 2857 | return fold_build2 (code, TREE_TYPE (exp), op0, op1); |
55f9d7dc | 2858 | |
2859 | case 3: | |
2860 | op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); | |
2861 | op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); | |
2862 | op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj); | |
2863 | ||
2864 | if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) | |
2865 | && op2 == TREE_OPERAND (exp, 2)) | |
2866 | return exp; | |
2867 | else | |
49d00087 | 2868 | return fold_build3 (code, TREE_TYPE (exp), op0, op1, op2); |
55f9d7dc | 2869 | |
f0ac718c | 2870 | case 4: |
2871 | op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); | |
2872 | op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); | |
2873 | op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj); | |
2874 | op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj); | |
2875 | ||
2876 | if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) | |
2877 | && op2 == TREE_OPERAND (exp, 2) | |
2878 | && op3 == TREE_OPERAND (exp, 3)) | |
2879 | return exp; | |
2880 | else | |
2881 | return fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3)); | |
2882 | ||
55f9d7dc | 2883 | default: |
8c0963c4 | 2884 | gcc_unreachable (); |
55f9d7dc | 2885 | } |
2886 | break; | |
2887 | ||
c2f47e15 | 2888 | case tcc_vl_exp: |
2889 | { | |
2890 | tree copy = NULL_TREE; | |
2891 | int i; | |
8084aa18 | 2892 | |
2893 | for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++) | |
c2f47e15 | 2894 | { |
2895 | tree op = TREE_OPERAND (exp, i); | |
8084aa18 | 2896 | tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj); |
2897 | if (new_op != op) | |
c2f47e15 | 2898 | { |
2899 | if (!copy) | |
2900 | copy = copy_node (exp); | |
8084aa18 | 2901 | TREE_OPERAND (copy, i) = new_op; |
c2f47e15 | 2902 | } |
2903 | } | |
8084aa18 | 2904 | |
c2f47e15 | 2905 | if (copy) |
2906 | return fold (copy); | |
2907 | else | |
2908 | return exp; | |
2909 | } | |
2910 | ||
55f9d7dc | 2911 | default: |
8c0963c4 | 2912 | gcc_unreachable (); |
55f9d7dc | 2913 | } |
2914 | } | |
2387fcfe | 2915 | \f |
10a9d4cf | 2916 | /* Stabilize a reference so that we can use it any number of times |
2917 | without causing its operands to be evaluated more than once. | |
d5d273ee | 2918 | Returns the stabilized reference. This works by means of save_expr, |
2919 | so see the caveats in the comments about save_expr. | |
10a9d4cf | 2920 | |
2921 | Also allows conversion expressions whose operands are references. | |
2922 | Any other kind of expression is returned unchanged. */ | |
2923 | ||
2924 | tree | |
60b8c5b3 | 2925 | stabilize_reference (tree ref) |
10a9d4cf | 2926 | { |
19cb6b50 | 2927 | tree result; |
2928 | enum tree_code code = TREE_CODE (ref); | |
10a9d4cf | 2929 | |
2930 | switch (code) | |
2931 | { | |
2932 | case VAR_DECL: | |
2933 | case PARM_DECL: | |
2934 | case RESULT_DECL: | |
2935 | /* No action is needed in this case. */ | |
2936 | return ref; | |
2937 | ||
72dd6141 | 2938 | CASE_CONVERT: |
10a9d4cf | 2939 | case FLOAT_EXPR: |
2940 | case FIX_TRUNC_EXPR: | |
10a9d4cf | 2941 | result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0))); |
2942 | break; | |
2943 | ||
2944 | case INDIRECT_REF: | |
2945 | result = build_nt (INDIRECT_REF, | |
2946 | stabilize_reference_1 (TREE_OPERAND (ref, 0))); | |
2947 | break; | |
2948 | ||
2949 | case COMPONENT_REF: | |
2950 | result = build_nt (COMPONENT_REF, | |
2951 | stabilize_reference (TREE_OPERAND (ref, 0)), | |
6374121b | 2952 | TREE_OPERAND (ref, 1), NULL_TREE); |
10a9d4cf | 2953 | break; |
2954 | ||
2955 | case BIT_FIELD_REF: | |
2956 | result = build_nt (BIT_FIELD_REF, | |
2957 | stabilize_reference (TREE_OPERAND (ref, 0)), | |
2958 | stabilize_reference_1 (TREE_OPERAND (ref, 1)), | |
2959 | stabilize_reference_1 (TREE_OPERAND (ref, 2))); | |
2960 | break; | |
2961 | ||
2962 | case ARRAY_REF: | |
2963 | result = build_nt (ARRAY_REF, | |
2964 | stabilize_reference (TREE_OPERAND (ref, 0)), | |
6374121b | 2965 | stabilize_reference_1 (TREE_OPERAND (ref, 1)), |
2966 | TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3)); | |
10a9d4cf | 2967 | break; |
2968 | ||
ba04d9d5 | 2969 | case ARRAY_RANGE_REF: |
2970 | result = build_nt (ARRAY_RANGE_REF, | |
2971 | stabilize_reference (TREE_OPERAND (ref, 0)), | |
6374121b | 2972 | stabilize_reference_1 (TREE_OPERAND (ref, 1)), |
2973 | TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3)); | |
ba04d9d5 | 2974 | break; |
2975 | ||
1acba6f7 | 2976 | case COMPOUND_EXPR: |
37e76d7d | 2977 | /* We cannot wrap the first expression in a SAVE_EXPR, as then |
2978 | it wouldn't be ignored. This matters when dealing with | |
2979 | volatiles. */ | |
2980 | return stabilize_reference_1 (ref); | |
1acba6f7 | 2981 | |
10a9d4cf | 2982 | /* If arg isn't a kind of lvalue we recognize, make no change. |
2983 | Caller should recognize the error for an invalid lvalue. */ | |
2984 | default: | |
2985 | return ref; | |
2986 | ||
2987 | case ERROR_MARK: | |
2988 | return error_mark_node; | |
2989 | } | |
2990 | ||
2991 | TREE_TYPE (result) = TREE_TYPE (ref); | |
2992 | TREE_READONLY (result) = TREE_READONLY (ref); | |
2993 | TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref); | |
2994 | TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref); | |
10a9d4cf | 2995 | |
2996 | return result; | |
2997 | } | |
2998 | ||
2999 | /* Subroutine of stabilize_reference; this is called for subtrees of | |
3000 | references. Any expression with side-effects must be put in a SAVE_EXPR | |
3001 | to ensure that it is only evaluated once. | |
3002 | ||
3003 | We don't put SAVE_EXPR nodes around everything, because assigning very | |
3004 | simple expressions to temporaries causes us to miss good opportunities | |
3005 | for optimizations. Among other things, the opportunity to fold in the | |
3006 | addition of a constant into an addressing mode often gets lost, e.g. | |
3007 | "y[i+1] += x;". In general, we take the approach that we should not make | |
3008 | an assignment unless we are forced into it - i.e., that any non-side effect | |
3009 | operator should be allowed, and that cse should take care of coalescing | |
3010 | multiple utterances of the same expression should that prove fruitful. */ | |
3011 | ||
bebf3d7b | 3012 | tree |
60b8c5b3 | 3013 | stabilize_reference_1 (tree e) |
10a9d4cf | 3014 | { |
19cb6b50 | 3015 | tree result; |
3016 | enum tree_code code = TREE_CODE (e); | |
10a9d4cf | 3017 | |
8a7a0a5a | 3018 | /* We cannot ignore const expressions because it might be a reference |
3019 | to a const array but whose index contains side-effects. But we can | |
3020 | ignore things that are actual constant or that already have been | |
3021 | handled by this function. */ | |
3022 | ||
c7d4e749 | 3023 | if (tree_invariant_p (e)) |
10a9d4cf | 3024 | return e; |
3025 | ||
3026 | switch (TREE_CODE_CLASS (code)) | |
3027 | { | |
ce45a448 | 3028 | case tcc_exceptional: |
3029 | case tcc_type: | |
3030 | case tcc_declaration: | |
3031 | case tcc_comparison: | |
3032 | case tcc_statement: | |
3033 | case tcc_expression: | |
3034 | case tcc_reference: | |
c2f47e15 | 3035 | case tcc_vl_exp: |
10a9d4cf | 3036 | /* If the expression has side-effects, then encase it in a SAVE_EXPR |
3037 | so that it will only be evaluated once. */ | |
3038 | /* The reference (r) and comparison (<) classes could be handled as | |
3039 | below, but it is generally faster to only evaluate them once. */ | |
3040 | if (TREE_SIDE_EFFECTS (e)) | |
3041 | return save_expr (e); | |
3042 | return e; | |
3043 | ||
ce45a448 | 3044 | case tcc_constant: |
10a9d4cf | 3045 | /* Constants need no processing. In fact, we should never reach |
3046 | here. */ | |
3047 | return e; | |
9bfff6cb | 3048 | |
ce45a448 | 3049 | case tcc_binary: |
ff00c725 | 3050 | /* Division is slow and tends to be compiled with jumps, |
3051 | especially the division by powers of 2 that is often | |
3052 | found inside of an array reference. So do it just once. */ | |
3053 | if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR | |
3054 | || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR | |
3055 | || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR | |
3056 | || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR) | |
3057 | return save_expr (e); | |
10a9d4cf | 3058 | /* Recursively stabilize each operand. */ |
3059 | result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)), | |
3060 | stabilize_reference_1 (TREE_OPERAND (e, 1))); | |
3061 | break; | |
3062 | ||
ce45a448 | 3063 | case tcc_unary: |
10a9d4cf | 3064 | /* Recursively stabilize each operand. */ |
3065 | result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0))); | |
3066 | break; | |
49ca1fcd | 3067 | |
3068 | default: | |
8c0963c4 | 3069 | gcc_unreachable (); |
10a9d4cf | 3070 | } |
9bfff6cb | 3071 | |
10a9d4cf | 3072 | TREE_TYPE (result) = TREE_TYPE (e); |
3073 | TREE_READONLY (result) = TREE_READONLY (e); | |
3074 | TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e); | |
3075 | TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e); | |
10a9d4cf | 3076 | |
3077 | return result; | |
3078 | } | |
3079 | \f | |
3080 | /* Low-level constructors for expressions. */ | |
3081 | ||
6374121b | 3082 | /* A helper function for build1 and constant folders. Set TREE_CONSTANT, |
c7d4e749 | 3083 | and TREE_SIDE_EFFECTS for an ADDR_EXPR. */ |
4ee9c684 | 3084 | |
3085 | void | |
750ad201 | 3086 | recompute_tree_invariant_for_addr_expr (tree t) |
4ee9c684 | 3087 | { |
6374121b | 3088 | tree node; |
c7d4e749 | 3089 | bool tc = true, se = false; |
4ee9c684 | 3090 | |
6374121b | 3091 | /* We started out assuming this address is both invariant and constant, but |
3092 | does not have side effects. Now go down any handled components and see if | |
3093 | any of them involve offsets that are either non-constant or non-invariant. | |
3094 | Also check for side-effects. | |
3095 | ||
3096 | ??? Note that this code makes no attempt to deal with the case where | |
3097 | taking the address of something causes a copy due to misalignment. */ | |
3098 | ||
c7d4e749 | 3099 | #define UPDATE_FLAGS(NODE) \ |
6374121b | 3100 | do { tree _node = (NODE); \ |
6374121b | 3101 | if (_node && !TREE_CONSTANT (_node)) tc = false; \ |
3102 | if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0) | |
3103 | ||
3104 | for (node = TREE_OPERAND (t, 0); handled_component_p (node); | |
3105 | node = TREE_OPERAND (node, 0)) | |
4ee9c684 | 3106 | { |
6374121b | 3107 | /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus |
3108 | array reference (probably made temporarily by the G++ front end), | |
3109 | so ignore all the operands. */ | |
3110 | if ((TREE_CODE (node) == ARRAY_REF | |
3111 | || TREE_CODE (node) == ARRAY_RANGE_REF) | |
3112 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE) | |
4ee9c684 | 3113 | { |
c7d4e749 | 3114 | UPDATE_FLAGS (TREE_OPERAND (node, 1)); |
20506a1d | 3115 | if (TREE_OPERAND (node, 2)) |
c7d4e749 | 3116 | UPDATE_FLAGS (TREE_OPERAND (node, 2)); |
20506a1d | 3117 | if (TREE_OPERAND (node, 3)) |
c7d4e749 | 3118 | UPDATE_FLAGS (TREE_OPERAND (node, 3)); |
4ee9c684 | 3119 | } |
6374121b | 3120 | /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a |
3121 | FIELD_DECL, apparently. The G++ front end can put something else | |
3122 | there, at least temporarily. */ | |
3123 | else if (TREE_CODE (node) == COMPONENT_REF | |
3124 | && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL) | |
20506a1d | 3125 | { |
3126 | if (TREE_OPERAND (node, 2)) | |
c7d4e749 | 3127 | UPDATE_FLAGS (TREE_OPERAND (node, 2)); |
20506a1d | 3128 | } |
6374121b | 3129 | else if (TREE_CODE (node) == BIT_FIELD_REF) |
c7d4e749 | 3130 | UPDATE_FLAGS (TREE_OPERAND (node, 2)); |
6374121b | 3131 | } |
b27ac6b5 | 3132 | |
c7d4e749 | 3133 | node = lang_hooks.expr_to_decl (node, &tc, &se); |
54d7165a | 3134 | |
6374121b | 3135 | /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from |
c7d4e749 | 3136 | the address, since &(*a)->b is a form of addition. If it's a constant, the |
3137 | address is constant too. If it's a decl, its address is constant if the | |
3138 | decl is static. Everything else is not constant and, furthermore, | |
3139 | taking the address of a volatile variable is not volatile. */ | |
6374121b | 3140 | if (TREE_CODE (node) == INDIRECT_REF) |
c7d4e749 | 3141 | UPDATE_FLAGS (TREE_OPERAND (node, 0)); |
ce45a448 | 3142 | else if (CONSTANT_CLASS_P (node)) |
6374121b | 3143 | ; |
c7d4e749 | 3144 | else if (DECL_P (node)) |
3145 | tc &= (staticp (node) != NULL_TREE); | |
6374121b | 3146 | else |
3147 | { | |
c7d4e749 | 3148 | tc = false; |
6374121b | 3149 | se |= TREE_SIDE_EFFECTS (node); |
4ee9c684 | 3150 | } |
3151 | ||
c7d4e749 | 3152 | |
4ee9c684 | 3153 | TREE_CONSTANT (t) = tc; |
6374121b | 3154 | TREE_SIDE_EFFECTS (t) = se; |
c7d4e749 | 3155 | #undef UPDATE_FLAGS |
4ee9c684 | 3156 | } |
3157 | ||
413a7abf | 3158 | /* Build an expression of code CODE, data type TYPE, and operands as |
3159 | specified. Expressions and reference nodes can be created this way. | |
3160 | Constants, decls, types and misc nodes cannot be. | |
3161 | ||
3162 | We define 5 non-variadic functions, from 0 to 4 arguments. This is | |
c1f8b332 | 3163 | enough for all extant tree codes. */ |
10a9d4cf | 3164 | |
3165 | tree | |
674b05f5 | 3166 | build0_stat (enum tree_code code, tree tt MEM_STAT_DECL) |
10a9d4cf | 3167 | { |
19cb6b50 | 3168 | tree t; |
10a9d4cf | 3169 | |
8c0963c4 | 3170 | gcc_assert (TREE_CODE_LENGTH (code) == 0); |
e9a0313b | 3171 | |
674b05f5 | 3172 | t = make_node_stat (code PASS_MEM_STAT); |
e9a0313b | 3173 | TREE_TYPE (t) = tt; |
10a9d4cf | 3174 | |
10a9d4cf | 3175 | return t; |
3176 | } | |
3177 | ||
10a9d4cf | 3178 | tree |
674b05f5 | 3179 | build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL) |
10a9d4cf | 3180 | { |
64b4a388 | 3181 | int length = sizeof (struct tree_exp); |
07e64d6e | 3182 | #ifdef GATHER_STATISTICS |
19cb6b50 | 3183 | tree_node_kind kind; |
07e64d6e | 3184 | #endif |
19cb6b50 | 3185 | tree t; |
10a9d4cf | 3186 | |
3187 | #ifdef GATHER_STATISTICS | |
64b4a388 | 3188 | switch (TREE_CODE_CLASS (code)) |
3189 | { | |
ce45a448 | 3190 | case tcc_statement: /* an expression with side effects */ |
64b4a388 | 3191 | kind = s_kind; |
3192 | break; | |
ce45a448 | 3193 | case tcc_reference: /* a reference */ |
64b4a388 | 3194 | kind = r_kind; |
3195 | break; | |
3196 | default: | |
3197 | kind = e_kind; | |
3198 | break; | |
3199 | } | |
3200 | ||
3201 | tree_node_counts[(int) kind]++; | |
3202 | tree_node_sizes[(int) kind] += length; | |
10a9d4cf | 3203 | #endif |
3204 | ||
8c0963c4 | 3205 | gcc_assert (TREE_CODE_LENGTH (code) == 1); |
6ba31ca8 | 3206 | |
45ba1503 | 3207 | t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); |
791ceafe | 3208 | |
b9a7cc69 | 3209 | memset (t, 0, sizeof (struct tree_common)); |
10a9d4cf | 3210 | |
10a9d4cf | 3211 | TREE_SET_CODE (t, code); |
49393347 | 3212 | |
791ceafe | 3213 | TREE_TYPE (t) = type; |
fdfe4b3f | 3214 | SET_EXPR_LOCATION (t, UNKNOWN_LOCATION); |
10a9d4cf | 3215 | TREE_OPERAND (t, 0) = node; |
4ee9c684 | 3216 | TREE_BLOCK (t) = NULL_TREE; |
4161c18d | 3217 | if (node && !TYPE_P (node)) |
49393347 | 3218 | { |
3219 | TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node); | |
3220 | TREE_READONLY (t) = TREE_READONLY (node); | |
3221 | } | |
10a9d4cf | 3222 | |
ce45a448 | 3223 | if (TREE_CODE_CLASS (code) == tcc_statement) |
13ebc860 | 3224 | TREE_SIDE_EFFECTS (t) = 1; |
64b4a388 | 3225 | else switch (code) |
c2b39255 | 3226 | { |
c2b39255 | 3227 | case VA_ARG_EXPR: |
c2b39255 | 3228 | /* All of these have side-effects, no matter what their |
3229 | operands are. */ | |
3230 | TREE_SIDE_EFFECTS (t) = 1; | |
49393347 | 3231 | TREE_READONLY (t) = 0; |
c2b39255 | 3232 | break; |
d965574e | 3233 | |
b056d812 | 3234 | case MISALIGNED_INDIRECT_REF: |
3235 | case ALIGN_INDIRECT_REF: | |
d965574e | 3236 | case INDIRECT_REF: |
3237 | /* Whether a dereference is readonly has nothing to do with whether | |
3238 | its operand is readonly. */ | |
3239 | TREE_READONLY (t) = 0; | |
3240 | break; | |
9bfff6cb | 3241 | |
a708df98 | 3242 | case ADDR_EXPR: |
3243 | if (node) | |
750ad201 | 3244 | recompute_tree_invariant_for_addr_expr (t); |
a708df98 | 3245 | break; |
3246 | ||
c2b39255 | 3247 | default: |
25a7cbe1 | 3248 | if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR) |
ce45a448 | 3249 | && node && !TYPE_P (node) |
66d12a6c | 3250 | && TREE_CONSTANT (node)) |
8541c166 | 3251 | TREE_CONSTANT (t) = 1; |
ce45a448 | 3252 | if (TREE_CODE_CLASS (code) == tcc_reference |
3253 | && node && TREE_THIS_VOLATILE (node)) | |
b25de375 | 3254 | TREE_THIS_VOLATILE (t) = 1; |
c2b39255 | 3255 | break; |
3256 | } | |
3257 | ||
10a9d4cf | 3258 | return t; |
3259 | } | |
3260 | ||
413a7abf | 3261 | #define PROCESS_ARG(N) \ |
3262 | do { \ | |
3263 | TREE_OPERAND (t, N) = arg##N; \ | |
4161c18d | 3264 | if (arg##N &&!TYPE_P (arg##N)) \ |
413a7abf | 3265 | { \ |
3266 | if (TREE_SIDE_EFFECTS (arg##N)) \ | |
3267 | side_effects = 1; \ | |
3268 | if (!TREE_READONLY (arg##N)) \ | |
3269 | read_only = 0; \ | |
3270 | if (!TREE_CONSTANT (arg##N)) \ | |
3271 | constant = 0; \ | |
3272 | } \ | |
3273 | } while (0) | |
3274 | ||
3275 | tree | |
674b05f5 | 3276 | build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL) |
413a7abf | 3277 | { |
c7d4e749 | 3278 | bool constant, read_only, side_effects; |
413a7abf | 3279 | tree t; |
413a7abf | 3280 | |
8c0963c4 | 3281 | gcc_assert (TREE_CODE_LENGTH (code) == 2); |
413a7abf | 3282 | |
0de36bdb | 3283 | if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR) |
5c485e88 | 3284 | && arg0 && arg1 && tt && POINTER_TYPE_P (tt) |
3285 | /* When sizetype precision doesn't match that of pointers | |
3286 | we need to be able to build explicit extensions or truncations | |
3287 | of the offset argument. */ | |
3288 | && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt)) | |
3289 | gcc_assert (TREE_CODE (arg0) == INTEGER_CST | |
3290 | && TREE_CODE (arg1) == INTEGER_CST); | |
0de36bdb | 3291 | |
3292 | if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt) | |
3293 | gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0)) | |
d2c9d80d | 3294 | && INTEGRAL_TYPE_P (TREE_TYPE (arg1)) |
548044d8 | 3295 | && useless_type_conversion_p (sizetype, TREE_TYPE (arg1))); |
0de36bdb | 3296 | |
674b05f5 | 3297 | t = make_node_stat (code PASS_MEM_STAT); |
413a7abf | 3298 | TREE_TYPE (t) = tt; |
3299 | ||
3300 | /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the | |
3301 | result based on those same flags for the arguments. But if the | |
3302 | arguments aren't really even `tree' expressions, we shouldn't be trying | |
3303 | to do this. */ | |
413a7abf | 3304 | |
3305 | /* Expressions without side effects may be constant if their | |
3306 | arguments are as well. */ | |
ce45a448 | 3307 | constant = (TREE_CODE_CLASS (code) == tcc_comparison |
3308 | || TREE_CODE_CLASS (code) == tcc_binary); | |
413a7abf | 3309 | read_only = 1; |
3310 | side_effects = TREE_SIDE_EFFECTS (t); | |
3311 | ||
3312 | PROCESS_ARG(0); | |
3313 | PROCESS_ARG(1); | |
3314 | ||
413a7abf | 3315 | TREE_READONLY (t) = read_only; |
3316 | TREE_CONSTANT (t) = constant; | |
b27ac6b5 | 3317 | TREE_SIDE_EFFECTS (t) = side_effects; |
6374121b | 3318 | TREE_THIS_VOLATILE (t) |
ce45a448 | 3319 | = (TREE_CODE_CLASS (code) == tcc_reference |
3320 | && arg0 && TREE_THIS_VOLATILE (arg0)); | |
413a7abf | 3321 | |
3322 | return t; | |
3323 | } | |
3324 | ||
35cc02b5 | 3325 | |
413a7abf | 3326 | tree |
674b05f5 | 3327 | build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1, |
3328 | tree arg2 MEM_STAT_DECL) | |
413a7abf | 3329 | { |
c7d4e749 | 3330 | bool constant, read_only, side_effects; |
413a7abf | 3331 | tree t; |
413a7abf | 3332 | |
8c0963c4 | 3333 | gcc_assert (TREE_CODE_LENGTH (code) == 3); |
c2f47e15 | 3334 | gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); |
413a7abf | 3335 | |
674b05f5 | 3336 | t = make_node_stat (code PASS_MEM_STAT); |
413a7abf | 3337 | TREE_TYPE (t) = tt; |
3338 | ||
63f88450 | 3339 | /* As a special exception, if COND_EXPR has NULL branches, we |
3340 | assume that it is a gimple statement and always consider | |
3341 | it to have side effects. */ | |
3342 | if (code == COND_EXPR | |
3343 | && tt == void_type_node | |
3344 | && arg1 == NULL_TREE | |
3345 | && arg2 == NULL_TREE) | |
3346 | side_effects = true; | |
3347 | else | |
3348 | side_effects = TREE_SIDE_EFFECTS (t); | |
413a7abf | 3349 | |
3350 | PROCESS_ARG(0); | |
3351 | PROCESS_ARG(1); | |
3352 | PROCESS_ARG(2); | |
3353 | ||
b27ac6b5 | 3354 | TREE_SIDE_EFFECTS (t) = side_effects; |
6374121b | 3355 | TREE_THIS_VOLATILE (t) |
ce45a448 | 3356 | = (TREE_CODE_CLASS (code) == tcc_reference |
3357 | && arg0 && TREE_THIS_VOLATILE (arg0)); | |
413a7abf | 3358 | |
3359 | return t; | |
3360 | } | |
3361 | ||
3362 | tree | |
674b05f5 | 3363 | build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1, |
3364 | tree arg2, tree arg3 MEM_STAT_DECL) | |
413a7abf | 3365 | { |
c7d4e749 | 3366 | bool constant, read_only, side_effects; |
413a7abf | 3367 | tree t; |
413a7abf | 3368 | |
8c0963c4 | 3369 | gcc_assert (TREE_CODE_LENGTH (code) == 4); |
413a7abf | 3370 | |
674b05f5 | 3371 | t = make_node_stat (code PASS_MEM_STAT); |
413a7abf | 3372 | TREE_TYPE (t) = tt; |
3373 | ||
413a7abf | 3374 | side_effects = TREE_SIDE_EFFECTS (t); |
3375 | ||
3376 | PROCESS_ARG(0); | |
3377 | PROCESS_ARG(1); | |
3378 | PROCESS_ARG(2); | |
3379 | PROCESS_ARG(3); | |
3380 | ||
b27ac6b5 | 3381 | TREE_SIDE_EFFECTS (t) = side_effects; |
6374121b | 3382 | TREE_THIS_VOLATILE (t) |
ce45a448 | 3383 | = (TREE_CODE_CLASS (code) == tcc_reference |
3384 | && arg0 && TREE_THIS_VOLATILE (arg0)); | |
413a7abf | 3385 | |
3386 | return t; | |
3387 | } | |
3388 | ||
1e8e9920 | 3389 | tree |
3390 | build5_stat (enum tree_code code, tree tt, tree arg0, tree arg1, | |
3391 | tree arg2, tree arg3, tree arg4 MEM_STAT_DECL) | |
3392 | { | |
c7d4e749 | 3393 | bool constant, read_only, side_effects; |
1e8e9920 | 3394 | tree t; |
3395 | ||
3396 | gcc_assert (TREE_CODE_LENGTH (code) == 5); | |
3397 | ||
3398 | t = make_node_stat (code PASS_MEM_STAT); | |
3399 | TREE_TYPE (t) = tt; | |
3400 | ||
3401 | side_effects = TREE_SIDE_EFFECTS (t); | |
3402 | ||
3403 | PROCESS_ARG(0); | |
3404 | PROCESS_ARG(1); | |
3405 | PROCESS_ARG(2); | |
3406 | PROCESS_ARG(3); | |
3407 | PROCESS_ARG(4); | |
3408 | ||
3409 | TREE_SIDE_EFFECTS (t) = side_effects; | |
3410 | TREE_THIS_VOLATILE (t) | |
3411 | = (TREE_CODE_CLASS (code) == tcc_reference | |
3412 | && arg0 && TREE_THIS_VOLATILE (arg0)); | |
3413 | ||
3414 | return t; | |
3415 | } | |
3416 | ||
aed164c3 | 3417 | tree |
dd277d48 | 3418 | build6_stat (enum tree_code code, tree tt, tree arg0, tree arg1, |
3419 | tree arg2, tree arg3, tree arg4, tree arg5 MEM_STAT_DECL) | |
aed164c3 | 3420 | { |
c7d4e749 | 3421 | bool constant, read_only, side_effects; |
aed164c3 | 3422 | tree t; |
3423 | ||
3424 | gcc_assert (code == TARGET_MEM_REF); | |
3425 | ||
3426 | t = make_node_stat (code PASS_MEM_STAT); | |
3427 | TREE_TYPE (t) = tt; | |
3428 | ||
3429 | side_effects = TREE_SIDE_EFFECTS (t); | |
3430 | ||
3431 | PROCESS_ARG(0); | |
3432 | PROCESS_ARG(1); | |
3433 | PROCESS_ARG(2); | |
3434 | PROCESS_ARG(3); | |
3435 | PROCESS_ARG(4); | |
3436 | PROCESS_ARG(5); | |
aed164c3 | 3437 | |
3438 | TREE_SIDE_EFFECTS (t) = side_effects; | |
3439 | TREE_THIS_VOLATILE (t) = 0; | |
3440 | ||
3441 | return t; | |
3442 | } | |
3443 | ||
10a9d4cf | 3444 | /* Similar except don't specify the TREE_TYPE |
3445 | and leave the TREE_SIDE_EFFECTS as 0. | |
3446 | It is permissible for arguments to be null, | |
3447 | or even garbage if their values do not matter. */ | |
3448 | ||
3449 | tree | |
ee582a61 | 3450 | build_nt (enum tree_code code, ...) |
10a9d4cf | 3451 | { |
19cb6b50 | 3452 | tree t; |
3453 | int length; | |
3454 | int i; | |
ee582a61 | 3455 | va_list p; |
10a9d4cf | 3456 | |
c2f47e15 | 3457 | gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); |
3458 | ||
ee582a61 | 3459 | va_start (p, code); |
e9a0313b | 3460 | |
10a9d4cf | 3461 | t = make_node (code); |
f3c6d29a | 3462 | length = TREE_CODE_LENGTH (code); |
10a9d4cf | 3463 | |
3464 | for (i = 0; i < length; i++) | |
3465 | TREE_OPERAND (t, i) = va_arg (p, tree); | |
3466 | ||
ee582a61 | 3467 | va_end (p); |
10a9d4cf | 3468 | return t; |
3469 | } | |
c2f47e15 | 3470 | |
3471 | /* Similar to build_nt, but for creating a CALL_EXPR object with | |
3472 | ARGLIST passed as a list. */ | |
3473 | ||
3474 | tree | |
3475 | build_nt_call_list (tree fn, tree arglist) | |
3476 | { | |
3477 | tree t; | |
3478 | int i; | |
3479 | ||
3480 | t = build_vl_exp (CALL_EXPR, list_length (arglist) + 3); | |
3481 | CALL_EXPR_FN (t) = fn; | |
3482 | CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE; | |
3483 | for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++) | |
3484 | CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist); | |
3485 | return t; | |
3486 | } | |
10a9d4cf | 3487 | \f |
3488 | /* Create a DECL_... node of code CODE, name NAME and data type TYPE. | |
3489 | We do NOT enter this node in any sort of symbol table. | |
3490 | ||
3491 | layout_decl is used to set up the decl's storage layout. | |
3492 | Other slots are initialized to 0 or null pointers. */ | |
3493 | ||
3494 | tree | |
674b05f5 | 3495 | build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL) |
10a9d4cf | 3496 | { |
19cb6b50 | 3497 | tree t; |
10a9d4cf | 3498 | |
674b05f5 | 3499 | t = make_node_stat (code PASS_MEM_STAT); |
10a9d4cf | 3500 | |
3501 | /* if (type == error_mark_node) | |
3502 | type = integer_type_node; */ | |
3503 | /* That is not done, deliberately, so that having error_mark_node | |
3504 | as the type can suppress useless errors in the use of this variable. */ | |
3505 | ||
3506 | DECL_NAME (t) = name; | |
10a9d4cf | 3507 | TREE_TYPE (t) = type; |
3508 | ||
3509 | if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL) | |
3510 | layout_decl (t, 0); | |
b27ac6b5 | 3511 | |
10a9d4cf | 3512 | return t; |
3513 | } | |
d7683f13 | 3514 | |
3515 | /* Builds and returns function declaration with NAME and TYPE. */ | |
3516 | ||
3517 | tree | |
3518 | build_fn_decl (const char *name, tree type) | |
3519 | { | |
3520 | tree id = get_identifier (name); | |
3521 | tree decl = build_decl (FUNCTION_DECL, id, type); | |
3522 | ||
3523 | DECL_EXTERNAL (decl) = 1; | |
3524 | TREE_PUBLIC (decl) = 1; | |
3525 | DECL_ARTIFICIAL (decl) = 1; | |
3526 | TREE_NOTHROW (decl) = 1; | |
3527 | ||
3528 | return decl; | |
3529 | } | |
3530 | ||
10a9d4cf | 3531 | \f |
3532 | /* BLOCK nodes are used to represent the structure of binding contours | |
3533 | and declarations, once those contours have been exited and their contents | |
98eaba23 | 3534 | compiled. This information is used for outputting debugging info. */ |
10a9d4cf | 3535 | |
3536 | tree | |
0a4b7550 | 3537 | build_block (tree vars, tree subblocks, tree supercontext, tree chain) |
10a9d4cf | 3538 | { |
19cb6b50 | 3539 | tree block = make_node (BLOCK); |
083a2b5e | 3540 | |
10a9d4cf | 3541 | BLOCK_VARS (block) = vars; |
10a9d4cf | 3542 | BLOCK_SUBBLOCKS (block) = subblocks; |
3543 | BLOCK_SUPERCONTEXT (block) = supercontext; | |
3544 | BLOCK_CHAIN (block) = chain; | |
3545 | return block; | |
3546 | } | |
dae7d8ad | 3547 | |
fdfe4b3f | 3548 | expanded_location |
3549 | expand_location (source_location loc) | |
3550 | { | |
3551 | expanded_location xloc; | |
7d4c98bc | 3552 | if (loc == 0) |
3553 | { | |
3554 | xloc.file = NULL; | |
3555 | xloc.line = 0; | |
3556 | xloc.column = 0; | |
bdbc474b | 3557 | xloc.sysp = 0; |
7d4c98bc | 3558 | } |
fdfe4b3f | 3559 | else |
3560 | { | |
931b0a0f | 3561 | const struct line_map *map = linemap_lookup (line_table, loc); |
fdfe4b3f | 3562 | xloc.file = map->to_file; |
3563 | xloc.line = SOURCE_LINE (map, loc); | |
a59d74d6 | 3564 | xloc.column = SOURCE_COLUMN (map, loc); |
bdbc474b | 3565 | xloc.sysp = map->sysp != 0; |
fdfe4b3f | 3566 | }; |
3567 | return xloc; | |
3568 | } | |
3569 | ||
10a9d4cf | 3570 | \f |
35cc02b5 | 3571 | /* Source location accessor functions. */ |
3572 | ||
3573 | ||
35cc02b5 | 3574 | void |
9c85a98a | 3575 | set_expr_locus (tree node, source_location *loc) |
35cc02b5 | 3576 | { |
35cc02b5 | 3577 | if (loc == NULL) |
75a70cf9 | 3578 | EXPR_CHECK (node)->exp.locus = UNKNOWN_LOCATION; |
35cc02b5 | 3579 | else |
75a70cf9 | 3580 | EXPR_CHECK (node)->exp.locus = *loc; |
35cc02b5 | 3581 | } |
dda49785 | 3582 | |
3583 | /* Like SET_EXPR_LOCATION, but make sure the tree can have a location. | |
3584 | ||
3585 | LOC is the location to use in tree T. */ | |
3586 | ||
3587 | void protected_set_expr_location (tree t, location_t loc) | |
3588 | { | |
064963bb | 3589 | if (t && CAN_HAVE_LOCATION_P (t)) |
dda49785 | 3590 | SET_EXPR_LOCATION (t, loc); |
3591 | } | |
35cc02b5 | 3592 | \f |
e3c541f0 | 3593 | /* Return a declaration like DDECL except that its DECL_ATTRIBUTES |
a92771b8 | 3594 | is ATTRIBUTE. */ |
83e622ea | 3595 | |
3596 | tree | |
60b8c5b3 | 3597 | build_decl_attribute_variant (tree ddecl, tree attribute) |
83e622ea | 3598 | { |
e3c541f0 | 3599 | DECL_ATTRIBUTES (ddecl) = attribute; |
83e622ea | 3600 | return ddecl; |
3601 | } | |
3602 | ||
c068056a | 3603 | /* Borrowed from hashtab.c iterative_hash implementation. */ |
3604 | #define mix(a,b,c) \ | |
3605 | { \ | |
3606 | a -= b; a -= c; a ^= (c>>13); \ | |
3607 | b -= c; b -= a; b ^= (a<< 8); \ | |
3608 | c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \ | |
3609 | a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \ | |
3610 | b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \ | |
3611 | c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \ | |
3612 | a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \ | |
3613 | b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \ | |
3614 | c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \ | |
3615 | } | |
3616 | ||
3617 | ||
3618 | /* Produce good hash value combining VAL and VAL2. */ | |
f6c33c78 | 3619 | hashval_t |
c068056a | 3620 | iterative_hash_hashval_t (hashval_t val, hashval_t val2) |
3621 | { | |
3622 | /* the golden ratio; an arbitrary value. */ | |
3623 | hashval_t a = 0x9e3779b9; | |
3624 | ||
3625 | mix (a, val, val2); | |
3626 | return val2; | |
3627 | } | |
3628 | ||
3629 | /* Produce good hash value combining PTR and VAL2. */ | |
3630 | static inline hashval_t | |
720082dc | 3631 | iterative_hash_pointer (const void *ptr, hashval_t val2) |
c068056a | 3632 | { |
3633 | if (sizeof (ptr) == sizeof (hashval_t)) | |
3634 | return iterative_hash_hashval_t ((size_t) ptr, val2); | |
3635 | else | |
3636 | { | |
3637 | hashval_t a = (hashval_t) (size_t) ptr; | |
3638 | /* Avoid warnings about shifting of more than the width of the type on | |
3639 | hosts that won't execute this path. */ | |
3640 | int zero = 0; | |
3641 | hashval_t b = (hashval_t) ((size_t) ptr >> (sizeof (hashval_t) * 8 + zero)); | |
3642 | mix (a, b, val2); | |
3643 | return val2; | |
3644 | } | |
3645 | } | |
3646 | ||
3647 | /* Produce good hash value combining VAL and VAL2. */ | |
3648 | static inline hashval_t | |
3649 | iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2) | |
3650 | { | |
3651 | if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t)) | |
3652 | return iterative_hash_hashval_t (val, val2); | |
3653 | else | |
3654 | { | |
3655 | hashval_t a = (hashval_t) val; | |
3656 | /* Avoid warnings about shifting of more than the width of the type on | |
3657 | hosts that won't execute this path. */ | |
3658 | int zero = 0; | |
3659 | hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 8 + zero)); | |
3660 | mix (a, b, val2); | |
3661 | if (sizeof (HOST_WIDE_INT) > 2 * sizeof (hashval_t)) | |
3662 | { | |
3663 | hashval_t a = (hashval_t) (val >> (sizeof (hashval_t) * 16 + zero)); | |
3664 | hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 24 + zero)); | |
3665 | mix (a, b, val2); | |
3666 | } | |
3667 | return val2; | |
3668 | } | |
3669 | } | |
3670 | ||
9dd95dae | 3671 | /* Return a type like TTYPE except that its TYPE_ATTRIBUTE |
b7d1b569 | 3672 | is ATTRIBUTE and its qualifiers are QUALS. |
9dd95dae | 3673 | |
7331a85d | 3674 | Record such modified types already made so we don't make duplicates. */ |
9dd95dae | 3675 | |
b7d1b569 | 3676 | static tree |
3677 | build_type_attribute_qual_variant (tree ttype, tree attribute, int quals) | |
9dd95dae | 3678 | { |
709c2f34 | 3679 | if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute)) |
9dd95dae | 3680 | { |
908e5f41 | 3681 | hashval_t hashcode = 0; |
9dd95dae | 3682 | tree ntype; |
908e5f41 | 3683 | enum tree_code code = TREE_CODE (ttype); |
9dd95dae | 3684 | |
881eb642 | 3685 | /* Building a distinct copy of a tagged type is inappropriate; it |
3686 | causes breakage in code that expects there to be a one-to-one | |
3687 | relationship between a struct and its fields. | |
3688 | build_duplicate_type is another solution (as used in | |
3689 | handle_transparent_union_attribute), but that doesn't play well | |
3690 | with the stronger C++ type identity model. */ | |
3691 | if (TREE_CODE (ttype) == RECORD_TYPE | |
3692 | || TREE_CODE (ttype) == UNION_TYPE | |
3693 | || TREE_CODE (ttype) == QUAL_UNION_TYPE | |
3694 | || TREE_CODE (ttype) == ENUMERAL_TYPE) | |
3695 | { | |
3696 | warning (OPT_Wattributes, | |
3697 | "ignoring attributes applied to %qT after definition", | |
3698 | TYPE_MAIN_VARIANT (ttype)); | |
3699 | return build_qualified_type (ttype, quals); | |
3700 | } | |
9dd95dae | 3701 | |
54deba71 | 3702 | ttype = build_qualified_type (ttype, TYPE_UNQUALIFIED); |
881eb642 | 3703 | ntype = build_distinct_type_copy (ttype); |
9dd95dae | 3704 | |
881eb642 | 3705 | TYPE_ATTRIBUTES (ntype) = attribute; |
9dd95dae | 3706 | |
908e5f41 | 3707 | hashcode = iterative_hash_object (code, hashcode); |
3708 | if (TREE_TYPE (ntype)) | |
3709 | hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)), | |
3710 | hashcode); | |
3711 | hashcode = attribute_hash_list (attribute, hashcode); | |
9dd95dae | 3712 | |
3713 | switch (TREE_CODE (ntype)) | |
9bfff6cb | 3714 | { |
0dbd1c74 | 3715 | case FUNCTION_TYPE: |
908e5f41 | 3716 | hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode); |
0dbd1c74 | 3717 | break; |
3718 | case ARRAY_TYPE: | |
e14d689c | 3719 | if (TYPE_DOMAIN (ntype)) |
3720 | hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)), | |
3721 | hashcode); | |
0dbd1c74 | 3722 | break; |
3723 | case INTEGER_TYPE: | |
908e5f41 | 3724 | hashcode = iterative_hash_object |
3725 | (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode); | |
3726 | hashcode = iterative_hash_object | |
3727 | (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode); | |
0dbd1c74 | 3728 | break; |
3729 | case REAL_TYPE: | |
06f0b99c | 3730 | case FIXED_POINT_TYPE: |
908e5f41 | 3731 | { |
3732 | unsigned int precision = TYPE_PRECISION (ntype); | |
3733 | hashcode = iterative_hash_object (precision, hashcode); | |
3734 | } | |
0dbd1c74 | 3735 | break; |
3736 | default: | |
3737 | break; | |
9bfff6cb | 3738 | } |
9dd95dae | 3739 | |
3740 | ntype = type_hash_canon (hashcode, ntype); | |
6753bca0 | 3741 | |
3742 | /* If the target-dependent attributes make NTYPE different from | |
3743 | its canonical type, we will need to use structural equality | |
54deba71 | 3744 | checks for this type. */ |
8059d350 | 3745 | if (TYPE_STRUCTURAL_EQUALITY_P (ttype) |
3746 | || !targetm.comp_type_attributes (ntype, ttype)) | |
6753bca0 | 3747 | SET_TYPE_STRUCTURAL_EQUALITY (ntype); |
54deba71 | 3748 | else if (TYPE_CANONICAL (ntype) == ntype) |
8059d350 | 3749 | TYPE_CANONICAL (ntype) = TYPE_CANONICAL (ttype); |
6753bca0 | 3750 | |
b7d1b569 | 3751 | ttype = build_qualified_type (ntype, quals); |
9dd95dae | 3752 | } |
06faa2fe | 3753 | else if (TYPE_QUALS (ttype) != quals) |
3754 | ttype = build_qualified_type (ttype, quals); | |
9dd95dae | 3755 | |
3756 | return ttype; | |
3757 | } | |
83e622ea | 3758 | |
23e9e85f | 3759 | |
b7d1b569 | 3760 | /* Return a type like TTYPE except that its TYPE_ATTRIBUTE |
3761 | is ATTRIBUTE. | |
3762 | ||
3763 | Record such modified types already made so we don't make duplicates. */ | |
3764 | ||
3765 | tree | |
3766 | build_type_attribute_variant (tree ttype, tree attribute) | |
3767 | { | |
3768 | return build_type_attribute_qual_variant (ttype, attribute, | |
3769 | TYPE_QUALS (ttype)); | |
3770 | } | |
3771 | ||
f712a0dc | 3772 | /* Return nonzero if IDENT is a valid name for attribute ATTR, |
edee2468 | 3773 | or zero if not. |
3774 | ||
3775 | We try both `text' and `__text__', ATTR may be either one. */ | |
3776 | /* ??? It might be a reasonable simplification to require ATTR to be only | |
3777 | `text'. One might then also require attribute lists to be stored in | |
3778 | their canonicalized form. */ | |
3779 | ||
23e9e85f | 3780 | static int |
720082dc | 3781 | is_attribute_with_length_p (const char *attr, int attr_len, const_tree ident) |
edee2468 | 3782 | { |
23e9e85f | 3783 | int ident_len; |
71d9fc9b | 3784 | const char *p; |
edee2468 | 3785 | |
3786 | if (TREE_CODE (ident) != IDENTIFIER_NODE) | |
3787 | return 0; | |
23e9e85f | 3788 | |
edee2468 | 3789 | p = IDENTIFIER_POINTER (ident); |
23e9e85f | 3790 | ident_len = IDENTIFIER_LENGTH (ident); |
3791 | ||
3792 | if (ident_len == attr_len | |
3793 | && strcmp (attr, p) == 0) | |
3794 | return 1; | |
edee2468 | 3795 | |
3796 | /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */ | |
3797 | if (attr[0] == '_') | |
3798 | { | |
8c0963c4 | 3799 | gcc_assert (attr[1] == '_'); |
3800 | gcc_assert (attr[attr_len - 2] == '_'); | |
3801 | gcc_assert (attr[attr_len - 1] == '_'); | |
edee2468 | 3802 | if (ident_len == attr_len - 4 |
3803 | && strncmp (attr + 2, p, attr_len - 4) == 0) | |
3804 | return 1; | |
3805 | } | |
3806 | else | |
3807 | { | |
3808 | if (ident_len == attr_len + 4 | |
3809 | && p[0] == '_' && p[1] == '_' | |
3810 | && p[ident_len - 2] == '_' && p[ident_len - 1] == '_' | |
3811 | && strncmp (attr, p + 2, attr_len) == 0) | |
3812 | return 1; | |
3813 | } | |
3814 | ||
3815 | return 0; | |
3816 | } | |
3817 | ||
23e9e85f | 3818 | /* Return nonzero if IDENT is a valid name for attribute ATTR, |
3819 | or zero if not. | |
3820 | ||
3821 | We try both `text' and `__text__', ATTR may be either one. */ | |
3822 | ||
3823 | int | |
720082dc | 3824 | is_attribute_p (const char *attr, const_tree ident) |
23e9e85f | 3825 | { |
3826 | return is_attribute_with_length_p (attr, strlen (attr), ident); | |
3827 | } | |
3828 | ||
edee2468 | 3829 | /* Given an attribute name and a list of attributes, return a pointer to the |
3830 | attribute's list element if the attribute is part of the list, or NULL_TREE | |
e3c541f0 | 3831 | if not found. If the attribute appears more than once, this only |
424da949 | 3832 | returns the first occurrence; the TREE_CHAIN of the return value should |
3833 | be passed back in if further occurrences are wanted. */ | |
edee2468 | 3834 | |
3835 | tree | |
60b8c5b3 | 3836 | lookup_attribute (const char *attr_name, tree list) |
edee2468 | 3837 | { |
ce4469fa | 3838 | tree l; |
3839 | size_t attr_len = strlen (attr_name); | |
edee2468 | 3840 | |
ce4469fa | 3841 | for (l = list; l; l = TREE_CHAIN (l)) |
3842 | { | |
3843 | gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE); | |
3844 | if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l))) | |
3845 | return l; | |
3846 | } | |
3847 | return NULL_TREE; | |
edee2468 | 3848 | } |
0d647a4f | 3849 | |
6a47600c | 3850 | /* Remove any instances of attribute ATTR_NAME in LIST and return the |
3851 | modified list. */ | |
3852 | ||
3853 | tree | |
3854 | remove_attribute (const char *attr_name, tree list) | |
3855 | { | |
3856 | tree *p; | |
3857 | size_t attr_len = strlen (attr_name); | |
3858 | ||
3859 | for (p = &list; *p; ) | |
3860 | { | |
3861 | tree l = *p; | |
3862 | gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE); | |
3863 | if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l))) | |
3864 | *p = TREE_CHAIN (l); | |
3865 | else | |
3866 | p = &TREE_CHAIN (l); | |
3867 | } | |
3868 | ||
3869 | return list; | |
3870 | } | |
3871 | ||
0d647a4f | 3872 | /* Return an attribute list that is the union of a1 and a2. */ |
3873 | ||
3874 | tree | |
60b8c5b3 | 3875 | merge_attributes (tree a1, tree a2) |
0d647a4f | 3876 | { |
3877 | tree attributes; | |
3878 | ||
3879 | /* Either one unset? Take the set one. */ | |
3880 | ||
083a2b5e | 3881 | if ((attributes = a1) == 0) |
0d647a4f | 3882 | attributes = a2; |
3883 | ||
3884 | /* One that completely contains the other? Take it. */ | |
3885 | ||
083a2b5e | 3886 | else if (a2 != 0 && ! attribute_list_contained (a1, a2)) |
9bfff6cb | 3887 | { |
3888 | if (attribute_list_contained (a2, a1)) | |
3889 | attributes = a2; | |
3890 | else | |
3891 | { | |
3892 | /* Pick the longest list, and hang on the other list. */ | |
9bfff6cb | 3893 | |
3894 | if (list_length (a1) < list_length (a2)) | |
3895 | attributes = a2, a2 = a1; | |
3896 | ||
3897 | for (; a2 != 0; a2 = TREE_CHAIN (a2)) | |
e3c541f0 | 3898 | { |
3899 | tree a; | |
3900 | for (a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)), | |
3901 | attributes); | |
3902 | a != NULL_TREE; | |
3903 | a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)), | |
3904 | TREE_CHAIN (a))) | |
3905 | { | |
9369a09f | 3906 | if (TREE_VALUE (a) != NULL |
3907 | && TREE_CODE (TREE_VALUE (a)) == TREE_LIST | |
3908 | && TREE_VALUE (a2) != NULL | |
3909 | && TREE_CODE (TREE_VALUE (a2)) == TREE_LIST) | |
3910 | { | |
3911 | if (simple_cst_list_equal (TREE_VALUE (a), | |
3912 | TREE_VALUE (a2)) == 1) | |
3913 | break; | |
3914 | } | |
3915 | else if (simple_cst_equal (TREE_VALUE (a), | |
3916 | TREE_VALUE (a2)) == 1) | |
e3c541f0 | 3917 | break; |
3918 | } | |
3919 | if (a == NULL_TREE) | |
3920 | { | |
3921 | a1 = copy_node (a2); | |
3922 | TREE_CHAIN (a1) = attributes; | |
3923 | attributes = a1; | |
3924 | } | |
3925 | } | |
9bfff6cb | 3926 | } |
3927 | } | |
0d647a4f | 3928 | return attributes; |
3929 | } | |
0bf60c2b | 3930 | |
3931 | /* Given types T1 and T2, merge their attributes and return | |
a767736d | 3932 | the result. */ |
0bf60c2b | 3933 | |
3934 | tree | |
60b8c5b3 | 3935 | merge_type_attributes (tree t1, tree t2) |
0bf60c2b | 3936 | { |
0bf60c2b | 3937 | return merge_attributes (TYPE_ATTRIBUTES (t1), |
3938 | TYPE_ATTRIBUTES (t2)); | |
0bf60c2b | 3939 | } |
3940 | ||
3941 | /* Given decls OLDDECL and NEWDECL, merge their attributes and return | |
3942 | the result. */ | |
3943 | ||
3944 | tree | |
60b8c5b3 | 3945 | merge_decl_attributes (tree olddecl, tree newdecl) |
0bf60c2b | 3946 | { |
e3c541f0 | 3947 | return merge_attributes (DECL_ATTRIBUTES (olddecl), |
3948 | DECL_ATTRIBUTES (newdecl)); | |
0bf60c2b | 3949 | } |
a767736d | 3950 | |
3aa0c315 | 3951 | #if TARGET_DLLIMPORT_DECL_ATTRIBUTES |
a767736d | 3952 | |
3953 | /* Specialization of merge_decl_attributes for various Windows targets. | |
3954 | ||
3955 | This handles the following situation: | |
3956 | ||
3957 | __declspec (dllimport) int foo; | |
3958 | int foo; | |
3959 | ||
3960 | The second instance of `foo' nullifies the dllimport. */ | |
3961 | ||
3962 | tree | |
8deb3959 | 3963 | merge_dllimport_decl_attributes (tree old, tree new_tree) |
a767736d | 3964 | { |
3965 | tree a; | |
6c1e551f | 3966 | int delete_dllimport_p = 1; |
a767736d | 3967 | |
3968 | /* What we need to do here is remove from `old' dllimport if it doesn't | |
3969 | appear in `new'. dllimport behaves like extern: if a declaration is | |
3970 | marked dllimport and a definition appears later, then the object | |
6c1e551f | 3971 | is not dllimport'd. We also remove a `new' dllimport if the old list |
3972 | contains dllexport: dllexport always overrides dllimport, regardless | |
3973 | of the order of declaration. */ | |
8deb3959 | 3974 | if (!VAR_OR_FUNCTION_DECL_P (new_tree)) |
6c1e551f | 3975 | delete_dllimport_p = 0; |
8deb3959 | 3976 | else if (DECL_DLLIMPORT_P (new_tree) |
6c1e551f | 3977 | && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old))) |
3978 | { | |
8deb3959 | 3979 | DECL_DLLIMPORT_P (new_tree) = 0; |
6c1e551f | 3980 | warning (OPT_Wattributes, "%q+D already declared with dllexport attribute: " |
8deb3959 | 3981 | "dllimport ignored", new_tree); |
6c1e551f | 3982 | } |
8deb3959 | 3983 | else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new_tree)) |
6c1e551f | 3984 | { |
f0b5f617 | 3985 | /* Warn about overriding a symbol that has already been used, e.g.: |
6c1e551f | 3986 | extern int __attribute__ ((dllimport)) foo; |
3987 | int* bar () {return &foo;} | |
3988 | int foo; | |
3989 | */ | |
3990 | if (TREE_USED (old)) | |
3991 | { | |
3992 | warning (0, "%q+D redeclared without dllimport attribute " | |
8deb3959 | 3993 | "after being referenced with dll linkage", new_tree); |
6c1e551f | 3994 | /* If we have used a variable's address with dllimport linkage, |
3995 | keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the | |
c7d4e749 | 3996 | decl may already have had TREE_CONSTANT computed. |
6c1e551f | 3997 | We still remove the attribute so that assembler code refers |
3998 | to '&foo rather than '_imp__foo'. */ | |
3999 | if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old)) | |
8deb3959 | 4000 | DECL_DLLIMPORT_P (new_tree) = 1; |
6c1e551f | 4001 | } |
4002 | ||
4003 | /* Let an inline definition silently override the external reference, | |
4004 | but otherwise warn about attribute inconsistency. */ | |
8deb3959 | 4005 | else if (TREE_CODE (new_tree) == VAR_DECL |
4006 | || !DECL_DECLARED_INLINE_P (new_tree)) | |
6c1e551f | 4007 | warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: " |
8deb3959 | 4008 | "previous dllimport ignored", new_tree); |
6c1e551f | 4009 | } |
a767736d | 4010 | else |
4011 | delete_dllimport_p = 0; | |
4012 | ||
8deb3959 | 4013 | a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new_tree)); |
a767736d | 4014 | |
6c1e551f | 4015 | if (delete_dllimport_p) |
a767736d | 4016 | { |
ac0c7fb1 | 4017 | tree prev, t; |
6c1e551f | 4018 | const size_t attr_len = strlen ("dllimport"); |
4019 | ||
a767736d | 4020 | /* Scan the list for dllimport and delete it. */ |
4021 | for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t)) | |
4022 | { | |
6c1e551f | 4023 | if (is_attribute_with_length_p ("dllimport", attr_len, |
4024 | TREE_PURPOSE (t))) | |
a767736d | 4025 | { |
4026 | if (prev == NULL_TREE) | |
4027 | a = TREE_CHAIN (a); | |
4028 | else | |
4029 | TREE_CHAIN (prev) = TREE_CHAIN (t); | |
4030 | break; | |
4031 | } | |
4032 | } | |
4033 | } | |
4034 | ||
4035 | return a; | |
4036 | } | |
4037 | ||
3aa0c315 | 4038 | /* Handle a "dllimport" or "dllexport" attribute; arguments as in |
4039 | struct attribute_spec.handler. */ | |
4040 | ||
4041 | tree | |
4042 | handle_dll_attribute (tree * pnode, tree name, tree args, int flags, | |
4043 | bool *no_add_attrs) | |
4044 | { | |
4045 | tree node = *pnode; | |
4046 | ||
4047 | /* These attributes may apply to structure and union types being created, | |
4048 | but otherwise should pass to the declaration involved. */ | |
4049 | if (!DECL_P (node)) | |
4050 | { | |
4051 | if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT | |
4052 | | (int) ATTR_FLAG_ARRAY_NEXT)) | |
4053 | { | |
4054 | *no_add_attrs = true; | |
4055 | return tree_cons (name, args, NULL_TREE); | |
4056 | } | |
098a01e7 | 4057 | if (TREE_CODE (node) == RECORD_TYPE |
4058 | || TREE_CODE (node) == UNION_TYPE) | |
4059 | { | |
4060 | node = TYPE_NAME (node); | |
4061 | if (!node) | |
4062 | return NULL_TREE; | |
4063 | } | |
4064 | else | |
3aa0c315 | 4065 | { |
9b2d6d13 | 4066 | warning (OPT_Wattributes, "%qs attribute ignored", |
4067 | IDENTIFIER_POINTER (name)); | |
3aa0c315 | 4068 | *no_add_attrs = true; |
098a01e7 | 4069 | return NULL_TREE; |
3aa0c315 | 4070 | } |
3aa0c315 | 4071 | } |
4072 | ||
27e0de67 | 4073 | if (TREE_CODE (node) != FUNCTION_DECL |
098a01e7 | 4074 | && TREE_CODE (node) != VAR_DECL |
4075 | && TREE_CODE (node) != TYPE_DECL) | |
27e0de67 | 4076 | { |
4077 | *no_add_attrs = true; | |
4078 | warning (OPT_Wattributes, "%qs attribute ignored", | |
4079 | IDENTIFIER_POINTER (name)); | |
4080 | return NULL_TREE; | |
4081 | } | |
4082 | ||
9c467f13 | 4083 | if (TREE_CODE (node) == TYPE_DECL |
4084 | && TREE_CODE (TREE_TYPE (node)) != RECORD_TYPE | |
4085 | && TREE_CODE (TREE_TYPE (node)) != UNION_TYPE) | |
4086 | { | |
4087 | *no_add_attrs = true; | |
4088 | warning (OPT_Wattributes, "%qs attribute ignored", | |
4089 | IDENTIFIER_POINTER (name)); | |
4090 | return NULL_TREE; | |
4091 | } | |
4092 | ||
3aa0c315 | 4093 | /* Report error on dllimport ambiguities seen now before they cause |
4094 | any damage. */ | |
27e0de67 | 4095 | else if (is_attribute_p ("dllimport", name)) |
3aa0c315 | 4096 | { |
7063afc3 | 4097 | /* Honor any target-specific overrides. */ |
6c1e551f | 4098 | if (!targetm.valid_dllimport_attribute_p (node)) |
4099 | *no_add_attrs = true; | |
4100 | ||
4101 | else if (TREE_CODE (node) == FUNCTION_DECL | |
4102 | && DECL_DECLARED_INLINE_P (node)) | |
4103 | { | |
4104 | warning (OPT_Wattributes, "inline function %q+D declared as " | |
4105 | " dllimport: attribute ignored", node); | |
4106 | *no_add_attrs = true; | |
4107 | } | |
3aa0c315 | 4108 | /* Like MS, treat definition of dllimported variables and |
6c1e551f | 4109 | non-inlined functions on declaration as syntax errors. */ |
4110 | else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node)) | |
3aa0c315 | 4111 | { |
3284a242 | 4112 | error ("function %q+D definition is marked dllimport", node); |
3aa0c315 | 4113 | *no_add_attrs = true; |
4114 | } | |
4115 | ||
6c1e551f | 4116 | else if (TREE_CODE (node) == VAR_DECL) |
3aa0c315 | 4117 | { |
4118 | if (DECL_INITIAL (node)) | |
4119 | { | |
3284a242 | 4120 | error ("variable %q+D definition is marked dllimport", |
3cf8b391 | 4121 | node); |
3aa0c315 | 4122 | *no_add_attrs = true; |
4123 | } | |
4124 | ||
4125 | /* `extern' needn't be specified with dllimport. | |
4126 | Specify `extern' now and hope for the best. Sigh. */ | |
4127 | DECL_EXTERNAL (node) = 1; | |
4128 | /* Also, implicitly give dllimport'd variables declared within | |
4129 | a function global scope, unless declared static. */ | |
4130 | if (current_function_decl != NULL_TREE && !TREE_STATIC (node)) | |
4131 | TREE_PUBLIC (node) = 1; | |
4132 | } | |
6c1e551f | 4133 | |
4134 | if (*no_add_attrs == false) | |
4135 | DECL_DLLIMPORT_P (node) = 1; | |
3aa0c315 | 4136 | } |
4137 | ||
4138 | /* Report error if symbol is not accessible at global scope. */ | |
4139 | if (!TREE_PUBLIC (node) | |
4140 | && (TREE_CODE (node) == VAR_DECL | |
4141 | || TREE_CODE (node) == FUNCTION_DECL)) | |
4142 | { | |
3cf8b391 | 4143 | error ("external linkage required for symbol %q+D because of " |
3284a242 | 4144 | "%qs attribute", node, IDENTIFIER_POINTER (name)); |
3aa0c315 | 4145 | *no_add_attrs = true; |
4146 | } | |
4147 | ||
098a01e7 | 4148 | /* A dllexport'd entity must have default visibility so that other |
4149 | program units (shared libraries or the main executable) can see | |
4150 | it. A dllimport'd entity must have default visibility so that | |
4151 | the linker knows that undefined references within this program | |
4152 | unit can be resolved by the dynamic linker. */ | |
4153 | if (!*no_add_attrs) | |
4154 | { | |
4155 | if (DECL_VISIBILITY_SPECIFIED (node) | |
4156 | && DECL_VISIBILITY (node) != VISIBILITY_DEFAULT) | |
4157 | error ("%qs implies default visibility, but %qD has already " | |
4158 | "been declared with a different visibility", | |
4159 | IDENTIFIER_POINTER (name), node); | |
4160 | DECL_VISIBILITY (node) = VISIBILITY_DEFAULT; | |
4161 | DECL_VISIBILITY_SPECIFIED (node) = 1; | |
4162 | } | |
4163 | ||
3aa0c315 | 4164 | return NULL_TREE; |
4165 | } | |
4166 | ||
a767736d | 4167 | #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */ |
9dd95dae | 4168 | \f |
a5b1863e | 4169 | /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask |
4170 | of the various TYPE_QUAL values. */ | |
10a9d4cf | 4171 | |
a5b1863e | 4172 | static void |
60b8c5b3 | 4173 | set_type_quals (tree type, int type_quals) |
a5b1863e | 4174 | { |
4175 | TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0; | |
4176 | TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0; | |
4177 | TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0; | |
4178 | } | |
10a9d4cf | 4179 | |
f47ba5b1 | 4180 | /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */ |
e40000f4 | 4181 | |
4182 | bool | |
720082dc | 4183 | check_qualified_type (const_tree cand, const_tree base, int type_quals) |
e40000f4 | 4184 | { |
4185 | return (TYPE_QUALS (cand) == type_quals | |
4186 | && TYPE_NAME (cand) == TYPE_NAME (base) | |
4187 | /* Apparently this is needed for Objective-C. */ | |
4188 | && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base) | |
4189 | && attribute_list_equal (TYPE_ATTRIBUTES (cand), | |
4190 | TYPE_ATTRIBUTES (base))); | |
4191 | } | |
4192 | ||
051b8c96 | 4193 | /* Return a version of the TYPE, qualified as indicated by the |
4194 | TYPE_QUALS, if one exists. If no qualified version exists yet, | |
4195 | return NULL_TREE. */ | |
10a9d4cf | 4196 | |
4197 | tree | |
60b8c5b3 | 4198 | get_qualified_type (tree type, int type_quals) |
10a9d4cf | 4199 | { |
051b8c96 | 4200 | tree t; |
9bfff6cb | 4201 | |
e40000f4 | 4202 | if (TYPE_QUALS (type) == type_quals) |
4203 | return type; | |
4204 | ||
3daca40f | 4205 | /* Search the chain of variants to see if there is already one there just |
4206 | like the one we need to have. If so, use that existing one. We must | |
4207 | preserve the TYPE_NAME, since there is code that depends on this. */ | |
13079119 | 4208 | for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) |
e40000f4 | 4209 | if (check_qualified_type (t, type, type_quals)) |
3daca40f | 4210 | return t; |
10a9d4cf | 4211 | |
051b8c96 | 4212 | return NULL_TREE; |
4213 | } | |
4214 | ||
4215 | /* Like get_qualified_type, but creates the type if it does not | |
4216 | exist. This function never returns NULL_TREE. */ | |
4217 | ||
4218 | tree | |
60b8c5b3 | 4219 | build_qualified_type (tree type, int type_quals) |
051b8c96 | 4220 | { |
4221 | tree t; | |
4222 | ||
4223 | /* See if we already have the appropriate qualified variant. */ | |
4224 | t = get_qualified_type (type, type_quals); | |
4225 | ||
4226 | /* If not, build it. */ | |
4227 | if (!t) | |
4228 | { | |
e086912e | 4229 | t = build_variant_type_copy (type); |
051b8c96 | 4230 | set_type_quals (t, type_quals); |
6753bca0 | 4231 | |
4232 | if (TYPE_STRUCTURAL_EQUALITY_P (type)) | |
4233 | /* Propagate structural equality. */ | |
4234 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
4235 | else if (TYPE_CANONICAL (type) != type) | |
4236 | /* Build the underlying canonical type, since it is different | |
4237 | from TYPE. */ | |
4238 | TYPE_CANONICAL (t) = build_qualified_type (TYPE_CANONICAL (type), | |
4239 | type_quals); | |
4240 | else | |
4241 | /* T is its own canonical type. */ | |
4242 | TYPE_CANONICAL (t) = t; | |
4243 | ||
051b8c96 | 4244 | } |
4245 | ||
10a9d4cf | 4246 | return t; |
4247 | } | |
bdf74c8a | 4248 | |
e086912e | 4249 | /* Create a new distinct copy of TYPE. The new type is made its own |
6753bca0 | 4250 | MAIN_VARIANT. If TYPE requires structural equality checks, the |
4251 | resulting type requires structural equality checks; otherwise, its | |
4252 | TYPE_CANONICAL points to itself. */ | |
bdf74c8a | 4253 | |
4254 | tree | |
e086912e | 4255 | build_distinct_type_copy (tree type) |
bdf74c8a | 4256 | { |
e086912e | 4257 | tree t = copy_node (type); |
4258 | ||
bdf74c8a | 4259 | TYPE_POINTER_TO (t) = 0; |
4260 | TYPE_REFERENCE_TO (t) = 0; | |
4261 | ||
6753bca0 | 4262 | /* Set the canonical type either to a new equivalence class, or |
4263 | propagate the need for structural equality checks. */ | |
4264 | if (TYPE_STRUCTURAL_EQUALITY_P (type)) | |
4265 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
4266 | else | |
4267 | TYPE_CANONICAL (t) = t; | |
4268 | ||
e086912e | 4269 | /* Make it its own variant. */ |
4270 | TYPE_MAIN_VARIANT (t) = t; | |
4271 | TYPE_NEXT_VARIANT (t) = 0; | |
b876a744 | 4272 | |
4273 | /* Note that it is now possible for TYPE_MIN_VALUE to be a value | |
4274 | whose TREE_TYPE is not t. This can also happen in the Ada | |
4275 | frontend when using subtypes. */ | |
d2154397 | 4276 | |
e086912e | 4277 | return t; |
4278 | } | |
4279 | ||
6753bca0 | 4280 | /* Create a new variant of TYPE, equivalent but distinct. This is so |
4281 | the caller can modify it. TYPE_CANONICAL for the return type will | |
4282 | be equivalent to TYPE_CANONICAL of TYPE, indicating that the types | |
4283 | are considered equal by the language itself (or that both types | |
4284 | require structural equality checks). */ | |
e086912e | 4285 | |
4286 | tree | |
4287 | build_variant_type_copy (tree type) | |
4288 | { | |
4289 | tree t, m = TYPE_MAIN_VARIANT (type); | |
4290 | ||
4291 | t = build_distinct_type_copy (type); | |
6753bca0 | 4292 | |
4293 | /* Since we're building a variant, assume that it is a non-semantic | |
4294 | variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */ | |
4295 | TYPE_CANONICAL (t) = TYPE_CANONICAL (type); | |
e086912e | 4296 | |
4297 | /* Add the new type to the chain of variants of TYPE. */ | |
bdf74c8a | 4298 | TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m); |
4299 | TYPE_NEXT_VARIANT (m) = t; | |
e086912e | 4300 | TYPE_MAIN_VARIANT (t) = m; |
bdf74c8a | 4301 | |
bdf74c8a | 4302 | return t; |
4303 | } | |
10a9d4cf | 4304 | \f |
8bc1e6ff | 4305 | /* Return true if the from tree in both tree maps are equal. */ |
4306 | ||
5ded8c6f | 4307 | int |
9af7fd5b | 4308 | tree_map_base_eq (const void *va, const void *vb) |
8bc1e6ff | 4309 | { |
45ba1503 | 4310 | const struct tree_map_base *const a = (const struct tree_map_base *) va, |
4311 | *const b = (const struct tree_map_base *) vb; | |
8bc1e6ff | 4312 | return (a->from == b->from); |
4313 | } | |
4314 | ||
4315 | /* Hash a from tree in a tree_map. */ | |
4316 | ||
5ded8c6f | 4317 | unsigned int |
9af7fd5b | 4318 | tree_map_base_hash (const void *item) |
8bc1e6ff | 4319 | { |
9af7fd5b | 4320 | return htab_hash_pointer (((const struct tree_map_base *)item)->from); |
8bc1e6ff | 4321 | } |
4322 | ||
4323 | /* Return true if this tree map structure is marked for garbage collection | |
4324 | purposes. We simply return true if the from tree is marked, so that this | |
4325 | structure goes away when the from tree goes away. */ | |
4326 | ||
5ded8c6f | 4327 | int |
9af7fd5b | 4328 | tree_map_base_marked_p (const void *p) |
8bc1e6ff | 4329 | { |
aae87fc3 | 4330 | return ggc_marked_p (((const struct tree_map_base *) p)->from); |
9af7fd5b | 4331 | } |
8bc1e6ff | 4332 | |
9af7fd5b | 4333 | unsigned int |
4334 | tree_map_hash (const void *item) | |
4335 | { | |
4336 | return (((const struct tree_map *) item)->hash); | |
8bc1e6ff | 4337 | } |
4338 | ||
9af7fd5b | 4339 | /* Return the initialization priority for DECL. */ |
5ded8c6f | 4340 | |
9af7fd5b | 4341 | priority_type |
4342 | decl_init_priority_lookup (tree decl) | |
5ded8c6f | 4343 | { |
9af7fd5b | 4344 | struct tree_priority_map *h; |
4345 | struct tree_map_base in; | |
4346 | ||
4347 | gcc_assert (VAR_OR_FUNCTION_DECL_P (decl)); | |
9af7fd5b | 4348 | in.from = decl; |
45ba1503 | 4349 | h = (struct tree_priority_map *) htab_find (init_priority_for_decl, &in); |
9af7fd5b | 4350 | return h ? h->init : DEFAULT_INIT_PRIORITY; |
5ded8c6f | 4351 | } |
4352 | ||
9af7fd5b | 4353 | /* Return the finalization priority for DECL. */ |
5ded8c6f | 4354 | |
9af7fd5b | 4355 | priority_type |
4356 | decl_fini_priority_lookup (tree decl) | |
5ded8c6f | 4357 | { |
9af7fd5b | 4358 | struct tree_priority_map *h; |
4359 | struct tree_map_base in; | |
4360 | ||
4361 | gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); | |
9af7fd5b | 4362 | in.from = decl; |
45ba1503 | 4363 | h = (struct tree_priority_map *) htab_find (init_priority_for_decl, &in); |
9af7fd5b | 4364 | return h ? h->fini : DEFAULT_INIT_PRIORITY; |
5ded8c6f | 4365 | } |
4366 | ||
9af7fd5b | 4367 | /* Return the initialization and finalization priority information for |
4368 | DECL. If there is no previous priority information, a freshly | |
4369 | allocated structure is returned. */ | |
5ded8c6f | 4370 | |
9af7fd5b | 4371 | static struct tree_priority_map * |
4372 | decl_priority_info (tree decl) | |
5ded8c6f | 4373 | { |
9af7fd5b | 4374 | struct tree_priority_map in; |
4375 | struct tree_priority_map *h; | |
4376 | void **loc; | |
4377 | ||
4378 | in.base.from = decl; | |
4379 | loc = htab_find_slot (init_priority_for_decl, &in, INSERT); | |
45ba1503 | 4380 | h = (struct tree_priority_map *) *loc; |
9af7fd5b | 4381 | if (!h) |
4382 | { | |
4383 | h = GGC_CNEW (struct tree_priority_map); | |
4384 | *loc = h; | |
4385 | h->base.from = decl; | |
4386 | h->init = DEFAULT_INIT_PRIORITY; | |
4387 | h->fini = DEFAULT_INIT_PRIORITY; | |
4388 | } | |
5ded8c6f | 4389 | |
9af7fd5b | 4390 | return h; |
5ded8c6f | 4391 | } |
5ded8c6f | 4392 | |
9af7fd5b | 4393 | /* Set the initialization priority for DECL to PRIORITY. */ |
4394 | ||
4395 | void | |
4396 | decl_init_priority_insert (tree decl, priority_type priority) | |
5ded8c6f | 4397 | { |
9af7fd5b | 4398 | struct tree_priority_map *h; |
5ded8c6f | 4399 | |
9af7fd5b | 4400 | gcc_assert (VAR_OR_FUNCTION_DECL_P (decl)); |
4401 | h = decl_priority_info (decl); | |
4402 | h->init = priority; | |
4403 | } | |
5ded8c6f | 4404 | |
9af7fd5b | 4405 | /* Set the finalization priority for DECL to PRIORITY. */ |
5ded8c6f | 4406 | |
4407 | void | |
9af7fd5b | 4408 | decl_fini_priority_insert (tree decl, priority_type priority) |
5ded8c6f | 4409 | { |
9af7fd5b | 4410 | struct tree_priority_map *h; |
5ded8c6f | 4411 | |
9af7fd5b | 4412 | gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); |
4413 | h = decl_priority_info (decl); | |
4414 | h->fini = priority; | |
5ded8c6f | 4415 | } |
4416 | ||
83b34c62 | 4417 | /* Look up a restrict qualified base decl for FROM. */ |
4418 | ||
4419 | tree | |
4420 | decl_restrict_base_lookup (tree from) | |
4421 | { | |
4422 | struct tree_map *h; | |
4423 | struct tree_map in; | |
4424 | ||
9af7fd5b | 4425 | in.base.from = from; |
45ba1503 | 4426 | h = (struct tree_map *) htab_find_with_hash (restrict_base_for_decl, &in, |
4427 | htab_hash_pointer (from)); | |
83b34c62 | 4428 | return h ? h->to : NULL_TREE; |
4429 | } | |
4430 | ||
4431 | /* Record the restrict qualified base TO for FROM. */ | |
4432 | ||
4433 | void | |
4434 | decl_restrict_base_insert (tree from, tree to) | |
4435 | { | |
4436 | struct tree_map *h; | |
4437 | void **loc; | |
4438 | ||
45ba1503 | 4439 | h = GGC_NEW (struct tree_map); |
83b34c62 | 4440 | h->hash = htab_hash_pointer (from); |
9af7fd5b | 4441 | h->base.from = from; |
83b34c62 | 4442 | h->to = to; |
4443 | loc = htab_find_slot_with_hash (restrict_base_for_decl, h, h->hash, INSERT); | |
4444 | *(struct tree_map **) loc = h; | |
4445 | } | |
4446 | ||
8bc1e6ff | 4447 | /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */ |
4448 | ||
4449 | static void | |
4450 | print_debug_expr_statistics (void) | |
4451 | { | |
4452 | fprintf (stderr, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n", | |
4453 | (long) htab_size (debug_expr_for_decl), | |
4454 | (long) htab_elements (debug_expr_for_decl), | |
4455 | htab_collisions (debug_expr_for_decl)); | |
4456 | } | |
4457 | ||
75fa4f82 | 4458 | /* Print out the statistics for the DECL_VALUE_EXPR hash table. */ |
4459 | ||
4460 | static void | |
4461 | print_value_expr_statistics (void) | |
4462 | { | |
4463 | fprintf (stderr, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n", | |
4464 | (long) htab_size (value_expr_for_decl), | |
4465 | (long) htab_elements (value_expr_for_decl), | |
4466 | htab_collisions (value_expr_for_decl)); | |
4467 | } | |
83b34c62 | 4468 | |
4469 | /* Print out statistics for the RESTRICT_BASE_FOR_DECL hash table, but | |
4470 | don't print anything if the table is empty. */ | |
4471 | ||
4472 | static void | |
4473 | print_restrict_base_statistics (void) | |
4474 | { | |
4475 | if (htab_elements (restrict_base_for_decl) != 0) | |
4476 | fprintf (stderr, | |
4477 | "RESTRICT_BASE hash: size %ld, %ld elements, %f collisions\n", | |
4478 | (long) htab_size (restrict_base_for_decl), | |
4479 | (long) htab_elements (restrict_base_for_decl), | |
4480 | htab_collisions (restrict_base_for_decl)); | |
4481 | } | |
4482 | ||
8bc1e6ff | 4483 | /* Lookup a debug expression for FROM, and return it if we find one. */ |
4484 | ||
4485 | tree | |
4486 | decl_debug_expr_lookup (tree from) | |
4487 | { | |
4488 | struct tree_map *h, in; | |
9af7fd5b | 4489 | in.base.from = from; |
8bc1e6ff | 4490 | |
45ba1503 | 4491 | h = (struct tree_map *) htab_find_with_hash (debug_expr_for_decl, &in, |
4492 | htab_hash_pointer (from)); | |
8bc1e6ff | 4493 | if (h) |
4494 | return h->to; | |
4495 | return NULL_TREE; | |
4496 | } | |
4497 | ||
4498 | /* Insert a mapping FROM->TO in the debug expression hashtable. */ | |
4499 | ||
4500 | void | |
4501 | decl_debug_expr_insert (tree from, tree to) | |
4502 | { | |
4503 | struct tree_map *h; | |
4504 | void **loc; | |
4505 | ||
45ba1503 | 4506 | h = GGC_NEW (struct tree_map); |
8bc1e6ff | 4507 | h->hash = htab_hash_pointer (from); |
9af7fd5b | 4508 | h->base.from = from; |
8bc1e6ff | 4509 | h->to = to; |
4510 | loc = htab_find_slot_with_hash (debug_expr_for_decl, h, h->hash, INSERT); | |
4511 | *(struct tree_map **) loc = h; | |
4512 | } | |
75fa4f82 | 4513 | |
4514 | /* Lookup a value expression for FROM, and return it if we find one. */ | |
4515 | ||
4516 | tree | |
4517 | decl_value_expr_lookup (tree from) | |
4518 | { | |
4519 | struct tree_map *h, in; | |
9af7fd5b | 4520 | in.base.from = from; |
75fa4f82 | 4521 | |
45ba1503 | 4522 | h = (struct tree_map *) htab_find_with_hash (value_expr_for_decl, &in, |
4523 | htab_hash_pointer (from)); | |
75fa4f82 | 4524 | if (h) |
4525 | return h->to; | |
4526 | return NULL_TREE; | |
4527 | } | |
4528 | ||
4529 | /* Insert a mapping FROM->TO in the value expression hashtable. */ | |
4530 | ||
4531 | void | |
4532 | decl_value_expr_insert (tree from, tree to) | |
4533 | { | |
4534 | struct tree_map *h; | |
4535 | void **loc; | |
4536 | ||
45ba1503 | 4537 | h = GGC_NEW (struct tree_map); |
75fa4f82 | 4538 | h->hash = htab_hash_pointer (from); |
9af7fd5b | 4539 | h->base.from = from; |
75fa4f82 | 4540 | h->to = to; |
4541 | loc = htab_find_slot_with_hash (value_expr_for_decl, h, h->hash, INSERT); | |
4542 | *(struct tree_map **) loc = h; | |
4543 | } | |
4544 | ||
10a9d4cf | 4545 | /* Hashing of types so that we don't make duplicates. |
4546 | The entry point is `type_hash_canon'. */ | |
4547 | ||
10a9d4cf | 4548 | /* Compute a hash code for a list of types (chain of TREE_LIST nodes |
4549 | with types in the TREE_VALUE slots), by adding the hash codes | |
4550 | of the individual types. */ | |
4551 | ||
720082dc | 4552 | static unsigned int |
4553 | type_hash_list (const_tree list, hashval_t hashcode) | |
10a9d4cf | 4554 | { |
720082dc | 4555 | const_tree tail; |
083a2b5e | 4556 | |
908e5f41 | 4557 | for (tail = list; tail; tail = TREE_CHAIN (tail)) |
4558 | if (TREE_VALUE (tail) != error_mark_node) | |
4559 | hashcode = iterative_hash_object (TYPE_HASH (TREE_VALUE (tail)), | |
4560 | hashcode); | |
083a2b5e | 4561 | |
10a9d4cf | 4562 | return hashcode; |
4563 | } | |
4564 | ||
f2d83427 | 4565 | /* These are the Hashtable callback functions. */ |
4566 | ||
82bb2115 | 4567 | /* Returns true iff the types are equivalent. */ |
f2d83427 | 4568 | |
4569 | static int | |
60b8c5b3 | 4570 | type_hash_eq (const void *va, const void *vb) |
f2d83427 | 4571 | { |
45ba1503 | 4572 | const struct type_hash *const a = (const struct type_hash *) va, |
4573 | *const b = (const struct type_hash *) vb; | |
82bb2115 | 4574 | |
4575 | /* First test the things that are the same for all types. */ | |
4576 | if (a->hash != b->hash | |
4577 | || TREE_CODE (a->type) != TREE_CODE (b->type) | |
4578 | || TREE_TYPE (a->type) != TREE_TYPE (b->type) | |
4579 | || !attribute_list_equal (TYPE_ATTRIBUTES (a->type), | |
4580 | TYPE_ATTRIBUTES (b->type)) | |
4581 | || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type) | |
54deba71 | 4582 | || TYPE_MODE (a->type) != TYPE_MODE (b->type) |
4583 | || (TREE_CODE (a->type) != COMPLEX_TYPE | |
4584 | && TYPE_NAME (a->type) != TYPE_NAME (b->type))) | |
82bb2115 | 4585 | return 0; |
4586 | ||
4587 | switch (TREE_CODE (a->type)) | |
4588 | { | |
4589 | case VOID_TYPE: | |
4590 | case COMPLEX_TYPE: | |
82bb2115 | 4591 | case POINTER_TYPE: |
4592 | case REFERENCE_TYPE: | |
4593 | return 1; | |
4594 | ||
bd971849 | 4595 | case VECTOR_TYPE: |
4596 | return TYPE_VECTOR_SUBPARTS (a->type) == TYPE_VECTOR_SUBPARTS (b->type); | |
4597 | ||
82bb2115 | 4598 | case ENUMERAL_TYPE: |
4599 | if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type) | |
4600 | && !(TYPE_VALUES (a->type) | |
4601 | && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST | |
4602 | && TYPE_VALUES (b->type) | |
4603 | && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST | |
4604 | && type_list_equal (TYPE_VALUES (a->type), | |
4605 | TYPE_VALUES (b->type)))) | |
4606 | return 0; | |
4607 | ||
4608 | /* ... fall through ... */ | |
4609 | ||
4610 | case INTEGER_TYPE: | |
4611 | case REAL_TYPE: | |
4612 | case BOOLEAN_TYPE: | |
82bb2115 | 4613 | return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type) |
4614 | || tree_int_cst_equal (TYPE_MAX_VALUE (a->type), | |
4615 | TYPE_MAX_VALUE (b->type))) | |
4616 | && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type) | |
c257ea20 | 4617 | || tree_int_cst_equal (TYPE_MIN_VALUE (a->type), |
82bb2115 | 4618 | TYPE_MIN_VALUE (b->type)))); |
4619 | ||
06f0b99c | 4620 | case FIXED_POINT_TYPE: |
4621 | return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type); | |
4622 | ||
82bb2115 | 4623 | case OFFSET_TYPE: |
4624 | return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type); | |
4625 | ||
4626 | case METHOD_TYPE: | |
4627 | return (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type) | |
4628 | && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type) | |
4629 | || (TYPE_ARG_TYPES (a->type) | |
4630 | && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST | |
4631 | && TYPE_ARG_TYPES (b->type) | |
4632 | && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST | |
4633 | && type_list_equal (TYPE_ARG_TYPES (a->type), | |
4634 | TYPE_ARG_TYPES (b->type))))); | |
b27ac6b5 | 4635 | |
82bb2115 | 4636 | case ARRAY_TYPE: |
82bb2115 | 4637 | return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type); |
4638 | ||
4639 | case RECORD_TYPE: | |
4640 | case UNION_TYPE: | |
4641 | case QUAL_UNION_TYPE: | |
4642 | return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type) | |
4643 | || (TYPE_FIELDS (a->type) | |
4644 | && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST | |
4645 | && TYPE_FIELDS (b->type) | |
4646 | && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST | |
4647 | && type_list_equal (TYPE_FIELDS (a->type), | |
4648 | TYPE_FIELDS (b->type)))); | |
4649 | ||
4650 | case FUNCTION_TYPE: | |
743f8dd1 | 4651 | if (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type) |
4652 | || (TYPE_ARG_TYPES (a->type) | |
4653 | && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST | |
4654 | && TYPE_ARG_TYPES (b->type) | |
4655 | && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST | |
4656 | && type_list_equal (TYPE_ARG_TYPES (a->type), | |
4657 | TYPE_ARG_TYPES (b->type)))) | |
4658 | break; | |
4659 | return 0; | |
82bb2115 | 4660 | |
4661 | default: | |
4662 | return 0; | |
4663 | } | |
743f8dd1 | 4664 | |
4665 | if (lang_hooks.types.type_hash_eq != NULL) | |
4666 | return lang_hooks.types.type_hash_eq (a->type, b->type); | |
4667 | ||
4668 | return 1; | |
f2d83427 | 4669 | } |
4670 | ||
4671 | /* Return the cached hash value. */ | |
4672 | ||
aa77e59f | 4673 | static hashval_t |
60b8c5b3 | 4674 | type_hash_hash (const void *item) |
f2d83427 | 4675 | { |
9bfff6cb | 4676 | return ((const struct type_hash *) item)->hash; |
f2d83427 | 4677 | } |
4678 | ||
10a9d4cf | 4679 | /* Look in the type hash table for a type isomorphic to TYPE. |
4680 | If one is found, return it. Otherwise return 0. */ | |
4681 | ||
4682 | tree | |
908e5f41 | 4683 | type_hash_lookup (hashval_t hashcode, tree type) |
10a9d4cf | 4684 | { |
f2d83427 | 4685 | struct type_hash *h, in; |
5fbce9e9 | 4686 | |
4687 | /* The TYPE_ALIGN field of a type is set by layout_type(), so we | |
9bfff6cb | 4688 | must call that routine before comparing TYPE_ALIGNs. */ |
5fbce9e9 | 4689 | layout_type (type); |
4690 | ||
f2d83427 | 4691 | in.hash = hashcode; |
4692 | in.type = type; | |
083a2b5e | 4693 | |
45ba1503 | 4694 | h = (struct type_hash *) htab_find_with_hash (type_hash_table, &in, |
4695 | hashcode); | |
f2d83427 | 4696 | if (h) |
4697 | return h->type; | |
4698 | return NULL_TREE; | |
10a9d4cf | 4699 | } |
4700 | ||
4701 | /* Add an entry to the type-hash-table | |
4702 | for a type TYPE whose hash code is HASHCODE. */ | |
4703 | ||
4704 | void | |
908e5f41 | 4705 | type_hash_add (hashval_t hashcode, tree type) |
10a9d4cf | 4706 | { |
f2d83427 | 4707 | struct type_hash *h; |
4708 | void **loc; | |
10a9d4cf | 4709 | |
45ba1503 | 4710 | h = GGC_NEW (struct type_hash); |
f2d83427 | 4711 | h->hash = hashcode; |
10a9d4cf | 4712 | h->type = type; |
1cb86e99 | 4713 | loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT); |
0b3b598f | 4714 | *loc = (void *)h; |
10a9d4cf | 4715 | } |
4716 | ||
4717 | /* Given TYPE, and HASHCODE its hash code, return the canonical | |
4718 | object for an identical type if one already exists. | |
a26d3281 | 4719 | Otherwise, return TYPE, and record it as the canonical object. |
10a9d4cf | 4720 | |
4721 | To use this function, first create a type of the sort you want. | |
4722 | Then compute its hash code from the fields of the type that | |
4723 | make it different from other similar types. | |
a26d3281 | 4724 | Then call this function and use the value. */ |
10a9d4cf | 4725 | |
4726 | tree | |
60b8c5b3 | 4727 | type_hash_canon (unsigned int hashcode, tree type) |
10a9d4cf | 4728 | { |
4729 | tree t1; | |
4730 | ||
a26d3281 | 4731 | /* The hash table only contains main variants, so ensure that's what we're |
4732 | being passed. */ | |
8c0963c4 | 4733 | gcc_assert (TYPE_MAIN_VARIANT (type) == type); |
a26d3281 | 4734 | |
4735 | if (!lang_hooks.types.hash_types) | |
10a9d4cf | 4736 | return type; |
4737 | ||
15d769aa | 4738 | /* See if the type is in the hash table already. If so, return it. |
4739 | Otherwise, add the type. */ | |
10a9d4cf | 4740 | t1 = type_hash_lookup (hashcode, type); |
4741 | if (t1 != 0) | |
4742 | { | |
10a9d4cf | 4743 | #ifdef GATHER_STATISTICS |
02e7a332 | 4744 | tree_node_counts[(int) t_kind]--; |
4745 | tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type); | |
10a9d4cf | 4746 | #endif |
4747 | return t1; | |
4748 | } | |
15d769aa | 4749 | else |
4750 | { | |
4751 | type_hash_add (hashcode, type); | |
4752 | return type; | |
4753 | } | |
10a9d4cf | 4754 | } |
4755 | ||
073fef87 | 4756 | /* See if the data pointed to by the type hash table is marked. We consider |
4757 | it marked if the type is marked or if a debug type number or symbol | |
4758 | table entry has been made for the type. This reduces the amount of | |
4759 | debugging output and eliminates that dependency of the debug output on | |
4760 | the number of garbage collections. */ | |
f2d83427 | 4761 | |
4762 | static int | |
60b8c5b3 | 4763 | type_hash_marked_p (const void *p) |
f2d83427 | 4764 | { |
aae87fc3 | 4765 | const_tree const type = ((const struct type_hash *) p)->type; |
073fef87 | 4766 | |
4767 | return ggc_marked_p (type) || TYPE_SYMTAB_POINTER (type); | |
f2d83427 | 4768 | } |
4769 | ||
f2d83427 | 4770 | static void |
60b8c5b3 | 4771 | print_type_hash_statistics (void) |
f2d83427 | 4772 | { |
02e7a332 | 4773 | fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n", |
4774 | (long) htab_size (type_hash_table), | |
4775 | (long) htab_elements (type_hash_table), | |
f2d83427 | 4776 | htab_collisions (type_hash_table)); |
a7b0c170 | 4777 | } |
4778 | ||
edee2468 | 4779 | /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes |
4780 | with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots), | |
4781 | by adding the hash codes of the individual attributes. */ | |
4599f57a | 4782 | |
720082dc | 4783 | static unsigned int |
4784 | attribute_hash_list (const_tree list, hashval_t hashcode) | |
4599f57a | 4785 | { |
720082dc | 4786 | const_tree tail; |
083a2b5e | 4787 | |
908e5f41 | 4788 | for (tail = list; tail; tail = TREE_CHAIN (tail)) |
edee2468 | 4789 | /* ??? Do we want to add in TREE_VALUE too? */ |
908e5f41 | 4790 | hashcode = iterative_hash_object |
4791 | (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail)), hashcode); | |
edee2468 | 4792 | return hashcode; |
4599f57a | 4793 | } |
4794 | ||
9dd95dae | 4795 | /* Given two lists of attributes, return true if list l2 is |
4796 | equivalent to l1. */ | |
4797 | ||
4798 | int | |
5493cb9a | 4799 | attribute_list_equal (const_tree l1, const_tree l2) |
9dd95dae | 4800 | { |
709c2f34 | 4801 | return attribute_list_contained (l1, l2) |
4802 | && attribute_list_contained (l2, l1); | |
9dd95dae | 4803 | } |
4804 | ||
edee2468 | 4805 | /* Given two lists of attributes, return true if list L2 is |
4806 | completely contained within L1. */ | |
4807 | /* ??? This would be faster if attribute names were stored in a canonicalized | |
4808 | form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method | |
4809 | must be used to show these elements are equivalent (which they are). */ | |
4810 | /* ??? It's not clear that attributes with arguments will always be handled | |
4811 | correctly. */ | |
9dd95dae | 4812 | |
4813 | int | |
5493cb9a | 4814 | attribute_list_contained (const_tree l1, const_tree l2) |
9dd95dae | 4815 | { |
5493cb9a | 4816 | const_tree t1, t2; |
9dd95dae | 4817 | |
4818 | /* First check the obvious, maybe the lists are identical. */ | |
4819 | if (l1 == l2) | |
9bfff6cb | 4820 | return 1; |
9dd95dae | 4821 | |
edee2468 | 4822 | /* Maybe the lists are similar. */ |
9dd95dae | 4823 | for (t1 = l1, t2 = l2; |
083a2b5e | 4824 | t1 != 0 && t2 != 0 |
edee2468 | 4825 | && TREE_PURPOSE (t1) == TREE_PURPOSE (t2) |
9dd95dae | 4826 | && TREE_VALUE (t1) == TREE_VALUE (t2); |
4827 | t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2)); | |
4828 | ||
4829 | /* Maybe the lists are equal. */ | |
4830 | if (t1 == 0 && t2 == 0) | |
ac0c7fb1 | 4831 | return 1; |
9dd95dae | 4832 | |
083a2b5e | 4833 | for (; t2 != 0; t2 = TREE_CHAIN (t2)) |
edee2468 | 4834 | { |
5493cb9a | 4835 | const_tree attr; |
ce4469fa | 4836 | /* This CONST_CAST is okay because lookup_attribute does not |
4837 | modify its argument and the return value is assigned to a | |
4838 | const_tree. */ | |
4839 | for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), | |
e47a6f81 | 4840 | CONST_CAST_TREE(l1)); |
e3c541f0 | 4841 | attr != NULL_TREE; |
ce4469fa | 4842 | attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), |
4843 | TREE_CHAIN (attr))) | |
e3c541f0 | 4844 | { |
9369a09f | 4845 | if (TREE_VALUE (t2) != NULL |
4846 | && TREE_CODE (TREE_VALUE (t2)) == TREE_LIST | |
4847 | && TREE_VALUE (attr) != NULL | |
4848 | && TREE_CODE (TREE_VALUE (attr)) == TREE_LIST) | |
4849 | { | |
4850 | if (simple_cst_list_equal (TREE_VALUE (t2), | |
4851 | TREE_VALUE (attr)) == 1) | |
4852 | break; | |
4853 | } | |
4854 | else if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) == 1) | |
e3c541f0 | 4855 | break; |
4856 | } | |
edee2468 | 4857 | |
083a2b5e | 4858 | if (attr == 0) |
9dd95dae | 4859 | return 0; |
edee2468 | 4860 | } |
4599f57a | 4861 | |
9dd95dae | 4862 | return 1; |
4863 | } | |
4864 | ||
10a9d4cf | 4865 | /* Given two lists of types |
4866 | (chains of TREE_LIST nodes with types in the TREE_VALUE slots) | |
4867 | return 1 if the lists contain the same types in the same order. | |
4868 | Also, the TREE_PURPOSEs must match. */ | |
4869 | ||
4870 | int | |
b7bf20db | 4871 | type_list_equal (const_tree l1, const_tree l2) |
10a9d4cf | 4872 | { |
b7bf20db | 4873 | const_tree t1, t2; |
3208534e | 4874 | |
10a9d4cf | 4875 | for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2)) |
3208534e | 4876 | if (TREE_VALUE (t1) != TREE_VALUE (t2) |
4877 | || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2) | |
bc274e3b | 4878 | && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)) |
4879 | && (TREE_TYPE (TREE_PURPOSE (t1)) | |
4880 | == TREE_TYPE (TREE_PURPOSE (t2)))))) | |
3208534e | 4881 | return 0; |
10a9d4cf | 4882 | |
4883 | return t1 == t2; | |
4884 | } | |
4885 | ||
e4c782a1 | 4886 | /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE |
4887 | given by TYPE. If the argument list accepts variable arguments, | |
4888 | then this function counts only the ordinary arguments. */ | |
4889 | ||
4890 | int | |
720082dc | 4891 | type_num_arguments (const_tree type) |
e4c782a1 | 4892 | { |
4893 | int i = 0; | |
4894 | tree t; | |
4895 | ||
4896 | for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t)) | |
4897 | /* If the function does not take a variable number of arguments, | |
4898 | the last element in the list will have type `void'. */ | |
4899 | if (VOID_TYPE_P (TREE_VALUE (t))) | |
4900 | break; | |
4901 | else | |
4902 | ++i; | |
4903 | ||
4904 | return i; | |
4905 | } | |
4906 | ||
10a9d4cf | 4907 | /* Nonzero if integer constants T1 and T2 |
4908 | represent the same constant value. */ | |
4909 | ||
4910 | int | |
720082dc | 4911 | tree_int_cst_equal (const_tree t1, const_tree t2) |
10a9d4cf | 4912 | { |
4913 | if (t1 == t2) | |
4914 | return 1; | |
083a2b5e | 4915 | |
10a9d4cf | 4916 | if (t1 == 0 || t2 == 0) |
4917 | return 0; | |
083a2b5e | 4918 | |
10a9d4cf | 4919 | if (TREE_CODE (t1) == INTEGER_CST |
4920 | && TREE_CODE (t2) == INTEGER_CST | |
4921 | && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2) | |
4922 | && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2)) | |
4923 | return 1; | |
083a2b5e | 4924 | |
10a9d4cf | 4925 | return 0; |
4926 | } | |
4927 | ||
4928 | /* Nonzero if integer constants T1 and T2 represent values that satisfy <. | |
4929 | The precise way of comparison depends on their data type. */ | |
4930 | ||
4931 | int | |
720082dc | 4932 | tree_int_cst_lt (const_tree t1, const_tree t2) |
10a9d4cf | 4933 | { |
4934 | if (t1 == t2) | |
4935 | return 0; | |
4936 | ||
78a8ed03 | 4937 | if (TYPE_UNSIGNED (TREE_TYPE (t1)) != TYPE_UNSIGNED (TREE_TYPE (t2))) |
1453bbde | 4938 | { |
4939 | int t1_sgn = tree_int_cst_sgn (t1); | |
4940 | int t2_sgn = tree_int_cst_sgn (t2); | |
4941 | ||
4942 | if (t1_sgn < t2_sgn) | |
4943 | return 1; | |
4944 | else if (t1_sgn > t2_sgn) | |
4945 | return 0; | |
4946 | /* Otherwise, both are non-negative, so we compare them as | |
4947 | unsigned just in case one of them would overflow a signed | |
4948 | type. */ | |
4949 | } | |
78a8ed03 | 4950 | else if (!TYPE_UNSIGNED (TREE_TYPE (t1))) |
10a9d4cf | 4951 | return INT_CST_LT (t1, t2); |
083a2b5e | 4952 | |
10a9d4cf | 4953 | return INT_CST_LT_UNSIGNED (t1, t2); |
4954 | } | |
4955 | ||
225ec6aa | 4956 | /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */ |
4957 | ||
4958 | int | |
720082dc | 4959 | tree_int_cst_compare (const_tree t1, const_tree t2) |
225ec6aa | 4960 | { |
4961 | if (tree_int_cst_lt (t1, t2)) | |
4962 | return -1; | |
4963 | else if (tree_int_cst_lt (t2, t1)) | |
4964 | return 1; | |
709c2f34 | 4965 | else |
225ec6aa | 4966 | return 0; |
4967 | } | |
4968 | ||
c53485bb | 4969 | /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on |
4970 | the host. If POS is zero, the value can be represented in a single | |
4168cdc3 | 4971 | HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can |
c53485bb | 4972 | be represented in a single unsigned HOST_WIDE_INT. */ |
5d844ba2 | 4973 | |
4974 | int | |
720082dc | 4975 | host_integerp (const_tree t, int pos) |
5d844ba2 | 4976 | { |
4977 | return (TREE_CODE (t) == INTEGER_CST | |
5d844ba2 | 4978 | && ((TREE_INT_CST_HIGH (t) == 0 |
4979 | && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0) | |
4980 | || (! pos && TREE_INT_CST_HIGH (t) == -1 | |
c53485bb | 4981 | && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0 |
be1f1b71 | 4982 | && (!TYPE_UNSIGNED (TREE_TYPE (t)) |
b2ee3594 | 4983 | || (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE |
4984 | && TYPE_IS_SIZETYPE (TREE_TYPE (t))))) | |
c53485bb | 4985 | || (pos && TREE_INT_CST_HIGH (t) == 0))); |
5d844ba2 | 4986 | } |
4987 | ||
4988 | /* Return the HOST_WIDE_INT least significant bits of T if it is an | |
4989 | INTEGER_CST and there is no overflow. POS is nonzero if the result must | |
4168cdc3 | 4990 | be non-negative. We must be able to satisfy the above conditions. */ |
5d844ba2 | 4991 | |
4992 | HOST_WIDE_INT | |
720082dc | 4993 | tree_low_cst (const_tree t, int pos) |
5d844ba2 | 4994 | { |
8c0963c4 | 4995 | gcc_assert (host_integerp (t, pos)); |
4996 | return TREE_INT_CST_LOW (t); | |
9bfff6cb | 4997 | } |
5d844ba2 | 4998 | |
ddb425f3 | 4999 | /* Return the most significant bit of the integer constant T. */ |
5000 | ||
5001 | int | |
720082dc | 5002 | tree_int_cst_msb (const_tree t) |
ddb425f3 | 5003 | { |
5004 | int prec; | |
5005 | HOST_WIDE_INT h; | |
5006 | unsigned HOST_WIDE_INT l; | |
5007 | ||
5008 | /* Note that using TYPE_PRECISION here is wrong. We care about the | |
5009 | actual bits, not the (arbitrary) range of the type. */ | |
5010 | prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1; | |
5011 | rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec, | |
5012 | 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0); | |
5013 | return (l & 1) == 1; | |
5014 | } | |
5015 | ||
58171fc5 | 5016 | /* Return an indication of the sign of the integer constant T. |
5017 | The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0. | |
21a67a88 | 5018 | Note that -1 will never be returned if T's type is unsigned. */ |
58171fc5 | 5019 | |
5020 | int | |
720082dc | 5021 | tree_int_cst_sgn (const_tree t) |
58171fc5 | 5022 | { |
5023 | if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0) | |
5024 | return 0; | |
78a8ed03 | 5025 | else if (TYPE_UNSIGNED (TREE_TYPE (t))) |
58171fc5 | 5026 | return 1; |
5027 | else if (TREE_INT_CST_HIGH (t) < 0) | |
5028 | return -1; | |
5029 | else | |
5030 | return 1; | |
5031 | } | |
5032 | ||
5485b959 | 5033 | /* Return the minimum number of bits needed to represent VALUE in a |
5034 | signed or unsigned type, UNSIGNEDP says which. */ | |
5035 | ||
5036 | unsigned int | |
5037 | tree_int_cst_min_precision (tree value, bool unsignedp) | |
5038 | { | |
5039 | int log; | |
5040 | ||
5041 | /* If the value is negative, compute its negative minus 1. The latter | |
5042 | adjustment is because the absolute value of the largest negative value | |
5043 | is one larger than the largest positive value. This is equivalent to | |
5044 | a bit-wise negation, so use that operation instead. */ | |
5045 | ||
5046 | if (tree_int_cst_sgn (value) < 0) | |
5047 | value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value); | |
5048 | ||
5049 | /* Return the number of bits needed, taking into account the fact | |
5050 | that we need one more bit for a signed than unsigned type. */ | |
5051 | ||
5052 | if (integer_zerop (value)) | |
5053 | log = 0; | |
5054 | else | |
5055 | log = tree_floor_log2 (value); | |
5056 | ||
5057 | return log + 1 + !unsignedp; | |
5058 | } | |
5059 | ||
3208534e | 5060 | /* Compare two constructor-element-type constants. Return 1 if the lists |
5061 | are known to be equal; otherwise return 0. */ | |
5062 | ||
10a9d4cf | 5063 | int |
720082dc | 5064 | simple_cst_list_equal (const_tree l1, const_tree l2) |
10a9d4cf | 5065 | { |
5066 | while (l1 != NULL_TREE && l2 != NULL_TREE) | |
5067 | { | |
3208534e | 5068 | if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1) |
10a9d4cf | 5069 | return 0; |
3208534e | 5070 | |
10a9d4cf | 5071 | l1 = TREE_CHAIN (l1); |
5072 | l2 = TREE_CHAIN (l2); | |
5073 | } | |
3208534e | 5074 | |
083a2b5e | 5075 | return l1 == l2; |
10a9d4cf | 5076 | } |
5077 | ||
5078 | /* Return truthvalue of whether T1 is the same tree structure as T2. | |
5079 | Return 1 if they are the same. | |
5080 | Return 0 if they are understandably different. | |
5081 | Return -1 if either contains tree structure not understood by | |
5082 | this function. */ | |
5083 | ||
5084 | int | |
b7bf20db | 5085 | simple_cst_equal (const_tree t1, const_tree t2) |
10a9d4cf | 5086 | { |
19cb6b50 | 5087 | enum tree_code code1, code2; |
10a9d4cf | 5088 | int cmp; |
083a2b5e | 5089 | int i; |
10a9d4cf | 5090 | |
5091 | if (t1 == t2) | |
5092 | return 1; | |
5093 | if (t1 == 0 || t2 == 0) | |
5094 | return 0; | |
5095 | ||
5096 | code1 = TREE_CODE (t1); | |
5097 | code2 = TREE_CODE (t2); | |
5098 | ||
d9659041 | 5099 | if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR) |
22e12a56 | 5100 | { |
d9659041 | 5101 | if (CONVERT_EXPR_CODE_P (code2) |
22e12a56 | 5102 | || code2 == NON_LVALUE_EXPR) |
5103 | return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
5104 | else | |
5105 | return simple_cst_equal (TREE_OPERAND (t1, 0), t2); | |
5106 | } | |
083a2b5e | 5107 | |
d9659041 | 5108 | else if (CONVERT_EXPR_CODE_P (code2) |
10a9d4cf | 5109 | || code2 == NON_LVALUE_EXPR) |
5110 | return simple_cst_equal (t1, TREE_OPERAND (t2, 0)); | |
5111 | ||
5112 | if (code1 != code2) | |
5113 | return 0; | |
5114 | ||
5115 | switch (code1) | |
5116 | { | |
5117 | case INTEGER_CST: | |
083a2b5e | 5118 | return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2) |
5119 | && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2)); | |
10a9d4cf | 5120 | |
5121 | case REAL_CST: | |
62aa7862 | 5122 | return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2)); |
10a9d4cf | 5123 | |
06f0b99c | 5124 | case FIXED_CST: |
5125 | return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2)); | |
5126 | ||
10a9d4cf | 5127 | case STRING_CST: |
083a2b5e | 5128 | return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2) |
d5130039 | 5129 | && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2), |
083a2b5e | 5130 | TREE_STRING_LENGTH (t1))); |
10a9d4cf | 5131 | |
5132 | case CONSTRUCTOR: | |
c75b4594 | 5133 | { |
5134 | unsigned HOST_WIDE_INT idx; | |
5135 | VEC(constructor_elt, gc) *v1 = CONSTRUCTOR_ELTS (t1); | |
5136 | VEC(constructor_elt, gc) *v2 = CONSTRUCTOR_ELTS (t2); | |
5137 | ||
5138 | if (VEC_length (constructor_elt, v1) != VEC_length (constructor_elt, v2)) | |
5139 | return false; | |
5140 | ||
5141 | for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx) | |
5142 | /* ??? Should we handle also fields here? */ | |
5143 | if (!simple_cst_equal (VEC_index (constructor_elt, v1, idx)->value, | |
5144 | VEC_index (constructor_elt, v2, idx)->value)) | |
5145 | return false; | |
5146 | return true; | |
5147 | } | |
10a9d4cf | 5148 | |
5149 | case SAVE_EXPR: | |
5150 | return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
5151 | ||
5152 | case CALL_EXPR: | |
c2f47e15 | 5153 | cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)); |
10a9d4cf | 5154 | if (cmp <= 0) |
5155 | return cmp; | |
c2f47e15 | 5156 | if (call_expr_nargs (t1) != call_expr_nargs (t2)) |
5157 | return 0; | |
5158 | { | |
b7bf20db | 5159 | const_tree arg1, arg2; |
5160 | const_call_expr_arg_iterator iter1, iter2; | |
5161 | for (arg1 = first_const_call_expr_arg (t1, &iter1), | |
5162 | arg2 = first_const_call_expr_arg (t2, &iter2); | |
c2f47e15 | 5163 | arg1 && arg2; |
b7bf20db | 5164 | arg1 = next_const_call_expr_arg (&iter1), |
5165 | arg2 = next_const_call_expr_arg (&iter2)) | |
c2f47e15 | 5166 | { |
5167 | cmp = simple_cst_equal (arg1, arg2); | |
5168 | if (cmp <= 0) | |
5169 | return cmp; | |
5170 | } | |
5171 | return arg1 == arg2; | |
5172 | } | |
10a9d4cf | 5173 | |
5174 | case TARGET_EXPR: | |
5175 | /* Special case: if either target is an unallocated VAR_DECL, | |
5176 | it means that it's going to be unified with whatever the | |
5177 | TARGET_EXPR is really supposed to initialize, so treat it | |
5178 | as being equivalent to anything. */ | |
5179 | if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL | |
5180 | && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE | |
0e8e37b2 | 5181 | && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0))) |
10a9d4cf | 5182 | || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL |
5183 | && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE | |
0e8e37b2 | 5184 | && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0)))) |
10a9d4cf | 5185 | cmp = 1; |
5186 | else | |
5187 | cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
083a2b5e | 5188 | |
10a9d4cf | 5189 | if (cmp <= 0) |
5190 | return cmp; | |
083a2b5e | 5191 | |
10a9d4cf | 5192 | return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); |
5193 | ||
5194 | case WITH_CLEANUP_EXPR: | |
5195 | cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
5196 | if (cmp <= 0) | |
5197 | return cmp; | |
083a2b5e | 5198 | |
5929001a | 5199 | return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1)); |
10a9d4cf | 5200 | |
5201 | case COMPONENT_REF: | |
5202 | if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1)) | |
5203 | return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
083a2b5e | 5204 | |
10a9d4cf | 5205 | return 0; |
5206 | ||
10a9d4cf | 5207 | case VAR_DECL: |
5208 | case PARM_DECL: | |
5209 | case CONST_DECL: | |
5210 | case FUNCTION_DECL: | |
5211 | return 0; | |
9bfff6cb | 5212 | |
0dbd1c74 | 5213 | default: |
5214 | break; | |
f768c418 | 5215 | } |
10a9d4cf | 5216 | |
d2d16a50 | 5217 | /* This general rule works for most tree codes. All exceptions should be |
5218 | handled above. If this is a language-specific tree code, we can't | |
5219 | trust what might be in the operand, so say we don't know | |
5220 | the situation. */ | |
b4dae43c | 5221 | if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE) |
d2d16a50 | 5222 | return -1; |
10a9d4cf | 5223 | |
f768c418 | 5224 | switch (TREE_CODE_CLASS (code1)) |
5225 | { | |
ce45a448 | 5226 | case tcc_unary: |
5227 | case tcc_binary: | |
5228 | case tcc_comparison: | |
5229 | case tcc_expression: | |
5230 | case tcc_reference: | |
5231 | case tcc_statement: | |
f768c418 | 5232 | cmp = 1; |
f3c6d29a | 5233 | for (i = 0; i < TREE_CODE_LENGTH (code1); i++) |
f768c418 | 5234 | { |
5235 | cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)); | |
5236 | if (cmp <= 0) | |
5237 | return cmp; | |
5238 | } | |
083a2b5e | 5239 | |
f768c418 | 5240 | return cmp; |
f768c418 | 5241 | |
0dbd1c74 | 5242 | default: |
5243 | return -1; | |
5244 | } | |
10a9d4cf | 5245 | } |
a0c2c45b | 5246 | |
5247 | /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value. | |
5248 | Return -1, 0, or 1 if the value of T is less than, equal to, or greater | |
5249 | than U, respectively. */ | |
5250 | ||
5251 | int | |
720082dc | 5252 | compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u) |
a0c2c45b | 5253 | { |
5254 | if (tree_int_cst_sgn (t) < 0) | |
5255 | return -1; | |
5256 | else if (TREE_INT_CST_HIGH (t) != 0) | |
5257 | return 1; | |
5258 | else if (TREE_INT_CST_LOW (t) == u) | |
5259 | return 0; | |
5260 | else if (TREE_INT_CST_LOW (t) < u) | |
5261 | return -1; | |
5262 | else | |
5263 | return 1; | |
5264 | } | |
10f6a269 | 5265 | |
21dff555 | 5266 | /* Return true if CODE represents an associative tree code. Otherwise |
5267 | return false. */ | |
5268 | bool | |
5269 | associative_tree_code (enum tree_code code) | |
5270 | { | |
5271 | switch (code) | |
5272 | { | |
5273 | case BIT_IOR_EXPR: | |
5274 | case BIT_AND_EXPR: | |
5275 | case BIT_XOR_EXPR: | |
5276 | case PLUS_EXPR: | |
21dff555 | 5277 | case MULT_EXPR: |
21dff555 | 5278 | case MIN_EXPR: |
5279 | case MAX_EXPR: | |
5280 | return true; | |
5281 | ||
5282 | default: | |
5283 | break; | |
5284 | } | |
5285 | return false; | |
5286 | } | |
5287 | ||
86481e89 | 5288 | /* Return true if CODE represents a commutative tree code. Otherwise |
21dff555 | 5289 | return false. */ |
5290 | bool | |
5291 | commutative_tree_code (enum tree_code code) | |
5292 | { | |
5293 | switch (code) | |
5294 | { | |
5295 | case PLUS_EXPR: | |
5296 | case MULT_EXPR: | |
5297 | case MIN_EXPR: | |
5298 | case MAX_EXPR: | |
5299 | case BIT_IOR_EXPR: | |
5300 | case BIT_XOR_EXPR: | |
5301 | case BIT_AND_EXPR: | |
5302 | case NE_EXPR: | |
5303 | case EQ_EXPR: | |
bd975dc2 | 5304 | case UNORDERED_EXPR: |
5305 | case ORDERED_EXPR: | |
5306 | case UNEQ_EXPR: | |
5307 | case LTGT_EXPR: | |
5308 | case TRUTH_AND_EXPR: | |
5309 | case TRUTH_XOR_EXPR: | |
5310 | case TRUTH_OR_EXPR: | |
21dff555 | 5311 | return true; |
5312 | ||
5313 | default: | |
5314 | break; | |
5315 | } | |
5316 | return false; | |
5317 | } | |
5318 | ||
10f6a269 | 5319 | /* Generate a hash value for an expression. This can be used iteratively |
75a70cf9 | 5320 | by passing a previous result as the VAL argument. |
10f6a269 | 5321 | |
5322 | This function is intended to produce the same hash for expressions which | |
5323 | would compare equal using operand_equal_p. */ | |
5324 | ||
5325 | hashval_t | |
720082dc | 5326 | iterative_hash_expr (const_tree t, hashval_t val) |
10f6a269 | 5327 | { |
5328 | int i; | |
5329 | enum tree_code code; | |
f4e36c33 | 5330 | char tclass; |
10f6a269 | 5331 | |
5332 | if (t == NULL_TREE) | |
c068056a | 5333 | return iterative_hash_pointer (t, val); |
10f6a269 | 5334 | |
5335 | code = TREE_CODE (t); | |
10f6a269 | 5336 | |
c068056a | 5337 | switch (code) |
10f6a269 | 5338 | { |
c068056a | 5339 | /* Alas, constants aren't shared, so we can't rely on pointer |
5340 | identity. */ | |
5341 | case INTEGER_CST: | |
5342 | val = iterative_hash_host_wide_int (TREE_INT_CST_LOW (t), val); | |
5343 | return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t), val); | |
5344 | case REAL_CST: | |
5345 | { | |
5346 | unsigned int val2 = real_hash (TREE_REAL_CST_PTR (t)); | |
29f35f64 | 5347 | |
06f0b99c | 5348 | return iterative_hash_hashval_t (val2, val); |
5349 | } | |
5350 | case FIXED_CST: | |
5351 | { | |
5352 | unsigned int val2 = fixed_hash (TREE_FIXED_CST_PTR (t)); | |
5353 | ||
c068056a | 5354 | return iterative_hash_hashval_t (val2, val); |
5355 | } | |
5356 | case STRING_CST: | |
5357 | return iterative_hash (TREE_STRING_POINTER (t), | |
5358 | TREE_STRING_LENGTH (t), val); | |
5359 | case COMPLEX_CST: | |
5360 | val = iterative_hash_expr (TREE_REALPART (t), val); | |
5361 | return iterative_hash_expr (TREE_IMAGPART (t), val); | |
5362 | case VECTOR_CST: | |
5363 | return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val); | |
5364 | ||
5365 | case SSA_NAME: | |
c068056a | 5366 | /* we can just compare by pointer. */ |
5367 | return iterative_hash_pointer (t, val); | |
5368 | ||
5369 | case TREE_LIST: | |
5370 | /* A list of expressions, for a CALL_EXPR or as the elements of a | |
5371 | VECTOR_CST. */ | |
5372 | for (; t; t = TREE_CHAIN (t)) | |
5373 | val = iterative_hash_expr (TREE_VALUE (t), val); | |
5374 | return val; | |
c75b4594 | 5375 | case CONSTRUCTOR: |
5376 | { | |
5377 | unsigned HOST_WIDE_INT idx; | |
5378 | tree field, value; | |
5379 | FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), idx, field, value) | |
5380 | { | |
5381 | val = iterative_hash_expr (field, val); | |
5382 | val = iterative_hash_expr (value, val); | |
5383 | } | |
5384 | return val; | |
5385 | } | |
0090be28 | 5386 | case FUNCTION_DECL: |
5387 | /* When referring to a built-in FUNCTION_DECL, use the | |
5388 | __builtin__ form. Otherwise nodes that compare equal | |
5389 | according to operand_equal_p might get different | |
5390 | hash codes. */ | |
5391 | if (DECL_BUILT_IN (t)) | |
5392 | { | |
5393 | val = iterative_hash_pointer (built_in_decls[DECL_FUNCTION_CODE (t)], | |
5394 | val); | |
5395 | return val; | |
5396 | } | |
5397 | /* else FALL THROUGH */ | |
c068056a | 5398 | default: |
f4e36c33 | 5399 | tclass = TREE_CODE_CLASS (code); |
10f6a269 | 5400 | |
f4e36c33 | 5401 | if (tclass == tcc_declaration) |
4ee9c684 | 5402 | { |
45337e7e | 5403 | /* DECL's have a unique ID */ |
5404 | val = iterative_hash_host_wide_int (DECL_UID (t), val); | |
4ee9c684 | 5405 | } |
9cee7c3f | 5406 | else |
851a56dc | 5407 | { |
f4e36c33 | 5408 | gcc_assert (IS_EXPR_CODE_CLASS (tclass)); |
9cee7c3f | 5409 | |
c068056a | 5410 | val = iterative_hash_object (code, val); |
5411 | ||
5412 | /* Don't hash the type, that can lead to having nodes which | |
5413 | compare equal according to operand_equal_p, but which | |
5414 | have different hash codes. */ | |
d9659041 | 5415 | if (CONVERT_EXPR_CODE_P (code) |
c068056a | 5416 | || code == NON_LVALUE_EXPR) |
5417 | { | |
5418 | /* Make sure to include signness in the hash computation. */ | |
5419 | val += TYPE_UNSIGNED (TREE_TYPE (t)); | |
5420 | val = iterative_hash_expr (TREE_OPERAND (t, 0), val); | |
5421 | } | |
5422 | ||
5423 | else if (commutative_tree_code (code)) | |
5424 | { | |
5425 | /* It's a commutative expression. We want to hash it the same | |
5426 | however it appears. We do this by first hashing both operands | |
5427 | and then rehashing based on the order of their independent | |
5428 | hashes. */ | |
5429 | hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0); | |
5430 | hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0); | |
5431 | hashval_t t; | |
5432 | ||
5433 | if (one > two) | |
5434 | t = one, one = two, two = t; | |
5435 | ||
5436 | val = iterative_hash_hashval_t (one, val); | |
5437 | val = iterative_hash_hashval_t (two, val); | |
5438 | } | |
5439 | else | |
c2f47e15 | 5440 | for (i = TREE_OPERAND_LENGTH (t) - 1; i >= 0; --i) |
c068056a | 5441 | val = iterative_hash_expr (TREE_OPERAND (t, i), val); |
851a56dc | 5442 | } |
c068056a | 5443 | return val; |
5444 | break; | |
4ee9c684 | 5445 | } |
10f6a269 | 5446 | } |
75a70cf9 | 5447 | |
5448 | /* Generate a hash value for a pair of expressions. This can be used | |
5449 | iteratively by passing a previous result as the VAL argument. | |
5450 | ||
5451 | The same hash value is always returned for a given pair of expressions, | |
5452 | regardless of the order in which they are presented. This is useful in | |
5453 | hashing the operands of commutative functions. */ | |
5454 | ||
5455 | hashval_t | |
5456 | iterative_hash_exprs_commutative (const_tree t1, | |
5457 | const_tree t2, hashval_t val) | |
5458 | { | |
5459 | hashval_t one = iterative_hash_expr (t1, 0); | |
5460 | hashval_t two = iterative_hash_expr (t2, 0); | |
5461 | hashval_t t; | |
5462 | ||
5463 | if (one > two) | |
5464 | t = one, one = two, two = t; | |
5465 | val = iterative_hash_hashval_t (one, val); | |
5466 | val = iterative_hash_hashval_t (two, val); | |
5467 | ||
5468 | return val; | |
5469 | } | |
10a9d4cf | 5470 | \f |
5471 | /* Constructors for pointer, array and function types. | |
5472 | (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are | |
5473 | constructed by language-dependent code, not here.) */ | |
5474 | ||
b24423db | 5475 | /* Construct, lay out and return the type of pointers to TO_TYPE with |
5476 | mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can | |
5477 | reference all of memory. If such a type has already been | |
5478 | constructed, reuse it. */ | |
10a9d4cf | 5479 | |
5480 | tree | |
b24423db | 5481 | build_pointer_type_for_mode (tree to_type, enum machine_mode mode, |
5482 | bool can_alias_all) | |
10a9d4cf | 5483 | { |
b24423db | 5484 | tree t; |
5485 | ||
9a33af6f | 5486 | if (to_type == error_mark_node) |
5487 | return error_mark_node; | |
5488 | ||
f06537f2 | 5489 | /* If the pointed-to type has the may_alias attribute set, force |
5490 | a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */ | |
5491 | if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type))) | |
5492 | can_alias_all = true; | |
5493 | ||
b24423db | 5494 | /* In some cases, languages will have things that aren't a POINTER_TYPE |
5495 | (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO. | |
5496 | In that case, return that type without regard to the rest of our | |
5497 | operands. | |
5498 | ||
5499 | ??? This is a kludge, but consistent with the way this function has | |
5500 | always operated and there doesn't seem to be a good way to avoid this | |
5501 | at the moment. */ | |
5502 | if (TYPE_POINTER_TO (to_type) != 0 | |
5503 | && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE) | |
5504 | return TYPE_POINTER_TO (to_type); | |
10a9d4cf | 5505 | |
0237aca8 | 5506 | /* First, if we already have a type for pointers to TO_TYPE and it's |
5507 | the proper mode, use it. */ | |
b24423db | 5508 | for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t)) |
0237aca8 | 5509 | if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all) |
b24423db | 5510 | return t; |
10a9d4cf | 5511 | |
10a9d4cf | 5512 | t = make_node (POINTER_TYPE); |
0b56cc51 | 5513 | |
10a9d4cf | 5514 | TREE_TYPE (t) = to_type; |
342ad2d6 | 5515 | SET_TYPE_MODE (t, mode); |
b24423db | 5516 | TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all; |
5517 | TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type); | |
5518 | TYPE_POINTER_TO (to_type) = t; | |
10a9d4cf | 5519 | |
6753bca0 | 5520 | if (TYPE_STRUCTURAL_EQUALITY_P (to_type)) |
5521 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
5522 | else if (TYPE_CANONICAL (to_type) != to_type) | |
5523 | TYPE_CANONICAL (t) | |
5524 | = build_pointer_type_for_mode (TYPE_CANONICAL (to_type), | |
5525 | mode, can_alias_all); | |
5526 | ||
10a9d4cf | 5527 | /* Lay out the type. This function has many callers that are concerned |
5b4621d9 | 5528 | with expression-construction, and this simplifies them all. */ |
10a9d4cf | 5529 | layout_type (t); |
5530 | ||
10a9d4cf | 5531 | return t; |
5532 | } | |
5533 | ||
805e22b2 | 5534 | /* By default build pointers in ptr_mode. */ |
083a2b5e | 5535 | |
5536 | tree | |
60b8c5b3 | 5537 | build_pointer_type (tree to_type) |
805e22b2 | 5538 | { |
b24423db | 5539 | return build_pointer_type_for_mode (to_type, ptr_mode, false); |
805e22b2 | 5540 | } |
5541 | ||
b24423db | 5542 | /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */ |
805e22b2 | 5543 | |
5544 | tree | |
b24423db | 5545 | build_reference_type_for_mode (tree to_type, enum machine_mode mode, |
5546 | bool can_alias_all) | |
083a2b5e | 5547 | { |
b24423db | 5548 | tree t; |
083a2b5e | 5549 | |
f06537f2 | 5550 | if (to_type == error_mark_node) |
5551 | return error_mark_node; | |
5552 | ||
5553 | /* If the pointed-to type has the may_alias attribute set, force | |
5554 | a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */ | |
5555 | if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type))) | |
5556 | can_alias_all = true; | |
5557 | ||
b24423db | 5558 | /* In some cases, languages will have things that aren't a REFERENCE_TYPE |
5559 | (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO. | |
5560 | In that case, return that type without regard to the rest of our | |
5561 | operands. | |
5562 | ||
5563 | ??? This is a kludge, but consistent with the way this function has | |
5564 | always operated and there doesn't seem to be a good way to avoid this | |
5565 | at the moment. */ | |
5566 | if (TYPE_REFERENCE_TO (to_type) != 0 | |
5567 | && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE) | |
5568 | return TYPE_REFERENCE_TO (to_type); | |
5569 | ||
0237aca8 | 5570 | /* First, if we already have a type for pointers to TO_TYPE and it's |
5571 | the proper mode, use it. */ | |
b24423db | 5572 | for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t)) |
0237aca8 | 5573 | if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all) |
b24423db | 5574 | return t; |
083a2b5e | 5575 | |
083a2b5e | 5576 | t = make_node (REFERENCE_TYPE); |
083a2b5e | 5577 | |
5578 | TREE_TYPE (t) = to_type; | |
342ad2d6 | 5579 | SET_TYPE_MODE (t, mode); |
b24423db | 5580 | TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all; |
5581 | TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type); | |
083a2b5e | 5582 | TYPE_REFERENCE_TO (to_type) = t; |
5583 | ||
6753bca0 | 5584 | if (TYPE_STRUCTURAL_EQUALITY_P (to_type)) |
5585 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
5586 | else if (TYPE_CANONICAL (to_type) != to_type) | |
5587 | TYPE_CANONICAL (t) | |
5588 | = build_reference_type_for_mode (TYPE_CANONICAL (to_type), | |
5589 | mode, can_alias_all); | |
5590 | ||
083a2b5e | 5591 | layout_type (t); |
5592 | ||
5593 | return t; | |
5594 | } | |
5595 | ||
805e22b2 | 5596 | |
5597 | /* Build the node for the type of references-to-TO_TYPE by default | |
5598 | in ptr_mode. */ | |
5599 | ||
5600 | tree | |
60b8c5b3 | 5601 | build_reference_type (tree to_type) |
805e22b2 | 5602 | { |
b24423db | 5603 | return build_reference_type_for_mode (to_type, ptr_mode, false); |
805e22b2 | 5604 | } |
5605 | ||
211f3116 | 5606 | /* Build a type that is compatible with t but has no cv quals anywhere |
5607 | in its type, thus | |
5608 | ||
5609 | const char *const *const * -> char ***. */ | |
5610 | ||
5611 | tree | |
60b8c5b3 | 5612 | build_type_no_quals (tree t) |
211f3116 | 5613 | { |
5614 | switch (TREE_CODE (t)) | |
5615 | { | |
5616 | case POINTER_TYPE: | |
a26d3281 | 5617 | return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t)), |
b24423db | 5618 | TYPE_MODE (t), |
5619 | TYPE_REF_CAN_ALIAS_ALL (t)); | |
211f3116 | 5620 | case REFERENCE_TYPE: |
a26d3281 | 5621 | return |
5622 | build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t)), | |
b24423db | 5623 | TYPE_MODE (t), |
5624 | TYPE_REF_CAN_ALIAS_ALL (t)); | |
211f3116 | 5625 | default: |
5626 | return TYPE_MAIN_VARIANT (t); | |
5627 | } | |
5628 | } | |
5629 | ||
10a9d4cf | 5630 | /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE. |
5631 | MAXVAL should be the maximum value in the domain | |
0dbd1c74 | 5632 | (one less than the length of the array). |
5633 | ||
5634 | The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT. | |
5635 | We don't enforce this limit, that is up to caller (e.g. language front end). | |
5636 | The limit exists because the result is a signed type and we don't handle | |
5637 | sizes that use more than one HOST_WIDE_INT. */ | |
10a9d4cf | 5638 | |
5639 | tree | |
60b8c5b3 | 5640 | build_index_type (tree maxval) |
10a9d4cf | 5641 | { |
19cb6b50 | 5642 | tree itype = make_node (INTEGER_TYPE); |
25b73a2d | 5643 | |
02e7a332 | 5644 | TREE_TYPE (itype) = sizetype; |
10a9d4cf | 5645 | TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype); |
c832e677 | 5646 | TYPE_MIN_VALUE (itype) = size_zero_node; |
5d7ed6c7 | 5647 | TYPE_MAX_VALUE (itype) = fold_convert (sizetype, maxval); |
342ad2d6 | 5648 | SET_TYPE_MODE (itype, TYPE_MODE (sizetype)); |
10a9d4cf | 5649 | TYPE_SIZE (itype) = TYPE_SIZE (sizetype); |
24a7e611 | 5650 | TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype); |
10a9d4cf | 5651 | TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype); |
aca14577 | 5652 | TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype); |
a0c2c45b | 5653 | |
c832e677 | 5654 | if (host_integerp (maxval, 1)) |
02e7a332 | 5655 | return type_hash_canon (tree_low_cst (maxval, 1), itype); |
10a9d4cf | 5656 | else |
6753bca0 | 5657 | { |
5658 | /* Since we cannot hash this type, we need to compare it using | |
5659 | structural equality checks. */ | |
5660 | SET_TYPE_STRUCTURAL_EQUALITY (itype); | |
5661 | return itype; | |
5662 | } | |
10a9d4cf | 5663 | } |
5664 | ||
4f7f7efd | 5665 | /* Builds a signed or unsigned integer type of precision PRECISION. |
5666 | Used for C bitfields whose precision does not match that of | |
5667 | built-in target types. */ | |
5668 | tree | |
5669 | build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision, | |
5670 | int unsignedp) | |
5671 | { | |
5672 | tree itype = make_node (INTEGER_TYPE); | |
5673 | ||
5674 | TYPE_PRECISION (itype) = precision; | |
5675 | ||
5676 | if (unsignedp) | |
5677 | fixup_unsigned_type (itype); | |
5678 | else | |
5679 | fixup_signed_type (itype); | |
5680 | ||
5681 | if (host_integerp (TYPE_MAX_VALUE (itype), 1)) | |
5682 | return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype); | |
5683 | ||
5684 | return itype; | |
5685 | } | |
5686 | ||
0b4f7046 | 5687 | /* Create a range of some discrete type TYPE (an INTEGER_TYPE, |
63bf54cf | 5688 | ENUMERAL_TYPE or BOOLEAN_TYPE), with low bound LOWVAL and |
5689 | high bound HIGHVAL. If TYPE is NULL, sizetype is used. */ | |
10a9d4cf | 5690 | |
5691 | tree | |
60b8c5b3 | 5692 | build_range_type (tree type, tree lowval, tree highval) |
10a9d4cf | 5693 | { |
19cb6b50 | 5694 | tree itype = make_node (INTEGER_TYPE); |
25b73a2d | 5695 | |
0b4f7046 | 5696 | TREE_TYPE (itype) = type; |
5697 | if (type == NULL_TREE) | |
5698 | type = sizetype; | |
25b73a2d | 5699 | |
e3b560a6 | 5700 | TYPE_MIN_VALUE (itype) = fold_convert (type, lowval); |
5701 | TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL; | |
25b73a2d | 5702 | |
5703 | TYPE_PRECISION (itype) = TYPE_PRECISION (type); | |
342ad2d6 | 5704 | SET_TYPE_MODE (itype, TYPE_MODE (type)); |
0b4f7046 | 5705 | TYPE_SIZE (itype) = TYPE_SIZE (type); |
b0bd3f2b | 5706 | TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type); |
0b4f7046 | 5707 | TYPE_ALIGN (itype) = TYPE_ALIGN (type); |
aca14577 | 5708 | TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type); |
f52483b5 | 5709 | |
02e7a332 | 5710 | if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0)) |
5711 | return type_hash_canon (tree_low_cst (highval, 0) | |
5712 | - tree_low_cst (lowval, 0), | |
5713 | itype); | |
10a9d4cf | 5714 | else |
5715 | return itype; | |
5716 | } | |
5717 | ||
0b4f7046 | 5718 | /* Just like build_index_type, but takes lowval and highval instead |
a92771b8 | 5719 | of just highval (maxval). */ |
0b4f7046 | 5720 | |
5721 | tree | |
60b8c5b3 | 5722 | build_index_2_type (tree lowval, tree highval) |
0b4f7046 | 5723 | { |
02e7a332 | 5724 | return build_range_type (sizetype, lowval, highval); |
0b4f7046 | 5725 | } |
5726 | ||
10a9d4cf | 5727 | /* Construct, lay out and return the type of arrays of elements with ELT_TYPE |
5728 | and number of elements specified by the range of values of INDEX_TYPE. | |
5729 | If such a type has already been constructed, reuse it. */ | |
5730 | ||
5731 | tree | |
60b8c5b3 | 5732 | build_array_type (tree elt_type, tree index_type) |
10a9d4cf | 5733 | { |
19cb6b50 | 5734 | tree t; |
908e5f41 | 5735 | hashval_t hashcode = 0; |
10a9d4cf | 5736 | |
5737 | if (TREE_CODE (elt_type) == FUNCTION_TYPE) | |
5738 | { | |
5739 | error ("arrays of functions are not meaningful"); | |
5740 | elt_type = integer_type_node; | |
5741 | } | |
5742 | ||
10a9d4cf | 5743 | t = make_node (ARRAY_TYPE); |
5744 | TREE_TYPE (t) = elt_type; | |
5745 | TYPE_DOMAIN (t) = index_type; | |
4b592242 | 5746 | |
10a9d4cf | 5747 | if (index_type == 0) |
4b592242 | 5748 | { |
ce675af0 | 5749 | tree save = t; |
5750 | hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode); | |
5751 | t = type_hash_canon (hashcode, t); | |
5752 | if (save == t) | |
5753 | layout_type (t); | |
6753bca0 | 5754 | |
5755 | if (TYPE_CANONICAL (t) == t) | |
5756 | { | |
5757 | if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)) | |
5758 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
5759 | else if (TYPE_CANONICAL (elt_type) != elt_type) | |
5760 | TYPE_CANONICAL (t) | |
5761 | = build_array_type (TYPE_CANONICAL (elt_type), index_type); | |
5762 | } | |
5763 | ||
4b592242 | 5764 | return t; |
5765 | } | |
10a9d4cf | 5766 | |
908e5f41 | 5767 | hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode); |
5768 | hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode); | |
10a9d4cf | 5769 | t = type_hash_canon (hashcode, t); |
5770 | ||
cd604e7f | 5771 | if (!COMPLETE_TYPE_P (t)) |
10a9d4cf | 5772 | layout_type (t); |
6753bca0 | 5773 | |
5774 | if (TYPE_CANONICAL (t) == t) | |
5775 | { | |
5776 | if (TYPE_STRUCTURAL_EQUALITY_P (elt_type) | |
5777 | || TYPE_STRUCTURAL_EQUALITY_P (index_type)) | |
5778 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
5779 | else if (TYPE_CANONICAL (elt_type) != elt_type | |
5780 | || TYPE_CANONICAL (index_type) != index_type) | |
5781 | TYPE_CANONICAL (t) | |
5782 | = build_array_type (TYPE_CANONICAL (elt_type), | |
5783 | TYPE_CANONICAL (index_type)); | |
5784 | } | |
5785 | ||
10a9d4cf | 5786 | return t; |
5787 | } | |
5788 | ||
eec9c06d | 5789 | /* Recursively examines the array elements of TYPE, until a non-array |
5790 | element type is found. */ | |
8cda90b9 | 5791 | |
5792 | tree | |
eec9c06d | 5793 | strip_array_types (tree type) |
8cda90b9 | 5794 | { |
8cda90b9 | 5795 | while (TREE_CODE (type) == ARRAY_TYPE) |
5796 | type = TREE_TYPE (type); | |
5797 | ||
5798 | return type; | |
5799 | } | |
5800 | ||
3084bb6f | 5801 | /* Computes the canonical argument types from the argument type list |
5802 | ARGTYPES. | |
5803 | ||
9cdfb835 | 5804 | Upon return, *ANY_STRUCTURAL_P will be true iff either it was true |
5805 | on entry to this function, or if any of the ARGTYPES are | |
3084bb6f | 5806 | structural. |
5807 | ||
9cdfb835 | 5808 | Upon return, *ANY_NONCANONICAL_P will be true iff either it was |
5809 | true on entry to this function, or if any of the ARGTYPES are | |
5810 | non-canonical. | |
3084bb6f | 5811 | |
5812 | Returns a canonical argument list, which may be ARGTYPES when the | |
5813 | canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is | |
5814 | true) or would not differ from ARGTYPES. */ | |
5815 | ||
5816 | static tree | |
5817 | maybe_canonicalize_argtypes(tree argtypes, | |
5818 | bool *any_structural_p, | |
5819 | bool *any_noncanonical_p) | |
5820 | { | |
5821 | tree arg; | |
5822 | bool any_noncanonical_argtypes_p = false; | |
5823 | ||
5824 | for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg)) | |
5825 | { | |
5826 | if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node) | |
5827 | /* Fail gracefully by stating that the type is structural. */ | |
5828 | *any_structural_p = true; | |
5829 | else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg))) | |
5830 | *any_structural_p = true; | |
5831 | else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg) | |
5832 | || TREE_PURPOSE (arg)) | |
5833 | /* If the argument has a default argument, we consider it | |
5834 | non-canonical even though the type itself is canonical. | |
5835 | That way, different variants of function and method types | |
5836 | with default arguments will all point to the variant with | |
5837 | no defaults as their canonical type. */ | |
5838 | any_noncanonical_argtypes_p = true; | |
5839 | } | |
5840 | ||
5841 | if (*any_structural_p) | |
5842 | return argtypes; | |
5843 | ||
5844 | if (any_noncanonical_argtypes_p) | |
5845 | { | |
5846 | /* Build the canonical list of argument types. */ | |
5847 | tree canon_argtypes = NULL_TREE; | |
5848 | bool is_void = false; | |
5849 | ||
5850 | for (arg = argtypes; arg; arg = TREE_CHAIN (arg)) | |
5851 | { | |
5852 | if (arg == void_list_node) | |
5853 | is_void = true; | |
5854 | else | |
5855 | canon_argtypes = tree_cons (NULL_TREE, | |
5856 | TYPE_CANONICAL (TREE_VALUE (arg)), | |
5857 | canon_argtypes); | |
5858 | } | |
5859 | ||
5860 | canon_argtypes = nreverse (canon_argtypes); | |
5861 | if (is_void) | |
5862 | canon_argtypes = chainon (canon_argtypes, void_list_node); | |
5863 | ||
5864 | /* There is a non-canonical type. */ | |
5865 | *any_noncanonical_p = true; | |
5866 | return canon_argtypes; | |
5867 | } | |
5868 | ||
5869 | /* The canonical argument types are the same as ARGTYPES. */ | |
5870 | return argtypes; | |
5871 | } | |
5872 | ||
10a9d4cf | 5873 | /* Construct, lay out and return |
5874 | the type of functions returning type VALUE_TYPE | |
5875 | given arguments of types ARG_TYPES. | |
5876 | ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs | |
5877 | are data type nodes for the arguments of the function. | |
5878 | If such a type has already been constructed, reuse it. */ | |
5879 | ||
5880 | tree | |
60b8c5b3 | 5881 | build_function_type (tree value_type, tree arg_types) |
10a9d4cf | 5882 | { |
19cb6b50 | 5883 | tree t; |
908e5f41 | 5884 | hashval_t hashcode = 0; |
3084bb6f | 5885 | bool any_structural_p, any_noncanonical_p; |
5886 | tree canon_argtypes; | |
10a9d4cf | 5887 | |
5dbb3364 | 5888 | if (TREE_CODE (value_type) == FUNCTION_TYPE) |
10a9d4cf | 5889 | { |
5dbb3364 | 5890 | error ("function return type cannot be function"); |
10a9d4cf | 5891 | value_type = integer_type_node; |
5892 | } | |
5893 | ||
5894 | /* Make a node of the sort we want. */ | |
5895 | t = make_node (FUNCTION_TYPE); | |
5896 | TREE_TYPE (t) = value_type; | |
5897 | TYPE_ARG_TYPES (t) = arg_types; | |
5898 | ||
a26d3281 | 5899 | /* If we already have such a type, use the old one. */ |
908e5f41 | 5900 | hashcode = iterative_hash_object (TYPE_HASH (value_type), hashcode); |
5901 | hashcode = type_hash_list (arg_types, hashcode); | |
10a9d4cf | 5902 | t = type_hash_canon (hashcode, t); |
5903 | ||
3084bb6f | 5904 | /* Set up the canonical type. */ |
5905 | any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type); | |
5906 | any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type; | |
5907 | canon_argtypes = maybe_canonicalize_argtypes (arg_types, | |
5908 | &any_structural_p, | |
5909 | &any_noncanonical_p); | |
5910 | if (any_structural_p) | |
5911 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
5912 | else if (any_noncanonical_p) | |
5913 | TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type), | |
5914 | canon_argtypes); | |
5915 | ||
4b72716d | 5916 | if (!COMPLETE_TYPE_P (t)) |
10a9d4cf | 5917 | layout_type (t); |
5918 | return t; | |
5919 | } | |
5920 | ||
5afe38fe | 5921 | /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP. */ |
5922 | ||
5923 | tree | |
5924 | build_function_type_skip_args (tree orig_type, bitmap args_to_skip) | |
5925 | { | |
5926 | tree new_type = NULL; | |
5927 | tree args, new_args = NULL, t; | |
5928 | tree new_reversed; | |
5929 | int i = 0; | |
5930 | ||
5931 | for (args = TYPE_ARG_TYPES (orig_type); args && args != void_list_node; | |
5932 | args = TREE_CHAIN (args), i++) | |
5933 | if (!bitmap_bit_p (args_to_skip, i)) | |
5934 | new_args = tree_cons (NULL_TREE, TREE_VALUE (args), new_args); | |
5935 | ||
5936 | new_reversed = nreverse (new_args); | |
5937 | if (args) | |
5938 | { | |
5939 | if (new_reversed) | |
5940 | TREE_CHAIN (new_args) = void_list_node; | |
5941 | else | |
5942 | new_reversed = void_list_node; | |
5943 | } | |
5944 | gcc_assert (new_reversed); | |
5945 | ||
5946 | /* Use copy_node to preserve as much as possible from original type | |
5947 | (debug info, attribute lists etc.) | |
5948 | Exception is METHOD_TYPEs must have THIS argument. | |
5949 | When we are asked to remove it, we need to build new FUNCTION_TYPE | |
5950 | instead. */ | |
5951 | if (TREE_CODE (orig_type) != METHOD_TYPE | |
5952 | || !bitmap_bit_p (args_to_skip, 0)) | |
5953 | { | |
5954 | new_type = copy_node (orig_type); | |
5955 | TYPE_ARG_TYPES (new_type) = new_reversed; | |
5956 | } | |
5957 | else | |
48a01d2a | 5958 | { |
5959 | new_type | |
5960 | = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type), | |
5961 | new_reversed)); | |
5962 | TYPE_CONTEXT (new_type) = TYPE_CONTEXT (orig_type); | |
5963 | } | |
5afe38fe | 5964 | |
5965 | /* This is a new type, not a copy of an old type. Need to reassociate | |
5966 | variants. We can handle everything except the main variant lazily. */ | |
5967 | t = TYPE_MAIN_VARIANT (orig_type); | |
5968 | if (orig_type != t) | |
5969 | { | |
5970 | TYPE_MAIN_VARIANT (new_type) = t; | |
5971 | TYPE_NEXT_VARIANT (new_type) = TYPE_NEXT_VARIANT (t); | |
5972 | TYPE_NEXT_VARIANT (t) = new_type; | |
5973 | } | |
5974 | else | |
5975 | { | |
5976 | TYPE_MAIN_VARIANT (new_type) = new_type; | |
5977 | TYPE_NEXT_VARIANT (new_type) = NULL; | |
5978 | } | |
5979 | return new_type; | |
5980 | } | |
5981 | ||
5982 | /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP. | |
5983 | ||
5984 | Arguments from DECL_ARGUMENTS list can't be removed now, since they are | |
5985 | linked by TREE_CHAIN directly. It is caller responsibility to eliminate | |
5986 | them when they are being duplicated (i.e. copy_arguments_for_versioning). */ | |
5987 | ||
5988 | tree | |
5989 | build_function_decl_skip_args (tree orig_decl, bitmap args_to_skip) | |
5990 | { | |
5991 | tree new_decl = copy_node (orig_decl); | |
5992 | tree new_type; | |
5993 | ||
5994 | new_type = TREE_TYPE (orig_decl); | |
5995 | if (prototype_p (new_type)) | |
5996 | new_type = build_function_type_skip_args (new_type, args_to_skip); | |
48a01d2a | 5997 | TREE_TYPE (new_decl) = new_type; |
5998 | ||
5999 | /* For declarations setting DECL_VINDEX (i.e. methods) | |
6000 | we expect first argument to be THIS pointer. */ | |
6001 | if (bitmap_bit_p (args_to_skip, 0)) | |
6002 | DECL_VINDEX (new_decl) = NULL_TREE; | |
5afe38fe | 6003 | return new_decl; |
6004 | } | |
6005 | ||
91c82c20 | 6006 | /* Build a function type. The RETURN_TYPE is the type returned by the |
1c73f824 | 6007 | function. If VAARGS is set, no void_type_node is appended to the |
6008 | the list. ARGP muse be alway be terminated be a NULL_TREE. */ | |
8b55c4ba | 6009 | |
1c73f824 | 6010 | static tree |
6011 | build_function_type_list_1 (bool vaargs, tree return_type, va_list argp) | |
8b55c4ba | 6012 | { |
6013 | tree t, args, last; | |
8b55c4ba | 6014 | |
1c73f824 | 6015 | t = va_arg (argp, tree); |
6016 | for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree)) | |
8b55c4ba | 6017 | args = tree_cons (NULL_TREE, t, args); |
6018 | ||
1c73f824 | 6019 | if (vaargs) |
6020 | { | |
5afe38fe | 6021 | last = args; |
6022 | if (args != NULL_TREE) | |
6023 | args = nreverse (args); | |
1c73f824 | 6024 | gcc_assert (args != NULL_TREE && last != void_list_node); |
6025 | } | |
6026 | else if (args == NULL_TREE) | |
baf63f24 | 6027 | args = void_list_node; |
6028 | else | |
6029 | { | |
6030 | last = args; | |
6031 | args = nreverse (args); | |
6032 | TREE_CHAIN (last) = void_list_node; | |
6033 | } | |
9cc64f48 | 6034 | args = build_function_type (return_type, args); |
8b55c4ba | 6035 | |
1c73f824 | 6036 | return args; |
6037 | } | |
6038 | ||
6039 | /* Build a function type. The RETURN_TYPE is the type returned by the | |
6040 | function. If additional arguments are provided, they are | |
6041 | additional argument types. The list of argument types must always | |
6042 | be terminated by NULL_TREE. */ | |
6043 | ||
6044 | tree | |
6045 | build_function_type_list (tree return_type, ...) | |
6046 | { | |
6047 | tree args; | |
6048 | va_list p; | |
6049 | ||
6050 | va_start (p, return_type); | |
6051 | args = build_function_type_list_1 (false, return_type, p); | |
6052 | va_end (p); | |
6053 | return args; | |
6054 | } | |
6055 | ||
6056 | /* Build a variable argument function type. The RETURN_TYPE is the | |
6057 | type returned by the function. If additional arguments are provided, | |
6058 | they are additional argument types. The list of argument types must | |
6059 | always be terminated by NULL_TREE. */ | |
6060 | ||
6061 | tree | |
6062 | build_varargs_function_type_list (tree return_type, ...) | |
6063 | { | |
6064 | tree args; | |
6065 | va_list p; | |
6066 | ||
6067 | va_start (p, return_type); | |
6068 | args = build_function_type_list_1 (true, return_type, p); | |
ee582a61 | 6069 | va_end (p); |
1c73f824 | 6070 | |
8b55c4ba | 6071 | return args; |
6072 | } | |
6073 | ||
8b8f063f | 6074 | /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE) |
6075 | and ARGTYPES (a TREE_LIST) are the return type and arguments types | |
6076 | for the method. An implicit additional parameter (of type | |
6077 | pointer-to-BASETYPE) is added to the ARGTYPES. */ | |
10a9d4cf | 6078 | |
6079 | tree | |
8b8f063f | 6080 | build_method_type_directly (tree basetype, |
6081 | tree rettype, | |
6082 | tree argtypes) | |
10a9d4cf | 6083 | { |
19cb6b50 | 6084 | tree t; |
8b8f063f | 6085 | tree ptype; |
908e5f41 | 6086 | int hashcode = 0; |
3084bb6f | 6087 | bool any_structural_p, any_noncanonical_p; |
6088 | tree canon_argtypes; | |
10a9d4cf | 6089 | |
6090 | /* Make a node of the sort we want. */ | |
6091 | t = make_node (METHOD_TYPE); | |
6092 | ||
10a9d4cf | 6093 | TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype); |
8b8f063f | 6094 | TREE_TYPE (t) = rettype; |
6095 | ptype = build_pointer_type (basetype); | |
10a9d4cf | 6096 | |
6097 | /* The actual arglist for this function includes a "hidden" argument | |
6098 | which is "this". Put it into the list of argument types. */ | |
8b8f063f | 6099 | argtypes = tree_cons (NULL_TREE, ptype, argtypes); |
6100 | TYPE_ARG_TYPES (t) = argtypes; | |
10a9d4cf | 6101 | |
a26d3281 | 6102 | /* If we already have such a type, use the old one. */ |
908e5f41 | 6103 | hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode); |
6104 | hashcode = iterative_hash_object (TYPE_HASH (rettype), hashcode); | |
6105 | hashcode = type_hash_list (argtypes, hashcode); | |
10a9d4cf | 6106 | t = type_hash_canon (hashcode, t); |
6107 | ||
3084bb6f | 6108 | /* Set up the canonical type. */ |
6109 | any_structural_p | |
6110 | = (TYPE_STRUCTURAL_EQUALITY_P (basetype) | |
6111 | || TYPE_STRUCTURAL_EQUALITY_P (rettype)); | |
6112 | any_noncanonical_p | |
6113 | = (TYPE_CANONICAL (basetype) != basetype | |
6114 | || TYPE_CANONICAL (rettype) != rettype); | |
6115 | canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes), | |
6116 | &any_structural_p, | |
6117 | &any_noncanonical_p); | |
6118 | if (any_structural_p) | |
6119 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
6120 | else if (any_noncanonical_p) | |
6121 | TYPE_CANONICAL (t) | |
6122 | = build_method_type_directly (TYPE_CANONICAL (basetype), | |
6123 | TYPE_CANONICAL (rettype), | |
6124 | canon_argtypes); | |
4b72716d | 6125 | if (!COMPLETE_TYPE_P (t)) |
10a9d4cf | 6126 | layout_type (t); |
6127 | ||
6128 | return t; | |
6129 | } | |
6130 | ||
8b8f063f | 6131 | /* Construct, lay out and return the type of methods belonging to class |
6132 | BASETYPE and whose arguments and values are described by TYPE. | |
6133 | If that type exists already, reuse it. | |
6134 | TYPE must be a FUNCTION_TYPE node. */ | |
6135 | ||
6136 | tree | |
6137 | build_method_type (tree basetype, tree type) | |
6138 | { | |
8c0963c4 | 6139 | gcc_assert (TREE_CODE (type) == FUNCTION_TYPE); |
8b8f063f | 6140 | |
b27ac6b5 | 6141 | return build_method_type_directly (basetype, |
8b8f063f | 6142 | TREE_TYPE (type), |
6143 | TYPE_ARG_TYPES (type)); | |
6144 | } | |
6145 | ||
f768c418 | 6146 | /* Construct, lay out and return the type of offsets to a value |
6147 | of type TYPE, within an object of type BASETYPE. | |
6148 | If a suitable offset type exists already, reuse it. */ | |
10a9d4cf | 6149 | |
6150 | tree | |
60b8c5b3 | 6151 | build_offset_type (tree basetype, tree type) |
10a9d4cf | 6152 | { |
19cb6b50 | 6153 | tree t; |
908e5f41 | 6154 | hashval_t hashcode = 0; |
10a9d4cf | 6155 | |
6156 | /* Make a node of the sort we want. */ | |
6157 | t = make_node (OFFSET_TYPE); | |
6158 | ||
6159 | TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype); | |
6160 | TREE_TYPE (t) = type; | |
6161 | ||
a26d3281 | 6162 | /* If we already have such a type, use the old one. */ |
908e5f41 | 6163 | hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode); |
6164 | hashcode = iterative_hash_object (TYPE_HASH (type), hashcode); | |
10a9d4cf | 6165 | t = type_hash_canon (hashcode, t); |
6166 | ||
4b72716d | 6167 | if (!COMPLETE_TYPE_P (t)) |
10a9d4cf | 6168 | layout_type (t); |
6169 | ||
6753bca0 | 6170 | if (TYPE_CANONICAL (t) == t) |
6171 | { | |
6172 | if (TYPE_STRUCTURAL_EQUALITY_P (basetype) | |
6173 | || TYPE_STRUCTURAL_EQUALITY_P (type)) | |
6174 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
7f0d3ba1 | 6175 | else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype |
6753bca0 | 6176 | || TYPE_CANONICAL (type) != type) |
6177 | TYPE_CANONICAL (t) | |
7f0d3ba1 | 6178 | = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)), |
6753bca0 | 6179 | TYPE_CANONICAL (type)); |
6180 | } | |
6181 | ||
10a9d4cf | 6182 | return t; |
6183 | } | |
6184 | ||
6185 | /* Create a complex type whose components are COMPONENT_TYPE. */ | |
6186 | ||
6187 | tree | |
60b8c5b3 | 6188 | build_complex_type (tree component_type) |
10a9d4cf | 6189 | { |
19cb6b50 | 6190 | tree t; |
908e5f41 | 6191 | hashval_t hashcode; |
10a9d4cf | 6192 | |
b7860e64 | 6193 | gcc_assert (INTEGRAL_TYPE_P (component_type) |
6194 | || SCALAR_FLOAT_TYPE_P (component_type) | |
6195 | || FIXED_POINT_TYPE_P (component_type)); | |
6196 | ||
10a9d4cf | 6197 | /* Make a node of the sort we want. */ |
6198 | t = make_node (COMPLEX_TYPE); | |
6199 | ||
6200 | TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type); | |
10a9d4cf | 6201 | |
a26d3281 | 6202 | /* If we already have such a type, use the old one. */ |
908e5f41 | 6203 | hashcode = iterative_hash_object (TYPE_HASH (component_type), 0); |
10a9d4cf | 6204 | t = type_hash_canon (hashcode, t); |
6205 | ||
4b72716d | 6206 | if (!COMPLETE_TYPE_P (t)) |
10a9d4cf | 6207 | layout_type (t); |
6208 | ||
6753bca0 | 6209 | if (TYPE_CANONICAL (t) == t) |
6210 | { | |
6211 | if (TYPE_STRUCTURAL_EQUALITY_P (component_type)) | |
6212 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
6213 | else if (TYPE_CANONICAL (component_type) != component_type) | |
6214 | TYPE_CANONICAL (t) | |
6215 | = build_complex_type (TYPE_CANONICAL (component_type)); | |
6216 | } | |
6217 | ||
c133ba93 | 6218 | /* We need to create a name, since complex is a fundamental type. */ |
6219 | if (! TYPE_NAME (t)) | |
5b5abf88 | 6220 | { |
20f0a040 | 6221 | const char *name; |
5b5abf88 | 6222 | if (component_type == char_type_node) |
6223 | name = "complex char"; | |
6224 | else if (component_type == signed_char_type_node) | |
6225 | name = "complex signed char"; | |
6226 | else if (component_type == unsigned_char_type_node) | |
6227 | name = "complex unsigned char"; | |
6228 | else if (component_type == short_integer_type_node) | |
6229 | name = "complex short int"; | |
6230 | else if (component_type == short_unsigned_type_node) | |
6231 | name = "complex short unsigned int"; | |
6232 | else if (component_type == integer_type_node) | |
6233 | name = "complex int"; | |
6234 | else if (component_type == unsigned_type_node) | |
6235 | name = "complex unsigned int"; | |
6236 | else if (component_type == long_integer_type_node) | |
6237 | name = "complex long int"; | |
6238 | else if (component_type == long_unsigned_type_node) | |
6239 | name = "complex long unsigned int"; | |
6240 | else if (component_type == long_long_integer_type_node) | |
6241 | name = "complex long long int"; | |
6242 | else if (component_type == long_long_unsigned_type_node) | |
6243 | name = "complex long long unsigned int"; | |
6244 | else | |
083a2b5e | 6245 | name = 0; |
5b5abf88 | 6246 | |
083a2b5e | 6247 | if (name != 0) |
a024c245 | 6248 | TYPE_NAME (t) = build_decl (TYPE_DECL, get_identifier (name), t); |
5b5abf88 | 6249 | } |
6250 | ||
a26d3281 | 6251 | return build_qualified_type (t, TYPE_QUALS (component_type)); |
10a9d4cf | 6252 | } |
c6418a4e | 6253 | |
6254 | /* If TYPE is a real or complex floating-point type and the target | |
6255 | does not directly support arithmetic on TYPE then return the wider | |
6256 | type to be used for arithmetic on TYPE. Otherwise, return | |
6257 | NULL_TREE. */ | |
6258 | ||
6259 | tree | |
6260 | excess_precision_type (tree type) | |
6261 | { | |
6262 | if (flag_excess_precision != EXCESS_PRECISION_FAST) | |
6263 | { | |
6264 | int flt_eval_method = TARGET_FLT_EVAL_METHOD; | |
6265 | switch (TREE_CODE (type)) | |
6266 | { | |
6267 | case REAL_TYPE: | |
6268 | switch (flt_eval_method) | |
6269 | { | |
6270 | case 1: | |
6271 | if (TYPE_MODE (type) == TYPE_MODE (float_type_node)) | |
6272 | return double_type_node; | |
6273 | break; | |
6274 | case 2: | |
6275 | if (TYPE_MODE (type) == TYPE_MODE (float_type_node) | |
6276 | || TYPE_MODE (type) == TYPE_MODE (double_type_node)) | |
6277 | return long_double_type_node; | |
6278 | break; | |
6279 | default: | |
6280 | gcc_unreachable (); | |
6281 | } | |
6282 | break; | |
6283 | case COMPLEX_TYPE: | |
6284 | if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE) | |
6285 | return NULL_TREE; | |
6286 | switch (flt_eval_method) | |
6287 | { | |
6288 | case 1: | |
6289 | if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node)) | |
6290 | return complex_double_type_node; | |
6291 | break; | |
6292 | case 2: | |
6293 | if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node) | |
6294 | || (TYPE_MODE (TREE_TYPE (type)) | |
6295 | == TYPE_MODE (double_type_node))) | |
6296 | return complex_long_double_type_node; | |
6297 | break; | |
6298 | default: | |
6299 | gcc_unreachable (); | |
6300 | } | |
6301 | break; | |
6302 | default: | |
6303 | break; | |
6304 | } | |
6305 | } | |
6306 | return NULL_TREE; | |
6307 | } | |
10a9d4cf | 6308 | \f |
6309 | /* Return OP, stripped of any conversions to wider types as much as is safe. | |
6310 | Converting the value back to OP's type makes a value equivalent to OP. | |
6311 | ||
6312 | If FOR_TYPE is nonzero, we return a value which, if converted to | |
6313 | type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE. | |
6314 | ||
10a9d4cf | 6315 | OP must have integer, real or enumeral type. Pointers are not allowed! |
6316 | ||
6317 | There are some cases where the obvious value we could return | |
9bfff6cb | 6318 | would regenerate to OP if converted to OP's type, |
10a9d4cf | 6319 | but would not extend like OP to wider types. |
6320 | If FOR_TYPE indicates such extension is contemplated, we eschew such values. | |
6321 | For example, if OP is (unsigned short)(signed char)-1, | |
6322 | we avoid returning (signed char)-1 if FOR_TYPE is int, | |
6323 | even though extending that to an unsigned short would regenerate OP, | |
6324 | since the result of extending (signed char)-1 to (int) | |
6325 | is different from (int) OP. */ | |
6326 | ||
6327 | tree | |
60b8c5b3 | 6328 | get_unwidened (tree op, tree for_type) |
10a9d4cf | 6329 | { |
6330 | /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */ | |
19cb6b50 | 6331 | tree type = TREE_TYPE (op); |
6332 | unsigned final_prec | |
10a9d4cf | 6333 | = TYPE_PRECISION (for_type != 0 ? for_type : type); |
19cb6b50 | 6334 | int uns |
10a9d4cf | 6335 | = (for_type != 0 && for_type != type |
6336 | && final_prec > TYPE_PRECISION (type) | |
78a8ed03 | 6337 | && TYPE_UNSIGNED (type)); |
19cb6b50 | 6338 | tree win = op; |
10a9d4cf | 6339 | |
72dd6141 | 6340 | while (CONVERT_EXPR_P (op)) |
10a9d4cf | 6341 | { |
352bd673 | 6342 | int bitschange; |
6343 | ||
6344 | /* TYPE_PRECISION on vector types has different meaning | |
6345 | (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions, | |
6346 | so avoid them here. */ | |
6347 | if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE) | |
6348 | break; | |
6349 | ||
6350 | bitschange = TYPE_PRECISION (TREE_TYPE (op)) | |
6351 | - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))); | |
10a9d4cf | 6352 | |
6353 | /* Truncations are many-one so cannot be removed. | |
6354 | Unless we are later going to truncate down even farther. */ | |
6355 | if (bitschange < 0 | |
6356 | && final_prec > TYPE_PRECISION (TREE_TYPE (op))) | |
6357 | break; | |
6358 | ||
6359 | /* See what's inside this conversion. If we decide to strip it, | |
6360 | we will set WIN. */ | |
6361 | op = TREE_OPERAND (op, 0); | |
6362 | ||
6363 | /* If we have not stripped any zero-extensions (uns is 0), | |
6364 | we can strip any kind of extension. | |
6365 | If we have previously stripped a zero-extension, | |
6366 | only zero-extensions can safely be stripped. | |
6367 | Any extension can be stripped if the bits it would produce | |
6368 | are all going to be discarded later by truncating to FOR_TYPE. */ | |
6369 | ||
6370 | if (bitschange > 0) | |
6371 | { | |
6372 | if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op))) | |
6373 | win = op; | |
78a8ed03 | 6374 | /* TYPE_UNSIGNED says whether this is a zero-extension. |
10a9d4cf | 6375 | Let's avoid computing it if it does not affect WIN |
6376 | and if UNS will not be needed again. */ | |
a846fd4d | 6377 | if ((uns |
72dd6141 | 6378 | || CONVERT_EXPR_P (op)) |
78a8ed03 | 6379 | && TYPE_UNSIGNED (TREE_TYPE (op))) |
10a9d4cf | 6380 | { |
6381 | uns = 1; | |
6382 | win = op; | |
6383 | } | |
6384 | } | |
6385 | } | |
6386 | ||
10a9d4cf | 6387 | return win; |
6388 | } | |
6389 | \f | |
6390 | /* Return OP or a simpler expression for a narrower value | |
6391 | which can be sign-extended or zero-extended to give back OP. | |
6392 | Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended | |
6393 | or 0 if the value should be sign-extended. */ | |
6394 | ||
6395 | tree | |
60b8c5b3 | 6396 | get_narrower (tree op, int *unsignedp_ptr) |
10a9d4cf | 6397 | { |
19cb6b50 | 6398 | int uns = 0; |
10a9d4cf | 6399 | int first = 1; |
19cb6b50 | 6400 | tree win = op; |
727c62dd | 6401 | bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op)); |
10a9d4cf | 6402 | |
6403 | while (TREE_CODE (op) == NOP_EXPR) | |
6404 | { | |
19cb6b50 | 6405 | int bitschange |
083a2b5e | 6406 | = (TYPE_PRECISION (TREE_TYPE (op)) |
6407 | - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)))); | |
10a9d4cf | 6408 | |
6409 | /* Truncations are many-one so cannot be removed. */ | |
6410 | if (bitschange < 0) | |
6411 | break; | |
6412 | ||
6413 | /* See what's inside this conversion. If we decide to strip it, | |
6414 | we will set WIN. */ | |
10a9d4cf | 6415 | |
6416 | if (bitschange > 0) | |
6417 | { | |
6cf10752 | 6418 | op = TREE_OPERAND (op, 0); |
10a9d4cf | 6419 | /* An extension: the outermost one can be stripped, |
6420 | but remember whether it is zero or sign extension. */ | |
6421 | if (first) | |
78a8ed03 | 6422 | uns = TYPE_UNSIGNED (TREE_TYPE (op)); |
10a9d4cf | 6423 | /* Otherwise, if a sign extension has been stripped, |
6424 | only sign extensions can now be stripped; | |
6425 | if a zero extension has been stripped, only zero-extensions. */ | |
78a8ed03 | 6426 | else if (uns != TYPE_UNSIGNED (TREE_TYPE (op))) |
10a9d4cf | 6427 | break; |
6428 | first = 0; | |
6429 | } | |
edbe57f0 | 6430 | else /* bitschange == 0 */ |
6431 | { | |
6432 | /* A change in nominal type can always be stripped, but we must | |
6433 | preserve the unsignedness. */ | |
6434 | if (first) | |
78a8ed03 | 6435 | uns = TYPE_UNSIGNED (TREE_TYPE (op)); |
edbe57f0 | 6436 | first = 0; |
6cf10752 | 6437 | op = TREE_OPERAND (op, 0); |
727c62dd | 6438 | /* Keep trying to narrow, but don't assign op to win if it |
6439 | would turn an integral type into something else. */ | |
6440 | if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p) | |
6441 | continue; | |
edbe57f0 | 6442 | } |
10a9d4cf | 6443 | |
6444 | win = op; | |
6445 | } | |
6446 | ||
6447 | if (TREE_CODE (op) == COMPONENT_REF | |
6448 | /* Since type_for_size always gives an integer type. */ | |
99651114 | 6449 | && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE |
06f0b99c | 6450 | && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE |
99651114 | 6451 | /* Ensure field is laid out already. */ |
6374121b | 6452 | && DECL_SIZE (TREE_OPERAND (op, 1)) != 0 |
6453 | && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1)) | |
10a9d4cf | 6454 | { |
99651114 | 6455 | unsigned HOST_WIDE_INT innerprec |
6456 | = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1); | |
86ae60fd | 6457 | int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1)) |
78a8ed03 | 6458 | || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1)))); |
dc24ddbd | 6459 | tree type = lang_hooks.types.type_for_size (innerprec, unsignedp); |
10a9d4cf | 6460 | |
6461 | /* We can get this structure field in a narrower type that fits it, | |
6462 | but the resulting extension to its nominal type (a fullword type) | |
6463 | must satisfy the same conditions as for other extensions. | |
6464 | ||
6465 | Do this only for fields that are aligned (not bit-fields), | |
6466 | because when bit-field insns will be used there is no | |
6467 | advantage in doing this. */ | |
6468 | ||
6469 | if (innerprec < TYPE_PRECISION (TREE_TYPE (op)) | |
6470 | && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)) | |
86ae60fd | 6471 | && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1))) |
10a9d4cf | 6472 | && type != 0) |
6473 | { | |
6474 | if (first) | |
86ae60fd | 6475 | uns = DECL_UNSIGNED (TREE_OPERAND (op, 1)); |
b1088b3e | 6476 | win = fold_convert (type, op); |
10a9d4cf | 6477 | } |
6478 | } | |
b1088b3e | 6479 | |
10a9d4cf | 6480 | *unsignedp_ptr = uns; |
6481 | return win; | |
6482 | } | |
6483 | \f | |
10a9d4cf | 6484 | /* Nonzero if integer constant C has a value that is permissible |
6485 | for type TYPE (an INTEGER_TYPE). */ | |
6486 | ||
6487 | int | |
720082dc | 6488 | int_fits_type_p (const_tree c, const_tree type) |
10a9d4cf | 6489 | { |
d235ab60 | 6490 | tree type_low_bound, type_high_bound; |
6491 | bool ok_for_low_bound, ok_for_high_bound, unsc; | |
6492 | double_int dc, dd; | |
6493 | ||
6494 | dc = tree_to_double_int (c); | |
6495 | unsc = TYPE_UNSIGNED (TREE_TYPE (c)); | |
6496 | ||
6497 | if (TREE_CODE (TREE_TYPE (c)) == INTEGER_TYPE | |
6498 | && TYPE_IS_SIZETYPE (TREE_TYPE (c)) | |
6499 | && unsc) | |
6500 | /* So c is an unsigned integer whose type is sizetype and type is not. | |
6501 | sizetype'd integers are sign extended even though they are | |
6502 | unsigned. If the integer value fits in the lower end word of c, | |
6503 | and if the higher end word has all its bits set to 1, that | |
6504 | means the higher end bits are set to 1 only for sign extension. | |
6505 | So let's convert c into an equivalent zero extended unsigned | |
6506 | integer. */ | |
6507 | dc = double_int_zext (dc, TYPE_PRECISION (TREE_TYPE (c))); | |
6508 | ||
6509 | retry: | |
6510 | type_low_bound = TYPE_MIN_VALUE (type); | |
6511 | type_high_bound = TYPE_MAX_VALUE (type); | |
ddb425f3 | 6512 | |
6513 | /* If at least one bound of the type is a constant integer, we can check | |
6514 | ourselves and maybe make a decision. If no such decision is possible, but | |
6515 | this type is a subtype, try checking against that. Otherwise, use | |
ca9b061d | 6516 | fit_double_type, which checks against the precision. |
ddb425f3 | 6517 | |
6518 | Compute the status for each possibly constant bound, and return if we see | |
6519 | one does not match. Use ok_for_xxx_bound for this purpose, assigning -1 | |
6520 | for "unknown if constant fits", 0 for "constant known *not* to fit" and 1 | |
6521 | for "constant known to fit". */ | |
6522 | ||
d235ab60 | 6523 | /* Check if c >= type_low_bound. */ |
ddb425f3 | 6524 | if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST) |
f27f695c | 6525 | { |
d235ab60 | 6526 | dd = tree_to_double_int (type_low_bound); |
6527 | if (TREE_CODE (type) == INTEGER_TYPE | |
6528 | && TYPE_IS_SIZETYPE (type) | |
6529 | && TYPE_UNSIGNED (type)) | |
6530 | dd = double_int_zext (dd, TYPE_PRECISION (type)); | |
6531 | if (unsc != TYPE_UNSIGNED (TREE_TYPE (type_low_bound))) | |
6532 | { | |
6533 | int c_neg = (!unsc && double_int_negative_p (dc)); | |
6534 | int t_neg = (unsc && double_int_negative_p (dd)); | |
6535 | ||
6536 | if (c_neg && !t_neg) | |
6537 | return 0; | |
6538 | if ((c_neg || !t_neg) && double_int_ucmp (dc, dd) < 0) | |
6539 | return 0; | |
6540 | } | |
6541 | else if (double_int_cmp (dc, dd, unsc) < 0) | |
ddb425f3 | 6542 | return 0; |
46d3b0a2 | 6543 | ok_for_low_bound = true; |
f27f695c | 6544 | } |
46d3b0a2 | 6545 | else |
6546 | ok_for_low_bound = false; | |
ddb425f3 | 6547 | |
6548 | /* Check if c <= type_high_bound. */ | |
6549 | if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST) | |
6550 | { | |
d235ab60 | 6551 | dd = tree_to_double_int (type_high_bound); |
6552 | if (TREE_CODE (type) == INTEGER_TYPE | |
6553 | && TYPE_IS_SIZETYPE (type) | |
6554 | && TYPE_UNSIGNED (type)) | |
6555 | dd = double_int_zext (dd, TYPE_PRECISION (type)); | |
6556 | if (unsc != TYPE_UNSIGNED (TREE_TYPE (type_high_bound))) | |
6557 | { | |
6558 | int c_neg = (!unsc && double_int_negative_p (dc)); | |
6559 | int t_neg = (unsc && double_int_negative_p (dd)); | |
6560 | ||
6561 | if (t_neg && !c_neg) | |
6562 | return 0; | |
6563 | if ((t_neg || !c_neg) && double_int_ucmp (dc, dd) > 0) | |
6564 | return 0; | |
6565 | } | |
6566 | else if (double_int_cmp (dc, dd, unsc) > 0) | |
ddb425f3 | 6567 | return 0; |
46d3b0a2 | 6568 | ok_for_high_bound = true; |
ddb425f3 | 6569 | } |
46d3b0a2 | 6570 | else |
6571 | ok_for_high_bound = false; | |
ddb425f3 | 6572 | |
6573 | /* If the constant fits both bounds, the result is known. */ | |
46d3b0a2 | 6574 | if (ok_for_low_bound && ok_for_high_bound) |
ddb425f3 | 6575 | return 1; |
6576 | ||
46d3b0a2 | 6577 | /* Perform some generic filtering which may allow making a decision |
6578 | even if the bounds are not constant. First, negative integers | |
6579 | never fit in unsigned types, */ | |
d235ab60 | 6580 | if (TYPE_UNSIGNED (type) && !unsc && double_int_negative_p (dc)) |
46d3b0a2 | 6581 | return 0; |
6582 | ||
6583 | /* Second, narrower types always fit in wider ones. */ | |
6584 | if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c))) | |
6585 | return 1; | |
6586 | ||
6587 | /* Third, unsigned integers with top bit set never fit signed types. */ | |
d235ab60 | 6588 | if (! TYPE_UNSIGNED (type) && unsc) |
6589 | { | |
6590 | int prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (c))) - 1; | |
6591 | if (prec < HOST_BITS_PER_WIDE_INT) | |
6592 | { | |
6593 | if (((((unsigned HOST_WIDE_INT) 1) << prec) & dc.low) != 0) | |
6594 | return 0; | |
6595 | } | |
6596 | else if (((((unsigned HOST_WIDE_INT) 1) | |
6597 | << (prec - HOST_BITS_PER_WIDE_INT)) & dc.high) != 0) | |
6598 | return 0; | |
6599 | } | |
46d3b0a2 | 6600 | |
ddb425f3 | 6601 | /* If we haven't been able to decide at this point, there nothing more we |
ca6a2cc9 | 6602 | can check ourselves here. Look at the base type if we have one and it |
6603 | has the same precision. */ | |
6604 | if (TREE_CODE (type) == INTEGER_TYPE | |
6605 | && TREE_TYPE (type) != 0 | |
6606 | && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type))) | |
d235ab60 | 6607 | { |
6608 | type = TREE_TYPE (type); | |
6609 | goto retry; | |
6610 | } | |
60b8c5b3 | 6611 | |
ca9b061d | 6612 | /* Or to fit_double_type, if nothing else. */ |
d235ab60 | 6613 | return !fit_double_type (dc.low, dc.high, &dc.low, &dc.high, type); |
10a9d4cf | 6614 | } |
6615 | ||
612a17fc | 6616 | /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant |
6617 | bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be | |
6618 | represented (assuming two's-complement arithmetic) within the bit | |
6619 | precision of the type are returned instead. */ | |
6620 | ||
6621 | void | |
1f1872fd | 6622 | get_type_static_bounds (const_tree type, mpz_t min, mpz_t max) |
612a17fc | 6623 | { |
6624 | if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type) | |
6625 | && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST) | |
6626 | mpz_set_double_int (min, tree_to_double_int (TYPE_MIN_VALUE (type)), | |
6627 | TYPE_UNSIGNED (type)); | |
6628 | else | |
6629 | { | |
6630 | if (TYPE_UNSIGNED (type)) | |
6631 | mpz_set_ui (min, 0); | |
6632 | else | |
6633 | { | |
6634 | double_int mn; | |
6635 | mn = double_int_mask (TYPE_PRECISION (type) - 1); | |
6636 | mn = double_int_sext (double_int_add (mn, double_int_one), | |
6637 | TYPE_PRECISION (type)); | |
6638 | mpz_set_double_int (min, mn, false); | |
6639 | } | |
6640 | } | |
6641 | ||
6642 | if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type) | |
6643 | && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST) | |
6644 | mpz_set_double_int (max, tree_to_double_int (TYPE_MAX_VALUE (type)), | |
6645 | TYPE_UNSIGNED (type)); | |
6646 | else | |
6647 | { | |
6648 | if (TYPE_UNSIGNED (type)) | |
6649 | mpz_set_double_int (max, double_int_mask (TYPE_PRECISION (type)), | |
6650 | true); | |
6651 | else | |
6652 | mpz_set_double_int (max, double_int_mask (TYPE_PRECISION (type) - 1), | |
6653 | true); | |
6654 | } | |
6655 | } | |
6656 | ||
75a70cf9 | 6657 | /* Return true if VAR is an automatic variable defined in function FN. */ |
2ef41604 | 6658 | |
6659 | bool | |
9f627b1a | 6660 | auto_var_in_fn_p (const_tree var, const_tree fn) |
2ef41604 | 6661 | { |
6662 | return (DECL_P (var) && DECL_CONTEXT (var) == fn | |
6663 | && (((TREE_CODE (var) == VAR_DECL || TREE_CODE (var) == PARM_DECL) | |
6664 | && ! TREE_STATIC (var)) | |
6665 | || TREE_CODE (var) == LABEL_DECL | |
6666 | || TREE_CODE (var) == RESULT_DECL)); | |
6667 | } | |
6668 | ||
1f8a6ff8 | 6669 | /* Subprogram of following function. Called by walk_tree. |
6670 | ||
6671 | Return *TP if it is an automatic variable or parameter of the | |
6672 | function passed in as DATA. */ | |
6673 | ||
6674 | static tree | |
6675 | find_var_from_fn (tree *tp, int *walk_subtrees, void *data) | |
6676 | { | |
6677 | tree fn = (tree) data; | |
6678 | ||
6679 | if (TYPE_P (*tp)) | |
6680 | *walk_subtrees = 0; | |
6681 | ||
ce45a448 | 6682 | else if (DECL_P (*tp) |
2ef41604 | 6683 | && auto_var_in_fn_p (*tp, fn)) |
1f8a6ff8 | 6684 | return *tp; |
6685 | ||
6686 | return NULL_TREE; | |
6687 | } | |
6688 | ||
21ac3a84 | 6689 | /* Returns true if T is, contains, or refers to a type with variable |
de8dea22 | 6690 | size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the |
6691 | arguments, but not the return type. If FN is nonzero, only return | |
6692 | true if a modifier of the type or position of FN is a variable or | |
6693 | parameter inside FN. | |
1f8a6ff8 | 6694 | |
6695 | This concept is more general than that of C99 'variably modified types': | |
6696 | in C99, a struct type is never variably modified because a VLA may not | |
6697 | appear as a structure member. However, in GNU C code like: | |
60b8c5b3 | 6698 | |
21ac3a84 | 6699 | struct S { int i[f()]; }; |
6700 | ||
6701 | is valid, and other languages may define similar constructs. */ | |
6702 | ||
6703 | bool | |
1f8a6ff8 | 6704 | variably_modified_type_p (tree type, tree fn) |
21ac3a84 | 6705 | { |
ecba2e4c | 6706 | tree t; |
6707 | ||
1f8a6ff8 | 6708 | /* Test if T is either variable (if FN is zero) or an expression containing |
6709 | a variable in FN. */ | |
6710 | #define RETURN_TRUE_IF_VAR(T) \ | |
6711 | do { tree _t = (T); \ | |
6712 | if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \ | |
6713 | && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \ | |
6714 | return true; } while (0) | |
6715 | ||
a6543b83 | 6716 | if (type == error_mark_node) |
6717 | return false; | |
6718 | ||
32d33ab2 | 6719 | /* If TYPE itself has variable size, it is variably modified. */ |
1f8a6ff8 | 6720 | RETURN_TRUE_IF_VAR (TYPE_SIZE (type)); |
6726ef59 | 6721 | RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type)); |
21ac3a84 | 6722 | |
ecba2e4c | 6723 | switch (TREE_CODE (type)) |
6724 | { | |
6725 | case POINTER_TYPE: | |
6726 | case REFERENCE_TYPE: | |
ab7083b0 | 6727 | case VECTOR_TYPE: |
1f8a6ff8 | 6728 | if (variably_modified_type_p (TREE_TYPE (type), fn)) |
ab7083b0 | 6729 | return true; |
6730 | break; | |
60b8c5b3 | 6731 | |
ecba2e4c | 6732 | case FUNCTION_TYPE: |
6733 | case METHOD_TYPE: | |
de8dea22 | 6734 | /* If TYPE is a function type, it is variably modified if the |
6735 | return type is variably modified. */ | |
1f8a6ff8 | 6736 | if (variably_modified_type_p (TREE_TYPE (type), fn)) |
ab7083b0 | 6737 | return true; |
ecba2e4c | 6738 | break; |
21ac3a84 | 6739 | |
ecba2e4c | 6740 | case INTEGER_TYPE: |
ab7083b0 | 6741 | case REAL_TYPE: |
06f0b99c | 6742 | case FIXED_POINT_TYPE: |
ab7083b0 | 6743 | case ENUMERAL_TYPE: |
6744 | case BOOLEAN_TYPE: | |
ecba2e4c | 6745 | /* Scalar types are variably modified if their end points |
6746 | aren't constant. */ | |
1f8a6ff8 | 6747 | RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type)); |
6748 | RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type)); | |
ab7083b0 | 6749 | break; |
6750 | ||
6751 | case RECORD_TYPE: | |
6752 | case UNION_TYPE: | |
6753 | case QUAL_UNION_TYPE: | |
32d33ab2 | 6754 | /* We can't see if any of the fields are variably-modified by the |
ab7083b0 | 6755 | definition we normally use, since that would produce infinite |
6756 | recursion via pointers. */ | |
6757 | /* This is variably modified if some field's type is. */ | |
6758 | for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t)) | |
6759 | if (TREE_CODE (t) == FIELD_DECL) | |
6760 | { | |
1f8a6ff8 | 6761 | RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t)); |
6762 | RETURN_TRUE_IF_VAR (DECL_SIZE (t)); | |
6763 | RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t)); | |
ab7083b0 | 6764 | |
1f8a6ff8 | 6765 | if (TREE_CODE (type) == QUAL_UNION_TYPE) |
6766 | RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t)); | |
ab7083b0 | 6767 | } |
6768 | break; | |
ecba2e4c | 6769 | |
6726ef59 | 6770 | case ARRAY_TYPE: |
6771 | /* Do not call ourselves to avoid infinite recursion. This is | |
6772 | variably modified if the element type is. */ | |
6773 | RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type))); | |
6774 | RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type))); | |
6775 | break; | |
6776 | ||
ecba2e4c | 6777 | default: |
6778 | break; | |
21ac3a84 | 6779 | } |
6780 | ||
6781 | /* The current language may have other cases to check, but in general, | |
6782 | all other types are not variably modified. */ | |
1f8a6ff8 | 6783 | return lang_hooks.tree_inlining.var_mod_type_p (type, fn); |
6784 | ||
6785 | #undef RETURN_TRUE_IF_VAR | |
21ac3a84 | 6786 | } |
6787 | ||
804dff30 | 6788 | /* Given a DECL or TYPE, return the scope in which it was declared, or |
d5e65e3e | 6789 | NULL_TREE if there is no containing scope. */ |
804dff30 | 6790 | |
6791 | tree | |
720082dc | 6792 | get_containing_scope (const_tree t) |
804dff30 | 6793 | { |
6794 | return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t)); | |
6795 | } | |
6796 | ||
d3862ba2 | 6797 | /* Return the innermost context enclosing DECL that is |
10a9d4cf | 6798 | a FUNCTION_DECL, or zero if none. */ |
6799 | ||
6800 | tree | |
720082dc | 6801 | decl_function_context (const_tree decl) |
10a9d4cf | 6802 | { |
6803 | tree context; | |
6804 | ||
d3862ba2 | 6805 | if (TREE_CODE (decl) == ERROR_MARK) |
10a9d4cf | 6806 | return 0; |
6807 | ||
53bdb86c | 6808 | /* C++ virtual functions use DECL_CONTEXT for the class of the vtable |
6809 | where we look up the function at runtime. Such functions always take | |
6810 | a first argument of type 'pointer to real context'. | |
6811 | ||
6812 | C++ should really be fixed to use DECL_CONTEXT for the real context, | |
6813 | and use something else for the "virtual context". */ | |
6814 | else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl)) | |
d5e65e3e | 6815 | context |
6816 | = TYPE_MAIN_VARIANT | |
6817 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
10a9d4cf | 6818 | else |
d3862ba2 | 6819 | context = DECL_CONTEXT (decl); |
10a9d4cf | 6820 | |
6821 | while (context && TREE_CODE (context) != FUNCTION_DECL) | |
6822 | { | |
804dff30 | 6823 | if (TREE_CODE (context) == BLOCK) |
10a9d4cf | 6824 | context = BLOCK_SUPERCONTEXT (context); |
9bfff6cb | 6825 | else |
804dff30 | 6826 | context = get_containing_scope (context); |
10a9d4cf | 6827 | } |
6828 | ||
6829 | return context; | |
6830 | } | |
6831 | ||
d3862ba2 | 6832 | /* Return the innermost context enclosing DECL that is |
5dbb3364 | 6833 | a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none. |
10a9d4cf | 6834 | TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */ |
6835 | ||
6836 | tree | |
720082dc | 6837 | decl_type_context (const_tree decl) |
10a9d4cf | 6838 | { |
d3862ba2 | 6839 | tree context = DECL_CONTEXT (decl); |
10a9d4cf | 6840 | |
6841 | while (context) | |
40109983 | 6842 | switch (TREE_CODE (context)) |
6843 | { | |
6844 | case NAMESPACE_DECL: | |
6845 | case TRANSLATION_UNIT_DECL: | |
6c34d0c2 | 6846 | return NULL_TREE; |
e9750a4e | 6847 | |
40109983 | 6848 | case RECORD_TYPE: |
6849 | case UNION_TYPE: | |
6850 | case QUAL_UNION_TYPE: | |
10a9d4cf | 6851 | return context; |
b27ac6b5 | 6852 | |
40109983 | 6853 | case TYPE_DECL: |
6854 | case FUNCTION_DECL: | |
10a9d4cf | 6855 | context = DECL_CONTEXT (context); |
40109983 | 6856 | break; |
b27ac6b5 | 6857 | |
40109983 | 6858 | case BLOCK: |
10a9d4cf | 6859 | context = BLOCK_SUPERCONTEXT (context); |
40109983 | 6860 | break; |
b27ac6b5 | 6861 | |
40109983 | 6862 | default: |
8c0963c4 | 6863 | gcc_unreachable (); |
40109983 | 6864 | } |
6865 | ||
10a9d4cf | 6866 | return NULL_TREE; |
6867 | } | |
6868 | ||
4a2fac76 | 6869 | /* CALL is a CALL_EXPR. Return the declaration for the function |
9bfff6cb | 6870 | called, or NULL_TREE if the called function cannot be |
4a2fac76 | 6871 | determined. */ |
6872 | ||
6873 | tree | |
b7bf20db | 6874 | get_callee_fndecl (const_tree call) |
4a2fac76 | 6875 | { |
6876 | tree addr; | |
6877 | ||
6da06c90 | 6878 | if (call == error_mark_node) |
b7bf20db | 6879 | return error_mark_node; |
6da06c90 | 6880 | |
4a2fac76 | 6881 | /* It's invalid to call this function with anything but a |
6882 | CALL_EXPR. */ | |
8c0963c4 | 6883 | gcc_assert (TREE_CODE (call) == CALL_EXPR); |
4a2fac76 | 6884 | |
6885 | /* The first operand to the CALL is the address of the function | |
6886 | called. */ | |
c2f47e15 | 6887 | addr = CALL_EXPR_FN (call); |
4a2fac76 | 6888 | |
b85737ba | 6889 | STRIP_NOPS (addr); |
6890 | ||
6891 | /* If this is a readonly function pointer, extract its initial value. */ | |
6892 | if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL | |
6893 | && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr) | |
6894 | && DECL_INITIAL (addr)) | |
6895 | addr = DECL_INITIAL (addr); | |
6896 | ||
4a2fac76 | 6897 | /* If the address is just `&f' for some function `f', then we know |
6898 | that `f' is being called. */ | |
6899 | if (TREE_CODE (addr) == ADDR_EXPR | |
6900 | && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL) | |
ad850f1c | 6901 | return TREE_OPERAND (addr, 0); |
b27ac6b5 | 6902 | |
4cd62850 | 6903 | /* We couldn't figure out what was being called. */ |
6904 | return NULL_TREE; | |
4a2fac76 | 6905 | } |
6906 | ||
73eac312 | 6907 | /* Print debugging information about tree nodes generated during the compile, |
6908 | and any language-specific information. */ | |
6909 | ||
10a9d4cf | 6910 | void |
60b8c5b3 | 6911 | dump_tree_statistics (void) |
10a9d4cf | 6912 | { |
07e64d6e | 6913 | #ifdef GATHER_STATISTICS |
10a9d4cf | 6914 | int i; |
6915 | int total_nodes, total_bytes; | |
07e64d6e | 6916 | #endif |
10a9d4cf | 6917 | |
6918 | fprintf (stderr, "\n??? tree nodes created\n\n"); | |
6919 | #ifdef GATHER_STATISTICS | |
b7257530 | 6920 | fprintf (stderr, "Kind Nodes Bytes\n"); |
6921 | fprintf (stderr, "---------------------------------------\n"); | |
10a9d4cf | 6922 | total_nodes = total_bytes = 0; |
6923 | for (i = 0; i < (int) all_kinds; i++) | |
6924 | { | |
b7257530 | 6925 | fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i], |
10a9d4cf | 6926 | tree_node_counts[i], tree_node_sizes[i]); |
6927 | total_nodes += tree_node_counts[i]; | |
6928 | total_bytes += tree_node_sizes[i]; | |
6929 | } | |
b7257530 | 6930 | fprintf (stderr, "---------------------------------------\n"); |
6931 | fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes); | |
6932 | fprintf (stderr, "---------------------------------------\n"); | |
4ee9c684 | 6933 | ssanames_print_statistics (); |
6934 | phinodes_print_statistics (); | |
10a9d4cf | 6935 | #else |
6936 | fprintf (stderr, "(No per-node statistics)\n"); | |
6937 | #endif | |
f2d83427 | 6938 | print_type_hash_statistics (); |
8bc1e6ff | 6939 | print_debug_expr_statistics (); |
75fa4f82 | 6940 | print_value_expr_statistics (); |
83b34c62 | 6941 | print_restrict_base_statistics (); |
dc24ddbd | 6942 | lang_hooks.print_statistics (); |
10a9d4cf | 6943 | } |
38d47eb8 | 6944 | \f |
9bc65db1 | 6945 | #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s" |
38d47eb8 | 6946 | |
eac18265 | 6947 | /* Generate a crc32 of a string. */ |
6717a67d | 6948 | |
eac18265 | 6949 | unsigned |
6950 | crc32_string (unsigned chksum, const char *string) | |
6717a67d | 6951 | { |
eac18265 | 6952 | do |
6953 | { | |
6954 | unsigned value = *string << 24; | |
6955 | unsigned ix; | |
b27ac6b5 | 6956 | |
eac18265 | 6957 | for (ix = 8; ix--; value <<= 1) |
6958 | { | |
6959 | unsigned feedback; | |
b27ac6b5 | 6960 | |
eac18265 | 6961 | feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0; |
6962 | chksum <<= 1; | |
6963 | chksum ^= feedback; | |
6964 | } | |
6965 | } | |
6966 | while (*string++); | |
6967 | return chksum; | |
6717a67d | 6968 | } |
6969 | ||
19f716e5 | 6970 | /* P is a string that will be used in a symbol. Mask out any characters |
6971 | that are not valid in that context. */ | |
6972 | ||
6973 | void | |
60b8c5b3 | 6974 | clean_symbol_name (char *p) |
19f716e5 | 6975 | { |
6976 | for (; *p; p++) | |
66a33570 | 6977 | if (! (ISALNUM (*p) |
19f716e5 | 6978 | #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */ |
6979 | || *p == '$' | |
6980 | #endif | |
6981 | #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */ | |
6982 | || *p == '.' | |
6983 | #endif | |
66a33570 | 6984 | )) |
19f716e5 | 6985 | *p = '_'; |
6986 | } | |
709c2f34 | 6987 | |
db85cc4f | 6988 | /* Generate a name for a special-purpose function function. |
6989 | The generated name may need to be unique across the whole link. | |
6717a67d | 6990 | TYPE is some string to identify the purpose of this function to the |
db85cc4f | 6991 | linker or collect2; it must start with an uppercase letter, |
6992 | one of: | |
6993 | I - for constructors | |
6994 | D - for destructors | |
6995 | N - for C++ anonymous namespaces | |
6996 | F - for DWARF unwind frame information. */ | |
38d47eb8 | 6997 | |
6998 | tree | |
db85cc4f | 6999 | get_file_function_name (const char *type) |
38d47eb8 | 7000 | { |
7001 | char *buf; | |
e772a198 | 7002 | const char *p; |
7003 | char *q; | |
38d47eb8 | 7004 | |
db85cc4f | 7005 | /* If we already have a name we know to be unique, just use that. */ |
38d47eb8 | 7006 | if (first_global_object_name) |
24e20bcd | 7007 | p = q = ASTRDUP (first_global_object_name); |
db85cc4f | 7008 | /* If the target is handling the constructors/destructors, they |
7009 | will be local to this file and the name is only necessary for | |
7010 | debugging purposes. */ | |
7011 | else if ((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors) | |
a0028b3d | 7012 | { |
db85cc4f | 7013 | const char *file = main_input_filename; |
7014 | if (! file) | |
7015 | file = input_filename; | |
7016 | /* Just use the file's basename, because the full pathname | |
7017 | might be quite long. */ | |
7018 | p = strrchr (file, '/'); | |
7019 | if (p) | |
7020 | p++; | |
7021 | else | |
7022 | p = file; | |
7023 | p = q = ASTRDUP (p); | |
a0028b3d | 7024 | } |
38d47eb8 | 7025 | else |
6717a67d | 7026 | { |
db85cc4f | 7027 | /* Otherwise, the name must be unique across the entire link. |
7028 | We don't have anything that we know to be unique to this translation | |
6717a67d | 7029 | unit, so use what we do have and throw in some randomness. */ |
eac18265 | 7030 | unsigned len; |
b788a3c3 | 7031 | const char *name = weak_global_object_name; |
7032 | const char *file = main_input_filename; | |
6717a67d | 7033 | |
7034 | if (! name) | |
7035 | name = ""; | |
7036 | if (! file) | |
7037 | file = input_filename; | |
7038 | ||
eac18265 | 7039 | len = strlen (file); |
45ba1503 | 7040 | q = (char *) alloca (9 * 2 + len + 1); |
eac18265 | 7041 | memcpy (q, file, len + 1); |
eac18265 | 7042 | |
eac18265 | 7043 | sprintf (q + len, "_%08X_%08X", crc32_string (0, name), |
b6c1bd72 | 7044 | crc32_string (0, get_random_seed (false))); |
6717a67d | 7045 | |
e772a198 | 7046 | p = q; |
6717a67d | 7047 | } |
38d47eb8 | 7048 | |
24e20bcd | 7049 | clean_symbol_name (q); |
45ba1503 | 7050 | buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p) |
7051 | + strlen (type)); | |
38d47eb8 | 7052 | |
9bfff6cb | 7053 | /* Set up the name of the file-level functions we may need. |
083a2b5e | 7054 | Use a global object (which is already required to be unique over |
38d47eb8 | 7055 | the program) rather than the file name (which imposes extra |
083a2b5e | 7056 | constraints). */ |
9bc65db1 | 7057 | sprintf (buf, FILE_FUNCTION_FORMAT, type, p); |
38d47eb8 | 7058 | |
38d47eb8 | 7059 | return get_identifier (buf); |
7060 | } | |
c141f4ab | 7061 | \f |
0c4e40c5 | 7062 | #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007) |
82bb2115 | 7063 | |
36066e37 | 7064 | /* Complain that the tree code of NODE does not match the expected 0 |
d409f4c9 | 7065 | terminated list of trailing codes. The trailing code list can be |
7066 | empty, for a more vague error message. FILE, LINE, and FUNCTION | |
7067 | are of the caller. */ | |
9bfff6cb | 7068 | |
a4070a91 | 7069 | void |
aae87fc3 | 7070 | tree_check_failed (const_tree node, const char *file, |
36066e37 | 7071 | int line, const char *function, ...) |
7072 | { | |
7073 | va_list args; | |
aae87fc3 | 7074 | const char *buffer; |
36066e37 | 7075 | unsigned length = 0; |
7076 | int code; | |
7077 | ||
7078 | va_start (args, function); | |
7079 | while ((code = va_arg (args, int))) | |
7080 | length += 4 + strlen (tree_code_name[code]); | |
7081 | va_end (args); | |
d409f4c9 | 7082 | if (length) |
36066e37 | 7083 | { |
aae87fc3 | 7084 | char *tmp; |
d409f4c9 | 7085 | va_start (args, function); |
7086 | length += strlen ("expected "); | |
45ba1503 | 7087 | buffer = tmp = (char *) alloca (length); |
d409f4c9 | 7088 | length = 0; |
7089 | while ((code = va_arg (args, int))) | |
36066e37 | 7090 | { |
d409f4c9 | 7091 | const char *prefix = length ? " or " : "expected "; |
7092 | ||
aae87fc3 | 7093 | strcpy (tmp + length, prefix); |
d409f4c9 | 7094 | length += strlen (prefix); |
aae87fc3 | 7095 | strcpy (tmp + length, tree_code_name[code]); |
d409f4c9 | 7096 | length += strlen (tree_code_name[code]); |
36066e37 | 7097 | } |
d409f4c9 | 7098 | va_end (args); |
36066e37 | 7099 | } |
d409f4c9 | 7100 | else |
aae87fc3 | 7101 | buffer = "unexpected node"; |
b27ac6b5 | 7102 | |
d409f4c9 | 7103 | internal_error ("tree check: %s, have %s in %s, at %s:%d", |
36066e37 | 7104 | buffer, tree_code_name[TREE_CODE (node)], |
82bb2115 | 7105 | function, trim_filename (file), line); |
7106 | } | |
7107 | ||
36066e37 | 7108 | /* Complain that the tree code of NODE does match the expected 0 |
7109 | terminated list of trailing codes. FILE, LINE, and FUNCTION are of | |
7110 | the caller. */ | |
82bb2115 | 7111 | |
7112 | void | |
aae87fc3 | 7113 | tree_not_check_failed (const_tree node, const char *file, |
36066e37 | 7114 | int line, const char *function, ...) |
7115 | { | |
7116 | va_list args; | |
7117 | char *buffer; | |
7118 | unsigned length = 0; | |
7119 | int code; | |
7120 | ||
7121 | va_start (args, function); | |
7122 | while ((code = va_arg (args, int))) | |
7123 | length += 4 + strlen (tree_code_name[code]); | |
7124 | va_end (args); | |
7125 | va_start (args, function); | |
45ba1503 | 7126 | buffer = (char *) alloca (length); |
36066e37 | 7127 | length = 0; |
7128 | while ((code = va_arg (args, int))) | |
7129 | { | |
7130 | if (length) | |
7131 | { | |
7132 | strcpy (buffer + length, " or "); | |
7133 | length += 4; | |
7134 | } | |
7135 | strcpy (buffer + length, tree_code_name[code]); | |
7136 | length += strlen (tree_code_name[code]); | |
7137 | } | |
7138 | va_end (args); | |
b27ac6b5 | 7139 | |
36066e37 | 7140 | internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d", |
7141 | buffer, tree_code_name[TREE_CODE (node)], | |
82bb2115 | 7142 | function, trim_filename (file), line); |
7143 | } | |
7144 | ||
82bb2115 | 7145 | /* Similar to tree_check_failed, except that we check for a class of tree |
9e042f31 | 7146 | code, given in CL. */ |
9bfff6cb | 7147 | |
a4070a91 | 7148 | void |
aae87fc3 | 7149 | tree_class_check_failed (const_tree node, const enum tree_code_class cl, |
ce45a448 | 7150 | const char *file, int line, const char *function) |
3e207e38 | 7151 | { |
0fc48b82 | 7152 | internal_error |
ce45a448 | 7153 | ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d", |
7154 | TREE_CODE_CLASS_STRING (cl), | |
7155 | TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))), | |
0fc48b82 | 7156 | tree_code_name[TREE_CODE (node)], function, trim_filename (file), line); |
a4070a91 | 7157 | } |
59db13d3 | 7158 | |
1e8e9920 | 7159 | /* Similar to tree_check_failed, except that instead of specifying a |
7160 | dozen codes, use the knowledge that they're all sequential. */ | |
7161 | ||
7162 | void | |
aae87fc3 | 7163 | tree_range_check_failed (const_tree node, const char *file, int line, |
1e8e9920 | 7164 | const char *function, enum tree_code c1, |
7165 | enum tree_code c2) | |
7166 | { | |
7167 | char *buffer; | |
7168 | unsigned length = 0; | |
7169 | enum tree_code c; | |
7170 | ||
7171 | for (c = c1; c <= c2; ++c) | |
7172 | length += 4 + strlen (tree_code_name[c]); | |
7173 | ||
7174 | length += strlen ("expected "); | |
45ba1503 | 7175 | buffer = (char *) alloca (length); |
1e8e9920 | 7176 | length = 0; |
7177 | ||
7178 | for (c = c1; c <= c2; ++c) | |
7179 | { | |
7180 | const char *prefix = length ? " or " : "expected "; | |
7181 | ||
7182 | strcpy (buffer + length, prefix); | |
7183 | length += strlen (prefix); | |
7184 | strcpy (buffer + length, tree_code_name[c]); | |
7185 | length += strlen (tree_code_name[c]); | |
7186 | } | |
7187 | ||
7188 | internal_error ("tree check: %s, have %s in %s, at %s:%d", | |
7189 | buffer, tree_code_name[TREE_CODE (node)], | |
7190 | function, trim_filename (file), line); | |
7191 | } | |
7192 | ||
7193 | ||
59db13d3 | 7194 | /* Similar to tree_check_failed, except that we check that a tree does |
7195 | not have the specified code, given in CL. */ | |
7196 | ||
7197 | void | |
aae87fc3 | 7198 | tree_not_class_check_failed (const_tree node, const enum tree_code_class cl, |
59db13d3 | 7199 | const char *file, int line, const char *function) |
7200 | { | |
7201 | internal_error | |
7202 | ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d", | |
7203 | TREE_CODE_CLASS_STRING (cl), | |
7204 | TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))), | |
7205 | tree_code_name[TREE_CODE (node)], function, trim_filename (file), line); | |
7206 | } | |
7207 | ||
55d6e7cd | 7208 | |
7209 | /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */ | |
7210 | ||
7211 | void | |
aae87fc3 | 7212 | omp_clause_check_failed (const_tree node, const char *file, int line, |
55d6e7cd | 7213 | const char *function, enum omp_clause_code code) |
7214 | { | |
7215 | internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d", | |
7216 | omp_clause_code_name[code], tree_code_name[TREE_CODE (node)], | |
7217 | function, trim_filename (file), line); | |
7218 | } | |
7219 | ||
7220 | ||
7221 | /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */ | |
7222 | ||
7223 | void | |
aae87fc3 | 7224 | omp_clause_range_check_failed (const_tree node, const char *file, int line, |
55d6e7cd | 7225 | const char *function, enum omp_clause_code c1, |
7226 | enum omp_clause_code c2) | |
7227 | { | |
7228 | char *buffer; | |
7229 | unsigned length = 0; | |
7230 | enum omp_clause_code c; | |
7231 | ||
7232 | for (c = c1; c <= c2; ++c) | |
7233 | length += 4 + strlen (omp_clause_code_name[c]); | |
7234 | ||
7235 | length += strlen ("expected "); | |
45ba1503 | 7236 | buffer = (char *) alloca (length); |
55d6e7cd | 7237 | length = 0; |
7238 | ||
7239 | for (c = c1; c <= c2; ++c) | |
7240 | { | |
7241 | const char *prefix = length ? " or " : "expected "; | |
7242 | ||
7243 | strcpy (buffer + length, prefix); | |
7244 | length += strlen (prefix); | |
7245 | strcpy (buffer + length, omp_clause_code_name[c]); | |
7246 | length += strlen (omp_clause_code_name[c]); | |
7247 | } | |
7248 | ||
7249 | internal_error ("tree check: %s, have %s in %s, at %s:%d", | |
7250 | buffer, omp_clause_code_name[TREE_CODE (node)], | |
7251 | function, trim_filename (file), line); | |
7252 | } | |
7253 | ||
7254 | ||
5ded8c6f | 7255 | #undef DEFTREESTRUCT |
7256 | #define DEFTREESTRUCT(VAL, NAME) NAME, | |
7257 | ||
7258 | static const char *ts_enum_names[] = { | |
7259 | #include "treestruct.def" | |
7260 | }; | |
7261 | #undef DEFTREESTRUCT | |
7262 | ||
7263 | #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)]) | |
7264 | ||
7265 | /* Similar to tree_class_check_failed, except that we check for | |
7266 | whether CODE contains the tree structure identified by EN. */ | |
7267 | ||
7268 | void | |
aae87fc3 | 7269 | tree_contains_struct_check_failed (const_tree node, |
5ded8c6f | 7270 | const enum tree_node_structure_enum en, |
7271 | const char *file, int line, | |
7272 | const char *function) | |
7273 | { | |
7274 | internal_error | |
21e9153c | 7275 | ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d", |
5ded8c6f | 7276 | TS_ENUM_NAME(en), |
7277 | tree_code_name[TREE_CODE (node)], function, trim_filename (file), line); | |
7278 | } | |
7279 | ||
a4070a91 | 7280 | |
66bc87db | 7281 | /* Similar to above, except that the check is for the bounds of a TREE_VEC's |
7282 | (dynamically sized) vector. */ | |
7283 | ||
7284 | void | |
60b8c5b3 | 7285 | tree_vec_elt_check_failed (int idx, int len, const char *file, int line, |
7286 | const char *function) | |
66bc87db | 7287 | { |
7288 | internal_error | |
7289 | ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d", | |
7290 | idx + 1, len, function, trim_filename (file), line); | |
7291 | } | |
7292 | ||
2fcde217 | 7293 | /* Similar to above, except that the check is for the bounds of the operand |
c2f47e15 | 7294 | vector of an expression node EXP. */ |
2fcde217 | 7295 | |
7296 | void | |
aae87fc3 | 7297 | tree_operand_check_failed (int idx, const_tree exp, const char *file, |
60b8c5b3 | 7298 | int line, const char *function) |
2fcde217 | 7299 | { |
c2f47e15 | 7300 | int code = TREE_CODE (exp); |
2fcde217 | 7301 | internal_error |
7302 | ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d", | |
c2f47e15 | 7303 | idx + 1, tree_code_name[code], TREE_OPERAND_LENGTH (exp), |
2fcde217 | 7304 | function, trim_filename (file), line); |
7305 | } | |
55d6e7cd | 7306 | |
7307 | /* Similar to above, except that the check is for the number of | |
7308 | operands of an OMP_CLAUSE node. */ | |
7309 | ||
7310 | void | |
720082dc | 7311 | omp_clause_operand_check_failed (int idx, const_tree t, const char *file, |
55d6e7cd | 7312 | int line, const char *function) |
7313 | { | |
7314 | internal_error | |
7315 | ("tree check: accessed operand %d of omp_clause %s with %d operands " | |
7316 | "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)], | |
7317 | omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function, | |
7318 | trim_filename (file), line); | |
7319 | } | |
0c4e40c5 | 7320 | #endif /* ENABLE_TREE_CHECKING */ |
775e7cc0 | 7321 | \f |
83e2a11b | 7322 | /* Create a new vector type node holding SUBPARTS units of type INNERTYPE, |
7323 | and mapped to the machine mode MODE. Initialize its fields and build | |
7324 | the information necessary for debugging output. */ | |
9bfff6cb | 7325 | |
83e2a11b | 7326 | static tree |
7327 | make_vector_type (tree innertype, int nunits, enum machine_mode mode) | |
e2ea7e3a | 7328 | { |
b7d1b569 | 7329 | tree t; |
7330 | hashval_t hashcode = 0; | |
7331 | ||
7332 | /* Build a main variant, based on the main variant of the inner type, then | |
7333 | use it to build the variant we return. */ | |
b2d81d54 | 7334 | if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype)) |
7335 | && TYPE_MAIN_VARIANT (innertype) != innertype) | |
b7d1b569 | 7336 | return build_type_attribute_qual_variant ( |
7337 | make_vector_type (TYPE_MAIN_VARIANT (innertype), nunits, mode), | |
7338 | TYPE_ATTRIBUTES (innertype), | |
7339 | TYPE_QUALS (innertype)); | |
83e2a11b | 7340 | |
b7d1b569 | 7341 | t = make_node (VECTOR_TYPE); |
bd971849 | 7342 | TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype); |
99d38b9e | 7343 | SET_TYPE_VECTOR_SUBPARTS (t, nunits); |
342ad2d6 | 7344 | SET_TYPE_MODE (t, mode); |
bd971849 | 7345 | TYPE_READONLY (t) = TYPE_READONLY (innertype); |
7346 | TYPE_VOLATILE (t) = TYPE_VOLATILE (innertype); | |
7347 | ||
6753bca0 | 7348 | if (TYPE_STRUCTURAL_EQUALITY_P (innertype)) |
7349 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
7350 | else if (TYPE_CANONICAL (innertype) != innertype | |
7351 | || mode != VOIDmode) | |
7352 | TYPE_CANONICAL (t) | |
7353 | = make_vector_type (TYPE_CANONICAL (innertype), nunits, VOIDmode); | |
7354 | ||
e2ea7e3a | 7355 | layout_type (t); |
7356 | ||
7357 | { | |
7016c612 | 7358 | tree index = build_int_cst (NULL_TREE, nunits - 1); |
83e2a11b | 7359 | tree array = build_array_type (innertype, build_index_type (index)); |
e2ea7e3a | 7360 | tree rt = make_node (RECORD_TYPE); |
7361 | ||
7362 | TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array); | |
7363 | DECL_CONTEXT (TYPE_FIELDS (rt)) = rt; | |
7364 | layout_type (rt); | |
7365 | TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt; | |
7366 | /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output | |
7367 | the representation type, and we want to find that die when looking up | |
7368 | the vector type. This is most easily achieved by making the TYPE_UID | |
7369 | numbers equal. */ | |
7370 | TYPE_UID (rt) = TYPE_UID (t); | |
7371 | } | |
83e2a11b | 7372 | |
b7d1b569 | 7373 | hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode); |
7374 | hashcode = iterative_hash_host_wide_int (mode, hashcode); | |
7375 | hashcode = iterative_hash_object (TYPE_HASH (innertype), hashcode); | |
7376 | return type_hash_canon (hashcode, t); | |
e2ea7e3a | 7377 | } |
7378 | ||
8b4b9810 | 7379 | static tree |
7380 | make_or_reuse_type (unsigned size, int unsignedp) | |
7381 | { | |
7382 | if (size == INT_TYPE_SIZE) | |
7383 | return unsignedp ? unsigned_type_node : integer_type_node; | |
7384 | if (size == CHAR_TYPE_SIZE) | |
7385 | return unsignedp ? unsigned_char_type_node : signed_char_type_node; | |
7386 | if (size == SHORT_TYPE_SIZE) | |
7387 | return unsignedp ? short_unsigned_type_node : short_integer_type_node; | |
7388 | if (size == LONG_TYPE_SIZE) | |
7389 | return unsignedp ? long_unsigned_type_node : long_integer_type_node; | |
7390 | if (size == LONG_LONG_TYPE_SIZE) | |
7391 | return (unsignedp ? long_long_unsigned_type_node | |
7392 | : long_long_integer_type_node); | |
7393 | ||
7394 | if (unsignedp) | |
7395 | return make_unsigned_type (size); | |
7396 | else | |
7397 | return make_signed_type (size); | |
7398 | } | |
7399 | ||
06f0b99c | 7400 | /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */ |
7401 | ||
7402 | static tree | |
7403 | make_or_reuse_fract_type (unsigned size, int unsignedp, int satp) | |
7404 | { | |
7405 | if (satp) | |
7406 | { | |
7407 | if (size == SHORT_FRACT_TYPE_SIZE) | |
7408 | return unsignedp ? sat_unsigned_short_fract_type_node | |
7409 | : sat_short_fract_type_node; | |
7410 | if (size == FRACT_TYPE_SIZE) | |
7411 | return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node; | |
7412 | if (size == LONG_FRACT_TYPE_SIZE) | |
7413 | return unsignedp ? sat_unsigned_long_fract_type_node | |
7414 | : sat_long_fract_type_node; | |
7415 | if (size == LONG_LONG_FRACT_TYPE_SIZE) | |
7416 | return unsignedp ? sat_unsigned_long_long_fract_type_node | |
7417 | : sat_long_long_fract_type_node; | |
7418 | } | |
7419 | else | |
7420 | { | |
7421 | if (size == SHORT_FRACT_TYPE_SIZE) | |
7422 | return unsignedp ? unsigned_short_fract_type_node | |
7423 | : short_fract_type_node; | |
7424 | if (size == FRACT_TYPE_SIZE) | |
7425 | return unsignedp ? unsigned_fract_type_node : fract_type_node; | |
7426 | if (size == LONG_FRACT_TYPE_SIZE) | |
7427 | return unsignedp ? unsigned_long_fract_type_node | |
7428 | : long_fract_type_node; | |
7429 | if (size == LONG_LONG_FRACT_TYPE_SIZE) | |
7430 | return unsignedp ? unsigned_long_long_fract_type_node | |
7431 | : long_long_fract_type_node; | |
7432 | } | |
7433 | ||
7434 | return make_fract_type (size, unsignedp, satp); | |
7435 | } | |
7436 | ||
7437 | /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */ | |
7438 | ||
7439 | static tree | |
7440 | make_or_reuse_accum_type (unsigned size, int unsignedp, int satp) | |
7441 | { | |
7442 | if (satp) | |
7443 | { | |
7444 | if (size == SHORT_ACCUM_TYPE_SIZE) | |
7445 | return unsignedp ? sat_unsigned_short_accum_type_node | |
7446 | : sat_short_accum_type_node; | |
7447 | if (size == ACCUM_TYPE_SIZE) | |
7448 | return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node; | |
7449 | if (size == LONG_ACCUM_TYPE_SIZE) | |
7450 | return unsignedp ? sat_unsigned_long_accum_type_node | |
7451 | : sat_long_accum_type_node; | |
7452 | if (size == LONG_LONG_ACCUM_TYPE_SIZE) | |
7453 | return unsignedp ? sat_unsigned_long_long_accum_type_node | |
7454 | : sat_long_long_accum_type_node; | |
7455 | } | |
7456 | else | |
7457 | { | |
7458 | if (size == SHORT_ACCUM_TYPE_SIZE) | |
7459 | return unsignedp ? unsigned_short_accum_type_node | |
7460 | : short_accum_type_node; | |
7461 | if (size == ACCUM_TYPE_SIZE) | |
7462 | return unsignedp ? unsigned_accum_type_node : accum_type_node; | |
7463 | if (size == LONG_ACCUM_TYPE_SIZE) | |
7464 | return unsignedp ? unsigned_long_accum_type_node | |
7465 | : long_accum_type_node; | |
7466 | if (size == LONG_LONG_ACCUM_TYPE_SIZE) | |
7467 | return unsignedp ? unsigned_long_long_accum_type_node | |
7468 | : long_long_accum_type_node; | |
7469 | } | |
7470 | ||
7471 | return make_accum_type (size, unsignedp, satp); | |
7472 | } | |
7473 | ||
775e7cc0 | 7474 | /* Create nodes for all integer types (and error_mark_node) using the sizes |
7475 | of C datatypes. The caller should call set_sizetype soon after calling | |
7476 | this function to select one of the types as sizetype. */ | |
9bfff6cb | 7477 | |
775e7cc0 | 7478 | void |
1561d3cd | 7479 | build_common_tree_nodes (bool signed_char, bool signed_sizetype) |
775e7cc0 | 7480 | { |
7481 | error_mark_node = make_node (ERROR_MARK); | |
7482 | TREE_TYPE (error_mark_node) = error_mark_node; | |
7483 | ||
1561d3cd | 7484 | initialize_sizetypes (signed_sizetype); |
902de8ed | 7485 | |
775e7cc0 | 7486 | /* Define both `signed char' and `unsigned char'. */ |
7487 | signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); | |
e026e576 | 7488 | TYPE_STRING_FLAG (signed_char_type_node) = 1; |
775e7cc0 | 7489 | unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); |
e026e576 | 7490 | TYPE_STRING_FLAG (unsigned_char_type_node) = 1; |
775e7cc0 | 7491 | |
7492 | /* Define `char', which is like either `signed char' or `unsigned char' | |
7493 | but not the same as either. */ | |
7494 | char_type_node | |
7495 | = (signed_char | |
7496 | ? make_signed_type (CHAR_TYPE_SIZE) | |
7497 | : make_unsigned_type (CHAR_TYPE_SIZE)); | |
e026e576 | 7498 | TYPE_STRING_FLAG (char_type_node) = 1; |
775e7cc0 | 7499 | |
7500 | short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); | |
7501 | short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); | |
7502 | integer_type_node = make_signed_type (INT_TYPE_SIZE); | |
775e7cc0 | 7503 | unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); |
7504 | long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); | |
7505 | long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); | |
7506 | long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); | |
7507 | long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); | |
7508 | ||
3c2239cf | 7509 | /* Define a boolean type. This type only represents boolean values but |
7510 | may be larger than char depending on the value of BOOL_TYPE_SIZE. | |
7511 | Front ends which want to override this size (i.e. Java) can redefine | |
7512 | boolean_type_node before calling build_common_tree_nodes_2. */ | |
7513 | boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE); | |
7514 | TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE); | |
7016c612 | 7515 | TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1); |
3c2239cf | 7516 | TYPE_PRECISION (boolean_type_node) = 1; |
7517 | ||
8b4b9810 | 7518 | /* Fill in the rest of the sized types. Reuse existing type nodes |
7519 | when possible. */ | |
7520 | intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0); | |
7521 | intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0); | |
7522 | intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0); | |
7523 | intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0); | |
7524 | intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0); | |
7525 | ||
7526 | unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1); | |
7527 | unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1); | |
7528 | unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1); | |
7529 | unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1); | |
7530 | unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1); | |
b27ac6b5 | 7531 | |
2c584053 | 7532 | access_public_node = get_identifier ("public"); |
7533 | access_protected_node = get_identifier ("protected"); | |
7534 | access_private_node = get_identifier ("private"); | |
775e7cc0 | 7535 | } |
7536 | ||
775e7cc0 | 7537 | /* Call this function after calling build_common_tree_nodes and set_sizetype. |
902de8ed | 7538 | It will create several other common tree nodes. */ |
083a2b5e | 7539 | |
775e7cc0 | 7540 | void |
60b8c5b3 | 7541 | build_common_tree_nodes_2 (int short_double) |
775e7cc0 | 7542 | { |
a0c2c45b | 7543 | /* Define these next since types below may used them. */ |
7016c612 | 7544 | integer_zero_node = build_int_cst (NULL_TREE, 0); |
7545 | integer_one_node = build_int_cst (NULL_TREE, 1); | |
7546 | integer_minus_one_node = build_int_cst (NULL_TREE, -1); | |
775e7cc0 | 7547 | |
02e7a332 | 7548 | size_zero_node = size_int (0); |
7549 | size_one_node = size_int (1); | |
7550 | bitsize_zero_node = bitsize_int (0); | |
7551 | bitsize_one_node = bitsize_int (1); | |
7552 | bitsize_unit_node = bitsize_int (BITS_PER_UNIT); | |
775e7cc0 | 7553 | |
3c2239cf | 7554 | boolean_false_node = TYPE_MIN_VALUE (boolean_type_node); |
7555 | boolean_true_node = TYPE_MAX_VALUE (boolean_type_node); | |
7556 | ||
775e7cc0 | 7557 | void_type_node = make_node (VOID_TYPE); |
a0c2c45b | 7558 | layout_type (void_type_node); |
083a2b5e | 7559 | |
775e7cc0 | 7560 | /* We are not going to have real types in C with less than byte alignment, |
7561 | so we might as well not have any types that claim to have it. */ | |
7562 | TYPE_ALIGN (void_type_node) = BITS_PER_UNIT; | |
aca14577 | 7563 | TYPE_USER_ALIGN (void_type_node) = 0; |
775e7cc0 | 7564 | |
7016c612 | 7565 | null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0); |
775e7cc0 | 7566 | layout_type (TREE_TYPE (null_pointer_node)); |
7567 | ||
7568 | ptr_type_node = build_pointer_type (void_type_node); | |
7569 | const_ptr_type_node | |
7570 | = build_pointer_type (build_type_variant (void_type_node, 1, 0)); | |
e256d445 | 7571 | fileptr_type_node = ptr_type_node; |
775e7cc0 | 7572 | |
7573 | float_type_node = make_node (REAL_TYPE); | |
7574 | TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; | |
7575 | layout_type (float_type_node); | |
7576 | ||
7577 | double_type_node = make_node (REAL_TYPE); | |
7578 | if (short_double) | |
7579 | TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; | |
7580 | else | |
7581 | TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; | |
7582 | layout_type (double_type_node); | |
7583 | ||
7584 | long_double_type_node = make_node (REAL_TYPE); | |
7585 | TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; | |
7586 | layout_type (long_double_type_node); | |
7587 | ||
4070bd43 | 7588 | float_ptr_type_node = build_pointer_type (float_type_node); |
7589 | double_ptr_type_node = build_pointer_type (double_type_node); | |
7590 | long_double_ptr_type_node = build_pointer_type (long_double_type_node); | |
7591 | integer_ptr_type_node = build_pointer_type (integer_type_node); | |
7592 | ||
42791117 | 7593 | /* Fixed size integer types. */ |
7594 | uint32_type_node = build_nonstandard_integer_type (32, true); | |
7595 | uint64_type_node = build_nonstandard_integer_type (64, true); | |
7596 | ||
c4503c0a | 7597 | /* Decimal float types. */ |
7598 | dfloat32_type_node = make_node (REAL_TYPE); | |
7599 | TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE; | |
7600 | layout_type (dfloat32_type_node); | |
342ad2d6 | 7601 | SET_TYPE_MODE (dfloat32_type_node, SDmode); |
c4503c0a | 7602 | dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node); |
7603 | ||
7604 | dfloat64_type_node = make_node (REAL_TYPE); | |
7605 | TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE; | |
7606 | layout_type (dfloat64_type_node); | |
342ad2d6 | 7607 | SET_TYPE_MODE (dfloat64_type_node, DDmode); |
c4503c0a | 7608 | dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node); |
7609 | ||
7610 | dfloat128_type_node = make_node (REAL_TYPE); | |
7611 | TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE; | |
7612 | layout_type (dfloat128_type_node); | |
342ad2d6 | 7613 | SET_TYPE_MODE (dfloat128_type_node, TDmode); |
c4503c0a | 7614 | dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node); |
7615 | ||
a024c245 | 7616 | complex_integer_type_node = build_complex_type (integer_type_node); |
7617 | complex_float_type_node = build_complex_type (float_type_node); | |
7618 | complex_double_type_node = build_complex_type (double_type_node); | |
7619 | complex_long_double_type_node = build_complex_type (long_double_type_node); | |
775e7cc0 | 7620 | |
06f0b99c | 7621 | /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */ |
9f92e1a2 | 7622 | #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \ |
7623 | sat_ ## KIND ## _type_node = \ | |
7624 | make_sat_signed_ ## KIND ## _type (SIZE); \ | |
7625 | sat_unsigned_ ## KIND ## _type_node = \ | |
7626 | make_sat_unsigned_ ## KIND ## _type (SIZE); \ | |
7627 | KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \ | |
7628 | unsigned_ ## KIND ## _type_node = \ | |
7629 | make_unsigned_ ## KIND ## _type (SIZE); | |
7630 | ||
7631 | #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \ | |
06f0b99c | 7632 | sat_ ## WIDTH ## KIND ## _type_node = \ |
7633 | make_sat_signed_ ## KIND ## _type (SIZE); \ | |
7634 | sat_unsigned_ ## WIDTH ## KIND ## _type_node = \ | |
7635 | make_sat_unsigned_ ## KIND ## _type (SIZE); \ | |
7636 | WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \ | |
7637 | unsigned_ ## WIDTH ## KIND ## _type_node = \ | |
7638 | make_unsigned_ ## KIND ## _type (SIZE); | |
7639 | ||
7640 | /* Make fixed-point type nodes based on four different widths. */ | |
7641 | #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \ | |
9f92e1a2 | 7642 | MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \ |
7643 | MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \ | |
7644 | MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \ | |
7645 | MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE) | |
06f0b99c | 7646 | |
7647 | /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */ | |
7648 | #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \ | |
7649 | NAME ## _type_node = \ | |
7650 | make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \ | |
7651 | u ## NAME ## _type_node = \ | |
7652 | make_or_reuse_unsigned_ ## KIND ## _type \ | |
7653 | (GET_MODE_BITSIZE (U ## MODE ## mode)); \ | |
7654 | sat_ ## NAME ## _type_node = \ | |
7655 | make_or_reuse_sat_signed_ ## KIND ## _type \ | |
7656 | (GET_MODE_BITSIZE (MODE ## mode)); \ | |
7657 | sat_u ## NAME ## _type_node = \ | |
7658 | make_or_reuse_sat_unsigned_ ## KIND ## _type \ | |
7659 | (GET_MODE_BITSIZE (U ## MODE ## mode)); | |
7660 | ||
7661 | /* Fixed-point type and mode nodes. */ | |
7662 | MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT) | |
7663 | MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM) | |
7664 | MAKE_FIXED_MODE_NODE (fract, qq, QQ) | |
7665 | MAKE_FIXED_MODE_NODE (fract, hq, HQ) | |
7666 | MAKE_FIXED_MODE_NODE (fract, sq, SQ) | |
7667 | MAKE_FIXED_MODE_NODE (fract, dq, DQ) | |
7668 | MAKE_FIXED_MODE_NODE (fract, tq, TQ) | |
7669 | MAKE_FIXED_MODE_NODE (accum, ha, HA) | |
7670 | MAKE_FIXED_MODE_NODE (accum, sa, SA) | |
7671 | MAKE_FIXED_MODE_NODE (accum, da, DA) | |
7672 | MAKE_FIXED_MODE_NODE (accum, ta, TA) | |
7673 | ||
36c543f3 | 7674 | { |
883b2e73 | 7675 | tree t = targetm.build_builtin_va_list (); |
28e67ee6 | 7676 | |
917bbcab | 7677 | /* Many back-ends define record types without setting TYPE_NAME. |
28e67ee6 | 7678 | If we copied the record type here, we'd keep the original |
7679 | record type without a name. This breaks name mangling. So, | |
7680 | don't copy record types and let c_common_nodes_and_builtins() | |
7681 | declare the type to be __builtin_va_list. */ | |
7682 | if (TREE_CODE (t) != RECORD_TYPE) | |
e086912e | 7683 | t = build_variant_type_copy (t); |
6753bca0 | 7684 | |
28e67ee6 | 7685 | va_list_type_node = t; |
36c543f3 | 7686 | } |
88ae7f04 | 7687 | } |
7688 | ||
9cfddb70 | 7689 | /* A subroutine of build_common_builtin_nodes. Define a builtin function. */ |
7690 | ||
7691 | static void | |
7692 | local_define_builtin (const char *name, tree type, enum built_in_function code, | |
7693 | const char *library_name, int ecf_flags) | |
7694 | { | |
7695 | tree decl; | |
7696 | ||
54be5d7e | 7697 | decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL, |
7698 | library_name, NULL_TREE); | |
9cfddb70 | 7699 | if (ecf_flags & ECF_CONST) |
7700 | TREE_READONLY (decl) = 1; | |
7701 | if (ecf_flags & ECF_PURE) | |
9c2a0c05 | 7702 | DECL_PURE_P (decl) = 1; |
7703 | if (ecf_flags & ECF_LOOPING_CONST_OR_PURE) | |
7704 | DECL_LOOPING_CONST_OR_PURE_P (decl) = 1; | |
9cfddb70 | 7705 | if (ecf_flags & ECF_NORETURN) |
7706 | TREE_THIS_VOLATILE (decl) = 1; | |
7707 | if (ecf_flags & ECF_NOTHROW) | |
7708 | TREE_NOTHROW (decl) = 1; | |
7709 | if (ecf_flags & ECF_MALLOC) | |
7710 | DECL_IS_MALLOC (decl) = 1; | |
7711 | ||
7712 | built_in_decls[code] = decl; | |
7713 | implicit_built_in_decls[code] = decl; | |
7714 | } | |
7715 | ||
7716 | /* Call this function after instantiating all builtins that the language | |
7717 | front end cares about. This will build the rest of the builtins that | |
7718 | are relied upon by the tree optimizers and the middle-end. */ | |
7719 | ||
7720 | void | |
7721 | build_common_builtin_nodes (void) | |
7722 | { | |
7723 | tree tmp, ftype; | |
7724 | ||
7725 | if (built_in_decls[BUILT_IN_MEMCPY] == NULL | |
7726 | || built_in_decls[BUILT_IN_MEMMOVE] == NULL) | |
7727 | { | |
7728 | tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); | |
7729 | tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp); | |
7730 | tmp = tree_cons (NULL_TREE, ptr_type_node, tmp); | |
7731 | ftype = build_function_type (ptr_type_node, tmp); | |
7732 | ||
7733 | if (built_in_decls[BUILT_IN_MEMCPY] == NULL) | |
7734 | local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY, | |
7735 | "memcpy", ECF_NOTHROW); | |
7736 | if (built_in_decls[BUILT_IN_MEMMOVE] == NULL) | |
7737 | local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE, | |
7738 | "memmove", ECF_NOTHROW); | |
7739 | } | |
7740 | ||
7741 | if (built_in_decls[BUILT_IN_MEMCMP] == NULL) | |
7742 | { | |
7743 | tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); | |
7744 | tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp); | |
7745 | tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp); | |
a69ced9f | 7746 | ftype = build_function_type (integer_type_node, tmp); |
9cfddb70 | 7747 | local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP, |
7748 | "memcmp", ECF_PURE | ECF_NOTHROW); | |
7749 | } | |
7750 | ||
7751 | if (built_in_decls[BUILT_IN_MEMSET] == NULL) | |
7752 | { | |
7753 | tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); | |
7754 | tmp = tree_cons (NULL_TREE, integer_type_node, tmp); | |
7755 | tmp = tree_cons (NULL_TREE, ptr_type_node, tmp); | |
7756 | ftype = build_function_type (ptr_type_node, tmp); | |
7757 | local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET, | |
7758 | "memset", ECF_NOTHROW); | |
7759 | } | |
7760 | ||
7761 | if (built_in_decls[BUILT_IN_ALLOCA] == NULL) | |
7762 | { | |
7763 | tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); | |
7764 | ftype = build_function_type (ptr_type_node, tmp); | |
7765 | local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA, | |
7766 | "alloca", ECF_NOTHROW | ECF_MALLOC); | |
7767 | } | |
7768 | ||
7769 | tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); | |
7770 | tmp = tree_cons (NULL_TREE, ptr_type_node, tmp); | |
7771 | tmp = tree_cons (NULL_TREE, ptr_type_node, tmp); | |
7772 | ftype = build_function_type (void_type_node, tmp); | |
7773 | local_define_builtin ("__builtin_init_trampoline", ftype, | |
7774 | BUILT_IN_INIT_TRAMPOLINE, | |
7775 | "__builtin_init_trampoline", ECF_NOTHROW); | |
7776 | ||
7777 | tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); | |
7778 | ftype = build_function_type (ptr_type_node, tmp); | |
7779 | local_define_builtin ("__builtin_adjust_trampoline", ftype, | |
7780 | BUILT_IN_ADJUST_TRAMPOLINE, | |
7781 | "__builtin_adjust_trampoline", | |
7782 | ECF_CONST | ECF_NOTHROW); | |
7783 | ||
7784 | tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); | |
7785 | tmp = tree_cons (NULL_TREE, ptr_type_node, tmp); | |
7786 | ftype = build_function_type (void_type_node, tmp); | |
7787 | local_define_builtin ("__builtin_nonlocal_goto", ftype, | |
7788 | BUILT_IN_NONLOCAL_GOTO, | |
7789 | "__builtin_nonlocal_goto", | |
7790 | ECF_NORETURN | ECF_NOTHROW); | |
7791 | ||
2c8a1497 | 7792 | tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); |
7793 | tmp = tree_cons (NULL_TREE, ptr_type_node, tmp); | |
7794 | ftype = build_function_type (void_type_node, tmp); | |
7795 | local_define_builtin ("__builtin_setjmp_setup", ftype, | |
7796 | BUILT_IN_SETJMP_SETUP, | |
7797 | "__builtin_setjmp_setup", ECF_NOTHROW); | |
7798 | ||
7799 | tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); | |
7800 | ftype = build_function_type (ptr_type_node, tmp); | |
7801 | local_define_builtin ("__builtin_setjmp_dispatcher", ftype, | |
7802 | BUILT_IN_SETJMP_DISPATCHER, | |
7803 | "__builtin_setjmp_dispatcher", | |
7804 | ECF_PURE | ECF_NOTHROW); | |
7805 | ||
7806 | tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); | |
7807 | ftype = build_function_type (void_type_node, tmp); | |
7808 | local_define_builtin ("__builtin_setjmp_receiver", ftype, | |
7809 | BUILT_IN_SETJMP_RECEIVER, | |
7810 | "__builtin_setjmp_receiver", ECF_NOTHROW); | |
7811 | ||
9cfddb70 | 7812 | ftype = build_function_type (ptr_type_node, void_list_node); |
7813 | local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE, | |
7814 | "__builtin_stack_save", ECF_NOTHROW); | |
7815 | ||
7816 | tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); | |
7817 | ftype = build_function_type (void_type_node, tmp); | |
7818 | local_define_builtin ("__builtin_stack_restore", ftype, | |
7819 | BUILT_IN_STACK_RESTORE, | |
7820 | "__builtin_stack_restore", ECF_NOTHROW); | |
7821 | ||
7822 | ftype = build_function_type (void_type_node, void_list_node); | |
7823 | local_define_builtin ("__builtin_profile_func_enter", ftype, | |
7824 | BUILT_IN_PROFILE_FUNC_ENTER, "profile_func_enter", 0); | |
7825 | local_define_builtin ("__builtin_profile_func_exit", ftype, | |
7826 | BUILT_IN_PROFILE_FUNC_EXIT, "profile_func_exit", 0); | |
0dfc45b5 | 7827 | |
7828 | /* Complex multiplication and division. These are handled as builtins | |
7829 | rather than optabs because emit_library_call_value doesn't support | |
7830 | complex. Further, we can do slightly better with folding these | |
7831 | beasties if the real and complex parts of the arguments are separate. */ | |
7832 | { | |
7833 | enum machine_mode mode; | |
7834 | ||
7835 | for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode) | |
7836 | { | |
7837 | char mode_name_buf[4], *q; | |
7838 | const char *p; | |
7839 | enum built_in_function mcode, dcode; | |
7840 | tree type, inner_type; | |
7841 | ||
7842 | type = lang_hooks.types.type_for_mode (mode, 0); | |
7843 | if (type == NULL) | |
7844 | continue; | |
7845 | inner_type = TREE_TYPE (type); | |
7846 | ||
7847 | tmp = tree_cons (NULL_TREE, inner_type, void_list_node); | |
7848 | tmp = tree_cons (NULL_TREE, inner_type, tmp); | |
7849 | tmp = tree_cons (NULL_TREE, inner_type, tmp); | |
7850 | tmp = tree_cons (NULL_TREE, inner_type, tmp); | |
7851 | ftype = build_function_type (type, tmp); | |
7852 | ||
7853 | mcode = BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT; | |
7854 | dcode = BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT; | |
7855 | ||
7856 | for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++) | |
7857 | *q = TOLOWER (*p); | |
7858 | *q = '\0'; | |
7859 | ||
7860 | built_in_names[mcode] = concat ("__mul", mode_name_buf, "3", NULL); | |
7861 | local_define_builtin (built_in_names[mcode], ftype, mcode, | |
7862 | built_in_names[mcode], ECF_CONST | ECF_NOTHROW); | |
7863 | ||
7864 | built_in_names[dcode] = concat ("__div", mode_name_buf, "3", NULL); | |
7865 | local_define_builtin (built_in_names[dcode], ftype, dcode, | |
7866 | built_in_names[dcode], ECF_CONST | ECF_NOTHROW); | |
7867 | } | |
7868 | } | |
9cfddb70 | 7869 | } |
7870 | ||
409a160c | 7871 | /* HACK. GROSS. This is absolutely disgusting. I wish there was a |
7872 | better way. | |
7873 | ||
7874 | If we requested a pointer to a vector, build up the pointers that | |
7875 | we stripped off while looking for the inner type. Similarly for | |
7876 | return values from functions. | |
7877 | ||
7878 | The argument TYPE is the top of the chain, and BOTTOM is the | |
7879 | new type which we will point to. */ | |
7880 | ||
7881 | tree | |
7882 | reconstruct_complex_type (tree type, tree bottom) | |
7883 | { | |
7884 | tree inner, outer; | |
86369aa7 | 7885 | |
7886 | if (TREE_CODE (type) == POINTER_TYPE) | |
7887 | { | |
7888 | inner = reconstruct_complex_type (TREE_TYPE (type), bottom); | |
7889 | outer = build_pointer_type_for_mode (inner, TYPE_MODE (type), | |
7890 | TYPE_REF_CAN_ALIAS_ALL (type)); | |
7891 | } | |
7892 | else if (TREE_CODE (type) == REFERENCE_TYPE) | |
409a160c | 7893 | { |
7894 | inner = reconstruct_complex_type (TREE_TYPE (type), bottom); | |
86369aa7 | 7895 | outer = build_reference_type_for_mode (inner, TYPE_MODE (type), |
7896 | TYPE_REF_CAN_ALIAS_ALL (type)); | |
409a160c | 7897 | } |
7898 | else if (TREE_CODE (type) == ARRAY_TYPE) | |
7899 | { | |
7900 | inner = reconstruct_complex_type (TREE_TYPE (type), bottom); | |
7901 | outer = build_array_type (inner, TYPE_DOMAIN (type)); | |
7902 | } | |
7903 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
7904 | { | |
7905 | inner = reconstruct_complex_type (TREE_TYPE (type), bottom); | |
7906 | outer = build_function_type (inner, TYPE_ARG_TYPES (type)); | |
7907 | } | |
7908 | else if (TREE_CODE (type) == METHOD_TYPE) | |
7909 | { | |
7910 | inner = reconstruct_complex_type (TREE_TYPE (type), bottom); | |
c37ff371 | 7911 | /* The build_method_type_directly() routine prepends 'this' to argument list, |
7912 | so we must compensate by getting rid of it. */ | |
3084bb6f | 7913 | outer |
7914 | = build_method_type_directly | |
7915 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))), | |
7916 | inner, | |
7917 | TREE_CHAIN (TYPE_ARG_TYPES (type))); | |
409a160c | 7918 | } |
2cb0e5d9 | 7919 | else if (TREE_CODE (type) == OFFSET_TYPE) |
7920 | { | |
7921 | inner = reconstruct_complex_type (TREE_TYPE (type), bottom); | |
7922 | outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner); | |
7923 | } | |
409a160c | 7924 | else |
7925 | return bottom; | |
7926 | ||
e3c15b04 | 7927 | return build_qualified_type (outer, TYPE_QUALS (type)); |
409a160c | 7928 | } |
7929 | ||
83e2a11b | 7930 | /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and |
7931 | the inner type. */ | |
409a160c | 7932 | tree |
4917c376 | 7933 | build_vector_type_for_mode (tree innertype, enum machine_mode mode) |
88ae7f04 | 7934 | { |
83e2a11b | 7935 | int nunits; |
e19896a4 | 7936 | |
8c0963c4 | 7937 | switch (GET_MODE_CLASS (mode)) |
83e2a11b | 7938 | { |
8c0963c4 | 7939 | case MODE_VECTOR_INT: |
7940 | case MODE_VECTOR_FLOAT: | |
06f0b99c | 7941 | case MODE_VECTOR_FRACT: |
7942 | case MODE_VECTOR_UFRACT: | |
7943 | case MODE_VECTOR_ACCUM: | |
7944 | case MODE_VECTOR_UACCUM: | |
8c0963c4 | 7945 | nunits = GET_MODE_NUNITS (mode); |
7946 | break; | |
7947 | ||
7948 | case MODE_INT: | |
83e2a11b | 7949 | /* Check that there are no leftover bits. */ |
8c0963c4 | 7950 | gcc_assert (GET_MODE_BITSIZE (mode) |
7951 | % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0); | |
4917c376 | 7952 | |
83e2a11b | 7953 | nunits = GET_MODE_BITSIZE (mode) |
7954 | / TREE_INT_CST_LOW (TYPE_SIZE (innertype)); | |
8c0963c4 | 7955 | break; |
7956 | ||
7957 | default: | |
7958 | gcc_unreachable (); | |
83e2a11b | 7959 | } |
4917c376 | 7960 | |
83e2a11b | 7961 | return make_vector_type (innertype, nunits, mode); |
7962 | } | |
4917c376 | 7963 | |
83e2a11b | 7964 | /* Similarly, but takes the inner type and number of units, which must be |
7965 | a power of two. */ | |
7966 | ||
7967 | tree | |
7968 | build_vector_type (tree innertype, int nunits) | |
7969 | { | |
7970 | return make_vector_type (innertype, nunits, VOIDmode); | |
4917c376 | 7971 | } |
7972 | ||
b7d1b569 | 7973 | |
b3f1469f | 7974 | /* Build RESX_EXPR with given REGION_NUMBER. */ |
7975 | tree | |
7976 | build_resx (int region_number) | |
7977 | { | |
7978 | tree t; | |
7979 | t = build1 (RESX_EXPR, void_type_node, | |
7980 | build_int_cst (NULL_TREE, region_number)); | |
7981 | return t; | |
7982 | } | |
7983 | ||
e19896a4 | 7984 | /* Given an initializer INIT, return TRUE if INIT is zero or some |
7985 | aggregate of zeros. Otherwise return FALSE. */ | |
e19896a4 | 7986 | bool |
720082dc | 7987 | initializer_zerop (const_tree init) |
e19896a4 | 7988 | { |
4ee9c684 | 7989 | tree elt; |
7990 | ||
e19896a4 | 7991 | STRIP_NOPS (init); |
7992 | ||
7993 | switch (TREE_CODE (init)) | |
7994 | { | |
7995 | case INTEGER_CST: | |
7996 | return integer_zerop (init); | |
4ee9c684 | 7997 | |
e19896a4 | 7998 | case REAL_CST: |
4ee9c684 | 7999 | /* ??? Note that this is not correct for C4X float formats. There, |
8000 | a bit pattern of all zeros is 1.0; 0.0 is encoded with the most | |
8001 | negative exponent. */ | |
e19896a4 | 8002 | return real_zerop (init) |
8003 | && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)); | |
4ee9c684 | 8004 | |
06f0b99c | 8005 | case FIXED_CST: |
8006 | return fixed_zerop (init); | |
8007 | ||
e19896a4 | 8008 | case COMPLEX_CST: |
8009 | return integer_zerop (init) | |
8010 | || (real_zerop (init) | |
8011 | && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init))) | |
8012 | && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))); | |
4ee9c684 | 8013 | |
8014 | case VECTOR_CST: | |
8015 | for (elt = TREE_VECTOR_CST_ELTS (init); elt; elt = TREE_CHAIN (elt)) | |
8016 | if (!initializer_zerop (TREE_VALUE (elt))) | |
ead47c26 | 8017 | return false; |
4ee9c684 | 8018 | return true; |
ead47c26 | 8019 | |
4ee9c684 | 8020 | case CONSTRUCTOR: |
c75b4594 | 8021 | { |
8022 | unsigned HOST_WIDE_INT idx; | |
4ee9c684 | 8023 | |
c75b4594 | 8024 | FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt) |
8025 | if (!initializer_zerop (elt)) | |
8026 | return false; | |
8027 | return true; | |
8028 | } | |
4ee9c684 | 8029 | |
e19896a4 | 8030 | default: |
8031 | return false; | |
8032 | } | |
8033 | } | |
1f3233d1 | 8034 | |
4ee9c684 | 8035 | /* Build an empty statement. */ |
8036 | ||
8037 | tree | |
8038 | build_empty_stmt (void) | |
8039 | { | |
8040 | return build1 (NOP_EXPR, void_type_node, size_zero_node); | |
8041 | } | |
8042 | ||
4ee9c684 | 8043 | |
55d6e7cd | 8044 | /* Build an OpenMP clause with code CODE. */ |
8045 | ||
8046 | tree | |
8047 | build_omp_clause (enum omp_clause_code code) | |
8048 | { | |
8049 | tree t; | |
8050 | int size, length; | |
8051 | ||
8052 | length = omp_clause_num_ops[code]; | |
8053 | size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree)); | |
8054 | ||
45ba1503 | 8055 | t = GGC_NEWVAR (union tree_node, size); |
55d6e7cd | 8056 | memset (t, 0, size); |
8057 | TREE_SET_CODE (t, OMP_CLAUSE); | |
8058 | OMP_CLAUSE_SET_CODE (t, code); | |
8059 | ||
8060 | #ifdef GATHER_STATISTICS | |
8061 | tree_node_counts[(int) omp_clause_kind]++; | |
8062 | tree_node_sizes[(int) omp_clause_kind] += size; | |
8063 | #endif | |
8064 | ||
8065 | return t; | |
8066 | } | |
8067 | ||
c2f47e15 | 8068 | /* Set various status flags when building a CALL_EXPR object T. */ |
8069 | ||
8070 | static void | |
8071 | process_call_operands (tree t) | |
8072 | { | |
8073 | bool side_effects; | |
8074 | ||
8075 | side_effects = TREE_SIDE_EFFECTS (t); | |
8076 | if (!side_effects) | |
8077 | { | |
8078 | int i, n; | |
8079 | n = TREE_OPERAND_LENGTH (t); | |
8080 | for (i = 1; i < n; i++) | |
8081 | { | |
8082 | tree op = TREE_OPERAND (t, i); | |
8083 | if (op && TREE_SIDE_EFFECTS (op)) | |
8084 | { | |
8085 | side_effects = 1; | |
8086 | break; | |
8087 | } | |
8088 | } | |
8089 | } | |
8090 | if (!side_effects) | |
8091 | { | |
8092 | int i; | |
8093 | ||
8094 | /* Calls have side-effects, except those to const or | |
8095 | pure functions. */ | |
8096 | i = call_expr_flags (t); | |
9c2a0c05 | 8097 | if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE))) |
c2f47e15 | 8098 | side_effects = 1; |
8099 | } | |
8100 | TREE_SIDE_EFFECTS (t) = side_effects; | |
8101 | } | |
8102 | ||
8103 | /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN | |
8104 | includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1. | |
8105 | Except for the CODE and operand count field, other storage for the | |
8106 | object is initialized to zeros. */ | |
8107 | ||
8108 | tree | |
8109 | build_vl_exp_stat (enum tree_code code, int len MEM_STAT_DECL) | |
8110 | { | |
8111 | tree t; | |
8112 | int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp); | |
8113 | ||
8114 | gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp); | |
8115 | gcc_assert (len >= 1); | |
8116 | ||
8117 | #ifdef GATHER_STATISTICS | |
8118 | tree_node_counts[(int) e_kind]++; | |
8119 | tree_node_sizes[(int) e_kind] += length; | |
8120 | #endif | |
8121 | ||
45ba1503 | 8122 | t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); |
c2f47e15 | 8123 | |
8124 | memset (t, 0, length); | |
8125 | ||
8126 | TREE_SET_CODE (t, code); | |
8127 | ||
8128 | /* Can't use TREE_OPERAND to store the length because if checking is | |
8129 | enabled, it will try to check the length before we store it. :-P */ | |
8130 | t->exp.operands[0] = build_int_cst (sizetype, len); | |
8131 | ||
8132 | return t; | |
8133 | } | |
8134 | ||
8135 | ||
8136 | /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE | |
8137 | and FN and a null static chain slot. ARGLIST is a TREE_LIST of the | |
8138 | arguments. */ | |
8139 | ||
8140 | tree | |
8141 | build_call_list (tree return_type, tree fn, tree arglist) | |
8142 | { | |
8143 | tree t; | |
8144 | int i; | |
8145 | ||
8146 | t = build_vl_exp (CALL_EXPR, list_length (arglist) + 3); | |
8147 | TREE_TYPE (t) = return_type; | |
8148 | CALL_EXPR_FN (t) = fn; | |
8149 | CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE; | |
8150 | for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++) | |
8151 | CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist); | |
8152 | process_call_operands (t); | |
8153 | return t; | |
8154 | } | |
8155 | ||
8156 | /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and | |
8157 | FN and a null static chain slot. NARGS is the number of call arguments | |
8158 | which are specified as "..." arguments. */ | |
8159 | ||
8160 | tree | |
8161 | build_call_nary (tree return_type, tree fn, int nargs, ...) | |
8162 | { | |
8163 | tree ret; | |
8164 | va_list args; | |
8165 | va_start (args, nargs); | |
8166 | ret = build_call_valist (return_type, fn, nargs, args); | |
8167 | va_end (args); | |
8168 | return ret; | |
8169 | } | |
8170 | ||
8171 | /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and | |
8172 | FN and a null static chain slot. NARGS is the number of call arguments | |
8173 | which are specified as a va_list ARGS. */ | |
8174 | ||
8175 | tree | |
8176 | build_call_valist (tree return_type, tree fn, int nargs, va_list args) | |
8177 | { | |
8178 | tree t; | |
8179 | int i; | |
8180 | ||
8181 | t = build_vl_exp (CALL_EXPR, nargs + 3); | |
8182 | TREE_TYPE (t) = return_type; | |
8183 | CALL_EXPR_FN (t) = fn; | |
8184 | CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE; | |
8185 | for (i = 0; i < nargs; i++) | |
8186 | CALL_EXPR_ARG (t, i) = va_arg (args, tree); | |
8187 | process_call_operands (t); | |
8188 | return t; | |
8189 | } | |
8190 | ||
8191 | /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and | |
8192 | FN and a null static chain slot. NARGS is the number of call arguments | |
8193 | which are specified as a tree array ARGS. */ | |
8194 | ||
8195 | tree | |
8196 | build_call_array (tree return_type, tree fn, int nargs, tree *args) | |
8197 | { | |
8198 | tree t; | |
8199 | int i; | |
8200 | ||
8201 | t = build_vl_exp (CALL_EXPR, nargs + 3); | |
8202 | TREE_TYPE (t) = return_type; | |
8203 | CALL_EXPR_FN (t) = fn; | |
8204 | CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE; | |
8205 | for (i = 0; i < nargs; i++) | |
8206 | CALL_EXPR_ARG (t, i) = args[i]; | |
8207 | process_call_operands (t); | |
8208 | return t; | |
8209 | } | |
8210 | ||
55d6e7cd | 8211 | |
7d23383d | 8212 | /* Returns true if it is possible to prove that the index of |
8213 | an array access REF (an ARRAY_REF expression) falls into the | |
8214 | array bounds. */ | |
8215 | ||
8216 | bool | |
8217 | in_array_bounds_p (tree ref) | |
8218 | { | |
8219 | tree idx = TREE_OPERAND (ref, 1); | |
8220 | tree min, max; | |
8221 | ||
8222 | if (TREE_CODE (idx) != INTEGER_CST) | |
8223 | return false; | |
b27ac6b5 | 8224 | |
7d23383d | 8225 | min = array_ref_low_bound (ref); |
8226 | max = array_ref_up_bound (ref); | |
8227 | if (!min | |
8228 | || !max | |
8229 | || TREE_CODE (min) != INTEGER_CST | |
8230 | || TREE_CODE (max) != INTEGER_CST) | |
8231 | return false; | |
8232 | ||
8233 | if (tree_int_cst_lt (idx, min) | |
8234 | || tree_int_cst_lt (max, idx)) | |
8235 | return false; | |
8236 | ||
8237 | return true; | |
8238 | } | |
8239 | ||
2100c228 | 8240 | /* Returns true if it is possible to prove that the range of |
8241 | an array access REF (an ARRAY_RANGE_REF expression) falls | |
8242 | into the array bounds. */ | |
8243 | ||
8244 | bool | |
8245 | range_in_array_bounds_p (tree ref) | |
8246 | { | |
8247 | tree domain_type = TYPE_DOMAIN (TREE_TYPE (ref)); | |
8248 | tree range_min, range_max, min, max; | |
8249 | ||
8250 | range_min = TYPE_MIN_VALUE (domain_type); | |
8251 | range_max = TYPE_MAX_VALUE (domain_type); | |
8252 | if (!range_min | |
8253 | || !range_max | |
8254 | || TREE_CODE (range_min) != INTEGER_CST | |
8255 | || TREE_CODE (range_max) != INTEGER_CST) | |
8256 | return false; | |
8257 | ||
8258 | min = array_ref_low_bound (ref); | |
8259 | max = array_ref_up_bound (ref); | |
8260 | if (!min | |
8261 | || !max | |
8262 | || TREE_CODE (min) != INTEGER_CST | |
8263 | || TREE_CODE (max) != INTEGER_CST) | |
8264 | return false; | |
8265 | ||
8266 | if (tree_int_cst_lt (range_min, min) | |
8267 | || tree_int_cst_lt (max, range_max)) | |
8268 | return false; | |
8269 | ||
8270 | return true; | |
8271 | } | |
8272 | ||
4ee9c684 | 8273 | /* Return true if T (assumed to be a DECL) must be assigned a memory |
8274 | location. */ | |
8275 | ||
8276 | bool | |
fb80456a | 8277 | needs_to_live_in_memory (const_tree t) |
4ee9c684 | 8278 | { |
de6ed584 | 8279 | if (TREE_CODE (t) == SSA_NAME) |
8280 | t = SSA_NAME_VAR (t); | |
8281 | ||
2ce91ad7 | 8282 | return (TREE_ADDRESSABLE (t) |
8283 | || is_global_var (t) | |
4ee9c684 | 8284 | || (TREE_CODE (t) == RESULT_DECL |
94e6573f | 8285 | && aggregate_value_p (t, current_function_decl))); |
4ee9c684 | 8286 | } |
8287 | ||
504d3463 | 8288 | /* There are situations in which a language considers record types |
8289 | compatible which have different field lists. Decide if two fields | |
8290 | are compatible. It is assumed that the parent records are compatible. */ | |
8291 | ||
8292 | bool | |
5d1b319b | 8293 | fields_compatible_p (const_tree f1, const_tree f2) |
504d3463 | 8294 | { |
8295 | if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1), | |
8296 | DECL_FIELD_BIT_OFFSET (f2), OEP_ONLY_CONST)) | |
8297 | return false; | |
8298 | ||
8299 | if (!operand_equal_p (DECL_FIELD_OFFSET (f1), | |
8300 | DECL_FIELD_OFFSET (f2), OEP_ONLY_CONST)) | |
8301 | return false; | |
8302 | ||
c8ca3ee7 | 8303 | if (!types_compatible_p (TREE_TYPE (f1), TREE_TYPE (f2))) |
b27ac6b5 | 8304 | return false; |
504d3463 | 8305 | |
8306 | return true; | |
8307 | } | |
8308 | ||
8309 | /* Locate within RECORD a field that is compatible with ORIG_FIELD. */ | |
8310 | ||
8311 | tree | |
8312 | find_compatible_field (tree record, tree orig_field) | |
8313 | { | |
8314 | tree f; | |
8315 | ||
8316 | for (f = TYPE_FIELDS (record); f ; f = TREE_CHAIN (f)) | |
8317 | if (TREE_CODE (f) == FIELD_DECL | |
8318 | && fields_compatible_p (f, orig_field)) | |
8319 | return f; | |
8320 | ||
8321 | /* ??? Why isn't this on the main fields list? */ | |
8322 | f = TYPE_VFIELD (record); | |
8323 | if (f && TREE_CODE (f) == FIELD_DECL | |
8324 | && fields_compatible_p (f, orig_field)) | |
8325 | return f; | |
8326 | ||
8327 | /* ??? We should abort here, but Java appears to do Bad Things | |
8328 | with inherited fields. */ | |
8329 | return orig_field; | |
8330 | } | |
8331 | ||
c782188f | 8332 | /* Return value of a constant X and sign-extend it. */ |
2146e26d | 8333 | |
8334 | HOST_WIDE_INT | |
720082dc | 8335 | int_cst_value (const_tree x) |
2146e26d | 8336 | { |
8337 | unsigned bits = TYPE_PRECISION (TREE_TYPE (x)); | |
8338 | unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x); | |
2146e26d | 8339 | |
c782188f | 8340 | /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */ |
8341 | gcc_assert (TREE_INT_CST_HIGH (x) == 0 | |
8342 | || TREE_INT_CST_HIGH (x) == -1); | |
2146e26d | 8343 | |
c782188f | 8344 | if (bits < HOST_BITS_PER_WIDE_INT) |
8345 | { | |
8346 | bool negative = ((val >> (bits - 1)) & 1) != 0; | |
8347 | if (negative) | |
8348 | val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1; | |
8349 | else | |
8350 | val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1); | |
8351 | } | |
2146e26d | 8352 | |
8353 | return val; | |
8354 | } | |
8355 | ||
11773141 | 8356 | /* If TYPE is an integral type, return an equivalent type which is |
8357 | unsigned iff UNSIGNEDP is true. If TYPE is not an integral type, | |
8358 | return TYPE itself. */ | |
504d3463 | 8359 | |
11773141 | 8360 | tree |
8361 | signed_or_unsigned_type_for (int unsignedp, tree type) | |
71eea85c | 8362 | { |
11773141 | 8363 | tree t = type; |
8364 | if (POINTER_TYPE_P (type)) | |
8365 | t = size_type_node; | |
8366 | ||
8367 | if (!INTEGRAL_TYPE_P (t) || TYPE_UNSIGNED (t) == unsignedp) | |
8368 | return t; | |
8369 | ||
8370 | return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp); | |
71eea85c | 8371 | } |
8372 | ||
dbc64c75 | 8373 | /* Returns unsigned variant of TYPE. */ |
8374 | ||
8375 | tree | |
8376 | unsigned_type_for (tree type) | |
8377 | { | |
11773141 | 8378 | return signed_or_unsigned_type_for (1, type); |
dbc64c75 | 8379 | } |
8380 | ||
8381 | /* Returns signed variant of TYPE. */ | |
8382 | ||
8383 | tree | |
8384 | signed_type_for (tree type) | |
8385 | { | |
11773141 | 8386 | return signed_or_unsigned_type_for (0, type); |
dbc64c75 | 8387 | } |
8388 | ||
faab57e3 | 8389 | /* Returns the largest value obtainable by casting something in INNER type to |
8390 | OUTER type. */ | |
8391 | ||
8392 | tree | |
8393 | upper_bound_in_type (tree outer, tree inner) | |
8394 | { | |
8395 | unsigned HOST_WIDE_INT lo, hi; | |
59653f01 | 8396 | unsigned int det = 0; |
8397 | unsigned oprec = TYPE_PRECISION (outer); | |
8398 | unsigned iprec = TYPE_PRECISION (inner); | |
8399 | unsigned prec; | |
8400 | ||
8401 | /* Compute a unique number for every combination. */ | |
8402 | det |= (oprec > iprec) ? 4 : 0; | |
8403 | det |= TYPE_UNSIGNED (outer) ? 2 : 0; | |
8404 | det |= TYPE_UNSIGNED (inner) ? 1 : 0; | |
8405 | ||
8406 | /* Determine the exponent to use. */ | |
8407 | switch (det) | |
8408 | { | |
8409 | case 0: | |
8410 | case 1: | |
8411 | /* oprec <= iprec, outer: signed, inner: don't care. */ | |
8412 | prec = oprec - 1; | |
8413 | break; | |
8414 | case 2: | |
8415 | case 3: | |
8416 | /* oprec <= iprec, outer: unsigned, inner: don't care. */ | |
8417 | prec = oprec; | |
8418 | break; | |
8419 | case 4: | |
8420 | /* oprec > iprec, outer: signed, inner: signed. */ | |
8421 | prec = iprec - 1; | |
8422 | break; | |
8423 | case 5: | |
8424 | /* oprec > iprec, outer: signed, inner: unsigned. */ | |
8425 | prec = iprec; | |
8426 | break; | |
8427 | case 6: | |
8428 | /* oprec > iprec, outer: unsigned, inner: signed. */ | |
8429 | prec = oprec; | |
8430 | break; | |
8431 | case 7: | |
8432 | /* oprec > iprec, outer: unsigned, inner: unsigned. */ | |
8433 | prec = iprec; | |
8434 | break; | |
8435 | default: | |
8436 | gcc_unreachable (); | |
8437 | } | |
faab57e3 | 8438 | |
59653f01 | 8439 | /* Compute 2^^prec - 1. */ |
8440 | if (prec <= HOST_BITS_PER_WIDE_INT) | |
faab57e3 | 8441 | { |
59653f01 | 8442 | hi = 0; |
8443 | lo = ((~(unsigned HOST_WIDE_INT) 0) | |
8444 | >> (HOST_BITS_PER_WIDE_INT - prec)); | |
faab57e3 | 8445 | } |
8446 | else | |
8447 | { | |
59653f01 | 8448 | hi = ((~(unsigned HOST_WIDE_INT) 0) |
8449 | >> (2 * HOST_BITS_PER_WIDE_INT - prec)); | |
8450 | lo = ~(unsigned HOST_WIDE_INT) 0; | |
faab57e3 | 8451 | } |
8452 | ||
59653f01 | 8453 | return build_int_cst_wide (outer, lo, hi); |
faab57e3 | 8454 | } |
8455 | ||
8456 | /* Returns the smallest value obtainable by casting something in INNER type to | |
8457 | OUTER type. */ | |
8458 | ||
8459 | tree | |
8460 | lower_bound_in_type (tree outer, tree inner) | |
8461 | { | |
8462 | unsigned HOST_WIDE_INT lo, hi; | |
59653f01 | 8463 | unsigned oprec = TYPE_PRECISION (outer); |
8464 | unsigned iprec = TYPE_PRECISION (inner); | |
8465 | ||
8466 | /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type | |
8467 | and obtain 0. */ | |
8468 | if (TYPE_UNSIGNED (outer) | |
8469 | /* If we are widening something of an unsigned type, OUTER type | |
8470 | contains all values of INNER type. In particular, both INNER | |
8471 | and OUTER types have zero in common. */ | |
8472 | || (oprec > iprec && TYPE_UNSIGNED (inner))) | |
faab57e3 | 8473 | lo = hi = 0; |
faab57e3 | 8474 | else |
8475 | { | |
59653f01 | 8476 | /* If we are widening a signed type to another signed type, we |
8477 | want to obtain -2^^(iprec-1). If we are keeping the | |
8478 | precision or narrowing to a signed type, we want to obtain | |
8479 | -2^(oprec-1). */ | |
8480 | unsigned prec = oprec > iprec ? iprec : oprec; | |
8481 | ||
8482 | if (prec <= HOST_BITS_PER_WIDE_INT) | |
8483 | { | |
8484 | hi = ~(unsigned HOST_WIDE_INT) 0; | |
8485 | lo = (~(unsigned HOST_WIDE_INT) 0) << (prec - 1); | |
8486 | } | |
8487 | else | |
8488 | { | |
8489 | hi = ((~(unsigned HOST_WIDE_INT) 0) | |
8490 | << (prec - HOST_BITS_PER_WIDE_INT - 1)); | |
8491 | lo = 0; | |
8492 | } | |
faab57e3 | 8493 | } |
8494 | ||
59653f01 | 8495 | return build_int_cst_wide (outer, lo, hi); |
faab57e3 | 8496 | } |
8497 | ||
5373158f | 8498 | /* Return nonzero if two operands that are suitable for PHI nodes are |
8499 | necessarily equal. Specifically, both ARG0 and ARG1 must be either | |
8500 | SSA_NAME or invariant. Note that this is strictly an optimization. | |
8501 | That is, callers of this function can directly call operand_equal_p | |
8502 | and get the same result, only slower. */ | |
8503 | ||
8504 | int | |
b7bf20db | 8505 | operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1) |
5373158f | 8506 | { |
8507 | if (arg0 == arg1) | |
8508 | return 1; | |
8509 | if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME) | |
8510 | return 0; | |
8511 | return operand_equal_p (arg0, arg1, 0); | |
8512 | } | |
8513 | ||
b091dc59 | 8514 | /* Returns number of zeros at the end of binary representation of X. |
8515 | ||
8516 | ??? Use ffs if available? */ | |
8517 | ||
8518 | tree | |
720082dc | 8519 | num_ending_zeros (const_tree x) |
b091dc59 | 8520 | { |
8521 | unsigned HOST_WIDE_INT fr, nfr; | |
8522 | unsigned num, abits; | |
8523 | tree type = TREE_TYPE (x); | |
8524 | ||
8525 | if (TREE_INT_CST_LOW (x) == 0) | |
8526 | { | |
8527 | num = HOST_BITS_PER_WIDE_INT; | |
8528 | fr = TREE_INT_CST_HIGH (x); | |
8529 | } | |
8530 | else | |
8531 | { | |
8532 | num = 0; | |
8533 | fr = TREE_INT_CST_LOW (x); | |
8534 | } | |
8535 | ||
8536 | for (abits = HOST_BITS_PER_WIDE_INT / 2; abits; abits /= 2) | |
8537 | { | |
8538 | nfr = fr >> abits; | |
8539 | if (nfr << abits == fr) | |
8540 | { | |
8541 | num += abits; | |
8542 | fr = nfr; | |
8543 | } | |
8544 | } | |
8545 | ||
8546 | if (num > TYPE_PRECISION (type)) | |
8547 | num = TYPE_PRECISION (type); | |
8548 | ||
8549 | return build_int_cst_type (type, num); | |
8550 | } | |
8551 | ||
98f8a662 | 8552 | |
8553 | #define WALK_SUBTREE(NODE) \ | |
8554 | do \ | |
8555 | { \ | |
20a8f962 | 8556 | result = walk_tree_1 (&(NODE), func, data, pset, lh); \ |
98f8a662 | 8557 | if (result) \ |
8558 | return result; \ | |
8559 | } \ | |
8560 | while (0) | |
8561 | ||
8562 | /* This is a subroutine of walk_tree that walks field of TYPE that are to | |
8563 | be walked whenever a type is seen in the tree. Rest of operands and return | |
8564 | value are as for walk_tree. */ | |
8565 | ||
8566 | static tree | |
8567 | walk_type_fields (tree type, walk_tree_fn func, void *data, | |
20a8f962 | 8568 | struct pointer_set_t *pset, walk_tree_lh lh) |
98f8a662 | 8569 | { |
8570 | tree result = NULL_TREE; | |
8571 | ||
8572 | switch (TREE_CODE (type)) | |
8573 | { | |
8574 | case POINTER_TYPE: | |
8575 | case REFERENCE_TYPE: | |
8576 | /* We have to worry about mutually recursive pointers. These can't | |
8577 | be written in C. They can in Ada. It's pathological, but | |
8578 | there's an ACATS test (c38102a) that checks it. Deal with this | |
8579 | by checking if we're pointing to another pointer, that one | |
8580 | points to another pointer, that one does too, and we have no htab. | |
8581 | If so, get a hash table. We check three levels deep to avoid | |
8582 | the cost of the hash table if we don't need one. */ | |
8583 | if (POINTER_TYPE_P (TREE_TYPE (type)) | |
8584 | && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type))) | |
8585 | && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type)))) | |
8586 | && !pset) | |
8587 | { | |
8588 | result = walk_tree_without_duplicates (&TREE_TYPE (type), | |
8589 | func, data); | |
8590 | if (result) | |
8591 | return result; | |
8592 | ||
8593 | break; | |
8594 | } | |
8595 | ||
8596 | /* ... fall through ... */ | |
8597 | ||
8598 | case COMPLEX_TYPE: | |
8599 | WALK_SUBTREE (TREE_TYPE (type)); | |
8600 | break; | |
8601 | ||
8602 | case METHOD_TYPE: | |
8603 | WALK_SUBTREE (TYPE_METHOD_BASETYPE (type)); | |
8604 | ||
8605 | /* Fall through. */ | |
8606 | ||
8607 | case FUNCTION_TYPE: | |
8608 | WALK_SUBTREE (TREE_TYPE (type)); | |
8609 | { | |
8610 | tree arg; | |
8611 | ||
8612 | /* We never want to walk into default arguments. */ | |
8613 | for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg)) | |
8614 | WALK_SUBTREE (TREE_VALUE (arg)); | |
8615 | } | |
8616 | break; | |
8617 | ||
8618 | case ARRAY_TYPE: | |
6783c055 | 8619 | /* Don't follow this nodes's type if a pointer for fear that |
8620 | we'll have infinite recursion. If we have a PSET, then we | |
8621 | need not fear. */ | |
8622 | if (pset | |
8623 | || (!POINTER_TYPE_P (TREE_TYPE (type)) | |
8624 | && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE)) | |
98f8a662 | 8625 | WALK_SUBTREE (TREE_TYPE (type)); |
8626 | WALK_SUBTREE (TYPE_DOMAIN (type)); | |
8627 | break; | |
8628 | ||
98f8a662 | 8629 | case OFFSET_TYPE: |
8630 | WALK_SUBTREE (TREE_TYPE (type)); | |
8631 | WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type)); | |
8632 | break; | |
8633 | ||
8634 | default: | |
8635 | break; | |
8636 | } | |
8637 | ||
8638 | return NULL_TREE; | |
8639 | } | |
8640 | ||
8641 | /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is | |
8642 | called with the DATA and the address of each sub-tree. If FUNC returns a | |
1fa3a8f6 | 8643 | non-NULL value, the traversal is stopped, and the value returned by FUNC |
98f8a662 | 8644 | is returned. If PSET is non-NULL it is used to record the nodes visited, |
8645 | and to avoid visiting a node more than once. */ | |
8646 | ||
8647 | tree | |
20a8f962 | 8648 | walk_tree_1 (tree *tp, walk_tree_fn func, void *data, |
8649 | struct pointer_set_t *pset, walk_tree_lh lh) | |
98f8a662 | 8650 | { |
8651 | enum tree_code code; | |
8652 | int walk_subtrees; | |
8653 | tree result; | |
8654 | ||
8655 | #define WALK_SUBTREE_TAIL(NODE) \ | |
8656 | do \ | |
8657 | { \ | |
8658 | tp = & (NODE); \ | |
8659 | goto tail_recurse; \ | |
8660 | } \ | |
8661 | while (0) | |
8662 | ||
8663 | tail_recurse: | |
8664 | /* Skip empty subtrees. */ | |
8665 | if (!*tp) | |
8666 | return NULL_TREE; | |
8667 | ||
8668 | /* Don't walk the same tree twice, if the user has requested | |
8669 | that we avoid doing so. */ | |
8670 | if (pset && pointer_set_insert (pset, *tp)) | |
8671 | return NULL_TREE; | |
8672 | ||
8673 | /* Call the function. */ | |
8674 | walk_subtrees = 1; | |
8675 | result = (*func) (tp, &walk_subtrees, data); | |
8676 | ||
8677 | /* If we found something, return it. */ | |
8678 | if (result) | |
8679 | return result; | |
8680 | ||
8681 | code = TREE_CODE (*tp); | |
8682 | ||
8683 | /* Even if we didn't, FUNC may have decided that there was nothing | |
8684 | interesting below this point in the tree. */ | |
8685 | if (!walk_subtrees) | |
8686 | { | |
1e8e9920 | 8687 | /* But we still need to check our siblings. */ |
98f8a662 | 8688 | if (code == TREE_LIST) |
98f8a662 | 8689 | WALK_SUBTREE_TAIL (TREE_CHAIN (*tp)); |
55d6e7cd | 8690 | else if (code == OMP_CLAUSE) |
1e8e9920 | 8691 | WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp)); |
98f8a662 | 8692 | else |
8693 | return NULL_TREE; | |
8694 | } | |
8695 | ||
20a8f962 | 8696 | if (lh) |
8697 | { | |
8698 | result = (*lh) (tp, &walk_subtrees, func, data, pset); | |
8699 | if (result || !walk_subtrees) | |
8700 | return result; | |
8701 | } | |
98f8a662 | 8702 | |
1e8e9920 | 8703 | switch (code) |
98f8a662 | 8704 | { |
1e8e9920 | 8705 | case ERROR_MARK: |
8706 | case IDENTIFIER_NODE: | |
8707 | case INTEGER_CST: | |
8708 | case REAL_CST: | |
06f0b99c | 8709 | case FIXED_CST: |
1e8e9920 | 8710 | case VECTOR_CST: |
8711 | case STRING_CST: | |
8712 | case BLOCK: | |
8713 | case PLACEHOLDER_EXPR: | |
8714 | case SSA_NAME: | |
8715 | case FIELD_DECL: | |
8716 | case RESULT_DECL: | |
8717 | /* None of these have subtrees other than those already walked | |
8718 | above. */ | |
8719 | break; | |
98f8a662 | 8720 | |
1e8e9920 | 8721 | case TREE_LIST: |
8722 | WALK_SUBTREE (TREE_VALUE (*tp)); | |
8723 | WALK_SUBTREE_TAIL (TREE_CHAIN (*tp)); | |
8724 | break; | |
98f8a662 | 8725 | |
1e8e9920 | 8726 | case TREE_VEC: |
8727 | { | |
8728 | int len = TREE_VEC_LENGTH (*tp); | |
98f8a662 | 8729 | |
1e8e9920 | 8730 | if (len == 0) |
8731 | break; | |
98f8a662 | 8732 | |
1e8e9920 | 8733 | /* Walk all elements but the first. */ |
8734 | while (--len) | |
8735 | WALK_SUBTREE (TREE_VEC_ELT (*tp, len)); | |
98f8a662 | 8736 | |
1e8e9920 | 8737 | /* Now walk the first one as a tail call. */ |
8738 | WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0)); | |
8739 | } | |
98f8a662 | 8740 | |
1e8e9920 | 8741 | case COMPLEX_CST: |
8742 | WALK_SUBTREE (TREE_REALPART (*tp)); | |
8743 | WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp)); | |
98f8a662 | 8744 | |
1e8e9920 | 8745 | case CONSTRUCTOR: |
8746 | { | |
8747 | unsigned HOST_WIDE_INT idx; | |
8748 | constructor_elt *ce; | |
98f8a662 | 8749 | |
1e8e9920 | 8750 | for (idx = 0; |
8751 | VEC_iterate(constructor_elt, CONSTRUCTOR_ELTS (*tp), idx, ce); | |
8752 | idx++) | |
8753 | WALK_SUBTREE (ce->value); | |
8754 | } | |
8755 | break; | |
98f8a662 | 8756 | |
1e8e9920 | 8757 | case SAVE_EXPR: |
8758 | WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 0)); | |
98f8a662 | 8759 | |
1e8e9920 | 8760 | case BIND_EXPR: |
8761 | { | |
8762 | tree decl; | |
8763 | for (decl = BIND_EXPR_VARS (*tp); decl; decl = TREE_CHAIN (decl)) | |
98f8a662 | 8764 | { |
1e8e9920 | 8765 | /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk |
8766 | into declarations that are just mentioned, rather than | |
8767 | declared; they don't really belong to this part of the tree. | |
8768 | And, we can see cycles: the initializer for a declaration | |
8769 | can refer to the declaration itself. */ | |
8770 | WALK_SUBTREE (DECL_INITIAL (decl)); | |
8771 | WALK_SUBTREE (DECL_SIZE (decl)); | |
8772 | WALK_SUBTREE (DECL_SIZE_UNIT (decl)); | |
8773 | } | |
8774 | WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp)); | |
8775 | } | |
98f8a662 | 8776 | |
1e8e9920 | 8777 | case STATEMENT_LIST: |
8778 | { | |
8779 | tree_stmt_iterator i; | |
8780 | for (i = tsi_start (*tp); !tsi_end_p (i); tsi_next (&i)) | |
8781 | WALK_SUBTREE (*tsi_stmt_ptr (i)); | |
8782 | } | |
8783 | break; | |
98f8a662 | 8784 | |
55d6e7cd | 8785 | case OMP_CLAUSE: |
8786 | switch (OMP_CLAUSE_CODE (*tp)) | |
8787 | { | |
8788 | case OMP_CLAUSE_PRIVATE: | |
8789 | case OMP_CLAUSE_SHARED: | |
8790 | case OMP_CLAUSE_FIRSTPRIVATE: | |
55d6e7cd | 8791 | case OMP_CLAUSE_COPYIN: |
8792 | case OMP_CLAUSE_COPYPRIVATE: | |
8793 | case OMP_CLAUSE_IF: | |
8794 | case OMP_CLAUSE_NUM_THREADS: | |
8795 | case OMP_CLAUSE_SCHEDULE: | |
8796 | WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, 0)); | |
8797 | /* FALLTHRU */ | |
8798 | ||
8799 | case OMP_CLAUSE_NOWAIT: | |
8800 | case OMP_CLAUSE_ORDERED: | |
8801 | case OMP_CLAUSE_DEFAULT: | |
fd6481cf | 8802 | case OMP_CLAUSE_UNTIED: |
55d6e7cd | 8803 | WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp)); |
8804 | ||
fd6481cf | 8805 | case OMP_CLAUSE_LASTPRIVATE: |
8806 | WALK_SUBTREE (OMP_CLAUSE_DECL (*tp)); | |
8807 | WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp)); | |
8808 | WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp)); | |
8809 | ||
8810 | case OMP_CLAUSE_COLLAPSE: | |
8811 | { | |
8812 | int i; | |
8813 | for (i = 0; i < 3; i++) | |
8814 | WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i)); | |
8815 | WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp)); | |
8816 | } | |
8817 | ||
55d6e7cd | 8818 | case OMP_CLAUSE_REDUCTION: |
8819 | { | |
8820 | int i; | |
8821 | for (i = 0; i < 4; i++) | |
8822 | WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i)); | |
8823 | WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp)); | |
8824 | } | |
8825 | ||
8826 | default: | |
8827 | gcc_unreachable (); | |
8828 | } | |
8829 | break; | |
98f8a662 | 8830 | |
1e8e9920 | 8831 | case TARGET_EXPR: |
8832 | { | |
8833 | int i, len; | |
8834 | ||
8835 | /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same. | |
8836 | But, we only want to walk once. */ | |
8837 | len = (TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1)) ? 2 : 3; | |
8838 | for (i = 0; i < len; ++i) | |
8839 | WALK_SUBTREE (TREE_OPERAND (*tp, i)); | |
8840 | WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len)); | |
8841 | } | |
98f8a662 | 8842 | |
75a70cf9 | 8843 | case CHANGE_DYNAMIC_TYPE_EXPR: |
8844 | WALK_SUBTREE (CHANGE_DYNAMIC_TYPE_NEW_TYPE (*tp)); | |
8845 | WALK_SUBTREE_TAIL (CHANGE_DYNAMIC_TYPE_LOCATION (*tp)); | |
8846 | ||
1e8e9920 | 8847 | case DECL_EXPR: |
89c5cfdc | 8848 | /* If this is a TYPE_DECL, walk into the fields of the type that it's |
8849 | defining. We only want to walk into these fields of a type in this | |
8850 | case and not in the general case of a mere reference to the type. | |
8851 | ||
8852 | The criterion is as follows: if the field can be an expression, it | |
8853 | must be walked only here. This should be in keeping with the fields | |
8854 | that are directly gimplified in gimplify_type_sizes in order for the | |
8855 | mark/copy-if-shared/unmark machinery of the gimplifier to work with | |
8856 | variable-sized types. | |
8857 | ||
8858 | Note that DECLs get walked as part of processing the BIND_EXPR. */ | |
8859 | if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL) | |
1e8e9920 | 8860 | { |
8861 | tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp)); | |
89c5cfdc | 8862 | if (TREE_CODE (*type_p) == ERROR_MARK) |
8863 | return NULL_TREE; | |
c75b4594 | 8864 | |
1e8e9920 | 8865 | /* Call the function for the type. See if it returns anything or |
8866 | doesn't want us to continue. If we are to continue, walk both | |
8867 | the normal fields and those for the declaration case. */ | |
8868 | result = (*func) (type_p, &walk_subtrees, data); | |
8869 | if (result || !walk_subtrees) | |
89c5cfdc | 8870 | return result; |
98f8a662 | 8871 | |
20a8f962 | 8872 | result = walk_type_fields (*type_p, func, data, pset, lh); |
1e8e9920 | 8873 | if (result) |
8874 | return result; | |
98f8a662 | 8875 | |
1e8e9920 | 8876 | /* If this is a record type, also walk the fields. */ |
8877 | if (TREE_CODE (*type_p) == RECORD_TYPE | |
8878 | || TREE_CODE (*type_p) == UNION_TYPE | |
8879 | || TREE_CODE (*type_p) == QUAL_UNION_TYPE) | |
8880 | { | |
8881 | tree field; | |
98f8a662 | 8882 | |
1e8e9920 | 8883 | for (field = TYPE_FIELDS (*type_p); field; |
8884 | field = TREE_CHAIN (field)) | |
8885 | { | |
8886 | /* We'd like to look at the type of the field, but we can | |
8887 | easily get infinite recursion. So assume it's pointed | |
8888 | to elsewhere in the tree. Also, ignore things that | |
8889 | aren't fields. */ | |
8890 | if (TREE_CODE (field) != FIELD_DECL) | |
8891 | continue; | |
8892 | ||
8893 | WALK_SUBTREE (DECL_FIELD_OFFSET (field)); | |
8894 | WALK_SUBTREE (DECL_SIZE (field)); | |
8895 | WALK_SUBTREE (DECL_SIZE_UNIT (field)); | |
8896 | if (TREE_CODE (*type_p) == QUAL_UNION_TYPE) | |
8897 | WALK_SUBTREE (DECL_QUALIFIER (field)); | |
8898 | } | |
8899 | } | |
98f8a662 | 8900 | |
89c5cfdc | 8901 | /* Same for scalar types. */ |
8902 | else if (TREE_CODE (*type_p) == BOOLEAN_TYPE | |
8903 | || TREE_CODE (*type_p) == ENUMERAL_TYPE | |
8904 | || TREE_CODE (*type_p) == INTEGER_TYPE | |
06f0b99c | 8905 | || TREE_CODE (*type_p) == FIXED_POINT_TYPE |
89c5cfdc | 8906 | || TREE_CODE (*type_p) == REAL_TYPE) |
8907 | { | |
8908 | WALK_SUBTREE (TYPE_MIN_VALUE (*type_p)); | |
8909 | WALK_SUBTREE (TYPE_MAX_VALUE (*type_p)); | |
8910 | } | |
8911 | ||
1e8e9920 | 8912 | WALK_SUBTREE (TYPE_SIZE (*type_p)); |
8913 | WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p)); | |
98f8a662 | 8914 | } |
1e8e9920 | 8915 | /* FALLTHRU */ |
8916 | ||
8917 | default: | |
75a70cf9 | 8918 | if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))) |
1e8e9920 | 8919 | { |
8920 | int i, len; | |
8921 | ||
8922 | /* Walk over all the sub-trees of this operand. */ | |
c2f47e15 | 8923 | len = TREE_OPERAND_LENGTH (*tp); |
1e8e9920 | 8924 | |
8925 | /* Go through the subtrees. We need to do this in forward order so | |
8926 | that the scope of a FOR_EXPR is handled properly. */ | |
8927 | if (len) | |
8928 | { | |
8929 | for (i = 0; i < len - 1; ++i) | |
75a70cf9 | 8930 | WALK_SUBTREE (TREE_OPERAND (*tp, i)); |
8931 | WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len - 1)); | |
1e8e9920 | 8932 | } |
8933 | } | |
1e8e9920 | 8934 | /* If this is a type, walk the needed fields in the type. */ |
8935 | else if (TYPE_P (*tp)) | |
20a8f962 | 8936 | return walk_type_fields (*tp, func, data, pset, lh); |
1e8e9920 | 8937 | break; |
98f8a662 | 8938 | } |
8939 | ||
8940 | /* We didn't find what we were looking for. */ | |
8941 | return NULL_TREE; | |
8942 | ||
8943 | #undef WALK_SUBTREE_TAIL | |
8944 | } | |
8945 | #undef WALK_SUBTREE | |
8946 | ||
8947 | /* Like walk_tree, but does not walk duplicate nodes more than once. */ | |
8948 | ||
8949 | tree | |
20a8f962 | 8950 | walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data, |
8951 | walk_tree_lh lh) | |
98f8a662 | 8952 | { |
8953 | tree result; | |
8954 | struct pointer_set_t *pset; | |
8955 | ||
8956 | pset = pointer_set_create (); | |
20a8f962 | 8957 | result = walk_tree_1 (tp, func, data, pset, lh); |
98f8a662 | 8958 | pointer_set_destroy (pset); |
8959 | return result; | |
8960 | } | |
8961 | ||
1e8e9920 | 8962 | |
35cc02b5 | 8963 | tree * |
8964 | tree_block (tree t) | |
8965 | { | |
8966 | char const c = TREE_CODE_CLASS (TREE_CODE (t)); | |
8967 | ||
8968 | if (IS_EXPR_CODE_CLASS (c)) | |
8969 | return &t->exp.block; | |
35cc02b5 | 8970 | gcc_unreachable (); |
8971 | return NULL; | |
8972 | } | |
8973 | ||
c2f47e15 | 8974 | /* Build and return a TREE_LIST of arguments in the CALL_EXPR exp. |
8975 | FIXME: don't use this function. It exists for compatibility with | |
8976 | the old representation of CALL_EXPRs where a list was used to hold the | |
8977 | arguments. Places that currently extract the arglist from a CALL_EXPR | |
8978 | ought to be rewritten to use the CALL_EXPR itself. */ | |
8979 | tree | |
8980 | call_expr_arglist (tree exp) | |
8981 | { | |
8982 | tree arglist = NULL_TREE; | |
8983 | int i; | |
8984 | for (i = call_expr_nargs (exp) - 1; i >= 0; i--) | |
8985 | arglist = tree_cons (NULL_TREE, CALL_EXPR_ARG (exp, i), arglist); | |
8986 | return arglist; | |
8987 | } | |
8988 | ||
75a70cf9 | 8989 | |
8990 | /* Create a nameless artificial label and put it in the current function | |
8991 | context. Returns the newly created label. */ | |
8992 | ||
8993 | tree | |
8994 | create_artificial_label (void) | |
8995 | { | |
8996 | tree lab = build_decl (LABEL_DECL, NULL_TREE, void_type_node); | |
8997 | ||
8998 | DECL_ARTIFICIAL (lab) = 1; | |
8999 | DECL_IGNORED_P (lab) = 1; | |
9000 | DECL_CONTEXT (lab) = current_function_decl; | |
9001 | return lab; | |
9002 | } | |
9003 | ||
9004 | /* Given a tree, try to return a useful variable name that we can use | |
9005 | to prefix a temporary that is being assigned the value of the tree. | |
9006 | I.E. given <temp> = &A, return A. */ | |
9007 | ||
9008 | const char * | |
9009 | get_name (tree t) | |
9010 | { | |
9011 | tree stripped_decl; | |
9012 | ||
9013 | stripped_decl = t; | |
9014 | STRIP_NOPS (stripped_decl); | |
9015 | if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl)) | |
9016 | return IDENTIFIER_POINTER (DECL_NAME (stripped_decl)); | |
9017 | else | |
9018 | { | |
9019 | switch (TREE_CODE (stripped_decl)) | |
9020 | { | |
9021 | case ADDR_EXPR: | |
9022 | return get_name (TREE_OPERAND (stripped_decl, 0)); | |
9023 | default: | |
9024 | return NULL; | |
9025 | } | |
9026 | } | |
9027 | } | |
9028 | ||
448e99f5 | 9029 | /* Return true if TYPE has a variable argument list. */ |
9030 | ||
9031 | bool | |
9032 | stdarg_p (tree fntype) | |
9033 | { | |
9034 | function_args_iterator args_iter; | |
9035 | tree n = NULL_TREE, t; | |
9036 | ||
9037 | if (!fntype) | |
9038 | return false; | |
9039 | ||
9040 | FOREACH_FUNCTION_ARGS(fntype, t, args_iter) | |
9041 | { | |
9042 | n = t; | |
9043 | } | |
9044 | ||
9045 | return n != NULL_TREE && n != void_type_node; | |
9046 | } | |
9047 | ||
9048 | /* Return true if TYPE has a prototype. */ | |
9049 | ||
9050 | bool | |
9051 | prototype_p (tree fntype) | |
9052 | { | |
9053 | tree t; | |
9054 | ||
9055 | gcc_assert (fntype != NULL_TREE); | |
9056 | ||
9057 | t = TYPE_ARG_TYPES (fntype); | |
9058 | return (t != NULL_TREE); | |
9059 | } | |
9060 | ||
9061 | /* Return the number of arguments that a function has. */ | |
9062 | ||
9063 | int | |
9064 | function_args_count (tree fntype) | |
9065 | { | |
9066 | function_args_iterator args_iter; | |
9067 | tree t; | |
9068 | int num = 0; | |
9069 | ||
9070 | if (fntype) | |
9071 | { | |
9072 | FOREACH_FUNCTION_ARGS(fntype, t, args_iter) | |
9073 | { | |
9074 | num++; | |
9075 | } | |
9076 | } | |
9077 | ||
9078 | return num; | |
9079 | } | |
9080 | ||
1b16fc45 | 9081 | /* If BLOCK is inlined from an __attribute__((__artificial__)) |
9082 | routine, return pointer to location from where it has been | |
9083 | called. */ | |
9084 | location_t * | |
9085 | block_nonartificial_location (tree block) | |
9086 | { | |
9087 | location_t *ret = NULL; | |
9088 | ||
9089 | while (block && TREE_CODE (block) == BLOCK | |
9090 | && BLOCK_ABSTRACT_ORIGIN (block)) | |
9091 | { | |
9092 | tree ao = BLOCK_ABSTRACT_ORIGIN (block); | |
9093 | ||
c112531f | 9094 | while (TREE_CODE (ao) == BLOCK |
9095 | && BLOCK_ABSTRACT_ORIGIN (ao) | |
9096 | && BLOCK_ABSTRACT_ORIGIN (ao) != ao) | |
1b16fc45 | 9097 | ao = BLOCK_ABSTRACT_ORIGIN (ao); |
9098 | ||
9099 | if (TREE_CODE (ao) == FUNCTION_DECL) | |
9100 | { | |
9101 | /* If AO is an artificial inline, point RET to the | |
9102 | call site locus at which it has been inlined and continue | |
9103 | the loop, in case AO's caller is also an artificial | |
9104 | inline. */ | |
9105 | if (DECL_DECLARED_INLINE_P (ao) | |
9106 | && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao))) | |
9107 | ret = &BLOCK_SOURCE_LOCATION (block); | |
9108 | else | |
9109 | break; | |
9110 | } | |
9111 | else if (TREE_CODE (ao) != BLOCK) | |
9112 | break; | |
9113 | ||
9114 | block = BLOCK_SUPERCONTEXT (block); | |
9115 | } | |
9116 | return ret; | |
9117 | } | |
9118 | ||
b430e8d9 | 9119 | |
9120 | /* If EXP is inlined from an __attribute__((__artificial__)) | |
9121 | function, return the location of the original call expression. */ | |
9122 | ||
9123 | location_t | |
9124 | tree_nonartificial_location (tree exp) | |
9125 | { | |
9126 | tree block = TREE_BLOCK (exp); | |
9127 | ||
9128 | while (block | |
9129 | && TREE_CODE (block) == BLOCK | |
9130 | && BLOCK_ABSTRACT_ORIGIN (block)) | |
9131 | { | |
9132 | tree ao = BLOCK_ABSTRACT_ORIGIN (block); | |
9133 | ||
9134 | do | |
9135 | { | |
9136 | if (TREE_CODE (ao) == FUNCTION_DECL | |
9137 | && DECL_DECLARED_INLINE_P (ao) | |
9138 | && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao))) | |
9139 | return BLOCK_SOURCE_LOCATION (block); | |
9140 | else if (TREE_CODE (ao) == BLOCK | |
9141 | && BLOCK_SUPERCONTEXT (ao) != ao) | |
9142 | ao = BLOCK_SUPERCONTEXT (ao); | |
9143 | else | |
9144 | break; | |
9145 | } | |
9146 | while (ao); | |
9147 | ||
9148 | block = BLOCK_SUPERCONTEXT (block); | |
9149 | } | |
9150 | ||
9151 | return EXPR_LOCATION (exp); | |
9152 | } | |
9153 | ||
9154 | ||
46f8e3b0 | 9155 | /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq |
9156 | nodes. */ | |
9157 | ||
9158 | /* Return the hash code code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */ | |
9159 | ||
9160 | static hashval_t | |
9161 | cl_option_hash_hash (const void *x) | |
9162 | { | |
9163 | const_tree const t = (const_tree) x; | |
9164 | const char *p; | |
9165 | size_t i; | |
9166 | size_t len = 0; | |
9167 | hashval_t hash = 0; | |
9168 | ||
9169 | if (TREE_CODE (t) == OPTIMIZATION_NODE) | |
9170 | { | |
9171 | p = (const char *)TREE_OPTIMIZATION (t); | |
9172 | len = sizeof (struct cl_optimization); | |
9173 | } | |
9174 | ||
9175 | else if (TREE_CODE (t) == TARGET_OPTION_NODE) | |
9176 | { | |
9177 | p = (const char *)TREE_TARGET_OPTION (t); | |
9178 | len = sizeof (struct cl_target_option); | |
9179 | } | |
9180 | ||
9181 | else | |
9182 | gcc_unreachable (); | |
9183 | ||
9184 | /* assume most opt flags are just 0/1, some are 2-3, and a few might be | |
9185 | something else. */ | |
9186 | for (i = 0; i < len; i++) | |
9187 | if (p[i]) | |
9188 | hash = (hash << 4) ^ ((i << 2) | p[i]); | |
9189 | ||
9190 | return hash; | |
9191 | } | |
9192 | ||
9193 | /* Return nonzero if the value represented by *X (an OPTIMIZATION or | |
9194 | TARGET_OPTION tree node) is the same as that given by *Y, which is the | |
9195 | same. */ | |
9196 | ||
9197 | static int | |
9198 | cl_option_hash_eq (const void *x, const void *y) | |
9199 | { | |
9200 | const_tree const xt = (const_tree) x; | |
9201 | const_tree const yt = (const_tree) y; | |
9202 | const char *xp; | |
9203 | const char *yp; | |
9204 | size_t len; | |
9205 | ||
9206 | if (TREE_CODE (xt) != TREE_CODE (yt)) | |
9207 | return 0; | |
9208 | ||
9209 | if (TREE_CODE (xt) == OPTIMIZATION_NODE) | |
9210 | { | |
9211 | xp = (const char *)TREE_OPTIMIZATION (xt); | |
9212 | yp = (const char *)TREE_OPTIMIZATION (yt); | |
9213 | len = sizeof (struct cl_optimization); | |
9214 | } | |
9215 | ||
9216 | else if (TREE_CODE (xt) == TARGET_OPTION_NODE) | |
9217 | { | |
9218 | xp = (const char *)TREE_TARGET_OPTION (xt); | |
9219 | yp = (const char *)TREE_TARGET_OPTION (yt); | |
9220 | len = sizeof (struct cl_target_option); | |
9221 | } | |
9222 | ||
9223 | else | |
9224 | gcc_unreachable (); | |
9225 | ||
9226 | return (memcmp (xp, yp, len) == 0); | |
9227 | } | |
9228 | ||
9229 | /* Build an OPTIMIZATION_NODE based on the current options. */ | |
9230 | ||
9231 | tree | |
9232 | build_optimization_node (void) | |
9233 | { | |
9234 | tree t; | |
9235 | void **slot; | |
9236 | ||
9237 | /* Use the cache of optimization nodes. */ | |
9238 | ||
9239 | cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node)); | |
9240 | ||
9241 | slot = htab_find_slot (cl_option_hash_table, cl_optimization_node, INSERT); | |
9242 | t = (tree) *slot; | |
9243 | if (!t) | |
9244 | { | |
9245 | /* Insert this one into the hash table. */ | |
9246 | t = cl_optimization_node; | |
9247 | *slot = t; | |
9248 | ||
9249 | /* Make a new node for next time round. */ | |
9250 | cl_optimization_node = make_node (OPTIMIZATION_NODE); | |
9251 | } | |
9252 | ||
9253 | return t; | |
9254 | } | |
9255 | ||
9256 | /* Build a TARGET_OPTION_NODE based on the current options. */ | |
9257 | ||
9258 | tree | |
9259 | build_target_option_node (void) | |
9260 | { | |
9261 | tree t; | |
9262 | void **slot; | |
9263 | ||
9264 | /* Use the cache of optimization nodes. */ | |
9265 | ||
9266 | cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node)); | |
9267 | ||
9268 | slot = htab_find_slot (cl_option_hash_table, cl_target_option_node, INSERT); | |
9269 | t = (tree) *slot; | |
9270 | if (!t) | |
9271 | { | |
9272 | /* Insert this one into the hash table. */ | |
9273 | t = cl_target_option_node; | |
9274 | *slot = t; | |
9275 | ||
9276 | /* Make a new node for next time round. */ | |
9277 | cl_target_option_node = make_node (TARGET_OPTION_NODE); | |
9278 | } | |
9279 | ||
9280 | return t; | |
9281 | } | |
9282 | ||
36267649 | 9283 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
9284 | instance of an inlined instance of a block which is local to an inline | |
9285 | function, so we have to trace all of the way back through the origin chain | |
9286 | to find out what sort of node actually served as the original seed for the | |
9287 | given block. */ | |
9288 | ||
9289 | tree | |
9290 | block_ultimate_origin (const_tree block) | |
9291 | { | |
9292 | tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); | |
9293 | ||
9294 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the | |
9295 | nodes in the function to point to themselves; ignore that if | |
9296 | we're trying to output the abstract instance of this function. */ | |
9297 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
9298 | return NULL_TREE; | |
9299 | ||
9300 | if (immediate_origin == NULL_TREE) | |
9301 | return NULL_TREE; | |
9302 | else | |
9303 | { | |
9304 | tree ret_val; | |
9305 | tree lookahead = immediate_origin; | |
9306 | ||
9307 | do | |
9308 | { | |
9309 | ret_val = lookahead; | |
9310 | lookahead = (TREE_CODE (ret_val) == BLOCK | |
9311 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL); | |
9312 | } | |
9313 | while (lookahead != NULL && lookahead != ret_val); | |
9314 | ||
9315 | /* The block's abstract origin chain may not be the *ultimate* origin of | |
9316 | the block. It could lead to a DECL that has an abstract origin set. | |
9317 | If so, we want that DECL's abstract origin (which is what DECL_ORIGIN | |
9318 | will give us if it has one). Note that DECL's abstract origins are | |
9319 | supposed to be the most distant ancestor (or so decl_ultimate_origin | |
9320 | claims), so we don't need to loop following the DECL origins. */ | |
9321 | if (DECL_P (ret_val)) | |
9322 | return DECL_ORIGIN (ret_val); | |
9323 | ||
9324 | return ret_val; | |
9325 | } | |
9326 | } | |
9327 | ||
1f3233d1 | 9328 | #include "gt-tree.h" |