1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This file contains the low level primitives for operating on tree nodes,
23 including allocation, list operations, interning of identifiers,
24 construction of data type nodes and statement nodes,
25 and construction of type conversion nodes. It also contains
26 tables index by tree code that describe how to take apart
29 It is intended to be language-independent, but occasionally
30 calls language-dependent routines defined (for C) in typecheck.c. */
34 #include "coretypes.h"
47 #include "langhooks.h"
48 #include "tree-iterator.h"
49 #include "basic-block.h"
50 #include "tree-flow.h"
53 /* obstack.[ch] explicitly declined to prototype this. */
54 extern int _obstack_allocated_p (struct obstack *h, void *obj);
56 #ifdef GATHER_STATISTICS
57 /* Statistics-gathering stuff. */
59 int tree_node_counts[(int) all_kinds];
60 int tree_node_sizes[(int) all_kinds];
62 /* Keep in sync with tree.h:enum tree_node_kind. */
63 static const char * const tree_node_kind_names[] = {
82 #endif /* GATHER_STATISTICS */
84 /* Unique id for next decl created. */
85 static GTY(()) int next_decl_uid;
86 /* Unique id for next type created. */
87 static GTY(()) int next_type_uid = 1;
89 /* Since we cannot rehash a type after it is in the table, we have to
90 keep the hash code. */
92 struct type_hash GTY(())
98 /* Initial size of the hash table (rounded to next prime). */
99 #define TYPE_HASH_INITIAL_SIZE 1000
101 /* Now here is the hash table. When recording a type, it is added to
102 the slot whose index is the hash code. Note that the hash table is
103 used for several kinds of types (function types, array types and
104 array index range types, for now). While all these live in the
105 same table, they are completely independent, and the hash code is
106 computed differently for each of these. */
108 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
109 htab_t type_hash_table;
111 static void set_type_quals (tree, int);
112 static int type_hash_eq (const void *, const void *);
113 static hashval_t type_hash_hash (const void *);
114 static void print_type_hash_statistics (void);
115 static tree make_vector_type (tree, int, enum machine_mode);
116 static int type_hash_marked_p (const void *);
117 static unsigned int type_hash_list (tree, hashval_t);
118 static unsigned int attribute_hash_list (tree, hashval_t);
120 tree global_trees[TI_MAX];
121 tree integer_types[itk_none];
128 /* Initialize the hash table of types. */
129 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
134 /* The name of the object as the assembler will see it (but before any
135 translations made by ASM_OUTPUT_LABELREF). Often this is the same
136 as DECL_NAME. It is an IDENTIFIER_NODE. */
138 decl_assembler_name (tree decl)
140 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
141 lang_hooks.set_decl_assembler_name (decl);
142 return DECL_CHECK (decl)->decl.assembler_name;
145 /* Compute the number of bytes occupied by 'node'. This routine only
146 looks at TREE_CODE and, if the code is TREE_VEC, TREE_VEC_LENGTH. */
148 tree_size (tree node)
150 enum tree_code code = TREE_CODE (node);
152 switch (TREE_CODE_CLASS (code))
154 case 'd': /* A decl node */
155 return sizeof (struct tree_decl);
157 case 't': /* a type node */
158 return sizeof (struct tree_type);
160 case 'r': /* a reference */
161 case 'e': /* an expression */
162 case 's': /* an expression with side effects */
163 case '<': /* a comparison expression */
164 case '1': /* a unary arithmetic expression */
165 case '2': /* a binary arithmetic expression */
166 return (sizeof (struct tree_exp)
167 + TREE_CODE_LENGTH (code) * sizeof (char *) - sizeof (char *));
169 case 'c': /* a constant */
172 case INTEGER_CST: return sizeof (struct tree_int_cst);
173 case REAL_CST: return sizeof (struct tree_real_cst);
174 case COMPLEX_CST: return sizeof (struct tree_complex);
175 case VECTOR_CST: return sizeof (struct tree_vector);
176 case STRING_CST: return sizeof (struct tree_string);
178 return lang_hooks.tree_size (code);
181 case 'x': /* something random, like an identifier. */
184 case IDENTIFIER_NODE: return lang_hooks.identifier_size;
185 case TREE_LIST: return sizeof (struct tree_list);
186 case TREE_VEC: return (sizeof (struct tree_vec)
187 + TREE_VEC_LENGTH(node) * sizeof(char *)
191 case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
193 case PHI_NODE: return (sizeof (struct tree_phi_node)
194 + (PHI_ARG_CAPACITY (node) - 1) *
195 sizeof (struct phi_arg_d));
197 case SSA_NAME: return sizeof (struct tree_ssa_name);
199 case STATEMENT_LIST: return sizeof (struct tree_statement_list);
200 case BLOCK: return sizeof (struct tree_block);
201 case VALUE_HANDLE: return sizeof (struct tree_value_handle);
204 return lang_hooks.tree_size (code);
212 /* Return a newly allocated node of code CODE.
213 For decl and type nodes, some other fields are initialized.
214 The rest of the node is initialized to zero.
216 Achoo! I got a code in the node. */
219 make_node_stat (enum tree_code code MEM_STAT_DECL)
222 int type = TREE_CODE_CLASS (code);
224 #ifdef GATHER_STATISTICS
227 struct tree_common ttmp;
229 /* We can't allocate a TREE_VEC, PHI_NODE, or STRING_CST
230 without knowing how many elements it will have. */
231 if (code == TREE_VEC || code == PHI_NODE)
234 TREE_SET_CODE ((tree)&ttmp, code);
235 length = tree_size ((tree)&ttmp);
237 #ifdef GATHER_STATISTICS
240 case 'd': /* A decl node */
244 case 't': /* a type node */
248 case 's': /* an expression with side effects */
252 case 'r': /* a reference */
256 case 'e': /* an expression */
257 case '<': /* a comparison expression */
258 case '1': /* a unary arithmetic expression */
259 case '2': /* a binary arithmetic expression */
263 case 'c': /* a constant */
267 case 'x': /* something random, like an identifier. */
268 if (code == IDENTIFIER_NODE)
270 else if (code == TREE_VEC)
272 else if (code == TREE_BINFO)
274 else if (code == PHI_NODE)
276 else if (code == SSA_NAME)
277 kind = ssa_name_kind;
278 else if (code == BLOCK)
288 tree_node_counts[(int) kind]++;
289 tree_node_sizes[(int) kind] += length;
292 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
294 memset (t, 0, length);
296 TREE_SET_CODE (t, code);
301 TREE_SIDE_EFFECTS (t) = 1;
305 if (code != FUNCTION_DECL)
307 DECL_USER_ALIGN (t) = 0;
308 DECL_IN_SYSTEM_HEADER (t) = in_system_header;
309 DECL_SOURCE_LOCATION (t) = input_location;
310 DECL_UID (t) = next_decl_uid++;
312 /* We have not yet computed the alias set for this declaration. */
313 DECL_POINTER_ALIAS_SET (t) = -1;
317 TYPE_UID (t) = next_type_uid++;
318 TYPE_ALIGN (t) = char_type_node ? TYPE_ALIGN (char_type_node) : 0;
319 TYPE_USER_ALIGN (t) = 0;
320 TYPE_MAIN_VARIANT (t) = t;
322 /* Default to no attributes for type, but let target change that. */
323 TYPE_ATTRIBUTES (t) = NULL_TREE;
324 targetm.set_default_type_attributes (t);
326 /* We have not yet computed the alias set for this type. */
327 TYPE_ALIAS_SET (t) = -1;
331 TREE_CONSTANT (t) = 1;
332 TREE_INVARIANT (t) = 1;
341 case PREDECREMENT_EXPR:
342 case PREINCREMENT_EXPR:
343 case POSTDECREMENT_EXPR:
344 case POSTINCREMENT_EXPR:
345 /* All of these have side-effects, no matter what their
347 TREE_SIDE_EFFECTS (t) = 1;
359 /* Return a new node with the same contents as NODE except that its
360 TREE_CHAIN is zero and it has a fresh uid. */
363 copy_node_stat (tree node MEM_STAT_DECL)
366 enum tree_code code = TREE_CODE (node);
369 #ifdef ENABLE_CHECKING
370 if (code == STATEMENT_LIST)
374 length = tree_size (node);
375 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
376 memcpy (t, node, length);
379 TREE_ASM_WRITTEN (t) = 0;
380 TREE_VISITED (t) = 0;
383 if (TREE_CODE_CLASS (code) == 'd')
384 DECL_UID (t) = next_decl_uid++;
385 else if (TREE_CODE_CLASS (code) == 't')
387 TYPE_UID (t) = next_type_uid++;
388 /* The following is so that the debug code for
389 the copy is different from the original type.
390 The two statements usually duplicate each other
391 (because they clear fields of the same union),
392 but the optimizer should catch that. */
393 TYPE_SYMTAB_POINTER (t) = 0;
394 TYPE_SYMTAB_ADDRESS (t) = 0;
396 /* Do not copy the values cache. */
397 if (TYPE_CACHED_VALUES_P(t))
399 TYPE_CACHED_VALUES_P (t) = 0;
400 TYPE_CACHED_VALUES (t) = NULL_TREE;
407 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
408 For example, this can copy a list made of TREE_LIST nodes. */
411 copy_list (tree list)
419 head = prev = copy_node (list);
420 next = TREE_CHAIN (list);
423 TREE_CHAIN (prev) = copy_node (next);
424 prev = TREE_CHAIN (prev);
425 next = TREE_CHAIN (next);
431 /* Create an INT_CST node with a LOW value sign extended. */
434 build_int_cst (tree type, HOST_WIDE_INT low)
436 return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
439 /* Create an INT_CST node with a LOW value zero extended. */
442 build_int_cstu (tree type, unsigned HOST_WIDE_INT low)
444 return build_int_cst_wide (type, low, 0);
447 /* Create an INT_CST node with a LOW value zero or sign extended depending
451 build_int_cst_type (tree type, HOST_WIDE_INT low)
453 unsigned HOST_WIDE_INT val = (unsigned HOST_WIDE_INT) low;
460 type = integer_type_node;
462 bits = TYPE_PRECISION (type);
463 signed_p = !TYPE_UNSIGNED (type);
464 negative = ((val >> (bits - 1)) & 1) != 0;
466 if (signed_p && negative)
468 if (bits < HOST_BITS_PER_WIDE_INT)
469 val = val | ((~(unsigned HOST_WIDE_INT) 0) << bits);
470 ret = build_int_cst_wide (type, val, ~(unsigned HOST_WIDE_INT) 0);
474 if (bits < HOST_BITS_PER_WIDE_INT)
475 val = val & ~((~(unsigned HOST_WIDE_INT) 0) << bits);
476 ret = build_int_cst_wide (type, val, 0);
482 /* Create an INT_CST node of TYPE and value HI:LOW. If TYPE is NULL,
483 integer_type_node is used. */
486 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
493 type = integer_type_node;
495 switch (TREE_CODE (type))
499 /* Cache NULL pointer. */
508 /* Cache false or true. */
517 if (TYPE_UNSIGNED (type))
520 limit = INTEGER_SHARE_LIMIT;
521 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
527 limit = INTEGER_SHARE_LIMIT + 1;
528 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
530 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
540 if (!TYPE_CACHED_VALUES_P (type))
542 TYPE_CACHED_VALUES_P (type) = 1;
543 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
546 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
549 /* Make sure no one is clobbering the shared constant. */
550 if (TREE_TYPE (t) != type)
552 if (TREE_INT_CST_LOW (t) != low || TREE_INT_CST_HIGH (t) != hi)
558 t = make_node (INTEGER_CST);
560 TREE_INT_CST_LOW (t) = low;
561 TREE_INT_CST_HIGH (t) = hi;
562 TREE_TYPE (t) = type;
565 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
570 /* Checks that X is integer constant that can be expressed in (unsigned)
571 HOST_WIDE_INT without loss of precision. */
574 cst_and_fits_in_hwi (tree x)
576 if (TREE_CODE (x) != INTEGER_CST)
579 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT)
582 return (TREE_INT_CST_HIGH (x) == 0
583 || TREE_INT_CST_HIGH (x) == -1);
586 /* Return a new VECTOR_CST node whose type is TYPE and whose values
587 are in a list pointed by VALS. */
590 build_vector (tree type, tree vals)
592 tree v = make_node (VECTOR_CST);
593 int over1 = 0, over2 = 0;
596 TREE_VECTOR_CST_ELTS (v) = vals;
597 TREE_TYPE (v) = type;
599 /* Iterate through elements and check for overflow. */
600 for (link = vals; link; link = TREE_CHAIN (link))
602 tree value = TREE_VALUE (link);
604 over1 |= TREE_OVERFLOW (value);
605 over2 |= TREE_CONSTANT_OVERFLOW (value);
608 TREE_OVERFLOW (v) = over1;
609 TREE_CONSTANT_OVERFLOW (v) = over2;
614 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
615 are in a list pointed to by VALS. */
617 build_constructor (tree type, tree vals)
619 tree c = make_node (CONSTRUCTOR);
620 TREE_TYPE (c) = type;
621 CONSTRUCTOR_ELTS (c) = vals;
623 /* ??? May not be necessary. Mirrors what build does. */
626 TREE_SIDE_EFFECTS (c) = TREE_SIDE_EFFECTS (vals);
627 TREE_READONLY (c) = TREE_READONLY (vals);
628 TREE_CONSTANT (c) = TREE_CONSTANT (vals);
629 TREE_INVARIANT (c) = TREE_INVARIANT (vals);
635 /* Return a new REAL_CST node whose type is TYPE and value is D. */
638 build_real (tree type, REAL_VALUE_TYPE d)
644 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
645 Consider doing it via real_convert now. */
647 v = make_node (REAL_CST);
648 dp = ggc_alloc (sizeof (REAL_VALUE_TYPE));
649 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
651 TREE_TYPE (v) = type;
652 TREE_REAL_CST_PTR (v) = dp;
653 TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
657 /* Return a new REAL_CST node whose type is TYPE
658 and whose value is the integer value of the INTEGER_CST node I. */
661 real_value_from_int_cst (tree type, tree i)
665 /* Clear all bits of the real value type so that we can later do
666 bitwise comparisons to see if two values are the same. */
667 memset (&d, 0, sizeof d);
669 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
670 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
671 TYPE_UNSIGNED (TREE_TYPE (i)));
675 /* Given a tree representing an integer constant I, return a tree
676 representing the same value as a floating-point constant of type TYPE. */
679 build_real_from_int_cst (tree type, tree i)
682 int overflow = TREE_OVERFLOW (i);
684 v = build_real (type, real_value_from_int_cst (type, i));
686 TREE_OVERFLOW (v) |= overflow;
687 TREE_CONSTANT_OVERFLOW (v) |= overflow;
691 /* Return a newly constructed STRING_CST node whose value is
692 the LEN characters at STR.
693 The TREE_TYPE is not initialized. */
696 build_string (int len, const char *str)
698 tree s = make_node (STRING_CST);
700 TREE_STRING_LENGTH (s) = len;
701 TREE_STRING_POINTER (s) = ggc_alloc_string (str, len);
706 /* Return a newly constructed COMPLEX_CST node whose value is
707 specified by the real and imaginary parts REAL and IMAG.
708 Both REAL and IMAG should be constant nodes. TYPE, if specified,
709 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
712 build_complex (tree type, tree real, tree imag)
714 tree t = make_node (COMPLEX_CST);
716 TREE_REALPART (t) = real;
717 TREE_IMAGPART (t) = imag;
718 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
719 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
720 TREE_CONSTANT_OVERFLOW (t)
721 = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
725 /* Build a BINFO with LEN language slots. */
728 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
731 size_t length = (offsetof (struct tree_binfo, base_binfos)
732 + VEC_embedded_size (tree, base_binfos));
734 #ifdef GATHER_STATISTICS
735 tree_node_counts[(int) binfo_kind]++;
736 tree_node_sizes[(int) binfo_kind] += length;
739 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
741 memset (t, 0, offsetof (struct tree_binfo, base_binfos));
743 TREE_SET_CODE (t, TREE_BINFO);
745 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos);
751 /* Build a newly constructed TREE_VEC node of length LEN. */
754 make_tree_vec_stat (int len MEM_STAT_DECL)
757 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
759 #ifdef GATHER_STATISTICS
760 tree_node_counts[(int) vec_kind]++;
761 tree_node_sizes[(int) vec_kind] += length;
764 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
766 memset (t, 0, length);
768 TREE_SET_CODE (t, TREE_VEC);
769 TREE_VEC_LENGTH (t) = len;
774 /* Return 1 if EXPR is the integer constant zero or a complex constant
778 integer_zerop (tree expr)
782 return ((TREE_CODE (expr) == INTEGER_CST
783 && ! TREE_CONSTANT_OVERFLOW (expr)
784 && TREE_INT_CST_LOW (expr) == 0
785 && TREE_INT_CST_HIGH (expr) == 0)
786 || (TREE_CODE (expr) == COMPLEX_CST
787 && integer_zerop (TREE_REALPART (expr))
788 && integer_zerop (TREE_IMAGPART (expr))));
791 /* Return 1 if EXPR is the integer constant one or the corresponding
795 integer_onep (tree expr)
799 return ((TREE_CODE (expr) == INTEGER_CST
800 && ! TREE_CONSTANT_OVERFLOW (expr)
801 && TREE_INT_CST_LOW (expr) == 1
802 && TREE_INT_CST_HIGH (expr) == 0)
803 || (TREE_CODE (expr) == COMPLEX_CST
804 && integer_onep (TREE_REALPART (expr))
805 && integer_zerop (TREE_IMAGPART (expr))));
808 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
809 it contains. Likewise for the corresponding complex constant. */
812 integer_all_onesp (tree expr)
819 if (TREE_CODE (expr) == COMPLEX_CST
820 && integer_all_onesp (TREE_REALPART (expr))
821 && integer_zerop (TREE_IMAGPART (expr)))
824 else if (TREE_CODE (expr) != INTEGER_CST
825 || TREE_CONSTANT_OVERFLOW (expr))
828 uns = TYPE_UNSIGNED (TREE_TYPE (expr));
830 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
831 && TREE_INT_CST_HIGH (expr) == -1);
833 /* Note that using TYPE_PRECISION here is wrong. We care about the
834 actual bits, not the (arbitrary) range of the type. */
835 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
836 if (prec >= HOST_BITS_PER_WIDE_INT)
838 HOST_WIDE_INT high_value;
841 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
843 if (shift_amount > HOST_BITS_PER_WIDE_INT)
844 /* Can not handle precisions greater than twice the host int size. */
846 else if (shift_amount == HOST_BITS_PER_WIDE_INT)
847 /* Shifting by the host word size is undefined according to the ANSI
848 standard, so we must handle this as a special case. */
851 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
853 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
854 && TREE_INT_CST_HIGH (expr) == high_value);
857 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
860 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
864 integer_pow2p (tree expr)
867 HOST_WIDE_INT high, low;
871 if (TREE_CODE (expr) == COMPLEX_CST
872 && integer_pow2p (TREE_REALPART (expr))
873 && integer_zerop (TREE_IMAGPART (expr)))
876 if (TREE_CODE (expr) != INTEGER_CST || TREE_CONSTANT_OVERFLOW (expr))
879 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
880 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
881 high = TREE_INT_CST_HIGH (expr);
882 low = TREE_INT_CST_LOW (expr);
884 /* First clear all bits that are beyond the type's precision in case
885 we've been sign extended. */
887 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
889 else if (prec > HOST_BITS_PER_WIDE_INT)
890 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
894 if (prec < HOST_BITS_PER_WIDE_INT)
895 low &= ~((HOST_WIDE_INT) (-1) << prec);
898 if (high == 0 && low == 0)
901 return ((high == 0 && (low & (low - 1)) == 0)
902 || (low == 0 && (high & (high - 1)) == 0));
905 /* Return 1 if EXPR is an integer constant other than zero or a
906 complex constant other than zero. */
909 integer_nonzerop (tree expr)
913 return ((TREE_CODE (expr) == INTEGER_CST
914 && ! TREE_CONSTANT_OVERFLOW (expr)
915 && (TREE_INT_CST_LOW (expr) != 0
916 || TREE_INT_CST_HIGH (expr) != 0))
917 || (TREE_CODE (expr) == COMPLEX_CST
918 && (integer_nonzerop (TREE_REALPART (expr))
919 || integer_nonzerop (TREE_IMAGPART (expr)))));
922 /* Return the power of two represented by a tree node known to be a
926 tree_log2 (tree expr)
929 HOST_WIDE_INT high, low;
933 if (TREE_CODE (expr) == COMPLEX_CST)
934 return tree_log2 (TREE_REALPART (expr));
936 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
937 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
939 high = TREE_INT_CST_HIGH (expr);
940 low = TREE_INT_CST_LOW (expr);
942 /* First clear all bits that are beyond the type's precision in case
943 we've been sign extended. */
945 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
947 else if (prec > HOST_BITS_PER_WIDE_INT)
948 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
952 if (prec < HOST_BITS_PER_WIDE_INT)
953 low &= ~((HOST_WIDE_INT) (-1) << prec);
956 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
960 /* Similar, but return the largest integer Y such that 2 ** Y is less
961 than or equal to EXPR. */
964 tree_floor_log2 (tree expr)
967 HOST_WIDE_INT high, low;
971 if (TREE_CODE (expr) == COMPLEX_CST)
972 return tree_log2 (TREE_REALPART (expr));
974 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
975 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
977 high = TREE_INT_CST_HIGH (expr);
978 low = TREE_INT_CST_LOW (expr);
980 /* First clear all bits that are beyond the type's precision in case
981 we've been sign extended. Ignore if type's precision hasn't been set
982 since what we are doing is setting it. */
984 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
986 else if (prec > HOST_BITS_PER_WIDE_INT)
987 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
991 if (prec < HOST_BITS_PER_WIDE_INT)
992 low &= ~((HOST_WIDE_INT) (-1) << prec);
995 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
999 /* Return 1 if EXPR is the real constant zero. */
1002 real_zerop (tree expr)
1006 return ((TREE_CODE (expr) == REAL_CST
1007 && ! TREE_CONSTANT_OVERFLOW (expr)
1008 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
1009 || (TREE_CODE (expr) == COMPLEX_CST
1010 && real_zerop (TREE_REALPART (expr))
1011 && real_zerop (TREE_IMAGPART (expr))));
1014 /* Return 1 if EXPR is the real constant one in real or complex form. */
1017 real_onep (tree expr)
1021 return ((TREE_CODE (expr) == REAL_CST
1022 && ! TREE_CONSTANT_OVERFLOW (expr)
1023 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
1024 || (TREE_CODE (expr) == COMPLEX_CST
1025 && real_onep (TREE_REALPART (expr))
1026 && real_zerop (TREE_IMAGPART (expr))));
1029 /* Return 1 if EXPR is the real constant two. */
1032 real_twop (tree expr)
1036 return ((TREE_CODE (expr) == REAL_CST
1037 && ! TREE_CONSTANT_OVERFLOW (expr)
1038 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
1039 || (TREE_CODE (expr) == COMPLEX_CST
1040 && real_twop (TREE_REALPART (expr))
1041 && real_zerop (TREE_IMAGPART (expr))));
1044 /* Return 1 if EXPR is the real constant minus one. */
1047 real_minus_onep (tree expr)
1051 return ((TREE_CODE (expr) == REAL_CST
1052 && ! TREE_CONSTANT_OVERFLOW (expr)
1053 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1))
1054 || (TREE_CODE (expr) == COMPLEX_CST
1055 && real_minus_onep (TREE_REALPART (expr))
1056 && real_zerop (TREE_IMAGPART (expr))));
1059 /* Nonzero if EXP is a constant or a cast of a constant. */
1062 really_constant_p (tree exp)
1064 /* This is not quite the same as STRIP_NOPS. It does more. */
1065 while (TREE_CODE (exp) == NOP_EXPR
1066 || TREE_CODE (exp) == CONVERT_EXPR
1067 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1068 exp = TREE_OPERAND (exp, 0);
1069 return TREE_CONSTANT (exp);
1072 /* Return first list element whose TREE_VALUE is ELEM.
1073 Return 0 if ELEM is not in LIST. */
1076 value_member (tree elem, tree list)
1080 if (elem == TREE_VALUE (list))
1082 list = TREE_CHAIN (list);
1087 /* Return first list element whose TREE_PURPOSE is ELEM.
1088 Return 0 if ELEM is not in LIST. */
1091 purpose_member (tree elem, tree list)
1095 if (elem == TREE_PURPOSE (list))
1097 list = TREE_CHAIN (list);
1102 /* Return nonzero if ELEM is part of the chain CHAIN. */
1105 chain_member (tree elem, tree chain)
1111 chain = TREE_CHAIN (chain);
1117 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1118 We expect a null pointer to mark the end of the chain.
1119 This is the Lisp primitive `length'. */
1122 list_length (tree t)
1125 #ifdef ENABLE_TREE_CHECKING
1133 #ifdef ENABLE_TREE_CHECKING
1145 /* Returns the number of FIELD_DECLs in TYPE. */
1148 fields_length (tree type)
1150 tree t = TYPE_FIELDS (type);
1153 for (; t; t = TREE_CHAIN (t))
1154 if (TREE_CODE (t) == FIELD_DECL)
1160 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1161 by modifying the last node in chain 1 to point to chain 2.
1162 This is the Lisp primitive `nconc'. */
1165 chainon (tree op1, tree op2)
1174 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1176 TREE_CHAIN (t1) = op2;
1178 #ifdef ENABLE_TREE_CHECKING
1181 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1183 abort (); /* Circularity created. */
1190 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1193 tree_last (tree chain)
1197 while ((next = TREE_CHAIN (chain)))
1202 /* Reverse the order of elements in the chain T,
1203 and return the new head of the chain (old last element). */
1208 tree prev = 0, decl, next;
1209 for (decl = t; decl; decl = next)
1211 next = TREE_CHAIN (decl);
1212 TREE_CHAIN (decl) = prev;
1218 /* Return a newly created TREE_LIST node whose
1219 purpose and value fields are PARM and VALUE. */
1222 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
1224 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
1225 TREE_PURPOSE (t) = parm;
1226 TREE_VALUE (t) = value;
1230 /* Return a newly created TREE_LIST node whose
1231 purpose and value fields are PURPOSE and VALUE
1232 and whose TREE_CHAIN is CHAIN. */
1235 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
1239 node = ggc_alloc_zone_stat (sizeof (struct tree_list),
1240 tree_zone PASS_MEM_STAT);
1242 memset (node, 0, sizeof (struct tree_common));
1244 #ifdef GATHER_STATISTICS
1245 tree_node_counts[(int) x_kind]++;
1246 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
1249 TREE_SET_CODE (node, TREE_LIST);
1250 TREE_CHAIN (node) = chain;
1251 TREE_PURPOSE (node) = purpose;
1252 TREE_VALUE (node) = value;
1257 /* Return the size nominally occupied by an object of type TYPE
1258 when it resides in memory. The value is measured in units of bytes,
1259 and its data type is that normally used for type sizes
1260 (which is the first type created by make_signed_type or
1261 make_unsigned_type). */
1264 size_in_bytes (tree type)
1268 if (type == error_mark_node)
1269 return integer_zero_node;
1271 type = TYPE_MAIN_VARIANT (type);
1272 t = TYPE_SIZE_UNIT (type);
1276 lang_hooks.types.incomplete_type_error (NULL_TREE, type);
1277 return size_zero_node;
1280 if (TREE_CODE (t) == INTEGER_CST)
1281 t = force_fit_type (t, 0, false, false);
1286 /* Return the size of TYPE (in bytes) as a wide integer
1287 or return -1 if the size can vary or is larger than an integer. */
1290 int_size_in_bytes (tree type)
1294 if (type == error_mark_node)
1297 type = TYPE_MAIN_VARIANT (type);
1298 t = TYPE_SIZE_UNIT (type);
1300 || TREE_CODE (t) != INTEGER_CST
1301 || TREE_OVERFLOW (t)
1302 || TREE_INT_CST_HIGH (t) != 0
1303 /* If the result would appear negative, it's too big to represent. */
1304 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
1307 return TREE_INT_CST_LOW (t);
1310 /* Return the bit position of FIELD, in bits from the start of the record.
1311 This is a tree of type bitsizetype. */
1314 bit_position (tree field)
1316 return bit_from_pos (DECL_FIELD_OFFSET (field),
1317 DECL_FIELD_BIT_OFFSET (field));
1320 /* Likewise, but return as an integer. Abort if it cannot be represented
1321 in that way (since it could be a signed value, we don't have the option
1322 of returning -1 like int_size_in_byte can. */
1325 int_bit_position (tree field)
1327 return tree_low_cst (bit_position (field), 0);
1330 /* Return the byte position of FIELD, in bytes from the start of the record.
1331 This is a tree of type sizetype. */
1334 byte_position (tree field)
1336 return byte_from_pos (DECL_FIELD_OFFSET (field),
1337 DECL_FIELD_BIT_OFFSET (field));
1340 /* Likewise, but return as an integer. Abort if it cannot be represented
1341 in that way (since it could be a signed value, we don't have the option
1342 of returning -1 like int_size_in_byte can. */
1345 int_byte_position (tree field)
1347 return tree_low_cst (byte_position (field), 0);
1350 /* Return the strictest alignment, in bits, that T is known to have. */
1355 unsigned int align0, align1;
1357 switch (TREE_CODE (t))
1359 case NOP_EXPR: case CONVERT_EXPR: case NON_LVALUE_EXPR:
1360 /* If we have conversions, we know that the alignment of the
1361 object must meet each of the alignments of the types. */
1362 align0 = expr_align (TREE_OPERAND (t, 0));
1363 align1 = TYPE_ALIGN (TREE_TYPE (t));
1364 return MAX (align0, align1);
1366 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
1367 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
1368 case CLEANUP_POINT_EXPR:
1369 /* These don't change the alignment of an object. */
1370 return expr_align (TREE_OPERAND (t, 0));
1373 /* The best we can do is say that the alignment is the least aligned
1375 align0 = expr_align (TREE_OPERAND (t, 1));
1376 align1 = expr_align (TREE_OPERAND (t, 2));
1377 return MIN (align0, align1);
1379 case LABEL_DECL: case CONST_DECL:
1380 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
1381 if (DECL_ALIGN (t) != 0)
1382 return DECL_ALIGN (t);
1386 return FUNCTION_BOUNDARY;
1392 /* Otherwise take the alignment from that of the type. */
1393 return TYPE_ALIGN (TREE_TYPE (t));
1396 /* Return, as a tree node, the number of elements for TYPE (which is an
1397 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1400 array_type_nelts (tree type)
1402 tree index_type, min, max;
1404 /* If they did it with unspecified bounds, then we should have already
1405 given an error about it before we got here. */
1406 if (! TYPE_DOMAIN (type))
1407 return error_mark_node;
1409 index_type = TYPE_DOMAIN (type);
1410 min = TYPE_MIN_VALUE (index_type);
1411 max = TYPE_MAX_VALUE (index_type);
1413 return (integer_zerop (min)
1415 : fold (build2 (MINUS_EXPR, TREE_TYPE (max), max, min)));
1418 /* If arg is static -- a reference to an object in static storage -- then
1419 return the object. This is not the same as the C meaning of `static'.
1420 If arg isn't static, return NULL. */
1425 switch (TREE_CODE (arg))
1428 /* Nested functions aren't static, since taking their address
1429 involves a trampoline. */
1430 return ((decl_function_context (arg) == 0 || DECL_NO_STATIC_CHAIN (arg))
1431 && ! DECL_NON_ADDR_CONST_P (arg)
1435 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
1436 && ! DECL_THREAD_LOCAL (arg)
1437 && ! DECL_NON_ADDR_CONST_P (arg)
1441 return TREE_STATIC (arg) ? arg : NULL;
1448 /* If the thing being referenced is not a field, then it is
1449 something language specific. */
1450 if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL)
1451 return (*lang_hooks.staticp) (arg);
1453 /* If we are referencing a bitfield, we can't evaluate an
1454 ADDR_EXPR at compile time and so it isn't a constant. */
1455 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
1458 return staticp (TREE_OPERAND (arg, 0));
1464 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
1467 case ARRAY_RANGE_REF:
1468 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
1469 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
1470 return staticp (TREE_OPERAND (arg, 0));
1475 if ((unsigned int) TREE_CODE (arg)
1476 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
1477 return lang_hooks.staticp (arg);
1483 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
1484 Do this to any expression which may be used in more than one place,
1485 but must be evaluated only once.
1487 Normally, expand_expr would reevaluate the expression each time.
1488 Calling save_expr produces something that is evaluated and recorded
1489 the first time expand_expr is called on it. Subsequent calls to
1490 expand_expr just reuse the recorded value.
1492 The call to expand_expr that generates code that actually computes
1493 the value is the first call *at compile time*. Subsequent calls
1494 *at compile time* generate code to use the saved value.
1495 This produces correct result provided that *at run time* control
1496 always flows through the insns made by the first expand_expr
1497 before reaching the other places where the save_expr was evaluated.
1498 You, the caller of save_expr, must make sure this is so.
1500 Constants, and certain read-only nodes, are returned with no
1501 SAVE_EXPR because that is safe. Expressions containing placeholders
1502 are not touched; see tree.def for an explanation of what these
1506 save_expr (tree expr)
1508 tree t = fold (expr);
1511 /* If the tree evaluates to a constant, then we don't want to hide that
1512 fact (i.e. this allows further folding, and direct checks for constants).
1513 However, a read-only object that has side effects cannot be bypassed.
1514 Since it is no problem to reevaluate literals, we just return the
1516 inner = skip_simple_arithmetic (t);
1518 if (TREE_INVARIANT (inner)
1519 || (TREE_READONLY (inner) && ! TREE_SIDE_EFFECTS (inner))
1520 || TREE_CODE (inner) == SAVE_EXPR
1521 || TREE_CODE (inner) == ERROR_MARK)
1524 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
1525 it means that the size or offset of some field of an object depends on
1526 the value within another field.
1528 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
1529 and some variable since it would then need to be both evaluated once and
1530 evaluated more than once. Front-ends must assure this case cannot
1531 happen by surrounding any such subexpressions in their own SAVE_EXPR
1532 and forcing evaluation at the proper time. */
1533 if (contains_placeholder_p (inner))
1536 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
1538 /* This expression might be placed ahead of a jump to ensure that the
1539 value was computed on both sides of the jump. So make sure it isn't
1540 eliminated as dead. */
1541 TREE_SIDE_EFFECTS (t) = 1;
1542 TREE_INVARIANT (t) = 1;
1546 /* Look inside EXPR and into any simple arithmetic operations. Return
1547 the innermost non-arithmetic node. */
1550 skip_simple_arithmetic (tree expr)
1554 /* We don't care about whether this can be used as an lvalue in this
1556 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
1557 expr = TREE_OPERAND (expr, 0);
1559 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
1560 a constant, it will be more efficient to not make another SAVE_EXPR since
1561 it will allow better simplification and GCSE will be able to merge the
1562 computations if they actually occur. */
1566 if (TREE_CODE_CLASS (TREE_CODE (inner)) == '1')
1567 inner = TREE_OPERAND (inner, 0);
1568 else if (TREE_CODE_CLASS (TREE_CODE (inner)) == '2')
1570 if (TREE_INVARIANT (TREE_OPERAND (inner, 1)))
1571 inner = TREE_OPERAND (inner, 0);
1572 else if (TREE_INVARIANT (TREE_OPERAND (inner, 0)))
1573 inner = TREE_OPERAND (inner, 1);
1584 /* Returns the index of the first non-tree operand for CODE, or the number
1585 of operands if all are trees. */
1588 first_rtl_op (enum tree_code code)
1593 return TREE_CODE_LENGTH (code);
1597 /* Return which tree structure is used by T. */
1599 enum tree_node_structure_enum
1600 tree_node_structure (tree t)
1602 enum tree_code code = TREE_CODE (t);
1604 switch (TREE_CODE_CLASS (code))
1606 case 'd': return TS_DECL;
1607 case 't': return TS_TYPE;
1608 case 'r': case '<': case '1': case '2': case 'e': case 's':
1610 default: /* 'c' and 'x' */
1616 case INTEGER_CST: return TS_INT_CST;
1617 case REAL_CST: return TS_REAL_CST;
1618 case COMPLEX_CST: return TS_COMPLEX;
1619 case VECTOR_CST: return TS_VECTOR;
1620 case STRING_CST: return TS_STRING;
1622 case ERROR_MARK: return TS_COMMON;
1623 case IDENTIFIER_NODE: return TS_IDENTIFIER;
1624 case TREE_LIST: return TS_LIST;
1625 case TREE_VEC: return TS_VEC;
1626 case PHI_NODE: return TS_PHI_NODE;
1627 case SSA_NAME: return TS_SSA_NAME;
1628 case PLACEHOLDER_EXPR: return TS_COMMON;
1629 case STATEMENT_LIST: return TS_STATEMENT_LIST;
1630 case BLOCK: return TS_BLOCK;
1631 case TREE_BINFO: return TS_BINFO;
1632 case VALUE_HANDLE: return TS_VALUE_HANDLE;
1639 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
1640 or offset that depends on a field within a record. */
1643 contains_placeholder_p (tree exp)
1645 enum tree_code code;
1650 code = TREE_CODE (exp);
1651 if (code == PLACEHOLDER_EXPR)
1654 switch (TREE_CODE_CLASS (code))
1657 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
1658 position computations since they will be converted into a
1659 WITH_RECORD_EXPR involving the reference, which will assume
1660 here will be valid. */
1661 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
1664 if (code == TREE_LIST)
1665 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
1666 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
1675 /* Ignoring the first operand isn't quite right, but works best. */
1676 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
1679 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
1680 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
1681 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
1687 switch (first_rtl_op (code))
1690 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
1692 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
1693 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
1704 /* Return 1 if any part of the computation of TYPE involves a PLACEHOLDER_EXPR.
1705 This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and field
1709 type_contains_placeholder_p (tree type)
1711 /* If the size contains a placeholder or the parent type (component type in
1712 the case of arrays) type involves a placeholder, this type does. */
1713 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
1714 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
1715 || (TREE_TYPE (type) != 0
1716 && type_contains_placeholder_p (TREE_TYPE (type))))
1719 /* Now do type-specific checks. Note that the last part of the check above
1720 greatly limits what we have to do below. */
1721 switch (TREE_CODE (type))
1730 case REFERENCE_TYPE:
1738 /* Here we just check the bounds. */
1739 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
1740 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
1745 /* We're already checked the component type (TREE_TYPE), so just check
1747 return type_contains_placeholder_p (TYPE_DOMAIN (type));
1751 case QUAL_UNION_TYPE:
1753 static tree seen_types = 0;
1757 /* We have to be careful here that we don't end up in infinite
1758 recursions due to a field of a type being a pointer to that type
1759 or to a mutually-recursive type. So we store a list of record
1760 types that we've seen and see if this type is in them. To save
1761 memory, we don't use a list for just one type. Here we check
1762 whether we've seen this type before and store it if not. */
1763 if (seen_types == 0)
1765 else if (TREE_CODE (seen_types) != TREE_LIST)
1767 if (seen_types == type)
1770 seen_types = tree_cons (NULL_TREE, type,
1771 build_tree_list (NULL_TREE, seen_types));
1775 if (value_member (type, seen_types) != 0)
1778 seen_types = tree_cons (NULL_TREE, type, seen_types);
1781 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1782 if (TREE_CODE (field) == FIELD_DECL
1783 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
1784 || (TREE_CODE (type) == QUAL_UNION_TYPE
1785 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
1786 || type_contains_placeholder_p (TREE_TYPE (field))))
1792 /* Now remove us from seen_types and return the result. */
1793 if (seen_types == type)
1796 seen_types = TREE_CHAIN (seen_types);
1806 /* Return 1 if EXP contains any expressions that produce cleanups for an
1807 outer scope to deal with. Used by fold. */
1810 has_cleanups (tree exp)
1814 if (! TREE_SIDE_EFFECTS (exp))
1817 switch (TREE_CODE (exp))
1820 case WITH_CLEANUP_EXPR:
1823 case CLEANUP_POINT_EXPR:
1827 for (exp = TREE_OPERAND (exp, 1); exp; exp = TREE_CHAIN (exp))
1829 cmp = has_cleanups (TREE_VALUE (exp));
1836 return (DECL_INITIAL (DECL_EXPR_DECL (exp))
1837 && has_cleanups (DECL_INITIAL (DECL_EXPR_DECL (exp))));
1843 /* This general rule works for most tree codes. All exceptions should be
1844 handled above. If this is a language-specific tree code, we can't
1845 trust what might be in the operand, so say we don't know
1847 if ((int) TREE_CODE (exp) >= (int) LAST_AND_UNUSED_TREE_CODE)
1850 nops = first_rtl_op (TREE_CODE (exp));
1851 for (i = 0; i < nops; i++)
1852 if (TREE_OPERAND (exp, i) != 0)
1854 int type = TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, i)));
1855 if (type == 'e' || type == '<' || type == '1' || type == '2'
1856 || type == 'r' || type == 's')
1858 cmp = has_cleanups (TREE_OPERAND (exp, i));
1867 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
1868 return a tree with all occurrences of references to F in a
1869 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
1870 contains only arithmetic expressions or a CALL_EXPR with a
1871 PLACEHOLDER_EXPR occurring only in its arglist. */
1874 substitute_in_expr (tree exp, tree f, tree r)
1876 enum tree_code code = TREE_CODE (exp);
1881 /* We handle TREE_LIST and COMPONENT_REF separately. */
1882 if (code == TREE_LIST)
1884 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
1885 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
1886 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
1889 return tree_cons (TREE_PURPOSE (exp), op1, op0);
1891 else if (code == COMPONENT_REF)
1893 /* If this expression is getting a value from a PLACEHOLDER_EXPR
1894 and it is the right field, replace it with R. */
1895 for (inner = TREE_OPERAND (exp, 0);
1896 TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
1897 inner = TREE_OPERAND (inner, 0))
1899 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
1900 && TREE_OPERAND (exp, 1) == f)
1903 /* If this expression hasn't been completed let, leave it alone. */
1904 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0)
1907 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
1908 if (op0 == TREE_OPERAND (exp, 0))
1911 new = fold (build3 (COMPONENT_REF, TREE_TYPE (exp),
1912 op0, TREE_OPERAND (exp, 1), NULL_TREE));
1915 switch (TREE_CODE_CLASS (code))
1927 switch (first_rtl_op (code))
1933 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
1934 if (op0 == TREE_OPERAND (exp, 0))
1937 new = fold (build1 (code, TREE_TYPE (exp), op0));
1941 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
1942 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
1944 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
1947 new = fold (build2 (code, TREE_TYPE (exp), op0, op1));
1951 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
1952 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
1953 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
1955 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
1956 && op2 == TREE_OPERAND (exp, 2))
1959 new = fold (build3 (code, TREE_TYPE (exp), op0, op1, op2));
1971 TREE_READONLY (new) = TREE_READONLY (exp);
1975 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
1976 for it within OBJ, a tree that is an object or a chain of references. */
1979 substitute_placeholder_in_expr (tree exp, tree obj)
1981 enum tree_code code = TREE_CODE (exp);
1982 tree op0, op1, op2, op3;
1984 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
1985 in the chain of OBJ. */
1986 if (code == PLACEHOLDER_EXPR)
1988 tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
1991 for (elt = obj; elt != 0;
1992 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
1993 || TREE_CODE (elt) == COND_EXPR)
1994 ? TREE_OPERAND (elt, 1)
1995 : (TREE_CODE_CLASS (TREE_CODE (elt)) == 'r'
1996 || TREE_CODE_CLASS (TREE_CODE (elt)) == '1'
1997 || TREE_CODE_CLASS (TREE_CODE (elt)) == '2'
1998 || TREE_CODE_CLASS (TREE_CODE (elt)) == 'e')
1999 ? TREE_OPERAND (elt, 0) : 0))
2000 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
2003 for (elt = obj; elt != 0;
2004 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
2005 || TREE_CODE (elt) == COND_EXPR)
2006 ? TREE_OPERAND (elt, 1)
2007 : (TREE_CODE_CLASS (TREE_CODE (elt)) == 'r'
2008 || TREE_CODE_CLASS (TREE_CODE (elt)) == '1'
2009 || TREE_CODE_CLASS (TREE_CODE (elt)) == '2'
2010 || TREE_CODE_CLASS (TREE_CODE (elt)) == 'e')
2011 ? TREE_OPERAND (elt, 0) : 0))
2012 if (POINTER_TYPE_P (TREE_TYPE (elt))
2013 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
2015 return fold (build1 (INDIRECT_REF, need_type, elt));
2017 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2018 survives until RTL generation, there will be an error. */
2022 /* TREE_LIST is special because we need to look at TREE_VALUE
2023 and TREE_CHAIN, not TREE_OPERANDS. */
2024 else if (code == TREE_LIST)
2026 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
2027 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
2028 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2031 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2034 switch (TREE_CODE_CLASS (code))
2047 switch (first_rtl_op (code))
2053 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2054 if (op0 == TREE_OPERAND (exp, 0))
2057 return fold (build1 (code, TREE_TYPE (exp), op0));
2060 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2061 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2063 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2066 return fold (build2 (code, TREE_TYPE (exp), op0, op1));
2069 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2070 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2071 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2073 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2074 && op2 == TREE_OPERAND (exp, 2))
2077 return fold (build3 (code, TREE_TYPE (exp), op0, op1, op2));
2080 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2081 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2082 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2083 op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
2085 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2086 && op2 == TREE_OPERAND (exp, 2)
2087 && op3 == TREE_OPERAND (exp, 3))
2090 return fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2102 /* Stabilize a reference so that we can use it any number of times
2103 without causing its operands to be evaluated more than once.
2104 Returns the stabilized reference. This works by means of save_expr,
2105 so see the caveats in the comments about save_expr.
2107 Also allows conversion expressions whose operands are references.
2108 Any other kind of expression is returned unchanged. */
2111 stabilize_reference (tree ref)
2114 enum tree_code code = TREE_CODE (ref);
2121 /* No action is needed in this case. */
2127 case FIX_TRUNC_EXPR:
2128 case FIX_FLOOR_EXPR:
2129 case FIX_ROUND_EXPR:
2131 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2135 result = build_nt (INDIRECT_REF,
2136 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2140 result = build_nt (COMPONENT_REF,
2141 stabilize_reference (TREE_OPERAND (ref, 0)),
2142 TREE_OPERAND (ref, 1), NULL_TREE);
2146 result = build_nt (BIT_FIELD_REF,
2147 stabilize_reference (TREE_OPERAND (ref, 0)),
2148 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2149 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2153 result = build_nt (ARRAY_REF,
2154 stabilize_reference (TREE_OPERAND (ref, 0)),
2155 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2156 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2159 case ARRAY_RANGE_REF:
2160 result = build_nt (ARRAY_RANGE_REF,
2161 stabilize_reference (TREE_OPERAND (ref, 0)),
2162 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2163 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2167 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2168 it wouldn't be ignored. This matters when dealing with
2170 return stabilize_reference_1 (ref);
2172 /* If arg isn't a kind of lvalue we recognize, make no change.
2173 Caller should recognize the error for an invalid lvalue. */
2178 return error_mark_node;
2181 TREE_TYPE (result) = TREE_TYPE (ref);
2182 TREE_READONLY (result) = TREE_READONLY (ref);
2183 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2184 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2189 /* Subroutine of stabilize_reference; this is called for subtrees of
2190 references. Any expression with side-effects must be put in a SAVE_EXPR
2191 to ensure that it is only evaluated once.
2193 We don't put SAVE_EXPR nodes around everything, because assigning very
2194 simple expressions to temporaries causes us to miss good opportunities
2195 for optimizations. Among other things, the opportunity to fold in the
2196 addition of a constant into an addressing mode often gets lost, e.g.
2197 "y[i+1] += x;". In general, we take the approach that we should not make
2198 an assignment unless we are forced into it - i.e., that any non-side effect
2199 operator should be allowed, and that cse should take care of coalescing
2200 multiple utterances of the same expression should that prove fruitful. */
2203 stabilize_reference_1 (tree e)
2206 enum tree_code code = TREE_CODE (e);
2208 /* We cannot ignore const expressions because it might be a reference
2209 to a const array but whose index contains side-effects. But we can
2210 ignore things that are actual constant or that already have been
2211 handled by this function. */
2213 if (TREE_INVARIANT (e))
2216 switch (TREE_CODE_CLASS (code))
2225 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2226 so that it will only be evaluated once. */
2227 /* The reference (r) and comparison (<) classes could be handled as
2228 below, but it is generally faster to only evaluate them once. */
2229 if (TREE_SIDE_EFFECTS (e))
2230 return save_expr (e);
2234 /* Constants need no processing. In fact, we should never reach
2239 /* Division is slow and tends to be compiled with jumps,
2240 especially the division by powers of 2 that is often
2241 found inside of an array reference. So do it just once. */
2242 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
2243 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
2244 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
2245 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
2246 return save_expr (e);
2247 /* Recursively stabilize each operand. */
2248 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
2249 stabilize_reference_1 (TREE_OPERAND (e, 1)));
2253 /* Recursively stabilize each operand. */
2254 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
2261 TREE_TYPE (result) = TREE_TYPE (e);
2262 TREE_READONLY (result) = TREE_READONLY (e);
2263 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
2264 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
2265 TREE_INVARIANT (result) = 1;
2270 /* Low-level constructors for expressions. */
2272 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
2273 TREE_INVARIANT, and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
2276 recompute_tree_invarant_for_addr_expr (tree t)
2279 bool tc = true, ti = true, se = false;
2281 /* We started out assuming this address is both invariant and constant, but
2282 does not have side effects. Now go down any handled components and see if
2283 any of them involve offsets that are either non-constant or non-invariant.
2284 Also check for side-effects.
2286 ??? Note that this code makes no attempt to deal with the case where
2287 taking the address of something causes a copy due to misalignment. */
2289 #define UPDATE_TITCSE(NODE) \
2290 do { tree _node = (NODE); \
2291 if (_node && !TREE_INVARIANT (_node)) ti = false; \
2292 if (_node && !TREE_CONSTANT (_node)) tc = false; \
2293 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
2295 for (node = TREE_OPERAND (t, 0); handled_component_p (node);
2296 node = TREE_OPERAND (node, 0))
2298 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
2299 array reference (probably made temporarily by the G++ front end),
2300 so ignore all the operands. */
2301 if ((TREE_CODE (node) == ARRAY_REF
2302 || TREE_CODE (node) == ARRAY_RANGE_REF)
2303 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
2305 UPDATE_TITCSE (TREE_OPERAND (node, 1));
2306 if (TREE_OPERAND (node, 2))
2307 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2308 if (TREE_OPERAND (node, 3))
2309 UPDATE_TITCSE (TREE_OPERAND (node, 3));
2311 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
2312 FIELD_DECL, apparently. The G++ front end can put something else
2313 there, at least temporarily. */
2314 else if (TREE_CODE (node) == COMPONENT_REF
2315 && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
2317 if (TREE_OPERAND (node, 2))
2318 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2320 else if (TREE_CODE (node) == BIT_FIELD_REF)
2321 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2324 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
2325 it. If it's a decl, it's invariant and constant if the decl is static.
2326 It's also invariant if it's a decl in the current function. (Taking the
2327 address of a volatile variable is not volatile.) If it's a constant,
2328 the address is both invariant and constant. Otherwise it's neither. */
2329 if (TREE_CODE (node) == INDIRECT_REF)
2331 /* If this is &((T*)0)->field, then this is a form of addition. */
2332 if (TREE_CODE (TREE_OPERAND (node, 0)) != INTEGER_CST)
2333 UPDATE_TITCSE (node);
2335 else if (DECL_P (node))
2339 else if (decl_function_context (node) == current_function_decl)
2344 else if (TREE_CODE_CLASS (TREE_CODE (node)) == 'c')
2349 se |= TREE_SIDE_EFFECTS (node);
2352 TREE_CONSTANT (t) = tc;
2353 TREE_INVARIANT (t) = ti;
2354 TREE_SIDE_EFFECTS (t) = se;
2355 #undef UPDATE_TITCSE
2358 /* Build an expression of code CODE, data type TYPE, and operands as
2359 specified. Expressions and reference nodes can be created this way.
2360 Constants, decls, types and misc nodes cannot be.
2362 We define 5 non-variadic functions, from 0 to 4 arguments. This is
2363 enough for all extant tree codes. These functions can be called
2364 directly (preferably!), but can also be obtained via GCC preprocessor
2365 magic within the build macro. */
2368 build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
2372 #ifdef ENABLE_CHECKING
2373 if (TREE_CODE_LENGTH (code) != 0)
2377 t = make_node_stat (code PASS_MEM_STAT);
2384 build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL)
2386 int length = sizeof (struct tree_exp);
2387 #ifdef GATHER_STATISTICS
2388 tree_node_kind kind;
2392 #ifdef GATHER_STATISTICS
2393 switch (TREE_CODE_CLASS (code))
2395 case 's': /* an expression with side effects */
2398 case 'r': /* a reference */
2406 tree_node_counts[(int) kind]++;
2407 tree_node_sizes[(int) kind] += length;
2410 #ifdef ENABLE_CHECKING
2411 if (TREE_CODE_LENGTH (code) != 1)
2413 #endif /* ENABLE_CHECKING */
2415 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
2417 memset (t, 0, sizeof (struct tree_common));
2419 TREE_SET_CODE (t, code);
2421 TREE_TYPE (t) = type;
2422 #ifdef USE_MAPPED_LOCATION
2423 SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
2425 SET_EXPR_LOCUS (t, NULL);
2427 TREE_COMPLEXITY (t) = 0;
2428 TREE_OPERAND (t, 0) = node;
2429 TREE_BLOCK (t) = NULL_TREE;
2430 if (node && !TYPE_P (node) && first_rtl_op (code) != 0)
2432 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
2433 TREE_READONLY (t) = TREE_READONLY (node);
2436 if (TREE_CODE_CLASS (code) == 's')
2437 TREE_SIDE_EFFECTS (t) = 1;
2443 case PREDECREMENT_EXPR:
2444 case PREINCREMENT_EXPR:
2445 case POSTDECREMENT_EXPR:
2446 case POSTINCREMENT_EXPR:
2447 /* All of these have side-effects, no matter what their
2449 TREE_SIDE_EFFECTS (t) = 1;
2450 TREE_READONLY (t) = 0;
2454 /* Whether a dereference is readonly has nothing to do with whether
2455 its operand is readonly. */
2456 TREE_READONLY (t) = 0;
2461 recompute_tree_invarant_for_addr_expr (t);
2465 if (TREE_CODE_CLASS (code) == '1' && node && !TYPE_P (node)
2466 && TREE_CONSTANT (node))
2467 TREE_CONSTANT (t) = 1;
2468 if (TREE_CODE_CLASS (code) == '1' && node && TREE_INVARIANT (node))
2469 TREE_INVARIANT (t) = 1;
2470 if (TREE_CODE_CLASS (code) == 'r' && node && TREE_THIS_VOLATILE (node))
2471 TREE_THIS_VOLATILE (t) = 1;
2478 #define PROCESS_ARG(N) \
2480 TREE_OPERAND (t, N) = arg##N; \
2481 if (arg##N &&!TYPE_P (arg##N) && fro > N) \
2483 if (TREE_SIDE_EFFECTS (arg##N)) \
2485 if (!TREE_READONLY (arg##N)) \
2487 if (!TREE_CONSTANT (arg##N)) \
2489 if (!TREE_INVARIANT (arg##N)) \
2495 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
2497 bool constant, read_only, side_effects, invariant;
2501 #ifdef ENABLE_CHECKING
2502 if (TREE_CODE_LENGTH (code) != 2)
2506 t = make_node_stat (code PASS_MEM_STAT);
2509 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
2510 result based on those same flags for the arguments. But if the
2511 arguments aren't really even `tree' expressions, we shouldn't be trying
2513 fro = first_rtl_op (code);
2515 /* Expressions without side effects may be constant if their
2516 arguments are as well. */
2517 constant = (TREE_CODE_CLASS (code) == '<'
2518 || TREE_CODE_CLASS (code) == '2');
2520 side_effects = TREE_SIDE_EFFECTS (t);
2521 invariant = constant;
2526 TREE_READONLY (t) = read_only;
2527 TREE_CONSTANT (t) = constant;
2528 TREE_INVARIANT (t) = invariant;
2529 TREE_SIDE_EFFECTS (t) = side_effects;
2530 TREE_THIS_VOLATILE (t)
2531 = TREE_CODE_CLASS (code) == 'r' && arg0 && TREE_THIS_VOLATILE (arg0);
2537 build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
2538 tree arg2 MEM_STAT_DECL)
2540 bool constant, read_only, side_effects, invariant;
2544 #ifdef ENABLE_CHECKING
2545 if (TREE_CODE_LENGTH (code) != 3)
2549 t = make_node_stat (code PASS_MEM_STAT);
2552 fro = first_rtl_op (code);
2554 side_effects = TREE_SIDE_EFFECTS (t);
2560 if (code == CALL_EXPR && !side_effects)
2565 /* Calls have side-effects, except those to const or
2567 i = call_expr_flags (t);
2568 if (!(i & (ECF_CONST | ECF_PURE)))
2571 /* And even those have side-effects if their arguments do. */
2572 else for (node = arg1; node; node = TREE_CHAIN (node))
2573 if (TREE_SIDE_EFFECTS (TREE_VALUE (node)))
2580 TREE_SIDE_EFFECTS (t) = side_effects;
2581 TREE_THIS_VOLATILE (t)
2582 = TREE_CODE_CLASS (code) == 'r' && arg0 && TREE_THIS_VOLATILE (arg0);
2588 build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
2589 tree arg2, tree arg3 MEM_STAT_DECL)
2591 bool constant, read_only, side_effects, invariant;
2595 #ifdef ENABLE_CHECKING
2596 if (TREE_CODE_LENGTH (code) != 4)
2600 t = make_node_stat (code PASS_MEM_STAT);
2603 fro = first_rtl_op (code);
2605 side_effects = TREE_SIDE_EFFECTS (t);
2612 TREE_SIDE_EFFECTS (t) = side_effects;
2613 TREE_THIS_VOLATILE (t)
2614 = TREE_CODE_CLASS (code) == 'r' && arg0 && TREE_THIS_VOLATILE (arg0);
2619 /* Backup definition for non-gcc build compilers. */
2622 (build) (enum tree_code code, tree tt, ...)
2624 tree t, arg0, arg1, arg2, arg3;
2625 int length = TREE_CODE_LENGTH (code);
2632 t = build0 (code, tt);
2635 arg0 = va_arg (p, tree);
2636 t = build1 (code, tt, arg0);
2639 arg0 = va_arg (p, tree);
2640 arg1 = va_arg (p, tree);
2641 t = build2 (code, tt, arg0, arg1);
2644 arg0 = va_arg (p, tree);
2645 arg1 = va_arg (p, tree);
2646 arg2 = va_arg (p, tree);
2647 t = build3 (code, tt, arg0, arg1, arg2);
2650 arg0 = va_arg (p, tree);
2651 arg1 = va_arg (p, tree);
2652 arg2 = va_arg (p, tree);
2653 arg3 = va_arg (p, tree);
2654 t = build4 (code, tt, arg0, arg1, arg2, arg3);
2664 /* Similar except don't specify the TREE_TYPE
2665 and leave the TREE_SIDE_EFFECTS as 0.
2666 It is permissible for arguments to be null,
2667 or even garbage if their values do not matter. */
2670 build_nt (enum tree_code code, ...)
2679 t = make_node (code);
2680 length = TREE_CODE_LENGTH (code);
2682 for (i = 0; i < length; i++)
2683 TREE_OPERAND (t, i) = va_arg (p, tree);
2689 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2690 We do NOT enter this node in any sort of symbol table.
2692 layout_decl is used to set up the decl's storage layout.
2693 Other slots are initialized to 0 or null pointers. */
2696 build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL)
2700 t = make_node_stat (code PASS_MEM_STAT);
2702 /* if (type == error_mark_node)
2703 type = integer_type_node; */
2704 /* That is not done, deliberately, so that having error_mark_node
2705 as the type can suppress useless errors in the use of this variable. */
2707 DECL_NAME (t) = name;
2708 TREE_TYPE (t) = type;
2710 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
2712 else if (code == FUNCTION_DECL)
2713 DECL_MODE (t) = FUNCTION_MODE;
2715 /* Set default visibility to whatever the user supplied with
2716 visibility_specified depending on #pragma GCC visibility. */
2717 DECL_VISIBILITY (t) = default_visibility;
2718 DECL_VISIBILITY_SPECIFIED (t) = visibility_options.inpragma;
2723 /* BLOCK nodes are used to represent the structure of binding contours
2724 and declarations, once those contours have been exited and their contents
2725 compiled. This information is used for outputting debugging info. */
2728 build_block (tree vars, tree tags ATTRIBUTE_UNUSED, tree subblocks,
2729 tree supercontext, tree chain)
2731 tree block = make_node (BLOCK);
2733 BLOCK_VARS (block) = vars;
2734 BLOCK_SUBBLOCKS (block) = subblocks;
2735 BLOCK_SUPERCONTEXT (block) = supercontext;
2736 BLOCK_CHAIN (block) = chain;
2740 #if 1 /* ! defined(USE_MAPPED_LOCATION) */
2741 /* ??? gengtype doesn't handle conditionals */
2742 static GTY(()) tree last_annotated_node;
2745 #ifdef USE_MAPPED_LOCATION
2748 expand_location (source_location loc)
2750 expanded_location xloc;
2751 if (loc == 0) { xloc.file = NULL; xloc.line = 0; xloc.column = 0; }
2754 const struct line_map *map = linemap_lookup (&line_table, loc);
2755 xloc.file = map->to_file;
2756 xloc.line = SOURCE_LINE (map, loc);
2757 xloc.column = SOURCE_COLUMN (map, loc);
2764 /* Record the exact location where an expression or an identifier were
2768 annotate_with_file_line (tree node, const char *file, int line)
2770 /* Roughly one percent of the calls to this function are to annotate
2771 a node with the same information already attached to that node!
2772 Just return instead of wasting memory. */
2773 if (EXPR_LOCUS (node)
2774 && (EXPR_FILENAME (node) == file
2775 || ! strcmp (EXPR_FILENAME (node), file))
2776 && EXPR_LINENO (node) == line)
2778 last_annotated_node = node;
2782 /* In heavily macroized code (such as GCC itself) this single
2783 entry cache can reduce the number of allocations by more
2785 if (last_annotated_node
2786 && EXPR_LOCUS (last_annotated_node)
2787 && (EXPR_FILENAME (last_annotated_node) == file
2788 || ! strcmp (EXPR_FILENAME (last_annotated_node), file))
2789 && EXPR_LINENO (last_annotated_node) == line)
2791 SET_EXPR_LOCUS (node, EXPR_LOCUS (last_annotated_node));
2795 SET_EXPR_LOCUS (node, ggc_alloc (sizeof (location_t)));
2796 EXPR_LINENO (node) = line;
2797 EXPR_FILENAME (node) = file;
2798 last_annotated_node = node;
2802 annotate_with_locus (tree node, location_t locus)
2804 annotate_with_file_line (node, locus.file, locus.line);
2808 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
2812 build_decl_attribute_variant (tree ddecl, tree attribute)
2814 DECL_ATTRIBUTES (ddecl) = attribute;
2818 /* Borrowed from hashtab.c iterative_hash implementation. */
2819 #define mix(a,b,c) \
2821 a -= b; a -= c; a ^= (c>>13); \
2822 b -= c; b -= a; b ^= (a<< 8); \
2823 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
2824 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
2825 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
2826 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
2827 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
2828 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
2829 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
2833 /* Produce good hash value combining VAL and VAL2. */
2834 static inline hashval_t
2835 iterative_hash_hashval_t (hashval_t val, hashval_t val2)
2837 /* the golden ratio; an arbitrary value. */
2838 hashval_t a = 0x9e3779b9;
2844 /* Produce good hash value combining PTR and VAL2. */
2845 static inline hashval_t
2846 iterative_hash_pointer (void *ptr, hashval_t val2)
2848 if (sizeof (ptr) == sizeof (hashval_t))
2849 return iterative_hash_hashval_t ((size_t) ptr, val2);
2852 hashval_t a = (hashval_t) (size_t) ptr;
2853 /* Avoid warnings about shifting of more than the width of the type on
2854 hosts that won't execute this path. */
2856 hashval_t b = (hashval_t) ((size_t) ptr >> (sizeof (hashval_t) * 8 + zero));
2862 /* Produce good hash value combining VAL and VAL2. */
2863 static inline hashval_t
2864 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2)
2866 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t))
2867 return iterative_hash_hashval_t (val, val2);
2870 hashval_t a = (hashval_t) val;
2871 /* Avoid warnings about shifting of more than the width of the type on
2872 hosts that won't execute this path. */
2874 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 8 + zero));
2876 if (sizeof (HOST_WIDE_INT) > 2 * sizeof (hashval_t))
2878 hashval_t a = (hashval_t) (val >> (sizeof (hashval_t) * 16 + zero));
2879 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 24 + zero));
2886 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
2889 Record such modified types already made so we don't make duplicates. */
2892 build_type_attribute_variant (tree ttype, tree attribute)
2894 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
2896 hashval_t hashcode = 0;
2898 enum tree_code code = TREE_CODE (ttype);
2900 ntype = copy_node (ttype);
2902 TYPE_POINTER_TO (ntype) = 0;
2903 TYPE_REFERENCE_TO (ntype) = 0;
2904 TYPE_ATTRIBUTES (ntype) = attribute;
2906 /* Create a new main variant of TYPE. */
2907 TYPE_MAIN_VARIANT (ntype) = ntype;
2908 TYPE_NEXT_VARIANT (ntype) = 0;
2909 set_type_quals (ntype, TYPE_UNQUALIFIED);
2911 hashcode = iterative_hash_object (code, hashcode);
2912 if (TREE_TYPE (ntype))
2913 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)),
2915 hashcode = attribute_hash_list (attribute, hashcode);
2917 switch (TREE_CODE (ntype))
2920 hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode);
2923 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)),
2927 hashcode = iterative_hash_object
2928 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode);
2929 hashcode = iterative_hash_object
2930 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode);
2934 unsigned int precision = TYPE_PRECISION (ntype);
2935 hashcode = iterative_hash_object (precision, hashcode);
2942 ntype = type_hash_canon (hashcode, ntype);
2943 ttype = build_qualified_type (ntype, TYPE_QUALS (ttype));
2949 /* Return nonzero if IDENT is a valid name for attribute ATTR,
2952 We try both `text' and `__text__', ATTR may be either one. */
2953 /* ??? It might be a reasonable simplification to require ATTR to be only
2954 `text'. One might then also require attribute lists to be stored in
2955 their canonicalized form. */
2958 is_attribute_p (const char *attr, tree ident)
2960 int ident_len, attr_len;
2963 if (TREE_CODE (ident) != IDENTIFIER_NODE)
2966 if (strcmp (attr, IDENTIFIER_POINTER (ident)) == 0)
2969 p = IDENTIFIER_POINTER (ident);
2970 ident_len = strlen (p);
2971 attr_len = strlen (attr);
2973 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
2977 || attr[attr_len - 2] != '_'
2978 || attr[attr_len - 1] != '_')
2980 if (ident_len == attr_len - 4
2981 && strncmp (attr + 2, p, attr_len - 4) == 0)
2986 if (ident_len == attr_len + 4
2987 && p[0] == '_' && p[1] == '_'
2988 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
2989 && strncmp (attr, p + 2, attr_len) == 0)
2996 /* Given an attribute name and a list of attributes, return a pointer to the
2997 attribute's list element if the attribute is part of the list, or NULL_TREE
2998 if not found. If the attribute appears more than once, this only
2999 returns the first occurrence; the TREE_CHAIN of the return value should
3000 be passed back in if further occurrences are wanted. */
3003 lookup_attribute (const char *attr_name, tree list)
3007 for (l = list; l; l = TREE_CHAIN (l))
3009 if (TREE_CODE (TREE_PURPOSE (l)) != IDENTIFIER_NODE)
3011 if (is_attribute_p (attr_name, TREE_PURPOSE (l)))
3018 /* Return an attribute list that is the union of a1 and a2. */
3021 merge_attributes (tree a1, tree a2)
3025 /* Either one unset? Take the set one. */
3027 if ((attributes = a1) == 0)
3030 /* One that completely contains the other? Take it. */
3032 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
3034 if (attribute_list_contained (a2, a1))
3038 /* Pick the longest list, and hang on the other list. */
3040 if (list_length (a1) < list_length (a2))
3041 attributes = a2, a2 = a1;
3043 for (; a2 != 0; a2 = TREE_CHAIN (a2))
3046 for (a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3049 a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3052 if (simple_cst_equal (TREE_VALUE (a), TREE_VALUE (a2)) == 1)
3057 a1 = copy_node (a2);
3058 TREE_CHAIN (a1) = attributes;
3067 /* Given types T1 and T2, merge their attributes and return
3071 merge_type_attributes (tree t1, tree t2)
3073 return merge_attributes (TYPE_ATTRIBUTES (t1),
3074 TYPE_ATTRIBUTES (t2));
3077 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
3081 merge_decl_attributes (tree olddecl, tree newdecl)
3083 return merge_attributes (DECL_ATTRIBUTES (olddecl),
3084 DECL_ATTRIBUTES (newdecl));
3087 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
3089 /* Specialization of merge_decl_attributes for various Windows targets.
3091 This handles the following situation:
3093 __declspec (dllimport) int foo;
3096 The second instance of `foo' nullifies the dllimport. */
3099 merge_dllimport_decl_attributes (tree old, tree new)
3102 int delete_dllimport_p;
3104 old = DECL_ATTRIBUTES (old);
3105 new = DECL_ATTRIBUTES (new);
3107 /* What we need to do here is remove from `old' dllimport if it doesn't
3108 appear in `new'. dllimport behaves like extern: if a declaration is
3109 marked dllimport and a definition appears later, then the object
3110 is not dllimport'd. */
3111 if (lookup_attribute ("dllimport", old) != NULL_TREE
3112 && lookup_attribute ("dllimport", new) == NULL_TREE)
3113 delete_dllimport_p = 1;
3115 delete_dllimport_p = 0;
3117 a = merge_attributes (old, new);
3119 if (delete_dllimport_p)
3123 /* Scan the list for dllimport and delete it. */
3124 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
3126 if (is_attribute_p ("dllimport", TREE_PURPOSE (t)))
3128 if (prev == NULL_TREE)
3131 TREE_CHAIN (prev) = TREE_CHAIN (t);
3140 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
3141 struct attribute_spec.handler. */
3144 handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
3149 /* These attributes may apply to structure and union types being created,
3150 but otherwise should pass to the declaration involved. */
3153 if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
3154 | (int) ATTR_FLAG_ARRAY_NEXT))
3156 *no_add_attrs = true;
3157 return tree_cons (name, args, NULL_TREE);
3159 if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
3161 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
3162 *no_add_attrs = true;
3168 /* Report error on dllimport ambiguities seen now before they cause
3170 if (is_attribute_p ("dllimport", name))
3172 /* Like MS, treat definition of dllimported variables and
3173 non-inlined functions on declaration as syntax errors. We
3174 allow the attribute for function definitions if declared
3176 if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node)
3177 && !DECL_DECLARED_INLINE_P (node))
3179 error ("%Jfunction `%D' definition is marked dllimport.", node, node);
3180 *no_add_attrs = true;
3183 else if (TREE_CODE (node) == VAR_DECL)
3185 if (DECL_INITIAL (node))
3187 error ("%Jvariable `%D' definition is marked dllimport.",
3189 *no_add_attrs = true;
3192 /* `extern' needn't be specified with dllimport.
3193 Specify `extern' now and hope for the best. Sigh. */
3194 DECL_EXTERNAL (node) = 1;
3195 /* Also, implicitly give dllimport'd variables declared within
3196 a function global scope, unless declared static. */
3197 if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
3198 TREE_PUBLIC (node) = 1;
3202 /* Report error if symbol is not accessible at global scope. */
3203 if (!TREE_PUBLIC (node)
3204 && (TREE_CODE (node) == VAR_DECL
3205 || TREE_CODE (node) == FUNCTION_DECL))
3207 error ("%Jexternal linkage required for symbol '%D' because of "
3208 "'%s' attribute.", node, node, IDENTIFIER_POINTER (name));
3209 *no_add_attrs = true;
3215 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
3217 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
3218 of the various TYPE_QUAL values. */
3221 set_type_quals (tree type, int type_quals)
3223 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
3224 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
3225 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
3228 /* Returns true iff cand is equivalent to base with type_quals. */
3231 check_qualified_type (tree cand, tree base, int type_quals)
3233 return (TYPE_QUALS (cand) == type_quals
3234 && TYPE_NAME (cand) == TYPE_NAME (base)
3235 /* Apparently this is needed for Objective-C. */
3236 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
3237 && attribute_list_equal (TYPE_ATTRIBUTES (cand),
3238 TYPE_ATTRIBUTES (base)));
3241 /* Return a version of the TYPE, qualified as indicated by the
3242 TYPE_QUALS, if one exists. If no qualified version exists yet,
3243 return NULL_TREE. */
3246 get_qualified_type (tree type, int type_quals)
3250 if (TYPE_QUALS (type) == type_quals)
3253 /* Search the chain of variants to see if there is already one there just
3254 like the one we need to have. If so, use that existing one. We must
3255 preserve the TYPE_NAME, since there is code that depends on this. */
3256 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
3257 if (check_qualified_type (t, type, type_quals))
3263 /* Like get_qualified_type, but creates the type if it does not
3264 exist. This function never returns NULL_TREE. */
3267 build_qualified_type (tree type, int type_quals)
3271 /* See if we already have the appropriate qualified variant. */
3272 t = get_qualified_type (type, type_quals);
3274 /* If not, build it. */
3277 t = build_variant_type_copy (type);
3278 set_type_quals (t, type_quals);
3284 /* Create a new distinct copy of TYPE. The new type is made its own
3288 build_distinct_type_copy (tree type)
3290 tree t = copy_node (type);
3292 TYPE_POINTER_TO (t) = 0;
3293 TYPE_REFERENCE_TO (t) = 0;
3295 /* Make it its own variant. */
3296 TYPE_MAIN_VARIANT (t) = t;
3297 TYPE_NEXT_VARIANT (t) = 0;
3302 /* Create a new variant of TYPE, equivalent but distinct.
3303 This is so the caller can modify it. */
3306 build_variant_type_copy (tree type)
3308 tree t, m = TYPE_MAIN_VARIANT (type);
3310 t = build_distinct_type_copy (type);
3312 /* Add the new type to the chain of variants of TYPE. */
3313 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
3314 TYPE_NEXT_VARIANT (m) = t;
3315 TYPE_MAIN_VARIANT (t) = m;
3320 /* Hashing of types so that we don't make duplicates.
3321 The entry point is `type_hash_canon'. */
3323 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
3324 with types in the TREE_VALUE slots), by adding the hash codes
3325 of the individual types. */
3328 type_hash_list (tree list, hashval_t hashcode)
3332 for (tail = list; tail; tail = TREE_CHAIN (tail))
3333 if (TREE_VALUE (tail) != error_mark_node)
3334 hashcode = iterative_hash_object (TYPE_HASH (TREE_VALUE (tail)),
3340 /* These are the Hashtable callback functions. */
3342 /* Returns true iff the types are equivalent. */
3345 type_hash_eq (const void *va, const void *vb)
3347 const struct type_hash *a = va, *b = vb;
3349 /* First test the things that are the same for all types. */
3350 if (a->hash != b->hash
3351 || TREE_CODE (a->type) != TREE_CODE (b->type)
3352 || TREE_TYPE (a->type) != TREE_TYPE (b->type)
3353 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
3354 TYPE_ATTRIBUTES (b->type))
3355 || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
3356 || TYPE_MODE (a->type) != TYPE_MODE (b->type))
3359 switch (TREE_CODE (a->type))
3365 case REFERENCE_TYPE:
3369 if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
3370 && !(TYPE_VALUES (a->type)
3371 && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
3372 && TYPE_VALUES (b->type)
3373 && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
3374 && type_list_equal (TYPE_VALUES (a->type),
3375 TYPE_VALUES (b->type))))
3378 /* ... fall through ... */
3384 return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
3385 || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
3386 TYPE_MAX_VALUE (b->type)))
3387 && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
3388 || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
3389 TYPE_MIN_VALUE (b->type))));
3392 return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
3395 return (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
3396 && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
3397 || (TYPE_ARG_TYPES (a->type)
3398 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
3399 && TYPE_ARG_TYPES (b->type)
3400 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
3401 && type_list_equal (TYPE_ARG_TYPES (a->type),
3402 TYPE_ARG_TYPES (b->type)))));
3406 return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type);
3410 case QUAL_UNION_TYPE:
3411 return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
3412 || (TYPE_FIELDS (a->type)
3413 && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
3414 && TYPE_FIELDS (b->type)
3415 && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
3416 && type_list_equal (TYPE_FIELDS (a->type),
3417 TYPE_FIELDS (b->type))));
3420 return (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
3421 || (TYPE_ARG_TYPES (a->type)
3422 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
3423 && TYPE_ARG_TYPES (b->type)
3424 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
3425 && type_list_equal (TYPE_ARG_TYPES (a->type),
3426 TYPE_ARG_TYPES (b->type))));
3433 /* Return the cached hash value. */
3436 type_hash_hash (const void *item)
3438 return ((const struct type_hash *) item)->hash;
3441 /* Look in the type hash table for a type isomorphic to TYPE.
3442 If one is found, return it. Otherwise return 0. */
3445 type_hash_lookup (hashval_t hashcode, tree type)
3447 struct type_hash *h, in;
3449 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
3450 must call that routine before comparing TYPE_ALIGNs. */
3456 h = htab_find_with_hash (type_hash_table, &in, hashcode);
3462 /* Add an entry to the type-hash-table
3463 for a type TYPE whose hash code is HASHCODE. */
3466 type_hash_add (hashval_t hashcode, tree type)
3468 struct type_hash *h;
3471 h = ggc_alloc (sizeof (struct type_hash));
3474 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
3475 *(struct type_hash **) loc = h;
3478 /* Given TYPE, and HASHCODE its hash code, return the canonical
3479 object for an identical type if one already exists.
3480 Otherwise, return TYPE, and record it as the canonical object.
3482 To use this function, first create a type of the sort you want.
3483 Then compute its hash code from the fields of the type that
3484 make it different from other similar types.
3485 Then call this function and use the value. */
3488 type_hash_canon (unsigned int hashcode, tree type)
3492 /* The hash table only contains main variants, so ensure that's what we're
3494 if (TYPE_MAIN_VARIANT (type) != type)
3497 if (!lang_hooks.types.hash_types)
3500 /* See if the type is in the hash table already. If so, return it.
3501 Otherwise, add the type. */
3502 t1 = type_hash_lookup (hashcode, type);
3505 #ifdef GATHER_STATISTICS
3506 tree_node_counts[(int) t_kind]--;
3507 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
3513 type_hash_add (hashcode, type);
3518 /* See if the data pointed to by the type hash table is marked. We consider
3519 it marked if the type is marked or if a debug type number or symbol
3520 table entry has been made for the type. This reduces the amount of
3521 debugging output and eliminates that dependency of the debug output on
3522 the number of garbage collections. */
3525 type_hash_marked_p (const void *p)
3527 tree type = ((struct type_hash *) p)->type;
3529 return ggc_marked_p (type) || TYPE_SYMTAB_POINTER (type);
3533 print_type_hash_statistics (void)
3535 fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
3536 (long) htab_size (type_hash_table),
3537 (long) htab_elements (type_hash_table),
3538 htab_collisions (type_hash_table));
3541 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
3542 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
3543 by adding the hash codes of the individual attributes. */
3546 attribute_hash_list (tree list, hashval_t hashcode)
3550 for (tail = list; tail; tail = TREE_CHAIN (tail))
3551 /* ??? Do we want to add in TREE_VALUE too? */
3552 hashcode = iterative_hash_object
3553 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail)), hashcode);
3557 /* Given two lists of attributes, return true if list l2 is
3558 equivalent to l1. */
3561 attribute_list_equal (tree l1, tree l2)
3563 return attribute_list_contained (l1, l2)
3564 && attribute_list_contained (l2, l1);
3567 /* Given two lists of attributes, return true if list L2 is
3568 completely contained within L1. */
3569 /* ??? This would be faster if attribute names were stored in a canonicalized
3570 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
3571 must be used to show these elements are equivalent (which they are). */
3572 /* ??? It's not clear that attributes with arguments will always be handled
3576 attribute_list_contained (tree l1, tree l2)
3580 /* First check the obvious, maybe the lists are identical. */
3584 /* Maybe the lists are similar. */
3585 for (t1 = l1, t2 = l2;
3587 && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
3588 && TREE_VALUE (t1) == TREE_VALUE (t2);
3589 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
3591 /* Maybe the lists are equal. */
3592 if (t1 == 0 && t2 == 0)
3595 for (; t2 != 0; t2 = TREE_CHAIN (t2))
3598 for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1);
3600 attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
3603 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) == 1)
3610 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) != 1)
3617 /* Given two lists of types
3618 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
3619 return 1 if the lists contain the same types in the same order.
3620 Also, the TREE_PURPOSEs must match. */
3623 type_list_equal (tree l1, tree l2)
3627 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
3628 if (TREE_VALUE (t1) != TREE_VALUE (t2)
3629 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
3630 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
3631 && (TREE_TYPE (TREE_PURPOSE (t1))
3632 == TREE_TYPE (TREE_PURPOSE (t2))))))
3638 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
3639 given by TYPE. If the argument list accepts variable arguments,
3640 then this function counts only the ordinary arguments. */
3643 type_num_arguments (tree type)
3648 for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
3649 /* If the function does not take a variable number of arguments,
3650 the last element in the list will have type `void'. */
3651 if (VOID_TYPE_P (TREE_VALUE (t)))
3659 /* Nonzero if integer constants T1 and T2
3660 represent the same constant value. */
3663 tree_int_cst_equal (tree t1, tree t2)
3668 if (t1 == 0 || t2 == 0)
3671 if (TREE_CODE (t1) == INTEGER_CST
3672 && TREE_CODE (t2) == INTEGER_CST
3673 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3674 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
3680 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
3681 The precise way of comparison depends on their data type. */
3684 tree_int_cst_lt (tree t1, tree t2)
3689 if (TYPE_UNSIGNED (TREE_TYPE (t1)) != TYPE_UNSIGNED (TREE_TYPE (t2)))
3691 int t1_sgn = tree_int_cst_sgn (t1);
3692 int t2_sgn = tree_int_cst_sgn (t2);
3694 if (t1_sgn < t2_sgn)
3696 else if (t1_sgn > t2_sgn)
3698 /* Otherwise, both are non-negative, so we compare them as
3699 unsigned just in case one of them would overflow a signed
3702 else if (!TYPE_UNSIGNED (TREE_TYPE (t1)))
3703 return INT_CST_LT (t1, t2);
3705 return INT_CST_LT_UNSIGNED (t1, t2);
3708 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
3711 tree_int_cst_compare (tree t1, tree t2)
3713 if (tree_int_cst_lt (t1, t2))
3715 else if (tree_int_cst_lt (t2, t1))
3721 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
3722 the host. If POS is zero, the value can be represented in a single
3723 HOST_WIDE_INT. If POS is nonzero, the value must be positive and can
3724 be represented in a single unsigned HOST_WIDE_INT. */
3727 host_integerp (tree t, int pos)
3729 return (TREE_CODE (t) == INTEGER_CST
3730 && ! TREE_OVERFLOW (t)
3731 && ((TREE_INT_CST_HIGH (t) == 0
3732 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
3733 || (! pos && TREE_INT_CST_HIGH (t) == -1
3734 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
3735 && !TYPE_UNSIGNED (TREE_TYPE (t)))
3736 || (pos && TREE_INT_CST_HIGH (t) == 0)));
3739 /* Return the HOST_WIDE_INT least significant bits of T if it is an
3740 INTEGER_CST and there is no overflow. POS is nonzero if the result must
3741 be positive. Abort if we cannot satisfy the above conditions. */
3744 tree_low_cst (tree t, int pos)
3746 if (host_integerp (t, pos))
3747 return TREE_INT_CST_LOW (t);
3752 /* Return the most significant bit of the integer constant T. */
3755 tree_int_cst_msb (tree t)
3759 unsigned HOST_WIDE_INT l;
3761 /* Note that using TYPE_PRECISION here is wrong. We care about the
3762 actual bits, not the (arbitrary) range of the type. */
3763 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
3764 rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
3765 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
3766 return (l & 1) == 1;
3769 /* Return an indication of the sign of the integer constant T.
3770 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
3771 Note that -1 will never be returned it T's type is unsigned. */
3774 tree_int_cst_sgn (tree t)
3776 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
3778 else if (TYPE_UNSIGNED (TREE_TYPE (t)))
3780 else if (TREE_INT_CST_HIGH (t) < 0)
3786 /* Compare two constructor-element-type constants. Return 1 if the lists
3787 are known to be equal; otherwise return 0. */
3790 simple_cst_list_equal (tree l1, tree l2)
3792 while (l1 != NULL_TREE && l2 != NULL_TREE)
3794 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
3797 l1 = TREE_CHAIN (l1);
3798 l2 = TREE_CHAIN (l2);
3804 /* Return truthvalue of whether T1 is the same tree structure as T2.
3805 Return 1 if they are the same.
3806 Return 0 if they are understandably different.
3807 Return -1 if either contains tree structure not understood by
3811 simple_cst_equal (tree t1, tree t2)
3813 enum tree_code code1, code2;
3819 if (t1 == 0 || t2 == 0)
3822 code1 = TREE_CODE (t1);
3823 code2 = TREE_CODE (t2);
3825 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
3827 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3828 || code2 == NON_LVALUE_EXPR)
3829 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3831 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
3834 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3835 || code2 == NON_LVALUE_EXPR)
3836 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
3844 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3845 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
3848 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3851 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3852 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3853 TREE_STRING_LENGTH (t1)));
3856 return simple_cst_list_equal (CONSTRUCTOR_ELTS (t1),
3857 CONSTRUCTOR_ELTS (t2));
3860 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3863 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3867 simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3870 /* Special case: if either target is an unallocated VAR_DECL,
3871 it means that it's going to be unified with whatever the
3872 TARGET_EXPR is really supposed to initialize, so treat it
3873 as being equivalent to anything. */
3874 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
3875 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
3876 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
3877 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
3878 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
3879 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
3882 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3887 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3889 case WITH_CLEANUP_EXPR:
3890 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3894 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
3897 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
3898 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3912 /* This general rule works for most tree codes. All exceptions should be
3913 handled above. If this is a language-specific tree code, we can't
3914 trust what might be in the operand, so say we don't know
3916 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
3919 switch (TREE_CODE_CLASS (code1))
3928 for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
3930 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
3942 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
3943 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
3944 than U, respectively. */
3947 compare_tree_int (tree t, unsigned HOST_WIDE_INT u)
3949 if (tree_int_cst_sgn (t) < 0)
3951 else if (TREE_INT_CST_HIGH (t) != 0)
3953 else if (TREE_INT_CST_LOW (t) == u)
3955 else if (TREE_INT_CST_LOW (t) < u)
3961 /* Return true if CODE represents an associative tree code. Otherwise
3964 associative_tree_code (enum tree_code code)
3983 /* Return true if CODE represents an commutative tree code. Otherwise
3986 commutative_tree_code (enum tree_code code)
3999 case UNORDERED_EXPR:
4003 case TRUTH_AND_EXPR:
4004 case TRUTH_XOR_EXPR:
4014 /* Generate a hash value for an expression. This can be used iteratively
4015 by passing a previous result as the "val" argument.
4017 This function is intended to produce the same hash for expressions which
4018 would compare equal using operand_equal_p. */
4021 iterative_hash_expr (tree t, hashval_t val)
4024 enum tree_code code;
4028 return iterative_hash_pointer (t, val);
4030 code = TREE_CODE (t);
4034 /* Alas, constants aren't shared, so we can't rely on pointer
4037 val = iterative_hash_host_wide_int (TREE_INT_CST_LOW (t), val);
4038 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t), val);
4041 unsigned int val2 = real_hash (TREE_REAL_CST_PTR (t));
4043 return iterative_hash_hashval_t (val2, val);
4046 return iterative_hash (TREE_STRING_POINTER (t),
4047 TREE_STRING_LENGTH (t), val);
4049 val = iterative_hash_expr (TREE_REALPART (t), val);
4050 return iterative_hash_expr (TREE_IMAGPART (t), val);
4052 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val);
4056 /* we can just compare by pointer. */
4057 return iterative_hash_pointer (t, val);
4060 /* A list of expressions, for a CALL_EXPR or as the elements of a
4062 for (; t; t = TREE_CHAIN (t))
4063 val = iterative_hash_expr (TREE_VALUE (t), val);
4066 class = TREE_CODE_CLASS (code);
4070 /* Decls we can just compare by pointer. */
4071 val = iterative_hash_pointer (t, val);
4073 else if (IS_EXPR_CODE_CLASS (class))
4075 val = iterative_hash_object (code, val);
4077 /* Don't hash the type, that can lead to having nodes which
4078 compare equal according to operand_equal_p, but which
4079 have different hash codes. */
4080 if (code == NOP_EXPR
4081 || code == CONVERT_EXPR
4082 || code == NON_LVALUE_EXPR)
4084 /* Make sure to include signness in the hash computation. */
4085 val += TYPE_UNSIGNED (TREE_TYPE (t));
4086 val = iterative_hash_expr (TREE_OPERAND (t, 0), val);
4089 else if (commutative_tree_code (code))
4091 /* It's a commutative expression. We want to hash it the same
4092 however it appears. We do this by first hashing both operands
4093 and then rehashing based on the order of their independent
4095 hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0);
4096 hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0);
4100 t = one, one = two, two = t;
4102 val = iterative_hash_hashval_t (one, val);
4103 val = iterative_hash_hashval_t (two, val);
4106 for (i = first_rtl_op (code) - 1; i >= 0; --i)
4107 val = iterative_hash_expr (TREE_OPERAND (t, i), val);
4116 /* Constructors for pointer, array and function types.
4117 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
4118 constructed by language-dependent code, not here.) */
4120 /* Construct, lay out and return the type of pointers to TO_TYPE with
4121 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
4122 reference all of memory. If such a type has already been
4123 constructed, reuse it. */
4126 build_pointer_type_for_mode (tree to_type, enum machine_mode mode,
4131 /* In some cases, languages will have things that aren't a POINTER_TYPE
4132 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
4133 In that case, return that type without regard to the rest of our
4136 ??? This is a kludge, but consistent with the way this function has
4137 always operated and there doesn't seem to be a good way to avoid this
4139 if (TYPE_POINTER_TO (to_type) != 0
4140 && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
4141 return TYPE_POINTER_TO (to_type);
4143 /* First, if we already have a type for pointers to TO_TYPE and it's
4144 the proper mode, use it. */
4145 for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
4146 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
4149 t = make_node (POINTER_TYPE);
4151 TREE_TYPE (t) = to_type;
4152 TYPE_MODE (t) = mode;
4153 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
4154 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
4155 TYPE_POINTER_TO (to_type) = t;
4157 /* Lay out the type. This function has many callers that are concerned
4158 with expression-construction, and this simplifies them all. */
4164 /* By default build pointers in ptr_mode. */
4167 build_pointer_type (tree to_type)
4169 return build_pointer_type_for_mode (to_type, ptr_mode, false);
4172 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
4175 build_reference_type_for_mode (tree to_type, enum machine_mode mode,
4180 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
4181 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
4182 In that case, return that type without regard to the rest of our
4185 ??? This is a kludge, but consistent with the way this function has
4186 always operated and there doesn't seem to be a good way to avoid this
4188 if (TYPE_REFERENCE_TO (to_type) != 0
4189 && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
4190 return TYPE_REFERENCE_TO (to_type);
4192 /* First, if we already have a type for pointers to TO_TYPE and it's
4193 the proper mode, use it. */
4194 for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
4195 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
4198 t = make_node (REFERENCE_TYPE);
4200 TREE_TYPE (t) = to_type;
4201 TYPE_MODE (t) = mode;
4202 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
4203 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
4204 TYPE_REFERENCE_TO (to_type) = t;
4212 /* Build the node for the type of references-to-TO_TYPE by default
4216 build_reference_type (tree to_type)
4218 return build_reference_type_for_mode (to_type, ptr_mode, false);
4221 /* Build a type that is compatible with t but has no cv quals anywhere
4224 const char *const *const * -> char ***. */
4227 build_type_no_quals (tree t)
4229 switch (TREE_CODE (t))
4232 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
4234 TYPE_REF_CAN_ALIAS_ALL (t));
4235 case REFERENCE_TYPE:
4237 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
4239 TYPE_REF_CAN_ALIAS_ALL (t));
4241 return TYPE_MAIN_VARIANT (t);
4245 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
4246 MAXVAL should be the maximum value in the domain
4247 (one less than the length of the array).
4249 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
4250 We don't enforce this limit, that is up to caller (e.g. language front end).
4251 The limit exists because the result is a signed type and we don't handle
4252 sizes that use more than one HOST_WIDE_INT. */
4255 build_index_type (tree maxval)
4257 tree itype = make_node (INTEGER_TYPE);
4259 TREE_TYPE (itype) = sizetype;
4260 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
4261 TYPE_MIN_VALUE (itype) = size_zero_node;
4262 TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
4263 TYPE_MODE (itype) = TYPE_MODE (sizetype);
4264 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
4265 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
4266 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
4267 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
4269 if (host_integerp (maxval, 1))
4270 return type_hash_canon (tree_low_cst (maxval, 1), itype);
4275 /* Builds a signed or unsigned integer type of precision PRECISION.
4276 Used for C bitfields whose precision does not match that of
4277 built-in target types. */
4279 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
4282 tree itype = make_node (INTEGER_TYPE);
4284 TYPE_PRECISION (itype) = precision;
4287 fixup_unsigned_type (itype);
4289 fixup_signed_type (itype);
4291 if (host_integerp (TYPE_MAX_VALUE (itype), 1))
4292 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype);
4297 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
4298 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
4299 low bound LOWVAL and high bound HIGHVAL.
4300 if TYPE==NULL_TREE, sizetype is used. */
4303 build_range_type (tree type, tree lowval, tree highval)
4305 tree itype = make_node (INTEGER_TYPE);
4307 TREE_TYPE (itype) = type;
4308 if (type == NULL_TREE)
4311 TYPE_MIN_VALUE (itype) = convert (type, lowval);
4312 TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL;
4314 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
4315 TYPE_MODE (itype) = TYPE_MODE (type);
4316 TYPE_SIZE (itype) = TYPE_SIZE (type);
4317 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
4318 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
4319 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
4321 if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
4322 return type_hash_canon (tree_low_cst (highval, 0)
4323 - tree_low_cst (lowval, 0),
4329 /* Just like build_index_type, but takes lowval and highval instead
4330 of just highval (maxval). */
4333 build_index_2_type (tree lowval, tree highval)
4335 return build_range_type (sizetype, lowval, highval);
4338 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
4339 and number of elements specified by the range of values of INDEX_TYPE.
4340 If such a type has already been constructed, reuse it. */
4343 build_array_type (tree elt_type, tree index_type)
4346 hashval_t hashcode = 0;
4348 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
4350 error ("arrays of functions are not meaningful");
4351 elt_type = integer_type_node;
4354 t = make_node (ARRAY_TYPE);
4355 TREE_TYPE (t) = elt_type;
4356 TYPE_DOMAIN (t) = index_type;
4358 if (index_type == 0)
4361 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
4362 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
4363 t = type_hash_canon (hashcode, t);
4365 if (!COMPLETE_TYPE_P (t))
4370 /* Return the TYPE of the elements comprising
4371 the innermost dimension of ARRAY. */
4374 get_inner_array_type (tree array)
4376 tree type = TREE_TYPE (array);
4378 while (TREE_CODE (type) == ARRAY_TYPE)
4379 type = TREE_TYPE (type);
4384 /* Construct, lay out and return
4385 the type of functions returning type VALUE_TYPE
4386 given arguments of types ARG_TYPES.
4387 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
4388 are data type nodes for the arguments of the function.
4389 If such a type has already been constructed, reuse it. */
4392 build_function_type (tree value_type, tree arg_types)
4395 hashval_t hashcode = 0;
4397 if (TREE_CODE (value_type) == FUNCTION_TYPE)
4399 error ("function return type cannot be function");
4400 value_type = integer_type_node;
4403 /* Make a node of the sort we want. */
4404 t = make_node (FUNCTION_TYPE);
4405 TREE_TYPE (t) = value_type;
4406 TYPE_ARG_TYPES (t) = arg_types;
4408 /* If we already have such a type, use the old one. */
4409 hashcode = iterative_hash_object (TYPE_HASH (value_type), hashcode);
4410 hashcode = type_hash_list (arg_types, hashcode);
4411 t = type_hash_canon (hashcode, t);
4413 if (!COMPLETE_TYPE_P (t))
4418 /* Build a function type. The RETURN_TYPE is the type returned by the
4419 function. If additional arguments are provided, they are
4420 additional argument types. The list of argument types must always
4421 be terminated by NULL_TREE. */
4424 build_function_type_list (tree return_type, ...)
4429 va_start (p, return_type);
4431 t = va_arg (p, tree);
4432 for (args = NULL_TREE; t != NULL_TREE; t = va_arg (p, tree))
4433 args = tree_cons (NULL_TREE, t, args);
4436 args = nreverse (args);
4437 TREE_CHAIN (last) = void_list_node;
4438 args = build_function_type (return_type, args);
4444 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
4445 and ARGTYPES (a TREE_LIST) are the return type and arguments types
4446 for the method. An implicit additional parameter (of type
4447 pointer-to-BASETYPE) is added to the ARGTYPES. */
4450 build_method_type_directly (tree basetype,
4458 /* Make a node of the sort we want. */
4459 t = make_node (METHOD_TYPE);
4461 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4462 TREE_TYPE (t) = rettype;
4463 ptype = build_pointer_type (basetype);
4465 /* The actual arglist for this function includes a "hidden" argument
4466 which is "this". Put it into the list of argument types. */
4467 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
4468 TYPE_ARG_TYPES (t) = argtypes;
4470 /* If we already have such a type, use the old one. */
4471 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
4472 hashcode = iterative_hash_object (TYPE_HASH (rettype), hashcode);
4473 hashcode = type_hash_list (argtypes, hashcode);
4474 t = type_hash_canon (hashcode, t);
4476 if (!COMPLETE_TYPE_P (t))
4482 /* Construct, lay out and return the type of methods belonging to class
4483 BASETYPE and whose arguments and values are described by TYPE.
4484 If that type exists already, reuse it.
4485 TYPE must be a FUNCTION_TYPE node. */
4488 build_method_type (tree basetype, tree type)
4490 if (TREE_CODE (type) != FUNCTION_TYPE)
4493 return build_method_type_directly (basetype,
4495 TYPE_ARG_TYPES (type));
4498 /* Construct, lay out and return the type of offsets to a value
4499 of type TYPE, within an object of type BASETYPE.
4500 If a suitable offset type exists already, reuse it. */
4503 build_offset_type (tree basetype, tree type)
4506 hashval_t hashcode = 0;
4508 /* Make a node of the sort we want. */
4509 t = make_node (OFFSET_TYPE);
4511 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4512 TREE_TYPE (t) = type;
4514 /* If we already have such a type, use the old one. */
4515 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
4516 hashcode = iterative_hash_object (TYPE_HASH (type), hashcode);
4517 t = type_hash_canon (hashcode, t);
4519 if (!COMPLETE_TYPE_P (t))
4525 /* Create a complex type whose components are COMPONENT_TYPE. */
4528 build_complex_type (tree component_type)
4533 /* Make a node of the sort we want. */
4534 t = make_node (COMPLEX_TYPE);
4536 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
4538 /* If we already have such a type, use the old one. */
4539 hashcode = iterative_hash_object (TYPE_HASH (component_type), 0);
4540 t = type_hash_canon (hashcode, t);
4542 if (!COMPLETE_TYPE_P (t))
4545 /* If we are writing Dwarf2 output we need to create a name,
4546 since complex is a fundamental type. */
4547 if ((write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4551 if (component_type == char_type_node)
4552 name = "complex char";
4553 else if (component_type == signed_char_type_node)
4554 name = "complex signed char";
4555 else if (component_type == unsigned_char_type_node)
4556 name = "complex unsigned char";
4557 else if (component_type == short_integer_type_node)
4558 name = "complex short int";
4559 else if (component_type == short_unsigned_type_node)
4560 name = "complex short unsigned int";
4561 else if (component_type == integer_type_node)
4562 name = "complex int";
4563 else if (component_type == unsigned_type_node)
4564 name = "complex unsigned int";
4565 else if (component_type == long_integer_type_node)
4566 name = "complex long int";
4567 else if (component_type == long_unsigned_type_node)
4568 name = "complex long unsigned int";
4569 else if (component_type == long_long_integer_type_node)
4570 name = "complex long long int";
4571 else if (component_type == long_long_unsigned_type_node)
4572 name = "complex long long unsigned int";
4577 TYPE_NAME (t) = get_identifier (name);
4580 return build_qualified_type (t, TYPE_QUALS (component_type));
4583 /* Return OP, stripped of any conversions to wider types as much as is safe.
4584 Converting the value back to OP's type makes a value equivalent to OP.
4586 If FOR_TYPE is nonzero, we return a value which, if converted to
4587 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
4589 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
4590 narrowest type that can hold the value, even if they don't exactly fit.
4591 Otherwise, bit-field references are changed to a narrower type
4592 only if they can be fetched directly from memory in that type.
4594 OP must have integer, real or enumeral type. Pointers are not allowed!
4596 There are some cases where the obvious value we could return
4597 would regenerate to OP if converted to OP's type,
4598 but would not extend like OP to wider types.
4599 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
4600 For example, if OP is (unsigned short)(signed char)-1,
4601 we avoid returning (signed char)-1 if FOR_TYPE is int,
4602 even though extending that to an unsigned short would regenerate OP,
4603 since the result of extending (signed char)-1 to (int)
4604 is different from (int) OP. */
4607 get_unwidened (tree op, tree for_type)
4609 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
4610 tree type = TREE_TYPE (op);
4612 = TYPE_PRECISION (for_type != 0 ? for_type : type);
4614 = (for_type != 0 && for_type != type
4615 && final_prec > TYPE_PRECISION (type)
4616 && TYPE_UNSIGNED (type));
4619 while (TREE_CODE (op) == NOP_EXPR)
4622 = TYPE_PRECISION (TREE_TYPE (op))
4623 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
4625 /* Truncations are many-one so cannot be removed.
4626 Unless we are later going to truncate down even farther. */
4628 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
4631 /* See what's inside this conversion. If we decide to strip it,
4633 op = TREE_OPERAND (op, 0);
4635 /* If we have not stripped any zero-extensions (uns is 0),
4636 we can strip any kind of extension.
4637 If we have previously stripped a zero-extension,
4638 only zero-extensions can safely be stripped.
4639 Any extension can be stripped if the bits it would produce
4640 are all going to be discarded later by truncating to FOR_TYPE. */
4644 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
4646 /* TYPE_UNSIGNED says whether this is a zero-extension.
4647 Let's avoid computing it if it does not affect WIN
4648 and if UNS will not be needed again. */
4649 if ((uns || TREE_CODE (op) == NOP_EXPR)
4650 && TYPE_UNSIGNED (TREE_TYPE (op)))
4658 if (TREE_CODE (op) == COMPONENT_REF
4659 /* Since type_for_size always gives an integer type. */
4660 && TREE_CODE (type) != REAL_TYPE
4661 /* Don't crash if field not laid out yet. */
4662 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
4663 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
4665 unsigned int innerprec
4666 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4667 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
4668 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
4669 type = lang_hooks.types.type_for_size (innerprec, unsignedp);
4671 /* We can get this structure field in the narrowest type it fits in.
4672 If FOR_TYPE is 0, do this only for a field that matches the
4673 narrower type exactly and is aligned for it
4674 The resulting extension to its nominal type (a fullword type)
4675 must fit the same conditions as for other extensions. */
4678 && INT_CST_LT_UNSIGNED (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (op)))
4679 && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
4680 && (! uns || final_prec <= innerprec || unsignedp))
4682 win = build3 (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4683 TREE_OPERAND (op, 1), NULL_TREE);
4684 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4685 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4692 /* Return OP or a simpler expression for a narrower value
4693 which can be sign-extended or zero-extended to give back OP.
4694 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
4695 or 0 if the value should be sign-extended. */
4698 get_narrower (tree op, int *unsignedp_ptr)
4703 bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
4705 while (TREE_CODE (op) == NOP_EXPR)
4708 = (TYPE_PRECISION (TREE_TYPE (op))
4709 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
4711 /* Truncations are many-one so cannot be removed. */
4715 /* See what's inside this conversion. If we decide to strip it,
4720 op = TREE_OPERAND (op, 0);
4721 /* An extension: the outermost one can be stripped,
4722 but remember whether it is zero or sign extension. */
4724 uns = TYPE_UNSIGNED (TREE_TYPE (op));
4725 /* Otherwise, if a sign extension has been stripped,
4726 only sign extensions can now be stripped;
4727 if a zero extension has been stripped, only zero-extensions. */
4728 else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
4732 else /* bitschange == 0 */
4734 /* A change in nominal type can always be stripped, but we must
4735 preserve the unsignedness. */
4737 uns = TYPE_UNSIGNED (TREE_TYPE (op));
4739 op = TREE_OPERAND (op, 0);
4740 /* Keep trying to narrow, but don't assign op to win if it
4741 would turn an integral type into something else. */
4742 if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
4749 if (TREE_CODE (op) == COMPONENT_REF
4750 /* Since type_for_size always gives an integer type. */
4751 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
4752 /* Ensure field is laid out already. */
4753 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
4754 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
4756 unsigned HOST_WIDE_INT innerprec
4757 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4758 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
4759 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
4760 tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
4762 /* We can get this structure field in a narrower type that fits it,
4763 but the resulting extension to its nominal type (a fullword type)
4764 must satisfy the same conditions as for other extensions.
4766 Do this only for fields that are aligned (not bit-fields),
4767 because when bit-field insns will be used there is no
4768 advantage in doing this. */
4770 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
4771 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
4772 && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
4776 uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
4777 win = build3 (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4778 TREE_OPERAND (op, 1), NULL_TREE);
4779 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4780 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4783 *unsignedp_ptr = uns;
4787 /* Nonzero if integer constant C has a value that is permissible
4788 for type TYPE (an INTEGER_TYPE). */
4791 int_fits_type_p (tree c, tree type)
4793 tree type_low_bound = TYPE_MIN_VALUE (type);
4794 tree type_high_bound = TYPE_MAX_VALUE (type);
4795 int ok_for_low_bound, ok_for_high_bound;
4797 /* Perform some generic filtering first, which may allow making a decision
4798 even if the bounds are not constant. First, negative integers never fit
4799 in unsigned types, */
4800 if ((TYPE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0)
4801 /* Also, unsigned integers with top bit set never fit signed types. */
4802 || (! TYPE_UNSIGNED (type)
4803 && TYPE_UNSIGNED (TREE_TYPE (c)) && tree_int_cst_msb (c)))
4806 /* If at least one bound of the type is a constant integer, we can check
4807 ourselves and maybe make a decision. If no such decision is possible, but
4808 this type is a subtype, try checking against that. Otherwise, use
4809 force_fit_type, which checks against the precision.
4811 Compute the status for each possibly constant bound, and return if we see
4812 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
4813 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
4814 for "constant known to fit". */
4816 ok_for_low_bound = -1;
4817 ok_for_high_bound = -1;
4819 /* Check if C >= type_low_bound. */
4820 if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
4822 ok_for_low_bound = ! tree_int_cst_lt (c, type_low_bound);
4823 if (! ok_for_low_bound)
4827 /* Check if c <= type_high_bound. */
4828 if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
4830 ok_for_high_bound = ! tree_int_cst_lt (type_high_bound, c);
4831 if (! ok_for_high_bound)
4835 /* If the constant fits both bounds, the result is known. */
4836 if (ok_for_low_bound == 1 && ok_for_high_bound == 1)
4839 /* If we haven't been able to decide at this point, there nothing more we
4840 can check ourselves here. Look at the base type if we have one. */
4841 else if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != 0)
4842 return int_fits_type_p (c, TREE_TYPE (type));
4844 /* Or to force_fit_type, if nothing else. */
4848 TREE_TYPE (c) = type;
4849 c = force_fit_type (c, -1, false, false);
4850 return !TREE_OVERFLOW (c);
4854 /* Subprogram of following function. Called by walk_tree.
4856 Return *TP if it is an automatic variable or parameter of the
4857 function passed in as DATA. */
4860 find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
4862 tree fn = (tree) data;
4867 else if (DECL_P (*tp) && lang_hooks.tree_inlining.auto_var_in_fn_p (*tp, fn))
4873 /* Returns true if T is, contains, or refers to a type with variable
4874 size. If FN is nonzero, only return true if a modifier of the type
4875 or position of FN is a variable or parameter inside FN.
4877 This concept is more general than that of C99 'variably modified types':
4878 in C99, a struct type is never variably modified because a VLA may not
4879 appear as a structure member. However, in GNU C code like:
4881 struct S { int i[f()]; };
4883 is valid, and other languages may define similar constructs. */
4886 variably_modified_type_p (tree type, tree fn)
4890 /* Test if T is either variable (if FN is zero) or an expression containing
4891 a variable in FN. */
4892 #define RETURN_TRUE_IF_VAR(T) \
4893 do { tree _t = (T); \
4894 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
4895 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
4896 return true; } while (0)
4898 if (type == error_mark_node)
4901 /* If TYPE itself has variable size, it is variably modified.
4903 We do not yet have a representation of the C99 '[*]' syntax.
4904 When a representation is chosen, this function should be modified
4905 to test for that case as well. */
4906 RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
4907 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT(type));
4909 switch (TREE_CODE (type))
4912 case REFERENCE_TYPE:
4916 if (variably_modified_type_p (TREE_TYPE (type), fn))
4922 /* If TYPE is a function type, it is variably modified if any of the
4923 parameters or the return type are variably modified. */
4924 if (variably_modified_type_p (TREE_TYPE (type), fn))
4927 for (t = TYPE_ARG_TYPES (type);
4928 t && t != void_list_node;
4930 if (variably_modified_type_p (TREE_VALUE (t), fn))
4939 /* Scalar types are variably modified if their end points
4941 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
4942 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
4947 case QUAL_UNION_TYPE:
4948 /* We can't see if any of the field are variably-modified by the
4949 definition we normally use, since that would produce infinite
4950 recursion via pointers. */
4951 /* This is variably modified if some field's type is. */
4952 for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
4953 if (TREE_CODE (t) == FIELD_DECL)
4955 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
4956 RETURN_TRUE_IF_VAR (DECL_SIZE (t));
4957 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
4959 if (TREE_CODE (type) == QUAL_UNION_TYPE)
4960 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
4968 /* The current language may have other cases to check, but in general,
4969 all other types are not variably modified. */
4970 return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
4972 #undef RETURN_TRUE_IF_VAR
4975 /* Given a DECL or TYPE, return the scope in which it was declared, or
4976 NULL_TREE if there is no containing scope. */
4979 get_containing_scope (tree t)
4981 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
4984 /* Return the innermost context enclosing DECL that is
4985 a FUNCTION_DECL, or zero if none. */
4988 decl_function_context (tree decl)
4992 if (TREE_CODE (decl) == ERROR_MARK)
4995 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
4996 where we look up the function at runtime. Such functions always take
4997 a first argument of type 'pointer to real context'.
4999 C++ should really be fixed to use DECL_CONTEXT for the real context,
5000 and use something else for the "virtual context". */
5001 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
5004 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
5006 context = DECL_CONTEXT (decl);
5008 while (context && TREE_CODE (context) != FUNCTION_DECL)
5010 if (TREE_CODE (context) == BLOCK)
5011 context = BLOCK_SUPERCONTEXT (context);
5013 context = get_containing_scope (context);
5019 /* Return the innermost context enclosing DECL that is
5020 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
5021 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
5024 decl_type_context (tree decl)
5026 tree context = DECL_CONTEXT (decl);
5029 switch (TREE_CODE (context))
5031 case NAMESPACE_DECL:
5032 case TRANSLATION_UNIT_DECL:
5037 case QUAL_UNION_TYPE:
5042 context = DECL_CONTEXT (context);
5046 context = BLOCK_SUPERCONTEXT (context);
5056 /* CALL is a CALL_EXPR. Return the declaration for the function
5057 called, or NULL_TREE if the called function cannot be
5061 get_callee_fndecl (tree call)
5065 /* It's invalid to call this function with anything but a
5067 if (TREE_CODE (call) != CALL_EXPR)
5070 /* The first operand to the CALL is the address of the function
5072 addr = TREE_OPERAND (call, 0);
5076 /* If this is a readonly function pointer, extract its initial value. */
5077 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
5078 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
5079 && DECL_INITIAL (addr))
5080 addr = DECL_INITIAL (addr);
5082 /* If the address is just `&f' for some function `f', then we know
5083 that `f' is being called. */
5084 if (TREE_CODE (addr) == ADDR_EXPR
5085 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
5086 return TREE_OPERAND (addr, 0);
5088 /* We couldn't figure out what was being called. Maybe the front
5089 end has some idea. */
5090 return lang_hooks.lang_get_callee_fndecl (call);
5093 /* Print debugging information about tree nodes generated during the compile,
5094 and any language-specific information. */
5097 dump_tree_statistics (void)
5099 #ifdef GATHER_STATISTICS
5101 int total_nodes, total_bytes;
5104 fprintf (stderr, "\n??? tree nodes created\n\n");
5105 #ifdef GATHER_STATISTICS
5106 fprintf (stderr, "Kind Nodes Bytes\n");
5107 fprintf (stderr, "---------------------------------------\n");
5108 total_nodes = total_bytes = 0;
5109 for (i = 0; i < (int) all_kinds; i++)
5111 fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
5112 tree_node_counts[i], tree_node_sizes[i]);
5113 total_nodes += tree_node_counts[i];
5114 total_bytes += tree_node_sizes[i];
5116 fprintf (stderr, "---------------------------------------\n");
5117 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
5118 fprintf (stderr, "---------------------------------------\n");
5119 ssanames_print_statistics ();
5120 phinodes_print_statistics ();
5122 fprintf (stderr, "(No per-node statistics)\n");
5124 print_type_hash_statistics ();
5125 lang_hooks.print_statistics ();
5128 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
5130 /* Generate a crc32 of a string. */
5133 crc32_string (unsigned chksum, const char *string)
5137 unsigned value = *string << 24;
5140 for (ix = 8; ix--; value <<= 1)
5144 feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
5153 /* P is a string that will be used in a symbol. Mask out any characters
5154 that are not valid in that context. */
5157 clean_symbol_name (char *p)
5161 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
5164 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
5171 /* Generate a name for a function unique to this translation unit.
5172 TYPE is some string to identify the purpose of this function to the
5173 linker or collect2. */
5176 get_file_function_name_long (const char *type)
5182 if (first_global_object_name)
5183 p = first_global_object_name;
5186 /* We don't have anything that we know to be unique to this translation
5187 unit, so use what we do have and throw in some randomness. */
5189 const char *name = weak_global_object_name;
5190 const char *file = main_input_filename;
5195 file = input_filename;
5197 len = strlen (file);
5198 q = alloca (9 * 2 + len + 1);
5199 memcpy (q, file, len + 1);
5200 clean_symbol_name (q);
5202 sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
5203 crc32_string (0, flag_random_seed));
5208 buf = alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p) + strlen (type));
5210 /* Set up the name of the file-level functions we may need.
5211 Use a global object (which is already required to be unique over
5212 the program) rather than the file name (which imposes extra
5214 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
5216 return get_identifier (buf);
5219 /* If KIND=='I', return a suitable global initializer (constructor) name.
5220 If KIND=='D', return a suitable global clean-up (destructor) name. */
5223 get_file_function_name (int kind)
5230 return get_file_function_name_long (p);
5233 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
5234 The result is placed in BUFFER (which has length BIT_SIZE),
5235 with one bit in each char ('\000' or '\001').
5237 If the constructor is constant, NULL_TREE is returned.
5238 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
5241 get_set_constructor_bits (tree init, char *buffer, int bit_size)
5245 HOST_WIDE_INT domain_min
5246 = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init))), 0);
5247 tree non_const_bits = NULL_TREE;
5249 for (i = 0; i < bit_size; i++)
5252 for (vals = TREE_OPERAND (init, 1);
5253 vals != NULL_TREE; vals = TREE_CHAIN (vals))
5255 if (!host_integerp (TREE_VALUE (vals), 0)
5256 || (TREE_PURPOSE (vals) != NULL_TREE
5257 && !host_integerp (TREE_PURPOSE (vals), 0)))
5259 = tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits);
5260 else if (TREE_PURPOSE (vals) != NULL_TREE)
5262 /* Set a range of bits to ones. */
5263 HOST_WIDE_INT lo_index
5264 = tree_low_cst (TREE_PURPOSE (vals), 0) - domain_min;
5265 HOST_WIDE_INT hi_index
5266 = tree_low_cst (TREE_VALUE (vals), 0) - domain_min;
5268 if (lo_index < 0 || lo_index >= bit_size
5269 || hi_index < 0 || hi_index >= bit_size)
5271 for (; lo_index <= hi_index; lo_index++)
5272 buffer[lo_index] = 1;
5276 /* Set a single bit to one. */
5278 = tree_low_cst (TREE_VALUE (vals), 0) - domain_min;
5279 if (index < 0 || index >= bit_size)
5281 error ("invalid initializer for bit string");
5287 return non_const_bits;
5290 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
5291 The result is placed in BUFFER (which is an array of bytes).
5292 If the constructor is constant, NULL_TREE is returned.
5293 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
5296 get_set_constructor_bytes (tree init, unsigned char *buffer, int wd_size)
5299 int set_word_size = BITS_PER_UNIT;
5300 int bit_size = wd_size * set_word_size;
5302 unsigned char *bytep = buffer;
5303 char *bit_buffer = alloca (bit_size);
5304 tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
5306 for (i = 0; i < wd_size; i++)
5309 for (i = 0; i < bit_size; i++)
5313 if (BYTES_BIG_ENDIAN)
5314 *bytep |= (1 << (set_word_size - 1 - bit_pos));
5316 *bytep |= 1 << bit_pos;
5319 if (bit_pos >= set_word_size)
5320 bit_pos = 0, bytep++;
5322 return non_const_bits;
5325 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
5327 /* Complain that the tree code of NODE does not match the expected 0
5328 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
5332 tree_check_failed (const tree node, const char *file,
5333 int line, const char *function, ...)
5337 unsigned length = 0;
5340 va_start (args, function);
5341 while ((code = va_arg (args, int)))
5342 length += 4 + strlen (tree_code_name[code]);
5344 va_start (args, function);
5345 buffer = alloca (length);
5347 while ((code = va_arg (args, int)))
5351 strcpy (buffer + length, " or ");
5354 strcpy (buffer + length, tree_code_name[code]);
5355 length += strlen (tree_code_name[code]);
5359 internal_error ("tree check: expected %s, have %s in %s, at %s:%d",
5360 buffer, tree_code_name[TREE_CODE (node)],
5361 function, trim_filename (file), line);
5364 /* Complain that the tree code of NODE does match the expected 0
5365 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
5369 tree_not_check_failed (const tree node, const char *file,
5370 int line, const char *function, ...)
5374 unsigned length = 0;
5377 va_start (args, function);
5378 while ((code = va_arg (args, int)))
5379 length += 4 + strlen (tree_code_name[code]);
5381 va_start (args, function);
5382 buffer = alloca (length);
5384 while ((code = va_arg (args, int)))
5388 strcpy (buffer + length, " or ");
5391 strcpy (buffer + length, tree_code_name[code]);
5392 length += strlen (tree_code_name[code]);
5396 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
5397 buffer, tree_code_name[TREE_CODE (node)],
5398 function, trim_filename (file), line);
5401 /* Similar to tree_check_failed, except that we check for a class of tree
5402 code, given in CL. */
5405 tree_class_check_failed (const tree node, int cl, const char *file,
5406 int line, const char *function)
5409 ("tree check: expected class '%c', have '%c' (%s) in %s, at %s:%d",
5410 cl, TREE_CODE_CLASS (TREE_CODE (node)),
5411 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
5414 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
5415 (dynamically sized) vector. */
5418 tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
5419 const char *function)
5422 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
5423 idx + 1, len, function, trim_filename (file), line);
5426 /* Similar to above, except that the check is for the bounds of a PHI_NODE's
5427 (dynamically sized) vector. */
5430 phi_node_elt_check_failed (int idx, int len, const char *file, int line,
5431 const char *function)
5434 ("tree check: accessed elt %d of phi_node with %d elts in %s, at %s:%d",
5435 idx + 1, len, function, trim_filename (file), line);
5438 /* Similar to above, except that the check is for the bounds of the operand
5439 vector of an expression node. */
5442 tree_operand_check_failed (int idx, enum tree_code code, const char *file,
5443 int line, const char *function)
5446 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
5447 idx + 1, tree_code_name[code], TREE_CODE_LENGTH (code),
5448 function, trim_filename (file), line);
5450 #endif /* ENABLE_TREE_CHECKING */
5452 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
5453 and mapped to the machine mode MODE. Initialize its fields and build
5454 the information necessary for debugging output. */
5457 make_vector_type (tree innertype, int nunits, enum machine_mode mode)
5459 tree t = make_node (VECTOR_TYPE);
5461 TREE_TYPE (t) = innertype;
5462 TYPE_VECTOR_SUBPARTS (t) = nunits;
5463 TYPE_MODE (t) = mode;
5467 tree index = build_int_cst (NULL_TREE, nunits - 1);
5468 tree array = build_array_type (innertype, build_index_type (index));
5469 tree rt = make_node (RECORD_TYPE);
5471 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
5472 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
5474 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
5475 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
5476 the representation type, and we want to find that die when looking up
5477 the vector type. This is most easily achieved by making the TYPE_UID
5479 TYPE_UID (rt) = TYPE_UID (t);
5486 make_or_reuse_type (unsigned size, int unsignedp)
5488 if (size == INT_TYPE_SIZE)
5489 return unsignedp ? unsigned_type_node : integer_type_node;
5490 if (size == CHAR_TYPE_SIZE)
5491 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
5492 if (size == SHORT_TYPE_SIZE)
5493 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
5494 if (size == LONG_TYPE_SIZE)
5495 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
5496 if (size == LONG_LONG_TYPE_SIZE)
5497 return (unsignedp ? long_long_unsigned_type_node
5498 : long_long_integer_type_node);
5501 return make_unsigned_type (size);
5503 return make_signed_type (size);
5506 /* Create nodes for all integer types (and error_mark_node) using the sizes
5507 of C datatypes. The caller should call set_sizetype soon after calling
5508 this function to select one of the types as sizetype. */
5511 build_common_tree_nodes (bool signed_char, bool signed_sizetype)
5513 error_mark_node = make_node (ERROR_MARK);
5514 TREE_TYPE (error_mark_node) = error_mark_node;
5516 initialize_sizetypes (signed_sizetype);
5518 /* Define both `signed char' and `unsigned char'. */
5519 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
5520 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
5522 /* Define `char', which is like either `signed char' or `unsigned char'
5523 but not the same as either. */
5526 ? make_signed_type (CHAR_TYPE_SIZE)
5527 : make_unsigned_type (CHAR_TYPE_SIZE));
5529 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
5530 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
5531 integer_type_node = make_signed_type (INT_TYPE_SIZE);
5532 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
5533 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
5534 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
5535 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
5536 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
5538 /* Define a boolean type. This type only represents boolean values but
5539 may be larger than char depending on the value of BOOL_TYPE_SIZE.
5540 Front ends which want to override this size (i.e. Java) can redefine
5541 boolean_type_node before calling build_common_tree_nodes_2. */
5542 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
5543 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
5544 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
5545 TYPE_PRECISION (boolean_type_node) = 1;
5547 /* Fill in the rest of the sized types. Reuse existing type nodes
5549 intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
5550 intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
5551 intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
5552 intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
5553 intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
5555 unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
5556 unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
5557 unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
5558 unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
5559 unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
5561 access_public_node = get_identifier ("public");
5562 access_protected_node = get_identifier ("protected");
5563 access_private_node = get_identifier ("private");
5566 /* Call this function after calling build_common_tree_nodes and set_sizetype.
5567 It will create several other common tree nodes. */
5570 build_common_tree_nodes_2 (int short_double)
5572 /* Define these next since types below may used them. */
5573 integer_zero_node = build_int_cst (NULL_TREE, 0);
5574 integer_one_node = build_int_cst (NULL_TREE, 1);
5575 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
5577 size_zero_node = size_int (0);
5578 size_one_node = size_int (1);
5579 bitsize_zero_node = bitsize_int (0);
5580 bitsize_one_node = bitsize_int (1);
5581 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
5583 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
5584 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
5586 void_type_node = make_node (VOID_TYPE);
5587 layout_type (void_type_node);
5589 /* We are not going to have real types in C with less than byte alignment,
5590 so we might as well not have any types that claim to have it. */
5591 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
5592 TYPE_USER_ALIGN (void_type_node) = 0;
5594 null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
5595 layout_type (TREE_TYPE (null_pointer_node));
5597 ptr_type_node = build_pointer_type (void_type_node);
5599 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
5600 fileptr_type_node = ptr_type_node;
5602 float_type_node = make_node (REAL_TYPE);
5603 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
5604 layout_type (float_type_node);
5606 double_type_node = make_node (REAL_TYPE);
5608 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
5610 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
5611 layout_type (double_type_node);
5613 long_double_type_node = make_node (REAL_TYPE);
5614 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
5615 layout_type (long_double_type_node);
5617 float_ptr_type_node = build_pointer_type (float_type_node);
5618 double_ptr_type_node = build_pointer_type (double_type_node);
5619 long_double_ptr_type_node = build_pointer_type (long_double_type_node);
5620 integer_ptr_type_node = build_pointer_type (integer_type_node);
5622 complex_integer_type_node = make_node (COMPLEX_TYPE);
5623 TREE_TYPE (complex_integer_type_node) = integer_type_node;
5624 layout_type (complex_integer_type_node);
5626 complex_float_type_node = make_node (COMPLEX_TYPE);
5627 TREE_TYPE (complex_float_type_node) = float_type_node;
5628 layout_type (complex_float_type_node);
5630 complex_double_type_node = make_node (COMPLEX_TYPE);
5631 TREE_TYPE (complex_double_type_node) = double_type_node;
5632 layout_type (complex_double_type_node);
5634 complex_long_double_type_node = make_node (COMPLEX_TYPE);
5635 TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
5636 layout_type (complex_long_double_type_node);
5639 tree t = targetm.build_builtin_va_list ();
5641 /* Many back-ends define record types without setting TYPE_NAME.
5642 If we copied the record type here, we'd keep the original
5643 record type without a name. This breaks name mangling. So,
5644 don't copy record types and let c_common_nodes_and_builtins()
5645 declare the type to be __builtin_va_list. */
5646 if (TREE_CODE (t) != RECORD_TYPE)
5647 t = build_variant_type_copy (t);
5649 va_list_type_node = t;
5653 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
5656 If we requested a pointer to a vector, build up the pointers that
5657 we stripped off while looking for the inner type. Similarly for
5658 return values from functions.
5660 The argument TYPE is the top of the chain, and BOTTOM is the
5661 new type which we will point to. */
5664 reconstruct_complex_type (tree type, tree bottom)
5668 if (POINTER_TYPE_P (type))
5670 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5671 outer = build_pointer_type (inner);
5673 else if (TREE_CODE (type) == ARRAY_TYPE)
5675 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5676 outer = build_array_type (inner, TYPE_DOMAIN (type));
5678 else if (TREE_CODE (type) == FUNCTION_TYPE)
5680 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5681 outer = build_function_type (inner, TYPE_ARG_TYPES (type));
5683 else if (TREE_CODE (type) == METHOD_TYPE)
5685 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5686 outer = build_method_type_directly (TYPE_METHOD_BASETYPE (type),
5688 TYPE_ARG_TYPES (type));
5693 TYPE_READONLY (outer) = TYPE_READONLY (type);
5694 TYPE_VOLATILE (outer) = TYPE_VOLATILE (type);
5699 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
5702 build_vector_type_for_mode (tree innertype, enum machine_mode mode)
5706 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
5707 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
5708 nunits = GET_MODE_NUNITS (mode);
5710 else if (GET_MODE_CLASS (mode) == MODE_INT)
5712 /* Check that there are no leftover bits. */
5713 if (GET_MODE_BITSIZE (mode) % TREE_INT_CST_LOW (TYPE_SIZE (innertype)))
5716 nunits = GET_MODE_BITSIZE (mode)
5717 / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
5722 return make_vector_type (innertype, nunits, mode);
5725 /* Similarly, but takes the inner type and number of units, which must be
5729 build_vector_type (tree innertype, int nunits)
5731 return make_vector_type (innertype, nunits, VOIDmode);
5734 /* Given an initializer INIT, return TRUE if INIT is zero or some
5735 aggregate of zeros. Otherwise return FALSE. */
5737 initializer_zerop (tree init)
5743 switch (TREE_CODE (init))
5746 return integer_zerop (init);
5749 /* ??? Note that this is not correct for C4X float formats. There,
5750 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
5751 negative exponent. */
5752 return real_zerop (init)
5753 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
5756 return integer_zerop (init)
5757 || (real_zerop (init)
5758 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
5759 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
5762 for (elt = TREE_VECTOR_CST_ELTS (init); elt; elt = TREE_CHAIN (elt))
5763 if (!initializer_zerop (TREE_VALUE (elt)))
5768 elt = CONSTRUCTOR_ELTS (init);
5769 if (elt == NULL_TREE)
5772 /* A set is empty only if it has no elements. */
5773 if (TREE_CODE (TREE_TYPE (init)) == SET_TYPE)
5776 for (; elt ; elt = TREE_CHAIN (elt))
5777 if (! initializer_zerop (TREE_VALUE (elt)))
5787 add_var_to_bind_expr (tree bind_expr, tree var)
5789 BIND_EXPR_VARS (bind_expr)
5790 = chainon (BIND_EXPR_VARS (bind_expr), var);
5791 if (BIND_EXPR_BLOCK (bind_expr))
5792 BLOCK_VARS (BIND_EXPR_BLOCK (bind_expr))
5793 = BIND_EXPR_VARS (bind_expr);
5796 /* Build an empty statement. */
5799 build_empty_stmt (void)
5801 return build1 (NOP_EXPR, void_type_node, size_zero_node);
5805 /* Returns true if it is possible to prove that the index of
5806 an array access REF (an ARRAY_REF expression) falls into the
5810 in_array_bounds_p (tree ref)
5812 tree idx = TREE_OPERAND (ref, 1);
5815 if (TREE_CODE (idx) != INTEGER_CST)
5818 min = array_ref_low_bound (ref);
5819 max = array_ref_up_bound (ref);
5822 || TREE_CODE (min) != INTEGER_CST
5823 || TREE_CODE (max) != INTEGER_CST)
5826 if (tree_int_cst_lt (idx, min)
5827 || tree_int_cst_lt (max, idx))
5833 /* Return true if T (assumed to be a DECL) is a global variable. */
5836 is_global_var (tree t)
5838 return (TREE_STATIC (t) || DECL_EXTERNAL (t));
5841 /* Return true if T (assumed to be a DECL) must be assigned a memory
5845 needs_to_live_in_memory (tree t)
5847 return (TREE_ADDRESSABLE (t)
5848 || is_global_var (t)
5849 || (TREE_CODE (t) == RESULT_DECL
5850 && aggregate_value_p (t, current_function_decl)));
5853 /* There are situations in which a language considers record types
5854 compatible which have different field lists. Decide if two fields
5855 are compatible. It is assumed that the parent records are compatible. */
5858 fields_compatible_p (tree f1, tree f2)
5860 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1),
5861 DECL_FIELD_BIT_OFFSET (f2), OEP_ONLY_CONST))
5864 if (!operand_equal_p (DECL_FIELD_OFFSET (f1),
5865 DECL_FIELD_OFFSET (f2), OEP_ONLY_CONST))
5868 if (!lang_hooks.types_compatible_p (TREE_TYPE (f1), TREE_TYPE (f2)))
5874 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
5877 find_compatible_field (tree record, tree orig_field)
5881 for (f = TYPE_FIELDS (record); f ; f = TREE_CHAIN (f))
5882 if (TREE_CODE (f) == FIELD_DECL
5883 && fields_compatible_p (f, orig_field))
5886 /* ??? Why isn't this on the main fields list? */
5887 f = TYPE_VFIELD (record);
5888 if (f && TREE_CODE (f) == FIELD_DECL
5889 && fields_compatible_p (f, orig_field))
5892 /* ??? We should abort here, but Java appears to do Bad Things
5893 with inherited fields. */
5897 /* Return value of a constant X. */
5900 int_cst_value (tree x)
5902 unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
5903 unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
5904 bool negative = ((val >> (bits - 1)) & 1) != 0;
5906 if (bits > HOST_BITS_PER_WIDE_INT)
5910 val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1;
5912 val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1);
5917 /* Returns the greatest common divisor of A and B, which must be
5921 tree_fold_gcd (tree a, tree b)
5924 tree type = TREE_TYPE (a);
5926 #if defined ENABLE_CHECKING
5927 if (TREE_CODE (a) != INTEGER_CST
5928 || TREE_CODE (b) != INTEGER_CST)
5932 if (integer_zerop (a))
5935 if (integer_zerop (b))
5938 if (tree_int_cst_sgn (a) == -1)
5939 a = fold (build2 (MULT_EXPR, type, a,
5940 convert (type, integer_minus_one_node)));
5942 if (tree_int_cst_sgn (b) == -1)
5943 b = fold (build2 (MULT_EXPR, type, b,
5944 convert (type, integer_minus_one_node)));
5948 a_mod_b = fold (build2 (CEIL_MOD_EXPR, type, a, b));
5950 if (!TREE_INT_CST_LOW (a_mod_b)
5951 && !TREE_INT_CST_HIGH (a_mod_b))
5959 #include "gt-tree.h"