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, 2006
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
23 /* This file contains the low level primitives for operating on tree nodes,
24 including allocation, list operations, interning of identifiers,
25 construction of data type nodes and statement nodes,
26 and construction of type conversion nodes. It also contains
27 tables index by tree code that describe how to take apart
30 It is intended to be language-independent, but occasionally
31 calls language-dependent routines defined (for C) in typecheck.c. */
35 #include "coretypes.h"
48 #include "langhooks.h"
49 #include "tree-iterator.h"
50 #include "basic-block.h"
51 #include "tree-flow.h"
53 #include "pointer-set.h"
55 /* Each tree code class has an associated string representation.
56 These must correspond to the tree_code_class entries. */
58 const char *const tree_code_class_strings
[] =
72 /* obstack.[ch] explicitly declined to prototype this. */
73 extern int _obstack_allocated_p (struct obstack
*h
, void *obj
);
75 #ifdef GATHER_STATISTICS
76 /* Statistics-gathering stuff. */
78 int tree_node_counts
[(int) all_kinds
];
79 int tree_node_sizes
[(int) all_kinds
];
81 /* Keep in sync with tree.h:enum tree_node_kind. */
82 static const char * const tree_node_kind_names
[] = {
104 #endif /* GATHER_STATISTICS */
106 /* Unique id for next decl created. */
107 static GTY(()) int next_decl_uid
;
108 /* Unique id for next type created. */
109 static GTY(()) int next_type_uid
= 1;
111 /* Since we cannot rehash a type after it is in the table, we have to
112 keep the hash code. */
114 struct type_hash
GTY(())
120 /* Initial size of the hash table (rounded to next prime). */
121 #define TYPE_HASH_INITIAL_SIZE 1000
123 /* Now here is the hash table. When recording a type, it is added to
124 the slot whose index is the hash code. Note that the hash table is
125 used for several kinds of types (function types, array types and
126 array index range types, for now). While all these live in the
127 same table, they are completely independent, and the hash code is
128 computed differently for each of these. */
130 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash
)))
131 htab_t type_hash_table
;
133 /* Hash table and temporary node for larger integer const values. */
134 static GTY (()) tree int_cst_node
;
135 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
136 htab_t int_cst_hash_table
;
138 /* General tree->tree mapping structure for use in hash tables. */
141 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
142 htab_t debug_expr_for_decl
;
144 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
145 htab_t value_expr_for_decl
;
147 static GTY ((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map
)))
148 htab_t init_priority_for_decl
;
150 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
151 htab_t restrict_base_for_decl
;
153 struct tree_int_map
GTY(())
158 static unsigned int tree_int_map_hash (const void *);
159 static int tree_int_map_eq (const void *, const void *);
160 static int tree_int_map_marked_p (const void *);
161 static void set_type_quals (tree
, int);
162 static int type_hash_eq (const void *, const void *);
163 static hashval_t
type_hash_hash (const void *);
164 static hashval_t
int_cst_hash_hash (const void *);
165 static int int_cst_hash_eq (const void *, const void *);
166 static void print_type_hash_statistics (void);
167 static void print_debug_expr_statistics (void);
168 static void print_value_expr_statistics (void);
169 static int type_hash_marked_p (const void *);
170 static unsigned int type_hash_list (tree
, hashval_t
);
171 static unsigned int attribute_hash_list (tree
, hashval_t
);
173 tree global_trees
[TI_MAX
];
174 tree integer_types
[itk_none
];
176 unsigned char tree_contains_struct
[256][64];
178 /* Number of operands for each OpenMP clause. */
179 unsigned const char omp_clause_num_ops
[] =
181 0, /* OMP_CLAUSE_ERROR */
182 1, /* OMP_CLAUSE_PRIVATE */
183 1, /* OMP_CLAUSE_SHARED */
184 1, /* OMP_CLAUSE_FIRSTPRIVATE */
185 1, /* OMP_CLAUSE_LASTPRIVATE */
186 4, /* OMP_CLAUSE_REDUCTION */
187 1, /* OMP_CLAUSE_COPYIN */
188 1, /* OMP_CLAUSE_COPYPRIVATE */
189 1, /* OMP_CLAUSE_IF */
190 1, /* OMP_CLAUSE_NUM_THREADS */
191 1, /* OMP_CLAUSE_SCHEDULE */
192 0, /* OMP_CLAUSE_NOWAIT */
193 0, /* OMP_CLAUSE_ORDERED */
194 0 /* OMP_CLAUSE_DEFAULT */
197 const char * const omp_clause_code_name
[] =
220 /* Initialize the hash table of types. */
221 type_hash_table
= htab_create_ggc (TYPE_HASH_INITIAL_SIZE
, type_hash_hash
,
224 debug_expr_for_decl
= htab_create_ggc (512, tree_map_hash
,
227 value_expr_for_decl
= htab_create_ggc (512, tree_map_hash
,
229 init_priority_for_decl
= htab_create_ggc (512, tree_int_map_hash
,
231 restrict_base_for_decl
= htab_create_ggc (256, tree_map_hash
,
234 int_cst_hash_table
= htab_create_ggc (1024, int_cst_hash_hash
,
235 int_cst_hash_eq
, NULL
);
237 int_cst_node
= make_node (INTEGER_CST
);
239 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
] = 1;
240 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_NON_COMMON
] = 1;
241 tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
] = 1;
244 tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
] = 1;
245 tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
] = 1;
246 tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
] = 1;
247 tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
] = 1;
248 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
] = 1;
249 tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
] = 1;
250 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
] = 1;
251 tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
] = 1;
252 tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
] = 1;
255 tree_contains_struct
[CONST_DECL
][TS_DECL_WRTL
] = 1;
256 tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
] = 1;
257 tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
] = 1;
258 tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
] = 1;
259 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
] = 1;
260 tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
] = 1;
262 tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
] = 1;
263 tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
] = 1;
264 tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
] = 1;
265 tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
] = 1;
266 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
] = 1;
267 tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
] = 1;
268 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
] = 1;
269 tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
] = 1;
270 tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
] = 1;
271 tree_contains_struct
[STRUCT_FIELD_TAG
][TS_DECL_MINIMAL
] = 1;
272 tree_contains_struct
[NAME_MEMORY_TAG
][TS_DECL_MINIMAL
] = 1;
273 tree_contains_struct
[SYMBOL_MEMORY_TAG
][TS_DECL_MINIMAL
] = 1;
274 tree_contains_struct
[MEMORY_PARTITION_TAG
][TS_DECL_MINIMAL
] = 1;
276 tree_contains_struct
[STRUCT_FIELD_TAG
][TS_MEMORY_TAG
] = 1;
277 tree_contains_struct
[NAME_MEMORY_TAG
][TS_MEMORY_TAG
] = 1;
278 tree_contains_struct
[SYMBOL_MEMORY_TAG
][TS_MEMORY_TAG
] = 1;
279 tree_contains_struct
[MEMORY_PARTITION_TAG
][TS_MEMORY_TAG
] = 1;
281 tree_contains_struct
[STRUCT_FIELD_TAG
][TS_STRUCT_FIELD_TAG
] = 1;
282 tree_contains_struct
[MEMORY_PARTITION_TAG
][TS_MEMORY_PARTITION_TAG
] = 1;
284 tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
] = 1;
285 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
] = 1;
286 tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
] = 1;
287 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_WITH_VIS
] = 1;
289 tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
] = 1;
290 tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
] = 1;
291 tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
] = 1;
292 tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
] = 1;
293 tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
] = 1;
294 tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
] = 1;
295 tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
] = 1;
296 tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
] = 1;
298 lang_hooks
.init_ts ();
302 /* The name of the object as the assembler will see it (but before any
303 translations made by ASM_OUTPUT_LABELREF). Often this is the same
304 as DECL_NAME. It is an IDENTIFIER_NODE. */
306 decl_assembler_name (tree decl
)
308 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
309 lang_hooks
.set_decl_assembler_name (decl
);
310 return DECL_WITH_VIS_CHECK (decl
)->decl_with_vis
.assembler_name
;
313 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
316 decl_assembler_name_equal (tree decl
, tree asmname
)
318 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
320 if (decl_asmname
== asmname
)
323 /* If the target assembler name was set by the user, things are trickier.
324 We have a leading '*' to begin with. After that, it's arguable what
325 is the correct thing to do with -fleading-underscore. Arguably, we've
326 historically been doing the wrong thing in assemble_alias by always
327 printing the leading underscore. Since we're not changing that, make
328 sure user_label_prefix follows the '*' before matching. */
329 if (IDENTIFIER_POINTER (decl_asmname
)[0] == '*')
331 const char *decl_str
= IDENTIFIER_POINTER (decl_asmname
) + 1;
332 size_t ulp_len
= strlen (user_label_prefix
);
336 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
341 return strcmp (decl_str
, IDENTIFIER_POINTER (asmname
)) == 0;
347 /* Compute the number of bytes occupied by a tree with code CODE.
348 This function cannot be used for TREE_VEC, PHI_NODE, or STRING_CST
349 codes, which are of variable length. */
351 tree_code_size (enum tree_code code
)
353 switch (TREE_CODE_CLASS (code
))
355 case tcc_declaration
: /* A decl node */
360 return sizeof (struct tree_field_decl
);
362 return sizeof (struct tree_parm_decl
);
364 return sizeof (struct tree_var_decl
);
366 return sizeof (struct tree_label_decl
);
368 return sizeof (struct tree_result_decl
);
370 return sizeof (struct tree_const_decl
);
372 return sizeof (struct tree_type_decl
);
374 return sizeof (struct tree_function_decl
);
375 case NAME_MEMORY_TAG
:
376 case SYMBOL_MEMORY_TAG
:
377 return sizeof (struct tree_memory_tag
);
378 case STRUCT_FIELD_TAG
:
379 return sizeof (struct tree_struct_field_tag
);
380 case MEMORY_PARTITION_TAG
:
381 return sizeof (struct tree_memory_partition_tag
);
383 return sizeof (struct tree_decl_non_common
);
387 case tcc_type
: /* a type node */
388 return sizeof (struct tree_type
);
390 case tcc_reference
: /* a reference */
391 case tcc_expression
: /* an expression */
392 case tcc_statement
: /* an expression with side effects */
393 case tcc_comparison
: /* a comparison expression */
394 case tcc_unary
: /* a unary arithmetic expression */
395 case tcc_binary
: /* a binary arithmetic expression */
396 return (sizeof (struct tree_exp
)
397 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (char *));
399 case tcc_gimple_stmt
:
400 return (sizeof (struct gimple_stmt
)
401 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (char *));
403 case tcc_constant
: /* a constant */
406 case INTEGER_CST
: return sizeof (struct tree_int_cst
);
407 case REAL_CST
: return sizeof (struct tree_real_cst
);
408 case COMPLEX_CST
: return sizeof (struct tree_complex
);
409 case VECTOR_CST
: return sizeof (struct tree_vector
);
410 case STRING_CST
: gcc_unreachable ();
412 return lang_hooks
.tree_size (code
);
415 case tcc_exceptional
: /* something random, like an identifier. */
418 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
419 case TREE_LIST
: return sizeof (struct tree_list
);
422 case PLACEHOLDER_EXPR
: return sizeof (struct tree_common
);
426 case PHI_NODE
: gcc_unreachable ();
428 case SSA_NAME
: return sizeof (struct tree_ssa_name
);
430 case STATEMENT_LIST
: return sizeof (struct tree_statement_list
);
431 case BLOCK
: return sizeof (struct tree_block
);
432 case VALUE_HANDLE
: return sizeof (struct tree_value_handle
);
433 case CONSTRUCTOR
: return sizeof (struct tree_constructor
);
436 return lang_hooks
.tree_size (code
);
444 /* Compute the number of bytes occupied by NODE. This routine only
445 looks at TREE_CODE, except for PHI_NODE and TREE_VEC nodes. */
447 tree_size (tree node
)
449 enum tree_code code
= TREE_CODE (node
);
453 return (sizeof (struct tree_phi_node
)
454 + (PHI_ARG_CAPACITY (node
) - 1) * sizeof (struct phi_arg_d
));
457 return (offsetof (struct tree_binfo
, base_binfos
)
458 + VEC_embedded_size (tree
, BINFO_N_BASE_BINFOS (node
)));
461 return (sizeof (struct tree_vec
)
462 + (TREE_VEC_LENGTH (node
) - 1) * sizeof(char *));
465 return TREE_STRING_LENGTH (node
) + offsetof (struct tree_string
, str
) + 1;
468 return (sizeof (struct tree_omp_clause
)
469 + (omp_clause_num_ops
[OMP_CLAUSE_CODE (node
)] - 1)
473 return tree_code_size (code
);
477 /* Return a newly allocated node of code CODE. For decl and type
478 nodes, some other fields are initialized. The rest of the node is
479 initialized to zero. This function cannot be used for PHI_NODE,
480 TREE_VEC or OMP_CLAUSE nodes, which is enforced by asserts in
483 Achoo! I got a code in the node. */
486 make_node_stat (enum tree_code code MEM_STAT_DECL
)
489 enum tree_code_class type
= TREE_CODE_CLASS (code
);
490 size_t length
= tree_code_size (code
);
491 #ifdef GATHER_STATISTICS
496 case tcc_declaration
: /* A decl node */
500 case tcc_type
: /* a type node */
504 case tcc_statement
: /* an expression with side effects */
508 case tcc_reference
: /* a reference */
512 case tcc_expression
: /* an expression */
513 case tcc_comparison
: /* a comparison expression */
514 case tcc_unary
: /* a unary arithmetic expression */
515 case tcc_binary
: /* a binary arithmetic expression */
519 case tcc_constant
: /* a constant */
523 case tcc_gimple_stmt
:
524 kind
= gimple_stmt_kind
;
527 case tcc_exceptional
: /* something random, like an identifier. */
530 case IDENTIFIER_NODE
:
547 kind
= ssa_name_kind
;
568 tree_node_counts
[(int) kind
]++;
569 tree_node_sizes
[(int) kind
] += length
;
572 if (code
== IDENTIFIER_NODE
)
573 t
= ggc_alloc_zone_pass_stat (length
, &tree_id_zone
);
575 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
577 memset (t
, 0, length
);
579 TREE_SET_CODE (t
, code
);
584 TREE_SIDE_EFFECTS (t
) = 1;
587 case tcc_declaration
:
588 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
589 DECL_IN_SYSTEM_HEADER (t
) = in_system_header
;
590 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
592 if (code
!= FUNCTION_DECL
)
594 DECL_USER_ALIGN (t
) = 0;
595 /* We have not yet computed the alias set for this declaration. */
596 DECL_POINTER_ALIAS_SET (t
) = -1;
598 DECL_SOURCE_LOCATION (t
) = input_location
;
599 DECL_UID (t
) = next_decl_uid
++;
604 TYPE_UID (t
) = next_type_uid
++;
605 TYPE_ALIGN (t
) = BITS_PER_UNIT
;
606 TYPE_USER_ALIGN (t
) = 0;
607 TYPE_MAIN_VARIANT (t
) = t
;
608 TYPE_CANONICAL (t
) = t
;
610 /* Default to no attributes for type, but let target change that. */
611 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
612 targetm
.set_default_type_attributes (t
);
614 /* We have not yet computed the alias set for this type. */
615 TYPE_ALIAS_SET (t
) = -1;
619 TREE_CONSTANT (t
) = 1;
620 TREE_INVARIANT (t
) = 1;
629 case PREDECREMENT_EXPR
:
630 case PREINCREMENT_EXPR
:
631 case POSTDECREMENT_EXPR
:
632 case POSTINCREMENT_EXPR
:
633 /* All of these have side-effects, no matter what their
635 TREE_SIDE_EFFECTS (t
) = 1;
643 case tcc_gimple_stmt
:
646 case GIMPLE_MODIFY_STMT
:
647 TREE_SIDE_EFFECTS (t
) = 1;
655 /* Other classes need no special treatment. */
662 /* Return a new node with the same contents as NODE except that its
663 TREE_CHAIN is zero and it has a fresh uid. */
666 copy_node_stat (tree node MEM_STAT_DECL
)
669 enum tree_code code
= TREE_CODE (node
);
672 gcc_assert (code
!= STATEMENT_LIST
);
674 length
= tree_size (node
);
675 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
676 memcpy (t
, node
, length
);
678 if (!GIMPLE_TUPLE_P (node
))
680 TREE_ASM_WRITTEN (t
) = 0;
681 TREE_VISITED (t
) = 0;
684 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
686 DECL_UID (t
) = next_decl_uid
++;
687 if ((TREE_CODE (node
) == PARM_DECL
|| TREE_CODE (node
) == VAR_DECL
)
688 && DECL_HAS_VALUE_EXPR_P (node
))
690 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
691 DECL_HAS_VALUE_EXPR_P (t
) = 1;
693 if (TREE_CODE (node
) == VAR_DECL
&& DECL_HAS_INIT_PRIORITY_P (node
))
695 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
696 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
698 if (TREE_CODE (node
) == VAR_DECL
&& DECL_BASED_ON_RESTRICT_P (node
))
700 SET_DECL_RESTRICT_BASE (t
, DECL_GET_RESTRICT_BASE (node
));
701 DECL_BASED_ON_RESTRICT_P (t
) = 1;
704 else if (TREE_CODE_CLASS (code
) == tcc_type
)
706 TYPE_UID (t
) = next_type_uid
++;
707 /* The following is so that the debug code for
708 the copy is different from the original type.
709 The two statements usually duplicate each other
710 (because they clear fields of the same union),
711 but the optimizer should catch that. */
712 TYPE_SYMTAB_POINTER (t
) = 0;
713 TYPE_SYMTAB_ADDRESS (t
) = 0;
715 /* Do not copy the values cache. */
716 if (TYPE_CACHED_VALUES_P(t
))
718 TYPE_CACHED_VALUES_P (t
) = 0;
719 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
726 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
727 For example, this can copy a list made of TREE_LIST nodes. */
730 copy_list (tree list
)
738 head
= prev
= copy_node (list
);
739 next
= TREE_CHAIN (list
);
742 TREE_CHAIN (prev
) = copy_node (next
);
743 prev
= TREE_CHAIN (prev
);
744 next
= TREE_CHAIN (next
);
750 /* Create an INT_CST node with a LOW value sign extended. */
753 build_int_cst (tree type
, HOST_WIDE_INT low
)
755 return build_int_cst_wide (type
, low
, low
< 0 ? -1 : 0);
758 /* Create an INT_CST node with a LOW value zero extended. */
761 build_int_cstu (tree type
, unsigned HOST_WIDE_INT low
)
763 return build_int_cst_wide (type
, low
, 0);
766 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
767 if it is negative. This function is similar to build_int_cst, but
768 the extra bits outside of the type precision are cleared. Constants
769 with these extra bits may confuse the fold so that it detects overflows
770 even in cases when they do not occur, and in general should be avoided.
771 We cannot however make this a default behavior of build_int_cst without
772 more intrusive changes, since there are parts of gcc that rely on the extra
773 precision of the integer constants. */
776 build_int_cst_type (tree type
, HOST_WIDE_INT low
)
778 unsigned HOST_WIDE_INT val
= (unsigned HOST_WIDE_INT
) low
;
779 unsigned HOST_WIDE_INT hi
, mask
;
785 type
= integer_type_node
;
787 bits
= TYPE_PRECISION (type
);
788 signed_p
= !TYPE_UNSIGNED (type
);
790 if (bits
>= HOST_BITS_PER_WIDE_INT
)
791 negative
= (low
< 0);
794 /* If the sign bit is inside precision of LOW, use it to determine
795 the sign of the constant. */
796 negative
= ((val
>> (bits
- 1)) & 1) != 0;
798 /* Mask out the bits outside of the precision of the constant. */
799 mask
= (((unsigned HOST_WIDE_INT
) 2) << (bits
- 1)) - 1;
801 if (signed_p
&& negative
)
807 /* Determine the high bits. */
808 hi
= (negative
? ~(unsigned HOST_WIDE_INT
) 0 : 0);
810 /* For unsigned type we need to mask out the bits outside of the type
814 if (bits
<= HOST_BITS_PER_WIDE_INT
)
818 bits
-= HOST_BITS_PER_WIDE_INT
;
819 mask
= (((unsigned HOST_WIDE_INT
) 2) << (bits
- 1)) - 1;
824 return build_int_cst_wide (type
, val
, hi
);
827 /* These are the hash table functions for the hash table of INTEGER_CST
828 nodes of a sizetype. */
830 /* Return the hash code code X, an INTEGER_CST. */
833 int_cst_hash_hash (const void *x
)
837 return (TREE_INT_CST_HIGH (t
) ^ TREE_INT_CST_LOW (t
)
838 ^ htab_hash_pointer (TREE_TYPE (t
)));
841 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
842 is the same as that given by *Y, which is the same. */
845 int_cst_hash_eq (const void *x
, const void *y
)
850 return (TREE_TYPE (xt
) == TREE_TYPE (yt
)
851 && TREE_INT_CST_HIGH (xt
) == TREE_INT_CST_HIGH (yt
)
852 && TREE_INT_CST_LOW (xt
) == TREE_INT_CST_LOW (yt
));
855 /* Create an INT_CST node of TYPE and value HI:LOW. If TYPE is NULL,
856 integer_type_node is used. The returned node is always shared.
857 For small integers we use a per-type vector cache, for larger ones
858 we use a single hash table. */
861 build_int_cst_wide (tree type
, unsigned HOST_WIDE_INT low
, HOST_WIDE_INT hi
)
868 type
= integer_type_node
;
870 switch (TREE_CODE (type
))
874 /* Cache NULL pointer. */
883 /* Cache false or true. */
891 if (TYPE_UNSIGNED (type
))
894 limit
= INTEGER_SHARE_LIMIT
;
895 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
901 limit
= INTEGER_SHARE_LIMIT
+ 1;
902 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
904 else if (hi
== -1 && low
== -(unsigned HOST_WIDE_INT
)1)
918 /* Look for it in the type's vector of small shared ints. */
919 if (!TYPE_CACHED_VALUES_P (type
))
921 TYPE_CACHED_VALUES_P (type
) = 1;
922 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
925 t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
);
928 /* Make sure no one is clobbering the shared constant. */
929 gcc_assert (TREE_TYPE (t
) == type
);
930 gcc_assert (TREE_INT_CST_LOW (t
) == low
);
931 gcc_assert (TREE_INT_CST_HIGH (t
) == hi
);
935 /* Create a new shared int. */
936 t
= make_node (INTEGER_CST
);
938 TREE_INT_CST_LOW (t
) = low
;
939 TREE_INT_CST_HIGH (t
) = hi
;
940 TREE_TYPE (t
) = type
;
942 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
947 /* Use the cache of larger shared ints. */
950 TREE_INT_CST_LOW (int_cst_node
) = low
;
951 TREE_INT_CST_HIGH (int_cst_node
) = hi
;
952 TREE_TYPE (int_cst_node
) = type
;
954 slot
= htab_find_slot (int_cst_hash_table
, int_cst_node
, INSERT
);
958 /* Insert this one into the hash table. */
961 /* Make a new node for next time round. */
962 int_cst_node
= make_node (INTEGER_CST
);
969 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
970 and the rest are zeros. */
973 build_low_bits_mask (tree type
, unsigned bits
)
975 unsigned HOST_WIDE_INT low
;
977 unsigned HOST_WIDE_INT all_ones
= ~(unsigned HOST_WIDE_INT
) 0;
979 gcc_assert (bits
<= TYPE_PRECISION (type
));
981 if (bits
== TYPE_PRECISION (type
)
982 && !TYPE_UNSIGNED (type
))
984 /* Sign extended all-ones mask. */
988 else if (bits
<= HOST_BITS_PER_WIDE_INT
)
990 low
= all_ones
>> (HOST_BITS_PER_WIDE_INT
- bits
);
995 bits
-= HOST_BITS_PER_WIDE_INT
;
997 high
= all_ones
>> (HOST_BITS_PER_WIDE_INT
- bits
);
1000 return build_int_cst_wide (type
, low
, high
);
1003 /* Checks that X is integer constant that can be expressed in (unsigned)
1004 HOST_WIDE_INT without loss of precision. */
1007 cst_and_fits_in_hwi (tree x
)
1009 if (TREE_CODE (x
) != INTEGER_CST
)
1012 if (TYPE_PRECISION (TREE_TYPE (x
)) > HOST_BITS_PER_WIDE_INT
)
1015 return (TREE_INT_CST_HIGH (x
) == 0
1016 || TREE_INT_CST_HIGH (x
) == -1);
1019 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1020 are in a list pointed to by VALS. */
1023 build_vector (tree type
, tree vals
)
1025 tree v
= make_node (VECTOR_CST
);
1026 int over1
= 0, over2
= 0;
1029 TREE_VECTOR_CST_ELTS (v
) = vals
;
1030 TREE_TYPE (v
) = type
;
1032 /* Iterate through elements and check for overflow. */
1033 for (link
= vals
; link
; link
= TREE_CHAIN (link
))
1035 tree value
= TREE_VALUE (link
);
1037 /* Don't crash if we get an address constant. */
1038 if (!CONSTANT_CLASS_P (value
))
1041 over1
|= TREE_OVERFLOW (value
);
1042 over2
|= TREE_CONSTANT_OVERFLOW (value
);
1045 TREE_OVERFLOW (v
) = over1
;
1046 TREE_CONSTANT_OVERFLOW (v
) = over2
;
1051 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1052 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1055 build_vector_from_ctor (tree type
, VEC(constructor_elt
,gc
) *v
)
1057 tree list
= NULL_TREE
;
1058 unsigned HOST_WIDE_INT idx
;
1061 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1062 list
= tree_cons (NULL_TREE
, value
, list
);
1063 return build_vector (type
, nreverse (list
));
1066 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1067 are in the VEC pointed to by VALS. */
1069 build_constructor (tree type
, VEC(constructor_elt
,gc
) *vals
)
1071 tree c
= make_node (CONSTRUCTOR
);
1072 TREE_TYPE (c
) = type
;
1073 CONSTRUCTOR_ELTS (c
) = vals
;
1077 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1080 build_constructor_single (tree type
, tree index
, tree value
)
1082 VEC(constructor_elt
,gc
) *v
;
1083 constructor_elt
*elt
;
1086 v
= VEC_alloc (constructor_elt
, gc
, 1);
1087 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
1091 t
= build_constructor (type
, v
);
1092 TREE_CONSTANT (t
) = TREE_CONSTANT (value
);
1097 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1098 are in a list pointed to by VALS. */
1100 build_constructor_from_list (tree type
, tree vals
)
1103 VEC(constructor_elt
,gc
) *v
= NULL
;
1104 bool constant_p
= true;
1108 v
= VEC_alloc (constructor_elt
, gc
, list_length (vals
));
1109 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
1111 constructor_elt
*elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
1112 val
= TREE_VALUE (t
);
1113 elt
->index
= TREE_PURPOSE (t
);
1115 if (!TREE_CONSTANT (val
))
1120 t
= build_constructor (type
, v
);
1121 TREE_CONSTANT (t
) = constant_p
;
1126 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1129 build_real (tree type
, REAL_VALUE_TYPE d
)
1132 REAL_VALUE_TYPE
*dp
;
1135 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1136 Consider doing it via real_convert now. */
1138 v
= make_node (REAL_CST
);
1139 dp
= ggc_alloc (sizeof (REAL_VALUE_TYPE
));
1140 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
1142 TREE_TYPE (v
) = type
;
1143 TREE_REAL_CST_PTR (v
) = dp
;
1144 TREE_OVERFLOW (v
) = TREE_CONSTANT_OVERFLOW (v
) = overflow
;
1148 /* Return a new REAL_CST node whose type is TYPE
1149 and whose value is the integer value of the INTEGER_CST node I. */
1152 real_value_from_int_cst (tree type
, tree i
)
1156 /* Clear all bits of the real value type so that we can later do
1157 bitwise comparisons to see if two values are the same. */
1158 memset (&d
, 0, sizeof d
);
1160 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
,
1161 TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
),
1162 TYPE_UNSIGNED (TREE_TYPE (i
)));
1166 /* Given a tree representing an integer constant I, return a tree
1167 representing the same value as a floating-point constant of type TYPE. */
1170 build_real_from_int_cst (tree type
, tree i
)
1173 int overflow
= TREE_OVERFLOW (i
);
1175 v
= build_real (type
, real_value_from_int_cst (type
, i
));
1177 TREE_OVERFLOW (v
) |= overflow
;
1178 TREE_CONSTANT_OVERFLOW (v
) |= overflow
;
1182 /* Return a newly constructed STRING_CST node whose value is
1183 the LEN characters at STR.
1184 The TREE_TYPE is not initialized. */
1187 build_string (int len
, const char *str
)
1192 /* Do not waste bytes provided by padding of struct tree_string. */
1193 length
= len
+ offsetof (struct tree_string
, str
) + 1;
1195 #ifdef GATHER_STATISTICS
1196 tree_node_counts
[(int) c_kind
]++;
1197 tree_node_sizes
[(int) c_kind
] += length
;
1200 s
= ggc_alloc_tree (length
);
1202 memset (s
, 0, sizeof (struct tree_common
));
1203 TREE_SET_CODE (s
, STRING_CST
);
1204 TREE_CONSTANT (s
) = 1;
1205 TREE_INVARIANT (s
) = 1;
1206 TREE_STRING_LENGTH (s
) = len
;
1207 memcpy ((char *) TREE_STRING_POINTER (s
), str
, len
);
1208 ((char *) TREE_STRING_POINTER (s
))[len
] = '\0';
1213 /* Return a newly constructed COMPLEX_CST node whose value is
1214 specified by the real and imaginary parts REAL and IMAG.
1215 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1216 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1219 build_complex (tree type
, tree real
, tree imag
)
1221 tree t
= make_node (COMPLEX_CST
);
1223 TREE_REALPART (t
) = real
;
1224 TREE_IMAGPART (t
) = imag
;
1225 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
1226 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1227 TREE_CONSTANT_OVERFLOW (t
)
1228 = TREE_CONSTANT_OVERFLOW (real
) | TREE_CONSTANT_OVERFLOW (imag
);
1232 /* Return a constant of arithmetic type TYPE which is the
1233 multiplicative identity of the set TYPE. */
1236 build_one_cst (tree type
)
1238 switch (TREE_CODE (type
))
1240 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1241 case POINTER_TYPE
: case REFERENCE_TYPE
:
1243 return build_int_cst (type
, 1);
1246 return build_real (type
, dconst1
);
1253 scalar
= build_one_cst (TREE_TYPE (type
));
1255 /* Create 'vect_cst_ = {cst,cst,...,cst}' */
1257 for (i
= TYPE_VECTOR_SUBPARTS (type
); --i
>= 0; )
1258 cst
= tree_cons (NULL_TREE
, scalar
, cst
);
1260 return build_vector (type
, cst
);
1264 return build_complex (type
,
1265 build_one_cst (TREE_TYPE (type
)),
1266 fold_convert (TREE_TYPE (type
), integer_zero_node
));
1273 /* Build a BINFO with LEN language slots. */
1276 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL
)
1279 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
1280 + VEC_embedded_size (tree
, base_binfos
));
1282 #ifdef GATHER_STATISTICS
1283 tree_node_counts
[(int) binfo_kind
]++;
1284 tree_node_sizes
[(int) binfo_kind
] += length
;
1287 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
1289 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
1291 TREE_SET_CODE (t
, TREE_BINFO
);
1293 VEC_embedded_init (tree
, BINFO_BASE_BINFOS (t
), base_binfos
);
1299 /* Build a newly constructed TREE_VEC node of length LEN. */
1302 make_tree_vec_stat (int len MEM_STAT_DECL
)
1305 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
1307 #ifdef GATHER_STATISTICS
1308 tree_node_counts
[(int) vec_kind
]++;
1309 tree_node_sizes
[(int) vec_kind
] += length
;
1312 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
1314 memset (t
, 0, length
);
1316 TREE_SET_CODE (t
, TREE_VEC
);
1317 TREE_VEC_LENGTH (t
) = len
;
1322 /* Return 1 if EXPR is the integer constant zero or a complex constant
1326 integer_zerop (tree expr
)
1330 return ((TREE_CODE (expr
) == INTEGER_CST
1331 && TREE_INT_CST_LOW (expr
) == 0
1332 && TREE_INT_CST_HIGH (expr
) == 0)
1333 || (TREE_CODE (expr
) == COMPLEX_CST
1334 && integer_zerop (TREE_REALPART (expr
))
1335 && integer_zerop (TREE_IMAGPART (expr
))));
1338 /* Return 1 if EXPR is the integer constant one or the corresponding
1339 complex constant. */
1342 integer_onep (tree expr
)
1346 return ((TREE_CODE (expr
) == INTEGER_CST
1347 && TREE_INT_CST_LOW (expr
) == 1
1348 && TREE_INT_CST_HIGH (expr
) == 0)
1349 || (TREE_CODE (expr
) == COMPLEX_CST
1350 && integer_onep (TREE_REALPART (expr
))
1351 && integer_zerop (TREE_IMAGPART (expr
))));
1354 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1355 it contains. Likewise for the corresponding complex constant. */
1358 integer_all_onesp (tree expr
)
1365 if (TREE_CODE (expr
) == COMPLEX_CST
1366 && integer_all_onesp (TREE_REALPART (expr
))
1367 && integer_zerop (TREE_IMAGPART (expr
)))
1370 else if (TREE_CODE (expr
) != INTEGER_CST
)
1373 uns
= TYPE_UNSIGNED (TREE_TYPE (expr
));
1374 if (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1375 && TREE_INT_CST_HIGH (expr
) == -1)
1380 /* Note that using TYPE_PRECISION here is wrong. We care about the
1381 actual bits, not the (arbitrary) range of the type. */
1382 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr
)));
1383 if (prec
>= HOST_BITS_PER_WIDE_INT
)
1385 HOST_WIDE_INT high_value
;
1388 shift_amount
= prec
- HOST_BITS_PER_WIDE_INT
;
1390 /* Can not handle precisions greater than twice the host int size. */
1391 gcc_assert (shift_amount
<= HOST_BITS_PER_WIDE_INT
);
1392 if (shift_amount
== HOST_BITS_PER_WIDE_INT
)
1393 /* Shifting by the host word size is undefined according to the ANSI
1394 standard, so we must handle this as a special case. */
1397 high_value
= ((HOST_WIDE_INT
) 1 << shift_amount
) - 1;
1399 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1400 && TREE_INT_CST_HIGH (expr
) == high_value
);
1403 return TREE_INT_CST_LOW (expr
) == ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
1406 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1410 integer_pow2p (tree expr
)
1413 HOST_WIDE_INT high
, low
;
1417 if (TREE_CODE (expr
) == COMPLEX_CST
1418 && integer_pow2p (TREE_REALPART (expr
))
1419 && integer_zerop (TREE_IMAGPART (expr
)))
1422 if (TREE_CODE (expr
) != INTEGER_CST
)
1425 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1426 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1427 high
= TREE_INT_CST_HIGH (expr
);
1428 low
= TREE_INT_CST_LOW (expr
);
1430 /* First clear all bits that are beyond the type's precision in case
1431 we've been sign extended. */
1433 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1435 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1436 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1440 if (prec
< HOST_BITS_PER_WIDE_INT
)
1441 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1444 if (high
== 0 && low
== 0)
1447 return ((high
== 0 && (low
& (low
- 1)) == 0)
1448 || (low
== 0 && (high
& (high
- 1)) == 0));
1451 /* Return 1 if EXPR is an integer constant other than zero or a
1452 complex constant other than zero. */
1455 integer_nonzerop (tree expr
)
1459 return ((TREE_CODE (expr
) == INTEGER_CST
1460 && (TREE_INT_CST_LOW (expr
) != 0
1461 || TREE_INT_CST_HIGH (expr
) != 0))
1462 || (TREE_CODE (expr
) == COMPLEX_CST
1463 && (integer_nonzerop (TREE_REALPART (expr
))
1464 || integer_nonzerop (TREE_IMAGPART (expr
)))));
1467 /* Return the power of two represented by a tree node known to be a
1471 tree_log2 (tree expr
)
1474 HOST_WIDE_INT high
, low
;
1478 if (TREE_CODE (expr
) == COMPLEX_CST
)
1479 return tree_log2 (TREE_REALPART (expr
));
1481 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1482 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1484 high
= TREE_INT_CST_HIGH (expr
);
1485 low
= TREE_INT_CST_LOW (expr
);
1487 /* First clear all bits that are beyond the type's precision in case
1488 we've been sign extended. */
1490 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1492 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1493 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1497 if (prec
< HOST_BITS_PER_WIDE_INT
)
1498 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1501 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ exact_log2 (high
)
1502 : exact_log2 (low
));
1505 /* Similar, but return the largest integer Y such that 2 ** Y is less
1506 than or equal to EXPR. */
1509 tree_floor_log2 (tree expr
)
1512 HOST_WIDE_INT high
, low
;
1516 if (TREE_CODE (expr
) == COMPLEX_CST
)
1517 return tree_log2 (TREE_REALPART (expr
));
1519 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1520 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1522 high
= TREE_INT_CST_HIGH (expr
);
1523 low
= TREE_INT_CST_LOW (expr
);
1525 /* First clear all bits that are beyond the type's precision in case
1526 we've been sign extended. Ignore if type's precision hasn't been set
1527 since what we are doing is setting it. */
1529 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
|| prec
== 0)
1531 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1532 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1536 if (prec
< HOST_BITS_PER_WIDE_INT
)
1537 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1540 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ floor_log2 (high
)
1541 : floor_log2 (low
));
1544 /* Return 1 if EXPR is the real constant zero. */
1547 real_zerop (tree expr
)
1551 return ((TREE_CODE (expr
) == REAL_CST
1552 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
))
1553 || (TREE_CODE (expr
) == COMPLEX_CST
1554 && real_zerop (TREE_REALPART (expr
))
1555 && real_zerop (TREE_IMAGPART (expr
))));
1558 /* Return 1 if EXPR is the real constant one in real or complex form. */
1561 real_onep (tree expr
)
1565 return ((TREE_CODE (expr
) == REAL_CST
1566 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
))
1567 || (TREE_CODE (expr
) == COMPLEX_CST
1568 && real_onep (TREE_REALPART (expr
))
1569 && real_zerop (TREE_IMAGPART (expr
))));
1572 /* Return 1 if EXPR is the real constant two. */
1575 real_twop (tree expr
)
1579 return ((TREE_CODE (expr
) == REAL_CST
1580 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst2
))
1581 || (TREE_CODE (expr
) == COMPLEX_CST
1582 && real_twop (TREE_REALPART (expr
))
1583 && real_zerop (TREE_IMAGPART (expr
))));
1586 /* Return 1 if EXPR is the real constant minus one. */
1589 real_minus_onep (tree expr
)
1593 return ((TREE_CODE (expr
) == REAL_CST
1594 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconstm1
))
1595 || (TREE_CODE (expr
) == COMPLEX_CST
1596 && real_minus_onep (TREE_REALPART (expr
))
1597 && real_zerop (TREE_IMAGPART (expr
))));
1600 /* Nonzero if EXP is a constant or a cast of a constant. */
1603 really_constant_p (tree exp
)
1605 /* This is not quite the same as STRIP_NOPS. It does more. */
1606 while (TREE_CODE (exp
) == NOP_EXPR
1607 || TREE_CODE (exp
) == CONVERT_EXPR
1608 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
1609 exp
= TREE_OPERAND (exp
, 0);
1610 return TREE_CONSTANT (exp
);
1613 /* Return first list element whose TREE_VALUE is ELEM.
1614 Return 0 if ELEM is not in LIST. */
1617 value_member (tree elem
, tree list
)
1621 if (elem
== TREE_VALUE (list
))
1623 list
= TREE_CHAIN (list
);
1628 /* Return first list element whose TREE_PURPOSE is ELEM.
1629 Return 0 if ELEM is not in LIST. */
1632 purpose_member (tree elem
, tree list
)
1636 if (elem
== TREE_PURPOSE (list
))
1638 list
= TREE_CHAIN (list
);
1643 /* Return nonzero if ELEM is part of the chain CHAIN. */
1646 chain_member (tree elem
, tree chain
)
1652 chain
= TREE_CHAIN (chain
);
1658 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1659 We expect a null pointer to mark the end of the chain.
1660 This is the Lisp primitive `length'. */
1663 list_length (tree t
)
1666 #ifdef ENABLE_TREE_CHECKING
1674 #ifdef ENABLE_TREE_CHECKING
1677 gcc_assert (p
!= q
);
1685 /* Returns the number of FIELD_DECLs in TYPE. */
1688 fields_length (tree type
)
1690 tree t
= TYPE_FIELDS (type
);
1693 for (; t
; t
= TREE_CHAIN (t
))
1694 if (TREE_CODE (t
) == FIELD_DECL
)
1700 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1701 by modifying the last node in chain 1 to point to chain 2.
1702 This is the Lisp primitive `nconc'. */
1705 chainon (tree op1
, tree op2
)
1714 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
1716 TREE_CHAIN (t1
) = op2
;
1718 #ifdef ENABLE_TREE_CHECKING
1721 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
1722 gcc_assert (t2
!= t1
);
1729 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1732 tree_last (tree chain
)
1736 while ((next
= TREE_CHAIN (chain
)))
1741 /* Reverse the order of elements in the chain T,
1742 and return the new head of the chain (old last element). */
1747 tree prev
= 0, decl
, next
;
1748 for (decl
= t
; decl
; decl
= next
)
1750 next
= TREE_CHAIN (decl
);
1751 TREE_CHAIN (decl
) = prev
;
1757 /* Return a newly created TREE_LIST node whose
1758 purpose and value fields are PARM and VALUE. */
1761 build_tree_list_stat (tree parm
, tree value MEM_STAT_DECL
)
1763 tree t
= make_node_stat (TREE_LIST PASS_MEM_STAT
);
1764 TREE_PURPOSE (t
) = parm
;
1765 TREE_VALUE (t
) = value
;
1769 /* Return a newly created TREE_LIST node whose
1770 purpose and value fields are PURPOSE and VALUE
1771 and whose TREE_CHAIN is CHAIN. */
1774 tree_cons_stat (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
1778 node
= ggc_alloc_zone_pass_stat (sizeof (struct tree_list
), &tree_zone
);
1780 memset (node
, 0, sizeof (struct tree_common
));
1782 #ifdef GATHER_STATISTICS
1783 tree_node_counts
[(int) x_kind
]++;
1784 tree_node_sizes
[(int) x_kind
] += sizeof (struct tree_list
);
1787 TREE_SET_CODE (node
, TREE_LIST
);
1788 TREE_CHAIN (node
) = chain
;
1789 TREE_PURPOSE (node
) = purpose
;
1790 TREE_VALUE (node
) = value
;
1795 /* Return the size nominally occupied by an object of type TYPE
1796 when it resides in memory. The value is measured in units of bytes,
1797 and its data type is that normally used for type sizes
1798 (which is the first type created by make_signed_type or
1799 make_unsigned_type). */
1802 size_in_bytes (tree type
)
1806 if (type
== error_mark_node
)
1807 return integer_zero_node
;
1809 type
= TYPE_MAIN_VARIANT (type
);
1810 t
= TYPE_SIZE_UNIT (type
);
1814 lang_hooks
.types
.incomplete_type_error (NULL_TREE
, type
);
1815 return size_zero_node
;
1818 if (TREE_CODE (t
) == INTEGER_CST
)
1819 t
= force_fit_type (t
, 0, false, false);
1824 /* Return the size of TYPE (in bytes) as a wide integer
1825 or return -1 if the size can vary or is larger than an integer. */
1828 int_size_in_bytes (tree type
)
1832 if (type
== error_mark_node
)
1835 type
= TYPE_MAIN_VARIANT (type
);
1836 t
= TYPE_SIZE_UNIT (type
);
1838 || TREE_CODE (t
) != INTEGER_CST
1839 || TREE_INT_CST_HIGH (t
) != 0
1840 /* If the result would appear negative, it's too big to represent. */
1841 || (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0)
1844 return TREE_INT_CST_LOW (t
);
1847 /* Return the maximum size of TYPE (in bytes) as a wide integer
1848 or return -1 if the size can vary or is larger than an integer. */
1851 max_int_size_in_bytes (tree type
)
1853 HOST_WIDE_INT size
= -1;
1856 /* If this is an array type, check for a possible MAX_SIZE attached. */
1858 if (TREE_CODE (type
) == ARRAY_TYPE
)
1860 size_tree
= TYPE_ARRAY_MAX_SIZE (type
);
1862 if (size_tree
&& host_integerp (size_tree
, 1))
1863 size
= tree_low_cst (size_tree
, 1);
1866 /* If we still haven't been able to get a size, see if the language
1867 can compute a maximum size. */
1871 size_tree
= lang_hooks
.types
.max_size (type
);
1873 if (size_tree
&& host_integerp (size_tree
, 1))
1874 size
= tree_low_cst (size_tree
, 1);
1880 /* Return the bit position of FIELD, in bits from the start of the record.
1881 This is a tree of type bitsizetype. */
1884 bit_position (tree field
)
1886 return bit_from_pos (DECL_FIELD_OFFSET (field
),
1887 DECL_FIELD_BIT_OFFSET (field
));
1890 /* Likewise, but return as an integer. It must be representable in
1891 that way (since it could be a signed value, we don't have the
1892 option of returning -1 like int_size_in_byte can. */
1895 int_bit_position (tree field
)
1897 return tree_low_cst (bit_position (field
), 0);
1900 /* Return the byte position of FIELD, in bytes from the start of the record.
1901 This is a tree of type sizetype. */
1904 byte_position (tree field
)
1906 return byte_from_pos (DECL_FIELD_OFFSET (field
),
1907 DECL_FIELD_BIT_OFFSET (field
));
1910 /* Likewise, but return as an integer. It must be representable in
1911 that way (since it could be a signed value, we don't have the
1912 option of returning -1 like int_size_in_byte can. */
1915 int_byte_position (tree field
)
1917 return tree_low_cst (byte_position (field
), 0);
1920 /* Return the strictest alignment, in bits, that T is known to have. */
1925 unsigned int align0
, align1
;
1927 switch (TREE_CODE (t
))
1929 case NOP_EXPR
: case CONVERT_EXPR
: case NON_LVALUE_EXPR
:
1930 /* If we have conversions, we know that the alignment of the
1931 object must meet each of the alignments of the types. */
1932 align0
= expr_align (TREE_OPERAND (t
, 0));
1933 align1
= TYPE_ALIGN (TREE_TYPE (t
));
1934 return MAX (align0
, align1
);
1937 /* FIXME tuples: It is unclear to me if this function, which
1938 is only called from ADA, is called on gimple or non gimple
1939 trees. Let's assume it's from gimple trees unless we hit
1943 case SAVE_EXPR
: case COMPOUND_EXPR
: case GIMPLE_MODIFY_STMT
:
1944 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
1945 case CLEANUP_POINT_EXPR
:
1946 /* These don't change the alignment of an object. */
1947 return expr_align (TREE_OPERAND (t
, 0));
1950 /* The best we can do is say that the alignment is the least aligned
1952 align0
= expr_align (TREE_OPERAND (t
, 1));
1953 align1
= expr_align (TREE_OPERAND (t
, 2));
1954 return MIN (align0
, align1
);
1956 case LABEL_DECL
: case CONST_DECL
:
1957 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
1958 if (DECL_ALIGN (t
) != 0)
1959 return DECL_ALIGN (t
);
1963 return FUNCTION_BOUNDARY
;
1969 /* Otherwise take the alignment from that of the type. */
1970 return TYPE_ALIGN (TREE_TYPE (t
));
1973 /* Return, as a tree node, the number of elements for TYPE (which is an
1974 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1977 array_type_nelts (tree type
)
1979 tree index_type
, min
, max
;
1981 /* If they did it with unspecified bounds, then we should have already
1982 given an error about it before we got here. */
1983 if (! TYPE_DOMAIN (type
))
1984 return error_mark_node
;
1986 index_type
= TYPE_DOMAIN (type
);
1987 min
= TYPE_MIN_VALUE (index_type
);
1988 max
= TYPE_MAX_VALUE (index_type
);
1990 return (integer_zerop (min
)
1992 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
1995 /* If arg is static -- a reference to an object in static storage -- then
1996 return the object. This is not the same as the C meaning of `static'.
1997 If arg isn't static, return NULL. */
2002 switch (TREE_CODE (arg
))
2005 /* Nested functions are static, even though taking their address will
2006 involve a trampoline as we unnest the nested function and create
2007 the trampoline on the tree level. */
2011 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2012 && ! DECL_THREAD_LOCAL_P (arg
)
2013 && ! DECL_DLLIMPORT_P (arg
)
2017 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2021 return TREE_STATIC (arg
) ? arg
: NULL
;
2028 /* If the thing being referenced is not a field, then it is
2029 something language specific. */
2030 if (TREE_CODE (TREE_OPERAND (arg
, 1)) != FIELD_DECL
)
2031 return (*lang_hooks
.staticp
) (arg
);
2033 /* If we are referencing a bitfield, we can't evaluate an
2034 ADDR_EXPR at compile time and so it isn't a constant. */
2035 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
2038 return staticp (TREE_OPERAND (arg
, 0));
2043 case MISALIGNED_INDIRECT_REF
:
2044 case ALIGN_INDIRECT_REF
:
2046 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
2049 case ARRAY_RANGE_REF
:
2050 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
2051 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
2052 return staticp (TREE_OPERAND (arg
, 0));
2057 if ((unsigned int) TREE_CODE (arg
)
2058 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
2059 return lang_hooks
.staticp (arg
);
2065 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2066 Do this to any expression which may be used in more than one place,
2067 but must be evaluated only once.
2069 Normally, expand_expr would reevaluate the expression each time.
2070 Calling save_expr produces something that is evaluated and recorded
2071 the first time expand_expr is called on it. Subsequent calls to
2072 expand_expr just reuse the recorded value.
2074 The call to expand_expr that generates code that actually computes
2075 the value is the first call *at compile time*. Subsequent calls
2076 *at compile time* generate code to use the saved value.
2077 This produces correct result provided that *at run time* control
2078 always flows through the insns made by the first expand_expr
2079 before reaching the other places where the save_expr was evaluated.
2080 You, the caller of save_expr, must make sure this is so.
2082 Constants, and certain read-only nodes, are returned with no
2083 SAVE_EXPR because that is safe. Expressions containing placeholders
2084 are not touched; see tree.def for an explanation of what these
2088 save_expr (tree expr
)
2090 tree t
= fold (expr
);
2093 /* If the tree evaluates to a constant, then we don't want to hide that
2094 fact (i.e. this allows further folding, and direct checks for constants).
2095 However, a read-only object that has side effects cannot be bypassed.
2096 Since it is no problem to reevaluate literals, we just return the
2098 inner
= skip_simple_arithmetic (t
);
2100 if (TREE_INVARIANT (inner
)
2101 || (TREE_READONLY (inner
) && ! TREE_SIDE_EFFECTS (inner
))
2102 || TREE_CODE (inner
) == SAVE_EXPR
2103 || TREE_CODE (inner
) == ERROR_MARK
)
2106 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2107 it means that the size or offset of some field of an object depends on
2108 the value within another field.
2110 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2111 and some variable since it would then need to be both evaluated once and
2112 evaluated more than once. Front-ends must assure this case cannot
2113 happen by surrounding any such subexpressions in their own SAVE_EXPR
2114 and forcing evaluation at the proper time. */
2115 if (contains_placeholder_p (inner
))
2118 t
= build1 (SAVE_EXPR
, TREE_TYPE (expr
), t
);
2120 /* This expression might be placed ahead of a jump to ensure that the
2121 value was computed on both sides of the jump. So make sure it isn't
2122 eliminated as dead. */
2123 TREE_SIDE_EFFECTS (t
) = 1;
2124 TREE_INVARIANT (t
) = 1;
2128 /* Look inside EXPR and into any simple arithmetic operations. Return
2129 the innermost non-arithmetic node. */
2132 skip_simple_arithmetic (tree expr
)
2136 /* We don't care about whether this can be used as an lvalue in this
2138 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
2139 expr
= TREE_OPERAND (expr
, 0);
2141 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2142 a constant, it will be more efficient to not make another SAVE_EXPR since
2143 it will allow better simplification and GCSE will be able to merge the
2144 computations if they actually occur. */
2148 if (UNARY_CLASS_P (inner
))
2149 inner
= TREE_OPERAND (inner
, 0);
2150 else if (BINARY_CLASS_P (inner
))
2152 if (TREE_INVARIANT (TREE_OPERAND (inner
, 1)))
2153 inner
= TREE_OPERAND (inner
, 0);
2154 else if (TREE_INVARIANT (TREE_OPERAND (inner
, 0)))
2155 inner
= TREE_OPERAND (inner
, 1);
2166 /* Return which tree structure is used by T. */
2168 enum tree_node_structure_enum
2169 tree_node_structure (tree t
)
2171 enum tree_code code
= TREE_CODE (t
);
2173 switch (TREE_CODE_CLASS (code
))
2175 case tcc_declaration
:
2180 return TS_FIELD_DECL
;
2182 return TS_PARM_DECL
;
2186 return TS_LABEL_DECL
;
2188 return TS_RESULT_DECL
;
2190 return TS_CONST_DECL
;
2192 return TS_TYPE_DECL
;
2194 return TS_FUNCTION_DECL
;
2195 case SYMBOL_MEMORY_TAG
:
2196 case NAME_MEMORY_TAG
:
2197 case STRUCT_FIELD_TAG
:
2198 case MEMORY_PARTITION_TAG
:
2199 return TS_MEMORY_TAG
;
2201 return TS_DECL_NON_COMMON
;
2207 case tcc_comparison
:
2210 case tcc_expression
:
2213 case tcc_gimple_stmt
:
2214 return TS_GIMPLE_STATEMENT
;
2215 default: /* tcc_constant and tcc_exceptional */
2220 /* tcc_constant cases. */
2221 case INTEGER_CST
: return TS_INT_CST
;
2222 case REAL_CST
: return TS_REAL_CST
;
2223 case COMPLEX_CST
: return TS_COMPLEX
;
2224 case VECTOR_CST
: return TS_VECTOR
;
2225 case STRING_CST
: return TS_STRING
;
2226 /* tcc_exceptional cases. */
2227 /* FIXME tuples: eventually this should be TS_BASE. For now, nothing
2229 case ERROR_MARK
: return TS_COMMON
;
2230 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
2231 case TREE_LIST
: return TS_LIST
;
2232 case TREE_VEC
: return TS_VEC
;
2233 case PHI_NODE
: return TS_PHI_NODE
;
2234 case SSA_NAME
: return TS_SSA_NAME
;
2235 case PLACEHOLDER_EXPR
: return TS_COMMON
;
2236 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
2237 case BLOCK
: return TS_BLOCK
;
2238 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
2239 case TREE_BINFO
: return TS_BINFO
;
2240 case VALUE_HANDLE
: return TS_VALUE_HANDLE
;
2241 case OMP_CLAUSE
: return TS_OMP_CLAUSE
;
2248 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2249 or offset that depends on a field within a record. */
2252 contains_placeholder_p (tree exp
)
2254 enum tree_code code
;
2259 code
= TREE_CODE (exp
);
2260 if (code
== PLACEHOLDER_EXPR
)
2263 switch (TREE_CODE_CLASS (code
))
2266 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2267 position computations since they will be converted into a
2268 WITH_RECORD_EXPR involving the reference, which will assume
2269 here will be valid. */
2270 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2272 case tcc_exceptional
:
2273 if (code
== TREE_LIST
)
2274 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
2275 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
2280 case tcc_comparison
:
2281 case tcc_expression
:
2285 /* Ignoring the first operand isn't quite right, but works best. */
2286 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
2289 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2290 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
2291 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
2294 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
2300 switch (TREE_CODE_LENGTH (code
))
2303 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2305 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2306 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
2317 /* Return true if any part of the computation of TYPE involves a
2318 PLACEHOLDER_EXPR. This includes size, bounds, qualifiers
2319 (for QUAL_UNION_TYPE) and field positions. */
2322 type_contains_placeholder_1 (tree type
)
2324 /* If the size contains a placeholder or the parent type (component type in
2325 the case of arrays) type involves a placeholder, this type does. */
2326 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
2327 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
2328 || (TREE_TYPE (type
) != 0
2329 && type_contains_placeholder_p (TREE_TYPE (type
))))
2332 /* Now do type-specific checks. Note that the last part of the check above
2333 greatly limits what we have to do below. */
2334 switch (TREE_CODE (type
))
2342 case REFERENCE_TYPE
:
2350 /* Here we just check the bounds. */
2351 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
2352 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
2355 /* We're already checked the component type (TREE_TYPE), so just check
2357 return type_contains_placeholder_p (TYPE_DOMAIN (type
));
2361 case QUAL_UNION_TYPE
:
2365 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2366 if (TREE_CODE (field
) == FIELD_DECL
2367 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
2368 || (TREE_CODE (type
) == QUAL_UNION_TYPE
2369 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
2370 || type_contains_placeholder_p (TREE_TYPE (field
))))
2382 type_contains_placeholder_p (tree type
)
2386 /* If the contains_placeholder_bits field has been initialized,
2387 then we know the answer. */
2388 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
2389 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
2391 /* Indicate that we've seen this type node, and the answer is false.
2392 This is what we want to return if we run into recursion via fields. */
2393 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
2395 /* Compute the real value. */
2396 result
= type_contains_placeholder_1 (type
);
2398 /* Store the real value. */
2399 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
2404 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2405 return a tree with all occurrences of references to F in a
2406 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2407 contains only arithmetic expressions or a CALL_EXPR with a
2408 PLACEHOLDER_EXPR occurring only in its arglist. */
2411 substitute_in_expr (tree exp
, tree f
, tree r
)
2413 enum tree_code code
= TREE_CODE (exp
);
2414 tree op0
, op1
, op2
, op3
;
2418 /* We handle TREE_LIST and COMPONENT_REF separately. */
2419 if (code
== TREE_LIST
)
2421 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
2422 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
2423 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
2426 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
2428 else if (code
== COMPONENT_REF
)
2430 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2431 and it is the right field, replace it with R. */
2432 for (inner
= TREE_OPERAND (exp
, 0);
2433 REFERENCE_CLASS_P (inner
);
2434 inner
= TREE_OPERAND (inner
, 0))
2436 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
2437 && TREE_OPERAND (exp
, 1) == f
)
2440 /* If this expression hasn't been completed let, leave it alone. */
2441 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& TREE_TYPE (inner
) == 0)
2444 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2445 if (op0
== TREE_OPERAND (exp
, 0))
2448 new = fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
),
2449 op0
, TREE_OPERAND (exp
, 1), NULL_TREE
);
2452 switch (TREE_CODE_CLASS (code
))
2455 case tcc_declaration
:
2458 case tcc_exceptional
:
2461 case tcc_comparison
:
2462 case tcc_expression
:
2464 switch (TREE_CODE_LENGTH (code
))
2470 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2471 if (op0
== TREE_OPERAND (exp
, 0))
2474 new = fold_build1 (code
, TREE_TYPE (exp
), op0
);
2478 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2479 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2481 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
2484 new = fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
2488 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2489 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2490 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
2492 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2493 && op2
== TREE_OPERAND (exp
, 2))
2496 new = fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
2500 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2501 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2502 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
2503 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
2505 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2506 && op2
== TREE_OPERAND (exp
, 2)
2507 && op3
== TREE_OPERAND (exp
, 3))
2510 new = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
2522 TREE_READONLY (new) = TREE_READONLY (exp
);
2526 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
2527 for it within OBJ, a tree that is an object or a chain of references. */
2530 substitute_placeholder_in_expr (tree exp
, tree obj
)
2532 enum tree_code code
= TREE_CODE (exp
);
2533 tree op0
, op1
, op2
, op3
;
2535 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
2536 in the chain of OBJ. */
2537 if (code
== PLACEHOLDER_EXPR
)
2539 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
2542 for (elt
= obj
; elt
!= 0;
2543 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
2544 || TREE_CODE (elt
) == COND_EXPR
)
2545 ? TREE_OPERAND (elt
, 1)
2546 : (REFERENCE_CLASS_P (elt
)
2547 || UNARY_CLASS_P (elt
)
2548 || BINARY_CLASS_P (elt
)
2549 || EXPRESSION_CLASS_P (elt
))
2550 ? TREE_OPERAND (elt
, 0) : 0))
2551 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
2554 for (elt
= obj
; elt
!= 0;
2555 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
2556 || TREE_CODE (elt
) == COND_EXPR
)
2557 ? TREE_OPERAND (elt
, 1)
2558 : (REFERENCE_CLASS_P (elt
)
2559 || UNARY_CLASS_P (elt
)
2560 || BINARY_CLASS_P (elt
)
2561 || EXPRESSION_CLASS_P (elt
))
2562 ? TREE_OPERAND (elt
, 0) : 0))
2563 if (POINTER_TYPE_P (TREE_TYPE (elt
))
2564 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
2566 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
2568 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2569 survives until RTL generation, there will be an error. */
2573 /* TREE_LIST is special because we need to look at TREE_VALUE
2574 and TREE_CHAIN, not TREE_OPERANDS. */
2575 else if (code
== TREE_LIST
)
2577 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
2578 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
2579 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
2582 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
2585 switch (TREE_CODE_CLASS (code
))
2588 case tcc_declaration
:
2591 case tcc_exceptional
:
2594 case tcc_comparison
:
2595 case tcc_expression
:
2598 switch (TREE_CODE_LENGTH (code
))
2604 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2605 if (op0
== TREE_OPERAND (exp
, 0))
2608 return fold_build1 (code
, TREE_TYPE (exp
), op0
);
2611 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2612 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2614 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
2617 return fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
2620 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2621 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2622 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
2624 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2625 && op2
== TREE_OPERAND (exp
, 2))
2628 return fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
2631 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2632 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2633 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
2634 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
2636 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2637 && op2
== TREE_OPERAND (exp
, 2)
2638 && op3
== TREE_OPERAND (exp
, 3))
2641 return fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
2653 /* Stabilize a reference so that we can use it any number of times
2654 without causing its operands to be evaluated more than once.
2655 Returns the stabilized reference. This works by means of save_expr,
2656 so see the caveats in the comments about save_expr.
2658 Also allows conversion expressions whose operands are references.
2659 Any other kind of expression is returned unchanged. */
2662 stabilize_reference (tree ref
)
2665 enum tree_code code
= TREE_CODE (ref
);
2672 /* No action is needed in this case. */
2678 case FIX_TRUNC_EXPR
:
2679 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
2683 result
= build_nt (INDIRECT_REF
,
2684 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
2688 result
= build_nt (COMPONENT_REF
,
2689 stabilize_reference (TREE_OPERAND (ref
, 0)),
2690 TREE_OPERAND (ref
, 1), NULL_TREE
);
2694 result
= build_nt (BIT_FIELD_REF
,
2695 stabilize_reference (TREE_OPERAND (ref
, 0)),
2696 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2697 stabilize_reference_1 (TREE_OPERAND (ref
, 2)));
2701 result
= build_nt (ARRAY_REF
,
2702 stabilize_reference (TREE_OPERAND (ref
, 0)),
2703 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2704 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
2707 case ARRAY_RANGE_REF
:
2708 result
= build_nt (ARRAY_RANGE_REF
,
2709 stabilize_reference (TREE_OPERAND (ref
, 0)),
2710 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2711 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
2715 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2716 it wouldn't be ignored. This matters when dealing with
2718 return stabilize_reference_1 (ref
);
2720 /* If arg isn't a kind of lvalue we recognize, make no change.
2721 Caller should recognize the error for an invalid lvalue. */
2726 return error_mark_node
;
2729 TREE_TYPE (result
) = TREE_TYPE (ref
);
2730 TREE_READONLY (result
) = TREE_READONLY (ref
);
2731 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
2732 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
2737 /* Subroutine of stabilize_reference; this is called for subtrees of
2738 references. Any expression with side-effects must be put in a SAVE_EXPR
2739 to ensure that it is only evaluated once.
2741 We don't put SAVE_EXPR nodes around everything, because assigning very
2742 simple expressions to temporaries causes us to miss good opportunities
2743 for optimizations. Among other things, the opportunity to fold in the
2744 addition of a constant into an addressing mode often gets lost, e.g.
2745 "y[i+1] += x;". In general, we take the approach that we should not make
2746 an assignment unless we are forced into it - i.e., that any non-side effect
2747 operator should be allowed, and that cse should take care of coalescing
2748 multiple utterances of the same expression should that prove fruitful. */
2751 stabilize_reference_1 (tree e
)
2754 enum tree_code code
= TREE_CODE (e
);
2756 /* We cannot ignore const expressions because it might be a reference
2757 to a const array but whose index contains side-effects. But we can
2758 ignore things that are actual constant or that already have been
2759 handled by this function. */
2761 if (TREE_INVARIANT (e
))
2764 switch (TREE_CODE_CLASS (code
))
2766 case tcc_exceptional
:
2768 case tcc_declaration
:
2769 case tcc_comparison
:
2771 case tcc_expression
:
2773 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2774 so that it will only be evaluated once. */
2775 /* The reference (r) and comparison (<) classes could be handled as
2776 below, but it is generally faster to only evaluate them once. */
2777 if (TREE_SIDE_EFFECTS (e
))
2778 return save_expr (e
);
2782 /* Constants need no processing. In fact, we should never reach
2787 /* Division is slow and tends to be compiled with jumps,
2788 especially the division by powers of 2 that is often
2789 found inside of an array reference. So do it just once. */
2790 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
2791 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
2792 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
2793 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
2794 return save_expr (e
);
2795 /* Recursively stabilize each operand. */
2796 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
2797 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
2801 /* Recursively stabilize each operand. */
2802 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
2809 TREE_TYPE (result
) = TREE_TYPE (e
);
2810 TREE_READONLY (result
) = TREE_READONLY (e
);
2811 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
2812 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
2813 TREE_INVARIANT (result
) = 1;
2818 /* Low-level constructors for expressions. */
2820 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
2821 TREE_INVARIANT, and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
2824 recompute_tree_invariant_for_addr_expr (tree t
)
2827 bool tc
= true, ti
= true, se
= false;
2829 /* We started out assuming this address is both invariant and constant, but
2830 does not have side effects. Now go down any handled components and see if
2831 any of them involve offsets that are either non-constant or non-invariant.
2832 Also check for side-effects.
2834 ??? Note that this code makes no attempt to deal with the case where
2835 taking the address of something causes a copy due to misalignment. */
2837 #define UPDATE_TITCSE(NODE) \
2838 do { tree _node = (NODE); \
2839 if (_node && !TREE_INVARIANT (_node)) ti = false; \
2840 if (_node && !TREE_CONSTANT (_node)) tc = false; \
2841 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
2843 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
2844 node
= TREE_OPERAND (node
, 0))
2846 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
2847 array reference (probably made temporarily by the G++ front end),
2848 so ignore all the operands. */
2849 if ((TREE_CODE (node
) == ARRAY_REF
2850 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
2851 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
2853 UPDATE_TITCSE (TREE_OPERAND (node
, 1));
2854 if (TREE_OPERAND (node
, 2))
2855 UPDATE_TITCSE (TREE_OPERAND (node
, 2));
2856 if (TREE_OPERAND (node
, 3))
2857 UPDATE_TITCSE (TREE_OPERAND (node
, 3));
2859 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
2860 FIELD_DECL, apparently. The G++ front end can put something else
2861 there, at least temporarily. */
2862 else if (TREE_CODE (node
) == COMPONENT_REF
2863 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
2865 if (TREE_OPERAND (node
, 2))
2866 UPDATE_TITCSE (TREE_OPERAND (node
, 2));
2868 else if (TREE_CODE (node
) == BIT_FIELD_REF
)
2869 UPDATE_TITCSE (TREE_OPERAND (node
, 2));
2872 node
= lang_hooks
.expr_to_decl (node
, &tc
, &ti
, &se
);
2874 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
2875 the address, since &(*a)->b is a form of addition. If it's a decl, it's
2876 invariant and constant if the decl is static. It's also invariant if it's
2877 a decl in the current function. Taking the address of a volatile variable
2878 is not volatile. If it's a constant, the address is both invariant and
2879 constant. Otherwise it's neither. */
2880 if (TREE_CODE (node
) == INDIRECT_REF
)
2881 UPDATE_TITCSE (TREE_OPERAND (node
, 0));
2882 else if (DECL_P (node
))
2886 else if (decl_function_context (node
) == current_function_decl
2887 /* Addresses of thread-local variables are invariant. */
2888 || (TREE_CODE (node
) == VAR_DECL
2889 && DECL_THREAD_LOCAL_P (node
)))
2894 else if (CONSTANT_CLASS_P (node
))
2899 se
|= TREE_SIDE_EFFECTS (node
);
2902 TREE_CONSTANT (t
) = tc
;
2903 TREE_INVARIANT (t
) = ti
;
2904 TREE_SIDE_EFFECTS (t
) = se
;
2905 #undef UPDATE_TITCSE
2908 /* Build an expression of code CODE, data type TYPE, and operands as
2909 specified. Expressions and reference nodes can be created this way.
2910 Constants, decls, types and misc nodes cannot be.
2912 We define 5 non-variadic functions, from 0 to 4 arguments. This is
2913 enough for all extant tree codes. */
2916 build0_stat (enum tree_code code
, tree tt MEM_STAT_DECL
)
2920 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
2922 t
= make_node_stat (code PASS_MEM_STAT
);
2929 build1_stat (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
2931 int length
= sizeof (struct tree_exp
);
2932 #ifdef GATHER_STATISTICS
2933 tree_node_kind kind
;
2937 #ifdef GATHER_STATISTICS
2938 switch (TREE_CODE_CLASS (code
))
2940 case tcc_statement
: /* an expression with side effects */
2943 case tcc_reference
: /* a reference */
2951 tree_node_counts
[(int) kind
]++;
2952 tree_node_sizes
[(int) kind
] += length
;
2955 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
2957 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
2959 memset (t
, 0, sizeof (struct tree_common
));
2961 TREE_SET_CODE (t
, code
);
2963 TREE_TYPE (t
) = type
;
2964 #ifdef USE_MAPPED_LOCATION
2965 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
2967 SET_EXPR_LOCUS (t
, NULL
);
2969 TREE_COMPLEXITY (t
) = 0;
2970 TREE_OPERAND (t
, 0) = node
;
2971 TREE_BLOCK (t
) = NULL_TREE
;
2972 if (node
&& !TYPE_P (node
))
2974 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
2975 TREE_READONLY (t
) = TREE_READONLY (node
);
2978 if (TREE_CODE_CLASS (code
) == tcc_statement
)
2979 TREE_SIDE_EFFECTS (t
) = 1;
2983 /* All of these have side-effects, no matter what their
2985 TREE_SIDE_EFFECTS (t
) = 1;
2986 TREE_READONLY (t
) = 0;
2989 case MISALIGNED_INDIRECT_REF
:
2990 case ALIGN_INDIRECT_REF
:
2992 /* Whether a dereference is readonly has nothing to do with whether
2993 its operand is readonly. */
2994 TREE_READONLY (t
) = 0;
2999 recompute_tree_invariant_for_addr_expr (t
);
3003 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
3004 && node
&& !TYPE_P (node
)
3005 && TREE_CONSTANT (node
))
3006 TREE_CONSTANT (t
) = 1;
3007 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
3008 && node
&& TREE_INVARIANT (node
))
3009 TREE_INVARIANT (t
) = 1;
3010 if (TREE_CODE_CLASS (code
) == tcc_reference
3011 && node
&& TREE_THIS_VOLATILE (node
))
3012 TREE_THIS_VOLATILE (t
) = 1;
3019 #define PROCESS_ARG(N) \
3021 TREE_OPERAND (t, N) = arg##N; \
3022 if (arg##N &&!TYPE_P (arg##N)) \
3024 if (TREE_SIDE_EFFECTS (arg##N)) \
3026 if (!TREE_READONLY (arg##N)) \
3028 if (!TREE_CONSTANT (arg##N)) \
3030 if (!TREE_INVARIANT (arg##N)) \
3036 build2_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
3038 bool constant
, read_only
, side_effects
, invariant
;
3041 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
3043 if (code
== MODIFY_EXPR
&& cfun
&& cfun
->gimplified
)
3045 /* We should be talking GIMPLE_MODIFY_STMT by now. */
3049 /* FIXME tuples: For now let's be lazy; later we must rewrite all
3050 build2 calls to build2_gimple calls. */
3051 if (TREE_CODE_CLASS (code
) == tcc_gimple_stmt
)
3052 return build2_gimple (code
, arg0
, arg1
);
3054 t
= make_node_stat (code PASS_MEM_STAT
);
3057 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
3058 result based on those same flags for the arguments. But if the
3059 arguments aren't really even `tree' expressions, we shouldn't be trying
3062 /* Expressions without side effects may be constant if their
3063 arguments are as well. */
3064 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
3065 || TREE_CODE_CLASS (code
) == tcc_binary
);
3067 side_effects
= TREE_SIDE_EFFECTS (t
);
3068 invariant
= constant
;
3073 TREE_READONLY (t
) = read_only
;
3074 TREE_CONSTANT (t
) = constant
;
3075 TREE_INVARIANT (t
) = invariant
;
3076 TREE_SIDE_EFFECTS (t
) = side_effects
;
3077 TREE_THIS_VOLATILE (t
)
3078 = (TREE_CODE_CLASS (code
) == tcc_reference
3079 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3085 /* Similar as build2_stat, but for GIMPLE tuples. For convenience's sake,
3086 arguments and return type are trees. */
3089 build2_gimple_stat (enum tree_code code
, tree arg0
, tree arg1 MEM_STAT_DECL
)
3094 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
3096 t
= make_node_stat (code PASS_MEM_STAT
);
3098 side_effects
= TREE_SIDE_EFFECTS (t
);
3100 /* ?? We don't care about setting flags for tuples... */
3101 GIMPLE_STMT_OPERAND (t
, 0) = arg0
;
3102 GIMPLE_STMT_OPERAND (t
, 1) = arg1
;
3104 /* ...except perhaps side_effects and volatility. ?? */
3105 TREE_SIDE_EFFECTS (t
) = side_effects
;
3106 TREE_THIS_VOLATILE (t
) = (TREE_CODE_CLASS (code
) == tcc_reference
3107 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3114 build3_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3115 tree arg2 MEM_STAT_DECL
)
3117 bool constant
, read_only
, side_effects
, invariant
;
3120 gcc_assert (TREE_CODE_LENGTH (code
) == 3);
3122 t
= make_node_stat (code PASS_MEM_STAT
);
3125 side_effects
= TREE_SIDE_EFFECTS (t
);
3131 if (code
== CALL_EXPR
&& !side_effects
)
3136 /* Calls have side-effects, except those to const or
3138 i
= call_expr_flags (t
);
3139 if (!(i
& (ECF_CONST
| ECF_PURE
)))
3142 /* And even those have side-effects if their arguments do. */
3143 else for (node
= arg1
; node
; node
= TREE_CHAIN (node
))
3144 if (TREE_SIDE_EFFECTS (TREE_VALUE (node
)))
3151 TREE_SIDE_EFFECTS (t
) = side_effects
;
3152 TREE_THIS_VOLATILE (t
)
3153 = (TREE_CODE_CLASS (code
) == tcc_reference
3154 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3160 build4_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3161 tree arg2
, tree arg3 MEM_STAT_DECL
)
3163 bool constant
, read_only
, side_effects
, invariant
;
3166 gcc_assert (TREE_CODE_LENGTH (code
) == 4);
3168 t
= make_node_stat (code PASS_MEM_STAT
);
3171 side_effects
= TREE_SIDE_EFFECTS (t
);
3178 TREE_SIDE_EFFECTS (t
) = side_effects
;
3179 TREE_THIS_VOLATILE (t
)
3180 = (TREE_CODE_CLASS (code
) == tcc_reference
3181 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3187 build5_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3188 tree arg2
, tree arg3
, tree arg4 MEM_STAT_DECL
)
3190 bool constant
, read_only
, side_effects
, invariant
;
3193 gcc_assert (TREE_CODE_LENGTH (code
) == 5);
3195 t
= make_node_stat (code PASS_MEM_STAT
);
3198 side_effects
= TREE_SIDE_EFFECTS (t
);
3206 TREE_SIDE_EFFECTS (t
) = side_effects
;
3207 TREE_THIS_VOLATILE (t
)
3208 = (TREE_CODE_CLASS (code
) == tcc_reference
3209 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3215 build7_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3216 tree arg2
, tree arg3
, tree arg4
, tree arg5
,
3217 tree arg6 MEM_STAT_DECL
)
3219 bool constant
, read_only
, side_effects
, invariant
;
3222 gcc_assert (code
== TARGET_MEM_REF
);
3224 t
= make_node_stat (code PASS_MEM_STAT
);
3227 side_effects
= TREE_SIDE_EFFECTS (t
);
3237 TREE_SIDE_EFFECTS (t
) = side_effects
;
3238 TREE_THIS_VOLATILE (t
) = 0;
3243 /* Similar except don't specify the TREE_TYPE
3244 and leave the TREE_SIDE_EFFECTS as 0.
3245 It is permissible for arguments to be null,
3246 or even garbage if their values do not matter. */
3249 build_nt (enum tree_code code
, ...)
3258 t
= make_node (code
);
3259 length
= TREE_CODE_LENGTH (code
);
3261 for (i
= 0; i
< length
; i
++)
3262 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
3268 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
3269 We do NOT enter this node in any sort of symbol table.
3271 layout_decl is used to set up the decl's storage layout.
3272 Other slots are initialized to 0 or null pointers. */
3275 build_decl_stat (enum tree_code code
, tree name
, tree type MEM_STAT_DECL
)
3279 t
= make_node_stat (code PASS_MEM_STAT
);
3281 /* if (type == error_mark_node)
3282 type = integer_type_node; */
3283 /* That is not done, deliberately, so that having error_mark_node
3284 as the type can suppress useless errors in the use of this variable. */
3286 DECL_NAME (t
) = name
;
3287 TREE_TYPE (t
) = type
;
3289 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
3291 else if (code
== FUNCTION_DECL
)
3292 DECL_MODE (t
) = FUNCTION_MODE
;
3297 /* Builds and returns function declaration with NAME and TYPE. */
3300 build_fn_decl (const char *name
, tree type
)
3302 tree id
= get_identifier (name
);
3303 tree decl
= build_decl (FUNCTION_DECL
, id
, type
);
3305 DECL_EXTERNAL (decl
) = 1;
3306 TREE_PUBLIC (decl
) = 1;
3307 DECL_ARTIFICIAL (decl
) = 1;
3308 TREE_NOTHROW (decl
) = 1;
3314 /* BLOCK nodes are used to represent the structure of binding contours
3315 and declarations, once those contours have been exited and their contents
3316 compiled. This information is used for outputting debugging info. */
3319 build_block (tree vars
, tree subblocks
, tree supercontext
, tree chain
)
3321 tree block
= make_node (BLOCK
);
3323 BLOCK_VARS (block
) = vars
;
3324 BLOCK_SUBBLOCKS (block
) = subblocks
;
3325 BLOCK_SUPERCONTEXT (block
) = supercontext
;
3326 BLOCK_CHAIN (block
) = chain
;
3330 #if 1 /* ! defined(USE_MAPPED_LOCATION) */
3331 /* ??? gengtype doesn't handle conditionals */
3332 static GTY(()) source_locus last_annotated_node
;
3335 #ifdef USE_MAPPED_LOCATION
3338 expand_location (source_location loc
)
3340 expanded_location xloc
;
3349 const struct line_map
*map
= linemap_lookup (&line_table
, loc
);
3350 xloc
.file
= map
->to_file
;
3351 xloc
.line
= SOURCE_LINE (map
, loc
);
3352 xloc
.column
= SOURCE_COLUMN (map
, loc
);
3359 /* Record the exact location where an expression or an identifier were
3363 annotate_with_file_line (tree node
, const char *file
, int line
)
3365 /* Roughly one percent of the calls to this function are to annotate
3366 a node with the same information already attached to that node!
3367 Just return instead of wasting memory. */
3368 if (EXPR_LOCUS (node
)
3369 && EXPR_LINENO (node
) == line
3370 && (EXPR_FILENAME (node
) == file
3371 || !strcmp (EXPR_FILENAME (node
), file
)))
3373 last_annotated_node
= EXPR_LOCUS (node
);
3377 /* In heavily macroized code (such as GCC itself) this single
3378 entry cache can reduce the number of allocations by more
3380 if (last_annotated_node
3381 && last_annotated_node
->line
== line
3382 && (last_annotated_node
->file
== file
3383 || !strcmp (last_annotated_node
->file
, file
)))
3385 SET_EXPR_LOCUS (node
, last_annotated_node
);
3389 SET_EXPR_LOCUS (node
, ggc_alloc (sizeof (location_t
)));
3390 EXPR_LINENO (node
) = line
;
3391 EXPR_FILENAME (node
) = file
;
3392 last_annotated_node
= EXPR_LOCUS (node
);
3396 annotate_with_locus (tree node
, location_t locus
)
3398 annotate_with_file_line (node
, locus
.file
, locus
.line
);
3402 /* Source location accessor functions. */
3405 /* The source location of this expression. Non-tree_exp nodes such as
3406 decls and constants can be shared among multiple locations, so
3409 expr_location (tree node
)
3411 #ifdef USE_MAPPED_LOCATION
3412 if (GIMPLE_STMT_P (node
))
3413 return GIMPLE_STMT_LOCUS (node
);
3414 return EXPR_P (node
) ? node
->exp
.locus
: UNKNOWN_LOCATION
;
3416 if (GIMPLE_STMT_P (node
))
3417 return EXPR_HAS_LOCATION (node
)
3418 ? *GIMPLE_STMT_LOCUS (node
) : UNKNOWN_LOCATION
;
3419 return EXPR_HAS_LOCATION (node
) ? *node
->exp
.locus
: UNKNOWN_LOCATION
;
3424 set_expr_location (tree node
, location_t locus
)
3426 #ifdef USE_MAPPED_LOCATION
3427 if (GIMPLE_STMT_P (node
))
3428 GIMPLE_STMT_LOCUS (node
) = locus
;
3430 EXPR_CHECK (node
)->exp
.locus
= locus
;
3432 annotate_with_locus (node
, locus
);
3437 expr_has_location (tree node
)
3439 #ifdef USE_MAPPED_LOCATION
3440 return expr_location (node
) != UNKNOWN_LOCATION
;
3442 return expr_locus (node
) != NULL
;
3446 #ifdef USE_MAPPED_LOCATION
3451 expr_locus (tree node
)
3453 #ifdef USE_MAPPED_LOCATION
3454 if (GIMPLE_STMT_P (node
))
3455 return &GIMPLE_STMT_LOCUS (node
);
3456 return EXPR_P (node
) ? &node
->exp
.locus
: (location_t
*) NULL
;
3458 if (GIMPLE_STMT_P (node
))
3459 return GIMPLE_STMT_LOCUS (node
);
3460 /* ?? The cast below was originally "(location_t *)" in the macro,
3461 but that makes no sense. ?? */
3462 return EXPR_P (node
) ? node
->exp
.locus
: (source_locus
) NULL
;
3467 set_expr_locus (tree node
,
3468 #ifdef USE_MAPPED_LOCATION
3469 source_location
*loc
3475 #ifdef USE_MAPPED_LOCATION
3478 if (GIMPLE_STMT_P (node
))
3479 GIMPLE_STMT_LOCUS (node
) = UNKNOWN_LOCATION
;
3481 EXPR_CHECK (node
)->exp
.locus
= UNKNOWN_LOCATION
;
3485 if (GIMPLE_STMT_P (node
))
3486 GIMPLE_STMT_LOCUS (node
) = *loc
;
3488 EXPR_CHECK (node
)->exp
.locus
= *loc
;
3491 if (GIMPLE_STMT_P (node
))
3492 GIMPLE_STMT_LOCUS (node
) = loc
;
3494 EXPR_CHECK (node
)->exp
.locus
= loc
;
3499 expr_filename (tree node
)
3501 #ifdef USE_MAPPED_LOCATION
3502 if (GIMPLE_STMT_P (node
))
3503 return &LOCATION_FILE (GIMPLE_STMT_LOCUS (node
));
3504 return &LOCATION_FILE (EXPR_CHECK (node
)->exp
.locus
);
3506 if (GIMPLE_STMT_P (node
))
3507 return &GIMPLE_STMT_LOCUS (node
)->file
;
3508 return &(EXPR_CHECK (node
)->exp
.locus
->file
);
3513 expr_lineno (tree node
)
3515 #ifdef USE_MAPPED_LOCATION
3516 if (GIMPLE_STMT_P (node
))
3517 return &LOCATION_LINE (GIMPLE_STMT_LOCUS (node
));
3518 return &LOCATION_LINE (EXPR_CHECK (node
)->exp
.locus
);
3520 if (GIMPLE_STMT_P (node
))
3521 return &GIMPLE_STMT_LOCUS (node
)->line
;
3522 return &EXPR_CHECK (node
)->exp
.locus
->line
;
3526 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
3530 build_decl_attribute_variant (tree ddecl
, tree attribute
)
3532 DECL_ATTRIBUTES (ddecl
) = attribute
;
3536 /* Borrowed from hashtab.c iterative_hash implementation. */
3537 #define mix(a,b,c) \
3539 a -= b; a -= c; a ^= (c>>13); \
3540 b -= c; b -= a; b ^= (a<< 8); \
3541 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
3542 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
3543 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
3544 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
3545 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
3546 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
3547 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
3551 /* Produce good hash value combining VAL and VAL2. */
3552 static inline hashval_t
3553 iterative_hash_hashval_t (hashval_t val
, hashval_t val2
)
3555 /* the golden ratio; an arbitrary value. */
3556 hashval_t a
= 0x9e3779b9;
3562 /* Produce good hash value combining PTR and VAL2. */
3563 static inline hashval_t
3564 iterative_hash_pointer (void *ptr
, hashval_t val2
)
3566 if (sizeof (ptr
) == sizeof (hashval_t
))
3567 return iterative_hash_hashval_t ((size_t) ptr
, val2
);
3570 hashval_t a
= (hashval_t
) (size_t) ptr
;
3571 /* Avoid warnings about shifting of more than the width of the type on
3572 hosts that won't execute this path. */
3574 hashval_t b
= (hashval_t
) ((size_t) ptr
>> (sizeof (hashval_t
) * 8 + zero
));
3580 /* Produce good hash value combining VAL and VAL2. */
3581 static inline hashval_t
3582 iterative_hash_host_wide_int (HOST_WIDE_INT val
, hashval_t val2
)
3584 if (sizeof (HOST_WIDE_INT
) == sizeof (hashval_t
))
3585 return iterative_hash_hashval_t (val
, val2
);
3588 hashval_t a
= (hashval_t
) val
;
3589 /* Avoid warnings about shifting of more than the width of the type on
3590 hosts that won't execute this path. */
3592 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 8 + zero
));
3594 if (sizeof (HOST_WIDE_INT
) > 2 * sizeof (hashval_t
))
3596 hashval_t a
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 16 + zero
));
3597 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 24 + zero
));
3604 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3605 is ATTRIBUTE and its qualifiers are QUALS.
3607 Record such modified types already made so we don't make duplicates. */
3610 build_type_attribute_qual_variant (tree ttype
, tree attribute
, int quals
)
3612 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
3614 hashval_t hashcode
= 0;
3616 enum tree_code code
= TREE_CODE (ttype
);
3618 ntype
= copy_node (ttype
);
3620 TYPE_POINTER_TO (ntype
) = 0;
3621 TYPE_REFERENCE_TO (ntype
) = 0;
3622 TYPE_ATTRIBUTES (ntype
) = attribute
;
3624 if (TYPE_STRUCTURAL_EQUALITY_P (ttype
))
3625 SET_TYPE_STRUCTURAL_EQUALITY (ntype
);
3627 TYPE_CANONICAL (ntype
)
3628 = build_qualified_type (TYPE_CANONICAL (ttype
), quals
);
3630 /* Create a new main variant of TYPE. */
3631 TYPE_MAIN_VARIANT (ntype
) = ntype
;
3632 TYPE_NEXT_VARIANT (ntype
) = 0;
3633 set_type_quals (ntype
, TYPE_UNQUALIFIED
);
3635 hashcode
= iterative_hash_object (code
, hashcode
);
3636 if (TREE_TYPE (ntype
))
3637 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype
)),
3639 hashcode
= attribute_hash_list (attribute
, hashcode
);
3641 switch (TREE_CODE (ntype
))
3644 hashcode
= type_hash_list (TYPE_ARG_TYPES (ntype
), hashcode
);
3647 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype
)),
3651 hashcode
= iterative_hash_object
3652 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype
)), hashcode
);
3653 hashcode
= iterative_hash_object
3654 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype
)), hashcode
);
3658 unsigned int precision
= TYPE_PRECISION (ntype
);
3659 hashcode
= iterative_hash_object (precision
, hashcode
);
3666 ntype
= type_hash_canon (hashcode
, ntype
);
3668 /* If the target-dependent attributes make NTYPE different from
3669 its canonical type, we will need to use structural equality
3670 checks for this qualified type. */
3671 if (!targetm
.comp_type_attributes (ntype
, ttype
))
3672 SET_TYPE_STRUCTURAL_EQUALITY (ntype
);
3674 ttype
= build_qualified_type (ntype
, quals
);
3681 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3684 Record such modified types already made so we don't make duplicates. */
3687 build_type_attribute_variant (tree ttype
, tree attribute
)
3689 return build_type_attribute_qual_variant (ttype
, attribute
,
3690 TYPE_QUALS (ttype
));
3693 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3696 We try both `text' and `__text__', ATTR may be either one. */
3697 /* ??? It might be a reasonable simplification to require ATTR to be only
3698 `text'. One might then also require attribute lists to be stored in
3699 their canonicalized form. */
3702 is_attribute_with_length_p (const char *attr
, int attr_len
, tree ident
)
3707 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
3710 p
= IDENTIFIER_POINTER (ident
);
3711 ident_len
= IDENTIFIER_LENGTH (ident
);
3713 if (ident_len
== attr_len
3714 && strcmp (attr
, p
) == 0)
3717 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
3720 gcc_assert (attr
[1] == '_');
3721 gcc_assert (attr
[attr_len
- 2] == '_');
3722 gcc_assert (attr
[attr_len
- 1] == '_');
3723 if (ident_len
== attr_len
- 4
3724 && strncmp (attr
+ 2, p
, attr_len
- 4) == 0)
3729 if (ident_len
== attr_len
+ 4
3730 && p
[0] == '_' && p
[1] == '_'
3731 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
3732 && strncmp (attr
, p
+ 2, attr_len
) == 0)
3739 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3742 We try both `text' and `__text__', ATTR may be either one. */
3745 is_attribute_p (const char *attr
, tree ident
)
3747 return is_attribute_with_length_p (attr
, strlen (attr
), ident
);
3750 /* Given an attribute name and a list of attributes, return a pointer to the
3751 attribute's list element if the attribute is part of the list, or NULL_TREE
3752 if not found. If the attribute appears more than once, this only
3753 returns the first occurrence; the TREE_CHAIN of the return value should
3754 be passed back in if further occurrences are wanted. */
3757 lookup_attribute (const char *attr_name
, tree list
)
3760 size_t attr_len
= strlen (attr_name
);
3762 for (l
= list
; l
; l
= TREE_CHAIN (l
))
3764 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
3765 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
3772 /* Remove any instances of attribute ATTR_NAME in LIST and return the
3776 remove_attribute (const char *attr_name
, tree list
)
3779 size_t attr_len
= strlen (attr_name
);
3781 for (p
= &list
; *p
; )
3784 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
3785 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
3786 *p
= TREE_CHAIN (l
);
3788 p
= &TREE_CHAIN (l
);
3794 /* Return an attribute list that is the union of a1 and a2. */
3797 merge_attributes (tree a1
, tree a2
)
3801 /* Either one unset? Take the set one. */
3803 if ((attributes
= a1
) == 0)
3806 /* One that completely contains the other? Take it. */
3808 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
3810 if (attribute_list_contained (a2
, a1
))
3814 /* Pick the longest list, and hang on the other list. */
3816 if (list_length (a1
) < list_length (a2
))
3817 attributes
= a2
, a2
= a1
;
3819 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
3822 for (a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
3825 a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
3828 if (TREE_VALUE (a
) != NULL
3829 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
3830 && TREE_VALUE (a2
) != NULL
3831 && TREE_CODE (TREE_VALUE (a2
)) == TREE_LIST
)
3833 if (simple_cst_list_equal (TREE_VALUE (a
),
3834 TREE_VALUE (a2
)) == 1)
3837 else if (simple_cst_equal (TREE_VALUE (a
),
3838 TREE_VALUE (a2
)) == 1)
3843 a1
= copy_node (a2
);
3844 TREE_CHAIN (a1
) = attributes
;
3853 /* Given types T1 and T2, merge their attributes and return
3857 merge_type_attributes (tree t1
, tree t2
)
3859 return merge_attributes (TYPE_ATTRIBUTES (t1
),
3860 TYPE_ATTRIBUTES (t2
));
3863 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
3867 merge_decl_attributes (tree olddecl
, tree newdecl
)
3869 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
3870 DECL_ATTRIBUTES (newdecl
));
3873 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
3875 /* Specialization of merge_decl_attributes for various Windows targets.
3877 This handles the following situation:
3879 __declspec (dllimport) int foo;
3882 The second instance of `foo' nullifies the dllimport. */
3885 merge_dllimport_decl_attributes (tree old
, tree
new)
3888 int delete_dllimport_p
= 1;
3890 /* What we need to do here is remove from `old' dllimport if it doesn't
3891 appear in `new'. dllimport behaves like extern: if a declaration is
3892 marked dllimport and a definition appears later, then the object
3893 is not dllimport'd. We also remove a `new' dllimport if the old list
3894 contains dllexport: dllexport always overrides dllimport, regardless
3895 of the order of declaration. */
3896 if (!VAR_OR_FUNCTION_DECL_P (new))
3897 delete_dllimport_p
= 0;
3898 else if (DECL_DLLIMPORT_P (new)
3899 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old
)))
3901 DECL_DLLIMPORT_P (new) = 0;
3902 warning (OPT_Wattributes
, "%q+D already declared with dllexport attribute: "
3903 "dllimport ignored", new);
3905 else if (DECL_DLLIMPORT_P (old
) && !DECL_DLLIMPORT_P (new))
3907 /* Warn about overriding a symbol that has already been used. eg:
3908 extern int __attribute__ ((dllimport)) foo;
3909 int* bar () {return &foo;}
3912 if (TREE_USED (old
))
3914 warning (0, "%q+D redeclared without dllimport attribute "
3915 "after being referenced with dll linkage", new);
3916 /* If we have used a variable's address with dllimport linkage,
3917 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
3918 decl may already have had TREE_INVARIANT and TREE_CONSTANT
3920 We still remove the attribute so that assembler code refers
3921 to '&foo rather than '_imp__foo'. */
3922 if (TREE_CODE (old
) == VAR_DECL
&& TREE_ADDRESSABLE (old
))
3923 DECL_DLLIMPORT_P (new) = 1;
3926 /* Let an inline definition silently override the external reference,
3927 but otherwise warn about attribute inconsistency. */
3928 else if (TREE_CODE (new) == VAR_DECL
3929 || !DECL_DECLARED_INLINE_P (new))
3930 warning (OPT_Wattributes
, "%q+D redeclared without dllimport attribute: "
3931 "previous dllimport ignored", new);
3934 delete_dllimport_p
= 0;
3936 a
= merge_attributes (DECL_ATTRIBUTES (old
), DECL_ATTRIBUTES (new));
3938 if (delete_dllimport_p
)
3941 const size_t attr_len
= strlen ("dllimport");
3943 /* Scan the list for dllimport and delete it. */
3944 for (prev
= NULL_TREE
, t
= a
; t
; prev
= t
, t
= TREE_CHAIN (t
))
3946 if (is_attribute_with_length_p ("dllimport", attr_len
,
3949 if (prev
== NULL_TREE
)
3952 TREE_CHAIN (prev
) = TREE_CHAIN (t
);
3961 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
3962 struct attribute_spec.handler. */
3965 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
3970 /* These attributes may apply to structure and union types being created,
3971 but otherwise should pass to the declaration involved. */
3974 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
3975 | (int) ATTR_FLAG_ARRAY_NEXT
))
3977 *no_add_attrs
= true;
3978 return tree_cons (name
, args
, NULL_TREE
);
3980 if (TREE_CODE (node
) != RECORD_TYPE
&& TREE_CODE (node
) != UNION_TYPE
)
3982 warning (OPT_Wattributes
, "%qs attribute ignored",
3983 IDENTIFIER_POINTER (name
));
3984 *no_add_attrs
= true;
3990 if (TREE_CODE (node
) != FUNCTION_DECL
3991 && TREE_CODE (node
) != VAR_DECL
)
3993 *no_add_attrs
= true;
3994 warning (OPT_Wattributes
, "%qs attribute ignored",
3995 IDENTIFIER_POINTER (name
));
3999 /* Report error on dllimport ambiguities seen now before they cause
4001 else if (is_attribute_p ("dllimport", name
))
4003 /* Honor any target-specific overrides. */
4004 if (!targetm
.valid_dllimport_attribute_p (node
))
4005 *no_add_attrs
= true;
4007 else if (TREE_CODE (node
) == FUNCTION_DECL
4008 && DECL_DECLARED_INLINE_P (node
))
4010 warning (OPT_Wattributes
, "inline function %q+D declared as "
4011 " dllimport: attribute ignored", node
);
4012 *no_add_attrs
= true;
4014 /* Like MS, treat definition of dllimported variables and
4015 non-inlined functions on declaration as syntax errors. */
4016 else if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
))
4018 error ("function %q+D definition is marked dllimport", node
);
4019 *no_add_attrs
= true;
4022 else if (TREE_CODE (node
) == VAR_DECL
)
4024 if (DECL_INITIAL (node
))
4026 error ("variable %q+D definition is marked dllimport",
4028 *no_add_attrs
= true;
4031 /* `extern' needn't be specified with dllimport.
4032 Specify `extern' now and hope for the best. Sigh. */
4033 DECL_EXTERNAL (node
) = 1;
4034 /* Also, implicitly give dllimport'd variables declared within
4035 a function global scope, unless declared static. */
4036 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
4037 TREE_PUBLIC (node
) = 1;
4040 if (*no_add_attrs
== false)
4041 DECL_DLLIMPORT_P (node
) = 1;
4044 /* Report error if symbol is not accessible at global scope. */
4045 if (!TREE_PUBLIC (node
)
4046 && (TREE_CODE (node
) == VAR_DECL
4047 || TREE_CODE (node
) == FUNCTION_DECL
))
4049 error ("external linkage required for symbol %q+D because of "
4050 "%qs attribute", node
, IDENTIFIER_POINTER (name
));
4051 *no_add_attrs
= true;
4057 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
4059 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
4060 of the various TYPE_QUAL values. */
4063 set_type_quals (tree type
, int type_quals
)
4065 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
4066 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
4067 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
4070 /* Returns true iff cand is equivalent to base with type_quals. */
4073 check_qualified_type (tree cand
, tree base
, int type_quals
)
4075 return (TYPE_QUALS (cand
) == type_quals
4076 && TYPE_NAME (cand
) == TYPE_NAME (base
)
4077 /* Apparently this is needed for Objective-C. */
4078 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
4079 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
4080 TYPE_ATTRIBUTES (base
)));
4083 /* Return a version of the TYPE, qualified as indicated by the
4084 TYPE_QUALS, if one exists. If no qualified version exists yet,
4085 return NULL_TREE. */
4088 get_qualified_type (tree type
, int type_quals
)
4092 if (TYPE_QUALS (type
) == type_quals
)
4095 /* Search the chain of variants to see if there is already one there just
4096 like the one we need to have. If so, use that existing one. We must
4097 preserve the TYPE_NAME, since there is code that depends on this. */
4098 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
4099 if (check_qualified_type (t
, type
, type_quals
))
4105 /* Like get_qualified_type, but creates the type if it does not
4106 exist. This function never returns NULL_TREE. */
4109 build_qualified_type (tree type
, int type_quals
)
4113 /* See if we already have the appropriate qualified variant. */
4114 t
= get_qualified_type (type
, type_quals
);
4116 /* If not, build it. */
4119 t
= build_variant_type_copy (type
);
4120 set_type_quals (t
, type_quals
);
4122 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
4123 /* Propagate structural equality. */
4124 SET_TYPE_STRUCTURAL_EQUALITY (t
);
4125 else if (TYPE_CANONICAL (type
) != type
)
4126 /* Build the underlying canonical type, since it is different
4128 TYPE_CANONICAL (t
) = build_qualified_type (TYPE_CANONICAL (type
),
4131 /* T is its own canonical type. */
4132 TYPE_CANONICAL (t
) = t
;
4139 /* Create a new distinct copy of TYPE. The new type is made its own
4140 MAIN_VARIANT. If TYPE requires structural equality checks, the
4141 resulting type requires structural equality checks; otherwise, its
4142 TYPE_CANONICAL points to itself. */
4145 build_distinct_type_copy (tree type
)
4147 tree t
= copy_node (type
);
4149 TYPE_POINTER_TO (t
) = 0;
4150 TYPE_REFERENCE_TO (t
) = 0;
4152 /* Set the canonical type either to a new equivalence class, or
4153 propagate the need for structural equality checks. */
4154 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
4155 SET_TYPE_STRUCTURAL_EQUALITY (t
);
4157 TYPE_CANONICAL (t
) = t
;
4159 /* Make it its own variant. */
4160 TYPE_MAIN_VARIANT (t
) = t
;
4161 TYPE_NEXT_VARIANT (t
) = 0;
4166 /* Create a new variant of TYPE, equivalent but distinct. This is so
4167 the caller can modify it. TYPE_CANONICAL for the return type will
4168 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
4169 are considered equal by the language itself (or that both types
4170 require structural equality checks). */
4173 build_variant_type_copy (tree type
)
4175 tree t
, m
= TYPE_MAIN_VARIANT (type
);
4177 t
= build_distinct_type_copy (type
);
4179 /* Since we're building a variant, assume that it is a non-semantic
4180 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
4181 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
4183 /* Add the new type to the chain of variants of TYPE. */
4184 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
4185 TYPE_NEXT_VARIANT (m
) = t
;
4186 TYPE_MAIN_VARIANT (t
) = m
;
4191 /* Return true if the from tree in both tree maps are equal. */
4194 tree_map_eq (const void *va
, const void *vb
)
4196 const struct tree_map
*a
= va
, *b
= vb
;
4197 return (a
->from
== b
->from
);
4200 /* Hash a from tree in a tree_map. */
4203 tree_map_hash (const void *item
)
4205 return (((const struct tree_map
*) item
)->hash
);
4208 /* Return true if this tree map structure is marked for garbage collection
4209 purposes. We simply return true if the from tree is marked, so that this
4210 structure goes away when the from tree goes away. */
4213 tree_map_marked_p (const void *p
)
4215 tree from
= ((struct tree_map
*) p
)->from
;
4217 return ggc_marked_p (from
);
4220 /* Return true if the trees in the tree_int_map *'s VA and VB are equal. */
4223 tree_int_map_eq (const void *va
, const void *vb
)
4225 const struct tree_int_map
*a
= va
, *b
= vb
;
4226 return (a
->from
== b
->from
);
4229 /* Hash a from tree in the tree_int_map * ITEM. */
4232 tree_int_map_hash (const void *item
)
4234 return htab_hash_pointer (((const struct tree_int_map
*)item
)->from
);
4237 /* Return true if this tree int map structure is marked for garbage collection
4238 purposes. We simply return true if the from tree_int_map *P's from tree is marked, so that this
4239 structure goes away when the from tree goes away. */
4242 tree_int_map_marked_p (const void *p
)
4244 tree from
= ((struct tree_int_map
*) p
)->from
;
4246 return ggc_marked_p (from
);
4248 /* Lookup an init priority for FROM, and return it if we find one. */
4251 decl_init_priority_lookup (tree from
)
4253 struct tree_int_map
*h
, in
;
4256 h
= htab_find_with_hash (init_priority_for_decl
,
4257 &in
, htab_hash_pointer (from
));
4263 /* Insert a mapping FROM->TO in the init priority hashtable. */
4266 decl_init_priority_insert (tree from
, unsigned short to
)
4268 struct tree_int_map
*h
;
4271 h
= ggc_alloc (sizeof (struct tree_int_map
));
4274 loc
= htab_find_slot_with_hash (init_priority_for_decl
, h
,
4275 htab_hash_pointer (from
), INSERT
);
4276 *(struct tree_int_map
**) loc
= h
;
4279 /* Look up a restrict qualified base decl for FROM. */
4282 decl_restrict_base_lookup (tree from
)
4288 h
= htab_find_with_hash (restrict_base_for_decl
, &in
,
4289 htab_hash_pointer (from
));
4290 return h
? h
->to
: NULL_TREE
;
4293 /* Record the restrict qualified base TO for FROM. */
4296 decl_restrict_base_insert (tree from
, tree to
)
4301 h
= ggc_alloc (sizeof (struct tree_map
));
4302 h
->hash
= htab_hash_pointer (from
);
4305 loc
= htab_find_slot_with_hash (restrict_base_for_decl
, h
, h
->hash
, INSERT
);
4306 *(struct tree_map
**) loc
= h
;
4309 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
4312 print_debug_expr_statistics (void)
4314 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
4315 (long) htab_size (debug_expr_for_decl
),
4316 (long) htab_elements (debug_expr_for_decl
),
4317 htab_collisions (debug_expr_for_decl
));
4320 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
4323 print_value_expr_statistics (void)
4325 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
4326 (long) htab_size (value_expr_for_decl
),
4327 (long) htab_elements (value_expr_for_decl
),
4328 htab_collisions (value_expr_for_decl
));
4331 /* Print out statistics for the RESTRICT_BASE_FOR_DECL hash table, but
4332 don't print anything if the table is empty. */
4335 print_restrict_base_statistics (void)
4337 if (htab_elements (restrict_base_for_decl
) != 0)
4339 "RESTRICT_BASE hash: size %ld, %ld elements, %f collisions\n",
4340 (long) htab_size (restrict_base_for_decl
),
4341 (long) htab_elements (restrict_base_for_decl
),
4342 htab_collisions (restrict_base_for_decl
));
4345 /* Lookup a debug expression for FROM, and return it if we find one. */
4348 decl_debug_expr_lookup (tree from
)
4350 struct tree_map
*h
, in
;
4353 h
= htab_find_with_hash (debug_expr_for_decl
, &in
, htab_hash_pointer (from
));
4359 /* Insert a mapping FROM->TO in the debug expression hashtable. */
4362 decl_debug_expr_insert (tree from
, tree to
)
4367 h
= ggc_alloc (sizeof (struct tree_map
));
4368 h
->hash
= htab_hash_pointer (from
);
4371 loc
= htab_find_slot_with_hash (debug_expr_for_decl
, h
, h
->hash
, INSERT
);
4372 *(struct tree_map
**) loc
= h
;
4375 /* Lookup a value expression for FROM, and return it if we find one. */
4378 decl_value_expr_lookup (tree from
)
4380 struct tree_map
*h
, in
;
4383 h
= htab_find_with_hash (value_expr_for_decl
, &in
, htab_hash_pointer (from
));
4389 /* Insert a mapping FROM->TO in the value expression hashtable. */
4392 decl_value_expr_insert (tree from
, tree to
)
4397 h
= ggc_alloc (sizeof (struct tree_map
));
4398 h
->hash
= htab_hash_pointer (from
);
4401 loc
= htab_find_slot_with_hash (value_expr_for_decl
, h
, h
->hash
, INSERT
);
4402 *(struct tree_map
**) loc
= h
;
4405 /* Hashing of types so that we don't make duplicates.
4406 The entry point is `type_hash_canon'. */
4408 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
4409 with types in the TREE_VALUE slots), by adding the hash codes
4410 of the individual types. */
4413 type_hash_list (tree list
, hashval_t hashcode
)
4417 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
4418 if (TREE_VALUE (tail
) != error_mark_node
)
4419 hashcode
= iterative_hash_object (TYPE_HASH (TREE_VALUE (tail
)),
4425 /* These are the Hashtable callback functions. */
4427 /* Returns true iff the types are equivalent. */
4430 type_hash_eq (const void *va
, const void *vb
)
4432 const struct type_hash
*a
= va
, *b
= vb
;
4434 /* First test the things that are the same for all types. */
4435 if (a
->hash
!= b
->hash
4436 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
4437 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
4438 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
4439 TYPE_ATTRIBUTES (b
->type
))
4440 || TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
4441 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
))
4444 switch (TREE_CODE (a
->type
))
4449 case REFERENCE_TYPE
:
4453 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
4456 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
4457 && !(TYPE_VALUES (a
->type
)
4458 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
4459 && TYPE_VALUES (b
->type
)
4460 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
4461 && type_list_equal (TYPE_VALUES (a
->type
),
4462 TYPE_VALUES (b
->type
))))
4465 /* ... fall through ... */
4470 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
4471 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
4472 TYPE_MAX_VALUE (b
->type
)))
4473 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
4474 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
4475 TYPE_MIN_VALUE (b
->type
))));
4478 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
4481 return (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
4482 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
4483 || (TYPE_ARG_TYPES (a
->type
)
4484 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
4485 && TYPE_ARG_TYPES (b
->type
)
4486 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
4487 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
4488 TYPE_ARG_TYPES (b
->type
)))));
4491 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
4495 case QUAL_UNION_TYPE
:
4496 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
4497 || (TYPE_FIELDS (a
->type
)
4498 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
4499 && TYPE_FIELDS (b
->type
)
4500 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
4501 && type_list_equal (TYPE_FIELDS (a
->type
),
4502 TYPE_FIELDS (b
->type
))));
4505 return (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
4506 || (TYPE_ARG_TYPES (a
->type
)
4507 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
4508 && TYPE_ARG_TYPES (b
->type
)
4509 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
4510 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
4511 TYPE_ARG_TYPES (b
->type
))));
4518 /* Return the cached hash value. */
4521 type_hash_hash (const void *item
)
4523 return ((const struct type_hash
*) item
)->hash
;
4526 /* Look in the type hash table for a type isomorphic to TYPE.
4527 If one is found, return it. Otherwise return 0. */
4530 type_hash_lookup (hashval_t hashcode
, tree type
)
4532 struct type_hash
*h
, in
;
4534 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
4535 must call that routine before comparing TYPE_ALIGNs. */
4541 h
= htab_find_with_hash (type_hash_table
, &in
, hashcode
);
4547 /* Add an entry to the type-hash-table
4548 for a type TYPE whose hash code is HASHCODE. */
4551 type_hash_add (hashval_t hashcode
, tree type
)
4553 struct type_hash
*h
;
4556 h
= ggc_alloc (sizeof (struct type_hash
));
4559 loc
= htab_find_slot_with_hash (type_hash_table
, h
, hashcode
, INSERT
);
4560 *(struct type_hash
**) loc
= h
;
4563 /* Given TYPE, and HASHCODE its hash code, return the canonical
4564 object for an identical type if one already exists.
4565 Otherwise, return TYPE, and record it as the canonical object.
4567 To use this function, first create a type of the sort you want.
4568 Then compute its hash code from the fields of the type that
4569 make it different from other similar types.
4570 Then call this function and use the value. */
4573 type_hash_canon (unsigned int hashcode
, tree type
)
4577 /* The hash table only contains main variants, so ensure that's what we're
4579 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
4581 if (!lang_hooks
.types
.hash_types
)
4584 /* See if the type is in the hash table already. If so, return it.
4585 Otherwise, add the type. */
4586 t1
= type_hash_lookup (hashcode
, type
);
4589 #ifdef GATHER_STATISTICS
4590 tree_node_counts
[(int) t_kind
]--;
4591 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type
);
4597 type_hash_add (hashcode
, type
);
4602 /* See if the data pointed to by the type hash table is marked. We consider
4603 it marked if the type is marked or if a debug type number or symbol
4604 table entry has been made for the type. This reduces the amount of
4605 debugging output and eliminates that dependency of the debug output on
4606 the number of garbage collections. */
4609 type_hash_marked_p (const void *p
)
4611 tree type
= ((struct type_hash
*) p
)->type
;
4613 return ggc_marked_p (type
) || TYPE_SYMTAB_POINTER (type
);
4617 print_type_hash_statistics (void)
4619 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
4620 (long) htab_size (type_hash_table
),
4621 (long) htab_elements (type_hash_table
),
4622 htab_collisions (type_hash_table
));
4625 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
4626 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
4627 by adding the hash codes of the individual attributes. */
4630 attribute_hash_list (tree list
, hashval_t hashcode
)
4634 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
4635 /* ??? Do we want to add in TREE_VALUE too? */
4636 hashcode
= iterative_hash_object
4637 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail
)), hashcode
);
4641 /* Given two lists of attributes, return true if list l2 is
4642 equivalent to l1. */
4645 attribute_list_equal (tree l1
, tree l2
)
4647 return attribute_list_contained (l1
, l2
)
4648 && attribute_list_contained (l2
, l1
);
4651 /* Given two lists of attributes, return true if list L2 is
4652 completely contained within L1. */
4653 /* ??? This would be faster if attribute names were stored in a canonicalized
4654 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
4655 must be used to show these elements are equivalent (which they are). */
4656 /* ??? It's not clear that attributes with arguments will always be handled
4660 attribute_list_contained (tree l1
, tree l2
)
4664 /* First check the obvious, maybe the lists are identical. */
4668 /* Maybe the lists are similar. */
4669 for (t1
= l1
, t2
= l2
;
4671 && TREE_PURPOSE (t1
) == TREE_PURPOSE (t2
)
4672 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
4673 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
));
4675 /* Maybe the lists are equal. */
4676 if (t1
== 0 && t2
== 0)
4679 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
4682 for (attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)), l1
);
4684 attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
4687 if (TREE_VALUE (t2
) != NULL
4688 && TREE_CODE (TREE_VALUE (t2
)) == TREE_LIST
4689 && TREE_VALUE (attr
) != NULL
4690 && TREE_CODE (TREE_VALUE (attr
)) == TREE_LIST
)
4692 if (simple_cst_list_equal (TREE_VALUE (t2
),
4693 TREE_VALUE (attr
)) == 1)
4696 else if (simple_cst_equal (TREE_VALUE (t2
), TREE_VALUE (attr
)) == 1)
4707 /* Given two lists of types
4708 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
4709 return 1 if the lists contain the same types in the same order.
4710 Also, the TREE_PURPOSEs must match. */
4713 type_list_equal (tree l1
, tree l2
)
4717 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
4718 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
4719 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
4720 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
4721 && (TREE_TYPE (TREE_PURPOSE (t1
))
4722 == TREE_TYPE (TREE_PURPOSE (t2
))))))
4728 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
4729 given by TYPE. If the argument list accepts variable arguments,
4730 then this function counts only the ordinary arguments. */
4733 type_num_arguments (tree type
)
4738 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
4739 /* If the function does not take a variable number of arguments,
4740 the last element in the list will have type `void'. */
4741 if (VOID_TYPE_P (TREE_VALUE (t
)))
4749 /* Nonzero if integer constants T1 and T2
4750 represent the same constant value. */
4753 tree_int_cst_equal (tree t1
, tree t2
)
4758 if (t1
== 0 || t2
== 0)
4761 if (TREE_CODE (t1
) == INTEGER_CST
4762 && TREE_CODE (t2
) == INTEGER_CST
4763 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
4764 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
4770 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
4771 The precise way of comparison depends on their data type. */
4774 tree_int_cst_lt (tree t1
, tree t2
)
4779 if (TYPE_UNSIGNED (TREE_TYPE (t1
)) != TYPE_UNSIGNED (TREE_TYPE (t2
)))
4781 int t1_sgn
= tree_int_cst_sgn (t1
);
4782 int t2_sgn
= tree_int_cst_sgn (t2
);
4784 if (t1_sgn
< t2_sgn
)
4786 else if (t1_sgn
> t2_sgn
)
4788 /* Otherwise, both are non-negative, so we compare them as
4789 unsigned just in case one of them would overflow a signed
4792 else if (!TYPE_UNSIGNED (TREE_TYPE (t1
)))
4793 return INT_CST_LT (t1
, t2
);
4795 return INT_CST_LT_UNSIGNED (t1
, t2
);
4798 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
4801 tree_int_cst_compare (tree t1
, tree t2
)
4803 if (tree_int_cst_lt (t1
, t2
))
4805 else if (tree_int_cst_lt (t2
, t1
))
4811 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
4812 the host. If POS is zero, the value can be represented in a single
4813 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
4814 be represented in a single unsigned HOST_WIDE_INT. */
4817 host_integerp (tree t
, int pos
)
4819 return (TREE_CODE (t
) == INTEGER_CST
4820 && ((TREE_INT_CST_HIGH (t
) == 0
4821 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) >= 0)
4822 || (! pos
&& TREE_INT_CST_HIGH (t
) == -1
4823 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0
4824 && !TYPE_UNSIGNED (TREE_TYPE (t
)))
4825 || (pos
&& TREE_INT_CST_HIGH (t
) == 0)));
4828 /* Return the HOST_WIDE_INT least significant bits of T if it is an
4829 INTEGER_CST and there is no overflow. POS is nonzero if the result must
4830 be non-negative. We must be able to satisfy the above conditions. */
4833 tree_low_cst (tree t
, int pos
)
4835 gcc_assert (host_integerp (t
, pos
));
4836 return TREE_INT_CST_LOW (t
);
4839 /* Return the most significant bit of the integer constant T. */
4842 tree_int_cst_msb (tree t
)
4846 unsigned HOST_WIDE_INT l
;
4848 /* Note that using TYPE_PRECISION here is wrong. We care about the
4849 actual bits, not the (arbitrary) range of the type. */
4850 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t
))) - 1;
4851 rshift_double (TREE_INT_CST_LOW (t
), TREE_INT_CST_HIGH (t
), prec
,
4852 2 * HOST_BITS_PER_WIDE_INT
, &l
, &h
, 0);
4853 return (l
& 1) == 1;
4856 /* Return an indication of the sign of the integer constant T.
4857 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
4858 Note that -1 will never be returned if T's type is unsigned. */
4861 tree_int_cst_sgn (tree t
)
4863 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
4865 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
4867 else if (TREE_INT_CST_HIGH (t
) < 0)
4873 /* Compare two constructor-element-type constants. Return 1 if the lists
4874 are known to be equal; otherwise return 0. */
4877 simple_cst_list_equal (tree l1
, tree l2
)
4879 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
4881 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
4884 l1
= TREE_CHAIN (l1
);
4885 l2
= TREE_CHAIN (l2
);
4891 /* Return truthvalue of whether T1 is the same tree structure as T2.
4892 Return 1 if they are the same.
4893 Return 0 if they are understandably different.
4894 Return -1 if either contains tree structure not understood by
4898 simple_cst_equal (tree t1
, tree t2
)
4900 enum tree_code code1
, code2
;
4906 if (t1
== 0 || t2
== 0)
4909 code1
= TREE_CODE (t1
);
4910 code2
= TREE_CODE (t2
);
4912 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
4914 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
4915 || code2
== NON_LVALUE_EXPR
)
4916 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
4918 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
4921 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
4922 || code2
== NON_LVALUE_EXPR
)
4923 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
4931 return (TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
4932 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
));
4935 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
4938 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
4939 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
4940 TREE_STRING_LENGTH (t1
)));
4944 unsigned HOST_WIDE_INT idx
;
4945 VEC(constructor_elt
, gc
) *v1
= CONSTRUCTOR_ELTS (t1
);
4946 VEC(constructor_elt
, gc
) *v2
= CONSTRUCTOR_ELTS (t2
);
4948 if (VEC_length (constructor_elt
, v1
) != VEC_length (constructor_elt
, v2
))
4951 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
4952 /* ??? Should we handle also fields here? */
4953 if (!simple_cst_equal (VEC_index (constructor_elt
, v1
, idx
)->value
,
4954 VEC_index (constructor_elt
, v2
, idx
)->value
))
4960 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
4963 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
4967 simple_cst_list_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
4970 /* Special case: if either target is an unallocated VAR_DECL,
4971 it means that it's going to be unified with whatever the
4972 TARGET_EXPR is really supposed to initialize, so treat it
4973 as being equivalent to anything. */
4974 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
4975 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
4976 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
4977 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
4978 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
4979 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
4982 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
4987 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
4989 case WITH_CLEANUP_EXPR
:
4990 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
4994 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
4997 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
4998 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5012 /* This general rule works for most tree codes. All exceptions should be
5013 handled above. If this is a language-specific tree code, we can't
5014 trust what might be in the operand, so say we don't know
5016 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
5019 switch (TREE_CODE_CLASS (code1
))
5023 case tcc_comparison
:
5024 case tcc_expression
:
5028 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
5030 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
5042 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
5043 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
5044 than U, respectively. */
5047 compare_tree_int (tree t
, unsigned HOST_WIDE_INT u
)
5049 if (tree_int_cst_sgn (t
) < 0)
5051 else if (TREE_INT_CST_HIGH (t
) != 0)
5053 else if (TREE_INT_CST_LOW (t
) == u
)
5055 else if (TREE_INT_CST_LOW (t
) < u
)
5061 /* Return true if CODE represents an associative tree code. Otherwise
5064 associative_tree_code (enum tree_code code
)
5083 /* Return true if CODE represents a commutative tree code. Otherwise
5086 commutative_tree_code (enum tree_code code
)
5099 case UNORDERED_EXPR
:
5103 case TRUTH_AND_EXPR
:
5104 case TRUTH_XOR_EXPR
:
5114 /* Generate a hash value for an expression. This can be used iteratively
5115 by passing a previous result as the "val" argument.
5117 This function is intended to produce the same hash for expressions which
5118 would compare equal using operand_equal_p. */
5121 iterative_hash_expr (tree t
, hashval_t val
)
5124 enum tree_code code
;
5128 return iterative_hash_pointer (t
, val
);
5130 code
= TREE_CODE (t
);
5134 /* Alas, constants aren't shared, so we can't rely on pointer
5137 val
= iterative_hash_host_wide_int (TREE_INT_CST_LOW (t
), val
);
5138 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t
), val
);
5141 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
5143 return iterative_hash_hashval_t (val2
, val
);
5146 return iterative_hash (TREE_STRING_POINTER (t
),
5147 TREE_STRING_LENGTH (t
), val
);
5149 val
= iterative_hash_expr (TREE_REALPART (t
), val
);
5150 return iterative_hash_expr (TREE_IMAGPART (t
), val
);
5152 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t
), val
);
5156 /* we can just compare by pointer. */
5157 return iterative_hash_pointer (t
, val
);
5160 /* A list of expressions, for a CALL_EXPR or as the elements of a
5162 for (; t
; t
= TREE_CHAIN (t
))
5163 val
= iterative_hash_expr (TREE_VALUE (t
), val
);
5167 unsigned HOST_WIDE_INT idx
;
5169 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
5171 val
= iterative_hash_expr (field
, val
);
5172 val
= iterative_hash_expr (value
, val
);
5177 /* When referring to a built-in FUNCTION_DECL, use the
5178 __builtin__ form. Otherwise nodes that compare equal
5179 according to operand_equal_p might get different
5181 if (DECL_BUILT_IN (t
))
5183 val
= iterative_hash_pointer (built_in_decls
[DECL_FUNCTION_CODE (t
)],
5187 /* else FALL THROUGH */
5189 class = TREE_CODE_CLASS (code
);
5191 if (class == tcc_declaration
)
5193 /* DECL's have a unique ID */
5194 val
= iterative_hash_host_wide_int (DECL_UID (t
), val
);
5198 gcc_assert (IS_EXPR_CODE_CLASS (class));
5200 val
= iterative_hash_object (code
, val
);
5202 /* Don't hash the type, that can lead to having nodes which
5203 compare equal according to operand_equal_p, but which
5204 have different hash codes. */
5205 if (code
== NOP_EXPR
5206 || code
== CONVERT_EXPR
5207 || code
== NON_LVALUE_EXPR
)
5209 /* Make sure to include signness in the hash computation. */
5210 val
+= TYPE_UNSIGNED (TREE_TYPE (t
));
5211 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
5214 else if (commutative_tree_code (code
))
5216 /* It's a commutative expression. We want to hash it the same
5217 however it appears. We do this by first hashing both operands
5218 and then rehashing based on the order of their independent
5220 hashval_t one
= iterative_hash_expr (TREE_OPERAND (t
, 0), 0);
5221 hashval_t two
= iterative_hash_expr (TREE_OPERAND (t
, 1), 0);
5225 t
= one
, one
= two
, two
= t
;
5227 val
= iterative_hash_hashval_t (one
, val
);
5228 val
= iterative_hash_hashval_t (two
, val
);
5231 for (i
= TREE_CODE_LENGTH (code
) - 1; i
>= 0; --i
)
5232 val
= iterative_hash_expr (TREE_OPERAND (t
, i
), val
);
5239 /* Constructors for pointer, array and function types.
5240 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
5241 constructed by language-dependent code, not here.) */
5243 /* Construct, lay out and return the type of pointers to TO_TYPE with
5244 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
5245 reference all of memory. If such a type has already been
5246 constructed, reuse it. */
5249 build_pointer_type_for_mode (tree to_type
, enum machine_mode mode
,
5254 if (to_type
== error_mark_node
)
5255 return error_mark_node
;
5257 /* In some cases, languages will have things that aren't a POINTER_TYPE
5258 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
5259 In that case, return that type without regard to the rest of our
5262 ??? This is a kludge, but consistent with the way this function has
5263 always operated and there doesn't seem to be a good way to avoid this
5265 if (TYPE_POINTER_TO (to_type
) != 0
5266 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
5267 return TYPE_POINTER_TO (to_type
);
5269 /* First, if we already have a type for pointers to TO_TYPE and it's
5270 the proper mode, use it. */
5271 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
5272 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
5275 t
= make_node (POINTER_TYPE
);
5277 TREE_TYPE (t
) = to_type
;
5278 TYPE_MODE (t
) = mode
;
5279 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
5280 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
5281 TYPE_POINTER_TO (to_type
) = t
;
5283 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
5284 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5285 else if (TYPE_CANONICAL (to_type
) != to_type
)
5287 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
5288 mode
, can_alias_all
);
5290 /* Lay out the type. This function has many callers that are concerned
5291 with expression-construction, and this simplifies them all. */
5297 /* By default build pointers in ptr_mode. */
5300 build_pointer_type (tree to_type
)
5302 return build_pointer_type_for_mode (to_type
, ptr_mode
, false);
5305 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
5308 build_reference_type_for_mode (tree to_type
, enum machine_mode mode
,
5313 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
5314 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
5315 In that case, return that type without regard to the rest of our
5318 ??? This is a kludge, but consistent with the way this function has
5319 always operated and there doesn't seem to be a good way to avoid this
5321 if (TYPE_REFERENCE_TO (to_type
) != 0
5322 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
5323 return TYPE_REFERENCE_TO (to_type
);
5325 /* First, if we already have a type for pointers to TO_TYPE and it's
5326 the proper mode, use it. */
5327 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
5328 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
5331 t
= make_node (REFERENCE_TYPE
);
5333 TREE_TYPE (t
) = to_type
;
5334 TYPE_MODE (t
) = mode
;
5335 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
5336 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
5337 TYPE_REFERENCE_TO (to_type
) = t
;
5339 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
5340 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5341 else if (TYPE_CANONICAL (to_type
) != to_type
)
5343 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
5344 mode
, can_alias_all
);
5352 /* Build the node for the type of references-to-TO_TYPE by default
5356 build_reference_type (tree to_type
)
5358 return build_reference_type_for_mode (to_type
, ptr_mode
, false);
5361 /* Build a type that is compatible with t but has no cv quals anywhere
5364 const char *const *const * -> char ***. */
5367 build_type_no_quals (tree t
)
5369 switch (TREE_CODE (t
))
5372 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
5374 TYPE_REF_CAN_ALIAS_ALL (t
));
5375 case REFERENCE_TYPE
:
5377 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
5379 TYPE_REF_CAN_ALIAS_ALL (t
));
5381 return TYPE_MAIN_VARIANT (t
);
5385 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
5386 MAXVAL should be the maximum value in the domain
5387 (one less than the length of the array).
5389 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
5390 We don't enforce this limit, that is up to caller (e.g. language front end).
5391 The limit exists because the result is a signed type and we don't handle
5392 sizes that use more than one HOST_WIDE_INT. */
5395 build_index_type (tree maxval
)
5397 tree itype
= make_node (INTEGER_TYPE
);
5399 TREE_TYPE (itype
) = sizetype
;
5400 TYPE_PRECISION (itype
) = TYPE_PRECISION (sizetype
);
5401 TYPE_MIN_VALUE (itype
) = size_zero_node
;
5402 TYPE_MAX_VALUE (itype
) = fold_convert (sizetype
, maxval
);
5403 TYPE_MODE (itype
) = TYPE_MODE (sizetype
);
5404 TYPE_SIZE (itype
) = TYPE_SIZE (sizetype
);
5405 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (sizetype
);
5406 TYPE_ALIGN (itype
) = TYPE_ALIGN (sizetype
);
5407 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (sizetype
);
5409 if (host_integerp (maxval
, 1))
5410 return type_hash_canon (tree_low_cst (maxval
, 1), itype
);
5413 /* Since we cannot hash this type, we need to compare it using
5414 structural equality checks. */
5415 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
5420 /* Builds a signed or unsigned integer type of precision PRECISION.
5421 Used for C bitfields whose precision does not match that of
5422 built-in target types. */
5424 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
5427 tree itype
= make_node (INTEGER_TYPE
);
5429 TYPE_PRECISION (itype
) = precision
;
5432 fixup_unsigned_type (itype
);
5434 fixup_signed_type (itype
);
5436 if (host_integerp (TYPE_MAX_VALUE (itype
), 1))
5437 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype
), 1), itype
);
5442 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
5443 ENUMERAL_TYPE or BOOLEAN_TYPE), with low bound LOWVAL and
5444 high bound HIGHVAL. If TYPE is NULL, sizetype is used. */
5447 build_range_type (tree type
, tree lowval
, tree highval
)
5449 tree itype
= make_node (INTEGER_TYPE
);
5451 TREE_TYPE (itype
) = type
;
5452 if (type
== NULL_TREE
)
5455 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
5456 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
5458 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
5459 TYPE_MODE (itype
) = TYPE_MODE (type
);
5460 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
5461 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
5462 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
5463 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
5465 if (host_integerp (lowval
, 0) && highval
!= 0 && host_integerp (highval
, 0))
5466 return type_hash_canon (tree_low_cst (highval
, 0)
5467 - tree_low_cst (lowval
, 0),
5473 /* Just like build_index_type, but takes lowval and highval instead
5474 of just highval (maxval). */
5477 build_index_2_type (tree lowval
, tree highval
)
5479 return build_range_type (sizetype
, lowval
, highval
);
5482 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
5483 and number of elements specified by the range of values of INDEX_TYPE.
5484 If such a type has already been constructed, reuse it. */
5487 build_array_type (tree elt_type
, tree index_type
)
5490 hashval_t hashcode
= 0;
5492 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
5494 error ("arrays of functions are not meaningful");
5495 elt_type
= integer_type_node
;
5498 t
= make_node (ARRAY_TYPE
);
5499 TREE_TYPE (t
) = elt_type
;
5500 TYPE_DOMAIN (t
) = index_type
;
5502 if (index_type
== 0)
5505 hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), hashcode
);
5506 t
= type_hash_canon (hashcode
, t
);
5510 if (TYPE_CANONICAL (t
) == t
)
5512 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
))
5513 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5514 else if (TYPE_CANONICAL (elt_type
) != elt_type
)
5516 = build_array_type (TYPE_CANONICAL (elt_type
), index_type
);
5522 hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), hashcode
);
5523 hashcode
= iterative_hash_object (TYPE_HASH (index_type
), hashcode
);
5524 t
= type_hash_canon (hashcode
, t
);
5526 if (!COMPLETE_TYPE_P (t
))
5529 if (TYPE_CANONICAL (t
) == t
)
5531 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
5532 || TYPE_STRUCTURAL_EQUALITY_P (index_type
))
5533 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5534 else if (TYPE_CANONICAL (elt_type
) != elt_type
5535 || TYPE_CANONICAL (index_type
) != index_type
)
5537 = build_array_type (TYPE_CANONICAL (elt_type
),
5538 TYPE_CANONICAL (index_type
));
5544 /* Return the TYPE of the elements comprising
5545 the innermost dimension of ARRAY. */
5548 get_inner_array_type (tree array
)
5550 tree type
= TREE_TYPE (array
);
5552 while (TREE_CODE (type
) == ARRAY_TYPE
)
5553 type
= TREE_TYPE (type
);
5558 /* Construct, lay out and return
5559 the type of functions returning type VALUE_TYPE
5560 given arguments of types ARG_TYPES.
5561 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
5562 are data type nodes for the arguments of the function.
5563 If such a type has already been constructed, reuse it. */
5566 build_function_type (tree value_type
, tree arg_types
)
5569 hashval_t hashcode
= 0;
5571 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
5573 error ("function return type cannot be function");
5574 value_type
= integer_type_node
;
5577 /* Make a node of the sort we want. */
5578 t
= make_node (FUNCTION_TYPE
);
5579 TREE_TYPE (t
) = value_type
;
5580 TYPE_ARG_TYPES (t
) = arg_types
;
5582 /* We don't have canonicalization of function types, yet. */
5583 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5585 /* If we already have such a type, use the old one. */
5586 hashcode
= iterative_hash_object (TYPE_HASH (value_type
), hashcode
);
5587 hashcode
= type_hash_list (arg_types
, hashcode
);
5588 t
= type_hash_canon (hashcode
, t
);
5590 if (!COMPLETE_TYPE_P (t
))
5595 /* Build a function type. The RETURN_TYPE is the type returned by the
5596 function. If additional arguments are provided, they are
5597 additional argument types. The list of argument types must always
5598 be terminated by NULL_TREE. */
5601 build_function_type_list (tree return_type
, ...)
5606 va_start (p
, return_type
);
5608 t
= va_arg (p
, tree
);
5609 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (p
, tree
))
5610 args
= tree_cons (NULL_TREE
, t
, args
);
5612 if (args
== NULL_TREE
)
5613 args
= void_list_node
;
5617 args
= nreverse (args
);
5618 TREE_CHAIN (last
) = void_list_node
;
5620 args
= build_function_type (return_type
, args
);
5626 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
5627 and ARGTYPES (a TREE_LIST) are the return type and arguments types
5628 for the method. An implicit additional parameter (of type
5629 pointer-to-BASETYPE) is added to the ARGTYPES. */
5632 build_method_type_directly (tree basetype
,
5640 /* Make a node of the sort we want. */
5641 t
= make_node (METHOD_TYPE
);
5643 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
5644 TREE_TYPE (t
) = rettype
;
5645 ptype
= build_pointer_type (basetype
);
5647 /* The actual arglist for this function includes a "hidden" argument
5648 which is "this". Put it into the list of argument types. */
5649 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
5650 TYPE_ARG_TYPES (t
) = argtypes
;
5652 /* We don't have canonicalization of method types yet. */
5653 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5655 /* If we already have such a type, use the old one. */
5656 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
5657 hashcode
= iterative_hash_object (TYPE_HASH (rettype
), hashcode
);
5658 hashcode
= type_hash_list (argtypes
, hashcode
);
5659 t
= type_hash_canon (hashcode
, t
);
5661 if (!COMPLETE_TYPE_P (t
))
5667 /* Construct, lay out and return the type of methods belonging to class
5668 BASETYPE and whose arguments and values are described by TYPE.
5669 If that type exists already, reuse it.
5670 TYPE must be a FUNCTION_TYPE node. */
5673 build_method_type (tree basetype
, tree type
)
5675 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
5677 return build_method_type_directly (basetype
,
5679 TYPE_ARG_TYPES (type
));
5682 /* Construct, lay out and return the type of offsets to a value
5683 of type TYPE, within an object of type BASETYPE.
5684 If a suitable offset type exists already, reuse it. */
5687 build_offset_type (tree basetype
, tree type
)
5690 hashval_t hashcode
= 0;
5692 /* Make a node of the sort we want. */
5693 t
= make_node (OFFSET_TYPE
);
5695 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
5696 TREE_TYPE (t
) = type
;
5698 /* If we already have such a type, use the old one. */
5699 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
5700 hashcode
= iterative_hash_object (TYPE_HASH (type
), hashcode
);
5701 t
= type_hash_canon (hashcode
, t
);
5703 if (!COMPLETE_TYPE_P (t
))
5706 if (TYPE_CANONICAL (t
) == t
)
5708 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
5709 || TYPE_STRUCTURAL_EQUALITY_P (type
))
5710 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5711 else if (TYPE_CANONICAL (basetype
) != basetype
5712 || TYPE_CANONICAL (type
) != type
)
5714 = build_offset_type (TYPE_CANONICAL (basetype
),
5715 TYPE_CANONICAL (type
));
5721 /* Create a complex type whose components are COMPONENT_TYPE. */
5724 build_complex_type (tree component_type
)
5729 /* Make a node of the sort we want. */
5730 t
= make_node (COMPLEX_TYPE
);
5732 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
5734 /* If we already have such a type, use the old one. */
5735 hashcode
= iterative_hash_object (TYPE_HASH (component_type
), 0);
5736 t
= type_hash_canon (hashcode
, t
);
5738 if (!COMPLETE_TYPE_P (t
))
5741 if (TYPE_CANONICAL (t
) == t
)
5743 if (TYPE_STRUCTURAL_EQUALITY_P (component_type
))
5744 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5745 else if (TYPE_CANONICAL (component_type
) != component_type
)
5747 = build_complex_type (TYPE_CANONICAL (component_type
));
5750 /* If we are writing Dwarf2 output we need to create a name,
5751 since complex is a fundamental type. */
5752 if ((write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
5756 if (component_type
== char_type_node
)
5757 name
= "complex char";
5758 else if (component_type
== signed_char_type_node
)
5759 name
= "complex signed char";
5760 else if (component_type
== unsigned_char_type_node
)
5761 name
= "complex unsigned char";
5762 else if (component_type
== short_integer_type_node
)
5763 name
= "complex short int";
5764 else if (component_type
== short_unsigned_type_node
)
5765 name
= "complex short unsigned int";
5766 else if (component_type
== integer_type_node
)
5767 name
= "complex int";
5768 else if (component_type
== unsigned_type_node
)
5769 name
= "complex unsigned int";
5770 else if (component_type
== long_integer_type_node
)
5771 name
= "complex long int";
5772 else if (component_type
== long_unsigned_type_node
)
5773 name
= "complex long unsigned int";
5774 else if (component_type
== long_long_integer_type_node
)
5775 name
= "complex long long int";
5776 else if (component_type
== long_long_unsigned_type_node
)
5777 name
= "complex long long unsigned int";
5782 TYPE_NAME (t
) = get_identifier (name
);
5785 return build_qualified_type (t
, TYPE_QUALS (component_type
));
5788 /* Return OP, stripped of any conversions to wider types as much as is safe.
5789 Converting the value back to OP's type makes a value equivalent to OP.
5791 If FOR_TYPE is nonzero, we return a value which, if converted to
5792 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
5794 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
5795 narrowest type that can hold the value, even if they don't exactly fit.
5796 Otherwise, bit-field references are changed to a narrower type
5797 only if they can be fetched directly from memory in that type.
5799 OP must have integer, real or enumeral type. Pointers are not allowed!
5801 There are some cases where the obvious value we could return
5802 would regenerate to OP if converted to OP's type,
5803 but would not extend like OP to wider types.
5804 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
5805 For example, if OP is (unsigned short)(signed char)-1,
5806 we avoid returning (signed char)-1 if FOR_TYPE is int,
5807 even though extending that to an unsigned short would regenerate OP,
5808 since the result of extending (signed char)-1 to (int)
5809 is different from (int) OP. */
5812 get_unwidened (tree op
, tree for_type
)
5814 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
5815 tree type
= TREE_TYPE (op
);
5817 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
5819 = (for_type
!= 0 && for_type
!= type
5820 && final_prec
> TYPE_PRECISION (type
)
5821 && TYPE_UNSIGNED (type
));
5824 while (TREE_CODE (op
) == NOP_EXPR
5825 || TREE_CODE (op
) == CONVERT_EXPR
)
5829 /* TYPE_PRECISION on vector types has different meaning
5830 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
5831 so avoid them here. */
5832 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
5835 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
5836 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
5838 /* Truncations are many-one so cannot be removed.
5839 Unless we are later going to truncate down even farther. */
5841 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
5844 /* See what's inside this conversion. If we decide to strip it,
5846 op
= TREE_OPERAND (op
, 0);
5848 /* If we have not stripped any zero-extensions (uns is 0),
5849 we can strip any kind of extension.
5850 If we have previously stripped a zero-extension,
5851 only zero-extensions can safely be stripped.
5852 Any extension can be stripped if the bits it would produce
5853 are all going to be discarded later by truncating to FOR_TYPE. */
5857 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
5859 /* TYPE_UNSIGNED says whether this is a zero-extension.
5860 Let's avoid computing it if it does not affect WIN
5861 and if UNS will not be needed again. */
5863 || TREE_CODE (op
) == NOP_EXPR
5864 || TREE_CODE (op
) == CONVERT_EXPR
)
5865 && TYPE_UNSIGNED (TREE_TYPE (op
)))
5873 if (TREE_CODE (op
) == COMPONENT_REF
5874 /* Since type_for_size always gives an integer type. */
5875 && TREE_CODE (type
) != REAL_TYPE
5876 /* Don't crash if field not laid out yet. */
5877 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
5878 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
5880 unsigned int innerprec
5881 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
5882 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
5883 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
5884 type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
5886 /* We can get this structure field in the narrowest type it fits in.
5887 If FOR_TYPE is 0, do this only for a field that matches the
5888 narrower type exactly and is aligned for it
5889 The resulting extension to its nominal type (a fullword type)
5890 must fit the same conditions as for other extensions. */
5893 && INT_CST_LT_UNSIGNED (TYPE_SIZE (type
), TYPE_SIZE (TREE_TYPE (op
)))
5894 && (for_type
|| ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1)))
5895 && (! uns
|| final_prec
<= innerprec
|| unsignedp
))
5897 win
= build3 (COMPONENT_REF
, type
, TREE_OPERAND (op
, 0),
5898 TREE_OPERAND (op
, 1), NULL_TREE
);
5899 TREE_SIDE_EFFECTS (win
) = TREE_SIDE_EFFECTS (op
);
5900 TREE_THIS_VOLATILE (win
) = TREE_THIS_VOLATILE (op
);
5907 /* Return OP or a simpler expression for a narrower value
5908 which can be sign-extended or zero-extended to give back OP.
5909 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
5910 or 0 if the value should be sign-extended. */
5913 get_narrower (tree op
, int *unsignedp_ptr
)
5918 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
5920 while (TREE_CODE (op
) == NOP_EXPR
)
5923 = (TYPE_PRECISION (TREE_TYPE (op
))
5924 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
5926 /* Truncations are many-one so cannot be removed. */
5930 /* See what's inside this conversion. If we decide to strip it,
5935 op
= TREE_OPERAND (op
, 0);
5936 /* An extension: the outermost one can be stripped,
5937 but remember whether it is zero or sign extension. */
5939 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
5940 /* Otherwise, if a sign extension has been stripped,
5941 only sign extensions can now be stripped;
5942 if a zero extension has been stripped, only zero-extensions. */
5943 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
5947 else /* bitschange == 0 */
5949 /* A change in nominal type can always be stripped, but we must
5950 preserve the unsignedness. */
5952 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
5954 op
= TREE_OPERAND (op
, 0);
5955 /* Keep trying to narrow, but don't assign op to win if it
5956 would turn an integral type into something else. */
5957 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
5964 if (TREE_CODE (op
) == COMPONENT_REF
5965 /* Since type_for_size always gives an integer type. */
5966 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
5967 /* Ensure field is laid out already. */
5968 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
5969 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
5971 unsigned HOST_WIDE_INT innerprec
5972 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
5973 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
5974 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
5975 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
5977 /* We can get this structure field in a narrower type that fits it,
5978 but the resulting extension to its nominal type (a fullword type)
5979 must satisfy the same conditions as for other extensions.
5981 Do this only for fields that are aligned (not bit-fields),
5982 because when bit-field insns will be used there is no
5983 advantage in doing this. */
5985 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
5986 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
5987 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
5991 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
5992 win
= build3 (COMPONENT_REF
, type
, TREE_OPERAND (op
, 0),
5993 TREE_OPERAND (op
, 1), NULL_TREE
);
5994 TREE_SIDE_EFFECTS (win
) = TREE_SIDE_EFFECTS (op
);
5995 TREE_THIS_VOLATILE (win
) = TREE_THIS_VOLATILE (op
);
5998 *unsignedp_ptr
= uns
;
6002 /* Nonzero if integer constant C has a value that is permissible
6003 for type TYPE (an INTEGER_TYPE). */
6006 int_fits_type_p (tree c
, tree type
)
6008 tree type_low_bound
= TYPE_MIN_VALUE (type
);
6009 tree type_high_bound
= TYPE_MAX_VALUE (type
);
6010 bool ok_for_low_bound
, ok_for_high_bound
;
6013 /* If at least one bound of the type is a constant integer, we can check
6014 ourselves and maybe make a decision. If no such decision is possible, but
6015 this type is a subtype, try checking against that. Otherwise, use
6016 force_fit_type, which checks against the precision.
6018 Compute the status for each possibly constant bound, and return if we see
6019 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
6020 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
6021 for "constant known to fit". */
6023 /* Check if C >= type_low_bound. */
6024 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
6026 if (tree_int_cst_lt (c
, type_low_bound
))
6028 ok_for_low_bound
= true;
6031 ok_for_low_bound
= false;
6033 /* Check if c <= type_high_bound. */
6034 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
6036 if (tree_int_cst_lt (type_high_bound
, c
))
6038 ok_for_high_bound
= true;
6041 ok_for_high_bound
= false;
6043 /* If the constant fits both bounds, the result is known. */
6044 if (ok_for_low_bound
&& ok_for_high_bound
)
6047 /* Perform some generic filtering which may allow making a decision
6048 even if the bounds are not constant. First, negative integers
6049 never fit in unsigned types, */
6050 if (TYPE_UNSIGNED (type
) && tree_int_cst_sgn (c
) < 0)
6053 /* Second, narrower types always fit in wider ones. */
6054 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
6057 /* Third, unsigned integers with top bit set never fit signed types. */
6058 if (! TYPE_UNSIGNED (type
)
6059 && TYPE_UNSIGNED (TREE_TYPE (c
))
6060 && tree_int_cst_msb (c
))
6063 /* If we haven't been able to decide at this point, there nothing more we
6064 can check ourselves here. Look at the base type if we have one and it
6065 has the same precision. */
6066 if (TREE_CODE (type
) == INTEGER_TYPE
6067 && TREE_TYPE (type
) != 0
6068 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
6069 return int_fits_type_p (c
, TREE_TYPE (type
));
6071 /* Or to force_fit_type, if nothing else. */
6072 tmp
= copy_node (c
);
6073 TREE_TYPE (tmp
) = type
;
6074 tmp
= force_fit_type (tmp
, -1, false, false);
6075 return TREE_INT_CST_HIGH (tmp
) == TREE_INT_CST_HIGH (c
)
6076 && TREE_INT_CST_LOW (tmp
) == TREE_INT_CST_LOW (c
);
6079 /* Subprogram of following function. Called by walk_tree.
6081 Return *TP if it is an automatic variable or parameter of the
6082 function passed in as DATA. */
6085 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
6087 tree fn
= (tree
) data
;
6092 else if (DECL_P (*tp
)
6093 && lang_hooks
.tree_inlining
.auto_var_in_fn_p (*tp
, fn
))
6099 /* Returns true if T is, contains, or refers to a type with variable
6100 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
6101 arguments, but not the return type. If FN is nonzero, only return
6102 true if a modifier of the type or position of FN is a variable or
6103 parameter inside FN.
6105 This concept is more general than that of C99 'variably modified types':
6106 in C99, a struct type is never variably modified because a VLA may not
6107 appear as a structure member. However, in GNU C code like:
6109 struct S { int i[f()]; };
6111 is valid, and other languages may define similar constructs. */
6114 variably_modified_type_p (tree type
, tree fn
)
6118 /* Test if T is either variable (if FN is zero) or an expression containing
6119 a variable in FN. */
6120 #define RETURN_TRUE_IF_VAR(T) \
6121 do { tree _t = (T); \
6122 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
6123 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
6124 return true; } while (0)
6126 if (type
== error_mark_node
)
6129 /* If TYPE itself has variable size, it is variably modified. */
6130 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
6131 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
6133 switch (TREE_CODE (type
))
6136 case REFERENCE_TYPE
:
6138 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
6144 /* If TYPE is a function type, it is variably modified if the
6145 return type is variably modified. */
6146 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
6154 /* Scalar types are variably modified if their end points
6156 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
6157 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
6162 case QUAL_UNION_TYPE
:
6163 /* We can't see if any of the fields are variably-modified by the
6164 definition we normally use, since that would produce infinite
6165 recursion via pointers. */
6166 /* This is variably modified if some field's type is. */
6167 for (t
= TYPE_FIELDS (type
); t
; t
= TREE_CHAIN (t
))
6168 if (TREE_CODE (t
) == FIELD_DECL
)
6170 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
6171 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
6172 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
6174 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
6175 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
6180 /* Do not call ourselves to avoid infinite recursion. This is
6181 variably modified if the element type is. */
6182 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
6183 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
6190 /* The current language may have other cases to check, but in general,
6191 all other types are not variably modified. */
6192 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
6194 #undef RETURN_TRUE_IF_VAR
6197 /* Given a DECL or TYPE, return the scope in which it was declared, or
6198 NULL_TREE if there is no containing scope. */
6201 get_containing_scope (tree t
)
6203 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
6206 /* Return the innermost context enclosing DECL that is
6207 a FUNCTION_DECL, or zero if none. */
6210 decl_function_context (tree decl
)
6214 if (TREE_CODE (decl
) == ERROR_MARK
)
6217 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
6218 where we look up the function at runtime. Such functions always take
6219 a first argument of type 'pointer to real context'.
6221 C++ should really be fixed to use DECL_CONTEXT for the real context,
6222 and use something else for the "virtual context". */
6223 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
6226 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
6228 context
= DECL_CONTEXT (decl
);
6230 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
6232 if (TREE_CODE (context
) == BLOCK
)
6233 context
= BLOCK_SUPERCONTEXT (context
);
6235 context
= get_containing_scope (context
);
6241 /* Return the innermost context enclosing DECL that is
6242 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
6243 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
6246 decl_type_context (tree decl
)
6248 tree context
= DECL_CONTEXT (decl
);
6251 switch (TREE_CODE (context
))
6253 case NAMESPACE_DECL
:
6254 case TRANSLATION_UNIT_DECL
:
6259 case QUAL_UNION_TYPE
:
6264 context
= DECL_CONTEXT (context
);
6268 context
= BLOCK_SUPERCONTEXT (context
);
6278 /* CALL is a CALL_EXPR. Return the declaration for the function
6279 called, or NULL_TREE if the called function cannot be
6283 get_callee_fndecl (tree call
)
6287 if (call
== error_mark_node
)
6290 /* It's invalid to call this function with anything but a
6292 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
6294 /* The first operand to the CALL is the address of the function
6296 addr
= TREE_OPERAND (call
, 0);
6300 /* If this is a readonly function pointer, extract its initial value. */
6301 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
6302 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
6303 && DECL_INITIAL (addr
))
6304 addr
= DECL_INITIAL (addr
);
6306 /* If the address is just `&f' for some function `f', then we know
6307 that `f' is being called. */
6308 if (TREE_CODE (addr
) == ADDR_EXPR
6309 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
6310 return TREE_OPERAND (addr
, 0);
6312 /* We couldn't figure out what was being called. Maybe the front
6313 end has some idea. */
6314 return lang_hooks
.lang_get_callee_fndecl (call
);
6317 /* Print debugging information about tree nodes generated during the compile,
6318 and any language-specific information. */
6321 dump_tree_statistics (void)
6323 #ifdef GATHER_STATISTICS
6325 int total_nodes
, total_bytes
;
6328 fprintf (stderr
, "\n??? tree nodes created\n\n");
6329 #ifdef GATHER_STATISTICS
6330 fprintf (stderr
, "Kind Nodes Bytes\n");
6331 fprintf (stderr
, "---------------------------------------\n");
6332 total_nodes
= total_bytes
= 0;
6333 for (i
= 0; i
< (int) all_kinds
; i
++)
6335 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
6336 tree_node_counts
[i
], tree_node_sizes
[i
]);
6337 total_nodes
+= tree_node_counts
[i
];
6338 total_bytes
+= tree_node_sizes
[i
];
6340 fprintf (stderr
, "---------------------------------------\n");
6341 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
6342 fprintf (stderr
, "---------------------------------------\n");
6343 ssanames_print_statistics ();
6344 phinodes_print_statistics ();
6346 fprintf (stderr
, "(No per-node statistics)\n");
6348 print_type_hash_statistics ();
6349 print_debug_expr_statistics ();
6350 print_value_expr_statistics ();
6351 print_restrict_base_statistics ();
6352 lang_hooks
.print_statistics ();
6355 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
6357 /* Generate a crc32 of a string. */
6360 crc32_string (unsigned chksum
, const char *string
)
6364 unsigned value
= *string
<< 24;
6367 for (ix
= 8; ix
--; value
<<= 1)
6371 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
6380 /* P is a string that will be used in a symbol. Mask out any characters
6381 that are not valid in that context. */
6384 clean_symbol_name (char *p
)
6388 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
6391 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
6398 /* Generate a name for a special-purpose function function.
6399 The generated name may need to be unique across the whole link.
6400 TYPE is some string to identify the purpose of this function to the
6401 linker or collect2; it must start with an uppercase letter,
6403 I - for constructors
6405 N - for C++ anonymous namespaces
6406 F - for DWARF unwind frame information. */
6409 get_file_function_name (const char *type
)
6415 /* If we already have a name we know to be unique, just use that. */
6416 if (first_global_object_name
)
6417 p
= first_global_object_name
;
6418 /* If the target is handling the constructors/destructors, they
6419 will be local to this file and the name is only necessary for
6420 debugging purposes. */
6421 else if ((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
6423 const char *file
= main_input_filename
;
6425 file
= input_filename
;
6426 /* Just use the file's basename, because the full pathname
6427 might be quite long. */
6428 p
= strrchr (file
, '/');
6433 p
= q
= ASTRDUP (p
);
6434 clean_symbol_name (q
);
6438 /* Otherwise, the name must be unique across the entire link.
6439 We don't have anything that we know to be unique to this translation
6440 unit, so use what we do have and throw in some randomness. */
6442 const char *name
= weak_global_object_name
;
6443 const char *file
= main_input_filename
;
6448 file
= input_filename
;
6450 len
= strlen (file
);
6451 q
= alloca (9 * 2 + len
+ 1);
6452 memcpy (q
, file
, len
+ 1);
6453 clean_symbol_name (q
);
6455 sprintf (q
+ len
, "_%08X_%08X", crc32_string (0, name
),
6456 crc32_string (0, flag_random_seed
));
6461 buf
= alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
) + strlen (type
));
6463 /* Set up the name of the file-level functions we may need.
6464 Use a global object (which is already required to be unique over
6465 the program) rather than the file name (which imposes extra
6467 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
6469 return get_identifier (buf
);
6472 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
6474 /* Complain that the tree code of NODE does not match the expected 0
6475 terminated list of trailing codes. The trailing code list can be
6476 empty, for a more vague error message. FILE, LINE, and FUNCTION
6477 are of the caller. */
6480 tree_check_failed (const tree node
, const char *file
,
6481 int line
, const char *function
, ...)
6485 unsigned length
= 0;
6488 va_start (args
, function
);
6489 while ((code
= va_arg (args
, int)))
6490 length
+= 4 + strlen (tree_code_name
[code
]);
6494 va_start (args
, function
);
6495 length
+= strlen ("expected ");
6496 buffer
= alloca (length
);
6498 while ((code
= va_arg (args
, int)))
6500 const char *prefix
= length
? " or " : "expected ";
6502 strcpy (buffer
+ length
, prefix
);
6503 length
+= strlen (prefix
);
6504 strcpy (buffer
+ length
, tree_code_name
[code
]);
6505 length
+= strlen (tree_code_name
[code
]);
6510 buffer
= (char *)"unexpected node";
6512 internal_error ("tree check: %s, have %s in %s, at %s:%d",
6513 buffer
, tree_code_name
[TREE_CODE (node
)],
6514 function
, trim_filename (file
), line
);
6517 /* Complain that the tree code of NODE does match the expected 0
6518 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
6522 tree_not_check_failed (const tree node
, const char *file
,
6523 int line
, const char *function
, ...)
6527 unsigned length
= 0;
6530 va_start (args
, function
);
6531 while ((code
= va_arg (args
, int)))
6532 length
+= 4 + strlen (tree_code_name
[code
]);
6534 va_start (args
, function
);
6535 buffer
= alloca (length
);
6537 while ((code
= va_arg (args
, int)))
6541 strcpy (buffer
+ length
, " or ");
6544 strcpy (buffer
+ length
, tree_code_name
[code
]);
6545 length
+= strlen (tree_code_name
[code
]);
6549 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
6550 buffer
, tree_code_name
[TREE_CODE (node
)],
6551 function
, trim_filename (file
), line
);
6554 /* Similar to tree_check_failed, except that we check for a class of tree
6555 code, given in CL. */
6558 tree_class_check_failed (const tree node
, const enum tree_code_class cl
,
6559 const char *file
, int line
, const char *function
)
6562 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
6563 TREE_CODE_CLASS_STRING (cl
),
6564 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
6565 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
6568 /* Similar to tree_check_failed, except that instead of specifying a
6569 dozen codes, use the knowledge that they're all sequential. */
6572 tree_range_check_failed (const tree node
, const char *file
, int line
,
6573 const char *function
, enum tree_code c1
,
6577 unsigned length
= 0;
6580 for (c
= c1
; c
<= c2
; ++c
)
6581 length
+= 4 + strlen (tree_code_name
[c
]);
6583 length
+= strlen ("expected ");
6584 buffer
= alloca (length
);
6587 for (c
= c1
; c
<= c2
; ++c
)
6589 const char *prefix
= length
? " or " : "expected ";
6591 strcpy (buffer
+ length
, prefix
);
6592 length
+= strlen (prefix
);
6593 strcpy (buffer
+ length
, tree_code_name
[c
]);
6594 length
+= strlen (tree_code_name
[c
]);
6597 internal_error ("tree check: %s, have %s in %s, at %s:%d",
6598 buffer
, tree_code_name
[TREE_CODE (node
)],
6599 function
, trim_filename (file
), line
);
6603 /* Similar to tree_check_failed, except that we check that a tree does
6604 not have the specified code, given in CL. */
6607 tree_not_class_check_failed (const tree node
, const enum tree_code_class cl
,
6608 const char *file
, int line
, const char *function
)
6611 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
6612 TREE_CODE_CLASS_STRING (cl
),
6613 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
6614 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
6618 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
6621 omp_clause_check_failed (const tree node
, const char *file
, int line
,
6622 const char *function
, enum omp_clause_code code
)
6624 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
6625 omp_clause_code_name
[code
], tree_code_name
[TREE_CODE (node
)],
6626 function
, trim_filename (file
), line
);
6630 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
6633 omp_clause_range_check_failed (const tree node
, const char *file
, int line
,
6634 const char *function
, enum omp_clause_code c1
,
6635 enum omp_clause_code c2
)
6638 unsigned length
= 0;
6639 enum omp_clause_code c
;
6641 for (c
= c1
; c
<= c2
; ++c
)
6642 length
+= 4 + strlen (omp_clause_code_name
[c
]);
6644 length
+= strlen ("expected ");
6645 buffer
= alloca (length
);
6648 for (c
= c1
; c
<= c2
; ++c
)
6650 const char *prefix
= length
? " or " : "expected ";
6652 strcpy (buffer
+ length
, prefix
);
6653 length
+= strlen (prefix
);
6654 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
6655 length
+= strlen (omp_clause_code_name
[c
]);
6658 internal_error ("tree check: %s, have %s in %s, at %s:%d",
6659 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
6660 function
, trim_filename (file
), line
);
6664 #undef DEFTREESTRUCT
6665 #define DEFTREESTRUCT(VAL, NAME) NAME,
6667 static const char *ts_enum_names
[] = {
6668 #include "treestruct.def"
6670 #undef DEFTREESTRUCT
6672 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
6674 /* Similar to tree_class_check_failed, except that we check for
6675 whether CODE contains the tree structure identified by EN. */
6678 tree_contains_struct_check_failed (const tree node
,
6679 const enum tree_node_structure_enum en
,
6680 const char *file
, int line
,
6681 const char *function
)
6684 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
6686 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
6690 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
6691 (dynamically sized) vector. */
6694 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
6695 const char *function
)
6698 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
6699 idx
+ 1, len
, function
, trim_filename (file
), line
);
6702 /* Similar to above, except that the check is for the bounds of a PHI_NODE's
6703 (dynamically sized) vector. */
6706 phi_node_elt_check_failed (int idx
, int len
, const char *file
, int line
,
6707 const char *function
)
6710 ("tree check: accessed elt %d of phi_node with %d elts in %s, at %s:%d",
6711 idx
+ 1, len
, function
, trim_filename (file
), line
);
6714 /* Similar to above, except that the check is for the bounds of the operand
6715 vector of an expression node. */
6718 tree_operand_check_failed (int idx
, enum tree_code code
, const char *file
,
6719 int line
, const char *function
)
6722 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
6723 idx
+ 1, tree_code_name
[code
], TREE_CODE_LENGTH (code
),
6724 function
, trim_filename (file
), line
);
6727 /* Similar to above, except that the check is for the number of
6728 operands of an OMP_CLAUSE node. */
6731 omp_clause_operand_check_failed (int idx
, tree t
, const char *file
,
6732 int line
, const char *function
)
6735 ("tree check: accessed operand %d of omp_clause %s with %d operands "
6736 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
6737 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
6738 trim_filename (file
), line
);
6740 #endif /* ENABLE_TREE_CHECKING */
6742 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
6743 and mapped to the machine mode MODE. Initialize its fields and build
6744 the information necessary for debugging output. */
6747 make_vector_type (tree innertype
, int nunits
, enum machine_mode mode
)
6750 hashval_t hashcode
= 0;
6752 /* Build a main variant, based on the main variant of the inner type, then
6753 use it to build the variant we return. */
6754 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
6755 && TYPE_MAIN_VARIANT (innertype
) != innertype
)
6756 return build_type_attribute_qual_variant (
6757 make_vector_type (TYPE_MAIN_VARIANT (innertype
), nunits
, mode
),
6758 TYPE_ATTRIBUTES (innertype
),
6759 TYPE_QUALS (innertype
));
6761 t
= make_node (VECTOR_TYPE
);
6762 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
6763 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
6764 TYPE_MODE (t
) = mode
;
6765 TYPE_READONLY (t
) = TYPE_READONLY (innertype
);
6766 TYPE_VOLATILE (t
) = TYPE_VOLATILE (innertype
);
6768 if (TYPE_STRUCTURAL_EQUALITY_P (innertype
))
6769 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6770 else if (TYPE_CANONICAL (innertype
) != innertype
6771 || mode
!= VOIDmode
)
6773 = make_vector_type (TYPE_CANONICAL (innertype
), nunits
, VOIDmode
);
6778 tree index
= build_int_cst (NULL_TREE
, nunits
- 1);
6779 tree array
= build_array_type (innertype
, build_index_type (index
));
6780 tree rt
= make_node (RECORD_TYPE
);
6782 TYPE_FIELDS (rt
) = build_decl (FIELD_DECL
, get_identifier ("f"), array
);
6783 DECL_CONTEXT (TYPE_FIELDS (rt
)) = rt
;
6785 TYPE_DEBUG_REPRESENTATION_TYPE (t
) = rt
;
6786 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
6787 the representation type, and we want to find that die when looking up
6788 the vector type. This is most easily achieved by making the TYPE_UID
6790 TYPE_UID (rt
) = TYPE_UID (t
);
6793 hashcode
= iterative_hash_host_wide_int (VECTOR_TYPE
, hashcode
);
6794 hashcode
= iterative_hash_host_wide_int (mode
, hashcode
);
6795 hashcode
= iterative_hash_object (TYPE_HASH (innertype
), hashcode
);
6796 return type_hash_canon (hashcode
, t
);
6800 make_or_reuse_type (unsigned size
, int unsignedp
)
6802 if (size
== INT_TYPE_SIZE
)
6803 return unsignedp
? unsigned_type_node
: integer_type_node
;
6804 if (size
== CHAR_TYPE_SIZE
)
6805 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
6806 if (size
== SHORT_TYPE_SIZE
)
6807 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
6808 if (size
== LONG_TYPE_SIZE
)
6809 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
6810 if (size
== LONG_LONG_TYPE_SIZE
)
6811 return (unsignedp
? long_long_unsigned_type_node
6812 : long_long_integer_type_node
);
6815 return make_unsigned_type (size
);
6817 return make_signed_type (size
);
6820 /* Create nodes for all integer types (and error_mark_node) using the sizes
6821 of C datatypes. The caller should call set_sizetype soon after calling
6822 this function to select one of the types as sizetype. */
6825 build_common_tree_nodes (bool signed_char
, bool signed_sizetype
)
6827 error_mark_node
= make_node (ERROR_MARK
);
6828 TREE_TYPE (error_mark_node
) = error_mark_node
;
6830 initialize_sizetypes (signed_sizetype
);
6832 /* Define both `signed char' and `unsigned char'. */
6833 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
6834 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
6835 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
6836 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
6838 /* Define `char', which is like either `signed char' or `unsigned char'
6839 but not the same as either. */
6842 ? make_signed_type (CHAR_TYPE_SIZE
)
6843 : make_unsigned_type (CHAR_TYPE_SIZE
));
6844 TYPE_STRING_FLAG (char_type_node
) = 1;
6846 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
6847 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
6848 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
6849 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
6850 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
6851 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
6852 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
6853 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
6855 /* Define a boolean type. This type only represents boolean values but
6856 may be larger than char depending on the value of BOOL_TYPE_SIZE.
6857 Front ends which want to override this size (i.e. Java) can redefine
6858 boolean_type_node before calling build_common_tree_nodes_2. */
6859 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
6860 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
6861 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
6862 TYPE_PRECISION (boolean_type_node
) = 1;
6864 /* Fill in the rest of the sized types. Reuse existing type nodes
6866 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
6867 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
6868 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
6869 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
6870 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
6872 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
6873 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
6874 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
6875 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
6876 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
6878 access_public_node
= get_identifier ("public");
6879 access_protected_node
= get_identifier ("protected");
6880 access_private_node
= get_identifier ("private");
6883 /* Call this function after calling build_common_tree_nodes and set_sizetype.
6884 It will create several other common tree nodes. */
6887 build_common_tree_nodes_2 (int short_double
)
6889 /* Define these next since types below may used them. */
6890 integer_zero_node
= build_int_cst (NULL_TREE
, 0);
6891 integer_one_node
= build_int_cst (NULL_TREE
, 1);
6892 integer_minus_one_node
= build_int_cst (NULL_TREE
, -1);
6894 size_zero_node
= size_int (0);
6895 size_one_node
= size_int (1);
6896 bitsize_zero_node
= bitsize_int (0);
6897 bitsize_one_node
= bitsize_int (1);
6898 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
6900 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
6901 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
6903 void_type_node
= make_node (VOID_TYPE
);
6904 layout_type (void_type_node
);
6906 /* We are not going to have real types in C with less than byte alignment,
6907 so we might as well not have any types that claim to have it. */
6908 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
6909 TYPE_USER_ALIGN (void_type_node
) = 0;
6911 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
6912 layout_type (TREE_TYPE (null_pointer_node
));
6914 ptr_type_node
= build_pointer_type (void_type_node
);
6916 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
6917 fileptr_type_node
= ptr_type_node
;
6919 float_type_node
= make_node (REAL_TYPE
);
6920 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
6921 layout_type (float_type_node
);
6923 double_type_node
= make_node (REAL_TYPE
);
6925 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
6927 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
6928 layout_type (double_type_node
);
6930 long_double_type_node
= make_node (REAL_TYPE
);
6931 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
6932 layout_type (long_double_type_node
);
6934 float_ptr_type_node
= build_pointer_type (float_type_node
);
6935 double_ptr_type_node
= build_pointer_type (double_type_node
);
6936 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
6937 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
6939 /* Fixed size integer types. */
6940 uint32_type_node
= build_nonstandard_integer_type (32, true);
6941 uint64_type_node
= build_nonstandard_integer_type (64, true);
6943 /* Decimal float types. */
6944 dfloat32_type_node
= make_node (REAL_TYPE
);
6945 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
6946 layout_type (dfloat32_type_node
);
6947 TYPE_MODE (dfloat32_type_node
) = SDmode
;
6948 dfloat32_ptr_type_node
= build_pointer_type (dfloat32_type_node
);
6950 dfloat64_type_node
= make_node (REAL_TYPE
);
6951 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
6952 layout_type (dfloat64_type_node
);
6953 TYPE_MODE (dfloat64_type_node
) = DDmode
;
6954 dfloat64_ptr_type_node
= build_pointer_type (dfloat64_type_node
);
6956 dfloat128_type_node
= make_node (REAL_TYPE
);
6957 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
6958 layout_type (dfloat128_type_node
);
6959 TYPE_MODE (dfloat128_type_node
) = TDmode
;
6960 dfloat128_ptr_type_node
= build_pointer_type (dfloat128_type_node
);
6962 complex_integer_type_node
= make_node (COMPLEX_TYPE
);
6963 TREE_TYPE (complex_integer_type_node
) = integer_type_node
;
6964 layout_type (complex_integer_type_node
);
6966 complex_float_type_node
= make_node (COMPLEX_TYPE
);
6967 TREE_TYPE (complex_float_type_node
) = float_type_node
;
6968 layout_type (complex_float_type_node
);
6970 complex_double_type_node
= make_node (COMPLEX_TYPE
);
6971 TREE_TYPE (complex_double_type_node
) = double_type_node
;
6972 layout_type (complex_double_type_node
);
6974 complex_long_double_type_node
= make_node (COMPLEX_TYPE
);
6975 TREE_TYPE (complex_long_double_type_node
) = long_double_type_node
;
6976 layout_type (complex_long_double_type_node
);
6979 tree t
= targetm
.build_builtin_va_list ();
6981 /* Many back-ends define record types without setting TYPE_NAME.
6982 If we copied the record type here, we'd keep the original
6983 record type without a name. This breaks name mangling. So,
6984 don't copy record types and let c_common_nodes_and_builtins()
6985 declare the type to be __builtin_va_list. */
6986 if (TREE_CODE (t
) != RECORD_TYPE
)
6987 t
= build_variant_type_copy (t
);
6989 va_list_type_node
= t
;
6993 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
6996 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
6997 const char *library_name
, int ecf_flags
)
7001 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
7002 library_name
, NULL_TREE
);
7003 if (ecf_flags
& ECF_CONST
)
7004 TREE_READONLY (decl
) = 1;
7005 if (ecf_flags
& ECF_PURE
)
7006 DECL_IS_PURE (decl
) = 1;
7007 if (ecf_flags
& ECF_NORETURN
)
7008 TREE_THIS_VOLATILE (decl
) = 1;
7009 if (ecf_flags
& ECF_NOTHROW
)
7010 TREE_NOTHROW (decl
) = 1;
7011 if (ecf_flags
& ECF_MALLOC
)
7012 DECL_IS_MALLOC (decl
) = 1;
7014 built_in_decls
[code
] = decl
;
7015 implicit_built_in_decls
[code
] = decl
;
7018 /* Call this function after instantiating all builtins that the language
7019 front end cares about. This will build the rest of the builtins that
7020 are relied upon by the tree optimizers and the middle-end. */
7023 build_common_builtin_nodes (void)
7027 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
7028 || built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
7030 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7031 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7032 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7033 ftype
= build_function_type (ptr_type_node
, tmp
);
7035 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
)
7036 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
7037 "memcpy", ECF_NOTHROW
);
7038 if (built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
7039 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
7040 "memmove", ECF_NOTHROW
);
7043 if (built_in_decls
[BUILT_IN_MEMCMP
] == NULL
)
7045 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7046 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7047 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7048 ftype
= build_function_type (integer_type_node
, tmp
);
7049 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
7050 "memcmp", ECF_PURE
| ECF_NOTHROW
);
7053 if (built_in_decls
[BUILT_IN_MEMSET
] == NULL
)
7055 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7056 tmp
= tree_cons (NULL_TREE
, integer_type_node
, tmp
);
7057 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7058 ftype
= build_function_type (ptr_type_node
, tmp
);
7059 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
7060 "memset", ECF_NOTHROW
);
7063 if (built_in_decls
[BUILT_IN_ALLOCA
] == NULL
)
7065 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7066 ftype
= build_function_type (ptr_type_node
, tmp
);
7067 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
7068 "alloca", ECF_NOTHROW
| ECF_MALLOC
);
7071 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7072 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7073 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7074 ftype
= build_function_type (void_type_node
, tmp
);
7075 local_define_builtin ("__builtin_init_trampoline", ftype
,
7076 BUILT_IN_INIT_TRAMPOLINE
,
7077 "__builtin_init_trampoline", ECF_NOTHROW
);
7079 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7080 ftype
= build_function_type (ptr_type_node
, tmp
);
7081 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
7082 BUILT_IN_ADJUST_TRAMPOLINE
,
7083 "__builtin_adjust_trampoline",
7084 ECF_CONST
| ECF_NOTHROW
);
7086 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7087 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7088 ftype
= build_function_type (void_type_node
, tmp
);
7089 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
7090 BUILT_IN_NONLOCAL_GOTO
,
7091 "__builtin_nonlocal_goto",
7092 ECF_NORETURN
| ECF_NOTHROW
);
7094 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7095 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7096 ftype
= build_function_type (void_type_node
, tmp
);
7097 local_define_builtin ("__builtin_setjmp_setup", ftype
,
7098 BUILT_IN_SETJMP_SETUP
,
7099 "__builtin_setjmp_setup", ECF_NOTHROW
);
7101 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7102 ftype
= build_function_type (ptr_type_node
, tmp
);
7103 local_define_builtin ("__builtin_setjmp_dispatcher", ftype
,
7104 BUILT_IN_SETJMP_DISPATCHER
,
7105 "__builtin_setjmp_dispatcher",
7106 ECF_PURE
| ECF_NOTHROW
);
7108 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7109 ftype
= build_function_type (void_type_node
, tmp
);
7110 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
7111 BUILT_IN_SETJMP_RECEIVER
,
7112 "__builtin_setjmp_receiver", ECF_NOTHROW
);
7114 ftype
= build_function_type (ptr_type_node
, void_list_node
);
7115 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
7116 "__builtin_stack_save", ECF_NOTHROW
);
7118 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7119 ftype
= build_function_type (void_type_node
, tmp
);
7120 local_define_builtin ("__builtin_stack_restore", ftype
,
7121 BUILT_IN_STACK_RESTORE
,
7122 "__builtin_stack_restore", ECF_NOTHROW
);
7124 ftype
= build_function_type (void_type_node
, void_list_node
);
7125 local_define_builtin ("__builtin_profile_func_enter", ftype
,
7126 BUILT_IN_PROFILE_FUNC_ENTER
, "profile_func_enter", 0);
7127 local_define_builtin ("__builtin_profile_func_exit", ftype
,
7128 BUILT_IN_PROFILE_FUNC_EXIT
, "profile_func_exit", 0);
7130 /* Complex multiplication and division. These are handled as builtins
7131 rather than optabs because emit_library_call_value doesn't support
7132 complex. Further, we can do slightly better with folding these
7133 beasties if the real and complex parts of the arguments are separate. */
7135 enum machine_mode mode
;
7137 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
7139 char mode_name_buf
[4], *q
;
7141 enum built_in_function mcode
, dcode
;
7142 tree type
, inner_type
;
7144 type
= lang_hooks
.types
.type_for_mode (mode
, 0);
7147 inner_type
= TREE_TYPE (type
);
7149 tmp
= tree_cons (NULL_TREE
, inner_type
, void_list_node
);
7150 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
7151 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
7152 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
7153 ftype
= build_function_type (type
, tmp
);
7155 mcode
= BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
;
7156 dcode
= BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
;
7158 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
7162 built_in_names
[mcode
] = concat ("__mul", mode_name_buf
, "3", NULL
);
7163 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
7164 built_in_names
[mcode
], ECF_CONST
| ECF_NOTHROW
);
7166 built_in_names
[dcode
] = concat ("__div", mode_name_buf
, "3", NULL
);
7167 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
7168 built_in_names
[dcode
], ECF_CONST
| ECF_NOTHROW
);
7173 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
7176 If we requested a pointer to a vector, build up the pointers that
7177 we stripped off while looking for the inner type. Similarly for
7178 return values from functions.
7180 The argument TYPE is the top of the chain, and BOTTOM is the
7181 new type which we will point to. */
7184 reconstruct_complex_type (tree type
, tree bottom
)
7188 if (POINTER_TYPE_P (type
))
7190 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7191 outer
= build_pointer_type (inner
);
7193 else if (TREE_CODE (type
) == ARRAY_TYPE
)
7195 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7196 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
7198 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
7200 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7201 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
7203 else if (TREE_CODE (type
) == METHOD_TYPE
)
7206 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7207 /* The build_method_type_directly() routine prepends 'this' to argument list,
7208 so we must compensate by getting rid of it. */
7209 argtypes
= TYPE_ARG_TYPES (type
);
7210 outer
= build_method_type_directly (TYPE_METHOD_BASETYPE (type
),
7212 TYPE_ARG_TYPES (type
));
7213 TYPE_ARG_TYPES (outer
) = argtypes
;
7218 TYPE_READONLY (outer
) = TYPE_READONLY (type
);
7219 TYPE_VOLATILE (outer
) = TYPE_VOLATILE (type
);
7224 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
7227 build_vector_type_for_mode (tree innertype
, enum machine_mode mode
)
7231 switch (GET_MODE_CLASS (mode
))
7233 case MODE_VECTOR_INT
:
7234 case MODE_VECTOR_FLOAT
:
7235 nunits
= GET_MODE_NUNITS (mode
);
7239 /* Check that there are no leftover bits. */
7240 gcc_assert (GET_MODE_BITSIZE (mode
)
7241 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
7243 nunits
= GET_MODE_BITSIZE (mode
)
7244 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
7251 return make_vector_type (innertype
, nunits
, mode
);
7254 /* Similarly, but takes the inner type and number of units, which must be
7258 build_vector_type (tree innertype
, int nunits
)
7260 return make_vector_type (innertype
, nunits
, VOIDmode
);
7264 /* Build RESX_EXPR with given REGION_NUMBER. */
7266 build_resx (int region_number
)
7269 t
= build1 (RESX_EXPR
, void_type_node
,
7270 build_int_cst (NULL_TREE
, region_number
));
7274 /* Given an initializer INIT, return TRUE if INIT is zero or some
7275 aggregate of zeros. Otherwise return FALSE. */
7277 initializer_zerop (tree init
)
7283 switch (TREE_CODE (init
))
7286 return integer_zerop (init
);
7289 /* ??? Note that this is not correct for C4X float formats. There,
7290 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
7291 negative exponent. */
7292 return real_zerop (init
)
7293 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
7296 return integer_zerop (init
)
7297 || (real_zerop (init
)
7298 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
7299 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
7302 for (elt
= TREE_VECTOR_CST_ELTS (init
); elt
; elt
= TREE_CHAIN (elt
))
7303 if (!initializer_zerop (TREE_VALUE (elt
)))
7309 unsigned HOST_WIDE_INT idx
;
7311 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
7312 if (!initializer_zerop (elt
))
7322 /* Build an empty statement. */
7325 build_empty_stmt (void)
7327 return build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
7331 /* Build an OpenMP clause with code CODE. */
7334 build_omp_clause (enum omp_clause_code code
)
7339 length
= omp_clause_num_ops
[code
];
7340 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
7342 t
= ggc_alloc (size
);
7343 memset (t
, 0, size
);
7344 TREE_SET_CODE (t
, OMP_CLAUSE
);
7345 OMP_CLAUSE_SET_CODE (t
, code
);
7347 #ifdef GATHER_STATISTICS
7348 tree_node_counts
[(int) omp_clause_kind
]++;
7349 tree_node_sizes
[(int) omp_clause_kind
] += size
;
7356 /* Returns true if it is possible to prove that the index of
7357 an array access REF (an ARRAY_REF expression) falls into the
7361 in_array_bounds_p (tree ref
)
7363 tree idx
= TREE_OPERAND (ref
, 1);
7366 if (TREE_CODE (idx
) != INTEGER_CST
)
7369 min
= array_ref_low_bound (ref
);
7370 max
= array_ref_up_bound (ref
);
7373 || TREE_CODE (min
) != INTEGER_CST
7374 || TREE_CODE (max
) != INTEGER_CST
)
7377 if (tree_int_cst_lt (idx
, min
)
7378 || tree_int_cst_lt (max
, idx
))
7384 /* Returns true if it is possible to prove that the range of
7385 an array access REF (an ARRAY_RANGE_REF expression) falls
7386 into the array bounds. */
7389 range_in_array_bounds_p (tree ref
)
7391 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (ref
));
7392 tree range_min
, range_max
, min
, max
;
7394 range_min
= TYPE_MIN_VALUE (domain_type
);
7395 range_max
= TYPE_MAX_VALUE (domain_type
);
7398 || TREE_CODE (range_min
) != INTEGER_CST
7399 || TREE_CODE (range_max
) != INTEGER_CST
)
7402 min
= array_ref_low_bound (ref
);
7403 max
= array_ref_up_bound (ref
);
7406 || TREE_CODE (min
) != INTEGER_CST
7407 || TREE_CODE (max
) != INTEGER_CST
)
7410 if (tree_int_cst_lt (range_min
, min
)
7411 || tree_int_cst_lt (max
, range_max
))
7417 /* Return true if T (assumed to be a DECL) is a global variable. */
7420 is_global_var (tree t
)
7423 return (TREE_STATIC (t
) || MTAG_GLOBAL (t
));
7425 return (TREE_STATIC (t
) || DECL_EXTERNAL (t
));
7428 /* Return true if T (assumed to be a DECL) must be assigned a memory
7432 needs_to_live_in_memory (tree t
)
7434 if (TREE_CODE (t
) == SSA_NAME
)
7435 t
= SSA_NAME_VAR (t
);
7437 return (TREE_ADDRESSABLE (t
)
7438 || is_global_var (t
)
7439 || (TREE_CODE (t
) == RESULT_DECL
7440 && aggregate_value_p (t
, current_function_decl
)));
7443 /* There are situations in which a language considers record types
7444 compatible which have different field lists. Decide if two fields
7445 are compatible. It is assumed that the parent records are compatible. */
7448 fields_compatible_p (tree f1
, tree f2
)
7450 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1
),
7451 DECL_FIELD_BIT_OFFSET (f2
), OEP_ONLY_CONST
))
7454 if (!operand_equal_p (DECL_FIELD_OFFSET (f1
),
7455 DECL_FIELD_OFFSET (f2
), OEP_ONLY_CONST
))
7458 if (!lang_hooks
.types_compatible_p (TREE_TYPE (f1
), TREE_TYPE (f2
)))
7464 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
7467 find_compatible_field (tree record
, tree orig_field
)
7471 for (f
= TYPE_FIELDS (record
); f
; f
= TREE_CHAIN (f
))
7472 if (TREE_CODE (f
) == FIELD_DECL
7473 && fields_compatible_p (f
, orig_field
))
7476 /* ??? Why isn't this on the main fields list? */
7477 f
= TYPE_VFIELD (record
);
7478 if (f
&& TREE_CODE (f
) == FIELD_DECL
7479 && fields_compatible_p (f
, orig_field
))
7482 /* ??? We should abort here, but Java appears to do Bad Things
7483 with inherited fields. */
7487 /* Return value of a constant X. */
7490 int_cst_value (tree x
)
7492 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
7493 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
7494 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
7496 gcc_assert (bits
<= HOST_BITS_PER_WIDE_INT
);
7499 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
7501 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
7506 /* Returns the greatest common divisor of A and B, which must be
7510 tree_fold_gcd (tree a
, tree b
)
7513 tree type
= TREE_TYPE (a
);
7515 gcc_assert (TREE_CODE (a
) == INTEGER_CST
);
7516 gcc_assert (TREE_CODE (b
) == INTEGER_CST
);
7518 if (integer_zerop (a
))
7521 if (integer_zerop (b
))
7524 if (tree_int_cst_sgn (a
) == -1)
7525 a
= fold_build2 (MULT_EXPR
, type
, a
,
7526 build_int_cst (type
, -1));
7528 if (tree_int_cst_sgn (b
) == -1)
7529 b
= fold_build2 (MULT_EXPR
, type
, b
,
7530 build_int_cst (type
, -1));
7534 a_mod_b
= fold_build2 (FLOOR_MOD_EXPR
, type
, a
, b
);
7536 if (!TREE_INT_CST_LOW (a_mod_b
)
7537 && !TREE_INT_CST_HIGH (a_mod_b
))
7545 /* Returns unsigned variant of TYPE. */
7548 unsigned_type_for (tree type
)
7550 if (POINTER_TYPE_P (type
))
7551 return lang_hooks
.types
.unsigned_type (size_type_node
);
7552 return lang_hooks
.types
.unsigned_type (type
);
7555 /* Returns signed variant of TYPE. */
7558 signed_type_for (tree type
)
7560 if (POINTER_TYPE_P (type
))
7561 return lang_hooks
.types
.signed_type (size_type_node
);
7562 return lang_hooks
.types
.signed_type (type
);
7565 /* Returns the largest value obtainable by casting something in INNER type to
7569 upper_bound_in_type (tree outer
, tree inner
)
7571 unsigned HOST_WIDE_INT lo
, hi
;
7572 unsigned int det
= 0;
7573 unsigned oprec
= TYPE_PRECISION (outer
);
7574 unsigned iprec
= TYPE_PRECISION (inner
);
7577 /* Compute a unique number for every combination. */
7578 det
|= (oprec
> iprec
) ? 4 : 0;
7579 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
7580 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
7582 /* Determine the exponent to use. */
7587 /* oprec <= iprec, outer: signed, inner: don't care. */
7592 /* oprec <= iprec, outer: unsigned, inner: don't care. */
7596 /* oprec > iprec, outer: signed, inner: signed. */
7600 /* oprec > iprec, outer: signed, inner: unsigned. */
7604 /* oprec > iprec, outer: unsigned, inner: signed. */
7608 /* oprec > iprec, outer: unsigned, inner: unsigned. */
7615 /* Compute 2^^prec - 1. */
7616 if (prec
<= HOST_BITS_PER_WIDE_INT
)
7619 lo
= ((~(unsigned HOST_WIDE_INT
) 0)
7620 >> (HOST_BITS_PER_WIDE_INT
- prec
));
7624 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
7625 >> (2 * HOST_BITS_PER_WIDE_INT
- prec
));
7626 lo
= ~(unsigned HOST_WIDE_INT
) 0;
7629 return build_int_cst_wide (outer
, lo
, hi
);
7632 /* Returns the smallest value obtainable by casting something in INNER type to
7636 lower_bound_in_type (tree outer
, tree inner
)
7638 unsigned HOST_WIDE_INT lo
, hi
;
7639 unsigned oprec
= TYPE_PRECISION (outer
);
7640 unsigned iprec
= TYPE_PRECISION (inner
);
7642 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
7644 if (TYPE_UNSIGNED (outer
)
7645 /* If we are widening something of an unsigned type, OUTER type
7646 contains all values of INNER type. In particular, both INNER
7647 and OUTER types have zero in common. */
7648 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
7652 /* If we are widening a signed type to another signed type, we
7653 want to obtain -2^^(iprec-1). If we are keeping the
7654 precision or narrowing to a signed type, we want to obtain
7656 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
7658 if (prec
<= HOST_BITS_PER_WIDE_INT
)
7660 hi
= ~(unsigned HOST_WIDE_INT
) 0;
7661 lo
= (~(unsigned HOST_WIDE_INT
) 0) << (prec
- 1);
7665 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
7666 << (prec
- HOST_BITS_PER_WIDE_INT
- 1));
7671 return build_int_cst_wide (outer
, lo
, hi
);
7674 /* Return nonzero if two operands that are suitable for PHI nodes are
7675 necessarily equal. Specifically, both ARG0 and ARG1 must be either
7676 SSA_NAME or invariant. Note that this is strictly an optimization.
7677 That is, callers of this function can directly call operand_equal_p
7678 and get the same result, only slower. */
7681 operand_equal_for_phi_arg_p (tree arg0
, tree arg1
)
7685 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
7687 return operand_equal_p (arg0
, arg1
, 0);
7690 /* Returns number of zeros at the end of binary representation of X.
7692 ??? Use ffs if available? */
7695 num_ending_zeros (tree x
)
7697 unsigned HOST_WIDE_INT fr
, nfr
;
7698 unsigned num
, abits
;
7699 tree type
= TREE_TYPE (x
);
7701 if (TREE_INT_CST_LOW (x
) == 0)
7703 num
= HOST_BITS_PER_WIDE_INT
;
7704 fr
= TREE_INT_CST_HIGH (x
);
7709 fr
= TREE_INT_CST_LOW (x
);
7712 for (abits
= HOST_BITS_PER_WIDE_INT
/ 2; abits
; abits
/= 2)
7715 if (nfr
<< abits
== fr
)
7722 if (num
> TYPE_PRECISION (type
))
7723 num
= TYPE_PRECISION (type
);
7725 return build_int_cst_type (type
, num
);
7729 #define WALK_SUBTREE(NODE) \
7732 result = walk_tree (&(NODE), func, data, pset); \
7738 /* This is a subroutine of walk_tree that walks field of TYPE that are to
7739 be walked whenever a type is seen in the tree. Rest of operands and return
7740 value are as for walk_tree. */
7743 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
7744 struct pointer_set_t
*pset
)
7746 tree result
= NULL_TREE
;
7748 switch (TREE_CODE (type
))
7751 case REFERENCE_TYPE
:
7752 /* We have to worry about mutually recursive pointers. These can't
7753 be written in C. They can in Ada. It's pathological, but
7754 there's an ACATS test (c38102a) that checks it. Deal with this
7755 by checking if we're pointing to another pointer, that one
7756 points to another pointer, that one does too, and we have no htab.
7757 If so, get a hash table. We check three levels deep to avoid
7758 the cost of the hash table if we don't need one. */
7759 if (POINTER_TYPE_P (TREE_TYPE (type
))
7760 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
7761 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
7764 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
7772 /* ... fall through ... */
7775 WALK_SUBTREE (TREE_TYPE (type
));
7779 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
7784 WALK_SUBTREE (TREE_TYPE (type
));
7788 /* We never want to walk into default arguments. */
7789 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
7790 WALK_SUBTREE (TREE_VALUE (arg
));
7795 /* Don't follow this nodes's type if a pointer for fear that we'll
7796 have infinite recursion. Those types are uninteresting anyway. */
7797 if (!POINTER_TYPE_P (TREE_TYPE (type
))
7798 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
)
7799 WALK_SUBTREE (TREE_TYPE (type
));
7800 WALK_SUBTREE (TYPE_DOMAIN (type
));
7804 WALK_SUBTREE (TREE_TYPE (type
));
7805 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
7815 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
7816 called with the DATA and the address of each sub-tree. If FUNC returns a
7817 non-NULL value, the traversal is stopped, and the value returned by FUNC
7818 is returned. If PSET is non-NULL it is used to record the nodes visited,
7819 and to avoid visiting a node more than once. */
7822 walk_tree (tree
*tp
, walk_tree_fn func
, void *data
, struct pointer_set_t
*pset
)
7824 enum tree_code code
;
7828 #define WALK_SUBTREE_TAIL(NODE) \
7832 goto tail_recurse; \
7837 /* Skip empty subtrees. */
7841 /* Don't walk the same tree twice, if the user has requested
7842 that we avoid doing so. */
7843 if (pset
&& pointer_set_insert (pset
, *tp
))
7846 /* Call the function. */
7848 result
= (*func
) (tp
, &walk_subtrees
, data
);
7850 /* If we found something, return it. */
7854 code
= TREE_CODE (*tp
);
7856 /* Even if we didn't, FUNC may have decided that there was nothing
7857 interesting below this point in the tree. */
7860 /* But we still need to check our siblings. */
7861 if (code
== TREE_LIST
)
7862 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
7863 else if (code
== OMP_CLAUSE
)
7864 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
7869 result
= lang_hooks
.tree_inlining
.walk_subtrees (tp
, &walk_subtrees
, func
,
7871 if (result
|| !walk_subtrees
)
7877 case IDENTIFIER_NODE
:
7883 case PLACEHOLDER_EXPR
:
7887 /* None of these have subtrees other than those already walked
7892 WALK_SUBTREE (TREE_VALUE (*tp
));
7893 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
7898 int len
= TREE_VEC_LENGTH (*tp
);
7903 /* Walk all elements but the first. */
7905 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
7907 /* Now walk the first one as a tail call. */
7908 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
7912 WALK_SUBTREE (TREE_REALPART (*tp
));
7913 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
7917 unsigned HOST_WIDE_INT idx
;
7918 constructor_elt
*ce
;
7921 VEC_iterate(constructor_elt
, CONSTRUCTOR_ELTS (*tp
), idx
, ce
);
7923 WALK_SUBTREE (ce
->value
);
7928 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
7933 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= TREE_CHAIN (decl
))
7935 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
7936 into declarations that are just mentioned, rather than
7937 declared; they don't really belong to this part of the tree.
7938 And, we can see cycles: the initializer for a declaration
7939 can refer to the declaration itself. */
7940 WALK_SUBTREE (DECL_INITIAL (decl
));
7941 WALK_SUBTREE (DECL_SIZE (decl
));
7942 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
7944 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
7947 case STATEMENT_LIST
:
7949 tree_stmt_iterator i
;
7950 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
7951 WALK_SUBTREE (*tsi_stmt_ptr (i
));
7956 switch (OMP_CLAUSE_CODE (*tp
))
7958 case OMP_CLAUSE_PRIVATE
:
7959 case OMP_CLAUSE_SHARED
:
7960 case OMP_CLAUSE_FIRSTPRIVATE
:
7961 case OMP_CLAUSE_LASTPRIVATE
:
7962 case OMP_CLAUSE_COPYIN
:
7963 case OMP_CLAUSE_COPYPRIVATE
:
7965 case OMP_CLAUSE_NUM_THREADS
:
7966 case OMP_CLAUSE_SCHEDULE
:
7967 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 0));
7970 case OMP_CLAUSE_NOWAIT
:
7971 case OMP_CLAUSE_ORDERED
:
7972 case OMP_CLAUSE_DEFAULT
:
7973 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
7975 case OMP_CLAUSE_REDUCTION
:
7978 for (i
= 0; i
< 4; i
++)
7979 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
7980 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
7992 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
7993 But, we only want to walk once. */
7994 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
7995 for (i
= 0; i
< len
; ++i
)
7996 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
7997 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
8001 /* If this is a TYPE_DECL, walk into the fields of the type that it's
8002 defining. We only want to walk into these fields of a type in this
8003 case and not in the general case of a mere reference to the type.
8005 The criterion is as follows: if the field can be an expression, it
8006 must be walked only here. This should be in keeping with the fields
8007 that are directly gimplified in gimplify_type_sizes in order for the
8008 mark/copy-if-shared/unmark machinery of the gimplifier to work with
8009 variable-sized types.
8011 Note that DECLs get walked as part of processing the BIND_EXPR. */
8012 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
8014 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
8015 if (TREE_CODE (*type_p
) == ERROR_MARK
)
8018 /* Call the function for the type. See if it returns anything or
8019 doesn't want us to continue. If we are to continue, walk both
8020 the normal fields and those for the declaration case. */
8021 result
= (*func
) (type_p
, &walk_subtrees
, data
);
8022 if (result
|| !walk_subtrees
)
8025 result
= walk_type_fields (*type_p
, func
, data
, pset
);
8029 /* If this is a record type, also walk the fields. */
8030 if (TREE_CODE (*type_p
) == RECORD_TYPE
8031 || TREE_CODE (*type_p
) == UNION_TYPE
8032 || TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
8036 for (field
= TYPE_FIELDS (*type_p
); field
;
8037 field
= TREE_CHAIN (field
))
8039 /* We'd like to look at the type of the field, but we can
8040 easily get infinite recursion. So assume it's pointed
8041 to elsewhere in the tree. Also, ignore things that
8043 if (TREE_CODE (field
) != FIELD_DECL
)
8046 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
8047 WALK_SUBTREE (DECL_SIZE (field
));
8048 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
8049 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
8050 WALK_SUBTREE (DECL_QUALIFIER (field
));
8054 /* Same for scalar types. */
8055 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
8056 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
8057 || TREE_CODE (*type_p
) == INTEGER_TYPE
8058 || TREE_CODE (*type_p
) == REAL_TYPE
)
8060 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
8061 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
8064 WALK_SUBTREE (TYPE_SIZE (*type_p
));
8065 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
8070 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
))
8071 || IS_GIMPLE_STMT_CODE_CLASS (TREE_CODE_CLASS (code
)))
8075 /* Walk over all the sub-trees of this operand. */
8076 len
= TREE_CODE_LENGTH (code
);
8078 /* Go through the subtrees. We need to do this in forward order so
8079 that the scope of a FOR_EXPR is handled properly. */
8082 for (i
= 0; i
< len
- 1; ++i
)
8083 WALK_SUBTREE (GENERIC_TREE_OPERAND (*tp
, i
));
8084 WALK_SUBTREE_TAIL (GENERIC_TREE_OPERAND (*tp
, len
- 1));
8087 /* If this is a type, walk the needed fields in the type. */
8088 else if (TYPE_P (*tp
))
8089 return walk_type_fields (*tp
, func
, data
, pset
);
8093 /* We didn't find what we were looking for. */
8096 #undef WALK_SUBTREE_TAIL
8100 /* Like walk_tree, but does not walk duplicate nodes more than once. */
8103 walk_tree_without_duplicates (tree
*tp
, walk_tree_fn func
, void *data
)
8106 struct pointer_set_t
*pset
;
8108 pset
= pointer_set_create ();
8109 result
= walk_tree (tp
, func
, data
, pset
);
8110 pointer_set_destroy (pset
);
8115 /* Return true if STMT is an empty statement or contains nothing but
8116 empty statements. */
8119 empty_body_p (tree stmt
)
8121 tree_stmt_iterator i
;
8124 if (IS_EMPTY_STMT (stmt
))
8126 else if (TREE_CODE (stmt
) == BIND_EXPR
)
8127 body
= BIND_EXPR_BODY (stmt
);
8128 else if (TREE_CODE (stmt
) == STATEMENT_LIST
)
8133 for (i
= tsi_start (body
); !tsi_end_p (i
); tsi_next (&i
))
8134 if (!empty_body_p (tsi_stmt (i
)))
8143 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
8145 if (IS_EXPR_CODE_CLASS (c
))
8146 return &t
->exp
.block
;
8147 else if (IS_GIMPLE_STMT_CODE_CLASS (c
))
8148 return &GIMPLE_STMT_BLOCK (t
);
8154 generic_tree_operand (tree node
, int i
)
8156 if (GIMPLE_STMT_P (node
))
8157 return &GIMPLE_STMT_OPERAND (node
, i
);
8158 return &TREE_OPERAND (node
, i
);
8162 generic_tree_type (tree node
)
8164 if (GIMPLE_STMT_P (node
))
8165 return &void_type_node
;
8166 return &TREE_TYPE (node
);
8169 #include "gt-tree.h"