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