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.
5 This file is part of GNU CC.
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)
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.
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. */
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
29 It is intended to be language-independent, but occasionally
30 calls language-dependent routines defined (for C) in typecheck.c.
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. */
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));
54 static void unsave_expr_now_r PARAMS ((tree));
56 /* Objects allocated on this obstack last forever. */
58 struct obstack permanent_obstack;
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. */
64 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
66 char tree_code_type[MAX_TREE_CODES] = {
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. */
75 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
77 int tree_code_length[MAX_TREE_CODES] = {
82 /* Names of tree components.
83 Used for printing out the tree and error messages. */
84 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
86 const char *tree_code_name[MAX_TREE_CODES] = {
91 /* Statistics-gathering stuff. */
112 int tree_node_counts[(int) all_kinds];
113 int tree_node_sizes[(int) all_kinds];
114 int id_string_size = 0;
116 static const char * const tree_node_kind_names[] = {
134 /* Hash table for uniquizing IDENTIFIER_NODEs by name. */
136 #define MAX_HASH_TABLE 1009
137 static tree hash_table[MAX_HASH_TABLE]; /* id hash buckets */
139 /* 0 while creating built-in identifiers. */
140 static int do_identifier_warnings;
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;
147 /* Here is how primitive or already-canonicalized types' hash
149 #define TYPE_HASH(TYPE) ((unsigned long) (TYPE) & 0777777)
151 /* Since we cannot rehash a type after it is in the table, we have to
152 keep the hash code. */
160 /* Initial size of the hash table (rounded to next prime). */
161 #define TYPE_HASH_INITIAL_SIZE 1000
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. */
170 htab_t type_hash_table;
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));
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));
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. */
194 static char *built_in_filename;
195 #define BUILT_IN_FILENAME ("<built-in>")
197 tree global_trees[TI_MAX];
198 tree integer_types[itk_none];
200 /* Init the principal obstacks. */
205 gcc_obstack_init (&permanent_obstack);
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));
211 /* Initialize the hash table of types. */
212 type_hash_table = htab_create (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
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);
220 gcc_obstack_init (obstack)
221 struct obstack *obstack;
223 /* Let particular systems override the size of a chunk. */
224 #ifndef OBSTACK_CHUNK_SIZE
225 #define OBSTACK_CHUNK_SIZE 0
227 /* Let them override the alloc and free routines too. */
228 #ifndef OBSTACK_CHUNK_ALLOC
229 #define OBSTACK_CHUNK_ALLOC xmalloc
231 #ifndef OBSTACK_CHUNK_FREE
232 #define OBSTACK_CHUNK_FREE free
234 _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
235 (void *(*) PARAMS ((long))) OBSTACK_CHUNK_ALLOC,
236 (void (*) PARAMS ((void *))) OBSTACK_CHUNK_FREE);
240 /* Allocate SIZE bytes in the permanent obstack
241 and return a pointer to them. */
247 return (char *) obstack_alloc (&permanent_obstack, size);
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. */
255 perm_calloc (nelem, size)
259 char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);
260 memset (rval, 0, nelem * size);
265 /* Init the tables indexed by tree code.
266 Note that languages can add to these tables to define their own codes. */
272 = ggc_alloc_string (BUILT_IN_FILENAME, sizeof (BUILT_IN_FILENAME));
273 ggc_add_string_root (&built_in_filename, 1);
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. */
282 enum tree_code code = TREE_CODE (node);
284 switch (TREE_CODE_CLASS (code))
286 case 'd': /* A decl node */
287 return sizeof (struct tree_decl);
289 case 't': /* a type node */
290 return sizeof (struct tree_type);
292 case 'b': /* a lexical block node */
293 return sizeof (struct tree_block);
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 *));
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);
315 return (sizeof (struct tree_common)
316 + TREE_CODE_LENGTH (code) * sizeof (char *));
318 case 'x': /* something random, like an identifier. */
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 *);
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.
337 Achoo! I got a code in the node. */
344 register int type = TREE_CODE_CLASS (code);
345 register size_t length;
346 #ifdef GATHER_STATISTICS
347 register tree_node_kind kind;
349 struct tree_common ttmp;
351 /* We can't allocate a TREE_VEC without knowing how many elements
353 if (code == TREE_VEC)
356 TREE_SET_CODE ((tree)&ttmp, code);
357 length = tree_size ((tree)&ttmp);
359 #ifdef GATHER_STATISTICS
362 case 'd': /* A decl node */
366 case 't': /* a type node */
370 case 'b': /* a lexical block */
374 case 's': /* an expression with side effects */
378 case 'r': /* a reference */
382 case 'e': /* an expression */
383 case '<': /* a comparison expression */
384 case '1': /* a unary arithmetic expression */
385 case '2': /* a binary arithmetic expression */
389 case 'c': /* a constant */
393 case 'x': /* something random, like an identifier. */
394 if (code == IDENTIFIER_NODE)
396 else if (code == OP_IDENTIFIER)
398 else if (code == TREE_VEC)
408 tree_node_counts[(int) kind]++;
409 tree_node_sizes[(int) kind] += length;
412 t = ggc_alloc_tree (length);
414 memset ((PTR) t, 0, length);
416 TREE_SET_CODE (t, code);
421 TREE_SIDE_EFFECTS (t) = 1;
422 TREE_TYPE (t) = void_type_node;
426 if (code != FUNCTION_DECL)
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
436 DECL_POINTER_ALIAS_SET (t) = -1;
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);
448 /* Note that we have not yet computed the alias set for this
450 TYPE_ALIAS_SET (t) = -1;
454 TREE_CONSTANT (t) = 1;
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
470 TREE_SIDE_EFFECTS (t) = 1;
482 /* A front-end can reset this to an appropriate function if types need
485 tree (*make_lang_type_fn) PARAMS ((enum tree_code)) = make_node;
487 /* Return a new type (with the indicated CODE), doing whatever
488 language-specific processing is required. */
491 make_lang_type (code)
494 return (*make_lang_type_fn) (code);
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
508 register enum tree_code code = TREE_CODE (node);
509 register size_t length;
511 length = tree_size (node);
512 t = ggc_alloc_tree (length);
513 memcpy (t, node, length);
516 TREE_ASM_WRITTEN (t) = 0;
518 if (TREE_CODE_CLASS (code) == 'd')
519 DECL_UID (t) = next_decl_uid++;
520 else if (TREE_CODE_CLASS (code) == 't')
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;
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. */
543 register tree prev, next;
548 head = prev = copy_node (list);
549 next = TREE_CHAIN (list);
552 TREE_CHAIN (prev) = copy_node (next);
553 prev = TREE_CHAIN (prev);
554 next = TREE_CHAIN (next);
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. */
566 get_identifier (text)
567 register const char *text;
572 register int len, hash_len;
574 /* Compute length of text in len. */
577 /* Decide how much of that length to hash on */
579 if (warn_id_clash && len > id_clash_len)
580 hash_len = id_clash_len;
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]));
587 hi &= (1 << HASHBITS) - 1;
588 hi %= MAX_HASH_TABLE;
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. */
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))
603 warning ("`%s' and `%s' identical in first %d characters",
604 IDENTIFIER_POINTER (idp), text, id_clash_len);
608 if (TREE_CODE_LENGTH (IDENTIFIER_NODE) < 0)
609 abort (); /* set_identifier_size hasn't been called. */
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;
618 IDENTIFIER_POINTER (idp) = ggc_alloc_string (text, len);
620 TREE_CHAIN (idp) = hash_table[hi];
621 hash_table[hi] = idp;
622 return idp; /* <-- return if created */
625 /* If an identifier with the name TEXT (a null-terminated string) has
626 previously been referred to, return that node; otherwise return
630 maybe_get_identifier (text)
631 register const char *text;
636 register int len, hash_len;
638 /* Compute length of text in len. */
641 /* Decide how much of that length to hash on */
643 if (warn_id_clash && len > id_clash_len)
644 hash_len = id_clash_len;
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]));
651 hi &= (1 << HASHBITS) - 1;
652 hi %= MAX_HASH_TABLE;
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 */
664 /* Enable warnings on similar identifiers (if requested).
665 Done after the built-in identifiers are created. */
668 start_identifier_warnings ()
670 do_identifier_warnings = 1;
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. */
679 set_identifier_size (size)
682 tree_code_length[(int) IDENTIFIER_NODE]
683 = (size - sizeof (struct tree_common)) / sizeof (tree);
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'.
690 This function should be used via the `build_int_2' macro. */
693 build_int_2_wide (low, hi)
694 unsigned HOST_WIDE_INT low;
697 register tree t = make_node (INTEGER_CST);
699 TREE_INT_CST_LOW (t) = low;
700 TREE_INT_CST_HIGH (t) = hi;
701 TREE_TYPE (t) = integer_type_node;
705 /* Return a new REAL_CST node whose type is TYPE and value is D. */
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);
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;
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. */
731 #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
734 real_value_from_int_cst (type, i)
735 tree type ATTRIBUTE_UNUSED, i;
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);
744 if (! TREE_UNSIGNED (TREE_TYPE (i)))
745 REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
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)))
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)));
761 e = (double) (~TREE_INT_CST_LOW (i));
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)));
773 e = (double) TREE_INT_CST_LOW (i);
776 #endif /* not REAL_ARITHMETIC */
780 /* Args to pass to and from build_real_from_int_cst_1. */
784 tree type; /* Input: type to conver to. */
785 tree i; /* Input: operand to convert. */
786 REAL_VALUE_TYPE d; /* Output: floating point value. */
789 /* Convert an integer to a floating point value while protected by a floating
790 point exception handler. */
793 build_real_from_int_cst_1 (data)
796 struct brfic_args *args = (struct brfic_args *) data;
798 #ifdef REAL_ARITHMETIC
799 args->d = real_value_from_int_cst (args->type, args->i);
802 = REAL_VALUE_TRUNCATE (TYPE_MODE (args->type),
803 real_value_from_int_cst (args->type, args->i));
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. */
813 build_real_from_int_cst (type, i)
818 int overflow = TREE_OVERFLOW (i);
820 struct brfic_args args;
822 v = make_node (REAL_CST);
823 TREE_TYPE (v) = type;
825 /* Setup input for build_real_from_int_cst_1() */
829 if (do_float_handler (build_real_from_int_cst_1, (PTR) &args))
830 /* Receive output from build_real_from_int_cst_1() */
834 /* We got an exception from build_real_from_int_cst_1() */
839 /* Check for valid float value for this type on this target machine. */
841 #ifdef CHECK_FLOAT_VALUE
842 CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow);
845 TREE_REAL_CST (v) = d;
846 TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
850 #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
852 /* Return a newly constructed STRING_CST node whose value is
853 the LEN characters at STR.
854 The TREE_TYPE is not initialized. */
857 build_string (len, str)
861 register tree s = make_node (STRING_CST);
863 TREE_STRING_LENGTH (s) = len;
864 TREE_STRING_POINTER (s) = ggc_alloc_string (str, len);
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. */
875 build_complex (type, real, imag)
879 register tree t = make_node (COMPLEX_CST);
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);
890 /* Build a newly constructed TREE_VEC node of length LEN. */
897 register int length = (len-1) * sizeof (tree) + sizeof (struct tree_vec);
899 #ifdef GATHER_STATISTICS
900 tree_node_counts[(int)vec_kind]++;
901 tree_node_sizes[(int)vec_kind] += length;
904 t = ggc_alloc_tree (length);
906 memset ((PTR) t, 0, length);
907 TREE_SET_CODE (t, TREE_VEC);
908 TREE_VEC_LENGTH (t) = len;
913 /* Return 1 if EXPR is the integer constant zero or a complex constant
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))));
931 /* Return 1 if EXPR is the integer constant one or the corresponding
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))));
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. */
953 integer_all_onesp (expr)
961 if (TREE_CODE (expr) == COMPLEX_CST
962 && integer_all_onesp (TREE_REALPART (expr))
963 && integer_zerop (TREE_IMAGPART (expr)))
966 else if (TREE_CODE (expr) != INTEGER_CST
967 || TREE_CONSTANT_OVERFLOW (expr))
970 uns = TREE_UNSIGNED (TREE_TYPE (expr));
972 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
973 && TREE_INT_CST_HIGH (expr) == -1);
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)
980 HOST_WIDE_INT high_value;
983 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
985 if (shift_amount > HOST_BITS_PER_WIDE_INT)
986 /* Can not handle precisions greater than twice the host int size. */
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. */
993 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
995 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
996 && TREE_INT_CST_HIGH (expr) == high_value);
999 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
1002 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1006 integer_pow2p (expr)
1010 HOST_WIDE_INT high, low;
1014 if (TREE_CODE (expr) == COMPLEX_CST
1015 && integer_pow2p (TREE_REALPART (expr))
1016 && integer_zerop (TREE_IMAGPART (expr)))
1019 if (TREE_CODE (expr) != INTEGER_CST || TREE_CONSTANT_OVERFLOW (expr))
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);
1027 /* First clear all bits that are beyond the type's precision in case
1028 we've been sign extended. */
1030 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1032 else if (prec > HOST_BITS_PER_WIDE_INT)
1033 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1037 if (prec < HOST_BITS_PER_WIDE_INT)
1038 low &= ~((HOST_WIDE_INT) (-1) << prec);
1041 if (high == 0 && low == 0)
1044 return ((high == 0 && (low & (low - 1)) == 0)
1045 || (low == 0 && (high & (high - 1)) == 0));
1048 /* Return the power of two represented by a tree node known to be a
1056 HOST_WIDE_INT high, low;
1060 if (TREE_CODE (expr) == COMPLEX_CST)
1061 return tree_log2 (TREE_REALPART (expr));
1063 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1064 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1066 high = TREE_INT_CST_HIGH (expr);
1067 low = TREE_INT_CST_LOW (expr);
1069 /* First clear all bits that are beyond the type's precision in case
1070 we've been sign extended. */
1072 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1074 else if (prec > HOST_BITS_PER_WIDE_INT)
1075 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1079 if (prec < HOST_BITS_PER_WIDE_INT)
1080 low &= ~((HOST_WIDE_INT) (-1) << prec);
1083 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
1084 : exact_log2 (low));
1087 /* Similar, but return the largest integer Y such that 2 ** Y is less
1088 than or equal to EXPR. */
1091 tree_floor_log2 (expr)
1095 HOST_WIDE_INT high, low;
1099 if (TREE_CODE (expr) == COMPLEX_CST)
1100 return tree_log2 (TREE_REALPART (expr));
1102 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1103 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1105 high = TREE_INT_CST_HIGH (expr);
1106 low = TREE_INT_CST_LOW (expr);
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. */
1112 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
1114 else if (prec > HOST_BITS_PER_WIDE_INT)
1115 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1119 if (prec < HOST_BITS_PER_WIDE_INT)
1120 low &= ~((HOST_WIDE_INT) (-1) << prec);
1123 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
1124 : floor_log2 (low));
1127 /* Return 1 if EXPR is the real constant zero. */
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))));
1143 /* Return 1 if EXPR is the real constant one in real or complex form. */
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))));
1159 /* Return 1 if EXPR is the real constant two. */
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))));
1175 /* Nonzero if EXP is a constant or a cast of a constant. */
1178 really_constant_p (exp)
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);
1189 /* Return first list element whose TREE_VALUE is ELEM.
1190 Return 0 if ELEM is not in LIST. */
1193 value_member (elem, list)
1198 if (elem == TREE_VALUE (list))
1200 list = TREE_CHAIN (list);
1205 /* Return first list element whose TREE_PURPOSE is ELEM.
1206 Return 0 if ELEM is not in LIST. */
1209 purpose_member (elem, list)
1214 if (elem == TREE_PURPOSE (list))
1216 list = TREE_CHAIN (list);
1221 /* Return first list element whose BINFO_TYPE is ELEM.
1222 Return 0 if ELEM is not in LIST. */
1225 binfo_member (elem, list)
1230 if (elem == BINFO_TYPE (list))
1232 list = TREE_CHAIN (list);
1237 /* Return nonzero if ELEM is part of the chain CHAIN. */
1240 chain_member (elem, chain)
1247 chain = TREE_CHAIN (chain);
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. */
1258 chain_member_value (elem, chain)
1263 if (elem == TREE_VALUE (chain))
1265 chain = TREE_CHAIN (chain);
1271 /* Return nonzero if ELEM is equal to TREE_PURPOSE (CHAIN)
1272 for any piece of chain CHAIN. */
1275 chain_member_purpose (elem, chain)
1280 if (elem == TREE_PURPOSE (chain))
1282 chain = TREE_CHAIN (chain);
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'. */
1297 register int len = 0;
1299 for (tail = t; tail; tail = TREE_CHAIN (tail))
1305 /* Returns the number of FIELD_DECLs in TYPE. */
1308 fields_length (type)
1311 tree t = TYPE_FIELDS (type);
1314 for (; t; t = TREE_CHAIN (t))
1315 if (TREE_CODE (t) == FIELD_DECL)
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'. */
1333 #ifdef ENABLE_TREE_CHECKING
1337 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1339 TREE_CHAIN (t1) = op2;
1340 #ifdef ENABLE_TREE_CHECKING
1341 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1343 abort (); /* Circularity created. */
1351 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1355 register tree chain;
1359 while ((next = TREE_CHAIN (chain)))
1364 /* Reverse the order of elements in the chain T,
1365 and return the new head of the chain (old last element). */
1371 register tree prev = 0, decl, next;
1372 for (decl = t; decl; decl = next)
1374 next = TREE_CHAIN (decl);
1375 TREE_CHAIN (decl) = prev;
1381 /* Given a chain CHAIN of tree nodes,
1382 construct and return a list of those nodes. */
1388 tree result = NULL_TREE;
1389 tree in_tail = chain;
1390 tree out_tail = NULL_TREE;
1394 tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE);
1396 TREE_CHAIN (out_tail) = next;
1400 in_tail = TREE_CHAIN (in_tail);
1406 /* Return a newly created TREE_LIST node whose
1407 purpose and value fields are PARM and VALUE. */
1410 build_tree_list (parm, value)
1413 register tree t = make_node (TREE_LIST);
1414 TREE_PURPOSE (t) = parm;
1415 TREE_VALUE (t) = value;
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. */
1424 tree_cons (purpose, value, chain)
1425 tree purpose, value, chain;
1429 node = ggc_alloc_tree (sizeof (struct tree_list));
1431 memset (node, 0, sizeof (struct tree_common));
1433 #ifdef GATHER_STATISTICS
1434 tree_node_counts[(int) x_kind]++;
1435 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
1438 TREE_SET_CODE (node, TREE_LIST);
1439 TREE_CHAIN (node) = chain;
1440 TREE_PURPOSE (node) = purpose;
1441 TREE_VALUE (node) = value;
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). */
1453 size_in_bytes (type)
1458 if (type == error_mark_node)
1459 return integer_zero_node;
1461 type = TYPE_MAIN_VARIANT (type);
1462 t = TYPE_SIZE_UNIT (type);
1466 incomplete_type_error (NULL_TREE, type);
1467 return size_zero_node;
1470 if (TREE_CODE (t) == INTEGER_CST)
1471 force_fit_type (t, 0);
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. */
1480 int_size_in_bytes (type)
1485 if (type == error_mark_node)
1488 type = TYPE_MAIN_VARIANT (type);
1489 t = TYPE_SIZE_UNIT (type);
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)
1498 return TREE_INT_CST_LOW (t);
1501 /* Return the bit position of FIELD, in bits from the start of the record.
1502 This is a tree of type bitsizetype. */
1505 bit_position (field)
1509 return bit_from_pos (DECL_FIELD_OFFSET (field),
1510 DECL_FIELD_BIT_OFFSET (field));
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. */
1518 int_bit_position (field)
1521 return tree_low_cst (bit_position (field), 0);
1524 /* Return the byte position of FIELD, in bytes from the start of the record.
1525 This is a tree of type sizetype. */
1528 byte_position (field)
1531 return byte_from_pos (DECL_FIELD_OFFSET (field),
1532 DECL_FIELD_BIT_OFFSET (field));
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. */
1540 int_byte_position (field)
1543 return tree_low_cst (byte_position (field), 0);
1546 /* Return the strictest alignment, in bits, that T is known to have. */
1552 unsigned int align0, align1;
1554 switch (TREE_CODE (t))
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);
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));
1570 /* The best we can do is say that the alignment is the least aligned
1572 align0 = expr_align (TREE_OPERAND (t, 1));
1573 align1 = expr_align (TREE_OPERAND (t, 2));
1574 return MIN (align0, align1);
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);
1583 return FUNCTION_BOUNDARY;
1589 /* Otherwise take the alignment from that of the type. */
1590 return TYPE_ALIGN (TREE_TYPE (t));
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. */
1597 array_type_nelts (type)
1600 tree index_type, min, max;
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;
1607 index_type = TYPE_DOMAIN (type);
1608 min = TYPE_MIN_VALUE (index_type);
1609 max = TYPE_MAX_VALUE (index_type);
1611 return (integer_zerop (min)
1613 : fold (build (MINUS_EXPR, TREE_TYPE (max), max, min)));
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'. */
1623 switch (TREE_CODE (arg))
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);
1632 return (TREE_STATIC (arg) || DECL_EXTERNAL (arg))
1633 && ! DECL_NON_ADDR_CONST_P (arg);
1636 return TREE_STATIC (arg);
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. */
1645 return (! DECL_BIT_FIELD (TREE_OPERAND (arg, 1))
1646 && staticp (TREE_OPERAND (arg, 0)));
1652 /* This case is technically correct, but results in setting
1653 TREE_CONSTANT on ADDR_EXPRs that cannot be evaluated at
1656 return TREE_CONSTANT (TREE_OPERAND (arg, 0));
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));
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.
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.
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.
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
1695 register tree t = fold (expr);
1697 /* We don't care about whether this can be used as an lvalue in this
1699 while (TREE_CODE (t) == NON_LVALUE_EXPR)
1700 t = TREE_OPERAND (t, 0);
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
1708 if (TREE_CONSTANT (t) || (TREE_READONLY (t) && ! TREE_SIDE_EFFECTS (t))
1709 || TREE_CODE (t) == SAVE_EXPR || TREE_CODE (t) == ERROR_MARK)
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.
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))
1724 t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE);
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;
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. */
1744 /* If this is already protected, no sense in protecting it again. */
1745 if (TREE_CODE (expr) == UNSAVE_EXPR)
1748 t = build1 (UNSAVE_EXPR, TREE_TYPE (expr), expr);
1749 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (expr);
1753 /* Returns the index of the first non-tree operand for CODE, or the number
1754 of operands if all are trees. */
1758 enum tree_code code;
1764 case GOTO_SUBROUTINE_EXPR:
1767 case WITH_CLEANUP_EXPR:
1768 /* Should be defined to be 2. */
1770 case METHOD_CALL_EXPR:
1773 return TREE_CODE_LENGTH (code);
1777 /* Perform any modifications to EXPR required when it is unsaved. Does
1778 not recurse into EXPR's subtrees. */
1781 unsave_expr_1 (expr)
1784 switch (TREE_CODE (expr))
1787 if (! SAVE_EXPR_PERSISTENT_P (expr))
1788 SAVE_EXPR_RTL (expr) = 0;
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
1796 if (TREE_OPERAND (expr, 1))
1799 TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 3);
1800 TREE_OPERAND (expr, 3) = NULL_TREE;
1804 /* I don't yet know how to emit a sequence multiple times. */
1805 if (RTL_EXPR_SEQUENCE (expr) != 0)
1810 if (lang_unsave_expr_now != 0)
1811 (*lang_unsave_expr_now) (expr);
1816 /* Helper function for unsave_expr_now. */
1819 unsave_expr_now_r (expr)
1822 enum tree_code code;
1824 /* There's nothing to do for NULL_TREE. */
1828 unsave_expr_1 (expr);
1830 code = TREE_CODE (expr);
1831 switch (TREE_CODE_CLASS (code))
1833 case 'c': /* a constant */
1834 case 't': /* a type node */
1835 case 'd': /* A decl node */
1836 case 'b': /* A block node */
1839 case 'x': /* miscellaneous: e.g., identifier, TREE_LIST or ERROR_MARK. */
1840 if (code == TREE_LIST)
1842 unsave_expr_now_r (TREE_VALUE (expr));
1843 unsave_expr_now_r (TREE_CHAIN (expr));
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 */
1856 for (i = first_rtl_op (code) - 1; i >= 0; i--)
1857 unsave_expr_now_r (TREE_OPERAND (expr, i));
1866 /* Modify a tree in place so that all the evaluate only once things
1867 are cleared out. Return the EXPR given. */
1870 unsave_expr_now (expr)
1873 if (lang_unsave!= 0)
1874 (*lang_unsave) (&expr);
1876 unsave_expr_now_r (expr);
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.
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.
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.
1894 RTL_EXPRs consume their rtl during evaluation. It is therefore
1895 never possible to unsave them. */
1898 unsafe_for_reeval (expr)
1902 enum tree_code code;
1907 if (expr == NULL_TREE)
1910 code = TREE_CODE (expr);
1911 first_rtl = first_rtl_op (code);
1920 for (exp = expr; exp != 0; exp = TREE_CHAIN (exp))
1922 tmp = unsafe_for_reeval (TREE_VALUE (exp));
1923 unsafeness = MAX (tmp, unsafeness);
1929 tmp = unsafe_for_reeval (TREE_OPERAND (expr, 1));
1930 return MAX (tmp, 1);
1937 /* ??? Add a lang hook if it becomes necessary. */
1941 switch (TREE_CODE_CLASS (code))
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 */
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--)
1958 tmp = unsafe_for_reeval (TREE_OPERAND (expr, i));
1959 unsafeness = MAX (tmp, unsafeness);
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. */
1973 contains_placeholder_p (exp)
1976 register enum tree_code code;
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)
1987 else if (code == PLACEHOLDER_EXPR)
1990 switch (TREE_CODE_CLASS (code))
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));
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))));
2012 /* Ignoring the first operand isn't quite right, but works best. */
2013 return contains_placeholder_p (TREE_OPERAND (exp, 1));
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)));
2025 /* If we already know this doesn't have a placeholder, don't
2027 if (SAVE_EXPR_NOPLACEHOLDER (exp) || SAVE_EXPR_RTL (exp) != 0)
2030 SAVE_EXPR_NOPLACEHOLDER (exp) = 1;
2031 result = contains_placeholder_p (TREE_OPERAND (exp, 0));
2033 SAVE_EXPR_NOPLACEHOLDER (exp) = 0;
2038 return (TREE_OPERAND (exp, 1) != 0
2039 && contains_placeholder_p (TREE_OPERAND (exp, 1)));
2045 switch (TREE_CODE_LENGTH (code))
2048 return contains_placeholder_p (TREE_OPERAND (exp, 0));
2050 return (contains_placeholder_p (TREE_OPERAND (exp, 0))
2051 || contains_placeholder_p (TREE_OPERAND (exp, 1)));
2062 /* Return 1 if EXP contains any expressions that produce cleanups for an
2063 outer scope to deal with. Used by fold. */
2071 if (! TREE_SIDE_EFFECTS (exp))
2074 switch (TREE_CODE (exp))
2077 case GOTO_SUBROUTINE_EXPR:
2078 case WITH_CLEANUP_EXPR:
2081 case CLEANUP_POINT_EXPR:
2085 for (exp = TREE_OPERAND (exp, 1); exp; exp = TREE_CHAIN (exp))
2087 cmp = has_cleanups (TREE_VALUE (exp));
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
2101 if ((int) TREE_CODE (exp) >= (int) LAST_AND_UNUSED_TREE_CODE)
2104 nops = first_rtl_op (TREE_CODE (exp));
2105 for (i = 0; i < nops; i++)
2106 if (TREE_OPERAND (exp, i) != 0)
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')
2112 cmp = has_cleanups (TREE_OPERAND (exp, i));
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. */
2128 substitute_in_expr (exp, f, r)
2133 enum tree_code code = TREE_CODE (exp);
2138 switch (TREE_CODE_CLASS (code))
2145 if (code == PLACEHOLDER_EXPR)
2147 else if (code == TREE_LIST)
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))
2155 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2164 switch (TREE_CODE_LENGTH (code))
2167 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2168 if (op0 == TREE_OPERAND (exp, 0))
2171 if (code == NON_LVALUE_EXPR)
2174 new = fold (build1 (code, TREE_TYPE (exp), op0));
2178 /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR
2179 could, but we don't support it. */
2180 if (code == RTL_EXPR)
2182 else if (code == CONSTRUCTOR)
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))
2190 new = fold (build (code, TREE_TYPE (exp), op0, op1));
2194 /* It cannot be that anything inside a SAVE_EXPR contains a
2195 PLACEHOLDER_EXPR. */
2196 if (code == SAVE_EXPR)
2199 else if (code == CALL_EXPR)
2201 op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
2202 if (op1 == TREE_OPERAND (exp, 1))
2205 return build (code, TREE_TYPE (exp),
2206 TREE_OPERAND (exp, 0), op1, NULL_TREE);
2209 else if (code != COND_EXPR)
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))
2219 new = fold (build (code, TREE_TYPE (exp), op0, op1, op2));
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))
2238 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2239 && TREE_OPERAND (exp, 1) == f)
2242 /* If this expression hasn't been completed let, leave it
2244 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2245 && TREE_TYPE (inner) == 0)
2248 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2249 if (op0 == TREE_OPERAND (exp, 0))
2252 new = fold (build (code, TREE_TYPE (exp), op0,
2253 TREE_OPERAND (exp, 1)));
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))
2264 new = fold (build (code, TREE_TYPE (exp), op0, op1, op2));
2269 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2270 if (op0 == TREE_OPERAND (exp, 0))
2273 new = fold (build1 (code, TREE_TYPE (exp), op0));
2285 TREE_READONLY (new) = TREE_READONLY (exp);
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.
2294 Also allows conversion expressions whose operands are references.
2295 Any other kind of expression is returned unchanged. */
2298 stabilize_reference (ref)
2301 register tree result;
2302 register enum tree_code code = TREE_CODE (ref);
2309 /* No action is needed in this case. */
2315 case FIX_TRUNC_EXPR:
2316 case FIX_FLOOR_EXPR:
2317 case FIX_ROUND_EXPR:
2319 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2323 result = build_nt (INDIRECT_REF,
2324 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2328 result = build_nt (COMPONENT_REF,
2329 stabilize_reference (TREE_OPERAND (ref, 0)),
2330 TREE_OPERAND (ref, 1));
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)));
2341 result = build_nt (ARRAY_REF,
2342 stabilize_reference (TREE_OPERAND (ref, 0)),
2343 stabilize_reference_1 (TREE_OPERAND (ref, 1)));
2347 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2348 it wouldn't be ignored. This matters when dealing with
2350 return stabilize_reference_1 (ref);
2353 result = build1 (INDIRECT_REF, TREE_TYPE (ref),
2354 save_expr (build1 (ADDR_EXPR,
2355 build_pointer_type (TREE_TYPE (ref)),
2359 /* If arg isn't a kind of lvalue we recognize, make no change.
2360 Caller should recognize the error for an invalid lvalue. */
2365 return error_mark_node;
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);
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.
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. */
2390 stabilize_reference_1 (e)
2393 register tree result;
2394 register enum tree_code code = TREE_CODE (e);
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. */
2401 if (TREE_CONSTANT (e) || code == SAVE_EXPR)
2404 switch (TREE_CODE_CLASS (code))
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);
2423 /* Constants need no processing. In fact, we should never reach
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)));
2442 /* Recursively stabilize each operand. */
2443 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
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);
2458 /* Low-level constructors for expressions. */
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. */
2466 build VPARAMS ((enum tree_code code, tree tt, ...))
2468 #ifndef ANSI_PROTOTYPES
2469 enum tree_code code;
2474 register int length;
2480 #ifndef ANSI_PROTOTYPES
2481 code = va_arg (p, enum tree_code);
2482 tt = va_arg (p, tree);
2485 t = make_node (code);
2486 length = TREE_CODE_LENGTH (code);
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
2493 fro = first_rtl_op (code);
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);
2501 TREE_OPERAND (t, 0) = arg0;
2502 TREE_OPERAND (t, 1) = arg1;
2503 TREE_READONLY (t) = 1;
2504 if (arg0 && fro > 0)
2506 if (TREE_SIDE_EFFECTS (arg0))
2507 TREE_SIDE_EFFECTS (t) = 1;
2508 if (!TREE_READONLY (arg0))
2509 TREE_READONLY (t) = 0;
2512 if (arg1 && fro > 1)
2514 if (TREE_SIDE_EFFECTS (arg1))
2515 TREE_SIDE_EFFECTS (t) = 1;
2516 if (!TREE_READONLY (arg1))
2517 TREE_READONLY (t) = 0;
2520 else if (length == 1)
2522 register tree arg0 = va_arg (p, tree);
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.
2528 ??? This really should use build1 too. */
2529 if (TREE_CODE_CLASS (code) != 's')
2531 TREE_OPERAND (t, 0) = arg0;
2535 for (i = 0; i < length; i++)
2537 register tree operand = va_arg (p, tree);
2539 TREE_OPERAND (t, i) = operand;
2540 if (operand && fro > i)
2542 if (TREE_SIDE_EFFECTS (operand))
2543 TREE_SIDE_EFFECTS (t) = 1;
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. */
2556 build1 (code, type, node)
2557 enum tree_code code;
2561 register int length;
2562 #ifdef GATHER_STATISTICS
2563 register tree_node_kind kind;
2567 #ifdef GATHER_STATISTICS
2568 if (TREE_CODE_CLASS (code) == 'r')
2574 length = sizeof (struct tree_exp);
2576 t = ggc_alloc_tree (length);
2578 memset ((PTR) t, 0, sizeof (struct tree_common));
2580 #ifdef GATHER_STATISTICS
2581 tree_node_counts[(int) kind]++;
2582 tree_node_sizes[(int) kind] += length;
2585 TREE_SET_CODE (t, code);
2587 TREE_TYPE (t) = type;
2588 TREE_COMPLEXITY (t) = 0;
2589 TREE_OPERAND (t, 0) = node;
2590 if (node && first_rtl_op (code) != 0)
2592 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
2593 TREE_READONLY (t) = TREE_READONLY (node);
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
2608 TREE_SIDE_EFFECTS (t) = 1;
2609 TREE_READONLY (t) = 0;
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. */
2625 build_nt VPARAMS ((enum tree_code code, ...))
2627 #ifndef ANSI_PROTOTYPES
2628 enum tree_code code;
2632 register int length;
2637 #ifndef ANSI_PROTOTYPES
2638 code = va_arg (p, enum tree_code);
2641 t = make_node (code);
2642 length = TREE_CODE_LENGTH (code);
2644 for (i = 0; i < length; i++)
2645 TREE_OPERAND (t, i) = va_arg (p, tree);
2651 /* Similar to `build_nt', except we build
2652 on the temp_decl_obstack, regardless. */
2655 build_parse_node VPARAMS ((enum tree_code code, ...))
2657 #ifndef ANSI_PROTOTYPES
2658 enum tree_code code;
2662 register int length;
2667 #ifndef ANSI_PROTOTYPES
2668 code = va_arg (p, enum tree_code);
2671 t = make_node (code);
2672 length = TREE_CODE_LENGTH (code);
2674 for (i = 0; i < length; i++)
2675 TREE_OPERAND (t, i) = va_arg (p, tree);
2682 /* Commented out because this wants to be done very
2683 differently. See cp-lex.c. */
2685 build_op_identifier (op1, op2)
2688 register tree t = make_node (OP_IDENTIFIER);
2689 TREE_PURPOSE (t) = op1;
2690 TREE_VALUE (t) = op2;
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.
2698 layout_decl is used to set up the decl's storage layout.
2699 Other slots are initialized to 0 or null pointers. */
2702 build_decl (code, name, type)
2703 enum tree_code code;
2708 t = make_node (code);
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. */
2715 DECL_NAME (t) = name;
2716 DECL_ASSEMBLER_NAME (t) = name;
2717 TREE_TYPE (t) = type;
2719 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
2721 else if (code == FUNCTION_DECL)
2722 DECL_MODE (t) = FUNCTION_MODE;
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. */
2732 build_block (vars, tags, subblocks, supercontext, chain)
2733 tree vars, tags ATTRIBUTE_UNUSED, subblocks, supercontext, chain;
2735 register tree block = make_node (BLOCK);
2737 BLOCK_VARS (block) = vars;
2738 BLOCK_SUBBLOCKS (block) = subblocks;
2739 BLOCK_SUPERCONTEXT (block) = supercontext;
2740 BLOCK_CHAIN (block) = chain;
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). */
2750 build_expr_wfl (node, file, line, col)
2755 static const char *last_file = 0;
2756 static tree last_filenode = NULL_TREE;
2757 register tree wfl = make_node (EXPR_WITH_FILE_LOCATION);
2759 EXPR_WFL_NODE (wfl) = node;
2760 EXPR_WFL_SET_LINECOL (wfl, line, col);
2761 if (file != last_file)
2764 last_filenode = file ? get_identifier (file) : NULL_TREE;
2767 EXPR_WFL_FILENAME_NODE (wfl) = last_filenode;
2770 TREE_SIDE_EFFECTS (wfl) = TREE_SIDE_EFFECTS (node);
2771 TREE_TYPE (wfl) = TREE_TYPE (node);
2777 /* Return a declaration like DDECL except that its DECL_MACHINE_ATTRIBUTE
2781 build_decl_attribute_variant (ddecl, attribute)
2782 tree ddecl, attribute;
2784 DECL_MACHINE_ATTRIBUTES (ddecl) = attribute;
2788 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
2791 Record such modified types already made so we don't make duplicates. */
2794 build_type_attribute_variant (ttype, attribute)
2795 tree ttype, attribute;
2797 if ( ! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
2799 unsigned int hashcode;
2802 ntype = copy_node (ttype);
2804 TYPE_POINTER_TO (ntype) = 0;
2805 TYPE_REFERENCE_TO (ntype) = 0;
2806 TYPE_ATTRIBUTES (ntype) = attribute;
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);
2813 hashcode = (TYPE_HASH (TREE_CODE (ntype))
2814 + TYPE_HASH (TREE_TYPE (ntype))
2815 + attribute_hash_list (attribute));
2817 switch (TREE_CODE (ntype))
2820 hashcode += TYPE_HASH (TYPE_ARG_TYPES (ntype));
2823 hashcode += TYPE_HASH (TYPE_DOMAIN (ntype));
2826 hashcode += TYPE_HASH (TYPE_MAX_VALUE (ntype));
2829 hashcode += TYPE_HASH (TYPE_PRECISION (ntype));
2835 ntype = type_hash_canon (hashcode, ntype);
2836 ttype = build_qualified_type (ntype, TYPE_QUALS (ttype));
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. */
2847 valid_machine_attribute (attr_name, attr_args, decl, type)
2849 tree attr_args ATTRIBUTE_UNUSED;
2850 tree decl ATTRIBUTE_UNUSED;
2851 tree type ATTRIBUTE_UNUSED;
2854 #ifdef VALID_MACHINE_DECL_ATTRIBUTE
2855 tree decl_attr_list = decl != 0 ? DECL_MACHINE_ATTRIBUTES (decl) : 0;
2857 #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
2858 tree type_attr_list = TYPE_ATTRIBUTES (type);
2861 if (TREE_CODE (attr_name) != IDENTIFIER_NODE)
2864 #ifdef VALID_MACHINE_DECL_ATTRIBUTE
2866 && VALID_MACHINE_DECL_ATTRIBUTE (decl, decl_attr_list, attr_name,
2869 tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
2872 if (attr != NULL_TREE)
2874 /* Override existing arguments. Declarations are unique so we can
2875 modify this in place. */
2876 TREE_VALUE (attr) = attr_args;
2880 decl_attr_list = tree_cons (attr_name, attr_args, decl_attr_list);
2881 decl = build_decl_attribute_variant (decl, decl_attr_list);
2888 #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
2890 /* Don't apply the attribute to both the decl and the type. */
2892 else if (VALID_MACHINE_TYPE_ATTRIBUTE (type, type_attr_list, attr_name,
2895 tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
2898 if (attr != NULL_TREE)
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;
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);
2913 type = build_type_attribute_variant (type, type_attr_list);
2915 TYPE_ATTRIBUTES (type) = type_attr_list;
2919 TREE_TYPE (decl) = type;
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))
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),
2936 if (attr != NULL_TREE)
2937 TREE_VALUE (attr) = attr_args;
2940 inner_attr_list = tree_cons (attr_name, attr_args, inner_attr_list);
2941 inner_type = build_type_attribute_variant (inner_type,
2946 TREE_TYPE (decl) = build_pointer_type (inner_type);
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;
2962 /* Return non-zero if IDENT is a valid name for attribute ATTR,
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. */
2971 is_attribute_p (attr, ident)
2975 int ident_len, attr_len;
2978 if (TREE_CODE (ident) != IDENTIFIER_NODE)
2981 if (strcmp (attr, IDENTIFIER_POINTER (ident)) == 0)
2984 p = IDENTIFIER_POINTER (ident);
2985 ident_len = strlen (p);
2986 attr_len = strlen (attr);
2988 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
2992 || attr[attr_len - 2] != '_'
2993 || attr[attr_len - 1] != '_')
2995 if (ident_len == attr_len - 4
2996 && strncmp (attr + 2, p, attr_len - 4) == 0)
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)
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
3016 lookup_attribute (attr_name, list)
3017 const char *attr_name;
3022 for (l = list; l; l = TREE_CHAIN (l))
3024 if (TREE_CODE (TREE_PURPOSE (l)) != IDENTIFIER_NODE)
3026 if (is_attribute_p (attr_name, TREE_PURPOSE (l)))
3033 /* Return an attribute list that is the union of a1 and a2. */
3036 merge_attributes (a1, a2)
3037 register tree a1, a2;
3041 /* Either one unset? Take the set one. */
3043 if ((attributes = a1) == 0)
3046 /* One that completely contains the other? Take it. */
3048 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
3050 if (attribute_list_contained (a2, a1))
3054 /* Pick the longest list, and hang on the other list. */
3055 /* ??? For the moment we punt on the issue of attrs with args. */
3057 if (list_length (a1) < list_length (a2))
3058 attributes = a2, a2 = a1;
3060 for (; a2 != 0; a2 = TREE_CHAIN (a2))
3061 if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3062 attributes) == NULL_TREE)
3064 a1 = copy_node (a2);
3065 TREE_CHAIN (a1) = attributes;
3073 /* Given types T1 and T2, merge their attributes and return
3077 merge_machine_type_attributes (t1, t2)
3080 #ifdef MERGE_MACHINE_TYPE_ATTRIBUTES
3081 return MERGE_MACHINE_TYPE_ATTRIBUTES (t1, t2);
3083 return merge_attributes (TYPE_ATTRIBUTES (t1),
3084 TYPE_ATTRIBUTES (t2));
3088 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
3092 merge_machine_decl_attributes (olddecl, newdecl)
3093 tree olddecl, newdecl;
3095 #ifdef MERGE_MACHINE_DECL_ATTRIBUTES
3096 return MERGE_MACHINE_DECL_ATTRIBUTES (olddecl, newdecl);
3098 return merge_attributes (DECL_MACHINE_ATTRIBUTES (olddecl),
3099 DECL_MACHINE_ATTRIBUTES (newdecl));
3103 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
3104 of the various TYPE_QUAL values. */
3107 set_type_quals (type, type_quals)
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;
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. */
3124 build_qualified_type (type, type_quals)
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. */
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))
3138 /* We need a new one. */
3139 t = build_type_copy (type);
3140 set_type_quals (t, type_quals);
3144 /* Create a new variant of TYPE, equivalent but distinct.
3145 This is so the caller can modify it. */
3148 build_type_copy (type)
3151 register tree t, m = TYPE_MAIN_VARIANT (type);
3153 t = copy_node (type);
3155 TYPE_POINTER_TO (t) = 0;
3156 TYPE_REFERENCE_TO (t) = 0;
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;
3165 /* Hashing of types so that we don't make duplicates.
3166 The entry point is `type_hash_canon'. */
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. */
3173 type_hash_list (list)
3176 unsigned int hashcode;
3179 for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
3180 hashcode += TYPE_HASH (TREE_VALUE (tail));
3185 /* These are the Hashtable callback functions. */
3187 /* Returns true if the types are equal. */
3190 type_hash_eq (va, vb)
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)))))
3219 /* Return the cached hash value. */
3222 type_hash_hash (item)
3225 return ((const struct type_hash *) item)->hash;
3228 /* Look in the type hash table for a type isomorphic to TYPE.
3229 If one is found, return it. Otherwise return 0. */
3232 type_hash_lookup (hashcode, type)
3233 unsigned int hashcode;
3236 struct type_hash *h, in;
3238 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
3239 must call that routine before comparing TYPE_ALIGNs. */
3245 h = htab_find_with_hash (type_hash_table, &in, hashcode);
3251 /* Add an entry to the type-hash-table
3252 for a type TYPE whose hash code is HASHCODE. */
3255 type_hash_add (hashcode, type)
3256 unsigned int hashcode;
3259 struct type_hash *h;
3262 h = (struct type_hash *) permalloc (sizeof (struct type_hash));
3265 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
3266 *(struct type_hash **) loc = h;
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.
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. */
3280 /* Set to 1 to debug without canonicalization. Never set by program. */
3281 int debug_no_type_hash = 0;
3284 type_hash_canon (hashcode, type)
3285 unsigned int hashcode;
3290 if (debug_no_type_hash)
3293 t1 = type_hash_lookup (hashcode, type);
3296 #ifdef GATHER_STATISTICS
3297 tree_node_counts[(int) t_kind]--;
3298 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
3303 /* If this is a permanent type, record it for later reuse. */
3304 type_hash_add (hashcode, type);
3309 /* Callback function for htab_traverse. */
3312 mark_hash_entry (entry, param)
3314 void *param ATTRIBUTE_UNUSED;
3316 struct type_hash *p = *(struct type_hash **) entry;
3318 ggc_mark_tree (p->type);
3320 /* Continue scan. */
3324 /* Mark ARG (which is really a htab_t *) for GC. */
3327 mark_type_hash (arg)
3330 htab_t t = *(htab_t *) arg;
3332 htab_traverse (t, mark_hash_entry, 0);
3336 print_type_hash_statistics ()
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));
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. */
3349 attribute_hash_list (list)
3352 unsigned int hashcode;
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));
3361 /* Given two lists of attributes, return true if list l2 is
3362 equivalent to l1. */
3365 attribute_list_equal (l1, l2)
3368 return attribute_list_contained (l1, l2)
3369 && attribute_list_contained (l2, l1);
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
3381 attribute_list_contained (l1, l2)
3384 register tree t1, t2;
3386 /* First check the obvious, maybe the lists are identical. */
3390 /* Maybe the lists are similar. */
3391 for (t1 = l1, t2 = l2;
3393 && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
3394 && TREE_VALUE (t1) == TREE_VALUE (t2);
3395 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
3397 /* Maybe the lists are equal. */
3398 if (t1 == 0 && t2 == 0)
3401 for (; t2 != 0; t2 = TREE_CHAIN (t2))
3404 = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1);
3409 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) != 1)
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. */
3422 type_list_equal (l1, l2)
3425 register tree t1, t2;
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))))))
3438 /* Nonzero if integer constants T1 and T2
3439 represent the same constant value. */
3442 tree_int_cst_equal (t1, t2)
3448 if (t1 == 0 || t2 == 0)
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))
3460 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
3461 The precise way of comparison depends on their data type. */
3464 tree_int_cst_lt (t1, t2)
3470 if (! TREE_UNSIGNED (TREE_TYPE (t1)))
3471 return INT_CST_LT (t1, t2);
3473 return INT_CST_LT_UNSIGNED (t1, t2);
3476 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
3479 tree_int_cst_compare (t1, t2)
3483 if (tree_int_cst_lt (t1, t2))
3485 else if (tree_int_cst_lt (t2, t1))
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. */
3495 host_integerp (t, pos)
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)))));
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. */
3514 tree_low_cst (t, pos)
3518 if (host_integerp (t, pos))
3519 return TREE_INT_CST_LOW (t);
3524 /* Return the most significant bit of the integer constant T. */
3527 tree_int_cst_msb (t)
3532 unsigned HOST_WIDE_INT l;
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;
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. */
3547 tree_int_cst_sgn (t)
3550 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
3552 else if (TREE_UNSIGNED (TREE_TYPE (t)))
3554 else if (TREE_INT_CST_HIGH (t) < 0)
3560 /* Compare two constructor-element-type constants. Return 1 if the lists
3561 are known to be equal; otherwise return 0. */
3564 simple_cst_list_equal (l1, l2)
3567 while (l1 != NULL_TREE && l2 != NULL_TREE)
3569 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
3572 l1 = TREE_CHAIN (l1);
3573 l2 = TREE_CHAIN (l2);
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
3586 simple_cst_equal (t1, t2)
3589 register enum tree_code code1, code2;
3595 if (t1 == 0 || t2 == 0)
3598 code1 = TREE_CODE (t1);
3599 code2 = TREE_CODE (t2);
3601 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
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));
3607 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
3610 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3611 || code2 == NON_LVALUE_EXPR)
3612 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
3620 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3621 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
3624 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
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)));
3632 if (CONSTRUCTOR_ELTS (t1) == CONSTRUCTOR_ELTS (t2))
3638 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3641 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3645 simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
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))
3660 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3665 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3667 case WITH_CLEANUP_EXPR:
3668 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3672 return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
3675 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
3676 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
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
3694 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
3697 switch (TREE_CODE_CLASS (code1))
3706 for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
3708 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
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. */
3725 compare_tree_int (t, u)
3729 if (tree_int_cst_sgn (t) < 0)
3731 else if (TREE_INT_CST_HIGH (t) != 0)
3733 else if (TREE_INT_CST_LOW (t) == u)
3735 else if (TREE_INT_CST_LOW (t) < u)
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.) */
3745 /* Construct, lay out and return the type of pointers to TO_TYPE.
3746 If such a type has already been constructed, reuse it. */
3749 build_pointer_type (to_type)
3752 register tree t = TYPE_POINTER_TO (to_type);
3754 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3759 /* We need a new one. */
3760 t = make_node (POINTER_TYPE);
3762 TREE_TYPE (t) = to_type;
3764 /* Record this type as the pointer to TO_TYPE. */
3765 TYPE_POINTER_TO (to_type) = t;
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. */
3775 /* Build the node for the type of references-to-TO_TYPE. */
3778 build_reference_type (to_type)
3781 register tree t = TYPE_REFERENCE_TO (to_type);
3783 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3788 /* We need a new one. */
3789 t = make_node (REFERENCE_TYPE);
3791 TREE_TYPE (t) = to_type;
3793 /* Record this type as the pointer to TO_TYPE. */
3794 TYPE_REFERENCE_TO (to_type) = t;
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).
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. */
3811 build_index_type (maxval)
3814 register tree itype = make_node (INTEGER_TYPE);
3817 TREE_TYPE (itype) = sizetype;
3818 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
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)
3825 TYPE_MIN_VALUE (itype) = size_one_node;
3826 TYPE_MAX_VALUE (itype) = size_zero_node;
3831 TYPE_MIN_VALUE (itype) = size_zero_node;
3832 TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
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);
3841 if (!no_hash && host_integerp (maxval, 1))
3842 return type_hash_canon (tree_low_cst (maxval, 1), itype);
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. */
3853 build_range_type (type, lowval, highval)
3854 tree type, lowval, highval;
3856 register tree itype = make_node (INTEGER_TYPE);
3858 TREE_TYPE (itype) = type;
3859 if (type == NULL_TREE)
3862 TYPE_MIN_VALUE (itype) = convert (type, lowval);
3863 TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL;
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);
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),
3880 /* Just like build_index_type, but takes lowval and highval instead
3881 of just highval (maxval). */
3884 build_index_2_type (lowval,highval)
3885 tree lowval, highval;
3887 return build_range_type (sizetype, lowval, highval);
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,
3896 index_type_equal (itype1, itype2)
3897 tree itype1, itype2;
3899 if (TREE_CODE (itype1) != TREE_CODE (itype2))
3902 if (TREE_CODE (itype1) == INTEGER_TYPE)
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))
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)))
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. */
3925 build_array_type (elt_type, index_type)
3926 tree elt_type, index_type;
3929 unsigned int hashcode;
3931 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
3933 error ("arrays of functions are not meaningful");
3934 elt_type = integer_type_node;
3937 /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
3938 build_pointer_type (elt_type);
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;
3946 if (index_type == 0)
3951 hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
3952 t = type_hash_canon (hashcode, t);
3954 if (!COMPLETE_TYPE_P (t))
3959 /* Return the TYPE of the elements comprising
3960 the innermost dimension of ARRAY. */
3963 get_inner_array_type (array)
3966 tree type = TREE_TYPE (array);
3968 while (TREE_CODE (type) == ARRAY_TYPE)
3969 type = TREE_TYPE (type);
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. */
3982 build_function_type (value_type, arg_types)
3983 tree value_type, arg_types;
3986 unsigned int hashcode;
3988 if (TREE_CODE (value_type) == FUNCTION_TYPE)
3990 error ("function return type cannot be function");
3991 value_type = integer_type_node;
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;
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);
4003 if (!COMPLETE_TYPE_P (t))
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. */
4014 build_method_type (basetype, type)
4015 tree basetype, type;
4018 unsigned int hashcode;
4020 /* Make a node of the sort we want. */
4021 t = make_node (METHOD_TYPE);
4023 if (TREE_CODE (type) != FUNCTION_TYPE)
4026 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4027 TREE_TYPE (t) = TREE_TYPE (type);
4029 /* The actual arglist for this function includes a "hidden" argument
4030 which is "this". Put it into the list of argument types. */
4033 = tree_cons (NULL_TREE,
4034 build_pointer_type (basetype), TYPE_ARG_TYPES (type));
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);
4040 if (!COMPLETE_TYPE_P (t))
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. */
4051 build_offset_type (basetype, type)
4052 tree basetype, type;
4055 unsigned int hashcode;
4057 /* Make a node of the sort we want. */
4058 t = make_node (OFFSET_TYPE);
4060 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4061 TREE_TYPE (t) = type;
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);
4067 if (!COMPLETE_TYPE_P (t))
4073 /* Create a complex type whose components are COMPONENT_TYPE. */
4076 build_complex_type (component_type)
4077 tree component_type;
4080 unsigned int hashcode;
4082 /* Make a node of the sort we want. */
4083 t = make_node (COMPLEX_TYPE);
4085 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
4086 set_type_quals (t, TYPE_QUALS (component_type));
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);
4092 if (!COMPLETE_TYPE_P (t))
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))
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";
4126 TYPE_NAME (t) = get_identifier (name);
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.
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.
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.
4143 OP must have integer, real or enumeral type. Pointers are not allowed!
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. */
4156 get_unwidened (op, for_type)
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);
4165 = (for_type != 0 && for_type != type
4166 && final_prec > TYPE_PRECISION (type)
4167 && TREE_UNSIGNED (type));
4168 register tree win = op;
4170 while (TREE_CODE (op) == NOP_EXPR)
4172 register int bitschange
4173 = TYPE_PRECISION (TREE_TYPE (op))
4174 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
4176 /* Truncations are many-one so cannot be removed.
4177 Unless we are later going to truncate down even farther. */
4179 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
4182 /* See what's inside this conversion. If we decide to strip it,
4184 op = TREE_OPERAND (op, 0);
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. */
4195 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (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)))
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 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
4216 unsigned int innerprec
4217 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4219 type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
4221 /* We can get this structure field in the narrowest type it fits in.
4222 If FOR_TYPE is 0, do this only for a field that matches the
4223 narrower type exactly and is aligned for it
4224 The resulting extension to its nominal type (a fullword type)
4225 must fit the same conditions as for other extensions. */
4227 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
4228 && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
4229 && (! uns || final_prec <= innerprec
4230 || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
4233 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4234 TREE_OPERAND (op, 1));
4235 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4236 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4243 /* Return OP or a simpler expression for a narrower value
4244 which can be sign-extended or zero-extended to give back OP.
4245 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
4246 or 0 if the value should be sign-extended. */
4249 get_narrower (op, unsignedp_ptr)
4253 register int uns = 0;
4255 register tree win = op;
4257 while (TREE_CODE (op) == NOP_EXPR)
4259 register int bitschange
4260 = (TYPE_PRECISION (TREE_TYPE (op))
4261 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
4263 /* Truncations are many-one so cannot be removed. */
4267 /* See what's inside this conversion. If we decide to strip it,
4269 op = TREE_OPERAND (op, 0);
4273 /* An extension: the outermost one can be stripped,
4274 but remember whether it is zero or sign extension. */
4276 uns = TREE_UNSIGNED (TREE_TYPE (op));
4277 /* Otherwise, if a sign extension has been stripped,
4278 only sign extensions can now be stripped;
4279 if a zero extension has been stripped, only zero-extensions. */
4280 else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
4284 else /* bitschange == 0 */
4286 /* A change in nominal type can always be stripped, but we must
4287 preserve the unsignedness. */
4289 uns = TREE_UNSIGNED (TREE_TYPE (op));
4296 if (TREE_CODE (op) == COMPONENT_REF
4297 /* Since type_for_size always gives an integer type. */
4298 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
4299 /* Ensure field is laid out already. */
4300 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0)
4302 unsigned HOST_WIDE_INT innerprec
4303 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4304 tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
4306 /* We can get this structure field in a narrower type that fits it,
4307 but the resulting extension to its nominal type (a fullword type)
4308 must satisfy the same conditions as for other extensions.
4310 Do this only for fields that are aligned (not bit-fields),
4311 because when bit-field insns will be used there is no
4312 advantage in doing this. */
4314 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
4315 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
4316 && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
4320 uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
4321 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4322 TREE_OPERAND (op, 1));
4323 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4324 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4327 *unsignedp_ptr = uns;
4331 /* Nonzero if integer constant C has a value that is permissible
4332 for type TYPE (an INTEGER_TYPE). */
4335 int_fits_type_p (c, type)
4338 /* If the bounds of the type are integers, we can check ourselves.
4339 Otherwise,. use force_fit_type, which checks against the precision. */
4340 if (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
4341 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
4343 if (TREE_UNSIGNED (type))
4344 return (! INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)
4345 && ! INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type))
4346 /* Negative ints never fit unsigned types. */
4347 && ! (TREE_INT_CST_HIGH (c) < 0
4348 && ! TREE_UNSIGNED (TREE_TYPE (c))));
4350 return (! INT_CST_LT (TYPE_MAX_VALUE (type), c)
4351 && ! INT_CST_LT (c, TYPE_MIN_VALUE (type))
4352 /* Unsigned ints with top bit set never fit signed types. */
4353 && ! (TREE_INT_CST_HIGH (c) < 0
4354 && TREE_UNSIGNED (TREE_TYPE (c))));
4359 TREE_TYPE (c) = type;
4360 return !force_fit_type (c, 0);
4364 /* Given a DECL or TYPE, return the scope in which it was declared, or
4365 NULL_TREE if there is no containing scope. */
4368 get_containing_scope (t)
4371 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
4374 /* Return the innermost context enclosing DECL that is
4375 a FUNCTION_DECL, or zero if none. */
4378 decl_function_context (decl)
4383 if (TREE_CODE (decl) == ERROR_MARK)
4386 if (TREE_CODE (decl) == SAVE_EXPR)
4387 context = SAVE_EXPR_CONTEXT (decl);
4389 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
4390 where we look up the function at runtime. Such functions always take
4391 a first argument of type 'pointer to real context'.
4393 C++ should really be fixed to use DECL_CONTEXT for the real context,
4394 and use something else for the "virtual context". */
4395 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
4398 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4400 context = DECL_CONTEXT (decl);
4402 while (context && TREE_CODE (context) != FUNCTION_DECL)
4404 if (TREE_CODE (context) == BLOCK)
4405 context = BLOCK_SUPERCONTEXT (context);
4407 context = get_containing_scope (context);
4413 /* Return the innermost context enclosing DECL that is
4414 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
4415 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
4418 decl_type_context (decl)
4421 tree context = DECL_CONTEXT (decl);
4425 if (TREE_CODE (context) == RECORD_TYPE
4426 || TREE_CODE (context) == UNION_TYPE
4427 || TREE_CODE (context) == QUAL_UNION_TYPE)
4430 if (TREE_CODE (context) == TYPE_DECL
4431 || TREE_CODE (context) == FUNCTION_DECL)
4432 context = DECL_CONTEXT (context);
4434 else if (TREE_CODE (context) == BLOCK)
4435 context = BLOCK_SUPERCONTEXT (context);
4438 /* Unhandled CONTEXT!? */
4444 /* CALL is a CALL_EXPR. Return the declaration for the function
4445 called, or NULL_TREE if the called function cannot be
4449 get_callee_fndecl (call)
4454 /* It's invalid to call this function with anything but a
4456 if (TREE_CODE (call) != CALL_EXPR)
4459 /* The first operand to the CALL is the address of the function
4461 addr = TREE_OPERAND (call, 0);
4465 /* If this is a readonly function pointer, extract its initial value. */
4466 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
4467 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
4468 && DECL_INITIAL (addr))
4469 addr = DECL_INITIAL (addr);
4471 /* If the address is just `&f' for some function `f', then we know
4472 that `f' is being called. */
4473 if (TREE_CODE (addr) == ADDR_EXPR
4474 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
4475 return TREE_OPERAND (addr, 0);
4477 /* We couldn't figure out what was being called. */
4481 /* Print debugging information about the obstack O, named STR. */
4484 print_obstack_statistics (str, o)
4488 struct _obstack_chunk *chunk = o->chunk;
4492 n_alloc += o->next_free - chunk->contents;
4493 chunk = chunk->prev;
4497 n_alloc += chunk->limit - &chunk->contents[0];
4498 chunk = chunk->prev;
4500 fprintf (stderr, "obstack %s: %u bytes, %d chunks\n",
4501 str, n_alloc, n_chunks);
4504 /* Print debugging information about tree nodes generated during the compile,
4505 and any language-specific information. */
4508 dump_tree_statistics ()
4510 #ifdef GATHER_STATISTICS
4512 int total_nodes, total_bytes;
4515 fprintf (stderr, "\n??? tree nodes created\n\n");
4516 #ifdef GATHER_STATISTICS
4517 fprintf (stderr, "Kind Nodes Bytes\n");
4518 fprintf (stderr, "-------------------------------------\n");
4519 total_nodes = total_bytes = 0;
4520 for (i = 0; i < (int) all_kinds; i++)
4522 fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
4523 tree_node_counts[i], tree_node_sizes[i]);
4524 total_nodes += tree_node_counts[i];
4525 total_bytes += tree_node_sizes[i];
4527 fprintf (stderr, "%-20s %9d\n", "identifier names", id_string_size);
4528 fprintf (stderr, "-------------------------------------\n");
4529 fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
4530 fprintf (stderr, "-------------------------------------\n");
4532 fprintf (stderr, "(No per-node statistics)\n");
4534 print_obstack_statistics ("permanent_obstack", &permanent_obstack);
4535 print_type_hash_statistics ();
4536 print_lang_statistics ();
4539 #define FILE_FUNCTION_PREFIX_LEN 9
4541 #ifndef NO_DOLLAR_IN_LABEL
4542 #define FILE_FUNCTION_FORMAT "_GLOBAL_$%s$%s"
4543 #else /* NO_DOLLAR_IN_LABEL */
4544 #ifndef NO_DOT_IN_LABEL
4545 #define FILE_FUNCTION_FORMAT "_GLOBAL_.%s.%s"
4546 #else /* NO_DOT_IN_LABEL */
4547 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
4548 #endif /* NO_DOT_IN_LABEL */
4549 #endif /* NO_DOLLAR_IN_LABEL */
4551 /* Appends 6 random characters to TEMPLATE to (hopefully) avoid name
4552 clashes in cases where we can't reliably choose a unique name.
4554 Derived from mkstemp.c in libiberty. */
4557 append_random_chars (template)
4560 static const char letters[]
4561 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
4562 static unsigned HOST_WIDE_INT value;
4563 unsigned HOST_WIDE_INT v;
4565 #ifdef HAVE_GETTIMEOFDAY
4569 template += strlen (template);
4571 #ifdef HAVE_GETTIMEOFDAY
4572 /* Get some more or less random data. */
4573 gettimeofday (&tv, NULL);
4574 value += ((unsigned HOST_WIDE_INT) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid ();
4581 /* Fill in the random bits. */
4582 template[0] = letters[v % 62];
4584 template[1] = letters[v % 62];
4586 template[2] = letters[v % 62];
4588 template[3] = letters[v % 62];
4590 template[4] = letters[v % 62];
4592 template[5] = letters[v % 62];
4597 /* P is a string that will be used in a symbol. Mask out any characters
4598 that are not valid in that context. */
4601 clean_symbol_name (p)
4606 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
4609 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
4617 /* Generate a name for a function unique to this translation unit.
4618 TYPE is some string to identify the purpose of this function to the
4619 linker or collect2. */
4622 get_file_function_name_long (type)
4629 if (first_global_object_name)
4630 p = first_global_object_name;
4633 /* We don't have anything that we know to be unique to this translation
4634 unit, so use what we do have and throw in some randomness. */
4636 const char *name = weak_global_object_name;
4637 const char *file = main_input_filename;
4642 file = input_filename;
4644 q = (char *) alloca (7 + strlen (name) + strlen (file));
4646 sprintf (q, "%s%s", name, file);
4647 append_random_chars (q);
4651 buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
4654 /* Set up the name of the file-level functions we may need.
4655 Use a global object (which is already required to be unique over
4656 the program) rather than the file name (which imposes extra
4658 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
4660 /* Don't need to pull weird characters out of global names. */
4661 if (p != first_global_object_name)
4662 clean_symbol_name (buf + 11);
4664 return get_identifier (buf);
4667 /* If KIND=='I', return a suitable global initializer (constructor) name.
4668 If KIND=='D', return a suitable global clean-up (destructor) name. */
4671 get_file_function_name (kind)
4679 return get_file_function_name_long (p);
4682 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
4683 The result is placed in BUFFER (which has length BIT_SIZE),
4684 with one bit in each char ('\000' or '\001').
4686 If the constructor is constant, NULL_TREE is returned.
4687 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
4690 get_set_constructor_bits (init, buffer, bit_size)
4697 HOST_WIDE_INT domain_min
4698 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init))));
4699 tree non_const_bits = NULL_TREE;
4700 for (i = 0; i < bit_size; i++)
4703 for (vals = TREE_OPERAND (init, 1);
4704 vals != NULL_TREE; vals = TREE_CHAIN (vals))
4706 if (TREE_CODE (TREE_VALUE (vals)) != INTEGER_CST
4707 || (TREE_PURPOSE (vals) != NULL_TREE
4708 && TREE_CODE (TREE_PURPOSE (vals)) != INTEGER_CST))
4710 = tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits);
4711 else if (TREE_PURPOSE (vals) != NULL_TREE)
4713 /* Set a range of bits to ones. */
4714 HOST_WIDE_INT lo_index
4715 = TREE_INT_CST_LOW (TREE_PURPOSE (vals)) - domain_min;
4716 HOST_WIDE_INT hi_index
4717 = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min;
4719 if (lo_index < 0 || lo_index >= bit_size
4720 || hi_index < 0 || hi_index >= bit_size)
4722 for (; lo_index <= hi_index; lo_index++)
4723 buffer[lo_index] = 1;
4727 /* Set a single bit to one. */
4729 = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min;
4730 if (index < 0 || index >= bit_size)
4732 error ("invalid initializer for bit string");
4738 return non_const_bits;
4741 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
4742 The result is placed in BUFFER (which is an array of bytes).
4743 If the constructor is constant, NULL_TREE is returned.
4744 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
4747 get_set_constructor_bytes (init, buffer, wd_size)
4749 unsigned char *buffer;
4753 int set_word_size = BITS_PER_UNIT;
4754 int bit_size = wd_size * set_word_size;
4756 unsigned char *bytep = buffer;
4757 char *bit_buffer = (char *) alloca (bit_size);
4758 tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
4760 for (i = 0; i < wd_size; i++)
4763 for (i = 0; i < bit_size; i++)
4767 if (BYTES_BIG_ENDIAN)
4768 *bytep |= (1 << (set_word_size - 1 - bit_pos));
4770 *bytep |= 1 << bit_pos;
4773 if (bit_pos >= set_word_size)
4774 bit_pos = 0, bytep++;
4776 return non_const_bits;
4779 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
4780 /* Complain that the tree code of NODE does not match the expected CODE.
4781 FILE, LINE, and FUNCTION are of the caller. */
4784 tree_check_failed (node, code, file, line, function)
4786 enum tree_code code;
4789 const char *function;
4791 error ("Tree check: expected %s, have %s",
4792 tree_code_name[code], tree_code_name[TREE_CODE (node)]);
4793 fancy_abort (file, line, function);
4796 /* Similar to above, except that we check for a class of tree
4797 code, given in CL. */
4800 tree_class_check_failed (node, cl, file, line, function)
4805 const char *function;
4807 error ("Tree check: expected class '%c', have '%c' (%s)",
4808 cl, TREE_CODE_CLASS (TREE_CODE (node)),
4809 tree_code_name[TREE_CODE (node)]);
4810 fancy_abort (file, line, function);
4813 #endif /* ENABLE_TREE_CHECKING */
4815 /* For a new vector type node T, build the information necessary for
4816 debuggint output. */
4819 finish_vector_type (t)
4825 tree index = build_int_2 (TYPE_VECTOR_SUBPARTS (t) - 1, 0);
4826 tree array = build_array_type (TREE_TYPE (t),
4827 build_index_type (index));
4828 tree rt = make_node (RECORD_TYPE);
4830 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
4831 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
4833 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
4834 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
4835 the representation type, and we want to find that die when looking up
4836 the vector type. This is most easily achieved by making the TYPE_UID
4838 TYPE_UID (rt) = TYPE_UID (t);
4842 /* Create nodes for all integer types (and error_mark_node) using the sizes
4843 of C datatypes. The caller should call set_sizetype soon after calling
4844 this function to select one of the types as sizetype. */
4847 build_common_tree_nodes (signed_char)
4850 error_mark_node = make_node (ERROR_MARK);
4851 TREE_TYPE (error_mark_node) = error_mark_node;
4853 initialize_sizetypes ();
4855 /* Define both `signed char' and `unsigned char'. */
4856 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
4857 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4859 /* Define `char', which is like either `signed char' or `unsigned char'
4860 but not the same as either. */
4863 ? make_signed_type (CHAR_TYPE_SIZE)
4864 : make_unsigned_type (CHAR_TYPE_SIZE));
4866 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
4867 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
4868 integer_type_node = make_signed_type (INT_TYPE_SIZE);
4869 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
4870 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
4871 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
4872 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
4873 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
4875 intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
4876 intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
4877 intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
4878 intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
4879 #if HOST_BITS_PER_WIDE_INT >= 64
4880 intTI_type_node = make_signed_type (GET_MODE_BITSIZE (TImode));
4883 unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
4884 unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
4885 unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
4886 unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
4887 #if HOST_BITS_PER_WIDE_INT >= 64
4888 unsigned_intTI_type_node = make_unsigned_type (GET_MODE_BITSIZE (TImode));
4892 /* Call this function after calling build_common_tree_nodes and set_sizetype.
4893 It will create several other common tree nodes. */
4896 build_common_tree_nodes_2 (short_double)
4899 /* Define these next since types below may used them. */
4900 integer_zero_node = build_int_2 (0, 0);
4901 integer_one_node = build_int_2 (1, 0);
4903 size_zero_node = size_int (0);
4904 size_one_node = size_int (1);
4905 bitsize_zero_node = bitsize_int (0);
4906 bitsize_one_node = bitsize_int (1);
4907 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
4909 void_type_node = make_node (VOID_TYPE);
4910 layout_type (void_type_node);
4912 /* We are not going to have real types in C with less than byte alignment,
4913 so we might as well not have any types that claim to have it. */
4914 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
4915 TYPE_USER_ALIGN (void_type_node) = 0;
4917 null_pointer_node = build_int_2 (0, 0);
4918 TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
4919 layout_type (TREE_TYPE (null_pointer_node));
4921 ptr_type_node = build_pointer_type (void_type_node);
4923 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
4925 float_type_node = make_node (REAL_TYPE);
4926 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
4927 layout_type (float_type_node);
4929 double_type_node = make_node (REAL_TYPE);
4931 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
4933 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
4934 layout_type (double_type_node);
4936 long_double_type_node = make_node (REAL_TYPE);
4937 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
4938 layout_type (long_double_type_node);
4940 complex_integer_type_node = make_node (COMPLEX_TYPE);
4941 TREE_TYPE (complex_integer_type_node) = integer_type_node;
4942 layout_type (complex_integer_type_node);
4944 complex_float_type_node = make_node (COMPLEX_TYPE);
4945 TREE_TYPE (complex_float_type_node) = float_type_node;
4946 layout_type (complex_float_type_node);
4948 complex_double_type_node = make_node (COMPLEX_TYPE);
4949 TREE_TYPE (complex_double_type_node) = double_type_node;
4950 layout_type (complex_double_type_node);
4952 complex_long_double_type_node = make_node (COMPLEX_TYPE);
4953 TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
4954 layout_type (complex_long_double_type_node);
4956 #ifdef BUILD_VA_LIST_TYPE
4957 BUILD_VA_LIST_TYPE (va_list_type_node);
4959 va_list_type_node = build_type_copy (ptr_type_node);
4962 V4SF_type_node = make_node (VECTOR_TYPE);
4963 TREE_TYPE (V4SF_type_node) = float_type_node;
4964 TYPE_MODE (V4SF_type_node) = V4SFmode;
4965 finish_vector_type (V4SF_type_node);
4967 V4SI_type_node = make_node (VECTOR_TYPE);
4968 TREE_TYPE (V4SI_type_node) = intSI_type_node;
4969 TYPE_MODE (V4SI_type_node) = V4SImode;
4970 finish_vector_type (V4SI_type_node);
4972 V2SI_type_node = make_node (VECTOR_TYPE);
4973 TREE_TYPE (V2SI_type_node) = intSI_type_node;
4974 TYPE_MODE (V2SI_type_node) = V2SImode;
4975 finish_vector_type (V2SI_type_node);
4977 V4HI_type_node = make_node (VECTOR_TYPE);
4978 TREE_TYPE (V4HI_type_node) = intHI_type_node;
4979 TYPE_MODE (V4HI_type_node) = V4HImode;
4980 finish_vector_type (V4HI_type_node);
4982 V8QI_type_node = make_node (VECTOR_TYPE);
4983 TREE_TYPE (V8QI_type_node) = intQI_type_node;
4984 TYPE_MODE (V8QI_type_node) = V8QImode;
4985 finish_vector_type (V8QI_type_node);