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, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
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. */
34 #include "coretypes.h"
47 #include "langhooks.h"
49 /* obstack.[ch] explicitly declined to prototype this. */
50 extern int _obstack_allocated_p (struct obstack *h, void *obj);
52 #ifdef GATHER_STATISTICS
53 /* Statistics-gathering stuff. */
55 int tree_node_counts[(int) all_kinds];
56 int tree_node_sizes[(int) all_kinds];
58 /* Keep in sync with tree.h:enum tree_node_kind. */
59 static const char * const tree_node_kind_names[] = {
75 #endif /* GATHER_STATISTICS */
77 /* Unique id for next decl created. */
78 static GTY(()) int next_decl_uid;
79 /* Unique id for next type created. */
80 static GTY(()) int next_type_uid = 1;
82 /* Since we cannot rehash a type after it is in the table, we have to
83 keep the hash code. */
85 struct type_hash GTY(())
91 /* Initial size of the hash table (rounded to next prime). */
92 #define TYPE_HASH_INITIAL_SIZE 1000
94 /* Now here is the hash table. When recording a type, it is added to
95 the slot whose index is the hash code. Note that the hash table is
96 used for several kinds of types (function types, array types and
97 array index range types, for now). While all these live in the
98 same table, they are completely independent, and the hash code is
99 computed differently for each of these. */
101 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
102 htab_t type_hash_table;
104 static void set_type_quals (tree, int);
105 static int type_hash_eq (const void *, const void *);
106 static hashval_t type_hash_hash (const void *);
107 static void print_type_hash_statistics (void);
108 static void finish_vector_type (tree);
109 static int type_hash_marked_p (const void *);
111 tree global_trees[TI_MAX];
112 tree integer_types[itk_none];
119 /* Initialize the hash table of types. */
120 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
125 /* The name of the object as the assembler will see it (but before any
126 translations made by ASM_OUTPUT_LABELREF). Often this is the same
127 as DECL_NAME. It is an IDENTIFIER_NODE. */
129 decl_assembler_name (tree decl)
131 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
132 (*lang_hooks.set_decl_assembler_name) (decl);
133 return DECL_CHECK (decl)->decl.assembler_name;
136 /* Compute the number of bytes occupied by 'node'. This routine only
137 looks at TREE_CODE and, if the code is TREE_VEC, TREE_VEC_LENGTH. */
139 tree_size (tree node)
141 enum tree_code code = TREE_CODE (node);
143 switch (TREE_CODE_CLASS (code))
145 case 'd': /* A decl node */
146 return sizeof (struct tree_decl);
148 case 't': /* a type node */
149 return sizeof (struct tree_type);
151 case 'b': /* a lexical block node */
152 return sizeof (struct tree_block);
154 case 'r': /* a reference */
155 case 'e': /* an expression */
156 case 's': /* an expression with side effects */
157 case '<': /* a comparison expression */
158 case '1': /* a unary arithmetic expression */
159 case '2': /* a binary arithmetic expression */
160 return (sizeof (struct tree_exp)
161 + TREE_CODE_LENGTH (code) * sizeof (char *) - sizeof (char *));
163 case 'c': /* a constant */
166 case INTEGER_CST: return sizeof (struct tree_int_cst);
167 case REAL_CST: return sizeof (struct tree_real_cst);
168 case COMPLEX_CST: return sizeof (struct tree_complex);
169 case VECTOR_CST: return sizeof (struct tree_vector);
170 case STRING_CST: return sizeof (struct tree_string);
172 return (*lang_hooks.tree_size) (code);
175 case 'x': /* something random, like an identifier. */
178 case IDENTIFIER_NODE: return lang_hooks.identifier_size;
179 case TREE_LIST: return sizeof (struct tree_list);
180 case TREE_VEC: return (sizeof (struct tree_vec)
181 + TREE_VEC_LENGTH(node) * sizeof(char *)
185 case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
188 return (*lang_hooks.tree_size) (code);
196 /* Return a newly allocated node of code CODE.
197 For decl and type nodes, some other fields are initialized.
198 The rest of the node is initialized to zero.
200 Achoo! I got a code in the node. */
203 make_node (enum tree_code code)
206 int type = TREE_CODE_CLASS (code);
208 #ifdef GATHER_STATISTICS
211 struct tree_common ttmp;
213 /* We can't allocate a TREE_VEC without knowing how many elements
215 if (code == TREE_VEC)
218 TREE_SET_CODE ((tree)&ttmp, code);
219 length = tree_size ((tree)&ttmp);
221 #ifdef GATHER_STATISTICS
224 case 'd': /* A decl node */
228 case 't': /* a type node */
232 case 'b': /* a lexical block */
236 case 's': /* an expression with side effects */
240 case 'r': /* a reference */
244 case 'e': /* an expression */
245 case '<': /* a comparison expression */
246 case '1': /* a unary arithmetic expression */
247 case '2': /* a binary arithmetic expression */
251 case 'c': /* a constant */
255 case 'x': /* something random, like an identifier. */
256 if (code == IDENTIFIER_NODE)
258 else if (code == TREE_VEC)
268 tree_node_counts[(int) kind]++;
269 tree_node_sizes[(int) kind] += length;
272 t = ggc_alloc_tree (length);
274 memset (t, 0, length);
276 TREE_SET_CODE (t, code);
281 TREE_SIDE_EFFECTS (t) = 1;
285 if (code != FUNCTION_DECL)
287 DECL_USER_ALIGN (t) = 0;
288 DECL_IN_SYSTEM_HEADER (t) = in_system_header;
289 DECL_SOURCE_LOCATION (t) = input_location;
290 DECL_UID (t) = next_decl_uid++;
292 /* We have not yet computed the alias set for this declaration. */
293 DECL_POINTER_ALIAS_SET (t) = -1;
297 TYPE_UID (t) = next_type_uid++;
298 TYPE_ALIGN (t) = char_type_node ? TYPE_ALIGN (char_type_node) : 0;
299 TYPE_USER_ALIGN (t) = 0;
300 TYPE_MAIN_VARIANT (t) = t;
302 /* Default to no attributes for type, but let target change that. */
303 TYPE_ATTRIBUTES (t) = NULL_TREE;
304 (*targetm.set_default_type_attributes) (t);
306 /* We have not yet computed the alias set for this type. */
307 TYPE_ALIAS_SET (t) = -1;
311 TREE_CONSTANT (t) = 1;
321 case PREDECREMENT_EXPR:
322 case PREINCREMENT_EXPR:
323 case POSTDECREMENT_EXPR:
324 case POSTINCREMENT_EXPR:
325 /* All of these have side-effects, no matter what their
327 TREE_SIDE_EFFECTS (t) = 1;
339 /* Return a new node with the same contents as NODE except that its
340 TREE_CHAIN is zero and it has a fresh uid. */
343 copy_node (tree node)
346 enum tree_code code = TREE_CODE (node);
349 length = tree_size (node);
350 t = ggc_alloc_tree (length);
351 memcpy (t, node, length);
354 TREE_ASM_WRITTEN (t) = 0;
356 if (TREE_CODE_CLASS (code) == 'd')
357 DECL_UID (t) = next_decl_uid++;
358 else if (TREE_CODE_CLASS (code) == 't')
360 TYPE_UID (t) = next_type_uid++;
361 /* The following is so that the debug code for
362 the copy is different from the original type.
363 The two statements usually duplicate each other
364 (because they clear fields of the same union),
365 but the optimizer should catch that. */
366 TYPE_SYMTAB_POINTER (t) = 0;
367 TYPE_SYMTAB_ADDRESS (t) = 0;
373 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
374 For example, this can copy a list made of TREE_LIST nodes. */
377 copy_list (tree list)
385 head = prev = copy_node (list);
386 next = TREE_CHAIN (list);
389 TREE_CHAIN (prev) = copy_node (next);
390 prev = TREE_CHAIN (prev);
391 next = TREE_CHAIN (next);
397 /* Return a newly constructed INTEGER_CST node whose constant value
398 is specified by the two ints LOW and HI.
399 The TREE_TYPE is set to `int'.
401 This function should be used via the `build_int_2' macro. */
404 build_int_2_wide (unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
406 tree t = make_node (INTEGER_CST);
408 TREE_INT_CST_LOW (t) = low;
409 TREE_INT_CST_HIGH (t) = hi;
410 TREE_TYPE (t) = integer_type_node;
414 /* Return a new VECTOR_CST node whose type is TYPE and whose values
415 are in a list pointed by VALS. */
418 build_vector (tree type, tree vals)
420 tree v = make_node (VECTOR_CST);
421 int over1 = 0, over2 = 0;
424 TREE_VECTOR_CST_ELTS (v) = vals;
425 TREE_TYPE (v) = type;
427 /* Iterate through elements and check for overflow. */
428 for (link = vals; link; link = TREE_CHAIN (link))
430 tree value = TREE_VALUE (link);
432 over1 |= TREE_OVERFLOW (value);
433 over2 |= TREE_CONSTANT_OVERFLOW (value);
436 TREE_OVERFLOW (v) = over1;
437 TREE_CONSTANT_OVERFLOW (v) = over2;
442 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
443 are in a list pointed to by VALS. */
445 build_constructor (tree type, tree vals)
447 tree c = make_node (CONSTRUCTOR);
448 TREE_TYPE (c) = type;
449 CONSTRUCTOR_ELTS (c) = vals;
451 /* ??? May not be necessary. Mirrors what build does. */
454 TREE_SIDE_EFFECTS (c) = TREE_SIDE_EFFECTS (vals);
455 TREE_READONLY (c) = TREE_READONLY (vals);
456 TREE_CONSTANT (c) = TREE_CONSTANT (vals);
459 TREE_CONSTANT (c) = 0; /* safe side */
464 /* Return a new REAL_CST node whose type is TYPE and value is D. */
467 build_real (tree type, REAL_VALUE_TYPE d)
473 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
474 Consider doing it via real_convert now. */
476 v = make_node (REAL_CST);
477 dp = ggc_alloc (sizeof (REAL_VALUE_TYPE));
478 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
480 TREE_TYPE (v) = type;
481 TREE_REAL_CST_PTR (v) = dp;
482 TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
486 /* Return a new REAL_CST node whose type is TYPE
487 and whose value is the integer value of the INTEGER_CST node I. */
490 real_value_from_int_cst (tree type, tree i)
494 /* Clear all bits of the real value type so that we can later do
495 bitwise comparisons to see if two values are the same. */
496 memset (&d, 0, sizeof d);
498 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
499 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
500 TREE_UNSIGNED (TREE_TYPE (i)));
504 /* Given a tree representing an integer constant I, return a tree
505 representing the same value as a floating-point constant of type TYPE. */
508 build_real_from_int_cst (tree type, tree i)
511 int overflow = TREE_OVERFLOW (i);
513 v = build_real (type, real_value_from_int_cst (type, i));
515 TREE_OVERFLOW (v) |= overflow;
516 TREE_CONSTANT_OVERFLOW (v) |= overflow;
520 /* Return a newly constructed STRING_CST node whose value is
521 the LEN characters at STR.
522 The TREE_TYPE is not initialized. */
525 build_string (int len, const char *str)
527 tree s = make_node (STRING_CST);
529 TREE_STRING_LENGTH (s) = len;
530 TREE_STRING_POINTER (s) = ggc_alloc_string (str, len);
535 /* Return a newly constructed COMPLEX_CST node whose value is
536 specified by the real and imaginary parts REAL and IMAG.
537 Both REAL and IMAG should be constant nodes. TYPE, if specified,
538 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
541 build_complex (tree type, tree real, tree imag)
543 tree t = make_node (COMPLEX_CST);
545 TREE_REALPART (t) = real;
546 TREE_IMAGPART (t) = imag;
547 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
548 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
549 TREE_CONSTANT_OVERFLOW (t)
550 = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
554 /* Build a newly constructed TREE_VEC node of length LEN. */
557 make_tree_vec (int len)
560 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
562 #ifdef GATHER_STATISTICS
563 tree_node_counts[(int) vec_kind]++;
564 tree_node_sizes[(int) vec_kind] += length;
567 t = ggc_alloc_tree (length);
569 memset (t, 0, length);
570 TREE_SET_CODE (t, TREE_VEC);
571 TREE_VEC_LENGTH (t) = len;
576 /* Return 1 if EXPR is the integer constant zero or a complex constant
580 integer_zerop (tree expr)
584 return ((TREE_CODE (expr) == INTEGER_CST
585 && ! TREE_CONSTANT_OVERFLOW (expr)
586 && TREE_INT_CST_LOW (expr) == 0
587 && TREE_INT_CST_HIGH (expr) == 0)
588 || (TREE_CODE (expr) == COMPLEX_CST
589 && integer_zerop (TREE_REALPART (expr))
590 && integer_zerop (TREE_IMAGPART (expr))));
593 /* Return 1 if EXPR is the integer constant one or the corresponding
597 integer_onep (tree expr)
601 return ((TREE_CODE (expr) == INTEGER_CST
602 && ! TREE_CONSTANT_OVERFLOW (expr)
603 && TREE_INT_CST_LOW (expr) == 1
604 && TREE_INT_CST_HIGH (expr) == 0)
605 || (TREE_CODE (expr) == COMPLEX_CST
606 && integer_onep (TREE_REALPART (expr))
607 && integer_zerop (TREE_IMAGPART (expr))));
610 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
611 it contains. Likewise for the corresponding complex constant. */
614 integer_all_onesp (tree expr)
621 if (TREE_CODE (expr) == COMPLEX_CST
622 && integer_all_onesp (TREE_REALPART (expr))
623 && integer_zerop (TREE_IMAGPART (expr)))
626 else if (TREE_CODE (expr) != INTEGER_CST
627 || TREE_CONSTANT_OVERFLOW (expr))
630 uns = TREE_UNSIGNED (TREE_TYPE (expr));
632 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
633 && TREE_INT_CST_HIGH (expr) == -1);
635 /* Note that using TYPE_PRECISION here is wrong. We care about the
636 actual bits, not the (arbitrary) range of the type. */
637 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
638 if (prec >= HOST_BITS_PER_WIDE_INT)
640 HOST_WIDE_INT high_value;
643 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
645 if (shift_amount > HOST_BITS_PER_WIDE_INT)
646 /* Can not handle precisions greater than twice the host int size. */
648 else if (shift_amount == HOST_BITS_PER_WIDE_INT)
649 /* Shifting by the host word size is undefined according to the ANSI
650 standard, so we must handle this as a special case. */
653 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
655 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
656 && TREE_INT_CST_HIGH (expr) == high_value);
659 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
662 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
666 integer_pow2p (tree expr)
669 HOST_WIDE_INT high, low;
673 if (TREE_CODE (expr) == COMPLEX_CST
674 && integer_pow2p (TREE_REALPART (expr))
675 && integer_zerop (TREE_IMAGPART (expr)))
678 if (TREE_CODE (expr) != INTEGER_CST || TREE_CONSTANT_OVERFLOW (expr))
681 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
682 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
683 high = TREE_INT_CST_HIGH (expr);
684 low = TREE_INT_CST_LOW (expr);
686 /* First clear all bits that are beyond the type's precision in case
687 we've been sign extended. */
689 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
691 else if (prec > HOST_BITS_PER_WIDE_INT)
692 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
696 if (prec < HOST_BITS_PER_WIDE_INT)
697 low &= ~((HOST_WIDE_INT) (-1) << prec);
700 if (high == 0 && low == 0)
703 return ((high == 0 && (low & (low - 1)) == 0)
704 || (low == 0 && (high & (high - 1)) == 0));
707 /* Return 1 if EXPR is an integer constant other than zero or a
708 complex constant other than zero. */
711 integer_nonzerop (tree expr)
715 return ((TREE_CODE (expr) == INTEGER_CST
716 && ! TREE_CONSTANT_OVERFLOW (expr)
717 && (TREE_INT_CST_LOW (expr) != 0
718 || TREE_INT_CST_HIGH (expr) != 0))
719 || (TREE_CODE (expr) == COMPLEX_CST
720 && (integer_nonzerop (TREE_REALPART (expr))
721 || integer_nonzerop (TREE_IMAGPART (expr)))));
724 /* Return the power of two represented by a tree node known to be a
728 tree_log2 (tree expr)
731 HOST_WIDE_INT high, low;
735 if (TREE_CODE (expr) == COMPLEX_CST)
736 return tree_log2 (TREE_REALPART (expr));
738 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
739 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
741 high = TREE_INT_CST_HIGH (expr);
742 low = TREE_INT_CST_LOW (expr);
744 /* First clear all bits that are beyond the type's precision in case
745 we've been sign extended. */
747 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
749 else if (prec > HOST_BITS_PER_WIDE_INT)
750 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
754 if (prec < HOST_BITS_PER_WIDE_INT)
755 low &= ~((HOST_WIDE_INT) (-1) << prec);
758 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
762 /* Similar, but return the largest integer Y such that 2 ** Y is less
763 than or equal to EXPR. */
766 tree_floor_log2 (tree expr)
769 HOST_WIDE_INT high, low;
773 if (TREE_CODE (expr) == COMPLEX_CST)
774 return tree_log2 (TREE_REALPART (expr));
776 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
777 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
779 high = TREE_INT_CST_HIGH (expr);
780 low = TREE_INT_CST_LOW (expr);
782 /* First clear all bits that are beyond the type's precision in case
783 we've been sign extended. Ignore if type's precision hasn't been set
784 since what we are doing is setting it. */
786 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
788 else if (prec > HOST_BITS_PER_WIDE_INT)
789 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
793 if (prec < HOST_BITS_PER_WIDE_INT)
794 low &= ~((HOST_WIDE_INT) (-1) << prec);
797 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
801 /* Return 1 if EXPR is the real constant zero. */
804 real_zerop (tree expr)
808 return ((TREE_CODE (expr) == REAL_CST
809 && ! TREE_CONSTANT_OVERFLOW (expr)
810 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
811 || (TREE_CODE (expr) == COMPLEX_CST
812 && real_zerop (TREE_REALPART (expr))
813 && real_zerop (TREE_IMAGPART (expr))));
816 /* Return 1 if EXPR is the real constant one in real or complex form. */
819 real_onep (tree expr)
823 return ((TREE_CODE (expr) == REAL_CST
824 && ! TREE_CONSTANT_OVERFLOW (expr)
825 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
826 || (TREE_CODE (expr) == COMPLEX_CST
827 && real_onep (TREE_REALPART (expr))
828 && real_zerop (TREE_IMAGPART (expr))));
831 /* Return 1 if EXPR is the real constant two. */
834 real_twop (tree expr)
838 return ((TREE_CODE (expr) == REAL_CST
839 && ! TREE_CONSTANT_OVERFLOW (expr)
840 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
841 || (TREE_CODE (expr) == COMPLEX_CST
842 && real_twop (TREE_REALPART (expr))
843 && real_zerop (TREE_IMAGPART (expr))));
846 /* Return 1 if EXPR is the real constant minus one. */
849 real_minus_onep (tree expr)
853 return ((TREE_CODE (expr) == REAL_CST
854 && ! TREE_CONSTANT_OVERFLOW (expr)
855 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1))
856 || (TREE_CODE (expr) == COMPLEX_CST
857 && real_minus_onep (TREE_REALPART (expr))
858 && real_zerop (TREE_IMAGPART (expr))));
861 /* Nonzero if EXP is a constant or a cast of a constant. */
864 really_constant_p (tree exp)
866 /* This is not quite the same as STRIP_NOPS. It does more. */
867 while (TREE_CODE (exp) == NOP_EXPR
868 || TREE_CODE (exp) == CONVERT_EXPR
869 || TREE_CODE (exp) == NON_LVALUE_EXPR)
870 exp = TREE_OPERAND (exp, 0);
871 return TREE_CONSTANT (exp);
874 /* Return first list element whose TREE_VALUE is ELEM.
875 Return 0 if ELEM is not in LIST. */
878 value_member (tree elem, tree list)
882 if (elem == TREE_VALUE (list))
884 list = TREE_CHAIN (list);
889 /* Return first list element whose TREE_PURPOSE is ELEM.
890 Return 0 if ELEM is not in LIST. */
893 purpose_member (tree elem, tree list)
897 if (elem == TREE_PURPOSE (list))
899 list = TREE_CHAIN (list);
904 /* Return first list element whose BINFO_TYPE is ELEM.
905 Return 0 if ELEM is not in LIST. */
908 binfo_member (tree elem, tree list)
912 if (elem == BINFO_TYPE (list))
914 list = TREE_CHAIN (list);
919 /* Return nonzero if ELEM is part of the chain CHAIN. */
922 chain_member (tree elem, tree chain)
928 chain = TREE_CHAIN (chain);
934 /* Return the length of a chain of nodes chained through TREE_CHAIN.
935 We expect a null pointer to mark the end of the chain.
936 This is the Lisp primitive `length'. */
944 for (tail = t; tail; tail = TREE_CHAIN (tail))
950 /* Returns the number of FIELD_DECLs in TYPE. */
953 fields_length (tree type)
955 tree t = TYPE_FIELDS (type);
958 for (; t; t = TREE_CHAIN (t))
959 if (TREE_CODE (t) == FIELD_DECL)
965 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
966 by modifying the last node in chain 1 to point to chain 2.
967 This is the Lisp primitive `nconc'. */
970 chainon (tree op1, tree op2)
979 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
981 TREE_CHAIN (t1) = op2;
983 #ifdef ENABLE_TREE_CHECKING
986 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
988 abort (); /* Circularity created. */
995 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
998 tree_last (tree chain)
1002 while ((next = TREE_CHAIN (chain)))
1007 /* Reverse the order of elements in the chain T,
1008 and return the new head of the chain (old last element). */
1013 tree prev = 0, decl, next;
1014 for (decl = t; decl; decl = next)
1016 next = TREE_CHAIN (decl);
1017 TREE_CHAIN (decl) = prev;
1023 /* Return a newly created TREE_LIST node whose
1024 purpose and value fields are PARM and VALUE. */
1027 build_tree_list (tree parm, tree value)
1029 tree t = make_node (TREE_LIST);
1030 TREE_PURPOSE (t) = parm;
1031 TREE_VALUE (t) = value;
1035 /* Return a newly created TREE_LIST node whose
1036 purpose and value fields are PURPOSE and VALUE
1037 and whose TREE_CHAIN is CHAIN. */
1040 tree_cons (tree purpose, tree value, tree chain)
1044 node = ggc_alloc_tree (sizeof (struct tree_list));
1046 memset (node, 0, sizeof (struct tree_common));
1048 #ifdef GATHER_STATISTICS
1049 tree_node_counts[(int) x_kind]++;
1050 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
1053 TREE_SET_CODE (node, TREE_LIST);
1054 TREE_CHAIN (node) = chain;
1055 TREE_PURPOSE (node) = purpose;
1056 TREE_VALUE (node) = value;
1060 /* Return the first expression in a sequence of COMPOUND_EXPRs. */
1063 expr_first (tree expr)
1065 if (expr == NULL_TREE)
1067 while (TREE_CODE (expr) == COMPOUND_EXPR)
1068 expr = TREE_OPERAND (expr, 0);
1072 /* Return the last expression in a sequence of COMPOUND_EXPRs. */
1075 expr_last (tree expr)
1077 if (expr == NULL_TREE)
1079 while (TREE_CODE (expr) == COMPOUND_EXPR)
1080 expr = TREE_OPERAND (expr, 1);
1084 /* Return the number of subexpressions in a sequence of COMPOUND_EXPRs. */
1087 expr_length (tree expr)
1091 if (expr == NULL_TREE)
1093 for (; TREE_CODE (expr) == COMPOUND_EXPR; expr = TREE_OPERAND (expr, 1))
1094 len += expr_length (TREE_OPERAND (expr, 0));
1099 /* Return the size nominally occupied by an object of type TYPE
1100 when it resides in memory. The value is measured in units of bytes,
1101 and its data type is that normally used for type sizes
1102 (which is the first type created by make_signed_type or
1103 make_unsigned_type). */
1106 size_in_bytes (tree type)
1110 if (type == error_mark_node)
1111 return integer_zero_node;
1113 type = TYPE_MAIN_VARIANT (type);
1114 t = TYPE_SIZE_UNIT (type);
1118 (*lang_hooks.types.incomplete_type_error) (NULL_TREE, type);
1119 return size_zero_node;
1122 if (TREE_CODE (t) == INTEGER_CST)
1123 force_fit_type (t, 0);
1128 /* Return the size of TYPE (in bytes) as a wide integer
1129 or return -1 if the size can vary or is larger than an integer. */
1132 int_size_in_bytes (tree type)
1136 if (type == error_mark_node)
1139 type = TYPE_MAIN_VARIANT (type);
1140 t = TYPE_SIZE_UNIT (type);
1142 || TREE_CODE (t) != INTEGER_CST
1143 || TREE_OVERFLOW (t)
1144 || TREE_INT_CST_HIGH (t) != 0
1145 /* If the result would appear negative, it's too big to represent. */
1146 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
1149 return TREE_INT_CST_LOW (t);
1152 /* Return the bit position of FIELD, in bits from the start of the record.
1153 This is a tree of type bitsizetype. */
1156 bit_position (tree field)
1158 return bit_from_pos (DECL_FIELD_OFFSET (field),
1159 DECL_FIELD_BIT_OFFSET (field));
1162 /* Likewise, but return as an integer. Abort if it cannot be represented
1163 in that way (since it could be a signed value, we don't have the option
1164 of returning -1 like int_size_in_byte can. */
1167 int_bit_position (tree field)
1169 return tree_low_cst (bit_position (field), 0);
1172 /* Return the byte position of FIELD, in bytes from the start of the record.
1173 This is a tree of type sizetype. */
1176 byte_position (tree field)
1178 return byte_from_pos (DECL_FIELD_OFFSET (field),
1179 DECL_FIELD_BIT_OFFSET (field));
1182 /* Likewise, but return as an integer. Abort if it cannot be represented
1183 in that way (since it could be a signed value, we don't have the option
1184 of returning -1 like int_size_in_byte can. */
1187 int_byte_position (tree field)
1189 return tree_low_cst (byte_position (field), 0);
1192 /* Return the strictest alignment, in bits, that T is known to have. */
1197 unsigned int align0, align1;
1199 switch (TREE_CODE (t))
1201 case NOP_EXPR: case CONVERT_EXPR: case NON_LVALUE_EXPR:
1202 /* If we have conversions, we know that the alignment of the
1203 object must meet each of the alignments of the types. */
1204 align0 = expr_align (TREE_OPERAND (t, 0));
1205 align1 = TYPE_ALIGN (TREE_TYPE (t));
1206 return MAX (align0, align1);
1208 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
1209 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
1210 case WITH_RECORD_EXPR: case CLEANUP_POINT_EXPR: case UNSAVE_EXPR:
1211 /* These don't change the alignment of an object. */
1212 return expr_align (TREE_OPERAND (t, 0));
1215 /* The best we can do is say that the alignment is the least aligned
1217 align0 = expr_align (TREE_OPERAND (t, 1));
1218 align1 = expr_align (TREE_OPERAND (t, 2));
1219 return MIN (align0, align1);
1221 case LABEL_DECL: case CONST_DECL:
1222 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
1223 if (DECL_ALIGN (t) != 0)
1224 return DECL_ALIGN (t);
1228 return FUNCTION_BOUNDARY;
1234 /* Otherwise take the alignment from that of the type. */
1235 return TYPE_ALIGN (TREE_TYPE (t));
1238 /* Return, as a tree node, the number of elements for TYPE (which is an
1239 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1242 array_type_nelts (tree type)
1244 tree index_type, min, max;
1246 /* If they did it with unspecified bounds, then we should have already
1247 given an error about it before we got here. */
1248 if (! TYPE_DOMAIN (type))
1249 return error_mark_node;
1251 index_type = TYPE_DOMAIN (type);
1252 min = TYPE_MIN_VALUE (index_type);
1253 max = TYPE_MAX_VALUE (index_type);
1255 return (integer_zerop (min)
1257 : fold (build (MINUS_EXPR, TREE_TYPE (max), max, min)));
1260 /* Return nonzero if arg is static -- a reference to an object in
1261 static storage. This is not the same as the C meaning of `static'. */
1266 switch (TREE_CODE (arg))
1269 /* Nested functions aren't static, since taking their address
1270 involves a trampoline. */
1271 return ((decl_function_context (arg) == 0 || DECL_NO_STATIC_CHAIN (arg))
1272 && ! DECL_NON_ADDR_CONST_P (arg));
1275 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
1276 && ! DECL_THREAD_LOCAL (arg)
1277 && ! DECL_NON_ADDR_CONST_P (arg));
1280 return TREE_STATIC (arg);
1286 /* If we are referencing a bitfield, we can't evaluate an
1287 ADDR_EXPR at compile time and so it isn't a constant. */
1289 return (! DECL_BIT_FIELD (TREE_OPERAND (arg, 1))
1290 && staticp (TREE_OPERAND (arg, 0)));
1296 /* This case is technically correct, but results in setting
1297 TREE_CONSTANT on ADDR_EXPRs that cannot be evaluated at
1300 return TREE_CONSTANT (TREE_OPERAND (arg, 0));
1304 case ARRAY_RANGE_REF:
1305 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
1306 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
1307 return staticp (TREE_OPERAND (arg, 0));
1310 if ((unsigned int) TREE_CODE (arg)
1311 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
1312 return (*lang_hooks.staticp) (arg);
1318 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
1319 Do this to any expression which may be used in more than one place,
1320 but must be evaluated only once.
1322 Normally, expand_expr would reevaluate the expression each time.
1323 Calling save_expr produces something that is evaluated and recorded
1324 the first time expand_expr is called on it. Subsequent calls to
1325 expand_expr just reuse the recorded value.
1327 The call to expand_expr that generates code that actually computes
1328 the value is the first call *at compile time*. Subsequent calls
1329 *at compile time* generate code to use the saved value.
1330 This produces correct result provided that *at run time* control
1331 always flows through the insns made by the first expand_expr
1332 before reaching the other places where the save_expr was evaluated.
1333 You, the caller of save_expr, must make sure this is so.
1335 Constants, and certain read-only nodes, are returned with no
1336 SAVE_EXPR because that is safe. Expressions containing placeholders
1337 are not touched; see tree.def for an explanation of what these
1341 save_expr (tree expr)
1343 tree t = fold (expr);
1346 /* If the tree evaluates to a constant, then we don't want to hide that
1347 fact (i.e. this allows further folding, and direct checks for constants).
1348 However, a read-only object that has side effects cannot be bypassed.
1349 Since it is no problem to reevaluate literals, we just return the
1351 inner = skip_simple_arithmetic (t);
1352 if (TREE_CONSTANT (inner)
1353 || (TREE_READONLY (inner) && ! TREE_SIDE_EFFECTS (inner))
1354 || TREE_CODE (inner) == SAVE_EXPR
1355 || TREE_CODE (inner) == ERROR_MARK)
1358 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
1359 it means that the size or offset of some field of an object depends on
1360 the value within another field.
1362 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
1363 and some variable since it would then need to be both evaluated once and
1364 evaluated more than once. Front-ends must assure this case cannot
1365 happen by surrounding any such subexpressions in their own SAVE_EXPR
1366 and forcing evaluation at the proper time. */
1367 if (contains_placeholder_p (inner))
1370 t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE);
1372 /* This expression might be placed ahead of a jump to ensure that the
1373 value was computed on both sides of the jump. So make sure it isn't
1374 eliminated as dead. */
1375 TREE_SIDE_EFFECTS (t) = 1;
1376 TREE_READONLY (t) = 1;
1380 /* Look inside EXPR and into any simple arithmetic operations. Return
1381 the innermost non-arithmetic node. */
1384 skip_simple_arithmetic (tree expr)
1388 /* We don't care about whether this can be used as an lvalue in this
1390 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
1391 expr = TREE_OPERAND (expr, 0);
1393 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
1394 a constant, it will be more efficient to not make another SAVE_EXPR since
1395 it will allow better simplification and GCSE will be able to merge the
1396 computations if they actually occur. */
1400 if (TREE_CODE_CLASS (TREE_CODE (inner)) == '1')
1401 inner = TREE_OPERAND (inner, 0);
1402 else if (TREE_CODE_CLASS (TREE_CODE (inner)) == '2')
1404 if (TREE_CONSTANT (TREE_OPERAND (inner, 1)))
1405 inner = TREE_OPERAND (inner, 0);
1406 else if (TREE_CONSTANT (TREE_OPERAND (inner, 0)))
1407 inner = TREE_OPERAND (inner, 1);
1418 /* Return TRUE if EXPR is a SAVE_EXPR or wraps simple arithmetic around a
1419 SAVE_EXPR. Return FALSE otherwise. */
1422 saved_expr_p (tree expr)
1424 return TREE_CODE (skip_simple_arithmetic (expr)) == SAVE_EXPR;
1427 /* Arrange for an expression to be expanded multiple independent
1428 times. This is useful for cleanup actions, as the backend can
1429 expand them multiple times in different places. */
1432 unsave_expr (tree expr)
1436 /* If this is already protected, no sense in protecting it again. */
1437 if (TREE_CODE (expr) == UNSAVE_EXPR)
1440 t = build1 (UNSAVE_EXPR, TREE_TYPE (expr), expr);
1441 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (expr);
1445 /* Returns the index of the first non-tree operand for CODE, or the number
1446 of operands if all are trees. */
1449 first_rtl_op (enum tree_code code)
1455 case GOTO_SUBROUTINE_EXPR:
1458 case WITH_CLEANUP_EXPR:
1461 return TREE_CODE_LENGTH (code);
1465 /* Return which tree structure is used by T. */
1467 enum tree_node_structure_enum
1468 tree_node_structure (tree t)
1470 enum tree_code code = TREE_CODE (t);
1472 switch (TREE_CODE_CLASS (code))
1474 case 'd': return TS_DECL;
1475 case 't': return TS_TYPE;
1476 case 'b': return TS_BLOCK;
1477 case 'r': case '<': case '1': case '2': case 'e': case 's':
1479 default: /* 'c' and 'x' */
1485 case INTEGER_CST: return TS_INT_CST;
1486 case REAL_CST: return TS_REAL_CST;
1487 case COMPLEX_CST: return TS_COMPLEX;
1488 case VECTOR_CST: return TS_VECTOR;
1489 case STRING_CST: return TS_STRING;
1491 case ERROR_MARK: return TS_COMMON;
1492 case IDENTIFIER_NODE: return TS_IDENTIFIER;
1493 case TREE_LIST: return TS_LIST;
1494 case TREE_VEC: return TS_VEC;
1495 case PLACEHOLDER_EXPR: return TS_COMMON;
1502 /* Perform any modifications to EXPR required when it is unsaved. Does
1503 not recurse into EXPR's subtrees. */
1506 unsave_expr_1 (tree expr)
1508 switch (TREE_CODE (expr))
1511 if (! SAVE_EXPR_PERSISTENT_P (expr))
1512 SAVE_EXPR_RTL (expr) = 0;
1516 /* Don't mess with a TARGET_EXPR that hasn't been expanded.
1517 It's OK for this to happen if it was part of a subtree that
1518 isn't immediately expanded, such as operand 2 of another
1520 if (TREE_OPERAND (expr, 1))
1523 TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 3);
1524 TREE_OPERAND (expr, 3) = NULL_TREE;
1528 /* I don't yet know how to emit a sequence multiple times. */
1529 if (RTL_EXPR_SEQUENCE (expr) != 0)
1538 /* Default lang hook for "unsave_expr_now". */
1541 lhd_unsave_expr_now (tree expr)
1543 enum tree_code code;
1545 /* There's nothing to do for NULL_TREE. */
1549 unsave_expr_1 (expr);
1551 code = TREE_CODE (expr);
1552 switch (TREE_CODE_CLASS (code))
1554 case 'c': /* a constant */
1555 case 't': /* a type node */
1556 case 'd': /* A decl node */
1557 case 'b': /* A block node */
1560 case 'x': /* miscellaneous: e.g., identifier, TREE_LIST or ERROR_MARK. */
1561 if (code == TREE_LIST)
1563 lhd_unsave_expr_now (TREE_VALUE (expr));
1564 lhd_unsave_expr_now (TREE_CHAIN (expr));
1568 case 'e': /* an expression */
1569 case 'r': /* a reference */
1570 case 's': /* an expression with side effects */
1571 case '<': /* a comparison expression */
1572 case '2': /* a binary arithmetic expression */
1573 case '1': /* a unary arithmetic expression */
1577 for (i = first_rtl_op (code) - 1; i >= 0; i--)
1578 lhd_unsave_expr_now (TREE_OPERAND (expr, i));
1589 /* Return 0 if it is safe to evaluate EXPR multiple times,
1590 return 1 if it is safe if EXPR is unsaved afterward, or
1591 return 2 if it is completely unsafe.
1593 This assumes that CALL_EXPRs and TARGET_EXPRs are never replicated in
1594 an expression tree, so that it safe to unsave them and the surrounding
1595 context will be correct.
1597 SAVE_EXPRs basically *only* appear replicated in an expression tree,
1598 occasionally across the whole of a function. It is therefore only
1599 safe to unsave a SAVE_EXPR if you know that all occurrences appear
1600 below the UNSAVE_EXPR.
1602 RTL_EXPRs consume their rtl during evaluation. It is therefore
1603 never possible to unsave them. */
1606 unsafe_for_reeval (tree expr)
1609 enum tree_code code;
1614 if (expr == NULL_TREE)
1617 code = TREE_CODE (expr);
1618 first_rtl = first_rtl_op (code);
1627 for (exp = expr; exp != 0; exp = TREE_CHAIN (exp))
1629 tmp = unsafe_for_reeval (TREE_VALUE (exp));
1630 unsafeness = MAX (tmp, unsafeness);
1636 tmp2 = unsafe_for_reeval (TREE_OPERAND (expr, 0));
1637 tmp = unsafe_for_reeval (TREE_OPERAND (expr, 1));
1638 return MAX (MAX (tmp, 1), tmp2);
1644 case EXIT_BLOCK_EXPR:
1645 /* EXIT_BLOCK_LABELED_BLOCK, a.k.a. TREE_OPERAND (expr, 0), holds
1646 a reference to an ancestor LABELED_BLOCK, so we need to avoid
1647 unbounded recursion in the 'e' traversal code below. */
1648 exp = EXIT_BLOCK_RETURN (expr);
1649 return exp ? unsafe_for_reeval (exp) : 0;
1652 tmp = (*lang_hooks.unsafe_for_reeval) (expr);
1658 switch (TREE_CODE_CLASS (code))
1660 case 'c': /* a constant */
1661 case 't': /* a type node */
1662 case 'x': /* something random, like an identifier or an ERROR_MARK. */
1663 case 'd': /* A decl node */
1664 case 'b': /* A block node */
1667 case 'e': /* an expression */
1668 case 'r': /* a reference */
1669 case 's': /* an expression with side effects */
1670 case '<': /* a comparison expression */
1671 case '2': /* a binary arithmetic expression */
1672 case '1': /* a unary arithmetic expression */
1673 for (i = first_rtl - 1; i >= 0; i--)
1675 tmp = unsafe_for_reeval (TREE_OPERAND (expr, i));
1676 unsafeness = MAX (tmp, unsafeness);
1686 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
1687 or offset that depends on a field within a record. */
1690 contains_placeholder_p (tree exp)
1692 enum tree_code code;
1698 /* If we have a WITH_RECORD_EXPR, it "cancels" any PLACEHOLDER_EXPR
1699 in it since it is supplying a value for it. */
1700 code = TREE_CODE (exp);
1701 if (code == WITH_RECORD_EXPR)
1703 else if (code == PLACEHOLDER_EXPR)
1706 switch (TREE_CODE_CLASS (code))
1709 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
1710 position computations since they will be converted into a
1711 WITH_RECORD_EXPR involving the reference, which will assume
1712 here will be valid. */
1713 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
1716 if (code == TREE_LIST)
1717 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
1718 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
1727 /* Ignoring the first operand isn't quite right, but works best. */
1728 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
1735 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
1736 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
1737 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
1740 /* If we already know this doesn't have a placeholder, don't
1742 if (SAVE_EXPR_NOPLACEHOLDER (exp) || SAVE_EXPR_RTL (exp) != 0)
1745 SAVE_EXPR_NOPLACEHOLDER (exp) = 1;
1746 result = CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
1748 SAVE_EXPR_NOPLACEHOLDER (exp) = 0;
1753 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
1759 switch (TREE_CODE_LENGTH (code))
1762 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
1764 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
1765 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
1776 /* Return 1 if any part of the computation of TYPE involves a PLACEHOLDER_EXPR.
1777 This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and field
1781 type_contains_placeholder_p (tree type)
1783 /* If the size contains a placeholder or the parent type (component type in
1784 the case of arrays) type involves a placeholder, this type does. */
1785 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
1786 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
1787 || (TREE_TYPE (type) != 0
1788 && type_contains_placeholder_p (TREE_TYPE (type))))
1791 /* Now do type-specific checks. Note that the last part of the check above
1792 greatly limits what we have to do below. */
1793 switch (TREE_CODE (type))
1803 case REFERENCE_TYPE:
1811 /* Here we just check the bounds. */
1812 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
1813 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
1817 /* We're already checked the component type (TREE_TYPE), so just check
1819 return type_contains_placeholder_p (TYPE_DOMAIN (type));
1823 case QUAL_UNION_TYPE:
1825 static tree seen_types = 0;
1829 /* We have to be careful here that we don't end up in infinite
1830 recursions due to a field of a type being a pointer to that type
1831 or to a mutually-recursive type. So we store a list of record
1832 types that we've seen and see if this type is in them. To save
1833 memory, we don't use a list for just one type. Here we check
1834 whether we've seen this type before and store it if not. */
1835 if (seen_types == 0)
1837 else if (TREE_CODE (seen_types) != TREE_LIST)
1839 if (seen_types == type)
1842 seen_types = tree_cons (NULL_TREE, type,
1843 build_tree_list (NULL_TREE, seen_types));
1847 if (value_member (type, seen_types) != 0)
1850 seen_types = tree_cons (NULL_TREE, type, seen_types);
1853 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1854 if (TREE_CODE (field) == FIELD_DECL
1855 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
1856 || (TREE_CODE (type) == QUAL_UNION_TYPE
1857 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
1858 || type_contains_placeholder_p (TREE_TYPE (field))))
1864 /* Now remove us from seen_types and return the result. */
1865 if (seen_types == type)
1868 seen_types = TREE_CHAIN (seen_types);
1878 /* Return 1 if EXP contains any expressions that produce cleanups for an
1879 outer scope to deal with. Used by fold. */
1882 has_cleanups (tree exp)
1886 if (! TREE_SIDE_EFFECTS (exp))
1889 switch (TREE_CODE (exp))
1892 case GOTO_SUBROUTINE_EXPR:
1893 case WITH_CLEANUP_EXPR:
1896 case CLEANUP_POINT_EXPR:
1900 for (exp = TREE_OPERAND (exp, 1); exp; exp = TREE_CHAIN (exp))
1902 cmp = has_cleanups (TREE_VALUE (exp));
1912 /* This general rule works for most tree codes. All exceptions should be
1913 handled above. If this is a language-specific tree code, we can't
1914 trust what might be in the operand, so say we don't know
1916 if ((int) TREE_CODE (exp) >= (int) LAST_AND_UNUSED_TREE_CODE)
1919 nops = first_rtl_op (TREE_CODE (exp));
1920 for (i = 0; i < nops; i++)
1921 if (TREE_OPERAND (exp, i) != 0)
1923 int type = TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, i)));
1924 if (type == 'e' || type == '<' || type == '1' || type == '2'
1925 || type == 'r' || type == 's')
1927 cmp = has_cleanups (TREE_OPERAND (exp, i));
1936 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
1937 return a tree with all occurrences of references to F in a
1938 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
1939 contains only arithmetic expressions or a CALL_EXPR with a
1940 PLACEHOLDER_EXPR occurring only in its arglist. */
1943 substitute_in_expr (tree exp, tree f, tree r)
1945 enum tree_code code = TREE_CODE (exp);
1950 switch (TREE_CODE_CLASS (code))
1957 if (code == PLACEHOLDER_EXPR)
1959 else if (code == TREE_LIST)
1961 op0 = (TREE_CHAIN (exp) == 0
1962 ? 0 : substitute_in_expr (TREE_CHAIN (exp), f, r));
1963 op1 = substitute_in_expr (TREE_VALUE (exp), f, r);
1964 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
1967 return tree_cons (TREE_PURPOSE (exp), op1, op0);
1976 switch (TREE_CODE_LENGTH (code))
1979 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
1980 if (op0 == TREE_OPERAND (exp, 0))
1983 if (code == NON_LVALUE_EXPR)
1986 new = fold (build1 (code, TREE_TYPE (exp), op0));
1990 /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR
1991 could, but we don't support it. */
1992 if (code == RTL_EXPR)
1994 else if (code == CONSTRUCTOR)
1997 op0 = TREE_OPERAND (exp, 0);
1998 op1 = TREE_OPERAND (exp, 1);
1999 if (CONTAINS_PLACEHOLDER_P (op0))
2000 op0 = substitute_in_expr (op0, f, r);
2001 if (CONTAINS_PLACEHOLDER_P (op1))
2002 op1 = substitute_in_expr (op1, f, r);
2004 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2007 new = fold (build (code, TREE_TYPE (exp), op0, op1));
2011 /* It cannot be that anything inside a SAVE_EXPR contains a
2012 PLACEHOLDER_EXPR. */
2013 if (code == SAVE_EXPR)
2016 else if (code == CALL_EXPR)
2018 op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
2019 if (op1 == TREE_OPERAND (exp, 1))
2022 return build (code, TREE_TYPE (exp),
2023 TREE_OPERAND (exp, 0), op1, NULL_TREE);
2026 else if (code != COND_EXPR)
2029 op0 = TREE_OPERAND (exp, 0);
2030 op1 = TREE_OPERAND (exp, 1);
2031 op2 = TREE_OPERAND (exp, 2);
2033 if (CONTAINS_PLACEHOLDER_P (op0))
2034 op0 = substitute_in_expr (op0, f, r);
2035 if (CONTAINS_PLACEHOLDER_P (op1))
2036 op1 = substitute_in_expr (op1, f, r);
2037 if (CONTAINS_PLACEHOLDER_P (op2))
2038 op2 = substitute_in_expr (op2, f, r);
2040 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2041 && op2 == TREE_OPERAND (exp, 2))
2044 new = fold (build (code, TREE_TYPE (exp), op0, op1, op2));
2057 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2058 and it is the right field, replace it with R. */
2059 for (inner = TREE_OPERAND (exp, 0);
2060 TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
2061 inner = TREE_OPERAND (inner, 0))
2063 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2064 && TREE_OPERAND (exp, 1) == f)
2067 /* If this expression hasn't been completed let, leave it
2069 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2070 && TREE_TYPE (inner) == 0)
2073 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2074 if (op0 == TREE_OPERAND (exp, 0))
2077 new = fold (build (code, TREE_TYPE (exp), op0,
2078 TREE_OPERAND (exp, 1)));
2082 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2083 op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
2084 op2 = substitute_in_expr (TREE_OPERAND (exp, 2), f, r);
2085 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2086 && op2 == TREE_OPERAND (exp, 2))
2089 new = fold (build (code, TREE_TYPE (exp), op0, op1, op2));
2094 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2095 if (op0 == TREE_OPERAND (exp, 0))
2098 new = fold (build1 (code, TREE_TYPE (exp), op0));
2110 TREE_READONLY (new) = TREE_READONLY (exp);
2114 /* Stabilize a reference so that we can use it any number of times
2115 without causing its operands to be evaluated more than once.
2116 Returns the stabilized reference. This works by means of save_expr,
2117 so see the caveats in the comments about save_expr.
2119 Also allows conversion expressions whose operands are references.
2120 Any other kind of expression is returned unchanged. */
2123 stabilize_reference (tree ref)
2126 enum tree_code code = TREE_CODE (ref);
2133 /* No action is needed in this case. */
2139 case FIX_TRUNC_EXPR:
2140 case FIX_FLOOR_EXPR:
2141 case FIX_ROUND_EXPR:
2143 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2147 result = build_nt (INDIRECT_REF,
2148 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2152 result = build_nt (COMPONENT_REF,
2153 stabilize_reference (TREE_OPERAND (ref, 0)),
2154 TREE_OPERAND (ref, 1));
2158 result = build_nt (BIT_FIELD_REF,
2159 stabilize_reference (TREE_OPERAND (ref, 0)),
2160 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2161 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2165 result = build_nt (ARRAY_REF,
2166 stabilize_reference (TREE_OPERAND (ref, 0)),
2167 stabilize_reference_1 (TREE_OPERAND (ref, 1)));
2170 case ARRAY_RANGE_REF:
2171 result = build_nt (ARRAY_RANGE_REF,
2172 stabilize_reference (TREE_OPERAND (ref, 0)),
2173 stabilize_reference_1 (TREE_OPERAND (ref, 1)));
2177 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2178 it wouldn't be ignored. This matters when dealing with
2180 return stabilize_reference_1 (ref);
2183 result = build1 (INDIRECT_REF, TREE_TYPE (ref),
2184 save_expr (build1 (ADDR_EXPR,
2185 build_pointer_type (TREE_TYPE (ref)),
2189 /* If arg isn't a kind of lvalue we recognize, make no change.
2190 Caller should recognize the error for an invalid lvalue. */
2195 return error_mark_node;
2198 TREE_TYPE (result) = TREE_TYPE (ref);
2199 TREE_READONLY (result) = TREE_READONLY (ref);
2200 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2201 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2206 /* Subroutine of stabilize_reference; this is called for subtrees of
2207 references. Any expression with side-effects must be put in a SAVE_EXPR
2208 to ensure that it is only evaluated once.
2210 We don't put SAVE_EXPR nodes around everything, because assigning very
2211 simple expressions to temporaries causes us to miss good opportunities
2212 for optimizations. Among other things, the opportunity to fold in the
2213 addition of a constant into an addressing mode often gets lost, e.g.
2214 "y[i+1] += x;". In general, we take the approach that we should not make
2215 an assignment unless we are forced into it - i.e., that any non-side effect
2216 operator should be allowed, and that cse should take care of coalescing
2217 multiple utterances of the same expression should that prove fruitful. */
2220 stabilize_reference_1 (tree e)
2223 enum tree_code code = TREE_CODE (e);
2225 /* We cannot ignore const expressions because it might be a reference
2226 to a const array but whose index contains side-effects. But we can
2227 ignore things that are actual constant or that already have been
2228 handled by this function. */
2230 if (TREE_CONSTANT (e) || code == SAVE_EXPR)
2233 switch (TREE_CODE_CLASS (code))
2243 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2244 so that it will only be evaluated once. */
2245 /* The reference (r) and comparison (<) classes could be handled as
2246 below, but it is generally faster to only evaluate them once. */
2247 if (TREE_SIDE_EFFECTS (e))
2248 return save_expr (e);
2252 /* Constants need no processing. In fact, we should never reach
2257 /* Division is slow and tends to be compiled with jumps,
2258 especially the division by powers of 2 that is often
2259 found inside of an array reference. So do it just once. */
2260 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
2261 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
2262 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
2263 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
2264 return save_expr (e);
2265 /* Recursively stabilize each operand. */
2266 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
2267 stabilize_reference_1 (TREE_OPERAND (e, 1)));
2271 /* Recursively stabilize each operand. */
2272 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
2279 TREE_TYPE (result) = TREE_TYPE (e);
2280 TREE_READONLY (result) = TREE_READONLY (e);
2281 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
2282 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
2287 /* Low-level constructors for expressions. */
2289 /* Build an expression of code CODE, data type TYPE,
2290 and operands as specified by the arguments ARG1 and following arguments.
2291 Expressions and reference nodes can be created this way.
2292 Constants, decls, types and misc nodes cannot be. */
2295 build (enum tree_code code, tree tt, ...)
2307 t = make_node (code);
2308 length = TREE_CODE_LENGTH (code);
2311 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
2312 result based on those same flags for the arguments. But if the
2313 arguments aren't really even `tree' expressions, we shouldn't be trying
2315 fro = first_rtl_op (code);
2317 /* Expressions without side effects may be constant if their
2318 arguments are as well. */
2319 constant = (TREE_CODE_CLASS (code) == '<'
2320 || TREE_CODE_CLASS (code) == '1'
2321 || TREE_CODE_CLASS (code) == '2'
2322 || TREE_CODE_CLASS (code) == 'c');
2326 /* This is equivalent to the loop below, but faster. */
2327 tree arg0 = va_arg (p, tree);
2328 tree arg1 = va_arg (p, tree);
2330 TREE_OPERAND (t, 0) = arg0;
2331 TREE_OPERAND (t, 1) = arg1;
2332 TREE_READONLY (t) = 1;
2333 if (arg0 && fro > 0)
2335 if (TREE_SIDE_EFFECTS (arg0))
2336 TREE_SIDE_EFFECTS (t) = 1;
2337 if (!TREE_READONLY (arg0))
2338 TREE_READONLY (t) = 0;
2339 if (!TREE_CONSTANT (arg0))
2343 if (arg1 && fro > 1)
2345 if (TREE_SIDE_EFFECTS (arg1))
2346 TREE_SIDE_EFFECTS (t) = 1;
2347 if (!TREE_READONLY (arg1))
2348 TREE_READONLY (t) = 0;
2349 if (!TREE_CONSTANT (arg1))
2353 else if (length == 1)
2355 tree arg0 = va_arg (p, tree);
2357 /* The only one-operand cases we handle here are those with side-effects.
2358 Others are handled with build1. So don't bother checked if the
2359 arg has side-effects since we'll already have set it.
2361 ??? This really should use build1 too. */
2362 if (TREE_CODE_CLASS (code) != 's')
2364 TREE_OPERAND (t, 0) = arg0;
2368 for (i = 0; i < length; i++)
2370 tree operand = va_arg (p, tree);
2372 TREE_OPERAND (t, i) = operand;
2373 if (operand && fro > i)
2375 if (TREE_SIDE_EFFECTS (operand))
2376 TREE_SIDE_EFFECTS (t) = 1;
2377 if (!TREE_CONSTANT (operand))
2384 TREE_CONSTANT (t) = constant;
2386 if (code == CALL_EXPR && !TREE_SIDE_EFFECTS (t))
2388 /* Calls have side-effects, except those to const or
2390 i = call_expr_flags (t);
2391 if (!(i & (ECF_CONST | ECF_PURE)))
2392 TREE_SIDE_EFFECTS (t) = 1;
2394 /* And even those have side-effects if their arguments do. */
2395 else for (node = TREE_OPERAND (t, 1); node; node = TREE_CHAIN (node))
2396 if (TREE_SIDE_EFFECTS (TREE_VALUE (node)))
2398 TREE_SIDE_EFFECTS (t) = 1;
2406 /* Same as above, but only builds for unary operators.
2407 Saves lions share of calls to `build'; cuts down use
2408 of varargs, which is expensive for RISC machines. */
2411 build1 (enum tree_code code, tree type, tree node)
2413 int length = sizeof (struct tree_exp);
2414 #ifdef GATHER_STATISTICS
2415 tree_node_kind kind;
2419 #ifdef GATHER_STATISTICS
2420 switch (TREE_CODE_CLASS (code))
2422 case 's': /* an expression with side effects */
2425 case 'r': /* a reference */
2433 tree_node_counts[(int) kind]++;
2434 tree_node_sizes[(int) kind] += length;
2437 #ifdef ENABLE_CHECKING
2438 if (TREE_CODE_CLASS (code) == '2'
2439 || TREE_CODE_CLASS (code) == '<'
2440 || TREE_CODE_LENGTH (code) != 1)
2442 #endif /* ENABLE_CHECKING */
2444 t = ggc_alloc_tree (length);
2446 memset (t, 0, sizeof (struct tree_common));
2448 TREE_SET_CODE (t, code);
2450 TREE_TYPE (t) = type;
2451 TREE_COMPLEXITY (t) = 0;
2452 TREE_OPERAND (t, 0) = node;
2453 if (node && first_rtl_op (code) != 0)
2455 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
2456 TREE_READONLY (t) = TREE_READONLY (node);
2459 if (TREE_CODE_CLASS (code) == 's')
2460 TREE_SIDE_EFFECTS (t) = 1;
2467 case PREDECREMENT_EXPR:
2468 case PREINCREMENT_EXPR:
2469 case POSTDECREMENT_EXPR:
2470 case POSTINCREMENT_EXPR:
2471 /* All of these have side-effects, no matter what their
2473 TREE_SIDE_EFFECTS (t) = 1;
2474 TREE_READONLY (t) = 0;
2478 /* Whether a dereference is readonly has nothing to do with whether
2479 its operand is readonly. */
2480 TREE_READONLY (t) = 0;
2486 /* The address of a volatile decl or reference does not have
2487 side-effects. But be careful not to ignore side-effects from
2488 other sources deeper in the expression--if node is a _REF and
2489 one of its operands has side-effects, so do we. */
2490 if (TREE_THIS_VOLATILE (node))
2492 TREE_SIDE_EFFECTS (t) = 0;
2495 int i = first_rtl_op (TREE_CODE (node)) - 1;
2498 if (TREE_SIDE_EFFECTS (TREE_OPERAND (node, i)))
2499 TREE_SIDE_EFFECTS (t) = 1;
2507 if (TREE_CODE_CLASS (code) == '1' && node && TREE_CONSTANT (node))
2508 TREE_CONSTANT (t) = 1;
2515 /* Similar except don't specify the TREE_TYPE
2516 and leave the TREE_SIDE_EFFECTS as 0.
2517 It is permissible for arguments to be null,
2518 or even garbage if their values do not matter. */
2521 build_nt (enum tree_code code, ...)
2530 t = make_node (code);
2531 length = TREE_CODE_LENGTH (code);
2533 for (i = 0; i < length; i++)
2534 TREE_OPERAND (t, i) = va_arg (p, tree);
2540 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2541 We do NOT enter this node in any sort of symbol table.
2543 layout_decl is used to set up the decl's storage layout.
2544 Other slots are initialized to 0 or null pointers. */
2547 build_decl (enum tree_code code, tree name, tree type)
2551 t = make_node (code);
2553 /* if (type == error_mark_node)
2554 type = integer_type_node; */
2555 /* That is not done, deliberately, so that having error_mark_node
2556 as the type can suppress useless errors in the use of this variable. */
2558 DECL_NAME (t) = name;
2559 TREE_TYPE (t) = type;
2561 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
2563 else if (code == FUNCTION_DECL)
2564 DECL_MODE (t) = FUNCTION_MODE;
2569 /* BLOCK nodes are used to represent the structure of binding contours
2570 and declarations, once those contours have been exited and their contents
2571 compiled. This information is used for outputting debugging info. */
2574 build_block (tree vars, tree tags ATTRIBUTE_UNUSED, tree subblocks,
2575 tree supercontext, tree chain)
2577 tree block = make_node (BLOCK);
2579 BLOCK_VARS (block) = vars;
2580 BLOCK_SUBBLOCKS (block) = subblocks;
2581 BLOCK_SUPERCONTEXT (block) = supercontext;
2582 BLOCK_CHAIN (block) = chain;
2586 /* EXPR_WITH_FILE_LOCATION are used to keep track of the exact
2587 location where an expression or an identifier were encountered. It
2588 is necessary for languages where the frontend parser will handle
2589 recursively more than one file (Java is one of them). */
2592 build_expr_wfl (tree node, const char *file, int line, int col)
2594 static const char *last_file = 0;
2595 static tree last_filenode = NULL_TREE;
2596 tree wfl = make_node (EXPR_WITH_FILE_LOCATION);
2598 EXPR_WFL_NODE (wfl) = node;
2599 EXPR_WFL_SET_LINECOL (wfl, line, col);
2600 if (file != last_file)
2603 last_filenode = file ? get_identifier (file) : NULL_TREE;
2606 EXPR_WFL_FILENAME_NODE (wfl) = last_filenode;
2609 TREE_SIDE_EFFECTS (wfl) = TREE_SIDE_EFFECTS (node);
2610 TREE_TYPE (wfl) = TREE_TYPE (node);
2616 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
2620 build_decl_attribute_variant (tree ddecl, tree attribute)
2622 DECL_ATTRIBUTES (ddecl) = attribute;
2626 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
2629 Record such modified types already made so we don't make duplicates. */
2632 build_type_attribute_variant (tree ttype, tree attribute)
2634 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
2636 unsigned int hashcode;
2639 ntype = copy_node (ttype);
2641 TYPE_POINTER_TO (ntype) = 0;
2642 TYPE_REFERENCE_TO (ntype) = 0;
2643 TYPE_ATTRIBUTES (ntype) = attribute;
2645 /* Create a new main variant of TYPE. */
2646 TYPE_MAIN_VARIANT (ntype) = ntype;
2647 TYPE_NEXT_VARIANT (ntype) = 0;
2648 set_type_quals (ntype, TYPE_UNQUALIFIED);
2650 hashcode = (TYPE_HASH (TREE_CODE (ntype))
2651 + TYPE_HASH (TREE_TYPE (ntype))
2652 + attribute_hash_list (attribute));
2654 switch (TREE_CODE (ntype))
2657 hashcode += TYPE_HASH (TYPE_ARG_TYPES (ntype));
2660 hashcode += TYPE_HASH (TYPE_DOMAIN (ntype));
2663 hashcode += TYPE_HASH (TYPE_MAX_VALUE (ntype));
2666 hashcode += TYPE_HASH (TYPE_PRECISION (ntype));
2672 ntype = type_hash_canon (hashcode, ntype);
2673 ttype = build_qualified_type (ntype, TYPE_QUALS (ttype));
2679 /* Return nonzero if IDENT is a valid name for attribute ATTR,
2682 We try both `text' and `__text__', ATTR may be either one. */
2683 /* ??? It might be a reasonable simplification to require ATTR to be only
2684 `text'. One might then also require attribute lists to be stored in
2685 their canonicalized form. */
2688 is_attribute_p (const char *attr, tree ident)
2690 int ident_len, attr_len;
2693 if (TREE_CODE (ident) != IDENTIFIER_NODE)
2696 if (strcmp (attr, IDENTIFIER_POINTER (ident)) == 0)
2699 p = IDENTIFIER_POINTER (ident);
2700 ident_len = strlen (p);
2701 attr_len = strlen (attr);
2703 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
2707 || attr[attr_len - 2] != '_'
2708 || attr[attr_len - 1] != '_')
2710 if (ident_len == attr_len - 4
2711 && strncmp (attr + 2, p, attr_len - 4) == 0)
2716 if (ident_len == attr_len + 4
2717 && p[0] == '_' && p[1] == '_'
2718 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
2719 && strncmp (attr, p + 2, attr_len) == 0)
2726 /* Given an attribute name and a list of attributes, return a pointer to the
2727 attribute's list element if the attribute is part of the list, or NULL_TREE
2728 if not found. If the attribute appears more than once, this only
2729 returns the first occurrence; the TREE_CHAIN of the return value should
2730 be passed back in if further occurrences are wanted. */
2733 lookup_attribute (const char *attr_name, tree list)
2737 for (l = list; l; l = TREE_CHAIN (l))
2739 if (TREE_CODE (TREE_PURPOSE (l)) != IDENTIFIER_NODE)
2741 if (is_attribute_p (attr_name, TREE_PURPOSE (l)))
2748 /* Return an attribute list that is the union of a1 and a2. */
2751 merge_attributes (tree a1, tree a2)
2755 /* Either one unset? Take the set one. */
2757 if ((attributes = a1) == 0)
2760 /* One that completely contains the other? Take it. */
2762 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
2764 if (attribute_list_contained (a2, a1))
2768 /* Pick the longest list, and hang on the other list. */
2770 if (list_length (a1) < list_length (a2))
2771 attributes = a2, a2 = a1;
2773 for (; a2 != 0; a2 = TREE_CHAIN (a2))
2776 for (a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
2779 a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
2782 if (simple_cst_equal (TREE_VALUE (a), TREE_VALUE (a2)) == 1)
2787 a1 = copy_node (a2);
2788 TREE_CHAIN (a1) = attributes;
2797 /* Given types T1 and T2, merge their attributes and return
2801 merge_type_attributes (tree t1, tree t2)
2803 return merge_attributes (TYPE_ATTRIBUTES (t1),
2804 TYPE_ATTRIBUTES (t2));
2807 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
2811 merge_decl_attributes (tree olddecl, tree newdecl)
2813 return merge_attributes (DECL_ATTRIBUTES (olddecl),
2814 DECL_ATTRIBUTES (newdecl));
2817 #ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
2819 /* Specialization of merge_decl_attributes for various Windows targets.
2821 This handles the following situation:
2823 __declspec (dllimport) int foo;
2826 The second instance of `foo' nullifies the dllimport. */
2829 merge_dllimport_decl_attributes (tree old, tree new)
2832 int delete_dllimport_p;
2834 old = DECL_ATTRIBUTES (old);
2835 new = DECL_ATTRIBUTES (new);
2837 /* What we need to do here is remove from `old' dllimport if it doesn't
2838 appear in `new'. dllimport behaves like extern: if a declaration is
2839 marked dllimport and a definition appears later, then the object
2840 is not dllimport'd. */
2841 if (lookup_attribute ("dllimport", old) != NULL_TREE
2842 && lookup_attribute ("dllimport", new) == NULL_TREE)
2843 delete_dllimport_p = 1;
2845 delete_dllimport_p = 0;
2847 a = merge_attributes (old, new);
2849 if (delete_dllimport_p)
2853 /* Scan the list for dllimport and delete it. */
2854 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
2856 if (is_attribute_p ("dllimport", TREE_PURPOSE (t)))
2858 if (prev == NULL_TREE)
2861 TREE_CHAIN (prev) = TREE_CHAIN (t);
2870 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
2872 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
2873 of the various TYPE_QUAL values. */
2876 set_type_quals (tree type, int type_quals)
2878 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
2879 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
2880 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
2883 /* Return a version of the TYPE, qualified as indicated by the
2884 TYPE_QUALS, if one exists. If no qualified version exists yet,
2885 return NULL_TREE. */
2888 get_qualified_type (tree type, int type_quals)
2892 /* Search the chain of variants to see if there is already one there just
2893 like the one we need to have. If so, use that existing one. We must
2894 preserve the TYPE_NAME, since there is code that depends on this. */
2895 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
2896 if (TYPE_QUALS (t) == type_quals && TYPE_NAME (t) == TYPE_NAME (type)
2897 && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
2898 && attribute_list_equal (TYPE_ATTRIBUTES (t), TYPE_ATTRIBUTES (type)))
2904 /* Like get_qualified_type, but creates the type if it does not
2905 exist. This function never returns NULL_TREE. */
2908 build_qualified_type (tree type, int type_quals)
2912 /* See if we already have the appropriate qualified variant. */
2913 t = get_qualified_type (type, type_quals);
2915 /* If not, build it. */
2918 t = build_type_copy (type);
2919 set_type_quals (t, type_quals);
2925 /* Create a new variant of TYPE, equivalent but distinct.
2926 This is so the caller can modify it. */
2929 build_type_copy (tree type)
2931 tree t, m = TYPE_MAIN_VARIANT (type);
2933 t = copy_node (type);
2935 TYPE_POINTER_TO (t) = 0;
2936 TYPE_REFERENCE_TO (t) = 0;
2938 /* Add this type to the chain of variants of TYPE. */
2939 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
2940 TYPE_NEXT_VARIANT (m) = t;
2945 /* Hashing of types so that we don't make duplicates.
2946 The entry point is `type_hash_canon'. */
2948 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
2949 with types in the TREE_VALUE slots), by adding the hash codes
2950 of the individual types. */
2953 type_hash_list (tree list)
2955 unsigned int hashcode;
2958 for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
2959 hashcode += TYPE_HASH (TREE_VALUE (tail));
2964 /* These are the Hashtable callback functions. */
2966 /* Returns true if the types are equal. */
2969 type_hash_eq (const void *va, const void *vb)
2971 const struct type_hash *a = va, *b = vb;
2972 if (a->hash == b->hash
2973 && TREE_CODE (a->type) == TREE_CODE (b->type)
2974 && TREE_TYPE (a->type) == TREE_TYPE (b->type)
2975 && attribute_list_equal (TYPE_ATTRIBUTES (a->type),
2976 TYPE_ATTRIBUTES (b->type))
2977 && TYPE_ALIGN (a->type) == TYPE_ALIGN (b->type)
2978 && (TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
2979 || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
2980 TYPE_MAX_VALUE (b->type)))
2981 && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
2982 || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
2983 TYPE_MIN_VALUE (b->type)))
2984 /* Note that TYPE_DOMAIN is TYPE_ARG_TYPES for FUNCTION_TYPE. */
2985 && (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
2986 || (TYPE_DOMAIN (a->type)
2987 && TREE_CODE (TYPE_DOMAIN (a->type)) == TREE_LIST
2988 && TYPE_DOMAIN (b->type)
2989 && TREE_CODE (TYPE_DOMAIN (b->type)) == TREE_LIST
2990 && type_list_equal (TYPE_DOMAIN (a->type),
2991 TYPE_DOMAIN (b->type)))))
2996 /* Return the cached hash value. */
2999 type_hash_hash (const void *item)
3001 return ((const struct type_hash *) item)->hash;
3004 /* Look in the type hash table for a type isomorphic to TYPE.
3005 If one is found, return it. Otherwise return 0. */
3008 type_hash_lookup (unsigned int hashcode, tree type)
3010 struct type_hash *h, in;
3012 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
3013 must call that routine before comparing TYPE_ALIGNs. */
3019 h = htab_find_with_hash (type_hash_table, &in, hashcode);
3025 /* Add an entry to the type-hash-table
3026 for a type TYPE whose hash code is HASHCODE. */
3029 type_hash_add (unsigned int hashcode, tree type)
3031 struct type_hash *h;
3034 h = ggc_alloc (sizeof (struct type_hash));
3037 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
3038 *(struct type_hash **) loc = h;
3041 /* Given TYPE, and HASHCODE its hash code, return the canonical
3042 object for an identical type if one already exists.
3043 Otherwise, return TYPE, and record it as the canonical object
3044 if it is a permanent object.
3046 To use this function, first create a type of the sort you want.
3047 Then compute its hash code from the fields of the type that
3048 make it different from other similar types.
3049 Then call this function and use the value.
3050 This function frees the type you pass in if it is a duplicate. */
3052 /* Set to 1 to debug without canonicalization. Never set by program. */
3053 int debug_no_type_hash = 0;
3056 type_hash_canon (unsigned int hashcode, tree type)
3060 if (debug_no_type_hash)
3063 /* See if the type is in the hash table already. If so, return it.
3064 Otherwise, add the type. */
3065 t1 = type_hash_lookup (hashcode, type);
3068 #ifdef GATHER_STATISTICS
3069 tree_node_counts[(int) t_kind]--;
3070 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
3076 type_hash_add (hashcode, type);
3081 /* See if the data pointed to by the type hash table is marked. We consider
3082 it marked if the type is marked or if a debug type number or symbol
3083 table entry has been made for the type. This reduces the amount of
3084 debugging output and eliminates that dependency of the debug output on
3085 the number of garbage collections. */
3088 type_hash_marked_p (const void *p)
3090 tree type = ((struct type_hash *) p)->type;
3092 return ggc_marked_p (type) || TYPE_SYMTAB_POINTER (type);
3096 print_type_hash_statistics (void)
3098 fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
3099 (long) htab_size (type_hash_table),
3100 (long) htab_elements (type_hash_table),
3101 htab_collisions (type_hash_table));
3104 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
3105 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
3106 by adding the hash codes of the individual attributes. */
3109 attribute_hash_list (tree list)
3111 unsigned int hashcode;
3114 for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
3115 /* ??? Do we want to add in TREE_VALUE too? */
3116 hashcode += TYPE_HASH (TREE_PURPOSE (tail));
3120 /* Given two lists of attributes, return true if list l2 is
3121 equivalent to l1. */
3124 attribute_list_equal (tree l1, tree l2)
3126 return attribute_list_contained (l1, l2)
3127 && attribute_list_contained (l2, l1);
3130 /* Given two lists of attributes, return true if list L2 is
3131 completely contained within L1. */
3132 /* ??? This would be faster if attribute names were stored in a canonicalized
3133 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
3134 must be used to show these elements are equivalent (which they are). */
3135 /* ??? It's not clear that attributes with arguments will always be handled
3139 attribute_list_contained (tree l1, tree l2)
3143 /* First check the obvious, maybe the lists are identical. */
3147 /* Maybe the lists are similar. */
3148 for (t1 = l1, t2 = l2;
3150 && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
3151 && TREE_VALUE (t1) == TREE_VALUE (t2);
3152 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
3154 /* Maybe the lists are equal. */
3155 if (t1 == 0 && t2 == 0)
3158 for (; t2 != 0; t2 = TREE_CHAIN (t2))
3161 for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1);
3163 attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
3166 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) == 1)
3173 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) != 1)
3180 /* Given two lists of types
3181 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
3182 return 1 if the lists contain the same types in the same order.
3183 Also, the TREE_PURPOSEs must match. */
3186 type_list_equal (tree l1, tree l2)
3190 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
3191 if (TREE_VALUE (t1) != TREE_VALUE (t2)
3192 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
3193 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
3194 && (TREE_TYPE (TREE_PURPOSE (t1))
3195 == TREE_TYPE (TREE_PURPOSE (t2))))))
3201 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
3202 given by TYPE. If the argument list accepts variable arguments,
3203 then this function counts only the ordinary arguments. */
3206 type_num_arguments (tree type)
3211 for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
3212 /* If the function does not take a variable number of arguments,
3213 the last element in the list will have type `void'. */
3214 if (VOID_TYPE_P (TREE_VALUE (t)))
3222 /* Nonzero if integer constants T1 and T2
3223 represent the same constant value. */
3226 tree_int_cst_equal (tree t1, tree t2)
3231 if (t1 == 0 || t2 == 0)
3234 if (TREE_CODE (t1) == INTEGER_CST
3235 && TREE_CODE (t2) == INTEGER_CST
3236 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3237 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
3243 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
3244 The precise way of comparison depends on their data type. */
3247 tree_int_cst_lt (tree t1, tree t2)
3252 if (TREE_UNSIGNED (TREE_TYPE (t1)) != TREE_UNSIGNED (TREE_TYPE (t2)))
3254 int t1_sgn = tree_int_cst_sgn (t1);
3255 int t2_sgn = tree_int_cst_sgn (t2);
3257 if (t1_sgn < t2_sgn)
3259 else if (t1_sgn > t2_sgn)
3261 /* Otherwise, both are non-negative, so we compare them as
3262 unsigned just in case one of them would overflow a signed
3265 else if (! TREE_UNSIGNED (TREE_TYPE (t1)))
3266 return INT_CST_LT (t1, t2);
3268 return INT_CST_LT_UNSIGNED (t1, t2);
3271 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
3274 tree_int_cst_compare (tree t1, tree t2)
3276 if (tree_int_cst_lt (t1, t2))
3278 else if (tree_int_cst_lt (t2, t1))
3284 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
3285 the host. If POS is zero, the value can be represented in a single
3286 HOST_WIDE_INT. If POS is nonzero, the value must be positive and can
3287 be represented in a single unsigned HOST_WIDE_INT. */
3290 host_integerp (tree t, int pos)
3292 return (TREE_CODE (t) == INTEGER_CST
3293 && ! TREE_OVERFLOW (t)
3294 && ((TREE_INT_CST_HIGH (t) == 0
3295 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
3296 || (! pos && TREE_INT_CST_HIGH (t) == -1
3297 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
3298 && ! TREE_UNSIGNED (TREE_TYPE (t)))
3299 || (pos && TREE_INT_CST_HIGH (t) == 0)));
3302 /* Return the HOST_WIDE_INT least significant bits of T if it is an
3303 INTEGER_CST and there is no overflow. POS is nonzero if the result must
3304 be positive. Abort if we cannot satisfy the above conditions. */
3307 tree_low_cst (tree t, int pos)
3309 if (host_integerp (t, pos))
3310 return TREE_INT_CST_LOW (t);
3315 /* Return the most significant bit of the integer constant T. */
3318 tree_int_cst_msb (tree t)
3322 unsigned HOST_WIDE_INT l;
3324 /* Note that using TYPE_PRECISION here is wrong. We care about the
3325 actual bits, not the (arbitrary) range of the type. */
3326 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
3327 rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
3328 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
3329 return (l & 1) == 1;
3332 /* Return an indication of the sign of the integer constant T.
3333 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
3334 Note that -1 will never be returned it T's type is unsigned. */
3337 tree_int_cst_sgn (tree t)
3339 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
3341 else if (TREE_UNSIGNED (TREE_TYPE (t)))
3343 else if (TREE_INT_CST_HIGH (t) < 0)
3349 /* Compare two constructor-element-type constants. Return 1 if the lists
3350 are known to be equal; otherwise return 0. */
3353 simple_cst_list_equal (tree l1, tree l2)
3355 while (l1 != NULL_TREE && l2 != NULL_TREE)
3357 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
3360 l1 = TREE_CHAIN (l1);
3361 l2 = TREE_CHAIN (l2);
3367 /* Return truthvalue of whether T1 is the same tree structure as T2.
3368 Return 1 if they are the same.
3369 Return 0 if they are understandably different.
3370 Return -1 if either contains tree structure not understood by
3374 simple_cst_equal (tree t1, tree t2)
3376 enum tree_code code1, code2;
3382 if (t1 == 0 || t2 == 0)
3385 code1 = TREE_CODE (t1);
3386 code2 = TREE_CODE (t2);
3388 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
3390 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3391 || code2 == NON_LVALUE_EXPR)
3392 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3394 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
3397 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3398 || code2 == NON_LVALUE_EXPR)
3399 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
3407 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3408 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
3411 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3414 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3415 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3416 TREE_STRING_LENGTH (t1)));
3419 if (CONSTRUCTOR_ELTS (t1) == CONSTRUCTOR_ELTS (t2))
3425 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3428 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3432 simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3435 /* Special case: if either target is an unallocated VAR_DECL,
3436 it means that it's going to be unified with whatever the
3437 TARGET_EXPR is really supposed to initialize, so treat it
3438 as being equivalent to anything. */
3439 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
3440 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
3441 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
3442 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
3443 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
3444 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
3447 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3452 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3454 case WITH_CLEANUP_EXPR:
3455 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3459 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
3462 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
3463 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3477 /* This general rule works for most tree codes. All exceptions should be
3478 handled above. If this is a language-specific tree code, we can't
3479 trust what might be in the operand, so say we don't know
3481 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
3484 switch (TREE_CODE_CLASS (code1))
3493 for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
3495 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
3507 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
3508 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
3509 than U, respectively. */
3512 compare_tree_int (tree t, unsigned HOST_WIDE_INT u)
3514 if (tree_int_cst_sgn (t) < 0)
3516 else if (TREE_INT_CST_HIGH (t) != 0)
3518 else if (TREE_INT_CST_LOW (t) == u)
3520 else if (TREE_INT_CST_LOW (t) < u)
3526 /* Return true if CODE represents an associative tree code. Otherwise
3529 associative_tree_code (enum tree_code code)
3551 /* Return true if CODE represents an commutative tree code. Otherwise
3554 commutative_tree_code (enum tree_code code)
3575 /* Generate a hash value for an expression. This can be used iteratively
3576 by passing a previous result as the "val" argument.
3578 This function is intended to produce the same hash for expressions which
3579 would compare equal using operand_equal_p. */
3582 iterative_hash_expr (tree t, hashval_t val)
3585 enum tree_code code;
3589 return iterative_hash_object (t, val);
3591 code = TREE_CODE (t);
3592 class = TREE_CODE_CLASS (code);
3596 /* Decls we can just compare by pointer. */
3597 val = iterative_hash_object (t, val);
3599 else if (class == 'c')
3601 /* Alas, constants aren't shared, so we can't rely on pointer
3603 if (code == INTEGER_CST)
3605 val = iterative_hash_object (TREE_INT_CST_LOW (t), val);
3606 val = iterative_hash_object (TREE_INT_CST_HIGH (t), val);
3608 else if (code == REAL_CST)
3609 val = iterative_hash (TREE_REAL_CST_PTR (t),
3610 sizeof (REAL_VALUE_TYPE), val);
3611 else if (code == STRING_CST)
3612 val = iterative_hash (TREE_STRING_POINTER (t),
3613 TREE_STRING_LENGTH (t), val);
3614 else if (code == COMPLEX_CST)
3616 val = iterative_hash_expr (TREE_REALPART (t), val);
3617 val = iterative_hash_expr (TREE_IMAGPART (t), val);
3619 else if (code == VECTOR_CST)
3620 val = iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val);
3624 else if (IS_EXPR_CODE_CLASS (class))
3626 val = iterative_hash_object (code, val);
3628 if (code == NOP_EXPR || code == CONVERT_EXPR
3629 || code == NON_LVALUE_EXPR)
3630 val = iterative_hash_object (TREE_TYPE (t), val);
3632 if (commutative_tree_code (code))
3634 /* It's a commutative expression. We want to hash it the same
3635 however it appears. We do this by first hashing both operands
3636 and then rehashing based on the order of their independent
3638 hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0);
3639 hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0);
3643 t = one, one = two, two = t;
3645 val = iterative_hash_object (one, val);
3646 val = iterative_hash_object (two, val);
3649 for (i = first_rtl_op (code) - 1; i >= 0; --i)
3650 val = iterative_hash_expr (TREE_OPERAND (t, i), val);
3652 else if (code == TREE_LIST)
3654 /* A list of expressions, for a CALL_EXPR or as the elements of a
3656 for (; t; t = TREE_CHAIN (t))
3657 val = iterative_hash_expr (TREE_VALUE (t), val);
3665 /* Constructors for pointer, array and function types.
3666 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
3667 constructed by language-dependent code, not here.) */
3669 /* Construct, lay out and return the type of pointers to TO_TYPE
3670 with mode MODE. If such a type has already been constructed,
3674 build_pointer_type_for_mode (tree to_type, enum machine_mode mode)
3676 tree t = TYPE_POINTER_TO (to_type);
3678 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3679 if (t != 0 && mode == ptr_mode)
3682 t = make_node (POINTER_TYPE);
3684 TREE_TYPE (t) = to_type;
3685 TYPE_MODE (t) = mode;
3687 /* Record this type as the pointer to TO_TYPE. */
3688 if (mode == ptr_mode)
3689 TYPE_POINTER_TO (to_type) = t;
3691 /* Lay out the type. This function has many callers that are concerned
3692 with expression-construction, and this simplifies them all.
3693 Also, it guarantees the TYPE_SIZE is in the same obstack as the type. */
3699 /* By default build pointers in ptr_mode. */
3702 build_pointer_type (tree to_type)
3704 return build_pointer_type_for_mode (to_type, ptr_mode);
3707 /* Construct, lay out and return the type of references to TO_TYPE
3708 with mode MODE. If such a type has already been constructed,
3712 build_reference_type_for_mode (tree to_type, enum machine_mode mode)
3714 tree t = TYPE_REFERENCE_TO (to_type);
3716 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3717 if (t != 0 && mode == ptr_mode)
3720 t = make_node (REFERENCE_TYPE);
3722 TREE_TYPE (t) = to_type;
3723 TYPE_MODE (t) = mode;
3725 /* Record this type as the pointer to TO_TYPE. */
3726 if (mode == ptr_mode)
3727 TYPE_REFERENCE_TO (to_type) = t;
3735 /* Build the node for the type of references-to-TO_TYPE by default
3739 build_reference_type (tree to_type)
3741 return build_reference_type_for_mode (to_type, ptr_mode);
3744 /* Build a type that is compatible with t but has no cv quals anywhere
3747 const char *const *const * -> char ***. */
3750 build_type_no_quals (tree t)
3752 switch (TREE_CODE (t))
3755 return build_pointer_type (build_type_no_quals (TREE_TYPE (t)));
3756 case REFERENCE_TYPE:
3757 return build_reference_type (build_type_no_quals (TREE_TYPE (t)));
3759 return TYPE_MAIN_VARIANT (t);
3763 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
3764 MAXVAL should be the maximum value in the domain
3765 (one less than the length of the array).
3767 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
3768 We don't enforce this limit, that is up to caller (e.g. language front end).
3769 The limit exists because the result is a signed type and we don't handle
3770 sizes that use more than one HOST_WIDE_INT. */
3773 build_index_type (tree maxval)
3775 tree itype = make_node (INTEGER_TYPE);
3777 TREE_TYPE (itype) = sizetype;
3778 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
3779 TYPE_MIN_VALUE (itype) = size_zero_node;
3780 TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
3781 TYPE_MODE (itype) = TYPE_MODE (sizetype);
3782 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
3783 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
3784 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
3785 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
3787 if (host_integerp (maxval, 1))
3788 return type_hash_canon (tree_low_cst (maxval, 1), itype);
3793 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
3794 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
3795 low bound LOWVAL and high bound HIGHVAL.
3796 if TYPE==NULL_TREE, sizetype is used. */
3799 build_range_type (tree type, tree lowval, tree highval)
3801 tree itype = make_node (INTEGER_TYPE);
3803 TREE_TYPE (itype) = type;
3804 if (type == NULL_TREE)
3807 TYPE_MIN_VALUE (itype) = convert (type, lowval);
3808 TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL;
3810 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
3811 TYPE_MODE (itype) = TYPE_MODE (type);
3812 TYPE_SIZE (itype) = TYPE_SIZE (type);
3813 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
3814 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
3815 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
3817 if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
3818 return type_hash_canon (tree_low_cst (highval, 0)
3819 - tree_low_cst (lowval, 0),
3825 /* Just like build_index_type, but takes lowval and highval instead
3826 of just highval (maxval). */
3829 build_index_2_type (tree lowval, tree highval)
3831 return build_range_type (sizetype, lowval, highval);
3834 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
3835 and number of elements specified by the range of values of INDEX_TYPE.
3836 If such a type has already been constructed, reuse it. */
3839 build_array_type (tree elt_type, tree index_type)
3842 unsigned int hashcode;
3844 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
3846 error ("arrays of functions are not meaningful");
3847 elt_type = integer_type_node;
3850 /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
3851 build_pointer_type (elt_type);
3853 /* Allocate the array after the pointer type,
3854 in case we free it in type_hash_canon. */
3855 t = make_node (ARRAY_TYPE);
3856 TREE_TYPE (t) = elt_type;
3857 TYPE_DOMAIN (t) = index_type;
3859 if (index_type == 0)
3864 hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
3865 t = type_hash_canon (hashcode, t);
3867 if (!COMPLETE_TYPE_P (t))
3872 /* Return the TYPE of the elements comprising
3873 the innermost dimension of ARRAY. */
3876 get_inner_array_type (tree array)
3878 tree type = TREE_TYPE (array);
3880 while (TREE_CODE (type) == ARRAY_TYPE)
3881 type = TREE_TYPE (type);
3886 /* Construct, lay out and return
3887 the type of functions returning type VALUE_TYPE
3888 given arguments of types ARG_TYPES.
3889 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
3890 are data type nodes for the arguments of the function.
3891 If such a type has already been constructed, reuse it. */
3894 build_function_type (tree value_type, tree arg_types)
3897 unsigned int hashcode;
3899 if (TREE_CODE (value_type) == FUNCTION_TYPE)
3901 error ("function return type cannot be function");
3902 value_type = integer_type_node;
3905 /* Make a node of the sort we want. */
3906 t = make_node (FUNCTION_TYPE);
3907 TREE_TYPE (t) = value_type;
3908 TYPE_ARG_TYPES (t) = arg_types;
3910 /* If we already have such a type, use the old one and free this one. */
3911 hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
3912 t = type_hash_canon (hashcode, t);
3914 if (!COMPLETE_TYPE_P (t))
3919 /* Build a function type. The RETURN_TYPE is the type returned by the
3920 function. If additional arguments are provided, they are
3921 additional argument types. The list of argument types must always
3922 be terminated by NULL_TREE. */
3925 build_function_type_list (tree return_type, ...)
3930 va_start (p, return_type);
3932 t = va_arg (p, tree);
3933 for (args = NULL_TREE; t != NULL_TREE; t = va_arg (p, tree))
3934 args = tree_cons (NULL_TREE, t, args);
3937 args = nreverse (args);
3938 TREE_CHAIN (last) = void_list_node;
3939 args = build_function_type (return_type, args);
3945 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
3946 and ARGTYPES (a TREE_LIST) are the return type and arguments types
3947 for the method. An implicit additional parameter (of type
3948 pointer-to-BASETYPE) is added to the ARGTYPES. */
3951 build_method_type_directly (tree basetype,
3959 /* Make a node of the sort we want. */
3960 t = make_node (METHOD_TYPE);
3962 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
3963 TREE_TYPE (t) = rettype;
3964 ptype = build_pointer_type (basetype);
3966 /* The actual arglist for this function includes a "hidden" argument
3967 which is "this". Put it into the list of argument types. */
3968 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
3969 TYPE_ARG_TYPES (t) = argtypes;
3971 /* If we already have such a type, use the old one and free this one.
3972 Note that it also frees up the above cons cell if found. */
3973 hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) +
3974 type_hash_list (argtypes);
3976 t = type_hash_canon (hashcode, t);
3978 if (!COMPLETE_TYPE_P (t))
3984 /* Construct, lay out and return the type of methods belonging to class
3985 BASETYPE and whose arguments and values are described by TYPE.
3986 If that type exists already, reuse it.
3987 TYPE must be a FUNCTION_TYPE node. */
3990 build_method_type (tree basetype, tree type)
3992 if (TREE_CODE (type) != FUNCTION_TYPE)
3995 return build_method_type_directly (basetype,
3997 TYPE_ARG_TYPES (type));
4000 /* Construct, lay out and return the type of offsets to a value
4001 of type TYPE, within an object of type BASETYPE.
4002 If a suitable offset type exists already, reuse it. */
4005 build_offset_type (tree basetype, tree type)
4008 unsigned int hashcode;
4010 /* Make a node of the sort we want. */
4011 t = make_node (OFFSET_TYPE);
4013 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4014 TREE_TYPE (t) = type;
4016 /* If we already have such a type, use the old one and free this one. */
4017 hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
4018 t = type_hash_canon (hashcode, t);
4020 if (!COMPLETE_TYPE_P (t))
4026 /* Create a complex type whose components are COMPONENT_TYPE. */
4029 build_complex_type (tree component_type)
4032 unsigned int hashcode;
4034 /* Make a node of the sort we want. */
4035 t = make_node (COMPLEX_TYPE);
4037 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
4038 set_type_quals (t, TYPE_QUALS (component_type));
4040 /* If we already have such a type, use the old one and free this one. */
4041 hashcode = TYPE_HASH (component_type);
4042 t = type_hash_canon (hashcode, t);
4044 if (!COMPLETE_TYPE_P (t))
4047 /* If we are writing Dwarf2 output we need to create a name,
4048 since complex is a fundamental type. */
4049 if ((write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4053 if (component_type == char_type_node)
4054 name = "complex char";
4055 else if (component_type == signed_char_type_node)
4056 name = "complex signed char";
4057 else if (component_type == unsigned_char_type_node)
4058 name = "complex unsigned char";
4059 else if (component_type == short_integer_type_node)
4060 name = "complex short int";
4061 else if (component_type == short_unsigned_type_node)
4062 name = "complex short unsigned int";
4063 else if (component_type == integer_type_node)
4064 name = "complex int";
4065 else if (component_type == unsigned_type_node)
4066 name = "complex unsigned int";
4067 else if (component_type == long_integer_type_node)
4068 name = "complex long int";
4069 else if (component_type == long_unsigned_type_node)
4070 name = "complex long unsigned int";
4071 else if (component_type == long_long_integer_type_node)
4072 name = "complex long long int";
4073 else if (component_type == long_long_unsigned_type_node)
4074 name = "complex long long unsigned int";
4079 TYPE_NAME (t) = get_identifier (name);
4085 /* Return OP, stripped of any conversions to wider types as much as is safe.
4086 Converting the value back to OP's type makes a value equivalent to OP.
4088 If FOR_TYPE is nonzero, we return a value which, if converted to
4089 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
4091 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
4092 narrowest type that can hold the value, even if they don't exactly fit.
4093 Otherwise, bit-field references are changed to a narrower type
4094 only if they can be fetched directly from memory in that type.
4096 OP must have integer, real or enumeral type. Pointers are not allowed!
4098 There are some cases where the obvious value we could return
4099 would regenerate to OP if converted to OP's type,
4100 but would not extend like OP to wider types.
4101 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
4102 For example, if OP is (unsigned short)(signed char)-1,
4103 we avoid returning (signed char)-1 if FOR_TYPE is int,
4104 even though extending that to an unsigned short would regenerate OP,
4105 since the result of extending (signed char)-1 to (int)
4106 is different from (int) OP. */
4109 get_unwidened (tree op, tree for_type)
4111 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
4112 tree type = TREE_TYPE (op);
4114 = TYPE_PRECISION (for_type != 0 ? for_type : type);
4116 = (for_type != 0 && for_type != type
4117 && final_prec > TYPE_PRECISION (type)
4118 && TREE_UNSIGNED (type));
4121 while (TREE_CODE (op) == NOP_EXPR)
4124 = TYPE_PRECISION (TREE_TYPE (op))
4125 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
4127 /* Truncations are many-one so cannot be removed.
4128 Unless we are later going to truncate down even farther. */
4130 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
4133 /* See what's inside this conversion. If we decide to strip it,
4135 op = TREE_OPERAND (op, 0);
4137 /* If we have not stripped any zero-extensions (uns is 0),
4138 we can strip any kind of extension.
4139 If we have previously stripped a zero-extension,
4140 only zero-extensions can safely be stripped.
4141 Any extension can be stripped if the bits it would produce
4142 are all going to be discarded later by truncating to FOR_TYPE. */
4146 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
4148 /* TREE_UNSIGNED says whether this is a zero-extension.
4149 Let's avoid computing it if it does not affect WIN
4150 and if UNS will not be needed again. */
4151 if ((uns || TREE_CODE (op) == NOP_EXPR)
4152 && TREE_UNSIGNED (TREE_TYPE (op)))
4160 if (TREE_CODE (op) == COMPONENT_REF
4161 /* Since type_for_size always gives an integer type. */
4162 && TREE_CODE (type) != REAL_TYPE
4163 /* Don't crash if field not laid out yet. */
4164 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
4165 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
4167 unsigned int innerprec
4168 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4169 int unsignedp = (TREE_UNSIGNED (TREE_OPERAND (op, 1))
4170 || TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
4171 type = (*lang_hooks.types.type_for_size) (innerprec, unsignedp);
4173 /* We can get this structure field in the narrowest type it fits in.
4174 If FOR_TYPE is 0, do this only for a field that matches the
4175 narrower type exactly and is aligned for it
4176 The resulting extension to its nominal type (a fullword type)
4177 must fit the same conditions as for other extensions. */
4180 && INT_CST_LT_UNSIGNED (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (op)))
4181 && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
4182 && (! uns || final_prec <= innerprec || unsignedp))
4184 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4185 TREE_OPERAND (op, 1));
4186 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4187 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4194 /* Return OP or a simpler expression for a narrower value
4195 which can be sign-extended or zero-extended to give back OP.
4196 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
4197 or 0 if the value should be sign-extended. */
4200 get_narrower (tree op, int *unsignedp_ptr)
4206 while (TREE_CODE (op) == NOP_EXPR)
4209 = (TYPE_PRECISION (TREE_TYPE (op))
4210 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
4212 /* Truncations are many-one so cannot be removed. */
4216 /* See what's inside this conversion. If we decide to strip it,
4221 op = TREE_OPERAND (op, 0);
4222 /* An extension: the outermost one can be stripped,
4223 but remember whether it is zero or sign extension. */
4225 uns = TREE_UNSIGNED (TREE_TYPE (op));
4226 /* Otherwise, if a sign extension has been stripped,
4227 only sign extensions can now be stripped;
4228 if a zero extension has been stripped, only zero-extensions. */
4229 else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
4233 else /* bitschange == 0 */
4235 /* A change in nominal type can always be stripped, but we must
4236 preserve the unsignedness. */
4238 uns = TREE_UNSIGNED (TREE_TYPE (op));
4240 op = TREE_OPERAND (op, 0);
4246 if (TREE_CODE (op) == COMPONENT_REF
4247 /* Since type_for_size always gives an integer type. */
4248 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
4249 /* Ensure field is laid out already. */
4250 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0)
4252 unsigned HOST_WIDE_INT innerprec
4253 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4254 int unsignedp = (TREE_UNSIGNED (TREE_OPERAND (op, 1))
4255 || TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
4256 tree type = (*lang_hooks.types.type_for_size) (innerprec, unsignedp);
4258 /* We can get this structure field in a narrower type that fits it,
4259 but the resulting extension to its nominal type (a fullword type)
4260 must satisfy the same conditions as for other extensions.
4262 Do this only for fields that are aligned (not bit-fields),
4263 because when bit-field insns will be used there is no
4264 advantage in doing this. */
4266 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
4267 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
4268 && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
4272 uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
4273 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4274 TREE_OPERAND (op, 1));
4275 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4276 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4279 *unsignedp_ptr = uns;
4283 /* Nonzero if integer constant C has a value that is permissible
4284 for type TYPE (an INTEGER_TYPE). */
4287 int_fits_type_p (tree c, tree type)
4289 tree type_low_bound = TYPE_MIN_VALUE (type);
4290 tree type_high_bound = TYPE_MAX_VALUE (type);
4291 int ok_for_low_bound, ok_for_high_bound;
4293 /* Perform some generic filtering first, which may allow making a decision
4294 even if the bounds are not constant. First, negative integers never fit
4295 in unsigned types, */
4296 if ((TREE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0)
4297 /* Also, unsigned integers with top bit set never fit signed types. */
4298 || (! TREE_UNSIGNED (type)
4299 && TREE_UNSIGNED (TREE_TYPE (c)) && tree_int_cst_msb (c)))
4302 /* If at least one bound of the type is a constant integer, we can check
4303 ourselves and maybe make a decision. If no such decision is possible, but
4304 this type is a subtype, try checking against that. Otherwise, use
4305 force_fit_type, which checks against the precision.
4307 Compute the status for each possibly constant bound, and return if we see
4308 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
4309 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
4310 for "constant known to fit". */
4312 ok_for_low_bound = -1;
4313 ok_for_high_bound = -1;
4315 /* Check if C >= type_low_bound. */
4316 if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
4318 ok_for_low_bound = ! tree_int_cst_lt (c, type_low_bound);
4319 if (! ok_for_low_bound)
4323 /* Check if c <= type_high_bound. */
4324 if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
4326 ok_for_high_bound = ! tree_int_cst_lt (type_high_bound, c);
4327 if (! ok_for_high_bound)
4331 /* If the constant fits both bounds, the result is known. */
4332 if (ok_for_low_bound == 1 && ok_for_high_bound == 1)
4335 /* If we haven't been able to decide at this point, there nothing more we
4336 can check ourselves here. Look at the base type if we have one. */
4337 else if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != 0)
4338 return int_fits_type_p (c, TREE_TYPE (type));
4340 /* Or to force_fit_type, if nothing else. */
4344 TREE_TYPE (c) = type;
4345 return !force_fit_type (c, 0);
4349 /* Returns true if T is, contains, or refers to a type with variable
4350 size. This concept is more general than that of C99 'variably
4351 modified types': in C99, a struct type is never variably modified
4352 because a VLA may not appear as a structure member. However, in
4355 struct S { int i[f()]; };
4357 is valid, and other languages may define similar constructs. */
4360 variably_modified_type_p (tree type)
4364 if (type == error_mark_node)
4367 /* If TYPE itself has variable size, it is variably modified.
4369 We do not yet have a representation of the C99 '[*]' syntax.
4370 When a representation is chosen, this function should be modified
4371 to test for that case as well. */
4372 t = TYPE_SIZE (type);
4373 if (t && t != error_mark_node && TREE_CODE (t) != INTEGER_CST)
4376 switch (TREE_CODE (type))
4379 case REFERENCE_TYPE:
4381 /* If TYPE is a pointer or reference, it is variably modified if
4382 the type pointed to is variably modified. Similarly for arrays;
4383 note that VLAs are handled by the TYPE_SIZE check above. */
4384 return variably_modified_type_p (TREE_TYPE (type));
4388 /* If TYPE is a function type, it is variably modified if any of the
4389 parameters or the return type are variably modified. */
4393 if (variably_modified_type_p (TREE_TYPE (type)))
4395 for (parm = TYPE_ARG_TYPES (type);
4396 parm && parm != void_list_node;
4397 parm = TREE_CHAIN (parm))
4398 if (variably_modified_type_p (TREE_VALUE (parm)))
4404 /* Scalar types are variably modified if their end points
4406 t = TYPE_MIN_VALUE (type);
4407 if (t && t != error_mark_node && TREE_CODE (t) != INTEGER_CST)
4409 t = TYPE_MAX_VALUE (type);
4410 if (t && t != error_mark_node && TREE_CODE (t) != INTEGER_CST)
4418 /* The current language may have other cases to check, but in general,
4419 all other types are not variably modified. */
4420 return (*lang_hooks.tree_inlining.var_mod_type_p) (type);
4423 /* Given a DECL or TYPE, return the scope in which it was declared, or
4424 NULL_TREE if there is no containing scope. */
4427 get_containing_scope (tree t)
4429 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
4432 /* Return the innermost context enclosing DECL that is
4433 a FUNCTION_DECL, or zero if none. */
4436 decl_function_context (tree decl)
4440 if (TREE_CODE (decl) == ERROR_MARK)
4443 if (TREE_CODE (decl) == SAVE_EXPR)
4444 context = SAVE_EXPR_CONTEXT (decl);
4446 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
4447 where we look up the function at runtime. Such functions always take
4448 a first argument of type 'pointer to real context'.
4450 C++ should really be fixed to use DECL_CONTEXT for the real context,
4451 and use something else for the "virtual context". */
4452 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
4455 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4457 context = DECL_CONTEXT (decl);
4459 while (context && TREE_CODE (context) != FUNCTION_DECL)
4461 if (TREE_CODE (context) == BLOCK)
4462 context = BLOCK_SUPERCONTEXT (context);
4464 context = get_containing_scope (context);
4470 /* Return the innermost context enclosing DECL that is
4471 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
4472 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
4475 decl_type_context (tree decl)
4477 tree context = DECL_CONTEXT (decl);
4480 switch (TREE_CODE (context))
4482 case NAMESPACE_DECL:
4483 case TRANSLATION_UNIT_DECL:
4488 case QUAL_UNION_TYPE:
4493 context = DECL_CONTEXT (context);
4497 context = BLOCK_SUPERCONTEXT (context);
4507 /* CALL is a CALL_EXPR. Return the declaration for the function
4508 called, or NULL_TREE if the called function cannot be
4512 get_callee_fndecl (tree call)
4516 /* It's invalid to call this function with anything but a
4518 if (TREE_CODE (call) != CALL_EXPR)
4521 /* The first operand to the CALL is the address of the function
4523 addr = TREE_OPERAND (call, 0);
4527 /* If this is a readonly function pointer, extract its initial value. */
4528 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
4529 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
4530 && DECL_INITIAL (addr))
4531 addr = DECL_INITIAL (addr);
4533 /* If the address is just `&f' for some function `f', then we know
4534 that `f' is being called. */
4535 if (TREE_CODE (addr) == ADDR_EXPR
4536 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
4537 return TREE_OPERAND (addr, 0);
4539 /* We couldn't figure out what was being called. Maybe the front
4540 end has some idea. */
4541 return (*lang_hooks.lang_get_callee_fndecl) (call);
4544 /* Print debugging information about tree nodes generated during the compile,
4545 and any language-specific information. */
4548 dump_tree_statistics (void)
4550 #ifdef GATHER_STATISTICS
4552 int total_nodes, total_bytes;
4555 fprintf (stderr, "\n??? tree nodes created\n\n");
4556 #ifdef GATHER_STATISTICS
4557 fprintf (stderr, "Kind Nodes Bytes\n");
4558 fprintf (stderr, "---------------------------------------\n");
4559 total_nodes = total_bytes = 0;
4560 for (i = 0; i < (int) all_kinds; i++)
4562 fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
4563 tree_node_counts[i], tree_node_sizes[i]);
4564 total_nodes += tree_node_counts[i];
4565 total_bytes += tree_node_sizes[i];
4567 fprintf (stderr, "---------------------------------------\n");
4568 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
4569 fprintf (stderr, "---------------------------------------\n");
4571 fprintf (stderr, "(No per-node statistics)\n");
4573 print_type_hash_statistics ();
4574 (*lang_hooks.print_statistics) ();
4577 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
4579 /* Generate a crc32 of a string. */
4582 crc32_string (unsigned chksum, const char *string)
4586 unsigned value = *string << 24;
4589 for (ix = 8; ix--; value <<= 1)
4593 feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
4602 /* P is a string that will be used in a symbol. Mask out any characters
4603 that are not valid in that context. */
4606 clean_symbol_name (char *p)
4610 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
4613 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
4620 /* Generate a name for a function unique to this translation unit.
4621 TYPE is some string to identify the purpose of this function to the
4622 linker or collect2. */
4625 get_file_function_name_long (const char *type)
4631 if (first_global_object_name)
4632 p = first_global_object_name;
4635 /* We don't have anything that we know to be unique to this translation
4636 unit, so use what we do have and throw in some randomness. */
4638 const char *name = weak_global_object_name;
4639 const char *file = main_input_filename;
4644 file = input_filename;
4646 len = strlen (file);
4647 q = alloca (9 * 2 + len + 1);
4648 memcpy (q, file, len + 1);
4649 clean_symbol_name (q);
4651 sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
4652 crc32_string (0, flag_random_seed));
4657 buf = alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p) + strlen (type));
4659 /* Set up the name of the file-level functions we may need.
4660 Use a global object (which is already required to be unique over
4661 the program) rather than the file name (which imposes extra
4663 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
4665 return get_identifier (buf);
4668 /* If KIND=='I', return a suitable global initializer (constructor) name.
4669 If KIND=='D', return a suitable global clean-up (destructor) name. */
4672 get_file_function_name (int kind)
4679 return get_file_function_name_long (p);
4682 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
4683 The result is placed in BUFFER (which has length BIT_SIZE),
4684 with one bit in each char ('\000' or '\001').
4686 If the constructor is constant, NULL_TREE is returned.
4687 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
4690 get_set_constructor_bits (tree init, char *buffer, int bit_size)
4694 HOST_WIDE_INT domain_min
4695 = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init))), 0);
4696 tree non_const_bits = NULL_TREE;
4698 for (i = 0; i < bit_size; i++)
4701 for (vals = TREE_OPERAND (init, 1);
4702 vals != NULL_TREE; vals = TREE_CHAIN (vals))
4704 if (!host_integerp (TREE_VALUE (vals), 0)
4705 || (TREE_PURPOSE (vals) != NULL_TREE
4706 && !host_integerp (TREE_PURPOSE (vals), 0)))
4708 = tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits);
4709 else if (TREE_PURPOSE (vals) != NULL_TREE)
4711 /* Set a range of bits to ones. */
4712 HOST_WIDE_INT lo_index
4713 = tree_low_cst (TREE_PURPOSE (vals), 0) - domain_min;
4714 HOST_WIDE_INT hi_index
4715 = tree_low_cst (TREE_VALUE (vals), 0) - domain_min;
4717 if (lo_index < 0 || lo_index >= bit_size
4718 || hi_index < 0 || hi_index >= bit_size)
4720 for (; lo_index <= hi_index; lo_index++)
4721 buffer[lo_index] = 1;
4725 /* Set a single bit to one. */
4727 = tree_low_cst (TREE_VALUE (vals), 0) - domain_min;
4728 if (index < 0 || index >= bit_size)
4730 error ("invalid initializer for bit string");
4736 return non_const_bits;
4739 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
4740 The result is placed in BUFFER (which is an array of bytes).
4741 If the constructor is constant, NULL_TREE is returned.
4742 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
4745 get_set_constructor_bytes (tree init, unsigned char *buffer, int wd_size)
4748 int set_word_size = BITS_PER_UNIT;
4749 int bit_size = wd_size * set_word_size;
4751 unsigned char *bytep = buffer;
4752 char *bit_buffer = alloca (bit_size);
4753 tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
4755 for (i = 0; i < wd_size; i++)
4758 for (i = 0; i < bit_size; i++)
4762 if (BYTES_BIG_ENDIAN)
4763 *bytep |= (1 << (set_word_size - 1 - bit_pos));
4765 *bytep |= 1 << bit_pos;
4768 if (bit_pos >= set_word_size)
4769 bit_pos = 0, bytep++;
4771 return non_const_bits;
4774 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
4775 /* Complain that the tree code of NODE does not match the expected CODE.
4776 FILE, LINE, and FUNCTION are of the caller. */
4779 tree_check_failed (const tree node, enum tree_code code, const char *file,
4780 int line, const char *function)
4782 internal_error ("tree check: expected %s, have %s in %s, at %s:%d",
4783 tree_code_name[code], tree_code_name[TREE_CODE (node)],
4784 function, trim_filename (file), line);
4787 /* Similar to above, except that we check for a class of tree
4788 code, given in CL. */
4791 tree_class_check_failed (const tree node, int cl, const char *file,
4792 int line, const char *function)
4795 ("tree check: expected class '%c', have '%c' (%s) in %s, at %s:%d",
4796 cl, TREE_CODE_CLASS (TREE_CODE (node)),
4797 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
4800 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
4801 (dynamically sized) vector. */
4804 tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
4805 const char *function)
4808 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
4809 idx + 1, len, function, trim_filename (file), line);
4812 /* Similar to above, except that the check is for the bounds of the operand
4813 vector of an expression node. */
4816 tree_operand_check_failed (int idx, enum tree_code code, const char *file,
4817 int line, const char *function)
4820 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
4821 idx + 1, tree_code_name[code], TREE_CODE_LENGTH (code),
4822 function, trim_filename (file), line);
4824 #endif /* ENABLE_TREE_CHECKING */
4826 /* For a new vector type node T, build the information necessary for
4827 debugging output. */
4830 finish_vector_type (tree t)
4835 tree index = build_int_2 (TYPE_VECTOR_SUBPARTS (t) - 1, 0);
4836 tree array = build_array_type (TREE_TYPE (t),
4837 build_index_type (index));
4838 tree rt = make_node (RECORD_TYPE);
4840 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
4841 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
4843 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
4844 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
4845 the representation type, and we want to find that die when looking up
4846 the vector type. This is most easily achieved by making the TYPE_UID
4848 TYPE_UID (rt) = TYPE_UID (t);
4852 /* Create nodes for all integer types (and error_mark_node) using the sizes
4853 of C datatypes. The caller should call set_sizetype soon after calling
4854 this function to select one of the types as sizetype. */
4857 build_common_tree_nodes (int signed_char)
4859 error_mark_node = make_node (ERROR_MARK);
4860 TREE_TYPE (error_mark_node) = error_mark_node;
4862 initialize_sizetypes ();
4864 /* Define both `signed char' and `unsigned char'. */
4865 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
4866 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4868 /* Define `char', which is like either `signed char' or `unsigned char'
4869 but not the same as either. */
4872 ? make_signed_type (CHAR_TYPE_SIZE)
4873 : make_unsigned_type (CHAR_TYPE_SIZE));
4875 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
4876 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
4877 integer_type_node = make_signed_type (INT_TYPE_SIZE);
4878 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
4879 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
4880 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
4881 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
4882 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
4884 /* Define a boolean type. This type only represents boolean values but
4885 may be larger than char depending on the value of BOOL_TYPE_SIZE.
4886 Front ends which want to override this size (i.e. Java) can redefine
4887 boolean_type_node before calling build_common_tree_nodes_2. */
4888 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
4889 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
4890 TYPE_MAX_VALUE (boolean_type_node) = build_int_2 (1, 0);
4891 TREE_TYPE (TYPE_MAX_VALUE (boolean_type_node)) = boolean_type_node;
4892 TYPE_PRECISION (boolean_type_node) = 1;
4894 intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
4895 intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
4896 intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
4897 intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
4898 intTI_type_node = make_signed_type (GET_MODE_BITSIZE (TImode));
4900 unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
4901 unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
4902 unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
4903 unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
4904 unsigned_intTI_type_node = make_unsigned_type (GET_MODE_BITSIZE (TImode));
4906 access_public_node = get_identifier ("public");
4907 access_protected_node = get_identifier ("protected");
4908 access_private_node = get_identifier ("private");
4911 /* Call this function after calling build_common_tree_nodes and set_sizetype.
4912 It will create several other common tree nodes. */
4915 build_common_tree_nodes_2 (int short_double)
4917 /* Define these next since types below may used them. */
4918 integer_zero_node = build_int_2 (0, 0);
4919 integer_one_node = build_int_2 (1, 0);
4920 integer_minus_one_node = build_int_2 (-1, -1);
4922 size_zero_node = size_int (0);
4923 size_one_node = size_int (1);
4924 bitsize_zero_node = bitsize_int (0);
4925 bitsize_one_node = bitsize_int (1);
4926 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
4928 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
4929 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
4931 void_type_node = make_node (VOID_TYPE);
4932 layout_type (void_type_node);
4934 /* We are not going to have real types in C with less than byte alignment,
4935 so we might as well not have any types that claim to have it. */
4936 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
4937 TYPE_USER_ALIGN (void_type_node) = 0;
4939 null_pointer_node = build_int_2 (0, 0);
4940 TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
4941 layout_type (TREE_TYPE (null_pointer_node));
4943 ptr_type_node = build_pointer_type (void_type_node);
4945 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
4947 float_type_node = make_node (REAL_TYPE);
4948 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
4949 layout_type (float_type_node);
4951 double_type_node = make_node (REAL_TYPE);
4953 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
4955 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
4956 layout_type (double_type_node);
4958 long_double_type_node = make_node (REAL_TYPE);
4959 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
4960 layout_type (long_double_type_node);
4962 float_ptr_type_node = build_pointer_type (float_type_node);
4963 double_ptr_type_node = build_pointer_type (double_type_node);
4964 long_double_ptr_type_node = build_pointer_type (long_double_type_node);
4965 integer_ptr_type_node = build_pointer_type (integer_type_node);
4967 complex_integer_type_node = make_node (COMPLEX_TYPE);
4968 TREE_TYPE (complex_integer_type_node) = integer_type_node;
4969 layout_type (complex_integer_type_node);
4971 complex_float_type_node = make_node (COMPLEX_TYPE);
4972 TREE_TYPE (complex_float_type_node) = float_type_node;
4973 layout_type (complex_float_type_node);
4975 complex_double_type_node = make_node (COMPLEX_TYPE);
4976 TREE_TYPE (complex_double_type_node) = double_type_node;
4977 layout_type (complex_double_type_node);
4979 complex_long_double_type_node = make_node (COMPLEX_TYPE);
4980 TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
4981 layout_type (complex_long_double_type_node);
4984 tree t = (*targetm.build_builtin_va_list) ();
4986 /* Many back-ends define record types without setting TYPE_NAME.
4987 If we copied the record type here, we'd keep the original
4988 record type without a name. This breaks name mangling. So,
4989 don't copy record types and let c_common_nodes_and_builtins()
4990 declare the type to be __builtin_va_list. */
4991 if (TREE_CODE (t) != RECORD_TYPE)
4992 t = build_type_copy (t);
4994 va_list_type_node = t;
4997 unsigned_V4SI_type_node
4998 = make_vector (V4SImode, unsigned_intSI_type_node, 1);
4999 unsigned_V2HI_type_node
5000 = make_vector (V2HImode, unsigned_intHI_type_node, 1);
5001 unsigned_V2SI_type_node
5002 = make_vector (V2SImode, unsigned_intSI_type_node, 1);
5003 unsigned_V2DI_type_node
5004 = make_vector (V2DImode, unsigned_intDI_type_node, 1);
5005 unsigned_V4HI_type_node
5006 = make_vector (V4HImode, unsigned_intHI_type_node, 1);
5007 unsigned_V8QI_type_node
5008 = make_vector (V8QImode, unsigned_intQI_type_node, 1);
5009 unsigned_V8HI_type_node
5010 = make_vector (V8HImode, unsigned_intHI_type_node, 1);
5011 unsigned_V16QI_type_node
5012 = make_vector (V16QImode, unsigned_intQI_type_node, 1);
5013 unsigned_V1DI_type_node
5014 = make_vector (V1DImode, unsigned_intDI_type_node, 1);
5016 V16SF_type_node = make_vector (V16SFmode, float_type_node, 0);
5017 V4SF_type_node = make_vector (V4SFmode, float_type_node, 0);
5018 V4SI_type_node = make_vector (V4SImode, intSI_type_node, 0);
5019 V2HI_type_node = make_vector (V2HImode, intHI_type_node, 0);
5020 V2SI_type_node = make_vector (V2SImode, intSI_type_node, 0);
5021 V2DI_type_node = make_vector (V2DImode, intDI_type_node, 0);
5022 V4HI_type_node = make_vector (V4HImode, intHI_type_node, 0);
5023 V8QI_type_node = make_vector (V8QImode, intQI_type_node, 0);
5024 V8HI_type_node = make_vector (V8HImode, intHI_type_node, 0);
5025 V2SF_type_node = make_vector (V2SFmode, float_type_node, 0);
5026 V2DF_type_node = make_vector (V2DFmode, double_type_node, 0);
5027 V16QI_type_node = make_vector (V16QImode, intQI_type_node, 0);
5028 V1DI_type_node = make_vector (V1DImode, intDI_type_node, 0);
5029 V4DF_type_node = make_vector (V4DFmode, double_type_node, 0);
5032 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
5035 If we requested a pointer to a vector, build up the pointers that
5036 we stripped off while looking for the inner type. Similarly for
5037 return values from functions.
5039 The argument TYPE is the top of the chain, and BOTTOM is the
5040 new type which we will point to. */
5043 reconstruct_complex_type (tree type, tree bottom)
5047 if (POINTER_TYPE_P (type))
5049 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5050 outer = build_pointer_type (inner);
5052 else if (TREE_CODE (type) == ARRAY_TYPE)
5054 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5055 outer = build_array_type (inner, TYPE_DOMAIN (type));
5057 else if (TREE_CODE (type) == FUNCTION_TYPE)
5059 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5060 outer = build_function_type (inner, TYPE_ARG_TYPES (type));
5062 else if (TREE_CODE (type) == METHOD_TYPE)
5064 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5065 outer = build_method_type_directly (TYPE_METHOD_BASETYPE (type),
5067 TYPE_ARG_TYPES (type));
5072 TREE_READONLY (outer) = TREE_READONLY (type);
5073 TREE_THIS_VOLATILE (outer) = TREE_THIS_VOLATILE (type);
5078 /* Returns a vector tree node given a vector mode, the inner type, and
5082 make_vector (enum machine_mode mode, tree innertype, int unsignedp)
5086 t = make_node (VECTOR_TYPE);
5087 TREE_TYPE (t) = innertype;
5088 TYPE_MODE (t) = mode;
5089 TREE_UNSIGNED (TREE_TYPE (t)) = unsignedp;
5090 finish_vector_type (t);
5095 /* Given an initializer INIT, return TRUE if INIT is zero or some
5096 aggregate of zeros. Otherwise return FALSE. */
5099 initializer_zerop (tree init)
5103 switch (TREE_CODE (init))
5106 return integer_zerop (init);
5108 return real_zerop (init)
5109 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
5111 return integer_zerop (init)
5112 || (real_zerop (init)
5113 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
5114 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
5117 /* Set is empty if it has no elements. */
5118 if ((TREE_CODE (TREE_TYPE (init)) == SET_TYPE)
5119 && CONSTRUCTOR_ELTS (init))
5122 if (AGGREGATE_TYPE_P (TREE_TYPE (init)))
5124 tree aggr_init = CONSTRUCTOR_ELTS (init);
5128 if (! initializer_zerop (TREE_VALUE (aggr_init)))
5130 aggr_init = TREE_CHAIN (aggr_init);
5141 #include "gt-tree.h"