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, 2005 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"
48 #include "tree-iterator.h"
49 #include "basic-block.h"
50 #include "tree-flow.h"
53 /* Each tree code class has an associated string representation.
54 These must correspond to the tree_code_class entries. */
56 const char *const tree_code_class_strings[] =
70 /* obstack.[ch] explicitly declined to prototype this. */
71 extern int _obstack_allocated_p (struct obstack *h, void *obj);
73 #ifdef GATHER_STATISTICS
74 /* Statistics-gathering stuff. */
76 int tree_node_counts[(int) all_kinds];
77 int tree_node_sizes[(int) all_kinds];
79 /* Keep in sync with tree.h:enum tree_node_kind. */
80 static const char * const tree_node_kind_names[] = {
99 #endif /* GATHER_STATISTICS */
101 /* Unique id for next decl created. */
102 static GTY(()) int next_decl_uid;
103 /* Unique id for next type created. */
104 static GTY(()) int next_type_uid = 1;
106 /* Since we cannot rehash a type after it is in the table, we have to
107 keep the hash code. */
109 struct type_hash GTY(())
115 /* Initial size of the hash table (rounded to next prime). */
116 #define TYPE_HASH_INITIAL_SIZE 1000
118 /* Now here is the hash table. When recording a type, it is added to
119 the slot whose index is the hash code. Note that the hash table is
120 used for several kinds of types (function types, array types and
121 array index range types, for now). While all these live in the
122 same table, they are completely independent, and the hash code is
123 computed differently for each of these. */
125 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
126 htab_t type_hash_table;
128 /* Hash table and temporary node for larger integer const values. */
129 static GTY (()) tree int_cst_node;
130 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
131 htab_t int_cst_hash_table;
133 static void set_type_quals (tree, int);
134 static int type_hash_eq (const void *, const void *);
135 static hashval_t type_hash_hash (const void *);
136 static hashval_t int_cst_hash_hash (const void *);
137 static int int_cst_hash_eq (const void *, const void *);
138 static void print_type_hash_statistics (void);
139 static tree make_vector_type (tree, int, enum machine_mode);
140 static int type_hash_marked_p (const void *);
141 static unsigned int type_hash_list (tree, hashval_t);
142 static unsigned int attribute_hash_list (tree, hashval_t);
144 tree global_trees[TI_MAX];
145 tree integer_types[itk_none];
152 /* Initialize the hash table of types. */
153 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
155 int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash,
156 int_cst_hash_eq, NULL);
157 int_cst_node = make_node (INTEGER_CST);
161 /* The name of the object as the assembler will see it (but before any
162 translations made by ASM_OUTPUT_LABELREF). Often this is the same
163 as DECL_NAME. It is an IDENTIFIER_NODE. */
165 decl_assembler_name (tree decl)
167 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
168 lang_hooks.set_decl_assembler_name (decl);
169 return DECL_CHECK (decl)->decl.assembler_name;
172 /* Compute the number of bytes occupied by a tree with code CODE.
173 This function cannot be used for TREE_VEC, PHI_NODE, or STRING_CST
174 codes, which are of variable length. */
176 tree_code_size (enum tree_code code)
178 switch (TREE_CODE_CLASS (code))
180 case tcc_declaration: /* A decl node */
181 return sizeof (struct tree_decl);
183 case tcc_type: /* a type node */
184 return sizeof (struct tree_type);
186 case tcc_reference: /* a reference */
187 case tcc_expression: /* an expression */
188 case tcc_statement: /* an expression with side effects */
189 case tcc_comparison: /* a comparison expression */
190 case tcc_unary: /* a unary arithmetic expression */
191 case tcc_binary: /* a binary arithmetic expression */
192 return (sizeof (struct tree_exp)
193 + (TREE_CODE_LENGTH (code) - 1) * sizeof (char *));
195 case tcc_constant: /* a constant */
198 case INTEGER_CST: return sizeof (struct tree_int_cst);
199 case REAL_CST: return sizeof (struct tree_real_cst);
200 case COMPLEX_CST: return sizeof (struct tree_complex);
201 case VECTOR_CST: return sizeof (struct tree_vector);
202 case STRING_CST: gcc_unreachable ();
204 return lang_hooks.tree_size (code);
207 case tcc_exceptional: /* something random, like an identifier. */
210 case IDENTIFIER_NODE: return lang_hooks.identifier_size;
211 case TREE_LIST: return sizeof (struct tree_list);
214 case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
217 case PHI_NODE: gcc_unreachable ();
219 case SSA_NAME: return sizeof (struct tree_ssa_name);
221 case STATEMENT_LIST: return sizeof (struct tree_statement_list);
222 case BLOCK: return sizeof (struct tree_block);
223 case VALUE_HANDLE: return sizeof (struct tree_value_handle);
226 return lang_hooks.tree_size (code);
234 /* Compute the number of bytes occupied by NODE. This routine only
235 looks at TREE_CODE, except for PHI_NODE and TREE_VEC nodes. */
237 tree_size (tree node)
239 enum tree_code code = TREE_CODE (node);
243 return (sizeof (struct tree_phi_node)
244 + (PHI_ARG_CAPACITY (node) - 1) * sizeof (struct phi_arg_d));
247 return (offsetof (struct tree_binfo, base_binfos)
248 + VEC_embedded_size (tree, BINFO_N_BASE_BINFOS (node)));
251 return (sizeof (struct tree_vec)
252 + (TREE_VEC_LENGTH (node) - 1) * sizeof(char *));
255 return sizeof (struct tree_string) + TREE_STRING_LENGTH (node) - 1;
258 return tree_code_size (code);
262 /* Return a newly allocated node of code CODE. For decl and type
263 nodes, some other fields are initialized. The rest of the node is
264 initialized to zero. This function cannot be used for PHI_NODE or
265 TREE_VEC nodes, which is enforced by asserts in tree_code_size.
267 Achoo! I got a code in the node. */
270 make_node_stat (enum tree_code code MEM_STAT_DECL)
273 enum tree_code_class type = TREE_CODE_CLASS (code);
274 size_t length = tree_code_size (code);
275 #ifdef GATHER_STATISTICS
280 case tcc_declaration: /* A decl node */
284 case tcc_type: /* a type node */
288 case tcc_statement: /* an expression with side effects */
292 case tcc_reference: /* a reference */
296 case tcc_expression: /* an expression */
297 case tcc_comparison: /* a comparison expression */
298 case tcc_unary: /* a unary arithmetic expression */
299 case tcc_binary: /* a binary arithmetic expression */
303 case tcc_constant: /* a constant */
307 case tcc_exceptional: /* something random, like an identifier. */
310 case IDENTIFIER_NODE:
327 kind = ssa_name_kind;
344 tree_node_counts[(int) kind]++;
345 tree_node_sizes[(int) kind] += length;
348 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
350 memset (t, 0, length);
352 TREE_SET_CODE (t, code);
357 TREE_SIDE_EFFECTS (t) = 1;
360 case tcc_declaration:
361 if (code != FUNCTION_DECL)
363 DECL_USER_ALIGN (t) = 0;
364 DECL_IN_SYSTEM_HEADER (t) = in_system_header;
365 DECL_SOURCE_LOCATION (t) = input_location;
366 DECL_UID (t) = next_decl_uid++;
368 /* We have not yet computed the alias set for this declaration. */
369 DECL_POINTER_ALIAS_SET (t) = -1;
373 TYPE_UID (t) = next_type_uid++;
374 TYPE_ALIGN (t) = char_type_node ? TYPE_ALIGN (char_type_node) : 0;
375 TYPE_USER_ALIGN (t) = 0;
376 TYPE_MAIN_VARIANT (t) = t;
378 /* Default to no attributes for type, but let target change that. */
379 TYPE_ATTRIBUTES (t) = NULL_TREE;
380 targetm.set_default_type_attributes (t);
382 /* We have not yet computed the alias set for this type. */
383 TYPE_ALIAS_SET (t) = -1;
387 TREE_CONSTANT (t) = 1;
388 TREE_INVARIANT (t) = 1;
397 case PREDECREMENT_EXPR:
398 case PREINCREMENT_EXPR:
399 case POSTDECREMENT_EXPR:
400 case POSTINCREMENT_EXPR:
401 /* All of these have side-effects, no matter what their
403 TREE_SIDE_EFFECTS (t) = 1;
412 /* Other classes need no special treatment. */
419 /* Return a new node with the same contents as NODE except that its
420 TREE_CHAIN is zero and it has a fresh uid. */
423 copy_node_stat (tree node MEM_STAT_DECL)
426 enum tree_code code = TREE_CODE (node);
429 gcc_assert (code != STATEMENT_LIST);
431 length = tree_size (node);
432 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
433 memcpy (t, node, length);
436 TREE_ASM_WRITTEN (t) = 0;
437 TREE_VISITED (t) = 0;
440 if (TREE_CODE_CLASS (code) == tcc_declaration)
441 DECL_UID (t) = next_decl_uid++;
442 else if (TREE_CODE_CLASS (code) == tcc_type)
444 TYPE_UID (t) = next_type_uid++;
445 /* The following is so that the debug code for
446 the copy is different from the original type.
447 The two statements usually duplicate each other
448 (because they clear fields of the same union),
449 but the optimizer should catch that. */
450 TYPE_SYMTAB_POINTER (t) = 0;
451 TYPE_SYMTAB_ADDRESS (t) = 0;
453 /* Do not copy the values cache. */
454 if (TYPE_CACHED_VALUES_P(t))
456 TYPE_CACHED_VALUES_P (t) = 0;
457 TYPE_CACHED_VALUES (t) = NULL_TREE;
464 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
465 For example, this can copy a list made of TREE_LIST nodes. */
468 copy_list (tree list)
476 head = prev = copy_node (list);
477 next = TREE_CHAIN (list);
480 TREE_CHAIN (prev) = copy_node (next);
481 prev = TREE_CHAIN (prev);
482 next = TREE_CHAIN (next);
488 /* Create an INT_CST node with a LOW value sign extended. */
491 build_int_cst (tree type, HOST_WIDE_INT low)
493 return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
496 /* Create an INT_CST node with a LOW value zero extended. */
499 build_int_cstu (tree type, unsigned HOST_WIDE_INT low)
501 return build_int_cst_wide (type, low, 0);
504 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
505 if it is negative. This function is similar to build_int_cst, but
506 the extra bits outside of the type precision are cleared. Constants
507 with these extra bits may confuse the fold so that it detects overflows
508 even in cases when they do not occur, and in general should be avoided.
509 We cannot however make this a default behavior of build_int_cst without
510 more intrusive changes, since there are parts of gcc that rely on the extra
511 precision of the integer constants. */
514 build_int_cst_type (tree type, HOST_WIDE_INT low)
516 unsigned HOST_WIDE_INT val = (unsigned HOST_WIDE_INT) low;
517 unsigned HOST_WIDE_INT hi;
523 type = integer_type_node;
525 bits = TYPE_PRECISION (type);
526 signed_p = !TYPE_UNSIGNED (type);
528 if (bits >= HOST_BITS_PER_WIDE_INT)
529 negative = (low < 0);
532 /* If the sign bit is inside precision of LOW, use it to determine
533 the sign of the constant. */
534 negative = ((val >> (bits - 1)) & 1) != 0;
536 /* Mask out the bits outside of the precision of the constant. */
537 if (signed_p && negative)
538 val = val | ((~(unsigned HOST_WIDE_INT) 0) << bits);
540 val = val & ~((~(unsigned HOST_WIDE_INT) 0) << bits);
543 /* Determine the high bits. */
544 hi = (negative ? ~(unsigned HOST_WIDE_INT) 0 : 0);
546 /* For unsigned type we need to mask out the bits outside of the type
550 if (bits <= HOST_BITS_PER_WIDE_INT)
554 bits -= HOST_BITS_PER_WIDE_INT;
555 hi = hi & ~((~(unsigned HOST_WIDE_INT) 0) << bits);
559 return build_int_cst_wide (type, val, hi);
562 /* These are the hash table functions for the hash table of INTEGER_CST
563 nodes of a sizetype. */
565 /* Return the hash code code X, an INTEGER_CST. */
568 int_cst_hash_hash (const void *x)
572 return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t)
573 ^ htab_hash_pointer (TREE_TYPE (t)));
576 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
577 is the same as that given by *Y, which is the same. */
580 int_cst_hash_eq (const void *x, const void *y)
585 return (TREE_TYPE (xt) == TREE_TYPE (yt)
586 && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt)
587 && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt));
590 /* Create an INT_CST node of TYPE and value HI:LOW. If TYPE is NULL,
591 integer_type_node is used. The returned node is always shared.
592 For small integers we use a per-type vector cache, for larger ones
593 we use a single hash table. */
596 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
603 type = integer_type_node;
605 switch (TREE_CODE (type))
609 /* Cache NULL pointer. */
618 /* Cache false or true. */
627 if (TYPE_UNSIGNED (type))
630 limit = INTEGER_SHARE_LIMIT;
631 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
637 limit = INTEGER_SHARE_LIMIT + 1;
638 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
640 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
650 /* Look for it in the type's vector of small shared ints. */
651 if (!TYPE_CACHED_VALUES_P (type))
653 TYPE_CACHED_VALUES_P (type) = 1;
654 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
657 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
660 /* Make sure no one is clobbering the shared constant. */
661 gcc_assert (TREE_TYPE (t) == type);
662 gcc_assert (TREE_INT_CST_LOW (t) == low);
663 gcc_assert (TREE_INT_CST_HIGH (t) == hi);
667 /* Create a new shared int. */
668 t = make_node (INTEGER_CST);
670 TREE_INT_CST_LOW (t) = low;
671 TREE_INT_CST_HIGH (t) = hi;
672 TREE_TYPE (t) = type;
674 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
679 /* Use the cache of larger shared ints. */
682 TREE_INT_CST_LOW (int_cst_node) = low;
683 TREE_INT_CST_HIGH (int_cst_node) = hi;
684 TREE_TYPE (int_cst_node) = type;
686 slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT);
690 /* Insert this one into the hash table. */
693 /* Make a new node for next time round. */
694 int_cst_node = make_node (INTEGER_CST);
701 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
702 and the rest are zeros. */
705 build_low_bits_mask (tree type, unsigned bits)
707 unsigned HOST_WIDE_INT low;
709 unsigned HOST_WIDE_INT all_ones = ~(unsigned HOST_WIDE_INT) 0;
711 gcc_assert (bits <= TYPE_PRECISION (type));
713 if (bits == TYPE_PRECISION (type)
714 && !TYPE_UNSIGNED (type))
716 /* Sign extended all-ones mask. */
720 else if (bits <= HOST_BITS_PER_WIDE_INT)
722 low = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
727 bits -= HOST_BITS_PER_WIDE_INT;
729 high = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
732 return build_int_cst_wide (type, low, high);
735 /* Checks that X is integer constant that can be expressed in (unsigned)
736 HOST_WIDE_INT without loss of precision. */
739 cst_and_fits_in_hwi (tree x)
741 if (TREE_CODE (x) != INTEGER_CST)
744 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT)
747 return (TREE_INT_CST_HIGH (x) == 0
748 || TREE_INT_CST_HIGH (x) == -1);
751 /* Return a new VECTOR_CST node whose type is TYPE and whose values
752 are in a list pointed by VALS. */
755 build_vector (tree type, tree vals)
757 tree v = make_node (VECTOR_CST);
758 int over1 = 0, over2 = 0;
761 TREE_VECTOR_CST_ELTS (v) = vals;
762 TREE_TYPE (v) = type;
764 /* Iterate through elements and check for overflow. */
765 for (link = vals; link; link = TREE_CHAIN (link))
767 tree value = TREE_VALUE (link);
769 over1 |= TREE_OVERFLOW (value);
770 over2 |= TREE_CONSTANT_OVERFLOW (value);
773 TREE_OVERFLOW (v) = over1;
774 TREE_CONSTANT_OVERFLOW (v) = over2;
779 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
780 are in a list pointed to by VALS. */
782 build_constructor (tree type, tree vals)
784 tree c = make_node (CONSTRUCTOR);
785 TREE_TYPE (c) = type;
786 CONSTRUCTOR_ELTS (c) = vals;
788 /* ??? May not be necessary. Mirrors what build does. */
791 TREE_SIDE_EFFECTS (c) = TREE_SIDE_EFFECTS (vals);
792 TREE_READONLY (c) = TREE_READONLY (vals);
793 TREE_CONSTANT (c) = TREE_CONSTANT (vals);
794 TREE_INVARIANT (c) = TREE_INVARIANT (vals);
800 /* Return a new REAL_CST node whose type is TYPE and value is D. */
803 build_real (tree type, REAL_VALUE_TYPE d)
809 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
810 Consider doing it via real_convert now. */
812 v = make_node (REAL_CST);
813 dp = ggc_alloc (sizeof (REAL_VALUE_TYPE));
814 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
816 TREE_TYPE (v) = type;
817 TREE_REAL_CST_PTR (v) = dp;
818 TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
822 /* Return a new REAL_CST node whose type is TYPE
823 and whose value is the integer value of the INTEGER_CST node I. */
826 real_value_from_int_cst (tree type, tree i)
830 /* Clear all bits of the real value type so that we can later do
831 bitwise comparisons to see if two values are the same. */
832 memset (&d, 0, sizeof d);
834 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
835 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
836 TYPE_UNSIGNED (TREE_TYPE (i)));
840 /* Given a tree representing an integer constant I, return a tree
841 representing the same value as a floating-point constant of type TYPE. */
844 build_real_from_int_cst (tree type, tree i)
847 int overflow = TREE_OVERFLOW (i);
849 v = build_real (type, real_value_from_int_cst (type, i));
851 TREE_OVERFLOW (v) |= overflow;
852 TREE_CONSTANT_OVERFLOW (v) |= overflow;
856 /* Return a newly constructed STRING_CST node whose value is
857 the LEN characters at STR.
858 The TREE_TYPE is not initialized. */
861 build_string (int len, const char *str)
866 length = len + sizeof (struct tree_string);
868 #ifdef GATHER_STATISTICS
869 tree_node_counts[(int) c_kind]++;
870 tree_node_sizes[(int) c_kind] += length;
873 s = ggc_alloc_tree (length);
875 memset (s, 0, sizeof (struct tree_common));
876 TREE_SET_CODE (s, STRING_CST);
877 TREE_STRING_LENGTH (s) = len;
878 memcpy ((char *) TREE_STRING_POINTER (s), str, len);
879 ((char *) TREE_STRING_POINTER (s))[len] = '\0';
884 /* Return a newly constructed COMPLEX_CST node whose value is
885 specified by the real and imaginary parts REAL and IMAG.
886 Both REAL and IMAG should be constant nodes. TYPE, if specified,
887 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
890 build_complex (tree type, tree real, tree imag)
892 tree t = make_node (COMPLEX_CST);
894 TREE_REALPART (t) = real;
895 TREE_IMAGPART (t) = imag;
896 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
897 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
898 TREE_CONSTANT_OVERFLOW (t)
899 = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
903 /* Build a BINFO with LEN language slots. */
906 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
909 size_t length = (offsetof (struct tree_binfo, base_binfos)
910 + VEC_embedded_size (tree, base_binfos));
912 #ifdef GATHER_STATISTICS
913 tree_node_counts[(int) binfo_kind]++;
914 tree_node_sizes[(int) binfo_kind] += length;
917 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
919 memset (t, 0, offsetof (struct tree_binfo, base_binfos));
921 TREE_SET_CODE (t, TREE_BINFO);
923 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos);
929 /* Build a newly constructed TREE_VEC node of length LEN. */
932 make_tree_vec_stat (int len MEM_STAT_DECL)
935 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
937 #ifdef GATHER_STATISTICS
938 tree_node_counts[(int) vec_kind]++;
939 tree_node_sizes[(int) vec_kind] += length;
942 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
944 memset (t, 0, length);
946 TREE_SET_CODE (t, TREE_VEC);
947 TREE_VEC_LENGTH (t) = len;
952 /* Return 1 if EXPR is the integer constant zero or a complex constant
956 integer_zerop (tree expr)
960 return ((TREE_CODE (expr) == INTEGER_CST
961 && ! TREE_CONSTANT_OVERFLOW (expr)
962 && TREE_INT_CST_LOW (expr) == 0
963 && TREE_INT_CST_HIGH (expr) == 0)
964 || (TREE_CODE (expr) == COMPLEX_CST
965 && integer_zerop (TREE_REALPART (expr))
966 && integer_zerop (TREE_IMAGPART (expr))));
969 /* Return 1 if EXPR is the integer constant one or the corresponding
973 integer_onep (tree expr)
977 return ((TREE_CODE (expr) == INTEGER_CST
978 && ! TREE_CONSTANT_OVERFLOW (expr)
979 && TREE_INT_CST_LOW (expr) == 1
980 && TREE_INT_CST_HIGH (expr) == 0)
981 || (TREE_CODE (expr) == COMPLEX_CST
982 && integer_onep (TREE_REALPART (expr))
983 && integer_zerop (TREE_IMAGPART (expr))));
986 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
987 it contains. Likewise for the corresponding complex constant. */
990 integer_all_onesp (tree expr)
997 if (TREE_CODE (expr) == COMPLEX_CST
998 && integer_all_onesp (TREE_REALPART (expr))
999 && integer_zerop (TREE_IMAGPART (expr)))
1002 else if (TREE_CODE (expr) != INTEGER_CST
1003 || TREE_CONSTANT_OVERFLOW (expr))
1006 uns = TYPE_UNSIGNED (TREE_TYPE (expr));
1008 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1009 && TREE_INT_CST_HIGH (expr) == -1);
1011 /* Note that using TYPE_PRECISION here is wrong. We care about the
1012 actual bits, not the (arbitrary) range of the type. */
1013 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
1014 if (prec >= HOST_BITS_PER_WIDE_INT)
1016 HOST_WIDE_INT high_value;
1019 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1021 /* Can not handle precisions greater than twice the host int size. */
1022 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT);
1023 if (shift_amount == HOST_BITS_PER_WIDE_INT)
1024 /* Shifting by the host word size is undefined according to the ANSI
1025 standard, so we must handle this as a special case. */
1028 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1030 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1031 && TREE_INT_CST_HIGH (expr) == high_value);
1034 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
1037 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1041 integer_pow2p (tree expr)
1044 HOST_WIDE_INT high, low;
1048 if (TREE_CODE (expr) == COMPLEX_CST
1049 && integer_pow2p (TREE_REALPART (expr))
1050 && integer_zerop (TREE_IMAGPART (expr)))
1053 if (TREE_CODE (expr) != INTEGER_CST || TREE_CONSTANT_OVERFLOW (expr))
1056 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1057 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1058 high = TREE_INT_CST_HIGH (expr);
1059 low = TREE_INT_CST_LOW (expr);
1061 /* First clear all bits that are beyond the type's precision in case
1062 we've been sign extended. */
1064 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1066 else if (prec > HOST_BITS_PER_WIDE_INT)
1067 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1071 if (prec < HOST_BITS_PER_WIDE_INT)
1072 low &= ~((HOST_WIDE_INT) (-1) << prec);
1075 if (high == 0 && low == 0)
1078 return ((high == 0 && (low & (low - 1)) == 0)
1079 || (low == 0 && (high & (high - 1)) == 0));
1082 /* Return 1 if EXPR is an integer constant other than zero or a
1083 complex constant other than zero. */
1086 integer_nonzerop (tree expr)
1090 return ((TREE_CODE (expr) == INTEGER_CST
1091 && ! TREE_CONSTANT_OVERFLOW (expr)
1092 && (TREE_INT_CST_LOW (expr) != 0
1093 || TREE_INT_CST_HIGH (expr) != 0))
1094 || (TREE_CODE (expr) == COMPLEX_CST
1095 && (integer_nonzerop (TREE_REALPART (expr))
1096 || integer_nonzerop (TREE_IMAGPART (expr)))));
1099 /* Return the power of two represented by a tree node known to be a
1103 tree_log2 (tree expr)
1106 HOST_WIDE_INT high, low;
1110 if (TREE_CODE (expr) == COMPLEX_CST)
1111 return tree_log2 (TREE_REALPART (expr));
1113 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1114 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1116 high = TREE_INT_CST_HIGH (expr);
1117 low = TREE_INT_CST_LOW (expr);
1119 /* First clear all bits that are beyond the type's precision in case
1120 we've been sign extended. */
1122 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1124 else if (prec > HOST_BITS_PER_WIDE_INT)
1125 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1129 if (prec < HOST_BITS_PER_WIDE_INT)
1130 low &= ~((HOST_WIDE_INT) (-1) << prec);
1133 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
1134 : exact_log2 (low));
1137 /* Similar, but return the largest integer Y such that 2 ** Y is less
1138 than or equal to EXPR. */
1141 tree_floor_log2 (tree expr)
1144 HOST_WIDE_INT high, low;
1148 if (TREE_CODE (expr) == COMPLEX_CST)
1149 return tree_log2 (TREE_REALPART (expr));
1151 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1152 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1154 high = TREE_INT_CST_HIGH (expr);
1155 low = TREE_INT_CST_LOW (expr);
1157 /* First clear all bits that are beyond the type's precision in case
1158 we've been sign extended. Ignore if type's precision hasn't been set
1159 since what we are doing is setting it. */
1161 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
1163 else if (prec > HOST_BITS_PER_WIDE_INT)
1164 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1168 if (prec < HOST_BITS_PER_WIDE_INT)
1169 low &= ~((HOST_WIDE_INT) (-1) << prec);
1172 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
1173 : floor_log2 (low));
1176 /* Return 1 if EXPR is the real constant zero. */
1179 real_zerop (tree expr)
1183 return ((TREE_CODE (expr) == REAL_CST
1184 && ! TREE_CONSTANT_OVERFLOW (expr)
1185 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
1186 || (TREE_CODE (expr) == COMPLEX_CST
1187 && real_zerop (TREE_REALPART (expr))
1188 && real_zerop (TREE_IMAGPART (expr))));
1191 /* Return 1 if EXPR is the real constant one in real or complex form. */
1194 real_onep (tree expr)
1198 return ((TREE_CODE (expr) == REAL_CST
1199 && ! TREE_CONSTANT_OVERFLOW (expr)
1200 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
1201 || (TREE_CODE (expr) == COMPLEX_CST
1202 && real_onep (TREE_REALPART (expr))
1203 && real_zerop (TREE_IMAGPART (expr))));
1206 /* Return 1 if EXPR is the real constant two. */
1209 real_twop (tree expr)
1213 return ((TREE_CODE (expr) == REAL_CST
1214 && ! TREE_CONSTANT_OVERFLOW (expr)
1215 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
1216 || (TREE_CODE (expr) == COMPLEX_CST
1217 && real_twop (TREE_REALPART (expr))
1218 && real_zerop (TREE_IMAGPART (expr))));
1221 /* Return 1 if EXPR is the real constant minus one. */
1224 real_minus_onep (tree expr)
1228 return ((TREE_CODE (expr) == REAL_CST
1229 && ! TREE_CONSTANT_OVERFLOW (expr)
1230 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1))
1231 || (TREE_CODE (expr) == COMPLEX_CST
1232 && real_minus_onep (TREE_REALPART (expr))
1233 && real_zerop (TREE_IMAGPART (expr))));
1236 /* Nonzero if EXP is a constant or a cast of a constant. */
1239 really_constant_p (tree exp)
1241 /* This is not quite the same as STRIP_NOPS. It does more. */
1242 while (TREE_CODE (exp) == NOP_EXPR
1243 || TREE_CODE (exp) == CONVERT_EXPR
1244 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1245 exp = TREE_OPERAND (exp, 0);
1246 return TREE_CONSTANT (exp);
1249 /* Return first list element whose TREE_VALUE is ELEM.
1250 Return 0 if ELEM is not in LIST. */
1253 value_member (tree elem, tree list)
1257 if (elem == TREE_VALUE (list))
1259 list = TREE_CHAIN (list);
1264 /* Return first list element whose TREE_PURPOSE is ELEM.
1265 Return 0 if ELEM is not in LIST. */
1268 purpose_member (tree elem, tree list)
1272 if (elem == TREE_PURPOSE (list))
1274 list = TREE_CHAIN (list);
1279 /* Return nonzero if ELEM is part of the chain CHAIN. */
1282 chain_member (tree elem, tree chain)
1288 chain = TREE_CHAIN (chain);
1294 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1295 We expect a null pointer to mark the end of the chain.
1296 This is the Lisp primitive `length'. */
1299 list_length (tree t)
1302 #ifdef ENABLE_TREE_CHECKING
1310 #ifdef ENABLE_TREE_CHECKING
1313 gcc_assert (p != q);
1321 /* Returns the number of FIELD_DECLs in TYPE. */
1324 fields_length (tree type)
1326 tree t = TYPE_FIELDS (type);
1329 for (; t; t = TREE_CHAIN (t))
1330 if (TREE_CODE (t) == FIELD_DECL)
1336 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1337 by modifying the last node in chain 1 to point to chain 2.
1338 This is the Lisp primitive `nconc'. */
1341 chainon (tree op1, tree op2)
1350 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1352 TREE_CHAIN (t1) = op2;
1354 #ifdef ENABLE_TREE_CHECKING
1357 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1358 gcc_assert (t2 != t1);
1365 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1368 tree_last (tree chain)
1372 while ((next = TREE_CHAIN (chain)))
1377 /* Reverse the order of elements in the chain T,
1378 and return the new head of the chain (old last element). */
1383 tree prev = 0, decl, next;
1384 for (decl = t; decl; decl = next)
1386 next = TREE_CHAIN (decl);
1387 TREE_CHAIN (decl) = prev;
1393 /* Return a newly created TREE_LIST node whose
1394 purpose and value fields are PARM and VALUE. */
1397 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
1399 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
1400 TREE_PURPOSE (t) = parm;
1401 TREE_VALUE (t) = value;
1405 /* Return a newly created TREE_LIST node whose
1406 purpose and value fields are PURPOSE and VALUE
1407 and whose TREE_CHAIN is CHAIN. */
1410 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
1414 node = ggc_alloc_zone_stat (sizeof (struct tree_list),
1415 tree_zone PASS_MEM_STAT);
1417 memset (node, 0, sizeof (struct tree_common));
1419 #ifdef GATHER_STATISTICS
1420 tree_node_counts[(int) x_kind]++;
1421 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
1424 TREE_SET_CODE (node, TREE_LIST);
1425 TREE_CHAIN (node) = chain;
1426 TREE_PURPOSE (node) = purpose;
1427 TREE_VALUE (node) = value;
1432 /* Return the size nominally occupied by an object of type TYPE
1433 when it resides in memory. The value is measured in units of bytes,
1434 and its data type is that normally used for type sizes
1435 (which is the first type created by make_signed_type or
1436 make_unsigned_type). */
1439 size_in_bytes (tree type)
1443 if (type == error_mark_node)
1444 return integer_zero_node;
1446 type = TYPE_MAIN_VARIANT (type);
1447 t = TYPE_SIZE_UNIT (type);
1451 lang_hooks.types.incomplete_type_error (NULL_TREE, type);
1452 return size_zero_node;
1455 if (TREE_CODE (t) == INTEGER_CST)
1456 t = force_fit_type (t, 0, false, false);
1461 /* Return the size of TYPE (in bytes) as a wide integer
1462 or return -1 if the size can vary or is larger than an integer. */
1465 int_size_in_bytes (tree type)
1469 if (type == error_mark_node)
1472 type = TYPE_MAIN_VARIANT (type);
1473 t = TYPE_SIZE_UNIT (type);
1475 || TREE_CODE (t) != INTEGER_CST
1476 || TREE_OVERFLOW (t)
1477 || TREE_INT_CST_HIGH (t) != 0
1478 /* If the result would appear negative, it's too big to represent. */
1479 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
1482 return TREE_INT_CST_LOW (t);
1485 /* Return the bit position of FIELD, in bits from the start of the record.
1486 This is a tree of type bitsizetype. */
1489 bit_position (tree field)
1491 return bit_from_pos (DECL_FIELD_OFFSET (field),
1492 DECL_FIELD_BIT_OFFSET (field));
1495 /* Likewise, but return as an integer. Abort if it cannot be represented
1496 in that way (since it could be a signed value, we don't have the option
1497 of returning -1 like int_size_in_byte can. */
1500 int_bit_position (tree field)
1502 return tree_low_cst (bit_position (field), 0);
1505 /* Return the byte position of FIELD, in bytes from the start of the record.
1506 This is a tree of type sizetype. */
1509 byte_position (tree field)
1511 return byte_from_pos (DECL_FIELD_OFFSET (field),
1512 DECL_FIELD_BIT_OFFSET (field));
1515 /* Likewise, but return as an integer. Abort if it cannot be represented
1516 in that way (since it could be a signed value, we don't have the option
1517 of returning -1 like int_size_in_byte can. */
1520 int_byte_position (tree field)
1522 return tree_low_cst (byte_position (field), 0);
1525 /* Return the strictest alignment, in bits, that T is known to have. */
1530 unsigned int align0, align1;
1532 switch (TREE_CODE (t))
1534 case NOP_EXPR: case CONVERT_EXPR: case NON_LVALUE_EXPR:
1535 /* If we have conversions, we know that the alignment of the
1536 object must meet each of the alignments of the types. */
1537 align0 = expr_align (TREE_OPERAND (t, 0));
1538 align1 = TYPE_ALIGN (TREE_TYPE (t));
1539 return MAX (align0, align1);
1541 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
1542 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
1543 case CLEANUP_POINT_EXPR:
1544 /* These don't change the alignment of an object. */
1545 return expr_align (TREE_OPERAND (t, 0));
1548 /* The best we can do is say that the alignment is the least aligned
1550 align0 = expr_align (TREE_OPERAND (t, 1));
1551 align1 = expr_align (TREE_OPERAND (t, 2));
1552 return MIN (align0, align1);
1554 case LABEL_DECL: case CONST_DECL:
1555 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
1556 if (DECL_ALIGN (t) != 0)
1557 return DECL_ALIGN (t);
1561 return FUNCTION_BOUNDARY;
1567 /* Otherwise take the alignment from that of the type. */
1568 return TYPE_ALIGN (TREE_TYPE (t));
1571 /* Return, as a tree node, the number of elements for TYPE (which is an
1572 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1575 array_type_nelts (tree type)
1577 tree index_type, min, max;
1579 /* If they did it with unspecified bounds, then we should have already
1580 given an error about it before we got here. */
1581 if (! TYPE_DOMAIN (type))
1582 return error_mark_node;
1584 index_type = TYPE_DOMAIN (type);
1585 min = TYPE_MIN_VALUE (index_type);
1586 max = TYPE_MAX_VALUE (index_type);
1588 return (integer_zerop (min)
1590 : fold (build2 (MINUS_EXPR, TREE_TYPE (max), max, min)));
1593 /* If arg is static -- a reference to an object in static storage -- then
1594 return the object. This is not the same as the C meaning of `static'.
1595 If arg isn't static, return NULL. */
1600 switch (TREE_CODE (arg))
1603 /* Nested functions are static, even though taking their address will
1604 involve a trampoline as we unnest the nested function and create
1605 the trampoline on the tree level. */
1609 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
1610 && ! DECL_THREAD_LOCAL (arg)
1611 && ! DECL_NON_ADDR_CONST_P (arg)
1615 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
1619 return TREE_STATIC (arg) ? arg : NULL;
1626 /* If the thing being referenced is not a field, then it is
1627 something language specific. */
1628 if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL)
1629 return (*lang_hooks.staticp) (arg);
1631 /* If we are referencing a bitfield, we can't evaluate an
1632 ADDR_EXPR at compile time and so it isn't a constant. */
1633 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
1636 return staticp (TREE_OPERAND (arg, 0));
1641 case MISALIGNED_INDIRECT_REF:
1642 case ALIGN_INDIRECT_REF:
1644 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
1647 case ARRAY_RANGE_REF:
1648 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
1649 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
1650 return staticp (TREE_OPERAND (arg, 0));
1655 if ((unsigned int) TREE_CODE (arg)
1656 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
1657 return lang_hooks.staticp (arg);
1663 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
1664 Do this to any expression which may be used in more than one place,
1665 but must be evaluated only once.
1667 Normally, expand_expr would reevaluate the expression each time.
1668 Calling save_expr produces something that is evaluated and recorded
1669 the first time expand_expr is called on it. Subsequent calls to
1670 expand_expr just reuse the recorded value.
1672 The call to expand_expr that generates code that actually computes
1673 the value is the first call *at compile time*. Subsequent calls
1674 *at compile time* generate code to use the saved value.
1675 This produces correct result provided that *at run time* control
1676 always flows through the insns made by the first expand_expr
1677 before reaching the other places where the save_expr was evaluated.
1678 You, the caller of save_expr, must make sure this is so.
1680 Constants, and certain read-only nodes, are returned with no
1681 SAVE_EXPR because that is safe. Expressions containing placeholders
1682 are not touched; see tree.def for an explanation of what these
1686 save_expr (tree expr)
1688 tree t = fold (expr);
1691 /* If the tree evaluates to a constant, then we don't want to hide that
1692 fact (i.e. this allows further folding, and direct checks for constants).
1693 However, a read-only object that has side effects cannot be bypassed.
1694 Since it is no problem to reevaluate literals, we just return the
1696 inner = skip_simple_arithmetic (t);
1698 if (TREE_INVARIANT (inner)
1699 || (TREE_READONLY (inner) && ! TREE_SIDE_EFFECTS (inner))
1700 || TREE_CODE (inner) == SAVE_EXPR
1701 || TREE_CODE (inner) == ERROR_MARK)
1704 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
1705 it means that the size or offset of some field of an object depends on
1706 the value within another field.
1708 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
1709 and some variable since it would then need to be both evaluated once and
1710 evaluated more than once. Front-ends must assure this case cannot
1711 happen by surrounding any such subexpressions in their own SAVE_EXPR
1712 and forcing evaluation at the proper time. */
1713 if (contains_placeholder_p (inner))
1716 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
1718 /* This expression might be placed ahead of a jump to ensure that the
1719 value was computed on both sides of the jump. So make sure it isn't
1720 eliminated as dead. */
1721 TREE_SIDE_EFFECTS (t) = 1;
1722 TREE_INVARIANT (t) = 1;
1726 /* Look inside EXPR and into any simple arithmetic operations. Return
1727 the innermost non-arithmetic node. */
1730 skip_simple_arithmetic (tree expr)
1734 /* We don't care about whether this can be used as an lvalue in this
1736 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
1737 expr = TREE_OPERAND (expr, 0);
1739 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
1740 a constant, it will be more efficient to not make another SAVE_EXPR since
1741 it will allow better simplification and GCSE will be able to merge the
1742 computations if they actually occur. */
1746 if (UNARY_CLASS_P (inner))
1747 inner = TREE_OPERAND (inner, 0);
1748 else if (BINARY_CLASS_P (inner))
1750 if (TREE_INVARIANT (TREE_OPERAND (inner, 1)))
1751 inner = TREE_OPERAND (inner, 0);
1752 else if (TREE_INVARIANT (TREE_OPERAND (inner, 0)))
1753 inner = TREE_OPERAND (inner, 1);
1764 /* Return which tree structure is used by T. */
1766 enum tree_node_structure_enum
1767 tree_node_structure (tree t)
1769 enum tree_code code = TREE_CODE (t);
1771 switch (TREE_CODE_CLASS (code))
1773 case tcc_declaration:
1778 case tcc_comparison:
1781 case tcc_expression:
1784 default: /* tcc_constant and tcc_exceptional */
1789 /* tcc_constant cases. */
1790 case INTEGER_CST: return TS_INT_CST;
1791 case REAL_CST: return TS_REAL_CST;
1792 case COMPLEX_CST: return TS_COMPLEX;
1793 case VECTOR_CST: return TS_VECTOR;
1794 case STRING_CST: return TS_STRING;
1795 /* tcc_exceptional cases. */
1796 case ERROR_MARK: return TS_COMMON;
1797 case IDENTIFIER_NODE: return TS_IDENTIFIER;
1798 case TREE_LIST: return TS_LIST;
1799 case TREE_VEC: return TS_VEC;
1800 case PHI_NODE: return TS_PHI_NODE;
1801 case SSA_NAME: return TS_SSA_NAME;
1802 case PLACEHOLDER_EXPR: return TS_COMMON;
1803 case STATEMENT_LIST: return TS_STATEMENT_LIST;
1804 case BLOCK: return TS_BLOCK;
1805 case TREE_BINFO: return TS_BINFO;
1806 case VALUE_HANDLE: return TS_VALUE_HANDLE;
1813 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
1814 or offset that depends on a field within a record. */
1817 contains_placeholder_p (tree exp)
1819 enum tree_code code;
1824 code = TREE_CODE (exp);
1825 if (code == PLACEHOLDER_EXPR)
1828 switch (TREE_CODE_CLASS (code))
1831 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
1832 position computations since they will be converted into a
1833 WITH_RECORD_EXPR involving the reference, which will assume
1834 here will be valid. */
1835 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
1837 case tcc_exceptional:
1838 if (code == TREE_LIST)
1839 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
1840 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
1845 case tcc_comparison:
1846 case tcc_expression:
1850 /* Ignoring the first operand isn't quite right, but works best. */
1851 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
1854 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
1855 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
1856 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
1862 switch (TREE_CODE_LENGTH (code))
1865 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
1867 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
1868 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
1879 /* Return true if any part of the computation of TYPE involves a
1880 PLACEHOLDER_EXPR. This includes size, bounds, qualifiers
1881 (for QUAL_UNION_TYPE) and field positions. */
1884 type_contains_placeholder_1 (tree type)
1886 /* If the size contains a placeholder or the parent type (component type in
1887 the case of arrays) type involves a placeholder, this type does. */
1888 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
1889 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
1890 || (TREE_TYPE (type) != 0
1891 && type_contains_placeholder_p (TREE_TYPE (type))))
1894 /* Now do type-specific checks. Note that the last part of the check above
1895 greatly limits what we have to do below. */
1896 switch (TREE_CODE (type))
1905 case REFERENCE_TYPE:
1914 /* Here we just check the bounds. */
1915 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
1916 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
1919 /* We're already checked the component type (TREE_TYPE), so just check
1921 return type_contains_placeholder_p (TYPE_DOMAIN (type));
1925 case QUAL_UNION_TYPE:
1929 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1930 if (TREE_CODE (field) == FIELD_DECL
1931 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
1932 || (TREE_CODE (type) == QUAL_UNION_TYPE
1933 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
1934 || type_contains_placeholder_p (TREE_TYPE (field))))
1946 type_contains_placeholder_p (tree type)
1950 /* If the contains_placeholder_bits field has been initialized,
1951 then we know the answer. */
1952 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
1953 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
1955 /* Indicate that we've seen this type node, and the answer is false.
1956 This is what we want to return if we run into recursion via fields. */
1957 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
1959 /* Compute the real value. */
1960 result = type_contains_placeholder_1 (type);
1962 /* Store the real value. */
1963 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
1968 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
1969 return a tree with all occurrences of references to F in a
1970 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
1971 contains only arithmetic expressions or a CALL_EXPR with a
1972 PLACEHOLDER_EXPR occurring only in its arglist. */
1975 substitute_in_expr (tree exp, tree f, tree r)
1977 enum tree_code code = TREE_CODE (exp);
1982 /* We handle TREE_LIST and COMPONENT_REF separately. */
1983 if (code == TREE_LIST)
1985 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
1986 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
1987 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
1990 return tree_cons (TREE_PURPOSE (exp), op1, op0);
1992 else if (code == COMPONENT_REF)
1994 /* If this expression is getting a value from a PLACEHOLDER_EXPR
1995 and it is the right field, replace it with R. */
1996 for (inner = TREE_OPERAND (exp, 0);
1997 REFERENCE_CLASS_P (inner);
1998 inner = TREE_OPERAND (inner, 0))
2000 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2001 && TREE_OPERAND (exp, 1) == f)
2004 /* If this expression hasn't been completed let, leave it alone. */
2005 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0)
2008 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2009 if (op0 == TREE_OPERAND (exp, 0))
2012 new = fold (build3 (COMPONENT_REF, TREE_TYPE (exp),
2013 op0, TREE_OPERAND (exp, 1), NULL_TREE));
2016 switch (TREE_CODE_CLASS (code))
2019 case tcc_declaration:
2022 case tcc_exceptional:
2025 case tcc_comparison:
2026 case tcc_expression:
2028 switch (TREE_CODE_LENGTH (code))
2034 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2035 if (op0 == TREE_OPERAND (exp, 0))
2038 new = fold (build1 (code, TREE_TYPE (exp), op0));
2042 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2043 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2045 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2048 new = fold (build2 (code, TREE_TYPE (exp), op0, op1));
2052 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2053 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2054 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
2056 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2057 && op2 == TREE_OPERAND (exp, 2))
2060 new = fold (build3 (code, TREE_TYPE (exp), op0, op1, op2));
2072 TREE_READONLY (new) = TREE_READONLY (exp);
2076 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
2077 for it within OBJ, a tree that is an object or a chain of references. */
2080 substitute_placeholder_in_expr (tree exp, tree obj)
2082 enum tree_code code = TREE_CODE (exp);
2083 tree op0, op1, op2, op3;
2085 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
2086 in the chain of OBJ. */
2087 if (code == PLACEHOLDER_EXPR)
2089 tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
2092 for (elt = obj; elt != 0;
2093 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
2094 || TREE_CODE (elt) == COND_EXPR)
2095 ? TREE_OPERAND (elt, 1)
2096 : (REFERENCE_CLASS_P (elt)
2097 || UNARY_CLASS_P (elt)
2098 || BINARY_CLASS_P (elt)
2099 || EXPRESSION_CLASS_P (elt))
2100 ? TREE_OPERAND (elt, 0) : 0))
2101 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
2104 for (elt = obj; elt != 0;
2105 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
2106 || TREE_CODE (elt) == COND_EXPR)
2107 ? TREE_OPERAND (elt, 1)
2108 : (REFERENCE_CLASS_P (elt)
2109 || UNARY_CLASS_P (elt)
2110 || BINARY_CLASS_P (elt)
2111 || EXPRESSION_CLASS_P (elt))
2112 ? TREE_OPERAND (elt, 0) : 0))
2113 if (POINTER_TYPE_P (TREE_TYPE (elt))
2114 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
2116 return fold (build1 (INDIRECT_REF, need_type, elt));
2118 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2119 survives until RTL generation, there will be an error. */
2123 /* TREE_LIST is special because we need to look at TREE_VALUE
2124 and TREE_CHAIN, not TREE_OPERANDS. */
2125 else if (code == TREE_LIST)
2127 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
2128 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
2129 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2132 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2135 switch (TREE_CODE_CLASS (code))
2138 case tcc_declaration:
2141 case tcc_exceptional:
2144 case tcc_comparison:
2145 case tcc_expression:
2148 switch (TREE_CODE_LENGTH (code))
2154 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2155 if (op0 == TREE_OPERAND (exp, 0))
2158 return fold (build1 (code, TREE_TYPE (exp), op0));
2161 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2162 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2164 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2167 return fold (build2 (code, TREE_TYPE (exp), op0, op1));
2170 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2171 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2172 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2174 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2175 && op2 == TREE_OPERAND (exp, 2))
2178 return fold (build3 (code, TREE_TYPE (exp), op0, op1, op2));
2181 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2182 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2183 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2184 op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
2186 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2187 && op2 == TREE_OPERAND (exp, 2)
2188 && op3 == TREE_OPERAND (exp, 3))
2191 return fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2203 /* Stabilize a reference so that we can use it any number of times
2204 without causing its operands to be evaluated more than once.
2205 Returns the stabilized reference. This works by means of save_expr,
2206 so see the caveats in the comments about save_expr.
2208 Also allows conversion expressions whose operands are references.
2209 Any other kind of expression is returned unchanged. */
2212 stabilize_reference (tree ref)
2215 enum tree_code code = TREE_CODE (ref);
2222 /* No action is needed in this case. */
2228 case FIX_TRUNC_EXPR:
2229 case FIX_FLOOR_EXPR:
2230 case FIX_ROUND_EXPR:
2232 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2236 result = build_nt (INDIRECT_REF,
2237 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2241 result = build_nt (COMPONENT_REF,
2242 stabilize_reference (TREE_OPERAND (ref, 0)),
2243 TREE_OPERAND (ref, 1), NULL_TREE);
2247 result = build_nt (BIT_FIELD_REF,
2248 stabilize_reference (TREE_OPERAND (ref, 0)),
2249 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2250 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2254 result = build_nt (ARRAY_REF,
2255 stabilize_reference (TREE_OPERAND (ref, 0)),
2256 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2257 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2260 case ARRAY_RANGE_REF:
2261 result = build_nt (ARRAY_RANGE_REF,
2262 stabilize_reference (TREE_OPERAND (ref, 0)),
2263 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2264 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2268 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2269 it wouldn't be ignored. This matters when dealing with
2271 return stabilize_reference_1 (ref);
2273 /* If arg isn't a kind of lvalue we recognize, make no change.
2274 Caller should recognize the error for an invalid lvalue. */
2279 return error_mark_node;
2282 TREE_TYPE (result) = TREE_TYPE (ref);
2283 TREE_READONLY (result) = TREE_READONLY (ref);
2284 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2285 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2290 /* Subroutine of stabilize_reference; this is called for subtrees of
2291 references. Any expression with side-effects must be put in a SAVE_EXPR
2292 to ensure that it is only evaluated once.
2294 We don't put SAVE_EXPR nodes around everything, because assigning very
2295 simple expressions to temporaries causes us to miss good opportunities
2296 for optimizations. Among other things, the opportunity to fold in the
2297 addition of a constant into an addressing mode often gets lost, e.g.
2298 "y[i+1] += x;". In general, we take the approach that we should not make
2299 an assignment unless we are forced into it - i.e., that any non-side effect
2300 operator should be allowed, and that cse should take care of coalescing
2301 multiple utterances of the same expression should that prove fruitful. */
2304 stabilize_reference_1 (tree e)
2307 enum tree_code code = TREE_CODE (e);
2309 /* We cannot ignore const expressions because it might be a reference
2310 to a const array but whose index contains side-effects. But we can
2311 ignore things that are actual constant or that already have been
2312 handled by this function. */
2314 if (TREE_INVARIANT (e))
2317 switch (TREE_CODE_CLASS (code))
2319 case tcc_exceptional:
2321 case tcc_declaration:
2322 case tcc_comparison:
2324 case tcc_expression:
2326 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2327 so that it will only be evaluated once. */
2328 /* The reference (r) and comparison (<) classes could be handled as
2329 below, but it is generally faster to only evaluate them once. */
2330 if (TREE_SIDE_EFFECTS (e))
2331 return save_expr (e);
2335 /* Constants need no processing. In fact, we should never reach
2340 /* Division is slow and tends to be compiled with jumps,
2341 especially the division by powers of 2 that is often
2342 found inside of an array reference. So do it just once. */
2343 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
2344 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
2345 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
2346 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
2347 return save_expr (e);
2348 /* Recursively stabilize each operand. */
2349 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
2350 stabilize_reference_1 (TREE_OPERAND (e, 1)));
2354 /* Recursively stabilize each operand. */
2355 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
2362 TREE_TYPE (result) = TREE_TYPE (e);
2363 TREE_READONLY (result) = TREE_READONLY (e);
2364 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
2365 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
2366 TREE_INVARIANT (result) = 1;
2371 /* Low-level constructors for expressions. */
2373 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
2374 TREE_INVARIANT, and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
2377 recompute_tree_invarant_for_addr_expr (tree t)
2380 bool tc = true, ti = true, se = false;
2382 /* We started out assuming this address is both invariant and constant, but
2383 does not have side effects. Now go down any handled components and see if
2384 any of them involve offsets that are either non-constant or non-invariant.
2385 Also check for side-effects.
2387 ??? Note that this code makes no attempt to deal with the case where
2388 taking the address of something causes a copy due to misalignment. */
2390 #define UPDATE_TITCSE(NODE) \
2391 do { tree _node = (NODE); \
2392 if (_node && !TREE_INVARIANT (_node)) ti = false; \
2393 if (_node && !TREE_CONSTANT (_node)) tc = false; \
2394 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
2396 for (node = TREE_OPERAND (t, 0); handled_component_p (node);
2397 node = TREE_OPERAND (node, 0))
2399 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
2400 array reference (probably made temporarily by the G++ front end),
2401 so ignore all the operands. */
2402 if ((TREE_CODE (node) == ARRAY_REF
2403 || TREE_CODE (node) == ARRAY_RANGE_REF)
2404 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
2406 UPDATE_TITCSE (TREE_OPERAND (node, 1));
2407 if (TREE_OPERAND (node, 2))
2408 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2409 if (TREE_OPERAND (node, 3))
2410 UPDATE_TITCSE (TREE_OPERAND (node, 3));
2412 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
2413 FIELD_DECL, apparently. The G++ front end can put something else
2414 there, at least temporarily. */
2415 else if (TREE_CODE (node) == COMPONENT_REF
2416 && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
2418 if (TREE_OPERAND (node, 2))
2419 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2421 else if (TREE_CODE (node) == BIT_FIELD_REF)
2422 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2425 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
2426 the address, since &(*a)->b is a form of addition. If it's a decl, it's
2427 invariant and constant if the decl is static. It's also invariant if it's
2428 a decl in the current function. Taking the address of a volatile variable
2429 is not volatile. If it's a constant, the address is both invariant and
2430 constant. Otherwise it's neither. */
2431 if (TREE_CODE (node) == INDIRECT_REF)
2432 UPDATE_TITCSE (TREE_OPERAND (node, 0));
2433 else if (DECL_P (node))
2437 else if (decl_function_context (node) == current_function_decl
2438 /* Addresses of thread-local variables are invariant. */
2439 || (TREE_CODE (node) == VAR_DECL && DECL_THREAD_LOCAL (node)))
2444 else if (CONSTANT_CLASS_P (node))
2449 se |= TREE_SIDE_EFFECTS (node);
2452 TREE_CONSTANT (t) = tc;
2453 TREE_INVARIANT (t) = ti;
2454 TREE_SIDE_EFFECTS (t) = se;
2455 #undef UPDATE_TITCSE
2458 /* Build an expression of code CODE, data type TYPE, and operands as
2459 specified. Expressions and reference nodes can be created this way.
2460 Constants, decls, types and misc nodes cannot be.
2462 We define 5 non-variadic functions, from 0 to 4 arguments. This is
2463 enough for all extant tree codes. These functions can be called
2464 directly (preferably!), but can also be obtained via GCC preprocessor
2465 magic within the build macro. */
2468 build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
2472 gcc_assert (TREE_CODE_LENGTH (code) == 0);
2474 t = make_node_stat (code PASS_MEM_STAT);
2481 build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL)
2483 int length = sizeof (struct tree_exp);
2484 #ifdef GATHER_STATISTICS
2485 tree_node_kind kind;
2489 #ifdef GATHER_STATISTICS
2490 switch (TREE_CODE_CLASS (code))
2492 case tcc_statement: /* an expression with side effects */
2495 case tcc_reference: /* a reference */
2503 tree_node_counts[(int) kind]++;
2504 tree_node_sizes[(int) kind] += length;
2507 gcc_assert (TREE_CODE_LENGTH (code) == 1);
2509 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
2511 memset (t, 0, sizeof (struct tree_common));
2513 TREE_SET_CODE (t, code);
2515 TREE_TYPE (t) = type;
2516 #ifdef USE_MAPPED_LOCATION
2517 SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
2519 SET_EXPR_LOCUS (t, NULL);
2521 TREE_COMPLEXITY (t) = 0;
2522 TREE_OPERAND (t, 0) = node;
2523 TREE_BLOCK (t) = NULL_TREE;
2524 if (node && !TYPE_P (node))
2526 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
2527 TREE_READONLY (t) = TREE_READONLY (node);
2530 if (TREE_CODE_CLASS (code) == tcc_statement)
2531 TREE_SIDE_EFFECTS (t) = 1;
2537 case PREDECREMENT_EXPR:
2538 case PREINCREMENT_EXPR:
2539 case POSTDECREMENT_EXPR:
2540 case POSTINCREMENT_EXPR:
2541 /* All of these have side-effects, no matter what their
2543 TREE_SIDE_EFFECTS (t) = 1;
2544 TREE_READONLY (t) = 0;
2547 case MISALIGNED_INDIRECT_REF:
2548 case ALIGN_INDIRECT_REF:
2550 /* Whether a dereference is readonly has nothing to do with whether
2551 its operand is readonly. */
2552 TREE_READONLY (t) = 0;
2557 recompute_tree_invarant_for_addr_expr (t);
2561 if (TREE_CODE_CLASS (code) == tcc_unary
2562 && node && !TYPE_P (node)
2563 && TREE_CONSTANT (node))
2564 TREE_CONSTANT (t) = 1;
2565 if (TREE_CODE_CLASS (code) == tcc_unary
2566 && node && TREE_INVARIANT (node))
2567 TREE_INVARIANT (t) = 1;
2568 if (TREE_CODE_CLASS (code) == tcc_reference
2569 && node && TREE_THIS_VOLATILE (node))
2570 TREE_THIS_VOLATILE (t) = 1;
2577 #define PROCESS_ARG(N) \
2579 TREE_OPERAND (t, N) = arg##N; \
2580 if (arg##N &&!TYPE_P (arg##N)) \
2582 if (TREE_SIDE_EFFECTS (arg##N)) \
2584 if (!TREE_READONLY (arg##N)) \
2586 if (!TREE_CONSTANT (arg##N)) \
2588 if (!TREE_INVARIANT (arg##N)) \
2594 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
2596 bool constant, read_only, side_effects, invariant;
2599 gcc_assert (TREE_CODE_LENGTH (code) == 2);
2601 t = make_node_stat (code PASS_MEM_STAT);
2604 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
2605 result based on those same flags for the arguments. But if the
2606 arguments aren't really even `tree' expressions, we shouldn't be trying
2609 /* Expressions without side effects may be constant if their
2610 arguments are as well. */
2611 constant = (TREE_CODE_CLASS (code) == tcc_comparison
2612 || TREE_CODE_CLASS (code) == tcc_binary);
2614 side_effects = TREE_SIDE_EFFECTS (t);
2615 invariant = constant;
2620 TREE_READONLY (t) = read_only;
2621 TREE_CONSTANT (t) = constant;
2622 TREE_INVARIANT (t) = invariant;
2623 TREE_SIDE_EFFECTS (t) = side_effects;
2624 TREE_THIS_VOLATILE (t)
2625 = (TREE_CODE_CLASS (code) == tcc_reference
2626 && arg0 && TREE_THIS_VOLATILE (arg0));
2632 build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
2633 tree arg2 MEM_STAT_DECL)
2635 bool constant, read_only, side_effects, invariant;
2638 gcc_assert (TREE_CODE_LENGTH (code) == 3);
2640 t = make_node_stat (code PASS_MEM_STAT);
2643 side_effects = TREE_SIDE_EFFECTS (t);
2649 if (code == CALL_EXPR && !side_effects)
2654 /* Calls have side-effects, except those to const or
2656 i = call_expr_flags (t);
2657 if (!(i & (ECF_CONST | ECF_PURE)))
2660 /* And even those have side-effects if their arguments do. */
2661 else for (node = arg1; node; node = TREE_CHAIN (node))
2662 if (TREE_SIDE_EFFECTS (TREE_VALUE (node)))
2669 TREE_SIDE_EFFECTS (t) = side_effects;
2670 TREE_THIS_VOLATILE (t)
2671 = (TREE_CODE_CLASS (code) == tcc_reference
2672 && arg0 && TREE_THIS_VOLATILE (arg0));
2678 build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
2679 tree arg2, tree arg3 MEM_STAT_DECL)
2681 bool constant, read_only, side_effects, invariant;
2684 gcc_assert (TREE_CODE_LENGTH (code) == 4);
2686 t = make_node_stat (code PASS_MEM_STAT);
2689 side_effects = TREE_SIDE_EFFECTS (t);
2696 TREE_SIDE_EFFECTS (t) = side_effects;
2697 TREE_THIS_VOLATILE (t)
2698 = (TREE_CODE_CLASS (code) == tcc_reference
2699 && arg0 && TREE_THIS_VOLATILE (arg0));
2704 /* Backup definition for non-gcc build compilers. */
2707 (build) (enum tree_code code, tree tt, ...)
2709 tree t, arg0, arg1, arg2, arg3;
2710 int length = TREE_CODE_LENGTH (code);
2717 t = build0 (code, tt);
2720 arg0 = va_arg (p, tree);
2721 t = build1 (code, tt, arg0);
2724 arg0 = va_arg (p, tree);
2725 arg1 = va_arg (p, tree);
2726 t = build2 (code, tt, arg0, arg1);
2729 arg0 = va_arg (p, tree);
2730 arg1 = va_arg (p, tree);
2731 arg2 = va_arg (p, tree);
2732 t = build3 (code, tt, arg0, arg1, arg2);
2735 arg0 = va_arg (p, tree);
2736 arg1 = va_arg (p, tree);
2737 arg2 = va_arg (p, tree);
2738 arg3 = va_arg (p, tree);
2739 t = build4 (code, tt, arg0, arg1, arg2, arg3);
2749 /* Similar except don't specify the TREE_TYPE
2750 and leave the TREE_SIDE_EFFECTS as 0.
2751 It is permissible for arguments to be null,
2752 or even garbage if their values do not matter. */
2755 build_nt (enum tree_code code, ...)
2764 t = make_node (code);
2765 length = TREE_CODE_LENGTH (code);
2767 for (i = 0; i < length; i++)
2768 TREE_OPERAND (t, i) = va_arg (p, tree);
2774 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2775 We do NOT enter this node in any sort of symbol table.
2777 layout_decl is used to set up the decl's storage layout.
2778 Other slots are initialized to 0 or null pointers. */
2781 build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL)
2785 t = make_node_stat (code PASS_MEM_STAT);
2787 /* if (type == error_mark_node)
2788 type = integer_type_node; */
2789 /* That is not done, deliberately, so that having error_mark_node
2790 as the type can suppress useless errors in the use of this variable. */
2792 DECL_NAME (t) = name;
2793 TREE_TYPE (t) = type;
2795 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
2797 else if (code == FUNCTION_DECL)
2798 DECL_MODE (t) = FUNCTION_MODE;
2800 /* Set default visibility to whatever the user supplied with
2801 visibility_specified depending on #pragma GCC visibility. */
2802 DECL_VISIBILITY (t) = default_visibility;
2803 DECL_VISIBILITY_SPECIFIED (t) = visibility_options.inpragma;
2808 /* BLOCK nodes are used to represent the structure of binding contours
2809 and declarations, once those contours have been exited and their contents
2810 compiled. This information is used for outputting debugging info. */
2813 build_block (tree vars, tree tags ATTRIBUTE_UNUSED, tree subblocks,
2814 tree supercontext, tree chain)
2816 tree block = make_node (BLOCK);
2818 BLOCK_VARS (block) = vars;
2819 BLOCK_SUBBLOCKS (block) = subblocks;
2820 BLOCK_SUPERCONTEXT (block) = supercontext;
2821 BLOCK_CHAIN (block) = chain;
2825 #if 1 /* ! defined(USE_MAPPED_LOCATION) */
2826 /* ??? gengtype doesn't handle conditionals */
2827 static GTY(()) tree last_annotated_node;
2830 #ifdef USE_MAPPED_LOCATION
2833 expand_location (source_location loc)
2835 expanded_location xloc;
2836 if (loc == 0) { xloc.file = NULL; xloc.line = 0; xloc.column = 0; }
2839 const struct line_map *map = linemap_lookup (&line_table, loc);
2840 xloc.file = map->to_file;
2841 xloc.line = SOURCE_LINE (map, loc);
2842 xloc.column = SOURCE_COLUMN (map, loc);
2849 /* Record the exact location where an expression or an identifier were
2853 annotate_with_file_line (tree node, const char *file, int line)
2855 /* Roughly one percent of the calls to this function are to annotate
2856 a node with the same information already attached to that node!
2857 Just return instead of wasting memory. */
2858 if (EXPR_LOCUS (node)
2859 && (EXPR_FILENAME (node) == file
2860 || ! strcmp (EXPR_FILENAME (node), file))
2861 && EXPR_LINENO (node) == line)
2863 last_annotated_node = node;
2867 /* In heavily macroized code (such as GCC itself) this single
2868 entry cache can reduce the number of allocations by more
2870 if (last_annotated_node
2871 && EXPR_LOCUS (last_annotated_node)
2872 && (EXPR_FILENAME (last_annotated_node) == file
2873 || ! strcmp (EXPR_FILENAME (last_annotated_node), file))
2874 && EXPR_LINENO (last_annotated_node) == line)
2876 SET_EXPR_LOCUS (node, EXPR_LOCUS (last_annotated_node));
2880 SET_EXPR_LOCUS (node, ggc_alloc (sizeof (location_t)));
2881 EXPR_LINENO (node) = line;
2882 EXPR_FILENAME (node) = file;
2883 last_annotated_node = node;
2887 annotate_with_locus (tree node, location_t locus)
2889 annotate_with_file_line (node, locus.file, locus.line);
2893 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
2897 build_decl_attribute_variant (tree ddecl, tree attribute)
2899 DECL_ATTRIBUTES (ddecl) = attribute;
2903 /* Borrowed from hashtab.c iterative_hash implementation. */
2904 #define mix(a,b,c) \
2906 a -= b; a -= c; a ^= (c>>13); \
2907 b -= c; b -= a; b ^= (a<< 8); \
2908 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
2909 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
2910 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
2911 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
2912 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
2913 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
2914 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
2918 /* Produce good hash value combining VAL and VAL2. */
2919 static inline hashval_t
2920 iterative_hash_hashval_t (hashval_t val, hashval_t val2)
2922 /* the golden ratio; an arbitrary value. */
2923 hashval_t a = 0x9e3779b9;
2929 /* Produce good hash value combining PTR and VAL2. */
2930 static inline hashval_t
2931 iterative_hash_pointer (void *ptr, hashval_t val2)
2933 if (sizeof (ptr) == sizeof (hashval_t))
2934 return iterative_hash_hashval_t ((size_t) ptr, val2);
2937 hashval_t a = (hashval_t) (size_t) ptr;
2938 /* Avoid warnings about shifting of more than the width of the type on
2939 hosts that won't execute this path. */
2941 hashval_t b = (hashval_t) ((size_t) ptr >> (sizeof (hashval_t) * 8 + zero));
2947 /* Produce good hash value combining VAL and VAL2. */
2948 static inline hashval_t
2949 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2)
2951 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t))
2952 return iterative_hash_hashval_t (val, val2);
2955 hashval_t a = (hashval_t) val;
2956 /* Avoid warnings about shifting of more than the width of the type on
2957 hosts that won't execute this path. */
2959 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 8 + zero));
2961 if (sizeof (HOST_WIDE_INT) > 2 * sizeof (hashval_t))
2963 hashval_t a = (hashval_t) (val >> (sizeof (hashval_t) * 16 + zero));
2964 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 24 + zero));
2971 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
2974 Record such modified types already made so we don't make duplicates. */
2977 build_type_attribute_variant (tree ttype, tree attribute)
2979 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
2981 hashval_t hashcode = 0;
2983 enum tree_code code = TREE_CODE (ttype);
2985 ntype = copy_node (ttype);
2987 TYPE_POINTER_TO (ntype) = 0;
2988 TYPE_REFERENCE_TO (ntype) = 0;
2989 TYPE_ATTRIBUTES (ntype) = attribute;
2991 /* Create a new main variant of TYPE. */
2992 TYPE_MAIN_VARIANT (ntype) = ntype;
2993 TYPE_NEXT_VARIANT (ntype) = 0;
2994 set_type_quals (ntype, TYPE_UNQUALIFIED);
2996 hashcode = iterative_hash_object (code, hashcode);
2997 if (TREE_TYPE (ntype))
2998 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)),
3000 hashcode = attribute_hash_list (attribute, hashcode);
3002 switch (TREE_CODE (ntype))
3005 hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode);
3008 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)),
3012 hashcode = iterative_hash_object
3013 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode);
3014 hashcode = iterative_hash_object
3015 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode);
3019 unsigned int precision = TYPE_PRECISION (ntype);
3020 hashcode = iterative_hash_object (precision, hashcode);
3027 ntype = type_hash_canon (hashcode, ntype);
3028 ttype = build_qualified_type (ntype, TYPE_QUALS (ttype));
3035 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3038 We try both `text' and `__text__', ATTR may be either one. */
3039 /* ??? It might be a reasonable simplification to require ATTR to be only
3040 `text'. One might then also require attribute lists to be stored in
3041 their canonicalized form. */
3044 is_attribute_with_length_p (const char *attr, int attr_len, tree ident)
3049 if (TREE_CODE (ident) != IDENTIFIER_NODE)
3052 p = IDENTIFIER_POINTER (ident);
3053 ident_len = IDENTIFIER_LENGTH (ident);
3055 if (ident_len == attr_len
3056 && strcmp (attr, p) == 0)
3059 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
3062 gcc_assert (attr[1] == '_');
3063 gcc_assert (attr[attr_len - 2] == '_');
3064 gcc_assert (attr[attr_len - 1] == '_');
3065 gcc_assert (attr[1] == '_');
3066 if (ident_len == attr_len - 4
3067 && strncmp (attr + 2, p, attr_len - 4) == 0)
3072 if (ident_len == attr_len + 4
3073 && p[0] == '_' && p[1] == '_'
3074 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
3075 && strncmp (attr, p + 2, attr_len) == 0)
3082 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3085 We try both `text' and `__text__', ATTR may be either one. */
3088 is_attribute_p (const char *attr, tree ident)
3090 return is_attribute_with_length_p (attr, strlen (attr), ident);
3093 /* Given an attribute name and a list of attributes, return a pointer to the
3094 attribute's list element if the attribute is part of the list, or NULL_TREE
3095 if not found. If the attribute appears more than once, this only
3096 returns the first occurrence; the TREE_CHAIN of the return value should
3097 be passed back in if further occurrences are wanted. */
3100 lookup_attribute (const char *attr_name, tree list)
3103 size_t attr_len = strlen (attr_name);
3105 for (l = list; l; l = TREE_CHAIN (l))
3107 gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE);
3108 if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l)))
3115 /* Return an attribute list that is the union of a1 and a2. */
3118 merge_attributes (tree a1, tree a2)
3122 /* Either one unset? Take the set one. */
3124 if ((attributes = a1) == 0)
3127 /* One that completely contains the other? Take it. */
3129 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
3131 if (attribute_list_contained (a2, a1))
3135 /* Pick the longest list, and hang on the other list. */
3137 if (list_length (a1) < list_length (a2))
3138 attributes = a2, a2 = a1;
3140 for (; a2 != 0; a2 = TREE_CHAIN (a2))
3143 for (a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3146 a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3149 if (simple_cst_equal (TREE_VALUE (a), TREE_VALUE (a2)) == 1)
3154 a1 = copy_node (a2);
3155 TREE_CHAIN (a1) = attributes;
3164 /* Given types T1 and T2, merge their attributes and return
3168 merge_type_attributes (tree t1, tree t2)
3170 return merge_attributes (TYPE_ATTRIBUTES (t1),
3171 TYPE_ATTRIBUTES (t2));
3174 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
3178 merge_decl_attributes (tree olddecl, tree newdecl)
3180 return merge_attributes (DECL_ATTRIBUTES (olddecl),
3181 DECL_ATTRIBUTES (newdecl));
3184 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
3186 /* Specialization of merge_decl_attributes for various Windows targets.
3188 This handles the following situation:
3190 __declspec (dllimport) int foo;
3193 The second instance of `foo' nullifies the dllimport. */
3196 merge_dllimport_decl_attributes (tree old, tree new)
3199 int delete_dllimport_p;
3201 old = DECL_ATTRIBUTES (old);
3202 new = DECL_ATTRIBUTES (new);
3204 /* What we need to do here is remove from `old' dllimport if it doesn't
3205 appear in `new'. dllimport behaves like extern: if a declaration is
3206 marked dllimport and a definition appears later, then the object
3207 is not dllimport'd. */
3208 if (lookup_attribute ("dllimport", old) != NULL_TREE
3209 && lookup_attribute ("dllimport", new) == NULL_TREE)
3210 delete_dllimport_p = 1;
3212 delete_dllimport_p = 0;
3214 a = merge_attributes (old, new);
3216 if (delete_dllimport_p)
3220 /* Scan the list for dllimport and delete it. */
3221 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
3223 if (is_attribute_p ("dllimport", TREE_PURPOSE (t)))
3225 if (prev == NULL_TREE)
3228 TREE_CHAIN (prev) = TREE_CHAIN (t);
3237 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
3238 struct attribute_spec.handler. */
3241 handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
3246 /* These attributes may apply to structure and union types being created,
3247 but otherwise should pass to the declaration involved. */
3250 if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
3251 | (int) ATTR_FLAG_ARRAY_NEXT))
3253 *no_add_attrs = true;
3254 return tree_cons (name, args, NULL_TREE);
3256 if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
3258 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
3259 *no_add_attrs = true;
3265 /* Report error on dllimport ambiguities seen now before they cause
3267 if (is_attribute_p ("dllimport", name))
3269 /* Like MS, treat definition of dllimported variables and
3270 non-inlined functions on declaration as syntax errors. We
3271 allow the attribute for function definitions if declared
3273 if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node)
3274 && !DECL_DECLARED_INLINE_P (node))
3276 error ("%Jfunction %qD definition is marked dllimport.", node, node);
3277 *no_add_attrs = true;
3280 else if (TREE_CODE (node) == VAR_DECL)
3282 if (DECL_INITIAL (node))
3284 error ("%Jvariable %qD definition is marked dllimport.",
3286 *no_add_attrs = true;
3289 /* `extern' needn't be specified with dllimport.
3290 Specify `extern' now and hope for the best. Sigh. */
3291 DECL_EXTERNAL (node) = 1;
3292 /* Also, implicitly give dllimport'd variables declared within
3293 a function global scope, unless declared static. */
3294 if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
3295 TREE_PUBLIC (node) = 1;
3299 /* Report error if symbol is not accessible at global scope. */
3300 if (!TREE_PUBLIC (node)
3301 && (TREE_CODE (node) == VAR_DECL
3302 || TREE_CODE (node) == FUNCTION_DECL))
3304 error ("%Jexternal linkage required for symbol %qD because of "
3305 "%qs attribute.", node, node, IDENTIFIER_POINTER (name));
3306 *no_add_attrs = true;
3312 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
3314 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
3315 of the various TYPE_QUAL values. */
3318 set_type_quals (tree type, int type_quals)
3320 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
3321 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
3322 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
3325 /* Returns true iff cand is equivalent to base with type_quals. */
3328 check_qualified_type (tree cand, tree base, int type_quals)
3330 return (TYPE_QUALS (cand) == type_quals
3331 && TYPE_NAME (cand) == TYPE_NAME (base)
3332 /* Apparently this is needed for Objective-C. */
3333 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
3334 && attribute_list_equal (TYPE_ATTRIBUTES (cand),
3335 TYPE_ATTRIBUTES (base)));
3338 /* Return a version of the TYPE, qualified as indicated by the
3339 TYPE_QUALS, if one exists. If no qualified version exists yet,
3340 return NULL_TREE. */
3343 get_qualified_type (tree type, int type_quals)
3347 if (TYPE_QUALS (type) == type_quals)
3350 /* Search the chain of variants to see if there is already one there just
3351 like the one we need to have. If so, use that existing one. We must
3352 preserve the TYPE_NAME, since there is code that depends on this. */
3353 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
3354 if (check_qualified_type (t, type, type_quals))
3360 /* Like get_qualified_type, but creates the type if it does not
3361 exist. This function never returns NULL_TREE. */
3364 build_qualified_type (tree type, int type_quals)
3368 /* See if we already have the appropriate qualified variant. */
3369 t = get_qualified_type (type, type_quals);
3371 /* If not, build it. */
3374 t = build_variant_type_copy (type);
3375 set_type_quals (t, type_quals);
3381 /* Create a new distinct copy of TYPE. The new type is made its own
3385 build_distinct_type_copy (tree type)
3387 tree t = copy_node (type);
3389 TYPE_POINTER_TO (t) = 0;
3390 TYPE_REFERENCE_TO (t) = 0;
3392 /* Make it its own variant. */
3393 TYPE_MAIN_VARIANT (t) = t;
3394 TYPE_NEXT_VARIANT (t) = 0;
3399 /* Create a new variant of TYPE, equivalent but distinct.
3400 This is so the caller can modify it. */
3403 build_variant_type_copy (tree type)
3405 tree t, m = TYPE_MAIN_VARIANT (type);
3407 t = build_distinct_type_copy (type);
3409 /* Add the new type to the chain of variants of TYPE. */
3410 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
3411 TYPE_NEXT_VARIANT (m) = t;
3412 TYPE_MAIN_VARIANT (t) = m;
3417 /* Hashing of types so that we don't make duplicates.
3418 The entry point is `type_hash_canon'. */
3420 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
3421 with types in the TREE_VALUE slots), by adding the hash codes
3422 of the individual types. */
3425 type_hash_list (tree list, hashval_t hashcode)
3429 for (tail = list; tail; tail = TREE_CHAIN (tail))
3430 if (TREE_VALUE (tail) != error_mark_node)
3431 hashcode = iterative_hash_object (TYPE_HASH (TREE_VALUE (tail)),
3437 /* These are the Hashtable callback functions. */
3439 /* Returns true iff the types are equivalent. */
3442 type_hash_eq (const void *va, const void *vb)
3444 const struct type_hash *a = va, *b = vb;
3446 /* First test the things that are the same for all types. */
3447 if (a->hash != b->hash
3448 || TREE_CODE (a->type) != TREE_CODE (b->type)
3449 || TREE_TYPE (a->type) != TREE_TYPE (b->type)
3450 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
3451 TYPE_ATTRIBUTES (b->type))
3452 || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
3453 || TYPE_MODE (a->type) != TYPE_MODE (b->type))
3456 switch (TREE_CODE (a->type))
3461 case REFERENCE_TYPE:
3465 return TYPE_VECTOR_SUBPARTS (a->type) == TYPE_VECTOR_SUBPARTS (b->type);
3468 if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
3469 && !(TYPE_VALUES (a->type)
3470 && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
3471 && TYPE_VALUES (b->type)
3472 && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
3473 && type_list_equal (TYPE_VALUES (a->type),
3474 TYPE_VALUES (b->type))))
3477 /* ... fall through ... */
3483 return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
3484 || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
3485 TYPE_MAX_VALUE (b->type)))
3486 && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
3487 || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
3488 TYPE_MIN_VALUE (b->type))));
3491 return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
3494 return (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
3495 && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
3496 || (TYPE_ARG_TYPES (a->type)
3497 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
3498 && TYPE_ARG_TYPES (b->type)
3499 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
3500 && type_list_equal (TYPE_ARG_TYPES (a->type),
3501 TYPE_ARG_TYPES (b->type)))));
3504 return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type);
3508 case QUAL_UNION_TYPE:
3509 return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
3510 || (TYPE_FIELDS (a->type)
3511 && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
3512 && TYPE_FIELDS (b->type)
3513 && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
3514 && type_list_equal (TYPE_FIELDS (a->type),
3515 TYPE_FIELDS (b->type))));
3518 return (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
3519 || (TYPE_ARG_TYPES (a->type)
3520 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
3521 && TYPE_ARG_TYPES (b->type)
3522 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
3523 && type_list_equal (TYPE_ARG_TYPES (a->type),
3524 TYPE_ARG_TYPES (b->type))));
3531 /* Return the cached hash value. */
3534 type_hash_hash (const void *item)
3536 return ((const struct type_hash *) item)->hash;
3539 /* Look in the type hash table for a type isomorphic to TYPE.
3540 If one is found, return it. Otherwise return 0. */
3543 type_hash_lookup (hashval_t hashcode, tree type)
3545 struct type_hash *h, in;
3547 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
3548 must call that routine before comparing TYPE_ALIGNs. */
3554 h = htab_find_with_hash (type_hash_table, &in, hashcode);
3560 /* Add an entry to the type-hash-table
3561 for a type TYPE whose hash code is HASHCODE. */
3564 type_hash_add (hashval_t hashcode, tree type)
3566 struct type_hash *h;
3569 h = ggc_alloc (sizeof (struct type_hash));
3572 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
3573 *(struct type_hash **) loc = h;
3576 /* Given TYPE, and HASHCODE its hash code, return the canonical
3577 object for an identical type if one already exists.
3578 Otherwise, return TYPE, and record it as the canonical object.
3580 To use this function, first create a type of the sort you want.
3581 Then compute its hash code from the fields of the type that
3582 make it different from other similar types.
3583 Then call this function and use the value. */
3586 type_hash_canon (unsigned int hashcode, tree type)
3590 /* The hash table only contains main variants, so ensure that's what we're
3592 gcc_assert (TYPE_MAIN_VARIANT (type) == type);
3594 if (!lang_hooks.types.hash_types)
3597 /* See if the type is in the hash table already. If so, return it.
3598 Otherwise, add the type. */
3599 t1 = type_hash_lookup (hashcode, type);
3602 #ifdef GATHER_STATISTICS
3603 tree_node_counts[(int) t_kind]--;
3604 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
3610 type_hash_add (hashcode, type);
3615 /* See if the data pointed to by the type hash table is marked. We consider
3616 it marked if the type is marked or if a debug type number or symbol
3617 table entry has been made for the type. This reduces the amount of
3618 debugging output and eliminates that dependency of the debug output on
3619 the number of garbage collections. */
3622 type_hash_marked_p (const void *p)
3624 tree type = ((struct type_hash *) p)->type;
3626 return ggc_marked_p (type) || TYPE_SYMTAB_POINTER (type);
3630 print_type_hash_statistics (void)
3632 fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
3633 (long) htab_size (type_hash_table),
3634 (long) htab_elements (type_hash_table),
3635 htab_collisions (type_hash_table));
3638 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
3639 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
3640 by adding the hash codes of the individual attributes. */
3643 attribute_hash_list (tree list, hashval_t hashcode)
3647 for (tail = list; tail; tail = TREE_CHAIN (tail))
3648 /* ??? Do we want to add in TREE_VALUE too? */
3649 hashcode = iterative_hash_object
3650 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail)), hashcode);
3654 /* Given two lists of attributes, return true if list l2 is
3655 equivalent to l1. */
3658 attribute_list_equal (tree l1, tree l2)
3660 return attribute_list_contained (l1, l2)
3661 && attribute_list_contained (l2, l1);
3664 /* Given two lists of attributes, return true if list L2 is
3665 completely contained within L1. */
3666 /* ??? This would be faster if attribute names were stored in a canonicalized
3667 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
3668 must be used to show these elements are equivalent (which they are). */
3669 /* ??? It's not clear that attributes with arguments will always be handled
3673 attribute_list_contained (tree l1, tree l2)
3677 /* First check the obvious, maybe the lists are identical. */
3681 /* Maybe the lists are similar. */
3682 for (t1 = l1, t2 = l2;
3684 && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
3685 && TREE_VALUE (t1) == TREE_VALUE (t2);
3686 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
3688 /* Maybe the lists are equal. */
3689 if (t1 == 0 && t2 == 0)
3692 for (; t2 != 0; t2 = TREE_CHAIN (t2))
3695 for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1);
3697 attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
3700 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) == 1)
3707 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) != 1)
3714 /* Given two lists of types
3715 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
3716 return 1 if the lists contain the same types in the same order.
3717 Also, the TREE_PURPOSEs must match. */
3720 type_list_equal (tree l1, tree l2)
3724 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
3725 if (TREE_VALUE (t1) != TREE_VALUE (t2)
3726 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
3727 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
3728 && (TREE_TYPE (TREE_PURPOSE (t1))
3729 == TREE_TYPE (TREE_PURPOSE (t2))))))
3735 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
3736 given by TYPE. If the argument list accepts variable arguments,
3737 then this function counts only the ordinary arguments. */
3740 type_num_arguments (tree type)
3745 for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
3746 /* If the function does not take a variable number of arguments,
3747 the last element in the list will have type `void'. */
3748 if (VOID_TYPE_P (TREE_VALUE (t)))
3756 /* Nonzero if integer constants T1 and T2
3757 represent the same constant value. */
3760 tree_int_cst_equal (tree t1, tree t2)
3765 if (t1 == 0 || t2 == 0)
3768 if (TREE_CODE (t1) == INTEGER_CST
3769 && TREE_CODE (t2) == INTEGER_CST
3770 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3771 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
3777 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
3778 The precise way of comparison depends on their data type. */
3781 tree_int_cst_lt (tree t1, tree t2)
3786 if (TYPE_UNSIGNED (TREE_TYPE (t1)) != TYPE_UNSIGNED (TREE_TYPE (t2)))
3788 int t1_sgn = tree_int_cst_sgn (t1);
3789 int t2_sgn = tree_int_cst_sgn (t2);
3791 if (t1_sgn < t2_sgn)
3793 else if (t1_sgn > t2_sgn)
3795 /* Otherwise, both are non-negative, so we compare them as
3796 unsigned just in case one of them would overflow a signed
3799 else if (!TYPE_UNSIGNED (TREE_TYPE (t1)))
3800 return INT_CST_LT (t1, t2);
3802 return INT_CST_LT_UNSIGNED (t1, t2);
3805 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
3808 tree_int_cst_compare (tree t1, tree t2)
3810 if (tree_int_cst_lt (t1, t2))
3812 else if (tree_int_cst_lt (t2, t1))
3818 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
3819 the host. If POS is zero, the value can be represented in a single
3820 HOST_WIDE_INT. If POS is nonzero, the value must be positive and can
3821 be represented in a single unsigned HOST_WIDE_INT. */
3824 host_integerp (tree t, int pos)
3826 return (TREE_CODE (t) == INTEGER_CST
3827 && ! TREE_OVERFLOW (t)
3828 && ((TREE_INT_CST_HIGH (t) == 0
3829 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
3830 || (! pos && TREE_INT_CST_HIGH (t) == -1
3831 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
3832 && !TYPE_UNSIGNED (TREE_TYPE (t)))
3833 || (pos && TREE_INT_CST_HIGH (t) == 0)));
3836 /* Return the HOST_WIDE_INT least significant bits of T if it is an
3837 INTEGER_CST and there is no overflow. POS is nonzero if the result must
3838 be positive. Abort if we cannot satisfy the above conditions. */
3841 tree_low_cst (tree t, int pos)
3843 gcc_assert (host_integerp (t, pos));
3844 return TREE_INT_CST_LOW (t);
3847 /* Return the most significant bit of the integer constant T. */
3850 tree_int_cst_msb (tree t)
3854 unsigned HOST_WIDE_INT l;
3856 /* Note that using TYPE_PRECISION here is wrong. We care about the
3857 actual bits, not the (arbitrary) range of the type. */
3858 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
3859 rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
3860 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
3861 return (l & 1) == 1;
3864 /* Return an indication of the sign of the integer constant T.
3865 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
3866 Note that -1 will never be returned it T's type is unsigned. */
3869 tree_int_cst_sgn (tree t)
3871 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
3873 else if (TYPE_UNSIGNED (TREE_TYPE (t)))
3875 else if (TREE_INT_CST_HIGH (t) < 0)
3881 /* Compare two constructor-element-type constants. Return 1 if the lists
3882 are known to be equal; otherwise return 0. */
3885 simple_cst_list_equal (tree l1, tree l2)
3887 while (l1 != NULL_TREE && l2 != NULL_TREE)
3889 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
3892 l1 = TREE_CHAIN (l1);
3893 l2 = TREE_CHAIN (l2);
3899 /* Return truthvalue of whether T1 is the same tree structure as T2.
3900 Return 1 if they are the same.
3901 Return 0 if they are understandably different.
3902 Return -1 if either contains tree structure not understood by
3906 simple_cst_equal (tree t1, tree t2)
3908 enum tree_code code1, code2;
3914 if (t1 == 0 || t2 == 0)
3917 code1 = TREE_CODE (t1);
3918 code2 = TREE_CODE (t2);
3920 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
3922 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3923 || code2 == NON_LVALUE_EXPR)
3924 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3926 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
3929 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3930 || code2 == NON_LVALUE_EXPR)
3931 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
3939 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3940 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
3943 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3946 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3947 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3948 TREE_STRING_LENGTH (t1)));
3951 return simple_cst_list_equal (CONSTRUCTOR_ELTS (t1),
3952 CONSTRUCTOR_ELTS (t2));
3955 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3958 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3962 simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3965 /* Special case: if either target is an unallocated VAR_DECL,
3966 it means that it's going to be unified with whatever the
3967 TARGET_EXPR is really supposed to initialize, so treat it
3968 as being equivalent to anything. */
3969 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
3970 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
3971 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
3972 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
3973 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
3974 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
3977 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3982 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3984 case WITH_CLEANUP_EXPR:
3985 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3989 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
3992 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
3993 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4007 /* This general rule works for most tree codes. All exceptions should be
4008 handled above. If this is a language-specific tree code, we can't
4009 trust what might be in the operand, so say we don't know
4011 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
4014 switch (TREE_CODE_CLASS (code1))
4018 case tcc_comparison:
4019 case tcc_expression:
4023 for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
4025 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
4037 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
4038 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
4039 than U, respectively. */
4042 compare_tree_int (tree t, unsigned HOST_WIDE_INT u)
4044 if (tree_int_cst_sgn (t) < 0)
4046 else if (TREE_INT_CST_HIGH (t) != 0)
4048 else if (TREE_INT_CST_LOW (t) == u)
4050 else if (TREE_INT_CST_LOW (t) < u)
4056 /* Return true if CODE represents an associative tree code. Otherwise
4059 associative_tree_code (enum tree_code code)
4078 /* Return true if CODE represents a commutative tree code. Otherwise
4081 commutative_tree_code (enum tree_code code)
4094 case UNORDERED_EXPR:
4098 case TRUTH_AND_EXPR:
4099 case TRUTH_XOR_EXPR:
4109 /* Generate a hash value for an expression. This can be used iteratively
4110 by passing a previous result as the "val" argument.
4112 This function is intended to produce the same hash for expressions which
4113 would compare equal using operand_equal_p. */
4116 iterative_hash_expr (tree t, hashval_t val)
4119 enum tree_code code;
4123 return iterative_hash_pointer (t, val);
4125 code = TREE_CODE (t);
4129 /* Alas, constants aren't shared, so we can't rely on pointer
4132 val = iterative_hash_host_wide_int (TREE_INT_CST_LOW (t), val);
4133 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t), val);
4136 unsigned int val2 = real_hash (TREE_REAL_CST_PTR (t));
4138 return iterative_hash_hashval_t (val2, val);
4141 return iterative_hash (TREE_STRING_POINTER (t),
4142 TREE_STRING_LENGTH (t), val);
4144 val = iterative_hash_expr (TREE_REALPART (t), val);
4145 return iterative_hash_expr (TREE_IMAGPART (t), val);
4147 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val);
4151 /* we can just compare by pointer. */
4152 return iterative_hash_pointer (t, val);
4155 /* A list of expressions, for a CALL_EXPR or as the elements of a
4157 for (; t; t = TREE_CHAIN (t))
4158 val = iterative_hash_expr (TREE_VALUE (t), val);
4161 /* When referring to a built-in FUNCTION_DECL, use the
4162 __builtin__ form. Otherwise nodes that compare equal
4163 according to operand_equal_p might get different
4165 if (DECL_BUILT_IN (t))
4167 val = iterative_hash_pointer (built_in_decls[DECL_FUNCTION_CODE (t)],
4171 /* else FALL THROUGH */
4173 class = TREE_CODE_CLASS (code);
4175 if (class == tcc_declaration)
4177 /* Otherwise, we can just compare decls by pointer. */
4178 val = iterative_hash_pointer (t, val);
4182 gcc_assert (IS_EXPR_CODE_CLASS (class));
4184 val = iterative_hash_object (code, val);
4186 /* Don't hash the type, that can lead to having nodes which
4187 compare equal according to operand_equal_p, but which
4188 have different hash codes. */
4189 if (code == NOP_EXPR
4190 || code == CONVERT_EXPR
4191 || code == NON_LVALUE_EXPR)
4193 /* Make sure to include signness in the hash computation. */
4194 val += TYPE_UNSIGNED (TREE_TYPE (t));
4195 val = iterative_hash_expr (TREE_OPERAND (t, 0), val);
4198 else if (commutative_tree_code (code))
4200 /* It's a commutative expression. We want to hash it the same
4201 however it appears. We do this by first hashing both operands
4202 and then rehashing based on the order of their independent
4204 hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0);
4205 hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0);
4209 t = one, one = two, two = t;
4211 val = iterative_hash_hashval_t (one, val);
4212 val = iterative_hash_hashval_t (two, val);
4215 for (i = TREE_CODE_LENGTH (code) - 1; i >= 0; --i)
4216 val = iterative_hash_expr (TREE_OPERAND (t, i), val);
4223 /* Constructors for pointer, array and function types.
4224 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
4225 constructed by language-dependent code, not here.) */
4227 /* Construct, lay out and return the type of pointers to TO_TYPE with
4228 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
4229 reference all of memory. If such a type has already been
4230 constructed, reuse it. */
4233 build_pointer_type_for_mode (tree to_type, enum machine_mode mode,
4238 /* In some cases, languages will have things that aren't a POINTER_TYPE
4239 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
4240 In that case, return that type without regard to the rest of our
4243 ??? This is a kludge, but consistent with the way this function has
4244 always operated and there doesn't seem to be a good way to avoid this
4246 if (TYPE_POINTER_TO (to_type) != 0
4247 && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
4248 return TYPE_POINTER_TO (to_type);
4250 /* First, if we already have a type for pointers to TO_TYPE and it's
4251 the proper mode, use it. */
4252 for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
4253 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
4256 t = make_node (POINTER_TYPE);
4258 TREE_TYPE (t) = to_type;
4259 TYPE_MODE (t) = mode;
4260 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
4261 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
4262 TYPE_POINTER_TO (to_type) = t;
4264 /* Lay out the type. This function has many callers that are concerned
4265 with expression-construction, and this simplifies them all. */
4271 /* By default build pointers in ptr_mode. */
4274 build_pointer_type (tree to_type)
4276 return build_pointer_type_for_mode (to_type, ptr_mode, false);
4279 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
4282 build_reference_type_for_mode (tree to_type, enum machine_mode mode,
4287 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
4288 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
4289 In that case, return that type without regard to the rest of our
4292 ??? This is a kludge, but consistent with the way this function has
4293 always operated and there doesn't seem to be a good way to avoid this
4295 if (TYPE_REFERENCE_TO (to_type) != 0
4296 && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
4297 return TYPE_REFERENCE_TO (to_type);
4299 /* First, if we already have a type for pointers to TO_TYPE and it's
4300 the proper mode, use it. */
4301 for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
4302 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
4305 t = make_node (REFERENCE_TYPE);
4307 TREE_TYPE (t) = to_type;
4308 TYPE_MODE (t) = mode;
4309 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
4310 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
4311 TYPE_REFERENCE_TO (to_type) = t;
4319 /* Build the node for the type of references-to-TO_TYPE by default
4323 build_reference_type (tree to_type)
4325 return build_reference_type_for_mode (to_type, ptr_mode, false);
4328 /* Build a type that is compatible with t but has no cv quals anywhere
4331 const char *const *const * -> char ***. */
4334 build_type_no_quals (tree t)
4336 switch (TREE_CODE (t))
4339 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
4341 TYPE_REF_CAN_ALIAS_ALL (t));
4342 case REFERENCE_TYPE:
4344 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
4346 TYPE_REF_CAN_ALIAS_ALL (t));
4348 return TYPE_MAIN_VARIANT (t);
4352 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
4353 MAXVAL should be the maximum value in the domain
4354 (one less than the length of the array).
4356 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
4357 We don't enforce this limit, that is up to caller (e.g. language front end).
4358 The limit exists because the result is a signed type and we don't handle
4359 sizes that use more than one HOST_WIDE_INT. */
4362 build_index_type (tree maxval)
4364 tree itype = make_node (INTEGER_TYPE);
4366 TREE_TYPE (itype) = sizetype;
4367 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
4368 TYPE_MIN_VALUE (itype) = size_zero_node;
4369 TYPE_MAX_VALUE (itype) = fold_convert (sizetype, maxval);
4370 TYPE_MODE (itype) = TYPE_MODE (sizetype);
4371 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
4372 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
4373 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
4374 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
4376 if (host_integerp (maxval, 1))
4377 return type_hash_canon (tree_low_cst (maxval, 1), itype);
4382 /* Builds a signed or unsigned integer type of precision PRECISION.
4383 Used for C bitfields whose precision does not match that of
4384 built-in target types. */
4386 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
4389 tree itype = make_node (INTEGER_TYPE);
4391 TYPE_PRECISION (itype) = precision;
4394 fixup_unsigned_type (itype);
4396 fixup_signed_type (itype);
4398 if (host_integerp (TYPE_MAX_VALUE (itype), 1))
4399 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype);
4404 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
4405 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
4406 low bound LOWVAL and high bound HIGHVAL.
4407 if TYPE==NULL_TREE, sizetype is used. */
4410 build_range_type (tree type, tree lowval, tree highval)
4412 tree itype = make_node (INTEGER_TYPE);
4414 TREE_TYPE (itype) = type;
4415 if (type == NULL_TREE)
4418 TYPE_MIN_VALUE (itype) = convert (type, lowval);
4419 TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL;
4421 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
4422 TYPE_MODE (itype) = TYPE_MODE (type);
4423 TYPE_SIZE (itype) = TYPE_SIZE (type);
4424 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
4425 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
4426 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
4428 if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
4429 return type_hash_canon (tree_low_cst (highval, 0)
4430 - tree_low_cst (lowval, 0),
4436 /* Just like build_index_type, but takes lowval and highval instead
4437 of just highval (maxval). */
4440 build_index_2_type (tree lowval, tree highval)
4442 return build_range_type (sizetype, lowval, highval);
4445 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
4446 and number of elements specified by the range of values of INDEX_TYPE.
4447 If such a type has already been constructed, reuse it. */
4450 build_array_type (tree elt_type, tree index_type)
4453 hashval_t hashcode = 0;
4455 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
4457 error ("arrays of functions are not meaningful");
4458 elt_type = integer_type_node;
4461 t = make_node (ARRAY_TYPE);
4462 TREE_TYPE (t) = elt_type;
4463 TYPE_DOMAIN (t) = index_type;
4465 if (index_type == 0)
4471 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
4472 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
4473 t = type_hash_canon (hashcode, t);
4475 if (!COMPLETE_TYPE_P (t))
4480 /* Return the TYPE of the elements comprising
4481 the innermost dimension of ARRAY. */
4484 get_inner_array_type (tree array)
4486 tree type = TREE_TYPE (array);
4488 while (TREE_CODE (type) == ARRAY_TYPE)
4489 type = TREE_TYPE (type);
4494 /* Construct, lay out and return
4495 the type of functions returning type VALUE_TYPE
4496 given arguments of types ARG_TYPES.
4497 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
4498 are data type nodes for the arguments of the function.
4499 If such a type has already been constructed, reuse it. */
4502 build_function_type (tree value_type, tree arg_types)
4505 hashval_t hashcode = 0;
4507 if (TREE_CODE (value_type) == FUNCTION_TYPE)
4509 error ("function return type cannot be function");
4510 value_type = integer_type_node;
4513 /* Make a node of the sort we want. */
4514 t = make_node (FUNCTION_TYPE);
4515 TREE_TYPE (t) = value_type;
4516 TYPE_ARG_TYPES (t) = arg_types;
4518 /* If we already have such a type, use the old one. */
4519 hashcode = iterative_hash_object (TYPE_HASH (value_type), hashcode);
4520 hashcode = type_hash_list (arg_types, hashcode);
4521 t = type_hash_canon (hashcode, t);
4523 if (!COMPLETE_TYPE_P (t))
4528 /* Build a function type. The RETURN_TYPE is the type returned by the
4529 function. If additional arguments are provided, they are
4530 additional argument types. The list of argument types must always
4531 be terminated by NULL_TREE. */
4534 build_function_type_list (tree return_type, ...)
4539 va_start (p, return_type);
4541 t = va_arg (p, tree);
4542 for (args = NULL_TREE; t != NULL_TREE; t = va_arg (p, tree))
4543 args = tree_cons (NULL_TREE, t, args);
4545 if (args == NULL_TREE)
4546 args = void_list_node;
4550 args = nreverse (args);
4551 TREE_CHAIN (last) = void_list_node;
4553 args = build_function_type (return_type, args);
4559 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
4560 and ARGTYPES (a TREE_LIST) are the return type and arguments types
4561 for the method. An implicit additional parameter (of type
4562 pointer-to-BASETYPE) is added to the ARGTYPES. */
4565 build_method_type_directly (tree basetype,
4573 /* Make a node of the sort we want. */
4574 t = make_node (METHOD_TYPE);
4576 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4577 TREE_TYPE (t) = rettype;
4578 ptype = build_pointer_type (basetype);
4580 /* The actual arglist for this function includes a "hidden" argument
4581 which is "this". Put it into the list of argument types. */
4582 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
4583 TYPE_ARG_TYPES (t) = argtypes;
4585 /* If we already have such a type, use the old one. */
4586 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
4587 hashcode = iterative_hash_object (TYPE_HASH (rettype), hashcode);
4588 hashcode = type_hash_list (argtypes, hashcode);
4589 t = type_hash_canon (hashcode, t);
4591 if (!COMPLETE_TYPE_P (t))
4597 /* Construct, lay out and return the type of methods belonging to class
4598 BASETYPE and whose arguments and values are described by TYPE.
4599 If that type exists already, reuse it.
4600 TYPE must be a FUNCTION_TYPE node. */
4603 build_method_type (tree basetype, tree type)
4605 gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
4607 return build_method_type_directly (basetype,
4609 TYPE_ARG_TYPES (type));
4612 /* Construct, lay out and return the type of offsets to a value
4613 of type TYPE, within an object of type BASETYPE.
4614 If a suitable offset type exists already, reuse it. */
4617 build_offset_type (tree basetype, tree type)
4620 hashval_t hashcode = 0;
4622 /* Make a node of the sort we want. */
4623 t = make_node (OFFSET_TYPE);
4625 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4626 TREE_TYPE (t) = type;
4628 /* If we already have such a type, use the old one. */
4629 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
4630 hashcode = iterative_hash_object (TYPE_HASH (type), hashcode);
4631 t = type_hash_canon (hashcode, t);
4633 if (!COMPLETE_TYPE_P (t))
4639 /* Create a complex type whose components are COMPONENT_TYPE. */
4642 build_complex_type (tree component_type)
4647 /* Make a node of the sort we want. */
4648 t = make_node (COMPLEX_TYPE);
4650 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
4652 /* If we already have such a type, use the old one. */
4653 hashcode = iterative_hash_object (TYPE_HASH (component_type), 0);
4654 t = type_hash_canon (hashcode, t);
4656 if (!COMPLETE_TYPE_P (t))
4659 /* If we are writing Dwarf2 output we need to create a name,
4660 since complex is a fundamental type. */
4661 if ((write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4665 if (component_type == char_type_node)
4666 name = "complex char";
4667 else if (component_type == signed_char_type_node)
4668 name = "complex signed char";
4669 else if (component_type == unsigned_char_type_node)
4670 name = "complex unsigned char";
4671 else if (component_type == short_integer_type_node)
4672 name = "complex short int";
4673 else if (component_type == short_unsigned_type_node)
4674 name = "complex short unsigned int";
4675 else if (component_type == integer_type_node)
4676 name = "complex int";
4677 else if (component_type == unsigned_type_node)
4678 name = "complex unsigned int";
4679 else if (component_type == long_integer_type_node)
4680 name = "complex long int";
4681 else if (component_type == long_unsigned_type_node)
4682 name = "complex long unsigned int";
4683 else if (component_type == long_long_integer_type_node)
4684 name = "complex long long int";
4685 else if (component_type == long_long_unsigned_type_node)
4686 name = "complex long long unsigned int";
4691 TYPE_NAME (t) = get_identifier (name);
4694 return build_qualified_type (t, TYPE_QUALS (component_type));
4697 /* Return OP, stripped of any conversions to wider types as much as is safe.
4698 Converting the value back to OP's type makes a value equivalent to OP.
4700 If FOR_TYPE is nonzero, we return a value which, if converted to
4701 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
4703 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
4704 narrowest type that can hold the value, even if they don't exactly fit.
4705 Otherwise, bit-field references are changed to a narrower type
4706 only if they can be fetched directly from memory in that type.
4708 OP must have integer, real or enumeral type. Pointers are not allowed!
4710 There are some cases where the obvious value we could return
4711 would regenerate to OP if converted to OP's type,
4712 but would not extend like OP to wider types.
4713 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
4714 For example, if OP is (unsigned short)(signed char)-1,
4715 we avoid returning (signed char)-1 if FOR_TYPE is int,
4716 even though extending that to an unsigned short would regenerate OP,
4717 since the result of extending (signed char)-1 to (int)
4718 is different from (int) OP. */
4721 get_unwidened (tree op, tree for_type)
4723 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
4724 tree type = TREE_TYPE (op);
4726 = TYPE_PRECISION (for_type != 0 ? for_type : type);
4728 = (for_type != 0 && for_type != type
4729 && final_prec > TYPE_PRECISION (type)
4730 && TYPE_UNSIGNED (type));
4733 while (TREE_CODE (op) == NOP_EXPR
4734 || TREE_CODE (op) == CONVERT_EXPR)
4737 = TYPE_PRECISION (TREE_TYPE (op))
4738 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
4740 /* Truncations are many-one so cannot be removed.
4741 Unless we are later going to truncate down even farther. */
4743 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
4746 /* See what's inside this conversion. If we decide to strip it,
4748 op = TREE_OPERAND (op, 0);
4750 /* If we have not stripped any zero-extensions (uns is 0),
4751 we can strip any kind of extension.
4752 If we have previously stripped a zero-extension,
4753 only zero-extensions can safely be stripped.
4754 Any extension can be stripped if the bits it would produce
4755 are all going to be discarded later by truncating to FOR_TYPE. */
4759 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
4761 /* TYPE_UNSIGNED says whether this is a zero-extension.
4762 Let's avoid computing it if it does not affect WIN
4763 and if UNS will not be needed again. */
4765 || TREE_CODE (op) == NOP_EXPR
4766 || TREE_CODE (op) == CONVERT_EXPR)
4767 && TYPE_UNSIGNED (TREE_TYPE (op)))
4775 if (TREE_CODE (op) == COMPONENT_REF
4776 /* Since type_for_size always gives an integer type. */
4777 && TREE_CODE (type) != REAL_TYPE
4778 /* Don't crash if field not laid out yet. */
4779 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
4780 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
4782 unsigned int innerprec
4783 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4784 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
4785 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
4786 type = lang_hooks.types.type_for_size (innerprec, unsignedp);
4788 /* We can get this structure field in the narrowest type it fits in.
4789 If FOR_TYPE is 0, do this only for a field that matches the
4790 narrower type exactly and is aligned for it
4791 The resulting extension to its nominal type (a fullword type)
4792 must fit the same conditions as for other extensions. */
4795 && INT_CST_LT_UNSIGNED (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (op)))
4796 && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
4797 && (! uns || final_prec <= innerprec || unsignedp))
4799 win = build3 (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4800 TREE_OPERAND (op, 1), NULL_TREE);
4801 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4802 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4809 /* Return OP or a simpler expression for a narrower value
4810 which can be sign-extended or zero-extended to give back OP.
4811 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
4812 or 0 if the value should be sign-extended. */
4815 get_narrower (tree op, int *unsignedp_ptr)
4820 bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
4822 while (TREE_CODE (op) == NOP_EXPR)
4825 = (TYPE_PRECISION (TREE_TYPE (op))
4826 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
4828 /* Truncations are many-one so cannot be removed. */
4832 /* See what's inside this conversion. If we decide to strip it,
4837 op = TREE_OPERAND (op, 0);
4838 /* An extension: the outermost one can be stripped,
4839 but remember whether it is zero or sign extension. */
4841 uns = TYPE_UNSIGNED (TREE_TYPE (op));
4842 /* Otherwise, if a sign extension has been stripped,
4843 only sign extensions can now be stripped;
4844 if a zero extension has been stripped, only zero-extensions. */
4845 else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
4849 else /* bitschange == 0 */
4851 /* A change in nominal type can always be stripped, but we must
4852 preserve the unsignedness. */
4854 uns = TYPE_UNSIGNED (TREE_TYPE (op));
4856 op = TREE_OPERAND (op, 0);
4857 /* Keep trying to narrow, but don't assign op to win if it
4858 would turn an integral type into something else. */
4859 if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
4866 if (TREE_CODE (op) == COMPONENT_REF
4867 /* Since type_for_size always gives an integer type. */
4868 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
4869 /* Ensure field is laid out already. */
4870 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
4871 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
4873 unsigned HOST_WIDE_INT innerprec
4874 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4875 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
4876 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
4877 tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
4879 /* We can get this structure field in a narrower type that fits it,
4880 but the resulting extension to its nominal type (a fullword type)
4881 must satisfy the same conditions as for other extensions.
4883 Do this only for fields that are aligned (not bit-fields),
4884 because when bit-field insns will be used there is no
4885 advantage in doing this. */
4887 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
4888 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
4889 && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
4893 uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
4894 win = build3 (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4895 TREE_OPERAND (op, 1), NULL_TREE);
4896 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4897 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4900 *unsignedp_ptr = uns;
4904 /* Nonzero if integer constant C has a value that is permissible
4905 for type TYPE (an INTEGER_TYPE). */
4908 int_fits_type_p (tree c, tree type)
4910 tree type_low_bound = TYPE_MIN_VALUE (type);
4911 tree type_high_bound = TYPE_MAX_VALUE (type);
4912 bool ok_for_low_bound, ok_for_high_bound;
4915 /* If at least one bound of the type is a constant integer, we can check
4916 ourselves and maybe make a decision. If no such decision is possible, but
4917 this type is a subtype, try checking against that. Otherwise, use
4918 force_fit_type, which checks against the precision.
4920 Compute the status for each possibly constant bound, and return if we see
4921 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
4922 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
4923 for "constant known to fit". */
4925 /* Check if C >= type_low_bound. */
4926 if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
4928 if (tree_int_cst_lt (c, type_low_bound))
4930 ok_for_low_bound = true;
4933 ok_for_low_bound = false;
4935 /* Check if c <= type_high_bound. */
4936 if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
4938 if (tree_int_cst_lt (type_high_bound, c))
4940 ok_for_high_bound = true;
4943 ok_for_high_bound = false;
4945 /* If the constant fits both bounds, the result is known. */
4946 if (ok_for_low_bound && ok_for_high_bound)
4949 /* Perform some generic filtering which may allow making a decision
4950 even if the bounds are not constant. First, negative integers
4951 never fit in unsigned types, */
4952 if (TYPE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0)
4955 /* Second, narrower types always fit in wider ones. */
4956 if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
4959 /* Third, unsigned integers with top bit set never fit signed types. */
4960 if (! TYPE_UNSIGNED (type)
4961 && TYPE_UNSIGNED (TREE_TYPE (c))
4962 && tree_int_cst_msb (c))
4965 /* If we haven't been able to decide at this point, there nothing more we
4966 can check ourselves here. Look at the base type if we have one. */
4967 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != 0)
4968 return int_fits_type_p (c, TREE_TYPE (type));
4970 /* Or to force_fit_type, if nothing else. */
4971 tmp = copy_node (c);
4972 TREE_TYPE (tmp) = type;
4973 tmp = force_fit_type (tmp, -1, false, false);
4974 return TREE_INT_CST_HIGH (tmp) == TREE_INT_CST_HIGH (c)
4975 && TREE_INT_CST_LOW (tmp) == TREE_INT_CST_LOW (c);
4978 /* Subprogram of following function. Called by walk_tree.
4980 Return *TP if it is an automatic variable or parameter of the
4981 function passed in as DATA. */
4984 find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
4986 tree fn = (tree) data;
4991 else if (DECL_P (*tp)
4992 && lang_hooks.tree_inlining.auto_var_in_fn_p (*tp, fn))
4998 /* Returns true if T is, contains, or refers to a type with variable
4999 size. If FN is nonzero, only return true if a modifier of the type
5000 or position of FN is a variable or parameter inside FN.
5002 This concept is more general than that of C99 'variably modified types':
5003 in C99, a struct type is never variably modified because a VLA may not
5004 appear as a structure member. However, in GNU C code like:
5006 struct S { int i[f()]; };
5008 is valid, and other languages may define similar constructs. */
5011 variably_modified_type_p (tree type, tree fn)
5015 /* Test if T is either variable (if FN is zero) or an expression containing
5016 a variable in FN. */
5017 #define RETURN_TRUE_IF_VAR(T) \
5018 do { tree _t = (T); \
5019 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
5020 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
5021 return true; } while (0)
5023 if (type == error_mark_node)
5026 /* If TYPE itself has variable size, it is variably modified.
5028 We do not yet have a representation of the C99 '[*]' syntax.
5029 When a representation is chosen, this function should be modified
5030 to test for that case as well. */
5031 RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
5032 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT(type));
5034 switch (TREE_CODE (type))
5037 case REFERENCE_TYPE:
5040 if (variably_modified_type_p (TREE_TYPE (type), fn))
5046 /* If TYPE is a function type, it is variably modified if any of the
5047 parameters or the return type are variably modified. */
5048 if (variably_modified_type_p (TREE_TYPE (type), fn))
5051 for (t = TYPE_ARG_TYPES (type);
5052 t && t != void_list_node;
5054 if (variably_modified_type_p (TREE_VALUE (t), fn))
5063 /* Scalar types are variably modified if their end points
5065 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
5066 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
5071 case QUAL_UNION_TYPE:
5072 /* We can't see if any of the field are variably-modified by the
5073 definition we normally use, since that would produce infinite
5074 recursion via pointers. */
5075 /* This is variably modified if some field's type is. */
5076 for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
5077 if (TREE_CODE (t) == FIELD_DECL)
5079 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
5080 RETURN_TRUE_IF_VAR (DECL_SIZE (t));
5081 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
5083 if (TREE_CODE (type) == QUAL_UNION_TYPE)
5084 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
5092 /* The current language may have other cases to check, but in general,
5093 all other types are not variably modified. */
5094 return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
5096 #undef RETURN_TRUE_IF_VAR
5099 /* Given a DECL or TYPE, return the scope in which it was declared, or
5100 NULL_TREE if there is no containing scope. */
5103 get_containing_scope (tree t)
5105 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
5108 /* Return the innermost context enclosing DECL that is
5109 a FUNCTION_DECL, or zero if none. */
5112 decl_function_context (tree decl)
5116 if (TREE_CODE (decl) == ERROR_MARK)
5119 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
5120 where we look up the function at runtime. Such functions always take
5121 a first argument of type 'pointer to real context'.
5123 C++ should really be fixed to use DECL_CONTEXT for the real context,
5124 and use something else for the "virtual context". */
5125 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
5128 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
5130 context = DECL_CONTEXT (decl);
5132 while (context && TREE_CODE (context) != FUNCTION_DECL)
5134 if (TREE_CODE (context) == BLOCK)
5135 context = BLOCK_SUPERCONTEXT (context);
5137 context = get_containing_scope (context);
5143 /* Return the innermost context enclosing DECL that is
5144 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
5145 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
5148 decl_type_context (tree decl)
5150 tree context = DECL_CONTEXT (decl);
5153 switch (TREE_CODE (context))
5155 case NAMESPACE_DECL:
5156 case TRANSLATION_UNIT_DECL:
5161 case QUAL_UNION_TYPE:
5166 context = DECL_CONTEXT (context);
5170 context = BLOCK_SUPERCONTEXT (context);
5180 /* CALL is a CALL_EXPR. Return the declaration for the function
5181 called, or NULL_TREE if the called function cannot be
5185 get_callee_fndecl (tree call)
5189 /* It's invalid to call this function with anything but a
5191 gcc_assert (TREE_CODE (call) == CALL_EXPR);
5193 /* The first operand to the CALL is the address of the function
5195 addr = TREE_OPERAND (call, 0);
5199 /* If this is a readonly function pointer, extract its initial value. */
5200 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
5201 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
5202 && DECL_INITIAL (addr))
5203 addr = DECL_INITIAL (addr);
5205 /* If the address is just `&f' for some function `f', then we know
5206 that `f' is being called. */
5207 if (TREE_CODE (addr) == ADDR_EXPR
5208 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
5209 return TREE_OPERAND (addr, 0);
5211 /* We couldn't figure out what was being called. Maybe the front
5212 end has some idea. */
5213 return lang_hooks.lang_get_callee_fndecl (call);
5216 /* Print debugging information about tree nodes generated during the compile,
5217 and any language-specific information. */
5220 dump_tree_statistics (void)
5222 #ifdef GATHER_STATISTICS
5224 int total_nodes, total_bytes;
5227 fprintf (stderr, "\n??? tree nodes created\n\n");
5228 #ifdef GATHER_STATISTICS
5229 fprintf (stderr, "Kind Nodes Bytes\n");
5230 fprintf (stderr, "---------------------------------------\n");
5231 total_nodes = total_bytes = 0;
5232 for (i = 0; i < (int) all_kinds; i++)
5234 fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
5235 tree_node_counts[i], tree_node_sizes[i]);
5236 total_nodes += tree_node_counts[i];
5237 total_bytes += tree_node_sizes[i];
5239 fprintf (stderr, "---------------------------------------\n");
5240 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
5241 fprintf (stderr, "---------------------------------------\n");
5242 ssanames_print_statistics ();
5243 phinodes_print_statistics ();
5245 fprintf (stderr, "(No per-node statistics)\n");
5247 print_type_hash_statistics ();
5248 lang_hooks.print_statistics ();
5251 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
5253 /* Generate a crc32 of a string. */
5256 crc32_string (unsigned chksum, const char *string)
5260 unsigned value = *string << 24;
5263 for (ix = 8; ix--; value <<= 1)
5267 feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
5276 /* P is a string that will be used in a symbol. Mask out any characters
5277 that are not valid in that context. */
5280 clean_symbol_name (char *p)
5284 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
5287 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
5294 /* Generate a name for a function unique to this translation unit.
5295 TYPE is some string to identify the purpose of this function to the
5296 linker or collect2. */
5299 get_file_function_name_long (const char *type)
5305 if (first_global_object_name)
5306 p = first_global_object_name;
5309 /* We don't have anything that we know to be unique to this translation
5310 unit, so use what we do have and throw in some randomness. */
5312 const char *name = weak_global_object_name;
5313 const char *file = main_input_filename;
5318 file = input_filename;
5320 len = strlen (file);
5321 q = alloca (9 * 2 + len + 1);
5322 memcpy (q, file, len + 1);
5323 clean_symbol_name (q);
5325 sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
5326 crc32_string (0, flag_random_seed));
5331 buf = alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p) + strlen (type));
5333 /* Set up the name of the file-level functions we may need.
5334 Use a global object (which is already required to be unique over
5335 the program) rather than the file name (which imposes extra
5337 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
5339 return get_identifier (buf);
5342 /* If KIND=='I', return a suitable global initializer (constructor) name.
5343 If KIND=='D', return a suitable global clean-up (destructor) name. */
5346 get_file_function_name (int kind)
5353 return get_file_function_name_long (p);
5356 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
5357 The result is placed in BUFFER (which has length BIT_SIZE),
5358 with one bit in each char ('\000' or '\001').
5360 If the constructor is constant, NULL_TREE is returned.
5361 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
5364 get_set_constructor_bits (tree init, char *buffer, int bit_size)
5368 HOST_WIDE_INT domain_min
5369 = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init))), 0);
5370 tree non_const_bits = NULL_TREE;
5372 for (i = 0; i < bit_size; i++)
5375 for (vals = TREE_OPERAND (init, 1);
5376 vals != NULL_TREE; vals = TREE_CHAIN (vals))
5378 if (!host_integerp (TREE_VALUE (vals), 0)
5379 || (TREE_PURPOSE (vals) != NULL_TREE
5380 && !host_integerp (TREE_PURPOSE (vals), 0)))
5382 = tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits);
5383 else if (TREE_PURPOSE (vals) != NULL_TREE)
5385 /* Set a range of bits to ones. */
5386 HOST_WIDE_INT lo_index
5387 = tree_low_cst (TREE_PURPOSE (vals), 0) - domain_min;
5388 HOST_WIDE_INT hi_index
5389 = tree_low_cst (TREE_VALUE (vals), 0) - domain_min;
5391 gcc_assert (lo_index >= 0);
5392 gcc_assert (lo_index < bit_size);
5393 gcc_assert (hi_index >= 0);
5394 gcc_assert (hi_index < bit_size);
5395 for (; lo_index <= hi_index; lo_index++)
5396 buffer[lo_index] = 1;
5400 /* Set a single bit to one. */
5402 = tree_low_cst (TREE_VALUE (vals), 0) - domain_min;
5403 if (index < 0 || index >= bit_size)
5405 error ("invalid initializer for bit string");
5411 return non_const_bits;
5414 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
5415 The result is placed in BUFFER (which is an array of bytes).
5416 If the constructor is constant, NULL_TREE is returned.
5417 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
5420 get_set_constructor_bytes (tree init, unsigned char *buffer, int wd_size)
5423 int set_word_size = BITS_PER_UNIT;
5424 int bit_size = wd_size * set_word_size;
5426 unsigned char *bytep = buffer;
5427 char *bit_buffer = alloca (bit_size);
5428 tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
5430 for (i = 0; i < wd_size; i++)
5433 for (i = 0; i < bit_size; i++)
5437 if (BYTES_BIG_ENDIAN)
5438 *bytep |= (1 << (set_word_size - 1 - bit_pos));
5440 *bytep |= 1 << bit_pos;
5443 if (bit_pos >= set_word_size)
5444 bit_pos = 0, bytep++;
5446 return non_const_bits;
5449 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
5451 /* Complain that the tree code of NODE does not match the expected 0
5452 terminated list of trailing codes. The trailing code list can be
5453 empty, for a more vague error message. FILE, LINE, and FUNCTION
5454 are of the caller. */
5457 tree_check_failed (const tree node, const char *file,
5458 int line, const char *function, ...)
5462 unsigned length = 0;
5465 va_start (args, function);
5466 while ((code = va_arg (args, int)))
5467 length += 4 + strlen (tree_code_name[code]);
5471 va_start (args, function);
5472 length += strlen ("expected ");
5473 buffer = alloca (length);
5475 while ((code = va_arg (args, int)))
5477 const char *prefix = length ? " or " : "expected ";
5479 strcpy (buffer + length, prefix);
5480 length += strlen (prefix);
5481 strcpy (buffer + length, tree_code_name[code]);
5482 length += strlen (tree_code_name[code]);
5487 buffer = (char *)"unexpected node";
5489 internal_error ("tree check: %s, have %s in %s, at %s:%d",
5490 buffer, tree_code_name[TREE_CODE (node)],
5491 function, trim_filename (file), line);
5494 /* Complain that the tree code of NODE does match the expected 0
5495 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
5499 tree_not_check_failed (const tree node, const char *file,
5500 int line, const char *function, ...)
5504 unsigned length = 0;
5507 va_start (args, function);
5508 while ((code = va_arg (args, int)))
5509 length += 4 + strlen (tree_code_name[code]);
5511 va_start (args, function);
5512 buffer = alloca (length);
5514 while ((code = va_arg (args, int)))
5518 strcpy (buffer + length, " or ");
5521 strcpy (buffer + length, tree_code_name[code]);
5522 length += strlen (tree_code_name[code]);
5526 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
5527 buffer, tree_code_name[TREE_CODE (node)],
5528 function, trim_filename (file), line);
5531 /* Similar to tree_check_failed, except that we check for a class of tree
5532 code, given in CL. */
5535 tree_class_check_failed (const tree node, const enum tree_code_class cl,
5536 const char *file, int line, const char *function)
5539 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
5540 TREE_CODE_CLASS_STRING (cl),
5541 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
5542 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
5545 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
5546 (dynamically sized) vector. */
5549 tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
5550 const char *function)
5553 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
5554 idx + 1, len, function, trim_filename (file), line);
5557 /* Similar to above, except that the check is for the bounds of a PHI_NODE's
5558 (dynamically sized) vector. */
5561 phi_node_elt_check_failed (int idx, int len, const char *file, int line,
5562 const char *function)
5565 ("tree check: accessed elt %d of phi_node with %d elts in %s, at %s:%d",
5566 idx + 1, len, function, trim_filename (file), line);
5569 /* Similar to above, except that the check is for the bounds of the operand
5570 vector of an expression node. */
5573 tree_operand_check_failed (int idx, enum tree_code code, const char *file,
5574 int line, const char *function)
5577 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
5578 idx + 1, tree_code_name[code], TREE_CODE_LENGTH (code),
5579 function, trim_filename (file), line);
5581 #endif /* ENABLE_TREE_CHECKING */
5583 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
5584 and mapped to the machine mode MODE. Initialize its fields and build
5585 the information necessary for debugging output. */
5588 make_vector_type (tree innertype, int nunits, enum machine_mode mode)
5590 tree t = make_node (VECTOR_TYPE);
5592 TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype);
5593 TYPE_VECTOR_SUBPARTS (t) = nunits;
5594 TYPE_MODE (t) = mode;
5595 TYPE_READONLY (t) = TYPE_READONLY (innertype);
5596 TYPE_VOLATILE (t) = TYPE_VOLATILE (innertype);
5601 tree index = build_int_cst (NULL_TREE, nunits - 1);
5602 tree array = build_array_type (innertype, build_index_type (index));
5603 tree rt = make_node (RECORD_TYPE);
5605 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
5606 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
5608 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
5609 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
5610 the representation type, and we want to find that die when looking up
5611 the vector type. This is most easily achieved by making the TYPE_UID
5613 TYPE_UID (rt) = TYPE_UID (t);
5616 /* Build our main variant, based on the main variant of the inner type. */
5617 if (TYPE_MAIN_VARIANT (innertype) != innertype)
5619 tree innertype_main_variant = TYPE_MAIN_VARIANT (innertype);
5620 unsigned int hash = TYPE_HASH (innertype_main_variant);
5621 TYPE_MAIN_VARIANT (t)
5622 = type_hash_canon (hash, make_vector_type (innertype_main_variant,
5630 make_or_reuse_type (unsigned size, int unsignedp)
5632 if (size == INT_TYPE_SIZE)
5633 return unsignedp ? unsigned_type_node : integer_type_node;
5634 if (size == CHAR_TYPE_SIZE)
5635 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
5636 if (size == SHORT_TYPE_SIZE)
5637 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
5638 if (size == LONG_TYPE_SIZE)
5639 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
5640 if (size == LONG_LONG_TYPE_SIZE)
5641 return (unsignedp ? long_long_unsigned_type_node
5642 : long_long_integer_type_node);
5645 return make_unsigned_type (size);
5647 return make_signed_type (size);
5650 /* Create nodes for all integer types (and error_mark_node) using the sizes
5651 of C datatypes. The caller should call set_sizetype soon after calling
5652 this function to select one of the types as sizetype. */
5655 build_common_tree_nodes (bool signed_char, bool signed_sizetype)
5657 error_mark_node = make_node (ERROR_MARK);
5658 TREE_TYPE (error_mark_node) = error_mark_node;
5660 initialize_sizetypes (signed_sizetype);
5662 /* Define both `signed char' and `unsigned char'. */
5663 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
5664 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
5666 /* Define `char', which is like either `signed char' or `unsigned char'
5667 but not the same as either. */
5670 ? make_signed_type (CHAR_TYPE_SIZE)
5671 : make_unsigned_type (CHAR_TYPE_SIZE));
5673 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
5674 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
5675 integer_type_node = make_signed_type (INT_TYPE_SIZE);
5676 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
5677 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
5678 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
5679 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
5680 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
5682 /* Define a boolean type. This type only represents boolean values but
5683 may be larger than char depending on the value of BOOL_TYPE_SIZE.
5684 Front ends which want to override this size (i.e. Java) can redefine
5685 boolean_type_node before calling build_common_tree_nodes_2. */
5686 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
5687 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
5688 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
5689 TYPE_PRECISION (boolean_type_node) = 1;
5691 /* Fill in the rest of the sized types. Reuse existing type nodes
5693 intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
5694 intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
5695 intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
5696 intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
5697 intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
5699 unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
5700 unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
5701 unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
5702 unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
5703 unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
5705 access_public_node = get_identifier ("public");
5706 access_protected_node = get_identifier ("protected");
5707 access_private_node = get_identifier ("private");
5710 /* Call this function after calling build_common_tree_nodes and set_sizetype.
5711 It will create several other common tree nodes. */
5714 build_common_tree_nodes_2 (int short_double)
5716 /* Define these next since types below may used them. */
5717 integer_zero_node = build_int_cst (NULL_TREE, 0);
5718 integer_one_node = build_int_cst (NULL_TREE, 1);
5719 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
5721 size_zero_node = size_int (0);
5722 size_one_node = size_int (1);
5723 bitsize_zero_node = bitsize_int (0);
5724 bitsize_one_node = bitsize_int (1);
5725 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
5727 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
5728 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
5730 void_type_node = make_node (VOID_TYPE);
5731 layout_type (void_type_node);
5733 /* We are not going to have real types in C with less than byte alignment,
5734 so we might as well not have any types that claim to have it. */
5735 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
5736 TYPE_USER_ALIGN (void_type_node) = 0;
5738 null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
5739 layout_type (TREE_TYPE (null_pointer_node));
5741 ptr_type_node = build_pointer_type (void_type_node);
5743 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
5744 fileptr_type_node = ptr_type_node;
5746 float_type_node = make_node (REAL_TYPE);
5747 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
5748 layout_type (float_type_node);
5750 double_type_node = make_node (REAL_TYPE);
5752 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
5754 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
5755 layout_type (double_type_node);
5757 long_double_type_node = make_node (REAL_TYPE);
5758 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
5759 layout_type (long_double_type_node);
5761 float_ptr_type_node = build_pointer_type (float_type_node);
5762 double_ptr_type_node = build_pointer_type (double_type_node);
5763 long_double_ptr_type_node = build_pointer_type (long_double_type_node);
5764 integer_ptr_type_node = build_pointer_type (integer_type_node);
5766 complex_integer_type_node = make_node (COMPLEX_TYPE);
5767 TREE_TYPE (complex_integer_type_node) = integer_type_node;
5768 layout_type (complex_integer_type_node);
5770 complex_float_type_node = make_node (COMPLEX_TYPE);
5771 TREE_TYPE (complex_float_type_node) = float_type_node;
5772 layout_type (complex_float_type_node);
5774 complex_double_type_node = make_node (COMPLEX_TYPE);
5775 TREE_TYPE (complex_double_type_node) = double_type_node;
5776 layout_type (complex_double_type_node);
5778 complex_long_double_type_node = make_node (COMPLEX_TYPE);
5779 TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
5780 layout_type (complex_long_double_type_node);
5783 tree t = targetm.build_builtin_va_list ();
5785 /* Many back-ends define record types without setting TYPE_NAME.
5786 If we copied the record type here, we'd keep the original
5787 record type without a name. This breaks name mangling. So,
5788 don't copy record types and let c_common_nodes_and_builtins()
5789 declare the type to be __builtin_va_list. */
5790 if (TREE_CODE (t) != RECORD_TYPE)
5791 t = build_variant_type_copy (t);
5793 va_list_type_node = t;
5797 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
5800 local_define_builtin (const char *name, tree type, enum built_in_function code,
5801 const char *library_name, int ecf_flags)
5805 decl = lang_hooks.builtin_function (name, type, code, BUILT_IN_NORMAL,
5806 library_name, NULL_TREE);
5807 if (ecf_flags & ECF_CONST)
5808 TREE_READONLY (decl) = 1;
5809 if (ecf_flags & ECF_PURE)
5810 DECL_IS_PURE (decl) = 1;
5811 if (ecf_flags & ECF_NORETURN)
5812 TREE_THIS_VOLATILE (decl) = 1;
5813 if (ecf_flags & ECF_NOTHROW)
5814 TREE_NOTHROW (decl) = 1;
5815 if (ecf_flags & ECF_MALLOC)
5816 DECL_IS_MALLOC (decl) = 1;
5818 built_in_decls[code] = decl;
5819 implicit_built_in_decls[code] = decl;
5822 /* Call this function after instantiating all builtins that the language
5823 front end cares about. This will build the rest of the builtins that
5824 are relied upon by the tree optimizers and the middle-end. */
5827 build_common_builtin_nodes (void)
5831 if (built_in_decls[BUILT_IN_MEMCPY] == NULL
5832 || built_in_decls[BUILT_IN_MEMMOVE] == NULL)
5834 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
5835 tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
5836 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
5837 ftype = build_function_type (ptr_type_node, tmp);
5839 if (built_in_decls[BUILT_IN_MEMCPY] == NULL)
5840 local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
5841 "memcpy", ECF_NOTHROW);
5842 if (built_in_decls[BUILT_IN_MEMMOVE] == NULL)
5843 local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
5844 "memmove", ECF_NOTHROW);
5847 if (built_in_decls[BUILT_IN_MEMCMP] == NULL)
5849 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
5850 tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
5851 tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
5852 ftype = build_function_type (ptr_type_node, tmp);
5853 local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
5854 "memcmp", ECF_PURE | ECF_NOTHROW);
5857 if (built_in_decls[BUILT_IN_MEMSET] == NULL)
5859 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
5860 tmp = tree_cons (NULL_TREE, integer_type_node, tmp);
5861 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
5862 ftype = build_function_type (ptr_type_node, tmp);
5863 local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
5864 "memset", ECF_NOTHROW);
5867 if (built_in_decls[BUILT_IN_ALLOCA] == NULL)
5869 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
5870 ftype = build_function_type (ptr_type_node, tmp);
5871 local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
5872 "alloca", ECF_NOTHROW | ECF_MALLOC);
5875 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
5876 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
5877 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
5878 ftype = build_function_type (void_type_node, tmp);
5879 local_define_builtin ("__builtin_init_trampoline", ftype,
5880 BUILT_IN_INIT_TRAMPOLINE,
5881 "__builtin_init_trampoline", ECF_NOTHROW);
5883 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
5884 ftype = build_function_type (ptr_type_node, tmp);
5885 local_define_builtin ("__builtin_adjust_trampoline", ftype,
5886 BUILT_IN_ADJUST_TRAMPOLINE,
5887 "__builtin_adjust_trampoline",
5888 ECF_CONST | ECF_NOTHROW);
5890 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
5891 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
5892 ftype = build_function_type (void_type_node, tmp);
5893 local_define_builtin ("__builtin_nonlocal_goto", ftype,
5894 BUILT_IN_NONLOCAL_GOTO,
5895 "__builtin_nonlocal_goto",
5896 ECF_NORETURN | ECF_NOTHROW);
5898 ftype = build_function_type (ptr_type_node, void_list_node);
5899 local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
5900 "__builtin_stack_save", ECF_NOTHROW);
5902 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
5903 ftype = build_function_type (void_type_node, tmp);
5904 local_define_builtin ("__builtin_stack_restore", ftype,
5905 BUILT_IN_STACK_RESTORE,
5906 "__builtin_stack_restore", ECF_NOTHROW);
5908 ftype = build_function_type (void_type_node, void_list_node);
5909 local_define_builtin ("__builtin_profile_func_enter", ftype,
5910 BUILT_IN_PROFILE_FUNC_ENTER, "profile_func_enter", 0);
5911 local_define_builtin ("__builtin_profile_func_exit", ftype,
5912 BUILT_IN_PROFILE_FUNC_EXIT, "profile_func_exit", 0);
5914 /* Complex multiplication and division. These are handled as builtins
5915 rather than optabs because emit_library_call_value doesn't support
5916 complex. Further, we can do slightly better with folding these
5917 beasties if the real and complex parts of the arguments are separate. */
5919 enum machine_mode mode;
5921 for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
5923 char mode_name_buf[4], *q;
5925 enum built_in_function mcode, dcode;
5926 tree type, inner_type;
5928 type = lang_hooks.types.type_for_mode (mode, 0);
5931 inner_type = TREE_TYPE (type);
5933 tmp = tree_cons (NULL_TREE, inner_type, void_list_node);
5934 tmp = tree_cons (NULL_TREE, inner_type, tmp);
5935 tmp = tree_cons (NULL_TREE, inner_type, tmp);
5936 tmp = tree_cons (NULL_TREE, inner_type, tmp);
5937 ftype = build_function_type (type, tmp);
5939 mcode = BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT;
5940 dcode = BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT;
5942 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
5946 built_in_names[mcode] = concat ("__mul", mode_name_buf, "3", NULL);
5947 local_define_builtin (built_in_names[mcode], ftype, mcode,
5948 built_in_names[mcode], ECF_CONST | ECF_NOTHROW);
5950 built_in_names[dcode] = concat ("__div", mode_name_buf, "3", NULL);
5951 local_define_builtin (built_in_names[dcode], ftype, dcode,
5952 built_in_names[dcode], ECF_CONST | ECF_NOTHROW);
5957 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
5960 If we requested a pointer to a vector, build up the pointers that
5961 we stripped off while looking for the inner type. Similarly for
5962 return values from functions.
5964 The argument TYPE is the top of the chain, and BOTTOM is the
5965 new type which we will point to. */
5968 reconstruct_complex_type (tree type, tree bottom)
5972 if (POINTER_TYPE_P (type))
5974 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5975 outer = build_pointer_type (inner);
5977 else if (TREE_CODE (type) == ARRAY_TYPE)
5979 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5980 outer = build_array_type (inner, TYPE_DOMAIN (type));
5982 else if (TREE_CODE (type) == FUNCTION_TYPE)
5984 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5985 outer = build_function_type (inner, TYPE_ARG_TYPES (type));
5987 else if (TREE_CODE (type) == METHOD_TYPE)
5990 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5991 /* The build_method_type_directly() routine prepends 'this' to argument list,
5992 so we must compensate by getting rid of it. */
5993 argtypes = TYPE_ARG_TYPES (type);
5994 outer = build_method_type_directly (TYPE_METHOD_BASETYPE (type),
5996 TYPE_ARG_TYPES (type));
5997 TYPE_ARG_TYPES (outer) = argtypes;
6002 TYPE_READONLY (outer) = TYPE_READONLY (type);
6003 TYPE_VOLATILE (outer) = TYPE_VOLATILE (type);
6008 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
6011 build_vector_type_for_mode (tree innertype, enum machine_mode mode)
6015 switch (GET_MODE_CLASS (mode))
6017 case MODE_VECTOR_INT:
6018 case MODE_VECTOR_FLOAT:
6019 nunits = GET_MODE_NUNITS (mode);
6023 /* Check that there are no leftover bits. */
6024 gcc_assert (GET_MODE_BITSIZE (mode)
6025 % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
6027 nunits = GET_MODE_BITSIZE (mode)
6028 / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
6035 return make_vector_type (innertype, nunits, mode);
6038 /* Similarly, but takes the inner type and number of units, which must be
6042 build_vector_type (tree innertype, int nunits)
6044 return make_vector_type (innertype, nunits, VOIDmode);
6047 /* Given an initializer INIT, return TRUE if INIT is zero or some
6048 aggregate of zeros. Otherwise return FALSE. */
6050 initializer_zerop (tree init)
6056 switch (TREE_CODE (init))
6059 return integer_zerop (init);
6062 /* ??? Note that this is not correct for C4X float formats. There,
6063 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
6064 negative exponent. */
6065 return real_zerop (init)
6066 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
6069 return integer_zerop (init)
6070 || (real_zerop (init)
6071 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
6072 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
6075 for (elt = TREE_VECTOR_CST_ELTS (init); elt; elt = TREE_CHAIN (elt))
6076 if (!initializer_zerop (TREE_VALUE (elt)))
6081 elt = CONSTRUCTOR_ELTS (init);
6082 if (elt == NULL_TREE)
6085 for (; elt ; elt = TREE_CHAIN (elt))
6086 if (! initializer_zerop (TREE_VALUE (elt)))
6096 add_var_to_bind_expr (tree bind_expr, tree var)
6098 BIND_EXPR_VARS (bind_expr)
6099 = chainon (BIND_EXPR_VARS (bind_expr), var);
6100 if (BIND_EXPR_BLOCK (bind_expr))
6101 BLOCK_VARS (BIND_EXPR_BLOCK (bind_expr))
6102 = BIND_EXPR_VARS (bind_expr);
6105 /* Build an empty statement. */
6108 build_empty_stmt (void)
6110 return build1 (NOP_EXPR, void_type_node, size_zero_node);
6114 /* Returns true if it is possible to prove that the index of
6115 an array access REF (an ARRAY_REF expression) falls into the
6119 in_array_bounds_p (tree ref)
6121 tree idx = TREE_OPERAND (ref, 1);
6124 if (TREE_CODE (idx) != INTEGER_CST)
6127 min = array_ref_low_bound (ref);
6128 max = array_ref_up_bound (ref);
6131 || TREE_CODE (min) != INTEGER_CST
6132 || TREE_CODE (max) != INTEGER_CST)
6135 if (tree_int_cst_lt (idx, min)
6136 || tree_int_cst_lt (max, idx))
6142 /* Return true if T (assumed to be a DECL) is a global variable. */
6145 is_global_var (tree t)
6147 return (TREE_STATIC (t) || DECL_EXTERNAL (t));
6150 /* Return true if T (assumed to be a DECL) must be assigned a memory
6154 needs_to_live_in_memory (tree t)
6156 return (TREE_ADDRESSABLE (t)
6157 || is_global_var (t)
6158 || (TREE_CODE (t) == RESULT_DECL
6159 && aggregate_value_p (t, current_function_decl)));
6162 /* There are situations in which a language considers record types
6163 compatible which have different field lists. Decide if two fields
6164 are compatible. It is assumed that the parent records are compatible. */
6167 fields_compatible_p (tree f1, tree f2)
6169 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1),
6170 DECL_FIELD_BIT_OFFSET (f2), OEP_ONLY_CONST))
6173 if (!operand_equal_p (DECL_FIELD_OFFSET (f1),
6174 DECL_FIELD_OFFSET (f2), OEP_ONLY_CONST))
6177 if (!lang_hooks.types_compatible_p (TREE_TYPE (f1), TREE_TYPE (f2)))
6183 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
6186 find_compatible_field (tree record, tree orig_field)
6190 for (f = TYPE_FIELDS (record); f ; f = TREE_CHAIN (f))
6191 if (TREE_CODE (f) == FIELD_DECL
6192 && fields_compatible_p (f, orig_field))
6195 /* ??? Why isn't this on the main fields list? */
6196 f = TYPE_VFIELD (record);
6197 if (f && TREE_CODE (f) == FIELD_DECL
6198 && fields_compatible_p (f, orig_field))
6201 /* ??? We should abort here, but Java appears to do Bad Things
6202 with inherited fields. */
6206 /* Return value of a constant X. */
6209 int_cst_value (tree x)
6211 unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
6212 unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
6213 bool negative = ((val >> (bits - 1)) & 1) != 0;
6215 gcc_assert (bits <= HOST_BITS_PER_WIDE_INT);
6218 val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1;
6220 val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1);
6225 /* Returns the greatest common divisor of A and B, which must be
6229 tree_fold_gcd (tree a, tree b)
6232 tree type = TREE_TYPE (a);
6234 gcc_assert (TREE_CODE (a) == INTEGER_CST);
6235 gcc_assert (TREE_CODE (b) == INTEGER_CST);
6237 if (integer_zerop (a))
6240 if (integer_zerop (b))
6243 if (tree_int_cst_sgn (a) == -1)
6244 a = fold (build2 (MULT_EXPR, type, a,
6245 convert (type, integer_minus_one_node)));
6247 if (tree_int_cst_sgn (b) == -1)
6248 b = fold (build2 (MULT_EXPR, type, b,
6249 convert (type, integer_minus_one_node)));
6253 a_mod_b = fold (build2 (FLOOR_MOD_EXPR, type, a, b));
6255 if (!TREE_INT_CST_LOW (a_mod_b)
6256 && !TREE_INT_CST_HIGH (a_mod_b))
6264 /* Returns unsigned variant of TYPE. */
6267 unsigned_type_for (tree type)
6269 return lang_hooks.types.unsigned_type (type);
6272 /* Returns signed variant of TYPE. */
6275 signed_type_for (tree type)
6277 return lang_hooks.types.signed_type (type);
6280 /* Returns the largest value obtainable by casting something in INNER type to
6284 upper_bound_in_type (tree outer, tree inner)
6286 unsigned HOST_WIDE_INT lo, hi;
6287 unsigned bits = TYPE_PRECISION (inner);
6289 if (TYPE_UNSIGNED (outer) || TYPE_UNSIGNED (inner))
6291 /* Zero extending in these cases. */
6292 if (bits <= HOST_BITS_PER_WIDE_INT)
6295 lo = (~(unsigned HOST_WIDE_INT) 0)
6296 >> (HOST_BITS_PER_WIDE_INT - bits);
6300 hi = (~(unsigned HOST_WIDE_INT) 0)
6301 >> (2 * HOST_BITS_PER_WIDE_INT - bits);
6302 lo = ~(unsigned HOST_WIDE_INT) 0;
6307 /* Sign extending in these cases. */
6308 if (bits <= HOST_BITS_PER_WIDE_INT)
6311 lo = (~(unsigned HOST_WIDE_INT) 0)
6312 >> (HOST_BITS_PER_WIDE_INT - bits) >> 1;
6316 hi = (~(unsigned HOST_WIDE_INT) 0)
6317 >> (2 * HOST_BITS_PER_WIDE_INT - bits) >> 1;
6318 lo = ~(unsigned HOST_WIDE_INT) 0;
6322 return fold_convert (outer,
6323 build_int_cst_wide (inner, lo, hi));
6326 /* Returns the smallest value obtainable by casting something in INNER type to
6330 lower_bound_in_type (tree outer, tree inner)
6332 unsigned HOST_WIDE_INT lo, hi;
6333 unsigned bits = TYPE_PRECISION (inner);
6335 if (TYPE_UNSIGNED (outer) || TYPE_UNSIGNED (inner))
6337 else if (bits <= HOST_BITS_PER_WIDE_INT)
6339 hi = ~(unsigned HOST_WIDE_INT) 0;
6340 lo = (~(unsigned HOST_WIDE_INT) 0) << (bits - 1);
6344 hi = (~(unsigned HOST_WIDE_INT) 0) << (bits - HOST_BITS_PER_WIDE_INT - 1);
6348 return fold_convert (outer,
6349 build_int_cst_wide (inner, lo, hi));
6352 /* Return nonzero if two operands that are suitable for PHI nodes are
6353 necessarily equal. Specifically, both ARG0 and ARG1 must be either
6354 SSA_NAME or invariant. Note that this is strictly an optimization.
6355 That is, callers of this function can directly call operand_equal_p
6356 and get the same result, only slower. */
6359 operand_equal_for_phi_arg_p (tree arg0, tree arg1)
6363 if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
6365 return operand_equal_p (arg0, arg1, 0);
6368 /* Returns number of zeros at the end of binary representation of X.
6370 ??? Use ffs if available? */
6373 num_ending_zeros (tree x)
6375 unsigned HOST_WIDE_INT fr, nfr;
6376 unsigned num, abits;
6377 tree type = TREE_TYPE (x);
6379 if (TREE_INT_CST_LOW (x) == 0)
6381 num = HOST_BITS_PER_WIDE_INT;
6382 fr = TREE_INT_CST_HIGH (x);
6387 fr = TREE_INT_CST_LOW (x);
6390 for (abits = HOST_BITS_PER_WIDE_INT / 2; abits; abits /= 2)
6393 if (nfr << abits == fr)
6400 if (num > TYPE_PRECISION (type))
6401 num = TYPE_PRECISION (type);
6403 return build_int_cst_type (type, num);
6406 #include "gt-tree.h"