1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
22 /* This file contains the low level primitives for operating on tree nodes,
23 including allocation, list operations, interning of identifiers,
24 construction of data type nodes and statement nodes,
25 and construction of type conversion nodes. It also contains
26 tables index by tree code that describe how to take apart
29 It is intended to be language-independent, but occasionally
30 calls language-dependent routines defined (for C) in typecheck.c. */
34 #include "coretypes.h"
47 #include "langhooks.h"
48 #include "tree-iterator.h"
49 #include "basic-block.h"
50 #include "tree-flow.h"
52 #include "pointer-set.h"
54 /* Each tree code class has an associated string representation.
55 These must correspond to the tree_code_class entries. */
57 const char *const tree_code_class_strings
[] =
71 /* obstack.[ch] explicitly declined to prototype this. */
72 extern int _obstack_allocated_p (struct obstack
*h
, void *obj
);
74 #ifdef GATHER_STATISTICS
75 /* Statistics-gathering stuff. */
77 int tree_node_counts
[(int) all_kinds
];
78 int tree_node_sizes
[(int) all_kinds
];
80 /* Keep in sync with tree.h:enum tree_node_kind. */
81 static const char * const tree_node_kind_names
[] = {
101 #endif /* GATHER_STATISTICS */
103 /* Unique id for next decl created. */
104 static GTY(()) int next_decl_uid
;
105 /* Unique id for next type created. */
106 static GTY(()) int next_type_uid
= 1;
108 /* Since we cannot rehash a type after it is in the table, we have to
109 keep the hash code. */
111 struct type_hash
GTY(())
117 /* Initial size of the hash table (rounded to next prime). */
118 #define TYPE_HASH_INITIAL_SIZE 1000
120 /* Now here is the hash table. When recording a type, it is added to
121 the slot whose index is the hash code. Note that the hash table is
122 used for several kinds of types (function types, array types and
123 array index range types, for now). While all these live in the
124 same table, they are completely independent, and the hash code is
125 computed differently for each of these. */
127 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash
)))
128 htab_t type_hash_table
;
130 /* Hash table and temporary node for larger integer const values. */
131 static GTY (()) tree int_cst_node
;
132 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
133 htab_t int_cst_hash_table
;
135 /* General tree->tree mapping structure for use in hash tables. */
138 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
139 htab_t debug_expr_for_decl
;
141 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
142 htab_t value_expr_for_decl
;
144 static GTY ((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map
)))
145 htab_t init_priority_for_decl
;
147 struct tree_int_map
GTY(())
152 static unsigned int tree_int_map_hash (const void *);
153 static int tree_int_map_eq (const void *, const void *);
154 static int tree_int_map_marked_p (const void *);
155 static void set_type_quals (tree
, int);
156 static int type_hash_eq (const void *, const void *);
157 static hashval_t
type_hash_hash (const void *);
158 static hashval_t
int_cst_hash_hash (const void *);
159 static int int_cst_hash_eq (const void *, const void *);
160 static void print_type_hash_statistics (void);
161 static void print_debug_expr_statistics (void);
162 static void print_value_expr_statistics (void);
163 static tree
make_vector_type (tree
, int, enum machine_mode
);
164 static int type_hash_marked_p (const void *);
165 static unsigned int type_hash_list (tree
, hashval_t
);
166 static unsigned int attribute_hash_list (tree
, hashval_t
);
168 tree global_trees
[TI_MAX
];
169 tree integer_types
[itk_none
];
171 unsigned char tree_contains_struct
[256][64];
179 /* Initialize the hash table of types. */
180 type_hash_table
= htab_create_ggc (TYPE_HASH_INITIAL_SIZE
, type_hash_hash
,
183 debug_expr_for_decl
= htab_create_ggc (512, tree_map_hash
,
186 value_expr_for_decl
= htab_create_ggc (512, tree_map_hash
,
188 init_priority_for_decl
= htab_create_ggc (512, tree_int_map_hash
,
191 int_cst_hash_table
= htab_create_ggc (1024, int_cst_hash_hash
,
192 int_cst_hash_eq
, NULL
);
194 int_cst_node
= make_node (INTEGER_CST
);
196 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
] = 1;
197 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_NON_COMMON
] = 1;
198 tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
] = 1;
201 tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
] = 1;
202 tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
] = 1;
203 tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
] = 1;
204 tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
] = 1;
205 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
] = 1;
206 tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
] = 1;
207 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
] = 1;
208 tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
] = 1;
209 tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
] = 1;
212 tree_contains_struct
[CONST_DECL
][TS_DECL_WRTL
] = 1;
213 tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
] = 1;
214 tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
] = 1;
215 tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
] = 1;
216 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
] = 1;
217 tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
] = 1;
219 tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
] = 1;
220 tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
] = 1;
221 tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
] = 1;
222 tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
] = 1;
223 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
] = 1;
224 tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
] = 1;
225 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
] = 1;
226 tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
] = 1;
227 tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
] = 1;
228 tree_contains_struct
[STRUCT_FIELD_TAG
][TS_DECL_MINIMAL
] = 1;
229 tree_contains_struct
[NAME_MEMORY_TAG
][TS_DECL_MINIMAL
] = 1;
230 tree_contains_struct
[TYPE_MEMORY_TAG
][TS_DECL_MINIMAL
] = 1;
232 tree_contains_struct
[STRUCT_FIELD_TAG
][TS_MEMORY_TAG
] = 1;
233 tree_contains_struct
[NAME_MEMORY_TAG
][TS_MEMORY_TAG
] = 1;
234 tree_contains_struct
[TYPE_MEMORY_TAG
][TS_MEMORY_TAG
] = 1;
236 tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
] = 1;
237 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
] = 1;
238 tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
] = 1;
239 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_WITH_VIS
] = 1;
241 tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
] = 1;
242 tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
] = 1;
243 tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
] = 1;
244 tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
] = 1;
245 tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
] = 1;
246 tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
] = 1;
247 tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
] = 1;
248 tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
] = 1;
250 lang_hooks
.init_ts ();
254 /* The name of the object as the assembler will see it (but before any
255 translations made by ASM_OUTPUT_LABELREF). Often this is the same
256 as DECL_NAME. It is an IDENTIFIER_NODE. */
258 decl_assembler_name (tree decl
)
260 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
261 lang_hooks
.set_decl_assembler_name (decl
);
262 return DECL_WITH_VIS_CHECK (decl
)->decl_with_vis
.assembler_name
;
265 /* Compute the number of bytes occupied by a tree with code CODE.
266 This function cannot be used for TREE_VEC, PHI_NODE, or STRING_CST
267 codes, which are of variable length. */
269 tree_code_size (enum tree_code code
)
271 switch (TREE_CODE_CLASS (code
))
273 case tcc_declaration
: /* A decl node */
278 return sizeof (struct tree_field_decl
);
280 return sizeof (struct tree_parm_decl
);
282 return sizeof (struct tree_var_decl
);
284 return sizeof (struct tree_label_decl
);
286 return sizeof (struct tree_result_decl
);
288 return sizeof (struct tree_const_decl
);
290 return sizeof (struct tree_type_decl
);
292 return sizeof (struct tree_function_decl
);
293 case NAME_MEMORY_TAG
:
294 case TYPE_MEMORY_TAG
:
295 case STRUCT_FIELD_TAG
:
296 return sizeof (struct tree_memory_tag
);
298 return sizeof (struct tree_decl_non_common
);
302 case tcc_type
: /* a type node */
303 return sizeof (struct tree_type
);
305 case tcc_reference
: /* a reference */
306 case tcc_expression
: /* an expression */
307 case tcc_statement
: /* an expression with side effects */
308 case tcc_comparison
: /* a comparison expression */
309 case tcc_unary
: /* a unary arithmetic expression */
310 case tcc_binary
: /* a binary arithmetic expression */
311 return (sizeof (struct tree_exp
)
312 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (char *));
314 case tcc_constant
: /* a constant */
317 case INTEGER_CST
: return sizeof (struct tree_int_cst
);
318 case REAL_CST
: return sizeof (struct tree_real_cst
);
319 case COMPLEX_CST
: return sizeof (struct tree_complex
);
320 case VECTOR_CST
: return sizeof (struct tree_vector
);
321 case STRING_CST
: gcc_unreachable ();
323 return lang_hooks
.tree_size (code
);
326 case tcc_exceptional
: /* something random, like an identifier. */
329 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
330 case TREE_LIST
: return sizeof (struct tree_list
);
333 case PLACEHOLDER_EXPR
: return sizeof (struct tree_common
);
336 case PHI_NODE
: gcc_unreachable ();
338 case SSA_NAME
: return sizeof (struct tree_ssa_name
);
340 case STATEMENT_LIST
: return sizeof (struct tree_statement_list
);
341 case BLOCK
: return sizeof (struct tree_block
);
342 case VALUE_HANDLE
: return sizeof (struct tree_value_handle
);
343 case CONSTRUCTOR
: return sizeof (struct tree_constructor
);
346 return lang_hooks
.tree_size (code
);
354 /* Compute the number of bytes occupied by NODE. This routine only
355 looks at TREE_CODE, except for PHI_NODE and TREE_VEC nodes. */
357 tree_size (tree node
)
359 enum tree_code code
= TREE_CODE (node
);
363 return (sizeof (struct tree_phi_node
)
364 + (PHI_ARG_CAPACITY (node
) - 1) * sizeof (struct phi_arg_d
));
367 return (offsetof (struct tree_binfo
, base_binfos
)
368 + VEC_embedded_size (tree
, BINFO_N_BASE_BINFOS (node
)));
371 return (sizeof (struct tree_vec
)
372 + (TREE_VEC_LENGTH (node
) - 1) * sizeof(char *));
375 return sizeof (struct tree_string
) + TREE_STRING_LENGTH (node
) - 1;
378 return tree_code_size (code
);
382 /* Return a newly allocated node of code CODE. For decl and type
383 nodes, some other fields are initialized. The rest of the node is
384 initialized to zero. This function cannot be used for PHI_NODE or
385 TREE_VEC nodes, which is enforced by asserts in tree_code_size.
387 Achoo! I got a code in the node. */
390 make_node_stat (enum tree_code code MEM_STAT_DECL
)
393 enum tree_code_class type
= TREE_CODE_CLASS (code
);
394 size_t length
= tree_code_size (code
);
395 #ifdef GATHER_STATISTICS
400 case tcc_declaration
: /* A decl node */
404 case tcc_type
: /* a type node */
408 case tcc_statement
: /* an expression with side effects */
412 case tcc_reference
: /* a reference */
416 case tcc_expression
: /* an expression */
417 case tcc_comparison
: /* a comparison expression */
418 case tcc_unary
: /* a unary arithmetic expression */
419 case tcc_binary
: /* a binary arithmetic expression */
423 case tcc_constant
: /* a constant */
427 case tcc_exceptional
: /* something random, like an identifier. */
430 case IDENTIFIER_NODE
:
447 kind
= ssa_name_kind
;
468 tree_node_counts
[(int) kind
]++;
469 tree_node_sizes
[(int) kind
] += length
;
472 if (code
== IDENTIFIER_NODE
)
473 t
= ggc_alloc_zone_pass_stat (length
, &tree_id_zone
);
475 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
477 memset (t
, 0, length
);
479 TREE_SET_CODE (t
, code
);
484 TREE_SIDE_EFFECTS (t
) = 1;
487 case tcc_declaration
:
488 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
489 DECL_IN_SYSTEM_HEADER (t
) = in_system_header
;
490 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
492 if (code
!= FUNCTION_DECL
)
494 DECL_USER_ALIGN (t
) = 0;
495 /* We have not yet computed the alias set for this declaration. */
496 DECL_POINTER_ALIAS_SET (t
) = -1;
498 DECL_SOURCE_LOCATION (t
) = input_location
;
499 DECL_UID (t
) = next_decl_uid
++;
504 TYPE_UID (t
) = next_type_uid
++;
505 TYPE_ALIGN (t
) = BITS_PER_UNIT
;
506 TYPE_USER_ALIGN (t
) = 0;
507 TYPE_MAIN_VARIANT (t
) = t
;
509 /* Default to no attributes for type, but let target change that. */
510 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
511 targetm
.set_default_type_attributes (t
);
513 /* We have not yet computed the alias set for this type. */
514 TYPE_ALIAS_SET (t
) = -1;
518 TREE_CONSTANT (t
) = 1;
519 TREE_INVARIANT (t
) = 1;
528 case PREDECREMENT_EXPR
:
529 case PREINCREMENT_EXPR
:
530 case POSTDECREMENT_EXPR
:
531 case POSTINCREMENT_EXPR
:
532 /* All of these have side-effects, no matter what their
534 TREE_SIDE_EFFECTS (t
) = 1;
543 /* Other classes need no special treatment. */
550 /* Return a new node with the same contents as NODE except that its
551 TREE_CHAIN is zero and it has a fresh uid. */
554 copy_node_stat (tree node MEM_STAT_DECL
)
557 enum tree_code code
= TREE_CODE (node
);
560 gcc_assert (code
!= STATEMENT_LIST
);
562 length
= tree_size (node
);
563 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
564 memcpy (t
, node
, length
);
567 TREE_ASM_WRITTEN (t
) = 0;
568 TREE_VISITED (t
) = 0;
571 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
573 DECL_UID (t
) = next_decl_uid
++;
574 if ((TREE_CODE (node
) == PARM_DECL
|| TREE_CODE (node
) == VAR_DECL
)
575 && DECL_HAS_VALUE_EXPR_P (node
))
577 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
578 DECL_HAS_VALUE_EXPR_P (t
) = 1;
580 if (TREE_CODE (node
) == VAR_DECL
&& DECL_HAS_INIT_PRIORITY_P (node
))
582 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
583 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
587 else if (TREE_CODE_CLASS (code
) == tcc_type
)
589 TYPE_UID (t
) = next_type_uid
++;
590 /* The following is so that the debug code for
591 the copy is different from the original type.
592 The two statements usually duplicate each other
593 (because they clear fields of the same union),
594 but the optimizer should catch that. */
595 TYPE_SYMTAB_POINTER (t
) = 0;
596 TYPE_SYMTAB_ADDRESS (t
) = 0;
598 /* Do not copy the values cache. */
599 if (TYPE_CACHED_VALUES_P(t
))
601 TYPE_CACHED_VALUES_P (t
) = 0;
602 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
609 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
610 For example, this can copy a list made of TREE_LIST nodes. */
613 copy_list (tree list
)
621 head
= prev
= copy_node (list
);
622 next
= TREE_CHAIN (list
);
625 TREE_CHAIN (prev
) = copy_node (next
);
626 prev
= TREE_CHAIN (prev
);
627 next
= TREE_CHAIN (next
);
633 /* Create an INT_CST node with a LOW value sign extended. */
636 build_int_cst (tree type
, HOST_WIDE_INT low
)
638 return build_int_cst_wide (type
, low
, low
< 0 ? -1 : 0);
641 /* Create an INT_CST node with a LOW value zero extended. */
644 build_int_cstu (tree type
, unsigned HOST_WIDE_INT low
)
646 return build_int_cst_wide (type
, low
, 0);
649 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
650 if it is negative. This function is similar to build_int_cst, but
651 the extra bits outside of the type precision are cleared. Constants
652 with these extra bits may confuse the fold so that it detects overflows
653 even in cases when they do not occur, and in general should be avoided.
654 We cannot however make this a default behavior of build_int_cst without
655 more intrusive changes, since there are parts of gcc that rely on the extra
656 precision of the integer constants. */
659 build_int_cst_type (tree type
, HOST_WIDE_INT low
)
661 unsigned HOST_WIDE_INT val
= (unsigned HOST_WIDE_INT
) low
;
662 unsigned HOST_WIDE_INT hi
, mask
;
668 type
= integer_type_node
;
670 bits
= TYPE_PRECISION (type
);
671 signed_p
= !TYPE_UNSIGNED (type
);
673 if (bits
>= HOST_BITS_PER_WIDE_INT
)
674 negative
= (low
< 0);
677 /* If the sign bit is inside precision of LOW, use it to determine
678 the sign of the constant. */
679 negative
= ((val
>> (bits
- 1)) & 1) != 0;
681 /* Mask out the bits outside of the precision of the constant. */
682 mask
= (((unsigned HOST_WIDE_INT
) 2) << (bits
- 1)) - 1;
684 if (signed_p
&& negative
)
690 /* Determine the high bits. */
691 hi
= (negative
? ~(unsigned HOST_WIDE_INT
) 0 : 0);
693 /* For unsigned type we need to mask out the bits outside of the type
697 if (bits
<= HOST_BITS_PER_WIDE_INT
)
701 bits
-= HOST_BITS_PER_WIDE_INT
;
702 mask
= (((unsigned HOST_WIDE_INT
) 2) << (bits
- 1)) - 1;
707 return build_int_cst_wide (type
, val
, hi
);
710 /* These are the hash table functions for the hash table of INTEGER_CST
711 nodes of a sizetype. */
713 /* Return the hash code code X, an INTEGER_CST. */
716 int_cst_hash_hash (const void *x
)
720 return (TREE_INT_CST_HIGH (t
) ^ TREE_INT_CST_LOW (t
)
721 ^ htab_hash_pointer (TREE_TYPE (t
)));
724 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
725 is the same as that given by *Y, which is the same. */
728 int_cst_hash_eq (const void *x
, const void *y
)
733 return (TREE_TYPE (xt
) == TREE_TYPE (yt
)
734 && TREE_INT_CST_HIGH (xt
) == TREE_INT_CST_HIGH (yt
)
735 && TREE_INT_CST_LOW (xt
) == TREE_INT_CST_LOW (yt
));
738 /* Create an INT_CST node of TYPE and value HI:LOW. If TYPE is NULL,
739 integer_type_node is used. The returned node is always shared.
740 For small integers we use a per-type vector cache, for larger ones
741 we use a single hash table. */
744 build_int_cst_wide (tree type
, unsigned HOST_WIDE_INT low
, HOST_WIDE_INT hi
)
751 type
= integer_type_node
;
753 switch (TREE_CODE (type
))
757 /* Cache NULL pointer. */
766 /* Cache false or true. */
775 if (TYPE_UNSIGNED (type
))
778 limit
= INTEGER_SHARE_LIMIT
;
779 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
785 limit
= INTEGER_SHARE_LIMIT
+ 1;
786 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
788 else if (hi
== -1 && low
== -(unsigned HOST_WIDE_INT
)1)
798 /* Look for it in the type's vector of small shared ints. */
799 if (!TYPE_CACHED_VALUES_P (type
))
801 TYPE_CACHED_VALUES_P (type
) = 1;
802 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
805 t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
);
808 /* Make sure no one is clobbering the shared constant. */
809 gcc_assert (TREE_TYPE (t
) == type
);
810 gcc_assert (TREE_INT_CST_LOW (t
) == low
);
811 gcc_assert (TREE_INT_CST_HIGH (t
) == hi
);
815 /* Create a new shared int. */
816 t
= make_node (INTEGER_CST
);
818 TREE_INT_CST_LOW (t
) = low
;
819 TREE_INT_CST_HIGH (t
) = hi
;
820 TREE_TYPE (t
) = type
;
822 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
827 /* Use the cache of larger shared ints. */
830 TREE_INT_CST_LOW (int_cst_node
) = low
;
831 TREE_INT_CST_HIGH (int_cst_node
) = hi
;
832 TREE_TYPE (int_cst_node
) = type
;
834 slot
= htab_find_slot (int_cst_hash_table
, int_cst_node
, INSERT
);
838 /* Insert this one into the hash table. */
841 /* Make a new node for next time round. */
842 int_cst_node
= make_node (INTEGER_CST
);
849 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
850 and the rest are zeros. */
853 build_low_bits_mask (tree type
, unsigned bits
)
855 unsigned HOST_WIDE_INT low
;
857 unsigned HOST_WIDE_INT all_ones
= ~(unsigned HOST_WIDE_INT
) 0;
859 gcc_assert (bits
<= TYPE_PRECISION (type
));
861 if (bits
== TYPE_PRECISION (type
)
862 && !TYPE_UNSIGNED (type
))
864 /* Sign extended all-ones mask. */
868 else if (bits
<= HOST_BITS_PER_WIDE_INT
)
870 low
= all_ones
>> (HOST_BITS_PER_WIDE_INT
- bits
);
875 bits
-= HOST_BITS_PER_WIDE_INT
;
877 high
= all_ones
>> (HOST_BITS_PER_WIDE_INT
- bits
);
880 return build_int_cst_wide (type
, low
, high
);
883 /* Checks that X is integer constant that can be expressed in (unsigned)
884 HOST_WIDE_INT without loss of precision. */
887 cst_and_fits_in_hwi (tree x
)
889 if (TREE_CODE (x
) != INTEGER_CST
)
892 if (TYPE_PRECISION (TREE_TYPE (x
)) > HOST_BITS_PER_WIDE_INT
)
895 return (TREE_INT_CST_HIGH (x
) == 0
896 || TREE_INT_CST_HIGH (x
) == -1);
899 /* Return a new VECTOR_CST node whose type is TYPE and whose values
900 are in a list pointed to by VALS. */
903 build_vector (tree type
, tree vals
)
905 tree v
= make_node (VECTOR_CST
);
906 int over1
= 0, over2
= 0;
909 TREE_VECTOR_CST_ELTS (v
) = vals
;
910 TREE_TYPE (v
) = type
;
912 /* Iterate through elements and check for overflow. */
913 for (link
= vals
; link
; link
= TREE_CHAIN (link
))
915 tree value
= TREE_VALUE (link
);
917 over1
|= TREE_OVERFLOW (value
);
918 over2
|= TREE_CONSTANT_OVERFLOW (value
);
921 TREE_OVERFLOW (v
) = over1
;
922 TREE_CONSTANT_OVERFLOW (v
) = over2
;
927 /* Return a new VECTOR_CST node whose type is TYPE and whose values
928 are extracted from V, a vector of CONSTRUCTOR_ELT. */
931 build_vector_from_ctor (tree type
, VEC(constructor_elt
,gc
) *v
)
933 tree list
= NULL_TREE
;
934 unsigned HOST_WIDE_INT idx
;
937 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
938 list
= tree_cons (NULL_TREE
, value
, list
);
939 return build_vector (type
, nreverse (list
));
942 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
943 are in the VEC pointed to by VALS. */
945 build_constructor (tree type
, VEC(constructor_elt
,gc
) *vals
)
947 tree c
= make_node (CONSTRUCTOR
);
948 TREE_TYPE (c
) = type
;
949 CONSTRUCTOR_ELTS (c
) = vals
;
953 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
956 build_constructor_single (tree type
, tree index
, tree value
)
958 VEC(constructor_elt
,gc
) *v
;
959 constructor_elt
*elt
;
961 v
= VEC_alloc (constructor_elt
, gc
, 1);
962 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
966 return build_constructor (type
, v
);
970 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
971 are in a list pointed to by VALS. */
973 build_constructor_from_list (tree type
, tree vals
)
976 VEC(constructor_elt
,gc
) *v
= NULL
;
980 v
= VEC_alloc (constructor_elt
, gc
, list_length (vals
));
981 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
983 constructor_elt
*elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
984 elt
->index
= TREE_PURPOSE (t
);
985 elt
->value
= TREE_VALUE (t
);
989 return build_constructor (type
, v
);
993 /* Return a new REAL_CST node whose type is TYPE and value is D. */
996 build_real (tree type
, REAL_VALUE_TYPE d
)
1002 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1003 Consider doing it via real_convert now. */
1005 v
= make_node (REAL_CST
);
1006 dp
= ggc_alloc (sizeof (REAL_VALUE_TYPE
));
1007 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
1009 TREE_TYPE (v
) = type
;
1010 TREE_REAL_CST_PTR (v
) = dp
;
1011 TREE_OVERFLOW (v
) = TREE_CONSTANT_OVERFLOW (v
) = overflow
;
1015 /* Return a new REAL_CST node whose type is TYPE
1016 and whose value is the integer value of the INTEGER_CST node I. */
1019 real_value_from_int_cst (tree type
, tree i
)
1023 /* Clear all bits of the real value type so that we can later do
1024 bitwise comparisons to see if two values are the same. */
1025 memset (&d
, 0, sizeof d
);
1027 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
,
1028 TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
),
1029 TYPE_UNSIGNED (TREE_TYPE (i
)));
1033 /* Given a tree representing an integer constant I, return a tree
1034 representing the same value as a floating-point constant of type TYPE. */
1037 build_real_from_int_cst (tree type
, tree i
)
1040 int overflow
= TREE_OVERFLOW (i
);
1042 v
= build_real (type
, real_value_from_int_cst (type
, i
));
1044 TREE_OVERFLOW (v
) |= overflow
;
1045 TREE_CONSTANT_OVERFLOW (v
) |= overflow
;
1049 /* Return a newly constructed STRING_CST node whose value is
1050 the LEN characters at STR.
1051 The TREE_TYPE is not initialized. */
1054 build_string (int len
, const char *str
)
1059 length
= len
+ sizeof (struct tree_string
);
1061 #ifdef GATHER_STATISTICS
1062 tree_node_counts
[(int) c_kind
]++;
1063 tree_node_sizes
[(int) c_kind
] += length
;
1066 s
= ggc_alloc_tree (length
);
1068 memset (s
, 0, sizeof (struct tree_common
));
1069 TREE_SET_CODE (s
, STRING_CST
);
1070 TREE_CONSTANT (s
) = 1;
1071 TREE_INVARIANT (s
) = 1;
1072 TREE_STRING_LENGTH (s
) = len
;
1073 memcpy ((char *) TREE_STRING_POINTER (s
), str
, len
);
1074 ((char *) TREE_STRING_POINTER (s
))[len
] = '\0';
1079 /* Return a newly constructed COMPLEX_CST node whose value is
1080 specified by the real and imaginary parts REAL and IMAG.
1081 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1082 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1085 build_complex (tree type
, tree real
, tree imag
)
1087 tree t
= make_node (COMPLEX_CST
);
1089 TREE_REALPART (t
) = real
;
1090 TREE_IMAGPART (t
) = imag
;
1091 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
1092 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1093 TREE_CONSTANT_OVERFLOW (t
)
1094 = TREE_CONSTANT_OVERFLOW (real
) | TREE_CONSTANT_OVERFLOW (imag
);
1098 /* Build a BINFO with LEN language slots. */
1101 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL
)
1104 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
1105 + VEC_embedded_size (tree
, base_binfos
));
1107 #ifdef GATHER_STATISTICS
1108 tree_node_counts
[(int) binfo_kind
]++;
1109 tree_node_sizes
[(int) binfo_kind
] += length
;
1112 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
1114 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
1116 TREE_SET_CODE (t
, TREE_BINFO
);
1118 VEC_embedded_init (tree
, BINFO_BASE_BINFOS (t
), base_binfos
);
1124 /* Build a newly constructed TREE_VEC node of length LEN. */
1127 make_tree_vec_stat (int len MEM_STAT_DECL
)
1130 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
1132 #ifdef GATHER_STATISTICS
1133 tree_node_counts
[(int) vec_kind
]++;
1134 tree_node_sizes
[(int) vec_kind
] += length
;
1137 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
1139 memset (t
, 0, length
);
1141 TREE_SET_CODE (t
, TREE_VEC
);
1142 TREE_VEC_LENGTH (t
) = len
;
1147 /* Return 1 if EXPR is the integer constant zero or a complex constant
1151 integer_zerop (tree expr
)
1155 return ((TREE_CODE (expr
) == INTEGER_CST
1156 && ! TREE_CONSTANT_OVERFLOW (expr
)
1157 && TREE_INT_CST_LOW (expr
) == 0
1158 && TREE_INT_CST_HIGH (expr
) == 0)
1159 || (TREE_CODE (expr
) == COMPLEX_CST
1160 && integer_zerop (TREE_REALPART (expr
))
1161 && integer_zerop (TREE_IMAGPART (expr
))));
1164 /* Return 1 if EXPR is the integer constant one or the corresponding
1165 complex constant. */
1168 integer_onep (tree expr
)
1172 return ((TREE_CODE (expr
) == INTEGER_CST
1173 && ! TREE_CONSTANT_OVERFLOW (expr
)
1174 && TREE_INT_CST_LOW (expr
) == 1
1175 && TREE_INT_CST_HIGH (expr
) == 0)
1176 || (TREE_CODE (expr
) == COMPLEX_CST
1177 && integer_onep (TREE_REALPART (expr
))
1178 && integer_zerop (TREE_IMAGPART (expr
))));
1181 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1182 it contains. Likewise for the corresponding complex constant. */
1185 integer_all_onesp (tree expr
)
1192 if (TREE_CODE (expr
) == COMPLEX_CST
1193 && integer_all_onesp (TREE_REALPART (expr
))
1194 && integer_zerop (TREE_IMAGPART (expr
)))
1197 else if (TREE_CODE (expr
) != INTEGER_CST
1198 || TREE_CONSTANT_OVERFLOW (expr
))
1201 uns
= TYPE_UNSIGNED (TREE_TYPE (expr
));
1203 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1204 && TREE_INT_CST_HIGH (expr
) == -1);
1206 /* Note that using TYPE_PRECISION here is wrong. We care about the
1207 actual bits, not the (arbitrary) range of the type. */
1208 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr
)));
1209 if (prec
>= HOST_BITS_PER_WIDE_INT
)
1211 HOST_WIDE_INT high_value
;
1214 shift_amount
= prec
- HOST_BITS_PER_WIDE_INT
;
1216 /* Can not handle precisions greater than twice the host int size. */
1217 gcc_assert (shift_amount
<= HOST_BITS_PER_WIDE_INT
);
1218 if (shift_amount
== HOST_BITS_PER_WIDE_INT
)
1219 /* Shifting by the host word size is undefined according to the ANSI
1220 standard, so we must handle this as a special case. */
1223 high_value
= ((HOST_WIDE_INT
) 1 << shift_amount
) - 1;
1225 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1226 && TREE_INT_CST_HIGH (expr
) == high_value
);
1229 return TREE_INT_CST_LOW (expr
) == ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
1232 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1236 integer_pow2p (tree expr
)
1239 HOST_WIDE_INT high
, low
;
1243 if (TREE_CODE (expr
) == COMPLEX_CST
1244 && integer_pow2p (TREE_REALPART (expr
))
1245 && integer_zerop (TREE_IMAGPART (expr
)))
1248 if (TREE_CODE (expr
) != INTEGER_CST
|| TREE_CONSTANT_OVERFLOW (expr
))
1251 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1252 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1253 high
= TREE_INT_CST_HIGH (expr
);
1254 low
= TREE_INT_CST_LOW (expr
);
1256 /* First clear all bits that are beyond the type's precision in case
1257 we've been sign extended. */
1259 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1261 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1262 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1266 if (prec
< HOST_BITS_PER_WIDE_INT
)
1267 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1270 if (high
== 0 && low
== 0)
1273 return ((high
== 0 && (low
& (low
- 1)) == 0)
1274 || (low
== 0 && (high
& (high
- 1)) == 0));
1277 /* Return 1 if EXPR is an integer constant other than zero or a
1278 complex constant other than zero. */
1281 integer_nonzerop (tree expr
)
1285 return ((TREE_CODE (expr
) == INTEGER_CST
1286 && ! TREE_CONSTANT_OVERFLOW (expr
)
1287 && (TREE_INT_CST_LOW (expr
) != 0
1288 || TREE_INT_CST_HIGH (expr
) != 0))
1289 || (TREE_CODE (expr
) == COMPLEX_CST
1290 && (integer_nonzerop (TREE_REALPART (expr
))
1291 || integer_nonzerop (TREE_IMAGPART (expr
)))));
1294 /* Return the power of two represented by a tree node known to be a
1298 tree_log2 (tree expr
)
1301 HOST_WIDE_INT high
, low
;
1305 if (TREE_CODE (expr
) == COMPLEX_CST
)
1306 return tree_log2 (TREE_REALPART (expr
));
1308 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1309 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1311 high
= TREE_INT_CST_HIGH (expr
);
1312 low
= TREE_INT_CST_LOW (expr
);
1314 /* First clear all bits that are beyond the type's precision in case
1315 we've been sign extended. */
1317 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1319 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1320 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1324 if (prec
< HOST_BITS_PER_WIDE_INT
)
1325 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1328 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ exact_log2 (high
)
1329 : exact_log2 (low
));
1332 /* Similar, but return the largest integer Y such that 2 ** Y is less
1333 than or equal to EXPR. */
1336 tree_floor_log2 (tree expr
)
1339 HOST_WIDE_INT high
, low
;
1343 if (TREE_CODE (expr
) == COMPLEX_CST
)
1344 return tree_log2 (TREE_REALPART (expr
));
1346 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1347 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1349 high
= TREE_INT_CST_HIGH (expr
);
1350 low
= TREE_INT_CST_LOW (expr
);
1352 /* First clear all bits that are beyond the type's precision in case
1353 we've been sign extended. Ignore if type's precision hasn't been set
1354 since what we are doing is setting it. */
1356 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
|| prec
== 0)
1358 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1359 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1363 if (prec
< HOST_BITS_PER_WIDE_INT
)
1364 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1367 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ floor_log2 (high
)
1368 : floor_log2 (low
));
1371 /* Return 1 if EXPR is the real constant zero. */
1374 real_zerop (tree expr
)
1378 return ((TREE_CODE (expr
) == REAL_CST
1379 && ! TREE_CONSTANT_OVERFLOW (expr
)
1380 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
))
1381 || (TREE_CODE (expr
) == COMPLEX_CST
1382 && real_zerop (TREE_REALPART (expr
))
1383 && real_zerop (TREE_IMAGPART (expr
))));
1386 /* Return 1 if EXPR is the real constant one in real or complex form. */
1389 real_onep (tree expr
)
1393 return ((TREE_CODE (expr
) == REAL_CST
1394 && ! TREE_CONSTANT_OVERFLOW (expr
)
1395 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
))
1396 || (TREE_CODE (expr
) == COMPLEX_CST
1397 && real_onep (TREE_REALPART (expr
))
1398 && real_zerop (TREE_IMAGPART (expr
))));
1401 /* Return 1 if EXPR is the real constant two. */
1404 real_twop (tree expr
)
1408 return ((TREE_CODE (expr
) == REAL_CST
1409 && ! TREE_CONSTANT_OVERFLOW (expr
)
1410 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst2
))
1411 || (TREE_CODE (expr
) == COMPLEX_CST
1412 && real_twop (TREE_REALPART (expr
))
1413 && real_zerop (TREE_IMAGPART (expr
))));
1416 /* Return 1 if EXPR is the real constant minus one. */
1419 real_minus_onep (tree expr
)
1423 return ((TREE_CODE (expr
) == REAL_CST
1424 && ! TREE_CONSTANT_OVERFLOW (expr
)
1425 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconstm1
))
1426 || (TREE_CODE (expr
) == COMPLEX_CST
1427 && real_minus_onep (TREE_REALPART (expr
))
1428 && real_zerop (TREE_IMAGPART (expr
))));
1431 /* Nonzero if EXP is a constant or a cast of a constant. */
1434 really_constant_p (tree exp
)
1436 /* This is not quite the same as STRIP_NOPS. It does more. */
1437 while (TREE_CODE (exp
) == NOP_EXPR
1438 || TREE_CODE (exp
) == CONVERT_EXPR
1439 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
1440 exp
= TREE_OPERAND (exp
, 0);
1441 return TREE_CONSTANT (exp
);
1444 /* Return first list element whose TREE_VALUE is ELEM.
1445 Return 0 if ELEM is not in LIST. */
1448 value_member (tree elem
, tree list
)
1452 if (elem
== TREE_VALUE (list
))
1454 list
= TREE_CHAIN (list
);
1459 /* Return first list element whose TREE_PURPOSE is ELEM.
1460 Return 0 if ELEM is not in LIST. */
1463 purpose_member (tree elem
, tree list
)
1467 if (elem
== TREE_PURPOSE (list
))
1469 list
= TREE_CHAIN (list
);
1474 /* Return nonzero if ELEM is part of the chain CHAIN. */
1477 chain_member (tree elem
, tree chain
)
1483 chain
= TREE_CHAIN (chain
);
1489 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1490 We expect a null pointer to mark the end of the chain.
1491 This is the Lisp primitive `length'. */
1494 list_length (tree t
)
1497 #ifdef ENABLE_TREE_CHECKING
1505 #ifdef ENABLE_TREE_CHECKING
1508 gcc_assert (p
!= q
);
1516 /* Returns the number of FIELD_DECLs in TYPE. */
1519 fields_length (tree type
)
1521 tree t
= TYPE_FIELDS (type
);
1524 for (; t
; t
= TREE_CHAIN (t
))
1525 if (TREE_CODE (t
) == FIELD_DECL
)
1531 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1532 by modifying the last node in chain 1 to point to chain 2.
1533 This is the Lisp primitive `nconc'. */
1536 chainon (tree op1
, tree op2
)
1545 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
1547 TREE_CHAIN (t1
) = op2
;
1549 #ifdef ENABLE_TREE_CHECKING
1552 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
1553 gcc_assert (t2
!= t1
);
1560 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1563 tree_last (tree chain
)
1567 while ((next
= TREE_CHAIN (chain
)))
1572 /* Reverse the order of elements in the chain T,
1573 and return the new head of the chain (old last element). */
1578 tree prev
= 0, decl
, next
;
1579 for (decl
= t
; decl
; decl
= next
)
1581 next
= TREE_CHAIN (decl
);
1582 TREE_CHAIN (decl
) = prev
;
1588 /* Return a newly created TREE_LIST node whose
1589 purpose and value fields are PARM and VALUE. */
1592 build_tree_list_stat (tree parm
, tree value MEM_STAT_DECL
)
1594 tree t
= make_node_stat (TREE_LIST PASS_MEM_STAT
);
1595 TREE_PURPOSE (t
) = parm
;
1596 TREE_VALUE (t
) = value
;
1600 /* Return a newly created TREE_LIST node whose
1601 purpose and value fields are PURPOSE and VALUE
1602 and whose TREE_CHAIN is CHAIN. */
1605 tree_cons_stat (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
1609 node
= ggc_alloc_zone_pass_stat (sizeof (struct tree_list
), &tree_zone
);
1611 memset (node
, 0, sizeof (struct tree_common
));
1613 #ifdef GATHER_STATISTICS
1614 tree_node_counts
[(int) x_kind
]++;
1615 tree_node_sizes
[(int) x_kind
] += sizeof (struct tree_list
);
1618 TREE_SET_CODE (node
, TREE_LIST
);
1619 TREE_CHAIN (node
) = chain
;
1620 TREE_PURPOSE (node
) = purpose
;
1621 TREE_VALUE (node
) = value
;
1626 /* Return the size nominally occupied by an object of type TYPE
1627 when it resides in memory. The value is measured in units of bytes,
1628 and its data type is that normally used for type sizes
1629 (which is the first type created by make_signed_type or
1630 make_unsigned_type). */
1633 size_in_bytes (tree type
)
1637 if (type
== error_mark_node
)
1638 return integer_zero_node
;
1640 type
= TYPE_MAIN_VARIANT (type
);
1641 t
= TYPE_SIZE_UNIT (type
);
1645 lang_hooks
.types
.incomplete_type_error (NULL_TREE
, type
);
1646 return size_zero_node
;
1649 if (TREE_CODE (t
) == INTEGER_CST
)
1650 t
= force_fit_type (t
, 0, false, false);
1655 /* Return the size of TYPE (in bytes) as a wide integer
1656 or return -1 if the size can vary or is larger than an integer. */
1659 int_size_in_bytes (tree type
)
1663 if (type
== error_mark_node
)
1666 type
= TYPE_MAIN_VARIANT (type
);
1667 t
= TYPE_SIZE_UNIT (type
);
1669 || TREE_CODE (t
) != INTEGER_CST
1670 || TREE_OVERFLOW (t
)
1671 || TREE_INT_CST_HIGH (t
) != 0
1672 /* If the result would appear negative, it's too big to represent. */
1673 || (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0)
1676 return TREE_INT_CST_LOW (t
);
1679 /* Return the bit position of FIELD, in bits from the start of the record.
1680 This is a tree of type bitsizetype. */
1683 bit_position (tree field
)
1685 return bit_from_pos (DECL_FIELD_OFFSET (field
),
1686 DECL_FIELD_BIT_OFFSET (field
));
1689 /* Likewise, but return as an integer. It must be representable in
1690 that way (since it could be a signed value, we don't have the
1691 option of returning -1 like int_size_in_byte can. */
1694 int_bit_position (tree field
)
1696 return tree_low_cst (bit_position (field
), 0);
1699 /* Return the byte position of FIELD, in bytes from the start of the record.
1700 This is a tree of type sizetype. */
1703 byte_position (tree field
)
1705 return byte_from_pos (DECL_FIELD_OFFSET (field
),
1706 DECL_FIELD_BIT_OFFSET (field
));
1709 /* Likewise, but return as an integer. It must be representable in
1710 that way (since it could be a signed value, we don't have the
1711 option of returning -1 like int_size_in_byte can. */
1714 int_byte_position (tree field
)
1716 return tree_low_cst (byte_position (field
), 0);
1719 /* Return the strictest alignment, in bits, that T is known to have. */
1724 unsigned int align0
, align1
;
1726 switch (TREE_CODE (t
))
1728 case NOP_EXPR
: case CONVERT_EXPR
: case NON_LVALUE_EXPR
:
1729 /* If we have conversions, we know that the alignment of the
1730 object must meet each of the alignments of the types. */
1731 align0
= expr_align (TREE_OPERAND (t
, 0));
1732 align1
= TYPE_ALIGN (TREE_TYPE (t
));
1733 return MAX (align0
, align1
);
1735 case SAVE_EXPR
: case COMPOUND_EXPR
: case MODIFY_EXPR
:
1736 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
1737 case CLEANUP_POINT_EXPR
:
1738 /* These don't change the alignment of an object. */
1739 return expr_align (TREE_OPERAND (t
, 0));
1742 /* The best we can do is say that the alignment is the least aligned
1744 align0
= expr_align (TREE_OPERAND (t
, 1));
1745 align1
= expr_align (TREE_OPERAND (t
, 2));
1746 return MIN (align0
, align1
);
1748 case LABEL_DECL
: case CONST_DECL
:
1749 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
1750 if (DECL_ALIGN (t
) != 0)
1751 return DECL_ALIGN (t
);
1755 return FUNCTION_BOUNDARY
;
1761 /* Otherwise take the alignment from that of the type. */
1762 return TYPE_ALIGN (TREE_TYPE (t
));
1765 /* Return, as a tree node, the number of elements for TYPE (which is an
1766 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1769 array_type_nelts (tree type
)
1771 tree index_type
, min
, max
;
1773 /* If they did it with unspecified bounds, then we should have already
1774 given an error about it before we got here. */
1775 if (! TYPE_DOMAIN (type
))
1776 return error_mark_node
;
1778 index_type
= TYPE_DOMAIN (type
);
1779 min
= TYPE_MIN_VALUE (index_type
);
1780 max
= TYPE_MAX_VALUE (index_type
);
1782 return (integer_zerop (min
)
1784 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
1787 /* If arg is static -- a reference to an object in static storage -- then
1788 return the object. This is not the same as the C meaning of `static'.
1789 If arg isn't static, return NULL. */
1794 switch (TREE_CODE (arg
))
1797 /* Nested functions are static, even though taking their address will
1798 involve a trampoline as we unnest the nested function and create
1799 the trampoline on the tree level. */
1803 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
1804 && ! DECL_THREAD_LOCAL_P (arg
)
1805 && ! DECL_NON_ADDR_CONST_P (arg
)
1809 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
1813 return TREE_STATIC (arg
) ? arg
: NULL
;
1820 /* If the thing being referenced is not a field, then it is
1821 something language specific. */
1822 if (TREE_CODE (TREE_OPERAND (arg
, 1)) != FIELD_DECL
)
1823 return (*lang_hooks
.staticp
) (arg
);
1825 /* If we are referencing a bitfield, we can't evaluate an
1826 ADDR_EXPR at compile time and so it isn't a constant. */
1827 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
1830 return staticp (TREE_OPERAND (arg
, 0));
1835 case MISALIGNED_INDIRECT_REF
:
1836 case ALIGN_INDIRECT_REF
:
1838 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
1841 case ARRAY_RANGE_REF
:
1842 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
1843 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
1844 return staticp (TREE_OPERAND (arg
, 0));
1849 if ((unsigned int) TREE_CODE (arg
)
1850 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
1851 return lang_hooks
.staticp (arg
);
1857 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
1858 Do this to any expression which may be used in more than one place,
1859 but must be evaluated only once.
1861 Normally, expand_expr would reevaluate the expression each time.
1862 Calling save_expr produces something that is evaluated and recorded
1863 the first time expand_expr is called on it. Subsequent calls to
1864 expand_expr just reuse the recorded value.
1866 The call to expand_expr that generates code that actually computes
1867 the value is the first call *at compile time*. Subsequent calls
1868 *at compile time* generate code to use the saved value.
1869 This produces correct result provided that *at run time* control
1870 always flows through the insns made by the first expand_expr
1871 before reaching the other places where the save_expr was evaluated.
1872 You, the caller of save_expr, must make sure this is so.
1874 Constants, and certain read-only nodes, are returned with no
1875 SAVE_EXPR because that is safe. Expressions containing placeholders
1876 are not touched; see tree.def for an explanation of what these
1880 save_expr (tree expr
)
1882 tree t
= fold (expr
);
1885 /* If the tree evaluates to a constant, then we don't want to hide that
1886 fact (i.e. this allows further folding, and direct checks for constants).
1887 However, a read-only object that has side effects cannot be bypassed.
1888 Since it is no problem to reevaluate literals, we just return the
1890 inner
= skip_simple_arithmetic (t
);
1892 if (TREE_INVARIANT (inner
)
1893 || (TREE_READONLY (inner
) && ! TREE_SIDE_EFFECTS (inner
))
1894 || TREE_CODE (inner
) == SAVE_EXPR
1895 || TREE_CODE (inner
) == ERROR_MARK
)
1898 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
1899 it means that the size or offset of some field of an object depends on
1900 the value within another field.
1902 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
1903 and some variable since it would then need to be both evaluated once and
1904 evaluated more than once. Front-ends must assure this case cannot
1905 happen by surrounding any such subexpressions in their own SAVE_EXPR
1906 and forcing evaluation at the proper time. */
1907 if (contains_placeholder_p (inner
))
1910 t
= build1 (SAVE_EXPR
, TREE_TYPE (expr
), t
);
1912 /* This expression might be placed ahead of a jump to ensure that the
1913 value was computed on both sides of the jump. So make sure it isn't
1914 eliminated as dead. */
1915 TREE_SIDE_EFFECTS (t
) = 1;
1916 TREE_INVARIANT (t
) = 1;
1920 /* Look inside EXPR and into any simple arithmetic operations. Return
1921 the innermost non-arithmetic node. */
1924 skip_simple_arithmetic (tree expr
)
1928 /* We don't care about whether this can be used as an lvalue in this
1930 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
1931 expr
= TREE_OPERAND (expr
, 0);
1933 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
1934 a constant, it will be more efficient to not make another SAVE_EXPR since
1935 it will allow better simplification and GCSE will be able to merge the
1936 computations if they actually occur. */
1940 if (UNARY_CLASS_P (inner
))
1941 inner
= TREE_OPERAND (inner
, 0);
1942 else if (BINARY_CLASS_P (inner
))
1944 if (TREE_INVARIANT (TREE_OPERAND (inner
, 1)))
1945 inner
= TREE_OPERAND (inner
, 0);
1946 else if (TREE_INVARIANT (TREE_OPERAND (inner
, 0)))
1947 inner
= TREE_OPERAND (inner
, 1);
1958 /* Return which tree structure is used by T. */
1960 enum tree_node_structure_enum
1961 tree_node_structure (tree t
)
1963 enum tree_code code
= TREE_CODE (t
);
1965 switch (TREE_CODE_CLASS (code
))
1967 case tcc_declaration
:
1972 return TS_FIELD_DECL
;
1974 return TS_PARM_DECL
;
1978 return TS_LABEL_DECL
;
1980 return TS_RESULT_DECL
;
1982 return TS_CONST_DECL
;
1984 return TS_TYPE_DECL
;
1986 return TS_FUNCTION_DECL
;
1987 case TYPE_MEMORY_TAG
:
1988 case NAME_MEMORY_TAG
:
1989 case STRUCT_FIELD_TAG
:
1990 return TS_MEMORY_TAG
;
1992 return TS_DECL_NON_COMMON
;
1998 case tcc_comparison
:
2001 case tcc_expression
:
2004 default: /* tcc_constant and tcc_exceptional */
2009 /* tcc_constant cases. */
2010 case INTEGER_CST
: return TS_INT_CST
;
2011 case REAL_CST
: return TS_REAL_CST
;
2012 case COMPLEX_CST
: return TS_COMPLEX
;
2013 case VECTOR_CST
: return TS_VECTOR
;
2014 case STRING_CST
: return TS_STRING
;
2015 /* tcc_exceptional cases. */
2016 case ERROR_MARK
: return TS_COMMON
;
2017 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
2018 case TREE_LIST
: return TS_LIST
;
2019 case TREE_VEC
: return TS_VEC
;
2020 case PHI_NODE
: return TS_PHI_NODE
;
2021 case SSA_NAME
: return TS_SSA_NAME
;
2022 case PLACEHOLDER_EXPR
: return TS_COMMON
;
2023 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
2024 case BLOCK
: return TS_BLOCK
;
2025 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
2026 case TREE_BINFO
: return TS_BINFO
;
2027 case VALUE_HANDLE
: return TS_VALUE_HANDLE
;
2034 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2035 or offset that depends on a field within a record. */
2038 contains_placeholder_p (tree exp
)
2040 enum tree_code code
;
2045 code
= TREE_CODE (exp
);
2046 if (code
== PLACEHOLDER_EXPR
)
2049 switch (TREE_CODE_CLASS (code
))
2052 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2053 position computations since they will be converted into a
2054 WITH_RECORD_EXPR involving the reference, which will assume
2055 here will be valid. */
2056 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2058 case tcc_exceptional
:
2059 if (code
== TREE_LIST
)
2060 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
2061 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
2066 case tcc_comparison
:
2067 case tcc_expression
:
2071 /* Ignoring the first operand isn't quite right, but works best. */
2072 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
2075 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2076 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
2077 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
2080 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
2086 switch (TREE_CODE_LENGTH (code
))
2089 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2091 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2092 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
2103 /* Return true if any part of the computation of TYPE involves a
2104 PLACEHOLDER_EXPR. This includes size, bounds, qualifiers
2105 (for QUAL_UNION_TYPE) and field positions. */
2108 type_contains_placeholder_1 (tree type
)
2110 /* If the size contains a placeholder or the parent type (component type in
2111 the case of arrays) type involves a placeholder, this type does. */
2112 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
2113 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
2114 || (TREE_TYPE (type
) != 0
2115 && type_contains_placeholder_p (TREE_TYPE (type
))))
2118 /* Now do type-specific checks. Note that the last part of the check above
2119 greatly limits what we have to do below. */
2120 switch (TREE_CODE (type
))
2129 case REFERENCE_TYPE
:
2137 /* Here we just check the bounds. */
2138 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
2139 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
2142 /* We're already checked the component type (TREE_TYPE), so just check
2144 return type_contains_placeholder_p (TYPE_DOMAIN (type
));
2148 case QUAL_UNION_TYPE
:
2152 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2153 if (TREE_CODE (field
) == FIELD_DECL
2154 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
2155 || (TREE_CODE (type
) == QUAL_UNION_TYPE
2156 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
2157 || type_contains_placeholder_p (TREE_TYPE (field
))))
2169 type_contains_placeholder_p (tree type
)
2173 /* If the contains_placeholder_bits field has been initialized,
2174 then we know the answer. */
2175 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
2176 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
2178 /* Indicate that we've seen this type node, and the answer is false.
2179 This is what we want to return if we run into recursion via fields. */
2180 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
2182 /* Compute the real value. */
2183 result
= type_contains_placeholder_1 (type
);
2185 /* Store the real value. */
2186 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
2191 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2192 return a tree with all occurrences of references to F in a
2193 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2194 contains only arithmetic expressions or a CALL_EXPR with a
2195 PLACEHOLDER_EXPR occurring only in its arglist. */
2198 substitute_in_expr (tree exp
, tree f
, tree r
)
2200 enum tree_code code
= TREE_CODE (exp
);
2201 tree op0
, op1
, op2
, op3
;
2205 /* We handle TREE_LIST and COMPONENT_REF separately. */
2206 if (code
== TREE_LIST
)
2208 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
2209 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
2210 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
2213 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
2215 else if (code
== COMPONENT_REF
)
2217 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2218 and it is the right field, replace it with R. */
2219 for (inner
= TREE_OPERAND (exp
, 0);
2220 REFERENCE_CLASS_P (inner
);
2221 inner
= TREE_OPERAND (inner
, 0))
2223 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
2224 && TREE_OPERAND (exp
, 1) == f
)
2227 /* If this expression hasn't been completed let, leave it alone. */
2228 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& TREE_TYPE (inner
) == 0)
2231 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2232 if (op0
== TREE_OPERAND (exp
, 0))
2235 new = fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
),
2236 op0
, TREE_OPERAND (exp
, 1), NULL_TREE
);
2239 switch (TREE_CODE_CLASS (code
))
2242 case tcc_declaration
:
2245 case tcc_exceptional
:
2248 case tcc_comparison
:
2249 case tcc_expression
:
2251 switch (TREE_CODE_LENGTH (code
))
2257 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2258 if (op0
== TREE_OPERAND (exp
, 0))
2261 new = fold_build1 (code
, TREE_TYPE (exp
), op0
);
2265 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2266 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2268 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
2271 new = fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
2275 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2276 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2277 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
2279 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2280 && op2
== TREE_OPERAND (exp
, 2))
2283 new = fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
2287 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2288 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2289 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
2290 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
2292 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2293 && op2
== TREE_OPERAND (exp
, 2)
2294 && op3
== TREE_OPERAND (exp
, 3))
2297 new = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
2309 TREE_READONLY (new) = TREE_READONLY (exp
);
2313 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
2314 for it within OBJ, a tree that is an object or a chain of references. */
2317 substitute_placeholder_in_expr (tree exp
, tree obj
)
2319 enum tree_code code
= TREE_CODE (exp
);
2320 tree op0
, op1
, op2
, op3
;
2322 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
2323 in the chain of OBJ. */
2324 if (code
== PLACEHOLDER_EXPR
)
2326 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
2329 for (elt
= obj
; elt
!= 0;
2330 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
2331 || TREE_CODE (elt
) == COND_EXPR
)
2332 ? TREE_OPERAND (elt
, 1)
2333 : (REFERENCE_CLASS_P (elt
)
2334 || UNARY_CLASS_P (elt
)
2335 || BINARY_CLASS_P (elt
)
2336 || EXPRESSION_CLASS_P (elt
))
2337 ? TREE_OPERAND (elt
, 0) : 0))
2338 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
2341 for (elt
= obj
; elt
!= 0;
2342 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
2343 || TREE_CODE (elt
) == COND_EXPR
)
2344 ? TREE_OPERAND (elt
, 1)
2345 : (REFERENCE_CLASS_P (elt
)
2346 || UNARY_CLASS_P (elt
)
2347 || BINARY_CLASS_P (elt
)
2348 || EXPRESSION_CLASS_P (elt
))
2349 ? TREE_OPERAND (elt
, 0) : 0))
2350 if (POINTER_TYPE_P (TREE_TYPE (elt
))
2351 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
2353 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
2355 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2356 survives until RTL generation, there will be an error. */
2360 /* TREE_LIST is special because we need to look at TREE_VALUE
2361 and TREE_CHAIN, not TREE_OPERANDS. */
2362 else if (code
== TREE_LIST
)
2364 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
2365 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
2366 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
2369 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
2372 switch (TREE_CODE_CLASS (code
))
2375 case tcc_declaration
:
2378 case tcc_exceptional
:
2381 case tcc_comparison
:
2382 case tcc_expression
:
2385 switch (TREE_CODE_LENGTH (code
))
2391 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2392 if (op0
== TREE_OPERAND (exp
, 0))
2395 return fold_build1 (code
, TREE_TYPE (exp
), op0
);
2398 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2399 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2401 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
2404 return fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
2407 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2408 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2409 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
2411 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2412 && op2
== TREE_OPERAND (exp
, 2))
2415 return fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
2418 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2419 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2420 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
2421 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
2423 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2424 && op2
== TREE_OPERAND (exp
, 2)
2425 && op3
== TREE_OPERAND (exp
, 3))
2428 return fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
2440 /* Stabilize a reference so that we can use it any number of times
2441 without causing its operands to be evaluated more than once.
2442 Returns the stabilized reference. This works by means of save_expr,
2443 so see the caveats in the comments about save_expr.
2445 Also allows conversion expressions whose operands are references.
2446 Any other kind of expression is returned unchanged. */
2449 stabilize_reference (tree ref
)
2452 enum tree_code code
= TREE_CODE (ref
);
2459 /* No action is needed in this case. */
2465 case FIX_TRUNC_EXPR
:
2466 case FIX_FLOOR_EXPR
:
2467 case FIX_ROUND_EXPR
:
2469 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
2473 result
= build_nt (INDIRECT_REF
,
2474 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
2478 result
= build_nt (COMPONENT_REF
,
2479 stabilize_reference (TREE_OPERAND (ref
, 0)),
2480 TREE_OPERAND (ref
, 1), NULL_TREE
);
2484 result
= build_nt (BIT_FIELD_REF
,
2485 stabilize_reference (TREE_OPERAND (ref
, 0)),
2486 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2487 stabilize_reference_1 (TREE_OPERAND (ref
, 2)));
2491 result
= build_nt (ARRAY_REF
,
2492 stabilize_reference (TREE_OPERAND (ref
, 0)),
2493 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2494 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
2497 case ARRAY_RANGE_REF
:
2498 result
= build_nt (ARRAY_RANGE_REF
,
2499 stabilize_reference (TREE_OPERAND (ref
, 0)),
2500 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2501 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
2505 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2506 it wouldn't be ignored. This matters when dealing with
2508 return stabilize_reference_1 (ref
);
2510 /* If arg isn't a kind of lvalue we recognize, make no change.
2511 Caller should recognize the error for an invalid lvalue. */
2516 return error_mark_node
;
2519 TREE_TYPE (result
) = TREE_TYPE (ref
);
2520 TREE_READONLY (result
) = TREE_READONLY (ref
);
2521 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
2522 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
2527 /* Subroutine of stabilize_reference; this is called for subtrees of
2528 references. Any expression with side-effects must be put in a SAVE_EXPR
2529 to ensure that it is only evaluated once.
2531 We don't put SAVE_EXPR nodes around everything, because assigning very
2532 simple expressions to temporaries causes us to miss good opportunities
2533 for optimizations. Among other things, the opportunity to fold in the
2534 addition of a constant into an addressing mode often gets lost, e.g.
2535 "y[i+1] += x;". In general, we take the approach that we should not make
2536 an assignment unless we are forced into it - i.e., that any non-side effect
2537 operator should be allowed, and that cse should take care of coalescing
2538 multiple utterances of the same expression should that prove fruitful. */
2541 stabilize_reference_1 (tree e
)
2544 enum tree_code code
= TREE_CODE (e
);
2546 /* We cannot ignore const expressions because it might be a reference
2547 to a const array but whose index contains side-effects. But we can
2548 ignore things that are actual constant or that already have been
2549 handled by this function. */
2551 if (TREE_INVARIANT (e
))
2554 switch (TREE_CODE_CLASS (code
))
2556 case tcc_exceptional
:
2558 case tcc_declaration
:
2559 case tcc_comparison
:
2561 case tcc_expression
:
2563 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2564 so that it will only be evaluated once. */
2565 /* The reference (r) and comparison (<) classes could be handled as
2566 below, but it is generally faster to only evaluate them once. */
2567 if (TREE_SIDE_EFFECTS (e
))
2568 return save_expr (e
);
2572 /* Constants need no processing. In fact, we should never reach
2577 /* Division is slow and tends to be compiled with jumps,
2578 especially the division by powers of 2 that is often
2579 found inside of an array reference. So do it just once. */
2580 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
2581 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
2582 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
2583 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
2584 return save_expr (e
);
2585 /* Recursively stabilize each operand. */
2586 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
2587 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
2591 /* Recursively stabilize each operand. */
2592 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
2599 TREE_TYPE (result
) = TREE_TYPE (e
);
2600 TREE_READONLY (result
) = TREE_READONLY (e
);
2601 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
2602 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
2603 TREE_INVARIANT (result
) = 1;
2608 /* Low-level constructors for expressions. */
2610 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
2611 TREE_INVARIANT, and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
2614 recompute_tree_invarant_for_addr_expr (tree t
)
2617 bool tc
= true, ti
= true, se
= false;
2619 /* We started out assuming this address is both invariant and constant, but
2620 does not have side effects. Now go down any handled components and see if
2621 any of them involve offsets that are either non-constant or non-invariant.
2622 Also check for side-effects.
2624 ??? Note that this code makes no attempt to deal with the case where
2625 taking the address of something causes a copy due to misalignment. */
2627 #define UPDATE_TITCSE(NODE) \
2628 do { tree _node = (NODE); \
2629 if (_node && !TREE_INVARIANT (_node)) ti = false; \
2630 if (_node && !TREE_CONSTANT (_node)) tc = false; \
2631 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
2633 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
2634 node
= TREE_OPERAND (node
, 0))
2636 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
2637 array reference (probably made temporarily by the G++ front end),
2638 so ignore all the operands. */
2639 if ((TREE_CODE (node
) == ARRAY_REF
2640 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
2641 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
2643 UPDATE_TITCSE (TREE_OPERAND (node
, 1));
2644 if (TREE_OPERAND (node
, 2))
2645 UPDATE_TITCSE (TREE_OPERAND (node
, 2));
2646 if (TREE_OPERAND (node
, 3))
2647 UPDATE_TITCSE (TREE_OPERAND (node
, 3));
2649 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
2650 FIELD_DECL, apparently. The G++ front end can put something else
2651 there, at least temporarily. */
2652 else if (TREE_CODE (node
) == COMPONENT_REF
2653 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
2655 if (TREE_OPERAND (node
, 2))
2656 UPDATE_TITCSE (TREE_OPERAND (node
, 2));
2658 else if (TREE_CODE (node
) == BIT_FIELD_REF
)
2659 UPDATE_TITCSE (TREE_OPERAND (node
, 2));
2662 node
= lang_hooks
.expr_to_decl (node
, &tc
, &ti
, &se
);
2664 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
2665 the address, since &(*a)->b is a form of addition. If it's a decl, it's
2666 invariant and constant if the decl is static. It's also invariant if it's
2667 a decl in the current function. Taking the address of a volatile variable
2668 is not volatile. If it's a constant, the address is both invariant and
2669 constant. Otherwise it's neither. */
2670 if (TREE_CODE (node
) == INDIRECT_REF
)
2671 UPDATE_TITCSE (TREE_OPERAND (node
, 0));
2672 else if (DECL_P (node
))
2676 else if (decl_function_context (node
) == current_function_decl
2677 /* Addresses of thread-local variables are invariant. */
2678 || (TREE_CODE (node
) == VAR_DECL
2679 && DECL_THREAD_LOCAL_P (node
)))
2684 else if (CONSTANT_CLASS_P (node
))
2689 se
|= TREE_SIDE_EFFECTS (node
);
2692 TREE_CONSTANT (t
) = tc
;
2693 TREE_INVARIANT (t
) = ti
;
2694 TREE_SIDE_EFFECTS (t
) = se
;
2695 #undef UPDATE_TITCSE
2698 /* Build an expression of code CODE, data type TYPE, and operands as
2699 specified. Expressions and reference nodes can be created this way.
2700 Constants, decls, types and misc nodes cannot be.
2702 We define 5 non-variadic functions, from 0 to 4 arguments. This is
2703 enough for all extant tree codes. These functions can be called
2704 directly (preferably!), but can also be obtained via GCC preprocessor
2705 magic within the build macro. */
2708 build0_stat (enum tree_code code
, tree tt MEM_STAT_DECL
)
2712 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
2714 t
= make_node_stat (code PASS_MEM_STAT
);
2721 build1_stat (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
2723 int length
= sizeof (struct tree_exp
);
2724 #ifdef GATHER_STATISTICS
2725 tree_node_kind kind
;
2729 #ifdef GATHER_STATISTICS
2730 switch (TREE_CODE_CLASS (code
))
2732 case tcc_statement
: /* an expression with side effects */
2735 case tcc_reference
: /* a reference */
2743 tree_node_counts
[(int) kind
]++;
2744 tree_node_sizes
[(int) kind
] += length
;
2747 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
2749 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
2751 memset (t
, 0, sizeof (struct tree_common
));
2753 TREE_SET_CODE (t
, code
);
2755 TREE_TYPE (t
) = type
;
2756 #ifdef USE_MAPPED_LOCATION
2757 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
2759 SET_EXPR_LOCUS (t
, NULL
);
2761 TREE_COMPLEXITY (t
) = 0;
2762 TREE_OPERAND (t
, 0) = node
;
2763 TREE_BLOCK (t
) = NULL_TREE
;
2764 if (node
&& !TYPE_P (node
))
2766 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
2767 TREE_READONLY (t
) = TREE_READONLY (node
);
2770 if (TREE_CODE_CLASS (code
) == tcc_statement
)
2771 TREE_SIDE_EFFECTS (t
) = 1;
2775 /* All of these have side-effects, no matter what their
2777 TREE_SIDE_EFFECTS (t
) = 1;
2778 TREE_READONLY (t
) = 0;
2781 case MISALIGNED_INDIRECT_REF
:
2782 case ALIGN_INDIRECT_REF
:
2784 /* Whether a dereference is readonly has nothing to do with whether
2785 its operand is readonly. */
2786 TREE_READONLY (t
) = 0;
2791 recompute_tree_invarant_for_addr_expr (t
);
2795 if (TREE_CODE_CLASS (code
) == tcc_unary
2796 && node
&& !TYPE_P (node
)
2797 && TREE_CONSTANT (node
))
2798 TREE_CONSTANT (t
) = 1;
2799 if (TREE_CODE_CLASS (code
) == tcc_unary
2800 && node
&& TREE_INVARIANT (node
))
2801 TREE_INVARIANT (t
) = 1;
2802 if (TREE_CODE_CLASS (code
) == tcc_reference
2803 && node
&& TREE_THIS_VOLATILE (node
))
2804 TREE_THIS_VOLATILE (t
) = 1;
2811 #define PROCESS_ARG(N) \
2813 TREE_OPERAND (t, N) = arg##N; \
2814 if (arg##N &&!TYPE_P (arg##N)) \
2816 if (TREE_SIDE_EFFECTS (arg##N)) \
2818 if (!TREE_READONLY (arg##N)) \
2820 if (!TREE_CONSTANT (arg##N)) \
2822 if (!TREE_INVARIANT (arg##N)) \
2828 build2_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
2830 bool constant
, read_only
, side_effects
, invariant
;
2833 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
2835 t
= make_node_stat (code PASS_MEM_STAT
);
2838 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
2839 result based on those same flags for the arguments. But if the
2840 arguments aren't really even `tree' expressions, we shouldn't be trying
2843 /* Expressions without side effects may be constant if their
2844 arguments are as well. */
2845 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
2846 || TREE_CODE_CLASS (code
) == tcc_binary
);
2848 side_effects
= TREE_SIDE_EFFECTS (t
);
2849 invariant
= constant
;
2854 TREE_READONLY (t
) = read_only
;
2855 TREE_CONSTANT (t
) = constant
;
2856 TREE_INVARIANT (t
) = invariant
;
2857 TREE_SIDE_EFFECTS (t
) = side_effects
;
2858 TREE_THIS_VOLATILE (t
)
2859 = (TREE_CODE_CLASS (code
) == tcc_reference
2860 && arg0
&& TREE_THIS_VOLATILE (arg0
));
2866 build3_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
2867 tree arg2 MEM_STAT_DECL
)
2869 bool constant
, read_only
, side_effects
, invariant
;
2872 gcc_assert (TREE_CODE_LENGTH (code
) == 3);
2874 t
= make_node_stat (code PASS_MEM_STAT
);
2877 side_effects
= TREE_SIDE_EFFECTS (t
);
2883 if (code
== CALL_EXPR
&& !side_effects
)
2888 /* Calls have side-effects, except those to const or
2890 i
= call_expr_flags (t
);
2891 if (!(i
& (ECF_CONST
| ECF_PURE
)))
2894 /* And even those have side-effects if their arguments do. */
2895 else for (node
= arg1
; node
; node
= TREE_CHAIN (node
))
2896 if (TREE_SIDE_EFFECTS (TREE_VALUE (node
)))
2903 TREE_SIDE_EFFECTS (t
) = side_effects
;
2904 TREE_THIS_VOLATILE (t
)
2905 = (TREE_CODE_CLASS (code
) == tcc_reference
2906 && arg0
&& TREE_THIS_VOLATILE (arg0
));
2912 build4_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
2913 tree arg2
, tree arg3 MEM_STAT_DECL
)
2915 bool constant
, read_only
, side_effects
, invariant
;
2918 gcc_assert (TREE_CODE_LENGTH (code
) == 4);
2920 t
= make_node_stat (code PASS_MEM_STAT
);
2923 side_effects
= TREE_SIDE_EFFECTS (t
);
2930 TREE_SIDE_EFFECTS (t
) = side_effects
;
2931 TREE_THIS_VOLATILE (t
)
2932 = (TREE_CODE_CLASS (code
) == tcc_reference
2933 && arg0
&& TREE_THIS_VOLATILE (arg0
));
2939 build7_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
2940 tree arg2
, tree arg3
, tree arg4
, tree arg5
,
2941 tree arg6 MEM_STAT_DECL
)
2943 bool constant
, read_only
, side_effects
, invariant
;
2946 gcc_assert (code
== TARGET_MEM_REF
);
2948 t
= make_node_stat (code PASS_MEM_STAT
);
2951 side_effects
= TREE_SIDE_EFFECTS (t
);
2961 TREE_SIDE_EFFECTS (t
) = side_effects
;
2962 TREE_THIS_VOLATILE (t
) = 0;
2967 /* Backup definition for non-gcc build compilers. */
2970 (build
) (enum tree_code code
, tree tt
, ...)
2972 tree t
, arg0
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
;
2973 int length
= TREE_CODE_LENGTH (code
);
2980 t
= build0 (code
, tt
);
2983 arg0
= va_arg (p
, tree
);
2984 t
= build1 (code
, tt
, arg0
);
2987 arg0
= va_arg (p
, tree
);
2988 arg1
= va_arg (p
, tree
);
2989 t
= build2 (code
, tt
, arg0
, arg1
);
2992 arg0
= va_arg (p
, tree
);
2993 arg1
= va_arg (p
, tree
);
2994 arg2
= va_arg (p
, tree
);
2995 t
= build3 (code
, tt
, arg0
, arg1
, arg2
);
2998 arg0
= va_arg (p
, tree
);
2999 arg1
= va_arg (p
, tree
);
3000 arg2
= va_arg (p
, tree
);
3001 arg3
= va_arg (p
, tree
);
3002 t
= build4 (code
, tt
, arg0
, arg1
, arg2
, arg3
);
3005 arg0
= va_arg (p
, tree
);
3006 arg1
= va_arg (p
, tree
);
3007 arg2
= va_arg (p
, tree
);
3008 arg3
= va_arg (p
, tree
);
3009 arg4
= va_arg (p
, tree
);
3010 arg5
= va_arg (p
, tree
);
3011 arg6
= va_arg (p
, tree
);
3012 t
= build7 (code
, tt
, arg0
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
3022 /* Similar except don't specify the TREE_TYPE
3023 and leave the TREE_SIDE_EFFECTS as 0.
3024 It is permissible for arguments to be null,
3025 or even garbage if their values do not matter. */
3028 build_nt (enum tree_code code
, ...)
3037 t
= make_node (code
);
3038 length
= TREE_CODE_LENGTH (code
);
3040 for (i
= 0; i
< length
; i
++)
3041 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
3047 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
3048 We do NOT enter this node in any sort of symbol table.
3050 layout_decl is used to set up the decl's storage layout.
3051 Other slots are initialized to 0 or null pointers. */
3054 build_decl_stat (enum tree_code code
, tree name
, tree type MEM_STAT_DECL
)
3058 t
= make_node_stat (code PASS_MEM_STAT
);
3060 /* if (type == error_mark_node)
3061 type = integer_type_node; */
3062 /* That is not done, deliberately, so that having error_mark_node
3063 as the type can suppress useless errors in the use of this variable. */
3065 DECL_NAME (t
) = name
;
3066 TREE_TYPE (t
) = type
;
3068 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
3070 else if (code
== FUNCTION_DECL
)
3071 DECL_MODE (t
) = FUNCTION_MODE
;
3073 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
3075 /* Set default visibility to whatever the user supplied with
3076 visibility_specified depending on #pragma GCC visibility. */
3077 DECL_VISIBILITY (t
) = default_visibility
;
3078 DECL_VISIBILITY_SPECIFIED (t
) = visibility_options
.inpragma
;
3084 /* Builds and returns function declaration with NAME and TYPE. */
3087 build_fn_decl (const char *name
, tree type
)
3089 tree id
= get_identifier (name
);
3090 tree decl
= build_decl (FUNCTION_DECL
, id
, type
);
3092 DECL_EXTERNAL (decl
) = 1;
3093 TREE_PUBLIC (decl
) = 1;
3094 DECL_ARTIFICIAL (decl
) = 1;
3095 TREE_NOTHROW (decl
) = 1;
3101 /* BLOCK nodes are used to represent the structure of binding contours
3102 and declarations, once those contours have been exited and their contents
3103 compiled. This information is used for outputting debugging info. */
3106 build_block (tree vars
, tree subblocks
, tree supercontext
, tree chain
)
3108 tree block
= make_node (BLOCK
);
3110 BLOCK_VARS (block
) = vars
;
3111 BLOCK_SUBBLOCKS (block
) = subblocks
;
3112 BLOCK_SUPERCONTEXT (block
) = supercontext
;
3113 BLOCK_CHAIN (block
) = chain
;
3117 #if 1 /* ! defined(USE_MAPPED_LOCATION) */
3118 /* ??? gengtype doesn't handle conditionals */
3119 static GTY(()) tree last_annotated_node
;
3122 #ifdef USE_MAPPED_LOCATION
3125 expand_location (source_location loc
)
3127 expanded_location xloc
;
3128 if (loc
== 0) { xloc
.file
= NULL
; xloc
.line
= 0; xloc
.column
= 0; }
3131 const struct line_map
*map
= linemap_lookup (&line_table
, loc
);
3132 xloc
.file
= map
->to_file
;
3133 xloc
.line
= SOURCE_LINE (map
, loc
);
3134 xloc
.column
= SOURCE_COLUMN (map
, loc
);
3141 /* Record the exact location where an expression or an identifier were
3145 annotate_with_file_line (tree node
, const char *file
, int line
)
3147 /* Roughly one percent of the calls to this function are to annotate
3148 a node with the same information already attached to that node!
3149 Just return instead of wasting memory. */
3150 if (EXPR_LOCUS (node
)
3151 && EXPR_LINENO (node
) == line
3152 && (EXPR_FILENAME (node
) == file
3153 || !strcmp (EXPR_FILENAME (node
), file
)))
3155 last_annotated_node
= node
;
3159 /* In heavily macroized code (such as GCC itself) this single
3160 entry cache can reduce the number of allocations by more
3162 if (last_annotated_node
3163 && EXPR_LOCUS (last_annotated_node
)
3164 && EXPR_LINENO (last_annotated_node
) == line
3165 && (EXPR_FILENAME (last_annotated_node
) == file
3166 || !strcmp (EXPR_FILENAME (last_annotated_node
), file
)))
3168 SET_EXPR_LOCUS (node
, EXPR_LOCUS (last_annotated_node
));
3172 SET_EXPR_LOCUS (node
, ggc_alloc (sizeof (location_t
)));
3173 EXPR_LINENO (node
) = line
;
3174 EXPR_FILENAME (node
) = file
;
3175 last_annotated_node
= node
;
3179 annotate_with_locus (tree node
, location_t locus
)
3181 annotate_with_file_line (node
, locus
.file
, locus
.line
);
3185 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
3189 build_decl_attribute_variant (tree ddecl
, tree attribute
)
3191 DECL_ATTRIBUTES (ddecl
) = attribute
;
3195 /* Borrowed from hashtab.c iterative_hash implementation. */
3196 #define mix(a,b,c) \
3198 a -= b; a -= c; a ^= (c>>13); \
3199 b -= c; b -= a; b ^= (a<< 8); \
3200 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
3201 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
3202 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
3203 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
3204 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
3205 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
3206 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
3210 /* Produce good hash value combining VAL and VAL2. */
3211 static inline hashval_t
3212 iterative_hash_hashval_t (hashval_t val
, hashval_t val2
)
3214 /* the golden ratio; an arbitrary value. */
3215 hashval_t a
= 0x9e3779b9;
3221 /* Produce good hash value combining PTR and VAL2. */
3222 static inline hashval_t
3223 iterative_hash_pointer (void *ptr
, hashval_t val2
)
3225 if (sizeof (ptr
) == sizeof (hashval_t
))
3226 return iterative_hash_hashval_t ((size_t) ptr
, val2
);
3229 hashval_t a
= (hashval_t
) (size_t) ptr
;
3230 /* Avoid warnings about shifting of more than the width of the type on
3231 hosts that won't execute this path. */
3233 hashval_t b
= (hashval_t
) ((size_t) ptr
>> (sizeof (hashval_t
) * 8 + zero
));
3239 /* Produce good hash value combining VAL and VAL2. */
3240 static inline hashval_t
3241 iterative_hash_host_wide_int (HOST_WIDE_INT val
, hashval_t val2
)
3243 if (sizeof (HOST_WIDE_INT
) == sizeof (hashval_t
))
3244 return iterative_hash_hashval_t (val
, val2
);
3247 hashval_t a
= (hashval_t
) val
;
3248 /* Avoid warnings about shifting of more than the width of the type on
3249 hosts that won't execute this path. */
3251 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 8 + zero
));
3253 if (sizeof (HOST_WIDE_INT
) > 2 * sizeof (hashval_t
))
3255 hashval_t a
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 16 + zero
));
3256 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 24 + zero
));
3263 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3266 Record such modified types already made so we don't make duplicates. */
3269 build_type_attribute_variant (tree ttype
, tree attribute
)
3271 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
3273 hashval_t hashcode
= 0;
3275 enum tree_code code
= TREE_CODE (ttype
);
3277 ntype
= copy_node (ttype
);
3279 TYPE_POINTER_TO (ntype
) = 0;
3280 TYPE_REFERENCE_TO (ntype
) = 0;
3281 TYPE_ATTRIBUTES (ntype
) = attribute
;
3283 /* Create a new main variant of TYPE. */
3284 TYPE_MAIN_VARIANT (ntype
) = ntype
;
3285 TYPE_NEXT_VARIANT (ntype
) = 0;
3286 set_type_quals (ntype
, TYPE_UNQUALIFIED
);
3288 hashcode
= iterative_hash_object (code
, hashcode
);
3289 if (TREE_TYPE (ntype
))
3290 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype
)),
3292 hashcode
= attribute_hash_list (attribute
, hashcode
);
3294 switch (TREE_CODE (ntype
))
3297 hashcode
= type_hash_list (TYPE_ARG_TYPES (ntype
), hashcode
);
3300 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype
)),
3304 hashcode
= iterative_hash_object
3305 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype
)), hashcode
);
3306 hashcode
= iterative_hash_object
3307 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype
)), hashcode
);
3311 unsigned int precision
= TYPE_PRECISION (ntype
);
3312 hashcode
= iterative_hash_object (precision
, hashcode
);
3319 ntype
= type_hash_canon (hashcode
, ntype
);
3320 ttype
= build_qualified_type (ntype
, TYPE_QUALS (ttype
));
3327 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3330 We try both `text' and `__text__', ATTR may be either one. */
3331 /* ??? It might be a reasonable simplification to require ATTR to be only
3332 `text'. One might then also require attribute lists to be stored in
3333 their canonicalized form. */
3336 is_attribute_with_length_p (const char *attr
, int attr_len
, tree ident
)
3341 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
3344 p
= IDENTIFIER_POINTER (ident
);
3345 ident_len
= IDENTIFIER_LENGTH (ident
);
3347 if (ident_len
== attr_len
3348 && strcmp (attr
, p
) == 0)
3351 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
3354 gcc_assert (attr
[1] == '_');
3355 gcc_assert (attr
[attr_len
- 2] == '_');
3356 gcc_assert (attr
[attr_len
- 1] == '_');
3357 gcc_assert (attr
[1] == '_');
3358 if (ident_len
== attr_len
- 4
3359 && strncmp (attr
+ 2, p
, attr_len
- 4) == 0)
3364 if (ident_len
== attr_len
+ 4
3365 && p
[0] == '_' && p
[1] == '_'
3366 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
3367 && strncmp (attr
, p
+ 2, attr_len
) == 0)
3374 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3377 We try both `text' and `__text__', ATTR may be either one. */
3380 is_attribute_p (const char *attr
, tree ident
)
3382 return is_attribute_with_length_p (attr
, strlen (attr
), ident
);
3385 /* Given an attribute name and a list of attributes, return a pointer to the
3386 attribute's list element if the attribute is part of the list, or NULL_TREE
3387 if not found. If the attribute appears more than once, this only
3388 returns the first occurrence; the TREE_CHAIN of the return value should
3389 be passed back in if further occurrences are wanted. */
3392 lookup_attribute (const char *attr_name
, tree list
)
3395 size_t attr_len
= strlen (attr_name
);
3397 for (l
= list
; l
; l
= TREE_CHAIN (l
))
3399 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
3400 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
3407 /* Return an attribute list that is the union of a1 and a2. */
3410 merge_attributes (tree a1
, tree a2
)
3414 /* Either one unset? Take the set one. */
3416 if ((attributes
= a1
) == 0)
3419 /* One that completely contains the other? Take it. */
3421 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
3423 if (attribute_list_contained (a2
, a1
))
3427 /* Pick the longest list, and hang on the other list. */
3429 if (list_length (a1
) < list_length (a2
))
3430 attributes
= a2
, a2
= a1
;
3432 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
3435 for (a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
3438 a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
3441 if (simple_cst_equal (TREE_VALUE (a
), TREE_VALUE (a2
)) == 1)
3446 a1
= copy_node (a2
);
3447 TREE_CHAIN (a1
) = attributes
;
3456 /* Given types T1 and T2, merge their attributes and return
3460 merge_type_attributes (tree t1
, tree t2
)
3462 return merge_attributes (TYPE_ATTRIBUTES (t1
),
3463 TYPE_ATTRIBUTES (t2
));
3466 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
3470 merge_decl_attributes (tree olddecl
, tree newdecl
)
3472 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
3473 DECL_ATTRIBUTES (newdecl
));
3476 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
3478 /* Specialization of merge_decl_attributes for various Windows targets.
3480 This handles the following situation:
3482 __declspec (dllimport) int foo;
3485 The second instance of `foo' nullifies the dllimport. */
3488 merge_dllimport_decl_attributes (tree old
, tree
new)
3491 int delete_dllimport_p
;
3493 old
= DECL_ATTRIBUTES (old
);
3494 new = DECL_ATTRIBUTES (new);
3496 /* What we need to do here is remove from `old' dllimport if it doesn't
3497 appear in `new'. dllimport behaves like extern: if a declaration is
3498 marked dllimport and a definition appears later, then the object
3499 is not dllimport'd. */
3500 if (lookup_attribute ("dllimport", old
) != NULL_TREE
3501 && lookup_attribute ("dllimport", new) == NULL_TREE
)
3502 delete_dllimport_p
= 1;
3504 delete_dllimport_p
= 0;
3506 a
= merge_attributes (old
, new);
3508 if (delete_dllimport_p
)
3512 /* Scan the list for dllimport and delete it. */
3513 for (prev
= NULL_TREE
, t
= a
; t
; prev
= t
, t
= TREE_CHAIN (t
))
3515 if (is_attribute_p ("dllimport", TREE_PURPOSE (t
)))
3517 if (prev
== NULL_TREE
)
3520 TREE_CHAIN (prev
) = TREE_CHAIN (t
);
3529 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
3530 struct attribute_spec.handler. */
3533 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
3538 /* These attributes may apply to structure and union types being created,
3539 but otherwise should pass to the declaration involved. */
3542 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
3543 | (int) ATTR_FLAG_ARRAY_NEXT
))
3545 *no_add_attrs
= true;
3546 return tree_cons (name
, args
, NULL_TREE
);
3548 if (TREE_CODE (node
) != RECORD_TYPE
&& TREE_CODE (node
) != UNION_TYPE
)
3550 warning (OPT_Wattributes
, "%qs attribute ignored",
3551 IDENTIFIER_POINTER (name
));
3552 *no_add_attrs
= true;
3558 /* Report error on dllimport ambiguities seen now before they cause
3560 if (is_attribute_p ("dllimport", name
))
3562 /* Like MS, treat definition of dllimported variables and
3563 non-inlined functions on declaration as syntax errors. We
3564 allow the attribute for function definitions if declared
3566 if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
)
3567 && !DECL_DECLARED_INLINE_P (node
))
3569 error ("function %q+D definition is marked dllimport", node
);
3570 *no_add_attrs
= true;
3573 else if (TREE_CODE (node
) == VAR_DECL
)
3575 if (DECL_INITIAL (node
))
3577 error ("variable %q+D definition is marked dllimport",
3579 *no_add_attrs
= true;
3582 /* `extern' needn't be specified with dllimport.
3583 Specify `extern' now and hope for the best. Sigh. */
3584 DECL_EXTERNAL (node
) = 1;
3585 /* Also, implicitly give dllimport'd variables declared within
3586 a function global scope, unless declared static. */
3587 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
3588 TREE_PUBLIC (node
) = 1;
3592 /* Report error if symbol is not accessible at global scope. */
3593 if (!TREE_PUBLIC (node
)
3594 && (TREE_CODE (node
) == VAR_DECL
3595 || TREE_CODE (node
) == FUNCTION_DECL
))
3597 error ("external linkage required for symbol %q+D because of "
3598 "%qs attribute", node
, IDENTIFIER_POINTER (name
));
3599 *no_add_attrs
= true;
3605 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
3607 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
3608 of the various TYPE_QUAL values. */
3611 set_type_quals (tree type
, int type_quals
)
3613 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
3614 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
3615 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
3618 /* Returns true iff cand is equivalent to base with type_quals. */
3621 check_qualified_type (tree cand
, tree base
, int type_quals
)
3623 return (TYPE_QUALS (cand
) == type_quals
3624 && TYPE_NAME (cand
) == TYPE_NAME (base
)
3625 /* Apparently this is needed for Objective-C. */
3626 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
3627 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
3628 TYPE_ATTRIBUTES (base
)));
3631 /* Return a version of the TYPE, qualified as indicated by the
3632 TYPE_QUALS, if one exists. If no qualified version exists yet,
3633 return NULL_TREE. */
3636 get_qualified_type (tree type
, int type_quals
)
3640 if (TYPE_QUALS (type
) == type_quals
)
3643 /* Search the chain of variants to see if there is already one there just
3644 like the one we need to have. If so, use that existing one. We must
3645 preserve the TYPE_NAME, since there is code that depends on this. */
3646 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
3647 if (check_qualified_type (t
, type
, type_quals
))
3653 /* Like get_qualified_type, but creates the type if it does not
3654 exist. This function never returns NULL_TREE. */
3657 build_qualified_type (tree type
, int type_quals
)
3661 /* See if we already have the appropriate qualified variant. */
3662 t
= get_qualified_type (type
, type_quals
);
3664 /* If not, build it. */
3667 t
= build_variant_type_copy (type
);
3668 set_type_quals (t
, type_quals
);
3674 /* Create a new distinct copy of TYPE. The new type is made its own
3678 build_distinct_type_copy (tree type
)
3680 tree t
= copy_node (type
);
3682 TYPE_POINTER_TO (t
) = 0;
3683 TYPE_REFERENCE_TO (t
) = 0;
3685 /* Make it its own variant. */
3686 TYPE_MAIN_VARIANT (t
) = t
;
3687 TYPE_NEXT_VARIANT (t
) = 0;
3692 /* Create a new variant of TYPE, equivalent but distinct.
3693 This is so the caller can modify it. */
3696 build_variant_type_copy (tree type
)
3698 tree t
, m
= TYPE_MAIN_VARIANT (type
);
3700 t
= build_distinct_type_copy (type
);
3702 /* Add the new type to the chain of variants of TYPE. */
3703 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
3704 TYPE_NEXT_VARIANT (m
) = t
;
3705 TYPE_MAIN_VARIANT (t
) = m
;
3710 /* Return true if the from tree in both tree maps are equal. */
3713 tree_map_eq (const void *va
, const void *vb
)
3715 const struct tree_map
*a
= va
, *b
= vb
;
3716 return (a
->from
== b
->from
);
3719 /* Hash a from tree in a tree_map. */
3722 tree_map_hash (const void *item
)
3724 return (((const struct tree_map
*) item
)->hash
);
3727 /* Return true if this tree map structure is marked for garbage collection
3728 purposes. We simply return true if the from tree is marked, so that this
3729 structure goes away when the from tree goes away. */
3732 tree_map_marked_p (const void *p
)
3734 tree from
= ((struct tree_map
*) p
)->from
;
3736 return ggc_marked_p (from
);
3739 /* Return true if the trees in the tree_int_map *'s VA and VB are equal. */
3742 tree_int_map_eq (const void *va
, const void *vb
)
3744 const struct tree_int_map
*a
= va
, *b
= vb
;
3745 return (a
->from
== b
->from
);
3748 /* Hash a from tree in the tree_int_map * ITEM. */
3751 tree_int_map_hash (const void *item
)
3753 return htab_hash_pointer (((const struct tree_int_map
*)item
)->from
);
3756 /* Return true if this tree int map structure is marked for garbage collection
3757 purposes. We simply return true if the from tree_int_map *P's from tree is marked, so that this
3758 structure goes away when the from tree goes away. */
3761 tree_int_map_marked_p (const void *p
)
3763 tree from
= ((struct tree_int_map
*) p
)->from
;
3765 return ggc_marked_p (from
);
3767 /* Lookup an init priority for FROM, and return it if we find one. */
3770 decl_init_priority_lookup (tree from
)
3772 struct tree_int_map
*h
, in
;
3775 h
= htab_find_with_hash (init_priority_for_decl
,
3776 &in
, htab_hash_pointer (from
));
3782 /* Insert a mapping FROM->TO in the init priority hashtable. */
3785 decl_init_priority_insert (tree from
, unsigned short to
)
3787 struct tree_int_map
*h
;
3790 h
= ggc_alloc (sizeof (struct tree_int_map
));
3793 loc
= htab_find_slot_with_hash (init_priority_for_decl
, h
,
3794 htab_hash_pointer (from
), INSERT
);
3795 *(struct tree_int_map
**) loc
= h
;
3798 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
3801 print_debug_expr_statistics (void)
3803 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
3804 (long) htab_size (debug_expr_for_decl
),
3805 (long) htab_elements (debug_expr_for_decl
),
3806 htab_collisions (debug_expr_for_decl
));
3809 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
3812 print_value_expr_statistics (void)
3814 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
3815 (long) htab_size (value_expr_for_decl
),
3816 (long) htab_elements (value_expr_for_decl
),
3817 htab_collisions (value_expr_for_decl
));
3819 /* Lookup a debug expression for FROM, and return it if we find one. */
3822 decl_debug_expr_lookup (tree from
)
3824 struct tree_map
*h
, in
;
3827 h
= htab_find_with_hash (debug_expr_for_decl
, &in
, htab_hash_pointer (from
));
3833 /* Insert a mapping FROM->TO in the debug expression hashtable. */
3836 decl_debug_expr_insert (tree from
, tree to
)
3841 h
= ggc_alloc (sizeof (struct tree_map
));
3842 h
->hash
= htab_hash_pointer (from
);
3845 loc
= htab_find_slot_with_hash (debug_expr_for_decl
, h
, h
->hash
, INSERT
);
3846 *(struct tree_map
**) loc
= h
;
3849 /* Lookup a value expression for FROM, and return it if we find one. */
3852 decl_value_expr_lookup (tree from
)
3854 struct tree_map
*h
, in
;
3857 h
= htab_find_with_hash (value_expr_for_decl
, &in
, htab_hash_pointer (from
));
3863 /* Insert a mapping FROM->TO in the value expression hashtable. */
3866 decl_value_expr_insert (tree from
, tree to
)
3871 h
= ggc_alloc (sizeof (struct tree_map
));
3872 h
->hash
= htab_hash_pointer (from
);
3875 loc
= htab_find_slot_with_hash (value_expr_for_decl
, h
, h
->hash
, INSERT
);
3876 *(struct tree_map
**) loc
= h
;
3879 /* Hashing of types so that we don't make duplicates.
3880 The entry point is `type_hash_canon'. */
3882 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
3883 with types in the TREE_VALUE slots), by adding the hash codes
3884 of the individual types. */
3887 type_hash_list (tree list
, hashval_t hashcode
)
3891 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
3892 if (TREE_VALUE (tail
) != error_mark_node
)
3893 hashcode
= iterative_hash_object (TYPE_HASH (TREE_VALUE (tail
)),
3899 /* These are the Hashtable callback functions. */
3901 /* Returns true iff the types are equivalent. */
3904 type_hash_eq (const void *va
, const void *vb
)
3906 const struct type_hash
*a
= va
, *b
= vb
;
3908 /* First test the things that are the same for all types. */
3909 if (a
->hash
!= b
->hash
3910 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
3911 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
3912 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
3913 TYPE_ATTRIBUTES (b
->type
))
3914 || TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
3915 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
))
3918 switch (TREE_CODE (a
->type
))
3923 case REFERENCE_TYPE
:
3927 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
3930 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
3931 && !(TYPE_VALUES (a
->type
)
3932 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
3933 && TYPE_VALUES (b
->type
)
3934 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
3935 && type_list_equal (TYPE_VALUES (a
->type
),
3936 TYPE_VALUES (b
->type
))))
3939 /* ... fall through ... */
3945 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
3946 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
3947 TYPE_MAX_VALUE (b
->type
)))
3948 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
3949 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
3950 TYPE_MIN_VALUE (b
->type
))));
3953 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
3956 return (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
3957 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
3958 || (TYPE_ARG_TYPES (a
->type
)
3959 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
3960 && TYPE_ARG_TYPES (b
->type
)
3961 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
3962 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
3963 TYPE_ARG_TYPES (b
->type
)))));
3966 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
3970 case QUAL_UNION_TYPE
:
3971 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
3972 || (TYPE_FIELDS (a
->type
)
3973 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
3974 && TYPE_FIELDS (b
->type
)
3975 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
3976 && type_list_equal (TYPE_FIELDS (a
->type
),
3977 TYPE_FIELDS (b
->type
))));
3980 return (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
3981 || (TYPE_ARG_TYPES (a
->type
)
3982 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
3983 && TYPE_ARG_TYPES (b
->type
)
3984 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
3985 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
3986 TYPE_ARG_TYPES (b
->type
))));
3993 /* Return the cached hash value. */
3996 type_hash_hash (const void *item
)
3998 return ((const struct type_hash
*) item
)->hash
;
4001 /* Look in the type hash table for a type isomorphic to TYPE.
4002 If one is found, return it. Otherwise return 0. */
4005 type_hash_lookup (hashval_t hashcode
, tree type
)
4007 struct type_hash
*h
, in
;
4009 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
4010 must call that routine before comparing TYPE_ALIGNs. */
4016 h
= htab_find_with_hash (type_hash_table
, &in
, hashcode
);
4022 /* Add an entry to the type-hash-table
4023 for a type TYPE whose hash code is HASHCODE. */
4026 type_hash_add (hashval_t hashcode
, tree type
)
4028 struct type_hash
*h
;
4031 h
= ggc_alloc (sizeof (struct type_hash
));
4034 loc
= htab_find_slot_with_hash (type_hash_table
, h
, hashcode
, INSERT
);
4035 *(struct type_hash
**) loc
= h
;
4038 /* Given TYPE, and HASHCODE its hash code, return the canonical
4039 object for an identical type if one already exists.
4040 Otherwise, return TYPE, and record it as the canonical object.
4042 To use this function, first create a type of the sort you want.
4043 Then compute its hash code from the fields of the type that
4044 make it different from other similar types.
4045 Then call this function and use the value. */
4048 type_hash_canon (unsigned int hashcode
, tree type
)
4052 /* The hash table only contains main variants, so ensure that's what we're
4054 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
4056 if (!lang_hooks
.types
.hash_types
)
4059 /* See if the type is in the hash table already. If so, return it.
4060 Otherwise, add the type. */
4061 t1
= type_hash_lookup (hashcode
, type
);
4064 #ifdef GATHER_STATISTICS
4065 tree_node_counts
[(int) t_kind
]--;
4066 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type
);
4072 type_hash_add (hashcode
, type
);
4077 /* See if the data pointed to by the type hash table is marked. We consider
4078 it marked if the type is marked or if a debug type number or symbol
4079 table entry has been made for the type. This reduces the amount of
4080 debugging output and eliminates that dependency of the debug output on
4081 the number of garbage collections. */
4084 type_hash_marked_p (const void *p
)
4086 tree type
= ((struct type_hash
*) p
)->type
;
4088 return ggc_marked_p (type
) || TYPE_SYMTAB_POINTER (type
);
4092 print_type_hash_statistics (void)
4094 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
4095 (long) htab_size (type_hash_table
),
4096 (long) htab_elements (type_hash_table
),
4097 htab_collisions (type_hash_table
));
4100 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
4101 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
4102 by adding the hash codes of the individual attributes. */
4105 attribute_hash_list (tree list
, hashval_t hashcode
)
4109 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
4110 /* ??? Do we want to add in TREE_VALUE too? */
4111 hashcode
= iterative_hash_object
4112 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail
)), hashcode
);
4116 /* Given two lists of attributes, return true if list l2 is
4117 equivalent to l1. */
4120 attribute_list_equal (tree l1
, tree l2
)
4122 return attribute_list_contained (l1
, l2
)
4123 && attribute_list_contained (l2
, l1
);
4126 /* Given two lists of attributes, return true if list L2 is
4127 completely contained within L1. */
4128 /* ??? This would be faster if attribute names were stored in a canonicalized
4129 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
4130 must be used to show these elements are equivalent (which they are). */
4131 /* ??? It's not clear that attributes with arguments will always be handled
4135 attribute_list_contained (tree l1
, tree l2
)
4139 /* First check the obvious, maybe the lists are identical. */
4143 /* Maybe the lists are similar. */
4144 for (t1
= l1
, t2
= l2
;
4146 && TREE_PURPOSE (t1
) == TREE_PURPOSE (t2
)
4147 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
4148 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
));
4150 /* Maybe the lists are equal. */
4151 if (t1
== 0 && t2
== 0)
4154 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
4157 for (attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)), l1
);
4159 attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
4162 if (simple_cst_equal (TREE_VALUE (t2
), TREE_VALUE (attr
)) == 1)
4169 if (simple_cst_equal (TREE_VALUE (t2
), TREE_VALUE (attr
)) != 1)
4176 /* Given two lists of types
4177 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
4178 return 1 if the lists contain the same types in the same order.
4179 Also, the TREE_PURPOSEs must match. */
4182 type_list_equal (tree l1
, tree l2
)
4186 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
4187 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
4188 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
4189 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
4190 && (TREE_TYPE (TREE_PURPOSE (t1
))
4191 == TREE_TYPE (TREE_PURPOSE (t2
))))))
4197 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
4198 given by TYPE. If the argument list accepts variable arguments,
4199 then this function counts only the ordinary arguments. */
4202 type_num_arguments (tree type
)
4207 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
4208 /* If the function does not take a variable number of arguments,
4209 the last element in the list will have type `void'. */
4210 if (VOID_TYPE_P (TREE_VALUE (t
)))
4218 /* Nonzero if integer constants T1 and T2
4219 represent the same constant value. */
4222 tree_int_cst_equal (tree t1
, tree t2
)
4227 if (t1
== 0 || t2
== 0)
4230 if (TREE_CODE (t1
) == INTEGER_CST
4231 && TREE_CODE (t2
) == INTEGER_CST
4232 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
4233 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
4239 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
4240 The precise way of comparison depends on their data type. */
4243 tree_int_cst_lt (tree t1
, tree t2
)
4248 if (TYPE_UNSIGNED (TREE_TYPE (t1
)) != TYPE_UNSIGNED (TREE_TYPE (t2
)))
4250 int t1_sgn
= tree_int_cst_sgn (t1
);
4251 int t2_sgn
= tree_int_cst_sgn (t2
);
4253 if (t1_sgn
< t2_sgn
)
4255 else if (t1_sgn
> t2_sgn
)
4257 /* Otherwise, both are non-negative, so we compare them as
4258 unsigned just in case one of them would overflow a signed
4261 else if (!TYPE_UNSIGNED (TREE_TYPE (t1
)))
4262 return INT_CST_LT (t1
, t2
);
4264 return INT_CST_LT_UNSIGNED (t1
, t2
);
4267 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
4270 tree_int_cst_compare (tree t1
, tree t2
)
4272 if (tree_int_cst_lt (t1
, t2
))
4274 else if (tree_int_cst_lt (t2
, t1
))
4280 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
4281 the host. If POS is zero, the value can be represented in a single
4282 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
4283 be represented in a single unsigned HOST_WIDE_INT. */
4286 host_integerp (tree t
, int pos
)
4288 return (TREE_CODE (t
) == INTEGER_CST
4289 && ! TREE_OVERFLOW (t
)
4290 && ((TREE_INT_CST_HIGH (t
) == 0
4291 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) >= 0)
4292 || (! pos
&& TREE_INT_CST_HIGH (t
) == -1
4293 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0
4294 && !TYPE_UNSIGNED (TREE_TYPE (t
)))
4295 || (pos
&& TREE_INT_CST_HIGH (t
) == 0)));
4298 /* Return the HOST_WIDE_INT least significant bits of T if it is an
4299 INTEGER_CST and there is no overflow. POS is nonzero if the result must
4300 be non-negative. We must be able to satisfy the above conditions. */
4303 tree_low_cst (tree t
, int pos
)
4305 gcc_assert (host_integerp (t
, pos
));
4306 return TREE_INT_CST_LOW (t
);
4309 /* Return the most significant bit of the integer constant T. */
4312 tree_int_cst_msb (tree t
)
4316 unsigned HOST_WIDE_INT l
;
4318 /* Note that using TYPE_PRECISION here is wrong. We care about the
4319 actual bits, not the (arbitrary) range of the type. */
4320 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t
))) - 1;
4321 rshift_double (TREE_INT_CST_LOW (t
), TREE_INT_CST_HIGH (t
), prec
,
4322 2 * HOST_BITS_PER_WIDE_INT
, &l
, &h
, 0);
4323 return (l
& 1) == 1;
4326 /* Return an indication of the sign of the integer constant T.
4327 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
4328 Note that -1 will never be returned it T's type is unsigned. */
4331 tree_int_cst_sgn (tree t
)
4333 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
4335 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
4337 else if (TREE_INT_CST_HIGH (t
) < 0)
4343 /* Compare two constructor-element-type constants. Return 1 if the lists
4344 are known to be equal; otherwise return 0. */
4347 simple_cst_list_equal (tree l1
, tree l2
)
4349 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
4351 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
4354 l1
= TREE_CHAIN (l1
);
4355 l2
= TREE_CHAIN (l2
);
4361 /* Return truthvalue of whether T1 is the same tree structure as T2.
4362 Return 1 if they are the same.
4363 Return 0 if they are understandably different.
4364 Return -1 if either contains tree structure not understood by
4368 simple_cst_equal (tree t1
, tree t2
)
4370 enum tree_code code1
, code2
;
4376 if (t1
== 0 || t2
== 0)
4379 code1
= TREE_CODE (t1
);
4380 code2
= TREE_CODE (t2
);
4382 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
4384 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
4385 || code2
== NON_LVALUE_EXPR
)
4386 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
4388 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
4391 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
4392 || code2
== NON_LVALUE_EXPR
)
4393 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
4401 return (TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
4402 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
));
4405 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
4408 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
4409 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
4410 TREE_STRING_LENGTH (t1
)));
4414 unsigned HOST_WIDE_INT idx
;
4415 VEC(constructor_elt
, gc
) *v1
= CONSTRUCTOR_ELTS (t1
);
4416 VEC(constructor_elt
, gc
) *v2
= CONSTRUCTOR_ELTS (t2
);
4418 if (VEC_length (constructor_elt
, v1
) != VEC_length (constructor_elt
, v2
))
4421 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
4422 /* ??? Should we handle also fields here? */
4423 if (!simple_cst_equal (VEC_index (constructor_elt
, v1
, idx
)->value
,
4424 VEC_index (constructor_elt
, v2
, idx
)->value
))
4430 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
4433 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
4437 simple_cst_list_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
4440 /* Special case: if either target is an unallocated VAR_DECL,
4441 it means that it's going to be unified with whatever the
4442 TARGET_EXPR is really supposed to initialize, so treat it
4443 as being equivalent to anything. */
4444 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
4445 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
4446 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
4447 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
4448 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
4449 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
4452 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
4457 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
4459 case WITH_CLEANUP_EXPR
:
4460 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
4464 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
4467 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
4468 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
4482 /* This general rule works for most tree codes. All exceptions should be
4483 handled above. If this is a language-specific tree code, we can't
4484 trust what might be in the operand, so say we don't know
4486 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
4489 switch (TREE_CODE_CLASS (code1
))
4493 case tcc_comparison
:
4494 case tcc_expression
:
4498 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
4500 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
4512 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
4513 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
4514 than U, respectively. */
4517 compare_tree_int (tree t
, unsigned HOST_WIDE_INT u
)
4519 if (tree_int_cst_sgn (t
) < 0)
4521 else if (TREE_INT_CST_HIGH (t
) != 0)
4523 else if (TREE_INT_CST_LOW (t
) == u
)
4525 else if (TREE_INT_CST_LOW (t
) < u
)
4531 /* Return true if CODE represents an associative tree code. Otherwise
4534 associative_tree_code (enum tree_code code
)
4553 /* Return true if CODE represents a commutative tree code. Otherwise
4556 commutative_tree_code (enum tree_code code
)
4569 case UNORDERED_EXPR
:
4573 case TRUTH_AND_EXPR
:
4574 case TRUTH_XOR_EXPR
:
4584 /* Generate a hash value for an expression. This can be used iteratively
4585 by passing a previous result as the "val" argument.
4587 This function is intended to produce the same hash for expressions which
4588 would compare equal using operand_equal_p. */
4591 iterative_hash_expr (tree t
, hashval_t val
)
4594 enum tree_code code
;
4598 return iterative_hash_pointer (t
, val
);
4600 code
= TREE_CODE (t
);
4604 /* Alas, constants aren't shared, so we can't rely on pointer
4607 val
= iterative_hash_host_wide_int (TREE_INT_CST_LOW (t
), val
);
4608 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t
), val
);
4611 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
4613 return iterative_hash_hashval_t (val2
, val
);
4616 return iterative_hash (TREE_STRING_POINTER (t
),
4617 TREE_STRING_LENGTH (t
), val
);
4619 val
= iterative_hash_expr (TREE_REALPART (t
), val
);
4620 return iterative_hash_expr (TREE_IMAGPART (t
), val
);
4622 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t
), val
);
4626 /* we can just compare by pointer. */
4627 return iterative_hash_pointer (t
, val
);
4630 /* A list of expressions, for a CALL_EXPR or as the elements of a
4632 for (; t
; t
= TREE_CHAIN (t
))
4633 val
= iterative_hash_expr (TREE_VALUE (t
), val
);
4637 unsigned HOST_WIDE_INT idx
;
4639 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
4641 val
= iterative_hash_expr (field
, val
);
4642 val
= iterative_hash_expr (value
, val
);
4647 /* When referring to a built-in FUNCTION_DECL, use the
4648 __builtin__ form. Otherwise nodes that compare equal
4649 according to operand_equal_p might get different
4651 if (DECL_BUILT_IN (t
))
4653 val
= iterative_hash_pointer (built_in_decls
[DECL_FUNCTION_CODE (t
)],
4657 /* else FALL THROUGH */
4659 class = TREE_CODE_CLASS (code
);
4661 if (class == tcc_declaration
)
4663 /* Otherwise, we can just compare decls by pointer. */
4664 val
= iterative_hash_pointer (t
, val
);
4668 gcc_assert (IS_EXPR_CODE_CLASS (class));
4670 val
= iterative_hash_object (code
, val
);
4672 /* Don't hash the type, that can lead to having nodes which
4673 compare equal according to operand_equal_p, but which
4674 have different hash codes. */
4675 if (code
== NOP_EXPR
4676 || code
== CONVERT_EXPR
4677 || code
== NON_LVALUE_EXPR
)
4679 /* Make sure to include signness in the hash computation. */
4680 val
+= TYPE_UNSIGNED (TREE_TYPE (t
));
4681 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
4684 else if (commutative_tree_code (code
))
4686 /* It's a commutative expression. We want to hash it the same
4687 however it appears. We do this by first hashing both operands
4688 and then rehashing based on the order of their independent
4690 hashval_t one
= iterative_hash_expr (TREE_OPERAND (t
, 0), 0);
4691 hashval_t two
= iterative_hash_expr (TREE_OPERAND (t
, 1), 0);
4695 t
= one
, one
= two
, two
= t
;
4697 val
= iterative_hash_hashval_t (one
, val
);
4698 val
= iterative_hash_hashval_t (two
, val
);
4701 for (i
= TREE_CODE_LENGTH (code
) - 1; i
>= 0; --i
)
4702 val
= iterative_hash_expr (TREE_OPERAND (t
, i
), val
);
4709 /* Constructors for pointer, array and function types.
4710 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
4711 constructed by language-dependent code, not here.) */
4713 /* Construct, lay out and return the type of pointers to TO_TYPE with
4714 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
4715 reference all of memory. If such a type has already been
4716 constructed, reuse it. */
4719 build_pointer_type_for_mode (tree to_type
, enum machine_mode mode
,
4724 if (to_type
== error_mark_node
)
4725 return error_mark_node
;
4727 /* In some cases, languages will have things that aren't a POINTER_TYPE
4728 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
4729 In that case, return that type without regard to the rest of our
4732 ??? This is a kludge, but consistent with the way this function has
4733 always operated and there doesn't seem to be a good way to avoid this
4735 if (TYPE_POINTER_TO (to_type
) != 0
4736 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
4737 return TYPE_POINTER_TO (to_type
);
4739 /* First, if we already have a type for pointers to TO_TYPE and it's
4740 the proper mode, use it. */
4741 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
4742 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
4745 t
= make_node (POINTER_TYPE
);
4747 TREE_TYPE (t
) = to_type
;
4748 TYPE_MODE (t
) = mode
;
4749 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
4750 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
4751 TYPE_POINTER_TO (to_type
) = t
;
4753 /* Lay out the type. This function has many callers that are concerned
4754 with expression-construction, and this simplifies them all. */
4760 /* By default build pointers in ptr_mode. */
4763 build_pointer_type (tree to_type
)
4765 return build_pointer_type_for_mode (to_type
, ptr_mode
, false);
4768 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
4771 build_reference_type_for_mode (tree to_type
, enum machine_mode mode
,
4776 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
4777 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
4778 In that case, return that type without regard to the rest of our
4781 ??? This is a kludge, but consistent with the way this function has
4782 always operated and there doesn't seem to be a good way to avoid this
4784 if (TYPE_REFERENCE_TO (to_type
) != 0
4785 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
4786 return TYPE_REFERENCE_TO (to_type
);
4788 /* First, if we already have a type for pointers to TO_TYPE and it's
4789 the proper mode, use it. */
4790 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
4791 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
4794 t
= make_node (REFERENCE_TYPE
);
4796 TREE_TYPE (t
) = to_type
;
4797 TYPE_MODE (t
) = mode
;
4798 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
4799 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
4800 TYPE_REFERENCE_TO (to_type
) = t
;
4808 /* Build the node for the type of references-to-TO_TYPE by default
4812 build_reference_type (tree to_type
)
4814 return build_reference_type_for_mode (to_type
, ptr_mode
, false);
4817 /* Build a type that is compatible with t but has no cv quals anywhere
4820 const char *const *const * -> char ***. */
4823 build_type_no_quals (tree t
)
4825 switch (TREE_CODE (t
))
4828 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
4830 TYPE_REF_CAN_ALIAS_ALL (t
));
4831 case REFERENCE_TYPE
:
4833 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
4835 TYPE_REF_CAN_ALIAS_ALL (t
));
4837 return TYPE_MAIN_VARIANT (t
);
4841 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
4842 MAXVAL should be the maximum value in the domain
4843 (one less than the length of the array).
4845 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
4846 We don't enforce this limit, that is up to caller (e.g. language front end).
4847 The limit exists because the result is a signed type and we don't handle
4848 sizes that use more than one HOST_WIDE_INT. */
4851 build_index_type (tree maxval
)
4853 tree itype
= make_node (INTEGER_TYPE
);
4855 TREE_TYPE (itype
) = sizetype
;
4856 TYPE_PRECISION (itype
) = TYPE_PRECISION (sizetype
);
4857 TYPE_MIN_VALUE (itype
) = size_zero_node
;
4858 TYPE_MAX_VALUE (itype
) = fold_convert (sizetype
, maxval
);
4859 TYPE_MODE (itype
) = TYPE_MODE (sizetype
);
4860 TYPE_SIZE (itype
) = TYPE_SIZE (sizetype
);
4861 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (sizetype
);
4862 TYPE_ALIGN (itype
) = TYPE_ALIGN (sizetype
);
4863 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (sizetype
);
4865 if (host_integerp (maxval
, 1))
4866 return type_hash_canon (tree_low_cst (maxval
, 1), itype
);
4871 /* Builds a signed or unsigned integer type of precision PRECISION.
4872 Used for C bitfields whose precision does not match that of
4873 built-in target types. */
4875 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
4878 tree itype
= make_node (INTEGER_TYPE
);
4880 TYPE_PRECISION (itype
) = precision
;
4883 fixup_unsigned_type (itype
);
4885 fixup_signed_type (itype
);
4887 if (host_integerp (TYPE_MAX_VALUE (itype
), 1))
4888 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype
), 1), itype
);
4893 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
4894 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
4895 low bound LOWVAL and high bound HIGHVAL.
4896 if TYPE==NULL_TREE, sizetype is used. */
4899 build_range_type (tree type
, tree lowval
, tree highval
)
4901 tree itype
= make_node (INTEGER_TYPE
);
4903 TREE_TYPE (itype
) = type
;
4904 if (type
== NULL_TREE
)
4907 TYPE_MIN_VALUE (itype
) = convert (type
, lowval
);
4908 TYPE_MAX_VALUE (itype
) = highval
? convert (type
, highval
) : NULL
;
4910 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
4911 TYPE_MODE (itype
) = TYPE_MODE (type
);
4912 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
4913 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
4914 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
4915 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
4917 if (host_integerp (lowval
, 0) && highval
!= 0 && host_integerp (highval
, 0))
4918 return type_hash_canon (tree_low_cst (highval
, 0)
4919 - tree_low_cst (lowval
, 0),
4925 /* Just like build_index_type, but takes lowval and highval instead
4926 of just highval (maxval). */
4929 build_index_2_type (tree lowval
, tree highval
)
4931 return build_range_type (sizetype
, lowval
, highval
);
4934 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
4935 and number of elements specified by the range of values of INDEX_TYPE.
4936 If such a type has already been constructed, reuse it. */
4939 build_array_type (tree elt_type
, tree index_type
)
4942 hashval_t hashcode
= 0;
4944 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
4946 error ("arrays of functions are not meaningful");
4947 elt_type
= integer_type_node
;
4950 t
= make_node (ARRAY_TYPE
);
4951 TREE_TYPE (t
) = elt_type
;
4952 TYPE_DOMAIN (t
) = index_type
;
4954 if (index_type
== 0)
4960 hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), hashcode
);
4961 hashcode
= iterative_hash_object (TYPE_HASH (index_type
), hashcode
);
4962 t
= type_hash_canon (hashcode
, t
);
4964 if (!COMPLETE_TYPE_P (t
))
4969 /* Return the TYPE of the elements comprising
4970 the innermost dimension of ARRAY. */
4973 get_inner_array_type (tree array
)
4975 tree type
= TREE_TYPE (array
);
4977 while (TREE_CODE (type
) == ARRAY_TYPE
)
4978 type
= TREE_TYPE (type
);
4983 /* Construct, lay out and return
4984 the type of functions returning type VALUE_TYPE
4985 given arguments of types ARG_TYPES.
4986 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
4987 are data type nodes for the arguments of the function.
4988 If such a type has already been constructed, reuse it. */
4991 build_function_type (tree value_type
, tree arg_types
)
4994 hashval_t hashcode
= 0;
4996 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
4998 error ("function return type cannot be function");
4999 value_type
= integer_type_node
;
5002 /* Make a node of the sort we want. */
5003 t
= make_node (FUNCTION_TYPE
);
5004 TREE_TYPE (t
) = value_type
;
5005 TYPE_ARG_TYPES (t
) = arg_types
;
5007 /* If we already have such a type, use the old one. */
5008 hashcode
= iterative_hash_object (TYPE_HASH (value_type
), hashcode
);
5009 hashcode
= type_hash_list (arg_types
, hashcode
);
5010 t
= type_hash_canon (hashcode
, t
);
5012 if (!COMPLETE_TYPE_P (t
))
5017 /* Build a function type. The RETURN_TYPE is the type returned by the
5018 function. If additional arguments are provided, they are
5019 additional argument types. The list of argument types must always
5020 be terminated by NULL_TREE. */
5023 build_function_type_list (tree return_type
, ...)
5028 va_start (p
, return_type
);
5030 t
= va_arg (p
, tree
);
5031 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (p
, tree
))
5032 args
= tree_cons (NULL_TREE
, t
, args
);
5034 if (args
== NULL_TREE
)
5035 args
= void_list_node
;
5039 args
= nreverse (args
);
5040 TREE_CHAIN (last
) = void_list_node
;
5042 args
= build_function_type (return_type
, args
);
5048 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
5049 and ARGTYPES (a TREE_LIST) are the return type and arguments types
5050 for the method. An implicit additional parameter (of type
5051 pointer-to-BASETYPE) is added to the ARGTYPES. */
5054 build_method_type_directly (tree basetype
,
5062 /* Make a node of the sort we want. */
5063 t
= make_node (METHOD_TYPE
);
5065 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
5066 TREE_TYPE (t
) = rettype
;
5067 ptype
= build_pointer_type (basetype
);
5069 /* The actual arglist for this function includes a "hidden" argument
5070 which is "this". Put it into the list of argument types. */
5071 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
5072 TYPE_ARG_TYPES (t
) = argtypes
;
5074 /* If we already have such a type, use the old one. */
5075 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
5076 hashcode
= iterative_hash_object (TYPE_HASH (rettype
), hashcode
);
5077 hashcode
= type_hash_list (argtypes
, hashcode
);
5078 t
= type_hash_canon (hashcode
, t
);
5080 if (!COMPLETE_TYPE_P (t
))
5086 /* Construct, lay out and return the type of methods belonging to class
5087 BASETYPE and whose arguments and values are described by TYPE.
5088 If that type exists already, reuse it.
5089 TYPE must be a FUNCTION_TYPE node. */
5092 build_method_type (tree basetype
, tree type
)
5094 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
5096 return build_method_type_directly (basetype
,
5098 TYPE_ARG_TYPES (type
));
5101 /* Construct, lay out and return the type of offsets to a value
5102 of type TYPE, within an object of type BASETYPE.
5103 If a suitable offset type exists already, reuse it. */
5106 build_offset_type (tree basetype
, tree type
)
5109 hashval_t hashcode
= 0;
5111 /* Make a node of the sort we want. */
5112 t
= make_node (OFFSET_TYPE
);
5114 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
5115 TREE_TYPE (t
) = type
;
5117 /* If we already have such a type, use the old one. */
5118 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
5119 hashcode
= iterative_hash_object (TYPE_HASH (type
), hashcode
);
5120 t
= type_hash_canon (hashcode
, t
);
5122 if (!COMPLETE_TYPE_P (t
))
5128 /* Create a complex type whose components are COMPONENT_TYPE. */
5131 build_complex_type (tree component_type
)
5136 /* Make a node of the sort we want. */
5137 t
= make_node (COMPLEX_TYPE
);
5139 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
5141 /* If we already have such a type, use the old one. */
5142 hashcode
= iterative_hash_object (TYPE_HASH (component_type
), 0);
5143 t
= type_hash_canon (hashcode
, t
);
5145 if (!COMPLETE_TYPE_P (t
))
5148 /* If we are writing Dwarf2 output we need to create a name,
5149 since complex is a fundamental type. */
5150 if ((write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
5154 if (component_type
== char_type_node
)
5155 name
= "complex char";
5156 else if (component_type
== signed_char_type_node
)
5157 name
= "complex signed char";
5158 else if (component_type
== unsigned_char_type_node
)
5159 name
= "complex unsigned char";
5160 else if (component_type
== short_integer_type_node
)
5161 name
= "complex short int";
5162 else if (component_type
== short_unsigned_type_node
)
5163 name
= "complex short unsigned int";
5164 else if (component_type
== integer_type_node
)
5165 name
= "complex int";
5166 else if (component_type
== unsigned_type_node
)
5167 name
= "complex unsigned int";
5168 else if (component_type
== long_integer_type_node
)
5169 name
= "complex long int";
5170 else if (component_type
== long_unsigned_type_node
)
5171 name
= "complex long unsigned int";
5172 else if (component_type
== long_long_integer_type_node
)
5173 name
= "complex long long int";
5174 else if (component_type
== long_long_unsigned_type_node
)
5175 name
= "complex long long unsigned int";
5180 TYPE_NAME (t
) = get_identifier (name
);
5183 return build_qualified_type (t
, TYPE_QUALS (component_type
));
5186 /* Return OP, stripped of any conversions to wider types as much as is safe.
5187 Converting the value back to OP's type makes a value equivalent to OP.
5189 If FOR_TYPE is nonzero, we return a value which, if converted to
5190 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
5192 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
5193 narrowest type that can hold the value, even if they don't exactly fit.
5194 Otherwise, bit-field references are changed to a narrower type
5195 only if they can be fetched directly from memory in that type.
5197 OP must have integer, real or enumeral type. Pointers are not allowed!
5199 There are some cases where the obvious value we could return
5200 would regenerate to OP if converted to OP's type,
5201 but would not extend like OP to wider types.
5202 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
5203 For example, if OP is (unsigned short)(signed char)-1,
5204 we avoid returning (signed char)-1 if FOR_TYPE is int,
5205 even though extending that to an unsigned short would regenerate OP,
5206 since the result of extending (signed char)-1 to (int)
5207 is different from (int) OP. */
5210 get_unwidened (tree op
, tree for_type
)
5212 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
5213 tree type
= TREE_TYPE (op
);
5215 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
5217 = (for_type
!= 0 && for_type
!= type
5218 && final_prec
> TYPE_PRECISION (type
)
5219 && TYPE_UNSIGNED (type
));
5222 while (TREE_CODE (op
) == NOP_EXPR
5223 || TREE_CODE (op
) == CONVERT_EXPR
)
5227 /* TYPE_PRECISION on vector types has different meaning
5228 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
5229 so avoid them here. */
5230 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
5233 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
5234 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
5236 /* Truncations are many-one so cannot be removed.
5237 Unless we are later going to truncate down even farther. */
5239 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
5242 /* See what's inside this conversion. If we decide to strip it,
5244 op
= TREE_OPERAND (op
, 0);
5246 /* If we have not stripped any zero-extensions (uns is 0),
5247 we can strip any kind of extension.
5248 If we have previously stripped a zero-extension,
5249 only zero-extensions can safely be stripped.
5250 Any extension can be stripped if the bits it would produce
5251 are all going to be discarded later by truncating to FOR_TYPE. */
5255 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
5257 /* TYPE_UNSIGNED says whether this is a zero-extension.
5258 Let's avoid computing it if it does not affect WIN
5259 and if UNS will not be needed again. */
5261 || TREE_CODE (op
) == NOP_EXPR
5262 || TREE_CODE (op
) == CONVERT_EXPR
)
5263 && TYPE_UNSIGNED (TREE_TYPE (op
)))
5271 if (TREE_CODE (op
) == COMPONENT_REF
5272 /* Since type_for_size always gives an integer type. */
5273 && TREE_CODE (type
) != REAL_TYPE
5274 /* Don't crash if field not laid out yet. */
5275 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
5276 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
5278 unsigned int innerprec
5279 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
5280 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
5281 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
5282 type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
5284 /* We can get this structure field in the narrowest type it fits in.
5285 If FOR_TYPE is 0, do this only for a field that matches the
5286 narrower type exactly and is aligned for it
5287 The resulting extension to its nominal type (a fullword type)
5288 must fit the same conditions as for other extensions. */
5291 && INT_CST_LT_UNSIGNED (TYPE_SIZE (type
), TYPE_SIZE (TREE_TYPE (op
)))
5292 && (for_type
|| ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1)))
5293 && (! uns
|| final_prec
<= innerprec
|| unsignedp
))
5295 win
= build3 (COMPONENT_REF
, type
, TREE_OPERAND (op
, 0),
5296 TREE_OPERAND (op
, 1), NULL_TREE
);
5297 TREE_SIDE_EFFECTS (win
) = TREE_SIDE_EFFECTS (op
);
5298 TREE_THIS_VOLATILE (win
) = TREE_THIS_VOLATILE (op
);
5305 /* Return OP or a simpler expression for a narrower value
5306 which can be sign-extended or zero-extended to give back OP.
5307 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
5308 or 0 if the value should be sign-extended. */
5311 get_narrower (tree op
, int *unsignedp_ptr
)
5316 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
5318 while (TREE_CODE (op
) == NOP_EXPR
)
5321 = (TYPE_PRECISION (TREE_TYPE (op
))
5322 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
5324 /* Truncations are many-one so cannot be removed. */
5328 /* See what's inside this conversion. If we decide to strip it,
5333 op
= TREE_OPERAND (op
, 0);
5334 /* An extension: the outermost one can be stripped,
5335 but remember whether it is zero or sign extension. */
5337 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
5338 /* Otherwise, if a sign extension has been stripped,
5339 only sign extensions can now be stripped;
5340 if a zero extension has been stripped, only zero-extensions. */
5341 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
5345 else /* bitschange == 0 */
5347 /* A change in nominal type can always be stripped, but we must
5348 preserve the unsignedness. */
5350 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
5352 op
= TREE_OPERAND (op
, 0);
5353 /* Keep trying to narrow, but don't assign op to win if it
5354 would turn an integral type into something else. */
5355 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
5362 if (TREE_CODE (op
) == COMPONENT_REF
5363 /* Since type_for_size always gives an integer type. */
5364 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
5365 /* Ensure field is laid out already. */
5366 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
5367 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
5369 unsigned HOST_WIDE_INT innerprec
5370 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
5371 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
5372 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
5373 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
5375 /* We can get this structure field in a narrower type that fits it,
5376 but the resulting extension to its nominal type (a fullword type)
5377 must satisfy the same conditions as for other extensions.
5379 Do this only for fields that are aligned (not bit-fields),
5380 because when bit-field insns will be used there is no
5381 advantage in doing this. */
5383 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
5384 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
5385 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
5389 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
5390 win
= build3 (COMPONENT_REF
, type
, TREE_OPERAND (op
, 0),
5391 TREE_OPERAND (op
, 1), NULL_TREE
);
5392 TREE_SIDE_EFFECTS (win
) = TREE_SIDE_EFFECTS (op
);
5393 TREE_THIS_VOLATILE (win
) = TREE_THIS_VOLATILE (op
);
5396 *unsignedp_ptr
= uns
;
5400 /* Nonzero if integer constant C has a value that is permissible
5401 for type TYPE (an INTEGER_TYPE). */
5404 int_fits_type_p (tree c
, tree type
)
5406 tree type_low_bound
= TYPE_MIN_VALUE (type
);
5407 tree type_high_bound
= TYPE_MAX_VALUE (type
);
5408 bool ok_for_low_bound
, ok_for_high_bound
;
5411 /* If at least one bound of the type is a constant integer, we can check
5412 ourselves and maybe make a decision. If no such decision is possible, but
5413 this type is a subtype, try checking against that. Otherwise, use
5414 force_fit_type, which checks against the precision.
5416 Compute the status for each possibly constant bound, and return if we see
5417 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
5418 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
5419 for "constant known to fit". */
5421 /* Check if C >= type_low_bound. */
5422 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
5424 if (tree_int_cst_lt (c
, type_low_bound
))
5426 ok_for_low_bound
= true;
5429 ok_for_low_bound
= false;
5431 /* Check if c <= type_high_bound. */
5432 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
5434 if (tree_int_cst_lt (type_high_bound
, c
))
5436 ok_for_high_bound
= true;
5439 ok_for_high_bound
= false;
5441 /* If the constant fits both bounds, the result is known. */
5442 if (ok_for_low_bound
&& ok_for_high_bound
)
5445 /* Perform some generic filtering which may allow making a decision
5446 even if the bounds are not constant. First, negative integers
5447 never fit in unsigned types, */
5448 if (TYPE_UNSIGNED (type
) && tree_int_cst_sgn (c
) < 0)
5451 /* Second, narrower types always fit in wider ones. */
5452 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
5455 /* Third, unsigned integers with top bit set never fit signed types. */
5456 if (! TYPE_UNSIGNED (type
)
5457 && TYPE_UNSIGNED (TREE_TYPE (c
))
5458 && tree_int_cst_msb (c
))
5461 /* If we haven't been able to decide at this point, there nothing more we
5462 can check ourselves here. Look at the base type if we have one. */
5463 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != 0)
5464 return int_fits_type_p (c
, TREE_TYPE (type
));
5466 /* Or to force_fit_type, if nothing else. */
5467 tmp
= copy_node (c
);
5468 TREE_TYPE (tmp
) = type
;
5469 tmp
= force_fit_type (tmp
, -1, false, false);
5470 return TREE_INT_CST_HIGH (tmp
) == TREE_INT_CST_HIGH (c
)
5471 && TREE_INT_CST_LOW (tmp
) == TREE_INT_CST_LOW (c
);
5474 /* Subprogram of following function. Called by walk_tree.
5476 Return *TP if it is an automatic variable or parameter of the
5477 function passed in as DATA. */
5480 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
5482 tree fn
= (tree
) data
;
5487 else if (DECL_P (*tp
)
5488 && lang_hooks
.tree_inlining
.auto_var_in_fn_p (*tp
, fn
))
5494 /* Returns true if T is, contains, or refers to a type with variable
5495 size. If FN is nonzero, only return true if a modifier of the type
5496 or position of FN is a variable or parameter inside FN.
5498 This concept is more general than that of C99 'variably modified types':
5499 in C99, a struct type is never variably modified because a VLA may not
5500 appear as a structure member. However, in GNU C code like:
5502 struct S { int i[f()]; };
5504 is valid, and other languages may define similar constructs. */
5507 variably_modified_type_p (tree type
, tree fn
)
5511 /* Test if T is either variable (if FN is zero) or an expression containing
5512 a variable in FN. */
5513 #define RETURN_TRUE_IF_VAR(T) \
5514 do { tree _t = (T); \
5515 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
5516 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
5517 return true; } while (0)
5519 if (type
== error_mark_node
)
5522 /* If TYPE itself has variable size, it is variably modified.
5524 We do not yet have a representation of the C99 '[*]' syntax.
5525 When a representation is chosen, this function should be modified
5526 to test for that case as well. */
5527 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
5528 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT(type
));
5530 switch (TREE_CODE (type
))
5533 case REFERENCE_TYPE
:
5536 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
5542 /* If TYPE is a function type, it is variably modified if any of the
5543 parameters or the return type are variably modified. */
5544 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
5547 for (t
= TYPE_ARG_TYPES (type
);
5548 t
&& t
!= void_list_node
;
5550 if (variably_modified_type_p (TREE_VALUE (t
), fn
))
5559 /* Scalar types are variably modified if their end points
5561 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
5562 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
5567 case QUAL_UNION_TYPE
:
5568 /* We can't see if any of the field are variably-modified by the
5569 definition we normally use, since that would produce infinite
5570 recursion via pointers. */
5571 /* This is variably modified if some field's type is. */
5572 for (t
= TYPE_FIELDS (type
); t
; t
= TREE_CHAIN (t
))
5573 if (TREE_CODE (t
) == FIELD_DECL
)
5575 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
5576 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
5577 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
5579 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
5580 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
5588 /* The current language may have other cases to check, but in general,
5589 all other types are not variably modified. */
5590 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
5592 #undef RETURN_TRUE_IF_VAR
5595 /* Given a DECL or TYPE, return the scope in which it was declared, or
5596 NULL_TREE if there is no containing scope. */
5599 get_containing_scope (tree t
)
5601 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
5604 /* Return the innermost context enclosing DECL that is
5605 a FUNCTION_DECL, or zero if none. */
5608 decl_function_context (tree decl
)
5612 if (TREE_CODE (decl
) == ERROR_MARK
)
5615 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
5616 where we look up the function at runtime. Such functions always take
5617 a first argument of type 'pointer to real context'.
5619 C++ should really be fixed to use DECL_CONTEXT for the real context,
5620 and use something else for the "virtual context". */
5621 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
5624 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
5626 context
= DECL_CONTEXT (decl
);
5628 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
5630 if (TREE_CODE (context
) == BLOCK
)
5631 context
= BLOCK_SUPERCONTEXT (context
);
5633 context
= get_containing_scope (context
);
5639 /* Return the innermost context enclosing DECL that is
5640 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
5641 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
5644 decl_type_context (tree decl
)
5646 tree context
= DECL_CONTEXT (decl
);
5649 switch (TREE_CODE (context
))
5651 case NAMESPACE_DECL
:
5652 case TRANSLATION_UNIT_DECL
:
5657 case QUAL_UNION_TYPE
:
5662 context
= DECL_CONTEXT (context
);
5666 context
= BLOCK_SUPERCONTEXT (context
);
5676 /* CALL is a CALL_EXPR. Return the declaration for the function
5677 called, or NULL_TREE if the called function cannot be
5681 get_callee_fndecl (tree call
)
5685 /* It's invalid to call this function with anything but a
5687 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
5689 /* The first operand to the CALL is the address of the function
5691 addr
= TREE_OPERAND (call
, 0);
5695 /* If this is a readonly function pointer, extract its initial value. */
5696 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
5697 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
5698 && DECL_INITIAL (addr
))
5699 addr
= DECL_INITIAL (addr
);
5701 /* If the address is just `&f' for some function `f', then we know
5702 that `f' is being called. */
5703 if (TREE_CODE (addr
) == ADDR_EXPR
5704 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
5705 return TREE_OPERAND (addr
, 0);
5707 /* We couldn't figure out what was being called. Maybe the front
5708 end has some idea. */
5709 return lang_hooks
.lang_get_callee_fndecl (call
);
5712 /* Print debugging information about tree nodes generated during the compile,
5713 and any language-specific information. */
5716 dump_tree_statistics (void)
5718 #ifdef GATHER_STATISTICS
5720 int total_nodes
, total_bytes
;
5723 fprintf (stderr
, "\n??? tree nodes created\n\n");
5724 #ifdef GATHER_STATISTICS
5725 fprintf (stderr
, "Kind Nodes Bytes\n");
5726 fprintf (stderr
, "---------------------------------------\n");
5727 total_nodes
= total_bytes
= 0;
5728 for (i
= 0; i
< (int) all_kinds
; i
++)
5730 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
5731 tree_node_counts
[i
], tree_node_sizes
[i
]);
5732 total_nodes
+= tree_node_counts
[i
];
5733 total_bytes
+= tree_node_sizes
[i
];
5735 fprintf (stderr
, "---------------------------------------\n");
5736 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
5737 fprintf (stderr
, "---------------------------------------\n");
5738 ssanames_print_statistics ();
5739 phinodes_print_statistics ();
5741 fprintf (stderr
, "(No per-node statistics)\n");
5743 print_type_hash_statistics ();
5744 print_debug_expr_statistics ();
5745 print_value_expr_statistics ();
5746 lang_hooks
.print_statistics ();
5749 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
5751 /* Generate a crc32 of a string. */
5754 crc32_string (unsigned chksum
, const char *string
)
5758 unsigned value
= *string
<< 24;
5761 for (ix
= 8; ix
--; value
<<= 1)
5765 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
5774 /* P is a string that will be used in a symbol. Mask out any characters
5775 that are not valid in that context. */
5778 clean_symbol_name (char *p
)
5782 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
5785 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
5792 /* Generate a name for a function unique to this translation unit.
5793 TYPE is some string to identify the purpose of this function to the
5794 linker or collect2. */
5797 get_file_function_name_long (const char *type
)
5803 if (first_global_object_name
)
5804 p
= first_global_object_name
;
5807 /* We don't have anything that we know to be unique to this translation
5808 unit, so use what we do have and throw in some randomness. */
5810 const char *name
= weak_global_object_name
;
5811 const char *file
= main_input_filename
;
5816 file
= input_filename
;
5818 len
= strlen (file
);
5819 q
= alloca (9 * 2 + len
+ 1);
5820 memcpy (q
, file
, len
+ 1);
5821 clean_symbol_name (q
);
5823 sprintf (q
+ len
, "_%08X_%08X", crc32_string (0, name
),
5824 crc32_string (0, flag_random_seed
));
5829 buf
= alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
) + strlen (type
));
5831 /* Set up the name of the file-level functions we may need.
5832 Use a global object (which is already required to be unique over
5833 the program) rather than the file name (which imposes extra
5835 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
5837 return get_identifier (buf
);
5840 /* If KIND=='I', return a suitable global initializer (constructor) name.
5841 If KIND=='D', return a suitable global clean-up (destructor) name. */
5844 get_file_function_name (int kind
)
5851 return get_file_function_name_long (p
);
5854 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
5856 /* Complain that the tree code of NODE does not match the expected 0
5857 terminated list of trailing codes. The trailing code list can be
5858 empty, for a more vague error message. FILE, LINE, and FUNCTION
5859 are of the caller. */
5862 tree_check_failed (const tree node
, const char *file
,
5863 int line
, const char *function
, ...)
5867 unsigned length
= 0;
5870 va_start (args
, function
);
5871 while ((code
= va_arg (args
, int)))
5872 length
+= 4 + strlen (tree_code_name
[code
]);
5876 va_start (args
, function
);
5877 length
+= strlen ("expected ");
5878 buffer
= alloca (length
);
5880 while ((code
= va_arg (args
, int)))
5882 const char *prefix
= length
? " or " : "expected ";
5884 strcpy (buffer
+ length
, prefix
);
5885 length
+= strlen (prefix
);
5886 strcpy (buffer
+ length
, tree_code_name
[code
]);
5887 length
+= strlen (tree_code_name
[code
]);
5892 buffer
= (char *)"unexpected node";
5894 internal_error ("tree check: %s, have %s in %s, at %s:%d",
5895 buffer
, tree_code_name
[TREE_CODE (node
)],
5896 function
, trim_filename (file
), line
);
5899 /* Complain that the tree code of NODE does match the expected 0
5900 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
5904 tree_not_check_failed (const tree node
, const char *file
,
5905 int line
, const char *function
, ...)
5909 unsigned length
= 0;
5912 va_start (args
, function
);
5913 while ((code
= va_arg (args
, int)))
5914 length
+= 4 + strlen (tree_code_name
[code
]);
5916 va_start (args
, function
);
5917 buffer
= alloca (length
);
5919 while ((code
= va_arg (args
, int)))
5923 strcpy (buffer
+ length
, " or ");
5926 strcpy (buffer
+ length
, tree_code_name
[code
]);
5927 length
+= strlen (tree_code_name
[code
]);
5931 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
5932 buffer
, tree_code_name
[TREE_CODE (node
)],
5933 function
, trim_filename (file
), line
);
5936 /* Similar to tree_check_failed, except that we check for a class of tree
5937 code, given in CL. */
5940 tree_class_check_failed (const tree node
, const enum tree_code_class cl
,
5941 const char *file
, int line
, const char *function
)
5944 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
5945 TREE_CODE_CLASS_STRING (cl
),
5946 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
5947 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
5949 #undef DEFTREESTRUCT
5950 #define DEFTREESTRUCT(VAL, NAME) NAME,
5952 static const char *ts_enum_names
[] = {
5953 #include "treestruct.def"
5955 #undef DEFTREESTRUCT
5957 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
5959 /* Similar to tree_class_check_failed, except that we check for
5960 whether CODE contains the tree structure identified by EN. */
5963 tree_contains_struct_check_failed (const tree node
,
5964 const enum tree_node_structure_enum en
,
5965 const char *file
, int line
,
5966 const char *function
)
5969 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
5971 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
5975 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
5976 (dynamically sized) vector. */
5979 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
5980 const char *function
)
5983 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
5984 idx
+ 1, len
, function
, trim_filename (file
), line
);
5987 /* Similar to above, except that the check is for the bounds of a PHI_NODE's
5988 (dynamically sized) vector. */
5991 phi_node_elt_check_failed (int idx
, int len
, const char *file
, int line
,
5992 const char *function
)
5995 ("tree check: accessed elt %d of phi_node with %d elts in %s, at %s:%d",
5996 idx
+ 1, len
, function
, trim_filename (file
), line
);
5999 /* Similar to above, except that the check is for the bounds of the operand
6000 vector of an expression node. */
6003 tree_operand_check_failed (int idx
, enum tree_code code
, const char *file
,
6004 int line
, const char *function
)
6007 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
6008 idx
+ 1, tree_code_name
[code
], TREE_CODE_LENGTH (code
),
6009 function
, trim_filename (file
), line
);
6011 #endif /* ENABLE_TREE_CHECKING */
6013 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
6014 and mapped to the machine mode MODE. Initialize its fields and build
6015 the information necessary for debugging output. */
6018 make_vector_type (tree innertype
, int nunits
, enum machine_mode mode
)
6020 tree t
= make_node (VECTOR_TYPE
);
6022 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
6023 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
6024 TYPE_MODE (t
) = mode
;
6025 TYPE_READONLY (t
) = TYPE_READONLY (innertype
);
6026 TYPE_VOLATILE (t
) = TYPE_VOLATILE (innertype
);
6031 tree index
= build_int_cst (NULL_TREE
, nunits
- 1);
6032 tree array
= build_array_type (innertype
, build_index_type (index
));
6033 tree rt
= make_node (RECORD_TYPE
);
6035 TYPE_FIELDS (rt
) = build_decl (FIELD_DECL
, get_identifier ("f"), array
);
6036 DECL_CONTEXT (TYPE_FIELDS (rt
)) = rt
;
6038 TYPE_DEBUG_REPRESENTATION_TYPE (t
) = rt
;
6039 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
6040 the representation type, and we want to find that die when looking up
6041 the vector type. This is most easily achieved by making the TYPE_UID
6043 TYPE_UID (rt
) = TYPE_UID (t
);
6046 /* Build our main variant, based on the main variant of the inner type. */
6047 if (TYPE_MAIN_VARIANT (innertype
) != innertype
)
6049 tree innertype_main_variant
= TYPE_MAIN_VARIANT (innertype
);
6050 unsigned int hash
= TYPE_HASH (innertype_main_variant
);
6051 TYPE_MAIN_VARIANT (t
)
6052 = type_hash_canon (hash
, make_vector_type (innertype_main_variant
,
6060 make_or_reuse_type (unsigned size
, int unsignedp
)
6062 if (size
== INT_TYPE_SIZE
)
6063 return unsignedp
? unsigned_type_node
: integer_type_node
;
6064 if (size
== CHAR_TYPE_SIZE
)
6065 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
6066 if (size
== SHORT_TYPE_SIZE
)
6067 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
6068 if (size
== LONG_TYPE_SIZE
)
6069 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
6070 if (size
== LONG_LONG_TYPE_SIZE
)
6071 return (unsignedp
? long_long_unsigned_type_node
6072 : long_long_integer_type_node
);
6075 return make_unsigned_type (size
);
6077 return make_signed_type (size
);
6080 /* Create nodes for all integer types (and error_mark_node) using the sizes
6081 of C datatypes. The caller should call set_sizetype soon after calling
6082 this function to select one of the types as sizetype. */
6085 build_common_tree_nodes (bool signed_char
, bool signed_sizetype
)
6087 error_mark_node
= make_node (ERROR_MARK
);
6088 TREE_TYPE (error_mark_node
) = error_mark_node
;
6090 initialize_sizetypes (signed_sizetype
);
6092 /* Define both `signed char' and `unsigned char'. */
6093 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
6094 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
6096 /* Define `char', which is like either `signed char' or `unsigned char'
6097 but not the same as either. */
6100 ? make_signed_type (CHAR_TYPE_SIZE
)
6101 : make_unsigned_type (CHAR_TYPE_SIZE
));
6103 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
6104 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
6105 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
6106 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
6107 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
6108 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
6109 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
6110 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
6112 /* Define a boolean type. This type only represents boolean values but
6113 may be larger than char depending on the value of BOOL_TYPE_SIZE.
6114 Front ends which want to override this size (i.e. Java) can redefine
6115 boolean_type_node before calling build_common_tree_nodes_2. */
6116 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
6117 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
6118 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
6119 TYPE_PRECISION (boolean_type_node
) = 1;
6121 /* Fill in the rest of the sized types. Reuse existing type nodes
6123 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
6124 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
6125 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
6126 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
6127 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
6129 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
6130 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
6131 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
6132 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
6133 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
6135 access_public_node
= get_identifier ("public");
6136 access_protected_node
= get_identifier ("protected");
6137 access_private_node
= get_identifier ("private");
6140 /* Call this function after calling build_common_tree_nodes and set_sizetype.
6141 It will create several other common tree nodes. */
6144 build_common_tree_nodes_2 (int short_double
)
6146 /* Define these next since types below may used them. */
6147 integer_zero_node
= build_int_cst (NULL_TREE
, 0);
6148 integer_one_node
= build_int_cst (NULL_TREE
, 1);
6149 integer_minus_one_node
= build_int_cst (NULL_TREE
, -1);
6151 size_zero_node
= size_int (0);
6152 size_one_node
= size_int (1);
6153 bitsize_zero_node
= bitsize_int (0);
6154 bitsize_one_node
= bitsize_int (1);
6155 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
6157 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
6158 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
6160 void_type_node
= make_node (VOID_TYPE
);
6161 layout_type (void_type_node
);
6163 /* We are not going to have real types in C with less than byte alignment,
6164 so we might as well not have any types that claim to have it. */
6165 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
6166 TYPE_USER_ALIGN (void_type_node
) = 0;
6168 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
6169 layout_type (TREE_TYPE (null_pointer_node
));
6171 ptr_type_node
= build_pointer_type (void_type_node
);
6173 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
6174 fileptr_type_node
= ptr_type_node
;
6176 float_type_node
= make_node (REAL_TYPE
);
6177 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
6178 layout_type (float_type_node
);
6180 double_type_node
= make_node (REAL_TYPE
);
6182 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
6184 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
6185 layout_type (double_type_node
);
6187 long_double_type_node
= make_node (REAL_TYPE
);
6188 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
6189 layout_type (long_double_type_node
);
6191 float_ptr_type_node
= build_pointer_type (float_type_node
);
6192 double_ptr_type_node
= build_pointer_type (double_type_node
);
6193 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
6194 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
6196 complex_integer_type_node
= make_node (COMPLEX_TYPE
);
6197 TREE_TYPE (complex_integer_type_node
) = integer_type_node
;
6198 layout_type (complex_integer_type_node
);
6200 complex_float_type_node
= make_node (COMPLEX_TYPE
);
6201 TREE_TYPE (complex_float_type_node
) = float_type_node
;
6202 layout_type (complex_float_type_node
);
6204 complex_double_type_node
= make_node (COMPLEX_TYPE
);
6205 TREE_TYPE (complex_double_type_node
) = double_type_node
;
6206 layout_type (complex_double_type_node
);
6208 complex_long_double_type_node
= make_node (COMPLEX_TYPE
);
6209 TREE_TYPE (complex_long_double_type_node
) = long_double_type_node
;
6210 layout_type (complex_long_double_type_node
);
6213 tree t
= targetm
.build_builtin_va_list ();
6215 /* Many back-ends define record types without setting TYPE_NAME.
6216 If we copied the record type here, we'd keep the original
6217 record type without a name. This breaks name mangling. So,
6218 don't copy record types and let c_common_nodes_and_builtins()
6219 declare the type to be __builtin_va_list. */
6220 if (TREE_CODE (t
) != RECORD_TYPE
)
6221 t
= build_variant_type_copy (t
);
6223 va_list_type_node
= t
;
6227 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
6230 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
6231 const char *library_name
, int ecf_flags
)
6235 decl
= lang_hooks
.builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
6236 library_name
, NULL_TREE
);
6237 if (ecf_flags
& ECF_CONST
)
6238 TREE_READONLY (decl
) = 1;
6239 if (ecf_flags
& ECF_PURE
)
6240 DECL_IS_PURE (decl
) = 1;
6241 if (ecf_flags
& ECF_NORETURN
)
6242 TREE_THIS_VOLATILE (decl
) = 1;
6243 if (ecf_flags
& ECF_NOTHROW
)
6244 TREE_NOTHROW (decl
) = 1;
6245 if (ecf_flags
& ECF_MALLOC
)
6246 DECL_IS_MALLOC (decl
) = 1;
6248 built_in_decls
[code
] = decl
;
6249 implicit_built_in_decls
[code
] = decl
;
6252 /* Call this function after instantiating all builtins that the language
6253 front end cares about. This will build the rest of the builtins that
6254 are relied upon by the tree optimizers and the middle-end. */
6257 build_common_builtin_nodes (void)
6261 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
6262 || built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
6264 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
6265 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
6266 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
6267 ftype
= build_function_type (ptr_type_node
, tmp
);
6269 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
)
6270 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
6271 "memcpy", ECF_NOTHROW
);
6272 if (built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
6273 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
6274 "memmove", ECF_NOTHROW
);
6277 if (built_in_decls
[BUILT_IN_MEMCMP
] == NULL
)
6279 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
6280 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
6281 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
6282 ftype
= build_function_type (integer_type_node
, tmp
);
6283 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
6284 "memcmp", ECF_PURE
| ECF_NOTHROW
);
6287 if (built_in_decls
[BUILT_IN_MEMSET
] == NULL
)
6289 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
6290 tmp
= tree_cons (NULL_TREE
, integer_type_node
, tmp
);
6291 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
6292 ftype
= build_function_type (ptr_type_node
, tmp
);
6293 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
6294 "memset", ECF_NOTHROW
);
6297 if (built_in_decls
[BUILT_IN_ALLOCA
] == NULL
)
6299 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
6300 ftype
= build_function_type (ptr_type_node
, tmp
);
6301 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
6302 "alloca", ECF_NOTHROW
| ECF_MALLOC
);
6305 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
6306 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
6307 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
6308 ftype
= build_function_type (void_type_node
, tmp
);
6309 local_define_builtin ("__builtin_init_trampoline", ftype
,
6310 BUILT_IN_INIT_TRAMPOLINE
,
6311 "__builtin_init_trampoline", ECF_NOTHROW
);
6313 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
6314 ftype
= build_function_type (ptr_type_node
, tmp
);
6315 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
6316 BUILT_IN_ADJUST_TRAMPOLINE
,
6317 "__builtin_adjust_trampoline",
6318 ECF_CONST
| ECF_NOTHROW
);
6320 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
6321 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
6322 ftype
= build_function_type (void_type_node
, tmp
);
6323 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
6324 BUILT_IN_NONLOCAL_GOTO
,
6325 "__builtin_nonlocal_goto",
6326 ECF_NORETURN
| ECF_NOTHROW
);
6328 ftype
= build_function_type (ptr_type_node
, void_list_node
);
6329 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
6330 "__builtin_stack_save", ECF_NOTHROW
);
6332 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
6333 ftype
= build_function_type (void_type_node
, tmp
);
6334 local_define_builtin ("__builtin_stack_restore", ftype
,
6335 BUILT_IN_STACK_RESTORE
,
6336 "__builtin_stack_restore", ECF_NOTHROW
);
6338 ftype
= build_function_type (void_type_node
, void_list_node
);
6339 local_define_builtin ("__builtin_profile_func_enter", ftype
,
6340 BUILT_IN_PROFILE_FUNC_ENTER
, "profile_func_enter", 0);
6341 local_define_builtin ("__builtin_profile_func_exit", ftype
,
6342 BUILT_IN_PROFILE_FUNC_EXIT
, "profile_func_exit", 0);
6344 /* Complex multiplication and division. These are handled as builtins
6345 rather than optabs because emit_library_call_value doesn't support
6346 complex. Further, we can do slightly better with folding these
6347 beasties if the real and complex parts of the arguments are separate. */
6349 enum machine_mode mode
;
6351 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
6353 char mode_name_buf
[4], *q
;
6355 enum built_in_function mcode
, dcode
;
6356 tree type
, inner_type
;
6358 type
= lang_hooks
.types
.type_for_mode (mode
, 0);
6361 inner_type
= TREE_TYPE (type
);
6363 tmp
= tree_cons (NULL_TREE
, inner_type
, void_list_node
);
6364 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
6365 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
6366 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
6367 ftype
= build_function_type (type
, tmp
);
6369 mcode
= BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
;
6370 dcode
= BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
;
6372 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
6376 built_in_names
[mcode
] = concat ("__mul", mode_name_buf
, "3", NULL
);
6377 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
6378 built_in_names
[mcode
], ECF_CONST
| ECF_NOTHROW
);
6380 built_in_names
[dcode
] = concat ("__div", mode_name_buf
, "3", NULL
);
6381 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
6382 built_in_names
[dcode
], ECF_CONST
| ECF_NOTHROW
);
6387 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
6390 If we requested a pointer to a vector, build up the pointers that
6391 we stripped off while looking for the inner type. Similarly for
6392 return values from functions.
6394 The argument TYPE is the top of the chain, and BOTTOM is the
6395 new type which we will point to. */
6398 reconstruct_complex_type (tree type
, tree bottom
)
6402 if (POINTER_TYPE_P (type
))
6404 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
6405 outer
= build_pointer_type (inner
);
6407 else if (TREE_CODE (type
) == ARRAY_TYPE
)
6409 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
6410 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
6412 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
6414 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
6415 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
6417 else if (TREE_CODE (type
) == METHOD_TYPE
)
6420 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
6421 /* The build_method_type_directly() routine prepends 'this' to argument list,
6422 so we must compensate by getting rid of it. */
6423 argtypes
= TYPE_ARG_TYPES (type
);
6424 outer
= build_method_type_directly (TYPE_METHOD_BASETYPE (type
),
6426 TYPE_ARG_TYPES (type
));
6427 TYPE_ARG_TYPES (outer
) = argtypes
;
6432 TYPE_READONLY (outer
) = TYPE_READONLY (type
);
6433 TYPE_VOLATILE (outer
) = TYPE_VOLATILE (type
);
6438 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
6441 build_vector_type_for_mode (tree innertype
, enum machine_mode mode
)
6445 switch (GET_MODE_CLASS (mode
))
6447 case MODE_VECTOR_INT
:
6448 case MODE_VECTOR_FLOAT
:
6449 nunits
= GET_MODE_NUNITS (mode
);
6453 /* Check that there are no leftover bits. */
6454 gcc_assert (GET_MODE_BITSIZE (mode
)
6455 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
6457 nunits
= GET_MODE_BITSIZE (mode
)
6458 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
6465 return make_vector_type (innertype
, nunits
, mode
);
6468 /* Similarly, but takes the inner type and number of units, which must be
6472 build_vector_type (tree innertype
, int nunits
)
6474 return make_vector_type (innertype
, nunits
, VOIDmode
);
6477 /* Build RESX_EXPR with given REGION_NUMBER. */
6479 build_resx (int region_number
)
6482 t
= build1 (RESX_EXPR
, void_type_node
,
6483 build_int_cst (NULL_TREE
, region_number
));
6487 /* Given an initializer INIT, return TRUE if INIT is zero or some
6488 aggregate of zeros. Otherwise return FALSE. */
6490 initializer_zerop (tree init
)
6496 switch (TREE_CODE (init
))
6499 return integer_zerop (init
);
6502 /* ??? Note that this is not correct for C4X float formats. There,
6503 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
6504 negative exponent. */
6505 return real_zerop (init
)
6506 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
6509 return integer_zerop (init
)
6510 || (real_zerop (init
)
6511 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
6512 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
6515 for (elt
= TREE_VECTOR_CST_ELTS (init
); elt
; elt
= TREE_CHAIN (elt
))
6516 if (!initializer_zerop (TREE_VALUE (elt
)))
6522 unsigned HOST_WIDE_INT idx
;
6524 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
6525 if (!initializer_zerop (elt
))
6536 add_var_to_bind_expr (tree bind_expr
, tree var
)
6538 BIND_EXPR_VARS (bind_expr
)
6539 = chainon (BIND_EXPR_VARS (bind_expr
), var
);
6540 if (BIND_EXPR_BLOCK (bind_expr
))
6541 BLOCK_VARS (BIND_EXPR_BLOCK (bind_expr
))
6542 = BIND_EXPR_VARS (bind_expr
);
6545 /* Build an empty statement. */
6548 build_empty_stmt (void)
6550 return build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
6554 /* Returns true if it is possible to prove that the index of
6555 an array access REF (an ARRAY_REF expression) falls into the
6559 in_array_bounds_p (tree ref
)
6561 tree idx
= TREE_OPERAND (ref
, 1);
6564 if (TREE_CODE (idx
) != INTEGER_CST
)
6567 min
= array_ref_low_bound (ref
);
6568 max
= array_ref_up_bound (ref
);
6571 || TREE_CODE (min
) != INTEGER_CST
6572 || TREE_CODE (max
) != INTEGER_CST
)
6575 if (tree_int_cst_lt (idx
, min
)
6576 || tree_int_cst_lt (max
, idx
))
6582 /* Return true if T (assumed to be a DECL) is a global variable. */
6585 is_global_var (tree t
)
6588 return (TREE_STATIC (t
) || MTAG_GLOBAL (t
));
6590 return (TREE_STATIC (t
) || DECL_EXTERNAL (t
));
6593 /* Return true if T (assumed to be a DECL) must be assigned a memory
6597 needs_to_live_in_memory (tree t
)
6599 return (TREE_ADDRESSABLE (t
)
6600 || is_global_var (t
)
6601 || (TREE_CODE (t
) == RESULT_DECL
6602 && aggregate_value_p (t
, current_function_decl
)));
6605 /* There are situations in which a language considers record types
6606 compatible which have different field lists. Decide if two fields
6607 are compatible. It is assumed that the parent records are compatible. */
6610 fields_compatible_p (tree f1
, tree f2
)
6612 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1
),
6613 DECL_FIELD_BIT_OFFSET (f2
), OEP_ONLY_CONST
))
6616 if (!operand_equal_p (DECL_FIELD_OFFSET (f1
),
6617 DECL_FIELD_OFFSET (f2
), OEP_ONLY_CONST
))
6620 if (!lang_hooks
.types_compatible_p (TREE_TYPE (f1
), TREE_TYPE (f2
)))
6626 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
6629 find_compatible_field (tree record
, tree orig_field
)
6633 for (f
= TYPE_FIELDS (record
); f
; f
= TREE_CHAIN (f
))
6634 if (TREE_CODE (f
) == FIELD_DECL
6635 && fields_compatible_p (f
, orig_field
))
6638 /* ??? Why isn't this on the main fields list? */
6639 f
= TYPE_VFIELD (record
);
6640 if (f
&& TREE_CODE (f
) == FIELD_DECL
6641 && fields_compatible_p (f
, orig_field
))
6644 /* ??? We should abort here, but Java appears to do Bad Things
6645 with inherited fields. */
6649 /* Return value of a constant X. */
6652 int_cst_value (tree x
)
6654 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
6655 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
6656 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
6658 gcc_assert (bits
<= HOST_BITS_PER_WIDE_INT
);
6661 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
6663 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
6668 /* Returns the greatest common divisor of A and B, which must be
6672 tree_fold_gcd (tree a
, tree b
)
6675 tree type
= TREE_TYPE (a
);
6677 gcc_assert (TREE_CODE (a
) == INTEGER_CST
);
6678 gcc_assert (TREE_CODE (b
) == INTEGER_CST
);
6680 if (integer_zerop (a
))
6683 if (integer_zerop (b
))
6686 if (tree_int_cst_sgn (a
) == -1)
6687 a
= fold_build2 (MULT_EXPR
, type
, a
,
6688 convert (type
, integer_minus_one_node
));
6690 if (tree_int_cst_sgn (b
) == -1)
6691 b
= fold_build2 (MULT_EXPR
, type
, b
,
6692 convert (type
, integer_minus_one_node
));
6696 a_mod_b
= fold_build2 (FLOOR_MOD_EXPR
, type
, a
, b
);
6698 if (!TREE_INT_CST_LOW (a_mod_b
)
6699 && !TREE_INT_CST_HIGH (a_mod_b
))
6707 /* Returns unsigned variant of TYPE. */
6710 unsigned_type_for (tree type
)
6712 return lang_hooks
.types
.unsigned_type (type
);
6715 /* Returns signed variant of TYPE. */
6718 signed_type_for (tree type
)
6720 return lang_hooks
.types
.signed_type (type
);
6723 /* Returns the largest value obtainable by casting something in INNER type to
6727 upper_bound_in_type (tree outer
, tree inner
)
6729 unsigned HOST_WIDE_INT lo
, hi
;
6730 unsigned int det
= 0;
6731 unsigned oprec
= TYPE_PRECISION (outer
);
6732 unsigned iprec
= TYPE_PRECISION (inner
);
6735 /* Compute a unique number for every combination. */
6736 det
|= (oprec
> iprec
) ? 4 : 0;
6737 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
6738 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
6740 /* Determine the exponent to use. */
6745 /* oprec <= iprec, outer: signed, inner: don't care. */
6750 /* oprec <= iprec, outer: unsigned, inner: don't care. */
6754 /* oprec > iprec, outer: signed, inner: signed. */
6758 /* oprec > iprec, outer: signed, inner: unsigned. */
6762 /* oprec > iprec, outer: unsigned, inner: signed. */
6766 /* oprec > iprec, outer: unsigned, inner: unsigned. */
6773 /* Compute 2^^prec - 1. */
6774 if (prec
<= HOST_BITS_PER_WIDE_INT
)
6777 lo
= ((~(unsigned HOST_WIDE_INT
) 0)
6778 >> (HOST_BITS_PER_WIDE_INT
- prec
));
6782 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
6783 >> (2 * HOST_BITS_PER_WIDE_INT
- prec
));
6784 lo
= ~(unsigned HOST_WIDE_INT
) 0;
6787 return build_int_cst_wide (outer
, lo
, hi
);
6790 /* Returns the smallest value obtainable by casting something in INNER type to
6794 lower_bound_in_type (tree outer
, tree inner
)
6796 unsigned HOST_WIDE_INT lo
, hi
;
6797 unsigned oprec
= TYPE_PRECISION (outer
);
6798 unsigned iprec
= TYPE_PRECISION (inner
);
6800 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
6802 if (TYPE_UNSIGNED (outer
)
6803 /* If we are widening something of an unsigned type, OUTER type
6804 contains all values of INNER type. In particular, both INNER
6805 and OUTER types have zero in common. */
6806 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
6810 /* If we are widening a signed type to another signed type, we
6811 want to obtain -2^^(iprec-1). If we are keeping the
6812 precision or narrowing to a signed type, we want to obtain
6814 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
6816 if (prec
<= HOST_BITS_PER_WIDE_INT
)
6818 hi
= ~(unsigned HOST_WIDE_INT
) 0;
6819 lo
= (~(unsigned HOST_WIDE_INT
) 0) << (prec
- 1);
6823 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
6824 << (prec
- HOST_BITS_PER_WIDE_INT
- 1));
6829 return build_int_cst_wide (outer
, lo
, hi
);
6832 /* Return nonzero if two operands that are suitable for PHI nodes are
6833 necessarily equal. Specifically, both ARG0 and ARG1 must be either
6834 SSA_NAME or invariant. Note that this is strictly an optimization.
6835 That is, callers of this function can directly call operand_equal_p
6836 and get the same result, only slower. */
6839 operand_equal_for_phi_arg_p (tree arg0
, tree arg1
)
6843 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
6845 return operand_equal_p (arg0
, arg1
, 0);
6848 /* Returns number of zeros at the end of binary representation of X.
6850 ??? Use ffs if available? */
6853 num_ending_zeros (tree x
)
6855 unsigned HOST_WIDE_INT fr
, nfr
;
6856 unsigned num
, abits
;
6857 tree type
= TREE_TYPE (x
);
6859 if (TREE_INT_CST_LOW (x
) == 0)
6861 num
= HOST_BITS_PER_WIDE_INT
;
6862 fr
= TREE_INT_CST_HIGH (x
);
6867 fr
= TREE_INT_CST_LOW (x
);
6870 for (abits
= HOST_BITS_PER_WIDE_INT
/ 2; abits
; abits
/= 2)
6873 if (nfr
<< abits
== fr
)
6880 if (num
> TYPE_PRECISION (type
))
6881 num
= TYPE_PRECISION (type
);
6883 return build_int_cst_type (type
, num
);
6887 #define WALK_SUBTREE(NODE) \
6890 result = walk_tree (&(NODE), func, data, pset); \
6896 /* This is a subroutine of walk_tree that walks field of TYPE that are to
6897 be walked whenever a type is seen in the tree. Rest of operands and return
6898 value are as for walk_tree. */
6901 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
6902 struct pointer_set_t
*pset
)
6904 tree result
= NULL_TREE
;
6906 switch (TREE_CODE (type
))
6909 case REFERENCE_TYPE
:
6910 /* We have to worry about mutually recursive pointers. These can't
6911 be written in C. They can in Ada. It's pathological, but
6912 there's an ACATS test (c38102a) that checks it. Deal with this
6913 by checking if we're pointing to another pointer, that one
6914 points to another pointer, that one does too, and we have no htab.
6915 If so, get a hash table. We check three levels deep to avoid
6916 the cost of the hash table if we don't need one. */
6917 if (POINTER_TYPE_P (TREE_TYPE (type
))
6918 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
6919 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
6922 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
6930 /* ... fall through ... */
6933 WALK_SUBTREE (TREE_TYPE (type
));
6937 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
6942 WALK_SUBTREE (TREE_TYPE (type
));
6946 /* We never want to walk into default arguments. */
6947 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
6948 WALK_SUBTREE (TREE_VALUE (arg
));
6953 /* Don't follow this nodes's type if a pointer for fear that we'll
6954 have infinite recursion. Those types are uninteresting anyway. */
6955 if (!POINTER_TYPE_P (TREE_TYPE (type
))
6956 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
)
6957 WALK_SUBTREE (TREE_TYPE (type
));
6958 WALK_SUBTREE (TYPE_DOMAIN (type
));
6966 WALK_SUBTREE (TYPE_MIN_VALUE (type
));
6967 WALK_SUBTREE (TYPE_MAX_VALUE (type
));
6971 WALK_SUBTREE (TREE_TYPE (type
));
6972 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
6982 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
6983 called with the DATA and the address of each sub-tree. If FUNC returns a
6984 non-NULL value, the traversal is stopped, and the value returned by FUNC
6985 is returned. If PSET is non-NULL it is used to record the nodes visited,
6986 and to avoid visiting a node more than once. */
6989 walk_tree (tree
*tp
, walk_tree_fn func
, void *data
, struct pointer_set_t
*pset
)
6991 enum tree_code code
;
6995 #define WALK_SUBTREE_TAIL(NODE) \
6999 goto tail_recurse; \
7004 /* Skip empty subtrees. */
7008 /* Don't walk the same tree twice, if the user has requested
7009 that we avoid doing so. */
7010 if (pset
&& pointer_set_insert (pset
, *tp
))
7013 /* Call the function. */
7015 result
= (*func
) (tp
, &walk_subtrees
, data
);
7017 /* If we found something, return it. */
7021 code
= TREE_CODE (*tp
);
7023 /* Even if we didn't, FUNC may have decided that there was nothing
7024 interesting below this point in the tree. */
7027 if (code
== TREE_LIST
)
7028 /* But we still need to check our siblings. */
7029 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
7034 result
= lang_hooks
.tree_inlining
.walk_subtrees (tp
, &walk_subtrees
, func
,
7036 if (result
|| ! walk_subtrees
)
7039 /* If this is a DECL_EXPR, walk into various fields of the type that it's
7040 defining. We only want to walk into these fields of a type in this
7041 case. Note that decls get walked as part of the processing of a
7044 ??? Precisely which fields of types that we are supposed to walk in
7045 this case vs. the normal case aren't well defined. */
7046 if (code
== DECL_EXPR
7047 && TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
7048 && TREE_CODE (TREE_TYPE (DECL_EXPR_DECL (*tp
))) != ERROR_MARK
)
7050 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
7052 /* Call the function for the type. See if it returns anything or
7053 doesn't want us to continue. If we are to continue, walk both
7054 the normal fields and those for the declaration case. */
7055 result
= (*func
) (type_p
, &walk_subtrees
, data
);
7056 if (result
|| !walk_subtrees
)
7059 result
= walk_type_fields (*type_p
, func
, data
, pset
);
7063 WALK_SUBTREE (TYPE_SIZE (*type_p
));
7064 WALK_SUBTREE (TYPE_SIZE_UNIT (*type_p
));
7066 /* If this is a record type, also walk the fields. */
7067 if (TREE_CODE (*type_p
) == RECORD_TYPE
7068 || TREE_CODE (*type_p
) == UNION_TYPE
7069 || TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
7073 for (field
= TYPE_FIELDS (*type_p
); field
;
7074 field
= TREE_CHAIN (field
))
7076 /* We'd like to look at the type of the field, but we can easily
7077 get infinite recursion. So assume it's pointed to elsewhere
7078 in the tree. Also, ignore things that aren't fields. */
7079 if (TREE_CODE (field
) != FIELD_DECL
)
7082 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
7083 WALK_SUBTREE (DECL_SIZE (field
));
7084 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
7085 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
7086 WALK_SUBTREE (DECL_QUALIFIER (field
));
7091 else if (code
!= SAVE_EXPR
7092 && code
!= BIND_EXPR
7093 && IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
)))
7097 /* Walk over all the sub-trees of this operand. */
7098 len
= TREE_CODE_LENGTH (code
);
7099 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
7100 But, we only want to walk once. */
7101 if (code
== TARGET_EXPR
7102 && TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1))
7105 /* Go through the subtrees. We need to do this in forward order so
7106 that the scope of a FOR_EXPR is handled properly. */
7107 #ifdef DEBUG_WALK_TREE
7108 for (i
= 0; i
< len
; ++i
)
7109 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
7111 for (i
= 0; i
< len
- 1; ++i
)
7112 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
7116 /* The common case is that we may tail recurse here. */
7117 if (code
!= BIND_EXPR
7118 && !TREE_CHAIN (*tp
))
7119 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
- 1));
7121 WALK_SUBTREE (TREE_OPERAND (*tp
, len
- 1));
7126 /* If this is a type, walk the needed fields in the type. */
7127 else if (TYPE_P (*tp
))
7129 result
= walk_type_fields (*tp
, func
, data
, pset
);
7135 /* Not one of the easy cases. We must explicitly go through the
7140 case IDENTIFIER_NODE
:
7146 case PLACEHOLDER_EXPR
:
7150 /* None of these have subtrees other than those already walked
7155 WALK_SUBTREE (TREE_VALUE (*tp
));
7156 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
7161 int len
= TREE_VEC_LENGTH (*tp
);
7166 /* Walk all elements but the first. */
7168 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
7170 /* Now walk the first one as a tail call. */
7171 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
7175 WALK_SUBTREE (TREE_REALPART (*tp
));
7176 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
7180 unsigned HOST_WIDE_INT idx
;
7181 constructor_elt
*ce
;
7184 VEC_iterate(constructor_elt
, CONSTRUCTOR_ELTS (*tp
), idx
, ce
);
7186 WALK_SUBTREE (ce
->value
);
7191 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
7196 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= TREE_CHAIN (decl
))
7198 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
7199 into declarations that are just mentioned, rather than
7200 declared; they don't really belong to this part of the tree.
7201 And, we can see cycles: the initializer for a declaration
7202 can refer to the declaration itself. */
7203 WALK_SUBTREE (DECL_INITIAL (decl
));
7204 WALK_SUBTREE (DECL_SIZE (decl
));
7205 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
7207 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
7210 case STATEMENT_LIST
:
7212 tree_stmt_iterator i
;
7213 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
7214 WALK_SUBTREE (*tsi_stmt_ptr (i
));
7219 /* ??? This could be a language-defined node. We really should make
7220 a hook for it, but right now just ignore it. */
7225 /* We didn't find what we were looking for. */
7228 #undef WALK_SUBTREE_TAIL
7232 /* Like walk_tree, but does not walk duplicate nodes more than once. */
7235 walk_tree_without_duplicates (tree
*tp
, walk_tree_fn func
, void *data
)
7238 struct pointer_set_t
*pset
;
7240 pset
= pointer_set_create ();
7241 result
= walk_tree (tp
, func
, data
, pset
);
7242 pointer_set_destroy (pset
);
7246 #include "gt-tree.h"