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
[] =
112 /* obstack.[ch] explicitly declined to prototype this. */
113 extern int _obstack_allocated_p (struct obstack
*h
, void *obj
);
115 #ifdef GATHER_STATISTICS
116 /* Statistics-gathering stuff. */
118 int tree_node_counts
[(int) all_kinds
];
119 int tree_node_sizes
[(int) all_kinds
];
121 /* Keep in sync with tree.h:enum tree_node_kind. */
122 static const char * const tree_node_kind_names
[] = {
144 #endif /* GATHER_STATISTICS */
146 /* Unique id for next decl created. */
147 static GTY(()) int next_decl_uid
;
148 /* Unique id for next type created. */
149 static GTY(()) int next_type_uid
= 1;
151 /* Since we cannot rehash a type after it is in the table, we have to
152 keep the hash code. */
154 struct type_hash
GTY(())
160 /* Initial size of the hash table (rounded to next prime). */
161 #define TYPE_HASH_INITIAL_SIZE 1000
163 /* Now here is the hash table. When recording a type, it is added to
164 the slot whose index is the hash code. Note that the hash table is
165 used for several kinds of types (function types, array types and
166 array index range types, for now). While all these live in the
167 same table, they are completely independent, and the hash code is
168 computed differently for each of these. */
170 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash
)))
171 htab_t type_hash_table
;
173 /* Hash table and temporary node for larger integer const values. */
174 static GTY (()) tree int_cst_node
;
175 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
176 htab_t int_cst_hash_table
;
178 /* General tree->tree mapping structure for use in hash tables. */
181 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
182 htab_t debug_expr_for_decl
;
184 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
185 htab_t value_expr_for_decl
;
187 static GTY ((if_marked ("tree_priority_map_marked_p"),
188 param_is (struct tree_priority_map
)))
189 htab_t init_priority_for_decl
;
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
192 htab_t restrict_base_for_decl
;
194 static void set_type_quals (tree
, int);
195 static int type_hash_eq (const void *, const void *);
196 static hashval_t
type_hash_hash (const void *);
197 static hashval_t
int_cst_hash_hash (const void *);
198 static int int_cst_hash_eq (const void *, const void *);
199 static void print_type_hash_statistics (void);
200 static void print_debug_expr_statistics (void);
201 static void print_value_expr_statistics (void);
202 static int type_hash_marked_p (const void *);
203 static unsigned int type_hash_list (const_tree
, hashval_t
);
204 static unsigned int attribute_hash_list (const_tree
, hashval_t
);
206 tree global_trees
[TI_MAX
];
207 tree integer_types
[itk_none
];
209 unsigned char tree_contains_struct
[MAX_TREE_CODES
][64];
211 /* Number of operands for each OpenMP clause. */
212 unsigned const char omp_clause_num_ops
[] =
214 0, /* OMP_CLAUSE_ERROR */
215 1, /* OMP_CLAUSE_PRIVATE */
216 1, /* OMP_CLAUSE_SHARED */
217 1, /* OMP_CLAUSE_FIRSTPRIVATE */
218 2, /* OMP_CLAUSE_LASTPRIVATE */
219 4, /* OMP_CLAUSE_REDUCTION */
220 1, /* OMP_CLAUSE_COPYIN */
221 1, /* OMP_CLAUSE_COPYPRIVATE */
222 1, /* OMP_CLAUSE_IF */
223 1, /* OMP_CLAUSE_NUM_THREADS */
224 1, /* OMP_CLAUSE_SCHEDULE */
225 0, /* OMP_CLAUSE_NOWAIT */
226 0, /* OMP_CLAUSE_ORDERED */
227 0, /* OMP_CLAUSE_DEFAULT */
228 3, /* OMP_CLAUSE_COLLAPSE */
229 0 /* OMP_CLAUSE_UNTIED */
232 const char * const omp_clause_code_name
[] =
257 /* Initialize the hash table of types. */
258 type_hash_table
= htab_create_ggc (TYPE_HASH_INITIAL_SIZE
, type_hash_hash
,
261 debug_expr_for_decl
= htab_create_ggc (512, tree_map_hash
,
264 value_expr_for_decl
= htab_create_ggc (512, tree_map_hash
,
266 init_priority_for_decl
= htab_create_ggc (512, tree_priority_map_hash
,
267 tree_priority_map_eq
, 0);
268 restrict_base_for_decl
= htab_create_ggc (256, tree_map_hash
,
271 int_cst_hash_table
= htab_create_ggc (1024, int_cst_hash_hash
,
272 int_cst_hash_eq
, NULL
);
274 int_cst_node
= make_node (INTEGER_CST
);
276 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
] = 1;
277 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_NON_COMMON
] = 1;
278 tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
] = 1;
281 tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
] = 1;
282 tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
] = 1;
283 tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
] = 1;
284 tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
] = 1;
285 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
] = 1;
286 tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
] = 1;
287 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
] = 1;
288 tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
] = 1;
289 tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
] = 1;
292 tree_contains_struct
[CONST_DECL
][TS_DECL_WRTL
] = 1;
293 tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
] = 1;
294 tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
] = 1;
295 tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
] = 1;
296 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
] = 1;
297 tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
] = 1;
299 tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
] = 1;
300 tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
] = 1;
301 tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
] = 1;
302 tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
] = 1;
303 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
] = 1;
304 tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
] = 1;
305 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
] = 1;
306 tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
] = 1;
307 tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
] = 1;
308 tree_contains_struct
[NAME_MEMORY_TAG
][TS_DECL_MINIMAL
] = 1;
309 tree_contains_struct
[SYMBOL_MEMORY_TAG
][TS_DECL_MINIMAL
] = 1;
310 tree_contains_struct
[MEMORY_PARTITION_TAG
][TS_DECL_MINIMAL
] = 1;
312 tree_contains_struct
[NAME_MEMORY_TAG
][TS_MEMORY_TAG
] = 1;
313 tree_contains_struct
[SYMBOL_MEMORY_TAG
][TS_MEMORY_TAG
] = 1;
314 tree_contains_struct
[MEMORY_PARTITION_TAG
][TS_MEMORY_TAG
] = 1;
316 tree_contains_struct
[MEMORY_PARTITION_TAG
][TS_MEMORY_PARTITION_TAG
] = 1;
318 tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
] = 1;
319 tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
] = 1;
320 tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
] = 1;
321 tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_WITH_VIS
] = 1;
323 tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
] = 1;
324 tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
] = 1;
325 tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
] = 1;
326 tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
] = 1;
327 tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
] = 1;
328 tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
] = 1;
329 tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
] = 1;
330 tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
] = 1;
332 lang_hooks
.init_ts ();
336 /* The name of the object as the assembler will see it (but before any
337 translations made by ASM_OUTPUT_LABELREF). Often this is the same
338 as DECL_NAME. It is an IDENTIFIER_NODE. */
340 decl_assembler_name (tree decl
)
342 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
343 lang_hooks
.set_decl_assembler_name (decl
);
344 return DECL_WITH_VIS_CHECK (decl
)->decl_with_vis
.assembler_name
;
347 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
350 decl_assembler_name_equal (tree decl
, const_tree asmname
)
352 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
353 const char *decl_str
;
354 const char *asmname_str
;
357 if (decl_asmname
== asmname
)
360 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
361 asmname_str
= IDENTIFIER_POINTER (asmname
);
364 /* If the target assembler name was set by the user, things are trickier.
365 We have a leading '*' to begin with. After that, it's arguable what
366 is the correct thing to do with -fleading-underscore. Arguably, we've
367 historically been doing the wrong thing in assemble_alias by always
368 printing the leading underscore. Since we're not changing that, make
369 sure user_label_prefix follows the '*' before matching. */
370 if (decl_str
[0] == '*')
372 size_t ulp_len
= strlen (user_label_prefix
);
378 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
379 decl_str
+= ulp_len
, test
=true;
383 if (asmname_str
[0] == '*')
385 size_t ulp_len
= strlen (user_label_prefix
);
391 else if (strncmp (asmname_str
, user_label_prefix
, ulp_len
) == 0)
392 asmname_str
+= ulp_len
, test
=true;
399 return strcmp (decl_str
, asmname_str
) == 0;
402 /* Hash asmnames ignoring the user specified marks. */
405 decl_assembler_name_hash (const_tree asmname
)
407 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
409 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
410 size_t ulp_len
= strlen (user_label_prefix
);
414 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
417 return htab_hash_string (decl_str
);
420 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
423 /* Compute the number of bytes occupied by a tree with code CODE.
424 This function cannot be used for nodes that have variable sizes,
425 including TREE_VEC, PHI_NODE, STRING_CST, and CALL_EXPR. */
427 tree_code_size (enum tree_code code
)
429 switch (TREE_CODE_CLASS (code
))
431 case tcc_declaration
: /* A decl node */
436 return sizeof (struct tree_field_decl
);
438 return sizeof (struct tree_parm_decl
);
440 return sizeof (struct tree_var_decl
);
442 return sizeof (struct tree_label_decl
);
444 return sizeof (struct tree_result_decl
);
446 return sizeof (struct tree_const_decl
);
448 return sizeof (struct tree_type_decl
);
450 return sizeof (struct tree_function_decl
);
451 case NAME_MEMORY_TAG
:
452 case SYMBOL_MEMORY_TAG
:
453 return sizeof (struct tree_memory_tag
);
454 case MEMORY_PARTITION_TAG
:
455 return sizeof (struct tree_memory_partition_tag
);
457 return sizeof (struct tree_decl_non_common
);
461 case tcc_type
: /* a type node */
462 return sizeof (struct tree_type
);
464 case tcc_reference
: /* a reference */
465 case tcc_expression
: /* an expression */
466 case tcc_statement
: /* an expression with side effects */
467 case tcc_comparison
: /* a comparison expression */
468 case tcc_unary
: /* a unary arithmetic expression */
469 case tcc_binary
: /* a binary arithmetic expression */
470 return (sizeof (struct tree_exp
)
471 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (tree
));
473 case tcc_gimple_stmt
:
474 return (sizeof (struct gimple_stmt
)
475 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (char *));
477 case tcc_constant
: /* a constant */
480 case INTEGER_CST
: return sizeof (struct tree_int_cst
);
481 case REAL_CST
: return sizeof (struct tree_real_cst
);
482 case FIXED_CST
: return sizeof (struct tree_fixed_cst
);
483 case COMPLEX_CST
: return sizeof (struct tree_complex
);
484 case VECTOR_CST
: return sizeof (struct tree_vector
);
485 case STRING_CST
: gcc_unreachable ();
487 return lang_hooks
.tree_size (code
);
490 case tcc_exceptional
: /* something random, like an identifier. */
493 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
494 case TREE_LIST
: return sizeof (struct tree_list
);
497 case PLACEHOLDER_EXPR
: return sizeof (struct tree_common
);
501 case PHI_NODE
: gcc_unreachable ();
503 case SSA_NAME
: return sizeof (struct tree_ssa_name
);
505 case STATEMENT_LIST
: return sizeof (struct tree_statement_list
);
506 case BLOCK
: return sizeof (struct tree_block
);
507 case CONSTRUCTOR
: return sizeof (struct tree_constructor
);
510 return lang_hooks
.tree_size (code
);
518 /* Compute the number of bytes occupied by NODE. This routine only
519 looks at TREE_CODE, except for those nodes that have variable sizes. */
521 tree_size (const_tree node
)
523 const enum tree_code code
= TREE_CODE (node
);
527 return (sizeof (struct tree_phi_node
)
528 + (PHI_ARG_CAPACITY (node
) - 1) * sizeof (struct phi_arg_d
));
531 return (offsetof (struct tree_binfo
, base_binfos
)
532 + VEC_embedded_size (tree
, BINFO_N_BASE_BINFOS (node
)));
535 return (sizeof (struct tree_vec
)
536 + (TREE_VEC_LENGTH (node
) - 1) * sizeof (tree
));
539 return TREE_STRING_LENGTH (node
) + offsetof (struct tree_string
, str
) + 1;
542 return (sizeof (struct tree_omp_clause
)
543 + (omp_clause_num_ops
[OMP_CLAUSE_CODE (node
)] - 1)
547 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
548 return (sizeof (struct tree_exp
)
549 + (VL_EXP_OPERAND_LENGTH (node
) - 1) * sizeof (tree
));
551 return tree_code_size (code
);
555 /* Return a newly allocated node of code CODE. For decl and type
556 nodes, some other fields are initialized. The rest of the node is
557 initialized to zero. This function cannot be used for PHI_NODE,
558 TREE_VEC or OMP_CLAUSE nodes, which is enforced by asserts in
561 Achoo! I got a code in the node. */
564 make_node_stat (enum tree_code code MEM_STAT_DECL
)
567 enum tree_code_class type
= TREE_CODE_CLASS (code
);
568 size_t length
= tree_code_size (code
);
569 #ifdef GATHER_STATISTICS
574 case tcc_declaration
: /* A decl node */
578 case tcc_type
: /* a type node */
582 case tcc_statement
: /* an expression with side effects */
586 case tcc_reference
: /* a reference */
590 case tcc_expression
: /* an expression */
591 case tcc_comparison
: /* a comparison expression */
592 case tcc_unary
: /* a unary arithmetic expression */
593 case tcc_binary
: /* a binary arithmetic expression */
597 case tcc_constant
: /* a constant */
601 case tcc_gimple_stmt
:
602 kind
= gimple_stmt_kind
;
605 case tcc_exceptional
: /* something random, like an identifier. */
608 case IDENTIFIER_NODE
:
625 kind
= ssa_name_kind
;
646 tree_node_counts
[(int) kind
]++;
647 tree_node_sizes
[(int) kind
] += length
;
650 if (code
== IDENTIFIER_NODE
)
651 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_id_zone
);
653 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
655 memset (t
, 0, length
);
657 TREE_SET_CODE (t
, code
);
662 TREE_SIDE_EFFECTS (t
) = 1;
665 case tcc_declaration
:
666 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_WITH_VIS
))
667 DECL_IN_SYSTEM_HEADER (t
) = in_system_header
;
668 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
670 if (code
== FUNCTION_DECL
)
672 DECL_ALIGN (t
) = FUNCTION_BOUNDARY
;
673 DECL_MODE (t
) = FUNCTION_MODE
;
677 /* We have not yet computed the alias set for this declaration. */
678 DECL_POINTER_ALIAS_SET (t
) = -1;
680 DECL_SOURCE_LOCATION (t
) = input_location
;
681 DECL_UID (t
) = next_decl_uid
++;
686 TYPE_UID (t
) = next_type_uid
++;
687 TYPE_ALIGN (t
) = BITS_PER_UNIT
;
688 TYPE_USER_ALIGN (t
) = 0;
689 TYPE_MAIN_VARIANT (t
) = t
;
690 TYPE_CANONICAL (t
) = t
;
692 /* Default to no attributes for type, but let target change that. */
693 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
694 targetm
.set_default_type_attributes (t
);
696 /* We have not yet computed the alias set for this type. */
697 TYPE_ALIAS_SET (t
) = -1;
701 TREE_CONSTANT (t
) = 1;
710 case PREDECREMENT_EXPR
:
711 case PREINCREMENT_EXPR
:
712 case POSTDECREMENT_EXPR
:
713 case POSTINCREMENT_EXPR
:
714 /* All of these have side-effects, no matter what their
716 TREE_SIDE_EFFECTS (t
) = 1;
724 case tcc_gimple_stmt
:
727 case GIMPLE_MODIFY_STMT
:
728 TREE_SIDE_EFFECTS (t
) = 1;
736 /* Other classes need no special treatment. */
743 /* Return a new node with the same contents as NODE except that its
744 TREE_CHAIN is zero and it has a fresh uid. */
747 copy_node_stat (tree node MEM_STAT_DECL
)
750 enum tree_code code
= TREE_CODE (node
);
753 gcc_assert (code
!= STATEMENT_LIST
);
755 length
= tree_size (node
);
756 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
757 memcpy (t
, node
, length
);
759 if (!GIMPLE_TUPLE_P (node
))
761 TREE_ASM_WRITTEN (t
) = 0;
762 TREE_VISITED (t
) = 0;
765 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
767 DECL_UID (t
) = next_decl_uid
++;
768 if ((TREE_CODE (node
) == PARM_DECL
|| TREE_CODE (node
) == VAR_DECL
)
769 && DECL_HAS_VALUE_EXPR_P (node
))
771 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
772 DECL_HAS_VALUE_EXPR_P (t
) = 1;
774 if (TREE_CODE (node
) == VAR_DECL
&& DECL_HAS_INIT_PRIORITY_P (node
))
776 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
777 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
779 if (TREE_CODE (node
) == VAR_DECL
&& DECL_BASED_ON_RESTRICT_P (node
))
781 SET_DECL_RESTRICT_BASE (t
, DECL_GET_RESTRICT_BASE (node
));
782 DECL_BASED_ON_RESTRICT_P (t
) = 1;
785 else if (TREE_CODE_CLASS (code
) == tcc_type
)
787 TYPE_UID (t
) = next_type_uid
++;
788 /* The following is so that the debug code for
789 the copy is different from the original type.
790 The two statements usually duplicate each other
791 (because they clear fields of the same union),
792 but the optimizer should catch that. */
793 TYPE_SYMTAB_POINTER (t
) = 0;
794 TYPE_SYMTAB_ADDRESS (t
) = 0;
796 /* Do not copy the values cache. */
797 if (TYPE_CACHED_VALUES_P(t
))
799 TYPE_CACHED_VALUES_P (t
) = 0;
800 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
807 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
808 For example, this can copy a list made of TREE_LIST nodes. */
811 copy_list (tree list
)
819 head
= prev
= copy_node (list
);
820 next
= TREE_CHAIN (list
);
823 TREE_CHAIN (prev
) = copy_node (next
);
824 prev
= TREE_CHAIN (prev
);
825 next
= TREE_CHAIN (next
);
831 /* Create an INT_CST node with a LOW value sign extended. */
834 build_int_cst (tree type
, HOST_WIDE_INT low
)
836 /* Support legacy code. */
838 type
= integer_type_node
;
840 return build_int_cst_wide (type
, low
, low
< 0 ? -1 : 0);
843 /* Create an INT_CST node with a LOW value zero extended. */
846 build_int_cstu (tree type
, unsigned HOST_WIDE_INT low
)
848 return build_int_cst_wide (type
, low
, 0);
851 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
852 if it is negative. This function is similar to build_int_cst, but
853 the extra bits outside of the type precision are cleared. Constants
854 with these extra bits may confuse the fold so that it detects overflows
855 even in cases when they do not occur, and in general should be avoided.
856 We cannot however make this a default behavior of build_int_cst without
857 more intrusive changes, since there are parts of gcc that rely on the extra
858 precision of the integer constants. */
861 build_int_cst_type (tree type
, HOST_WIDE_INT low
)
863 unsigned HOST_WIDE_INT low1
;
868 fit_double_type (low
, low
< 0 ? -1 : 0, &low1
, &hi
, type
);
870 return build_int_cst_wide (type
, low1
, hi
);
873 /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated
874 and sign extended according to the value range of TYPE. */
877 build_int_cst_wide_type (tree type
,
878 unsigned HOST_WIDE_INT low
, HOST_WIDE_INT high
)
880 fit_double_type (low
, high
, &low
, &high
, type
);
881 return build_int_cst_wide (type
, low
, high
);
884 /* These are the hash table functions for the hash table of INTEGER_CST
885 nodes of a sizetype. */
887 /* Return the hash code code X, an INTEGER_CST. */
890 int_cst_hash_hash (const void *x
)
892 const_tree
const t
= (const_tree
) x
;
894 return (TREE_INT_CST_HIGH (t
) ^ TREE_INT_CST_LOW (t
)
895 ^ htab_hash_pointer (TREE_TYPE (t
)));
898 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
899 is the same as that given by *Y, which is the same. */
902 int_cst_hash_eq (const void *x
, const void *y
)
904 const_tree
const xt
= (const_tree
) x
;
905 const_tree
const yt
= (const_tree
) y
;
907 return (TREE_TYPE (xt
) == TREE_TYPE (yt
)
908 && TREE_INT_CST_HIGH (xt
) == TREE_INT_CST_HIGH (yt
)
909 && TREE_INT_CST_LOW (xt
) == TREE_INT_CST_LOW (yt
));
912 /* Create an INT_CST node of TYPE and value HI:LOW.
913 The returned node is always shared. For small integers we use a
914 per-type vector cache, for larger ones we use a single hash table. */
917 build_int_cst_wide (tree type
, unsigned HOST_WIDE_INT low
, HOST_WIDE_INT hi
)
925 switch (TREE_CODE (type
))
929 /* Cache NULL pointer. */
938 /* Cache false or true. */
946 if (TYPE_UNSIGNED (type
))
949 limit
= INTEGER_SHARE_LIMIT
;
950 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
956 limit
= INTEGER_SHARE_LIMIT
+ 1;
957 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
959 else if (hi
== -1 && low
== -(unsigned HOST_WIDE_INT
)1)
973 /* Look for it in the type's vector of small shared ints. */
974 if (!TYPE_CACHED_VALUES_P (type
))
976 TYPE_CACHED_VALUES_P (type
) = 1;
977 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
980 t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
);
983 /* Make sure no one is clobbering the shared constant. */
984 gcc_assert (TREE_TYPE (t
) == type
);
985 gcc_assert (TREE_INT_CST_LOW (t
) == low
);
986 gcc_assert (TREE_INT_CST_HIGH (t
) == hi
);
990 /* Create a new shared int. */
991 t
= make_node (INTEGER_CST
);
993 TREE_INT_CST_LOW (t
) = low
;
994 TREE_INT_CST_HIGH (t
) = hi
;
995 TREE_TYPE (t
) = type
;
997 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
1002 /* Use the cache of larger shared ints. */
1005 TREE_INT_CST_LOW (int_cst_node
) = low
;
1006 TREE_INT_CST_HIGH (int_cst_node
) = hi
;
1007 TREE_TYPE (int_cst_node
) = type
;
1009 slot
= htab_find_slot (int_cst_hash_table
, int_cst_node
, INSERT
);
1013 /* Insert this one into the hash table. */
1016 /* Make a new node for next time round. */
1017 int_cst_node
= make_node (INTEGER_CST
);
1024 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1025 and the rest are zeros. */
1028 build_low_bits_mask (tree type
, unsigned bits
)
1030 unsigned HOST_WIDE_INT low
;
1032 unsigned HOST_WIDE_INT all_ones
= ~(unsigned HOST_WIDE_INT
) 0;
1034 gcc_assert (bits
<= TYPE_PRECISION (type
));
1036 if (bits
== TYPE_PRECISION (type
)
1037 && !TYPE_UNSIGNED (type
))
1039 /* Sign extended all-ones mask. */
1043 else if (bits
<= HOST_BITS_PER_WIDE_INT
)
1045 low
= all_ones
>> (HOST_BITS_PER_WIDE_INT
- bits
);
1050 bits
-= HOST_BITS_PER_WIDE_INT
;
1052 high
= all_ones
>> (HOST_BITS_PER_WIDE_INT
- bits
);
1055 return build_int_cst_wide (type
, low
, high
);
1058 /* Checks that X is integer constant that can be expressed in (unsigned)
1059 HOST_WIDE_INT without loss of precision. */
1062 cst_and_fits_in_hwi (const_tree x
)
1064 if (TREE_CODE (x
) != INTEGER_CST
)
1067 if (TYPE_PRECISION (TREE_TYPE (x
)) > HOST_BITS_PER_WIDE_INT
)
1070 return (TREE_INT_CST_HIGH (x
) == 0
1071 || TREE_INT_CST_HIGH (x
) == -1);
1074 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1075 are in a list pointed to by VALS. */
1078 build_vector (tree type
, tree vals
)
1080 tree v
= make_node (VECTOR_CST
);
1084 TREE_VECTOR_CST_ELTS (v
) = vals
;
1085 TREE_TYPE (v
) = type
;
1087 /* Iterate through elements and check for overflow. */
1088 for (link
= vals
; link
; link
= TREE_CHAIN (link
))
1090 tree value
= TREE_VALUE (link
);
1092 /* Don't crash if we get an address constant. */
1093 if (!CONSTANT_CLASS_P (value
))
1096 over
|= TREE_OVERFLOW (value
);
1099 TREE_OVERFLOW (v
) = over
;
1103 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1104 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1107 build_vector_from_ctor (tree type
, VEC(constructor_elt
,gc
) *v
)
1109 tree list
= NULL_TREE
;
1110 unsigned HOST_WIDE_INT idx
;
1113 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1114 list
= tree_cons (NULL_TREE
, value
, list
);
1115 return build_vector (type
, nreverse (list
));
1118 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1119 are in the VEC pointed to by VALS. */
1121 build_constructor (tree type
, VEC(constructor_elt
,gc
) *vals
)
1123 tree c
= make_node (CONSTRUCTOR
);
1124 TREE_TYPE (c
) = type
;
1125 CONSTRUCTOR_ELTS (c
) = vals
;
1129 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1132 build_constructor_single (tree type
, tree index
, tree value
)
1134 VEC(constructor_elt
,gc
) *v
;
1135 constructor_elt
*elt
;
1138 v
= VEC_alloc (constructor_elt
, gc
, 1);
1139 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
1143 t
= build_constructor (type
, v
);
1144 TREE_CONSTANT (t
) = TREE_CONSTANT (value
);
1149 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1150 are in a list pointed to by VALS. */
1152 build_constructor_from_list (tree type
, tree vals
)
1155 VEC(constructor_elt
,gc
) *v
= NULL
;
1156 bool constant_p
= true;
1160 v
= VEC_alloc (constructor_elt
, gc
, list_length (vals
));
1161 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
1163 constructor_elt
*elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
1164 val
= TREE_VALUE (t
);
1165 elt
->index
= TREE_PURPOSE (t
);
1167 if (!TREE_CONSTANT (val
))
1172 t
= build_constructor (type
, v
);
1173 TREE_CONSTANT (t
) = constant_p
;
1177 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1180 build_fixed (tree type
, FIXED_VALUE_TYPE f
)
1183 FIXED_VALUE_TYPE
*fp
;
1185 v
= make_node (FIXED_CST
);
1186 fp
= GGC_NEW (FIXED_VALUE_TYPE
);
1187 memcpy (fp
, &f
, sizeof (FIXED_VALUE_TYPE
));
1189 TREE_TYPE (v
) = type
;
1190 TREE_FIXED_CST_PTR (v
) = fp
;
1194 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1197 build_real (tree type
, REAL_VALUE_TYPE d
)
1200 REAL_VALUE_TYPE
*dp
;
1203 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1204 Consider doing it via real_convert now. */
1206 v
= make_node (REAL_CST
);
1207 dp
= GGC_NEW (REAL_VALUE_TYPE
);
1208 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
1210 TREE_TYPE (v
) = type
;
1211 TREE_REAL_CST_PTR (v
) = dp
;
1212 TREE_OVERFLOW (v
) = overflow
;
1216 /* Return a new REAL_CST node whose type is TYPE
1217 and whose value is the integer value of the INTEGER_CST node I. */
1220 real_value_from_int_cst (const_tree type
, const_tree i
)
1224 /* Clear all bits of the real value type so that we can later do
1225 bitwise comparisons to see if two values are the same. */
1226 memset (&d
, 0, sizeof d
);
1228 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
,
1229 TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
),
1230 TYPE_UNSIGNED (TREE_TYPE (i
)));
1234 /* Given a tree representing an integer constant I, return a tree
1235 representing the same value as a floating-point constant of type TYPE. */
1238 build_real_from_int_cst (tree type
, const_tree i
)
1241 int overflow
= TREE_OVERFLOW (i
);
1243 v
= build_real (type
, real_value_from_int_cst (type
, i
));
1245 TREE_OVERFLOW (v
) |= overflow
;
1249 /* Return a newly constructed STRING_CST node whose value is
1250 the LEN characters at STR.
1251 The TREE_TYPE is not initialized. */
1254 build_string (int len
, const char *str
)
1259 /* Do not waste bytes provided by padding of struct tree_string. */
1260 length
= len
+ offsetof (struct tree_string
, str
) + 1;
1262 #ifdef GATHER_STATISTICS
1263 tree_node_counts
[(int) c_kind
]++;
1264 tree_node_sizes
[(int) c_kind
] += length
;
1267 s
= ggc_alloc_tree (length
);
1269 memset (s
, 0, sizeof (struct tree_common
));
1270 TREE_SET_CODE (s
, STRING_CST
);
1271 TREE_CONSTANT (s
) = 1;
1272 TREE_STRING_LENGTH (s
) = len
;
1273 memcpy (s
->string
.str
, str
, len
);
1274 s
->string
.str
[len
] = '\0';
1279 /* Return a newly constructed COMPLEX_CST node whose value is
1280 specified by the real and imaginary parts REAL and IMAG.
1281 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1282 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1285 build_complex (tree type
, tree real
, tree imag
)
1287 tree t
= make_node (COMPLEX_CST
);
1289 TREE_REALPART (t
) = real
;
1290 TREE_IMAGPART (t
) = imag
;
1291 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
1292 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1296 /* Return a constant of arithmetic type TYPE which is the
1297 multiplicative identity of the set TYPE. */
1300 build_one_cst (tree type
)
1302 switch (TREE_CODE (type
))
1304 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1305 case POINTER_TYPE
: case REFERENCE_TYPE
:
1307 return build_int_cst (type
, 1);
1310 return build_real (type
, dconst1
);
1312 case FIXED_POINT_TYPE
:
1313 /* We can only generate 1 for accum types. */
1314 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
1315 return build_fixed (type
, FCONST1(TYPE_MODE (type
)));
1322 scalar
= build_one_cst (TREE_TYPE (type
));
1324 /* Create 'vect_cst_ = {cst,cst,...,cst}' */
1326 for (i
= TYPE_VECTOR_SUBPARTS (type
); --i
>= 0; )
1327 cst
= tree_cons (NULL_TREE
, scalar
, cst
);
1329 return build_vector (type
, cst
);
1333 return build_complex (type
,
1334 build_one_cst (TREE_TYPE (type
)),
1335 fold_convert (TREE_TYPE (type
), integer_zero_node
));
1342 /* Build a BINFO with LEN language slots. */
1345 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL
)
1348 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
1349 + VEC_embedded_size (tree
, base_binfos
));
1351 #ifdef GATHER_STATISTICS
1352 tree_node_counts
[(int) binfo_kind
]++;
1353 tree_node_sizes
[(int) binfo_kind
] += length
;
1356 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
1358 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
1360 TREE_SET_CODE (t
, TREE_BINFO
);
1362 VEC_embedded_init (tree
, BINFO_BASE_BINFOS (t
), base_binfos
);
1368 /* Build a newly constructed TREE_VEC node of length LEN. */
1371 make_tree_vec_stat (int len MEM_STAT_DECL
)
1374 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
1376 #ifdef GATHER_STATISTICS
1377 tree_node_counts
[(int) vec_kind
]++;
1378 tree_node_sizes
[(int) vec_kind
] += length
;
1381 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
1383 memset (t
, 0, length
);
1385 TREE_SET_CODE (t
, TREE_VEC
);
1386 TREE_VEC_LENGTH (t
) = len
;
1391 /* Return 1 if EXPR is the integer constant zero or a complex constant
1395 integer_zerop (const_tree expr
)
1399 return ((TREE_CODE (expr
) == INTEGER_CST
1400 && TREE_INT_CST_LOW (expr
) == 0
1401 && TREE_INT_CST_HIGH (expr
) == 0)
1402 || (TREE_CODE (expr
) == COMPLEX_CST
1403 && integer_zerop (TREE_REALPART (expr
))
1404 && integer_zerop (TREE_IMAGPART (expr
))));
1407 /* Return 1 if EXPR is the integer constant one or the corresponding
1408 complex constant. */
1411 integer_onep (const_tree expr
)
1415 return ((TREE_CODE (expr
) == INTEGER_CST
1416 && TREE_INT_CST_LOW (expr
) == 1
1417 && TREE_INT_CST_HIGH (expr
) == 0)
1418 || (TREE_CODE (expr
) == COMPLEX_CST
1419 && integer_onep (TREE_REALPART (expr
))
1420 && integer_zerop (TREE_IMAGPART (expr
))));
1423 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1424 it contains. Likewise for the corresponding complex constant. */
1427 integer_all_onesp (const_tree expr
)
1434 if (TREE_CODE (expr
) == COMPLEX_CST
1435 && integer_all_onesp (TREE_REALPART (expr
))
1436 && integer_zerop (TREE_IMAGPART (expr
)))
1439 else if (TREE_CODE (expr
) != INTEGER_CST
)
1442 uns
= TYPE_UNSIGNED (TREE_TYPE (expr
));
1443 if (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1444 && TREE_INT_CST_HIGH (expr
) == -1)
1449 /* Note that using TYPE_PRECISION here is wrong. We care about the
1450 actual bits, not the (arbitrary) range of the type. */
1451 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr
)));
1452 if (prec
>= HOST_BITS_PER_WIDE_INT
)
1454 HOST_WIDE_INT high_value
;
1457 shift_amount
= prec
- HOST_BITS_PER_WIDE_INT
;
1459 /* Can not handle precisions greater than twice the host int size. */
1460 gcc_assert (shift_amount
<= HOST_BITS_PER_WIDE_INT
);
1461 if (shift_amount
== HOST_BITS_PER_WIDE_INT
)
1462 /* Shifting by the host word size is undefined according to the ANSI
1463 standard, so we must handle this as a special case. */
1466 high_value
= ((HOST_WIDE_INT
) 1 << shift_amount
) - 1;
1468 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1469 && TREE_INT_CST_HIGH (expr
) == high_value
);
1472 return TREE_INT_CST_LOW (expr
) == ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
1475 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1479 integer_pow2p (const_tree expr
)
1482 HOST_WIDE_INT high
, low
;
1486 if (TREE_CODE (expr
) == COMPLEX_CST
1487 && integer_pow2p (TREE_REALPART (expr
))
1488 && integer_zerop (TREE_IMAGPART (expr
)))
1491 if (TREE_CODE (expr
) != INTEGER_CST
)
1494 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1495 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1496 high
= TREE_INT_CST_HIGH (expr
);
1497 low
= TREE_INT_CST_LOW (expr
);
1499 /* First clear all bits that are beyond the type's precision in case
1500 we've been sign extended. */
1502 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1504 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1505 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1509 if (prec
< HOST_BITS_PER_WIDE_INT
)
1510 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1513 if (high
== 0 && low
== 0)
1516 return ((high
== 0 && (low
& (low
- 1)) == 0)
1517 || (low
== 0 && (high
& (high
- 1)) == 0));
1520 /* Return 1 if EXPR is an integer constant other than zero or a
1521 complex constant other than zero. */
1524 integer_nonzerop (const_tree expr
)
1528 return ((TREE_CODE (expr
) == INTEGER_CST
1529 && (TREE_INT_CST_LOW (expr
) != 0
1530 || TREE_INT_CST_HIGH (expr
) != 0))
1531 || (TREE_CODE (expr
) == COMPLEX_CST
1532 && (integer_nonzerop (TREE_REALPART (expr
))
1533 || integer_nonzerop (TREE_IMAGPART (expr
)))));
1536 /* Return 1 if EXPR is the fixed-point constant zero. */
1539 fixed_zerop (const_tree expr
)
1541 return (TREE_CODE (expr
) == FIXED_CST
1542 && double_int_zero_p (TREE_FIXED_CST (expr
).data
));
1545 /* Return the power of two represented by a tree node known to be a
1549 tree_log2 (const_tree expr
)
1552 HOST_WIDE_INT high
, low
;
1556 if (TREE_CODE (expr
) == COMPLEX_CST
)
1557 return tree_log2 (TREE_REALPART (expr
));
1559 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1560 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1562 high
= TREE_INT_CST_HIGH (expr
);
1563 low
= TREE_INT_CST_LOW (expr
);
1565 /* First clear all bits that are beyond the type's precision in case
1566 we've been sign extended. */
1568 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
)
1570 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1571 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1575 if (prec
< HOST_BITS_PER_WIDE_INT
)
1576 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1579 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ exact_log2 (high
)
1580 : exact_log2 (low
));
1583 /* Similar, but return the largest integer Y such that 2 ** Y is less
1584 than or equal to EXPR. */
1587 tree_floor_log2 (const_tree expr
)
1590 HOST_WIDE_INT high
, low
;
1594 if (TREE_CODE (expr
) == COMPLEX_CST
)
1595 return tree_log2 (TREE_REALPART (expr
));
1597 prec
= (POINTER_TYPE_P (TREE_TYPE (expr
))
1598 ? POINTER_SIZE
: TYPE_PRECISION (TREE_TYPE (expr
)));
1600 high
= TREE_INT_CST_HIGH (expr
);
1601 low
= TREE_INT_CST_LOW (expr
);
1603 /* First clear all bits that are beyond the type's precision in case
1604 we've been sign extended. Ignore if type's precision hasn't been set
1605 since what we are doing is setting it. */
1607 if (prec
== 2 * HOST_BITS_PER_WIDE_INT
|| prec
== 0)
1609 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1610 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1614 if (prec
< HOST_BITS_PER_WIDE_INT
)
1615 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1618 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ floor_log2 (high
)
1619 : floor_log2 (low
));
1622 /* Return 1 if EXPR is the real constant zero. */
1625 real_zerop (const_tree expr
)
1629 return ((TREE_CODE (expr
) == REAL_CST
1630 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
))
1631 || (TREE_CODE (expr
) == COMPLEX_CST
1632 && real_zerop (TREE_REALPART (expr
))
1633 && real_zerop (TREE_IMAGPART (expr
))));
1636 /* Return 1 if EXPR is the real constant one in real or complex form. */
1639 real_onep (const_tree expr
)
1643 return ((TREE_CODE (expr
) == REAL_CST
1644 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
))
1645 || (TREE_CODE (expr
) == COMPLEX_CST
1646 && real_onep (TREE_REALPART (expr
))
1647 && real_zerop (TREE_IMAGPART (expr
))));
1650 /* Return 1 if EXPR is the real constant two. */
1653 real_twop (const_tree expr
)
1657 return ((TREE_CODE (expr
) == REAL_CST
1658 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst2
))
1659 || (TREE_CODE (expr
) == COMPLEX_CST
1660 && real_twop (TREE_REALPART (expr
))
1661 && real_zerop (TREE_IMAGPART (expr
))));
1664 /* Return 1 if EXPR is the real constant minus one. */
1667 real_minus_onep (const_tree expr
)
1671 return ((TREE_CODE (expr
) == REAL_CST
1672 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconstm1
))
1673 || (TREE_CODE (expr
) == COMPLEX_CST
1674 && real_minus_onep (TREE_REALPART (expr
))
1675 && real_zerop (TREE_IMAGPART (expr
))));
1678 /* Nonzero if EXP is a constant or a cast of a constant. */
1681 really_constant_p (const_tree exp
)
1683 /* This is not quite the same as STRIP_NOPS. It does more. */
1684 while (CONVERT_EXPR_P (exp
)
1685 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
1686 exp
= TREE_OPERAND (exp
, 0);
1687 return TREE_CONSTANT (exp
);
1690 /* Return first list element whose TREE_VALUE is ELEM.
1691 Return 0 if ELEM is not in LIST. */
1694 value_member (tree elem
, tree list
)
1698 if (elem
== TREE_VALUE (list
))
1700 list
= TREE_CHAIN (list
);
1705 /* Return first list element whose TREE_PURPOSE is ELEM.
1706 Return 0 if ELEM is not in LIST. */
1709 purpose_member (const_tree elem
, tree list
)
1713 if (elem
== TREE_PURPOSE (list
))
1715 list
= TREE_CHAIN (list
);
1720 /* Return nonzero if ELEM is part of the chain CHAIN. */
1723 chain_member (const_tree elem
, const_tree chain
)
1729 chain
= TREE_CHAIN (chain
);
1735 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1736 We expect a null pointer to mark the end of the chain.
1737 This is the Lisp primitive `length'. */
1740 list_length (const_tree t
)
1743 #ifdef ENABLE_TREE_CHECKING
1751 #ifdef ENABLE_TREE_CHECKING
1754 gcc_assert (p
!= q
);
1762 /* Returns the number of FIELD_DECLs in TYPE. */
1765 fields_length (const_tree type
)
1767 tree t
= TYPE_FIELDS (type
);
1770 for (; t
; t
= TREE_CHAIN (t
))
1771 if (TREE_CODE (t
) == FIELD_DECL
)
1777 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1778 by modifying the last node in chain 1 to point to chain 2.
1779 This is the Lisp primitive `nconc'. */
1782 chainon (tree op1
, tree op2
)
1791 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
1793 TREE_CHAIN (t1
) = op2
;
1795 #ifdef ENABLE_TREE_CHECKING
1798 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
1799 gcc_assert (t2
!= t1
);
1806 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1809 tree_last (tree chain
)
1813 while ((next
= TREE_CHAIN (chain
)))
1818 /* Reverse the order of elements in the chain T,
1819 and return the new head of the chain (old last element). */
1824 tree prev
= 0, decl
, next
;
1825 for (decl
= t
; decl
; decl
= next
)
1827 next
= TREE_CHAIN (decl
);
1828 TREE_CHAIN (decl
) = prev
;
1834 /* Return a newly created TREE_LIST node whose
1835 purpose and value fields are PARM and VALUE. */
1838 build_tree_list_stat (tree parm
, tree value MEM_STAT_DECL
)
1840 tree t
= make_node_stat (TREE_LIST PASS_MEM_STAT
);
1841 TREE_PURPOSE (t
) = parm
;
1842 TREE_VALUE (t
) = value
;
1846 /* Return a newly created TREE_LIST node whose
1847 purpose and value fields are PURPOSE and VALUE
1848 and whose TREE_CHAIN is CHAIN. */
1851 tree_cons_stat (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
1855 node
= (tree
) ggc_alloc_zone_pass_stat (sizeof (struct tree_list
), &tree_zone
);
1857 memset (node
, 0, sizeof (struct tree_common
));
1859 #ifdef GATHER_STATISTICS
1860 tree_node_counts
[(int) x_kind
]++;
1861 tree_node_sizes
[(int) x_kind
] += sizeof (struct tree_list
);
1864 TREE_SET_CODE (node
, TREE_LIST
);
1865 TREE_CHAIN (node
) = chain
;
1866 TREE_PURPOSE (node
) = purpose
;
1867 TREE_VALUE (node
) = value
;
1871 /* Return the elements of a CONSTRUCTOR as a TREE_LIST. */
1874 ctor_to_list (tree ctor
)
1876 tree list
= NULL_TREE
;
1881 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), ix
, purpose
, val
)
1883 *p
= build_tree_list (purpose
, val
);
1884 p
= &TREE_CHAIN (*p
);
1890 /* Return the size nominally occupied by an object of type TYPE
1891 when it resides in memory. The value is measured in units of bytes,
1892 and its data type is that normally used for type sizes
1893 (which is the first type created by make_signed_type or
1894 make_unsigned_type). */
1897 size_in_bytes (const_tree type
)
1901 if (type
== error_mark_node
)
1902 return integer_zero_node
;
1904 type
= TYPE_MAIN_VARIANT (type
);
1905 t
= TYPE_SIZE_UNIT (type
);
1909 lang_hooks
.types
.incomplete_type_error (NULL_TREE
, type
);
1910 return size_zero_node
;
1916 /* Return the size of TYPE (in bytes) as a wide integer
1917 or return -1 if the size can vary or is larger than an integer. */
1920 int_size_in_bytes (const_tree type
)
1924 if (type
== error_mark_node
)
1927 type
= TYPE_MAIN_VARIANT (type
);
1928 t
= TYPE_SIZE_UNIT (type
);
1930 || TREE_CODE (t
) != INTEGER_CST
1931 || TREE_INT_CST_HIGH (t
) != 0
1932 /* If the result would appear negative, it's too big to represent. */
1933 || (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0)
1936 return TREE_INT_CST_LOW (t
);
1939 /* Return the maximum size of TYPE (in bytes) as a wide integer
1940 or return -1 if the size can vary or is larger than an integer. */
1943 max_int_size_in_bytes (const_tree type
)
1945 HOST_WIDE_INT size
= -1;
1948 /* If this is an array type, check for a possible MAX_SIZE attached. */
1950 if (TREE_CODE (type
) == ARRAY_TYPE
)
1952 size_tree
= TYPE_ARRAY_MAX_SIZE (type
);
1954 if (size_tree
&& host_integerp (size_tree
, 1))
1955 size
= tree_low_cst (size_tree
, 1);
1958 /* If we still haven't been able to get a size, see if the language
1959 can compute a maximum size. */
1963 size_tree
= lang_hooks
.types
.max_size (type
);
1965 if (size_tree
&& host_integerp (size_tree
, 1))
1966 size
= tree_low_cst (size_tree
, 1);
1972 /* Return the bit position of FIELD, in bits from the start of the record.
1973 This is a tree of type bitsizetype. */
1976 bit_position (const_tree field
)
1978 return bit_from_pos (DECL_FIELD_OFFSET (field
),
1979 DECL_FIELD_BIT_OFFSET (field
));
1982 /* Likewise, but return as an integer. It must be representable in
1983 that way (since it could be a signed value, we don't have the
1984 option of returning -1 like int_size_in_byte can. */
1987 int_bit_position (const_tree field
)
1989 return tree_low_cst (bit_position (field
), 0);
1992 /* Return the byte position of FIELD, in bytes from the start of the record.
1993 This is a tree of type sizetype. */
1996 byte_position (const_tree field
)
1998 return byte_from_pos (DECL_FIELD_OFFSET (field
),
1999 DECL_FIELD_BIT_OFFSET (field
));
2002 /* Likewise, but return as an integer. It must be representable in
2003 that way (since it could be a signed value, we don't have the
2004 option of returning -1 like int_size_in_byte can. */
2007 int_byte_position (const_tree field
)
2009 return tree_low_cst (byte_position (field
), 0);
2012 /* Return the strictest alignment, in bits, that T is known to have. */
2015 expr_align (const_tree t
)
2017 unsigned int align0
, align1
;
2019 switch (TREE_CODE (t
))
2021 CASE_CONVERT
: case NON_LVALUE_EXPR
:
2022 /* If we have conversions, we know that the alignment of the
2023 object must meet each of the alignments of the types. */
2024 align0
= expr_align (TREE_OPERAND (t
, 0));
2025 align1
= TYPE_ALIGN (TREE_TYPE (t
));
2026 return MAX (align0
, align1
);
2028 case GIMPLE_MODIFY_STMT
:
2029 /* We should never ask for the alignment of a gimple statement. */
2032 case SAVE_EXPR
: case COMPOUND_EXPR
: case MODIFY_EXPR
:
2033 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
2034 case CLEANUP_POINT_EXPR
:
2035 /* These don't change the alignment of an object. */
2036 return expr_align (TREE_OPERAND (t
, 0));
2039 /* The best we can do is say that the alignment is the least aligned
2041 align0
= expr_align (TREE_OPERAND (t
, 1));
2042 align1
= expr_align (TREE_OPERAND (t
, 2));
2043 return MIN (align0
, align1
);
2045 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2046 meaningfully, it's always 1. */
2047 case LABEL_DECL
: case CONST_DECL
:
2048 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
2050 gcc_assert (DECL_ALIGN (t
) != 0);
2051 return DECL_ALIGN (t
);
2057 /* Otherwise take the alignment from that of the type. */
2058 return TYPE_ALIGN (TREE_TYPE (t
));
2061 /* Return, as a tree node, the number of elements for TYPE (which is an
2062 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2065 array_type_nelts (const_tree type
)
2067 tree index_type
, min
, max
;
2069 /* If they did it with unspecified bounds, then we should have already
2070 given an error about it before we got here. */
2071 if (! TYPE_DOMAIN (type
))
2072 return error_mark_node
;
2074 index_type
= TYPE_DOMAIN (type
);
2075 min
= TYPE_MIN_VALUE (index_type
);
2076 max
= TYPE_MAX_VALUE (index_type
);
2078 return (integer_zerop (min
)
2080 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
2083 /* If arg is static -- a reference to an object in static storage -- then
2084 return the object. This is not the same as the C meaning of `static'.
2085 If arg isn't static, return NULL. */
2090 switch (TREE_CODE (arg
))
2093 /* Nested functions are static, even though taking their address will
2094 involve a trampoline as we unnest the nested function and create
2095 the trampoline on the tree level. */
2099 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2100 && ! DECL_THREAD_LOCAL_P (arg
)
2101 && ! DECL_DLLIMPORT_P (arg
)
2105 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2109 return TREE_STATIC (arg
) ? arg
: NULL
;
2116 /* If the thing being referenced is not a field, then it is
2117 something language specific. */
2118 if (TREE_CODE (TREE_OPERAND (arg
, 1)) != FIELD_DECL
)
2119 return (*lang_hooks
.staticp
) (arg
);
2121 /* If we are referencing a bitfield, we can't evaluate an
2122 ADDR_EXPR at compile time and so it isn't a constant. */
2123 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
2126 return staticp (TREE_OPERAND (arg
, 0));
2131 case MISALIGNED_INDIRECT_REF
:
2132 case ALIGN_INDIRECT_REF
:
2134 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
2137 case ARRAY_RANGE_REF
:
2138 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
2139 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
2140 return staticp (TREE_OPERAND (arg
, 0));
2145 if ((unsigned int) TREE_CODE (arg
)
2146 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
2147 return lang_hooks
.staticp (arg
);
2156 /* Return whether OP is a DECL whose address is function-invariant. */
2159 decl_address_invariant_p (const_tree op
)
2161 /* The conditions below are slightly less strict than the one in
2164 switch (TREE_CODE (op
))
2173 if (((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2174 && !DECL_DLLIMPORT_P (op
))
2175 || DECL_THREAD_LOCAL_P (op
)
2176 || DECL_CONTEXT (op
) == current_function_decl
2177 || decl_function_context (op
) == current_function_decl
)
2182 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2183 || decl_function_context (op
) == current_function_decl
)
2195 /* Return true if T is function-invariant (internal function, does
2196 not handle arithmetic; that's handled in skip_simple_arithmetic and
2197 tree_invariant_p). */
2199 static bool tree_invariant_p (tree t
);
2202 tree_invariant_p_1 (tree t
)
2206 if (TREE_CONSTANT (t
)
2207 || (TREE_READONLY (t
) && !TREE_SIDE_EFFECTS (t
)))
2210 switch (TREE_CODE (t
))
2216 op
= TREE_OPERAND (t
, 0);
2217 while (handled_component_p (op
))
2219 switch (TREE_CODE (op
))
2222 case ARRAY_RANGE_REF
:
2223 if (!tree_invariant_p (TREE_OPERAND (op
, 1))
2224 || TREE_OPERAND (op
, 2) != NULL_TREE
2225 || TREE_OPERAND (op
, 3) != NULL_TREE
)
2230 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
2236 op
= TREE_OPERAND (op
, 0);
2239 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
2248 /* Return true if T is function-invariant. */
2251 tree_invariant_p (tree t
)
2253 tree inner
= skip_simple_arithmetic (t
);
2254 return tree_invariant_p_1 (inner
);
2257 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2258 Do this to any expression which may be used in more than one place,
2259 but must be evaluated only once.
2261 Normally, expand_expr would reevaluate the expression each time.
2262 Calling save_expr produces something that is evaluated and recorded
2263 the first time expand_expr is called on it. Subsequent calls to
2264 expand_expr just reuse the recorded value.
2266 The call to expand_expr that generates code that actually computes
2267 the value is the first call *at compile time*. Subsequent calls
2268 *at compile time* generate code to use the saved value.
2269 This produces correct result provided that *at run time* control
2270 always flows through the insns made by the first expand_expr
2271 before reaching the other places where the save_expr was evaluated.
2272 You, the caller of save_expr, must make sure this is so.
2274 Constants, and certain read-only nodes, are returned with no
2275 SAVE_EXPR because that is safe. Expressions containing placeholders
2276 are not touched; see tree.def for an explanation of what these
2280 save_expr (tree expr
)
2282 tree t
= fold (expr
);
2285 /* If the tree evaluates to a constant, then we don't want to hide that
2286 fact (i.e. this allows further folding, and direct checks for constants).
2287 However, a read-only object that has side effects cannot be bypassed.
2288 Since it is no problem to reevaluate literals, we just return the
2290 inner
= skip_simple_arithmetic (t
);
2291 if (TREE_CODE (inner
) == ERROR_MARK
)
2294 if (tree_invariant_p_1 (inner
))
2297 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2298 it means that the size or offset of some field of an object depends on
2299 the value within another field.
2301 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2302 and some variable since it would then need to be both evaluated once and
2303 evaluated more than once. Front-ends must assure this case cannot
2304 happen by surrounding any such subexpressions in their own SAVE_EXPR
2305 and forcing evaluation at the proper time. */
2306 if (contains_placeholder_p (inner
))
2309 t
= build1 (SAVE_EXPR
, TREE_TYPE (expr
), t
);
2311 /* This expression might be placed ahead of a jump to ensure that the
2312 value was computed on both sides of the jump. So make sure it isn't
2313 eliminated as dead. */
2314 TREE_SIDE_EFFECTS (t
) = 1;
2318 /* Look inside EXPR and into any simple arithmetic operations. Return
2319 the innermost non-arithmetic node. */
2322 skip_simple_arithmetic (tree expr
)
2326 /* We don't care about whether this can be used as an lvalue in this
2328 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
2329 expr
= TREE_OPERAND (expr
, 0);
2331 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2332 a constant, it will be more efficient to not make another SAVE_EXPR since
2333 it will allow better simplification and GCSE will be able to merge the
2334 computations if they actually occur. */
2338 if (UNARY_CLASS_P (inner
))
2339 inner
= TREE_OPERAND (inner
, 0);
2340 else if (BINARY_CLASS_P (inner
))
2342 if (tree_invariant_p (TREE_OPERAND (inner
, 1)))
2343 inner
= TREE_OPERAND (inner
, 0);
2344 else if (tree_invariant_p (TREE_OPERAND (inner
, 0)))
2345 inner
= TREE_OPERAND (inner
, 1);
2356 /* Return which tree structure is used by T. */
2358 enum tree_node_structure_enum
2359 tree_node_structure (const_tree t
)
2361 const enum tree_code code
= TREE_CODE (t
);
2363 switch (TREE_CODE_CLASS (code
))
2365 case tcc_declaration
:
2370 return TS_FIELD_DECL
;
2372 return TS_PARM_DECL
;
2376 return TS_LABEL_DECL
;
2378 return TS_RESULT_DECL
;
2380 return TS_CONST_DECL
;
2382 return TS_TYPE_DECL
;
2384 return TS_FUNCTION_DECL
;
2385 case SYMBOL_MEMORY_TAG
:
2386 case NAME_MEMORY_TAG
:
2387 case MEMORY_PARTITION_TAG
:
2388 return TS_MEMORY_TAG
;
2390 return TS_DECL_NON_COMMON
;
2396 case tcc_comparison
:
2399 case tcc_expression
:
2403 case tcc_gimple_stmt
:
2404 return TS_GIMPLE_STATEMENT
;
2405 default: /* tcc_constant and tcc_exceptional */
2410 /* tcc_constant cases. */
2411 case INTEGER_CST
: return TS_INT_CST
;
2412 case REAL_CST
: return TS_REAL_CST
;
2413 case FIXED_CST
: return TS_FIXED_CST
;
2414 case COMPLEX_CST
: return TS_COMPLEX
;
2415 case VECTOR_CST
: return TS_VECTOR
;
2416 case STRING_CST
: return TS_STRING
;
2417 /* tcc_exceptional cases. */
2418 /* FIXME tuples: eventually this should be TS_BASE. For now, nothing
2420 case ERROR_MARK
: return TS_COMMON
;
2421 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
2422 case TREE_LIST
: return TS_LIST
;
2423 case TREE_VEC
: return TS_VEC
;
2424 case PHI_NODE
: return TS_PHI_NODE
;
2425 case SSA_NAME
: return TS_SSA_NAME
;
2426 case PLACEHOLDER_EXPR
: return TS_COMMON
;
2427 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
2428 case BLOCK
: return TS_BLOCK
;
2429 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
2430 case TREE_BINFO
: return TS_BINFO
;
2431 case OMP_CLAUSE
: return TS_OMP_CLAUSE
;
2438 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2439 or offset that depends on a field within a record. */
2442 contains_placeholder_p (const_tree exp
)
2444 enum tree_code code
;
2449 code
= TREE_CODE (exp
);
2450 if (code
== PLACEHOLDER_EXPR
)
2453 switch (TREE_CODE_CLASS (code
))
2456 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2457 position computations since they will be converted into a
2458 WITH_RECORD_EXPR involving the reference, which will assume
2459 here will be valid. */
2460 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2462 case tcc_exceptional
:
2463 if (code
== TREE_LIST
)
2464 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
2465 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
2470 case tcc_comparison
:
2471 case tcc_expression
:
2475 /* Ignoring the first operand isn't quite right, but works best. */
2476 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
2479 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2480 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
2481 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
2487 switch (TREE_CODE_LENGTH (code
))
2490 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
2492 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
2493 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
2504 const_call_expr_arg_iterator iter
;
2505 FOR_EACH_CONST_CALL_EXPR_ARG (arg
, iter
, exp
)
2506 if (CONTAINS_PLACEHOLDER_P (arg
))
2520 /* Return true if any part of the computation of TYPE involves a
2521 PLACEHOLDER_EXPR. This includes size, bounds, qualifiers
2522 (for QUAL_UNION_TYPE) and field positions. */
2525 type_contains_placeholder_1 (const_tree type
)
2527 /* If the size contains a placeholder or the parent type (component type in
2528 the case of arrays) type involves a placeholder, this type does. */
2529 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
2530 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
2531 || (TREE_TYPE (type
) != 0
2532 && type_contains_placeholder_p (TREE_TYPE (type
))))
2535 /* Now do type-specific checks. Note that the last part of the check above
2536 greatly limits what we have to do below. */
2537 switch (TREE_CODE (type
))
2545 case REFERENCE_TYPE
:
2553 case FIXED_POINT_TYPE
:
2554 /* Here we just check the bounds. */
2555 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
2556 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
2559 /* We're already checked the component type (TREE_TYPE), so just check
2561 return type_contains_placeholder_p (TYPE_DOMAIN (type
));
2565 case QUAL_UNION_TYPE
:
2569 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2570 if (TREE_CODE (field
) == FIELD_DECL
2571 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
2572 || (TREE_CODE (type
) == QUAL_UNION_TYPE
2573 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
2574 || type_contains_placeholder_p (TREE_TYPE (field
))))
2586 type_contains_placeholder_p (tree type
)
2590 /* If the contains_placeholder_bits field has been initialized,
2591 then we know the answer. */
2592 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
2593 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
2595 /* Indicate that we've seen this type node, and the answer is false.
2596 This is what we want to return if we run into recursion via fields. */
2597 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
2599 /* Compute the real value. */
2600 result
= type_contains_placeholder_1 (type
);
2602 /* Store the real value. */
2603 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
2608 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2609 return a tree with all occurrences of references to F in a
2610 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2611 contains only arithmetic expressions or a CALL_EXPR with a
2612 PLACEHOLDER_EXPR occurring only in its arglist. */
2615 substitute_in_expr (tree exp
, tree f
, tree r
)
2617 enum tree_code code
= TREE_CODE (exp
);
2618 tree op0
, op1
, op2
, op3
;
2621 /* We handle TREE_LIST and COMPONENT_REF separately. */
2622 if (code
== TREE_LIST
)
2624 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
2625 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
2626 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
2629 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
2631 else if (code
== COMPONENT_REF
)
2633 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2634 and it is the right field, replace it with R. */
2635 for (inner
= TREE_OPERAND (exp
, 0);
2636 REFERENCE_CLASS_P (inner
);
2637 inner
= TREE_OPERAND (inner
, 0))
2639 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
2640 && TREE_OPERAND (exp
, 1) == f
)
2643 /* If this expression hasn't been completed let, leave it alone. */
2644 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& TREE_TYPE (inner
) == 0)
2647 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2648 if (op0
== TREE_OPERAND (exp
, 0))
2651 new = fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
),
2652 op0
, TREE_OPERAND (exp
, 1), NULL_TREE
);
2655 switch (TREE_CODE_CLASS (code
))
2658 case tcc_declaration
:
2661 case tcc_exceptional
:
2664 case tcc_comparison
:
2665 case tcc_expression
:
2667 switch (TREE_CODE_LENGTH (code
))
2673 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2674 if (op0
== TREE_OPERAND (exp
, 0))
2677 new = fold_build1 (code
, TREE_TYPE (exp
), op0
);
2681 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2682 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2684 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
2687 new = fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
2691 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2692 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2693 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
2695 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2696 && op2
== TREE_OPERAND (exp
, 2))
2699 new = fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
2703 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
2704 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
2705 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
2706 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
2708 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2709 && op2
== TREE_OPERAND (exp
, 2)
2710 && op3
== TREE_OPERAND (exp
, 3))
2713 new = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
2723 tree copy
= NULL_TREE
;
2726 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
2728 tree op
= TREE_OPERAND (exp
, i
);
2729 tree new_op
= SUBSTITUTE_IN_EXPR (op
, f
, r
);
2733 copy
= copy_node (exp
);
2734 TREE_OPERAND (copy
, i
) = new_op
;
2749 TREE_READONLY (new) = TREE_READONLY (exp
);
2753 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
2754 for it within OBJ, a tree that is an object or a chain of references. */
2757 substitute_placeholder_in_expr (tree exp
, tree obj
)
2759 enum tree_code code
= TREE_CODE (exp
);
2760 tree op0
, op1
, op2
, op3
;
2762 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
2763 in the chain of OBJ. */
2764 if (code
== PLACEHOLDER_EXPR
)
2766 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
2769 for (elt
= obj
; elt
!= 0;
2770 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
2771 || TREE_CODE (elt
) == COND_EXPR
)
2772 ? TREE_OPERAND (elt
, 1)
2773 : (REFERENCE_CLASS_P (elt
)
2774 || UNARY_CLASS_P (elt
)
2775 || BINARY_CLASS_P (elt
)
2776 || VL_EXP_CLASS_P (elt
)
2777 || EXPRESSION_CLASS_P (elt
))
2778 ? TREE_OPERAND (elt
, 0) : 0))
2779 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
2782 for (elt
= obj
; elt
!= 0;
2783 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
2784 || TREE_CODE (elt
) == COND_EXPR
)
2785 ? TREE_OPERAND (elt
, 1)
2786 : (REFERENCE_CLASS_P (elt
)
2787 || UNARY_CLASS_P (elt
)
2788 || BINARY_CLASS_P (elt
)
2789 || VL_EXP_CLASS_P (elt
)
2790 || EXPRESSION_CLASS_P (elt
))
2791 ? TREE_OPERAND (elt
, 0) : 0))
2792 if (POINTER_TYPE_P (TREE_TYPE (elt
))
2793 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
2795 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
2797 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2798 survives until RTL generation, there will be an error. */
2802 /* TREE_LIST is special because we need to look at TREE_VALUE
2803 and TREE_CHAIN, not TREE_OPERANDS. */
2804 else if (code
== TREE_LIST
)
2806 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
2807 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
2808 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
2811 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
2814 switch (TREE_CODE_CLASS (code
))
2817 case tcc_declaration
:
2820 case tcc_exceptional
:
2823 case tcc_comparison
:
2824 case tcc_expression
:
2827 switch (TREE_CODE_LENGTH (code
))
2833 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2834 if (op0
== TREE_OPERAND (exp
, 0))
2837 return fold_build1 (code
, TREE_TYPE (exp
), op0
);
2840 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2841 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2843 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
2846 return fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
2849 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2850 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2851 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
2853 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2854 && op2
== TREE_OPERAND (exp
, 2))
2857 return fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
2860 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
2861 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
2862 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
2863 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
2865 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
2866 && op2
== TREE_OPERAND (exp
, 2)
2867 && op3
== TREE_OPERAND (exp
, 3))
2870 return fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
2879 tree copy
= NULL_TREE
;
2882 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
2884 tree op
= TREE_OPERAND (exp
, i
);
2885 tree new_op
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (op
, obj
);
2889 copy
= copy_node (exp
);
2890 TREE_OPERAND (copy
, i
) = new_op
;
2905 /* Stabilize a reference so that we can use it any number of times
2906 without causing its operands to be evaluated more than once.
2907 Returns the stabilized reference. This works by means of save_expr,
2908 so see the caveats in the comments about save_expr.
2910 Also allows conversion expressions whose operands are references.
2911 Any other kind of expression is returned unchanged. */
2914 stabilize_reference (tree ref
)
2917 enum tree_code code
= TREE_CODE (ref
);
2924 /* No action is needed in this case. */
2929 case FIX_TRUNC_EXPR
:
2930 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
2934 result
= build_nt (INDIRECT_REF
,
2935 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
2939 result
= build_nt (COMPONENT_REF
,
2940 stabilize_reference (TREE_OPERAND (ref
, 0)),
2941 TREE_OPERAND (ref
, 1), NULL_TREE
);
2945 result
= build_nt (BIT_FIELD_REF
,
2946 stabilize_reference (TREE_OPERAND (ref
, 0)),
2947 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2948 stabilize_reference_1 (TREE_OPERAND (ref
, 2)));
2952 result
= build_nt (ARRAY_REF
,
2953 stabilize_reference (TREE_OPERAND (ref
, 0)),
2954 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2955 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
2958 case ARRAY_RANGE_REF
:
2959 result
= build_nt (ARRAY_RANGE_REF
,
2960 stabilize_reference (TREE_OPERAND (ref
, 0)),
2961 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2962 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
2966 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2967 it wouldn't be ignored. This matters when dealing with
2969 return stabilize_reference_1 (ref
);
2971 /* If arg isn't a kind of lvalue we recognize, make no change.
2972 Caller should recognize the error for an invalid lvalue. */
2977 return error_mark_node
;
2980 TREE_TYPE (result
) = TREE_TYPE (ref
);
2981 TREE_READONLY (result
) = TREE_READONLY (ref
);
2982 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
2983 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
2988 /* Subroutine of stabilize_reference; this is called for subtrees of
2989 references. Any expression with side-effects must be put in a SAVE_EXPR
2990 to ensure that it is only evaluated once.
2992 We don't put SAVE_EXPR nodes around everything, because assigning very
2993 simple expressions to temporaries causes us to miss good opportunities
2994 for optimizations. Among other things, the opportunity to fold in the
2995 addition of a constant into an addressing mode often gets lost, e.g.
2996 "y[i+1] += x;". In general, we take the approach that we should not make
2997 an assignment unless we are forced into it - i.e., that any non-side effect
2998 operator should be allowed, and that cse should take care of coalescing
2999 multiple utterances of the same expression should that prove fruitful. */
3002 stabilize_reference_1 (tree e
)
3005 enum tree_code code
= TREE_CODE (e
);
3007 /* We cannot ignore const expressions because it might be a reference
3008 to a const array but whose index contains side-effects. But we can
3009 ignore things that are actual constant or that already have been
3010 handled by this function. */
3012 if (tree_invariant_p (e
))
3015 switch (TREE_CODE_CLASS (code
))
3017 case tcc_exceptional
:
3019 case tcc_declaration
:
3020 case tcc_comparison
:
3022 case tcc_expression
:
3025 /* If the expression has side-effects, then encase it in a SAVE_EXPR
3026 so that it will only be evaluated once. */
3027 /* The reference (r) and comparison (<) classes could be handled as
3028 below, but it is generally faster to only evaluate them once. */
3029 if (TREE_SIDE_EFFECTS (e
))
3030 return save_expr (e
);
3034 /* Constants need no processing. In fact, we should never reach
3039 /* Division is slow and tends to be compiled with jumps,
3040 especially the division by powers of 2 that is often
3041 found inside of an array reference. So do it just once. */
3042 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
3043 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
3044 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
3045 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
3046 return save_expr (e
);
3047 /* Recursively stabilize each operand. */
3048 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
3049 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
3053 /* Recursively stabilize each operand. */
3054 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
3061 TREE_TYPE (result
) = TREE_TYPE (e
);
3062 TREE_READONLY (result
) = TREE_READONLY (e
);
3063 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
3064 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
3069 /* Low-level constructors for expressions. */
3071 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
3072 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
3075 recompute_tree_invariant_for_addr_expr (tree t
)
3078 bool tc
= true, se
= false;
3080 /* We started out assuming this address is both invariant and constant, but
3081 does not have side effects. Now go down any handled components and see if
3082 any of them involve offsets that are either non-constant or non-invariant.
3083 Also check for side-effects.
3085 ??? Note that this code makes no attempt to deal with the case where
3086 taking the address of something causes a copy due to misalignment. */
3088 #define UPDATE_FLAGS(NODE) \
3089 do { tree _node = (NODE); \
3090 if (_node && !TREE_CONSTANT (_node)) tc = false; \
3091 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
3093 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
3094 node
= TREE_OPERAND (node
, 0))
3096 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
3097 array reference (probably made temporarily by the G++ front end),
3098 so ignore all the operands. */
3099 if ((TREE_CODE (node
) == ARRAY_REF
3100 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
3101 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
3103 UPDATE_FLAGS (TREE_OPERAND (node
, 1));
3104 if (TREE_OPERAND (node
, 2))
3105 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3106 if (TREE_OPERAND (node
, 3))
3107 UPDATE_FLAGS (TREE_OPERAND (node
, 3));
3109 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
3110 FIELD_DECL, apparently. The G++ front end can put something else
3111 there, at least temporarily. */
3112 else if (TREE_CODE (node
) == COMPONENT_REF
3113 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
3115 if (TREE_OPERAND (node
, 2))
3116 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3118 else if (TREE_CODE (node
) == BIT_FIELD_REF
)
3119 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3122 node
= lang_hooks
.expr_to_decl (node
, &tc
, &se
);
3124 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
3125 the address, since &(*a)->b is a form of addition. If it's a constant, the
3126 address is constant too. If it's a decl, its address is constant if the
3127 decl is static. Everything else is not constant and, furthermore,
3128 taking the address of a volatile variable is not volatile. */
3129 if (TREE_CODE (node
) == INDIRECT_REF
)
3130 UPDATE_FLAGS (TREE_OPERAND (node
, 0));
3131 else if (CONSTANT_CLASS_P (node
))
3133 else if (DECL_P (node
))
3134 tc
&= (staticp (node
) != NULL_TREE
);
3138 se
|= TREE_SIDE_EFFECTS (node
);
3142 TREE_CONSTANT (t
) = tc
;
3143 TREE_SIDE_EFFECTS (t
) = se
;
3147 /* Build an expression of code CODE, data type TYPE, and operands as
3148 specified. Expressions and reference nodes can be created this way.
3149 Constants, decls, types and misc nodes cannot be.
3151 We define 5 non-variadic functions, from 0 to 4 arguments. This is
3152 enough for all extant tree codes. */
3155 build0_stat (enum tree_code code
, tree tt MEM_STAT_DECL
)
3159 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
3161 t
= make_node_stat (code PASS_MEM_STAT
);
3168 build1_stat (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
3170 int length
= sizeof (struct tree_exp
);
3171 #ifdef GATHER_STATISTICS
3172 tree_node_kind kind
;
3176 #ifdef GATHER_STATISTICS
3177 switch (TREE_CODE_CLASS (code
))
3179 case tcc_statement
: /* an expression with side effects */
3182 case tcc_reference
: /* a reference */
3190 tree_node_counts
[(int) kind
]++;
3191 tree_node_sizes
[(int) kind
] += length
;
3194 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
3196 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
3198 memset (t
, 0, sizeof (struct tree_common
));
3200 TREE_SET_CODE (t
, code
);
3202 TREE_TYPE (t
) = type
;
3203 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
3204 TREE_OPERAND (t
, 0) = node
;
3205 TREE_BLOCK (t
) = NULL_TREE
;
3206 if (node
&& !TYPE_P (node
))
3208 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
3209 TREE_READONLY (t
) = TREE_READONLY (node
);
3212 if (TREE_CODE_CLASS (code
) == tcc_statement
)
3213 TREE_SIDE_EFFECTS (t
) = 1;
3217 /* All of these have side-effects, no matter what their
3219 TREE_SIDE_EFFECTS (t
) = 1;
3220 TREE_READONLY (t
) = 0;
3223 case MISALIGNED_INDIRECT_REF
:
3224 case ALIGN_INDIRECT_REF
:
3226 /* Whether a dereference is readonly has nothing to do with whether
3227 its operand is readonly. */
3228 TREE_READONLY (t
) = 0;
3233 recompute_tree_invariant_for_addr_expr (t
);
3237 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
3238 && node
&& !TYPE_P (node
)
3239 && TREE_CONSTANT (node
))
3240 TREE_CONSTANT (t
) = 1;
3241 if (TREE_CODE_CLASS (code
) == tcc_reference
3242 && node
&& TREE_THIS_VOLATILE (node
))
3243 TREE_THIS_VOLATILE (t
) = 1;
3250 #define PROCESS_ARG(N) \
3252 TREE_OPERAND (t, N) = arg##N; \
3253 if (arg##N &&!TYPE_P (arg##N)) \
3255 if (TREE_SIDE_EFFECTS (arg##N)) \
3257 if (!TREE_READONLY (arg##N)) \
3259 if (!TREE_CONSTANT (arg##N)) \
3265 build2_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
3267 bool constant
, read_only
, side_effects
;
3270 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
3273 /* FIXME tuples: Statement's aren't expressions! */
3274 if (code
== GIMPLE_MODIFY_STMT
)
3275 return build_gimple_modify_stmt_stat (arg0
, arg1 PASS_MEM_STAT
);
3277 /* Must use build_gimple_modify_stmt to construct GIMPLE_MODIFY_STMTs. */
3278 gcc_assert (code
!= GIMPLE_MODIFY_STMT
);
3281 if ((code
== MINUS_EXPR
|| code
== PLUS_EXPR
|| code
== MULT_EXPR
)
3282 && arg0
&& arg1
&& tt
&& POINTER_TYPE_P (tt
))
3283 gcc_assert (TREE_CODE (arg0
) == INTEGER_CST
&& TREE_CODE (arg1
) == INTEGER_CST
);
3285 if (code
== POINTER_PLUS_EXPR
&& arg0
&& arg1
&& tt
)
3286 gcc_assert (POINTER_TYPE_P (tt
) && POINTER_TYPE_P (TREE_TYPE (arg0
))
3287 && INTEGRAL_TYPE_P (TREE_TYPE (arg1
))
3288 && useless_type_conversion_p (sizetype
, TREE_TYPE (arg1
)));
3290 t
= make_node_stat (code PASS_MEM_STAT
);
3293 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
3294 result based on those same flags for the arguments. But if the
3295 arguments aren't really even `tree' expressions, we shouldn't be trying
3298 /* Expressions without side effects may be constant if their
3299 arguments are as well. */
3300 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
3301 || TREE_CODE_CLASS (code
) == tcc_binary
);
3303 side_effects
= TREE_SIDE_EFFECTS (t
);
3308 TREE_READONLY (t
) = read_only
;
3309 TREE_CONSTANT (t
) = constant
;
3310 TREE_SIDE_EFFECTS (t
) = side_effects
;
3311 TREE_THIS_VOLATILE (t
)
3312 = (TREE_CODE_CLASS (code
) == tcc_reference
3313 && arg0
&& TREE_THIS_VOLATILE (arg0
));
3319 /* Build a GIMPLE_MODIFY_STMT node. This tree code doesn't have a
3320 type, so we can't use build2 (a.k.a. build2_stat). */
3323 build_gimple_modify_stmt_stat (tree arg0
, tree arg1 MEM_STAT_DECL
)
3327 t
= make_node_stat (GIMPLE_MODIFY_STMT PASS_MEM_STAT
);
3328 /* ?? We don't care about setting flags for tuples... */
3329 GIMPLE_STMT_OPERAND (t
, 0) = arg0
;
3330 GIMPLE_STMT_OPERAND (t
, 1) = arg1
;
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
;
3570 const struct line_map
*map
= linemap_lookup (line_table
, loc
);
3571 xloc
.file
= map
->to_file
;
3572 xloc
.line
= SOURCE_LINE (map
, loc
);
3573 xloc
.column
= SOURCE_COLUMN (map
, loc
);
3579 /* Source location accessor functions. */
3582 /* The source location of this expression. Non-tree_exp nodes such as
3583 decls and constants can be shared among multiple locations, so
3586 expr_location (const_tree node
)
3588 if (GIMPLE_STMT_P (node
))
3589 return GIMPLE_STMT_LOCUS (node
);
3590 return EXPR_P (node
) ? node
->exp
.locus
: UNKNOWN_LOCATION
;
3594 set_expr_location (tree node
, location_t locus
)
3596 if (GIMPLE_STMT_P (node
))
3597 GIMPLE_STMT_LOCUS (node
) = locus
;
3599 EXPR_CHECK (node
)->exp
.locus
= locus
;
3603 expr_has_location (const_tree node
)
3605 return expr_location (node
) != UNKNOWN_LOCATION
;
3609 expr_locus (const_tree node
)
3611 if (GIMPLE_STMT_P (node
))
3612 return CONST_CAST (source_location
*, &GIMPLE_STMT_LOCUS (node
));
3613 return (EXPR_P (node
)
3614 ? CONST_CAST (source_location
*, &node
->exp
.locus
)
3615 : (source_location
*) NULL
);
3619 set_expr_locus (tree node
, source_location
*loc
)
3623 if (GIMPLE_STMT_P (node
))
3624 GIMPLE_STMT_LOCUS (node
) = UNKNOWN_LOCATION
;
3626 EXPR_CHECK (node
)->exp
.locus
= UNKNOWN_LOCATION
;
3630 if (GIMPLE_STMT_P (node
))
3631 GIMPLE_STMT_LOCUS (node
) = *loc
;
3633 EXPR_CHECK (node
)->exp
.locus
= *loc
;
3637 /* Return the file name of the location of NODE. */
3639 expr_filename (const_tree node
)
3641 if (GIMPLE_STMT_P (node
))
3642 return LOCATION_FILE (GIMPLE_STMT_LOCUS (node
));
3643 return LOCATION_FILE (EXPR_CHECK (node
)->exp
.locus
);
3646 /* Return the line number of the location of NODE. */
3648 expr_lineno (const_tree node
)
3650 if (GIMPLE_STMT_P (node
))
3651 return LOCATION_LINE (GIMPLE_STMT_LOCUS (node
));
3652 return LOCATION_LINE (EXPR_CHECK (node
)->exp
.locus
);
3656 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
3660 build_decl_attribute_variant (tree ddecl
, tree attribute
)
3662 DECL_ATTRIBUTES (ddecl
) = attribute
;
3666 /* Borrowed from hashtab.c iterative_hash implementation. */
3667 #define mix(a,b,c) \
3669 a -= b; a -= c; a ^= (c>>13); \
3670 b -= c; b -= a; b ^= (a<< 8); \
3671 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
3672 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
3673 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
3674 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
3675 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
3676 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
3677 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
3681 /* Produce good hash value combining VAL and VAL2. */
3683 iterative_hash_hashval_t (hashval_t val
, hashval_t val2
)
3685 /* the golden ratio; an arbitrary value. */
3686 hashval_t a
= 0x9e3779b9;
3692 /* Produce good hash value combining PTR and VAL2. */
3693 static inline hashval_t
3694 iterative_hash_pointer (const void *ptr
, hashval_t val2
)
3696 if (sizeof (ptr
) == sizeof (hashval_t
))
3697 return iterative_hash_hashval_t ((size_t) ptr
, val2
);
3700 hashval_t a
= (hashval_t
) (size_t) ptr
;
3701 /* Avoid warnings about shifting of more than the width of the type on
3702 hosts that won't execute this path. */
3704 hashval_t b
= (hashval_t
) ((size_t) ptr
>> (sizeof (hashval_t
) * 8 + zero
));
3710 /* Produce good hash value combining VAL and VAL2. */
3711 static inline hashval_t
3712 iterative_hash_host_wide_int (HOST_WIDE_INT val
, hashval_t val2
)
3714 if (sizeof (HOST_WIDE_INT
) == sizeof (hashval_t
))
3715 return iterative_hash_hashval_t (val
, val2
);
3718 hashval_t a
= (hashval_t
) val
;
3719 /* Avoid warnings about shifting of more than the width of the type on
3720 hosts that won't execute this path. */
3722 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 8 + zero
));
3724 if (sizeof (HOST_WIDE_INT
) > 2 * sizeof (hashval_t
))
3726 hashval_t a
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 16 + zero
));
3727 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 24 + zero
));
3734 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3735 is ATTRIBUTE and its qualifiers are QUALS.
3737 Record such modified types already made so we don't make duplicates. */
3740 build_type_attribute_qual_variant (tree ttype
, tree attribute
, int quals
)
3742 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
3744 hashval_t hashcode
= 0;
3746 enum tree_code code
= TREE_CODE (ttype
);
3748 /* Building a distinct copy of a tagged type is inappropriate; it
3749 causes breakage in code that expects there to be a one-to-one
3750 relationship between a struct and its fields.
3751 build_duplicate_type is another solution (as used in
3752 handle_transparent_union_attribute), but that doesn't play well
3753 with the stronger C++ type identity model. */
3754 if (TREE_CODE (ttype
) == RECORD_TYPE
3755 || TREE_CODE (ttype
) == UNION_TYPE
3756 || TREE_CODE (ttype
) == QUAL_UNION_TYPE
3757 || TREE_CODE (ttype
) == ENUMERAL_TYPE
)
3759 warning (OPT_Wattributes
,
3760 "ignoring attributes applied to %qT after definition",
3761 TYPE_MAIN_VARIANT (ttype
));
3762 return build_qualified_type (ttype
, quals
);
3765 ntype
= build_distinct_type_copy (ttype
);
3767 TYPE_ATTRIBUTES (ntype
) = attribute
;
3768 set_type_quals (ntype
, TYPE_UNQUALIFIED
);
3770 hashcode
= iterative_hash_object (code
, hashcode
);
3771 if (TREE_TYPE (ntype
))
3772 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype
)),
3774 hashcode
= attribute_hash_list (attribute
, hashcode
);
3776 switch (TREE_CODE (ntype
))
3779 hashcode
= type_hash_list (TYPE_ARG_TYPES (ntype
), hashcode
);
3782 if (TYPE_DOMAIN (ntype
))
3783 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype
)),
3787 hashcode
= iterative_hash_object
3788 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype
)), hashcode
);
3789 hashcode
= iterative_hash_object
3790 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype
)), hashcode
);
3793 case FIXED_POINT_TYPE
:
3795 unsigned int precision
= TYPE_PRECISION (ntype
);
3796 hashcode
= iterative_hash_object (precision
, hashcode
);
3803 ntype
= type_hash_canon (hashcode
, ntype
);
3805 /* If the target-dependent attributes make NTYPE different from
3806 its canonical type, we will need to use structural equality
3807 checks for this qualified type. */
3808 ttype
= build_qualified_type (ttype
, TYPE_UNQUALIFIED
);
3809 if (TYPE_STRUCTURAL_EQUALITY_P (ttype
)
3810 || !targetm
.comp_type_attributes (ntype
, ttype
))
3811 SET_TYPE_STRUCTURAL_EQUALITY (ntype
);
3813 TYPE_CANONICAL (ntype
) = TYPE_CANONICAL (ttype
);
3815 ttype
= build_qualified_type (ntype
, quals
);
3817 else if (TYPE_QUALS (ttype
) != quals
)
3818 ttype
= build_qualified_type (ttype
, quals
);
3824 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3827 Record such modified types already made so we don't make duplicates. */
3830 build_type_attribute_variant (tree ttype
, tree attribute
)
3832 return build_type_attribute_qual_variant (ttype
, attribute
,
3833 TYPE_QUALS (ttype
));
3836 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3839 We try both `text' and `__text__', ATTR may be either one. */
3840 /* ??? It might be a reasonable simplification to require ATTR to be only
3841 `text'. One might then also require attribute lists to be stored in
3842 their canonicalized form. */
3845 is_attribute_with_length_p (const char *attr
, int attr_len
, const_tree ident
)
3850 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
3853 p
= IDENTIFIER_POINTER (ident
);
3854 ident_len
= IDENTIFIER_LENGTH (ident
);
3856 if (ident_len
== attr_len
3857 && strcmp (attr
, p
) == 0)
3860 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
3863 gcc_assert (attr
[1] == '_');
3864 gcc_assert (attr
[attr_len
- 2] == '_');
3865 gcc_assert (attr
[attr_len
- 1] == '_');
3866 if (ident_len
== attr_len
- 4
3867 && strncmp (attr
+ 2, p
, attr_len
- 4) == 0)
3872 if (ident_len
== attr_len
+ 4
3873 && p
[0] == '_' && p
[1] == '_'
3874 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
3875 && strncmp (attr
, p
+ 2, attr_len
) == 0)
3882 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3885 We try both `text' and `__text__', ATTR may be either one. */
3888 is_attribute_p (const char *attr
, const_tree ident
)
3890 return is_attribute_with_length_p (attr
, strlen (attr
), ident
);
3893 /* Given an attribute name and a list of attributes, return a pointer to the
3894 attribute's list element if the attribute is part of the list, or NULL_TREE
3895 if not found. If the attribute appears more than once, this only
3896 returns the first occurrence; the TREE_CHAIN of the return value should
3897 be passed back in if further occurrences are wanted. */
3900 lookup_attribute (const char *attr_name
, tree list
)
3903 size_t attr_len
= strlen (attr_name
);
3905 for (l
= list
; l
; l
= TREE_CHAIN (l
))
3907 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
3908 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
3914 /* Remove any instances of attribute ATTR_NAME in LIST and return the
3918 remove_attribute (const char *attr_name
, tree list
)
3921 size_t attr_len
= strlen (attr_name
);
3923 for (p
= &list
; *p
; )
3926 gcc_assert (TREE_CODE (TREE_PURPOSE (l
)) == IDENTIFIER_NODE
);
3927 if (is_attribute_with_length_p (attr_name
, attr_len
, TREE_PURPOSE (l
)))
3928 *p
= TREE_CHAIN (l
);
3930 p
= &TREE_CHAIN (l
);
3936 /* Return an attribute list that is the union of a1 and a2. */
3939 merge_attributes (tree a1
, tree a2
)
3943 /* Either one unset? Take the set one. */
3945 if ((attributes
= a1
) == 0)
3948 /* One that completely contains the other? Take it. */
3950 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
3952 if (attribute_list_contained (a2
, a1
))
3956 /* Pick the longest list, and hang on the other list. */
3958 if (list_length (a1
) < list_length (a2
))
3959 attributes
= a2
, a2
= a1
;
3961 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
3964 for (a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
3967 a
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2
)),
3970 if (TREE_VALUE (a
) != NULL
3971 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
3972 && TREE_VALUE (a2
) != NULL
3973 && TREE_CODE (TREE_VALUE (a2
)) == TREE_LIST
)
3975 if (simple_cst_list_equal (TREE_VALUE (a
),
3976 TREE_VALUE (a2
)) == 1)
3979 else if (simple_cst_equal (TREE_VALUE (a
),
3980 TREE_VALUE (a2
)) == 1)
3985 a1
= copy_node (a2
);
3986 TREE_CHAIN (a1
) = attributes
;
3995 /* Given types T1 and T2, merge their attributes and return
3999 merge_type_attributes (tree t1
, tree t2
)
4001 return merge_attributes (TYPE_ATTRIBUTES (t1
),
4002 TYPE_ATTRIBUTES (t2
));
4005 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
4009 merge_decl_attributes (tree olddecl
, tree newdecl
)
4011 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
4012 DECL_ATTRIBUTES (newdecl
));
4015 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
4017 /* Specialization of merge_decl_attributes for various Windows targets.
4019 This handles the following situation:
4021 __declspec (dllimport) int foo;
4024 The second instance of `foo' nullifies the dllimport. */
4027 merge_dllimport_decl_attributes (tree old
, tree
new)
4030 int delete_dllimport_p
= 1;
4032 /* What we need to do here is remove from `old' dllimport if it doesn't
4033 appear in `new'. dllimport behaves like extern: if a declaration is
4034 marked dllimport and a definition appears later, then the object
4035 is not dllimport'd. We also remove a `new' dllimport if the old list
4036 contains dllexport: dllexport always overrides dllimport, regardless
4037 of the order of declaration. */
4038 if (!VAR_OR_FUNCTION_DECL_P (new))
4039 delete_dllimport_p
= 0;
4040 else if (DECL_DLLIMPORT_P (new)
4041 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old
)))
4043 DECL_DLLIMPORT_P (new) = 0;
4044 warning (OPT_Wattributes
, "%q+D already declared with dllexport attribute: "
4045 "dllimport ignored", new);
4047 else if (DECL_DLLIMPORT_P (old
) && !DECL_DLLIMPORT_P (new))
4049 /* Warn about overriding a symbol that has already been used, e.g.:
4050 extern int __attribute__ ((dllimport)) foo;
4051 int* bar () {return &foo;}
4054 if (TREE_USED (old
))
4056 warning (0, "%q+D redeclared without dllimport attribute "
4057 "after being referenced with dll linkage", new);
4058 /* If we have used a variable's address with dllimport linkage,
4059 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
4060 decl may already have had TREE_CONSTANT computed.
4061 We still remove the attribute so that assembler code refers
4062 to '&foo rather than '_imp__foo'. */
4063 if (TREE_CODE (old
) == VAR_DECL
&& TREE_ADDRESSABLE (old
))
4064 DECL_DLLIMPORT_P (new) = 1;
4067 /* Let an inline definition silently override the external reference,
4068 but otherwise warn about attribute inconsistency. */
4069 else if (TREE_CODE (new) == VAR_DECL
4070 || !DECL_DECLARED_INLINE_P (new))
4071 warning (OPT_Wattributes
, "%q+D redeclared without dllimport attribute: "
4072 "previous dllimport ignored", new);
4075 delete_dllimport_p
= 0;
4077 a
= merge_attributes (DECL_ATTRIBUTES (old
), DECL_ATTRIBUTES (new));
4079 if (delete_dllimport_p
)
4082 const size_t attr_len
= strlen ("dllimport");
4084 /* Scan the list for dllimport and delete it. */
4085 for (prev
= NULL_TREE
, t
= a
; t
; prev
= t
, t
= TREE_CHAIN (t
))
4087 if (is_attribute_with_length_p ("dllimport", attr_len
,
4090 if (prev
== NULL_TREE
)
4093 TREE_CHAIN (prev
) = TREE_CHAIN (t
);
4102 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
4103 struct attribute_spec.handler. */
4106 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
4111 /* These attributes may apply to structure and union types being created,
4112 but otherwise should pass to the declaration involved. */
4115 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
4116 | (int) ATTR_FLAG_ARRAY_NEXT
))
4118 *no_add_attrs
= true;
4119 return tree_cons (name
, args
, NULL_TREE
);
4121 if (TREE_CODE (node
) == RECORD_TYPE
4122 || TREE_CODE (node
) == UNION_TYPE
)
4124 node
= TYPE_NAME (node
);
4130 warning (OPT_Wattributes
, "%qs attribute ignored",
4131 IDENTIFIER_POINTER (name
));
4132 *no_add_attrs
= true;
4137 if (TREE_CODE (node
) != FUNCTION_DECL
4138 && TREE_CODE (node
) != VAR_DECL
4139 && TREE_CODE (node
) != TYPE_DECL
)
4141 *no_add_attrs
= true;
4142 warning (OPT_Wattributes
, "%qs attribute ignored",
4143 IDENTIFIER_POINTER (name
));
4147 if (TREE_CODE (node
) == TYPE_DECL
4148 && TREE_CODE (TREE_TYPE (node
)) != RECORD_TYPE
4149 && TREE_CODE (TREE_TYPE (node
)) != UNION_TYPE
)
4151 *no_add_attrs
= true;
4152 warning (OPT_Wattributes
, "%qs attribute ignored",
4153 IDENTIFIER_POINTER (name
));
4157 /* Report error on dllimport ambiguities seen now before they cause
4159 else if (is_attribute_p ("dllimport", name
))
4161 /* Honor any target-specific overrides. */
4162 if (!targetm
.valid_dllimport_attribute_p (node
))
4163 *no_add_attrs
= true;
4165 else if (TREE_CODE (node
) == FUNCTION_DECL
4166 && DECL_DECLARED_INLINE_P (node
))
4168 warning (OPT_Wattributes
, "inline function %q+D declared as "
4169 " dllimport: attribute ignored", node
);
4170 *no_add_attrs
= true;
4172 /* Like MS, treat definition of dllimported variables and
4173 non-inlined functions on declaration as syntax errors. */
4174 else if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
))
4176 error ("function %q+D definition is marked dllimport", node
);
4177 *no_add_attrs
= true;
4180 else if (TREE_CODE (node
) == VAR_DECL
)
4182 if (DECL_INITIAL (node
))
4184 error ("variable %q+D definition is marked dllimport",
4186 *no_add_attrs
= true;
4189 /* `extern' needn't be specified with dllimport.
4190 Specify `extern' now and hope for the best. Sigh. */
4191 DECL_EXTERNAL (node
) = 1;
4192 /* Also, implicitly give dllimport'd variables declared within
4193 a function global scope, unless declared static. */
4194 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
4195 TREE_PUBLIC (node
) = 1;
4198 if (*no_add_attrs
== false)
4199 DECL_DLLIMPORT_P (node
) = 1;
4202 /* Report error if symbol is not accessible at global scope. */
4203 if (!TREE_PUBLIC (node
)
4204 && (TREE_CODE (node
) == VAR_DECL
4205 || TREE_CODE (node
) == FUNCTION_DECL
))
4207 error ("external linkage required for symbol %q+D because of "
4208 "%qs attribute", node
, IDENTIFIER_POINTER (name
));
4209 *no_add_attrs
= true;
4212 /* A dllexport'd entity must have default visibility so that other
4213 program units (shared libraries or the main executable) can see
4214 it. A dllimport'd entity must have default visibility so that
4215 the linker knows that undefined references within this program
4216 unit can be resolved by the dynamic linker. */
4219 if (DECL_VISIBILITY_SPECIFIED (node
)
4220 && DECL_VISIBILITY (node
) != VISIBILITY_DEFAULT
)
4221 error ("%qs implies default visibility, but %qD has already "
4222 "been declared with a different visibility",
4223 IDENTIFIER_POINTER (name
), node
);
4224 DECL_VISIBILITY (node
) = VISIBILITY_DEFAULT
;
4225 DECL_VISIBILITY_SPECIFIED (node
) = 1;
4231 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
4233 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
4234 of the various TYPE_QUAL values. */
4237 set_type_quals (tree type
, int type_quals
)
4239 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
4240 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
4241 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
4244 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
4247 check_qualified_type (const_tree cand
, const_tree base
, int type_quals
)
4249 return (TYPE_QUALS (cand
) == type_quals
4250 && TYPE_NAME (cand
) == TYPE_NAME (base
)
4251 /* Apparently this is needed for Objective-C. */
4252 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
4253 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
4254 TYPE_ATTRIBUTES (base
)));
4257 /* Return a version of the TYPE, qualified as indicated by the
4258 TYPE_QUALS, if one exists. If no qualified version exists yet,
4259 return NULL_TREE. */
4262 get_qualified_type (tree type
, int type_quals
)
4266 if (TYPE_QUALS (type
) == type_quals
)
4269 /* Search the chain of variants to see if there is already one there just
4270 like the one we need to have. If so, use that existing one. We must
4271 preserve the TYPE_NAME, since there is code that depends on this. */
4272 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
4273 if (check_qualified_type (t
, type
, type_quals
))
4279 /* Like get_qualified_type, but creates the type if it does not
4280 exist. This function never returns NULL_TREE. */
4283 build_qualified_type (tree type
, int type_quals
)
4287 /* See if we already have the appropriate qualified variant. */
4288 t
= get_qualified_type (type
, type_quals
);
4290 /* If not, build it. */
4293 t
= build_variant_type_copy (type
);
4294 set_type_quals (t
, type_quals
);
4296 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
4297 /* Propagate structural equality. */
4298 SET_TYPE_STRUCTURAL_EQUALITY (t
);
4299 else if (TYPE_CANONICAL (type
) != type
)
4300 /* Build the underlying canonical type, since it is different
4302 TYPE_CANONICAL (t
) = build_qualified_type (TYPE_CANONICAL (type
),
4305 /* T is its own canonical type. */
4306 TYPE_CANONICAL (t
) = t
;
4313 /* Create a new distinct copy of TYPE. The new type is made its own
4314 MAIN_VARIANT. If TYPE requires structural equality checks, the
4315 resulting type requires structural equality checks; otherwise, its
4316 TYPE_CANONICAL points to itself. */
4319 build_distinct_type_copy (tree type
)
4321 tree t
= copy_node (type
);
4323 TYPE_POINTER_TO (t
) = 0;
4324 TYPE_REFERENCE_TO (t
) = 0;
4326 /* Set the canonical type either to a new equivalence class, or
4327 propagate the need for structural equality checks. */
4328 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
4329 SET_TYPE_STRUCTURAL_EQUALITY (t
);
4331 TYPE_CANONICAL (t
) = t
;
4333 /* Make it its own variant. */
4334 TYPE_MAIN_VARIANT (t
) = t
;
4335 TYPE_NEXT_VARIANT (t
) = 0;
4337 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
4338 whose TREE_TYPE is not t. This can also happen in the Ada
4339 frontend when using subtypes. */
4344 /* Create a new variant of TYPE, equivalent but distinct. This is so
4345 the caller can modify it. TYPE_CANONICAL for the return type will
4346 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
4347 are considered equal by the language itself (or that both types
4348 require structural equality checks). */
4351 build_variant_type_copy (tree type
)
4353 tree t
, m
= TYPE_MAIN_VARIANT (type
);
4355 t
= build_distinct_type_copy (type
);
4357 /* Since we're building a variant, assume that it is a non-semantic
4358 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
4359 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
4361 /* Add the new type to the chain of variants of TYPE. */
4362 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
4363 TYPE_NEXT_VARIANT (m
) = t
;
4364 TYPE_MAIN_VARIANT (t
) = m
;
4369 /* Return true if the from tree in both tree maps are equal. */
4372 tree_map_base_eq (const void *va
, const void *vb
)
4374 const struct tree_map_base
*const a
= (const struct tree_map_base
*) va
,
4375 *const b
= (const struct tree_map_base
*) vb
;
4376 return (a
->from
== b
->from
);
4379 /* Hash a from tree in a tree_map. */
4382 tree_map_base_hash (const void *item
)
4384 return htab_hash_pointer (((const struct tree_map_base
*)item
)->from
);
4387 /* Return true if this tree map structure is marked for garbage collection
4388 purposes. We simply return true if the from tree is marked, so that this
4389 structure goes away when the from tree goes away. */
4392 tree_map_base_marked_p (const void *p
)
4394 return ggc_marked_p (((const struct tree_map_base
*) p
)->from
);
4398 tree_map_hash (const void *item
)
4400 return (((const struct tree_map
*) item
)->hash
);
4403 /* Return the initialization priority for DECL. */
4406 decl_init_priority_lookup (tree decl
)
4408 struct tree_priority_map
*h
;
4409 struct tree_map_base in
;
4411 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
4413 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
4414 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
4417 /* Return the finalization priority for DECL. */
4420 decl_fini_priority_lookup (tree decl
)
4422 struct tree_priority_map
*h
;
4423 struct tree_map_base in
;
4425 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
4427 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
4428 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
4431 /* Return the initialization and finalization priority information for
4432 DECL. If there is no previous priority information, a freshly
4433 allocated structure is returned. */
4435 static struct tree_priority_map
*
4436 decl_priority_info (tree decl
)
4438 struct tree_priority_map in
;
4439 struct tree_priority_map
*h
;
4442 in
.base
.from
= decl
;
4443 loc
= htab_find_slot (init_priority_for_decl
, &in
, INSERT
);
4444 h
= (struct tree_priority_map
*) *loc
;
4447 h
= GGC_CNEW (struct tree_priority_map
);
4449 h
->base
.from
= decl
;
4450 h
->init
= DEFAULT_INIT_PRIORITY
;
4451 h
->fini
= DEFAULT_INIT_PRIORITY
;
4457 /* Set the initialization priority for DECL to PRIORITY. */
4460 decl_init_priority_insert (tree decl
, priority_type priority
)
4462 struct tree_priority_map
*h
;
4464 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
4465 h
= decl_priority_info (decl
);
4469 /* Set the finalization priority for DECL to PRIORITY. */
4472 decl_fini_priority_insert (tree decl
, priority_type priority
)
4474 struct tree_priority_map
*h
;
4476 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
4477 h
= decl_priority_info (decl
);
4481 /* Look up a restrict qualified base decl for FROM. */
4484 decl_restrict_base_lookup (tree from
)
4489 in
.base
.from
= from
;
4490 h
= (struct tree_map
*) htab_find_with_hash (restrict_base_for_decl
, &in
,
4491 htab_hash_pointer (from
));
4492 return h
? h
->to
: NULL_TREE
;
4495 /* Record the restrict qualified base TO for FROM. */
4498 decl_restrict_base_insert (tree from
, tree to
)
4503 h
= GGC_NEW (struct tree_map
);
4504 h
->hash
= htab_hash_pointer (from
);
4505 h
->base
.from
= from
;
4507 loc
= htab_find_slot_with_hash (restrict_base_for_decl
, h
, h
->hash
, INSERT
);
4508 *(struct tree_map
**) loc
= h
;
4511 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
4514 print_debug_expr_statistics (void)
4516 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
4517 (long) htab_size (debug_expr_for_decl
),
4518 (long) htab_elements (debug_expr_for_decl
),
4519 htab_collisions (debug_expr_for_decl
));
4522 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
4525 print_value_expr_statistics (void)
4527 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
4528 (long) htab_size (value_expr_for_decl
),
4529 (long) htab_elements (value_expr_for_decl
),
4530 htab_collisions (value_expr_for_decl
));
4533 /* Print out statistics for the RESTRICT_BASE_FOR_DECL hash table, but
4534 don't print anything if the table is empty. */
4537 print_restrict_base_statistics (void)
4539 if (htab_elements (restrict_base_for_decl
) != 0)
4541 "RESTRICT_BASE hash: size %ld, %ld elements, %f collisions\n",
4542 (long) htab_size (restrict_base_for_decl
),
4543 (long) htab_elements (restrict_base_for_decl
),
4544 htab_collisions (restrict_base_for_decl
));
4547 /* Lookup a debug expression for FROM, and return it if we find one. */
4550 decl_debug_expr_lookup (tree from
)
4552 struct tree_map
*h
, in
;
4553 in
.base
.from
= from
;
4555 h
= (struct tree_map
*) htab_find_with_hash (debug_expr_for_decl
, &in
,
4556 htab_hash_pointer (from
));
4562 /* Insert a mapping FROM->TO in the debug expression hashtable. */
4565 decl_debug_expr_insert (tree from
, tree to
)
4570 h
= GGC_NEW (struct tree_map
);
4571 h
->hash
= htab_hash_pointer (from
);
4572 h
->base
.from
= from
;
4574 loc
= htab_find_slot_with_hash (debug_expr_for_decl
, h
, h
->hash
, INSERT
);
4575 *(struct tree_map
**) loc
= h
;
4578 /* Lookup a value expression for FROM, and return it if we find one. */
4581 decl_value_expr_lookup (tree from
)
4583 struct tree_map
*h
, in
;
4584 in
.base
.from
= from
;
4586 h
= (struct tree_map
*) htab_find_with_hash (value_expr_for_decl
, &in
,
4587 htab_hash_pointer (from
));
4593 /* Insert a mapping FROM->TO in the value expression hashtable. */
4596 decl_value_expr_insert (tree from
, tree to
)
4601 h
= GGC_NEW (struct tree_map
);
4602 h
->hash
= htab_hash_pointer (from
);
4603 h
->base
.from
= from
;
4605 loc
= htab_find_slot_with_hash (value_expr_for_decl
, h
, h
->hash
, INSERT
);
4606 *(struct tree_map
**) loc
= h
;
4609 /* Hashing of types so that we don't make duplicates.
4610 The entry point is `type_hash_canon'. */
4612 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
4613 with types in the TREE_VALUE slots), by adding the hash codes
4614 of the individual types. */
4617 type_hash_list (const_tree list
, hashval_t hashcode
)
4621 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
4622 if (TREE_VALUE (tail
) != error_mark_node
)
4623 hashcode
= iterative_hash_object (TYPE_HASH (TREE_VALUE (tail
)),
4629 /* These are the Hashtable callback functions. */
4631 /* Returns true iff the types are equivalent. */
4634 type_hash_eq (const void *va
, const void *vb
)
4636 const struct type_hash
*const a
= (const struct type_hash
*) va
,
4637 *const b
= (const struct type_hash
*) vb
;
4639 /* First test the things that are the same for all types. */
4640 if (a
->hash
!= b
->hash
4641 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
4642 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
4643 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
4644 TYPE_ATTRIBUTES (b
->type
))
4645 || TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
4646 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
))
4649 switch (TREE_CODE (a
->type
))
4654 case REFERENCE_TYPE
:
4658 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
4661 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
4662 && !(TYPE_VALUES (a
->type
)
4663 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
4664 && TYPE_VALUES (b
->type
)
4665 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
4666 && type_list_equal (TYPE_VALUES (a
->type
),
4667 TYPE_VALUES (b
->type
))))
4670 /* ... fall through ... */
4675 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
4676 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
4677 TYPE_MAX_VALUE (b
->type
)))
4678 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
4679 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
4680 TYPE_MIN_VALUE (b
->type
))));
4682 case FIXED_POINT_TYPE
:
4683 return TYPE_SATURATING (a
->type
) == TYPE_SATURATING (b
->type
);
4686 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
4689 return (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
4690 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
4691 || (TYPE_ARG_TYPES (a
->type
)
4692 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
4693 && TYPE_ARG_TYPES (b
->type
)
4694 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
4695 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
4696 TYPE_ARG_TYPES (b
->type
)))));
4699 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
4703 case QUAL_UNION_TYPE
:
4704 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
4705 || (TYPE_FIELDS (a
->type
)
4706 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
4707 && TYPE_FIELDS (b
->type
)
4708 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
4709 && type_list_equal (TYPE_FIELDS (a
->type
),
4710 TYPE_FIELDS (b
->type
))));
4713 if (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
4714 || (TYPE_ARG_TYPES (a
->type
)
4715 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
4716 && TYPE_ARG_TYPES (b
->type
)
4717 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
4718 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
4719 TYPE_ARG_TYPES (b
->type
))))
4727 if (lang_hooks
.types
.type_hash_eq
!= NULL
)
4728 return lang_hooks
.types
.type_hash_eq (a
->type
, b
->type
);
4733 /* Return the cached hash value. */
4736 type_hash_hash (const void *item
)
4738 return ((const struct type_hash
*) item
)->hash
;
4741 /* Look in the type hash table for a type isomorphic to TYPE.
4742 If one is found, return it. Otherwise return 0. */
4745 type_hash_lookup (hashval_t hashcode
, tree type
)
4747 struct type_hash
*h
, in
;
4749 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
4750 must call that routine before comparing TYPE_ALIGNs. */
4756 h
= (struct type_hash
*) htab_find_with_hash (type_hash_table
, &in
,
4763 /* Add an entry to the type-hash-table
4764 for a type TYPE whose hash code is HASHCODE. */
4767 type_hash_add (hashval_t hashcode
, tree type
)
4769 struct type_hash
*h
;
4772 h
= GGC_NEW (struct type_hash
);
4775 loc
= htab_find_slot_with_hash (type_hash_table
, h
, hashcode
, INSERT
);
4779 /* Given TYPE, and HASHCODE its hash code, return the canonical
4780 object for an identical type if one already exists.
4781 Otherwise, return TYPE, and record it as the canonical object.
4783 To use this function, first create a type of the sort you want.
4784 Then compute its hash code from the fields of the type that
4785 make it different from other similar types.
4786 Then call this function and use the value. */
4789 type_hash_canon (unsigned int hashcode
, tree type
)
4793 /* The hash table only contains main variants, so ensure that's what we're
4795 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
4797 if (!lang_hooks
.types
.hash_types
)
4800 /* See if the type is in the hash table already. If so, return it.
4801 Otherwise, add the type. */
4802 t1
= type_hash_lookup (hashcode
, type
);
4805 #ifdef GATHER_STATISTICS
4806 tree_node_counts
[(int) t_kind
]--;
4807 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type
);
4813 type_hash_add (hashcode
, type
);
4818 /* See if the data pointed to by the type hash table is marked. We consider
4819 it marked if the type is marked or if a debug type number or symbol
4820 table entry has been made for the type. This reduces the amount of
4821 debugging output and eliminates that dependency of the debug output on
4822 the number of garbage collections. */
4825 type_hash_marked_p (const void *p
)
4827 const_tree
const type
= ((const struct type_hash
*) p
)->type
;
4829 return ggc_marked_p (type
) || TYPE_SYMTAB_POINTER (type
);
4833 print_type_hash_statistics (void)
4835 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
4836 (long) htab_size (type_hash_table
),
4837 (long) htab_elements (type_hash_table
),
4838 htab_collisions (type_hash_table
));
4841 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
4842 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
4843 by adding the hash codes of the individual attributes. */
4846 attribute_hash_list (const_tree list
, hashval_t hashcode
)
4850 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
4851 /* ??? Do we want to add in TREE_VALUE too? */
4852 hashcode
= iterative_hash_object
4853 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail
)), hashcode
);
4857 /* Given two lists of attributes, return true if list l2 is
4858 equivalent to l1. */
4861 attribute_list_equal (const_tree l1
, const_tree l2
)
4863 return attribute_list_contained (l1
, l2
)
4864 && attribute_list_contained (l2
, l1
);
4867 /* Given two lists of attributes, return true if list L2 is
4868 completely contained within L1. */
4869 /* ??? This would be faster if attribute names were stored in a canonicalized
4870 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
4871 must be used to show these elements are equivalent (which they are). */
4872 /* ??? It's not clear that attributes with arguments will always be handled
4876 attribute_list_contained (const_tree l1
, const_tree l2
)
4880 /* First check the obvious, maybe the lists are identical. */
4884 /* Maybe the lists are similar. */
4885 for (t1
= l1
, t2
= l2
;
4887 && TREE_PURPOSE (t1
) == TREE_PURPOSE (t2
)
4888 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
4889 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
));
4891 /* Maybe the lists are equal. */
4892 if (t1
== 0 && t2
== 0)
4895 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
4898 /* This CONST_CAST is okay because lookup_attribute does not
4899 modify its argument and the return value is assigned to a
4901 for (attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
4902 CONST_CAST_TREE(l1
));
4904 attr
= lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2
)),
4907 if (TREE_VALUE (t2
) != NULL
4908 && TREE_CODE (TREE_VALUE (t2
)) == TREE_LIST
4909 && TREE_VALUE (attr
) != NULL
4910 && TREE_CODE (TREE_VALUE (attr
)) == TREE_LIST
)
4912 if (simple_cst_list_equal (TREE_VALUE (t2
),
4913 TREE_VALUE (attr
)) == 1)
4916 else if (simple_cst_equal (TREE_VALUE (t2
), TREE_VALUE (attr
)) == 1)
4927 /* Given two lists of types
4928 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
4929 return 1 if the lists contain the same types in the same order.
4930 Also, the TREE_PURPOSEs must match. */
4933 type_list_equal (const_tree l1
, const_tree l2
)
4937 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
4938 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
4939 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
4940 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
4941 && (TREE_TYPE (TREE_PURPOSE (t1
))
4942 == TREE_TYPE (TREE_PURPOSE (t2
))))))
4948 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
4949 given by TYPE. If the argument list accepts variable arguments,
4950 then this function counts only the ordinary arguments. */
4953 type_num_arguments (const_tree type
)
4958 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
4959 /* If the function does not take a variable number of arguments,
4960 the last element in the list will have type `void'. */
4961 if (VOID_TYPE_P (TREE_VALUE (t
)))
4969 /* Nonzero if integer constants T1 and T2
4970 represent the same constant value. */
4973 tree_int_cst_equal (const_tree t1
, const_tree t2
)
4978 if (t1
== 0 || t2
== 0)
4981 if (TREE_CODE (t1
) == INTEGER_CST
4982 && TREE_CODE (t2
) == INTEGER_CST
4983 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
4984 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
4990 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
4991 The precise way of comparison depends on their data type. */
4994 tree_int_cst_lt (const_tree t1
, const_tree t2
)
4999 if (TYPE_UNSIGNED (TREE_TYPE (t1
)) != TYPE_UNSIGNED (TREE_TYPE (t2
)))
5001 int t1_sgn
= tree_int_cst_sgn (t1
);
5002 int t2_sgn
= tree_int_cst_sgn (t2
);
5004 if (t1_sgn
< t2_sgn
)
5006 else if (t1_sgn
> t2_sgn
)
5008 /* Otherwise, both are non-negative, so we compare them as
5009 unsigned just in case one of them would overflow a signed
5012 else if (!TYPE_UNSIGNED (TREE_TYPE (t1
)))
5013 return INT_CST_LT (t1
, t2
);
5015 return INT_CST_LT_UNSIGNED (t1
, t2
);
5018 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
5021 tree_int_cst_compare (const_tree t1
, const_tree t2
)
5023 if (tree_int_cst_lt (t1
, t2
))
5025 else if (tree_int_cst_lt (t2
, t1
))
5031 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
5032 the host. If POS is zero, the value can be represented in a single
5033 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
5034 be represented in a single unsigned HOST_WIDE_INT. */
5037 host_integerp (const_tree t
, int pos
)
5039 return (TREE_CODE (t
) == INTEGER_CST
5040 && ((TREE_INT_CST_HIGH (t
) == 0
5041 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) >= 0)
5042 || (! pos
&& TREE_INT_CST_HIGH (t
) == -1
5043 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0
5044 && (!TYPE_UNSIGNED (TREE_TYPE (t
))
5045 || (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
5046 && TYPE_IS_SIZETYPE (TREE_TYPE (t
)))))
5047 || (pos
&& TREE_INT_CST_HIGH (t
) == 0)));
5050 /* Return the HOST_WIDE_INT least significant bits of T if it is an
5051 INTEGER_CST and there is no overflow. POS is nonzero if the result must
5052 be non-negative. We must be able to satisfy the above conditions. */
5055 tree_low_cst (const_tree t
, int pos
)
5057 gcc_assert (host_integerp (t
, pos
));
5058 return TREE_INT_CST_LOW (t
);
5061 /* Return the most significant bit of the integer constant T. */
5064 tree_int_cst_msb (const_tree t
)
5068 unsigned HOST_WIDE_INT l
;
5070 /* Note that using TYPE_PRECISION here is wrong. We care about the
5071 actual bits, not the (arbitrary) range of the type. */
5072 prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t
))) - 1;
5073 rshift_double (TREE_INT_CST_LOW (t
), TREE_INT_CST_HIGH (t
), prec
,
5074 2 * HOST_BITS_PER_WIDE_INT
, &l
, &h
, 0);
5075 return (l
& 1) == 1;
5078 /* Return an indication of the sign of the integer constant T.
5079 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
5080 Note that -1 will never be returned if T's type is unsigned. */
5083 tree_int_cst_sgn (const_tree t
)
5085 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
5087 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
5089 else if (TREE_INT_CST_HIGH (t
) < 0)
5095 /* Compare two constructor-element-type constants. Return 1 if the lists
5096 are known to be equal; otherwise return 0. */
5099 simple_cst_list_equal (const_tree l1
, const_tree l2
)
5101 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
5103 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
5106 l1
= TREE_CHAIN (l1
);
5107 l2
= TREE_CHAIN (l2
);
5113 /* Return truthvalue of whether T1 is the same tree structure as T2.
5114 Return 1 if they are the same.
5115 Return 0 if they are understandably different.
5116 Return -1 if either contains tree structure not understood by
5120 simple_cst_equal (const_tree t1
, const_tree t2
)
5122 enum tree_code code1
, code2
;
5128 if (t1
== 0 || t2
== 0)
5131 code1
= TREE_CODE (t1
);
5132 code2
= TREE_CODE (t2
);
5134 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
5136 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
5137 || code2
== NON_LVALUE_EXPR
)
5138 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5140 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
5143 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
5144 || code2
== NON_LVALUE_EXPR
)
5145 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
5153 return (TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
5154 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
));
5157 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
5160 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
5163 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
5164 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
5165 TREE_STRING_LENGTH (t1
)));
5169 unsigned HOST_WIDE_INT idx
;
5170 VEC(constructor_elt
, gc
) *v1
= CONSTRUCTOR_ELTS (t1
);
5171 VEC(constructor_elt
, gc
) *v2
= CONSTRUCTOR_ELTS (t2
);
5173 if (VEC_length (constructor_elt
, v1
) != VEC_length (constructor_elt
, v2
))
5176 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
5177 /* ??? Should we handle also fields here? */
5178 if (!simple_cst_equal (VEC_index (constructor_elt
, v1
, idx
)->value
,
5179 VEC_index (constructor_elt
, v2
, idx
)->value
))
5185 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5188 cmp
= simple_cst_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
));
5191 if (call_expr_nargs (t1
) != call_expr_nargs (t2
))
5194 const_tree arg1
, arg2
;
5195 const_call_expr_arg_iterator iter1
, iter2
;
5196 for (arg1
= first_const_call_expr_arg (t1
, &iter1
),
5197 arg2
= first_const_call_expr_arg (t2
, &iter2
);
5199 arg1
= next_const_call_expr_arg (&iter1
),
5200 arg2
= next_const_call_expr_arg (&iter2
))
5202 cmp
= simple_cst_equal (arg1
, arg2
);
5206 return arg1
== arg2
;
5210 /* Special case: if either target is an unallocated VAR_DECL,
5211 it means that it's going to be unified with whatever the
5212 TARGET_EXPR is really supposed to initialize, so treat it
5213 as being equivalent to anything. */
5214 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
5215 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
5216 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
5217 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
5218 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
5219 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
5222 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5227 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
5229 case WITH_CLEANUP_EXPR
:
5230 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5234 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
5237 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
5238 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
5252 /* This general rule works for most tree codes. All exceptions should be
5253 handled above. If this is a language-specific tree code, we can't
5254 trust what might be in the operand, so say we don't know
5256 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
5259 switch (TREE_CODE_CLASS (code1
))
5263 case tcc_comparison
:
5264 case tcc_expression
:
5268 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
5270 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
5282 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
5283 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
5284 than U, respectively. */
5287 compare_tree_int (const_tree t
, unsigned HOST_WIDE_INT u
)
5289 if (tree_int_cst_sgn (t
) < 0)
5291 else if (TREE_INT_CST_HIGH (t
) != 0)
5293 else if (TREE_INT_CST_LOW (t
) == u
)
5295 else if (TREE_INT_CST_LOW (t
) < u
)
5301 /* Return true if CODE represents an associative tree code. Otherwise
5304 associative_tree_code (enum tree_code code
)
5323 /* Return true if CODE represents a commutative tree code. Otherwise
5326 commutative_tree_code (enum tree_code code
)
5339 case UNORDERED_EXPR
:
5343 case TRUTH_AND_EXPR
:
5344 case TRUTH_XOR_EXPR
:
5354 /* Generate a hash value for an expression. This can be used iteratively
5355 by passing a previous result as the "val" argument.
5357 This function is intended to produce the same hash for expressions which
5358 would compare equal using operand_equal_p. */
5361 iterative_hash_expr (const_tree t
, hashval_t val
)
5364 enum tree_code code
;
5368 return iterative_hash_pointer (t
, val
);
5370 code
= TREE_CODE (t
);
5374 /* Alas, constants aren't shared, so we can't rely on pointer
5377 val
= iterative_hash_host_wide_int (TREE_INT_CST_LOW (t
), val
);
5378 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t
), val
);
5381 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
5383 return iterative_hash_hashval_t (val2
, val
);
5387 unsigned int val2
= fixed_hash (TREE_FIXED_CST_PTR (t
));
5389 return iterative_hash_hashval_t (val2
, val
);
5392 return iterative_hash (TREE_STRING_POINTER (t
),
5393 TREE_STRING_LENGTH (t
), val
);
5395 val
= iterative_hash_expr (TREE_REALPART (t
), val
);
5396 return iterative_hash_expr (TREE_IMAGPART (t
), val
);
5398 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t
), val
);
5401 /* we can just compare by pointer. */
5402 return iterative_hash_pointer (t
, val
);
5405 /* A list of expressions, for a CALL_EXPR or as the elements of a
5407 for (; t
; t
= TREE_CHAIN (t
))
5408 val
= iterative_hash_expr (TREE_VALUE (t
), val
);
5412 unsigned HOST_WIDE_INT idx
;
5414 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
5416 val
= iterative_hash_expr (field
, val
);
5417 val
= iterative_hash_expr (value
, val
);
5422 /* When referring to a built-in FUNCTION_DECL, use the
5423 __builtin__ form. Otherwise nodes that compare equal
5424 according to operand_equal_p might get different
5426 if (DECL_BUILT_IN (t
))
5428 val
= iterative_hash_pointer (built_in_decls
[DECL_FUNCTION_CODE (t
)],
5432 /* else FALL THROUGH */
5434 class = TREE_CODE_CLASS (code
);
5436 if (class == tcc_declaration
)
5438 /* DECL's have a unique ID */
5439 val
= iterative_hash_host_wide_int (DECL_UID (t
), val
);
5443 gcc_assert (IS_EXPR_CODE_CLASS (class));
5445 val
= iterative_hash_object (code
, val
);
5447 /* Don't hash the type, that can lead to having nodes which
5448 compare equal according to operand_equal_p, but which
5449 have different hash codes. */
5450 if (code
== NOP_EXPR
5451 || code
== CONVERT_EXPR
5452 || code
== NON_LVALUE_EXPR
)
5454 /* Make sure to include signness in the hash computation. */
5455 val
+= TYPE_UNSIGNED (TREE_TYPE (t
));
5456 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
5459 else if (commutative_tree_code (code
))
5461 /* It's a commutative expression. We want to hash it the same
5462 however it appears. We do this by first hashing both operands
5463 and then rehashing based on the order of their independent
5465 hashval_t one
= iterative_hash_expr (TREE_OPERAND (t
, 0), 0);
5466 hashval_t two
= iterative_hash_expr (TREE_OPERAND (t
, 1), 0);
5470 t
= one
, one
= two
, two
= t
;
5472 val
= iterative_hash_hashval_t (one
, val
);
5473 val
= iterative_hash_hashval_t (two
, val
);
5476 for (i
= TREE_OPERAND_LENGTH (t
) - 1; i
>= 0; --i
)
5477 val
= iterative_hash_expr (TREE_OPERAND (t
, i
), val
);
5484 /* Constructors for pointer, array and function types.
5485 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
5486 constructed by language-dependent code, not here.) */
5488 /* Construct, lay out and return the type of pointers to TO_TYPE with
5489 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
5490 reference all of memory. If such a type has already been
5491 constructed, reuse it. */
5494 build_pointer_type_for_mode (tree to_type
, enum machine_mode mode
,
5499 if (to_type
== error_mark_node
)
5500 return error_mark_node
;
5502 /* In some cases, languages will have things that aren't a POINTER_TYPE
5503 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
5504 In that case, return that type without regard to the rest of our
5507 ??? This is a kludge, but consistent with the way this function has
5508 always operated and there doesn't seem to be a good way to avoid this
5510 if (TYPE_POINTER_TO (to_type
) != 0
5511 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
5512 return TYPE_POINTER_TO (to_type
);
5514 /* First, if we already have a type for pointers to TO_TYPE and it's
5515 the proper mode, use it. */
5516 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
5517 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
5520 t
= make_node (POINTER_TYPE
);
5522 TREE_TYPE (t
) = to_type
;
5523 TYPE_MODE (t
) = mode
;
5524 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
5525 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
5526 TYPE_POINTER_TO (to_type
) = t
;
5528 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
5529 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5530 else if (TYPE_CANONICAL (to_type
) != to_type
)
5532 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
5533 mode
, can_alias_all
);
5535 /* Lay out the type. This function has many callers that are concerned
5536 with expression-construction, and this simplifies them all. */
5542 /* By default build pointers in ptr_mode. */
5545 build_pointer_type (tree to_type
)
5547 return build_pointer_type_for_mode (to_type
, ptr_mode
, false);
5550 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
5553 build_reference_type_for_mode (tree to_type
, enum machine_mode mode
,
5558 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
5559 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
5560 In that case, return that type without regard to the rest of our
5563 ??? This is a kludge, but consistent with the way this function has
5564 always operated and there doesn't seem to be a good way to avoid this
5566 if (TYPE_REFERENCE_TO (to_type
) != 0
5567 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
5568 return TYPE_REFERENCE_TO (to_type
);
5570 /* First, if we already have a type for pointers to TO_TYPE and it's
5571 the proper mode, use it. */
5572 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
5573 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
5576 t
= make_node (REFERENCE_TYPE
);
5578 TREE_TYPE (t
) = to_type
;
5579 TYPE_MODE (t
) = mode
;
5580 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
5581 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
5582 TYPE_REFERENCE_TO (to_type
) = t
;
5584 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
5585 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5586 else if (TYPE_CANONICAL (to_type
) != to_type
)
5588 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
5589 mode
, can_alias_all
);
5597 /* Build the node for the type of references-to-TO_TYPE by default
5601 build_reference_type (tree to_type
)
5603 return build_reference_type_for_mode (to_type
, ptr_mode
, false);
5606 /* Build a type that is compatible with t but has no cv quals anywhere
5609 const char *const *const * -> char ***. */
5612 build_type_no_quals (tree t
)
5614 switch (TREE_CODE (t
))
5617 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
5619 TYPE_REF_CAN_ALIAS_ALL (t
));
5620 case REFERENCE_TYPE
:
5622 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
5624 TYPE_REF_CAN_ALIAS_ALL (t
));
5626 return TYPE_MAIN_VARIANT (t
);
5630 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
5631 MAXVAL should be the maximum value in the domain
5632 (one less than the length of the array).
5634 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
5635 We don't enforce this limit, that is up to caller (e.g. language front end).
5636 The limit exists because the result is a signed type and we don't handle
5637 sizes that use more than one HOST_WIDE_INT. */
5640 build_index_type (tree maxval
)
5642 tree itype
= make_node (INTEGER_TYPE
);
5644 TREE_TYPE (itype
) = sizetype
;
5645 TYPE_PRECISION (itype
) = TYPE_PRECISION (sizetype
);
5646 TYPE_MIN_VALUE (itype
) = size_zero_node
;
5647 TYPE_MAX_VALUE (itype
) = fold_convert (sizetype
, maxval
);
5648 TYPE_MODE (itype
) = TYPE_MODE (sizetype
);
5649 TYPE_SIZE (itype
) = TYPE_SIZE (sizetype
);
5650 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (sizetype
);
5651 TYPE_ALIGN (itype
) = TYPE_ALIGN (sizetype
);
5652 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (sizetype
);
5654 if (host_integerp (maxval
, 1))
5655 return type_hash_canon (tree_low_cst (maxval
, 1), itype
);
5658 /* Since we cannot hash this type, we need to compare it using
5659 structural equality checks. */
5660 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
5665 /* Builds a signed or unsigned integer type of precision PRECISION.
5666 Used for C bitfields whose precision does not match that of
5667 built-in target types. */
5669 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
5672 tree itype
= make_node (INTEGER_TYPE
);
5674 TYPE_PRECISION (itype
) = precision
;
5677 fixup_unsigned_type (itype
);
5679 fixup_signed_type (itype
);
5681 if (host_integerp (TYPE_MAX_VALUE (itype
), 1))
5682 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype
), 1), itype
);
5687 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
5688 ENUMERAL_TYPE or BOOLEAN_TYPE), with low bound LOWVAL and
5689 high bound HIGHVAL. If TYPE is NULL, sizetype is used. */
5692 build_range_type (tree type
, tree lowval
, tree highval
)
5694 tree itype
= make_node (INTEGER_TYPE
);
5696 TREE_TYPE (itype
) = type
;
5697 if (type
== NULL_TREE
)
5700 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
5701 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
5703 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
5704 TYPE_MODE (itype
) = TYPE_MODE (type
);
5705 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
5706 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
5707 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
5708 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
5710 if (host_integerp (lowval
, 0) && highval
!= 0 && host_integerp (highval
, 0))
5711 return type_hash_canon (tree_low_cst (highval
, 0)
5712 - tree_low_cst (lowval
, 0),
5718 /* Just like build_index_type, but takes lowval and highval instead
5719 of just highval (maxval). */
5722 build_index_2_type (tree lowval
, tree highval
)
5724 return build_range_type (sizetype
, lowval
, highval
);
5727 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
5728 and number of elements specified by the range of values of INDEX_TYPE.
5729 If such a type has already been constructed, reuse it. */
5732 build_array_type (tree elt_type
, tree index_type
)
5735 hashval_t hashcode
= 0;
5737 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
5739 error ("arrays of functions are not meaningful");
5740 elt_type
= integer_type_node
;
5743 t
= make_node (ARRAY_TYPE
);
5744 TREE_TYPE (t
) = elt_type
;
5745 TYPE_DOMAIN (t
) = index_type
;
5747 if (index_type
== 0)
5750 hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), hashcode
);
5751 t
= type_hash_canon (hashcode
, t
);
5755 if (TYPE_CANONICAL (t
) == t
)
5757 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
))
5758 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5759 else if (TYPE_CANONICAL (elt_type
) != elt_type
)
5761 = build_array_type (TYPE_CANONICAL (elt_type
), index_type
);
5767 hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), hashcode
);
5768 hashcode
= iterative_hash_object (TYPE_HASH (index_type
), hashcode
);
5769 t
= type_hash_canon (hashcode
, t
);
5771 if (!COMPLETE_TYPE_P (t
))
5774 if (TYPE_CANONICAL (t
) == t
)
5776 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
5777 || TYPE_STRUCTURAL_EQUALITY_P (index_type
))
5778 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5779 else if (TYPE_CANONICAL (elt_type
) != elt_type
5780 || TYPE_CANONICAL (index_type
) != index_type
)
5782 = build_array_type (TYPE_CANONICAL (elt_type
),
5783 TYPE_CANONICAL (index_type
));
5789 /* Recursively examines the array elements of TYPE, until a non-array
5790 element type is found. */
5793 strip_array_types (tree type
)
5795 while (TREE_CODE (type
) == ARRAY_TYPE
)
5796 type
= TREE_TYPE (type
);
5801 /* Computes the canonical argument types from the argument type list
5804 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
5805 on entry to this function, or if any of the ARGTYPES are
5808 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
5809 true on entry to this function, or if any of the ARGTYPES are
5812 Returns a canonical argument list, which may be ARGTYPES when the
5813 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
5814 true) or would not differ from ARGTYPES. */
5817 maybe_canonicalize_argtypes(tree argtypes
,
5818 bool *any_structural_p
,
5819 bool *any_noncanonical_p
)
5822 bool any_noncanonical_argtypes_p
= false;
5824 for (arg
= argtypes
; arg
&& !(*any_structural_p
); arg
= TREE_CHAIN (arg
))
5826 if (!TREE_VALUE (arg
) || TREE_VALUE (arg
) == error_mark_node
)
5827 /* Fail gracefully by stating that the type is structural. */
5828 *any_structural_p
= true;
5829 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg
)))
5830 *any_structural_p
= true;
5831 else if (TYPE_CANONICAL (TREE_VALUE (arg
)) != TREE_VALUE (arg
)
5832 || TREE_PURPOSE (arg
))
5833 /* If the argument has a default argument, we consider it
5834 non-canonical even though the type itself is canonical.
5835 That way, different variants of function and method types
5836 with default arguments will all point to the variant with
5837 no defaults as their canonical type. */
5838 any_noncanonical_argtypes_p
= true;
5841 if (*any_structural_p
)
5844 if (any_noncanonical_argtypes_p
)
5846 /* Build the canonical list of argument types. */
5847 tree canon_argtypes
= NULL_TREE
;
5848 bool is_void
= false;
5850 for (arg
= argtypes
; arg
; arg
= TREE_CHAIN (arg
))
5852 if (arg
== void_list_node
)
5855 canon_argtypes
= tree_cons (NULL_TREE
,
5856 TYPE_CANONICAL (TREE_VALUE (arg
)),
5860 canon_argtypes
= nreverse (canon_argtypes
);
5862 canon_argtypes
= chainon (canon_argtypes
, void_list_node
);
5864 /* There is a non-canonical type. */
5865 *any_noncanonical_p
= true;
5866 return canon_argtypes
;
5869 /* The canonical argument types are the same as ARGTYPES. */
5873 /* Construct, lay out and return
5874 the type of functions returning type VALUE_TYPE
5875 given arguments of types ARG_TYPES.
5876 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
5877 are data type nodes for the arguments of the function.
5878 If such a type has already been constructed, reuse it. */
5881 build_function_type (tree value_type
, tree arg_types
)
5884 hashval_t hashcode
= 0;
5885 bool any_structural_p
, any_noncanonical_p
;
5886 tree canon_argtypes
;
5888 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
5890 error ("function return type cannot be function");
5891 value_type
= integer_type_node
;
5894 /* Make a node of the sort we want. */
5895 t
= make_node (FUNCTION_TYPE
);
5896 TREE_TYPE (t
) = value_type
;
5897 TYPE_ARG_TYPES (t
) = arg_types
;
5899 /* If we already have such a type, use the old one. */
5900 hashcode
= iterative_hash_object (TYPE_HASH (value_type
), hashcode
);
5901 hashcode
= type_hash_list (arg_types
, hashcode
);
5902 t
= type_hash_canon (hashcode
, t
);
5904 /* Set up the canonical type. */
5905 any_structural_p
= TYPE_STRUCTURAL_EQUALITY_P (value_type
);
5906 any_noncanonical_p
= TYPE_CANONICAL (value_type
) != value_type
;
5907 canon_argtypes
= maybe_canonicalize_argtypes (arg_types
,
5909 &any_noncanonical_p
);
5910 if (any_structural_p
)
5911 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5912 else if (any_noncanonical_p
)
5913 TYPE_CANONICAL (t
) = build_function_type (TYPE_CANONICAL (value_type
),
5916 if (!COMPLETE_TYPE_P (t
))
5921 /* Build a function type. The RETURN_TYPE is the type returned by the
5922 function. If VAARGS is set, no void_type_node is appended to the
5923 the list. ARGP muse be alway be terminated be a NULL_TREE. */
5926 build_function_type_list_1 (bool vaargs
, tree return_type
, va_list argp
)
5930 t
= va_arg (argp
, tree
);
5931 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (argp
, tree
))
5932 args
= tree_cons (NULL_TREE
, t
, args
);
5937 if (args
!= NULL_TREE
)
5938 args
= nreverse (args
);
5939 gcc_assert (args
!= NULL_TREE
&& last
!= void_list_node
);
5941 else if (args
== NULL_TREE
)
5942 args
= void_list_node
;
5946 args
= nreverse (args
);
5947 TREE_CHAIN (last
) = void_list_node
;
5949 args
= build_function_type (return_type
, args
);
5954 /* Build a function type. The RETURN_TYPE is the type returned by the
5955 function. If additional arguments are provided, they are
5956 additional argument types. The list of argument types must always
5957 be terminated by NULL_TREE. */
5960 build_function_type_list (tree return_type
, ...)
5965 va_start (p
, return_type
);
5966 args
= build_function_type_list_1 (false, return_type
, p
);
5971 /* Build a variable argument function type. The RETURN_TYPE is the
5972 type returned by the function. If additional arguments are provided,
5973 they are additional argument types. The list of argument types must
5974 always be terminated by NULL_TREE. */
5977 build_varargs_function_type_list (tree return_type
, ...)
5982 va_start (p
, return_type
);
5983 args
= build_function_type_list_1 (true, return_type
, p
);
5989 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
5990 and ARGTYPES (a TREE_LIST) are the return type and arguments types
5991 for the method. An implicit additional parameter (of type
5992 pointer-to-BASETYPE) is added to the ARGTYPES. */
5995 build_method_type_directly (tree basetype
,
6002 bool any_structural_p
, any_noncanonical_p
;
6003 tree canon_argtypes
;
6005 /* Make a node of the sort we want. */
6006 t
= make_node (METHOD_TYPE
);
6008 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
6009 TREE_TYPE (t
) = rettype
;
6010 ptype
= build_pointer_type (basetype
);
6012 /* The actual arglist for this function includes a "hidden" argument
6013 which is "this". Put it into the list of argument types. */
6014 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
6015 TYPE_ARG_TYPES (t
) = argtypes
;
6017 /* If we already have such a type, use the old one. */
6018 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
6019 hashcode
= iterative_hash_object (TYPE_HASH (rettype
), hashcode
);
6020 hashcode
= type_hash_list (argtypes
, hashcode
);
6021 t
= type_hash_canon (hashcode
, t
);
6023 /* Set up the canonical type. */
6025 = (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
6026 || TYPE_STRUCTURAL_EQUALITY_P (rettype
));
6028 = (TYPE_CANONICAL (basetype
) != basetype
6029 || TYPE_CANONICAL (rettype
) != rettype
);
6030 canon_argtypes
= maybe_canonicalize_argtypes (TREE_CHAIN (argtypes
),
6032 &any_noncanonical_p
);
6033 if (any_structural_p
)
6034 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6035 else if (any_noncanonical_p
)
6037 = build_method_type_directly (TYPE_CANONICAL (basetype
),
6038 TYPE_CANONICAL (rettype
),
6040 if (!COMPLETE_TYPE_P (t
))
6046 /* Construct, lay out and return the type of methods belonging to class
6047 BASETYPE and whose arguments and values are described by TYPE.
6048 If that type exists already, reuse it.
6049 TYPE must be a FUNCTION_TYPE node. */
6052 build_method_type (tree basetype
, tree type
)
6054 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
6056 return build_method_type_directly (basetype
,
6058 TYPE_ARG_TYPES (type
));
6061 /* Construct, lay out and return the type of offsets to a value
6062 of type TYPE, within an object of type BASETYPE.
6063 If a suitable offset type exists already, reuse it. */
6066 build_offset_type (tree basetype
, tree type
)
6069 hashval_t hashcode
= 0;
6071 /* Make a node of the sort we want. */
6072 t
= make_node (OFFSET_TYPE
);
6074 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
6075 TREE_TYPE (t
) = type
;
6077 /* If we already have such a type, use the old one. */
6078 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
6079 hashcode
= iterative_hash_object (TYPE_HASH (type
), hashcode
);
6080 t
= type_hash_canon (hashcode
, t
);
6082 if (!COMPLETE_TYPE_P (t
))
6085 if (TYPE_CANONICAL (t
) == t
)
6087 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
6088 || TYPE_STRUCTURAL_EQUALITY_P (type
))
6089 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6090 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)) != basetype
6091 || TYPE_CANONICAL (type
) != type
)
6093 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)),
6094 TYPE_CANONICAL (type
));
6100 /* Create a complex type whose components are COMPONENT_TYPE. */
6103 build_complex_type (tree component_type
)
6108 /* Make a node of the sort we want. */
6109 t
= make_node (COMPLEX_TYPE
);
6111 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
6113 /* If we already have such a type, use the old one. */
6114 hashcode
= iterative_hash_object (TYPE_HASH (component_type
), 0);
6115 t
= type_hash_canon (hashcode
, t
);
6117 if (!COMPLETE_TYPE_P (t
))
6120 if (TYPE_CANONICAL (t
) == t
)
6122 if (TYPE_STRUCTURAL_EQUALITY_P (component_type
))
6123 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6124 else if (TYPE_CANONICAL (component_type
) != component_type
)
6126 = build_complex_type (TYPE_CANONICAL (component_type
));
6129 /* We need to create a name, since complex is a fundamental type. */
6130 if (! TYPE_NAME (t
))
6133 if (component_type
== char_type_node
)
6134 name
= "complex char";
6135 else if (component_type
== signed_char_type_node
)
6136 name
= "complex signed char";
6137 else if (component_type
== unsigned_char_type_node
)
6138 name
= "complex unsigned char";
6139 else if (component_type
== short_integer_type_node
)
6140 name
= "complex short int";
6141 else if (component_type
== short_unsigned_type_node
)
6142 name
= "complex short unsigned int";
6143 else if (component_type
== integer_type_node
)
6144 name
= "complex int";
6145 else if (component_type
== unsigned_type_node
)
6146 name
= "complex unsigned int";
6147 else if (component_type
== long_integer_type_node
)
6148 name
= "complex long int";
6149 else if (component_type
== long_unsigned_type_node
)
6150 name
= "complex long unsigned int";
6151 else if (component_type
== long_long_integer_type_node
)
6152 name
= "complex long long int";
6153 else if (component_type
== long_long_unsigned_type_node
)
6154 name
= "complex long long unsigned int";
6159 TYPE_NAME (t
) = build_decl (TYPE_DECL
, get_identifier (name
), t
);
6162 return build_qualified_type (t
, TYPE_QUALS (component_type
));
6165 /* Return OP, stripped of any conversions to wider types as much as is safe.
6166 Converting the value back to OP's type makes a value equivalent to OP.
6168 If FOR_TYPE is nonzero, we return a value which, if converted to
6169 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
6171 OP must have integer, real or enumeral type. Pointers are not allowed!
6173 There are some cases where the obvious value we could return
6174 would regenerate to OP if converted to OP's type,
6175 but would not extend like OP to wider types.
6176 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
6177 For example, if OP is (unsigned short)(signed char)-1,
6178 we avoid returning (signed char)-1 if FOR_TYPE is int,
6179 even though extending that to an unsigned short would regenerate OP,
6180 since the result of extending (signed char)-1 to (int)
6181 is different from (int) OP. */
6184 get_unwidened (tree op
, tree for_type
)
6186 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
6187 tree type
= TREE_TYPE (op
);
6189 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
6191 = (for_type
!= 0 && for_type
!= type
6192 && final_prec
> TYPE_PRECISION (type
)
6193 && TYPE_UNSIGNED (type
));
6196 while (CONVERT_EXPR_P (op
))
6200 /* TYPE_PRECISION on vector types has different meaning
6201 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
6202 so avoid them here. */
6203 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
6206 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
6207 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
6209 /* Truncations are many-one so cannot be removed.
6210 Unless we are later going to truncate down even farther. */
6212 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
6215 /* See what's inside this conversion. If we decide to strip it,
6217 op
= TREE_OPERAND (op
, 0);
6219 /* If we have not stripped any zero-extensions (uns is 0),
6220 we can strip any kind of extension.
6221 If we have previously stripped a zero-extension,
6222 only zero-extensions can safely be stripped.
6223 Any extension can be stripped if the bits it would produce
6224 are all going to be discarded later by truncating to FOR_TYPE. */
6228 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
6230 /* TYPE_UNSIGNED says whether this is a zero-extension.
6231 Let's avoid computing it if it does not affect WIN
6232 and if UNS will not be needed again. */
6234 || CONVERT_EXPR_P (op
))
6235 && TYPE_UNSIGNED (TREE_TYPE (op
)))
6246 /* Return OP or a simpler expression for a narrower value
6247 which can be sign-extended or zero-extended to give back OP.
6248 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
6249 or 0 if the value should be sign-extended. */
6252 get_narrower (tree op
, int *unsignedp_ptr
)
6257 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
6259 while (TREE_CODE (op
) == NOP_EXPR
)
6262 = (TYPE_PRECISION (TREE_TYPE (op
))
6263 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
6265 /* Truncations are many-one so cannot be removed. */
6269 /* See what's inside this conversion. If we decide to strip it,
6274 op
= TREE_OPERAND (op
, 0);
6275 /* An extension: the outermost one can be stripped,
6276 but remember whether it is zero or sign extension. */
6278 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
6279 /* Otherwise, if a sign extension has been stripped,
6280 only sign extensions can now be stripped;
6281 if a zero extension has been stripped, only zero-extensions. */
6282 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
6286 else /* bitschange == 0 */
6288 /* A change in nominal type can always be stripped, but we must
6289 preserve the unsignedness. */
6291 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
6293 op
= TREE_OPERAND (op
, 0);
6294 /* Keep trying to narrow, but don't assign op to win if it
6295 would turn an integral type into something else. */
6296 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
6303 if (TREE_CODE (op
) == COMPONENT_REF
6304 /* Since type_for_size always gives an integer type. */
6305 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
6306 && TREE_CODE (TREE_TYPE (op
)) != FIXED_POINT_TYPE
6307 /* Ensure field is laid out already. */
6308 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
6309 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
6311 unsigned HOST_WIDE_INT innerprec
6312 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
6313 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
6314 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
6315 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
6317 /* We can get this structure field in a narrower type that fits it,
6318 but the resulting extension to its nominal type (a fullword type)
6319 must satisfy the same conditions as for other extensions.
6321 Do this only for fields that are aligned (not bit-fields),
6322 because when bit-field insns will be used there is no
6323 advantage in doing this. */
6325 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
6326 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
6327 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
6331 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
6332 win
= fold_convert (type
, op
);
6336 *unsignedp_ptr
= uns
;
6340 /* Nonzero if integer constant C has a value that is permissible
6341 for type TYPE (an INTEGER_TYPE). */
6344 int_fits_type_p (const_tree c
, const_tree type
)
6346 tree type_low_bound
= TYPE_MIN_VALUE (type
);
6347 tree type_high_bound
= TYPE_MAX_VALUE (type
);
6348 bool ok_for_low_bound
, ok_for_high_bound
;
6349 unsigned HOST_WIDE_INT low
;
6352 /* If at least one bound of the type is a constant integer, we can check
6353 ourselves and maybe make a decision. If no such decision is possible, but
6354 this type is a subtype, try checking against that. Otherwise, use
6355 fit_double_type, which checks against the precision.
6357 Compute the status for each possibly constant bound, and return if we see
6358 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
6359 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
6360 for "constant known to fit". */
6362 /* Check if C >= type_low_bound. */
6363 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
6365 if (tree_int_cst_lt (c
, type_low_bound
))
6367 ok_for_low_bound
= true;
6370 ok_for_low_bound
= false;
6372 /* Check if c <= type_high_bound. */
6373 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
6375 if (tree_int_cst_lt (type_high_bound
, c
))
6377 ok_for_high_bound
= true;
6380 ok_for_high_bound
= false;
6382 /* If the constant fits both bounds, the result is known. */
6383 if (ok_for_low_bound
&& ok_for_high_bound
)
6386 /* Perform some generic filtering which may allow making a decision
6387 even if the bounds are not constant. First, negative integers
6388 never fit in unsigned types, */
6389 if (TYPE_UNSIGNED (type
) && tree_int_cst_sgn (c
) < 0)
6392 /* Second, narrower types always fit in wider ones. */
6393 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
6396 /* Third, unsigned integers with top bit set never fit signed types. */
6397 if (! TYPE_UNSIGNED (type
)
6398 && TYPE_UNSIGNED (TREE_TYPE (c
))
6399 && tree_int_cst_msb (c
))
6402 /* If we haven't been able to decide at this point, there nothing more we
6403 can check ourselves here. Look at the base type if we have one and it
6404 has the same precision. */
6405 if (TREE_CODE (type
) == INTEGER_TYPE
6406 && TREE_TYPE (type
) != 0
6407 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
6408 return int_fits_type_p (c
, TREE_TYPE (type
));
6410 /* Or to fit_double_type, if nothing else. */
6411 low
= TREE_INT_CST_LOW (c
);
6412 high
= TREE_INT_CST_HIGH (c
);
6413 return !fit_double_type (low
, high
, &low
, &high
, type
);
6416 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
6417 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
6418 represented (assuming two's-complement arithmetic) within the bit
6419 precision of the type are returned instead. */
6422 get_type_static_bounds (const_tree type
, mpz_t min
, mpz_t max
)
6424 if (!POINTER_TYPE_P (type
) && TYPE_MIN_VALUE (type
)
6425 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
6426 mpz_set_double_int (min
, tree_to_double_int (TYPE_MIN_VALUE (type
)),
6427 TYPE_UNSIGNED (type
));
6430 if (TYPE_UNSIGNED (type
))
6431 mpz_set_ui (min
, 0);
6435 mn
= double_int_mask (TYPE_PRECISION (type
) - 1);
6436 mn
= double_int_sext (double_int_add (mn
, double_int_one
),
6437 TYPE_PRECISION (type
));
6438 mpz_set_double_int (min
, mn
, false);
6442 if (!POINTER_TYPE_P (type
) && TYPE_MAX_VALUE (type
)
6443 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
)
6444 mpz_set_double_int (max
, tree_to_double_int (TYPE_MAX_VALUE (type
)),
6445 TYPE_UNSIGNED (type
));
6448 if (TYPE_UNSIGNED (type
))
6449 mpz_set_double_int (max
, double_int_mask (TYPE_PRECISION (type
)),
6452 mpz_set_double_int (max
, double_int_mask (TYPE_PRECISION (type
) - 1),
6457 /* auto_var_in_fn_p is called to determine whether VAR is an automatic
6458 variable defined in function FN. */
6461 auto_var_in_fn_p (const_tree var
, const_tree fn
)
6463 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
6464 && (((TREE_CODE (var
) == VAR_DECL
|| TREE_CODE (var
) == PARM_DECL
)
6465 && ! TREE_STATIC (var
))
6466 || TREE_CODE (var
) == LABEL_DECL
6467 || TREE_CODE (var
) == RESULT_DECL
));
6470 /* Subprogram of following function. Called by walk_tree.
6472 Return *TP if it is an automatic variable or parameter of the
6473 function passed in as DATA. */
6476 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
6478 tree fn
= (tree
) data
;
6483 else if (DECL_P (*tp
)
6484 && auto_var_in_fn_p (*tp
, fn
))
6490 /* Returns true if T is, contains, or refers to a type with variable
6491 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
6492 arguments, but not the return type. If FN is nonzero, only return
6493 true if a modifier of the type or position of FN is a variable or
6494 parameter inside FN.
6496 This concept is more general than that of C99 'variably modified types':
6497 in C99, a struct type is never variably modified because a VLA may not
6498 appear as a structure member. However, in GNU C code like:
6500 struct S { int i[f()]; };
6502 is valid, and other languages may define similar constructs. */
6505 variably_modified_type_p (tree type
, tree fn
)
6509 /* Test if T is either variable (if FN is zero) or an expression containing
6510 a variable in FN. */
6511 #define RETURN_TRUE_IF_VAR(T) \
6512 do { tree _t = (T); \
6513 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
6514 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
6515 return true; } while (0)
6517 if (type
== error_mark_node
)
6520 /* If TYPE itself has variable size, it is variably modified. */
6521 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
6522 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
6524 switch (TREE_CODE (type
))
6527 case REFERENCE_TYPE
:
6529 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
6535 /* If TYPE is a function type, it is variably modified if the
6536 return type is variably modified. */
6537 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
6543 case FIXED_POINT_TYPE
:
6546 /* Scalar types are variably modified if their end points
6548 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
6549 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
6554 case QUAL_UNION_TYPE
:
6555 /* We can't see if any of the fields are variably-modified by the
6556 definition we normally use, since that would produce infinite
6557 recursion via pointers. */
6558 /* This is variably modified if some field's type is. */
6559 for (t
= TYPE_FIELDS (type
); t
; t
= TREE_CHAIN (t
))
6560 if (TREE_CODE (t
) == FIELD_DECL
)
6562 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
6563 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
6564 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
6566 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
6567 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
6572 /* Do not call ourselves to avoid infinite recursion. This is
6573 variably modified if the element type is. */
6574 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
6575 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
6582 /* The current language may have other cases to check, but in general,
6583 all other types are not variably modified. */
6584 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
6586 #undef RETURN_TRUE_IF_VAR
6589 /* Given a DECL or TYPE, return the scope in which it was declared, or
6590 NULL_TREE if there is no containing scope. */
6593 get_containing_scope (const_tree t
)
6595 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
6598 /* Return the innermost context enclosing DECL that is
6599 a FUNCTION_DECL, or zero if none. */
6602 decl_function_context (const_tree decl
)
6606 if (TREE_CODE (decl
) == ERROR_MARK
)
6609 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
6610 where we look up the function at runtime. Such functions always take
6611 a first argument of type 'pointer to real context'.
6613 C++ should really be fixed to use DECL_CONTEXT for the real context,
6614 and use something else for the "virtual context". */
6615 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
6618 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
6620 context
= DECL_CONTEXT (decl
);
6622 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
6624 if (TREE_CODE (context
) == BLOCK
)
6625 context
= BLOCK_SUPERCONTEXT (context
);
6627 context
= get_containing_scope (context
);
6633 /* Return the innermost context enclosing DECL that is
6634 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
6635 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
6638 decl_type_context (const_tree decl
)
6640 tree context
= DECL_CONTEXT (decl
);
6643 switch (TREE_CODE (context
))
6645 case NAMESPACE_DECL
:
6646 case TRANSLATION_UNIT_DECL
:
6651 case QUAL_UNION_TYPE
:
6656 context
= DECL_CONTEXT (context
);
6660 context
= BLOCK_SUPERCONTEXT (context
);
6670 /* CALL is a CALL_EXPR. Return the declaration for the function
6671 called, or NULL_TREE if the called function cannot be
6675 get_callee_fndecl (const_tree call
)
6679 if (call
== error_mark_node
)
6680 return error_mark_node
;
6682 /* It's invalid to call this function with anything but a
6684 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
6686 /* The first operand to the CALL is the address of the function
6688 addr
= CALL_EXPR_FN (call
);
6692 /* If this is a readonly function pointer, extract its initial value. */
6693 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
6694 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
6695 && DECL_INITIAL (addr
))
6696 addr
= DECL_INITIAL (addr
);
6698 /* If the address is just `&f' for some function `f', then we know
6699 that `f' is being called. */
6700 if (TREE_CODE (addr
) == ADDR_EXPR
6701 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
6702 return TREE_OPERAND (addr
, 0);
6704 /* We couldn't figure out what was being called. Maybe the front
6705 end has some idea. */
6706 return lang_hooks
.lang_get_callee_fndecl (call
);
6709 /* Print debugging information about tree nodes generated during the compile,
6710 and any language-specific information. */
6713 dump_tree_statistics (void)
6715 #ifdef GATHER_STATISTICS
6717 int total_nodes
, total_bytes
;
6720 fprintf (stderr
, "\n??? tree nodes created\n\n");
6721 #ifdef GATHER_STATISTICS
6722 fprintf (stderr
, "Kind Nodes Bytes\n");
6723 fprintf (stderr
, "---------------------------------------\n");
6724 total_nodes
= total_bytes
= 0;
6725 for (i
= 0; i
< (int) all_kinds
; i
++)
6727 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
6728 tree_node_counts
[i
], tree_node_sizes
[i
]);
6729 total_nodes
+= tree_node_counts
[i
];
6730 total_bytes
+= tree_node_sizes
[i
];
6732 fprintf (stderr
, "---------------------------------------\n");
6733 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
6734 fprintf (stderr
, "---------------------------------------\n");
6735 ssanames_print_statistics ();
6736 phinodes_print_statistics ();
6738 fprintf (stderr
, "(No per-node statistics)\n");
6740 print_type_hash_statistics ();
6741 print_debug_expr_statistics ();
6742 print_value_expr_statistics ();
6743 print_restrict_base_statistics ();
6744 lang_hooks
.print_statistics ();
6747 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
6749 /* Generate a crc32 of a string. */
6752 crc32_string (unsigned chksum
, const char *string
)
6756 unsigned value
= *string
<< 24;
6759 for (ix
= 8; ix
--; value
<<= 1)
6763 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
6772 /* P is a string that will be used in a symbol. Mask out any characters
6773 that are not valid in that context. */
6776 clean_symbol_name (char *p
)
6780 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
6783 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
6790 /* Generate a name for a special-purpose function function.
6791 The generated name may need to be unique across the whole link.
6792 TYPE is some string to identify the purpose of this function to the
6793 linker or collect2; it must start with an uppercase letter,
6795 I - for constructors
6797 N - for C++ anonymous namespaces
6798 F - for DWARF unwind frame information. */
6801 get_file_function_name (const char *type
)
6807 /* If we already have a name we know to be unique, just use that. */
6808 if (first_global_object_name
)
6809 p
= first_global_object_name
;
6810 /* If the target is handling the constructors/destructors, they
6811 will be local to this file and the name is only necessary for
6812 debugging purposes. */
6813 else if ((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
6815 const char *file
= main_input_filename
;
6817 file
= input_filename
;
6818 /* Just use the file's basename, because the full pathname
6819 might be quite long. */
6820 p
= strrchr (file
, '/');
6825 p
= q
= ASTRDUP (p
);
6826 clean_symbol_name (q
);
6830 /* Otherwise, the name must be unique across the entire link.
6831 We don't have anything that we know to be unique to this translation
6832 unit, so use what we do have and throw in some randomness. */
6834 const char *name
= weak_global_object_name
;
6835 const char *file
= main_input_filename
;
6840 file
= input_filename
;
6842 len
= strlen (file
);
6843 q
= (char *) alloca (9 * 2 + len
+ 1);
6844 memcpy (q
, file
, len
+ 1);
6845 clean_symbol_name (q
);
6847 sprintf (q
+ len
, "_%08X_%08X", crc32_string (0, name
),
6848 crc32_string (0, get_random_seed (false)));
6853 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
)
6856 /* Set up the name of the file-level functions we may need.
6857 Use a global object (which is already required to be unique over
6858 the program) rather than the file name (which imposes extra
6860 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
6862 return get_identifier (buf
);
6865 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
6867 /* Complain that the tree code of NODE does not match the expected 0
6868 terminated list of trailing codes. The trailing code list can be
6869 empty, for a more vague error message. FILE, LINE, and FUNCTION
6870 are of the caller. */
6873 tree_check_failed (const_tree node
, const char *file
,
6874 int line
, const char *function
, ...)
6878 unsigned length
= 0;
6881 va_start (args
, function
);
6882 while ((code
= va_arg (args
, int)))
6883 length
+= 4 + strlen (tree_code_name
[code
]);
6888 va_start (args
, function
);
6889 length
+= strlen ("expected ");
6890 buffer
= tmp
= (char *) alloca (length
);
6892 while ((code
= va_arg (args
, int)))
6894 const char *prefix
= length
? " or " : "expected ";
6896 strcpy (tmp
+ length
, prefix
);
6897 length
+= strlen (prefix
);
6898 strcpy (tmp
+ length
, tree_code_name
[code
]);
6899 length
+= strlen (tree_code_name
[code
]);
6904 buffer
= "unexpected node";
6906 internal_error ("tree check: %s, have %s in %s, at %s:%d",
6907 buffer
, tree_code_name
[TREE_CODE (node
)],
6908 function
, trim_filename (file
), line
);
6911 /* Complain that the tree code of NODE does match the expected 0
6912 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
6916 tree_not_check_failed (const_tree node
, const char *file
,
6917 int line
, const char *function
, ...)
6921 unsigned length
= 0;
6924 va_start (args
, function
);
6925 while ((code
= va_arg (args
, int)))
6926 length
+= 4 + strlen (tree_code_name
[code
]);
6928 va_start (args
, function
);
6929 buffer
= (char *) alloca (length
);
6931 while ((code
= va_arg (args
, int)))
6935 strcpy (buffer
+ length
, " or ");
6938 strcpy (buffer
+ length
, tree_code_name
[code
]);
6939 length
+= strlen (tree_code_name
[code
]);
6943 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
6944 buffer
, tree_code_name
[TREE_CODE (node
)],
6945 function
, trim_filename (file
), line
);
6948 /* Similar to tree_check_failed, except that we check for a class of tree
6949 code, given in CL. */
6952 tree_class_check_failed (const_tree node
, const enum tree_code_class cl
,
6953 const char *file
, int line
, const char *function
)
6956 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
6957 TREE_CODE_CLASS_STRING (cl
),
6958 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
6959 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
6962 /* Similar to tree_check_failed, except that instead of specifying a
6963 dozen codes, use the knowledge that they're all sequential. */
6966 tree_range_check_failed (const_tree node
, const char *file
, int line
,
6967 const char *function
, enum tree_code c1
,
6971 unsigned length
= 0;
6974 for (c
= c1
; c
<= c2
; ++c
)
6975 length
+= 4 + strlen (tree_code_name
[c
]);
6977 length
+= strlen ("expected ");
6978 buffer
= (char *) alloca (length
);
6981 for (c
= c1
; c
<= c2
; ++c
)
6983 const char *prefix
= length
? " or " : "expected ";
6985 strcpy (buffer
+ length
, prefix
);
6986 length
+= strlen (prefix
);
6987 strcpy (buffer
+ length
, tree_code_name
[c
]);
6988 length
+= strlen (tree_code_name
[c
]);
6991 internal_error ("tree check: %s, have %s in %s, at %s:%d",
6992 buffer
, tree_code_name
[TREE_CODE (node
)],
6993 function
, trim_filename (file
), line
);
6997 /* Similar to tree_check_failed, except that we check that a tree does
6998 not have the specified code, given in CL. */
7001 tree_not_class_check_failed (const_tree node
, const enum tree_code_class cl
,
7002 const char *file
, int line
, const char *function
)
7005 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
7006 TREE_CODE_CLASS_STRING (cl
),
7007 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
7008 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
7012 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
7015 omp_clause_check_failed (const_tree node
, const char *file
, int line
,
7016 const char *function
, enum omp_clause_code code
)
7018 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
7019 omp_clause_code_name
[code
], tree_code_name
[TREE_CODE (node
)],
7020 function
, trim_filename (file
), line
);
7024 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
7027 omp_clause_range_check_failed (const_tree node
, const char *file
, int line
,
7028 const char *function
, enum omp_clause_code c1
,
7029 enum omp_clause_code c2
)
7032 unsigned length
= 0;
7033 enum omp_clause_code c
;
7035 for (c
= c1
; c
<= c2
; ++c
)
7036 length
+= 4 + strlen (omp_clause_code_name
[c
]);
7038 length
+= strlen ("expected ");
7039 buffer
= (char *) alloca (length
);
7042 for (c
= c1
; c
<= c2
; ++c
)
7044 const char *prefix
= length
? " or " : "expected ";
7046 strcpy (buffer
+ length
, prefix
);
7047 length
+= strlen (prefix
);
7048 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
7049 length
+= strlen (omp_clause_code_name
[c
]);
7052 internal_error ("tree check: %s, have %s in %s, at %s:%d",
7053 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
7054 function
, trim_filename (file
), line
);
7058 #undef DEFTREESTRUCT
7059 #define DEFTREESTRUCT(VAL, NAME) NAME,
7061 static const char *ts_enum_names
[] = {
7062 #include "treestruct.def"
7064 #undef DEFTREESTRUCT
7066 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
7068 /* Similar to tree_class_check_failed, except that we check for
7069 whether CODE contains the tree structure identified by EN. */
7072 tree_contains_struct_check_failed (const_tree node
,
7073 const enum tree_node_structure_enum en
,
7074 const char *file
, int line
,
7075 const char *function
)
7078 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
7080 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
7084 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
7085 (dynamically sized) vector. */
7088 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
7089 const char *function
)
7092 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
7093 idx
+ 1, len
, function
, trim_filename (file
), line
);
7096 /* Similar to above, except that the check is for the bounds of a PHI_NODE's
7097 (dynamically sized) vector. */
7100 phi_node_elt_check_failed (int idx
, int len
, const char *file
, int line
,
7101 const char *function
)
7104 ("tree check: accessed elt %d of phi_node with %d elts in %s, at %s:%d",
7105 idx
+ 1, len
, function
, trim_filename (file
), line
);
7108 /* Similar to above, except that the check is for the bounds of the operand
7109 vector of an expression node EXP. */
7112 tree_operand_check_failed (int idx
, const_tree exp
, const char *file
,
7113 int line
, const char *function
)
7115 int code
= TREE_CODE (exp
);
7117 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
7118 idx
+ 1, tree_code_name
[code
], TREE_OPERAND_LENGTH (exp
),
7119 function
, trim_filename (file
), line
);
7122 /* Similar to above, except that the check is for the number of
7123 operands of an OMP_CLAUSE node. */
7126 omp_clause_operand_check_failed (int idx
, const_tree t
, const char *file
,
7127 int line
, const char *function
)
7130 ("tree check: accessed operand %d of omp_clause %s with %d operands "
7131 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
7132 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
7133 trim_filename (file
), line
);
7135 #endif /* ENABLE_TREE_CHECKING */
7137 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
7138 and mapped to the machine mode MODE. Initialize its fields and build
7139 the information necessary for debugging output. */
7142 make_vector_type (tree innertype
, int nunits
, enum machine_mode mode
)
7145 hashval_t hashcode
= 0;
7147 /* Build a main variant, based on the main variant of the inner type, then
7148 use it to build the variant we return. */
7149 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
7150 && TYPE_MAIN_VARIANT (innertype
) != innertype
)
7151 return build_type_attribute_qual_variant (
7152 make_vector_type (TYPE_MAIN_VARIANT (innertype
), nunits
, mode
),
7153 TYPE_ATTRIBUTES (innertype
),
7154 TYPE_QUALS (innertype
));
7156 t
= make_node (VECTOR_TYPE
);
7157 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
7158 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
7159 TYPE_MODE (t
) = mode
;
7160 TYPE_READONLY (t
) = TYPE_READONLY (innertype
);
7161 TYPE_VOLATILE (t
) = TYPE_VOLATILE (innertype
);
7163 if (TYPE_STRUCTURAL_EQUALITY_P (innertype
))
7164 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7165 else if (TYPE_CANONICAL (innertype
) != innertype
7166 || mode
!= VOIDmode
)
7168 = make_vector_type (TYPE_CANONICAL (innertype
), nunits
, VOIDmode
);
7173 tree index
= build_int_cst (NULL_TREE
, nunits
- 1);
7174 tree array
= build_array_type (innertype
, build_index_type (index
));
7175 tree rt
= make_node (RECORD_TYPE
);
7177 TYPE_FIELDS (rt
) = build_decl (FIELD_DECL
, get_identifier ("f"), array
);
7178 DECL_CONTEXT (TYPE_FIELDS (rt
)) = rt
;
7180 TYPE_DEBUG_REPRESENTATION_TYPE (t
) = rt
;
7181 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
7182 the representation type, and we want to find that die when looking up
7183 the vector type. This is most easily achieved by making the TYPE_UID
7185 TYPE_UID (rt
) = TYPE_UID (t
);
7188 hashcode
= iterative_hash_host_wide_int (VECTOR_TYPE
, hashcode
);
7189 hashcode
= iterative_hash_host_wide_int (mode
, hashcode
);
7190 hashcode
= iterative_hash_object (TYPE_HASH (innertype
), hashcode
);
7191 return type_hash_canon (hashcode
, t
);
7195 make_or_reuse_type (unsigned size
, int unsignedp
)
7197 if (size
== INT_TYPE_SIZE
)
7198 return unsignedp
? unsigned_type_node
: integer_type_node
;
7199 if (size
== CHAR_TYPE_SIZE
)
7200 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
7201 if (size
== SHORT_TYPE_SIZE
)
7202 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
7203 if (size
== LONG_TYPE_SIZE
)
7204 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
7205 if (size
== LONG_LONG_TYPE_SIZE
)
7206 return (unsignedp
? long_long_unsigned_type_node
7207 : long_long_integer_type_node
);
7210 return make_unsigned_type (size
);
7212 return make_signed_type (size
);
7215 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
7218 make_or_reuse_fract_type (unsigned size
, int unsignedp
, int satp
)
7222 if (size
== SHORT_FRACT_TYPE_SIZE
)
7223 return unsignedp
? sat_unsigned_short_fract_type_node
7224 : sat_short_fract_type_node
;
7225 if (size
== FRACT_TYPE_SIZE
)
7226 return unsignedp
? sat_unsigned_fract_type_node
: sat_fract_type_node
;
7227 if (size
== LONG_FRACT_TYPE_SIZE
)
7228 return unsignedp
? sat_unsigned_long_fract_type_node
7229 : sat_long_fract_type_node
;
7230 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
7231 return unsignedp
? sat_unsigned_long_long_fract_type_node
7232 : sat_long_long_fract_type_node
;
7236 if (size
== SHORT_FRACT_TYPE_SIZE
)
7237 return unsignedp
? unsigned_short_fract_type_node
7238 : short_fract_type_node
;
7239 if (size
== FRACT_TYPE_SIZE
)
7240 return unsignedp
? unsigned_fract_type_node
: fract_type_node
;
7241 if (size
== LONG_FRACT_TYPE_SIZE
)
7242 return unsignedp
? unsigned_long_fract_type_node
7243 : long_fract_type_node
;
7244 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
7245 return unsignedp
? unsigned_long_long_fract_type_node
7246 : long_long_fract_type_node
;
7249 return make_fract_type (size
, unsignedp
, satp
);
7252 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
7255 make_or_reuse_accum_type (unsigned size
, int unsignedp
, int satp
)
7259 if (size
== SHORT_ACCUM_TYPE_SIZE
)
7260 return unsignedp
? sat_unsigned_short_accum_type_node
7261 : sat_short_accum_type_node
;
7262 if (size
== ACCUM_TYPE_SIZE
)
7263 return unsignedp
? sat_unsigned_accum_type_node
: sat_accum_type_node
;
7264 if (size
== LONG_ACCUM_TYPE_SIZE
)
7265 return unsignedp
? sat_unsigned_long_accum_type_node
7266 : sat_long_accum_type_node
;
7267 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
7268 return unsignedp
? sat_unsigned_long_long_accum_type_node
7269 : sat_long_long_accum_type_node
;
7273 if (size
== SHORT_ACCUM_TYPE_SIZE
)
7274 return unsignedp
? unsigned_short_accum_type_node
7275 : short_accum_type_node
;
7276 if (size
== ACCUM_TYPE_SIZE
)
7277 return unsignedp
? unsigned_accum_type_node
: accum_type_node
;
7278 if (size
== LONG_ACCUM_TYPE_SIZE
)
7279 return unsignedp
? unsigned_long_accum_type_node
7280 : long_accum_type_node
;
7281 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
7282 return unsignedp
? unsigned_long_long_accum_type_node
7283 : long_long_accum_type_node
;
7286 return make_accum_type (size
, unsignedp
, satp
);
7289 /* Create nodes for all integer types (and error_mark_node) using the sizes
7290 of C datatypes. The caller should call set_sizetype soon after calling
7291 this function to select one of the types as sizetype. */
7294 build_common_tree_nodes (bool signed_char
, bool signed_sizetype
)
7296 error_mark_node
= make_node (ERROR_MARK
);
7297 TREE_TYPE (error_mark_node
) = error_mark_node
;
7299 initialize_sizetypes (signed_sizetype
);
7301 /* Define both `signed char' and `unsigned char'. */
7302 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
7303 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
7304 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
7305 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
7307 /* Define `char', which is like either `signed char' or `unsigned char'
7308 but not the same as either. */
7311 ? make_signed_type (CHAR_TYPE_SIZE
)
7312 : make_unsigned_type (CHAR_TYPE_SIZE
));
7313 TYPE_STRING_FLAG (char_type_node
) = 1;
7315 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
7316 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
7317 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
7318 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
7319 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
7320 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
7321 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
7322 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
7324 /* Define a boolean type. This type only represents boolean values but
7325 may be larger than char depending on the value of BOOL_TYPE_SIZE.
7326 Front ends which want to override this size (i.e. Java) can redefine
7327 boolean_type_node before calling build_common_tree_nodes_2. */
7328 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
7329 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
7330 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
7331 TYPE_PRECISION (boolean_type_node
) = 1;
7333 /* Fill in the rest of the sized types. Reuse existing type nodes
7335 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
7336 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
7337 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
7338 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
7339 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
7341 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
7342 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
7343 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
7344 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
7345 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
7347 access_public_node
= get_identifier ("public");
7348 access_protected_node
= get_identifier ("protected");
7349 access_private_node
= get_identifier ("private");
7352 /* Call this function after calling build_common_tree_nodes and set_sizetype.
7353 It will create several other common tree nodes. */
7356 build_common_tree_nodes_2 (int short_double
)
7358 /* Define these next since types below may used them. */
7359 integer_zero_node
= build_int_cst (NULL_TREE
, 0);
7360 integer_one_node
= build_int_cst (NULL_TREE
, 1);
7361 integer_minus_one_node
= build_int_cst (NULL_TREE
, -1);
7363 size_zero_node
= size_int (0);
7364 size_one_node
= size_int (1);
7365 bitsize_zero_node
= bitsize_int (0);
7366 bitsize_one_node
= bitsize_int (1);
7367 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
7369 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
7370 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
7372 void_type_node
= make_node (VOID_TYPE
);
7373 layout_type (void_type_node
);
7375 /* We are not going to have real types in C with less than byte alignment,
7376 so we might as well not have any types that claim to have it. */
7377 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
7378 TYPE_USER_ALIGN (void_type_node
) = 0;
7380 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
7381 layout_type (TREE_TYPE (null_pointer_node
));
7383 ptr_type_node
= build_pointer_type (void_type_node
);
7385 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
7386 fileptr_type_node
= ptr_type_node
;
7388 float_type_node
= make_node (REAL_TYPE
);
7389 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
7390 layout_type (float_type_node
);
7392 double_type_node
= make_node (REAL_TYPE
);
7394 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
7396 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
7397 layout_type (double_type_node
);
7399 long_double_type_node
= make_node (REAL_TYPE
);
7400 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
7401 layout_type (long_double_type_node
);
7403 float_ptr_type_node
= build_pointer_type (float_type_node
);
7404 double_ptr_type_node
= build_pointer_type (double_type_node
);
7405 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
7406 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
7408 /* Fixed size integer types. */
7409 uint32_type_node
= build_nonstandard_integer_type (32, true);
7410 uint64_type_node
= build_nonstandard_integer_type (64, true);
7412 /* Decimal float types. */
7413 dfloat32_type_node
= make_node (REAL_TYPE
);
7414 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
7415 layout_type (dfloat32_type_node
);
7416 TYPE_MODE (dfloat32_type_node
) = SDmode
;
7417 dfloat32_ptr_type_node
= build_pointer_type (dfloat32_type_node
);
7419 dfloat64_type_node
= make_node (REAL_TYPE
);
7420 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
7421 layout_type (dfloat64_type_node
);
7422 TYPE_MODE (dfloat64_type_node
) = DDmode
;
7423 dfloat64_ptr_type_node
= build_pointer_type (dfloat64_type_node
);
7425 dfloat128_type_node
= make_node (REAL_TYPE
);
7426 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
7427 layout_type (dfloat128_type_node
);
7428 TYPE_MODE (dfloat128_type_node
) = TDmode
;
7429 dfloat128_ptr_type_node
= build_pointer_type (dfloat128_type_node
);
7431 complex_integer_type_node
= build_complex_type (integer_type_node
);
7432 complex_float_type_node
= build_complex_type (float_type_node
);
7433 complex_double_type_node
= build_complex_type (double_type_node
);
7434 complex_long_double_type_node
= build_complex_type (long_double_type_node
);
7436 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
7437 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
7438 sat_ ## KIND ## _type_node = \
7439 make_sat_signed_ ## KIND ## _type (SIZE); \
7440 sat_unsigned_ ## KIND ## _type_node = \
7441 make_sat_unsigned_ ## KIND ## _type (SIZE); \
7442 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
7443 unsigned_ ## KIND ## _type_node = \
7444 make_unsigned_ ## KIND ## _type (SIZE);
7446 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
7447 sat_ ## WIDTH ## KIND ## _type_node = \
7448 make_sat_signed_ ## KIND ## _type (SIZE); \
7449 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
7450 make_sat_unsigned_ ## KIND ## _type (SIZE); \
7451 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
7452 unsigned_ ## WIDTH ## KIND ## _type_node = \
7453 make_unsigned_ ## KIND ## _type (SIZE);
7455 /* Make fixed-point type nodes based on four different widths. */
7456 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
7457 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
7458 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
7459 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
7460 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
7462 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
7463 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
7464 NAME ## _type_node = \
7465 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
7466 u ## NAME ## _type_node = \
7467 make_or_reuse_unsigned_ ## KIND ## _type \
7468 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
7469 sat_ ## NAME ## _type_node = \
7470 make_or_reuse_sat_signed_ ## KIND ## _type \
7471 (GET_MODE_BITSIZE (MODE ## mode)); \
7472 sat_u ## NAME ## _type_node = \
7473 make_or_reuse_sat_unsigned_ ## KIND ## _type \
7474 (GET_MODE_BITSIZE (U ## MODE ## mode));
7476 /* Fixed-point type and mode nodes. */
7477 MAKE_FIXED_TYPE_NODE_FAMILY (fract
, FRACT
)
7478 MAKE_FIXED_TYPE_NODE_FAMILY (accum
, ACCUM
)
7479 MAKE_FIXED_MODE_NODE (fract
, qq
, QQ
)
7480 MAKE_FIXED_MODE_NODE (fract
, hq
, HQ
)
7481 MAKE_FIXED_MODE_NODE (fract
, sq
, SQ
)
7482 MAKE_FIXED_MODE_NODE (fract
, dq
, DQ
)
7483 MAKE_FIXED_MODE_NODE (fract
, tq
, TQ
)
7484 MAKE_FIXED_MODE_NODE (accum
, ha
, HA
)
7485 MAKE_FIXED_MODE_NODE (accum
, sa
, SA
)
7486 MAKE_FIXED_MODE_NODE (accum
, da
, DA
)
7487 MAKE_FIXED_MODE_NODE (accum
, ta
, TA
)
7490 tree t
= targetm
.build_builtin_va_list ();
7492 /* Many back-ends define record types without setting TYPE_NAME.
7493 If we copied the record type here, we'd keep the original
7494 record type without a name. This breaks name mangling. So,
7495 don't copy record types and let c_common_nodes_and_builtins()
7496 declare the type to be __builtin_va_list. */
7497 if (TREE_CODE (t
) != RECORD_TYPE
)
7498 t
= build_variant_type_copy (t
);
7500 va_list_type_node
= t
;
7504 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
7507 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
7508 const char *library_name
, int ecf_flags
)
7512 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
7513 library_name
, NULL_TREE
);
7514 if (ecf_flags
& ECF_CONST
)
7515 TREE_READONLY (decl
) = 1;
7516 if (ecf_flags
& ECF_PURE
)
7517 DECL_PURE_P (decl
) = 1;
7518 if (ecf_flags
& ECF_LOOPING_CONST_OR_PURE
)
7519 DECL_LOOPING_CONST_OR_PURE_P (decl
) = 1;
7520 if (ecf_flags
& ECF_NORETURN
)
7521 TREE_THIS_VOLATILE (decl
) = 1;
7522 if (ecf_flags
& ECF_NOTHROW
)
7523 TREE_NOTHROW (decl
) = 1;
7524 if (ecf_flags
& ECF_MALLOC
)
7525 DECL_IS_MALLOC (decl
) = 1;
7527 built_in_decls
[code
] = decl
;
7528 implicit_built_in_decls
[code
] = decl
;
7531 /* Call this function after instantiating all builtins that the language
7532 front end cares about. This will build the rest of the builtins that
7533 are relied upon by the tree optimizers and the middle-end. */
7536 build_common_builtin_nodes (void)
7540 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
7541 || built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
7543 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7544 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7545 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7546 ftype
= build_function_type (ptr_type_node
, tmp
);
7548 if (built_in_decls
[BUILT_IN_MEMCPY
] == NULL
)
7549 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
7550 "memcpy", ECF_NOTHROW
);
7551 if (built_in_decls
[BUILT_IN_MEMMOVE
] == NULL
)
7552 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
7553 "memmove", ECF_NOTHROW
);
7556 if (built_in_decls
[BUILT_IN_MEMCMP
] == NULL
)
7558 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7559 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7560 tmp
= tree_cons (NULL_TREE
, const_ptr_type_node
, tmp
);
7561 ftype
= build_function_type (integer_type_node
, tmp
);
7562 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
7563 "memcmp", ECF_PURE
| ECF_NOTHROW
);
7566 if (built_in_decls
[BUILT_IN_MEMSET
] == NULL
)
7568 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7569 tmp
= tree_cons (NULL_TREE
, integer_type_node
, tmp
);
7570 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7571 ftype
= build_function_type (ptr_type_node
, tmp
);
7572 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
7573 "memset", ECF_NOTHROW
);
7576 if (built_in_decls
[BUILT_IN_ALLOCA
] == NULL
)
7578 tmp
= tree_cons (NULL_TREE
, size_type_node
, void_list_node
);
7579 ftype
= build_function_type (ptr_type_node
, tmp
);
7580 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
7581 "alloca", ECF_NOTHROW
| ECF_MALLOC
);
7584 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7585 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7586 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7587 ftype
= build_function_type (void_type_node
, tmp
);
7588 local_define_builtin ("__builtin_init_trampoline", ftype
,
7589 BUILT_IN_INIT_TRAMPOLINE
,
7590 "__builtin_init_trampoline", ECF_NOTHROW
);
7592 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7593 ftype
= build_function_type (ptr_type_node
, tmp
);
7594 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
7595 BUILT_IN_ADJUST_TRAMPOLINE
,
7596 "__builtin_adjust_trampoline",
7597 ECF_CONST
| ECF_NOTHROW
);
7599 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7600 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7601 ftype
= build_function_type (void_type_node
, tmp
);
7602 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
7603 BUILT_IN_NONLOCAL_GOTO
,
7604 "__builtin_nonlocal_goto",
7605 ECF_NORETURN
| ECF_NOTHROW
);
7607 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7608 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, tmp
);
7609 ftype
= build_function_type (void_type_node
, tmp
);
7610 local_define_builtin ("__builtin_setjmp_setup", ftype
,
7611 BUILT_IN_SETJMP_SETUP
,
7612 "__builtin_setjmp_setup", ECF_NOTHROW
);
7614 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7615 ftype
= build_function_type (ptr_type_node
, tmp
);
7616 local_define_builtin ("__builtin_setjmp_dispatcher", ftype
,
7617 BUILT_IN_SETJMP_DISPATCHER
,
7618 "__builtin_setjmp_dispatcher",
7619 ECF_PURE
| ECF_NOTHROW
);
7621 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7622 ftype
= build_function_type (void_type_node
, tmp
);
7623 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
7624 BUILT_IN_SETJMP_RECEIVER
,
7625 "__builtin_setjmp_receiver", ECF_NOTHROW
);
7627 ftype
= build_function_type (ptr_type_node
, void_list_node
);
7628 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
7629 "__builtin_stack_save", ECF_NOTHROW
);
7631 tmp
= tree_cons (NULL_TREE
, ptr_type_node
, void_list_node
);
7632 ftype
= build_function_type (void_type_node
, tmp
);
7633 local_define_builtin ("__builtin_stack_restore", ftype
,
7634 BUILT_IN_STACK_RESTORE
,
7635 "__builtin_stack_restore", ECF_NOTHROW
);
7637 ftype
= build_function_type (void_type_node
, void_list_node
);
7638 local_define_builtin ("__builtin_profile_func_enter", ftype
,
7639 BUILT_IN_PROFILE_FUNC_ENTER
, "profile_func_enter", 0);
7640 local_define_builtin ("__builtin_profile_func_exit", ftype
,
7641 BUILT_IN_PROFILE_FUNC_EXIT
, "profile_func_exit", 0);
7643 /* Complex multiplication and division. These are handled as builtins
7644 rather than optabs because emit_library_call_value doesn't support
7645 complex. Further, we can do slightly better with folding these
7646 beasties if the real and complex parts of the arguments are separate. */
7648 enum machine_mode mode
;
7650 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
7652 char mode_name_buf
[4], *q
;
7654 enum built_in_function mcode
, dcode
;
7655 tree type
, inner_type
;
7657 type
= lang_hooks
.types
.type_for_mode (mode
, 0);
7660 inner_type
= TREE_TYPE (type
);
7662 tmp
= tree_cons (NULL_TREE
, inner_type
, void_list_node
);
7663 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
7664 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
7665 tmp
= tree_cons (NULL_TREE
, inner_type
, tmp
);
7666 ftype
= build_function_type (type
, tmp
);
7668 mcode
= BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
;
7669 dcode
= BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
;
7671 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
7675 built_in_names
[mcode
] = concat ("__mul", mode_name_buf
, "3", NULL
);
7676 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
7677 built_in_names
[mcode
], ECF_CONST
| ECF_NOTHROW
);
7679 built_in_names
[dcode
] = concat ("__div", mode_name_buf
, "3", NULL
);
7680 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
7681 built_in_names
[dcode
], ECF_CONST
| ECF_NOTHROW
);
7686 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
7689 If we requested a pointer to a vector, build up the pointers that
7690 we stripped off while looking for the inner type. Similarly for
7691 return values from functions.
7693 The argument TYPE is the top of the chain, and BOTTOM is the
7694 new type which we will point to. */
7697 reconstruct_complex_type (tree type
, tree bottom
)
7701 if (TREE_CODE (type
) == POINTER_TYPE
)
7703 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7704 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
7705 TYPE_REF_CAN_ALIAS_ALL (type
));
7707 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
7709 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7710 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
7711 TYPE_REF_CAN_ALIAS_ALL (type
));
7713 else if (TREE_CODE (type
) == ARRAY_TYPE
)
7715 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7716 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
7718 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
7720 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7721 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
7723 else if (TREE_CODE (type
) == METHOD_TYPE
)
7725 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7726 /* The build_method_type_directly() routine prepends 'this' to argument list,
7727 so we must compensate by getting rid of it. */
7729 = build_method_type_directly
7730 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type
))),
7732 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
7734 else if (TREE_CODE (type
) == OFFSET_TYPE
)
7736 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
7737 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
7742 return build_qualified_type (outer
, TYPE_QUALS (type
));
7745 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
7748 build_vector_type_for_mode (tree innertype
, enum machine_mode mode
)
7752 switch (GET_MODE_CLASS (mode
))
7754 case MODE_VECTOR_INT
:
7755 case MODE_VECTOR_FLOAT
:
7756 case MODE_VECTOR_FRACT
:
7757 case MODE_VECTOR_UFRACT
:
7758 case MODE_VECTOR_ACCUM
:
7759 case MODE_VECTOR_UACCUM
:
7760 nunits
= GET_MODE_NUNITS (mode
);
7764 /* Check that there are no leftover bits. */
7765 gcc_assert (GET_MODE_BITSIZE (mode
)
7766 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
7768 nunits
= GET_MODE_BITSIZE (mode
)
7769 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
7776 return make_vector_type (innertype
, nunits
, mode
);
7779 /* Similarly, but takes the inner type and number of units, which must be
7783 build_vector_type (tree innertype
, int nunits
)
7785 return make_vector_type (innertype
, nunits
, VOIDmode
);
7789 /* Build RESX_EXPR with given REGION_NUMBER. */
7791 build_resx (int region_number
)
7794 t
= build1 (RESX_EXPR
, void_type_node
,
7795 build_int_cst (NULL_TREE
, region_number
));
7799 /* Given an initializer INIT, return TRUE if INIT is zero or some
7800 aggregate of zeros. Otherwise return FALSE. */
7802 initializer_zerop (const_tree init
)
7808 switch (TREE_CODE (init
))
7811 return integer_zerop (init
);
7814 /* ??? Note that this is not correct for C4X float formats. There,
7815 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
7816 negative exponent. */
7817 return real_zerop (init
)
7818 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
7821 return fixed_zerop (init
);
7824 return integer_zerop (init
)
7825 || (real_zerop (init
)
7826 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
7827 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
7830 for (elt
= TREE_VECTOR_CST_ELTS (init
); elt
; elt
= TREE_CHAIN (elt
))
7831 if (!initializer_zerop (TREE_VALUE (elt
)))
7837 unsigned HOST_WIDE_INT idx
;
7839 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
7840 if (!initializer_zerop (elt
))
7850 /* Build an empty statement. */
7853 build_empty_stmt (void)
7855 return build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
7859 /* Build an OpenMP clause with code CODE. */
7862 build_omp_clause (enum omp_clause_code code
)
7867 length
= omp_clause_num_ops
[code
];
7868 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
7870 t
= GGC_NEWVAR (union tree_node
, size
);
7871 memset (t
, 0, size
);
7872 TREE_SET_CODE (t
, OMP_CLAUSE
);
7873 OMP_CLAUSE_SET_CODE (t
, code
);
7875 #ifdef GATHER_STATISTICS
7876 tree_node_counts
[(int) omp_clause_kind
]++;
7877 tree_node_sizes
[(int) omp_clause_kind
] += size
;
7883 /* Set various status flags when building a CALL_EXPR object T. */
7886 process_call_operands (tree t
)
7890 side_effects
= TREE_SIDE_EFFECTS (t
);
7894 n
= TREE_OPERAND_LENGTH (t
);
7895 for (i
= 1; i
< n
; i
++)
7897 tree op
= TREE_OPERAND (t
, i
);
7898 if (op
&& TREE_SIDE_EFFECTS (op
))
7909 /* Calls have side-effects, except those to const or
7911 i
= call_expr_flags (t
);
7912 if ((i
& ECF_LOOPING_CONST_OR_PURE
) || !(i
& (ECF_CONST
| ECF_PURE
)))
7915 TREE_SIDE_EFFECTS (t
) = side_effects
;
7918 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
7919 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
7920 Except for the CODE and operand count field, other storage for the
7921 object is initialized to zeros. */
7924 build_vl_exp_stat (enum tree_code code
, int len MEM_STAT_DECL
)
7927 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_exp
);
7929 gcc_assert (TREE_CODE_CLASS (code
) == tcc_vl_exp
);
7930 gcc_assert (len
>= 1);
7932 #ifdef GATHER_STATISTICS
7933 tree_node_counts
[(int) e_kind
]++;
7934 tree_node_sizes
[(int) e_kind
] += length
;
7937 t
= (tree
) ggc_alloc_zone_pass_stat (length
, &tree_zone
);
7939 memset (t
, 0, length
);
7941 TREE_SET_CODE (t
, code
);
7943 /* Can't use TREE_OPERAND to store the length because if checking is
7944 enabled, it will try to check the length before we store it. :-P */
7945 t
->exp
.operands
[0] = build_int_cst (sizetype
, len
);
7951 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE
7952 and FN and a null static chain slot. ARGLIST is a TREE_LIST of the
7956 build_call_list (tree return_type
, tree fn
, tree arglist
)
7961 t
= build_vl_exp (CALL_EXPR
, list_length (arglist
) + 3);
7962 TREE_TYPE (t
) = return_type
;
7963 CALL_EXPR_FN (t
) = fn
;
7964 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
7965 for (i
= 0; arglist
; arglist
= TREE_CHAIN (arglist
), i
++)
7966 CALL_EXPR_ARG (t
, i
) = TREE_VALUE (arglist
);
7967 process_call_operands (t
);
7971 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
7972 FN and a null static chain slot. NARGS is the number of call arguments
7973 which are specified as "..." arguments. */
7976 build_call_nary (tree return_type
, tree fn
, int nargs
, ...)
7980 va_start (args
, nargs
);
7981 ret
= build_call_valist (return_type
, fn
, nargs
, args
);
7986 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
7987 FN and a null static chain slot. NARGS is the number of call arguments
7988 which are specified as a va_list ARGS. */
7991 build_call_valist (tree return_type
, tree fn
, int nargs
, va_list args
)
7996 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
7997 TREE_TYPE (t
) = return_type
;
7998 CALL_EXPR_FN (t
) = fn
;
7999 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
8000 for (i
= 0; i
< nargs
; i
++)
8001 CALL_EXPR_ARG (t
, i
) = va_arg (args
, tree
);
8002 process_call_operands (t
);
8006 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8007 FN and a null static chain slot. NARGS is the number of call arguments
8008 which are specified as a tree array ARGS. */
8011 build_call_array (tree return_type
, tree fn
, int nargs
, tree
*args
)
8016 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
8017 TREE_TYPE (t
) = return_type
;
8018 CALL_EXPR_FN (t
) = fn
;
8019 CALL_EXPR_STATIC_CHAIN (t
) = NULL_TREE
;
8020 for (i
= 0; i
< nargs
; i
++)
8021 CALL_EXPR_ARG (t
, i
) = args
[i
];
8022 process_call_operands (t
);
8027 /* Returns true if it is possible to prove that the index of
8028 an array access REF (an ARRAY_REF expression) falls into the
8032 in_array_bounds_p (tree ref
)
8034 tree idx
= TREE_OPERAND (ref
, 1);
8037 if (TREE_CODE (idx
) != INTEGER_CST
)
8040 min
= array_ref_low_bound (ref
);
8041 max
= array_ref_up_bound (ref
);
8044 || TREE_CODE (min
) != INTEGER_CST
8045 || TREE_CODE (max
) != INTEGER_CST
)
8048 if (tree_int_cst_lt (idx
, min
)
8049 || tree_int_cst_lt (max
, idx
))
8055 /* Returns true if it is possible to prove that the range of
8056 an array access REF (an ARRAY_RANGE_REF expression) falls
8057 into the array bounds. */
8060 range_in_array_bounds_p (tree ref
)
8062 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (ref
));
8063 tree range_min
, range_max
, min
, max
;
8065 range_min
= TYPE_MIN_VALUE (domain_type
);
8066 range_max
= TYPE_MAX_VALUE (domain_type
);
8069 || TREE_CODE (range_min
) != INTEGER_CST
8070 || TREE_CODE (range_max
) != INTEGER_CST
)
8073 min
= array_ref_low_bound (ref
);
8074 max
= array_ref_up_bound (ref
);
8077 || TREE_CODE (min
) != INTEGER_CST
8078 || TREE_CODE (max
) != INTEGER_CST
)
8081 if (tree_int_cst_lt (range_min
, min
)
8082 || tree_int_cst_lt (max
, range_max
))
8088 /* Return true if T (assumed to be a DECL) must be assigned a memory
8092 needs_to_live_in_memory (const_tree t
)
8094 if (TREE_CODE (t
) == SSA_NAME
)
8095 t
= SSA_NAME_VAR (t
);
8097 return (TREE_ADDRESSABLE (t
)
8098 || is_global_var (t
)
8099 || (TREE_CODE (t
) == RESULT_DECL
8100 && aggregate_value_p (t
, current_function_decl
)));
8103 /* There are situations in which a language considers record types
8104 compatible which have different field lists. Decide if two fields
8105 are compatible. It is assumed that the parent records are compatible. */
8108 fields_compatible_p (const_tree f1
, const_tree f2
)
8110 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1
),
8111 DECL_FIELD_BIT_OFFSET (f2
), OEP_ONLY_CONST
))
8114 if (!operand_equal_p (DECL_FIELD_OFFSET (f1
),
8115 DECL_FIELD_OFFSET (f2
), OEP_ONLY_CONST
))
8118 if (!types_compatible_p (TREE_TYPE (f1
), TREE_TYPE (f2
)))
8124 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
8127 find_compatible_field (tree record
, tree orig_field
)
8131 for (f
= TYPE_FIELDS (record
); f
; f
= TREE_CHAIN (f
))
8132 if (TREE_CODE (f
) == FIELD_DECL
8133 && fields_compatible_p (f
, orig_field
))
8136 /* ??? Why isn't this on the main fields list? */
8137 f
= TYPE_VFIELD (record
);
8138 if (f
&& TREE_CODE (f
) == FIELD_DECL
8139 && fields_compatible_p (f
, orig_field
))
8142 /* ??? We should abort here, but Java appears to do Bad Things
8143 with inherited fields. */
8147 /* Return value of a constant X and sign-extend it. */
8150 int_cst_value (const_tree x
)
8152 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
8153 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
8155 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
8156 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
8157 || TREE_INT_CST_HIGH (x
) == -1);
8159 if (bits
< HOST_BITS_PER_WIDE_INT
)
8161 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
8163 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
8165 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
8171 /* If TYPE is an integral type, return an equivalent type which is
8172 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type,
8173 return TYPE itself. */
8176 signed_or_unsigned_type_for (int unsignedp
, tree type
)
8179 if (POINTER_TYPE_P (type
))
8182 if (!INTEGRAL_TYPE_P (t
) || TYPE_UNSIGNED (t
) == unsignedp
)
8185 return lang_hooks
.types
.type_for_size (TYPE_PRECISION (t
), unsignedp
);
8188 /* Returns unsigned variant of TYPE. */
8191 unsigned_type_for (tree type
)
8193 return signed_or_unsigned_type_for (1, type
);
8196 /* Returns signed variant of TYPE. */
8199 signed_type_for (tree type
)
8201 return signed_or_unsigned_type_for (0, type
);
8204 /* Returns the largest value obtainable by casting something in INNER type to
8208 upper_bound_in_type (tree outer
, tree inner
)
8210 unsigned HOST_WIDE_INT lo
, hi
;
8211 unsigned int det
= 0;
8212 unsigned oprec
= TYPE_PRECISION (outer
);
8213 unsigned iprec
= TYPE_PRECISION (inner
);
8216 /* Compute a unique number for every combination. */
8217 det
|= (oprec
> iprec
) ? 4 : 0;
8218 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
8219 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
8221 /* Determine the exponent to use. */
8226 /* oprec <= iprec, outer: signed, inner: don't care. */
8231 /* oprec <= iprec, outer: unsigned, inner: don't care. */
8235 /* oprec > iprec, outer: signed, inner: signed. */
8239 /* oprec > iprec, outer: signed, inner: unsigned. */
8243 /* oprec > iprec, outer: unsigned, inner: signed. */
8247 /* oprec > iprec, outer: unsigned, inner: unsigned. */
8254 /* Compute 2^^prec - 1. */
8255 if (prec
<= HOST_BITS_PER_WIDE_INT
)
8258 lo
= ((~(unsigned HOST_WIDE_INT
) 0)
8259 >> (HOST_BITS_PER_WIDE_INT
- prec
));
8263 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
8264 >> (2 * HOST_BITS_PER_WIDE_INT
- prec
));
8265 lo
= ~(unsigned HOST_WIDE_INT
) 0;
8268 return build_int_cst_wide (outer
, lo
, hi
);
8271 /* Returns the smallest value obtainable by casting something in INNER type to
8275 lower_bound_in_type (tree outer
, tree inner
)
8277 unsigned HOST_WIDE_INT lo
, hi
;
8278 unsigned oprec
= TYPE_PRECISION (outer
);
8279 unsigned iprec
= TYPE_PRECISION (inner
);
8281 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
8283 if (TYPE_UNSIGNED (outer
)
8284 /* If we are widening something of an unsigned type, OUTER type
8285 contains all values of INNER type. In particular, both INNER
8286 and OUTER types have zero in common. */
8287 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
8291 /* If we are widening a signed type to another signed type, we
8292 want to obtain -2^^(iprec-1). If we are keeping the
8293 precision or narrowing to a signed type, we want to obtain
8295 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
8297 if (prec
<= HOST_BITS_PER_WIDE_INT
)
8299 hi
= ~(unsigned HOST_WIDE_INT
) 0;
8300 lo
= (~(unsigned HOST_WIDE_INT
) 0) << (prec
- 1);
8304 hi
= ((~(unsigned HOST_WIDE_INT
) 0)
8305 << (prec
- HOST_BITS_PER_WIDE_INT
- 1));
8310 return build_int_cst_wide (outer
, lo
, hi
);
8313 /* Return nonzero if two operands that are suitable for PHI nodes are
8314 necessarily equal. Specifically, both ARG0 and ARG1 must be either
8315 SSA_NAME or invariant. Note that this is strictly an optimization.
8316 That is, callers of this function can directly call operand_equal_p
8317 and get the same result, only slower. */
8320 operand_equal_for_phi_arg_p (const_tree arg0
, const_tree arg1
)
8324 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
8326 return operand_equal_p (arg0
, arg1
, 0);
8329 /* Returns number of zeros at the end of binary representation of X.
8331 ??? Use ffs if available? */
8334 num_ending_zeros (const_tree x
)
8336 unsigned HOST_WIDE_INT fr
, nfr
;
8337 unsigned num
, abits
;
8338 tree type
= TREE_TYPE (x
);
8340 if (TREE_INT_CST_LOW (x
) == 0)
8342 num
= HOST_BITS_PER_WIDE_INT
;
8343 fr
= TREE_INT_CST_HIGH (x
);
8348 fr
= TREE_INT_CST_LOW (x
);
8351 for (abits
= HOST_BITS_PER_WIDE_INT
/ 2; abits
; abits
/= 2)
8354 if (nfr
<< abits
== fr
)
8361 if (num
> TYPE_PRECISION (type
))
8362 num
= TYPE_PRECISION (type
);
8364 return build_int_cst_type (type
, num
);
8368 #define WALK_SUBTREE(NODE) \
8371 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
8377 /* This is a subroutine of walk_tree that walks field of TYPE that are to
8378 be walked whenever a type is seen in the tree. Rest of operands and return
8379 value are as for walk_tree. */
8382 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
8383 struct pointer_set_t
*pset
, walk_tree_lh lh
)
8385 tree result
= NULL_TREE
;
8387 switch (TREE_CODE (type
))
8390 case REFERENCE_TYPE
:
8391 /* We have to worry about mutually recursive pointers. These can't
8392 be written in C. They can in Ada. It's pathological, but
8393 there's an ACATS test (c38102a) that checks it. Deal with this
8394 by checking if we're pointing to another pointer, that one
8395 points to another pointer, that one does too, and we have no htab.
8396 If so, get a hash table. We check three levels deep to avoid
8397 the cost of the hash table if we don't need one. */
8398 if (POINTER_TYPE_P (TREE_TYPE (type
))
8399 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
8400 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
8403 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
8411 /* ... fall through ... */
8414 WALK_SUBTREE (TREE_TYPE (type
));
8418 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
8423 WALK_SUBTREE (TREE_TYPE (type
));
8427 /* We never want to walk into default arguments. */
8428 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
8429 WALK_SUBTREE (TREE_VALUE (arg
));
8434 /* Don't follow this nodes's type if a pointer for fear that
8435 we'll have infinite recursion. If we have a PSET, then we
8438 || (!POINTER_TYPE_P (TREE_TYPE (type
))
8439 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
))
8440 WALK_SUBTREE (TREE_TYPE (type
));
8441 WALK_SUBTREE (TYPE_DOMAIN (type
));
8445 WALK_SUBTREE (TREE_TYPE (type
));
8446 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
8456 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
8457 called with the DATA and the address of each sub-tree. If FUNC returns a
8458 non-NULL value, the traversal is stopped, and the value returned by FUNC
8459 is returned. If PSET is non-NULL it is used to record the nodes visited,
8460 and to avoid visiting a node more than once. */
8463 walk_tree_1 (tree
*tp
, walk_tree_fn func
, void *data
,
8464 struct pointer_set_t
*pset
, walk_tree_lh lh
)
8466 enum tree_code code
;
8470 #define WALK_SUBTREE_TAIL(NODE) \
8474 goto tail_recurse; \
8479 /* Skip empty subtrees. */
8483 /* Don't walk the same tree twice, if the user has requested
8484 that we avoid doing so. */
8485 if (pset
&& pointer_set_insert (pset
, *tp
))
8488 /* Call the function. */
8490 result
= (*func
) (tp
, &walk_subtrees
, data
);
8492 /* If we found something, return it. */
8496 code
= TREE_CODE (*tp
);
8498 /* Even if we didn't, FUNC may have decided that there was nothing
8499 interesting below this point in the tree. */
8502 /* But we still need to check our siblings. */
8503 if (code
== TREE_LIST
)
8504 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
8505 else if (code
== OMP_CLAUSE
)
8506 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8513 result
= (*lh
) (tp
, &walk_subtrees
, func
, data
, pset
);
8514 if (result
|| !walk_subtrees
)
8521 case IDENTIFIER_NODE
:
8528 case PLACEHOLDER_EXPR
:
8532 /* None of these have subtrees other than those already walked
8537 WALK_SUBTREE (TREE_VALUE (*tp
));
8538 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
8543 int len
= TREE_VEC_LENGTH (*tp
);
8548 /* Walk all elements but the first. */
8550 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
8552 /* Now walk the first one as a tail call. */
8553 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
8557 WALK_SUBTREE (TREE_REALPART (*tp
));
8558 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
8562 unsigned HOST_WIDE_INT idx
;
8563 constructor_elt
*ce
;
8566 VEC_iterate(constructor_elt
, CONSTRUCTOR_ELTS (*tp
), idx
, ce
);
8568 WALK_SUBTREE (ce
->value
);
8573 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
8578 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= TREE_CHAIN (decl
))
8580 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
8581 into declarations that are just mentioned, rather than
8582 declared; they don't really belong to this part of the tree.
8583 And, we can see cycles: the initializer for a declaration
8584 can refer to the declaration itself. */
8585 WALK_SUBTREE (DECL_INITIAL (decl
));
8586 WALK_SUBTREE (DECL_SIZE (decl
));
8587 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
8589 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
8592 case STATEMENT_LIST
:
8594 tree_stmt_iterator i
;
8595 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
8596 WALK_SUBTREE (*tsi_stmt_ptr (i
));
8601 switch (OMP_CLAUSE_CODE (*tp
))
8603 case OMP_CLAUSE_PRIVATE
:
8604 case OMP_CLAUSE_SHARED
:
8605 case OMP_CLAUSE_FIRSTPRIVATE
:
8606 case OMP_CLAUSE_COPYIN
:
8607 case OMP_CLAUSE_COPYPRIVATE
:
8609 case OMP_CLAUSE_NUM_THREADS
:
8610 case OMP_CLAUSE_SCHEDULE
:
8611 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 0));
8614 case OMP_CLAUSE_NOWAIT
:
8615 case OMP_CLAUSE_ORDERED
:
8616 case OMP_CLAUSE_DEFAULT
:
8617 case OMP_CLAUSE_UNTIED
:
8618 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8620 case OMP_CLAUSE_LASTPRIVATE
:
8621 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
8622 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp
));
8623 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8625 case OMP_CLAUSE_COLLAPSE
:
8628 for (i
= 0; i
< 3; i
++)
8629 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
8630 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8633 case OMP_CLAUSE_REDUCTION
:
8636 for (i
= 0; i
< 4; i
++)
8637 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
8638 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
8650 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
8651 But, we only want to walk once. */
8652 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
8653 for (i
= 0; i
< len
; ++i
)
8654 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
8655 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
8659 /* If this is a TYPE_DECL, walk into the fields of the type that it's
8660 defining. We only want to walk into these fields of a type in this
8661 case and not in the general case of a mere reference to the type.
8663 The criterion is as follows: if the field can be an expression, it
8664 must be walked only here. This should be in keeping with the fields
8665 that are directly gimplified in gimplify_type_sizes in order for the
8666 mark/copy-if-shared/unmark machinery of the gimplifier to work with
8667 variable-sized types.
8669 Note that DECLs get walked as part of processing the BIND_EXPR. */
8670 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
8672 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
8673 if (TREE_CODE (*type_p
) == ERROR_MARK
)
8676 /* Call the function for the type. See if it returns anything or
8677 doesn't want us to continue. If we are to continue, walk both
8678 the normal fields and those for the declaration case. */
8679 result
= (*func
) (type_p
, &walk_subtrees
, data
);
8680 if (result
|| !walk_subtrees
)
8683 result
= walk_type_fields (*type_p
, func
, data
, pset
, lh
);
8687 /* If this is a record type, also walk the fields. */
8688 if (TREE_CODE (*type_p
) == RECORD_TYPE
8689 || TREE_CODE (*type_p
) == UNION_TYPE
8690 || TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
8694 for (field
= TYPE_FIELDS (*type_p
); field
;
8695 field
= TREE_CHAIN (field
))
8697 /* We'd like to look at the type of the field, but we can
8698 easily get infinite recursion. So assume it's pointed
8699 to elsewhere in the tree. Also, ignore things that
8701 if (TREE_CODE (field
) != FIELD_DECL
)
8704 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
8705 WALK_SUBTREE (DECL_SIZE (field
));
8706 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
8707 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
8708 WALK_SUBTREE (DECL_QUALIFIER (field
));
8712 /* Same for scalar types. */
8713 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
8714 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
8715 || TREE_CODE (*type_p
) == INTEGER_TYPE
8716 || TREE_CODE (*type_p
) == FIXED_POINT_TYPE
8717 || TREE_CODE (*type_p
) == REAL_TYPE
)
8719 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
8720 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
8723 WALK_SUBTREE (TYPE_SIZE (*type_p
));
8724 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
8729 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
))
8730 || IS_GIMPLE_STMT_CODE_CLASS (TREE_CODE_CLASS (code
)))
8734 /* Walk over all the sub-trees of this operand. */
8735 len
= TREE_OPERAND_LENGTH (*tp
);
8737 /* Go through the subtrees. We need to do this in forward order so
8738 that the scope of a FOR_EXPR is handled properly. */
8741 for (i
= 0; i
< len
- 1; ++i
)
8742 WALK_SUBTREE (GENERIC_TREE_OPERAND (*tp
, i
));
8743 WALK_SUBTREE_TAIL (GENERIC_TREE_OPERAND (*tp
, len
- 1));
8746 /* If this is a type, walk the needed fields in the type. */
8747 else if (TYPE_P (*tp
))
8748 return walk_type_fields (*tp
, func
, data
, pset
, lh
);
8752 /* We didn't find what we were looking for. */
8755 #undef WALK_SUBTREE_TAIL
8759 /* Like walk_tree, but does not walk duplicate nodes more than once. */
8762 walk_tree_without_duplicates_1 (tree
*tp
, walk_tree_fn func
, void *data
,
8766 struct pointer_set_t
*pset
;
8768 pset
= pointer_set_create ();
8769 result
= walk_tree_1 (tp
, func
, data
, pset
, lh
);
8770 pointer_set_destroy (pset
);
8775 /* Return true if STMT is an empty statement or contains nothing but
8776 empty statements. */
8779 empty_body_p (tree stmt
)
8781 tree_stmt_iterator i
;
8784 if (IS_EMPTY_STMT (stmt
))
8786 else if (TREE_CODE (stmt
) == BIND_EXPR
)
8787 body
= BIND_EXPR_BODY (stmt
);
8788 else if (TREE_CODE (stmt
) == STATEMENT_LIST
)
8793 for (i
= tsi_start (body
); !tsi_end_p (i
); tsi_next (&i
))
8794 if (!empty_body_p (tsi_stmt (i
)))
8803 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
8805 if (IS_EXPR_CODE_CLASS (c
))
8806 return &t
->exp
.block
;
8807 else if (IS_GIMPLE_STMT_CODE_CLASS (c
))
8808 return &GIMPLE_STMT_BLOCK (t
);
8814 generic_tree_operand (tree node
, int i
)
8816 if (GIMPLE_STMT_P (node
))
8817 return &GIMPLE_STMT_OPERAND (node
, i
);
8818 return &TREE_OPERAND (node
, i
);
8822 generic_tree_type (tree node
)
8824 if (GIMPLE_STMT_P (node
))
8825 return &void_type_node
;
8826 return &TREE_TYPE (node
);
8829 /* Build and return a TREE_LIST of arguments in the CALL_EXPR exp.
8830 FIXME: don't use this function. It exists for compatibility with
8831 the old representation of CALL_EXPRs where a list was used to hold the
8832 arguments. Places that currently extract the arglist from a CALL_EXPR
8833 ought to be rewritten to use the CALL_EXPR itself. */
8835 call_expr_arglist (tree exp
)
8837 tree arglist
= NULL_TREE
;
8839 for (i
= call_expr_nargs (exp
) - 1; i
>= 0; i
--)
8840 arglist
= tree_cons (NULL_TREE
, CALL_EXPR_ARG (exp
, i
), arglist
);
8844 /* Return true if TYPE has a variable argument list. */
8847 stdarg_p (tree fntype
)
8849 function_args_iterator args_iter
;
8850 tree n
= NULL_TREE
, t
;
8855 FOREACH_FUNCTION_ARGS(fntype
, t
, args_iter
)
8860 return n
!= NULL_TREE
&& n
!= void_type_node
;
8863 /* Return true if TYPE has a prototype. */
8866 prototype_p (tree fntype
)
8870 gcc_assert (fntype
!= NULL_TREE
);
8872 t
= TYPE_ARG_TYPES (fntype
);
8873 return (t
!= NULL_TREE
);
8876 /* Return the number of arguments that a function has. */
8879 function_args_count (tree fntype
)
8881 function_args_iterator args_iter
;
8887 FOREACH_FUNCTION_ARGS(fntype
, t
, args_iter
)
8896 /* If BLOCK is inlined from an __attribute__((__artificial__))
8897 routine, return pointer to location from where it has been
8900 block_nonartificial_location (tree block
)
8902 location_t
*ret
= NULL
;
8904 while (block
&& TREE_CODE (block
) == BLOCK
8905 && BLOCK_ABSTRACT_ORIGIN (block
))
8907 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
8909 while (TREE_CODE (ao
) == BLOCK
&& BLOCK_ABSTRACT_ORIGIN (ao
))
8910 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
8912 if (TREE_CODE (ao
) == FUNCTION_DECL
)
8914 /* If AO is an artificial inline, point RET to the
8915 call site locus at which it has been inlined and continue
8916 the loop, in case AO's caller is also an artificial
8918 if (DECL_DECLARED_INLINE_P (ao
)
8919 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao
)))
8920 ret
= &BLOCK_SOURCE_LOCATION (block
);
8924 else if (TREE_CODE (ao
) != BLOCK
)
8927 block
= BLOCK_SUPERCONTEXT (block
);
8932 #include "gt-tree.h"