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;
400 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
401 For example, this can copy a list made of TREE_LIST nodes. */
404 copy_list (tree list)
412 head = prev = copy_node (list);
413 next = TREE_CHAIN (list);
416 TREE_CHAIN (prev) = copy_node (next);
417 prev = TREE_CHAIN (prev);
418 next = TREE_CHAIN (next);
424 /* Create an INT_CST node of TYPE and value HI:LOW. If TYPE is NULL,
425 integer_type_node is used. */
428 build_int_cst (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
435 type = integer_type_node;
437 switch (TREE_CODE (type))
441 /* Cache NULL pointer. */
450 /* Cache false or true. */
459 if (TYPE_UNSIGNED (type))
462 limit = INTEGER_SHARE_LIMIT;
463 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
469 limit = INTEGER_SHARE_LIMIT + 1;
470 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
472 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
482 if (!TYPE_CACHED_VALUES_P (type))
484 TYPE_CACHED_VALUES_P (type) = 1;
485 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
488 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
491 /* Make sure no one is clobbering the shared constant. */
492 if (TREE_TYPE (t) != type)
494 if (TREE_INT_CST_LOW (t) != low || TREE_INT_CST_HIGH (t) != hi)
500 t = make_node (INTEGER_CST);
502 TREE_INT_CST_LOW (t) = low;
503 TREE_INT_CST_HIGH (t) = hi;
504 TREE_TYPE (t) = type;
507 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
512 /* Return a new VECTOR_CST node whose type is TYPE and whose values
513 are in a list pointed by VALS. */
516 build_vector (tree type, tree vals)
518 tree v = make_node (VECTOR_CST);
519 int over1 = 0, over2 = 0;
522 TREE_VECTOR_CST_ELTS (v) = vals;
523 TREE_TYPE (v) = type;
525 /* Iterate through elements and check for overflow. */
526 for (link = vals; link; link = TREE_CHAIN (link))
528 tree value = TREE_VALUE (link);
530 over1 |= TREE_OVERFLOW (value);
531 over2 |= TREE_CONSTANT_OVERFLOW (value);
534 TREE_OVERFLOW (v) = over1;
535 TREE_CONSTANT_OVERFLOW (v) = over2;
540 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
541 are in a list pointed to by VALS. */
543 build_constructor (tree type, tree vals)
545 tree c = make_node (CONSTRUCTOR);
546 TREE_TYPE (c) = type;
547 CONSTRUCTOR_ELTS (c) = vals;
549 /* ??? May not be necessary. Mirrors what build does. */
552 TREE_SIDE_EFFECTS (c) = TREE_SIDE_EFFECTS (vals);
553 TREE_READONLY (c) = TREE_READONLY (vals);
554 TREE_CONSTANT (c) = TREE_CONSTANT (vals);
555 TREE_INVARIANT (c) = TREE_INVARIANT (vals);
561 /* Return a new REAL_CST node whose type is TYPE and value is D. */
564 build_real (tree type, REAL_VALUE_TYPE d)
570 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
571 Consider doing it via real_convert now. */
573 v = make_node (REAL_CST);
574 dp = ggc_alloc (sizeof (REAL_VALUE_TYPE));
575 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
577 TREE_TYPE (v) = type;
578 TREE_REAL_CST_PTR (v) = dp;
579 TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
583 /* Return a new REAL_CST node whose type is TYPE
584 and whose value is the integer value of the INTEGER_CST node I. */
587 real_value_from_int_cst (tree type, tree i)
591 /* Clear all bits of the real value type so that we can later do
592 bitwise comparisons to see if two values are the same. */
593 memset (&d, 0, sizeof d);
595 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
596 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
597 TYPE_UNSIGNED (TREE_TYPE (i)));
601 /* Given a tree representing an integer constant I, return a tree
602 representing the same value as a floating-point constant of type TYPE. */
605 build_real_from_int_cst (tree type, tree i)
608 int overflow = TREE_OVERFLOW (i);
610 v = build_real (type, real_value_from_int_cst (type, i));
612 TREE_OVERFLOW (v) |= overflow;
613 TREE_CONSTANT_OVERFLOW (v) |= overflow;
617 /* Return a newly constructed STRING_CST node whose value is
618 the LEN characters at STR.
619 The TREE_TYPE is not initialized. */
622 build_string (int len, const char *str)
624 tree s = make_node (STRING_CST);
626 TREE_STRING_LENGTH (s) = len;
627 TREE_STRING_POINTER (s) = ggc_alloc_string (str, len);
632 /* Return a newly constructed COMPLEX_CST node whose value is
633 specified by the real and imaginary parts REAL and IMAG.
634 Both REAL and IMAG should be constant nodes. TYPE, if specified,
635 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
638 build_complex (tree type, tree real, tree imag)
640 tree t = make_node (COMPLEX_CST);
642 TREE_REALPART (t) = real;
643 TREE_IMAGPART (t) = imag;
644 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
645 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
646 TREE_CONSTANT_OVERFLOW (t)
647 = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
651 /* Build a BINFO with LEN language slots. */
654 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
657 size_t length = (offsetof (struct tree_binfo, base_binfos)
658 + VEC_embedded_size (tree, base_binfos));
660 #ifdef GATHER_STATISTICS
661 tree_node_counts[(int) binfo_kind]++;
662 tree_node_sizes[(int) binfo_kind] += length;
665 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
667 memset (t, 0, offsetof (struct tree_binfo, base_binfos));
669 TREE_SET_CODE (t, TREE_BINFO);
671 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos);
677 /* Build a newly constructed TREE_VEC node of length LEN. */
680 make_tree_vec_stat (int len MEM_STAT_DECL)
683 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
685 #ifdef GATHER_STATISTICS
686 tree_node_counts[(int) vec_kind]++;
687 tree_node_sizes[(int) vec_kind] += length;
690 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
692 memset (t, 0, length);
694 TREE_SET_CODE (t, TREE_VEC);
695 TREE_VEC_LENGTH (t) = len;
700 /* Return 1 if EXPR is the integer constant zero or a complex constant
704 integer_zerop (tree expr)
708 return ((TREE_CODE (expr) == INTEGER_CST
709 && ! TREE_CONSTANT_OVERFLOW (expr)
710 && TREE_INT_CST_LOW (expr) == 0
711 && TREE_INT_CST_HIGH (expr) == 0)
712 || (TREE_CODE (expr) == COMPLEX_CST
713 && integer_zerop (TREE_REALPART (expr))
714 && integer_zerop (TREE_IMAGPART (expr))));
717 /* Return 1 if EXPR is the integer constant one or the corresponding
721 integer_onep (tree expr)
725 return ((TREE_CODE (expr) == INTEGER_CST
726 && ! TREE_CONSTANT_OVERFLOW (expr)
727 && TREE_INT_CST_LOW (expr) == 1
728 && TREE_INT_CST_HIGH (expr) == 0)
729 || (TREE_CODE (expr) == COMPLEX_CST
730 && integer_onep (TREE_REALPART (expr))
731 && integer_zerop (TREE_IMAGPART (expr))));
734 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
735 it contains. Likewise for the corresponding complex constant. */
738 integer_all_onesp (tree expr)
745 if (TREE_CODE (expr) == COMPLEX_CST
746 && integer_all_onesp (TREE_REALPART (expr))
747 && integer_zerop (TREE_IMAGPART (expr)))
750 else if (TREE_CODE (expr) != INTEGER_CST
751 || TREE_CONSTANT_OVERFLOW (expr))
754 uns = TYPE_UNSIGNED (TREE_TYPE (expr));
756 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
757 && TREE_INT_CST_HIGH (expr) == -1);
759 /* Note that using TYPE_PRECISION here is wrong. We care about the
760 actual bits, not the (arbitrary) range of the type. */
761 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
762 if (prec >= HOST_BITS_PER_WIDE_INT)
764 HOST_WIDE_INT high_value;
767 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
769 if (shift_amount > HOST_BITS_PER_WIDE_INT)
770 /* Can not handle precisions greater than twice the host int size. */
772 else if (shift_amount == HOST_BITS_PER_WIDE_INT)
773 /* Shifting by the host word size is undefined according to the ANSI
774 standard, so we must handle this as a special case. */
777 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
779 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
780 && TREE_INT_CST_HIGH (expr) == high_value);
783 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
786 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
790 integer_pow2p (tree expr)
793 HOST_WIDE_INT high, low;
797 if (TREE_CODE (expr) == COMPLEX_CST
798 && integer_pow2p (TREE_REALPART (expr))
799 && integer_zerop (TREE_IMAGPART (expr)))
802 if (TREE_CODE (expr) != INTEGER_CST || TREE_CONSTANT_OVERFLOW (expr))
805 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
806 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
807 high = TREE_INT_CST_HIGH (expr);
808 low = TREE_INT_CST_LOW (expr);
810 /* First clear all bits that are beyond the type's precision in case
811 we've been sign extended. */
813 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
815 else if (prec > HOST_BITS_PER_WIDE_INT)
816 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
820 if (prec < HOST_BITS_PER_WIDE_INT)
821 low &= ~((HOST_WIDE_INT) (-1) << prec);
824 if (high == 0 && low == 0)
827 return ((high == 0 && (low & (low - 1)) == 0)
828 || (low == 0 && (high & (high - 1)) == 0));
831 /* Return 1 if EXPR is an integer constant other than zero or a
832 complex constant other than zero. */
835 integer_nonzerop (tree expr)
839 return ((TREE_CODE (expr) == INTEGER_CST
840 && ! TREE_CONSTANT_OVERFLOW (expr)
841 && (TREE_INT_CST_LOW (expr) != 0
842 || TREE_INT_CST_HIGH (expr) != 0))
843 || (TREE_CODE (expr) == COMPLEX_CST
844 && (integer_nonzerop (TREE_REALPART (expr))
845 || integer_nonzerop (TREE_IMAGPART (expr)))));
848 /* Return the power of two represented by a tree node known to be a
852 tree_log2 (tree expr)
855 HOST_WIDE_INT high, low;
859 if (TREE_CODE (expr) == COMPLEX_CST)
860 return tree_log2 (TREE_REALPART (expr));
862 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
863 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
865 high = TREE_INT_CST_HIGH (expr);
866 low = TREE_INT_CST_LOW (expr);
868 /* First clear all bits that are beyond the type's precision in case
869 we've been sign extended. */
871 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
873 else if (prec > HOST_BITS_PER_WIDE_INT)
874 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
878 if (prec < HOST_BITS_PER_WIDE_INT)
879 low &= ~((HOST_WIDE_INT) (-1) << prec);
882 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
886 /* Similar, but return the largest integer Y such that 2 ** Y is less
887 than or equal to EXPR. */
890 tree_floor_log2 (tree expr)
893 HOST_WIDE_INT high, low;
897 if (TREE_CODE (expr) == COMPLEX_CST)
898 return tree_log2 (TREE_REALPART (expr));
900 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
901 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
903 high = TREE_INT_CST_HIGH (expr);
904 low = TREE_INT_CST_LOW (expr);
906 /* First clear all bits that are beyond the type's precision in case
907 we've been sign extended. Ignore if type's precision hasn't been set
908 since what we are doing is setting it. */
910 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
912 else if (prec > HOST_BITS_PER_WIDE_INT)
913 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
917 if (prec < HOST_BITS_PER_WIDE_INT)
918 low &= ~((HOST_WIDE_INT) (-1) << prec);
921 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
925 /* Return 1 if EXPR is the real constant zero. */
928 real_zerop (tree expr)
932 return ((TREE_CODE (expr) == REAL_CST
933 && ! TREE_CONSTANT_OVERFLOW (expr)
934 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
935 || (TREE_CODE (expr) == COMPLEX_CST
936 && real_zerop (TREE_REALPART (expr))
937 && real_zerop (TREE_IMAGPART (expr))));
940 /* Return 1 if EXPR is the real constant one in real or complex form. */
943 real_onep (tree expr)
947 return ((TREE_CODE (expr) == REAL_CST
948 && ! TREE_CONSTANT_OVERFLOW (expr)
949 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
950 || (TREE_CODE (expr) == COMPLEX_CST
951 && real_onep (TREE_REALPART (expr))
952 && real_zerop (TREE_IMAGPART (expr))));
955 /* Return 1 if EXPR is the real constant two. */
958 real_twop (tree expr)
962 return ((TREE_CODE (expr) == REAL_CST
963 && ! TREE_CONSTANT_OVERFLOW (expr)
964 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
965 || (TREE_CODE (expr) == COMPLEX_CST
966 && real_twop (TREE_REALPART (expr))
967 && real_zerop (TREE_IMAGPART (expr))));
970 /* Return 1 if EXPR is the real constant minus one. */
973 real_minus_onep (tree expr)
977 return ((TREE_CODE (expr) == REAL_CST
978 && ! TREE_CONSTANT_OVERFLOW (expr)
979 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1))
980 || (TREE_CODE (expr) == COMPLEX_CST
981 && real_minus_onep (TREE_REALPART (expr))
982 && real_zerop (TREE_IMAGPART (expr))));
985 /* Nonzero if EXP is a constant or a cast of a constant. */
988 really_constant_p (tree exp)
990 /* This is not quite the same as STRIP_NOPS. It does more. */
991 while (TREE_CODE (exp) == NOP_EXPR
992 || TREE_CODE (exp) == CONVERT_EXPR
993 || TREE_CODE (exp) == NON_LVALUE_EXPR)
994 exp = TREE_OPERAND (exp, 0);
995 return TREE_CONSTANT (exp);
998 /* Return first list element whose TREE_VALUE is ELEM.
999 Return 0 if ELEM is not in LIST. */
1002 value_member (tree elem, tree list)
1006 if (elem == TREE_VALUE (list))
1008 list = TREE_CHAIN (list);
1013 /* Return first list element whose TREE_PURPOSE is ELEM.
1014 Return 0 if ELEM is not in LIST. */
1017 purpose_member (tree elem, tree list)
1021 if (elem == TREE_PURPOSE (list))
1023 list = TREE_CHAIN (list);
1028 /* Return nonzero if ELEM is part of the chain CHAIN. */
1031 chain_member (tree elem, tree chain)
1037 chain = TREE_CHAIN (chain);
1043 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1044 We expect a null pointer to mark the end of the chain.
1045 This is the Lisp primitive `length'. */
1048 list_length (tree t)
1051 #ifdef ENABLE_TREE_CHECKING
1059 #ifdef ENABLE_TREE_CHECKING
1071 /* Returns the number of FIELD_DECLs in TYPE. */
1074 fields_length (tree type)
1076 tree t = TYPE_FIELDS (type);
1079 for (; t; t = TREE_CHAIN (t))
1080 if (TREE_CODE (t) == FIELD_DECL)
1086 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1087 by modifying the last node in chain 1 to point to chain 2.
1088 This is the Lisp primitive `nconc'. */
1091 chainon (tree op1, tree op2)
1100 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1102 TREE_CHAIN (t1) = op2;
1104 #ifdef ENABLE_TREE_CHECKING
1107 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1109 abort (); /* Circularity created. */
1116 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1119 tree_last (tree chain)
1123 while ((next = TREE_CHAIN (chain)))
1128 /* Reverse the order of elements in the chain T,
1129 and return the new head of the chain (old last element). */
1134 tree prev = 0, decl, next;
1135 for (decl = t; decl; decl = next)
1137 next = TREE_CHAIN (decl);
1138 TREE_CHAIN (decl) = prev;
1144 /* Return a newly created TREE_LIST node whose
1145 purpose and value fields are PARM and VALUE. */
1148 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
1150 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
1151 TREE_PURPOSE (t) = parm;
1152 TREE_VALUE (t) = value;
1156 /* Return a newly created TREE_LIST node whose
1157 purpose and value fields are PURPOSE and VALUE
1158 and whose TREE_CHAIN is CHAIN. */
1161 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
1165 node = ggc_alloc_zone_stat (sizeof (struct tree_list),
1166 tree_zone PASS_MEM_STAT);
1168 memset (node, 0, sizeof (struct tree_common));
1170 #ifdef GATHER_STATISTICS
1171 tree_node_counts[(int) x_kind]++;
1172 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
1175 TREE_SET_CODE (node, TREE_LIST);
1176 TREE_CHAIN (node) = chain;
1177 TREE_PURPOSE (node) = purpose;
1178 TREE_VALUE (node) = value;
1183 /* Return the size nominally occupied by an object of type TYPE
1184 when it resides in memory. The value is measured in units of bytes,
1185 and its data type is that normally used for type sizes
1186 (which is the first type created by make_signed_type or
1187 make_unsigned_type). */
1190 size_in_bytes (tree type)
1194 if (type == error_mark_node)
1195 return integer_zero_node;
1197 type = TYPE_MAIN_VARIANT (type);
1198 t = TYPE_SIZE_UNIT (type);
1202 lang_hooks.types.incomplete_type_error (NULL_TREE, type);
1203 return size_zero_node;
1206 if (TREE_CODE (t) == INTEGER_CST)
1207 t = force_fit_type (t, 0, false, false);
1212 /* Return the size of TYPE (in bytes) as a wide integer
1213 or return -1 if the size can vary or is larger than an integer. */
1216 int_size_in_bytes (tree type)
1220 if (type == error_mark_node)
1223 type = TYPE_MAIN_VARIANT (type);
1224 t = TYPE_SIZE_UNIT (type);
1226 || TREE_CODE (t) != INTEGER_CST
1227 || TREE_OVERFLOW (t)
1228 || TREE_INT_CST_HIGH (t) != 0
1229 /* If the result would appear negative, it's too big to represent. */
1230 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
1233 return TREE_INT_CST_LOW (t);
1236 /* Return the bit position of FIELD, in bits from the start of the record.
1237 This is a tree of type bitsizetype. */
1240 bit_position (tree field)
1242 return bit_from_pos (DECL_FIELD_OFFSET (field),
1243 DECL_FIELD_BIT_OFFSET (field));
1246 /* Likewise, but return as an integer. Abort if it cannot be represented
1247 in that way (since it could be a signed value, we don't have the option
1248 of returning -1 like int_size_in_byte can. */
1251 int_bit_position (tree field)
1253 return tree_low_cst (bit_position (field), 0);
1256 /* Return the byte position of FIELD, in bytes from the start of the record.
1257 This is a tree of type sizetype. */
1260 byte_position (tree field)
1262 return byte_from_pos (DECL_FIELD_OFFSET (field),
1263 DECL_FIELD_BIT_OFFSET (field));
1266 /* Likewise, but return as an integer. Abort if it cannot be represented
1267 in that way (since it could be a signed value, we don't have the option
1268 of returning -1 like int_size_in_byte can. */
1271 int_byte_position (tree field)
1273 return tree_low_cst (byte_position (field), 0);
1276 /* Return the strictest alignment, in bits, that T is known to have. */
1281 unsigned int align0, align1;
1283 switch (TREE_CODE (t))
1285 case NOP_EXPR: case CONVERT_EXPR: case NON_LVALUE_EXPR:
1286 /* If we have conversions, we know that the alignment of the
1287 object must meet each of the alignments of the types. */
1288 align0 = expr_align (TREE_OPERAND (t, 0));
1289 align1 = TYPE_ALIGN (TREE_TYPE (t));
1290 return MAX (align0, align1);
1292 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
1293 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
1294 case CLEANUP_POINT_EXPR:
1295 /* These don't change the alignment of an object. */
1296 return expr_align (TREE_OPERAND (t, 0));
1299 /* The best we can do is say that the alignment is the least aligned
1301 align0 = expr_align (TREE_OPERAND (t, 1));
1302 align1 = expr_align (TREE_OPERAND (t, 2));
1303 return MIN (align0, align1);
1305 case LABEL_DECL: case CONST_DECL:
1306 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
1307 if (DECL_ALIGN (t) != 0)
1308 return DECL_ALIGN (t);
1312 return FUNCTION_BOUNDARY;
1318 /* Otherwise take the alignment from that of the type. */
1319 return TYPE_ALIGN (TREE_TYPE (t));
1322 /* Return, as a tree node, the number of elements for TYPE (which is an
1323 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1326 array_type_nelts (tree type)
1328 tree index_type, min, max;
1330 /* If they did it with unspecified bounds, then we should have already
1331 given an error about it before we got here. */
1332 if (! TYPE_DOMAIN (type))
1333 return error_mark_node;
1335 index_type = TYPE_DOMAIN (type);
1336 min = TYPE_MIN_VALUE (index_type);
1337 max = TYPE_MAX_VALUE (index_type);
1339 return (integer_zerop (min)
1341 : fold (build2 (MINUS_EXPR, TREE_TYPE (max), max, min)));
1344 /* Return true if arg is static -- a reference to an object in
1345 static storage. This is not the same as the C meaning of `static'. */
1350 switch (TREE_CODE (arg))
1353 /* Nested functions aren't static, since taking their address
1354 involves a trampoline. */
1355 return ((decl_function_context (arg) == 0 || DECL_NO_STATIC_CHAIN (arg))
1356 && ! DECL_NON_ADDR_CONST_P (arg));
1359 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
1360 && ! DECL_THREAD_LOCAL (arg)
1361 && ! DECL_NON_ADDR_CONST_P (arg));
1364 return TREE_STATIC (arg);
1371 /* If the thing being referenced is not a field, then it is
1372 something language specific. */
1373 if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL)
1374 return (*lang_hooks.staticp) (arg);
1376 /* If we are referencing a bitfield, we can't evaluate an
1377 ADDR_EXPR at compile time and so it isn't a constant. */
1378 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
1381 return staticp (TREE_OPERAND (arg, 0));
1387 /* This case is technically correct, but results in setting
1388 TREE_CONSTANT on ADDR_EXPRs that cannot be evaluated at
1391 return TREE_CONSTANT (TREE_OPERAND (arg, 0));
1395 case ARRAY_RANGE_REF:
1396 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
1397 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
1398 return staticp (TREE_OPERAND (arg, 0));
1403 if ((unsigned int) TREE_CODE (arg)
1404 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
1405 return lang_hooks.staticp (arg);
1411 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
1412 Do this to any expression which may be used in more than one place,
1413 but must be evaluated only once.
1415 Normally, expand_expr would reevaluate the expression each time.
1416 Calling save_expr produces something that is evaluated and recorded
1417 the first time expand_expr is called on it. Subsequent calls to
1418 expand_expr just reuse the recorded value.
1420 The call to expand_expr that generates code that actually computes
1421 the value is the first call *at compile time*. Subsequent calls
1422 *at compile time* generate code to use the saved value.
1423 This produces correct result provided that *at run time* control
1424 always flows through the insns made by the first expand_expr
1425 before reaching the other places where the save_expr was evaluated.
1426 You, the caller of save_expr, must make sure this is so.
1428 Constants, and certain read-only nodes, are returned with no
1429 SAVE_EXPR because that is safe. Expressions containing placeholders
1430 are not touched; see tree.def for an explanation of what these
1434 save_expr (tree expr)
1436 tree t = fold (expr);
1439 /* If the tree evaluates to a constant, then we don't want to hide that
1440 fact (i.e. this allows further folding, and direct checks for constants).
1441 However, a read-only object that has side effects cannot be bypassed.
1442 Since it is no problem to reevaluate literals, we just return the
1444 inner = skip_simple_arithmetic (t);
1446 if (TREE_INVARIANT (inner)
1447 || (TREE_READONLY (inner) && ! TREE_SIDE_EFFECTS (inner))
1448 || TREE_CODE (inner) == SAVE_EXPR
1449 || TREE_CODE (inner) == ERROR_MARK)
1452 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
1453 it means that the size or offset of some field of an object depends on
1454 the value within another field.
1456 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
1457 and some variable since it would then need to be both evaluated once and
1458 evaluated more than once. Front-ends must assure this case cannot
1459 happen by surrounding any such subexpressions in their own SAVE_EXPR
1460 and forcing evaluation at the proper time. */
1461 if (contains_placeholder_p (inner))
1464 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
1466 /* This expression might be placed ahead of a jump to ensure that the
1467 value was computed on both sides of the jump. So make sure it isn't
1468 eliminated as dead. */
1469 TREE_SIDE_EFFECTS (t) = 1;
1470 TREE_READONLY (t) = 1;
1471 TREE_INVARIANT (t) = 1;
1475 /* Look inside EXPR and into any simple arithmetic operations. Return
1476 the innermost non-arithmetic node. */
1479 skip_simple_arithmetic (tree expr)
1483 /* We don't care about whether this can be used as an lvalue in this
1485 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
1486 expr = TREE_OPERAND (expr, 0);
1488 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
1489 a constant, it will be more efficient to not make another SAVE_EXPR since
1490 it will allow better simplification and GCSE will be able to merge the
1491 computations if they actually occur. */
1495 if (TREE_CODE_CLASS (TREE_CODE (inner)) == '1')
1496 inner = TREE_OPERAND (inner, 0);
1497 else if (TREE_CODE_CLASS (TREE_CODE (inner)) == '2')
1499 if (TREE_INVARIANT (TREE_OPERAND (inner, 1)))
1500 inner = TREE_OPERAND (inner, 0);
1501 else if (TREE_INVARIANT (TREE_OPERAND (inner, 0)))
1502 inner = TREE_OPERAND (inner, 1);
1513 /* Returns the index of the first non-tree operand for CODE, or the number
1514 of operands if all are trees. */
1517 first_rtl_op (enum tree_code code)
1522 return TREE_CODE_LENGTH (code);
1526 /* Return which tree structure is used by T. */
1528 enum tree_node_structure_enum
1529 tree_node_structure (tree t)
1531 enum tree_code code = TREE_CODE (t);
1533 switch (TREE_CODE_CLASS (code))
1535 case 'd': return TS_DECL;
1536 case 't': return TS_TYPE;
1537 case 'r': case '<': case '1': case '2': case 'e': case 's':
1539 default: /* 'c' and 'x' */
1545 case INTEGER_CST: return TS_INT_CST;
1546 case REAL_CST: return TS_REAL_CST;
1547 case COMPLEX_CST: return TS_COMPLEX;
1548 case VECTOR_CST: return TS_VECTOR;
1549 case STRING_CST: return TS_STRING;
1551 case ERROR_MARK: return TS_COMMON;
1552 case IDENTIFIER_NODE: return TS_IDENTIFIER;
1553 case TREE_LIST: return TS_LIST;
1554 case TREE_VEC: return TS_VEC;
1555 case PHI_NODE: return TS_PHI_NODE;
1556 case SSA_NAME: return TS_SSA_NAME;
1557 case PLACEHOLDER_EXPR: return TS_COMMON;
1558 case STATEMENT_LIST: return TS_STATEMENT_LIST;
1559 case BLOCK: return TS_BLOCK;
1560 case TREE_BINFO: return TS_BINFO;
1561 case VALUE_HANDLE: return TS_VALUE_HANDLE;
1568 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
1569 or offset that depends on a field within a record. */
1572 contains_placeholder_p (tree exp)
1574 enum tree_code code;
1579 code = TREE_CODE (exp);
1580 if (code == PLACEHOLDER_EXPR)
1583 switch (TREE_CODE_CLASS (code))
1586 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
1587 position computations since they will be converted into a
1588 WITH_RECORD_EXPR involving the reference, which will assume
1589 here will be valid. */
1590 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
1593 if (code == TREE_LIST)
1594 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
1595 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
1604 /* Ignoring the first operand isn't quite right, but works best. */
1605 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
1608 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
1609 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
1610 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
1616 switch (first_rtl_op (code))
1619 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
1621 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
1622 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
1633 /* Return 1 if any part of the computation of TYPE involves a PLACEHOLDER_EXPR.
1634 This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and field
1638 type_contains_placeholder_p (tree type)
1640 /* If the size contains a placeholder or the parent type (component type in
1641 the case of arrays) type involves a placeholder, this type does. */
1642 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
1643 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
1644 || (TREE_TYPE (type) != 0
1645 && type_contains_placeholder_p (TREE_TYPE (type))))
1648 /* Now do type-specific checks. Note that the last part of the check above
1649 greatly limits what we have to do below. */
1650 switch (TREE_CODE (type))
1659 case REFERENCE_TYPE:
1667 /* Here we just check the bounds. */
1668 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
1669 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
1674 /* We're already checked the component type (TREE_TYPE), so just check
1676 return type_contains_placeholder_p (TYPE_DOMAIN (type));
1680 case QUAL_UNION_TYPE:
1682 static tree seen_types = 0;
1686 /* We have to be careful here that we don't end up in infinite
1687 recursions due to a field of a type being a pointer to that type
1688 or to a mutually-recursive type. So we store a list of record
1689 types that we've seen and see if this type is in them. To save
1690 memory, we don't use a list for just one type. Here we check
1691 whether we've seen this type before and store it if not. */
1692 if (seen_types == 0)
1694 else if (TREE_CODE (seen_types) != TREE_LIST)
1696 if (seen_types == type)
1699 seen_types = tree_cons (NULL_TREE, type,
1700 build_tree_list (NULL_TREE, seen_types));
1704 if (value_member (type, seen_types) != 0)
1707 seen_types = tree_cons (NULL_TREE, type, seen_types);
1710 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1711 if (TREE_CODE (field) == FIELD_DECL
1712 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
1713 || (TREE_CODE (type) == QUAL_UNION_TYPE
1714 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
1715 || type_contains_placeholder_p (TREE_TYPE (field))))
1721 /* Now remove us from seen_types and return the result. */
1722 if (seen_types == type)
1725 seen_types = TREE_CHAIN (seen_types);
1735 /* Return 1 if EXP contains any expressions that produce cleanups for an
1736 outer scope to deal with. Used by fold. */
1739 has_cleanups (tree exp)
1743 if (! TREE_SIDE_EFFECTS (exp))
1746 switch (TREE_CODE (exp))
1749 case WITH_CLEANUP_EXPR:
1752 case CLEANUP_POINT_EXPR:
1756 for (exp = TREE_OPERAND (exp, 1); exp; exp = TREE_CHAIN (exp))
1758 cmp = has_cleanups (TREE_VALUE (exp));
1765 return (DECL_INITIAL (DECL_EXPR_DECL (exp))
1766 && has_cleanups (DECL_INITIAL (DECL_EXPR_DECL (exp))));
1772 /* This general rule works for most tree codes. All exceptions should be
1773 handled above. If this is a language-specific tree code, we can't
1774 trust what might be in the operand, so say we don't know
1776 if ((int) TREE_CODE (exp) >= (int) LAST_AND_UNUSED_TREE_CODE)
1779 nops = first_rtl_op (TREE_CODE (exp));
1780 for (i = 0; i < nops; i++)
1781 if (TREE_OPERAND (exp, i) != 0)
1783 int type = TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, i)));
1784 if (type == 'e' || type == '<' || type == '1' || type == '2'
1785 || type == 'r' || type == 's')
1787 cmp = has_cleanups (TREE_OPERAND (exp, i));
1796 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
1797 return a tree with all occurrences of references to F in a
1798 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
1799 contains only arithmetic expressions or a CALL_EXPR with a
1800 PLACEHOLDER_EXPR occurring only in its arglist. */
1803 substitute_in_expr (tree exp, tree f, tree r)
1805 enum tree_code code = TREE_CODE (exp);
1810 /* We handle TREE_LIST and COMPONENT_REF separately. */
1811 if (code == TREE_LIST)
1813 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
1814 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
1815 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
1818 return tree_cons (TREE_PURPOSE (exp), op1, op0);
1820 else if (code == COMPONENT_REF)
1822 /* If this expression is getting a value from a PLACEHOLDER_EXPR
1823 and it is the right field, replace it with R. */
1824 for (inner = TREE_OPERAND (exp, 0);
1825 TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
1826 inner = TREE_OPERAND (inner, 0))
1828 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
1829 && TREE_OPERAND (exp, 1) == f)
1832 /* If this expression hasn't been completed let, leave it alone. */
1833 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0)
1836 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
1837 if (op0 == TREE_OPERAND (exp, 0))
1840 new = fold (build3 (COMPONENT_REF, TREE_TYPE (exp),
1841 op0, TREE_OPERAND (exp, 1), NULL_TREE));
1844 switch (TREE_CODE_CLASS (code))
1856 switch (first_rtl_op (code))
1862 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
1863 if (op0 == TREE_OPERAND (exp, 0))
1866 new = fold (build1 (code, TREE_TYPE (exp), op0));
1870 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
1871 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
1873 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
1876 new = fold (build2 (code, TREE_TYPE (exp), op0, op1));
1880 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
1881 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
1882 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
1884 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
1885 && op2 == TREE_OPERAND (exp, 2))
1888 new = fold (build3 (code, TREE_TYPE (exp), op0, op1, op2));
1900 TREE_READONLY (new) = TREE_READONLY (exp);
1904 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
1905 for it within OBJ, a tree that is an object or a chain of references. */
1908 substitute_placeholder_in_expr (tree exp, tree obj)
1910 enum tree_code code = TREE_CODE (exp);
1911 tree op0, op1, op2, op3;
1913 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
1914 in the chain of OBJ. */
1915 if (code == PLACEHOLDER_EXPR)
1917 tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
1920 for (elt = obj; elt != 0;
1921 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
1922 || TREE_CODE (elt) == COND_EXPR)
1923 ? TREE_OPERAND (elt, 1)
1924 : (TREE_CODE_CLASS (TREE_CODE (elt)) == 'r'
1925 || TREE_CODE_CLASS (TREE_CODE (elt)) == '1'
1926 || TREE_CODE_CLASS (TREE_CODE (elt)) == '2'
1927 || TREE_CODE_CLASS (TREE_CODE (elt)) == 'e')
1928 ? TREE_OPERAND (elt, 0) : 0))
1929 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
1932 for (elt = obj; elt != 0;
1933 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
1934 || TREE_CODE (elt) == COND_EXPR)
1935 ? TREE_OPERAND (elt, 1)
1936 : (TREE_CODE_CLASS (TREE_CODE (elt)) == 'r'
1937 || TREE_CODE_CLASS (TREE_CODE (elt)) == '1'
1938 || TREE_CODE_CLASS (TREE_CODE (elt)) == '2'
1939 || TREE_CODE_CLASS (TREE_CODE (elt)) == 'e')
1940 ? TREE_OPERAND (elt, 0) : 0))
1941 if (POINTER_TYPE_P (TREE_TYPE (elt))
1942 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
1944 return fold (build1 (INDIRECT_REF, need_type, elt));
1946 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
1947 survives until RTL generation, there will be an error. */
1951 /* TREE_LIST is special because we need to look at TREE_VALUE
1952 and TREE_CHAIN, not TREE_OPERANDS. */
1953 else if (code == TREE_LIST)
1955 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
1956 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
1957 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
1960 return tree_cons (TREE_PURPOSE (exp), op1, op0);
1963 switch (TREE_CODE_CLASS (code))
1976 switch (first_rtl_op (code))
1982 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
1983 if (op0 == TREE_OPERAND (exp, 0))
1986 return fold (build1 (code, TREE_TYPE (exp), op0));
1989 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
1990 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
1992 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
1995 return fold (build2 (code, TREE_TYPE (exp), op0, op1));
1998 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
1999 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2000 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2002 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2003 && op2 == TREE_OPERAND (exp, 2))
2006 return fold (build3 (code, TREE_TYPE (exp), op0, op1, op2));
2009 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2010 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2011 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2012 op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
2014 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2015 && op2 == TREE_OPERAND (exp, 2)
2016 && op3 == TREE_OPERAND (exp, 3))
2019 return fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2031 /* Stabilize a reference so that we can use it any number of times
2032 without causing its operands to be evaluated more than once.
2033 Returns the stabilized reference. This works by means of save_expr,
2034 so see the caveats in the comments about save_expr.
2036 Also allows conversion expressions whose operands are references.
2037 Any other kind of expression is returned unchanged. */
2040 stabilize_reference (tree ref)
2043 enum tree_code code = TREE_CODE (ref);
2050 /* No action is needed in this case. */
2056 case FIX_TRUNC_EXPR:
2057 case FIX_FLOOR_EXPR:
2058 case FIX_ROUND_EXPR:
2060 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2064 result = build_nt (INDIRECT_REF,
2065 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2069 result = build_nt (COMPONENT_REF,
2070 stabilize_reference (TREE_OPERAND (ref, 0)),
2071 TREE_OPERAND (ref, 1), NULL_TREE);
2075 result = build_nt (BIT_FIELD_REF,
2076 stabilize_reference (TREE_OPERAND (ref, 0)),
2077 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2078 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2082 result = build_nt (ARRAY_REF,
2083 stabilize_reference (TREE_OPERAND (ref, 0)),
2084 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2085 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2088 case ARRAY_RANGE_REF:
2089 result = build_nt (ARRAY_RANGE_REF,
2090 stabilize_reference (TREE_OPERAND (ref, 0)),
2091 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2092 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2096 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2097 it wouldn't be ignored. This matters when dealing with
2099 return stabilize_reference_1 (ref);
2101 /* If arg isn't a kind of lvalue we recognize, make no change.
2102 Caller should recognize the error for an invalid lvalue. */
2107 return error_mark_node;
2110 TREE_TYPE (result) = TREE_TYPE (ref);
2111 TREE_READONLY (result) = TREE_READONLY (ref);
2112 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2113 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2118 /* Subroutine of stabilize_reference; this is called for subtrees of
2119 references. Any expression with side-effects must be put in a SAVE_EXPR
2120 to ensure that it is only evaluated once.
2122 We don't put SAVE_EXPR nodes around everything, because assigning very
2123 simple expressions to temporaries causes us to miss good opportunities
2124 for optimizations. Among other things, the opportunity to fold in the
2125 addition of a constant into an addressing mode often gets lost, e.g.
2126 "y[i+1] += x;". In general, we take the approach that we should not make
2127 an assignment unless we are forced into it - i.e., that any non-side effect
2128 operator should be allowed, and that cse should take care of coalescing
2129 multiple utterances of the same expression should that prove fruitful. */
2132 stabilize_reference_1 (tree e)
2135 enum tree_code code = TREE_CODE (e);
2137 /* We cannot ignore const expressions because it might be a reference
2138 to a const array but whose index contains side-effects. But we can
2139 ignore things that are actual constant or that already have been
2140 handled by this function. */
2142 if (TREE_INVARIANT (e))
2145 switch (TREE_CODE_CLASS (code))
2154 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2155 so that it will only be evaluated once. */
2156 /* The reference (r) and comparison (<) classes could be handled as
2157 below, but it is generally faster to only evaluate them once. */
2158 if (TREE_SIDE_EFFECTS (e))
2159 return save_expr (e);
2163 /* Constants need no processing. In fact, we should never reach
2168 /* Division is slow and tends to be compiled with jumps,
2169 especially the division by powers of 2 that is often
2170 found inside of an array reference. So do it just once. */
2171 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
2172 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
2173 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
2174 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
2175 return save_expr (e);
2176 /* Recursively stabilize each operand. */
2177 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
2178 stabilize_reference_1 (TREE_OPERAND (e, 1)));
2182 /* Recursively stabilize each operand. */
2183 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
2190 TREE_TYPE (result) = TREE_TYPE (e);
2191 TREE_READONLY (result) = TREE_READONLY (e);
2192 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
2193 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
2194 TREE_INVARIANT (result) = 1;
2199 /* Low-level constructors for expressions. */
2201 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
2202 TREE_INVARIANT, and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
2205 recompute_tree_invarant_for_addr_expr (tree t)
2208 bool tc = true, ti = true, se = false;
2210 /* We started out assuming this address is both invariant and constant, but
2211 does not have side effects. Now go down any handled components and see if
2212 any of them involve offsets that are either non-constant or non-invariant.
2213 Also check for side-effects.
2215 ??? Note that this code makes no attempt to deal with the case where
2216 taking the address of something causes a copy due to misalignment. */
2218 #define UPDATE_TITCSE(NODE) \
2219 do { tree _node = (NODE); \
2220 if (_node && !TREE_INVARIANT (_node)) ti = false; \
2221 if (_node && !TREE_CONSTANT (_node)) tc = false; \
2222 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
2224 for (node = TREE_OPERAND (t, 0); handled_component_p (node);
2225 node = TREE_OPERAND (node, 0))
2227 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
2228 array reference (probably made temporarily by the G++ front end),
2229 so ignore all the operands. */
2230 if ((TREE_CODE (node) == ARRAY_REF
2231 || TREE_CODE (node) == ARRAY_RANGE_REF)
2232 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
2234 UPDATE_TITCSE (TREE_OPERAND (node, 1));
2235 UPDATE_TITCSE (array_ref_low_bound (node));
2236 UPDATE_TITCSE (array_ref_element_size (node));
2238 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
2239 FIELD_DECL, apparently. The G++ front end can put something else
2240 there, at least temporarily. */
2241 else if (TREE_CODE (node) == COMPONENT_REF
2242 && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
2243 UPDATE_TITCSE (component_ref_field_offset (node));
2244 else if (TREE_CODE (node) == BIT_FIELD_REF)
2245 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2248 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
2249 it. If it's a decl, it's invariant and constant if the decl is static.
2250 It's also invariant if it's a decl in the current function. (Taking the
2251 address of a volatile variable is not volatile.) If it's a constant,
2252 the address is both invariant and constant. Otherwise it's neither. */
2253 if (TREE_CODE (node) == INDIRECT_REF)
2254 UPDATE_TITCSE (node);
2255 else if (DECL_P (node))
2259 else if (decl_function_context (node) == current_function_decl)
2264 else if (TREE_CODE_CLASS (TREE_CODE (node)) == 'c')
2269 se |= TREE_SIDE_EFFECTS (node);
2272 TREE_CONSTANT (t) = tc;
2273 TREE_INVARIANT (t) = ti;
2274 TREE_SIDE_EFFECTS (t) = se;
2275 #undef UPDATE_TITCSE
2278 /* Build an expression of code CODE, data type TYPE, and operands as
2279 specified. Expressions and reference nodes can be created this way.
2280 Constants, decls, types and misc nodes cannot be.
2282 We define 5 non-variadic functions, from 0 to 4 arguments. This is
2283 enough for all extant tree codes. These functions can be called
2284 directly (preferably!), but can also be obtained via GCC preprocessor
2285 magic within the build macro. */
2288 build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
2292 #ifdef ENABLE_CHECKING
2293 if (TREE_CODE_LENGTH (code) != 0)
2297 t = make_node_stat (code PASS_MEM_STAT);
2304 build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL)
2306 int length = sizeof (struct tree_exp);
2307 #ifdef GATHER_STATISTICS
2308 tree_node_kind kind;
2312 #ifdef GATHER_STATISTICS
2313 switch (TREE_CODE_CLASS (code))
2315 case 's': /* an expression with side effects */
2318 case 'r': /* a reference */
2326 tree_node_counts[(int) kind]++;
2327 tree_node_sizes[(int) kind] += length;
2330 #ifdef ENABLE_CHECKING
2331 if (TREE_CODE_LENGTH (code) != 1)
2333 #endif /* ENABLE_CHECKING */
2335 t = ggc_alloc_zone_stat (length, tree_zone PASS_MEM_STAT);
2337 memset (t, 0, sizeof (struct tree_common));
2339 TREE_SET_CODE (t, code);
2341 TREE_TYPE (t) = type;
2342 #ifdef USE_MAPPED_LOCATION
2343 SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
2345 SET_EXPR_LOCUS (t, NULL);
2347 TREE_COMPLEXITY (t) = 0;
2348 TREE_OPERAND (t, 0) = node;
2349 TREE_BLOCK (t) = NULL_TREE;
2350 if (node && !TYPE_P (node) && first_rtl_op (code) != 0)
2352 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
2353 TREE_READONLY (t) = TREE_READONLY (node);
2356 if (TREE_CODE_CLASS (code) == 's')
2357 TREE_SIDE_EFFECTS (t) = 1;
2363 case PREDECREMENT_EXPR:
2364 case PREINCREMENT_EXPR:
2365 case POSTDECREMENT_EXPR:
2366 case POSTINCREMENT_EXPR:
2367 /* All of these have side-effects, no matter what their
2369 TREE_SIDE_EFFECTS (t) = 1;
2370 TREE_READONLY (t) = 0;
2374 /* Whether a dereference is readonly has nothing to do with whether
2375 its operand is readonly. */
2376 TREE_READONLY (t) = 0;
2381 recompute_tree_invarant_for_addr_expr (t);
2385 if (TREE_CODE_CLASS (code) == '1' && node && !TYPE_P (node)
2386 && TREE_CONSTANT (node))
2387 TREE_CONSTANT (t) = 1;
2388 if (TREE_CODE_CLASS (code) == '1' && node && TREE_INVARIANT (node))
2389 TREE_INVARIANT (t) = 1;
2390 if (TREE_CODE_CLASS (code) == 'r' && node && TREE_THIS_VOLATILE (node))
2391 TREE_THIS_VOLATILE (t) = 1;
2398 #define PROCESS_ARG(N) \
2400 TREE_OPERAND (t, N) = arg##N; \
2401 if (arg##N &&!TYPE_P (arg##N) && fro > N) \
2403 if (TREE_SIDE_EFFECTS (arg##N)) \
2405 if (!TREE_READONLY (arg##N)) \
2407 if (!TREE_CONSTANT (arg##N)) \
2409 if (!TREE_INVARIANT (arg##N)) \
2415 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
2417 bool constant, read_only, side_effects, invariant;
2421 #ifdef ENABLE_CHECKING
2422 if (TREE_CODE_LENGTH (code) != 2)
2426 t = make_node_stat (code PASS_MEM_STAT);
2429 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
2430 result based on those same flags for the arguments. But if the
2431 arguments aren't really even `tree' expressions, we shouldn't be trying
2433 fro = first_rtl_op (code);
2435 /* Expressions without side effects may be constant if their
2436 arguments are as well. */
2437 constant = (TREE_CODE_CLASS (code) == '<'
2438 || TREE_CODE_CLASS (code) == '2');
2440 side_effects = TREE_SIDE_EFFECTS (t);
2441 invariant = constant;
2446 TREE_READONLY (t) = read_only;
2447 TREE_CONSTANT (t) = constant;
2448 TREE_INVARIANT (t) = invariant;
2449 TREE_SIDE_EFFECTS (t) = side_effects;
2450 TREE_THIS_VOLATILE (t)
2451 = TREE_CODE_CLASS (code) == 'r' && arg0 && TREE_THIS_VOLATILE (arg0);
2457 build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
2458 tree arg2 MEM_STAT_DECL)
2460 bool constant, read_only, side_effects, invariant;
2464 #ifdef ENABLE_CHECKING
2465 if (TREE_CODE_LENGTH (code) != 3)
2469 t = make_node_stat (code PASS_MEM_STAT);
2472 fro = first_rtl_op (code);
2474 side_effects = TREE_SIDE_EFFECTS (t);
2480 if (code == CALL_EXPR && !side_effects)
2485 /* Calls have side-effects, except those to const or
2487 i = call_expr_flags (t);
2488 if (!(i & (ECF_CONST | ECF_PURE)))
2491 /* And even those have side-effects if their arguments do. */
2492 else for (node = arg1; node; node = TREE_CHAIN (node))
2493 if (TREE_SIDE_EFFECTS (TREE_VALUE (node)))
2500 TREE_SIDE_EFFECTS (t) = side_effects;
2501 TREE_THIS_VOLATILE (t)
2502 = TREE_CODE_CLASS (code) == 'r' && arg0 && TREE_THIS_VOLATILE (arg0);
2508 build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
2509 tree arg2, tree arg3 MEM_STAT_DECL)
2511 bool constant, read_only, side_effects, invariant;
2515 #ifdef ENABLE_CHECKING
2516 if (TREE_CODE_LENGTH (code) != 4)
2520 t = make_node_stat (code PASS_MEM_STAT);
2523 fro = first_rtl_op (code);
2525 side_effects = TREE_SIDE_EFFECTS (t);
2532 TREE_SIDE_EFFECTS (t) = side_effects;
2533 TREE_THIS_VOLATILE (t)
2534 = TREE_CODE_CLASS (code) == 'r' && arg0 && TREE_THIS_VOLATILE (arg0);
2539 /* Backup definition for non-gcc build compilers. */
2542 (build) (enum tree_code code, tree tt, ...)
2544 tree t, arg0, arg1, arg2, arg3;
2545 int length = TREE_CODE_LENGTH (code);
2552 t = build0 (code, tt);
2555 arg0 = va_arg (p, tree);
2556 t = build1 (code, tt, arg0);
2559 arg0 = va_arg (p, tree);
2560 arg1 = va_arg (p, tree);
2561 t = build2 (code, tt, arg0, arg1);
2564 arg0 = va_arg (p, tree);
2565 arg1 = va_arg (p, tree);
2566 arg2 = va_arg (p, tree);
2567 t = build3 (code, tt, arg0, arg1, arg2);
2570 arg0 = va_arg (p, tree);
2571 arg1 = va_arg (p, tree);
2572 arg2 = va_arg (p, tree);
2573 arg3 = va_arg (p, tree);
2574 t = build4 (code, tt, arg0, arg1, arg2, arg3);
2584 /* Similar except don't specify the TREE_TYPE
2585 and leave the TREE_SIDE_EFFECTS as 0.
2586 It is permissible for arguments to be null,
2587 or even garbage if their values do not matter. */
2590 build_nt (enum tree_code code, ...)
2599 t = make_node (code);
2600 length = TREE_CODE_LENGTH (code);
2602 for (i = 0; i < length; i++)
2603 TREE_OPERAND (t, i) = va_arg (p, tree);
2609 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2610 We do NOT enter this node in any sort of symbol table.
2612 layout_decl is used to set up the decl's storage layout.
2613 Other slots are initialized to 0 or null pointers. */
2616 build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL)
2620 t = make_node_stat (code PASS_MEM_STAT);
2622 /* if (type == error_mark_node)
2623 type = integer_type_node; */
2624 /* That is not done, deliberately, so that having error_mark_node
2625 as the type can suppress useless errors in the use of this variable. */
2627 DECL_NAME (t) = name;
2628 TREE_TYPE (t) = type;
2630 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
2632 else if (code == FUNCTION_DECL)
2633 DECL_MODE (t) = FUNCTION_MODE;
2635 /* Set default visibility to whatever the user supplied with
2636 visibility_specified depending on #pragma GCC visibility. */
2637 DECL_VISIBILITY (t) = default_visibility;
2638 DECL_VISIBILITY_SPECIFIED (t) = visibility_options.inpragma;
2643 /* BLOCK nodes are used to represent the structure of binding contours
2644 and declarations, once those contours have been exited and their contents
2645 compiled. This information is used for outputting debugging info. */
2648 build_block (tree vars, tree tags ATTRIBUTE_UNUSED, tree subblocks,
2649 tree supercontext, tree chain)
2651 tree block = make_node (BLOCK);
2653 BLOCK_VARS (block) = vars;
2654 BLOCK_SUBBLOCKS (block) = subblocks;
2655 BLOCK_SUPERCONTEXT (block) = supercontext;
2656 BLOCK_CHAIN (block) = chain;
2660 #if 1 /* ! defined(USE_MAPPED_LOCATION) */
2661 /* ??? gengtype doesn't handle conditionals */
2662 static GTY(()) tree last_annotated_node;
2665 #ifdef USE_MAPPED_LOCATION
2668 expand_location (source_location loc)
2670 expanded_location xloc;
2671 if (loc == 0) { xloc.file = NULL; xloc.line = 0; xloc.column = 0; }
2674 const struct line_map *map = linemap_lookup (&line_table, loc);
2675 xloc.file = map->to_file;
2676 xloc.line = SOURCE_LINE (map, loc);
2677 xloc.column = SOURCE_COLUMN (map, loc);
2684 /* Record the exact location where an expression or an identifier were
2688 annotate_with_file_line (tree node, const char *file, int line)
2690 /* Roughly one percent of the calls to this function are to annotate
2691 a node with the same information already attached to that node!
2692 Just return instead of wasting memory. */
2693 if (EXPR_LOCUS (node)
2694 && (EXPR_FILENAME (node) == file
2695 || ! strcmp (EXPR_FILENAME (node), file))
2696 && EXPR_LINENO (node) == line)
2698 last_annotated_node = node;
2702 /* In heavily macroized code (such as GCC itself) this single
2703 entry cache can reduce the number of allocations by more
2705 if (last_annotated_node
2706 && EXPR_LOCUS (last_annotated_node)
2707 && (EXPR_FILENAME (last_annotated_node) == file
2708 || ! strcmp (EXPR_FILENAME (last_annotated_node), file))
2709 && EXPR_LINENO (last_annotated_node) == line)
2711 SET_EXPR_LOCUS (node, EXPR_LOCUS (last_annotated_node));
2715 SET_EXPR_LOCUS (node, ggc_alloc (sizeof (location_t)));
2716 EXPR_LINENO (node) = line;
2717 EXPR_FILENAME (node) = file;
2718 last_annotated_node = node;
2722 annotate_with_locus (tree node, location_t locus)
2724 annotate_with_file_line (node, locus.file, locus.line);
2728 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
2732 build_decl_attribute_variant (tree ddecl, tree attribute)
2734 DECL_ATTRIBUTES (ddecl) = attribute;
2738 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
2741 Record such modified types already made so we don't make duplicates. */
2744 build_type_attribute_variant (tree ttype, tree attribute)
2746 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
2748 hashval_t hashcode = 0;
2750 enum tree_code code = TREE_CODE (ttype);
2752 ntype = copy_node (ttype);
2754 TYPE_POINTER_TO (ntype) = 0;
2755 TYPE_REFERENCE_TO (ntype) = 0;
2756 TYPE_ATTRIBUTES (ntype) = attribute;
2758 /* Create a new main variant of TYPE. */
2759 TYPE_MAIN_VARIANT (ntype) = ntype;
2760 TYPE_NEXT_VARIANT (ntype) = 0;
2761 set_type_quals (ntype, TYPE_UNQUALIFIED);
2763 hashcode = iterative_hash_object (code, hashcode);
2764 if (TREE_TYPE (ntype))
2765 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)),
2767 hashcode = attribute_hash_list (attribute, hashcode);
2769 switch (TREE_CODE (ntype))
2772 hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode);
2775 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)),
2779 hashcode = iterative_hash_object
2780 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode);
2781 hashcode = iterative_hash_object
2782 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode);
2786 unsigned int precision = TYPE_PRECISION (ntype);
2787 hashcode = iterative_hash_object (precision, hashcode);
2794 ntype = type_hash_canon (hashcode, ntype);
2795 ttype = build_qualified_type (ntype, TYPE_QUALS (ttype));
2801 /* Return nonzero if IDENT is a valid name for attribute ATTR,
2804 We try both `text' and `__text__', ATTR may be either one. */
2805 /* ??? It might be a reasonable simplification to require ATTR to be only
2806 `text'. One might then also require attribute lists to be stored in
2807 their canonicalized form. */
2810 is_attribute_p (const char *attr, tree ident)
2812 int ident_len, attr_len;
2815 if (TREE_CODE (ident) != IDENTIFIER_NODE)
2818 if (strcmp (attr, IDENTIFIER_POINTER (ident)) == 0)
2821 p = IDENTIFIER_POINTER (ident);
2822 ident_len = strlen (p);
2823 attr_len = strlen (attr);
2825 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
2829 || attr[attr_len - 2] != '_'
2830 || attr[attr_len - 1] != '_')
2832 if (ident_len == attr_len - 4
2833 && strncmp (attr + 2, p, attr_len - 4) == 0)
2838 if (ident_len == attr_len + 4
2839 && p[0] == '_' && p[1] == '_'
2840 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
2841 && strncmp (attr, p + 2, attr_len) == 0)
2848 /* Given an attribute name and a list of attributes, return a pointer to the
2849 attribute's list element if the attribute is part of the list, or NULL_TREE
2850 if not found. If the attribute appears more than once, this only
2851 returns the first occurrence; the TREE_CHAIN of the return value should
2852 be passed back in if further occurrences are wanted. */
2855 lookup_attribute (const char *attr_name, tree list)
2859 for (l = list; l; l = TREE_CHAIN (l))
2861 if (TREE_CODE (TREE_PURPOSE (l)) != IDENTIFIER_NODE)
2863 if (is_attribute_p (attr_name, TREE_PURPOSE (l)))
2870 /* Return an attribute list that is the union of a1 and a2. */
2873 merge_attributes (tree a1, tree a2)
2877 /* Either one unset? Take the set one. */
2879 if ((attributes = a1) == 0)
2882 /* One that completely contains the other? Take it. */
2884 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
2886 if (attribute_list_contained (a2, a1))
2890 /* Pick the longest list, and hang on the other list. */
2892 if (list_length (a1) < list_length (a2))
2893 attributes = a2, a2 = a1;
2895 for (; a2 != 0; a2 = TREE_CHAIN (a2))
2898 for (a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
2901 a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
2904 if (simple_cst_equal (TREE_VALUE (a), TREE_VALUE (a2)) == 1)
2909 a1 = copy_node (a2);
2910 TREE_CHAIN (a1) = attributes;
2919 /* Given types T1 and T2, merge their attributes and return
2923 merge_type_attributes (tree t1, tree t2)
2925 return merge_attributes (TYPE_ATTRIBUTES (t1),
2926 TYPE_ATTRIBUTES (t2));
2929 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
2933 merge_decl_attributes (tree olddecl, tree newdecl)
2935 return merge_attributes (DECL_ATTRIBUTES (olddecl),
2936 DECL_ATTRIBUTES (newdecl));
2939 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
2941 /* Specialization of merge_decl_attributes for various Windows targets.
2943 This handles the following situation:
2945 __declspec (dllimport) int foo;
2948 The second instance of `foo' nullifies the dllimport. */
2951 merge_dllimport_decl_attributes (tree old, tree new)
2954 int delete_dllimport_p;
2956 old = DECL_ATTRIBUTES (old);
2957 new = DECL_ATTRIBUTES (new);
2959 /* What we need to do here is remove from `old' dllimport if it doesn't
2960 appear in `new'. dllimport behaves like extern: if a declaration is
2961 marked dllimport and a definition appears later, then the object
2962 is not dllimport'd. */
2963 if (lookup_attribute ("dllimport", old) != NULL_TREE
2964 && lookup_attribute ("dllimport", new) == NULL_TREE)
2965 delete_dllimport_p = 1;
2967 delete_dllimport_p = 0;
2969 a = merge_attributes (old, new);
2971 if (delete_dllimport_p)
2975 /* Scan the list for dllimport and delete it. */
2976 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
2978 if (is_attribute_p ("dllimport", TREE_PURPOSE (t)))
2980 if (prev == NULL_TREE)
2983 TREE_CHAIN (prev) = TREE_CHAIN (t);
2992 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
2993 struct attribute_spec.handler. */
2996 handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
3001 /* These attributes may apply to structure and union types being created,
3002 but otherwise should pass to the declaration involved. */
3005 if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
3006 | (int) ATTR_FLAG_ARRAY_NEXT))
3008 *no_add_attrs = true;
3009 return tree_cons (name, args, NULL_TREE);
3011 if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
3013 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
3014 *no_add_attrs = true;
3020 /* Report error on dllimport ambiguities seen now before they cause
3022 if (is_attribute_p ("dllimport", name))
3024 /* Like MS, treat definition of dllimported variables and
3025 non-inlined functions on declaration as syntax errors. We
3026 allow the attribute for function definitions if declared
3028 if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node)
3029 && !DECL_DECLARED_INLINE_P (node))
3031 error ("%Jfunction `%D' definition is marked dllimport.", node, node);
3032 *no_add_attrs = true;
3035 else if (TREE_CODE (node) == VAR_DECL)
3037 if (DECL_INITIAL (node))
3039 error ("%Jvariable `%D' definition is marked dllimport.",
3041 *no_add_attrs = true;
3044 /* `extern' needn't be specified with dllimport.
3045 Specify `extern' now and hope for the best. Sigh. */
3046 DECL_EXTERNAL (node) = 1;
3047 /* Also, implicitly give dllimport'd variables declared within
3048 a function global scope, unless declared static. */
3049 if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
3050 TREE_PUBLIC (node) = 1;
3054 /* Report error if symbol is not accessible at global scope. */
3055 if (!TREE_PUBLIC (node)
3056 && (TREE_CODE (node) == VAR_DECL
3057 || TREE_CODE (node) == FUNCTION_DECL))
3059 error ("%Jexternal linkage required for symbol '%D' because of "
3060 "'%s' attribute.", node, node, IDENTIFIER_POINTER (name));
3061 *no_add_attrs = true;
3067 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
3069 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
3070 of the various TYPE_QUAL values. */
3073 set_type_quals (tree type, int type_quals)
3075 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
3076 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
3077 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
3080 /* Returns true iff cand is equivalent to base with type_quals. */
3083 check_qualified_type (tree cand, tree base, int type_quals)
3085 return (TYPE_QUALS (cand) == type_quals
3086 && TYPE_NAME (cand) == TYPE_NAME (base)
3087 /* Apparently this is needed for Objective-C. */
3088 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
3089 && attribute_list_equal (TYPE_ATTRIBUTES (cand),
3090 TYPE_ATTRIBUTES (base)));
3093 /* Return a version of the TYPE, qualified as indicated by the
3094 TYPE_QUALS, if one exists. If no qualified version exists yet,
3095 return NULL_TREE. */
3098 get_qualified_type (tree type, int type_quals)
3102 if (TYPE_QUALS (type) == type_quals)
3105 /* Search the chain of variants to see if there is already one there just
3106 like the one we need to have. If so, use that existing one. We must
3107 preserve the TYPE_NAME, since there is code that depends on this. */
3108 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
3109 if (check_qualified_type (t, type, type_quals))
3115 /* Like get_qualified_type, but creates the type if it does not
3116 exist. This function never returns NULL_TREE. */
3119 build_qualified_type (tree type, int type_quals)
3123 /* See if we already have the appropriate qualified variant. */
3124 t = get_qualified_type (type, type_quals);
3126 /* If not, build it. */
3129 t = build_variant_type_copy (type);
3130 set_type_quals (t, type_quals);
3136 /* Create a new distinct copy of TYPE. The new type is made its own
3140 build_distinct_type_copy (tree type)
3142 tree t = copy_node (type);
3144 if (TYPE_CACHED_VALUES_P(t))
3146 /* Do not copy the values cache. */
3147 if (TREE_CODE (t) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t))
3149 TYPE_CACHED_VALUES_P (t) = 0;
3150 TYPE_CACHED_VALUES (t) = NULL_TREE;
3153 TYPE_POINTER_TO (t) = 0;
3154 TYPE_REFERENCE_TO (t) = 0;
3156 /* Make it its own variant. */
3157 TYPE_MAIN_VARIANT (t) = t;
3158 TYPE_NEXT_VARIANT (t) = 0;
3163 /* Create a new variant of TYPE, equivalent but distinct.
3164 This is so the caller can modify it. */
3167 build_variant_type_copy (tree type)
3169 tree t, m = TYPE_MAIN_VARIANT (type);
3171 t = build_distinct_type_copy (type);
3173 /* Add the new type to the chain of variants of TYPE. */
3174 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
3175 TYPE_NEXT_VARIANT (m) = t;
3176 TYPE_MAIN_VARIANT (t) = m;
3181 /* Hashing of types so that we don't make duplicates.
3182 The entry point is `type_hash_canon'. */
3184 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
3185 with types in the TREE_VALUE slots), by adding the hash codes
3186 of the individual types. */
3189 type_hash_list (tree list, hashval_t hashcode)
3193 for (tail = list; tail; tail = TREE_CHAIN (tail))
3194 if (TREE_VALUE (tail) != error_mark_node)
3195 hashcode = iterative_hash_object (TYPE_HASH (TREE_VALUE (tail)),
3201 /* These are the Hashtable callback functions. */
3203 /* Returns true iff the types are equivalent. */
3206 type_hash_eq (const void *va, const void *vb)
3208 const struct type_hash *a = va, *b = vb;
3210 /* First test the things that are the same for all types. */
3211 if (a->hash != b->hash
3212 || TREE_CODE (a->type) != TREE_CODE (b->type)
3213 || TREE_TYPE (a->type) != TREE_TYPE (b->type)
3214 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
3215 TYPE_ATTRIBUTES (b->type))
3216 || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
3217 || TYPE_MODE (a->type) != TYPE_MODE (b->type))
3220 switch (TREE_CODE (a->type))
3226 case REFERENCE_TYPE:
3230 if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
3231 && !(TYPE_VALUES (a->type)
3232 && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
3233 && TYPE_VALUES (b->type)
3234 && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
3235 && type_list_equal (TYPE_VALUES (a->type),
3236 TYPE_VALUES (b->type))))
3239 /* ... fall through ... */
3245 return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
3246 || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
3247 TYPE_MAX_VALUE (b->type)))
3248 && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
3249 || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
3250 TYPE_MIN_VALUE (b->type))));
3253 return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
3256 return (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
3257 && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
3258 || (TYPE_ARG_TYPES (a->type)
3259 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
3260 && TYPE_ARG_TYPES (b->type)
3261 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
3262 && type_list_equal (TYPE_ARG_TYPES (a->type),
3263 TYPE_ARG_TYPES (b->type)))));
3267 return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type);
3271 case QUAL_UNION_TYPE:
3272 return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
3273 || (TYPE_FIELDS (a->type)
3274 && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
3275 && TYPE_FIELDS (b->type)
3276 && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
3277 && type_list_equal (TYPE_FIELDS (a->type),
3278 TYPE_FIELDS (b->type))));
3281 return (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
3282 || (TYPE_ARG_TYPES (a->type)
3283 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
3284 && TYPE_ARG_TYPES (b->type)
3285 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
3286 && type_list_equal (TYPE_ARG_TYPES (a->type),
3287 TYPE_ARG_TYPES (b->type))));
3294 /* Return the cached hash value. */
3297 type_hash_hash (const void *item)
3299 return ((const struct type_hash *) item)->hash;
3302 /* Look in the type hash table for a type isomorphic to TYPE.
3303 If one is found, return it. Otherwise return 0. */
3306 type_hash_lookup (hashval_t hashcode, tree type)
3308 struct type_hash *h, in;
3310 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
3311 must call that routine before comparing TYPE_ALIGNs. */
3317 h = htab_find_with_hash (type_hash_table, &in, hashcode);
3323 /* Add an entry to the type-hash-table
3324 for a type TYPE whose hash code is HASHCODE. */
3327 type_hash_add (hashval_t hashcode, tree type)
3329 struct type_hash *h;
3332 h = ggc_alloc (sizeof (struct type_hash));
3335 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
3336 *(struct type_hash **) loc = h;
3339 /* Given TYPE, and HASHCODE its hash code, return the canonical
3340 object for an identical type if one already exists.
3341 Otherwise, return TYPE, and record it as the canonical object.
3343 To use this function, first create a type of the sort you want.
3344 Then compute its hash code from the fields of the type that
3345 make it different from other similar types.
3346 Then call this function and use the value. */
3349 type_hash_canon (unsigned int hashcode, tree type)
3353 /* The hash table only contains main variants, so ensure that's what we're
3355 if (TYPE_MAIN_VARIANT (type) != type)
3358 if (!lang_hooks.types.hash_types)
3361 /* See if the type is in the hash table already. If so, return it.
3362 Otherwise, add the type. */
3363 t1 = type_hash_lookup (hashcode, type);
3366 #ifdef GATHER_STATISTICS
3367 tree_node_counts[(int) t_kind]--;
3368 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
3374 type_hash_add (hashcode, type);
3379 /* See if the data pointed to by the type hash table is marked. We consider
3380 it marked if the type is marked or if a debug type number or symbol
3381 table entry has been made for the type. This reduces the amount of
3382 debugging output and eliminates that dependency of the debug output on
3383 the number of garbage collections. */
3386 type_hash_marked_p (const void *p)
3388 tree type = ((struct type_hash *) p)->type;
3390 return ggc_marked_p (type) || TYPE_SYMTAB_POINTER (type);
3394 print_type_hash_statistics (void)
3396 fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
3397 (long) htab_size (type_hash_table),
3398 (long) htab_elements (type_hash_table),
3399 htab_collisions (type_hash_table));
3402 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
3403 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
3404 by adding the hash codes of the individual attributes. */
3407 attribute_hash_list (tree list, hashval_t hashcode)
3411 for (tail = list; tail; tail = TREE_CHAIN (tail))
3412 /* ??? Do we want to add in TREE_VALUE too? */
3413 hashcode = iterative_hash_object
3414 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail)), hashcode);
3418 /* Given two lists of attributes, return true if list l2 is
3419 equivalent to l1. */
3422 attribute_list_equal (tree l1, tree l2)
3424 return attribute_list_contained (l1, l2)
3425 && attribute_list_contained (l2, l1);
3428 /* Given two lists of attributes, return true if list L2 is
3429 completely contained within L1. */
3430 /* ??? This would be faster if attribute names were stored in a canonicalized
3431 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
3432 must be used to show these elements are equivalent (which they are). */
3433 /* ??? It's not clear that attributes with arguments will always be handled
3437 attribute_list_contained (tree l1, tree l2)
3441 /* First check the obvious, maybe the lists are identical. */
3445 /* Maybe the lists are similar. */
3446 for (t1 = l1, t2 = l2;
3448 && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
3449 && TREE_VALUE (t1) == TREE_VALUE (t2);
3450 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
3452 /* Maybe the lists are equal. */
3453 if (t1 == 0 && t2 == 0)
3456 for (; t2 != 0; t2 = TREE_CHAIN (t2))
3459 for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1);
3461 attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
3464 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) == 1)
3471 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) != 1)
3478 /* Given two lists of types
3479 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
3480 return 1 if the lists contain the same types in the same order.
3481 Also, the TREE_PURPOSEs must match. */
3484 type_list_equal (tree l1, tree l2)
3488 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
3489 if (TREE_VALUE (t1) != TREE_VALUE (t2)
3490 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
3491 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
3492 && (TREE_TYPE (TREE_PURPOSE (t1))
3493 == TREE_TYPE (TREE_PURPOSE (t2))))))
3499 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
3500 given by TYPE. If the argument list accepts variable arguments,
3501 then this function counts only the ordinary arguments. */
3504 type_num_arguments (tree type)
3509 for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
3510 /* If the function does not take a variable number of arguments,
3511 the last element in the list will have type `void'. */
3512 if (VOID_TYPE_P (TREE_VALUE (t)))
3520 /* Nonzero if integer constants T1 and T2
3521 represent the same constant value. */
3524 tree_int_cst_equal (tree t1, tree t2)
3529 if (t1 == 0 || t2 == 0)
3532 if (TREE_CODE (t1) == INTEGER_CST
3533 && TREE_CODE (t2) == INTEGER_CST
3534 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3535 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
3541 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
3542 The precise way of comparison depends on their data type. */
3545 tree_int_cst_lt (tree t1, tree t2)
3550 if (TYPE_UNSIGNED (TREE_TYPE (t1)) != TYPE_UNSIGNED (TREE_TYPE (t2)))
3552 int t1_sgn = tree_int_cst_sgn (t1);
3553 int t2_sgn = tree_int_cst_sgn (t2);
3555 if (t1_sgn < t2_sgn)
3557 else if (t1_sgn > t2_sgn)
3559 /* Otherwise, both are non-negative, so we compare them as
3560 unsigned just in case one of them would overflow a signed
3563 else if (!TYPE_UNSIGNED (TREE_TYPE (t1)))
3564 return INT_CST_LT (t1, t2);
3566 return INT_CST_LT_UNSIGNED (t1, t2);
3569 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
3572 tree_int_cst_compare (tree t1, tree t2)
3574 if (tree_int_cst_lt (t1, t2))
3576 else if (tree_int_cst_lt (t2, t1))
3582 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
3583 the host. If POS is zero, the value can be represented in a single
3584 HOST_WIDE_INT. If POS is nonzero, the value must be positive and can
3585 be represented in a single unsigned HOST_WIDE_INT. */
3588 host_integerp (tree t, int pos)
3590 return (TREE_CODE (t) == INTEGER_CST
3591 && ! TREE_OVERFLOW (t)
3592 && ((TREE_INT_CST_HIGH (t) == 0
3593 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
3594 || (! pos && TREE_INT_CST_HIGH (t) == -1
3595 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
3596 && !TYPE_UNSIGNED (TREE_TYPE (t)))
3597 || (pos && TREE_INT_CST_HIGH (t) == 0)));
3600 /* Return the HOST_WIDE_INT least significant bits of T if it is an
3601 INTEGER_CST and there is no overflow. POS is nonzero if the result must
3602 be positive. Abort if we cannot satisfy the above conditions. */
3605 tree_low_cst (tree t, int pos)
3607 if (host_integerp (t, pos))
3608 return TREE_INT_CST_LOW (t);
3613 /* Return the most significant bit of the integer constant T. */
3616 tree_int_cst_msb (tree t)
3620 unsigned HOST_WIDE_INT l;
3622 /* Note that using TYPE_PRECISION here is wrong. We care about the
3623 actual bits, not the (arbitrary) range of the type. */
3624 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
3625 rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
3626 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
3627 return (l & 1) == 1;
3630 /* Return an indication of the sign of the integer constant T.
3631 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
3632 Note that -1 will never be returned it T's type is unsigned. */
3635 tree_int_cst_sgn (tree t)
3637 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
3639 else if (TYPE_UNSIGNED (TREE_TYPE (t)))
3641 else if (TREE_INT_CST_HIGH (t) < 0)
3647 /* Compare two constructor-element-type constants. Return 1 if the lists
3648 are known to be equal; otherwise return 0. */
3651 simple_cst_list_equal (tree l1, tree l2)
3653 while (l1 != NULL_TREE && l2 != NULL_TREE)
3655 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
3658 l1 = TREE_CHAIN (l1);
3659 l2 = TREE_CHAIN (l2);
3665 /* Return truthvalue of whether T1 is the same tree structure as T2.
3666 Return 1 if they are the same.
3667 Return 0 if they are understandably different.
3668 Return -1 if either contains tree structure not understood by
3672 simple_cst_equal (tree t1, tree t2)
3674 enum tree_code code1, code2;
3680 if (t1 == 0 || t2 == 0)
3683 code1 = TREE_CODE (t1);
3684 code2 = TREE_CODE (t2);
3686 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
3688 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3689 || code2 == NON_LVALUE_EXPR)
3690 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3692 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
3695 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3696 || code2 == NON_LVALUE_EXPR)
3697 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
3705 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3706 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
3709 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3712 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3713 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3714 TREE_STRING_LENGTH (t1)));
3717 return simple_cst_list_equal (CONSTRUCTOR_ELTS (t1),
3718 CONSTRUCTOR_ELTS (t2));
3721 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3724 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3728 simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3731 /* Special case: if either target is an unallocated VAR_DECL,
3732 it means that it's going to be unified with whatever the
3733 TARGET_EXPR is really supposed to initialize, so treat it
3734 as being equivalent to anything. */
3735 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
3736 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
3737 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
3738 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
3739 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
3740 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
3743 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3748 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3750 case WITH_CLEANUP_EXPR:
3751 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3755 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
3758 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
3759 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3773 /* This general rule works for most tree codes. All exceptions should be
3774 handled above. If this is a language-specific tree code, we can't
3775 trust what might be in the operand, so say we don't know
3777 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
3780 switch (TREE_CODE_CLASS (code1))
3789 for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
3791 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
3803 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
3804 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
3805 than U, respectively. */
3808 compare_tree_int (tree t, unsigned HOST_WIDE_INT u)
3810 if (tree_int_cst_sgn (t) < 0)
3812 else if (TREE_INT_CST_HIGH (t) != 0)
3814 else if (TREE_INT_CST_LOW (t) == u)
3816 else if (TREE_INT_CST_LOW (t) < u)
3822 /* Return true if CODE represents an associative tree code. Otherwise
3825 associative_tree_code (enum tree_code code)
3844 /* Return true if CODE represents an commutative tree code. Otherwise
3847 commutative_tree_code (enum tree_code code)
3860 case UNORDERED_EXPR:
3864 case TRUTH_AND_EXPR:
3865 case TRUTH_XOR_EXPR:
3875 /* Generate a hash value for an expression. This can be used iteratively
3876 by passing a previous result as the "val" argument.
3878 This function is intended to produce the same hash for expressions which
3879 would compare equal using operand_equal_p. */
3882 iterative_hash_expr (tree t, hashval_t val)
3885 enum tree_code code;
3889 return iterative_hash_object (t, val);
3891 code = TREE_CODE (t);
3892 class = TREE_CODE_CLASS (code);
3895 || TREE_CODE (t) == VALUE_HANDLE)
3897 /* Decls we can just compare by pointer. */
3898 val = iterative_hash_object (t, val);
3900 else if (class == 'c')
3902 /* Alas, constants aren't shared, so we can't rely on pointer
3904 if (code == INTEGER_CST)
3906 val = iterative_hash_object (TREE_INT_CST_LOW (t), val);
3907 val = iterative_hash_object (TREE_INT_CST_HIGH (t), val);
3909 else if (code == REAL_CST)
3911 unsigned int val2 = real_hash (TREE_REAL_CST_PTR (t));
3913 val = iterative_hash (&val2, sizeof (unsigned int), val);
3915 else if (code == STRING_CST)
3916 val = iterative_hash (TREE_STRING_POINTER (t),
3917 TREE_STRING_LENGTH (t), val);
3918 else if (code == COMPLEX_CST)
3920 val = iterative_hash_expr (TREE_REALPART (t), val);
3921 val = iterative_hash_expr (TREE_IMAGPART (t), val);
3923 else if (code == VECTOR_CST)
3924 val = iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val);
3928 else if (IS_EXPR_CODE_CLASS (class))
3930 val = iterative_hash_object (code, val);
3932 /* Don't hash the type, that can lead to having nodes which
3933 compare equal according to operand_equal_p, but which
3934 have different hash codes. */
3935 if (code == NOP_EXPR
3936 || code == CONVERT_EXPR
3937 || code == NON_LVALUE_EXPR)
3939 /* Make sure to include signness in the hash computation. */
3940 val += TYPE_UNSIGNED (TREE_TYPE (t));
3941 val = iterative_hash_expr (TREE_OPERAND (t, 0), val);
3944 if (commutative_tree_code (code))
3946 /* It's a commutative expression. We want to hash it the same
3947 however it appears. We do this by first hashing both operands
3948 and then rehashing based on the order of their independent
3950 hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0);
3951 hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0);
3955 t = one, one = two, two = t;
3957 val = iterative_hash_object (one, val);
3958 val = iterative_hash_object (two, val);
3961 for (i = first_rtl_op (code) - 1; i >= 0; --i)
3962 val = iterative_hash_expr (TREE_OPERAND (t, i), val);
3964 else if (code == TREE_LIST)
3966 /* A list of expressions, for a CALL_EXPR or as the elements of a
3968 for (; t; t = TREE_CHAIN (t))
3969 val = iterative_hash_expr (TREE_VALUE (t), val);
3971 else if (code == SSA_NAME)
3973 val = iterative_hash_object (SSA_NAME_VERSION (t), val);
3974 val = iterative_hash_expr (SSA_NAME_VAR (t), val);
3982 /* Constructors for pointer, array and function types.
3983 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
3984 constructed by language-dependent code, not here.) */
3986 /* Construct, lay out and return the type of pointers to TO_TYPE with
3987 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
3988 reference all of memory. If such a type has already been
3989 constructed, reuse it. */
3992 build_pointer_type_for_mode (tree to_type, enum machine_mode mode,
3997 /* In some cases, languages will have things that aren't a POINTER_TYPE
3998 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
3999 In that case, return that type without regard to the rest of our
4002 ??? This is a kludge, but consistent with the way this function has
4003 always operated and there doesn't seem to be a good way to avoid this
4005 if (TYPE_POINTER_TO (to_type) != 0
4006 && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
4007 return TYPE_POINTER_TO (to_type);
4009 /* First, if we already have a type for pointers to TO_TYPE and it's
4010 the proper mode, use it. */
4011 for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
4012 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
4015 t = make_node (POINTER_TYPE);
4017 TREE_TYPE (t) = to_type;
4018 TYPE_MODE (t) = mode;
4019 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
4020 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
4021 TYPE_POINTER_TO (to_type) = t;
4023 /* Lay out the type. This function has many callers that are concerned
4024 with expression-construction, and this simplifies them all. */
4030 /* By default build pointers in ptr_mode. */
4033 build_pointer_type (tree to_type)
4035 return build_pointer_type_for_mode (to_type, ptr_mode, false);
4038 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
4041 build_reference_type_for_mode (tree to_type, enum machine_mode mode,
4046 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
4047 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
4048 In that case, return that type without regard to the rest of our
4051 ??? This is a kludge, but consistent with the way this function has
4052 always operated and there doesn't seem to be a good way to avoid this
4054 if (TYPE_REFERENCE_TO (to_type) != 0
4055 && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
4056 return TYPE_REFERENCE_TO (to_type);
4058 /* First, if we already have a type for pointers to TO_TYPE and it's
4059 the proper mode, use it. */
4060 for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
4061 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
4064 t = make_node (REFERENCE_TYPE);
4066 TREE_TYPE (t) = to_type;
4067 TYPE_MODE (t) = mode;
4068 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
4069 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
4070 TYPE_REFERENCE_TO (to_type) = t;
4078 /* Build the node for the type of references-to-TO_TYPE by default
4082 build_reference_type (tree to_type)
4084 return build_reference_type_for_mode (to_type, ptr_mode, false);
4087 /* Build a type that is compatible with t but has no cv quals anywhere
4090 const char *const *const * -> char ***. */
4093 build_type_no_quals (tree t)
4095 switch (TREE_CODE (t))
4098 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
4100 TYPE_REF_CAN_ALIAS_ALL (t));
4101 case REFERENCE_TYPE:
4103 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
4105 TYPE_REF_CAN_ALIAS_ALL (t));
4107 return TYPE_MAIN_VARIANT (t);
4111 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
4112 MAXVAL should be the maximum value in the domain
4113 (one less than the length of the array).
4115 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
4116 We don't enforce this limit, that is up to caller (e.g. language front end).
4117 The limit exists because the result is a signed type and we don't handle
4118 sizes that use more than one HOST_WIDE_INT. */
4121 build_index_type (tree maxval)
4123 tree itype = make_node (INTEGER_TYPE);
4125 TREE_TYPE (itype) = sizetype;
4126 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
4127 TYPE_MIN_VALUE (itype) = size_zero_node;
4128 TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
4129 TYPE_MODE (itype) = TYPE_MODE (sizetype);
4130 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
4131 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
4132 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
4133 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
4135 if (host_integerp (maxval, 1))
4136 return type_hash_canon (tree_low_cst (maxval, 1), itype);
4141 /* Builds a signed or unsigned integer type of precision PRECISION.
4142 Used for C bitfields whose precision does not match that of
4143 built-in target types. */
4145 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
4148 tree itype = make_node (INTEGER_TYPE);
4150 TYPE_PRECISION (itype) = precision;
4153 fixup_unsigned_type (itype);
4155 fixup_signed_type (itype);
4157 if (host_integerp (TYPE_MAX_VALUE (itype), 1))
4158 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype);
4163 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
4164 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
4165 low bound LOWVAL and high bound HIGHVAL.
4166 if TYPE==NULL_TREE, sizetype is used. */
4169 build_range_type (tree type, tree lowval, tree highval)
4171 tree itype = make_node (INTEGER_TYPE);
4173 TREE_TYPE (itype) = type;
4174 if (type == NULL_TREE)
4177 TYPE_MIN_VALUE (itype) = convert (type, lowval);
4178 TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL;
4180 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
4181 TYPE_MODE (itype) = TYPE_MODE (type);
4182 TYPE_SIZE (itype) = TYPE_SIZE (type);
4183 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
4184 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
4185 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
4187 if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
4188 return type_hash_canon (tree_low_cst (highval, 0)
4189 - tree_low_cst (lowval, 0),
4195 /* Just like build_index_type, but takes lowval and highval instead
4196 of just highval (maxval). */
4199 build_index_2_type (tree lowval, tree highval)
4201 return build_range_type (sizetype, lowval, highval);
4204 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
4205 and number of elements specified by the range of values of INDEX_TYPE.
4206 If such a type has already been constructed, reuse it. */
4209 build_array_type (tree elt_type, tree index_type)
4212 hashval_t hashcode = 0;
4214 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
4216 error ("arrays of functions are not meaningful");
4217 elt_type = integer_type_node;
4220 t = make_node (ARRAY_TYPE);
4221 TREE_TYPE (t) = elt_type;
4222 TYPE_DOMAIN (t) = index_type;
4224 if (index_type == 0)
4227 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
4228 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
4229 t = type_hash_canon (hashcode, t);
4231 if (!COMPLETE_TYPE_P (t))
4236 /* Return the TYPE of the elements comprising
4237 the innermost dimension of ARRAY. */
4240 get_inner_array_type (tree array)
4242 tree type = TREE_TYPE (array);
4244 while (TREE_CODE (type) == ARRAY_TYPE)
4245 type = TREE_TYPE (type);
4250 /* Construct, lay out and return
4251 the type of functions returning type VALUE_TYPE
4252 given arguments of types ARG_TYPES.
4253 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
4254 are data type nodes for the arguments of the function.
4255 If such a type has already been constructed, reuse it. */
4258 build_function_type (tree value_type, tree arg_types)
4261 hashval_t hashcode = 0;
4263 if (TREE_CODE (value_type) == FUNCTION_TYPE)
4265 error ("function return type cannot be function");
4266 value_type = integer_type_node;
4269 /* Make a node of the sort we want. */
4270 t = make_node (FUNCTION_TYPE);
4271 TREE_TYPE (t) = value_type;
4272 TYPE_ARG_TYPES (t) = arg_types;
4274 /* If we already have such a type, use the old one. */
4275 hashcode = iterative_hash_object (TYPE_HASH (value_type), hashcode);
4276 hashcode = type_hash_list (arg_types, hashcode);
4277 t = type_hash_canon (hashcode, t);
4279 if (!COMPLETE_TYPE_P (t))
4284 /* Build a function type. The RETURN_TYPE is the type returned by the
4285 function. If additional arguments are provided, they are
4286 additional argument types. The list of argument types must always
4287 be terminated by NULL_TREE. */
4290 build_function_type_list (tree return_type, ...)
4295 va_start (p, return_type);
4297 t = va_arg (p, tree);
4298 for (args = NULL_TREE; t != NULL_TREE; t = va_arg (p, tree))
4299 args = tree_cons (NULL_TREE, t, args);
4302 args = nreverse (args);
4303 TREE_CHAIN (last) = void_list_node;
4304 args = build_function_type (return_type, args);
4310 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
4311 and ARGTYPES (a TREE_LIST) are the return type and arguments types
4312 for the method. An implicit additional parameter (of type
4313 pointer-to-BASETYPE) is added to the ARGTYPES. */
4316 build_method_type_directly (tree basetype,
4324 /* Make a node of the sort we want. */
4325 t = make_node (METHOD_TYPE);
4327 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4328 TREE_TYPE (t) = rettype;
4329 ptype = build_pointer_type (basetype);
4331 /* The actual arglist for this function includes a "hidden" argument
4332 which is "this". Put it into the list of argument types. */
4333 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
4334 TYPE_ARG_TYPES (t) = argtypes;
4336 /* If we already have such a type, use the old one. */
4337 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
4338 hashcode = iterative_hash_object (TYPE_HASH (rettype), hashcode);
4339 hashcode = type_hash_list (argtypes, hashcode);
4340 t = type_hash_canon (hashcode, t);
4342 if (!COMPLETE_TYPE_P (t))
4348 /* Construct, lay out and return the type of methods belonging to class
4349 BASETYPE and whose arguments and values are described by TYPE.
4350 If that type exists already, reuse it.
4351 TYPE must be a FUNCTION_TYPE node. */
4354 build_method_type (tree basetype, tree type)
4356 if (TREE_CODE (type) != FUNCTION_TYPE)
4359 return build_method_type_directly (basetype,
4361 TYPE_ARG_TYPES (type));
4364 /* Construct, lay out and return the type of offsets to a value
4365 of type TYPE, within an object of type BASETYPE.
4366 If a suitable offset type exists already, reuse it. */
4369 build_offset_type (tree basetype, tree type)
4372 hashval_t hashcode = 0;
4374 /* Make a node of the sort we want. */
4375 t = make_node (OFFSET_TYPE);
4377 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4378 TREE_TYPE (t) = type;
4380 /* If we already have such a type, use the old one. */
4381 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
4382 hashcode = iterative_hash_object (TYPE_HASH (type), hashcode);
4383 t = type_hash_canon (hashcode, t);
4385 if (!COMPLETE_TYPE_P (t))
4391 /* Create a complex type whose components are COMPONENT_TYPE. */
4394 build_complex_type (tree component_type)
4399 /* Make a node of the sort we want. */
4400 t = make_node (COMPLEX_TYPE);
4402 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
4404 /* If we already have such a type, use the old one. */
4405 hashcode = iterative_hash_object (TYPE_HASH (component_type), 0);
4406 t = type_hash_canon (hashcode, t);
4408 if (!COMPLETE_TYPE_P (t))
4411 /* If we are writing Dwarf2 output we need to create a name,
4412 since complex is a fundamental type. */
4413 if ((write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4417 if (component_type == char_type_node)
4418 name = "complex char";
4419 else if (component_type == signed_char_type_node)
4420 name = "complex signed char";
4421 else if (component_type == unsigned_char_type_node)
4422 name = "complex unsigned char";
4423 else if (component_type == short_integer_type_node)
4424 name = "complex short int";
4425 else if (component_type == short_unsigned_type_node)
4426 name = "complex short unsigned int";
4427 else if (component_type == integer_type_node)
4428 name = "complex int";
4429 else if (component_type == unsigned_type_node)
4430 name = "complex unsigned int";
4431 else if (component_type == long_integer_type_node)
4432 name = "complex long int";
4433 else if (component_type == long_unsigned_type_node)
4434 name = "complex long unsigned int";
4435 else if (component_type == long_long_integer_type_node)
4436 name = "complex long long int";
4437 else if (component_type == long_long_unsigned_type_node)
4438 name = "complex long long unsigned int";
4443 TYPE_NAME (t) = get_identifier (name);
4446 return build_qualified_type (t, TYPE_QUALS (component_type));
4449 /* Return OP, stripped of any conversions to wider types as much as is safe.
4450 Converting the value back to OP's type makes a value equivalent to OP.
4452 If FOR_TYPE is nonzero, we return a value which, if converted to
4453 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
4455 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
4456 narrowest type that can hold the value, even if they don't exactly fit.
4457 Otherwise, bit-field references are changed to a narrower type
4458 only if they can be fetched directly from memory in that type.
4460 OP must have integer, real or enumeral type. Pointers are not allowed!
4462 There are some cases where the obvious value we could return
4463 would regenerate to OP if converted to OP's type,
4464 but would not extend like OP to wider types.
4465 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
4466 For example, if OP is (unsigned short)(signed char)-1,
4467 we avoid returning (signed char)-1 if FOR_TYPE is int,
4468 even though extending that to an unsigned short would regenerate OP,
4469 since the result of extending (signed char)-1 to (int)
4470 is different from (int) OP. */
4473 get_unwidened (tree op, tree for_type)
4475 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
4476 tree type = TREE_TYPE (op);
4478 = TYPE_PRECISION (for_type != 0 ? for_type : type);
4480 = (for_type != 0 && for_type != type
4481 && final_prec > TYPE_PRECISION (type)
4482 && TYPE_UNSIGNED (type));
4485 while (TREE_CODE (op) == NOP_EXPR)
4488 = TYPE_PRECISION (TREE_TYPE (op))
4489 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
4491 /* Truncations are many-one so cannot be removed.
4492 Unless we are later going to truncate down even farther. */
4494 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
4497 /* See what's inside this conversion. If we decide to strip it,
4499 op = TREE_OPERAND (op, 0);
4501 /* If we have not stripped any zero-extensions (uns is 0),
4502 we can strip any kind of extension.
4503 If we have previously stripped a zero-extension,
4504 only zero-extensions can safely be stripped.
4505 Any extension can be stripped if the bits it would produce
4506 are all going to be discarded later by truncating to FOR_TYPE. */
4510 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
4512 /* TYPE_UNSIGNED says whether this is a zero-extension.
4513 Let's avoid computing it if it does not affect WIN
4514 and if UNS will not be needed again. */
4515 if ((uns || TREE_CODE (op) == NOP_EXPR)
4516 && TYPE_UNSIGNED (TREE_TYPE (op)))
4524 if (TREE_CODE (op) == COMPONENT_REF
4525 /* Since type_for_size always gives an integer type. */
4526 && TREE_CODE (type) != REAL_TYPE
4527 /* Don't crash if field not laid out yet. */
4528 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
4529 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
4531 unsigned int innerprec
4532 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4533 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
4534 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
4535 type = lang_hooks.types.type_for_size (innerprec, unsignedp);
4537 /* We can get this structure field in the narrowest type it fits in.
4538 If FOR_TYPE is 0, do this only for a field that matches the
4539 narrower type exactly and is aligned for it
4540 The resulting extension to its nominal type (a fullword type)
4541 must fit the same conditions as for other extensions. */
4544 && INT_CST_LT_UNSIGNED (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (op)))
4545 && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
4546 && (! uns || final_prec <= innerprec || unsignedp))
4548 win = build3 (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4549 TREE_OPERAND (op, 1), NULL_TREE);
4550 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4551 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4558 /* Return OP or a simpler expression for a narrower value
4559 which can be sign-extended or zero-extended to give back OP.
4560 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
4561 or 0 if the value should be sign-extended. */
4564 get_narrower (tree op, int *unsignedp_ptr)
4569 bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
4571 while (TREE_CODE (op) == NOP_EXPR)
4574 = (TYPE_PRECISION (TREE_TYPE (op))
4575 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
4577 /* Truncations are many-one so cannot be removed. */
4581 /* See what's inside this conversion. If we decide to strip it,
4586 op = TREE_OPERAND (op, 0);
4587 /* An extension: the outermost one can be stripped,
4588 but remember whether it is zero or sign extension. */
4590 uns = TYPE_UNSIGNED (TREE_TYPE (op));
4591 /* Otherwise, if a sign extension has been stripped,
4592 only sign extensions can now be stripped;
4593 if a zero extension has been stripped, only zero-extensions. */
4594 else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
4598 else /* bitschange == 0 */
4600 /* A change in nominal type can always be stripped, but we must
4601 preserve the unsignedness. */
4603 uns = TYPE_UNSIGNED (TREE_TYPE (op));
4605 op = TREE_OPERAND (op, 0);
4606 /* Keep trying to narrow, but don't assign op to win if it
4607 would turn an integral type into something else. */
4608 if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
4615 if (TREE_CODE (op) == COMPONENT_REF
4616 /* Since type_for_size always gives an integer type. */
4617 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
4618 /* Ensure field is laid out already. */
4619 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
4620 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
4622 unsigned HOST_WIDE_INT innerprec
4623 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4624 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
4625 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
4626 tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
4628 /* We can get this structure field in a narrower type that fits it,
4629 but the resulting extension to its nominal type (a fullword type)
4630 must satisfy the same conditions as for other extensions.
4632 Do this only for fields that are aligned (not bit-fields),
4633 because when bit-field insns will be used there is no
4634 advantage in doing this. */
4636 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
4637 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
4638 && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
4642 uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
4643 win = build3 (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4644 TREE_OPERAND (op, 1), NULL_TREE);
4645 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4646 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4649 *unsignedp_ptr = uns;
4653 /* Nonzero if integer constant C has a value that is permissible
4654 for type TYPE (an INTEGER_TYPE). */
4657 int_fits_type_p (tree c, tree type)
4659 tree type_low_bound = TYPE_MIN_VALUE (type);
4660 tree type_high_bound = TYPE_MAX_VALUE (type);
4661 int ok_for_low_bound, ok_for_high_bound;
4663 /* Perform some generic filtering first, which may allow making a decision
4664 even if the bounds are not constant. First, negative integers never fit
4665 in unsigned types, */
4666 if ((TYPE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0)
4667 /* Also, unsigned integers with top bit set never fit signed types. */
4668 || (! TYPE_UNSIGNED (type)
4669 && TYPE_UNSIGNED (TREE_TYPE (c)) && tree_int_cst_msb (c)))
4672 /* If at least one bound of the type is a constant integer, we can check
4673 ourselves and maybe make a decision. If no such decision is possible, but
4674 this type is a subtype, try checking against that. Otherwise, use
4675 force_fit_type, which checks against the precision.
4677 Compute the status for each possibly constant bound, and return if we see
4678 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
4679 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
4680 for "constant known to fit". */
4682 ok_for_low_bound = -1;
4683 ok_for_high_bound = -1;
4685 /* Check if C >= type_low_bound. */
4686 if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
4688 ok_for_low_bound = ! tree_int_cst_lt (c, type_low_bound);
4689 if (! ok_for_low_bound)
4693 /* Check if c <= type_high_bound. */
4694 if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
4696 ok_for_high_bound = ! tree_int_cst_lt (type_high_bound, c);
4697 if (! ok_for_high_bound)
4701 /* If the constant fits both bounds, the result is known. */
4702 if (ok_for_low_bound == 1 && ok_for_high_bound == 1)
4705 /* If we haven't been able to decide at this point, there nothing more we
4706 can check ourselves here. Look at the base type if we have one. */
4707 else if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != 0)
4708 return int_fits_type_p (c, TREE_TYPE (type));
4710 /* Or to force_fit_type, if nothing else. */
4714 TREE_TYPE (c) = type;
4715 c = force_fit_type (c, -1, false, false);
4716 return !TREE_OVERFLOW (c);
4720 /* Subprogram of following function. Called by walk_tree.
4722 Return *TP if it is an automatic variable or parameter of the
4723 function passed in as DATA. */
4726 find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
4728 tree fn = (tree) data;
4733 else if (DECL_P (*tp) && lang_hooks.tree_inlining.auto_var_in_fn_p (*tp, fn))
4739 /* Returns true if T is, contains, or refers to a type with variable
4740 size. If FN is nonzero, only return true if a modifier of the type
4741 or position of FN is a variable or parameter inside FN.
4743 This concept is more general than that of C99 'variably modified types':
4744 in C99, a struct type is never variably modified because a VLA may not
4745 appear as a structure member. However, in GNU C code like:
4747 struct S { int i[f()]; };
4749 is valid, and other languages may define similar constructs. */
4752 variably_modified_type_p (tree type, tree fn)
4756 /* Test if T is either variable (if FN is zero) or an expression containing
4757 a variable in FN. */
4758 #define RETURN_TRUE_IF_VAR(T) \
4759 do { tree _t = (T); \
4760 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
4761 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
4762 return true; } while (0)
4764 if (type == error_mark_node)
4767 /* If TYPE itself has variable size, it is variably modified.
4769 We do not yet have a representation of the C99 '[*]' syntax.
4770 When a representation is chosen, this function should be modified
4771 to test for that case as well. */
4772 RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
4773 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT(type));
4775 switch (TREE_CODE (type))
4778 case REFERENCE_TYPE:
4782 if (variably_modified_type_p (TREE_TYPE (type), fn))
4788 /* If TYPE is a function type, it is variably modified if any of the
4789 parameters or the return type are variably modified. */
4790 if (variably_modified_type_p (TREE_TYPE (type), fn))
4793 for (t = TYPE_ARG_TYPES (type);
4794 t && t != void_list_node;
4796 if (variably_modified_type_p (TREE_VALUE (t), fn))
4805 /* Scalar types are variably modified if their end points
4807 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
4808 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
4813 case QUAL_UNION_TYPE:
4814 /* We can't see if any of the field are variably-modified by the
4815 definition we normally use, since that would produce infinite
4816 recursion via pointers. */
4817 /* This is variably modified if some field's type is. */
4818 for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
4819 if (TREE_CODE (t) == FIELD_DECL)
4821 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
4822 RETURN_TRUE_IF_VAR (DECL_SIZE (t));
4823 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
4825 if (TREE_CODE (type) == QUAL_UNION_TYPE)
4826 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
4834 /* The current language may have other cases to check, but in general,
4835 all other types are not variably modified. */
4836 return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
4838 #undef RETURN_TRUE_IF_VAR
4841 /* Given a DECL or TYPE, return the scope in which it was declared, or
4842 NULL_TREE if there is no containing scope. */
4845 get_containing_scope (tree t)
4847 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
4850 /* Return the innermost context enclosing DECL that is
4851 a FUNCTION_DECL, or zero if none. */
4854 decl_function_context (tree decl)
4858 if (TREE_CODE (decl) == ERROR_MARK)
4861 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
4862 where we look up the function at runtime. Such functions always take
4863 a first argument of type 'pointer to real context'.
4865 C++ should really be fixed to use DECL_CONTEXT for the real context,
4866 and use something else for the "virtual context". */
4867 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
4870 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4872 context = DECL_CONTEXT (decl);
4874 while (context && TREE_CODE (context) != FUNCTION_DECL)
4876 if (TREE_CODE (context) == BLOCK)
4877 context = BLOCK_SUPERCONTEXT (context);
4879 context = get_containing_scope (context);
4885 /* Return the innermost context enclosing DECL that is
4886 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
4887 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
4890 decl_type_context (tree decl)
4892 tree context = DECL_CONTEXT (decl);
4895 switch (TREE_CODE (context))
4897 case NAMESPACE_DECL:
4898 case TRANSLATION_UNIT_DECL:
4903 case QUAL_UNION_TYPE:
4908 context = DECL_CONTEXT (context);
4912 context = BLOCK_SUPERCONTEXT (context);
4922 /* CALL is a CALL_EXPR. Return the declaration for the function
4923 called, or NULL_TREE if the called function cannot be
4927 get_callee_fndecl (tree call)
4931 /* It's invalid to call this function with anything but a
4933 if (TREE_CODE (call) != CALL_EXPR)
4936 /* The first operand to the CALL is the address of the function
4938 addr = TREE_OPERAND (call, 0);
4942 /* If this is a readonly function pointer, extract its initial value. */
4943 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
4944 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
4945 && DECL_INITIAL (addr))
4946 addr = DECL_INITIAL (addr);
4948 /* If the address is just `&f' for some function `f', then we know
4949 that `f' is being called. */
4950 if (TREE_CODE (addr) == ADDR_EXPR
4951 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
4952 return TREE_OPERAND (addr, 0);
4954 /* We couldn't figure out what was being called. Maybe the front
4955 end has some idea. */
4956 return lang_hooks.lang_get_callee_fndecl (call);
4959 /* Print debugging information about tree nodes generated during the compile,
4960 and any language-specific information. */
4963 dump_tree_statistics (void)
4965 #ifdef GATHER_STATISTICS
4967 int total_nodes, total_bytes;
4970 fprintf (stderr, "\n??? tree nodes created\n\n");
4971 #ifdef GATHER_STATISTICS
4972 fprintf (stderr, "Kind Nodes Bytes\n");
4973 fprintf (stderr, "---------------------------------------\n");
4974 total_nodes = total_bytes = 0;
4975 for (i = 0; i < (int) all_kinds; i++)
4977 fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
4978 tree_node_counts[i], tree_node_sizes[i]);
4979 total_nodes += tree_node_counts[i];
4980 total_bytes += tree_node_sizes[i];
4982 fprintf (stderr, "---------------------------------------\n");
4983 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
4984 fprintf (stderr, "---------------------------------------\n");
4985 ssanames_print_statistics ();
4986 phinodes_print_statistics ();
4988 fprintf (stderr, "(No per-node statistics)\n");
4990 print_type_hash_statistics ();
4991 lang_hooks.print_statistics ();
4994 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
4996 /* Generate a crc32 of a string. */
4999 crc32_string (unsigned chksum, const char *string)
5003 unsigned value = *string << 24;
5006 for (ix = 8; ix--; value <<= 1)
5010 feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
5019 /* P is a string that will be used in a symbol. Mask out any characters
5020 that are not valid in that context. */
5023 clean_symbol_name (char *p)
5027 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
5030 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
5037 /* Generate a name for a function unique to this translation unit.
5038 TYPE is some string to identify the purpose of this function to the
5039 linker or collect2. */
5042 get_file_function_name_long (const char *type)
5048 if (first_global_object_name)
5049 p = first_global_object_name;
5052 /* We don't have anything that we know to be unique to this translation
5053 unit, so use what we do have and throw in some randomness. */
5055 const char *name = weak_global_object_name;
5056 const char *file = main_input_filename;
5061 file = input_filename;
5063 len = strlen (file);
5064 q = alloca (9 * 2 + len + 1);
5065 memcpy (q, file, len + 1);
5066 clean_symbol_name (q);
5068 sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
5069 crc32_string (0, flag_random_seed));
5074 buf = alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p) + strlen (type));
5076 /* Set up the name of the file-level functions we may need.
5077 Use a global object (which is already required to be unique over
5078 the program) rather than the file name (which imposes extra
5080 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
5082 return get_identifier (buf);
5085 /* If KIND=='I', return a suitable global initializer (constructor) name.
5086 If KIND=='D', return a suitable global clean-up (destructor) name. */
5089 get_file_function_name (int kind)
5096 return get_file_function_name_long (p);
5099 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
5100 The result is placed in BUFFER (which has length BIT_SIZE),
5101 with one bit in each char ('\000' or '\001').
5103 If the constructor is constant, NULL_TREE is returned.
5104 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
5107 get_set_constructor_bits (tree init, char *buffer, int bit_size)
5111 HOST_WIDE_INT domain_min
5112 = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init))), 0);
5113 tree non_const_bits = NULL_TREE;
5115 for (i = 0; i < bit_size; i++)
5118 for (vals = TREE_OPERAND (init, 1);
5119 vals != NULL_TREE; vals = TREE_CHAIN (vals))
5121 if (!host_integerp (TREE_VALUE (vals), 0)
5122 || (TREE_PURPOSE (vals) != NULL_TREE
5123 && !host_integerp (TREE_PURPOSE (vals), 0)))
5125 = tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits);
5126 else if (TREE_PURPOSE (vals) != NULL_TREE)
5128 /* Set a range of bits to ones. */
5129 HOST_WIDE_INT lo_index
5130 = tree_low_cst (TREE_PURPOSE (vals), 0) - domain_min;
5131 HOST_WIDE_INT hi_index
5132 = tree_low_cst (TREE_VALUE (vals), 0) - domain_min;
5134 if (lo_index < 0 || lo_index >= bit_size
5135 || hi_index < 0 || hi_index >= bit_size)
5137 for (; lo_index <= hi_index; lo_index++)
5138 buffer[lo_index] = 1;
5142 /* Set a single bit to one. */
5144 = tree_low_cst (TREE_VALUE (vals), 0) - domain_min;
5145 if (index < 0 || index >= bit_size)
5147 error ("invalid initializer for bit string");
5153 return non_const_bits;
5156 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
5157 The result is placed in BUFFER (which is an array of bytes).
5158 If the constructor is constant, NULL_TREE is returned.
5159 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
5162 get_set_constructor_bytes (tree init, unsigned char *buffer, int wd_size)
5165 int set_word_size = BITS_PER_UNIT;
5166 int bit_size = wd_size * set_word_size;
5168 unsigned char *bytep = buffer;
5169 char *bit_buffer = alloca (bit_size);
5170 tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
5172 for (i = 0; i < wd_size; i++)
5175 for (i = 0; i < bit_size; i++)
5179 if (BYTES_BIG_ENDIAN)
5180 *bytep |= (1 << (set_word_size - 1 - bit_pos));
5182 *bytep |= 1 << bit_pos;
5185 if (bit_pos >= set_word_size)
5186 bit_pos = 0, bytep++;
5188 return non_const_bits;
5191 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
5193 /* Complain that the tree code of NODE does not match the expected 0
5194 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
5198 tree_check_failed (const tree node, const char *file,
5199 int line, const char *function, ...)
5203 unsigned length = 0;
5206 va_start (args, function);
5207 while ((code = va_arg (args, int)))
5208 length += 4 + strlen (tree_code_name[code]);
5210 va_start (args, function);
5211 buffer = alloca (length);
5213 while ((code = va_arg (args, int)))
5217 strcpy (buffer + length, " or ");
5220 strcpy (buffer + length, tree_code_name[code]);
5221 length += strlen (tree_code_name[code]);
5225 internal_error ("tree check: expected %s, have %s in %s, at %s:%d",
5226 buffer, tree_code_name[TREE_CODE (node)],
5227 function, trim_filename (file), line);
5230 /* Complain that the tree code of NODE does match the expected 0
5231 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
5235 tree_not_check_failed (const tree node, const char *file,
5236 int line, const char *function, ...)
5240 unsigned length = 0;
5243 va_start (args, function);
5244 while ((code = va_arg (args, int)))
5245 length += 4 + strlen (tree_code_name[code]);
5247 va_start (args, function);
5248 buffer = alloca (length);
5250 while ((code = va_arg (args, int)))
5254 strcpy (buffer + length, " or ");
5257 strcpy (buffer + length, tree_code_name[code]);
5258 length += strlen (tree_code_name[code]);
5262 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
5263 buffer, tree_code_name[TREE_CODE (node)],
5264 function, trim_filename (file), line);
5267 /* Similar to tree_check_failed, except that we check for a class of tree
5268 code, given in CL. */
5271 tree_class_check_failed (const tree node, int cl, const char *file,
5272 int line, const char *function)
5275 ("tree check: expected class '%c', have '%c' (%s) in %s, at %s:%d",
5276 cl, TREE_CODE_CLASS (TREE_CODE (node)),
5277 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
5280 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
5281 (dynamically sized) vector. */
5284 tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
5285 const char *function)
5288 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
5289 idx + 1, len, function, trim_filename (file), line);
5292 /* Similar to above, except that the check is for the bounds of a PHI_NODE's
5293 (dynamically sized) vector. */
5296 phi_node_elt_check_failed (int idx, int len, const char *file, int line,
5297 const char *function)
5300 ("tree check: accessed elt %d of phi_node with %d elts in %s, at %s:%d",
5301 idx + 1, len, function, trim_filename (file), line);
5304 /* Similar to above, except that the check is for the bounds of the operand
5305 vector of an expression node. */
5308 tree_operand_check_failed (int idx, enum tree_code code, const char *file,
5309 int line, const char *function)
5312 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
5313 idx + 1, tree_code_name[code], TREE_CODE_LENGTH (code),
5314 function, trim_filename (file), line);
5316 #endif /* ENABLE_TREE_CHECKING */
5318 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
5319 and mapped to the machine mode MODE. Initialize its fields and build
5320 the information necessary for debugging output. */
5323 make_vector_type (tree innertype, int nunits, enum machine_mode mode)
5325 tree t = make_node (VECTOR_TYPE);
5327 TREE_TYPE (t) = innertype;
5328 TYPE_VECTOR_SUBPARTS (t) = nunits;
5329 TYPE_MODE (t) = mode;
5333 tree index = build_int_cst (NULL_TREE, nunits - 1, 0);
5334 tree array = build_array_type (innertype, build_index_type (index));
5335 tree rt = make_node (RECORD_TYPE);
5337 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
5338 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
5340 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
5341 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
5342 the representation type, and we want to find that die when looking up
5343 the vector type. This is most easily achieved by making the TYPE_UID
5345 TYPE_UID (rt) = TYPE_UID (t);
5352 make_or_reuse_type (unsigned size, int unsignedp)
5354 if (size == INT_TYPE_SIZE)
5355 return unsignedp ? unsigned_type_node : integer_type_node;
5356 if (size == CHAR_TYPE_SIZE)
5357 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
5358 if (size == SHORT_TYPE_SIZE)
5359 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
5360 if (size == LONG_TYPE_SIZE)
5361 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
5362 if (size == LONG_LONG_TYPE_SIZE)
5363 return (unsignedp ? long_long_unsigned_type_node
5364 : long_long_integer_type_node);
5367 return make_unsigned_type (size);
5369 return make_signed_type (size);
5372 /* Create nodes for all integer types (and error_mark_node) using the sizes
5373 of C datatypes. The caller should call set_sizetype soon after calling
5374 this function to select one of the types as sizetype. */
5377 build_common_tree_nodes (int signed_char)
5379 error_mark_node = make_node (ERROR_MARK);
5380 TREE_TYPE (error_mark_node) = error_mark_node;
5382 initialize_sizetypes ();
5384 /* Define both `signed char' and `unsigned char'. */
5385 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
5386 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
5388 /* Define `char', which is like either `signed char' or `unsigned char'
5389 but not the same as either. */
5392 ? make_signed_type (CHAR_TYPE_SIZE)
5393 : make_unsigned_type (CHAR_TYPE_SIZE));
5395 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
5396 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
5397 integer_type_node = make_signed_type (INT_TYPE_SIZE);
5398 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
5399 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
5400 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
5401 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
5402 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
5404 /* Define a boolean type. This type only represents boolean values but
5405 may be larger than char depending on the value of BOOL_TYPE_SIZE.
5406 Front ends which want to override this size (i.e. Java) can redefine
5407 boolean_type_node before calling build_common_tree_nodes_2. */
5408 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
5409 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
5410 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1, 0);
5411 TYPE_PRECISION (boolean_type_node) = 1;
5413 /* Fill in the rest of the sized types. Reuse existing type nodes
5415 intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
5416 intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
5417 intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
5418 intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
5419 intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
5421 unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
5422 unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
5423 unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
5424 unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
5425 unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
5427 access_public_node = get_identifier ("public");
5428 access_protected_node = get_identifier ("protected");
5429 access_private_node = get_identifier ("private");
5432 /* Call this function after calling build_common_tree_nodes and set_sizetype.
5433 It will create several other common tree nodes. */
5436 build_common_tree_nodes_2 (int short_double)
5438 /* Define these next since types below may used them. */
5439 integer_zero_node = build_int_cst (NULL_TREE, 0, 0);
5440 integer_one_node = build_int_cst (NULL_TREE, 1, 0);
5441 integer_minus_one_node = build_int_cst (NULL_TREE, -1, -1);
5443 size_zero_node = size_int (0);
5444 size_one_node = size_int (1);
5445 bitsize_zero_node = bitsize_int (0);
5446 bitsize_one_node = bitsize_int (1);
5447 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
5449 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
5450 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
5452 void_type_node = make_node (VOID_TYPE);
5453 layout_type (void_type_node);
5455 /* We are not going to have real types in C with less than byte alignment,
5456 so we might as well not have any types that claim to have it. */
5457 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
5458 TYPE_USER_ALIGN (void_type_node) = 0;
5460 null_pointer_node = build_int_cst (build_pointer_type (void_type_node),
5462 layout_type (TREE_TYPE (null_pointer_node));
5464 ptr_type_node = build_pointer_type (void_type_node);
5466 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
5467 fileptr_type_node = ptr_type_node;
5469 float_type_node = make_node (REAL_TYPE);
5470 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
5471 layout_type (float_type_node);
5473 double_type_node = make_node (REAL_TYPE);
5475 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
5477 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
5478 layout_type (double_type_node);
5480 long_double_type_node = make_node (REAL_TYPE);
5481 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
5482 layout_type (long_double_type_node);
5484 float_ptr_type_node = build_pointer_type (float_type_node);
5485 double_ptr_type_node = build_pointer_type (double_type_node);
5486 long_double_ptr_type_node = build_pointer_type (long_double_type_node);
5487 integer_ptr_type_node = build_pointer_type (integer_type_node);
5489 complex_integer_type_node = make_node (COMPLEX_TYPE);
5490 TREE_TYPE (complex_integer_type_node) = integer_type_node;
5491 layout_type (complex_integer_type_node);
5493 complex_float_type_node = make_node (COMPLEX_TYPE);
5494 TREE_TYPE (complex_float_type_node) = float_type_node;
5495 layout_type (complex_float_type_node);
5497 complex_double_type_node = make_node (COMPLEX_TYPE);
5498 TREE_TYPE (complex_double_type_node) = double_type_node;
5499 layout_type (complex_double_type_node);
5501 complex_long_double_type_node = make_node (COMPLEX_TYPE);
5502 TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
5503 layout_type (complex_long_double_type_node);
5506 tree t = targetm.build_builtin_va_list ();
5508 /* Many back-ends define record types without setting TYPE_NAME.
5509 If we copied the record type here, we'd keep the original
5510 record type without a name. This breaks name mangling. So,
5511 don't copy record types and let c_common_nodes_and_builtins()
5512 declare the type to be __builtin_va_list. */
5513 if (TREE_CODE (t) != RECORD_TYPE)
5514 t = build_variant_type_copy (t);
5516 va_list_type_node = t;
5520 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
5523 If we requested a pointer to a vector, build up the pointers that
5524 we stripped off while looking for the inner type. Similarly for
5525 return values from functions.
5527 The argument TYPE is the top of the chain, and BOTTOM is the
5528 new type which we will point to. */
5531 reconstruct_complex_type (tree type, tree bottom)
5535 if (POINTER_TYPE_P (type))
5537 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5538 outer = build_pointer_type (inner);
5540 else if (TREE_CODE (type) == ARRAY_TYPE)
5542 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5543 outer = build_array_type (inner, TYPE_DOMAIN (type));
5545 else if (TREE_CODE (type) == FUNCTION_TYPE)
5547 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5548 outer = build_function_type (inner, TYPE_ARG_TYPES (type));
5550 else if (TREE_CODE (type) == METHOD_TYPE)
5552 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
5553 outer = build_method_type_directly (TYPE_METHOD_BASETYPE (type),
5555 TYPE_ARG_TYPES (type));
5560 TYPE_READONLY (outer) = TYPE_READONLY (type);
5561 TYPE_VOLATILE (outer) = TYPE_VOLATILE (type);
5566 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
5569 build_vector_type_for_mode (tree innertype, enum machine_mode mode)
5573 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
5574 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
5575 nunits = GET_MODE_NUNITS (mode);
5577 else if (GET_MODE_CLASS (mode) == MODE_INT)
5579 /* Check that there are no leftover bits. */
5580 if (GET_MODE_BITSIZE (mode) % TREE_INT_CST_LOW (TYPE_SIZE (innertype)))
5583 nunits = GET_MODE_BITSIZE (mode)
5584 / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
5589 return make_vector_type (innertype, nunits, mode);
5592 /* Similarly, but takes the inner type and number of units, which must be
5596 build_vector_type (tree innertype, int nunits)
5598 return make_vector_type (innertype, nunits, VOIDmode);
5601 /* Given an initializer INIT, return TRUE if INIT is zero or some
5602 aggregate of zeros. Otherwise return FALSE. */
5604 initializer_zerop (tree init)
5610 switch (TREE_CODE (init))
5613 return integer_zerop (init);
5616 /* ??? Note that this is not correct for C4X float formats. There,
5617 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
5618 negative exponent. */
5619 return real_zerop (init)
5620 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
5623 return integer_zerop (init)
5624 || (real_zerop (init)
5625 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
5626 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
5629 for (elt = TREE_VECTOR_CST_ELTS (init); elt; elt = TREE_CHAIN (elt))
5630 if (!initializer_zerop (TREE_VALUE (elt)))
5635 elt = CONSTRUCTOR_ELTS (init);
5636 if (elt == NULL_TREE)
5639 /* A set is empty only if it has no elements. */
5640 if (TREE_CODE (TREE_TYPE (init)) == SET_TYPE)
5643 for (; elt ; elt = TREE_CHAIN (elt))
5644 if (! initializer_zerop (TREE_VALUE (elt)))
5654 add_var_to_bind_expr (tree bind_expr, tree var)
5656 BIND_EXPR_VARS (bind_expr)
5657 = chainon (BIND_EXPR_VARS (bind_expr), var);
5658 if (BIND_EXPR_BLOCK (bind_expr))
5659 BLOCK_VARS (BIND_EXPR_BLOCK (bind_expr))
5660 = BIND_EXPR_VARS (bind_expr);
5663 /* Build an empty statement. */
5666 build_empty_stmt (void)
5668 return build1 (NOP_EXPR, void_type_node, size_zero_node);
5672 /* Returns true if it is possible to prove that the index of
5673 an array access REF (an ARRAY_REF expression) falls into the
5677 in_array_bounds_p (tree ref)
5679 tree idx = TREE_OPERAND (ref, 1);
5682 if (TREE_CODE (idx) != INTEGER_CST)
5685 min = array_ref_low_bound (ref);
5686 max = array_ref_up_bound (ref);
5689 || TREE_CODE (min) != INTEGER_CST
5690 || TREE_CODE (max) != INTEGER_CST)
5693 if (tree_int_cst_lt (idx, min)
5694 || tree_int_cst_lt (max, idx))
5700 /* Return true if T (assumed to be a DECL) is a global variable. */
5703 is_global_var (tree t)
5705 return (TREE_STATIC (t) || DECL_EXTERNAL (t));
5708 /* Return true if T (assumed to be a DECL) must be assigned a memory
5712 needs_to_live_in_memory (tree t)
5714 return (TREE_ADDRESSABLE (t)
5715 || is_global_var (t)
5716 || (TREE_CODE (t) == RESULT_DECL
5717 && aggregate_value_p (t, current_function_decl)));
5720 /* There are situations in which a language considers record types
5721 compatible which have different field lists. Decide if two fields
5722 are compatible. It is assumed that the parent records are compatible. */
5725 fields_compatible_p (tree f1, tree f2)
5727 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1),
5728 DECL_FIELD_BIT_OFFSET (f2), OEP_ONLY_CONST))
5731 if (!operand_equal_p (DECL_FIELD_OFFSET (f1),
5732 DECL_FIELD_OFFSET (f2), OEP_ONLY_CONST))
5735 if (!lang_hooks.types_compatible_p (TREE_TYPE (f1), TREE_TYPE (f2)))
5741 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
5744 find_compatible_field (tree record, tree orig_field)
5748 for (f = TYPE_FIELDS (record); f ; f = TREE_CHAIN (f))
5749 if (TREE_CODE (f) == FIELD_DECL
5750 && fields_compatible_p (f, orig_field))
5753 /* ??? Why isn't this on the main fields list? */
5754 f = TYPE_VFIELD (record);
5755 if (f && TREE_CODE (f) == FIELD_DECL
5756 && fields_compatible_p (f, orig_field))
5759 /* ??? We should abort here, but Java appears to do Bad Things
5760 with inherited fields. */
5764 /* Return value of a constant X. */
5767 int_cst_value (tree x)
5769 unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
5770 unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
5771 bool negative = ((val >> (bits - 1)) & 1) != 0;
5773 if (bits > HOST_BITS_PER_WIDE_INT)
5777 val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1;
5779 val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1);
5784 /* Returns the greatest common divisor of A and B, which must be
5788 tree_fold_gcd (tree a, tree b)
5791 tree type = TREE_TYPE (a);
5793 #if defined ENABLE_CHECKING
5794 if (TREE_CODE (a) != INTEGER_CST
5795 || TREE_CODE (b) != INTEGER_CST)
5799 if (integer_zerop (a))
5802 if (integer_zerop (b))
5805 if (tree_int_cst_sgn (a) == -1)
5806 a = fold (build2 (MULT_EXPR, type, a,
5807 convert (type, integer_minus_one_node)));
5809 if (tree_int_cst_sgn (b) == -1)
5810 b = fold (build2 (MULT_EXPR, type, b,
5811 convert (type, integer_minus_one_node)));
5815 a_mod_b = fold (build2 (CEIL_MOD_EXPR, type, a, b));
5817 if (!TREE_INT_CST_LOW (a_mod_b)
5818 && !TREE_INT_CST_HIGH (a_mod_b))
5826 #include "gt-tree.h"