]>
Commit | Line | Data |
---|---|---|
c6a1db6c | 1 | /* Language-independent node constructors for parse phase of GNU compiler. |
06ceef4e RK |
2 | Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
3 | 1999, 2000 Free Software Foundation, Inc. | |
c6a1db6c RS |
4 | |
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
e9fa0c7c RK |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
c6a1db6c RS |
21 | |
22 | ||
23 | /* This file contains the low level primitives for operating on tree nodes, | |
24 | including allocation, list operations, interning of identifiers, | |
25 | construction of data type nodes and statement nodes, | |
26 | and construction of type conversion nodes. It also contains | |
27 | tables index by tree code that describe how to take apart | |
28 | nodes of that code. | |
29 | ||
30 | It is intended to be language-independent, but occasionally | |
31 | calls language-dependent routines defined (for C) in typecheck.c. | |
32 | ||
33 | The low-level allocation routines oballoc and permalloc | |
34 | are used also for allocating many other kinds of objects | |
35 | by all passes of the compiler. */ | |
36 | ||
37 | #include "config.h" | |
670ee920 | 38 | #include "system.h" |
c6a1db6c | 39 | #include "flags.h" |
c6a1db6c | 40 | #include "tree.h" |
6baf1cc8 | 41 | #include "tm_p.h" |
d69c4bd1 | 42 | #include "function.h" |
c6a1db6c | 43 | #include "obstack.h" |
10f0ad3d | 44 | #include "toplev.h" |
87ff9c8e | 45 | #include "ggc.h" |
956d6950 | 46 | |
c6a1db6c RS |
47 | #define obstack_chunk_alloc xmalloc |
48 | #define obstack_chunk_free free | |
cab634f2 | 49 | /* obstack.[ch] explicitly declined to prototype this. */ |
58782098 | 50 | extern int _obstack_allocated_p PARAMS ((struct obstack *h, PTR obj)); |
c6a1db6c | 51 | |
58782098 | 52 | static void unsave_expr_now_r PARAMS ((tree)); |
582db8e4 | 53 | |
c6a1db6c RS |
54 | /* Tree nodes of permanent duration are allocated in this obstack. |
55 | They are the identifier nodes, and everything outside of | |
56 | the bodies and parameters of function definitions. */ | |
57 | ||
58 | struct obstack permanent_obstack; | |
59 | ||
60 | /* The initial RTL, and all ..._TYPE nodes, in a function | |
61 | are allocated in this obstack. Usually they are freed at the | |
62 | end of the function, but if the function is inline they are saved. | |
63 | For top-level functions, this is maybepermanent_obstack. | |
64 | Separate obstacks are made for nested functions. */ | |
65 | ||
66 | struct obstack *function_maybepermanent_obstack; | |
67 | ||
68 | /* This is the function_maybepermanent_obstack for top-level functions. */ | |
69 | ||
70 | struct obstack maybepermanent_obstack; | |
71 | ||
72 | /* The contents of the current function definition are allocated | |
73 | in this obstack, and all are freed at the end of the function. | |
74 | For top-level functions, this is temporary_obstack. | |
75 | Separate obstacks are made for nested functions. */ | |
76 | ||
77 | struct obstack *function_obstack; | |
78 | ||
79 | /* This is used for reading initializers of global variables. */ | |
80 | ||
81 | struct obstack temporary_obstack; | |
82 | ||
83 | /* The tree nodes of an expression are allocated | |
84 | in this obstack, and all are freed at the end of the expression. */ | |
85 | ||
86 | struct obstack momentary_obstack; | |
87 | ||
88 | /* The tree nodes of a declarator are allocated | |
89 | in this obstack, and all are freed when the declarator | |
90 | has been parsed. */ | |
91 | ||
92 | static struct obstack temp_decl_obstack; | |
93 | ||
94 | /* This points at either permanent_obstack | |
95 | or the current function_maybepermanent_obstack. */ | |
96 | ||
97 | struct obstack *saveable_obstack; | |
98 | ||
99 | /* This is same as saveable_obstack during parse and expansion phase; | |
100 | it points to the current function's obstack during optimization. | |
101 | This is the obstack to be used for creating rtl objects. */ | |
102 | ||
103 | struct obstack *rtl_obstack; | |
104 | ||
105 | /* This points at either permanent_obstack or the current function_obstack. */ | |
106 | ||
107 | struct obstack *current_obstack; | |
108 | ||
109 | /* This points at either permanent_obstack or the current function_obstack | |
110 | or momentary_obstack. */ | |
111 | ||
112 | struct obstack *expression_obstack; | |
113 | ||
114 | /* Stack of obstack selections for push_obstacks and pop_obstacks. */ | |
115 | ||
116 | struct obstack_stack | |
117 | { | |
118 | struct obstack_stack *next; | |
119 | struct obstack *current; | |
120 | struct obstack *saveable; | |
121 | struct obstack *expression; | |
122 | struct obstack *rtl; | |
123 | }; | |
124 | ||
125 | struct obstack_stack *obstack_stack; | |
126 | ||
127 | /* Obstack for allocating struct obstack_stack entries. */ | |
128 | ||
129 | static struct obstack obstack_stack_obstack; | |
130 | ||
131 | /* Addresses of first objects in some obstacks. | |
132 | This is for freeing their entire contents. */ | |
133 | char *maybepermanent_firstobj; | |
134 | char *temporary_firstobj; | |
135 | char *momentary_firstobj; | |
136 | char *temp_decl_firstobj; | |
137 | ||
2b417d3c JW |
138 | /* This is used to preserve objects (mainly array initializers) that need to |
139 | live until the end of the current function, but no further. */ | |
140 | char *momentary_function_firstobj; | |
141 | ||
c6a1db6c RS |
142 | /* Nonzero means all ..._TYPE nodes should be allocated permanently. */ |
143 | ||
144 | int all_types_permanent; | |
145 | ||
146 | /* Stack of places to restore the momentary obstack back to. */ | |
147 | ||
148 | struct momentary_level | |
149 | { | |
150 | /* Pointer back to previous such level. */ | |
151 | struct momentary_level *prev; | |
152 | /* First object allocated within this level. */ | |
153 | char *base; | |
154 | /* Value of expression_obstack saved at entry to this level. */ | |
155 | struct obstack *obstack; | |
156 | }; | |
157 | ||
158 | struct momentary_level *momentary_stack; | |
159 | ||
160 | /* Table indexed by tree code giving a string containing a character | |
161 | classifying the tree code. Possibilities are | |
162 | t, d, s, c, r, <, 1, 2 and e. See tree.def for details. */ | |
163 | ||
164 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, | |
165 | ||
0a6969ad | 166 | char tree_code_type[MAX_TREE_CODES] = { |
c6a1db6c RS |
167 | #include "tree.def" |
168 | }; | |
169 | #undef DEFTREECODE | |
170 | ||
171 | /* Table indexed by tree code giving number of expression | |
172 | operands beyond the fixed part of the node structure. | |
173 | Not used for types or decls. */ | |
174 | ||
175 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, | |
176 | ||
0a6969ad | 177 | int tree_code_length[MAX_TREE_CODES] = { |
c6a1db6c RS |
178 | #include "tree.def" |
179 | }; | |
180 | #undef DEFTREECODE | |
181 | ||
182 | /* Names of tree components. | |
183 | Used for printing out the tree and error messages. */ | |
184 | #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME, | |
185 | ||
5f8ded66 | 186 | const char *tree_code_name[MAX_TREE_CODES] = { |
c6a1db6c RS |
187 | #include "tree.def" |
188 | }; | |
189 | #undef DEFTREECODE | |
190 | ||
c6a1db6c RS |
191 | /* Statistics-gathering stuff. */ |
192 | typedef enum | |
193 | { | |
03646189 RS |
194 | d_kind, |
195 | t_kind, | |
196 | b_kind, | |
197 | s_kind, | |
198 | r_kind, | |
199 | e_kind, | |
200 | c_kind, | |
201 | id_kind, | |
202 | op_id_kind, | |
203 | perm_list_kind, | |
204 | temp_list_kind, | |
205 | vec_kind, | |
206 | x_kind, | |
207 | lang_decl, | |
208 | lang_type, | |
209 | all_kinds | |
c6a1db6c | 210 | } tree_node_kind; |
03646189 | 211 | |
c6a1db6c RS |
212 | int tree_node_counts[(int)all_kinds]; |
213 | int tree_node_sizes[(int)all_kinds]; | |
214 | int id_string_size = 0; | |
03646189 | 215 | |
341a243e | 216 | static const char * const tree_node_kind_names[] = { |
03646189 RS |
217 | "decls", |
218 | "types", | |
219 | "blocks", | |
220 | "stmts", | |
221 | "refs", | |
222 | "exprs", | |
223 | "constants", | |
224 | "identifiers", | |
225 | "op_identifiers", | |
226 | "perm_tree_lists", | |
227 | "temp_tree_lists", | |
228 | "vecs", | |
229 | "random kinds", | |
230 | "lang_decl kinds", | |
231 | "lang_type kinds" | |
232 | }; | |
c6a1db6c RS |
233 | |
234 | /* Hash table for uniquizing IDENTIFIER_NODEs by name. */ | |
235 | ||
236 | #define MAX_HASH_TABLE 1009 | |
237 | static tree hash_table[MAX_HASH_TABLE]; /* id hash buckets */ | |
238 | ||
239 | /* 0 while creating built-in identifiers. */ | |
240 | static int do_identifier_warnings; | |
241 | ||
0e77444b RS |
242 | /* Unique id for next decl created. */ |
243 | static int next_decl_uid; | |
579f50b6 RK |
244 | /* Unique id for next type created. */ |
245 | static int next_type_uid = 1; | |
0e77444b | 246 | |
41472af8 MM |
247 | /* The language-specific function for alias analysis. If NULL, the |
248 | language does not do any special alias analysis. */ | |
58782098 | 249 | int (*lang_get_alias_set) PARAMS ((tree)); |
41472af8 | 250 | |
91e97eb8 RK |
251 | /* Here is how primitive or already-canonicalized types' hash |
252 | codes are made. */ | |
7bcac048 | 253 | #define TYPE_HASH(TYPE) ((unsigned long) (TYPE) & 0777777) |
91e97eb8 | 254 | |
87ff9c8e RH |
255 | /* Each hash table slot is a bucket containing a chain |
256 | of these structures. */ | |
257 | ||
258 | struct type_hash | |
259 | { | |
260 | struct type_hash *next; /* Next structure in the bucket. */ | |
05bccae2 | 261 | unsigned int hashcode; /* Hash code of this type. */ |
87ff9c8e RH |
262 | tree type; /* The type recorded here. */ |
263 | }; | |
264 | ||
265 | /* Now here is the hash table. When recording a type, it is added | |
266 | to the slot whose index is the hash code mod the table size. | |
267 | Note that the hash table is used for several kinds of types | |
268 | (function types, array types and array index range types, for now). | |
269 | While all these live in the same table, they are completely independent, | |
270 | and the hash code is computed differently for each of these. */ | |
271 | ||
272 | #define TYPE_HASH_SIZE 59 | |
273 | struct type_hash *type_hash_table[TYPE_HASH_SIZE]; | |
274 | ||
58782098 KG |
275 | static void build_real_from_int_cst_1 PARAMS ((PTR)); |
276 | static void set_type_quals PARAMS ((tree, int)); | |
277 | static void append_random_chars PARAMS ((char *)); | |
278 | static void mark_type_hash PARAMS ((void *)); | |
0a818f84 | 279 | |
582db8e4 MM |
280 | /* If non-null, these are language-specific helper functions for |
281 | unsave_expr_now. If present, LANG_UNSAVE is called before its | |
282 | argument (an UNSAVE_EXPR) is to be unsaved, and all other | |
283 | processing in unsave_expr_now is aborted. LANG_UNSAVE_EXPR_NOW is | |
284 | called from unsave_expr_1 for language-specific tree codes. */ | |
58782098 KG |
285 | void (*lang_unsave) PARAMS ((tree *)); |
286 | void (*lang_unsave_expr_now) PARAMS ((tree)); | |
5c7261ab AS |
287 | |
288 | /* The string used as a placeholder instead of a source file name for | |
289 | built-in tree nodes. The variable, which is dynamically allocated, | |
290 | should be used; the macro is only used to initialize it. */ | |
291 | ||
292 | static char *built_in_filename; | |
293 | #define BUILT_IN_FILENAME ("<built-in>") | |
c6a1db6c | 294 | \f |
81b3411c BS |
295 | tree global_trees[TI_MAX]; |
296 | \f | |
c6a1db6c RS |
297 | /* Init the principal obstacks. */ |
298 | ||
299 | void | |
300 | init_obstacks () | |
301 | { | |
302 | gcc_obstack_init (&obstack_stack_obstack); | |
303 | gcc_obstack_init (&permanent_obstack); | |
304 | ||
305 | gcc_obstack_init (&temporary_obstack); | |
306 | temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0); | |
307 | gcc_obstack_init (&momentary_obstack); | |
308 | momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0); | |
2b417d3c | 309 | momentary_function_firstobj = momentary_firstobj; |
c6a1db6c RS |
310 | gcc_obstack_init (&maybepermanent_obstack); |
311 | maybepermanent_firstobj | |
312 | = (char *) obstack_alloc (&maybepermanent_obstack, 0); | |
313 | gcc_obstack_init (&temp_decl_obstack); | |
314 | temp_decl_firstobj = (char *) obstack_alloc (&temp_decl_obstack, 0); | |
315 | ||
316 | function_obstack = &temporary_obstack; | |
317 | function_maybepermanent_obstack = &maybepermanent_obstack; | |
318 | current_obstack = &permanent_obstack; | |
319 | expression_obstack = &permanent_obstack; | |
320 | rtl_obstack = saveable_obstack = &permanent_obstack; | |
321 | ||
322 | /* Init the hash table of identifiers. */ | |
4c9a05bc | 323 | bzero ((char *) hash_table, sizeof hash_table); |
d4b60170 RK |
324 | ggc_add_tree_root (hash_table, sizeof hash_table / sizeof (tree)); |
325 | ||
326 | /* Initialize the hash table of types. */ | |
327 | bzero ((char *) type_hash_table, | |
328 | sizeof type_hash_table / sizeof type_hash_table[0]); | |
329 | ggc_add_root (type_hash_table, | |
330 | sizeof type_hash_table / sizeof type_hash_table [0], | |
331 | sizeof type_hash_table[0], mark_type_hash); | |
81b3411c | 332 | ggc_add_tree_root (global_trees, TI_MAX); |
c6a1db6c RS |
333 | } |
334 | ||
335 | void | |
336 | gcc_obstack_init (obstack) | |
337 | struct obstack *obstack; | |
338 | { | |
339 | /* Let particular systems override the size of a chunk. */ | |
340 | #ifndef OBSTACK_CHUNK_SIZE | |
341 | #define OBSTACK_CHUNK_SIZE 0 | |
342 | #endif | |
343 | /* Let them override the alloc and free routines too. */ | |
344 | #ifndef OBSTACK_CHUNK_ALLOC | |
345 | #define OBSTACK_CHUNK_ALLOC xmalloc | |
346 | #endif | |
347 | #ifndef OBSTACK_CHUNK_FREE | |
348 | #define OBSTACK_CHUNK_FREE free | |
349 | #endif | |
350 | _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0, | |
58782098 KG |
351 | (void *(*) PARAMS ((long))) OBSTACK_CHUNK_ALLOC, |
352 | (void (*) PARAMS ((void *))) OBSTACK_CHUNK_FREE); | |
c6a1db6c RS |
353 | } |
354 | ||
83fdb191 MM |
355 | /* Save all variables describing the current status into the structure |
356 | *P. This function is called whenever we start compiling one | |
357 | function in the midst of compiling another. For example, when | |
358 | compiling a nested function, or, in C++, a template instantiation | |
359 | that is required by the function we are currently compiling. | |
a0dabda5 JM |
360 | |
361 | CONTEXT is the decl_function_context for the function we're about to | |
362 | compile; if it isn't current_function_decl, we have to play some games. */ | |
c6a1db6c RS |
363 | |
364 | void | |
36edd3cc | 365 | save_tree_status (p) |
c6a1db6c RS |
366 | struct function *p; |
367 | { | |
368 | p->all_types_permanent = all_types_permanent; | |
369 | p->momentary_stack = momentary_stack; | |
370 | p->maybepermanent_firstobj = maybepermanent_firstobj; | |
8fa6b6c9 | 371 | p->temporary_firstobj = temporary_firstobj; |
c6a1db6c | 372 | p->momentary_firstobj = momentary_firstobj; |
2b417d3c | 373 | p->momentary_function_firstobj = momentary_function_firstobj; |
c6a1db6c RS |
374 | p->function_obstack = function_obstack; |
375 | p->function_maybepermanent_obstack = function_maybepermanent_obstack; | |
376 | p->current_obstack = current_obstack; | |
377 | p->expression_obstack = expression_obstack; | |
378 | p->saveable_obstack = saveable_obstack; | |
379 | p->rtl_obstack = rtl_obstack; | |
a0dabda5 | 380 | |
36edd3cc BS |
381 | function_maybepermanent_obstack |
382 | = (struct obstack *) xmalloc (sizeof (struct obstack)); | |
383 | gcc_obstack_init (function_maybepermanent_obstack); | |
24554b03 RH |
384 | maybepermanent_firstobj |
385 | = (char *) obstack_finish (function_maybepermanent_obstack); | |
19e7d354 | 386 | |
c6a1db6c RS |
387 | function_obstack = (struct obstack *) xmalloc (sizeof (struct obstack)); |
388 | gcc_obstack_init (function_obstack); | |
389 | ||
c6a1db6c RS |
390 | current_obstack = &permanent_obstack; |
391 | expression_obstack = &permanent_obstack; | |
392 | rtl_obstack = saveable_obstack = &permanent_obstack; | |
393 | ||
8fa6b6c9 | 394 | temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0); |
c6a1db6c | 395 | momentary_firstobj = (char *) obstack_finish (&momentary_obstack); |
2b417d3c | 396 | momentary_function_firstobj = momentary_firstobj; |
c6a1db6c RS |
397 | } |
398 | ||
399 | /* Restore all variables describing the current status from the structure *P. | |
400 | This is used after a nested function. */ | |
401 | ||
402 | void | |
36edd3cc | 403 | restore_tree_status (p) |
c6a1db6c RS |
404 | struct function *p; |
405 | { | |
406 | all_types_permanent = p->all_types_permanent; | |
407 | momentary_stack = p->momentary_stack; | |
408 | ||
2b417d3c | 409 | obstack_free (&momentary_obstack, momentary_function_firstobj); |
19e7d354 | 410 | |
a0dabda5 | 411 | /* Free saveable storage used by the function just compiled and not |
36edd3cc | 412 | saved. */ |
a0dabda5 | 413 | obstack_free (function_maybepermanent_obstack, maybepermanent_firstobj); |
24554b03 RH |
414 | if (obstack_empty_p (function_maybepermanent_obstack)) |
415 | { | |
416 | obstack_free (function_maybepermanent_obstack, NULL); | |
417 | free (function_maybepermanent_obstack); | |
418 | } | |
19e7d354 | 419 | |
36edd3cc BS |
420 | obstack_free (&temporary_obstack, temporary_firstobj); |
421 | obstack_free (&momentary_obstack, momentary_function_firstobj); | |
d1485032 | 422 | |
69ba6af3 | 423 | obstack_free (function_obstack, NULL); |
c6a1db6c RS |
424 | free (function_obstack); |
425 | ||
8fa6b6c9 | 426 | temporary_firstobj = p->temporary_firstobj; |
c6a1db6c | 427 | momentary_firstobj = p->momentary_firstobj; |
2b417d3c | 428 | momentary_function_firstobj = p->momentary_function_firstobj; |
c6a1db6c RS |
429 | maybepermanent_firstobj = p->maybepermanent_firstobj; |
430 | function_obstack = p->function_obstack; | |
431 | function_maybepermanent_obstack = p->function_maybepermanent_obstack; | |
432 | current_obstack = p->current_obstack; | |
433 | expression_obstack = p->expression_obstack; | |
434 | saveable_obstack = p->saveable_obstack; | |
435 | rtl_obstack = p->rtl_obstack; | |
436 | } | |
437 | \f | |
438 | /* Start allocating on the temporary (per function) obstack. | |
439 | This is done in start_function before parsing the function body, | |
440 | and before each initialization at top level, and to go back | |
956af069 | 441 | to temporary allocation after doing permanent_allocation. */ |
c6a1db6c RS |
442 | |
443 | void | |
444 | temporary_allocation () | |
445 | { | |
446 | /* Note that function_obstack at top level points to temporary_obstack. | |
447 | But within a nested function context, it is a separate obstack. */ | |
448 | current_obstack = function_obstack; | |
449 | expression_obstack = function_obstack; | |
450 | rtl_obstack = saveable_obstack = function_maybepermanent_obstack; | |
451 | momentary_stack = 0; | |
452 | } | |
453 | ||
454 | /* Start allocating on the permanent obstack but don't | |
455 | free the temporary data. After calling this, call | |
456 | `permanent_allocation' to fully resume permanent allocation status. */ | |
457 | ||
458 | void | |
459 | end_temporary_allocation () | |
460 | { | |
461 | current_obstack = &permanent_obstack; | |
462 | expression_obstack = &permanent_obstack; | |
463 | rtl_obstack = saveable_obstack = &permanent_obstack; | |
464 | } | |
465 | ||
466 | /* Resume allocating on the temporary obstack, undoing | |
467 | effects of `end_temporary_allocation'. */ | |
468 | ||
469 | void | |
470 | resume_temporary_allocation () | |
471 | { | |
472 | current_obstack = function_obstack; | |
473 | expression_obstack = function_obstack; | |
474 | rtl_obstack = saveable_obstack = function_maybepermanent_obstack; | |
475 | } | |
476 | ||
477 | /* While doing temporary allocation, switch to allocating in such a | |
478 | way as to save all nodes if the function is inlined. Call | |
479 | resume_temporary_allocation to go back to ordinary temporary | |
480 | allocation. */ | |
481 | ||
482 | void | |
483 | saveable_allocation () | |
484 | { | |
485 | /* Note that function_obstack at top level points to temporary_obstack. | |
486 | But within a nested function context, it is a separate obstack. */ | |
487 | expression_obstack = current_obstack = saveable_obstack; | |
488 | } | |
489 | ||
490 | /* Switch to current obstack CURRENT and maybepermanent obstack SAVEABLE, | |
491 | recording the previously current obstacks on a stack. | |
492 | This does not free any storage in any obstack. */ | |
493 | ||
494 | void | |
495 | push_obstacks (current, saveable) | |
496 | struct obstack *current, *saveable; | |
497 | { | |
a3770a81 RH |
498 | struct obstack_stack *p; |
499 | ||
a3770a81 | 500 | p = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack, |
c6a1db6c RS |
501 | (sizeof (struct obstack_stack))); |
502 | ||
503 | p->current = current_obstack; | |
504 | p->saveable = saveable_obstack; | |
505 | p->expression = expression_obstack; | |
506 | p->rtl = rtl_obstack; | |
507 | p->next = obstack_stack; | |
508 | obstack_stack = p; | |
509 | ||
510 | current_obstack = current; | |
511 | expression_obstack = current; | |
512 | rtl_obstack = saveable_obstack = saveable; | |
513 | } | |
514 | ||
515 | /* Save the current set of obstacks, but don't change them. */ | |
516 | ||
517 | void | |
518 | push_obstacks_nochange () | |
519 | { | |
a3770a81 RH |
520 | struct obstack_stack *p; |
521 | ||
a3770a81 | 522 | p = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack, |
c6a1db6c RS |
523 | (sizeof (struct obstack_stack))); |
524 | ||
525 | p->current = current_obstack; | |
526 | p->saveable = saveable_obstack; | |
527 | p->expression = expression_obstack; | |
528 | p->rtl = rtl_obstack; | |
529 | p->next = obstack_stack; | |
530 | obstack_stack = p; | |
531 | } | |
532 | ||
533 | /* Pop the obstack selection stack. */ | |
534 | ||
535 | void | |
536 | pop_obstacks () | |
537 | { | |
a3770a81 RH |
538 | struct obstack_stack *p; |
539 | ||
a3770a81 | 540 | p = obstack_stack; |
c6a1db6c RS |
541 | obstack_stack = p->next; |
542 | ||
543 | current_obstack = p->current; | |
544 | saveable_obstack = p->saveable; | |
545 | expression_obstack = p->expression; | |
546 | rtl_obstack = p->rtl; | |
547 | ||
548 | obstack_free (&obstack_stack_obstack, p); | |
549 | } | |
550 | ||
551 | /* Nonzero if temporary allocation is currently in effect. | |
552 | Zero if currently doing permanent allocation. */ | |
553 | ||
554 | int | |
555 | allocation_temporary_p () | |
556 | { | |
557 | return current_obstack != &permanent_obstack; | |
558 | } | |
559 | ||
560 | /* Go back to allocating on the permanent obstack | |
561 | and free everything in the temporary obstack. | |
2b417d3c JW |
562 | |
563 | FUNCTION_END is true only if we have just finished compiling a function. | |
564 | In that case, we also free preserved initial values on the momentary | |
565 | obstack. */ | |
c6a1db6c RS |
566 | |
567 | void | |
2b417d3c JW |
568 | permanent_allocation (function_end) |
569 | int function_end; | |
c6a1db6c RS |
570 | { |
571 | /* Free up previous temporary obstack data */ | |
572 | obstack_free (&temporary_obstack, temporary_firstobj); | |
2b417d3c | 573 | if (function_end) |
c61f7d69 RK |
574 | { |
575 | obstack_free (&momentary_obstack, momentary_function_firstobj); | |
576 | momentary_firstobj = momentary_function_firstobj; | |
577 | } | |
2b417d3c JW |
578 | else |
579 | obstack_free (&momentary_obstack, momentary_firstobj); | |
d4b60170 | 580 | |
9ccd47de | 581 | obstack_free (function_maybepermanent_obstack, maybepermanent_firstobj); |
c6a1db6c RS |
582 | obstack_free (&temp_decl_obstack, temp_decl_firstobj); |
583 | ||
584 | current_obstack = &permanent_obstack; | |
585 | expression_obstack = &permanent_obstack; | |
586 | rtl_obstack = saveable_obstack = &permanent_obstack; | |
587 | } | |
588 | ||
589 | /* Save permanently everything on the maybepermanent_obstack. */ | |
590 | ||
591 | void | |
592 | preserve_data () | |
593 | { | |
594 | maybepermanent_firstobj | |
595 | = (char *) obstack_alloc (function_maybepermanent_obstack, 0); | |
596 | } | |
597 | ||
598 | void | |
599 | preserve_initializer () | |
600 | { | |
2b417d3c JW |
601 | struct momentary_level *tem; |
602 | char *old_momentary; | |
603 | ||
c6a1db6c RS |
604 | temporary_firstobj |
605 | = (char *) obstack_alloc (&temporary_obstack, 0); | |
c6a1db6c RS |
606 | maybepermanent_firstobj |
607 | = (char *) obstack_alloc (function_maybepermanent_obstack, 0); | |
2b417d3c JW |
608 | |
609 | old_momentary = momentary_firstobj; | |
610 | momentary_firstobj | |
611 | = (char *) obstack_alloc (&momentary_obstack, 0); | |
612 | if (momentary_firstobj != old_momentary) | |
613 | for (tem = momentary_stack; tem; tem = tem->prev) | |
614 | tem->base = momentary_firstobj; | |
c6a1db6c RS |
615 | } |
616 | ||
617 | /* Start allocating new rtl in current_obstack. | |
618 | Use resume_temporary_allocation | |
619 | to go back to allocating rtl in saveable_obstack. */ | |
620 | ||
621 | void | |
622 | rtl_in_current_obstack () | |
623 | { | |
624 | rtl_obstack = current_obstack; | |
625 | } | |
626 | ||
02e39be1 JW |
627 | /* Start allocating rtl from saveable_obstack. Intended to be used after |
628 | a call to push_obstacks_nochange. */ | |
c6a1db6c | 629 | |
02e39be1 | 630 | void |
c6a1db6c RS |
631 | rtl_in_saveable_obstack () |
632 | { | |
02e39be1 | 633 | rtl_obstack = saveable_obstack; |
c6a1db6c RS |
634 | } |
635 | \f | |
636 | /* Allocate SIZE bytes in the current obstack | |
637 | and return a pointer to them. | |
638 | In practice the current obstack is always the temporary one. */ | |
639 | ||
640 | char * | |
641 | oballoc (size) | |
642 | int size; | |
643 | { | |
644 | return (char *) obstack_alloc (current_obstack, size); | |
645 | } | |
646 | ||
647 | /* Free the object PTR in the current obstack | |
648 | as well as everything allocated since PTR. | |
649 | In practice the current obstack is always the temporary one. */ | |
650 | ||
651 | void | |
652 | obfree (ptr) | |
653 | char *ptr; | |
654 | { | |
655 | obstack_free (current_obstack, ptr); | |
656 | } | |
657 | ||
658 | /* Allocate SIZE bytes in the permanent obstack | |
659 | and return a pointer to them. */ | |
660 | ||
661 | char * | |
662 | permalloc (size) | |
37366632 | 663 | int size; |
c6a1db6c RS |
664 | { |
665 | return (char *) obstack_alloc (&permanent_obstack, size); | |
666 | } | |
667 | ||
668 | /* Allocate NELEM items of SIZE bytes in the permanent obstack | |
669 | and return a pointer to them. The storage is cleared before | |
670 | returning the value. */ | |
671 | ||
672 | char * | |
673 | perm_calloc (nelem, size) | |
674 | int nelem; | |
675 | long size; | |
676 | { | |
677 | char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size); | |
678 | bzero (rval, nelem * size); | |
679 | return rval; | |
680 | } | |
681 | ||
682 | /* Allocate SIZE bytes in the saveable obstack | |
683 | and return a pointer to them. */ | |
684 | ||
685 | char * | |
686 | savealloc (size) | |
687 | int size; | |
688 | { | |
689 | return (char *) obstack_alloc (saveable_obstack, size); | |
690 | } | |
f0632762 JM |
691 | |
692 | /* Allocate SIZE bytes in the expression obstack | |
693 | and return a pointer to them. */ | |
694 | ||
695 | char * | |
696 | expralloc (size) | |
697 | int size; | |
698 | { | |
699 | return (char *) obstack_alloc (expression_obstack, size); | |
700 | } | |
c6a1db6c RS |
701 | \f |
702 | /* Print out which obstack an object is in. */ | |
703 | ||
704 | void | |
c4be79d2 | 705 | print_obstack_name (object, file, prefix) |
c6a1db6c | 706 | char *object; |
c4be79d2 | 707 | FILE *file; |
37b37199 | 708 | const char *prefix; |
c6a1db6c RS |
709 | { |
710 | struct obstack *obstack = NULL; | |
37b37199 | 711 | const char *obstack_name = NULL; |
c6a1db6c RS |
712 | struct function *p; |
713 | ||
714 | for (p = outer_function_chain; p; p = p->next) | |
715 | { | |
716 | if (_obstack_allocated_p (p->function_obstack, object)) | |
717 | { | |
718 | obstack = p->function_obstack; | |
719 | obstack_name = "containing function obstack"; | |
720 | } | |
721 | if (_obstack_allocated_p (p->function_maybepermanent_obstack, object)) | |
722 | { | |
723 | obstack = p->function_maybepermanent_obstack; | |
724 | obstack_name = "containing function maybepermanent obstack"; | |
725 | } | |
726 | } | |
727 | ||
728 | if (_obstack_allocated_p (&obstack_stack_obstack, object)) | |
729 | { | |
730 | obstack = &obstack_stack_obstack; | |
731 | obstack_name = "obstack_stack_obstack"; | |
732 | } | |
733 | else if (_obstack_allocated_p (function_obstack, object)) | |
734 | { | |
735 | obstack = function_obstack; | |
736 | obstack_name = "function obstack"; | |
737 | } | |
738 | else if (_obstack_allocated_p (&permanent_obstack, object)) | |
739 | { | |
740 | obstack = &permanent_obstack; | |
741 | obstack_name = "permanent_obstack"; | |
742 | } | |
743 | else if (_obstack_allocated_p (&momentary_obstack, object)) | |
744 | { | |
745 | obstack = &momentary_obstack; | |
746 | obstack_name = "momentary_obstack"; | |
747 | } | |
748 | else if (_obstack_allocated_p (function_maybepermanent_obstack, object)) | |
749 | { | |
750 | obstack = function_maybepermanent_obstack; | |
751 | obstack_name = "function maybepermanent obstack"; | |
752 | } | |
753 | else if (_obstack_allocated_p (&temp_decl_obstack, object)) | |
754 | { | |
755 | obstack = &temp_decl_obstack; | |
756 | obstack_name = "temp_decl_obstack"; | |
757 | } | |
758 | ||
0f41302f | 759 | /* Check to see if the object is in the free area of the obstack. */ |
c6a1db6c RS |
760 | if (obstack != NULL) |
761 | { | |
762 | if (object >= obstack->next_free | |
763 | && object < obstack->chunk_limit) | |
c4be79d2 RK |
764 | fprintf (file, "%s in free portion of obstack %s", |
765 | prefix, obstack_name); | |
c6a1db6c | 766 | else |
c4be79d2 | 767 | fprintf (file, "%s allocated from %s", prefix, obstack_name); |
c6a1db6c RS |
768 | } |
769 | else | |
c4be79d2 RK |
770 | fprintf (file, "%s not allocated from any obstack", prefix); |
771 | } | |
772 | ||
773 | void | |
774 | debug_obstack (object) | |
775 | char *object; | |
776 | { | |
777 | print_obstack_name (object, stderr, "object"); | |
778 | fprintf (stderr, ".\n"); | |
c6a1db6c RS |
779 | } |
780 | ||
781 | /* Return 1 if OBJ is in the permanent obstack. | |
782 | This is slow, and should be used only for debugging. | |
783 | Use TREE_PERMANENT for other purposes. */ | |
784 | ||
785 | int | |
786 | object_permanent_p (obj) | |
787 | tree obj; | |
788 | { | |
789 | return _obstack_allocated_p (&permanent_obstack, obj); | |
790 | } | |
791 | \f | |
792 | /* Start a level of momentary allocation. | |
793 | In C, each compound statement has its own level | |
794 | and that level is freed at the end of each statement. | |
795 | All expression nodes are allocated in the momentary allocation level. */ | |
796 | ||
797 | void | |
798 | push_momentary () | |
799 | { | |
800 | struct momentary_level *tem | |
801 | = (struct momentary_level *) obstack_alloc (&momentary_obstack, | |
802 | sizeof (struct momentary_level)); | |
803 | tem->prev = momentary_stack; | |
804 | tem->base = (char *) obstack_base (&momentary_obstack); | |
805 | tem->obstack = expression_obstack; | |
806 | momentary_stack = tem; | |
807 | expression_obstack = &momentary_obstack; | |
808 | } | |
809 | ||
9e8730a4 RK |
810 | /* Set things up so the next clear_momentary will only clear memory |
811 | past our present position in momentary_obstack. */ | |
812 | ||
813 | void | |
814 | preserve_momentary () | |
815 | { | |
816 | momentary_stack->base = (char *) obstack_base (&momentary_obstack); | |
817 | } | |
818 | ||
c6a1db6c RS |
819 | /* Free all the storage in the current momentary-allocation level. |
820 | In C, this happens at the end of each statement. */ | |
821 | ||
822 | void | |
823 | clear_momentary () | |
824 | { | |
825 | obstack_free (&momentary_obstack, momentary_stack->base); | |
826 | } | |
827 | ||
828 | /* Discard a level of momentary allocation. | |
829 | In C, this happens at the end of each compound statement. | |
830 | Restore the status of expression node allocation | |
831 | that was in effect before this level was created. */ | |
832 | ||
833 | void | |
834 | pop_momentary () | |
835 | { | |
836 | struct momentary_level *tem = momentary_stack; | |
837 | momentary_stack = tem->prev; | |
838 | expression_obstack = tem->obstack; | |
2b417d3c JW |
839 | /* We can't free TEM from the momentary_obstack, because there might |
840 | be objects above it which have been saved. We can free back to the | |
841 | stack of the level we are popping off though. */ | |
842 | obstack_free (&momentary_obstack, tem->base); | |
c6a1db6c RS |
843 | } |
844 | ||
14b6efff RS |
845 | /* Pop back to the previous level of momentary allocation, |
846 | but don't free any momentary data just yet. */ | |
847 | ||
848 | void | |
849 | pop_momentary_nofree () | |
850 | { | |
851 | struct momentary_level *tem = momentary_stack; | |
852 | momentary_stack = tem->prev; | |
853 | expression_obstack = tem->obstack; | |
854 | } | |
855 | ||
c6a1db6c RS |
856 | /* Call when starting to parse a declaration: |
857 | make expressions in the declaration last the length of the function. | |
858 | Returns an argument that should be passed to resume_momentary later. */ | |
859 | ||
860 | int | |
861 | suspend_momentary () | |
862 | { | |
863 | register int tem = expression_obstack == &momentary_obstack; | |
864 | expression_obstack = saveable_obstack; | |
865 | return tem; | |
866 | } | |
867 | ||
868 | /* Call when finished parsing a declaration: | |
869 | restore the treatment of node-allocation that was | |
870 | in effect before the suspension. | |
871 | YES should be the value previously returned by suspend_momentary. */ | |
872 | ||
873 | void | |
874 | resume_momentary (yes) | |
875 | int yes; | |
876 | { | |
877 | if (yes) | |
878 | expression_obstack = &momentary_obstack; | |
879 | } | |
880 | \f | |
881 | /* Init the tables indexed by tree code. | |
882 | Note that languages can add to these tables to define their own codes. */ | |
883 | ||
884 | void | |
885 | init_tree_codes () | |
886 | { | |
d4b60170 RK |
887 | built_in_filename |
888 | = ggc_alloc_string (BUILT_IN_FILENAME, sizeof (BUILT_IN_FILENAME)); | |
5c7261ab | 889 | ggc_add_string_root (&built_in_filename, 1); |
c6a1db6c RS |
890 | } |
891 | ||
892 | /* Return a newly allocated node of code CODE. | |
893 | Initialize the node's unique id and its TREE_PERMANENT flag. | |
23dfa477 ZW |
894 | Note that if garbage collection is in use, TREE_PERMANENT will |
895 | always be zero - we want to eliminate use of TREE_PERMANENT. | |
c6a1db6c RS |
896 | For decl and type nodes, some other fields are initialized. |
897 | The rest of the node is initialized to zero. | |
898 | ||
899 | Achoo! I got a code in the node. */ | |
900 | ||
901 | tree | |
902 | make_node (code) | |
903 | enum tree_code code; | |
904 | { | |
905 | register tree t; | |
906 | register int type = TREE_CODE_CLASS (code); | |
c16ddde3 | 907 | register int length = 0; |
c6a1db6c | 908 | register struct obstack *obstack = current_obstack; |
5e9defae | 909 | #ifdef GATHER_STATISTICS |
c6a1db6c | 910 | register tree_node_kind kind; |
5e9defae | 911 | #endif |
c6a1db6c RS |
912 | |
913 | switch (type) | |
914 | { | |
915 | case 'd': /* A decl node */ | |
916 | #ifdef GATHER_STATISTICS | |
917 | kind = d_kind; | |
918 | #endif | |
919 | length = sizeof (struct tree_decl); | |
920 | /* All decls in an inline function need to be saved. */ | |
921 | if (obstack != &permanent_obstack) | |
922 | obstack = saveable_obstack; | |
f52b5958 RK |
923 | |
924 | /* PARM_DECLs go on the context of the parent. If this is a nested | |
925 | function, then we must allocate the PARM_DECL on the parent's | |
926 | obstack, so that they will live to the end of the parent's | |
9faa82d8 | 927 | closing brace. This is necessary in case we try to inline the |
f52b5958 RK |
928 | function into its parent. |
929 | ||
930 | PARM_DECLs of top-level functions do not have this problem. However, | |
9faa82d8 | 931 | we allocate them where we put the FUNCTION_DECL for languages such as |
f52b5958 | 932 | Ada that need to consult some flags in the PARM_DECLs of the function |
19e7d354 RK |
933 | when calling it. |
934 | ||
935 | See comment in restore_tree_status for why we can't put this | |
936 | in function_obstack. */ | |
937 | if (code == PARM_DECL && obstack != &permanent_obstack) | |
e97b2a1c JW |
938 | { |
939 | tree context = 0; | |
940 | if (current_function_decl) | |
941 | context = decl_function_context (current_function_decl); | |
f52b5958 | 942 | |
e97b2a1c | 943 | if (context) |
f52b5958 | 944 | obstack |
19e7d354 | 945 | = find_function_data (context)->function_maybepermanent_obstack; |
e97b2a1c | 946 | } |
c6a1db6c RS |
947 | break; |
948 | ||
949 | case 't': /* a type node */ | |
950 | #ifdef GATHER_STATISTICS | |
951 | kind = t_kind; | |
952 | #endif | |
953 | length = sizeof (struct tree_type); | |
954 | /* All data types are put where we can preserve them if nec. */ | |
955 | if (obstack != &permanent_obstack) | |
956 | obstack = all_types_permanent ? &permanent_obstack : saveable_obstack; | |
957 | break; | |
958 | ||
03646189 RS |
959 | case 'b': /* a lexical block */ |
960 | #ifdef GATHER_STATISTICS | |
961 | kind = b_kind; | |
962 | #endif | |
963 | length = sizeof (struct tree_block); | |
964 | /* All BLOCK nodes are put where we can preserve them if nec. */ | |
965 | if (obstack != &permanent_obstack) | |
966 | obstack = saveable_obstack; | |
967 | break; | |
968 | ||
c6a1db6c RS |
969 | case 's': /* an expression with side effects */ |
970 | #ifdef GATHER_STATISTICS | |
971 | kind = s_kind; | |
972 | goto usual_kind; | |
973 | #endif | |
974 | case 'r': /* a reference */ | |
975 | #ifdef GATHER_STATISTICS | |
976 | kind = r_kind; | |
977 | goto usual_kind; | |
978 | #endif | |
979 | case 'e': /* an expression */ | |
980 | case '<': /* a comparison expression */ | |
981 | case '1': /* a unary arithmetic expression */ | |
982 | case '2': /* a binary arithmetic expression */ | |
983 | #ifdef GATHER_STATISTICS | |
984 | kind = e_kind; | |
985 | usual_kind: | |
986 | #endif | |
987 | obstack = expression_obstack; | |
03646189 RS |
988 | /* All BIND_EXPR nodes are put where we can preserve them if nec. */ |
989 | if (code == BIND_EXPR && obstack != &permanent_obstack) | |
c6a1db6c RS |
990 | obstack = saveable_obstack; |
991 | length = sizeof (struct tree_exp) | |
992 | + (tree_code_length[(int) code] - 1) * sizeof (char *); | |
993 | break; | |
994 | ||
995 | case 'c': /* a constant */ | |
996 | #ifdef GATHER_STATISTICS | |
997 | kind = c_kind; | |
998 | #endif | |
999 | obstack = expression_obstack; | |
66212c2f RK |
1000 | |
1001 | /* We can't use tree_code_length for INTEGER_CST, since the number of | |
1002 | words is machine-dependent due to varying length of HOST_WIDE_INT, | |
1003 | which might be wider than a pointer (e.g., long long). Similarly | |
1004 | for REAL_CST, since the number of words is machine-dependent due | |
1005 | to varying size and alignment of `double'. */ | |
1006 | ||
1007 | if (code == INTEGER_CST) | |
1008 | length = sizeof (struct tree_int_cst); | |
1009 | else if (code == REAL_CST) | |
1010 | length = sizeof (struct tree_real_cst); | |
1011 | else | |
1012 | length = sizeof (struct tree_common) | |
1013 | + tree_code_length[(int) code] * sizeof (char *); | |
1014 | break; | |
c6a1db6c RS |
1015 | |
1016 | case 'x': /* something random, like an identifier. */ | |
1017 | #ifdef GATHER_STATISTICS | |
1018 | if (code == IDENTIFIER_NODE) | |
1019 | kind = id_kind; | |
1020 | else if (code == OP_IDENTIFIER) | |
1021 | kind = op_id_kind; | |
1022 | else if (code == TREE_VEC) | |
1023 | kind = vec_kind; | |
1024 | else | |
1025 | kind = x_kind; | |
1026 | #endif | |
1027 | length = sizeof (struct tree_common) | |
1028 | + tree_code_length[(int) code] * sizeof (char *); | |
1029 | /* Identifier nodes are always permanent since they are | |
1030 | unique in a compiler run. */ | |
1031 | if (code == IDENTIFIER_NODE) obstack = &permanent_obstack; | |
a7fcb968 RK |
1032 | break; |
1033 | ||
1034 | default: | |
1035 | abort (); | |
c6a1db6c RS |
1036 | } |
1037 | ||
a3770a81 RH |
1038 | if (ggc_p) |
1039 | t = ggc_alloc_tree (length); | |
1040 | else | |
1041 | { | |
1042 | t = (tree) obstack_alloc (obstack, length); | |
1fef02f6 | 1043 | memset ((PTR) t, 0, length); |
a3770a81 | 1044 | } |
c6a1db6c RS |
1045 | |
1046 | #ifdef GATHER_STATISTICS | |
1047 | tree_node_counts[(int)kind]++; | |
1048 | tree_node_sizes[(int)kind] += length; | |
1049 | #endif | |
1050 | ||
c6a1db6c | 1051 | TREE_SET_CODE (t, code); |
23dfa477 | 1052 | TREE_SET_PERMANENT (t); |
c6a1db6c RS |
1053 | |
1054 | switch (type) | |
1055 | { | |
1056 | case 's': | |
1057 | TREE_SIDE_EFFECTS (t) = 1; | |
1058 | TREE_TYPE (t) = void_type_node; | |
1059 | break; | |
1060 | ||
1061 | case 'd': | |
c0920bf9 | 1062 | if (code != FUNCTION_DECL) |
c7ee7249 | 1063 | DECL_ALIGN (t) = 1; |
23dfa477 | 1064 | DECL_IN_SYSTEM_HEADER (t) = in_system_header; |
c6a1db6c | 1065 | DECL_SOURCE_LINE (t) = lineno; |
5c7261ab AS |
1066 | DECL_SOURCE_FILE (t) = |
1067 | (input_filename) ? input_filename : built_in_filename; | |
0e77444b | 1068 | DECL_UID (t) = next_decl_uid++; |
3932261a MM |
1069 | /* Note that we have not yet computed the alias set for this |
1070 | declaration. */ | |
1071 | DECL_POINTER_ALIAS_SET (t) = -1; | |
c6a1db6c RS |
1072 | break; |
1073 | ||
1074 | case 't': | |
579f50b6 | 1075 | TYPE_UID (t) = next_type_uid++; |
c6a1db6c RS |
1076 | TYPE_ALIGN (t) = 1; |
1077 | TYPE_MAIN_VARIANT (t) = t; | |
d9cbc259 | 1078 | TYPE_OBSTACK (t) = obstack; |
91e97eb8 RK |
1079 | TYPE_ATTRIBUTES (t) = NULL_TREE; |
1080 | #ifdef SET_DEFAULT_TYPE_ATTRIBUTES | |
1081 | SET_DEFAULT_TYPE_ATTRIBUTES (t); | |
1082 | #endif | |
41472af8 MM |
1083 | /* Note that we have not yet computed the alias set for this |
1084 | type. */ | |
1085 | TYPE_ALIAS_SET (t) = -1; | |
c6a1db6c RS |
1086 | break; |
1087 | ||
1088 | case 'c': | |
1089 | TREE_CONSTANT (t) = 1; | |
1090 | break; | |
783feeb0 MM |
1091 | |
1092 | case 'e': | |
1093 | switch (code) | |
1094 | { | |
1095 | case INIT_EXPR: | |
1096 | case MODIFY_EXPR: | |
1097 | case VA_ARG_EXPR: | |
1098 | case RTL_EXPR: | |
1099 | case PREDECREMENT_EXPR: | |
1100 | case PREINCREMENT_EXPR: | |
1101 | case POSTDECREMENT_EXPR: | |
1102 | case POSTINCREMENT_EXPR: | |
1103 | /* All of these have side-effects, no matter what their | |
1104 | operands are. */ | |
1105 | TREE_SIDE_EFFECTS (t) = 1; | |
1106 | break; | |
1107 | ||
1108 | default: | |
1109 | break; | |
1110 | } | |
1111 | break; | |
c6a1db6c RS |
1112 | } |
1113 | ||
1114 | return t; | |
1115 | } | |
0f4fd75d FS |
1116 | |
1117 | /* A front-end can reset this to an appropriate function if types need | |
1118 | special handling. */ | |
1119 | ||
58782098 | 1120 | tree (*make_lang_type_fn) PARAMS ((enum tree_code)) = make_node; |
0f4fd75d FS |
1121 | |
1122 | /* Return a new type (with the indicated CODE), doing whatever | |
1123 | language-specific processing is required. */ | |
1124 | ||
1125 | tree | |
1126 | make_lang_type (code) | |
1127 | enum tree_code code; | |
1128 | { | |
1129 | return (*make_lang_type_fn) (code); | |
1130 | } | |
c6a1db6c | 1131 | \f |
c3da6f12 MM |
1132 | /* Return a new node with the same contents as NODE except that its |
1133 | TREE_CHAIN is zero and it has a fresh uid. Unlike make_node, this | |
1134 | function always performs the allocation on the CURRENT_OBSTACK; | |
1135 | it's up to the caller to pick the right obstack before calling this | |
1136 | function. */ | |
c6a1db6c RS |
1137 | |
1138 | tree | |
1139 | copy_node (node) | |
1140 | tree node; | |
1141 | { | |
1142 | register tree t; | |
1143 | register enum tree_code code = TREE_CODE (node); | |
4e86caed | 1144 | register int length = 0; |
c6a1db6c RS |
1145 | |
1146 | switch (TREE_CODE_CLASS (code)) | |
1147 | { | |
1148 | case 'd': /* A decl node */ | |
1149 | length = sizeof (struct tree_decl); | |
1150 | break; | |
1151 | ||
1152 | case 't': /* a type node */ | |
1153 | length = sizeof (struct tree_type); | |
1154 | break; | |
1155 | ||
03646189 RS |
1156 | case 'b': /* a lexical block node */ |
1157 | length = sizeof (struct tree_block); | |
1158 | break; | |
1159 | ||
c6a1db6c | 1160 | case 'r': /* a reference */ |
858a47b1 | 1161 | case 'e': /* an expression */ |
c6a1db6c RS |
1162 | case 's': /* an expression with side effects */ |
1163 | case '<': /* a comparison expression */ | |
1164 | case '1': /* a unary arithmetic expression */ | |
1165 | case '2': /* a binary arithmetic expression */ | |
1166 | length = sizeof (struct tree_exp) | |
1167 | + (tree_code_length[(int) code] - 1) * sizeof (char *); | |
1168 | break; | |
1169 | ||
1170 | case 'c': /* a constant */ | |
49b08aba RK |
1171 | /* We can't use tree_code_length for INTEGER_CST, since the number of |
1172 | words is machine-dependent due to varying length of HOST_WIDE_INT, | |
1173 | which might be wider than a pointer (e.g., long long). Similarly | |
1174 | for REAL_CST, since the number of words is machine-dependent due | |
1175 | to varying size and alignment of `double'. */ | |
1176 | if (code == INTEGER_CST) | |
b14b8129 | 1177 | length = sizeof (struct tree_int_cst); |
49b08aba | 1178 | else if (code == REAL_CST) |
b14b8129 | 1179 | length = sizeof (struct tree_real_cst); |
ff615e83 | 1180 | else |
b14b8129 RK |
1181 | length = (sizeof (struct tree_common) |
1182 | + tree_code_length[(int) code] * sizeof (char *)); | |
1183 | break; | |
c6a1db6c RS |
1184 | |
1185 | case 'x': /* something random, like an identifier. */ | |
1186 | length = sizeof (struct tree_common) | |
1187 | + tree_code_length[(int) code] * sizeof (char *); | |
1188 | if (code == TREE_VEC) | |
1189 | length += (TREE_VEC_LENGTH (node) - 1) * sizeof (char *); | |
1190 | } | |
1191 | ||
a3770a81 RH |
1192 | if (ggc_p) |
1193 | t = ggc_alloc_tree (length); | |
1194 | else | |
2e28f042 BS |
1195 | t = (tree) obstack_alloc (current_obstack, length); |
1196 | memcpy (t, node, length); | |
c6a1db6c | 1197 | |
1e54d32b | 1198 | TREE_CHAIN (t) = 0; |
69b7087e | 1199 | TREE_ASM_WRITTEN (t) = 0; |
c6a1db6c | 1200 | |
579f50b6 RK |
1201 | if (TREE_CODE_CLASS (code) == 'd') |
1202 | DECL_UID (t) = next_decl_uid++; | |
1203 | else if (TREE_CODE_CLASS (code) == 't') | |
d9cbc259 RK |
1204 | { |
1205 | TYPE_UID (t) = next_type_uid++; | |
1206 | TYPE_OBSTACK (t) = current_obstack; | |
28238567 PB |
1207 | |
1208 | /* The following is so that the debug code for | |
1209 | the copy is different from the original type. | |
1210 | The two statements usually duplicate each other | |
1211 | (because they clear fields of the same union), | |
0f41302f | 1212 | but the optimizer should catch that. */ |
28238567 PB |
1213 | TYPE_SYMTAB_POINTER (t) = 0; |
1214 | TYPE_SYMTAB_ADDRESS (t) = 0; | |
d9cbc259 | 1215 | } |
579f50b6 | 1216 | |
23dfa477 | 1217 | TREE_SET_PERMANENT (t); |
c6a1db6c RS |
1218 | |
1219 | return t; | |
1220 | } | |
1221 | ||
1222 | /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field. | |
1223 | For example, this can copy a list made of TREE_LIST nodes. */ | |
1224 | ||
1225 | tree | |
1226 | copy_list (list) | |
1227 | tree list; | |
1228 | { | |
1229 | tree head; | |
1230 | register tree prev, next; | |
1231 | ||
1232 | if (list == 0) | |
1233 | return 0; | |
1234 | ||
1235 | head = prev = copy_node (list); | |
1236 | next = TREE_CHAIN (list); | |
1237 | while (next) | |
1238 | { | |
1239 | TREE_CHAIN (prev) = copy_node (next); | |
1240 | prev = TREE_CHAIN (prev); | |
1241 | next = TREE_CHAIN (next); | |
1242 | } | |
1243 | return head; | |
1244 | } | |
1245 | \f | |
1246 | #define HASHBITS 30 | |
1247 | ||
1248 | /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string). | |
1249 | If an identifier with that name has previously been referred to, | |
1250 | the same node is returned this time. */ | |
1251 | ||
1252 | tree | |
1253 | get_identifier (text) | |
37b37199 | 1254 | register const char *text; |
c6a1db6c RS |
1255 | { |
1256 | register int hi; | |
1257 | register int i; | |
1258 | register tree idp; | |
1259 | register int len, hash_len; | |
1260 | ||
1261 | /* Compute length of text in len. */ | |
dfa27ef1 | 1262 | len = strlen (text); |
c6a1db6c RS |
1263 | |
1264 | /* Decide how much of that length to hash on */ | |
1265 | hash_len = len; | |
06ceef4e | 1266 | if (warn_id_clash && len > id_clash_len) |
c6a1db6c RS |
1267 | hash_len = id_clash_len; |
1268 | ||
1269 | /* Compute hash code */ | |
0f41302f | 1270 | hi = hash_len * 613 + (unsigned) text[0]; |
c6a1db6c | 1271 | for (i = 1; i < hash_len; i += 2) |
0f41302f | 1272 | hi = ((hi * 613) + (unsigned) (text[i])); |
c6a1db6c RS |
1273 | |
1274 | hi &= (1 << HASHBITS) - 1; | |
1275 | hi %= MAX_HASH_TABLE; | |
1276 | ||
1277 | /* Search table for identifier */ | |
1278 | for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp)) | |
1279 | if (IDENTIFIER_LENGTH (idp) == len | |
1280 | && IDENTIFIER_POINTER (idp)[0] == text[0] | |
1281 | && !bcmp (IDENTIFIER_POINTER (idp), text, len)) | |
1282 | return idp; /* <-- return if found */ | |
1283 | ||
1284 | /* Not found; optionally warn about a similar identifier */ | |
06ceef4e | 1285 | if (warn_id_clash && do_identifier_warnings && len >= id_clash_len) |
c6a1db6c RS |
1286 | for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp)) |
1287 | if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len)) | |
1288 | { | |
1289 | warning ("`%s' and `%s' identical in first %d characters", | |
1290 | IDENTIFIER_POINTER (idp), text, id_clash_len); | |
1291 | break; | |
1292 | } | |
1293 | ||
1294 | if (tree_code_length[(int) IDENTIFIER_NODE] < 0) | |
1295 | abort (); /* set_identifier_size hasn't been called. */ | |
1296 | ||
1297 | /* Not found, create one, add to chain */ | |
1298 | idp = make_node (IDENTIFIER_NODE); | |
1299 | IDENTIFIER_LENGTH (idp) = len; | |
1300 | #ifdef GATHER_STATISTICS | |
1301 | id_string_size += len; | |
1302 | #endif | |
1303 | ||
a3770a81 RH |
1304 | if (ggc_p) |
1305 | IDENTIFIER_POINTER (idp) = ggc_alloc_string (text, len); | |
1306 | else | |
1307 | IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len); | |
c6a1db6c RS |
1308 | |
1309 | TREE_CHAIN (idp) = hash_table[hi]; | |
1310 | hash_table[hi] = idp; | |
1311 | return idp; /* <-- return if created */ | |
1312 | } | |
1313 | ||
a94dbf2c JM |
1314 | /* If an identifier with the name TEXT (a null-terminated string) has |
1315 | previously been referred to, return that node; otherwise return | |
1316 | NULL_TREE. */ | |
1317 | ||
1318 | tree | |
1319 | maybe_get_identifier (text) | |
37b37199 | 1320 | register const char *text; |
a94dbf2c JM |
1321 | { |
1322 | register int hi; | |
1323 | register int i; | |
1324 | register tree idp; | |
1325 | register int len, hash_len; | |
1326 | ||
1327 | /* Compute length of text in len. */ | |
dfa27ef1 | 1328 | len = strlen (text); |
a94dbf2c JM |
1329 | |
1330 | /* Decide how much of that length to hash on */ | |
1331 | hash_len = len; | |
06ceef4e | 1332 | if (warn_id_clash && len > id_clash_len) |
a94dbf2c JM |
1333 | hash_len = id_clash_len; |
1334 | ||
1335 | /* Compute hash code */ | |
1336 | hi = hash_len * 613 + (unsigned) text[0]; | |
1337 | for (i = 1; i < hash_len; i += 2) | |
1338 | hi = ((hi * 613) + (unsigned) (text[i])); | |
1339 | ||
1340 | hi &= (1 << HASHBITS) - 1; | |
1341 | hi %= MAX_HASH_TABLE; | |
1342 | ||
1343 | /* Search table for identifier */ | |
1344 | for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp)) | |
1345 | if (IDENTIFIER_LENGTH (idp) == len | |
1346 | && IDENTIFIER_POINTER (idp)[0] == text[0] | |
1347 | && !bcmp (IDENTIFIER_POINTER (idp), text, len)) | |
1348 | return idp; /* <-- return if found */ | |
1349 | ||
1350 | return NULL_TREE; | |
1351 | } | |
1352 | ||
c6a1db6c RS |
1353 | /* Enable warnings on similar identifiers (if requested). |
1354 | Done after the built-in identifiers are created. */ | |
1355 | ||
1356 | void | |
1357 | start_identifier_warnings () | |
1358 | { | |
1359 | do_identifier_warnings = 1; | |
1360 | } | |
1361 | ||
1362 | /* Record the size of an identifier node for the language in use. | |
1363 | SIZE is the total size in bytes. | |
1364 | This is called by the language-specific files. This must be | |
1365 | called before allocating any identifiers. */ | |
1366 | ||
1367 | void | |
1368 | set_identifier_size (size) | |
1369 | int size; | |
1370 | { | |
1371 | tree_code_length[(int) IDENTIFIER_NODE] | |
1372 | = (size - sizeof (struct tree_common)) / sizeof (tree); | |
1373 | } | |
1374 | \f | |
1375 | /* Return a newly constructed INTEGER_CST node whose constant value | |
1376 | is specified by the two ints LOW and HI. | |
37366632 RK |
1377 | The TREE_TYPE is set to `int'. |
1378 | ||
1379 | This function should be used via the `build_int_2' macro. */ | |
c6a1db6c RS |
1380 | |
1381 | tree | |
37366632 RK |
1382 | build_int_2_wide (low, hi) |
1383 | HOST_WIDE_INT low, hi; | |
c6a1db6c RS |
1384 | { |
1385 | register tree t = make_node (INTEGER_CST); | |
d4b60170 | 1386 | |
c6a1db6c RS |
1387 | TREE_INT_CST_LOW (t) = low; |
1388 | TREE_INT_CST_HIGH (t) = hi; | |
1389 | TREE_TYPE (t) = integer_type_node; | |
1390 | return t; | |
1391 | } | |
1392 | ||
1393 | /* Return a new REAL_CST node whose type is TYPE and value is D. */ | |
1394 | ||
1395 | tree | |
1396 | build_real (type, d) | |
1397 | tree type; | |
1398 | REAL_VALUE_TYPE d; | |
1399 | { | |
1400 | tree v; | |
0afbe93d | 1401 | int overflow = 0; |
c6a1db6c RS |
1402 | |
1403 | /* Check for valid float value for this type on this target machine; | |
1404 | if not, can print error message and store a valid value in D. */ | |
1405 | #ifdef CHECK_FLOAT_VALUE | |
0afbe93d | 1406 | CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow); |
c6a1db6c RS |
1407 | #endif |
1408 | ||
1409 | v = make_node (REAL_CST); | |
1410 | TREE_TYPE (v) = type; | |
1411 | TREE_REAL_CST (v) = d; | |
0afbe93d | 1412 | TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow; |
c6a1db6c RS |
1413 | return v; |
1414 | } | |
1415 | ||
1416 | /* Return a new REAL_CST node whose type is TYPE | |
1417 | and whose value is the integer value of the INTEGER_CST node I. */ | |
1418 | ||
1419 | #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC) | |
1420 | ||
1421 | REAL_VALUE_TYPE | |
84c7be4b | 1422 | real_value_from_int_cst (type, i) |
7bdb32b9 | 1423 | tree type ATTRIBUTE_UNUSED, i; |
c6a1db6c RS |
1424 | { |
1425 | REAL_VALUE_TYPE d; | |
2026444a | 1426 | |
c6a1db6c | 1427 | #ifdef REAL_ARITHMETIC |
e545d37f RK |
1428 | /* Clear all bits of the real value type so that we can later do |
1429 | bitwise comparisons to see if two values are the same. */ | |
1430 | bzero ((char *) &d, sizeof d); | |
1431 | ||
15c76378 | 1432 | if (! TREE_UNSIGNED (TREE_TYPE (i))) |
84c7be4b RK |
1433 | REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i), |
1434 | TYPE_MODE (type)); | |
15c76378 | 1435 | else |
84c7be4b RK |
1436 | REAL_VALUE_FROM_UNSIGNED_INT (d, TREE_INT_CST_LOW (i), |
1437 | TREE_INT_CST_HIGH (i), TYPE_MODE (type)); | |
c6a1db6c | 1438 | #else /* not REAL_ARITHMETIC */ |
5e9defae KG |
1439 | /* Some 386 compilers mishandle unsigned int to float conversions, |
1440 | so introduce a temporary variable E to avoid those bugs. */ | |
db7e5239 | 1441 | if (TREE_INT_CST_HIGH (i) < 0 && ! TREE_UNSIGNED (TREE_TYPE (i))) |
c6a1db6c | 1442 | { |
5e9defae KG |
1443 | REAL_VALUE_TYPE e; |
1444 | ||
c6a1db6c | 1445 | d = (double) (~ TREE_INT_CST_HIGH (i)); |
2026444a | 1446 | e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)) |
37366632 | 1447 | * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))); |
2026444a | 1448 | d *= e; |
05bccae2 | 1449 | e = (double) (~ TREE_INT_CST_LOW (i)); |
2026444a | 1450 | d += e; |
c6a1db6c RS |
1451 | d = (- d - 1.0); |
1452 | } | |
1453 | else | |
1454 | { | |
5e9defae KG |
1455 | REAL_VALUE_TYPE e; |
1456 | ||
db7e5239 | 1457 | d = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (i); |
2026444a | 1458 | e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)) |
37366632 | 1459 | * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))); |
2026444a | 1460 | d *= e; |
05bccae2 | 1461 | e = (double) TREE_INT_CST_LOW (i); |
2026444a | 1462 | d += e; |
c6a1db6c RS |
1463 | } |
1464 | #endif /* not REAL_ARITHMETIC */ | |
1465 | return d; | |
1466 | } | |
1467 | ||
d4b60170 RK |
1468 | /* Args to pass to and from build_real_from_int_cst_1. */ |
1469 | ||
1a87eea2 KG |
1470 | struct brfic_args |
1471 | { | |
d4b60170 RK |
1472 | tree type; /* Input: type to conver to. */ |
1473 | tree i; /* Input: operand to convert */ | |
1474 | REAL_VALUE_TYPE d; /* Output: floating point value. */ | |
1a87eea2 KG |
1475 | }; |
1476 | ||
d4b60170 RK |
1477 | /* Convert an integer to a floating point value while protected by a floating |
1478 | point exception handler. */ | |
1479 | ||
1a87eea2 KG |
1480 | static void |
1481 | build_real_from_int_cst_1 (data) | |
1482 | PTR data; | |
1483 | { | |
d4b60170 | 1484 | struct brfic_args *args = (struct brfic_args *) data; |
1a87eea2 KG |
1485 | |
1486 | #ifdef REAL_ARITHMETIC | |
1487 | args->d = real_value_from_int_cst (args->type, args->i); | |
1488 | #else | |
d4b60170 RK |
1489 | args->d |
1490 | = REAL_VALUE_TRUNCATE (TYPE_MODE (args->type), | |
1491 | real_value_from_int_cst (args->type, args->i)); | |
1a87eea2 KG |
1492 | #endif |
1493 | } | |
1494 | ||
d4b60170 RK |
1495 | /* Given a tree representing an integer constant I, return a tree |
1496 | representing the same value as a floating-point constant of type TYPE. | |
1497 | We cannot perform this operation if there is no way of doing arithmetic | |
1498 | on floating-point values. */ | |
c6a1db6c RS |
1499 | |
1500 | tree | |
1501 | build_real_from_int_cst (type, i) | |
1502 | tree type; | |
1503 | tree i; | |
1504 | { | |
1505 | tree v; | |
53d74c3c | 1506 | int overflow = TREE_OVERFLOW (i); |
c6a1db6c | 1507 | REAL_VALUE_TYPE d; |
1a87eea2 | 1508 | struct brfic_args args; |
c6a1db6c RS |
1509 | |
1510 | v = make_node (REAL_CST); | |
1511 | TREE_TYPE (v) = type; | |
1512 | ||
1a87eea2 KG |
1513 | /* Setup input for build_real_from_int_cst_1() */ |
1514 | args.type = type; | |
1515 | args.i = i; | |
1516 | ||
1517 | if (do_float_handler (build_real_from_int_cst_1, (PTR) &args)) | |
d4b60170 RK |
1518 | /* Receive output from build_real_from_int_cst_1() */ |
1519 | d = args.d; | |
1a87eea2 KG |
1520 | else |
1521 | { | |
1522 | /* We got an exception from build_real_from_int_cst_1() */ | |
53d74c3c RK |
1523 | d = dconst0; |
1524 | overflow = 1; | |
53d74c3c | 1525 | } |
1a87eea2 | 1526 | |
53d74c3c RK |
1527 | /* Check for valid float value for this type on this target machine. */ |
1528 | ||
c6a1db6c | 1529 | #ifdef CHECK_FLOAT_VALUE |
53d74c3c | 1530 | CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow); |
c6a1db6c RS |
1531 | #endif |
1532 | ||
1533 | TREE_REAL_CST (v) = d; | |
53d74c3c | 1534 | TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow; |
c6a1db6c RS |
1535 | return v; |
1536 | } | |
1537 | ||
1538 | #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */ | |
1539 | ||
1540 | /* Return a newly constructed STRING_CST node whose value is | |
1541 | the LEN characters at STR. | |
1542 | The TREE_TYPE is not initialized. */ | |
1543 | ||
1544 | tree | |
1545 | build_string (len, str) | |
1546 | int len; | |
37b37199 | 1547 | const char *str; |
c6a1db6c | 1548 | { |
526a6253 RK |
1549 | /* Put the string in saveable_obstack since it will be placed in the RTL |
1550 | for an "asm" statement and will also be kept around a while if | |
1551 | deferring constant output in varasm.c. */ | |
1552 | ||
c6a1db6c | 1553 | register tree s = make_node (STRING_CST); |
d4b60170 | 1554 | |
c6a1db6c | 1555 | TREE_STRING_LENGTH (s) = len; |
a3770a81 RH |
1556 | if (ggc_p) |
1557 | TREE_STRING_POINTER (s) = ggc_alloc_string (str, len); | |
1558 | else | |
1559 | TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len); | |
d4b60170 | 1560 | |
c6a1db6c RS |
1561 | return s; |
1562 | } | |
1563 | ||
1564 | /* Return a newly constructed COMPLEX_CST node whose value is | |
1565 | specified by the real and imaginary parts REAL and IMAG. | |
b217d7fe RK |
1566 | Both REAL and IMAG should be constant nodes. TYPE, if specified, |
1567 | will be the type of the COMPLEX_CST; otherwise a new type will be made. */ | |
c6a1db6c RS |
1568 | |
1569 | tree | |
b217d7fe RK |
1570 | build_complex (type, real, imag) |
1571 | tree type; | |
c6a1db6c RS |
1572 | tree real, imag; |
1573 | { | |
1574 | register tree t = make_node (COMPLEX_CST); | |
53d74c3c | 1575 | |
c6a1db6c RS |
1576 | TREE_REALPART (t) = real; |
1577 | TREE_IMAGPART (t) = imag; | |
b217d7fe | 1578 | TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real)); |
53d74c3c RK |
1579 | TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag); |
1580 | TREE_CONSTANT_OVERFLOW (t) | |
1581 | = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag); | |
c6a1db6c RS |
1582 | return t; |
1583 | } | |
1584 | ||
1585 | /* Build a newly constructed TREE_VEC node of length LEN. */ | |
0f41302f | 1586 | |
c6a1db6c RS |
1587 | tree |
1588 | make_tree_vec (len) | |
1589 | int len; | |
1590 | { | |
1591 | register tree t; | |
1592 | register int length = (len-1) * sizeof (tree) + sizeof (struct tree_vec); | |
1593 | register struct obstack *obstack = current_obstack; | |
c6a1db6c RS |
1594 | |
1595 | #ifdef GATHER_STATISTICS | |
1596 | tree_node_counts[(int)vec_kind]++; | |
1597 | tree_node_sizes[(int)vec_kind] += length; | |
1598 | #endif | |
1599 | ||
a3770a81 RH |
1600 | if (ggc_p) |
1601 | t = ggc_alloc_tree (length); | |
1602 | else | |
1603 | { | |
1604 | t = (tree) obstack_alloc (obstack, length); | |
1605 | bzero ((PTR) t, length); | |
1606 | } | |
508f8149 | 1607 | |
c6a1db6c RS |
1608 | TREE_SET_CODE (t, TREE_VEC); |
1609 | TREE_VEC_LENGTH (t) = len; | |
23dfa477 | 1610 | TREE_SET_PERMANENT (t); |
c6a1db6c RS |
1611 | |
1612 | return t; | |
1613 | } | |
1614 | \f | |
9ad265b0 RK |
1615 | /* Return 1 if EXPR is the integer constant zero or a complex constant |
1616 | of zero. */ | |
c6a1db6c RS |
1617 | |
1618 | int | |
1619 | integer_zerop (expr) | |
1620 | tree expr; | |
1621 | { | |
d964285c | 1622 | STRIP_NOPS (expr); |
c6a1db6c | 1623 | |
9ad265b0 | 1624 | return ((TREE_CODE (expr) == INTEGER_CST |
1ac876be | 1625 | && ! TREE_CONSTANT_OVERFLOW (expr) |
9ad265b0 RK |
1626 | && TREE_INT_CST_LOW (expr) == 0 |
1627 | && TREE_INT_CST_HIGH (expr) == 0) | |
1628 | || (TREE_CODE (expr) == COMPLEX_CST | |
1629 | && integer_zerop (TREE_REALPART (expr)) | |
1630 | && integer_zerop (TREE_IMAGPART (expr)))); | |
c6a1db6c RS |
1631 | } |
1632 | ||
9ad265b0 RK |
1633 | /* Return 1 if EXPR is the integer constant one or the corresponding |
1634 | complex constant. */ | |
c6a1db6c RS |
1635 | |
1636 | int | |
1637 | integer_onep (expr) | |
1638 | tree expr; | |
1639 | { | |
d964285c | 1640 | STRIP_NOPS (expr); |
c6a1db6c | 1641 | |
9ad265b0 | 1642 | return ((TREE_CODE (expr) == INTEGER_CST |
1ac876be | 1643 | && ! TREE_CONSTANT_OVERFLOW (expr) |
9ad265b0 RK |
1644 | && TREE_INT_CST_LOW (expr) == 1 |
1645 | && TREE_INT_CST_HIGH (expr) == 0) | |
1646 | || (TREE_CODE (expr) == COMPLEX_CST | |
1647 | && integer_onep (TREE_REALPART (expr)) | |
1648 | && integer_zerop (TREE_IMAGPART (expr)))); | |
c6a1db6c RS |
1649 | } |
1650 | ||
9ad265b0 RK |
1651 | /* Return 1 if EXPR is an integer containing all 1's in as much precision as |
1652 | it contains. Likewise for the corresponding complex constant. */ | |
c6a1db6c RS |
1653 | |
1654 | int | |
1655 | integer_all_onesp (expr) | |
1656 | tree expr; | |
1657 | { | |
1658 | register int prec; | |
1659 | register int uns; | |
1660 | ||
d964285c | 1661 | STRIP_NOPS (expr); |
c6a1db6c | 1662 | |
9ad265b0 RK |
1663 | if (TREE_CODE (expr) == COMPLEX_CST |
1664 | && integer_all_onesp (TREE_REALPART (expr)) | |
1665 | && integer_zerop (TREE_IMAGPART (expr))) | |
1666 | return 1; | |
1667 | ||
1ac876be RK |
1668 | else if (TREE_CODE (expr) != INTEGER_CST |
1669 | || TREE_CONSTANT_OVERFLOW (expr)) | |
c6a1db6c RS |
1670 | return 0; |
1671 | ||
1672 | uns = TREE_UNSIGNED (TREE_TYPE (expr)); | |
1673 | if (!uns) | |
05bccae2 RK |
1674 | return (TREE_INT_CST_LOW (expr) == ~ (unsigned HOST_WIDE_INT) 0 |
1675 | && TREE_INT_CST_HIGH (expr) == -1); | |
c6a1db6c | 1676 | |
8980b5a3 RK |
1677 | /* Note that using TYPE_PRECISION here is wrong. We care about the |
1678 | actual bits, not the (arbitrary) range of the type. */ | |
1679 | prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr))); | |
37366632 | 1680 | if (prec >= HOST_BITS_PER_WIDE_INT) |
c6a1db6c | 1681 | { |
05bccae2 RK |
1682 | HOST_WIDE_INT high_value; |
1683 | int shift_amount; | |
c6a1db6c | 1684 | |
37366632 | 1685 | shift_amount = prec - HOST_BITS_PER_WIDE_INT; |
c6a1db6c | 1686 | |
37366632 | 1687 | if (shift_amount > HOST_BITS_PER_WIDE_INT) |
c6a1db6c RS |
1688 | /* Can not handle precisions greater than twice the host int size. */ |
1689 | abort (); | |
37366632 | 1690 | else if (shift_amount == HOST_BITS_PER_WIDE_INT) |
c6a1db6c RS |
1691 | /* Shifting by the host word size is undefined according to the ANSI |
1692 | standard, so we must handle this as a special case. */ | |
1693 | high_value = -1; | |
1694 | else | |
37366632 | 1695 | high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1; |
c6a1db6c | 1696 | |
05bccae2 RK |
1697 | return (TREE_INT_CST_LOW (expr) == ~ (unsigned HOST_WIDE_INT) 0 |
1698 | && TREE_INT_CST_HIGH (expr) == high_value); | |
c6a1db6c RS |
1699 | } |
1700 | else | |
05bccae2 | 1701 | return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1; |
c6a1db6c RS |
1702 | } |
1703 | ||
1704 | /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only | |
1705 | one bit on). */ | |
1706 | ||
1707 | int | |
1708 | integer_pow2p (expr) | |
1709 | tree expr; | |
1710 | { | |
5cb1f2fa | 1711 | int prec; |
37366632 | 1712 | HOST_WIDE_INT high, low; |
c6a1db6c | 1713 | |
d964285c | 1714 | STRIP_NOPS (expr); |
c6a1db6c | 1715 | |
9ad265b0 RK |
1716 | if (TREE_CODE (expr) == COMPLEX_CST |
1717 | && integer_pow2p (TREE_REALPART (expr)) | |
1718 | && integer_zerop (TREE_IMAGPART (expr))) | |
1719 | return 1; | |
1720 | ||
1ac876be | 1721 | if (TREE_CODE (expr) != INTEGER_CST || TREE_CONSTANT_OVERFLOW (expr)) |
c6a1db6c RS |
1722 | return 0; |
1723 | ||
e5e809f4 | 1724 | prec = (POINTER_TYPE_P (TREE_TYPE (expr)) |
5cb1f2fa | 1725 | ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr))); |
c6a1db6c RS |
1726 | high = TREE_INT_CST_HIGH (expr); |
1727 | low = TREE_INT_CST_LOW (expr); | |
1728 | ||
5cb1f2fa RK |
1729 | /* First clear all bits that are beyond the type's precision in case |
1730 | we've been sign extended. */ | |
1731 | ||
1732 | if (prec == 2 * HOST_BITS_PER_WIDE_INT) | |
1733 | ; | |
1734 | else if (prec > HOST_BITS_PER_WIDE_INT) | |
1735 | high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); | |
1736 | else | |
1737 | { | |
1738 | high = 0; | |
1739 | if (prec < HOST_BITS_PER_WIDE_INT) | |
1740 | low &= ~((HOST_WIDE_INT) (-1) << prec); | |
1741 | } | |
1742 | ||
c6a1db6c RS |
1743 | if (high == 0 && low == 0) |
1744 | return 0; | |
1745 | ||
1746 | return ((high == 0 && (low & (low - 1)) == 0) | |
1747 | || (low == 0 && (high & (high - 1)) == 0)); | |
1748 | } | |
1749 | ||
5cb1f2fa RK |
1750 | /* Return the power of two represented by a tree node known to be a |
1751 | power of two. */ | |
1752 | ||
1753 | int | |
1754 | tree_log2 (expr) | |
1755 | tree expr; | |
1756 | { | |
1757 | int prec; | |
1758 | HOST_WIDE_INT high, low; | |
1759 | ||
1760 | STRIP_NOPS (expr); | |
1761 | ||
1762 | if (TREE_CODE (expr) == COMPLEX_CST) | |
1763 | return tree_log2 (TREE_REALPART (expr)); | |
1764 | ||
e5e809f4 | 1765 | prec = (POINTER_TYPE_P (TREE_TYPE (expr)) |
5cb1f2fa RK |
1766 | ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr))); |
1767 | ||
1768 | high = TREE_INT_CST_HIGH (expr); | |
1769 | low = TREE_INT_CST_LOW (expr); | |
1770 | ||
1771 | /* First clear all bits that are beyond the type's precision in case | |
1772 | we've been sign extended. */ | |
1773 | ||
1774 | if (prec == 2 * HOST_BITS_PER_WIDE_INT) | |
1775 | ; | |
1776 | else if (prec > HOST_BITS_PER_WIDE_INT) | |
1777 | high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); | |
1778 | else | |
1779 | { | |
1780 | high = 0; | |
1781 | if (prec < HOST_BITS_PER_WIDE_INT) | |
1782 | low &= ~((HOST_WIDE_INT) (-1) << prec); | |
1783 | } | |
1784 | ||
1785 | return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high) | |
1786 | : exact_log2 (low)); | |
1787 | } | |
1788 | ||
05bccae2 RK |
1789 | /* Similar, but return the largest integer Y such that 2 ** Y is less |
1790 | than or equal to EXPR. */ | |
1791 | ||
1792 | int | |
1793 | tree_floor_log2 (expr) | |
1794 | tree expr; | |
1795 | { | |
1796 | int prec; | |
1797 | HOST_WIDE_INT high, low; | |
1798 | ||
1799 | STRIP_NOPS (expr); | |
1800 | ||
1801 | if (TREE_CODE (expr) == COMPLEX_CST) | |
1802 | return tree_log2 (TREE_REALPART (expr)); | |
1803 | ||
1804 | prec = (POINTER_TYPE_P (TREE_TYPE (expr)) | |
1805 | ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr))); | |
1806 | ||
1807 | high = TREE_INT_CST_HIGH (expr); | |
1808 | low = TREE_INT_CST_LOW (expr); | |
1809 | ||
1810 | /* First clear all bits that are beyond the type's precision in case | |
1811 | we've been sign extended. Ignore if type's precision hasn't been set | |
1812 | since what we are doing is setting it. */ | |
1813 | ||
1814 | if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0) | |
1815 | ; | |
1816 | else if (prec > HOST_BITS_PER_WIDE_INT) | |
1817 | high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); | |
1818 | else | |
1819 | { | |
1820 | high = 0; | |
1821 | if (prec < HOST_BITS_PER_WIDE_INT) | |
1822 | low &= ~((HOST_WIDE_INT) (-1) << prec); | |
1823 | } | |
1824 | ||
1825 | return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high) | |
1826 | : floor_log2 (low)); | |
1827 | } | |
1828 | ||
c6a1db6c RS |
1829 | /* Return 1 if EXPR is the real constant zero. */ |
1830 | ||
1831 | int | |
1832 | real_zerop (expr) | |
1833 | tree expr; | |
1834 | { | |
d964285c | 1835 | STRIP_NOPS (expr); |
c6a1db6c | 1836 | |
9ad265b0 | 1837 | return ((TREE_CODE (expr) == REAL_CST |
1ac876be | 1838 | && ! TREE_CONSTANT_OVERFLOW (expr) |
9ad265b0 RK |
1839 | && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0)) |
1840 | || (TREE_CODE (expr) == COMPLEX_CST | |
1841 | && real_zerop (TREE_REALPART (expr)) | |
1842 | && real_zerop (TREE_IMAGPART (expr)))); | |
c6a1db6c RS |
1843 | } |
1844 | ||
9ad265b0 | 1845 | /* Return 1 if EXPR is the real constant one in real or complex form. */ |
c6a1db6c RS |
1846 | |
1847 | int | |
1848 | real_onep (expr) | |
1849 | tree expr; | |
1850 | { | |
d964285c | 1851 | STRIP_NOPS (expr); |
c6a1db6c | 1852 | |
9ad265b0 | 1853 | return ((TREE_CODE (expr) == REAL_CST |
1ac876be | 1854 | && ! TREE_CONSTANT_OVERFLOW (expr) |
9ad265b0 RK |
1855 | && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1)) |
1856 | || (TREE_CODE (expr) == COMPLEX_CST | |
1857 | && real_onep (TREE_REALPART (expr)) | |
1858 | && real_zerop (TREE_IMAGPART (expr)))); | |
c6a1db6c RS |
1859 | } |
1860 | ||
1861 | /* Return 1 if EXPR is the real constant two. */ | |
1862 | ||
1863 | int | |
1864 | real_twop (expr) | |
1865 | tree expr; | |
1866 | { | |
d964285c | 1867 | STRIP_NOPS (expr); |
c6a1db6c | 1868 | |
9ad265b0 | 1869 | return ((TREE_CODE (expr) == REAL_CST |
1ac876be | 1870 | && ! TREE_CONSTANT_OVERFLOW (expr) |
9ad265b0 RK |
1871 | && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2)) |
1872 | || (TREE_CODE (expr) == COMPLEX_CST | |
1873 | && real_twop (TREE_REALPART (expr)) | |
1874 | && real_zerop (TREE_IMAGPART (expr)))); | |
c6a1db6c RS |
1875 | } |
1876 | ||
1877 | /* Nonzero if EXP is a constant or a cast of a constant. */ | |
1878 | ||
1879 | int | |
1880 | really_constant_p (exp) | |
1881 | tree exp; | |
1882 | { | |
d964285c | 1883 | /* This is not quite the same as STRIP_NOPS. It does more. */ |
c6a1db6c RS |
1884 | while (TREE_CODE (exp) == NOP_EXPR |
1885 | || TREE_CODE (exp) == CONVERT_EXPR | |
1886 | || TREE_CODE (exp) == NON_LVALUE_EXPR) | |
1887 | exp = TREE_OPERAND (exp, 0); | |
1888 | return TREE_CONSTANT (exp); | |
1889 | } | |
1890 | \f | |
1891 | /* Return first list element whose TREE_VALUE is ELEM. | |
2a3c15b5 | 1892 | Return 0 if ELEM is not in LIST. */ |
c6a1db6c RS |
1893 | |
1894 | tree | |
1895 | value_member (elem, list) | |
1896 | tree elem, list; | |
1897 | { | |
1898 | while (list) | |
1899 | { | |
1900 | if (elem == TREE_VALUE (list)) | |
1901 | return list; | |
1902 | list = TREE_CHAIN (list); | |
1903 | } | |
1904 | return NULL_TREE; | |
1905 | } | |
1906 | ||
1907 | /* Return first list element whose TREE_PURPOSE is ELEM. | |
2a3c15b5 | 1908 | Return 0 if ELEM is not in LIST. */ |
c6a1db6c RS |
1909 | |
1910 | tree | |
1911 | purpose_member (elem, list) | |
1912 | tree elem, list; | |
1913 | { | |
1914 | while (list) | |
1915 | { | |
1916 | if (elem == TREE_PURPOSE (list)) | |
1917 | return list; | |
1918 | list = TREE_CHAIN (list); | |
1919 | } | |
1920 | return NULL_TREE; | |
1921 | } | |
1922 | ||
1923 | /* Return first list element whose BINFO_TYPE is ELEM. | |
2a3c15b5 | 1924 | Return 0 if ELEM is not in LIST. */ |
c6a1db6c RS |
1925 | |
1926 | tree | |
1927 | binfo_member (elem, list) | |
1928 | tree elem, list; | |
1929 | { | |
1930 | while (list) | |
1931 | { | |
1932 | if (elem == BINFO_TYPE (list)) | |
1933 | return list; | |
1934 | list = TREE_CHAIN (list); | |
1935 | } | |
1936 | return NULL_TREE; | |
1937 | } | |
1938 | ||
0f41302f | 1939 | /* Return nonzero if ELEM is part of the chain CHAIN. */ |
c6a1db6c RS |
1940 | |
1941 | int | |
1942 | chain_member (elem, chain) | |
1943 | tree elem, chain; | |
1944 | { | |
1945 | while (chain) | |
1946 | { | |
1947 | if (elem == chain) | |
1948 | return 1; | |
1949 | chain = TREE_CHAIN (chain); | |
1950 | } | |
1951 | ||
1952 | return 0; | |
1953 | } | |
1954 | ||
1a2927d2 | 1955 | /* Return nonzero if ELEM is equal to TREE_VALUE (CHAIN) for any piece of |
d4b60170 RK |
1956 | chain CHAIN. This and the next function are currently unused, but |
1957 | are retained for completeness. */ | |
1a2927d2 RK |
1958 | |
1959 | int | |
1960 | chain_member_value (elem, chain) | |
1961 | tree elem, chain; | |
1962 | { | |
1963 | while (chain) | |
1964 | { | |
1965 | if (elem == TREE_VALUE (chain)) | |
1966 | return 1; | |
1967 | chain = TREE_CHAIN (chain); | |
1968 | } | |
1969 | ||
1970 | return 0; | |
1971 | } | |
1972 | ||
33a79dfa | 1973 | /* Return nonzero if ELEM is equal to TREE_PURPOSE (CHAIN) |
0f41302f | 1974 | for any piece of chain CHAIN. */ |
0bcec367 RK |
1975 | |
1976 | int | |
1977 | chain_member_purpose (elem, chain) | |
1978 | tree elem, chain; | |
1979 | { | |
0bcec367 RK |
1980 | while (chain) |
1981 | { | |
33a79dfa | 1982 | if (elem == TREE_PURPOSE (chain)) |
0bcec367 RK |
1983 | return 1; |
1984 | chain = TREE_CHAIN (chain); | |
1985 | } | |
1986 | ||
1987 | return 0; | |
1988 | } | |
1989 | ||
c6a1db6c RS |
1990 | /* Return the length of a chain of nodes chained through TREE_CHAIN. |
1991 | We expect a null pointer to mark the end of the chain. | |
1992 | This is the Lisp primitive `length'. */ | |
1993 | ||
1994 | int | |
1995 | list_length (t) | |
1996 | tree t; | |
1997 | { | |
1998 | register tree tail; | |
1999 | register int len = 0; | |
2000 | ||
2001 | for (tail = t; tail; tail = TREE_CHAIN (tail)) | |
2002 | len++; | |
2003 | ||
2004 | return len; | |
2005 | } | |
2006 | ||
2007 | /* Concatenate two chains of nodes (chained through TREE_CHAIN) | |
2008 | by modifying the last node in chain 1 to point to chain 2. | |
2009 | This is the Lisp primitive `nconc'. */ | |
2010 | ||
2011 | tree | |
2012 | chainon (op1, op2) | |
2013 | tree op1, op2; | |
2014 | { | |
c6a1db6c RS |
2015 | |
2016 | if (op1) | |
2017 | { | |
1810c3fa | 2018 | register tree t1; |
f4524c9e | 2019 | #ifdef ENABLE_TREE_CHECKING |
1810c3fa | 2020 | register tree t2; |
cbbfcb3b | 2021 | #endif |
1810c3fa RK |
2022 | |
2023 | for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1)) | |
2024 | ; | |
2025 | TREE_CHAIN (t1) = op2; | |
f4524c9e | 2026 | #ifdef ENABLE_TREE_CHECKING |
1810c3fa RK |
2027 | for (t2 = op2; t2; t2 = TREE_CHAIN (t2)) |
2028 | if (t2 == t1) | |
2029 | abort (); /* Circularity created. */ | |
0f4668ef | 2030 | #endif |
c6a1db6c RS |
2031 | return op1; |
2032 | } | |
2033 | else return op2; | |
2034 | } | |
2035 | ||
2036 | /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */ | |
2037 | ||
2038 | tree | |
2039 | tree_last (chain) | |
2040 | register tree chain; | |
2041 | { | |
2042 | register tree next; | |
2043 | if (chain) | |
5e9defae | 2044 | while ((next = TREE_CHAIN (chain))) |
c6a1db6c RS |
2045 | chain = next; |
2046 | return chain; | |
2047 | } | |
2048 | ||
2049 | /* Reverse the order of elements in the chain T, | |
2050 | and return the new head of the chain (old last element). */ | |
2051 | ||
2052 | tree | |
2053 | nreverse (t) | |
2054 | tree t; | |
2055 | { | |
2056 | register tree prev = 0, decl, next; | |
2057 | for (decl = t; decl; decl = next) | |
2058 | { | |
2059 | next = TREE_CHAIN (decl); | |
2060 | TREE_CHAIN (decl) = prev; | |
2061 | prev = decl; | |
2062 | } | |
2063 | return prev; | |
2064 | } | |
2065 | ||
2066 | /* Given a chain CHAIN of tree nodes, | |
2067 | construct and return a list of those nodes. */ | |
2068 | ||
2069 | tree | |
2070 | listify (chain) | |
2071 | tree chain; | |
2072 | { | |
2073 | tree result = NULL_TREE; | |
2074 | tree in_tail = chain; | |
2075 | tree out_tail = NULL_TREE; | |
2076 | ||
2077 | while (in_tail) | |
2078 | { | |
2079 | tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE); | |
2080 | if (out_tail) | |
2081 | TREE_CHAIN (out_tail) = next; | |
2082 | else | |
2083 | result = next; | |
2084 | out_tail = next; | |
2085 | in_tail = TREE_CHAIN (in_tail); | |
2086 | } | |
2087 | ||
2088 | return result; | |
2089 | } | |
2090 | \f | |
2091 | /* Return a newly created TREE_LIST node whose | |
2092 | purpose and value fields are PARM and VALUE. */ | |
2093 | ||
2094 | tree | |
2095 | build_tree_list (parm, value) | |
2096 | tree parm, value; | |
2097 | { | |
2098 | register tree t = make_node (TREE_LIST); | |
2099 | TREE_PURPOSE (t) = parm; | |
2100 | TREE_VALUE (t) = value; | |
2101 | return t; | |
2102 | } | |
2103 | ||
2104 | /* Similar, but build on the temp_decl_obstack. */ | |
2105 | ||
2106 | tree | |
2107 | build_decl_list (parm, value) | |
2108 | tree parm, value; | |
2109 | { | |
2110 | register tree node; | |
2111 | register struct obstack *ambient_obstack = current_obstack; | |
d4b60170 | 2112 | |
c6a1db6c RS |
2113 | current_obstack = &temp_decl_obstack; |
2114 | node = build_tree_list (parm, value); | |
2115 | current_obstack = ambient_obstack; | |
2116 | return node; | |
2117 | } | |
2118 | ||
f0632762 JM |
2119 | /* Similar, but build on the expression_obstack. */ |
2120 | ||
2121 | tree | |
2122 | build_expr_list (parm, value) | |
2123 | tree parm, value; | |
2124 | { | |
2125 | register tree node; | |
2126 | register struct obstack *ambient_obstack = current_obstack; | |
d4b60170 | 2127 | |
f0632762 JM |
2128 | current_obstack = expression_obstack; |
2129 | node = build_tree_list (parm, value); | |
2130 | current_obstack = ambient_obstack; | |
2131 | return node; | |
2132 | } | |
2133 | ||
c6a1db6c RS |
2134 | /* Return a newly created TREE_LIST node whose |
2135 | purpose and value fields are PARM and VALUE | |
2136 | and whose TREE_CHAIN is CHAIN. */ | |
2137 | ||
2138 | tree | |
2139 | tree_cons (purpose, value, chain) | |
2140 | tree purpose, value, chain; | |
2141 | { | |
a3770a81 RH |
2142 | register tree node; |
2143 | ||
2144 | if (ggc_p) | |
2145 | node = ggc_alloc_tree (sizeof (struct tree_list)); | |
2146 | else | |
2147 | { | |
2148 | node = (tree) obstack_alloc (current_obstack, sizeof (struct tree_list)); | |
341a243e | 2149 | memset (node, 0, sizeof (struct tree_common)); |
a3770a81 RH |
2150 | } |
2151 | ||
c6a1db6c RS |
2152 | #ifdef GATHER_STATISTICS |
2153 | tree_node_counts[(int)x_kind]++; | |
2154 | tree_node_sizes[(int)x_kind] += sizeof (struct tree_list); | |
2155 | #endif | |
2156 | ||
c6a1db6c | 2157 | TREE_SET_CODE (node, TREE_LIST); |
23dfa477 | 2158 | TREE_SET_PERMANENT (node); |
c6a1db6c RS |
2159 | |
2160 | TREE_CHAIN (node) = chain; | |
2161 | TREE_PURPOSE (node) = purpose; | |
2162 | TREE_VALUE (node) = value; | |
2163 | return node; | |
2164 | } | |
2165 | ||
2166 | /* Similar, but build on the temp_decl_obstack. */ | |
2167 | ||
2168 | tree | |
2169 | decl_tree_cons (purpose, value, chain) | |
2170 | tree purpose, value, chain; | |
2171 | { | |
2172 | register tree node; | |
2173 | register struct obstack *ambient_obstack = current_obstack; | |
d4b60170 | 2174 | |
c6a1db6c RS |
2175 | current_obstack = &temp_decl_obstack; |
2176 | node = tree_cons (purpose, value, chain); | |
f0632762 JM |
2177 | current_obstack = ambient_obstack; |
2178 | return node; | |
2179 | } | |
2180 | ||
2181 | /* Similar, but build on the expression_obstack. */ | |
2182 | ||
2183 | tree | |
2184 | expr_tree_cons (purpose, value, chain) | |
2185 | tree purpose, value, chain; | |
2186 | { | |
2187 | register tree node; | |
2188 | register struct obstack *ambient_obstack = current_obstack; | |
d4b60170 | 2189 | |
f0632762 JM |
2190 | current_obstack = expression_obstack; |
2191 | node = tree_cons (purpose, value, chain); | |
c6a1db6c RS |
2192 | current_obstack = ambient_obstack; |
2193 | return node; | |
2194 | } | |
2195 | ||
2196 | /* Same as `tree_cons' but make a permanent object. */ | |
2197 | ||
2198 | tree | |
2199 | perm_tree_cons (purpose, value, chain) | |
2200 | tree purpose, value, chain; | |
2201 | { | |
2202 | register tree node; | |
2203 | register struct obstack *ambient_obstack = current_obstack; | |
c6a1db6c | 2204 | |
d4b60170 | 2205 | current_obstack = &permanent_obstack; |
c6a1db6c RS |
2206 | node = tree_cons (purpose, value, chain); |
2207 | current_obstack = ambient_obstack; | |
2208 | return node; | |
2209 | } | |
2210 | ||
2211 | /* Same as `tree_cons', but make this node temporary, regardless. */ | |
2212 | ||
2213 | tree | |
2214 | temp_tree_cons (purpose, value, chain) | |
2215 | tree purpose, value, chain; | |
2216 | { | |
2217 | register tree node; | |
2218 | register struct obstack *ambient_obstack = current_obstack; | |
c6a1db6c | 2219 | |
d4b60170 | 2220 | current_obstack = &temporary_obstack; |
c6a1db6c RS |
2221 | node = tree_cons (purpose, value, chain); |
2222 | current_obstack = ambient_obstack; | |
2223 | return node; | |
2224 | } | |
2225 | ||
2226 | /* Same as `tree_cons', but save this node if the function's RTL is saved. */ | |
2227 | ||
2228 | tree | |
2229 | saveable_tree_cons (purpose, value, chain) | |
2230 | tree purpose, value, chain; | |
2231 | { | |
2232 | register tree node; | |
2233 | register struct obstack *ambient_obstack = current_obstack; | |
c6a1db6c | 2234 | |
d4b60170 | 2235 | current_obstack = saveable_obstack; |
c6a1db6c RS |
2236 | node = tree_cons (purpose, value, chain); |
2237 | current_obstack = ambient_obstack; | |
2238 | return node; | |
2239 | } | |
2240 | \f | |
2241 | /* Return the size nominally occupied by an object of type TYPE | |
2242 | when it resides in memory. The value is measured in units of bytes, | |
2243 | and its data type is that normally used for type sizes | |
2244 | (which is the first type created by make_signed_type or | |
2245 | make_unsigned_type). */ | |
2246 | ||
2247 | tree | |
2248 | size_in_bytes (type) | |
2249 | tree type; | |
2250 | { | |
cdc5a032 RS |
2251 | tree t; |
2252 | ||
c6a1db6c RS |
2253 | if (type == error_mark_node) |
2254 | return integer_zero_node; | |
ead17059 | 2255 | |
c6a1db6c | 2256 | type = TYPE_MAIN_VARIANT (type); |
ead17059 | 2257 | t = TYPE_SIZE_UNIT (type); |
d4b60170 | 2258 | |
ead17059 | 2259 | if (t == 0) |
c6a1db6c | 2260 | { |
37366632 | 2261 | incomplete_type_error (NULL_TREE, type); |
c6a1db6c RS |
2262 | return integer_zero_node; |
2263 | } | |
d4b60170 | 2264 | |
4d7d0403 | 2265 | if (TREE_CODE (t) == INTEGER_CST) |
b6542989 | 2266 | force_fit_type (t, 0); |
ead17059 | 2267 | |
cdc5a032 | 2268 | return t; |
c6a1db6c RS |
2269 | } |
2270 | ||
e5e809f4 JL |
2271 | /* Return the size of TYPE (in bytes) as a wide integer |
2272 | or return -1 if the size can vary or is larger than an integer. */ | |
c6a1db6c | 2273 | |
e5e809f4 | 2274 | HOST_WIDE_INT |
c6a1db6c RS |
2275 | int_size_in_bytes (type) |
2276 | tree type; | |
2277 | { | |
e5e809f4 JL |
2278 | tree t; |
2279 | ||
c6a1db6c RS |
2280 | if (type == error_mark_node) |
2281 | return 0; | |
e5e809f4 | 2282 | |
c6a1db6c | 2283 | type = TYPE_MAIN_VARIANT (type); |
ead17059 RH |
2284 | t = TYPE_SIZE_UNIT (type); |
2285 | if (t == 0 | |
2286 | || TREE_CODE (t) != INTEGER_CST | |
d4b60170 | 2287 | || TREE_OVERFLOW (t) |
ead17059 | 2288 | || TREE_INT_CST_HIGH (t) != 0) |
c6a1db6c | 2289 | return -1; |
e5e809f4 JL |
2290 | |
2291 | return TREE_INT_CST_LOW (t); | |
c6a1db6c | 2292 | } |
729a2125 RK |
2293 | |
2294 | /* Return the strictest alignment, in bits, that T is known to have. */ | |
2295 | ||
2296 | unsigned int | |
2297 | expr_align (t) | |
2298 | tree t; | |
2299 | { | |
2300 | unsigned int align0, align1; | |
2301 | ||
2302 | switch (TREE_CODE (t)) | |
2303 | { | |
2304 | case NOP_EXPR: case CONVERT_EXPR: case NON_LVALUE_EXPR: | |
2305 | /* If we have conversions, we know that the alignment of the | |
2306 | object must meet each of the alignments of the types. */ | |
2307 | align0 = expr_align (TREE_OPERAND (t, 0)); | |
2308 | align1 = TYPE_ALIGN (TREE_TYPE (t)); | |
2309 | return MAX (align0, align1); | |
2310 | ||
2311 | case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR: | |
2312 | case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR: | |
2313 | case WITH_RECORD_EXPR: case CLEANUP_POINT_EXPR: case UNSAVE_EXPR: | |
2314 | /* These don't change the alignment of an object. */ | |
2315 | return expr_align (TREE_OPERAND (t, 0)); | |
2316 | ||
2317 | case COND_EXPR: | |
2318 | /* The best we can do is say that the alignment is the least aligned | |
2319 | of the two arms. */ | |
2320 | align0 = expr_align (TREE_OPERAND (t, 1)); | |
2321 | align1 = expr_align (TREE_OPERAND (t, 2)); | |
2322 | return MIN (align0, align1); | |
2323 | ||
06ceef4e | 2324 | case LABEL_DECL: case CONST_DECL: |
729a2125 RK |
2325 | case VAR_DECL: case PARM_DECL: case RESULT_DECL: |
2326 | if (DECL_ALIGN (t) != 0) | |
2327 | return DECL_ALIGN (t); | |
2328 | break; | |
2329 | ||
06ceef4e RK |
2330 | case FUNCTION_DECL: |
2331 | return FUNCTION_BOUNDARY; | |
2332 | ||
729a2125 RK |
2333 | default: |
2334 | break; | |
2335 | } | |
2336 | ||
2337 | /* Otherwise take the alignment from that of the type. */ | |
2338 | return TYPE_ALIGN (TREE_TYPE (t)); | |
2339 | } | |
c0560b8b RK |
2340 | \f |
2341 | /* Return, as a tree node, the number of elements for TYPE (which is an | |
d26f8097 | 2342 | ARRAY_TYPE) minus one. This counts only elements of the top array. */ |
c6a1db6c RS |
2343 | |
2344 | tree | |
2345 | array_type_nelts (type) | |
2346 | tree type; | |
2347 | { | |
7671d67b BK |
2348 | tree index_type, min, max; |
2349 | ||
2350 | /* If they did it with unspecified bounds, then we should have already | |
2351 | given an error about it before we got here. */ | |
2352 | if (! TYPE_DOMAIN (type)) | |
2353 | return error_mark_node; | |
2354 | ||
2355 | index_type = TYPE_DOMAIN (type); | |
2356 | min = TYPE_MIN_VALUE (index_type); | |
2357 | max = TYPE_MAX_VALUE (index_type); | |
83b853c9 | 2358 | |
83b853c9 JM |
2359 | return (integer_zerop (min) |
2360 | ? max | |
2361 | : fold (build (MINUS_EXPR, TREE_TYPE (max), max, min))); | |
c6a1db6c RS |
2362 | } |
2363 | \f | |
2364 | /* Return nonzero if arg is static -- a reference to an object in | |
2365 | static storage. This is not the same as the C meaning of `static'. */ | |
2366 | ||
2367 | int | |
2368 | staticp (arg) | |
2369 | tree arg; | |
2370 | { | |
2371 | switch (TREE_CODE (arg)) | |
2372 | { | |
c6a1db6c | 2373 | case FUNCTION_DECL: |
1324c5de | 2374 | /* Nested functions aren't static, since taking their address |
86270344 | 2375 | involves a trampoline. */ |
27da1b4d MK |
2376 | return (decl_function_context (arg) == 0 || DECL_NO_STATIC_CHAIN (arg)) |
2377 | && ! DECL_NON_ADDR_CONST_P (arg); | |
2378 | ||
86270344 | 2379 | case VAR_DECL: |
27da1b4d MK |
2380 | return (TREE_STATIC (arg) || DECL_EXTERNAL (arg)) |
2381 | && ! DECL_NON_ADDR_CONST_P (arg); | |
c6a1db6c | 2382 | |
492c86a4 RK |
2383 | case CONSTRUCTOR: |
2384 | return TREE_STATIC (arg); | |
2385 | ||
c6a1db6c RS |
2386 | case STRING_CST: |
2387 | return 1; | |
2388 | ||
f7fa6ef9 RK |
2389 | /* If we are referencing a bitfield, we can't evaluate an |
2390 | ADDR_EXPR at compile time and so it isn't a constant. */ | |
c6a1db6c | 2391 | case COMPONENT_REF: |
f7fa6ef9 RK |
2392 | return (! DECL_BIT_FIELD (TREE_OPERAND (arg, 1)) |
2393 | && staticp (TREE_OPERAND (arg, 0))); | |
2394 | ||
c6a1db6c | 2395 | case BIT_FIELD_REF: |
f7fa6ef9 | 2396 | return 0; |
c6a1db6c | 2397 | |
2cd2a93e RK |
2398 | #if 0 |
2399 | /* This case is technically correct, but results in setting | |
2400 | TREE_CONSTANT on ADDR_EXPRs that cannot be evaluated at | |
2401 | compile time. */ | |
c6a1db6c RS |
2402 | case INDIRECT_REF: |
2403 | return TREE_CONSTANT (TREE_OPERAND (arg, 0)); | |
2cd2a93e | 2404 | #endif |
c6a1db6c RS |
2405 | |
2406 | case ARRAY_REF: | |
2407 | if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST | |
2408 | && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST) | |
2409 | return staticp (TREE_OPERAND (arg, 0)); | |
c6a1db6c | 2410 | |
e9a25f70 JL |
2411 | default: |
2412 | return 0; | |
2413 | } | |
c6a1db6c RS |
2414 | } |
2415 | \f | |
3aa77500 RS |
2416 | /* Wrap a SAVE_EXPR around EXPR, if appropriate. |
2417 | Do this to any expression which may be used in more than one place, | |
2418 | but must be evaluated only once. | |
2419 | ||
2420 | Normally, expand_expr would reevaluate the expression each time. | |
2421 | Calling save_expr produces something that is evaluated and recorded | |
2422 | the first time expand_expr is called on it. Subsequent calls to | |
2423 | expand_expr just reuse the recorded value. | |
2424 | ||
2425 | The call to expand_expr that generates code that actually computes | |
2426 | the value is the first call *at compile time*. Subsequent calls | |
2427 | *at compile time* generate code to use the saved value. | |
2428 | This produces correct result provided that *at run time* control | |
2429 | always flows through the insns made by the first expand_expr | |
2430 | before reaching the other places where the save_expr was evaluated. | |
2431 | You, the caller of save_expr, must make sure this is so. | |
2432 | ||
2433 | Constants, and certain read-only nodes, are returned with no | |
2434 | SAVE_EXPR because that is safe. Expressions containing placeholders | |
c5af9901 RK |
2435 | are not touched; see tree.def for an explanation of what these |
2436 | are used for. */ | |
c6a1db6c RS |
2437 | |
2438 | tree | |
2439 | save_expr (expr) | |
2440 | tree expr; | |
2441 | { | |
2442 | register tree t = fold (expr); | |
2443 | ||
2444 | /* We don't care about whether this can be used as an lvalue in this | |
2445 | context. */ | |
2446 | while (TREE_CODE (t) == NON_LVALUE_EXPR) | |
2447 | t = TREE_OPERAND (t, 0); | |
2448 | ||
2449 | /* If the tree evaluates to a constant, then we don't want to hide that | |
2450 | fact (i.e. this allows further folding, and direct checks for constants). | |
af929c62 | 2451 | However, a read-only object that has side effects cannot be bypassed. |
c6a1db6c | 2452 | Since it is no problem to reevaluate literals, we just return the |
0f41302f | 2453 | literal node. */ |
c6a1db6c | 2454 | |
af929c62 | 2455 | if (TREE_CONSTANT (t) || (TREE_READONLY (t) && ! TREE_SIDE_EFFECTS (t)) |
e0094edb | 2456 | || TREE_CODE (t) == SAVE_EXPR || TREE_CODE (t) == ERROR_MARK) |
c6a1db6c RS |
2457 | return t; |
2458 | ||
dec20b4b RK |
2459 | /* If T contains a PLACEHOLDER_EXPR, we must evaluate it each time, since |
2460 | it means that the size or offset of some field of an object depends on | |
2461 | the value within another field. | |
2462 | ||
2463 | Note that it must not be the case that T contains both a PLACEHOLDER_EXPR | |
2464 | and some variable since it would then need to be both evaluated once and | |
2465 | evaluated more than once. Front-ends must assure this case cannot | |
2466 | happen by surrounding any such subexpressions in their own SAVE_EXPR | |
2467 | and forcing evaluation at the proper time. */ | |
2468 | if (contains_placeholder_p (t)) | |
2469 | return t; | |
2470 | ||
37366632 | 2471 | t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE); |
c6a1db6c RS |
2472 | |
2473 | /* This expression might be placed ahead of a jump to ensure that the | |
2474 | value was computed on both sides of the jump. So make sure it isn't | |
2475 | eliminated as dead. */ | |
2476 | TREE_SIDE_EFFECTS (t) = 1; | |
2477 | return t; | |
2478 | } | |
679163cf MS |
2479 | |
2480 | /* Arrange for an expression to be expanded multiple independent | |
2481 | times. This is useful for cleanup actions, as the backend can | |
2482 | expand them multiple times in different places. */ | |
0f41302f | 2483 | |
679163cf MS |
2484 | tree |
2485 | unsave_expr (expr) | |
2486 | tree expr; | |
2487 | { | |
2488 | tree t; | |
2489 | ||
2490 | /* If this is already protected, no sense in protecting it again. */ | |
2491 | if (TREE_CODE (expr) == UNSAVE_EXPR) | |
2492 | return expr; | |
2493 | ||
2494 | t = build1 (UNSAVE_EXPR, TREE_TYPE (expr), expr); | |
2495 | TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (expr); | |
2496 | return t; | |
2497 | } | |
2498 | ||
b7f6588d JM |
2499 | /* Returns the index of the first non-tree operand for CODE, or the number |
2500 | of operands if all are trees. */ | |
2501 | ||
2502 | int | |
2503 | first_rtl_op (code) | |
2504 | enum tree_code code; | |
2505 | { | |
2506 | switch (code) | |
2507 | { | |
2508 | case SAVE_EXPR: | |
2509 | return 2; | |
8dd858ca | 2510 | case GOTO_SUBROUTINE_EXPR: |
b7f6588d JM |
2511 | case RTL_EXPR: |
2512 | return 0; | |
2513 | case CALL_EXPR: | |
2514 | return 2; | |
2515 | case WITH_CLEANUP_EXPR: | |
2516 | /* Should be defined to be 2. */ | |
2517 | return 1; | |
2518 | case METHOD_CALL_EXPR: | |
2519 | return 3; | |
2520 | default: | |
2521 | return tree_code_length [(int) code]; | |
2522 | } | |
2523 | } | |
2524 | ||
582db8e4 MM |
2525 | /* Perform any modifications to EXPR required when it is unsaved. Does |
2526 | not recurse into EXPR's subtrees. */ | |
0f41302f | 2527 | |
582db8e4 MM |
2528 | void |
2529 | unsave_expr_1 (expr) | |
679163cf MS |
2530 | tree expr; |
2531 | { | |
582db8e4 | 2532 | switch (TREE_CODE (expr)) |
679163cf MS |
2533 | { |
2534 | case SAVE_EXPR: | |
d4b60170 | 2535 | if (! SAVE_EXPR_PERSISTENT_P (expr)) |
d26f8097 | 2536 | SAVE_EXPR_RTL (expr) = 0; |
679163cf MS |
2537 | break; |
2538 | ||
2539 | case TARGET_EXPR: | |
4847c938 MS |
2540 | TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 3); |
2541 | TREE_OPERAND (expr, 3) = NULL_TREE; | |
679163cf MS |
2542 | break; |
2543 | ||
2544 | case RTL_EXPR: | |
4847c938 | 2545 | /* I don't yet know how to emit a sequence multiple times. */ |
d4b60170 | 2546 | if (RTL_EXPR_SEQUENCE (expr) != 0) |
4847c938 | 2547 | abort (); |
679163cf MS |
2548 | break; |
2549 | ||
2550 | case CALL_EXPR: | |
4d12b2fe | 2551 | CALL_EXPR_RTL (expr) = 0; |
679163cf | 2552 | break; |
e9a25f70 JL |
2553 | |
2554 | default: | |
d4b60170 | 2555 | if (lang_unsave_expr_now != 0) |
0a818f84 | 2556 | (*lang_unsave_expr_now) (expr); |
e9a25f70 | 2557 | break; |
679163cf | 2558 | } |
582db8e4 MM |
2559 | } |
2560 | ||
2561 | /* Helper function for unsave_expr_now. */ | |
2562 | ||
2563 | static void | |
2564 | unsave_expr_now_r (expr) | |
2565 | tree expr; | |
2566 | { | |
2567 | enum tree_code code; | |
2568 | ||
7a12ace5 | 2569 | /* There's nothing to do for NULL_TREE. */ |
d4b60170 | 2570 | if (expr == 0) |
7a12ace5 MM |
2571 | return; |
2572 | ||
582db8e4 | 2573 | unsave_expr_1 (expr); |
679163cf | 2574 | |
582db8e4 MM |
2575 | code = TREE_CODE (expr); |
2576 | if (code == CALL_EXPR | |
2577 | && TREE_OPERAND (expr, 1) | |
2578 | && TREE_CODE (TREE_OPERAND (expr, 1)) == TREE_LIST) | |
2579 | { | |
2580 | tree exp = TREE_OPERAND (expr, 1); | |
2581 | while (exp) | |
2582 | { | |
2583 | unsave_expr_now_r (TREE_VALUE (exp)); | |
2584 | exp = TREE_CHAIN (exp); | |
2585 | } | |
2586 | } | |
2587 | ||
679163cf MS |
2588 | switch (TREE_CODE_CLASS (code)) |
2589 | { | |
2590 | case 'c': /* a constant */ | |
2591 | case 't': /* a type node */ | |
2592 | case 'x': /* something random, like an identifier or an ERROR_MARK. */ | |
2593 | case 'd': /* A decl node */ | |
2594 | case 'b': /* A block node */ | |
582db8e4 | 2595 | break; |
679163cf MS |
2596 | |
2597 | case 'e': /* an expression */ | |
2598 | case 'r': /* a reference */ | |
2599 | case 's': /* an expression with side effects */ | |
2600 | case '<': /* a comparison expression */ | |
2601 | case '2': /* a binary arithmetic expression */ | |
2602 | case '1': /* a unary arithmetic expression */ | |
582db8e4 MM |
2603 | { |
2604 | int i; | |
2605 | ||
2606 | for (i = first_rtl_op (code) - 1; i >= 0; i--) | |
2607 | unsave_expr_now_r (TREE_OPERAND (expr, i)); | |
2608 | } | |
2609 | break; | |
679163cf MS |
2610 | |
2611 | default: | |
2612 | abort (); | |
2613 | } | |
2614 | } | |
582db8e4 MM |
2615 | |
2616 | /* Modify a tree in place so that all the evaluate only once things | |
2617 | are cleared out. Return the EXPR given. */ | |
2618 | ||
2619 | tree | |
2620 | unsave_expr_now (expr) | |
2621 | tree expr; | |
2622 | { | |
d4b60170 | 2623 | if (lang_unsave!= 0) |
582db8e4 MM |
2624 | (*lang_unsave) (&expr); |
2625 | else | |
2626 | unsave_expr_now_r (expr); | |
2627 | ||
2628 | return expr; | |
2629 | } | |
dec20b4b RK |
2630 | \f |
2631 | /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size | |
3910a7cb | 2632 | or offset that depends on a field within a record. */ |
dec20b4b RK |
2633 | |
2634 | int | |
2635 | contains_placeholder_p (exp) | |
2636 | tree exp; | |
2637 | { | |
2638 | register enum tree_code code = TREE_CODE (exp); | |
e9a25f70 | 2639 | int result; |
dec20b4b | 2640 | |
67c8d7de RK |
2641 | /* If we have a WITH_RECORD_EXPR, it "cancels" any PLACEHOLDER_EXPR |
2642 | in it since it is supplying a value for it. */ | |
2643 | if (code == WITH_RECORD_EXPR) | |
2644 | return 0; | |
a5ee6e44 | 2645 | else if (code == PLACEHOLDER_EXPR) |
cc3c7c13 | 2646 | return 1; |
67c8d7de | 2647 | |
dec20b4b RK |
2648 | switch (TREE_CODE_CLASS (code)) |
2649 | { | |
2650 | case 'r': | |
cc3c7c13 RK |
2651 | /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit |
2652 | position computations since they will be converted into a | |
2653 | WITH_RECORD_EXPR involving the reference, which will assume | |
2654 | here will be valid. */ | |
2655 | return contains_placeholder_p (TREE_OPERAND (exp, 0)); | |
dec20b4b | 2656 | |
e9a25f70 JL |
2657 | case 'x': |
2658 | if (code == TREE_LIST) | |
2659 | return (contains_placeholder_p (TREE_VALUE (exp)) | |
2660 | || (TREE_CHAIN (exp) != 0 | |
2661 | && contains_placeholder_p (TREE_CHAIN (exp)))); | |
2662 | break; | |
2663 | ||
dec20b4b RK |
2664 | case '1': |
2665 | case '2': case '<': | |
2666 | case 'e': | |
3910a7cb RK |
2667 | switch (code) |
2668 | { | |
2669 | case COMPOUND_EXPR: | |
2670 | /* Ignoring the first operand isn't quite right, but works best. */ | |
cc3c7c13 | 2671 | return contains_placeholder_p (TREE_OPERAND (exp, 1)); |
3910a7cb RK |
2672 | |
2673 | case RTL_EXPR: | |
2674 | case CONSTRUCTOR: | |
2675 | return 0; | |
2676 | ||
2677 | case COND_EXPR: | |
cc3c7c13 RK |
2678 | return (contains_placeholder_p (TREE_OPERAND (exp, 0)) |
2679 | || contains_placeholder_p (TREE_OPERAND (exp, 1)) | |
2680 | || contains_placeholder_p (TREE_OPERAND (exp, 2))); | |
3910a7cb RK |
2681 | |
2682 | case SAVE_EXPR: | |
e9a25f70 JL |
2683 | /* If we already know this doesn't have a placeholder, don't |
2684 | check again. */ | |
2685 | if (SAVE_EXPR_NOPLACEHOLDER (exp) || SAVE_EXPR_RTL (exp) != 0) | |
2686 | return 0; | |
2687 | ||
2688 | SAVE_EXPR_NOPLACEHOLDER (exp) = 1; | |
2689 | result = contains_placeholder_p (TREE_OPERAND (exp, 0)); | |
2690 | if (result) | |
2691 | SAVE_EXPR_NOPLACEHOLDER (exp) = 0; | |
2692 | ||
2693 | return result; | |
2694 | ||
2695 | case CALL_EXPR: | |
2696 | return (TREE_OPERAND (exp, 1) != 0 | |
2697 | && contains_placeholder_p (TREE_OPERAND (exp, 1))); | |
2698 | ||
2699 | default: | |
2700 | break; | |
3910a7cb RK |
2701 | } |
2702 | ||
dec20b4b RK |
2703 | switch (tree_code_length[(int) code]) |
2704 | { | |
2705 | case 1: | |
cc3c7c13 | 2706 | return contains_placeholder_p (TREE_OPERAND (exp, 0)); |
dec20b4b | 2707 | case 2: |
cc3c7c13 RK |
2708 | return (contains_placeholder_p (TREE_OPERAND (exp, 0)) |
2709 | || contains_placeholder_p (TREE_OPERAND (exp, 1))); | |
e9a25f70 JL |
2710 | default: |
2711 | return 0; | |
dec20b4b | 2712 | } |
dec20b4b | 2713 | |
e9a25f70 JL |
2714 | default: |
2715 | return 0; | |
2716 | } | |
1160f9ec | 2717 | return 0; |
dec20b4b | 2718 | } |
b7f6588d JM |
2719 | |
2720 | /* Return 1 if EXP contains any expressions that produce cleanups for an | |
2721 | outer scope to deal with. Used by fold. */ | |
2722 | ||
2723 | int | |
2724 | has_cleanups (exp) | |
2725 | tree exp; | |
2726 | { | |
2727 | int i, nops, cmp; | |
2728 | ||
2729 | if (! TREE_SIDE_EFFECTS (exp)) | |
2730 | return 0; | |
2731 | ||
2732 | switch (TREE_CODE (exp)) | |
2733 | { | |
2734 | case TARGET_EXPR: | |
8dd858ca | 2735 | case GOTO_SUBROUTINE_EXPR: |
b7f6588d JM |
2736 | case WITH_CLEANUP_EXPR: |
2737 | return 1; | |
2738 | ||
2739 | case CLEANUP_POINT_EXPR: | |
2740 | return 0; | |
2741 | ||
2742 | case CALL_EXPR: | |
2743 | for (exp = TREE_OPERAND (exp, 1); exp; exp = TREE_CHAIN (exp)) | |
2744 | { | |
2745 | cmp = has_cleanups (TREE_VALUE (exp)); | |
2746 | if (cmp) | |
2747 | return cmp; | |
2748 | } | |
2749 | return 0; | |
2750 | ||
2751 | default: | |
2752 | break; | |
2753 | } | |
2754 | ||
2755 | /* This general rule works for most tree codes. All exceptions should be | |
2756 | handled above. If this is a language-specific tree code, we can't | |
2757 | trust what might be in the operand, so say we don't know | |
2758 | the situation. */ | |
2759 | if ((int) TREE_CODE (exp) >= (int) LAST_AND_UNUSED_TREE_CODE) | |
2760 | return -1; | |
2761 | ||
2762 | nops = first_rtl_op (TREE_CODE (exp)); | |
2763 | for (i = 0; i < nops; i++) | |
2764 | if (TREE_OPERAND (exp, i) != 0) | |
2765 | { | |
2766 | int type = TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, i))); | |
2767 | if (type == 'e' || type == '<' || type == '1' || type == '2' | |
2768 | || type == 'r' || type == 's') | |
2769 | { | |
2770 | cmp = has_cleanups (TREE_OPERAND (exp, i)); | |
2771 | if (cmp) | |
2772 | return cmp; | |
2773 | } | |
2774 | } | |
2775 | ||
2776 | return 0; | |
2777 | } | |
dec20b4b RK |
2778 | \f |
2779 | /* Given a tree EXP, a FIELD_DECL F, and a replacement value R, | |
2780 | return a tree with all occurrences of references to F in a | |
2781 | PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP | |
e9a25f70 JL |
2782 | contains only arithmetic expressions or a CALL_EXPR with a |
2783 | PLACEHOLDER_EXPR occurring only in its arglist. */ | |
dec20b4b RK |
2784 | |
2785 | tree | |
2786 | substitute_in_expr (exp, f, r) | |
2787 | tree exp; | |
2788 | tree f; | |
2789 | tree r; | |
2790 | { | |
2791 | enum tree_code code = TREE_CODE (exp); | |
9b594acf | 2792 | tree op0, op1, op2; |
e9a25f70 | 2793 | tree new; |
dec20b4b RK |
2794 | tree inner; |
2795 | ||
2796 | switch (TREE_CODE_CLASS (code)) | |
2797 | { | |
2798 | case 'c': | |
2799 | case 'd': | |
2800 | return exp; | |
2801 | ||
2802 | case 'x': | |
2803 | if (code == PLACEHOLDER_EXPR) | |
2804 | return exp; | |
e9a25f70 JL |
2805 | else if (code == TREE_LIST) |
2806 | { | |
2807 | op0 = (TREE_CHAIN (exp) == 0 | |
2808 | ? 0 : substitute_in_expr (TREE_CHAIN (exp), f, r)); | |
2809 | op1 = substitute_in_expr (TREE_VALUE (exp), f, r); | |
956d6950 | 2810 | if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp)) |
e9a25f70 JL |
2811 | return exp; |
2812 | ||
956d6950 | 2813 | return tree_cons (TREE_PURPOSE (exp), op1, op0); |
e9a25f70 JL |
2814 | } |
2815 | ||
2816 | abort (); | |
dec20b4b RK |
2817 | |
2818 | case '1': | |
2819 | case '2': | |
2820 | case '<': | |
2821 | case 'e': | |
2822 | switch (tree_code_length[(int) code]) | |
2823 | { | |
2824 | case 1: | |
9b594acf RK |
2825 | op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r); |
2826 | if (op0 == TREE_OPERAND (exp, 0)) | |
2827 | return exp; | |
2828 | ||
2829 | new = fold (build1 (code, TREE_TYPE (exp), op0)); | |
abd23b66 | 2830 | break; |
dec20b4b RK |
2831 | |
2832 | case 2: | |
6a22e3a7 RK |
2833 | /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR |
2834 | could, but we don't support it. */ | |
2835 | if (code == RTL_EXPR) | |
2836 | return exp; | |
2837 | else if (code == CONSTRUCTOR) | |
dec20b4b RK |
2838 | abort (); |
2839 | ||
9b594acf RK |
2840 | op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r); |
2841 | op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r); | |
2842 | if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)) | |
2843 | return exp; | |
2844 | ||
2845 | new = fold (build (code, TREE_TYPE (exp), op0, op1)); | |
abd23b66 | 2846 | break; |
dec20b4b RK |
2847 | |
2848 | case 3: | |
6a22e3a7 RK |
2849 | /* It cannot be that anything inside a SAVE_EXPR contains a |
2850 | PLACEHOLDER_EXPR. */ | |
2851 | if (code == SAVE_EXPR) | |
2852 | return exp; | |
2853 | ||
e9a25f70 JL |
2854 | else if (code == CALL_EXPR) |
2855 | { | |
2856 | op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r); | |
2857 | if (op1 == TREE_OPERAND (exp, 1)) | |
2858 | return exp; | |
2859 | ||
2860 | return build (code, TREE_TYPE (exp), | |
2861 | TREE_OPERAND (exp, 0), op1, NULL_TREE); | |
2862 | } | |
2863 | ||
2864 | else if (code != COND_EXPR) | |
dec20b4b RK |
2865 | abort (); |
2866 | ||
9b594acf RK |
2867 | op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r); |
2868 | op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r); | |
2869 | op2 = substitute_in_expr (TREE_OPERAND (exp, 2), f, r); | |
2870 | if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) | |
2871 | && op2 == TREE_OPERAND (exp, 2)) | |
2872 | return exp; | |
2873 | ||
2874 | new = fold (build (code, TREE_TYPE (exp), op0, op1, op2)); | |
e9a25f70 JL |
2875 | break; |
2876 | ||
2877 | default: | |
2878 | abort (); | |
dec20b4b RK |
2879 | } |
2880 | ||
2881 | break; | |
2882 | ||
2883 | case 'r': | |
2884 | switch (code) | |
2885 | { | |
2886 | case COMPONENT_REF: | |
2887 | /* If this expression is getting a value from a PLACEHOLDER_EXPR | |
2888 | and it is the right field, replace it with R. */ | |
2889 | for (inner = TREE_OPERAND (exp, 0); | |
2890 | TREE_CODE_CLASS (TREE_CODE (inner)) == 'r'; | |
2891 | inner = TREE_OPERAND (inner, 0)) | |
2892 | ; | |
2893 | if (TREE_CODE (inner) == PLACEHOLDER_EXPR | |
2894 | && TREE_OPERAND (exp, 1) == f) | |
2895 | return r; | |
2896 | ||
6cba9fcc RK |
2897 | /* If this expression hasn't been completed let, leave it |
2898 | alone. */ | |
2899 | if (TREE_CODE (inner) == PLACEHOLDER_EXPR | |
2900 | && TREE_TYPE (inner) == 0) | |
2901 | return exp; | |
2902 | ||
9b594acf RK |
2903 | op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r); |
2904 | if (op0 == TREE_OPERAND (exp, 0)) | |
2905 | return exp; | |
2906 | ||
2907 | new = fold (build (code, TREE_TYPE (exp), op0, | |
abd23b66 RK |
2908 | TREE_OPERAND (exp, 1))); |
2909 | break; | |
2910 | ||
dec20b4b | 2911 | case BIT_FIELD_REF: |
9b594acf RK |
2912 | op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r); |
2913 | op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r); | |
2914 | op2 = substitute_in_expr (TREE_OPERAND (exp, 2), f, r); | |
2915 | if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) | |
2916 | && op2 == TREE_OPERAND (exp, 2)) | |
2917 | return exp; | |
2918 | ||
2919 | new = fold (build (code, TREE_TYPE (exp), op0, op1, op2)); | |
abd23b66 RK |
2920 | break; |
2921 | ||
dec20b4b RK |
2922 | case INDIRECT_REF: |
2923 | case BUFFER_REF: | |
9b594acf RK |
2924 | op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r); |
2925 | if (op0 == TREE_OPERAND (exp, 0)) | |
2926 | return exp; | |
2927 | ||
2928 | new = fold (build1 (code, TREE_TYPE (exp), op0)); | |
abd23b66 | 2929 | break; |
e9a25f70 JL |
2930 | |
2931 | default: | |
2932 | abort (); | |
dec20b4b | 2933 | } |
e9a25f70 JL |
2934 | break; |
2935 | ||
2936 | default: | |
2937 | abort (); | |
dec20b4b RK |
2938 | } |
2939 | ||
abd23b66 RK |
2940 | TREE_READONLY (new) = TREE_READONLY (exp); |
2941 | return new; | |
dec20b4b RK |
2942 | } |
2943 | \f | |
c6a1db6c RS |
2944 | /* Stabilize a reference so that we can use it any number of times |
2945 | without causing its operands to be evaluated more than once. | |
4b1d0fea RS |
2946 | Returns the stabilized reference. This works by means of save_expr, |
2947 | so see the caveats in the comments about save_expr. | |
c6a1db6c RS |
2948 | |
2949 | Also allows conversion expressions whose operands are references. | |
2950 | Any other kind of expression is returned unchanged. */ | |
2951 | ||
2952 | tree | |
2953 | stabilize_reference (ref) | |
2954 | tree ref; | |
2955 | { | |
2956 | register tree result; | |
2957 | register enum tree_code code = TREE_CODE (ref); | |
2958 | ||
2959 | switch (code) | |
2960 | { | |
2961 | case VAR_DECL: | |
2962 | case PARM_DECL: | |
2963 | case RESULT_DECL: | |
2964 | /* No action is needed in this case. */ | |
2965 | return ref; | |
2966 | ||
2967 | case NOP_EXPR: | |
2968 | case CONVERT_EXPR: | |
2969 | case FLOAT_EXPR: | |
2970 | case FIX_TRUNC_EXPR: | |
2971 | case FIX_FLOOR_EXPR: | |
2972 | case FIX_ROUND_EXPR: | |
2973 | case FIX_CEIL_EXPR: | |
2974 | result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0))); | |
2975 | break; | |
2976 | ||
2977 | case INDIRECT_REF: | |
2978 | result = build_nt (INDIRECT_REF, | |
2979 | stabilize_reference_1 (TREE_OPERAND (ref, 0))); | |
2980 | break; | |
2981 | ||
2982 | case COMPONENT_REF: | |
2983 | result = build_nt (COMPONENT_REF, | |
2984 | stabilize_reference (TREE_OPERAND (ref, 0)), | |
2985 | TREE_OPERAND (ref, 1)); | |
2986 | break; | |
2987 | ||
2988 | case BIT_FIELD_REF: | |
2989 | result = build_nt (BIT_FIELD_REF, | |
2990 | stabilize_reference (TREE_OPERAND (ref, 0)), | |
2991 | stabilize_reference_1 (TREE_OPERAND (ref, 1)), | |
2992 | stabilize_reference_1 (TREE_OPERAND (ref, 2))); | |
2993 | break; | |
2994 | ||
2995 | case ARRAY_REF: | |
2996 | result = build_nt (ARRAY_REF, | |
2997 | stabilize_reference (TREE_OPERAND (ref, 0)), | |
2998 | stabilize_reference_1 (TREE_OPERAND (ref, 1))); | |
2999 | break; | |
3000 | ||
c451a7a0 | 3001 | case COMPOUND_EXPR: |
7b8b9722 MS |
3002 | /* We cannot wrap the first expression in a SAVE_EXPR, as then |
3003 | it wouldn't be ignored. This matters when dealing with | |
3004 | volatiles. */ | |
3005 | return stabilize_reference_1 (ref); | |
c451a7a0 | 3006 | |
c36a127d RK |
3007 | case RTL_EXPR: |
3008 | result = build1 (INDIRECT_REF, TREE_TYPE (ref), | |
3009 | save_expr (build1 (ADDR_EXPR, | |
21f0e042 | 3010 | build_pointer_type (TREE_TYPE (ref)), |
c36a127d RK |
3011 | ref))); |
3012 | break; | |
3013 | ||
c451a7a0 | 3014 | |
c6a1db6c RS |
3015 | /* If arg isn't a kind of lvalue we recognize, make no change. |
3016 | Caller should recognize the error for an invalid lvalue. */ | |
3017 | default: | |
3018 | return ref; | |
3019 | ||
3020 | case ERROR_MARK: | |
3021 | return error_mark_node; | |
3022 | } | |
3023 | ||
3024 | TREE_TYPE (result) = TREE_TYPE (ref); | |
3025 | TREE_READONLY (result) = TREE_READONLY (ref); | |
3026 | TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref); | |
3027 | TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref); | |
3028 | TREE_RAISES (result) = TREE_RAISES (ref); | |
3029 | ||
3030 | return result; | |
3031 | } | |
3032 | ||
3033 | /* Subroutine of stabilize_reference; this is called for subtrees of | |
3034 | references. Any expression with side-effects must be put in a SAVE_EXPR | |
3035 | to ensure that it is only evaluated once. | |
3036 | ||
3037 | We don't put SAVE_EXPR nodes around everything, because assigning very | |
3038 | simple expressions to temporaries causes us to miss good opportunities | |
3039 | for optimizations. Among other things, the opportunity to fold in the | |
3040 | addition of a constant into an addressing mode often gets lost, e.g. | |
3041 | "y[i+1] += x;". In general, we take the approach that we should not make | |
3042 | an assignment unless we are forced into it - i.e., that any non-side effect | |
3043 | operator should be allowed, and that cse should take care of coalescing | |
3044 | multiple utterances of the same expression should that prove fruitful. */ | |
3045 | ||
4745ddae | 3046 | tree |
c6a1db6c RS |
3047 | stabilize_reference_1 (e) |
3048 | tree e; | |
3049 | { | |
3050 | register tree result; | |
c6a1db6c RS |
3051 | register enum tree_code code = TREE_CODE (e); |
3052 | ||
af929c62 RK |
3053 | /* We cannot ignore const expressions because it might be a reference |
3054 | to a const array but whose index contains side-effects. But we can | |
3055 | ignore things that are actual constant or that already have been | |
3056 | handled by this function. */ | |
3057 | ||
3058 | if (TREE_CONSTANT (e) || code == SAVE_EXPR) | |
c6a1db6c RS |
3059 | return e; |
3060 | ||
3061 | switch (TREE_CODE_CLASS (code)) | |
3062 | { | |
3063 | case 'x': | |
3064 | case 't': | |
3065 | case 'd': | |
03646189 | 3066 | case 'b': |
c6a1db6c RS |
3067 | case '<': |
3068 | case 's': | |
3069 | case 'e': | |
3070 | case 'r': | |
3071 | /* If the expression has side-effects, then encase it in a SAVE_EXPR | |
3072 | so that it will only be evaluated once. */ | |
3073 | /* The reference (r) and comparison (<) classes could be handled as | |
3074 | below, but it is generally faster to only evaluate them once. */ | |
3075 | if (TREE_SIDE_EFFECTS (e)) | |
3076 | return save_expr (e); | |
3077 | return e; | |
3078 | ||
3079 | case 'c': | |
3080 | /* Constants need no processing. In fact, we should never reach | |
3081 | here. */ | |
3082 | return e; | |
3083 | ||
3084 | case '2': | |
ae698e41 RS |
3085 | /* Division is slow and tends to be compiled with jumps, |
3086 | especially the division by powers of 2 that is often | |
3087 | found inside of an array reference. So do it just once. */ | |
3088 | if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR | |
3089 | || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR | |
3090 | || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR | |
3091 | || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR) | |
3092 | return save_expr (e); | |
c6a1db6c RS |
3093 | /* Recursively stabilize each operand. */ |
3094 | result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)), | |
3095 | stabilize_reference_1 (TREE_OPERAND (e, 1))); | |
3096 | break; | |
3097 | ||
3098 | case '1': | |
3099 | /* Recursively stabilize each operand. */ | |
3100 | result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0))); | |
3101 | break; | |
a7fcb968 RK |
3102 | |
3103 | default: | |
3104 | abort (); | |
c6a1db6c RS |
3105 | } |
3106 | ||
3107 | TREE_TYPE (result) = TREE_TYPE (e); | |
3108 | TREE_READONLY (result) = TREE_READONLY (e); | |
3109 | TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e); | |
3110 | TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e); | |
3111 | TREE_RAISES (result) = TREE_RAISES (e); | |
3112 | ||
3113 | return result; | |
3114 | } | |
3115 | \f | |
3116 | /* Low-level constructors for expressions. */ | |
3117 | ||
3118 | /* Build an expression of code CODE, data type TYPE, | |
3119 | and operands as specified by the arguments ARG1 and following arguments. | |
3120 | Expressions and reference nodes can be created this way. | |
3121 | Constants, decls, types and misc nodes cannot be. */ | |
3122 | ||
3123 | tree | |
58782098 | 3124 | build VPARAMS ((enum tree_code code, tree tt, ...)) |
c6a1db6c | 3125 | { |
5148a72b | 3126 | #ifndef ANSI_PROTOTYPES |
c6a1db6c | 3127 | enum tree_code code; |
ba63ed56 RK |
3128 | tree tt; |
3129 | #endif | |
3130 | va_list p; | |
c6a1db6c RS |
3131 | register tree t; |
3132 | register int length; | |
3133 | register int i; | |
97ca93c3 | 3134 | int fro; |
c6a1db6c | 3135 | |
ba63ed56 | 3136 | VA_START (p, tt); |
c6a1db6c | 3137 | |
5148a72b | 3138 | #ifndef ANSI_PROTOTYPES |
c6a1db6c | 3139 | code = va_arg (p, enum tree_code); |
ba63ed56 RK |
3140 | tt = va_arg (p, tree); |
3141 | #endif | |
3142 | ||
c6a1db6c RS |
3143 | t = make_node (code); |
3144 | length = tree_code_length[(int) code]; | |
ba63ed56 | 3145 | TREE_TYPE (t) = tt; |
c6a1db6c | 3146 | |
97ca93c3 MM |
3147 | /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_RAISED for |
3148 | the result based on those same flags for the arguments. But, if | |
3149 | the arguments aren't really even `tree' expressions, we shouldn't | |
3150 | be trying to do this. */ | |
3151 | fro = first_rtl_op (code); | |
3152 | ||
c6a1db6c RS |
3153 | if (length == 2) |
3154 | { | |
3155 | /* This is equivalent to the loop below, but faster. */ | |
3156 | register tree arg0 = va_arg (p, tree); | |
3157 | register tree arg1 = va_arg (p, tree); | |
3158 | TREE_OPERAND (t, 0) = arg0; | |
3159 | TREE_OPERAND (t, 1) = arg1; | |
97ca93c3 MM |
3160 | if (arg0 && fro > 0) |
3161 | { | |
3162 | if (TREE_SIDE_EFFECTS (arg0)) | |
3163 | TREE_SIDE_EFFECTS (t) = 1; | |
3164 | if (TREE_RAISES (arg0)) | |
3165 | TREE_RAISES (t) = 1; | |
3166 | } | |
3167 | if (arg1 && fro > 1) | |
3168 | { | |
3169 | if (TREE_SIDE_EFFECTS (arg1)) | |
3170 | TREE_SIDE_EFFECTS (t) = 1; | |
3171 | if (TREE_RAISES (arg1)) | |
3172 | TREE_RAISES (t) = 1; | |
3173 | } | |
c6a1db6c RS |
3174 | } |
3175 | else if (length == 1) | |
3176 | { | |
3177 | register tree arg0 = va_arg (p, tree); | |
3178 | ||
3179 | /* Call build1 for this! */ | |
3180 | if (TREE_CODE_CLASS (code) != 's') | |
3181 | abort (); | |
3182 | TREE_OPERAND (t, 0) = arg0; | |
97ca93c3 MM |
3183 | if (fro > 0) |
3184 | { | |
3185 | if (arg0 && TREE_SIDE_EFFECTS (arg0)) | |
3186 | TREE_SIDE_EFFECTS (t) = 1; | |
3187 | TREE_RAISES (t) = (arg0 && TREE_RAISES (arg0)); | |
3188 | } | |
c6a1db6c RS |
3189 | } |
3190 | else | |
3191 | { | |
3192 | for (i = 0; i < length; i++) | |
3193 | { | |
3194 | register tree operand = va_arg (p, tree); | |
3195 | TREE_OPERAND (t, i) = operand; | |
97ca93c3 | 3196 | if (operand && fro > i) |
c6a1db6c RS |
3197 | { |
3198 | if (TREE_SIDE_EFFECTS (operand)) | |
3199 | TREE_SIDE_EFFECTS (t) = 1; | |
3200 | if (TREE_RAISES (operand)) | |
3201 | TREE_RAISES (t) = 1; | |
3202 | } | |
3203 | } | |
3204 | } | |
3205 | va_end (p); | |
3206 | return t; | |
3207 | } | |
3208 | ||
3209 | /* Same as above, but only builds for unary operators. | |
3210 | Saves lions share of calls to `build'; cuts down use | |
3211 | of varargs, which is expensive for RISC machines. */ | |
0f41302f | 3212 | |
c6a1db6c RS |
3213 | tree |
3214 | build1 (code, type, node) | |
3215 | enum tree_code code; | |
3216 | tree type; | |
3217 | tree node; | |
3218 | { | |
0ac224f8 | 3219 | register struct obstack *obstack = expression_obstack; |
42cb11fc | 3220 | register int length; |
5e9defae | 3221 | #ifdef GATHER_STATISTICS |
c6a1db6c | 3222 | register tree_node_kind kind; |
5e9defae | 3223 | #endif |
c6a1db6c RS |
3224 | register tree t; |
3225 | ||
3226 | #ifdef GATHER_STATISTICS | |
3227 | if (TREE_CODE_CLASS (code) == 'r') | |
3228 | kind = r_kind; | |
3229 | else | |
3230 | kind = e_kind; | |
3231 | #endif | |
3232 | ||
c6a1db6c RS |
3233 | length = sizeof (struct tree_exp); |
3234 | ||
a3770a81 RH |
3235 | if (ggc_p) |
3236 | t = ggc_alloc_tree (length); | |
3237 | else | |
1fef02f6 RH |
3238 | { |
3239 | t = (tree) obstack_alloc (obstack, length); | |
3240 | memset ((PTR) t, 0, length); | |
3241 | } | |
c6a1db6c RS |
3242 | |
3243 | #ifdef GATHER_STATISTICS | |
3244 | tree_node_counts[(int)kind]++; | |
3245 | tree_node_sizes[(int)kind] += length; | |
3246 | #endif | |
3247 | ||
508f8149 | 3248 | TREE_TYPE (t) = type; |
c6a1db6c | 3249 | TREE_SET_CODE (t, code); |
23dfa477 | 3250 | TREE_SET_PERMANENT (t); |
c6a1db6c RS |
3251 | |
3252 | TREE_OPERAND (t, 0) = node; | |
97ca93c3 | 3253 | if (node && first_rtl_op (code) != 0) |
c6a1db6c RS |
3254 | { |
3255 | if (TREE_SIDE_EFFECTS (node)) | |
3256 | TREE_SIDE_EFFECTS (t) = 1; | |
3257 | if (TREE_RAISES (node)) | |
3258 | TREE_RAISES (t) = 1; | |
3259 | } | |
3260 | ||
1fef02f6 RH |
3261 | switch (code) |
3262 | { | |
3263 | case INIT_EXPR: | |
3264 | case MODIFY_EXPR: | |
3265 | case VA_ARG_EXPR: | |
3266 | case RTL_EXPR: | |
3267 | case PREDECREMENT_EXPR: | |
3268 | case PREINCREMENT_EXPR: | |
3269 | case POSTDECREMENT_EXPR: | |
3270 | case POSTINCREMENT_EXPR: | |
3271 | /* All of these have side-effects, no matter what their | |
3272 | operands are. */ | |
3273 | TREE_SIDE_EFFECTS (t) = 1; | |
3274 | break; | |
3275 | ||
3276 | default: | |
3277 | break; | |
3278 | } | |
3279 | ||
c6a1db6c RS |
3280 | return t; |
3281 | } | |
3282 | ||
3283 | /* Similar except don't specify the TREE_TYPE | |
3284 | and leave the TREE_SIDE_EFFECTS as 0. | |
3285 | It is permissible for arguments to be null, | |
3286 | or even garbage if their values do not matter. */ | |
3287 | ||
3288 | tree | |
58782098 | 3289 | build_nt VPARAMS ((enum tree_code code, ...)) |
c6a1db6c | 3290 | { |
5148a72b | 3291 | #ifndef ANSI_PROTOTYPES |
c5ffba1a | 3292 | enum tree_code code; |
ba63ed56 RK |
3293 | #endif |
3294 | va_list p; | |
c6a1db6c RS |
3295 | register tree t; |
3296 | register int length; | |
3297 | register int i; | |
3298 | ||
ba63ed56 | 3299 | VA_START (p, code); |
c6a1db6c | 3300 | |
5148a72b | 3301 | #ifndef ANSI_PROTOTYPES |
c6a1db6c | 3302 | code = va_arg (p, enum tree_code); |
ba63ed56 RK |
3303 | #endif |
3304 | ||
c6a1db6c RS |
3305 | t = make_node (code); |
3306 | length = tree_code_length[(int) code]; | |
3307 | ||
3308 | for (i = 0; i < length; i++) | |
3309 | TREE_OPERAND (t, i) = va_arg (p, tree); | |
3310 | ||
3311 | va_end (p); | |
3312 | return t; | |
3313 | } | |
3314 | ||
3315 | /* Similar to `build_nt', except we build | |
3316 | on the temp_decl_obstack, regardless. */ | |
3317 | ||
3318 | tree | |
58782098 | 3319 | build_parse_node VPARAMS ((enum tree_code code, ...)) |
c6a1db6c | 3320 | { |
5148a72b | 3321 | #ifndef ANSI_PROTOTYPES |
c5ffba1a | 3322 | enum tree_code code; |
ba63ed56 | 3323 | #endif |
c6a1db6c RS |
3324 | register struct obstack *ambient_obstack = expression_obstack; |
3325 | va_list p; | |
c6a1db6c RS |
3326 | register tree t; |
3327 | register int length; | |
3328 | register int i; | |
3329 | ||
ba63ed56 | 3330 | VA_START (p, code); |
c6a1db6c | 3331 | |
5148a72b | 3332 | #ifndef ANSI_PROTOTYPES |
c6a1db6c | 3333 | code = va_arg (p, enum tree_code); |
ba63ed56 RK |
3334 | #endif |
3335 | ||
3336 | expression_obstack = &temp_decl_obstack; | |
3337 | ||
c6a1db6c RS |
3338 | t = make_node (code); |
3339 | length = tree_code_length[(int) code]; | |
3340 | ||
3341 | for (i = 0; i < length; i++) | |
3342 | TREE_OPERAND (t, i) = va_arg (p, tree); | |
3343 | ||
3344 | va_end (p); | |
3345 | expression_obstack = ambient_obstack; | |
3346 | return t; | |
3347 | } | |
3348 | ||
3349 | #if 0 | |
3350 | /* Commented out because this wants to be done very | |
3351 | differently. See cp-lex.c. */ | |
3352 | tree | |
3353 | build_op_identifier (op1, op2) | |
3354 | tree op1, op2; | |
3355 | { | |
3356 | register tree t = make_node (OP_IDENTIFIER); | |
3357 | TREE_PURPOSE (t) = op1; | |
3358 | TREE_VALUE (t) = op2; | |
3359 | return t; | |
3360 | } | |
3361 | #endif | |
3362 | \f | |
3363 | /* Create a DECL_... node of code CODE, name NAME and data type TYPE. | |
3364 | We do NOT enter this node in any sort of symbol table. | |
3365 | ||
3366 | layout_decl is used to set up the decl's storage layout. | |
3367 | Other slots are initialized to 0 or null pointers. */ | |
3368 | ||
3369 | tree | |
3370 | build_decl (code, name, type) | |
3371 | enum tree_code code; | |
3372 | tree name, type; | |
3373 | { | |
3374 | register tree t; | |
3375 | ||
3376 | t = make_node (code); | |
3377 | ||
3378 | /* if (type == error_mark_node) | |
3379 | type = integer_type_node; */ | |
3380 | /* That is not done, deliberately, so that having error_mark_node | |
3381 | as the type can suppress useless errors in the use of this variable. */ | |
3382 | ||
3383 | DECL_NAME (t) = name; | |
3384 | DECL_ASSEMBLER_NAME (t) = name; | |
3385 | TREE_TYPE (t) = type; | |
3386 | ||
3387 | if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL) | |
3388 | layout_decl (t, 0); | |
3389 | else if (code == FUNCTION_DECL) | |
3390 | DECL_MODE (t) = FUNCTION_MODE; | |
3391 | ||
3392 | return t; | |
3393 | } | |
3394 | \f | |
3395 | /* BLOCK nodes are used to represent the structure of binding contours | |
3396 | and declarations, once those contours have been exited and their contents | |
52d2830e | 3397 | compiled. This information is used for outputting debugging info. */ |
c6a1db6c RS |
3398 | |
3399 | tree | |
3400 | build_block (vars, tags, subblocks, supercontext, chain) | |
272df862 | 3401 | tree vars, tags ATTRIBUTE_UNUSED, subblocks, supercontext, chain; |
c6a1db6c RS |
3402 | { |
3403 | register tree block = make_node (BLOCK); | |
d4b60170 | 3404 | |
c6a1db6c | 3405 | BLOCK_VARS (block) = vars; |
c6a1db6c RS |
3406 | BLOCK_SUBBLOCKS (block) = subblocks; |
3407 | BLOCK_SUPERCONTEXT (block) = supercontext; | |
3408 | BLOCK_CHAIN (block) = chain; | |
3409 | return block; | |
3410 | } | |
bf1e5319 APB |
3411 | |
3412 | /* EXPR_WITH_FILE_LOCATION are used to keep track of the exact | |
3413 | location where an expression or an identifier were encountered. It | |
3414 | is necessary for languages where the frontend parser will handle | |
3415 | recursively more than one file (Java is one of them). */ | |
3416 | ||
3417 | tree | |
3418 | build_expr_wfl (node, file, line, col) | |
3419 | tree node; | |
37b37199 | 3420 | const char *file; |
bf1e5319 APB |
3421 | int line, col; |
3422 | { | |
37b37199 | 3423 | static const char *last_file = 0; |
d4b60170 | 3424 | static tree last_filenode = NULL_TREE; |
bf1e5319 | 3425 | register tree wfl = make_node (EXPR_WITH_FILE_LOCATION); |
9fe9a2e1 | 3426 | |
bf1e5319 | 3427 | EXPR_WFL_NODE (wfl) = node; |
bf1e5319 | 3428 | EXPR_WFL_SET_LINECOL (wfl, line, col); |
9fe9a2e1 APB |
3429 | if (file != last_file) |
3430 | { | |
3431 | last_file = file; | |
3432 | last_filenode = file ? get_identifier (file) : NULL_TREE; | |
3433 | } | |
d4b60170 | 3434 | |
9fe9a2e1 APB |
3435 | EXPR_WFL_FILENAME_NODE (wfl) = last_filenode; |
3436 | if (node) | |
3437 | { | |
3438 | TREE_SIDE_EFFECTS (wfl) = TREE_SIDE_EFFECTS (node); | |
3439 | TREE_TYPE (wfl) = TREE_TYPE (node); | |
3440 | } | |
d4b60170 | 3441 | |
bf1e5319 APB |
3442 | return wfl; |
3443 | } | |
c6a1db6c | 3444 | \f |
1a2927d2 | 3445 | /* Return a declaration like DDECL except that its DECL_MACHINE_ATTRIBUTE |
0f41302f | 3446 | is ATTRIBUTE. */ |
1a2927d2 RK |
3447 | |
3448 | tree | |
3449 | build_decl_attribute_variant (ddecl, attribute) | |
3450 | tree ddecl, attribute; | |
3451 | { | |
3452 | DECL_MACHINE_ATTRIBUTES (ddecl) = attribute; | |
3453 | return ddecl; | |
3454 | } | |
3455 | ||
91e97eb8 RK |
3456 | /* Return a type like TTYPE except that its TYPE_ATTRIBUTE |
3457 | is ATTRIBUTE. | |
3458 | ||
f8a89236 | 3459 | Record such modified types already made so we don't make duplicates. */ |
91e97eb8 RK |
3460 | |
3461 | tree | |
3462 | build_type_attribute_variant (ttype, attribute) | |
3463 | tree ttype, attribute; | |
3464 | { | |
3465 | if ( ! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute)) | |
3466 | { | |
05bccae2 | 3467 | unsigned int hashcode; |
91e97eb8 RK |
3468 | tree ntype; |
3469 | ||
14a774a9 | 3470 | push_obstacks (TYPE_OBSTACK (ttype), TYPE_OBSTACK (ttype)); |
91e97eb8 | 3471 | ntype = copy_node (ttype); |
91e97eb8 RK |
3472 | |
3473 | TYPE_POINTER_TO (ntype) = 0; | |
3474 | TYPE_REFERENCE_TO (ntype) = 0; | |
3475 | TYPE_ATTRIBUTES (ntype) = attribute; | |
3476 | ||
3477 | /* Create a new main variant of TYPE. */ | |
3478 | TYPE_MAIN_VARIANT (ntype) = ntype; | |
3479 | TYPE_NEXT_VARIANT (ntype) = 0; | |
3932261a | 3480 | set_type_quals (ntype, TYPE_UNQUALIFIED); |
91e97eb8 | 3481 | |
05bccae2 RK |
3482 | hashcode = (TYPE_HASH (TREE_CODE (ntype)) |
3483 | + TYPE_HASH (TREE_TYPE (ntype)) | |
3484 | + attribute_hash_list (attribute)); | |
91e97eb8 RK |
3485 | |
3486 | switch (TREE_CODE (ntype)) | |
3487 | { | |
e9a25f70 JL |
3488 | case FUNCTION_TYPE: |
3489 | hashcode += TYPE_HASH (TYPE_ARG_TYPES (ntype)); | |
3490 | break; | |
3491 | case ARRAY_TYPE: | |
3492 | hashcode += TYPE_HASH (TYPE_DOMAIN (ntype)); | |
3493 | break; | |
3494 | case INTEGER_TYPE: | |
3495 | hashcode += TYPE_HASH (TYPE_MAX_VALUE (ntype)); | |
3496 | break; | |
3497 | case REAL_TYPE: | |
3498 | hashcode += TYPE_HASH (TYPE_PRECISION (ntype)); | |
3499 | break; | |
3500 | default: | |
3501 | break; | |
91e97eb8 RK |
3502 | } |
3503 | ||
3504 | ntype = type_hash_canon (hashcode, ntype); | |
3932261a | 3505 | ttype = build_qualified_type (ntype, TYPE_QUALS (ttype)); |
14a774a9 | 3506 | pop_obstacks (); |
91e97eb8 RK |
3507 | } |
3508 | ||
3509 | return ttype; | |
3510 | } | |
1a2927d2 | 3511 | |
4084f789 RK |
3512 | /* Return a 1 if ATTR_NAME and ATTR_ARGS is valid for either declaration DECL |
3513 | or type TYPE and 0 otherwise. Validity is determined the configuration | |
0f41302f | 3514 | macros VALID_MACHINE_DECL_ATTRIBUTE and VALID_MACHINE_TYPE_ATTRIBUTE. */ |
1a2927d2 RK |
3515 | |
3516 | int | |
4084f789 | 3517 | valid_machine_attribute (attr_name, attr_args, decl, type) |
c84e2712 KG |
3518 | tree attr_name; |
3519 | tree attr_args ATTRIBUTE_UNUSED; | |
3520 | tree decl ATTRIBUTE_UNUSED; | |
3521 | tree type ATTRIBUTE_UNUSED; | |
1a2927d2 | 3522 | { |
ab87f8c8 | 3523 | int validated = 0; |
51723711 | 3524 | #ifdef VALID_MACHINE_DECL_ATTRIBUTE |
4084f789 | 3525 | tree decl_attr_list = decl != 0 ? DECL_MACHINE_ATTRIBUTES (decl) : 0; |
51723711 KG |
3526 | #endif |
3527 | #ifdef VALID_MACHINE_TYPE_ATTRIBUTE | |
1a2927d2 | 3528 | tree type_attr_list = TYPE_ATTRIBUTES (type); |
51723711 | 3529 | #endif |
1a2927d2 | 3530 | |
2a3c15b5 DE |
3531 | if (TREE_CODE (attr_name) != IDENTIFIER_NODE) |
3532 | abort (); | |
4084f789 | 3533 | |
1a2927d2 | 3534 | #ifdef VALID_MACHINE_DECL_ATTRIBUTE |
4084f789 | 3535 | if (decl != 0 |
d4b60170 RK |
3536 | && VALID_MACHINE_DECL_ATTRIBUTE (decl, decl_attr_list, attr_name, |
3537 | attr_args)) | |
1a2927d2 | 3538 | { |
2a3c15b5 DE |
3539 | tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name), |
3540 | decl_attr_list); | |
1a2927d2 | 3541 | |
2a3c15b5 DE |
3542 | if (attr != NULL_TREE) |
3543 | { | |
3544 | /* Override existing arguments. Declarations are unique so we can | |
3545 | modify this in place. */ | |
3546 | TREE_VALUE (attr) = attr_args; | |
3547 | } | |
3548 | else | |
3549 | { | |
3550 | decl_attr_list = tree_cons (attr_name, attr_args, decl_attr_list); | |
3e3d7e77 RK |
3551 | decl = build_decl_attribute_variant (decl, decl_attr_list); |
3552 | } | |
1a2927d2 | 3553 | |
ab87f8c8 | 3554 | validated = 1; |
1a2927d2 RK |
3555 | } |
3556 | #endif | |
3557 | ||
3558 | #ifdef VALID_MACHINE_TYPE_ATTRIBUTE | |
ab87f8c8 | 3559 | if (validated) |
226c39d3 JM |
3560 | /* Don't apply the attribute to both the decl and the type. */; |
3561 | else if (VALID_MACHINE_TYPE_ATTRIBUTE (type, type_attr_list, attr_name, | |
3562 | attr_args)) | |
1a2927d2 | 3563 | { |
2a3c15b5 DE |
3564 | tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name), |
3565 | type_attr_list); | |
3566 | ||
3567 | if (attr != NULL_TREE) | |
3e3d7e77 | 3568 | { |
2a3c15b5 DE |
3569 | /* Override existing arguments. |
3570 | ??? This currently works since attribute arguments are not | |
3571 | included in `attribute_hash_list'. Something more complicated | |
3572 | may be needed in the future. */ | |
3573 | TREE_VALUE (attr) = attr_args; | |
3574 | } | |
3575 | else | |
3576 | { | |
f022f9bc RE |
3577 | /* If this is part of a declaration, create a type variant, |
3578 | otherwise, this is part of a type definition, so add it | |
3579 | to the base type. */ | |
2a3c15b5 | 3580 | type_attr_list = tree_cons (attr_name, attr_args, type_attr_list); |
f022f9bc RE |
3581 | if (decl != 0) |
3582 | type = build_type_attribute_variant (type, type_attr_list); | |
3583 | else | |
3584 | TYPE_ATTRIBUTES (type) = type_attr_list; | |
3e3d7e77 | 3585 | } |
d4b60170 | 3586 | |
4084f789 RK |
3587 | if (decl != 0) |
3588 | TREE_TYPE (decl) = type; | |
d4b60170 | 3589 | |
ab87f8c8 | 3590 | validated = 1; |
1a2927d2 | 3591 | } |
15c8ec1c RK |
3592 | |
3593 | /* Handle putting a type attribute on pointer-to-function-type by putting | |
3594 | the attribute on the function type. */ | |
e5e809f4 | 3595 | else if (POINTER_TYPE_P (type) |
15c8ec1c RK |
3596 | && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE |
3597 | && VALID_MACHINE_TYPE_ATTRIBUTE (TREE_TYPE (type), type_attr_list, | |
3598 | attr_name, attr_args)) | |
3599 | { | |
3600 | tree inner_type = TREE_TYPE (type); | |
3601 | tree inner_attr_list = TYPE_ATTRIBUTES (inner_type); | |
3602 | tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name), | |
3603 | type_attr_list); | |
3604 | ||
3605 | if (attr != NULL_TREE) | |
3606 | TREE_VALUE (attr) = attr_args; | |
3607 | else | |
3608 | { | |
3609 | inner_attr_list = tree_cons (attr_name, attr_args, inner_attr_list); | |
3610 | inner_type = build_type_attribute_variant (inner_type, | |
3611 | inner_attr_list); | |
3612 | } | |
3613 | ||
3614 | if (decl != 0) | |
3615 | TREE_TYPE (decl) = build_pointer_type (inner_type); | |
ace3c40a JM |
3616 | else |
3617 | { | |
3618 | /* Clear TYPE_POINTER_TO for the old inner type, since | |
3619 | `type' won't be pointing to it anymore. */ | |
3620 | TYPE_POINTER_TO (TREE_TYPE (type)) = NULL_TREE; | |
3621 | TREE_TYPE (type) = inner_type; | |
3622 | } | |
15c8ec1c | 3623 | |
ab87f8c8 | 3624 | validated = 1; |
15c8ec1c | 3625 | } |
1a2927d2 RK |
3626 | #endif |
3627 | ||
ab87f8c8 | 3628 | return validated; |
1a2927d2 | 3629 | } |
2a3c15b5 DE |
3630 | |
3631 | /* Return non-zero if IDENT is a valid name for attribute ATTR, | |
3632 | or zero if not. | |
3633 | ||
3634 | We try both `text' and `__text__', ATTR may be either one. */ | |
3635 | /* ??? It might be a reasonable simplification to require ATTR to be only | |
3636 | `text'. One might then also require attribute lists to be stored in | |
3637 | their canonicalized form. */ | |
3638 | ||
3639 | int | |
3640 | is_attribute_p (attr, ident) | |
37b37199 | 3641 | const char *attr; |
2a3c15b5 DE |
3642 | tree ident; |
3643 | { | |
3644 | int ident_len, attr_len; | |
3645 | char *p; | |
3646 | ||
3647 | if (TREE_CODE (ident) != IDENTIFIER_NODE) | |
3648 | return 0; | |
3649 | ||
3650 | if (strcmp (attr, IDENTIFIER_POINTER (ident)) == 0) | |
3651 | return 1; | |
3652 | ||
3653 | p = IDENTIFIER_POINTER (ident); | |
3654 | ident_len = strlen (p); | |
3655 | attr_len = strlen (attr); | |
3656 | ||
3657 | /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */ | |
3658 | if (attr[0] == '_') | |
3659 | { | |
3660 | if (attr[1] != '_' | |
3661 | || attr[attr_len - 2] != '_' | |
3662 | || attr[attr_len - 1] != '_') | |
3663 | abort (); | |
3664 | if (ident_len == attr_len - 4 | |
3665 | && strncmp (attr + 2, p, attr_len - 4) == 0) | |
3666 | return 1; | |
3667 | } | |
3668 | else | |
3669 | { | |
3670 | if (ident_len == attr_len + 4 | |
3671 | && p[0] == '_' && p[1] == '_' | |
3672 | && p[ident_len - 2] == '_' && p[ident_len - 1] == '_' | |
3673 | && strncmp (attr, p + 2, attr_len) == 0) | |
3674 | return 1; | |
3675 | } | |
3676 | ||
3677 | return 0; | |
3678 | } | |
3679 | ||
3680 | /* Given an attribute name and a list of attributes, return a pointer to the | |
3681 | attribute's list element if the attribute is part of the list, or NULL_TREE | |
3682 | if not found. */ | |
3683 | ||
3684 | tree | |
3685 | lookup_attribute (attr_name, list) | |
37b37199 | 3686 | const char *attr_name; |
2a3c15b5 DE |
3687 | tree list; |
3688 | { | |
3689 | tree l; | |
3690 | ||
3691 | for (l = list; l; l = TREE_CHAIN (l)) | |
3692 | { | |
3693 | if (TREE_CODE (TREE_PURPOSE (l)) != IDENTIFIER_NODE) | |
3694 | abort (); | |
3695 | if (is_attribute_p (attr_name, TREE_PURPOSE (l))) | |
3696 | return l; | |
3697 | } | |
3698 | ||
3699 | return NULL_TREE; | |
3700 | } | |
f3209e2f DE |
3701 | |
3702 | /* Return an attribute list that is the union of a1 and a2. */ | |
3703 | ||
3704 | tree | |
3705 | merge_attributes (a1, a2) | |
3706 | register tree a1, a2; | |
3707 | { | |
3708 | tree attributes; | |
3709 | ||
3710 | /* Either one unset? Take the set one. */ | |
3711 | ||
d4b60170 | 3712 | if ((attributes = a1) == 0) |
f3209e2f DE |
3713 | attributes = a2; |
3714 | ||
3715 | /* One that completely contains the other? Take it. */ | |
3716 | ||
d4b60170 | 3717 | else if (a2 != 0 && ! attribute_list_contained (a1, a2)) |
51723711 | 3718 | { |
f3209e2f DE |
3719 | if (attribute_list_contained (a2, a1)) |
3720 | attributes = a2; | |
3721 | else | |
3722 | { | |
3723 | /* Pick the longest list, and hang on the other list. */ | |
3724 | /* ??? For the moment we punt on the issue of attrs with args. */ | |
3725 | ||
3726 | if (list_length (a1) < list_length (a2)) | |
3727 | attributes = a2, a2 = a1; | |
3728 | ||
d4b60170 | 3729 | for (; a2 != 0; a2 = TREE_CHAIN (a2)) |
f3209e2f DE |
3730 | if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)), |
3731 | attributes) == NULL_TREE) | |
3732 | { | |
3733 | a1 = copy_node (a2); | |
3734 | TREE_CHAIN (a1) = attributes; | |
3735 | attributes = a1; | |
3736 | } | |
3737 | } | |
51723711 | 3738 | } |
f3209e2f DE |
3739 | return attributes; |
3740 | } | |
d9525bec BK |
3741 | |
3742 | /* Given types T1 and T2, merge their attributes and return | |
3743 | the result. */ | |
3744 | ||
3745 | tree | |
3746 | merge_machine_type_attributes (t1, t2) | |
3747 | tree t1, t2; | |
3748 | { | |
3749 | #ifdef MERGE_MACHINE_TYPE_ATTRIBUTES | |
3750 | return MERGE_MACHINE_TYPE_ATTRIBUTES (t1, t2); | |
3751 | #else | |
3752 | return merge_attributes (TYPE_ATTRIBUTES (t1), | |
3753 | TYPE_ATTRIBUTES (t2)); | |
3754 | #endif | |
3755 | } | |
3756 | ||
3757 | /* Given decls OLDDECL and NEWDECL, merge their attributes and return | |
3758 | the result. */ | |
3759 | ||
3760 | tree | |
3761 | merge_machine_decl_attributes (olddecl, newdecl) | |
3762 | tree olddecl, newdecl; | |
3763 | { | |
3764 | #ifdef MERGE_MACHINE_DECL_ATTRIBUTES | |
3765 | return MERGE_MACHINE_DECL_ATTRIBUTES (olddecl, newdecl); | |
3766 | #else | |
3767 | return merge_attributes (DECL_MACHINE_ATTRIBUTES (olddecl), | |
3768 | DECL_MACHINE_ATTRIBUTES (newdecl)); | |
3769 | #endif | |
3770 | } | |
91e97eb8 | 3771 | \f |
3932261a MM |
3772 | /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask |
3773 | of the various TYPE_QUAL values. */ | |
c6a1db6c | 3774 | |
3932261a MM |
3775 | static void |
3776 | set_type_quals (type, type_quals) | |
3777 | tree type; | |
3778 | int type_quals; | |
3779 | { | |
3780 | TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0; | |
3781 | TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0; | |
3782 | TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0; | |
3783 | } | |
c6a1db6c | 3784 | |
3932261a MM |
3785 | /* Given a type node TYPE and a TYPE_QUALIFIER_SET, return a type for |
3786 | the same kind of data as TYPE describes. Variants point to the | |
3787 | "main variant" (which has no qualifiers set) via TYPE_MAIN_VARIANT, | |
3788 | and it points to a chain of other variants so that duplicate | |
3789 | variants are never made. Only main variants should ever appear as | |
3790 | types of expressions. */ | |
c6a1db6c RS |
3791 | |
3792 | tree | |
3932261a | 3793 | build_qualified_type (type, type_quals) |
c6a1db6c | 3794 | tree type; |
3932261a | 3795 | int type_quals; |
c6a1db6c | 3796 | { |
2c3dd6b7 | 3797 | register tree t; |
3932261a | 3798 | |
e24fa534 JW |
3799 | /* Search the chain of variants to see if there is already one there just |
3800 | like the one we need to have. If so, use that existing one. We must | |
3801 | preserve the TYPE_NAME, since there is code that depends on this. */ | |
3802 | ||
b217d7fe | 3803 | for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) |
3932261a | 3804 | if (TYPE_QUALS (t) == type_quals && TYPE_NAME (t) == TYPE_NAME (type)) |
e24fa534 | 3805 | return t; |
c6a1db6c RS |
3806 | |
3807 | /* We need a new one. */ | |
2c3dd6b7 | 3808 | t = build_type_copy (type); |
3932261a | 3809 | set_type_quals (t, type_quals); |
c6a1db6c RS |
3810 | return t; |
3811 | } | |
b4ac57ab RS |
3812 | |
3813 | /* Create a new variant of TYPE, equivalent but distinct. | |
3814 | This is so the caller can modify it. */ | |
3815 | ||
3816 | tree | |
3817 | build_type_copy (type) | |
3818 | tree type; | |
3819 | { | |
3820 | register tree t, m = TYPE_MAIN_VARIANT (type); | |
3821 | register struct obstack *ambient_obstack = current_obstack; | |
3822 | ||
d9cbc259 | 3823 | current_obstack = TYPE_OBSTACK (type); |
b4ac57ab | 3824 | t = copy_node (type); |
d9cbc259 RK |
3825 | current_obstack = ambient_obstack; |
3826 | ||
b4ac57ab RS |
3827 | TYPE_POINTER_TO (t) = 0; |
3828 | TYPE_REFERENCE_TO (t) = 0; | |
3829 | ||
3830 | /* Add this type to the chain of variants of TYPE. */ | |
3831 | TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m); | |
3832 | TYPE_NEXT_VARIANT (m) = t; | |
3833 | ||
b4ac57ab RS |
3834 | return t; |
3835 | } | |
c6a1db6c RS |
3836 | \f |
3837 | /* Hashing of types so that we don't make duplicates. | |
3838 | The entry point is `type_hash_canon'. */ | |
3839 | ||
c6a1db6c RS |
3840 | /* Compute a hash code for a list of types (chain of TREE_LIST nodes |
3841 | with types in the TREE_VALUE slots), by adding the hash codes | |
3842 | of the individual types. */ | |
3843 | ||
05bccae2 | 3844 | unsigned int |
c6a1db6c RS |
3845 | type_hash_list (list) |
3846 | tree list; | |
3847 | { | |
05bccae2 | 3848 | unsigned int hashcode; |
c6a1db6c | 3849 | register tree tail; |
d4b60170 | 3850 | |
c6a1db6c RS |
3851 | for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail)) |
3852 | hashcode += TYPE_HASH (TREE_VALUE (tail)); | |
d4b60170 | 3853 | |
c6a1db6c RS |
3854 | return hashcode; |
3855 | } | |
3856 | ||
3857 | /* Look in the type hash table for a type isomorphic to TYPE. | |
3858 | If one is found, return it. Otherwise return 0. */ | |
3859 | ||
3860 | tree | |
3861 | type_hash_lookup (hashcode, type) | |
05bccae2 | 3862 | unsigned int hashcode; |
c6a1db6c RS |
3863 | tree type; |
3864 | { | |
3865 | register struct type_hash *h; | |
da48638e AH |
3866 | |
3867 | /* The TYPE_ALIGN field of a type is set by layout_type(), so we | |
3868 | must call that routine before comparing TYPE_ALIGNs. */ | |
3869 | layout_type (type); | |
3870 | ||
c6a1db6c RS |
3871 | for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next) |
3872 | if (h->hashcode == hashcode | |
3873 | && TREE_CODE (h->type) == TREE_CODE (type) | |
3874 | && TREE_TYPE (h->type) == TREE_TYPE (type) | |
91e97eb8 RK |
3875 | && attribute_list_equal (TYPE_ATTRIBUTES (h->type), |
3876 | TYPE_ATTRIBUTES (type)) | |
da48638e | 3877 | && TYPE_ALIGN (h->type) == TYPE_ALIGN (type) |
c6a1db6c RS |
3878 | && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type) |
3879 | || tree_int_cst_equal (TYPE_MAX_VALUE (h->type), | |
3880 | TYPE_MAX_VALUE (type))) | |
3881 | && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type) | |
3882 | || tree_int_cst_equal (TYPE_MIN_VALUE (h->type), | |
3883 | TYPE_MIN_VALUE (type))) | |
364e1f1c | 3884 | /* Note that TYPE_DOMAIN is TYPE_ARG_TYPES for FUNCTION_TYPE. */ |
c6a1db6c RS |
3885 | && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type) |
3886 | || (TYPE_DOMAIN (h->type) | |
3887 | && TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST | |
3888 | && TYPE_DOMAIN (type) | |
3889 | && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST | |
364e1f1c RK |
3890 | && type_list_equal (TYPE_DOMAIN (h->type), |
3891 | TYPE_DOMAIN (type))))) | |
c6a1db6c | 3892 | return h->type; |
d4b60170 | 3893 | |
c6a1db6c RS |
3894 | return 0; |
3895 | } | |
3896 | ||
3897 | /* Add an entry to the type-hash-table | |
3898 | for a type TYPE whose hash code is HASHCODE. */ | |
3899 | ||
3900 | void | |
3901 | type_hash_add (hashcode, type) | |
05bccae2 | 3902 | unsigned int hashcode; |
c6a1db6c RS |
3903 | tree type; |
3904 | { | |
3905 | register struct type_hash *h; | |
3906 | ||
63ebc275 | 3907 | h = (struct type_hash *) permalloc (sizeof (struct type_hash)); |
c6a1db6c RS |
3908 | h->hashcode = hashcode; |
3909 | h->type = type; | |
3910 | h->next = type_hash_table[hashcode % TYPE_HASH_SIZE]; | |
3911 | type_hash_table[hashcode % TYPE_HASH_SIZE] = h; | |
3912 | } | |
3913 | ||
3914 | /* Given TYPE, and HASHCODE its hash code, return the canonical | |
3915 | object for an identical type if one already exists. | |
3916 | Otherwise, return TYPE, and record it as the canonical object | |
3917 | if it is a permanent object. | |
3918 | ||
3919 | To use this function, first create a type of the sort you want. | |
3920 | Then compute its hash code from the fields of the type that | |
3921 | make it different from other similar types. | |
3922 | Then call this function and use the value. | |
3923 | This function frees the type you pass in if it is a duplicate. */ | |
3924 | ||
3925 | /* Set to 1 to debug without canonicalization. Never set by program. */ | |
3926 | int debug_no_type_hash = 0; | |
3927 | ||
3928 | tree | |
3929 | type_hash_canon (hashcode, type) | |
05bccae2 | 3930 | unsigned int hashcode; |
c6a1db6c RS |
3931 | tree type; |
3932 | { | |
3933 | tree t1; | |
3934 | ||
3935 | if (debug_no_type_hash) | |
3936 | return type; | |
3937 | ||
3938 | t1 = type_hash_lookup (hashcode, type); | |
3939 | if (t1 != 0) | |
3940 | { | |
a3770a81 RH |
3941 | if (!ggc_p) |
3942 | obstack_free (TYPE_OBSTACK (type), type); | |
d4b60170 | 3943 | |
c6a1db6c RS |
3944 | #ifdef GATHER_STATISTICS |
3945 | tree_node_counts[(int)t_kind]--; | |
3946 | tree_node_sizes[(int)t_kind] -= sizeof (struct tree_type); | |
3947 | #endif | |
3948 | return t1; | |
3949 | } | |
3950 | ||
af493865 | 3951 | /* If this is a permanent type, record it for later reuse. */ |
858e574f | 3952 | if (ggc_p || TREE_PERMANENT (type)) |
c6a1db6c RS |
3953 | type_hash_add (hashcode, type); |
3954 | ||
3955 | return type; | |
3956 | } | |
3957 | ||
87ff9c8e RH |
3958 | /* Mark ARG (which is really a struct type_hash **) for GC. */ |
3959 | ||
3960 | static void | |
3961 | mark_type_hash (arg) | |
3962 | void *arg; | |
3963 | { | |
3964 | struct type_hash *t = *(struct type_hash **) arg; | |
3965 | ||
3966 | while (t) | |
3967 | { | |
3968 | ggc_mark_tree (t->type); | |
3969 | t = t->next; | |
3970 | } | |
3971 | } | |
3972 | ||
2a3c15b5 DE |
3973 | /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes |
3974 | with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots), | |
3975 | by adding the hash codes of the individual attributes. */ | |
3e3d7e77 | 3976 | |
05bccae2 | 3977 | unsigned int |
2a3c15b5 DE |
3978 | attribute_hash_list (list) |
3979 | tree list; | |
3e3d7e77 | 3980 | { |
05bccae2 | 3981 | unsigned int hashcode; |
2a3c15b5 | 3982 | register tree tail; |
d4b60170 | 3983 | |
2a3c15b5 DE |
3984 | for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail)) |
3985 | /* ??? Do we want to add in TREE_VALUE too? */ | |
3986 | hashcode += TYPE_HASH (TREE_PURPOSE (tail)); | |
3987 | return hashcode; | |
3e3d7e77 RK |
3988 | } |
3989 | ||
91e97eb8 RK |
3990 | /* Given two lists of attributes, return true if list l2 is |
3991 | equivalent to l1. */ | |
3992 | ||
3993 | int | |
3994 | attribute_list_equal (l1, l2) | |
3995 | tree l1, l2; | |
3996 | { | |
3997 | return attribute_list_contained (l1, l2) | |
3998 | && attribute_list_contained (l2, l1); | |
3999 | } | |
4000 | ||
2a3c15b5 DE |
4001 | /* Given two lists of attributes, return true if list L2 is |
4002 | completely contained within L1. */ | |
4003 | /* ??? This would be faster if attribute names were stored in a canonicalized | |
4004 | form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method | |
4005 | must be used to show these elements are equivalent (which they are). */ | |
4006 | /* ??? It's not clear that attributes with arguments will always be handled | |
4007 | correctly. */ | |
91e97eb8 RK |
4008 | |
4009 | int | |
4010 | attribute_list_contained (l1, l2) | |
4011 | tree l1, l2; | |
4012 | { | |
4013 | register tree t1, t2; | |
4014 | ||
4015 | /* First check the obvious, maybe the lists are identical. */ | |
4016 | if (l1 == l2) | |
4017 | return 1; | |
4018 | ||
2a3c15b5 | 4019 | /* Maybe the lists are similar. */ |
91e97eb8 | 4020 | for (t1 = l1, t2 = l2; |
d4b60170 | 4021 | t1 != 0 && t2 != 0 |
2a3c15b5 | 4022 | && TREE_PURPOSE (t1) == TREE_PURPOSE (t2) |
91e97eb8 RK |
4023 | && TREE_VALUE (t1) == TREE_VALUE (t2); |
4024 | t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2)); | |
4025 | ||
4026 | /* Maybe the lists are equal. */ | |
4027 | if (t1 == 0 && t2 == 0) | |
4028 | return 1; | |
4029 | ||
d4b60170 | 4030 | for (; t2 != 0; t2 = TREE_CHAIN (t2)) |
2a3c15b5 | 4031 | { |
364e1f1c RK |
4032 | tree attr |
4033 | = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1); | |
2a3c15b5 | 4034 | |
d4b60170 | 4035 | if (attr == 0) |
91e97eb8 | 4036 | return 0; |
d4b60170 | 4037 | |
2a3c15b5 DE |
4038 | if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) != 1) |
4039 | return 0; | |
4040 | } | |
3e3d7e77 | 4041 | |
91e97eb8 RK |
4042 | return 1; |
4043 | } | |
4044 | ||
c6a1db6c RS |
4045 | /* Given two lists of types |
4046 | (chains of TREE_LIST nodes with types in the TREE_VALUE slots) | |
4047 | return 1 if the lists contain the same types in the same order. | |
4048 | Also, the TREE_PURPOSEs must match. */ | |
4049 | ||
4050 | int | |
4051 | type_list_equal (l1, l2) | |
4052 | tree l1, l2; | |
4053 | { | |
4054 | register tree t1, t2; | |
364e1f1c | 4055 | |
c6a1db6c | 4056 | for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2)) |
364e1f1c RK |
4057 | if (TREE_VALUE (t1) != TREE_VALUE (t2) |
4058 | || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2) | |
bbda4250 JM |
4059 | && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)) |
4060 | && (TREE_TYPE (TREE_PURPOSE (t1)) | |
4061 | == TREE_TYPE (TREE_PURPOSE (t2)))))) | |
364e1f1c | 4062 | return 0; |
c6a1db6c RS |
4063 | |
4064 | return t1 == t2; | |
4065 | } | |
4066 | ||
4067 | /* Nonzero if integer constants T1 and T2 | |
4068 | represent the same constant value. */ | |
4069 | ||
4070 | int | |
4071 | tree_int_cst_equal (t1, t2) | |
4072 | tree t1, t2; | |
4073 | { | |
4074 | if (t1 == t2) | |
4075 | return 1; | |
d4b60170 | 4076 | |
c6a1db6c RS |
4077 | if (t1 == 0 || t2 == 0) |
4078 | return 0; | |
d4b60170 | 4079 | |
c6a1db6c RS |
4080 | if (TREE_CODE (t1) == INTEGER_CST |
4081 | && TREE_CODE (t2) == INTEGER_CST | |
4082 | && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2) | |
4083 | && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2)) | |
4084 | return 1; | |
d4b60170 | 4085 | |
c6a1db6c RS |
4086 | return 0; |
4087 | } | |
4088 | ||
4089 | /* Nonzero if integer constants T1 and T2 represent values that satisfy <. | |
4090 | The precise way of comparison depends on their data type. */ | |
4091 | ||
4092 | int | |
4093 | tree_int_cst_lt (t1, t2) | |
4094 | tree t1, t2; | |
4095 | { | |
4096 | if (t1 == t2) | |
4097 | return 0; | |
4098 | ||
d4b60170 | 4099 | if (! TREE_UNSIGNED (TREE_TYPE (t1))) |
c6a1db6c | 4100 | return INT_CST_LT (t1, t2); |
d4b60170 | 4101 | |
c6a1db6c RS |
4102 | return INT_CST_LT_UNSIGNED (t1, t2); |
4103 | } | |
4104 | ||
a49a6a68 JW |
4105 | /* Return the most significant bit of the integer constant T. */ |
4106 | ||
4107 | int | |
4108 | tree_int_cst_msb (t) | |
4109 | tree t; | |
4110 | { | |
4111 | register int prec; | |
4112 | HOST_WIDE_INT h; | |
4113 | HOST_WIDE_INT l; | |
4114 | ||
4115 | /* Note that using TYPE_PRECISION here is wrong. We care about the | |
4116 | actual bits, not the (arbitrary) range of the type. */ | |
4117 | prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1; | |
4118 | rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec, | |
4119 | 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0); | |
4120 | return (l & 1) == 1; | |
4121 | } | |
4122 | ||
6d9cb074 RK |
4123 | /* Return an indication of the sign of the integer constant T. |
4124 | The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0. | |
4125 | Note that -1 will never be returned it T's type is unsigned. */ | |
4126 | ||
4127 | int | |
4128 | tree_int_cst_sgn (t) | |
4129 | tree t; | |
4130 | { | |
4131 | if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0) | |
4132 | return 0; | |
4133 | else if (TREE_UNSIGNED (TREE_TYPE (t))) | |
4134 | return 1; | |
4135 | else if (TREE_INT_CST_HIGH (t) < 0) | |
4136 | return -1; | |
4137 | else | |
4138 | return 1; | |
4139 | } | |
4140 | ||
364e1f1c RK |
4141 | /* Compare two constructor-element-type constants. Return 1 if the lists |
4142 | are known to be equal; otherwise return 0. */ | |
4143 | ||
c6a1db6c RS |
4144 | int |
4145 | simple_cst_list_equal (l1, l2) | |
4146 | tree l1, l2; | |
4147 | { | |
4148 | while (l1 != NULL_TREE && l2 != NULL_TREE) | |
4149 | { | |
364e1f1c | 4150 | if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1) |
c6a1db6c | 4151 | return 0; |
364e1f1c | 4152 | |
c6a1db6c RS |
4153 | l1 = TREE_CHAIN (l1); |
4154 | l2 = TREE_CHAIN (l2); | |
4155 | } | |
364e1f1c | 4156 | |
d4b60170 | 4157 | return l1 == l2; |
c6a1db6c RS |
4158 | } |
4159 | ||
4160 | /* Return truthvalue of whether T1 is the same tree structure as T2. | |
4161 | Return 1 if they are the same. | |
4162 | Return 0 if they are understandably different. | |
4163 | Return -1 if either contains tree structure not understood by | |
4164 | this function. */ | |
4165 | ||
4166 | int | |
4167 | simple_cst_equal (t1, t2) | |
4168 | tree t1, t2; | |
4169 | { | |
4170 | register enum tree_code code1, code2; | |
4171 | int cmp; | |
d4b60170 | 4172 | int i; |
c6a1db6c RS |
4173 | |
4174 | if (t1 == t2) | |
4175 | return 1; | |
4176 | if (t1 == 0 || t2 == 0) | |
4177 | return 0; | |
4178 | ||
4179 | code1 = TREE_CODE (t1); | |
4180 | code2 = TREE_CODE (t2); | |
4181 | ||
4182 | if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR) | |
af79bb86 JM |
4183 | { |
4184 | if (code2 == NOP_EXPR || code2 == CONVERT_EXPR | |
4185 | || code2 == NON_LVALUE_EXPR) | |
4186 | return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
4187 | else | |
4188 | return simple_cst_equal (TREE_OPERAND (t1, 0), t2); | |
4189 | } | |
d4b60170 | 4190 | |
c6a1db6c RS |
4191 | else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR |
4192 | || code2 == NON_LVALUE_EXPR) | |
4193 | return simple_cst_equal (t1, TREE_OPERAND (t2, 0)); | |
4194 | ||
4195 | if (code1 != code2) | |
4196 | return 0; | |
4197 | ||
4198 | switch (code1) | |
4199 | { | |
4200 | case INTEGER_CST: | |
d4b60170 RK |
4201 | return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2) |
4202 | && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2)); | |
c6a1db6c RS |
4203 | |
4204 | case REAL_CST: | |
41c9120b | 4205 | return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2)); |
c6a1db6c RS |
4206 | |
4207 | case STRING_CST: | |
d4b60170 RK |
4208 | return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2) |
4209 | && ! bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2), | |
4210 | TREE_STRING_LENGTH (t1))); | |
c6a1db6c RS |
4211 | |
4212 | case CONSTRUCTOR: | |
b3abfd6f JM |
4213 | if (CONSTRUCTOR_ELTS (t1) == CONSTRUCTOR_ELTS (t2)) |
4214 | return 1; | |
4215 | else | |
4216 | abort (); | |
c6a1db6c RS |
4217 | |
4218 | case SAVE_EXPR: | |
4219 | return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
4220 | ||
4221 | case CALL_EXPR: | |
4222 | cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
4223 | if (cmp <= 0) | |
4224 | return cmp; | |
d4b60170 RK |
4225 | return |
4226 | simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); | |
c6a1db6c RS |
4227 | |
4228 | case TARGET_EXPR: | |
4229 | /* Special case: if either target is an unallocated VAR_DECL, | |
4230 | it means that it's going to be unified with whatever the | |
4231 | TARGET_EXPR is really supposed to initialize, so treat it | |
4232 | as being equivalent to anything. */ | |
4233 | if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL | |
4234 | && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE | |
4235 | && DECL_RTL (TREE_OPERAND (t1, 0)) == 0) | |
4236 | || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL | |
4237 | && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE | |
4238 | && DECL_RTL (TREE_OPERAND (t2, 0)) == 0)) | |
4239 | cmp = 1; | |
4240 | else | |
4241 | cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
d4b60170 | 4242 | |
c6a1db6c RS |
4243 | if (cmp <= 0) |
4244 | return cmp; | |
d4b60170 | 4245 | |
c6a1db6c RS |
4246 | return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); |
4247 | ||
4248 | case WITH_CLEANUP_EXPR: | |
4249 | cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
4250 | if (cmp <= 0) | |
4251 | return cmp; | |
d4b60170 | 4252 | |
c6a1db6c RS |
4253 | return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2)); |
4254 | ||
4255 | case COMPONENT_REF: | |
4256 | if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1)) | |
4257 | return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
d4b60170 | 4258 | |
c6a1db6c RS |
4259 | return 0; |
4260 | ||
c6a1db6c RS |
4261 | case VAR_DECL: |
4262 | case PARM_DECL: | |
4263 | case CONST_DECL: | |
4264 | case FUNCTION_DECL: | |
4265 | return 0; | |
e9a25f70 JL |
4266 | |
4267 | default: | |
4268 | break; | |
86aed40b | 4269 | } |
c6a1db6c | 4270 | |
8ae49a28 RK |
4271 | /* This general rule works for most tree codes. All exceptions should be |
4272 | handled above. If this is a language-specific tree code, we can't | |
4273 | trust what might be in the operand, so say we don't know | |
4274 | the situation. */ | |
0a6969ad | 4275 | if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE) |
8ae49a28 | 4276 | return -1; |
c6a1db6c | 4277 | |
86aed40b RS |
4278 | switch (TREE_CODE_CLASS (code1)) |
4279 | { | |
86aed40b RS |
4280 | case '1': |
4281 | case '2': | |
4282 | case '<': | |
4283 | case 'e': | |
4284 | case 'r': | |
4285 | case 's': | |
4286 | cmp = 1; | |
d4b60170 | 4287 | for (i = 0; i < tree_code_length[(int) code1]; i++) |
86aed40b RS |
4288 | { |
4289 | cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)); | |
4290 | if (cmp <= 0) | |
4291 | return cmp; | |
4292 | } | |
d4b60170 | 4293 | |
86aed40b | 4294 | return cmp; |
86aed40b | 4295 | |
e9a25f70 JL |
4296 | default: |
4297 | return -1; | |
4298 | } | |
c6a1db6c | 4299 | } |
05bccae2 RK |
4300 | |
4301 | /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value. | |
4302 | Return -1, 0, or 1 if the value of T is less than, equal to, or greater | |
4303 | than U, respectively. */ | |
4304 | ||
4305 | int | |
4306 | compare_tree_int (t, u) | |
4307 | tree t; | |
4308 | unsigned int u; | |
4309 | { | |
4310 | if (tree_int_cst_sgn (t) < 0) | |
4311 | return -1; | |
4312 | else if (TREE_INT_CST_HIGH (t) != 0) | |
4313 | return 1; | |
4314 | else if (TREE_INT_CST_LOW (t) == u) | |
4315 | return 0; | |
4316 | else if (TREE_INT_CST_LOW (t) < u) | |
4317 | return -1; | |
4318 | else | |
4319 | return 1; | |
4320 | } | |
c6a1db6c RS |
4321 | \f |
4322 | /* Constructors for pointer, array and function types. | |
4323 | (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are | |
4324 | constructed by language-dependent code, not here.) */ | |
4325 | ||
4326 | /* Construct, lay out and return the type of pointers to TO_TYPE. | |
4327 | If such a type has already been constructed, reuse it. */ | |
4328 | ||
4329 | tree | |
4330 | build_pointer_type (to_type) | |
4331 | tree to_type; | |
4332 | { | |
4333 | register tree t = TYPE_POINTER_TO (to_type); | |
c6a1db6c RS |
4334 | |
4335 | /* First, if we already have a type for pointers to TO_TYPE, use it. */ | |
4336 | ||
d4b60170 | 4337 | if (t != 0) |
c6a1db6c RS |
4338 | return t; |
4339 | ||
d9cbc259 RK |
4340 | /* We need a new one. Put this in the same obstack as TO_TYPE. */ |
4341 | push_obstacks (TYPE_OBSTACK (to_type), TYPE_OBSTACK (to_type)); | |
c6a1db6c | 4342 | t = make_node (POINTER_TYPE); |
d9cbc259 RK |
4343 | pop_obstacks (); |
4344 | ||
c6a1db6c RS |
4345 | TREE_TYPE (t) = to_type; |
4346 | ||
4347 | /* Record this type as the pointer to TO_TYPE. */ | |
4348 | TYPE_POINTER_TO (to_type) = t; | |
4349 | ||
4350 | /* Lay out the type. This function has many callers that are concerned | |
4351 | with expression-construction, and this simplifies them all. | |
d9cbc259 | 4352 | Also, it guarantees the TYPE_SIZE is in the same obstack as the type. */ |
c6a1db6c RS |
4353 | layout_type (t); |
4354 | ||
c6a1db6c RS |
4355 | return t; |
4356 | } | |
4357 | ||
d4b60170 RK |
4358 | /* Build the node for the type of references-to-TO_TYPE. */ |
4359 | ||
4360 | tree | |
4361 | build_reference_type (to_type) | |
4362 | tree to_type; | |
4363 | { | |
4364 | register tree t = TYPE_REFERENCE_TO (to_type); | |
4365 | ||
4366 | /* First, if we already have a type for pointers to TO_TYPE, use it. */ | |
4367 | ||
4368 | if (t) | |
4369 | return t; | |
4370 | ||
4371 | /* We need a new one. Put this in the same obstack as TO_TYPE. */ | |
4372 | push_obstacks (TYPE_OBSTACK (to_type), TYPE_OBSTACK (to_type)); | |
4373 | t = make_node (REFERENCE_TYPE); | |
4374 | pop_obstacks (); | |
4375 | ||
4376 | TREE_TYPE (t) = to_type; | |
4377 | ||
4378 | /* Record this type as the pointer to TO_TYPE. */ | |
4379 | TYPE_REFERENCE_TO (to_type) = t; | |
4380 | ||
4381 | layout_type (t); | |
4382 | ||
4383 | return t; | |
4384 | } | |
4385 | ||
c6a1db6c RS |
4386 | /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE. |
4387 | MAXVAL should be the maximum value in the domain | |
e9a25f70 JL |
4388 | (one less than the length of the array). |
4389 | ||
4390 | The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT. | |
4391 | We don't enforce this limit, that is up to caller (e.g. language front end). | |
4392 | The limit exists because the result is a signed type and we don't handle | |
4393 | sizes that use more than one HOST_WIDE_INT. */ | |
c6a1db6c RS |
4394 | |
4395 | tree | |
4396 | build_index_type (maxval) | |
4397 | tree maxval; | |
4398 | { | |
4399 | register tree itype = make_node (INTEGER_TYPE); | |
0fd17968 | 4400 | |
c6a1db6c | 4401 | TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype); |
0fd17968 RK |
4402 | TYPE_MIN_VALUE (itype) = size_zero_node; |
4403 | ||
4404 | push_obstacks (TYPE_OBSTACK (itype), TYPE_OBSTACK (itype)); | |
c6a1db6c | 4405 | TYPE_MAX_VALUE (itype) = convert (sizetype, maxval); |
0fd17968 RK |
4406 | pop_obstacks (); |
4407 | ||
c6a1db6c RS |
4408 | TYPE_MODE (itype) = TYPE_MODE (sizetype); |
4409 | TYPE_SIZE (itype) = TYPE_SIZE (sizetype); | |
def9b006 | 4410 | TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype); |
c6a1db6c RS |
4411 | TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype); |
4412 | if (TREE_CODE (maxval) == INTEGER_CST) | |
4413 | { | |
05bccae2 RK |
4414 | int maxint = TREE_INT_CST_LOW (maxval); |
4415 | ||
cdc5a032 RS |
4416 | /* If the domain should be empty, make sure the maxval |
4417 | remains -1 and is not spoiled by truncation. */ | |
05bccae2 | 4418 | if (tree_int_cst_sgn (maxval) < 0) |
cdc5a032 RS |
4419 | { |
4420 | TYPE_MAX_VALUE (itype) = build_int_2 (-1, -1); | |
4421 | TREE_TYPE (TYPE_MAX_VALUE (itype)) = sizetype; | |
4422 | } | |
05bccae2 | 4423 | |
bc99efc9 | 4424 | return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype); |
c6a1db6c RS |
4425 | } |
4426 | else | |
4427 | return itype; | |
4428 | } | |
4429 | ||
742e43a2 | 4430 | /* Create a range of some discrete type TYPE (an INTEGER_TYPE, |
238a1856 | 4431 | ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with |
742e43a2 | 4432 | low bound LOWVAL and high bound HIGHVAL. |
0f41302f | 4433 | if TYPE==NULL_TREE, sizetype is used. */ |
c6a1db6c RS |
4434 | |
4435 | tree | |
742e43a2 PB |
4436 | build_range_type (type, lowval, highval) |
4437 | tree type, lowval, highval; | |
c6a1db6c RS |
4438 | { |
4439 | register tree itype = make_node (INTEGER_TYPE); | |
0fd17968 | 4440 | |
742e43a2 PB |
4441 | TREE_TYPE (itype) = type; |
4442 | if (type == NULL_TREE) | |
4443 | type = sizetype; | |
0fd17968 RK |
4444 | |
4445 | push_obstacks (TYPE_OBSTACK (itype), TYPE_OBSTACK (itype)); | |
742e43a2 | 4446 | TYPE_MIN_VALUE (itype) = convert (type, lowval); |
e1ee5cdc | 4447 | TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL; |
0fd17968 RK |
4448 | pop_obstacks (); |
4449 | ||
4450 | TYPE_PRECISION (itype) = TYPE_PRECISION (type); | |
742e43a2 PB |
4451 | TYPE_MODE (itype) = TYPE_MODE (type); |
4452 | TYPE_SIZE (itype) = TYPE_SIZE (type); | |
28372f41 | 4453 | TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type); |
742e43a2 | 4454 | TYPE_ALIGN (itype) = TYPE_ALIGN (type); |
e1ee5cdc | 4455 | if (TREE_CODE (lowval) == INTEGER_CST) |
c6a1db6c | 4456 | { |
e1ee5cdc RH |
4457 | HOST_WIDE_INT lowint, highint; |
4458 | int maxint; | |
4459 | ||
4460 | lowint = TREE_INT_CST_LOW (lowval); | |
4461 | if (highval && TREE_CODE (highval) == INTEGER_CST) | |
4462 | highint = TREE_INT_CST_LOW (highval); | |
4463 | else | |
05bccae2 | 4464 | highint = (~(unsigned HOST_WIDE_INT) 0) >> 1; |
e1ee5cdc RH |
4465 | |
4466 | maxint = (int) (highint - lowint); | |
05bccae2 | 4467 | |
bc99efc9 | 4468 | return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype); |
c6a1db6c RS |
4469 | } |
4470 | else | |
4471 | return itype; | |
4472 | } | |
4473 | ||
742e43a2 | 4474 | /* Just like build_index_type, but takes lowval and highval instead |
0f41302f | 4475 | of just highval (maxval). */ |
742e43a2 PB |
4476 | |
4477 | tree | |
4478 | build_index_2_type (lowval,highval) | |
4479 | tree lowval, highval; | |
4480 | { | |
4481 | return build_range_type (NULL_TREE, lowval, highval); | |
4482 | } | |
4483 | ||
c6a1db6c RS |
4484 | /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense). |
4485 | Needed because when index types are not hashed, equal index types | |
4486 | built at different times appear distinct, even though structurally, | |
4487 | they are not. */ | |
4488 | ||
4489 | int | |
4490 | index_type_equal (itype1, itype2) | |
4491 | tree itype1, itype2; | |
4492 | { | |
4493 | if (TREE_CODE (itype1) != TREE_CODE (itype2)) | |
4494 | return 0; | |
d4b60170 | 4495 | |
c6a1db6c RS |
4496 | if (TREE_CODE (itype1) == INTEGER_TYPE) |
4497 | { | |
4498 | if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2) | |
4499 | || TYPE_MODE (itype1) != TYPE_MODE (itype2) | |
364e1f1c | 4500 | || simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2)) != 1 |
c6a1db6c RS |
4501 | || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2)) |
4502 | return 0; | |
d4b60170 | 4503 | |
364e1f1c RK |
4504 | if (1 == simple_cst_equal (TYPE_MIN_VALUE (itype1), |
4505 | TYPE_MIN_VALUE (itype2)) | |
4506 | && 1 == simple_cst_equal (TYPE_MAX_VALUE (itype1), | |
4507 | TYPE_MAX_VALUE (itype2))) | |
c6a1db6c RS |
4508 | return 1; |
4509 | } | |
364e1f1c | 4510 | |
c6a1db6c RS |
4511 | return 0; |
4512 | } | |
4513 | ||
4514 | /* Construct, lay out and return the type of arrays of elements with ELT_TYPE | |
4515 | and number of elements specified by the range of values of INDEX_TYPE. | |
4516 | If such a type has already been constructed, reuse it. */ | |
4517 | ||
4518 | tree | |
4519 | build_array_type (elt_type, index_type) | |
4520 | tree elt_type, index_type; | |
4521 | { | |
4522 | register tree t; | |
05bccae2 | 4523 | unsigned int hashcode; |
c6a1db6c RS |
4524 | |
4525 | if (TREE_CODE (elt_type) == FUNCTION_TYPE) | |
4526 | { | |
4527 | error ("arrays of functions are not meaningful"); | |
4528 | elt_type = integer_type_node; | |
4529 | } | |
4530 | ||
4531 | /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */ | |
4532 | build_pointer_type (elt_type); | |
4533 | ||
4534 | /* Allocate the array after the pointer type, | |
4535 | in case we free it in type_hash_canon. */ | |
4536 | t = make_node (ARRAY_TYPE); | |
4537 | TREE_TYPE (t) = elt_type; | |
4538 | TYPE_DOMAIN (t) = index_type; | |
4539 | ||
4540 | if (index_type == 0) | |
15c76378 | 4541 | { |
15c76378 RS |
4542 | return t; |
4543 | } | |
c6a1db6c RS |
4544 | |
4545 | hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type); | |
4546 | t = type_hash_canon (hashcode, t); | |
4547 | ||
4548 | if (TYPE_SIZE (t) == 0) | |
4549 | layout_type (t); | |
4550 | return t; | |
4551 | } | |
4552 | ||
a260abc9 DE |
4553 | /* Return the TYPE of the elements comprising |
4554 | the innermost dimension of ARRAY. */ | |
4555 | ||
4556 | tree | |
4557 | get_inner_array_type (array) | |
4558 | tree array; | |
4559 | { | |
4560 | tree type = TREE_TYPE (array); | |
4561 | ||
4562 | while (TREE_CODE (type) == ARRAY_TYPE) | |
4563 | type = TREE_TYPE (type); | |
4564 | ||
4565 | return type; | |
4566 | } | |
4567 | ||
c6a1db6c RS |
4568 | /* Construct, lay out and return |
4569 | the type of functions returning type VALUE_TYPE | |
4570 | given arguments of types ARG_TYPES. | |
4571 | ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs | |
4572 | are data type nodes for the arguments of the function. | |
4573 | If such a type has already been constructed, reuse it. */ | |
4574 | ||
4575 | tree | |
4576 | build_function_type (value_type, arg_types) | |
4577 | tree value_type, arg_types; | |
4578 | { | |
4579 | register tree t; | |
05bccae2 | 4580 | unsigned int hashcode; |
c6a1db6c | 4581 | |
c0560b8b | 4582 | if (TREE_CODE (value_type) == FUNCTION_TYPE) |
c6a1db6c | 4583 | { |
c0560b8b | 4584 | error ("function return type cannot be function"); |
c6a1db6c RS |
4585 | value_type = integer_type_node; |
4586 | } | |
4587 | ||
4588 | /* Make a node of the sort we want. */ | |
4589 | t = make_node (FUNCTION_TYPE); | |
4590 | TREE_TYPE (t) = value_type; | |
4591 | TYPE_ARG_TYPES (t) = arg_types; | |
4592 | ||
4593 | /* If we already have such a type, use the old one and free this one. */ | |
4594 | hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types); | |
4595 | t = type_hash_canon (hashcode, t); | |
4596 | ||
4597 | if (TYPE_SIZE (t) == 0) | |
4598 | layout_type (t); | |
4599 | return t; | |
4600 | } | |
4601 | ||
c6a1db6c RS |
4602 | /* Construct, lay out and return the type of methods belonging to class |
4603 | BASETYPE and whose arguments and values are described by TYPE. | |
4604 | If that type exists already, reuse it. | |
4605 | TYPE must be a FUNCTION_TYPE node. */ | |
4606 | ||
4607 | tree | |
4608 | build_method_type (basetype, type) | |
4609 | tree basetype, type; | |
4610 | { | |
4611 | register tree t; | |
05bccae2 | 4612 | unsigned int hashcode; |
c6a1db6c RS |
4613 | |
4614 | /* Make a node of the sort we want. */ | |
4615 | t = make_node (METHOD_TYPE); | |
4616 | ||
4617 | if (TREE_CODE (type) != FUNCTION_TYPE) | |
4618 | abort (); | |
4619 | ||
4620 | TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype); | |
4621 | TREE_TYPE (t) = TREE_TYPE (type); | |
4622 | ||
4623 | /* The actual arglist for this function includes a "hidden" argument | |
4624 | which is "this". Put it into the list of argument types. */ | |
4625 | ||
4626 | TYPE_ARG_TYPES (t) | |
37366632 RK |
4627 | = tree_cons (NULL_TREE, |
4628 | build_pointer_type (basetype), TYPE_ARG_TYPES (type)); | |
c6a1db6c RS |
4629 | |
4630 | /* If we already have such a type, use the old one and free this one. */ | |
4631 | hashcode = TYPE_HASH (basetype) + TYPE_HASH (type); | |
4632 | t = type_hash_canon (hashcode, t); | |
4633 | ||
4634 | if (TYPE_SIZE (t) == 0) | |
4635 | layout_type (t); | |
4636 | ||
4637 | return t; | |
4638 | } | |
4639 | ||
86aed40b RS |
4640 | /* Construct, lay out and return the type of offsets to a value |
4641 | of type TYPE, within an object of type BASETYPE. | |
4642 | If a suitable offset type exists already, reuse it. */ | |
c6a1db6c RS |
4643 | |
4644 | tree | |
4645 | build_offset_type (basetype, type) | |
4646 | tree basetype, type; | |
4647 | { | |
4648 | register tree t; | |
05bccae2 | 4649 | unsigned int hashcode; |
c6a1db6c RS |
4650 | |
4651 | /* Make a node of the sort we want. */ | |
4652 | t = make_node (OFFSET_TYPE); | |
4653 | ||
4654 | TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype); | |
4655 | TREE_TYPE (t) = type; | |
4656 | ||
4657 | /* If we already have such a type, use the old one and free this one. */ | |
4658 | hashcode = TYPE_HASH (basetype) + TYPE_HASH (type); | |
4659 | t = type_hash_canon (hashcode, t); | |
4660 | ||
4661 | if (TYPE_SIZE (t) == 0) | |
4662 | layout_type (t); | |
4663 | ||
4664 | return t; | |
4665 | } | |
4666 | ||
4667 | /* Create a complex type whose components are COMPONENT_TYPE. */ | |
4668 | ||
4669 | tree | |
4670 | build_complex_type (component_type) | |
4671 | tree component_type; | |
4672 | { | |
4673 | register tree t; | |
05bccae2 | 4674 | unsigned int hashcode; |
c6a1db6c RS |
4675 | |
4676 | /* Make a node of the sort we want. */ | |
4677 | t = make_node (COMPLEX_TYPE); | |
4678 | ||
4679 | TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type); | |
3932261a | 4680 | set_type_quals (t, TYPE_QUALS (component_type)); |
c6a1db6c RS |
4681 | |
4682 | /* If we already have such a type, use the old one and free this one. */ | |
4683 | hashcode = TYPE_HASH (component_type); | |
4684 | t = type_hash_canon (hashcode, t); | |
4685 | ||
4686 | if (TYPE_SIZE (t) == 0) | |
4687 | layout_type (t); | |
4688 | ||
405f63da MM |
4689 | /* If we are writing Dwarf2 output we need to create a name, |
4690 | since complex is a fundamental type. */ | |
4691 | if (write_symbols == DWARF2_DEBUG && ! TYPE_NAME (t)) | |
4692 | { | |
ec0ce6e2 | 4693 | const char *name; |
405f63da MM |
4694 | if (component_type == char_type_node) |
4695 | name = "complex char"; | |
4696 | else if (component_type == signed_char_type_node) | |
4697 | name = "complex signed char"; | |
4698 | else if (component_type == unsigned_char_type_node) | |
4699 | name = "complex unsigned char"; | |
4700 | else if (component_type == short_integer_type_node) | |
4701 | name = "complex short int"; | |
4702 | else if (component_type == short_unsigned_type_node) | |
4703 | name = "complex short unsigned int"; | |
4704 | else if (component_type == integer_type_node) | |
4705 | name = "complex int"; | |
4706 | else if (component_type == unsigned_type_node) | |
4707 | name = "complex unsigned int"; | |
4708 | else if (component_type == long_integer_type_node) | |
4709 | name = "complex long int"; | |
4710 | else if (component_type == long_unsigned_type_node) | |
4711 | name = "complex long unsigned int"; | |
4712 | else if (component_type == long_long_integer_type_node) | |
4713 | name = "complex long long int"; | |
4714 | else if (component_type == long_long_unsigned_type_node) | |
4715 | name = "complex long long unsigned int"; | |
4716 | else | |
d4b60170 | 4717 | name = 0; |
405f63da | 4718 | |
d4b60170 | 4719 | if (name != 0) |
405f63da MM |
4720 | TYPE_NAME (t) = get_identifier (name); |
4721 | } | |
4722 | ||
c6a1db6c RS |
4723 | return t; |
4724 | } | |
4725 | \f | |
4726 | /* Return OP, stripped of any conversions to wider types as much as is safe. | |
4727 | Converting the value back to OP's type makes a value equivalent to OP. | |
4728 | ||
4729 | If FOR_TYPE is nonzero, we return a value which, if converted to | |
4730 | type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE. | |
4731 | ||
4732 | If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the | |
4733 | narrowest type that can hold the value, even if they don't exactly fit. | |
4734 | Otherwise, bit-field references are changed to a narrower type | |
4735 | only if they can be fetched directly from memory in that type. | |
4736 | ||
4737 | OP must have integer, real or enumeral type. Pointers are not allowed! | |
4738 | ||
4739 | There are some cases where the obvious value we could return | |
4740 | would regenerate to OP if converted to OP's type, | |
4741 | but would not extend like OP to wider types. | |
4742 | If FOR_TYPE indicates such extension is contemplated, we eschew such values. | |
4743 | For example, if OP is (unsigned short)(signed char)-1, | |
4744 | we avoid returning (signed char)-1 if FOR_TYPE is int, | |
4745 | even though extending that to an unsigned short would regenerate OP, | |
4746 | since the result of extending (signed char)-1 to (int) | |
4747 | is different from (int) OP. */ | |
4748 | ||
4749 | tree | |
4750 | get_unwidened (op, for_type) | |
4751 | register tree op; | |
4752 | tree for_type; | |
4753 | { | |
4754 | /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */ | |
c6a1db6c RS |
4755 | register tree type = TREE_TYPE (op); |
4756 | register unsigned final_prec | |
4757 | = TYPE_PRECISION (for_type != 0 ? for_type : type); | |
4758 | register int uns | |
4759 | = (for_type != 0 && for_type != type | |
4760 | && final_prec > TYPE_PRECISION (type) | |
4761 | && TREE_UNSIGNED (type)); | |
4762 | register tree win = op; | |
4763 | ||
4764 | while (TREE_CODE (op) == NOP_EXPR) | |
4765 | { | |
4766 | register int bitschange | |
4767 | = TYPE_PRECISION (TREE_TYPE (op)) | |
4768 | - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))); | |
4769 | ||
4770 | /* Truncations are many-one so cannot be removed. | |
4771 | Unless we are later going to truncate down even farther. */ | |
4772 | if (bitschange < 0 | |
4773 | && final_prec > TYPE_PRECISION (TREE_TYPE (op))) | |
4774 | break; | |
4775 | ||
4776 | /* See what's inside this conversion. If we decide to strip it, | |
4777 | we will set WIN. */ | |
4778 | op = TREE_OPERAND (op, 0); | |
4779 | ||
4780 | /* If we have not stripped any zero-extensions (uns is 0), | |
4781 | we can strip any kind of extension. | |
4782 | If we have previously stripped a zero-extension, | |
4783 | only zero-extensions can safely be stripped. | |
4784 | Any extension can be stripped if the bits it would produce | |
4785 | are all going to be discarded later by truncating to FOR_TYPE. */ | |
4786 | ||
4787 | if (bitschange > 0) | |
4788 | { | |
4789 | if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op))) | |
4790 | win = op; | |
4791 | /* TREE_UNSIGNED says whether this is a zero-extension. | |
4792 | Let's avoid computing it if it does not affect WIN | |
4793 | and if UNS will not be needed again. */ | |
4794 | if ((uns || TREE_CODE (op) == NOP_EXPR) | |
4795 | && TREE_UNSIGNED (TREE_TYPE (op))) | |
4796 | { | |
4797 | uns = 1; | |
4798 | win = op; | |
4799 | } | |
4800 | } | |
4801 | } | |
4802 | ||
4803 | if (TREE_CODE (op) == COMPONENT_REF | |
4804 | /* Since type_for_size always gives an integer type. */ | |
02a27e82 | 4805 | && TREE_CODE (type) != REAL_TYPE |
956d6950 | 4806 | /* Don't crash if field not laid out yet. */ |
02a27e82 | 4807 | && DECL_SIZE (TREE_OPERAND (op, 1)) != 0) |
c6a1db6c | 4808 | { |
05bccae2 RK |
4809 | unsigned int innerprec |
4810 | = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1))); | |
4811 | ||
c6a1db6c RS |
4812 | type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1))); |
4813 | ||
4814 | /* We can get this structure field in the narrowest type it fits in. | |
4815 | If FOR_TYPE is 0, do this only for a field that matches the | |
4816 | narrower type exactly and is aligned for it | |
4817 | The resulting extension to its nominal type (a fullword type) | |
4818 | must fit the same conditions as for other extensions. */ | |
4819 | ||
4820 | if (innerprec < TYPE_PRECISION (TREE_TYPE (op)) | |
4821 | && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))) | |
4822 | && (! uns || final_prec <= innerprec | |
4823 | || TREE_UNSIGNED (TREE_OPERAND (op, 1))) | |
4824 | && type != 0) | |
4825 | { | |
4826 | win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0), | |
4827 | TREE_OPERAND (op, 1)); | |
4828 | TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op); | |
4829 | TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op); | |
4830 | TREE_RAISES (win) = TREE_RAISES (op); | |
4831 | } | |
4832 | } | |
4833 | return win; | |
4834 | } | |
4835 | \f | |
4836 | /* Return OP or a simpler expression for a narrower value | |
4837 | which can be sign-extended or zero-extended to give back OP. | |
4838 | Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended | |
4839 | or 0 if the value should be sign-extended. */ | |
4840 | ||
4841 | tree | |
4842 | get_narrower (op, unsignedp_ptr) | |
4843 | register tree op; | |
4844 | int *unsignedp_ptr; | |
4845 | { | |
4846 | register int uns = 0; | |
4847 | int first = 1; | |
4848 | register tree win = op; | |
4849 | ||
4850 | while (TREE_CODE (op) == NOP_EXPR) | |
4851 | { | |
4852 | register int bitschange | |
d4b60170 RK |
4853 | = (TYPE_PRECISION (TREE_TYPE (op)) |
4854 | - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)))); | |
c6a1db6c RS |
4855 | |
4856 | /* Truncations are many-one so cannot be removed. */ | |
4857 | if (bitschange < 0) | |
4858 | break; | |
4859 | ||
4860 | /* See what's inside this conversion. If we decide to strip it, | |
4861 | we will set WIN. */ | |
4862 | op = TREE_OPERAND (op, 0); | |
4863 | ||
4864 | if (bitschange > 0) | |
4865 | { | |
4866 | /* An extension: the outermost one can be stripped, | |
4867 | but remember whether it is zero or sign extension. */ | |
4868 | if (first) | |
4869 | uns = TREE_UNSIGNED (TREE_TYPE (op)); | |
4870 | /* Otherwise, if a sign extension has been stripped, | |
4871 | only sign extensions can now be stripped; | |
4872 | if a zero extension has been stripped, only zero-extensions. */ | |
4873 | else if (uns != TREE_UNSIGNED (TREE_TYPE (op))) | |
4874 | break; | |
4875 | first = 0; | |
4876 | } | |
e02b9957 DE |
4877 | else /* bitschange == 0 */ |
4878 | { | |
4879 | /* A change in nominal type can always be stripped, but we must | |
4880 | preserve the unsignedness. */ | |
4881 | if (first) | |
4882 | uns = TREE_UNSIGNED (TREE_TYPE (op)); | |
4883 | first = 0; | |
4884 | } | |
c6a1db6c RS |
4885 | |
4886 | win = op; | |
4887 | } | |
4888 | ||
4889 | if (TREE_CODE (op) == COMPONENT_REF | |
4890 | /* Since type_for_size always gives an integer type. */ | |
4891 | && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE) | |
4892 | { | |
05bccae2 RK |
4893 | unsigned int innerprec |
4894 | = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1))); | |
4895 | ||
c6a1db6c RS |
4896 | tree type = type_for_size (innerprec, TREE_UNSIGNED (op)); |
4897 | ||
4898 | /* We can get this structure field in a narrower type that fits it, | |
4899 | but the resulting extension to its nominal type (a fullword type) | |
4900 | must satisfy the same conditions as for other extensions. | |
4901 | ||
4902 | Do this only for fields that are aligned (not bit-fields), | |
4903 | because when bit-field insns will be used there is no | |
4904 | advantage in doing this. */ | |
4905 | ||
4906 | if (innerprec < TYPE_PRECISION (TREE_TYPE (op)) | |
4907 | && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)) | |
4908 | && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1))) | |
4909 | && type != 0) | |
4910 | { | |
4911 | if (first) | |
4912 | uns = TREE_UNSIGNED (TREE_OPERAND (op, 1)); | |
4913 | win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0), | |
4914 | TREE_OPERAND (op, 1)); | |
4915 | TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op); | |
4916 | TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op); | |
4917 | TREE_RAISES (win) = TREE_RAISES (op); | |
4918 | } | |
4919 | } | |
4920 | *unsignedp_ptr = uns; | |
4921 | return win; | |
4922 | } | |
4923 | \f | |
c6a1db6c RS |
4924 | /* Nonzero if integer constant C has a value that is permissible |
4925 | for type TYPE (an INTEGER_TYPE). */ | |
4926 | ||
4927 | int | |
4928 | int_fits_type_p (c, type) | |
4929 | tree c, type; | |
4930 | { | |
4931 | if (TREE_UNSIGNED (type)) | |
857d2849 RK |
4932 | return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST |
4933 | && INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)) | |
4934 | && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST | |
ae0a3dfb RK |
4935 | && INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type))) |
4936 | /* Negative ints never fit unsigned types. */ | |
4937 | && ! (TREE_INT_CST_HIGH (c) < 0 | |
4938 | && ! TREE_UNSIGNED (TREE_TYPE (c)))); | |
c6a1db6c | 4939 | else |
857d2849 RK |
4940 | return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST |
4941 | && INT_CST_LT (TYPE_MAX_VALUE (type), c)) | |
4942 | && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST | |
ae0a3dfb RK |
4943 | && INT_CST_LT (c, TYPE_MIN_VALUE (type))) |
4944 | /* Unsigned ints with top bit set never fit signed types. */ | |
4945 | && ! (TREE_INT_CST_HIGH (c) < 0 | |
4946 | && TREE_UNSIGNED (TREE_TYPE (c)))); | |
c6a1db6c RS |
4947 | } |
4948 | ||
140b60b4 MM |
4949 | /* Given a DECL or TYPE, return the scope in which it was declared, or |
4950 | NUL_TREE if there is no containing scope. */ | |
4951 | ||
4952 | tree | |
4953 | get_containing_scope (t) | |
4954 | tree t; | |
4955 | { | |
4956 | return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t)); | |
4957 | } | |
4958 | ||
bfa30b22 | 4959 | /* Return the innermost context enclosing DECL that is |
c6a1db6c RS |
4960 | a FUNCTION_DECL, or zero if none. */ |
4961 | ||
4962 | tree | |
bfa30b22 RK |
4963 | decl_function_context (decl) |
4964 | tree decl; | |
c6a1db6c RS |
4965 | { |
4966 | tree context; | |
4967 | ||
bfa30b22 | 4968 | if (TREE_CODE (decl) == ERROR_MARK) |
c6a1db6c RS |
4969 | return 0; |
4970 | ||
bfa30b22 RK |
4971 | if (TREE_CODE (decl) == SAVE_EXPR) |
4972 | context = SAVE_EXPR_CONTEXT (decl); | |
6ff7fb95 JM |
4973 | /* C++ virtual functions use DECL_CONTEXT for the class of the vtable |
4974 | where we look up the function at runtime. Such functions always take | |
4975 | a first argument of type 'pointer to real context'. | |
4976 | ||
4977 | C++ should really be fixed to use DECL_CONTEXT for the real context, | |
4978 | and use something else for the "virtual context". */ | |
4979 | else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl)) | |
4980 | context = TYPE_MAIN_VARIANT | |
4981 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
c6a1db6c | 4982 | else |
bfa30b22 | 4983 | context = DECL_CONTEXT (decl); |
c6a1db6c RS |
4984 | |
4985 | while (context && TREE_CODE (context) != FUNCTION_DECL) | |
4986 | { | |
140b60b4 | 4987 | if (TREE_CODE (context) == BLOCK) |
c6a1db6c | 4988 | context = BLOCK_SUPERCONTEXT (context); |
140b60b4 MM |
4989 | else |
4990 | context = get_containing_scope (context); | |
c6a1db6c RS |
4991 | } |
4992 | ||
4993 | return context; | |
4994 | } | |
4995 | ||
bfa30b22 | 4996 | /* Return the innermost context enclosing DECL that is |
c0560b8b | 4997 | a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none. |
c6a1db6c RS |
4998 | TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */ |
4999 | ||
5000 | tree | |
bfa30b22 RK |
5001 | decl_type_context (decl) |
5002 | tree decl; | |
c6a1db6c | 5003 | { |
bfa30b22 | 5004 | tree context = DECL_CONTEXT (decl); |
c6a1db6c RS |
5005 | |
5006 | while (context) | |
5007 | { | |
5008 | if (TREE_CODE (context) == RECORD_TYPE | |
c0560b8b RK |
5009 | || TREE_CODE (context) == UNION_TYPE |
5010 | || TREE_CODE (context) == QUAL_UNION_TYPE) | |
c6a1db6c | 5011 | return context; |
d4b60170 | 5012 | |
c6a1db6c RS |
5013 | if (TREE_CODE (context) == TYPE_DECL |
5014 | || TREE_CODE (context) == FUNCTION_DECL) | |
5015 | context = DECL_CONTEXT (context); | |
d4b60170 | 5016 | |
c6a1db6c RS |
5017 | else if (TREE_CODE (context) == BLOCK) |
5018 | context = BLOCK_SUPERCONTEXT (context); | |
d4b60170 | 5019 | |
c6a1db6c RS |
5020 | else |
5021 | /* Unhandled CONTEXT!? */ | |
5022 | abort (); | |
5023 | } | |
5024 | return NULL_TREE; | |
5025 | } | |
5026 | ||
582db8e4 MM |
5027 | /* CALL is a CALL_EXPR. Return the declaration for the function |
5028 | called, or NULL_TREE if the called function cannot be | |
5029 | determined. */ | |
5030 | ||
5031 | tree | |
5032 | get_callee_fndecl (call) | |
5033 | tree call; | |
5034 | { | |
5035 | tree addr; | |
5036 | ||
5037 | /* It's invalid to call this function with anything but a | |
5038 | CALL_EXPR. */ | |
5039 | if (TREE_CODE (call) != CALL_EXPR) | |
5040 | abort (); | |
5041 | ||
5042 | /* The first operand to the CALL is the address of the function | |
5043 | called. */ | |
5044 | addr = TREE_OPERAND (call, 0); | |
5045 | ||
5046 | /* If the address is just `&f' for some function `f', then we know | |
5047 | that `f' is being called. */ | |
5048 | if (TREE_CODE (addr) == ADDR_EXPR | |
5049 | && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL) | |
5050 | return TREE_OPERAND (addr, 0); | |
5051 | ||
5052 | /* We couldn't figure out what was being called. */ | |
5053 | return NULL_TREE; | |
5054 | } | |
5055 | ||
d1485032 JM |
5056 | /* Print debugging information about the obstack O, named STR. */ |
5057 | ||
c6a1db6c RS |
5058 | void |
5059 | print_obstack_statistics (str, o) | |
37b37199 | 5060 | const char *str; |
c6a1db6c RS |
5061 | struct obstack *o; |
5062 | { | |
5063 | struct _obstack_chunk *chunk = o->chunk; | |
d1485032 | 5064 | int n_chunks = 1; |
e9a25f70 | 5065 | int n_alloc = 0; |
c6a1db6c | 5066 | |
d1485032 JM |
5067 | n_alloc += o->next_free - chunk->contents; |
5068 | chunk = chunk->prev; | |
c6a1db6c RS |
5069 | while (chunk) |
5070 | { | |
5071 | n_chunks += 1; | |
5072 | n_alloc += chunk->limit - &chunk->contents[0]; | |
5073 | chunk = chunk->prev; | |
5074 | } | |
5e9defae | 5075 | fprintf (stderr, "obstack %s: %u bytes, %d chunks\n", |
c6a1db6c RS |
5076 | str, n_alloc, n_chunks); |
5077 | } | |
d1485032 JM |
5078 | |
5079 | /* Print debugging information about tree nodes generated during the compile, | |
5080 | and any language-specific information. */ | |
5081 | ||
c6a1db6c RS |
5082 | void |
5083 | dump_tree_statistics () | |
5084 | { | |
5e9defae | 5085 | #ifdef GATHER_STATISTICS |
c6a1db6c RS |
5086 | int i; |
5087 | int total_nodes, total_bytes; | |
5e9defae | 5088 | #endif |
c6a1db6c RS |
5089 | |
5090 | fprintf (stderr, "\n??? tree nodes created\n\n"); | |
5091 | #ifdef GATHER_STATISTICS | |
5092 | fprintf (stderr, "Kind Nodes Bytes\n"); | |
5093 | fprintf (stderr, "-------------------------------------\n"); | |
5094 | total_nodes = total_bytes = 0; | |
5095 | for (i = 0; i < (int) all_kinds; i++) | |
5096 | { | |
5097 | fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i], | |
5098 | tree_node_counts[i], tree_node_sizes[i]); | |
5099 | total_nodes += tree_node_counts[i]; | |
5100 | total_bytes += tree_node_sizes[i]; | |
5101 | } | |
5102 | fprintf (stderr, "%-20s %9d\n", "identifier names", id_string_size); | |
5103 | fprintf (stderr, "-------------------------------------\n"); | |
5104 | fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes); | |
5105 | fprintf (stderr, "-------------------------------------\n"); | |
5106 | #else | |
5107 | fprintf (stderr, "(No per-node statistics)\n"); | |
5108 | #endif | |
d1485032 JM |
5109 | print_obstack_statistics ("permanent_obstack", &permanent_obstack); |
5110 | print_obstack_statistics ("maybepermanent_obstack", &maybepermanent_obstack); | |
5111 | print_obstack_statistics ("temporary_obstack", &temporary_obstack); | |
5112 | print_obstack_statistics ("momentary_obstack", &momentary_obstack); | |
5113 | print_obstack_statistics ("temp_decl_obstack", &temp_decl_obstack); | |
c6a1db6c RS |
5114 | print_lang_statistics (); |
5115 | } | |
bb288278 PB |
5116 | \f |
5117 | #define FILE_FUNCTION_PREFIX_LEN 9 | |
5118 | ||
5119 | #ifndef NO_DOLLAR_IN_LABEL | |
2ce3c6c6 | 5120 | #define FILE_FUNCTION_FORMAT "_GLOBAL_$%s$%s" |
bb288278 PB |
5121 | #else /* NO_DOLLAR_IN_LABEL */ |
5122 | #ifndef NO_DOT_IN_LABEL | |
2ce3c6c6 | 5123 | #define FILE_FUNCTION_FORMAT "_GLOBAL_.%s.%s" |
bb288278 | 5124 | #else /* NO_DOT_IN_LABEL */ |
2ce3c6c6 | 5125 | #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s" |
bb288278 PB |
5126 | #endif /* NO_DOT_IN_LABEL */ |
5127 | #endif /* NO_DOLLAR_IN_LABEL */ | |
5128 | ||
d4b60170 RK |
5129 | extern char *first_global_object_name; |
5130 | extern char *weak_global_object_name; | |
bb288278 | 5131 | |
e2c31432 JM |
5132 | /* Appends 6 random characters to TEMPLATE to (hopefully) avoid name |
5133 | clashes in cases where we can't reliably choose a unique name. | |
5134 | ||
5135 | Derived from mkstemp.c in libiberty. */ | |
5136 | ||
5137 | static void | |
5138 | append_random_chars (template) | |
5139 | char *template; | |
5140 | { | |
5141 | static const char letters[] | |
5142 | = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | |
5143 | static unsigned HOST_WIDE_INT value; | |
5144 | unsigned HOST_WIDE_INT v; | |
5145 | ||
5146 | #ifdef HAVE_GETTIMEOFDAY | |
5147 | struct timeval tv; | |
5148 | #endif | |
5149 | ||
5150 | template += strlen (template); | |
5151 | ||
5152 | #ifdef HAVE_GETTIMEOFDAY | |
5153 | /* Get some more or less random data. */ | |
5154 | gettimeofday (&tv, NULL); | |
5155 | value += ((unsigned HOST_WIDE_INT) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); | |
5156 | #else | |
5157 | value += getpid (); | |
5158 | #endif | |
5159 | ||
5160 | v = value; | |
5161 | ||
5162 | /* Fill in the random bits. */ | |
5163 | template[0] = letters[v % 62]; | |
5164 | v /= 62; | |
5165 | template[1] = letters[v % 62]; | |
5166 | v /= 62; | |
5167 | template[2] = letters[v % 62]; | |
5168 | v /= 62; | |
5169 | template[3] = letters[v % 62]; | |
5170 | v /= 62; | |
5171 | template[4] = letters[v % 62]; | |
5172 | v /= 62; | |
5173 | template[5] = letters[v % 62]; | |
5174 | ||
5175 | template[6] = '\0'; | |
5176 | } | |
5177 | ||
5178 | /* Generate a name for a function unique to this translation unit. | |
5179 | TYPE is some string to identify the purpose of this function to the | |
5180 | linker or collect2. */ | |
bb288278 PB |
5181 | |
5182 | tree | |
2ce3c6c6 | 5183 | get_file_function_name_long (type) |
37b37199 | 5184 | const char *type; |
bb288278 PB |
5185 | { |
5186 | char *buf; | |
5187 | register char *p; | |
5188 | ||
5189 | if (first_global_object_name) | |
5190 | p = first_global_object_name; | |
bb288278 | 5191 | else |
e2c31432 JM |
5192 | { |
5193 | /* We don't have anything that we know to be unique to this translation | |
5194 | unit, so use what we do have and throw in some randomness. */ | |
5195 | ||
37b37199 KG |
5196 | const char *name = weak_global_object_name; |
5197 | const char *file = main_input_filename; | |
e2c31432 JM |
5198 | |
5199 | if (! name) | |
5200 | name = ""; | |
5201 | if (! file) | |
5202 | file = input_filename; | |
5203 | ||
5204 | p = (char *) alloca (7 + strlen (name) + strlen (file)); | |
5205 | ||
5206 | sprintf (p, "%s%s", name, file); | |
5207 | append_random_chars (p); | |
5208 | } | |
bb288278 | 5209 | |
2ce3c6c6 JM |
5210 | buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p) |
5211 | + strlen (type)); | |
bb288278 | 5212 | |
d4b60170 RK |
5213 | /* Set up the name of the file-level functions we may need. |
5214 | Use a global object (which is already required to be unique over | |
bb288278 | 5215 | the program) rather than the file name (which imposes extra |
d4b60170 | 5216 | constraints). */ |
2ce3c6c6 | 5217 | sprintf (buf, FILE_FUNCTION_FORMAT, type, p); |
bb288278 | 5218 | |
9faa82d8 | 5219 | /* Don't need to pull weird characters out of global names. */ |
bb288278 PB |
5220 | if (p != first_global_object_name) |
5221 | { | |
5222 | for (p = buf+11; *p; p++) | |
f3ad1f9c | 5223 | if (! ( ISDIGIT(*p) |
bb288278 PB |
5224 | #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */ |
5225 | #ifndef ASM_IDENTIFY_GCC /* this is required if `.' is invalid -- k. raeburn */ | |
5226 | || *p == '.' | |
5227 | #endif | |
5228 | #endif | |
5229 | #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */ | |
5230 | || *p == '$' | |
5231 | #endif | |
0f41302f | 5232 | #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */ |
bb288278 PB |
5233 | || *p == '.' |
5234 | #endif | |
f3ad1f9c LV |
5235 | || ISUPPER(*p) |
5236 | || ISLOWER(*p))) | |
bb288278 PB |
5237 | *p = '_'; |
5238 | } | |
5239 | ||
bb288278 PB |
5240 | return get_identifier (buf); |
5241 | } | |
2ce3c6c6 JM |
5242 | |
5243 | /* If KIND=='I', return a suitable global initializer (constructor) name. | |
5244 | If KIND=='D', return a suitable global clean-up (destructor) name. */ | |
5245 | ||
5246 | tree | |
5247 | get_file_function_name (kind) | |
5248 | int kind; | |
5249 | { | |
5250 | char p[2]; | |
d4b60170 | 5251 | |
2ce3c6c6 JM |
5252 | p[0] = kind; |
5253 | p[1] = 0; | |
5254 | ||
5255 | return get_file_function_name_long (p); | |
5256 | } | |
bca949e2 | 5257 | \f |
9faa82d8 | 5258 | /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node. |
bca949e2 PB |
5259 | The result is placed in BUFFER (which has length BIT_SIZE), |
5260 | with one bit in each char ('\000' or '\001'). | |
5261 | ||
5262 | If the constructor is constant, NULL_TREE is returned. | |
0f41302f | 5263 | Otherwise, a TREE_LIST of the non-constant elements is emitted. */ |
bca949e2 PB |
5264 | |
5265 | tree | |
5266 | get_set_constructor_bits (init, buffer, bit_size) | |
5267 | tree init; | |
5268 | char *buffer; | |
5269 | int bit_size; | |
5270 | { | |
5271 | int i; | |
5272 | tree vals; | |
5273 | HOST_WIDE_INT domain_min | |
5274 | = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init)))); | |
5275 | tree non_const_bits = NULL_TREE; | |
5276 | for (i = 0; i < bit_size; i++) | |
5277 | buffer[i] = 0; | |
5278 | ||
5279 | for (vals = TREE_OPERAND (init, 1); | |
5280 | vals != NULL_TREE; vals = TREE_CHAIN (vals)) | |
5281 | { | |
5282 | if (TREE_CODE (TREE_VALUE (vals)) != INTEGER_CST | |
5283 | || (TREE_PURPOSE (vals) != NULL_TREE | |
5284 | && TREE_CODE (TREE_PURPOSE (vals)) != INTEGER_CST)) | |
db3cf6fb MS |
5285 | non_const_bits |
5286 | = tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits); | |
bca949e2 PB |
5287 | else if (TREE_PURPOSE (vals) != NULL_TREE) |
5288 | { | |
0f41302f | 5289 | /* Set a range of bits to ones. */ |
bca949e2 PB |
5290 | HOST_WIDE_INT lo_index |
5291 | = TREE_INT_CST_LOW (TREE_PURPOSE (vals)) - domain_min; | |
5292 | HOST_WIDE_INT hi_index | |
5293 | = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min; | |
05bccae2 | 5294 | |
bca949e2 PB |
5295 | if (lo_index < 0 || lo_index >= bit_size |
5296 | || hi_index < 0 || hi_index >= bit_size) | |
5297 | abort (); | |
5298 | for ( ; lo_index <= hi_index; lo_index++) | |
5299 | buffer[lo_index] = 1; | |
5300 | } | |
5301 | else | |
5302 | { | |
0f41302f | 5303 | /* Set a single bit to one. */ |
bca949e2 PB |
5304 | HOST_WIDE_INT index |
5305 | = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min; | |
5306 | if (index < 0 || index >= bit_size) | |
5307 | { | |
5308 | error ("invalid initializer for bit string"); | |
5309 | return NULL_TREE; | |
5310 | } | |
5311 | buffer[index] = 1; | |
5312 | } | |
5313 | } | |
5314 | return non_const_bits; | |
5315 | } | |
5316 | ||
9faa82d8 | 5317 | /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node. |
f3ffec8e | 5318 | The result is placed in BUFFER (which is an array of bytes). |
bca949e2 | 5319 | If the constructor is constant, NULL_TREE is returned. |
0f41302f | 5320 | Otherwise, a TREE_LIST of the non-constant elements is emitted. */ |
bca949e2 PB |
5321 | |
5322 | tree | |
f3ffec8e | 5323 | get_set_constructor_bytes (init, buffer, wd_size) |
bca949e2 | 5324 | tree init; |
f3ffec8e | 5325 | unsigned char *buffer; |
bca949e2 PB |
5326 | int wd_size; |
5327 | { | |
5328 | int i; | |
f3ffec8e | 5329 | int set_word_size = BITS_PER_UNIT; |
bca949e2 PB |
5330 | int bit_size = wd_size * set_word_size; |
5331 | int bit_pos = 0; | |
f3ffec8e | 5332 | unsigned char *bytep = buffer; |
0f41302f | 5333 | char *bit_buffer = (char *) alloca(bit_size); |
bca949e2 PB |
5334 | tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size); |
5335 | ||
5336 | for (i = 0; i < wd_size; i++) | |
5337 | buffer[i] = 0; | |
5338 | ||
5339 | for (i = 0; i < bit_size; i++) | |
5340 | { | |
5341 | if (bit_buffer[i]) | |
5342 | { | |
8a0e8d4d | 5343 | if (BYTES_BIG_ENDIAN) |
f3ffec8e | 5344 | *bytep |= (1 << (set_word_size - 1 - bit_pos)); |
f76b9db2 | 5345 | else |
f3ffec8e | 5346 | *bytep |= 1 << bit_pos; |
bca949e2 PB |
5347 | } |
5348 | bit_pos++; | |
5349 | if (bit_pos >= set_word_size) | |
f3ffec8e | 5350 | bit_pos = 0, bytep++; |
bca949e2 PB |
5351 | } |
5352 | return non_const_bits; | |
5353 | } | |
9ec36da5 | 5354 | \f |
f4524c9e | 5355 | #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007) |
8f985ec4 | 5356 | /* Complain that the tree code of NODE does not match the expected CODE. |
987009bf | 5357 | FILE, LINE, and FUNCTION are of the caller. */ |
8f985ec4 ZW |
5358 | void |
5359 | tree_check_failed (node, code, file, line, function) | |
5360 | const tree node; | |
12b195d9 | 5361 | enum tree_code code; |
37b37199 | 5362 | const char *file; |
12b195d9 | 5363 | int line; |
8f985ec4 | 5364 | const char *function; |
12b195d9 | 5365 | { |
987009bf | 5366 | error ("Tree check: expected %s, have %s", |
8f985ec4 | 5367 | tree_code_name[code], tree_code_name[TREE_CODE (node)]); |
987009bf | 5368 | fancy_abort (file, line, function); |
12b195d9 ML |
5369 | } |
5370 | ||
9ec36da5 JL |
5371 | /* Similar to above, except that we check for a class of tree |
5372 | code, given in CL. */ | |
8f985ec4 ZW |
5373 | void |
5374 | tree_class_check_failed (node, cl, file, line, function) | |
5375 | const tree node; | |
12b195d9 | 5376 | char cl; |
37b37199 | 5377 | const char *file; |
12b195d9 | 5378 | int line; |
8f985ec4 | 5379 | const char *function; |
12b195d9 | 5380 | { |
987009bf ZW |
5381 | error ("Tree check: expected class '%c', have '%c' (%s)", |
5382 | cl, TREE_CODE_CLASS (TREE_CODE (node)), | |
8f985ec4 | 5383 | tree_code_name[TREE_CODE (node)]); |
987009bf | 5384 | fancy_abort (file, line, function); |
8f985ec4 ZW |
5385 | } |
5386 | ||
f4524c9e | 5387 | #endif /* ENABLE_TREE_CHECKING */ |
41472af8 MM |
5388 | |
5389 | /* Return the alias set for T, which may be either a type or an | |
5390 | expression. */ | |
5391 | ||
2ba57343 RH |
5392 | int |
5393 | get_alias_set (t) | |
41472af8 MM |
5394 | tree t; |
5395 | { | |
d4b60170 | 5396 | if (! flag_strict_aliasing || lang_get_alias_set == 0) |
41472af8 MM |
5397 | /* If we're not doing any lanaguage-specific alias analysis, just |
5398 | assume everything aliases everything else. */ | |
5399 | return 0; | |
5400 | else | |
5401 | return (*lang_get_alias_set) (t); | |
5402 | } | |
2ba57343 RH |
5403 | |
5404 | /* Return a brand-new alias set. */ | |
5405 | ||
5406 | int | |
5407 | new_alias_set () | |
5408 | { | |
5409 | static int last_alias_set; | |
d4b60170 | 5410 | |
a17fcad7 RH |
5411 | if (flag_strict_aliasing) |
5412 | return ++last_alias_set; | |
5413 | else | |
5414 | return 0; | |
2ba57343 | 5415 | } |
81b3411c BS |
5416 | \f |
5417 | #ifndef CHAR_TYPE_SIZE | |
5418 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
5419 | #endif | |
5420 | ||
5421 | #ifndef SHORT_TYPE_SIZE | |
5422 | #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) | |
5423 | #endif | |
5424 | ||
5425 | #ifndef INT_TYPE_SIZE | |
5426 | #define INT_TYPE_SIZE BITS_PER_WORD | |
5427 | #endif | |
5428 | ||
5429 | #ifndef LONG_TYPE_SIZE | |
5430 | #define LONG_TYPE_SIZE BITS_PER_WORD | |
5431 | #endif | |
5432 | ||
5433 | #ifndef LONG_LONG_TYPE_SIZE | |
5434 | #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) | |
5435 | #endif | |
5436 | ||
5437 | #ifndef FLOAT_TYPE_SIZE | |
5438 | #define FLOAT_TYPE_SIZE BITS_PER_WORD | |
5439 | #endif | |
5440 | ||
5441 | #ifndef DOUBLE_TYPE_SIZE | |
5442 | #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
5443 | #endif | |
5444 | ||
5445 | #ifndef LONG_DOUBLE_TYPE_SIZE | |
5446 | #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
5447 | #endif | |
5448 | ||
5449 | /* Create nodes for all integer types (and error_mark_node) using the sizes | |
5450 | of C datatypes. The caller should call set_sizetype soon after calling | |
5451 | this function to select one of the types as sizetype. */ | |
5452 | ||
5453 | void | |
5454 | build_common_tree_nodes (signed_char) | |
5455 | int signed_char; | |
5456 | { | |
5457 | error_mark_node = make_node (ERROR_MARK); | |
5458 | TREE_TYPE (error_mark_node) = error_mark_node; | |
5459 | ||
fed3cef0 RK |
5460 | initialize_sizetypes (); |
5461 | ||
81b3411c BS |
5462 | /* Define both `signed char' and `unsigned char'. */ |
5463 | signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); | |
5464 | unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); | |
5465 | ||
5466 | /* Define `char', which is like either `signed char' or `unsigned char' | |
5467 | but not the same as either. */ | |
5468 | char_type_node | |
5469 | = (signed_char | |
5470 | ? make_signed_type (CHAR_TYPE_SIZE) | |
5471 | : make_unsigned_type (CHAR_TYPE_SIZE)); | |
5472 | ||
5473 | short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); | |
5474 | short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); | |
5475 | integer_type_node = make_signed_type (INT_TYPE_SIZE); | |
81b3411c BS |
5476 | unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); |
5477 | long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); | |
5478 | long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); | |
5479 | long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); | |
5480 | long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); | |
5481 | ||
5482 | intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode)); | |
5483 | intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode)); | |
5484 | intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode)); | |
5485 | intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); | |
5486 | intTI_type_node = make_signed_type (GET_MODE_BITSIZE (TImode)); | |
5487 | ||
5488 | unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); | |
5489 | unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); | |
5490 | unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode)); | |
5491 | unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); | |
5492 | unsigned_intTI_type_node = make_unsigned_type (GET_MODE_BITSIZE (TImode)); | |
5493 | } | |
5494 | ||
81b3411c | 5495 | /* Call this function after calling build_common_tree_nodes and set_sizetype. |
fed3cef0 | 5496 | It will create several other common tree nodes. */ |
d4b60170 | 5497 | |
81b3411c BS |
5498 | void |
5499 | build_common_tree_nodes_2 (short_double) | |
5500 | int short_double; | |
5501 | { | |
05bccae2 | 5502 | /* Define these next since types below may used them. */ |
81b3411c BS |
5503 | integer_zero_node = build_int_2 (0, 0); |
5504 | TREE_TYPE (integer_zero_node) = integer_type_node; | |
5505 | integer_one_node = build_int_2 (1, 0); | |
5506 | TREE_TYPE (integer_one_node) = integer_type_node; | |
5507 | ||
5508 | size_zero_node = build_int_2 (0, 0); | |
5509 | TREE_TYPE (size_zero_node) = sizetype; | |
5510 | size_one_node = build_int_2 (1, 0); | |
5511 | TREE_TYPE (size_one_node) = sizetype; | |
5512 | ||
5513 | void_type_node = make_node (VOID_TYPE); | |
05bccae2 | 5514 | layout_type (void_type_node); |
d4b60170 | 5515 | |
81b3411c BS |
5516 | /* We are not going to have real types in C with less than byte alignment, |
5517 | so we might as well not have any types that claim to have it. */ | |
5518 | TYPE_ALIGN (void_type_node) = BITS_PER_UNIT; | |
5519 | ||
5520 | null_pointer_node = build_int_2 (0, 0); | |
5521 | TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); | |
5522 | layout_type (TREE_TYPE (null_pointer_node)); | |
5523 | ||
5524 | ptr_type_node = build_pointer_type (void_type_node); | |
5525 | const_ptr_type_node | |
5526 | = build_pointer_type (build_type_variant (void_type_node, 1, 0)); | |
5527 | ||
5528 | float_type_node = make_node (REAL_TYPE); | |
5529 | TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; | |
5530 | layout_type (float_type_node); | |
5531 | ||
5532 | double_type_node = make_node (REAL_TYPE); | |
5533 | if (short_double) | |
5534 | TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; | |
5535 | else | |
5536 | TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; | |
5537 | layout_type (double_type_node); | |
5538 | ||
5539 | long_double_type_node = make_node (REAL_TYPE); | |
5540 | TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; | |
5541 | layout_type (long_double_type_node); | |
5542 | ||
5543 | complex_integer_type_node = make_node (COMPLEX_TYPE); | |
5544 | TREE_TYPE (complex_integer_type_node) = integer_type_node; | |
5545 | layout_type (complex_integer_type_node); | |
5546 | ||
5547 | complex_float_type_node = make_node (COMPLEX_TYPE); | |
5548 | TREE_TYPE (complex_float_type_node) = float_type_node; | |
5549 | layout_type (complex_float_type_node); | |
5550 | ||
5551 | complex_double_type_node = make_node (COMPLEX_TYPE); | |
5552 | TREE_TYPE (complex_double_type_node) = double_type_node; | |
5553 | layout_type (complex_double_type_node); | |
5554 | ||
5555 | complex_long_double_type_node = make_node (COMPLEX_TYPE); | |
5556 | TREE_TYPE (complex_long_double_type_node) = long_double_type_node; | |
5557 | layout_type (complex_long_double_type_node); | |
5558 | ||
5559 | #ifdef BUILD_VA_LIST_TYPE | |
5560 | BUILD_VA_LIST_TYPE(va_list_type_node); | |
5561 | #else | |
5562 | va_list_type_node = ptr_type_node; | |
5563 | #endif | |
5564 | } |