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
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-iterator.h"
49 #include "basic-block.h"
50 #include "tree-flow.h"
52 #include "pointer-set.h"
53 #include "fixed-value.h"
55 /* Each tree code class has an associated string representation.
56 These must correspond to the tree_code_class entries. */
58 const char *const tree_code_class_strings
[] =
74 /* obstack.[ch] explicitly declined to prototype this. */
75 extern int _obstack_allocated_p (struct obstack
*h
, void *obj
);
77 #ifdef GATHER_STATISTICS
78 /* Statistics-gathering stuff. */
80 int tree_node_counts
[(int) all_kinds
];
81 int tree_node_sizes
[(int) all_kinds
];
83 /* Keep in sync with tree.h:enum tree_node_kind. */
84 static const char * const tree_node_kind_names
[] = {
106 #endif /* GATHER_STATISTICS */
108 /* Unique id for next decl created. */
109 static GTY(()) int next_decl_uid
;
110 /* Unique id for next type created. */
111 static GTY(()) int next_type_uid
= 1;
113 /* Mapping from unique DECL_UID to the decl tree node. */
114 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
115 htab_t decl_for_uid_map
;
117 static void insert_decl_to_uid_decl_map (tree
);
119 /* Since we cannot rehash a type after it is in the table, we have to
120 keep the hash code. */
122 struct type_hash
GTY(())
128 /* Initial size of the hash table (rounded to next prime). */
129 #define TYPE_HASH_INITIAL_SIZE 1000
131 /* Now here is the hash table. When recording a type, it is added to
132 the slot whose index is the hash code. Note that the hash table is
133 used for several kinds of types (function types, array types and
134 array index range types, for now). While all these live in the
135 same table, they are completely independent, and the hash code is
136 computed differently for each of these. */
138 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash
)))
139 htab_t type_hash_table
;
141 /* Hash table and temporary node for larger integer const values. */
142 static GTY (()) tree int_cst_node
;
143 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
144 htab_t int_cst_hash_table
;
146 /* General tree->tree mapping structure for use in hash tables. */
149 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
150 htab_t debug_expr_for_decl
;
152 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
153 htab_t value_expr_for_decl
;
155 static GTY ((if_marked ("tree_priority_map_marked_p"),
156 param_is (struct tree_priority_map
)))
157 htab_t init_priority_for_decl
;
159 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
160 htab_t restrict_base_for_decl
;
162 static void set_type_quals (tree
, int);
163 static int type_hash_eq (const void *, const void *);
164 static hashval_t
type_hash_hash (const void *);
165 static hashval_t
int_cst_hash_hash (const void *);
166 static int int_cst_hash_eq (const void *, const void *);
167 static void print_type_hash_statistics (void);
168 static void print_debug_expr_statistics (void);
169 static void print_value_expr_statistics (void);
170 static int type_hash_marked_p (const void *);
171 static unsigned int type_hash_list (const_tree
, hashval_t
);
172 static unsigned int attribute_hash_list (const_tree
, hashval_t
);
174 tree global_trees
[TI_MAX
];
175 tree integer_types
[itk_none
];
177 unsigned char tree_contains_struct
[MAX_TREE_CODES
][64];
179 /* Number of operands for each OpenMP clause. */
180 unsigned const char omp_clause_num_ops
[] =
182 0, /* OMP_CLAUSE_ERROR */
183 1, /* OMP_CLAUSE_PRIVATE */
184 1, /* OMP_CLAUSE_SHARED */
185 1, /* OMP_CLAUSE_FIRSTPRIVATE */
186 1, /* OMP_CLAUSE_LASTPRIVATE */
187 4, /* OMP_CLAUSE_REDUCTION */
188 1, /* OMP_CLAUSE_COPYIN */
189 1, /* OMP_CLAUSE_COPYPRIVATE */
190 1, /* OMP_CLAUSE_IF */
191 1, /* OMP_CLAUSE_NUM_THREADS */
192 1, /* OMP_CLAUSE_SCHEDULE */
193 0, /* OMP_CLAUSE_NOWAIT */
194 0, /* OMP_CLAUSE_ORDERED */
195 0 /* OMP_CLAUSE_DEFAULT */
198 const char * const omp_clause_code_name
[] =
221 /* Initialize the hash table of types. */
222 type_hash_table
= htab_create_ggc (TYPE_HASH_INITIAL_SIZE
, type_hash_hash
,
225 debug_expr_for_decl
= htab_create_ggc (512, tree_map_hash
,
228 value_expr_for_decl
= htab_create_ggc (512, tree_map_hash
,
230 init_priority_for_decl
= htab_create_ggc (512, tree_priority_map_hash
,
231 tree_priority_map_eq
, 0);
232 restrict_base_for_decl
= htab_create_ggc (256, tree_map_hash
,
235 int_cst_hash_table
= htab_create_ggc (1024, int_cst_hash_hash
,
236 int_cst_hash_eq
, NULL
);
238 int_cst_node
= make_node (INTEGER_CST
);
240 decl_for_uid_map
= htab_create_ggc (4093, uid_decl_map_hash
,
241 uid_decl_map_eq
, NULL
);
243 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
] = 1;
244 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_NON_COMMON
] = 1;
245 tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
] = 1;
248 tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
] = 1;
249 tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
] = 1;
250 tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
] = 1;
251 tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
] = 1;
252 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
] = 1;
253 tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
] = 1;
254 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
] = 1;
255 tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
] = 1;
256 tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
] = 1;
259 tree_contains_struct
[CONST_DECL
][TS_DECL_WRTL
] = 1;
260 tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
] = 1;
261 tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
] = 1;
262 tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
] = 1;
263 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
] = 1;
264 tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
] = 1;
266 tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
] = 1;
267 tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
] = 1;
268 tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
] = 1;
269 tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
] = 1;
270 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
] = 1;
271 tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
] = 1;
272 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
] = 1;
273 tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
] = 1;
274 tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
] = 1;
275 tree_contains_struct
[STRUCT_FIELD_TAG
][TS_DECL_MINIMAL
] = 1;
276 tree_contains_struct
[NAME_MEMORY_TAG
][TS_DECL_MINIMAL
] = 1;
277 tree_contains_struct
[SYMBOL_MEMORY_TAG
][TS_DECL_MINIMAL
] = 1;
278 tree_contains_struct
[MEMORY_PARTITION_TAG
][TS_DECL_MINIMAL
] = 1;
280 tree_contains_struct
[STRUCT_FIELD_TAG
][TS_MEMORY_TAG
] = 1;
281 tree_contains_struct
[NAME_MEMORY_TAG
][TS_MEMORY_TAG
] = 1;
282 tree_contains_struct
[SYMBOL_MEMORY_TAG
][TS_MEMORY_TAG
] = 1;
283 tree_contains_struct
[MEMORY_PARTITION_TAG
][TS_MEMORY_TAG
] = 1;
285 tree_contains_struct
[STRUCT_FIELD_TAG
][TS_STRUCT_FIELD_TAG
] = 1;
286 tree_contains_struct
[MEMORY_PARTITION_TAG
][TS_MEMORY_PARTITION_TAG
] = 1;
288 tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
] = 1;
289 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
] = 1;
290 tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
] = 1;
291 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_WITH_VIS
] = 1;
293 tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
] = 1;
294 tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
] = 1;
295 tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
] = 1;
296 tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
] = 1;
297 tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
] = 1;
298 tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
] = 1;
299 tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
] = 1;
300 tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
] = 1;
302 lang_hooks
.init_ts ();
306 /* The name of the object as the assembler will see it (but before any
307 translations made by ASM_OUTPUT_LABELREF). Often this is the same
308 as DECL_NAME. It is an IDENTIFIER_NODE. */
310 decl_assembler_name (tree decl
)
312 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
313 lang_hooks
.set_decl_assembler_name (decl
);
314 return DECL_WITH_VIS_CHECK (decl
)->decl_with_vis
.assembler_name
;
317 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
320 decl_assembler_name_equal (tree decl
, tree asmname
)
322 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
324 if (decl_asmname
== asmname
)
327 /* If the target assembler name was set by the user, things are trickier.
328 We have a leading '*' to begin with. After that, it's arguable what
329 is the correct thing to do with -fleading-underscore. Arguably, we've
330 historically been doing the wrong thing in assemble_alias by always
331 printing the leading underscore. Since we're not changing that, make
332 sure user_label_prefix follows the '*' before matching. */
333 if (IDENTIFIER_POINTER (decl_asmname
)[0] == '*')
335 const char *decl_str
= IDENTIFIER_POINTER (decl_asmname
) + 1;
336 size_t ulp_len
= strlen (user_label_prefix
);
340 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
345 return strcmp (decl_str
, IDENTIFIER_POINTER (asmname
)) == 0;
351 /* Compute the number of bytes occupied by a tree with code CODE.
352 This function cannot be used for nodes that have variable sizes,
353 including TREE_VEC, PHI_NODE, STRING_CST, and CALL_EXPR. */
355 tree_code_size (enum tree_code code
)
357 switch (TREE_CODE_CLASS (code
))
359 case tcc_declaration
: /* A decl node */
364 return sizeof (struct tree_field_decl
);
366 return sizeof (struct tree_parm_decl
);
368 return sizeof (struct tree_var_decl
);
370 return sizeof (struct tree_label_decl
);
372 return sizeof (struct tree_result_decl
);
374 return sizeof (struct tree_const_decl
);
376 return sizeof (struct tree_type_decl
);
378 return sizeof (struct tree_function_decl
);
379 case NAME_MEMORY_TAG
:
380 case SYMBOL_MEMORY_TAG
:
381 return sizeof (struct tree_memory_tag
);
382 case STRUCT_FIELD_TAG
:
383 return sizeof (struct tree_struct_field_tag
);
384 case MEMORY_PARTITION_TAG
:
385 return sizeof (struct tree_memory_partition_tag
);
387 return sizeof (struct tree_decl_non_common
);
391 case tcc_type
: /* a type node */
392 return sizeof (struct tree_type
);
394 case tcc_reference
: /* a reference */
395 case tcc_expression
: /* an expression */
396 case tcc_statement
: /* an expression with side effects */
397 case tcc_comparison
: /* a comparison expression */
398 case tcc_unary
: /* a unary arithmetic expression */
399 case tcc_binary
: /* a binary arithmetic expression */
400 return (sizeof (struct tree_exp
)
401 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (tree
));
403 case tcc_gimple_stmt
:
404 return (sizeof (struct gimple_stmt
)
405 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (char *));
407 case tcc_constant
: /* a constant */
410 case INTEGER_CST
: return sizeof (struct tree_int_cst
);
411 case REAL_CST
: return sizeof (struct tree_real_cst
);
412 case FIXED_CST
: return sizeof (struct tree_fixed_cst
);
413 case COMPLEX_CST
: return sizeof (struct tree_complex
);
414 case VECTOR_CST
: return sizeof (struct tree_vector
);
415 case STRING_CST
: gcc_unreachable ();
417 return lang_hooks
.tree_size (code
);
420 case tcc_exceptional
: /* something random, like an identifier. */
423 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
424 case TREE_LIST
: return sizeof (struct tree_list
);
427 case PLACEHOLDER_EXPR
: return sizeof (struct tree_common
);
431 case PHI_NODE
: gcc_unreachable ();
433 case SSA_NAME
: return sizeof (struct tree_ssa_name
);
435 case STATEMENT_LIST
: return sizeof (struct tree_statement_list
);
436 case BLOCK
: return sizeof (struct tree_block
);
437 case VALUE_HANDLE
: return sizeof (struct tree_value_handle
);
438 case CONSTRUCTOR
: return sizeof (struct tree_constructor
);
441 return lang_hooks
.tree_size (code
);
449 /* Compute the number of bytes occupied by NODE. This routine only
450 looks at TREE_CODE, except for those nodes that have variable sizes. */
452 tree_size (const_tree node
)
454 const enum tree_code code
= TREE_CODE (node
);
458 return (sizeof (struct tree_phi_node
)
459 + (PHI_ARG_CAPACITY (node
) - 1) * sizeof (struct phi_arg_d
));
462 return (offsetof (struct tree_binfo
, base_binfos
)
463 + VEC_embedded_size (tree
, BINFO_N_BASE_BINFOS (node
)));
466 return (sizeof (struct tree_vec
)
467 + (TREE_VEC_LENGTH (node
) - 1) * sizeof (tree
));
470 return TREE_STRING_LENGTH (node
) + offsetof (struct tree_string
, str
) + 1;
473 return (sizeof (struct tree_omp_clause
)
474 + (omp_clause_num_ops
[OMP_CLAUSE_CODE (node
)] - 1)
478 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
479 return (sizeof (struct tree_exp
)
480 + (VL_EXP_OPERAND_LENGTH (node
) - 1) * sizeof (tree
));
482 return tree_code_size (code
);
486 /* Return a newly allocated node of code CODE. For decl and type
487 nodes, some other fields are initialized. The rest of the node is
488 initialized to zero. This function cannot be used for PHI_NODE,
489 TREE_VEC or OMP_CLAUSE nodes, which is enforced by asserts in
492 Achoo! I got a code in the node. */
495 make_node_stat (enum tree_code code MEM_STAT_DECL
)
498 enum tree_code_class type
= TREE_CODE_CLASS (code
);
499 size_t length
= tree_code_size (code
);
500 #ifdef GATHER_STATISTICS
505 case tcc_declaration
: /* A decl node */
509 case tcc_type
: /* a type node */
513 case tcc_statement
: /* an expression with side effects */
517 case tcc_reference
: /* a reference */
521 case tcc_expression
: /* an expression */
522 case tcc_comparison
: /* a comparison expression */
523 case tcc_unary
: /* a unary arithmetic expression */
524 case tcc_binary
: /* a binary arithmetic expression */
528 case tcc_constant
: /* a constant */
532 case tcc_gimple_stmt
:
533 kind
= gimple_stmt_kind
;
536 case tcc_exceptional
: /* something random, like an identifier. */
539 case IDENTIFIER_NODE
:
556 kind
= ssa_name_kind
;
577 tree_node_counts
[(int) kind
]++;
578 tree_node_sizes
[(int) kind
] += length
;
581 if (code
== IDENTIFIER_NODE
)
582 t
= ggc_alloc_zone_pass_stat (length
, &tree_id_zone
);
584 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
586 memset (t
, 0, length
);
588 TREE_SET_CODE (t
, code
);
593 TREE_SIDE_EFFECTS (t
) = 1;
596 case tcc_declaration
:
597 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
598 DECL_IN_SYSTEM_HEADER (t
) = in_system_header
;
599 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
601 if (code
== FUNCTION_DECL
)
603 DECL_ALIGN (t
) = FUNCTION_BOUNDARY
;
604 DECL_MODE (t
) = FUNCTION_MODE
;
608 /* We have not yet computed the alias set for this declaration. */
609 DECL_POINTER_ALIAS_SET (t
) = -1;
611 DECL_SOURCE_LOCATION (t
) = input_location
;
612 DECL_UID (t
) = next_decl_uid
++;
613 insert_decl_to_uid_decl_map (t
);
618 TYPE_UID (t
) = next_type_uid
++;
619 TYPE_ALIGN (t
) = BITS_PER_UNIT
;
620 TYPE_USER_ALIGN (t
) = 0;
621 TYPE_MAIN_VARIANT (t
) = t
;
622 TYPE_CANONICAL (t
) = t
;
624 /* Default to no attributes for type, but let target change that. */
625 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
626 targetm
.set_default_type_attributes (t
);
628 /* We have not yet computed the alias set for this type. */
629 TYPE_ALIAS_SET (t
) = -1;
633 TREE_CONSTANT (t
) = 1;
634 TREE_INVARIANT (t
) = 1;
643 case PREDECREMENT_EXPR
:
644 case PREINCREMENT_EXPR
:
645 case POSTDECREMENT_EXPR
:
646 case POSTINCREMENT_EXPR
:
647 /* All of these have side-effects, no matter what their
649 TREE_SIDE_EFFECTS (t
) = 1;
657 case tcc_gimple_stmt
:
660 case GIMPLE_MODIFY_STMT
:
661 TREE_SIDE_EFFECTS (t
) = 1;
669 /* Other classes need no special treatment. */
676 /* Return a new node with the same contents as NODE except that its
677 TREE_CHAIN is zero and it has a fresh uid. */
680 copy_node_stat (tree node MEM_STAT_DECL
)
683 enum tree_code code
= TREE_CODE (node
);
686 gcc_assert (code
!= STATEMENT_LIST
);
688 length
= tree_size (node
);
689 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
690 memcpy (t
, node
, length
);
692 if (!GIMPLE_TUPLE_P (node
))
694 TREE_ASM_WRITTEN (t
) = 0;
695 TREE_VISITED (t
) = 0;
698 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
700 DECL_UID (t
) = next_decl_uid
++;
701 if ((TREE_CODE (node
) == PARM_DECL
|| TREE_CODE (node
) == VAR_DECL
)
702 && DECL_HAS_VALUE_EXPR_P (node
))
704 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
705 DECL_HAS_VALUE_EXPR_P (t
) = 1;
707 if (TREE_CODE (node
) == VAR_DECL
&& DECL_HAS_INIT_PRIORITY_P (node
))
709 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
710 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
712 if (TREE_CODE (node
) == VAR_DECL
&& DECL_BASED_ON_RESTRICT_P (node
))
714 SET_DECL_RESTRICT_BASE (t
, DECL_GET_RESTRICT_BASE (node
));
715 DECL_BASED_ON_RESTRICT_P (t
) = 1;
717 insert_decl_to_uid_decl_map (t
);
719 else if (TREE_CODE_CLASS (code
) == tcc_type
)
721 TYPE_UID (t
) = next_type_uid
++;
722 /* The following is so that the debug code for
723 the copy is different from the original type.
724 The two statements usually duplicate each other
725 (because they clear fields of the same union),
726 but the optimizer should catch that. */
727 TYPE_SYMTAB_POINTER (t
) = 0;
728 TYPE_SYMTAB_ADDRESS (t
) = 0;
730 /* Do not copy the values cache. */
731 if (TYPE_CACHED_VALUES_P(t
))
733 TYPE_CACHED_VALUES_P (t
) = 0;
734 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
741 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
742 For example, this can copy a list made of TREE_LIST nodes. */
745 copy_list (tree list
)
753 head
= prev
= copy_node (list
);
754 next
= TREE_CHAIN (list
);
757 TREE_CHAIN (prev
) = copy_node (next
);
758 prev
= TREE_CHAIN (prev
);
759 next
= TREE_CHAIN (next
);
765 /* Create an INT_CST node with a LOW value sign extended. */
768 build_int_cst (tree type
, HOST_WIDE_INT low
)
770 /* Support legacy code. */
772 type
= integer_type_node
;
774 return build_int_cst_wide (type
, low
, low
< 0 ? -1 : 0);
777 /* Create an INT_CST node with a LOW value zero extended. */
780 build_int_cstu (tree type
, unsigned HOST_WIDE_INT low
)
782 return build_int_cst_wide (type
, low
, 0);
785 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
786 if it is negative. This function is similar to build_int_cst, but
787 the extra bits outside of the type precision are cleared. Constants
788 with these extra bits may confuse the fold so that it detects overflows
789 even in cases when they do not occur, and in general should be avoided.
790 We cannot however make this a default behavior of build_int_cst without
791 more intrusive changes, since there are parts of gcc that rely on the extra
792 precision of the integer constants. */
795 build_int_cst_type (tree type
, HOST_WIDE_INT low
)
797 unsigned HOST_WIDE_INT low1
;
802 fit_double_type (low
, low
< 0 ? -1 : 0, &low1
, &hi
, type
);
804 return build_int_cst_wide (type
, low1
, hi
);
807 /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated
808 and sign extended according to the value range of TYPE. */
811 build_int_cst_wide_type (tree type
,
812 unsigned HOST_WIDE_INT low
, HOST_WIDE_INT high
)
814 fit_double_type (low
, high
, &low
, &high
, type
);
815 return build_int_cst_wide (type
, low
, high
);
818 /* These are the hash table functions for the hash table of INTEGER_CST
819 nodes of a sizetype. */
821 /* Return the hash code code X, an INTEGER_CST. */
824 int_cst_hash_hash (const void *x
)
826 const_tree
const t
= (const_tree
) x
;
828 return (TREE_INT_CST_HIGH (t
) ^ TREE_INT_CST_LOW (t
)
829 ^ htab_hash_pointer (TREE_TYPE (t
)));
832 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
833 is the same as that given by *Y, which is the same. */
836 int_cst_hash_eq (const void *x
, const void *y
)
838 const_tree
const xt
= (const_tree
) x
;
839 const_tree
const yt
= (const_tree
) y
;
841 return (TREE_TYPE (xt
) == TREE_TYPE (yt
)
842 && TREE_INT_CST_HIGH (xt
) == TREE_INT_CST_HIGH (yt
)
843 && TREE_INT_CST_LOW (xt
) == TREE_INT_CST_LOW (yt
));
846 /* Create an INT_CST node of TYPE and value HI:LOW.
847 The returned node is always shared. For small integers we use a
848 per-type vector cache, for larger ones we use a single hash table. */
851 build_int_cst_wide (tree type
, unsigned HOST_WIDE_INT low
, HOST_WIDE_INT hi
)
859 switch (TREE_CODE (type
))
863 /* Cache NULL pointer. */
872 /* Cache false or true. */
880 if (TYPE_UNSIGNED (type
))
883 limit
= INTEGER_SHARE_LIMIT
;
884 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
890 limit
= INTEGER_SHARE_LIMIT
+ 1;
891 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
893 else if (hi
== -1 && low
== -(unsigned HOST_WIDE_INT
)1)
907 /* Look for it in the type's vector of small shared ints. */
908 if (!TYPE_CACHED_VALUES_P (type
))
910 TYPE_CACHED_VALUES_P (type
) = 1;
911 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
914 t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
);
917 /* Make sure no one is clobbering the shared constant. */
918 gcc_assert (TREE_TYPE (t
) == type
);
919 gcc_assert (TREE_INT_CST_LOW (t
) == low
);
920 gcc_assert (TREE_INT_CST_HIGH (t
) == hi
);
924 /* Create a new shared int. */
925 t
= make_node (INTEGER_CST
);
927 TREE_INT_CST_LOW (t
) = low
;
928 TREE_INT_CST_HIGH (t
) = hi
;
929 TREE_TYPE (t
) = type
;
931 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
936 /* Use the cache of larger shared ints. */
939 TREE_INT_CST_LOW (int_cst_node
) = low
;
940 TREE_INT_CST_HIGH (int_cst_node
) = hi
;
941 TREE_TYPE (int_cst_node
) = type
;
943 slot
= htab_find_slot (int_cst_hash_table
, int_cst_node
, INSERT
);
947 /* Insert this one into the hash table. */
950 /* Make a new node for next time round. */
951 int_cst_node
= make_node (INTEGER_CST
);
958 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
959 and the rest are zeros. */
962 build_low_bits_mask (tree type
, unsigned bits
)
964 unsigned HOST_WIDE_INT low
;
966 unsigned HOST_WIDE_INT all_ones
= ~(unsigned HOST_WIDE_INT
) 0;
968 gcc_assert (bits
<= TYPE_PRECISION (type
));
970 if (bits
== TYPE_PRECISION (type
)
971 && !TYPE_UNSIGNED (type
))
973 /* Sign extended all-ones mask. */
977 else if (bits
<= HOST_BITS_PER_WIDE_INT
)
979 low
= all_ones
>> (HOST_BITS_PER_WIDE_INT
- bits
);
984 bits
-= HOST_BITS_PER_WIDE_INT
;
986 high
= all_ones
>> (HOST_BITS_PER_WIDE_INT
- bits
);
989 return build_int_cst_wide (type
, low
, high
);
992 /* Checks that X is integer constant that can be expressed in (unsigned)
993 HOST_WIDE_INT without loss of precision. */
996 cst_and_fits_in_hwi (const_tree x
)
998 if (TREE_CODE (x
) != INTEGER_CST
)
1001 if (TYPE_PRECISION (TREE_TYPE (x
)) > HOST_BITS_PER_WIDE_INT
)
1004 return (TREE_INT_CST_HIGH (x
) == 0
1005 || TREE_INT_CST_HIGH (x
) == -1);
1008 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1009 are in a list pointed to by VALS. */
1012 build_vector (tree type
, tree vals
)
1014 tree v
= make_node (VECTOR_CST
);
1018 TREE_VECTOR_CST_ELTS (v
) = vals
;
1019 TREE_TYPE (v
) = type
;
1021 /* Iterate through elements and check for overflow. */
1022 for (link
= vals
; link
; link
= TREE_CHAIN (link
))
1024 tree value
= TREE_VALUE (link
);
1026 /* Don't crash if we get an address constant. */
1027 if (!CONSTANT_CLASS_P (value
))
1030 over
|= TREE_OVERFLOW (value
);
1033 TREE_OVERFLOW (v
) = over
;
1037 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1038 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1041 build_vector_from_ctor (tree type
, VEC(constructor_elt
,gc
) *v
)
1043 tree list
= NULL_TREE
;
1044 unsigned HOST_WIDE_INT idx
;
1047 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1048 list
= tree_cons (NULL_TREE
, value
, list
);
1049 return build_vector (type
, nreverse (list
));
1052 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1053 are in the VEC pointed to by VALS. */
1055 build_constructor (tree type
, VEC(constructor_elt
,gc
) *vals
)
1057 tree c
= make_node (CONSTRUCTOR
);
1058 TREE_TYPE (c
) = type
;
1059 CONSTRUCTOR_ELTS (c
) = vals
;
1063 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1066 build_constructor_single (tree type
, tree index
, tree value
)
1068 VEC(constructor_elt
,gc
) *v
;
1069 constructor_elt
*elt
;
1072 v
= VEC_alloc (constructor_elt
, gc
, 1);
1073 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
1077 t
= build_constructor (type
, v
);
1078 TREE_CONSTANT (t
) = TREE_CONSTANT (value
);
1083 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1084 are in a list pointed to by VALS. */
1086 build_constructor_from_list (tree type
, tree vals
)
1089 VEC(constructor_elt
,gc
) *v
= NULL
;
1090 bool constant_p
= true;
1094 v
= VEC_alloc (constructor_elt
, gc
, list_length (vals
));
1095 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
1097 constructor_elt
*elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
1098 val
= TREE_VALUE (t
);
1099 elt
->index
= TREE_PURPOSE (t
);
1101 if (!TREE_CONSTANT (val
))
1106 t
= build_constructor (type
, v
);
1107 TREE_CONSTANT (t
) = constant_p
;
1111 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1114 build_fixed (tree type
, FIXED_VALUE_TYPE f
)
1117 FIXED_VALUE_TYPE
*fp
;
1119 v
= make_node (FIXED_CST
);
1120 fp
= ggc_alloc (sizeof (FIXED_VALUE_TYPE
));
1121 memcpy (fp
, &f
, sizeof (FIXED_VALUE_TYPE
));
1123 TREE_TYPE (v
) = type
;
1124 TREE_FIXED_CST_PTR (v
) = fp
;
1128 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1131 build_real (tree type
, REAL_VALUE_TYPE d
)
1134 REAL_VALUE_TYPE
*dp
;
1137 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1138 Consider doing it via real_convert now. */
1140 v
= make_node (REAL_CST
);
1141 dp
= ggc_alloc (sizeof (REAL_VALUE_TYPE
));
1142 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
1144 TREE_TYPE (v
) = type
;
1145 TREE_REAL_CST_PTR (v
) = dp
;
1146 TREE_OVERFLOW (v
) = overflow
;
1150 /* Return a new REAL_CST node whose type is TYPE
1151 and whose value is the integer value of the INTEGER_CST node I. */
1154 real_value_from_int_cst (const_tree type
, const_tree i
)
1158 /* Clear all bits of the real value type so that we can later do
1159 bitwise comparisons to see if two values are the same. */
1160 memset (&d
, 0, sizeof d
);
1162 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
,
1163 TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
),
1164 TYPE_UNSIGNED (TREE_TYPE (i
)));
1168 /* Given a tree representing an integer constant I, return a tree
1169 representing the same value as a floating-point constant of type TYPE. */
1172 build_real_from_int_cst (tree type
, const_tree i
)
1175 int overflow
= TREE_OVERFLOW (i
);
1177 v
= build_real (type
, real_value_from_int_cst (type
, i
));
1179 TREE_OVERFLOW (v
) |= overflow
;
1183 /* Return a newly constructed STRING_CST node whose value is
1184 the LEN characters at STR.
1185 The TREE_TYPE is not initialized. */
1188 build_string (int len
, const char *str
)
1193 /* Do not waste bytes provided by padding of struct tree_string. */
1194 length
= len
+ offsetof (struct tree_string
, str
) + 1;
1196 #ifdef GATHER_STATISTICS
1197 tree_node_counts
[(int) c_kind
]++;
1198 tree_node_sizes
[(int) c_kind
] += length
;
1201 s
= ggc_alloc_tree (length
);
1203 memset (s
, 0, sizeof (struct tree_common
));
1204 TREE_SET_CODE (s
, STRING_CST
);
1205 TREE_CONSTANT (s
) = 1;
1206 TREE_INVARIANT (s
) = 1;
1207 TREE_STRING_LENGTH (s
) = len
;
1208 memcpy (s
->string
.str
, str
, len
);
1209 s
->string
.str
[len
] = '\0';
1214 /* Return a newly constructed COMPLEX_CST node whose value is
1215 specified by the real and imaginary parts REAL and IMAG.
1216 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1217 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1220 build_complex (tree type
, tree real
, tree imag
)
1222 tree t
= make_node (COMPLEX_CST
);
1224 TREE_REALPART (t
) = real
;
1225 TREE_IMAGPART (t
) = imag
;
1226 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
1227 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1231 /* Return a constant of arithmetic type TYPE which is the
1232 multiplicative identity of the set TYPE. */
1235 build_one_cst (tree type
)
1237 switch (TREE_CODE (type
))
1239 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1240 case POINTER_TYPE
: case REFERENCE_TYPE
:
1242 return build_int_cst (type
, 1);
1245 return build_real (type
, dconst1
);
1247 case FIXED_POINT_TYPE
:
1248 /* We can only generate 1 for accum types. */
1249 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
1250 return build_fixed (type
, FCONST1(TYPE_MODE (type
)));
1257 scalar
= build_one_cst (TREE_TYPE (type
));
1259 /* Create 'vect_cst_ = {cst,cst,...,cst}' */
1261 for (i
= TYPE_VECTOR_SUBPARTS (type
); --i
>= 0; )
1262 cst
= tree_cons (NULL_TREE
, scalar
, cst
);
1264 return build_vector (type
, cst
);
1268 return build_complex (type
,
1269 build_one_cst (TREE_TYPE (type
)),
1270 fold_convert (TREE_TYPE (type
), integer_zero_node
));
1277 /* Build a BINFO with LEN language slots. */
1280 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL
)
1283 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
1284 + VEC_embedded_size (tree
, base_binfos
));
1286 #ifdef GATHER_STATISTICS
1287 tree_node_counts
[(int) binfo_kind
]++;
1288 tree_node_sizes
[(int) binfo_kind
] += length
;
1291 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
1293 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
1295 TREE_SET_CODE (t
, TREE_BINFO
);
1297 VEC_embedded_init (tree
, BINFO_BASE_BINFOS (t
), base_binfos
);
1303 /* Build a newly constructed TREE_VEC node of length LEN. */
1306 make_tree_vec_stat (int len MEM_STAT_DECL
)
1309 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
1311 #ifdef GATHER_STATISTICS
1312 tree_node_counts
[(int) vec_kind
]++;
1313 tree_node_sizes
[(int) vec_kind
] += length
;
1316 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
1318 memset (t
, 0, length
);
1320 TREE_SET_CODE (t
, TREE_VEC
);
1321 TREE_VEC_LENGTH (t
) = len
;
1326 /* Return 1 if EXPR is the integer constant zero or a complex constant
1330 integer_zerop (const_tree expr
)
1334 return ((TREE_CODE (expr
) == INTEGER_CST
1335 && TREE_INT_CST_LOW (expr
) == 0
1336 && TREE_INT_CST_HIGH (expr
) == 0)
1337 || (TREE_CODE (expr
) == COMPLEX_CST
1338 && integer_zerop (TREE_REALPART (expr
))
1339 && integer_zerop (TREE_IMAGPART (expr
))));
1342 /* Return 1 if EXPR is the integer constant one or the corresponding
1343 complex constant. */
1346 integer_onep (const_tree expr
)
1350 return ((TREE_CODE (expr
) == INTEGER_CST
1351 && TREE_INT_CST_LOW (expr
) == 1
1352 && TREE_INT_CST_HIGH (expr
) == 0)
1353 || (TREE_CODE (expr
) == COMPLEX_CST
1354 && integer_onep (TREE_REALPART (expr
))
1355 && integer_zerop (TREE_IMAGPART (expr
))));
1358 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1359 it contains. Likewise for the corresponding complex constant. */
1362 integer_all_onesp (const_tree expr
)
1369 if (TREE_CODE (expr
) == COMPLEX_CST
1370 && integer_all_onesp (TREE_REALPART (expr
))
1371 && integer_zerop (TREE_IMAGPART (expr
)))
1374 else if (TREE_CODE (expr
) != INTEGER_CST
)
1377 uns
= TYPE_UNSIGNED (TREE_TYPE (expr
));
1378 if (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1379 && TREE_INT_CST_HIGH (expr
) == -1)
1384 /* Note that using TYPE_PRECISION here is wrong. We care about the
1385 actual bits, not the (arbitrary) range of the type. */
1386 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr
)));
1387 if (prec
>= HOST_BITS_PER_WIDE_INT
)
1389 HOST_WIDE_INT high_value
;
1392 shift_amount
= prec
- HOST_BITS_PER_WIDE_INT
;
1394 /* Can not handle precisions greater than twice the host int size. */
1395 gcc_assert (shift_amount
<= HOST_BITS_PER_WIDE_INT
);
1396 if (shift_amount
== HOST_BITS_PER_WIDE_INT
)
1397 /* Shifting by the host word size is undefined according to the ANSI
1398 standard, so we must handle this as a special case. */
1401 high_value
= ((HOST_WIDE_INT
) 1 << shift_amount
) - 1;
1403 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1404 && TREE_INT_CST_HIGH (expr
) == high_value
);
1407 return TREE_INT_CST_LOW (expr
) == ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
1410 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1414 integer_pow2p (const_tree expr
)
1417 HOST_WIDE_INT high
, low
;
1421 if (TREE_CODE (expr
) == COMPLEX_CST
1422 && integer_pow2p (TREE_REALPART (expr
))
1423 && integer_zerop (TREE_IMAGPART (expr
)))
1426 if (TREE_CODE (expr
) != INTEGER_CST
)
1429 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1430 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1431 high
= TREE_INT_CST_HIGH (expr
);
1432 low
= TREE_INT_CST_LOW (expr
);
1434 /* First clear all bits that are beyond the type's precision in case
1435 we've been sign extended. */
1437 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1439 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1440 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1444 if (prec
< HOST_BITS_PER_WIDE_INT
)
1445 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1448 if (high
== 0 && low
== 0)
1451 return ((high
== 0 && (low
& (low
- 1)) == 0)
1452 || (low
== 0 && (high
& (high
- 1)) == 0));
1455 /* Return 1 if EXPR is an integer constant other than zero or a
1456 complex constant other than zero. */
1459 integer_nonzerop (const_tree expr
)
1463 return ((TREE_CODE (expr
) == INTEGER_CST
1464 && (TREE_INT_CST_LOW (expr
) != 0
1465 || TREE_INT_CST_HIGH (expr
) != 0))
1466 || (TREE_CODE (expr
) == COMPLEX_CST
1467 && (integer_nonzerop (TREE_REALPART (expr
))
1468 || integer_nonzerop (TREE_IMAGPART (expr
)))));
1471 /* Return 1 if EXPR is the fixed-point constant zero. */
1474 fixed_zerop (const_tree expr
)
1476 return (TREE_CODE (expr
) == FIXED_CST
1477 && double_int_zero_p (TREE_FIXED_CST (expr
).data
));
1480 /* Return the power of two represented by a tree node known to be a
1484 tree_log2 (const_tree expr
)
1487 HOST_WIDE_INT high
, low
;
1491 if (TREE_CODE (expr
) == COMPLEX_CST
)
1492 return tree_log2 (TREE_REALPART (expr
));
1494 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1495 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1497 high
= TREE_INT_CST_HIGH (expr
);
1498 low
= TREE_INT_CST_LOW (expr
);
1500 /* First clear all bits that are beyond the type's precision in case
1501 we've been sign extended. */
1503 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1505 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1506 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1510 if (prec
< HOST_BITS_PER_WIDE_INT
)
1511 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1514 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ exact_log2 (high
)
1515 : exact_log2 (low
));
1518 /* Similar, but return the largest integer Y such that 2 ** Y is less
1519 than or equal to EXPR. */
1522 tree_floor_log2 (const_tree expr
)
1525 HOST_WIDE_INT high
, low
;
1529 if (TREE_CODE (expr
) == COMPLEX_CST
)
1530 return tree_log2 (TREE_REALPART (expr
));
1532 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1533 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1535 high
= TREE_INT_CST_HIGH (expr
);
1536 low
= TREE_INT_CST_LOW (expr
);
1538 /* First clear all bits that are beyond the type's precision in case
1539 we've been sign extended. Ignore if type's precision hasn't been set
1540 since what we are doing is setting it. */
1542 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
|| prec
== 0)
1544 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1545 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1549 if (prec
< HOST_BITS_PER_WIDE_INT
)
1550 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1553 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ floor_log2 (high
)
1554 : floor_log2 (low
));
1557 /* Return 1 if EXPR is the real constant zero. */
1560 real_zerop (const_tree expr
)
1564 return ((TREE_CODE (expr
) == REAL_CST
1565 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
))
1566 || (TREE_CODE (expr
) == COMPLEX_CST
1567 && real_zerop (TREE_REALPART (expr
))
1568 && real_zerop (TREE_IMAGPART (expr
))));
1571 /* Return 1 if EXPR is the real constant one in real or complex form. */
1574 real_onep (const_tree expr
)
1578 return ((TREE_CODE (expr
) == REAL_CST
1579 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
))
1580 || (TREE_CODE (expr
) == COMPLEX_CST
1581 && real_onep (TREE_REALPART (expr
))
1582 && real_zerop (TREE_IMAGPART (expr
))));
1585 /* Return 1 if EXPR is the real constant two. */
1588 real_twop (const_tree expr
)
1592 return ((TREE_CODE (expr
) == REAL_CST
1593 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst2
))
1594 || (TREE_CODE (expr
) == COMPLEX_CST
1595 && real_twop (TREE_REALPART (expr
))
1596 && real_zerop (TREE_IMAGPART (expr
))));
1599 /* Return 1 if EXPR is the real constant minus one. */
1602 real_minus_onep (const_tree expr
)
1606 return ((TREE_CODE (expr
) == REAL_CST
1607 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconstm1
))
1608 || (TREE_CODE (expr
) == COMPLEX_CST
1609 && real_minus_onep (TREE_REALPART (expr
))
1610 && real_zerop (TREE_IMAGPART (expr
))));
1613 /* Nonzero if EXP is a constant or a cast of a constant. */
1616 really_constant_p (const_tree exp
)
1618 /* This is not quite the same as STRIP_NOPS. It does more. */
1619 while (TREE_CODE (exp
) == NOP_EXPR
1620 || TREE_CODE (exp
) == CONVERT_EXPR
1621 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
1622 exp
= TREE_OPERAND (exp
, 0);
1623 return TREE_CONSTANT (exp
);
1626 /* Return first list element whose TREE_VALUE is ELEM.
1627 Return 0 if ELEM is not in LIST. */
1630 value_member (tree elem
, tree list
)
1634 if (elem
== TREE_VALUE (list
))
1636 list
= TREE_CHAIN (list
);
1641 /* Return first list element whose TREE_PURPOSE is ELEM.
1642 Return 0 if ELEM is not in LIST. */
1645 purpose_member (const_tree elem
, tree list
)
1649 if (elem
== TREE_PURPOSE (list
))
1651 list
= TREE_CHAIN (list
);
1656 /* Return nonzero if ELEM is part of the chain CHAIN. */
1659 chain_member (const_tree elem
, const_tree chain
)
1665 chain
= TREE_CHAIN (chain
);
1671 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1672 We expect a null pointer to mark the end of the chain.
1673 This is the Lisp primitive `length'. */
1676 list_length (const_tree t
)
1679 #ifdef ENABLE_TREE_CHECKING
1687 #ifdef ENABLE_TREE_CHECKING
1690 gcc_assert (p
!= q
);
1698 /* Returns the number of FIELD_DECLs in TYPE. */
1701 fields_length (const_tree type
)
1703 tree t
= TYPE_FIELDS (type
);
1706 for (; t
; t
= TREE_CHAIN (t
))
1707 if (TREE_CODE (t
) == FIELD_DECL
)
1713 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1714 by modifying the last node in chain 1 to point to chain 2.
1715 This is the Lisp primitive `nconc'. */
1718 chainon (tree op1
, tree op2
)
1727 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
1729 TREE_CHAIN (t1
) = op2
;
1731 #ifdef ENABLE_TREE_CHECKING
1734 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
1735 gcc_assert (t2
!= t1
);
1742 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1745 tree_last (tree chain
)
1749 while ((next
= TREE_CHAIN (chain
)))
1754 /* Reverse the order of elements in the chain T,
1755 and return the new head of the chain (old last element). */
1760 tree prev
= 0, decl
, next
;
1761 for (decl
= t
; decl
; decl
= next
)
1763 next
= TREE_CHAIN (decl
);
1764 TREE_CHAIN (decl
) = prev
;
1770 /* Return a newly created TREE_LIST node whose
1771 purpose and value fields are PARM and VALUE. */
1774 build_tree_list_stat (tree parm
, tree value MEM_STAT_DECL
)
1776 tree t
= make_node_stat (TREE_LIST PASS_MEM_STAT
);
1777 TREE_PURPOSE (t
) = parm
;
1778 TREE_VALUE (t
) = value
;
1782 /* Return a newly created TREE_LIST node whose
1783 purpose and value fields are PURPOSE and VALUE
1784 and whose TREE_CHAIN is CHAIN. */
1787 tree_cons_stat (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
1791 node
= ggc_alloc_zone_pass_stat (sizeof (struct tree_list
), &tree_zone
);
1793 memset (node
, 0, sizeof (struct tree_common
));
1795 #ifdef GATHER_STATISTICS
1796 tree_node_counts
[(int) x_kind
]++;
1797 tree_node_sizes
[(int) x_kind
] += sizeof (struct tree_list
);
1800 TREE_SET_CODE (node
, TREE_LIST
);
1801 TREE_CHAIN (node
) = chain
;
1802 TREE_PURPOSE (node
) = purpose
;
1803 TREE_VALUE (node
) = value
;
1808 /* Return the size nominally occupied by an object of type TYPE
1809 when it resides in memory. The value is measured in units of bytes,
1810 and its data type is that normally used for type sizes
1811 (which is the first type created by make_signed_type or
1812 make_unsigned_type). */
1815 size_in_bytes (const_tree type
)
1819 if (type
== error_mark_node
)
1820 return integer_zero_node
;
1822 type
= TYPE_MAIN_VARIANT (type
);
1823 t
= TYPE_SIZE_UNIT (type
);
1827 lang_hooks
.types
.incomplete_type_error (NULL_TREE
, type
);
1828 return size_zero_node
;
1834 /* Return the size of TYPE (in bytes) as a wide integer
1835 or return -1 if the size can vary or is larger than an integer. */
1838 int_size_in_bytes (const_tree type
)
1842 if (type
== error_mark_node
)
1845 type
= TYPE_MAIN_VARIANT (type
);
1846 t
= TYPE_SIZE_UNIT (type
);
1848 || TREE_CODE (t
) != INTEGER_CST
1849 || TREE_INT_CST_HIGH (t
) != 0
1850 /* If the result would appear negative, it's too big to represent. */
1851 || (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0)
1854 return TREE_INT_CST_LOW (t
);
1857 /* Return the maximum size of TYPE (in bytes) as a wide integer
1858 or return -1 if the size can vary or is larger than an integer. */
1861 max_int_size_in_bytes (const_tree type
)
1863 HOST_WIDE_INT size
= -1;
1866 /* If this is an array type, check for a possible MAX_SIZE attached. */
1868 if (TREE_CODE (type
) == ARRAY_TYPE
)
1870 size_tree
= TYPE_ARRAY_MAX_SIZE (type
);
1872 if (size_tree
&& host_integerp (size_tree
, 1))
1873 size
= tree_low_cst (size_tree
, 1);
1876 /* If we still haven't been able to get a size, see if the language
1877 can compute a maximum size. */
1881 size_tree
= lang_hooks
.types
.max_size (type
);
1883 if (size_tree
&& host_integerp (size_tree
, 1))
1884 size
= tree_low_cst (size_tree
, 1);
1890 /* Return the bit position of FIELD, in bits from the start of the record.
1891 This is a tree of type bitsizetype. */
1894 bit_position (const_tree field
)
1896 return bit_from_pos (DECL_FIELD_OFFSET (field
),
1897 DECL_FIELD_BIT_OFFSET (field
));
1900 /* Likewise, but return as an integer. It must be representable in
1901 that way (since it could be a signed value, we don't have the
1902 option of returning -1 like int_size_in_byte can. */
1905 int_bit_position (const_tree field
)
1907 return tree_low_cst (bit_position (field
), 0);
1910 /* Return the byte position of FIELD, in bytes from the start of the record.
1911 This is a tree of type sizetype. */
1914 byte_position (const_tree field
)
1916 return byte_from_pos (DECL_FIELD_OFFSET (field
),
1917 DECL_FIELD_BIT_OFFSET (field
));
1920 /* Likewise, but return as an integer. It must be representable in
1921 that way (since it could be a signed value, we don't have the
1922 option of returning -1 like int_size_in_byte can. */
1925 int_byte_position (const_tree field
)
1927 return tree_low_cst (byte_position (field
), 0);
1930 /* Return the strictest alignment, in bits, that T is known to have. */
1933 expr_align (const_tree t
)
1935 unsigned int align0
, align1
;
1937 switch (TREE_CODE (t
))
1939 case NOP_EXPR
: case CONVERT_EXPR
: case NON_LVALUE_EXPR
:
1940 /* If we have conversions, we know that the alignment of the
1941 object must meet each of the alignments of the types. */
1942 align0
= expr_align (TREE_OPERAND (t
, 0));
1943 align1
= TYPE_ALIGN (TREE_TYPE (t
));
1944 return MAX (align0
, align1
);
1946 case GIMPLE_MODIFY_STMT
:
1947 /* We should never ask for the alignment of a gimple statement. */
1950 case SAVE_EXPR
: case COMPOUND_EXPR
: case MODIFY_EXPR
:
1951 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
1952 case CLEANUP_POINT_EXPR
:
1953 /* These don't change the alignment of an object. */
1954 return expr_align (TREE_OPERAND (t
, 0));
1957 /* The best we can do is say that the alignment is the least aligned
1959 align0
= expr_align (TREE_OPERAND (t
, 1));
1960 align1
= expr_align (TREE_OPERAND (t
, 2));
1961 return MIN (align0
, align1
);
1963 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
1964 meaningfully, it's always 1. */
1965 case LABEL_DECL
: case CONST_DECL
:
1966 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
1968 gcc_assert (DECL_ALIGN (t
) != 0);
1969 return DECL_ALIGN (t
);
1975 /* Otherwise take the alignment from that of the type. */
1976 return TYPE_ALIGN (TREE_TYPE (t
));
1979 /* Return, as a tree node, the number of elements for TYPE (which is an
1980 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1983 array_type_nelts (const_tree type
)
1985 tree index_type
, min
, max
;
1987 /* If they did it with unspecified bounds, then we should have already
1988 given an error about it before we got here. */
1989 if (! TYPE_DOMAIN (type
))
1990 return error_mark_node
;
1992 index_type
= TYPE_DOMAIN (type
);
1993 min
= TYPE_MIN_VALUE (index_type
);
1994 max
= TYPE_MAX_VALUE (index_type
);
1996 return (integer_zerop (min
)
1998 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
2001 /* If arg is static -- a reference to an object in static storage -- then
2002 return the object. This is not the same as the C meaning of `static'.
2003 If arg isn't static, return NULL. */
2008 switch (TREE_CODE (arg
))
2011 /* Nested functions are static, even though taking their address will
2012 involve a trampoline as we unnest the nested function and create
2013 the trampoline on the tree level. */
2017 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2018 && ! DECL_THREAD_LOCAL_P (arg
)
2019 && ! DECL_DLLIMPORT_P (arg
)
2023 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2027 return TREE_STATIC (arg
) ? arg
: NULL
;
2034 /* If the thing being referenced is not a field, then it is
2035 something language specific. */
2036 if (TREE_CODE (TREE_OPERAND (arg
, 1)) != FIELD_DECL
)
2037 return (*lang_hooks
.staticp
) (arg
);
2039 /* If we are referencing a bitfield, we can't evaluate an
2040 ADDR_EXPR at compile time and so it isn't a constant. */
2041 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
2044 return staticp (TREE_OPERAND (arg
, 0));
2049 case MISALIGNED_INDIRECT_REF
:
2050 case ALIGN_INDIRECT_REF
:
2052 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
2055 case ARRAY_RANGE_REF
:
2056 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
2057 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
2058 return staticp (TREE_OPERAND (arg
, 0));
2063 if ((unsigned int) TREE_CODE (arg
)
2064 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
2065 return lang_hooks
.staticp (arg
);
2071 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2072 Do this to any expression which may be used in more than one place,
2073 but must be evaluated only once.
2075 Normally, expand_expr would reevaluate the expression each time.
2076 Calling save_expr produces something that is evaluated and recorded
2077 the first time expand_expr is called on it. Subsequent calls to
2078 expand_expr just reuse the recorded value.
2080 The call to expand_expr that generates code that actually computes
2081 the value is the first call *at compile time*. Subsequent calls
2082 *at compile time* generate code to use the saved value.
2083 This produces correct result provided that *at run time* control
2084 always flows through the insns made by the first expand_expr
2085 before reaching the other places where the save_expr was evaluated.
2086 You, the caller of save_expr, must make sure this is so.
2088 Constants, and certain read-only nodes, are returned with no
2089 SAVE_EXPR because that is safe. Expressions containing placeholders
2090 are not touched; see tree.def for an explanation of what these
2094 save_expr (tree expr
)
2096 tree t
= fold (expr
);
2099 /* If the tree evaluates to a constant, then we don't want to hide that
2100 fact (i.e. this allows further folding, and direct checks for constants).
2101 However, a read-only object that has side effects cannot be bypassed.
2102 Since it is no problem to reevaluate literals, we just return the
2104 inner
= skip_simple_arithmetic (t
);
2106 if (TREE_INVARIANT (inner
)
2107 || (TREE_READONLY (inner
) && ! TREE_SIDE_EFFECTS (inner
))
2108 || TREE_CODE (inner
) == SAVE_EXPR
2109 || TREE_CODE (inner
) == ERROR_MARK
)
2112 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2113 it means that the size or offset of some field of an object depends on
2114 the value within another field.
2116 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2117 and some variable since it would then need to be both evaluated once and
2118 evaluated more than once. Front-ends must assure this case cannot
2119 happen by surrounding any such subexpressions in their own SAVE_EXPR
2120 and forcing evaluation at the proper time. */
2121 if (contains_placeholder_p (inner
))
2124 t
= build1 (SAVE_EXPR
, TREE_TYPE (expr
), t
);
2126 /* This expression might be placed ahead of a jump to ensure that the
2127 value was computed on both sides of the jump. So make sure it isn't
2128 eliminated as dead. */
2129 TREE_SIDE_EFFECTS (t
) = 1;
2130 TREE_INVARIANT (t
) = 1;
2134 /* Look inside EXPR and into any simple arithmetic operations. Return
2135 the innermost non-arithmetic node. */
2138 skip_simple_arithmetic (tree expr
)
2142 /* We don't care about whether this can be used as an lvalue in this
2144 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
2145 expr
= TREE_OPERAND (expr
, 0);
2147 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2148 a constant, it will be more efficient to not make another SAVE_EXPR since
2149 it will allow better simplification and GCSE will be able to merge the
2150 computations if they actually occur. */
2154 if (UNARY_CLASS_P (inner
))
2155 inner
= TREE_OPERAND (inner
, 0);
2156 else if (BINARY_CLASS_P (inner
))
2158 if (TREE_INVARIANT (TREE_OPERAND (inner
, 1)))
2159 inner
= TREE_OPERAND (inner
, 0);
2160 else if (TREE_INVARIANT (TREE_OPERAND (inner
, 0)))
2161 inner
= TREE_OPERAND (inner
, 1);
2172 /* Return which tree structure is used by T. */
2174 enum tree_node_structure_enum
2175 tree_node_structure (const_tree t
)
2177 const enum tree_code code
= TREE_CODE (t
);
2179 switch (TREE_CODE_CLASS (code
))
2181 case tcc_declaration
:
2186 return TS_FIELD_DECL
;
2188 return TS_PARM_DECL
;
2192 return TS_LABEL_DECL
;
2194 return TS_RESULT_DECL
;
2196 return TS_CONST_DECL
;
2198 return TS_TYPE_DECL
;
2200 return TS_FUNCTION_DECL
;
2201 case SYMBOL_MEMORY_TAG
:
2202 case NAME_MEMORY_TAG
:
2203 case STRUCT_FIELD_TAG
:
2204 case MEMORY_PARTITION_TAG
:
2205 return TS_MEMORY_TAG
;
2207 return TS_DECL_NON_COMMON
;
2213 case tcc_comparison
:
2216 case tcc_expression
:
2220 case tcc_gimple_stmt
:
2221 return TS_GIMPLE_STATEMENT
;
2222 default: /* tcc_constant and tcc_exceptional */
2227 /* tcc_constant cases. */
2228 case INTEGER_CST
: return TS_INT_CST
;
2229 case REAL_CST
: return TS_REAL_CST
;
2230 case FIXED_CST
: return TS_FIXED_CST
;
2231 case COMPLEX_CST
: return TS_COMPLEX
;
2232 case VECTOR_CST
: return TS_VECTOR
;
2233 case STRING_CST
: return TS_STRING
;
2234 /* tcc_exceptional cases. */
2235 /* FIXME tuples: eventually this should be TS_BASE. For now, nothing
2237 case ERROR_MARK
: return TS_COMMON
;
2238 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
2239 case TREE_LIST
: return TS_LIST
;
2240 case TREE_VEC
: return TS_VEC
;
2241 case PHI_NODE
: return TS_PHI_NODE
;
2242 case SSA_NAME
: return TS_SSA_NAME
;
2243 case PLACEHOLDER_EXPR
: return TS_COMMON
;
2244 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
2245 case BLOCK
: return TS_BLOCK
;
2246 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
2247 case TREE_BINFO
: return TS_BINFO
;
2248 case VALUE_HANDLE
: return TS_VALUE_HANDLE
;
2249 case OMP_CLAUSE
: return TS_OMP_CLAUSE
;
2256 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2257 or offset that depends on a field within a record. */
2260 contains_placeholder_p (const_tree exp
)
2262 enum tree_code code
;
2267 code
= TREE_CODE (exp
);
2268 if (code
== PLACEHOLDER_EXPR
)
2271 switch (TREE_CODE_CLASS (code
))
2274 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2275 position computations since they will be converted into a
2276 WITH_RECORD_EXPR involving the reference, which will assume
2277 here will be valid. */
2278 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2280 case tcc_exceptional
:
2281 if (code
== TREE_LIST
)
2282 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
2283 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
2288 case tcc_comparison
:
2289 case tcc_expression
:
2293 /* Ignoring the first operand isn't quite right, but works best. */
2294 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
2297 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2298 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
2299 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
2305 switch (TREE_CODE_LENGTH (code
))
2308 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2310 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2311 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
2322 const_call_expr_arg_iterator iter
;
2323 FOR_EACH_CONST_CALL_EXPR_ARG (arg
, iter
, exp
)
2324 if (CONTAINS_PLACEHOLDER_P (arg
))
2338 /* Return true if any part of the computation of TYPE involves a
2339 PLACEHOLDER_EXPR. This includes size, bounds, qualifiers
2340 (for QUAL_UNION_TYPE) and field positions. */
2343 type_contains_placeholder_1 (const_tree type
)
2345 /* If the size contains a placeholder or the parent type (component type in
2346 the case of arrays) type involves a placeholder, this type does. */
2347 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
2348 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
2349 || (TREE_TYPE (type
) != 0
2350 && type_contains_placeholder_p (TREE_TYPE (type
))))
2353 /* Now do type-specific checks. Note that the last part of the check above
2354 greatly limits what we have to do below. */
2355 switch (TREE_CODE (type
))
2363 case REFERENCE_TYPE
:
2371 case FIXED_POINT_TYPE
:
2372 /* Here we just check the bounds. */
2373 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
2374 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
2377 /* We're already checked the component type (TREE_TYPE), so just check
2379 return type_contains_placeholder_p (TYPE_DOMAIN (type
));
2383 case QUAL_UNION_TYPE
:
2387 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2388 if (TREE_CODE (field
) == FIELD_DECL
2389 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
2390 || (TREE_CODE (type
) == QUAL_UNION_TYPE
2391 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
2392 || type_contains_placeholder_p (TREE_TYPE (field
))))
2404 type_contains_placeholder_p (tree type
)
2408 /* If the contains_placeholder_bits field has been initialized,
2409 then we know the answer. */
2410 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
2411 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
2413 /* Indicate that we've seen this type node, and the answer is false.
2414 This is what we want to return if we run into recursion via fields. */
2415 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
2417 /* Compute the real value. */
2418 result
= type_contains_placeholder_1 (type
);
2420 /* Store the real value. */
2421 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
2426 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2427 return a tree with all occurrences of references to F in a
2428 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2429 contains only arithmetic expressions or a CALL_EXPR with a
2430 PLACEHOLDER_EXPR occurring only in its arglist. */
2433 substitute_in_expr (tree exp
, tree f
, tree r
)
2435 enum tree_code code
= TREE_CODE (exp
);
2436 tree op0
, op1
, op2
, op3
;
2440 /* We handle TREE_LIST and COMPONENT_REF separately. */
2441 if (code
== TREE_LIST
)
2443 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
2444 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
2445 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
2448 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
2450 else if (code
== COMPONENT_REF
)
2452 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2453 and it is the right field, replace it with R. */
2454 for (inner
= TREE_OPERAND (exp
, 0);
2455 REFERENCE_CLASS_P (inner
);
2456 inner
= TREE_OPERAND (inner
, 0))
2458 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
2459 && TREE_OPERAND (exp
, 1) == f
)
2462 /* If this expression hasn't been completed let, leave it alone. */
2463 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& TREE_TYPE (inner
) == 0)
2466 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2467 if (op0
== TREE_OPERAND (exp
, 0))
2470 new = fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
),
2471 op0
, TREE_OPERAND (exp
, 1), NULL_TREE
);
2474 switch (TREE_CODE_CLASS (code
))
2477 case tcc_declaration
:
2480 case tcc_exceptional
:
2483 case tcc_comparison
:
2484 case tcc_expression
:
2486 switch (TREE_CODE_LENGTH (code
))
2492 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2493 if (op0
== TREE_OPERAND (exp
, 0))
2496 new = fold_build1 (code
, TREE_TYPE (exp
), op0
);
2500 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2501 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2503 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
2506 new = fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
2510 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2511 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2512 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
2514 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2515 && op2
== TREE_OPERAND (exp
, 2))
2518 new = fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
2522 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2523 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2524 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
2525 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
2527 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2528 && op2
== TREE_OPERAND (exp
, 2)
2529 && op3
== TREE_OPERAND (exp
, 3))
2532 new = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
2542 tree copy
= NULL_TREE
;
2545 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
2547 tree op
= TREE_OPERAND (exp
, i
);
2548 tree newop
= SUBSTITUTE_IN_EXPR (op
, f
, r
);
2551 copy
= copy_node (exp
);
2552 TREE_OPERAND (copy
, i
) = newop
;
2566 TREE_READONLY (new) = TREE_READONLY (exp
);
2570 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
2571 for it within OBJ, a tree that is an object or a chain of references. */
2574 substitute_placeholder_in_expr (tree exp
, tree obj
)
2576 enum tree_code code
= TREE_CODE (exp
);
2577 tree op0
, op1
, op2
, op3
;
2579 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
2580 in the chain of OBJ. */
2581 if (code
== PLACEHOLDER_EXPR
)
2583 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
2586 for (elt
= obj
; elt
!= 0;
2587 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
2588 || TREE_CODE (elt
) == COND_EXPR
)
2589 ? TREE_OPERAND (elt
, 1)
2590 : (REFERENCE_CLASS_P (elt
)
2591 || UNARY_CLASS_P (elt
)
2592 || BINARY_CLASS_P (elt
)
2593 || VL_EXP_CLASS_P (elt
)
2594 || EXPRESSION_CLASS_P (elt
))
2595 ? TREE_OPERAND (elt
, 0) : 0))
2596 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
2599 for (elt
= obj
; elt
!= 0;
2600 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
2601 || TREE_CODE (elt
) == COND_EXPR
)
2602 ? TREE_OPERAND (elt
, 1)
2603 : (REFERENCE_CLASS_P (elt
)
2604 || UNARY_CLASS_P (elt
)
2605 || BINARY_CLASS_P (elt
)
2606 || VL_EXP_CLASS_P (elt
)
2607 || EXPRESSION_CLASS_P (elt
))
2608 ? TREE_OPERAND (elt
, 0) : 0))
2609 if (POINTER_TYPE_P (TREE_TYPE (elt
))
2610 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
2612 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
2614 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2615 survives until RTL generation, there will be an error. */
2619 /* TREE_LIST is special because we need to look at TREE_VALUE
2620 and TREE_CHAIN, not TREE_OPERANDS. */
2621 else if (code
== TREE_LIST
)
2623 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
2624 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
2625 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
2628 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
2631 switch (TREE_CODE_CLASS (code
))
2634 case tcc_declaration
:
2637 case tcc_exceptional
:
2640 case tcc_comparison
:
2641 case tcc_expression
:
2644 switch (TREE_CODE_LENGTH (code
))
2650 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2651 if (op0
== TREE_OPERAND (exp
, 0))
2654 return fold_build1 (code
, TREE_TYPE (exp
), op0
);
2657 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2658 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2660 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
2663 return fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
2666 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2667 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2668 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
2670 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2671 && op2
== TREE_OPERAND (exp
, 2))
2674 return fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
2677 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2678 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2679 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
2680 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
2682 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2683 && op2
== TREE_OPERAND (exp
, 2)
2684 && op3
== TREE_OPERAND (exp
, 3))
2687 return fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
2696 tree copy
= NULL_TREE
;
2698 int n
= TREE_OPERAND_LENGTH (exp
);
2699 for (i
= 1; i
< n
; i
++)
2701 tree op
= TREE_OPERAND (exp
, i
);
2702 tree newop
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (op
, obj
);
2706 copy
= copy_node (exp
);
2707 TREE_OPERAND (copy
, i
) = newop
;
2721 /* Stabilize a reference so that we can use it any number of times
2722 without causing its operands to be evaluated more than once.
2723 Returns the stabilized reference. This works by means of save_expr,
2724 so see the caveats in the comments about save_expr.
2726 Also allows conversion expressions whose operands are references.
2727 Any other kind of expression is returned unchanged. */
2730 stabilize_reference (tree ref
)
2733 enum tree_code code
= TREE_CODE (ref
);
2740 /* No action is needed in this case. */
2746 case FIX_TRUNC_EXPR
:
2747 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
2751 result
= build_nt (INDIRECT_REF
,
2752 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
2756 result
= build_nt (COMPONENT_REF
,
2757 stabilize_reference (TREE_OPERAND (ref
, 0)),
2758 TREE_OPERAND (ref
, 1), NULL_TREE
);
2762 result
= build_nt (BIT_FIELD_REF
,
2763 stabilize_reference (TREE_OPERAND (ref
, 0)),
2764 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2765 stabilize_reference_1 (TREE_OPERAND (ref
, 2)));
2769 result
= build_nt (ARRAY_REF
,
2770 stabilize_reference (TREE_OPERAND (ref
, 0)),
2771 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2772 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
2775 case ARRAY_RANGE_REF
:
2776 result
= build_nt (ARRAY_RANGE_REF
,
2777 stabilize_reference (TREE_OPERAND (ref
, 0)),
2778 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2779 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
2783 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2784 it wouldn't be ignored. This matters when dealing with
2786 return stabilize_reference_1 (ref
);
2788 /* If arg isn't a kind of lvalue we recognize, make no change.
2789 Caller should recognize the error for an invalid lvalue. */
2794 return error_mark_node
;
2797 TREE_TYPE (result
) = TREE_TYPE (ref
);
2798 TREE_READONLY (result
) = TREE_READONLY (ref
);
2799 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
2800 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
2805 /* Subroutine of stabilize_reference; this is called for subtrees of
2806 references. Any expression with side-effects must be put in a SAVE_EXPR
2807 to ensure that it is only evaluated once.
2809 We don't put SAVE_EXPR nodes around everything, because assigning very
2810 simple expressions to temporaries causes us to miss good opportunities
2811 for optimizations. Among other things, the opportunity to fold in the
2812 addition of a constant into an addressing mode often gets lost, e.g.
2813 "y[i+1] += x;". In general, we take the approach that we should not make
2814 an assignment unless we are forced into it - i.e., that any non-side effect
2815 operator should be allowed, and that cse should take care of coalescing
2816 multiple utterances of the same expression should that prove fruitful. */
2819 stabilize_reference_1 (tree e
)
2822 enum tree_code code
= TREE_CODE (e
);
2824 /* We cannot ignore const expressions because it might be a reference
2825 to a const array but whose index contains side-effects. But we can
2826 ignore things that are actual constant or that already have been
2827 handled by this function. */
2829 if (TREE_INVARIANT (e
))
2832 switch (TREE_CODE_CLASS (code
))
2834 case tcc_exceptional
:
2836 case tcc_declaration
:
2837 case tcc_comparison
:
2839 case tcc_expression
:
2842 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2843 so that it will only be evaluated once. */
2844 /* The reference (r) and comparison (<) classes could be handled as
2845 below, but it is generally faster to only evaluate them once. */
2846 if (TREE_SIDE_EFFECTS (e
))
2847 return save_expr (e
);
2851 /* Constants need no processing. In fact, we should never reach
2856 /* Division is slow and tends to be compiled with jumps,
2857 especially the division by powers of 2 that is often
2858 found inside of an array reference. So do it just once. */
2859 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
2860 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
2861 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
2862 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
2863 return save_expr (e
);
2864 /* Recursively stabilize each operand. */
2865 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
2866 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
2870 /* Recursively stabilize each operand. */
2871 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
2878 TREE_TYPE (result
) = TREE_TYPE (e
);
2879 TREE_READONLY (result
) = TREE_READONLY (e
);
2880 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
2881 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
2882 TREE_INVARIANT (result
) = 1;
2887 /* Low-level constructors for expressions. */
2889 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
2890 TREE_INVARIANT, and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
2893 recompute_tree_invariant_for_addr_expr (tree t
)
2896 bool tc
= true, ti
= true, se
= false;
2898 /* We started out assuming this address is both invariant and constant, but
2899 does not have side effects. Now go down any handled components and see if
2900 any of them involve offsets that are either non-constant or non-invariant.
2901 Also check for side-effects.
2903 ??? Note that this code makes no attempt to deal with the case where
2904 taking the address of something causes a copy due to misalignment. */
2906 #define UPDATE_TITCSE(NODE) \
2907 do { tree _node = (NODE); \
2908 if (_node && !TREE_INVARIANT (_node)) ti = false; \
2909 if (_node && !TREE_CONSTANT (_node)) tc = false; \
2910 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
2912 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
2913 node
= TREE_OPERAND (node
, 0))
2915 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
2916 array reference (probably made temporarily by the G++ front end),
2917 so ignore all the operands. */
2918 if ((TREE_CODE (node
) == ARRAY_REF
2919 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
2920 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
2922 UPDATE_TITCSE (TREE_OPERAND (node
, 1));
2923 if (TREE_OPERAND (node
, 2))
2924 UPDATE_TITCSE (TREE_OPERAND (node
, 2));
2925 if (TREE_OPERAND (node
, 3))
2926 UPDATE_TITCSE (TREE_OPERAND (node
, 3));
2928 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
2929 FIELD_DECL, apparently. The G++ front end can put something else
2930 there, at least temporarily. */
2931 else if (TREE_CODE (node
) == COMPONENT_REF
2932 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
2934 if (TREE_OPERAND (node
, 2))
2935 UPDATE_TITCSE (TREE_OPERAND (node
, 2));
2937 else if (TREE_CODE (node
) == BIT_FIELD_REF
)
2938 UPDATE_TITCSE (TREE_OPERAND (node
, 2));
2941 node
= lang_hooks
.expr_to_decl (node
, &tc
, &ti
, &se
);
2943 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
2944 the address, since &(*a)->b is a form of addition. If it's a decl, it's
2945 invariant and constant if the decl is static. It's also invariant if it's
2946 a decl in the current function. Taking the address of a volatile variable
2947 is not volatile. If it's a constant, the address is both invariant and
2948 constant. Otherwise it's neither. */
2949 if (TREE_CODE (node
) == INDIRECT_REF
)
2950 UPDATE_TITCSE (TREE_OPERAND (node
, 0));
2951 else if (DECL_P (node
))
2955 else if (decl_function_context (node
) == current_function_decl
2956 /* Addresses of thread-local variables are invariant. */
2957 || (TREE_CODE (node
) == VAR_DECL
2958 && DECL_THREAD_LOCAL_P (node
)))
2963 else if (CONSTANT_CLASS_P (node
))
2968 se
|= TREE_SIDE_EFFECTS (node
);
2971 TREE_CONSTANT (t
) = tc
;
2972 TREE_INVARIANT (t
) = ti
;
2973 TREE_SIDE_EFFECTS (t
) = se
;
2974 #undef UPDATE_TITCSE
2977 /* Build an expression of code CODE, data type TYPE, and operands as
2978 specified. Expressions and reference nodes can be created this way.
2979 Constants, decls, types and misc nodes cannot be.
2981 We define 5 non-variadic functions, from 0 to 4 arguments. This is
2982 enough for all extant tree codes. */
2985 build0_stat (enum tree_code code
, tree tt MEM_STAT_DECL
)
2989 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
2991 t
= make_node_stat (code PASS_MEM_STAT
);
2998 build1_stat (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
3000 int length
= sizeof (struct tree_exp
);
3001 #ifdef GATHER_STATISTICS
3002 tree_node_kind kind
;
3006 #ifdef GATHER_STATISTICS
3007 switch (TREE_CODE_CLASS (code
))
3009 case tcc_statement
: /* an expression with side effects */
3012 case tcc_reference
: /* a reference */
3020 tree_node_counts
[(int) kind
]++;
3021 tree_node_sizes
[(int) kind
] += length
;
3024 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
3026 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
3028 memset (t
, 0, sizeof (struct tree_common
));
3030 TREE_SET_CODE (t
, code
);
3032 TREE_TYPE (t
) = type
;
3033 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
3034 TREE_OPERAND (t
, 0) = node
;
3035 TREE_BLOCK (t
) = NULL_TREE
;
3036 if (node
&& !TYPE_P (node
))
3038 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
3039 TREE_READONLY (t
) = TREE_READONLY (node
);
3042 if (TREE_CODE_CLASS (code
) == tcc_statement
)
3043 TREE_SIDE_EFFECTS (t
) = 1;
3047 /* All of these have side-effects, no matter what their
3049 TREE_SIDE_EFFECTS (t
) = 1;
3050 TREE_READONLY (t
) = 0;
3053 case MISALIGNED_INDIRECT_REF
:
3054 case ALIGN_INDIRECT_REF
:
3056 /* Whether a dereference is readonly has nothing to do with whether
3057 its operand is readonly. */
3058 TREE_READONLY (t
) = 0;
3063 recompute_tree_invariant_for_addr_expr (t
);
3067 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
3068 && node
&& !TYPE_P (node
)
3069 && TREE_CONSTANT (node
))
3070 TREE_CONSTANT (t
) = 1;
3071 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
3072 && node
&& TREE_INVARIANT (node
))
3073 TREE_INVARIANT (t
) = 1;
3074 if (TREE_CODE_CLASS (code
) == tcc_reference
3075 && node
&& TREE_THIS_VOLATILE (node
))
3076 TREE_THIS_VOLATILE (t
) = 1;
3083 #define PROCESS_ARG(N) \
3085 TREE_OPERAND (t, N) = arg##N; \
3086 if (arg##N &&!TYPE_P (arg##N)) \
3088 if (TREE_SIDE_EFFECTS (arg##N)) \
3090 if (!TREE_READONLY (arg##N)) \
3092 if (!TREE_CONSTANT (arg##N)) \
3094 if (!TREE_INVARIANT (arg##N)) \
3100 build2_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
3102 bool constant
, read_only
, side_effects
, invariant
;
3105 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
3108 /* FIXME tuples: Statement's aren't expressions! */
3109 if (code
== GIMPLE_MODIFY_STMT
)
3110 return build_gimple_modify_stmt_stat (arg0
, arg1 PASS_MEM_STAT
);
3112 /* Must use build_gimple_modify_stmt to construct GIMPLE_MODIFY_STMTs. */
3113 gcc_assert (code
!= GIMPLE_MODIFY_STMT
);
3116 if ((code
== MINUS_EXPR
|| code
== PLUS_EXPR
|| code
== MULT_EXPR
)
3117 && arg0
&& arg1
&& tt
&& POINTER_TYPE_P (tt
))
3118 gcc_assert (TREE_CODE (arg0
) == INTEGER_CST
&& TREE_CODE (arg1
) == INTEGER_CST
);
3120 if (code
== POINTER_PLUS_EXPR
&& arg0
&& arg1
&& tt
)
3121 gcc_assert (POINTER_TYPE_P (tt
) && POINTER_TYPE_P (TREE_TYPE (arg0
))
3122 && INTEGRAL_TYPE_P (TREE_TYPE (arg1
))
3123 && useless_type_conversion_p (sizetype
, TREE_TYPE (arg1
)));
3125 t
= make_node_stat (code PASS_MEM_STAT
);
3128 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
3129 result based on those same flags for the arguments. But if the
3130 arguments aren't really even `tree' expressions, we shouldn't be trying
3133 /* Expressions without side effects may be constant if their
3134 arguments are as well. */
3135 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
3136 || TREE_CODE_CLASS (code
) == tcc_binary
);
3138 side_effects
= TREE_SIDE_EFFECTS (t
);
3139 invariant
= constant
;
3144 TREE_READONLY (t
) = read_only
;
3145 TREE_CONSTANT (t
) = constant
;
3146 TREE_INVARIANT (t
) = invariant
;
3147 TREE_SIDE_EFFECTS (t
) = side_effects
;
3148 TREE_THIS_VOLATILE (t
)
3149 = (TREE_CODE_CLASS (code
) == tcc_reference
3150 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3156 /* Build a GIMPLE_MODIFY_STMT node. This tree code doesn't have a
3157 type, so we can't use build2 (a.k.a. build2_stat). */
3160 build_gimple_modify_stmt_stat (tree arg0
, tree arg1 MEM_STAT_DECL
)
3164 t
= make_node_stat (GIMPLE_MODIFY_STMT PASS_MEM_STAT
);
3165 /* ?? We don't care about setting flags for tuples... */
3166 GIMPLE_STMT_OPERAND (t
, 0) = arg0
;
3167 GIMPLE_STMT_OPERAND (t
, 1) = arg1
;
3172 build3_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3173 tree arg2 MEM_STAT_DECL
)
3175 bool constant
, read_only
, side_effects
, invariant
;
3178 gcc_assert (TREE_CODE_LENGTH (code
) == 3);
3179 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
3181 t
= make_node_stat (code PASS_MEM_STAT
);
3184 /* As a special exception, if COND_EXPR has NULL branches, we
3185 assume that it is a gimple statement and always consider
3186 it to have side effects. */
3187 if (code
== COND_EXPR
3188 && tt
== void_type_node
3189 && arg1
== NULL_TREE
3190 && arg2
== NULL_TREE
)
3191 side_effects
= true;
3193 side_effects
= TREE_SIDE_EFFECTS (t
);
3199 TREE_SIDE_EFFECTS (t
) = side_effects
;
3200 TREE_THIS_VOLATILE (t
)
3201 = (TREE_CODE_CLASS (code
) == tcc_reference
3202 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3208 build4_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3209 tree arg2
, tree arg3 MEM_STAT_DECL
)
3211 bool constant
, read_only
, side_effects
, invariant
;
3214 gcc_assert (TREE_CODE_LENGTH (code
) == 4);
3216 t
= make_node_stat (code PASS_MEM_STAT
);
3219 side_effects
= TREE_SIDE_EFFECTS (t
);
3226 TREE_SIDE_EFFECTS (t
) = side_effects
;
3227 TREE_THIS_VOLATILE (t
)
3228 = (TREE_CODE_CLASS (code
) == tcc_reference
3229 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3235 build5_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3236 tree arg2
, tree arg3
, tree arg4 MEM_STAT_DECL
)
3238 bool constant
, read_only
, side_effects
, invariant
;
3241 gcc_assert (TREE_CODE_LENGTH (code
) == 5);
3243 t
= make_node_stat (code PASS_MEM_STAT
);
3246 side_effects
= TREE_SIDE_EFFECTS (t
);
3254 TREE_SIDE_EFFECTS (t
) = side_effects
;
3255 TREE_THIS_VOLATILE (t
)
3256 = (TREE_CODE_CLASS (code
) == tcc_reference
3257 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3263 build7_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3264 tree arg2
, tree arg3
, tree arg4
, tree arg5
,
3265 tree arg6 MEM_STAT_DECL
)
3267 bool constant
, read_only
, side_effects
, invariant
;
3270 gcc_assert (code
== TARGET_MEM_REF
);
3272 t
= make_node_stat (code PASS_MEM_STAT
);
3275 side_effects
= TREE_SIDE_EFFECTS (t
);
3285 TREE_SIDE_EFFECTS (t
) = side_effects
;
3286 TREE_THIS_VOLATILE (t
) = 0;
3291 /* Similar except don't specify the TREE_TYPE
3292 and leave the TREE_SIDE_EFFECTS as 0.
3293 It is permissible for arguments to be null,
3294 or even garbage if their values do not matter. */
3297 build_nt (enum tree_code code
, ...)
3304 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
3308 t
= make_node (code
);
3309 length
= TREE_CODE_LENGTH (code
);
3311 for (i
= 0; i
< length
; i
++)
3312 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
3318 /* Similar to build_nt, but for creating a CALL_EXPR object with
3319 ARGLIST passed as a list. */
3322 build_nt_call_list (tree fn
, tree arglist
)
3327 t
= build_vl_exp (CALL_EXPR
, list_length (arglist
) + 3);
3328 CALL_EXPR_FN (t
) = fn
;
3329 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
3330 for (i
= 0; arglist
; arglist
= TREE_CHAIN (arglist
), i
++)
3331 CALL_EXPR_ARG (t
, i
) = TREE_VALUE (arglist
);
3335 /* Return true if the DECL_UID in both trees are equal. */
3338 uid_decl_map_eq (const void *va
, const void *vb
)
3340 const_tree a
= (const_tree
) va
;
3341 const_tree b
= (const_tree
) vb
;
3342 return (a
->decl_minimal
.uid
== b
->decl_minimal
.uid
);
3345 /* Hash a tree in a uid_decl_map. */
3348 uid_decl_map_hash (const void *item
)
3350 return ((const_tree
)item
)->decl_minimal
.uid
;
3353 /* Insert the declaration NODE into the map mapping its unique uid
3354 back to the tree. */
3357 insert_decl_to_uid_decl_map (tree node
)
3360 struct tree_decl_minimal key
;
3362 key
.uid
= DECL_UID (node
);
3363 slot
= htab_find_slot_with_hash (decl_for_uid_map
,
3364 &key
, DECL_UID (node
), INSERT
);
3366 /* We should never try to re-insert a decl with the same uid.
3367 ??? The C++ frontend breaks this invariant. Hopefully in a
3368 non-fatal way, so just overwrite the slot in this case. */
3370 gcc_assert (!*slot
);
3373 *(tree
*)slot
= node
;
3376 /* Lookup the declaration tree from its unique DECL_UID UID. Returns
3377 the tree node with DECL_UID UID or NULL, if this node was collected. */
3380 lookup_decl_from_uid (int uid
)
3382 struct tree_decl_minimal key
;
3385 return (tree
) htab_find_with_hash (decl_for_uid_map
, &key
, uid
);
3388 /* Remove the declaration tree DECL from the global UID to decl map.
3389 This needs to be called if you ggc_free a decl tree, otherwise
3390 garbage collection will take care of it. */
3393 remove_decl_from_map (tree decl
)
3395 struct tree_decl_minimal key
;
3397 key
.uid
= DECL_UID (decl
);
3399 gcc_assert (decl
== htab_find_with_hash (decl_for_uid_map
, &key
, key
.uid
));
3401 htab_remove_elt_with_hash (decl_for_uid_map
, &key
, key
.uid
);
3404 /* Print out the statistics for the decl_for_uid_map hash table. */
3407 print_decl_for_uid_map_statistics (void)
3409 fprintf (stderr
, "DECL_FOR_UID_MAP hash: size %ld, %ld elements, %f collisions\n",
3410 (long) htab_size (decl_for_uid_map
),
3411 (long) htab_elements (decl_for_uid_map
),
3412 htab_collisions (decl_for_uid_map
));
3415 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
3416 We do NOT enter this node in any sort of symbol table.
3418 layout_decl is used to set up the decl's storage layout.
3419 Other slots are initialized to 0 or null pointers. */
3422 build_decl_stat (enum tree_code code
, tree name
, tree type MEM_STAT_DECL
)
3426 t
= make_node_stat (code PASS_MEM_STAT
);
3428 /* if (type == error_mark_node)
3429 type = integer_type_node; */
3430 /* That is not done, deliberately, so that having error_mark_node
3431 as the type can suppress useless errors in the use of this variable. */
3433 DECL_NAME (t
) = name
;
3434 TREE_TYPE (t
) = type
;
3436 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
3442 /* Builds and returns function declaration with NAME and TYPE. */
3445 build_fn_decl (const char *name
, tree type
)
3447 tree id
= get_identifier (name
);
3448 tree decl
= build_decl (FUNCTION_DECL
, id
, type
);
3450 DECL_EXTERNAL (decl
) = 1;
3451 TREE_PUBLIC (decl
) = 1;
3452 DECL_ARTIFICIAL (decl
) = 1;
3453 TREE_NOTHROW (decl
) = 1;
3459 /* BLOCK nodes are used to represent the structure of binding contours
3460 and declarations, once those contours have been exited and their contents
3461 compiled. This information is used for outputting debugging info. */
3464 build_block (tree vars
, tree subblocks
, tree supercontext
, tree chain
)
3466 tree block
= make_node (BLOCK
);
3468 BLOCK_VARS (block
) = vars
;
3469 BLOCK_SUBBLOCKS (block
) = subblocks
;
3470 BLOCK_SUPERCONTEXT (block
) = supercontext
;
3471 BLOCK_CHAIN (block
) = chain
;
3476 expand_location (source_location loc
)
3478 expanded_location xloc
;
3487 const struct line_map
*map
= linemap_lookup (line_table
, loc
);
3488 xloc
.file
= map
->to_file
;
3489 xloc
.line
= SOURCE_LINE (map
, loc
);
3490 xloc
.column
= SOURCE_COLUMN (map
, loc
);
3496 /* Source location accessor functions. */
3499 /* The source location of this expression. Non-tree_exp nodes such as
3500 decls and constants can be shared among multiple locations, so
3503 expr_location (const_tree node
)
3505 if (GIMPLE_STMT_P (node
))
3506 return GIMPLE_STMT_LOCUS (node
);
3507 return EXPR_P (node
) ? node
->exp
.locus
: UNKNOWN_LOCATION
;
3511 set_expr_location (tree node
, location_t locus
)
3513 if (GIMPLE_STMT_P (node
))
3514 GIMPLE_STMT_LOCUS (node
) = locus
;
3516 EXPR_CHECK (node
)->exp
.locus
= locus
;
3520 expr_has_location (const_tree node
)
3522 return expr_location (node
) != UNKNOWN_LOCATION
;
3526 expr_locus (const_tree node
)
3528 if (GIMPLE_STMT_P (node
))
3529 return CONST_CAST (source_location
*, &GIMPLE_STMT_LOCUS (node
));
3530 return (EXPR_P (node
)
3531 ? CONST_CAST (source_location
*, &node
->exp
.locus
)
3532 : (source_location
*) NULL
);
3536 set_expr_locus (tree node
, source_location
*loc
)
3540 if (GIMPLE_STMT_P (node
))
3541 GIMPLE_STMT_LOCUS (node
) = UNKNOWN_LOCATION
;
3543 EXPR_CHECK (node
)->exp
.locus
= UNKNOWN_LOCATION
;
3547 if (GIMPLE_STMT_P (node
))
3548 GIMPLE_STMT_LOCUS (node
) = *loc
;
3550 EXPR_CHECK (node
)->exp
.locus
= *loc
;
3554 /* Return the file name of the location of NODE. */
3556 expr_filename (const_tree node
)
3558 if (GIMPLE_STMT_P (node
))
3559 return LOCATION_FILE (GIMPLE_STMT_LOCUS (node
));
3560 return LOCATION_FILE (EXPR_CHECK (node
)->exp
.locus
);
3563 /* Return the line number of the location of NODE. */
3565 expr_lineno (const_tree node
)
3567 if (GIMPLE_STMT_P (node
))
3568 return LOCATION_LINE (GIMPLE_STMT_LOCUS (node
));
3569 return LOCATION_LINE (EXPR_CHECK (node
)->exp
.locus
);
3573 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
3577 build_decl_attribute_variant (tree ddecl
, tree attribute
)
3579 DECL_ATTRIBUTES (ddecl
) = attribute
;
3583 /* Borrowed from hashtab.c iterative_hash implementation. */
3584 #define mix(a,b,c) \
3586 a -= b; a -= c; a ^= (c>>13); \
3587 b -= c; b -= a; b ^= (a<< 8); \
3588 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
3589 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
3590 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
3591 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
3592 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
3593 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
3594 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
3598 /* Produce good hash value combining VAL and VAL2. */
3599 static inline hashval_t
3600 iterative_hash_hashval_t (hashval_t val
, hashval_t val2
)
3602 /* the golden ratio; an arbitrary value. */
3603 hashval_t a
= 0x9e3779b9;
3609 /* Produce good hash value combining PTR and VAL2. */
3610 static inline hashval_t
3611 iterative_hash_pointer (const void *ptr
, hashval_t val2
)
3613 if (sizeof (ptr
) == sizeof (hashval_t
))
3614 return iterative_hash_hashval_t ((size_t) ptr
, val2
);
3617 hashval_t a
= (hashval_t
) (size_t) ptr
;
3618 /* Avoid warnings about shifting of more than the width of the type on
3619 hosts that won't execute this path. */
3621 hashval_t b
= (hashval_t
) ((size_t) ptr
>> (sizeof (hashval_t
) * 8 + zero
));
3627 /* Produce good hash value combining VAL and VAL2. */
3628 static inline hashval_t
3629 iterative_hash_host_wide_int (HOST_WIDE_INT val
, hashval_t val2
)
3631 if (sizeof (HOST_WIDE_INT
) == sizeof (hashval_t
))
3632 return iterative_hash_hashval_t (val
, val2
);
3635 hashval_t a
= (hashval_t
) val
;
3636 /* Avoid warnings about shifting of more than the width of the type on
3637 hosts that won't execute this path. */
3639 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 8 + zero
));
3641 if (sizeof (HOST_WIDE_INT
) > 2 * sizeof (hashval_t
))
3643 hashval_t a
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 16 + zero
));
3644 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 24 + zero
));
3651 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3652 is ATTRIBUTE and its qualifiers are QUALS.
3654 Record such modified types already made so we don't make duplicates. */
3657 build_type_attribute_qual_variant (tree ttype
, tree attribute
, int quals
)
3659 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
3661 hashval_t hashcode
= 0;
3663 enum tree_code code
= TREE_CODE (ttype
);
3665 /* Building a distinct copy of a tagged type is inappropriate; it
3666 causes breakage in code that expects there to be a one-to-one
3667 relationship between a struct and its fields.
3668 build_duplicate_type is another solution (as used in
3669 handle_transparent_union_attribute), but that doesn't play well
3670 with the stronger C++ type identity model. */
3671 if (TREE_CODE (ttype
) == RECORD_TYPE
3672 || TREE_CODE (ttype
) == UNION_TYPE
3673 || TREE_CODE (ttype
) == QUAL_UNION_TYPE
3674 || TREE_CODE (ttype
) == ENUMERAL_TYPE
)
3676 warning (OPT_Wattributes
,
3677 "ignoring attributes applied to %qT after definition",
3678 TYPE_MAIN_VARIANT (ttype
));
3679 return build_qualified_type (ttype
, quals
);
3682 ntype
= build_distinct_type_copy (ttype
);
3684 TYPE_ATTRIBUTES (ntype
) = attribute
;
3685 set_type_quals (ntype
, TYPE_UNQUALIFIED
);
3687 hashcode
= iterative_hash_object (code
, hashcode
);
3688 if (TREE_TYPE (ntype
))
3689 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype
)),
3691 hashcode
= attribute_hash_list (attribute
, hashcode
);
3693 switch (TREE_CODE (ntype
))
3696 hashcode
= type_hash_list (TYPE_ARG_TYPES (ntype
), hashcode
);
3699 if (TYPE_DOMAIN (ntype
))
3700 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype
)),
3704 hashcode
= iterative_hash_object
3705 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype
)), hashcode
);
3706 hashcode
= iterative_hash_object
3707 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype
)), hashcode
);
3710 case FIXED_POINT_TYPE
:
3712 unsigned int precision
= TYPE_PRECISION (ntype
);
3713 hashcode
= iterative_hash_object (precision
, hashcode
);
3720 ntype
= type_hash_canon (hashcode
, ntype
);
3722 /* If the target-dependent attributes make NTYPE different from
3723 its canonical type, we will need to use structural equality
3724 checks for this qualified type. */
3725 ttype
= build_qualified_type (ttype
, TYPE_UNQUALIFIED
);
3726 if (TYPE_STRUCTURAL_EQUALITY_P (ttype
)
3727 || !targetm
.comp_type_attributes (ntype
, ttype
))
3728 SET_TYPE_STRUCTURAL_EQUALITY (ntype
);
3730 TYPE_CANONICAL (ntype
) = TYPE_CANONICAL (ttype
);
3732 ttype
= build_qualified_type (ntype
, quals
);
3734 else if (TYPE_QUALS (ttype
) != quals
)
3735 ttype
= build_qualified_type (ttype
, quals
);
3741 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3744 Record such modified types already made so we don't make duplicates. */
3747 build_type_attribute_variant (tree ttype
, tree attribute
)
3749 return build_type_attribute_qual_variant (ttype
, attribute
,
3750 TYPE_QUALS (ttype
));
3753 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3756 We try both `text' and `__text__', ATTR may be either one. */
3757 /* ??? It might be a reasonable simplification to require ATTR to be only
3758 `text'. One might then also require attribute lists to be stored in
3759 their canonicalized form. */
3762 is_attribute_with_length_p (const char *attr
, int attr_len
, const_tree ident
)
3767 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
3770 p
= IDENTIFIER_POINTER (ident
);
3771 ident_len
= IDENTIFIER_LENGTH (ident
);
3773 if (ident_len
== attr_len
3774 && strcmp (attr
, p
) == 0)
3777 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
3780 gcc_assert (attr
[1] == '_');
3781 gcc_assert (attr
[attr_len
- 2] == '_');
3782 gcc_assert (attr
[attr_len
- 1] == '_');
3783 if (ident_len
== attr_len
- 4
3784 && strncmp (attr
+ 2, p
, attr_len
- 4) == 0)
3789 if (ident_len
== attr_len
+ 4
3790 && p
[0] == '_' && p
[1] == '_'
3791 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
3792 && strncmp (attr
, p
+ 2, attr_len
) == 0)
3799 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3802 We try both `text' and `__text__', ATTR may be either one. */
3805 is_attribute_p (const char *attr
, const_tree ident
)
3807 return is_attribute_with_length_p (attr
, strlen (attr
), ident
);
3810 /* Given an attribute name and a list of attributes, return a pointer to the
3811 attribute's list element if the attribute is part of the list, or NULL_TREE
3812 if not found. If the attribute appears more than once, this only
3813 returns the first occurrence; the TREE_CHAIN of the return value should
3814 be passed back in if further occurrences are wanted. */
3817 lookup_attribute (const char *attr_name
, tree list
)
3820 size_t attr_len
= strlen (attr_name
);
3822 for (l
= list
; l
; l
= TREE_CHAIN (l
))
3824 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
3825 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
3831 /* Remove any instances of attribute ATTR_NAME in LIST and return the
3835 remove_attribute (const char *attr_name
, tree list
)
3838 size_t attr_len
= strlen (attr_name
);
3840 for (p
= &list
; *p
; )
3843 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
3844 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
3845 *p
= TREE_CHAIN (l
);
3847 p
= &TREE_CHAIN (l
);
3853 /* Return an attribute list that is the union of a1 and a2. */
3856 merge_attributes (tree a1
, tree a2
)
3860 /* Either one unset? Take the set one. */
3862 if ((attributes
= a1
) == 0)
3865 /* One that completely contains the other? Take it. */
3867 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
3869 if (attribute_list_contained (a2
, a1
))
3873 /* Pick the longest list, and hang on the other list. */
3875 if (list_length (a1
) < list_length (a2
))
3876 attributes
= a2
, a2
= a1
;
3878 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
3881 for (a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
3884 a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
3887 if (TREE_VALUE (a
) != NULL
3888 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
3889 && TREE_VALUE (a2
) != NULL
3890 && TREE_CODE (TREE_VALUE (a2
)) == TREE_LIST
)
3892 if (simple_cst_list_equal (TREE_VALUE (a
),
3893 TREE_VALUE (a2
)) == 1)
3896 else if (simple_cst_equal (TREE_VALUE (a
),
3897 TREE_VALUE (a2
)) == 1)
3902 a1
= copy_node (a2
);
3903 TREE_CHAIN (a1
) = attributes
;
3912 /* Given types T1 and T2, merge their attributes and return
3916 merge_type_attributes (tree t1
, tree t2
)
3918 return merge_attributes (TYPE_ATTRIBUTES (t1
),
3919 TYPE_ATTRIBUTES (t2
));
3922 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
3926 merge_decl_attributes (tree olddecl
, tree newdecl
)
3928 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
3929 DECL_ATTRIBUTES (newdecl
));
3932 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
3934 /* Specialization of merge_decl_attributes for various Windows targets.
3936 This handles the following situation:
3938 __declspec (dllimport) int foo;
3941 The second instance of `foo' nullifies the dllimport. */
3944 merge_dllimport_decl_attributes (tree old
, tree
new)
3947 int delete_dllimport_p
= 1;
3949 /* What we need to do here is remove from `old' dllimport if it doesn't
3950 appear in `new'. dllimport behaves like extern: if a declaration is
3951 marked dllimport and a definition appears later, then the object
3952 is not dllimport'd. We also remove a `new' dllimport if the old list
3953 contains dllexport: dllexport always overrides dllimport, regardless
3954 of the order of declaration. */
3955 if (!VAR_OR_FUNCTION_DECL_P (new))
3956 delete_dllimport_p
= 0;
3957 else if (DECL_DLLIMPORT_P (new)
3958 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old
)))
3960 DECL_DLLIMPORT_P (new) = 0;
3961 warning (OPT_Wattributes
, "%q+D already declared with dllexport attribute: "
3962 "dllimport ignored", new);
3964 else if (DECL_DLLIMPORT_P (old
) && !DECL_DLLIMPORT_P (new))
3966 /* Warn about overriding a symbol that has already been used. eg:
3967 extern int __attribute__ ((dllimport)) foo;
3968 int* bar () {return &foo;}
3971 if (TREE_USED (old
))
3973 warning (0, "%q+D redeclared without dllimport attribute "
3974 "after being referenced with dll linkage", new);
3975 /* If we have used a variable's address with dllimport linkage,
3976 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
3977 decl may already have had TREE_INVARIANT and TREE_CONSTANT
3979 We still remove the attribute so that assembler code refers
3980 to '&foo rather than '_imp__foo'. */
3981 if (TREE_CODE (old
) == VAR_DECL
&& TREE_ADDRESSABLE (old
))
3982 DECL_DLLIMPORT_P (new) = 1;
3985 /* Let an inline definition silently override the external reference,
3986 but otherwise warn about attribute inconsistency. */
3987 else if (TREE_CODE (new) == VAR_DECL
3988 || !DECL_DECLARED_INLINE_P (new))
3989 warning (OPT_Wattributes
, "%q+D redeclared without dllimport attribute: "
3990 "previous dllimport ignored", new);
3993 delete_dllimport_p
= 0;
3995 a
= merge_attributes (DECL_ATTRIBUTES (old
), DECL_ATTRIBUTES (new));
3997 if (delete_dllimport_p
)
4000 const size_t attr_len
= strlen ("dllimport");
4002 /* Scan the list for dllimport and delete it. */
4003 for (prev
= NULL_TREE
, t
= a
; t
; prev
= t
, t
= TREE_CHAIN (t
))
4005 if (is_attribute_with_length_p ("dllimport", attr_len
,
4008 if (prev
== NULL_TREE
)
4011 TREE_CHAIN (prev
) = TREE_CHAIN (t
);
4020 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
4021 struct attribute_spec.handler. */
4024 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
4029 /* These attributes may apply to structure and union types being created,
4030 but otherwise should pass to the declaration involved. */
4033 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
4034 | (int) ATTR_FLAG_ARRAY_NEXT
))
4036 *no_add_attrs
= true;
4037 return tree_cons (name
, args
, NULL_TREE
);
4039 if (TREE_CODE (node
) == RECORD_TYPE
4040 || TREE_CODE (node
) == UNION_TYPE
)
4042 node
= TYPE_NAME (node
);
4048 warning (OPT_Wattributes
, "%qs attribute ignored",
4049 IDENTIFIER_POINTER (name
));
4050 *no_add_attrs
= true;
4055 if (TREE_CODE (node
) != FUNCTION_DECL
4056 && TREE_CODE (node
) != VAR_DECL
4057 && TREE_CODE (node
) != TYPE_DECL
)
4059 *no_add_attrs
= true;
4060 warning (OPT_Wattributes
, "%qs attribute ignored",
4061 IDENTIFIER_POINTER (name
));
4065 /* Report error on dllimport ambiguities seen now before they cause
4067 else if (is_attribute_p ("dllimport", name
))
4069 /* Honor any target-specific overrides. */
4070 if (!targetm
.valid_dllimport_attribute_p (node
))
4071 *no_add_attrs
= true;
4073 else if (TREE_CODE (node
) == FUNCTION_DECL
4074 && DECL_DECLARED_INLINE_P (node
))
4076 warning (OPT_Wattributes
, "inline function %q+D declared as "
4077 " dllimport: attribute ignored", node
);
4078 *no_add_attrs
= true;
4080 /* Like MS, treat definition of dllimported variables and
4081 non-inlined functions on declaration as syntax errors. */
4082 else if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
))
4084 error ("function %q+D definition is marked dllimport", node
);
4085 *no_add_attrs
= true;
4088 else if (TREE_CODE (node
) == VAR_DECL
)
4090 if (DECL_INITIAL (node
))
4092 error ("variable %q+D definition is marked dllimport",
4094 *no_add_attrs
= true;
4097 /* `extern' needn't be specified with dllimport.
4098 Specify `extern' now and hope for the best. Sigh. */
4099 DECL_EXTERNAL (node
) = 1;
4100 /* Also, implicitly give dllimport'd variables declared within
4101 a function global scope, unless declared static. */
4102 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
4103 TREE_PUBLIC (node
) = 1;
4106 if (*no_add_attrs
== false)
4107 DECL_DLLIMPORT_P (node
) = 1;
4110 /* Report error if symbol is not accessible at global scope. */
4111 if (!TREE_PUBLIC (node
)
4112 && (TREE_CODE (node
) == VAR_DECL
4113 || TREE_CODE (node
) == FUNCTION_DECL
))
4115 error ("external linkage required for symbol %q+D because of "
4116 "%qs attribute", node
, IDENTIFIER_POINTER (name
));
4117 *no_add_attrs
= true;
4120 /* A dllexport'd entity must have default visibility so that other
4121 program units (shared libraries or the main executable) can see
4122 it. A dllimport'd entity must have default visibility so that
4123 the linker knows that undefined references within this program
4124 unit can be resolved by the dynamic linker. */
4127 if (DECL_VISIBILITY_SPECIFIED (node
)
4128 && DECL_VISIBILITY (node
) != VISIBILITY_DEFAULT
)
4129 error ("%qs implies default visibility, but %qD has already "
4130 "been declared with a different visibility",
4131 IDENTIFIER_POINTER (name
), node
);
4132 DECL_VISIBILITY (node
) = VISIBILITY_DEFAULT
;
4133 DECL_VISIBILITY_SPECIFIED (node
) = 1;
4139 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
4141 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
4142 of the various TYPE_QUAL values. */
4145 set_type_quals (tree type
, int type_quals
)
4147 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
4148 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
4149 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
4152 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
4155 check_qualified_type (const_tree cand
, const_tree base
, int type_quals
)
4157 return (TYPE_QUALS (cand
) == type_quals
4158 && TYPE_NAME (cand
) == TYPE_NAME (base
)
4159 /* Apparently this is needed for Objective-C. */
4160 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
4161 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
4162 TYPE_ATTRIBUTES (base
)));
4165 /* Return a version of the TYPE, qualified as indicated by the
4166 TYPE_QUALS, if one exists. If no qualified version exists yet,
4167 return NULL_TREE. */
4170 get_qualified_type (tree type
, int type_quals
)
4174 if (TYPE_QUALS (type
) == type_quals
)
4177 /* Search the chain of variants to see if there is already one there just
4178 like the one we need to have. If so, use that existing one. We must
4179 preserve the TYPE_NAME, since there is code that depends on this. */
4180 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
4181 if (check_qualified_type (t
, type
, type_quals
))
4187 /* Like get_qualified_type, but creates the type if it does not
4188 exist. This function never returns NULL_TREE. */
4191 build_qualified_type (tree type
, int type_quals
)
4195 /* See if we already have the appropriate qualified variant. */
4196 t
= get_qualified_type (type
, type_quals
);
4198 /* If not, build it. */
4201 t
= build_variant_type_copy (type
);
4202 set_type_quals (t
, type_quals
);
4204 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
4205 /* Propagate structural equality. */
4206 SET_TYPE_STRUCTURAL_EQUALITY (t
);
4207 else if (TYPE_CANONICAL (type
) != type
)
4208 /* Build the underlying canonical type, since it is different
4210 TYPE_CANONICAL (t
) = build_qualified_type (TYPE_CANONICAL (type
),
4213 /* T is its own canonical type. */
4214 TYPE_CANONICAL (t
) = t
;
4221 /* Create a new distinct copy of TYPE. The new type is made its own
4222 MAIN_VARIANT. If TYPE requires structural equality checks, the
4223 resulting type requires structural equality checks; otherwise, its
4224 TYPE_CANONICAL points to itself. */
4227 build_distinct_type_copy (tree type
)
4229 tree t
= copy_node (type
);
4231 TYPE_POINTER_TO (t
) = 0;
4232 TYPE_REFERENCE_TO (t
) = 0;
4234 /* Set the canonical type either to a new equivalence class, or
4235 propagate the need for structural equality checks. */
4236 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
4237 SET_TYPE_STRUCTURAL_EQUALITY (t
);
4239 TYPE_CANONICAL (t
) = t
;
4241 /* Make it its own variant. */
4242 TYPE_MAIN_VARIANT (t
) = t
;
4243 TYPE_NEXT_VARIANT (t
) = 0;
4245 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
4246 whose TREE_TYPE is not t. This can also happen in the Ada
4247 frontend when using subtypes. */
4252 /* Create a new variant of TYPE, equivalent but distinct. This is so
4253 the caller can modify it. TYPE_CANONICAL for the return type will
4254 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
4255 are considered equal by the language itself (or that both types
4256 require structural equality checks). */
4259 build_variant_type_copy (tree type
)
4261 tree t
, m
= TYPE_MAIN_VARIANT (type
);
4263 t
= build_distinct_type_copy (type
);
4265 /* Since we're building a variant, assume that it is a non-semantic
4266 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
4267 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
4269 /* Add the new type to the chain of variants of TYPE. */
4270 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
4271 TYPE_NEXT_VARIANT (m
) = t
;
4272 TYPE_MAIN_VARIANT (t
) = m
;
4277 /* Return true if the from tree in both tree maps are equal. */
4280 tree_map_base_eq (const void *va
, const void *vb
)
4282 const struct tree_map_base
*const a
= va
, *const b
= vb
;
4283 return (a
->from
== b
->from
);
4286 /* Hash a from tree in a tree_map. */
4289 tree_map_base_hash (const void *item
)
4291 return htab_hash_pointer (((const struct tree_map_base
*)item
)->from
);
4294 /* Return true if this tree map structure is marked for garbage collection
4295 purposes. We simply return true if the from tree is marked, so that this
4296 structure goes away when the from tree goes away. */
4299 tree_map_base_marked_p (const void *p
)
4301 return ggc_marked_p (((const struct tree_map_base
*) p
)->from
);
4305 tree_map_hash (const void *item
)
4307 return (((const struct tree_map
*) item
)->hash
);
4310 /* Return the initialization priority for DECL. */
4313 decl_init_priority_lookup (tree decl
)
4315 struct tree_priority_map
*h
;
4316 struct tree_map_base in
;
4318 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
4320 h
= htab_find (init_priority_for_decl
, &in
);
4321 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
4324 /* Return the finalization priority for DECL. */
4327 decl_fini_priority_lookup (tree decl
)
4329 struct tree_priority_map
*h
;
4330 struct tree_map_base in
;
4332 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
4334 h
= htab_find (init_priority_for_decl
, &in
);
4335 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
4338 /* Return the initialization and finalization priority information for
4339 DECL. If there is no previous priority information, a freshly
4340 allocated structure is returned. */
4342 static struct tree_priority_map
*
4343 decl_priority_info (tree decl
)
4345 struct tree_priority_map in
;
4346 struct tree_priority_map
*h
;
4349 in
.base
.from
= decl
;
4350 loc
= htab_find_slot (init_priority_for_decl
, &in
, INSERT
);
4354 h
= GGC_CNEW (struct tree_priority_map
);
4356 h
->base
.from
= decl
;
4357 h
->init
= DEFAULT_INIT_PRIORITY
;
4358 h
->fini
= DEFAULT_INIT_PRIORITY
;
4364 /* Set the initialization priority for DECL to PRIORITY. */
4367 decl_init_priority_insert (tree decl
, priority_type priority
)
4369 struct tree_priority_map
*h
;
4371 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
4372 h
= decl_priority_info (decl
);
4376 /* Set the finalization priority for DECL to PRIORITY. */
4379 decl_fini_priority_insert (tree decl
, priority_type priority
)
4381 struct tree_priority_map
*h
;
4383 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
4384 h
= decl_priority_info (decl
);
4388 /* Look up a restrict qualified base decl for FROM. */
4391 decl_restrict_base_lookup (tree from
)
4396 in
.base
.from
= from
;
4397 h
= htab_find_with_hash (restrict_base_for_decl
, &in
,
4398 htab_hash_pointer (from
));
4399 return h
? h
->to
: NULL_TREE
;
4402 /* Record the restrict qualified base TO for FROM. */
4405 decl_restrict_base_insert (tree from
, tree to
)
4410 h
= ggc_alloc (sizeof (struct tree_map
));
4411 h
->hash
= htab_hash_pointer (from
);
4412 h
->base
.from
= from
;
4414 loc
= htab_find_slot_with_hash (restrict_base_for_decl
, h
, h
->hash
, INSERT
);
4415 *(struct tree_map
**) loc
= h
;
4418 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
4421 print_debug_expr_statistics (void)
4423 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
4424 (long) htab_size (debug_expr_for_decl
),
4425 (long) htab_elements (debug_expr_for_decl
),
4426 htab_collisions (debug_expr_for_decl
));
4429 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
4432 print_value_expr_statistics (void)
4434 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
4435 (long) htab_size (value_expr_for_decl
),
4436 (long) htab_elements (value_expr_for_decl
),
4437 htab_collisions (value_expr_for_decl
));
4440 /* Print out statistics for the RESTRICT_BASE_FOR_DECL hash table, but
4441 don't print anything if the table is empty. */
4444 print_restrict_base_statistics (void)
4446 if (htab_elements (restrict_base_for_decl
) != 0)
4448 "RESTRICT_BASE hash: size %ld, %ld elements, %f collisions\n",
4449 (long) htab_size (restrict_base_for_decl
),
4450 (long) htab_elements (restrict_base_for_decl
),
4451 htab_collisions (restrict_base_for_decl
));
4454 /* Lookup a debug expression for FROM, and return it if we find one. */
4457 decl_debug_expr_lookup (tree from
)
4459 struct tree_map
*h
, in
;
4460 in
.base
.from
= from
;
4462 h
= htab_find_with_hash (debug_expr_for_decl
, &in
, htab_hash_pointer (from
));
4468 /* Insert a mapping FROM->TO in the debug expression hashtable. */
4471 decl_debug_expr_insert (tree from
, tree to
)
4476 h
= ggc_alloc (sizeof (struct tree_map
));
4477 h
->hash
= htab_hash_pointer (from
);
4478 h
->base
.from
= from
;
4480 loc
= htab_find_slot_with_hash (debug_expr_for_decl
, h
, h
->hash
, INSERT
);
4481 *(struct tree_map
**) loc
= h
;
4484 /* Lookup a value expression for FROM, and return it if we find one. */
4487 decl_value_expr_lookup (tree from
)
4489 struct tree_map
*h
, in
;
4490 in
.base
.from
= from
;
4492 h
= htab_find_with_hash (value_expr_for_decl
, &in
, htab_hash_pointer (from
));
4498 /* Insert a mapping FROM->TO in the value expression hashtable. */
4501 decl_value_expr_insert (tree from
, tree to
)
4506 h
= ggc_alloc (sizeof (struct tree_map
));
4507 h
->hash
= htab_hash_pointer (from
);
4508 h
->base
.from
= from
;
4510 loc
= htab_find_slot_with_hash (value_expr_for_decl
, h
, h
->hash
, INSERT
);
4511 *(struct tree_map
**) loc
= h
;
4514 /* Hashing of types so that we don't make duplicates.
4515 The entry point is `type_hash_canon'. */
4517 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
4518 with types in the TREE_VALUE slots), by adding the hash codes
4519 of the individual types. */
4522 type_hash_list (const_tree list
, hashval_t hashcode
)
4526 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
4527 if (TREE_VALUE (tail
) != error_mark_node
)
4528 hashcode
= iterative_hash_object (TYPE_HASH (TREE_VALUE (tail
)),
4534 /* These are the Hashtable callback functions. */
4536 /* Returns true iff the types are equivalent. */
4539 type_hash_eq (const void *va
, const void *vb
)
4541 const struct type_hash
*const a
= va
, *const b
= vb
;
4543 /* First test the things that are the same for all types. */
4544 if (a
->hash
!= b
->hash
4545 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
4546 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
4547 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
4548 TYPE_ATTRIBUTES (b
->type
))
4549 || TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
4550 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
))
4553 switch (TREE_CODE (a
->type
))
4558 case REFERENCE_TYPE
:
4562 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
4565 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
4566 && !(TYPE_VALUES (a
->type
)
4567 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
4568 && TYPE_VALUES (b
->type
)
4569 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
4570 && type_list_equal (TYPE_VALUES (a
->type
),
4571 TYPE_VALUES (b
->type
))))
4574 /* ... fall through ... */
4579 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
4580 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
4581 TYPE_MAX_VALUE (b
->type
)))
4582 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
4583 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
4584 TYPE_MIN_VALUE (b
->type
))));
4586 case FIXED_POINT_TYPE
:
4587 return TYPE_SATURATING (a
->type
) == TYPE_SATURATING (b
->type
);
4590 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
4593 return (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
4594 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
4595 || (TYPE_ARG_TYPES (a
->type
)
4596 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
4597 && TYPE_ARG_TYPES (b
->type
)
4598 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
4599 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
4600 TYPE_ARG_TYPES (b
->type
)))));
4603 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
4607 case QUAL_UNION_TYPE
:
4608 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
4609 || (TYPE_FIELDS (a
->type
)
4610 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
4611 && TYPE_FIELDS (b
->type
)
4612 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
4613 && type_list_equal (TYPE_FIELDS (a
->type
),
4614 TYPE_FIELDS (b
->type
))));
4617 if (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
4618 || (TYPE_ARG_TYPES (a
->type
)
4619 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
4620 && TYPE_ARG_TYPES (b
->type
)
4621 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
4622 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
4623 TYPE_ARG_TYPES (b
->type
))))
4631 if (lang_hooks
.types
.type_hash_eq
!= NULL
)
4632 return lang_hooks
.types
.type_hash_eq (a
->type
, b
->type
);
4637 /* Return the cached hash value. */
4640 type_hash_hash (const void *item
)
4642 return ((const struct type_hash
*) item
)->hash
;
4645 /* Look in the type hash table for a type isomorphic to TYPE.
4646 If one is found, return it. Otherwise return 0. */
4649 type_hash_lookup (hashval_t hashcode
, tree type
)
4651 struct type_hash
*h
, in
;
4653 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
4654 must call that routine before comparing TYPE_ALIGNs. */
4660 h
= htab_find_with_hash (type_hash_table
, &in
, hashcode
);
4666 /* Add an entry to the type-hash-table
4667 for a type TYPE whose hash code is HASHCODE. */
4670 type_hash_add (hashval_t hashcode
, tree type
)
4672 struct type_hash
*h
;
4675 h
= ggc_alloc (sizeof (struct type_hash
));
4678 loc
= htab_find_slot_with_hash (type_hash_table
, h
, hashcode
, INSERT
);
4682 /* Given TYPE, and HASHCODE its hash code, return the canonical
4683 object for an identical type if one already exists.
4684 Otherwise, return TYPE, and record it as the canonical object.
4686 To use this function, first create a type of the sort you want.
4687 Then compute its hash code from the fields of the type that
4688 make it different from other similar types.
4689 Then call this function and use the value. */
4692 type_hash_canon (unsigned int hashcode
, tree type
)
4696 /* The hash table only contains main variants, so ensure that's what we're
4698 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
4700 if (!lang_hooks
.types
.hash_types
)
4703 /* See if the type is in the hash table already. If so, return it.
4704 Otherwise, add the type. */
4705 t1
= type_hash_lookup (hashcode
, type
);
4708 #ifdef GATHER_STATISTICS
4709 tree_node_counts
[(int) t_kind
]--;
4710 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type
);
4716 type_hash_add (hashcode
, type
);
4721 /* See if the data pointed to by the type hash table is marked. We consider
4722 it marked if the type is marked or if a debug type number or symbol
4723 table entry has been made for the type. This reduces the amount of
4724 debugging output and eliminates that dependency of the debug output on
4725 the number of garbage collections. */
4728 type_hash_marked_p (const void *p
)
4730 const_tree
const type
= ((const struct type_hash
*) p
)->type
;
4732 return ggc_marked_p (type
) || TYPE_SYMTAB_POINTER (type
);
4736 print_type_hash_statistics (void)
4738 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
4739 (long) htab_size (type_hash_table
),
4740 (long) htab_elements (type_hash_table
),
4741 htab_collisions (type_hash_table
));
4744 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
4745 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
4746 by adding the hash codes of the individual attributes. */
4749 attribute_hash_list (const_tree list
, hashval_t hashcode
)
4753 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
4754 /* ??? Do we want to add in TREE_VALUE too? */
4755 hashcode
= iterative_hash_object
4756 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail
)), hashcode
);
4760 /* Given two lists of attributes, return true if list l2 is
4761 equivalent to l1. */
4764 attribute_list_equal (const_tree l1
, const_tree l2
)
4766 return attribute_list_contained (l1
, l2
)
4767 && attribute_list_contained (l2
, l1
);
4770 /* Given two lists of attributes, return true if list L2 is
4771 completely contained within L1. */
4772 /* ??? This would be faster if attribute names were stored in a canonicalized
4773 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
4774 must be used to show these elements are equivalent (which they are). */
4775 /* ??? It's not clear that attributes with arguments will always be handled
4779 attribute_list_contained (const_tree l1
, const_tree l2
)
4783 /* First check the obvious, maybe the lists are identical. */
4787 /* Maybe the lists are similar. */
4788 for (t1
= l1
, t2
= l2
;
4790 && TREE_PURPOSE (t1
) == TREE_PURPOSE (t2
)
4791 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
4792 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
));
4794 /* Maybe the lists are equal. */
4795 if (t1
== 0 && t2
== 0)
4798 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
4801 /* This CONST_CAST is okay because lookup_attribute does not
4802 modify its argument and the return value is assigned to a
4804 for (attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
4805 CONST_CAST_TREE(l1
));
4807 attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
4810 if (TREE_VALUE (t2
) != NULL
4811 && TREE_CODE (TREE_VALUE (t2
)) == TREE_LIST
4812 && TREE_VALUE (attr
) != NULL
4813 && TREE_CODE (TREE_VALUE (attr
)) == TREE_LIST
)
4815 if (simple_cst_list_equal (TREE_VALUE (t2
),
4816 TREE_VALUE (attr
)) == 1)
4819 else if (simple_cst_equal (TREE_VALUE (t2
), TREE_VALUE (attr
)) == 1)
4830 /* Given two lists of types
4831 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
4832 return 1 if the lists contain the same types in the same order.
4833 Also, the TREE_PURPOSEs must match. */
4836 type_list_equal (const_tree l1
, const_tree l2
)
4840 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
4841 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
4842 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
4843 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
4844 && (TREE_TYPE (TREE_PURPOSE (t1
))
4845 == TREE_TYPE (TREE_PURPOSE (t2
))))))
4851 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
4852 given by TYPE. If the argument list accepts variable arguments,
4853 then this function counts only the ordinary arguments. */
4856 type_num_arguments (const_tree type
)
4861 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
4862 /* If the function does not take a variable number of arguments,
4863 the last element in the list will have type `void'. */
4864 if (VOID_TYPE_P (TREE_VALUE (t
)))
4872 /* Nonzero if integer constants T1 and T2
4873 represent the same constant value. */
4876 tree_int_cst_equal (const_tree t1
, const_tree t2
)
4881 if (t1
== 0 || t2
== 0)
4884 if (TREE_CODE (t1
) == INTEGER_CST
4885 && TREE_CODE (t2
) == INTEGER_CST
4886 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
4887 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
4893 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
4894 The precise way of comparison depends on their data type. */
4897 tree_int_cst_lt (const_tree t1
, const_tree t2
)
4902 if (TYPE_UNSIGNED (TREE_TYPE (t1
)) != TYPE_UNSIGNED (TREE_TYPE (t2
)))
4904 int t1_sgn
= tree_int_cst_sgn (t1
);
4905 int t2_sgn
= tree_int_cst_sgn (t2
);
4907 if (t1_sgn
< t2_sgn
)
4909 else if (t1_sgn
> t2_sgn
)
4911 /* Otherwise, both are non-negative, so we compare them as
4912 unsigned just in case one of them would overflow a signed
4915 else if (!TYPE_UNSIGNED (TREE_TYPE (t1
)))
4916 return INT_CST_LT (t1
, t2
);
4918 return INT_CST_LT_UNSIGNED (t1
, t2
);
4921 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
4924 tree_int_cst_compare (const_tree t1
, const_tree t2
)
4926 if (tree_int_cst_lt (t1
, t2
))
4928 else if (tree_int_cst_lt (t2
, t1
))
4934 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
4935 the host. If POS is zero, the value can be represented in a single
4936 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
4937 be represented in a single unsigned HOST_WIDE_INT. */
4940 host_integerp (const_tree t
, int pos
)
4942 return (TREE_CODE (t
) == INTEGER_CST
4943 && ((TREE_INT_CST_HIGH (t
) == 0
4944 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) >= 0)
4945 || (! pos
&& TREE_INT_CST_HIGH (t
) == -1
4946 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0
4947 && (!TYPE_UNSIGNED (TREE_TYPE (t
))
4948 || (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
4949 && TYPE_IS_SIZETYPE (TREE_TYPE (t
)))))
4950 || (pos
&& TREE_INT_CST_HIGH (t
) == 0)));
4953 /* Return the HOST_WIDE_INT least significant bits of T if it is an
4954 INTEGER_CST and there is no overflow. POS is nonzero if the result must
4955 be non-negative. We must be able to satisfy the above conditions. */
4958 tree_low_cst (const_tree t
, int pos
)
4960 gcc_assert (host_integerp (t
, pos
));
4961 return TREE_INT_CST_LOW (t
);
4964 /* Return the most significant bit of the integer constant T. */
4967 tree_int_cst_msb (const_tree t
)
4971 unsigned HOST_WIDE_INT l
;
4973 /* Note that using TYPE_PRECISION here is wrong. We care about the
4974 actual bits, not the (arbitrary) range of the type. */
4975 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t
))) - 1;
4976 rshift_double (TREE_INT_CST_LOW (t
), TREE_INT_CST_HIGH (t
), prec
,
4977 2 * HOST_BITS_PER_WIDE_INT
, &l
, &h
, 0);
4978 return (l
& 1) == 1;
4981 /* Return an indication of the sign of the integer constant T.
4982 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
4983 Note that -1 will never be returned if T's type is unsigned. */
4986 tree_int_cst_sgn (const_tree t
)
4988 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
4990 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
4992 else if (TREE_INT_CST_HIGH (t
) < 0)
4998 /* Compare two constructor-element-type constants. Return 1 if the lists
4999 are known to be equal; otherwise return 0. */
5002 simple_cst_list_equal (const_tree l1
, const_tree l2
)
5004 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
5006 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
5009 l1
= TREE_CHAIN (l1
);
5010 l2
= TREE_CHAIN (l2
);
5016 /* Return truthvalue of whether T1 is the same tree structure as T2.
5017 Return 1 if they are the same.
5018 Return 0 if they are understandably different.
5019 Return -1 if either contains tree structure not understood by
5023 simple_cst_equal (const_tree t1
, const_tree t2
)
5025 enum tree_code code1
, code2
;
5031 if (t1
== 0 || t2
== 0)
5034 code1
= TREE_CODE (t1
);
5035 code2
= TREE_CODE (t2
);
5037 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
5039 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
5040 || code2
== NON_LVALUE_EXPR
)
5041 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5043 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
5046 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
5047 || code2
== NON_LVALUE_EXPR
)
5048 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
5056 return (TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
5057 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
));
5060 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
5063 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
5066 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
5067 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
5068 TREE_STRING_LENGTH (t1
)));
5072 unsigned HOST_WIDE_INT idx
;
5073 VEC(constructor_elt
, gc
) *v1
= CONSTRUCTOR_ELTS (t1
);
5074 VEC(constructor_elt
, gc
) *v2
= CONSTRUCTOR_ELTS (t2
);
5076 if (VEC_length (constructor_elt
, v1
) != VEC_length (constructor_elt
, v2
))
5079 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
5080 /* ??? Should we handle also fields here? */
5081 if (!simple_cst_equal (VEC_index (constructor_elt
, v1
, idx
)->value
,
5082 VEC_index (constructor_elt
, v2
, idx
)->value
))
5088 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5091 cmp
= simple_cst_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
));
5094 if (call_expr_nargs (t1
) != call_expr_nargs (t2
))
5097 const_tree arg1
, arg2
;
5098 const_call_expr_arg_iterator iter1
, iter2
;
5099 for (arg1
= first_const_call_expr_arg (t1
, &iter1
),
5100 arg2
= first_const_call_expr_arg (t2
, &iter2
);
5102 arg1
= next_const_call_expr_arg (&iter1
),
5103 arg2
= next_const_call_expr_arg (&iter2
))
5105 cmp
= simple_cst_equal (arg1
, arg2
);
5109 return arg1
== arg2
;
5113 /* Special case: if either target is an unallocated VAR_DECL,
5114 it means that it's going to be unified with whatever the
5115 TARGET_EXPR is really supposed to initialize, so treat it
5116 as being equivalent to anything. */
5117 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
5118 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
5119 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
5120 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
5121 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
5122 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
5125 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5130 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
5132 case WITH_CLEANUP_EXPR
:
5133 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5137 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
5140 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
5141 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5155 /* This general rule works for most tree codes. All exceptions should be
5156 handled above. If this is a language-specific tree code, we can't
5157 trust what might be in the operand, so say we don't know
5159 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
5162 switch (TREE_CODE_CLASS (code1
))
5166 case tcc_comparison
:
5167 case tcc_expression
:
5171 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
5173 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
5185 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
5186 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
5187 than U, respectively. */
5190 compare_tree_int (const_tree t
, unsigned HOST_WIDE_INT u
)
5192 if (tree_int_cst_sgn (t
) < 0)
5194 else if (TREE_INT_CST_HIGH (t
) != 0)
5196 else if (TREE_INT_CST_LOW (t
) == u
)
5198 else if (TREE_INT_CST_LOW (t
) < u
)
5204 /* Return true if CODE represents an associative tree code. Otherwise
5207 associative_tree_code (enum tree_code code
)
5226 /* Return true if CODE represents a commutative tree code. Otherwise
5229 commutative_tree_code (enum tree_code code
)
5242 case UNORDERED_EXPR
:
5246 case TRUTH_AND_EXPR
:
5247 case TRUTH_XOR_EXPR
:
5257 /* Generate a hash value for an expression. This can be used iteratively
5258 by passing a previous result as the "val" argument.
5260 This function is intended to produce the same hash for expressions which
5261 would compare equal using operand_equal_p. */
5264 iterative_hash_expr (const_tree t
, hashval_t val
)
5267 enum tree_code code
;
5271 return iterative_hash_pointer (t
, val
);
5273 code
= TREE_CODE (t
);
5277 /* Alas, constants aren't shared, so we can't rely on pointer
5280 val
= iterative_hash_host_wide_int (TREE_INT_CST_LOW (t
), val
);
5281 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t
), val
);
5284 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
5286 return iterative_hash_hashval_t (val2
, val
);
5290 unsigned int val2
= fixed_hash (TREE_FIXED_CST_PTR (t
));
5292 return iterative_hash_hashval_t (val2
, val
);
5295 return iterative_hash (TREE_STRING_POINTER (t
),
5296 TREE_STRING_LENGTH (t
), val
);
5298 val
= iterative_hash_expr (TREE_REALPART (t
), val
);
5299 return iterative_hash_expr (TREE_IMAGPART (t
), val
);
5301 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t
), val
);
5305 /* we can just compare by pointer. */
5306 return iterative_hash_pointer (t
, val
);
5309 /* A list of expressions, for a CALL_EXPR or as the elements of a
5311 for (; t
; t
= TREE_CHAIN (t
))
5312 val
= iterative_hash_expr (TREE_VALUE (t
), val
);
5316 unsigned HOST_WIDE_INT idx
;
5318 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
5320 val
= iterative_hash_expr (field
, val
);
5321 val
= iterative_hash_expr (value
, val
);
5326 /* When referring to a built-in FUNCTION_DECL, use the
5327 __builtin__ form. Otherwise nodes that compare equal
5328 according to operand_equal_p might get different
5330 if (DECL_BUILT_IN (t
))
5332 val
= iterative_hash_pointer (built_in_decls
[DECL_FUNCTION_CODE (t
)],
5336 /* else FALL THROUGH */
5338 class = TREE_CODE_CLASS (code
);
5340 if (class == tcc_declaration
)
5342 /* DECL's have a unique ID */
5343 val
= iterative_hash_host_wide_int (DECL_UID (t
), val
);
5347 gcc_assert (IS_EXPR_CODE_CLASS (class));
5349 val
= iterative_hash_object (code
, val
);
5351 /* Don't hash the type, that can lead to having nodes which
5352 compare equal according to operand_equal_p, but which
5353 have different hash codes. */
5354 if (code
== NOP_EXPR
5355 || code
== CONVERT_EXPR
5356 || code
== NON_LVALUE_EXPR
)
5358 /* Make sure to include signness in the hash computation. */
5359 val
+= TYPE_UNSIGNED (TREE_TYPE (t
));
5360 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
5363 else if (commutative_tree_code (code
))
5365 /* It's a commutative expression. We want to hash it the same
5366 however it appears. We do this by first hashing both operands
5367 and then rehashing based on the order of their independent
5369 hashval_t one
= iterative_hash_expr (TREE_OPERAND (t
, 0), 0);
5370 hashval_t two
= iterative_hash_expr (TREE_OPERAND (t
, 1), 0);
5374 t
= one
, one
= two
, two
= t
;
5376 val
= iterative_hash_hashval_t (one
, val
);
5377 val
= iterative_hash_hashval_t (two
, val
);
5380 for (i
= TREE_OPERAND_LENGTH (t
) - 1; i
>= 0; --i
)
5381 val
= iterative_hash_expr (TREE_OPERAND (t
, i
), val
);
5388 /* Constructors for pointer, array and function types.
5389 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
5390 constructed by language-dependent code, not here.) */
5392 /* Construct, lay out and return the type of pointers to TO_TYPE with
5393 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
5394 reference all of memory. If such a type has already been
5395 constructed, reuse it. */
5398 build_pointer_type_for_mode (tree to_type
, enum machine_mode mode
,
5403 if (to_type
== error_mark_node
)
5404 return error_mark_node
;
5406 /* In some cases, languages will have things that aren't a POINTER_TYPE
5407 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
5408 In that case, return that type without regard to the rest of our
5411 ??? This is a kludge, but consistent with the way this function has
5412 always operated and there doesn't seem to be a good way to avoid this
5414 if (TYPE_POINTER_TO (to_type
) != 0
5415 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
5416 return TYPE_POINTER_TO (to_type
);
5418 /* First, if we already have a type for pointers to TO_TYPE and it's
5419 the proper mode, use it. */
5420 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
5421 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
5424 t
= make_node (POINTER_TYPE
);
5426 TREE_TYPE (t
) = to_type
;
5427 TYPE_MODE (t
) = mode
;
5428 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
5429 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
5430 TYPE_POINTER_TO (to_type
) = t
;
5432 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
5433 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5434 else if (TYPE_CANONICAL (to_type
) != to_type
)
5436 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
5437 mode
, can_alias_all
);
5439 /* Lay out the type. This function has many callers that are concerned
5440 with expression-construction, and this simplifies them all. */
5446 /* By default build pointers in ptr_mode. */
5449 build_pointer_type (tree to_type
)
5451 return build_pointer_type_for_mode (to_type
, ptr_mode
, false);
5454 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
5457 build_reference_type_for_mode (tree to_type
, enum machine_mode mode
,
5462 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
5463 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
5464 In that case, return that type without regard to the rest of our
5467 ??? This is a kludge, but consistent with the way this function has
5468 always operated and there doesn't seem to be a good way to avoid this
5470 if (TYPE_REFERENCE_TO (to_type
) != 0
5471 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
5472 return TYPE_REFERENCE_TO (to_type
);
5474 /* First, if we already have a type for pointers to TO_TYPE and it's
5475 the proper mode, use it. */
5476 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
5477 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
5480 t
= make_node (REFERENCE_TYPE
);
5482 TREE_TYPE (t
) = to_type
;
5483 TYPE_MODE (t
) = mode
;
5484 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
5485 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
5486 TYPE_REFERENCE_TO (to_type
) = t
;
5488 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
5489 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5490 else if (TYPE_CANONICAL (to_type
) != to_type
)
5492 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
5493 mode
, can_alias_all
);
5501 /* Build the node for the type of references-to-TO_TYPE by default
5505 build_reference_type (tree to_type
)
5507 return build_reference_type_for_mode (to_type
, ptr_mode
, false);
5510 /* Build a type that is compatible with t but has no cv quals anywhere
5513 const char *const *const * -> char ***. */
5516 build_type_no_quals (tree t
)
5518 switch (TREE_CODE (t
))
5521 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
5523 TYPE_REF_CAN_ALIAS_ALL (t
));
5524 case REFERENCE_TYPE
:
5526 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
5528 TYPE_REF_CAN_ALIAS_ALL (t
));
5530 return TYPE_MAIN_VARIANT (t
);
5534 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
5535 MAXVAL should be the maximum value in the domain
5536 (one less than the length of the array).
5538 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
5539 We don't enforce this limit, that is up to caller (e.g. language front end).
5540 The limit exists because the result is a signed type and we don't handle
5541 sizes that use more than one HOST_WIDE_INT. */
5544 build_index_type (tree maxval
)
5546 tree itype
= make_node (INTEGER_TYPE
);
5548 TREE_TYPE (itype
) = sizetype
;
5549 TYPE_PRECISION (itype
) = TYPE_PRECISION (sizetype
);
5550 TYPE_MIN_VALUE (itype
) = size_zero_node
;
5551 TYPE_MAX_VALUE (itype
) = fold_convert (sizetype
, maxval
);
5552 TYPE_MODE (itype
) = TYPE_MODE (sizetype
);
5553 TYPE_SIZE (itype
) = TYPE_SIZE (sizetype
);
5554 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (sizetype
);
5555 TYPE_ALIGN (itype
) = TYPE_ALIGN (sizetype
);
5556 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (sizetype
);
5558 if (host_integerp (maxval
, 1))
5559 return type_hash_canon (tree_low_cst (maxval
, 1), itype
);
5562 /* Since we cannot hash this type, we need to compare it using
5563 structural equality checks. */
5564 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
5569 /* Builds a signed or unsigned integer type of precision PRECISION.
5570 Used for C bitfields whose precision does not match that of
5571 built-in target types. */
5573 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
5576 tree itype
= make_node (INTEGER_TYPE
);
5578 TYPE_PRECISION (itype
) = precision
;
5581 fixup_unsigned_type (itype
);
5583 fixup_signed_type (itype
);
5585 if (host_integerp (TYPE_MAX_VALUE (itype
), 1))
5586 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype
), 1), itype
);
5591 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
5592 ENUMERAL_TYPE or BOOLEAN_TYPE), with low bound LOWVAL and
5593 high bound HIGHVAL. If TYPE is NULL, sizetype is used. */
5596 build_range_type (tree type
, tree lowval
, tree highval
)
5598 tree itype
= make_node (INTEGER_TYPE
);
5600 TREE_TYPE (itype
) = type
;
5601 if (type
== NULL_TREE
)
5604 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
5605 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
5607 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
5608 TYPE_MODE (itype
) = TYPE_MODE (type
);
5609 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
5610 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
5611 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
5612 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
5614 if (host_integerp (lowval
, 0) && highval
!= 0 && host_integerp (highval
, 0))
5615 return type_hash_canon (tree_low_cst (highval
, 0)
5616 - tree_low_cst (lowval
, 0),
5622 /* Just like build_index_type, but takes lowval and highval instead
5623 of just highval (maxval). */
5626 build_index_2_type (tree lowval
, tree highval
)
5628 return build_range_type (sizetype
, lowval
, highval
);
5631 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
5632 and number of elements specified by the range of values of INDEX_TYPE.
5633 If such a type has already been constructed, reuse it. */
5636 build_array_type (tree elt_type
, tree index_type
)
5639 hashval_t hashcode
= 0;
5641 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
5643 error ("arrays of functions are not meaningful");
5644 elt_type
= integer_type_node
;
5647 t
= make_node (ARRAY_TYPE
);
5648 TREE_TYPE (t
) = elt_type
;
5649 TYPE_DOMAIN (t
) = index_type
;
5651 if (index_type
== 0)
5654 hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), hashcode
);
5655 t
= type_hash_canon (hashcode
, t
);
5659 if (TYPE_CANONICAL (t
) == t
)
5661 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
))
5662 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5663 else if (TYPE_CANONICAL (elt_type
) != elt_type
)
5665 = build_array_type (TYPE_CANONICAL (elt_type
), index_type
);
5671 hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), hashcode
);
5672 hashcode
= iterative_hash_object (TYPE_HASH (index_type
), hashcode
);
5673 t
= type_hash_canon (hashcode
, t
);
5675 if (!COMPLETE_TYPE_P (t
))
5678 if (TYPE_CANONICAL (t
) == t
)
5680 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
5681 || TYPE_STRUCTURAL_EQUALITY_P (index_type
))
5682 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5683 else if (TYPE_CANONICAL (elt_type
) != elt_type
5684 || TYPE_CANONICAL (index_type
) != index_type
)
5686 = build_array_type (TYPE_CANONICAL (elt_type
),
5687 TYPE_CANONICAL (index_type
));
5693 /* Return the TYPE of the elements comprising
5694 the innermost dimension of ARRAY. */
5697 get_inner_array_type (const_tree array
)
5699 tree type
= TREE_TYPE (array
);
5701 while (TREE_CODE (type
) == ARRAY_TYPE
)
5702 type
= TREE_TYPE (type
);
5707 /* Computes the canonical argument types from the argument type list
5710 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
5711 on entry to this function, or if any of the ARGTYPES are
5714 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
5715 true on entry to this function, or if any of the ARGTYPES are
5718 Returns a canonical argument list, which may be ARGTYPES when the
5719 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
5720 true) or would not differ from ARGTYPES. */
5723 maybe_canonicalize_argtypes(tree argtypes
,
5724 bool *any_structural_p
,
5725 bool *any_noncanonical_p
)
5728 bool any_noncanonical_argtypes_p
= false;
5730 for (arg
= argtypes
; arg
&& !(*any_structural_p
); arg
= TREE_CHAIN (arg
))
5732 if (!TREE_VALUE (arg
) || TREE_VALUE (arg
) == error_mark_node
)
5733 /* Fail gracefully by stating that the type is structural. */
5734 *any_structural_p
= true;
5735 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg
)))
5736 *any_structural_p
= true;
5737 else if (TYPE_CANONICAL (TREE_VALUE (arg
)) != TREE_VALUE (arg
)
5738 || TREE_PURPOSE (arg
))
5739 /* If the argument has a default argument, we consider it
5740 non-canonical even though the type itself is canonical.
5741 That way, different variants of function and method types
5742 with default arguments will all point to the variant with
5743 no defaults as their canonical type. */
5744 any_noncanonical_argtypes_p
= true;
5747 if (*any_structural_p
)
5750 if (any_noncanonical_argtypes_p
)
5752 /* Build the canonical list of argument types. */
5753 tree canon_argtypes
= NULL_TREE
;
5754 bool is_void
= false;
5756 for (arg
= argtypes
; arg
; arg
= TREE_CHAIN (arg
))
5758 if (arg
== void_list_node
)
5761 canon_argtypes
= tree_cons (NULL_TREE
,
5762 TYPE_CANONICAL (TREE_VALUE (arg
)),
5766 canon_argtypes
= nreverse (canon_argtypes
);
5768 canon_argtypes
= chainon (canon_argtypes
, void_list_node
);
5770 /* There is a non-canonical type. */
5771 *any_noncanonical_p
= true;
5772 return canon_argtypes
;
5775 /* The canonical argument types are the same as ARGTYPES. */
5779 /* Construct, lay out and return
5780 the type of functions returning type VALUE_TYPE
5781 given arguments of types ARG_TYPES.
5782 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
5783 are data type nodes for the arguments of the function.
5784 If such a type has already been constructed, reuse it. */
5787 build_function_type (tree value_type
, tree arg_types
)
5790 hashval_t hashcode
= 0;
5791 bool any_structural_p
, any_noncanonical_p
;
5792 tree canon_argtypes
;
5794 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
5796 error ("function return type cannot be function");
5797 value_type
= integer_type_node
;
5800 /* Make a node of the sort we want. */
5801 t
= make_node (FUNCTION_TYPE
);
5802 TREE_TYPE (t
) = value_type
;
5803 TYPE_ARG_TYPES (t
) = arg_types
;
5805 /* If we already have such a type, use the old one. */
5806 hashcode
= iterative_hash_object (TYPE_HASH (value_type
), hashcode
);
5807 hashcode
= type_hash_list (arg_types
, hashcode
);
5808 t
= type_hash_canon (hashcode
, t
);
5810 /* Set up the canonical type. */
5811 any_structural_p
= TYPE_STRUCTURAL_EQUALITY_P (value_type
);
5812 any_noncanonical_p
= TYPE_CANONICAL (value_type
) != value_type
;
5813 canon_argtypes
= maybe_canonicalize_argtypes (arg_types
,
5815 &any_noncanonical_p
);
5816 if (any_structural_p
)
5817 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5818 else if (any_noncanonical_p
)
5819 TYPE_CANONICAL (t
) = build_function_type (TYPE_CANONICAL (value_type
),
5822 if (!COMPLETE_TYPE_P (t
))
5827 /* Build a function type. The RETURN_TYPE is the type returned by the
5828 function. If additional arguments are provided, they are
5829 additional argument types. The list of argument types must always
5830 be terminated by NULL_TREE. */
5833 build_function_type_list (tree return_type
, ...)
5838 va_start (p
, return_type
);
5840 t
= va_arg (p
, tree
);
5841 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (p
, tree
))
5842 args
= tree_cons (NULL_TREE
, t
, args
);
5844 if (args
== NULL_TREE
)
5845 args
= void_list_node
;
5849 args
= nreverse (args
);
5850 TREE_CHAIN (last
) = void_list_node
;
5852 args
= build_function_type (return_type
, args
);
5858 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
5859 and ARGTYPES (a TREE_LIST) are the return type and arguments types
5860 for the method. An implicit additional parameter (of type
5861 pointer-to-BASETYPE) is added to the ARGTYPES. */
5864 build_method_type_directly (tree basetype
,
5871 bool any_structural_p
, any_noncanonical_p
;
5872 tree canon_argtypes
;
5874 /* Make a node of the sort we want. */
5875 t
= make_node (METHOD_TYPE
);
5877 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
5878 TREE_TYPE (t
) = rettype
;
5879 ptype
= build_pointer_type (basetype
);
5881 /* The actual arglist for this function includes a "hidden" argument
5882 which is "this". Put it into the list of argument types. */
5883 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
5884 TYPE_ARG_TYPES (t
) = argtypes
;
5886 /* If we already have such a type, use the old one. */
5887 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
5888 hashcode
= iterative_hash_object (TYPE_HASH (rettype
), hashcode
);
5889 hashcode
= type_hash_list (argtypes
, hashcode
);
5890 t
= type_hash_canon (hashcode
, t
);
5892 /* Set up the canonical type. */
5894 = (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
5895 || TYPE_STRUCTURAL_EQUALITY_P (rettype
));
5897 = (TYPE_CANONICAL (basetype
) != basetype
5898 || TYPE_CANONICAL (rettype
) != rettype
);
5899 canon_argtypes
= maybe_canonicalize_argtypes (TREE_CHAIN (argtypes
),
5901 &any_noncanonical_p
);
5902 if (any_structural_p
)
5903 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5904 else if (any_noncanonical_p
)
5906 = build_method_type_directly (TYPE_CANONICAL (basetype
),
5907 TYPE_CANONICAL (rettype
),
5909 if (!COMPLETE_TYPE_P (t
))
5915 /* Construct, lay out and return the type of methods belonging to class
5916 BASETYPE and whose arguments and values are described by TYPE.
5917 If that type exists already, reuse it.
5918 TYPE must be a FUNCTION_TYPE node. */
5921 build_method_type (tree basetype
, tree type
)
5923 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
5925 return build_method_type_directly (basetype
,
5927 TYPE_ARG_TYPES (type
));
5930 /* Construct, lay out and return the type of offsets to a value
5931 of type TYPE, within an object of type BASETYPE.
5932 If a suitable offset type exists already, reuse it. */
5935 build_offset_type (tree basetype
, tree type
)
5938 hashval_t hashcode
= 0;
5940 /* Make a node of the sort we want. */
5941 t
= make_node (OFFSET_TYPE
);
5943 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
5944 TREE_TYPE (t
) = type
;
5946 /* If we already have such a type, use the old one. */
5947 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
5948 hashcode
= iterative_hash_object (TYPE_HASH (type
), hashcode
);
5949 t
= type_hash_canon (hashcode
, t
);
5951 if (!COMPLETE_TYPE_P (t
))
5954 if (TYPE_CANONICAL (t
) == t
)
5956 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
5957 || TYPE_STRUCTURAL_EQUALITY_P (type
))
5958 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5959 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)) != basetype
5960 || TYPE_CANONICAL (type
) != type
)
5962 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)),
5963 TYPE_CANONICAL (type
));
5969 /* Create a complex type whose components are COMPONENT_TYPE. */
5972 build_complex_type (tree component_type
)
5977 /* Make a node of the sort we want. */
5978 t
= make_node (COMPLEX_TYPE
);
5980 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
5982 /* If we already have such a type, use the old one. */
5983 hashcode
= iterative_hash_object (TYPE_HASH (component_type
), 0);
5984 t
= type_hash_canon (hashcode
, t
);
5986 if (!COMPLETE_TYPE_P (t
))
5989 if (TYPE_CANONICAL (t
) == t
)
5991 if (TYPE_STRUCTURAL_EQUALITY_P (component_type
))
5992 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5993 else if (TYPE_CANONICAL (component_type
) != component_type
)
5995 = build_complex_type (TYPE_CANONICAL (component_type
));
5998 /* We need to create a name, since complex is a fundamental type. */
5999 if (! TYPE_NAME (t
))
6002 if (component_type
== char_type_node
)
6003 name
= "complex char";
6004 else if (component_type
== signed_char_type_node
)
6005 name
= "complex signed char";
6006 else if (component_type
== unsigned_char_type_node
)
6007 name
= "complex unsigned char";
6008 else if (component_type
== short_integer_type_node
)
6009 name
= "complex short int";
6010 else if (component_type
== short_unsigned_type_node
)
6011 name
= "complex short unsigned int";
6012 else if (component_type
== integer_type_node
)
6013 name
= "complex int";
6014 else if (component_type
== unsigned_type_node
)
6015 name
= "complex unsigned int";
6016 else if (component_type
== long_integer_type_node
)
6017 name
= "complex long int";
6018 else if (component_type
== long_unsigned_type_node
)
6019 name
= "complex long unsigned int";
6020 else if (component_type
== long_long_integer_type_node
)
6021 name
= "complex long long int";
6022 else if (component_type
== long_long_unsigned_type_node
)
6023 name
= "complex long long unsigned int";
6028 TYPE_NAME (t
) = build_decl (TYPE_DECL
, get_identifier (name
), t
);
6031 return build_qualified_type (t
, TYPE_QUALS (component_type
));
6034 /* Return OP, stripped of any conversions to wider types as much as is safe.
6035 Converting the value back to OP's type makes a value equivalent to OP.
6037 If FOR_TYPE is nonzero, we return a value which, if converted to
6038 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
6040 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
6041 narrowest type that can hold the value, even if they don't exactly fit.
6042 Otherwise, bit-field references are changed to a narrower type
6043 only if they can be fetched directly from memory in that type.
6045 OP must have integer, real or enumeral type. Pointers are not allowed!
6047 There are some cases where the obvious value we could return
6048 would regenerate to OP if converted to OP's type,
6049 but would not extend like OP to wider types.
6050 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
6051 For example, if OP is (unsigned short)(signed char)-1,
6052 we avoid returning (signed char)-1 if FOR_TYPE is int,
6053 even though extending that to an unsigned short would regenerate OP,
6054 since the result of extending (signed char)-1 to (int)
6055 is different from (int) OP. */
6058 get_unwidened (tree op
, tree for_type
)
6060 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
6061 tree type
= TREE_TYPE (op
);
6063 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
6065 = (for_type
!= 0 && for_type
!= type
6066 && final_prec
> TYPE_PRECISION (type
)
6067 && TYPE_UNSIGNED (type
));
6070 while (TREE_CODE (op
) == NOP_EXPR
6071 || TREE_CODE (op
) == CONVERT_EXPR
)
6075 /* TYPE_PRECISION on vector types has different meaning
6076 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
6077 so avoid them here. */
6078 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
6081 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
6082 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
6084 /* Truncations are many-one so cannot be removed.
6085 Unless we are later going to truncate down even farther. */
6087 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
6090 /* See what's inside this conversion. If we decide to strip it,
6092 op
= TREE_OPERAND (op
, 0);
6094 /* If we have not stripped any zero-extensions (uns is 0),
6095 we can strip any kind of extension.
6096 If we have previously stripped a zero-extension,
6097 only zero-extensions can safely be stripped.
6098 Any extension can be stripped if the bits it would produce
6099 are all going to be discarded later by truncating to FOR_TYPE. */
6103 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
6105 /* TYPE_UNSIGNED says whether this is a zero-extension.
6106 Let's avoid computing it if it does not affect WIN
6107 and if UNS will not be needed again. */
6109 || TREE_CODE (op
) == NOP_EXPR
6110 || TREE_CODE (op
) == CONVERT_EXPR
)
6111 && TYPE_UNSIGNED (TREE_TYPE (op
)))
6119 if (TREE_CODE (op
) == COMPONENT_REF
6120 /* Since type_for_size always gives an integer type. */
6121 && TREE_CODE (type
) != REAL_TYPE
6122 && TREE_CODE (type
) != FIXED_POINT_TYPE
6123 /* Don't crash if field not laid out yet. */
6124 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
6125 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
6127 unsigned int innerprec
6128 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
6129 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
6130 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
6131 type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
6133 /* We can get this structure field in the narrowest type it fits in.
6134 If FOR_TYPE is 0, do this only for a field that matches the
6135 narrower type exactly and is aligned for it
6136 The resulting extension to its nominal type (a fullword type)
6137 must fit the same conditions as for other extensions. */
6140 && INT_CST_LT_UNSIGNED (TYPE_SIZE (type
), TYPE_SIZE (TREE_TYPE (op
)))
6141 && (for_type
|| ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1)))
6142 && (! uns
|| final_prec
<= innerprec
|| unsignedp
))
6144 win
= build3 (COMPONENT_REF
, type
, TREE_OPERAND (op
, 0),
6145 TREE_OPERAND (op
, 1), NULL_TREE
);
6146 TREE_SIDE_EFFECTS (win
) = TREE_SIDE_EFFECTS (op
);
6147 TREE_THIS_VOLATILE (win
) = TREE_THIS_VOLATILE (op
);
6154 /* Return OP or a simpler expression for a narrower value
6155 which can be sign-extended or zero-extended to give back OP.
6156 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
6157 or 0 if the value should be sign-extended. */
6160 get_narrower (tree op
, int *unsignedp_ptr
)
6165 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
6167 while (TREE_CODE (op
) == NOP_EXPR
)
6170 = (TYPE_PRECISION (TREE_TYPE (op
))
6171 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
6173 /* Truncations are many-one so cannot be removed. */
6177 /* See what's inside this conversion. If we decide to strip it,
6182 op
= TREE_OPERAND (op
, 0);
6183 /* An extension: the outermost one can be stripped,
6184 but remember whether it is zero or sign extension. */
6186 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
6187 /* Otherwise, if a sign extension has been stripped,
6188 only sign extensions can now be stripped;
6189 if a zero extension has been stripped, only zero-extensions. */
6190 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
6194 else /* bitschange == 0 */
6196 /* A change in nominal type can always be stripped, but we must
6197 preserve the unsignedness. */
6199 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
6201 op
= TREE_OPERAND (op
, 0);
6202 /* Keep trying to narrow, but don't assign op to win if it
6203 would turn an integral type into something else. */
6204 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
6211 if (TREE_CODE (op
) == COMPONENT_REF
6212 /* Since type_for_size always gives an integer type. */
6213 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
6214 && TREE_CODE (TREE_TYPE (op
)) != FIXED_POINT_TYPE
6215 /* Ensure field is laid out already. */
6216 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
6217 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
6219 unsigned HOST_WIDE_INT innerprec
6220 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
6221 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
6222 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
6223 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
6225 /* We can get this structure field in a narrower type that fits it,
6226 but the resulting extension to its nominal type (a fullword type)
6227 must satisfy the same conditions as for other extensions.
6229 Do this only for fields that are aligned (not bit-fields),
6230 because when bit-field insns will be used there is no
6231 advantage in doing this. */
6233 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
6234 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
6235 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
6239 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
6240 win
= fold_convert (type
, op
);
6244 *unsignedp_ptr
= uns
;
6248 /* Nonzero if integer constant C has a value that is permissible
6249 for type TYPE (an INTEGER_TYPE). */
6252 int_fits_type_p (const_tree c
, const_tree type
)
6254 tree type_low_bound
= TYPE_MIN_VALUE (type
);
6255 tree type_high_bound
= TYPE_MAX_VALUE (type
);
6256 bool ok_for_low_bound
, ok_for_high_bound
;
6257 unsigned HOST_WIDE_INT low
;
6260 /* If at least one bound of the type is a constant integer, we can check
6261 ourselves and maybe make a decision. If no such decision is possible, but
6262 this type is a subtype, try checking against that. Otherwise, use
6263 fit_double_type, which checks against the precision.
6265 Compute the status for each possibly constant bound, and return if we see
6266 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
6267 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
6268 for "constant known to fit". */
6270 /* Check if C >= type_low_bound. */
6271 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
6273 if (tree_int_cst_lt (c
, type_low_bound
))
6275 ok_for_low_bound
= true;
6278 ok_for_low_bound
= false;
6280 /* Check if c <= type_high_bound. */
6281 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
6283 if (tree_int_cst_lt (type_high_bound
, c
))
6285 ok_for_high_bound
= true;
6288 ok_for_high_bound
= false;
6290 /* If the constant fits both bounds, the result is known. */
6291 if (ok_for_low_bound
&& ok_for_high_bound
)
6294 /* Perform some generic filtering which may allow making a decision
6295 even if the bounds are not constant. First, negative integers
6296 never fit in unsigned types, */
6297 if (TYPE_UNSIGNED (type
) && tree_int_cst_sgn (c
) < 0)
6300 /* Second, narrower types always fit in wider ones. */
6301 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
6304 /* Third, unsigned integers with top bit set never fit signed types. */
6305 if (! TYPE_UNSIGNED (type
)
6306 && TYPE_UNSIGNED (TREE_TYPE (c
))
6307 && tree_int_cst_msb (c
))
6310 /* If we haven't been able to decide at this point, there nothing more we
6311 can check ourselves here. Look at the base type if we have one and it
6312 has the same precision. */
6313 if (TREE_CODE (type
) == INTEGER_TYPE
6314 && TREE_TYPE (type
) != 0
6315 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
6316 return int_fits_type_p (c
, TREE_TYPE (type
));
6318 /* Or to fit_double_type, if nothing else. */
6319 low
= TREE_INT_CST_LOW (c
);
6320 high
= TREE_INT_CST_HIGH (c
);
6321 return !fit_double_type (low
, high
, &low
, &high
, type
);
6324 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
6325 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
6326 represented (assuming two's-complement arithmetic) within the bit
6327 precision of the type are returned instead. */
6330 get_type_static_bounds (const_tree type
, mpz_t min
, mpz_t max
)
6332 if (!POINTER_TYPE_P (type
) && TYPE_MIN_VALUE (type
)
6333 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
6334 mpz_set_double_int (min
, tree_to_double_int (TYPE_MIN_VALUE (type
)),
6335 TYPE_UNSIGNED (type
));
6338 if (TYPE_UNSIGNED (type
))
6339 mpz_set_ui (min
, 0);
6343 mn
= double_int_mask (TYPE_PRECISION (type
) - 1);
6344 mn
= double_int_sext (double_int_add (mn
, double_int_one
),
6345 TYPE_PRECISION (type
));
6346 mpz_set_double_int (min
, mn
, false);
6350 if (!POINTER_TYPE_P (type
) && TYPE_MAX_VALUE (type
)
6351 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
)
6352 mpz_set_double_int (max
, tree_to_double_int (TYPE_MAX_VALUE (type
)),
6353 TYPE_UNSIGNED (type
));
6356 if (TYPE_UNSIGNED (type
))
6357 mpz_set_double_int (max
, double_int_mask (TYPE_PRECISION (type
)),
6360 mpz_set_double_int (max
, double_int_mask (TYPE_PRECISION (type
) - 1),
6365 /* auto_var_in_fn_p is called to determine whether VAR is an automatic
6366 variable defined in function FN. */
6369 auto_var_in_fn_p (const_tree var
, const_tree fn
)
6371 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
6372 && (((TREE_CODE (var
) == VAR_DECL
|| TREE_CODE (var
) == PARM_DECL
)
6373 && ! TREE_STATIC (var
))
6374 || TREE_CODE (var
) == LABEL_DECL
6375 || TREE_CODE (var
) == RESULT_DECL
));
6378 /* Subprogram of following function. Called by walk_tree.
6380 Return *TP if it is an automatic variable or parameter of the
6381 function passed in as DATA. */
6384 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
6386 tree fn
= (tree
) data
;
6391 else if (DECL_P (*tp
)
6392 && auto_var_in_fn_p (*tp
, fn
))
6398 /* Returns true if T is, contains, or refers to a type with variable
6399 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
6400 arguments, but not the return type. If FN is nonzero, only return
6401 true if a modifier of the type or position of FN is a variable or
6402 parameter inside FN.
6404 This concept is more general than that of C99 'variably modified types':
6405 in C99, a struct type is never variably modified because a VLA may not
6406 appear as a structure member. However, in GNU C code like:
6408 struct S { int i[f()]; };
6410 is valid, and other languages may define similar constructs. */
6413 variably_modified_type_p (tree type
, tree fn
)
6417 /* Test if T is either variable (if FN is zero) or an expression containing
6418 a variable in FN. */
6419 #define RETURN_TRUE_IF_VAR(T) \
6420 do { tree _t = (T); \
6421 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
6422 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
6423 return true; } while (0)
6425 if (type
== error_mark_node
)
6428 /* If TYPE itself has variable size, it is variably modified. */
6429 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
6430 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
6432 switch (TREE_CODE (type
))
6435 case REFERENCE_TYPE
:
6437 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
6443 /* If TYPE is a function type, it is variably modified if the
6444 return type is variably modified. */
6445 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
6451 case FIXED_POINT_TYPE
:
6454 /* Scalar types are variably modified if their end points
6456 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
6457 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
6462 case QUAL_UNION_TYPE
:
6463 /* We can't see if any of the fields are variably-modified by the
6464 definition we normally use, since that would produce infinite
6465 recursion via pointers. */
6466 /* This is variably modified if some field's type is. */
6467 for (t
= TYPE_FIELDS (type
); t
; t
= TREE_CHAIN (t
))
6468 if (TREE_CODE (t
) == FIELD_DECL
)
6470 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
6471 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
6472 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
6474 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
6475 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
6480 /* Do not call ourselves to avoid infinite recursion. This is
6481 variably modified if the element type is. */
6482 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
6483 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
6490 /* The current language may have other cases to check, but in general,
6491 all other types are not variably modified. */
6492 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
6494 #undef RETURN_TRUE_IF_VAR
6497 /* Given a DECL or TYPE, return the scope in which it was declared, or
6498 NULL_TREE if there is no containing scope. */
6501 get_containing_scope (const_tree t
)
6503 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
6506 /* Return the innermost context enclosing DECL that is
6507 a FUNCTION_DECL, or zero if none. */
6510 decl_function_context (const_tree decl
)
6514 if (TREE_CODE (decl
) == ERROR_MARK
)
6517 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
6518 where we look up the function at runtime. Such functions always take
6519 a first argument of type 'pointer to real context'.
6521 C++ should really be fixed to use DECL_CONTEXT for the real context,
6522 and use something else for the "virtual context". */
6523 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
6526 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
6528 context
= DECL_CONTEXT (decl
);
6530 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
6532 if (TREE_CODE (context
) == BLOCK
)
6533 context
= BLOCK_SUPERCONTEXT (context
);
6535 context
= get_containing_scope (context
);
6541 /* Return the innermost context enclosing DECL that is
6542 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
6543 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
6546 decl_type_context (const_tree decl
)
6548 tree context
= DECL_CONTEXT (decl
);
6551 switch (TREE_CODE (context
))
6553 case NAMESPACE_DECL
:
6554 case TRANSLATION_UNIT_DECL
:
6559 case QUAL_UNION_TYPE
:
6564 context
= DECL_CONTEXT (context
);
6568 context
= BLOCK_SUPERCONTEXT (context
);
6578 /* CALL is a CALL_EXPR. Return the declaration for the function
6579 called, or NULL_TREE if the called function cannot be
6583 get_callee_fndecl (const_tree call
)
6587 if (call
== error_mark_node
)
6588 return error_mark_node
;
6590 /* It's invalid to call this function with anything but a
6592 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
6594 /* The first operand to the CALL is the address of the function
6596 addr
= CALL_EXPR_FN (call
);
6600 /* If this is a readonly function pointer, extract its initial value. */
6601 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
6602 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
6603 && DECL_INITIAL (addr
))
6604 addr
= DECL_INITIAL (addr
);
6606 /* If the address is just `&f' for some function `f', then we know
6607 that `f' is being called. */
6608 if (TREE_CODE (addr
) == ADDR_EXPR
6609 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
6610 return TREE_OPERAND (addr
, 0);
6612 /* We couldn't figure out what was being called. Maybe the front
6613 end has some idea. */
6614 return lang_hooks
.lang_get_callee_fndecl (call
);
6617 /* Print debugging information about tree nodes generated during the compile,
6618 and any language-specific information. */
6621 dump_tree_statistics (void)
6623 #ifdef GATHER_STATISTICS
6625 int total_nodes
, total_bytes
;
6628 fprintf (stderr
, "\n??? tree nodes created\n\n");
6629 #ifdef GATHER_STATISTICS
6630 fprintf (stderr
, "Kind Nodes Bytes\n");
6631 fprintf (stderr
, "---------------------------------------\n");
6632 total_nodes
= total_bytes
= 0;
6633 for (i
= 0; i
< (int) all_kinds
; i
++)
6635 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
6636 tree_node_counts
[i
], tree_node_sizes
[i
]);
6637 total_nodes
+= tree_node_counts
[i
];
6638 total_bytes
+= tree_node_sizes
[i
];
6640 fprintf (stderr
, "---------------------------------------\n");
6641 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
6642 fprintf (stderr
, "---------------------------------------\n");
6643 ssanames_print_statistics ();
6644 phinodes_print_statistics ();
6646 fprintf (stderr
, "(No per-node statistics)\n");
6648 print_type_hash_statistics ();
6649 print_debug_expr_statistics ();
6650 print_value_expr_statistics ();
6651 print_restrict_base_statistics ();
6652 print_decl_for_uid_map_statistics ();
6653 lang_hooks
.print_statistics ();
6656 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
6658 /* Generate a crc32 of a string. */
6661 crc32_string (unsigned chksum
, const char *string
)
6665 unsigned value
= *string
<< 24;
6668 for (ix
= 8; ix
--; value
<<= 1)
6672 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
6681 /* P is a string that will be used in a symbol. Mask out any characters
6682 that are not valid in that context. */
6685 clean_symbol_name (char *p
)
6689 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
6692 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
6699 /* Generate a name for a special-purpose function function.
6700 The generated name may need to be unique across the whole link.
6701 TYPE is some string to identify the purpose of this function to the
6702 linker or collect2; it must start with an uppercase letter,
6704 I - for constructors
6706 N - for C++ anonymous namespaces
6707 F - for DWARF unwind frame information. */
6710 get_file_function_name (const char *type
)
6716 /* If we already have a name we know to be unique, just use that. */
6717 if (first_global_object_name
)
6718 p
= first_global_object_name
;
6719 /* If the target is handling the constructors/destructors, they
6720 will be local to this file and the name is only necessary for
6721 debugging purposes. */
6722 else if ((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
6724 const char *file
= main_input_filename
;
6726 file
= input_filename
;
6727 /* Just use the file's basename, because the full pathname
6728 might be quite long. */
6729 p
= strrchr (file
, '/');
6734 p
= q
= ASTRDUP (p
);
6735 clean_symbol_name (q
);
6739 /* Otherwise, the name must be unique across the entire link.
6740 We don't have anything that we know to be unique to this translation
6741 unit, so use what we do have and throw in some randomness. */
6743 const char *name
= weak_global_object_name
;
6744 const char *file
= main_input_filename
;
6749 file
= input_filename
;
6751 len
= strlen (file
);
6752 q
= alloca (9 * 2 + len
+ 1);
6753 memcpy (q
, file
, len
+ 1);
6754 clean_symbol_name (q
);
6756 sprintf (q
+ len
, "_%08X_%08X", crc32_string (0, name
),
6757 crc32_string (0, get_random_seed (false)));
6762 buf
= alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
) + strlen (type
));
6764 /* Set up the name of the file-level functions we may need.
6765 Use a global object (which is already required to be unique over
6766 the program) rather than the file name (which imposes extra
6768 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
6770 return get_identifier (buf
);
6773 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
6775 /* Complain that the tree code of NODE does not match the expected 0
6776 terminated list of trailing codes. The trailing code list can be
6777 empty, for a more vague error message. FILE, LINE, and FUNCTION
6778 are of the caller. */
6781 tree_check_failed (const_tree node
, const char *file
,
6782 int line
, const char *function
, ...)
6786 unsigned length
= 0;
6789 va_start (args
, function
);
6790 while ((code
= va_arg (args
, int)))
6791 length
+= 4 + strlen (tree_code_name
[code
]);
6796 va_start (args
, function
);
6797 length
+= strlen ("expected ");
6798 buffer
= tmp
= alloca (length
);
6800 while ((code
= va_arg (args
, int)))
6802 const char *prefix
= length
? " or " : "expected ";
6804 strcpy (tmp
+ length
, prefix
);
6805 length
+= strlen (prefix
);
6806 strcpy (tmp
+ length
, tree_code_name
[code
]);
6807 length
+= strlen (tree_code_name
[code
]);
6812 buffer
= "unexpected node";
6814 internal_error ("tree check: %s, have %s in %s, at %s:%d",
6815 buffer
, tree_code_name
[TREE_CODE (node
)],
6816 function
, trim_filename (file
), line
);
6819 /* Complain that the tree code of NODE does match the expected 0
6820 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
6824 tree_not_check_failed (const_tree node
, const char *file
,
6825 int line
, const char *function
, ...)
6829 unsigned length
= 0;
6832 va_start (args
, function
);
6833 while ((code
= va_arg (args
, int)))
6834 length
+= 4 + strlen (tree_code_name
[code
]);
6836 va_start (args
, function
);
6837 buffer
= alloca (length
);
6839 while ((code
= va_arg (args
, int)))
6843 strcpy (buffer
+ length
, " or ");
6846 strcpy (buffer
+ length
, tree_code_name
[code
]);
6847 length
+= strlen (tree_code_name
[code
]);
6851 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
6852 buffer
, tree_code_name
[TREE_CODE (node
)],
6853 function
, trim_filename (file
), line
);
6856 /* Similar to tree_check_failed, except that we check for a class of tree
6857 code, given in CL. */
6860 tree_class_check_failed (const_tree node
, const enum tree_code_class cl
,
6861 const char *file
, int line
, const char *function
)
6864 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
6865 TREE_CODE_CLASS_STRING (cl
),
6866 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
6867 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
6870 /* Similar to tree_check_failed, except that instead of specifying a
6871 dozen codes, use the knowledge that they're all sequential. */
6874 tree_range_check_failed (const_tree node
, const char *file
, int line
,
6875 const char *function
, enum tree_code c1
,
6879 unsigned length
= 0;
6882 for (c
= c1
; c
<= c2
; ++c
)
6883 length
+= 4 + strlen (tree_code_name
[c
]);
6885 length
+= strlen ("expected ");
6886 buffer
= alloca (length
);
6889 for (c
= c1
; c
<= c2
; ++c
)
6891 const char *prefix
= length
? " or " : "expected ";
6893 strcpy (buffer
+ length
, prefix
);
6894 length
+= strlen (prefix
);
6895 strcpy (buffer
+ length
, tree_code_name
[c
]);
6896 length
+= strlen (tree_code_name
[c
]);
6899 internal_error ("tree check: %s, have %s in %s, at %s:%d",
6900 buffer
, tree_code_name
[TREE_CODE (node
)],
6901 function
, trim_filename (file
), line
);
6905 /* Similar to tree_check_failed, except that we check that a tree does
6906 not have the specified code, given in CL. */
6909 tree_not_class_check_failed (const_tree node
, const enum tree_code_class cl
,
6910 const char *file
, int line
, const char *function
)
6913 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
6914 TREE_CODE_CLASS_STRING (cl
),
6915 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
6916 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
6920 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
6923 omp_clause_check_failed (const_tree node
, const char *file
, int line
,
6924 const char *function
, enum omp_clause_code code
)
6926 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
6927 omp_clause_code_name
[code
], tree_code_name
[TREE_CODE (node
)],
6928 function
, trim_filename (file
), line
);
6932 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
6935 omp_clause_range_check_failed (const_tree node
, const char *file
, int line
,
6936 const char *function
, enum omp_clause_code c1
,
6937 enum omp_clause_code c2
)
6940 unsigned length
= 0;
6941 enum omp_clause_code c
;
6943 for (c
= c1
; c
<= c2
; ++c
)
6944 length
+= 4 + strlen (omp_clause_code_name
[c
]);
6946 length
+= strlen ("expected ");
6947 buffer
= alloca (length
);
6950 for (c
= c1
; c
<= c2
; ++c
)
6952 const char *prefix
= length
? " or " : "expected ";
6954 strcpy (buffer
+ length
, prefix
);
6955 length
+= strlen (prefix
);
6956 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
6957 length
+= strlen (omp_clause_code_name
[c
]);
6960 internal_error ("tree check: %s, have %s in %s, at %s:%d",
6961 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
6962 function
, trim_filename (file
), line
);
6966 #undef DEFTREESTRUCT
6967 #define DEFTREESTRUCT(VAL, NAME) NAME,
6969 static const char *ts_enum_names
[] = {
6970 #include "treestruct.def"
6972 #undef DEFTREESTRUCT
6974 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
6976 /* Similar to tree_class_check_failed, except that we check for
6977 whether CODE contains the tree structure identified by EN. */
6980 tree_contains_struct_check_failed (const_tree node
,
6981 const enum tree_node_structure_enum en
,
6982 const char *file
, int line
,
6983 const char *function
)
6986 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
6988 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
6992 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
6993 (dynamically sized) vector. */
6996 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
6997 const char *function
)
7000 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
7001 idx
+ 1, len
, function
, trim_filename (file
), line
);
7004 /* Similar to above, except that the check is for the bounds of a PHI_NODE's
7005 (dynamically sized) vector. */
7008 phi_node_elt_check_failed (int idx
, int len
, const char *file
, int line
,
7009 const char *function
)
7012 ("tree check: accessed elt %d of phi_node with %d elts in %s, at %s:%d",
7013 idx
+ 1, len
, function
, trim_filename (file
), line
);
7016 /* Similar to above, except that the check is for the bounds of the operand
7017 vector of an expression node EXP. */
7020 tree_operand_check_failed (int idx
, const_tree exp
, const char *file
,
7021 int line
, const char *function
)
7023 int code
= TREE_CODE (exp
);
7025 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
7026 idx
+ 1, tree_code_name
[code
], TREE_OPERAND_LENGTH (exp
),
7027 function
, trim_filename (file
), line
);
7030 /* Similar to above, except that the check is for the number of
7031 operands of an OMP_CLAUSE node. */
7034 omp_clause_operand_check_failed (int idx
, const_tree t
, const char *file
,
7035 int line
, const char *function
)
7038 ("tree check: accessed operand %d of omp_clause %s with %d operands "
7039 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
7040 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
7041 trim_filename (file
), line
);
7043 #endif /* ENABLE_TREE_CHECKING */
7045 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
7046 and mapped to the machine mode MODE. Initialize its fields and build
7047 the information necessary for debugging output. */
7050 make_vector_type (tree innertype
, int nunits
, enum machine_mode mode
)
7053 hashval_t hashcode
= 0;
7055 /* Build a main variant, based on the main variant of the inner type, then
7056 use it to build the variant we return. */
7057 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
7058 && TYPE_MAIN_VARIANT (innertype
) != innertype
)
7059 return build_type_attribute_qual_variant (
7060 make_vector_type (TYPE_MAIN_VARIANT (innertype
), nunits
, mode
),
7061 TYPE_ATTRIBUTES (innertype
),
7062 TYPE_QUALS (innertype
));
7064 t
= make_node (VECTOR_TYPE
);
7065 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
7066 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
7067 TYPE_MODE (t
) = mode
;
7068 TYPE_READONLY (t
) = TYPE_READONLY (innertype
);
7069 TYPE_VOLATILE (t
) = TYPE_VOLATILE (innertype
);
7071 if (TYPE_STRUCTURAL_EQUALITY_P (innertype
))
7072 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7073 else if (TYPE_CANONICAL (innertype
) != innertype
7074 || mode
!= VOIDmode
)
7076 = make_vector_type (TYPE_CANONICAL (innertype
), nunits
, VOIDmode
);
7081 tree index
= build_int_cst (NULL_TREE
, nunits
- 1);
7082 tree array
= build_array_type (innertype
, build_index_type (index
));
7083 tree rt
= make_node (RECORD_TYPE
);
7085 TYPE_FIELDS (rt
) = build_decl (FIELD_DECL
, get_identifier ("f"), array
);
7086 DECL_CONTEXT (TYPE_FIELDS (rt
)) = rt
;
7088 TYPE_DEBUG_REPRESENTATION_TYPE (t
) = rt
;
7089 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
7090 the representation type, and we want to find that die when looking up
7091 the vector type. This is most easily achieved by making the TYPE_UID
7093 TYPE_UID (rt
) = TYPE_UID (t
);
7096 hashcode
= iterative_hash_host_wide_int (VECTOR_TYPE
, hashcode
);
7097 hashcode
= iterative_hash_host_wide_int (mode
, hashcode
);
7098 hashcode
= iterative_hash_object (TYPE_HASH (innertype
), hashcode
);
7099 return type_hash_canon (hashcode
, t
);
7103 make_or_reuse_type (unsigned size
, int unsignedp
)
7105 if (size
== INT_TYPE_SIZE
)
7106 return unsignedp
? unsigned_type_node
: integer_type_node
;
7107 if (size
== CHAR_TYPE_SIZE
)
7108 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
7109 if (size
== SHORT_TYPE_SIZE
)
7110 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
7111 if (size
== LONG_TYPE_SIZE
)
7112 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
7113 if (size
== LONG_LONG_TYPE_SIZE
)
7114 return (unsignedp
? long_long_unsigned_type_node
7115 : long_long_integer_type_node
);
7118 return make_unsigned_type (size
);
7120 return make_signed_type (size
);
7123 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
7126 make_or_reuse_fract_type (unsigned size
, int unsignedp
, int satp
)
7130 if (size
== SHORT_FRACT_TYPE_SIZE
)
7131 return unsignedp
? sat_unsigned_short_fract_type_node
7132 : sat_short_fract_type_node
;
7133 if (size
== FRACT_TYPE_SIZE
)
7134 return unsignedp
? sat_unsigned_fract_type_node
: sat_fract_type_node
;
7135 if (size
== LONG_FRACT_TYPE_SIZE
)
7136 return unsignedp
? sat_unsigned_long_fract_type_node
7137 : sat_long_fract_type_node
;
7138 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
7139 return unsignedp
? sat_unsigned_long_long_fract_type_node
7140 : sat_long_long_fract_type_node
;
7144 if (size
== SHORT_FRACT_TYPE_SIZE
)
7145 return unsignedp
? unsigned_short_fract_type_node
7146 : short_fract_type_node
;
7147 if (size
== FRACT_TYPE_SIZE
)
7148 return unsignedp
? unsigned_fract_type_node
: fract_type_node
;
7149 if (size
== LONG_FRACT_TYPE_SIZE
)
7150 return unsignedp
? unsigned_long_fract_type_node
7151 : long_fract_type_node
;
7152 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
7153 return unsignedp
? unsigned_long_long_fract_type_node
7154 : long_long_fract_type_node
;
7157 return make_fract_type (size
, unsignedp
, satp
);
7160 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
7163 make_or_reuse_accum_type (unsigned size
, int unsignedp
, int satp
)
7167 if (size
== SHORT_ACCUM_TYPE_SIZE
)
7168 return unsignedp
? sat_unsigned_short_accum_type_node
7169 : sat_short_accum_type_node
;
7170 if (size
== ACCUM_TYPE_SIZE
)
7171 return unsignedp
? sat_unsigned_accum_type_node
: sat_accum_type_node
;
7172 if (size
== LONG_ACCUM_TYPE_SIZE
)
7173 return unsignedp
? sat_unsigned_long_accum_type_node
7174 : sat_long_accum_type_node
;
7175 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
7176 return unsignedp
? sat_unsigned_long_long_accum_type_node
7177 : sat_long_long_accum_type_node
;
7181 if (size
== SHORT_ACCUM_TYPE_SIZE
)
7182 return unsignedp
? unsigned_short_accum_type_node
7183 : short_accum_type_node
;
7184 if (size
== ACCUM_TYPE_SIZE
)
7185 return unsignedp
? unsigned_accum_type_node
: accum_type_node
;
7186 if (size
== LONG_ACCUM_TYPE_SIZE
)
7187 return unsignedp
? unsigned_long_accum_type_node
7188 : long_accum_type_node
;
7189 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
7190 return unsignedp
? unsigned_long_long_accum_type_node
7191 : long_long_accum_type_node
;
7194 return make_accum_type (size
, unsignedp
, satp
);
7197 /* Create nodes for all integer types (and error_mark_node) using the sizes
7198 of C datatypes. The caller should call set_sizetype soon after calling
7199 this function to select one of the types as sizetype. */
7202 build_common_tree_nodes (bool signed_char
, bool signed_sizetype
)
7204 error_mark_node
= make_node (ERROR_MARK
);
7205 TREE_TYPE (error_mark_node
) = error_mark_node
;
7207 initialize_sizetypes (signed_sizetype
);
7209 /* Define both `signed char' and `unsigned char'. */
7210 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
7211 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
7212 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
7213 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
7215 /* Define `char', which is like either `signed char' or `unsigned char'
7216 but not the same as either. */
7219 ? make_signed_type (CHAR_TYPE_SIZE
)
7220 : make_unsigned_type (CHAR_TYPE_SIZE
));
7221 TYPE_STRING_FLAG (char_type_node
) = 1;
7223 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
7224 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
7225 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
7226 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
7227 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
7228 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
7229 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
7230 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
7232 /* Define a boolean type. This type only represents boolean values but
7233 may be larger than char depending on the value of BOOL_TYPE_SIZE.
7234 Front ends which want to override this size (i.e. Java) can redefine
7235 boolean_type_node before calling build_common_tree_nodes_2. */
7236 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
7237 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
7238 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
7239 TYPE_PRECISION (boolean_type_node
) = 1;
7241 /* Fill in the rest of the sized types. Reuse existing type nodes
7243 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
7244 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
7245 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
7246 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
7247 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
7249 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
7250 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
7251 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
7252 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
7253 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
7255 access_public_node
= get_identifier ("public");
7256 access_protected_node
= get_identifier ("protected");
7257 access_private_node
= get_identifier ("private");
7260 /* Call this function after calling build_common_tree_nodes and set_sizetype.
7261 It will create several other common tree nodes. */
7264 build_common_tree_nodes_2 (int short_double
)
7266 /* Define these next since types below may used them. */
7267 integer_zero_node
= build_int_cst (NULL_TREE
, 0);
7268 integer_one_node
= build_int_cst (NULL_TREE
, 1);
7269 integer_minus_one_node
= build_int_cst (NULL_TREE
, -1);
7271 size_zero_node
= size_int (0);
7272 size_one_node
= size_int (1);
7273 bitsize_zero_node
= bitsize_int (0);
7274 bitsize_one_node
= bitsize_int (1);
7275 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
7277 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
7278 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
7280 void_type_node
= make_node (VOID_TYPE
);
7281 layout_type (void_type_node
);
7283 /* We are not going to have real types in C with less than byte alignment,
7284 so we might as well not have any types that claim to have it. */
7285 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
7286 TYPE_USER_ALIGN (void_type_node
) = 0;
7288 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
7289 layout_type (TREE_TYPE (null_pointer_node
));
7291 ptr_type_node
= build_pointer_type (void_type_node
);
7293 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
7294 fileptr_type_node
= ptr_type_node
;
7296 float_type_node
= make_node (REAL_TYPE
);
7297 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
7298 layout_type (float_type_node
);
7300 double_type_node
= make_node (REAL_TYPE
);
7302 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
7304 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
7305 layout_type (double_type_node
);
7307 long_double_type_node
= make_node (REAL_TYPE
);
7308 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
7309 layout_type (long_double_type_node
);
7311 float_ptr_type_node
= build_pointer_type (float_type_node
);
7312 double_ptr_type_node
= build_pointer_type (double_type_node
);
7313 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
7314 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
7316 /* Fixed size integer types. */
7317 uint32_type_node
= build_nonstandard_integer_type (32, true);
7318 uint64_type_node
= build_nonstandard_integer_type (64, true);
7320 /* Decimal float types. */
7321 dfloat32_type_node
= make_node (REAL_TYPE
);
7322 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
7323 layout_type (dfloat32_type_node
);
7324 TYPE_MODE (dfloat32_type_node
) = SDmode
;
7325 dfloat32_ptr_type_node
= build_pointer_type (dfloat32_type_node
);
7327 dfloat64_type_node
= make_node (REAL_TYPE
);
7328 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
7329 layout_type (dfloat64_type_node
);
7330 TYPE_MODE (dfloat64_type_node
) = DDmode
;
7331 dfloat64_ptr_type_node
= build_pointer_type (dfloat64_type_node
);
7333 dfloat128_type_node
= make_node (REAL_TYPE
);
7334 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
7335 layout_type (dfloat128_type_node
);
7336 TYPE_MODE (dfloat128_type_node
) = TDmode
;
7337 dfloat128_ptr_type_node
= build_pointer_type (dfloat128_type_node
);
7339 complex_integer_type_node
= build_complex_type (integer_type_node
);
7340 complex_float_type_node
= build_complex_type (float_type_node
);
7341 complex_double_type_node
= build_complex_type (double_type_node
);
7342 complex_long_double_type_node
= build_complex_type (long_double_type_node
);
7344 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
7345 #define MAKE_FIXED_TYPE_NODE(KIND,WIDTH,SIZE) \
7346 sat_ ## WIDTH ## KIND ## _type_node = \
7347 make_sat_signed_ ## KIND ## _type (SIZE); \
7348 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
7349 make_sat_unsigned_ ## KIND ## _type (SIZE); \
7350 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
7351 unsigned_ ## WIDTH ## KIND ## _type_node = \
7352 make_unsigned_ ## KIND ## _type (SIZE);
7354 /* Make fixed-point type nodes based on four different widths. */
7355 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
7356 MAKE_FIXED_TYPE_NODE (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
7357 MAKE_FIXED_TYPE_NODE (N1, , N2 ## _TYPE_SIZE) \
7358 MAKE_FIXED_TYPE_NODE (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
7359 MAKE_FIXED_TYPE_NODE (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
7361 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
7362 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
7363 NAME ## _type_node = \
7364 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
7365 u ## NAME ## _type_node = \
7366 make_or_reuse_unsigned_ ## KIND ## _type \
7367 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
7368 sat_ ## NAME ## _type_node = \
7369 make_or_reuse_sat_signed_ ## KIND ## _type \
7370 (GET_MODE_BITSIZE (MODE ## mode)); \
7371 sat_u ## NAME ## _type_node = \
7372 make_or_reuse_sat_unsigned_ ## KIND ## _type \
7373 (GET_MODE_BITSIZE (U ## MODE ## mode));
7375 /* Fixed-point type and mode nodes. */
7376 MAKE_FIXED_TYPE_NODE_FAMILY (fract
, FRACT
)
7377 MAKE_FIXED_TYPE_NODE_FAMILY (accum
, ACCUM
)
7378 MAKE_FIXED_MODE_NODE (fract
, qq
, QQ
)
7379 MAKE_FIXED_MODE_NODE (fract
, hq
, HQ
)
7380 MAKE_FIXED_MODE_NODE (fract
, sq
, SQ
)
7381 MAKE_FIXED_MODE_NODE (fract
, dq
, DQ
)
7382 MAKE_FIXED_MODE_NODE (fract
, tq
, TQ
)
7383 MAKE_FIXED_MODE_NODE (accum
, ha
, HA
)
7384 MAKE_FIXED_MODE_NODE (accum
, sa
, SA
)
7385 MAKE_FIXED_MODE_NODE (accum
, da
, DA
)
7386 MAKE_FIXED_MODE_NODE (accum
, ta
, TA
)
7389 tree t
= targetm
.build_builtin_va_list ();
7391 /* Many back-ends define record types without setting TYPE_NAME.
7392 If we copied the record type here, we'd keep the original
7393 record type without a name. This breaks name mangling. So,
7394 don't copy record types and let c_common_nodes_and_builtins()
7395 declare the type to be __builtin_va_list. */
7396 if (TREE_CODE (t
) != RECORD_TYPE
)
7397 t
= build_variant_type_copy (t
);
7399 va_list_type_node
= t
;
7403 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
7406 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
7407 const char *library_name
, int ecf_flags
)
7411 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
7412 library_name
, NULL_TREE
);
7413 if (ecf_flags
& ECF_CONST
)
7414 TREE_READONLY (decl
) = 1;
7415 if (ecf_flags
& ECF_PURE
)
7416 DECL_IS_PURE (decl
) = 1;
7417 if (ecf_flags
& ECF_NORETURN
)
7418 TREE_THIS_VOLATILE (decl
) = 1;
7419 if (ecf_flags
& ECF_NOTHROW
)
7420 TREE_NOTHROW (decl
) = 1;
7421 if (ecf_flags
& ECF_MALLOC
)
7422 DECL_IS_MALLOC (decl
) = 1;
7424 built_in_decls
[code
] = decl
;
7425 implicit_built_in_decls
[code
] = decl
;
7428 /* Call this function after instantiating all builtins that the language
7429 front end cares about. This will build the rest of the builtins that
7430 are relied upon by the tree optimizers and the middle-end. */
7433 build_common_builtin_nodes (void)
7437 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
7438 || built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
7440 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7441 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7442 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7443 ftype
= build_function_type (ptr_type_node
, tmp
);
7445 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
)
7446 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
7447 "memcpy", ECF_NOTHROW
);
7448 if (built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
7449 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
7450 "memmove", ECF_NOTHROW
);
7453 if (built_in_decls
[BUILT_IN_MEMCMP
] == NULL
)
7455 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7456 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7457 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7458 ftype
= build_function_type (integer_type_node
, tmp
);
7459 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
7460 "memcmp", ECF_PURE
| ECF_NOTHROW
);
7463 if (built_in_decls
[BUILT_IN_MEMSET
] == NULL
)
7465 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7466 tmp
= tree_cons (NULL_TREE
, integer_type_node
, tmp
);
7467 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7468 ftype
= build_function_type (ptr_type_node
, tmp
);
7469 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
7470 "memset", ECF_NOTHROW
);
7473 if (built_in_decls
[BUILT_IN_ALLOCA
] == NULL
)
7475 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7476 ftype
= build_function_type (ptr_type_node
, tmp
);
7477 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
7478 "alloca", ECF_NOTHROW
| ECF_MALLOC
);
7481 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7482 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7483 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7484 ftype
= build_function_type (void_type_node
, tmp
);
7485 local_define_builtin ("__builtin_init_trampoline", ftype
,
7486 BUILT_IN_INIT_TRAMPOLINE
,
7487 "__builtin_init_trampoline", ECF_NOTHROW
);
7489 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7490 ftype
= build_function_type (ptr_type_node
, tmp
);
7491 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
7492 BUILT_IN_ADJUST_TRAMPOLINE
,
7493 "__builtin_adjust_trampoline",
7494 ECF_CONST
| ECF_NOTHROW
);
7496 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7497 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7498 ftype
= build_function_type (void_type_node
, tmp
);
7499 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
7500 BUILT_IN_NONLOCAL_GOTO
,
7501 "__builtin_nonlocal_goto",
7502 ECF_NORETURN
| ECF_NOTHROW
);
7504 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7505 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7506 ftype
= build_function_type (void_type_node
, tmp
);
7507 local_define_builtin ("__builtin_setjmp_setup", ftype
,
7508 BUILT_IN_SETJMP_SETUP
,
7509 "__builtin_setjmp_setup", ECF_NOTHROW
);
7511 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7512 ftype
= build_function_type (ptr_type_node
, tmp
);
7513 local_define_builtin ("__builtin_setjmp_dispatcher", ftype
,
7514 BUILT_IN_SETJMP_DISPATCHER
,
7515 "__builtin_setjmp_dispatcher",
7516 ECF_PURE
| ECF_NOTHROW
);
7518 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7519 ftype
= build_function_type (void_type_node
, tmp
);
7520 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
7521 BUILT_IN_SETJMP_RECEIVER
,
7522 "__builtin_setjmp_receiver", ECF_NOTHROW
);
7524 ftype
= build_function_type (ptr_type_node
, void_list_node
);
7525 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
7526 "__builtin_stack_save", ECF_NOTHROW
);
7528 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7529 ftype
= build_function_type (void_type_node
, tmp
);
7530 local_define_builtin ("__builtin_stack_restore", ftype
,
7531 BUILT_IN_STACK_RESTORE
,
7532 "__builtin_stack_restore", ECF_NOTHROW
);
7534 ftype
= build_function_type (void_type_node
, void_list_node
);
7535 local_define_builtin ("__builtin_profile_func_enter", ftype
,
7536 BUILT_IN_PROFILE_FUNC_ENTER
, "profile_func_enter", 0);
7537 local_define_builtin ("__builtin_profile_func_exit", ftype
,
7538 BUILT_IN_PROFILE_FUNC_EXIT
, "profile_func_exit", 0);
7540 /* Complex multiplication and division. These are handled as builtins
7541 rather than optabs because emit_library_call_value doesn't support
7542 complex. Further, we can do slightly better with folding these
7543 beasties if the real and complex parts of the arguments are separate. */
7545 enum machine_mode mode
;
7547 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
7549 char mode_name_buf
[4], *q
;
7551 enum built_in_function mcode
, dcode
;
7552 tree type
, inner_type
;
7554 type
= lang_hooks
.types
.type_for_mode (mode
, 0);
7557 inner_type
= TREE_TYPE (type
);
7559 tmp
= tree_cons (NULL_TREE
, inner_type
, void_list_node
);
7560 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
7561 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
7562 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
7563 ftype
= build_function_type (type
, tmp
);
7565 mcode
= BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
;
7566 dcode
= BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
;
7568 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
7572 built_in_names
[mcode
] = concat ("__mul", mode_name_buf
, "3", NULL
);
7573 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
7574 built_in_names
[mcode
], ECF_CONST
| ECF_NOTHROW
);
7576 built_in_names
[dcode
] = concat ("__div", mode_name_buf
, "3", NULL
);
7577 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
7578 built_in_names
[dcode
], ECF_CONST
| ECF_NOTHROW
);
7583 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
7586 If we requested a pointer to a vector, build up the pointers that
7587 we stripped off while looking for the inner type. Similarly for
7588 return values from functions.
7590 The argument TYPE is the top of the chain, and BOTTOM is the
7591 new type which we will point to. */
7594 reconstruct_complex_type (tree type
, tree bottom
)
7598 if (TREE_CODE (type
) == POINTER_TYPE
)
7600 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7601 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
7602 TYPE_REF_CAN_ALIAS_ALL (type
));
7604 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
7606 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7607 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
7608 TYPE_REF_CAN_ALIAS_ALL (type
));
7610 else if (TREE_CODE (type
) == ARRAY_TYPE
)
7612 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7613 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
7615 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
7617 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7618 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
7620 else if (TREE_CODE (type
) == METHOD_TYPE
)
7622 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7623 /* The build_method_type_directly() routine prepends 'this' to argument list,
7624 so we must compensate by getting rid of it. */
7626 = build_method_type_directly
7627 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type
))),
7629 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
7631 else if (TREE_CODE (type
) == OFFSET_TYPE
)
7633 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7634 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
7639 return build_qualified_type (outer
, TYPE_QUALS (type
));
7642 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
7645 build_vector_type_for_mode (tree innertype
, enum machine_mode mode
)
7649 switch (GET_MODE_CLASS (mode
))
7651 case MODE_VECTOR_INT
:
7652 case MODE_VECTOR_FLOAT
:
7653 case MODE_VECTOR_FRACT
:
7654 case MODE_VECTOR_UFRACT
:
7655 case MODE_VECTOR_ACCUM
:
7656 case MODE_VECTOR_UACCUM
:
7657 nunits
= GET_MODE_NUNITS (mode
);
7661 /* Check that there are no leftover bits. */
7662 gcc_assert (GET_MODE_BITSIZE (mode
)
7663 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
7665 nunits
= GET_MODE_BITSIZE (mode
)
7666 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
7673 return make_vector_type (innertype
, nunits
, mode
);
7676 /* Similarly, but takes the inner type and number of units, which must be
7680 build_vector_type (tree innertype
, int nunits
)
7682 return make_vector_type (innertype
, nunits
, VOIDmode
);
7686 /* Build RESX_EXPR with given REGION_NUMBER. */
7688 build_resx (int region_number
)
7691 t
= build1 (RESX_EXPR
, void_type_node
,
7692 build_int_cst (NULL_TREE
, region_number
));
7696 /* Given an initializer INIT, return TRUE if INIT is zero or some
7697 aggregate of zeros. Otherwise return FALSE. */
7699 initializer_zerop (const_tree init
)
7705 switch (TREE_CODE (init
))
7708 return integer_zerop (init
);
7711 /* ??? Note that this is not correct for C4X float formats. There,
7712 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
7713 negative exponent. */
7714 return real_zerop (init
)
7715 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
7718 return fixed_zerop (init
);
7721 return integer_zerop (init
)
7722 || (real_zerop (init
)
7723 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
7724 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
7727 for (elt
= TREE_VECTOR_CST_ELTS (init
); elt
; elt
= TREE_CHAIN (elt
))
7728 if (!initializer_zerop (TREE_VALUE (elt
)))
7734 unsigned HOST_WIDE_INT idx
;
7736 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
7737 if (!initializer_zerop (elt
))
7747 /* Build an empty statement. */
7750 build_empty_stmt (void)
7752 return build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
7756 /* Build an OpenMP clause with code CODE. */
7759 build_omp_clause (enum omp_clause_code code
)
7764 length
= omp_clause_num_ops
[code
];
7765 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
7767 t
= ggc_alloc (size
);
7768 memset (t
, 0, size
);
7769 TREE_SET_CODE (t
, OMP_CLAUSE
);
7770 OMP_CLAUSE_SET_CODE (t
, code
);
7772 #ifdef GATHER_STATISTICS
7773 tree_node_counts
[(int) omp_clause_kind
]++;
7774 tree_node_sizes
[(int) omp_clause_kind
] += size
;
7780 /* Set various status flags when building a CALL_EXPR object T. */
7783 process_call_operands (tree t
)
7787 side_effects
= TREE_SIDE_EFFECTS (t
);
7791 n
= TREE_OPERAND_LENGTH (t
);
7792 for (i
= 1; i
< n
; i
++)
7794 tree op
= TREE_OPERAND (t
, i
);
7795 if (op
&& TREE_SIDE_EFFECTS (op
))
7806 /* Calls have side-effects, except those to const or
7808 i
= call_expr_flags (t
);
7809 if (!(i
& (ECF_CONST
| ECF_PURE
)))
7812 TREE_SIDE_EFFECTS (t
) = side_effects
;
7815 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
7816 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
7817 Except for the CODE and operand count field, other storage for the
7818 object is initialized to zeros. */
7821 build_vl_exp_stat (enum tree_code code
, int len MEM_STAT_DECL
)
7824 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_exp
);
7826 gcc_assert (TREE_CODE_CLASS (code
) == tcc_vl_exp
);
7827 gcc_assert (len
>= 1);
7829 #ifdef GATHER_STATISTICS
7830 tree_node_counts
[(int) e_kind
]++;
7831 tree_node_sizes
[(int) e_kind
] += length
;
7834 t
= ggc_alloc_zone_pass_stat (length
, &tree_zone
);
7836 memset (t
, 0, length
);
7838 TREE_SET_CODE (t
, code
);
7840 /* Can't use TREE_OPERAND to store the length because if checking is
7841 enabled, it will try to check the length before we store it. :-P */
7842 t
->exp
.operands
[0] = build_int_cst (sizetype
, len
);
7848 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE
7849 and FN and a null static chain slot. ARGLIST is a TREE_LIST of the
7853 build_call_list (tree return_type
, tree fn
, tree arglist
)
7858 t
= build_vl_exp (CALL_EXPR
, list_length (arglist
) + 3);
7859 TREE_TYPE (t
) = return_type
;
7860 CALL_EXPR_FN (t
) = fn
;
7861 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
7862 for (i
= 0; arglist
; arglist
= TREE_CHAIN (arglist
), i
++)
7863 CALL_EXPR_ARG (t
, i
) = TREE_VALUE (arglist
);
7864 process_call_operands (t
);
7868 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
7869 FN and a null static chain slot. NARGS is the number of call arguments
7870 which are specified as "..." arguments. */
7873 build_call_nary (tree return_type
, tree fn
, int nargs
, ...)
7877 va_start (args
, nargs
);
7878 ret
= build_call_valist (return_type
, fn
, nargs
, args
);
7883 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
7884 FN and a null static chain slot. NARGS is the number of call arguments
7885 which are specified as a va_list ARGS. */
7888 build_call_valist (tree return_type
, tree fn
, int nargs
, va_list args
)
7893 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
7894 TREE_TYPE (t
) = return_type
;
7895 CALL_EXPR_FN (t
) = fn
;
7896 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
7897 for (i
= 0; i
< nargs
; i
++)
7898 CALL_EXPR_ARG (t
, i
) = va_arg (args
, tree
);
7899 process_call_operands (t
);
7903 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
7904 FN and a null static chain slot. NARGS is the number of call arguments
7905 which are specified as a tree array ARGS. */
7908 build_call_array (tree return_type
, tree fn
, int nargs
, tree
*args
)
7913 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
7914 TREE_TYPE (t
) = return_type
;
7915 CALL_EXPR_FN (t
) = fn
;
7916 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
7917 for (i
= 0; i
< nargs
; i
++)
7918 CALL_EXPR_ARG (t
, i
) = args
[i
];
7919 process_call_operands (t
);
7924 /* Returns true if it is possible to prove that the index of
7925 an array access REF (an ARRAY_REF expression) falls into the
7929 in_array_bounds_p (tree ref
)
7931 tree idx
= TREE_OPERAND (ref
, 1);
7934 if (TREE_CODE (idx
) != INTEGER_CST
)
7937 min
= array_ref_low_bound (ref
);
7938 max
= array_ref_up_bound (ref
);
7941 || TREE_CODE (min
) != INTEGER_CST
7942 || TREE_CODE (max
) != INTEGER_CST
)
7945 if (tree_int_cst_lt (idx
, min
)
7946 || tree_int_cst_lt (max
, idx
))
7952 /* Returns true if it is possible to prove that the range of
7953 an array access REF (an ARRAY_RANGE_REF expression) falls
7954 into the array bounds. */
7957 range_in_array_bounds_p (tree ref
)
7959 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (ref
));
7960 tree range_min
, range_max
, min
, max
;
7962 range_min
= TYPE_MIN_VALUE (domain_type
);
7963 range_max
= TYPE_MAX_VALUE (domain_type
);
7966 || TREE_CODE (range_min
) != INTEGER_CST
7967 || TREE_CODE (range_max
) != INTEGER_CST
)
7970 min
= array_ref_low_bound (ref
);
7971 max
= array_ref_up_bound (ref
);
7974 || TREE_CODE (min
) != INTEGER_CST
7975 || TREE_CODE (max
) != INTEGER_CST
)
7978 if (tree_int_cst_lt (range_min
, min
)
7979 || tree_int_cst_lt (max
, range_max
))
7985 /* Return true if T (assumed to be a DECL) must be assigned a memory
7989 needs_to_live_in_memory (const_tree t
)
7991 if (TREE_CODE (t
) == SSA_NAME
)
7992 t
= SSA_NAME_VAR (t
);
7994 return (TREE_ADDRESSABLE (t
)
7995 || is_global_var (t
)
7996 || (TREE_CODE (t
) == RESULT_DECL
7997 && aggregate_value_p (t
, current_function_decl
)));
8000 /* There are situations in which a language considers record types
8001 compatible which have different field lists. Decide if two fields
8002 are compatible. It is assumed that the parent records are compatible. */
8005 fields_compatible_p (const_tree f1
, const_tree f2
)
8007 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1
),
8008 DECL_FIELD_BIT_OFFSET (f2
), OEP_ONLY_CONST
))
8011 if (!operand_equal_p (DECL_FIELD_OFFSET (f1
),
8012 DECL_FIELD_OFFSET (f2
), OEP_ONLY_CONST
))
8015 if (!types_compatible_p (TREE_TYPE (f1
), TREE_TYPE (f2
)))
8021 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
8024 find_compatible_field (tree record
, tree orig_field
)
8028 for (f
= TYPE_FIELDS (record
); f
; f
= TREE_CHAIN (f
))
8029 if (TREE_CODE (f
) == FIELD_DECL
8030 && fields_compatible_p (f
, orig_field
))
8033 /* ??? Why isn't this on the main fields list? */
8034 f
= TYPE_VFIELD (record
);
8035 if (f
&& TREE_CODE (f
) == FIELD_DECL
8036 && fields_compatible_p (f
, orig_field
))
8039 /* ??? We should abort here, but Java appears to do Bad Things
8040 with inherited fields. */
8044 /* Return value of a constant X and sign-extend it. */
8047 int_cst_value (const_tree x
)
8049 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
8050 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
8052 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
8053 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
8054 || TREE_INT_CST_HIGH (x
) == -1);
8056 if (bits
< HOST_BITS_PER_WIDE_INT
)
8058 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
8060 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
8062 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
8068 /* If TYPE is an integral type, return an equivalent type which is
8069 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type,
8070 return TYPE itself. */
8073 signed_or_unsigned_type_for (int unsignedp
, tree type
)
8076 if (POINTER_TYPE_P (type
))
8079 if (!INTEGRAL_TYPE_P (t
) || TYPE_UNSIGNED (t
) == unsignedp
)
8082 return lang_hooks
.types
.type_for_size (TYPE_PRECISION (t
), unsignedp
);
8085 /* Returns unsigned variant of TYPE. */
8088 unsigned_type_for (tree type
)
8090 return signed_or_unsigned_type_for (1, type
);
8093 /* Returns signed variant of TYPE. */
8096 signed_type_for (tree type
)
8098 return signed_or_unsigned_type_for (0, type
);
8101 /* Returns the largest value obtainable by casting something in INNER type to
8105 upper_bound_in_type (tree outer
, tree inner
)
8107 unsigned HOST_WIDE_INT lo
, hi
;
8108 unsigned int det
= 0;
8109 unsigned oprec
= TYPE_PRECISION (outer
);
8110 unsigned iprec
= TYPE_PRECISION (inner
);
8113 /* Compute a unique number for every combination. */
8114 det
|= (oprec
> iprec
) ? 4 : 0;
8115 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
8116 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
8118 /* Determine the exponent to use. */
8123 /* oprec <= iprec, outer: signed, inner: don't care. */
8128 /* oprec <= iprec, outer: unsigned, inner: don't care. */
8132 /* oprec > iprec, outer: signed, inner: signed. */
8136 /* oprec > iprec, outer: signed, inner: unsigned. */
8140 /* oprec > iprec, outer: unsigned, inner: signed. */
8144 /* oprec > iprec, outer: unsigned, inner: unsigned. */
8151 /* Compute 2^^prec - 1. */
8152 if (prec
<= HOST_BITS_PER_WIDE_INT
)
8155 lo
= ((~(unsigned HOST_WIDE_INT
) 0)
8156 >> (HOST_BITS_PER_WIDE_INT
- prec
));
8160 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
8161 >> (2 * HOST_BITS_PER_WIDE_INT
- prec
));
8162 lo
= ~(unsigned HOST_WIDE_INT
) 0;
8165 return build_int_cst_wide (outer
, lo
, hi
);
8168 /* Returns the smallest value obtainable by casting something in INNER type to
8172 lower_bound_in_type (tree outer
, tree inner
)
8174 unsigned HOST_WIDE_INT lo
, hi
;
8175 unsigned oprec
= TYPE_PRECISION (outer
);
8176 unsigned iprec
= TYPE_PRECISION (inner
);
8178 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
8180 if (TYPE_UNSIGNED (outer
)
8181 /* If we are widening something of an unsigned type, OUTER type
8182 contains all values of INNER type. In particular, both INNER
8183 and OUTER types have zero in common. */
8184 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
8188 /* If we are widening a signed type to another signed type, we
8189 want to obtain -2^^(iprec-1). If we are keeping the
8190 precision or narrowing to a signed type, we want to obtain
8192 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
8194 if (prec
<= HOST_BITS_PER_WIDE_INT
)
8196 hi
= ~(unsigned HOST_WIDE_INT
) 0;
8197 lo
= (~(unsigned HOST_WIDE_INT
) 0) << (prec
- 1);
8201 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
8202 << (prec
- HOST_BITS_PER_WIDE_INT
- 1));
8207 return build_int_cst_wide (outer
, lo
, hi
);
8210 /* Return nonzero if two operands that are suitable for PHI nodes are
8211 necessarily equal. Specifically, both ARG0 and ARG1 must be either
8212 SSA_NAME or invariant. Note that this is strictly an optimization.
8213 That is, callers of this function can directly call operand_equal_p
8214 and get the same result, only slower. */
8217 operand_equal_for_phi_arg_p (const_tree arg0
, const_tree arg1
)
8221 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
8223 return operand_equal_p (arg0
, arg1
, 0);
8226 /* Returns number of zeros at the end of binary representation of X.
8228 ??? Use ffs if available? */
8231 num_ending_zeros (const_tree x
)
8233 unsigned HOST_WIDE_INT fr
, nfr
;
8234 unsigned num
, abits
;
8235 tree type
= TREE_TYPE (x
);
8237 if (TREE_INT_CST_LOW (x
) == 0)
8239 num
= HOST_BITS_PER_WIDE_INT
;
8240 fr
= TREE_INT_CST_HIGH (x
);
8245 fr
= TREE_INT_CST_LOW (x
);
8248 for (abits
= HOST_BITS_PER_WIDE_INT
/ 2; abits
; abits
/= 2)
8251 if (nfr
<< abits
== fr
)
8258 if (num
> TYPE_PRECISION (type
))
8259 num
= TYPE_PRECISION (type
);
8261 return build_int_cst_type (type
, num
);
8265 #define WALK_SUBTREE(NODE) \
8268 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
8274 /* This is a subroutine of walk_tree that walks field of TYPE that are to
8275 be walked whenever a type is seen in the tree. Rest of operands and return
8276 value are as for walk_tree. */
8279 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
8280 struct pointer_set_t
*pset
, walk_tree_lh lh
)
8282 tree result
= NULL_TREE
;
8284 switch (TREE_CODE (type
))
8287 case REFERENCE_TYPE
:
8288 /* We have to worry about mutually recursive pointers. These can't
8289 be written in C. They can in Ada. It's pathological, but
8290 there's an ACATS test (c38102a) that checks it. Deal with this
8291 by checking if we're pointing to another pointer, that one
8292 points to another pointer, that one does too, and we have no htab.
8293 If so, get a hash table. We check three levels deep to avoid
8294 the cost of the hash table if we don't need one. */
8295 if (POINTER_TYPE_P (TREE_TYPE (type
))
8296 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
8297 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
8300 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
8308 /* ... fall through ... */
8311 WALK_SUBTREE (TREE_TYPE (type
));
8315 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
8320 WALK_SUBTREE (TREE_TYPE (type
));
8324 /* We never want to walk into default arguments. */
8325 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
8326 WALK_SUBTREE (TREE_VALUE (arg
));
8331 /* Don't follow this nodes's type if a pointer for fear that
8332 we'll have infinite recursion. If we have a PSET, then we
8335 || (!POINTER_TYPE_P (TREE_TYPE (type
))
8336 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
))
8337 WALK_SUBTREE (TREE_TYPE (type
));
8338 WALK_SUBTREE (TYPE_DOMAIN (type
));
8342 WALK_SUBTREE (TREE_TYPE (type
));
8343 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
8353 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
8354 called with the DATA and the address of each sub-tree. If FUNC returns a
8355 non-NULL value, the traversal is stopped, and the value returned by FUNC
8356 is returned. If PSET is non-NULL it is used to record the nodes visited,
8357 and to avoid visiting a node more than once. */
8360 walk_tree_1 (tree
*tp
, walk_tree_fn func
, void *data
,
8361 struct pointer_set_t
*pset
, walk_tree_lh lh
)
8363 enum tree_code code
;
8367 #define WALK_SUBTREE_TAIL(NODE) \
8371 goto tail_recurse; \
8376 /* Skip empty subtrees. */
8380 /* Don't walk the same tree twice, if the user has requested
8381 that we avoid doing so. */
8382 if (pset
&& pointer_set_insert (pset
, *tp
))
8385 /* Call the function. */
8387 result
= (*func
) (tp
, &walk_subtrees
, data
);
8389 /* If we found something, return it. */
8393 code
= TREE_CODE (*tp
);
8395 /* Even if we didn't, FUNC may have decided that there was nothing
8396 interesting below this point in the tree. */
8399 /* But we still need to check our siblings. */
8400 if (code
== TREE_LIST
)
8401 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
8402 else if (code
== OMP_CLAUSE
)
8403 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8410 result
= (*lh
) (tp
, &walk_subtrees
, func
, data
, pset
);
8411 if (result
|| !walk_subtrees
)
8418 case IDENTIFIER_NODE
:
8425 case PLACEHOLDER_EXPR
:
8429 /* None of these have subtrees other than those already walked
8434 WALK_SUBTREE (TREE_VALUE (*tp
));
8435 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
8440 int len
= TREE_VEC_LENGTH (*tp
);
8445 /* Walk all elements but the first. */
8447 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
8449 /* Now walk the first one as a tail call. */
8450 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
8454 WALK_SUBTREE (TREE_REALPART (*tp
));
8455 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
8459 unsigned HOST_WIDE_INT idx
;
8460 constructor_elt
*ce
;
8463 VEC_iterate(constructor_elt
, CONSTRUCTOR_ELTS (*tp
), idx
, ce
);
8465 WALK_SUBTREE (ce
->value
);
8470 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
8475 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= TREE_CHAIN (decl
))
8477 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
8478 into declarations that are just mentioned, rather than
8479 declared; they don't really belong to this part of the tree.
8480 And, we can see cycles: the initializer for a declaration
8481 can refer to the declaration itself. */
8482 WALK_SUBTREE (DECL_INITIAL (decl
));
8483 WALK_SUBTREE (DECL_SIZE (decl
));
8484 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
8486 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
8489 case STATEMENT_LIST
:
8491 tree_stmt_iterator i
;
8492 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
8493 WALK_SUBTREE (*tsi_stmt_ptr (i
));
8498 switch (OMP_CLAUSE_CODE (*tp
))
8500 case OMP_CLAUSE_PRIVATE
:
8501 case OMP_CLAUSE_SHARED
:
8502 case OMP_CLAUSE_FIRSTPRIVATE
:
8503 case OMP_CLAUSE_LASTPRIVATE
:
8504 case OMP_CLAUSE_COPYIN
:
8505 case OMP_CLAUSE_COPYPRIVATE
:
8507 case OMP_CLAUSE_NUM_THREADS
:
8508 case OMP_CLAUSE_SCHEDULE
:
8509 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 0));
8512 case OMP_CLAUSE_NOWAIT
:
8513 case OMP_CLAUSE_ORDERED
:
8514 case OMP_CLAUSE_DEFAULT
:
8515 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8517 case OMP_CLAUSE_REDUCTION
:
8520 for (i
= 0; i
< 4; i
++)
8521 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
8522 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8534 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
8535 But, we only want to walk once. */
8536 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
8537 for (i
= 0; i
< len
; ++i
)
8538 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
8539 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
8543 /* If this is a TYPE_DECL, walk into the fields of the type that it's
8544 defining. We only want to walk into these fields of a type in this
8545 case and not in the general case of a mere reference to the type.
8547 The criterion is as follows: if the field can be an expression, it
8548 must be walked only here. This should be in keeping with the fields
8549 that are directly gimplified in gimplify_type_sizes in order for the
8550 mark/copy-if-shared/unmark machinery of the gimplifier to work with
8551 variable-sized types.
8553 Note that DECLs get walked as part of processing the BIND_EXPR. */
8554 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
8556 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
8557 if (TREE_CODE (*type_p
) == ERROR_MARK
)
8560 /* Call the function for the type. See if it returns anything or
8561 doesn't want us to continue. If we are to continue, walk both
8562 the normal fields and those for the declaration case. */
8563 result
= (*func
) (type_p
, &walk_subtrees
, data
);
8564 if (result
|| !walk_subtrees
)
8567 result
= walk_type_fields (*type_p
, func
, data
, pset
, lh
);
8571 /* If this is a record type, also walk the fields. */
8572 if (TREE_CODE (*type_p
) == RECORD_TYPE
8573 || TREE_CODE (*type_p
) == UNION_TYPE
8574 || TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
8578 for (field
= TYPE_FIELDS (*type_p
); field
;
8579 field
= TREE_CHAIN (field
))
8581 /* We'd like to look at the type of the field, but we can
8582 easily get infinite recursion. So assume it's pointed
8583 to elsewhere in the tree. Also, ignore things that
8585 if (TREE_CODE (field
) != FIELD_DECL
)
8588 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
8589 WALK_SUBTREE (DECL_SIZE (field
));
8590 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
8591 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
8592 WALK_SUBTREE (DECL_QUALIFIER (field
));
8596 /* Same for scalar types. */
8597 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
8598 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
8599 || TREE_CODE (*type_p
) == INTEGER_TYPE
8600 || TREE_CODE (*type_p
) == FIXED_POINT_TYPE
8601 || TREE_CODE (*type_p
) == REAL_TYPE
)
8603 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
8604 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
8607 WALK_SUBTREE (TYPE_SIZE (*type_p
));
8608 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
8613 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
))
8614 || IS_GIMPLE_STMT_CODE_CLASS (TREE_CODE_CLASS (code
)))
8618 /* Walk over all the sub-trees of this operand. */
8619 len
= TREE_OPERAND_LENGTH (*tp
);
8621 /* Go through the subtrees. We need to do this in forward order so
8622 that the scope of a FOR_EXPR is handled properly. */
8625 for (i
= 0; i
< len
- 1; ++i
)
8626 WALK_SUBTREE (GENERIC_TREE_OPERAND (*tp
, i
));
8627 WALK_SUBTREE_TAIL (GENERIC_TREE_OPERAND (*tp
, len
- 1));
8630 /* If this is a type, walk the needed fields in the type. */
8631 else if (TYPE_P (*tp
))
8632 return walk_type_fields (*tp
, func
, data
, pset
, lh
);
8636 /* We didn't find what we were looking for. */
8639 #undef WALK_SUBTREE_TAIL
8643 /* Like walk_tree, but does not walk duplicate nodes more than once. */
8646 walk_tree_without_duplicates_1 (tree
*tp
, walk_tree_fn func
, void *data
,
8650 struct pointer_set_t
*pset
;
8652 pset
= pointer_set_create ();
8653 result
= walk_tree_1 (tp
, func
, data
, pset
, lh
);
8654 pointer_set_destroy (pset
);
8659 /* Return true if STMT is an empty statement or contains nothing but
8660 empty statements. */
8663 empty_body_p (tree stmt
)
8665 tree_stmt_iterator i
;
8668 if (IS_EMPTY_STMT (stmt
))
8670 else if (TREE_CODE (stmt
) == BIND_EXPR
)
8671 body
= BIND_EXPR_BODY (stmt
);
8672 else if (TREE_CODE (stmt
) == STATEMENT_LIST
)
8677 for (i
= tsi_start (body
); !tsi_end_p (i
); tsi_next (&i
))
8678 if (!empty_body_p (tsi_stmt (i
)))
8687 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
8689 if (IS_EXPR_CODE_CLASS (c
))
8690 return &t
->exp
.block
;
8691 else if (IS_GIMPLE_STMT_CODE_CLASS (c
))
8692 return &GIMPLE_STMT_BLOCK (t
);
8698 generic_tree_operand (tree node
, int i
)
8700 if (GIMPLE_STMT_P (node
))
8701 return &GIMPLE_STMT_OPERAND (node
, i
);
8702 return &TREE_OPERAND (node
, i
);
8706 generic_tree_type (tree node
)
8708 if (GIMPLE_STMT_P (node
))
8709 return &void_type_node
;
8710 return &TREE_TYPE (node
);
8713 /* Build and return a TREE_LIST of arguments in the CALL_EXPR exp.
8714 FIXME: don't use this function. It exists for compatibility with
8715 the old representation of CALL_EXPRs where a list was used to hold the
8716 arguments. Places that currently extract the arglist from a CALL_EXPR
8717 ought to be rewritten to use the CALL_EXPR itself. */
8719 call_expr_arglist (tree exp
)
8721 tree arglist
= NULL_TREE
;
8723 for (i
= call_expr_nargs (exp
) - 1; i
>= 0; i
--)
8724 arglist
= tree_cons (NULL_TREE
, CALL_EXPR_ARG (exp
, i
), arglist
);
8728 /* Return true if TYPE has a variable argument list. */
8731 stdarg_p (tree fntype
)
8733 function_args_iterator args_iter
;
8734 tree n
= NULL_TREE
, t
;
8739 FOREACH_FUNCTION_ARGS(fntype
, t
, args_iter
)
8744 return n
!= NULL_TREE
&& n
!= void_type_node
;
8747 /* Return true if TYPE has a prototype. */
8750 prototype_p (tree fntype
)
8754 gcc_assert (fntype
!= NULL_TREE
);
8756 t
= TYPE_ARG_TYPES (fntype
);
8757 return (t
!= NULL_TREE
);
8760 /* Return the number of arguments that a function has. */
8763 function_args_count (tree fntype
)
8765 function_args_iterator args_iter
;
8771 FOREACH_FUNCTION_ARGS(fntype
, t
, args_iter
)
8780 /* If BLOCK is inlined from an __attribute__((__artificial__))
8781 routine, return pointer to location from where it has been
8784 block_nonartificial_location (tree block
)
8786 location_t
*ret
= NULL
;
8788 while (block
&& TREE_CODE (block
) == BLOCK
8789 && BLOCK_ABSTRACT_ORIGIN (block
))
8791 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
8793 while (TREE_CODE (ao
) == BLOCK
&& BLOCK_ABSTRACT_ORIGIN (ao
))
8794 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
8796 if (TREE_CODE (ao
) == FUNCTION_DECL
)
8798 /* If AO is an artificial inline, point RET to the
8799 call site locus at which it has been inlined and continue
8800 the loop, in case AO's caller is also an artificial
8802 if (DECL_DECLARED_INLINE_P (ao
)
8803 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao
)))
8804 ret
= &BLOCK_SOURCE_LOCATION (block
);
8808 else if (TREE_CODE (ao
) != BLOCK
)
8811 block
= BLOCK_SUPERCONTEXT (block
);
8816 #include "gt-tree.h"