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 /* Tree code classes. */
57 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
58 #define END_OF_BASE_TREE_CODES tcc_exceptional,
60 const enum tree_code_class tree_code_type
[] = {
61 #include "all-tree.def"
65 #undef END_OF_BASE_TREE_CODES
67 /* Table indexed by tree code giving number of expression
68 operands beyond the fixed part of the node structure.
69 Not used for types or decls. */
71 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
72 #define END_OF_BASE_TREE_CODES 0,
74 const unsigned char tree_code_length
[] = {
75 #include "all-tree.def"
79 #undef END_OF_BASE_TREE_CODES
81 /* Names of tree components.
82 Used for printing out the tree and error messages. */
83 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
84 #define END_OF_BASE_TREE_CODES "@dummy",
86 const char *const tree_code_name
[] = {
87 #include "all-tree.def"
91 #undef END_OF_BASE_TREE_CODES
93 /* Each tree code class has an associated string representation.
94 These must correspond to the tree_code_class entries. */
96 const char *const tree_code_class_strings
[] =
111 /* obstack.[ch] explicitly declined to prototype this. */
112 extern int _obstack_allocated_p (struct obstack
*h
, void *obj
);
114 #ifdef GATHER_STATISTICS
115 /* Statistics-gathering stuff. */
117 int tree_node_counts
[(int) all_kinds
];
118 int tree_node_sizes
[(int) all_kinds
];
120 /* Keep in sync with tree.h:enum tree_node_kind. */
121 static const char * const tree_node_kind_names
[] = {
141 #endif /* GATHER_STATISTICS */
143 /* Unique id for next decl created. */
144 static GTY(()) int next_decl_uid
;
145 /* Unique id for next type created. */
146 static GTY(()) int next_type_uid
= 1;
148 /* Since we cannot rehash a type after it is in the table, we have to
149 keep the hash code. */
151 struct type_hash
GTY(())
157 /* Initial size of the hash table (rounded to next prime). */
158 #define TYPE_HASH_INITIAL_SIZE 1000
160 /* Now here is the hash table. When recording a type, it is added to
161 the slot whose index is the hash code. Note that the hash table is
162 used for several kinds of types (function types, array types and
163 array index range types, for now). While all these live in the
164 same table, they are completely independent, and the hash code is
165 computed differently for each of these. */
167 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash
)))
168 htab_t type_hash_table
;
170 /* Hash table and temporary node for larger integer const values. */
171 static GTY (()) tree int_cst_node
;
172 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
173 htab_t int_cst_hash_table
;
175 /* Hash table for optimization flags and target option flags. Use the same
176 hash table for both sets of options. Nodes for building the current
177 optimization and target option nodes. The assumption is most of the time
178 the options created will already be in the hash table, so we avoid
179 allocating and freeing up a node repeatably. */
180 static GTY (()) tree cl_optimization_node
;
181 static GTY (()) tree cl_target_option_node
;
182 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
183 htab_t cl_option_hash_table
;
185 /* General tree->tree mapping structure for use in hash tables. */
188 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
189 htab_t debug_expr_for_decl
;
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
192 htab_t value_expr_for_decl
;
194 static GTY ((if_marked ("tree_priority_map_marked_p"),
195 param_is (struct tree_priority_map
)))
196 htab_t init_priority_for_decl
;
198 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
199 htab_t restrict_base_for_decl
;
201 static void set_type_quals (tree
, int);
202 static int type_hash_eq (const void *, const void *);
203 static hashval_t
type_hash_hash (const void *);
204 static hashval_t
int_cst_hash_hash (const void *);
205 static int int_cst_hash_eq (const void *, const void *);
206 static hashval_t
cl_option_hash_hash (const void *);
207 static int cl_option_hash_eq (const void *, const void *);
208 static void print_type_hash_statistics (void);
209 static void print_debug_expr_statistics (void);
210 static void print_value_expr_statistics (void);
211 static int type_hash_marked_p (const void *);
212 static unsigned int type_hash_list (const_tree
, hashval_t
);
213 static unsigned int attribute_hash_list (const_tree
, hashval_t
);
215 tree global_trees
[TI_MAX
];
216 tree integer_types
[itk_none
];
218 unsigned char tree_contains_struct
[MAX_TREE_CODES
][64];
220 /* Number of operands for each OpenMP clause. */
221 unsigned const char omp_clause_num_ops
[] =
223 0, /* OMP_CLAUSE_ERROR */
224 1, /* OMP_CLAUSE_PRIVATE */
225 1, /* OMP_CLAUSE_SHARED */
226 1, /* OMP_CLAUSE_FIRSTPRIVATE */
227 2, /* OMP_CLAUSE_LASTPRIVATE */
228 4, /* OMP_CLAUSE_REDUCTION */
229 1, /* OMP_CLAUSE_COPYIN */
230 1, /* OMP_CLAUSE_COPYPRIVATE */
231 1, /* OMP_CLAUSE_IF */
232 1, /* OMP_CLAUSE_NUM_THREADS */
233 1, /* OMP_CLAUSE_SCHEDULE */
234 0, /* OMP_CLAUSE_NOWAIT */
235 0, /* OMP_CLAUSE_ORDERED */
236 0, /* OMP_CLAUSE_DEFAULT */
237 3, /* OMP_CLAUSE_COLLAPSE */
238 0 /* OMP_CLAUSE_UNTIED */
241 const char * const omp_clause_code_name
[] =
266 /* Initialize the hash table of types. */
267 type_hash_table
= htab_create_ggc (TYPE_HASH_INITIAL_SIZE
, type_hash_hash
,
270 debug_expr_for_decl
= htab_create_ggc (512, tree_map_hash
,
273 value_expr_for_decl
= htab_create_ggc (512, tree_map_hash
,
275 init_priority_for_decl
= htab_create_ggc (512, tree_priority_map_hash
,
276 tree_priority_map_eq
, 0);
277 restrict_base_for_decl
= htab_create_ggc (256, tree_map_hash
,
280 int_cst_hash_table
= htab_create_ggc (1024, int_cst_hash_hash
,
281 int_cst_hash_eq
, NULL
);
283 int_cst_node
= make_node (INTEGER_CST
);
285 cl_option_hash_table
= htab_create_ggc (64, cl_option_hash_hash
,
286 cl_option_hash_eq
, NULL
);
288 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
289 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
291 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
] = 1;
292 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_NON_COMMON
] = 1;
293 tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
] = 1;
296 tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
] = 1;
297 tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
] = 1;
298 tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
] = 1;
299 tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
] = 1;
300 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
] = 1;
301 tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
] = 1;
302 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
] = 1;
303 tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
] = 1;
304 tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
] = 1;
307 tree_contains_struct
[CONST_DECL
][TS_DECL_WRTL
] = 1;
308 tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
] = 1;
309 tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
] = 1;
310 tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
] = 1;
311 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
] = 1;
312 tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
] = 1;
314 tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
] = 1;
315 tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
] = 1;
316 tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
] = 1;
317 tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
] = 1;
318 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
] = 1;
319 tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
] = 1;
320 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
] = 1;
321 tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
] = 1;
322 tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
] = 1;
323 tree_contains_struct
[NAME_MEMORY_TAG
][TS_DECL_MINIMAL
] = 1;
324 tree_contains_struct
[SYMBOL_MEMORY_TAG
][TS_DECL_MINIMAL
] = 1;
325 tree_contains_struct
[MEMORY_PARTITION_TAG
][TS_DECL_MINIMAL
] = 1;
327 tree_contains_struct
[NAME_MEMORY_TAG
][TS_MEMORY_TAG
] = 1;
328 tree_contains_struct
[SYMBOL_MEMORY_TAG
][TS_MEMORY_TAG
] = 1;
329 tree_contains_struct
[MEMORY_PARTITION_TAG
][TS_MEMORY_TAG
] = 1;
331 tree_contains_struct
[MEMORY_PARTITION_TAG
][TS_MEMORY_PARTITION_TAG
] = 1;
333 tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
] = 1;
334 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
] = 1;
335 tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
] = 1;
336 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_WITH_VIS
] = 1;
338 tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
] = 1;
339 tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
] = 1;
340 tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
] = 1;
341 tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
] = 1;
342 tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
] = 1;
343 tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
] = 1;
344 tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
] = 1;
345 tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
] = 1;
346 tree_contains_struct
[IMPORTED_DECL
][TS_DECL_MINIMAL
] = 1;
347 tree_contains_struct
[IMPORTED_DECL
][TS_DECL_COMMON
] = 1;
349 lang_hooks
.init_ts ();
353 /* The name of the object as the assembler will see it (but before any
354 translations made by ASM_OUTPUT_LABELREF). Often this is the same
355 as DECL_NAME. It is an IDENTIFIER_NODE. */
357 decl_assembler_name (tree decl
)
359 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
360 lang_hooks
.set_decl_assembler_name (decl
);
361 return DECL_WITH_VIS_CHECK (decl
)->decl_with_vis
.assembler_name
;
364 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
367 decl_assembler_name_equal (tree decl
, const_tree asmname
)
369 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
370 const char *decl_str
;
371 const char *asmname_str
;
374 if (decl_asmname
== asmname
)
377 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
378 asmname_str
= IDENTIFIER_POINTER (asmname
);
381 /* If the target assembler name was set by the user, things are trickier.
382 We have a leading '*' to begin with. After that, it's arguable what
383 is the correct thing to do with -fleading-underscore. Arguably, we've
384 historically been doing the wrong thing in assemble_alias by always
385 printing the leading underscore. Since we're not changing that, make
386 sure user_label_prefix follows the '*' before matching. */
387 if (decl_str
[0] == '*')
389 size_t ulp_len
= strlen (user_label_prefix
);
395 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
396 decl_str
+= ulp_len
, test
=true;
400 if (asmname_str
[0] == '*')
402 size_t ulp_len
= strlen (user_label_prefix
);
408 else if (strncmp (asmname_str
, user_label_prefix
, ulp_len
) == 0)
409 asmname_str
+= ulp_len
, test
=true;
416 return strcmp (decl_str
, asmname_str
) == 0;
419 /* Hash asmnames ignoring the user specified marks. */
422 decl_assembler_name_hash (const_tree asmname
)
424 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
426 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
427 size_t ulp_len
= strlen (user_label_prefix
);
431 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
434 return htab_hash_string (decl_str
);
437 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
440 /* Compute the number of bytes occupied by a tree with code CODE.
441 This function cannot be used for nodes that have variable sizes,
442 including TREE_VEC, STRING_CST, and CALL_EXPR. */
444 tree_code_size (enum tree_code code
)
446 switch (TREE_CODE_CLASS (code
))
448 case tcc_declaration
: /* A decl node */
453 return sizeof (struct tree_field_decl
);
455 return sizeof (struct tree_parm_decl
);
457 return sizeof (struct tree_var_decl
);
459 return sizeof (struct tree_label_decl
);
461 return sizeof (struct tree_result_decl
);
463 return sizeof (struct tree_const_decl
);
465 return sizeof (struct tree_type_decl
);
467 return sizeof (struct tree_function_decl
);
468 case NAME_MEMORY_TAG
:
469 case SYMBOL_MEMORY_TAG
:
470 return sizeof (struct tree_memory_tag
);
471 case MEMORY_PARTITION_TAG
:
472 return sizeof (struct tree_memory_partition_tag
);
474 return sizeof (struct tree_decl_non_common
);
478 case tcc_type
: /* a type node */
479 return sizeof (struct tree_type
);
481 case tcc_reference
: /* a reference */
482 case tcc_expression
: /* an expression */
483 case tcc_statement
: /* an expression with side effects */
484 case tcc_comparison
: /* a comparison expression */
485 case tcc_unary
: /* a unary arithmetic expression */
486 case tcc_binary
: /* a binary arithmetic expression */
487 return (sizeof (struct tree_exp
)
488 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (tree
));
490 case tcc_constant
: /* a constant */
493 case INTEGER_CST
: return sizeof (struct tree_int_cst
);
494 case REAL_CST
: return sizeof (struct tree_real_cst
);
495 case FIXED_CST
: return sizeof (struct tree_fixed_cst
);
496 case COMPLEX_CST
: return sizeof (struct tree_complex
);
497 case VECTOR_CST
: return sizeof (struct tree_vector
);
498 case STRING_CST
: gcc_unreachable ();
500 return lang_hooks
.tree_size (code
);
503 case tcc_exceptional
: /* something random, like an identifier. */
506 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
507 case TREE_LIST
: return sizeof (struct tree_list
);
510 case PLACEHOLDER_EXPR
: return sizeof (struct tree_common
);
513 case OMP_CLAUSE
: gcc_unreachable ();
515 case SSA_NAME
: return sizeof (struct tree_ssa_name
);
517 case STATEMENT_LIST
: return sizeof (struct tree_statement_list
);
518 case BLOCK
: return sizeof (struct tree_block
);
519 case CONSTRUCTOR
: return sizeof (struct tree_constructor
);
520 case OPTIMIZATION_NODE
: return sizeof (struct tree_optimization_option
);
521 case TARGET_OPTION_NODE
: return sizeof (struct tree_target_option
);
524 return lang_hooks
.tree_size (code
);
532 /* Compute the number of bytes occupied by NODE. This routine only
533 looks at TREE_CODE, except for those nodes that have variable sizes. */
535 tree_size (const_tree node
)
537 const enum tree_code code
= TREE_CODE (node
);
541 return (offsetof (struct tree_binfo
, base_binfos
)
542 + VEC_embedded_size (tree
, BINFO_N_BASE_BINFOS (node
)));
545 return (sizeof (struct tree_vec
)
546 + (TREE_VEC_LENGTH (node
) - 1) * sizeof (tree
));
549 return TREE_STRING_LENGTH (node
) + offsetof (struct tree_string
, str
) + 1;
552 return (sizeof (struct tree_omp_clause
)
553 + (omp_clause_num_ops
[OMP_CLAUSE_CODE (node
)] - 1)
557 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
558 return (sizeof (struct tree_exp
)
559 + (VL_EXP_OPERAND_LENGTH (node
) - 1) * sizeof (tree
));
561 return tree_code_size (code
);
565 /* Return a newly allocated node of code CODE. For decl and type
566 nodes, some other fields are initialized. The rest of the node is
567 initialized to zero. This function cannot be used for TREE_VEC or
568 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size.
570 Achoo! I got a code in the node. */
573 make_node_stat (enum tree_code code MEM_STAT_DECL
)
576 enum tree_code_class type
= TREE_CODE_CLASS (code
);
577 size_t length
= tree_code_size (code
);
578 #ifdef GATHER_STATISTICS
583 case tcc_declaration
: /* A decl node */
587 case tcc_type
: /* a type node */
591 case tcc_statement
: /* an expression with side effects */
595 case tcc_reference
: /* a reference */
599 case tcc_expression
: /* an expression */
600 case tcc_comparison
: /* a comparison expression */
601 case tcc_unary
: /* a unary arithmetic expression */
602 case tcc_binary
: /* a binary arithmetic expression */
606 case tcc_constant
: /* a constant */
610 case tcc_exceptional
: /* something random, like an identifier. */
613 case IDENTIFIER_NODE
:
626 kind
= ssa_name_kind
;
647 tree_node_counts
[(int) kind
]++;
648 tree_node_sizes
[(int) kind
] += length
;
651 if (code
== IDENTIFIER_NODE
)
652 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_id_zone
);
654 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
656 memset (t
, 0, length
);
658 TREE_SET_CODE (t
, code
);
663 TREE_SIDE_EFFECTS (t
) = 1;
666 case tcc_declaration
:
667 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
669 if (code
== FUNCTION_DECL
)
671 DECL_ALIGN (t
) = FUNCTION_BOUNDARY
;
672 DECL_MODE (t
) = FUNCTION_MODE
;
676 /* We have not yet computed the alias set for this declaration. */
677 DECL_POINTER_ALIAS_SET (t
) = -1;
679 DECL_SOURCE_LOCATION (t
) = input_location
;
680 DECL_UID (t
) = next_decl_uid
++;
685 TYPE_UID (t
) = next_type_uid
++;
686 TYPE_ALIGN (t
) = BITS_PER_UNIT
;
687 TYPE_USER_ALIGN (t
) = 0;
688 TYPE_MAIN_VARIANT (t
) = t
;
689 TYPE_CANONICAL (t
) = t
;
691 /* Default to no attributes for type, but let target change that. */
692 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
693 targetm
.set_default_type_attributes (t
);
695 /* We have not yet computed the alias set for this type. */
696 TYPE_ALIAS_SET (t
) = -1;
700 TREE_CONSTANT (t
) = 1;
709 case PREDECREMENT_EXPR
:
710 case PREINCREMENT_EXPR
:
711 case POSTDECREMENT_EXPR
:
712 case POSTINCREMENT_EXPR
:
713 /* All of these have side-effects, no matter what their
715 TREE_SIDE_EFFECTS (t
) = 1;
724 /* Other classes need no special treatment. */
731 /* Return a new node with the same contents as NODE except that its
732 TREE_CHAIN is zero and it has a fresh uid. */
735 copy_node_stat (tree node MEM_STAT_DECL
)
738 enum tree_code code
= TREE_CODE (node
);
741 gcc_assert (code
!= STATEMENT_LIST
);
743 length
= tree_size (node
);
744 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
745 memcpy (t
, node
, length
);
748 TREE_ASM_WRITTEN (t
) = 0;
749 TREE_VISITED (t
) = 0;
752 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
754 DECL_UID (t
) = next_decl_uid
++;
755 if ((TREE_CODE (node
) == PARM_DECL
|| TREE_CODE (node
) == VAR_DECL
)
756 && DECL_HAS_VALUE_EXPR_P (node
))
758 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
759 DECL_HAS_VALUE_EXPR_P (t
) = 1;
761 if (TREE_CODE (node
) == VAR_DECL
&& DECL_HAS_INIT_PRIORITY_P (node
))
763 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
764 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
766 if (TREE_CODE (node
) == VAR_DECL
&& DECL_BASED_ON_RESTRICT_P (node
))
768 SET_DECL_RESTRICT_BASE (t
, DECL_GET_RESTRICT_BASE (node
));
769 DECL_BASED_ON_RESTRICT_P (t
) = 1;
772 else if (TREE_CODE_CLASS (code
) == tcc_type
)
774 TYPE_UID (t
) = next_type_uid
++;
775 /* The following is so that the debug code for
776 the copy is different from the original type.
777 The two statements usually duplicate each other
778 (because they clear fields of the same union),
779 but the optimizer should catch that. */
780 TYPE_SYMTAB_POINTER (t
) = 0;
781 TYPE_SYMTAB_ADDRESS (t
) = 0;
783 /* Do not copy the values cache. */
784 if (TYPE_CACHED_VALUES_P(t
))
786 TYPE_CACHED_VALUES_P (t
) = 0;
787 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
794 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
795 For example, this can copy a list made of TREE_LIST nodes. */
798 copy_list (tree list
)
806 head
= prev
= copy_node (list
);
807 next
= TREE_CHAIN (list
);
810 TREE_CHAIN (prev
) = copy_node (next
);
811 prev
= TREE_CHAIN (prev
);
812 next
= TREE_CHAIN (next
);
818 /* Create an INT_CST node with a LOW value sign extended. */
821 build_int_cst (tree type
, HOST_WIDE_INT low
)
823 /* Support legacy code. */
825 type
= integer_type_node
;
827 return build_int_cst_wide (type
, low
, low
< 0 ? -1 : 0);
830 /* Create an INT_CST node with a LOW value zero extended. */
833 build_int_cstu (tree type
, unsigned HOST_WIDE_INT low
)
835 return build_int_cst_wide (type
, low
, 0);
838 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
839 if it is negative. This function is similar to build_int_cst, but
840 the extra bits outside of the type precision are cleared. Constants
841 with these extra bits may confuse the fold so that it detects overflows
842 even in cases when they do not occur, and in general should be avoided.
843 We cannot however make this a default behavior of build_int_cst without
844 more intrusive changes, since there are parts of gcc that rely on the extra
845 precision of the integer constants. */
848 build_int_cst_type (tree type
, HOST_WIDE_INT low
)
850 unsigned HOST_WIDE_INT low1
;
855 fit_double_type (low
, low
< 0 ? -1 : 0, &low1
, &hi
, type
);
857 return build_int_cst_wide (type
, low1
, hi
);
860 /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated
861 and sign extended according to the value range of TYPE. */
864 build_int_cst_wide_type (tree type
,
865 unsigned HOST_WIDE_INT low
, HOST_WIDE_INT high
)
867 fit_double_type (low
, high
, &low
, &high
, type
);
868 return build_int_cst_wide (type
, low
, high
);
871 /* These are the hash table functions for the hash table of INTEGER_CST
872 nodes of a sizetype. */
874 /* Return the hash code code X, an INTEGER_CST. */
877 int_cst_hash_hash (const void *x
)
879 const_tree
const t
= (const_tree
) x
;
881 return (TREE_INT_CST_HIGH (t
) ^ TREE_INT_CST_LOW (t
)
882 ^ htab_hash_pointer (TREE_TYPE (t
)));
885 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
886 is the same as that given by *Y, which is the same. */
889 int_cst_hash_eq (const void *x
, const void *y
)
891 const_tree
const xt
= (const_tree
) x
;
892 const_tree
const yt
= (const_tree
) y
;
894 return (TREE_TYPE (xt
) == TREE_TYPE (yt
)
895 && TREE_INT_CST_HIGH (xt
) == TREE_INT_CST_HIGH (yt
)
896 && TREE_INT_CST_LOW (xt
) == TREE_INT_CST_LOW (yt
));
899 /* Create an INT_CST node of TYPE and value HI:LOW.
900 The returned node is always shared. For small integers we use a
901 per-type vector cache, for larger ones we use a single hash table. */
904 build_int_cst_wide (tree type
, unsigned HOST_WIDE_INT low
, HOST_WIDE_INT hi
)
912 switch (TREE_CODE (type
))
916 /* Cache NULL pointer. */
925 /* Cache false or true. */
933 if (TYPE_UNSIGNED (type
))
936 limit
= INTEGER_SHARE_LIMIT
;
937 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
943 limit
= INTEGER_SHARE_LIMIT
+ 1;
944 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
946 else if (hi
== -1 && low
== -(unsigned HOST_WIDE_INT
)1)
960 /* Look for it in the type's vector of small shared ints. */
961 if (!TYPE_CACHED_VALUES_P (type
))
963 TYPE_CACHED_VALUES_P (type
) = 1;
964 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
967 t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
);
970 /* Make sure no one is clobbering the shared constant. */
971 gcc_assert (TREE_TYPE (t
) == type
);
972 gcc_assert (TREE_INT_CST_LOW (t
) == low
);
973 gcc_assert (TREE_INT_CST_HIGH (t
) == hi
);
977 /* Create a new shared int. */
978 t
= make_node (INTEGER_CST
);
980 TREE_INT_CST_LOW (t
) = low
;
981 TREE_INT_CST_HIGH (t
) = hi
;
982 TREE_TYPE (t
) = type
;
984 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
989 /* Use the cache of larger shared ints. */
992 TREE_INT_CST_LOW (int_cst_node
) = low
;
993 TREE_INT_CST_HIGH (int_cst_node
) = hi
;
994 TREE_TYPE (int_cst_node
) = type
;
996 slot
= htab_find_slot (int_cst_hash_table
, int_cst_node
, INSERT
);
1000 /* Insert this one into the hash table. */
1003 /* Make a new node for next time round. */
1004 int_cst_node
= make_node (INTEGER_CST
);
1011 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1012 and the rest are zeros. */
1015 build_low_bits_mask (tree type
, unsigned bits
)
1017 unsigned HOST_WIDE_INT low
;
1019 unsigned HOST_WIDE_INT all_ones
= ~(unsigned HOST_WIDE_INT
) 0;
1021 gcc_assert (bits
<= TYPE_PRECISION (type
));
1023 if (bits
== TYPE_PRECISION (type
)
1024 && !TYPE_UNSIGNED (type
))
1026 /* Sign extended all-ones mask. */
1030 else if (bits
<= HOST_BITS_PER_WIDE_INT
)
1032 low
= all_ones
>> (HOST_BITS_PER_WIDE_INT
- bits
);
1037 bits
-= HOST_BITS_PER_WIDE_INT
;
1039 high
= all_ones
>> (HOST_BITS_PER_WIDE_INT
- bits
);
1042 return build_int_cst_wide (type
, low
, high
);
1045 /* Checks that X is integer constant that can be expressed in (unsigned)
1046 HOST_WIDE_INT without loss of precision. */
1049 cst_and_fits_in_hwi (const_tree x
)
1051 if (TREE_CODE (x
) != INTEGER_CST
)
1054 if (TYPE_PRECISION (TREE_TYPE (x
)) > HOST_BITS_PER_WIDE_INT
)
1057 return (TREE_INT_CST_HIGH (x
) == 0
1058 || TREE_INT_CST_HIGH (x
) == -1);
1061 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1062 are in a list pointed to by VALS. */
1065 build_vector (tree type
, tree vals
)
1067 tree v
= make_node (VECTOR_CST
);
1071 TREE_VECTOR_CST_ELTS (v
) = vals
;
1072 TREE_TYPE (v
) = type
;
1074 /* Iterate through elements and check for overflow. */
1075 for (link
= vals
; link
; link
= TREE_CHAIN (link
))
1077 tree value
= TREE_VALUE (link
);
1079 /* Don't crash if we get an address constant. */
1080 if (!CONSTANT_CLASS_P (value
))
1083 over
|= TREE_OVERFLOW (value
);
1086 TREE_OVERFLOW (v
) = over
;
1090 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1091 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1094 build_vector_from_ctor (tree type
, VEC(constructor_elt
,gc
) *v
)
1096 tree list
= NULL_TREE
;
1097 unsigned HOST_WIDE_INT idx
;
1100 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1101 list
= tree_cons (NULL_TREE
, value
, list
);
1102 return build_vector (type
, nreverse (list
));
1105 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1106 are in the VEC pointed to by VALS. */
1108 build_constructor (tree type
, VEC(constructor_elt
,gc
) *vals
)
1110 tree c
= make_node (CONSTRUCTOR
);
1111 TREE_TYPE (c
) = type
;
1112 CONSTRUCTOR_ELTS (c
) = vals
;
1116 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1119 build_constructor_single (tree type
, tree index
, tree value
)
1121 VEC(constructor_elt
,gc
) *v
;
1122 constructor_elt
*elt
;
1125 v
= VEC_alloc (constructor_elt
, gc
, 1);
1126 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
1130 t
= build_constructor (type
, v
);
1131 TREE_CONSTANT (t
) = TREE_CONSTANT (value
);
1136 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1137 are in a list pointed to by VALS. */
1139 build_constructor_from_list (tree type
, tree vals
)
1142 VEC(constructor_elt
,gc
) *v
= NULL
;
1143 bool constant_p
= true;
1147 v
= VEC_alloc (constructor_elt
, gc
, list_length (vals
));
1148 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
1150 constructor_elt
*elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
1151 val
= TREE_VALUE (t
);
1152 elt
->index
= TREE_PURPOSE (t
);
1154 if (!TREE_CONSTANT (val
))
1159 t
= build_constructor (type
, v
);
1160 TREE_CONSTANT (t
) = constant_p
;
1164 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1167 build_fixed (tree type
, FIXED_VALUE_TYPE f
)
1170 FIXED_VALUE_TYPE
*fp
;
1172 v
= make_node (FIXED_CST
);
1173 fp
= GGC_NEW (FIXED_VALUE_TYPE
);
1174 memcpy (fp
, &f
, sizeof (FIXED_VALUE_TYPE
));
1176 TREE_TYPE (v
) = type
;
1177 TREE_FIXED_CST_PTR (v
) = fp
;
1181 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1184 build_real (tree type
, REAL_VALUE_TYPE d
)
1187 REAL_VALUE_TYPE
*dp
;
1190 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1191 Consider doing it via real_convert now. */
1193 v
= make_node (REAL_CST
);
1194 dp
= GGC_NEW (REAL_VALUE_TYPE
);
1195 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
1197 TREE_TYPE (v
) = type
;
1198 TREE_REAL_CST_PTR (v
) = dp
;
1199 TREE_OVERFLOW (v
) = overflow
;
1203 /* Return a new REAL_CST node whose type is TYPE
1204 and whose value is the integer value of the INTEGER_CST node I. */
1207 real_value_from_int_cst (const_tree type
, const_tree i
)
1211 /* Clear all bits of the real value type so that we can later do
1212 bitwise comparisons to see if two values are the same. */
1213 memset (&d
, 0, sizeof d
);
1215 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
,
1216 TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
),
1217 TYPE_UNSIGNED (TREE_TYPE (i
)));
1221 /* Given a tree representing an integer constant I, return a tree
1222 representing the same value as a floating-point constant of type TYPE. */
1225 build_real_from_int_cst (tree type
, const_tree i
)
1228 int overflow
= TREE_OVERFLOW (i
);
1230 v
= build_real (type
, real_value_from_int_cst (type
, i
));
1232 TREE_OVERFLOW (v
) |= overflow
;
1236 /* Return a newly constructed STRING_CST node whose value is
1237 the LEN characters at STR.
1238 The TREE_TYPE is not initialized. */
1241 build_string (int len
, const char *str
)
1246 /* Do not waste bytes provided by padding of struct tree_string. */
1247 length
= len
+ offsetof (struct tree_string
, str
) + 1;
1249 #ifdef GATHER_STATISTICS
1250 tree_node_counts
[(int) c_kind
]++;
1251 tree_node_sizes
[(int) c_kind
] += length
;
1254 s
= ggc_alloc_tree (length
);
1256 memset (s
, 0, sizeof (struct tree_common
));
1257 TREE_SET_CODE (s
, STRING_CST
);
1258 TREE_CONSTANT (s
) = 1;
1259 TREE_STRING_LENGTH (s
) = len
;
1260 memcpy (s
->string
.str
, str
, len
);
1261 s
->string
.str
[len
] = '\0';
1266 /* Return a newly constructed COMPLEX_CST node whose value is
1267 specified by the real and imaginary parts REAL and IMAG.
1268 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1269 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1272 build_complex (tree type
, tree real
, tree imag
)
1274 tree t
= make_node (COMPLEX_CST
);
1276 TREE_REALPART (t
) = real
;
1277 TREE_IMAGPART (t
) = imag
;
1278 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
1279 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1283 /* Return a constant of arithmetic type TYPE which is the
1284 multiplicative identity of the set TYPE. */
1287 build_one_cst (tree type
)
1289 switch (TREE_CODE (type
))
1291 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1292 case POINTER_TYPE
: case REFERENCE_TYPE
:
1294 return build_int_cst (type
, 1);
1297 return build_real (type
, dconst1
);
1299 case FIXED_POINT_TYPE
:
1300 /* We can only generate 1 for accum types. */
1301 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
1302 return build_fixed (type
, FCONST1(TYPE_MODE (type
)));
1309 scalar
= build_one_cst (TREE_TYPE (type
));
1311 /* Create 'vect_cst_ = {cst,cst,...,cst}' */
1313 for (i
= TYPE_VECTOR_SUBPARTS (type
); --i
>= 0; )
1314 cst
= tree_cons (NULL_TREE
, scalar
, cst
);
1316 return build_vector (type
, cst
);
1320 return build_complex (type
,
1321 build_one_cst (TREE_TYPE (type
)),
1322 fold_convert (TREE_TYPE (type
), integer_zero_node
));
1329 /* Build a BINFO with LEN language slots. */
1332 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL
)
1335 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
1336 + VEC_embedded_size (tree
, base_binfos
));
1338 #ifdef GATHER_STATISTICS
1339 tree_node_counts
[(int) binfo_kind
]++;
1340 tree_node_sizes
[(int) binfo_kind
] += length
;
1343 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
1345 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
1347 TREE_SET_CODE (t
, TREE_BINFO
);
1349 VEC_embedded_init (tree
, BINFO_BASE_BINFOS (t
), base_binfos
);
1355 /* Build a newly constructed TREE_VEC node of length LEN. */
1358 make_tree_vec_stat (int len MEM_STAT_DECL
)
1361 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
1363 #ifdef GATHER_STATISTICS
1364 tree_node_counts
[(int) vec_kind
]++;
1365 tree_node_sizes
[(int) vec_kind
] += length
;
1368 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
1370 memset (t
, 0, length
);
1372 TREE_SET_CODE (t
, TREE_VEC
);
1373 TREE_VEC_LENGTH (t
) = len
;
1378 /* Return 1 if EXPR is the integer constant zero or a complex constant
1382 integer_zerop (const_tree expr
)
1386 return ((TREE_CODE (expr
) == INTEGER_CST
1387 && TREE_INT_CST_LOW (expr
) == 0
1388 && TREE_INT_CST_HIGH (expr
) == 0)
1389 || (TREE_CODE (expr
) == COMPLEX_CST
1390 && integer_zerop (TREE_REALPART (expr
))
1391 && integer_zerop (TREE_IMAGPART (expr
))));
1394 /* Return 1 if EXPR is the integer constant one or the corresponding
1395 complex constant. */
1398 integer_onep (const_tree expr
)
1402 return ((TREE_CODE (expr
) == INTEGER_CST
1403 && TREE_INT_CST_LOW (expr
) == 1
1404 && TREE_INT_CST_HIGH (expr
) == 0)
1405 || (TREE_CODE (expr
) == COMPLEX_CST
1406 && integer_onep (TREE_REALPART (expr
))
1407 && integer_zerop (TREE_IMAGPART (expr
))));
1410 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1411 it contains. Likewise for the corresponding complex constant. */
1414 integer_all_onesp (const_tree expr
)
1421 if (TREE_CODE (expr
) == COMPLEX_CST
1422 && integer_all_onesp (TREE_REALPART (expr
))
1423 && integer_zerop (TREE_IMAGPART (expr
)))
1426 else if (TREE_CODE (expr
) != INTEGER_CST
)
1429 uns
= TYPE_UNSIGNED (TREE_TYPE (expr
));
1430 if (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1431 && TREE_INT_CST_HIGH (expr
) == -1)
1436 /* Note that using TYPE_PRECISION here is wrong. We care about the
1437 actual bits, not the (arbitrary) range of the type. */
1438 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr
)));
1439 if (prec
>= HOST_BITS_PER_WIDE_INT
)
1441 HOST_WIDE_INT high_value
;
1444 shift_amount
= prec
- HOST_BITS_PER_WIDE_INT
;
1446 /* Can not handle precisions greater than twice the host int size. */
1447 gcc_assert (shift_amount
<= HOST_BITS_PER_WIDE_INT
);
1448 if (shift_amount
== HOST_BITS_PER_WIDE_INT
)
1449 /* Shifting by the host word size is undefined according to the ANSI
1450 standard, so we must handle this as a special case. */
1453 high_value
= ((HOST_WIDE_INT
) 1 << shift_amount
) - 1;
1455 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1456 && TREE_INT_CST_HIGH (expr
) == high_value
);
1459 return TREE_INT_CST_LOW (expr
) == ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
1462 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1466 integer_pow2p (const_tree expr
)
1469 HOST_WIDE_INT high
, low
;
1473 if (TREE_CODE (expr
) == COMPLEX_CST
1474 && integer_pow2p (TREE_REALPART (expr
))
1475 && integer_zerop (TREE_IMAGPART (expr
)))
1478 if (TREE_CODE (expr
) != INTEGER_CST
)
1481 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1482 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1483 high
= TREE_INT_CST_HIGH (expr
);
1484 low
= TREE_INT_CST_LOW (expr
);
1486 /* First clear all bits that are beyond the type's precision in case
1487 we've been sign extended. */
1489 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1491 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1492 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1496 if (prec
< HOST_BITS_PER_WIDE_INT
)
1497 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1500 if (high
== 0 && low
== 0)
1503 return ((high
== 0 && (low
& (low
- 1)) == 0)
1504 || (low
== 0 && (high
& (high
- 1)) == 0));
1507 /* Return 1 if EXPR is an integer constant other than zero or a
1508 complex constant other than zero. */
1511 integer_nonzerop (const_tree expr
)
1515 return ((TREE_CODE (expr
) == INTEGER_CST
1516 && (TREE_INT_CST_LOW (expr
) != 0
1517 || TREE_INT_CST_HIGH (expr
) != 0))
1518 || (TREE_CODE (expr
) == COMPLEX_CST
1519 && (integer_nonzerop (TREE_REALPART (expr
))
1520 || integer_nonzerop (TREE_IMAGPART (expr
)))));
1523 /* Return 1 if EXPR is the fixed-point constant zero. */
1526 fixed_zerop (const_tree expr
)
1528 return (TREE_CODE (expr
) == FIXED_CST
1529 && double_int_zero_p (TREE_FIXED_CST (expr
).data
));
1532 /* Return the power of two represented by a tree node known to be a
1536 tree_log2 (const_tree expr
)
1539 HOST_WIDE_INT high
, low
;
1543 if (TREE_CODE (expr
) == COMPLEX_CST
)
1544 return tree_log2 (TREE_REALPART (expr
));
1546 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1547 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1549 high
= TREE_INT_CST_HIGH (expr
);
1550 low
= TREE_INT_CST_LOW (expr
);
1552 /* First clear all bits that are beyond the type's precision in case
1553 we've been sign extended. */
1555 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1557 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1558 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1562 if (prec
< HOST_BITS_PER_WIDE_INT
)
1563 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1566 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ exact_log2 (high
)
1567 : exact_log2 (low
));
1570 /* Similar, but return the largest integer Y such that 2 ** Y is less
1571 than or equal to EXPR. */
1574 tree_floor_log2 (const_tree expr
)
1577 HOST_WIDE_INT high
, low
;
1581 if (TREE_CODE (expr
) == COMPLEX_CST
)
1582 return tree_log2 (TREE_REALPART (expr
));
1584 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1585 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1587 high
= TREE_INT_CST_HIGH (expr
);
1588 low
= TREE_INT_CST_LOW (expr
);
1590 /* First clear all bits that are beyond the type's precision in case
1591 we've been sign extended. Ignore if type's precision hasn't been set
1592 since what we are doing is setting it. */
1594 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
|| prec
== 0)
1596 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1597 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1601 if (prec
< HOST_BITS_PER_WIDE_INT
)
1602 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1605 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ floor_log2 (high
)
1606 : floor_log2 (low
));
1609 /* Return 1 if EXPR is the real constant zero. */
1612 real_zerop (const_tree expr
)
1616 return ((TREE_CODE (expr
) == REAL_CST
1617 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
))
1618 || (TREE_CODE (expr
) == COMPLEX_CST
1619 && real_zerop (TREE_REALPART (expr
))
1620 && real_zerop (TREE_IMAGPART (expr
))));
1623 /* Return 1 if EXPR is the real constant one in real or complex form. */
1626 real_onep (const_tree expr
)
1630 return ((TREE_CODE (expr
) == REAL_CST
1631 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
))
1632 || (TREE_CODE (expr
) == COMPLEX_CST
1633 && real_onep (TREE_REALPART (expr
))
1634 && real_zerop (TREE_IMAGPART (expr
))));
1637 /* Return 1 if EXPR is the real constant two. */
1640 real_twop (const_tree expr
)
1644 return ((TREE_CODE (expr
) == REAL_CST
1645 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst2
))
1646 || (TREE_CODE (expr
) == COMPLEX_CST
1647 && real_twop (TREE_REALPART (expr
))
1648 && real_zerop (TREE_IMAGPART (expr
))));
1651 /* Return 1 if EXPR is the real constant minus one. */
1654 real_minus_onep (const_tree expr
)
1658 return ((TREE_CODE (expr
) == REAL_CST
1659 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconstm1
))
1660 || (TREE_CODE (expr
) == COMPLEX_CST
1661 && real_minus_onep (TREE_REALPART (expr
))
1662 && real_zerop (TREE_IMAGPART (expr
))));
1665 /* Nonzero if EXP is a constant or a cast of a constant. */
1668 really_constant_p (const_tree exp
)
1670 /* This is not quite the same as STRIP_NOPS. It does more. */
1671 while (CONVERT_EXPR_P (exp
)
1672 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
1673 exp
= TREE_OPERAND (exp
, 0);
1674 return TREE_CONSTANT (exp
);
1677 /* Return first list element whose TREE_VALUE is ELEM.
1678 Return 0 if ELEM is not in LIST. */
1681 value_member (tree elem
, tree list
)
1685 if (elem
== TREE_VALUE (list
))
1687 list
= TREE_CHAIN (list
);
1692 /* Return first list element whose TREE_PURPOSE is ELEM.
1693 Return 0 if ELEM is not in LIST. */
1696 purpose_member (const_tree elem
, tree list
)
1700 if (elem
== TREE_PURPOSE (list
))
1702 list
= TREE_CHAIN (list
);
1707 /* Return nonzero if ELEM is part of the chain CHAIN. */
1710 chain_member (const_tree elem
, const_tree chain
)
1716 chain
= TREE_CHAIN (chain
);
1722 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1723 We expect a null pointer to mark the end of the chain.
1724 This is the Lisp primitive `length'. */
1727 list_length (const_tree t
)
1730 #ifdef ENABLE_TREE_CHECKING
1738 #ifdef ENABLE_TREE_CHECKING
1741 gcc_assert (p
!= q
);
1749 /* Returns the number of FIELD_DECLs in TYPE. */
1752 fields_length (const_tree type
)
1754 tree t
= TYPE_FIELDS (type
);
1757 for (; t
; t
= TREE_CHAIN (t
))
1758 if (TREE_CODE (t
) == FIELD_DECL
)
1764 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1765 by modifying the last node in chain 1 to point to chain 2.
1766 This is the Lisp primitive `nconc'. */
1769 chainon (tree op1
, tree op2
)
1778 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
1780 TREE_CHAIN (t1
) = op2
;
1782 #ifdef ENABLE_TREE_CHECKING
1785 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
1786 gcc_assert (t2
!= t1
);
1793 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1796 tree_last (tree chain
)
1800 while ((next
= TREE_CHAIN (chain
)))
1805 /* Reverse the order of elements in the chain T,
1806 and return the new head of the chain (old last element). */
1811 tree prev
= 0, decl
, next
;
1812 for (decl
= t
; decl
; decl
= next
)
1814 next
= TREE_CHAIN (decl
);
1815 TREE_CHAIN (decl
) = prev
;
1821 /* Return a newly created TREE_LIST node whose
1822 purpose and value fields are PARM and VALUE. */
1825 build_tree_list_stat (tree parm
, tree value MEM_STAT_DECL
)
1827 tree t
= make_node_stat (TREE_LIST PASS_MEM_STAT
);
1828 TREE_PURPOSE (t
) = parm
;
1829 TREE_VALUE (t
) = value
;
1833 /* Return a newly created TREE_LIST node whose
1834 purpose and value fields are PURPOSE and VALUE
1835 and whose TREE_CHAIN is CHAIN. */
1838 tree_cons_stat (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
1842 node
= (tree
) ggc_alloc_zone_pass_stat (sizeof (struct tree_list
), &tree_zone
);
1844 memset (node
, 0, sizeof (struct tree_common
));
1846 #ifdef GATHER_STATISTICS
1847 tree_node_counts
[(int) x_kind
]++;
1848 tree_node_sizes
[(int) x_kind
] += sizeof (struct tree_list
);
1851 TREE_SET_CODE (node
, TREE_LIST
);
1852 TREE_CHAIN (node
) = chain
;
1853 TREE_PURPOSE (node
) = purpose
;
1854 TREE_VALUE (node
) = value
;
1858 /* Return the elements of a CONSTRUCTOR as a TREE_LIST. */
1861 ctor_to_list (tree ctor
)
1863 tree list
= NULL_TREE
;
1868 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), ix
, purpose
, val
)
1870 *p
= build_tree_list (purpose
, val
);
1871 p
= &TREE_CHAIN (*p
);
1877 /* Return the size nominally occupied by an object of type TYPE
1878 when it resides in memory. The value is measured in units of bytes,
1879 and its data type is that normally used for type sizes
1880 (which is the first type created by make_signed_type or
1881 make_unsigned_type). */
1884 size_in_bytes (const_tree type
)
1888 if (type
== error_mark_node
)
1889 return integer_zero_node
;
1891 type
= TYPE_MAIN_VARIANT (type
);
1892 t
= TYPE_SIZE_UNIT (type
);
1896 lang_hooks
.types
.incomplete_type_error (NULL_TREE
, type
);
1897 return size_zero_node
;
1903 /* Return the size of TYPE (in bytes) as a wide integer
1904 or return -1 if the size can vary or is larger than an integer. */
1907 int_size_in_bytes (const_tree type
)
1911 if (type
== error_mark_node
)
1914 type
= TYPE_MAIN_VARIANT (type
);
1915 t
= TYPE_SIZE_UNIT (type
);
1917 || TREE_CODE (t
) != INTEGER_CST
1918 || TREE_INT_CST_HIGH (t
) != 0
1919 /* If the result would appear negative, it's too big to represent. */
1920 || (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0)
1923 return TREE_INT_CST_LOW (t
);
1926 /* Return the maximum size of TYPE (in bytes) as a wide integer
1927 or return -1 if the size can vary or is larger than an integer. */
1930 max_int_size_in_bytes (const_tree type
)
1932 HOST_WIDE_INT size
= -1;
1935 /* If this is an array type, check for a possible MAX_SIZE attached. */
1937 if (TREE_CODE (type
) == ARRAY_TYPE
)
1939 size_tree
= TYPE_ARRAY_MAX_SIZE (type
);
1941 if (size_tree
&& host_integerp (size_tree
, 1))
1942 size
= tree_low_cst (size_tree
, 1);
1945 /* If we still haven't been able to get a size, see if the language
1946 can compute a maximum size. */
1950 size_tree
= lang_hooks
.types
.max_size (type
);
1952 if (size_tree
&& host_integerp (size_tree
, 1))
1953 size
= tree_low_cst (size_tree
, 1);
1959 /* Return the bit position of FIELD, in bits from the start of the record.
1960 This is a tree of type bitsizetype. */
1963 bit_position (const_tree field
)
1965 return bit_from_pos (DECL_FIELD_OFFSET (field
),
1966 DECL_FIELD_BIT_OFFSET (field
));
1969 /* Likewise, but return as an integer. It must be representable in
1970 that way (since it could be a signed value, we don't have the
1971 option of returning -1 like int_size_in_byte can. */
1974 int_bit_position (const_tree field
)
1976 return tree_low_cst (bit_position (field
), 0);
1979 /* Return the byte position of FIELD, in bytes from the start of the record.
1980 This is a tree of type sizetype. */
1983 byte_position (const_tree field
)
1985 return byte_from_pos (DECL_FIELD_OFFSET (field
),
1986 DECL_FIELD_BIT_OFFSET (field
));
1989 /* Likewise, but return as an integer. It must be representable in
1990 that way (since it could be a signed value, we don't have the
1991 option of returning -1 like int_size_in_byte can. */
1994 int_byte_position (const_tree field
)
1996 return tree_low_cst (byte_position (field
), 0);
1999 /* Return the strictest alignment, in bits, that T is known to have. */
2002 expr_align (const_tree t
)
2004 unsigned int align0
, align1
;
2006 switch (TREE_CODE (t
))
2008 CASE_CONVERT
: case NON_LVALUE_EXPR
:
2009 /* If we have conversions, we know that the alignment of the
2010 object must meet each of the alignments of the types. */
2011 align0
= expr_align (TREE_OPERAND (t
, 0));
2012 align1
= TYPE_ALIGN (TREE_TYPE (t
));
2013 return MAX (align0
, align1
);
2015 case SAVE_EXPR
: case COMPOUND_EXPR
: case MODIFY_EXPR
:
2016 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
2017 case CLEANUP_POINT_EXPR
:
2018 /* These don't change the alignment of an object. */
2019 return expr_align (TREE_OPERAND (t
, 0));
2022 /* The best we can do is say that the alignment is the least aligned
2024 align0
= expr_align (TREE_OPERAND (t
, 1));
2025 align1
= expr_align (TREE_OPERAND (t
, 2));
2026 return MIN (align0
, align1
);
2028 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2029 meaningfully, it's always 1. */
2030 case LABEL_DECL
: case CONST_DECL
:
2031 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
2033 gcc_assert (DECL_ALIGN (t
) != 0);
2034 return DECL_ALIGN (t
);
2040 /* Otherwise take the alignment from that of the type. */
2041 return TYPE_ALIGN (TREE_TYPE (t
));
2044 /* Return, as a tree node, the number of elements for TYPE (which is an
2045 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2048 array_type_nelts (const_tree type
)
2050 tree index_type
, min
, max
;
2052 /* If they did it with unspecified bounds, then we should have already
2053 given an error about it before we got here. */
2054 if (! TYPE_DOMAIN (type
))
2055 return error_mark_node
;
2057 index_type
= TYPE_DOMAIN (type
);
2058 min
= TYPE_MIN_VALUE (index_type
);
2059 max
= TYPE_MAX_VALUE (index_type
);
2061 return (integer_zerop (min
)
2063 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
2066 /* If arg is static -- a reference to an object in static storage -- then
2067 return the object. This is not the same as the C meaning of `static'.
2068 If arg isn't static, return NULL. */
2073 switch (TREE_CODE (arg
))
2076 /* Nested functions are static, even though taking their address will
2077 involve a trampoline as we unnest the nested function and create
2078 the trampoline on the tree level. */
2082 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2083 && ! DECL_THREAD_LOCAL_P (arg
)
2084 && ! DECL_DLLIMPORT_P (arg
)
2088 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2092 return TREE_STATIC (arg
) ? arg
: NULL
;
2099 /* If the thing being referenced is not a field, then it is
2100 something language specific. */
2101 if (TREE_CODE (TREE_OPERAND (arg
, 1)) != FIELD_DECL
)
2102 return (*lang_hooks
.staticp
) (arg
);
2104 /* If we are referencing a bitfield, we can't evaluate an
2105 ADDR_EXPR at compile time and so it isn't a constant. */
2106 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
2109 return staticp (TREE_OPERAND (arg
, 0));
2114 case MISALIGNED_INDIRECT_REF
:
2115 case ALIGN_INDIRECT_REF
:
2117 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
2120 case ARRAY_RANGE_REF
:
2121 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
2122 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
2123 return staticp (TREE_OPERAND (arg
, 0));
2128 if ((unsigned int) TREE_CODE (arg
)
2129 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
2130 return lang_hooks
.staticp (arg
);
2139 /* Return whether OP is a DECL whose address is function-invariant. */
2142 decl_address_invariant_p (const_tree op
)
2144 /* The conditions below are slightly less strict than the one in
2147 switch (TREE_CODE (op
))
2156 if (((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2157 && !DECL_DLLIMPORT_P (op
))
2158 || DECL_THREAD_LOCAL_P (op
)
2159 || DECL_CONTEXT (op
) == current_function_decl
2160 || decl_function_context (op
) == current_function_decl
)
2165 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2166 || decl_function_context (op
) == current_function_decl
)
2177 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
2180 decl_address_ip_invariant_p (const_tree op
)
2182 /* The conditions below are slightly less strict than the one in
2185 switch (TREE_CODE (op
))
2193 if (((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2194 && !DECL_DLLIMPORT_P (op
))
2195 || DECL_THREAD_LOCAL_P (op
))
2200 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
)))
2212 /* Return true if T is function-invariant (internal function, does
2213 not handle arithmetic; that's handled in skip_simple_arithmetic and
2214 tree_invariant_p). */
2216 static bool tree_invariant_p (tree t
);
2219 tree_invariant_p_1 (tree t
)
2223 if (TREE_CONSTANT (t
)
2224 || (TREE_READONLY (t
) && !TREE_SIDE_EFFECTS (t
)))
2227 switch (TREE_CODE (t
))
2233 op
= TREE_OPERAND (t
, 0);
2234 while (handled_component_p (op
))
2236 switch (TREE_CODE (op
))
2239 case ARRAY_RANGE_REF
:
2240 if (!tree_invariant_p (TREE_OPERAND (op
, 1))
2241 || TREE_OPERAND (op
, 2) != NULL_TREE
2242 || TREE_OPERAND (op
, 3) != NULL_TREE
)
2247 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
2253 op
= TREE_OPERAND (op
, 0);
2256 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
2265 /* Return true if T is function-invariant. */
2268 tree_invariant_p (tree t
)
2270 tree inner
= skip_simple_arithmetic (t
);
2271 return tree_invariant_p_1 (inner
);
2274 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2275 Do this to any expression which may be used in more than one place,
2276 but must be evaluated only once.
2278 Normally, expand_expr would reevaluate the expression each time.
2279 Calling save_expr produces something that is evaluated and recorded
2280 the first time expand_expr is called on it. Subsequent calls to
2281 expand_expr just reuse the recorded value.
2283 The call to expand_expr that generates code that actually computes
2284 the value is the first call *at compile time*. Subsequent calls
2285 *at compile time* generate code to use the saved value.
2286 This produces correct result provided that *at run time* control
2287 always flows through the insns made by the first expand_expr
2288 before reaching the other places where the save_expr was evaluated.
2289 You, the caller of save_expr, must make sure this is so.
2291 Constants, and certain read-only nodes, are returned with no
2292 SAVE_EXPR because that is safe. Expressions containing placeholders
2293 are not touched; see tree.def for an explanation of what these
2297 save_expr (tree expr
)
2299 tree t
= fold (expr
);
2302 /* If the tree evaluates to a constant, then we don't want to hide that
2303 fact (i.e. this allows further folding, and direct checks for constants).
2304 However, a read-only object that has side effects cannot be bypassed.
2305 Since it is no problem to reevaluate literals, we just return the
2307 inner
= skip_simple_arithmetic (t
);
2308 if (TREE_CODE (inner
) == ERROR_MARK
)
2311 if (tree_invariant_p_1 (inner
))
2314 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2315 it means that the size or offset of some field of an object depends on
2316 the value within another field.
2318 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2319 and some variable since it would then need to be both evaluated once and
2320 evaluated more than once. Front-ends must assure this case cannot
2321 happen by surrounding any such subexpressions in their own SAVE_EXPR
2322 and forcing evaluation at the proper time. */
2323 if (contains_placeholder_p (inner
))
2326 t
= build1 (SAVE_EXPR
, TREE_TYPE (expr
), t
);
2328 /* This expression might be placed ahead of a jump to ensure that the
2329 value was computed on both sides of the jump. So make sure it isn't
2330 eliminated as dead. */
2331 TREE_SIDE_EFFECTS (t
) = 1;
2335 /* Look inside EXPR and into any simple arithmetic operations. Return
2336 the innermost non-arithmetic node. */
2339 skip_simple_arithmetic (tree expr
)
2343 /* We don't care about whether this can be used as an lvalue in this
2345 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
2346 expr
= TREE_OPERAND (expr
, 0);
2348 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2349 a constant, it will be more efficient to not make another SAVE_EXPR since
2350 it will allow better simplification and GCSE will be able to merge the
2351 computations if they actually occur. */
2355 if (UNARY_CLASS_P (inner
))
2356 inner
= TREE_OPERAND (inner
, 0);
2357 else if (BINARY_CLASS_P (inner
))
2359 if (tree_invariant_p (TREE_OPERAND (inner
, 1)))
2360 inner
= TREE_OPERAND (inner
, 0);
2361 else if (tree_invariant_p (TREE_OPERAND (inner
, 0)))
2362 inner
= TREE_OPERAND (inner
, 1);
2373 /* Return which tree structure is used by T. */
2375 enum tree_node_structure_enum
2376 tree_node_structure (const_tree t
)
2378 const enum tree_code code
= TREE_CODE (t
);
2380 switch (TREE_CODE_CLASS (code
))
2382 case tcc_declaration
:
2387 return TS_FIELD_DECL
;
2389 return TS_PARM_DECL
;
2393 return TS_LABEL_DECL
;
2395 return TS_RESULT_DECL
;
2397 return TS_CONST_DECL
;
2399 return TS_TYPE_DECL
;
2401 return TS_FUNCTION_DECL
;
2402 case SYMBOL_MEMORY_TAG
:
2403 case NAME_MEMORY_TAG
:
2404 case MEMORY_PARTITION_TAG
:
2405 return TS_MEMORY_TAG
;
2407 return TS_DECL_NON_COMMON
;
2413 case tcc_comparison
:
2416 case tcc_expression
:
2420 default: /* tcc_constant and tcc_exceptional */
2425 /* tcc_constant cases. */
2426 case INTEGER_CST
: return TS_INT_CST
;
2427 case REAL_CST
: return TS_REAL_CST
;
2428 case FIXED_CST
: return TS_FIXED_CST
;
2429 case COMPLEX_CST
: return TS_COMPLEX
;
2430 case VECTOR_CST
: return TS_VECTOR
;
2431 case STRING_CST
: return TS_STRING
;
2432 /* tcc_exceptional cases. */
2433 case ERROR_MARK
: return TS_COMMON
;
2434 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
2435 case TREE_LIST
: return TS_LIST
;
2436 case TREE_VEC
: return TS_VEC
;
2437 case SSA_NAME
: return TS_SSA_NAME
;
2438 case PLACEHOLDER_EXPR
: return TS_COMMON
;
2439 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
2440 case BLOCK
: return TS_BLOCK
;
2441 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
2442 case TREE_BINFO
: return TS_BINFO
;
2443 case OMP_CLAUSE
: return TS_OMP_CLAUSE
;
2444 case OPTIMIZATION_NODE
: return TS_OPTIMIZATION
;
2445 case TARGET_OPTION_NODE
: return TS_TARGET_OPTION
;
2452 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2453 or offset that depends on a field within a record. */
2456 contains_placeholder_p (const_tree exp
)
2458 enum tree_code code
;
2463 code
= TREE_CODE (exp
);
2464 if (code
== PLACEHOLDER_EXPR
)
2467 switch (TREE_CODE_CLASS (code
))
2470 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2471 position computations since they will be converted into a
2472 WITH_RECORD_EXPR involving the reference, which will assume
2473 here will be valid. */
2474 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2476 case tcc_exceptional
:
2477 if (code
== TREE_LIST
)
2478 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
2479 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
2484 case tcc_comparison
:
2485 case tcc_expression
:
2489 /* Ignoring the first operand isn't quite right, but works best. */
2490 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
2493 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2494 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
2495 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
2498 /* The save_expr function never wraps anything containing
2499 a PLACEHOLDER_EXPR. */
2506 switch (TREE_CODE_LENGTH (code
))
2509 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2511 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2512 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
2523 const_call_expr_arg_iterator iter
;
2524 FOR_EACH_CONST_CALL_EXPR_ARG (arg
, iter
, exp
)
2525 if (CONTAINS_PLACEHOLDER_P (arg
))
2539 /* Return true if any part of the computation of TYPE involves a
2540 PLACEHOLDER_EXPR. This includes size, bounds, qualifiers
2541 (for QUAL_UNION_TYPE) and field positions. */
2544 type_contains_placeholder_1 (const_tree type
)
2546 /* If the size contains a placeholder or the parent type (component type in
2547 the case of arrays) type involves a placeholder, this type does. */
2548 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
2549 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
2550 || (TREE_TYPE (type
) != 0
2551 && type_contains_placeholder_p (TREE_TYPE (type
))))
2554 /* Now do type-specific checks. Note that the last part of the check above
2555 greatly limits what we have to do below. */
2556 switch (TREE_CODE (type
))
2564 case REFERENCE_TYPE
:
2572 case FIXED_POINT_TYPE
:
2573 /* Here we just check the bounds. */
2574 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
2575 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
2578 /* We're already checked the component type (TREE_TYPE), so just check
2580 return type_contains_placeholder_p (TYPE_DOMAIN (type
));
2584 case QUAL_UNION_TYPE
:
2588 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2589 if (TREE_CODE (field
) == FIELD_DECL
2590 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
2591 || (TREE_CODE (type
) == QUAL_UNION_TYPE
2592 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
2593 || type_contains_placeholder_p (TREE_TYPE (field
))))
2605 type_contains_placeholder_p (tree type
)
2609 /* If the contains_placeholder_bits field has been initialized,
2610 then we know the answer. */
2611 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
2612 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
2614 /* Indicate that we've seen this type node, and the answer is false.
2615 This is what we want to return if we run into recursion via fields. */
2616 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
2618 /* Compute the real value. */
2619 result
= type_contains_placeholder_1 (type
);
2621 /* Store the real value. */
2622 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
2627 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2628 return a tree with all occurrences of references to F in a
2629 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2630 contains only arithmetic expressions or a CALL_EXPR with a
2631 PLACEHOLDER_EXPR occurring only in its arglist. */
2634 substitute_in_expr (tree exp
, tree f
, tree r
)
2636 enum tree_code code
= TREE_CODE (exp
);
2637 tree op0
, op1
, op2
, op3
;
2638 tree new_tree
, inner
;
2640 /* We handle TREE_LIST and COMPONENT_REF separately. */
2641 if (code
== TREE_LIST
)
2643 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
2644 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
2645 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
2648 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
2650 else if (code
== COMPONENT_REF
)
2652 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2653 and it is the right field, replace it with R. */
2654 for (inner
= TREE_OPERAND (exp
, 0);
2655 REFERENCE_CLASS_P (inner
);
2656 inner
= TREE_OPERAND (inner
, 0))
2658 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
2659 && TREE_OPERAND (exp
, 1) == f
)
2662 /* If this expression hasn't been completed let, leave it alone. */
2663 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& TREE_TYPE (inner
) == 0)
2666 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2667 if (op0
== TREE_OPERAND (exp
, 0))
2670 new_tree
= fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
),
2671 op0
, TREE_OPERAND (exp
, 1), NULL_TREE
);
2674 switch (TREE_CODE_CLASS (code
))
2677 case tcc_declaration
:
2680 case tcc_exceptional
:
2683 case tcc_comparison
:
2684 case tcc_expression
:
2686 switch (TREE_CODE_LENGTH (code
))
2692 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2693 if (op0
== TREE_OPERAND (exp
, 0))
2696 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
2700 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2701 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2703 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
2706 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
2710 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2711 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2712 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
2714 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2715 && op2
== TREE_OPERAND (exp
, 2))
2718 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
2722 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2723 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2724 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
2725 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
2727 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2728 && op2
== TREE_OPERAND (exp
, 2)
2729 && op3
== TREE_OPERAND (exp
, 3))
2732 new_tree
= fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
2742 tree copy
= NULL_TREE
;
2745 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
2747 tree op
= TREE_OPERAND (exp
, i
);
2748 tree new_op
= SUBSTITUTE_IN_EXPR (op
, f
, r
);
2752 copy
= copy_node (exp
);
2753 TREE_OPERAND (copy
, i
) = new_op
;
2758 new_tree
= fold (copy
);
2768 TREE_READONLY (new_tree
) = TREE_READONLY (exp
);
2772 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
2773 for it within OBJ, a tree that is an object or a chain of references. */
2776 substitute_placeholder_in_expr (tree exp
, tree obj
)
2778 enum tree_code code
= TREE_CODE (exp
);
2779 tree op0
, op1
, op2
, op3
;
2781 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
2782 in the chain of OBJ. */
2783 if (code
== PLACEHOLDER_EXPR
)
2785 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
2788 for (elt
= obj
; elt
!= 0;
2789 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
2790 || TREE_CODE (elt
) == COND_EXPR
)
2791 ? TREE_OPERAND (elt
, 1)
2792 : (REFERENCE_CLASS_P (elt
)
2793 || UNARY_CLASS_P (elt
)
2794 || BINARY_CLASS_P (elt
)
2795 || VL_EXP_CLASS_P (elt
)
2796 || EXPRESSION_CLASS_P (elt
))
2797 ? TREE_OPERAND (elt
, 0) : 0))
2798 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
2801 for (elt
= obj
; elt
!= 0;
2802 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
2803 || TREE_CODE (elt
) == COND_EXPR
)
2804 ? TREE_OPERAND (elt
, 1)
2805 : (REFERENCE_CLASS_P (elt
)
2806 || UNARY_CLASS_P (elt
)
2807 || BINARY_CLASS_P (elt
)
2808 || VL_EXP_CLASS_P (elt
)
2809 || EXPRESSION_CLASS_P (elt
))
2810 ? TREE_OPERAND (elt
, 0) : 0))
2811 if (POINTER_TYPE_P (TREE_TYPE (elt
))
2812 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
2814 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
2816 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2817 survives until RTL generation, there will be an error. */
2821 /* TREE_LIST is special because we need to look at TREE_VALUE
2822 and TREE_CHAIN, not TREE_OPERANDS. */
2823 else if (code
== TREE_LIST
)
2825 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
2826 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
2827 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
2830 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
2833 switch (TREE_CODE_CLASS (code
))
2836 case tcc_declaration
:
2839 case tcc_exceptional
:
2842 case tcc_comparison
:
2843 case tcc_expression
:
2846 switch (TREE_CODE_LENGTH (code
))
2852 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2853 if (op0
== TREE_OPERAND (exp
, 0))
2856 return fold_build1 (code
, TREE_TYPE (exp
), op0
);
2859 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2860 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2862 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
2865 return fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
2868 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2869 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2870 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
2872 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2873 && op2
== TREE_OPERAND (exp
, 2))
2876 return fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
2879 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2880 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2881 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
2882 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
2884 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2885 && op2
== TREE_OPERAND (exp
, 2)
2886 && op3
== TREE_OPERAND (exp
, 3))
2889 return fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
2898 tree copy
= NULL_TREE
;
2901 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
2903 tree op
= TREE_OPERAND (exp
, i
);
2904 tree new_op
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (op
, obj
);
2908 copy
= copy_node (exp
);
2909 TREE_OPERAND (copy
, i
) = new_op
;
2924 /* Stabilize a reference so that we can use it any number of times
2925 without causing its operands to be evaluated more than once.
2926 Returns the stabilized reference. This works by means of save_expr,
2927 so see the caveats in the comments about save_expr.
2929 Also allows conversion expressions whose operands are references.
2930 Any other kind of expression is returned unchanged. */
2933 stabilize_reference (tree ref
)
2936 enum tree_code code
= TREE_CODE (ref
);
2943 /* No action is needed in this case. */
2948 case FIX_TRUNC_EXPR
:
2949 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
2953 result
= build_nt (INDIRECT_REF
,
2954 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
2958 result
= build_nt (COMPONENT_REF
,
2959 stabilize_reference (TREE_OPERAND (ref
, 0)),
2960 TREE_OPERAND (ref
, 1), NULL_TREE
);
2964 result
= build_nt (BIT_FIELD_REF
,
2965 stabilize_reference (TREE_OPERAND (ref
, 0)),
2966 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2967 stabilize_reference_1 (TREE_OPERAND (ref
, 2)));
2971 result
= build_nt (ARRAY_REF
,
2972 stabilize_reference (TREE_OPERAND (ref
, 0)),
2973 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2974 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
2977 case ARRAY_RANGE_REF
:
2978 result
= build_nt (ARRAY_RANGE_REF
,
2979 stabilize_reference (TREE_OPERAND (ref
, 0)),
2980 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2981 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
2985 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2986 it wouldn't be ignored. This matters when dealing with
2988 return stabilize_reference_1 (ref
);
2990 /* If arg isn't a kind of lvalue we recognize, make no change.
2991 Caller should recognize the error for an invalid lvalue. */
2996 return error_mark_node
;
2999 TREE_TYPE (result
) = TREE_TYPE (ref
);
3000 TREE_READONLY (result
) = TREE_READONLY (ref
);
3001 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
3002 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
3007 /* Subroutine of stabilize_reference; this is called for subtrees of
3008 references. Any expression with side-effects must be put in a SAVE_EXPR
3009 to ensure that it is only evaluated once.
3011 We don't put SAVE_EXPR nodes around everything, because assigning very
3012 simple expressions to temporaries causes us to miss good opportunities
3013 for optimizations. Among other things, the opportunity to fold in the
3014 addition of a constant into an addressing mode often gets lost, e.g.
3015 "y[i+1] += x;". In general, we take the approach that we should not make
3016 an assignment unless we are forced into it - i.e., that any non-side effect
3017 operator should be allowed, and that cse should take care of coalescing
3018 multiple utterances of the same expression should that prove fruitful. */
3021 stabilize_reference_1 (tree e
)
3024 enum tree_code code
= TREE_CODE (e
);
3026 /* We cannot ignore const expressions because it might be a reference
3027 to a const array but whose index contains side-effects. But we can
3028 ignore things that are actual constant or that already have been
3029 handled by this function. */
3031 if (tree_invariant_p (e
))
3034 switch (TREE_CODE_CLASS (code
))
3036 case tcc_exceptional
:
3038 case tcc_declaration
:
3039 case tcc_comparison
:
3041 case tcc_expression
:
3044 /* If the expression has side-effects, then encase it in a SAVE_EXPR
3045 so that it will only be evaluated once. */
3046 /* The reference (r) and comparison (<) classes could be handled as
3047 below, but it is generally faster to only evaluate them once. */
3048 if (TREE_SIDE_EFFECTS (e
))
3049 return save_expr (e
);
3053 /* Constants need no processing. In fact, we should never reach
3058 /* Division is slow and tends to be compiled with jumps,
3059 especially the division by powers of 2 that is often
3060 found inside of an array reference. So do it just once. */
3061 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
3062 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
3063 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
3064 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
3065 return save_expr (e
);
3066 /* Recursively stabilize each operand. */
3067 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
3068 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
3072 /* Recursively stabilize each operand. */
3073 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
3080 TREE_TYPE (result
) = TREE_TYPE (e
);
3081 TREE_READONLY (result
) = TREE_READONLY (e
);
3082 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
3083 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
3088 /* Low-level constructors for expressions. */
3090 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
3091 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
3094 recompute_tree_invariant_for_addr_expr (tree t
)
3097 bool tc
= true, se
= false;
3099 /* We started out assuming this address is both invariant and constant, but
3100 does not have side effects. Now go down any handled components and see if
3101 any of them involve offsets that are either non-constant or non-invariant.
3102 Also check for side-effects.
3104 ??? Note that this code makes no attempt to deal with the case where
3105 taking the address of something causes a copy due to misalignment. */
3107 #define UPDATE_FLAGS(NODE) \
3108 do { tree _node = (NODE); \
3109 if (_node && !TREE_CONSTANT (_node)) tc = false; \
3110 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
3112 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
3113 node
= TREE_OPERAND (node
, 0))
3115 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
3116 array reference (probably made temporarily by the G++ front end),
3117 so ignore all the operands. */
3118 if ((TREE_CODE (node
) == ARRAY_REF
3119 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
3120 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
3122 UPDATE_FLAGS (TREE_OPERAND (node
, 1));
3123 if (TREE_OPERAND (node
, 2))
3124 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3125 if (TREE_OPERAND (node
, 3))
3126 UPDATE_FLAGS (TREE_OPERAND (node
, 3));
3128 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
3129 FIELD_DECL, apparently. The G++ front end can put something else
3130 there, at least temporarily. */
3131 else if (TREE_CODE (node
) == COMPONENT_REF
3132 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
3134 if (TREE_OPERAND (node
, 2))
3135 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3137 else if (TREE_CODE (node
) == BIT_FIELD_REF
)
3138 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3141 node
= lang_hooks
.expr_to_decl (node
, &tc
, &se
);
3143 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
3144 the address, since &(*a)->b is a form of addition. If it's a constant, the
3145 address is constant too. If it's a decl, its address is constant if the
3146 decl is static. Everything else is not constant and, furthermore,
3147 taking the address of a volatile variable is not volatile. */
3148 if (TREE_CODE (node
) == INDIRECT_REF
)
3149 UPDATE_FLAGS (TREE_OPERAND (node
, 0));
3150 else if (CONSTANT_CLASS_P (node
))
3152 else if (DECL_P (node
))
3153 tc
&= (staticp (node
) != NULL_TREE
);
3157 se
|= TREE_SIDE_EFFECTS (node
);
3161 TREE_CONSTANT (t
) = tc
;
3162 TREE_SIDE_EFFECTS (t
) = se
;
3166 /* Build an expression of code CODE, data type TYPE, and operands as
3167 specified. Expressions and reference nodes can be created this way.
3168 Constants, decls, types and misc nodes cannot be.
3170 We define 5 non-variadic functions, from 0 to 4 arguments. This is
3171 enough for all extant tree codes. */
3174 build0_stat (enum tree_code code
, tree tt MEM_STAT_DECL
)
3178 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
3180 t
= make_node_stat (code PASS_MEM_STAT
);
3187 build1_stat (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
3189 int length
= sizeof (struct tree_exp
);
3190 #ifdef GATHER_STATISTICS
3191 tree_node_kind kind
;
3195 #ifdef GATHER_STATISTICS
3196 switch (TREE_CODE_CLASS (code
))
3198 case tcc_statement
: /* an expression with side effects */
3201 case tcc_reference
: /* a reference */
3209 tree_node_counts
[(int) kind
]++;
3210 tree_node_sizes
[(int) kind
] += length
;
3213 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
3215 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
3217 memset (t
, 0, sizeof (struct tree_common
));
3219 TREE_SET_CODE (t
, code
);
3221 TREE_TYPE (t
) = type
;
3222 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
3223 TREE_OPERAND (t
, 0) = node
;
3224 TREE_BLOCK (t
) = NULL_TREE
;
3225 if (node
&& !TYPE_P (node
))
3227 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
3228 TREE_READONLY (t
) = TREE_READONLY (node
);
3231 if (TREE_CODE_CLASS (code
) == tcc_statement
)
3232 TREE_SIDE_EFFECTS (t
) = 1;
3236 /* All of these have side-effects, no matter what their
3238 TREE_SIDE_EFFECTS (t
) = 1;
3239 TREE_READONLY (t
) = 0;
3242 case MISALIGNED_INDIRECT_REF
:
3243 case ALIGN_INDIRECT_REF
:
3245 /* Whether a dereference is readonly has nothing to do with whether
3246 its operand is readonly. */
3247 TREE_READONLY (t
) = 0;
3252 recompute_tree_invariant_for_addr_expr (t
);
3256 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
3257 && node
&& !TYPE_P (node
)
3258 && TREE_CONSTANT (node
))
3259 TREE_CONSTANT (t
) = 1;
3260 if (TREE_CODE_CLASS (code
) == tcc_reference
3261 && node
&& TREE_THIS_VOLATILE (node
))
3262 TREE_THIS_VOLATILE (t
) = 1;
3269 #define PROCESS_ARG(N) \
3271 TREE_OPERAND (t, N) = arg##N; \
3272 if (arg##N &&!TYPE_P (arg##N)) \
3274 if (TREE_SIDE_EFFECTS (arg##N)) \
3276 if (!TREE_READONLY (arg##N)) \
3278 if (!TREE_CONSTANT (arg##N)) \
3284 build2_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
3286 bool constant
, read_only
, side_effects
;
3289 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
3291 if ((code
== MINUS_EXPR
|| code
== PLUS_EXPR
|| code
== MULT_EXPR
)
3292 && arg0
&& arg1
&& tt
&& POINTER_TYPE_P (tt
)
3293 /* When sizetype precision doesn't match that of pointers
3294 we need to be able to build explicit extensions or truncations
3295 of the offset argument. */
3296 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (tt
))
3297 gcc_assert (TREE_CODE (arg0
) == INTEGER_CST
3298 && TREE_CODE (arg1
) == INTEGER_CST
);
3300 if (code
== POINTER_PLUS_EXPR
&& arg0
&& arg1
&& tt
)
3301 gcc_assert (POINTER_TYPE_P (tt
) && POINTER_TYPE_P (TREE_TYPE (arg0
))
3302 && INTEGRAL_TYPE_P (TREE_TYPE (arg1
))
3303 && useless_type_conversion_p (sizetype
, TREE_TYPE (arg1
)));
3305 t
= make_node_stat (code PASS_MEM_STAT
);
3308 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
3309 result based on those same flags for the arguments. But if the
3310 arguments aren't really even `tree' expressions, we shouldn't be trying
3313 /* Expressions without side effects may be constant if their
3314 arguments are as well. */
3315 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
3316 || TREE_CODE_CLASS (code
) == tcc_binary
);
3318 side_effects
= TREE_SIDE_EFFECTS (t
);
3323 TREE_READONLY (t
) = read_only
;
3324 TREE_CONSTANT (t
) = constant
;
3325 TREE_SIDE_EFFECTS (t
) = side_effects
;
3326 TREE_THIS_VOLATILE (t
)
3327 = (TREE_CODE_CLASS (code
) == tcc_reference
3328 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3335 build3_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3336 tree arg2 MEM_STAT_DECL
)
3338 bool constant
, read_only
, side_effects
;
3341 gcc_assert (TREE_CODE_LENGTH (code
) == 3);
3342 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
3344 t
= make_node_stat (code PASS_MEM_STAT
);
3347 /* As a special exception, if COND_EXPR has NULL branches, we
3348 assume that it is a gimple statement and always consider
3349 it to have side effects. */
3350 if (code
== COND_EXPR
3351 && tt
== void_type_node
3352 && arg1
== NULL_TREE
3353 && arg2
== NULL_TREE
)
3354 side_effects
= true;
3356 side_effects
= TREE_SIDE_EFFECTS (t
);
3362 TREE_SIDE_EFFECTS (t
) = side_effects
;
3363 TREE_THIS_VOLATILE (t
)
3364 = (TREE_CODE_CLASS (code
) == tcc_reference
3365 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3371 build4_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3372 tree arg2
, tree arg3 MEM_STAT_DECL
)
3374 bool constant
, read_only
, side_effects
;
3377 gcc_assert (TREE_CODE_LENGTH (code
) == 4);
3379 t
= make_node_stat (code PASS_MEM_STAT
);
3382 side_effects
= TREE_SIDE_EFFECTS (t
);
3389 TREE_SIDE_EFFECTS (t
) = side_effects
;
3390 TREE_THIS_VOLATILE (t
)
3391 = (TREE_CODE_CLASS (code
) == tcc_reference
3392 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3398 build5_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3399 tree arg2
, tree arg3
, tree arg4 MEM_STAT_DECL
)
3401 bool constant
, read_only
, side_effects
;
3404 gcc_assert (TREE_CODE_LENGTH (code
) == 5);
3406 t
= make_node_stat (code PASS_MEM_STAT
);
3409 side_effects
= TREE_SIDE_EFFECTS (t
);
3417 TREE_SIDE_EFFECTS (t
) = side_effects
;
3418 TREE_THIS_VOLATILE (t
)
3419 = (TREE_CODE_CLASS (code
) == tcc_reference
3420 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3426 build7_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
3427 tree arg2
, tree arg3
, tree arg4
, tree arg5
,
3428 tree arg6 MEM_STAT_DECL
)
3430 bool constant
, read_only
, side_effects
;
3433 gcc_assert (code
== TARGET_MEM_REF
);
3435 t
= make_node_stat (code PASS_MEM_STAT
);
3438 side_effects
= TREE_SIDE_EFFECTS (t
);
3448 TREE_SIDE_EFFECTS (t
) = side_effects
;
3449 TREE_THIS_VOLATILE (t
) = 0;
3454 /* Similar except don't specify the TREE_TYPE
3455 and leave the TREE_SIDE_EFFECTS as 0.
3456 It is permissible for arguments to be null,
3457 or even garbage if their values do not matter. */
3460 build_nt (enum tree_code code
, ...)
3467 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
3471 t
= make_node (code
);
3472 length
= TREE_CODE_LENGTH (code
);
3474 for (i
= 0; i
< length
; i
++)
3475 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
3481 /* Similar to build_nt, but for creating a CALL_EXPR object with
3482 ARGLIST passed as a list. */
3485 build_nt_call_list (tree fn
, tree arglist
)
3490 t
= build_vl_exp (CALL_EXPR
, list_length (arglist
) + 3);
3491 CALL_EXPR_FN (t
) = fn
;
3492 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
3493 for (i
= 0; arglist
; arglist
= TREE_CHAIN (arglist
), i
++)
3494 CALL_EXPR_ARG (t
, i
) = TREE_VALUE (arglist
);
3498 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
3499 We do NOT enter this node in any sort of symbol table.
3501 layout_decl is used to set up the decl's storage layout.
3502 Other slots are initialized to 0 or null pointers. */
3505 build_decl_stat (enum tree_code code
, tree name
, tree type MEM_STAT_DECL
)
3509 t
= make_node_stat (code PASS_MEM_STAT
);
3511 /* if (type == error_mark_node)
3512 type = integer_type_node; */
3513 /* That is not done, deliberately, so that having error_mark_node
3514 as the type can suppress useless errors in the use of this variable. */
3516 DECL_NAME (t
) = name
;
3517 TREE_TYPE (t
) = type
;
3519 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
3525 /* Builds and returns function declaration with NAME and TYPE. */
3528 build_fn_decl (const char *name
, tree type
)
3530 tree id
= get_identifier (name
);
3531 tree decl
= build_decl (FUNCTION_DECL
, id
, type
);
3533 DECL_EXTERNAL (decl
) = 1;
3534 TREE_PUBLIC (decl
) = 1;
3535 DECL_ARTIFICIAL (decl
) = 1;
3536 TREE_NOTHROW (decl
) = 1;
3542 /* BLOCK nodes are used to represent the structure of binding contours
3543 and declarations, once those contours have been exited and their contents
3544 compiled. This information is used for outputting debugging info. */
3547 build_block (tree vars
, tree subblocks
, tree supercontext
, tree chain
)
3549 tree block
= make_node (BLOCK
);
3551 BLOCK_VARS (block
) = vars
;
3552 BLOCK_SUBBLOCKS (block
) = subblocks
;
3553 BLOCK_SUPERCONTEXT (block
) = supercontext
;
3554 BLOCK_CHAIN (block
) = chain
;
3559 expand_location (source_location loc
)
3561 expanded_location xloc
;
3571 const struct line_map
*map
= linemap_lookup (line_table
, loc
);
3572 xloc
.file
= map
->to_file
;
3573 xloc
.line
= SOURCE_LINE (map
, loc
);
3574 xloc
.column
= SOURCE_COLUMN (map
, loc
);
3575 xloc
.sysp
= map
->sysp
!= 0;
3581 /* Source location accessor functions. */
3585 set_expr_locus (tree node
, source_location
*loc
)
3588 EXPR_CHECK (node
)->exp
.locus
= UNKNOWN_LOCATION
;
3590 EXPR_CHECK (node
)->exp
.locus
= *loc
;
3593 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
3595 LOC is the location to use in tree T. */
3597 void protected_set_expr_location (tree t
, location_t loc
)
3599 if (t
&& CAN_HAVE_LOCATION_P (t
))
3600 SET_EXPR_LOCATION (t
, loc
);
3603 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
3607 build_decl_attribute_variant (tree ddecl
, tree attribute
)
3609 DECL_ATTRIBUTES (ddecl
) = attribute
;
3613 /* Borrowed from hashtab.c iterative_hash implementation. */
3614 #define mix(a,b,c) \
3616 a -= b; a -= c; a ^= (c>>13); \
3617 b -= c; b -= a; b ^= (a<< 8); \
3618 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
3619 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
3620 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
3621 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
3622 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
3623 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
3624 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
3628 /* Produce good hash value combining VAL and VAL2. */
3630 iterative_hash_hashval_t (hashval_t val
, hashval_t val2
)
3632 /* the golden ratio; an arbitrary value. */
3633 hashval_t a
= 0x9e3779b9;
3639 /* Produce good hash value combining PTR and VAL2. */
3640 static inline hashval_t
3641 iterative_hash_pointer (const void *ptr
, hashval_t val2
)
3643 if (sizeof (ptr
) == sizeof (hashval_t
))
3644 return iterative_hash_hashval_t ((size_t) ptr
, val2
);
3647 hashval_t a
= (hashval_t
) (size_t) ptr
;
3648 /* Avoid warnings about shifting of more than the width of the type on
3649 hosts that won't execute this path. */
3651 hashval_t b
= (hashval_t
) ((size_t) ptr
>> (sizeof (hashval_t
) * 8 + zero
));
3657 /* Produce good hash value combining VAL and VAL2. */
3658 static inline hashval_t
3659 iterative_hash_host_wide_int (HOST_WIDE_INT val
, hashval_t val2
)
3661 if (sizeof (HOST_WIDE_INT
) == sizeof (hashval_t
))
3662 return iterative_hash_hashval_t (val
, val2
);
3665 hashval_t a
= (hashval_t
) val
;
3666 /* Avoid warnings about shifting of more than the width of the type on
3667 hosts that won't execute this path. */
3669 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 8 + zero
));
3671 if (sizeof (HOST_WIDE_INT
) > 2 * sizeof (hashval_t
))
3673 hashval_t a
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 16 + zero
));
3674 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 24 + zero
));
3681 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3682 is ATTRIBUTE and its qualifiers are QUALS.
3684 Record such modified types already made so we don't make duplicates. */
3687 build_type_attribute_qual_variant (tree ttype
, tree attribute
, int quals
)
3689 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
3691 hashval_t hashcode
= 0;
3693 enum tree_code code
= TREE_CODE (ttype
);
3695 /* Building a distinct copy of a tagged type is inappropriate; it
3696 causes breakage in code that expects there to be a one-to-one
3697 relationship between a struct and its fields.
3698 build_duplicate_type is another solution (as used in
3699 handle_transparent_union_attribute), but that doesn't play well
3700 with the stronger C++ type identity model. */
3701 if (TREE_CODE (ttype
) == RECORD_TYPE
3702 || TREE_CODE (ttype
) == UNION_TYPE
3703 || TREE_CODE (ttype
) == QUAL_UNION_TYPE
3704 || TREE_CODE (ttype
) == ENUMERAL_TYPE
)
3706 warning (OPT_Wattributes
,
3707 "ignoring attributes applied to %qT after definition",
3708 TYPE_MAIN_VARIANT (ttype
));
3709 return build_qualified_type (ttype
, quals
);
3712 ttype
= build_qualified_type (ttype
, TYPE_UNQUALIFIED
);
3713 ntype
= build_distinct_type_copy (ttype
);
3715 TYPE_ATTRIBUTES (ntype
) = attribute
;
3717 hashcode
= iterative_hash_object (code
, hashcode
);
3718 if (TREE_TYPE (ntype
))
3719 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype
)),
3721 hashcode
= attribute_hash_list (attribute
, hashcode
);
3723 switch (TREE_CODE (ntype
))
3726 hashcode
= type_hash_list (TYPE_ARG_TYPES (ntype
), hashcode
);
3729 if (TYPE_DOMAIN (ntype
))
3730 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype
)),
3734 hashcode
= iterative_hash_object
3735 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype
)), hashcode
);
3736 hashcode
= iterative_hash_object
3737 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype
)), hashcode
);
3740 case FIXED_POINT_TYPE
:
3742 unsigned int precision
= TYPE_PRECISION (ntype
);
3743 hashcode
= iterative_hash_object (precision
, hashcode
);
3750 ntype
= type_hash_canon (hashcode
, ntype
);
3752 /* If the target-dependent attributes make NTYPE different from
3753 its canonical type, we will need to use structural equality
3754 checks for this type. */
3755 if (TYPE_STRUCTURAL_EQUALITY_P (ttype
)
3756 || !targetm
.comp_type_attributes (ntype
, ttype
))
3757 SET_TYPE_STRUCTURAL_EQUALITY (ntype
);
3758 else if (TYPE_CANONICAL (ntype
) == ntype
)
3759 TYPE_CANONICAL (ntype
) = TYPE_CANONICAL (ttype
);
3761 ttype
= build_qualified_type (ntype
, quals
);
3763 else if (TYPE_QUALS (ttype
) != quals
)
3764 ttype
= build_qualified_type (ttype
, quals
);
3770 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3773 Record such modified types already made so we don't make duplicates. */
3776 build_type_attribute_variant (tree ttype
, tree attribute
)
3778 return build_type_attribute_qual_variant (ttype
, attribute
,
3779 TYPE_QUALS (ttype
));
3782 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3785 We try both `text' and `__text__', ATTR may be either one. */
3786 /* ??? It might be a reasonable simplification to require ATTR to be only
3787 `text'. One might then also require attribute lists to be stored in
3788 their canonicalized form. */
3791 is_attribute_with_length_p (const char *attr
, int attr_len
, const_tree ident
)
3796 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
3799 p
= IDENTIFIER_POINTER (ident
);
3800 ident_len
= IDENTIFIER_LENGTH (ident
);
3802 if (ident_len
== attr_len
3803 && strcmp (attr
, p
) == 0)
3806 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
3809 gcc_assert (attr
[1] == '_');
3810 gcc_assert (attr
[attr_len
- 2] == '_');
3811 gcc_assert (attr
[attr_len
- 1] == '_');
3812 if (ident_len
== attr_len
- 4
3813 && strncmp (attr
+ 2, p
, attr_len
- 4) == 0)
3818 if (ident_len
== attr_len
+ 4
3819 && p
[0] == '_' && p
[1] == '_'
3820 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
3821 && strncmp (attr
, p
+ 2, attr_len
) == 0)
3828 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3831 We try both `text' and `__text__', ATTR may be either one. */
3834 is_attribute_p (const char *attr
, const_tree ident
)
3836 return is_attribute_with_length_p (attr
, strlen (attr
), ident
);
3839 /* Given an attribute name and a list of attributes, return a pointer to the
3840 attribute's list element if the attribute is part of the list, or NULL_TREE
3841 if not found. If the attribute appears more than once, this only
3842 returns the first occurrence; the TREE_CHAIN of the return value should
3843 be passed back in if further occurrences are wanted. */
3846 lookup_attribute (const char *attr_name
, tree list
)
3849 size_t attr_len
= strlen (attr_name
);
3851 for (l
= list
; l
; l
= TREE_CHAIN (l
))
3853 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
3854 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
3860 /* Remove any instances of attribute ATTR_NAME in LIST and return the
3864 remove_attribute (const char *attr_name
, tree list
)
3867 size_t attr_len
= strlen (attr_name
);
3869 for (p
= &list
; *p
; )
3872 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
3873 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
3874 *p
= TREE_CHAIN (l
);
3876 p
= &TREE_CHAIN (l
);
3882 /* Return an attribute list that is the union of a1 and a2. */
3885 merge_attributes (tree a1
, tree a2
)
3889 /* Either one unset? Take the set one. */
3891 if ((attributes
= a1
) == 0)
3894 /* One that completely contains the other? Take it. */
3896 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
3898 if (attribute_list_contained (a2
, a1
))
3902 /* Pick the longest list, and hang on the other list. */
3904 if (list_length (a1
) < list_length (a2
))
3905 attributes
= a2
, a2
= a1
;
3907 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
3910 for (a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
3913 a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
3916 if (TREE_VALUE (a
) != NULL
3917 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
3918 && TREE_VALUE (a2
) != NULL
3919 && TREE_CODE (TREE_VALUE (a2
)) == TREE_LIST
)
3921 if (simple_cst_list_equal (TREE_VALUE (a
),
3922 TREE_VALUE (a2
)) == 1)
3925 else if (simple_cst_equal (TREE_VALUE (a
),
3926 TREE_VALUE (a2
)) == 1)
3931 a1
= copy_node (a2
);
3932 TREE_CHAIN (a1
) = attributes
;
3941 /* Given types T1 and T2, merge their attributes and return
3945 merge_type_attributes (tree t1
, tree t2
)
3947 return merge_attributes (TYPE_ATTRIBUTES (t1
),
3948 TYPE_ATTRIBUTES (t2
));
3951 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
3955 merge_decl_attributes (tree olddecl
, tree newdecl
)
3957 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
3958 DECL_ATTRIBUTES (newdecl
));
3961 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
3963 /* Specialization of merge_decl_attributes for various Windows targets.
3965 This handles the following situation:
3967 __declspec (dllimport) int foo;
3970 The second instance of `foo' nullifies the dllimport. */
3973 merge_dllimport_decl_attributes (tree old
, tree new_tree
)
3976 int delete_dllimport_p
= 1;
3978 /* What we need to do here is remove from `old' dllimport if it doesn't
3979 appear in `new'. dllimport behaves like extern: if a declaration is
3980 marked dllimport and a definition appears later, then the object
3981 is not dllimport'd. We also remove a `new' dllimport if the old list
3982 contains dllexport: dllexport always overrides dllimport, regardless
3983 of the order of declaration. */
3984 if (!VAR_OR_FUNCTION_DECL_P (new_tree
))
3985 delete_dllimport_p
= 0;
3986 else if (DECL_DLLIMPORT_P (new_tree
)
3987 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old
)))
3989 DECL_DLLIMPORT_P (new_tree
) = 0;
3990 warning (OPT_Wattributes
, "%q+D already declared with dllexport attribute: "
3991 "dllimport ignored", new_tree
);
3993 else if (DECL_DLLIMPORT_P (old
) && !DECL_DLLIMPORT_P (new_tree
))
3995 /* Warn about overriding a symbol that has already been used, e.g.:
3996 extern int __attribute__ ((dllimport)) foo;
3997 int* bar () {return &foo;}
4000 if (TREE_USED (old
))
4002 warning (0, "%q+D redeclared without dllimport attribute "
4003 "after being referenced with dll linkage", new_tree
);
4004 /* If we have used a variable's address with dllimport linkage,
4005 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
4006 decl may already have had TREE_CONSTANT computed.
4007 We still remove the attribute so that assembler code refers
4008 to '&foo rather than '_imp__foo'. */
4009 if (TREE_CODE (old
) == VAR_DECL
&& TREE_ADDRESSABLE (old
))
4010 DECL_DLLIMPORT_P (new_tree
) = 1;
4013 /* Let an inline definition silently override the external reference,
4014 but otherwise warn about attribute inconsistency. */
4015 else if (TREE_CODE (new_tree
) == VAR_DECL
4016 || !DECL_DECLARED_INLINE_P (new_tree
))
4017 warning (OPT_Wattributes
, "%q+D redeclared without dllimport attribute: "
4018 "previous dllimport ignored", new_tree
);
4021 delete_dllimport_p
= 0;
4023 a
= merge_attributes (DECL_ATTRIBUTES (old
), DECL_ATTRIBUTES (new_tree
));
4025 if (delete_dllimport_p
)
4028 const size_t attr_len
= strlen ("dllimport");
4030 /* Scan the list for dllimport and delete it. */
4031 for (prev
= NULL_TREE
, t
= a
; t
; prev
= t
, t
= TREE_CHAIN (t
))
4033 if (is_attribute_with_length_p ("dllimport", attr_len
,
4036 if (prev
== NULL_TREE
)
4039 TREE_CHAIN (prev
) = TREE_CHAIN (t
);
4048 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
4049 struct attribute_spec.handler. */
4052 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
4057 /* These attributes may apply to structure and union types being created,
4058 but otherwise should pass to the declaration involved. */
4061 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
4062 | (int) ATTR_FLAG_ARRAY_NEXT
))
4064 *no_add_attrs
= true;
4065 return tree_cons (name
, args
, NULL_TREE
);
4067 if (TREE_CODE (node
) == RECORD_TYPE
4068 || TREE_CODE (node
) == UNION_TYPE
)
4070 node
= TYPE_NAME (node
);
4076 warning (OPT_Wattributes
, "%qs attribute ignored",
4077 IDENTIFIER_POINTER (name
));
4078 *no_add_attrs
= true;
4083 if (TREE_CODE (node
) != FUNCTION_DECL
4084 && TREE_CODE (node
) != VAR_DECL
4085 && TREE_CODE (node
) != TYPE_DECL
)
4087 *no_add_attrs
= true;
4088 warning (OPT_Wattributes
, "%qs attribute ignored",
4089 IDENTIFIER_POINTER (name
));
4093 if (TREE_CODE (node
) == TYPE_DECL
4094 && TREE_CODE (TREE_TYPE (node
)) != RECORD_TYPE
4095 && TREE_CODE (TREE_TYPE (node
)) != UNION_TYPE
)
4097 *no_add_attrs
= true;
4098 warning (OPT_Wattributes
, "%qs attribute ignored",
4099 IDENTIFIER_POINTER (name
));
4103 /* Report error on dllimport ambiguities seen now before they cause
4105 else if (is_attribute_p ("dllimport", name
))
4107 /* Honor any target-specific overrides. */
4108 if (!targetm
.valid_dllimport_attribute_p (node
))
4109 *no_add_attrs
= true;
4111 else if (TREE_CODE (node
) == FUNCTION_DECL
4112 && DECL_DECLARED_INLINE_P (node
))
4114 warning (OPT_Wattributes
, "inline function %q+D declared as "
4115 " dllimport: attribute ignored", node
);
4116 *no_add_attrs
= true;
4118 /* Like MS, treat definition of dllimported variables and
4119 non-inlined functions on declaration as syntax errors. */
4120 else if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
))
4122 error ("function %q+D definition is marked dllimport", node
);
4123 *no_add_attrs
= true;
4126 else if (TREE_CODE (node
) == VAR_DECL
)
4128 if (DECL_INITIAL (node
))
4130 error ("variable %q+D definition is marked dllimport",
4132 *no_add_attrs
= true;
4135 /* `extern' needn't be specified with dllimport.
4136 Specify `extern' now and hope for the best. Sigh. */
4137 DECL_EXTERNAL (node
) = 1;
4138 /* Also, implicitly give dllimport'd variables declared within
4139 a function global scope, unless declared static. */
4140 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
4141 TREE_PUBLIC (node
) = 1;
4144 if (*no_add_attrs
== false)
4145 DECL_DLLIMPORT_P (node
) = 1;
4148 /* Report error if symbol is not accessible at global scope. */
4149 if (!TREE_PUBLIC (node
)
4150 && (TREE_CODE (node
) == VAR_DECL
4151 || TREE_CODE (node
) == FUNCTION_DECL
))
4153 error ("external linkage required for symbol %q+D because of "
4154 "%qs attribute", node
, IDENTIFIER_POINTER (name
));
4155 *no_add_attrs
= true;
4158 /* A dllexport'd entity must have default visibility so that other
4159 program units (shared libraries or the main executable) can see
4160 it. A dllimport'd entity must have default visibility so that
4161 the linker knows that undefined references within this program
4162 unit can be resolved by the dynamic linker. */
4165 if (DECL_VISIBILITY_SPECIFIED (node
)
4166 && DECL_VISIBILITY (node
) != VISIBILITY_DEFAULT
)
4167 error ("%qs implies default visibility, but %qD has already "
4168 "been declared with a different visibility",
4169 IDENTIFIER_POINTER (name
), node
);
4170 DECL_VISIBILITY (node
) = VISIBILITY_DEFAULT
;
4171 DECL_VISIBILITY_SPECIFIED (node
) = 1;
4177 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
4179 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
4180 of the various TYPE_QUAL values. */
4183 set_type_quals (tree type
, int type_quals
)
4185 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
4186 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
4187 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
4190 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
4193 check_qualified_type (const_tree cand
, const_tree base
, int type_quals
)
4195 return (TYPE_QUALS (cand
) == type_quals
4196 && TYPE_NAME (cand
) == TYPE_NAME (base
)
4197 /* Apparently this is needed for Objective-C. */
4198 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
4199 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
4200 TYPE_ATTRIBUTES (base
)));
4203 /* Return a version of the TYPE, qualified as indicated by the
4204 TYPE_QUALS, if one exists. If no qualified version exists yet,
4205 return NULL_TREE. */
4208 get_qualified_type (tree type
, int type_quals
)
4212 if (TYPE_QUALS (type
) == type_quals
)
4215 /* Search the chain of variants to see if there is already one there just
4216 like the one we need to have. If so, use that existing one. We must
4217 preserve the TYPE_NAME, since there is code that depends on this. */
4218 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
4219 if (check_qualified_type (t
, type
, type_quals
))
4225 /* Like get_qualified_type, but creates the type if it does not
4226 exist. This function never returns NULL_TREE. */
4229 build_qualified_type (tree type
, int type_quals
)
4233 /* See if we already have the appropriate qualified variant. */
4234 t
= get_qualified_type (type
, type_quals
);
4236 /* If not, build it. */
4239 t
= build_variant_type_copy (type
);
4240 set_type_quals (t
, type_quals
);
4242 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
4243 /* Propagate structural equality. */
4244 SET_TYPE_STRUCTURAL_EQUALITY (t
);
4245 else if (TYPE_CANONICAL (type
) != type
)
4246 /* Build the underlying canonical type, since it is different
4248 TYPE_CANONICAL (t
) = build_qualified_type (TYPE_CANONICAL (type
),
4251 /* T is its own canonical type. */
4252 TYPE_CANONICAL (t
) = t
;
4259 /* Create a new distinct copy of TYPE. The new type is made its own
4260 MAIN_VARIANT. If TYPE requires structural equality checks, the
4261 resulting type requires structural equality checks; otherwise, its
4262 TYPE_CANONICAL points to itself. */
4265 build_distinct_type_copy (tree type
)
4267 tree t
= copy_node (type
);
4269 TYPE_POINTER_TO (t
) = 0;
4270 TYPE_REFERENCE_TO (t
) = 0;
4272 /* Set the canonical type either to a new equivalence class, or
4273 propagate the need for structural equality checks. */
4274 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
4275 SET_TYPE_STRUCTURAL_EQUALITY (t
);
4277 TYPE_CANONICAL (t
) = t
;
4279 /* Make it its own variant. */
4280 TYPE_MAIN_VARIANT (t
) = t
;
4281 TYPE_NEXT_VARIANT (t
) = 0;
4283 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
4284 whose TREE_TYPE is not t. This can also happen in the Ada
4285 frontend when using subtypes. */
4290 /* Create a new variant of TYPE, equivalent but distinct. This is so
4291 the caller can modify it. TYPE_CANONICAL for the return type will
4292 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
4293 are considered equal by the language itself (or that both types
4294 require structural equality checks). */
4297 build_variant_type_copy (tree type
)
4299 tree t
, m
= TYPE_MAIN_VARIANT (type
);
4301 t
= build_distinct_type_copy (type
);
4303 /* Since we're building a variant, assume that it is a non-semantic
4304 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
4305 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
4307 /* Add the new type to the chain of variants of TYPE. */
4308 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
4309 TYPE_NEXT_VARIANT (m
) = t
;
4310 TYPE_MAIN_VARIANT (t
) = m
;
4315 /* Return true if the from tree in both tree maps are equal. */
4318 tree_map_base_eq (const void *va
, const void *vb
)
4320 const struct tree_map_base
*const a
= (const struct tree_map_base
*) va
,
4321 *const b
= (const struct tree_map_base
*) vb
;
4322 return (a
->from
== b
->from
);
4325 /* Hash a from tree in a tree_map. */
4328 tree_map_base_hash (const void *item
)
4330 return htab_hash_pointer (((const struct tree_map_base
*)item
)->from
);
4333 /* Return true if this tree map structure is marked for garbage collection
4334 purposes. We simply return true if the from tree is marked, so that this
4335 structure goes away when the from tree goes away. */
4338 tree_map_base_marked_p (const void *p
)
4340 return ggc_marked_p (((const struct tree_map_base
*) p
)->from
);
4344 tree_map_hash (const void *item
)
4346 return (((const struct tree_map
*) item
)->hash
);
4349 /* Return the initialization priority for DECL. */
4352 decl_init_priority_lookup (tree decl
)
4354 struct tree_priority_map
*h
;
4355 struct tree_map_base in
;
4357 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
4359 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
4360 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
4363 /* Return the finalization priority for DECL. */
4366 decl_fini_priority_lookup (tree decl
)
4368 struct tree_priority_map
*h
;
4369 struct tree_map_base in
;
4371 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
4373 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
4374 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
4377 /* Return the initialization and finalization priority information for
4378 DECL. If there is no previous priority information, a freshly
4379 allocated structure is returned. */
4381 static struct tree_priority_map
*
4382 decl_priority_info (tree decl
)
4384 struct tree_priority_map in
;
4385 struct tree_priority_map
*h
;
4388 in
.base
.from
= decl
;
4389 loc
= htab_find_slot (init_priority_for_decl
, &in
, INSERT
);
4390 h
= (struct tree_priority_map
*) *loc
;
4393 h
= GGC_CNEW (struct tree_priority_map
);
4395 h
->base
.from
= decl
;
4396 h
->init
= DEFAULT_INIT_PRIORITY
;
4397 h
->fini
= DEFAULT_INIT_PRIORITY
;
4403 /* Set the initialization priority for DECL to PRIORITY. */
4406 decl_init_priority_insert (tree decl
, priority_type priority
)
4408 struct tree_priority_map
*h
;
4410 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
4411 h
= decl_priority_info (decl
);
4415 /* Set the finalization priority for DECL to PRIORITY. */
4418 decl_fini_priority_insert (tree decl
, priority_type priority
)
4420 struct tree_priority_map
*h
;
4422 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
4423 h
= decl_priority_info (decl
);
4427 /* Look up a restrict qualified base decl for FROM. */
4430 decl_restrict_base_lookup (tree from
)
4435 in
.base
.from
= from
;
4436 h
= (struct tree_map
*) htab_find_with_hash (restrict_base_for_decl
, &in
,
4437 htab_hash_pointer (from
));
4438 return h
? h
->to
: NULL_TREE
;
4441 /* Record the restrict qualified base TO for FROM. */
4444 decl_restrict_base_insert (tree from
, tree to
)
4449 h
= GGC_NEW (struct tree_map
);
4450 h
->hash
= htab_hash_pointer (from
);
4451 h
->base
.from
= from
;
4453 loc
= htab_find_slot_with_hash (restrict_base_for_decl
, h
, h
->hash
, INSERT
);
4454 *(struct tree_map
**) loc
= h
;
4457 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
4460 print_debug_expr_statistics (void)
4462 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
4463 (long) htab_size (debug_expr_for_decl
),
4464 (long) htab_elements (debug_expr_for_decl
),
4465 htab_collisions (debug_expr_for_decl
));
4468 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
4471 print_value_expr_statistics (void)
4473 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
4474 (long) htab_size (value_expr_for_decl
),
4475 (long) htab_elements (value_expr_for_decl
),
4476 htab_collisions (value_expr_for_decl
));
4479 /* Print out statistics for the RESTRICT_BASE_FOR_DECL hash table, but
4480 don't print anything if the table is empty. */
4483 print_restrict_base_statistics (void)
4485 if (htab_elements (restrict_base_for_decl
) != 0)
4487 "RESTRICT_BASE hash: size %ld, %ld elements, %f collisions\n",
4488 (long) htab_size (restrict_base_for_decl
),
4489 (long) htab_elements (restrict_base_for_decl
),
4490 htab_collisions (restrict_base_for_decl
));
4493 /* Lookup a debug expression for FROM, and return it if we find one. */
4496 decl_debug_expr_lookup (tree from
)
4498 struct tree_map
*h
, in
;
4499 in
.base
.from
= from
;
4501 h
= (struct tree_map
*) htab_find_with_hash (debug_expr_for_decl
, &in
,
4502 htab_hash_pointer (from
));
4508 /* Insert a mapping FROM->TO in the debug expression hashtable. */
4511 decl_debug_expr_insert (tree from
, tree to
)
4516 h
= GGC_NEW (struct tree_map
);
4517 h
->hash
= htab_hash_pointer (from
);
4518 h
->base
.from
= from
;
4520 loc
= htab_find_slot_with_hash (debug_expr_for_decl
, h
, h
->hash
, INSERT
);
4521 *(struct tree_map
**) loc
= h
;
4524 /* Lookup a value expression for FROM, and return it if we find one. */
4527 decl_value_expr_lookup (tree from
)
4529 struct tree_map
*h
, in
;
4530 in
.base
.from
= from
;
4532 h
= (struct tree_map
*) htab_find_with_hash (value_expr_for_decl
, &in
,
4533 htab_hash_pointer (from
));
4539 /* Insert a mapping FROM->TO in the value expression hashtable. */
4542 decl_value_expr_insert (tree from
, tree to
)
4547 h
= GGC_NEW (struct tree_map
);
4548 h
->hash
= htab_hash_pointer (from
);
4549 h
->base
.from
= from
;
4551 loc
= htab_find_slot_with_hash (value_expr_for_decl
, h
, h
->hash
, INSERT
);
4552 *(struct tree_map
**) loc
= h
;
4555 /* Hashing of types so that we don't make duplicates.
4556 The entry point is `type_hash_canon'. */
4558 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
4559 with types in the TREE_VALUE slots), by adding the hash codes
4560 of the individual types. */
4563 type_hash_list (const_tree list
, hashval_t hashcode
)
4567 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
4568 if (TREE_VALUE (tail
) != error_mark_node
)
4569 hashcode
= iterative_hash_object (TYPE_HASH (TREE_VALUE (tail
)),
4575 /* These are the Hashtable callback functions. */
4577 /* Returns true iff the types are equivalent. */
4580 type_hash_eq (const void *va
, const void *vb
)
4582 const struct type_hash
*const a
= (const struct type_hash
*) va
,
4583 *const b
= (const struct type_hash
*) vb
;
4585 /* First test the things that are the same for all types. */
4586 if (a
->hash
!= b
->hash
4587 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
4588 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
4589 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
4590 TYPE_ATTRIBUTES (b
->type
))
4591 || TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
4592 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
)
4593 || (TREE_CODE (a
->type
) != COMPLEX_TYPE
4594 && TYPE_NAME (a
->type
) != TYPE_NAME (b
->type
)))
4597 switch (TREE_CODE (a
->type
))
4602 case REFERENCE_TYPE
:
4606 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
4609 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
4610 && !(TYPE_VALUES (a
->type
)
4611 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
4612 && TYPE_VALUES (b
->type
)
4613 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
4614 && type_list_equal (TYPE_VALUES (a
->type
),
4615 TYPE_VALUES (b
->type
))))
4618 /* ... fall through ... */
4623 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
4624 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
4625 TYPE_MAX_VALUE (b
->type
)))
4626 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
4627 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
4628 TYPE_MIN_VALUE (b
->type
))));
4630 case FIXED_POINT_TYPE
:
4631 return TYPE_SATURATING (a
->type
) == TYPE_SATURATING (b
->type
);
4634 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
4637 return (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
4638 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
4639 || (TYPE_ARG_TYPES (a
->type
)
4640 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
4641 && TYPE_ARG_TYPES (b
->type
)
4642 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
4643 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
4644 TYPE_ARG_TYPES (b
->type
)))));
4647 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
4651 case QUAL_UNION_TYPE
:
4652 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
4653 || (TYPE_FIELDS (a
->type
)
4654 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
4655 && TYPE_FIELDS (b
->type
)
4656 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
4657 && type_list_equal (TYPE_FIELDS (a
->type
),
4658 TYPE_FIELDS (b
->type
))));
4661 if (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
4662 || (TYPE_ARG_TYPES (a
->type
)
4663 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
4664 && TYPE_ARG_TYPES (b
->type
)
4665 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
4666 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
4667 TYPE_ARG_TYPES (b
->type
))))
4675 if (lang_hooks
.types
.type_hash_eq
!= NULL
)
4676 return lang_hooks
.types
.type_hash_eq (a
->type
, b
->type
);
4681 /* Return the cached hash value. */
4684 type_hash_hash (const void *item
)
4686 return ((const struct type_hash
*) item
)->hash
;
4689 /* Look in the type hash table for a type isomorphic to TYPE.
4690 If one is found, return it. Otherwise return 0. */
4693 type_hash_lookup (hashval_t hashcode
, tree type
)
4695 struct type_hash
*h
, in
;
4697 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
4698 must call that routine before comparing TYPE_ALIGNs. */
4704 h
= (struct type_hash
*) htab_find_with_hash (type_hash_table
, &in
,
4711 /* Add an entry to the type-hash-table
4712 for a type TYPE whose hash code is HASHCODE. */
4715 type_hash_add (hashval_t hashcode
, tree type
)
4717 struct type_hash
*h
;
4720 h
= GGC_NEW (struct type_hash
);
4723 loc
= htab_find_slot_with_hash (type_hash_table
, h
, hashcode
, INSERT
);
4727 /* Given TYPE, and HASHCODE its hash code, return the canonical
4728 object for an identical type if one already exists.
4729 Otherwise, return TYPE, and record it as the canonical object.
4731 To use this function, first create a type of the sort you want.
4732 Then compute its hash code from the fields of the type that
4733 make it different from other similar types.
4734 Then call this function and use the value. */
4737 type_hash_canon (unsigned int hashcode
, tree type
)
4741 /* The hash table only contains main variants, so ensure that's what we're
4743 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
4745 if (!lang_hooks
.types
.hash_types
)
4748 /* See if the type is in the hash table already. If so, return it.
4749 Otherwise, add the type. */
4750 t1
= type_hash_lookup (hashcode
, type
);
4753 #ifdef GATHER_STATISTICS
4754 tree_node_counts
[(int) t_kind
]--;
4755 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type
);
4761 type_hash_add (hashcode
, type
);
4766 /* See if the data pointed to by the type hash table is marked. We consider
4767 it marked if the type is marked or if a debug type number or symbol
4768 table entry has been made for the type. This reduces the amount of
4769 debugging output and eliminates that dependency of the debug output on
4770 the number of garbage collections. */
4773 type_hash_marked_p (const void *p
)
4775 const_tree
const type
= ((const struct type_hash
*) p
)->type
;
4777 return ggc_marked_p (type
) || TYPE_SYMTAB_POINTER (type
);
4781 print_type_hash_statistics (void)
4783 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
4784 (long) htab_size (type_hash_table
),
4785 (long) htab_elements (type_hash_table
),
4786 htab_collisions (type_hash_table
));
4789 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
4790 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
4791 by adding the hash codes of the individual attributes. */
4794 attribute_hash_list (const_tree list
, hashval_t hashcode
)
4798 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
4799 /* ??? Do we want to add in TREE_VALUE too? */
4800 hashcode
= iterative_hash_object
4801 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail
)), hashcode
);
4805 /* Given two lists of attributes, return true if list l2 is
4806 equivalent to l1. */
4809 attribute_list_equal (const_tree l1
, const_tree l2
)
4811 return attribute_list_contained (l1
, l2
)
4812 && attribute_list_contained (l2
, l1
);
4815 /* Given two lists of attributes, return true if list L2 is
4816 completely contained within L1. */
4817 /* ??? This would be faster if attribute names were stored in a canonicalized
4818 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
4819 must be used to show these elements are equivalent (which they are). */
4820 /* ??? It's not clear that attributes with arguments will always be handled
4824 attribute_list_contained (const_tree l1
, const_tree l2
)
4828 /* First check the obvious, maybe the lists are identical. */
4832 /* Maybe the lists are similar. */
4833 for (t1
= l1
, t2
= l2
;
4835 && TREE_PURPOSE (t1
) == TREE_PURPOSE (t2
)
4836 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
4837 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
));
4839 /* Maybe the lists are equal. */
4840 if (t1
== 0 && t2
== 0)
4843 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
4846 /* This CONST_CAST is okay because lookup_attribute does not
4847 modify its argument and the return value is assigned to a
4849 for (attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
4850 CONST_CAST_TREE(l1
));
4852 attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
4855 if (TREE_VALUE (t2
) != NULL
4856 && TREE_CODE (TREE_VALUE (t2
)) == TREE_LIST
4857 && TREE_VALUE (attr
) != NULL
4858 && TREE_CODE (TREE_VALUE (attr
)) == TREE_LIST
)
4860 if (simple_cst_list_equal (TREE_VALUE (t2
),
4861 TREE_VALUE (attr
)) == 1)
4864 else if (simple_cst_equal (TREE_VALUE (t2
), TREE_VALUE (attr
)) == 1)
4875 /* Given two lists of types
4876 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
4877 return 1 if the lists contain the same types in the same order.
4878 Also, the TREE_PURPOSEs must match. */
4881 type_list_equal (const_tree l1
, const_tree l2
)
4885 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
4886 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
4887 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
4888 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
4889 && (TREE_TYPE (TREE_PURPOSE (t1
))
4890 == TREE_TYPE (TREE_PURPOSE (t2
))))))
4896 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
4897 given by TYPE. If the argument list accepts variable arguments,
4898 then this function counts only the ordinary arguments. */
4901 type_num_arguments (const_tree type
)
4906 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
4907 /* If the function does not take a variable number of arguments,
4908 the last element in the list will have type `void'. */
4909 if (VOID_TYPE_P (TREE_VALUE (t
)))
4917 /* Nonzero if integer constants T1 and T2
4918 represent the same constant value. */
4921 tree_int_cst_equal (const_tree t1
, const_tree t2
)
4926 if (t1
== 0 || t2
== 0)
4929 if (TREE_CODE (t1
) == INTEGER_CST
4930 && TREE_CODE (t2
) == INTEGER_CST
4931 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
4932 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
4938 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
4939 The precise way of comparison depends on their data type. */
4942 tree_int_cst_lt (const_tree t1
, const_tree t2
)
4947 if (TYPE_UNSIGNED (TREE_TYPE (t1
)) != TYPE_UNSIGNED (TREE_TYPE (t2
)))
4949 int t1_sgn
= tree_int_cst_sgn (t1
);
4950 int t2_sgn
= tree_int_cst_sgn (t2
);
4952 if (t1_sgn
< t2_sgn
)
4954 else if (t1_sgn
> t2_sgn
)
4956 /* Otherwise, both are non-negative, so we compare them as
4957 unsigned just in case one of them would overflow a signed
4960 else if (!TYPE_UNSIGNED (TREE_TYPE (t1
)))
4961 return INT_CST_LT (t1
, t2
);
4963 return INT_CST_LT_UNSIGNED (t1
, t2
);
4966 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
4969 tree_int_cst_compare (const_tree t1
, const_tree t2
)
4971 if (tree_int_cst_lt (t1
, t2
))
4973 else if (tree_int_cst_lt (t2
, t1
))
4979 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
4980 the host. If POS is zero, the value can be represented in a single
4981 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
4982 be represented in a single unsigned HOST_WIDE_INT. */
4985 host_integerp (const_tree t
, int pos
)
4987 return (TREE_CODE (t
) == INTEGER_CST
4988 && ((TREE_INT_CST_HIGH (t
) == 0
4989 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) >= 0)
4990 || (! pos
&& TREE_INT_CST_HIGH (t
) == -1
4991 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0
4992 && (!TYPE_UNSIGNED (TREE_TYPE (t
))
4993 || (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
4994 && TYPE_IS_SIZETYPE (TREE_TYPE (t
)))))
4995 || (pos
&& TREE_INT_CST_HIGH (t
) == 0)));
4998 /* Return the HOST_WIDE_INT least significant bits of T if it is an
4999 INTEGER_CST and there is no overflow. POS is nonzero if the result must
5000 be non-negative. We must be able to satisfy the above conditions. */
5003 tree_low_cst (const_tree t
, int pos
)
5005 gcc_assert (host_integerp (t
, pos
));
5006 return TREE_INT_CST_LOW (t
);
5009 /* Return the most significant bit of the integer constant T. */
5012 tree_int_cst_msb (const_tree t
)
5016 unsigned HOST_WIDE_INT l
;
5018 /* Note that using TYPE_PRECISION here is wrong. We care about the
5019 actual bits, not the (arbitrary) range of the type. */
5020 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t
))) - 1;
5021 rshift_double (TREE_INT_CST_LOW (t
), TREE_INT_CST_HIGH (t
), prec
,
5022 2 * HOST_BITS_PER_WIDE_INT
, &l
, &h
, 0);
5023 return (l
& 1) == 1;
5026 /* Return an indication of the sign of the integer constant T.
5027 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
5028 Note that -1 will never be returned if T's type is unsigned. */
5031 tree_int_cst_sgn (const_tree t
)
5033 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
5035 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
5037 else if (TREE_INT_CST_HIGH (t
) < 0)
5043 /* Return the minimum number of bits needed to represent VALUE in a
5044 signed or unsigned type, UNSIGNEDP says which. */
5047 tree_int_cst_min_precision (tree value
, bool unsignedp
)
5051 /* If the value is negative, compute its negative minus 1. The latter
5052 adjustment is because the absolute value of the largest negative value
5053 is one larger than the largest positive value. This is equivalent to
5054 a bit-wise negation, so use that operation instead. */
5056 if (tree_int_cst_sgn (value
) < 0)
5057 value
= fold_build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
);
5059 /* Return the number of bits needed, taking into account the fact
5060 that we need one more bit for a signed than unsigned type. */
5062 if (integer_zerop (value
))
5065 log
= tree_floor_log2 (value
);
5067 return log
+ 1 + !unsignedp
;
5070 /* Compare two constructor-element-type constants. Return 1 if the lists
5071 are known to be equal; otherwise return 0. */
5074 simple_cst_list_equal (const_tree l1
, const_tree l2
)
5076 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
5078 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
5081 l1
= TREE_CHAIN (l1
);
5082 l2
= TREE_CHAIN (l2
);
5088 /* Return truthvalue of whether T1 is the same tree structure as T2.
5089 Return 1 if they are the same.
5090 Return 0 if they are understandably different.
5091 Return -1 if either contains tree structure not understood by
5095 simple_cst_equal (const_tree t1
, const_tree t2
)
5097 enum tree_code code1
, code2
;
5103 if (t1
== 0 || t2
== 0)
5106 code1
= TREE_CODE (t1
);
5107 code2
= TREE_CODE (t2
);
5109 if (CONVERT_EXPR_CODE_P (code1
) || code1
== NON_LVALUE_EXPR
)
5111 if (CONVERT_EXPR_CODE_P (code2
)
5112 || code2
== NON_LVALUE_EXPR
)
5113 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5115 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
5118 else if (CONVERT_EXPR_CODE_P (code2
)
5119 || code2
== NON_LVALUE_EXPR
)
5120 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
5128 return (TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
5129 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
));
5132 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
5135 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
5138 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
5139 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
5140 TREE_STRING_LENGTH (t1
)));
5144 unsigned HOST_WIDE_INT idx
;
5145 VEC(constructor_elt
, gc
) *v1
= CONSTRUCTOR_ELTS (t1
);
5146 VEC(constructor_elt
, gc
) *v2
= CONSTRUCTOR_ELTS (t2
);
5148 if (VEC_length (constructor_elt
, v1
) != VEC_length (constructor_elt
, v2
))
5151 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
5152 /* ??? Should we handle also fields here? */
5153 if (!simple_cst_equal (VEC_index (constructor_elt
, v1
, idx
)->value
,
5154 VEC_index (constructor_elt
, v2
, idx
)->value
))
5160 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5163 cmp
= simple_cst_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
));
5166 if (call_expr_nargs (t1
) != call_expr_nargs (t2
))
5169 const_tree arg1
, arg2
;
5170 const_call_expr_arg_iterator iter1
, iter2
;
5171 for (arg1
= first_const_call_expr_arg (t1
, &iter1
),
5172 arg2
= first_const_call_expr_arg (t2
, &iter2
);
5174 arg1
= next_const_call_expr_arg (&iter1
),
5175 arg2
= next_const_call_expr_arg (&iter2
))
5177 cmp
= simple_cst_equal (arg1
, arg2
);
5181 return arg1
== arg2
;
5185 /* Special case: if either target is an unallocated VAR_DECL,
5186 it means that it's going to be unified with whatever the
5187 TARGET_EXPR is really supposed to initialize, so treat it
5188 as being equivalent to anything. */
5189 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
5190 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
5191 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
5192 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
5193 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
5194 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
5197 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5202 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
5204 case WITH_CLEANUP_EXPR
:
5205 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5209 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
5212 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
5213 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5227 /* This general rule works for most tree codes. All exceptions should be
5228 handled above. If this is a language-specific tree code, we can't
5229 trust what might be in the operand, so say we don't know
5231 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
5234 switch (TREE_CODE_CLASS (code1
))
5238 case tcc_comparison
:
5239 case tcc_expression
:
5243 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
5245 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
5257 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
5258 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
5259 than U, respectively. */
5262 compare_tree_int (const_tree t
, unsigned HOST_WIDE_INT u
)
5264 if (tree_int_cst_sgn (t
) < 0)
5266 else if (TREE_INT_CST_HIGH (t
) != 0)
5268 else if (TREE_INT_CST_LOW (t
) == u
)
5270 else if (TREE_INT_CST_LOW (t
) < u
)
5276 /* Return true if CODE represents an associative tree code. Otherwise
5279 associative_tree_code (enum tree_code code
)
5298 /* Return true if CODE represents a commutative tree code. Otherwise
5301 commutative_tree_code (enum tree_code code
)
5314 case UNORDERED_EXPR
:
5318 case TRUTH_AND_EXPR
:
5319 case TRUTH_XOR_EXPR
:
5329 /* Generate a hash value for an expression. This can be used iteratively
5330 by passing a previous result as the VAL argument.
5332 This function is intended to produce the same hash for expressions which
5333 would compare equal using operand_equal_p. */
5336 iterative_hash_expr (const_tree t
, hashval_t val
)
5339 enum tree_code code
;
5343 return iterative_hash_pointer (t
, val
);
5345 code
= TREE_CODE (t
);
5349 /* Alas, constants aren't shared, so we can't rely on pointer
5352 val
= iterative_hash_host_wide_int (TREE_INT_CST_LOW (t
), val
);
5353 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t
), val
);
5356 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
5358 return iterative_hash_hashval_t (val2
, val
);
5362 unsigned int val2
= fixed_hash (TREE_FIXED_CST_PTR (t
));
5364 return iterative_hash_hashval_t (val2
, val
);
5367 return iterative_hash (TREE_STRING_POINTER (t
),
5368 TREE_STRING_LENGTH (t
), val
);
5370 val
= iterative_hash_expr (TREE_REALPART (t
), val
);
5371 return iterative_hash_expr (TREE_IMAGPART (t
), val
);
5373 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t
), val
);
5376 /* we can just compare by pointer. */
5377 return iterative_hash_pointer (t
, val
);
5380 /* A list of expressions, for a CALL_EXPR or as the elements of a
5382 for (; t
; t
= TREE_CHAIN (t
))
5383 val
= iterative_hash_expr (TREE_VALUE (t
), val
);
5387 unsigned HOST_WIDE_INT idx
;
5389 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
5391 val
= iterative_hash_expr (field
, val
);
5392 val
= iterative_hash_expr (value
, val
);
5397 /* When referring to a built-in FUNCTION_DECL, use the
5398 __builtin__ form. Otherwise nodes that compare equal
5399 according to operand_equal_p might get different
5401 if (DECL_BUILT_IN (t
))
5403 val
= iterative_hash_pointer (built_in_decls
[DECL_FUNCTION_CODE (t
)],
5407 /* else FALL THROUGH */
5409 tclass
= TREE_CODE_CLASS (code
);
5411 if (tclass
== tcc_declaration
)
5413 /* DECL's have a unique ID */
5414 val
= iterative_hash_host_wide_int (DECL_UID (t
), val
);
5418 gcc_assert (IS_EXPR_CODE_CLASS (tclass
));
5420 val
= iterative_hash_object (code
, val
);
5422 /* Don't hash the type, that can lead to having nodes which
5423 compare equal according to operand_equal_p, but which
5424 have different hash codes. */
5425 if (CONVERT_EXPR_CODE_P (code
)
5426 || code
== NON_LVALUE_EXPR
)
5428 /* Make sure to include signness in the hash computation. */
5429 val
+= TYPE_UNSIGNED (TREE_TYPE (t
));
5430 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
5433 else if (commutative_tree_code (code
))
5435 /* It's a commutative expression. We want to hash it the same
5436 however it appears. We do this by first hashing both operands
5437 and then rehashing based on the order of their independent
5439 hashval_t one
= iterative_hash_expr (TREE_OPERAND (t
, 0), 0);
5440 hashval_t two
= iterative_hash_expr (TREE_OPERAND (t
, 1), 0);
5444 t
= one
, one
= two
, two
= t
;
5446 val
= iterative_hash_hashval_t (one
, val
);
5447 val
= iterative_hash_hashval_t (two
, val
);
5450 for (i
= TREE_OPERAND_LENGTH (t
) - 1; i
>= 0; --i
)
5451 val
= iterative_hash_expr (TREE_OPERAND (t
, i
), val
);
5458 /* Generate a hash value for a pair of expressions. This can be used
5459 iteratively by passing a previous result as the VAL argument.
5461 The same hash value is always returned for a given pair of expressions,
5462 regardless of the order in which they are presented. This is useful in
5463 hashing the operands of commutative functions. */
5466 iterative_hash_exprs_commutative (const_tree t1
,
5467 const_tree t2
, hashval_t val
)
5469 hashval_t one
= iterative_hash_expr (t1
, 0);
5470 hashval_t two
= iterative_hash_expr (t2
, 0);
5474 t
= one
, one
= two
, two
= t
;
5475 val
= iterative_hash_hashval_t (one
, val
);
5476 val
= iterative_hash_hashval_t (two
, val
);
5481 /* Constructors for pointer, array and function types.
5482 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
5483 constructed by language-dependent code, not here.) */
5485 /* Construct, lay out and return the type of pointers to TO_TYPE with
5486 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
5487 reference all of memory. If such a type has already been
5488 constructed, reuse it. */
5491 build_pointer_type_for_mode (tree to_type
, enum machine_mode mode
,
5496 if (to_type
== error_mark_node
)
5497 return error_mark_node
;
5499 /* If the pointed-to type has the may_alias attribute set, force
5500 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
5501 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
5502 can_alias_all
= true;
5504 /* In some cases, languages will have things that aren't a POINTER_TYPE
5505 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
5506 In that case, return that type without regard to the rest of our
5509 ??? This is a kludge, but consistent with the way this function has
5510 always operated and there doesn't seem to be a good way to avoid this
5512 if (TYPE_POINTER_TO (to_type
) != 0
5513 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
5514 return TYPE_POINTER_TO (to_type
);
5516 /* First, if we already have a type for pointers to TO_TYPE and it's
5517 the proper mode, use it. */
5518 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
5519 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
5522 t
= make_node (POINTER_TYPE
);
5524 TREE_TYPE (t
) = to_type
;
5525 SET_TYPE_MODE (t
, mode
);
5526 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
5527 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
5528 TYPE_POINTER_TO (to_type
) = t
;
5530 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
5531 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5532 else if (TYPE_CANONICAL (to_type
) != to_type
)
5534 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
5535 mode
, can_alias_all
);
5537 /* Lay out the type. This function has many callers that are concerned
5538 with expression-construction, and this simplifies them all. */
5544 /* By default build pointers in ptr_mode. */
5547 build_pointer_type (tree to_type
)
5549 return build_pointer_type_for_mode (to_type
, ptr_mode
, false);
5552 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
5555 build_reference_type_for_mode (tree to_type
, enum machine_mode mode
,
5560 if (to_type
== error_mark_node
)
5561 return error_mark_node
;
5563 /* If the pointed-to type has the may_alias attribute set, force
5564 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
5565 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
5566 can_alias_all
= true;
5568 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
5569 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
5570 In that case, return that type without regard to the rest of our
5573 ??? This is a kludge, but consistent with the way this function has
5574 always operated and there doesn't seem to be a good way to avoid this
5576 if (TYPE_REFERENCE_TO (to_type
) != 0
5577 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
5578 return TYPE_REFERENCE_TO (to_type
);
5580 /* First, if we already have a type for pointers to TO_TYPE and it's
5581 the proper mode, use it. */
5582 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
5583 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
5586 t
= make_node (REFERENCE_TYPE
);
5588 TREE_TYPE (t
) = to_type
;
5589 SET_TYPE_MODE (t
, mode
);
5590 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
5591 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
5592 TYPE_REFERENCE_TO (to_type
) = t
;
5594 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
5595 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5596 else if (TYPE_CANONICAL (to_type
) != to_type
)
5598 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
5599 mode
, can_alias_all
);
5607 /* Build the node for the type of references-to-TO_TYPE by default
5611 build_reference_type (tree to_type
)
5613 return build_reference_type_for_mode (to_type
, ptr_mode
, false);
5616 /* Build a type that is compatible with t but has no cv quals anywhere
5619 const char *const *const * -> char ***. */
5622 build_type_no_quals (tree t
)
5624 switch (TREE_CODE (t
))
5627 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
5629 TYPE_REF_CAN_ALIAS_ALL (t
));
5630 case REFERENCE_TYPE
:
5632 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
5634 TYPE_REF_CAN_ALIAS_ALL (t
));
5636 return TYPE_MAIN_VARIANT (t
);
5640 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
5641 MAXVAL should be the maximum value in the domain
5642 (one less than the length of the array).
5644 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
5645 We don't enforce this limit, that is up to caller (e.g. language front end).
5646 The limit exists because the result is a signed type and we don't handle
5647 sizes that use more than one HOST_WIDE_INT. */
5650 build_index_type (tree maxval
)
5652 tree itype
= make_node (INTEGER_TYPE
);
5654 TREE_TYPE (itype
) = sizetype
;
5655 TYPE_PRECISION (itype
) = TYPE_PRECISION (sizetype
);
5656 TYPE_MIN_VALUE (itype
) = size_zero_node
;
5657 TYPE_MAX_VALUE (itype
) = fold_convert (sizetype
, maxval
);
5658 SET_TYPE_MODE (itype
, TYPE_MODE (sizetype
));
5659 TYPE_SIZE (itype
) = TYPE_SIZE (sizetype
);
5660 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (sizetype
);
5661 TYPE_ALIGN (itype
) = TYPE_ALIGN (sizetype
);
5662 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (sizetype
);
5664 if (host_integerp (maxval
, 1))
5665 return type_hash_canon (tree_low_cst (maxval
, 1), itype
);
5668 /* Since we cannot hash this type, we need to compare it using
5669 structural equality checks. */
5670 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
5675 /* Builds a signed or unsigned integer type of precision PRECISION.
5676 Used for C bitfields whose precision does not match that of
5677 built-in target types. */
5679 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
5682 tree itype
= make_node (INTEGER_TYPE
);
5684 TYPE_PRECISION (itype
) = precision
;
5687 fixup_unsigned_type (itype
);
5689 fixup_signed_type (itype
);
5691 if (host_integerp (TYPE_MAX_VALUE (itype
), 1))
5692 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype
), 1), itype
);
5697 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
5698 ENUMERAL_TYPE or BOOLEAN_TYPE), with low bound LOWVAL and
5699 high bound HIGHVAL. If TYPE is NULL, sizetype is used. */
5702 build_range_type (tree type
, tree lowval
, tree highval
)
5704 tree itype
= make_node (INTEGER_TYPE
);
5706 TREE_TYPE (itype
) = type
;
5707 if (type
== NULL_TREE
)
5710 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
5711 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
5713 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
5714 SET_TYPE_MODE (itype
, TYPE_MODE (type
));
5715 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
5716 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
5717 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
5718 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
5720 if (host_integerp (lowval
, 0) && highval
!= 0 && host_integerp (highval
, 0))
5721 return type_hash_canon (tree_low_cst (highval
, 0)
5722 - tree_low_cst (lowval
, 0),
5728 /* Just like build_index_type, but takes lowval and highval instead
5729 of just highval (maxval). */
5732 build_index_2_type (tree lowval
, tree highval
)
5734 return build_range_type (sizetype
, lowval
, highval
);
5737 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
5738 and number of elements specified by the range of values of INDEX_TYPE.
5739 If such a type has already been constructed, reuse it. */
5742 build_array_type (tree elt_type
, tree index_type
)
5745 hashval_t hashcode
= 0;
5747 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
5749 error ("arrays of functions are not meaningful");
5750 elt_type
= integer_type_node
;
5753 t
= make_node (ARRAY_TYPE
);
5754 TREE_TYPE (t
) = elt_type
;
5755 TYPE_DOMAIN (t
) = index_type
;
5757 if (index_type
== 0)
5760 hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), hashcode
);
5761 t
= type_hash_canon (hashcode
, t
);
5765 if (TYPE_CANONICAL (t
) == t
)
5767 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
))
5768 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5769 else if (TYPE_CANONICAL (elt_type
) != elt_type
)
5771 = build_array_type (TYPE_CANONICAL (elt_type
), index_type
);
5777 hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), hashcode
);
5778 hashcode
= iterative_hash_object (TYPE_HASH (index_type
), hashcode
);
5779 t
= type_hash_canon (hashcode
, t
);
5781 if (!COMPLETE_TYPE_P (t
))
5784 if (TYPE_CANONICAL (t
) == t
)
5786 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
5787 || TYPE_STRUCTURAL_EQUALITY_P (index_type
))
5788 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5789 else if (TYPE_CANONICAL (elt_type
) != elt_type
5790 || TYPE_CANONICAL (index_type
) != index_type
)
5792 = build_array_type (TYPE_CANONICAL (elt_type
),
5793 TYPE_CANONICAL (index_type
));
5799 /* Recursively examines the array elements of TYPE, until a non-array
5800 element type is found. */
5803 strip_array_types (tree type
)
5805 while (TREE_CODE (type
) == ARRAY_TYPE
)
5806 type
= TREE_TYPE (type
);
5811 /* Computes the canonical argument types from the argument type list
5814 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
5815 on entry to this function, or if any of the ARGTYPES are
5818 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
5819 true on entry to this function, or if any of the ARGTYPES are
5822 Returns a canonical argument list, which may be ARGTYPES when the
5823 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
5824 true) or would not differ from ARGTYPES. */
5827 maybe_canonicalize_argtypes(tree argtypes
,
5828 bool *any_structural_p
,
5829 bool *any_noncanonical_p
)
5832 bool any_noncanonical_argtypes_p
= false;
5834 for (arg
= argtypes
; arg
&& !(*any_structural_p
); arg
= TREE_CHAIN (arg
))
5836 if (!TREE_VALUE (arg
) || TREE_VALUE (arg
) == error_mark_node
)
5837 /* Fail gracefully by stating that the type is structural. */
5838 *any_structural_p
= true;
5839 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg
)))
5840 *any_structural_p
= true;
5841 else if (TYPE_CANONICAL (TREE_VALUE (arg
)) != TREE_VALUE (arg
)
5842 || TREE_PURPOSE (arg
))
5843 /* If the argument has a default argument, we consider it
5844 non-canonical even though the type itself is canonical.
5845 That way, different variants of function and method types
5846 with default arguments will all point to the variant with
5847 no defaults as their canonical type. */
5848 any_noncanonical_argtypes_p
= true;
5851 if (*any_structural_p
)
5854 if (any_noncanonical_argtypes_p
)
5856 /* Build the canonical list of argument types. */
5857 tree canon_argtypes
= NULL_TREE
;
5858 bool is_void
= false;
5860 for (arg
= argtypes
; arg
; arg
= TREE_CHAIN (arg
))
5862 if (arg
== void_list_node
)
5865 canon_argtypes
= tree_cons (NULL_TREE
,
5866 TYPE_CANONICAL (TREE_VALUE (arg
)),
5870 canon_argtypes
= nreverse (canon_argtypes
);
5872 canon_argtypes
= chainon (canon_argtypes
, void_list_node
);
5874 /* There is a non-canonical type. */
5875 *any_noncanonical_p
= true;
5876 return canon_argtypes
;
5879 /* The canonical argument types are the same as ARGTYPES. */
5883 /* Construct, lay out and return
5884 the type of functions returning type VALUE_TYPE
5885 given arguments of types ARG_TYPES.
5886 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
5887 are data type nodes for the arguments of the function.
5888 If such a type has already been constructed, reuse it. */
5891 build_function_type (tree value_type
, tree arg_types
)
5894 hashval_t hashcode
= 0;
5895 bool any_structural_p
, any_noncanonical_p
;
5896 tree canon_argtypes
;
5898 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
5900 error ("function return type cannot be function");
5901 value_type
= integer_type_node
;
5904 /* Make a node of the sort we want. */
5905 t
= make_node (FUNCTION_TYPE
);
5906 TREE_TYPE (t
) = value_type
;
5907 TYPE_ARG_TYPES (t
) = arg_types
;
5909 /* If we already have such a type, use the old one. */
5910 hashcode
= iterative_hash_object (TYPE_HASH (value_type
), hashcode
);
5911 hashcode
= type_hash_list (arg_types
, hashcode
);
5912 t
= type_hash_canon (hashcode
, t
);
5914 /* Set up the canonical type. */
5915 any_structural_p
= TYPE_STRUCTURAL_EQUALITY_P (value_type
);
5916 any_noncanonical_p
= TYPE_CANONICAL (value_type
) != value_type
;
5917 canon_argtypes
= maybe_canonicalize_argtypes (arg_types
,
5919 &any_noncanonical_p
);
5920 if (any_structural_p
)
5921 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5922 else if (any_noncanonical_p
)
5923 TYPE_CANONICAL (t
) = build_function_type (TYPE_CANONICAL (value_type
),
5926 if (!COMPLETE_TYPE_P (t
))
5931 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP. */
5934 build_function_type_skip_args (tree orig_type
, bitmap args_to_skip
)
5936 tree new_type
= NULL
;
5937 tree args
, new_args
= NULL
, t
;
5941 for (args
= TYPE_ARG_TYPES (orig_type
); args
&& args
!= void_list_node
;
5942 args
= TREE_CHAIN (args
), i
++)
5943 if (!bitmap_bit_p (args_to_skip
, i
))
5944 new_args
= tree_cons (NULL_TREE
, TREE_VALUE (args
), new_args
);
5946 new_reversed
= nreverse (new_args
);
5950 TREE_CHAIN (new_args
) = void_list_node
;
5952 new_reversed
= void_list_node
;
5954 gcc_assert (new_reversed
);
5956 /* Use copy_node to preserve as much as possible from original type
5957 (debug info, attribute lists etc.)
5958 Exception is METHOD_TYPEs must have THIS argument.
5959 When we are asked to remove it, we need to build new FUNCTION_TYPE
5961 if (TREE_CODE (orig_type
) != METHOD_TYPE
5962 || !bitmap_bit_p (args_to_skip
, 0))
5964 new_type
= copy_node (orig_type
);
5965 TYPE_ARG_TYPES (new_type
) = new_reversed
;
5970 = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type
),
5972 TYPE_CONTEXT (new_type
) = TYPE_CONTEXT (orig_type
);
5975 /* This is a new type, not a copy of an old type. Need to reassociate
5976 variants. We can handle everything except the main variant lazily. */
5977 t
= TYPE_MAIN_VARIANT (orig_type
);
5980 TYPE_MAIN_VARIANT (new_type
) = t
;
5981 TYPE_NEXT_VARIANT (new_type
) = TYPE_NEXT_VARIANT (t
);
5982 TYPE_NEXT_VARIANT (t
) = new_type
;
5986 TYPE_MAIN_VARIANT (new_type
) = new_type
;
5987 TYPE_NEXT_VARIANT (new_type
) = NULL
;
5992 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP.
5994 Arguments from DECL_ARGUMENTS list can't be removed now, since they are
5995 linked by TREE_CHAIN directly. It is caller responsibility to eliminate
5996 them when they are being duplicated (i.e. copy_arguments_for_versioning). */
5999 build_function_decl_skip_args (tree orig_decl
, bitmap args_to_skip
)
6001 tree new_decl
= copy_node (orig_decl
);
6004 new_type
= TREE_TYPE (orig_decl
);
6005 if (prototype_p (new_type
))
6006 new_type
= build_function_type_skip_args (new_type
, args_to_skip
);
6007 TREE_TYPE (new_decl
) = new_type
;
6009 /* For declarations setting DECL_VINDEX (i.e. methods)
6010 we expect first argument to be THIS pointer. */
6011 if (bitmap_bit_p (args_to_skip
, 0))
6012 DECL_VINDEX (new_decl
) = NULL_TREE
;
6016 /* Build a function type. The RETURN_TYPE is the type returned by the
6017 function. If VAARGS is set, no void_type_node is appended to the
6018 the list. ARGP muse be alway be terminated be a NULL_TREE. */
6021 build_function_type_list_1 (bool vaargs
, tree return_type
, va_list argp
)
6025 t
= va_arg (argp
, tree
);
6026 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (argp
, tree
))
6027 args
= tree_cons (NULL_TREE
, t
, args
);
6032 if (args
!= NULL_TREE
)
6033 args
= nreverse (args
);
6034 gcc_assert (args
!= NULL_TREE
&& last
!= void_list_node
);
6036 else if (args
== NULL_TREE
)
6037 args
= void_list_node
;
6041 args
= nreverse (args
);
6042 TREE_CHAIN (last
) = void_list_node
;
6044 args
= build_function_type (return_type
, args
);
6049 /* Build a function type. The RETURN_TYPE is the type returned by the
6050 function. If additional arguments are provided, they are
6051 additional argument types. The list of argument types must always
6052 be terminated by NULL_TREE. */
6055 build_function_type_list (tree return_type
, ...)
6060 va_start (p
, return_type
);
6061 args
= build_function_type_list_1 (false, return_type
, p
);
6066 /* Build a variable argument function type. The RETURN_TYPE is the
6067 type returned by the function. If additional arguments are provided,
6068 they are additional argument types. The list of argument types must
6069 always be terminated by NULL_TREE. */
6072 build_varargs_function_type_list (tree return_type
, ...)
6077 va_start (p
, return_type
);
6078 args
= build_function_type_list_1 (true, return_type
, p
);
6084 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
6085 and ARGTYPES (a TREE_LIST) are the return type and arguments types
6086 for the method. An implicit additional parameter (of type
6087 pointer-to-BASETYPE) is added to the ARGTYPES. */
6090 build_method_type_directly (tree basetype
,
6097 bool any_structural_p
, any_noncanonical_p
;
6098 tree canon_argtypes
;
6100 /* Make a node of the sort we want. */
6101 t
= make_node (METHOD_TYPE
);
6103 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
6104 TREE_TYPE (t
) = rettype
;
6105 ptype
= build_pointer_type (basetype
);
6107 /* The actual arglist for this function includes a "hidden" argument
6108 which is "this". Put it into the list of argument types. */
6109 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
6110 TYPE_ARG_TYPES (t
) = argtypes
;
6112 /* If we already have such a type, use the old one. */
6113 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
6114 hashcode
= iterative_hash_object (TYPE_HASH (rettype
), hashcode
);
6115 hashcode
= type_hash_list (argtypes
, hashcode
);
6116 t
= type_hash_canon (hashcode
, t
);
6118 /* Set up the canonical type. */
6120 = (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
6121 || TYPE_STRUCTURAL_EQUALITY_P (rettype
));
6123 = (TYPE_CANONICAL (basetype
) != basetype
6124 || TYPE_CANONICAL (rettype
) != rettype
);
6125 canon_argtypes
= maybe_canonicalize_argtypes (TREE_CHAIN (argtypes
),
6127 &any_noncanonical_p
);
6128 if (any_structural_p
)
6129 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6130 else if (any_noncanonical_p
)
6132 = build_method_type_directly (TYPE_CANONICAL (basetype
),
6133 TYPE_CANONICAL (rettype
),
6135 if (!COMPLETE_TYPE_P (t
))
6141 /* Construct, lay out and return the type of methods belonging to class
6142 BASETYPE and whose arguments and values are described by TYPE.
6143 If that type exists already, reuse it.
6144 TYPE must be a FUNCTION_TYPE node. */
6147 build_method_type (tree basetype
, tree type
)
6149 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
6151 return build_method_type_directly (basetype
,
6153 TYPE_ARG_TYPES (type
));
6156 /* Construct, lay out and return the type of offsets to a value
6157 of type TYPE, within an object of type BASETYPE.
6158 If a suitable offset type exists already, reuse it. */
6161 build_offset_type (tree basetype
, tree type
)
6164 hashval_t hashcode
= 0;
6166 /* Make a node of the sort we want. */
6167 t
= make_node (OFFSET_TYPE
);
6169 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
6170 TREE_TYPE (t
) = type
;
6172 /* If we already have such a type, use the old one. */
6173 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
6174 hashcode
= iterative_hash_object (TYPE_HASH (type
), hashcode
);
6175 t
= type_hash_canon (hashcode
, t
);
6177 if (!COMPLETE_TYPE_P (t
))
6180 if (TYPE_CANONICAL (t
) == t
)
6182 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
6183 || TYPE_STRUCTURAL_EQUALITY_P (type
))
6184 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6185 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)) != basetype
6186 || TYPE_CANONICAL (type
) != type
)
6188 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)),
6189 TYPE_CANONICAL (type
));
6195 /* Create a complex type whose components are COMPONENT_TYPE. */
6198 build_complex_type (tree component_type
)
6203 gcc_assert (INTEGRAL_TYPE_P (component_type
)
6204 || SCALAR_FLOAT_TYPE_P (component_type
)
6205 || FIXED_POINT_TYPE_P (component_type
));
6207 /* Make a node of the sort we want. */
6208 t
= make_node (COMPLEX_TYPE
);
6210 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
6212 /* If we already have such a type, use the old one. */
6213 hashcode
= iterative_hash_object (TYPE_HASH (component_type
), 0);
6214 t
= type_hash_canon (hashcode
, t
);
6216 if (!COMPLETE_TYPE_P (t
))
6219 if (TYPE_CANONICAL (t
) == t
)
6221 if (TYPE_STRUCTURAL_EQUALITY_P (component_type
))
6222 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6223 else if (TYPE_CANONICAL (component_type
) != component_type
)
6225 = build_complex_type (TYPE_CANONICAL (component_type
));
6228 /* We need to create a name, since complex is a fundamental type. */
6229 if (! TYPE_NAME (t
))
6232 if (component_type
== char_type_node
)
6233 name
= "complex char";
6234 else if (component_type
== signed_char_type_node
)
6235 name
= "complex signed char";
6236 else if (component_type
== unsigned_char_type_node
)
6237 name
= "complex unsigned char";
6238 else if (component_type
== short_integer_type_node
)
6239 name
= "complex short int";
6240 else if (component_type
== short_unsigned_type_node
)
6241 name
= "complex short unsigned int";
6242 else if (component_type
== integer_type_node
)
6243 name
= "complex int";
6244 else if (component_type
== unsigned_type_node
)
6245 name
= "complex unsigned int";
6246 else if (component_type
== long_integer_type_node
)
6247 name
= "complex long int";
6248 else if (component_type
== long_unsigned_type_node
)
6249 name
= "complex long unsigned int";
6250 else if (component_type
== long_long_integer_type_node
)
6251 name
= "complex long long int";
6252 else if (component_type
== long_long_unsigned_type_node
)
6253 name
= "complex long long unsigned int";
6258 TYPE_NAME (t
) = build_decl (TYPE_DECL
, get_identifier (name
), t
);
6261 return build_qualified_type (t
, TYPE_QUALS (component_type
));
6264 /* Return OP, stripped of any conversions to wider types as much as is safe.
6265 Converting the value back to OP's type makes a value equivalent to OP.
6267 If FOR_TYPE is nonzero, we return a value which, if converted to
6268 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
6270 OP must have integer, real or enumeral type. Pointers are not allowed!
6272 There are some cases where the obvious value we could return
6273 would regenerate to OP if converted to OP's type,
6274 but would not extend like OP to wider types.
6275 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
6276 For example, if OP is (unsigned short)(signed char)-1,
6277 we avoid returning (signed char)-1 if FOR_TYPE is int,
6278 even though extending that to an unsigned short would regenerate OP,
6279 since the result of extending (signed char)-1 to (int)
6280 is different from (int) OP. */
6283 get_unwidened (tree op
, tree for_type
)
6285 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
6286 tree type
= TREE_TYPE (op
);
6288 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
6290 = (for_type
!= 0 && for_type
!= type
6291 && final_prec
> TYPE_PRECISION (type
)
6292 && TYPE_UNSIGNED (type
));
6295 while (CONVERT_EXPR_P (op
))
6299 /* TYPE_PRECISION on vector types has different meaning
6300 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
6301 so avoid them here. */
6302 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
6305 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
6306 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
6308 /* Truncations are many-one so cannot be removed.
6309 Unless we are later going to truncate down even farther. */
6311 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
6314 /* See what's inside this conversion. If we decide to strip it,
6316 op
= TREE_OPERAND (op
, 0);
6318 /* If we have not stripped any zero-extensions (uns is 0),
6319 we can strip any kind of extension.
6320 If we have previously stripped a zero-extension,
6321 only zero-extensions can safely be stripped.
6322 Any extension can be stripped if the bits it would produce
6323 are all going to be discarded later by truncating to FOR_TYPE. */
6327 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
6329 /* TYPE_UNSIGNED says whether this is a zero-extension.
6330 Let's avoid computing it if it does not affect WIN
6331 and if UNS will not be needed again. */
6333 || CONVERT_EXPR_P (op
))
6334 && TYPE_UNSIGNED (TREE_TYPE (op
)))
6345 /* Return OP or a simpler expression for a narrower value
6346 which can be sign-extended or zero-extended to give back OP.
6347 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
6348 or 0 if the value should be sign-extended. */
6351 get_narrower (tree op
, int *unsignedp_ptr
)
6356 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
6358 while (TREE_CODE (op
) == NOP_EXPR
)
6361 = (TYPE_PRECISION (TREE_TYPE (op
))
6362 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
6364 /* Truncations are many-one so cannot be removed. */
6368 /* See what's inside this conversion. If we decide to strip it,
6373 op
= TREE_OPERAND (op
, 0);
6374 /* An extension: the outermost one can be stripped,
6375 but remember whether it is zero or sign extension. */
6377 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
6378 /* Otherwise, if a sign extension has been stripped,
6379 only sign extensions can now be stripped;
6380 if a zero extension has been stripped, only zero-extensions. */
6381 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
6385 else /* bitschange == 0 */
6387 /* A change in nominal type can always be stripped, but we must
6388 preserve the unsignedness. */
6390 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
6392 op
= TREE_OPERAND (op
, 0);
6393 /* Keep trying to narrow, but don't assign op to win if it
6394 would turn an integral type into something else. */
6395 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
6402 if (TREE_CODE (op
) == COMPONENT_REF
6403 /* Since type_for_size always gives an integer type. */
6404 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
6405 && TREE_CODE (TREE_TYPE (op
)) != FIXED_POINT_TYPE
6406 /* Ensure field is laid out already. */
6407 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
6408 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
6410 unsigned HOST_WIDE_INT innerprec
6411 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
6412 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
6413 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
6414 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
6416 /* We can get this structure field in a narrower type that fits it,
6417 but the resulting extension to its nominal type (a fullword type)
6418 must satisfy the same conditions as for other extensions.
6420 Do this only for fields that are aligned (not bit-fields),
6421 because when bit-field insns will be used there is no
6422 advantage in doing this. */
6424 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
6425 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
6426 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
6430 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
6431 win
= fold_convert (type
, op
);
6435 *unsignedp_ptr
= uns
;
6439 /* Nonzero if integer constant C has a value that is permissible
6440 for type TYPE (an INTEGER_TYPE). */
6443 int_fits_type_p (const_tree c
, const_tree type
)
6445 tree type_low_bound
, type_high_bound
;
6446 bool ok_for_low_bound
, ok_for_high_bound
, unsc
;
6449 dc
= tree_to_double_int (c
);
6450 unsc
= TYPE_UNSIGNED (TREE_TYPE (c
));
6452 if (TREE_CODE (TREE_TYPE (c
)) == INTEGER_TYPE
6453 && TYPE_IS_SIZETYPE (TREE_TYPE (c
))
6455 /* So c is an unsigned integer whose type is sizetype and type is not.
6456 sizetype'd integers are sign extended even though they are
6457 unsigned. If the integer value fits in the lower end word of c,
6458 and if the higher end word has all its bits set to 1, that
6459 means the higher end bits are set to 1 only for sign extension.
6460 So let's convert c into an equivalent zero extended unsigned
6462 dc
= double_int_zext (dc
, TYPE_PRECISION (TREE_TYPE (c
)));
6465 type_low_bound
= TYPE_MIN_VALUE (type
);
6466 type_high_bound
= TYPE_MAX_VALUE (type
);
6468 /* If at least one bound of the type is a constant integer, we can check
6469 ourselves and maybe make a decision. If no such decision is possible, but
6470 this type is a subtype, try checking against that. Otherwise, use
6471 fit_double_type, which checks against the precision.
6473 Compute the status for each possibly constant bound, and return if we see
6474 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
6475 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
6476 for "constant known to fit". */
6478 /* Check if c >= type_low_bound. */
6479 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
6481 dd
= tree_to_double_int (type_low_bound
);
6482 if (TREE_CODE (type
) == INTEGER_TYPE
6483 && TYPE_IS_SIZETYPE (type
)
6484 && TYPE_UNSIGNED (type
))
6485 dd
= double_int_zext (dd
, TYPE_PRECISION (type
));
6486 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_low_bound
)))
6488 int c_neg
= (!unsc
&& double_int_negative_p (dc
));
6489 int t_neg
= (unsc
&& double_int_negative_p (dd
));
6491 if (c_neg
&& !t_neg
)
6493 if ((c_neg
|| !t_neg
) && double_int_ucmp (dc
, dd
) < 0)
6496 else if (double_int_cmp (dc
, dd
, unsc
) < 0)
6498 ok_for_low_bound
= true;
6501 ok_for_low_bound
= false;
6503 /* Check if c <= type_high_bound. */
6504 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
6506 dd
= tree_to_double_int (type_high_bound
);
6507 if (TREE_CODE (type
) == INTEGER_TYPE
6508 && TYPE_IS_SIZETYPE (type
)
6509 && TYPE_UNSIGNED (type
))
6510 dd
= double_int_zext (dd
, TYPE_PRECISION (type
));
6511 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_high_bound
)))
6513 int c_neg
= (!unsc
&& double_int_negative_p (dc
));
6514 int t_neg
= (unsc
&& double_int_negative_p (dd
));
6516 if (t_neg
&& !c_neg
)
6518 if ((t_neg
|| !c_neg
) && double_int_ucmp (dc
, dd
) > 0)
6521 else if (double_int_cmp (dc
, dd
, unsc
) > 0)
6523 ok_for_high_bound
= true;
6526 ok_for_high_bound
= false;
6528 /* If the constant fits both bounds, the result is known. */
6529 if (ok_for_low_bound
&& ok_for_high_bound
)
6532 /* Perform some generic filtering which may allow making a decision
6533 even if the bounds are not constant. First, negative integers
6534 never fit in unsigned types, */
6535 if (TYPE_UNSIGNED (type
) && !unsc
&& double_int_negative_p (dc
))
6538 /* Second, narrower types always fit in wider ones. */
6539 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
6542 /* Third, unsigned integers with top bit set never fit signed types. */
6543 if (! TYPE_UNSIGNED (type
) && unsc
)
6545 int prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (c
))) - 1;
6546 if (prec
< HOST_BITS_PER_WIDE_INT
)
6548 if (((((unsigned HOST_WIDE_INT
) 1) << prec
) & dc
.low
) != 0)
6551 else if (((((unsigned HOST_WIDE_INT
) 1)
6552 << (prec
- HOST_BITS_PER_WIDE_INT
)) & dc
.high
) != 0)
6556 /* If we haven't been able to decide at this point, there nothing more we
6557 can check ourselves here. Look at the base type if we have one and it
6558 has the same precision. */
6559 if (TREE_CODE (type
) == INTEGER_TYPE
6560 && TREE_TYPE (type
) != 0
6561 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
6563 type
= TREE_TYPE (type
);
6567 /* Or to fit_double_type, if nothing else. */
6568 return !fit_double_type (dc
.low
, dc
.high
, &dc
.low
, &dc
.high
, type
);
6571 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
6572 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
6573 represented (assuming two's-complement arithmetic) within the bit
6574 precision of the type are returned instead. */
6577 get_type_static_bounds (const_tree type
, mpz_t min
, mpz_t max
)
6579 if (!POINTER_TYPE_P (type
) && TYPE_MIN_VALUE (type
)
6580 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
6581 mpz_set_double_int (min
, tree_to_double_int (TYPE_MIN_VALUE (type
)),
6582 TYPE_UNSIGNED (type
));
6585 if (TYPE_UNSIGNED (type
))
6586 mpz_set_ui (min
, 0);
6590 mn
= double_int_mask (TYPE_PRECISION (type
) - 1);
6591 mn
= double_int_sext (double_int_add (mn
, double_int_one
),
6592 TYPE_PRECISION (type
));
6593 mpz_set_double_int (min
, mn
, false);
6597 if (!POINTER_TYPE_P (type
) && TYPE_MAX_VALUE (type
)
6598 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
)
6599 mpz_set_double_int (max
, tree_to_double_int (TYPE_MAX_VALUE (type
)),
6600 TYPE_UNSIGNED (type
));
6603 if (TYPE_UNSIGNED (type
))
6604 mpz_set_double_int (max
, double_int_mask (TYPE_PRECISION (type
)),
6607 mpz_set_double_int (max
, double_int_mask (TYPE_PRECISION (type
) - 1),
6612 /* Return true if VAR is an automatic variable defined in function FN. */
6615 auto_var_in_fn_p (const_tree var
, const_tree fn
)
6617 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
6618 && (((TREE_CODE (var
) == VAR_DECL
|| TREE_CODE (var
) == PARM_DECL
)
6619 && ! TREE_STATIC (var
))
6620 || TREE_CODE (var
) == LABEL_DECL
6621 || TREE_CODE (var
) == RESULT_DECL
));
6624 /* Subprogram of following function. Called by walk_tree.
6626 Return *TP if it is an automatic variable or parameter of the
6627 function passed in as DATA. */
6630 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
6632 tree fn
= (tree
) data
;
6637 else if (DECL_P (*tp
)
6638 && auto_var_in_fn_p (*tp
, fn
))
6644 /* Returns true if T is, contains, or refers to a type with variable
6645 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
6646 arguments, but not the return type. If FN is nonzero, only return
6647 true if a modifier of the type or position of FN is a variable or
6648 parameter inside FN.
6650 This concept is more general than that of C99 'variably modified types':
6651 in C99, a struct type is never variably modified because a VLA may not
6652 appear as a structure member. However, in GNU C code like:
6654 struct S { int i[f()]; };
6656 is valid, and other languages may define similar constructs. */
6659 variably_modified_type_p (tree type
, tree fn
)
6663 /* Test if T is either variable (if FN is zero) or an expression containing
6664 a variable in FN. */
6665 #define RETURN_TRUE_IF_VAR(T) \
6666 do { tree _t = (T); \
6667 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
6668 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
6669 return true; } while (0)
6671 if (type
== error_mark_node
)
6674 /* If TYPE itself has variable size, it is variably modified. */
6675 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
6676 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
6678 switch (TREE_CODE (type
))
6681 case REFERENCE_TYPE
:
6683 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
6689 /* If TYPE is a function type, it is variably modified if the
6690 return type is variably modified. */
6691 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
6697 case FIXED_POINT_TYPE
:
6700 /* Scalar types are variably modified if their end points
6702 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
6703 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
6708 case QUAL_UNION_TYPE
:
6709 /* We can't see if any of the fields are variably-modified by the
6710 definition we normally use, since that would produce infinite
6711 recursion via pointers. */
6712 /* This is variably modified if some field's type is. */
6713 for (t
= TYPE_FIELDS (type
); t
; t
= TREE_CHAIN (t
))
6714 if (TREE_CODE (t
) == FIELD_DECL
)
6716 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
6717 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
6718 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
6720 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
6721 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
6726 /* Do not call ourselves to avoid infinite recursion. This is
6727 variably modified if the element type is. */
6728 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
6729 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
6736 /* The current language may have other cases to check, but in general,
6737 all other types are not variably modified. */
6738 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
6740 #undef RETURN_TRUE_IF_VAR
6743 /* Given a DECL or TYPE, return the scope in which it was declared, or
6744 NULL_TREE if there is no containing scope. */
6747 get_containing_scope (const_tree t
)
6749 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
6752 /* Return the innermost context enclosing DECL that is
6753 a FUNCTION_DECL, or zero if none. */
6756 decl_function_context (const_tree decl
)
6760 if (TREE_CODE (decl
) == ERROR_MARK
)
6763 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
6764 where we look up the function at runtime. Such functions always take
6765 a first argument of type 'pointer to real context'.
6767 C++ should really be fixed to use DECL_CONTEXT for the real context,
6768 and use something else for the "virtual context". */
6769 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
6772 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
6774 context
= DECL_CONTEXT (decl
);
6776 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
6778 if (TREE_CODE (context
) == BLOCK
)
6779 context
= BLOCK_SUPERCONTEXT (context
);
6781 context
= get_containing_scope (context
);
6787 /* Return the innermost context enclosing DECL that is
6788 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
6789 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
6792 decl_type_context (const_tree decl
)
6794 tree context
= DECL_CONTEXT (decl
);
6797 switch (TREE_CODE (context
))
6799 case NAMESPACE_DECL
:
6800 case TRANSLATION_UNIT_DECL
:
6805 case QUAL_UNION_TYPE
:
6810 context
= DECL_CONTEXT (context
);
6814 context
= BLOCK_SUPERCONTEXT (context
);
6824 /* CALL is a CALL_EXPR. Return the declaration for the function
6825 called, or NULL_TREE if the called function cannot be
6829 get_callee_fndecl (const_tree call
)
6833 if (call
== error_mark_node
)
6834 return error_mark_node
;
6836 /* It's invalid to call this function with anything but a
6838 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
6840 /* The first operand to the CALL is the address of the function
6842 addr
= CALL_EXPR_FN (call
);
6846 /* If this is a readonly function pointer, extract its initial value. */
6847 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
6848 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
6849 && DECL_INITIAL (addr
))
6850 addr
= DECL_INITIAL (addr
);
6852 /* If the address is just `&f' for some function `f', then we know
6853 that `f' is being called. */
6854 if (TREE_CODE (addr
) == ADDR_EXPR
6855 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
6856 return TREE_OPERAND (addr
, 0);
6858 /* We couldn't figure out what was being called. */
6862 /* Print debugging information about tree nodes generated during the compile,
6863 and any language-specific information. */
6866 dump_tree_statistics (void)
6868 #ifdef GATHER_STATISTICS
6870 int total_nodes
, total_bytes
;
6873 fprintf (stderr
, "\n??? tree nodes created\n\n");
6874 #ifdef GATHER_STATISTICS
6875 fprintf (stderr
, "Kind Nodes Bytes\n");
6876 fprintf (stderr
, "---------------------------------------\n");
6877 total_nodes
= total_bytes
= 0;
6878 for (i
= 0; i
< (int) all_kinds
; i
++)
6880 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
6881 tree_node_counts
[i
], tree_node_sizes
[i
]);
6882 total_nodes
+= tree_node_counts
[i
];
6883 total_bytes
+= tree_node_sizes
[i
];
6885 fprintf (stderr
, "---------------------------------------\n");
6886 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
6887 fprintf (stderr
, "---------------------------------------\n");
6888 ssanames_print_statistics ();
6889 phinodes_print_statistics ();
6891 fprintf (stderr
, "(No per-node statistics)\n");
6893 print_type_hash_statistics ();
6894 print_debug_expr_statistics ();
6895 print_value_expr_statistics ();
6896 print_restrict_base_statistics ();
6897 lang_hooks
.print_statistics ();
6900 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
6902 /* Generate a crc32 of a string. */
6905 crc32_string (unsigned chksum
, const char *string
)
6909 unsigned value
= *string
<< 24;
6912 for (ix
= 8; ix
--; value
<<= 1)
6916 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
6925 /* P is a string that will be used in a symbol. Mask out any characters
6926 that are not valid in that context. */
6929 clean_symbol_name (char *p
)
6933 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
6936 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
6943 /* Generate a name for a special-purpose function function.
6944 The generated name may need to be unique across the whole link.
6945 TYPE is some string to identify the purpose of this function to the
6946 linker or collect2; it must start with an uppercase letter,
6948 I - for constructors
6950 N - for C++ anonymous namespaces
6951 F - for DWARF unwind frame information. */
6954 get_file_function_name (const char *type
)
6960 /* If we already have a name we know to be unique, just use that. */
6961 if (first_global_object_name
)
6962 p
= q
= ASTRDUP (first_global_object_name
);
6963 /* If the target is handling the constructors/destructors, they
6964 will be local to this file and the name is only necessary for
6965 debugging purposes. */
6966 else if ((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
6968 const char *file
= main_input_filename
;
6970 file
= input_filename
;
6971 /* Just use the file's basename, because the full pathname
6972 might be quite long. */
6973 p
= strrchr (file
, '/');
6978 p
= q
= ASTRDUP (p
);
6982 /* Otherwise, the name must be unique across the entire link.
6983 We don't have anything that we know to be unique to this translation
6984 unit, so use what we do have and throw in some randomness. */
6986 const char *name
= weak_global_object_name
;
6987 const char *file
= main_input_filename
;
6992 file
= input_filename
;
6994 len
= strlen (file
);
6995 q
= (char *) alloca (9 * 2 + len
+ 1);
6996 memcpy (q
, file
, len
+ 1);
6998 sprintf (q
+ len
, "_%08X_%08X", crc32_string (0, name
),
6999 crc32_string (0, get_random_seed (false)));
7004 clean_symbol_name (q
);
7005 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
)
7008 /* Set up the name of the file-level functions we may need.
7009 Use a global object (which is already required to be unique over
7010 the program) rather than the file name (which imposes extra
7012 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
7014 return get_identifier (buf
);
7017 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
7019 /* Complain that the tree code of NODE does not match the expected 0
7020 terminated list of trailing codes. The trailing code list can be
7021 empty, for a more vague error message. FILE, LINE, and FUNCTION
7022 are of the caller. */
7025 tree_check_failed (const_tree node
, const char *file
,
7026 int line
, const char *function
, ...)
7030 unsigned length
= 0;
7033 va_start (args
, function
);
7034 while ((code
= va_arg (args
, int)))
7035 length
+= 4 + strlen (tree_code_name
[code
]);
7040 va_start (args
, function
);
7041 length
+= strlen ("expected ");
7042 buffer
= tmp
= (char *) alloca (length
);
7044 while ((code
= va_arg (args
, int)))
7046 const char *prefix
= length
? " or " : "expected ";
7048 strcpy (tmp
+ length
, prefix
);
7049 length
+= strlen (prefix
);
7050 strcpy (tmp
+ length
, tree_code_name
[code
]);
7051 length
+= strlen (tree_code_name
[code
]);
7056 buffer
= "unexpected node";
7058 internal_error ("tree check: %s, have %s in %s, at %s:%d",
7059 buffer
, tree_code_name
[TREE_CODE (node
)],
7060 function
, trim_filename (file
), line
);
7063 /* Complain that the tree code of NODE does match the expected 0
7064 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
7068 tree_not_check_failed (const_tree node
, const char *file
,
7069 int line
, const char *function
, ...)
7073 unsigned length
= 0;
7076 va_start (args
, function
);
7077 while ((code
= va_arg (args
, int)))
7078 length
+= 4 + strlen (tree_code_name
[code
]);
7080 va_start (args
, function
);
7081 buffer
= (char *) alloca (length
);
7083 while ((code
= va_arg (args
, int)))
7087 strcpy (buffer
+ length
, " or ");
7090 strcpy (buffer
+ length
, tree_code_name
[code
]);
7091 length
+= strlen (tree_code_name
[code
]);
7095 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
7096 buffer
, tree_code_name
[TREE_CODE (node
)],
7097 function
, trim_filename (file
), line
);
7100 /* Similar to tree_check_failed, except that we check for a class of tree
7101 code, given in CL. */
7104 tree_class_check_failed (const_tree node
, const enum tree_code_class cl
,
7105 const char *file
, int line
, const char *function
)
7108 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
7109 TREE_CODE_CLASS_STRING (cl
),
7110 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
7111 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
7114 /* Similar to tree_check_failed, except that instead of specifying a
7115 dozen codes, use the knowledge that they're all sequential. */
7118 tree_range_check_failed (const_tree node
, const char *file
, int line
,
7119 const char *function
, enum tree_code c1
,
7123 unsigned length
= 0;
7126 for (c
= c1
; c
<= c2
; ++c
)
7127 length
+= 4 + strlen (tree_code_name
[c
]);
7129 length
+= strlen ("expected ");
7130 buffer
= (char *) alloca (length
);
7133 for (c
= c1
; c
<= c2
; ++c
)
7135 const char *prefix
= length
? " or " : "expected ";
7137 strcpy (buffer
+ length
, prefix
);
7138 length
+= strlen (prefix
);
7139 strcpy (buffer
+ length
, tree_code_name
[c
]);
7140 length
+= strlen (tree_code_name
[c
]);
7143 internal_error ("tree check: %s, have %s in %s, at %s:%d",
7144 buffer
, tree_code_name
[TREE_CODE (node
)],
7145 function
, trim_filename (file
), line
);
7149 /* Similar to tree_check_failed, except that we check that a tree does
7150 not have the specified code, given in CL. */
7153 tree_not_class_check_failed (const_tree node
, const enum tree_code_class cl
,
7154 const char *file
, int line
, const char *function
)
7157 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
7158 TREE_CODE_CLASS_STRING (cl
),
7159 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
7160 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
7164 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
7167 omp_clause_check_failed (const_tree node
, const char *file
, int line
,
7168 const char *function
, enum omp_clause_code code
)
7170 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
7171 omp_clause_code_name
[code
], tree_code_name
[TREE_CODE (node
)],
7172 function
, trim_filename (file
), line
);
7176 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
7179 omp_clause_range_check_failed (const_tree node
, const char *file
, int line
,
7180 const char *function
, enum omp_clause_code c1
,
7181 enum omp_clause_code c2
)
7184 unsigned length
= 0;
7185 enum omp_clause_code c
;
7187 for (c
= c1
; c
<= c2
; ++c
)
7188 length
+= 4 + strlen (omp_clause_code_name
[c
]);
7190 length
+= strlen ("expected ");
7191 buffer
= (char *) alloca (length
);
7194 for (c
= c1
; c
<= c2
; ++c
)
7196 const char *prefix
= length
? " or " : "expected ";
7198 strcpy (buffer
+ length
, prefix
);
7199 length
+= strlen (prefix
);
7200 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
7201 length
+= strlen (omp_clause_code_name
[c
]);
7204 internal_error ("tree check: %s, have %s in %s, at %s:%d",
7205 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
7206 function
, trim_filename (file
), line
);
7210 #undef DEFTREESTRUCT
7211 #define DEFTREESTRUCT(VAL, NAME) NAME,
7213 static const char *ts_enum_names
[] = {
7214 #include "treestruct.def"
7216 #undef DEFTREESTRUCT
7218 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
7220 /* Similar to tree_class_check_failed, except that we check for
7221 whether CODE contains the tree structure identified by EN. */
7224 tree_contains_struct_check_failed (const_tree node
,
7225 const enum tree_node_structure_enum en
,
7226 const char *file
, int line
,
7227 const char *function
)
7230 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
7232 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
7236 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
7237 (dynamically sized) vector. */
7240 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
7241 const char *function
)
7244 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
7245 idx
+ 1, len
, function
, trim_filename (file
), line
);
7248 /* Similar to above, except that the check is for the bounds of the operand
7249 vector of an expression node EXP. */
7252 tree_operand_check_failed (int idx
, const_tree exp
, const char *file
,
7253 int line
, const char *function
)
7255 int code
= TREE_CODE (exp
);
7257 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
7258 idx
+ 1, tree_code_name
[code
], TREE_OPERAND_LENGTH (exp
),
7259 function
, trim_filename (file
), line
);
7262 /* Similar to above, except that the check is for the number of
7263 operands of an OMP_CLAUSE node. */
7266 omp_clause_operand_check_failed (int idx
, const_tree t
, const char *file
,
7267 int line
, const char *function
)
7270 ("tree check: accessed operand %d of omp_clause %s with %d operands "
7271 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
7272 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
7273 trim_filename (file
), line
);
7275 #endif /* ENABLE_TREE_CHECKING */
7277 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
7278 and mapped to the machine mode MODE. Initialize its fields and build
7279 the information necessary for debugging output. */
7282 make_vector_type (tree innertype
, int nunits
, enum machine_mode mode
)
7285 hashval_t hashcode
= 0;
7287 /* Build a main variant, based on the main variant of the inner type, then
7288 use it to build the variant we return. */
7289 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
7290 && TYPE_MAIN_VARIANT (innertype
) != innertype
)
7291 return build_type_attribute_qual_variant (
7292 make_vector_type (TYPE_MAIN_VARIANT (innertype
), nunits
, mode
),
7293 TYPE_ATTRIBUTES (innertype
),
7294 TYPE_QUALS (innertype
));
7296 t
= make_node (VECTOR_TYPE
);
7297 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
7298 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
7299 SET_TYPE_MODE (t
, mode
);
7300 TYPE_READONLY (t
) = TYPE_READONLY (innertype
);
7301 TYPE_VOLATILE (t
) = TYPE_VOLATILE (innertype
);
7303 if (TYPE_STRUCTURAL_EQUALITY_P (innertype
))
7304 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7305 else if (TYPE_CANONICAL (innertype
) != innertype
7306 || mode
!= VOIDmode
)
7308 = make_vector_type (TYPE_CANONICAL (innertype
), nunits
, VOIDmode
);
7313 tree index
= build_int_cst (NULL_TREE
, nunits
- 1);
7314 tree array
= build_array_type (innertype
, build_index_type (index
));
7315 tree rt
= make_node (RECORD_TYPE
);
7317 TYPE_FIELDS (rt
) = build_decl (FIELD_DECL
, get_identifier ("f"), array
);
7318 DECL_CONTEXT (TYPE_FIELDS (rt
)) = rt
;
7320 TYPE_DEBUG_REPRESENTATION_TYPE (t
) = rt
;
7321 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
7322 the representation type, and we want to find that die when looking up
7323 the vector type. This is most easily achieved by making the TYPE_UID
7325 TYPE_UID (rt
) = TYPE_UID (t
);
7328 hashcode
= iterative_hash_host_wide_int (VECTOR_TYPE
, hashcode
);
7329 hashcode
= iterative_hash_host_wide_int (mode
, hashcode
);
7330 hashcode
= iterative_hash_object (TYPE_HASH (innertype
), hashcode
);
7331 return type_hash_canon (hashcode
, t
);
7335 make_or_reuse_type (unsigned size
, int unsignedp
)
7337 if (size
== INT_TYPE_SIZE
)
7338 return unsignedp
? unsigned_type_node
: integer_type_node
;
7339 if (size
== CHAR_TYPE_SIZE
)
7340 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
7341 if (size
== SHORT_TYPE_SIZE
)
7342 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
7343 if (size
== LONG_TYPE_SIZE
)
7344 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
7345 if (size
== LONG_LONG_TYPE_SIZE
)
7346 return (unsignedp
? long_long_unsigned_type_node
7347 : long_long_integer_type_node
);
7350 return make_unsigned_type (size
);
7352 return make_signed_type (size
);
7355 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
7358 make_or_reuse_fract_type (unsigned size
, int unsignedp
, int satp
)
7362 if (size
== SHORT_FRACT_TYPE_SIZE
)
7363 return unsignedp
? sat_unsigned_short_fract_type_node
7364 : sat_short_fract_type_node
;
7365 if (size
== FRACT_TYPE_SIZE
)
7366 return unsignedp
? sat_unsigned_fract_type_node
: sat_fract_type_node
;
7367 if (size
== LONG_FRACT_TYPE_SIZE
)
7368 return unsignedp
? sat_unsigned_long_fract_type_node
7369 : sat_long_fract_type_node
;
7370 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
7371 return unsignedp
? sat_unsigned_long_long_fract_type_node
7372 : sat_long_long_fract_type_node
;
7376 if (size
== SHORT_FRACT_TYPE_SIZE
)
7377 return unsignedp
? unsigned_short_fract_type_node
7378 : short_fract_type_node
;
7379 if (size
== FRACT_TYPE_SIZE
)
7380 return unsignedp
? unsigned_fract_type_node
: fract_type_node
;
7381 if (size
== LONG_FRACT_TYPE_SIZE
)
7382 return unsignedp
? unsigned_long_fract_type_node
7383 : long_fract_type_node
;
7384 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
7385 return unsignedp
? unsigned_long_long_fract_type_node
7386 : long_long_fract_type_node
;
7389 return make_fract_type (size
, unsignedp
, satp
);
7392 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
7395 make_or_reuse_accum_type (unsigned size
, int unsignedp
, int satp
)
7399 if (size
== SHORT_ACCUM_TYPE_SIZE
)
7400 return unsignedp
? sat_unsigned_short_accum_type_node
7401 : sat_short_accum_type_node
;
7402 if (size
== ACCUM_TYPE_SIZE
)
7403 return unsignedp
? sat_unsigned_accum_type_node
: sat_accum_type_node
;
7404 if (size
== LONG_ACCUM_TYPE_SIZE
)
7405 return unsignedp
? sat_unsigned_long_accum_type_node
7406 : sat_long_accum_type_node
;
7407 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
7408 return unsignedp
? sat_unsigned_long_long_accum_type_node
7409 : sat_long_long_accum_type_node
;
7413 if (size
== SHORT_ACCUM_TYPE_SIZE
)
7414 return unsignedp
? unsigned_short_accum_type_node
7415 : short_accum_type_node
;
7416 if (size
== ACCUM_TYPE_SIZE
)
7417 return unsignedp
? unsigned_accum_type_node
: accum_type_node
;
7418 if (size
== LONG_ACCUM_TYPE_SIZE
)
7419 return unsignedp
? unsigned_long_accum_type_node
7420 : long_accum_type_node
;
7421 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
7422 return unsignedp
? unsigned_long_long_accum_type_node
7423 : long_long_accum_type_node
;
7426 return make_accum_type (size
, unsignedp
, satp
);
7429 /* Create nodes for all integer types (and error_mark_node) using the sizes
7430 of C datatypes. The caller should call set_sizetype soon after calling
7431 this function to select one of the types as sizetype. */
7434 build_common_tree_nodes (bool signed_char
, bool signed_sizetype
)
7436 error_mark_node
= make_node (ERROR_MARK
);
7437 TREE_TYPE (error_mark_node
) = error_mark_node
;
7439 initialize_sizetypes (signed_sizetype
);
7441 /* Define both `signed char' and `unsigned char'. */
7442 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
7443 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
7444 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
7445 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
7447 /* Define `char', which is like either `signed char' or `unsigned char'
7448 but not the same as either. */
7451 ? make_signed_type (CHAR_TYPE_SIZE
)
7452 : make_unsigned_type (CHAR_TYPE_SIZE
));
7453 TYPE_STRING_FLAG (char_type_node
) = 1;
7455 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
7456 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
7457 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
7458 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
7459 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
7460 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
7461 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
7462 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
7464 /* Define a boolean type. This type only represents boolean values but
7465 may be larger than char depending on the value of BOOL_TYPE_SIZE.
7466 Front ends which want to override this size (i.e. Java) can redefine
7467 boolean_type_node before calling build_common_tree_nodes_2. */
7468 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
7469 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
7470 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
7471 TYPE_PRECISION (boolean_type_node
) = 1;
7473 /* Fill in the rest of the sized types. Reuse existing type nodes
7475 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
7476 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
7477 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
7478 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
7479 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
7481 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
7482 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
7483 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
7484 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
7485 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
7487 access_public_node
= get_identifier ("public");
7488 access_protected_node
= get_identifier ("protected");
7489 access_private_node
= get_identifier ("private");
7492 /* Call this function after calling build_common_tree_nodes and set_sizetype.
7493 It will create several other common tree nodes. */
7496 build_common_tree_nodes_2 (int short_double
)
7498 /* Define these next since types below may used them. */
7499 integer_zero_node
= build_int_cst (NULL_TREE
, 0);
7500 integer_one_node
= build_int_cst (NULL_TREE
, 1);
7501 integer_minus_one_node
= build_int_cst (NULL_TREE
, -1);
7503 size_zero_node
= size_int (0);
7504 size_one_node
= size_int (1);
7505 bitsize_zero_node
= bitsize_int (0);
7506 bitsize_one_node
= bitsize_int (1);
7507 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
7509 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
7510 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
7512 void_type_node
= make_node (VOID_TYPE
);
7513 layout_type (void_type_node
);
7515 /* We are not going to have real types in C with less than byte alignment,
7516 so we might as well not have any types that claim to have it. */
7517 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
7518 TYPE_USER_ALIGN (void_type_node
) = 0;
7520 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
7521 layout_type (TREE_TYPE (null_pointer_node
));
7523 ptr_type_node
= build_pointer_type (void_type_node
);
7525 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
7526 fileptr_type_node
= ptr_type_node
;
7528 float_type_node
= make_node (REAL_TYPE
);
7529 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
7530 layout_type (float_type_node
);
7532 double_type_node
= make_node (REAL_TYPE
);
7534 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
7536 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
7537 layout_type (double_type_node
);
7539 long_double_type_node
= make_node (REAL_TYPE
);
7540 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
7541 layout_type (long_double_type_node
);
7543 float_ptr_type_node
= build_pointer_type (float_type_node
);
7544 double_ptr_type_node
= build_pointer_type (double_type_node
);
7545 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
7546 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
7548 /* Fixed size integer types. */
7549 uint32_type_node
= build_nonstandard_integer_type (32, true);
7550 uint64_type_node
= build_nonstandard_integer_type (64, true);
7552 /* Decimal float types. */
7553 dfloat32_type_node
= make_node (REAL_TYPE
);
7554 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
7555 layout_type (dfloat32_type_node
);
7556 SET_TYPE_MODE (dfloat32_type_node
, SDmode
);
7557 dfloat32_ptr_type_node
= build_pointer_type (dfloat32_type_node
);
7559 dfloat64_type_node
= make_node (REAL_TYPE
);
7560 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
7561 layout_type (dfloat64_type_node
);
7562 SET_TYPE_MODE (dfloat64_type_node
, DDmode
);
7563 dfloat64_ptr_type_node
= build_pointer_type (dfloat64_type_node
);
7565 dfloat128_type_node
= make_node (REAL_TYPE
);
7566 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
7567 layout_type (dfloat128_type_node
);
7568 SET_TYPE_MODE (dfloat128_type_node
, TDmode
);
7569 dfloat128_ptr_type_node
= build_pointer_type (dfloat128_type_node
);
7571 complex_integer_type_node
= build_complex_type (integer_type_node
);
7572 complex_float_type_node
= build_complex_type (float_type_node
);
7573 complex_double_type_node
= build_complex_type (double_type_node
);
7574 complex_long_double_type_node
= build_complex_type (long_double_type_node
);
7576 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
7577 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
7578 sat_ ## KIND ## _type_node = \
7579 make_sat_signed_ ## KIND ## _type (SIZE); \
7580 sat_unsigned_ ## KIND ## _type_node = \
7581 make_sat_unsigned_ ## KIND ## _type (SIZE); \
7582 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
7583 unsigned_ ## KIND ## _type_node = \
7584 make_unsigned_ ## KIND ## _type (SIZE);
7586 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
7587 sat_ ## WIDTH ## KIND ## _type_node = \
7588 make_sat_signed_ ## KIND ## _type (SIZE); \
7589 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
7590 make_sat_unsigned_ ## KIND ## _type (SIZE); \
7591 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
7592 unsigned_ ## WIDTH ## KIND ## _type_node = \
7593 make_unsigned_ ## KIND ## _type (SIZE);
7595 /* Make fixed-point type nodes based on four different widths. */
7596 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
7597 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
7598 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
7599 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
7600 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
7602 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
7603 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
7604 NAME ## _type_node = \
7605 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
7606 u ## NAME ## _type_node = \
7607 make_or_reuse_unsigned_ ## KIND ## _type \
7608 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
7609 sat_ ## NAME ## _type_node = \
7610 make_or_reuse_sat_signed_ ## KIND ## _type \
7611 (GET_MODE_BITSIZE (MODE ## mode)); \
7612 sat_u ## NAME ## _type_node = \
7613 make_or_reuse_sat_unsigned_ ## KIND ## _type \
7614 (GET_MODE_BITSIZE (U ## MODE ## mode));
7616 /* Fixed-point type and mode nodes. */
7617 MAKE_FIXED_TYPE_NODE_FAMILY (fract
, FRACT
)
7618 MAKE_FIXED_TYPE_NODE_FAMILY (accum
, ACCUM
)
7619 MAKE_FIXED_MODE_NODE (fract
, qq
, QQ
)
7620 MAKE_FIXED_MODE_NODE (fract
, hq
, HQ
)
7621 MAKE_FIXED_MODE_NODE (fract
, sq
, SQ
)
7622 MAKE_FIXED_MODE_NODE (fract
, dq
, DQ
)
7623 MAKE_FIXED_MODE_NODE (fract
, tq
, TQ
)
7624 MAKE_FIXED_MODE_NODE (accum
, ha
, HA
)
7625 MAKE_FIXED_MODE_NODE (accum
, sa
, SA
)
7626 MAKE_FIXED_MODE_NODE (accum
, da
, DA
)
7627 MAKE_FIXED_MODE_NODE (accum
, ta
, TA
)
7630 tree t
= targetm
.build_builtin_va_list ();
7632 /* Many back-ends define record types without setting TYPE_NAME.
7633 If we copied the record type here, we'd keep the original
7634 record type without a name. This breaks name mangling. So,
7635 don't copy record types and let c_common_nodes_and_builtins()
7636 declare the type to be __builtin_va_list. */
7637 if (TREE_CODE (t
) != RECORD_TYPE
)
7638 t
= build_variant_type_copy (t
);
7640 va_list_type_node
= t
;
7644 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
7647 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
7648 const char *library_name
, int ecf_flags
)
7652 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
7653 library_name
, NULL_TREE
);
7654 if (ecf_flags
& ECF_CONST
)
7655 TREE_READONLY (decl
) = 1;
7656 if (ecf_flags
& ECF_PURE
)
7657 DECL_PURE_P (decl
) = 1;
7658 if (ecf_flags
& ECF_LOOPING_CONST_OR_PURE
)
7659 DECL_LOOPING_CONST_OR_PURE_P (decl
) = 1;
7660 if (ecf_flags
& ECF_NORETURN
)
7661 TREE_THIS_VOLATILE (decl
) = 1;
7662 if (ecf_flags
& ECF_NOTHROW
)
7663 TREE_NOTHROW (decl
) = 1;
7664 if (ecf_flags
& ECF_MALLOC
)
7665 DECL_IS_MALLOC (decl
) = 1;
7667 built_in_decls
[code
] = decl
;
7668 implicit_built_in_decls
[code
] = decl
;
7671 /* Call this function after instantiating all builtins that the language
7672 front end cares about. This will build the rest of the builtins that
7673 are relied upon by the tree optimizers and the middle-end. */
7676 build_common_builtin_nodes (void)
7680 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
7681 || built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
7683 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7684 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7685 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7686 ftype
= build_function_type (ptr_type_node
, tmp
);
7688 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
)
7689 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
7690 "memcpy", ECF_NOTHROW
);
7691 if (built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
7692 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
7693 "memmove", ECF_NOTHROW
);
7696 if (built_in_decls
[BUILT_IN_MEMCMP
] == NULL
)
7698 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7699 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7700 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7701 ftype
= build_function_type (integer_type_node
, tmp
);
7702 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
7703 "memcmp", ECF_PURE
| ECF_NOTHROW
);
7706 if (built_in_decls
[BUILT_IN_MEMSET
] == NULL
)
7708 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7709 tmp
= tree_cons (NULL_TREE
, integer_type_node
, tmp
);
7710 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7711 ftype
= build_function_type (ptr_type_node
, tmp
);
7712 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
7713 "memset", ECF_NOTHROW
);
7716 if (built_in_decls
[BUILT_IN_ALLOCA
] == NULL
)
7718 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7719 ftype
= build_function_type (ptr_type_node
, tmp
);
7720 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
7721 "alloca", ECF_NOTHROW
| ECF_MALLOC
);
7724 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7725 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7726 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7727 ftype
= build_function_type (void_type_node
, tmp
);
7728 local_define_builtin ("__builtin_init_trampoline", ftype
,
7729 BUILT_IN_INIT_TRAMPOLINE
,
7730 "__builtin_init_trampoline", ECF_NOTHROW
);
7732 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7733 ftype
= build_function_type (ptr_type_node
, tmp
);
7734 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
7735 BUILT_IN_ADJUST_TRAMPOLINE
,
7736 "__builtin_adjust_trampoline",
7737 ECF_CONST
| ECF_NOTHROW
);
7739 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7740 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7741 ftype
= build_function_type (void_type_node
, tmp
);
7742 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
7743 BUILT_IN_NONLOCAL_GOTO
,
7744 "__builtin_nonlocal_goto",
7745 ECF_NORETURN
| ECF_NOTHROW
);
7747 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7748 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7749 ftype
= build_function_type (void_type_node
, tmp
);
7750 local_define_builtin ("__builtin_setjmp_setup", ftype
,
7751 BUILT_IN_SETJMP_SETUP
,
7752 "__builtin_setjmp_setup", ECF_NOTHROW
);
7754 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7755 ftype
= build_function_type (ptr_type_node
, tmp
);
7756 local_define_builtin ("__builtin_setjmp_dispatcher", ftype
,
7757 BUILT_IN_SETJMP_DISPATCHER
,
7758 "__builtin_setjmp_dispatcher",
7759 ECF_PURE
| ECF_NOTHROW
);
7761 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7762 ftype
= build_function_type (void_type_node
, tmp
);
7763 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
7764 BUILT_IN_SETJMP_RECEIVER
,
7765 "__builtin_setjmp_receiver", ECF_NOTHROW
);
7767 ftype
= build_function_type (ptr_type_node
, void_list_node
);
7768 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
7769 "__builtin_stack_save", ECF_NOTHROW
);
7771 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7772 ftype
= build_function_type (void_type_node
, tmp
);
7773 local_define_builtin ("__builtin_stack_restore", ftype
,
7774 BUILT_IN_STACK_RESTORE
,
7775 "__builtin_stack_restore", ECF_NOTHROW
);
7777 ftype
= build_function_type (void_type_node
, void_list_node
);
7778 local_define_builtin ("__builtin_profile_func_enter", ftype
,
7779 BUILT_IN_PROFILE_FUNC_ENTER
, "profile_func_enter", 0);
7780 local_define_builtin ("__builtin_profile_func_exit", ftype
,
7781 BUILT_IN_PROFILE_FUNC_EXIT
, "profile_func_exit", 0);
7783 /* Complex multiplication and division. These are handled as builtins
7784 rather than optabs because emit_library_call_value doesn't support
7785 complex. Further, we can do slightly better with folding these
7786 beasties if the real and complex parts of the arguments are separate. */
7788 enum machine_mode mode
;
7790 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
7792 char mode_name_buf
[4], *q
;
7794 enum built_in_function mcode
, dcode
;
7795 tree type
, inner_type
;
7797 type
= lang_hooks
.types
.type_for_mode (mode
, 0);
7800 inner_type
= TREE_TYPE (type
);
7802 tmp
= tree_cons (NULL_TREE
, inner_type
, void_list_node
);
7803 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
7804 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
7805 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
7806 ftype
= build_function_type (type
, tmp
);
7808 mcode
= BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
;
7809 dcode
= BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
;
7811 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
7815 built_in_names
[mcode
] = concat ("__mul", mode_name_buf
, "3", NULL
);
7816 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
7817 built_in_names
[mcode
], ECF_CONST
| ECF_NOTHROW
);
7819 built_in_names
[dcode
] = concat ("__div", mode_name_buf
, "3", NULL
);
7820 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
7821 built_in_names
[dcode
], ECF_CONST
| ECF_NOTHROW
);
7826 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
7829 If we requested a pointer to a vector, build up the pointers that
7830 we stripped off while looking for the inner type. Similarly for
7831 return values from functions.
7833 The argument TYPE is the top of the chain, and BOTTOM is the
7834 new type which we will point to. */
7837 reconstruct_complex_type (tree type
, tree bottom
)
7841 if (TREE_CODE (type
) == POINTER_TYPE
)
7843 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7844 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
7845 TYPE_REF_CAN_ALIAS_ALL (type
));
7847 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
7849 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7850 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
7851 TYPE_REF_CAN_ALIAS_ALL (type
));
7853 else if (TREE_CODE (type
) == ARRAY_TYPE
)
7855 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7856 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
7858 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
7860 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7861 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
7863 else if (TREE_CODE (type
) == METHOD_TYPE
)
7865 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7866 /* The build_method_type_directly() routine prepends 'this' to argument list,
7867 so we must compensate by getting rid of it. */
7869 = build_method_type_directly
7870 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type
))),
7872 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
7874 else if (TREE_CODE (type
) == OFFSET_TYPE
)
7876 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7877 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
7882 return build_qualified_type (outer
, TYPE_QUALS (type
));
7885 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
7888 build_vector_type_for_mode (tree innertype
, enum machine_mode mode
)
7892 switch (GET_MODE_CLASS (mode
))
7894 case MODE_VECTOR_INT
:
7895 case MODE_VECTOR_FLOAT
:
7896 case MODE_VECTOR_FRACT
:
7897 case MODE_VECTOR_UFRACT
:
7898 case MODE_VECTOR_ACCUM
:
7899 case MODE_VECTOR_UACCUM
:
7900 nunits
= GET_MODE_NUNITS (mode
);
7904 /* Check that there are no leftover bits. */
7905 gcc_assert (GET_MODE_BITSIZE (mode
)
7906 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
7908 nunits
= GET_MODE_BITSIZE (mode
)
7909 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
7916 return make_vector_type (innertype
, nunits
, mode
);
7919 /* Similarly, but takes the inner type and number of units, which must be
7923 build_vector_type (tree innertype
, int nunits
)
7925 return make_vector_type (innertype
, nunits
, VOIDmode
);
7929 /* Build RESX_EXPR with given REGION_NUMBER. */
7931 build_resx (int region_number
)
7934 t
= build1 (RESX_EXPR
, void_type_node
,
7935 build_int_cst (NULL_TREE
, region_number
));
7939 /* Given an initializer INIT, return TRUE if INIT is zero or some
7940 aggregate of zeros. Otherwise return FALSE. */
7942 initializer_zerop (const_tree init
)
7948 switch (TREE_CODE (init
))
7951 return integer_zerop (init
);
7954 /* ??? Note that this is not correct for C4X float formats. There,
7955 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
7956 negative exponent. */
7957 return real_zerop (init
)
7958 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
7961 return fixed_zerop (init
);
7964 return integer_zerop (init
)
7965 || (real_zerop (init
)
7966 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
7967 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
7970 for (elt
= TREE_VECTOR_CST_ELTS (init
); elt
; elt
= TREE_CHAIN (elt
))
7971 if (!initializer_zerop (TREE_VALUE (elt
)))
7977 unsigned HOST_WIDE_INT idx
;
7979 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
7980 if (!initializer_zerop (elt
))
7990 /* Build an empty statement. */
7993 build_empty_stmt (void)
7995 return build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
7999 /* Build an OpenMP clause with code CODE. */
8002 build_omp_clause (enum omp_clause_code code
)
8007 length
= omp_clause_num_ops
[code
];
8008 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
8010 t
= GGC_NEWVAR (union tree_node
, size
);
8011 memset (t
, 0, size
);
8012 TREE_SET_CODE (t
, OMP_CLAUSE
);
8013 OMP_CLAUSE_SET_CODE (t
, code
);
8015 #ifdef GATHER_STATISTICS
8016 tree_node_counts
[(int) omp_clause_kind
]++;
8017 tree_node_sizes
[(int) omp_clause_kind
] += size
;
8023 /* Set various status flags when building a CALL_EXPR object T. */
8026 process_call_operands (tree t
)
8030 side_effects
= TREE_SIDE_EFFECTS (t
);
8034 n
= TREE_OPERAND_LENGTH (t
);
8035 for (i
= 1; i
< n
; i
++)
8037 tree op
= TREE_OPERAND (t
, i
);
8038 if (op
&& TREE_SIDE_EFFECTS (op
))
8049 /* Calls have side-effects, except those to const or
8051 i
= call_expr_flags (t
);
8052 if ((i
& ECF_LOOPING_CONST_OR_PURE
) || !(i
& (ECF_CONST
| ECF_PURE
)))
8055 TREE_SIDE_EFFECTS (t
) = side_effects
;
8058 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
8059 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
8060 Except for the CODE and operand count field, other storage for the
8061 object is initialized to zeros. */
8064 build_vl_exp_stat (enum tree_code code
, int len MEM_STAT_DECL
)
8067 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_exp
);
8069 gcc_assert (TREE_CODE_CLASS (code
) == tcc_vl_exp
);
8070 gcc_assert (len
>= 1);
8072 #ifdef GATHER_STATISTICS
8073 tree_node_counts
[(int) e_kind
]++;
8074 tree_node_sizes
[(int) e_kind
] += length
;
8077 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
8079 memset (t
, 0, length
);
8081 TREE_SET_CODE (t
, code
);
8083 /* Can't use TREE_OPERAND to store the length because if checking is
8084 enabled, it will try to check the length before we store it. :-P */
8085 t
->exp
.operands
[0] = build_int_cst (sizetype
, len
);
8091 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE
8092 and FN and a null static chain slot. ARGLIST is a TREE_LIST of the
8096 build_call_list (tree return_type
, tree fn
, tree arglist
)
8101 t
= build_vl_exp (CALL_EXPR
, list_length (arglist
) + 3);
8102 TREE_TYPE (t
) = return_type
;
8103 CALL_EXPR_FN (t
) = fn
;
8104 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
8105 for (i
= 0; arglist
; arglist
= TREE_CHAIN (arglist
), i
++)
8106 CALL_EXPR_ARG (t
, i
) = TREE_VALUE (arglist
);
8107 process_call_operands (t
);
8111 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8112 FN and a null static chain slot. NARGS is the number of call arguments
8113 which are specified as "..." arguments. */
8116 build_call_nary (tree return_type
, tree fn
, int nargs
, ...)
8120 va_start (args
, nargs
);
8121 ret
= build_call_valist (return_type
, fn
, nargs
, args
);
8126 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8127 FN and a null static chain slot. NARGS is the number of call arguments
8128 which are specified as a va_list ARGS. */
8131 build_call_valist (tree return_type
, tree fn
, int nargs
, va_list args
)
8136 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
8137 TREE_TYPE (t
) = return_type
;
8138 CALL_EXPR_FN (t
) = fn
;
8139 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
8140 for (i
= 0; i
< nargs
; i
++)
8141 CALL_EXPR_ARG (t
, i
) = va_arg (args
, tree
);
8142 process_call_operands (t
);
8146 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8147 FN and a null static chain slot. NARGS is the number of call arguments
8148 which are specified as a tree array ARGS. */
8151 build_call_array (tree return_type
, tree fn
, int nargs
, tree
*args
)
8156 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
8157 TREE_TYPE (t
) = return_type
;
8158 CALL_EXPR_FN (t
) = fn
;
8159 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
8160 for (i
= 0; i
< nargs
; i
++)
8161 CALL_EXPR_ARG (t
, i
) = args
[i
];
8162 process_call_operands (t
);
8167 /* Returns true if it is possible to prove that the index of
8168 an array access REF (an ARRAY_REF expression) falls into the
8172 in_array_bounds_p (tree ref
)
8174 tree idx
= TREE_OPERAND (ref
, 1);
8177 if (TREE_CODE (idx
) != INTEGER_CST
)
8180 min
= array_ref_low_bound (ref
);
8181 max
= array_ref_up_bound (ref
);
8184 || TREE_CODE (min
) != INTEGER_CST
8185 || TREE_CODE (max
) != INTEGER_CST
)
8188 if (tree_int_cst_lt (idx
, min
)
8189 || tree_int_cst_lt (max
, idx
))
8195 /* Returns true if it is possible to prove that the range of
8196 an array access REF (an ARRAY_RANGE_REF expression) falls
8197 into the array bounds. */
8200 range_in_array_bounds_p (tree ref
)
8202 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (ref
));
8203 tree range_min
, range_max
, min
, max
;
8205 range_min
= TYPE_MIN_VALUE (domain_type
);
8206 range_max
= TYPE_MAX_VALUE (domain_type
);
8209 || TREE_CODE (range_min
) != INTEGER_CST
8210 || TREE_CODE (range_max
) != INTEGER_CST
)
8213 min
= array_ref_low_bound (ref
);
8214 max
= array_ref_up_bound (ref
);
8217 || TREE_CODE (min
) != INTEGER_CST
8218 || TREE_CODE (max
) != INTEGER_CST
)
8221 if (tree_int_cst_lt (range_min
, min
)
8222 || tree_int_cst_lt (max
, range_max
))
8228 /* Return true if T (assumed to be a DECL) must be assigned a memory
8232 needs_to_live_in_memory (const_tree t
)
8234 if (TREE_CODE (t
) == SSA_NAME
)
8235 t
= SSA_NAME_VAR (t
);
8237 return (TREE_ADDRESSABLE (t
)
8238 || is_global_var (t
)
8239 || (TREE_CODE (t
) == RESULT_DECL
8240 && aggregate_value_p (t
, current_function_decl
)));
8243 /* There are situations in which a language considers record types
8244 compatible which have different field lists. Decide if two fields
8245 are compatible. It is assumed that the parent records are compatible. */
8248 fields_compatible_p (const_tree f1
, const_tree f2
)
8250 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1
),
8251 DECL_FIELD_BIT_OFFSET (f2
), OEP_ONLY_CONST
))
8254 if (!operand_equal_p (DECL_FIELD_OFFSET (f1
),
8255 DECL_FIELD_OFFSET (f2
), OEP_ONLY_CONST
))
8258 if (!types_compatible_p (TREE_TYPE (f1
), TREE_TYPE (f2
)))
8264 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
8267 find_compatible_field (tree record
, tree orig_field
)
8271 for (f
= TYPE_FIELDS (record
); f
; f
= TREE_CHAIN (f
))
8272 if (TREE_CODE (f
) == FIELD_DECL
8273 && fields_compatible_p (f
, orig_field
))
8276 /* ??? Why isn't this on the main fields list? */
8277 f
= TYPE_VFIELD (record
);
8278 if (f
&& TREE_CODE (f
) == FIELD_DECL
8279 && fields_compatible_p (f
, orig_field
))
8282 /* ??? We should abort here, but Java appears to do Bad Things
8283 with inherited fields. */
8287 /* Return value of a constant X and sign-extend it. */
8290 int_cst_value (const_tree x
)
8292 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
8293 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
8295 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
8296 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
8297 || TREE_INT_CST_HIGH (x
) == -1);
8299 if (bits
< HOST_BITS_PER_WIDE_INT
)
8301 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
8303 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
8305 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
8311 /* If TYPE is an integral type, return an equivalent type which is
8312 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type,
8313 return TYPE itself. */
8316 signed_or_unsigned_type_for (int unsignedp
, tree type
)
8319 if (POINTER_TYPE_P (type
))
8322 if (!INTEGRAL_TYPE_P (t
) || TYPE_UNSIGNED (t
) == unsignedp
)
8325 return lang_hooks
.types
.type_for_size (TYPE_PRECISION (t
), unsignedp
);
8328 /* Returns unsigned variant of TYPE. */
8331 unsigned_type_for (tree type
)
8333 return signed_or_unsigned_type_for (1, type
);
8336 /* Returns signed variant of TYPE. */
8339 signed_type_for (tree type
)
8341 return signed_or_unsigned_type_for (0, type
);
8344 /* Returns the largest value obtainable by casting something in INNER type to
8348 upper_bound_in_type (tree outer
, tree inner
)
8350 unsigned HOST_WIDE_INT lo
, hi
;
8351 unsigned int det
= 0;
8352 unsigned oprec
= TYPE_PRECISION (outer
);
8353 unsigned iprec
= TYPE_PRECISION (inner
);
8356 /* Compute a unique number for every combination. */
8357 det
|= (oprec
> iprec
) ? 4 : 0;
8358 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
8359 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
8361 /* Determine the exponent to use. */
8366 /* oprec <= iprec, outer: signed, inner: don't care. */
8371 /* oprec <= iprec, outer: unsigned, inner: don't care. */
8375 /* oprec > iprec, outer: signed, inner: signed. */
8379 /* oprec > iprec, outer: signed, inner: unsigned. */
8383 /* oprec > iprec, outer: unsigned, inner: signed. */
8387 /* oprec > iprec, outer: unsigned, inner: unsigned. */
8394 /* Compute 2^^prec - 1. */
8395 if (prec
<= HOST_BITS_PER_WIDE_INT
)
8398 lo
= ((~(unsigned HOST_WIDE_INT
) 0)
8399 >> (HOST_BITS_PER_WIDE_INT
- prec
));
8403 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
8404 >> (2 * HOST_BITS_PER_WIDE_INT
- prec
));
8405 lo
= ~(unsigned HOST_WIDE_INT
) 0;
8408 return build_int_cst_wide (outer
, lo
, hi
);
8411 /* Returns the smallest value obtainable by casting something in INNER type to
8415 lower_bound_in_type (tree outer
, tree inner
)
8417 unsigned HOST_WIDE_INT lo
, hi
;
8418 unsigned oprec
= TYPE_PRECISION (outer
);
8419 unsigned iprec
= TYPE_PRECISION (inner
);
8421 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
8423 if (TYPE_UNSIGNED (outer
)
8424 /* If we are widening something of an unsigned type, OUTER type
8425 contains all values of INNER type. In particular, both INNER
8426 and OUTER types have zero in common. */
8427 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
8431 /* If we are widening a signed type to another signed type, we
8432 want to obtain -2^^(iprec-1). If we are keeping the
8433 precision or narrowing to a signed type, we want to obtain
8435 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
8437 if (prec
<= HOST_BITS_PER_WIDE_INT
)
8439 hi
= ~(unsigned HOST_WIDE_INT
) 0;
8440 lo
= (~(unsigned HOST_WIDE_INT
) 0) << (prec
- 1);
8444 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
8445 << (prec
- HOST_BITS_PER_WIDE_INT
- 1));
8450 return build_int_cst_wide (outer
, lo
, hi
);
8453 /* Return nonzero if two operands that are suitable for PHI nodes are
8454 necessarily equal. Specifically, both ARG0 and ARG1 must be either
8455 SSA_NAME or invariant. Note that this is strictly an optimization.
8456 That is, callers of this function can directly call operand_equal_p
8457 and get the same result, only slower. */
8460 operand_equal_for_phi_arg_p (const_tree arg0
, const_tree arg1
)
8464 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
8466 return operand_equal_p (arg0
, arg1
, 0);
8469 /* Returns number of zeros at the end of binary representation of X.
8471 ??? Use ffs if available? */
8474 num_ending_zeros (const_tree x
)
8476 unsigned HOST_WIDE_INT fr
, nfr
;
8477 unsigned num
, abits
;
8478 tree type
= TREE_TYPE (x
);
8480 if (TREE_INT_CST_LOW (x
) == 0)
8482 num
= HOST_BITS_PER_WIDE_INT
;
8483 fr
= TREE_INT_CST_HIGH (x
);
8488 fr
= TREE_INT_CST_LOW (x
);
8491 for (abits
= HOST_BITS_PER_WIDE_INT
/ 2; abits
; abits
/= 2)
8494 if (nfr
<< abits
== fr
)
8501 if (num
> TYPE_PRECISION (type
))
8502 num
= TYPE_PRECISION (type
);
8504 return build_int_cst_type (type
, num
);
8508 #define WALK_SUBTREE(NODE) \
8511 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
8517 /* This is a subroutine of walk_tree that walks field of TYPE that are to
8518 be walked whenever a type is seen in the tree. Rest of operands and return
8519 value are as for walk_tree. */
8522 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
8523 struct pointer_set_t
*pset
, walk_tree_lh lh
)
8525 tree result
= NULL_TREE
;
8527 switch (TREE_CODE (type
))
8530 case REFERENCE_TYPE
:
8531 /* We have to worry about mutually recursive pointers. These can't
8532 be written in C. They can in Ada. It's pathological, but
8533 there's an ACATS test (c38102a) that checks it. Deal with this
8534 by checking if we're pointing to another pointer, that one
8535 points to another pointer, that one does too, and we have no htab.
8536 If so, get a hash table. We check three levels deep to avoid
8537 the cost of the hash table if we don't need one. */
8538 if (POINTER_TYPE_P (TREE_TYPE (type
))
8539 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
8540 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
8543 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
8551 /* ... fall through ... */
8554 WALK_SUBTREE (TREE_TYPE (type
));
8558 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
8563 WALK_SUBTREE (TREE_TYPE (type
));
8567 /* We never want to walk into default arguments. */
8568 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
8569 WALK_SUBTREE (TREE_VALUE (arg
));
8574 /* Don't follow this nodes's type if a pointer for fear that
8575 we'll have infinite recursion. If we have a PSET, then we
8578 || (!POINTER_TYPE_P (TREE_TYPE (type
))
8579 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
))
8580 WALK_SUBTREE (TREE_TYPE (type
));
8581 WALK_SUBTREE (TYPE_DOMAIN (type
));
8585 WALK_SUBTREE (TREE_TYPE (type
));
8586 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
8596 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
8597 called with the DATA and the address of each sub-tree. If FUNC returns a
8598 non-NULL value, the traversal is stopped, and the value returned by FUNC
8599 is returned. If PSET is non-NULL it is used to record the nodes visited,
8600 and to avoid visiting a node more than once. */
8603 walk_tree_1 (tree
*tp
, walk_tree_fn func
, void *data
,
8604 struct pointer_set_t
*pset
, walk_tree_lh lh
)
8606 enum tree_code code
;
8610 #define WALK_SUBTREE_TAIL(NODE) \
8614 goto tail_recurse; \
8619 /* Skip empty subtrees. */
8623 /* Don't walk the same tree twice, if the user has requested
8624 that we avoid doing so. */
8625 if (pset
&& pointer_set_insert (pset
, *tp
))
8628 /* Call the function. */
8630 result
= (*func
) (tp
, &walk_subtrees
, data
);
8632 /* If we found something, return it. */
8636 code
= TREE_CODE (*tp
);
8638 /* Even if we didn't, FUNC may have decided that there was nothing
8639 interesting below this point in the tree. */
8642 /* But we still need to check our siblings. */
8643 if (code
== TREE_LIST
)
8644 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
8645 else if (code
== OMP_CLAUSE
)
8646 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8653 result
= (*lh
) (tp
, &walk_subtrees
, func
, data
, pset
);
8654 if (result
|| !walk_subtrees
)
8661 case IDENTIFIER_NODE
:
8668 case PLACEHOLDER_EXPR
:
8672 /* None of these have subtrees other than those already walked
8677 WALK_SUBTREE (TREE_VALUE (*tp
));
8678 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
8683 int len
= TREE_VEC_LENGTH (*tp
);
8688 /* Walk all elements but the first. */
8690 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
8692 /* Now walk the first one as a tail call. */
8693 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
8697 WALK_SUBTREE (TREE_REALPART (*tp
));
8698 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
8702 unsigned HOST_WIDE_INT idx
;
8703 constructor_elt
*ce
;
8706 VEC_iterate(constructor_elt
, CONSTRUCTOR_ELTS (*tp
), idx
, ce
);
8708 WALK_SUBTREE (ce
->value
);
8713 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
8718 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= TREE_CHAIN (decl
))
8720 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
8721 into declarations that are just mentioned, rather than
8722 declared; they don't really belong to this part of the tree.
8723 And, we can see cycles: the initializer for a declaration
8724 can refer to the declaration itself. */
8725 WALK_SUBTREE (DECL_INITIAL (decl
));
8726 WALK_SUBTREE (DECL_SIZE (decl
));
8727 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
8729 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
8732 case STATEMENT_LIST
:
8734 tree_stmt_iterator i
;
8735 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
8736 WALK_SUBTREE (*tsi_stmt_ptr (i
));
8741 switch (OMP_CLAUSE_CODE (*tp
))
8743 case OMP_CLAUSE_PRIVATE
:
8744 case OMP_CLAUSE_SHARED
:
8745 case OMP_CLAUSE_FIRSTPRIVATE
:
8746 case OMP_CLAUSE_COPYIN
:
8747 case OMP_CLAUSE_COPYPRIVATE
:
8749 case OMP_CLAUSE_NUM_THREADS
:
8750 case OMP_CLAUSE_SCHEDULE
:
8751 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 0));
8754 case OMP_CLAUSE_NOWAIT
:
8755 case OMP_CLAUSE_ORDERED
:
8756 case OMP_CLAUSE_DEFAULT
:
8757 case OMP_CLAUSE_UNTIED
:
8758 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8760 case OMP_CLAUSE_LASTPRIVATE
:
8761 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
8762 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp
));
8763 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8765 case OMP_CLAUSE_COLLAPSE
:
8768 for (i
= 0; i
< 3; i
++)
8769 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
8770 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8773 case OMP_CLAUSE_REDUCTION
:
8776 for (i
= 0; i
< 4; i
++)
8777 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
8778 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8790 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
8791 But, we only want to walk once. */
8792 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
8793 for (i
= 0; i
< len
; ++i
)
8794 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
8795 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
8798 case CHANGE_DYNAMIC_TYPE_EXPR
:
8799 WALK_SUBTREE (CHANGE_DYNAMIC_TYPE_NEW_TYPE (*tp
));
8800 WALK_SUBTREE_TAIL (CHANGE_DYNAMIC_TYPE_LOCATION (*tp
));
8803 /* If this is a TYPE_DECL, walk into the fields of the type that it's
8804 defining. We only want to walk into these fields of a type in this
8805 case and not in the general case of a mere reference to the type.
8807 The criterion is as follows: if the field can be an expression, it
8808 must be walked only here. This should be in keeping with the fields
8809 that are directly gimplified in gimplify_type_sizes in order for the
8810 mark/copy-if-shared/unmark machinery of the gimplifier to work with
8811 variable-sized types.
8813 Note that DECLs get walked as part of processing the BIND_EXPR. */
8814 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
8816 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
8817 if (TREE_CODE (*type_p
) == ERROR_MARK
)
8820 /* Call the function for the type. See if it returns anything or
8821 doesn't want us to continue. If we are to continue, walk both
8822 the normal fields and those for the declaration case. */
8823 result
= (*func
) (type_p
, &walk_subtrees
, data
);
8824 if (result
|| !walk_subtrees
)
8827 result
= walk_type_fields (*type_p
, func
, data
, pset
, lh
);
8831 /* If this is a record type, also walk the fields. */
8832 if (TREE_CODE (*type_p
) == RECORD_TYPE
8833 || TREE_CODE (*type_p
) == UNION_TYPE
8834 || TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
8838 for (field
= TYPE_FIELDS (*type_p
); field
;
8839 field
= TREE_CHAIN (field
))
8841 /* We'd like to look at the type of the field, but we can
8842 easily get infinite recursion. So assume it's pointed
8843 to elsewhere in the tree. Also, ignore things that
8845 if (TREE_CODE (field
) != FIELD_DECL
)
8848 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
8849 WALK_SUBTREE (DECL_SIZE (field
));
8850 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
8851 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
8852 WALK_SUBTREE (DECL_QUALIFIER (field
));
8856 /* Same for scalar types. */
8857 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
8858 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
8859 || TREE_CODE (*type_p
) == INTEGER_TYPE
8860 || TREE_CODE (*type_p
) == FIXED_POINT_TYPE
8861 || TREE_CODE (*type_p
) == REAL_TYPE
)
8863 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
8864 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
8867 WALK_SUBTREE (TYPE_SIZE (*type_p
));
8868 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
8873 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
)))
8877 /* Walk over all the sub-trees of this operand. */
8878 len
= TREE_OPERAND_LENGTH (*tp
);
8880 /* Go through the subtrees. We need to do this in forward order so
8881 that the scope of a FOR_EXPR is handled properly. */
8884 for (i
= 0; i
< len
- 1; ++i
)
8885 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
8886 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
- 1));
8889 /* If this is a type, walk the needed fields in the type. */
8890 else if (TYPE_P (*tp
))
8891 return walk_type_fields (*tp
, func
, data
, pset
, lh
);
8895 /* We didn't find what we were looking for. */
8898 #undef WALK_SUBTREE_TAIL
8902 /* Like walk_tree, but does not walk duplicate nodes more than once. */
8905 walk_tree_without_duplicates_1 (tree
*tp
, walk_tree_fn func
, void *data
,
8909 struct pointer_set_t
*pset
;
8911 pset
= pointer_set_create ();
8912 result
= walk_tree_1 (tp
, func
, data
, pset
, lh
);
8913 pointer_set_destroy (pset
);
8921 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
8923 if (IS_EXPR_CODE_CLASS (c
))
8924 return &t
->exp
.block
;
8929 /* Build and return a TREE_LIST of arguments in the CALL_EXPR exp.
8930 FIXME: don't use this function. It exists for compatibility with
8931 the old representation of CALL_EXPRs where a list was used to hold the
8932 arguments. Places that currently extract the arglist from a CALL_EXPR
8933 ought to be rewritten to use the CALL_EXPR itself. */
8935 call_expr_arglist (tree exp
)
8937 tree arglist
= NULL_TREE
;
8939 for (i
= call_expr_nargs (exp
) - 1; i
>= 0; i
--)
8940 arglist
= tree_cons (NULL_TREE
, CALL_EXPR_ARG (exp
, i
), arglist
);
8945 /* Create a nameless artificial label and put it in the current function
8946 context. Returns the newly created label. */
8949 create_artificial_label (void)
8951 tree lab
= build_decl (LABEL_DECL
, NULL_TREE
, void_type_node
);
8953 DECL_ARTIFICIAL (lab
) = 1;
8954 DECL_IGNORED_P (lab
) = 1;
8955 DECL_CONTEXT (lab
) = current_function_decl
;
8959 /* Given a tree, try to return a useful variable name that we can use
8960 to prefix a temporary that is being assigned the value of the tree.
8961 I.E. given <temp> = &A, return A. */
8969 STRIP_NOPS (stripped_decl
);
8970 if (DECL_P (stripped_decl
) && DECL_NAME (stripped_decl
))
8971 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl
));
8974 switch (TREE_CODE (stripped_decl
))
8977 return get_name (TREE_OPERAND (stripped_decl
, 0));
8984 /* Return true if TYPE has a variable argument list. */
8987 stdarg_p (tree fntype
)
8989 function_args_iterator args_iter
;
8990 tree n
= NULL_TREE
, t
;
8995 FOREACH_FUNCTION_ARGS(fntype
, t
, args_iter
)
9000 return n
!= NULL_TREE
&& n
!= void_type_node
;
9003 /* Return true if TYPE has a prototype. */
9006 prototype_p (tree fntype
)
9010 gcc_assert (fntype
!= NULL_TREE
);
9012 t
= TYPE_ARG_TYPES (fntype
);
9013 return (t
!= NULL_TREE
);
9016 /* Return the number of arguments that a function has. */
9019 function_args_count (tree fntype
)
9021 function_args_iterator args_iter
;
9027 FOREACH_FUNCTION_ARGS(fntype
, t
, args_iter
)
9036 /* If BLOCK is inlined from an __attribute__((__artificial__))
9037 routine, return pointer to location from where it has been
9040 block_nonartificial_location (tree block
)
9042 location_t
*ret
= NULL
;
9044 while (block
&& TREE_CODE (block
) == BLOCK
9045 && BLOCK_ABSTRACT_ORIGIN (block
))
9047 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
9049 while (TREE_CODE (ao
) == BLOCK
9050 && BLOCK_ABSTRACT_ORIGIN (ao
)
9051 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
9052 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
9054 if (TREE_CODE (ao
) == FUNCTION_DECL
)
9056 /* If AO is an artificial inline, point RET to the
9057 call site locus at which it has been inlined and continue
9058 the loop, in case AO's caller is also an artificial
9060 if (DECL_DECLARED_INLINE_P (ao
)
9061 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao
)))
9062 ret
= &BLOCK_SOURCE_LOCATION (block
);
9066 else if (TREE_CODE (ao
) != BLOCK
)
9069 block
= BLOCK_SUPERCONTEXT (block
);
9074 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
9077 /* Return the hash code code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
9080 cl_option_hash_hash (const void *x
)
9082 const_tree
const t
= (const_tree
) x
;
9088 if (TREE_CODE (t
) == OPTIMIZATION_NODE
)
9090 p
= (const char *)TREE_OPTIMIZATION (t
);
9091 len
= sizeof (struct cl_optimization
);
9094 else if (TREE_CODE (t
) == TARGET_OPTION_NODE
)
9096 p
= (const char *)TREE_TARGET_OPTION (t
);
9097 len
= sizeof (struct cl_target_option
);
9103 /* assume most opt flags are just 0/1, some are 2-3, and a few might be
9105 for (i
= 0; i
< len
; i
++)
9107 hash
= (hash
<< 4) ^ ((i
<< 2) | p
[i
]);
9112 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
9113 TARGET_OPTION tree node) is the same as that given by *Y, which is the
9117 cl_option_hash_eq (const void *x
, const void *y
)
9119 const_tree
const xt
= (const_tree
) x
;
9120 const_tree
const yt
= (const_tree
) y
;
9125 if (TREE_CODE (xt
) != TREE_CODE (yt
))
9128 if (TREE_CODE (xt
) == OPTIMIZATION_NODE
)
9130 xp
= (const char *)TREE_OPTIMIZATION (xt
);
9131 yp
= (const char *)TREE_OPTIMIZATION (yt
);
9132 len
= sizeof (struct cl_optimization
);
9135 else if (TREE_CODE (xt
) == TARGET_OPTION_NODE
)
9137 xp
= (const char *)TREE_TARGET_OPTION (xt
);
9138 yp
= (const char *)TREE_TARGET_OPTION (yt
);
9139 len
= sizeof (struct cl_target_option
);
9145 return (memcmp (xp
, yp
, len
) == 0);
9148 /* Build an OPTIMIZATION_NODE based on the current options. */
9151 build_optimization_node (void)
9156 /* Use the cache of optimization nodes. */
9158 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node
));
9160 slot
= htab_find_slot (cl_option_hash_table
, cl_optimization_node
, INSERT
);
9164 /* Insert this one into the hash table. */
9165 t
= cl_optimization_node
;
9168 /* Make a new node for next time round. */
9169 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
9175 /* Build a TARGET_OPTION_NODE based on the current options. */
9178 build_target_option_node (void)
9183 /* Use the cache of optimization nodes. */
9185 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node
));
9187 slot
= htab_find_slot (cl_option_hash_table
, cl_target_option_node
, INSERT
);
9191 /* Insert this one into the hash table. */
9192 t
= cl_target_option_node
;
9195 /* Make a new node for next time round. */
9196 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
9202 #include "gt-tree.h"