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 bzero ((char *) hash_table, 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 bzero (rval, 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++;
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 && !bcmp (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 && !bcmp (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 bzero ((char *) &d, 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;
1733 /* Arrange for an expression to be expanded multiple independent
1734 times. This is useful for cleanup actions, as the backend can
1735 expand them multiple times in different places. */
1743 /* If this is already protected, no sense in protecting it again. */
1744 if (TREE_CODE (expr) == UNSAVE_EXPR)
1747 t = build1 (UNSAVE_EXPR, TREE_TYPE (expr), expr);
1748 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (expr);
1752 /* Returns the index of the first non-tree operand for CODE, or the number
1753 of operands if all are trees. */
1757 enum tree_code code;
1763 case GOTO_SUBROUTINE_EXPR:
1768 case WITH_CLEANUP_EXPR:
1769 /* Should be defined to be 2. */
1771 case METHOD_CALL_EXPR:
1774 return TREE_CODE_LENGTH (code);
1778 /* Perform any modifications to EXPR required when it is unsaved. Does
1779 not recurse into EXPR's subtrees. */
1782 unsave_expr_1 (expr)
1785 switch (TREE_CODE (expr))
1788 if (! SAVE_EXPR_PERSISTENT_P (expr))
1789 SAVE_EXPR_RTL (expr) = 0;
1793 /* Don't mess with a TARGET_EXPR that hasn't been expanded.
1794 It's OK for this to happen if it was part of a subtree that
1795 isn't immediately expanded, such as operand 2 of another
1797 if (TREE_OPERAND (expr, 1))
1800 TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 3);
1801 TREE_OPERAND (expr, 3) = NULL_TREE;
1805 /* I don't yet know how to emit a sequence multiple times. */
1806 if (RTL_EXPR_SEQUENCE (expr) != 0)
1811 CALL_EXPR_RTL (expr) = 0;
1815 if (lang_unsave_expr_now != 0)
1816 (*lang_unsave_expr_now) (expr);
1821 /* Helper function for unsave_expr_now. */
1824 unsave_expr_now_r (expr)
1827 enum tree_code code;
1829 /* There's nothing to do for NULL_TREE. */
1833 unsave_expr_1 (expr);
1835 code = TREE_CODE (expr);
1836 switch (TREE_CODE_CLASS (code))
1838 case 'c': /* a constant */
1839 case 't': /* a type node */
1840 case 'd': /* A decl node */
1841 case 'b': /* A block node */
1844 case 'x': /* miscellaneous: e.g., identifier, TREE_LIST or ERROR_MARK. */
1845 if (code == TREE_LIST)
1847 unsave_expr_now_r (TREE_VALUE (expr));
1848 unsave_expr_now_r (TREE_CHAIN (expr));
1852 case 'e': /* an expression */
1853 case 'r': /* a reference */
1854 case 's': /* an expression with side effects */
1855 case '<': /* a comparison expression */
1856 case '2': /* a binary arithmetic expression */
1857 case '1': /* a unary arithmetic expression */
1861 for (i = first_rtl_op (code) - 1; i >= 0; i--)
1862 unsave_expr_now_r (TREE_OPERAND (expr, i));
1871 /* Modify a tree in place so that all the evaluate only once things
1872 are cleared out. Return the EXPR given. */
1875 unsave_expr_now (expr)
1878 if (lang_unsave!= 0)
1879 (*lang_unsave) (&expr);
1881 unsave_expr_now_r (expr);
1886 /* Return 0 if it is safe to evaluate EXPR multiple times,
1887 return 1 if it is safe if EXPR is unsaved afterward, or
1888 return 2 if it is completely unsafe.
1890 This assumes that CALL_EXPRs and TARGET_EXPRs are never replicated in
1891 an expression tree, so that it safe to unsave them and the surrounding
1892 context will be correct.
1894 SAVE_EXPRs basically *only* appear replicated in an expression tree,
1895 occasionally across the whole of a function. It is therefore only
1896 safe to unsave a SAVE_EXPR if you know that all occurrences appear
1897 below the UNSAVE_EXPR.
1899 RTL_EXPRs consume their rtl during evaluation. It is therefore
1900 never possible to unsave them. */
1903 unsafe_for_reeval (expr)
1907 enum tree_code code;
1912 if (expr == NULL_TREE)
1915 code = TREE_CODE (expr);
1916 first_rtl = first_rtl_op (code);
1925 for (exp = expr; exp != 0; exp = TREE_CHAIN (exp))
1927 tmp = unsafe_for_reeval (TREE_VALUE (exp));
1928 unsafeness = MAX (tmp, unsafeness);
1934 tmp = unsafe_for_reeval (TREE_OPERAND (expr, 1));
1935 return MAX (tmp, 1);
1942 /* ??? Add a lang hook if it becomes necessary. */
1946 switch (TREE_CODE_CLASS (code))
1948 case 'c': /* a constant */
1949 case 't': /* a type node */
1950 case 'x': /* something random, like an identifier or an ERROR_MARK. */
1951 case 'd': /* A decl node */
1952 case 'b': /* A block node */
1955 case 'e': /* an expression */
1956 case 'r': /* a reference */
1957 case 's': /* an expression with side effects */
1958 case '<': /* a comparison expression */
1959 case '2': /* a binary arithmetic expression */
1960 case '1': /* a unary arithmetic expression */
1961 for (i = first_rtl - 1; i >= 0; i--)
1963 tmp = unsafe_for_reeval (TREE_OPERAND (expr, i));
1964 unsafeness = MAX (tmp, unsafeness);
1974 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
1975 or offset that depends on a field within a record. */
1978 contains_placeholder_p (exp)
1981 register enum tree_code code;
1987 /* If we have a WITH_RECORD_EXPR, it "cancels" any PLACEHOLDER_EXPR
1988 in it since it is supplying a value for it. */
1989 code = TREE_CODE (exp);
1990 if (code == WITH_RECORD_EXPR)
1992 else if (code == PLACEHOLDER_EXPR)
1995 switch (TREE_CODE_CLASS (code))
1998 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
1999 position computations since they will be converted into a
2000 WITH_RECORD_EXPR involving the reference, which will assume
2001 here will be valid. */
2002 return contains_placeholder_p (TREE_OPERAND (exp, 0));
2005 if (code == TREE_LIST)
2006 return (contains_placeholder_p (TREE_VALUE (exp))
2007 || (TREE_CHAIN (exp) != 0
2008 && contains_placeholder_p (TREE_CHAIN (exp))));
2017 /* Ignoring the first operand isn't quite right, but works best. */
2018 return contains_placeholder_p (TREE_OPERAND (exp, 1));
2025 return (contains_placeholder_p (TREE_OPERAND (exp, 0))
2026 || contains_placeholder_p (TREE_OPERAND (exp, 1))
2027 || contains_placeholder_p (TREE_OPERAND (exp, 2)));
2030 /* If we already know this doesn't have a placeholder, don't
2032 if (SAVE_EXPR_NOPLACEHOLDER (exp) || SAVE_EXPR_RTL (exp) != 0)
2035 SAVE_EXPR_NOPLACEHOLDER (exp) = 1;
2036 result = contains_placeholder_p (TREE_OPERAND (exp, 0));
2038 SAVE_EXPR_NOPLACEHOLDER (exp) = 0;
2043 return (TREE_OPERAND (exp, 1) != 0
2044 && contains_placeholder_p (TREE_OPERAND (exp, 1)));
2050 switch (TREE_CODE_LENGTH (code))
2053 return contains_placeholder_p (TREE_OPERAND (exp, 0));
2055 return (contains_placeholder_p (TREE_OPERAND (exp, 0))
2056 || contains_placeholder_p (TREE_OPERAND (exp, 1)));
2067 /* Return 1 if EXP contains any expressions that produce cleanups for an
2068 outer scope to deal with. Used by fold. */
2076 if (! TREE_SIDE_EFFECTS (exp))
2079 switch (TREE_CODE (exp))
2082 case GOTO_SUBROUTINE_EXPR:
2083 case WITH_CLEANUP_EXPR:
2086 case CLEANUP_POINT_EXPR:
2090 for (exp = TREE_OPERAND (exp, 1); exp; exp = TREE_CHAIN (exp))
2092 cmp = has_cleanups (TREE_VALUE (exp));
2102 /* This general rule works for most tree codes. All exceptions should be
2103 handled above. If this is a language-specific tree code, we can't
2104 trust what might be in the operand, so say we don't know
2106 if ((int) TREE_CODE (exp) >= (int) LAST_AND_UNUSED_TREE_CODE)
2109 nops = first_rtl_op (TREE_CODE (exp));
2110 for (i = 0; i < nops; i++)
2111 if (TREE_OPERAND (exp, i) != 0)
2113 int type = TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, i)));
2114 if (type == 'e' || type == '<' || type == '1' || type == '2'
2115 || type == 'r' || type == 's')
2117 cmp = has_cleanups (TREE_OPERAND (exp, i));
2126 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2127 return a tree with all occurrences of references to F in a
2128 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2129 contains only arithmetic expressions or a CALL_EXPR with a
2130 PLACEHOLDER_EXPR occurring only in its arglist. */
2133 substitute_in_expr (exp, f, r)
2138 enum tree_code code = TREE_CODE (exp);
2143 switch (TREE_CODE_CLASS (code))
2150 if (code == PLACEHOLDER_EXPR)
2152 else if (code == TREE_LIST)
2154 op0 = (TREE_CHAIN (exp) == 0
2155 ? 0 : substitute_in_expr (TREE_CHAIN (exp), f, r));
2156 op1 = substitute_in_expr (TREE_VALUE (exp), f, r);
2157 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2160 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2169 switch (TREE_CODE_LENGTH (code))
2172 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2173 if (op0 == TREE_OPERAND (exp, 0))
2176 new = fold (build1 (code, TREE_TYPE (exp), op0));
2180 /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR
2181 could, but we don't support it. */
2182 if (code == RTL_EXPR)
2184 else if (code == CONSTRUCTOR)
2187 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2188 op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
2189 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2192 new = fold (build (code, TREE_TYPE (exp), op0, op1));
2196 /* It cannot be that anything inside a SAVE_EXPR contains a
2197 PLACEHOLDER_EXPR. */
2198 if (code == SAVE_EXPR)
2201 else if (code == CALL_EXPR)
2203 op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
2204 if (op1 == TREE_OPERAND (exp, 1))
2207 return build (code, TREE_TYPE (exp),
2208 TREE_OPERAND (exp, 0), op1, NULL_TREE);
2211 else if (code != COND_EXPR)
2214 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2215 op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
2216 op2 = substitute_in_expr (TREE_OPERAND (exp, 2), f, r);
2217 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2218 && op2 == TREE_OPERAND (exp, 2))
2221 new = fold (build (code, TREE_TYPE (exp), op0, op1, op2));
2234 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2235 and it is the right field, replace it with R. */
2236 for (inner = TREE_OPERAND (exp, 0);
2237 TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
2238 inner = TREE_OPERAND (inner, 0))
2240 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2241 && TREE_OPERAND (exp, 1) == f)
2244 /* If this expression hasn't been completed let, leave it
2246 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2247 && TREE_TYPE (inner) == 0)
2250 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2251 if (op0 == TREE_OPERAND (exp, 0))
2254 new = fold (build (code, TREE_TYPE (exp), op0,
2255 TREE_OPERAND (exp, 1)));
2259 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2260 op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
2261 op2 = substitute_in_expr (TREE_OPERAND (exp, 2), f, r);
2262 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2263 && op2 == TREE_OPERAND (exp, 2))
2266 new = fold (build (code, TREE_TYPE (exp), op0, op1, op2));
2271 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2272 if (op0 == TREE_OPERAND (exp, 0))
2275 new = fold (build1 (code, TREE_TYPE (exp), op0));
2287 TREE_READONLY (new) = TREE_READONLY (exp);
2291 /* Stabilize a reference so that we can use it any number of times
2292 without causing its operands to be evaluated more than once.
2293 Returns the stabilized reference. This works by means of save_expr,
2294 so see the caveats in the comments about save_expr.
2296 Also allows conversion expressions whose operands are references.
2297 Any other kind of expression is returned unchanged. */
2300 stabilize_reference (ref)
2303 register tree result;
2304 register enum tree_code code = TREE_CODE (ref);
2311 /* No action is needed in this case. */
2317 case FIX_TRUNC_EXPR:
2318 case FIX_FLOOR_EXPR:
2319 case FIX_ROUND_EXPR:
2321 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2325 result = build_nt (INDIRECT_REF,
2326 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2330 result = build_nt (COMPONENT_REF,
2331 stabilize_reference (TREE_OPERAND (ref, 0)),
2332 TREE_OPERAND (ref, 1));
2336 result = build_nt (BIT_FIELD_REF,
2337 stabilize_reference (TREE_OPERAND (ref, 0)),
2338 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2339 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2343 result = build_nt (ARRAY_REF,
2344 stabilize_reference (TREE_OPERAND (ref, 0)),
2345 stabilize_reference_1 (TREE_OPERAND (ref, 1)));
2349 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2350 it wouldn't be ignored. This matters when dealing with
2352 return stabilize_reference_1 (ref);
2355 result = build1 (INDIRECT_REF, TREE_TYPE (ref),
2356 save_expr (build1 (ADDR_EXPR,
2357 build_pointer_type (TREE_TYPE (ref)),
2361 /* If arg isn't a kind of lvalue we recognize, make no change.
2362 Caller should recognize the error for an invalid lvalue. */
2367 return error_mark_node;
2370 TREE_TYPE (result) = TREE_TYPE (ref);
2371 TREE_READONLY (result) = TREE_READONLY (ref);
2372 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2373 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2378 /* Subroutine of stabilize_reference; this is called for subtrees of
2379 references. Any expression with side-effects must be put in a SAVE_EXPR
2380 to ensure that it is only evaluated once.
2382 We don't put SAVE_EXPR nodes around everything, because assigning very
2383 simple expressions to temporaries causes us to miss good opportunities
2384 for optimizations. Among other things, the opportunity to fold in the
2385 addition of a constant into an addressing mode often gets lost, e.g.
2386 "y[i+1] += x;". In general, we take the approach that we should not make
2387 an assignment unless we are forced into it - i.e., that any non-side effect
2388 operator should be allowed, and that cse should take care of coalescing
2389 multiple utterances of the same expression should that prove fruitful. */
2392 stabilize_reference_1 (e)
2395 register tree result;
2396 register enum tree_code code = TREE_CODE (e);
2398 /* We cannot ignore const expressions because it might be a reference
2399 to a const array but whose index contains side-effects. But we can
2400 ignore things that are actual constant or that already have been
2401 handled by this function. */
2403 if (TREE_CONSTANT (e) || code == SAVE_EXPR)
2406 switch (TREE_CODE_CLASS (code))
2416 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2417 so that it will only be evaluated once. */
2418 /* The reference (r) and comparison (<) classes could be handled as
2419 below, but it is generally faster to only evaluate them once. */
2420 if (TREE_SIDE_EFFECTS (e))
2421 return save_expr (e);
2425 /* Constants need no processing. In fact, we should never reach
2430 /* Division is slow and tends to be compiled with jumps,
2431 especially the division by powers of 2 that is often
2432 found inside of an array reference. So do it just once. */
2433 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
2434 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
2435 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
2436 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
2437 return save_expr (e);
2438 /* Recursively stabilize each operand. */
2439 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
2440 stabilize_reference_1 (TREE_OPERAND (e, 1)));
2444 /* Recursively stabilize each operand. */
2445 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
2452 TREE_TYPE (result) = TREE_TYPE (e);
2453 TREE_READONLY (result) = TREE_READONLY (e);
2454 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
2455 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
2460 /* Low-level constructors for expressions. */
2462 /* Build an expression of code CODE, data type TYPE,
2463 and operands as specified by the arguments ARG1 and following arguments.
2464 Expressions and reference nodes can be created this way.
2465 Constants, decls, types and misc nodes cannot be. */
2468 build VPARAMS ((enum tree_code code, tree tt, ...))
2470 #ifndef ANSI_PROTOTYPES
2471 enum tree_code code;
2476 register int length;
2482 #ifndef ANSI_PROTOTYPES
2483 code = va_arg (p, enum tree_code);
2484 tt = va_arg (p, tree);
2487 t = make_node (code);
2488 length = TREE_CODE_LENGTH (code);
2491 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_RAISED for
2492 the result based on those same flags for the arguments. But, if
2493 the arguments aren't really even `tree' expressions, we shouldn't
2494 be trying to do this. */
2495 fro = first_rtl_op (code);
2499 /* This is equivalent to the loop below, but faster. */
2500 register tree arg0 = va_arg (p, tree);
2501 register tree arg1 = va_arg (p, tree);
2502 TREE_OPERAND (t, 0) = arg0;
2503 TREE_OPERAND (t, 1) = arg1;
2504 if (arg0 && fro > 0)
2506 if (TREE_SIDE_EFFECTS (arg0))
2507 TREE_SIDE_EFFECTS (t) = 1;
2509 if (arg1 && fro > 1)
2511 if (TREE_SIDE_EFFECTS (arg1))
2512 TREE_SIDE_EFFECTS (t) = 1;
2515 else if (length == 1)
2517 register tree arg0 = va_arg (p, tree);
2519 /* Call build1 for this! */
2520 if (TREE_CODE_CLASS (code) != 's')
2522 TREE_OPERAND (t, 0) = arg0;
2525 if (arg0 && TREE_SIDE_EFFECTS (arg0))
2526 TREE_SIDE_EFFECTS (t) = 1;
2531 for (i = 0; i < length; i++)
2533 register tree operand = va_arg (p, tree);
2534 TREE_OPERAND (t, i) = operand;
2535 if (operand && fro > i)
2537 if (TREE_SIDE_EFFECTS (operand))
2538 TREE_SIDE_EFFECTS (t) = 1;
2546 /* Same as above, but only builds for unary operators.
2547 Saves lions share of calls to `build'; cuts down use
2548 of varargs, which is expensive for RISC machines. */
2551 build1 (code, type, node)
2552 enum tree_code code;
2556 register int length;
2557 #ifdef GATHER_STATISTICS
2558 register tree_node_kind kind;
2562 #ifdef GATHER_STATISTICS
2563 if (TREE_CODE_CLASS (code) == 'r')
2569 length = sizeof (struct tree_exp);
2571 t = ggc_alloc_tree (length);
2573 memset ((PTR) t, 0, sizeof (struct tree_common));
2575 #ifdef GATHER_STATISTICS
2576 tree_node_counts[(int) kind]++;
2577 tree_node_sizes[(int) kind] += length;
2580 TREE_SET_CODE (t, code);
2581 TREE_TYPE (t) = type;
2582 TREE_COMPLEXITY (t) = 0;
2583 TREE_OPERAND (t, 0) = node;
2584 if (node && first_rtl_op (code) != 0 && TREE_SIDE_EFFECTS (node))
2585 TREE_SIDE_EFFECTS (t) = 1;
2593 case PREDECREMENT_EXPR:
2594 case PREINCREMENT_EXPR:
2595 case POSTDECREMENT_EXPR:
2596 case POSTINCREMENT_EXPR:
2597 /* All of these have side-effects, no matter what their
2599 TREE_SIDE_EFFECTS (t) = 1;
2609 /* Similar except don't specify the TREE_TYPE
2610 and leave the TREE_SIDE_EFFECTS as 0.
2611 It is permissible for arguments to be null,
2612 or even garbage if their values do not matter. */
2615 build_nt VPARAMS ((enum tree_code code, ...))
2617 #ifndef ANSI_PROTOTYPES
2618 enum tree_code code;
2622 register int length;
2627 #ifndef ANSI_PROTOTYPES
2628 code = va_arg (p, enum tree_code);
2631 t = make_node (code);
2632 length = TREE_CODE_LENGTH (code);
2634 for (i = 0; i < length; i++)
2635 TREE_OPERAND (t, i) = va_arg (p, tree);
2641 /* Similar to `build_nt', except we build
2642 on the temp_decl_obstack, regardless. */
2645 build_parse_node VPARAMS ((enum tree_code code, ...))
2647 #ifndef ANSI_PROTOTYPES
2648 enum tree_code code;
2652 register int length;
2657 #ifndef ANSI_PROTOTYPES
2658 code = va_arg (p, enum tree_code);
2661 t = make_node (code);
2662 length = TREE_CODE_LENGTH (code);
2664 for (i = 0; i < length; i++)
2665 TREE_OPERAND (t, i) = va_arg (p, tree);
2672 /* Commented out because this wants to be done very
2673 differently. See cp-lex.c. */
2675 build_op_identifier (op1, op2)
2678 register tree t = make_node (OP_IDENTIFIER);
2679 TREE_PURPOSE (t) = op1;
2680 TREE_VALUE (t) = op2;
2685 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2686 We do NOT enter this node in any sort of symbol table.
2688 layout_decl is used to set up the decl's storage layout.
2689 Other slots are initialized to 0 or null pointers. */
2692 build_decl (code, name, type)
2693 enum tree_code code;
2698 t = make_node (code);
2700 /* if (type == error_mark_node)
2701 type = integer_type_node; */
2702 /* That is not done, deliberately, so that having error_mark_node
2703 as the type can suppress useless errors in the use of this variable. */
2705 DECL_NAME (t) = name;
2706 DECL_ASSEMBLER_NAME (t) = name;
2707 TREE_TYPE (t) = type;
2709 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
2711 else if (code == FUNCTION_DECL)
2712 DECL_MODE (t) = FUNCTION_MODE;
2717 /* BLOCK nodes are used to represent the structure of binding contours
2718 and declarations, once those contours have been exited and their contents
2719 compiled. This information is used for outputting debugging info. */
2722 build_block (vars, tags, subblocks, supercontext, chain)
2723 tree vars, tags ATTRIBUTE_UNUSED, subblocks, supercontext, chain;
2725 register tree block = make_node (BLOCK);
2727 BLOCK_VARS (block) = vars;
2728 BLOCK_SUBBLOCKS (block) = subblocks;
2729 BLOCK_SUPERCONTEXT (block) = supercontext;
2730 BLOCK_CHAIN (block) = chain;
2734 /* EXPR_WITH_FILE_LOCATION are used to keep track of the exact
2735 location where an expression or an identifier were encountered. It
2736 is necessary for languages where the frontend parser will handle
2737 recursively more than one file (Java is one of them). */
2740 build_expr_wfl (node, file, line, col)
2745 static const char *last_file = 0;
2746 static tree last_filenode = NULL_TREE;
2747 register tree wfl = make_node (EXPR_WITH_FILE_LOCATION);
2749 EXPR_WFL_NODE (wfl) = node;
2750 EXPR_WFL_SET_LINECOL (wfl, line, col);
2751 if (file != last_file)
2754 last_filenode = file ? get_identifier (file) : NULL_TREE;
2757 EXPR_WFL_FILENAME_NODE (wfl) = last_filenode;
2760 TREE_SIDE_EFFECTS (wfl) = TREE_SIDE_EFFECTS (node);
2761 TREE_TYPE (wfl) = TREE_TYPE (node);
2767 /* Return a declaration like DDECL except that its DECL_MACHINE_ATTRIBUTE
2771 build_decl_attribute_variant (ddecl, attribute)
2772 tree ddecl, attribute;
2774 DECL_MACHINE_ATTRIBUTES (ddecl) = attribute;
2778 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
2781 Record such modified types already made so we don't make duplicates. */
2784 build_type_attribute_variant (ttype, attribute)
2785 tree ttype, attribute;
2787 if ( ! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
2789 unsigned int hashcode;
2792 ntype = copy_node (ttype);
2794 TYPE_POINTER_TO (ntype) = 0;
2795 TYPE_REFERENCE_TO (ntype) = 0;
2796 TYPE_ATTRIBUTES (ntype) = attribute;
2798 /* Create a new main variant of TYPE. */
2799 TYPE_MAIN_VARIANT (ntype) = ntype;
2800 TYPE_NEXT_VARIANT (ntype) = 0;
2801 set_type_quals (ntype, TYPE_UNQUALIFIED);
2803 hashcode = (TYPE_HASH (TREE_CODE (ntype))
2804 + TYPE_HASH (TREE_TYPE (ntype))
2805 + attribute_hash_list (attribute));
2807 switch (TREE_CODE (ntype))
2810 hashcode += TYPE_HASH (TYPE_ARG_TYPES (ntype));
2813 hashcode += TYPE_HASH (TYPE_DOMAIN (ntype));
2816 hashcode += TYPE_HASH (TYPE_MAX_VALUE (ntype));
2819 hashcode += TYPE_HASH (TYPE_PRECISION (ntype));
2825 ntype = type_hash_canon (hashcode, ntype);
2826 ttype = build_qualified_type (ntype, TYPE_QUALS (ttype));
2832 /* Return a 1 if ATTR_NAME and ATTR_ARGS is valid for either declaration DECL
2833 or type TYPE and 0 otherwise. Validity is determined the configuration
2834 macros VALID_MACHINE_DECL_ATTRIBUTE and VALID_MACHINE_TYPE_ATTRIBUTE. */
2837 valid_machine_attribute (attr_name, attr_args, decl, type)
2839 tree attr_args ATTRIBUTE_UNUSED;
2840 tree decl ATTRIBUTE_UNUSED;
2841 tree type ATTRIBUTE_UNUSED;
2844 #ifdef VALID_MACHINE_DECL_ATTRIBUTE
2845 tree decl_attr_list = decl != 0 ? DECL_MACHINE_ATTRIBUTES (decl) : 0;
2847 #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
2848 tree type_attr_list = TYPE_ATTRIBUTES (type);
2851 if (TREE_CODE (attr_name) != IDENTIFIER_NODE)
2854 #ifdef VALID_MACHINE_DECL_ATTRIBUTE
2856 && VALID_MACHINE_DECL_ATTRIBUTE (decl, decl_attr_list, attr_name,
2859 tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
2862 if (attr != NULL_TREE)
2864 /* Override existing arguments. Declarations are unique so we can
2865 modify this in place. */
2866 TREE_VALUE (attr) = attr_args;
2870 decl_attr_list = tree_cons (attr_name, attr_args, decl_attr_list);
2871 decl = build_decl_attribute_variant (decl, decl_attr_list);
2878 #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
2880 /* Don't apply the attribute to both the decl and the type. */
2882 else if (VALID_MACHINE_TYPE_ATTRIBUTE (type, type_attr_list, attr_name,
2885 tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
2888 if (attr != NULL_TREE)
2890 /* Override existing arguments.
2891 ??? This currently works since attribute arguments are not
2892 included in `attribute_hash_list'. Something more complicated
2893 may be needed in the future. */
2894 TREE_VALUE (attr) = attr_args;
2898 /* If this is part of a declaration, create a type variant,
2899 otherwise, this is part of a type definition, so add it
2900 to the base type. */
2901 type_attr_list = tree_cons (attr_name, attr_args, type_attr_list);
2903 type = build_type_attribute_variant (type, type_attr_list);
2905 TYPE_ATTRIBUTES (type) = type_attr_list;
2909 TREE_TYPE (decl) = type;
2914 /* Handle putting a type attribute on pointer-to-function-type by putting
2915 the attribute on the function type. */
2916 else if (POINTER_TYPE_P (type)
2917 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
2918 && VALID_MACHINE_TYPE_ATTRIBUTE (TREE_TYPE (type), type_attr_list,
2919 attr_name, attr_args))
2921 tree inner_type = TREE_TYPE (type);
2922 tree inner_attr_list = TYPE_ATTRIBUTES (inner_type);
2923 tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
2926 if (attr != NULL_TREE)
2927 TREE_VALUE (attr) = attr_args;
2930 inner_attr_list = tree_cons (attr_name, attr_args, inner_attr_list);
2931 inner_type = build_type_attribute_variant (inner_type,
2936 TREE_TYPE (decl) = build_pointer_type (inner_type);
2939 /* Clear TYPE_POINTER_TO for the old inner type, since
2940 `type' won't be pointing to it anymore. */
2941 TYPE_POINTER_TO (TREE_TYPE (type)) = NULL_TREE;
2942 TREE_TYPE (type) = inner_type;
2952 /* Return non-zero if IDENT is a valid name for attribute ATTR,
2955 We try both `text' and `__text__', ATTR may be either one. */
2956 /* ??? It might be a reasonable simplification to require ATTR to be only
2957 `text'. One might then also require attribute lists to be stored in
2958 their canonicalized form. */
2961 is_attribute_p (attr, ident)
2965 int ident_len, attr_len;
2968 if (TREE_CODE (ident) != IDENTIFIER_NODE)
2971 if (strcmp (attr, IDENTIFIER_POINTER (ident)) == 0)
2974 p = IDENTIFIER_POINTER (ident);
2975 ident_len = strlen (p);
2976 attr_len = strlen (attr);
2978 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
2982 || attr[attr_len - 2] != '_'
2983 || attr[attr_len - 1] != '_')
2985 if (ident_len == attr_len - 4
2986 && strncmp (attr + 2, p, attr_len - 4) == 0)
2991 if (ident_len == attr_len + 4
2992 && p[0] == '_' && p[1] == '_'
2993 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
2994 && strncmp (attr, p + 2, attr_len) == 0)
3001 /* Given an attribute name and a list of attributes, return a pointer to the
3002 attribute's list element if the attribute is part of the list, or NULL_TREE
3006 lookup_attribute (attr_name, list)
3007 const char *attr_name;
3012 for (l = list; l; l = TREE_CHAIN (l))
3014 if (TREE_CODE (TREE_PURPOSE (l)) != IDENTIFIER_NODE)
3016 if (is_attribute_p (attr_name, TREE_PURPOSE (l)))
3023 /* Return an attribute list that is the union of a1 and a2. */
3026 merge_attributes (a1, a2)
3027 register tree a1, a2;
3031 /* Either one unset? Take the set one. */
3033 if ((attributes = a1) == 0)
3036 /* One that completely contains the other? Take it. */
3038 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
3040 if (attribute_list_contained (a2, a1))
3044 /* Pick the longest list, and hang on the other list. */
3045 /* ??? For the moment we punt on the issue of attrs with args. */
3047 if (list_length (a1) < list_length (a2))
3048 attributes = a2, a2 = a1;
3050 for (; a2 != 0; a2 = TREE_CHAIN (a2))
3051 if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3052 attributes) == NULL_TREE)
3054 a1 = copy_node (a2);
3055 TREE_CHAIN (a1) = attributes;
3063 /* Given types T1 and T2, merge their attributes and return
3067 merge_machine_type_attributes (t1, t2)
3070 #ifdef MERGE_MACHINE_TYPE_ATTRIBUTES
3071 return MERGE_MACHINE_TYPE_ATTRIBUTES (t1, t2);
3073 return merge_attributes (TYPE_ATTRIBUTES (t1),
3074 TYPE_ATTRIBUTES (t2));
3078 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
3082 merge_machine_decl_attributes (olddecl, newdecl)
3083 tree olddecl, newdecl;
3085 #ifdef MERGE_MACHINE_DECL_ATTRIBUTES
3086 return MERGE_MACHINE_DECL_ATTRIBUTES (olddecl, newdecl);
3088 return merge_attributes (DECL_MACHINE_ATTRIBUTES (olddecl),
3089 DECL_MACHINE_ATTRIBUTES (newdecl));
3093 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
3094 of the various TYPE_QUAL values. */
3097 set_type_quals (type, type_quals)
3101 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
3102 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
3103 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
3106 /* Given a type node TYPE and a TYPE_QUALIFIER_SET, return a type for
3107 the same kind of data as TYPE describes. Variants point to the
3108 "main variant" (which has no qualifiers set) via TYPE_MAIN_VARIANT,
3109 and it points to a chain of other variants so that duplicate
3110 variants are never made. Only main variants should ever appear as
3111 types of expressions. */
3114 build_qualified_type (type, type_quals)
3120 /* Search the chain of variants to see if there is already one there just
3121 like the one we need to have. If so, use that existing one. We must
3122 preserve the TYPE_NAME, since there is code that depends on this. */
3124 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
3125 if (TYPE_QUALS (t) == type_quals && TYPE_NAME (t) == TYPE_NAME (type))
3128 /* We need a new one. */
3129 t = build_type_copy (type);
3130 set_type_quals (t, type_quals);
3134 /* Create a new variant of TYPE, equivalent but distinct.
3135 This is so the caller can modify it. */
3138 build_type_copy (type)
3141 register tree t, m = TYPE_MAIN_VARIANT (type);
3143 t = copy_node (type);
3145 TYPE_POINTER_TO (t) = 0;
3146 TYPE_REFERENCE_TO (t) = 0;
3148 /* Add this type to the chain of variants of TYPE. */
3149 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
3150 TYPE_NEXT_VARIANT (m) = t;
3155 /* Hashing of types so that we don't make duplicates.
3156 The entry point is `type_hash_canon'. */
3158 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
3159 with types in the TREE_VALUE slots), by adding the hash codes
3160 of the individual types. */
3163 type_hash_list (list)
3166 unsigned int hashcode;
3169 for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
3170 hashcode += TYPE_HASH (TREE_VALUE (tail));
3175 /* These are the Hashtable callback functions. */
3177 /* Returns true if the types are equal. */
3180 type_hash_eq (va, vb)
3184 const struct type_hash *a = va, *b = vb;
3185 if (a->hash == b->hash
3186 && TREE_CODE (a->type) == TREE_CODE (b->type)
3187 && TREE_TYPE (a->type) == TREE_TYPE (b->type)
3188 && attribute_list_equal (TYPE_ATTRIBUTES (a->type),
3189 TYPE_ATTRIBUTES (b->type))
3190 && TYPE_ALIGN (a->type) == TYPE_ALIGN (b->type)
3191 && (TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
3192 || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
3193 TYPE_MAX_VALUE (b->type)))
3194 && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
3195 || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
3196 TYPE_MIN_VALUE (b->type)))
3197 /* Note that TYPE_DOMAIN is TYPE_ARG_TYPES for FUNCTION_TYPE. */
3198 && (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
3199 || (TYPE_DOMAIN (a->type)
3200 && TREE_CODE (TYPE_DOMAIN (a->type)) == TREE_LIST
3201 && TYPE_DOMAIN (b->type)
3202 && TREE_CODE (TYPE_DOMAIN (b->type)) == TREE_LIST
3203 && type_list_equal (TYPE_DOMAIN (a->type),
3204 TYPE_DOMAIN (b->type)))))
3209 /* Return the cached hash value. */
3212 type_hash_hash (item)
3215 return ((const struct type_hash *) item)->hash;
3218 /* Look in the type hash table for a type isomorphic to TYPE.
3219 If one is found, return it. Otherwise return 0. */
3222 type_hash_lookup (hashcode, type)
3223 unsigned int hashcode;
3226 struct type_hash *h, in;
3228 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
3229 must call that routine before comparing TYPE_ALIGNs. */
3235 h = htab_find_with_hash (type_hash_table, &in, hashcode);
3241 /* Add an entry to the type-hash-table
3242 for a type TYPE whose hash code is HASHCODE. */
3245 type_hash_add (hashcode, type)
3246 unsigned int hashcode;
3249 struct type_hash *h;
3252 h = (struct type_hash *) permalloc (sizeof (struct type_hash));
3255 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
3256 *(struct type_hash **) loc = h;
3259 /* Given TYPE, and HASHCODE its hash code, return the canonical
3260 object for an identical type if one already exists.
3261 Otherwise, return TYPE, and record it as the canonical object
3262 if it is a permanent object.
3264 To use this function, first create a type of the sort you want.
3265 Then compute its hash code from the fields of the type that
3266 make it different from other similar types.
3267 Then call this function and use the value.
3268 This function frees the type you pass in if it is a duplicate. */
3270 /* Set to 1 to debug without canonicalization. Never set by program. */
3271 int debug_no_type_hash = 0;
3274 type_hash_canon (hashcode, type)
3275 unsigned int hashcode;
3280 if (debug_no_type_hash)
3283 t1 = type_hash_lookup (hashcode, type);
3286 #ifdef GATHER_STATISTICS
3287 tree_node_counts[(int) t_kind]--;
3288 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
3293 /* If this is a permanent type, record it for later reuse. */
3294 type_hash_add (hashcode, type);
3299 /* Callback function for htab_traverse. */
3302 mark_hash_entry (entry, param)
3304 void *param ATTRIBUTE_UNUSED;
3306 struct type_hash *p = *(struct type_hash **) entry;
3308 ggc_mark_tree (p->type);
3310 /* Continue scan. */
3314 /* Mark ARG (which is really a htab_t *) for GC. */
3317 mark_type_hash (arg)
3320 htab_t t = *(htab_t *) arg;
3322 htab_traverse (t, mark_hash_entry, 0);
3326 print_type_hash_statistics ()
3328 fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
3329 (long) htab_size (type_hash_table),
3330 (long) htab_elements (type_hash_table),
3331 htab_collisions (type_hash_table));
3334 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
3335 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
3336 by adding the hash codes of the individual attributes. */
3339 attribute_hash_list (list)
3342 unsigned int hashcode;
3345 for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
3346 /* ??? Do we want to add in TREE_VALUE too? */
3347 hashcode += TYPE_HASH (TREE_PURPOSE (tail));
3351 /* Given two lists of attributes, return true if list l2 is
3352 equivalent to l1. */
3355 attribute_list_equal (l1, l2)
3358 return attribute_list_contained (l1, l2)
3359 && attribute_list_contained (l2, l1);
3362 /* Given two lists of attributes, return true if list L2 is
3363 completely contained within L1. */
3364 /* ??? This would be faster if attribute names were stored in a canonicalized
3365 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
3366 must be used to show these elements are equivalent (which they are). */
3367 /* ??? It's not clear that attributes with arguments will always be handled
3371 attribute_list_contained (l1, l2)
3374 register tree t1, t2;
3376 /* First check the obvious, maybe the lists are identical. */
3380 /* Maybe the lists are similar. */
3381 for (t1 = l1, t2 = l2;
3383 && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
3384 && TREE_VALUE (t1) == TREE_VALUE (t2);
3385 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
3387 /* Maybe the lists are equal. */
3388 if (t1 == 0 && t2 == 0)
3391 for (; t2 != 0; t2 = TREE_CHAIN (t2))
3394 = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1);
3399 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) != 1)
3406 /* Given two lists of types
3407 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
3408 return 1 if the lists contain the same types in the same order.
3409 Also, the TREE_PURPOSEs must match. */
3412 type_list_equal (l1, l2)
3415 register tree t1, t2;
3417 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
3418 if (TREE_VALUE (t1) != TREE_VALUE (t2)
3419 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
3420 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
3421 && (TREE_TYPE (TREE_PURPOSE (t1))
3422 == TREE_TYPE (TREE_PURPOSE (t2))))))
3428 /* Nonzero if integer constants T1 and T2
3429 represent the same constant value. */
3432 tree_int_cst_equal (t1, t2)
3438 if (t1 == 0 || t2 == 0)
3441 if (TREE_CODE (t1) == INTEGER_CST
3442 && TREE_CODE (t2) == INTEGER_CST
3443 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3444 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
3450 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
3451 The precise way of comparison depends on their data type. */
3454 tree_int_cst_lt (t1, t2)
3460 if (! TREE_UNSIGNED (TREE_TYPE (t1)))
3461 return INT_CST_LT (t1, t2);
3463 return INT_CST_LT_UNSIGNED (t1, t2);
3466 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
3469 tree_int_cst_compare (t1, t2)
3473 if (tree_int_cst_lt (t1, t2))
3475 else if (tree_int_cst_lt (t2, t1))
3481 /* Return 1 if T is an INTEGER_CST that can be represented in a single
3482 HOST_WIDE_INT value. If POS is nonzero, the result must be positive. */
3485 host_integerp (t, pos)
3489 return (TREE_CODE (t) == INTEGER_CST
3490 && ! TREE_OVERFLOW (t)
3491 && ((TREE_INT_CST_HIGH (t) == 0
3492 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
3493 || (! pos && TREE_INT_CST_HIGH (t) == -1
3494 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
3495 || (! pos && TREE_INT_CST_HIGH (t) == 0
3496 && TREE_UNSIGNED (TREE_TYPE (t)))));
3499 /* Return the HOST_WIDE_INT least significant bits of T if it is an
3500 INTEGER_CST and there is no overflow. POS is nonzero if the result must
3501 be positive. Abort if we cannot satisfy the above conditions. */
3504 tree_low_cst (t, pos)
3508 if (host_integerp (t, pos))
3509 return TREE_INT_CST_LOW (t);
3514 /* Return the most significant bit of the integer constant T. */
3517 tree_int_cst_msb (t)
3522 unsigned HOST_WIDE_INT l;
3524 /* Note that using TYPE_PRECISION here is wrong. We care about the
3525 actual bits, not the (arbitrary) range of the type. */
3526 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
3527 rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
3528 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
3529 return (l & 1) == 1;
3532 /* Return an indication of the sign of the integer constant T.
3533 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
3534 Note that -1 will never be returned it T's type is unsigned. */
3537 tree_int_cst_sgn (t)
3540 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
3542 else if (TREE_UNSIGNED (TREE_TYPE (t)))
3544 else if (TREE_INT_CST_HIGH (t) < 0)
3550 /* Compare two constructor-element-type constants. Return 1 if the lists
3551 are known to be equal; otherwise return 0. */
3554 simple_cst_list_equal (l1, l2)
3557 while (l1 != NULL_TREE && l2 != NULL_TREE)
3559 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
3562 l1 = TREE_CHAIN (l1);
3563 l2 = TREE_CHAIN (l2);
3569 /* Return truthvalue of whether T1 is the same tree structure as T2.
3570 Return 1 if they are the same.
3571 Return 0 if they are understandably different.
3572 Return -1 if either contains tree structure not understood by
3576 simple_cst_equal (t1, t2)
3579 register enum tree_code code1, code2;
3585 if (t1 == 0 || t2 == 0)
3588 code1 = TREE_CODE (t1);
3589 code2 = TREE_CODE (t2);
3591 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
3593 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3594 || code2 == NON_LVALUE_EXPR)
3595 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3597 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
3600 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3601 || code2 == NON_LVALUE_EXPR)
3602 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
3610 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3611 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
3614 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3617 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3618 && ! bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3619 TREE_STRING_LENGTH (t1)));
3622 if (CONSTRUCTOR_ELTS (t1) == CONSTRUCTOR_ELTS (t2))
3628 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3631 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3635 simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3638 /* Special case: if either target is an unallocated VAR_DECL,
3639 it means that it's going to be unified with whatever the
3640 TARGET_EXPR is really supposed to initialize, so treat it
3641 as being equivalent to anything. */
3642 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
3643 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
3644 && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)
3645 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
3646 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
3647 && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))
3650 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3655 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3657 case WITH_CLEANUP_EXPR:
3658 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3662 return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
3665 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
3666 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3680 /* This general rule works for most tree codes. All exceptions should be
3681 handled above. If this is a language-specific tree code, we can't
3682 trust what might be in the operand, so say we don't know
3684 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
3687 switch (TREE_CODE_CLASS (code1))
3696 for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
3698 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
3710 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
3711 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
3712 than U, respectively. */
3715 compare_tree_int (t, u)
3719 if (tree_int_cst_sgn (t) < 0)
3721 else if (TREE_INT_CST_HIGH (t) != 0)
3723 else if (TREE_INT_CST_LOW (t) == u)
3725 else if (TREE_INT_CST_LOW (t) < u)
3731 /* Constructors for pointer, array and function types.
3732 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
3733 constructed by language-dependent code, not here.) */
3735 /* Construct, lay out and return the type of pointers to TO_TYPE.
3736 If such a type has already been constructed, reuse it. */
3739 build_pointer_type (to_type)
3742 register tree t = TYPE_POINTER_TO (to_type);
3744 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3749 /* We need a new one. */
3750 t = make_node (POINTER_TYPE);
3752 TREE_TYPE (t) = to_type;
3754 /* Record this type as the pointer to TO_TYPE. */
3755 TYPE_POINTER_TO (to_type) = t;
3757 /* Lay out the type. This function has many callers that are concerned
3758 with expression-construction, and this simplifies them all.
3759 Also, it guarantees the TYPE_SIZE is in the same obstack as the type. */
3765 /* Build the node for the type of references-to-TO_TYPE. */
3768 build_reference_type (to_type)
3771 register tree t = TYPE_REFERENCE_TO (to_type);
3773 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3778 /* We need a new one. */
3779 t = make_node (REFERENCE_TYPE);
3781 TREE_TYPE (t) = to_type;
3783 /* Record this type as the pointer to TO_TYPE. */
3784 TYPE_REFERENCE_TO (to_type) = t;
3791 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
3792 MAXVAL should be the maximum value in the domain
3793 (one less than the length of the array).
3795 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
3796 We don't enforce this limit, that is up to caller (e.g. language front end).
3797 The limit exists because the result is a signed type and we don't handle
3798 sizes that use more than one HOST_WIDE_INT. */
3801 build_index_type (maxval)
3804 register tree itype = make_node (INTEGER_TYPE);
3806 TREE_TYPE (itype) = sizetype;
3807 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
3808 TYPE_MIN_VALUE (itype) = size_zero_node;
3810 TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
3812 TYPE_MODE (itype) = TYPE_MODE (sizetype);
3813 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
3814 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
3815 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
3816 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
3818 if (host_integerp (maxval, 1))
3819 return type_hash_canon (tree_low_cst (maxval, 1), itype);
3824 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
3825 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
3826 low bound LOWVAL and high bound HIGHVAL.
3827 if TYPE==NULL_TREE, sizetype is used. */
3830 build_range_type (type, lowval, highval)
3831 tree type, lowval, highval;
3833 register tree itype = make_node (INTEGER_TYPE);
3835 TREE_TYPE (itype) = type;
3836 if (type == NULL_TREE)
3839 TYPE_MIN_VALUE (itype) = convert (type, lowval);
3840 TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL;
3842 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
3843 TYPE_MODE (itype) = TYPE_MODE (type);
3844 TYPE_SIZE (itype) = TYPE_SIZE (type);
3845 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
3846 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
3847 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
3849 if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
3850 return type_hash_canon (tree_low_cst (highval, 0)
3851 - tree_low_cst (lowval, 0),
3857 /* Just like build_index_type, but takes lowval and highval instead
3858 of just highval (maxval). */
3861 build_index_2_type (lowval,highval)
3862 tree lowval, highval;
3864 return build_range_type (sizetype, lowval, highval);
3867 /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
3868 Needed because when index types are not hashed, equal index types
3869 built at different times appear distinct, even though structurally,
3873 index_type_equal (itype1, itype2)
3874 tree itype1, itype2;
3876 if (TREE_CODE (itype1) != TREE_CODE (itype2))
3879 if (TREE_CODE (itype1) == INTEGER_TYPE)
3881 if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2)
3882 || TYPE_MODE (itype1) != TYPE_MODE (itype2)
3883 || simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2)) != 1
3884 || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2))
3887 if (1 == simple_cst_equal (TYPE_MIN_VALUE (itype1),
3888 TYPE_MIN_VALUE (itype2))
3889 && 1 == simple_cst_equal (TYPE_MAX_VALUE (itype1),
3890 TYPE_MAX_VALUE (itype2)))
3897 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
3898 and number of elements specified by the range of values of INDEX_TYPE.
3899 If such a type has already been constructed, reuse it. */
3902 build_array_type (elt_type, index_type)
3903 tree elt_type, index_type;
3906 unsigned int hashcode;
3908 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
3910 error ("arrays of functions are not meaningful");
3911 elt_type = integer_type_node;
3914 /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
3915 build_pointer_type (elt_type);
3917 /* Allocate the array after the pointer type,
3918 in case we free it in type_hash_canon. */
3919 t = make_node (ARRAY_TYPE);
3920 TREE_TYPE (t) = elt_type;
3921 TYPE_DOMAIN (t) = index_type;
3923 if (index_type == 0)
3928 hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
3929 t = type_hash_canon (hashcode, t);
3931 if (!COMPLETE_TYPE_P (t))
3936 /* Return the TYPE of the elements comprising
3937 the innermost dimension of ARRAY. */
3940 get_inner_array_type (array)
3943 tree type = TREE_TYPE (array);
3945 while (TREE_CODE (type) == ARRAY_TYPE)
3946 type = TREE_TYPE (type);
3951 /* Construct, lay out and return
3952 the type of functions returning type VALUE_TYPE
3953 given arguments of types ARG_TYPES.
3954 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
3955 are data type nodes for the arguments of the function.
3956 If such a type has already been constructed, reuse it. */
3959 build_function_type (value_type, arg_types)
3960 tree value_type, arg_types;
3963 unsigned int hashcode;
3965 if (TREE_CODE (value_type) == FUNCTION_TYPE)
3967 error ("function return type cannot be function");
3968 value_type = integer_type_node;
3971 /* Make a node of the sort we want. */
3972 t = make_node (FUNCTION_TYPE);
3973 TREE_TYPE (t) = value_type;
3974 TYPE_ARG_TYPES (t) = arg_types;
3976 /* If we already have such a type, use the old one and free this one. */
3977 hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
3978 t = type_hash_canon (hashcode, t);
3980 if (!COMPLETE_TYPE_P (t))
3985 /* Construct, lay out and return the type of methods belonging to class
3986 BASETYPE and whose arguments and values are described by TYPE.
3987 If that type exists already, reuse it.
3988 TYPE must be a FUNCTION_TYPE node. */
3991 build_method_type (basetype, type)
3992 tree basetype, type;
3995 unsigned int hashcode;
3997 /* Make a node of the sort we want. */
3998 t = make_node (METHOD_TYPE);
4000 if (TREE_CODE (type) != FUNCTION_TYPE)
4003 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4004 TREE_TYPE (t) = TREE_TYPE (type);
4006 /* The actual arglist for this function includes a "hidden" argument
4007 which is "this". Put it into the list of argument types. */
4010 = tree_cons (NULL_TREE,
4011 build_pointer_type (basetype), TYPE_ARG_TYPES (type));
4013 /* If we already have such a type, use the old one and free this one. */
4014 hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
4015 t = type_hash_canon (hashcode, t);
4017 if (!COMPLETE_TYPE_P (t))
4023 /* Construct, lay out and return the type of offsets to a value
4024 of type TYPE, within an object of type BASETYPE.
4025 If a suitable offset type exists already, reuse it. */
4028 build_offset_type (basetype, type)
4029 tree basetype, type;
4032 unsigned int hashcode;
4034 /* Make a node of the sort we want. */
4035 t = make_node (OFFSET_TYPE);
4037 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4038 TREE_TYPE (t) = type;
4040 /* If we already have such a type, use the old one and free this one. */
4041 hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
4042 t = type_hash_canon (hashcode, t);
4044 if (!COMPLETE_TYPE_P (t))
4050 /* Create a complex type whose components are COMPONENT_TYPE. */
4053 build_complex_type (component_type)
4054 tree component_type;
4057 unsigned int hashcode;
4059 /* Make a node of the sort we want. */
4060 t = make_node (COMPLEX_TYPE);
4062 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
4063 set_type_quals (t, TYPE_QUALS (component_type));
4065 /* If we already have such a type, use the old one and free this one. */
4066 hashcode = TYPE_HASH (component_type);
4067 t = type_hash_canon (hashcode, t);
4069 if (!COMPLETE_TYPE_P (t))
4072 /* If we are writing Dwarf2 output we need to create a name,
4073 since complex is a fundamental type. */
4074 if (write_symbols == DWARF2_DEBUG && ! TYPE_NAME (t))
4077 if (component_type == char_type_node)
4078 name = "complex char";
4079 else if (component_type == signed_char_type_node)
4080 name = "complex signed char";
4081 else if (component_type == unsigned_char_type_node)
4082 name = "complex unsigned char";
4083 else if (component_type == short_integer_type_node)
4084 name = "complex short int";
4085 else if (component_type == short_unsigned_type_node)
4086 name = "complex short unsigned int";
4087 else if (component_type == integer_type_node)
4088 name = "complex int";
4089 else if (component_type == unsigned_type_node)
4090 name = "complex unsigned int";
4091 else if (component_type == long_integer_type_node)
4092 name = "complex long int";
4093 else if (component_type == long_unsigned_type_node)
4094 name = "complex long unsigned int";
4095 else if (component_type == long_long_integer_type_node)
4096 name = "complex long long int";
4097 else if (component_type == long_long_unsigned_type_node)
4098 name = "complex long long unsigned int";
4103 TYPE_NAME (t) = get_identifier (name);
4109 /* Return OP, stripped of any conversions to wider types as much as is safe.
4110 Converting the value back to OP's type makes a value equivalent to OP.
4112 If FOR_TYPE is nonzero, we return a value which, if converted to
4113 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
4115 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
4116 narrowest type that can hold the value, even if they don't exactly fit.
4117 Otherwise, bit-field references are changed to a narrower type
4118 only if they can be fetched directly from memory in that type.
4120 OP must have integer, real or enumeral type. Pointers are not allowed!
4122 There are some cases where the obvious value we could return
4123 would regenerate to OP if converted to OP's type,
4124 but would not extend like OP to wider types.
4125 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
4126 For example, if OP is (unsigned short)(signed char)-1,
4127 we avoid returning (signed char)-1 if FOR_TYPE is int,
4128 even though extending that to an unsigned short would regenerate OP,
4129 since the result of extending (signed char)-1 to (int)
4130 is different from (int) OP. */
4133 get_unwidened (op, for_type)
4137 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
4138 register tree type = TREE_TYPE (op);
4139 register unsigned final_prec
4140 = TYPE_PRECISION (for_type != 0 ? for_type : type);
4142 = (for_type != 0 && for_type != type
4143 && final_prec > TYPE_PRECISION (type)
4144 && TREE_UNSIGNED (type));
4145 register tree win = op;
4147 while (TREE_CODE (op) == NOP_EXPR)
4149 register int bitschange
4150 = TYPE_PRECISION (TREE_TYPE (op))
4151 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
4153 /* Truncations are many-one so cannot be removed.
4154 Unless we are later going to truncate down even farther. */
4156 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
4159 /* See what's inside this conversion. If we decide to strip it,
4161 op = TREE_OPERAND (op, 0);
4163 /* If we have not stripped any zero-extensions (uns is 0),
4164 we can strip any kind of extension.
4165 If we have previously stripped a zero-extension,
4166 only zero-extensions can safely be stripped.
4167 Any extension can be stripped if the bits it would produce
4168 are all going to be discarded later by truncating to FOR_TYPE. */
4172 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
4174 /* TREE_UNSIGNED says whether this is a zero-extension.
4175 Let's avoid computing it if it does not affect WIN
4176 and if UNS will not be needed again. */
4177 if ((uns || TREE_CODE (op) == NOP_EXPR)
4178 && TREE_UNSIGNED (TREE_TYPE (op)))
4186 if (TREE_CODE (op) == COMPONENT_REF
4187 /* Since type_for_size always gives an integer type. */
4188 && TREE_CODE (type) != REAL_TYPE
4189 /* Don't crash if field not laid out yet. */
4190 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0)
4192 unsigned int innerprec
4193 = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
4195 type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
4197 /* We can get this structure field in the narrowest type it fits in.
4198 If FOR_TYPE is 0, do this only for a field that matches the
4199 narrower type exactly and is aligned for it
4200 The resulting extension to its nominal type (a fullword type)
4201 must fit the same conditions as for other extensions. */
4203 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
4204 && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
4205 && (! uns || final_prec <= innerprec
4206 || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
4209 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4210 TREE_OPERAND (op, 1));
4211 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4212 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4218 /* Return OP or a simpler expression for a narrower value
4219 which can be sign-extended or zero-extended to give back OP.
4220 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
4221 or 0 if the value should be sign-extended. */
4224 get_narrower (op, unsignedp_ptr)
4228 register int uns = 0;
4230 register tree win = op;
4232 while (TREE_CODE (op) == NOP_EXPR)
4234 register int bitschange
4235 = (TYPE_PRECISION (TREE_TYPE (op))
4236 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
4238 /* Truncations are many-one so cannot be removed. */
4242 /* See what's inside this conversion. If we decide to strip it,
4244 op = TREE_OPERAND (op, 0);
4248 /* An extension: the outermost one can be stripped,
4249 but remember whether it is zero or sign extension. */
4251 uns = TREE_UNSIGNED (TREE_TYPE (op));
4252 /* Otherwise, if a sign extension has been stripped,
4253 only sign extensions can now be stripped;
4254 if a zero extension has been stripped, only zero-extensions. */
4255 else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
4259 else /* bitschange == 0 */
4261 /* A change in nominal type can always be stripped, but we must
4262 preserve the unsignedness. */
4264 uns = TREE_UNSIGNED (TREE_TYPE (op));
4271 if (TREE_CODE (op) == COMPONENT_REF
4272 /* Since type_for_size always gives an integer type. */
4273 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
4274 /* Ensure field is laid out already. */
4275 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0)
4277 unsigned HOST_WIDE_INT innerprec
4278 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4279 tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
4281 /* We can get this structure field in a narrower type that fits it,
4282 but the resulting extension to its nominal type (a fullword type)
4283 must satisfy the same conditions as for other extensions.
4285 Do this only for fields that are aligned (not bit-fields),
4286 because when bit-field insns will be used there is no
4287 advantage in doing this. */
4289 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
4290 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
4291 && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
4295 uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
4296 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4297 TREE_OPERAND (op, 1));
4298 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4299 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4302 *unsignedp_ptr = uns;
4306 /* Nonzero if integer constant C has a value that is permissible
4307 for type TYPE (an INTEGER_TYPE). */
4310 int_fits_type_p (c, type)
4313 if (TREE_UNSIGNED (type))
4314 return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
4315 && INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c))
4316 && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
4317 && INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type)))
4318 /* Negative ints never fit unsigned types. */
4319 && ! (TREE_INT_CST_HIGH (c) < 0
4320 && ! TREE_UNSIGNED (TREE_TYPE (c))));
4322 return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
4323 && INT_CST_LT (TYPE_MAX_VALUE (type), c))
4324 && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
4325 && INT_CST_LT (c, TYPE_MIN_VALUE (type)))
4326 /* Unsigned ints with top bit set never fit signed types. */
4327 && ! (TREE_INT_CST_HIGH (c) < 0
4328 && TREE_UNSIGNED (TREE_TYPE (c))));
4331 /* Given a DECL or TYPE, return the scope in which it was declared, or
4332 NULL_TREE if there is no containing scope. */
4335 get_containing_scope (t)
4338 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
4341 /* Return the innermost context enclosing DECL that is
4342 a FUNCTION_DECL, or zero if none. */
4345 decl_function_context (decl)
4350 if (TREE_CODE (decl) == ERROR_MARK)
4353 if (TREE_CODE (decl) == SAVE_EXPR)
4354 context = SAVE_EXPR_CONTEXT (decl);
4356 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
4357 where we look up the function at runtime. Such functions always take
4358 a first argument of type 'pointer to real context'.
4360 C++ should really be fixed to use DECL_CONTEXT for the real context,
4361 and use something else for the "virtual context". */
4362 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
4365 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4367 context = DECL_CONTEXT (decl);
4369 while (context && TREE_CODE (context) != FUNCTION_DECL)
4371 if (TREE_CODE (context) == BLOCK)
4372 context = BLOCK_SUPERCONTEXT (context);
4374 context = get_containing_scope (context);
4380 /* Return the innermost context enclosing DECL that is
4381 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
4382 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
4385 decl_type_context (decl)
4388 tree context = DECL_CONTEXT (decl);
4392 if (TREE_CODE (context) == RECORD_TYPE
4393 || TREE_CODE (context) == UNION_TYPE
4394 || TREE_CODE (context) == QUAL_UNION_TYPE)
4397 if (TREE_CODE (context) == TYPE_DECL
4398 || TREE_CODE (context) == FUNCTION_DECL)
4399 context = DECL_CONTEXT (context);
4401 else if (TREE_CODE (context) == BLOCK)
4402 context = BLOCK_SUPERCONTEXT (context);
4405 /* Unhandled CONTEXT!? */
4411 /* CALL is a CALL_EXPR. Return the declaration for the function
4412 called, or NULL_TREE if the called function cannot be
4416 get_callee_fndecl (call)
4421 /* It's invalid to call this function with anything but a
4423 if (TREE_CODE (call) != CALL_EXPR)
4426 /* The first operand to the CALL is the address of the function
4428 addr = TREE_OPERAND (call, 0);
4432 /* If this is a readonly function pointer, extract its initial value. */
4433 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
4434 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
4435 && DECL_INITIAL (addr))
4436 addr = DECL_INITIAL (addr);
4438 /* If the address is just `&f' for some function `f', then we know
4439 that `f' is being called. */
4440 if (TREE_CODE (addr) == ADDR_EXPR
4441 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
4442 return TREE_OPERAND (addr, 0);
4444 /* We couldn't figure out what was being called. */
4448 /* Print debugging information about the obstack O, named STR. */
4451 print_obstack_statistics (str, o)
4455 struct _obstack_chunk *chunk = o->chunk;
4459 n_alloc += o->next_free - chunk->contents;
4460 chunk = chunk->prev;
4464 n_alloc += chunk->limit - &chunk->contents[0];
4465 chunk = chunk->prev;
4467 fprintf (stderr, "obstack %s: %u bytes, %d chunks\n",
4468 str, n_alloc, n_chunks);
4471 /* Print debugging information about tree nodes generated during the compile,
4472 and any language-specific information. */
4475 dump_tree_statistics ()
4477 #ifdef GATHER_STATISTICS
4479 int total_nodes, total_bytes;
4482 fprintf (stderr, "\n??? tree nodes created\n\n");
4483 #ifdef GATHER_STATISTICS
4484 fprintf (stderr, "Kind Nodes Bytes\n");
4485 fprintf (stderr, "-------------------------------------\n");
4486 total_nodes = total_bytes = 0;
4487 for (i = 0; i < (int) all_kinds; i++)
4489 fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
4490 tree_node_counts[i], tree_node_sizes[i]);
4491 total_nodes += tree_node_counts[i];
4492 total_bytes += tree_node_sizes[i];
4494 fprintf (stderr, "%-20s %9d\n", "identifier names", id_string_size);
4495 fprintf (stderr, "-------------------------------------\n");
4496 fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
4497 fprintf (stderr, "-------------------------------------\n");
4499 fprintf (stderr, "(No per-node statistics)\n");
4501 print_obstack_statistics ("permanent_obstack", &permanent_obstack);
4502 print_type_hash_statistics ();
4503 print_lang_statistics ();
4506 #define FILE_FUNCTION_PREFIX_LEN 9
4508 #ifndef NO_DOLLAR_IN_LABEL
4509 #define FILE_FUNCTION_FORMAT "_GLOBAL_$%s$%s"
4510 #else /* NO_DOLLAR_IN_LABEL */
4511 #ifndef NO_DOT_IN_LABEL
4512 #define FILE_FUNCTION_FORMAT "_GLOBAL_.%s.%s"
4513 #else /* NO_DOT_IN_LABEL */
4514 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
4515 #endif /* NO_DOT_IN_LABEL */
4516 #endif /* NO_DOLLAR_IN_LABEL */
4518 /* Appends 6 random characters to TEMPLATE to (hopefully) avoid name
4519 clashes in cases where we can't reliably choose a unique name.
4521 Derived from mkstemp.c in libiberty. */
4524 append_random_chars (template)
4527 static const char letters[]
4528 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
4529 static unsigned HOST_WIDE_INT value;
4530 unsigned HOST_WIDE_INT v;
4532 #ifdef HAVE_GETTIMEOFDAY
4536 template += strlen (template);
4538 #ifdef HAVE_GETTIMEOFDAY
4539 /* Get some more or less random data. */
4540 gettimeofday (&tv, NULL);
4541 value += ((unsigned HOST_WIDE_INT) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid ();
4548 /* Fill in the random bits. */
4549 template[0] = letters[v % 62];
4551 template[1] = letters[v % 62];
4553 template[2] = letters[v % 62];
4555 template[3] = letters[v % 62];
4557 template[4] = letters[v % 62];
4559 template[5] = letters[v % 62];
4564 /* P is a string that will be used in a symbol. Mask out any characters
4565 that are not valid in that context. */
4568 clean_symbol_name (p)
4573 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
4576 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
4584 /* Generate a name for a function unique to this translation unit.
4585 TYPE is some string to identify the purpose of this function to the
4586 linker or collect2. */
4589 get_file_function_name_long (type)
4596 if (first_global_object_name)
4597 p = first_global_object_name;
4600 /* We don't have anything that we know to be unique to this translation
4601 unit, so use what we do have and throw in some randomness. */
4603 const char *name = weak_global_object_name;
4604 const char *file = main_input_filename;
4609 file = input_filename;
4611 q = (char *) alloca (7 + strlen (name) + strlen (file));
4613 sprintf (q, "%s%s", name, file);
4614 append_random_chars (q);
4618 buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
4621 /* Set up the name of the file-level functions we may need.
4622 Use a global object (which is already required to be unique over
4623 the program) rather than the file name (which imposes extra
4625 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
4627 /* Don't need to pull weird characters out of global names. */
4628 if (p != first_global_object_name)
4629 clean_symbol_name (buf + 11);
4631 return get_identifier (buf);
4634 /* If KIND=='I', return a suitable global initializer (constructor) name.
4635 If KIND=='D', return a suitable global clean-up (destructor) name. */
4638 get_file_function_name (kind)
4646 return get_file_function_name_long (p);
4649 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
4650 The result is placed in BUFFER (which has length BIT_SIZE),
4651 with one bit in each char ('\000' or '\001').
4653 If the constructor is constant, NULL_TREE is returned.
4654 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
4657 get_set_constructor_bits (init, buffer, bit_size)
4664 HOST_WIDE_INT domain_min
4665 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init))));
4666 tree non_const_bits = NULL_TREE;
4667 for (i = 0; i < bit_size; i++)
4670 for (vals = TREE_OPERAND (init, 1);
4671 vals != NULL_TREE; vals = TREE_CHAIN (vals))
4673 if (TREE_CODE (TREE_VALUE (vals)) != INTEGER_CST
4674 || (TREE_PURPOSE (vals) != NULL_TREE
4675 && TREE_CODE (TREE_PURPOSE (vals)) != INTEGER_CST))
4677 = tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits);
4678 else if (TREE_PURPOSE (vals) != NULL_TREE)
4680 /* Set a range of bits to ones. */
4681 HOST_WIDE_INT lo_index
4682 = TREE_INT_CST_LOW (TREE_PURPOSE (vals)) - domain_min;
4683 HOST_WIDE_INT hi_index
4684 = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min;
4686 if (lo_index < 0 || lo_index >= bit_size
4687 || hi_index < 0 || hi_index >= bit_size)
4689 for (; lo_index <= hi_index; lo_index++)
4690 buffer[lo_index] = 1;
4694 /* Set a single bit to one. */
4696 = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min;
4697 if (index < 0 || index >= bit_size)
4699 error ("invalid initializer for bit string");
4705 return non_const_bits;
4708 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
4709 The result is placed in BUFFER (which is an array of bytes).
4710 If the constructor is constant, NULL_TREE is returned.
4711 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
4714 get_set_constructor_bytes (init, buffer, wd_size)
4716 unsigned char *buffer;
4720 int set_word_size = BITS_PER_UNIT;
4721 int bit_size = wd_size * set_word_size;
4723 unsigned char *bytep = buffer;
4724 char *bit_buffer = (char *) alloca (bit_size);
4725 tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
4727 for (i = 0; i < wd_size; i++)
4730 for (i = 0; i < bit_size; i++)
4734 if (BYTES_BIG_ENDIAN)
4735 *bytep |= (1 << (set_word_size - 1 - bit_pos));
4737 *bytep |= 1 << bit_pos;
4740 if (bit_pos >= set_word_size)
4741 bit_pos = 0, bytep++;
4743 return non_const_bits;
4746 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
4747 /* Complain that the tree code of NODE does not match the expected CODE.
4748 FILE, LINE, and FUNCTION are of the caller. */
4751 tree_check_failed (node, code, file, line, function)
4753 enum tree_code code;
4756 const char *function;
4758 error ("Tree check: expected %s, have %s",
4759 tree_code_name[code], tree_code_name[TREE_CODE (node)]);
4760 fancy_abort (file, line, function);
4763 /* Similar to above, except that we check for a class of tree
4764 code, given in CL. */
4767 tree_class_check_failed (node, cl, file, line, function)
4772 const char *function;
4774 error ("Tree check: expected class '%c', have '%c' (%s)",
4775 cl, TREE_CODE_CLASS (TREE_CODE (node)),
4776 tree_code_name[TREE_CODE (node)]);
4777 fancy_abort (file, line, function);
4780 #endif /* ENABLE_TREE_CHECKING */
4782 /* For a new vector type node T, build the information necessary for
4783 debuggint output. */
4786 finish_vector_type (t)
4792 tree index = build_int_2 (TYPE_VECTOR_SUBPARTS (t) - 1, 0);
4793 tree array = build_array_type (TREE_TYPE (t),
4794 build_index_type (index));
4795 tree rt = make_node (RECORD_TYPE);
4797 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
4798 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
4800 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
4801 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
4802 the representation type, and we want to find that die when looking up
4803 the vector type. This is most easily achieved by making the TYPE_UID
4805 TYPE_UID (rt) = TYPE_UID (t);
4809 /* Create nodes for all integer types (and error_mark_node) using the sizes
4810 of C datatypes. The caller should call set_sizetype soon after calling
4811 this function to select one of the types as sizetype. */
4814 build_common_tree_nodes (signed_char)
4817 error_mark_node = make_node (ERROR_MARK);
4818 TREE_TYPE (error_mark_node) = error_mark_node;
4820 initialize_sizetypes ();
4822 /* Define both `signed char' and `unsigned char'. */
4823 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
4824 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4826 /* Define `char', which is like either `signed char' or `unsigned char'
4827 but not the same as either. */
4830 ? make_signed_type (CHAR_TYPE_SIZE)
4831 : make_unsigned_type (CHAR_TYPE_SIZE));
4833 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
4834 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
4835 integer_type_node = make_signed_type (INT_TYPE_SIZE);
4836 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
4837 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
4838 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
4839 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
4840 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
4842 intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
4843 intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
4844 intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
4845 intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
4846 #if HOST_BITS_PER_WIDE_INT >= 64
4847 intTI_type_node = make_signed_type (GET_MODE_BITSIZE (TImode));
4850 unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
4851 unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
4852 unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
4853 unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
4854 #if HOST_BITS_PER_WIDE_INT >= 64
4855 unsigned_intTI_type_node = make_unsigned_type (GET_MODE_BITSIZE (TImode));
4859 /* Call this function after calling build_common_tree_nodes and set_sizetype.
4860 It will create several other common tree nodes. */
4863 build_common_tree_nodes_2 (short_double)
4866 /* Define these next since types below may used them. */
4867 integer_zero_node = build_int_2 (0, 0);
4868 integer_one_node = build_int_2 (1, 0);
4870 size_zero_node = size_int (0);
4871 size_one_node = size_int (1);
4872 bitsize_zero_node = bitsize_int (0);
4873 bitsize_one_node = bitsize_int (1);
4874 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
4876 void_type_node = make_node (VOID_TYPE);
4877 layout_type (void_type_node);
4879 /* We are not going to have real types in C with less than byte alignment,
4880 so we might as well not have any types that claim to have it. */
4881 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
4882 TYPE_USER_ALIGN (void_type_node) = 0;
4884 null_pointer_node = build_int_2 (0, 0);
4885 TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
4886 layout_type (TREE_TYPE (null_pointer_node));
4888 ptr_type_node = build_pointer_type (void_type_node);
4890 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
4892 float_type_node = make_node (REAL_TYPE);
4893 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
4894 layout_type (float_type_node);
4896 double_type_node = make_node (REAL_TYPE);
4898 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
4900 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
4901 layout_type (double_type_node);
4903 long_double_type_node = make_node (REAL_TYPE);
4904 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
4905 layout_type (long_double_type_node);
4907 complex_integer_type_node = make_node (COMPLEX_TYPE);
4908 TREE_TYPE (complex_integer_type_node) = integer_type_node;
4909 layout_type (complex_integer_type_node);
4911 complex_float_type_node = make_node (COMPLEX_TYPE);
4912 TREE_TYPE (complex_float_type_node) = float_type_node;
4913 layout_type (complex_float_type_node);
4915 complex_double_type_node = make_node (COMPLEX_TYPE);
4916 TREE_TYPE (complex_double_type_node) = double_type_node;
4917 layout_type (complex_double_type_node);
4919 complex_long_double_type_node = make_node (COMPLEX_TYPE);
4920 TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
4921 layout_type (complex_long_double_type_node);
4923 #ifdef BUILD_VA_LIST_TYPE
4924 BUILD_VA_LIST_TYPE (va_list_type_node);
4926 va_list_type_node = ptr_type_node;
4929 V4SF_type_node = make_node (VECTOR_TYPE);
4930 TREE_TYPE (V4SF_type_node) = float_type_node;
4931 TYPE_MODE (V4SF_type_node) = V4SFmode;
4932 finish_vector_type (V4SF_type_node);
4934 V4SI_type_node = make_node (VECTOR_TYPE);
4935 TREE_TYPE (V4SI_type_node) = intSI_type_node;
4936 TYPE_MODE (V4SI_type_node) = V4SImode;
4937 finish_vector_type (V4SI_type_node);
4939 V2SI_type_node = make_node (VECTOR_TYPE);
4940 TREE_TYPE (V2SI_type_node) = intSI_type_node;
4941 TYPE_MODE (V2SI_type_node) = V2SImode;
4942 finish_vector_type (V2SI_type_node);
4944 V4HI_type_node = make_node (VECTOR_TYPE);
4945 TREE_TYPE (V4HI_type_node) = intHI_type_node;
4946 TYPE_MODE (V4HI_type_node) = V4HImode;
4947 finish_vector_type (V4HI_type_node);
4949 V8QI_type_node = make_node (VECTOR_TYPE);
4950 TREE_TYPE (V8QI_type_node) = intQI_type_node;
4951 TYPE_MODE (V8QI_type_node) = V8QImode;
4952 finish_vector_type (V8QI_type_node);