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, 2007, 2008, 2009
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 3, 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 COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This file contains the low level primitives for operating on tree nodes,
23 including allocation, list operations, interning of identifiers,
24 construction of data type nodes and statement nodes,
25 and construction of type conversion nodes. It also contains
26 tables index by tree code that describe how to take apart
29 It is intended to be language-independent, but occasionally
30 calls language-dependent routines defined (for C) in typecheck.c. */
34 #include "coretypes.h"
47 #include "langhooks.h"
48 #include "tree-inline.h"
49 #include "tree-iterator.h"
50 #include "basic-block.h"
51 #include "tree-flow.h"
53 #include "pointer-set.h"
54 #include "fixed-value.h"
56 /* Tree code classes. */
58 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
59 #define END_OF_BASE_TREE_CODES tcc_exceptional,
61 const enum tree_code_class tree_code_type
[] = {
62 #include "all-tree.def"
66 #undef END_OF_BASE_TREE_CODES
68 /* Table indexed by tree code giving number of expression
69 operands beyond the fixed part of the node structure.
70 Not used for types or decls. */
72 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
73 #define END_OF_BASE_TREE_CODES 0,
75 const unsigned char tree_code_length
[] = {
76 #include "all-tree.def"
80 #undef END_OF_BASE_TREE_CODES
82 /* Names of tree components.
83 Used for printing out the tree and error messages. */
84 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
85 #define END_OF_BASE_TREE_CODES "@dummy",
87 const char *const tree_code_name
[] = {
88 #include "all-tree.def"
92 #undef END_OF_BASE_TREE_CODES
94 /* Each tree code class has an associated string representation.
95 These must correspond to the tree_code_class entries. */
97 const char *const tree_code_class_strings
[] =
112 /* obstack.[ch] explicitly declined to prototype this. */
113 extern int _obstack_allocated_p (struct obstack
*h
, void *obj
);
115 #ifdef GATHER_STATISTICS
116 /* Statistics-gathering stuff. */
118 int tree_node_counts
[(int) all_kinds
];
119 int tree_node_sizes
[(int) all_kinds
];
121 /* Keep in sync with tree.h:enum tree_node_kind. */
122 static const char * const tree_node_kind_names
[] = {
142 #endif /* GATHER_STATISTICS */
144 /* Unique id for next decl created. */
145 static GTY(()) int next_decl_uid
;
146 /* Unique id for next type created. */
147 static GTY(()) int next_type_uid
= 1;
149 /* Since we cannot rehash a type after it is in the table, we have to
150 keep the hash code. */
152 struct GTY(()) type_hash
{
157 /* Initial size of the hash table (rounded to next prime). */
158 #define TYPE_HASH_INITIAL_SIZE 1000
160 /* Now here is the hash table. When recording a type, it is added to
161 the slot whose index is the hash code. Note that the hash table is
162 used for several kinds of types (function types, array types and
163 array index range types, for now). While all these live in the
164 same table, they are completely independent, and the hash code is
165 computed differently for each of these. */
167 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash
)))
168 htab_t type_hash_table
;
170 /* Hash table and temporary node for larger integer const values. */
171 static GTY (()) tree int_cst_node
;
172 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
173 htab_t int_cst_hash_table
;
175 /* Hash table for optimization flags and target option flags. Use the same
176 hash table for both sets of options. Nodes for building the current
177 optimization and target option nodes. The assumption is most of the time
178 the options created will already be in the hash table, so we avoid
179 allocating and freeing up a node repeatably. */
180 static GTY (()) tree cl_optimization_node
;
181 static GTY (()) tree cl_target_option_node
;
182 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
183 htab_t cl_option_hash_table
;
185 /* General tree->tree mapping structure for use in hash tables. */
188 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
189 htab_t debug_expr_for_decl
;
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
192 htab_t value_expr_for_decl
;
194 static GTY ((if_marked ("tree_priority_map_marked_p"),
195 param_is (struct tree_priority_map
)))
196 htab_t init_priority_for_decl
;
198 static void set_type_quals (tree
, int);
199 static int type_hash_eq (const void *, const void *);
200 static hashval_t
type_hash_hash (const void *);
201 static hashval_t
int_cst_hash_hash (const void *);
202 static int int_cst_hash_eq (const void *, const void *);
203 static hashval_t
cl_option_hash_hash (const void *);
204 static int cl_option_hash_eq (const void *, const void *);
205 static void print_type_hash_statistics (void);
206 static void print_debug_expr_statistics (void);
207 static void print_value_expr_statistics (void);
208 static int type_hash_marked_p (const void *);
209 static unsigned int type_hash_list (const_tree
, hashval_t
);
210 static unsigned int attribute_hash_list (const_tree
, hashval_t
);
212 tree global_trees
[TI_MAX
];
213 tree integer_types
[itk_none
];
215 unsigned char tree_contains_struct
[MAX_TREE_CODES
][64];
217 /* Number of operands for each OpenMP clause. */
218 unsigned const char omp_clause_num_ops
[] =
220 0, /* OMP_CLAUSE_ERROR */
221 1, /* OMP_CLAUSE_PRIVATE */
222 1, /* OMP_CLAUSE_SHARED */
223 1, /* OMP_CLAUSE_FIRSTPRIVATE */
224 2, /* OMP_CLAUSE_LASTPRIVATE */
225 4, /* OMP_CLAUSE_REDUCTION */
226 1, /* OMP_CLAUSE_COPYIN */
227 1, /* OMP_CLAUSE_COPYPRIVATE */
228 1, /* OMP_CLAUSE_IF */
229 1, /* OMP_CLAUSE_NUM_THREADS */
230 1, /* OMP_CLAUSE_SCHEDULE */
231 0, /* OMP_CLAUSE_NOWAIT */
232 0, /* OMP_CLAUSE_ORDERED */
233 0, /* OMP_CLAUSE_DEFAULT */
234 3, /* OMP_CLAUSE_COLLAPSE */
235 0 /* OMP_CLAUSE_UNTIED */
238 const char * const omp_clause_code_name
[] =
263 /* Initialize the hash table of types. */
264 type_hash_table
= htab_create_ggc (TYPE_HASH_INITIAL_SIZE
, type_hash_hash
,
267 debug_expr_for_decl
= htab_create_ggc (512, tree_map_hash
,
270 value_expr_for_decl
= htab_create_ggc (512, tree_map_hash
,
272 init_priority_for_decl
= htab_create_ggc (512, tree_priority_map_hash
,
273 tree_priority_map_eq
, 0);
275 int_cst_hash_table
= htab_create_ggc (1024, int_cst_hash_hash
,
276 int_cst_hash_eq
, NULL
);
278 int_cst_node
= make_node (INTEGER_CST
);
280 cl_option_hash_table
= htab_create_ggc (64, cl_option_hash_hash
,
281 cl_option_hash_eq
, NULL
);
283 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
284 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
286 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
] = 1;
287 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_NON_COMMON
] = 1;
288 tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
] = 1;
291 tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
] = 1;
292 tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
] = 1;
293 tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
] = 1;
294 tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
] = 1;
295 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
] = 1;
296 tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
] = 1;
297 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
] = 1;
298 tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
] = 1;
299 tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
] = 1;
302 tree_contains_struct
[CONST_DECL
][TS_DECL_WRTL
] = 1;
303 tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
] = 1;
304 tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
] = 1;
305 tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
] = 1;
306 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
] = 1;
307 tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
] = 1;
309 tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
] = 1;
310 tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
] = 1;
311 tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
] = 1;
312 tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
] = 1;
313 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
] = 1;
314 tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
] = 1;
315 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
] = 1;
316 tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
] = 1;
317 tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
] = 1;
319 tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
] = 1;
320 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
] = 1;
321 tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
] = 1;
322 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_WITH_VIS
] = 1;
324 tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
] = 1;
325 tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
] = 1;
326 tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
] = 1;
327 tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
] = 1;
328 tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
] = 1;
329 tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
] = 1;
330 tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
] = 1;
331 tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
] = 1;
332 tree_contains_struct
[IMPORTED_DECL
][TS_DECL_MINIMAL
] = 1;
333 tree_contains_struct
[IMPORTED_DECL
][TS_DECL_COMMON
] = 1;
335 lang_hooks
.init_ts ();
339 /* The name of the object as the assembler will see it (but before any
340 translations made by ASM_OUTPUT_LABELREF). Often this is the same
341 as DECL_NAME. It is an IDENTIFIER_NODE. */
343 decl_assembler_name (tree decl
)
345 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
346 lang_hooks
.set_decl_assembler_name (decl
);
347 return DECL_WITH_VIS_CHECK (decl
)->decl_with_vis
.assembler_name
;
350 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
353 decl_assembler_name_equal (tree decl
, const_tree asmname
)
355 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
356 const char *decl_str
;
357 const char *asmname_str
;
360 if (decl_asmname
== asmname
)
363 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
364 asmname_str
= IDENTIFIER_POINTER (asmname
);
367 /* If the target assembler name was set by the user, things are trickier.
368 We have a leading '*' to begin with. After that, it's arguable what
369 is the correct thing to do with -fleading-underscore. Arguably, we've
370 historically been doing the wrong thing in assemble_alias by always
371 printing the leading underscore. Since we're not changing that, make
372 sure user_label_prefix follows the '*' before matching. */
373 if (decl_str
[0] == '*')
375 size_t ulp_len
= strlen (user_label_prefix
);
381 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
382 decl_str
+= ulp_len
, test
=true;
386 if (asmname_str
[0] == '*')
388 size_t ulp_len
= strlen (user_label_prefix
);
394 else if (strncmp (asmname_str
, user_label_prefix
, ulp_len
) == 0)
395 asmname_str
+= ulp_len
, test
=true;
402 return strcmp (decl_str
, asmname_str
) == 0;
405 /* Hash asmnames ignoring the user specified marks. */
408 decl_assembler_name_hash (const_tree asmname
)
410 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
412 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
413 size_t ulp_len
= strlen (user_label_prefix
);
417 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
420 return htab_hash_string (decl_str
);
423 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
426 /* Compute the number of bytes occupied by a tree with code CODE.
427 This function cannot be used for nodes that have variable sizes,
428 including TREE_VEC, STRING_CST, and CALL_EXPR. */
430 tree_code_size (enum tree_code code
)
432 switch (TREE_CODE_CLASS (code
))
434 case tcc_declaration
: /* A decl node */
439 return sizeof (struct tree_field_decl
);
441 return sizeof (struct tree_parm_decl
);
443 return sizeof (struct tree_var_decl
);
445 return sizeof (struct tree_label_decl
);
447 return sizeof (struct tree_result_decl
);
449 return sizeof (struct tree_const_decl
);
451 return sizeof (struct tree_type_decl
);
453 return sizeof (struct tree_function_decl
);
455 return sizeof (struct tree_decl_non_common
);
459 case tcc_type
: /* a type node */
460 return sizeof (struct tree_type
);
462 case tcc_reference
: /* a reference */
463 case tcc_expression
: /* an expression */
464 case tcc_statement
: /* an expression with side effects */
465 case tcc_comparison
: /* a comparison expression */
466 case tcc_unary
: /* a unary arithmetic expression */
467 case tcc_binary
: /* a binary arithmetic expression */
468 return (sizeof (struct tree_exp
)
469 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (tree
));
471 case tcc_constant
: /* a constant */
474 case INTEGER_CST
: return sizeof (struct tree_int_cst
);
475 case REAL_CST
: return sizeof (struct tree_real_cst
);
476 case FIXED_CST
: return sizeof (struct tree_fixed_cst
);
477 case COMPLEX_CST
: return sizeof (struct tree_complex
);
478 case VECTOR_CST
: return sizeof (struct tree_vector
);
479 case STRING_CST
: gcc_unreachable ();
481 return lang_hooks
.tree_size (code
);
484 case tcc_exceptional
: /* something random, like an identifier. */
487 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
488 case TREE_LIST
: return sizeof (struct tree_list
);
491 case PLACEHOLDER_EXPR
: return sizeof (struct tree_common
);
494 case OMP_CLAUSE
: gcc_unreachable ();
496 case SSA_NAME
: return sizeof (struct tree_ssa_name
);
498 case STATEMENT_LIST
: return sizeof (struct tree_statement_list
);
499 case BLOCK
: return sizeof (struct tree_block
);
500 case CONSTRUCTOR
: return sizeof (struct tree_constructor
);
501 case OPTIMIZATION_NODE
: return sizeof (struct tree_optimization_option
);
502 case TARGET_OPTION_NODE
: return sizeof (struct tree_target_option
);
505 return lang_hooks
.tree_size (code
);
513 /* Compute the number of bytes occupied by NODE. This routine only
514 looks at TREE_CODE, except for those nodes that have variable sizes. */
516 tree_size (const_tree node
)
518 const enum tree_code code
= TREE_CODE (node
);
522 return (offsetof (struct tree_binfo
, base_binfos
)
523 + VEC_embedded_size (tree
, BINFO_N_BASE_BINFOS (node
)));
526 return (sizeof (struct tree_vec
)
527 + (TREE_VEC_LENGTH (node
) - 1) * sizeof (tree
));
530 return TREE_STRING_LENGTH (node
) + offsetof (struct tree_string
, str
) + 1;
533 return (sizeof (struct tree_omp_clause
)
534 + (omp_clause_num_ops
[OMP_CLAUSE_CODE (node
)] - 1)
538 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
539 return (sizeof (struct tree_exp
)
540 + (VL_EXP_OPERAND_LENGTH (node
) - 1) * sizeof (tree
));
542 return tree_code_size (code
);
546 /* Return a newly allocated node of code CODE. For decl and type
547 nodes, some other fields are initialized. The rest of the node is
548 initialized to zero. This function cannot be used for TREE_VEC or
549 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size.
551 Achoo! I got a code in the node. */
554 make_node_stat (enum tree_code code MEM_STAT_DECL
)
557 enum tree_code_class type
= TREE_CODE_CLASS (code
);
558 size_t length
= tree_code_size (code
);
559 #ifdef GATHER_STATISTICS
564 case tcc_declaration
: /* A decl node */
568 case tcc_type
: /* a type node */
572 case tcc_statement
: /* an expression with side effects */
576 case tcc_reference
: /* a reference */
580 case tcc_expression
: /* an expression */
581 case tcc_comparison
: /* a comparison expression */
582 case tcc_unary
: /* a unary arithmetic expression */
583 case tcc_binary
: /* a binary arithmetic expression */
587 case tcc_constant
: /* a constant */
591 case tcc_exceptional
: /* something random, like an identifier. */
594 case IDENTIFIER_NODE
:
607 kind
= ssa_name_kind
;
628 tree_node_counts
[(int) kind
]++;
629 tree_node_sizes
[(int) kind
] += length
;
632 if (code
== IDENTIFIER_NODE
)
633 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_id_zone
);
635 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
637 memset (t
, 0, length
);
639 TREE_SET_CODE (t
, code
);
644 TREE_SIDE_EFFECTS (t
) = 1;
647 case tcc_declaration
:
648 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
650 if (code
== FUNCTION_DECL
)
652 DECL_ALIGN (t
) = FUNCTION_BOUNDARY
;
653 DECL_MODE (t
) = FUNCTION_MODE
;
658 DECL_SOURCE_LOCATION (t
) = input_location
;
659 DECL_UID (t
) = next_decl_uid
++;
660 if (TREE_CODE (t
) == LABEL_DECL
)
661 LABEL_DECL_UID (t
) = -1;
666 TYPE_UID (t
) = next_type_uid
++;
667 TYPE_ALIGN (t
) = BITS_PER_UNIT
;
668 TYPE_USER_ALIGN (t
) = 0;
669 TYPE_MAIN_VARIANT (t
) = t
;
670 TYPE_CANONICAL (t
) = t
;
672 /* Default to no attributes for type, but let target change that. */
673 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
674 targetm
.set_default_type_attributes (t
);
676 /* We have not yet computed the alias set for this type. */
677 TYPE_ALIAS_SET (t
) = -1;
681 TREE_CONSTANT (t
) = 1;
690 case PREDECREMENT_EXPR
:
691 case PREINCREMENT_EXPR
:
692 case POSTDECREMENT_EXPR
:
693 case POSTINCREMENT_EXPR
:
694 /* All of these have side-effects, no matter what their
696 TREE_SIDE_EFFECTS (t
) = 1;
705 /* Other classes need no special treatment. */
712 /* Return a new node with the same contents as NODE except that its
713 TREE_CHAIN is zero and it has a fresh uid. */
716 copy_node_stat (tree node MEM_STAT_DECL
)
719 enum tree_code code
= TREE_CODE (node
);
722 gcc_assert (code
!= STATEMENT_LIST
);
724 length
= tree_size (node
);
725 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
726 memcpy (t
, node
, length
);
729 TREE_ASM_WRITTEN (t
) = 0;
730 TREE_VISITED (t
) = 0;
733 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
735 DECL_UID (t
) = next_decl_uid
++;
736 if ((TREE_CODE (node
) == PARM_DECL
|| TREE_CODE (node
) == VAR_DECL
)
737 && DECL_HAS_VALUE_EXPR_P (node
))
739 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
740 DECL_HAS_VALUE_EXPR_P (t
) = 1;
742 if (TREE_CODE (node
) == VAR_DECL
&& DECL_HAS_INIT_PRIORITY_P (node
))
744 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
745 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
748 else if (TREE_CODE_CLASS (code
) == tcc_type
)
750 TYPE_UID (t
) = next_type_uid
++;
751 /* The following is so that the debug code for
752 the copy is different from the original type.
753 The two statements usually duplicate each other
754 (because they clear fields of the same union),
755 but the optimizer should catch that. */
756 TYPE_SYMTAB_POINTER (t
) = 0;
757 TYPE_SYMTAB_ADDRESS (t
) = 0;
759 /* Do not copy the values cache. */
760 if (TYPE_CACHED_VALUES_P(t
))
762 TYPE_CACHED_VALUES_P (t
) = 0;
763 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
770 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
771 For example, this can copy a list made of TREE_LIST nodes. */
774 copy_list (tree list
)
782 head
= prev
= copy_node (list
);
783 next
= TREE_CHAIN (list
);
786 TREE_CHAIN (prev
) = copy_node (next
);
787 prev
= TREE_CHAIN (prev
);
788 next
= TREE_CHAIN (next
);
794 /* Create an INT_CST node with a LOW value sign extended. */
797 build_int_cst (tree type
, HOST_WIDE_INT low
)
799 /* Support legacy code. */
801 type
= integer_type_node
;
803 return build_int_cst_wide (type
, low
, low
< 0 ? -1 : 0);
806 /* Create an INT_CST node with a LOW value zero extended. */
809 build_int_cstu (tree type
, unsigned HOST_WIDE_INT low
)
811 return build_int_cst_wide (type
, low
, 0);
814 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
815 if it is negative. This function is similar to build_int_cst, but
816 the extra bits outside of the type precision are cleared. Constants
817 with these extra bits may confuse the fold so that it detects overflows
818 even in cases when they do not occur, and in general should be avoided.
819 We cannot however make this a default behavior of build_int_cst without
820 more intrusive changes, since there are parts of gcc that rely on the extra
821 precision of the integer constants. */
824 build_int_cst_type (tree type
, HOST_WIDE_INT low
)
826 unsigned HOST_WIDE_INT low1
;
831 fit_double_type (low
, low
< 0 ? -1 : 0, &low1
, &hi
, type
);
833 return build_int_cst_wide (type
, low1
, hi
);
836 /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated
837 and sign extended according to the value range of TYPE. */
840 build_int_cst_wide_type (tree type
,
841 unsigned HOST_WIDE_INT low
, HOST_WIDE_INT high
)
843 fit_double_type (low
, high
, &low
, &high
, type
);
844 return build_int_cst_wide (type
, low
, high
);
847 /* These are the hash table functions for the hash table of INTEGER_CST
848 nodes of a sizetype. */
850 /* Return the hash code code X, an INTEGER_CST. */
853 int_cst_hash_hash (const void *x
)
855 const_tree
const t
= (const_tree
) x
;
857 return (TREE_INT_CST_HIGH (t
) ^ TREE_INT_CST_LOW (t
)
858 ^ htab_hash_pointer (TREE_TYPE (t
)));
861 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
862 is the same as that given by *Y, which is the same. */
865 int_cst_hash_eq (const void *x
, const void *y
)
867 const_tree
const xt
= (const_tree
) x
;
868 const_tree
const yt
= (const_tree
) y
;
870 return (TREE_TYPE (xt
) == TREE_TYPE (yt
)
871 && TREE_INT_CST_HIGH (xt
) == TREE_INT_CST_HIGH (yt
)
872 && TREE_INT_CST_LOW (xt
) == TREE_INT_CST_LOW (yt
));
875 /* Create an INT_CST node of TYPE and value HI:LOW.
876 The returned node is always shared. For small integers we use a
877 per-type vector cache, for larger ones we use a single hash table. */
880 build_int_cst_wide (tree type
, unsigned HOST_WIDE_INT low
, HOST_WIDE_INT hi
)
888 switch (TREE_CODE (type
))
892 /* Cache NULL pointer. */
901 /* Cache false or true. */
909 if (TYPE_UNSIGNED (type
))
912 limit
= INTEGER_SHARE_LIMIT
;
913 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
919 limit
= INTEGER_SHARE_LIMIT
+ 1;
920 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
922 else if (hi
== -1 && low
== -(unsigned HOST_WIDE_INT
)1)
936 /* Look for it in the type's vector of small shared ints. */
937 if (!TYPE_CACHED_VALUES_P (type
))
939 TYPE_CACHED_VALUES_P (type
) = 1;
940 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
943 t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
);
946 /* Make sure no one is clobbering the shared constant. */
947 gcc_assert (TREE_TYPE (t
) == type
);
948 gcc_assert (TREE_INT_CST_LOW (t
) == low
);
949 gcc_assert (TREE_INT_CST_HIGH (t
) == hi
);
953 /* Create a new shared int. */
954 t
= make_node (INTEGER_CST
);
956 TREE_INT_CST_LOW (t
) = low
;
957 TREE_INT_CST_HIGH (t
) = hi
;
958 TREE_TYPE (t
) = type
;
960 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
965 /* Use the cache of larger shared ints. */
968 TREE_INT_CST_LOW (int_cst_node
) = low
;
969 TREE_INT_CST_HIGH (int_cst_node
) = hi
;
970 TREE_TYPE (int_cst_node
) = type
;
972 slot
= htab_find_slot (int_cst_hash_table
, int_cst_node
, INSERT
);
976 /* Insert this one into the hash table. */
979 /* Make a new node for next time round. */
980 int_cst_node
= make_node (INTEGER_CST
);
987 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
988 and the rest are zeros. */
991 build_low_bits_mask (tree type
, unsigned bits
)
993 unsigned HOST_WIDE_INT low
;
995 unsigned HOST_WIDE_INT all_ones
= ~(unsigned HOST_WIDE_INT
) 0;
997 gcc_assert (bits
<= TYPE_PRECISION (type
));
999 if (bits
== TYPE_PRECISION (type
)
1000 && !TYPE_UNSIGNED (type
))
1002 /* Sign extended all-ones mask. */
1006 else if (bits
<= HOST_BITS_PER_WIDE_INT
)
1008 low
= all_ones
>> (HOST_BITS_PER_WIDE_INT
- bits
);
1013 bits
-= HOST_BITS_PER_WIDE_INT
;
1015 high
= all_ones
>> (HOST_BITS_PER_WIDE_INT
- bits
);
1018 return build_int_cst_wide (type
, low
, high
);
1021 /* Checks that X is integer constant that can be expressed in (unsigned)
1022 HOST_WIDE_INT without loss of precision. */
1025 cst_and_fits_in_hwi (const_tree x
)
1027 if (TREE_CODE (x
) != INTEGER_CST
)
1030 if (TYPE_PRECISION (TREE_TYPE (x
)) > HOST_BITS_PER_WIDE_INT
)
1033 return (TREE_INT_CST_HIGH (x
) == 0
1034 || TREE_INT_CST_HIGH (x
) == -1);
1037 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1038 are in a list pointed to by VALS. */
1041 build_vector (tree type
, tree vals
)
1043 tree v
= make_node (VECTOR_CST
);
1047 TREE_VECTOR_CST_ELTS (v
) = vals
;
1048 TREE_TYPE (v
) = type
;
1050 /* Iterate through elements and check for overflow. */
1051 for (link
= vals
; link
; link
= TREE_CHAIN (link
))
1053 tree value
= TREE_VALUE (link
);
1055 /* Don't crash if we get an address constant. */
1056 if (!CONSTANT_CLASS_P (value
))
1059 over
|= TREE_OVERFLOW (value
);
1062 TREE_OVERFLOW (v
) = over
;
1066 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1067 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1070 build_vector_from_ctor (tree type
, VEC(constructor_elt
,gc
) *v
)
1072 tree list
= NULL_TREE
;
1073 unsigned HOST_WIDE_INT idx
;
1076 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1077 list
= tree_cons (NULL_TREE
, value
, list
);
1078 return build_vector (type
, nreverse (list
));
1081 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1082 are in the VEC pointed to by VALS. */
1084 build_constructor (tree type
, VEC(constructor_elt
,gc
) *vals
)
1086 tree c
= make_node (CONSTRUCTOR
);
1087 TREE_TYPE (c
) = type
;
1088 CONSTRUCTOR_ELTS (c
) = vals
;
1092 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1095 build_constructor_single (tree type
, tree index
, tree value
)
1097 VEC(constructor_elt
,gc
) *v
;
1098 constructor_elt
*elt
;
1101 v
= VEC_alloc (constructor_elt
, gc
, 1);
1102 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
1106 t
= build_constructor (type
, v
);
1107 TREE_CONSTANT (t
) = TREE_CONSTANT (value
);
1112 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1113 are in a list pointed to by VALS. */
1115 build_constructor_from_list (tree type
, tree vals
)
1118 VEC(constructor_elt
,gc
) *v
= NULL
;
1119 bool constant_p
= true;
1123 v
= VEC_alloc (constructor_elt
, gc
, list_length (vals
));
1124 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
1126 constructor_elt
*elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
1127 val
= TREE_VALUE (t
);
1128 elt
->index
= TREE_PURPOSE (t
);
1130 if (!TREE_CONSTANT (val
))
1135 t
= build_constructor (type
, v
);
1136 TREE_CONSTANT (t
) = constant_p
;
1140 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1143 build_fixed (tree type
, FIXED_VALUE_TYPE f
)
1146 FIXED_VALUE_TYPE
*fp
;
1148 v
= make_node (FIXED_CST
);
1149 fp
= GGC_NEW (FIXED_VALUE_TYPE
);
1150 memcpy (fp
, &f
, sizeof (FIXED_VALUE_TYPE
));
1152 TREE_TYPE (v
) = type
;
1153 TREE_FIXED_CST_PTR (v
) = fp
;
1157 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1160 build_real (tree type
, REAL_VALUE_TYPE d
)
1163 REAL_VALUE_TYPE
*dp
;
1166 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1167 Consider doing it via real_convert now. */
1169 v
= make_node (REAL_CST
);
1170 dp
= GGC_NEW (REAL_VALUE_TYPE
);
1171 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
1173 TREE_TYPE (v
) = type
;
1174 TREE_REAL_CST_PTR (v
) = dp
;
1175 TREE_OVERFLOW (v
) = overflow
;
1179 /* Return a new REAL_CST node whose type is TYPE
1180 and whose value is the integer value of the INTEGER_CST node I. */
1183 real_value_from_int_cst (const_tree type
, const_tree i
)
1187 /* Clear all bits of the real value type so that we can later do
1188 bitwise comparisons to see if two values are the same. */
1189 memset (&d
, 0, sizeof d
);
1191 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
,
1192 TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
),
1193 TYPE_UNSIGNED (TREE_TYPE (i
)));
1197 /* Given a tree representing an integer constant I, return a tree
1198 representing the same value as a floating-point constant of type TYPE. */
1201 build_real_from_int_cst (tree type
, const_tree i
)
1204 int overflow
= TREE_OVERFLOW (i
);
1206 v
= build_real (type
, real_value_from_int_cst (type
, i
));
1208 TREE_OVERFLOW (v
) |= overflow
;
1212 /* Return a newly constructed STRING_CST node whose value is
1213 the LEN characters at STR.
1214 The TREE_TYPE is not initialized. */
1217 build_string (int len
, const char *str
)
1222 /* Do not waste bytes provided by padding of struct tree_string. */
1223 length
= len
+ offsetof (struct tree_string
, str
) + 1;
1225 #ifdef GATHER_STATISTICS
1226 tree_node_counts
[(int) c_kind
]++;
1227 tree_node_sizes
[(int) c_kind
] += length
;
1230 s
= ggc_alloc_tree (length
);
1232 memset (s
, 0, sizeof (struct tree_common
));
1233 TREE_SET_CODE (s
, STRING_CST
);
1234 TREE_CONSTANT (s
) = 1;
1235 TREE_STRING_LENGTH (s
) = len
;
1236 memcpy (s
->string
.str
, str
, len
);
1237 s
->string
.str
[len
] = '\0';
1242 /* Return a newly constructed COMPLEX_CST node whose value is
1243 specified by the real and imaginary parts REAL and IMAG.
1244 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1245 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1248 build_complex (tree type
, tree real
, tree imag
)
1250 tree t
= make_node (COMPLEX_CST
);
1252 TREE_REALPART (t
) = real
;
1253 TREE_IMAGPART (t
) = imag
;
1254 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
1255 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1259 /* Return a constant of arithmetic type TYPE which is the
1260 multiplicative identity of the set TYPE. */
1263 build_one_cst (tree type
)
1265 switch (TREE_CODE (type
))
1267 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1268 case POINTER_TYPE
: case REFERENCE_TYPE
:
1270 return build_int_cst (type
, 1);
1273 return build_real (type
, dconst1
);
1275 case FIXED_POINT_TYPE
:
1276 /* We can only generate 1 for accum types. */
1277 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
1278 return build_fixed (type
, FCONST1(TYPE_MODE (type
)));
1285 scalar
= build_one_cst (TREE_TYPE (type
));
1287 /* Create 'vect_cst_ = {cst,cst,...,cst}' */
1289 for (i
= TYPE_VECTOR_SUBPARTS (type
); --i
>= 0; )
1290 cst
= tree_cons (NULL_TREE
, scalar
, cst
);
1292 return build_vector (type
, cst
);
1296 return build_complex (type
,
1297 build_one_cst (TREE_TYPE (type
)),
1298 fold_convert (TREE_TYPE (type
), integer_zero_node
));
1305 /* Build a BINFO with LEN language slots. */
1308 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL
)
1311 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
1312 + VEC_embedded_size (tree
, base_binfos
));
1314 #ifdef GATHER_STATISTICS
1315 tree_node_counts
[(int) binfo_kind
]++;
1316 tree_node_sizes
[(int) binfo_kind
] += length
;
1319 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
1321 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
1323 TREE_SET_CODE (t
, TREE_BINFO
);
1325 VEC_embedded_init (tree
, BINFO_BASE_BINFOS (t
), base_binfos
);
1331 /* Build a newly constructed TREE_VEC node of length LEN. */
1334 make_tree_vec_stat (int len MEM_STAT_DECL
)
1337 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
1339 #ifdef GATHER_STATISTICS
1340 tree_node_counts
[(int) vec_kind
]++;
1341 tree_node_sizes
[(int) vec_kind
] += length
;
1344 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
1346 memset (t
, 0, length
);
1348 TREE_SET_CODE (t
, TREE_VEC
);
1349 TREE_VEC_LENGTH (t
) = len
;
1354 /* Return 1 if EXPR is the integer constant zero or a complex constant
1358 integer_zerop (const_tree expr
)
1362 return ((TREE_CODE (expr
) == INTEGER_CST
1363 && TREE_INT_CST_LOW (expr
) == 0
1364 && TREE_INT_CST_HIGH (expr
) == 0)
1365 || (TREE_CODE (expr
) == COMPLEX_CST
1366 && integer_zerop (TREE_REALPART (expr
))
1367 && integer_zerop (TREE_IMAGPART (expr
))));
1370 /* Return 1 if EXPR is the integer constant one or the corresponding
1371 complex constant. */
1374 integer_onep (const_tree expr
)
1378 return ((TREE_CODE (expr
) == INTEGER_CST
1379 && TREE_INT_CST_LOW (expr
) == 1
1380 && TREE_INT_CST_HIGH (expr
) == 0)
1381 || (TREE_CODE (expr
) == COMPLEX_CST
1382 && integer_onep (TREE_REALPART (expr
))
1383 && integer_zerop (TREE_IMAGPART (expr
))));
1386 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1387 it contains. Likewise for the corresponding complex constant. */
1390 integer_all_onesp (const_tree expr
)
1397 if (TREE_CODE (expr
) == COMPLEX_CST
1398 && integer_all_onesp (TREE_REALPART (expr
))
1399 && integer_zerop (TREE_IMAGPART (expr
)))
1402 else if (TREE_CODE (expr
) != INTEGER_CST
)
1405 uns
= TYPE_UNSIGNED (TREE_TYPE (expr
));
1406 if (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1407 && TREE_INT_CST_HIGH (expr
) == -1)
1412 /* Note that using TYPE_PRECISION here is wrong. We care about the
1413 actual bits, not the (arbitrary) range of the type. */
1414 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr
)));
1415 if (prec
>= HOST_BITS_PER_WIDE_INT
)
1417 HOST_WIDE_INT high_value
;
1420 shift_amount
= prec
- HOST_BITS_PER_WIDE_INT
;
1422 /* Can not handle precisions greater than twice the host int size. */
1423 gcc_assert (shift_amount
<= HOST_BITS_PER_WIDE_INT
);
1424 if (shift_amount
== HOST_BITS_PER_WIDE_INT
)
1425 /* Shifting by the host word size is undefined according to the ANSI
1426 standard, so we must handle this as a special case. */
1429 high_value
= ((HOST_WIDE_INT
) 1 << shift_amount
) - 1;
1431 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1432 && TREE_INT_CST_HIGH (expr
) == high_value
);
1435 return TREE_INT_CST_LOW (expr
) == ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
1438 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1442 integer_pow2p (const_tree expr
)
1445 HOST_WIDE_INT high
, low
;
1449 if (TREE_CODE (expr
) == COMPLEX_CST
1450 && integer_pow2p (TREE_REALPART (expr
))
1451 && integer_zerop (TREE_IMAGPART (expr
)))
1454 if (TREE_CODE (expr
) != INTEGER_CST
)
1457 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1458 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1459 high
= TREE_INT_CST_HIGH (expr
);
1460 low
= TREE_INT_CST_LOW (expr
);
1462 /* First clear all bits that are beyond the type's precision in case
1463 we've been sign extended. */
1465 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1467 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1468 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1472 if (prec
< HOST_BITS_PER_WIDE_INT
)
1473 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1476 if (high
== 0 && low
== 0)
1479 return ((high
== 0 && (low
& (low
- 1)) == 0)
1480 || (low
== 0 && (high
& (high
- 1)) == 0));
1483 /* Return 1 if EXPR is an integer constant other than zero or a
1484 complex constant other than zero. */
1487 integer_nonzerop (const_tree expr
)
1491 return ((TREE_CODE (expr
) == INTEGER_CST
1492 && (TREE_INT_CST_LOW (expr
) != 0
1493 || TREE_INT_CST_HIGH (expr
) != 0))
1494 || (TREE_CODE (expr
) == COMPLEX_CST
1495 && (integer_nonzerop (TREE_REALPART (expr
))
1496 || integer_nonzerop (TREE_IMAGPART (expr
)))));
1499 /* Return 1 if EXPR is the fixed-point constant zero. */
1502 fixed_zerop (const_tree expr
)
1504 return (TREE_CODE (expr
) == FIXED_CST
1505 && double_int_zero_p (TREE_FIXED_CST (expr
).data
));
1508 /* Return the power of two represented by a tree node known to be a
1512 tree_log2 (const_tree expr
)
1515 HOST_WIDE_INT high
, low
;
1519 if (TREE_CODE (expr
) == COMPLEX_CST
)
1520 return tree_log2 (TREE_REALPART (expr
));
1522 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1523 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1525 high
= TREE_INT_CST_HIGH (expr
);
1526 low
= TREE_INT_CST_LOW (expr
);
1528 /* First clear all bits that are beyond the type's precision in case
1529 we've been sign extended. */
1531 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1533 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1534 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1538 if (prec
< HOST_BITS_PER_WIDE_INT
)
1539 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1542 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ exact_log2 (high
)
1543 : exact_log2 (low
));
1546 /* Similar, but return the largest integer Y such that 2 ** Y is less
1547 than or equal to EXPR. */
1550 tree_floor_log2 (const_tree expr
)
1553 HOST_WIDE_INT high
, low
;
1557 if (TREE_CODE (expr
) == COMPLEX_CST
)
1558 return tree_log2 (TREE_REALPART (expr
));
1560 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1561 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1563 high
= TREE_INT_CST_HIGH (expr
);
1564 low
= TREE_INT_CST_LOW (expr
);
1566 /* First clear all bits that are beyond the type's precision in case
1567 we've been sign extended. Ignore if type's precision hasn't been set
1568 since what we are doing is setting it. */
1570 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
|| prec
== 0)
1572 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1573 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1577 if (prec
< HOST_BITS_PER_WIDE_INT
)
1578 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1581 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ floor_log2 (high
)
1582 : floor_log2 (low
));
1585 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
1586 decimal float constants, so don't return 1 for them. */
1589 real_zerop (const_tree expr
)
1593 return ((TREE_CODE (expr
) == REAL_CST
1594 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
)
1595 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
)))))
1596 || (TREE_CODE (expr
) == COMPLEX_CST
1597 && real_zerop (TREE_REALPART (expr
))
1598 && real_zerop (TREE_IMAGPART (expr
))));
1601 /* Return 1 if EXPR is the real constant one in real or complex form.
1602 Trailing zeroes matter for decimal float constants, so don't return
1606 real_onep (const_tree expr
)
1610 return ((TREE_CODE (expr
) == REAL_CST
1611 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
)
1612 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
)))))
1613 || (TREE_CODE (expr
) == COMPLEX_CST
1614 && real_onep (TREE_REALPART (expr
))
1615 && real_zerop (TREE_IMAGPART (expr
))));
1618 /* Return 1 if EXPR is the real constant two. Trailing zeroes matter
1619 for decimal float constants, so don't return 1 for them. */
1622 real_twop (const_tree expr
)
1626 return ((TREE_CODE (expr
) == REAL_CST
1627 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst2
)
1628 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
)))))
1629 || (TREE_CODE (expr
) == COMPLEX_CST
1630 && real_twop (TREE_REALPART (expr
))
1631 && real_zerop (TREE_IMAGPART (expr
))));
1634 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
1635 matter for decimal float constants, so don't return 1 for them. */
1638 real_minus_onep (const_tree expr
)
1642 return ((TREE_CODE (expr
) == REAL_CST
1643 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconstm1
)
1644 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
)))))
1645 || (TREE_CODE (expr
) == COMPLEX_CST
1646 && real_minus_onep (TREE_REALPART (expr
))
1647 && real_zerop (TREE_IMAGPART (expr
))));
1650 /* Nonzero if EXP is a constant or a cast of a constant. */
1653 really_constant_p (const_tree exp
)
1655 /* This is not quite the same as STRIP_NOPS. It does more. */
1656 while (CONVERT_EXPR_P (exp
)
1657 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
1658 exp
= TREE_OPERAND (exp
, 0);
1659 return TREE_CONSTANT (exp
);
1662 /* Return first list element whose TREE_VALUE is ELEM.
1663 Return 0 if ELEM is not in LIST. */
1666 value_member (tree elem
, tree list
)
1670 if (elem
== TREE_VALUE (list
))
1672 list
= TREE_CHAIN (list
);
1677 /* Return first list element whose TREE_PURPOSE is ELEM.
1678 Return 0 if ELEM is not in LIST. */
1681 purpose_member (const_tree elem
, tree list
)
1685 if (elem
== TREE_PURPOSE (list
))
1687 list
= TREE_CHAIN (list
);
1692 /* Return nonzero if ELEM is part of the chain CHAIN. */
1695 chain_member (const_tree elem
, const_tree chain
)
1701 chain
= TREE_CHAIN (chain
);
1707 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1708 We expect a null pointer to mark the end of the chain.
1709 This is the Lisp primitive `length'. */
1712 list_length (const_tree t
)
1715 #ifdef ENABLE_TREE_CHECKING
1723 #ifdef ENABLE_TREE_CHECKING
1726 gcc_assert (p
!= q
);
1734 /* Returns the number of FIELD_DECLs in TYPE. */
1737 fields_length (const_tree type
)
1739 tree t
= TYPE_FIELDS (type
);
1742 for (; t
; t
= TREE_CHAIN (t
))
1743 if (TREE_CODE (t
) == FIELD_DECL
)
1749 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1750 by modifying the last node in chain 1 to point to chain 2.
1751 This is the Lisp primitive `nconc'. */
1754 chainon (tree op1
, tree op2
)
1763 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
1765 TREE_CHAIN (t1
) = op2
;
1767 #ifdef ENABLE_TREE_CHECKING
1770 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
1771 gcc_assert (t2
!= t1
);
1778 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1781 tree_last (tree chain
)
1785 while ((next
= TREE_CHAIN (chain
)))
1790 /* Return the node in a chain of nodes whose value is x, NULL if not found. */
1793 tree_find_value (tree chain
, tree x
)
1796 for (list
= chain
; list
; list
= TREE_CHAIN (list
))
1797 if (TREE_VALUE (list
) == x
)
1802 /* Reverse the order of elements in the chain T,
1803 and return the new head of the chain (old last element). */
1808 tree prev
= 0, decl
, next
;
1809 for (decl
= t
; decl
; decl
= next
)
1811 next
= TREE_CHAIN (decl
);
1812 TREE_CHAIN (decl
) = prev
;
1818 /* Return a newly created TREE_LIST node whose
1819 purpose and value fields are PARM and VALUE. */
1822 build_tree_list_stat (tree parm
, tree value MEM_STAT_DECL
)
1824 tree t
= make_node_stat (TREE_LIST PASS_MEM_STAT
);
1825 TREE_PURPOSE (t
) = parm
;
1826 TREE_VALUE (t
) = value
;
1830 /* Build a chain of TREE_LIST nodes from a vector. */
1833 build_tree_list_vec_stat (const VEC(tree
,gc
) *vec MEM_STAT_DECL
)
1835 tree ret
= NULL_TREE
;
1839 for (i
= 0; VEC_iterate (tree
, vec
, i
, t
); ++i
)
1841 *pp
= build_tree_list_stat (NULL
, t PASS_MEM_STAT
);
1842 pp
= &TREE_CHAIN (*pp
);
1847 /* Return a newly created TREE_LIST node whose
1848 purpose and value fields are PURPOSE and VALUE
1849 and whose TREE_CHAIN is CHAIN. */
1852 tree_cons_stat (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
1856 node
= (tree
) ggc_alloc_zone_pass_stat (sizeof (struct tree_list
), &tree_zone
);
1858 memset (node
, 0, sizeof (struct tree_common
));
1860 #ifdef GATHER_STATISTICS
1861 tree_node_counts
[(int) x_kind
]++;
1862 tree_node_sizes
[(int) x_kind
] += sizeof (struct tree_list
);
1865 TREE_SET_CODE (node
, TREE_LIST
);
1866 TREE_CHAIN (node
) = chain
;
1867 TREE_PURPOSE (node
) = purpose
;
1868 TREE_VALUE (node
) = value
;
1872 /* Return the elements of a CONSTRUCTOR as a TREE_LIST. */
1875 ctor_to_list (tree ctor
)
1877 tree list
= NULL_TREE
;
1882 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), ix
, purpose
, val
)
1884 *p
= build_tree_list (purpose
, val
);
1885 p
= &TREE_CHAIN (*p
);
1891 /* Return the values of the elements of a CONSTRUCTOR as a vector of
1895 ctor_to_vec (tree ctor
)
1897 VEC(tree
, gc
) *vec
= VEC_alloc (tree
, gc
, CONSTRUCTOR_NELTS (ctor
));
1901 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor
), ix
, val
)
1902 VEC_quick_push (tree
, vec
, val
);
1907 /* Return the size nominally occupied by an object of type TYPE
1908 when it resides in memory. The value is measured in units of bytes,
1909 and its data type is that normally used for type sizes
1910 (which is the first type created by make_signed_type or
1911 make_unsigned_type). */
1914 size_in_bytes (const_tree type
)
1918 if (type
== error_mark_node
)
1919 return integer_zero_node
;
1921 type
= TYPE_MAIN_VARIANT (type
);
1922 t
= TYPE_SIZE_UNIT (type
);
1926 lang_hooks
.types
.incomplete_type_error (NULL_TREE
, type
);
1927 return size_zero_node
;
1933 /* Return the size of TYPE (in bytes) as a wide integer
1934 or return -1 if the size can vary or is larger than an integer. */
1937 int_size_in_bytes (const_tree type
)
1941 if (type
== error_mark_node
)
1944 type
= TYPE_MAIN_VARIANT (type
);
1945 t
= TYPE_SIZE_UNIT (type
);
1947 || TREE_CODE (t
) != INTEGER_CST
1948 || TREE_INT_CST_HIGH (t
) != 0
1949 /* If the result would appear negative, it's too big to represent. */
1950 || (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0)
1953 return TREE_INT_CST_LOW (t
);
1956 /* Return the maximum size of TYPE (in bytes) as a wide integer
1957 or return -1 if the size can vary or is larger than an integer. */
1960 max_int_size_in_bytes (const_tree type
)
1962 HOST_WIDE_INT size
= -1;
1965 /* If this is an array type, check for a possible MAX_SIZE attached. */
1967 if (TREE_CODE (type
) == ARRAY_TYPE
)
1969 size_tree
= TYPE_ARRAY_MAX_SIZE (type
);
1971 if (size_tree
&& host_integerp (size_tree
, 1))
1972 size
= tree_low_cst (size_tree
, 1);
1975 /* If we still haven't been able to get a size, see if the language
1976 can compute a maximum size. */
1980 size_tree
= lang_hooks
.types
.max_size (type
);
1982 if (size_tree
&& host_integerp (size_tree
, 1))
1983 size
= tree_low_cst (size_tree
, 1);
1989 /* Return the bit position of FIELD, in bits from the start of the record.
1990 This is a tree of type bitsizetype. */
1993 bit_position (const_tree field
)
1995 return bit_from_pos (DECL_FIELD_OFFSET (field
),
1996 DECL_FIELD_BIT_OFFSET (field
));
1999 /* Likewise, but return as an integer. It must be representable in
2000 that way (since it could be a signed value, we don't have the
2001 option of returning -1 like int_size_in_byte can. */
2004 int_bit_position (const_tree field
)
2006 return tree_low_cst (bit_position (field
), 0);
2009 /* Return the byte position of FIELD, in bytes from the start of the record.
2010 This is a tree of type sizetype. */
2013 byte_position (const_tree field
)
2015 return byte_from_pos (DECL_FIELD_OFFSET (field
),
2016 DECL_FIELD_BIT_OFFSET (field
));
2019 /* Likewise, but return as an integer. It must be representable in
2020 that way (since it could be a signed value, we don't have the
2021 option of returning -1 like int_size_in_byte can. */
2024 int_byte_position (const_tree field
)
2026 return tree_low_cst (byte_position (field
), 0);
2029 /* Return the strictest alignment, in bits, that T is known to have. */
2032 expr_align (const_tree t
)
2034 unsigned int align0
, align1
;
2036 switch (TREE_CODE (t
))
2038 CASE_CONVERT
: case NON_LVALUE_EXPR
:
2039 /* If we have conversions, we know that the alignment of the
2040 object must meet each of the alignments of the types. */
2041 align0
= expr_align (TREE_OPERAND (t
, 0));
2042 align1
= TYPE_ALIGN (TREE_TYPE (t
));
2043 return MAX (align0
, align1
);
2045 case SAVE_EXPR
: case COMPOUND_EXPR
: case MODIFY_EXPR
:
2046 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
2047 case CLEANUP_POINT_EXPR
:
2048 /* These don't change the alignment of an object. */
2049 return expr_align (TREE_OPERAND (t
, 0));
2052 /* The best we can do is say that the alignment is the least aligned
2054 align0
= expr_align (TREE_OPERAND (t
, 1));
2055 align1
= expr_align (TREE_OPERAND (t
, 2));
2056 return MIN (align0
, align1
);
2058 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2059 meaningfully, it's always 1. */
2060 case LABEL_DECL
: case CONST_DECL
:
2061 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
2063 gcc_assert (DECL_ALIGN (t
) != 0);
2064 return DECL_ALIGN (t
);
2070 /* Otherwise take the alignment from that of the type. */
2071 return TYPE_ALIGN (TREE_TYPE (t
));
2074 /* Return, as a tree node, the number of elements for TYPE (which is an
2075 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2078 array_type_nelts (const_tree type
)
2080 tree index_type
, min
, max
;
2082 /* If they did it with unspecified bounds, then we should have already
2083 given an error about it before we got here. */
2084 if (! TYPE_DOMAIN (type
))
2085 return error_mark_node
;
2087 index_type
= TYPE_DOMAIN (type
);
2088 min
= TYPE_MIN_VALUE (index_type
);
2089 max
= TYPE_MAX_VALUE (index_type
);
2091 return (integer_zerop (min
)
2093 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
2096 /* If arg is static -- a reference to an object in static storage -- then
2097 return the object. This is not the same as the C meaning of `static'.
2098 If arg isn't static, return NULL. */
2103 switch (TREE_CODE (arg
))
2106 /* Nested functions are static, even though taking their address will
2107 involve a trampoline as we unnest the nested function and create
2108 the trampoline on the tree level. */
2112 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2113 && ! DECL_THREAD_LOCAL_P (arg
)
2114 && ! DECL_DLLIMPORT_P (arg
)
2118 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2122 return TREE_STATIC (arg
) ? arg
: NULL
;
2129 /* If the thing being referenced is not a field, then it is
2130 something language specific. */
2131 gcc_assert (TREE_CODE (TREE_OPERAND (arg
, 1)) == FIELD_DECL
);
2133 /* If we are referencing a bitfield, we can't evaluate an
2134 ADDR_EXPR at compile time and so it isn't a constant. */
2135 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
2138 return staticp (TREE_OPERAND (arg
, 0));
2143 case MISALIGNED_INDIRECT_REF
:
2144 case ALIGN_INDIRECT_REF
:
2146 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
2149 case ARRAY_RANGE_REF
:
2150 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
2151 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
2152 return staticp (TREE_OPERAND (arg
, 0));
2156 case COMPOUND_LITERAL_EXPR
:
2157 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg
)) ? arg
: NULL
;
2167 /* Return whether OP is a DECL whose address is function-invariant. */
2170 decl_address_invariant_p (const_tree op
)
2172 /* The conditions below are slightly less strict than the one in
2175 switch (TREE_CODE (op
))
2184 if (((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2185 && !DECL_DLLIMPORT_P (op
))
2186 || DECL_THREAD_LOCAL_P (op
)
2187 || DECL_CONTEXT (op
) == current_function_decl
2188 || decl_function_context (op
) == current_function_decl
)
2193 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2194 || decl_function_context (op
) == current_function_decl
)
2205 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
2208 decl_address_ip_invariant_p (const_tree op
)
2210 /* The conditions below are slightly less strict than the one in
2213 switch (TREE_CODE (op
))
2221 if (((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2222 && !DECL_DLLIMPORT_P (op
))
2223 || DECL_THREAD_LOCAL_P (op
))
2228 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
)))
2240 /* Return true if T is function-invariant (internal function, does
2241 not handle arithmetic; that's handled in skip_simple_arithmetic and
2242 tree_invariant_p). */
2244 static bool tree_invariant_p (tree t
);
2247 tree_invariant_p_1 (tree t
)
2251 if (TREE_CONSTANT (t
)
2252 || (TREE_READONLY (t
) && !TREE_SIDE_EFFECTS (t
)))
2255 switch (TREE_CODE (t
))
2261 op
= TREE_OPERAND (t
, 0);
2262 while (handled_component_p (op
))
2264 switch (TREE_CODE (op
))
2267 case ARRAY_RANGE_REF
:
2268 if (!tree_invariant_p (TREE_OPERAND (op
, 1))
2269 || TREE_OPERAND (op
, 2) != NULL_TREE
2270 || TREE_OPERAND (op
, 3) != NULL_TREE
)
2275 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
2281 op
= TREE_OPERAND (op
, 0);
2284 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
2293 /* Return true if T is function-invariant. */
2296 tree_invariant_p (tree t
)
2298 tree inner
= skip_simple_arithmetic (t
);
2299 return tree_invariant_p_1 (inner
);
2302 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2303 Do this to any expression which may be used in more than one place,
2304 but must be evaluated only once.
2306 Normally, expand_expr would reevaluate the expression each time.
2307 Calling save_expr produces something that is evaluated and recorded
2308 the first time expand_expr is called on it. Subsequent calls to
2309 expand_expr just reuse the recorded value.
2311 The call to expand_expr that generates code that actually computes
2312 the value is the first call *at compile time*. Subsequent calls
2313 *at compile time* generate code to use the saved value.
2314 This produces correct result provided that *at run time* control
2315 always flows through the insns made by the first expand_expr
2316 before reaching the other places where the save_expr was evaluated.
2317 You, the caller of save_expr, must make sure this is so.
2319 Constants, and certain read-only nodes, are returned with no
2320 SAVE_EXPR because that is safe. Expressions containing placeholders
2321 are not touched; see tree.def for an explanation of what these
2325 save_expr (tree expr
)
2327 tree t
= fold (expr
);
2330 /* If the tree evaluates to a constant, then we don't want to hide that
2331 fact (i.e. this allows further folding, and direct checks for constants).
2332 However, a read-only object that has side effects cannot be bypassed.
2333 Since it is no problem to reevaluate literals, we just return the
2335 inner
= skip_simple_arithmetic (t
);
2336 if (TREE_CODE (inner
) == ERROR_MARK
)
2339 if (tree_invariant_p_1 (inner
))
2342 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2343 it means that the size or offset of some field of an object depends on
2344 the value within another field.
2346 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2347 and some variable since it would then need to be both evaluated once and
2348 evaluated more than once. Front-ends must assure this case cannot
2349 happen by surrounding any such subexpressions in their own SAVE_EXPR
2350 and forcing evaluation at the proper time. */
2351 if (contains_placeholder_p (inner
))
2354 t
= build1 (SAVE_EXPR
, TREE_TYPE (expr
), t
);
2355 SET_EXPR_LOCATION (t
, EXPR_LOCATION (expr
));
2357 /* This expression might be placed ahead of a jump to ensure that the
2358 value was computed on both sides of the jump. So make sure it isn't
2359 eliminated as dead. */
2360 TREE_SIDE_EFFECTS (t
) = 1;
2364 /* Look inside EXPR and into any simple arithmetic operations. Return
2365 the innermost non-arithmetic node. */
2368 skip_simple_arithmetic (tree expr
)
2372 /* We don't care about whether this can be used as an lvalue in this
2374 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
2375 expr
= TREE_OPERAND (expr
, 0);
2377 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2378 a constant, it will be more efficient to not make another SAVE_EXPR since
2379 it will allow better simplification and GCSE will be able to merge the
2380 computations if they actually occur. */
2384 if (UNARY_CLASS_P (inner
))
2385 inner
= TREE_OPERAND (inner
, 0);
2386 else if (BINARY_CLASS_P (inner
))
2388 if (tree_invariant_p (TREE_OPERAND (inner
, 1)))
2389 inner
= TREE_OPERAND (inner
, 0);
2390 else if (tree_invariant_p (TREE_OPERAND (inner
, 0)))
2391 inner
= TREE_OPERAND (inner
, 1);
2402 /* Return which tree structure is used by T. */
2404 enum tree_node_structure_enum
2405 tree_node_structure (const_tree t
)
2407 const enum tree_code code
= TREE_CODE (t
);
2409 switch (TREE_CODE_CLASS (code
))
2411 case tcc_declaration
:
2416 return TS_FIELD_DECL
;
2418 return TS_PARM_DECL
;
2422 return TS_LABEL_DECL
;
2424 return TS_RESULT_DECL
;
2426 return TS_CONST_DECL
;
2428 return TS_TYPE_DECL
;
2430 return TS_FUNCTION_DECL
;
2432 return TS_DECL_NON_COMMON
;
2438 case tcc_comparison
:
2441 case tcc_expression
:
2445 default: /* tcc_constant and tcc_exceptional */
2450 /* tcc_constant cases. */
2451 case INTEGER_CST
: return TS_INT_CST
;
2452 case REAL_CST
: return TS_REAL_CST
;
2453 case FIXED_CST
: return TS_FIXED_CST
;
2454 case COMPLEX_CST
: return TS_COMPLEX
;
2455 case VECTOR_CST
: return TS_VECTOR
;
2456 case STRING_CST
: return TS_STRING
;
2457 /* tcc_exceptional cases. */
2458 case ERROR_MARK
: return TS_COMMON
;
2459 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
2460 case TREE_LIST
: return TS_LIST
;
2461 case TREE_VEC
: return TS_VEC
;
2462 case SSA_NAME
: return TS_SSA_NAME
;
2463 case PLACEHOLDER_EXPR
: return TS_COMMON
;
2464 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
2465 case BLOCK
: return TS_BLOCK
;
2466 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
2467 case TREE_BINFO
: return TS_BINFO
;
2468 case OMP_CLAUSE
: return TS_OMP_CLAUSE
;
2469 case OPTIMIZATION_NODE
: return TS_OPTIMIZATION
;
2470 case TARGET_OPTION_NODE
: return TS_TARGET_OPTION
;
2477 /* Set various status flags when building a CALL_EXPR object T. */
2480 process_call_operands (tree t
)
2482 bool side_effects
= TREE_SIDE_EFFECTS (t
);
2483 bool read_only
= false;
2484 int i
= call_expr_flags (t
);
2486 /* Calls have side-effects, except those to const or pure functions. */
2487 if ((i
& ECF_LOOPING_CONST_OR_PURE
) || !(i
& (ECF_CONST
| ECF_PURE
)))
2488 side_effects
= true;
2489 /* Propagate TREE_READONLY of arguments for const functions. */
2493 if (!side_effects
|| read_only
)
2494 for (i
= 1; i
< TREE_OPERAND_LENGTH (t
); i
++)
2496 tree op
= TREE_OPERAND (t
, i
);
2497 if (op
&& TREE_SIDE_EFFECTS (op
))
2498 side_effects
= true;
2499 if (op
&& !TREE_READONLY (op
) && !CONSTANT_CLASS_P (op
))
2503 TREE_SIDE_EFFECTS (t
) = side_effects
;
2504 TREE_READONLY (t
) = read_only
;
2507 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2508 or offset that depends on a field within a record. */
2511 contains_placeholder_p (const_tree exp
)
2513 enum tree_code code
;
2518 code
= TREE_CODE (exp
);
2519 if (code
== PLACEHOLDER_EXPR
)
2522 switch (TREE_CODE_CLASS (code
))
2525 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2526 position computations since they will be converted into a
2527 WITH_RECORD_EXPR involving the reference, which will assume
2528 here will be valid. */
2529 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2531 case tcc_exceptional
:
2532 if (code
== TREE_LIST
)
2533 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
2534 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
2539 case tcc_comparison
:
2540 case tcc_expression
:
2544 /* Ignoring the first operand isn't quite right, but works best. */
2545 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
2548 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2549 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
2550 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
2553 /* The save_expr function never wraps anything containing
2554 a PLACEHOLDER_EXPR. */
2561 switch (TREE_CODE_LENGTH (code
))
2564 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2566 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2567 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
2578 const_call_expr_arg_iterator iter
;
2579 FOR_EACH_CONST_CALL_EXPR_ARG (arg
, iter
, exp
)
2580 if (CONTAINS_PLACEHOLDER_P (arg
))
2594 /* Return true if any part of the computation of TYPE involves a
2595 PLACEHOLDER_EXPR. This includes size, bounds, qualifiers
2596 (for QUAL_UNION_TYPE) and field positions. */
2599 type_contains_placeholder_1 (const_tree type
)
2601 /* If the size contains a placeholder or the parent type (component type in
2602 the case of arrays) type involves a placeholder, this type does. */
2603 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
2604 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
2605 || (TREE_TYPE (type
) != 0
2606 && type_contains_placeholder_p (TREE_TYPE (type
))))
2609 /* Now do type-specific checks. Note that the last part of the check above
2610 greatly limits what we have to do below. */
2611 switch (TREE_CODE (type
))
2619 case REFERENCE_TYPE
:
2627 case FIXED_POINT_TYPE
:
2628 /* Here we just check the bounds. */
2629 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
2630 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
2633 /* We're already checked the component type (TREE_TYPE), so just check
2635 return type_contains_placeholder_p (TYPE_DOMAIN (type
));
2639 case QUAL_UNION_TYPE
:
2643 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2644 if (TREE_CODE (field
) == FIELD_DECL
2645 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
2646 || (TREE_CODE (type
) == QUAL_UNION_TYPE
2647 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
2648 || type_contains_placeholder_p (TREE_TYPE (field
))))
2660 type_contains_placeholder_p (tree type
)
2664 /* If the contains_placeholder_bits field has been initialized,
2665 then we know the answer. */
2666 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
2667 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
2669 /* Indicate that we've seen this type node, and the answer is false.
2670 This is what we want to return if we run into recursion via fields. */
2671 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
2673 /* Compute the real value. */
2674 result
= type_contains_placeholder_1 (type
);
2676 /* Store the real value. */
2677 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
2682 /* Push tree EXP onto vector QUEUE if it is not already present. */
2685 push_without_duplicates (tree exp
, VEC (tree
, heap
) **queue
)
2690 for (i
= 0; VEC_iterate (tree
, *queue
, i
, iter
); i
++)
2691 if (simple_cst_equal (iter
, exp
) == 1)
2695 VEC_safe_push (tree
, heap
, *queue
, exp
);
2698 /* Given a tree EXP, find all occurences of references to fields
2699 in a PLACEHOLDER_EXPR and place them in vector REFS without
2700 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
2701 we assume here that EXP contains only arithmetic expressions
2702 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
2706 find_placeholder_in_expr (tree exp
, VEC (tree
, heap
) **refs
)
2708 enum tree_code code
= TREE_CODE (exp
);
2712 /* We handle TREE_LIST and COMPONENT_REF separately. */
2713 if (code
== TREE_LIST
)
2715 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), refs
);
2716 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), refs
);
2718 else if (code
== COMPONENT_REF
)
2720 for (inner
= TREE_OPERAND (exp
, 0);
2721 REFERENCE_CLASS_P (inner
);
2722 inner
= TREE_OPERAND (inner
, 0))
2725 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
)
2726 push_without_duplicates (exp
, refs
);
2728 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), refs
);
2731 switch (TREE_CODE_CLASS (code
))
2736 case tcc_declaration
:
2737 /* Variables allocated to static storage can stay. */
2738 if (!TREE_STATIC (exp
))
2739 push_without_duplicates (exp
, refs
);
2742 case tcc_expression
:
2743 /* This is the pattern built in ada/make_aligning_type. */
2744 if (code
== ADDR_EXPR
2745 && TREE_CODE (TREE_OPERAND (exp
, 0)) == PLACEHOLDER_EXPR
)
2747 push_without_duplicates (exp
, refs
);
2751 /* Fall through... */
2753 case tcc_exceptional
:
2756 case tcc_comparison
:
2758 for (i
= 0; i
< TREE_CODE_LENGTH (code
); i
++)
2759 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
2763 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
2764 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
2772 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2773 return a tree with all occurrences of references to F in a
2774 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
2775 CONST_DECLs. Note that we assume here that EXP contains only
2776 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
2777 occurring only in their argument list. */
2780 substitute_in_expr (tree exp
, tree f
, tree r
)
2782 enum tree_code code
= TREE_CODE (exp
);
2783 tree op0
, op1
, op2
, op3
;
2786 /* We handle TREE_LIST and COMPONENT_REF separately. */
2787 if (code
== TREE_LIST
)
2789 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
2790 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
2791 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
2794 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
2796 else if (code
== COMPONENT_REF
)
2800 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2801 and it is the right field, replace it with R. */
2802 for (inner
= TREE_OPERAND (exp
, 0);
2803 REFERENCE_CLASS_P (inner
);
2804 inner
= TREE_OPERAND (inner
, 0))
2808 op1
= TREE_OPERAND (exp
, 1);
2810 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& op1
== f
)
2813 /* If this expression hasn't been completed let, leave it alone. */
2814 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& !TREE_TYPE (inner
))
2817 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2818 if (op0
== TREE_OPERAND (exp
, 0))
2822 = fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
), op0
, op1
, NULL_TREE
);
2825 switch (TREE_CODE_CLASS (code
))
2830 case tcc_declaration
:
2836 case tcc_expression
:
2840 /* Fall through... */
2842 case tcc_exceptional
:
2845 case tcc_comparison
:
2847 switch (TREE_CODE_LENGTH (code
))
2853 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2854 if (op0
== TREE_OPERAND (exp
, 0))
2857 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
2861 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2862 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2864 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
2867 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
2871 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2872 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2873 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
2875 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2876 && op2
== TREE_OPERAND (exp
, 2))
2879 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
2883 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2884 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2885 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
2886 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
2888 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2889 && op2
== TREE_OPERAND (exp
, 2)
2890 && op3
== TREE_OPERAND (exp
, 3))
2894 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
2906 new_tree
= NULL_TREE
;
2908 /* If we are trying to replace F with a constant, inline back
2909 functions which do nothing else than computing a value from
2910 the arguments they are passed. This makes it possible to
2911 fold partially or entirely the replacement expression. */
2912 if (CONSTANT_CLASS_P (r
) && code
== CALL_EXPR
)
2914 tree t
= maybe_inline_call_in_expr (exp
);
2916 return SUBSTITUTE_IN_EXPR (t
, f
, r
);
2919 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
2921 tree op
= TREE_OPERAND (exp
, i
);
2922 tree new_op
= SUBSTITUTE_IN_EXPR (op
, f
, r
);
2926 new_tree
= copy_node (exp
);
2927 TREE_OPERAND (new_tree
, i
) = new_op
;
2933 new_tree
= fold (new_tree
);
2934 if (TREE_CODE (new_tree
) == CALL_EXPR
)
2935 process_call_operands (new_tree
);
2946 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
2950 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
2951 for it within OBJ, a tree that is an object or a chain of references. */
2954 substitute_placeholder_in_expr (tree exp
, tree obj
)
2956 enum tree_code code
= TREE_CODE (exp
);
2957 tree op0
, op1
, op2
, op3
;
2960 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
2961 in the chain of OBJ. */
2962 if (code
== PLACEHOLDER_EXPR
)
2964 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
2967 for (elt
= obj
; elt
!= 0;
2968 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
2969 || TREE_CODE (elt
) == COND_EXPR
)
2970 ? TREE_OPERAND (elt
, 1)
2971 : (REFERENCE_CLASS_P (elt
)
2972 || UNARY_CLASS_P (elt
)
2973 || BINARY_CLASS_P (elt
)
2974 || VL_EXP_CLASS_P (elt
)
2975 || EXPRESSION_CLASS_P (elt
))
2976 ? TREE_OPERAND (elt
, 0) : 0))
2977 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
2980 for (elt
= obj
; elt
!= 0;
2981 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
2982 || TREE_CODE (elt
) == COND_EXPR
)
2983 ? TREE_OPERAND (elt
, 1)
2984 : (REFERENCE_CLASS_P (elt
)
2985 || UNARY_CLASS_P (elt
)
2986 || BINARY_CLASS_P (elt
)
2987 || VL_EXP_CLASS_P (elt
)
2988 || EXPRESSION_CLASS_P (elt
))
2989 ? TREE_OPERAND (elt
, 0) : 0))
2990 if (POINTER_TYPE_P (TREE_TYPE (elt
))
2991 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
2993 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
2995 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2996 survives until RTL generation, there will be an error. */
3000 /* TREE_LIST is special because we need to look at TREE_VALUE
3001 and TREE_CHAIN, not TREE_OPERANDS. */
3002 else if (code
== TREE_LIST
)
3004 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
3005 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
3006 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3009 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3012 switch (TREE_CODE_CLASS (code
))
3015 case tcc_declaration
:
3018 case tcc_exceptional
:
3021 case tcc_comparison
:
3022 case tcc_expression
:
3025 switch (TREE_CODE_LENGTH (code
))
3031 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3032 if (op0
== TREE_OPERAND (exp
, 0))
3035 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
3039 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3040 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3042 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
3045 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
3049 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3050 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3051 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
3053 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3054 && op2
== TREE_OPERAND (exp
, 2))
3057 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
3061 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3062 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3063 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
3064 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
3066 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3067 && op2
== TREE_OPERAND (exp
, 2)
3068 && op3
== TREE_OPERAND (exp
, 3))
3072 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
3084 new_tree
= NULL_TREE
;
3086 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3088 tree op
= TREE_OPERAND (exp
, i
);
3089 tree new_op
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (op
, obj
);
3093 new_tree
= copy_node (exp
);
3094 TREE_OPERAND (new_tree
, i
) = new_op
;
3100 new_tree
= fold (new_tree
);
3101 if (TREE_CODE (new_tree
) == CALL_EXPR
)
3102 process_call_operands (new_tree
);
3113 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
3117 /* Stabilize a reference so that we can use it any number of times
3118 without causing its operands to be evaluated more than once.
3119 Returns the stabilized reference. This works by means of save_expr,
3120 so see the caveats in the comments about save_expr.
3122 Also allows conversion expressions whose operands are references.
3123 Any other kind of expression is returned unchanged. */
3126 stabilize_reference (tree ref
)
3129 enum tree_code code
= TREE_CODE (ref
);
3136 /* No action is needed in this case. */
3141 case FIX_TRUNC_EXPR
:
3142 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
3146 result
= build_nt (INDIRECT_REF
,
3147 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
3151 result
= build_nt (COMPONENT_REF
,
3152 stabilize_reference (TREE_OPERAND (ref
, 0)),
3153 TREE_OPERAND (ref
, 1), NULL_TREE
);
3157 result
= build_nt (BIT_FIELD_REF
,
3158 stabilize_reference (TREE_OPERAND (ref
, 0)),
3159 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
3160 stabilize_reference_1 (TREE_OPERAND (ref
, 2)));
3164 result
= build_nt (ARRAY_REF
,
3165 stabilize_reference (TREE_OPERAND (ref
, 0)),
3166 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
3167 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
3170 case ARRAY_RANGE_REF
:
3171 result
= build_nt (ARRAY_RANGE_REF
,
3172 stabilize_reference (TREE_OPERAND (ref
, 0)),
3173 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
3174 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
3178 /* We cannot wrap the first expression in a SAVE_EXPR, as then
3179 it wouldn't be ignored. This matters when dealing with
3181 return stabilize_reference_1 (ref
);
3183 /* If arg isn't a kind of lvalue we recognize, make no change.
3184 Caller should recognize the error for an invalid lvalue. */
3189 return error_mark_node
;
3192 TREE_TYPE (result
) = TREE_TYPE (ref
);
3193 TREE_READONLY (result
) = TREE_READONLY (ref
);
3194 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
3195 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
3200 /* Subroutine of stabilize_reference; this is called for subtrees of
3201 references. Any expression with side-effects must be put in a SAVE_EXPR
3202 to ensure that it is only evaluated once.
3204 We don't put SAVE_EXPR nodes around everything, because assigning very
3205 simple expressions to temporaries causes us to miss good opportunities
3206 for optimizations. Among other things, the opportunity to fold in the
3207 addition of a constant into an addressing mode often gets lost, e.g.
3208 "y[i+1] += x;". In general, we take the approach that we should not make
3209 an assignment unless we are forced into it - i.e., that any non-side effect
3210 operator should be allowed, and that cse should take care of coalescing
3211 multiple utterances of the same expression should that prove fruitful. */
3214 stabilize_reference_1 (tree e
)
3217 enum tree_code code
= TREE_CODE (e
);
3219 /* We cannot ignore const expressions because it might be a reference
3220 to a const array but whose index contains side-effects. But we can
3221 ignore things that are actual constant or that already have been
3222 handled by this function. */
3224 if (tree_invariant_p (e
))
3227 switch (TREE_CODE_CLASS (code
))
3229 case tcc_exceptional
:
3231 case tcc_declaration
:
3232 case tcc_comparison
:
3234 case tcc_expression
:
3237 /* If the expression has side-effects, then encase it in a SAVE_EXPR
3238 so that it will only be evaluated once. */
3239 /* The reference (r) and comparison (<) classes could be handled as
3240 below, but it is generally faster to only evaluate them once. */
3241 if (TREE_SIDE_EFFECTS (e
))
3242 return save_expr (e
);
3246 /* Constants need no processing. In fact, we should never reach
3251 /* Division is slow and tends to be compiled with jumps,
3252 especially the division by powers of 2 that is often
3253 found inside of an array reference. So do it just once. */
3254 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
3255 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
3256 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
3257 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
3258 return save_expr (e
);
3259 /* Recursively stabilize each operand. */
3260 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
3261 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
3265 /* Recursively stabilize each operand. */
3266 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
3273 TREE_TYPE (result
) = TREE_TYPE (e
);
3274 TREE_READONLY (result
) = TREE_READONLY (e
);
3275 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
3276 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
3281 /* Low-level constructors for expressions. */
3283 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
3284 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
3287 recompute_tree_invariant_for_addr_expr (tree t
)
3290 bool tc
= true, se
= false;
3292 /* We started out assuming this address is both invariant and constant, but
3293 does not have side effects. Now go down any handled components and see if
3294 any of them involve offsets that are either non-constant or non-invariant.
3295 Also check for side-effects.
3297 ??? Note that this code makes no attempt to deal with the case where
3298 taking the address of something causes a copy due to misalignment. */
3300 #define UPDATE_FLAGS(NODE) \
3301 do { tree _node = (NODE); \
3302 if (_node && !TREE_CONSTANT (_node)) tc = false; \
3303 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
3305 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
3306 node
= TREE_OPERAND (node
, 0))
3308 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
3309 array reference (probably made temporarily by the G++ front end),
3310 so ignore all the operands. */
3311 if ((TREE_CODE (node
) == ARRAY_REF
3312 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
3313 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
3315 UPDATE_FLAGS (TREE_OPERAND (node
, 1));
3316 if (TREE_OPERAND (node
, 2))
3317 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3318 if (TREE_OPERAND (node
, 3))
3319 UPDATE_FLAGS (TREE_OPERAND (node
, 3));
3321 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
3322 FIELD_DECL, apparently. The G++ front end can put something else
3323 there, at least temporarily. */
3324 else if (TREE_CODE (node
) == COMPONENT_REF
3325 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
3327 if (TREE_OPERAND (node
, 2))
3328 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3330 else if (TREE_CODE (node
) == BIT_FIELD_REF
)
3331 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3334 node
= lang_hooks
.expr_to_decl (node
, &tc
, &se
);
3336 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
3337 the address, since &(*a)->b is a form of addition. If it's a constant, the
3338 address is constant too. If it's a decl, its address is constant if the
3339 decl is static. Everything else is not constant and, furthermore,
3340 taking the address of a volatile variable is not volatile. */
3341 if (TREE_CODE (node
) == INDIRECT_REF
)
3342 UPDATE_FLAGS (TREE_OPERAND (node
, 0));
3343 else if (CONSTANT_CLASS_P (node
))
3345 else if (DECL_P (node
))
3346 tc
&= (staticp (node
) != NULL_TREE
);
3350 se
|= TREE_SIDE_EFFECTS (node
);
3354 TREE_CONSTANT (t
) = tc
;
3355 TREE_SIDE_EFFECTS (t
) = se
;
3359 /* Build an expression of code CODE, data type TYPE, and operands as
3360 specified. Expressions and reference nodes can be created this way.
3361 Constants, decls, types and misc nodes cannot be.
3363 We define 5 non-variadic functions, from 0 to 4 arguments. This is
3364 enough for all extant tree codes. */
3367 build0_stat (enum tree_code code
, tree tt MEM_STAT_DECL
)
3371 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
3373 t
= make_node_stat (code PASS_MEM_STAT
);
3380 build1_stat (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
3382 int length
= sizeof (struct tree_exp
);
3383 #ifdef GATHER_STATISTICS
3384 tree_node_kind kind
;
3388 #ifdef GATHER_STATISTICS
3389 switch (TREE_CODE_CLASS (code
))
3391 case tcc_statement
: /* an expression with side effects */
3394 case tcc_reference
: /* a reference */
3402 tree_node_counts
[(int) kind
]++;
3403 tree_node_sizes
[(int) kind
] += length
;
3406 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
3408 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
3410 memset (t
, 0, sizeof (struct tree_common
));
3412 TREE_SET_CODE (t
, code
);
3414 TREE_TYPE (t
) = type
;
3415 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
3416 TREE_OPERAND (t
, 0) = node
;
3417 TREE_BLOCK (t
) = NULL_TREE
;
3418 if (node
&& !TYPE_P (node
))
3420 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
3421 TREE_READONLY (t
) = TREE_READONLY (node
);
3424 if (TREE_CODE_CLASS (code
) == tcc_statement
)
3425 TREE_SIDE_EFFECTS (t
) = 1;
3429 /* All of these have side-effects, no matter what their
3431 TREE_SIDE_EFFECTS (t
) = 1;
3432 TREE_READONLY (t
) = 0;
3435 case MISALIGNED_INDIRECT_REF
:
3436 case ALIGN_INDIRECT_REF
:
3438 /* Whether a dereference is readonly has nothing to do with whether
3439 its operand is readonly. */
3440 TREE_READONLY (t
) = 0;
3445 recompute_tree_invariant_for_addr_expr (t
);
3449 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
3450 && node
&& !TYPE_P (node
)
3451 && TREE_CONSTANT (node
))
3452 TREE_CONSTANT (t
) = 1;
3453 if (TREE_CODE_CLASS (code
) == tcc_reference
3454 && node
&& TREE_THIS_VOLATILE (node
))
3455 TREE_THIS_VOLATILE (t
) = 1;
3462 #define PROCESS_ARG(N) \
3464 TREE_OPERAND (t, N) = arg##N; \
3465 if (arg##N &&!TYPE_P (arg##N)) \
3467 if (TREE_SIDE_EFFECTS (arg##N)) \
3469 if (!TREE_READONLY (arg##N) \
3470 && !CONSTANT_CLASS_P (arg##N)) \
3472 if (!TREE_CONSTANT (arg##N)) \
3478 build2_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
3480 bool constant
, read_only
, side_effects
;
3483 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
3485 if ((code
== MINUS_EXPR
|| code
== PLUS_EXPR
|| code
== MULT_EXPR
)
3486 && arg0
&& arg1
&& tt
&& POINTER_TYPE_P (tt
)
3487 /* When sizetype precision doesn't match that of pointers
3488 we need to be able to build explicit extensions or truncations
3489 of the offset argument. */
3490 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (tt
))
3491 gcc_assert (TREE_CODE (arg0
) == INTEGER_CST
3492 && TREE_CODE (arg1
) == INTEGER_CST
);
3494 if (code
== POINTER_PLUS_EXPR
&& arg0
&& arg1
&& tt
)
3495 gcc_assert (POINTER_TYPE_P (tt
) && POINTER_TYPE_P (TREE_TYPE (arg0
))
3496 && INTEGRAL_TYPE_P (TREE_TYPE (arg1
))
3497 && useless_type_conversion_p (sizetype
, TREE_TYPE (arg1
)));
3499 t
= make_node_stat (code PASS_MEM_STAT
);
3502 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
3503 result based on those same flags for the arguments. But if the
3504 arguments aren't really even `tree' expressions, we shouldn't be trying
3507 /* Expressions without side effects may be constant if their
3508 arguments are as well. */
3509 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
3510 || TREE_CODE_CLASS (code
) == tcc_binary
);
3512 side_effects
= TREE_SIDE_EFFECTS (t
);
3517 TREE_READONLY (t
) = read_only
;
3518 TREE_CONSTANT (t
) = constant
;
3519 TREE_SIDE_EFFECTS (t
) = side_effects
;
3520 TREE_THIS_VOLATILE (t
)
3521 = (TREE_CODE_CLASS (code
) == tcc_reference
3522 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3529 build3_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3530 tree arg2 MEM_STAT_DECL
)
3532 bool constant
, read_only
, side_effects
;
3535 gcc_assert (TREE_CODE_LENGTH (code
) == 3);
3536 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
3538 t
= make_node_stat (code PASS_MEM_STAT
);
3543 /* As a special exception, if COND_EXPR has NULL branches, we
3544 assume that it is a gimple statement and always consider
3545 it to have side effects. */
3546 if (code
== COND_EXPR
3547 && tt
== void_type_node
3548 && arg1
== NULL_TREE
3549 && arg2
== NULL_TREE
)
3550 side_effects
= true;
3552 side_effects
= TREE_SIDE_EFFECTS (t
);
3558 if (code
== COND_EXPR
)
3559 TREE_READONLY (t
) = read_only
;
3561 TREE_SIDE_EFFECTS (t
) = side_effects
;
3562 TREE_THIS_VOLATILE (t
)
3563 = (TREE_CODE_CLASS (code
) == tcc_reference
3564 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3570 build4_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3571 tree arg2
, tree arg3 MEM_STAT_DECL
)
3573 bool constant
, read_only
, side_effects
;
3576 gcc_assert (TREE_CODE_LENGTH (code
) == 4);
3578 t
= make_node_stat (code PASS_MEM_STAT
);
3581 side_effects
= TREE_SIDE_EFFECTS (t
);
3588 TREE_SIDE_EFFECTS (t
) = side_effects
;
3589 TREE_THIS_VOLATILE (t
)
3590 = (TREE_CODE_CLASS (code
) == tcc_reference
3591 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3597 build5_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3598 tree arg2
, tree arg3
, tree arg4 MEM_STAT_DECL
)
3600 bool constant
, read_only
, side_effects
;
3603 gcc_assert (TREE_CODE_LENGTH (code
) == 5);
3605 t
= make_node_stat (code PASS_MEM_STAT
);
3608 side_effects
= TREE_SIDE_EFFECTS (t
);
3616 TREE_SIDE_EFFECTS (t
) = side_effects
;
3617 TREE_THIS_VOLATILE (t
)
3618 = (TREE_CODE_CLASS (code
) == tcc_reference
3619 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3625 build6_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3626 tree arg2
, tree arg3
, tree arg4
, tree arg5 MEM_STAT_DECL
)
3628 bool constant
, read_only
, side_effects
;
3631 gcc_assert (code
== TARGET_MEM_REF
);
3633 t
= make_node_stat (code PASS_MEM_STAT
);
3636 side_effects
= TREE_SIDE_EFFECTS (t
);
3645 TREE_SIDE_EFFECTS (t
) = side_effects
;
3646 TREE_THIS_VOLATILE (t
) = 0;
3651 /* Similar except don't specify the TREE_TYPE
3652 and leave the TREE_SIDE_EFFECTS as 0.
3653 It is permissible for arguments to be null,
3654 or even garbage if their values do not matter. */
3657 build_nt (enum tree_code code
, ...)
3664 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
3668 t
= make_node (code
);
3669 length
= TREE_CODE_LENGTH (code
);
3671 for (i
= 0; i
< length
; i
++)
3672 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
3678 /* Similar to build_nt, but for creating a CALL_EXPR object with
3679 ARGLIST passed as a list. */
3682 build_nt_call_list (tree fn
, tree arglist
)
3687 t
= build_vl_exp (CALL_EXPR
, list_length (arglist
) + 3);
3688 CALL_EXPR_FN (t
) = fn
;
3689 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
3690 for (i
= 0; arglist
; arglist
= TREE_CHAIN (arglist
), i
++)
3691 CALL_EXPR_ARG (t
, i
) = TREE_VALUE (arglist
);
3695 /* Similar to build_nt, but for creating a CALL_EXPR object with a
3699 build_nt_call_vec (tree fn
, VEC(tree
,gc
) *args
)
3704 ret
= build_vl_exp (CALL_EXPR
, VEC_length (tree
, args
) + 3);
3705 CALL_EXPR_FN (ret
) = fn
;
3706 CALL_EXPR_STATIC_CHAIN (ret
) = NULL_TREE
;
3707 for (ix
= 0; VEC_iterate (tree
, args
, ix
, t
); ++ix
)
3708 CALL_EXPR_ARG (ret
, ix
) = t
;
3712 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
3713 We do NOT enter this node in any sort of symbol table.
3715 LOC is the location of the decl.
3717 layout_decl is used to set up the decl's storage layout.
3718 Other slots are initialized to 0 or null pointers. */
3721 build_decl_stat (location_t loc
, enum tree_code code
, tree name
,
3722 tree type MEM_STAT_DECL
)
3726 t
= make_node_stat (code PASS_MEM_STAT
);
3727 DECL_SOURCE_LOCATION (t
) = loc
;
3729 /* if (type == error_mark_node)
3730 type = integer_type_node; */
3731 /* That is not done, deliberately, so that having error_mark_node
3732 as the type can suppress useless errors in the use of this variable. */
3734 DECL_NAME (t
) = name
;
3735 TREE_TYPE (t
) = type
;
3737 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
3743 /* Builds and returns function declaration with NAME and TYPE. */
3746 build_fn_decl (const char *name
, tree type
)
3748 tree id
= get_identifier (name
);
3749 tree decl
= build_decl (input_location
, FUNCTION_DECL
, id
, type
);
3751 DECL_EXTERNAL (decl
) = 1;
3752 TREE_PUBLIC (decl
) = 1;
3753 DECL_ARTIFICIAL (decl
) = 1;
3754 TREE_NOTHROW (decl
) = 1;
3760 /* BLOCK nodes are used to represent the structure of binding contours
3761 and declarations, once those contours have been exited and their contents
3762 compiled. This information is used for outputting debugging info. */
3765 build_block (tree vars
, tree subblocks
, tree supercontext
, tree chain
)
3767 tree block
= make_node (BLOCK
);
3769 BLOCK_VARS (block
) = vars
;
3770 BLOCK_SUBBLOCKS (block
) = subblocks
;
3771 BLOCK_SUPERCONTEXT (block
) = supercontext
;
3772 BLOCK_CHAIN (block
) = chain
;
3777 expand_location (source_location loc
)
3779 expanded_location xloc
;
3789 const struct line_map
*map
= linemap_lookup (line_table
, loc
);
3790 xloc
.file
= map
->to_file
;
3791 xloc
.line
= SOURCE_LINE (map
, loc
);
3792 xloc
.column
= SOURCE_COLUMN (map
, loc
);
3793 xloc
.sysp
= map
->sysp
!= 0;
3799 /* Source location accessor functions. */
3803 set_expr_locus (tree node
, source_location
*loc
)
3806 EXPR_CHECK (node
)->exp
.locus
= UNKNOWN_LOCATION
;
3808 EXPR_CHECK (node
)->exp
.locus
= *loc
;
3811 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
3813 LOC is the location to use in tree T. */
3816 protected_set_expr_location (tree t
, location_t loc
)
3818 if (t
&& CAN_HAVE_LOCATION_P (t
))
3819 SET_EXPR_LOCATION (t
, loc
);
3822 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
3826 build_decl_attribute_variant (tree ddecl
, tree attribute
)
3828 DECL_ATTRIBUTES (ddecl
) = attribute
;
3832 /* Borrowed from hashtab.c iterative_hash implementation. */
3833 #define mix(a,b,c) \
3835 a -= b; a -= c; a ^= (c>>13); \
3836 b -= c; b -= a; b ^= (a<< 8); \
3837 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
3838 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
3839 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
3840 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
3841 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
3842 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
3843 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
3847 /* Produce good hash value combining VAL and VAL2. */
3849 iterative_hash_hashval_t (hashval_t val
, hashval_t val2
)
3851 /* the golden ratio; an arbitrary value. */
3852 hashval_t a
= 0x9e3779b9;
3858 /* Produce good hash value combining VAL and VAL2. */
3859 static inline hashval_t
3860 iterative_hash_host_wide_int (HOST_WIDE_INT val
, hashval_t val2
)
3862 if (sizeof (HOST_WIDE_INT
) == sizeof (hashval_t
))
3863 return iterative_hash_hashval_t (val
, val2
);
3866 hashval_t a
= (hashval_t
) val
;
3867 /* Avoid warnings about shifting of more than the width of the type on
3868 hosts that won't execute this path. */
3870 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 8 + zero
));
3872 if (sizeof (HOST_WIDE_INT
) > 2 * sizeof (hashval_t
))
3874 hashval_t a
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 16 + zero
));
3875 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 24 + zero
));
3882 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3883 is ATTRIBUTE and its qualifiers are QUALS.
3885 Record such modified types already made so we don't make duplicates. */
3888 build_type_attribute_qual_variant (tree ttype
, tree attribute
, int quals
)
3890 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
3892 hashval_t hashcode
= 0;
3894 enum tree_code code
= TREE_CODE (ttype
);
3896 /* Building a distinct copy of a tagged type is inappropriate; it
3897 causes breakage in code that expects there to be a one-to-one
3898 relationship between a struct and its fields.
3899 build_duplicate_type is another solution (as used in
3900 handle_transparent_union_attribute), but that doesn't play well
3901 with the stronger C++ type identity model. */
3902 if (TREE_CODE (ttype
) == RECORD_TYPE
3903 || TREE_CODE (ttype
) == UNION_TYPE
3904 || TREE_CODE (ttype
) == QUAL_UNION_TYPE
3905 || TREE_CODE (ttype
) == ENUMERAL_TYPE
)
3907 warning (OPT_Wattributes
,
3908 "ignoring attributes applied to %qT after definition",
3909 TYPE_MAIN_VARIANT (ttype
));
3910 return build_qualified_type (ttype
, quals
);
3913 ttype
= build_qualified_type (ttype
, TYPE_UNQUALIFIED
);
3914 ntype
= build_distinct_type_copy (ttype
);
3916 TYPE_ATTRIBUTES (ntype
) = attribute
;
3918 hashcode
= iterative_hash_object (code
, hashcode
);
3919 if (TREE_TYPE (ntype
))
3920 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype
)),
3922 hashcode
= attribute_hash_list (attribute
, hashcode
);
3924 switch (TREE_CODE (ntype
))
3927 hashcode
= type_hash_list (TYPE_ARG_TYPES (ntype
), hashcode
);
3930 if (TYPE_DOMAIN (ntype
))
3931 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype
)),
3935 hashcode
= iterative_hash_object
3936 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype
)), hashcode
);
3937 hashcode
= iterative_hash_object
3938 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype
)), hashcode
);
3941 case FIXED_POINT_TYPE
:
3943 unsigned int precision
= TYPE_PRECISION (ntype
);
3944 hashcode
= iterative_hash_object (precision
, hashcode
);
3951 ntype
= type_hash_canon (hashcode
, ntype
);
3953 /* If the target-dependent attributes make NTYPE different from
3954 its canonical type, we will need to use structural equality
3955 checks for this type. */
3956 if (TYPE_STRUCTURAL_EQUALITY_P (ttype
)
3957 || !targetm
.comp_type_attributes (ntype
, ttype
))
3958 SET_TYPE_STRUCTURAL_EQUALITY (ntype
);
3959 else if (TYPE_CANONICAL (ntype
) == ntype
)
3960 TYPE_CANONICAL (ntype
) = TYPE_CANONICAL (ttype
);
3962 ttype
= build_qualified_type (ntype
, quals
);
3964 else if (TYPE_QUALS (ttype
) != quals
)
3965 ttype
= build_qualified_type (ttype
, quals
);
3971 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3974 Record such modified types already made so we don't make duplicates. */
3977 build_type_attribute_variant (tree ttype
, tree attribute
)
3979 return build_type_attribute_qual_variant (ttype
, attribute
,
3980 TYPE_QUALS (ttype
));
3983 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3986 We try both `text' and `__text__', ATTR may be either one. */
3987 /* ??? It might be a reasonable simplification to require ATTR to be only
3988 `text'. One might then also require attribute lists to be stored in
3989 their canonicalized form. */
3992 is_attribute_with_length_p (const char *attr
, int attr_len
, const_tree ident
)
3997 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
4000 p
= IDENTIFIER_POINTER (ident
);
4001 ident_len
= IDENTIFIER_LENGTH (ident
);
4003 if (ident_len
== attr_len
4004 && strcmp (attr
, p
) == 0)
4007 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
4010 gcc_assert (attr
[1] == '_');
4011 gcc_assert (attr
[attr_len
- 2] == '_');
4012 gcc_assert (attr
[attr_len
- 1] == '_');
4013 if (ident_len
== attr_len
- 4
4014 && strncmp (attr
+ 2, p
, attr_len
- 4) == 0)
4019 if (ident_len
== attr_len
+ 4
4020 && p
[0] == '_' && p
[1] == '_'
4021 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
4022 && strncmp (attr
, p
+ 2, attr_len
) == 0)
4029 /* Return nonzero if IDENT is a valid name for attribute ATTR,
4032 We try both `text' and `__text__', ATTR may be either one. */
4035 is_attribute_p (const char *attr
, const_tree ident
)
4037 return is_attribute_with_length_p (attr
, strlen (attr
), ident
);
4040 /* Given an attribute name and a list of attributes, return a pointer to the
4041 attribute's list element if the attribute is part of the list, or NULL_TREE
4042 if not found. If the attribute appears more than once, this only
4043 returns the first occurrence; the TREE_CHAIN of the return value should
4044 be passed back in if further occurrences are wanted. */
4047 lookup_attribute (const char *attr_name
, tree list
)
4050 size_t attr_len
= strlen (attr_name
);
4052 for (l
= list
; l
; l
= TREE_CHAIN (l
))
4054 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
4055 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
4061 /* Remove any instances of attribute ATTR_NAME in LIST and return the
4065 remove_attribute (const char *attr_name
, tree list
)
4068 size_t attr_len
= strlen (attr_name
);
4070 for (p
= &list
; *p
; )
4073 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
4074 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
4075 *p
= TREE_CHAIN (l
);
4077 p
= &TREE_CHAIN (l
);
4083 /* Return an attribute list that is the union of a1 and a2. */
4086 merge_attributes (tree a1
, tree a2
)
4090 /* Either one unset? Take the set one. */
4092 if ((attributes
= a1
) == 0)
4095 /* One that completely contains the other? Take it. */
4097 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
4099 if (attribute_list_contained (a2
, a1
))
4103 /* Pick the longest list, and hang on the other list. */
4105 if (list_length (a1
) < list_length (a2
))
4106 attributes
= a2
, a2
= a1
;
4108 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
4111 for (a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
4114 a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
4117 if (TREE_VALUE (a
) != NULL
4118 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
4119 && TREE_VALUE (a2
) != NULL
4120 && TREE_CODE (TREE_VALUE (a2
)) == TREE_LIST
)
4122 if (simple_cst_list_equal (TREE_VALUE (a
),
4123 TREE_VALUE (a2
)) == 1)
4126 else if (simple_cst_equal (TREE_VALUE (a
),
4127 TREE_VALUE (a2
)) == 1)
4132 a1
= copy_node (a2
);
4133 TREE_CHAIN (a1
) = attributes
;
4142 /* Given types T1 and T2, merge their attributes and return
4146 merge_type_attributes (tree t1
, tree t2
)
4148 return merge_attributes (TYPE_ATTRIBUTES (t1
),
4149 TYPE_ATTRIBUTES (t2
));
4152 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
4156 merge_decl_attributes (tree olddecl
, tree newdecl
)
4158 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
4159 DECL_ATTRIBUTES (newdecl
));
4162 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
4164 /* Specialization of merge_decl_attributes for various Windows targets.
4166 This handles the following situation:
4168 __declspec (dllimport) int foo;
4171 The second instance of `foo' nullifies the dllimport. */
4174 merge_dllimport_decl_attributes (tree old
, tree new_tree
)
4177 int delete_dllimport_p
= 1;
4179 /* What we need to do here is remove from `old' dllimport if it doesn't
4180 appear in `new'. dllimport behaves like extern: if a declaration is
4181 marked dllimport and a definition appears later, then the object
4182 is not dllimport'd. We also remove a `new' dllimport if the old list
4183 contains dllexport: dllexport always overrides dllimport, regardless
4184 of the order of declaration. */
4185 if (!VAR_OR_FUNCTION_DECL_P (new_tree
))
4186 delete_dllimport_p
= 0;
4187 else if (DECL_DLLIMPORT_P (new_tree
)
4188 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old
)))
4190 DECL_DLLIMPORT_P (new_tree
) = 0;
4191 warning (OPT_Wattributes
, "%q+D already declared with dllexport attribute: "
4192 "dllimport ignored", new_tree
);
4194 else if (DECL_DLLIMPORT_P (old
) && !DECL_DLLIMPORT_P (new_tree
))
4196 /* Warn about overriding a symbol that has already been used, e.g.:
4197 extern int __attribute__ ((dllimport)) foo;
4198 int* bar () {return &foo;}
4201 if (TREE_USED (old
))
4203 warning (0, "%q+D redeclared without dllimport attribute "
4204 "after being referenced with dll linkage", new_tree
);
4205 /* If we have used a variable's address with dllimport linkage,
4206 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
4207 decl may already have had TREE_CONSTANT computed.
4208 We still remove the attribute so that assembler code refers
4209 to '&foo rather than '_imp__foo'. */
4210 if (TREE_CODE (old
) == VAR_DECL
&& TREE_ADDRESSABLE (old
))
4211 DECL_DLLIMPORT_P (new_tree
) = 1;
4214 /* Let an inline definition silently override the external reference,
4215 but otherwise warn about attribute inconsistency. */
4216 else if (TREE_CODE (new_tree
) == VAR_DECL
4217 || !DECL_DECLARED_INLINE_P (new_tree
))
4218 warning (OPT_Wattributes
, "%q+D redeclared without dllimport attribute: "
4219 "previous dllimport ignored", new_tree
);
4222 delete_dllimport_p
= 0;
4224 a
= merge_attributes (DECL_ATTRIBUTES (old
), DECL_ATTRIBUTES (new_tree
));
4226 if (delete_dllimport_p
)
4229 const size_t attr_len
= strlen ("dllimport");
4231 /* Scan the list for dllimport and delete it. */
4232 for (prev
= NULL_TREE
, t
= a
; t
; prev
= t
, t
= TREE_CHAIN (t
))
4234 if (is_attribute_with_length_p ("dllimport", attr_len
,
4237 if (prev
== NULL_TREE
)
4240 TREE_CHAIN (prev
) = TREE_CHAIN (t
);
4249 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
4250 struct attribute_spec.handler. */
4253 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
4259 /* These attributes may apply to structure and union types being created,
4260 but otherwise should pass to the declaration involved. */
4263 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
4264 | (int) ATTR_FLAG_ARRAY_NEXT
))
4266 *no_add_attrs
= true;
4267 return tree_cons (name
, args
, NULL_TREE
);
4269 if (TREE_CODE (node
) == RECORD_TYPE
4270 || TREE_CODE (node
) == UNION_TYPE
)
4272 node
= TYPE_NAME (node
);
4278 warning (OPT_Wattributes
, "%qE attribute ignored",
4280 *no_add_attrs
= true;
4285 if (TREE_CODE (node
) != FUNCTION_DECL
4286 && TREE_CODE (node
) != VAR_DECL
4287 && TREE_CODE (node
) != TYPE_DECL
)
4289 *no_add_attrs
= true;
4290 warning (OPT_Wattributes
, "%qE attribute ignored",
4295 if (TREE_CODE (node
) == TYPE_DECL
4296 && TREE_CODE (TREE_TYPE (node
)) != RECORD_TYPE
4297 && TREE_CODE (TREE_TYPE (node
)) != UNION_TYPE
)
4299 *no_add_attrs
= true;
4300 warning (OPT_Wattributes
, "%qE attribute ignored",
4305 is_dllimport
= is_attribute_p ("dllimport", name
);
4307 /* Report error on dllimport ambiguities seen now before they cause
4311 /* Honor any target-specific overrides. */
4312 if (!targetm
.valid_dllimport_attribute_p (node
))
4313 *no_add_attrs
= true;
4315 else if (TREE_CODE (node
) == FUNCTION_DECL
4316 && DECL_DECLARED_INLINE_P (node
))
4318 warning (OPT_Wattributes
, "inline function %q+D declared as "
4319 " dllimport: attribute ignored", node
);
4320 *no_add_attrs
= true;
4322 /* Like MS, treat definition of dllimported variables and
4323 non-inlined functions on declaration as syntax errors. */
4324 else if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
))
4326 error ("function %q+D definition is marked dllimport", node
);
4327 *no_add_attrs
= true;
4330 else if (TREE_CODE (node
) == VAR_DECL
)
4332 if (DECL_INITIAL (node
))
4334 error ("variable %q+D definition is marked dllimport",
4336 *no_add_attrs
= true;
4339 /* `extern' needn't be specified with dllimport.
4340 Specify `extern' now and hope for the best. Sigh. */
4341 DECL_EXTERNAL (node
) = 1;
4342 /* Also, implicitly give dllimport'd variables declared within
4343 a function global scope, unless declared static. */
4344 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
4345 TREE_PUBLIC (node
) = 1;
4348 if (*no_add_attrs
== false)
4349 DECL_DLLIMPORT_P (node
) = 1;
4351 else if (TREE_CODE (node
) == FUNCTION_DECL
4352 && DECL_DECLARED_INLINE_P (node
))
4353 /* An exported function, even if inline, must be emitted. */
4354 DECL_EXTERNAL (node
) = 0;
4356 /* Report error if symbol is not accessible at global scope. */
4357 if (!TREE_PUBLIC (node
)
4358 && (TREE_CODE (node
) == VAR_DECL
4359 || TREE_CODE (node
) == FUNCTION_DECL
))
4361 error ("external linkage required for symbol %q+D because of "
4362 "%qE attribute", node
, name
);
4363 *no_add_attrs
= true;
4366 /* A dllexport'd entity must have default visibility so that other
4367 program units (shared libraries or the main executable) can see
4368 it. A dllimport'd entity must have default visibility so that
4369 the linker knows that undefined references within this program
4370 unit can be resolved by the dynamic linker. */
4373 if (DECL_VISIBILITY_SPECIFIED (node
)
4374 && DECL_VISIBILITY (node
) != VISIBILITY_DEFAULT
)
4375 error ("%qE implies default visibility, but %qD has already "
4376 "been declared with a different visibility",
4378 DECL_VISIBILITY (node
) = VISIBILITY_DEFAULT
;
4379 DECL_VISIBILITY_SPECIFIED (node
) = 1;
4385 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
4387 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
4388 of the various TYPE_QUAL values. */
4391 set_type_quals (tree type
, int type_quals
)
4393 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
4394 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
4395 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
4398 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
4401 check_qualified_type (const_tree cand
, const_tree base
, int type_quals
)
4403 return (TYPE_QUALS (cand
) == type_quals
4404 && TYPE_NAME (cand
) == TYPE_NAME (base
)
4405 /* Apparently this is needed for Objective-C. */
4406 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
4407 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
4408 TYPE_ATTRIBUTES (base
)));
4411 /* Return a version of the TYPE, qualified as indicated by the
4412 TYPE_QUALS, if one exists. If no qualified version exists yet,
4413 return NULL_TREE. */
4416 get_qualified_type (tree type
, int type_quals
)
4420 if (TYPE_QUALS (type
) == type_quals
)
4423 /* Search the chain of variants to see if there is already one there just
4424 like the one we need to have. If so, use that existing one. We must
4425 preserve the TYPE_NAME, since there is code that depends on this. */
4426 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
4427 if (check_qualified_type (t
, type
, type_quals
))
4433 /* Like get_qualified_type, but creates the type if it does not
4434 exist. This function never returns NULL_TREE. */
4437 build_qualified_type (tree type
, int type_quals
)
4441 /* See if we already have the appropriate qualified variant. */
4442 t
= get_qualified_type (type
, type_quals
);
4444 /* If not, build it. */
4447 t
= build_variant_type_copy (type
);
4448 set_type_quals (t
, type_quals
);
4450 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
4451 /* Propagate structural equality. */
4452 SET_TYPE_STRUCTURAL_EQUALITY (t
);
4453 else if (TYPE_CANONICAL (type
) != type
)
4454 /* Build the underlying canonical type, since it is different
4456 TYPE_CANONICAL (t
) = build_qualified_type (TYPE_CANONICAL (type
),
4459 /* T is its own canonical type. */
4460 TYPE_CANONICAL (t
) = t
;
4467 /* Create a new distinct copy of TYPE. The new type is made its own
4468 MAIN_VARIANT. If TYPE requires structural equality checks, the
4469 resulting type requires structural equality checks; otherwise, its
4470 TYPE_CANONICAL points to itself. */
4473 build_distinct_type_copy (tree type
)
4475 tree t
= copy_node (type
);
4477 TYPE_POINTER_TO (t
) = 0;
4478 TYPE_REFERENCE_TO (t
) = 0;
4480 /* Set the canonical type either to a new equivalence class, or
4481 propagate the need for structural equality checks. */
4482 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
4483 SET_TYPE_STRUCTURAL_EQUALITY (t
);
4485 TYPE_CANONICAL (t
) = t
;
4487 /* Make it its own variant. */
4488 TYPE_MAIN_VARIANT (t
) = t
;
4489 TYPE_NEXT_VARIANT (t
) = 0;
4491 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
4492 whose TREE_TYPE is not t. This can also happen in the Ada
4493 frontend when using subtypes. */
4498 /* Create a new variant of TYPE, equivalent but distinct. This is so
4499 the caller can modify it. TYPE_CANONICAL for the return type will
4500 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
4501 are considered equal by the language itself (or that both types
4502 require structural equality checks). */
4505 build_variant_type_copy (tree type
)
4507 tree t
, m
= TYPE_MAIN_VARIANT (type
);
4509 t
= build_distinct_type_copy (type
);
4511 /* Since we're building a variant, assume that it is a non-semantic
4512 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
4513 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
4515 /* Add the new type to the chain of variants of TYPE. */
4516 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
4517 TYPE_NEXT_VARIANT (m
) = t
;
4518 TYPE_MAIN_VARIANT (t
) = m
;
4523 /* Return true if the from tree in both tree maps are equal. */
4526 tree_map_base_eq (const void *va
, const void *vb
)
4528 const struct tree_map_base
*const a
= (const struct tree_map_base
*) va
,
4529 *const b
= (const struct tree_map_base
*) vb
;
4530 return (a
->from
== b
->from
);
4533 /* Hash a from tree in a tree_map. */
4536 tree_map_base_hash (const void *item
)
4538 return htab_hash_pointer (((const struct tree_map_base
*)item
)->from
);
4541 /* Return true if this tree map structure is marked for garbage collection
4542 purposes. We simply return true if the from tree is marked, so that this
4543 structure goes away when the from tree goes away. */
4546 tree_map_base_marked_p (const void *p
)
4548 return ggc_marked_p (((const struct tree_map_base
*) p
)->from
);
4552 tree_map_hash (const void *item
)
4554 return (((const struct tree_map
*) item
)->hash
);
4557 /* Return the initialization priority for DECL. */
4560 decl_init_priority_lookup (tree decl
)
4562 struct tree_priority_map
*h
;
4563 struct tree_map_base in
;
4565 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
4567 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
4568 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
4571 /* Return the finalization priority for DECL. */
4574 decl_fini_priority_lookup (tree decl
)
4576 struct tree_priority_map
*h
;
4577 struct tree_map_base in
;
4579 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
4581 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
4582 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
4585 /* Return the initialization and finalization priority information for
4586 DECL. If there is no previous priority information, a freshly
4587 allocated structure is returned. */
4589 static struct tree_priority_map
*
4590 decl_priority_info (tree decl
)
4592 struct tree_priority_map in
;
4593 struct tree_priority_map
*h
;
4596 in
.base
.from
= decl
;
4597 loc
= htab_find_slot (init_priority_for_decl
, &in
, INSERT
);
4598 h
= (struct tree_priority_map
*) *loc
;
4601 h
= GGC_CNEW (struct tree_priority_map
);
4603 h
->base
.from
= decl
;
4604 h
->init
= DEFAULT_INIT_PRIORITY
;
4605 h
->fini
= DEFAULT_INIT_PRIORITY
;
4611 /* Set the initialization priority for DECL to PRIORITY. */
4614 decl_init_priority_insert (tree decl
, priority_type priority
)
4616 struct tree_priority_map
*h
;
4618 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
4619 h
= decl_priority_info (decl
);
4623 /* Set the finalization priority for DECL to PRIORITY. */
4626 decl_fini_priority_insert (tree decl
, priority_type priority
)
4628 struct tree_priority_map
*h
;
4630 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
4631 h
= decl_priority_info (decl
);
4635 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
4638 print_debug_expr_statistics (void)
4640 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
4641 (long) htab_size (debug_expr_for_decl
),
4642 (long) htab_elements (debug_expr_for_decl
),
4643 htab_collisions (debug_expr_for_decl
));
4646 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
4649 print_value_expr_statistics (void)
4651 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
4652 (long) htab_size (value_expr_for_decl
),
4653 (long) htab_elements (value_expr_for_decl
),
4654 htab_collisions (value_expr_for_decl
));
4657 /* Lookup a debug expression for FROM, and return it if we find one. */
4660 decl_debug_expr_lookup (tree from
)
4662 struct tree_map
*h
, in
;
4663 in
.base
.from
= from
;
4665 h
= (struct tree_map
*) htab_find_with_hash (debug_expr_for_decl
, &in
,
4666 htab_hash_pointer (from
));
4672 /* Insert a mapping FROM->TO in the debug expression hashtable. */
4675 decl_debug_expr_insert (tree from
, tree to
)
4680 h
= GGC_NEW (struct tree_map
);
4681 h
->hash
= htab_hash_pointer (from
);
4682 h
->base
.from
= from
;
4684 loc
= htab_find_slot_with_hash (debug_expr_for_decl
, h
, h
->hash
, INSERT
);
4685 *(struct tree_map
**) loc
= h
;
4688 /* Lookup a value expression for FROM, and return it if we find one. */
4691 decl_value_expr_lookup (tree from
)
4693 struct tree_map
*h
, in
;
4694 in
.base
.from
= from
;
4696 h
= (struct tree_map
*) htab_find_with_hash (value_expr_for_decl
, &in
,
4697 htab_hash_pointer (from
));
4703 /* Insert a mapping FROM->TO in the value expression hashtable. */
4706 decl_value_expr_insert (tree from
, tree to
)
4711 h
= GGC_NEW (struct tree_map
);
4712 h
->hash
= htab_hash_pointer (from
);
4713 h
->base
.from
= from
;
4715 loc
= htab_find_slot_with_hash (value_expr_for_decl
, h
, h
->hash
, INSERT
);
4716 *(struct tree_map
**) loc
= h
;
4719 /* Hashing of types so that we don't make duplicates.
4720 The entry point is `type_hash_canon'. */
4722 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
4723 with types in the TREE_VALUE slots), by adding the hash codes
4724 of the individual types. */
4727 type_hash_list (const_tree list
, hashval_t hashcode
)
4731 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
4732 if (TREE_VALUE (tail
) != error_mark_node
)
4733 hashcode
= iterative_hash_object (TYPE_HASH (TREE_VALUE (tail
)),
4739 /* These are the Hashtable callback functions. */
4741 /* Returns true iff the types are equivalent. */
4744 type_hash_eq (const void *va
, const void *vb
)
4746 const struct type_hash
*const a
= (const struct type_hash
*) va
,
4747 *const b
= (const struct type_hash
*) vb
;
4749 /* First test the things that are the same for all types. */
4750 if (a
->hash
!= b
->hash
4751 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
4752 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
4753 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
4754 TYPE_ATTRIBUTES (b
->type
))
4755 || TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
4756 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
)
4757 || (TREE_CODE (a
->type
) != COMPLEX_TYPE
4758 && TYPE_NAME (a
->type
) != TYPE_NAME (b
->type
)))
4761 switch (TREE_CODE (a
->type
))
4766 case REFERENCE_TYPE
:
4770 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
4773 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
4774 && !(TYPE_VALUES (a
->type
)
4775 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
4776 && TYPE_VALUES (b
->type
)
4777 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
4778 && type_list_equal (TYPE_VALUES (a
->type
),
4779 TYPE_VALUES (b
->type
))))
4782 /* ... fall through ... */
4787 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
4788 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
4789 TYPE_MAX_VALUE (b
->type
)))
4790 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
4791 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
4792 TYPE_MIN_VALUE (b
->type
))));
4794 case FIXED_POINT_TYPE
:
4795 return TYPE_SATURATING (a
->type
) == TYPE_SATURATING (b
->type
);
4798 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
4801 return (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
4802 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
4803 || (TYPE_ARG_TYPES (a
->type
)
4804 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
4805 && TYPE_ARG_TYPES (b
->type
)
4806 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
4807 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
4808 TYPE_ARG_TYPES (b
->type
)))));
4811 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
4815 case QUAL_UNION_TYPE
:
4816 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
4817 || (TYPE_FIELDS (a
->type
)
4818 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
4819 && TYPE_FIELDS (b
->type
)
4820 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
4821 && type_list_equal (TYPE_FIELDS (a
->type
),
4822 TYPE_FIELDS (b
->type
))));
4825 if (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
4826 || (TYPE_ARG_TYPES (a
->type
)
4827 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
4828 && TYPE_ARG_TYPES (b
->type
)
4829 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
4830 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
4831 TYPE_ARG_TYPES (b
->type
))))
4839 if (lang_hooks
.types
.type_hash_eq
!= NULL
)
4840 return lang_hooks
.types
.type_hash_eq (a
->type
, b
->type
);
4845 /* Return the cached hash value. */
4848 type_hash_hash (const void *item
)
4850 return ((const struct type_hash
*) item
)->hash
;
4853 /* Look in the type hash table for a type isomorphic to TYPE.
4854 If one is found, return it. Otherwise return 0. */
4857 type_hash_lookup (hashval_t hashcode
, tree type
)
4859 struct type_hash
*h
, in
;
4861 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
4862 must call that routine before comparing TYPE_ALIGNs. */
4868 h
= (struct type_hash
*) htab_find_with_hash (type_hash_table
, &in
,
4875 /* Add an entry to the type-hash-table
4876 for a type TYPE whose hash code is HASHCODE. */
4879 type_hash_add (hashval_t hashcode
, tree type
)
4881 struct type_hash
*h
;
4884 h
= GGC_NEW (struct type_hash
);
4887 loc
= htab_find_slot_with_hash (type_hash_table
, h
, hashcode
, INSERT
);
4891 /* Given TYPE, and HASHCODE its hash code, return the canonical
4892 object for an identical type if one already exists.
4893 Otherwise, return TYPE, and record it as the canonical object.
4895 To use this function, first create a type of the sort you want.
4896 Then compute its hash code from the fields of the type that
4897 make it different from other similar types.
4898 Then call this function and use the value. */
4901 type_hash_canon (unsigned int hashcode
, tree type
)
4905 /* The hash table only contains main variants, so ensure that's what we're
4907 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
4909 if (!lang_hooks
.types
.hash_types
)
4912 /* See if the type is in the hash table already. If so, return it.
4913 Otherwise, add the type. */
4914 t1
= type_hash_lookup (hashcode
, type
);
4917 #ifdef GATHER_STATISTICS
4918 tree_node_counts
[(int) t_kind
]--;
4919 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type
);
4925 type_hash_add (hashcode
, type
);
4930 /* See if the data pointed to by the type hash table is marked. We consider
4931 it marked if the type is marked or if a debug type number or symbol
4932 table entry has been made for the type. This reduces the amount of
4933 debugging output and eliminates that dependency of the debug output on
4934 the number of garbage collections. */
4937 type_hash_marked_p (const void *p
)
4939 const_tree
const type
= ((const struct type_hash
*) p
)->type
;
4941 return ggc_marked_p (type
) || TYPE_SYMTAB_POINTER (type
);
4945 print_type_hash_statistics (void)
4947 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
4948 (long) htab_size (type_hash_table
),
4949 (long) htab_elements (type_hash_table
),
4950 htab_collisions (type_hash_table
));
4953 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
4954 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
4955 by adding the hash codes of the individual attributes. */
4958 attribute_hash_list (const_tree list
, hashval_t hashcode
)
4962 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
4963 /* ??? Do we want to add in TREE_VALUE too? */
4964 hashcode
= iterative_hash_object
4965 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail
)), hashcode
);
4969 /* Given two lists of attributes, return true if list l2 is
4970 equivalent to l1. */
4973 attribute_list_equal (const_tree l1
, const_tree l2
)
4975 return attribute_list_contained (l1
, l2
)
4976 && attribute_list_contained (l2
, l1
);
4979 /* Given two lists of attributes, return true if list L2 is
4980 completely contained within L1. */
4981 /* ??? This would be faster if attribute names were stored in a canonicalized
4982 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
4983 must be used to show these elements are equivalent (which they are). */
4984 /* ??? It's not clear that attributes with arguments will always be handled
4988 attribute_list_contained (const_tree l1
, const_tree l2
)
4992 /* First check the obvious, maybe the lists are identical. */
4996 /* Maybe the lists are similar. */
4997 for (t1
= l1
, t2
= l2
;
4999 && TREE_PURPOSE (t1
) == TREE_PURPOSE (t2
)
5000 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
5001 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
));
5003 /* Maybe the lists are equal. */
5004 if (t1
== 0 && t2
== 0)
5007 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
5010 /* This CONST_CAST is okay because lookup_attribute does not
5011 modify its argument and the return value is assigned to a
5013 for (attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
5014 CONST_CAST_TREE(l1
));
5016 attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
5019 if (TREE_VALUE (t2
) != NULL
5020 && TREE_CODE (TREE_VALUE (t2
)) == TREE_LIST
5021 && TREE_VALUE (attr
) != NULL
5022 && TREE_CODE (TREE_VALUE (attr
)) == TREE_LIST
)
5024 if (simple_cst_list_equal (TREE_VALUE (t2
),
5025 TREE_VALUE (attr
)) == 1)
5028 else if (simple_cst_equal (TREE_VALUE (t2
), TREE_VALUE (attr
)) == 1)
5039 /* Given two lists of types
5040 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
5041 return 1 if the lists contain the same types in the same order.
5042 Also, the TREE_PURPOSEs must match. */
5045 type_list_equal (const_tree l1
, const_tree l2
)
5049 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
5050 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
5051 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
5052 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
5053 && (TREE_TYPE (TREE_PURPOSE (t1
))
5054 == TREE_TYPE (TREE_PURPOSE (t2
))))))
5060 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
5061 given by TYPE. If the argument list accepts variable arguments,
5062 then this function counts only the ordinary arguments. */
5065 type_num_arguments (const_tree type
)
5070 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
5071 /* If the function does not take a variable number of arguments,
5072 the last element in the list will have type `void'. */
5073 if (VOID_TYPE_P (TREE_VALUE (t
)))
5081 /* Nonzero if integer constants T1 and T2
5082 represent the same constant value. */
5085 tree_int_cst_equal (const_tree t1
, const_tree t2
)
5090 if (t1
== 0 || t2
== 0)
5093 if (TREE_CODE (t1
) == INTEGER_CST
5094 && TREE_CODE (t2
) == INTEGER_CST
5095 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
5096 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
5102 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
5103 The precise way of comparison depends on their data type. */
5106 tree_int_cst_lt (const_tree t1
, const_tree t2
)
5111 if (TYPE_UNSIGNED (TREE_TYPE (t1
)) != TYPE_UNSIGNED (TREE_TYPE (t2
)))
5113 int t1_sgn
= tree_int_cst_sgn (t1
);
5114 int t2_sgn
= tree_int_cst_sgn (t2
);
5116 if (t1_sgn
< t2_sgn
)
5118 else if (t1_sgn
> t2_sgn
)
5120 /* Otherwise, both are non-negative, so we compare them as
5121 unsigned just in case one of them would overflow a signed
5124 else if (!TYPE_UNSIGNED (TREE_TYPE (t1
)))
5125 return INT_CST_LT (t1
, t2
);
5127 return INT_CST_LT_UNSIGNED (t1
, t2
);
5130 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
5133 tree_int_cst_compare (const_tree t1
, const_tree t2
)
5135 if (tree_int_cst_lt (t1
, t2
))
5137 else if (tree_int_cst_lt (t2
, t1
))
5143 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
5144 the host. If POS is zero, the value can be represented in a single
5145 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
5146 be represented in a single unsigned HOST_WIDE_INT. */
5149 host_integerp (const_tree t
, int pos
)
5151 return (TREE_CODE (t
) == INTEGER_CST
5152 && ((TREE_INT_CST_HIGH (t
) == 0
5153 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) >= 0)
5154 || (! pos
&& TREE_INT_CST_HIGH (t
) == -1
5155 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0
5156 && (!TYPE_UNSIGNED (TREE_TYPE (t
))
5157 || (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
5158 && TYPE_IS_SIZETYPE (TREE_TYPE (t
)))))
5159 || (pos
&& TREE_INT_CST_HIGH (t
) == 0)));
5162 /* Return the HOST_WIDE_INT least significant bits of T if it is an
5163 INTEGER_CST and there is no overflow. POS is nonzero if the result must
5164 be non-negative. We must be able to satisfy the above conditions. */
5167 tree_low_cst (const_tree t
, int pos
)
5169 gcc_assert (host_integerp (t
, pos
));
5170 return TREE_INT_CST_LOW (t
);
5173 /* Return the most significant bit of the integer constant T. */
5176 tree_int_cst_msb (const_tree t
)
5180 unsigned HOST_WIDE_INT l
;
5182 /* Note that using TYPE_PRECISION here is wrong. We care about the
5183 actual bits, not the (arbitrary) range of the type. */
5184 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t
))) - 1;
5185 rshift_double (TREE_INT_CST_LOW (t
), TREE_INT_CST_HIGH (t
), prec
,
5186 2 * HOST_BITS_PER_WIDE_INT
, &l
, &h
, 0);
5187 return (l
& 1) == 1;
5190 /* Return an indication of the sign of the integer constant T.
5191 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
5192 Note that -1 will never be returned if T's type is unsigned. */
5195 tree_int_cst_sgn (const_tree t
)
5197 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
5199 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
5201 else if (TREE_INT_CST_HIGH (t
) < 0)
5207 /* Return the minimum number of bits needed to represent VALUE in a
5208 signed or unsigned type, UNSIGNEDP says which. */
5211 tree_int_cst_min_precision (tree value
, bool unsignedp
)
5215 /* If the value is negative, compute its negative minus 1. The latter
5216 adjustment is because the absolute value of the largest negative value
5217 is one larger than the largest positive value. This is equivalent to
5218 a bit-wise negation, so use that operation instead. */
5220 if (tree_int_cst_sgn (value
) < 0)
5221 value
= fold_build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
);
5223 /* Return the number of bits needed, taking into account the fact
5224 that we need one more bit for a signed than unsigned type. */
5226 if (integer_zerop (value
))
5229 log
= tree_floor_log2 (value
);
5231 return log
+ 1 + !unsignedp
;
5234 /* Compare two constructor-element-type constants. Return 1 if the lists
5235 are known to be equal; otherwise return 0. */
5238 simple_cst_list_equal (const_tree l1
, const_tree l2
)
5240 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
5242 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
5245 l1
= TREE_CHAIN (l1
);
5246 l2
= TREE_CHAIN (l2
);
5252 /* Return truthvalue of whether T1 is the same tree structure as T2.
5253 Return 1 if they are the same.
5254 Return 0 if they are understandably different.
5255 Return -1 if either contains tree structure not understood by
5259 simple_cst_equal (const_tree t1
, const_tree t2
)
5261 enum tree_code code1
, code2
;
5267 if (t1
== 0 || t2
== 0)
5270 code1
= TREE_CODE (t1
);
5271 code2
= TREE_CODE (t2
);
5273 if (CONVERT_EXPR_CODE_P (code1
) || code1
== NON_LVALUE_EXPR
)
5275 if (CONVERT_EXPR_CODE_P (code2
)
5276 || code2
== NON_LVALUE_EXPR
)
5277 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5279 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
5282 else if (CONVERT_EXPR_CODE_P (code2
)
5283 || code2
== NON_LVALUE_EXPR
)
5284 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
5292 return (TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
5293 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
));
5296 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
5299 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
5302 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
5303 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
5304 TREE_STRING_LENGTH (t1
)));
5308 unsigned HOST_WIDE_INT idx
;
5309 VEC(constructor_elt
, gc
) *v1
= CONSTRUCTOR_ELTS (t1
);
5310 VEC(constructor_elt
, gc
) *v2
= CONSTRUCTOR_ELTS (t2
);
5312 if (VEC_length (constructor_elt
, v1
) != VEC_length (constructor_elt
, v2
))
5315 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
5316 /* ??? Should we handle also fields here? */
5317 if (!simple_cst_equal (VEC_index (constructor_elt
, v1
, idx
)->value
,
5318 VEC_index (constructor_elt
, v2
, idx
)->value
))
5324 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5327 cmp
= simple_cst_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
));
5330 if (call_expr_nargs (t1
) != call_expr_nargs (t2
))
5333 const_tree arg1
, arg2
;
5334 const_call_expr_arg_iterator iter1
, iter2
;
5335 for (arg1
= first_const_call_expr_arg (t1
, &iter1
),
5336 arg2
= first_const_call_expr_arg (t2
, &iter2
);
5338 arg1
= next_const_call_expr_arg (&iter1
),
5339 arg2
= next_const_call_expr_arg (&iter2
))
5341 cmp
= simple_cst_equal (arg1
, arg2
);
5345 return arg1
== arg2
;
5349 /* Special case: if either target is an unallocated VAR_DECL,
5350 it means that it's going to be unified with whatever the
5351 TARGET_EXPR is really supposed to initialize, so treat it
5352 as being equivalent to anything. */
5353 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
5354 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
5355 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
5356 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
5357 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
5358 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
5361 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5366 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
5368 case WITH_CLEANUP_EXPR
:
5369 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5373 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
5376 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
5377 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5391 /* This general rule works for most tree codes. All exceptions should be
5392 handled above. If this is a language-specific tree code, we can't
5393 trust what might be in the operand, so say we don't know
5395 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
5398 switch (TREE_CODE_CLASS (code1
))
5402 case tcc_comparison
:
5403 case tcc_expression
:
5407 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
5409 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
5421 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
5422 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
5423 than U, respectively. */
5426 compare_tree_int (const_tree t
, unsigned HOST_WIDE_INT u
)
5428 if (tree_int_cst_sgn (t
) < 0)
5430 else if (TREE_INT_CST_HIGH (t
) != 0)
5432 else if (TREE_INT_CST_LOW (t
) == u
)
5434 else if (TREE_INT_CST_LOW (t
) < u
)
5440 /* Return true if CODE represents an associative tree code. Otherwise
5443 associative_tree_code (enum tree_code code
)
5462 /* Return true if CODE represents a commutative tree code. Otherwise
5465 commutative_tree_code (enum tree_code code
)
5478 case UNORDERED_EXPR
:
5482 case TRUTH_AND_EXPR
:
5483 case TRUTH_XOR_EXPR
:
5493 /* Generate a hash value for an expression. This can be used iteratively
5494 by passing a previous result as the VAL argument.
5496 This function is intended to produce the same hash for expressions which
5497 would compare equal using operand_equal_p. */
5500 iterative_hash_expr (const_tree t
, hashval_t val
)
5503 enum tree_code code
;
5507 return iterative_hash_hashval_t (0, val
);
5509 code
= TREE_CODE (t
);
5513 /* Alas, constants aren't shared, so we can't rely on pointer
5516 val
= iterative_hash_host_wide_int (TREE_INT_CST_LOW (t
), val
);
5517 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t
), val
);
5520 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
5522 return iterative_hash_hashval_t (val2
, val
);
5526 unsigned int val2
= fixed_hash (TREE_FIXED_CST_PTR (t
));
5528 return iterative_hash_hashval_t (val2
, val
);
5531 return iterative_hash (TREE_STRING_POINTER (t
),
5532 TREE_STRING_LENGTH (t
), val
);
5534 val
= iterative_hash_expr (TREE_REALPART (t
), val
);
5535 return iterative_hash_expr (TREE_IMAGPART (t
), val
);
5537 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t
), val
);
5540 /* we can just compare by pointer. */
5541 return iterative_hash_host_wide_int (SSA_NAME_VERSION (t
), val
);
5544 /* A list of expressions, for a CALL_EXPR or as the elements of a
5546 for (; t
; t
= TREE_CHAIN (t
))
5547 val
= iterative_hash_expr (TREE_VALUE (t
), val
);
5551 unsigned HOST_WIDE_INT idx
;
5553 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
5555 val
= iterative_hash_expr (field
, val
);
5556 val
= iterative_hash_expr (value
, val
);
5561 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
5562 Otherwise nodes that compare equal according to operand_equal_p might
5563 get different hash codes. However, don't do this for machine specific
5564 or front end builtins, since the function code is overloaded in those
5566 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
5567 && built_in_decls
[DECL_FUNCTION_CODE (t
)])
5569 t
= built_in_decls
[DECL_FUNCTION_CODE (t
)];
5570 code
= TREE_CODE (t
);
5574 tclass
= TREE_CODE_CLASS (code
);
5576 if (tclass
== tcc_declaration
)
5578 /* DECL's have a unique ID */
5579 val
= iterative_hash_host_wide_int (DECL_UID (t
), val
);
5583 gcc_assert (IS_EXPR_CODE_CLASS (tclass
));
5585 val
= iterative_hash_object (code
, val
);
5587 /* Don't hash the type, that can lead to having nodes which
5588 compare equal according to operand_equal_p, but which
5589 have different hash codes. */
5590 if (CONVERT_EXPR_CODE_P (code
)
5591 || code
== NON_LVALUE_EXPR
)
5593 /* Make sure to include signness in the hash computation. */
5594 val
+= TYPE_UNSIGNED (TREE_TYPE (t
));
5595 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
5598 else if (commutative_tree_code (code
))
5600 /* It's a commutative expression. We want to hash it the same
5601 however it appears. We do this by first hashing both operands
5602 and then rehashing based on the order of their independent
5604 hashval_t one
= iterative_hash_expr (TREE_OPERAND (t
, 0), 0);
5605 hashval_t two
= iterative_hash_expr (TREE_OPERAND (t
, 1), 0);
5609 t
= one
, one
= two
, two
= t
;
5611 val
= iterative_hash_hashval_t (one
, val
);
5612 val
= iterative_hash_hashval_t (two
, val
);
5615 for (i
= TREE_OPERAND_LENGTH (t
) - 1; i
>= 0; --i
)
5616 val
= iterative_hash_expr (TREE_OPERAND (t
, i
), val
);
5623 /* Generate a hash value for a pair of expressions. This can be used
5624 iteratively by passing a previous result as the VAL argument.
5626 The same hash value is always returned for a given pair of expressions,
5627 regardless of the order in which they are presented. This is useful in
5628 hashing the operands of commutative functions. */
5631 iterative_hash_exprs_commutative (const_tree t1
,
5632 const_tree t2
, hashval_t val
)
5634 hashval_t one
= iterative_hash_expr (t1
, 0);
5635 hashval_t two
= iterative_hash_expr (t2
, 0);
5639 t
= one
, one
= two
, two
= t
;
5640 val
= iterative_hash_hashval_t (one
, val
);
5641 val
= iterative_hash_hashval_t (two
, val
);
5646 /* Constructors for pointer, array and function types.
5647 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
5648 constructed by language-dependent code, not here.) */
5650 /* Construct, lay out and return the type of pointers to TO_TYPE with
5651 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
5652 reference all of memory. If such a type has already been
5653 constructed, reuse it. */
5656 build_pointer_type_for_mode (tree to_type
, enum machine_mode mode
,
5661 if (to_type
== error_mark_node
)
5662 return error_mark_node
;
5664 /* If the pointed-to type has the may_alias attribute set, force
5665 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
5666 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
5667 can_alias_all
= true;
5669 /* In some cases, languages will have things that aren't a POINTER_TYPE
5670 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
5671 In that case, return that type without regard to the rest of our
5674 ??? This is a kludge, but consistent with the way this function has
5675 always operated and there doesn't seem to be a good way to avoid this
5677 if (TYPE_POINTER_TO (to_type
) != 0
5678 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
5679 return TYPE_POINTER_TO (to_type
);
5681 /* First, if we already have a type for pointers to TO_TYPE and it's
5682 the proper mode, use it. */
5683 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
5684 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
5687 t
= make_node (POINTER_TYPE
);
5689 TREE_TYPE (t
) = to_type
;
5690 SET_TYPE_MODE (t
, mode
);
5691 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
5692 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
5693 TYPE_POINTER_TO (to_type
) = t
;
5695 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
5696 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5697 else if (TYPE_CANONICAL (to_type
) != to_type
)
5699 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
5700 mode
, can_alias_all
);
5702 /* Lay out the type. This function has many callers that are concerned
5703 with expression-construction, and this simplifies them all. */
5709 /* By default build pointers in ptr_mode. */
5712 build_pointer_type (tree to_type
)
5714 return build_pointer_type_for_mode (to_type
, ptr_mode
, false);
5717 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
5720 build_reference_type_for_mode (tree to_type
, enum machine_mode mode
,
5725 if (to_type
== error_mark_node
)
5726 return error_mark_node
;
5728 /* If the pointed-to type has the may_alias attribute set, force
5729 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
5730 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
5731 can_alias_all
= true;
5733 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
5734 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
5735 In that case, return that type without regard to the rest of our
5738 ??? This is a kludge, but consistent with the way this function has
5739 always operated and there doesn't seem to be a good way to avoid this
5741 if (TYPE_REFERENCE_TO (to_type
) != 0
5742 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
5743 return TYPE_REFERENCE_TO (to_type
);
5745 /* First, if we already have a type for pointers to TO_TYPE and it's
5746 the proper mode, use it. */
5747 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
5748 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
5751 t
= make_node (REFERENCE_TYPE
);
5753 TREE_TYPE (t
) = to_type
;
5754 SET_TYPE_MODE (t
, mode
);
5755 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
5756 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
5757 TYPE_REFERENCE_TO (to_type
) = t
;
5759 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
5760 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5761 else if (TYPE_CANONICAL (to_type
) != to_type
)
5763 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
5764 mode
, can_alias_all
);
5772 /* Build the node for the type of references-to-TO_TYPE by default
5776 build_reference_type (tree to_type
)
5778 return build_reference_type_for_mode (to_type
, ptr_mode
, false);
5781 /* Build a type that is compatible with t but has no cv quals anywhere
5784 const char *const *const * -> char ***. */
5787 build_type_no_quals (tree t
)
5789 switch (TREE_CODE (t
))
5792 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
5794 TYPE_REF_CAN_ALIAS_ALL (t
));
5795 case REFERENCE_TYPE
:
5797 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
5799 TYPE_REF_CAN_ALIAS_ALL (t
));
5801 return TYPE_MAIN_VARIANT (t
);
5805 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
5806 MAXVAL should be the maximum value in the domain
5807 (one less than the length of the array).
5809 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
5810 We don't enforce this limit, that is up to caller (e.g. language front end).
5811 The limit exists because the result is a signed type and we don't handle
5812 sizes that use more than one HOST_WIDE_INT. */
5815 build_index_type (tree maxval
)
5817 tree itype
= make_node (INTEGER_TYPE
);
5819 TREE_TYPE (itype
) = sizetype
;
5820 TYPE_PRECISION (itype
) = TYPE_PRECISION (sizetype
);
5821 TYPE_MIN_VALUE (itype
) = size_zero_node
;
5822 TYPE_MAX_VALUE (itype
) = fold_convert (sizetype
, maxval
);
5823 SET_TYPE_MODE (itype
, TYPE_MODE (sizetype
));
5824 TYPE_SIZE (itype
) = TYPE_SIZE (sizetype
);
5825 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (sizetype
);
5826 TYPE_ALIGN (itype
) = TYPE_ALIGN (sizetype
);
5827 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (sizetype
);
5829 if (host_integerp (maxval
, 1))
5830 return type_hash_canon (tree_low_cst (maxval
, 1), itype
);
5833 /* Since we cannot hash this type, we need to compare it using
5834 structural equality checks. */
5835 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
5840 /* Builds a signed or unsigned integer type of precision PRECISION.
5841 Used for C bitfields whose precision does not match that of
5842 built-in target types. */
5844 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
5847 tree itype
= make_node (INTEGER_TYPE
);
5849 TYPE_PRECISION (itype
) = precision
;
5852 fixup_unsigned_type (itype
);
5854 fixup_signed_type (itype
);
5856 if (host_integerp (TYPE_MAX_VALUE (itype
), 1))
5857 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype
), 1), itype
);
5862 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
5863 ENUMERAL_TYPE or BOOLEAN_TYPE), with low bound LOWVAL and
5864 high bound HIGHVAL. If TYPE is NULL, sizetype is used. */
5867 build_range_type (tree type
, tree lowval
, tree highval
)
5869 tree itype
= make_node (INTEGER_TYPE
);
5871 TREE_TYPE (itype
) = type
;
5872 if (type
== NULL_TREE
)
5875 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
5876 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
5878 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
5879 SET_TYPE_MODE (itype
, TYPE_MODE (type
));
5880 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
5881 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
5882 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
5883 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
5885 if (host_integerp (lowval
, 0) && highval
!= 0 && host_integerp (highval
, 0))
5886 return type_hash_canon (tree_low_cst (highval
, 0)
5887 - tree_low_cst (lowval
, 0),
5893 /* Return true if the debug information for TYPE, a subtype, should be emitted
5894 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
5895 high bound, respectively. Sometimes doing so unnecessarily obfuscates the
5896 debug info and doesn't reflect the source code. */
5899 subrange_type_for_debug_p (const_tree type
, tree
*lowval
, tree
*highval
)
5901 tree base_type
= TREE_TYPE (type
), low
, high
;
5903 /* Subrange types have a base type which is an integral type. */
5904 if (!INTEGRAL_TYPE_P (base_type
))
5907 /* Get the real bounds of the subtype. */
5908 if (lang_hooks
.types
.get_subrange_bounds
)
5909 lang_hooks
.types
.get_subrange_bounds (type
, &low
, &high
);
5912 low
= TYPE_MIN_VALUE (type
);
5913 high
= TYPE_MAX_VALUE (type
);
5916 /* If the type and its base type have the same representation and the same
5917 name, then the type is not a subrange but a copy of the base type. */
5918 if ((TREE_CODE (base_type
) == INTEGER_TYPE
5919 || TREE_CODE (base_type
) == BOOLEAN_TYPE
)
5920 && int_size_in_bytes (type
) == int_size_in_bytes (base_type
)
5921 && tree_int_cst_equal (low
, TYPE_MIN_VALUE (base_type
))
5922 && tree_int_cst_equal (high
, TYPE_MAX_VALUE (base_type
)))
5924 tree type_name
= TYPE_NAME (type
);
5925 tree base_type_name
= TYPE_NAME (base_type
);
5927 if (type_name
&& TREE_CODE (type_name
) == TYPE_DECL
)
5928 type_name
= DECL_NAME (type_name
);
5930 if (base_type_name
&& TREE_CODE (base_type_name
) == TYPE_DECL
)
5931 base_type_name
= DECL_NAME (base_type_name
);
5933 if (type_name
== base_type_name
)
5944 /* Just like build_index_type, but takes lowval and highval instead
5945 of just highval (maxval). */
5948 build_index_2_type (tree lowval
, tree highval
)
5950 return build_range_type (sizetype
, lowval
, highval
);
5953 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
5954 and number of elements specified by the range of values of INDEX_TYPE.
5955 If such a type has already been constructed, reuse it. */
5958 build_array_type (tree elt_type
, tree index_type
)
5961 hashval_t hashcode
= 0;
5963 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
5965 error ("arrays of functions are not meaningful");
5966 elt_type
= integer_type_node
;
5969 t
= make_node (ARRAY_TYPE
);
5970 TREE_TYPE (t
) = elt_type
;
5971 TYPE_DOMAIN (t
) = index_type
;
5973 if (index_type
== 0)
5976 hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), hashcode
);
5977 t
= type_hash_canon (hashcode
, t
);
5981 if (TYPE_CANONICAL (t
) == t
)
5983 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
))
5984 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5985 else if (TYPE_CANONICAL (elt_type
) != elt_type
)
5987 = build_array_type (TYPE_CANONICAL (elt_type
), index_type
);
5993 hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), hashcode
);
5994 hashcode
= iterative_hash_object (TYPE_HASH (index_type
), hashcode
);
5995 t
= type_hash_canon (hashcode
, t
);
5997 if (!COMPLETE_TYPE_P (t
))
6000 if (TYPE_CANONICAL (t
) == t
)
6002 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
6003 || TYPE_STRUCTURAL_EQUALITY_P (index_type
))
6004 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6005 else if (TYPE_CANONICAL (elt_type
) != elt_type
6006 || TYPE_CANONICAL (index_type
) != index_type
)
6008 = build_array_type (TYPE_CANONICAL (elt_type
),
6009 TYPE_CANONICAL (index_type
));
6015 /* Recursively examines the array elements of TYPE, until a non-array
6016 element type is found. */
6019 strip_array_types (tree type
)
6021 while (TREE_CODE (type
) == ARRAY_TYPE
)
6022 type
= TREE_TYPE (type
);
6027 /* Computes the canonical argument types from the argument type list
6030 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
6031 on entry to this function, or if any of the ARGTYPES are
6034 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
6035 true on entry to this function, or if any of the ARGTYPES are
6038 Returns a canonical argument list, which may be ARGTYPES when the
6039 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
6040 true) or would not differ from ARGTYPES. */
6043 maybe_canonicalize_argtypes(tree argtypes
,
6044 bool *any_structural_p
,
6045 bool *any_noncanonical_p
)
6048 bool any_noncanonical_argtypes_p
= false;
6050 for (arg
= argtypes
; arg
&& !(*any_structural_p
); arg
= TREE_CHAIN (arg
))
6052 if (!TREE_VALUE (arg
) || TREE_VALUE (arg
) == error_mark_node
)
6053 /* Fail gracefully by stating that the type is structural. */
6054 *any_structural_p
= true;
6055 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg
)))
6056 *any_structural_p
= true;
6057 else if (TYPE_CANONICAL (TREE_VALUE (arg
)) != TREE_VALUE (arg
)
6058 || TREE_PURPOSE (arg
))
6059 /* If the argument has a default argument, we consider it
6060 non-canonical even though the type itself is canonical.
6061 That way, different variants of function and method types
6062 with default arguments will all point to the variant with
6063 no defaults as their canonical type. */
6064 any_noncanonical_argtypes_p
= true;
6067 if (*any_structural_p
)
6070 if (any_noncanonical_argtypes_p
)
6072 /* Build the canonical list of argument types. */
6073 tree canon_argtypes
= NULL_TREE
;
6074 bool is_void
= false;
6076 for (arg
= argtypes
; arg
; arg
= TREE_CHAIN (arg
))
6078 if (arg
== void_list_node
)
6081 canon_argtypes
= tree_cons (NULL_TREE
,
6082 TYPE_CANONICAL (TREE_VALUE (arg
)),
6086 canon_argtypes
= nreverse (canon_argtypes
);
6088 canon_argtypes
= chainon (canon_argtypes
, void_list_node
);
6090 /* There is a non-canonical type. */
6091 *any_noncanonical_p
= true;
6092 return canon_argtypes
;
6095 /* The canonical argument types are the same as ARGTYPES. */
6099 /* Construct, lay out and return
6100 the type of functions returning type VALUE_TYPE
6101 given arguments of types ARG_TYPES.
6102 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
6103 are data type nodes for the arguments of the function.
6104 If such a type has already been constructed, reuse it. */
6107 build_function_type (tree value_type
, tree arg_types
)
6110 hashval_t hashcode
= 0;
6111 bool any_structural_p
, any_noncanonical_p
;
6112 tree canon_argtypes
;
6114 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
6116 error ("function return type cannot be function");
6117 value_type
= integer_type_node
;
6120 /* Make a node of the sort we want. */
6121 t
= make_node (FUNCTION_TYPE
);
6122 TREE_TYPE (t
) = value_type
;
6123 TYPE_ARG_TYPES (t
) = arg_types
;
6125 /* If we already have such a type, use the old one. */
6126 hashcode
= iterative_hash_object (TYPE_HASH (value_type
), hashcode
);
6127 hashcode
= type_hash_list (arg_types
, hashcode
);
6128 t
= type_hash_canon (hashcode
, t
);
6130 /* Set up the canonical type. */
6131 any_structural_p
= TYPE_STRUCTURAL_EQUALITY_P (value_type
);
6132 any_noncanonical_p
= TYPE_CANONICAL (value_type
) != value_type
;
6133 canon_argtypes
= maybe_canonicalize_argtypes (arg_types
,
6135 &any_noncanonical_p
);
6136 if (any_structural_p
)
6137 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6138 else if (any_noncanonical_p
)
6139 TYPE_CANONICAL (t
) = build_function_type (TYPE_CANONICAL (value_type
),
6142 if (!COMPLETE_TYPE_P (t
))
6147 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP. */
6150 build_function_type_skip_args (tree orig_type
, bitmap args_to_skip
)
6152 tree new_type
= NULL
;
6153 tree args
, new_args
= NULL
, t
;
6157 for (args
= TYPE_ARG_TYPES (orig_type
); args
&& args
!= void_list_node
;
6158 args
= TREE_CHAIN (args
), i
++)
6159 if (!bitmap_bit_p (args_to_skip
, i
))
6160 new_args
= tree_cons (NULL_TREE
, TREE_VALUE (args
), new_args
);
6162 new_reversed
= nreverse (new_args
);
6166 TREE_CHAIN (new_args
) = void_list_node
;
6168 new_reversed
= void_list_node
;
6170 gcc_assert (new_reversed
);
6172 /* Use copy_node to preserve as much as possible from original type
6173 (debug info, attribute lists etc.)
6174 Exception is METHOD_TYPEs must have THIS argument.
6175 When we are asked to remove it, we need to build new FUNCTION_TYPE
6177 if (TREE_CODE (orig_type
) != METHOD_TYPE
6178 || !bitmap_bit_p (args_to_skip
, 0))
6180 new_type
= copy_node (orig_type
);
6181 TYPE_ARG_TYPES (new_type
) = new_reversed
;
6186 = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type
),
6188 TYPE_CONTEXT (new_type
) = TYPE_CONTEXT (orig_type
);
6191 /* This is a new type, not a copy of an old type. Need to reassociate
6192 variants. We can handle everything except the main variant lazily. */
6193 t
= TYPE_MAIN_VARIANT (orig_type
);
6196 TYPE_MAIN_VARIANT (new_type
) = t
;
6197 TYPE_NEXT_VARIANT (new_type
) = TYPE_NEXT_VARIANT (t
);
6198 TYPE_NEXT_VARIANT (t
) = new_type
;
6202 TYPE_MAIN_VARIANT (new_type
) = new_type
;
6203 TYPE_NEXT_VARIANT (new_type
) = NULL
;
6208 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP.
6210 Arguments from DECL_ARGUMENTS list can't be removed now, since they are
6211 linked by TREE_CHAIN directly. It is caller responsibility to eliminate
6212 them when they are being duplicated (i.e. copy_arguments_for_versioning). */
6215 build_function_decl_skip_args (tree orig_decl
, bitmap args_to_skip
)
6217 tree new_decl
= copy_node (orig_decl
);
6220 new_type
= TREE_TYPE (orig_decl
);
6221 if (prototype_p (new_type
))
6222 new_type
= build_function_type_skip_args (new_type
, args_to_skip
);
6223 TREE_TYPE (new_decl
) = new_type
;
6225 /* For declarations setting DECL_VINDEX (i.e. methods)
6226 we expect first argument to be THIS pointer. */
6227 if (bitmap_bit_p (args_to_skip
, 0))
6228 DECL_VINDEX (new_decl
) = NULL_TREE
;
6232 /* Build a function type. The RETURN_TYPE is the type returned by the
6233 function. If VAARGS is set, no void_type_node is appended to the
6234 the list. ARGP muse be alway be terminated be a NULL_TREE. */
6237 build_function_type_list_1 (bool vaargs
, tree return_type
, va_list argp
)
6241 t
= va_arg (argp
, tree
);
6242 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (argp
, tree
))
6243 args
= tree_cons (NULL_TREE
, t
, args
);
6248 if (args
!= NULL_TREE
)
6249 args
= nreverse (args
);
6250 gcc_assert (args
!= NULL_TREE
&& last
!= void_list_node
);
6252 else if (args
== NULL_TREE
)
6253 args
= void_list_node
;
6257 args
= nreverse (args
);
6258 TREE_CHAIN (last
) = void_list_node
;
6260 args
= build_function_type (return_type
, args
);
6265 /* Build a function type. The RETURN_TYPE is the type returned by the
6266 function. If additional arguments are provided, they are
6267 additional argument types. The list of argument types must always
6268 be terminated by NULL_TREE. */
6271 build_function_type_list (tree return_type
, ...)
6276 va_start (p
, return_type
);
6277 args
= build_function_type_list_1 (false, return_type
, p
);
6282 /* Build a variable argument function type. The RETURN_TYPE is the
6283 type returned by the function. If additional arguments are provided,
6284 they are additional argument types. The list of argument types must
6285 always be terminated by NULL_TREE. */
6288 build_varargs_function_type_list (tree return_type
, ...)
6293 va_start (p
, return_type
);
6294 args
= build_function_type_list_1 (true, return_type
, p
);
6300 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
6301 and ARGTYPES (a TREE_LIST) are the return type and arguments types
6302 for the method. An implicit additional parameter (of type
6303 pointer-to-BASETYPE) is added to the ARGTYPES. */
6306 build_method_type_directly (tree basetype
,
6313 bool any_structural_p
, any_noncanonical_p
;
6314 tree canon_argtypes
;
6316 /* Make a node of the sort we want. */
6317 t
= make_node (METHOD_TYPE
);
6319 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
6320 TREE_TYPE (t
) = rettype
;
6321 ptype
= build_pointer_type (basetype
);
6323 /* The actual arglist for this function includes a "hidden" argument
6324 which is "this". Put it into the list of argument types. */
6325 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
6326 TYPE_ARG_TYPES (t
) = argtypes
;
6328 /* If we already have such a type, use the old one. */
6329 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
6330 hashcode
= iterative_hash_object (TYPE_HASH (rettype
), hashcode
);
6331 hashcode
= type_hash_list (argtypes
, hashcode
);
6332 t
= type_hash_canon (hashcode
, t
);
6334 /* Set up the canonical type. */
6336 = (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
6337 || TYPE_STRUCTURAL_EQUALITY_P (rettype
));
6339 = (TYPE_CANONICAL (basetype
) != basetype
6340 || TYPE_CANONICAL (rettype
) != rettype
);
6341 canon_argtypes
= maybe_canonicalize_argtypes (TREE_CHAIN (argtypes
),
6343 &any_noncanonical_p
);
6344 if (any_structural_p
)
6345 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6346 else if (any_noncanonical_p
)
6348 = build_method_type_directly (TYPE_CANONICAL (basetype
),
6349 TYPE_CANONICAL (rettype
),
6351 if (!COMPLETE_TYPE_P (t
))
6357 /* Construct, lay out and return the type of methods belonging to class
6358 BASETYPE and whose arguments and values are described by TYPE.
6359 If that type exists already, reuse it.
6360 TYPE must be a FUNCTION_TYPE node. */
6363 build_method_type (tree basetype
, tree type
)
6365 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
6367 return build_method_type_directly (basetype
,
6369 TYPE_ARG_TYPES (type
));
6372 /* Construct, lay out and return the type of offsets to a value
6373 of type TYPE, within an object of type BASETYPE.
6374 If a suitable offset type exists already, reuse it. */
6377 build_offset_type (tree basetype
, tree type
)
6380 hashval_t hashcode
= 0;
6382 /* Make a node of the sort we want. */
6383 t
= make_node (OFFSET_TYPE
);
6385 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
6386 TREE_TYPE (t
) = type
;
6388 /* If we already have such a type, use the old one. */
6389 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
6390 hashcode
= iterative_hash_object (TYPE_HASH (type
), hashcode
);
6391 t
= type_hash_canon (hashcode
, t
);
6393 if (!COMPLETE_TYPE_P (t
))
6396 if (TYPE_CANONICAL (t
) == t
)
6398 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
6399 || TYPE_STRUCTURAL_EQUALITY_P (type
))
6400 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6401 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)) != basetype
6402 || TYPE_CANONICAL (type
) != type
)
6404 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)),
6405 TYPE_CANONICAL (type
));
6411 /* Create a complex type whose components are COMPONENT_TYPE. */
6414 build_complex_type (tree component_type
)
6419 gcc_assert (INTEGRAL_TYPE_P (component_type
)
6420 || SCALAR_FLOAT_TYPE_P (component_type
)
6421 || FIXED_POINT_TYPE_P (component_type
));
6423 /* Make a node of the sort we want. */
6424 t
= make_node (COMPLEX_TYPE
);
6426 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
6428 /* If we already have such a type, use the old one. */
6429 hashcode
= iterative_hash_object (TYPE_HASH (component_type
), 0);
6430 t
= type_hash_canon (hashcode
, t
);
6432 if (!COMPLETE_TYPE_P (t
))
6435 if (TYPE_CANONICAL (t
) == t
)
6437 if (TYPE_STRUCTURAL_EQUALITY_P (component_type
))
6438 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6439 else if (TYPE_CANONICAL (component_type
) != component_type
)
6441 = build_complex_type (TYPE_CANONICAL (component_type
));
6444 /* We need to create a name, since complex is a fundamental type. */
6445 if (! TYPE_NAME (t
))
6448 if (component_type
== char_type_node
)
6449 name
= "complex char";
6450 else if (component_type
== signed_char_type_node
)
6451 name
= "complex signed char";
6452 else if (component_type
== unsigned_char_type_node
)
6453 name
= "complex unsigned char";
6454 else if (component_type
== short_integer_type_node
)
6455 name
= "complex short int";
6456 else if (component_type
== short_unsigned_type_node
)
6457 name
= "complex short unsigned int";
6458 else if (component_type
== integer_type_node
)
6459 name
= "complex int";
6460 else if (component_type
== unsigned_type_node
)
6461 name
= "complex unsigned int";
6462 else if (component_type
== long_integer_type_node
)
6463 name
= "complex long int";
6464 else if (component_type
== long_unsigned_type_node
)
6465 name
= "complex long unsigned int";
6466 else if (component_type
== long_long_integer_type_node
)
6467 name
= "complex long long int";
6468 else if (component_type
== long_long_unsigned_type_node
)
6469 name
= "complex long long unsigned int";
6474 TYPE_NAME (t
) = build_decl (UNKNOWN_LOCATION
, TYPE_DECL
,
6475 get_identifier (name
), t
);
6478 return build_qualified_type (t
, TYPE_QUALS (component_type
));
6481 /* If TYPE is a real or complex floating-point type and the target
6482 does not directly support arithmetic on TYPE then return the wider
6483 type to be used for arithmetic on TYPE. Otherwise, return
6487 excess_precision_type (tree type
)
6489 if (flag_excess_precision
!= EXCESS_PRECISION_FAST
)
6491 int flt_eval_method
= TARGET_FLT_EVAL_METHOD
;
6492 switch (TREE_CODE (type
))
6495 switch (flt_eval_method
)
6498 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
))
6499 return double_type_node
;
6502 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
)
6503 || TYPE_MODE (type
) == TYPE_MODE (double_type_node
))
6504 return long_double_type_node
;
6511 if (TREE_CODE (TREE_TYPE (type
)) != REAL_TYPE
)
6513 switch (flt_eval_method
)
6516 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
))
6517 return complex_double_type_node
;
6520 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
)
6521 || (TYPE_MODE (TREE_TYPE (type
))
6522 == TYPE_MODE (double_type_node
)))
6523 return complex_long_double_type_node
;
6536 /* Return OP, stripped of any conversions to wider types as much as is safe.
6537 Converting the value back to OP's type makes a value equivalent to OP.
6539 If FOR_TYPE is nonzero, we return a value which, if converted to
6540 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
6542 OP must have integer, real or enumeral type. Pointers are not allowed!
6544 There are some cases where the obvious value we could return
6545 would regenerate to OP if converted to OP's type,
6546 but would not extend like OP to wider types.
6547 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
6548 For example, if OP is (unsigned short)(signed char)-1,
6549 we avoid returning (signed char)-1 if FOR_TYPE is int,
6550 even though extending that to an unsigned short would regenerate OP,
6551 since the result of extending (signed char)-1 to (int)
6552 is different from (int) OP. */
6555 get_unwidened (tree op
, tree for_type
)
6557 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
6558 tree type
= TREE_TYPE (op
);
6560 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
6562 = (for_type
!= 0 && for_type
!= type
6563 && final_prec
> TYPE_PRECISION (type
)
6564 && TYPE_UNSIGNED (type
));
6567 while (CONVERT_EXPR_P (op
))
6571 /* TYPE_PRECISION on vector types has different meaning
6572 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
6573 so avoid them here. */
6574 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
6577 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
6578 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
6580 /* Truncations are many-one so cannot be removed.
6581 Unless we are later going to truncate down even farther. */
6583 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
6586 /* See what's inside this conversion. If we decide to strip it,
6588 op
= TREE_OPERAND (op
, 0);
6590 /* If we have not stripped any zero-extensions (uns is 0),
6591 we can strip any kind of extension.
6592 If we have previously stripped a zero-extension,
6593 only zero-extensions can safely be stripped.
6594 Any extension can be stripped if the bits it would produce
6595 are all going to be discarded later by truncating to FOR_TYPE. */
6599 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
6601 /* TYPE_UNSIGNED says whether this is a zero-extension.
6602 Let's avoid computing it if it does not affect WIN
6603 and if UNS will not be needed again. */
6605 || CONVERT_EXPR_P (op
))
6606 && TYPE_UNSIGNED (TREE_TYPE (op
)))
6617 /* Return OP or a simpler expression for a narrower value
6618 which can be sign-extended or zero-extended to give back OP.
6619 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
6620 or 0 if the value should be sign-extended. */
6623 get_narrower (tree op
, int *unsignedp_ptr
)
6628 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
6630 while (TREE_CODE (op
) == NOP_EXPR
)
6633 = (TYPE_PRECISION (TREE_TYPE (op
))
6634 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
6636 /* Truncations are many-one so cannot be removed. */
6640 /* See what's inside this conversion. If we decide to strip it,
6645 op
= TREE_OPERAND (op
, 0);
6646 /* An extension: the outermost one can be stripped,
6647 but remember whether it is zero or sign extension. */
6649 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
6650 /* Otherwise, if a sign extension has been stripped,
6651 only sign extensions can now be stripped;
6652 if a zero extension has been stripped, only zero-extensions. */
6653 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
6657 else /* bitschange == 0 */
6659 /* A change in nominal type can always be stripped, but we must
6660 preserve the unsignedness. */
6662 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
6664 op
= TREE_OPERAND (op
, 0);
6665 /* Keep trying to narrow, but don't assign op to win if it
6666 would turn an integral type into something else. */
6667 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
6674 if (TREE_CODE (op
) == COMPONENT_REF
6675 /* Since type_for_size always gives an integer type. */
6676 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
6677 && TREE_CODE (TREE_TYPE (op
)) != FIXED_POINT_TYPE
6678 /* Ensure field is laid out already. */
6679 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
6680 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
6682 unsigned HOST_WIDE_INT innerprec
6683 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
6684 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
6685 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
6686 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
6688 /* We can get this structure field in a narrower type that fits it,
6689 but the resulting extension to its nominal type (a fullword type)
6690 must satisfy the same conditions as for other extensions.
6692 Do this only for fields that are aligned (not bit-fields),
6693 because when bit-field insns will be used there is no
6694 advantage in doing this. */
6696 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
6697 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
6698 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
6702 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
6703 win
= fold_convert (type
, op
);
6707 *unsignedp_ptr
= uns
;
6711 /* Nonzero if integer constant C has a value that is permissible
6712 for type TYPE (an INTEGER_TYPE). */
6715 int_fits_type_p (const_tree c
, const_tree type
)
6717 tree type_low_bound
, type_high_bound
;
6718 bool ok_for_low_bound
, ok_for_high_bound
, unsc
;
6721 dc
= tree_to_double_int (c
);
6722 unsc
= TYPE_UNSIGNED (TREE_TYPE (c
));
6724 if (TREE_CODE (TREE_TYPE (c
)) == INTEGER_TYPE
6725 && TYPE_IS_SIZETYPE (TREE_TYPE (c
))
6727 /* So c is an unsigned integer whose type is sizetype and type is not.
6728 sizetype'd integers are sign extended even though they are
6729 unsigned. If the integer value fits in the lower end word of c,
6730 and if the higher end word has all its bits set to 1, that
6731 means the higher end bits are set to 1 only for sign extension.
6732 So let's convert c into an equivalent zero extended unsigned
6734 dc
= double_int_zext (dc
, TYPE_PRECISION (TREE_TYPE (c
)));
6737 type_low_bound
= TYPE_MIN_VALUE (type
);
6738 type_high_bound
= TYPE_MAX_VALUE (type
);
6740 /* If at least one bound of the type is a constant integer, we can check
6741 ourselves and maybe make a decision. If no such decision is possible, but
6742 this type is a subtype, try checking against that. Otherwise, use
6743 fit_double_type, which checks against the precision.
6745 Compute the status for each possibly constant bound, and return if we see
6746 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
6747 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
6748 for "constant known to fit". */
6750 /* Check if c >= type_low_bound. */
6751 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
6753 dd
= tree_to_double_int (type_low_bound
);
6754 if (TREE_CODE (type
) == INTEGER_TYPE
6755 && TYPE_IS_SIZETYPE (type
)
6756 && TYPE_UNSIGNED (type
))
6757 dd
= double_int_zext (dd
, TYPE_PRECISION (type
));
6758 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_low_bound
)))
6760 int c_neg
= (!unsc
&& double_int_negative_p (dc
));
6761 int t_neg
= (unsc
&& double_int_negative_p (dd
));
6763 if (c_neg
&& !t_neg
)
6765 if ((c_neg
|| !t_neg
) && double_int_ucmp (dc
, dd
) < 0)
6768 else if (double_int_cmp (dc
, dd
, unsc
) < 0)
6770 ok_for_low_bound
= true;
6773 ok_for_low_bound
= false;
6775 /* Check if c <= type_high_bound. */
6776 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
6778 dd
= tree_to_double_int (type_high_bound
);
6779 if (TREE_CODE (type
) == INTEGER_TYPE
6780 && TYPE_IS_SIZETYPE (type
)
6781 && TYPE_UNSIGNED (type
))
6782 dd
= double_int_zext (dd
, TYPE_PRECISION (type
));
6783 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_high_bound
)))
6785 int c_neg
= (!unsc
&& double_int_negative_p (dc
));
6786 int t_neg
= (unsc
&& double_int_negative_p (dd
));
6788 if (t_neg
&& !c_neg
)
6790 if ((t_neg
|| !c_neg
) && double_int_ucmp (dc
, dd
) > 0)
6793 else if (double_int_cmp (dc
, dd
, unsc
) > 0)
6795 ok_for_high_bound
= true;
6798 ok_for_high_bound
= false;
6800 /* If the constant fits both bounds, the result is known. */
6801 if (ok_for_low_bound
&& ok_for_high_bound
)
6804 /* Perform some generic filtering which may allow making a decision
6805 even if the bounds are not constant. First, negative integers
6806 never fit in unsigned types, */
6807 if (TYPE_UNSIGNED (type
) && !unsc
&& double_int_negative_p (dc
))
6810 /* Second, narrower types always fit in wider ones. */
6811 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
6814 /* Third, unsigned integers with top bit set never fit signed types. */
6815 if (! TYPE_UNSIGNED (type
) && unsc
)
6817 int prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (c
))) - 1;
6818 if (prec
< HOST_BITS_PER_WIDE_INT
)
6820 if (((((unsigned HOST_WIDE_INT
) 1) << prec
) & dc
.low
) != 0)
6823 else if (((((unsigned HOST_WIDE_INT
) 1)
6824 << (prec
- HOST_BITS_PER_WIDE_INT
)) & dc
.high
) != 0)
6828 /* If we haven't been able to decide at this point, there nothing more we
6829 can check ourselves here. Look at the base type if we have one and it
6830 has the same precision. */
6831 if (TREE_CODE (type
) == INTEGER_TYPE
6832 && TREE_TYPE (type
) != 0
6833 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
6835 type
= TREE_TYPE (type
);
6839 /* Or to fit_double_type, if nothing else. */
6840 return !fit_double_type (dc
.low
, dc
.high
, &dc
.low
, &dc
.high
, type
);
6843 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
6844 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
6845 represented (assuming two's-complement arithmetic) within the bit
6846 precision of the type are returned instead. */
6849 get_type_static_bounds (const_tree type
, mpz_t min
, mpz_t max
)
6851 if (!POINTER_TYPE_P (type
) && TYPE_MIN_VALUE (type
)
6852 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
6853 mpz_set_double_int (min
, tree_to_double_int (TYPE_MIN_VALUE (type
)),
6854 TYPE_UNSIGNED (type
));
6857 if (TYPE_UNSIGNED (type
))
6858 mpz_set_ui (min
, 0);
6862 mn
= double_int_mask (TYPE_PRECISION (type
) - 1);
6863 mn
= double_int_sext (double_int_add (mn
, double_int_one
),
6864 TYPE_PRECISION (type
));
6865 mpz_set_double_int (min
, mn
, false);
6869 if (!POINTER_TYPE_P (type
) && TYPE_MAX_VALUE (type
)
6870 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
)
6871 mpz_set_double_int (max
, tree_to_double_int (TYPE_MAX_VALUE (type
)),
6872 TYPE_UNSIGNED (type
));
6875 if (TYPE_UNSIGNED (type
))
6876 mpz_set_double_int (max
, double_int_mask (TYPE_PRECISION (type
)),
6879 mpz_set_double_int (max
, double_int_mask (TYPE_PRECISION (type
) - 1),
6884 /* Return true if VAR is an automatic variable defined in function FN. */
6887 auto_var_in_fn_p (const_tree var
, const_tree fn
)
6889 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
6890 && (((TREE_CODE (var
) == VAR_DECL
|| TREE_CODE (var
) == PARM_DECL
)
6891 && ! TREE_STATIC (var
))
6892 || TREE_CODE (var
) == LABEL_DECL
6893 || TREE_CODE (var
) == RESULT_DECL
));
6896 /* Subprogram of following function. Called by walk_tree.
6898 Return *TP if it is an automatic variable or parameter of the
6899 function passed in as DATA. */
6902 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
6904 tree fn
= (tree
) data
;
6909 else if (DECL_P (*tp
)
6910 && auto_var_in_fn_p (*tp
, fn
))
6916 /* Returns true if T is, contains, or refers to a type with variable
6917 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
6918 arguments, but not the return type. If FN is nonzero, only return
6919 true if a modifier of the type or position of FN is a variable or
6920 parameter inside FN.
6922 This concept is more general than that of C99 'variably modified types':
6923 in C99, a struct type is never variably modified because a VLA may not
6924 appear as a structure member. However, in GNU C code like:
6926 struct S { int i[f()]; };
6928 is valid, and other languages may define similar constructs. */
6931 variably_modified_type_p (tree type
, tree fn
)
6935 /* Test if T is either variable (if FN is zero) or an expression containing
6936 a variable in FN. */
6937 #define RETURN_TRUE_IF_VAR(T) \
6938 do { tree _t = (T); \
6939 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
6940 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
6941 return true; } while (0)
6943 if (type
== error_mark_node
)
6946 /* If TYPE itself has variable size, it is variably modified. */
6947 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
6948 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
6950 switch (TREE_CODE (type
))
6953 case REFERENCE_TYPE
:
6955 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
6961 /* If TYPE is a function type, it is variably modified if the
6962 return type is variably modified. */
6963 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
6969 case FIXED_POINT_TYPE
:
6972 /* Scalar types are variably modified if their end points
6974 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
6975 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
6980 case QUAL_UNION_TYPE
:
6981 /* We can't see if any of the fields are variably-modified by the
6982 definition we normally use, since that would produce infinite
6983 recursion via pointers. */
6984 /* This is variably modified if some field's type is. */
6985 for (t
= TYPE_FIELDS (type
); t
; t
= TREE_CHAIN (t
))
6986 if (TREE_CODE (t
) == FIELD_DECL
)
6988 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
6989 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
6990 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
6992 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
6993 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
6998 /* Do not call ourselves to avoid infinite recursion. This is
6999 variably modified if the element type is. */
7000 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
7001 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
7008 /* The current language may have other cases to check, but in general,
7009 all other types are not variably modified. */
7010 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
7012 #undef RETURN_TRUE_IF_VAR
7015 /* Given a DECL or TYPE, return the scope in which it was declared, or
7016 NULL_TREE if there is no containing scope. */
7019 get_containing_scope (const_tree t
)
7021 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
7024 /* Return the innermost context enclosing DECL that is
7025 a FUNCTION_DECL, or zero if none. */
7028 decl_function_context (const_tree decl
)
7032 if (TREE_CODE (decl
) == ERROR_MARK
)
7035 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
7036 where we look up the function at runtime. Such functions always take
7037 a first argument of type 'pointer to real context'.
7039 C++ should really be fixed to use DECL_CONTEXT for the real context,
7040 and use something else for the "virtual context". */
7041 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
7044 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
7046 context
= DECL_CONTEXT (decl
);
7048 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
7050 if (TREE_CODE (context
) == BLOCK
)
7051 context
= BLOCK_SUPERCONTEXT (context
);
7053 context
= get_containing_scope (context
);
7059 /* Return the innermost context enclosing DECL that is
7060 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
7061 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
7064 decl_type_context (const_tree decl
)
7066 tree context
= DECL_CONTEXT (decl
);
7069 switch (TREE_CODE (context
))
7071 case NAMESPACE_DECL
:
7072 case TRANSLATION_UNIT_DECL
:
7077 case QUAL_UNION_TYPE
:
7082 context
= DECL_CONTEXT (context
);
7086 context
= BLOCK_SUPERCONTEXT (context
);
7096 /* CALL is a CALL_EXPR. Return the declaration for the function
7097 called, or NULL_TREE if the called function cannot be
7101 get_callee_fndecl (const_tree call
)
7105 if (call
== error_mark_node
)
7106 return error_mark_node
;
7108 /* It's invalid to call this function with anything but a
7110 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
7112 /* The first operand to the CALL is the address of the function
7114 addr
= CALL_EXPR_FN (call
);
7118 /* If this is a readonly function pointer, extract its initial value. */
7119 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
7120 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
7121 && DECL_INITIAL (addr
))
7122 addr
= DECL_INITIAL (addr
);
7124 /* If the address is just `&f' for some function `f', then we know
7125 that `f' is being called. */
7126 if (TREE_CODE (addr
) == ADDR_EXPR
7127 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
7128 return TREE_OPERAND (addr
, 0);
7130 /* We couldn't figure out what was being called. */
7134 /* Print debugging information about tree nodes generated during the compile,
7135 and any language-specific information. */
7138 dump_tree_statistics (void)
7140 #ifdef GATHER_STATISTICS
7142 int total_nodes
, total_bytes
;
7145 fprintf (stderr
, "\n??? tree nodes created\n\n");
7146 #ifdef GATHER_STATISTICS
7147 fprintf (stderr
, "Kind Nodes Bytes\n");
7148 fprintf (stderr
, "---------------------------------------\n");
7149 total_nodes
= total_bytes
= 0;
7150 for (i
= 0; i
< (int) all_kinds
; i
++)
7152 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
7153 tree_node_counts
[i
], tree_node_sizes
[i
]);
7154 total_nodes
+= tree_node_counts
[i
];
7155 total_bytes
+= tree_node_sizes
[i
];
7157 fprintf (stderr
, "---------------------------------------\n");
7158 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
7159 fprintf (stderr
, "---------------------------------------\n");
7160 ssanames_print_statistics ();
7161 phinodes_print_statistics ();
7163 fprintf (stderr
, "(No per-node statistics)\n");
7165 print_type_hash_statistics ();
7166 print_debug_expr_statistics ();
7167 print_value_expr_statistics ();
7168 lang_hooks
.print_statistics ();
7171 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
7173 /* Generate a crc32 of a string. */
7176 crc32_string (unsigned chksum
, const char *string
)
7180 unsigned value
= *string
<< 24;
7183 for (ix
= 8; ix
--; value
<<= 1)
7187 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
7196 /* P is a string that will be used in a symbol. Mask out any characters
7197 that are not valid in that context. */
7200 clean_symbol_name (char *p
)
7204 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
7207 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
7214 /* Generate a name for a special-purpose function function.
7215 The generated name may need to be unique across the whole link.
7216 TYPE is some string to identify the purpose of this function to the
7217 linker or collect2; it must start with an uppercase letter,
7219 I - for constructors
7221 N - for C++ anonymous namespaces
7222 F - for DWARF unwind frame information. */
7225 get_file_function_name (const char *type
)
7231 /* If we already have a name we know to be unique, just use that. */
7232 if (first_global_object_name
)
7233 p
= q
= ASTRDUP (first_global_object_name
);
7234 /* If the target is handling the constructors/destructors, they
7235 will be local to this file and the name is only necessary for
7236 debugging purposes. */
7237 else if ((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
7239 const char *file
= main_input_filename
;
7241 file
= input_filename
;
7242 /* Just use the file's basename, because the full pathname
7243 might be quite long. */
7244 p
= strrchr (file
, '/');
7249 p
= q
= ASTRDUP (p
);
7253 /* Otherwise, the name must be unique across the entire link.
7254 We don't have anything that we know to be unique to this translation
7255 unit, so use what we do have and throw in some randomness. */
7257 const char *name
= weak_global_object_name
;
7258 const char *file
= main_input_filename
;
7263 file
= input_filename
;
7265 len
= strlen (file
);
7266 q
= (char *) alloca (9 * 2 + len
+ 1);
7267 memcpy (q
, file
, len
+ 1);
7269 sprintf (q
+ len
, "_%08X_%08X", crc32_string (0, name
),
7270 crc32_string (0, get_random_seed (false)));
7275 clean_symbol_name (q
);
7276 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
)
7279 /* Set up the name of the file-level functions we may need.
7280 Use a global object (which is already required to be unique over
7281 the program) rather than the file name (which imposes extra
7283 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
7285 return get_identifier (buf
);
7288 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
7290 /* Complain that the tree code of NODE does not match the expected 0
7291 terminated list of trailing codes. The trailing code list can be
7292 empty, for a more vague error message. FILE, LINE, and FUNCTION
7293 are of the caller. */
7296 tree_check_failed (const_tree node
, const char *file
,
7297 int line
, const char *function
, ...)
7301 unsigned length
= 0;
7304 va_start (args
, function
);
7305 while ((code
= va_arg (args
, int)))
7306 length
+= 4 + strlen (tree_code_name
[code
]);
7311 va_start (args
, function
);
7312 length
+= strlen ("expected ");
7313 buffer
= tmp
= (char *) alloca (length
);
7315 while ((code
= va_arg (args
, int)))
7317 const char *prefix
= length
? " or " : "expected ";
7319 strcpy (tmp
+ length
, prefix
);
7320 length
+= strlen (prefix
);
7321 strcpy (tmp
+ length
, tree_code_name
[code
]);
7322 length
+= strlen (tree_code_name
[code
]);
7327 buffer
= "unexpected node";
7329 internal_error ("tree check: %s, have %s in %s, at %s:%d",
7330 buffer
, tree_code_name
[TREE_CODE (node
)],
7331 function
, trim_filename (file
), line
);
7334 /* Complain that the tree code of NODE does match the expected 0
7335 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
7339 tree_not_check_failed (const_tree node
, const char *file
,
7340 int line
, const char *function
, ...)
7344 unsigned length
= 0;
7347 va_start (args
, function
);
7348 while ((code
= va_arg (args
, int)))
7349 length
+= 4 + strlen (tree_code_name
[code
]);
7351 va_start (args
, function
);
7352 buffer
= (char *) alloca (length
);
7354 while ((code
= va_arg (args
, int)))
7358 strcpy (buffer
+ length
, " or ");
7361 strcpy (buffer
+ length
, tree_code_name
[code
]);
7362 length
+= strlen (tree_code_name
[code
]);
7366 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
7367 buffer
, tree_code_name
[TREE_CODE (node
)],
7368 function
, trim_filename (file
), line
);
7371 /* Similar to tree_check_failed, except that we check for a class of tree
7372 code, given in CL. */
7375 tree_class_check_failed (const_tree node
, const enum tree_code_class cl
,
7376 const char *file
, int line
, const char *function
)
7379 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
7380 TREE_CODE_CLASS_STRING (cl
),
7381 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
7382 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
7385 /* Similar to tree_check_failed, except that instead of specifying a
7386 dozen codes, use the knowledge that they're all sequential. */
7389 tree_range_check_failed (const_tree node
, const char *file
, int line
,
7390 const char *function
, enum tree_code c1
,
7394 unsigned length
= 0;
7397 for (c
= c1
; c
<= c2
; ++c
)
7398 length
+= 4 + strlen (tree_code_name
[c
]);
7400 length
+= strlen ("expected ");
7401 buffer
= (char *) alloca (length
);
7404 for (c
= c1
; c
<= c2
; ++c
)
7406 const char *prefix
= length
? " or " : "expected ";
7408 strcpy (buffer
+ length
, prefix
);
7409 length
+= strlen (prefix
);
7410 strcpy (buffer
+ length
, tree_code_name
[c
]);
7411 length
+= strlen (tree_code_name
[c
]);
7414 internal_error ("tree check: %s, have %s in %s, at %s:%d",
7415 buffer
, tree_code_name
[TREE_CODE (node
)],
7416 function
, trim_filename (file
), line
);
7420 /* Similar to tree_check_failed, except that we check that a tree does
7421 not have the specified code, given in CL. */
7424 tree_not_class_check_failed (const_tree node
, const enum tree_code_class cl
,
7425 const char *file
, int line
, const char *function
)
7428 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
7429 TREE_CODE_CLASS_STRING (cl
),
7430 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
7431 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
7435 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
7438 omp_clause_check_failed (const_tree node
, const char *file
, int line
,
7439 const char *function
, enum omp_clause_code code
)
7441 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
7442 omp_clause_code_name
[code
], tree_code_name
[TREE_CODE (node
)],
7443 function
, trim_filename (file
), line
);
7447 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
7450 omp_clause_range_check_failed (const_tree node
, const char *file
, int line
,
7451 const char *function
, enum omp_clause_code c1
,
7452 enum omp_clause_code c2
)
7455 unsigned length
= 0;
7458 for (c
= c1
; c
<= c2
; ++c
)
7459 length
+= 4 + strlen (omp_clause_code_name
[c
]);
7461 length
+= strlen ("expected ");
7462 buffer
= (char *) alloca (length
);
7465 for (c
= c1
; c
<= c2
; ++c
)
7467 const char *prefix
= length
? " or " : "expected ";
7469 strcpy (buffer
+ length
, prefix
);
7470 length
+= strlen (prefix
);
7471 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
7472 length
+= strlen (omp_clause_code_name
[c
]);
7475 internal_error ("tree check: %s, have %s in %s, at %s:%d",
7476 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
7477 function
, trim_filename (file
), line
);
7481 #undef DEFTREESTRUCT
7482 #define DEFTREESTRUCT(VAL, NAME) NAME,
7484 static const char *ts_enum_names
[] = {
7485 #include "treestruct.def"
7487 #undef DEFTREESTRUCT
7489 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
7491 /* Similar to tree_class_check_failed, except that we check for
7492 whether CODE contains the tree structure identified by EN. */
7495 tree_contains_struct_check_failed (const_tree node
,
7496 const enum tree_node_structure_enum en
,
7497 const char *file
, int line
,
7498 const char *function
)
7501 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
7503 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
7507 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
7508 (dynamically sized) vector. */
7511 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
7512 const char *function
)
7515 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
7516 idx
+ 1, len
, function
, trim_filename (file
), line
);
7519 /* Similar to above, except that the check is for the bounds of the operand
7520 vector of an expression node EXP. */
7523 tree_operand_check_failed (int idx
, const_tree exp
, const char *file
,
7524 int line
, const char *function
)
7526 int code
= TREE_CODE (exp
);
7528 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
7529 idx
+ 1, tree_code_name
[code
], TREE_OPERAND_LENGTH (exp
),
7530 function
, trim_filename (file
), line
);
7533 /* Similar to above, except that the check is for the number of
7534 operands of an OMP_CLAUSE node. */
7537 omp_clause_operand_check_failed (int idx
, const_tree t
, const char *file
,
7538 int line
, const char *function
)
7541 ("tree check: accessed operand %d of omp_clause %s with %d operands "
7542 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
7543 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
7544 trim_filename (file
), line
);
7546 #endif /* ENABLE_TREE_CHECKING */
7548 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
7549 and mapped to the machine mode MODE. Initialize its fields and build
7550 the information necessary for debugging output. */
7553 make_vector_type (tree innertype
, int nunits
, enum machine_mode mode
)
7556 hashval_t hashcode
= 0;
7558 /* Build a main variant, based on the main variant of the inner type, then
7559 use it to build the variant we return. */
7560 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
7561 && TYPE_MAIN_VARIANT (innertype
) != innertype
)
7562 return build_type_attribute_qual_variant (
7563 make_vector_type (TYPE_MAIN_VARIANT (innertype
), nunits
, mode
),
7564 TYPE_ATTRIBUTES (innertype
),
7565 TYPE_QUALS (innertype
));
7567 t
= make_node (VECTOR_TYPE
);
7568 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
7569 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
7570 SET_TYPE_MODE (t
, mode
);
7571 TYPE_READONLY (t
) = TYPE_READONLY (innertype
);
7572 TYPE_VOLATILE (t
) = TYPE_VOLATILE (innertype
);
7574 if (TYPE_STRUCTURAL_EQUALITY_P (innertype
))
7575 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7576 else if (TYPE_CANONICAL (innertype
) != innertype
7577 || mode
!= VOIDmode
)
7579 = make_vector_type (TYPE_CANONICAL (innertype
), nunits
, VOIDmode
);
7584 tree index
= build_int_cst (NULL_TREE
, nunits
- 1);
7585 tree array
= build_array_type (TYPE_MAIN_VARIANT (innertype
),
7586 build_index_type (index
));
7587 tree rt
= make_node (RECORD_TYPE
);
7589 TYPE_FIELDS (rt
) = build_decl (UNKNOWN_LOCATION
, FIELD_DECL
,
7590 get_identifier ("f"), array
);
7591 DECL_CONTEXT (TYPE_FIELDS (rt
)) = rt
;
7593 TYPE_DEBUG_REPRESENTATION_TYPE (t
) = rt
;
7594 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
7595 the representation type, and we want to find that die when looking up
7596 the vector type. This is most easily achieved by making the TYPE_UID
7598 TYPE_UID (rt
) = TYPE_UID (t
);
7601 hashcode
= iterative_hash_host_wide_int (VECTOR_TYPE
, hashcode
);
7602 hashcode
= iterative_hash_host_wide_int (mode
, hashcode
);
7603 hashcode
= iterative_hash_object (TYPE_HASH (innertype
), hashcode
);
7604 return type_hash_canon (hashcode
, t
);
7608 make_or_reuse_type (unsigned size
, int unsignedp
)
7610 if (size
== INT_TYPE_SIZE
)
7611 return unsignedp
? unsigned_type_node
: integer_type_node
;
7612 if (size
== CHAR_TYPE_SIZE
)
7613 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
7614 if (size
== SHORT_TYPE_SIZE
)
7615 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
7616 if (size
== LONG_TYPE_SIZE
)
7617 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
7618 if (size
== LONG_LONG_TYPE_SIZE
)
7619 return (unsignedp
? long_long_unsigned_type_node
7620 : long_long_integer_type_node
);
7623 return make_unsigned_type (size
);
7625 return make_signed_type (size
);
7628 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
7631 make_or_reuse_fract_type (unsigned size
, int unsignedp
, int satp
)
7635 if (size
== SHORT_FRACT_TYPE_SIZE
)
7636 return unsignedp
? sat_unsigned_short_fract_type_node
7637 : sat_short_fract_type_node
;
7638 if (size
== FRACT_TYPE_SIZE
)
7639 return unsignedp
? sat_unsigned_fract_type_node
: sat_fract_type_node
;
7640 if (size
== LONG_FRACT_TYPE_SIZE
)
7641 return unsignedp
? sat_unsigned_long_fract_type_node
7642 : sat_long_fract_type_node
;
7643 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
7644 return unsignedp
? sat_unsigned_long_long_fract_type_node
7645 : sat_long_long_fract_type_node
;
7649 if (size
== SHORT_FRACT_TYPE_SIZE
)
7650 return unsignedp
? unsigned_short_fract_type_node
7651 : short_fract_type_node
;
7652 if (size
== FRACT_TYPE_SIZE
)
7653 return unsignedp
? unsigned_fract_type_node
: fract_type_node
;
7654 if (size
== LONG_FRACT_TYPE_SIZE
)
7655 return unsignedp
? unsigned_long_fract_type_node
7656 : long_fract_type_node
;
7657 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
7658 return unsignedp
? unsigned_long_long_fract_type_node
7659 : long_long_fract_type_node
;
7662 return make_fract_type (size
, unsignedp
, satp
);
7665 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
7668 make_or_reuse_accum_type (unsigned size
, int unsignedp
, int satp
)
7672 if (size
== SHORT_ACCUM_TYPE_SIZE
)
7673 return unsignedp
? sat_unsigned_short_accum_type_node
7674 : sat_short_accum_type_node
;
7675 if (size
== ACCUM_TYPE_SIZE
)
7676 return unsignedp
? sat_unsigned_accum_type_node
: sat_accum_type_node
;
7677 if (size
== LONG_ACCUM_TYPE_SIZE
)
7678 return unsignedp
? sat_unsigned_long_accum_type_node
7679 : sat_long_accum_type_node
;
7680 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
7681 return unsignedp
? sat_unsigned_long_long_accum_type_node
7682 : sat_long_long_accum_type_node
;
7686 if (size
== SHORT_ACCUM_TYPE_SIZE
)
7687 return unsignedp
? unsigned_short_accum_type_node
7688 : short_accum_type_node
;
7689 if (size
== ACCUM_TYPE_SIZE
)
7690 return unsignedp
? unsigned_accum_type_node
: accum_type_node
;
7691 if (size
== LONG_ACCUM_TYPE_SIZE
)
7692 return unsignedp
? unsigned_long_accum_type_node
7693 : long_accum_type_node
;
7694 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
7695 return unsignedp
? unsigned_long_long_accum_type_node
7696 : long_long_accum_type_node
;
7699 return make_accum_type (size
, unsignedp
, satp
);
7702 /* Create nodes for all integer types (and error_mark_node) using the sizes
7703 of C datatypes. The caller should call set_sizetype soon after calling
7704 this function to select one of the types as sizetype. */
7707 build_common_tree_nodes (bool signed_char
, bool signed_sizetype
)
7709 error_mark_node
= make_node (ERROR_MARK
);
7710 TREE_TYPE (error_mark_node
) = error_mark_node
;
7712 initialize_sizetypes (signed_sizetype
);
7714 /* Define both `signed char' and `unsigned char'. */
7715 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
7716 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
7717 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
7718 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
7720 /* Define `char', which is like either `signed char' or `unsigned char'
7721 but not the same as either. */
7724 ? make_signed_type (CHAR_TYPE_SIZE
)
7725 : make_unsigned_type (CHAR_TYPE_SIZE
));
7726 TYPE_STRING_FLAG (char_type_node
) = 1;
7728 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
7729 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
7730 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
7731 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
7732 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
7733 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
7734 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
7735 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
7737 /* Define a boolean type. This type only represents boolean values but
7738 may be larger than char depending on the value of BOOL_TYPE_SIZE.
7739 Front ends which want to override this size (i.e. Java) can redefine
7740 boolean_type_node before calling build_common_tree_nodes_2. */
7741 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
7742 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
7743 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
7744 TYPE_PRECISION (boolean_type_node
) = 1;
7746 /* Fill in the rest of the sized types. Reuse existing type nodes
7748 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
7749 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
7750 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
7751 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
7752 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
7754 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
7755 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
7756 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
7757 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
7758 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
7760 access_public_node
= get_identifier ("public");
7761 access_protected_node
= get_identifier ("protected");
7762 access_private_node
= get_identifier ("private");
7765 /* Call this function after calling build_common_tree_nodes and set_sizetype.
7766 It will create several other common tree nodes. */
7769 build_common_tree_nodes_2 (int short_double
)
7771 /* Define these next since types below may used them. */
7772 integer_zero_node
= build_int_cst (NULL_TREE
, 0);
7773 integer_one_node
= build_int_cst (NULL_TREE
, 1);
7774 integer_minus_one_node
= build_int_cst (NULL_TREE
, -1);
7776 size_zero_node
= size_int (0);
7777 size_one_node
= size_int (1);
7778 bitsize_zero_node
= bitsize_int (0);
7779 bitsize_one_node
= bitsize_int (1);
7780 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
7782 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
7783 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
7785 void_type_node
= make_node (VOID_TYPE
);
7786 layout_type (void_type_node
);
7788 /* We are not going to have real types in C with less than byte alignment,
7789 so we might as well not have any types that claim to have it. */
7790 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
7791 TYPE_USER_ALIGN (void_type_node
) = 0;
7793 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
7794 layout_type (TREE_TYPE (null_pointer_node
));
7796 ptr_type_node
= build_pointer_type (void_type_node
);
7798 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
7799 fileptr_type_node
= ptr_type_node
;
7801 float_type_node
= make_node (REAL_TYPE
);
7802 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
7803 layout_type (float_type_node
);
7805 double_type_node
= make_node (REAL_TYPE
);
7807 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
7809 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
7810 layout_type (double_type_node
);
7812 long_double_type_node
= make_node (REAL_TYPE
);
7813 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
7814 layout_type (long_double_type_node
);
7816 float_ptr_type_node
= build_pointer_type (float_type_node
);
7817 double_ptr_type_node
= build_pointer_type (double_type_node
);
7818 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
7819 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
7821 /* Fixed size integer types. */
7822 uint32_type_node
= build_nonstandard_integer_type (32, true);
7823 uint64_type_node
= build_nonstandard_integer_type (64, true);
7825 /* Decimal float types. */
7826 dfloat32_type_node
= make_node (REAL_TYPE
);
7827 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
7828 layout_type (dfloat32_type_node
);
7829 SET_TYPE_MODE (dfloat32_type_node
, SDmode
);
7830 dfloat32_ptr_type_node
= build_pointer_type (dfloat32_type_node
);
7832 dfloat64_type_node
= make_node (REAL_TYPE
);
7833 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
7834 layout_type (dfloat64_type_node
);
7835 SET_TYPE_MODE (dfloat64_type_node
, DDmode
);
7836 dfloat64_ptr_type_node
= build_pointer_type (dfloat64_type_node
);
7838 dfloat128_type_node
= make_node (REAL_TYPE
);
7839 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
7840 layout_type (dfloat128_type_node
);
7841 SET_TYPE_MODE (dfloat128_type_node
, TDmode
);
7842 dfloat128_ptr_type_node
= build_pointer_type (dfloat128_type_node
);
7844 complex_integer_type_node
= build_complex_type (integer_type_node
);
7845 complex_float_type_node
= build_complex_type (float_type_node
);
7846 complex_double_type_node
= build_complex_type (double_type_node
);
7847 complex_long_double_type_node
= build_complex_type (long_double_type_node
);
7849 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
7850 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
7851 sat_ ## KIND ## _type_node = \
7852 make_sat_signed_ ## KIND ## _type (SIZE); \
7853 sat_unsigned_ ## KIND ## _type_node = \
7854 make_sat_unsigned_ ## KIND ## _type (SIZE); \
7855 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
7856 unsigned_ ## KIND ## _type_node = \
7857 make_unsigned_ ## KIND ## _type (SIZE);
7859 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
7860 sat_ ## WIDTH ## KIND ## _type_node = \
7861 make_sat_signed_ ## KIND ## _type (SIZE); \
7862 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
7863 make_sat_unsigned_ ## KIND ## _type (SIZE); \
7864 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
7865 unsigned_ ## WIDTH ## KIND ## _type_node = \
7866 make_unsigned_ ## KIND ## _type (SIZE);
7868 /* Make fixed-point type nodes based on four different widths. */
7869 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
7870 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
7871 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
7872 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
7873 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
7875 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
7876 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
7877 NAME ## _type_node = \
7878 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
7879 u ## NAME ## _type_node = \
7880 make_or_reuse_unsigned_ ## KIND ## _type \
7881 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
7882 sat_ ## NAME ## _type_node = \
7883 make_or_reuse_sat_signed_ ## KIND ## _type \
7884 (GET_MODE_BITSIZE (MODE ## mode)); \
7885 sat_u ## NAME ## _type_node = \
7886 make_or_reuse_sat_unsigned_ ## KIND ## _type \
7887 (GET_MODE_BITSIZE (U ## MODE ## mode));
7889 /* Fixed-point type and mode nodes. */
7890 MAKE_FIXED_TYPE_NODE_FAMILY (fract
, FRACT
)
7891 MAKE_FIXED_TYPE_NODE_FAMILY (accum
, ACCUM
)
7892 MAKE_FIXED_MODE_NODE (fract
, qq
, QQ
)
7893 MAKE_FIXED_MODE_NODE (fract
, hq
, HQ
)
7894 MAKE_FIXED_MODE_NODE (fract
, sq
, SQ
)
7895 MAKE_FIXED_MODE_NODE (fract
, dq
, DQ
)
7896 MAKE_FIXED_MODE_NODE (fract
, tq
, TQ
)
7897 MAKE_FIXED_MODE_NODE (accum
, ha
, HA
)
7898 MAKE_FIXED_MODE_NODE (accum
, sa
, SA
)
7899 MAKE_FIXED_MODE_NODE (accum
, da
, DA
)
7900 MAKE_FIXED_MODE_NODE (accum
, ta
, TA
)
7903 tree t
= targetm
.build_builtin_va_list ();
7905 /* Many back-ends define record types without setting TYPE_NAME.
7906 If we copied the record type here, we'd keep the original
7907 record type without a name. This breaks name mangling. So,
7908 don't copy record types and let c_common_nodes_and_builtins()
7909 declare the type to be __builtin_va_list. */
7910 if (TREE_CODE (t
) != RECORD_TYPE
)
7911 t
= build_variant_type_copy (t
);
7913 va_list_type_node
= t
;
7917 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
7920 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
7921 const char *library_name
, int ecf_flags
)
7925 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
7926 library_name
, NULL_TREE
);
7927 if (ecf_flags
& ECF_CONST
)
7928 TREE_READONLY (decl
) = 1;
7929 if (ecf_flags
& ECF_PURE
)
7930 DECL_PURE_P (decl
) = 1;
7931 if (ecf_flags
& ECF_LOOPING_CONST_OR_PURE
)
7932 DECL_LOOPING_CONST_OR_PURE_P (decl
) = 1;
7933 if (ecf_flags
& ECF_NORETURN
)
7934 TREE_THIS_VOLATILE (decl
) = 1;
7935 if (ecf_flags
& ECF_NOTHROW
)
7936 TREE_NOTHROW (decl
) = 1;
7937 if (ecf_flags
& ECF_MALLOC
)
7938 DECL_IS_MALLOC (decl
) = 1;
7940 built_in_decls
[code
] = decl
;
7941 implicit_built_in_decls
[code
] = decl
;
7944 /* Call this function after instantiating all builtins that the language
7945 front end cares about. This will build the rest of the builtins that
7946 are relied upon by the tree optimizers and the middle-end. */
7949 build_common_builtin_nodes (void)
7953 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
7954 || built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
7956 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7957 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7958 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7959 ftype
= build_function_type (ptr_type_node
, tmp
);
7961 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
)
7962 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
7963 "memcpy", ECF_NOTHROW
);
7964 if (built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
7965 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
7966 "memmove", ECF_NOTHROW
);
7969 if (built_in_decls
[BUILT_IN_MEMCMP
] == NULL
)
7971 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7972 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7973 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7974 ftype
= build_function_type (integer_type_node
, tmp
);
7975 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
7976 "memcmp", ECF_PURE
| ECF_NOTHROW
);
7979 if (built_in_decls
[BUILT_IN_MEMSET
] == NULL
)
7981 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7982 tmp
= tree_cons (NULL_TREE
, integer_type_node
, tmp
);
7983 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7984 ftype
= build_function_type (ptr_type_node
, tmp
);
7985 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
7986 "memset", ECF_NOTHROW
);
7989 if (built_in_decls
[BUILT_IN_ALLOCA
] == NULL
)
7991 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7992 ftype
= build_function_type (ptr_type_node
, tmp
);
7993 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
7994 "alloca", ECF_NOTHROW
| ECF_MALLOC
);
7997 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7998 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7999 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
8000 ftype
= build_function_type (void_type_node
, tmp
);
8001 local_define_builtin ("__builtin_init_trampoline", ftype
,
8002 BUILT_IN_INIT_TRAMPOLINE
,
8003 "__builtin_init_trampoline", ECF_NOTHROW
);
8005 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
8006 ftype
= build_function_type (ptr_type_node
, tmp
);
8007 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
8008 BUILT_IN_ADJUST_TRAMPOLINE
,
8009 "__builtin_adjust_trampoline",
8010 ECF_CONST
| ECF_NOTHROW
);
8012 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
8013 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
8014 ftype
= build_function_type (void_type_node
, tmp
);
8015 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
8016 BUILT_IN_NONLOCAL_GOTO
,
8017 "__builtin_nonlocal_goto",
8018 ECF_NORETURN
| ECF_NOTHROW
);
8020 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
8021 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
8022 ftype
= build_function_type (void_type_node
, tmp
);
8023 local_define_builtin ("__builtin_setjmp_setup", ftype
,
8024 BUILT_IN_SETJMP_SETUP
,
8025 "__builtin_setjmp_setup", ECF_NOTHROW
);
8027 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
8028 ftype
= build_function_type (ptr_type_node
, tmp
);
8029 local_define_builtin ("__builtin_setjmp_dispatcher", ftype
,
8030 BUILT_IN_SETJMP_DISPATCHER
,
8031 "__builtin_setjmp_dispatcher",
8032 ECF_PURE
| ECF_NOTHROW
);
8034 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
8035 ftype
= build_function_type (void_type_node
, tmp
);
8036 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
8037 BUILT_IN_SETJMP_RECEIVER
,
8038 "__builtin_setjmp_receiver", ECF_NOTHROW
);
8040 ftype
= build_function_type (ptr_type_node
, void_list_node
);
8041 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
8042 "__builtin_stack_save", ECF_NOTHROW
);
8044 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
8045 ftype
= build_function_type (void_type_node
, tmp
);
8046 local_define_builtin ("__builtin_stack_restore", ftype
,
8047 BUILT_IN_STACK_RESTORE
,
8048 "__builtin_stack_restore", ECF_NOTHROW
);
8050 ftype
= build_function_type (void_type_node
, void_list_node
);
8051 local_define_builtin ("__builtin_profile_func_enter", ftype
,
8052 BUILT_IN_PROFILE_FUNC_ENTER
, "profile_func_enter", 0);
8053 local_define_builtin ("__builtin_profile_func_exit", ftype
,
8054 BUILT_IN_PROFILE_FUNC_EXIT
, "profile_func_exit", 0);
8056 /* Complex multiplication and division. These are handled as builtins
8057 rather than optabs because emit_library_call_value doesn't support
8058 complex. Further, we can do slightly better with folding these
8059 beasties if the real and complex parts of the arguments are separate. */
8063 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
8065 char mode_name_buf
[4], *q
;
8067 enum built_in_function mcode
, dcode
;
8068 tree type
, inner_type
;
8070 type
= lang_hooks
.types
.type_for_mode ((enum machine_mode
) mode
, 0);
8073 inner_type
= TREE_TYPE (type
);
8075 tmp
= tree_cons (NULL_TREE
, inner_type
, void_list_node
);
8076 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
8077 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
8078 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
8079 ftype
= build_function_type (type
, tmp
);
8081 mcode
= ((enum built_in_function
)
8082 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
8083 dcode
= ((enum built_in_function
)
8084 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
8086 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
8090 built_in_names
[mcode
] = concat ("__mul", mode_name_buf
, "3", NULL
);
8091 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
8092 built_in_names
[mcode
], ECF_CONST
| ECF_NOTHROW
);
8094 built_in_names
[dcode
] = concat ("__div", mode_name_buf
, "3", NULL
);
8095 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
8096 built_in_names
[dcode
], ECF_CONST
| ECF_NOTHROW
);
8101 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
8104 If we requested a pointer to a vector, build up the pointers that
8105 we stripped off while looking for the inner type. Similarly for
8106 return values from functions.
8108 The argument TYPE is the top of the chain, and BOTTOM is the
8109 new type which we will point to. */
8112 reconstruct_complex_type (tree type
, tree bottom
)
8116 if (TREE_CODE (type
) == POINTER_TYPE
)
8118 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
8119 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
8120 TYPE_REF_CAN_ALIAS_ALL (type
));
8122 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
8124 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
8125 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
8126 TYPE_REF_CAN_ALIAS_ALL (type
));
8128 else if (TREE_CODE (type
) == ARRAY_TYPE
)
8130 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
8131 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
8133 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
8135 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
8136 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
8138 else if (TREE_CODE (type
) == METHOD_TYPE
)
8140 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
8141 /* The build_method_type_directly() routine prepends 'this' to argument list,
8142 so we must compensate by getting rid of it. */
8144 = build_method_type_directly
8145 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type
))),
8147 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
8149 else if (TREE_CODE (type
) == OFFSET_TYPE
)
8151 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
8152 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
8157 return build_qualified_type (outer
, TYPE_QUALS (type
));
8160 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
8163 build_vector_type_for_mode (tree innertype
, enum machine_mode mode
)
8167 switch (GET_MODE_CLASS (mode
))
8169 case MODE_VECTOR_INT
:
8170 case MODE_VECTOR_FLOAT
:
8171 case MODE_VECTOR_FRACT
:
8172 case MODE_VECTOR_UFRACT
:
8173 case MODE_VECTOR_ACCUM
:
8174 case MODE_VECTOR_UACCUM
:
8175 nunits
= GET_MODE_NUNITS (mode
);
8179 /* Check that there are no leftover bits. */
8180 gcc_assert (GET_MODE_BITSIZE (mode
)
8181 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
8183 nunits
= GET_MODE_BITSIZE (mode
)
8184 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
8191 return make_vector_type (innertype
, nunits
, mode
);
8194 /* Similarly, but takes the inner type and number of units, which must be
8198 build_vector_type (tree innertype
, int nunits
)
8200 return make_vector_type (innertype
, nunits
, VOIDmode
);
8203 /* Similarly, but takes the inner type and number of units, which must be
8207 build_opaque_vector_type (tree innertype
, int nunits
)
8210 innertype
= build_distinct_type_copy (innertype
);
8211 t
= make_vector_type (innertype
, nunits
, VOIDmode
);
8212 TYPE_VECTOR_OPAQUE (t
) = true;
8217 /* Build RESX_EXPR with given REGION_NUMBER. */
8219 build_resx (int region_number
)
8222 t
= build1 (RESX_EXPR
, void_type_node
,
8223 build_int_cst (NULL_TREE
, region_number
));
8227 /* Given an initializer INIT, return TRUE if INIT is zero or some
8228 aggregate of zeros. Otherwise return FALSE. */
8230 initializer_zerop (const_tree init
)
8236 switch (TREE_CODE (init
))
8239 return integer_zerop (init
);
8242 /* ??? Note that this is not correct for C4X float formats. There,
8243 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
8244 negative exponent. */
8245 return real_zerop (init
)
8246 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
8249 return fixed_zerop (init
);
8252 return integer_zerop (init
)
8253 || (real_zerop (init
)
8254 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
8255 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
8258 for (elt
= TREE_VECTOR_CST_ELTS (init
); elt
; elt
= TREE_CHAIN (elt
))
8259 if (!initializer_zerop (TREE_VALUE (elt
)))
8265 unsigned HOST_WIDE_INT idx
;
8267 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
8268 if (!initializer_zerop (elt
))
8278 /* Build an empty statement at location LOC. */
8281 build_empty_stmt (location_t loc
)
8283 tree t
= build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
8284 SET_EXPR_LOCATION (t
, loc
);
8289 /* Build an OpenMP clause with code CODE. LOC is the location of the
8293 build_omp_clause (location_t loc
, enum omp_clause_code code
)
8298 length
= omp_clause_num_ops
[code
];
8299 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
8301 t
= GGC_NEWVAR (union tree_node
, size
);
8302 memset (t
, 0, size
);
8303 TREE_SET_CODE (t
, OMP_CLAUSE
);
8304 OMP_CLAUSE_SET_CODE (t
, code
);
8305 OMP_CLAUSE_LOCATION (t
) = loc
;
8307 #ifdef GATHER_STATISTICS
8308 tree_node_counts
[(int) omp_clause_kind
]++;
8309 tree_node_sizes
[(int) omp_clause_kind
] += size
;
8315 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
8316 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
8317 Except for the CODE and operand count field, other storage for the
8318 object is initialized to zeros. */
8321 build_vl_exp_stat (enum tree_code code
, int len MEM_STAT_DECL
)
8324 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_exp
);
8326 gcc_assert (TREE_CODE_CLASS (code
) == tcc_vl_exp
);
8327 gcc_assert (len
>= 1);
8329 #ifdef GATHER_STATISTICS
8330 tree_node_counts
[(int) e_kind
]++;
8331 tree_node_sizes
[(int) e_kind
] += length
;
8334 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
8336 memset (t
, 0, length
);
8338 TREE_SET_CODE (t
, code
);
8340 /* Can't use TREE_OPERAND to store the length because if checking is
8341 enabled, it will try to check the length before we store it. :-P */
8342 t
->exp
.operands
[0] = build_int_cst (sizetype
, len
);
8348 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE
8349 and FN and a null static chain slot. ARGLIST is a TREE_LIST of the
8353 build_call_list (tree return_type
, tree fn
, tree arglist
)
8358 t
= build_vl_exp (CALL_EXPR
, list_length (arglist
) + 3);
8359 TREE_TYPE (t
) = return_type
;
8360 CALL_EXPR_FN (t
) = fn
;
8361 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
8362 for (i
= 0; arglist
; arglist
= TREE_CHAIN (arglist
), i
++)
8363 CALL_EXPR_ARG (t
, i
) = TREE_VALUE (arglist
);
8364 process_call_operands (t
);
8368 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8369 FN and a null static chain slot. NARGS is the number of call arguments
8370 which are specified as "..." arguments. */
8373 build_call_nary (tree return_type
, tree fn
, int nargs
, ...)
8377 va_start (args
, nargs
);
8378 ret
= build_call_valist (return_type
, fn
, nargs
, args
);
8383 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8384 FN and a null static chain slot. NARGS is the number of call arguments
8385 which are specified as a va_list ARGS. */
8388 build_call_valist (tree return_type
, tree fn
, int nargs
, va_list args
)
8393 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
8394 TREE_TYPE (t
) = return_type
;
8395 CALL_EXPR_FN (t
) = fn
;
8396 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
8397 for (i
= 0; i
< nargs
; i
++)
8398 CALL_EXPR_ARG (t
, i
) = va_arg (args
, tree
);
8399 process_call_operands (t
);
8403 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8404 FN and a null static chain slot. NARGS is the number of call arguments
8405 which are specified as a tree array ARGS. */
8408 build_call_array (tree return_type
, tree fn
, int nargs
, const tree
*args
)
8413 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
8414 TREE_TYPE (t
) = return_type
;
8415 CALL_EXPR_FN (t
) = fn
;
8416 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
8417 for (i
= 0; i
< nargs
; i
++)
8418 CALL_EXPR_ARG (t
, i
) = args
[i
];
8419 process_call_operands (t
);
8423 /* Like build_call_array, but takes a VEC. */
8426 build_call_vec (tree return_type
, tree fn
, VEC(tree
,gc
) *args
)
8431 ret
= build_vl_exp (CALL_EXPR
, VEC_length (tree
, args
) + 3);
8432 TREE_TYPE (ret
) = return_type
;
8433 CALL_EXPR_FN (ret
) = fn
;
8434 CALL_EXPR_STATIC_CHAIN (ret
) = NULL_TREE
;
8435 for (ix
= 0; VEC_iterate (tree
, args
, ix
, t
); ++ix
)
8436 CALL_EXPR_ARG (ret
, ix
) = t
;
8437 process_call_operands (ret
);
8442 /* Returns true if it is possible to prove that the index of
8443 an array access REF (an ARRAY_REF expression) falls into the
8447 in_array_bounds_p (tree ref
)
8449 tree idx
= TREE_OPERAND (ref
, 1);
8452 if (TREE_CODE (idx
) != INTEGER_CST
)
8455 min
= array_ref_low_bound (ref
);
8456 max
= array_ref_up_bound (ref
);
8459 || TREE_CODE (min
) != INTEGER_CST
8460 || TREE_CODE (max
) != INTEGER_CST
)
8463 if (tree_int_cst_lt (idx
, min
)
8464 || tree_int_cst_lt (max
, idx
))
8470 /* Returns true if it is possible to prove that the range of
8471 an array access REF (an ARRAY_RANGE_REF expression) falls
8472 into the array bounds. */
8475 range_in_array_bounds_p (tree ref
)
8477 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (ref
));
8478 tree range_min
, range_max
, min
, max
;
8480 range_min
= TYPE_MIN_VALUE (domain_type
);
8481 range_max
= TYPE_MAX_VALUE (domain_type
);
8484 || TREE_CODE (range_min
) != INTEGER_CST
8485 || TREE_CODE (range_max
) != INTEGER_CST
)
8488 min
= array_ref_low_bound (ref
);
8489 max
= array_ref_up_bound (ref
);
8492 || TREE_CODE (min
) != INTEGER_CST
8493 || TREE_CODE (max
) != INTEGER_CST
)
8496 if (tree_int_cst_lt (range_min
, min
)
8497 || tree_int_cst_lt (max
, range_max
))
8503 /* Return true if T (assumed to be a DECL) must be assigned a memory
8507 needs_to_live_in_memory (const_tree t
)
8509 if (TREE_CODE (t
) == SSA_NAME
)
8510 t
= SSA_NAME_VAR (t
);
8512 return (TREE_ADDRESSABLE (t
)
8513 || is_global_var (t
)
8514 || (TREE_CODE (t
) == RESULT_DECL
8515 && aggregate_value_p (t
, current_function_decl
)));
8518 /* There are situations in which a language considers record types
8519 compatible which have different field lists. Decide if two fields
8520 are compatible. It is assumed that the parent records are compatible. */
8523 fields_compatible_p (const_tree f1
, const_tree f2
)
8525 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1
),
8526 DECL_FIELD_BIT_OFFSET (f2
), OEP_ONLY_CONST
))
8529 if (!operand_equal_p (DECL_FIELD_OFFSET (f1
),
8530 DECL_FIELD_OFFSET (f2
), OEP_ONLY_CONST
))
8533 if (!types_compatible_p (TREE_TYPE (f1
), TREE_TYPE (f2
)))
8539 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
8542 find_compatible_field (tree record
, tree orig_field
)
8546 for (f
= TYPE_FIELDS (record
); f
; f
= TREE_CHAIN (f
))
8547 if (TREE_CODE (f
) == FIELD_DECL
8548 && fields_compatible_p (f
, orig_field
))
8551 /* ??? Why isn't this on the main fields list? */
8552 f
= TYPE_VFIELD (record
);
8553 if (f
&& TREE_CODE (f
) == FIELD_DECL
8554 && fields_compatible_p (f
, orig_field
))
8557 /* ??? We should abort here, but Java appears to do Bad Things
8558 with inherited fields. */
8562 /* Return value of a constant X and sign-extend it. */
8565 int_cst_value (const_tree x
)
8567 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
8568 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
8570 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
8571 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
8572 || TREE_INT_CST_HIGH (x
) == -1);
8574 if (bits
< HOST_BITS_PER_WIDE_INT
)
8576 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
8578 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
8580 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
8586 /* Return value of a constant X and sign-extend it. */
8589 widest_int_cst_value (const_tree x
)
8591 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
8592 unsigned HOST_WIDEST_INT val
= TREE_INT_CST_LOW (x
);
8594 #if HOST_BITS_PER_WIDEST_INT > HOST_BITS_PER_WIDE_INT
8595 gcc_assert (HOST_BITS_PER_WIDEST_INT
>= 2 * HOST_BITS_PER_WIDE_INT
);
8596 val
|= (((unsigned HOST_WIDEST_INT
) TREE_INT_CST_HIGH (x
))
8597 << HOST_BITS_PER_WIDE_INT
);
8599 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
8600 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
8601 || TREE_INT_CST_HIGH (x
) == -1);
8604 if (bits
< HOST_BITS_PER_WIDEST_INT
)
8606 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
8608 val
|= (~(unsigned HOST_WIDEST_INT
) 0) << (bits
- 1) << 1;
8610 val
&= ~((~(unsigned HOST_WIDEST_INT
) 0) << (bits
- 1) << 1);
8616 /* If TYPE is an integral type, return an equivalent type which is
8617 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type,
8618 return TYPE itself. */
8621 signed_or_unsigned_type_for (int unsignedp
, tree type
)
8624 if (POINTER_TYPE_P (type
))
8627 if (!INTEGRAL_TYPE_P (t
) || TYPE_UNSIGNED (t
) == unsignedp
)
8630 return lang_hooks
.types
.type_for_size (TYPE_PRECISION (t
), unsignedp
);
8633 /* Returns unsigned variant of TYPE. */
8636 unsigned_type_for (tree type
)
8638 return signed_or_unsigned_type_for (1, type
);
8641 /* Returns signed variant of TYPE. */
8644 signed_type_for (tree type
)
8646 return signed_or_unsigned_type_for (0, type
);
8649 /* Returns the largest value obtainable by casting something in INNER type to
8653 upper_bound_in_type (tree outer
, tree inner
)
8655 unsigned HOST_WIDE_INT lo
, hi
;
8656 unsigned int det
= 0;
8657 unsigned oprec
= TYPE_PRECISION (outer
);
8658 unsigned iprec
= TYPE_PRECISION (inner
);
8661 /* Compute a unique number for every combination. */
8662 det
|= (oprec
> iprec
) ? 4 : 0;
8663 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
8664 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
8666 /* Determine the exponent to use. */
8671 /* oprec <= iprec, outer: signed, inner: don't care. */
8676 /* oprec <= iprec, outer: unsigned, inner: don't care. */
8680 /* oprec > iprec, outer: signed, inner: signed. */
8684 /* oprec > iprec, outer: signed, inner: unsigned. */
8688 /* oprec > iprec, outer: unsigned, inner: signed. */
8692 /* oprec > iprec, outer: unsigned, inner: unsigned. */
8699 /* Compute 2^^prec - 1. */
8700 if (prec
<= HOST_BITS_PER_WIDE_INT
)
8703 lo
= ((~(unsigned HOST_WIDE_INT
) 0)
8704 >> (HOST_BITS_PER_WIDE_INT
- prec
));
8708 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
8709 >> (2 * HOST_BITS_PER_WIDE_INT
- prec
));
8710 lo
= ~(unsigned HOST_WIDE_INT
) 0;
8713 return build_int_cst_wide (outer
, lo
, hi
);
8716 /* Returns the smallest value obtainable by casting something in INNER type to
8720 lower_bound_in_type (tree outer
, tree inner
)
8722 unsigned HOST_WIDE_INT lo
, hi
;
8723 unsigned oprec
= TYPE_PRECISION (outer
);
8724 unsigned iprec
= TYPE_PRECISION (inner
);
8726 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
8728 if (TYPE_UNSIGNED (outer
)
8729 /* If we are widening something of an unsigned type, OUTER type
8730 contains all values of INNER type. In particular, both INNER
8731 and OUTER types have zero in common. */
8732 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
8736 /* If we are widening a signed type to another signed type, we
8737 want to obtain -2^^(iprec-1). If we are keeping the
8738 precision or narrowing to a signed type, we want to obtain
8740 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
8742 if (prec
<= HOST_BITS_PER_WIDE_INT
)
8744 hi
= ~(unsigned HOST_WIDE_INT
) 0;
8745 lo
= (~(unsigned HOST_WIDE_INT
) 0) << (prec
- 1);
8749 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
8750 << (prec
- HOST_BITS_PER_WIDE_INT
- 1));
8755 return build_int_cst_wide (outer
, lo
, hi
);
8758 /* Return nonzero if two operands that are suitable for PHI nodes are
8759 necessarily equal. Specifically, both ARG0 and ARG1 must be either
8760 SSA_NAME or invariant. Note that this is strictly an optimization.
8761 That is, callers of this function can directly call operand_equal_p
8762 and get the same result, only slower. */
8765 operand_equal_for_phi_arg_p (const_tree arg0
, const_tree arg1
)
8769 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
8771 return operand_equal_p (arg0
, arg1
, 0);
8774 /* Returns number of zeros at the end of binary representation of X.
8776 ??? Use ffs if available? */
8779 num_ending_zeros (const_tree x
)
8781 unsigned HOST_WIDE_INT fr
, nfr
;
8782 unsigned num
, abits
;
8783 tree type
= TREE_TYPE (x
);
8785 if (TREE_INT_CST_LOW (x
) == 0)
8787 num
= HOST_BITS_PER_WIDE_INT
;
8788 fr
= TREE_INT_CST_HIGH (x
);
8793 fr
= TREE_INT_CST_LOW (x
);
8796 for (abits
= HOST_BITS_PER_WIDE_INT
/ 2; abits
; abits
/= 2)
8799 if (nfr
<< abits
== fr
)
8806 if (num
> TYPE_PRECISION (type
))
8807 num
= TYPE_PRECISION (type
);
8809 return build_int_cst_type (type
, num
);
8813 #define WALK_SUBTREE(NODE) \
8816 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
8822 /* This is a subroutine of walk_tree that walks field of TYPE that are to
8823 be walked whenever a type is seen in the tree. Rest of operands and return
8824 value are as for walk_tree. */
8827 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
8828 struct pointer_set_t
*pset
, walk_tree_lh lh
)
8830 tree result
= NULL_TREE
;
8832 switch (TREE_CODE (type
))
8835 case REFERENCE_TYPE
:
8836 /* We have to worry about mutually recursive pointers. These can't
8837 be written in C. They can in Ada. It's pathological, but
8838 there's an ACATS test (c38102a) that checks it. Deal with this
8839 by checking if we're pointing to another pointer, that one
8840 points to another pointer, that one does too, and we have no htab.
8841 If so, get a hash table. We check three levels deep to avoid
8842 the cost of the hash table if we don't need one. */
8843 if (POINTER_TYPE_P (TREE_TYPE (type
))
8844 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
8845 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
8848 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
8856 /* ... fall through ... */
8859 WALK_SUBTREE (TREE_TYPE (type
));
8863 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
8868 WALK_SUBTREE (TREE_TYPE (type
));
8872 /* We never want to walk into default arguments. */
8873 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
8874 WALK_SUBTREE (TREE_VALUE (arg
));
8879 /* Don't follow this nodes's type if a pointer for fear that
8880 we'll have infinite recursion. If we have a PSET, then we
8883 || (!POINTER_TYPE_P (TREE_TYPE (type
))
8884 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
))
8885 WALK_SUBTREE (TREE_TYPE (type
));
8886 WALK_SUBTREE (TYPE_DOMAIN (type
));
8890 WALK_SUBTREE (TREE_TYPE (type
));
8891 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
8901 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
8902 called with the DATA and the address of each sub-tree. If FUNC returns a
8903 non-NULL value, the traversal is stopped, and the value returned by FUNC
8904 is returned. If PSET is non-NULL it is used to record the nodes visited,
8905 and to avoid visiting a node more than once. */
8908 walk_tree_1 (tree
*tp
, walk_tree_fn func
, void *data
,
8909 struct pointer_set_t
*pset
, walk_tree_lh lh
)
8911 enum tree_code code
;
8915 #define WALK_SUBTREE_TAIL(NODE) \
8919 goto tail_recurse; \
8924 /* Skip empty subtrees. */
8928 /* Don't walk the same tree twice, if the user has requested
8929 that we avoid doing so. */
8930 if (pset
&& pointer_set_insert (pset
, *tp
))
8933 /* Call the function. */
8935 result
= (*func
) (tp
, &walk_subtrees
, data
);
8937 /* If we found something, return it. */
8941 code
= TREE_CODE (*tp
);
8943 /* Even if we didn't, FUNC may have decided that there was nothing
8944 interesting below this point in the tree. */
8947 /* But we still need to check our siblings. */
8948 if (code
== TREE_LIST
)
8949 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
8950 else if (code
== OMP_CLAUSE
)
8951 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8958 result
= (*lh
) (tp
, &walk_subtrees
, func
, data
, pset
);
8959 if (result
|| !walk_subtrees
)
8966 case IDENTIFIER_NODE
:
8973 case PLACEHOLDER_EXPR
:
8977 /* None of these have subtrees other than those already walked
8982 WALK_SUBTREE (TREE_VALUE (*tp
));
8983 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
8988 int len
= TREE_VEC_LENGTH (*tp
);
8993 /* Walk all elements but the first. */
8995 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
8997 /* Now walk the first one as a tail call. */
8998 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
9002 WALK_SUBTREE (TREE_REALPART (*tp
));
9003 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
9007 unsigned HOST_WIDE_INT idx
;
9008 constructor_elt
*ce
;
9011 VEC_iterate(constructor_elt
, CONSTRUCTOR_ELTS (*tp
), idx
, ce
);
9013 WALK_SUBTREE (ce
->value
);
9018 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
9023 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= TREE_CHAIN (decl
))
9025 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
9026 into declarations that are just mentioned, rather than
9027 declared; they don't really belong to this part of the tree.
9028 And, we can see cycles: the initializer for a declaration
9029 can refer to the declaration itself. */
9030 WALK_SUBTREE (DECL_INITIAL (decl
));
9031 WALK_SUBTREE (DECL_SIZE (decl
));
9032 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
9034 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
9037 case STATEMENT_LIST
:
9039 tree_stmt_iterator i
;
9040 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
9041 WALK_SUBTREE (*tsi_stmt_ptr (i
));
9046 switch (OMP_CLAUSE_CODE (*tp
))
9048 case OMP_CLAUSE_PRIVATE
:
9049 case OMP_CLAUSE_SHARED
:
9050 case OMP_CLAUSE_FIRSTPRIVATE
:
9051 case OMP_CLAUSE_COPYIN
:
9052 case OMP_CLAUSE_COPYPRIVATE
:
9054 case OMP_CLAUSE_NUM_THREADS
:
9055 case OMP_CLAUSE_SCHEDULE
:
9056 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 0));
9059 case OMP_CLAUSE_NOWAIT
:
9060 case OMP_CLAUSE_ORDERED
:
9061 case OMP_CLAUSE_DEFAULT
:
9062 case OMP_CLAUSE_UNTIED
:
9063 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
9065 case OMP_CLAUSE_LASTPRIVATE
:
9066 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
9067 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp
));
9068 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
9070 case OMP_CLAUSE_COLLAPSE
:
9073 for (i
= 0; i
< 3; i
++)
9074 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
9075 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
9078 case OMP_CLAUSE_REDUCTION
:
9081 for (i
= 0; i
< 4; i
++)
9082 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
9083 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
9095 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
9096 But, we only want to walk once. */
9097 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
9098 for (i
= 0; i
< len
; ++i
)
9099 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
9100 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
9104 /* If this is a TYPE_DECL, walk into the fields of the type that it's
9105 defining. We only want to walk into these fields of a type in this
9106 case and not in the general case of a mere reference to the type.
9108 The criterion is as follows: if the field can be an expression, it
9109 must be walked only here. This should be in keeping with the fields
9110 that are directly gimplified in gimplify_type_sizes in order for the
9111 mark/copy-if-shared/unmark machinery of the gimplifier to work with
9112 variable-sized types.
9114 Note that DECLs get walked as part of processing the BIND_EXPR. */
9115 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
9117 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
9118 if (TREE_CODE (*type_p
) == ERROR_MARK
)
9121 /* Call the function for the type. See if it returns anything or
9122 doesn't want us to continue. If we are to continue, walk both
9123 the normal fields and those for the declaration case. */
9124 result
= (*func
) (type_p
, &walk_subtrees
, data
);
9125 if (result
|| !walk_subtrees
)
9128 result
= walk_type_fields (*type_p
, func
, data
, pset
, lh
);
9132 /* If this is a record type, also walk the fields. */
9133 if (TREE_CODE (*type_p
) == RECORD_TYPE
9134 || TREE_CODE (*type_p
) == UNION_TYPE
9135 || TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
9139 for (field
= TYPE_FIELDS (*type_p
); field
;
9140 field
= TREE_CHAIN (field
))
9142 /* We'd like to look at the type of the field, but we can
9143 easily get infinite recursion. So assume it's pointed
9144 to elsewhere in the tree. Also, ignore things that
9146 if (TREE_CODE (field
) != FIELD_DECL
)
9149 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
9150 WALK_SUBTREE (DECL_SIZE (field
));
9151 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
9152 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
9153 WALK_SUBTREE (DECL_QUALIFIER (field
));
9157 /* Same for scalar types. */
9158 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
9159 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
9160 || TREE_CODE (*type_p
) == INTEGER_TYPE
9161 || TREE_CODE (*type_p
) == FIXED_POINT_TYPE
9162 || TREE_CODE (*type_p
) == REAL_TYPE
)
9164 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
9165 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
9168 WALK_SUBTREE (TYPE_SIZE (*type_p
));
9169 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
9174 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
)))
9178 /* Walk over all the sub-trees of this operand. */
9179 len
= TREE_OPERAND_LENGTH (*tp
);
9181 /* Go through the subtrees. We need to do this in forward order so
9182 that the scope of a FOR_EXPR is handled properly. */
9185 for (i
= 0; i
< len
- 1; ++i
)
9186 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
9187 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
- 1));
9190 /* If this is a type, walk the needed fields in the type. */
9191 else if (TYPE_P (*tp
))
9192 return walk_type_fields (*tp
, func
, data
, pset
, lh
);
9196 /* We didn't find what we were looking for. */
9199 #undef WALK_SUBTREE_TAIL
9203 /* Like walk_tree, but does not walk duplicate nodes more than once. */
9206 walk_tree_without_duplicates_1 (tree
*tp
, walk_tree_fn func
, void *data
,
9210 struct pointer_set_t
*pset
;
9212 pset
= pointer_set_create ();
9213 result
= walk_tree_1 (tp
, func
, data
, pset
, lh
);
9214 pointer_set_destroy (pset
);
9222 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
9224 if (IS_EXPR_CODE_CLASS (c
))
9225 return &t
->exp
.block
;
9230 /* Build and return a TREE_LIST of arguments in the CALL_EXPR exp.
9231 FIXME: don't use this function. It exists for compatibility with
9232 the old representation of CALL_EXPRs where a list was used to hold the
9233 arguments. Places that currently extract the arglist from a CALL_EXPR
9234 ought to be rewritten to use the CALL_EXPR itself. */
9236 call_expr_arglist (tree exp
)
9238 tree arglist
= NULL_TREE
;
9240 for (i
= call_expr_nargs (exp
) - 1; i
>= 0; i
--)
9241 arglist
= tree_cons (NULL_TREE
, CALL_EXPR_ARG (exp
, i
), arglist
);
9246 /* Create a nameless artificial label and put it in the current
9247 function context. The label has a location of LOC. Returns the
9248 newly created label. */
9251 create_artificial_label (location_t loc
)
9253 tree lab
= build_decl (loc
,
9254 LABEL_DECL
, NULL_TREE
, void_type_node
);
9256 DECL_ARTIFICIAL (lab
) = 1;
9257 DECL_IGNORED_P (lab
) = 1;
9258 DECL_CONTEXT (lab
) = current_function_decl
;
9262 /* Given a tree, try to return a useful variable name that we can use
9263 to prefix a temporary that is being assigned the value of the tree.
9264 I.E. given <temp> = &A, return A. */
9272 STRIP_NOPS (stripped_decl
);
9273 if (DECL_P (stripped_decl
) && DECL_NAME (stripped_decl
))
9274 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl
));
9277 switch (TREE_CODE (stripped_decl
))
9280 return get_name (TREE_OPERAND (stripped_decl
, 0));
9287 /* Return true if TYPE has a variable argument list. */
9290 stdarg_p (tree fntype
)
9292 function_args_iterator args_iter
;
9293 tree n
= NULL_TREE
, t
;
9298 FOREACH_FUNCTION_ARGS(fntype
, t
, args_iter
)
9303 return n
!= NULL_TREE
&& n
!= void_type_node
;
9306 /* Return true if TYPE has a prototype. */
9309 prototype_p (tree fntype
)
9313 gcc_assert (fntype
!= NULL_TREE
);
9315 t
= TYPE_ARG_TYPES (fntype
);
9316 return (t
!= NULL_TREE
);
9319 /* If BLOCK is inlined from an __attribute__((__artificial__))
9320 routine, return pointer to location from where it has been
9323 block_nonartificial_location (tree block
)
9325 location_t
*ret
= NULL
;
9327 while (block
&& TREE_CODE (block
) == BLOCK
9328 && BLOCK_ABSTRACT_ORIGIN (block
))
9330 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
9332 while (TREE_CODE (ao
) == BLOCK
9333 && BLOCK_ABSTRACT_ORIGIN (ao
)
9334 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
9335 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
9337 if (TREE_CODE (ao
) == FUNCTION_DECL
)
9339 /* If AO is an artificial inline, point RET to the
9340 call site locus at which it has been inlined and continue
9341 the loop, in case AO's caller is also an artificial
9343 if (DECL_DECLARED_INLINE_P (ao
)
9344 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao
)))
9345 ret
= &BLOCK_SOURCE_LOCATION (block
);
9349 else if (TREE_CODE (ao
) != BLOCK
)
9352 block
= BLOCK_SUPERCONTEXT (block
);
9358 /* If EXP is inlined from an __attribute__((__artificial__))
9359 function, return the location of the original call expression. */
9362 tree_nonartificial_location (tree exp
)
9364 location_t
*loc
= block_nonartificial_location (TREE_BLOCK (exp
));
9369 return EXPR_LOCATION (exp
);
9373 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
9376 /* Return the hash code code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
9379 cl_option_hash_hash (const void *x
)
9381 const_tree
const t
= (const_tree
) x
;
9387 if (TREE_CODE (t
) == OPTIMIZATION_NODE
)
9389 p
= (const char *)TREE_OPTIMIZATION (t
);
9390 len
= sizeof (struct cl_optimization
);
9393 else if (TREE_CODE (t
) == TARGET_OPTION_NODE
)
9395 p
= (const char *)TREE_TARGET_OPTION (t
);
9396 len
= sizeof (struct cl_target_option
);
9402 /* assume most opt flags are just 0/1, some are 2-3, and a few might be
9404 for (i
= 0; i
< len
; i
++)
9406 hash
= (hash
<< 4) ^ ((i
<< 2) | p
[i
]);
9411 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
9412 TARGET_OPTION tree node) is the same as that given by *Y, which is the
9416 cl_option_hash_eq (const void *x
, const void *y
)
9418 const_tree
const xt
= (const_tree
) x
;
9419 const_tree
const yt
= (const_tree
) y
;
9424 if (TREE_CODE (xt
) != TREE_CODE (yt
))
9427 if (TREE_CODE (xt
) == OPTIMIZATION_NODE
)
9429 xp
= (const char *)TREE_OPTIMIZATION (xt
);
9430 yp
= (const char *)TREE_OPTIMIZATION (yt
);
9431 len
= sizeof (struct cl_optimization
);
9434 else if (TREE_CODE (xt
) == TARGET_OPTION_NODE
)
9436 xp
= (const char *)TREE_TARGET_OPTION (xt
);
9437 yp
= (const char *)TREE_TARGET_OPTION (yt
);
9438 len
= sizeof (struct cl_target_option
);
9444 return (memcmp (xp
, yp
, len
) == 0);
9447 /* Build an OPTIMIZATION_NODE based on the current options. */
9450 build_optimization_node (void)
9455 /* Use the cache of optimization nodes. */
9457 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node
));
9459 slot
= htab_find_slot (cl_option_hash_table
, cl_optimization_node
, INSERT
);
9463 /* Insert this one into the hash table. */
9464 t
= cl_optimization_node
;
9467 /* Make a new node for next time round. */
9468 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
9474 /* Build a TARGET_OPTION_NODE based on the current options. */
9477 build_target_option_node (void)
9482 /* Use the cache of optimization nodes. */
9484 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node
));
9486 slot
= htab_find_slot (cl_option_hash_table
, cl_target_option_node
, INSERT
);
9490 /* Insert this one into the hash table. */
9491 t
= cl_target_option_node
;
9494 /* Make a new node for next time round. */
9495 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
9501 /* Determine the "ultimate origin" of a block. The block may be an inlined
9502 instance of an inlined instance of a block which is local to an inline
9503 function, so we have to trace all of the way back through the origin chain
9504 to find out what sort of node actually served as the original seed for the
9508 block_ultimate_origin (const_tree block
)
9510 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
9512 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
9513 nodes in the function to point to themselves; ignore that if
9514 we're trying to output the abstract instance of this function. */
9515 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
9518 if (immediate_origin
== NULL_TREE
)
9523 tree lookahead
= immediate_origin
;
9527 ret_val
= lookahead
;
9528 lookahead
= (TREE_CODE (ret_val
) == BLOCK
9529 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
9531 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
9533 /* The block's abstract origin chain may not be the *ultimate* origin of
9534 the block. It could lead to a DECL that has an abstract origin set.
9535 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
9536 will give us if it has one). Note that DECL's abstract origins are
9537 supposed to be the most distant ancestor (or so decl_ultimate_origin
9538 claims), so we don't need to loop following the DECL origins. */
9539 if (DECL_P (ret_val
))
9540 return DECL_ORIGIN (ret_val
);
9546 /* Return true if T1 and T2 are equivalent lists. */
9549 list_equal_p (const_tree t1
, const_tree t2
)
9551 for (; t1
&& t2
; t1
= TREE_CHAIN (t1
) , t2
= TREE_CHAIN (t2
))
9552 if (TREE_VALUE (t1
) != TREE_VALUE (t2
))
9557 /* Return true iff conversion in EXP generates no instruction. Mark
9558 it inline so that we fully inline into the stripping functions even
9559 though we have two uses of this function. */
9562 tree_nop_conversion (const_tree exp
)
9564 tree outer_type
, inner_type
;
9566 if (!CONVERT_EXPR_P (exp
)
9567 && TREE_CODE (exp
) != NON_LVALUE_EXPR
)
9569 if (TREE_OPERAND (exp
, 0) == error_mark_node
)
9572 outer_type
= TREE_TYPE (exp
);
9573 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
9575 /* Use precision rather then machine mode when we can, which gives
9576 the correct answer even for submode (bit-field) types. */
9577 if ((INTEGRAL_TYPE_P (outer_type
)
9578 || POINTER_TYPE_P (outer_type
)
9579 || TREE_CODE (outer_type
) == OFFSET_TYPE
)
9580 && (INTEGRAL_TYPE_P (inner_type
)
9581 || POINTER_TYPE_P (inner_type
)
9582 || TREE_CODE (inner_type
) == OFFSET_TYPE
))
9583 return TYPE_PRECISION (outer_type
) == TYPE_PRECISION (inner_type
);
9585 /* Otherwise fall back on comparing machine modes (e.g. for
9586 aggregate types, floats). */
9587 return TYPE_MODE (outer_type
) == TYPE_MODE (inner_type
);
9590 /* Return true iff conversion in EXP generates no instruction. Don't
9591 consider conversions changing the signedness. */
9594 tree_sign_nop_conversion (const_tree exp
)
9596 tree outer_type
, inner_type
;
9598 if (!tree_nop_conversion (exp
))
9601 outer_type
= TREE_TYPE (exp
);
9602 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
9604 return (TYPE_UNSIGNED (outer_type
) == TYPE_UNSIGNED (inner_type
)
9605 && POINTER_TYPE_P (outer_type
) == POINTER_TYPE_P (inner_type
));
9608 /* Strip conversions from EXP according to tree_nop_conversion and
9609 return the resulting expression. */
9612 tree_strip_nop_conversions (tree exp
)
9614 while (tree_nop_conversion (exp
))
9615 exp
= TREE_OPERAND (exp
, 0);
9619 /* Strip conversions from EXP according to tree_sign_nop_conversion
9620 and return the resulting expression. */
9623 tree_strip_sign_nop_conversions (tree exp
)
9625 while (tree_sign_nop_conversion (exp
))
9626 exp
= TREE_OPERAND (exp
, 0);
9631 #include "gt-tree.h"