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 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. */
45 #include "langhooks.h"
47 /* obstack.[ch] explicitly declined to prototype this. */
48 extern int _obstack_allocated_p
PARAMS ((struct obstack
*h
, PTR obj
));
50 #ifdef GATHER_STATISTICS
51 /* Statistics-gathering stuff. */
71 int tree_node_counts
[(int) all_kinds
];
72 int tree_node_sizes
[(int) all_kinds
];
74 static const char * const tree_node_kind_names
[] = {
90 #endif /* GATHER_STATISTICS */
92 /* Unique id for next decl created. */
93 static int next_decl_uid
;
94 /* Unique id for next type created. */
95 static int next_type_uid
= 1;
97 /* Since we cannot rehash a type after it is in the table, we have to
98 keep the hash code. */
100 struct type_hash
GTY(())
106 /* Initial size of the hash table (rounded to next prime). */
107 #define TYPE_HASH_INITIAL_SIZE 1000
109 /* Now here is the hash table. When recording a type, it is added to
110 the slot whose index is the hash code. Note that the hash table is
111 used for several kinds of types (function types, array types and
112 array index range types, for now). While all these live in the
113 same table, they are completely independent, and the hash code is
114 computed differently for each of these. */
116 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash
)))
117 htab_t type_hash_table
;
119 static void set_type_quals
PARAMS ((tree
, int));
120 static void append_random_chars
PARAMS ((char *));
121 static int type_hash_eq
PARAMS ((const void *, const void *));
122 static unsigned int type_hash_hash
PARAMS ((const void *));
123 static void print_type_hash_statistics
PARAMS((void));
124 static void finish_vector_type
PARAMS((tree
));
125 static tree make_vector
PARAMS ((enum machine_mode
, tree
, int));
126 static int type_hash_marked_p
PARAMS ((const void *));
128 tree global_trees
[TI_MAX
];
129 tree integer_types
[itk_none
];
136 /* Initialize the hash table of types. */
137 type_hash_table
= htab_create (TYPE_HASH_INITIAL_SIZE
, type_hash_hash
,
142 /* The name of the object as the assembler will see it (but before any
143 translations made by ASM_OUTPUT_LABELREF). Often this is the same
144 as DECL_NAME. It is an IDENTIFIER_NODE. */
146 decl_assembler_name (decl
)
149 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
150 (*lang_hooks
.set_decl_assembler_name
) (decl
);
151 return DECL_CHECK (decl
)->decl
.assembler_name
;
154 /* Compute the number of bytes occupied by 'node'. This routine only
155 looks at TREE_CODE and, if the code is TREE_VEC, TREE_VEC_LENGTH. */
160 enum tree_code code
= TREE_CODE (node
);
162 switch (TREE_CODE_CLASS (code
))
164 case 'd': /* A decl node */
165 return sizeof (struct tree_decl
);
167 case 't': /* a type node */
168 return sizeof (struct tree_type
);
170 case 'b': /* a lexical block node */
171 return sizeof (struct tree_block
);
173 case 'r': /* a reference */
174 case 'e': /* an expression */
175 case 's': /* an expression with side effects */
176 case '<': /* a comparison expression */
177 case '1': /* a unary arithmetic expression */
178 case '2': /* a binary arithmetic expression */
179 return (sizeof (struct tree_exp
)
180 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (char *));
182 case 'c': /* a constant */
183 /* We can't use TREE_CODE_LENGTH for INTEGER_CST, since the number of
184 words is machine-dependent due to varying length of HOST_WIDE_INT,
185 which might be wider than a pointer (e.g., long long). Similarly
186 for REAL_CST, since the number of words is machine-dependent due
187 to varying size and alignment of `double'. */
188 if (code
== INTEGER_CST
)
189 return sizeof (struct tree_int_cst
);
190 else if (code
== REAL_CST
)
191 return sizeof (struct tree_real_cst
);
193 return (sizeof (struct tree_common
)
194 + TREE_CODE_LENGTH (code
) * sizeof (char *));
196 case 'x': /* something random, like an identifier. */
199 length
= (sizeof (struct tree_common
)
200 + TREE_CODE_LENGTH (code
) * sizeof (char *));
201 if (code
== TREE_VEC
)
202 length
+= (TREE_VEC_LENGTH (node
) - 1) * sizeof (char *);
211 /* Return a newly allocated node of code CODE.
212 For decl and type nodes, some other fields are initialized.
213 The rest of the node is initialized to zero.
215 Achoo! I got a code in the node. */
222 int type
= TREE_CODE_CLASS (code
);
224 #ifdef GATHER_STATISTICS
227 struct tree_common ttmp
;
229 /* We can't allocate a TREE_VEC without knowing how many elements
231 if (code
== TREE_VEC
)
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 'b': /* a lexical block */
252 case 's': /* an expression with side effects */
256 case 'r': /* a reference */
260 case 'e': /* an expression */
261 case '<': /* a comparison expression */
262 case '1': /* a unary arithmetic expression */
263 case '2': /* a binary arithmetic expression */
267 case 'c': /* a constant */
271 case 'x': /* something random, like an identifier. */
272 if (code
== IDENTIFIER_NODE
)
274 else if (code
== TREE_VEC
)
284 tree_node_counts
[(int) kind
]++;
285 tree_node_sizes
[(int) kind
] += length
;
288 t
= ggc_alloc_tree (length
);
290 memset ((PTR
) t
, 0, length
);
292 TREE_SET_CODE (t
, code
);
297 TREE_SIDE_EFFECTS (t
) = 1;
298 TREE_TYPE (t
) = void_type_node
;
302 if (code
!= FUNCTION_DECL
)
304 DECL_USER_ALIGN (t
) = 0;
305 DECL_IN_SYSTEM_HEADER (t
) = in_system_header
;
306 DECL_SOURCE_LINE (t
) = lineno
;
307 DECL_SOURCE_FILE (t
) =
308 (input_filename
) ? input_filename
: "<built-in>";
309 DECL_UID (t
) = next_decl_uid
++;
311 /* We have not yet computed the alias set for this declaration. */
312 DECL_POINTER_ALIAS_SET (t
) = -1;
316 TYPE_UID (t
) = next_type_uid
++;
317 TYPE_ALIGN (t
) = char_type_node
? TYPE_ALIGN (char_type_node
) : 0;
318 TYPE_USER_ALIGN (t
) = 0;
319 TYPE_MAIN_VARIANT (t
) = t
;
321 /* Default to no attributes for type, but let target change that. */
322 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
323 (*targetm
.set_default_type_attributes
) (t
);
325 /* We have not yet computed the alias set for this type. */
326 TYPE_ALIAS_SET (t
) = -1;
330 TREE_CONSTANT (t
) = 1;
340 case PREDECREMENT_EXPR
:
341 case PREINCREMENT_EXPR
:
342 case POSTDECREMENT_EXPR
:
343 case POSTINCREMENT_EXPR
:
344 /* All of these have side-effects, no matter what their
346 TREE_SIDE_EFFECTS (t
) = 1;
358 /* Return a new node with the same contents as NODE except that its
359 TREE_CHAIN is zero and it has a fresh uid. */
366 enum tree_code code
= TREE_CODE (node
);
369 length
= tree_size (node
);
370 t
= ggc_alloc_tree (length
);
371 memcpy (t
, node
, length
);
374 TREE_ASM_WRITTEN (t
) = 0;
376 if (TREE_CODE_CLASS (code
) == 'd')
377 DECL_UID (t
) = next_decl_uid
++;
378 else if (TREE_CODE_CLASS (code
) == 't')
380 TYPE_UID (t
) = next_type_uid
++;
381 /* The following is so that the debug code for
382 the copy is different from the original type.
383 The two statements usually duplicate each other
384 (because they clear fields of the same union),
385 but the optimizer should catch that. */
386 TYPE_SYMTAB_POINTER (t
) = 0;
387 TYPE_SYMTAB_ADDRESS (t
) = 0;
393 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
394 For example, this can copy a list made of TREE_LIST nodes. */
406 head
= prev
= copy_node (list
);
407 next
= TREE_CHAIN (list
);
410 TREE_CHAIN (prev
) = copy_node (next
);
411 prev
= TREE_CHAIN (prev
);
412 next
= TREE_CHAIN (next
);
418 /* Return a newly constructed INTEGER_CST node whose constant value
419 is specified by the two ints LOW and HI.
420 The TREE_TYPE is set to `int'.
422 This function should be used via the `build_int_2' macro. */
425 build_int_2_wide (low
, hi
)
426 unsigned HOST_WIDE_INT low
;
429 tree t
= make_node (INTEGER_CST
);
431 TREE_INT_CST_LOW (t
) = low
;
432 TREE_INT_CST_HIGH (t
) = hi
;
433 TREE_TYPE (t
) = integer_type_node
;
437 /* Return a new VECTOR_CST node whose type is TYPE and whose values
438 are in a list pointed by VALS. */
441 build_vector (type
, vals
)
444 tree v
= make_node (VECTOR_CST
);
445 int over1
= 0, over2
= 0;
448 TREE_VECTOR_CST_ELTS (v
) = vals
;
449 TREE_TYPE (v
) = type
;
451 /* Iterate through elements and check for overflow. */
452 for (link
= vals
; link
; link
= TREE_CHAIN (link
))
454 tree value
= TREE_VALUE (link
);
456 over1
|= TREE_OVERFLOW (value
);
457 over2
|= TREE_CONSTANT_OVERFLOW (value
);
460 TREE_OVERFLOW (v
) = over1
;
461 TREE_CONSTANT_OVERFLOW (v
) = over2
;
466 /* Return a new REAL_CST node whose type is TYPE and value is D. */
477 /* Check for valid float value for this type on this target machine;
478 if not, can print error message and store a valid value in D. */
479 #ifdef CHECK_FLOAT_VALUE
480 CHECK_FLOAT_VALUE (TYPE_MODE (type
), d
, overflow
);
483 v
= make_node (REAL_CST
);
484 dp
= ggc_alloc (sizeof (REAL_VALUE_TYPE
));
485 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
487 TREE_TYPE (v
) = type
;
488 TREE_REAL_CST_PTR (v
) = dp
;
489 TREE_OVERFLOW (v
) = TREE_CONSTANT_OVERFLOW (v
) = overflow
;
493 /* Return a new REAL_CST node whose type is TYPE
494 and whose value is the integer value of the INTEGER_CST node I. */
497 real_value_from_int_cst (type
, i
)
498 tree type ATTRIBUTE_UNUSED
, i
;
502 /* Clear all bits of the real value type so that we can later do
503 bitwise comparisons to see if two values are the same. */
504 memset ((char *) &d
, 0, sizeof d
);
506 if (! TREE_UNSIGNED (TREE_TYPE (i
)))
507 REAL_VALUE_FROM_INT (d
, TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
),
510 REAL_VALUE_FROM_UNSIGNED_INT (d
, TREE_INT_CST_LOW (i
),
511 TREE_INT_CST_HIGH (i
), TYPE_MODE (type
));
515 /* Given a tree representing an integer constant I, return a tree
516 representing the same value as a floating-point constant of type TYPE. */
519 build_real_from_int_cst (type
, i
)
524 int overflow
= TREE_OVERFLOW (i
);
526 v
= build_real (type
, real_value_from_int_cst (type
, i
));
528 TREE_OVERFLOW (v
) |= overflow
;
529 TREE_CONSTANT_OVERFLOW (v
) |= overflow
;
533 /* Return a newly constructed STRING_CST node whose value is
534 the LEN characters at STR.
535 The TREE_TYPE is not initialized. */
538 build_string (len
, str
)
542 tree s
= make_node (STRING_CST
);
544 TREE_STRING_LENGTH (s
) = len
;
545 TREE_STRING_POINTER (s
) = ggc_alloc_string (str
, len
);
550 /* Return a newly constructed COMPLEX_CST node whose value is
551 specified by the real and imaginary parts REAL and IMAG.
552 Both REAL and IMAG should be constant nodes. TYPE, if specified,
553 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
556 build_complex (type
, real
, imag
)
560 tree t
= make_node (COMPLEX_CST
);
562 TREE_REALPART (t
) = real
;
563 TREE_IMAGPART (t
) = imag
;
564 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
565 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
566 TREE_CONSTANT_OVERFLOW (t
)
567 = TREE_CONSTANT_OVERFLOW (real
) | TREE_CONSTANT_OVERFLOW (imag
);
571 /* Build a newly constructed TREE_VEC node of length LEN. */
578 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
580 #ifdef GATHER_STATISTICS
581 tree_node_counts
[(int) vec_kind
]++;
582 tree_node_sizes
[(int) vec_kind
] += length
;
585 t
= ggc_alloc_tree (length
);
587 memset ((PTR
) t
, 0, length
);
588 TREE_SET_CODE (t
, TREE_VEC
);
589 TREE_VEC_LENGTH (t
) = len
;
594 /* Return 1 if EXPR is the integer constant zero or a complex constant
603 return ((TREE_CODE (expr
) == INTEGER_CST
604 && ! TREE_CONSTANT_OVERFLOW (expr
)
605 && TREE_INT_CST_LOW (expr
) == 0
606 && TREE_INT_CST_HIGH (expr
) == 0)
607 || (TREE_CODE (expr
) == COMPLEX_CST
608 && integer_zerop (TREE_REALPART (expr
))
609 && integer_zerop (TREE_IMAGPART (expr
))));
612 /* Return 1 if EXPR is the integer constant one or the corresponding
621 return ((TREE_CODE (expr
) == INTEGER_CST
622 && ! TREE_CONSTANT_OVERFLOW (expr
)
623 && TREE_INT_CST_LOW (expr
) == 1
624 && TREE_INT_CST_HIGH (expr
) == 0)
625 || (TREE_CODE (expr
) == COMPLEX_CST
626 && integer_onep (TREE_REALPART (expr
))
627 && integer_zerop (TREE_IMAGPART (expr
))));
630 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
631 it contains. Likewise for the corresponding complex constant. */
634 integer_all_onesp (expr
)
642 if (TREE_CODE (expr
) == COMPLEX_CST
643 && integer_all_onesp (TREE_REALPART (expr
))
644 && integer_zerop (TREE_IMAGPART (expr
)))
647 else if (TREE_CODE (expr
) != INTEGER_CST
648 || TREE_CONSTANT_OVERFLOW (expr
))
651 uns
= TREE_UNSIGNED (TREE_TYPE (expr
));
653 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
654 && TREE_INT_CST_HIGH (expr
) == -1);
656 /* Note that using TYPE_PRECISION here is wrong. We care about the
657 actual bits, not the (arbitrary) range of the type. */
658 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr
)));
659 if (prec
>= HOST_BITS_PER_WIDE_INT
)
661 HOST_WIDE_INT high_value
;
664 shift_amount
= prec
- HOST_BITS_PER_WIDE_INT
;
666 if (shift_amount
> HOST_BITS_PER_WIDE_INT
)
667 /* Can not handle precisions greater than twice the host int size. */
669 else if (shift_amount
== HOST_BITS_PER_WIDE_INT
)
670 /* Shifting by the host word size is undefined according to the ANSI
671 standard, so we must handle this as a special case. */
674 high_value
= ((HOST_WIDE_INT
) 1 << shift_amount
) - 1;
676 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
677 && TREE_INT_CST_HIGH (expr
) == high_value
);
680 return TREE_INT_CST_LOW (expr
) == ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
683 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
691 HOST_WIDE_INT high
, low
;
695 if (TREE_CODE (expr
) == COMPLEX_CST
696 && integer_pow2p (TREE_REALPART (expr
))
697 && integer_zerop (TREE_IMAGPART (expr
)))
700 if (TREE_CODE (expr
) != INTEGER_CST
|| TREE_CONSTANT_OVERFLOW (expr
))
703 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
704 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
705 high
= TREE_INT_CST_HIGH (expr
);
706 low
= TREE_INT_CST_LOW (expr
);
708 /* First clear all bits that are beyond the type's precision in case
709 we've been sign extended. */
711 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
713 else if (prec
> HOST_BITS_PER_WIDE_INT
)
714 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
718 if (prec
< HOST_BITS_PER_WIDE_INT
)
719 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
722 if (high
== 0 && low
== 0)
725 return ((high
== 0 && (low
& (low
- 1)) == 0)
726 || (low
== 0 && (high
& (high
- 1)) == 0));
729 /* Return the power of two represented by a tree node known to be a
737 HOST_WIDE_INT high
, low
;
741 if (TREE_CODE (expr
) == COMPLEX_CST
)
742 return tree_log2 (TREE_REALPART (expr
));
744 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
745 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
747 high
= TREE_INT_CST_HIGH (expr
);
748 low
= TREE_INT_CST_LOW (expr
);
750 /* First clear all bits that are beyond the type's precision in case
751 we've been sign extended. */
753 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
755 else if (prec
> HOST_BITS_PER_WIDE_INT
)
756 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
760 if (prec
< HOST_BITS_PER_WIDE_INT
)
761 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
764 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ exact_log2 (high
)
768 /* Similar, but return the largest integer Y such that 2 ** Y is less
769 than or equal to EXPR. */
772 tree_floor_log2 (expr
)
776 HOST_WIDE_INT high
, low
;
780 if (TREE_CODE (expr
) == COMPLEX_CST
)
781 return tree_log2 (TREE_REALPART (expr
));
783 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
784 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
786 high
= TREE_INT_CST_HIGH (expr
);
787 low
= TREE_INT_CST_LOW (expr
);
789 /* First clear all bits that are beyond the type's precision in case
790 we've been sign extended. Ignore if type's precision hasn't been set
791 since what we are doing is setting it. */
793 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
|| prec
== 0)
795 else if (prec
> HOST_BITS_PER_WIDE_INT
)
796 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
800 if (prec
< HOST_BITS_PER_WIDE_INT
)
801 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
804 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ floor_log2 (high
)
808 /* Return 1 if EXPR is the real constant zero. */
816 return ((TREE_CODE (expr
) == REAL_CST
817 && ! TREE_CONSTANT_OVERFLOW (expr
)
818 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
))
819 || (TREE_CODE (expr
) == COMPLEX_CST
820 && real_zerop (TREE_REALPART (expr
))
821 && real_zerop (TREE_IMAGPART (expr
))));
824 /* Return 1 if EXPR is the real constant one in real or complex form. */
832 return ((TREE_CODE (expr
) == REAL_CST
833 && ! TREE_CONSTANT_OVERFLOW (expr
)
834 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
))
835 || (TREE_CODE (expr
) == COMPLEX_CST
836 && real_onep (TREE_REALPART (expr
))
837 && real_zerop (TREE_IMAGPART (expr
))));
840 /* Return 1 if EXPR is the real constant two. */
848 return ((TREE_CODE (expr
) == REAL_CST
849 && ! TREE_CONSTANT_OVERFLOW (expr
)
850 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst2
))
851 || (TREE_CODE (expr
) == COMPLEX_CST
852 && real_twop (TREE_REALPART (expr
))
853 && real_zerop (TREE_IMAGPART (expr
))));
856 /* Return 1 if EXPR is the real constant minus one. */
859 real_minus_onep (expr
)
864 return ((TREE_CODE (expr
) == REAL_CST
865 && ! TREE_CONSTANT_OVERFLOW (expr
)
866 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconstm1
))
867 || (TREE_CODE (expr
) == COMPLEX_CST
868 && real_minus_onep (TREE_REALPART (expr
))
869 && real_zerop (TREE_IMAGPART (expr
))));
872 /* Nonzero if EXP is a constant or a cast of a constant. */
875 really_constant_p (exp
)
878 /* This is not quite the same as STRIP_NOPS. It does more. */
879 while (TREE_CODE (exp
) == NOP_EXPR
880 || TREE_CODE (exp
) == CONVERT_EXPR
881 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
882 exp
= TREE_OPERAND (exp
, 0);
883 return TREE_CONSTANT (exp
);
886 /* Return first list element whose TREE_VALUE is ELEM.
887 Return 0 if ELEM is not in LIST. */
890 value_member (elem
, list
)
895 if (elem
== TREE_VALUE (list
))
897 list
= TREE_CHAIN (list
);
902 /* Return first list element whose TREE_PURPOSE is ELEM.
903 Return 0 if ELEM is not in LIST. */
906 purpose_member (elem
, list
)
911 if (elem
== TREE_PURPOSE (list
))
913 list
= TREE_CHAIN (list
);
918 /* Return first list element whose BINFO_TYPE is ELEM.
919 Return 0 if ELEM is not in LIST. */
922 binfo_member (elem
, list
)
927 if (elem
== BINFO_TYPE (list
))
929 list
= TREE_CHAIN (list
);
934 /* Return nonzero if ELEM is part of the chain CHAIN. */
937 chain_member (elem
, chain
)
944 chain
= TREE_CHAIN (chain
);
950 /* Return nonzero if ELEM is equal to TREE_VALUE (CHAIN) for any piece of
951 chain CHAIN. This and the next function are currently unused, but
952 are retained for completeness. */
955 chain_member_value (elem
, chain
)
960 if (elem
== TREE_VALUE (chain
))
962 chain
= TREE_CHAIN (chain
);
968 /* Return nonzero if ELEM is equal to TREE_PURPOSE (CHAIN)
969 for any piece of chain CHAIN. */
972 chain_member_purpose (elem
, chain
)
977 if (elem
== TREE_PURPOSE (chain
))
979 chain
= TREE_CHAIN (chain
);
985 /* Return the length of a chain of nodes chained through TREE_CHAIN.
986 We expect a null pointer to mark the end of the chain.
987 This is the Lisp primitive `length'. */
996 for (tail
= t
; tail
; tail
= TREE_CHAIN (tail
))
1002 /* Returns the number of FIELD_DECLs in TYPE. */
1005 fields_length (type
)
1008 tree t
= TYPE_FIELDS (type
);
1011 for (; t
; t
= TREE_CHAIN (t
))
1012 if (TREE_CODE (t
) == FIELD_DECL
)
1018 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1019 by modifying the last node in chain 1 to point to chain 2.
1020 This is the Lisp primitive `nconc'. */
1030 #ifdef ENABLE_TREE_CHECKING
1034 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
1036 TREE_CHAIN (t1
) = op2
;
1037 #ifdef ENABLE_TREE_CHECKING
1038 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
1040 abort (); /* Circularity created. */
1048 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1056 while ((next
= TREE_CHAIN (chain
)))
1061 /* Reverse the order of elements in the chain T,
1062 and return the new head of the chain (old last element). */
1068 tree prev
= 0, decl
, next
;
1069 for (decl
= t
; decl
; decl
= next
)
1071 next
= TREE_CHAIN (decl
);
1072 TREE_CHAIN (decl
) = prev
;
1078 /* Given a chain CHAIN of tree nodes,
1079 construct and return a list of those nodes. */
1085 tree result
= NULL_TREE
;
1086 tree in_tail
= chain
;
1087 tree out_tail
= NULL_TREE
;
1091 tree next
= tree_cons (NULL_TREE
, in_tail
, NULL_TREE
);
1093 TREE_CHAIN (out_tail
) = next
;
1097 in_tail
= TREE_CHAIN (in_tail
);
1103 /* Return a newly created TREE_LIST node whose
1104 purpose and value fields are PARM and VALUE. */
1107 build_tree_list (parm
, value
)
1110 tree t
= make_node (TREE_LIST
);
1111 TREE_PURPOSE (t
) = parm
;
1112 TREE_VALUE (t
) = value
;
1116 /* Return a newly created TREE_LIST node whose
1117 purpose and value fields are PARM and VALUE
1118 and whose TREE_CHAIN is CHAIN. */
1121 tree_cons (purpose
, value
, chain
)
1122 tree purpose
, value
, chain
;
1126 node
= ggc_alloc_tree (sizeof (struct tree_list
));
1128 memset (node
, 0, sizeof (struct tree_common
));
1130 #ifdef GATHER_STATISTICS
1131 tree_node_counts
[(int) x_kind
]++;
1132 tree_node_sizes
[(int) x_kind
] += sizeof (struct tree_list
);
1135 TREE_SET_CODE (node
, TREE_LIST
);
1136 TREE_CHAIN (node
) = chain
;
1137 TREE_PURPOSE (node
) = purpose
;
1138 TREE_VALUE (node
) = value
;
1143 /* Return the size nominally occupied by an object of type TYPE
1144 when it resides in memory. The value is measured in units of bytes,
1145 and its data type is that normally used for type sizes
1146 (which is the first type created by make_signed_type or
1147 make_unsigned_type). */
1150 size_in_bytes (type
)
1155 if (type
== error_mark_node
)
1156 return integer_zero_node
;
1158 type
= TYPE_MAIN_VARIANT (type
);
1159 t
= TYPE_SIZE_UNIT (type
);
1163 (*lang_hooks
.types
.incomplete_type_error
) (NULL_TREE
, type
);
1164 return size_zero_node
;
1167 if (TREE_CODE (t
) == INTEGER_CST
)
1168 force_fit_type (t
, 0);
1173 /* Return the size of TYPE (in bytes) as a wide integer
1174 or return -1 if the size can vary or is larger than an integer. */
1177 int_size_in_bytes (type
)
1182 if (type
== error_mark_node
)
1185 type
= TYPE_MAIN_VARIANT (type
);
1186 t
= TYPE_SIZE_UNIT (type
);
1188 || TREE_CODE (t
) != INTEGER_CST
1189 || TREE_OVERFLOW (t
)
1190 || TREE_INT_CST_HIGH (t
) != 0
1191 /* If the result would appear negative, it's too big to represent. */
1192 || (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0)
1195 return TREE_INT_CST_LOW (t
);
1198 /* Return the bit position of FIELD, in bits from the start of the record.
1199 This is a tree of type bitsizetype. */
1202 bit_position (field
)
1206 return bit_from_pos (DECL_FIELD_OFFSET (field
),
1207 DECL_FIELD_BIT_OFFSET (field
));
1210 /* Likewise, but return as an integer. Abort if it cannot be represented
1211 in that way (since it could be a signed value, we don't have the option
1212 of returning -1 like int_size_in_byte can. */
1215 int_bit_position (field
)
1218 return tree_low_cst (bit_position (field
), 0);
1221 /* Return the byte position of FIELD, in bytes from the start of the record.
1222 This is a tree of type sizetype. */
1225 byte_position (field
)
1228 return byte_from_pos (DECL_FIELD_OFFSET (field
),
1229 DECL_FIELD_BIT_OFFSET (field
));
1232 /* Likewise, but return as an integer. Abort if it cannot be represented
1233 in that way (since it could be a signed value, we don't have the option
1234 of returning -1 like int_size_in_byte can. */
1237 int_byte_position (field
)
1240 return tree_low_cst (byte_position (field
), 0);
1243 /* Return the strictest alignment, in bits, that T is known to have. */
1249 unsigned int align0
, align1
;
1251 switch (TREE_CODE (t
))
1253 case NOP_EXPR
: case CONVERT_EXPR
: case NON_LVALUE_EXPR
:
1254 /* If we have conversions, we know that the alignment of the
1255 object must meet each of the alignments of the types. */
1256 align0
= expr_align (TREE_OPERAND (t
, 0));
1257 align1
= TYPE_ALIGN (TREE_TYPE (t
));
1258 return MAX (align0
, align1
);
1260 case SAVE_EXPR
: case COMPOUND_EXPR
: case MODIFY_EXPR
:
1261 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
1262 case WITH_RECORD_EXPR
: case CLEANUP_POINT_EXPR
: case UNSAVE_EXPR
:
1263 /* These don't change the alignment of an object. */
1264 return expr_align (TREE_OPERAND (t
, 0));
1267 /* The best we can do is say that the alignment is the least aligned
1269 align0
= expr_align (TREE_OPERAND (t
, 1));
1270 align1
= expr_align (TREE_OPERAND (t
, 2));
1271 return MIN (align0
, align1
);
1273 case LABEL_DECL
: case CONST_DECL
:
1274 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
1275 if (DECL_ALIGN (t
) != 0)
1276 return DECL_ALIGN (t
);
1280 return FUNCTION_BOUNDARY
;
1286 /* Otherwise take the alignment from that of the type. */
1287 return TYPE_ALIGN (TREE_TYPE (t
));
1290 /* Return, as a tree node, the number of elements for TYPE (which is an
1291 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1294 array_type_nelts (type
)
1297 tree index_type
, min
, max
;
1299 /* If they did it with unspecified bounds, then we should have already
1300 given an error about it before we got here. */
1301 if (! TYPE_DOMAIN (type
))
1302 return error_mark_node
;
1304 index_type
= TYPE_DOMAIN (type
);
1305 min
= TYPE_MIN_VALUE (index_type
);
1306 max
= TYPE_MAX_VALUE (index_type
);
1308 return (integer_zerop (min
)
1310 : fold (build (MINUS_EXPR
, TREE_TYPE (max
), max
, min
)));
1313 /* Return nonzero if arg is static -- a reference to an object in
1314 static storage. This is not the same as the C meaning of `static'. */
1320 switch (TREE_CODE (arg
))
1323 /* Nested functions aren't static, since taking their address
1324 involves a trampoline. */
1325 return ((decl_function_context (arg
) == 0 || DECL_NO_STATIC_CHAIN (arg
))
1326 && ! DECL_NON_ADDR_CONST_P (arg
));
1329 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
1330 && ! DECL_THREAD_LOCAL (arg
)
1331 && ! DECL_NON_ADDR_CONST_P (arg
));
1334 return TREE_STATIC (arg
);
1340 /* If we are referencing a bitfield, we can't evaluate an
1341 ADDR_EXPR at compile time and so it isn't a constant. */
1343 return (! DECL_BIT_FIELD (TREE_OPERAND (arg
, 1))
1344 && staticp (TREE_OPERAND (arg
, 0)));
1350 /* This case is technically correct, but results in setting
1351 TREE_CONSTANT on ADDR_EXPRs that cannot be evaluated at
1354 return TREE_CONSTANT (TREE_OPERAND (arg
, 0));
1358 case ARRAY_RANGE_REF
:
1359 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
1360 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
1361 return staticp (TREE_OPERAND (arg
, 0));
1364 if ((unsigned int) TREE_CODE (arg
)
1365 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
1366 return (*lang_hooks
.staticp
) (arg
);
1372 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
1373 Do this to any expression which may be used in more than one place,
1374 but must be evaluated only once.
1376 Normally, expand_expr would reevaluate the expression each time.
1377 Calling save_expr produces something that is evaluated and recorded
1378 the first time expand_expr is called on it. Subsequent calls to
1379 expand_expr just reuse the recorded value.
1381 The call to expand_expr that generates code that actually computes
1382 the value is the first call *at compile time*. Subsequent calls
1383 *at compile time* generate code to use the saved value.
1384 This produces correct result provided that *at run time* control
1385 always flows through the insns made by the first expand_expr
1386 before reaching the other places where the save_expr was evaluated.
1387 You, the caller of save_expr, must make sure this is so.
1389 Constants, and certain read-only nodes, are returned with no
1390 SAVE_EXPR because that is safe. Expressions containing placeholders
1391 are not touched; see tree.def for an explanation of what these
1398 tree t
= fold (expr
);
1401 /* We don't care about whether this can be used as an lvalue in this
1403 while (TREE_CODE (t
) == NON_LVALUE_EXPR
)
1404 t
= TREE_OPERAND (t
, 0);
1406 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
1407 a constant, it will be more efficient to not make another SAVE_EXPR since
1408 it will allow better simplification and GCSE will be able to merge the
1409 computations if they actualy occur. */
1411 (TREE_CODE_CLASS (TREE_CODE (inner
)) == '1'
1412 || (TREE_CODE_CLASS (TREE_CODE (inner
)) == '2'
1413 && TREE_CONSTANT (TREE_OPERAND (inner
, 1))));
1414 inner
= TREE_OPERAND (inner
, 0))
1417 /* If the tree evaluates to a constant, then we don't want to hide that
1418 fact (i.e. this allows further folding, and direct checks for constants).
1419 However, a read-only object that has side effects cannot be bypassed.
1420 Since it is no problem to reevaluate literals, we just return the
1422 if (TREE_CONSTANT (inner
)
1423 || (TREE_READONLY (inner
) && ! TREE_SIDE_EFFECTS (inner
))
1424 || TREE_CODE (inner
) == SAVE_EXPR
|| TREE_CODE (inner
) == ERROR_MARK
)
1427 /* If T contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
1428 it means that the size or offset of some field of an object depends on
1429 the value within another field.
1431 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
1432 and some variable since it would then need to be both evaluated once and
1433 evaluated more than once. Front-ends must assure this case cannot
1434 happen by surrounding any such subexpressions in their own SAVE_EXPR
1435 and forcing evaluation at the proper time. */
1436 if (contains_placeholder_p (t
))
1439 t
= build (SAVE_EXPR
, TREE_TYPE (expr
), t
, current_function_decl
, NULL_TREE
);
1441 /* This expression might be placed ahead of a jump to ensure that the
1442 value was computed on both sides of the jump. So make sure it isn't
1443 eliminated as dead. */
1444 TREE_SIDE_EFFECTS (t
) = 1;
1445 TREE_READONLY (t
) = 1;
1449 /* Arrange for an expression to be expanded multiple independent
1450 times. This is useful for cleanup actions, as the backend can
1451 expand them multiple times in different places. */
1459 /* If this is already protected, no sense in protecting it again. */
1460 if (TREE_CODE (expr
) == UNSAVE_EXPR
)
1463 t
= build1 (UNSAVE_EXPR
, TREE_TYPE (expr
), expr
);
1464 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (expr
);
1468 /* Returns the index of the first non-tree operand for CODE, or the number
1469 of operands if all are trees. */
1473 enum tree_code code
;
1479 case GOTO_SUBROUTINE_EXPR
:
1482 case WITH_CLEANUP_EXPR
:
1484 case METHOD_CALL_EXPR
:
1487 return TREE_CODE_LENGTH (code
);
1491 /* Return which tree structure is used by T. */
1493 enum tree_node_structure_enum
1494 tree_node_structure (t
)
1497 enum tree_code code
= TREE_CODE (t
);
1499 switch (TREE_CODE_CLASS (code
))
1501 case 'd': return TS_DECL
;
1502 case 't': return TS_TYPE
;
1503 case 'b': return TS_BLOCK
;
1504 case 'r': case '<': case '1': case '2': case 'e': case 's':
1506 default: /* 'c' and 'x' */
1512 case INTEGER_CST
: return TS_INT_CST
;
1513 case REAL_CST
: return TS_REAL_CST
;
1514 case COMPLEX_CST
: return TS_COMPLEX
;
1515 case VECTOR_CST
: return TS_VECTOR
;
1516 case STRING_CST
: return TS_STRING
;
1518 case ERROR_MARK
: return TS_COMMON
;
1519 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
1520 case TREE_LIST
: return TS_LIST
;
1521 case TREE_VEC
: return TS_VEC
;
1522 case PLACEHOLDER_EXPR
: return TS_COMMON
;
1529 /* Perform any modifications to EXPR required when it is unsaved. Does
1530 not recurse into EXPR's subtrees. */
1533 unsave_expr_1 (expr
)
1536 switch (TREE_CODE (expr
))
1539 if (! SAVE_EXPR_PERSISTENT_P (expr
))
1540 SAVE_EXPR_RTL (expr
) = 0;
1544 /* Don't mess with a TARGET_EXPR that hasn't been expanded.
1545 It's OK for this to happen if it was part of a subtree that
1546 isn't immediately expanded, such as operand 2 of another
1548 if (TREE_OPERAND (expr
, 1))
1551 TREE_OPERAND (expr
, 1) = TREE_OPERAND (expr
, 3);
1552 TREE_OPERAND (expr
, 3) = NULL_TREE
;
1556 /* I don't yet know how to emit a sequence multiple times. */
1557 if (RTL_EXPR_SEQUENCE (expr
) != 0)
1566 /* Default lang hook for "unsave_expr_now". */
1569 lhd_unsave_expr_now (expr
)
1572 enum tree_code code
;
1574 /* There's nothing to do for NULL_TREE. */
1578 unsave_expr_1 (expr
);
1580 code
= TREE_CODE (expr
);
1581 switch (TREE_CODE_CLASS (code
))
1583 case 'c': /* a constant */
1584 case 't': /* a type node */
1585 case 'd': /* A decl node */
1586 case 'b': /* A block node */
1589 case 'x': /* miscellaneous: e.g., identifier, TREE_LIST or ERROR_MARK. */
1590 if (code
== TREE_LIST
)
1592 lhd_unsave_expr_now (TREE_VALUE (expr
));
1593 lhd_unsave_expr_now (TREE_CHAIN (expr
));
1597 case 'e': /* an expression */
1598 case 'r': /* a reference */
1599 case 's': /* an expression with side effects */
1600 case '<': /* a comparison expression */
1601 case '2': /* a binary arithmetic expression */
1602 case '1': /* a unary arithmetic expression */
1606 for (i
= first_rtl_op (code
) - 1; i
>= 0; i
--)
1607 lhd_unsave_expr_now (TREE_OPERAND (expr
, i
));
1618 /* Return 0 if it is safe to evaluate EXPR multiple times,
1619 return 1 if it is safe if EXPR is unsaved afterward, or
1620 return 2 if it is completely unsafe.
1622 This assumes that CALL_EXPRs and TARGET_EXPRs are never replicated in
1623 an expression tree, so that it safe to unsave them and the surrounding
1624 context will be correct.
1626 SAVE_EXPRs basically *only* appear replicated in an expression tree,
1627 occasionally across the whole of a function. It is therefore only
1628 safe to unsave a SAVE_EXPR if you know that all occurrences appear
1629 below the UNSAVE_EXPR.
1631 RTL_EXPRs consume their rtl during evaluation. It is therefore
1632 never possible to unsave them. */
1635 unsafe_for_reeval (expr
)
1639 enum tree_code code
;
1644 if (expr
== NULL_TREE
)
1647 code
= TREE_CODE (expr
);
1648 first_rtl
= first_rtl_op (code
);
1657 for (exp
= expr
; exp
!= 0; exp
= TREE_CHAIN (exp
))
1659 tmp
= unsafe_for_reeval (TREE_VALUE (exp
));
1660 unsafeness
= MAX (tmp
, unsafeness
);
1666 tmp
= unsafe_for_reeval (TREE_OPERAND (expr
, 1));
1667 return MAX (tmp
, 1);
1674 tmp
= (*lang_hooks
.unsafe_for_reeval
) (expr
);
1680 switch (TREE_CODE_CLASS (code
))
1682 case 'c': /* a constant */
1683 case 't': /* a type node */
1684 case 'x': /* something random, like an identifier or an ERROR_MARK. */
1685 case 'd': /* A decl node */
1686 case 'b': /* A block node */
1689 case 'e': /* an expression */
1690 case 'r': /* a reference */
1691 case 's': /* an expression with side effects */
1692 case '<': /* a comparison expression */
1693 case '2': /* a binary arithmetic expression */
1694 case '1': /* a unary arithmetic expression */
1695 for (i
= first_rtl
- 1; i
>= 0; i
--)
1697 tmp
= unsafe_for_reeval (TREE_OPERAND (expr
, i
));
1698 unsafeness
= MAX (tmp
, unsafeness
);
1708 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
1709 or offset that depends on a field within a record. */
1712 contains_placeholder_p (exp
)
1715 enum tree_code code
;
1721 /* If we have a WITH_RECORD_EXPR, it "cancels" any PLACEHOLDER_EXPR
1722 in it since it is supplying a value for it. */
1723 code
= TREE_CODE (exp
);
1724 if (code
== WITH_RECORD_EXPR
)
1726 else if (code
== PLACEHOLDER_EXPR
)
1729 switch (TREE_CODE_CLASS (code
))
1732 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
1733 position computations since they will be converted into a
1734 WITH_RECORD_EXPR involving the reference, which will assume
1735 here will be valid. */
1736 return contains_placeholder_p (TREE_OPERAND (exp
, 0));
1739 if (code
== TREE_LIST
)
1740 return (contains_placeholder_p (TREE_VALUE (exp
))
1741 || (TREE_CHAIN (exp
) != 0
1742 && contains_placeholder_p (TREE_CHAIN (exp
))));
1751 /* Ignoring the first operand isn't quite right, but works best. */
1752 return contains_placeholder_p (TREE_OPERAND (exp
, 1));
1759 return (contains_placeholder_p (TREE_OPERAND (exp
, 0))
1760 || contains_placeholder_p (TREE_OPERAND (exp
, 1))
1761 || contains_placeholder_p (TREE_OPERAND (exp
, 2)));
1764 /* If we already know this doesn't have a placeholder, don't
1766 if (SAVE_EXPR_NOPLACEHOLDER (exp
) || SAVE_EXPR_RTL (exp
) != 0)
1769 SAVE_EXPR_NOPLACEHOLDER (exp
) = 1;
1770 result
= contains_placeholder_p (TREE_OPERAND (exp
, 0));
1772 SAVE_EXPR_NOPLACEHOLDER (exp
) = 0;
1777 return (TREE_OPERAND (exp
, 1) != 0
1778 && contains_placeholder_p (TREE_OPERAND (exp
, 1)));
1784 switch (TREE_CODE_LENGTH (code
))
1787 return contains_placeholder_p (TREE_OPERAND (exp
, 0));
1789 return (contains_placeholder_p (TREE_OPERAND (exp
, 0))
1790 || contains_placeholder_p (TREE_OPERAND (exp
, 1)));
1801 /* Return 1 if EXP contains any expressions that produce cleanups for an
1802 outer scope to deal with. Used by fold. */
1810 if (! TREE_SIDE_EFFECTS (exp
))
1813 switch (TREE_CODE (exp
))
1816 case GOTO_SUBROUTINE_EXPR
:
1817 case WITH_CLEANUP_EXPR
:
1820 case CLEANUP_POINT_EXPR
:
1824 for (exp
= TREE_OPERAND (exp
, 1); exp
; exp
= TREE_CHAIN (exp
))
1826 cmp
= has_cleanups (TREE_VALUE (exp
));
1836 /* This general rule works for most tree codes. All exceptions should be
1837 handled above. If this is a language-specific tree code, we can't
1838 trust what might be in the operand, so say we don't know
1840 if ((int) TREE_CODE (exp
) >= (int) LAST_AND_UNUSED_TREE_CODE
)
1843 nops
= first_rtl_op (TREE_CODE (exp
));
1844 for (i
= 0; i
< nops
; i
++)
1845 if (TREE_OPERAND (exp
, i
) != 0)
1847 int type
= TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp
, i
)));
1848 if (type
== 'e' || type
== '<' || type
== '1' || type
== '2'
1849 || type
== 'r' || type
== 's')
1851 cmp
= has_cleanups (TREE_OPERAND (exp
, i
));
1860 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
1861 return a tree with all occurrences of references to F in a
1862 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
1863 contains only arithmetic expressions or a CALL_EXPR with a
1864 PLACEHOLDER_EXPR occurring only in its arglist. */
1867 substitute_in_expr (exp
, f
, r
)
1872 enum tree_code code
= TREE_CODE (exp
);
1877 switch (TREE_CODE_CLASS (code
))
1884 if (code
== PLACEHOLDER_EXPR
)
1886 else if (code
== TREE_LIST
)
1888 op0
= (TREE_CHAIN (exp
) == 0
1889 ? 0 : substitute_in_expr (TREE_CHAIN (exp
), f
, r
));
1890 op1
= substitute_in_expr (TREE_VALUE (exp
), f
, r
);
1891 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
1894 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
1903 switch (TREE_CODE_LENGTH (code
))
1906 op0
= substitute_in_expr (TREE_OPERAND (exp
, 0), f
, r
);
1907 if (op0
== TREE_OPERAND (exp
, 0))
1910 if (code
== NON_LVALUE_EXPR
)
1913 new = fold (build1 (code
, TREE_TYPE (exp
), op0
));
1917 /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR
1918 could, but we don't support it. */
1919 if (code
== RTL_EXPR
)
1921 else if (code
== CONSTRUCTOR
)
1924 op0
= substitute_in_expr (TREE_OPERAND (exp
, 0), f
, r
);
1925 op1
= substitute_in_expr (TREE_OPERAND (exp
, 1), f
, r
);
1926 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
1929 new = fold (build (code
, TREE_TYPE (exp
), op0
, op1
));
1933 /* It cannot be that anything inside a SAVE_EXPR contains a
1934 PLACEHOLDER_EXPR. */
1935 if (code
== SAVE_EXPR
)
1938 else if (code
== CALL_EXPR
)
1940 op1
= substitute_in_expr (TREE_OPERAND (exp
, 1), f
, r
);
1941 if (op1
== TREE_OPERAND (exp
, 1))
1944 return build (code
, TREE_TYPE (exp
),
1945 TREE_OPERAND (exp
, 0), op1
, NULL_TREE
);
1948 else if (code
!= COND_EXPR
)
1951 op0
= substitute_in_expr (TREE_OPERAND (exp
, 0), f
, r
);
1952 op1
= substitute_in_expr (TREE_OPERAND (exp
, 1), f
, r
);
1953 op2
= substitute_in_expr (TREE_OPERAND (exp
, 2), f
, r
);
1954 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
1955 && op2
== TREE_OPERAND (exp
, 2))
1958 new = fold (build (code
, TREE_TYPE (exp
), op0
, op1
, op2
));
1971 /* If this expression is getting a value from a PLACEHOLDER_EXPR
1972 and it is the right field, replace it with R. */
1973 for (inner
= TREE_OPERAND (exp
, 0);
1974 TREE_CODE_CLASS (TREE_CODE (inner
)) == 'r';
1975 inner
= TREE_OPERAND (inner
, 0))
1977 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
1978 && TREE_OPERAND (exp
, 1) == f
)
1981 /* If this expression hasn't been completed let, leave it
1983 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
1984 && TREE_TYPE (inner
) == 0)
1987 op0
= substitute_in_expr (TREE_OPERAND (exp
, 0), f
, r
);
1988 if (op0
== TREE_OPERAND (exp
, 0))
1991 new = fold (build (code
, TREE_TYPE (exp
), op0
,
1992 TREE_OPERAND (exp
, 1)));
1996 op0
= substitute_in_expr (TREE_OPERAND (exp
, 0), f
, r
);
1997 op1
= substitute_in_expr (TREE_OPERAND (exp
, 1), f
, r
);
1998 op2
= substitute_in_expr (TREE_OPERAND (exp
, 2), f
, r
);
1999 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2000 && op2
== TREE_OPERAND (exp
, 2))
2003 new = fold (build (code
, TREE_TYPE (exp
), op0
, op1
, op2
));
2008 op0
= substitute_in_expr (TREE_OPERAND (exp
, 0), f
, r
);
2009 if (op0
== TREE_OPERAND (exp
, 0))
2012 new = fold (build1 (code
, TREE_TYPE (exp
), op0
));
2024 TREE_READONLY (new) = TREE_READONLY (exp
);
2028 /* Stabilize a reference so that we can use it any number of times
2029 without causing its operands to be evaluated more than once.
2030 Returns the stabilized reference. This works by means of save_expr,
2031 so see the caveats in the comments about save_expr.
2033 Also allows conversion expressions whose operands are references.
2034 Any other kind of expression is returned unchanged. */
2037 stabilize_reference (ref
)
2041 enum tree_code code
= TREE_CODE (ref
);
2048 /* No action is needed in this case. */
2054 case FIX_TRUNC_EXPR
:
2055 case FIX_FLOOR_EXPR
:
2056 case FIX_ROUND_EXPR
:
2058 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
2062 result
= build_nt (INDIRECT_REF
,
2063 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
2067 result
= build_nt (COMPONENT_REF
,
2068 stabilize_reference (TREE_OPERAND (ref
, 0)),
2069 TREE_OPERAND (ref
, 1));
2073 result
= build_nt (BIT_FIELD_REF
,
2074 stabilize_reference (TREE_OPERAND (ref
, 0)),
2075 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2076 stabilize_reference_1 (TREE_OPERAND (ref
, 2)));
2080 result
= build_nt (ARRAY_REF
,
2081 stabilize_reference (TREE_OPERAND (ref
, 0)),
2082 stabilize_reference_1 (TREE_OPERAND (ref
, 1)));
2085 case ARRAY_RANGE_REF
:
2086 result
= build_nt (ARRAY_RANGE_REF
,
2087 stabilize_reference (TREE_OPERAND (ref
, 0)),
2088 stabilize_reference_1 (TREE_OPERAND (ref
, 1)));
2092 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2093 it wouldn't be ignored. This matters when dealing with
2095 return stabilize_reference_1 (ref
);
2098 result
= build1 (INDIRECT_REF
, TREE_TYPE (ref
),
2099 save_expr (build1 (ADDR_EXPR
,
2100 build_pointer_type (TREE_TYPE (ref
)),
2104 /* If arg isn't a kind of lvalue we recognize, make no change.
2105 Caller should recognize the error for an invalid lvalue. */
2110 return error_mark_node
;
2113 TREE_TYPE (result
) = TREE_TYPE (ref
);
2114 TREE_READONLY (result
) = TREE_READONLY (ref
);
2115 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
2116 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
2121 /* Subroutine of stabilize_reference; this is called for subtrees of
2122 references. Any expression with side-effects must be put in a SAVE_EXPR
2123 to ensure that it is only evaluated once.
2125 We don't put SAVE_EXPR nodes around everything, because assigning very
2126 simple expressions to temporaries causes us to miss good opportunities
2127 for optimizations. Among other things, the opportunity to fold in the
2128 addition of a constant into an addressing mode often gets lost, e.g.
2129 "y[i+1] += x;". In general, we take the approach that we should not make
2130 an assignment unless we are forced into it - i.e., that any non-side effect
2131 operator should be allowed, and that cse should take care of coalescing
2132 multiple utterances of the same expression should that prove fruitful. */
2135 stabilize_reference_1 (e
)
2139 enum tree_code code
= TREE_CODE (e
);
2141 /* We cannot ignore const expressions because it might be a reference
2142 to a const array but whose index contains side-effects. But we can
2143 ignore things that are actual constant or that already have been
2144 handled by this function. */
2146 if (TREE_CONSTANT (e
) || code
== SAVE_EXPR
)
2149 switch (TREE_CODE_CLASS (code
))
2159 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2160 so that it will only be evaluated once. */
2161 /* The reference (r) and comparison (<) classes could be handled as
2162 below, but it is generally faster to only evaluate them once. */
2163 if (TREE_SIDE_EFFECTS (e
))
2164 return save_expr (e
);
2168 /* Constants need no processing. In fact, we should never reach
2173 /* Division is slow and tends to be compiled with jumps,
2174 especially the division by powers of 2 that is often
2175 found inside of an array reference. So do it just once. */
2176 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
2177 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
2178 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
2179 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
2180 return save_expr (e
);
2181 /* Recursively stabilize each operand. */
2182 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
2183 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
2187 /* Recursively stabilize each operand. */
2188 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
2195 TREE_TYPE (result
) = TREE_TYPE (e
);
2196 TREE_READONLY (result
) = TREE_READONLY (e
);
2197 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
2198 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
2203 /* Low-level constructors for expressions. */
2205 /* Build an expression of code CODE, data type TYPE,
2206 and operands as specified by the arguments ARG1 and following arguments.
2207 Expressions and reference nodes can be created this way.
2208 Constants, decls, types and misc nodes cannot be. */
2211 build
VPARAMS ((enum tree_code code
, tree tt
, ...))
2220 VA_FIXEDARG (p
, enum tree_code
, code
);
2221 VA_FIXEDARG (p
, tree
, tt
);
2223 t
= make_node (code
);
2224 length
= TREE_CODE_LENGTH (code
);
2227 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
2228 result based on those same flags for the arguments. But if the
2229 arguments aren't really even `tree' expressions, we shouldn't be trying
2231 fro
= first_rtl_op (code
);
2233 /* Expressions without side effects may be constant if their
2234 arguments are as well. */
2235 constant
= (TREE_CODE_CLASS (code
) == '<'
2236 || TREE_CODE_CLASS (code
) == '1'
2237 || TREE_CODE_CLASS (code
) == '2'
2238 || TREE_CODE_CLASS (code
) == 'c');
2242 /* This is equivalent to the loop below, but faster. */
2243 tree arg0
= va_arg (p
, tree
);
2244 tree arg1
= va_arg (p
, tree
);
2246 TREE_OPERAND (t
, 0) = arg0
;
2247 TREE_OPERAND (t
, 1) = arg1
;
2248 TREE_READONLY (t
) = 1;
2249 if (arg0
&& fro
> 0)
2251 if (TREE_SIDE_EFFECTS (arg0
))
2252 TREE_SIDE_EFFECTS (t
) = 1;
2253 if (!TREE_READONLY (arg0
))
2254 TREE_READONLY (t
) = 0;
2255 if (!TREE_CONSTANT (arg0
))
2259 if (arg1
&& fro
> 1)
2261 if (TREE_SIDE_EFFECTS (arg1
))
2262 TREE_SIDE_EFFECTS (t
) = 1;
2263 if (!TREE_READONLY (arg1
))
2264 TREE_READONLY (t
) = 0;
2265 if (!TREE_CONSTANT (arg1
))
2269 else if (length
== 1)
2271 tree arg0
= va_arg (p
, tree
);
2273 /* The only one-operand cases we handle here are those with side-effects.
2274 Others are handled with build1. So don't bother checked if the
2275 arg has side-effects since we'll already have set it.
2277 ??? This really should use build1 too. */
2278 if (TREE_CODE_CLASS (code
) != 's')
2280 TREE_OPERAND (t
, 0) = arg0
;
2284 for (i
= 0; i
< length
; i
++)
2286 tree operand
= va_arg (p
, tree
);
2288 TREE_OPERAND (t
, i
) = operand
;
2289 if (operand
&& fro
> i
)
2291 if (TREE_SIDE_EFFECTS (operand
))
2292 TREE_SIDE_EFFECTS (t
) = 1;
2293 if (!TREE_CONSTANT (operand
))
2300 TREE_CONSTANT (t
) = constant
;
2304 /* Same as above, but only builds for unary operators.
2305 Saves lions share of calls to `build'; cuts down use
2306 of varargs, which is expensive for RISC machines. */
2309 build1 (code
, type
, node
)
2310 enum tree_code code
;
2315 #ifdef GATHER_STATISTICS
2316 tree_node_kind kind
;
2320 #ifdef GATHER_STATISTICS
2321 if (TREE_CODE_CLASS (code
) == 'r')
2327 #ifdef ENABLE_CHECKING
2328 if (TREE_CODE_CLASS (code
) == '2'
2329 || TREE_CODE_CLASS (code
) == '<'
2330 || TREE_CODE_LENGTH (code
) != 1)
2332 #endif /* ENABLE_CHECKING */
2334 length
= sizeof (struct tree_exp
);
2336 t
= ggc_alloc_tree (length
);
2338 memset ((PTR
) t
, 0, sizeof (struct tree_common
));
2340 #ifdef GATHER_STATISTICS
2341 tree_node_counts
[(int) kind
]++;
2342 tree_node_sizes
[(int) kind
] += length
;
2345 TREE_SET_CODE (t
, code
);
2347 TREE_TYPE (t
) = type
;
2348 TREE_COMPLEXITY (t
) = 0;
2349 TREE_OPERAND (t
, 0) = node
;
2350 if (node
&& first_rtl_op (code
) != 0)
2352 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
2353 TREE_READONLY (t
) = TREE_READONLY (node
);
2362 case PREDECREMENT_EXPR
:
2363 case PREINCREMENT_EXPR
:
2364 case POSTDECREMENT_EXPR
:
2365 case POSTINCREMENT_EXPR
:
2366 /* All of these have side-effects, no matter what their
2368 TREE_SIDE_EFFECTS (t
) = 1;
2369 TREE_READONLY (t
) = 0;
2373 /* Whether a dereference is readonly has nothing to do with whether
2374 its operand is readonly. */
2375 TREE_READONLY (t
) = 0;
2379 if (TREE_CODE_CLASS (code
) == '1' && node
&& TREE_CONSTANT (node
))
2380 TREE_CONSTANT (t
) = 1;
2387 /* Similar except don't specify the TREE_TYPE
2388 and leave the TREE_SIDE_EFFECTS as 0.
2389 It is permissible for arguments to be null,
2390 or even garbage if their values do not matter. */
2393 build_nt
VPARAMS ((enum tree_code code
, ...))
2400 VA_FIXEDARG (p
, enum tree_code
, code
);
2402 t
= make_node (code
);
2403 length
= TREE_CODE_LENGTH (code
);
2405 for (i
= 0; i
< length
; i
++)
2406 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
2412 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2413 We do NOT enter this node in any sort of symbol table.
2415 layout_decl is used to set up the decl's storage layout.
2416 Other slots are initialized to 0 or null pointers. */
2419 build_decl (code
, name
, type
)
2420 enum tree_code code
;
2425 t
= make_node (code
);
2427 /* if (type == error_mark_node)
2428 type = integer_type_node; */
2429 /* That is not done, deliberately, so that having error_mark_node
2430 as the type can suppress useless errors in the use of this variable. */
2432 DECL_NAME (t
) = name
;
2433 TREE_TYPE (t
) = type
;
2435 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
2437 else if (code
== FUNCTION_DECL
)
2438 DECL_MODE (t
) = FUNCTION_MODE
;
2443 /* BLOCK nodes are used to represent the structure of binding contours
2444 and declarations, once those contours have been exited and their contents
2445 compiled. This information is used for outputting debugging info. */
2448 build_block (vars
, tags
, subblocks
, supercontext
, chain
)
2449 tree vars
, tags ATTRIBUTE_UNUSED
, subblocks
, supercontext
, chain
;
2451 tree block
= make_node (BLOCK
);
2453 BLOCK_VARS (block
) = vars
;
2454 BLOCK_SUBBLOCKS (block
) = subblocks
;
2455 BLOCK_SUPERCONTEXT (block
) = supercontext
;
2456 BLOCK_CHAIN (block
) = chain
;
2460 /* EXPR_WITH_FILE_LOCATION are used to keep track of the exact
2461 location where an expression or an identifier were encountered. It
2462 is necessary for languages where the frontend parser will handle
2463 recursively more than one file (Java is one of them). */
2466 build_expr_wfl (node
, file
, line
, col
)
2471 static const char *last_file
= 0;
2472 static tree last_filenode
= NULL_TREE
;
2473 tree wfl
= make_node (EXPR_WITH_FILE_LOCATION
);
2475 EXPR_WFL_NODE (wfl
) = node
;
2476 EXPR_WFL_SET_LINECOL (wfl
, line
, col
);
2477 if (file
!= last_file
)
2480 last_filenode
= file
? get_identifier (file
) : NULL_TREE
;
2483 EXPR_WFL_FILENAME_NODE (wfl
) = last_filenode
;
2486 TREE_SIDE_EFFECTS (wfl
) = TREE_SIDE_EFFECTS (node
);
2487 TREE_TYPE (wfl
) = TREE_TYPE (node
);
2493 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
2497 build_decl_attribute_variant (ddecl
, attribute
)
2498 tree ddecl
, attribute
;
2500 DECL_ATTRIBUTES (ddecl
) = attribute
;
2504 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
2507 Record such modified types already made so we don't make duplicates. */
2510 build_type_attribute_variant (ttype
, attribute
)
2511 tree ttype
, attribute
;
2513 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
2515 unsigned int hashcode
;
2518 ntype
= copy_node (ttype
);
2520 TYPE_POINTER_TO (ntype
) = 0;
2521 TYPE_REFERENCE_TO (ntype
) = 0;
2522 TYPE_ATTRIBUTES (ntype
) = attribute
;
2524 /* Create a new main variant of TYPE. */
2525 TYPE_MAIN_VARIANT (ntype
) = ntype
;
2526 TYPE_NEXT_VARIANT (ntype
) = 0;
2527 set_type_quals (ntype
, TYPE_UNQUALIFIED
);
2529 hashcode
= (TYPE_HASH (TREE_CODE (ntype
))
2530 + TYPE_HASH (TREE_TYPE (ntype
))
2531 + attribute_hash_list (attribute
));
2533 switch (TREE_CODE (ntype
))
2536 hashcode
+= TYPE_HASH (TYPE_ARG_TYPES (ntype
));
2539 hashcode
+= TYPE_HASH (TYPE_DOMAIN (ntype
));
2542 hashcode
+= TYPE_HASH (TYPE_MAX_VALUE (ntype
));
2545 hashcode
+= TYPE_HASH (TYPE_PRECISION (ntype
));
2551 ntype
= type_hash_canon (hashcode
, ntype
);
2552 ttype
= build_qualified_type (ntype
, TYPE_QUALS (ttype
));
2558 /* Default value of targetm.comp_type_attributes that always returns 1. */
2561 default_comp_type_attributes (type1
, type2
)
2562 tree type1 ATTRIBUTE_UNUSED
;
2563 tree type2 ATTRIBUTE_UNUSED
;
2568 /* Default version of targetm.set_default_type_attributes that always does
2572 default_set_default_type_attributes (type
)
2573 tree type ATTRIBUTE_UNUSED
;
2577 /* Default version of targetm.insert_attributes that always does nothing. */
2579 default_insert_attributes (decl
, attr_ptr
)
2580 tree decl ATTRIBUTE_UNUSED
;
2581 tree
*attr_ptr ATTRIBUTE_UNUSED
;
2585 /* Default value of targetm.function_attribute_inlinable_p that always
2588 default_function_attribute_inlinable_p (fndecl
)
2589 tree fndecl ATTRIBUTE_UNUSED
;
2591 /* By default, functions with machine attributes cannot be inlined. */
2595 /* Default value of targetm.ms_bitfield_layout_p that always returns
2598 default_ms_bitfield_layout_p (record
)
2599 tree record ATTRIBUTE_UNUSED
;
2601 /* By default, GCC does not use the MS VC++ bitfield layout rules. */
2605 /* Return non-zero if IDENT is a valid name for attribute ATTR,
2608 We try both `text' and `__text__', ATTR may be either one. */
2609 /* ??? It might be a reasonable simplification to require ATTR to be only
2610 `text'. One might then also require attribute lists to be stored in
2611 their canonicalized form. */
2614 is_attribute_p (attr
, ident
)
2618 int ident_len
, attr_len
;
2621 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
2624 if (strcmp (attr
, IDENTIFIER_POINTER (ident
)) == 0)
2627 p
= IDENTIFIER_POINTER (ident
);
2628 ident_len
= strlen (p
);
2629 attr_len
= strlen (attr
);
2631 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
2635 || attr
[attr_len
- 2] != '_'
2636 || attr
[attr_len
- 1] != '_')
2638 if (ident_len
== attr_len
- 4
2639 && strncmp (attr
+ 2, p
, attr_len
- 4) == 0)
2644 if (ident_len
== attr_len
+ 4
2645 && p
[0] == '_' && p
[1] == '_'
2646 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
2647 && strncmp (attr
, p
+ 2, attr_len
) == 0)
2654 /* Given an attribute name and a list of attributes, return a pointer to the
2655 attribute's list element if the attribute is part of the list, or NULL_TREE
2656 if not found. If the attribute appears more than once, this only
2657 returns the first occurrence; the TREE_CHAIN of the return value should
2658 be passed back in if further occurrences are wanted. */
2661 lookup_attribute (attr_name
, list
)
2662 const char *attr_name
;
2667 for (l
= list
; l
; l
= TREE_CHAIN (l
))
2669 if (TREE_CODE (TREE_PURPOSE (l
)) != IDENTIFIER_NODE
)
2671 if (is_attribute_p (attr_name
, TREE_PURPOSE (l
)))
2678 /* Return an attribute list that is the union of a1 and a2. */
2681 merge_attributes (a1
, a2
)
2686 /* Either one unset? Take the set one. */
2688 if ((attributes
= a1
) == 0)
2691 /* One that completely contains the other? Take it. */
2693 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
2695 if (attribute_list_contained (a2
, a1
))
2699 /* Pick the longest list, and hang on the other list. */
2701 if (list_length (a1
) < list_length (a2
))
2702 attributes
= a2
, a2
= a1
;
2704 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
2707 for (a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
2710 a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
2713 if (simple_cst_equal (TREE_VALUE (a
), TREE_VALUE (a2
)) == 1)
2718 a1
= copy_node (a2
);
2719 TREE_CHAIN (a1
) = attributes
;
2728 /* Given types T1 and T2, merge their attributes and return
2732 merge_type_attributes (t1
, t2
)
2735 return merge_attributes (TYPE_ATTRIBUTES (t1
),
2736 TYPE_ATTRIBUTES (t2
));
2739 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
2743 merge_decl_attributes (olddecl
, newdecl
)
2744 tree olddecl
, newdecl
;
2746 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
2747 DECL_ATTRIBUTES (newdecl
));
2750 #ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
2752 /* Specialization of merge_decl_attributes for various Windows targets.
2754 This handles the following situation:
2756 __declspec (dllimport) int foo;
2759 The second instance of `foo' nullifies the dllimport. */
2762 merge_dllimport_decl_attributes (old
, new)
2767 int delete_dllimport_p
;
2769 old
= DECL_ATTRIBUTES (old
);
2770 new = DECL_ATTRIBUTES (new);
2772 /* What we need to do here is remove from `old' dllimport if it doesn't
2773 appear in `new'. dllimport behaves like extern: if a declaration is
2774 marked dllimport and a definition appears later, then the object
2775 is not dllimport'd. */
2776 if (lookup_attribute ("dllimport", old
) != NULL_TREE
2777 && lookup_attribute ("dllimport", new) == NULL_TREE
)
2778 delete_dllimport_p
= 1;
2780 delete_dllimport_p
= 0;
2782 a
= merge_attributes (old
, new);
2784 if (delete_dllimport_p
)
2788 /* Scan the list for dllimport and delete it. */
2789 for (prev
= NULL_TREE
, t
= a
; t
; prev
= t
, t
= TREE_CHAIN (t
))
2791 if (is_attribute_p ("dllimport", TREE_PURPOSE (t
)))
2793 if (prev
== NULL_TREE
)
2796 TREE_CHAIN (prev
) = TREE_CHAIN (t
);
2805 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
2807 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
2808 of the various TYPE_QUAL values. */
2811 set_type_quals (type
, type_quals
)
2815 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
2816 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
2817 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
2820 /* Return a version of the TYPE, qualified as indicated by the
2821 TYPE_QUALS, if one exists. If no qualified version exists yet,
2822 return NULL_TREE. */
2825 get_qualified_type (type
, type_quals
)
2831 /* Search the chain of variants to see if there is already one there just
2832 like the one we need to have. If so, use that existing one. We must
2833 preserve the TYPE_NAME, since there is code that depends on this. */
2834 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
2835 if (TYPE_QUALS (t
) == type_quals
&& TYPE_NAME (t
) == TYPE_NAME (type
)
2836 && TYPE_CONTEXT (t
) == TYPE_CONTEXT (type
))
2842 /* Like get_qualified_type, but creates the type if it does not
2843 exist. This function never returns NULL_TREE. */
2846 build_qualified_type (type
, type_quals
)
2852 /* See if we already have the appropriate qualified variant. */
2853 t
= get_qualified_type (type
, type_quals
);
2855 /* If not, build it. */
2858 t
= build_type_copy (type
);
2859 set_type_quals (t
, type_quals
);
2865 /* Create a new variant of TYPE, equivalent but distinct.
2866 This is so the caller can modify it. */
2869 build_type_copy (type
)
2872 tree t
, m
= TYPE_MAIN_VARIANT (type
);
2874 t
= copy_node (type
);
2876 TYPE_POINTER_TO (t
) = 0;
2877 TYPE_REFERENCE_TO (t
) = 0;
2879 /* Add this type to the chain of variants of TYPE. */
2880 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
2881 TYPE_NEXT_VARIANT (m
) = t
;
2886 /* Hashing of types so that we don't make duplicates.
2887 The entry point is `type_hash_canon'. */
2889 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
2890 with types in the TREE_VALUE slots), by adding the hash codes
2891 of the individual types. */
2894 type_hash_list (list
)
2897 unsigned int hashcode
;
2900 for (hashcode
= 0, tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2901 hashcode
+= TYPE_HASH (TREE_VALUE (tail
));
2906 /* These are the Hashtable callback functions. */
2908 /* Returns true if the types are equal. */
2911 type_hash_eq (va
, vb
)
2915 const struct type_hash
*a
= va
, *b
= vb
;
2916 if (a
->hash
== b
->hash
2917 && TREE_CODE (a
->type
) == TREE_CODE (b
->type
)
2918 && TREE_TYPE (a
->type
) == TREE_TYPE (b
->type
)
2919 && attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
2920 TYPE_ATTRIBUTES (b
->type
))
2921 && TYPE_ALIGN (a
->type
) == TYPE_ALIGN (b
->type
)
2922 && (TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
2923 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
2924 TYPE_MAX_VALUE (b
->type
)))
2925 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
2926 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
2927 TYPE_MIN_VALUE (b
->type
)))
2928 /* Note that TYPE_DOMAIN is TYPE_ARG_TYPES for FUNCTION_TYPE. */
2929 && (TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
)
2930 || (TYPE_DOMAIN (a
->type
)
2931 && TREE_CODE (TYPE_DOMAIN (a
->type
)) == TREE_LIST
2932 && TYPE_DOMAIN (b
->type
)
2933 && TREE_CODE (TYPE_DOMAIN (b
->type
)) == TREE_LIST
2934 && type_list_equal (TYPE_DOMAIN (a
->type
),
2935 TYPE_DOMAIN (b
->type
)))))
2940 /* Return the cached hash value. */
2943 type_hash_hash (item
)
2946 return ((const struct type_hash
*) item
)->hash
;
2949 /* Look in the type hash table for a type isomorphic to TYPE.
2950 If one is found, return it. Otherwise return 0. */
2953 type_hash_lookup (hashcode
, type
)
2954 unsigned int hashcode
;
2957 struct type_hash
*h
, in
;
2959 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
2960 must call that routine before comparing TYPE_ALIGNs. */
2966 h
= htab_find_with_hash (type_hash_table
, &in
, hashcode
);
2972 /* Add an entry to the type-hash-table
2973 for a type TYPE whose hash code is HASHCODE. */
2976 type_hash_add (hashcode
, type
)
2977 unsigned int hashcode
;
2980 struct type_hash
*h
;
2983 h
= (struct type_hash
*) ggc_alloc (sizeof (struct type_hash
));
2986 loc
= htab_find_slot_with_hash (type_hash_table
, h
, hashcode
, INSERT
);
2987 *(struct type_hash
**) loc
= h
;
2990 /* Given TYPE, and HASHCODE its hash code, return the canonical
2991 object for an identical type if one already exists.
2992 Otherwise, return TYPE, and record it as the canonical object
2993 if it is a permanent object.
2995 To use this function, first create a type of the sort you want.
2996 Then compute its hash code from the fields of the type that
2997 make it different from other similar types.
2998 Then call this function and use the value.
2999 This function frees the type you pass in if it is a duplicate. */
3001 /* Set to 1 to debug without canonicalization. Never set by program. */
3002 int debug_no_type_hash
= 0;
3005 type_hash_canon (hashcode
, type
)
3006 unsigned int hashcode
;
3011 if (debug_no_type_hash
)
3014 /* See if the type is in the hash table already. If so, return it.
3015 Otherwise, add the type. */
3016 t1
= type_hash_lookup (hashcode
, type
);
3019 #ifdef GATHER_STATISTICS
3020 tree_node_counts
[(int) t_kind
]--;
3021 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type
);
3027 type_hash_add (hashcode
, type
);
3032 /* See if the data pointed to by the type hash table is marked. We consider
3033 it marked if the type is marked or if a debug type number or symbol
3034 table entry has been made for the type. This reduces the amount of
3035 debugging output and eliminates that dependency of the debug output on
3036 the number of garbage collections. */
3039 type_hash_marked_p (p
)
3042 tree type
= ((struct type_hash
*) p
)->type
;
3044 return ggc_marked_p (type
) || TYPE_SYMTAB_POINTER (type
);
3048 print_type_hash_statistics ()
3050 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
3051 (long) htab_size (type_hash_table
),
3052 (long) htab_elements (type_hash_table
),
3053 htab_collisions (type_hash_table
));
3056 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
3057 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
3058 by adding the hash codes of the individual attributes. */
3061 attribute_hash_list (list
)
3064 unsigned int hashcode
;
3067 for (hashcode
= 0, tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
3068 /* ??? Do we want to add in TREE_VALUE too? */
3069 hashcode
+= TYPE_HASH (TREE_PURPOSE (tail
));
3073 /* Given two lists of attributes, return true if list l2 is
3074 equivalent to l1. */
3077 attribute_list_equal (l1
, l2
)
3080 return attribute_list_contained (l1
, l2
)
3081 && attribute_list_contained (l2
, l1
);
3084 /* Given two lists of attributes, return true if list L2 is
3085 completely contained within L1. */
3086 /* ??? This would be faster if attribute names were stored in a canonicalized
3087 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
3088 must be used to show these elements are equivalent (which they are). */
3089 /* ??? It's not clear that attributes with arguments will always be handled
3093 attribute_list_contained (l1
, l2
)
3098 /* First check the obvious, maybe the lists are identical. */
3102 /* Maybe the lists are similar. */
3103 for (t1
= l1
, t2
= l2
;
3105 && TREE_PURPOSE (t1
) == TREE_PURPOSE (t2
)
3106 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
3107 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
));
3109 /* Maybe the lists are equal. */
3110 if (t1
== 0 && t2
== 0)
3113 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
3116 for (attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)), l1
);
3118 attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
3121 if (simple_cst_equal (TREE_VALUE (t2
), TREE_VALUE (attr
)) == 1)
3128 if (simple_cst_equal (TREE_VALUE (t2
), TREE_VALUE (attr
)) != 1)
3135 /* Given two lists of types
3136 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
3137 return 1 if the lists contain the same types in the same order.
3138 Also, the TREE_PURPOSEs must match. */
3141 type_list_equal (l1
, l2
)
3146 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
3147 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
3148 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
3149 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
3150 && (TREE_TYPE (TREE_PURPOSE (t1
))
3151 == TREE_TYPE (TREE_PURPOSE (t2
))))))
3157 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
3158 given by TYPE. If the argument list accepts variable arguments,
3159 then this function counts only the ordinary arguments. */
3162 type_num_arguments (type
)
3168 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
3169 /* If the function does not take a variable number of arguments,
3170 the last element in the list will have type `void'. */
3171 if (VOID_TYPE_P (TREE_VALUE (t
)))
3179 /* Nonzero if integer constants T1 and T2
3180 represent the same constant value. */
3183 tree_int_cst_equal (t1
, t2
)
3189 if (t1
== 0 || t2
== 0)
3192 if (TREE_CODE (t1
) == INTEGER_CST
3193 && TREE_CODE (t2
) == INTEGER_CST
3194 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
3195 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
3201 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
3202 The precise way of comparison depends on their data type. */
3205 tree_int_cst_lt (t1
, t2
)
3211 if (TREE_UNSIGNED (TREE_TYPE (t1
)) != TREE_UNSIGNED (TREE_TYPE (t2
)))
3213 int t1_sgn
= tree_int_cst_sgn (t1
);
3214 int t2_sgn
= tree_int_cst_sgn (t2
);
3216 if (t1_sgn
< t2_sgn
)
3218 else if (t1_sgn
> t2_sgn
)
3220 /* Otherwise, both are non-negative, so we compare them as
3221 unsigned just in case one of them would overflow a signed
3224 else if (! TREE_UNSIGNED (TREE_TYPE (t1
)))
3225 return INT_CST_LT (t1
, t2
);
3227 return INT_CST_LT_UNSIGNED (t1
, t2
);
3230 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
3233 tree_int_cst_compare (t1
, t2
)
3237 if (tree_int_cst_lt (t1
, t2
))
3239 else if (tree_int_cst_lt (t2
, t1
))
3245 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
3246 the host. If POS is zero, the value can be represented in a single
3247 HOST_WIDE_INT. If POS is nonzero, the value must be positive and can
3248 be represented in a single unsigned HOST_WIDE_INT. */
3251 host_integerp (t
, pos
)
3255 return (TREE_CODE (t
) == INTEGER_CST
3256 && ! TREE_OVERFLOW (t
)
3257 && ((TREE_INT_CST_HIGH (t
) == 0
3258 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) >= 0)
3259 || (! pos
&& TREE_INT_CST_HIGH (t
) == -1
3260 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0
3261 && ! TREE_UNSIGNED (TREE_TYPE (t
)))
3262 || (pos
&& TREE_INT_CST_HIGH (t
) == 0)));
3265 /* Return the HOST_WIDE_INT least significant bits of T if it is an
3266 INTEGER_CST and there is no overflow. POS is nonzero if the result must
3267 be positive. Abort if we cannot satisfy the above conditions. */
3270 tree_low_cst (t
, pos
)
3274 if (host_integerp (t
, pos
))
3275 return TREE_INT_CST_LOW (t
);
3280 /* Return the most significant bit of the integer constant T. */
3283 tree_int_cst_msb (t
)
3288 unsigned HOST_WIDE_INT l
;
3290 /* Note that using TYPE_PRECISION here is wrong. We care about the
3291 actual bits, not the (arbitrary) range of the type. */
3292 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t
))) - 1;
3293 rshift_double (TREE_INT_CST_LOW (t
), TREE_INT_CST_HIGH (t
), prec
,
3294 2 * HOST_BITS_PER_WIDE_INT
, &l
, &h
, 0);
3295 return (l
& 1) == 1;
3298 /* Return an indication of the sign of the integer constant T.
3299 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
3300 Note that -1 will never be returned it T's type is unsigned. */
3303 tree_int_cst_sgn (t
)
3306 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
3308 else if (TREE_UNSIGNED (TREE_TYPE (t
)))
3310 else if (TREE_INT_CST_HIGH (t
) < 0)
3316 /* Compare two constructor-element-type constants. Return 1 if the lists
3317 are known to be equal; otherwise return 0. */
3320 simple_cst_list_equal (l1
, l2
)
3323 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
3325 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
3328 l1
= TREE_CHAIN (l1
);
3329 l2
= TREE_CHAIN (l2
);
3335 /* Return truthvalue of whether T1 is the same tree structure as T2.
3336 Return 1 if they are the same.
3337 Return 0 if they are understandably different.
3338 Return -1 if either contains tree structure not understood by
3342 simple_cst_equal (t1
, t2
)
3345 enum tree_code code1
, code2
;
3351 if (t1
== 0 || t2
== 0)
3354 code1
= TREE_CODE (t1
);
3355 code2
= TREE_CODE (t2
);
3357 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
3359 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
3360 || code2
== NON_LVALUE_EXPR
)
3361 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3363 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
3366 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
3367 || code2
== NON_LVALUE_EXPR
)
3368 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
3376 return (TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
3377 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
));
3380 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
3383 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3384 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3385 TREE_STRING_LENGTH (t1
)));
3388 if (CONSTRUCTOR_ELTS (t1
) == CONSTRUCTOR_ELTS (t2
))
3394 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3397 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3401 simple_cst_list_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
3404 /* Special case: if either target is an unallocated VAR_DECL,
3405 it means that it's going to be unified with whatever the
3406 TARGET_EXPR is really supposed to initialize, so treat it
3407 as being equivalent to anything. */
3408 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
3409 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
3410 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
3411 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
3412 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
3413 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
3416 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3421 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
3423 case WITH_CLEANUP_EXPR
:
3424 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3428 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
3431 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
3432 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3446 /* This general rule works for most tree codes. All exceptions should be
3447 handled above. If this is a language-specific tree code, we can't
3448 trust what might be in the operand, so say we don't know
3450 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
3453 switch (TREE_CODE_CLASS (code1
))
3462 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
3464 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
3476 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
3477 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
3478 than U, respectively. */
3481 compare_tree_int (t
, u
)
3483 unsigned HOST_WIDE_INT u
;
3485 if (tree_int_cst_sgn (t
) < 0)
3487 else if (TREE_INT_CST_HIGH (t
) != 0)
3489 else if (TREE_INT_CST_LOW (t
) == u
)
3491 else if (TREE_INT_CST_LOW (t
) < u
)
3497 /* Constructors for pointer, array and function types.
3498 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
3499 constructed by language-dependent code, not here.) */
3501 /* Construct, lay out and return the type of pointers to TO_TYPE.
3502 If such a type has already been constructed, reuse it. */
3505 build_pointer_type (to_type
)
3508 tree t
= TYPE_POINTER_TO (to_type
);
3510 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3515 /* We need a new one. */
3516 t
= make_node (POINTER_TYPE
);
3518 TREE_TYPE (t
) = to_type
;
3520 /* Record this type as the pointer to TO_TYPE. */
3521 TYPE_POINTER_TO (to_type
) = t
;
3523 /* Lay out the type. This function has many callers that are concerned
3524 with expression-construction, and this simplifies them all.
3525 Also, it guarantees the TYPE_SIZE is in the same obstack as the type. */
3531 /* Build the node for the type of references-to-TO_TYPE. */
3534 build_reference_type (to_type
)
3537 tree t
= TYPE_REFERENCE_TO (to_type
);
3539 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3544 /* We need a new one. */
3545 t
= make_node (REFERENCE_TYPE
);
3547 TREE_TYPE (t
) = to_type
;
3549 /* Record this type as the pointer to TO_TYPE. */
3550 TYPE_REFERENCE_TO (to_type
) = t
;
3557 /* Build a type that is compatible with t but has no cv quals anywhere
3560 const char *const *const * -> char ***. */
3563 build_type_no_quals (t
)
3566 switch (TREE_CODE (t
))
3569 return build_pointer_type (build_type_no_quals (TREE_TYPE (t
)));
3570 case REFERENCE_TYPE
:
3571 return build_reference_type (build_type_no_quals (TREE_TYPE (t
)));
3573 return TYPE_MAIN_VARIANT (t
);
3577 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
3578 MAXVAL should be the maximum value in the domain
3579 (one less than the length of the array).
3581 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
3582 We don't enforce this limit, that is up to caller (e.g. language front end).
3583 The limit exists because the result is a signed type and we don't handle
3584 sizes that use more than one HOST_WIDE_INT. */
3587 build_index_type (maxval
)
3590 tree itype
= make_node (INTEGER_TYPE
);
3592 TREE_TYPE (itype
) = sizetype
;
3593 TYPE_PRECISION (itype
) = TYPE_PRECISION (sizetype
);
3594 TYPE_MIN_VALUE (itype
) = size_zero_node
;
3595 TYPE_MAX_VALUE (itype
) = convert (sizetype
, maxval
);
3596 TYPE_MODE (itype
) = TYPE_MODE (sizetype
);
3597 TYPE_SIZE (itype
) = TYPE_SIZE (sizetype
);
3598 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (sizetype
);
3599 TYPE_ALIGN (itype
) = TYPE_ALIGN (sizetype
);
3600 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (sizetype
);
3602 if (host_integerp (maxval
, 1))
3603 return type_hash_canon (tree_low_cst (maxval
, 1), itype
);
3608 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
3609 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
3610 low bound LOWVAL and high bound HIGHVAL.
3611 if TYPE==NULL_TREE, sizetype is used. */
3614 build_range_type (type
, lowval
, highval
)
3615 tree type
, lowval
, highval
;
3617 tree itype
= make_node (INTEGER_TYPE
);
3619 TREE_TYPE (itype
) = type
;
3620 if (type
== NULL_TREE
)
3623 TYPE_MIN_VALUE (itype
) = convert (type
, lowval
);
3624 TYPE_MAX_VALUE (itype
) = highval
? convert (type
, highval
) : NULL
;
3626 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
3627 TYPE_MODE (itype
) = TYPE_MODE (type
);
3628 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
3629 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
3630 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
3631 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
3633 if (host_integerp (lowval
, 0) && highval
!= 0 && host_integerp (highval
, 0))
3634 return type_hash_canon (tree_low_cst (highval
, 0)
3635 - tree_low_cst (lowval
, 0),
3641 /* Just like build_index_type, but takes lowval and highval instead
3642 of just highval (maxval). */
3645 build_index_2_type (lowval
, highval
)
3646 tree lowval
, highval
;
3648 return build_range_type (sizetype
, lowval
, highval
);
3651 /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
3652 Needed because when index types are not hashed, equal index types
3653 built at different times appear distinct, even though structurally,
3657 index_type_equal (itype1
, itype2
)
3658 tree itype1
, itype2
;
3660 if (TREE_CODE (itype1
) != TREE_CODE (itype2
))
3663 if (TREE_CODE (itype1
) == INTEGER_TYPE
)
3665 if (TYPE_PRECISION (itype1
) != TYPE_PRECISION (itype2
)
3666 || TYPE_MODE (itype1
) != TYPE_MODE (itype2
)
3667 || simple_cst_equal (TYPE_SIZE (itype1
), TYPE_SIZE (itype2
)) != 1
3668 || TYPE_ALIGN (itype1
) != TYPE_ALIGN (itype2
))
3671 if (1 == simple_cst_equal (TYPE_MIN_VALUE (itype1
),
3672 TYPE_MIN_VALUE (itype2
))
3673 && 1 == simple_cst_equal (TYPE_MAX_VALUE (itype1
),
3674 TYPE_MAX_VALUE (itype2
)))
3681 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
3682 and number of elements specified by the range of values of INDEX_TYPE.
3683 If such a type has already been constructed, reuse it. */
3686 build_array_type (elt_type
, index_type
)
3687 tree elt_type
, index_type
;
3690 unsigned int hashcode
;
3692 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
3694 error ("arrays of functions are not meaningful");
3695 elt_type
= integer_type_node
;
3698 /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
3699 build_pointer_type (elt_type
);
3701 /* Allocate the array after the pointer type,
3702 in case we free it in type_hash_canon. */
3703 t
= make_node (ARRAY_TYPE
);
3704 TREE_TYPE (t
) = elt_type
;
3705 TYPE_DOMAIN (t
) = index_type
;
3707 if (index_type
== 0)
3712 hashcode
= TYPE_HASH (elt_type
) + TYPE_HASH (index_type
);
3713 t
= type_hash_canon (hashcode
, t
);
3715 if (!COMPLETE_TYPE_P (t
))
3720 /* Return the TYPE of the elements comprising
3721 the innermost dimension of ARRAY. */
3724 get_inner_array_type (array
)
3727 tree type
= TREE_TYPE (array
);
3729 while (TREE_CODE (type
) == ARRAY_TYPE
)
3730 type
= TREE_TYPE (type
);
3735 /* Construct, lay out and return
3736 the type of functions returning type VALUE_TYPE
3737 given arguments of types ARG_TYPES.
3738 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
3739 are data type nodes for the arguments of the function.
3740 If such a type has already been constructed, reuse it. */
3743 build_function_type (value_type
, arg_types
)
3744 tree value_type
, arg_types
;
3747 unsigned int hashcode
;
3749 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
3751 error ("function return type cannot be function");
3752 value_type
= integer_type_node
;
3755 /* Make a node of the sort we want. */
3756 t
= make_node (FUNCTION_TYPE
);
3757 TREE_TYPE (t
) = value_type
;
3758 TYPE_ARG_TYPES (t
) = arg_types
;
3760 /* If we already have such a type, use the old one and free this one. */
3761 hashcode
= TYPE_HASH (value_type
) + type_hash_list (arg_types
);
3762 t
= type_hash_canon (hashcode
, t
);
3764 if (!COMPLETE_TYPE_P (t
))
3769 /* Build a function type. The RETURN_TYPE is the type retured by the
3770 function. If additional arguments are provided, they are
3771 additional argument types. The list of argument types must always
3772 be terminated by NULL_TREE. */
3775 build_function_type_list
VPARAMS ((tree return_type
, ...))
3779 VA_OPEN (p
, return_type
);
3780 VA_FIXEDARG (p
, tree
, return_type
);
3782 t
= va_arg (p
, tree
);
3783 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (p
, tree
))
3784 args
= tree_cons (NULL_TREE
, t
, args
);
3787 args
= nreverse (args
);
3788 TREE_CHAIN (last
) = void_list_node
;
3789 args
= build_function_type (return_type
, args
);
3795 /* Construct, lay out and return the type of methods belonging to class
3796 BASETYPE and whose arguments and values are described by TYPE.
3797 If that type exists already, reuse it.
3798 TYPE must be a FUNCTION_TYPE node. */
3801 build_method_type (basetype
, type
)
3802 tree basetype
, type
;
3805 unsigned int hashcode
;
3807 /* Make a node of the sort we want. */
3808 t
= make_node (METHOD_TYPE
);
3810 if (TREE_CODE (type
) != FUNCTION_TYPE
)
3813 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
3814 TREE_TYPE (t
) = TREE_TYPE (type
);
3816 /* The actual arglist for this function includes a "hidden" argument
3817 which is "this". Put it into the list of argument types. */
3820 = tree_cons (NULL_TREE
,
3821 build_pointer_type (basetype
), TYPE_ARG_TYPES (type
));
3823 /* If we already have such a type, use the old one and free this one. */
3824 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (type
);
3825 t
= type_hash_canon (hashcode
, t
);
3827 if (!COMPLETE_TYPE_P (t
))
3833 /* Construct, lay out and return the type of offsets to a value
3834 of type TYPE, within an object of type BASETYPE.
3835 If a suitable offset type exists already, reuse it. */
3838 build_offset_type (basetype
, type
)
3839 tree basetype
, type
;
3842 unsigned int hashcode
;
3844 /* Make a node of the sort we want. */
3845 t
= make_node (OFFSET_TYPE
);
3847 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
3848 TREE_TYPE (t
) = type
;
3850 /* If we already have such a type, use the old one and free this one. */
3851 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (type
);
3852 t
= type_hash_canon (hashcode
, t
);
3854 if (!COMPLETE_TYPE_P (t
))
3860 /* Create a complex type whose components are COMPONENT_TYPE. */
3863 build_complex_type (component_type
)
3864 tree component_type
;
3867 unsigned int hashcode
;
3869 /* Make a node of the sort we want. */
3870 t
= make_node (COMPLEX_TYPE
);
3872 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
3873 set_type_quals (t
, TYPE_QUALS (component_type
));
3875 /* If we already have such a type, use the old one and free this one. */
3876 hashcode
= TYPE_HASH (component_type
);
3877 t
= type_hash_canon (hashcode
, t
);
3879 if (!COMPLETE_TYPE_P (t
))
3882 /* If we are writing Dwarf2 output we need to create a name,
3883 since complex is a fundamental type. */
3884 if ((write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
3888 if (component_type
== char_type_node
)
3889 name
= "complex char";
3890 else if (component_type
== signed_char_type_node
)
3891 name
= "complex signed char";
3892 else if (component_type
== unsigned_char_type_node
)
3893 name
= "complex unsigned char";
3894 else if (component_type
== short_integer_type_node
)
3895 name
= "complex short int";
3896 else if (component_type
== short_unsigned_type_node
)
3897 name
= "complex short unsigned int";
3898 else if (component_type
== integer_type_node
)
3899 name
= "complex int";
3900 else if (component_type
== unsigned_type_node
)
3901 name
= "complex unsigned int";
3902 else if (component_type
== long_integer_type_node
)
3903 name
= "complex long int";
3904 else if (component_type
== long_unsigned_type_node
)
3905 name
= "complex long unsigned int";
3906 else if (component_type
== long_long_integer_type_node
)
3907 name
= "complex long long int";
3908 else if (component_type
== long_long_unsigned_type_node
)
3909 name
= "complex long long unsigned int";
3914 TYPE_NAME (t
) = get_identifier (name
);
3920 /* Return OP, stripped of any conversions to wider types as much as is safe.
3921 Converting the value back to OP's type makes a value equivalent to OP.
3923 If FOR_TYPE is nonzero, we return a value which, if converted to
3924 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
3926 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
3927 narrowest type that can hold the value, even if they don't exactly fit.
3928 Otherwise, bit-field references are changed to a narrower type
3929 only if they can be fetched directly from memory in that type.
3931 OP must have integer, real or enumeral type. Pointers are not allowed!
3933 There are some cases where the obvious value we could return
3934 would regenerate to OP if converted to OP's type,
3935 but would not extend like OP to wider types.
3936 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
3937 For example, if OP is (unsigned short)(signed char)-1,
3938 we avoid returning (signed char)-1 if FOR_TYPE is int,
3939 even though extending that to an unsigned short would regenerate OP,
3940 since the result of extending (signed char)-1 to (int)
3941 is different from (int) OP. */
3944 get_unwidened (op
, for_type
)
3948 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
3949 tree type
= TREE_TYPE (op
);
3951 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
3953 = (for_type
!= 0 && for_type
!= type
3954 && final_prec
> TYPE_PRECISION (type
)
3955 && TREE_UNSIGNED (type
));
3958 while (TREE_CODE (op
) == NOP_EXPR
)
3961 = TYPE_PRECISION (TREE_TYPE (op
))
3962 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
3964 /* Truncations are many-one so cannot be removed.
3965 Unless we are later going to truncate down even farther. */
3967 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
3970 /* See what's inside this conversion. If we decide to strip it,
3972 op
= TREE_OPERAND (op
, 0);
3974 /* If we have not stripped any zero-extensions (uns is 0),
3975 we can strip any kind of extension.
3976 If we have previously stripped a zero-extension,
3977 only zero-extensions can safely be stripped.
3978 Any extension can be stripped if the bits it would produce
3979 are all going to be discarded later by truncating to FOR_TYPE. */
3983 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
3985 /* TREE_UNSIGNED says whether this is a zero-extension.
3986 Let's avoid computing it if it does not affect WIN
3987 and if UNS will not be needed again. */
3988 if ((uns
|| TREE_CODE (op
) == NOP_EXPR
)
3989 && TREE_UNSIGNED (TREE_TYPE (op
)))
3997 if (TREE_CODE (op
) == COMPONENT_REF
3998 /* Since type_for_size always gives an integer type. */
3999 && TREE_CODE (type
) != REAL_TYPE
4000 /* Don't crash if field not laid out yet. */
4001 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
4002 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
4004 unsigned int innerprec
4005 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
4006 int unsignedp
= TREE_UNSIGNED (TREE_OPERAND (op
, 1));
4007 type
= (*lang_hooks
.types
.type_for_size
) (innerprec
, unsignedp
);
4009 /* We can get this structure field in the narrowest type it fits in.
4010 If FOR_TYPE is 0, do this only for a field that matches the
4011 narrower type exactly and is aligned for it
4012 The resulting extension to its nominal type (a fullword type)
4013 must fit the same conditions as for other extensions. */
4015 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
4016 && (for_type
|| ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1)))
4017 && (! uns
|| final_prec
<= innerprec
|| unsignedp
)
4020 win
= build (COMPONENT_REF
, type
, TREE_OPERAND (op
, 0),
4021 TREE_OPERAND (op
, 1));
4022 TREE_SIDE_EFFECTS (win
) = TREE_SIDE_EFFECTS (op
);
4023 TREE_THIS_VOLATILE (win
) = TREE_THIS_VOLATILE (op
);
4030 /* Return OP or a simpler expression for a narrower value
4031 which can be sign-extended or zero-extended to give back OP.
4032 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
4033 or 0 if the value should be sign-extended. */
4036 get_narrower (op
, unsignedp_ptr
)
4044 while (TREE_CODE (op
) == NOP_EXPR
)
4047 = (TYPE_PRECISION (TREE_TYPE (op
))
4048 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
4050 /* Truncations are many-one so cannot be removed. */
4054 /* See what's inside this conversion. If we decide to strip it,
4056 op
= TREE_OPERAND (op
, 0);
4060 /* An extension: the outermost one can be stripped,
4061 but remember whether it is zero or sign extension. */
4063 uns
= TREE_UNSIGNED (TREE_TYPE (op
));
4064 /* Otherwise, if a sign extension has been stripped,
4065 only sign extensions can now be stripped;
4066 if a zero extension has been stripped, only zero-extensions. */
4067 else if (uns
!= TREE_UNSIGNED (TREE_TYPE (op
)))
4071 else /* bitschange == 0 */
4073 /* A change in nominal type can always be stripped, but we must
4074 preserve the unsignedness. */
4076 uns
= TREE_UNSIGNED (TREE_TYPE (op
));
4083 if (TREE_CODE (op
) == COMPONENT_REF
4084 /* Since type_for_size always gives an integer type. */
4085 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
4086 /* Ensure field is laid out already. */
4087 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0)
4089 unsigned HOST_WIDE_INT innerprec
4090 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
4091 tree type
= (*lang_hooks
.types
.type_for_size
) (innerprec
,
4092 TREE_UNSIGNED (op
));
4094 /* We can get this structure field in a narrower type that fits it,
4095 but the resulting extension to its nominal type (a fullword type)
4096 must satisfy the same conditions as for other extensions.
4098 Do this only for fields that are aligned (not bit-fields),
4099 because when bit-field insns will be used there is no
4100 advantage in doing this. */
4102 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
4103 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
4104 && (first
|| uns
== TREE_UNSIGNED (TREE_OPERAND (op
, 1)))
4108 uns
= TREE_UNSIGNED (TREE_OPERAND (op
, 1));
4109 win
= build (COMPONENT_REF
, type
, TREE_OPERAND (op
, 0),
4110 TREE_OPERAND (op
, 1));
4111 TREE_SIDE_EFFECTS (win
) = TREE_SIDE_EFFECTS (op
);
4112 TREE_THIS_VOLATILE (win
) = TREE_THIS_VOLATILE (op
);
4115 *unsignedp_ptr
= uns
;
4119 /* Nonzero if integer constant C has a value that is permissible
4120 for type TYPE (an INTEGER_TYPE). */
4123 int_fits_type_p (c
, type
)
4126 /* If the bounds of the type are integers, we can check ourselves.
4127 If not, but this type is a subtype, try checking against that.
4128 Otherwise, use force_fit_type, which checks against the precision. */
4129 if (TYPE_MAX_VALUE (type
) != NULL_TREE
4130 && TYPE_MIN_VALUE (type
) != NULL_TREE
4131 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
4132 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
4134 if (TREE_UNSIGNED (type
))
4135 return (! INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type
), c
)
4136 && ! INT_CST_LT_UNSIGNED (c
, TYPE_MIN_VALUE (type
))
4137 /* Negative ints never fit unsigned types. */
4138 && ! (TREE_INT_CST_HIGH (c
) < 0
4139 && ! TREE_UNSIGNED (TREE_TYPE (c
))));
4141 return (! INT_CST_LT (TYPE_MAX_VALUE (type
), c
)
4142 && ! INT_CST_LT (c
, TYPE_MIN_VALUE (type
))
4143 /* Unsigned ints with top bit set never fit signed types. */
4144 && ! (TREE_INT_CST_HIGH (c
) < 0
4145 && TREE_UNSIGNED (TREE_TYPE (c
))));
4147 else if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != 0)
4148 return int_fits_type_p (c
, TREE_TYPE (type
));
4152 TREE_TYPE (c
) = type
;
4153 return !force_fit_type (c
, 0);
4157 /* Given a DECL or TYPE, return the scope in which it was declared, or
4158 NULL_TREE if there is no containing scope. */
4161 get_containing_scope (t
)
4164 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
4167 /* Return the innermost context enclosing DECL that is
4168 a FUNCTION_DECL, or zero if none. */
4171 decl_function_context (decl
)
4176 if (TREE_CODE (decl
) == ERROR_MARK
)
4179 if (TREE_CODE (decl
) == SAVE_EXPR
)
4180 context
= SAVE_EXPR_CONTEXT (decl
);
4182 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
4183 where we look up the function at runtime. Such functions always take
4184 a first argument of type 'pointer to real context'.
4186 C++ should really be fixed to use DECL_CONTEXT for the real context,
4187 and use something else for the "virtual context". */
4188 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
4191 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4193 context
= DECL_CONTEXT (decl
);
4195 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
4197 if (TREE_CODE (context
) == BLOCK
)
4198 context
= BLOCK_SUPERCONTEXT (context
);
4200 context
= get_containing_scope (context
);
4206 /* Return the innermost context enclosing DECL that is
4207 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
4208 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
4211 decl_type_context (decl
)
4214 tree context
= DECL_CONTEXT (decl
);
4218 if (TREE_CODE (context
) == NAMESPACE_DECL
)
4221 if (TREE_CODE (context
) == RECORD_TYPE
4222 || TREE_CODE (context
) == UNION_TYPE
4223 || TREE_CODE (context
) == QUAL_UNION_TYPE
)
4226 if (TREE_CODE (context
) == TYPE_DECL
4227 || TREE_CODE (context
) == FUNCTION_DECL
)
4228 context
= DECL_CONTEXT (context
);
4230 else if (TREE_CODE (context
) == BLOCK
)
4231 context
= BLOCK_SUPERCONTEXT (context
);
4234 /* Unhandled CONTEXT!? */
4240 /* CALL is a CALL_EXPR. Return the declaration for the function
4241 called, or NULL_TREE if the called function cannot be
4245 get_callee_fndecl (call
)
4250 /* It's invalid to call this function with anything but a
4252 if (TREE_CODE (call
) != CALL_EXPR
)
4255 /* The first operand to the CALL is the address of the function
4257 addr
= TREE_OPERAND (call
, 0);
4261 /* If this is a readonly function pointer, extract its initial value. */
4262 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
4263 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
4264 && DECL_INITIAL (addr
))
4265 addr
= DECL_INITIAL (addr
);
4267 /* If the address is just `&f' for some function `f', then we know
4268 that `f' is being called. */
4269 if (TREE_CODE (addr
) == ADDR_EXPR
4270 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
4271 return TREE_OPERAND (addr
, 0);
4273 /* We couldn't figure out what was being called. */
4277 /* Print debugging information about the obstack O, named STR. */
4280 print_obstack_statistics (str
, o
)
4284 struct _obstack_chunk
*chunk
= o
->chunk
;
4288 n_alloc
+= o
->next_free
- chunk
->contents
;
4289 chunk
= chunk
->prev
;
4293 n_alloc
+= chunk
->limit
- &chunk
->contents
[0];
4294 chunk
= chunk
->prev
;
4296 fprintf (stderr
, "obstack %s: %u bytes, %d chunks\n",
4297 str
, n_alloc
, n_chunks
);
4300 /* Print debugging information about tree nodes generated during the compile,
4301 and any language-specific information. */
4304 dump_tree_statistics ()
4306 #ifdef GATHER_STATISTICS
4308 int total_nodes
, total_bytes
;
4311 fprintf (stderr
, "\n??? tree nodes created\n\n");
4312 #ifdef GATHER_STATISTICS
4313 fprintf (stderr
, "Kind Nodes Bytes\n");
4314 fprintf (stderr
, "-------------------------------------\n");
4315 total_nodes
= total_bytes
= 0;
4316 for (i
= 0; i
< (int) all_kinds
; i
++)
4318 fprintf (stderr
, "%-20s %6d %9d\n", tree_node_kind_names
[i
],
4319 tree_node_counts
[i
], tree_node_sizes
[i
]);
4320 total_nodes
+= tree_node_counts
[i
];
4321 total_bytes
+= tree_node_sizes
[i
];
4323 fprintf (stderr
, "-------------------------------------\n");
4324 fprintf (stderr
, "%-20s %6d %9d\n", "Total", total_nodes
, total_bytes
);
4325 fprintf (stderr
, "-------------------------------------\n");
4327 fprintf (stderr
, "(No per-node statistics)\n");
4329 print_type_hash_statistics ();
4330 (*lang_hooks
.print_statistics
) ();
4333 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
4335 /* Appends 6 random characters to TEMPLATE to (hopefully) avoid name
4336 clashes in cases where we can't reliably choose a unique name.
4338 Derived from mkstemp.c in libiberty. */
4341 append_random_chars (template)
4344 static const char letters
[]
4345 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
4346 static unsigned HOST_WIDE_INT value
;
4347 unsigned HOST_WIDE_INT v
;
4353 /* VALUE should be unique for each file and must not change between
4354 compiles since this can cause bootstrap comparison errors. */
4356 if (stat (main_input_filename
, &st
) < 0)
4358 /* This can happen when preprocessed text is shipped between
4359 machines, e.g. with bug reports. Assume that uniqueness
4360 isn't actually an issue. */
4365 /* In VMS, ino is an array, so we have to use both values. We
4366 conditionalize that. */
4368 #define INO_TO_INT(INO) ((int) (INO)[1] << 16 ^ (int) (INO)[2])
4370 #define INO_TO_INT(INO) INO
4372 value
= st
.st_dev
^ INO_TO_INT (st
.st_ino
) ^ st
.st_mtime
;
4376 template += strlen (template);
4380 /* Fill in the random bits. */
4381 template[0] = letters
[v
% 62];
4383 template[1] = letters
[v
% 62];
4385 template[2] = letters
[v
% 62];
4387 template[3] = letters
[v
% 62];
4389 template[4] = letters
[v
% 62];
4391 template[5] = letters
[v
% 62];
4396 /* P is a string that will be used in a symbol. Mask out any characters
4397 that are not valid in that context. */
4400 clean_symbol_name (p
)
4405 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
4408 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
4415 /* Generate a name for a function unique to this translation unit.
4416 TYPE is some string to identify the purpose of this function to the
4417 linker or collect2. */
4420 get_file_function_name_long (type
)
4427 if (first_global_object_name
)
4428 p
= first_global_object_name
;
4431 /* We don't have anything that we know to be unique to this translation
4432 unit, so use what we do have and throw in some randomness. */
4434 const char *name
= weak_global_object_name
;
4435 const char *file
= main_input_filename
;
4440 file
= input_filename
;
4442 q
= (char *) alloca (7 + strlen (name
) + strlen (file
));
4444 sprintf (q
, "%s%s", name
, file
);
4445 append_random_chars (q
);
4449 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
)
4452 /* Set up the name of the file-level functions we may need.
4453 Use a global object (which is already required to be unique over
4454 the program) rather than the file name (which imposes extra
4456 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
4458 /* Don't need to pull weird characters out of global names. */
4459 if (p
!= first_global_object_name
)
4460 clean_symbol_name (buf
+ 11);
4462 return get_identifier (buf
);
4465 /* If KIND=='I', return a suitable global initializer (constructor) name.
4466 If KIND=='D', return a suitable global clean-up (destructor) name. */
4469 get_file_function_name (kind
)
4477 return get_file_function_name_long (p
);
4480 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
4481 The result is placed in BUFFER (which has length BIT_SIZE),
4482 with one bit in each char ('\000' or '\001').
4484 If the constructor is constant, NULL_TREE is returned.
4485 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
4488 get_set_constructor_bits (init
, buffer
, bit_size
)
4495 HOST_WIDE_INT domain_min
4496 = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init
))), 0);
4497 tree non_const_bits
= NULL_TREE
;
4499 for (i
= 0; i
< bit_size
; i
++)
4502 for (vals
= TREE_OPERAND (init
, 1);
4503 vals
!= NULL_TREE
; vals
= TREE_CHAIN (vals
))
4505 if (!host_integerp (TREE_VALUE (vals
), 0)
4506 || (TREE_PURPOSE (vals
) != NULL_TREE
4507 && !host_integerp (TREE_PURPOSE (vals
), 0)))
4509 = tree_cons (TREE_PURPOSE (vals
), TREE_VALUE (vals
), non_const_bits
);
4510 else if (TREE_PURPOSE (vals
) != NULL_TREE
)
4512 /* Set a range of bits to ones. */
4513 HOST_WIDE_INT lo_index
4514 = tree_low_cst (TREE_PURPOSE (vals
), 0) - domain_min
;
4515 HOST_WIDE_INT hi_index
4516 = tree_low_cst (TREE_VALUE (vals
), 0) - domain_min
;
4518 if (lo_index
< 0 || lo_index
>= bit_size
4519 || hi_index
< 0 || hi_index
>= bit_size
)
4521 for (; lo_index
<= hi_index
; lo_index
++)
4522 buffer
[lo_index
] = 1;
4526 /* Set a single bit to one. */
4528 = tree_low_cst (TREE_VALUE (vals
), 0) - domain_min
;
4529 if (index
< 0 || index
>= bit_size
)
4531 error ("invalid initializer for bit string");
4537 return non_const_bits
;
4540 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
4541 The result is placed in BUFFER (which is an array of bytes).
4542 If the constructor is constant, NULL_TREE is returned.
4543 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
4546 get_set_constructor_bytes (init
, buffer
, wd_size
)
4548 unsigned char *buffer
;
4552 int set_word_size
= BITS_PER_UNIT
;
4553 int bit_size
= wd_size
* set_word_size
;
4555 unsigned char *bytep
= buffer
;
4556 char *bit_buffer
= (char *) alloca (bit_size
);
4557 tree non_const_bits
= get_set_constructor_bits (init
, bit_buffer
, bit_size
);
4559 for (i
= 0; i
< wd_size
; i
++)
4562 for (i
= 0; i
< bit_size
; i
++)
4566 if (BYTES_BIG_ENDIAN
)
4567 *bytep
|= (1 << (set_word_size
- 1 - bit_pos
));
4569 *bytep
|= 1 << bit_pos
;
4572 if (bit_pos
>= set_word_size
)
4573 bit_pos
= 0, bytep
++;
4575 return non_const_bits
;
4578 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
4579 /* Complain that the tree code of NODE does not match the expected CODE.
4580 FILE, LINE, and FUNCTION are of the caller. */
4583 tree_check_failed (node
, code
, file
, line
, function
)
4585 enum tree_code code
;
4588 const char *function
;
4590 internal_error ("tree check: expected %s, have %s in %s, at %s:%d",
4591 tree_code_name
[code
], tree_code_name
[TREE_CODE (node
)],
4592 function
, trim_filename (file
), line
);
4595 /* Similar to above, except that we check for a class of tree
4596 code, given in CL. */
4599 tree_class_check_failed (node
, cl
, file
, line
, function
)
4604 const char *function
;
4607 ("tree check: expected class '%c', have '%c' (%s) in %s, at %s:%d",
4608 cl
, TREE_CODE_CLASS (TREE_CODE (node
)),
4609 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
4612 #endif /* ENABLE_TREE_CHECKING */
4614 /* For a new vector type node T, build the information necessary for
4615 debugging output. */
4618 finish_vector_type (t
)
4624 tree index
= build_int_2 (TYPE_VECTOR_SUBPARTS (t
) - 1, 0);
4625 tree array
= build_array_type (TREE_TYPE (t
),
4626 build_index_type (index
));
4627 tree rt
= make_node (RECORD_TYPE
);
4629 TYPE_FIELDS (rt
) = build_decl (FIELD_DECL
, get_identifier ("f"), array
);
4630 DECL_CONTEXT (TYPE_FIELDS (rt
)) = rt
;
4632 TYPE_DEBUG_REPRESENTATION_TYPE (t
) = rt
;
4633 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
4634 the representation type, and we want to find that die when looking up
4635 the vector type. This is most easily achieved by making the TYPE_UID
4637 TYPE_UID (rt
) = TYPE_UID (t
);
4641 /* Create nodes for all integer types (and error_mark_node) using the sizes
4642 of C datatypes. The caller should call set_sizetype soon after calling
4643 this function to select one of the types as sizetype. */
4646 build_common_tree_nodes (signed_char
)
4649 error_mark_node
= make_node (ERROR_MARK
);
4650 TREE_TYPE (error_mark_node
) = error_mark_node
;
4652 initialize_sizetypes ();
4654 /* Define both `signed char' and `unsigned char'. */
4655 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
4656 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
4658 /* Define `char', which is like either `signed char' or `unsigned char'
4659 but not the same as either. */
4662 ? make_signed_type (CHAR_TYPE_SIZE
)
4663 : make_unsigned_type (CHAR_TYPE_SIZE
));
4665 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
4666 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
4667 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
4668 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
4669 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
4670 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
4671 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
4672 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
4674 intQI_type_node
= make_signed_type (GET_MODE_BITSIZE (QImode
));
4675 intHI_type_node
= make_signed_type (GET_MODE_BITSIZE (HImode
));
4676 intSI_type_node
= make_signed_type (GET_MODE_BITSIZE (SImode
));
4677 intDI_type_node
= make_signed_type (GET_MODE_BITSIZE (DImode
));
4678 intTI_type_node
= make_signed_type (GET_MODE_BITSIZE (TImode
));
4680 unsigned_intQI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (QImode
));
4681 unsigned_intHI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (HImode
));
4682 unsigned_intSI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (SImode
));
4683 unsigned_intDI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (DImode
));
4684 unsigned_intTI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (TImode
));
4687 /* Call this function after calling build_common_tree_nodes and set_sizetype.
4688 It will create several other common tree nodes. */
4691 build_common_tree_nodes_2 (short_double
)
4694 /* Define these next since types below may used them. */
4695 integer_zero_node
= build_int_2 (0, 0);
4696 integer_one_node
= build_int_2 (1, 0);
4697 integer_minus_one_node
= build_int_2 (-1, -1);
4699 size_zero_node
= size_int (0);
4700 size_one_node
= size_int (1);
4701 bitsize_zero_node
= bitsize_int (0);
4702 bitsize_one_node
= bitsize_int (1);
4703 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
4705 void_type_node
= make_node (VOID_TYPE
);
4706 layout_type (void_type_node
);
4708 /* We are not going to have real types in C with less than byte alignment,
4709 so we might as well not have any types that claim to have it. */
4710 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
4711 TYPE_USER_ALIGN (void_type_node
) = 0;
4713 null_pointer_node
= build_int_2 (0, 0);
4714 TREE_TYPE (null_pointer_node
) = build_pointer_type (void_type_node
);
4715 layout_type (TREE_TYPE (null_pointer_node
));
4717 ptr_type_node
= build_pointer_type (void_type_node
);
4719 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
4721 float_type_node
= make_node (REAL_TYPE
);
4722 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
4723 layout_type (float_type_node
);
4725 double_type_node
= make_node (REAL_TYPE
);
4727 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
4729 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
4730 layout_type (double_type_node
);
4732 long_double_type_node
= make_node (REAL_TYPE
);
4733 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
4734 layout_type (long_double_type_node
);
4736 complex_integer_type_node
= make_node (COMPLEX_TYPE
);
4737 TREE_TYPE (complex_integer_type_node
) = integer_type_node
;
4738 layout_type (complex_integer_type_node
);
4740 complex_float_type_node
= make_node (COMPLEX_TYPE
);
4741 TREE_TYPE (complex_float_type_node
) = float_type_node
;
4742 layout_type (complex_float_type_node
);
4744 complex_double_type_node
= make_node (COMPLEX_TYPE
);
4745 TREE_TYPE (complex_double_type_node
) = double_type_node
;
4746 layout_type (complex_double_type_node
);
4748 complex_long_double_type_node
= make_node (COMPLEX_TYPE
);
4749 TREE_TYPE (complex_long_double_type_node
) = long_double_type_node
;
4750 layout_type (complex_long_double_type_node
);
4754 BUILD_VA_LIST_TYPE (t
);
4756 /* Many back-ends define record types without seting TYPE_NAME.
4757 If we copied the record type here, we'd keep the original
4758 record type without a name. This breaks name mangling. So,
4759 don't copy record types and let c_common_nodes_and_builtins()
4760 declare the type to be __builtin_va_list. */
4761 if (TREE_CODE (t
) != RECORD_TYPE
)
4762 t
= build_type_copy (t
);
4764 va_list_type_node
= t
;
4767 unsigned_V4SI_type_node
4768 = make_vector (V4SImode
, unsigned_intSI_type_node
, 1);
4769 unsigned_V2SI_type_node
4770 = make_vector (V2SImode
, unsigned_intSI_type_node
, 1);
4771 unsigned_V2DI_type_node
4772 = make_vector (V2DImode
, unsigned_intDI_type_node
, 1);
4773 unsigned_V4HI_type_node
4774 = make_vector (V4HImode
, unsigned_intHI_type_node
, 1);
4775 unsigned_V8QI_type_node
4776 = make_vector (V8QImode
, unsigned_intQI_type_node
, 1);
4777 unsigned_V8HI_type_node
4778 = make_vector (V8HImode
, unsigned_intHI_type_node
, 1);
4779 unsigned_V16QI_type_node
4780 = make_vector (V16QImode
, unsigned_intQI_type_node
, 1);
4782 V16SF_type_node
= make_vector (V16SFmode
, float_type_node
, 0);
4783 V4SF_type_node
= make_vector (V4SFmode
, float_type_node
, 0);
4784 V4SI_type_node
= make_vector (V4SImode
, intSI_type_node
, 0);
4785 V2SI_type_node
= make_vector (V2SImode
, intSI_type_node
, 0);
4786 V2DI_type_node
= make_vector (V2DImode
, intDI_type_node
, 0);
4787 V4HI_type_node
= make_vector (V4HImode
, intHI_type_node
, 0);
4788 V8QI_type_node
= make_vector (V8QImode
, intQI_type_node
, 0);
4789 V8HI_type_node
= make_vector (V8HImode
, intHI_type_node
, 0);
4790 V2SF_type_node
= make_vector (V2SFmode
, float_type_node
, 0);
4791 V2DF_type_node
= make_vector (V2DFmode
, double_type_node
, 0);
4792 V16QI_type_node
= make_vector (V16QImode
, intQI_type_node
, 0);
4795 /* Returns a vector tree node given a vector mode, the inner type, and
4799 make_vector (mode
, innertype
, unsignedp
)
4800 enum machine_mode mode
;
4806 t
= make_node (VECTOR_TYPE
);
4807 TREE_TYPE (t
) = innertype
;
4808 TYPE_MODE (t
) = mode
;
4809 TREE_UNSIGNED (TREE_TYPE (t
)) = unsignedp
;
4810 finish_vector_type (t
);
4815 /* Given an initializer INIT, return TRUE if INIT is zero or some
4816 aggregate of zeros. Otherwise return FALSE. */
4819 initializer_zerop (init
)
4824 switch (TREE_CODE (init
))
4827 return integer_zerop (init
);
4829 return real_zerop (init
)
4830 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
4832 return integer_zerop (init
)
4833 || (real_zerop (init
)
4834 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
4835 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
4838 if (AGGREGATE_TYPE_P (TREE_TYPE (init
)))
4840 tree aggr_init
= TREE_OPERAND (init
, 1);
4844 if (! initializer_zerop (TREE_VALUE (aggr_init
)))
4846 aggr_init
= TREE_CHAIN (aggr_init
);
4857 #include "gt-tree.h"