1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This file contains the low level primitives for operating on tree nodes,
23 including allocation, list operations, interning of identifiers,
24 construction of data type nodes and statement nodes,
25 and construction of type conversion nodes. It also contains
26 tables index by tree code that describe how to take apart
29 It is intended to be language-independent, but occasionally
30 calls language-dependent routines defined (for C) in typecheck.c. */
34 #include "coretypes.h"
47 #include "langhooks.h"
48 #include "tree-iterator.h"
49 #include "basic-block.h"
50 #include "tree-flow.h"
52 #include "pointer-set.h"
53 #include "fixed-value.h"
55 /* Tree code classes. */
57 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
58 #define END_OF_BASE_TREE_CODES tcc_exceptional,
60 const enum tree_code_class tree_code_type[] = {
61 #include "all-tree.def"
65 #undef END_OF_BASE_TREE_CODES
67 /* Table indexed by tree code giving number of expression
68 operands beyond the fixed part of the node structure.
69 Not used for types or decls. */
71 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
72 #define END_OF_BASE_TREE_CODES 0,
74 const unsigned char tree_code_length[] = {
75 #include "all-tree.def"
79 #undef END_OF_BASE_TREE_CODES
81 /* Names of tree components.
82 Used for printing out the tree and error messages. */
83 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
84 #define END_OF_BASE_TREE_CODES "@dummy",
86 const char *const tree_code_name[] = {
87 #include "all-tree.def"
91 #undef END_OF_BASE_TREE_CODES
93 /* Each tree code class has an associated string representation.
94 These must correspond to the tree_code_class entries. */
96 const char *const tree_code_class_strings[] =
111 /* obstack.[ch] explicitly declined to prototype this. */
112 extern int _obstack_allocated_p (struct obstack *h, void *obj);
114 #ifdef GATHER_STATISTICS
115 /* Statistics-gathering stuff. */
117 int tree_node_counts[(int) all_kinds];
118 int tree_node_sizes[(int) all_kinds];
120 /* Keep in sync with tree.h:enum tree_node_kind. */
121 static const char * const tree_node_kind_names[] = {
141 #endif /* GATHER_STATISTICS */
143 /* Unique id for next decl created. */
144 static GTY(()) int next_decl_uid;
145 /* Unique id for next type created. */
146 static GTY(()) int next_type_uid = 1;
148 /* Since we cannot rehash a type after it is in the table, we have to
149 keep the hash code. */
151 struct type_hash GTY(())
157 /* Initial size of the hash table (rounded to next prime). */
158 #define TYPE_HASH_INITIAL_SIZE 1000
160 /* Now here is the hash table. When recording a type, it is added to
161 the slot whose index is the hash code. Note that the hash table is
162 used for several kinds of types (function types, array types and
163 array index range types, for now). While all these live in the
164 same table, they are completely independent, and the hash code is
165 computed differently for each of these. */
167 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
168 htab_t type_hash_table;
170 /* Hash table and temporary node for larger integer const values. */
171 static GTY (()) tree int_cst_node;
172 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
173 htab_t int_cst_hash_table;
175 /* Hash table for optimization flags and target option flags. Use the same
176 hash table for both sets of options. Nodes for building the current
177 optimization and target option nodes. The assumption is most of the time
178 the options created will already be in the hash table, so we avoid
179 allocating and freeing up a node repeatably. */
180 static GTY (()) tree cl_optimization_node;
181 static GTY (()) tree cl_target_option_node;
182 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
183 htab_t cl_option_hash_table;
185 /* General tree->tree mapping structure for use in hash tables. */
188 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
189 htab_t debug_expr_for_decl;
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
192 htab_t value_expr_for_decl;
194 static GTY ((if_marked ("tree_priority_map_marked_p"),
195 param_is (struct tree_priority_map)))
196 htab_t init_priority_for_decl;
198 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
199 htab_t restrict_base_for_decl;
201 static void set_type_quals (tree, int);
202 static int type_hash_eq (const void *, const void *);
203 static hashval_t type_hash_hash (const void *);
204 static hashval_t int_cst_hash_hash (const void *);
205 static int int_cst_hash_eq (const void *, const void *);
206 static hashval_t cl_option_hash_hash (const void *);
207 static int cl_option_hash_eq (const void *, const void *);
208 static void print_type_hash_statistics (void);
209 static void print_debug_expr_statistics (void);
210 static void print_value_expr_statistics (void);
211 static int type_hash_marked_p (const void *);
212 static unsigned int type_hash_list (const_tree, hashval_t);
213 static unsigned int attribute_hash_list (const_tree, hashval_t);
215 tree global_trees[TI_MAX];
216 tree integer_types[itk_none];
218 unsigned char tree_contains_struct[MAX_TREE_CODES][64];
220 /* Number of operands for each OpenMP clause. */
221 unsigned const char omp_clause_num_ops[] =
223 0, /* OMP_CLAUSE_ERROR */
224 1, /* OMP_CLAUSE_PRIVATE */
225 1, /* OMP_CLAUSE_SHARED */
226 1, /* OMP_CLAUSE_FIRSTPRIVATE */
227 2, /* OMP_CLAUSE_LASTPRIVATE */
228 4, /* OMP_CLAUSE_REDUCTION */
229 1, /* OMP_CLAUSE_COPYIN */
230 1, /* OMP_CLAUSE_COPYPRIVATE */
231 1, /* OMP_CLAUSE_IF */
232 1, /* OMP_CLAUSE_NUM_THREADS */
233 1, /* OMP_CLAUSE_SCHEDULE */
234 0, /* OMP_CLAUSE_NOWAIT */
235 0, /* OMP_CLAUSE_ORDERED */
236 0, /* OMP_CLAUSE_DEFAULT */
237 3, /* OMP_CLAUSE_COLLAPSE */
238 0 /* OMP_CLAUSE_UNTIED */
241 const char * const omp_clause_code_name[] =
266 /* Initialize the hash table of types. */
267 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
270 debug_expr_for_decl = htab_create_ggc (512, tree_map_hash,
273 value_expr_for_decl = htab_create_ggc (512, tree_map_hash,
275 init_priority_for_decl = htab_create_ggc (512, tree_priority_map_hash,
276 tree_priority_map_eq, 0);
277 restrict_base_for_decl = htab_create_ggc (256, tree_map_hash,
280 int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash,
281 int_cst_hash_eq, NULL);
283 int_cst_node = make_node (INTEGER_CST);
285 cl_option_hash_table = htab_create_ggc (64, cl_option_hash_hash,
286 cl_option_hash_eq, NULL);
288 cl_optimization_node = make_node (OPTIMIZATION_NODE);
289 cl_target_option_node = make_node (TARGET_OPTION_NODE);
291 tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON] = 1;
292 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_NON_COMMON] = 1;
293 tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON] = 1;
296 tree_contains_struct[CONST_DECL][TS_DECL_COMMON] = 1;
297 tree_contains_struct[VAR_DECL][TS_DECL_COMMON] = 1;
298 tree_contains_struct[PARM_DECL][TS_DECL_COMMON] = 1;
299 tree_contains_struct[RESULT_DECL][TS_DECL_COMMON] = 1;
300 tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON] = 1;
301 tree_contains_struct[TYPE_DECL][TS_DECL_COMMON] = 1;
302 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON] = 1;
303 tree_contains_struct[LABEL_DECL][TS_DECL_COMMON] = 1;
304 tree_contains_struct[FIELD_DECL][TS_DECL_COMMON] = 1;
307 tree_contains_struct[CONST_DECL][TS_DECL_WRTL] = 1;
308 tree_contains_struct[VAR_DECL][TS_DECL_WRTL] = 1;
309 tree_contains_struct[PARM_DECL][TS_DECL_WRTL] = 1;
310 tree_contains_struct[RESULT_DECL][TS_DECL_WRTL] = 1;
311 tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL] = 1;
312 tree_contains_struct[LABEL_DECL][TS_DECL_WRTL] = 1;
314 tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL] = 1;
315 tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL] = 1;
316 tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL] = 1;
317 tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL] = 1;
318 tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL] = 1;
319 tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL] = 1;
320 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL] = 1;
321 tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL] = 1;
322 tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL] = 1;
324 tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS] = 1;
325 tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS] = 1;
326 tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS] = 1;
327 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_WITH_VIS] = 1;
329 tree_contains_struct[VAR_DECL][TS_VAR_DECL] = 1;
330 tree_contains_struct[FIELD_DECL][TS_FIELD_DECL] = 1;
331 tree_contains_struct[PARM_DECL][TS_PARM_DECL] = 1;
332 tree_contains_struct[LABEL_DECL][TS_LABEL_DECL] = 1;
333 tree_contains_struct[RESULT_DECL][TS_RESULT_DECL] = 1;
334 tree_contains_struct[CONST_DECL][TS_CONST_DECL] = 1;
335 tree_contains_struct[TYPE_DECL][TS_TYPE_DECL] = 1;
336 tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL] = 1;
337 tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL] = 1;
338 tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON] = 1;
340 lang_hooks.init_ts ();
344 /* The name of the object as the assembler will see it (but before any
345 translations made by ASM_OUTPUT_LABELREF). Often this is the same
346 as DECL_NAME. It is an IDENTIFIER_NODE. */
348 decl_assembler_name (tree decl)
350 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
351 lang_hooks.set_decl_assembler_name (decl);
352 return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name;
355 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
358 decl_assembler_name_equal (tree decl, const_tree asmname)
360 tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
361 const char *decl_str;
362 const char *asmname_str;
365 if (decl_asmname == asmname)
368 decl_str = IDENTIFIER_POINTER (decl_asmname);
369 asmname_str = IDENTIFIER_POINTER (asmname);
372 /* If the target assembler name was set by the user, things are trickier.
373 We have a leading '*' to begin with. After that, it's arguable what
374 is the correct thing to do with -fleading-underscore. Arguably, we've
375 historically been doing the wrong thing in assemble_alias by always
376 printing the leading underscore. Since we're not changing that, make
377 sure user_label_prefix follows the '*' before matching. */
378 if (decl_str[0] == '*')
380 size_t ulp_len = strlen (user_label_prefix);
386 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
387 decl_str += ulp_len, test=true;
391 if (asmname_str[0] == '*')
393 size_t ulp_len = strlen (user_label_prefix);
399 else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0)
400 asmname_str += ulp_len, test=true;
407 return strcmp (decl_str, asmname_str) == 0;
410 /* Hash asmnames ignoring the user specified marks. */
413 decl_assembler_name_hash (const_tree asmname)
415 if (IDENTIFIER_POINTER (asmname)[0] == '*')
417 const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
418 size_t ulp_len = strlen (user_label_prefix);
422 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
425 return htab_hash_string (decl_str);
428 return htab_hash_string (IDENTIFIER_POINTER (asmname));
431 /* Compute the number of bytes occupied by a tree with code CODE.
432 This function cannot be used for nodes that have variable sizes,
433 including TREE_VEC, STRING_CST, and CALL_EXPR. */
435 tree_code_size (enum tree_code code)
437 switch (TREE_CODE_CLASS (code))
439 case tcc_declaration: /* A decl node */
444 return sizeof (struct tree_field_decl);
446 return sizeof (struct tree_parm_decl);
448 return sizeof (struct tree_var_decl);
450 return sizeof (struct tree_label_decl);
452 return sizeof (struct tree_result_decl);
454 return sizeof (struct tree_const_decl);
456 return sizeof (struct tree_type_decl);
458 return sizeof (struct tree_function_decl);
460 return sizeof (struct tree_decl_non_common);
464 case tcc_type: /* a type node */
465 return sizeof (struct tree_type);
467 case tcc_reference: /* a reference */
468 case tcc_expression: /* an expression */
469 case tcc_statement: /* an expression with side effects */
470 case tcc_comparison: /* a comparison expression */
471 case tcc_unary: /* a unary arithmetic expression */
472 case tcc_binary: /* a binary arithmetic expression */
473 return (sizeof (struct tree_exp)
474 + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
476 case tcc_constant: /* a constant */
479 case INTEGER_CST: return sizeof (struct tree_int_cst);
480 case REAL_CST: return sizeof (struct tree_real_cst);
481 case FIXED_CST: return sizeof (struct tree_fixed_cst);
482 case COMPLEX_CST: return sizeof (struct tree_complex);
483 case VECTOR_CST: return sizeof (struct tree_vector);
484 case STRING_CST: gcc_unreachable ();
486 return lang_hooks.tree_size (code);
489 case tcc_exceptional: /* something random, like an identifier. */
492 case IDENTIFIER_NODE: return lang_hooks.identifier_size;
493 case TREE_LIST: return sizeof (struct tree_list);
496 case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
499 case OMP_CLAUSE: gcc_unreachable ();
501 case SSA_NAME: return sizeof (struct tree_ssa_name);
503 case STATEMENT_LIST: return sizeof (struct tree_statement_list);
504 case BLOCK: return sizeof (struct tree_block);
505 case CONSTRUCTOR: return sizeof (struct tree_constructor);
506 case OPTIMIZATION_NODE: return sizeof (struct tree_optimization_option);
507 case TARGET_OPTION_NODE: return sizeof (struct tree_target_option);
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 (offsetof (struct tree_binfo, base_binfos)
528 + VEC_embedded_size (tree, BINFO_N_BASE_BINFOS (node)));
531 return (sizeof (struct tree_vec)
532 + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
535 return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
538 return (sizeof (struct tree_omp_clause)
539 + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
543 if (TREE_CODE_CLASS (code) == tcc_vl_exp)
544 return (sizeof (struct tree_exp)
545 + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
547 return tree_code_size (code);
551 /* Return a newly allocated node of code CODE. For decl and type
552 nodes, some other fields are initialized. The rest of the node is
553 initialized to zero. This function cannot be used for TREE_VEC or
554 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size.
556 Achoo! I got a code in the node. */
559 make_node_stat (enum tree_code code MEM_STAT_DECL)
562 enum tree_code_class type = TREE_CODE_CLASS (code);
563 size_t length = tree_code_size (code);
564 #ifdef GATHER_STATISTICS
569 case tcc_declaration: /* A decl node */
573 case tcc_type: /* a type node */
577 case tcc_statement: /* an expression with side effects */
581 case tcc_reference: /* a reference */
585 case tcc_expression: /* an expression */
586 case tcc_comparison: /* a comparison expression */
587 case tcc_unary: /* a unary arithmetic expression */
588 case tcc_binary: /* a binary arithmetic expression */
592 case tcc_constant: /* a constant */
596 case tcc_exceptional: /* something random, like an identifier. */
599 case IDENTIFIER_NODE:
612 kind = ssa_name_kind;
633 tree_node_counts[(int) kind]++;
634 tree_node_sizes[(int) kind] += length;
637 if (code == IDENTIFIER_NODE)
638 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_id_zone);
640 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
642 memset (t, 0, length);
644 TREE_SET_CODE (t, code);
649 TREE_SIDE_EFFECTS (t) = 1;
652 case tcc_declaration:
653 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
655 if (code == FUNCTION_DECL)
657 DECL_ALIGN (t) = FUNCTION_BOUNDARY;
658 DECL_MODE (t) = FUNCTION_MODE;
662 /* We have not yet computed the alias set for this declaration. */
663 DECL_POINTER_ALIAS_SET (t) = -1;
665 DECL_SOURCE_LOCATION (t) = input_location;
666 DECL_UID (t) = next_decl_uid++;
671 TYPE_UID (t) = next_type_uid++;
672 TYPE_ALIGN (t) = BITS_PER_UNIT;
673 TYPE_USER_ALIGN (t) = 0;
674 TYPE_MAIN_VARIANT (t) = t;
675 TYPE_CANONICAL (t) = t;
677 /* Default to no attributes for type, but let target change that. */
678 TYPE_ATTRIBUTES (t) = NULL_TREE;
679 targetm.set_default_type_attributes (t);
681 /* We have not yet computed the alias set for this type. */
682 TYPE_ALIAS_SET (t) = -1;
686 TREE_CONSTANT (t) = 1;
695 case PREDECREMENT_EXPR:
696 case PREINCREMENT_EXPR:
697 case POSTDECREMENT_EXPR:
698 case POSTINCREMENT_EXPR:
699 /* All of these have side-effects, no matter what their
701 TREE_SIDE_EFFECTS (t) = 1;
710 /* Other classes need no special treatment. */
717 /* Return a new node with the same contents as NODE except that its
718 TREE_CHAIN is zero and it has a fresh uid. */
721 copy_node_stat (tree node MEM_STAT_DECL)
724 enum tree_code code = TREE_CODE (node);
727 gcc_assert (code != STATEMENT_LIST);
729 length = tree_size (node);
730 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
731 memcpy (t, node, length);
734 TREE_ASM_WRITTEN (t) = 0;
735 TREE_VISITED (t) = 0;
738 if (TREE_CODE_CLASS (code) == tcc_declaration)
740 DECL_UID (t) = next_decl_uid++;
741 if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL)
742 && DECL_HAS_VALUE_EXPR_P (node))
744 SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
745 DECL_HAS_VALUE_EXPR_P (t) = 1;
747 if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node))
749 SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
750 DECL_HAS_INIT_PRIORITY_P (t) = 1;
752 if (TREE_CODE (node) == VAR_DECL && DECL_BASED_ON_RESTRICT_P (node))
754 SET_DECL_RESTRICT_BASE (t, DECL_GET_RESTRICT_BASE (node));
755 DECL_BASED_ON_RESTRICT_P (t) = 1;
758 else if (TREE_CODE_CLASS (code) == tcc_type)
760 TYPE_UID (t) = next_type_uid++;
761 /* The following is so that the debug code for
762 the copy is different from the original type.
763 The two statements usually duplicate each other
764 (because they clear fields of the same union),
765 but the optimizer should catch that. */
766 TYPE_SYMTAB_POINTER (t) = 0;
767 TYPE_SYMTAB_ADDRESS (t) = 0;
769 /* Do not copy the values cache. */
770 if (TYPE_CACHED_VALUES_P(t))
772 TYPE_CACHED_VALUES_P (t) = 0;
773 TYPE_CACHED_VALUES (t) = NULL_TREE;
780 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
781 For example, this can copy a list made of TREE_LIST nodes. */
784 copy_list (tree list)
792 head = prev = copy_node (list);
793 next = TREE_CHAIN (list);
796 TREE_CHAIN (prev) = copy_node (next);
797 prev = TREE_CHAIN (prev);
798 next = TREE_CHAIN (next);
804 /* Create an INT_CST node with a LOW value sign extended. */
807 build_int_cst (tree type, HOST_WIDE_INT low)
809 /* Support legacy code. */
811 type = integer_type_node;
813 return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
816 /* Create an INT_CST node with a LOW value zero extended. */
819 build_int_cstu (tree type, unsigned HOST_WIDE_INT low)
821 return build_int_cst_wide (type, low, 0);
824 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
825 if it is negative. This function is similar to build_int_cst, but
826 the extra bits outside of the type precision are cleared. Constants
827 with these extra bits may confuse the fold so that it detects overflows
828 even in cases when they do not occur, and in general should be avoided.
829 We cannot however make this a default behavior of build_int_cst without
830 more intrusive changes, since there are parts of gcc that rely on the extra
831 precision of the integer constants. */
834 build_int_cst_type (tree type, HOST_WIDE_INT low)
836 unsigned HOST_WIDE_INT low1;
841 fit_double_type (low, low < 0 ? -1 : 0, &low1, &hi, type);
843 return build_int_cst_wide (type, low1, hi);
846 /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated
847 and sign extended according to the value range of TYPE. */
850 build_int_cst_wide_type (tree type,
851 unsigned HOST_WIDE_INT low, HOST_WIDE_INT high)
853 fit_double_type (low, high, &low, &high, type);
854 return build_int_cst_wide (type, low, high);
857 /* These are the hash table functions for the hash table of INTEGER_CST
858 nodes of a sizetype. */
860 /* Return the hash code code X, an INTEGER_CST. */
863 int_cst_hash_hash (const void *x)
865 const_tree const t = (const_tree) x;
867 return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t)
868 ^ htab_hash_pointer (TREE_TYPE (t)));
871 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
872 is the same as that given by *Y, which is the same. */
875 int_cst_hash_eq (const void *x, const void *y)
877 const_tree const xt = (const_tree) x;
878 const_tree const yt = (const_tree) y;
880 return (TREE_TYPE (xt) == TREE_TYPE (yt)
881 && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt)
882 && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt));
885 /* Create an INT_CST node of TYPE and value HI:LOW.
886 The returned node is always shared. For small integers we use a
887 per-type vector cache, for larger ones we use a single hash table. */
890 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
898 switch (TREE_CODE (type))
902 /* Cache NULL pointer. */
911 /* Cache false or true. */
919 if (TYPE_UNSIGNED (type))
922 limit = INTEGER_SHARE_LIMIT;
923 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
929 limit = INTEGER_SHARE_LIMIT + 1;
930 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
932 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
946 /* Look for it in the type's vector of small shared ints. */
947 if (!TYPE_CACHED_VALUES_P (type))
949 TYPE_CACHED_VALUES_P (type) = 1;
950 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
953 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
956 /* Make sure no one is clobbering the shared constant. */
957 gcc_assert (TREE_TYPE (t) == type);
958 gcc_assert (TREE_INT_CST_LOW (t) == low);
959 gcc_assert (TREE_INT_CST_HIGH (t) == hi);
963 /* Create a new shared int. */
964 t = make_node (INTEGER_CST);
966 TREE_INT_CST_LOW (t) = low;
967 TREE_INT_CST_HIGH (t) = hi;
968 TREE_TYPE (t) = type;
970 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
975 /* Use the cache of larger shared ints. */
978 TREE_INT_CST_LOW (int_cst_node) = low;
979 TREE_INT_CST_HIGH (int_cst_node) = hi;
980 TREE_TYPE (int_cst_node) = type;
982 slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT);
986 /* Insert this one into the hash table. */
989 /* Make a new node for next time round. */
990 int_cst_node = make_node (INTEGER_CST);
997 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
998 and the rest are zeros. */
1001 build_low_bits_mask (tree type, unsigned bits)
1003 unsigned HOST_WIDE_INT low;
1005 unsigned HOST_WIDE_INT all_ones = ~(unsigned HOST_WIDE_INT) 0;
1007 gcc_assert (bits <= TYPE_PRECISION (type));
1009 if (bits == TYPE_PRECISION (type)
1010 && !TYPE_UNSIGNED (type))
1012 /* Sign extended all-ones mask. */
1016 else if (bits <= HOST_BITS_PER_WIDE_INT)
1018 low = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
1023 bits -= HOST_BITS_PER_WIDE_INT;
1025 high = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
1028 return build_int_cst_wide (type, low, high);
1031 /* Checks that X is integer constant that can be expressed in (unsigned)
1032 HOST_WIDE_INT without loss of precision. */
1035 cst_and_fits_in_hwi (const_tree x)
1037 if (TREE_CODE (x) != INTEGER_CST)
1040 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT)
1043 return (TREE_INT_CST_HIGH (x) == 0
1044 || TREE_INT_CST_HIGH (x) == -1);
1047 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1048 are in a list pointed to by VALS. */
1051 build_vector (tree type, tree vals)
1053 tree v = make_node (VECTOR_CST);
1057 TREE_VECTOR_CST_ELTS (v) = vals;
1058 TREE_TYPE (v) = type;
1060 /* Iterate through elements and check for overflow. */
1061 for (link = vals; link; link = TREE_CHAIN (link))
1063 tree value = TREE_VALUE (link);
1065 /* Don't crash if we get an address constant. */
1066 if (!CONSTANT_CLASS_P (value))
1069 over |= TREE_OVERFLOW (value);
1072 TREE_OVERFLOW (v) = over;
1076 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1077 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1080 build_vector_from_ctor (tree type, VEC(constructor_elt,gc) *v)
1082 tree list = NULL_TREE;
1083 unsigned HOST_WIDE_INT idx;
1086 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
1087 list = tree_cons (NULL_TREE, value, list);
1088 return build_vector (type, nreverse (list));
1091 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1092 are in the VEC pointed to by VALS. */
1094 build_constructor (tree type, VEC(constructor_elt,gc) *vals)
1096 tree c = make_node (CONSTRUCTOR);
1097 TREE_TYPE (c) = type;
1098 CONSTRUCTOR_ELTS (c) = vals;
1102 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1105 build_constructor_single (tree type, tree index, tree value)
1107 VEC(constructor_elt,gc) *v;
1108 constructor_elt *elt;
1111 v = VEC_alloc (constructor_elt, gc, 1);
1112 elt = VEC_quick_push (constructor_elt, v, NULL);
1116 t = build_constructor (type, v);
1117 TREE_CONSTANT (t) = TREE_CONSTANT (value);
1122 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1123 are in a list pointed to by VALS. */
1125 build_constructor_from_list (tree type, tree vals)
1128 VEC(constructor_elt,gc) *v = NULL;
1129 bool constant_p = true;
1133 v = VEC_alloc (constructor_elt, gc, list_length (vals));
1134 for (t = vals; t; t = TREE_CHAIN (t))
1136 constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL);
1137 val = TREE_VALUE (t);
1138 elt->index = TREE_PURPOSE (t);
1140 if (!TREE_CONSTANT (val))
1145 t = build_constructor (type, v);
1146 TREE_CONSTANT (t) = constant_p;
1150 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1153 build_fixed (tree type, FIXED_VALUE_TYPE f)
1156 FIXED_VALUE_TYPE *fp;
1158 v = make_node (FIXED_CST);
1159 fp = GGC_NEW (FIXED_VALUE_TYPE);
1160 memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
1162 TREE_TYPE (v) = type;
1163 TREE_FIXED_CST_PTR (v) = fp;
1167 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1170 build_real (tree type, REAL_VALUE_TYPE d)
1173 REAL_VALUE_TYPE *dp;
1176 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1177 Consider doing it via real_convert now. */
1179 v = make_node (REAL_CST);
1180 dp = GGC_NEW (REAL_VALUE_TYPE);
1181 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
1183 TREE_TYPE (v) = type;
1184 TREE_REAL_CST_PTR (v) = dp;
1185 TREE_OVERFLOW (v) = overflow;
1189 /* Return a new REAL_CST node whose type is TYPE
1190 and whose value is the integer value of the INTEGER_CST node I. */
1193 real_value_from_int_cst (const_tree type, const_tree i)
1197 /* Clear all bits of the real value type so that we can later do
1198 bitwise comparisons to see if two values are the same. */
1199 memset (&d, 0, sizeof d);
1201 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
1202 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
1203 TYPE_UNSIGNED (TREE_TYPE (i)));
1207 /* Given a tree representing an integer constant I, return a tree
1208 representing the same value as a floating-point constant of type TYPE. */
1211 build_real_from_int_cst (tree type, const_tree i)
1214 int overflow = TREE_OVERFLOW (i);
1216 v = build_real (type, real_value_from_int_cst (type, i));
1218 TREE_OVERFLOW (v) |= overflow;
1222 /* Return a newly constructed STRING_CST node whose value is
1223 the LEN characters at STR.
1224 The TREE_TYPE is not initialized. */
1227 build_string (int len, const char *str)
1232 /* Do not waste bytes provided by padding of struct tree_string. */
1233 length = len + offsetof (struct tree_string, str) + 1;
1235 #ifdef GATHER_STATISTICS
1236 tree_node_counts[(int) c_kind]++;
1237 tree_node_sizes[(int) c_kind] += length;
1240 s = ggc_alloc_tree (length);
1242 memset (s, 0, sizeof (struct tree_common));
1243 TREE_SET_CODE (s, STRING_CST);
1244 TREE_CONSTANT (s) = 1;
1245 TREE_STRING_LENGTH (s) = len;
1246 memcpy (s->string.str, str, len);
1247 s->string.str[len] = '\0';
1252 /* Return a newly constructed COMPLEX_CST node whose value is
1253 specified by the real and imaginary parts REAL and IMAG.
1254 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1255 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1258 build_complex (tree type, tree real, tree imag)
1260 tree t = make_node (COMPLEX_CST);
1262 TREE_REALPART (t) = real;
1263 TREE_IMAGPART (t) = imag;
1264 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
1265 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
1269 /* Return a constant of arithmetic type TYPE which is the
1270 multiplicative identity of the set TYPE. */
1273 build_one_cst (tree type)
1275 switch (TREE_CODE (type))
1277 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
1278 case POINTER_TYPE: case REFERENCE_TYPE:
1280 return build_int_cst (type, 1);
1283 return build_real (type, dconst1);
1285 case FIXED_POINT_TYPE:
1286 /* We can only generate 1 for accum types. */
1287 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
1288 return build_fixed (type, FCONST1(TYPE_MODE (type)));
1295 scalar = build_one_cst (TREE_TYPE (type));
1297 /* Create 'vect_cst_ = {cst,cst,...,cst}' */
1299 for (i = TYPE_VECTOR_SUBPARTS (type); --i >= 0; )
1300 cst = tree_cons (NULL_TREE, scalar, cst);
1302 return build_vector (type, cst);
1306 return build_complex (type,
1307 build_one_cst (TREE_TYPE (type)),
1308 fold_convert (TREE_TYPE (type), integer_zero_node));
1315 /* Build a BINFO with LEN language slots. */
1318 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
1321 size_t length = (offsetof (struct tree_binfo, base_binfos)
1322 + VEC_embedded_size (tree, base_binfos));
1324 #ifdef GATHER_STATISTICS
1325 tree_node_counts[(int) binfo_kind]++;
1326 tree_node_sizes[(int) binfo_kind] += length;
1329 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
1331 memset (t, 0, offsetof (struct tree_binfo, base_binfos));
1333 TREE_SET_CODE (t, TREE_BINFO);
1335 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos);
1341 /* Build a newly constructed TREE_VEC node of length LEN. */
1344 make_tree_vec_stat (int len MEM_STAT_DECL)
1347 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
1349 #ifdef GATHER_STATISTICS
1350 tree_node_counts[(int) vec_kind]++;
1351 tree_node_sizes[(int) vec_kind] += length;
1354 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
1356 memset (t, 0, length);
1358 TREE_SET_CODE (t, TREE_VEC);
1359 TREE_VEC_LENGTH (t) = len;
1364 /* Return 1 if EXPR is the integer constant zero or a complex constant
1368 integer_zerop (const_tree expr)
1372 return ((TREE_CODE (expr) == INTEGER_CST
1373 && TREE_INT_CST_LOW (expr) == 0
1374 && TREE_INT_CST_HIGH (expr) == 0)
1375 || (TREE_CODE (expr) == COMPLEX_CST
1376 && integer_zerop (TREE_REALPART (expr))
1377 && integer_zerop (TREE_IMAGPART (expr))));
1380 /* Return 1 if EXPR is the integer constant one or the corresponding
1381 complex constant. */
1384 integer_onep (const_tree expr)
1388 return ((TREE_CODE (expr) == INTEGER_CST
1389 && TREE_INT_CST_LOW (expr) == 1
1390 && TREE_INT_CST_HIGH (expr) == 0)
1391 || (TREE_CODE (expr) == COMPLEX_CST
1392 && integer_onep (TREE_REALPART (expr))
1393 && integer_zerop (TREE_IMAGPART (expr))));
1396 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1397 it contains. Likewise for the corresponding complex constant. */
1400 integer_all_onesp (const_tree expr)
1407 if (TREE_CODE (expr) == COMPLEX_CST
1408 && integer_all_onesp (TREE_REALPART (expr))
1409 && integer_zerop (TREE_IMAGPART (expr)))
1412 else if (TREE_CODE (expr) != INTEGER_CST)
1415 uns = TYPE_UNSIGNED (TREE_TYPE (expr));
1416 if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1417 && TREE_INT_CST_HIGH (expr) == -1)
1422 /* Note that using TYPE_PRECISION here is wrong. We care about the
1423 actual bits, not the (arbitrary) range of the type. */
1424 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
1425 if (prec >= HOST_BITS_PER_WIDE_INT)
1427 HOST_WIDE_INT high_value;
1430 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1432 /* Can not handle precisions greater than twice the host int size. */
1433 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT);
1434 if (shift_amount == HOST_BITS_PER_WIDE_INT)
1435 /* Shifting by the host word size is undefined according to the ANSI
1436 standard, so we must handle this as a special case. */
1439 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1441 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1442 && TREE_INT_CST_HIGH (expr) == high_value);
1445 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
1448 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1452 integer_pow2p (const_tree expr)
1455 HOST_WIDE_INT high, low;
1459 if (TREE_CODE (expr) == COMPLEX_CST
1460 && integer_pow2p (TREE_REALPART (expr))
1461 && integer_zerop (TREE_IMAGPART (expr)))
1464 if (TREE_CODE (expr) != INTEGER_CST)
1467 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1468 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1469 high = TREE_INT_CST_HIGH (expr);
1470 low = TREE_INT_CST_LOW (expr);
1472 /* First clear all bits that are beyond the type's precision in case
1473 we've been sign extended. */
1475 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1477 else if (prec > HOST_BITS_PER_WIDE_INT)
1478 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1482 if (prec < HOST_BITS_PER_WIDE_INT)
1483 low &= ~((HOST_WIDE_INT) (-1) << prec);
1486 if (high == 0 && low == 0)
1489 return ((high == 0 && (low & (low - 1)) == 0)
1490 || (low == 0 && (high & (high - 1)) == 0));
1493 /* Return 1 if EXPR is an integer constant other than zero or a
1494 complex constant other than zero. */
1497 integer_nonzerop (const_tree expr)
1501 return ((TREE_CODE (expr) == INTEGER_CST
1502 && (TREE_INT_CST_LOW (expr) != 0
1503 || TREE_INT_CST_HIGH (expr) != 0))
1504 || (TREE_CODE (expr) == COMPLEX_CST
1505 && (integer_nonzerop (TREE_REALPART (expr))
1506 || integer_nonzerop (TREE_IMAGPART (expr)))));
1509 /* Return 1 if EXPR is the fixed-point constant zero. */
1512 fixed_zerop (const_tree expr)
1514 return (TREE_CODE (expr) == FIXED_CST
1515 && double_int_zero_p (TREE_FIXED_CST (expr).data));
1518 /* Return the power of two represented by a tree node known to be a
1522 tree_log2 (const_tree expr)
1525 HOST_WIDE_INT high, low;
1529 if (TREE_CODE (expr) == COMPLEX_CST)
1530 return tree_log2 (TREE_REALPART (expr));
1532 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1533 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1535 high = TREE_INT_CST_HIGH (expr);
1536 low = TREE_INT_CST_LOW (expr);
1538 /* First clear all bits that are beyond the type's precision in case
1539 we've been sign extended. */
1541 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1543 else if (prec > HOST_BITS_PER_WIDE_INT)
1544 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1548 if (prec < HOST_BITS_PER_WIDE_INT)
1549 low &= ~((HOST_WIDE_INT) (-1) << prec);
1552 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
1553 : exact_log2 (low));
1556 /* Similar, but return the largest integer Y such that 2 ** Y is less
1557 than or equal to EXPR. */
1560 tree_floor_log2 (const_tree expr)
1563 HOST_WIDE_INT high, low;
1567 if (TREE_CODE (expr) == COMPLEX_CST)
1568 return tree_log2 (TREE_REALPART (expr));
1570 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1571 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1573 high = TREE_INT_CST_HIGH (expr);
1574 low = TREE_INT_CST_LOW (expr);
1576 /* First clear all bits that are beyond the type's precision in case
1577 we've been sign extended. Ignore if type's precision hasn't been set
1578 since what we are doing is setting it. */
1580 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
1582 else if (prec > HOST_BITS_PER_WIDE_INT)
1583 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1587 if (prec < HOST_BITS_PER_WIDE_INT)
1588 low &= ~((HOST_WIDE_INT) (-1) << prec);
1591 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
1592 : floor_log2 (low));
1595 /* Return 1 if EXPR is the real constant zero. */
1598 real_zerop (const_tree expr)
1602 return ((TREE_CODE (expr) == REAL_CST
1603 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
1604 || (TREE_CODE (expr) == COMPLEX_CST
1605 && real_zerop (TREE_REALPART (expr))
1606 && real_zerop (TREE_IMAGPART (expr))));
1609 /* Return 1 if EXPR is the real constant one in real or complex form. */
1612 real_onep (const_tree expr)
1616 return ((TREE_CODE (expr) == REAL_CST
1617 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
1618 || (TREE_CODE (expr) == COMPLEX_CST
1619 && real_onep (TREE_REALPART (expr))
1620 && real_zerop (TREE_IMAGPART (expr))));
1623 /* Return 1 if EXPR is the real constant two. */
1626 real_twop (const_tree expr)
1630 return ((TREE_CODE (expr) == REAL_CST
1631 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
1632 || (TREE_CODE (expr) == COMPLEX_CST
1633 && real_twop (TREE_REALPART (expr))
1634 && real_zerop (TREE_IMAGPART (expr))));
1637 /* Return 1 if EXPR is the real constant minus one. */
1640 real_minus_onep (const_tree expr)
1644 return ((TREE_CODE (expr) == REAL_CST
1645 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1))
1646 || (TREE_CODE (expr) == COMPLEX_CST
1647 && real_minus_onep (TREE_REALPART (expr))
1648 && real_zerop (TREE_IMAGPART (expr))));
1651 /* Nonzero if EXP is a constant or a cast of a constant. */
1654 really_constant_p (const_tree exp)
1656 /* This is not quite the same as STRIP_NOPS. It does more. */
1657 while (CONVERT_EXPR_P (exp)
1658 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1659 exp = TREE_OPERAND (exp, 0);
1660 return TREE_CONSTANT (exp);
1663 /* Return first list element whose TREE_VALUE is ELEM.
1664 Return 0 if ELEM is not in LIST. */
1667 value_member (tree elem, tree list)
1671 if (elem == TREE_VALUE (list))
1673 list = TREE_CHAIN (list);
1678 /* Return first list element whose TREE_PURPOSE is ELEM.
1679 Return 0 if ELEM is not in LIST. */
1682 purpose_member (const_tree elem, tree list)
1686 if (elem == TREE_PURPOSE (list))
1688 list = TREE_CHAIN (list);
1693 /* Return nonzero if ELEM is part of the chain CHAIN. */
1696 chain_member (const_tree elem, const_tree chain)
1702 chain = TREE_CHAIN (chain);
1708 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1709 We expect a null pointer to mark the end of the chain.
1710 This is the Lisp primitive `length'. */
1713 list_length (const_tree t)
1716 #ifdef ENABLE_TREE_CHECKING
1724 #ifdef ENABLE_TREE_CHECKING
1727 gcc_assert (p != q);
1735 /* Returns the number of FIELD_DECLs in TYPE. */
1738 fields_length (const_tree type)
1740 tree t = TYPE_FIELDS (type);
1743 for (; t; t = TREE_CHAIN (t))
1744 if (TREE_CODE (t) == FIELD_DECL)
1750 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1751 by modifying the last node in chain 1 to point to chain 2.
1752 This is the Lisp primitive `nconc'. */
1755 chainon (tree op1, tree op2)
1764 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1766 TREE_CHAIN (t1) = op2;
1768 #ifdef ENABLE_TREE_CHECKING
1771 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1772 gcc_assert (t2 != t1);
1779 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1782 tree_last (tree chain)
1786 while ((next = TREE_CHAIN (chain)))
1791 /* Return the node in a chain of nodes whose value is x, NULL if not found. */
1794 tree_find_value (tree chain, tree x)
1797 for (list = chain; list; list = TREE_CHAIN (list))
1798 if (TREE_VALUE (list) == x)
1803 /* Reverse the order of elements in the chain T,
1804 and return the new head of the chain (old last element). */
1809 tree prev = 0, decl, next;
1810 for (decl = t; decl; decl = next)
1812 next = TREE_CHAIN (decl);
1813 TREE_CHAIN (decl) = prev;
1819 /* Return a newly created TREE_LIST node whose
1820 purpose and value fields are PARM and VALUE. */
1823 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
1825 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
1826 TREE_PURPOSE (t) = parm;
1827 TREE_VALUE (t) = value;
1831 /* Return a newly created TREE_LIST node whose
1832 purpose and value fields are PURPOSE and VALUE
1833 and whose TREE_CHAIN is CHAIN. */
1836 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
1840 node = (tree) ggc_alloc_zone_pass_stat (sizeof (struct tree_list), &tree_zone);
1842 memset (node, 0, sizeof (struct tree_common));
1844 #ifdef GATHER_STATISTICS
1845 tree_node_counts[(int) x_kind]++;
1846 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
1849 TREE_SET_CODE (node, TREE_LIST);
1850 TREE_CHAIN (node) = chain;
1851 TREE_PURPOSE (node) = purpose;
1852 TREE_VALUE (node) = value;
1856 /* Return the elements of a CONSTRUCTOR as a TREE_LIST. */
1859 ctor_to_list (tree ctor)
1861 tree list = NULL_TREE;
1866 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), ix, purpose, val)
1868 *p = build_tree_list (purpose, val);
1869 p = &TREE_CHAIN (*p);
1875 /* Return the size nominally occupied by an object of type TYPE
1876 when it resides in memory. The value is measured in units of bytes,
1877 and its data type is that normally used for type sizes
1878 (which is the first type created by make_signed_type or
1879 make_unsigned_type). */
1882 size_in_bytes (const_tree type)
1886 if (type == error_mark_node)
1887 return integer_zero_node;
1889 type = TYPE_MAIN_VARIANT (type);
1890 t = TYPE_SIZE_UNIT (type);
1894 lang_hooks.types.incomplete_type_error (NULL_TREE, type);
1895 return size_zero_node;
1901 /* Return the size of TYPE (in bytes) as a wide integer
1902 or return -1 if the size can vary or is larger than an integer. */
1905 int_size_in_bytes (const_tree type)
1909 if (type == error_mark_node)
1912 type = TYPE_MAIN_VARIANT (type);
1913 t = TYPE_SIZE_UNIT (type);
1915 || TREE_CODE (t) != INTEGER_CST
1916 || TREE_INT_CST_HIGH (t) != 0
1917 /* If the result would appear negative, it's too big to represent. */
1918 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
1921 return TREE_INT_CST_LOW (t);
1924 /* Return the maximum size of TYPE (in bytes) as a wide integer
1925 or return -1 if the size can vary or is larger than an integer. */
1928 max_int_size_in_bytes (const_tree type)
1930 HOST_WIDE_INT size = -1;
1933 /* If this is an array type, check for a possible MAX_SIZE attached. */
1935 if (TREE_CODE (type) == ARRAY_TYPE)
1937 size_tree = TYPE_ARRAY_MAX_SIZE (type);
1939 if (size_tree && host_integerp (size_tree, 1))
1940 size = tree_low_cst (size_tree, 1);
1943 /* If we still haven't been able to get a size, see if the language
1944 can compute a maximum size. */
1948 size_tree = lang_hooks.types.max_size (type);
1950 if (size_tree && host_integerp (size_tree, 1))
1951 size = tree_low_cst (size_tree, 1);
1957 /* Return the bit position of FIELD, in bits from the start of the record.
1958 This is a tree of type bitsizetype. */
1961 bit_position (const_tree field)
1963 return bit_from_pos (DECL_FIELD_OFFSET (field),
1964 DECL_FIELD_BIT_OFFSET (field));
1967 /* Likewise, but return as an integer. It must be representable in
1968 that way (since it could be a signed value, we don't have the
1969 option of returning -1 like int_size_in_byte can. */
1972 int_bit_position (const_tree field)
1974 return tree_low_cst (bit_position (field), 0);
1977 /* Return the byte position of FIELD, in bytes from the start of the record.
1978 This is a tree of type sizetype. */
1981 byte_position (const_tree field)
1983 return byte_from_pos (DECL_FIELD_OFFSET (field),
1984 DECL_FIELD_BIT_OFFSET (field));
1987 /* Likewise, but return as an integer. It must be representable in
1988 that way (since it could be a signed value, we don't have the
1989 option of returning -1 like int_size_in_byte can. */
1992 int_byte_position (const_tree field)
1994 return tree_low_cst (byte_position (field), 0);
1997 /* Return the strictest alignment, in bits, that T is known to have. */
2000 expr_align (const_tree t)
2002 unsigned int align0, align1;
2004 switch (TREE_CODE (t))
2006 CASE_CONVERT: case NON_LVALUE_EXPR:
2007 /* If we have conversions, we know that the alignment of the
2008 object must meet each of the alignments of the types. */
2009 align0 = expr_align (TREE_OPERAND (t, 0));
2010 align1 = TYPE_ALIGN (TREE_TYPE (t));
2011 return MAX (align0, align1);
2013 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
2014 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
2015 case CLEANUP_POINT_EXPR:
2016 /* These don't change the alignment of an object. */
2017 return expr_align (TREE_OPERAND (t, 0));
2020 /* The best we can do is say that the alignment is the least aligned
2022 align0 = expr_align (TREE_OPERAND (t, 1));
2023 align1 = expr_align (TREE_OPERAND (t, 2));
2024 return MIN (align0, align1);
2026 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2027 meaningfully, it's always 1. */
2028 case LABEL_DECL: case CONST_DECL:
2029 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
2031 gcc_assert (DECL_ALIGN (t) != 0);
2032 return DECL_ALIGN (t);
2038 /* Otherwise take the alignment from that of the type. */
2039 return TYPE_ALIGN (TREE_TYPE (t));
2042 /* Return, as a tree node, the number of elements for TYPE (which is an
2043 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2046 array_type_nelts (const_tree type)
2048 tree index_type, min, max;
2050 /* If they did it with unspecified bounds, then we should have already
2051 given an error about it before we got here. */
2052 if (! TYPE_DOMAIN (type))
2053 return error_mark_node;
2055 index_type = TYPE_DOMAIN (type);
2056 min = TYPE_MIN_VALUE (index_type);
2057 max = TYPE_MAX_VALUE (index_type);
2059 return (integer_zerop (min)
2061 : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
2064 /* If arg is static -- a reference to an object in static storage -- then
2065 return the object. This is not the same as the C meaning of `static'.
2066 If arg isn't static, return NULL. */
2071 switch (TREE_CODE (arg))
2074 /* Nested functions are static, even though taking their address will
2075 involve a trampoline as we unnest the nested function and create
2076 the trampoline on the tree level. */
2080 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2081 && ! DECL_THREAD_LOCAL_P (arg)
2082 && ! DECL_DLLIMPORT_P (arg)
2086 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2090 return TREE_STATIC (arg) ? arg : NULL;
2097 /* If the thing being referenced is not a field, then it is
2098 something language specific. */
2099 gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
2101 /* If we are referencing a bitfield, we can't evaluate an
2102 ADDR_EXPR at compile time and so it isn't a constant. */
2103 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
2106 return staticp (TREE_OPERAND (arg, 0));
2111 case MISALIGNED_INDIRECT_REF:
2112 case ALIGN_INDIRECT_REF:
2114 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
2117 case ARRAY_RANGE_REF:
2118 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
2119 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
2120 return staticp (TREE_OPERAND (arg, 0));
2124 case COMPOUND_LITERAL_EXPR:
2125 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
2135 /* Return whether OP is a DECL whose address is function-invariant. */
2138 decl_address_invariant_p (const_tree op)
2140 /* The conditions below are slightly less strict than the one in
2143 switch (TREE_CODE (op))
2152 if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
2153 && !DECL_DLLIMPORT_P (op))
2154 || DECL_THREAD_LOCAL_P (op)
2155 || DECL_CONTEXT (op) == current_function_decl
2156 || decl_function_context (op) == current_function_decl)
2161 if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
2162 || decl_function_context (op) == current_function_decl)
2173 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
2176 decl_address_ip_invariant_p (const_tree op)
2178 /* The conditions below are slightly less strict than the one in
2181 switch (TREE_CODE (op))
2189 if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
2190 && !DECL_DLLIMPORT_P (op))
2191 || DECL_THREAD_LOCAL_P (op))
2196 if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
2208 /* Return true if T is function-invariant (internal function, does
2209 not handle arithmetic; that's handled in skip_simple_arithmetic and
2210 tree_invariant_p). */
2212 static bool tree_invariant_p (tree t);
2215 tree_invariant_p_1 (tree t)
2219 if (TREE_CONSTANT (t)
2220 || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
2223 switch (TREE_CODE (t))
2229 op = TREE_OPERAND (t, 0);
2230 while (handled_component_p (op))
2232 switch (TREE_CODE (op))
2235 case ARRAY_RANGE_REF:
2236 if (!tree_invariant_p (TREE_OPERAND (op, 1))
2237 || TREE_OPERAND (op, 2) != NULL_TREE
2238 || TREE_OPERAND (op, 3) != NULL_TREE)
2243 if (TREE_OPERAND (op, 2) != NULL_TREE)
2249 op = TREE_OPERAND (op, 0);
2252 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
2261 /* Return true if T is function-invariant. */
2264 tree_invariant_p (tree t)
2266 tree inner = skip_simple_arithmetic (t);
2267 return tree_invariant_p_1 (inner);
2270 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2271 Do this to any expression which may be used in more than one place,
2272 but must be evaluated only once.
2274 Normally, expand_expr would reevaluate the expression each time.
2275 Calling save_expr produces something that is evaluated and recorded
2276 the first time expand_expr is called on it. Subsequent calls to
2277 expand_expr just reuse the recorded value.
2279 The call to expand_expr that generates code that actually computes
2280 the value is the first call *at compile time*. Subsequent calls
2281 *at compile time* generate code to use the saved value.
2282 This produces correct result provided that *at run time* control
2283 always flows through the insns made by the first expand_expr
2284 before reaching the other places where the save_expr was evaluated.
2285 You, the caller of save_expr, must make sure this is so.
2287 Constants, and certain read-only nodes, are returned with no
2288 SAVE_EXPR because that is safe. Expressions containing placeholders
2289 are not touched; see tree.def for an explanation of what these
2293 save_expr (tree expr)
2295 tree t = fold (expr);
2298 /* If the tree evaluates to a constant, then we don't want to hide that
2299 fact (i.e. this allows further folding, and direct checks for constants).
2300 However, a read-only object that has side effects cannot be bypassed.
2301 Since it is no problem to reevaluate literals, we just return the
2303 inner = skip_simple_arithmetic (t);
2304 if (TREE_CODE (inner) == ERROR_MARK)
2307 if (tree_invariant_p_1 (inner))
2310 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2311 it means that the size or offset of some field of an object depends on
2312 the value within another field.
2314 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2315 and some variable since it would then need to be both evaluated once and
2316 evaluated more than once. Front-ends must assure this case cannot
2317 happen by surrounding any such subexpressions in their own SAVE_EXPR
2318 and forcing evaluation at the proper time. */
2319 if (contains_placeholder_p (inner))
2322 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
2324 /* This expression might be placed ahead of a jump to ensure that the
2325 value was computed on both sides of the jump. So make sure it isn't
2326 eliminated as dead. */
2327 TREE_SIDE_EFFECTS (t) = 1;
2331 /* Look inside EXPR and into any simple arithmetic operations. Return
2332 the innermost non-arithmetic node. */
2335 skip_simple_arithmetic (tree expr)
2339 /* We don't care about whether this can be used as an lvalue in this
2341 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
2342 expr = TREE_OPERAND (expr, 0);
2344 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2345 a constant, it will be more efficient to not make another SAVE_EXPR since
2346 it will allow better simplification and GCSE will be able to merge the
2347 computations if they actually occur. */
2351 if (UNARY_CLASS_P (inner))
2352 inner = TREE_OPERAND (inner, 0);
2353 else if (BINARY_CLASS_P (inner))
2355 if (tree_invariant_p (TREE_OPERAND (inner, 1)))
2356 inner = TREE_OPERAND (inner, 0);
2357 else if (tree_invariant_p (TREE_OPERAND (inner, 0)))
2358 inner = TREE_OPERAND (inner, 1);
2369 /* Return which tree structure is used by T. */
2371 enum tree_node_structure_enum
2372 tree_node_structure (const_tree t)
2374 const enum tree_code code = TREE_CODE (t);
2376 switch (TREE_CODE_CLASS (code))
2378 case tcc_declaration:
2383 return TS_FIELD_DECL;
2385 return TS_PARM_DECL;
2389 return TS_LABEL_DECL;
2391 return TS_RESULT_DECL;
2393 return TS_CONST_DECL;
2395 return TS_TYPE_DECL;
2397 return TS_FUNCTION_DECL;
2399 return TS_DECL_NON_COMMON;
2405 case tcc_comparison:
2408 case tcc_expression:
2412 default: /* tcc_constant and tcc_exceptional */
2417 /* tcc_constant cases. */
2418 case INTEGER_CST: return TS_INT_CST;
2419 case REAL_CST: return TS_REAL_CST;
2420 case FIXED_CST: return TS_FIXED_CST;
2421 case COMPLEX_CST: return TS_COMPLEX;
2422 case VECTOR_CST: return TS_VECTOR;
2423 case STRING_CST: return TS_STRING;
2424 /* tcc_exceptional cases. */
2425 case ERROR_MARK: return TS_COMMON;
2426 case IDENTIFIER_NODE: return TS_IDENTIFIER;
2427 case TREE_LIST: return TS_LIST;
2428 case TREE_VEC: return TS_VEC;
2429 case SSA_NAME: return TS_SSA_NAME;
2430 case PLACEHOLDER_EXPR: return TS_COMMON;
2431 case STATEMENT_LIST: return TS_STATEMENT_LIST;
2432 case BLOCK: return TS_BLOCK;
2433 case CONSTRUCTOR: return TS_CONSTRUCTOR;
2434 case TREE_BINFO: return TS_BINFO;
2435 case OMP_CLAUSE: return TS_OMP_CLAUSE;
2436 case OPTIMIZATION_NODE: return TS_OPTIMIZATION;
2437 case TARGET_OPTION_NODE: return TS_TARGET_OPTION;
2444 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2445 or offset that depends on a field within a record. */
2448 contains_placeholder_p (const_tree exp)
2450 enum tree_code code;
2455 code = TREE_CODE (exp);
2456 if (code == PLACEHOLDER_EXPR)
2459 switch (TREE_CODE_CLASS (code))
2462 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2463 position computations since they will be converted into a
2464 WITH_RECORD_EXPR involving the reference, which will assume
2465 here will be valid. */
2466 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
2468 case tcc_exceptional:
2469 if (code == TREE_LIST)
2470 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
2471 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
2476 case tcc_comparison:
2477 case tcc_expression:
2481 /* Ignoring the first operand isn't quite right, but works best. */
2482 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
2485 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
2486 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
2487 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
2490 /* The save_expr function never wraps anything containing
2491 a PLACEHOLDER_EXPR. */
2498 switch (TREE_CODE_LENGTH (code))
2501 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
2503 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
2504 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
2515 const_call_expr_arg_iterator iter;
2516 FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
2517 if (CONTAINS_PLACEHOLDER_P (arg))
2531 /* Return true if any part of the computation of TYPE involves a
2532 PLACEHOLDER_EXPR. This includes size, bounds, qualifiers
2533 (for QUAL_UNION_TYPE) and field positions. */
2536 type_contains_placeholder_1 (const_tree type)
2538 /* If the size contains a placeholder or the parent type (component type in
2539 the case of arrays) type involves a placeholder, this type does. */
2540 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
2541 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
2542 || (TREE_TYPE (type) != 0
2543 && type_contains_placeholder_p (TREE_TYPE (type))))
2546 /* Now do type-specific checks. Note that the last part of the check above
2547 greatly limits what we have to do below. */
2548 switch (TREE_CODE (type))
2556 case REFERENCE_TYPE:
2564 case FIXED_POINT_TYPE:
2565 /* Here we just check the bounds. */
2566 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
2567 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
2570 /* We're already checked the component type (TREE_TYPE), so just check
2572 return type_contains_placeholder_p (TYPE_DOMAIN (type));
2576 case QUAL_UNION_TYPE:
2580 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
2581 if (TREE_CODE (field) == FIELD_DECL
2582 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
2583 || (TREE_CODE (type) == QUAL_UNION_TYPE
2584 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
2585 || type_contains_placeholder_p (TREE_TYPE (field))))
2597 type_contains_placeholder_p (tree type)
2601 /* If the contains_placeholder_bits field has been initialized,
2602 then we know the answer. */
2603 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
2604 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
2606 /* Indicate that we've seen this type node, and the answer is false.
2607 This is what we want to return if we run into recursion via fields. */
2608 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
2610 /* Compute the real value. */
2611 result = type_contains_placeholder_1 (type);
2613 /* Store the real value. */
2614 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
2619 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2620 return a tree with all occurrences of references to F in a
2621 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2622 contains only arithmetic expressions or a CALL_EXPR with a
2623 PLACEHOLDER_EXPR occurring only in its arglist. */
2626 substitute_in_expr (tree exp, tree f, tree r)
2628 enum tree_code code = TREE_CODE (exp);
2629 tree op0, op1, op2, op3;
2630 tree new_tree, inner;
2632 /* We handle TREE_LIST and COMPONENT_REF separately. */
2633 if (code == TREE_LIST)
2635 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
2636 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
2637 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2640 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2642 else if (code == COMPONENT_REF)
2644 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2645 and it is the right field, replace it with R. */
2646 for (inner = TREE_OPERAND (exp, 0);
2647 REFERENCE_CLASS_P (inner);
2648 inner = TREE_OPERAND (inner, 0))
2650 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2651 && TREE_OPERAND (exp, 1) == f)
2654 /* If this expression hasn't been completed let, leave it alone. */
2655 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0)
2658 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2659 if (op0 == TREE_OPERAND (exp, 0))
2662 new_tree = fold_build3 (COMPONENT_REF, TREE_TYPE (exp),
2663 op0, TREE_OPERAND (exp, 1), NULL_TREE);
2666 switch (TREE_CODE_CLASS (code))
2669 case tcc_declaration:
2672 case tcc_exceptional:
2675 case tcc_comparison:
2676 case tcc_expression:
2678 switch (TREE_CODE_LENGTH (code))
2684 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2685 if (op0 == TREE_OPERAND (exp, 0))
2688 new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
2692 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2693 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2695 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2698 new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
2702 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2703 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2704 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
2706 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2707 && op2 == TREE_OPERAND (exp, 2))
2710 new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
2714 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2715 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2716 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
2717 op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
2719 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2720 && op2 == TREE_OPERAND (exp, 2)
2721 && op3 == TREE_OPERAND (exp, 3))
2724 new_tree = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2734 tree copy = NULL_TREE;
2737 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
2739 tree op = TREE_OPERAND (exp, i);
2740 tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
2744 copy = copy_node (exp);
2745 TREE_OPERAND (copy, i) = new_op;
2750 new_tree = fold (copy);
2760 TREE_READONLY (new_tree) = TREE_READONLY (exp);
2764 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
2765 for it within OBJ, a tree that is an object or a chain of references. */
2768 substitute_placeholder_in_expr (tree exp, tree obj)
2770 enum tree_code code = TREE_CODE (exp);
2771 tree op0, op1, op2, op3;
2773 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
2774 in the chain of OBJ. */
2775 if (code == PLACEHOLDER_EXPR)
2777 tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
2780 for (elt = obj; elt != 0;
2781 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
2782 || TREE_CODE (elt) == COND_EXPR)
2783 ? TREE_OPERAND (elt, 1)
2784 : (REFERENCE_CLASS_P (elt)
2785 || UNARY_CLASS_P (elt)
2786 || BINARY_CLASS_P (elt)
2787 || VL_EXP_CLASS_P (elt)
2788 || EXPRESSION_CLASS_P (elt))
2789 ? TREE_OPERAND (elt, 0) : 0))
2790 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
2793 for (elt = obj; elt != 0;
2794 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
2795 || TREE_CODE (elt) == COND_EXPR)
2796 ? TREE_OPERAND (elt, 1)
2797 : (REFERENCE_CLASS_P (elt)
2798 || UNARY_CLASS_P (elt)
2799 || BINARY_CLASS_P (elt)
2800 || VL_EXP_CLASS_P (elt)
2801 || EXPRESSION_CLASS_P (elt))
2802 ? TREE_OPERAND (elt, 0) : 0))
2803 if (POINTER_TYPE_P (TREE_TYPE (elt))
2804 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
2806 return fold_build1 (INDIRECT_REF, need_type, elt);
2808 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2809 survives until RTL generation, there will be an error. */
2813 /* TREE_LIST is special because we need to look at TREE_VALUE
2814 and TREE_CHAIN, not TREE_OPERANDS. */
2815 else if (code == TREE_LIST)
2817 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
2818 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
2819 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2822 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2825 switch (TREE_CODE_CLASS (code))
2828 case tcc_declaration:
2831 case tcc_exceptional:
2834 case tcc_comparison:
2835 case tcc_expression:
2838 switch (TREE_CODE_LENGTH (code))
2844 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2845 if (op0 == TREE_OPERAND (exp, 0))
2848 return fold_build1 (code, TREE_TYPE (exp), op0);
2851 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2852 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2854 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2857 return fold_build2 (code, TREE_TYPE (exp), op0, op1);
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);
2864 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2865 && op2 == TREE_OPERAND (exp, 2))
2868 return fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
2871 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2872 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2873 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2874 op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
2876 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2877 && op2 == TREE_OPERAND (exp, 2)
2878 && op3 == TREE_OPERAND (exp, 3))
2881 return fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2890 tree copy = NULL_TREE;
2893 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
2895 tree op = TREE_OPERAND (exp, i);
2896 tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
2900 copy = copy_node (exp);
2901 TREE_OPERAND (copy, i) = new_op;
2916 /* Stabilize a reference so that we can use it any number of times
2917 without causing its operands to be evaluated more than once.
2918 Returns the stabilized reference. This works by means of save_expr,
2919 so see the caveats in the comments about save_expr.
2921 Also allows conversion expressions whose operands are references.
2922 Any other kind of expression is returned unchanged. */
2925 stabilize_reference (tree ref)
2928 enum tree_code code = TREE_CODE (ref);
2935 /* No action is needed in this case. */
2940 case FIX_TRUNC_EXPR:
2941 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2945 result = build_nt (INDIRECT_REF,
2946 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2950 result = build_nt (COMPONENT_REF,
2951 stabilize_reference (TREE_OPERAND (ref, 0)),
2952 TREE_OPERAND (ref, 1), NULL_TREE);
2956 result = build_nt (BIT_FIELD_REF,
2957 stabilize_reference (TREE_OPERAND (ref, 0)),
2958 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2959 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2963 result = build_nt (ARRAY_REF,
2964 stabilize_reference (TREE_OPERAND (ref, 0)),
2965 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2966 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2969 case ARRAY_RANGE_REF:
2970 result = build_nt (ARRAY_RANGE_REF,
2971 stabilize_reference (TREE_OPERAND (ref, 0)),
2972 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2973 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2977 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2978 it wouldn't be ignored. This matters when dealing with
2980 return stabilize_reference_1 (ref);
2982 /* If arg isn't a kind of lvalue we recognize, make no change.
2983 Caller should recognize the error for an invalid lvalue. */
2988 return error_mark_node;
2991 TREE_TYPE (result) = TREE_TYPE (ref);
2992 TREE_READONLY (result) = TREE_READONLY (ref);
2993 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2994 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2999 /* Subroutine of stabilize_reference; this is called for subtrees of
3000 references. Any expression with side-effects must be put in a SAVE_EXPR
3001 to ensure that it is only evaluated once.
3003 We don't put SAVE_EXPR nodes around everything, because assigning very
3004 simple expressions to temporaries causes us to miss good opportunities
3005 for optimizations. Among other things, the opportunity to fold in the
3006 addition of a constant into an addressing mode often gets lost, e.g.
3007 "y[i+1] += x;". In general, we take the approach that we should not make
3008 an assignment unless we are forced into it - i.e., that any non-side effect
3009 operator should be allowed, and that cse should take care of coalescing
3010 multiple utterances of the same expression should that prove fruitful. */
3013 stabilize_reference_1 (tree e)
3016 enum tree_code code = TREE_CODE (e);
3018 /* We cannot ignore const expressions because it might be a reference
3019 to a const array but whose index contains side-effects. But we can
3020 ignore things that are actual constant or that already have been
3021 handled by this function. */
3023 if (tree_invariant_p (e))
3026 switch (TREE_CODE_CLASS (code))
3028 case tcc_exceptional:
3030 case tcc_declaration:
3031 case tcc_comparison:
3033 case tcc_expression:
3036 /* If the expression has side-effects, then encase it in a SAVE_EXPR
3037 so that it will only be evaluated once. */
3038 /* The reference (r) and comparison (<) classes could be handled as
3039 below, but it is generally faster to only evaluate them once. */
3040 if (TREE_SIDE_EFFECTS (e))
3041 return save_expr (e);
3045 /* Constants need no processing. In fact, we should never reach
3050 /* Division is slow and tends to be compiled with jumps,
3051 especially the division by powers of 2 that is often
3052 found inside of an array reference. So do it just once. */
3053 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
3054 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
3055 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
3056 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
3057 return save_expr (e);
3058 /* Recursively stabilize each operand. */
3059 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
3060 stabilize_reference_1 (TREE_OPERAND (e, 1)));
3064 /* Recursively stabilize each operand. */
3065 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
3072 TREE_TYPE (result) = TREE_TYPE (e);
3073 TREE_READONLY (result) = TREE_READONLY (e);
3074 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
3075 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
3080 /* Low-level constructors for expressions. */
3082 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
3083 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
3086 recompute_tree_invariant_for_addr_expr (tree t)
3089 bool tc = true, se = false;
3091 /* We started out assuming this address is both invariant and constant, but
3092 does not have side effects. Now go down any handled components and see if
3093 any of them involve offsets that are either non-constant or non-invariant.
3094 Also check for side-effects.
3096 ??? Note that this code makes no attempt to deal with the case where
3097 taking the address of something causes a copy due to misalignment. */
3099 #define UPDATE_FLAGS(NODE) \
3100 do { tree _node = (NODE); \
3101 if (_node && !TREE_CONSTANT (_node)) tc = false; \
3102 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
3104 for (node = TREE_OPERAND (t, 0); handled_component_p (node);
3105 node = TREE_OPERAND (node, 0))
3107 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
3108 array reference (probably made temporarily by the G++ front end),
3109 so ignore all the operands. */
3110 if ((TREE_CODE (node) == ARRAY_REF
3111 || TREE_CODE (node) == ARRAY_RANGE_REF)
3112 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
3114 UPDATE_FLAGS (TREE_OPERAND (node, 1));
3115 if (TREE_OPERAND (node, 2))
3116 UPDATE_FLAGS (TREE_OPERAND (node, 2));
3117 if (TREE_OPERAND (node, 3))
3118 UPDATE_FLAGS (TREE_OPERAND (node, 3));
3120 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
3121 FIELD_DECL, apparently. The G++ front end can put something else
3122 there, at least temporarily. */
3123 else if (TREE_CODE (node) == COMPONENT_REF
3124 && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
3126 if (TREE_OPERAND (node, 2))
3127 UPDATE_FLAGS (TREE_OPERAND (node, 2));
3129 else if (TREE_CODE (node) == BIT_FIELD_REF)
3130 UPDATE_FLAGS (TREE_OPERAND (node, 2));
3133 node = lang_hooks.expr_to_decl (node, &tc, &se);
3135 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
3136 the address, since &(*a)->b is a form of addition. If it's a constant, the
3137 address is constant too. If it's a decl, its address is constant if the
3138 decl is static. Everything else is not constant and, furthermore,
3139 taking the address of a volatile variable is not volatile. */
3140 if (TREE_CODE (node) == INDIRECT_REF)
3141 UPDATE_FLAGS (TREE_OPERAND (node, 0));
3142 else if (CONSTANT_CLASS_P (node))
3144 else if (DECL_P (node))
3145 tc &= (staticp (node) != NULL_TREE);
3149 se |= TREE_SIDE_EFFECTS (node);
3153 TREE_CONSTANT (t) = tc;
3154 TREE_SIDE_EFFECTS (t) = se;
3158 /* Build an expression of code CODE, data type TYPE, and operands as
3159 specified. Expressions and reference nodes can be created this way.
3160 Constants, decls, types and misc nodes cannot be.
3162 We define 5 non-variadic functions, from 0 to 4 arguments. This is
3163 enough for all extant tree codes. */
3166 build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
3170 gcc_assert (TREE_CODE_LENGTH (code) == 0);
3172 t = make_node_stat (code PASS_MEM_STAT);
3179 build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL)
3181 int length = sizeof (struct tree_exp);
3182 #ifdef GATHER_STATISTICS
3183 tree_node_kind kind;
3187 #ifdef GATHER_STATISTICS
3188 switch (TREE_CODE_CLASS (code))
3190 case tcc_statement: /* an expression with side effects */
3193 case tcc_reference: /* a reference */
3201 tree_node_counts[(int) kind]++;
3202 tree_node_sizes[(int) kind] += length;
3205 gcc_assert (TREE_CODE_LENGTH (code) == 1);
3207 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
3209 memset (t, 0, sizeof (struct tree_common));
3211 TREE_SET_CODE (t, code);
3213 TREE_TYPE (t) = type;
3214 SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
3215 TREE_OPERAND (t, 0) = node;
3216 TREE_BLOCK (t) = NULL_TREE;
3217 if (node && !TYPE_P (node))
3219 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
3220 TREE_READONLY (t) = TREE_READONLY (node);
3223 if (TREE_CODE_CLASS (code) == tcc_statement)
3224 TREE_SIDE_EFFECTS (t) = 1;
3228 /* All of these have side-effects, no matter what their
3230 TREE_SIDE_EFFECTS (t) = 1;
3231 TREE_READONLY (t) = 0;
3234 case MISALIGNED_INDIRECT_REF:
3235 case ALIGN_INDIRECT_REF:
3237 /* Whether a dereference is readonly has nothing to do with whether
3238 its operand is readonly. */
3239 TREE_READONLY (t) = 0;
3244 recompute_tree_invariant_for_addr_expr (t);
3248 if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
3249 && node && !TYPE_P (node)
3250 && TREE_CONSTANT (node))
3251 TREE_CONSTANT (t) = 1;
3252 if (TREE_CODE_CLASS (code) == tcc_reference
3253 && node && TREE_THIS_VOLATILE (node))
3254 TREE_THIS_VOLATILE (t) = 1;
3261 #define PROCESS_ARG(N) \
3263 TREE_OPERAND (t, N) = arg##N; \
3264 if (arg##N &&!TYPE_P (arg##N)) \
3266 if (TREE_SIDE_EFFECTS (arg##N)) \
3268 if (!TREE_READONLY (arg##N)) \
3270 if (!TREE_CONSTANT (arg##N)) \
3276 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
3278 bool constant, read_only, side_effects;
3281 gcc_assert (TREE_CODE_LENGTH (code) == 2);
3283 if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
3284 && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
3285 /* When sizetype precision doesn't match that of pointers
3286 we need to be able to build explicit extensions or truncations
3287 of the offset argument. */
3288 && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
3289 gcc_assert (TREE_CODE (arg0) == INTEGER_CST
3290 && TREE_CODE (arg1) == INTEGER_CST);
3292 if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
3293 gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
3294 && INTEGRAL_TYPE_P (TREE_TYPE (arg1))
3295 && useless_type_conversion_p (sizetype, TREE_TYPE (arg1)));
3297 t = make_node_stat (code PASS_MEM_STAT);
3300 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
3301 result based on those same flags for the arguments. But if the
3302 arguments aren't really even `tree' expressions, we shouldn't be trying
3305 /* Expressions without side effects may be constant if their
3306 arguments are as well. */
3307 constant = (TREE_CODE_CLASS (code) == tcc_comparison
3308 || TREE_CODE_CLASS (code) == tcc_binary);
3310 side_effects = TREE_SIDE_EFFECTS (t);
3315 TREE_READONLY (t) = read_only;
3316 TREE_CONSTANT (t) = constant;
3317 TREE_SIDE_EFFECTS (t) = side_effects;
3318 TREE_THIS_VOLATILE (t)
3319 = (TREE_CODE_CLASS (code) == tcc_reference
3320 && arg0 && TREE_THIS_VOLATILE (arg0));
3327 build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3328 tree arg2 MEM_STAT_DECL)
3330 bool constant, read_only, side_effects;
3333 gcc_assert (TREE_CODE_LENGTH (code) == 3);
3334 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3336 t = make_node_stat (code PASS_MEM_STAT);
3339 /* As a special exception, if COND_EXPR has NULL branches, we
3340 assume that it is a gimple statement and always consider
3341 it to have side effects. */
3342 if (code == COND_EXPR
3343 && tt == void_type_node
3344 && arg1 == NULL_TREE
3345 && arg2 == NULL_TREE)
3346 side_effects = true;
3348 side_effects = TREE_SIDE_EFFECTS (t);
3354 TREE_SIDE_EFFECTS (t) = side_effects;
3355 TREE_THIS_VOLATILE (t)
3356 = (TREE_CODE_CLASS (code) == tcc_reference
3357 && arg0 && TREE_THIS_VOLATILE (arg0));
3363 build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3364 tree arg2, tree arg3 MEM_STAT_DECL)
3366 bool constant, read_only, side_effects;
3369 gcc_assert (TREE_CODE_LENGTH (code) == 4);
3371 t = make_node_stat (code PASS_MEM_STAT);
3374 side_effects = TREE_SIDE_EFFECTS (t);
3381 TREE_SIDE_EFFECTS (t) = side_effects;
3382 TREE_THIS_VOLATILE (t)
3383 = (TREE_CODE_CLASS (code) == tcc_reference
3384 && arg0 && TREE_THIS_VOLATILE (arg0));
3390 build5_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3391 tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
3393 bool constant, read_only, side_effects;
3396 gcc_assert (TREE_CODE_LENGTH (code) == 5);
3398 t = make_node_stat (code PASS_MEM_STAT);
3401 side_effects = TREE_SIDE_EFFECTS (t);
3409 TREE_SIDE_EFFECTS (t) = side_effects;
3410 TREE_THIS_VOLATILE (t)
3411 = (TREE_CODE_CLASS (code) == tcc_reference
3412 && arg0 && TREE_THIS_VOLATILE (arg0));
3418 build6_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3419 tree arg2, tree arg3, tree arg4, tree arg5 MEM_STAT_DECL)
3421 bool constant, read_only, side_effects;
3424 gcc_assert (code == TARGET_MEM_REF);
3426 t = make_node_stat (code PASS_MEM_STAT);
3429 side_effects = TREE_SIDE_EFFECTS (t);
3438 TREE_SIDE_EFFECTS (t) = side_effects;
3439 TREE_THIS_VOLATILE (t) = 0;
3444 /* Similar except don't specify the TREE_TYPE
3445 and leave the TREE_SIDE_EFFECTS as 0.
3446 It is permissible for arguments to be null,
3447 or even garbage if their values do not matter. */
3450 build_nt (enum tree_code code, ...)
3457 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3461 t = make_node (code);
3462 length = TREE_CODE_LENGTH (code);
3464 for (i = 0; i < length; i++)
3465 TREE_OPERAND (t, i) = va_arg (p, tree);
3471 /* Similar to build_nt, but for creating a CALL_EXPR object with
3472 ARGLIST passed as a list. */
3475 build_nt_call_list (tree fn, tree arglist)
3480 t = build_vl_exp (CALL_EXPR, list_length (arglist) + 3);
3481 CALL_EXPR_FN (t) = fn;
3482 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
3483 for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++)
3484 CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist);
3488 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
3489 We do NOT enter this node in any sort of symbol table.
3491 layout_decl is used to set up the decl's storage layout.
3492 Other slots are initialized to 0 or null pointers. */
3495 build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL)
3499 t = make_node_stat (code PASS_MEM_STAT);
3501 /* if (type == error_mark_node)
3502 type = integer_type_node; */
3503 /* That is not done, deliberately, so that having error_mark_node
3504 as the type can suppress useless errors in the use of this variable. */
3506 DECL_NAME (t) = name;
3507 TREE_TYPE (t) = type;
3509 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
3515 /* Builds and returns function declaration with NAME and TYPE. */
3518 build_fn_decl (const char *name, tree type)
3520 tree id = get_identifier (name);
3521 tree decl = build_decl (FUNCTION_DECL, id, type);
3523 DECL_EXTERNAL (decl) = 1;
3524 TREE_PUBLIC (decl) = 1;
3525 DECL_ARTIFICIAL (decl) = 1;
3526 TREE_NOTHROW (decl) = 1;
3532 /* BLOCK nodes are used to represent the structure of binding contours
3533 and declarations, once those contours have been exited and their contents
3534 compiled. This information is used for outputting debugging info. */
3537 build_block (tree vars, tree subblocks, tree supercontext, tree chain)
3539 tree block = make_node (BLOCK);
3541 BLOCK_VARS (block) = vars;
3542 BLOCK_SUBBLOCKS (block) = subblocks;
3543 BLOCK_SUPERCONTEXT (block) = supercontext;
3544 BLOCK_CHAIN (block) = chain;
3549 expand_location (source_location loc)
3551 expanded_location xloc;
3561 const struct line_map *map = linemap_lookup (line_table, loc);
3562 xloc.file = map->to_file;
3563 xloc.line = SOURCE_LINE (map, loc);
3564 xloc.column = SOURCE_COLUMN (map, loc);
3565 xloc.sysp = map->sysp != 0;
3571 /* Source location accessor functions. */
3575 set_expr_locus (tree node, source_location *loc)
3578 EXPR_CHECK (node)->exp.locus = UNKNOWN_LOCATION;
3580 EXPR_CHECK (node)->exp.locus = *loc;
3583 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
3585 LOC is the location to use in tree T. */
3588 protected_set_expr_location (tree t, location_t loc)
3590 if (t && CAN_HAVE_LOCATION_P (t))
3591 SET_EXPR_LOCATION (t, loc);
3594 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
3598 build_decl_attribute_variant (tree ddecl, tree attribute)
3600 DECL_ATTRIBUTES (ddecl) = attribute;
3604 /* Borrowed from hashtab.c iterative_hash implementation. */
3605 #define mix(a,b,c) \
3607 a -= b; a -= c; a ^= (c>>13); \
3608 b -= c; b -= a; b ^= (a<< 8); \
3609 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
3610 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
3611 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
3612 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
3613 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
3614 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
3615 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
3619 /* Produce good hash value combining VAL and VAL2. */
3621 iterative_hash_hashval_t (hashval_t val, hashval_t val2)
3623 /* the golden ratio; an arbitrary value. */
3624 hashval_t a = 0x9e3779b9;
3630 /* Produce good hash value combining PTR and VAL2. */
3631 static inline hashval_t
3632 iterative_hash_pointer (const void *ptr, hashval_t val2)
3634 if (sizeof (ptr) == sizeof (hashval_t))
3635 return iterative_hash_hashval_t ((size_t) ptr, val2);
3638 hashval_t a = (hashval_t) (size_t) ptr;
3639 /* Avoid warnings about shifting of more than the width of the type on
3640 hosts that won't execute this path. */
3642 hashval_t b = (hashval_t) ((size_t) ptr >> (sizeof (hashval_t) * 8 + zero));
3648 /* Produce good hash value combining VAL and VAL2. */
3649 static inline hashval_t
3650 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2)
3652 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t))
3653 return iterative_hash_hashval_t (val, val2);
3656 hashval_t a = (hashval_t) val;
3657 /* Avoid warnings about shifting of more than the width of the type on
3658 hosts that won't execute this path. */
3660 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 8 + zero));
3662 if (sizeof (HOST_WIDE_INT) > 2 * sizeof (hashval_t))
3664 hashval_t a = (hashval_t) (val >> (sizeof (hashval_t) * 16 + zero));
3665 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 24 + zero));
3672 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3673 is ATTRIBUTE and its qualifiers are QUALS.
3675 Record such modified types already made so we don't make duplicates. */
3678 build_type_attribute_qual_variant (tree ttype, tree attribute, int quals)
3680 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
3682 hashval_t hashcode = 0;
3684 enum tree_code code = TREE_CODE (ttype);
3686 /* Building a distinct copy of a tagged type is inappropriate; it
3687 causes breakage in code that expects there to be a one-to-one
3688 relationship between a struct and its fields.
3689 build_duplicate_type is another solution (as used in
3690 handle_transparent_union_attribute), but that doesn't play well
3691 with the stronger C++ type identity model. */
3692 if (TREE_CODE (ttype) == RECORD_TYPE
3693 || TREE_CODE (ttype) == UNION_TYPE
3694 || TREE_CODE (ttype) == QUAL_UNION_TYPE
3695 || TREE_CODE (ttype) == ENUMERAL_TYPE)
3697 warning (OPT_Wattributes,
3698 "ignoring attributes applied to %qT after definition",
3699 TYPE_MAIN_VARIANT (ttype));
3700 return build_qualified_type (ttype, quals);
3703 ttype = build_qualified_type (ttype, TYPE_UNQUALIFIED);
3704 ntype = build_distinct_type_copy (ttype);
3706 TYPE_ATTRIBUTES (ntype) = attribute;
3708 hashcode = iterative_hash_object (code, hashcode);
3709 if (TREE_TYPE (ntype))
3710 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)),
3712 hashcode = attribute_hash_list (attribute, hashcode);
3714 switch (TREE_CODE (ntype))
3717 hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode);
3720 if (TYPE_DOMAIN (ntype))
3721 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)),
3725 hashcode = iterative_hash_object
3726 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode);
3727 hashcode = iterative_hash_object
3728 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode);
3731 case FIXED_POINT_TYPE:
3733 unsigned int precision = TYPE_PRECISION (ntype);
3734 hashcode = iterative_hash_object (precision, hashcode);
3741 ntype = type_hash_canon (hashcode, ntype);
3743 /* If the target-dependent attributes make NTYPE different from
3744 its canonical type, we will need to use structural equality
3745 checks for this type. */
3746 if (TYPE_STRUCTURAL_EQUALITY_P (ttype)
3747 || !targetm.comp_type_attributes (ntype, ttype))
3748 SET_TYPE_STRUCTURAL_EQUALITY (ntype);
3749 else if (TYPE_CANONICAL (ntype) == ntype)
3750 TYPE_CANONICAL (ntype) = TYPE_CANONICAL (ttype);
3752 ttype = build_qualified_type (ntype, quals);
3754 else if (TYPE_QUALS (ttype) != quals)
3755 ttype = build_qualified_type (ttype, quals);
3761 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3764 Record such modified types already made so we don't make duplicates. */
3767 build_type_attribute_variant (tree ttype, tree attribute)
3769 return build_type_attribute_qual_variant (ttype, attribute,
3770 TYPE_QUALS (ttype));
3773 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3776 We try both `text' and `__text__', ATTR may be either one. */
3777 /* ??? It might be a reasonable simplification to require ATTR to be only
3778 `text'. One might then also require attribute lists to be stored in
3779 their canonicalized form. */
3782 is_attribute_with_length_p (const char *attr, int attr_len, const_tree ident)
3787 if (TREE_CODE (ident) != IDENTIFIER_NODE)
3790 p = IDENTIFIER_POINTER (ident);
3791 ident_len = IDENTIFIER_LENGTH (ident);
3793 if (ident_len == attr_len
3794 && strcmp (attr, p) == 0)
3797 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
3800 gcc_assert (attr[1] == '_');
3801 gcc_assert (attr[attr_len - 2] == '_');
3802 gcc_assert (attr[attr_len - 1] == '_');
3803 if (ident_len == attr_len - 4
3804 && strncmp (attr + 2, p, attr_len - 4) == 0)
3809 if (ident_len == attr_len + 4
3810 && p[0] == '_' && p[1] == '_'
3811 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
3812 && strncmp (attr, p + 2, attr_len) == 0)
3819 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3822 We try both `text' and `__text__', ATTR may be either one. */
3825 is_attribute_p (const char *attr, const_tree ident)
3827 return is_attribute_with_length_p (attr, strlen (attr), ident);
3830 /* Given an attribute name and a list of attributes, return a pointer to the
3831 attribute's list element if the attribute is part of the list, or NULL_TREE
3832 if not found. If the attribute appears more than once, this only
3833 returns the first occurrence; the TREE_CHAIN of the return value should
3834 be passed back in if further occurrences are wanted. */
3837 lookup_attribute (const char *attr_name, tree list)
3840 size_t attr_len = strlen (attr_name);
3842 for (l = list; l; l = TREE_CHAIN (l))
3844 gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE);
3845 if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l)))
3851 /* Remove any instances of attribute ATTR_NAME in LIST and return the
3855 remove_attribute (const char *attr_name, tree list)
3858 size_t attr_len = strlen (attr_name);
3860 for (p = &list; *p; )
3863 gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE);
3864 if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l)))
3865 *p = TREE_CHAIN (l);
3867 p = &TREE_CHAIN (l);
3873 /* Return an attribute list that is the union of a1 and a2. */
3876 merge_attributes (tree a1, tree a2)
3880 /* Either one unset? Take the set one. */
3882 if ((attributes = a1) == 0)
3885 /* One that completely contains the other? Take it. */
3887 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
3889 if (attribute_list_contained (a2, a1))
3893 /* Pick the longest list, and hang on the other list. */
3895 if (list_length (a1) < list_length (a2))
3896 attributes = a2, a2 = a1;
3898 for (; a2 != 0; a2 = TREE_CHAIN (a2))
3901 for (a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3904 a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3907 if (TREE_VALUE (a) != NULL
3908 && TREE_CODE (TREE_VALUE (a)) == TREE_LIST
3909 && TREE_VALUE (a2) != NULL
3910 && TREE_CODE (TREE_VALUE (a2)) == TREE_LIST)
3912 if (simple_cst_list_equal (TREE_VALUE (a),
3913 TREE_VALUE (a2)) == 1)
3916 else if (simple_cst_equal (TREE_VALUE (a),
3917 TREE_VALUE (a2)) == 1)
3922 a1 = copy_node (a2);
3923 TREE_CHAIN (a1) = attributes;
3932 /* Given types T1 and T2, merge their attributes and return
3936 merge_type_attributes (tree t1, tree t2)
3938 return merge_attributes (TYPE_ATTRIBUTES (t1),
3939 TYPE_ATTRIBUTES (t2));
3942 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
3946 merge_decl_attributes (tree olddecl, tree newdecl)
3948 return merge_attributes (DECL_ATTRIBUTES (olddecl),
3949 DECL_ATTRIBUTES (newdecl));
3952 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
3954 /* Specialization of merge_decl_attributes for various Windows targets.
3956 This handles the following situation:
3958 __declspec (dllimport) int foo;
3961 The second instance of `foo' nullifies the dllimport. */
3964 merge_dllimport_decl_attributes (tree old, tree new_tree)
3967 int delete_dllimport_p = 1;
3969 /* What we need to do here is remove from `old' dllimport if it doesn't
3970 appear in `new'. dllimport behaves like extern: if a declaration is
3971 marked dllimport and a definition appears later, then the object
3972 is not dllimport'd. We also remove a `new' dllimport if the old list
3973 contains dllexport: dllexport always overrides dllimport, regardless
3974 of the order of declaration. */
3975 if (!VAR_OR_FUNCTION_DECL_P (new_tree))
3976 delete_dllimport_p = 0;
3977 else if (DECL_DLLIMPORT_P (new_tree)
3978 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old)))
3980 DECL_DLLIMPORT_P (new_tree) = 0;
3981 warning (OPT_Wattributes, "%q+D already declared with dllexport attribute: "
3982 "dllimport ignored", new_tree);
3984 else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new_tree))
3986 /* Warn about overriding a symbol that has already been used, e.g.:
3987 extern int __attribute__ ((dllimport)) foo;
3988 int* bar () {return &foo;}
3991 if (TREE_USED (old))
3993 warning (0, "%q+D redeclared without dllimport attribute "
3994 "after being referenced with dll linkage", new_tree);
3995 /* If we have used a variable's address with dllimport linkage,
3996 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
3997 decl may already have had TREE_CONSTANT computed.
3998 We still remove the attribute so that assembler code refers
3999 to '&foo rather than '_imp__foo'. */
4000 if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old))
4001 DECL_DLLIMPORT_P (new_tree) = 1;
4004 /* Let an inline definition silently override the external reference,
4005 but otherwise warn about attribute inconsistency. */
4006 else if (TREE_CODE (new_tree) == VAR_DECL
4007 || !DECL_DECLARED_INLINE_P (new_tree))
4008 warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: "
4009 "previous dllimport ignored", new_tree);
4012 delete_dllimport_p = 0;
4014 a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new_tree));
4016 if (delete_dllimport_p)
4019 const size_t attr_len = strlen ("dllimport");
4021 /* Scan the list for dllimport and delete it. */
4022 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
4024 if (is_attribute_with_length_p ("dllimport", attr_len,
4027 if (prev == NULL_TREE)
4030 TREE_CHAIN (prev) = TREE_CHAIN (t);
4039 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
4040 struct attribute_spec.handler. */
4043 handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
4048 /* These attributes may apply to structure and union types being created,
4049 but otherwise should pass to the declaration involved. */
4052 if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
4053 | (int) ATTR_FLAG_ARRAY_NEXT))
4055 *no_add_attrs = true;
4056 return tree_cons (name, args, NULL_TREE);
4058 if (TREE_CODE (node) == RECORD_TYPE
4059 || TREE_CODE (node) == UNION_TYPE)
4061 node = TYPE_NAME (node);
4067 warning (OPT_Wattributes, "%qs attribute ignored",
4068 IDENTIFIER_POINTER (name));
4069 *no_add_attrs = true;
4074 if (TREE_CODE (node) != FUNCTION_DECL
4075 && TREE_CODE (node) != VAR_DECL
4076 && TREE_CODE (node) != TYPE_DECL)
4078 *no_add_attrs = true;
4079 warning (OPT_Wattributes, "%qs attribute ignored",
4080 IDENTIFIER_POINTER (name));
4084 if (TREE_CODE (node) == TYPE_DECL
4085 && TREE_CODE (TREE_TYPE (node)) != RECORD_TYPE
4086 && TREE_CODE (TREE_TYPE (node)) != UNION_TYPE)
4088 *no_add_attrs = true;
4089 warning (OPT_Wattributes, "%qs attribute ignored",
4090 IDENTIFIER_POINTER (name));
4094 /* Report error on dllimport ambiguities seen now before they cause
4096 else if (is_attribute_p ("dllimport", name))
4098 /* Honor any target-specific overrides. */
4099 if (!targetm.valid_dllimport_attribute_p (node))
4100 *no_add_attrs = true;
4102 else if (TREE_CODE (node) == FUNCTION_DECL
4103 && DECL_DECLARED_INLINE_P (node))
4105 warning (OPT_Wattributes, "inline function %q+D declared as "
4106 " dllimport: attribute ignored", node);
4107 *no_add_attrs = true;
4109 /* Like MS, treat definition of dllimported variables and
4110 non-inlined functions on declaration as syntax errors. */
4111 else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node))
4113 error ("function %q+D definition is marked dllimport", node);
4114 *no_add_attrs = true;
4117 else if (TREE_CODE (node) == VAR_DECL)
4119 if (DECL_INITIAL (node))
4121 error ("variable %q+D definition is marked dllimport",
4123 *no_add_attrs = true;
4126 /* `extern' needn't be specified with dllimport.
4127 Specify `extern' now and hope for the best. Sigh. */
4128 DECL_EXTERNAL (node) = 1;
4129 /* Also, implicitly give dllimport'd variables declared within
4130 a function global scope, unless declared static. */
4131 if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
4132 TREE_PUBLIC (node) = 1;
4135 if (*no_add_attrs == false)
4136 DECL_DLLIMPORT_P (node) = 1;
4139 /* Report error if symbol is not accessible at global scope. */
4140 if (!TREE_PUBLIC (node)
4141 && (TREE_CODE (node) == VAR_DECL
4142 || TREE_CODE (node) == FUNCTION_DECL))
4144 error ("external linkage required for symbol %q+D because of "
4145 "%qs attribute", node, IDENTIFIER_POINTER (name));
4146 *no_add_attrs = true;
4149 /* A dllexport'd entity must have default visibility so that other
4150 program units (shared libraries or the main executable) can see
4151 it. A dllimport'd entity must have default visibility so that
4152 the linker knows that undefined references within this program
4153 unit can be resolved by the dynamic linker. */
4156 if (DECL_VISIBILITY_SPECIFIED (node)
4157 && DECL_VISIBILITY (node) != VISIBILITY_DEFAULT)
4158 error ("%qs implies default visibility, but %qD has already "
4159 "been declared with a different visibility",
4160 IDENTIFIER_POINTER (name), node);
4161 DECL_VISIBILITY (node) = VISIBILITY_DEFAULT;
4162 DECL_VISIBILITY_SPECIFIED (node) = 1;
4168 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
4170 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
4171 of the various TYPE_QUAL values. */
4174 set_type_quals (tree type, int type_quals)
4176 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
4177 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
4178 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
4181 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
4184 check_qualified_type (const_tree cand, const_tree base, int type_quals)
4186 return (TYPE_QUALS (cand) == type_quals
4187 && TYPE_NAME (cand) == TYPE_NAME (base)
4188 /* Apparently this is needed for Objective-C. */
4189 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
4190 && attribute_list_equal (TYPE_ATTRIBUTES (cand),
4191 TYPE_ATTRIBUTES (base)));
4194 /* Return a version of the TYPE, qualified as indicated by the
4195 TYPE_QUALS, if one exists. If no qualified version exists yet,
4196 return NULL_TREE. */
4199 get_qualified_type (tree type, int type_quals)
4203 if (TYPE_QUALS (type) == type_quals)
4206 /* Search the chain of variants to see if there is already one there just
4207 like the one we need to have. If so, use that existing one. We must
4208 preserve the TYPE_NAME, since there is code that depends on this. */
4209 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
4210 if (check_qualified_type (t, type, type_quals))
4216 /* Like get_qualified_type, but creates the type if it does not
4217 exist. This function never returns NULL_TREE. */
4220 build_qualified_type (tree type, int type_quals)
4224 /* See if we already have the appropriate qualified variant. */
4225 t = get_qualified_type (type, type_quals);
4227 /* If not, build it. */
4230 t = build_variant_type_copy (type);
4231 set_type_quals (t, type_quals);
4233 if (TYPE_STRUCTURAL_EQUALITY_P (type))
4234 /* Propagate structural equality. */
4235 SET_TYPE_STRUCTURAL_EQUALITY (t);
4236 else if (TYPE_CANONICAL (type) != type)
4237 /* Build the underlying canonical type, since it is different
4239 TYPE_CANONICAL (t) = build_qualified_type (TYPE_CANONICAL (type),
4242 /* T is its own canonical type. */
4243 TYPE_CANONICAL (t) = t;
4250 /* Create a new distinct copy of TYPE. The new type is made its own
4251 MAIN_VARIANT. If TYPE requires structural equality checks, the
4252 resulting type requires structural equality checks; otherwise, its
4253 TYPE_CANONICAL points to itself. */
4256 build_distinct_type_copy (tree type)
4258 tree t = copy_node (type);
4260 TYPE_POINTER_TO (t) = 0;
4261 TYPE_REFERENCE_TO (t) = 0;
4263 /* Set the canonical type either to a new equivalence class, or
4264 propagate the need for structural equality checks. */
4265 if (TYPE_STRUCTURAL_EQUALITY_P (type))
4266 SET_TYPE_STRUCTURAL_EQUALITY (t);
4268 TYPE_CANONICAL (t) = t;
4270 /* Make it its own variant. */
4271 TYPE_MAIN_VARIANT (t) = t;
4272 TYPE_NEXT_VARIANT (t) = 0;
4274 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
4275 whose TREE_TYPE is not t. This can also happen in the Ada
4276 frontend when using subtypes. */
4281 /* Create a new variant of TYPE, equivalent but distinct. This is so
4282 the caller can modify it. TYPE_CANONICAL for the return type will
4283 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
4284 are considered equal by the language itself (or that both types
4285 require structural equality checks). */
4288 build_variant_type_copy (tree type)
4290 tree t, m = TYPE_MAIN_VARIANT (type);
4292 t = build_distinct_type_copy (type);
4294 /* Since we're building a variant, assume that it is a non-semantic
4295 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
4296 TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
4298 /* Add the new type to the chain of variants of TYPE. */
4299 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
4300 TYPE_NEXT_VARIANT (m) = t;
4301 TYPE_MAIN_VARIANT (t) = m;
4306 /* Return true if the from tree in both tree maps are equal. */
4309 tree_map_base_eq (const void *va, const void *vb)
4311 const struct tree_map_base *const a = (const struct tree_map_base *) va,
4312 *const b = (const struct tree_map_base *) vb;
4313 return (a->from == b->from);
4316 /* Hash a from tree in a tree_map. */
4319 tree_map_base_hash (const void *item)
4321 return htab_hash_pointer (((const struct tree_map_base *)item)->from);
4324 /* Return true if this tree map structure is marked for garbage collection
4325 purposes. We simply return true if the from tree is marked, so that this
4326 structure goes away when the from tree goes away. */
4329 tree_map_base_marked_p (const void *p)
4331 return ggc_marked_p (((const struct tree_map_base *) p)->from);
4335 tree_map_hash (const void *item)
4337 return (((const struct tree_map *) item)->hash);
4340 /* Return the initialization priority for DECL. */
4343 decl_init_priority_lookup (tree decl)
4345 struct tree_priority_map *h;
4346 struct tree_map_base in;
4348 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
4350 h = (struct tree_priority_map *) htab_find (init_priority_for_decl, &in);
4351 return h ? h->init : DEFAULT_INIT_PRIORITY;
4354 /* Return the finalization priority for DECL. */
4357 decl_fini_priority_lookup (tree decl)
4359 struct tree_priority_map *h;
4360 struct tree_map_base in;
4362 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
4364 h = (struct tree_priority_map *) htab_find (init_priority_for_decl, &in);
4365 return h ? h->fini : DEFAULT_INIT_PRIORITY;
4368 /* Return the initialization and finalization priority information for
4369 DECL. If there is no previous priority information, a freshly
4370 allocated structure is returned. */
4372 static struct tree_priority_map *
4373 decl_priority_info (tree decl)
4375 struct tree_priority_map in;
4376 struct tree_priority_map *h;
4379 in.base.from = decl;
4380 loc = htab_find_slot (init_priority_for_decl, &in, INSERT);
4381 h = (struct tree_priority_map *) *loc;
4384 h = GGC_CNEW (struct tree_priority_map);
4386 h->base.from = decl;
4387 h->init = DEFAULT_INIT_PRIORITY;
4388 h->fini = DEFAULT_INIT_PRIORITY;
4394 /* Set the initialization priority for DECL to PRIORITY. */
4397 decl_init_priority_insert (tree decl, priority_type priority)
4399 struct tree_priority_map *h;
4401 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
4402 h = decl_priority_info (decl);
4406 /* Set the finalization priority for DECL to PRIORITY. */
4409 decl_fini_priority_insert (tree decl, priority_type priority)
4411 struct tree_priority_map *h;
4413 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
4414 h = decl_priority_info (decl);
4418 /* Look up a restrict qualified base decl for FROM. */
4421 decl_restrict_base_lookup (tree from)
4426 in.base.from = from;
4427 h = (struct tree_map *) htab_find_with_hash (restrict_base_for_decl, &in,
4428 htab_hash_pointer (from));
4429 return h ? h->to : NULL_TREE;
4432 /* Record the restrict qualified base TO for FROM. */
4435 decl_restrict_base_insert (tree from, tree to)
4440 h = GGC_NEW (struct tree_map);
4441 h->hash = htab_hash_pointer (from);
4442 h->base.from = from;
4444 loc = htab_find_slot_with_hash (restrict_base_for_decl, h, h->hash, INSERT);
4445 *(struct tree_map **) loc = h;
4448 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
4451 print_debug_expr_statistics (void)
4453 fprintf (stderr, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
4454 (long) htab_size (debug_expr_for_decl),
4455 (long) htab_elements (debug_expr_for_decl),
4456 htab_collisions (debug_expr_for_decl));
4459 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
4462 print_value_expr_statistics (void)
4464 fprintf (stderr, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
4465 (long) htab_size (value_expr_for_decl),
4466 (long) htab_elements (value_expr_for_decl),
4467 htab_collisions (value_expr_for_decl));
4470 /* Print out statistics for the RESTRICT_BASE_FOR_DECL hash table, but
4471 don't print anything if the table is empty. */
4474 print_restrict_base_statistics (void)
4476 if (htab_elements (restrict_base_for_decl) != 0)
4478 "RESTRICT_BASE hash: size %ld, %ld elements, %f collisions\n",
4479 (long) htab_size (restrict_base_for_decl),
4480 (long) htab_elements (restrict_base_for_decl),
4481 htab_collisions (restrict_base_for_decl));
4484 /* Lookup a debug expression for FROM, and return it if we find one. */
4487 decl_debug_expr_lookup (tree from)
4489 struct tree_map *h, in;
4490 in.base.from = from;
4492 h = (struct tree_map *) htab_find_with_hash (debug_expr_for_decl, &in,
4493 htab_hash_pointer (from));
4499 /* Insert a mapping FROM->TO in the debug expression hashtable. */
4502 decl_debug_expr_insert (tree from, tree to)
4507 h = GGC_NEW (struct tree_map);
4508 h->hash = htab_hash_pointer (from);
4509 h->base.from = from;
4511 loc = htab_find_slot_with_hash (debug_expr_for_decl, h, h->hash, INSERT);
4512 *(struct tree_map **) loc = h;
4515 /* Lookup a value expression for FROM, and return it if we find one. */
4518 decl_value_expr_lookup (tree from)
4520 struct tree_map *h, in;
4521 in.base.from = from;
4523 h = (struct tree_map *) htab_find_with_hash (value_expr_for_decl, &in,
4524 htab_hash_pointer (from));
4530 /* Insert a mapping FROM->TO in the value expression hashtable. */
4533 decl_value_expr_insert (tree from, tree to)
4538 h = GGC_NEW (struct tree_map);
4539 h->hash = htab_hash_pointer (from);
4540 h->base.from = from;
4542 loc = htab_find_slot_with_hash (value_expr_for_decl, h, h->hash, INSERT);
4543 *(struct tree_map **) loc = h;
4546 /* Hashing of types so that we don't make duplicates.
4547 The entry point is `type_hash_canon'. */
4549 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
4550 with types in the TREE_VALUE slots), by adding the hash codes
4551 of the individual types. */
4554 type_hash_list (const_tree list, hashval_t hashcode)
4558 for (tail = list; tail; tail = TREE_CHAIN (tail))
4559 if (TREE_VALUE (tail) != error_mark_node)
4560 hashcode = iterative_hash_object (TYPE_HASH (TREE_VALUE (tail)),
4566 /* These are the Hashtable callback functions. */
4568 /* Returns true iff the types are equivalent. */
4571 type_hash_eq (const void *va, const void *vb)
4573 const struct type_hash *const a = (const struct type_hash *) va,
4574 *const b = (const struct type_hash *) vb;
4576 /* First test the things that are the same for all types. */
4577 if (a->hash != b->hash
4578 || TREE_CODE (a->type) != TREE_CODE (b->type)
4579 || TREE_TYPE (a->type) != TREE_TYPE (b->type)
4580 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
4581 TYPE_ATTRIBUTES (b->type))
4582 || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
4583 || TYPE_MODE (a->type) != TYPE_MODE (b->type)
4584 || (TREE_CODE (a->type) != COMPLEX_TYPE
4585 && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
4588 switch (TREE_CODE (a->type))
4593 case REFERENCE_TYPE:
4597 return TYPE_VECTOR_SUBPARTS (a->type) == TYPE_VECTOR_SUBPARTS (b->type);
4600 if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
4601 && !(TYPE_VALUES (a->type)
4602 && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
4603 && TYPE_VALUES (b->type)
4604 && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
4605 && type_list_equal (TYPE_VALUES (a->type),
4606 TYPE_VALUES (b->type))))
4609 /* ... fall through ... */
4614 return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
4615 || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
4616 TYPE_MAX_VALUE (b->type)))
4617 && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
4618 || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
4619 TYPE_MIN_VALUE (b->type))));
4621 case FIXED_POINT_TYPE:
4622 return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
4625 return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
4628 return (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
4629 && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
4630 || (TYPE_ARG_TYPES (a->type)
4631 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
4632 && TYPE_ARG_TYPES (b->type)
4633 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
4634 && type_list_equal (TYPE_ARG_TYPES (a->type),
4635 TYPE_ARG_TYPES (b->type)))));
4638 return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type);
4642 case QUAL_UNION_TYPE:
4643 return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
4644 || (TYPE_FIELDS (a->type)
4645 && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
4646 && TYPE_FIELDS (b->type)
4647 && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
4648 && type_list_equal (TYPE_FIELDS (a->type),
4649 TYPE_FIELDS (b->type))));
4652 if (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
4653 || (TYPE_ARG_TYPES (a->type)
4654 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
4655 && TYPE_ARG_TYPES (b->type)
4656 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
4657 && type_list_equal (TYPE_ARG_TYPES (a->type),
4658 TYPE_ARG_TYPES (b->type))))
4666 if (lang_hooks.types.type_hash_eq != NULL)
4667 return lang_hooks.types.type_hash_eq (a->type, b->type);
4672 /* Return the cached hash value. */
4675 type_hash_hash (const void *item)
4677 return ((const struct type_hash *) item)->hash;
4680 /* Look in the type hash table for a type isomorphic to TYPE.
4681 If one is found, return it. Otherwise return 0. */
4684 type_hash_lookup (hashval_t hashcode, tree type)
4686 struct type_hash *h, in;
4688 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
4689 must call that routine before comparing TYPE_ALIGNs. */
4695 h = (struct type_hash *) htab_find_with_hash (type_hash_table, &in,
4702 /* Add an entry to the type-hash-table
4703 for a type TYPE whose hash code is HASHCODE. */
4706 type_hash_add (hashval_t hashcode, tree type)
4708 struct type_hash *h;
4711 h = GGC_NEW (struct type_hash);
4714 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
4718 /* Given TYPE, and HASHCODE its hash code, return the canonical
4719 object for an identical type if one already exists.
4720 Otherwise, return TYPE, and record it as the canonical object.
4722 To use this function, first create a type of the sort you want.
4723 Then compute its hash code from the fields of the type that
4724 make it different from other similar types.
4725 Then call this function and use the value. */
4728 type_hash_canon (unsigned int hashcode, tree type)
4732 /* The hash table only contains main variants, so ensure that's what we're
4734 gcc_assert (TYPE_MAIN_VARIANT (type) == type);
4736 if (!lang_hooks.types.hash_types)
4739 /* See if the type is in the hash table already. If so, return it.
4740 Otherwise, add the type. */
4741 t1 = type_hash_lookup (hashcode, type);
4744 #ifdef GATHER_STATISTICS
4745 tree_node_counts[(int) t_kind]--;
4746 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
4752 type_hash_add (hashcode, type);
4757 /* See if the data pointed to by the type hash table is marked. We consider
4758 it marked if the type is marked or if a debug type number or symbol
4759 table entry has been made for the type. This reduces the amount of
4760 debugging output and eliminates that dependency of the debug output on
4761 the number of garbage collections. */
4764 type_hash_marked_p (const void *p)
4766 const_tree const type = ((const struct type_hash *) p)->type;
4768 return ggc_marked_p (type) || TYPE_SYMTAB_POINTER (type);
4772 print_type_hash_statistics (void)
4774 fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
4775 (long) htab_size (type_hash_table),
4776 (long) htab_elements (type_hash_table),
4777 htab_collisions (type_hash_table));
4780 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
4781 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
4782 by adding the hash codes of the individual attributes. */
4785 attribute_hash_list (const_tree list, hashval_t hashcode)
4789 for (tail = list; tail; tail = TREE_CHAIN (tail))
4790 /* ??? Do we want to add in TREE_VALUE too? */
4791 hashcode = iterative_hash_object
4792 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail)), hashcode);
4796 /* Given two lists of attributes, return true if list l2 is
4797 equivalent to l1. */
4800 attribute_list_equal (const_tree l1, const_tree l2)
4802 return attribute_list_contained (l1, l2)
4803 && attribute_list_contained (l2, l1);
4806 /* Given two lists of attributes, return true if list L2 is
4807 completely contained within L1. */
4808 /* ??? This would be faster if attribute names were stored in a canonicalized
4809 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
4810 must be used to show these elements are equivalent (which they are). */
4811 /* ??? It's not clear that attributes with arguments will always be handled
4815 attribute_list_contained (const_tree l1, const_tree l2)
4819 /* First check the obvious, maybe the lists are identical. */
4823 /* Maybe the lists are similar. */
4824 for (t1 = l1, t2 = l2;
4826 && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
4827 && TREE_VALUE (t1) == TREE_VALUE (t2);
4828 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
4830 /* Maybe the lists are equal. */
4831 if (t1 == 0 && t2 == 0)
4834 for (; t2 != 0; t2 = TREE_CHAIN (t2))
4837 /* This CONST_CAST is okay because lookup_attribute does not
4838 modify its argument and the return value is assigned to a
4840 for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
4841 CONST_CAST_TREE(l1));
4843 attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
4846 if (TREE_VALUE (t2) != NULL
4847 && TREE_CODE (TREE_VALUE (t2)) == TREE_LIST
4848 && TREE_VALUE (attr) != NULL
4849 && TREE_CODE (TREE_VALUE (attr)) == TREE_LIST)
4851 if (simple_cst_list_equal (TREE_VALUE (t2),
4852 TREE_VALUE (attr)) == 1)
4855 else if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) == 1)
4866 /* Given two lists of types
4867 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
4868 return 1 if the lists contain the same types in the same order.
4869 Also, the TREE_PURPOSEs must match. */
4872 type_list_equal (const_tree l1, const_tree l2)
4876 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
4877 if (TREE_VALUE (t1) != TREE_VALUE (t2)
4878 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
4879 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
4880 && (TREE_TYPE (TREE_PURPOSE (t1))
4881 == TREE_TYPE (TREE_PURPOSE (t2))))))
4887 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
4888 given by TYPE. If the argument list accepts variable arguments,
4889 then this function counts only the ordinary arguments. */
4892 type_num_arguments (const_tree type)
4897 for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
4898 /* If the function does not take a variable number of arguments,
4899 the last element in the list will have type `void'. */
4900 if (VOID_TYPE_P (TREE_VALUE (t)))
4908 /* Nonzero if integer constants T1 and T2
4909 represent the same constant value. */
4912 tree_int_cst_equal (const_tree t1, const_tree t2)
4917 if (t1 == 0 || t2 == 0)
4920 if (TREE_CODE (t1) == INTEGER_CST
4921 && TREE_CODE (t2) == INTEGER_CST
4922 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
4923 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
4929 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
4930 The precise way of comparison depends on their data type. */
4933 tree_int_cst_lt (const_tree t1, const_tree t2)
4938 if (TYPE_UNSIGNED (TREE_TYPE (t1)) != TYPE_UNSIGNED (TREE_TYPE (t2)))
4940 int t1_sgn = tree_int_cst_sgn (t1);
4941 int t2_sgn = tree_int_cst_sgn (t2);
4943 if (t1_sgn < t2_sgn)
4945 else if (t1_sgn > t2_sgn)
4947 /* Otherwise, both are non-negative, so we compare them as
4948 unsigned just in case one of them would overflow a signed
4951 else if (!TYPE_UNSIGNED (TREE_TYPE (t1)))
4952 return INT_CST_LT (t1, t2);
4954 return INT_CST_LT_UNSIGNED (t1, t2);
4957 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
4960 tree_int_cst_compare (const_tree t1, const_tree t2)
4962 if (tree_int_cst_lt (t1, t2))
4964 else if (tree_int_cst_lt (t2, t1))
4970 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
4971 the host. If POS is zero, the value can be represented in a single
4972 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
4973 be represented in a single unsigned HOST_WIDE_INT. */
4976 host_integerp (const_tree t, int pos)
4978 return (TREE_CODE (t) == INTEGER_CST
4979 && ((TREE_INT_CST_HIGH (t) == 0
4980 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
4981 || (! pos && TREE_INT_CST_HIGH (t) == -1
4982 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
4983 && (!TYPE_UNSIGNED (TREE_TYPE (t))
4984 || (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE
4985 && TYPE_IS_SIZETYPE (TREE_TYPE (t)))))
4986 || (pos && TREE_INT_CST_HIGH (t) == 0)));
4989 /* Return the HOST_WIDE_INT least significant bits of T if it is an
4990 INTEGER_CST and there is no overflow. POS is nonzero if the result must
4991 be non-negative. We must be able to satisfy the above conditions. */
4994 tree_low_cst (const_tree t, int pos)
4996 gcc_assert (host_integerp (t, pos));
4997 return TREE_INT_CST_LOW (t);
5000 /* Return the most significant bit of the integer constant T. */
5003 tree_int_cst_msb (const_tree t)
5007 unsigned HOST_WIDE_INT l;
5009 /* Note that using TYPE_PRECISION here is wrong. We care about the
5010 actual bits, not the (arbitrary) range of the type. */
5011 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
5012 rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
5013 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
5014 return (l & 1) == 1;
5017 /* Return an indication of the sign of the integer constant T.
5018 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
5019 Note that -1 will never be returned if T's type is unsigned. */
5022 tree_int_cst_sgn (const_tree t)
5024 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
5026 else if (TYPE_UNSIGNED (TREE_TYPE (t)))
5028 else if (TREE_INT_CST_HIGH (t) < 0)
5034 /* Return the minimum number of bits needed to represent VALUE in a
5035 signed or unsigned type, UNSIGNEDP says which. */
5038 tree_int_cst_min_precision (tree value, bool unsignedp)
5042 /* If the value is negative, compute its negative minus 1. The latter
5043 adjustment is because the absolute value of the largest negative value
5044 is one larger than the largest positive value. This is equivalent to
5045 a bit-wise negation, so use that operation instead. */
5047 if (tree_int_cst_sgn (value) < 0)
5048 value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value);
5050 /* Return the number of bits needed, taking into account the fact
5051 that we need one more bit for a signed than unsigned type. */
5053 if (integer_zerop (value))
5056 log = tree_floor_log2 (value);
5058 return log + 1 + !unsignedp;
5061 /* Compare two constructor-element-type constants. Return 1 if the lists
5062 are known to be equal; otherwise return 0. */
5065 simple_cst_list_equal (const_tree l1, const_tree l2)
5067 while (l1 != NULL_TREE && l2 != NULL_TREE)
5069 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
5072 l1 = TREE_CHAIN (l1);
5073 l2 = TREE_CHAIN (l2);
5079 /* Return truthvalue of whether T1 is the same tree structure as T2.
5080 Return 1 if they are the same.
5081 Return 0 if they are understandably different.
5082 Return -1 if either contains tree structure not understood by
5086 simple_cst_equal (const_tree t1, const_tree t2)
5088 enum tree_code code1, code2;
5094 if (t1 == 0 || t2 == 0)
5097 code1 = TREE_CODE (t1);
5098 code2 = TREE_CODE (t2);
5100 if (CONVERT_EXPR_CODE_P (code1) || code1 == NON_LVALUE_EXPR)
5102 if (CONVERT_EXPR_CODE_P (code2)
5103 || code2 == NON_LVALUE_EXPR)
5104 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
5106 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
5109 else if (CONVERT_EXPR_CODE_P (code2)
5110 || code2 == NON_LVALUE_EXPR)
5111 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
5119 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
5120 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
5123 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
5126 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
5129 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
5130 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
5131 TREE_STRING_LENGTH (t1)));
5135 unsigned HOST_WIDE_INT idx;
5136 VEC(constructor_elt, gc) *v1 = CONSTRUCTOR_ELTS (t1);
5137 VEC(constructor_elt, gc) *v2 = CONSTRUCTOR_ELTS (t2);
5139 if (VEC_length (constructor_elt, v1) != VEC_length (constructor_elt, v2))
5142 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
5143 /* ??? Should we handle also fields here? */
5144 if (!simple_cst_equal (VEC_index (constructor_elt, v1, idx)->value,
5145 VEC_index (constructor_elt, v2, idx)->value))
5151 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
5154 cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
5157 if (call_expr_nargs (t1) != call_expr_nargs (t2))
5160 const_tree arg1, arg2;
5161 const_call_expr_arg_iterator iter1, iter2;
5162 for (arg1 = first_const_call_expr_arg (t1, &iter1),
5163 arg2 = first_const_call_expr_arg (t2, &iter2);
5165 arg1 = next_const_call_expr_arg (&iter1),
5166 arg2 = next_const_call_expr_arg (&iter2))
5168 cmp = simple_cst_equal (arg1, arg2);
5172 return arg1 == arg2;
5176 /* Special case: if either target is an unallocated VAR_DECL,
5177 it means that it's going to be unified with whatever the
5178 TARGET_EXPR is really supposed to initialize, so treat it
5179 as being equivalent to anything. */
5180 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
5181 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
5182 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
5183 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
5184 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
5185 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
5188 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
5193 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
5195 case WITH_CLEANUP_EXPR:
5196 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
5200 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
5203 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
5204 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
5218 /* This general rule works for most tree codes. All exceptions should be
5219 handled above. If this is a language-specific tree code, we can't
5220 trust what might be in the operand, so say we don't know
5222 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
5225 switch (TREE_CODE_CLASS (code1))
5229 case tcc_comparison:
5230 case tcc_expression:
5234 for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
5236 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
5248 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
5249 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
5250 than U, respectively. */
5253 compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
5255 if (tree_int_cst_sgn (t) < 0)
5257 else if (TREE_INT_CST_HIGH (t) != 0)
5259 else if (TREE_INT_CST_LOW (t) == u)
5261 else if (TREE_INT_CST_LOW (t) < u)
5267 /* Return true if CODE represents an associative tree code. Otherwise
5270 associative_tree_code (enum tree_code code)
5289 /* Return true if CODE represents a commutative tree code. Otherwise
5292 commutative_tree_code (enum tree_code code)
5305 case UNORDERED_EXPR:
5309 case TRUTH_AND_EXPR:
5310 case TRUTH_XOR_EXPR:
5320 /* Generate a hash value for an expression. This can be used iteratively
5321 by passing a previous result as the VAL argument.
5323 This function is intended to produce the same hash for expressions which
5324 would compare equal using operand_equal_p. */
5327 iterative_hash_expr (const_tree t, hashval_t val)
5330 enum tree_code code;
5334 return iterative_hash_pointer (t, val);
5336 code = TREE_CODE (t);
5340 /* Alas, constants aren't shared, so we can't rely on pointer
5343 val = iterative_hash_host_wide_int (TREE_INT_CST_LOW (t), val);
5344 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t), val);
5347 unsigned int val2 = real_hash (TREE_REAL_CST_PTR (t));
5349 return iterative_hash_hashval_t (val2, val);
5353 unsigned int val2 = fixed_hash (TREE_FIXED_CST_PTR (t));
5355 return iterative_hash_hashval_t (val2, val);
5358 return iterative_hash (TREE_STRING_POINTER (t),
5359 TREE_STRING_LENGTH (t), val);
5361 val = iterative_hash_expr (TREE_REALPART (t), val);
5362 return iterative_hash_expr (TREE_IMAGPART (t), val);
5364 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val);
5367 /* we can just compare by pointer. */
5368 return iterative_hash_pointer (t, val);
5371 /* A list of expressions, for a CALL_EXPR or as the elements of a
5373 for (; t; t = TREE_CHAIN (t))
5374 val = iterative_hash_expr (TREE_VALUE (t), val);
5378 unsigned HOST_WIDE_INT idx;
5380 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), idx, field, value)
5382 val = iterative_hash_expr (field, val);
5383 val = iterative_hash_expr (value, val);
5388 /* When referring to a built-in FUNCTION_DECL, use the
5389 __builtin__ form. Otherwise nodes that compare equal
5390 according to operand_equal_p might get different
5392 if (DECL_BUILT_IN (t))
5394 val = iterative_hash_pointer (built_in_decls[DECL_FUNCTION_CODE (t)],
5398 /* else FALL THROUGH */
5400 tclass = TREE_CODE_CLASS (code);
5402 if (tclass == tcc_declaration)
5404 /* DECL's have a unique ID */
5405 val = iterative_hash_host_wide_int (DECL_UID (t), val);
5409 gcc_assert (IS_EXPR_CODE_CLASS (tclass));
5411 val = iterative_hash_object (code, val);
5413 /* Don't hash the type, that can lead to having nodes which
5414 compare equal according to operand_equal_p, but which
5415 have different hash codes. */
5416 if (CONVERT_EXPR_CODE_P (code)
5417 || code == NON_LVALUE_EXPR)
5419 /* Make sure to include signness in the hash computation. */
5420 val += TYPE_UNSIGNED (TREE_TYPE (t));
5421 val = iterative_hash_expr (TREE_OPERAND (t, 0), val);
5424 else if (commutative_tree_code (code))
5426 /* It's a commutative expression. We want to hash it the same
5427 however it appears. We do this by first hashing both operands
5428 and then rehashing based on the order of their independent
5430 hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0);
5431 hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0);
5435 t = one, one = two, two = t;
5437 val = iterative_hash_hashval_t (one, val);
5438 val = iterative_hash_hashval_t (two, val);
5441 for (i = TREE_OPERAND_LENGTH (t) - 1; i >= 0; --i)
5442 val = iterative_hash_expr (TREE_OPERAND (t, i), val);
5449 /* Generate a hash value for a pair of expressions. This can be used
5450 iteratively by passing a previous result as the VAL argument.
5452 The same hash value is always returned for a given pair of expressions,
5453 regardless of the order in which they are presented. This is useful in
5454 hashing the operands of commutative functions. */
5457 iterative_hash_exprs_commutative (const_tree t1,
5458 const_tree t2, hashval_t val)
5460 hashval_t one = iterative_hash_expr (t1, 0);
5461 hashval_t two = iterative_hash_expr (t2, 0);
5465 t = one, one = two, two = t;
5466 val = iterative_hash_hashval_t (one, val);
5467 val = iterative_hash_hashval_t (two, val);
5472 /* Constructors for pointer, array and function types.
5473 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
5474 constructed by language-dependent code, not here.) */
5476 /* Construct, lay out and return the type of pointers to TO_TYPE with
5477 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
5478 reference all of memory. If such a type has already been
5479 constructed, reuse it. */
5482 build_pointer_type_for_mode (tree to_type, enum machine_mode mode,
5487 if (to_type == error_mark_node)
5488 return error_mark_node;
5490 /* If the pointed-to type has the may_alias attribute set, force
5491 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
5492 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
5493 can_alias_all = true;
5495 /* In some cases, languages will have things that aren't a POINTER_TYPE
5496 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
5497 In that case, return that type without regard to the rest of our
5500 ??? This is a kludge, but consistent with the way this function has
5501 always operated and there doesn't seem to be a good way to avoid this
5503 if (TYPE_POINTER_TO (to_type) != 0
5504 && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
5505 return TYPE_POINTER_TO (to_type);
5507 /* First, if we already have a type for pointers to TO_TYPE and it's
5508 the proper mode, use it. */
5509 for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
5510 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
5513 t = make_node (POINTER_TYPE);
5515 TREE_TYPE (t) = to_type;
5516 SET_TYPE_MODE (t, mode);
5517 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
5518 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
5519 TYPE_POINTER_TO (to_type) = t;
5521 if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
5522 SET_TYPE_STRUCTURAL_EQUALITY (t);
5523 else if (TYPE_CANONICAL (to_type) != to_type)
5525 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
5526 mode, can_alias_all);
5528 /* Lay out the type. This function has many callers that are concerned
5529 with expression-construction, and this simplifies them all. */
5535 /* By default build pointers in ptr_mode. */
5538 build_pointer_type (tree to_type)
5540 return build_pointer_type_for_mode (to_type, ptr_mode, false);
5543 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
5546 build_reference_type_for_mode (tree to_type, enum machine_mode mode,
5551 if (to_type == error_mark_node)
5552 return error_mark_node;
5554 /* If the pointed-to type has the may_alias attribute set, force
5555 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
5556 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
5557 can_alias_all = true;
5559 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
5560 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
5561 In that case, return that type without regard to the rest of our
5564 ??? This is a kludge, but consistent with the way this function has
5565 always operated and there doesn't seem to be a good way to avoid this
5567 if (TYPE_REFERENCE_TO (to_type) != 0
5568 && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
5569 return TYPE_REFERENCE_TO (to_type);
5571 /* First, if we already have a type for pointers to TO_TYPE and it's
5572 the proper mode, use it. */
5573 for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
5574 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
5577 t = make_node (REFERENCE_TYPE);
5579 TREE_TYPE (t) = to_type;
5580 SET_TYPE_MODE (t, mode);
5581 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
5582 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
5583 TYPE_REFERENCE_TO (to_type) = t;
5585 if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
5586 SET_TYPE_STRUCTURAL_EQUALITY (t);
5587 else if (TYPE_CANONICAL (to_type) != to_type)
5589 = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
5590 mode, can_alias_all);
5598 /* Build the node for the type of references-to-TO_TYPE by default
5602 build_reference_type (tree to_type)
5604 return build_reference_type_for_mode (to_type, ptr_mode, false);
5607 /* Build a type that is compatible with t but has no cv quals anywhere
5610 const char *const *const * -> char ***. */
5613 build_type_no_quals (tree t)
5615 switch (TREE_CODE (t))
5618 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
5620 TYPE_REF_CAN_ALIAS_ALL (t));
5621 case REFERENCE_TYPE:
5623 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
5625 TYPE_REF_CAN_ALIAS_ALL (t));
5627 return TYPE_MAIN_VARIANT (t);
5631 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
5632 MAXVAL should be the maximum value in the domain
5633 (one less than the length of the array).
5635 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
5636 We don't enforce this limit, that is up to caller (e.g. language front end).
5637 The limit exists because the result is a signed type and we don't handle
5638 sizes that use more than one HOST_WIDE_INT. */
5641 build_index_type (tree maxval)
5643 tree itype = make_node (INTEGER_TYPE);
5645 TREE_TYPE (itype) = sizetype;
5646 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
5647 TYPE_MIN_VALUE (itype) = size_zero_node;
5648 TYPE_MAX_VALUE (itype) = fold_convert (sizetype, maxval);
5649 SET_TYPE_MODE (itype, TYPE_MODE (sizetype));
5650 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
5651 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
5652 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
5653 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
5655 if (host_integerp (maxval, 1))
5656 return type_hash_canon (tree_low_cst (maxval, 1), itype);
5659 /* Since we cannot hash this type, we need to compare it using
5660 structural equality checks. */
5661 SET_TYPE_STRUCTURAL_EQUALITY (itype);
5666 /* Builds a signed or unsigned integer type of precision PRECISION.
5667 Used for C bitfields whose precision does not match that of
5668 built-in target types. */
5670 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
5673 tree itype = make_node (INTEGER_TYPE);
5675 TYPE_PRECISION (itype) = precision;
5678 fixup_unsigned_type (itype);
5680 fixup_signed_type (itype);
5682 if (host_integerp (TYPE_MAX_VALUE (itype), 1))
5683 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype);
5688 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
5689 ENUMERAL_TYPE or BOOLEAN_TYPE), with low bound LOWVAL and
5690 high bound HIGHVAL. If TYPE is NULL, sizetype is used. */
5693 build_range_type (tree type, tree lowval, tree highval)
5695 tree itype = make_node (INTEGER_TYPE);
5697 TREE_TYPE (itype) = type;
5698 if (type == NULL_TREE)
5701 TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
5702 TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
5704 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
5705 SET_TYPE_MODE (itype, TYPE_MODE (type));
5706 TYPE_SIZE (itype) = TYPE_SIZE (type);
5707 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
5708 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
5709 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
5711 if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
5712 return type_hash_canon (tree_low_cst (highval, 0)
5713 - tree_low_cst (lowval, 0),
5719 /* Just like build_index_type, but takes lowval and highval instead
5720 of just highval (maxval). */
5723 build_index_2_type (tree lowval, tree highval)
5725 return build_range_type (sizetype, lowval, highval);
5728 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
5729 and number of elements specified by the range of values of INDEX_TYPE.
5730 If such a type has already been constructed, reuse it. */
5733 build_array_type (tree elt_type, tree index_type)
5736 hashval_t hashcode = 0;
5738 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
5740 error ("arrays of functions are not meaningful");
5741 elt_type = integer_type_node;
5744 t = make_node (ARRAY_TYPE);
5745 TREE_TYPE (t) = elt_type;
5746 TYPE_DOMAIN (t) = index_type;
5748 if (index_type == 0)
5751 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
5752 t = type_hash_canon (hashcode, t);
5756 if (TYPE_CANONICAL (t) == t)
5758 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type))
5759 SET_TYPE_STRUCTURAL_EQUALITY (t);
5760 else if (TYPE_CANONICAL (elt_type) != elt_type)
5762 = build_array_type (TYPE_CANONICAL (elt_type), index_type);
5768 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
5769 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
5770 t = type_hash_canon (hashcode, t);
5772 if (!COMPLETE_TYPE_P (t))
5775 if (TYPE_CANONICAL (t) == t)
5777 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
5778 || TYPE_STRUCTURAL_EQUALITY_P (index_type))
5779 SET_TYPE_STRUCTURAL_EQUALITY (t);
5780 else if (TYPE_CANONICAL (elt_type) != elt_type
5781 || TYPE_CANONICAL (index_type) != index_type)
5783 = build_array_type (TYPE_CANONICAL (elt_type),
5784 TYPE_CANONICAL (index_type));
5790 /* Recursively examines the array elements of TYPE, until a non-array
5791 element type is found. */
5794 strip_array_types (tree type)
5796 while (TREE_CODE (type) == ARRAY_TYPE)
5797 type = TREE_TYPE (type);
5802 /* Computes the canonical argument types from the argument type list
5805 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
5806 on entry to this function, or if any of the ARGTYPES are
5809 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
5810 true on entry to this function, or if any of the ARGTYPES are
5813 Returns a canonical argument list, which may be ARGTYPES when the
5814 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
5815 true) or would not differ from ARGTYPES. */
5818 maybe_canonicalize_argtypes(tree argtypes,
5819 bool *any_structural_p,
5820 bool *any_noncanonical_p)
5823 bool any_noncanonical_argtypes_p = false;
5825 for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
5827 if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
5828 /* Fail gracefully by stating that the type is structural. */
5829 *any_structural_p = true;
5830 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
5831 *any_structural_p = true;
5832 else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
5833 || TREE_PURPOSE (arg))
5834 /* If the argument has a default argument, we consider it
5835 non-canonical even though the type itself is canonical.
5836 That way, different variants of function and method types
5837 with default arguments will all point to the variant with
5838 no defaults as their canonical type. */
5839 any_noncanonical_argtypes_p = true;
5842 if (*any_structural_p)
5845 if (any_noncanonical_argtypes_p)
5847 /* Build the canonical list of argument types. */
5848 tree canon_argtypes = NULL_TREE;
5849 bool is_void = false;
5851 for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
5853 if (arg == void_list_node)
5856 canon_argtypes = tree_cons (NULL_TREE,
5857 TYPE_CANONICAL (TREE_VALUE (arg)),
5861 canon_argtypes = nreverse (canon_argtypes);
5863 canon_argtypes = chainon (canon_argtypes, void_list_node);
5865 /* There is a non-canonical type. */
5866 *any_noncanonical_p = true;
5867 return canon_argtypes;
5870 /* The canonical argument types are the same as ARGTYPES. */
5874 /* Construct, lay out and return
5875 the type of functions returning type VALUE_TYPE
5876 given arguments of types ARG_TYPES.
5877 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
5878 are data type nodes for the arguments of the function.
5879 If such a type has already been constructed, reuse it. */
5882 build_function_type (tree value_type, tree arg_types)
5885 hashval_t hashcode = 0;
5886 bool any_structural_p, any_noncanonical_p;
5887 tree canon_argtypes;
5889 if (TREE_CODE (value_type) == FUNCTION_TYPE)
5891 error ("function return type cannot be function");
5892 value_type = integer_type_node;
5895 /* Make a node of the sort we want. */
5896 t = make_node (FUNCTION_TYPE);
5897 TREE_TYPE (t) = value_type;
5898 TYPE_ARG_TYPES (t) = arg_types;
5900 /* If we already have such a type, use the old one. */
5901 hashcode = iterative_hash_object (TYPE_HASH (value_type), hashcode);
5902 hashcode = type_hash_list (arg_types, hashcode);
5903 t = type_hash_canon (hashcode, t);
5905 /* Set up the canonical type. */
5906 any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
5907 any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
5908 canon_argtypes = maybe_canonicalize_argtypes (arg_types,
5910 &any_noncanonical_p);
5911 if (any_structural_p)
5912 SET_TYPE_STRUCTURAL_EQUALITY (t);
5913 else if (any_noncanonical_p)
5914 TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
5917 if (!COMPLETE_TYPE_P (t))
5922 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP. */
5925 build_function_type_skip_args (tree orig_type, bitmap args_to_skip)
5927 tree new_type = NULL;
5928 tree args, new_args = NULL, t;
5932 for (args = TYPE_ARG_TYPES (orig_type); args && args != void_list_node;
5933 args = TREE_CHAIN (args), i++)
5934 if (!bitmap_bit_p (args_to_skip, i))
5935 new_args = tree_cons (NULL_TREE, TREE_VALUE (args), new_args);
5937 new_reversed = nreverse (new_args);
5941 TREE_CHAIN (new_args) = void_list_node;
5943 new_reversed = void_list_node;
5945 gcc_assert (new_reversed);
5947 /* Use copy_node to preserve as much as possible from original type
5948 (debug info, attribute lists etc.)
5949 Exception is METHOD_TYPEs must have THIS argument.
5950 When we are asked to remove it, we need to build new FUNCTION_TYPE
5952 if (TREE_CODE (orig_type) != METHOD_TYPE
5953 || !bitmap_bit_p (args_to_skip, 0))
5955 new_type = copy_node (orig_type);
5956 TYPE_ARG_TYPES (new_type) = new_reversed;
5961 = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type),
5963 TYPE_CONTEXT (new_type) = TYPE_CONTEXT (orig_type);
5966 /* This is a new type, not a copy of an old type. Need to reassociate
5967 variants. We can handle everything except the main variant lazily. */
5968 t = TYPE_MAIN_VARIANT (orig_type);
5971 TYPE_MAIN_VARIANT (new_type) = t;
5972 TYPE_NEXT_VARIANT (new_type) = TYPE_NEXT_VARIANT (t);
5973 TYPE_NEXT_VARIANT (t) = new_type;
5977 TYPE_MAIN_VARIANT (new_type) = new_type;
5978 TYPE_NEXT_VARIANT (new_type) = NULL;
5983 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP.
5985 Arguments from DECL_ARGUMENTS list can't be removed now, since they are
5986 linked by TREE_CHAIN directly. It is caller responsibility to eliminate
5987 them when they are being duplicated (i.e. copy_arguments_for_versioning). */
5990 build_function_decl_skip_args (tree orig_decl, bitmap args_to_skip)
5992 tree new_decl = copy_node (orig_decl);
5995 new_type = TREE_TYPE (orig_decl);
5996 if (prototype_p (new_type))
5997 new_type = build_function_type_skip_args (new_type, args_to_skip);
5998 TREE_TYPE (new_decl) = new_type;
6000 /* For declarations setting DECL_VINDEX (i.e. methods)
6001 we expect first argument to be THIS pointer. */
6002 if (bitmap_bit_p (args_to_skip, 0))
6003 DECL_VINDEX (new_decl) = NULL_TREE;
6007 /* Build a function type. The RETURN_TYPE is the type returned by the
6008 function. If VAARGS is set, no void_type_node is appended to the
6009 the list. ARGP muse be alway be terminated be a NULL_TREE. */
6012 build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
6016 t = va_arg (argp, tree);
6017 for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
6018 args = tree_cons (NULL_TREE, t, args);
6023 if (args != NULL_TREE)
6024 args = nreverse (args);
6025 gcc_assert (args != NULL_TREE && last != void_list_node);
6027 else if (args == NULL_TREE)
6028 args = void_list_node;
6032 args = nreverse (args);
6033 TREE_CHAIN (last) = void_list_node;
6035 args = build_function_type (return_type, args);
6040 /* Build a function type. The RETURN_TYPE is the type returned by the
6041 function. If additional arguments are provided, they are
6042 additional argument types. The list of argument types must always
6043 be terminated by NULL_TREE. */
6046 build_function_type_list (tree return_type, ...)
6051 va_start (p, return_type);
6052 args = build_function_type_list_1 (false, return_type, p);
6057 /* Build a variable argument function type. The RETURN_TYPE is the
6058 type returned by the function. If additional arguments are provided,
6059 they are additional argument types. The list of argument types must
6060 always be terminated by NULL_TREE. */
6063 build_varargs_function_type_list (tree return_type, ...)
6068 va_start (p, return_type);
6069 args = build_function_type_list_1 (true, return_type, p);
6075 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
6076 and ARGTYPES (a TREE_LIST) are the return type and arguments types
6077 for the method. An implicit additional parameter (of type
6078 pointer-to-BASETYPE) is added to the ARGTYPES. */
6081 build_method_type_directly (tree basetype,
6088 bool any_structural_p, any_noncanonical_p;
6089 tree canon_argtypes;
6091 /* Make a node of the sort we want. */
6092 t = make_node (METHOD_TYPE);
6094 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
6095 TREE_TYPE (t) = rettype;
6096 ptype = build_pointer_type (basetype);
6098 /* The actual arglist for this function includes a "hidden" argument
6099 which is "this". Put it into the list of argument types. */
6100 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
6101 TYPE_ARG_TYPES (t) = argtypes;
6103 /* If we already have such a type, use the old one. */
6104 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
6105 hashcode = iterative_hash_object (TYPE_HASH (rettype), hashcode);
6106 hashcode = type_hash_list (argtypes, hashcode);
6107 t = type_hash_canon (hashcode, t);
6109 /* Set up the canonical type. */
6111 = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
6112 || TYPE_STRUCTURAL_EQUALITY_P (rettype));
6114 = (TYPE_CANONICAL (basetype) != basetype
6115 || TYPE_CANONICAL (rettype) != rettype);
6116 canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
6118 &any_noncanonical_p);
6119 if (any_structural_p)
6120 SET_TYPE_STRUCTURAL_EQUALITY (t);
6121 else if (any_noncanonical_p)
6123 = build_method_type_directly (TYPE_CANONICAL (basetype),
6124 TYPE_CANONICAL (rettype),
6126 if (!COMPLETE_TYPE_P (t))
6132 /* Construct, lay out and return the type of methods belonging to class
6133 BASETYPE and whose arguments and values are described by TYPE.
6134 If that type exists already, reuse it.
6135 TYPE must be a FUNCTION_TYPE node. */
6138 build_method_type (tree basetype, tree type)
6140 gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
6142 return build_method_type_directly (basetype,
6144 TYPE_ARG_TYPES (type));
6147 /* Construct, lay out and return the type of offsets to a value
6148 of type TYPE, within an object of type BASETYPE.
6149 If a suitable offset type exists already, reuse it. */
6152 build_offset_type (tree basetype, tree type)
6155 hashval_t hashcode = 0;
6157 /* Make a node of the sort we want. */
6158 t = make_node (OFFSET_TYPE);
6160 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
6161 TREE_TYPE (t) = type;
6163 /* If we already have such a type, use the old one. */
6164 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
6165 hashcode = iterative_hash_object (TYPE_HASH (type), hashcode);
6166 t = type_hash_canon (hashcode, t);
6168 if (!COMPLETE_TYPE_P (t))
6171 if (TYPE_CANONICAL (t) == t)
6173 if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
6174 || TYPE_STRUCTURAL_EQUALITY_P (type))
6175 SET_TYPE_STRUCTURAL_EQUALITY (t);
6176 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
6177 || TYPE_CANONICAL (type) != type)
6179 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
6180 TYPE_CANONICAL (type));
6186 /* Create a complex type whose components are COMPONENT_TYPE. */
6189 build_complex_type (tree component_type)
6194 gcc_assert (INTEGRAL_TYPE_P (component_type)
6195 || SCALAR_FLOAT_TYPE_P (component_type)
6196 || FIXED_POINT_TYPE_P (component_type));
6198 /* Make a node of the sort we want. */
6199 t = make_node (COMPLEX_TYPE);
6201 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
6203 /* If we already have such a type, use the old one. */
6204 hashcode = iterative_hash_object (TYPE_HASH (component_type), 0);
6205 t = type_hash_canon (hashcode, t);
6207 if (!COMPLETE_TYPE_P (t))
6210 if (TYPE_CANONICAL (t) == t)
6212 if (TYPE_STRUCTURAL_EQUALITY_P (component_type))
6213 SET_TYPE_STRUCTURAL_EQUALITY (t);
6214 else if (TYPE_CANONICAL (component_type) != component_type)
6216 = build_complex_type (TYPE_CANONICAL (component_type));
6219 /* We need to create a name, since complex is a fundamental type. */
6220 if (! TYPE_NAME (t))
6223 if (component_type == char_type_node)
6224 name = "complex char";
6225 else if (component_type == signed_char_type_node)
6226 name = "complex signed char";
6227 else if (component_type == unsigned_char_type_node)
6228 name = "complex unsigned char";
6229 else if (component_type == short_integer_type_node)
6230 name = "complex short int";
6231 else if (component_type == short_unsigned_type_node)
6232 name = "complex short unsigned int";
6233 else if (component_type == integer_type_node)
6234 name = "complex int";
6235 else if (component_type == unsigned_type_node)
6236 name = "complex unsigned int";
6237 else if (component_type == long_integer_type_node)
6238 name = "complex long int";
6239 else if (component_type == long_unsigned_type_node)
6240 name = "complex long unsigned int";
6241 else if (component_type == long_long_integer_type_node)
6242 name = "complex long long int";
6243 else if (component_type == long_long_unsigned_type_node)
6244 name = "complex long long unsigned int";
6249 TYPE_NAME (t) = build_decl (TYPE_DECL, get_identifier (name), t);
6252 return build_qualified_type (t, TYPE_QUALS (component_type));
6255 /* If TYPE is a real or complex floating-point type and the target
6256 does not directly support arithmetic on TYPE then return the wider
6257 type to be used for arithmetic on TYPE. Otherwise, return
6261 excess_precision_type (tree type)
6263 if (flag_excess_precision != EXCESS_PRECISION_FAST)
6265 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
6266 switch (TREE_CODE (type))
6269 switch (flt_eval_method)
6272 if (TYPE_MODE (type) == TYPE_MODE (float_type_node))
6273 return double_type_node;
6276 if (TYPE_MODE (type) == TYPE_MODE (float_type_node)
6277 || TYPE_MODE (type) == TYPE_MODE (double_type_node))
6278 return long_double_type_node;
6285 if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
6287 switch (flt_eval_method)
6290 if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node))
6291 return complex_double_type_node;
6294 if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node)
6295 || (TYPE_MODE (TREE_TYPE (type))
6296 == TYPE_MODE (double_type_node)))
6297 return complex_long_double_type_node;
6310 /* Return OP, stripped of any conversions to wider types as much as is safe.
6311 Converting the value back to OP's type makes a value equivalent to OP.
6313 If FOR_TYPE is nonzero, we return a value which, if converted to
6314 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
6316 OP must have integer, real or enumeral type. Pointers are not allowed!
6318 There are some cases where the obvious value we could return
6319 would regenerate to OP if converted to OP's type,
6320 but would not extend like OP to wider types.
6321 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
6322 For example, if OP is (unsigned short)(signed char)-1,
6323 we avoid returning (signed char)-1 if FOR_TYPE is int,
6324 even though extending that to an unsigned short would regenerate OP,
6325 since the result of extending (signed char)-1 to (int)
6326 is different from (int) OP. */
6329 get_unwidened (tree op, tree for_type)
6331 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
6332 tree type = TREE_TYPE (op);
6334 = TYPE_PRECISION (for_type != 0 ? for_type : type);
6336 = (for_type != 0 && for_type != type
6337 && final_prec > TYPE_PRECISION (type)
6338 && TYPE_UNSIGNED (type));
6341 while (CONVERT_EXPR_P (op))
6345 /* TYPE_PRECISION on vector types has different meaning
6346 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
6347 so avoid them here. */
6348 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
6351 bitschange = TYPE_PRECISION (TREE_TYPE (op))
6352 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
6354 /* Truncations are many-one so cannot be removed.
6355 Unless we are later going to truncate down even farther. */
6357 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
6360 /* See what's inside this conversion. If we decide to strip it,
6362 op = TREE_OPERAND (op, 0);
6364 /* If we have not stripped any zero-extensions (uns is 0),
6365 we can strip any kind of extension.
6366 If we have previously stripped a zero-extension,
6367 only zero-extensions can safely be stripped.
6368 Any extension can be stripped if the bits it would produce
6369 are all going to be discarded later by truncating to FOR_TYPE. */
6373 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
6375 /* TYPE_UNSIGNED says whether this is a zero-extension.
6376 Let's avoid computing it if it does not affect WIN
6377 and if UNS will not be needed again. */
6379 || CONVERT_EXPR_P (op))
6380 && TYPE_UNSIGNED (TREE_TYPE (op)))
6391 /* Return OP or a simpler expression for a narrower value
6392 which can be sign-extended or zero-extended to give back OP.
6393 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
6394 or 0 if the value should be sign-extended. */
6397 get_narrower (tree op, int *unsignedp_ptr)
6402 bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
6404 while (TREE_CODE (op) == NOP_EXPR)
6407 = (TYPE_PRECISION (TREE_TYPE (op))
6408 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
6410 /* Truncations are many-one so cannot be removed. */
6414 /* See what's inside this conversion. If we decide to strip it,
6419 op = TREE_OPERAND (op, 0);
6420 /* An extension: the outermost one can be stripped,
6421 but remember whether it is zero or sign extension. */
6423 uns = TYPE_UNSIGNED (TREE_TYPE (op));
6424 /* Otherwise, if a sign extension has been stripped,
6425 only sign extensions can now be stripped;
6426 if a zero extension has been stripped, only zero-extensions. */
6427 else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
6431 else /* bitschange == 0 */
6433 /* A change in nominal type can always be stripped, but we must
6434 preserve the unsignedness. */
6436 uns = TYPE_UNSIGNED (TREE_TYPE (op));
6438 op = TREE_OPERAND (op, 0);
6439 /* Keep trying to narrow, but don't assign op to win if it
6440 would turn an integral type into something else. */
6441 if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
6448 if (TREE_CODE (op) == COMPONENT_REF
6449 /* Since type_for_size always gives an integer type. */
6450 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
6451 && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
6452 /* Ensure field is laid out already. */
6453 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
6454 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
6456 unsigned HOST_WIDE_INT innerprec
6457 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
6458 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
6459 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
6460 tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
6462 /* We can get this structure field in a narrower type that fits it,
6463 but the resulting extension to its nominal type (a fullword type)
6464 must satisfy the same conditions as for other extensions.
6466 Do this only for fields that are aligned (not bit-fields),
6467 because when bit-field insns will be used there is no
6468 advantage in doing this. */
6470 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
6471 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
6472 && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
6476 uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
6477 win = fold_convert (type, op);
6481 *unsignedp_ptr = uns;
6485 /* Nonzero if integer constant C has a value that is permissible
6486 for type TYPE (an INTEGER_TYPE). */
6489 int_fits_type_p (const_tree c, const_tree type)
6491 tree type_low_bound, type_high_bound;
6492 bool ok_for_low_bound, ok_for_high_bound, unsc;
6495 dc = tree_to_double_int (c);
6496 unsc = TYPE_UNSIGNED (TREE_TYPE (c));
6498 if (TREE_CODE (TREE_TYPE (c)) == INTEGER_TYPE
6499 && TYPE_IS_SIZETYPE (TREE_TYPE (c))
6501 /* So c is an unsigned integer whose type is sizetype and type is not.
6502 sizetype'd integers are sign extended even though they are
6503 unsigned. If the integer value fits in the lower end word of c,
6504 and if the higher end word has all its bits set to 1, that
6505 means the higher end bits are set to 1 only for sign extension.
6506 So let's convert c into an equivalent zero extended unsigned
6508 dc = double_int_zext (dc, TYPE_PRECISION (TREE_TYPE (c)));
6511 type_low_bound = TYPE_MIN_VALUE (type);
6512 type_high_bound = TYPE_MAX_VALUE (type);
6514 /* If at least one bound of the type is a constant integer, we can check
6515 ourselves and maybe make a decision. If no such decision is possible, but
6516 this type is a subtype, try checking against that. Otherwise, use
6517 fit_double_type, which checks against the precision.
6519 Compute the status for each possibly constant bound, and return if we see
6520 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
6521 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
6522 for "constant known to fit". */
6524 /* Check if c >= type_low_bound. */
6525 if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
6527 dd = tree_to_double_int (type_low_bound);
6528 if (TREE_CODE (type) == INTEGER_TYPE
6529 && TYPE_IS_SIZETYPE (type)
6530 && TYPE_UNSIGNED (type))
6531 dd = double_int_zext (dd, TYPE_PRECISION (type));
6532 if (unsc != TYPE_UNSIGNED (TREE_TYPE (type_low_bound)))
6534 int c_neg = (!unsc && double_int_negative_p (dc));
6535 int t_neg = (unsc && double_int_negative_p (dd));
6537 if (c_neg && !t_neg)
6539 if ((c_neg || !t_neg) && double_int_ucmp (dc, dd) < 0)
6542 else if (double_int_cmp (dc, dd, unsc) < 0)
6544 ok_for_low_bound = true;
6547 ok_for_low_bound = false;
6549 /* Check if c <= type_high_bound. */
6550 if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
6552 dd = tree_to_double_int (type_high_bound);
6553 if (TREE_CODE (type) == INTEGER_TYPE
6554 && TYPE_IS_SIZETYPE (type)
6555 && TYPE_UNSIGNED (type))
6556 dd = double_int_zext (dd, TYPE_PRECISION (type));
6557 if (unsc != TYPE_UNSIGNED (TREE_TYPE (type_high_bound)))
6559 int c_neg = (!unsc && double_int_negative_p (dc));
6560 int t_neg = (unsc && double_int_negative_p (dd));
6562 if (t_neg && !c_neg)
6564 if ((t_neg || !c_neg) && double_int_ucmp (dc, dd) > 0)
6567 else if (double_int_cmp (dc, dd, unsc) > 0)
6569 ok_for_high_bound = true;
6572 ok_for_high_bound = false;
6574 /* If the constant fits both bounds, the result is known. */
6575 if (ok_for_low_bound && ok_for_high_bound)
6578 /* Perform some generic filtering which may allow making a decision
6579 even if the bounds are not constant. First, negative integers
6580 never fit in unsigned types, */
6581 if (TYPE_UNSIGNED (type) && !unsc && double_int_negative_p (dc))
6584 /* Second, narrower types always fit in wider ones. */
6585 if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
6588 /* Third, unsigned integers with top bit set never fit signed types. */
6589 if (! TYPE_UNSIGNED (type) && unsc)
6591 int prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (c))) - 1;
6592 if (prec < HOST_BITS_PER_WIDE_INT)
6594 if (((((unsigned HOST_WIDE_INT) 1) << prec) & dc.low) != 0)
6597 else if (((((unsigned HOST_WIDE_INT) 1)
6598 << (prec - HOST_BITS_PER_WIDE_INT)) & dc.high) != 0)
6602 /* If we haven't been able to decide at this point, there nothing more we
6603 can check ourselves here. Look at the base type if we have one and it
6604 has the same precision. */
6605 if (TREE_CODE (type) == INTEGER_TYPE
6606 && TREE_TYPE (type) != 0
6607 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
6609 type = TREE_TYPE (type);
6613 /* Or to fit_double_type, if nothing else. */
6614 return !fit_double_type (dc.low, dc.high, &dc.low, &dc.high, type);
6617 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
6618 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
6619 represented (assuming two's-complement arithmetic) within the bit
6620 precision of the type are returned instead. */
6623 get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
6625 if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
6626 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
6627 mpz_set_double_int (min, tree_to_double_int (TYPE_MIN_VALUE (type)),
6628 TYPE_UNSIGNED (type));
6631 if (TYPE_UNSIGNED (type))
6632 mpz_set_ui (min, 0);
6636 mn = double_int_mask (TYPE_PRECISION (type) - 1);
6637 mn = double_int_sext (double_int_add (mn, double_int_one),
6638 TYPE_PRECISION (type));
6639 mpz_set_double_int (min, mn, false);
6643 if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
6644 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
6645 mpz_set_double_int (max, tree_to_double_int (TYPE_MAX_VALUE (type)),
6646 TYPE_UNSIGNED (type));
6649 if (TYPE_UNSIGNED (type))
6650 mpz_set_double_int (max, double_int_mask (TYPE_PRECISION (type)),
6653 mpz_set_double_int (max, double_int_mask (TYPE_PRECISION (type) - 1),
6658 /* Return true if VAR is an automatic variable defined in function FN. */
6661 auto_var_in_fn_p (const_tree var, const_tree fn)
6663 return (DECL_P (var) && DECL_CONTEXT (var) == fn
6664 && (((TREE_CODE (var) == VAR_DECL || TREE_CODE (var) == PARM_DECL)
6665 && ! TREE_STATIC (var))
6666 || TREE_CODE (var) == LABEL_DECL
6667 || TREE_CODE (var) == RESULT_DECL));
6670 /* Subprogram of following function. Called by walk_tree.
6672 Return *TP if it is an automatic variable or parameter of the
6673 function passed in as DATA. */
6676 find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
6678 tree fn = (tree) data;
6683 else if (DECL_P (*tp)
6684 && auto_var_in_fn_p (*tp, fn))
6690 /* Returns true if T is, contains, or refers to a type with variable
6691 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
6692 arguments, but not the return type. If FN is nonzero, only return
6693 true if a modifier of the type or position of FN is a variable or
6694 parameter inside FN.
6696 This concept is more general than that of C99 'variably modified types':
6697 in C99, a struct type is never variably modified because a VLA may not
6698 appear as a structure member. However, in GNU C code like:
6700 struct S { int i[f()]; };
6702 is valid, and other languages may define similar constructs. */
6705 variably_modified_type_p (tree type, tree fn)
6709 /* Test if T is either variable (if FN is zero) or an expression containing
6710 a variable in FN. */
6711 #define RETURN_TRUE_IF_VAR(T) \
6712 do { tree _t = (T); \
6713 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
6714 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
6715 return true; } while (0)
6717 if (type == error_mark_node)
6720 /* If TYPE itself has variable size, it is variably modified. */
6721 RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
6722 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
6724 switch (TREE_CODE (type))
6727 case REFERENCE_TYPE:
6729 if (variably_modified_type_p (TREE_TYPE (type), fn))
6735 /* If TYPE is a function type, it is variably modified if the
6736 return type is variably modified. */
6737 if (variably_modified_type_p (TREE_TYPE (type), fn))
6743 case FIXED_POINT_TYPE:
6746 /* Scalar types are variably modified if their end points
6748 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
6749 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
6754 case QUAL_UNION_TYPE:
6755 /* We can't see if any of the fields are variably-modified by the
6756 definition we normally use, since that would produce infinite
6757 recursion via pointers. */
6758 /* This is variably modified if some field's type is. */
6759 for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
6760 if (TREE_CODE (t) == FIELD_DECL)
6762 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
6763 RETURN_TRUE_IF_VAR (DECL_SIZE (t));
6764 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
6766 if (TREE_CODE (type) == QUAL_UNION_TYPE)
6767 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
6772 /* Do not call ourselves to avoid infinite recursion. This is
6773 variably modified if the element type is. */
6774 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
6775 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
6782 /* The current language may have other cases to check, but in general,
6783 all other types are not variably modified. */
6784 return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
6786 #undef RETURN_TRUE_IF_VAR
6789 /* Given a DECL or TYPE, return the scope in which it was declared, or
6790 NULL_TREE if there is no containing scope. */
6793 get_containing_scope (const_tree t)
6795 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
6798 /* Return the innermost context enclosing DECL that is
6799 a FUNCTION_DECL, or zero if none. */
6802 decl_function_context (const_tree decl)
6806 if (TREE_CODE (decl) == ERROR_MARK)
6809 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
6810 where we look up the function at runtime. Such functions always take
6811 a first argument of type 'pointer to real context'.
6813 C++ should really be fixed to use DECL_CONTEXT for the real context,
6814 and use something else for the "virtual context". */
6815 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
6818 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
6820 context = DECL_CONTEXT (decl);
6822 while (context && TREE_CODE (context) != FUNCTION_DECL)
6824 if (TREE_CODE (context) == BLOCK)
6825 context = BLOCK_SUPERCONTEXT (context);
6827 context = get_containing_scope (context);
6833 /* Return the innermost context enclosing DECL that is
6834 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
6835 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
6838 decl_type_context (const_tree decl)
6840 tree context = DECL_CONTEXT (decl);
6843 switch (TREE_CODE (context))
6845 case NAMESPACE_DECL:
6846 case TRANSLATION_UNIT_DECL:
6851 case QUAL_UNION_TYPE:
6856 context = DECL_CONTEXT (context);
6860 context = BLOCK_SUPERCONTEXT (context);
6870 /* CALL is a CALL_EXPR. Return the declaration for the function
6871 called, or NULL_TREE if the called function cannot be
6875 get_callee_fndecl (const_tree call)
6879 if (call == error_mark_node)
6880 return error_mark_node;
6882 /* It's invalid to call this function with anything but a
6884 gcc_assert (TREE_CODE (call) == CALL_EXPR);
6886 /* The first operand to the CALL is the address of the function
6888 addr = CALL_EXPR_FN (call);
6892 /* If this is a readonly function pointer, extract its initial value. */
6893 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
6894 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
6895 && DECL_INITIAL (addr))
6896 addr = DECL_INITIAL (addr);
6898 /* If the address is just `&f' for some function `f', then we know
6899 that `f' is being called. */
6900 if (TREE_CODE (addr) == ADDR_EXPR
6901 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
6902 return TREE_OPERAND (addr, 0);
6904 /* We couldn't figure out what was being called. */
6908 /* Print debugging information about tree nodes generated during the compile,
6909 and any language-specific information. */
6912 dump_tree_statistics (void)
6914 #ifdef GATHER_STATISTICS
6916 int total_nodes, total_bytes;
6919 fprintf (stderr, "\n??? tree nodes created\n\n");
6920 #ifdef GATHER_STATISTICS
6921 fprintf (stderr, "Kind Nodes Bytes\n");
6922 fprintf (stderr, "---------------------------------------\n");
6923 total_nodes = total_bytes = 0;
6924 for (i = 0; i < (int) all_kinds; i++)
6926 fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
6927 tree_node_counts[i], tree_node_sizes[i]);
6928 total_nodes += tree_node_counts[i];
6929 total_bytes += tree_node_sizes[i];
6931 fprintf (stderr, "---------------------------------------\n");
6932 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
6933 fprintf (stderr, "---------------------------------------\n");
6934 ssanames_print_statistics ();
6935 phinodes_print_statistics ();
6937 fprintf (stderr, "(No per-node statistics)\n");
6939 print_type_hash_statistics ();
6940 print_debug_expr_statistics ();
6941 print_value_expr_statistics ();
6942 print_restrict_base_statistics ();
6943 lang_hooks.print_statistics ();
6946 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
6948 /* Generate a crc32 of a string. */
6951 crc32_string (unsigned chksum, const char *string)
6955 unsigned value = *string << 24;
6958 for (ix = 8; ix--; value <<= 1)
6962 feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
6971 /* P is a string that will be used in a symbol. Mask out any characters
6972 that are not valid in that context. */
6975 clean_symbol_name (char *p)
6979 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
6982 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
6989 /* Generate a name for a special-purpose function function.
6990 The generated name may need to be unique across the whole link.
6991 TYPE is some string to identify the purpose of this function to the
6992 linker or collect2; it must start with an uppercase letter,
6994 I - for constructors
6996 N - for C++ anonymous namespaces
6997 F - for DWARF unwind frame information. */
7000 get_file_function_name (const char *type)
7006 /* If we already have a name we know to be unique, just use that. */
7007 if (first_global_object_name)
7008 p = q = ASTRDUP (first_global_object_name);
7009 /* If the target is handling the constructors/destructors, they
7010 will be local to this file and the name is only necessary for
7011 debugging purposes. */
7012 else if ((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
7014 const char *file = main_input_filename;
7016 file = input_filename;
7017 /* Just use the file's basename, because the full pathname
7018 might be quite long. */
7019 p = strrchr (file, '/');
7024 p = q = ASTRDUP (p);
7028 /* Otherwise, the name must be unique across the entire link.
7029 We don't have anything that we know to be unique to this translation
7030 unit, so use what we do have and throw in some randomness. */
7032 const char *name = weak_global_object_name;
7033 const char *file = main_input_filename;
7038 file = input_filename;
7040 len = strlen (file);
7041 q = (char *) alloca (9 * 2 + len + 1);
7042 memcpy (q, file, len + 1);
7044 sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
7045 crc32_string (0, get_random_seed (false)));
7050 clean_symbol_name (q);
7051 buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
7054 /* Set up the name of the file-level functions we may need.
7055 Use a global object (which is already required to be unique over
7056 the program) rather than the file name (which imposes extra
7058 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
7060 return get_identifier (buf);
7063 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
7065 /* Complain that the tree code of NODE does not match the expected 0
7066 terminated list of trailing codes. The trailing code list can be
7067 empty, for a more vague error message. FILE, LINE, and FUNCTION
7068 are of the caller. */
7071 tree_check_failed (const_tree node, const char *file,
7072 int line, const char *function, ...)
7076 unsigned length = 0;
7079 va_start (args, function);
7080 while ((code = va_arg (args, int)))
7081 length += 4 + strlen (tree_code_name[code]);
7086 va_start (args, function);
7087 length += strlen ("expected ");
7088 buffer = tmp = (char *) alloca (length);
7090 while ((code = va_arg (args, int)))
7092 const char *prefix = length ? " or " : "expected ";
7094 strcpy (tmp + length, prefix);
7095 length += strlen (prefix);
7096 strcpy (tmp + length, tree_code_name[code]);
7097 length += strlen (tree_code_name[code]);
7102 buffer = "unexpected node";
7104 internal_error ("tree check: %s, have %s in %s, at %s:%d",
7105 buffer, tree_code_name[TREE_CODE (node)],
7106 function, trim_filename (file), line);
7109 /* Complain that the tree code of NODE does match the expected 0
7110 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
7114 tree_not_check_failed (const_tree node, const char *file,
7115 int line, const char *function, ...)
7119 unsigned length = 0;
7122 va_start (args, function);
7123 while ((code = va_arg (args, int)))
7124 length += 4 + strlen (tree_code_name[code]);
7126 va_start (args, function);
7127 buffer = (char *) alloca (length);
7129 while ((code = va_arg (args, int)))
7133 strcpy (buffer + length, " or ");
7136 strcpy (buffer + length, tree_code_name[code]);
7137 length += strlen (tree_code_name[code]);
7141 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
7142 buffer, tree_code_name[TREE_CODE (node)],
7143 function, trim_filename (file), line);
7146 /* Similar to tree_check_failed, except that we check for a class of tree
7147 code, given in CL. */
7150 tree_class_check_failed (const_tree node, const enum tree_code_class cl,
7151 const char *file, int line, const char *function)
7154 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
7155 TREE_CODE_CLASS_STRING (cl),
7156 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
7157 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
7160 /* Similar to tree_check_failed, except that instead of specifying a
7161 dozen codes, use the knowledge that they're all sequential. */
7164 tree_range_check_failed (const_tree node, const char *file, int line,
7165 const char *function, enum tree_code c1,
7169 unsigned length = 0;
7172 for (c = c1; c <= c2; ++c)
7173 length += 4 + strlen (tree_code_name[c]);
7175 length += strlen ("expected ");
7176 buffer = (char *) alloca (length);
7179 for (c = c1; c <= c2; ++c)
7181 const char *prefix = length ? " or " : "expected ";
7183 strcpy (buffer + length, prefix);
7184 length += strlen (prefix);
7185 strcpy (buffer + length, tree_code_name[c]);
7186 length += strlen (tree_code_name[c]);
7189 internal_error ("tree check: %s, have %s in %s, at %s:%d",
7190 buffer, tree_code_name[TREE_CODE (node)],
7191 function, trim_filename (file), line);
7195 /* Similar to tree_check_failed, except that we check that a tree does
7196 not have the specified code, given in CL. */
7199 tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
7200 const char *file, int line, const char *function)
7203 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
7204 TREE_CODE_CLASS_STRING (cl),
7205 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
7206 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
7210 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
7213 omp_clause_check_failed (const_tree node, const char *file, int line,
7214 const char *function, enum omp_clause_code code)
7216 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
7217 omp_clause_code_name[code], tree_code_name[TREE_CODE (node)],
7218 function, trim_filename (file), line);
7222 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
7225 omp_clause_range_check_failed (const_tree node, const char *file, int line,
7226 const char *function, enum omp_clause_code c1,
7227 enum omp_clause_code c2)
7230 unsigned length = 0;
7231 enum omp_clause_code c;
7233 for (c = c1; c <= c2; ++c)
7234 length += 4 + strlen (omp_clause_code_name[c]);
7236 length += strlen ("expected ");
7237 buffer = (char *) alloca (length);
7240 for (c = c1; c <= c2; ++c)
7242 const char *prefix = length ? " or " : "expected ";
7244 strcpy (buffer + length, prefix);
7245 length += strlen (prefix);
7246 strcpy (buffer + length, omp_clause_code_name[c]);
7247 length += strlen (omp_clause_code_name[c]);
7250 internal_error ("tree check: %s, have %s in %s, at %s:%d",
7251 buffer, omp_clause_code_name[TREE_CODE (node)],
7252 function, trim_filename (file), line);
7256 #undef DEFTREESTRUCT
7257 #define DEFTREESTRUCT(VAL, NAME) NAME,
7259 static const char *ts_enum_names[] = {
7260 #include "treestruct.def"
7262 #undef DEFTREESTRUCT
7264 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
7266 /* Similar to tree_class_check_failed, except that we check for
7267 whether CODE contains the tree structure identified by EN. */
7270 tree_contains_struct_check_failed (const_tree node,
7271 const enum tree_node_structure_enum en,
7272 const char *file, int line,
7273 const char *function)
7276 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
7278 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
7282 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
7283 (dynamically sized) vector. */
7286 tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
7287 const char *function)
7290 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
7291 idx + 1, len, function, trim_filename (file), line);
7294 /* Similar to above, except that the check is for the bounds of the operand
7295 vector of an expression node EXP. */
7298 tree_operand_check_failed (int idx, const_tree exp, const char *file,
7299 int line, const char *function)
7301 int code = TREE_CODE (exp);
7303 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
7304 idx + 1, tree_code_name[code], TREE_OPERAND_LENGTH (exp),
7305 function, trim_filename (file), line);
7308 /* Similar to above, except that the check is for the number of
7309 operands of an OMP_CLAUSE node. */
7312 omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
7313 int line, const char *function)
7316 ("tree check: accessed operand %d of omp_clause %s with %d operands "
7317 "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
7318 omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
7319 trim_filename (file), line);
7321 #endif /* ENABLE_TREE_CHECKING */
7323 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
7324 and mapped to the machine mode MODE. Initialize its fields and build
7325 the information necessary for debugging output. */
7328 make_vector_type (tree innertype, int nunits, enum machine_mode mode)
7331 hashval_t hashcode = 0;
7333 /* Build a main variant, based on the main variant of the inner type, then
7334 use it to build the variant we return. */
7335 if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
7336 && TYPE_MAIN_VARIANT (innertype) != innertype)
7337 return build_type_attribute_qual_variant (
7338 make_vector_type (TYPE_MAIN_VARIANT (innertype), nunits, mode),
7339 TYPE_ATTRIBUTES (innertype),
7340 TYPE_QUALS (innertype));
7342 t = make_node (VECTOR_TYPE);
7343 TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype);
7344 SET_TYPE_VECTOR_SUBPARTS (t, nunits);
7345 SET_TYPE_MODE (t, mode);
7346 TYPE_READONLY (t) = TYPE_READONLY (innertype);
7347 TYPE_VOLATILE (t) = TYPE_VOLATILE (innertype);
7349 if (TYPE_STRUCTURAL_EQUALITY_P (innertype))
7350 SET_TYPE_STRUCTURAL_EQUALITY (t);
7351 else if (TYPE_CANONICAL (innertype) != innertype
7352 || mode != VOIDmode)
7354 = make_vector_type (TYPE_CANONICAL (innertype), nunits, VOIDmode);
7359 tree index = build_int_cst (NULL_TREE, nunits - 1);
7360 tree array = build_array_type (innertype, build_index_type (index));
7361 tree rt = make_node (RECORD_TYPE);
7363 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
7364 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
7366 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
7367 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
7368 the representation type, and we want to find that die when looking up
7369 the vector type. This is most easily achieved by making the TYPE_UID
7371 TYPE_UID (rt) = TYPE_UID (t);
7374 hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode);
7375 hashcode = iterative_hash_host_wide_int (mode, hashcode);
7376 hashcode = iterative_hash_object (TYPE_HASH (innertype), hashcode);
7377 return type_hash_canon (hashcode, t);
7381 make_or_reuse_type (unsigned size, int unsignedp)
7383 if (size == INT_TYPE_SIZE)
7384 return unsignedp ? unsigned_type_node : integer_type_node;
7385 if (size == CHAR_TYPE_SIZE)
7386 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
7387 if (size == SHORT_TYPE_SIZE)
7388 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
7389 if (size == LONG_TYPE_SIZE)
7390 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
7391 if (size == LONG_LONG_TYPE_SIZE)
7392 return (unsignedp ? long_long_unsigned_type_node
7393 : long_long_integer_type_node);
7396 return make_unsigned_type (size);
7398 return make_signed_type (size);
7401 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
7404 make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
7408 if (size == SHORT_FRACT_TYPE_SIZE)
7409 return unsignedp ? sat_unsigned_short_fract_type_node
7410 : sat_short_fract_type_node;
7411 if (size == FRACT_TYPE_SIZE)
7412 return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
7413 if (size == LONG_FRACT_TYPE_SIZE)
7414 return unsignedp ? sat_unsigned_long_fract_type_node
7415 : sat_long_fract_type_node;
7416 if (size == LONG_LONG_FRACT_TYPE_SIZE)
7417 return unsignedp ? sat_unsigned_long_long_fract_type_node
7418 : sat_long_long_fract_type_node;
7422 if (size == SHORT_FRACT_TYPE_SIZE)
7423 return unsignedp ? unsigned_short_fract_type_node
7424 : short_fract_type_node;
7425 if (size == FRACT_TYPE_SIZE)
7426 return unsignedp ? unsigned_fract_type_node : fract_type_node;
7427 if (size == LONG_FRACT_TYPE_SIZE)
7428 return unsignedp ? unsigned_long_fract_type_node
7429 : long_fract_type_node;
7430 if (size == LONG_LONG_FRACT_TYPE_SIZE)
7431 return unsignedp ? unsigned_long_long_fract_type_node
7432 : long_long_fract_type_node;
7435 return make_fract_type (size, unsignedp, satp);
7438 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
7441 make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
7445 if (size == SHORT_ACCUM_TYPE_SIZE)
7446 return unsignedp ? sat_unsigned_short_accum_type_node
7447 : sat_short_accum_type_node;
7448 if (size == ACCUM_TYPE_SIZE)
7449 return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
7450 if (size == LONG_ACCUM_TYPE_SIZE)
7451 return unsignedp ? sat_unsigned_long_accum_type_node
7452 : sat_long_accum_type_node;
7453 if (size == LONG_LONG_ACCUM_TYPE_SIZE)
7454 return unsignedp ? sat_unsigned_long_long_accum_type_node
7455 : sat_long_long_accum_type_node;
7459 if (size == SHORT_ACCUM_TYPE_SIZE)
7460 return unsignedp ? unsigned_short_accum_type_node
7461 : short_accum_type_node;
7462 if (size == ACCUM_TYPE_SIZE)
7463 return unsignedp ? unsigned_accum_type_node : accum_type_node;
7464 if (size == LONG_ACCUM_TYPE_SIZE)
7465 return unsignedp ? unsigned_long_accum_type_node
7466 : long_accum_type_node;
7467 if (size == LONG_LONG_ACCUM_TYPE_SIZE)
7468 return unsignedp ? unsigned_long_long_accum_type_node
7469 : long_long_accum_type_node;
7472 return make_accum_type (size, unsignedp, satp);
7475 /* Create nodes for all integer types (and error_mark_node) using the sizes
7476 of C datatypes. The caller should call set_sizetype soon after calling
7477 this function to select one of the types as sizetype. */
7480 build_common_tree_nodes (bool signed_char, bool signed_sizetype)
7482 error_mark_node = make_node (ERROR_MARK);
7483 TREE_TYPE (error_mark_node) = error_mark_node;
7485 initialize_sizetypes (signed_sizetype);
7487 /* Define both `signed char' and `unsigned char'. */
7488 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
7489 TYPE_STRING_FLAG (signed_char_type_node) = 1;
7490 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
7491 TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
7493 /* Define `char', which is like either `signed char' or `unsigned char'
7494 but not the same as either. */
7497 ? make_signed_type (CHAR_TYPE_SIZE)
7498 : make_unsigned_type (CHAR_TYPE_SIZE));
7499 TYPE_STRING_FLAG (char_type_node) = 1;
7501 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
7502 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
7503 integer_type_node = make_signed_type (INT_TYPE_SIZE);
7504 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
7505 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
7506 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
7507 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
7508 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
7510 /* Define a boolean type. This type only represents boolean values but
7511 may be larger than char depending on the value of BOOL_TYPE_SIZE.
7512 Front ends which want to override this size (i.e. Java) can redefine
7513 boolean_type_node before calling build_common_tree_nodes_2. */
7514 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
7515 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
7516 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
7517 TYPE_PRECISION (boolean_type_node) = 1;
7519 /* Fill in the rest of the sized types. Reuse existing type nodes
7521 intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
7522 intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
7523 intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
7524 intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
7525 intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
7527 unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
7528 unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
7529 unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
7530 unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
7531 unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
7533 access_public_node = get_identifier ("public");
7534 access_protected_node = get_identifier ("protected");
7535 access_private_node = get_identifier ("private");
7538 /* Call this function after calling build_common_tree_nodes and set_sizetype.
7539 It will create several other common tree nodes. */
7542 build_common_tree_nodes_2 (int short_double)
7544 /* Define these next since types below may used them. */
7545 integer_zero_node = build_int_cst (NULL_TREE, 0);
7546 integer_one_node = build_int_cst (NULL_TREE, 1);
7547 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
7549 size_zero_node = size_int (0);
7550 size_one_node = size_int (1);
7551 bitsize_zero_node = bitsize_int (0);
7552 bitsize_one_node = bitsize_int (1);
7553 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
7555 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
7556 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
7558 void_type_node = make_node (VOID_TYPE);
7559 layout_type (void_type_node);
7561 /* We are not going to have real types in C with less than byte alignment,
7562 so we might as well not have any types that claim to have it. */
7563 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
7564 TYPE_USER_ALIGN (void_type_node) = 0;
7566 null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
7567 layout_type (TREE_TYPE (null_pointer_node));
7569 ptr_type_node = build_pointer_type (void_type_node);
7571 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
7572 fileptr_type_node = ptr_type_node;
7574 float_type_node = make_node (REAL_TYPE);
7575 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
7576 layout_type (float_type_node);
7578 double_type_node = make_node (REAL_TYPE);
7580 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
7582 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
7583 layout_type (double_type_node);
7585 long_double_type_node = make_node (REAL_TYPE);
7586 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
7587 layout_type (long_double_type_node);
7589 float_ptr_type_node = build_pointer_type (float_type_node);
7590 double_ptr_type_node = build_pointer_type (double_type_node);
7591 long_double_ptr_type_node = build_pointer_type (long_double_type_node);
7592 integer_ptr_type_node = build_pointer_type (integer_type_node);
7594 /* Fixed size integer types. */
7595 uint32_type_node = build_nonstandard_integer_type (32, true);
7596 uint64_type_node = build_nonstandard_integer_type (64, true);
7598 /* Decimal float types. */
7599 dfloat32_type_node = make_node (REAL_TYPE);
7600 TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
7601 layout_type (dfloat32_type_node);
7602 SET_TYPE_MODE (dfloat32_type_node, SDmode);
7603 dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node);
7605 dfloat64_type_node = make_node (REAL_TYPE);
7606 TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
7607 layout_type (dfloat64_type_node);
7608 SET_TYPE_MODE (dfloat64_type_node, DDmode);
7609 dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node);
7611 dfloat128_type_node = make_node (REAL_TYPE);
7612 TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
7613 layout_type (dfloat128_type_node);
7614 SET_TYPE_MODE (dfloat128_type_node, TDmode);
7615 dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node);
7617 complex_integer_type_node = build_complex_type (integer_type_node);
7618 complex_float_type_node = build_complex_type (float_type_node);
7619 complex_double_type_node = build_complex_type (double_type_node);
7620 complex_long_double_type_node = build_complex_type (long_double_type_node);
7622 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
7623 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
7624 sat_ ## KIND ## _type_node = \
7625 make_sat_signed_ ## KIND ## _type (SIZE); \
7626 sat_unsigned_ ## KIND ## _type_node = \
7627 make_sat_unsigned_ ## KIND ## _type (SIZE); \
7628 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
7629 unsigned_ ## KIND ## _type_node = \
7630 make_unsigned_ ## KIND ## _type (SIZE);
7632 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
7633 sat_ ## WIDTH ## KIND ## _type_node = \
7634 make_sat_signed_ ## KIND ## _type (SIZE); \
7635 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
7636 make_sat_unsigned_ ## KIND ## _type (SIZE); \
7637 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
7638 unsigned_ ## WIDTH ## KIND ## _type_node = \
7639 make_unsigned_ ## KIND ## _type (SIZE);
7641 /* Make fixed-point type nodes based on four different widths. */
7642 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
7643 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
7644 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
7645 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
7646 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
7648 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
7649 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
7650 NAME ## _type_node = \
7651 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
7652 u ## NAME ## _type_node = \
7653 make_or_reuse_unsigned_ ## KIND ## _type \
7654 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
7655 sat_ ## NAME ## _type_node = \
7656 make_or_reuse_sat_signed_ ## KIND ## _type \
7657 (GET_MODE_BITSIZE (MODE ## mode)); \
7658 sat_u ## NAME ## _type_node = \
7659 make_or_reuse_sat_unsigned_ ## KIND ## _type \
7660 (GET_MODE_BITSIZE (U ## MODE ## mode));
7662 /* Fixed-point type and mode nodes. */
7663 MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
7664 MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
7665 MAKE_FIXED_MODE_NODE (fract, qq, QQ)
7666 MAKE_FIXED_MODE_NODE (fract, hq, HQ)
7667 MAKE_FIXED_MODE_NODE (fract, sq, SQ)
7668 MAKE_FIXED_MODE_NODE (fract, dq, DQ)
7669 MAKE_FIXED_MODE_NODE (fract, tq, TQ)
7670 MAKE_FIXED_MODE_NODE (accum, ha, HA)
7671 MAKE_FIXED_MODE_NODE (accum, sa, SA)
7672 MAKE_FIXED_MODE_NODE (accum, da, DA)
7673 MAKE_FIXED_MODE_NODE (accum, ta, TA)
7676 tree t = targetm.build_builtin_va_list ();
7678 /* Many back-ends define record types without setting TYPE_NAME.
7679 If we copied the record type here, we'd keep the original
7680 record type without a name. This breaks name mangling. So,
7681 don't copy record types and let c_common_nodes_and_builtins()
7682 declare the type to be __builtin_va_list. */
7683 if (TREE_CODE (t) != RECORD_TYPE)
7684 t = build_variant_type_copy (t);
7686 va_list_type_node = t;
7690 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
7693 local_define_builtin (const char *name, tree type, enum built_in_function code,
7694 const char *library_name, int ecf_flags)
7698 decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
7699 library_name, NULL_TREE);
7700 if (ecf_flags & ECF_CONST)
7701 TREE_READONLY (decl) = 1;
7702 if (ecf_flags & ECF_PURE)
7703 DECL_PURE_P (decl) = 1;
7704 if (ecf_flags & ECF_LOOPING_CONST_OR_PURE)
7705 DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
7706 if (ecf_flags & ECF_NORETURN)
7707 TREE_THIS_VOLATILE (decl) = 1;
7708 if (ecf_flags & ECF_NOTHROW)
7709 TREE_NOTHROW (decl) = 1;
7710 if (ecf_flags & ECF_MALLOC)
7711 DECL_IS_MALLOC (decl) = 1;
7713 built_in_decls[code] = decl;
7714 implicit_built_in_decls[code] = decl;
7717 /* Call this function after instantiating all builtins that the language
7718 front end cares about. This will build the rest of the builtins that
7719 are relied upon by the tree optimizers and the middle-end. */
7722 build_common_builtin_nodes (void)
7726 if (built_in_decls[BUILT_IN_MEMCPY] == NULL
7727 || built_in_decls[BUILT_IN_MEMMOVE] == NULL)
7729 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
7730 tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
7731 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7732 ftype = build_function_type (ptr_type_node, tmp);
7734 if (built_in_decls[BUILT_IN_MEMCPY] == NULL)
7735 local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
7736 "memcpy", ECF_NOTHROW);
7737 if (built_in_decls[BUILT_IN_MEMMOVE] == NULL)
7738 local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
7739 "memmove", ECF_NOTHROW);
7742 if (built_in_decls[BUILT_IN_MEMCMP] == NULL)
7744 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
7745 tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
7746 tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
7747 ftype = build_function_type (integer_type_node, tmp);
7748 local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
7749 "memcmp", ECF_PURE | ECF_NOTHROW);
7752 if (built_in_decls[BUILT_IN_MEMSET] == NULL)
7754 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
7755 tmp = tree_cons (NULL_TREE, integer_type_node, tmp);
7756 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7757 ftype = build_function_type (ptr_type_node, tmp);
7758 local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
7759 "memset", ECF_NOTHROW);
7762 if (built_in_decls[BUILT_IN_ALLOCA] == NULL)
7764 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
7765 ftype = build_function_type (ptr_type_node, tmp);
7766 local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
7767 "alloca", ECF_NOTHROW | ECF_MALLOC);
7770 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7771 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7772 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7773 ftype = build_function_type (void_type_node, tmp);
7774 local_define_builtin ("__builtin_init_trampoline", ftype,
7775 BUILT_IN_INIT_TRAMPOLINE,
7776 "__builtin_init_trampoline", ECF_NOTHROW);
7778 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7779 ftype = build_function_type (ptr_type_node, tmp);
7780 local_define_builtin ("__builtin_adjust_trampoline", ftype,
7781 BUILT_IN_ADJUST_TRAMPOLINE,
7782 "__builtin_adjust_trampoline",
7783 ECF_CONST | ECF_NOTHROW);
7785 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7786 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7787 ftype = build_function_type (void_type_node, tmp);
7788 local_define_builtin ("__builtin_nonlocal_goto", ftype,
7789 BUILT_IN_NONLOCAL_GOTO,
7790 "__builtin_nonlocal_goto",
7791 ECF_NORETURN | ECF_NOTHROW);
7793 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7794 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7795 ftype = build_function_type (void_type_node, tmp);
7796 local_define_builtin ("__builtin_setjmp_setup", ftype,
7797 BUILT_IN_SETJMP_SETUP,
7798 "__builtin_setjmp_setup", ECF_NOTHROW);
7800 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7801 ftype = build_function_type (ptr_type_node, tmp);
7802 local_define_builtin ("__builtin_setjmp_dispatcher", ftype,
7803 BUILT_IN_SETJMP_DISPATCHER,
7804 "__builtin_setjmp_dispatcher",
7805 ECF_PURE | ECF_NOTHROW);
7807 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7808 ftype = build_function_type (void_type_node, tmp);
7809 local_define_builtin ("__builtin_setjmp_receiver", ftype,
7810 BUILT_IN_SETJMP_RECEIVER,
7811 "__builtin_setjmp_receiver", ECF_NOTHROW);
7813 ftype = build_function_type (ptr_type_node, void_list_node);
7814 local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
7815 "__builtin_stack_save", ECF_NOTHROW);
7817 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7818 ftype = build_function_type (void_type_node, tmp);
7819 local_define_builtin ("__builtin_stack_restore", ftype,
7820 BUILT_IN_STACK_RESTORE,
7821 "__builtin_stack_restore", ECF_NOTHROW);
7823 ftype = build_function_type (void_type_node, void_list_node);
7824 local_define_builtin ("__builtin_profile_func_enter", ftype,
7825 BUILT_IN_PROFILE_FUNC_ENTER, "profile_func_enter", 0);
7826 local_define_builtin ("__builtin_profile_func_exit", ftype,
7827 BUILT_IN_PROFILE_FUNC_EXIT, "profile_func_exit", 0);
7829 /* Complex multiplication and division. These are handled as builtins
7830 rather than optabs because emit_library_call_value doesn't support
7831 complex. Further, we can do slightly better with folding these
7832 beasties if the real and complex parts of the arguments are separate. */
7834 enum machine_mode mode;
7836 for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
7838 char mode_name_buf[4], *q;
7840 enum built_in_function mcode, dcode;
7841 tree type, inner_type;
7843 type = lang_hooks.types.type_for_mode (mode, 0);
7846 inner_type = TREE_TYPE (type);
7848 tmp = tree_cons (NULL_TREE, inner_type, void_list_node);
7849 tmp = tree_cons (NULL_TREE, inner_type, tmp);
7850 tmp = tree_cons (NULL_TREE, inner_type, tmp);
7851 tmp = tree_cons (NULL_TREE, inner_type, tmp);
7852 ftype = build_function_type (type, tmp);
7854 mcode = BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT;
7855 dcode = BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT;
7857 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
7861 built_in_names[mcode] = concat ("__mul", mode_name_buf, "3", NULL);
7862 local_define_builtin (built_in_names[mcode], ftype, mcode,
7863 built_in_names[mcode], ECF_CONST | ECF_NOTHROW);
7865 built_in_names[dcode] = concat ("__div", mode_name_buf, "3", NULL);
7866 local_define_builtin (built_in_names[dcode], ftype, dcode,
7867 built_in_names[dcode], ECF_CONST | ECF_NOTHROW);
7872 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
7875 If we requested a pointer to a vector, build up the pointers that
7876 we stripped off while looking for the inner type. Similarly for
7877 return values from functions.
7879 The argument TYPE is the top of the chain, and BOTTOM is the
7880 new type which we will point to. */
7883 reconstruct_complex_type (tree type, tree bottom)
7887 if (TREE_CODE (type) == POINTER_TYPE)
7889 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7890 outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
7891 TYPE_REF_CAN_ALIAS_ALL (type));
7893 else if (TREE_CODE (type) == REFERENCE_TYPE)
7895 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7896 outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
7897 TYPE_REF_CAN_ALIAS_ALL (type));
7899 else if (TREE_CODE (type) == ARRAY_TYPE)
7901 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7902 outer = build_array_type (inner, TYPE_DOMAIN (type));
7904 else if (TREE_CODE (type) == FUNCTION_TYPE)
7906 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7907 outer = build_function_type (inner, TYPE_ARG_TYPES (type));
7909 else if (TREE_CODE (type) == METHOD_TYPE)
7911 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7912 /* The build_method_type_directly() routine prepends 'this' to argument list,
7913 so we must compensate by getting rid of it. */
7915 = build_method_type_directly
7916 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
7918 TREE_CHAIN (TYPE_ARG_TYPES (type)));
7920 else if (TREE_CODE (type) == OFFSET_TYPE)
7922 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7923 outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
7928 return build_qualified_type (outer, TYPE_QUALS (type));
7931 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
7934 build_vector_type_for_mode (tree innertype, enum machine_mode mode)
7938 switch (GET_MODE_CLASS (mode))
7940 case MODE_VECTOR_INT:
7941 case MODE_VECTOR_FLOAT:
7942 case MODE_VECTOR_FRACT:
7943 case MODE_VECTOR_UFRACT:
7944 case MODE_VECTOR_ACCUM:
7945 case MODE_VECTOR_UACCUM:
7946 nunits = GET_MODE_NUNITS (mode);
7950 /* Check that there are no leftover bits. */
7951 gcc_assert (GET_MODE_BITSIZE (mode)
7952 % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
7954 nunits = GET_MODE_BITSIZE (mode)
7955 / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
7962 return make_vector_type (innertype, nunits, mode);
7965 /* Similarly, but takes the inner type and number of units, which must be
7969 build_vector_type (tree innertype, int nunits)
7971 return make_vector_type (innertype, nunits, VOIDmode);
7974 /* Similarly, but takes the inner type and number of units, which must be
7978 build_opaque_vector_type (tree innertype, int nunits)
7981 innertype = build_distinct_type_copy (innertype);
7982 t = make_vector_type (innertype, nunits, VOIDmode);
7983 TYPE_VECTOR_OPAQUE (t) = true;
7988 /* Build RESX_EXPR with given REGION_NUMBER. */
7990 build_resx (int region_number)
7993 t = build1 (RESX_EXPR, void_type_node,
7994 build_int_cst (NULL_TREE, region_number));
7998 /* Given an initializer INIT, return TRUE if INIT is zero or some
7999 aggregate of zeros. Otherwise return FALSE. */
8001 initializer_zerop (const_tree init)
8007 switch (TREE_CODE (init))
8010 return integer_zerop (init);
8013 /* ??? Note that this is not correct for C4X float formats. There,
8014 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
8015 negative exponent. */
8016 return real_zerop (init)
8017 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
8020 return fixed_zerop (init);
8023 return integer_zerop (init)
8024 || (real_zerop (init)
8025 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
8026 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
8029 for (elt = TREE_VECTOR_CST_ELTS (init); elt; elt = TREE_CHAIN (elt))
8030 if (!initializer_zerop (TREE_VALUE (elt)))
8036 unsigned HOST_WIDE_INT idx;
8038 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
8039 if (!initializer_zerop (elt))
8049 /* Build an empty statement. */
8052 build_empty_stmt (void)
8054 return build1 (NOP_EXPR, void_type_node, size_zero_node);
8058 /* Build an OpenMP clause with code CODE. */
8061 build_omp_clause (enum omp_clause_code code)
8066 length = omp_clause_num_ops[code];
8067 size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
8069 t = GGC_NEWVAR (union tree_node, size);
8070 memset (t, 0, size);
8071 TREE_SET_CODE (t, OMP_CLAUSE);
8072 OMP_CLAUSE_SET_CODE (t, code);
8074 #ifdef GATHER_STATISTICS
8075 tree_node_counts[(int) omp_clause_kind]++;
8076 tree_node_sizes[(int) omp_clause_kind] += size;
8082 /* Set various status flags when building a CALL_EXPR object T. */
8085 process_call_operands (tree t)
8089 side_effects = TREE_SIDE_EFFECTS (t);
8093 n = TREE_OPERAND_LENGTH (t);
8094 for (i = 1; i < n; i++)
8096 tree op = TREE_OPERAND (t, i);
8097 if (op && TREE_SIDE_EFFECTS (op))
8108 /* Calls have side-effects, except those to const or
8110 i = call_expr_flags (t);
8111 if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
8114 TREE_SIDE_EFFECTS (t) = side_effects;
8117 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
8118 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
8119 Except for the CODE and operand count field, other storage for the
8120 object is initialized to zeros. */
8123 build_vl_exp_stat (enum tree_code code, int len MEM_STAT_DECL)
8126 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
8128 gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
8129 gcc_assert (len >= 1);
8131 #ifdef GATHER_STATISTICS
8132 tree_node_counts[(int) e_kind]++;
8133 tree_node_sizes[(int) e_kind] += length;
8136 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
8138 memset (t, 0, length);
8140 TREE_SET_CODE (t, code);
8142 /* Can't use TREE_OPERAND to store the length because if checking is
8143 enabled, it will try to check the length before we store it. :-P */
8144 t->exp.operands[0] = build_int_cst (sizetype, len);
8150 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE
8151 and FN and a null static chain slot. ARGLIST is a TREE_LIST of the
8155 build_call_list (tree return_type, tree fn, tree arglist)
8160 t = build_vl_exp (CALL_EXPR, list_length (arglist) + 3);
8161 TREE_TYPE (t) = return_type;
8162 CALL_EXPR_FN (t) = fn;
8163 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
8164 for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++)
8165 CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist);
8166 process_call_operands (t);
8170 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8171 FN and a null static chain slot. NARGS is the number of call arguments
8172 which are specified as "..." arguments. */
8175 build_call_nary (tree return_type, tree fn, int nargs, ...)
8179 va_start (args, nargs);
8180 ret = build_call_valist (return_type, fn, nargs, args);
8185 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8186 FN and a null static chain slot. NARGS is the number of call arguments
8187 which are specified as a va_list ARGS. */
8190 build_call_valist (tree return_type, tree fn, int nargs, va_list args)
8195 t = build_vl_exp (CALL_EXPR, nargs + 3);
8196 TREE_TYPE (t) = return_type;
8197 CALL_EXPR_FN (t) = fn;
8198 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
8199 for (i = 0; i < nargs; i++)
8200 CALL_EXPR_ARG (t, i) = va_arg (args, tree);
8201 process_call_operands (t);
8205 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8206 FN and a null static chain slot. NARGS is the number of call arguments
8207 which are specified as a tree array ARGS. */
8210 build_call_array (tree return_type, tree fn, int nargs, tree *args)
8215 t = build_vl_exp (CALL_EXPR, nargs + 3);
8216 TREE_TYPE (t) = return_type;
8217 CALL_EXPR_FN (t) = fn;
8218 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
8219 for (i = 0; i < nargs; i++)
8220 CALL_EXPR_ARG (t, i) = args[i];
8221 process_call_operands (t);
8226 /* Returns true if it is possible to prove that the index of
8227 an array access REF (an ARRAY_REF expression) falls into the
8231 in_array_bounds_p (tree ref)
8233 tree idx = TREE_OPERAND (ref, 1);
8236 if (TREE_CODE (idx) != INTEGER_CST)
8239 min = array_ref_low_bound (ref);
8240 max = array_ref_up_bound (ref);
8243 || TREE_CODE (min) != INTEGER_CST
8244 || TREE_CODE (max) != INTEGER_CST)
8247 if (tree_int_cst_lt (idx, min)
8248 || tree_int_cst_lt (max, idx))
8254 /* Returns true if it is possible to prove that the range of
8255 an array access REF (an ARRAY_RANGE_REF expression) falls
8256 into the array bounds. */
8259 range_in_array_bounds_p (tree ref)
8261 tree domain_type = TYPE_DOMAIN (TREE_TYPE (ref));
8262 tree range_min, range_max, min, max;
8264 range_min = TYPE_MIN_VALUE (domain_type);
8265 range_max = TYPE_MAX_VALUE (domain_type);
8268 || TREE_CODE (range_min) != INTEGER_CST
8269 || TREE_CODE (range_max) != INTEGER_CST)
8272 min = array_ref_low_bound (ref);
8273 max = array_ref_up_bound (ref);
8276 || TREE_CODE (min) != INTEGER_CST
8277 || TREE_CODE (max) != INTEGER_CST)
8280 if (tree_int_cst_lt (range_min, min)
8281 || tree_int_cst_lt (max, range_max))
8287 /* Return true if T (assumed to be a DECL) must be assigned a memory
8291 needs_to_live_in_memory (const_tree t)
8293 if (TREE_CODE (t) == SSA_NAME)
8294 t = SSA_NAME_VAR (t);
8296 return (TREE_ADDRESSABLE (t)
8297 || is_global_var (t)
8298 || (TREE_CODE (t) == RESULT_DECL
8299 && aggregate_value_p (t, current_function_decl)));
8302 /* There are situations in which a language considers record types
8303 compatible which have different field lists. Decide if two fields
8304 are compatible. It is assumed that the parent records are compatible. */
8307 fields_compatible_p (const_tree f1, const_tree f2)
8309 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1),
8310 DECL_FIELD_BIT_OFFSET (f2), OEP_ONLY_CONST))
8313 if (!operand_equal_p (DECL_FIELD_OFFSET (f1),
8314 DECL_FIELD_OFFSET (f2), OEP_ONLY_CONST))
8317 if (!types_compatible_p (TREE_TYPE (f1), TREE_TYPE (f2)))
8323 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
8326 find_compatible_field (tree record, tree orig_field)
8330 for (f = TYPE_FIELDS (record); f ; f = TREE_CHAIN (f))
8331 if (TREE_CODE (f) == FIELD_DECL
8332 && fields_compatible_p (f, orig_field))
8335 /* ??? Why isn't this on the main fields list? */
8336 f = TYPE_VFIELD (record);
8337 if (f && TREE_CODE (f) == FIELD_DECL
8338 && fields_compatible_p (f, orig_field))
8341 /* ??? We should abort here, but Java appears to do Bad Things
8342 with inherited fields. */
8346 /* Return value of a constant X and sign-extend it. */
8349 int_cst_value (const_tree x)
8351 unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
8352 unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
8354 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
8355 gcc_assert (TREE_INT_CST_HIGH (x) == 0
8356 || TREE_INT_CST_HIGH (x) == -1);
8358 if (bits < HOST_BITS_PER_WIDE_INT)
8360 bool negative = ((val >> (bits - 1)) & 1) != 0;
8362 val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1;
8364 val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1);
8370 /* If TYPE is an integral type, return an equivalent type which is
8371 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type,
8372 return TYPE itself. */
8375 signed_or_unsigned_type_for (int unsignedp, tree type)
8378 if (POINTER_TYPE_P (type))
8381 if (!INTEGRAL_TYPE_P (t) || TYPE_UNSIGNED (t) == unsignedp)
8384 return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp);
8387 /* Returns unsigned variant of TYPE. */
8390 unsigned_type_for (tree type)
8392 return signed_or_unsigned_type_for (1, type);
8395 /* Returns signed variant of TYPE. */
8398 signed_type_for (tree type)
8400 return signed_or_unsigned_type_for (0, type);
8403 /* Returns the largest value obtainable by casting something in INNER type to
8407 upper_bound_in_type (tree outer, tree inner)
8409 unsigned HOST_WIDE_INT lo, hi;
8410 unsigned int det = 0;
8411 unsigned oprec = TYPE_PRECISION (outer);
8412 unsigned iprec = TYPE_PRECISION (inner);
8415 /* Compute a unique number for every combination. */
8416 det |= (oprec > iprec) ? 4 : 0;
8417 det |= TYPE_UNSIGNED (outer) ? 2 : 0;
8418 det |= TYPE_UNSIGNED (inner) ? 1 : 0;
8420 /* Determine the exponent to use. */
8425 /* oprec <= iprec, outer: signed, inner: don't care. */
8430 /* oprec <= iprec, outer: unsigned, inner: don't care. */
8434 /* oprec > iprec, outer: signed, inner: signed. */
8438 /* oprec > iprec, outer: signed, inner: unsigned. */
8442 /* oprec > iprec, outer: unsigned, inner: signed. */
8446 /* oprec > iprec, outer: unsigned, inner: unsigned. */
8453 /* Compute 2^^prec - 1. */
8454 if (prec <= HOST_BITS_PER_WIDE_INT)
8457 lo = ((~(unsigned HOST_WIDE_INT) 0)
8458 >> (HOST_BITS_PER_WIDE_INT - prec));
8462 hi = ((~(unsigned HOST_WIDE_INT) 0)
8463 >> (2 * HOST_BITS_PER_WIDE_INT - prec));
8464 lo = ~(unsigned HOST_WIDE_INT) 0;
8467 return build_int_cst_wide (outer, lo, hi);
8470 /* Returns the smallest value obtainable by casting something in INNER type to
8474 lower_bound_in_type (tree outer, tree inner)
8476 unsigned HOST_WIDE_INT lo, hi;
8477 unsigned oprec = TYPE_PRECISION (outer);
8478 unsigned iprec = TYPE_PRECISION (inner);
8480 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
8482 if (TYPE_UNSIGNED (outer)
8483 /* If we are widening something of an unsigned type, OUTER type
8484 contains all values of INNER type. In particular, both INNER
8485 and OUTER types have zero in common. */
8486 || (oprec > iprec && TYPE_UNSIGNED (inner)))
8490 /* If we are widening a signed type to another signed type, we
8491 want to obtain -2^^(iprec-1). If we are keeping the
8492 precision or narrowing to a signed type, we want to obtain
8494 unsigned prec = oprec > iprec ? iprec : oprec;
8496 if (prec <= HOST_BITS_PER_WIDE_INT)
8498 hi = ~(unsigned HOST_WIDE_INT) 0;
8499 lo = (~(unsigned HOST_WIDE_INT) 0) << (prec - 1);
8503 hi = ((~(unsigned HOST_WIDE_INT) 0)
8504 << (prec - HOST_BITS_PER_WIDE_INT - 1));
8509 return build_int_cst_wide (outer, lo, hi);
8512 /* Return nonzero if two operands that are suitable for PHI nodes are
8513 necessarily equal. Specifically, both ARG0 and ARG1 must be either
8514 SSA_NAME or invariant. Note that this is strictly an optimization.
8515 That is, callers of this function can directly call operand_equal_p
8516 and get the same result, only slower. */
8519 operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
8523 if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
8525 return operand_equal_p (arg0, arg1, 0);
8528 /* Returns number of zeros at the end of binary representation of X.
8530 ??? Use ffs if available? */
8533 num_ending_zeros (const_tree x)
8535 unsigned HOST_WIDE_INT fr, nfr;
8536 unsigned num, abits;
8537 tree type = TREE_TYPE (x);
8539 if (TREE_INT_CST_LOW (x) == 0)
8541 num = HOST_BITS_PER_WIDE_INT;
8542 fr = TREE_INT_CST_HIGH (x);
8547 fr = TREE_INT_CST_LOW (x);
8550 for (abits = HOST_BITS_PER_WIDE_INT / 2; abits; abits /= 2)
8553 if (nfr << abits == fr)
8560 if (num > TYPE_PRECISION (type))
8561 num = TYPE_PRECISION (type);
8563 return build_int_cst_type (type, num);
8567 #define WALK_SUBTREE(NODE) \
8570 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
8576 /* This is a subroutine of walk_tree that walks field of TYPE that are to
8577 be walked whenever a type is seen in the tree. Rest of operands and return
8578 value are as for walk_tree. */
8581 walk_type_fields (tree type, walk_tree_fn func, void *data,
8582 struct pointer_set_t *pset, walk_tree_lh lh)
8584 tree result = NULL_TREE;
8586 switch (TREE_CODE (type))
8589 case REFERENCE_TYPE:
8590 /* We have to worry about mutually recursive pointers. These can't
8591 be written in C. They can in Ada. It's pathological, but
8592 there's an ACATS test (c38102a) that checks it. Deal with this
8593 by checking if we're pointing to another pointer, that one
8594 points to another pointer, that one does too, and we have no htab.
8595 If so, get a hash table. We check three levels deep to avoid
8596 the cost of the hash table if we don't need one. */
8597 if (POINTER_TYPE_P (TREE_TYPE (type))
8598 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
8599 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
8602 result = walk_tree_without_duplicates (&TREE_TYPE (type),
8610 /* ... fall through ... */
8613 WALK_SUBTREE (TREE_TYPE (type));
8617 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
8622 WALK_SUBTREE (TREE_TYPE (type));
8626 /* We never want to walk into default arguments. */
8627 for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
8628 WALK_SUBTREE (TREE_VALUE (arg));
8633 /* Don't follow this nodes's type if a pointer for fear that
8634 we'll have infinite recursion. If we have a PSET, then we
8637 || (!POINTER_TYPE_P (TREE_TYPE (type))
8638 && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
8639 WALK_SUBTREE (TREE_TYPE (type));
8640 WALK_SUBTREE (TYPE_DOMAIN (type));
8644 WALK_SUBTREE (TREE_TYPE (type));
8645 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
8655 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
8656 called with the DATA and the address of each sub-tree. If FUNC returns a
8657 non-NULL value, the traversal is stopped, and the value returned by FUNC
8658 is returned. If PSET is non-NULL it is used to record the nodes visited,
8659 and to avoid visiting a node more than once. */
8662 walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
8663 struct pointer_set_t *pset, walk_tree_lh lh)
8665 enum tree_code code;
8669 #define WALK_SUBTREE_TAIL(NODE) \
8673 goto tail_recurse; \
8678 /* Skip empty subtrees. */
8682 /* Don't walk the same tree twice, if the user has requested
8683 that we avoid doing so. */
8684 if (pset && pointer_set_insert (pset, *tp))
8687 /* Call the function. */
8689 result = (*func) (tp, &walk_subtrees, data);
8691 /* If we found something, return it. */
8695 code = TREE_CODE (*tp);
8697 /* Even if we didn't, FUNC may have decided that there was nothing
8698 interesting below this point in the tree. */
8701 /* But we still need to check our siblings. */
8702 if (code == TREE_LIST)
8703 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
8704 else if (code == OMP_CLAUSE)
8705 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
8712 result = (*lh) (tp, &walk_subtrees, func, data, pset);
8713 if (result || !walk_subtrees)
8720 case IDENTIFIER_NODE:
8727 case PLACEHOLDER_EXPR:
8731 /* None of these have subtrees other than those already walked
8736 WALK_SUBTREE (TREE_VALUE (*tp));
8737 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
8742 int len = TREE_VEC_LENGTH (*tp);
8747 /* Walk all elements but the first. */
8749 WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
8751 /* Now walk the first one as a tail call. */
8752 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0));
8756 WALK_SUBTREE (TREE_REALPART (*tp));
8757 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp));
8761 unsigned HOST_WIDE_INT idx;
8762 constructor_elt *ce;
8765 VEC_iterate(constructor_elt, CONSTRUCTOR_ELTS (*tp), idx, ce);
8767 WALK_SUBTREE (ce->value);
8772 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 0));
8777 for (decl = BIND_EXPR_VARS (*tp); decl; decl = TREE_CHAIN (decl))
8779 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
8780 into declarations that are just mentioned, rather than
8781 declared; they don't really belong to this part of the tree.
8782 And, we can see cycles: the initializer for a declaration
8783 can refer to the declaration itself. */
8784 WALK_SUBTREE (DECL_INITIAL (decl));
8785 WALK_SUBTREE (DECL_SIZE (decl));
8786 WALK_SUBTREE (DECL_SIZE_UNIT (decl));
8788 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp));
8791 case STATEMENT_LIST:
8793 tree_stmt_iterator i;
8794 for (i = tsi_start (*tp); !tsi_end_p (i); tsi_next (&i))
8795 WALK_SUBTREE (*tsi_stmt_ptr (i));
8800 switch (OMP_CLAUSE_CODE (*tp))
8802 case OMP_CLAUSE_PRIVATE:
8803 case OMP_CLAUSE_SHARED:
8804 case OMP_CLAUSE_FIRSTPRIVATE:
8805 case OMP_CLAUSE_COPYIN:
8806 case OMP_CLAUSE_COPYPRIVATE:
8808 case OMP_CLAUSE_NUM_THREADS:
8809 case OMP_CLAUSE_SCHEDULE:
8810 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, 0));
8813 case OMP_CLAUSE_NOWAIT:
8814 case OMP_CLAUSE_ORDERED:
8815 case OMP_CLAUSE_DEFAULT:
8816 case OMP_CLAUSE_UNTIED:
8817 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
8819 case OMP_CLAUSE_LASTPRIVATE:
8820 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp));
8821 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp));
8822 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
8824 case OMP_CLAUSE_COLLAPSE:
8827 for (i = 0; i < 3; i++)
8828 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i));
8829 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
8832 case OMP_CLAUSE_REDUCTION:
8835 for (i = 0; i < 4; i++)
8836 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i));
8837 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
8849 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
8850 But, we only want to walk once. */
8851 len = (TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1)) ? 2 : 3;
8852 for (i = 0; i < len; ++i)
8853 WALK_SUBTREE (TREE_OPERAND (*tp, i));
8854 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len));
8857 case CHANGE_DYNAMIC_TYPE_EXPR:
8858 WALK_SUBTREE (CHANGE_DYNAMIC_TYPE_NEW_TYPE (*tp));
8859 WALK_SUBTREE_TAIL (CHANGE_DYNAMIC_TYPE_LOCATION (*tp));
8862 /* If this is a TYPE_DECL, walk into the fields of the type that it's
8863 defining. We only want to walk into these fields of a type in this
8864 case and not in the general case of a mere reference to the type.
8866 The criterion is as follows: if the field can be an expression, it
8867 must be walked only here. This should be in keeping with the fields
8868 that are directly gimplified in gimplify_type_sizes in order for the
8869 mark/copy-if-shared/unmark machinery of the gimplifier to work with
8870 variable-sized types.
8872 Note that DECLs get walked as part of processing the BIND_EXPR. */
8873 if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL)
8875 tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp));
8876 if (TREE_CODE (*type_p) == ERROR_MARK)
8879 /* Call the function for the type. See if it returns anything or
8880 doesn't want us to continue. If we are to continue, walk both
8881 the normal fields and those for the declaration case. */
8882 result = (*func) (type_p, &walk_subtrees, data);
8883 if (result || !walk_subtrees)
8886 result = walk_type_fields (*type_p, func, data, pset, lh);
8890 /* If this is a record type, also walk the fields. */
8891 if (TREE_CODE (*type_p) == RECORD_TYPE
8892 || TREE_CODE (*type_p) == UNION_TYPE
8893 || TREE_CODE (*type_p) == QUAL_UNION_TYPE)
8897 for (field = TYPE_FIELDS (*type_p); field;
8898 field = TREE_CHAIN (field))
8900 /* We'd like to look at the type of the field, but we can
8901 easily get infinite recursion. So assume it's pointed
8902 to elsewhere in the tree. Also, ignore things that
8904 if (TREE_CODE (field) != FIELD_DECL)
8907 WALK_SUBTREE (DECL_FIELD_OFFSET (field));
8908 WALK_SUBTREE (DECL_SIZE (field));
8909 WALK_SUBTREE (DECL_SIZE_UNIT (field));
8910 if (TREE_CODE (*type_p) == QUAL_UNION_TYPE)
8911 WALK_SUBTREE (DECL_QUALIFIER (field));
8915 /* Same for scalar types. */
8916 else if (TREE_CODE (*type_p) == BOOLEAN_TYPE
8917 || TREE_CODE (*type_p) == ENUMERAL_TYPE
8918 || TREE_CODE (*type_p) == INTEGER_TYPE
8919 || TREE_CODE (*type_p) == FIXED_POINT_TYPE
8920 || TREE_CODE (*type_p) == REAL_TYPE)
8922 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p));
8923 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p));
8926 WALK_SUBTREE (TYPE_SIZE (*type_p));
8927 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p));
8932 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
8936 /* Walk over all the sub-trees of this operand. */
8937 len = TREE_OPERAND_LENGTH (*tp);
8939 /* Go through the subtrees. We need to do this in forward order so
8940 that the scope of a FOR_EXPR is handled properly. */
8943 for (i = 0; i < len - 1; ++i)
8944 WALK_SUBTREE (TREE_OPERAND (*tp, i));
8945 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len - 1));
8948 /* If this is a type, walk the needed fields in the type. */
8949 else if (TYPE_P (*tp))
8950 return walk_type_fields (*tp, func, data, pset, lh);
8954 /* We didn't find what we were looking for. */
8957 #undef WALK_SUBTREE_TAIL
8961 /* Like walk_tree, but does not walk duplicate nodes more than once. */
8964 walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
8968 struct pointer_set_t *pset;
8970 pset = pointer_set_create ();
8971 result = walk_tree_1 (tp, func, data, pset, lh);
8972 pointer_set_destroy (pset);
8980 char const c = TREE_CODE_CLASS (TREE_CODE (t));
8982 if (IS_EXPR_CODE_CLASS (c))
8983 return &t->exp.block;
8988 /* Build and return a TREE_LIST of arguments in the CALL_EXPR exp.
8989 FIXME: don't use this function. It exists for compatibility with
8990 the old representation of CALL_EXPRs where a list was used to hold the
8991 arguments. Places that currently extract the arglist from a CALL_EXPR
8992 ought to be rewritten to use the CALL_EXPR itself. */
8994 call_expr_arglist (tree exp)
8996 tree arglist = NULL_TREE;
8998 for (i = call_expr_nargs (exp) - 1; i >= 0; i--)
8999 arglist = tree_cons (NULL_TREE, CALL_EXPR_ARG (exp, i), arglist);
9004 /* Create a nameless artificial label and put it in the current function
9005 context. Returns the newly created label. */
9008 create_artificial_label (void)
9010 tree lab = build_decl (LABEL_DECL, NULL_TREE, void_type_node);
9012 DECL_ARTIFICIAL (lab) = 1;
9013 DECL_IGNORED_P (lab) = 1;
9014 DECL_CONTEXT (lab) = current_function_decl;
9018 /* Given a tree, try to return a useful variable name that we can use
9019 to prefix a temporary that is being assigned the value of the tree.
9020 I.E. given <temp> = &A, return A. */
9028 STRIP_NOPS (stripped_decl);
9029 if (DECL_P (stripped_decl) && DECL_NAME (stripped_decl))
9030 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
9033 switch (TREE_CODE (stripped_decl))
9036 return get_name (TREE_OPERAND (stripped_decl, 0));
9043 /* Return true if TYPE has a variable argument list. */
9046 stdarg_p (tree fntype)
9048 function_args_iterator args_iter;
9049 tree n = NULL_TREE, t;
9054 FOREACH_FUNCTION_ARGS(fntype, t, args_iter)
9059 return n != NULL_TREE && n != void_type_node;
9062 /* Return true if TYPE has a prototype. */
9065 prototype_p (tree fntype)
9069 gcc_assert (fntype != NULL_TREE);
9071 t = TYPE_ARG_TYPES (fntype);
9072 return (t != NULL_TREE);
9075 /* If BLOCK is inlined from an __attribute__((__artificial__))
9076 routine, return pointer to location from where it has been
9079 block_nonartificial_location (tree block)
9081 location_t *ret = NULL;
9083 while (block && TREE_CODE (block) == BLOCK
9084 && BLOCK_ABSTRACT_ORIGIN (block))
9086 tree ao = BLOCK_ABSTRACT_ORIGIN (block);
9088 while (TREE_CODE (ao) == BLOCK
9089 && BLOCK_ABSTRACT_ORIGIN (ao)
9090 && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
9091 ao = BLOCK_ABSTRACT_ORIGIN (ao);
9093 if (TREE_CODE (ao) == FUNCTION_DECL)
9095 /* If AO is an artificial inline, point RET to the
9096 call site locus at which it has been inlined and continue
9097 the loop, in case AO's caller is also an artificial
9099 if (DECL_DECLARED_INLINE_P (ao)
9100 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
9101 ret = &BLOCK_SOURCE_LOCATION (block);
9105 else if (TREE_CODE (ao) != BLOCK)
9108 block = BLOCK_SUPERCONTEXT (block);
9114 /* If EXP is inlined from an __attribute__((__artificial__))
9115 function, return the location of the original call expression. */
9118 tree_nonartificial_location (tree exp)
9120 tree block = TREE_BLOCK (exp);
9123 && TREE_CODE (block) == BLOCK
9124 && BLOCK_ABSTRACT_ORIGIN (block))
9126 tree ao = BLOCK_ABSTRACT_ORIGIN (block);
9130 if (TREE_CODE (ao) == FUNCTION_DECL
9131 && DECL_DECLARED_INLINE_P (ao)
9132 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
9133 return BLOCK_SOURCE_LOCATION (block);
9134 else if (TREE_CODE (ao) == BLOCK
9135 && BLOCK_SUPERCONTEXT (ao) != ao)
9136 ao = BLOCK_SUPERCONTEXT (ao);
9142 block = BLOCK_SUPERCONTEXT (block);
9145 return EXPR_LOCATION (exp);
9149 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
9152 /* Return the hash code code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
9155 cl_option_hash_hash (const void *x)
9157 const_tree const t = (const_tree) x;
9163 if (TREE_CODE (t) == OPTIMIZATION_NODE)
9165 p = (const char *)TREE_OPTIMIZATION (t);
9166 len = sizeof (struct cl_optimization);
9169 else if (TREE_CODE (t) == TARGET_OPTION_NODE)
9171 p = (const char *)TREE_TARGET_OPTION (t);
9172 len = sizeof (struct cl_target_option);
9178 /* assume most opt flags are just 0/1, some are 2-3, and a few might be
9180 for (i = 0; i < len; i++)
9182 hash = (hash << 4) ^ ((i << 2) | p[i]);
9187 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
9188 TARGET_OPTION tree node) is the same as that given by *Y, which is the
9192 cl_option_hash_eq (const void *x, const void *y)
9194 const_tree const xt = (const_tree) x;
9195 const_tree const yt = (const_tree) y;
9200 if (TREE_CODE (xt) != TREE_CODE (yt))
9203 if (TREE_CODE (xt) == OPTIMIZATION_NODE)
9205 xp = (const char *)TREE_OPTIMIZATION (xt);
9206 yp = (const char *)TREE_OPTIMIZATION (yt);
9207 len = sizeof (struct cl_optimization);
9210 else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
9212 xp = (const char *)TREE_TARGET_OPTION (xt);
9213 yp = (const char *)TREE_TARGET_OPTION (yt);
9214 len = sizeof (struct cl_target_option);
9220 return (memcmp (xp, yp, len) == 0);
9223 /* Build an OPTIMIZATION_NODE based on the current options. */
9226 build_optimization_node (void)
9231 /* Use the cache of optimization nodes. */
9233 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node));
9235 slot = htab_find_slot (cl_option_hash_table, cl_optimization_node, INSERT);
9239 /* Insert this one into the hash table. */
9240 t = cl_optimization_node;
9243 /* Make a new node for next time round. */
9244 cl_optimization_node = make_node (OPTIMIZATION_NODE);
9250 /* Build a TARGET_OPTION_NODE based on the current options. */
9253 build_target_option_node (void)
9258 /* Use the cache of optimization nodes. */
9260 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node));
9262 slot = htab_find_slot (cl_option_hash_table, cl_target_option_node, INSERT);
9266 /* Insert this one into the hash table. */
9267 t = cl_target_option_node;
9270 /* Make a new node for next time round. */
9271 cl_target_option_node = make_node (TARGET_OPTION_NODE);
9277 /* Determine the "ultimate origin" of a block. The block may be an inlined
9278 instance of an inlined instance of a block which is local to an inline
9279 function, so we have to trace all of the way back through the origin chain
9280 to find out what sort of node actually served as the original seed for the
9284 block_ultimate_origin (const_tree block)
9286 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
9288 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
9289 nodes in the function to point to themselves; ignore that if
9290 we're trying to output the abstract instance of this function. */
9291 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
9294 if (immediate_origin == NULL_TREE)
9299 tree lookahead = immediate_origin;
9303 ret_val = lookahead;
9304 lookahead = (TREE_CODE (ret_val) == BLOCK
9305 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
9307 while (lookahead != NULL && lookahead != ret_val);
9309 /* The block's abstract origin chain may not be the *ultimate* origin of
9310 the block. It could lead to a DECL that has an abstract origin set.
9311 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
9312 will give us if it has one). Note that DECL's abstract origins are
9313 supposed to be the most distant ancestor (or so decl_ultimate_origin
9314 claims), so we don't need to loop following the DECL origins. */
9315 if (DECL_P (ret_val))
9316 return DECL_ORIGIN (ret_val);
9322 #include "gt-tree.h"